SESSION 12

Worktree + Task Isolation 工作树隔离

按目录隔离,按任务 ID 协调 — Directory Isolation, Task ID Coordination

CONTROL PLANE (.tasks/ directory) task_auth_001.json id: "auth_001" status: "in_progress" worktree: "wt/auth" owner: "alice" task_perf_002.json id: "perf_002" status: "in_progress" worktree: "wt/perf" owner: "bob" task_test_003.json id: "test_003" status: "pending" worktree: null owner: null task_id binding: task.worktree = worktree_path | task.owner = agent_id BINDING unbound EXECUTION PLANE (.worktrees/ directory) wt/auth branch: wt/auth src/ package.json tests/ auth.ts worktree_run(auth_001) wt/perf branch: wt/perf src/ benchmark/ tests/ perf.ts worktree_run(perf_002) main repo branch: main full codebase .tasks/ .team/ lead agent operates here isolated copy isolated copy EventBus append-only JSONL CREATED auth_001 wt/auth BOUND auth_001 -> alice STARTED auth_001 run CREATED perf_002 wt/perf BOUND perf_002 -> bob STARTED perf_002 run COMMIT auth_001 fix-login COMPLETE auth_001 success REMOVED auth_001 wt/auth ... lifecycle observability Worktree Lifecycle create bind run test commit keep remove worktree_run: cd $worktree_dir && execute agent loop in isolated directory No file conflicts. No branch conflicts. Each agent has its own complete code copy.
CONCEPT 01

目录 = 隔离 Directory = Isolation

每个 worktree 是 git 仓库的独立代码副本。不同 Agent 在不同目录工作,互不干扰,无文件冲突,无分支竞争。

CONCEPT 02

任务 ID = 协调 Task ID = Coordination

通过 task_id 关联任务(控制平面)和 worktree(执行平面)。任务 JSON 记录 worktree 路径和 owner,实现跨平面追踪。

CONCEPT 03

事件总线 Event Bus

所有 worktree 生命周期事件写入 append-only JSONL 文件。CREATEDBOUNDSTARTEDCOMMITCOMPLETEREMOVED 等事件提供完整可观测性。

CONCEPT 04

完整工作流 Full Workflow

create 创建 worktree,bind 绑定任务,run 执行代码,test 验证,commit 提交,最后 keep(保留分支)或 remove(清理)。

试一试 Try It Out

1

"为后端身份验证和前端登录页面创建任务,然后列出任务。"

"Create tasks for backend auth and frontend login page, then list tasks."

2

"为任务 1 创建 worktree 'auth-refactor',为任务 2 创建 worktree 'ui-login'。"

"Create worktree 'auth-refactor' for task 1, then bind task 2 to a new worktree 'ui-login'."

3

"在 worktree 'auth-refactor' 中运行 'git status --short'。"

"Run 'git status --short' in worktree 'auth-refactor'."

4

"保留 worktree 'ui-login',然后列出 worktree 并检查事件。"

"Keep worktree 'ui-login', then list worktrees and inspect events."

5

"使用 complete_task=true 删除 worktree 'auth-refactor',然后列出任务/worktree/事件。"

"Remove worktree 'auth-refactor' with complete_task=true, then list tasks/worktrees/events."