fix(opencode): pass --dir to opencode so agents run in the worktree, not main repo#531
Open
jregeimbal wants to merge 1 commit into
Open
Conversation
d2adbe8 to
218049c
Compare
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.
Summary
When opencode is launched inside a git worktree, it follows the
.gitfile pointer back to the main repository root, causing all agent file operations to target the main repo instead of the isolated worktree. Passing--dir <worktree>prevents this gitdir resolution.Fixes #530.
Motivation
Worktree isolation exists to keep each cluster's changes sandboxed. opencode's internal git detection walks
.git(which in a worktree is a file likegitdir: /main/.git/worktrees/...) up to the main repo root, silently defeating the isolation — the agent reads and modifies files in the main repo rather than the worktree.The fix is to prefer
--dirover--cwdwhen opencode supports it. Unlike--cwd,--dirtells opencode explicitly which directory to treat as root and bypasses the gitdir pointer walk.Changes
src/agent-cli-provider/types.ts: AddsupportsDirtoOpencodeCliFeaturesandCliFeatureOverridessrc/agent-cli-provider/adapters/opencode.ts: Detect--dirindetectCliFeatures()via help text scan; inaddOpencodeOptionalArgs(), pass--dir <cwd>whensupportsDiris true, falling back to--cwdfor older opencode versions that lack the flagtests/provider-cli-builder.test.js: 5 new regression tests covering:--diris passed whensupportsDiris true (the fix)--cwdis used as fallback whensupportsDiris falsecommandSpec.cwdis always set regardless of CLI flag supportdetectCliFeaturescorrectly detectssupportsDirfrom help textdetectCliFeaturescorrectly rejectssupportsDirwhen--diris absentTesting
tests/provider-cli-builder.test.js— 5 new tests, all passing)Breaking Changes
None.
--diris only passed whendetectCliFeatures()confirms opencode supports it; older versions continue to receive--cwdas before.Checklist
npm test)npm run lint)npm run typecheck)