diff --git a/.agents/skills/multi-agent-mux-status/scripts/status.sh b/.agents/skills/multi-agent-mux-status/scripts/status.sh index ca66b6a..e3aea31 100755 --- a/.agents/skills/multi-agent-mux-status/scripts/status.sh +++ b/.agents/skills/multi-agent-mux-status/scripts/status.sh @@ -105,20 +105,10 @@ def resume_on_disk(s): if agent == 'opencode': u = s.get('opencode_session_id_own') if u: - base_dir = f"{home}/.local/share/opencode" - odb = None - for cand in [f"{base_dir}/opencode.db", f"{base_dir}/storage.db"]: - if os.path.exists(cand): - odb = cand - break - if not odb and os.path.isdir(f"{base_dir}/project"): - for root, _, files in os.walk(f"{base_dir}/project"): - for f in files: - if f.endswith(".db"): - odb = os.path.join(root, f) - break - if odb: - break + # the adapter's db: `opencode debug paths`, which follows XDG_DATA_HOME (Issue #60) + from lib_py.agents.registry import get_adapter + from lib_py.agents.base import DiscoveryContext + odb = get_adapter('opencode')._resolve_db(DiscoveryContext(workspace=cwd, agent_name='opencode', home_dir=home)) if not odb or not os.path.exists(odb): return 'MISSING' try: @@ -315,20 +305,10 @@ def resume_on_disk(s): if agent == 'opencode': u = s.get('opencode_session_id_own') if u: - base_dir = f"{home}/.local/share/opencode" - odb = None - for cand in [f"{base_dir}/opencode.db", f"{base_dir}/storage.db"]: - if os.path.exists(cand): - odb = cand - break - if not odb and os.path.isdir(f"{base_dir}/project"): - for root, _, files in os.walk(f"{base_dir}/project"): - for f in files: - if f.endswith(".db"): - odb = os.path.join(root, f) - break - if odb: - break + # the adapter's db: `opencode debug paths`, which follows XDG_DATA_HOME (Issue #60) + from lib_py.agents.registry import get_adapter + from lib_py.agents.base import DiscoveryContext + odb = get_adapter('opencode')._resolve_db(DiscoveryContext(workspace=cwd, agent_name='opencode', home_dir=home)) if not odb or not os.path.exists(odb): return 'MISSING' try: diff --git a/tests/_agent_home_guard.py b/tests/_agent_home_guard.py index 0b02d28..c57a7b0 100644 --- a/tests/_agent_home_guard.py +++ b/tests/_agent_home_guard.py @@ -18,7 +18,7 @@ import tempfile # The pane-inherited variables conftest._isolate_agent_homes drops for every # test, so HOME (which the tests set) governs, as it does in a plain shell. -DROPPED_VARS = ("HOME_DIR", "CLAUDE_PROJECT_DIR", "CLAUDE_CONFIG_DIR", "CODEX_HOME", "LOCAL_BIN") +DROPPED_VARS = ("HOME_DIR", "CLAUDE_PROJECT_DIR", "CLAUDE_CONFIG_DIR", "CODEX_HOME", "XDG_DATA_HOME", "LOCAL_BIN") # Read by the code under test but left alone, on purpose: HOME is where the # real herdr tests and the shim bootstrap find the server socket, and it is # what the suite's own tests set for an isolated home; XDG_CONFIG_HOME and @@ -45,7 +45,8 @@ def watch_dirs(ambient): for d in ("conversations", "cache", "brain", "annotations", "presence")] dirs += [("codex", os.path.join(codex, "sessions")), ("grok", os.path.join(home, ".grok", "sessions")), - ("opencode", os.path.join(home, ".local", "share", "opencode")), + ("opencode", os.path.join(ambient.get("XDG_DATA_HOME") or os.path.join(home, ".local", "share"), + "opencode")), ("hermes", os.path.join(home, ".hermes"))] return dirs diff --git a/tests/test_issue60_opencode_v2.py b/tests/test_issue60_opencode_v2.py index 17adc6d..7380fbc 100644 --- a/tests/test_issue60_opencode_v2.py +++ b/tests/test_issue60_opencode_v2.py @@ -291,8 +291,13 @@ def _real_opencode(): path = shutil.which("opencode") or os.path.expanduser("~/.opencode/bin/opencode") if not os.path.isfile(path): return None + import tempfile try: - out = subprocess.run([path, "--version"], capture_output=True, text=True, timeout=20).stdout + # Even --version writes opencode's log under its data dir: give it a + # home of its own (review 8a485fa0 N2). + with tempfile.TemporaryDirectory() as tmp: + env = {"PATH": os.environ.get("PATH", ""), "HOME": tmp, "TMPDIR": tmp} + out = subprocess.run([path, "--version"], capture_output=True, text=True, timeout=20, env=env).stdout except Exception: return None m = re.search(r"(\d+)\.\d+\.\d+", out)