Skip to content

Conversation

@ethanndickson
Copy link
Member

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 WorktreeRuntime and the upcoming DevcontainerRuntime.

Context

The Devcontainer runtime will need to:

  1. Create git worktrees on the host (same as WorktreeRuntime)
  2. Build/start a devcontainer from the worktree
  3. Execute commands inside the container (different from WorktreeRuntime)

To enable this, we need the worktree creation logic to be reusable. This PR extracts it into a standalone WorktreeManager class.

Changes

WorktreeManager extraction:

  • New src/node/worktree/WorktreeManager.ts containing all worktree operations:
    • getWorkspacePath - compute workspace path from project + branch
    • createWorkspace - create git worktree with branch
    • renameWorkspace - move worktree and rename branch
    • deleteWorkspace - remove worktree and optionally delete branch
    • forkWorkspace - create new worktree from existing branch

WorktreeRuntime simplification:

  • Now a thin delegator that composes WorktreeManager
  • Retains initWorkspace (runs .mux/init hook) which is runtime-specific

Flag rename:

  • deferredHostdeferredRuntimeAccess for clarity (runtime access is deferred until postCreateSetup completes, e.g., Coder workspace startup)

DevcontainerRuntime shell:

  • Added as dead code (not wired into runtimeFactory)
  • Composes WorktreeManager for worktree operations
  • Stub initWorkspace - will build/start container in Phase 2
  • Sets deferredRuntimeAccess: true (container not available until built)

Test reorganization:

  • WorktreeManager.test.ts - tests worktree logic directly (tilde expansion, delete behaviors)
  • LocalBaseRuntime.test.ts - tests resolvePath with minimal test subclass
  • Removed WorktreeRuntime.test.ts (now a thin delegator, logic tested via WorktreeManager)

Verification

  • make static-check passes
  • All existing tests pass
  • No behavior changes (WorktreeRuntime delegates to same logic)

Generated with mux • Model: anthropic:claude-opus-4-5 • Thinking: high • Cost: $4.79

Phase 1 prep for Devcontainer runtime support:

- Extract worktree logic into WorktreeManager (getWorkspacePath,
  createWorkspace, renameWorkspace, deleteWorkspace, forkWorkspace)
- WorktreeRuntime now delegates all worktree operations to WorktreeManager
- Rename deferredHost flag to deferredRuntimeAccess for clarity
- Add DevcontainerRuntime shell (not wired into factory yet)
- Move tests: WorktreeManager.test.ts for worktree logic,
  LocalBaseRuntime.test.ts for resolvePath

No behavior changes - pure refactor to enable code reuse.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant