🤖 refactor: extract WorktreeManager for Devcontainer runtime prep #1770
+707
−530
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
Phase 1 prep for adding Devcontainer runtime support. This is a pure refactor with no behavior changes—extracting reusable worktree logic so it can be shared between
WorktreeRuntimeand the upcomingDevcontainerRuntime.Context
The Devcontainer runtime will need to:
WorktreeRuntime)WorktreeRuntime)To enable this, we need the worktree creation logic to be reusable. This PR extracts it into a standalone
WorktreeManagerclass.Changes
WorktreeManager extraction:
src/node/worktree/WorktreeManager.tscontaining all worktree operations:getWorkspacePath- compute workspace path from project + branchcreateWorkspace- create git worktree with branchrenameWorkspace- move worktree and rename branchdeleteWorkspace- remove worktree and optionally delete branchforkWorkspace- create new worktree from existing branchWorktreeRuntime simplification:
WorktreeManagerinitWorkspace(runs.mux/inithook) which is runtime-specificFlag rename:
deferredHost→deferredRuntimeAccessfor clarity (runtime access is deferred untilpostCreateSetupcompletes, e.g., Coder workspace startup)DevcontainerRuntime shell:
runtimeFactory)WorktreeManagerfor worktree operationsinitWorkspace- will build/start container in Phase 2deferredRuntimeAccess: true(container not available until built)Test reorganization:
WorktreeManager.test.ts- tests worktree logic directly (tilde expansion, delete behaviors)LocalBaseRuntime.test.ts- testsresolvePathwith minimal test subclassWorktreeRuntime.test.ts(now a thin delegator, logic tested via WorktreeManager)Verification
make static-checkpassesGenerated with
mux• Model:anthropic:claude-opus-4-5• Thinking:high• Cost:$4.79