Skip to content

Commit ccb3283

Browse files
committed
Improve harness: worktree tracking, completion gate, pwd reporting
- Add pwd/branch reporting at harness start so caller knows the working directory - Add Completion Gate with git status check to prevent uncommitted changes from being left behind - Skill Step 2B reuses existing worktree if PR branch is already checked out, instead of always creating a new one - Step 3 requires main agent to record worktree→PR mapping for directing future operations to the correct directory Signed-off-by: Heng Qian <qianheng@amazon.com>
1 parent d41e598 commit ccb3283

3 files changed

Lines changed: 78 additions & 1 deletion

File tree

.claude/commands/ppl-bugfix.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,33 @@ Agent(
8383

8484
### 2B: Follow-up
8585

86+
Before dispatching, check if an existing worktree already has the PR branch checked out:
87+
88+
```bash
89+
# List worktrees and find one on the PR branch
90+
for wt in .claude/worktrees/agent-*/; do
91+
branch=$(git -C "$wt" branch --show-current 2>/dev/null)
92+
if [ "$branch" = "<pr_branch>" ]; then
93+
echo "REUSE: $wt (branch: $branch)"
94+
fi
95+
done
96+
```
97+
98+
**If existing worktree found**: Do NOT use `isolation: "worktree"`. Pass the worktree path in the prompt so the subagent works there directly.
99+
100+
```
101+
Agent(
102+
mode: "<resolved_mode>",
103+
name: "bugfix-<issue_number>",
104+
description: "PPL bugfix #<issue_number> followup",
105+
prompt: "cd <worktree_path> first, then read .claude/harness/ppl-bugfix-followup.md and follow it.
106+
PR: <pr_number> (<pr_url>), Issue: #<issue_number>
107+
Working directory: <worktree_path>"
108+
)
109+
```
110+
111+
**If no existing worktree**: Create a new one.
112+
86113
```
87114
Agent(
88115
mode: "<resolved_mode>",
@@ -100,6 +127,16 @@ After all subagents complete, report a summary for each:
100127
- Classification, fix summary, PR URL, worktree path and branch, items needing human attention (2A)
101128
- What was addressed, current PR state, whether another round is needed (2B)
102129

130+
**Always include the worktree→PR mapping** from the subagent's output, e.g.:
131+
132+
```
133+
Worktree: /path/to/.claude/worktrees/agent-xxxx
134+
Branch: bugfix-1234
135+
PR: #5678
136+
```
137+
138+
**Important**: After reporting, the main agent must remember this mapping. When the user later asks to make changes to the PR (e.g., "commit this to PR #5678"), operate in the worktree directory — not the main session directory.
139+
103140
## Subagent Lifecycle
104141

105142
Subagents are task-scoped. They complete and release context — they cannot poll for events.

.claude/harness/ppl-bugfix-followup.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@
66

77
---
88

9+
## Report Working Directory
10+
11+
```bash
12+
echo "Worktree: $(pwd)"
13+
echo "Branch: $(git branch --show-current)"
14+
```
15+
16+
Include this in your output so the caller knows where changes are happening.
17+
918
## Reconstruct Context
1019

11-
The follow-up agent runs in a fresh worktree. First checkout the PR branch, then load state:
20+
First checkout the PR branch, then load state:
1221

1322
```bash
1423
# Checkout the PR branch in this worktree
@@ -101,3 +110,16 @@ For each comment addressed (bot or human):
101110
- **Did the follow-up workflow itself miss this signal?** → Update this file
102111

103112
If any improvement is needed, make the edit and include it in the same commit.
113+
114+
## Completion Gate
115+
116+
Before reporting "done":
117+
118+
1. Run `git status --porcelain` — if any uncommitted changes remain, commit and push them. This includes harness edits from Retrospective.
119+
2. Report in your final output:
120+
121+
```
122+
Worktree: <absolute path>
123+
Branch: <branch name>
124+
PR: <pr_number>
125+
```

.claude/harness/ppl-bugfix-harness.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## Phase 0: Triage
44

5+
### 0.0 Report Working Directory
6+
7+
```bash
8+
echo "Worktree: $(pwd)"
9+
echo "Branch: $(git branch --show-current)"
10+
```
11+
12+
Include this in your output so the caller knows where changes are happening.
13+
514
### 0.1 Load & Reproduce
615

716
```bash
@@ -126,6 +135,8 @@ EOF
126135

127136
## Completion Gate
128137

138+
Run `git status --porcelain` — if any uncommitted changes remain, commit and push them before proceeding.
139+
129140
Do NOT report "done" until every item below is checked. List each in your final report:
130141

131142
- [ ] **Unit tests**: New test class or methods
@@ -149,3 +160,10 @@ If any item is blocked, report which and why.
149160
- [ ] New pattern? Add to Case Index.
150161

151162
Include harness improvements in the same PR.
163+
164+
Report in your final output:
165+
```
166+
Worktree: <absolute path>
167+
Branch: <branch name>
168+
PR: <pr_number>
169+
```

0 commit comments

Comments
 (0)