Skip to content

Commit 2ef9b55

Browse files
jpicklykclaude
andauthored
feat(plugin): improve worktree reliability with hybrid hook + skill approach (#74)
* feat: add ktlint linting with Gradle integration, .editorconfig, and CI enforcement Add ktlint (v12.1.2, engine v1.5.0) via jlleitschuh/ktlint-gradle plugin for automated Kotlin code style enforcement. Includes .editorconfig with wildcard import allowlist, disabled trailing comma rules, and 140-char line limit. CI workflow gets a ktlintCheck step before tests. Applied ktlint formatting across ~108 source files (mechanical whitespace/blank line changes only). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: use HEX() for short UUID prefix lookup in SQLite CAST(blob AS VARCHAR) produces raw bytes in SQLite, not a formatted UUID string, causing prefix lookups to always return empty results. Switch to LOWER(HEX(id)) for SQLite and LOWER(RAWTOHEX(id)) for H2, which both produce dashless lowercase hex strings suitable for LIKE prefix matching. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: ktlint formatting for multiline expression in findByIdPrefix Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat(plugin): improve worktree reliability with hybrid hook + skill approach Enhance SubagentStart hook with "Subagent Discipline" section — universal rules for commit-before-return, stay-in-scope, and prefer-absolute-paths that fire for every subagent automatically. Add "Worktree Dispatch" section to output styles with pre-dispatch and post-return checklists, review agent worktree template, and squash-merge ordering guidance. Tighten implement skill: replace prose scoping rules with hook reference, add review-in-worktree copy-paste template, add test baseline management section for parallel dispatch contamination prevention. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dacc6e2 commit 2ef9b55

File tree

3 files changed

+68
-7
lines changed

3 files changed

+68
-7
lines changed

.claude/skills/implement/SKILL.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,18 @@ actual changes. Include in the review agent prompt:
187187
- Instruction: "Run all commands and read all files from within the worktree at
188188
`<worktree-path>`. Do NOT read files from the main working directory."
189189

190+
**Review agent worktree template (copy verbatim, fill placeholders):**
191+
192+
```
193+
You are reviewing implementation work in an isolated worktree.
194+
- Worktree path: <WORKTREE_PATH>
195+
- Branch: <BRANCH_NAME>
196+
- Changed files: <OUTPUT OF git -C <WORKTREE_PATH> diff main --name-only>
197+
198+
Run ALL commands from within the worktree at <WORKTREE_PATH>.
199+
Read ALL files from that directory. Do NOT read from the main working directory.
200+
```
201+
190202
**If NOT using worktree isolation**, the review agent reads from the current
191203
working branch as normal.
192204

@@ -370,12 +382,16 @@ Agent(
370382
)
371383
```
372384

373-
**Scoping rules — include in every worktree subagent prompt:**
374-
- "Only modify files directly related to your task"
375-
- "Do not bump versions, modify shared config, or edit files outside your scope"
376-
- "Commit your changes before returning"
377-
- Cross-cutting changes (version bumps, shared config) are handled by the
378-
orchestrator after all agents return
385+
**Scoping rules:** The `subagent-start` hook automatically injects commit, scope,
386+
and cd-discipline rules into every subagent. You do NOT need to include these in
387+
delegation prompts. Focus prompts on task-specific context:
388+
- Item UUID and what to implement
389+
- Which files to modify (explicit list when possible)
390+
- Test expectations
391+
- Return format
392+
393+
Cross-cutting changes (version bumps, shared config) are handled by the
394+
orchestrator after all agents return.
379395

380396
### Worktree lifecycle
381397

@@ -417,6 +433,20 @@ When multiple agents return from parallel worktrees:
417433
5. Run the full test suite after all merges to catch integration issues
418434
6. Delete worktree branches after successful squash-merge
419435

436+
### Test baseline management
437+
438+
When dispatching parallel worktree agents, check if any task modifies shared
439+
code (domain models, enums, database schema, test infrastructure). If so:
440+
441+
1. Dispatch the shared-code task **first** (not in parallel)
442+
2. After it returns, run `./gradlew :current:test` on main to establish a clean baseline
443+
3. **Then** dispatch the remaining independent tasks in parallel
444+
445+
**Symptom of contamination:** Multiple agents report "N pre-existing test
446+
failures unrelated to our changes" on the same tests. That's contamination
447+
from a parallel task, not pre-existing failures. Always verify agent test
448+
reports with a direct test run after all agents complete.
449+
420450
---
421451

422452
## Resuming In-Progress Work

claude-plugins/task-orchestrator/hooks/subagent-start.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ const output = {
2626
2727
6. **Return results.** Report: (1) files changed with line counts, (2) test results summary, (3) any blockers. Do not echo back the task description.
2828
29-
**CRITICAL:** Do NOT call \`advance_item(trigger="start")\` a second time — that would skip your phase. Do NOT call \`advance_item(trigger="complete")\` — the orchestrator handles terminal transitions.`
29+
**CRITICAL:** Do NOT call \`advance_item(trigger="start")\` a second time — that would skip your phase. Do NOT call \`advance_item(trigger="complete")\` — the orchestrator handles terminal transitions.
30+
31+
## Subagent Discipline
32+
33+
1. **Commit before returning.** After making all file changes, stage and commit with a descriptive message. The orchestrator needs committed changes to squash-merge your branch.
34+
2. **Stay in scope.** Only modify files directly related to your assigned task. Do NOT bump versions, modify shared config, edit CI files, or touch files outside your scope. Cross-cutting changes are handled by the orchestrator after all agents return.
35+
3. **Use absolute paths or \`git -C\` where possible.** If you are working in an isolated worktree, you may need to \`cd\` into the worktree path — that is fine. But avoid unnecessary \`cd <project-root> &&\` prefixes when your working directory is already correct.`
3036
}
3137
};
3238
process.stdout.write(JSON.stringify(output));

claude-plugins/task-orchestrator/output-styles/workflow-orchestrator.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,31 @@ After dispatching a subagent and receiving its return, optionally record delegat
7171

7272
This is orchestrator-side data that agents cannot self-report. The `/session-retrospective` skill uses it for delegation alignment analysis when present.
7373

74+
## Worktree Dispatch
75+
76+
When dispatching agents with `isolation: "worktree"`:
77+
78+
**Pre-dispatch checklist:**
79+
- Verify tasks are independent — no dependency edges between items dispatched in parallel
80+
- If any task changes shared domain models, enums, or test infrastructure, dispatch it **first** and run `./gradlew test` after it returns before dispatching the parallel wave (prevents test baseline contamination)
81+
- Focus prompts on task-specific context (item UUID, files to modify, test expectations) — the `subagent-start` hook injects commit, scope, and cd-discipline rules automatically
82+
83+
**Post-return checklist — for each worktree agent:**
84+
1. Capture **worktree path** and **branch name** from Agent return metadata
85+
2. Record in tracking table: `| Item UUID | Worktree Path | Branch | Status |`
86+
3. Spot-check diff: `git -C <worktree-path> diff main --stat`
87+
88+
**Review agent worktree template — include ALL of the following:**
89+
- Worktree path: `<path from implementation agent return>`
90+
- Branch name: `<branch from implementation agent return>`
91+
- Changed files: output of `git -C <path> diff main --name-only`
92+
- Instruction: "Run all commands and read all files from within the worktree at `<path>`. Do NOT read files from the main working directory."
93+
94+
**Post-review — squash-merge each worktree sequentially:**
95+
1. `git merge --squash <worktree-branch>` into local `main`
96+
2. Run full test suite after each merge to catch integration issues
97+
3. Delete worktree branch after successful merge
98+
7499
## Retrospective Nudge
75100

76101
When items reach terminal after an implementation run — whether via `advance_item`, `complete_tree`, or auto-cascade — suggest running `/session-retrospective` to capture learnings.

0 commit comments

Comments
 (0)