dev-loops 0.7.1 → 0.7.2

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 (86) hide show
  1. package/.claude/.claude-plugin/plugin.json +1 -1
  2. package/.claude/agents/dev-loop.md +7 -7
  3. package/.claude/agents/fixer.md +1 -0
  4. package/.claude/agents/refiner.md +2 -2
  5. package/.claude/agents/review.md +2 -2
  6. package/.claude/commands/loop-enqueue.md +1 -1
  7. package/.claude/commands/loop-info.md +1 -1
  8. package/.claude/commands/loop-start-spike.md +1 -1
  9. package/.claude/skills/copilot-pr-followup/SKILL.md +37 -23
  10. package/.claude/skills/dev-loop/SKILL.md +6 -6
  11. package/.claude/skills/docs/acceptance-criteria-verification.md +3 -2
  12. package/.claude/skills/docs/anti-patterns.md +3 -2
  13. package/.claude/skills/docs/artifact-authority-contract.md +12 -11
  14. package/.claude/skills/docs/confirmation-rules.md +1 -0
  15. package/.claude/skills/docs/contract-style-guide.md +37 -0
  16. package/.claude/skills/docs/copilot-loop-operations.md +18 -14
  17. package/.claude/skills/docs/cross-harness-regression-contract.md +2 -2
  18. package/.claude/skills/docs/debt-remediation-contract.md +1 -1
  19. package/.claude/skills/docs/epic-tree-refinement-procedure.md +25 -22
  20. package/.claude/skills/docs/issue-intake-procedure.md +25 -19
  21. package/.claude/skills/docs/merge-preconditions.md +13 -11
  22. package/.claude/skills/docs/pr-lifecycle-contract.md +44 -35
  23. package/.claude/skills/docs/public-dev-loop-contract.md +59 -43
  24. package/.claude/skills/docs/retrospective-checkpoint-contract.md +18 -5
  25. package/.claude/skills/docs/spike-mode-contract.md +14 -7
  26. package/.claude/skills/docs/stop-conditions.md +30 -15
  27. package/.claude/skills/docs/tracker-first-loop-state.md +13 -8
  28. package/.claude/skills/docs/validation-policy.md +4 -5
  29. package/.claude/skills/local-implementation/SKILL.md +48 -142
  30. package/CHANGELOG.md +6 -0
  31. package/agents/dev-loop.agent.md +8 -8
  32. package/agents/fixer.agent.md +1 -0
  33. package/agents/refiner.agent.md +2 -2
  34. package/agents/review.agent.md +2 -2
  35. package/package.json +5 -4
  36. package/scripts/_core-helpers.mjs +2 -0
  37. package/scripts/claude/headless-dev-loop.mjs +1 -1
  38. package/scripts/docs/validate-rule-ownership.mjs +442 -0
  39. package/scripts/docs/validate-state-machine-conformance.mjs +1092 -0
  40. package/scripts/github/_review-thread-mutations.mjs +5 -2
  41. package/scripts/github/create-pr.mjs +119 -10
  42. package/scripts/github/detect-checkpoint-evidence.mjs +102 -17
  43. package/scripts/github/list-review-threads.mjs +277 -0
  44. package/scripts/github/post-gate-findings.mjs +6 -3
  45. package/scripts/github/request-copilot-review.mjs +92 -26
  46. package/scripts/github/upsert-checkpoint-verdict.mjs +74 -5
  47. package/scripts/github/verify-briefing-prefixes.mjs +191 -0
  48. package/scripts/github/verify-fresh-review-context.mjs +78 -3
  49. package/scripts/github/wait-pr-checks.mjs +171 -0
  50. package/scripts/github/write-gate-context.mjs +213 -7
  51. package/scripts/github/write-gate-findings-log.mjs +54 -2
  52. package/scripts/loop/copilot-pr-handoff.mjs +29 -2
  53. package/scripts/loop/detect-change-scope.mjs +2 -2
  54. package/scripts/loop/detect-copilot-loop-state.mjs +23 -3
  55. package/scripts/loop/detect-pr-gate-coordination-state.mjs +35 -3
  56. package/scripts/loop/resolve-dev-loop-startup.mjs +145 -8
  57. package/scripts/loop/sanctioned-commands.mjs +2 -0
  58. package/scripts/loop/validate-pr-body-spec.mjs +21 -5
  59. package/scripts/pages/build-state-atlas.mjs +50 -48
  60. package/scripts/projects/_resolve-project.mjs +1 -148
  61. package/scripts/projects/list-queue-items.mjs +3 -377
  62. package/scripts/projects/move-queue-item.mjs +3 -410
  63. package/scripts/projects/reorder-queue-item.mjs +3 -22
  64. package/skills/copilot-pr-followup/SKILL.md +37 -23
  65. package/skills/dev-loop/SKILL.md +1 -1
  66. package/skills/docs/acceptance-criteria-verification.md +3 -2
  67. package/skills/docs/anti-patterns.md +3 -2
  68. package/skills/docs/artifact-authority-contract.md +12 -11
  69. package/skills/docs/confirmation-rules.md +1 -0
  70. package/skills/docs/contract-style-guide.md +37 -0
  71. package/skills/docs/copilot-loop-operations.md +18 -14
  72. package/skills/docs/cross-harness-regression-contract.md +2 -2
  73. package/skills/docs/debt-remediation-contract.md +1 -1
  74. package/skills/docs/epic-tree-refinement-procedure.md +25 -22
  75. package/skills/docs/issue-intake-procedure.md +25 -19
  76. package/skills/docs/merge-preconditions.md +13 -11
  77. package/skills/docs/pr-lifecycle-contract.md +44 -35
  78. package/skills/docs/public-dev-loop-contract.md +59 -43
  79. package/skills/docs/required-rules.json +149 -0
  80. package/skills/docs/retrospective-checkpoint-contract.md +18 -5
  81. package/skills/docs/spike-mode-contract.md +14 -7
  82. package/skills/docs/stop-conditions.md +30 -15
  83. package/skills/docs/tracker-first-loop-state.md +13 -8
  84. package/skills/docs/validation-policy.md +4 -5
  85. package/skills/local-implementation/SKILL.md +48 -142
  86. package/scripts/docs/validate-no-duplicate-rules.mjs +0 -250
@@ -1,7 +1,8 @@
1
1
  # Tracker-First Story-to-PR Contract
2
2
 
3
- This document defines the adapter-agnostic MVP contract for the tracker-first
4
- story-to-PR workflow in `dev-loops`.
3
+ Canonical owner for the adapter-agnostic MVP contract for the tracker-first
4
+ story-to-PR workflow in `dev-loops`, and for the tracker-first loop state
5
+ machine (#449).
5
6
 
6
7
  **MVP invariant: one tracker work item → one GitHub PR.**
7
8
 
@@ -30,7 +31,8 @@ Implementation for each:
30
31
  | Epic / PRD reference | Optional linked metadata only; no roll-up or automation in this slice |
31
32
  | ADR / RFC reference | Optional linked metadata only; no decision-sync in this slice |
32
33
 
33
- **Invariant:** For any single tracker work item in scope, there is at most
34
+ <!-- rule: TRACKER-ONE-ACTIVE-PR -->
35
+ For any single tracker work item in scope, there MUST be at most
34
36
  one active GitHub PR at a time. Multi-PR workflows and roll-up automation
35
37
  are out of scope for this slice.
36
38
 
@@ -57,6 +59,9 @@ already-correct PR leaves it unchanged.
57
59
 
58
60
  ### 3.1 Required PR Metadata
59
61
 
62
+ <!-- rule: TRACKER-PROJECTION-REQUIRED-METADATA -->
63
+ Every projected PR MUST carry the following fields:
64
+
60
65
  | Field | Rule |
61
66
  |---|---|
62
67
  | PR title | `[{TRACKER_ID}] {tracker item title}` — bracketed tracker identifier followed by the item title verbatim |
@@ -64,7 +69,7 @@ already-correct PR leaves it unchanged.
64
69
  | PR body — Summary section | Required. Brief description of the change implemented in this PR. |
65
70
  | PR body — Acceptance Criteria section | Required. Copied or linked from the tracker item's acceptance criteria. |
66
71
  | Labels | Required: `tracker:{TRACKER_ID}`. Optional reference labels: `epic:{EPIC_ID}`, `prd:{PRD_ID}` when references are present. |
67
- | Draft state | PR must start as a draft. It must not be marked ready-for-review until development work is complete. |
72
+ | Draft state | PR MUST start as a draft. It MUST NOT be marked ready-for-review until development work is complete. |
68
73
 
69
74
  ### 3.2 Optional Reference Metadata
70
75
 
@@ -85,9 +90,9 @@ They are read-only metadata in this slice and do not trigger any automation:
85
90
  2. **On tracker item field change**: Re-apply projection rules to PR title,
86
91
  body, and labels. Leave any sections not covered by projection rules
87
92
  (e.g. reviewer-added review comments) intact.
88
- 3. **Idempotent regeneration**: If the PR already has the correct title, body
89
- sections, and labels, no mutation is performed. Projection is a no-op
90
- when the current state already matches the target.
93
+ 3. <!-- rule: TRACKER-PROJECTION-IDEMPOTENT --> **Idempotent regeneration**: Projection MUST be a no-op when the PR already has the correct
94
+ title, body sections, and labels re-applying the rules to an already-correct PR MUST NOT
95
+ mutate it.
91
96
 
92
97
  ### 3.4 PR Body Template
93
98
 
@@ -120,7 +125,7 @@ implementations map canonical action names to tracker-native field updates.
120
125
  | `pr_merged` — PR merged | `set_done` | Tracker moves to done/completed terminal state |
121
126
  | `pr_closed_unmerged` — PR closed without merge | `none` | No automatic terminal transition; human decision required |
122
127
  | `no_tracker_item` | `none` | No tracker item to update |
123
- | `blocked_needs_user_decision` | `none` | Stop and report; no automatic tracker update |
128
+ | <!-- rule: TRACKER-BLOCKED-FAIL-CLOSED --> `blocked_needs_user_decision` | `none` | An unexpected or contradictory snapshot MUST stop and report; the helper MUST NOT apply an automatic tracker update |
124
129
 
125
130
  ### 4.2 Event Triggers
126
131
 
@@ -4,9 +4,8 @@ Canonical owner for validation requirements across all workflow families.
4
4
 
5
5
  ## Default validation
6
6
 
7
- - `npm run verify` is the default repo-level local validation path
8
- - Must pass before: PR creation, gate entry, merge
9
- - At minimum: `npm test && npm run test:dev-loop`
7
+ <!-- rule: VALIDATE-VERIFY-BEFORE-GATE -->
8
+ `VALIDATE-VERIFY-BEFORE-GATE`: `npm run verify` is the default repo-level local validation path and MUST pass before PR creation, gate entry, and merge; at minimum this means `npm test && npm run test:dev-loop`.
10
9
 
11
10
  ## Gate-specific requirements
12
11
 
@@ -17,8 +16,8 @@ Canonical owner for validation requirements across all workflow families.
17
16
 
18
17
  ## Coverage requirements
19
18
 
20
- - ≥90% coverage for lines, statements, functions, and branches on changed files
21
- - Test-first for all non-trivial logic
19
+ <!-- rule: VALIDATE-COVERAGE-THRESHOLD -->
20
+ `VALIDATE-COVERAGE-THRESHOLD`: Changed files MUST have ≥90% coverage for lines, statements, functions, and branches, and non-trivial logic MUST be test-first.
22
21
 
23
22
  ## Cross-references
24
23
 
@@ -61,47 +61,38 @@ When the local spec already lives in a tracker issue:
61
61
  - resolve the tracker reference deterministically from a GitHub issue URL or explicit `<owner/name>` + issue number
62
62
  - use the bounded GitHub helper `scripts/github/resolve-tracker-local-spec.mjs` when you need a machine-readable spec bundle
63
63
  - treat the tracker issue title/body/url/state as the durable local spec bundle
64
- - do not create or read [Phase Plan](../../docs/phases/phase-x.md) for that same tracker-backed session
64
+ - the no-duplicate-phase-doc rule is owned by `ARTIFACT-TRACKER-FIRST-NO-DUP` in [Artifact Authority Contract](../docs/artifact-authority-contract.md); do not read [Phase Plan](../../docs/phases/phase-x.md) for that same tracker-backed session either
65
65
  - sync durable scope / acceptance / status changes back to the tracker issue rather than maintaining a duplicate local phase doc
66
66
  - keep `tmp/` as temporary local execution state only; it does not become a second durable spec surface
67
67
  - for tracker-backed sessions, the handoff path is always: push the working branch → open a PR → merge via GitHub
68
- - for tracker-backed sessions, always open PRs through the canonical `dev-loops pr create` path, which is ALWAYS draft and always assigned — self-assigned by default (`--assignee @me` when none is given; honors an explicit `--assignee <login>` / `-a <login>`), never via raw `gh pr create`. 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 --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.
69
- - do not suggest a direct local-main merge for tracker-backed sessions; do not merge the working branch into local `main` at phase completion
68
+ - <!-- rule: LOCAL-PR-CREATE-CANONICAL --> for tracker-backed sessions, you MUST open PRs through the canonical `dev-loops pr create` path always draft and always assigned — self-assigned by default (`--assignee @me` when none is given; honors an explicit `--assignee <login>` / `-a <login>`) and MUST NOT open them via raw `gh pr create`. 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 --assignee @me ...`; the draft-first requirement itself is owned by [`OPS-DRAFT-FIRST-PR`](../docs/copilot-loop-operations.md).
69
+ - <!-- rule: LOCAL-TRACKER-NO-DIRECT-MERGE --> `LOCAL-TRACKER-NO-DIRECT-MERGE`: for tracker-backed sessions, agents MUST NOT suggest a direct local-main merge and MUST NOT merge the working branch into local `main` at phase completion
70
70
 
71
71
  ## Primary execution rules
72
72
 
73
73
  ### Step 0: Pre-flight gate (mandatory for local_implementation)
74
74
 
75
- For the `local_implementation` strategy, before any planning or implementation mutation, run the pre-flight gate:
75
+ <!-- rule: LOCAL-PREFLIGHT-GATE-MANDATORY -->
76
+ For the `local_implementation` strategy, before any planning or implementation mutation, you MUST run the pre-flight gate:
76
77
 
77
78
  ```sh
78
79
  node scripts/loop/pre-flight-gate.mjs --expected-branch <working-branch> --check-subagents
79
80
  ```
80
81
 
81
- Before creating or reusing a worktree for local implementation, use the canonical lifecycle entrypoint, which fetches the base remote, then creates-or-reuses the worktree at its namespaced path and provisions it in one step:
82
+ Before creating or reusing a worktree for local implementation, use the canonical lifecycle entrypoint (`WORKTREE-CREATE-PROVISION`, see [Worktree usage guidance](../../docs/worktree-guidance.md#create-or-reuse--provision-ensure-worktreemjs)):
82
83
 
83
84
  ```sh
84
85
  node scripts/loop/ensure-worktree.mjs --repo-root <main> --issue <n>
85
86
  ```
86
87
 
87
- This creates (or reuses) the worktree at `tmp/worktrees/dev-loops/<kind>-<n>` from a freshly fetched `origin/main` (the authoritative base for all worktree creation) and provisions its gitignored runtime files. Raw `git worktree add -b <branch> tmp/worktrees/dev-loops/<kind>-<n> origin/main` is the underlying mechanism `ensure-worktree.mjs` runs for you. See [worktree guidance](../../docs/worktree-guidance.md).
88
+ This validates worktree isolation (current directory under `tmp/worktrees/`) and branch identity (current branch matches the working branch); `--check-subagents` only reports subagent availability and is advisory (fails-open, does not block the gate). If the gate fails, **stop and fix the violation** before proceeding do not bypass it in normal workflow execution.
88
89
 
89
- This validates:
90
- - Worktree isolation (current directory is under `tmp/worktrees/`)
91
- - Branch identity (current branch matches the working branch)
92
- - Subagent availability (subagents should be used for fan-out when available)
93
-
94
- If the gate fails, **stop and fix the violation** before proceeding. Do not bypass the gate in normal workflow execution.
95
-
96
- Note: `--check-subagents` is advisory — it reports availability but does not block the gate. The worktree and branch checks are the mandatory gates.
97
-
98
- 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.
99
-
100
- Development-only bypass (`DEVLOOPS_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.
90
+ 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. The development-only bypass (`DEVLOOPS_PREFLIGHT_BYPASS=1`) exists for testing the gate itself and MUST NOT be used in production workflow runs — it is a testing convenience, not an operational escape hatch.
101
91
 
102
92
  ## Narrow failure-triage fast path
103
93
 
104
- When resuming local implementation with dirty work or an observed failing command, use this path before broad discovery:
94
+ <!-- rule: LOCAL-FAILURE-TRIAGE-ORDER -->
95
+ When resuming local implementation with dirty work or an observed failing command, you MUST follow this ordered path before broad discovery:
105
96
 
106
97
  1. run startup once from the relevant worktree/context
107
98
  2. inspect current state with `git status` and the changed files
@@ -115,20 +106,13 @@ Follow [Anti-patterns](../docs/anti-patterns.md) for the general tooling-interna
115
106
 
116
107
  ### Step 1
117
108
 
118
- - Implement **one phase at a time**.
119
- - Do not refine later phases in detail before the current phase is complete.
109
+ - <!-- rule: LOCAL-PHASE-ONE-AT-A-TIME --> You MUST implement **one phase at a time** and MUST NOT refine later phases in detail before the current phase is complete.
120
110
  - Use the `refiner` agent for phase-refinement work when subagents are available; escalate RFC-worthy technical decisions to the parent session / human operator.
121
- - Work **test-first** for all non-trivial logic.
122
- - Maintain **90% coverage** thresholds.
111
+ - <!-- rule: LOCAL-TEST-FIRST-COVERAGE --> You MUST work **test-first** for all non-trivial logic and SHOULD maintain **90% coverage** thresholds (coverage is not enforced by the shipped verify config; treat it as the working target).
123
112
  - Log detailed iteration artifacts under `tmp/` using the required structure below.
124
- - 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/`.
125
- - 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.
113
+ - Spec-of-record split (phase-doc-backed vs. tracker-backed vs. lightweight): see [Tracker-backed local implementation](#tracker-backed-local-implementation) above.
126
114
  - 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.
127
- - Do implementation work on a dedicated local branch, not directly on `main`.
128
- - 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.
129
- - Use small atomic local commits as progress checkpoints whenever a coherent slice is green and reviewable.
130
- - 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.
131
- - 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.
115
+ - Branch, commit, pre-approval-gate, and finalization mechanics: see [Branch / review / merge policy](#branch--review--merge-policy), [Commit policy](#commit-policy), and [Implementation loop for the phase](#implementation-loop-for-the-phase) below.
132
116
  - When subagents are used, log what each subagent was asked to do and what it concluded.
133
117
  - 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.
134
118
 
@@ -138,32 +122,14 @@ Apply [Structural Quality](../docs/structural-quality.md) from the `deep` review
138
122
 
139
123
  ## Light mode (small changes)
140
124
 
141
- Light mode is wired into gate dispatch. A PR that is **under threshold** (≤ `maxLines` lines changed AND ≤ `maxFiles` files, per `.devloops` field `localImplementation.lightMode` — this repo sets `maxLines: 20`, `maxFiles: 2`; the shipped built-in default has light mode disabled (`enabled: false`); if enabled without explicit values it falls back to `maxFiles: 3` / `maxLines: 200`) AND carries no `gate:full` label collapses BOTH `draft_gate` and `pre_approval_gate` to a single inline single-agent correctness + no-op check. The Copilot review request and its polling are skipped.
142
-
143
- **Escalation:**
144
- 1. Auto-escalate — if the inline check surfaces any finding whose severity is in the gate's `blockCleanOnFindingSeverities` (i.e. ≥ `worth-fixing-now`), dispatch escalates to full fan-out.
145
- 2. Label override — the `gate:full` label forces full fan-out regardless of PR size.
146
-
147
- The `draft_gate` boundary (draft → ready) is still recorded because `requireDraftFirst` is honored: light mode only changes HOW the gate runs (inline vs fan-out), not WHETHER the draft boundary exists.
148
-
149
- Dispatch is resolved deterministically via `resolveGateDispatchMode(config, gate, { scope, hasFullLabel, inlineFindingSeverities })` from `@dev-loops/core/config`. `scripts/loop/resolve-gate-dispatch.mjs` is the CLI wrapper the orchestrator calls, combining `detect-change-scope.mjs` output with the `gate:full` label fact.
125
+ <!-- rule: LOCAL-LIGHT-MODE-CONFIG-SURFACE -->
126
+ `localImplementation.lightMode` (`.devloops` field; this repo sets `maxLines: 20`, `maxFiles: 2`) is this skill's config surface for light-mode gate dispatch. Gate-collapse mechanics, escalation, and dispatch resolution (`resolveGateDispatchMode`, `scripts/loop/resolve-gate-dispatch.mjs`) are owned by [Light-mode inline acceptance](../../docs/gate-review-sub-loop-contract.md#light-mode-inline-acceptance-under-threshold-micro-prs); this skill MUST NOT redefine them.
150
127
 
151
128
  Use `scripts/loop/detect-change-scope.mjs` to determine scope:
152
129
  ```sh
153
130
  node scripts/loop/detect-change-scope.mjs
154
131
  ```
155
132
 
156
- **Override threshold:**
157
- ```yaml
158
- localImplementation:
159
- lightMode:
160
- enabled: true
161
- maxFiles: 2
162
- maxLines: 20
163
- ```
164
-
165
- Scope above threshold falls back to the full fan-out/fan-in path.
166
-
167
133
  ## Deterministic logging structure
168
134
 
169
135
  Treat the workflow as three layers:
@@ -409,7 +375,8 @@ If the review finds real issues, revise the merged plan and briefly update the r
409
375
 
410
376
  ### 6. Only then start implementation
411
377
 
412
- Do not begin coding before the merged phase plan has passed review.
378
+ <!-- rule: LOCAL-PLAN-REVIEW-GATE -->
379
+ You MUST NOT begin coding before the merged phase plan has passed review.
413
380
  Update `manifest.json` to show that phase implementation has started.
414
381
 
415
382
  ## Task breakdown & delegation
@@ -428,7 +395,8 @@ into parallel executable tasks and dispatch them to the right specialist subagen
428
395
 
429
396
  ### Delegation contract
430
397
 
431
- Dispatch implementation tasks to dedicated specialist agents:
398
+ <!-- rule: LOCAL-DELEGATION-TABLE -->
399
+ Implementation tasks MUST be dispatched to dedicated specialist agents per this table:
432
400
 
433
401
  | Task type | Delegate to |
434
402
  |---|---|
@@ -528,7 +496,7 @@ After the phase plan passes review:
528
496
  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:
529
497
  - 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
530
498
  - run the resolved angle-focused passes in parallel with fresh context when practical
531
- - 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)
499
+ - the sequential-fallback rule is owned by `GATE-EXEC-FANOUT-SEQUENTIAL-FALLBACK` in [Gate Review Sub-Loop Contract](../../docs/gate-review-sub-loop-contract.md); when it applies, record the fallback in `Phase Review` (`tmp/phases/phase-x/review.md`) (or the equivalent merged review artifact)
532
500
  - 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
533
501
  - 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.
534
502
  - 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
@@ -542,8 +510,8 @@ After the phase plan passes review:
542
510
  9. Write `Retrospective` (`tmp/phases/phase-x/retrospective.md`) using [Retrospective Template](../dev-loop/templates/retrospective.md).
543
511
  10. Update `tmp/phases/phase-x/manifest.json` and `tmp/phases/index.json`.
544
512
  11. Update [Implementation State](../../docs/IMPLEMENTATION_STATE.md).
545
- 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.
546
- 13. For tracker-backed sessions, create the PR from the working branch using the canonical `dev-loops pr create --assignee @me --repo <owner/name> --base main --head <branch> --title "..." --body-file <body-file>` (always draft, self-assigned by default; `--assignee @me` is the default and is shown here for clarity). When the `dev-loops` CLI helper is unavailable, use the equivalent `create-pr.mjs` script directly: `node <resolved-skill-scripts>/github/create-pr.mjs --repo <owner/name> --assignee @me --base main --head <branch> --title "..." --body-file <body-file>`. Never open a PR with raw `gh pr create`. 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
+ 12. <!-- rule: LOCAL-COMMIT-BEFORE-EXIT --> **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.
514
+ 13. For tracker-backed sessions, create the PR from the working branch: `dev-loops pr create --assignee @me --repo <owner/name> --base main --head <branch> --title "..." --body-file <body-file>` (fallback when the CLI helper is unavailable: `node <resolved-skill-scripts>/github/create-pr.mjs --repo <owner/name> --assignee @me --base main --head <branch> --title "..." --body-file <body-file>`); never raw `gh pr create`. Draft/assignment/`Closes #N` policy: [LOCAL-PR-CREATE-CANONICAL](#tracker-backed-local-implementation) above.
547
515
  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).
548
516
  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.
549
517
 
@@ -556,85 +524,32 @@ The retrospective must capture:
556
524
  - what should change in the skill or workflow next time
557
525
  - what a fresh session should know before the next phase
558
526
 
559
- This is the infrastructure for self-improvement. Do not skip it.
527
+ <!-- rule: LOCAL-RETROSPECTIVE-REQUIRED -->
528
+ This is the infrastructure for self-improvement; you MUST NOT skip it.
560
529
 
561
530
  ## Dev mode
562
531
 
563
- Dev mode is for improving the local implementation loop itself while using it.
564
-
565
- 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.
566
-
567
- 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.
568
-
569
- In dev mode, after the normal phase summary and retrospective are written, run one extra bounded self-improvement pass before moving on:
570
-
571
- 1. collect a deterministic context bundle for the phase using:
572
- - `../dev-loop/scripts/dev-mode-context.mjs`
573
- - output to `tmp/phases/phase-x/dev-mode-context.json`
574
- 2. review the phase artifacts and logs with emphasis on the workflow itself:
575
- - planning quality
576
- - review quality
577
- - validation friction
578
- - bash exit-code-1 patterns
579
- - places where skill or agent prompts should be tightened
580
- - places where deterministic tooling should replace ad hoc work
581
- 3. write `Dev Mode Retrospective` (`tmp/phases/phase-x/dev-mode-retrospective.md`)
582
- - this is the required dev-mode retrospective artifact
583
- - it should name the highest-value prompt/workflow follow-ups revealed by the phase
584
- 4. optionally write `Dev Mode Review` (`tmp/phases/phase-x/dev-mode-review.md`) when separate analytical notes help support the retrospective
585
- 5. apply at least one bounded follow-up update to a relevant skill and/or agent prompt
586
- - deterministic tooling, docs, templates, or tests may accompany that change
587
- - but they do not replace the required prompt update
588
- - keep the change phase-bounded and tied directly to the retrospective findings
589
- 6. write `Dev Mode Skill Changes` (`tmp/phases/phase-x/dev-mode-skill-changes.md`)
590
- - record which skill and/or agent prompts changed
591
- - record any supporting tooling/docs/template changes that accompanied them
592
- - if no prompt update can be justified safely, stop and report that dev-mode exit criteria were not met
593
- 7. if skill scripts or deterministic tooling changed, rerun the skill-local tests
594
- 8. stop after this bounded self-improvement pass; do not recurse into endless self-editing loops
595
-
596
- Dev mode is still phase-bounded. It improves the loop around the completed phase; it does not authorize work on the next product phase.
532
+ Dev mode improves the local implementation loop itself while using it. A repo may declare a default via `.devloops` field `workflow.devModeDefault`; explicit user opt-in/opt-out for the current run still wins over that default. 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.
597
533
 
598
- ## tmp/ logging requirements
534
+ After the normal phase summary and retrospective, run one extra bounded self-improvement pass:
599
535
 
600
- At minimum, each phase should leave behind:
601
- - a durable phase doc at [Phase Plan](../../docs/phases/phase-x.md)
602
- - local `tmp/` execution artifacts needed to resume and audit the phase, including:
603
- - `manifest.json`
604
- - `Variant A` (`tmp/phases/phase-x/variant-a.md`)
605
- - `Variant B` (`tmp/phases/phase-x/variant-b.md`)
606
- - `merged-plan.md`
607
- - `review.md`
608
- - `summary.md`
609
- - `retrospective.md`
610
- - optional `Variant C` (`tmp/phases/phase-x/variant-c.md`) when a third variant was actually useful
611
- - `bash-exit-1.jsonl` when any bash call during the phase exited with code `1`
612
- - `clarification.md` when a plan-sufficiency interview or auto-clarification step was needed
613
- - subagent summaries when subagents were used
614
- - raw subagent outputs only when they were saved separately on purpose
615
- - in dev mode: `dev-mode-context.json`, `dev-mode-retrospective.md`, and `dev-mode-skill-changes.md`
616
- - optional in dev mode: `dev-mode-review.md` when separate analytical notes were useful
617
-
618
- These `tmp/` artifacts are normally temporary and do not need to be checked into git.
619
-
620
- Also log validation output summaries and notable decisions if they help evaluate the local dev loop later.
621
-
622
- Additionally, append every bash call that exits with code `1` to:
623
- - `tmp/phases/phase-x/bash-exit-1.jsonl`
536
+ 1. Collect a deterministic context bundle: `../dev-loop/scripts/dev-mode-context.mjs` → `tmp/phases/phase-x/dev-mode-context.json`.
537
+ 2. Review the phase artifacts/logs for planning quality, review quality, validation friction, bash exit-code-1 patterns, and places where prompts or deterministic tooling should improve.
538
+ 3. Write `Dev Mode Retrospective` (`tmp/phases/phase-x/dev-mode-retrospective.md`) required; name the highest-value prompt/workflow follow-ups revealed by the phase.
539
+ 4. Optionally write `Dev Mode Review` (`tmp/phases/phase-x/dev-mode-review.md`) when separate analytical notes help.
540
+ 5. Apply at least one bounded follow-up update to a relevant skill and/or agent prompt (supporting tooling/docs/template changes may accompany it but do not replace the prompt update), kept phase-bounded and tied directly to the retrospective findings.
541
+ 6. Write `Dev Mode Skill Changes` (`tmp/phases/phase-x/dev-mode-skill-changes.md`) recording which prompts and supporting changes landed; if no prompt update can be justified safely, stop and report that dev-mode exit criteria were not met.
542
+ 7. If skill scripts or deterministic tooling changed, rerun the skill-local tests.
543
+ 8. Stop after this bounded pass — do not recurse into endless self-editing loops.
544
+
545
+ Dev mode is still phase-bounded: it improves the loop around the completed phase and does not authorize work on the next product phase.
624
546
 
625
- Use the deterministic helper:
626
- - `../dev-loop/scripts/log-bash-exit-1.mjs`
547
+ ## tmp/ logging requirements
627
548
 
628
- Each line should be one JSON object with at least:
629
- - `timestamp`
630
- - `phase`
631
- - `cwd`
632
- - `command`
633
- - `exitCode`
634
- - `purpose`
635
- - `summary`
549
+ <!-- rule: LOCAL-TMP-EPHEMERAL-STATE -->
550
+ The required durable-doc + `tmp/` artifact set for a phase is defined once in [Deterministic logging structure](#deterministic-logging-structure); this section MUST NOT duplicate that list. Those artifacts are normally temporary and do not need to be checked into git; do not force-add them unless the user explicitly wants checked-in examples or fixtures. Also log validation output summaries and notable decisions if they help evaluate the local dev loop later.
636
551
 
637
- 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.
552
+ Additionally, append every bash call that exits with code `1` to `tmp/phases/phase-x/bash-exit-1.jsonl` using the deterministic helper `../dev-loop/scripts/log-bash-exit-1.mjs`. Each line is one JSON object with at least `timestamp`, `phase`, `cwd`, `command`, `exitCode`, `purpose`, `summary` (optionally truncated `stdout`/`stderr` or a path to a larger saved artifact). This log improves the local dev loop itself, so do not skip it just because the command was exploratory.
638
553
 
639
554
  ## Stop conditions
640
555
 
@@ -642,29 +557,20 @@ See [Stop Conditions](../docs/stop-conditions.md). Local-specific stops: phase c
642
557
 
643
558
  ## Branch / review / merge policy
644
559
 
645
- - Do not implement directly on `main`.
646
- - Start or switch to a dedicated local working branch before the first mutating step.
647
- - If the repository is unborn (no commits yet), still create the working branch first and make the initial atomic commits there.
648
- - Use atomic local commits to log progress, but only for coherent reviewable slices.
649
- - Before merging, run a full parallel review / fix loop and resolve accepted findings on the same branch.
650
- - Rerun validation after review-driven fixes.
651
- - 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.
652
- - 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`.
653
- - PR creation always goes through `dev-loops pr create`, which is ALWAYS draft and always assigned — self-assigned by default (`--assignee @me` when none is given; honors an explicit `--assignee <login>` / `-a <login>`), never via raw `gh pr create`, 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 --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.
654
- - When authorization is pending, record the phase as `awaiting-finalization` and describe the exact missing step.
560
+ - Implement on a dedicated local working branch, never directly on `main`, switching to it before the first mutating step; if the repo is unborn (no commits yet), still create the working branch first and make the initial atomic commits there.
561
+ - Use atomic local commits to log progress, but only for coherent reviewable slices [Commit policy](#commit-policy) below governs commit timing/authorization.
562
+ - Before merging, run a full parallel review / fix loop and resolve accepted findings on the same branch; rerun validation after review-driven fixes.
563
+ - 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); when authorization for that finalization is still pending, record the phase as `awaiting-finalization` and describe the exact missing step.
564
+ - 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`. PR creation follows [LOCAL-PR-CREATE-CANONICAL](#tracker-backed-local-implementation) above; a new PR must exist in draft before `gh pr ready` is eligible.
655
565
  - For phase-doc-backed sessions, merge the fully reviewed, locally validated branch back into local `main` when authorized.
656
566
  - Behind-branch integration before merge (for example a sibling PR merged first and both touch shared files): prefer a merge commit (`git merge origin/main`) over rebase + force-push. Since dev-loop PRs are squash-merged, intermediate branch history is discarded at merge time, so a merge commit lands an identical result on `main` while avoiding a non-fast-forward push to the remote. Force-push (`--force-with-lease` only, never bare `--force`) remains acceptable only for a branch the loop solely owns and where no integration alternative exists (rare); document that carve-out rather than leaving it implicit. After any integration that changes the head SHA, re-verify gate evidence at the new head (existing behavior — see [Merge Preconditions](../docs/merge-preconditions.md#required-before-merge)).
657
567
 
658
568
  ## Commit policy
659
569
 
660
- - Do not commit speculative work.
661
- - Do not commit before the relevant validation for that slice passes.
570
+ - Do not commit speculative work or before the relevant validation for that slice passes.
662
571
  - 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.
663
- - Keep commits small and phase-bounded.
664
- - 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).
665
- - 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).
572
+ - 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, enforced by [LOCAL-COMMIT-BEFORE-EXIT](#implementation-loop-for-the-phase) (implementation loop step 12; `git status --porcelain` must be empty before the session terminates).
666
573
  - If commit/merge authorization has not yet been given, do not call the phase `completed`; call it `awaiting-finalization` instead.
667
- - **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.
668
574
 
669
575
  ## Anti-patterns
670
576