Skip to content

Migrate worktree and git logic from CLI to agent manager - #4643

Merged
marius-kilocode merged 12 commits into
mainfrom
worktree-migration
Jan 6, 2026
Merged

Migrate worktree and git logic from CLI to agent manager#4643
marius-kilocode merged 12 commits into
mainfrom
worktree-migration

Conversation

@marius-kilocode

Copy link
Copy Markdown
Collaborator

Summary

Moves git worktree creation and management from the CLI to the VSCode extension (AgentManagerProvider). This gives the extension full control over parallel mode sessions.

What Changed

  • New WorktreeManager - Handles worktree lifecycle (create, remove, commit, discover) in .kilocode/worktrees/
  • New AgentTaskRunner - Reusable pattern for agent-driven tasks (e.g., asking agent to commit with proper message, with timeout fallback)
  • Updated AgentManagerProvider - Creates worktrees before spawning CLI, passes worktree path as workspace
  • Updated CliArgsBuilder - Simplified; no longer handles worktree/parallel mode flags (CLI is now worktree-agnostic)
  • Session resumption - Properly reuses existing worktrees or recreates from branch when resuming parallel mode sessions

How It Works

  1. User starts parallel mode session
  2. Extension creates worktree in .kilocode/worktrees/{branch-name}/
  3. CLI spawns with worktree path as its workspace (CLI doesn't know it's a worktree)
  4. On "Finish", extension asks agent to commit changes, then cleans up worktree (keeps branch)
  5. On cancel/stop, worktree persists for later resumption

Implications

  • Worktrees stored in project directory (.kilocode/worktrees/) instead of temp
  • .gitignore entry added automatically to prevent accidental commits
  • CLI becomes simpler (no worktree awareness needed)
  • Extension has full visibility into worktree state for UI/resumption

@changeset-bot

changeset-bot Bot commented Dec 23, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 22bba9a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
kilo-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@marius-kilocode
marius-kilocode marked this pull request as ready for review January 6, 2026 14:34
@marius-kilocode marius-kilocode changed the title spike: migrate worktree and git logic from CLI to agent manager Migrate worktree and git logic from CLI to agent manager Jan 6, 2026
@kilo-code-bot

kilo-code-bot Bot commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

This PR successfully migrates worktree creation from the CLI to the extension for parallel mode sessions. The implementation is clean and well-structured.

Key Changes:

  • New WorktreeManager.ts - Handles git worktree creation, commit, and cleanup with proper error handling
  • New AgentTaskRunner.ts - Provides a reusable pattern for agent-driven tasks with timeout and fallback support
  • Modified AgentManagerProvider.ts - Integrates worktree management into session lifecycle
  • Modified CliProcessHandler.ts - Passes worktree info to sessions for state tracking
  • Modified CliArgsBuilder.ts - Removed --parallel and --existing-branch flags (CLI is now worktree-agnostic)
  • Updated types.ts - Added parentBranch to ParallelModeInfo

Strengths:

  • Good separation of concerns with dedicated WorktreeManager class
  • Proper error handling with custom WorktreeError class
  • Fallback mechanism for agent-driven commits (programmatic commit if agent times out)
  • Automatic .gitignore management for worktree directory
  • Comprehensive test coverage for new functionality
Files Reviewed (14 files)
  • .changeset/worktree-migration.md
  • apps/kilocode-docs/docs/advanced-usage/agent-manager.md
  • src/core/kilocode/agent-manager/AgentManagerProvider.ts
  • src/core/kilocode/agent-manager/AgentTaskRunner.ts
  • src/core/kilocode/agent-manager/CliArgsBuilder.ts
  • src/core/kilocode/agent-manager/CliOutputParser.ts
  • src/core/kilocode/agent-manager/CliProcessHandler.ts
  • src/core/kilocode/agent-manager/WorktreeManager.ts
  • src/core/kilocode/agent-manager/__tests__/AgentManagerProvider.spec.ts
  • src/core/kilocode/agent-manager/__tests__/AgentTaskRunner.test.ts
  • src/core/kilocode/agent-manager/__tests__/CliArgsBuilder.spec.ts
  • src/core/kilocode/agent-manager/__tests__/CliArgsBuilder.test.ts
  • src/core/kilocode/agent-manager/__tests__/WorktreeManager.test.ts
  • src/core/kilocode/agent-manager/types.ts

@marius-kilocode
marius-kilocode merged commit bf89c48 into main Jan 6, 2026
21 checks passed
@marius-kilocode
marius-kilocode deleted the worktree-migration branch January 6, 2026 15:29
slamj1 pushed a commit to slamj1/kilocode that referenced this pull request May 16, 2026
* spike: migrate worktree and git logic from CLI to agent manager

* chore: add changeset for worktree migration

* docs: document worktree location for parallel mode

* chore: increase agent commit timeout to 60s

* Simplify changeset

* fix: make WorktreeManager tests cross-platform compatible

- Add helper to normalize path separators for assertions
- Fix tests to handle both / and \ in paths (Windows vs Unix)
jliounis pushed a commit to jliounis/kilocode that referenced this pull request May 18, 2026
* spike: migrate worktree and git logic from CLI to agent manager

* chore: add changeset for worktree migration

* docs: document worktree location for parallel mode

* chore: increase agent commit timeout to 60s

* Simplify changeset

* fix: make WorktreeManager tests cross-platform compatible

- Add helper to normalize path separators for assertions
- Fix tests to handle both / and \ in paths (Windows vs Unix)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants