Parent Epic
Part of #52 — Parallel stacked workstreams
Summary
Add a cwd parameter to run_agent() so the copilot agent runs inside a git worktree directory instead of the repo root. Update all prompts to stop instructing the agent to create branches (the worktree already has the branch checked out).
Context
Today, run_agent() in agent.py does not pass cwd to subprocess.Popen(), so the agent inherits the orchestrator's working directory. With git worktrees, each task gets its own directory — the agent must run inside it.
Additionally, prompts currently tell the agent to git checkout -b <branch>, which is wrong in a worktree context (the branch already exists).
Changes
agent.py
- Add
cwd parameter to run_agent() signature
- Pass
cwd=cwd to subprocess.Popen()
- Default to
None (current behavior) for backward compatibility
orchestrator.py
BaseOrchestrator stores worktree path (from task record)
- Pass
cwd=self.worktree_path to run_agent() calls in _run_agent_with_retry()
_get_workspace_dirs() updated to scan from worktree path, not os.getcwd()
- Fix
os.getcwd() usage in _do_resolve_comments() for .autopilot-fix-summary.json path
prompts.py
implement_prompt(): Remove git checkout -b instruction when worktree is active; add You are already on branch <branch> context
implement_on_existing_branch_prompt(): Same adjustment
plan_and_implement_prompt(): Same adjustment
- Replace hardcoded
git diff main with git diff <base_branch> (uses get_default_branch())
persistence.py
- Add
worktree_path column to tasks table (nullable TEXT)
- Schema version bump + migration
Depends On
Testing
run_agent() with cwd parameter passes it to subprocess
- Prompts omit
git checkout -b when worktree context is set
- Orchestrator reads worktree path from task record
.autopilot-fix-summary.json read from worktree path, not os.getcwd()
Parent Epic
Part of #52 — Parallel stacked workstreams
Summary
Add a
cwdparameter torun_agent()so the copilot agent runs inside a git worktree directory instead of the repo root. Update all prompts to stop instructing the agent to create branches (the worktree already has the branch checked out).Context
Today,
run_agent()inagent.pydoes not passcwdtosubprocess.Popen(), so the agent inherits the orchestrator's working directory. With git worktrees, each task gets its own directory — the agent must run inside it.Additionally, prompts currently tell the agent to
git checkout -b <branch>, which is wrong in a worktree context (the branch already exists).Changes
agent.pycwdparameter torun_agent()signaturecwd=cwdtosubprocess.Popen()None(current behavior) for backward compatibilityorchestrator.pyBaseOrchestratorstores worktree path (from task record)cwd=self.worktree_pathtorun_agent()calls in_run_agent_with_retry()_get_workspace_dirs()updated to scan from worktree path, notos.getcwd()os.getcwd()usage in_do_resolve_comments()for.autopilot-fix-summary.jsonpathprompts.pyimplement_prompt(): Removegit checkout -binstruction when worktree is active; addYou are already on branch <branch>contextimplement_on_existing_branch_prompt(): Same adjustmentplan_and_implement_prompt(): Same adjustmentgit diff mainwithgit diff <base_branch>(usesget_default_branch())persistence.pyworktree_pathcolumn to tasks table (nullable TEXT)Depends On
Testing
run_agent()withcwdparameter passes it to subprocessgit checkout -bwhen worktree context is set.autopilot-fix-summary.jsonread from worktree path, notos.getcwd()