Skip to content

fix(opencode-plugin): bind git sync and tools to the active worktree - #48

Merged
mislavivanda merged 1 commit into
mainfrom
fix/opencode-plugin-active-worktree
Aug 14, 2026
Merged

fix(opencode-plugin): bind git sync and tools to the active worktree#48
mislavivanda merged 1 commit into
mainfrom
fix/opencode-plugin-active-worktree

Conversation

@mislavivanda

@mislavivanda mislavivanda commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Part of #46 (item: plugin binds to ctx.project.worktree instead of the active worktree).

OpenCode persists project.worktree the first time a project is opened and never updates it for that project, while the active checkout is provided separately as ctx.worktree (PluginInput.worktree). Because OpenCode derives the project ID from the git remote (or a marker in the git common dir), linked worktrees of the same repo share one project — so in a git worktree add setup, ctx.project.worktree can point at a previously opened checkout instead of the one the session is actually running in.

Before this change that stale path was used as the base for all host-side git operations, so:

  • sandbox setup pushed the wrong checkout's HEAD into the sandbox, and
  • idle-time syncs pulled sandbox commits into the wrong checkout's opencode/N branch.

Changes

  • plugins/session-events.ts: bind session event handling to ctx.worktree
  • plugins/custom-tools.ts: bind sandbox tools to ctx.worktree

Persisted session state is unaffected: ProjectDataStorage.updateSession already refreshes the stored worktree on every call, and opencode/N branch allocation operates on refs in the shared git common dir, so numbering stays unique across linked worktrees.

Testing

  • tsc --noEmit clean; npm run build covered by CI

Summary by cubic

Bind git sync and sandbox tools to the active worktree to target the checkout the session is running in. Previously they used the persisted project worktree and could operate on a different checkout in linked-worktree setups; now they use ctx.worktree and land in the active checkout.

  • Changes limited to packages/opencode-plugin/.opencode/plugin/daytona/plugins/session-events.ts and packages/opencode-plugin/.opencode/plugin/daytona/plugins/custom-tools.ts: both read ctx.worktree instead of ctx.project.worktree.
  • In a git worktree add setup, confirm sandbox setup pushes the active checkout’s HEAD and idle-time syncs update the active checkout’s opencode/N branch.
  • Persisted session state remains correct; opencode/N numbering stays unique via refs in the shared git common dir.
  • No migration actions required.

Written for commit bdd9d56. Summary will update on new commits.

Review in cubic

ctx.project.worktree is persisted the first time a project is opened and
never updated afterwards, while OpenCode provides the active checkout as
ctx.worktree. In linked-worktree setups (git worktree add) the two can
differ, so session git syncs could land in (and push from) a previously
opened checkout instead of the one the session is running in.

Bind session events and sandbox tools to ctx.worktree instead.

Fixes part of #46

Signed-off-by: Mislav Ivanda <mislavivanda454@gmail.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@mislavivanda
mislavivanda merged commit 2288e08 into main Aug 14, 2026
33 checks passed
@mislavivanda
mislavivanda deleted the fix/opencode-plugin-active-worktree branch August 14, 2026 14:16
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant