fix(opencode-plugin): bind git sync and tools to the active worktree - #48
Merged
Merged
Conversation
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>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
Part of #46 (item: plugin binds to
ctx.project.worktreeinstead of the active worktree).OpenCode persists
project.worktreethe first time a project is opened and never updates it for that project, while the active checkout is provided separately asctx.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 agit worktree addsetup,ctx.project.worktreecan 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:
HEADinto the sandbox, andopencode/Nbranch.Changes
plugins/session-events.ts: bind session event handling toctx.worktreeplugins/custom-tools.ts: bind sandbox tools toctx.worktreePersisted session state is unaffected:
ProjectDataStorage.updateSessionalready refreshes the stored worktree on every call, andopencode/Nbranch allocation operates on refs in the shared git common dir, so numbering stays unique across linked worktrees.Testing
tsc --noEmitclean;npm run buildcovered by CISummary 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.worktreeand land in the active checkout.packages/opencode-plugin/.opencode/plugin/daytona/plugins/session-events.tsandpackages/opencode-plugin/.opencode/plugin/daytona/plugins/custom-tools.ts: both readctx.worktreeinstead ofctx.project.worktree.git worktree addsetup, confirm sandbox setup pushes the active checkout’sHEADand idle-time syncs update the active checkout’sopencode/Nbranch.opencode/Nnumbering stays unique via refs in the shared git common dir.Written for commit bdd9d56. Summary will update on new commits.