fix(do): reuse worktree across phases via DO_WORKTREE_DIR env var

Previously, each codeagent-wrapper --worktree call created a new worktree,
causing multiple worktrees per /do task (one per phase).

Changes:
- setup-do.py: create worktree at initialization, export DO_WORKTREE_DIR
- executor.go: check DO_WORKTREE_DIR first, reuse if set
- SKILL.md: update documentation for new behavior

Generated with SWE-Agent.ai

Co-Authored-By: SWE-Agent.ai <noreply@swe-agent.ai>
This commit is contained in:
cexll
2026-02-05 23:32:52 +08:00
parent 81fa6843d9
commit 5853539cab
3 changed files with 53 additions and 5 deletions

View File

@@ -941,8 +941,13 @@ func RunCodexTaskWithContext(parentCtx context.Context, taskSpec TaskSpec, backe
cfg.WorkDir = defaultWorkdir
}
// Handle worktree mode: create a new git worktree and update cfg.WorkDir
if taskSpec.Worktree {
// Handle worktree mode: check DO_WORKTREE_DIR env var first, then create if needed
if worktreeDir := os.Getenv("DO_WORKTREE_DIR"); worktreeDir != "" {
// Use existing worktree from /do setup
cfg.WorkDir = worktreeDir
logInfo(fmt.Sprintf("Using existing worktree from DO_WORKTREE_DIR: %s", worktreeDir))
} else if taskSpec.Worktree {
// Create new worktree (backward compatibility for standalone --worktree usage)
paths, err := createWorktreeFn(cfg.WorkDir)
if err != nil {
result.ExitCode = 1