fix(opencode): debug paths runs once per binary and home in a process (Issue #60, Linux item 6)
Every run appends a line to opencode's log, and one discover resolved the database once per candidate. A successful answer is kept per (binary, HOME, XDG_DATA_HOME) - the values the run sees; a failed run is not remembered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ac5f1154c7
commit
614ab1420f
2 files changed
+62
-1
No files matched your search
@@ -19,6 +19,9 @@ def _ro_connect(db: str):
|
||||
return sqlite3.connect(f"file:{quote(path)}?mode=ro" + ("" if both else "&immutable=1"), uri=True)
|
||||
|
||||
|
||||
# (binary, HOME, XDG_DATA_HOME) -> the db `debug paths` printed for them.
|
||||
_DB_PATHS = {}
|
||||
|
||||
_PROVIDER_ENV_VARS = (
|
||||
'ANTHROPIC_API_KEY',
|
||||
'OPENAI_API_KEY',
|
||||
@@ -126,13 +129,23 @@ class OpenCodeAgentAdapter(BaseAgentAdapter):
|
||||
def _resolve_db(self, ctx: DiscoveryContext) -> Optional[str]:
|
||||
# opencode 2.x prints its paths with `debug paths` (the 1.x `db path`
|
||||
# is gone: it prints the help and exits 0). Fallback: the default.
|
||||
# Each run writes a line to opencode's log, so a process asks once
|
||||
# per (binary, HOME, XDG_DATA_HOME) the run would see (Issue #60).
|
||||
bin_path = self._bin(ctx)
|
||||
if ctx.home_dir:
|
||||
key = (bin_path, ctx.home_dir, self._data_home(ctx))
|
||||
else:
|
||||
key = (bin_path, os.environ.get("HOME"), os.environ.get("XDG_DATA_HOME"))
|
||||
if bin_path and key in _DB_PATHS:
|
||||
return _DB_PATHS[key]
|
||||
try:
|
||||
res = self._run(ctx, ["debug", "paths"], timeout=5)
|
||||
if res is not None and res.returncode == 0:
|
||||
for line in res.stdout.splitlines():
|
||||
parts = line.split(None, 1)
|
||||
if len(parts) == 2 and parts[0] == "db":
|
||||
return parts[1].strip()
|
||||
_DB_PATHS[key] = parts[1].strip()
|
||||
return _DB_PATHS[key]
|
||||
except Exception:
|
||||
pass
|
||||
return os.path.join(self._data_home(ctx), "opencode", "opencode.db")
|
||||
|
||||
Reference in new issue
Block a user