dev-loops 0.7.1 → 0.8.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 (107) 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 +4 -4
  5. package/.claude/agents/review.md +10 -13
  6. package/.claude/commands/loop-continue.md +2 -1
  7. package/.claude/commands/loop-enqueue.md +9 -2
  8. package/.claude/commands/loop-info.md +1 -1
  9. package/.claude/commands/loop-start-spike.md +1 -1
  10. package/.claude/hooks/_bash-command-classify.mjs +7 -6
  11. package/.claude/hooks/_hook-decisions.mjs +5 -4
  12. package/.claude/skills/copilot-pr-followup/SKILL.md +42 -28
  13. package/.claude/skills/dev-loop/SKILL.md +8 -8
  14. package/.claude/skills/docs/acceptance-criteria-verification.md +13 -4
  15. package/.claude/skills/docs/anti-patterns.md +6 -5
  16. package/.claude/skills/docs/artifact-authority-contract.md +17 -14
  17. package/.claude/skills/docs/confirmation-rules.md +2 -1
  18. package/.claude/skills/docs/contract-style-guide.md +37 -0
  19. package/.claude/skills/docs/copilot-loop-operations.md +21 -15
  20. package/.claude/skills/docs/cross-harness-regression-contract.md +2 -2
  21. package/.claude/skills/docs/debt-remediation-contract.md +1 -1
  22. package/.claude/skills/docs/epic-tree-refinement-procedure.md +25 -22
  23. package/.claude/skills/docs/issue-intake-procedure.md +37 -22
  24. package/.claude/skills/docs/merge-preconditions.md +17 -13
  25. package/.claude/skills/docs/pr-lifecycle-contract.md +45 -36
  26. package/.claude/skills/docs/public-dev-loop-contract.md +61 -44
  27. package/.claude/skills/docs/retrospective-checkpoint-contract.md +25 -9
  28. package/.claude/skills/docs/spike-mode-contract.md +14 -7
  29. package/.claude/skills/docs/stop-conditions.md +30 -15
  30. package/.claude/skills/docs/tracker-first-loop-state.md +13 -8
  31. package/.claude/skills/docs/validation-policy.md +4 -5
  32. package/.claude/skills/local-implementation/SKILL.md +49 -143
  33. package/.claude/skills/loop-grill/SKILL.md +34 -14
  34. package/AGENTS.md +1 -1
  35. package/CHANGELOG.md +36 -0
  36. package/README.md +95 -189
  37. package/agents/dev-loop.agent.md +8 -8
  38. package/agents/fixer.agent.md +1 -0
  39. package/agents/refiner.agent.md +4 -4
  40. package/agents/review.agent.md +10 -13
  41. package/extension/README.md +5 -4
  42. package/package.json +7 -5
  43. package/scripts/_core-helpers.mjs +2 -0
  44. package/scripts/claude/headless-dev-loop.mjs +1 -1
  45. package/scripts/docs/validate-rule-ownership.mjs +442 -0
  46. package/scripts/docs/validate-state-machine-conformance.mjs +1169 -0
  47. package/scripts/github/_gate-names.mjs +5 -0
  48. package/scripts/github/_review-thread-mutations.mjs +5 -2
  49. package/scripts/github/capture-review-threads.mjs +2 -2
  50. package/scripts/github/create-pr.mjs +119 -10
  51. package/scripts/github/detect-checkpoint-evidence.mjs +109 -24
  52. package/scripts/github/edit-issue.mjs +259 -0
  53. package/scripts/github/list-review-threads.mjs +277 -0
  54. package/scripts/github/post-gate-findings.mjs +6 -3
  55. package/scripts/github/probe-ci-status.mjs +18 -0
  56. package/scripts/github/probe-copilot-review.mjs +24 -3
  57. package/scripts/github/reconcile-draft-gate.mjs +13 -13
  58. package/scripts/github/request-copilot-review.mjs +109 -42
  59. package/scripts/github/upsert-checkpoint-verdict.mjs +98 -27
  60. package/scripts/github/verify-briefing-prefixes.mjs +382 -0
  61. package/scripts/github/verify-fresh-review-context.mjs +78 -3
  62. package/scripts/github/wait-pr-checks.mjs +171 -0
  63. package/scripts/github/write-gate-context.mjs +220 -10
  64. package/scripts/github/write-gate-findings-log.mjs +54 -2
  65. package/scripts/loop/_post-convergence-change.mjs +2 -2
  66. package/scripts/loop/_pr-runner-coordination.mjs +112 -13
  67. package/scripts/loop/check-retro-tooling.mjs +14 -9
  68. package/scripts/loop/copilot-pr-handoff.mjs +47 -16
  69. package/scripts/loop/detect-change-scope.mjs +2 -2
  70. package/scripts/loop/detect-copilot-loop-state.mjs +34 -14
  71. package/scripts/loop/detect-internal-only-pr.mjs +6 -6
  72. package/scripts/loop/detect-pr-gate-coordination-state.mjs +152 -18
  73. package/scripts/loop/detect-refinement-grill-state.mjs +136 -0
  74. package/scripts/loop/resolve-dev-loop-startup.mjs +145 -8
  75. package/scripts/loop/run-watch-cycle.mjs +42 -7
  76. package/scripts/loop/sanctioned-commands.mjs +3 -0
  77. package/scripts/loop/validate-pr-body-spec.mjs +21 -5
  78. package/scripts/pages/build-state-atlas.mjs +65 -48
  79. package/scripts/projects/_resolve-project.mjs +1 -148
  80. package/scripts/projects/add-queue-item.mjs +87 -4
  81. package/scripts/projects/list-queue-items.mjs +3 -377
  82. package/scripts/projects/move-queue-item.mjs +3 -410
  83. package/scripts/projects/reorder-queue-item.mjs +3 -22
  84. package/skills/copilot-pr-followup/SKILL.md +42 -28
  85. package/skills/dev-loop/SKILL.md +3 -3
  86. package/skills/docs/acceptance-criteria-verification.md +13 -4
  87. package/skills/docs/anti-patterns.md +6 -5
  88. package/skills/docs/artifact-authority-contract.md +17 -14
  89. package/skills/docs/confirmation-rules.md +2 -1
  90. package/skills/docs/contract-style-guide.md +37 -0
  91. package/skills/docs/copilot-loop-operations.md +21 -15
  92. package/skills/docs/cross-harness-regression-contract.md +2 -2
  93. package/skills/docs/debt-remediation-contract.md +1 -1
  94. package/skills/docs/epic-tree-refinement-procedure.md +25 -22
  95. package/skills/docs/issue-intake-procedure.md +37 -22
  96. package/skills/docs/merge-preconditions.md +17 -13
  97. package/skills/docs/pr-lifecycle-contract.md +45 -36
  98. package/skills/docs/public-dev-loop-contract.md +61 -44
  99. package/skills/docs/required-rules.json +165 -0
  100. package/skills/docs/retrospective-checkpoint-contract.md +25 -9
  101. package/skills/docs/spike-mode-contract.md +14 -7
  102. package/skills/docs/stop-conditions.md +30 -15
  103. package/skills/docs/tracker-first-loop-state.md +13 -8
  104. package/skills/docs/validation-policy.md +4 -5
  105. package/skills/local-implementation/SKILL.md +49 -143
  106. package/skills/loop-grill/SKILL.md +38 -17
  107. 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 SHOULD maintain ≥90% coverage for lines, statements, functions, and branches (not enforced by the shipped verify config; treat it as the working target), and non-trivial logic MUST be test-first.
22
21
 
23
22
  ## Cross-references
24
23
 
@@ -13,7 +13,7 @@ user-invocable: false
13
13
 
14
14
  # Local Implementation
15
15
 
16
- This skill is the canonical internal `local_implementation` route behind the public `dev-loop` façade.
16
+ Canonical owner for the internal `local_implementation` route behind the public `dev-loop` façade.
17
17
 
18
18
  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.
19
19
 
@@ -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 always-draft creation mechanism is owned by [`OPS-DRAFT-FIRST-PR`](../docs/copilot-loop-operations.md) `create-pr.mjs` is unconditionally draft-only regardless of the toggle, which separately governs whether the draft-gate boundary is enforced before ready.
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; coverage thresholds are owned by [VALIDATE-COVERAGE-THRESHOLD](../docs/validation-policy.md).
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
 
@@ -1,10 +1,11 @@
1
1
  ---
2
2
  name: loop-grill
3
3
  description: >-
4
- Standalone pre-loop Socratic Q&A grill for issues (tracker-first) or local
5
- plan files (local-planning). Detects spec gaps, asks clarifying questions
6
- (interactive) or self-answers them from codebase context (--auto), then
7
- writes a ## Grill findings section back to the source artifact.
4
+ Standalone pre-loop Socratic Q&A grill for issues (tracker-first), PR bodies,
5
+ or local plan files (local-planning). Detects spec gaps, asks clarifying
6
+ questions (interactive) or self-answers them from codebase context (--auto),
7
+ then synthesizes Acceptance criteria / Definition of done / Non-goals into the
8
+ body while keeping the raw Q&A only in an ephemeral tmp artifact.
8
9
  allowed-tools: read bash edit write
9
10
  user-invocable: false
10
11
  ---
@@ -14,15 +15,23 @@ A standalone, on-demand pre-loop grilling skill. Run it against an issue or a lo
14
15
 
15
16
  It is entirely separate from the in-loop docs-grill (`docs/docs-grill-step.md`), which audits code/doc drift while the loop runs. This skill operates on the *spec* before any implementation begins.
16
17
 
18
+ ## State machine
19
+
20
+ This grill is the bounded, closed sub-loop modeled by `packages/core/src/loop/refinement-grill-state.mjs` (detector `scripts/loop/detect-refinement-grill-state.mjs`), rendered on the State atlas; see `docs/refinement-grill-state-graph.md`. It obeys `GRILL-SUBLOOP-STATE-MACHINE`, `GRILL-SUBLOOP-ITERATE-TO-CLEAN`, `GRILL-SUBLOOP-NO-EMBED-SYNTHESIS`, and `GRILL-SUBLOOP-HONEST-HANDOFF`. Iteration lives in the transition graph; the answer/synthesis is the bounded input consumed at the `await_answers` state.
21
+
17
22
  ## Interface
18
23
 
19
24
  ```
20
25
  /loop-grill <issue-number> # tracker-first, interactive
21
26
  /loop-grill <issue-number> --auto # tracker-first, auto-answer
27
+ /loop-grill <pr-url-or-number> # PR body, interactive
28
+ /loop-grill <pr-url-or-number> --auto # PR body, auto-answer
22
29
  /loop-grill <path/to/plan.md> # local-planning, interactive
23
30
  /loop-grill <path/to/plan.md> --auto # local-planning, auto-answer
24
31
  ```
25
32
 
33
+ PR bodies are supported the same way as issues: fetch/edit the PR body via the existing PR wrappers (`scripts/github/view-pr.mjs` / `scripts/github/edit-pr.mjs`), never raw `gh`.
34
+
26
35
  ## Argument validation (fail-closed)
27
36
 
28
37
  Before doing anything else:
@@ -35,9 +44,12 @@ Before doing anything else:
35
44
 
36
45
  ## Step 1 — Load the target
37
46
 
38
- - **Tracker-first:** fetch the issue body (title + description + any existing `## Grill findings` section).
47
+ - **Tracker-first:** fetch the issue body (title + description).
48
+ - **PR body:** fetch the PR body via `scripts/github/view-pr.mjs` (never raw `gh`).
39
49
  - **Local-planning:** read the plan file from disk.
40
50
 
51
+ "Is it refined" is decided by `detectIssueRefinementArtifact` (`packages/core/src/loop/issue-refinement-artifact.mjs`) — the single source of truth, same as the enqueue gate; do not add a divergent check. An already-refined artifact (AC/DoD present) is a zero-iteration `grill_clean`: do not rewrite the body.
52
+
41
53
  ## Step 1b — Surface external resources
42
54
 
43
55
  Before detecting gaps, scan the loaded content for external resource references: links, other repo URLs, API endpoints, doc URLs, screenshots, or Playwright navigation descriptors.
@@ -91,15 +103,20 @@ Record the evidence source for every answer. Flag a question as **`unresolved`**
91
103
 
92
104
  Do not silently guess an `inferred` answer when no evidence can be cited — flag it `unresolved` instead.
93
105
 
94
- ## Step 4 — Write back (replace-section semantics)
106
+ ## Step 4 — Write back (synthesize sections; raw Q&A to tmp only)
95
107
 
96
- Write a `## Grill findings` section back to the source artifact using **replace-section** semantics:
108
+ Synthesize the answers into the body as sharpened `## Acceptance criteria`, `## Definition of done`, and `## Non-goals` sections. Per canonical heading, use **replace-section** semantics:
97
109
 
98
- - **Find** the existing `## Grill findings` section: the range from the `## Grill findings` heading through the next `##`-level heading (exclusive) or end of file.
99
- - **Replace** that range in place with the new section content.
100
- - If no `## Grill findings` section exists, **append** it.
110
+ - **Find** the existing section: the range from that `##`-level heading through the next `##`-level heading (exclusive) or end of file.
111
+ - **Replace** that range in place with the synthesized content; if the section is absent, **append** it.
101
112
  - This makes re-runs idempotent — no accumulated noise, no duplicate sections.
102
- - If parsing the section boundary fails, **abort with an error** rather than silently truncating.
113
+ - If parsing a section boundary fails, **abort with an error** rather than silently truncating.
114
+
115
+ The body carries ONLY the synthesized sharpened sections. Do NOT write a `## Grill findings` section and do NOT embed the raw Q&A table in the body (`GRILL-SUBLOOP-NO-EMBED-SYNTHESIS`).
116
+
117
+ If a body migrated from older embed behavior still carries a `## Grill findings` section, **remove** it as part of write-back — strip from that heading through the next `##`-level heading (exclusive) or end of file, using the same replace-section boundary logic. This is a removal-only migration, never a re-introduction of the embed.
118
+
119
+ Write the raw Q&A transcript ONLY to the gitignored, ephemeral, session-scoped artifact `tmp/issues/issue-<n>/grill/<timestamp>.md` (`tmp/` is already gitignored; never committed). For PR-body and plan-file surfaces, use the same tmp path shape scoped by surface (issues: `tmp/issues/issue-<n>/grill/`; a parallel `tmp/...` path for PR/plan).
103
120
 
104
121
  **Tracker-first write-back:** update the GitHub issue body using:
105
122
 
@@ -107,19 +124,23 @@ Write a `## Grill findings` section back to the source artifact using **replace-
107
124
  gh issue edit <n> --repo <owner/repo> --body-file <tmp-path>
108
125
  ```
109
126
 
110
- The `## Grill findings` section lives in the issue body, not as a comment. Do not use `comment-issue.mjs` here — that creates a comment, not a body update.
127
+ The synthesized sections live in the issue body, not as a comment. Do not use `comment-issue.mjs` here — that creates a comment, not a body update.
128
+
129
+ **PR-body write-back:** update the PR body via `scripts/github/edit-pr.mjs` (never raw `gh`), same replace-section semantics.
111
130
 
112
- **GitHub body size guard:** issue bodies are capped at 65,536 characters. Before writing back, check whether the updated body would exceed this limit. If so, warn: `Warning: updated body would exceed GitHub's 65,536-character limit — write-back skipped. Truncate the findings or the issue body manually.` Do not silently truncate.
131
+ **GitHub body size guard:** issue/PR bodies are capped at 65,536 characters. Before writing back, check whether the updated body would exceed this limit. If so, warn: `Warning: updated body would exceed GitHub's 65,536-character limit — write-back skipped. Sharpen the sections or the body manually.` Do not silently truncate.
113
132
 
114
133
  **Local-planning write-back:** update the plan file in place using the edit tool.
115
134
 
116
135
  ## Output artifact format
117
136
 
118
- The `## Grill findings` section written to the artifact:
137
+ Two distinct artifacts:
119
138
 
120
- ```markdown
121
- ## Grill findings
139
+ 1. **Synthesized body sections** (issue/PR/plan body): only `## Acceptance criteria`, `## Definition of done`, and `## Non-goals`, sharpened from the answers. No raw Q&A.
122
140
 
141
+ 2. **Raw Q&A transcript** (ephemeral `tmp/issues/issue-<n>/grill/<timestamp>.md` only — never the body):
142
+
143
+ ```markdown
123
144
  <!-- loop-grill: <timestamp> mode:<interactive|auto> -->
124
145
 
125
146
  ### Resolved gaps
@@ -154,7 +175,7 @@ When `CONTEXT.md` is absent from the repo root, skip the context-source check si
154
175
 
155
176
  ## Idempotency guarantee
156
177
 
157
- Running `/loop-grill` twice on the same target must produce a single `## Grill findings` section, not two. The replace-section logic handles the already-present-section case. On the second run, if the gap set is identical to the first run, the section content is replaced with an equivalent section (same questions, same answers, updated timestamp).
178
+ Running `/loop-grill` twice on the same target must not accumulate duplicate sections: the per-heading replace-section logic replaces the synthesized `## Acceptance criteria` / `## Definition of done` / `## Non-goals` sections in place. An already-refined target is a zero-iteration `grill_clean` and its body is left unchanged. The raw Q&A transcript is written to a fresh timestamped tmp file per run; the body never carries it.
158
179
 
159
180
  ## Non-goals
160
181