opencode-thrum-pro 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/assets/commands/thrum-_deviations-protocol.md +87 -0
  2. package/assets/commands/thrum-_generator-idempotency-protocol.md +15 -0
  3. package/assets/commands/thrum-_project-rules-protocol.md +18 -0
  4. package/assets/commands/thrum-_snapshot-protocol.md +265 -0
  5. package/assets/commands/thrum-_stamp-protocol.md +112 -0
  6. package/assets/commands/thrum-_verify-before-write-protocol.md +27 -0
  7. package/assets/commands/thrum-inbox.md +22 -0
  8. package/assets/commands/thrum-load-context.md +17 -0
  9. package/assets/commands/thrum-overview.md +17 -0
  10. package/assets/commands/thrum-prime.md +30 -0
  11. package/assets/commands/thrum-quickstart.md +14 -0
  12. package/assets/commands/thrum-reply.md +28 -0
  13. package/assets/commands/thrum-restart-extended.md +195 -0
  14. package/assets/commands/thrum-restart.md +293 -0
  15. package/assets/commands/thrum-send.md +31 -0
  16. package/assets/commands/thrum-sleep-extended.md +186 -0
  17. package/assets/commands/thrum-sleep.md +212 -0
  18. package/assets/commands/thrum-team.md +12 -0
  19. package/assets/commands/thrum-update-project.md +259 -0
  20. package/assets/commands/thrum-wait.md +14 -0
  21. package/assets/skills/adversarial-critique/SKILL.md +242 -0
  22. package/assets/skills/brainstorm-queue-aware/SKILL.md +167 -0
  23. package/assets/skills/brainstorm-steward/SKILL.md +181 -0
  24. package/assets/skills/choosing-subagent-models/SKILL.md +244 -0
  25. package/assets/skills/closing-findings-while-warm/SKILL.md +104 -0
  26. package/assets/skills/configure-roles/SKILL.md +229 -0
  27. package/assets/skills/coordinator-assessing-agent-completion/SKILL.md +205 -0
  28. package/assets/skills/coordinator-assessing-agent-completion/scan.py +117 -0
  29. package/assets/skills/coordinator-branch-split-on-block/SKILL.md +168 -0
  30. package/assets/skills/coordinator-context-monitoring/SKILL.md +674 -0
  31. package/assets/skills/coordinator-dispatching-work/SKILL.md +288 -0
  32. package/assets/skills/coordinator-hotpath-merge-gate/SKILL.md +522 -0
  33. package/assets/skills/coordinator-interacting-with-the-owner/SKILL.md +171 -0
  34. package/assets/skills/coordinator-maintaining-memory/SKILL.md +89 -0
  35. package/assets/skills/coordinator-managing-state-and-lifecycle/SKILL.md +192 -0
  36. package/assets/skills/coordinator-merging-code/SKILL.md +331 -0
  37. package/assets/skills/coordinator-philosophy-merge-gate/SKILL.md +442 -0
  38. package/assets/skills/coordinator-plan-reconcile-gate/SKILL.md +198 -0
  39. package/assets/skills/coordinator-post-restart-sweep/SKILL.md +135 -0
  40. package/assets/skills/coordinator-running-autonomous-feature-development/SKILL.md +199 -0
  41. package/assets/skills/coordinator-running-brainstorm-cycles/SKILL.md +654 -0
  42. package/assets/skills/coordinator-running-review-cycles/SKILL.md +153 -0
  43. package/assets/skills/coordinator-single-responsibility-merge-gate/SKILL.md +14 -0
  44. package/assets/skills/diagnosing-fleet-and-daemon/SKILL.md +255 -0
  45. package/assets/skills/efficient-multi-agent-research/SKILL.md +177 -0
  46. package/assets/skills/fixing-documentation-errors/SKILL.md +258 -0
  47. package/assets/skills/implementer-maintaining-memory/SKILL.md +84 -0
  48. package/assets/skills/implementer-orchestrating-execution/SKILL.md +125 -0
  49. package/assets/skills/implementer-receiving-dispatch/SKILL.md +127 -0
  50. package/assets/skills/implementer-receiving-review-feedback/SKILL.md +125 -0
  51. package/assets/skills/implementer-status-and-handoff/SKILL.md +150 -0
  52. package/assets/skills/implementer-tdd-and-quality/SKILL.md +99 -0
  53. package/assets/skills/memory-audit-recover/SKILL.md +153 -0
  54. package/assets/skills/memory-curate/SKILL.md +139 -0
  55. package/assets/skills/memory-maintenance/SKILL.md +87 -0
  56. package/assets/skills/memory-read-discipline/SKILL.md +164 -0
  57. package/assets/skills/memory-search-advanced/SKILL.md +217 -0
  58. package/assets/skills/memory-write-discipline/SKILL.md +135 -0
  59. package/assets/skills/orchestrate/SKILL.md +795 -0
  60. package/assets/skills/persistent-watcher-archetype/SKILL.md +225 -0
  61. package/assets/skills/prime-agent/SKILL.md +92 -0
  62. package/assets/skills/project-hotpath-gate/SKILL.md +255 -0
  63. package/assets/skills/project-philosophy/SKILL.md +418 -0
  64. package/assets/skills/project-philosophy/resources/philosophy-template.md +155 -0
  65. package/assets/skills/project-philosophy/resources/reliability-class-library.md +653 -0
  66. package/assets/skills/project-setup/SKILL.md +1007 -0
  67. package/assets/skills/project-setup/resources/implementation-agent.md +826 -0
  68. package/assets/skills/researcher-answering-queries/SKILL.md +100 -0
  69. package/assets/skills/researcher-investigating/SKILL.md +152 -0
  70. package/assets/skills/researcher-maintaining-memory/SKILL.md +176 -0
  71. package/assets/skills/state-migration/SKILL.md +54 -0
  72. package/assets/skills/thrum/SKILL.md +161 -0
  73. package/assets/skills/thrum/resources/ANTI_PATTERNS.md +132 -0
  74. package/assets/skills/thrum/resources/BOUNDARIES.md +56 -0
  75. package/assets/skills/thrum/resources/CLI_REFERENCE.md +1066 -0
  76. package/assets/skills/thrum/resources/IDENTITY.md +49 -0
  77. package/assets/skills/thrum/resources/LISTENER_PATTERN.md +64 -0
  78. package/assets/skills/thrum/resources/MESSAGING.md +163 -0
  79. package/assets/skills/thrum/resources/TMUX_SESSIONS.md +118 -0
  80. package/assets/skills/thrum/resources/WORKTREES.md +117 -0
  81. package/assets/skills/thrum-memory/SKILL.md +138 -0
  82. package/assets/skills/trace-spec-to-plan/SKILL.md +104 -0
  83. package/assets/skills/trace-spec-to-plan/resources/sweep-agent-prompt.md +57 -0
  84. package/assets/skills/update-queue/SKILL.md +149 -0
  85. package/assets/skills/using-the-queue/SKILL.md +172 -0
  86. package/assets/skills/using-thrum-state/SKILL.md +104 -0
  87. package/assets/skills/verify-against-plan/SKILL.md +323 -0
  88. package/assets/skills/verify-against-source/SKILL.md +237 -0
  89. package/assets/skills/watcher-archetype/SKILL.md +84 -0
  90. package/assets/skills/writing-durable-markdown/SKILL.md +66 -0
  91. package/dist/hooks/block-sync-cd.d.ts +9 -0
  92. package/dist/hooks/block-sync-cd.js +71 -0
  93. package/dist/hooks/block-sync-cd.test.d.ts +1 -0
  94. package/dist/hooks/block-sync-cd.test.js +61 -0
  95. package/dist/hooks/shell-env.d.ts +8 -0
  96. package/dist/hooks/shell-env.js +22 -0
  97. package/dist/index.d.ts +6 -0
  98. package/dist/index.js +25 -0
  99. package/dist/installer.d.ts +2 -0
  100. package/dist/installer.js +86 -0
  101. package/package.json +49 -0
@@ -0,0 +1,826 @@
1
+ # Implementation Agent Template
2
+
3
+ ## Purpose
4
+
5
+ Guide an agent through implementing an epic's tasks in a designated worktree.
6
+ Supports both cold-start and resume scenarios. The agent works through beads
7
+ tasks in order, runs quality gates, and pushes completed work.
8
+
9
+ ## CRITICAL: Prompt Generation Rules
10
+
11
+ <!-- STRIP THIS SECTION — it is for the coordinator filling the template, not
12
+ for the implementation agent. project-setup must remove it along with
13
+ ## Purpose and ## Inputs Required. -->
14
+
15
+ When filling this template to create an implementation prompt:
16
+
17
+ 1. **Every section is mandatory unless explicitly marked optional.** Do not
18
+ summarize, paraphrase, or abbreviate sections — copy them verbatim and fill
19
+ in the `{{PLACEHOLDERS}}`. Sections marked `IMPORTANT` must appear in the
20
+ output prompt word-for-word.
21
+ 2. **The Sub-Agent Strategy section (below) must be included in full.** It
22
+ contains the agent selection table, parallelization criteria, and verifier
23
+ pattern. These are operational directives, not background context. Omitting
24
+ them degrades agent performance by removing their ability to delegate and
25
+ parallelize work.
26
+ 3. **Strip ALL meta-instructions.** Lines and blocks marked with
27
+ `<!-- STRIP ... -->` comments, and any text that addresses "the coordinator"
28
+ or "when filling this template", must be removed from the filled prompt. The
29
+ implementation agent should never see instructions about how to fill the
30
+ template — only instructions about how to implement the epic.
31
+
32
+ ## Inputs Required
33
+
34
+ - `{{EPIC_ID}}` — The beads epic ID to implement
35
+ - `{{WORKTREE_PATH}}` — Absolute path to the working worktree
36
+ - `{{BRANCH_NAME}}` — Git branch for this work (e.g., `feature/auth`)
37
+ - `{{BASE_BRANCH}}` — The branch this work merges into. **Resolve it from the
38
+ project's actual merge target** (`jq -r '.orchestration.merge_target'
39
+ .thrum/config.json`); do not assume `main` and do not carry a branch name
40
+ from another document
41
+ - `{{DESIGN_DOC}}` — **Absolute path** to the design spec (if applicable)
42
+ - `{{REFERENCE_CODE}}` — Paths to reference implementations (if any)
43
+ - `{{QUALITY_COMMANDS}}` — Commands for test/lint, **scoped to packages this
44
+ epic modifies** (e.g., `go test ./internal/processing/localstore/` not
45
+ `go test ./...`). Scoping avoids false failures from pre-existing issues in
46
+ unrelated packages.
47
+ - `{{COVERAGE_TARGET}}` — Minimum coverage threshold (e.g., >80%)
48
+ - `{{AGENT_NAME}}` — Unique name for this agent (e.g., `impl-daemon`,
49
+ `impl-cli`)
50
+ - `{{SUPERVISOR_NAME}}` — Agent name of the supervisor — coordinator or
51
+ orchestrator (from `thrum team`). Use for direct messages, not the role name.
52
+ - `{{PLAN_FILE}}` — **Absolute path** to the implementation plan file
53
+ - `{{PROJECT_ROOT}}` — Absolute path to the project root
54
+ - `{{ANTI_PATTERNS}}` — Epic-specific implementation standards. Injected by
55
+ project-setup Phase 4. If empty, the generic verifier pattern still applies
56
+ but without domain-specific checks. Refer to the `project-philosophy` skill
57
+ for the format spec.
58
+ - `{{CROSS_EPIC_DEPS}}` — Cross-epic dependency table showing which tasks in
59
+ this epic are blocked by tasks in other epics. Injected by project-setup
60
+ Phase 4. If empty (no cross-epic deps), this section is omitted.
61
+
62
+ **Why absolute paths?** Design docs, plan files, and prompts typically live in
63
+ gitignored directories (`dev-docs/`, `docs/plans/`). Worktrees only share
64
+ committed files, so agents in worktrees cannot resolve relative paths to these
65
+ files. All `{{DESIGN_DOC}}`, `{{PLAN_FILE}}`, and prompt references must be
66
+ absolute paths (e.g., `/Users/you/project/dev-docs/plans/file.md`).
67
+
68
+ ---
69
+
70
+ ## Sub-Agent Strategy
71
+
72
+ You are an **orchestrator**. You implement by dispatching research,
73
+ implementation, and verification to sub-agents and synthesizing their output —
74
+ not by doing the legwork yourself. Your context is for judgment (synthesize
75
+ reports, target edits, judge verification); the legwork goes to cheaper
76
+ sub-agents. The full procedure is the `implementer-orchestrating-execution`
77
+ skill — it is canonical; this section only sets the default. Invoke that skill
78
+ at the start of executing any scoped task.
79
+
80
+ ### Scoping gate (before dispatching anything)
81
+
82
+ Classify the whole task. If it is a bounded change (≤ ~15 lines, ≤ 2 files)
83
+ whose targets you already know and where any reading is purely to **locate**
84
+ (not to understand), do it inline as correction-class and skip orchestration.
85
+ Otherwise, orchestrate via the agent table below.
86
+
87
+ ### Agent selection
88
+
89
+ | Dispatch | Agent type | Model | Background? |
90
+ | ------------------------------ | ------------------------------ | --------------------------------------- | ----------- |
91
+ | Research / explore a code area | `Explore` or `general-purpose` | `sonnet` | yes |
92
+ | Implement a task | `general-purpose` | `sonnet` (low effort if purely mechanical) | no |
93
+ | Verify a task against the plan | `general-purpose` | `sonnet` | no |
94
+ | Run tests / lint | `general-purpose` | `sonnet` (low effort) | yes |
95
+
96
+ Always pass `model:` explicitly — never let a sub-agent inherit your (Opus)
97
+ model. Label every dispatch's `description` with `research:` / `implement:` /
98
+ `verify:` (the evaluation harness classifies delegation shape from these
99
+ labels).
100
+
101
+ ### The inline-vs-dispatch boundary
102
+
103
+ > **Default verb is dispatch.** Inline editing is permitted in exactly three
104
+ > cases:
105
+ >
106
+ > 1. **Correcting** a sub-agent's edit that came back wrong.
107
+ > 2. An edit whose change you **already fully know**, where any reading is
108
+ > purely to **locate** the insertion point (not to understand), AND the
109
+ > change is bounded (≤ ~15 lines, ≤ 2 files).
110
+ > 3. The scoping-gate case: the whole task meets the bound in (2).
111
+ >
112
+ > **The moment you must read code to _understand what to change_ — discovering
113
+ > unknown structure, not finding a known target — that is a research dispatch,
114
+ > not an inline edit.**
115
+
116
+ ### Verifier dispatch (per task)
117
+
118
+ After an implementation dispatch returns, spawn a `sonnet` verifier against the
119
+ plan the implementing sub-agent was given — confirm the diff meets the
120
+ acceptance criteria. This is the in-loop check; the full code review still
121
+ happens at Phase 3: Self-Review Gate.
122
+
123
+ ---
124
+
125
+ ## MANDATORY: Register Before Any Work
126
+
127
+ **STOP. Run these commands before doing anything else.** Do not skip this
128
+ section.
129
+
130
+ ```bash
131
+ cd {{WORKTREE_PATH}}
132
+ thrum quickstart --name {{AGENT_NAME}} --role implementer --module {{BRANCH_NAME}} --intent "Implementing {{EPIC_ID}}"
133
+ thrum inbox --unread
134
+ # Tip: thrum inbox --unread peeks without marking read; thrum message read --all to mark all read
135
+ # Tip: default page is 10 newest-first — stale unread sorts LAST; use `thrum message search "<term>"` to find it
136
+ thrum send --to @{{SUPERVISOR_NAME}} --stdin <<'EOF'
137
+ Starting work on {{EPIC_ID}}
138
+ EOF
139
+ ```
140
+
141
+ **Verify registration succeeded** — you must see your agent name in the output
142
+ of `thrum quickstart`. If it fails, check that the daemon is running with
143
+ `thrum daemon status`.
144
+
145
+ **Finding agent names:** Run `thrum team` to see all active agents and their
146
+ names. Always send to agent names (e.g., `--to @coord_main`), not role names
147
+ (e.g., `--to @coordinator`). Sending to a role fans out to ALL agents with that
148
+ role.
149
+
150
+ **Use the message listener** — Spawn a background listener to get async
151
+ notifications. Re-arm it every time it returns (both MESSAGES_RECEIVED and
152
+ NO_MESSAGES_TIMEOUT).
153
+
154
+ When your work is complete (Phase 4), send a completion message prefixed with
155
+ the appropriate **status token** (see Status Vocabulary at the start of Phase
156
+ 4):
157
+
158
+ ```bash
159
+ thrum send --to @{{SUPERVISOR_NAME}} --stdin <<'EOF'
160
+ DONE: {{EPIC_ID}} complete. All tasks done, tests passing.
161
+ EOF
162
+ ```
163
+
164
+ If you hit a blocker from another agent's work, escalate with the `BLOCKED`
165
+ token:
166
+
167
+ ```bash
168
+ thrum send --to @{{SUPERVISOR_NAME}} --stdin <<'EOF'
169
+ BLOCKED: {{TASK_ID}} waiting on {{BLOCKER_ID}}
170
+ EOF
171
+ ```
172
+
173
+ ---
174
+
175
+ ## Phase 1: Orient
176
+
177
+ Whether starting fresh or resuming after context loss, always begin here. This
178
+ phase is idempotent — running it multiple times is safe and expected.
179
+
180
+ 🔴 **BEFORE ANYTHING ELSE — OBTAIN THE PLAN INTO YOUR WORKTREE AND CONFIRM YOU CAN OPEN IT.** Do NOT implement from plan detail relayed to you in messages or beads — relay is lossy and drifts as the plan is updated.
181
+
182
+ ```bash
183
+ cd {{WORKTREE_PATH}}
184
+ git pull # pull the committed plan into this worktree
185
+ head -1 {{PLAN_FILE}} # confirm the plan file actually opens here
186
+ ```
187
+
188
+ If `{{PLAN_FILE}}` cannot be opened, STOP and tell {{SUPERVISOR_NAME}} — do not proceed from relayed or remembered plan text.
189
+
190
+ ### Step 1: Check Epic & Task Status
191
+
192
+ ```bash
193
+ # Navigate to worktree
194
+ cd {{WORKTREE_PATH}}
195
+
196
+ # Check epic status — see which tasks are done, in_progress, or pending
197
+ bd show {{EPIC_ID}}
198
+
199
+ # Check for any in-progress tasks (may be from a prior session)
200
+ bd list --status=in_progress
201
+
202
+ # Check completed tasks
203
+ bd list --status=closed
204
+ ```
205
+
206
+ ### Step 2: Check Git State
207
+
208
+ ```bash
209
+ # Verify you're on the right branch
210
+ git branch --show-current
211
+
212
+ # Check for uncommitted work from a prior session
213
+ git status
214
+
215
+ # Review recent commits to understand what's been done
216
+ git --no-pager log --oneline -10
217
+
218
+ # Pull latest changes (if remote tracking is set up) — merge, never rebase
219
+ git pull
220
+ ```
221
+
222
+ ### Step 3: Explore Existing Code
223
+
224
+ Dispatch a research sub-agent (see `implementer-orchestrating-execution`) to map
225
+ what already exists — don't read the codebase into your own context:
226
+
227
+ 1. Check which files/packages have been created
228
+ 2. Review existing implementations for patterns to follow
229
+ 3. Identify the current state of any in-progress tasks
230
+
231
+ If a design doc exists, read it: `{{DESIGN_DOC}}`
232
+
233
+ If reference code exists, explore it: `{{REFERENCE_CODE}}`
234
+
235
+ ### Step 4: Determine Starting Point
236
+
237
+ - If **all tasks are complete**: Skip to Phase 3 (Verify Quality) then Phase 4
238
+ (Complete)
239
+ - If **a task is `in_progress`**: Review its state — check what's partially
240
+ implemented, check git diff, then continue from where it left off
241
+ - If **tasks are pending**: Start with the first unblocked pending task (lowest
242
+ dependency order)
243
+
244
+ **CRITICAL: DO NOT redo completed work.** Trust the beads status and git
245
+ history. Pick up from exactly where the previous session stopped.
246
+
247
+ ### Step 5: Check Cross-Epic Dependencies
248
+
249
+ {{CROSS_EPIC_DEPS}}
250
+
251
+ <!-- STRIP: This comment is for project-setup. When filling, replace
252
+ {{CROSS_EPIC_DEPS}} with either a dependency table or
253
+ "No cross-epic dependencies." Then remove this comment. -->
254
+
255
+ ---
256
+
257
+ ## Implementation Standards
258
+
259
+ {{ANTI_PATTERNS}}
260
+
261
+ <!-- STRIP: Replace {{ANTI_PATTERNS}} with content generated per the
262
+ project-philosophy anti-pattern format. Then remove this comment. The
263
+ self-review gate in Phase 3 passes these to the code-reviewer sub-agent. -->
264
+
265
+ ---
266
+
267
+ ## Phase 2: Implement Tasks
268
+
269
+ ### Task Execution Loop
270
+
271
+ For each task (in dependency order, foundations first):
272
+
273
+ #### 1. Claim the Task
274
+
275
+ ```bash
276
+ bd update {{TASK_ID}} --status=in_progress
277
+ ```
278
+
279
+ #### 2. Read the Task Details
280
+
281
+ ```bash
282
+ bd show {{TASK_ID}}
283
+ ```
284
+
285
+ The task description is the **source of truth** for what to build. It contains
286
+ acceptance criteria that must be satisfied before closing the task.
287
+
288
+ For detailed implementation code, search the plan file for the matching task
289
+ section:
290
+
291
+ ```bash
292
+ grep -n "## Task: {{TASK_ID}}" {{PLAN_FILE}}
293
+ ```
294
+
295
+ Read ONLY that section (from the matching heading to the next `## Task:` heading
296
+ or end of file), not the entire plan file. Plan files can be large (50KB+) and
297
+ reading the whole file exhausts context. The plan file provides step-by-step
298
+ code; the beads task provides completion criteria. Use both.
299
+
300
+ #### 3. Implement the Task
301
+
302
+ - Follow the task description
303
+ - Write tests alongside implementation (TDD when appropriate)
304
+ - Follow existing code patterns and conventions in the codebase
305
+ - Reference `{{DESIGN_DOC}}` for architectural context when needed
306
+
307
+ #### 4. Verify the Task
308
+
309
+ ```bash
310
+ # Run project quality gates
311
+ {{QUALITY_COMMANDS}}
312
+ ```
313
+
314
+ All tests must pass before proceeding. If tests fail, fix them before moving on.
315
+ Do not skip failing tests or mark them as known failures without explicit
316
+ instruction.
317
+
318
+ #### 5. Commit the Work
319
+
320
+ ```bash
321
+ git add <specific-files>
322
+ git commit -m "{{EPIC_TITLE}}: <concise task description>"
323
+ ```
324
+
325
+ Commit after each task, not in bulk at the end. Use descriptive commit messages
326
+ that explain what was built.
327
+
328
+ #### 6. Close the Task
329
+
330
+ ```bash
331
+ bd close {{TASK_ID}}
332
+ ```
333
+
334
+ #### 7. Move to Next Task
335
+
336
+ Repeat from step 1 with the next unblocked pending task.
337
+
338
+ If multiple tasks are complete, close them in batch:
339
+
340
+ ```bash
341
+ bd close {{TASK_ID_1}} {{TASK_ID_2}} {{TASK_ID_3}}
342
+ ```
343
+
344
+ ---
345
+
346
+ ### Parallel Task Implementation
347
+
348
+ When multiple tasks are unblocked and independent, implement them
349
+ simultaneously. This is the biggest context and time win.
350
+
351
+ #### Identify Parallelizable Tasks
352
+
353
+ After completing a task, check for unblocked work:
354
+
355
+ ```bash
356
+ bd show {{EPIC_ID}} # Which tasks are pending and unblocked?
357
+ ```
358
+
359
+ Tasks are parallelizable when they touch different files/packages and don't
360
+ depend on each other's output.
361
+
362
+ #### Launch Pattern
363
+
364
+ Give each sub-agent everything it needs to work autonomously. Each prompt must
365
+ include: worktree path, branch name, the full `bd show <task_id>` output as the
366
+ source of truth, the quality commands for the verify step, and the
367
+ commit-message format (`{{EPIC_TITLE}}: <task summary>`). Each sub-agent returns
368
+ what was built, test results, and the commit hash.
369
+
370
+ Invoke `efficient-multi-agent-research` § Core Pattern for the launch-and-wait
371
+ mechanics (dispatch all agents in ONE message, `run_in_background=true`, wait
372
+ for all completions before consolidating).
373
+
374
+ #### After Sub-Agents Complete
375
+
376
+ 1. Review reported results (commit hashes, test output)
377
+ 2. Check for conflicts: `git --no-pager log --oneline -5`
378
+ 3. Close completed tasks: `bd close {{TASK_A}} {{TASK_B}}`
379
+ 4. Run unified quality gate: `{{QUALITY_COMMANDS}}`
380
+ 5. Check for newly unblocked tasks — repeat if more are available
381
+
382
+ #### Guardrails
383
+
384
+ - **2-3 concurrent sub-agents** is the sweet spot. More adds coordination
385
+ overhead without proportional speedup.
386
+ - **Partition by file/package** to avoid git conflicts. If two tasks touch the
387
+ same file, run them sequentially.
388
+ - **Always run a final unified test pass** after parallel work — concurrent
389
+ sub-agents may miss interaction bugs.
390
+
391
+ ---
392
+
393
+ ### Tool Usage
394
+
395
+ #### Code Exploration
396
+
397
+ Use Grep, Glob, and Read tools for targeted searches. For broader exploration of
398
+ unfamiliar code areas, spawn an Explore sub-agent — it's more context-efficient
399
+ than reading entire files into your main context.
400
+
401
+ #### Subagents
402
+
403
+ The canonical procedure is the `implementer-orchestrating-execution` skill
404
+ (scoping gate, research → implementation → verification dispatch, model tiers,
405
+ label convention). The **Sub-Agent Strategy** section at the top of this
406
+ template sets the orchestrator default and points at that skill.
407
+
408
+ ---
409
+
410
+ ### Logging Refactoring Opportunities
411
+
412
+ During implementation you will often discover code that could be improved —
413
+ duplicated patterns, hardcoded values that should be shared, missed
414
+ abstractions, or DRY violations. **Do not fix these inline** (scope creep) and
415
+ **do not lose them** (they're valuable).
416
+
417
+ Self-filing here is limited to purely cosmetic improvements to code that
418
+ already works correctly — naming, duplication, structure. Anything that
419
+ touches correctness, or is a defect, a plan gap, a missing case, or one of a
420
+ class of sites where others are already wrong, goes to your dispatcher via the
421
+ `closing-findings-while-warm` skill — no exceptions, and regardless of how you
422
+ label it. If you cannot tell which side of that line you are on, that
423
+ uncertainty is itself the answer: surface it.
424
+
425
+ Instead, log them to the project's persistent **refactoring epic** in beads:
426
+
427
+ #### 1. Find the Refactoring Epic
428
+
429
+ ```bash
430
+ bd list --type=epic | grep -i refactor
431
+ ```
432
+
433
+ If no refactoring epic exists, create one:
434
+
435
+ `--description` is multi-line prose — never double-quoted inline. On
436
+ `scripts/bd-shared`, `--stdin`/`--body-file` are refused (remote-path
437
+ resolution + silent-empty-body hazards), so write it to a scratch file and
438
+ pass `-d "$(cat <file>)"`; see your role preamble's 🔴 PROSE INTO A COMMAND
439
+ rule.
440
+
441
+ ```bash
442
+ cat > /tmp/refactor-epic-desc.md <<'EOF'
443
+ Persistent backlog for refactoring, DRY improvements, and code organization
444
+ opportunities discovered during feature work. Tasks are added by
445
+ implementation agents as they encounter opportunities. Reviewed and
446
+ prioritized by the coordinator periodically.
447
+ EOF
448
+ bd create --title="Refactoring & DRY Opportunities" --type=epic --priority=3 -d "$(cat /tmp/refactor-epic-desc.md)"
449
+ ```
450
+
451
+ #### 2. Log the Opportunity
452
+
453
+ Same `--description` handling as §1 above (scratch file + `-d "$(cat <file>)"`).
454
+
455
+ ```bash
456
+ cat > /tmp/refactor-task-desc.md <<'EOF'
457
+ **Discovered during:** {{EPIC_ID}}
458
+ **Files:** <file paths>
459
+ **Opportunity:** <what could be improved — duplicated code, hardcoded values, missed abstraction>
460
+ **Suggested approach:** <how to fix it>
461
+ **Effort estimate:** small/medium/large
462
+ EOF
463
+ bd create --title="Refactor: <short description>" --type=task --parent=<refactoring-epic-id> --priority=3 -d "$(cat /tmp/refactor-task-desc.md)"
464
+ ```
465
+
466
+ #### 3. Continue With Your Assigned Work
467
+
468
+ Do not implement the refactoring — just log it and move on. The coordinator
469
+ reviews and prioritizes these periodically. This keeps your scope tight while
470
+ ensuring good ideas aren't lost.
471
+
472
+ **Examples of what to log:**
473
+
474
+ - Two handlers with nearly identical pagination logic → extract shared helper
475
+ - Hardcoded demo values that should come from seed data
476
+ - Multiple packages importing the same 5-line utility pattern
477
+ - An interface that's grown too large and should be split
478
+ - A notification store duplicated across two packages (should be unified)
479
+
480
+ ---
481
+
482
+ ### Handling Blockers
483
+
484
+ If a task is blocked:
485
+
486
+ 1. Check what's blocking it: `bd show {{BLOCKER_ID}}`
487
+ 2. If the blocker is another task **within your epic**, work on the blocker
488
+ first
489
+ 3. If the blocker is **external** (different epic, different agent), skip the
490
+ blocked task and work on the next unblocked one
491
+ 4. Document the blocker:
492
+ `bd update {{TASK_ID}} --notes="Blocked by {{BLOCKER_ID}}: <reason>"`
493
+ 5. **Notify via Thrum** so the coordinator or blocking agent is aware:
494
+
495
+ ```bash
496
+ # Ask the blocking agent for help
497
+ # NOTE: --mention @implementer (with no --to) delivers ONLY to agent(s) matching
498
+ # that role/name — it does not go to the supervisor and does not broadcast. A
499
+ # message with ZERO addressing (no --to, no mentions) routes to the local
500
+ # coordinator instead. Broadcast to everyone requires an explicit
501
+ # --to everyone / --mention @everyone.
502
+ thrum send --mention @implementer --stdin <<'EOF'
503
+ BLOCKED: {{TASK_ID}} — waiting for {{BLOCKER_ID}}. Can you prioritize?
504
+ EOF
505
+
506
+ # Or escalate to the coordinator
507
+ thrum send --to @{{SUPERVISOR_NAME}} --stdin <<'EOF'
508
+ BLOCKED: {{TASK_ID}} by external dependency {{BLOCKER_ID}}
509
+ EOF
510
+ ```
511
+
512
+ ### When you hit a design fork
513
+
514
+ **If you're blocked on a genuine 2-3 way design fork** — a real tradeoff where
515
+ "just pick one" would likely be regretted — invoke `adversarial-critique` with
516
+ the options, constraints, and the decision you need made. The
517
+ `adversarial-critique` skill documents cost, threshold, and the audit artifact
518
+ path.
519
+
520
+ **If you're investigating N > 6 items** (function call sites, pattern audits,
521
+ multi-file reviews), invoke the `efficient-multi-agent-research` skill _instead
522
+ of_ reading files into this context. It partitions the work across parallel
523
+ sub-agents that write findings to disk, then consolidates into one report.
524
+
525
+ Cost: ~50-100k tokens depending on item count. Worth it to keep decision-making
526
+ context clean and produce an auditable research trail at `dev-docs/<topic>/`.
527
+ Skip it when:
528
+
529
+ - Fewer than ~6 items — just use Grep/Glob
530
+ - Items are deeply interdependent and can't be partitioned
531
+
532
+ These two gates are sister patterns: critique decides _which option wins_;
533
+ research uncovers _what's there_.
534
+
535
+ ### Communicating During Work
536
+
537
+ Use Thrum to stay coordinated:
538
+
539
+ ```bash
540
+ # Report progress on significant milestones
541
+ thrum send --to @{{SUPERVISOR_NAME}} --stdin <<'EOF'
542
+ Completed task {{TASK_ID}}, moving to next
543
+ EOF
544
+
545
+ # Ask for input when you need a decision
546
+ thrum send --to @{{SUPERVISOR_NAME}} --stdin <<'EOF'
547
+ Need input: should X use approach A or B? Context: ...
548
+ EOF
549
+
550
+ # If you realize your work affects another agent's files
551
+ # NOTE: delivers only to agent(s) matching @implementer — see the mention-delivery
552
+ # note under "Handling Blockers" above for the full rule.
553
+ thrum send --mention @implementer --stdin <<'EOF'
554
+ Heads up: I'm modifying internal/daemon/rpc.go which may overlap with your work
555
+ EOF
556
+
557
+ # Update your intent when switching tasks
558
+ thrum agent set-intent "Working on {{TASK_ID}}: <description>"
559
+ ```
560
+
561
+ ---
562
+
563
+ <!-- REVIEW_GATE_TEMPLATE_START -->
564
+
565
+ ## Review Gate: {{EPIC_ID}}
566
+
567
+ Before proceeding to the next epic:
568
+
569
+ 1. Commit all work for this epic
570
+ 2. Run tests: verify all tests pass for changes in this epic
571
+ 3. Report completion via Thrum:
572
+ `thrum send --to @{{SUPERVISOR_NAME}} --body-file done.md` (body: "DONE: Epic
573
+ {{EPIC_ID}} complete. Ready for review.")
574
+ 4. Set status: `thrum agent set-status idle`
575
+ 5. **STOP.** Wait for review approval before continuing.
576
+ <!-- REVIEW_GATE_TEMPLATE_END -->
577
+
578
+ ---
579
+
580
+ ## Phase 3: Self-Review Gate (MANDATORY)
581
+
582
+ **You MUST complete this phase before claiming the epic is done.** Do not skip
583
+ or abbreviate it. The purpose is to catch issues before the coordinator reviews,
584
+ reducing back-and-forth rounds.
585
+
586
+ Use a **two-stage review** in this exact order: **spec compliance first, then
587
+ code quality.** Run `verify-against-plan` before `feature-dev:code-reviewer`;
588
+ fix each stage's findings before moving to the next.
589
+
590
+ ### Step 1: Run Quality Gates
591
+
592
+ ```bash
593
+ cd {{WORKTREE_PATH}}
594
+
595
+ # Run all tests
596
+ {{QUALITY_COMMANDS}}
597
+
598
+ # Check coverage if applicable
599
+ # Target: {{COVERAGE_TARGET}}
600
+ ```
601
+
602
+ Fix any failures before proceeding. Do not submit broken code for review.
603
+
604
+ ### Step 2: Spec Compliance Review (Stage 1)
605
+
606
+ Verify the implementation covers everything specified in the plan, design doc,
607
+ and each task's acceptance criteria. No code-style judgments at this stage —
608
+ only "does the code do what was asked?"
609
+
610
+ Invoke `verify-against-plan` with these inputs:
611
+
612
+ ```text
613
+ /verify-against-plan plan={{PLAN_FILE}} branch={{BRANCH_NAME}}
614
+ ```
615
+
616
+ The skill produces structured `BLOCKING` / `IMPORTANT` / `MINOR` findings with
617
+ plan-reference + file:line evidence.
618
+
619
+ **When findings come back:**
620
+
621
+ - For each `BLOCKING` or `IMPORTANT` finding, apply the `Suggested resolution`
622
+ from the finding using the same TDD cycle from Phase 2. Commit each fix:
623
+ `git commit -m "feat: cover missing scope — <description>"`. Re-run
624
+ `verify-against-plan` until no `BLOCKING` or `IMPORTANT` findings remain.
625
+ `MINOR` findings may be noted but do not block.
626
+ - When the skill returns with no `BLOCKING` or `IMPORTANT` findings, proceed to
627
+ Step 3.
628
+
629
+ **Maximum iterations:** 2 rounds. If findings persist after 2 rounds, note them
630
+ in the completion message to the coordinator with status `DONE_WITH_CONCERNS`.
631
+
632
+ ### Step 3: Code Quality Review (Stage 2)
633
+
634
+ Only after spec compliance is clean. Compute the diff range for the full epic:
635
+
636
+ ```bash
637
+ BASE_SHA=$(git merge-base HEAD "{{BASE_BRANCH}}") # NOT `main` — resolve the real base
638
+ HEAD_SHA=$(git rev-parse HEAD)
639
+ ```
640
+
641
+ Spawn a `feature-dev:code-reviewer` sub-agent in **foreground** (you need the
642
+ results before proceeding). The reviewer is a separate agent — you cannot
643
+ influence its findings.
644
+
645
+ ```text
646
+ Agent(subagent_type="feature-dev:code-reviewer", model="sonnet",
647
+ prompt="Review code quality of the implementation on branch {{BRANCH_NAME}}
648
+ in {{WORKTREE_PATH}}. Focus only on quality of the code that was written —
649
+ spec compliance is covered separately by verify-against-plan.
650
+
651
+ ## What to Review
652
+
653
+ Run `git --no-pager diff {BASE_SHA}...{HEAD_SHA}` to see all changes.
654
+
655
+ ## Review Criteria
656
+
657
+ ### 1. Code Quality
658
+ - Security: XSS, RBAC bypass, SQL injection, command injection
659
+ - Error handling: no swallowed errors, proper HTTP status codes
660
+ - Go idioms: proper error returns, no bare panics, correct defer usage
661
+ - No dead code, no commented-out code, no TODO items left behind
662
+
663
+ ### 2. Implementation Standards (Anti-Patterns)
664
+
665
+ {{ANTI_PATTERNS}}
666
+
667
+ Check every changed file against these rules. Grep for the red flags listed.
668
+ Each violation is a finding.
669
+
670
+ ## Output Format
671
+
672
+ Return a numbered list of findings. For each finding:
673
+ - File path and line number
674
+ - Severity: CRITICAL / HIGH / MEDIUM / LOW
675
+ - What's wrong
676
+ - How to fix it
677
+
678
+ End with: 'Ready to merge: Yes/No'
679
+
680
+ If no issues found, return: 'Ready to merge: Yes — no issues found.'")
681
+ ```
682
+
683
+ **When the review comes back**, invoke `superpowers:receiving-code-review` and
684
+ follow its response pattern:
685
+
686
+ 1. **READ** the full review without reacting
687
+ 2. **VERIFY** each finding against the codebase — is it actually valid? Check
688
+ the file and line number. The reviewer can be wrong.
689
+ 3. **FIX** Critical and Important issues. Push back with reasoning if a finding
690
+ is incorrect — do not blindly implement wrong suggestions.
691
+ 4. **MEDIUM** findings — use judgment, but default to fixing.
692
+ 5. **LOW** findings — fix if trivial, otherwise note and move on.
693
+ 6. Commit fixes:
694
+
695
+ ```bash
696
+ git add <fixed-files>
697
+ git commit -m "fix: address review findings for {{EPIC_ID}}"
698
+ ```
699
+
700
+ 7. **Re-run the code-reviewer** on the new diff (`BASE_SHA` = previous
701
+ `HEAD_SHA`, `HEAD_SHA` = new HEAD). Repeat until the reviewer returns "Ready
702
+ to merge: Yes" with no Critical or Important issues remaining.
703
+
704
+ **If code-quality fixes introduce substantive new logic** (not just renames or
705
+ reformatting), return to Step 2 (Spec Compliance) on the new code before
706
+ re-running code quality. New logic can create new gaps.
707
+
708
+ **Maximum iterations:** 3 review rounds. If issues persist after 3 rounds,
709
+ proceed to Step 4 and note the unresolved findings in your completion message
710
+ with status `DONE_WITH_CONCERNS`. Do not loop indefinitely.
711
+
712
+ ### Step 4: Final Verification
713
+
714
+ Run `{{QUALITY_COMMANDS}}` one final time. Review fixes and scope additions can
715
+ introduce regressions — do not skip this.
716
+
717
+ **If tests fail:** Fix failures before proceeding.
718
+
719
+ ### Verification Checklist
720
+
721
+ Before proceeding to Phase 4, confirm:
722
+
723
+ - [ ] All tasks in the epic are closed: `bd show {{EPIC_ID}}`
724
+ - [ ] All tests pass: `{{QUALITY_COMMANDS}}`
725
+ - [ ] `verify-against-plan` returned no `BLOCKING` or `IMPORTANT` findings
726
+ - [ ] Code quality returned "Ready to merge: Yes"
727
+ - [ ] Commit history is clean and descriptive:
728
+ `git --no-pager log --oneline -20`
729
+
730
+ ---
731
+
732
+ ## Phase 4: Complete & Land
733
+
734
+ ### Status Vocabulary (MANDATORY)
735
+
736
+ Every completion or escalation message to your supervisor must start with one of
737
+ these four status tokens. The coordinator's handler depends on the token — wrong
738
+ token means wrong response.
739
+
740
+ | Token | Meaning | Send When |
741
+ | -------------------- | -------------------------------------------------------------- | ---------------------------------------------------------------------- |
742
+ | `DONE` | Epic complete, all tasks closed, tests pass, self-review clean | Ready for coordinator review and merge |
743
+ | `DONE_WITH_CONCERNS` | Work complete but with caveats the coordinator should see | Unresolved review findings, architectural concerns, iteration caps hit |
744
+ | `NEEDS_CONTEXT` | Cannot proceed without more information | Missing design decision, ambiguous spec, unclear scope |
745
+ | `BLOCKED` | Cannot proceed — external dependency or tooling issue | Cross-epic dependency, test infra broken, auth problem |
746
+
747
+ Prefix every completion and escalation `thrum send` with the status token, for
748
+ example: `thrum send --to @{{SUPERVISOR_NAME}} --body-file done.md` (body:
749
+ "DONE: {{EPIC_ID}} complete. Branch pushed.")
750
+
751
+ ### Step 1: Close the Epic
752
+
753
+ ```bash
754
+ # Verify all tasks are closed
755
+ bd show {{EPIC_ID}}
756
+
757
+ # Close the epic
758
+ bd close {{EPIC_ID}} --reason="All tasks implemented and verified"
759
+ ```
760
+
761
+ ### Step 2: Push Branch & Notify Coordinator
762
+
763
+ Do NOT merge to main yourself. Push your branch and notify the coordinator for
764
+ code review and merge:
765
+
766
+ ```bash
767
+ # Ensure branch is up to date with {{BASE_BRANCH}} — merge forward, never rebase
768
+ git fetch origin {{BASE_BRANCH}}
769
+ git merge origin/{{BASE_BRANCH}}
770
+
771
+ # If conflicts arise, resolve them, then:
772
+ # git add <resolved files> && git commit
773
+
774
+ # Run quality gates one final time after merging forward
775
+ {{QUALITY_COMMANDS}}
776
+
777
+ # Push the branch (NOT main)
778
+ git push origin {{BRANCH_NAME}}
779
+
780
+ # Notify the coordinator
781
+ thrum send --to @{{SUPERVISOR_NAME}} --stdin <<'EOF'
782
+ DONE: {{EPIC_ID}} complete. Branch {{BRANCH_NAME}} pushed, all tests passing. Ready for review/merge.
783
+ EOF
784
+ ```
785
+
786
+ The coordinator handles code review and merge to main. This ensures review gates
787
+ are not bypassed and cross-epic integration is verified.
788
+
789
+ > **For solo-agent workflows:** If no coordinator exists, override this step to
790
+ > merge directly to main after running the full quality gate.
791
+
792
+ ### Step 3: Clean Up (Only If Instructed)
793
+
794
+ ```bash
795
+ # Remove the worktree if no longer needed
796
+ git worktree remove {{WORKTREE_PATH}}
797
+
798
+ # Delete the feature branch
799
+ git branch -d {{BRANCH_NAME}}
800
+ ```
801
+
802
+ Only clean up if explicitly instructed. The user may want to keep the worktree
803
+ for future work.
804
+
805
+ ---
806
+
807
+ ## Resume Quick Reference
808
+
809
+ If you're resuming after context loss (compaction, new session, etc.), here's
810
+ the minimal sequence:
811
+
812
+ ```bash
813
+ # 1. Re-register with Thrum (MANDATORY — do this first)
814
+ cd {{WORKTREE_PATH}}
815
+ thrum quickstart --name {{AGENT_NAME}} --role implementer --module {{BRANCH_NAME}} --intent "Resuming {{EPIC_ID}}"
816
+ thrum inbox --unread
817
+ # Tip: thrum inbox --unread peeks without marking read; thrum message read --all to mark all read
818
+ # Tip: default page is 10 newest-first — stale unread sorts LAST; use `thrum message search "<term>"` to find it
819
+
820
+ # 2. Orient from beads and git
821
+ bd show {{EPIC_ID}} # What's done?
822
+ bd list --status=in_progress # Anything mid-flight?
823
+ git --no-pager log --oneline -10 # What was committed?
824
+ git status # Any uncommitted work?
825
+ # Then pick up from the first incomplete task — DO NOT redo completed work
826
+ ```