Skip to content

Conversation

@MikeeBuilds
Copy link
Owner

Summary

Implements isolated Git worktrees for each agent task, enabling safe parallel execution without conflicts.

Features

  • Worktree Creation: Each task with a \ ask_id\ gets its own worktree in .worktrees/task-XXX/\
  • Branch Isolation: Each worktree has its own branch \squadron/task-XXX\
  • Merge/Discard: Tasks can be finalized by merging to main or discarding
  • API Endpoints: Dashboard can manage worktrees via REST API

Files Changed

[NEW] \squadron/services/worktree.py\

Core worktree management module with:

  • \create_worktree(task_id)\ - Create isolated worktree + branch
  • \cleanup_worktree(task_id, merge)\ - Remove worktree, optionally merge
  • \get_worktree_path(task_id)\ - Check if worktree exists
  • \list_worktrees()\ - List all active worktrees

[MODIFY] \squadron/swarm/agent.py\

  • Creates worktree at task start when \ ask_id\ in context
  • Executes in isolated directory
  • Returns to original directory on completion

[MODIFY] \squadron/swarm/overseer.py\

  • \ inalize_task()\ - Merge or discard task worktree
  • \list_worktrees()\ - Get active worktrees for dashboard

[MODIFY] \squadron/server.py\

  • \POST /tasks/{task_id}/finalize\ - Merge or discard worktree
  • \GET /worktrees\ - List all active worktrees

Testing

✅ Tested create/cleanup cycle successfully:
\
Created: .worktrees/task-test-123
Worktrees: [{'path': '...', 'task_id': 'test-123'}]
Cleaned up, worktrees: []
\\

Closes #8

- Add squadron/services/worktree.py with core functions:
  - create_worktree() - Create isolated worktree + branch
  - cleanup_worktree() - Remove worktree, optionally merge to main
  - get_worktree_path() - Check if worktree exists
  - list_worktrees() - List all active worktrees

- Integrate into agent.py:
  - Creates worktree at task start when task_id provided
  - Executes in isolated directory
  - Returns to original directory on completion

- Add overseer.py methods:
  - finalize_task() - Merge or discard task worktree
  - list_worktrees() - Get active worktrees for dashboard

- Add API endpoints:
  - POST /tasks/{task_id}/finalize - Merge or discard worktree
  - GET /worktrees - List all active worktrees

Enables safe parallel agent execution without conflicts.
@MikeeBuilds MikeeBuilds merged commit 336f869 into main Dec 22, 2025
1 of 4 checks passed
@MikeeBuilds MikeeBuilds deleted the feature/issue-8-worktree-isolation branch December 22, 2025 23:21
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.

Implement Git worktree isolation for agent tasks (Safety & Parallelism)

2 participants