Skip to content

Commit cd2d6ca

Browse files
authored
feat(core-engineering)!: rewrite worktrees, consolidate code-reviewer (#56)
## Summary - Rewrites `using-git-worktrees` and `finishing-a-development-branch` with environment detection (`GIT_DIR != GIT_COMMON`), consent gate before creating worktrees, native-tool preference (defers to `EnterWorktree`-style harness commands), and provenance-based cleanup that only removes worktrees this skill created - Consolidates the `code-reviewer` named agent into the `requesting-code-review` skill template — the persona/checklist was duplicated and the two files could drift - Drops the leaked "review every 3 tasks" cadence (it was meant for `executing-plans`, not `subagent-driven-development`) and removes vestigial `## Integration` sections from four skills ## Breaking change Removes the `core-engineering:code-reviewer` named agent. Callers should dispatch `Task(general-purpose)` with the template at `skills/requesting-code-review/code-reviewer.md` instead.
1 parent 4601b00 commit cd2d6ca

13 files changed

Lines changed: 335 additions & 349 deletions

File tree

core-engineering/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ There's a bunch more to it, but that's the core of the system. And because the s
5959

6060
### Agents
6161

62-
- **code-reviewer** - Reviews completed work against the original plan and coding standards
6362
- **dependency-manager** - Vulnerability scanning, version conflict resolution, and bundle optimization
6463
- **documentation-specialist** - API docs, tutorials, architecture guides, and documentation audits
6564
- **git-workflow-manager** - Branching strategies, release automation, and merge conflict resolution

core-engineering/agents/code-reviewer.md

Lines changed: 0 additions & 53 deletions
This file was deleted.

core-engineering/skills/executing-plans/SKILL.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,3 @@ After all tasks complete and verified:
6161
- Reference skills when plan says to
6262
- Stop when blocked, don't guess
6363
- Never start implementation on main/master branch without explicit user consent
64-
65-
## Integration
66-
67-
**Required workflow skills:**
68-
- **core-engineering:using-git-worktrees** - REQUIRED: Set up isolated workspace before starting
69-
- **core-engineering:writing-plans** - Creates the plan this skill executes
70-
- **core-engineering:finishing-a-development-branch** - Complete development after all tasks

core-engineering/skills/finishing-a-development-branch/SKILL.md

Lines changed: 120 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description: Use when implementation is complete, all tests pass, and you need t
99

1010
Guide completion of development work by presenting clear options and handling chosen workflow.
1111

12-
**Core principle:** Verify tests → Present options → Execute choice → Clean up.
12+
**Core principle:** Verify tests → Detect environment → Present options → Execute choice → Clean up.
1313

1414
**Announce at start:** "I'm using the finishing-a-development-branch skill to complete this work."
1515

@@ -25,6 +25,7 @@ npm test / cargo test / pytest / go test ./...
2525
```
2626

2727
**If tests fail:**
28+
2829
```
2930
Tests failing (<N> failures). Must fix before completing:
3031
@@ -37,7 +38,24 @@ Stop. Don't proceed to Step 2.
3738

3839
**If tests pass:** Continue to Step 2.
3940

40-
### Step 2: Determine Base Branch
41+
### Step 2: Detect Environment
42+
43+
**Determine workspace state before presenting options:**
44+
45+
```bash
46+
GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
47+
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
48+
```
49+
50+
This determines which menu to show and how cleanup works:
51+
52+
| State | Menu | Cleanup |
53+
|-------|------|---------|
54+
| `GIT_DIR == GIT_COMMON` (normal repo) | Standard 4 options | No worktree to clean up |
55+
| `GIT_DIR != GIT_COMMON`, named branch | Standard 4 options | Provenance-based (see Step 6) |
56+
| `GIT_DIR != GIT_COMMON`, detached HEAD | Reduced 3 options (no merge) | No cleanup (externally managed) |
57+
58+
### Step 3: Determine Base Branch
4159

4260
```bash
4361
# Try common base branches
@@ -46,9 +64,9 @@ git merge-base HEAD main 2>/dev/null || git merge-base HEAD master 2>/dev/null
4664

4765
Or ask: "This branch split from main - is that correct?"
4866

49-
### Step 3: Present Options
67+
### Step 4: Present Options
5068

51-
Present exactly these 4 options:
69+
**Normal repo and named-branch worktree — present exactly these 4 options:**
5270

5371
```
5472
Implementation complete. What would you like to do?
@@ -61,30 +79,58 @@ Implementation complete. What would you like to do?
6179
Which option?
6280
```
6381

82+
**Detached HEAD — present exactly these 3 options:**
83+
84+
```
85+
Implementation complete. You're on a detached HEAD (externally managed workspace).
86+
87+
1. Push as new branch and create a Pull Request
88+
2. Keep as-is (I'll handle it later)
89+
3. Discard this work
90+
91+
Which option?
92+
```
93+
6494
**Don't add explanation** - keep options concise.
6595

66-
### Step 4: Execute Choice
96+
**Detached-HEAD option mapping for Step 5/6:**
97+
98+
| Detached HEAD | Standard equivalent | Execution | Cleanup (Step 6) |
99+
|---------------|---------------------|-----------|------------------|
100+
| 1. Push + PR | Standard Option 2 | Create branch from HEAD, then standard Option 2 flow | Skip — externally managed |
101+
| 2. Keep as-is | Standard Option 3 | Standard Option 3 flow | Skip — externally managed |
102+
| 3. Discard | Standard Option 4 | Standard Option 4 flow, but no branch to delete | Skip — externally managed |
103+
104+
The host environment owns the workspace in detached HEAD mode, so Step 6 never removes the worktree regardless of which option the user picks.
105+
106+
### Step 5: Execute Choice
67107

68108
#### Option 1: Merge Locally
69109

70110
```bash
71-
# Switch to base branch
72-
git checkout <base-branch>
111+
# Capture worktree path BEFORE leaving it — Step 6 cleanup needs this
112+
WORKTREE_PATH=$(git rev-parse --show-toplevel)
73113

74-
# Pull latest
75-
git pull
114+
# Get main repo root for CWD safety
115+
MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel)
116+
cd "$MAIN_ROOT"
76117

77-
# Merge feature branch
118+
# Merge first — verify success before removing anything
119+
git checkout <base-branch>
120+
git pull
78121
git merge <feature-branch>
79122

80123
# Verify tests on merged result
81124
<test command>
82125

83-
# If tests pass
84-
git branch -d <feature-branch>
126+
# Only after merge succeeds: cleanup worktree (Step 6), then delete branch
85127
```
86128

87-
Then: Cleanup worktree (Step 5)
129+
Then: Cleanup worktree (Step 6), then delete branch:
130+
131+
```bash
132+
git branch -d <feature-branch>
133+
```
88134

89135
#### Option 2: Push and Create PR
90136

@@ -103,7 +149,7 @@ EOF
103149
)"
104150
```
105151

106-
Then: Cleanup worktree (Step 5)
152+
**Do NOT clean up worktree** — user needs it alive to iterate on PR feedback.
107153

108154
#### Option 3: Keep As-Is
109155

@@ -114,6 +160,7 @@ Report: "Keeping branch <name>. Worktree preserved at <path>."
114160
#### Option 4: Discard
115161

116162
**Confirm first:**
163+
117164
```
118165
This will permanently delete:
119166
- Branch <name>
@@ -126,53 +173,88 @@ Type 'discard' to confirm.
126173
Wait for exact confirmation.
127174

128175
If confirmed:
176+
177+
```bash
178+
# Capture worktree path BEFORE leaving it — Step 6 cleanup needs this
179+
WORKTREE_PATH=$(git rev-parse --show-toplevel)
180+
181+
MAIN_ROOT=$(git -C "$(git rev-parse --git-common-dir)/.." rev-parse --show-toplevel)
182+
cd "$MAIN_ROOT"
183+
```
184+
185+
Then: Cleanup worktree (Step 6), then force-delete branch:
186+
129187
```bash
130-
git checkout <base-branch>
131188
git branch -D <feature-branch>
132189
```
133190

134-
Then: Cleanup worktree (Step 5)
191+
### Step 6: Cleanup Workspace
135192

136-
### Step 5: Cleanup Worktree
193+
**Only runs for Options 1 and 4.** Options 2 and 3 always preserve the worktree.
137194

138-
**For Options 1, 2, 4:**
195+
`WORKTREE_PATH` was captured in Step 5 before the `cd "$MAIN_ROOT"`. Re-derive
196+
environment state from the original worktree path (not the current CWD):
139197

140-
Check if in worktree:
141198
```bash
142-
git worktree list | grep $(git branch --show-current)
199+
ORIG_GIT_DIR=$(cd "$WORKTREE_PATH" && git rev-parse --git-dir 2>/dev/null)
200+
ORIG_GIT_COMMON=$(cd "$WORKTREE_PATH" && git rev-parse --git-common-dir 2>/dev/null)
143201
```
144202

145-
If yes:
203+
**If `ORIG_GIT_DIR == ORIG_GIT_COMMON`:** The original workspace was the main checkout, not a linked worktree. No worktree to clean up. Done.
204+
205+
**If `$WORKTREE_PATH` is under `.worktrees/`, `worktrees/`, or `~/.config/skills/worktrees/`:** This skill created the worktree — we own cleanup.
206+
146207
```bash
147-
git worktree remove <worktree-path>
208+
# CWD is already $MAIN_ROOT from Step 5
209+
git worktree remove "$WORKTREE_PATH"
210+
git worktree prune # Self-healing: clean up any stale registrations
148211
```
149212

150-
**For Option 3:** Keep worktree.
213+
**Otherwise:** The host environment (harness) owns this workspace. Do NOT remove it. If your platform provides a workspace-exit tool, use it. Otherwise, leave the workspace in place.
151214

152215
## Quick Reference
153216

154217
| Option | Merge | Push | Keep Worktree | Cleanup Branch |
155218
|--------|-------|------|---------------|----------------|
156-
| 1. Merge locally | | - | - | |
157-
| 2. Create PR | - | | | - |
158-
| 3. Keep as-is | - | - | | - |
159-
| 4. Discard | - | - | - | (force) |
219+
| 1. Merge locally | yes | - | - | yes |
220+
| 2. Create PR | - | yes | yes | - |
221+
| 3. Keep as-is | - | - | yes | - |
222+
| 4. Discard | - | - | - | yes (force) |
160223

161224
## Common Mistakes
162225

163226
**Skipping test verification**
227+
164228
- **Problem:** Merge broken code, create failing PR
165229
- **Fix:** Always verify tests before offering options
166230

167231
**Open-ended questions**
168-
- **Problem:** "What should I do next?" → ambiguous
169-
- **Fix:** Present exactly 4 structured options
170232

171-
**Automatic worktree cleanup**
172-
- **Problem:** Remove worktree when might need it (Option 2, 3)
233+
- **Problem:** "What should I do next?" is ambiguous
234+
- **Fix:** Present exactly 4 structured options (or 3 for detached HEAD)
235+
236+
**Cleaning up worktree for Option 2**
237+
238+
- **Problem:** Remove worktree user needs for PR iteration
173239
- **Fix:** Only cleanup for Options 1 and 4
174240

241+
**Deleting branch before removing worktree**
242+
243+
- **Problem:** `git branch -d` fails because worktree still references the branch
244+
- **Fix:** Merge first, remove worktree, then delete branch
245+
246+
**Running git worktree remove from inside the worktree**
247+
248+
- **Problem:** Command fails silently when CWD is inside the worktree being removed
249+
- **Fix:** Always `cd` to main repo root before `git worktree remove`
250+
251+
**Cleaning up harness-owned worktrees**
252+
253+
- **Problem:** Removing a worktree the harness created causes phantom state
254+
- **Fix:** Only clean up worktrees under `.worktrees/`, `worktrees/`, or `~/.config/skills/worktrees/`
255+
175256
**No confirmation for discard**
257+
176258
- **Problem:** Accidentally delete work
177259
- **Fix:** Require typed "discard" confirmation
178260

@@ -183,18 +265,15 @@ git worktree remove <worktree-path>
183265
- Merge without verifying tests on result
184266
- Delete work without confirmation
185267
- Force-push without explicit request
268+
- Remove a worktree before confirming merge success
269+
- Clean up worktrees you didn't create (provenance check)
270+
- Run `git worktree remove` from inside the worktree
186271

187272
**Always:**
188273
- Verify tests before offering options
189-
- Present exactly 4 options
274+
- Detect environment before presenting menu
275+
- Present exactly 4 options (or 3 for detached HEAD)
190276
- Get typed confirmation for Option 4
191277
- Clean up worktree for Options 1 & 4 only
192-
193-
## Integration
194-
195-
**Called by:**
196-
- **subagent-driven-development** (Step 7) - After all tasks complete
197-
- **executing-plans** (Step 5) - After all batches complete
198-
199-
**Pairs with:**
200-
- **using-git-worktrees** - Cleans up worktree created by that skill
278+
- `cd` to main repo root before worktree removal
279+
- Run `git worktree prune` after removal

core-engineering/skills/requesting-code-review/SKILL.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Use when completing tasks, implementing major features, or before m
55

66
# Requesting Code Review
77

8-
Dispatch core-engineering:code-reviewer subagent to catch issues before they cascade. The reviewer gets precisely crafted context for evaluation — never your session's history. This keeps the reviewer focused on the work product, not your thought process, and preserves your own context for continued work.
8+
Dispatch a code reviewer subagent to catch issues before they cascade. The reviewer gets precisely crafted context for evaluation — never your session's history. This keeps the reviewer focused on the work product, not your thought process, and preserves your own context for continued work.
99

1010
**Core principle:** Review early, review often.
1111

@@ -29,16 +29,15 @@ BASE_SHA=$(git rev-parse HEAD~1) # or origin/main
2929
HEAD_SHA=$(git rev-parse HEAD)
3030
```
3131

32-
**2. Dispatch code-reviewer subagent:**
32+
**2. Dispatch code reviewer subagent:**
3333

34-
Use Task tool with core-engineering:code-reviewer, fill template at `code-reviewer.md`
34+
Use Task tool with `general-purpose` type, fill template at `code-reviewer.md`
3535

3636
**Placeholders:**
37-
- `{WHAT_WAS_IMPLEMENTED}` - What you just built
37+
- `{DESCRIPTION}` - Brief summary of what you built
3838
- `{PLAN_OR_REQUIREMENTS}` - What it should do
3939
- `{BASE_SHA}` - Starting commit
4040
- `{HEAD_SHA}` - Ending commit
41-
- `{DESCRIPTION}` - Brief summary
4241

4342
**3. Act on feedback:**
4443
- Fix Critical issues immediately
@@ -56,12 +55,11 @@ You: Let me request code review before proceeding.
5655
BASE_SHA=$(git log --oneline | grep "Task 1" | head -1 | awk '{print $1}')
5756
HEAD_SHA=$(git rev-parse HEAD)
5857
59-
[Dispatch core-engineering:code-reviewer subagent]
60-
WHAT_WAS_IMPLEMENTED: Verification and repair functions for conversation index
58+
[Dispatch code reviewer subagent]
59+
DESCRIPTION: Added verifyIndex() and repairIndex() with 4 issue types
6160
PLAN_OR_REQUIREMENTS: Task 2 from docs/plans/deployment-plan.md
6261
BASE_SHA: a7981ec
6362
HEAD_SHA: 3df7661
64-
DESCRIPTION: Added verifyIndex() and repairIndex() with 4 issue types
6563
6664
[Subagent returns]:
6765
Strengths: Clean architecture, real tests
@@ -82,7 +80,7 @@ You: [Fix progress indicators]
8280
- Fix before moving to next task
8381

8482
**Executing Plans:**
85-
- Review after each batch (3 tasks)
83+
- Review after each task or at natural checkpoints
8684
- Get feedback, apply, continue
8785

8886
**Ad-Hoc Development:**

0 commit comments

Comments
 (0)