fix(agent-connector): run opencode in the configured working directory (#435)#559
Open
nolanchic wants to merge 1 commit into
Open
fix(agent-connector): run opencode in the configured working directory (#435)#559nolanchic wants to merge 1 commit into
nolanchic wants to merge 1 commit into
Conversation
opencode confines an agent's file access to its `--dir` worktree root; in
headless mode a tool call outside it is auto-rejected ("user rejected
permission"). The opencode adapter hardcoded `--dir`/`cwd` to the per-agent
scratch dir (agentHome) and ignored the configured `path` (workingDir), so
opencode ran in an empty dir and could never reach the project it was
created for.
Run opencode in the configured workingDir, falling back to agentHome when
none is set so pre-existing agents keep running where they always did.
Preflight now access-checks the resolved working dir and surfaces
cwd_unavailable (naming the configured path) when it is missing.
Because an opencode session ID is only resumable against the --dir it was
created under, scope the persisted session store per working dir
(sha256[:16], matching the goose and nanoclaw adapters) so a path change
can't poison a run with a stale, unresumable ID. The default (no workingDir)
keeps the legacy sessions.json so existing agents retain their context.
Closes openagents-org#435
|
@nolanchic is attempting to deploy a commit to the Raphael's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #435
agn create <name> --type opencode --path <project>ignored the configured path: the opencode adapter documentedopts.workingDirbut never used it, hardcoding--dirandcwdto the per-agent scratch dir (~/.openagents/agents/<name>).opencode confines an agent's file access to its
--dirworktree root, so in headless mode any read/edit tool call against a real project file is auto-rejected with "The user rejected permission to use this specific tool call." — on every platform, not only Windows.Fix
workingDir(both--dirand the spawncwd) via a new_resolveCwd()helper. When no path is configured it falls back toagentHome, so pre-existing agents keep running exactly where they always did.sessions-<sha256[:16]>.json). An opencode session ID is only resumable against the--dirit was created under, so without scoping a path change (or an agent that previously ran inagentHomegetting a path configured) would poison the next run with a stale ID that 404s. The default (noworkingDir) keeps the legacysessions.jsonso existing agents retain their context. Files always live underagentHome, never inside the project tree. This mirrors thesha256[:16]per-cwd idiom already used by the goose and nanoclaw adapters.cwd_unavailable(naming the configured path) when it is missing or unreadable, instead of silently running inagentHome.this.workingDiris already populated byBaseAdapterand passed bydaemon.js(workingDir: agentCfg.path || defaultAgentWorkdir(name)), so no daemon changes are needed — the adapter just had to use it.Test plan
node --test test/opencode-workingdir.test.js— 7/7 new tests pass. Covers_resolveCwd(configured vs fallback),--dir/cwdpassed to the real subprocess (asserted via achild_process.spawnshim installed before require, same pattern astest/aider.test.js), per-working-dir session-store scoping, and the preflightcwd_unavailable/pass cases.node --test test/opencode.test.js— existing 8.1–8.5 suites pass. (Two preflight credential tests are non-hermetic — they inspect the real home dir and fail when a real~/.config/opencode/opencode.jsonexists on the machine; identical failures occur ondevelop, unrelated to this change.)agn create demo --type opencode --path /path/to/project; connect to a workspace; @mention it to read or edit a project file and confirm the "user rejected permission" error is gone; send a second message in the same channel and confirm context is retained.