diff --git a/cortex/alert.py b/cortex/alert.py index b0104a2..0fec675 100644 --- a/cortex/alert.py +++ b/cortex/alert.py @@ -8,6 +8,7 @@ Usage: """ import argparse +import os import json import subprocess import sys @@ -75,11 +76,11 @@ def check_nats() -> list[Alert]: def check_docker() -> list[Alert]: alerts = [] rc, out, _ = _run( - ["ssh", "deploy@192.168.0.137", "docker ps --format '{{.Names}}|{{.Status}}'"], + ["ssh", os.environ.get("DARKPLEX_DOCKER_HOST", "deploy@localhost"), "docker ps --format '{{.Names}}|{{.Status}}'"], timeout=15, ) if rc != 0: - alerts.append(Alert("Docker", "warning", "Cannot reach dock5")) + alerts.append(Alert("Docker", "warning", "Cannot reach Docker host")) return alerts for line in out.strip().split("\n"): @@ -143,7 +144,7 @@ def aggregate_all(quiet=False) -> list[Alert]: for name, fn in checks: if not quiet: - print(f"🔍 Checking {name}...", file=sys.stderr) + logging.getLogger(__name__).info("Checking %s...", name) try: all_alerts.extend(fn()) except Exception as e: diff --git a/cortex/anomaly.py b/cortex/anomaly.py index 1c8ea9f..5c927d6 100644 --- a/cortex/anomaly.py +++ b/cortex/anomaly.py @@ -58,7 +58,7 @@ def fetch_events(hours: int = 1) -> list: return events info = json.loads(r.stdout) end_seq = info["state"]["last_seq"] - start_seq = max(info["state"]["first_seq"], end_seq - 2000) + start_seq = max(info["state"]["first_seq"], end_seq - 200) for seq in range(start_seq, end_seq + 1): try: diff --git a/cortex/monitor.py b/cortex/monitor.py index 4a0d1ff..c2ccb5f 100644 --- a/cortex/monitor.py +++ b/cortex/monitor.py @@ -9,6 +9,7 @@ Usage: import argparse import json +import os import subprocess import sys from datetime import datetime @@ -16,14 +17,28 @@ from pathlib import Path from cortex.config import cortex_home -AGENTS = { - "main": {"name": "Claudia", "emoji": "🛡️", "stream": "openclaw-events"}, - "mondo-assistant": {"name": "Mona", "emoji": "🌙", "stream": "events-mondo-assistant"}, - "vera": {"name": "Vera", "emoji": "🔒", "stream": "events-vera"}, - "stella": {"name": "Stella", "emoji": "💰", "stream": "events-stella"}, - "viola": {"name": "Viola", "emoji": "⚙️", "stream": "events-viola"}, +# Default agents — override via DARKPLEX_AGENTS_CONFIG or agents.json in config dir +_DEFAULT_AGENTS = { + "main": {"name": "Main", "emoji": "🤖", "stream": "openclaw-events"}, } +def _load_agents(): + """Load agent config from file or env, fall back to defaults.""" + config_path = os.environ.get("DARKPLEX_AGENTS_CONFIG", "") + if not config_path: + config_dir = os.environ.get("DARKPLEX_CONFIG_DIR", os.path.expanduser("~/.darkplex")) + config_path = os.path.join(config_dir, "agents.json") + if os.path.exists(config_path): + try: + with open(config_path) as f: + import json + return json.load(f) + except Exception: + pass + return _DEFAULT_AGENTS + +AGENTS = _load_agents() + NATS_BIN = str(Path.home() / "bin" / "nats") diff --git a/cortex/needs.py b/cortex/needs.py index 6e1ef36..cca03f0 100644 --- a/cortex/needs.py +++ b/cortex/needs.py @@ -10,6 +10,7 @@ Usage: import argparse import json +import os import subprocess import sys from dataclasses import asdict, dataclass, field @@ -97,9 +98,9 @@ def sense_context(): details.append("BOOT_CONTEXT.md missing") home = cortex_home() - memory_md = home.parent / "clawd" / "MEMORY.md" if "cortex" not in str(home) else home / "MEMORY.md" + memory_md = Path(os.environ.get("DARKPLEX_WORKSPACE", str(Path.home()))) / "MEMORY.md" if "cortex" not in str(home) else home / "MEMORY.md" # Try standard location - for p in [Path.home() / "clawd" / "MEMORY.md", home / "MEMORY.md"]: + for p in [Path(os.environ.get('DARKPLEX_WORKSPACE', os.environ.get('OPENCLAW_WORKSPACE', str(Path.home())))) / "MEMORY.md", home / "MEMORY.md"]: if p.exists(): if p.stat().st_size < 100: score -= 0.3 @@ -119,7 +120,7 @@ def sense_context(): def sense_health(): score, details, healed, escalate = 1.0, [], [], [] - rc, out, _ = _run_cmd(["systemctl", "--user", "is-active", "event-consumer"]) + rc, out, _ = _run_cmd(["systemctl", "--user", "is-active", os.environ.get("DARKPLEX_EVENT_SERVICE", "event-consumer")]) if out.strip() != "active": score -= 0.3 details.append("Event Consumer inactive") @@ -154,7 +155,7 @@ def sense_energy(): score, details = 1.0, [] total_ctx_bytes = 0 - clawd = Path.home() / "clawd" + clawd = Path(os.environ.get('DARKPLEX_WORKSPACE', os.environ.get('OPENCLAW_WORKSPACE', str(Path.home())))) for f in ["SOUL.md", "AGENTS.md", "TOOLS.md", "MEMORY.md", "USER.md"]: p = clawd / f if p.exists(): @@ -189,7 +190,7 @@ def sense_connection(): def sense_growth(): score, details = 1.0, [] - rag_db = Path.home() / "clawd" / ".rag-db" / "chroma.sqlite3" + rag_db = Path(os.environ.get('DARKPLEX_WORKSPACE', os.environ.get('OPENCLAW_WORKSPACE', str(Path.home())))) / ".rag-db" / "chroma.sqlite3" if rag_db.exists(): age_days = (datetime.now().timestamp() - rag_db.stat().st_mtime) / 86400 if age_days > 14: diff --git a/cortex/summarize.py b/cortex/summarize.py index b333b70..4b02e0a 100644 --- a/cortex/summarize.py +++ b/cortex/summarize.py @@ -8,6 +8,7 @@ Usage: import argparse import base64 import json +import os import subprocess import sys import time @@ -17,7 +18,7 @@ from pathlib import Path from cortex.config import cortex_home NATS_BIN = str(Path.home() / "bin" / "nats") -OLLAMA_URL = "http://desktop01:11434/api/generate" +OLLAMA_URL = os.environ.get("DARKPLEX_LLM_URL", "http://localhost:11434/api/generate") STREAM = "openclaw-events" SUMMARY_PROMPT = """You are a personal assistant summarizing a day's conversations.