dev-loops 0.1.3 → 0.2.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 (75) hide show
  1. package/.claude/.claude-plugin/plugin.json +9 -0
  2. package/.claude/agents/dev-loop.md +69 -0
  3. package/.claude/agents/developer.md +35 -0
  4. package/.claude/agents/docs.md +31 -0
  5. package/.claude/agents/fixer.md +51 -0
  6. package/.claude/agents/quality.md +26 -0
  7. package/.claude/agents/refiner.md +85 -0
  8. package/.claude/agents/review.md +61 -0
  9. package/.claude/hooks/_hook-io.mjs +38 -0
  10. package/.claude/hooks/hooks.json +35 -0
  11. package/.claude/hooks/post-tool-use-merge.mjs +23 -0
  12. package/.claude/hooks/pre-tool-use-bash-gate.mjs +73 -0
  13. package/.claude/hooks/pre-tool-use-write-guard.mjs +55 -0
  14. package/.claude/skills/copilot-pr-followup/SKILL.md +376 -0
  15. package/.claude/skills/dev-loop/SKILL.md +140 -0
  16. package/.claude/skills/dev-loop/templates/bootstrap-agents.md +26 -0
  17. package/.claude/skills/dev-loop/templates/bootstrap-implementation-state.md +31 -0
  18. package/.claude/skills/dev-loop/templates/bootstrap-implementation-workflow.md +17 -0
  19. package/.claude/skills/dev-loop/templates/dev-mode-retrospective.md +15 -0
  20. package/.claude/skills/dev-loop/templates/dev-mode-review.md +17 -0
  21. package/.claude/skills/dev-loop/templates/dev-mode-skill-changes.md +11 -0
  22. package/.claude/skills/dev-loop/templates/merged-phase-plan.md +19 -0
  23. package/.claude/skills/dev-loop/templates/phase-doc.md +27 -0
  24. package/.claude/skills/dev-loop/templates/phase-summary.md +13 -0
  25. package/.claude/skills/dev-loop/templates/phase-variant.md +15 -0
  26. package/.claude/skills/dev-loop/templates/retrospective.md +11 -0
  27. package/.claude/skills/dev-loop/templates/review.md +32 -0
  28. package/.claude/skills/dev-loop/templates/ui-vision-review.md +55 -0
  29. package/.claude/skills/docs/acceptance-criteria-verification.md +21 -0
  30. package/.claude/skills/docs/anti-patterns.md +21 -0
  31. package/.claude/skills/docs/artifact-authority-contract.md +119 -0
  32. package/.claude/skills/docs/confirmation-rules.md +28 -0
  33. package/.claude/skills/docs/copilot-ci-status-contract.md +52 -0
  34. package/.claude/skills/docs/copilot-loop-operations.md +233 -0
  35. package/.claude/skills/docs/debt-remediation-contract.md +107 -0
  36. package/.claude/skills/docs/entrypoint-strategies.md +115 -0
  37. package/.claude/skills/docs/epic-tree-refinement-procedure.md +234 -0
  38. package/.claude/skills/docs/issue-intake-procedure.md +235 -0
  39. package/.claude/skills/docs/main-agent-contract.md +85 -0
  40. package/.claude/skills/docs/merge-preconditions.md +29 -0
  41. package/.claude/skills/docs/pr-lifecycle-contract.md +209 -0
  42. package/.claude/skills/docs/public-dev-loop-contract.md +497 -0
  43. package/.claude/skills/docs/retrospective-checkpoint-contract.md +159 -0
  44. package/.claude/skills/docs/stop-conditions.md +29 -0
  45. package/.claude/skills/docs/structural-quality.md +42 -0
  46. package/.claude/skills/docs/tracker-first-loop-state.md +281 -0
  47. package/.claude/skills/docs/validation-policy.md +27 -0
  48. package/.claude/skills/docs/workflow-handoff-contract.md +135 -0
  49. package/.claude/skills/final-approval/SKILL.md +18 -0
  50. package/.claude/skills/local-implementation/SKILL.md +636 -0
  51. package/CHANGELOG.md +51 -0
  52. package/README.md +16 -0
  53. package/agents/dev-loop.agent.md +4 -0
  54. package/cli/index.mjs +5 -5
  55. package/extension/checks.ts +18 -29
  56. package/extension/harness-types.ts +47 -0
  57. package/extension/index.ts +10 -8
  58. package/extension/pi-extension-adapter.ts +64 -0
  59. package/extension/post-merge-update.ts +69 -190
  60. package/package.json +16 -9
  61. package/scripts/README.md +6 -3
  62. package/scripts/claude/generate-claude-assets.mjs +175 -0
  63. package/scripts/claude/headless-dev-loop.mjs +89 -0
  64. package/scripts/claude/headless-info-smoke.mjs +90 -0
  65. package/scripts/github/_review-thread-mutations.mjs +3 -0
  66. package/scripts/github/reply-resolve-review-threads.mjs +3 -3
  67. package/scripts/github/upsert-checkpoint-verdict.mjs +4 -3
  68. package/scripts/loop/_pr-runner-coordination.mjs +2 -1
  69. package/scripts/loop/copilot-pr-handoff.mjs +3 -2
  70. package/scripts/loop/detect-stale-runner.mjs +5 -7
  71. package/scripts/loop/info.mjs +3 -2
  72. package/scripts/loop/inspect-run-viewer/server.mjs +2 -1
  73. package/scripts/loop/outer-loop.mjs +2 -2
  74. package/scripts/loop/pr-runner-coordination.mjs +4 -4
  75. package/skills/docs/main-agent-contract.md +19 -6
@@ -0,0 +1,636 @@
1
+ ---
2
+ name: "local-implementation"
3
+ description: "Internal routed strategy behind `dev-loop` for local phase-bounded implementation. Use it when authoritative startup/resume routing selects the `local_implementation` strategy so the child agent can own phase planning, artifact discipline, test-first implementation, and local validation in fresh context."
4
+ allowed-tools: Read Bash Edit Write Agent
5
+ user-invocable: false
6
+ ---
7
+ <!-- GENERATED from skills/local-implementation/SKILL.md by scripts/claude/generate-claude-assets.mjs — do not edit; edit the source and regenerate. -->
8
+
9
+
10
+ # Local Implementation
11
+
12
+ This skill is the canonical internal `local_implementation` route behind the public `dev-loop` façade.
13
+
14
+ Use it only after the public dispatcher has already resolved `selectedStrategy: local_implementation`. This skill owns the local phase procedure and artifact discipline for that route; it does not redefine the shipped runtime semantics of helper CLIs, shared loop logic, or extension commands.
15
+
16
+ Read the authoritative public routing contract at [Public Dev Loop Contract](../docs/public-dev-loop-contract.md) and keep any repository-specific decisions grounded in [Project Plan](../../PLAN.md), durable phase docs, source, tests, config, and actual validation commands.
17
+ For UI validation under `dev-loop`, see [UI Validation Contract](../../docs/ui-validation-contract.md), [UI Smoke Harness](../../docs/ui-smoke-harness.md), [UI Artifact Contract](../../docs/ui-artifact-contract.md), and [UI Designer Review Loop](../../docs/ui-designer-review-loop.md) (designer + `uiReviewMode: vision`) (these are repo-level docs present in the source checkout; they are not part of the bundled `../docs/` runtime contract surface for installed skill copies).
18
+
19
+ ## Minimal required project inputs
20
+
21
+ For a new project, the only required inputs are:
22
+
23
+ 1. [Project Plan](../../PLAN.md)
24
+ 2. [this skill file](./SKILL.md)
25
+
26
+ Everything else is optional and may be bootstrapped by this skill.
27
+
28
+ ## Required startup reads
29
+
30
+ Read the canonical entrypoint briefing first: [Entrypoint Strategies](../docs/entrypoint-strategies.md#local-implementation). Then read only what the current step needs:
31
+
32
+ - [Agent Instructions](../../AGENTS.md) (repo constitution)
33
+ - [Public Dev Loop Contract](../docs/public-dev-loop-contract.md)
34
+ - [Retrospective Checkpoint Contract](../docs/retrospective-checkpoint-contract.md) (when async state applies)
35
+ - [Project Plan](../../PLAN.md) and phase/tracker docs when relevant
36
+ - Relevant issue/PR, validation surface, and task files
37
+
38
+ Treat missing optional files as normal bootstrap conditions, not errors.
39
+
40
+ ### Tracker-backed local implementation
41
+
42
+ Local implementation supports two durable spec inputs:
43
+
44
+ - phase-doc-backed local sessions ([Phase Plan](../../docs/phases/phase-x.md) is canonical)
45
+ - tracker-backed local sessions (the tracker issue is canonical)
46
+
47
+ Tracker-backed local implementation stays inside the existing `local_implementation` path. For sub-issue tree decomposition, see [Sub-Issue Tree Contract](../../docs/sub-issue-tree-contract.md) (this is a source-repo reference; it is not part of the bundled `../docs/` runtime contract surface for installed skill copies). It does not introduce a new routing mode.
48
+
49
+ When the local spec already lives in a tracker issue:
50
+
51
+ - resolve the tracker reference deterministically from a GitHub issue URL or explicit `<owner/name>` + issue number
52
+ - use the bounded GitHub helper `scripts/github/resolve-tracker-local-spec.mjs` when you need a machine-readable spec bundle
53
+ - treat the tracker issue title/body/url/state as the durable local spec bundle
54
+ - do not create or read [Phase Plan](../../docs/phases/phase-x.md) for that same tracker-backed session
55
+ - sync durable scope / acceptance / status changes back to the tracker issue rather than maintaining a duplicate local phase doc
56
+ - keep `tmp/` as temporary local execution state only; it does not become a second durable spec surface
57
+ - for tracker-backed sessions, the handoff path is always: push the working branch → open a PR → merge via GitHub
58
+ - for tracker-backed sessions, PR creation must always include `--assignee @me` so the new PR is self-assigned, and the PR body must contain `Closes #N` (or `Fixes #N`) for the linked issue so GitHub auto-closes it on merge. When `.devloops` sets `workflow.requireDraftFirst` to true, use `dev-loops pr create-draft --assignee @me ...`. Do not create a fresh PR directly in ready-for-review state unless the user explicitly overrides that policy for the current PR scope. The draft gate inspection is a real workflow boundary.
59
+ - do not suggest a direct local-main merge for tracker-backed sessions; do not merge the working branch into local `main` at phase completion
60
+
61
+ ## Primary execution rules
62
+
63
+ ### Step 0: Pre-flight gate (mandatory for local_implementation)
64
+
65
+ For the `local_implementation` strategy, before any planning or implementation mutation, run the pre-flight gate:
66
+
67
+ ```sh
68
+ node scripts/loop/pre-flight-gate.mjs --expected-branch <working-branch> --check-subagents
69
+ ```
70
+
71
+ Before creating or reusing a worktree for local implementation, always run `git fetch origin` first. Always create worktrees from a freshly fetched `origin/main`. The fetched `origin/main` is the authoritative base for all worktree creation.
72
+
73
+ This validates:
74
+ - Worktree isolation (current directory is under `tmp/worktrees/`)
75
+ - Branch identity (current branch matches the working branch)
76
+ - Subagent availability (subagents should be used for fan-out when available)
77
+
78
+ If the gate fails, **stop and fix the violation** before proceeding. Do not bypass the gate in normal workflow execution.
79
+
80
+ Note: `--check-subagents` is advisory — it reports availability but does not block the gate. The worktree and branch checks are the mandatory gates.
81
+
82
+ This gate does **not** apply to other routed strategies (`copilot_pr_followup`, `external_pr_followup`, `reviewer_fixer`, `wait_watch`, `final_approval`, `issue_intake`). Those strategies have their own execution rules and may edit code from any checkout as needed.
83
+
84
+ Development-only bypass (`PI_PREFLIGHT_BYPASS=1`) exists for testing the gate itself but must not be used in production workflow runs. The bypass variable is a testing convenience, not an operational escape hatch.
85
+
86
+ ### Step 1
87
+
88
+ - Implement **one phase at a time**.
89
+ - Do not refine later phases in detail before the current phase is complete.
90
+ - Use the `refiner` agent for phase-refinement work when subagents are available; escalate RFC-worthy technical decisions to the parent session / human operator.
91
+ - Work **test-first** for all non-trivial logic.
92
+ - Maintain **90% coverage** thresholds.
93
+ - Log detailed iteration artifacts under `tmp/` using the required structure below.
94
+ - For phase-doc-backed local sessions, keep durable phase intent and acceptance criteria in [Phase Plan](../../docs/phases/phase-x.md); for tracker-backed local sessions, keep that durable intent in the tracker issue and do not duplicate it into [Phase Plan](../../docs/phases/phase-x.md). Keep detailed execution artifacts in `tmp/`.
95
+ - Treat `tmp/` as temporary local execution state. Do not rely on it as durable repo history and do not force-add it to git unless the user explicitly wants checked-in examples or fixtures.
96
+ - When a phase changes durable product truth in ways `PLAN.md` should express (for example command surface, accepted product decisions, resolved open questions, or scope changes), update [Project Plan](../../PLAN.md) before closing the phase.
97
+ - Do implementation work on a dedicated local branch, not directly on `main`.
98
+ - If the repo has no commits yet, still create the working branch first so the first commits land off `main`; only move `main` forward after review and validation.
99
+ - Use small atomic local commits as progress checkpoints whenever a coherent slice is green and reviewable.
100
+ - Before a branch is considered review-complete, approval-ready, merge-ready, or ready for final handoff, run the default pre-approval gate as a full review / fix loop with the review angles resolved from config (`resolveGateAngles(config, "preApproval")`), then apply accepted fixes and rerun validation. Shipped defaults include the `deep` angle.
101
+ - A phase is only fully complete when its scoped work, required support files, artifacts, validation, review/fix pass, commit(s), and finalization (merge into local `main` for phase-doc-backed sessions; PR merge for tracker-backed sessions) are done, or when the only remaining step is an explicitly noted authorization-gated finalization action.
102
+ - When subagents are used, log what each subagent was asked to do and what it concluded.
103
+ - If [Project Plan](../../PLAN.md) is too rough or ambiguous to safely start the current phase, do not guess: run a clarification/interview step with the user first.
104
+
105
+ ## Structural quality
106
+
107
+ Apply [Structural Quality](../docs/structural-quality.md) from the `deep` review angle.
108
+
109
+ ## Light mode (small changes) — config-only
110
+
111
+ Light mode is currently **config-only**: the schema, resolver, and scope detector are implemented, but no functional wiring exists yet in the local-implementation flow. When scope is small enough, the intent is to skip fan-out/fan-in and use a single review pass instead. Light mode will still require validation and pre-approval gate once wired.
112
+
113
+ **Eligibility:** ≤3 files AND ≤200 lines changed (configurable via `.devloops` field `localImplementation.lightMode`).
114
+
115
+ Use `scripts/loop/detect-change-scope.mjs` to determine eligibility:
116
+ ```sh
117
+ node scripts/loop/detect-change-scope.mjs
118
+ ```
119
+
120
+ **Planned light mode path (not yet wired):**
121
+ 1. Validation (`npm run verify`)
122
+ 2. Single review pass (not multi-angle fan-out)
123
+ 3. Pre-approval gate
124
+ 4. Finalization
125
+
126
+ **Override threshold:**
127
+ ```yaml
128
+ localImplementation:
129
+ lightMode:
130
+ enabled: true
131
+ maxFiles: 5
132
+ maxLines: 300
133
+ ```
134
+
135
+ Disabled by default (opt-in). Scope above threshold falls back to full fan-out/fan-in path.
136
+
137
+ ## Deterministic logging structure
138
+
139
+ Treat the workflow as three layers:
140
+ - [Project Plan](../../PLAN.md) = strategic product and architecture truth
141
+ - [Phase Plan](../../docs/phases/phase-x.md) or the canonical tracker issue = durable per-phase plan and acceptance criteria for the active local session
142
+ - `tmp/` = temporary local execution audit trail and machine-friendly continuation state
143
+
144
+ Maintain the core paths below while the phase is active locally, and create optional artifacts only when they are actually used:
145
+
146
+ Core paths:
147
+ - for phase-doc-backed local sessions: [Phase Plan](../../docs/phases/phase-x.md)
148
+ - `tmp/phases/index.json`
149
+ - `tmp/phases/phase-x/manifest.json`
150
+ - `Variant A` (`tmp/phases/phase-x/variant-a.md`)
151
+ - `Variant B` (`tmp/phases/phase-x/variant-b.md`)
152
+ - `Merged Plan` (`tmp/phases/phase-x/merged-plan.md`)
153
+ - `Phase Review` (`tmp/phases/phase-x/review.md`)
154
+ - `Phase Summary` (`tmp/phases/phase-x/summary.md`)
155
+ - `Retrospective` (`tmp/phases/phase-x/retrospective.md`)
156
+
157
+ Optional when used:
158
+ - `Variant C` (`tmp/phases/phase-x/variant-c.md`)
159
+ - `tmp/phases/phase-x/subagents/`
160
+ - `tmp/phases/phase-x/subagents/raw/`
161
+ - `tmp/phases/phase-x/bash-exit-1.jsonl`
162
+ - `Clarification Log` (`tmp/phases/phase-x/clarification.md`)
163
+ - in dev mode: `tmp/phases/phase-x/dev-mode-context.json`
164
+ - in dev mode: `Dev Mode Review` (`tmp/phases/phase-x/dev-mode-review.md`) as optional analytical notes when they help shape the retrospective
165
+ - in dev mode: `Dev Mode Retrospective` (`tmp/phases/phase-x/dev-mode-retrospective.md`)
166
+ - in dev mode: `Dev Mode Skill Changes` (`tmp/phases/phase-x/dev-mode-skill-changes.md`)
167
+
168
+ Use the templates in `../dev-loop/templates/` (the sibling `skills/dev-loop/templates/` directory in this repo).
169
+
170
+ Use deterministic helper scripts from `../dev-loop/scripts/` (the sibling `skills/dev-loop/scripts/` directory in this repo; in installed-skill layouts these live at `../dev-loop/scripts/` relative to this skill file, not inside this skill's own directory) for repeatable support tasks such as phase initialization, phase-file updates, template materialization, bash-exit logging, and dev-mode context collection.
171
+
172
+ ## Bootstrap missing support files
173
+
174
+ If these files are missing, create them from the `../dev-loop/templates/` directory before continuing:
175
+
176
+ - missing [Agent Instructions](../../AGENTS.md) -> create from [Bootstrap Agents Template](../dev-loop/templates/bootstrap-agents.md)
177
+ - missing [Implementation State](../../docs/IMPLEMENTATION_STATE.md) -> create from [Bootstrap Implementation State Template](../dev-loop/templates/bootstrap-implementation-state.md)
178
+ - missing [Implementation Workflow](../../docs/IMPLEMENTATION_WORKFLOW.md) -> create from [Bootstrap Implementation Workflow Template](../dev-loop/templates/bootstrap-implementation-workflow.md)
179
+ - missing [Phase Plan](../../docs/phases/phase-x.md) for the active phase -> create from [Phase Doc Template](../dev-loop/templates/phase-doc.md)
180
+ - missing `tmp/phases/index.json` -> create or reinitialize it
181
+
182
+ The bootstrap files are support infrastructure. [Project Plan](../../PLAN.md) remains the product source of truth. For phase-doc-backed local sessions, [Phase Plan](../../docs/phases/phase-x.md) is the durable source of truth for the current phase's plan and acceptance boundary. For tracker-backed local sessions, the tracker issue is that durable source of truth, and no duplicate local phase doc should be bootstrapped.
183
+
184
+ For bootstrap/setup phases, do not mark the phase `completed` or `awaiting-finalization` until the expected durable support files for the chosen workflow contract actually exist in the repository. Temporary `tmp/` execution artifacts do not need to be committed.
185
+ ## Plan sufficiency check
186
+
187
+ Before phase planning, check whether [Project Plan](../../PLAN.md) contains enough information to proceed safely.
188
+
189
+ At minimum, the current phase needs enough information to infer:
190
+ - the goal of the phase
191
+ - the main constraints
192
+ - the intended scope or boundaries
193
+ - at least rough acceptance criteria or success shape
194
+
195
+ If that information is missing or too ambiguous, pause implementation and run a clarification/interview step.
196
+
197
+ ## Clarification / interview step
198
+
199
+ When the plan is insufficient, use one of these modes:
200
+
201
+ ### Mode A — interactive clarification
202
+ - ask only the missing high-value questions needed to safely refine the current phase
203
+ - prefer a short interview or wizard-style sequence over one giant question dump
204
+ - record the answers in `Clarification Log` (`tmp/phases/phase-x/clarification.md`)
205
+ - update [Phase Plan](../../docs/phases/phase-x.md) with clarified durable phase intent, scope, or acceptance criteria
206
+ - update [Project Plan](../../PLAN.md) only if the clarified information is durable product/project truth beyond the current phase
207
+ - update [Implementation State](../../docs/IMPLEMENTATION_STATE.md) if the clarification changes the next phase boundary
208
+
209
+ ### Mode B — auto clarification
210
+ Use this when the user explicitly asks for an auto option, says to just proceed, or is clearly optimizing for speed over discussion.
211
+
212
+ In auto mode:
213
+ - infer the smallest safe defaults for the current phase only
214
+ - prefer conservative assumptions over ambitious ones
215
+ - never auto-resolve product, security, or architecture decisions that could materially change scope
216
+ - write all assumptions to `Clarification Log` (`tmp/phases/phase-x/clarification.md`)
217
+ - mark them clearly as `auto-assumptions`
218
+ - surface the assumptions in the phase plan audit so they can be challenged later
219
+ - if an assumption is too risky to make safely, stop and ask the user anyway
220
+
221
+ Do not begin fan-out planning until the current phase is sufficiently specified, either by user clarification or safe auto-assumptions.
222
+
223
+ ## Determine where to resume
224
+
225
+ Read [Implementation State](../../docs/IMPLEMENTATION_STATE.md) and identify the next unfinished phase.
226
+ Read [Phase Plan](../../docs/phases/phase-x.md) for that phase if it exists.
227
+
228
+ If `tmp/phases/index.json` exists locally, use it as a fast index for prior artifacts.
229
+ If the durable phase doc, the state file, and the tmp index disagree, trust docs first and note the mismatch in the phase plan audit log.
230
+
231
+ If the state file is ambiguous, resolve ambiguity conservatively:
232
+ - prefer the earliest clearly unfinished phase
233
+ - do not skip ahead
234
+ - note the ambiguity in the phase plan audit log under `tmp/`
235
+ - if this is a first-run bootstrap, start from the earliest phase implied by [Project Plan](../../PLAN.md)
236
+
237
+ ## Phase planning loop
238
+
239
+ For the **current phase only**, run this loop before implementation.
240
+
241
+ ### 1. Create or update the durable phase doc and tmp scaffold
242
+
243
+ Use paths like:
244
+ - `docs/phases/phase-0.md`
245
+ - `tmp/phases/phase-0/`
246
+ - `docs/phases/phase-1.md`
247
+ - `tmp/phases/phase-1/`
248
+
249
+ Create or update:
250
+ - [Phase Plan](../../docs/phases/phase-x.md)
251
+ - `tmp/phases/phase-x/manifest.json`
252
+ - `tmp/phases/index.json`
253
+
254
+ Prefer the deterministic helper:
255
+ - `../dev-loop/scripts/init-phase.mjs`
256
+
257
+ Use `../dev-loop/scripts/phase-files.mjs` only when you need a narrower manifest/index update without regenerating the standard phase-planning scaffold.
258
+
259
+ ### 2. Read the previous phase's learning before planning the next one
260
+
261
+ If a previous phase exists, read:
262
+ - its `summary.md`
263
+ - its `retrospective.md`
264
+ - any relevant subagent summaries
265
+
266
+ Use those lessons to improve the current phase plan.
267
+
268
+ ### 2b. Optional bounded refinement audit
269
+
270
+ Before variant fan-out, optionally run one bounded audit when the active phase would benefit from slop-risk discovery, structural drift discovery, or adjacent cleanup discovery.
271
+
272
+ When used:
273
+ - run one bounded audit before variant fan-out
274
+ - write the audit artifact to `tmp/phases/phase-x/audit/refinement-audit-summary.json`
275
+ - use `node scripts/loop/run-refinement-audit.mjs --paths ... --output tmp/phases/phase-x/audit/refinement-audit-summary.json`
276
+ - pass a concise audit summary into every refiner briefing
277
+ - keep the audit opt-in; do not turn it into a mandatory precondition
278
+ - preserve prioritized findings, the highest-value follow-up candidates, and an explicit statement of what this phase will not rewrite or broaden in the merged plan and review artifacts
279
+
280
+ ### 3. Fan out short plan variants
281
+
282
+ Write 2-3 short variants:
283
+ - `Variant A` (`tmp/phases/phase-x/variant-a.md`) = smallest safe implementation
284
+ - `Variant B` (`tmp/phases/phase-x/variant-b.md`) = best practical UX/developer-experience option within phase scope
285
+ - `Variant C` (`tmp/phases/phase-x/variant-c.md`) = safest boundary/risk-reduction option when useful
286
+
287
+ When subagents are available, the default refinement path should use the `refiner` role and **parallel fresh-context subagents** so the variants are independently generated rather than serially contaminated by one another. Pass each refiner a concise written briefing summary instead of relying on forked parent-session context.
288
+
289
+ For future refinement hardening, treat the `variant-a` / `variant-b` pattern as the stable inner fan-out shape for a given persona or review angle. Do not switch personas halfway through one `a/b` pair. Instead, when more hardening is needed, run multiple fresh-context fan-out passes with different personas or angles, each with its own consistent `a/b` pair, and then merge across those persona-specific passes.
290
+
291
+ Each refiner variant should make room for:
292
+ - explicit non-goals
293
+ - complete acceptance criteria
294
+ - a complete definition of done
295
+ - risks and unresolved questions
296
+ - when a bounded audit artifact exists: prioritized findings, highest-value follow-up candidates, and what the phase will not rewrite or broaden
297
+ - RFC escalation notes when technical decisions should go to the parent session / human operator
298
+ - for watcher/predicate-heavy phases: explicit negative-case tests and timeout semantics, including any zero-timeout or single-check contract
299
+
300
+ Use the template in [Phase Variant Template](../dev-loop/templates/phase-variant.md).
301
+
302
+ Each variant should cover only:
303
+ - scope for this phase
304
+ - files/modules touched
305
+ - tests to add first
306
+ - implementation order
307
+ - acceptance criteria
308
+ - risks/non-goals
309
+
310
+ When a phase includes a bounded audit, inventory, or scan:
311
+ - treat the scan as a first-class deliverable rather than an implicit side note
312
+ - require prioritized findings, not an unbounded dump
313
+ - state explicitly what the scan does **not** authorize or rewrite in the current phase
314
+
315
+ If subagents generate the variants:
316
+ - run them in parallel with clean context when practical
317
+ - give each variant generator a concise briefing summary that includes phase objective, in-scope work, constraints, known risks, and required outputs
318
+ - keep each `variant-a` / `variant-b` pair anchored to one persona or refinement angle so the alternatives are directly comparable
319
+ - when you want broader hardening, add another fan-out pass with a different persona or angle and its own `variant-a` / `variant-b` pair instead of blending multiple personas into one pair
320
+ - do not fork the parent session just to share planning context; summarize it instead
321
+ - save raw subagent outputs under `tmp/phases/phase-x/subagents/raw/` only when keeping the raw capture is actually useful
322
+ - then write the human-oriented `Variant A` (`tmp/phases/phase-x/variant-a.md`) / `Variant B` (`tmp/phases/phase-x/variant-b.md`) / `Variant C` (`tmp/phases/phase-x/variant-c.md`) files from those raw outputs when applicable
323
+
324
+ Update `manifest.json` with the planned artifact list and current status.
325
+
326
+ ### 4. Fan in to a merged phase plan
327
+
328
+ Write:
329
+ - `Merged Plan` (`tmp/phases/phase-x/merged-plan.md`)
330
+ - update [Phase Plan](../../docs/phases/phase-x.md) with the selected durable phase plan
331
+
332
+ Use the templates in [Merged Phase Plan Template](../dev-loop/templates/merged-phase-plan.md) and [Phase Doc Template](../dev-loop/templates/phase-doc.md).
333
+
334
+ The merged plan must include:
335
+ - exact scope for this phase
336
+ - explicit non-goals
337
+ - tests to write first
338
+ - implementation order
339
+ - validation steps
340
+ - acceptance criteria
341
+ - definition of done
342
+ - when a bounded audit artifact exists: prioritized findings, highest-value follow-up candidates, and an explicit statement of what this phase will not rewrite or broaden
343
+ - RFC escalation notes for any RFC-worthy technical decisions that must go to the parent session / human operator instead of being silently resolved during refinement
344
+ - for any new CLI surface: explicit success-output and malformed-argument/error-contract expectations
345
+ - for any watcher/predicate-driven behavior: explicit timeout semantics plus negative-case detection rules for non-target identities or events
346
+ - for package-first phases in a source-loaded workspace: explicit expectations about whether callers consume shared logic through workspace/source adapters or published package import paths during local development
347
+
348
+ The durable phase doc should capture the subset that a fresh human or agent should read first: objective, why now, scope, non-goals, acceptance criteria, definition of done, validation approach, durable decisions, and open questions.
349
+
350
+ ### 5. Review the merged phase plan adversarially
351
+
352
+ Write:
353
+ - `Phase Review` (`tmp/phases/phase-x/review.md`)
354
+
355
+ Use the template in [Review Template](../dev-loop/templates/review.md).
356
+ Ensure the durable phase doc still matches the reviewed plan; update [Phase Plan](../../docs/phases/phase-x.md) if the review changes accepted scope or criteria.
357
+
358
+ The review must check for:
359
+ - overreach beyond phase scope
360
+ - KISS/SRP/YAGNI violations
361
+ - missing tests
362
+ - weak validation
363
+ - unclear module boundaries
364
+ - hidden coupling to Pi runtime internals
365
+ - ambiguous acceptance criteria
366
+ - unclear or incomplete definition-of-done output
367
+ - missing review-surface completeness
368
+ - weak RFC-escalation sanity when the plan surfaces an unresolved technical decision
369
+ - for bounded audits/scans: missing prioritization or quiet expansion into a broad rewrite
370
+ - for new CLI surfaces: weak malformed-argument or error-contract coverage
371
+ - for watcher/predicate-heavy behavior: weak timeout semantics or missing negative-case tests for non-target activity
372
+ - for package-first phases: ambiguous source-loaded workspace integration boundaries that leave local scripts/tests guessing how shared helpers are consumed
373
+
374
+ If the review finds real issues, revise the merged plan and briefly update the review.
375
+
376
+ ### 6. Only then start implementation
377
+
378
+ Do not begin coding before the merged phase plan has passed review.
379
+ Update `manifest.json` to show that phase implementation has started.
380
+
381
+ ## Task breakdown & delegation
382
+
383
+ After the merged phase plan passes review and before implementation starts, break the phase
384
+ into parallel executable tasks and dispatch them to the right specialist subagents.
385
+
386
+ ### Task decomposition
387
+
388
+ 1. Read the merged phase plan and identify independent work slices.
389
+ 2. Break each slice into a discrete task with explicit acceptance criteria, required files,
390
+ and expected verification.
391
+ 3. Prefer parallel dispatch of non-overlapping tasks.
392
+ 4. Treat task ordering as: parallel-independent work first, then dependent work that requires
393
+ a prior task's output.
394
+
395
+ ### Delegation contract
396
+
397
+ Dispatch implementation tasks to dedicated specialist agents:
398
+
399
+ | Task type | Delegate to |
400
+ |---|---|
401
+ | Code changes, refactors, tests, bug fixes, feature work | `developer` |
402
+ | Build systems, CI, test runners, type-checking, linting | `quality` |
403
+ | README, plan docs, agent docs, migration notes | `docs` |
404
+ | Review-comment follow-up, PR fix commits | `fixer` |
405
+
406
+ For each delegated task:
407
+ - give the subagent one focused task with exact success criteria
408
+ - include only the minimum relevant files, plans, and repo context
409
+ - tell the subagent whether it should implement, verify, or review
410
+ - require the subagent to report blockers, verification results, and changed files
411
+ - avoid circular delegation and overlapping scopes
412
+
413
+ ### Status monitoring
414
+
415
+ Track each dispatched task:
416
+ - at minimum record agent name, task summary, status (`queued`, `running`, `done`, `failed`),
417
+ and output artifacts
418
+ - when tasks are dispatched asynchronously, check status periodically
419
+ - if a subagent exits while the task is still non-terminal, resume or re-dispatch
420
+
421
+ ### Consolidation
422
+
423
+ After all dispatched tasks complete:
424
+ 1. Collect results and verification output from each task.
425
+ 2. Review that each task's acceptance criteria are genuinely satisfied.
426
+ 3. Resolve any coordination gaps or overlapping changes.
427
+ 4. Proceed to the implementation loop for the phase once all tasks are green.
428
+
429
+ ## Subagent summary logging
430
+
431
+ If subagents are used for planning, review, research, or implementation support:
432
+
433
+ Create one summary file per subagent run under:
434
+ - `tmp/phases/phase-x/subagents/`
435
+
436
+ Recommended naming:
437
+ - `001-planner.md`
438
+ - `002-reviewer-correctness.md`
439
+ - `003-reviewer-maintainability.md`
440
+ - `004-worker-followup.md`
441
+
442
+ Each summary must include a machine-readable header block using bullet-key format so
443
+ `conductor-monitor.mjs` can detect and parse local phase subagent state:
444
+
445
+ ```
446
+ - agent name: <developer|quality|docs|review|refiner|fixer>
447
+ - status: <queued|running|completed|failed|paused>
448
+ - run id: <subagent-run-id>
449
+ - task: <one-line task summary>
450
+ - cwd: <working directory>
451
+ ```
452
+
453
+ Only `agent name` and `status` are required for conductor-monitor detection; the
454
+ other fields improve resume-plan quality. The header block must start at the
455
+ beginning of a line (no leading whitespace before the bullet).
456
+
457
+ Below the header, include human-readable context:
458
+ - whether it was sync or async
459
+ - why it was used
460
+ - main findings or output
461
+ - files or artifacts it influenced
462
+ - whether its advice was accepted, partially accepted, or rejected
463
+ - raw output path if output was saved separately
464
+
465
+ If the subagent ran asynchronously, update its summary when results arrive so fresh sessions can understand what happened without replaying the whole conversation.
466
+
467
+ ## Workflow-run subagent hand-off contract
468
+
469
+ When handing off a full workflow run to a subagent (draft PR → gates → Copilot → merge),
470
+ use the canonical hand-off contract. Do not rely on abbreviated task summaries or operator
471
+ memory.
472
+
473
+ The canonical contract is [Workflow Handoff Contract](../docs/workflow-handoff-contract.md) (source-tree path: `skills/docs/workflow-handoff-contract.md`). It includes:
474
+ - direct contract-doc references the subagent must read before executing
475
+ - a mandatory 8-step checklist (draft PR → draft_gate → ready → Copilot → resolve → pre_approval_gate → merge)
476
+ - non-negotiable invariants (Copilot review loop between gates, `unresolvedThreadCount === 0`, visible gate comments)
477
+
478
+ For all GitHub-first routed follow-up (`copilot_pr_followup`, `issue_intake`), the
479
+ `local-implementation` skill uses this template when delegating the full run to a subagent.
480
+ Reference it by path, not by memory.
481
+
482
+ ## Implementation loop for the phase
483
+
484
+ After the phase plan passes review:
485
+
486
+ 1. Write or update tests first.
487
+ 2. Implement only enough code for the current phase.
488
+ 3. Run local validation:
489
+ - `npm run verify`
490
+ - when a narrower local check is more honest for the touched slice, say so explicitly and run the narrowest justified subset instead of pretending the full verify path was unnecessary
491
+ - for user-facing HTML/UI/component slices when the user opts in, add a bounded deterministic browser smoke harness (prefer fixture-backed Playwright WebKit plus screenshot capture); use `npm run test:playwright:viewer` when that viewer/browser surface is part of the slice, and wire it into CI once it becomes required validation for that slice
492
+ - **Commit immediately after validation passes.** Once `npm run verify` (or the narrowest justified validation subset) is green, stage and commit the current slice of work with an atomic commit message. For tracker-backed sessions, also push the commit. In non-interactive subagent sessions, commit authorization is implicit — the subagent was dispatched to implement and must commit before exiting. In interactive sessions, wait for coordination agent authorization. Do not defer commits — uncommitted changes when the session terminates are a workflow defect.
493
+ 4. Review the implementation against the merged phase plan.
494
+ 5. Run the default pre-approval gate as a full review / fix loop on the branch before calling it review-complete, approval-ready, merge-ready, or ready for final handoff:
495
+ - resolve review angles from config: `resolveGateAngles(config, "preApproval")` from `@dev-loops/core/config` (shipped defaults enable all 11 pre-approval gate angle families; consumer repos may opt out individual angles via `excludeAngles`); run via the chain prescription below
496
+ - run the resolved angle-focused passes in parallel with fresh context when practical
497
+ - if parallel execution is impractical (for example due to tooling or resource constraints), run all angles sequentially and explicitly record why parallel execution was impractical in `Phase Review` (`tmp/phases/phase-x/review.md`) (or the equivalent merged review artifact)
498
+ - for each angle, resolve its persona and prompt via `resolveReviewerRole(config, angle)` — start each reviewer in fresh context with a concise briefing including the angle-specific prompt, the branch/phase, intended behavior, acceptance criteria, relevant files or artifacts, and current validation status
499
+ - run the mandatory chain defined in [Gate Review Sub-Loop Contract](../../docs/gate-review-sub-loop-contract.md). Retry rule: in subsequent cycles, only re-run reviewers that produced findings in the previous pass. Do not fork the parent session for parallel reviewers; write a compact handoff artifact under `tmp/` and point the reviewer at it.
500
+ - when reviewer subagents stumble on raw source-tree reads (for example unresolved build artifacts or import assumptions), generate a deterministic diff/review artifact under `tmp/` and have reviewers inspect that artifact instead of the raw file set
501
+ - synthesize actionable findings
502
+ - apply accepted fixes on the same branch
503
+ - rerun validation after fixes
504
+ - log review artifacts and subagent summaries under `tmp/`
505
+ 6. Update [Phase Plan](../../docs/phases/phase-x.md) so it reflects the phase as actually implemented, including any accepted scope or validation changes.
506
+ 7. Update [Project Plan](../../PLAN.md) when the phase changed durable product truth, resolved an open question, or made the shipped command/behavior surface more concrete.
507
+ 8. Write `Phase Summary` (`tmp/phases/phase-x/summary.md`) using [Phase Summary Template](../dev-loop/templates/phase-summary.md).
508
+ 9. Write `Retrospective` (`tmp/phases/phase-x/retrospective.md`) using [Retrospective Template](../dev-loop/templates/retrospective.md).
509
+ 10. Update `tmp/phases/phase-x/manifest.json` and `tmp/phases/index.json`.
510
+ 11. Update [Implementation State](../../docs/IMPLEMENTATION_STATE.md).
511
+ 12. **Exit validation gate — no uncommitted changes.** Before the subagent session terminates, run `git status --porcelain` and verify the output is empty. If uncommitted changes exist, first determine whether they are intended implementation changes or unintended/post-validation deltas. Revert any unintended or speculative changes. For intended changes, rerun the narrowest justified validation (`npm run verify` or equivalent) before staging and committing with an appropriate message; for tracker-backed sessions, also push the branch. A subagent session that exits with uncommitted changes in the worktree is a workflow defect and must not be treated as a clean completion. After committing, verify `git status --porcelain` is empty before declaring phase completion.
512
+ 13. For tracker-backed sessions, create a draft PR from the working branch using `dev-loops pr create-draft --assignee @me --repo <owner/name> --base main --head <branch> --title "..." --body-file <body-file>`. When the `dev-loops` CLI helper is unavailable, use the equivalent `create-draft-pr.mjs` script directly: `node <resolved-skill-scripts>/github/create-draft-pr.mjs --repo <owner/name> --assignee @me --base main --head <branch> --title "..." --body-file <body-file>`. The PR body must contain `Closes #N` (or `Fixes #N`) for the linked issue. Do not create a fresh PR directly in ready-for-review state unless the user explicitly overrides that policy.
513
+ 14. If authorized, merge the fully reviewed, locally validated phase branch back into local `main` (phase-doc-backed sessions) or proceed through the PR gate pipeline (tracker-backed sessions).
514
+ 15. If authorization for PR creation or merge is still pending (commit authorization is already enforced by the exit validation gate in step 12), mark the phase as `awaiting-finalization` rather than `completed`, and record exactly which finalization step is pending.
515
+
516
+ ## Retrospective requirements
517
+
518
+ The retrospective must capture:
519
+ - what worked well in the local dev loop
520
+ - what caused friction or waste
521
+ - whether the fan-out/fan-in/review loop improved the phase
522
+ - what should change in the skill or workflow next time
523
+ - what a fresh session should know before the next phase
524
+
525
+ This is the infrastructure for self-improvement. Do not skip it.
526
+
527
+ ## Dev mode
528
+
529
+ Dev mode is for improving the local implementation loop itself while using it.
530
+
531
+ A repository may also declare a formal-dev-mode default through `.devloops` field `workflow.devModeDefault`. Treat that config as the policy source of truth when present, but explicit user opt-in or opt-out for the current run still wins. Runtime consumption of that config may be staged separately from this documentation update.
532
+
533
+ Trigger it when the user explicitly asks for dev mode, self-improvement mode, or says they want the skill to refine itself as it goes.
534
+
535
+ In dev mode, after the normal phase summary and retrospective are written, run one extra bounded self-improvement pass before moving on:
536
+
537
+ 1. collect a deterministic context bundle for the phase using:
538
+ - `../dev-loop/scripts/dev-mode-context.mjs`
539
+ - output to `tmp/phases/phase-x/dev-mode-context.json`
540
+ 2. review the phase artifacts and logs with emphasis on the workflow itself:
541
+ - planning quality
542
+ - review quality
543
+ - validation friction
544
+ - bash exit-code-1 patterns
545
+ - places where skill or agent prompts should be tightened
546
+ - places where deterministic tooling should replace ad hoc work
547
+ 3. write `Dev Mode Retrospective` (`tmp/phases/phase-x/dev-mode-retrospective.md`)
548
+ - this is the required dev-mode retrospective artifact
549
+ - it should name the highest-value prompt/workflow follow-ups revealed by the phase
550
+ 4. optionally write `Dev Mode Review` (`tmp/phases/phase-x/dev-mode-review.md`) when separate analytical notes help support the retrospective
551
+ 5. apply at least one bounded follow-up update to a relevant skill and/or agent prompt
552
+ - deterministic tooling, docs, templates, or tests may accompany that change
553
+ - but they do not replace the required prompt update
554
+ - keep the change phase-bounded and tied directly to the retrospective findings
555
+ 6. write `Dev Mode Skill Changes` (`tmp/phases/phase-x/dev-mode-skill-changes.md`)
556
+ - record which skill and/or agent prompts changed
557
+ - record any supporting tooling/docs/template changes that accompanied them
558
+ - if no prompt update can be justified safely, stop and report that dev-mode exit criteria were not met
559
+ 7. if skill scripts or deterministic tooling changed, rerun the skill-local tests
560
+ 8. stop after this bounded self-improvement pass; do not recurse into endless self-editing loops
561
+
562
+ Dev mode is still phase-bounded. It improves the loop around the completed phase; it does not authorize work on the next product phase.
563
+
564
+ ## tmp/ logging requirements
565
+
566
+ At minimum, each phase should leave behind:
567
+ - a durable phase doc at [Phase Plan](../../docs/phases/phase-x.md)
568
+ - local `tmp/` execution artifacts needed to resume and audit the phase, including:
569
+ - `manifest.json`
570
+ - `Variant A` (`tmp/phases/phase-x/variant-a.md`)
571
+ - `Variant B` (`tmp/phases/phase-x/variant-b.md`)
572
+ - `merged-plan.md`
573
+ - `review.md`
574
+ - `summary.md`
575
+ - `retrospective.md`
576
+ - optional `Variant C` (`tmp/phases/phase-x/variant-c.md`) when a third variant was actually useful
577
+ - `bash-exit-1.jsonl` when any bash call during the phase exited with code `1`
578
+ - `clarification.md` when a plan-sufficiency interview or auto-clarification step was needed
579
+ - subagent summaries when subagents were used
580
+ - raw subagent outputs only when they were saved separately on purpose
581
+ - in dev mode: `dev-mode-context.json`, `dev-mode-retrospective.md`, and `dev-mode-skill-changes.md`
582
+ - optional in dev mode: `dev-mode-review.md` when separate analytical notes were useful
583
+
584
+ These `tmp/` artifacts are normally temporary and do not need to be checked into git.
585
+
586
+ Also log validation output summaries and notable decisions if they help evaluate the local dev loop later.
587
+
588
+ Additionally, append every bash call that exits with code `1` to:
589
+ - `tmp/phases/phase-x/bash-exit-1.jsonl`
590
+
591
+ Use the deterministic helper:
592
+ - `../dev-loop/scripts/log-bash-exit-1.mjs`
593
+
594
+ Each line should be one JSON object with at least:
595
+ - `timestamp`
596
+ - `phase`
597
+ - `cwd`
598
+ - `command`
599
+ - `exitCode`
600
+ - `purpose`
601
+ - `summary`
602
+
603
+ If useful, also include truncated `stdout` and `stderr` fields or a path to a larger saved artifact. This log is for improving the local dev loop itself, so do not skip it just because the command was exploratory.
604
+
605
+ ## Stop conditions
606
+
607
+ See [Stop Conditions](../docs/stop-conditions.md). Local-specific stops: phase completed & finalized, next-phase refinement needed, user/main-agent approval required, validation failure needing direction change.
608
+
609
+ ## Branch / review / merge policy
610
+
611
+ - Do not implement directly on `main`.
612
+ - Start or switch to a dedicated local working branch before the first mutating step.
613
+ - If the repository is unborn (no commits yet), still create the working branch first and make the initial atomic commits there.
614
+ - Use atomic local commits to log progress, but only for coherent reviewable slices.
615
+ - Before merging, run a full parallel review / fix loop and resolve accepted findings on the same branch.
616
+ - Rerun validation after review-driven fixes.
617
+ - A phase is not operationally closed until its branch state is captured in commit history and the reviewed branch has been finalized according to session type (merged into local `main` for phase-doc-backed sessions; merged via GitHub PR for tracker-backed sessions), unless authorization for that finalization is still pending.
618
+ - For tracker-backed sessions, the handoff path is always: push the working branch → open a PR → merge via GitHub; never merge the working branch into local `main`.
619
+ - PR creation must always include `--assignee @me` so the new PR is self-assigned, and the PR body must contain `Closes #N` (or `Fixes #N`) for the linked issue so GitHub auto-closes it on merge. When `.devloops` sets `workflow.requireDraftFirst` to true, use `dev-loops pr create-draft --assignee @me ...`. Do not create a fresh PR directly in ready-for-review state unless the user explicitly overrides that policy for the current PR scope. The draft gate inspection is a real workflow boundary, so a new PR must exist in draft before `gh pr ready` is eligible.
620
+ - When authorization is pending, record the phase as `awaiting-finalization` and describe the exact missing step.
621
+ - For phase-doc-backed sessions, merge the fully reviewed, locally validated branch back into local `main` when authorized.
622
+
623
+ ## Commit policy
624
+
625
+ - Do not commit speculative work.
626
+ - Do not commit before the relevant validation for that slice passes.
627
+ - Immediately before every `git add && git commit` sequence, assert branch identity with `git branch --show-current` and stop if it does not match the intended local working branch.
628
+ - Keep commits small and phase-bounded.
629
+ - Do not leave completed phase work stranded off `main`; once the reviewed branch is ready and authorized, finalize it according to session type (merge into local `main` for phase-doc-backed sessions; complete via PR merge for tracker-backed sessions).
630
+ - Commit only when the coordination/main agent has decided the slice or phase is ready. **Exception:** in non-interactive subagent sessions, commit authorization is implicit — the subagent was dispatched to implement and must commit before exiting (see the commit sub-bullet under implementation loop step 3 and the exit validation gate in step 12).
631
+ - If commit/merge authorization has not yet been given, do not call the phase `completed`; call it `awaiting-finalization` instead.
632
+ - **Subagent exit contract:** before a subagent session terminates, the exit validation gate (implementation loop step 12) must pass — `git status --porcelain` must be empty. A subagent that exits with uncommitted changes in the worktree has not completed its task, regardless of what was implemented.
633
+
634
+ ## Anti-patterns
635
+
636
+ See [Anti-patterns](../docs/anti-patterns.md). Local-specific: don't assume optional plan docs exist, don't guess through missing plan details, don't skip fan-out/fan-in, don't skip `tmp/` artifacts, don't use subagents without readable summaries.