@juicesharp/rpiv-pi 2.9.0 → 2.10.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 (33) hide show
  1. package/extensions/rpiv-core/artifact-collector.ts +30 -7
  2. package/extensions/rpiv-core/built-in-workflows.ts +222 -70
  3. package/extensions/rpiv-core/built-ins/citations.ts +9 -0
  4. package/extensions/rpiv-core/built-ins/design.ts +64 -0
  5. package/extensions/rpiv-core/built-ins/elaboration.ts +53 -0
  6. package/extensions/rpiv-core/built-ins/gates.ts +282 -12
  7. package/extensions/rpiv-core/built-ins/grade-panel.ts +54 -26
  8. package/extensions/rpiv-core/built-ins/index.ts +20 -1
  9. package/extensions/rpiv-core/built-ins/markdown-fence.ts +26 -1
  10. package/extensions/rpiv-core/built-ins/plan-phases.ts +8 -0
  11. package/extensions/rpiv-core/built-ins/priors.ts +9 -2
  12. package/extensions/rpiv-core/built-ins/remediation.ts +60 -7
  13. package/extensions/rpiv-core/built-ins/scope-checks.ts +74 -11
  14. package/extensions/rpiv-core/built-ins/shared.ts +5 -3
  15. package/extensions/rpiv-core/built-ins/slice-checks.ts +164 -28
  16. package/extensions/rpiv-core/built-ins/slices.ts +44 -13
  17. package/extensions/rpiv-core/built-ins/verdict-collector.ts +207 -0
  18. package/extensions/rpiv-core/built-ins/verdict-outcome.ts +36 -0
  19. package/extensions/rpiv-core/lane-list.ts +10 -1
  20. package/extensions/rpiv-core/lane-progress.ts +1 -1
  21. package/extensions/rpiv-core/lane-usage.ts +1 -1
  22. package/extensions/rpiv-core/models-picker.ts +4 -3
  23. package/extensions/rpiv-core/run-lane-registry.ts +1 -2
  24. package/extensions/rpiv-core/sdk-workflow-host.ts +20 -4
  25. package/extensions/rpiv-core/session-hooks.ts +1 -1
  26. package/package.json +4 -3
  27. package/skills/_shared/stitch-elaborations.mjs +282 -21
  28. package/skills/acceptance/SKILL.md +3 -2
  29. package/skills/amend/SKILL.md +5 -5
  30. package/skills/design-slice/SKILL.md +5 -0
  31. package/skills/elaborate/SKILL.md +10 -3
  32. package/skills/grade/SKILL.md +13 -10
  33. package/skills/validate/SKILL.md +14 -0
@@ -14,11 +14,14 @@
14
14
  * (`research`, `plans`, etc.) — the collector halts the chain if the
15
15
  * agent strayed.
16
16
  *
17
- * Both collectors carry a disk-corroborated basename fallback: when the
18
- * full-path transcript scan misses (agent mangled the directory prefix in
19
- * prose), a bare `<file>.md` token from the transcript is accepted iff it
20
- * resolves to exactly one existing file under `.rpiv/artifacts/` — see the
21
- * fallback section below.
17
+ * Both collectors carry two fallbacks behind the spoken-text scan, tried in
18
+ * order: (1) the tool-argument surface — the `path` argument of a `write`/`edit`
19
+ * call (the recorded action, for an agent that wrote the file but never
20
+ * announced it; see the fallback-surface section below); (2) the
21
+ * disk-corroborated basename fallback — when both scans miss (agent mangled
22
+ * the directory prefix in prose), a bare `<file>.md` token from the transcript
23
+ * is accepted iff it resolves to exactly one existing file under
24
+ * `.rpiv/artifacts/` — see that section below.
22
25
  *
23
26
  * One parser: `frontmatterParser` parses YAML frontmatter from the
24
27
  * primary fs artifact into `Record<string, unknown>` — what
@@ -144,9 +147,29 @@ function withDiskFallback(primary: ArtifactCollector, bucket?: string): Artifact
144
147
  });
145
148
  }
146
149
 
150
+ // ---------------------------------------------------------------------------
151
+ // Tool-argument fallback surface
152
+ // ---------------------------------------------------------------------------
153
+ //
154
+ // When the spoken announcement misses, the text-scan primitive consults the
155
+ // agent's recorded tool calls. That surface is narrowed HARD here, because a
156
+ // stage's transcript is full of other artifacts' paths in tool arguments: an
157
+ // elaborate lane `read`s sibling elaborations, a grader `bash`-greps the plan,
158
+ // `ls .rpiv/artifacts/<bucket>/` lists every neighbour. Only a FILE-WRITING
159
+ // tool proves the agent produced the path, and only its `path` argument names
160
+ // what it wrote — a `write` call's `content` may quote a sibling's path (a
161
+ // `source:` line, a cross-reference) and must never outrank the destination.
162
+ // Pi's file-writing tools are `write` (`{ path, content }`) and `edit`
163
+ // (`{ path, edits }`); `bash` heredoc writes are deliberately NOT accepted (a
164
+ // `command` string carries arbitrary paths) — for those the disk-corroborated
165
+ // basename fallback below still applies.
166
+ const FILE_WRITING_TOOLS: ReadonlySet<string> = new Set(["write", "edit"]);
167
+ const isFileWrite = (tc: { name: string }): boolean => FILE_WRITING_TOOLS.has(tc.name);
168
+ const TOOL_ARG_FALLBACK = { match: isFileWrite, argKeys: ["path"] as const };
169
+
147
170
  /** Bucket-agnostic — accepts any `.rpiv/artifacts/<bucket>/...md`. */
148
171
  export const rpivArtifactCollector: ArtifactCollector = withDiskFallback(
149
- transcriptPathCollector({ pattern: RPIV_ARTIFACT_PATTERN }),
172
+ transcriptPathCollector({ pattern: RPIV_ARTIFACT_PATTERN, ...TOOL_ARG_FALLBACK }),
150
173
  );
151
174
 
152
175
  /** Bucket-narrowed — accepts only `.rpiv/artifacts/<bucket>/...md`. The filename
@@ -155,7 +178,7 @@ export const rpivArtifactCollector: ArtifactCollector = withDiskFallback(
155
178
  export function rpivBucketCollector(bucket: string): ArtifactCollector {
156
179
  const escaped = bucket.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
157
180
  const pattern = new RegExp(String.raw`\.rpiv/artifacts/${escaped}/${TEMPERED_SEGMENT}\.md`, "g");
158
- return withDiskFallback(transcriptPathCollector({ pattern }), bucket);
181
+ return withDiskFallback(transcriptPathCollector({ pattern, ...TOOL_ARG_FALLBACK }), bucket);
159
182
  }
160
183
 
161
184
  // ---------------------------------------------------------------------------
@@ -20,7 +20,6 @@ import {
20
20
  acts,
21
21
  defineRoute,
22
22
  defineWorkflow,
23
- directoryPathCollector,
24
23
  type EdgeFn,
25
24
  eq,
26
25
  fanin,
@@ -28,7 +27,6 @@ import {
28
27
  gitCommitOutcome,
29
28
  gt,
30
29
  handleToString,
31
- jsonBodyParser,
32
30
  match,
33
31
  type PromptFn,
34
32
  produces,
@@ -39,9 +37,9 @@ import {
39
37
  import { rpivBucketOutcome } from "./artifact-collector.js";
40
38
  import {
41
39
  allDimensionsPass,
42
- anchorNitsOnly,
43
40
  CODE_CONFIRM_FANOUT,
44
41
  CODE_DIMENSION_FANOUT,
42
+ CODE_PANEL_PROGRESS,
45
43
  COMMIT_BASELINE_PROMPT,
46
44
  captureGoal,
47
45
  captureReviewScope,
@@ -49,7 +47,9 @@ import {
49
47
  codeGatePasses,
50
48
  codeSnapshot,
51
49
  confirmDue,
52
- FRONTMATTER_PHASE_FANOUT,
50
+ designOutcome,
51
+ ELABORATE_PHASE_FANOUT,
52
+ elaborationOutcome,
53
53
  freshVerdicts,
54
54
  haltPreflight,
55
55
  IMPLEMENT_DAG_FANOUT,
@@ -63,6 +63,7 @@ import {
63
63
  PLAN_CONFIRM_FANOUT,
64
64
  PLAN_DIMENSION_FANOUT,
65
65
  PLAN_DIMENSIONS,
66
+ PLAN_PANEL_PROGRESS,
66
67
  planAuthoredRisks,
67
68
  planCitationCheck,
68
69
  planDemote,
@@ -74,17 +75,27 @@ import {
74
75
  rulingEffectivePass,
75
76
  SHIP_DIMENSION_FANOUT,
76
77
  SHIP_DIMENSIONS,
78
+ SHIP_PANEL_PROGRESS,
77
79
  SLICE_DESIGN_FANOUT,
78
80
  SLICE_DIMENSION_FANOUT,
81
+ SLICE_DIMENSIONS,
82
+ SLICE_PANEL_PROGRESS,
79
83
  SYNTH_CLUSTER_FANOUT,
80
84
  scopeQuarantine,
85
+ seedLiftStuck,
86
+ seedOnlyCiteFail,
81
87
  shipGatePasses,
82
88
  shipVerdictOutcome,
83
89
  sliceGatePasses,
90
+ sliceSeedLift,
84
91
  sliceStructureCheck,
85
92
  subplanCoverageCheck,
86
93
  subplanGatePasses,
94
+ unitFailedDimensions,
87
95
  VALIDATE_GOAL_PROMPT,
96
+ type VerdictRecord,
97
+ verdictBlocks,
98
+ verdictOutcome,
88
99
  verdictRiskRulings,
89
100
  } from "./built-ins/index.js";
90
101
 
@@ -138,7 +149,9 @@ const polishWorkflow = defineWorkflow({
138
149
  validate: "code-review",
139
150
  // Backward edge: code-review → blueprint re-plans (implement needs a plan).
140
151
  // The iterate stage re-runs over every review phase; bounded by the
141
- // runner's default maxBackwardJumps (3 → up to 4 review iterations).
152
+ // runner's default maxBackwardJumps (3 → up to 4 review iterations)
153
+ // under the absolute per-stage maxLaps ceiling (default 8; both
154
+ // budgets fresh per invocation — a resume re-opens the loop).
142
155
  "code-review": gate("blockers_count", { blueprint: gt(0), commit: eq(0) }, "commit"),
143
156
  commit: "stop",
144
157
  },
@@ -223,24 +236,20 @@ const SHIP_RESEARCH_PROMPT: PromptFn = ({ state }) =>
223
236
  ].join("\n");
224
237
 
225
238
  /**
226
- * Verdict channels — grade writes JSON to `.rpiv/artifacts/verdicts/`, so these
227
- * use the JSON directory collector + `jsonBodyParser` (NOT the md
228
- * `rpivBucketOutcome`). The slice gate and plan gate publish to DISTINCT named
229
- * channels (same dir, different artifact basenames) so their verdicts never
230
- * collide and `plan-fix`/`code-fix` can pick each via the `-verdicts` suffix convention.
239
+ * Verdict channels — grade writes JSON to `.rpiv/artifacts/verdicts/`, so
240
+ * these use the disk-first verdict factory in `built-ins/verdict-outcome.ts`
241
+ * (NOT the md `rpivBucketOutcome`). The slice gate and plan gate publish to
242
+ * DISTINCT named channels (same dir, different artifact basenames) so their
243
+ * verdicts never collide and `plan-fix`/`code-fix` can pick each via the
244
+ * `-verdicts` suffix convention.
231
245
  */
232
- const verdictOutcome = (name: string) => ({
233
- name,
234
- collector: directoryPathCollector({ dir: ".rpiv/artifacts/verdicts", ext: "json" }),
235
- parser: jsonBodyParser,
236
- });
237
- const sliceVerdictOutcome = verdictOutcome("slice-verdicts");
238
- const planVerdictOutcome = verdictOutcome("plan-verdicts");
246
+ const sliceVerdictOutcome = verdictOutcome("slice-verdicts", "slices");
247
+ const planVerdictOutcome = verdictOutcome("plan-verdicts", "plans");
239
248
  // The post-splice code gate re-grades the now code-bearing plan on its own
240
249
  // channel, so its verdicts never mix with the pre-elaborate plan gate's. Named
241
250
  // for the object under judgment — the code the gate grades — completing the
242
251
  // slice-verdicts / plan-verdicts / code-verdicts parallel.
243
- const codeVerdictOutcome = verdictOutcome("code-verdicts");
252
+ const codeVerdictOutcome = verdictOutcome("code-verdicts", "plans");
244
253
 
245
254
  /**
246
255
  * Absolute path to rpiv-pi's bundled deterministic stitch script. Resolved off
@@ -275,21 +284,33 @@ const STITCH_SCRIPT = join(
275
284
  * tracked excess to downstream adjudication (build threads the verdict to
276
285
  * validate via `--scope`; vet's review loop sees the whole diff) instead of
277
286
  * halting, the citation-floor precedent (demote where a remedy or adjudicator
278
- * exists). "untracked-only" takes the deterministic `scope-quarantine` arm.
287
+ * exists). The excess pick is an HONEST pass-through: it attaches a route note
288
+ * naming the downstream adjudicator (`opts.deferredTo` — validate on build,
289
+ * code-review on vet) so the end-of-run recap's `routingNotes` can surface the
290
+ * deferral; the pass pick attaches no note (a clean pass needs no
291
+ * explanation). "untracked-only" takes the deterministic `scope-quarantine`
292
+ * arm.
279
293
  * Anything else — a missing or corrupt verdict — terminates ("stop" with a
280
294
  * route note): the integrity clause every de-halting change has preserved.
281
295
  * A `match` cannot send two enum values to one target, hence `defineRoute`;
282
296
  * `readsData: false` — the route consults the stage's published channel, not
283
297
  * its projected output (matching the other deterministic-floor routes).
284
298
  */
285
- const scopeFloorGate = (): EdgeFn => {
299
+ const scopeFloorGate = (opts: { deferredTo: string }): EdgeFn => {
286
300
  const route: EdgeFn = defineRoute(
287
301
  ["reconcile", "scope-quarantine", "stop"],
288
302
  ({ state }) => {
289
303
  const verdict = (state.named["implement-scope-check"]?.at(-1)?.data as { verdict?: unknown } | undefined)
290
304
  ?.verdict;
291
305
  if (verdict === "untracked-only") return "scope-quarantine";
292
- if (verdict === "pass" || verdict === "excess") return "reconcile";
306
+ if (verdict === "pass") return "reconcile";
307
+ if (verdict === "excess") {
308
+ // Honest pass-through: the floor did not PASS, it DEFERRED — record why
309
+ // on the routing row (the recap's routingNotes) instead of a silent
310
+ // reconcile that reads like a clean pass.
311
+ setRouteNote(route, `pass-through: implement-scope-check defers to ${opts.deferredTo}`);
312
+ return "reconcile";
313
+ }
293
314
  setRouteNote(
294
315
  route,
295
316
  `implement-scope-check verdict ${JSON.stringify(verdict ?? null)} is not a ScopeVerdict — terminated (integrity stop)`,
@@ -466,9 +487,10 @@ const vetWorkflow = defineWorkflow({
466
487
  implement: "implement-scope-check",
467
488
  // Scope-check still gates onward into `reconcile` (not validate): the
468
489
  // coherence backstop runs after the write-set is judged. Tiered route —
469
- // see scopeFloorGate: pass/excess ⇒ reconcile, untracked-only ⇒ the
470
- // quarantine arm, missing/corrupt verdict ⇒ STOP.
471
- "implement-scope-check": scopeFloorGate(),
490
+ // see scopeFloorGate: pass/excess ⇒ reconcile (excess carries the
491
+ // code-review pass-through note), untracked-only ⇒ the quarantine arm,
492
+ // missing/corrupt verdict ⇒ STOP.
493
+ "implement-scope-check": scopeFloorGate({ deferredTo: "code-review" }),
472
494
  // Deterministic re-entry after the quarantine arm: a plain string edge
473
495
  // (non-counted, mirroring build's validate-fix hop) with guaranteed
474
496
  // progress — quarantined paths leave the dirty set, so the re-check
@@ -487,7 +509,9 @@ const vetWorkflow = defineWorkflow({
487
509
  // UNCHANGED. The scope-check inserts before validate, so a failing scope
488
510
  // verdict halts before re-review, and a passing one flows into validate and
489
511
  // back to code-review exactly as today. Bounded by the runner's default
490
- // maxBackwardJumps (3 → at most 4 review iterations).
512
+ // maxBackwardJumps (3 → at most 4 review iterations) under the absolute
513
+ // per-stage maxLaps ceiling (default 8; both budgets fresh per
514
+ // invocation — a resume re-opens the loop).
491
515
  validate: "code-review",
492
516
  commit: "stop",
493
517
  },
@@ -595,6 +619,71 @@ const validateFixGate = (): EdgeFn => {
595
619
  return route;
596
620
  };
597
621
 
622
+ /**
623
+ * The fix-arm note for a dead grade unit — the dimension soft-halted (after
624
+ * its retry budget ran out, when the panel wires one) and left no verdict to
625
+ * fold. Naming it keeps the failure legible and the repair targeted: the fix
626
+ * arm re-enters the panel, `dimensionsToRegrade` still lists the dimension as
627
+ * pending, and a healthy re-dispatch grades it for real.
628
+ */
629
+ const unitFailedNote = (dims: readonly string[]): string => `unit-failed: ${dims.join(", ")} produced no verdict`;
630
+
631
+ /** The slice gate's grade edge — design-readiness pass ⇒ design; a dead
632
+ * dimension unit ⇒ slice-fix with the note (a verdict-less dead dimension is
633
+ * never a classification candidate). A SEED-ONLY cite fail (every finding
634
+ * naming a concrete seed to add) ⇒ the deterministic `slice-seed-lift` arm,
635
+ * which appends the seeds and re-enters `slice-check` for the discharge
636
+ * stamp; anything else ⇒ slice-fix. Belt-and-suspenders for the live graph:
637
+ * the slice roster is one dimension, so a double miss makes the generation
638
+ * all-failed and `haltWhenAllFailed` halts at the panel close before any
639
+ * route runs — the arms pin the route contract for any future multi-dimension
640
+ * slice roster and for constructed-state trails. */
641
+ const sliceGradeRoute: EdgeFn = defineRoute(
642
+ ["slice-design", "slice-seed-lift", "slice-fix"],
643
+ ({ state }) => {
644
+ if (sliceGatePasses(state)) return "slice-design";
645
+ const unitFailed = unitFailedDimensions(state, "slices", "slice-verdicts", SLICE_DIMENSIONS);
646
+ if (unitFailed.length > 0) {
647
+ setRouteNote(sliceGradeRoute, unitFailedNote(unitFailed));
648
+ return "slice-fix";
649
+ }
650
+ return seedOnlyCiteFail(state) ? "slice-seed-lift" : "slice-fix";
651
+ },
652
+ { readsData: false },
653
+ );
654
+
655
+ /** The plan gate's demote edge — the unit-failed preemption fires BEFORE the
656
+ * confirm divert (a previously-passing dimension whose re-grade died is not
657
+ * a flap to adjudicate; there is no verdict to adjudicate). */
658
+ const planDemoteRoute: EdgeFn = defineRoute(
659
+ ["code", "plan-confirm", "plan-snapshot"],
660
+ ({ state }) => {
661
+ if (planGatePasses(state)) return "code";
662
+ const unitFailed = unitFailedDimensions(state, "plans", "plan-verdicts", PLAN_DIMENSIONS);
663
+ if (unitFailed.length > 0) {
664
+ setRouteNote(planDemoteRoute, unitFailedNote(unitFailed));
665
+ return "plan-snapshot";
666
+ }
667
+ return confirmDue(state, "plans", "plan-verdicts", PLAN_DIMENSIONS) ? "plan-confirm" : "plan-snapshot";
668
+ },
669
+ { readsData: false },
670
+ );
671
+
672
+ /** The code gate's demote edge — the plan gate's twin on `code-verdicts`. */
673
+ const codeDemoteRoute: EdgeFn = defineRoute(
674
+ ["implement", "code-confirm", "code-snapshot"],
675
+ ({ state }) => {
676
+ if (codeGatePasses(state)) return "implement";
677
+ const unitFailed = unitFailedDimensions(state, "plans", "code-verdicts", PLAN_DIMENSIONS);
678
+ if (unitFailed.length > 0) {
679
+ setRouteNote(codeDemoteRoute, unitFailedNote(unitFailed));
680
+ return "code-snapshot";
681
+ }
682
+ return confirmDue(state, "plans", "code-verdicts", PLAN_DIMENSIONS) ? "code-confirm" : "code-snapshot";
683
+ },
684
+ { readsData: false },
685
+ );
686
+
598
687
  const buildWorkflow = defineWorkflow({
599
688
  name: "build",
600
689
  description:
@@ -632,6 +721,10 @@ const buildWorkflow = defineWorkflow({
632
721
  skill: "grade",
633
722
  loop: SLICE_DIMENSION_FANOUT,
634
723
  outcome: sliceVerdictOutcome,
724
+ // Whole-lap progress: the slice lane's three re-entered destinations
725
+ // (grade/fix/seed-lift) share ONE hook instance, so every counted
726
+ // re-entry reads the same verdict-channel fold.
727
+ progress: SLICE_PANEL_PROGRESS,
635
728
  reads: ["slices"],
636
729
  }),
637
730
  // Re-cut the slice map from the failing verdicts. Routes through `slice`
@@ -642,10 +735,27 @@ const buildWorkflow = defineWorkflow({
642
735
  "slice-fix": produces({
643
736
  skill: "slice",
644
737
  outcome: rpivBucketOutcome("slices"),
738
+ progress: SLICE_PANEL_PROGRESS,
645
739
  reads: ["slices", fanin("slice-verdicts"), fanin("slice-check")],
646
740
  }),
741
+ // Deterministic seed lift — the engine-owned half of the cite remedy: a
742
+ // seed-only design-readiness fail (every finding demanding a concrete
743
+ // `requires` citation) is repaired by appending the seeds to the named
744
+ // slices' `Draws on` lines in place, never by a full re-slice + re-grade.
745
+ // Publishes on its OWN stage channel (a script stage cannot carry an
746
+ // outcome; the in-place amend keeps `latestFsArtifact(state, "slices")`
747
+ // resolving the same amended file), then re-enters `slice-check`, whose
748
+ // re-run stamps the cite discharge the gate folds on — no second panel.
749
+ "slice-seed-lift": produces.script({
750
+ reads: ["slices", fanin("slice-verdicts")],
751
+ run: sliceSeedLift,
752
+ progress: SLICE_PANEL_PROGRESS,
753
+ }),
647
754
  // Design every slice in parallel.
648
- "slice-design": produces({ skill: "design-slice", loop: SLICE_DESIGN_FANOUT }),
755
+ // `designOutcome` derives `filename_slice` beside the frontmatter so the
756
+ // design-slice contract refuses a path whose `_slice-<N>_` token is missing
757
+ // or disagrees with `slice_n` while the lane can still rename it.
758
+ "slice-design": produces({ skill: "design-slice", loop: SLICE_DESIGN_FANOUT, outcome: designOutcome }),
649
759
  // One consolidated developer checkpoint over EVERY per-slice design, at the
650
760
  // single fan-in seam where they all exist and nothing parallel is running.
651
761
  // Presents the proposed shape (interfaces, data types, scope) and lets the
@@ -685,6 +795,9 @@ const buildWorkflow = defineWorkflow({
685
795
  skill: "grade",
686
796
  loop: PLAN_DIMENSION_FANOUT,
687
797
  outcome: planVerdictOutcome,
798
+ // Whole-lap progress: the plan lane's three re-entered destinations
799
+ // (grade/confirm/snapshot) share ONE hook instance — a lap is one unit.
800
+ progress: PLAN_PANEL_PROGRESS,
688
801
  // `research` is read so the architecture-fit unit can thread it as
689
802
  // --context; `goal` so completeness/correctness anchor on the brief.
690
803
  reads: ["plans", "research", "goal", "acceptance"],
@@ -706,6 +819,7 @@ const buildWorkflow = defineWorkflow({
706
819
  skill: "grade",
707
820
  loop: PLAN_CONFIRM_FANOUT,
708
821
  outcome: planVerdictOutcome,
822
+ progress: PLAN_PANEL_PROGRESS,
709
823
  reads: ["plans", "research", "goal", "acceptance"],
710
824
  }),
711
825
  "plan-fix": produces({
@@ -727,11 +841,16 @@ const buildWorkflow = defineWorkflow({
727
841
  // rides its stage-name channel, so this publishes to `plan-snapshot`, NOT
728
842
  // `plans` — `latestFsArtifact(state, "plans")` still resolves to the real
729
843
  // (amended) plan.
730
- "plan-snapshot": produces.script({ reads: ["plans"], run: planSnapshot }),
844
+ "plan-snapshot": produces.script({ reads: ["plans"], run: planSnapshot, progress: PLAN_PANEL_PROGRESS }),
731
845
  // Elaborate implement-ready code into each phase in parallel (fanout),
732
846
  // deterministically splice it back into the plan (code-splice), then
733
847
  // re-grade the now code-bearing plan — guarding the blind-splice risk.
734
- code: produces({ skill: "elaborate", loop: FRONTMATTER_PHASE_FANOUT, reads: ["plans"] }),
848
+ code: produces({
849
+ skill: "elaborate",
850
+ loop: ELABORATE_PHASE_FANOUT,
851
+ reads: ["plans"],
852
+ outcome: elaborationOutcome,
853
+ }),
735
854
  "code-splice": acts.script({
736
855
  reads: ["plans"],
737
856
  run: ({ state, cwd }) => {
@@ -744,7 +863,16 @@ const buildWorkflow = defineWorkflow({
744
863
  );
745
864
  }
746
865
  const planPath = isAbsolute(plan.handle.path) ? plan.handle.path : join(cwd, plan.handle.path);
747
- execFileSync("node", [STITCH_SCRIPT, planPath], { cwd });
866
+ try {
867
+ execFileSync("node", [STITCH_SCRIPT, planPath], { cwd, stdio: ["ignore", "pipe", "pipe"] });
868
+ } catch (err) {
869
+ const stderr = (err as { stderr?: Buffer | string }).stderr?.toString().trim();
870
+ throw haltPreflight(
871
+ "code-splice",
872
+ "code-splice: stitch refused the elaborations",
873
+ stderr || (err instanceof Error ? err.message : String(err)),
874
+ );
875
+ }
748
876
  },
749
877
  }),
750
878
  // Deterministic citation floor over the SPLICED (code-bearing) plan before
@@ -754,6 +882,9 @@ const buildWorkflow = defineWorkflow({
754
882
  skill: "grade",
755
883
  loop: CODE_DIMENSION_FANOUT,
756
884
  outcome: codeVerdictOutcome,
885
+ // Whole-lap progress: the code lane's three re-entered destinations
886
+ // (grade/confirm/snapshot) share ONE hook instance — a lap is one unit.
887
+ progress: CODE_PANEL_PROGRESS,
757
888
  // `research` is read so the architecture-fit unit can thread it as
758
889
  // --context; `goal` so completeness/correctness anchor on the brief.
759
890
  reads: ["plans", "research", "goal", "acceptance"],
@@ -777,6 +908,7 @@ const buildWorkflow = defineWorkflow({
777
908
  skill: "grade",
778
909
  loop: CODE_CONFIRM_FANOUT,
779
910
  outcome: codeVerdictOutcome,
911
+ progress: CODE_PANEL_PROGRESS,
780
912
  reads: ["plans", "research", "goal", "acceptance"],
781
913
  }),
782
914
  "code-fix": produces({
@@ -792,7 +924,7 @@ const buildWorkflow = defineWorkflow({
792
924
  // Snapshot the graded plan BEFORE code-fix amends it — the code-gate twin
793
925
  // of `plan-snapshot` (code-grade/code-confirm → code-snapshot → code-fix),
794
926
  // publishing the prior on the `code-snapshot` channel.
795
- "code-snapshot": produces.script({ reads: ["plans"], run: codeSnapshot }),
927
+ "code-snapshot": produces.script({ reads: ["plans"], run: codeSnapshot, progress: CODE_PANEL_PROGRESS }),
796
928
  implement: acts({ loop: IMPLEMENT_DAG_FANOUT, reads: ["plans"] }),
797
929
  // Lane-level scope floor — the structural backstop beneath the quality
798
930
  // gates. After the (now concurrent) implement lane lands, judge the working
@@ -803,6 +935,11 @@ const buildWorkflow = defineWorkflow({
803
935
  // (threaded via --scope); missing verdict ⇒ STOP. No schema is declared
804
936
  // (matching slice-check/plan-cite-check — the route reads the channel).
805
937
  // Reads `goal` for the run-start baseline that subtracts pre-existing dirt.
938
+ // On a validate-fix re-entry the floor additionally accepts the latest
939
+ // report's blockers-named writes as declared scope — a validate-fix hop's
940
+ // targeted repair is the one writer the plan cannot declare (it predates
941
+ // the report); fail-closed on missing/older remediation (see
942
+ // validateReportAcceptance).
806
943
  "implement-scope-check": produces.script({ reads: ["plans", "goal"], run: implementScopeCheck }),
807
944
  // Deterministic remedy arm for the untracked-only tier: move (never
808
945
  // delete) run-created untracked excess under .rpiv/tmp/scope-quarantine/
@@ -852,34 +989,50 @@ const buildWorkflow = defineWorkflow({
852
989
  // already passes, so re-grading would only re-roll a flappy judgment. Also
853
990
  // skips after a fix for a `remedy: "cite"` fail once `slice-check` has
854
991
  // deterministically verified the demanded seeds landed on a structurally
855
- // unchanged map (the `citeDischarged` stamp — see `citeRemedyDischarged`).
856
- // First pass (no verdict yet) ⇒ not satisfied ⇒ into `slice-grade`.
992
+ // unchanged map (the `citeDischarged` stamp — see `citeRemedyDischarged`),
993
+ // and after a seed lift for the same reason.
994
+ // First pass (no verdict yet) ⇒ not satisfied ⇒ into `slice-grade`. A
995
+ // seed lift that already ran and left the gate red is STUCK — re-grading
996
+ // or re-lifting cannot change the outcome — so the fail branch routes
997
+ // the structural fix arm BEFORE the re-grade fallthrough.
857
998
  "slice-check": defineRoute(
858
- ["slice-design", "slice-grade"],
859
- ({ state }) => (sliceGatePasses(state) ? "slice-design" : "slice-grade"),
860
- { readsData: false },
861
- ),
862
- // Design-readiness gate BEFORE any design. Structure + design-readiness pass⇒ design; any fails ⇒
863
- // slice-fix and loop back. Bounded by the runner's maxBackwardJumps (default 3).
864
- "slice-grade": defineRoute(
865
- ["slice-design", "slice-fix"],
866
- ({ state }) => (sliceGatePasses(state) ? "slice-design" : "slice-fix"),
999
+ ["slice-design", "slice-fix", "slice-grade"],
1000
+ ({ state }) => (sliceGatePasses(state) ? "slice-design" : seedLiftStuck(state) ? "slice-fix" : "slice-grade"),
867
1001
  { readsData: false },
868
1002
  ),
1003
+ // Design-readiness gate BEFORE any design. Structure + design-readiness pass ⇒
1004
+ // design; a SEED-ONLY cite fail (every finding naming a concrete seed to add) ⇒
1005
+ // the deterministic `slice-seed-lift` arm, which appends the seeds and re-enters
1006
+ // `slice-check` for the discharge stamp — a full re-slice + re-grade for pure
1007
+ // citation bookkeeping repairs nothing the verdict flagged; anything else ⇒
1008
+ // slice-fix and loop back. (A dimension whose re-dispatch produced no verdict
1009
+ // takes the fix arm ahead of the seed-only check — a verdict-less dead
1010
+ // dimension is never seed-only.) Bounded by the runner's maxBackwardJumps
1011
+ // (default 3) under the absolute per-stage maxLaps ceiling (default 8;
1012
+ // both budgets fresh per invocation — a resume re-opens the loop).
1013
+ "slice-grade": sliceGradeRoute,
869
1014
  "slice-fix": "slice-check",
1015
+ // Deterministic re-entry after the seed lift: the re-run structure check
1016
+ // stamps the discharge the gate folds on (a plain string edge — the
1017
+ // counted decision is the slice-grade route's lift pick).
1018
+ "slice-seed-lift": "slice-check",
870
1019
  // Design fanout → consolidated human checkpoint → hierarchical synthesis.
871
1020
  "slice-design": "design-review",
872
1021
  "design-review": "subplan",
873
1022
  // Route the cluster fanout through the deterministic coverage floor before
874
1023
  // the root merge — the twin of `slice → slice-check`. A pass folds straight
875
1024
  // to `plan`; a lost/clobbered cluster routes the backward edge to `subplan`,
876
- // bounded by the runner's maxBackwardJumps.
1025
+ // bounded by the runner's maxBackwardJumps (default 3) under the absolute
1026
+ // per-stage maxLaps ceiling (default 8; both budgets fresh per invocation
1027
+ // — a resume re-opens the loop).
877
1028
  subplan: "subplan-check",
878
1029
  // Subplan coverage gate. Pass ⇒ root merge. A fail (lost cluster, clobbered
879
1030
  // ordinal, tokenless basename, or a slice design absent from every sources:)
880
1031
  // routes the backward edge to `subplan` — re-dispatch the cluster fanout,
881
1032
  // which re-supplies each cluster's '--cluster <k>'. Bounded by the runner's
882
- // maxBackwardJumps. `readsData: false` — the route consults only the
1033
+ // maxBackwardJumps (default 3) under the absolute per-stage maxLaps ceiling
1034
+ // (default 8; both budgets fresh per invocation — a resume re-opens the
1035
+ // loop). `readsData: false` — the route consults only the
883
1036
  // deterministic verdict channel (mirrors the slice-check/plan-cite-check routes).
884
1037
  "subplan-check": defineRoute(
885
1038
  ["plan", "subplan"],
@@ -913,16 +1066,7 @@ const buildWorkflow = defineWorkflow({
913
1066
  // plan-fix, looping back THROUGH the citation floor so the amended plan
914
1067
  // re-verifies. Route logic unchanged — merely shifted one hop later so the
915
1068
  // demote write-back precedes it.
916
- "plan-demote": defineRoute(
917
- ["code", "plan-confirm", "plan-snapshot"],
918
- ({ state }) =>
919
- planGatePasses(state)
920
- ? "code"
921
- : confirmDue(state, "plans", "plan-verdicts", PLAN_DIMENSIONS)
922
- ? "plan-confirm"
923
- : "plan-snapshot",
924
- { readsData: false },
925
- ),
1069
+ "plan-demote": planDemoteRoute,
926
1070
  // After the second judgment the gate re-folds on the latest verdicts: a
927
1071
  // confirming pass overwrote the flap and clears the gate; a confirming
928
1072
  // fail routes to the fix with two agreeing judgments behind it.
@@ -956,17 +1100,10 @@ const buildWorkflow = defineWorkflow({
956
1100
  // back to `code`: the gate fails on plan-text defects (edit anchors, line
957
1101
  // citations, naming) that a per-phase code rewrite cannot reach, so the
958
1102
  // surgical arm is the one with authority over them. Route logic unchanged —
959
- // merely shifted one hop later. Bounded by the runner's maxBackwardJumps.
960
- "code-demote": defineRoute(
961
- ["implement", "code-confirm", "code-snapshot"],
962
- ({ state }) =>
963
- codeGatePasses(state)
964
- ? "implement"
965
- : confirmDue(state, "plans", "code-verdicts", PLAN_DIMENSIONS)
966
- ? "code-confirm"
967
- : "code-snapshot",
968
- { readsData: false },
969
- ),
1103
+ // merely shifted one hop later. Bounded by the runner's maxBackwardJumps
1104
+ // (default 3) under the absolute per-stage maxLaps ceiling (default 8;
1105
+ // both budgets fresh per invocation — a resume re-opens the loop).
1106
+ "code-demote": codeDemoteRoute,
970
1107
  "code-confirm": defineRoute(
971
1108
  ["implement", "code-snapshot"],
972
1109
  ({ state }) => (codeGatePasses(state) ? "implement" : "code-snapshot"),
@@ -981,10 +1118,12 @@ const buildWorkflow = defineWorkflow({
981
1118
  // validate adjudicates them via the --scope thread — the citation floor's
982
1119
  // demote-and-adjudicate precedent); untracked-only ⇒ the deterministic
983
1120
  // scope-quarantine arm; a missing/corrupt verdict ⇒ STOP (integrity
984
- // clause). Sourced from the scope-check's published verdict channel (the
1121
+ // clause). The excess pick attaches the pass-through note naming validate
1122
+ // (the recap's routingNotes surface the deferral). Sourced from the
1123
+ // scope-check's published verdict channel (the
985
1124
  // stage key for an outcome-less `produces.script`, per
986
1125
  // `resolvePublishName`); `readsData: false` suppresses the outputSchema lint.
987
- "implement-scope-check": scopeFloorGate(),
1126
+ "implement-scope-check": scopeFloorGate({ deferredTo: "validate" }),
988
1127
  // Deterministic re-entry after the quarantine arm: a plain string edge
989
1128
  // (non-counted, mirroring validate-fix's hop) with guaranteed progress —
990
1129
  // quarantined paths leave the dirty set, so the re-check either passes or
@@ -1031,7 +1170,8 @@ const buildWorkflow = defineWorkflow({
1031
1170
  * edges attach their own no-match diagnostics; only these two `defineRoute`
1032
1171
  * gates would otherwise stop silently. Best-effort DIAGNOSTICS, not gates:
1033
1172
  * `allDimensionsPass`/`shipGatePasses` stay the sole routing authorities, and
1034
- * these mirror their severity floor only to NAME the blockers.
1173
+ * these consult the shared `verdictBlocks` predicate — the same fold those
1174
+ * gates route on — only to NAME the blockers.
1035
1175
  */
1036
1176
  const shipCiteStopNote = (state: RunView): string => {
1037
1177
  const data = state.named["plan-cite-check"]?.at(-1)?.data as { findings?: unknown } | undefined;
@@ -1043,6 +1183,11 @@ const shipCiteStopNote = (state: RunView): string => {
1043
1183
  return n > 0 ? `plan citation check failed (${n} finding${n === 1 ? "" : "s"})` : "plan citation check failed";
1044
1184
  };
1045
1185
  const shipGradeStopNote = (state: RunView): string => {
1186
+ // A dead grade unit (post-re-dispatch) is the loudest blocker — name it
1187
+ // ahead of the severity blockers (ship's arm is stop + hand-repair +
1188
+ // resume, so the note IS the repair instruction).
1189
+ const unitFailed = unitFailedDimensions(state, "plans", "ship-verdicts", SHIP_DIMENSIONS);
1190
+ if (unitFailed.length > 0) return unitFailedNote(unitFailed);
1046
1191
  const fresh = freshVerdicts(state.named["ship-verdicts"], latestArtifactPath(state, "plans"));
1047
1192
  if (fresh.length === 0) return "no fresh verdicts for the current plan";
1048
1193
  const risks = planAuthoredRisks(state, "plans");
@@ -1051,9 +1196,8 @@ const shipGradeStopNote = (state: RunView): string => {
1051
1196
  for (const d of SHIP_DIMENSIONS) {
1052
1197
  const o = latest.get(d);
1053
1198
  if (!o) continue;
1054
- const v = o.data as { pass?: boolean; severity?: string; findings?: unknown };
1055
- const floored = v.pass === true || v.severity === "low" || v.severity === "none" || anchorNitsOnly(v);
1056
- if (!floored) blockers.push(`${d} failed (${v.severity ?? "unrated"})`);
1199
+ const v = o.data as VerdictRecord | undefined;
1200
+ if (verdictBlocks(v)) blockers.push(`${d} failed (${v?.severity ?? "unrated"})`);
1057
1201
  else if (verdictRiskRulings(o).some((r) => !rulingEffectivePass(r, risks.get(r.id))))
1058
1202
  blockers.push(`${d} risk flag failed`);
1059
1203
  }
@@ -1176,6 +1320,10 @@ const shipWorkflow = defineWorkflow({
1176
1320
  skill: "grade",
1177
1321
  loop: SHIP_DIMENSION_FANOUT,
1178
1322
  outcome: shipVerdictOutcome,
1323
+ // Whole-lap progress: declared for uniformity — ship's grade gate
1324
+ // routes implement or stop, so no edge ever re-enters this stage and
1325
+ // the hook never fires.
1326
+ progress: SHIP_PANEL_PROGRESS,
1179
1327
  reads: ["plans", "research", "goal", "acceptance"],
1180
1328
  }),
1181
1329
  // Dep-gated DAG implement — build's lane verbatim.
@@ -1183,6 +1331,10 @@ const shipWorkflow = defineWorkflow({
1183
1331
  // Lane-level scope floor — build's latest-only variant (vet uses the
1184
1332
  // union variant for its fix loop; ship has no loop, so the latest plan's
1185
1333
  // declared write-set is the whole contract). Pass ⇒ reconcile; fail ⇒ STOP.
1334
+ // The shared run function carries the validate-report acceptance: a
1335
+ // validate-fix hop's blocker-named writes are accepted as declared scope
1336
+ // (fail-closed on missing/older remediation) — ship's single bounded
1337
+ // validate-fix hop re-enters here, landing exactly that shape.
1186
1338
  "implement-scope-check": produces.script({ reads: ["plans", "goal"], run: implementScopeCheck }),
1187
1339
  // Deterministic post-implement reconciliation — build's run-function
1188
1340
  // verbatim. Pass ⇒ validate; fail ⇒ ONE bounded reconcile-fix hop
@@ -259,6 +259,15 @@ const verifyCitations = (body: string, cwd: string, declared?: ReadonlySet<strin
259
259
  const [, path, startStr, endStr] = m;
260
260
  if (!path || !startStr) continue;
261
261
  if (fenced.some(([s, e]) => m.index >= s && m.index < e)) continue;
262
+ // Sanctioned quoting — arrow-pair halves: a citation immediately followed
263
+ // by "→" (a revision note's OLD half) or immediately preceded by "→" (its
264
+ // NEW half) is a quoted reference, not a live claim — the same contract
265
+ // `citeOccursLive` honors for the cite remedy (the slice skill's re-slice
266
+ // mode pins revision-note quotations to arrow pairs or fences). Skipped
267
+ // BEFORE the `seen`-key bookkeeping so a live occurrence of the same cite
268
+ // elsewhere in the body still verifies.
269
+ if (body.startsWith("→", m.index + m[0].length)) continue;
270
+ if (body.endsWith("→", m.index)) continue;
262
271
  if (PLACEHOLDER_CITATION_PREFIXES.some((p) => path.startsWith(p))) continue;
263
272
  const key = `${path}:${startStr}${endStr ? `-${endStr}` : ""}`;
264
273
  if (seen.has(key)) continue;