@juicesharp/rpiv-pi 2.7.1 → 2.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.
@@ -44,6 +44,7 @@ import {
44
44
  CODE_DIMENSION_FANOUT,
45
45
  COMMIT_BASELINE_PROMPT,
46
46
  captureGoal,
47
+ captureReviewScope,
47
48
  codeDemote,
48
49
  codeGatePasses,
49
50
  codeSnapshot,
@@ -144,7 +145,8 @@ const polishWorkflow = defineWorkflow({
144
145
  });
145
146
 
146
147
  // ===========================================================================
147
- // build — goal (verbatim-brief capture) → research → slice → slice-check
148
+ // build — goal (verbatim-brief capture) → research → acceptance (the
149
+ // goal-derived executable standard of completion) → slice → slice-check
148
150
  // (deterministic floor) → slice-grade (design-readiness, slice-fix loop)
149
151
  // → slice-design (fanout) → design-review (one human checkpoint) →
150
152
  // subplan (cluster fanout) → plan → plan-grade (plan-fix loop) →
@@ -183,26 +185,41 @@ const RESEARCH_BRIEF_PROMPT: PromptFn = ({ state }) => `/skill:research ${state.
183
185
 
184
186
  /**
185
187
  * ship's research front-load — a LEANER grounding than build's `/skill:research`
186
- * pass. Bypasses the research skill and bounds the agent to at most TWO targeted
187
- * `codebase-analyzer` dispatches (sequentially — never parallel, never
188
- * `run_in_background`) to map only what a lightweight single-phase plan needs to
189
- * be correct: entry points, the relevant module's shape, and the conventions the
190
- * implement lane must match. The agent then `Write`s a grounding doc under
191
- * `.rpiv/artifacts/research/`, where the research bucket collector harvests it —
192
- * the grade panel's architecture-fit dimension threads it as `--context` exactly
193
- * as build's research artifact does. A prompt stage (no skill), so the stage
194
- * name `research` drives outcome derivation (research contract → `research`
188
+ * pass, tiered to the brief's pre-chewedness. Bypasses the research skill: a
189
+ * pre-chewed brief (root cause, files to touch, or fix already named) gets
190
+ * VERIFICATION, not re-derivation — at most ONE verify-only `codebase-analyzer`
191
+ * dispatch confirming each named anchor, or none at all when the anchors are
192
+ * plain file paths the stage child reads itself; a symptom-only brief keeps at
193
+ * most TWO targeted `codebase-analyzer` dispatches (sequentially — never
194
+ * parallel, never `run_in_background`) mapping only what a lightweight
195
+ * single-phase plan needs to be correct. The agent then `Write`s a grounding
196
+ * doc under `.rpiv/artifacts/research/` (the prompt names the directory only —
197
+ * a full example path would prime the collector's pre-write path-echo hazard),
198
+ * where the research bucket collector harvests it — the grade panel's
199
+ * architecture-fit dimension threads it as `--context` exactly as build's
200
+ * research artifact does. A prompt stage (no skill), so the stage name
201
+ * `research` drives outcome derivation (research contract → `research`
195
202
  * bucket), exactly as build's `RESEARCH_BRIEF_PROMPT` stage does — the prompt
196
- * text, not dispatch, is what differs.
203
+ * text, not dispatch, is what differs. The prompt also pins a progress-marker
204
+ * protocol — a `[Classified]:` first line naming the chosen tier,
205
+ * `[Dispatch N/M]:` / `[Dispatch N/M returned]:` echo lines around each
206
+ * grounding dispatch (plus the `[Dispatch]: none` zero-dispatch escape) — so
207
+ * the lane console's live tail narrates the otherwise-silent batch window;
208
+ * markers are transcript text only and never carry an artifacts path before
209
+ * the write.
197
210
  */
198
211
  const SHIP_RESEARCH_PROMPT: PromptFn = ({ state }) =>
199
212
  [
200
213
  "Ground this brief for a lightweight ship plan.",
201
- "Do NOT dispatch /skill:research. Instead dispatch at most TWO targeted codebase-analyzer subagents (sequentially — never parallel, never run_in_background) to map only what a single-phase plan needs to be correct: entry points, the relevant module's shape, and the conventions the implement lane must match.",
214
+ "Do NOT dispatch /skill:research — size the grounding to what the brief already carries.",
215
+ "Classify the brief first, then follow ONLY the matching tier:",
216
+ "- Tier A (pre-chewed — the brief names the root cause, the files to touch, or the fix): VERIFY, don't re-derive. Dispatch at most ONE codebase-analyzer subagent (sequentially — never parallel, never run_in_background) in verify-only mode, confirming or denying each named anchor against the actual code and reporting drift with the corrected file:line. If the anchors are plain file paths, dispatch nothing — Read/Grep them yourself.",
217
+ "- Tier B (symptom only — the brief names none of the three: no root cause, no files, no fix): dispatch at most TWO targeted codebase-analyzer subagents (sequentially — never parallel, never run_in_background) to map only what a single-phase plan needs to be correct: entry points, the relevant module's shape, and the conventions the implement lane must match.",
218
+ "Progress markers — echo your status as you go: the first line of your reply, before anything else, is [Classified]: Tier A — verify-only or [Classified]: Tier B — map ground truth (the tier you classified the brief into). Before each dispatch, emit [Dispatch N/M]: <purpose phrase>; once it lands, emit [Dispatch N/M returned]: <outcome phrase> (M is the tier's dispatch ceiling: 1 for Tier A, 2 for Tier B). For Tier A's zero-dispatch escape, emit [Dispatch]: none — reading the named anchors directly. Markers are transcript text only, never artifact content, and must NEVER contain a .rpiv/artifacts/ path before the file is written.",
202
219
  "",
203
220
  `Brief: ${state.originalInput}`,
204
221
  "",
205
- "Then Write a grounding doc under .rpiv/artifacts/research/ (timestamped filename) carrying the findings, and stop.",
222
+ "Then Write the grounding doc under .rpiv/artifacts/research/ (timestamped filename, under 150 lines) carrying the findings with verifiable file:line citations — Code References, Integration Points, the relevant module's shape, and the conventions the implement lane must match — announce the written file's path in your final message, and stop.",
206
223
  ].join("\n");
207
224
 
208
225
  /**
@@ -291,8 +308,10 @@ const vetWorkflow = defineWorkflow({
291
308
  start: "goal",
292
309
  stages: {
293
310
  // Capture the user's brief verbatim on its own `goal` channel, and snapshot
294
- // the run-start pre-existing-dirty paths (role "baseline"). Reuses build's
295
- // `captureGoal` verbatim — no new function — so the scope-check's
311
+ // the run-start pre-existing-dirty paths (role "baseline"). Uses
312
+ // `captureReviewScope` — build's capture minus the garbage-brief floor,
313
+ // because vet's input is a review-scope token ("staged", a hash) that is
314
+ // legitimately shorter than any brief the floor admits — so the scope-check's
296
315
  // `reads: ["plans", "goal"]` resolves a baseline to subtract and the goal md
297
316
  // rides the channel face. `goal` as start publishes the goal-md as
298
317
  // `artifacts[0]`; `code-review` is a plain `produces()` SKILL stage (skill
@@ -308,7 +327,7 @@ const vetWorkflow = defineWorkflow({
308
327
  // attaches its `outputSchema` and the `blockers_count` gate would read
309
328
  // UNVALIDATED data (NaN-route risk, not just a warning). Keeping it a skill
310
329
  // stage keeps `skill="code-review"` → contract schema attaches → validated.
311
- goal: produces.script({ run: captureGoal }),
330
+ goal: produces.script({ run: captureReviewScope }),
312
331
  "code-review": produces(),
313
332
  blueprint: produces(),
314
333
  // Dep-gated DAG variant: implement phases now
@@ -375,81 +394,111 @@ const vetWorkflow = defineWorkflow({
375
394
  });
376
395
 
377
396
  /**
378
- * Build's validate gate — classifies a failing verdict BEFORE routing to the
379
- * repair arm. `remediate`'s work-list is contractually the report's `pass:
380
- * false` risk rulings plus its structured `blockers:` entries; a `verdict:
381
- * fail` carrying NEITHER (run 2026-08-22_12-14-12-64eb: two whole-plan gate
382
- * failures recorded only in report prose) has no handle the arm may act on,
383
- * so routing it to `validate-fix` buys a provably futile lap — the arm
384
- * drift-escapes without an edit and the unchanged tree re-validates to the
385
- * identical verdict until the backward-jump guard halts the run. Such a fail
386
- * now STOPs at the gate with a route note naming why (the ship-gate
397
+ * The classifying validate gate — classifies a failing verdict BEFORE routing
398
+ * to the repair arm. `remediate`'s work-list is contractually the report's
399
+ * `pass: false` risk rulings plus its structured `blockers:` entries; a
400
+ * `verdict: fail` carrying NEITHER (run 2026-08-22_12-14-12-64eb: two
401
+ * whole-plan gate failures recorded only in report prose) has no handle the
402
+ * arm may act on, so routing it to `validate-fix` buys a provably futile lap
403
+ * — the arm drift-escapes without an edit and the unchanged tree re-validates
404
+ * to the identical verdict until the backward-jump guard halts the run. Such
405
+ * a fail STOPs at the gate with a route note naming why (the ship-gate
387
406
  * `setRouteNote` pattern; a noted decision stop records as a halt). The
388
407
  * repair-arm authority rule the slice gate learned the same way: a gate may
389
408
  * only loop into an arm whose authority covers the failure class.
390
409
  *
410
+ * A factory (not one shared EdgeFn) for the scopeFloorGate reason — each
411
+ * workflow's route-note symbol must never alias the other's. `maxFixRounds`
412
+ * caps the remediation hops a remediable fail may buy: each `validate-fix`
413
+ * pass publishes exactly one digest on the `remediation` channel, so the
414
+ * channel length IS the rounds already spent. Build passes no cap (the
415
+ * runner's backward-jump guard is its budget); ship caps at ONE — the single
416
+ * bounded hop its stop-on-fail identity concedes (run 7299: a docs-gap
417
+ * `fail` at the last stage stranded ~50 min of verified implementation).
418
+ *
391
419
  * Reads the `validation` channel (validate's contract-derived publish bucket
392
420
  * — a prompt stage owns its message and can't inherit its contract's output
393
421
  * schema, so the gate folds the channel, never the raw stage output). A
394
422
  * missing/unexpected verdict stays terminal STOP, exactly as the `match` it
395
423
  * replaces — un-anticipated data can never route INTO commit OR the repair arm.
396
424
  */
397
- const validateGate: EdgeFn = defineRoute(
398
- ["commit", "validate-fix", "stop"],
399
- ({ state }) => {
400
- const latest = state.named.validation?.at(-1);
401
- const data = latest?.data as { verdict?: unknown; blockers?: unknown } | undefined;
402
- if (data?.verdict === "pass") return "commit";
403
- if (data?.verdict !== "fail") {
404
- setRouteNote(
405
- validateGate,
406
- `validate verdict ${JSON.stringify(data?.verdict ?? null)} matched no branch — terminated (no fallback)`,
407
- );
408
- return "stop";
409
- }
410
- // Remediable handles: `pass: false` risk rulings (the arm's original
411
- // work-list) + structured `blockers:` entries (whole-plan gate failures
412
- // the validate skill attributes with a runnable command + in-delta file).
413
- const failedRulings = latest ? verdictRiskRulings(latest).filter((r) => !r.pass).length : 0;
414
- const blockers = Array.isArray(data.blockers) ? data.blockers.length : 0;
415
- if (failedRulings + blockers > 0) return "validate-fix";
416
- setRouteNote(
417
- validateGate,
418
- "validate failed with no remediable handle (no pass:false risk ruling, no blockers entry) — the remediation arm cannot act; fix manually or revise the plan",
419
- );
420
- return "stop";
421
- },
422
- { readsData: false },
423
- );
425
+ const validateGate = (opts?: { maxFixRounds?: number }): EdgeFn => {
426
+ const maxFixRounds = opts?.maxFixRounds ?? Number.POSITIVE_INFINITY;
427
+ const route: EdgeFn = defineRoute(
428
+ ["commit", "validate-fix", "stop"],
429
+ ({ state }) => {
430
+ const latest = state.named.validation?.at(-1);
431
+ const data = latest?.data as { verdict?: unknown; blockers?: unknown } | undefined;
432
+ if (data?.verdict === "pass") return "commit";
433
+ if (data?.verdict !== "fail") {
434
+ setRouteNote(
435
+ route,
436
+ `validate verdict ${JSON.stringify(data?.verdict ?? null)} matched no branch — terminated (no fallback)`,
437
+ );
438
+ return "stop";
439
+ }
440
+ // Remediable handles: `pass: false` risk rulings (the arm's original
441
+ // work-list) + structured `blockers:` entries (whole-plan gate failures
442
+ // the validate skill attributes with a runnable command + in-delta file).
443
+ const failedRulings = latest ? verdictRiskRulings(latest).filter((r) => !r.pass).length : 0;
444
+ const blockers = Array.isArray(data.blockers) ? data.blockers.length : 0;
445
+ if (failedRulings + blockers === 0) {
446
+ setRouteNote(
447
+ route,
448
+ "validate failed with no remediable handle (no pass:false risk ruling, no blockers entry) — the remediation arm cannot act; fix manually or revise the plan",
449
+ );
450
+ return "stop";
451
+ }
452
+ if ((state.named.remediation?.length ?? 0) >= maxFixRounds) {
453
+ setRouteNote(
454
+ route,
455
+ `validate still fails after ${maxFixRounds} remediation round${maxFixRounds === 1 ? "" : "s"} — fix manually, then resume to re-validate`,
456
+ );
457
+ return "stop";
458
+ }
459
+ return "validate-fix";
460
+ },
461
+ { readsData: false },
462
+ );
463
+ return route;
464
+ };
424
465
 
425
466
  /**
426
- * Build's repair-arm progress gate — the deterministic no-op backstop. The
467
+ * The repair-arm progress gate — the deterministic no-op backstop. The
427
468
  * `remediation` channel carries `remediationOutcome`'s `{ changed }` (a
428
469
  * git-only tree digest snapshotted around the `validate-fix` stage): an
429
470
  * unchanged tree makes the re-validate lap provably futile (validate's
430
471
  * verdict is a function of the tree), so it STOPs with a note instead of
431
472
  * burning a backward-jump on an identical verdict. Only an explicit
432
473
  * `changed: false` stops — a missing signal (non-repo, git failure, absent
433
- * channel) proceeds, the worktree-digest degrade doctrine.
474
+ * channel) proceeds, the worktree-digest degrade doctrine. A factory for the
475
+ * same note-symbol-aliasing reason as `validateGate`. NOTE the resume
476
+ * asymmetry this stop relies on: the runner never re-dispatches a halted
477
+ * SIDE-EFFECT gate stage — resume re-enters at this gate's onward target
478
+ * (implement-scope-check), so a hand-fix after this stop re-verifies
479
+ * end-to-end instead of replaying a remediation that would no-op again.
434
480
  */
435
- const validateFixGate: EdgeFn = defineRoute(
436
- ["implement-scope-check", "stop"],
437
- ({ state }) => {
438
- const data = state.named.remediation?.at(-1)?.data as { changed?: unknown } | undefined;
439
- if (data?.changed !== false) return "implement-scope-check";
440
- setRouteNote(
441
- validateFixGate,
442
- "remediation left the working tree unchanged — re-validating cannot change the verdict; fix manually or revise the plan",
443
- );
444
- return "stop";
445
- },
446
- { readsData: false },
447
- );
481
+ const validateFixGate = (): EdgeFn => {
482
+ const route: EdgeFn = defineRoute(
483
+ ["implement-scope-check", "stop"],
484
+ ({ state }) => {
485
+ const data = state.named.remediation?.at(-1)?.data as { changed?: unknown } | undefined;
486
+ if (data?.changed !== false) return "implement-scope-check";
487
+ setRouteNote(
488
+ route,
489
+ "remediation left the working tree unchanged — re-validating cannot change the verdict; fix manually or revise the plan",
490
+ );
491
+ return "stop";
492
+ },
493
+ { readsData: false },
494
+ );
495
+ return route;
496
+ };
448
497
 
449
498
  const buildWorkflow = defineWorkflow({
450
499
  name: "build",
451
500
  description:
452
- "Ship, sliced: capture the verbatim brief as a goal artifact (the north star the quality gates' completeness/correctness dimensions and validate anchor against) → research the brief → decompose it into vertical slices → two-phase slice gate (a deterministic floor — dependency-cycle freedom + brief-coverage conservation so a slice-fix can't pass by dropping scope — then one LLM design-readiness judgment that each slice is chewable by a single design pass) with a slice-fix loop → design each slice in parallel → one consolidated developer checkpoint (accept or adjust the proposed interfaces/data types, adjustments applied surgically and cascaded to dependents) → synthesize hierarchically (per-cluster sub-plans → one merged plan) → tier-scaled quality-panel gate (a one-slice, <=2-phase run grades correctness+completeness only; larger or previously-failing runs grade the full completeness/correctness/actionability/pattern-following/architecture-fit roster) where a dimension's first blocking verdict gets one confirming second judgment before it buys a plan-fix round → elaborate code per phase in parallel → splice it into the plan → re-grade the code-bearing plan (same tier + confirm contract) → implement → implement-scope-check → reconcile → validate → commit. Research-led; three automated gates plus one human design checkpoint, before design, before code, and after the splice.",
501
+ "Ship, sliced: capture the verbatim brief as a goal artifact (the north star the quality gates' completeness/correctness dimensions and validate anchor against) → research the brief → derive a goal-anchored acceptance inventory (the executable standard of completion, frozen before any plan so it cannot inherit the plan's scope; the completeness gates anchor on it and validate executes its evidence commands) → decompose it into vertical slices → two-phase slice gate (a deterministic floor — dependency-cycle freedom + brief-coverage conservation so a slice-fix can't pass by dropping scope — then one LLM design-readiness judgment that each slice is chewable by a single design pass) with a slice-fix loop → design each slice in parallel → one consolidated developer checkpoint (accept or adjust the proposed interfaces/data types, adjustments applied surgically and cascaded to dependents) → synthesize hierarchically (per-cluster sub-plans → one merged plan) → tier-scaled quality-panel gate (a one-slice, <=2-phase run grades correctness+completeness only; larger or previously-failing runs grade the full completeness/correctness/actionability/pattern-following/architecture-fit roster) where a dimension's fresh HIGH-severity, risk-ruling, or regressed-pass blocking verdict gets one confirming second judgment before it buys a plan-fix round (a first-time medium finding routes straight to the surgical fix) → elaborate code per phase in parallel → splice it into the plan → re-grade the code-bearing plan (same tier + confirm contract) → implement → implement-scope-check → reconcile → validate → commit. Research-led; three automated gates plus one human design checkpoint, before design, before code, and after the splice.",
453
502
  start: "goal",
454
503
  stages: {
455
504
  // The user's brief, verbatim, on its own channel — the judgment seams
@@ -462,7 +511,20 @@ const buildWorkflow = defineWorkflow({
462
511
  // gate's architecture-fit dimension its --context. Prompt-dispatched so it
463
512
  // still receives the raw brief now that `goal` holds the start slot.
464
513
  research: produces({ prompt: RESEARCH_BRIEF_PROMPT }),
465
- slice: produces(),
514
+ // The goal-derived acceptance inventory (see ship's twin comment): the
515
+ // executable standard of completion, frozen before slicing/planning so
516
+ // it cannot inherit their scope. Threaded to the plan/code gates'
517
+ // completeness units (--acceptance) and to validate, which executes the
518
+ // evidence commands. Deliberately NOT fed to slice/design/synthesize —
519
+ // the bounded-context doctrine that keeps `goal` out of the generative
520
+ // stages applies to its derived standard too.
521
+ acceptance: produces({ reads: ["goal", "research"] }),
522
+ // `reads: ["research"]` (not the rolling primary): `acceptance` now sits
523
+ // between research and slice, so the rolling primary at this stage is
524
+ // the acceptance doc — the explicit read restores the research artifact
525
+ // as slice's grounding input (dispatched as `--research <path>`; the
526
+ // slice skill accepts the flag form of its fresh input).
527
+ slice: produces({ reads: ["research"] }),
466
528
  // Deterministic floor (no LLM): dependency-cycle freedom + brief-coverage conservation.
467
529
  "slice-check": produces.script({ reads: ["slices"], run: sliceStructureCheck }),
468
530
  // One LLM design-readiness judgment; verdicts on their own channel.
@@ -525,7 +587,7 @@ const buildWorkflow = defineWorkflow({
525
587
  outcome: planVerdictOutcome,
526
588
  // `research` is read so the architecture-fit unit can thread it as
527
589
  // --context; `goal` so completeness/correctness anchor on the brief.
528
- reads: ["plans", "research", "goal"],
590
+ reads: ["plans", "research", "goal", "acceptance"],
529
591
  }),
530
592
  // Stamp the duty demotion onto the graded verdicts as legible on-disk data
531
593
  // (a `risk_duty_demotions` array written in place onto each demoted
@@ -544,7 +606,7 @@ const buildWorkflow = defineWorkflow({
544
606
  skill: "grade",
545
607
  loop: PLAN_CONFIRM_FANOUT,
546
608
  outcome: planVerdictOutcome,
547
- reads: ["plans", "research", "goal"],
609
+ reads: ["plans", "research", "goal", "acceptance"],
548
610
  }),
549
611
  "plan-fix": produces({
550
612
  skill: "amend",
@@ -594,7 +656,7 @@ const buildWorkflow = defineWorkflow({
594
656
  outcome: codeVerdictOutcome,
595
657
  // `research` is read so the architecture-fit unit can thread it as
596
658
  // --context; `goal` so completeness/correctness anchor on the brief.
597
- reads: ["plans", "research", "goal"],
659
+ reads: ["plans", "research", "goal", "acceptance"],
598
660
  }),
599
661
  // The code-gate twin of `plan-demote`: stamp the duty demotion onto the
600
662
  // code-graded verdicts (re-grading `plans` on `code-verdicts`) one hop
@@ -615,7 +677,7 @@ const buildWorkflow = defineWorkflow({
615
677
  skill: "grade",
616
678
  loop: CODE_CONFIRM_FANOUT,
617
679
  outcome: codeVerdictOutcome,
618
- reads: ["plans", "research", "goal"],
680
+ reads: ["plans", "research", "goal", "acceptance"],
619
681
  }),
620
682
  "code-fix": produces({
621
683
  skill: "amend",
@@ -672,9 +734,12 @@ const buildWorkflow = defineWorkflow({
672
734
  },
673
735
  edges: {
674
736
  goal: "research",
675
- // Research's artifact is auto-fed to slice as its argument (the slice skill's
676
- // "Fresh" input is a research path).
677
- research: "slice",
737
+ // The acceptance inventory derives between research (which grounds its
738
+ // evidence commands) and slice (which must never see it — bounded
739
+ // context). Slice's research input rides its explicit `reads` now that
740
+ // the rolling primary here is the acceptance doc.
741
+ research: "acceptance",
742
+ acceptance: "slice",
678
743
  slice: "slice-check",
679
744
  // Skip the design-readiness re-grade when the gate is already satisfied — after
680
745
  // a `slice-fix` that only cleared the deterministic structure floor (the common
@@ -734,8 +799,11 @@ const buildWorkflow = defineWorkflow({
734
799
  // readers. `plan-grade` is now a simple always-hop edge to `plan-demote`;
735
800
  // the route body below is the verbatim logic that used to live here.
736
801
  "plan-grade": "plan-demote",
737
- // Pass ⇒ code. A dimension's FIRST blocking verdict ⇒ plan-confirm (one
738
- // independent second judgment — see `confirmDue`); a confirmed blocker, or
802
+ // Pass ⇒ code. A dimension's fresh confirm-worthy blocking verdict — a
803
+ // HIGH-severity or risk-ruling blocker, or a regressed carried pass — ⇒
804
+ // plan-confirm (one independent second judgment — see `confirmDue`; a
805
+ // first-time medium finding skips the confirm and buys the surgical fix
806
+ // directly); a confirmed blocker, or
739
807
  // a failure with no dimension blocking (the citation floor alone is red) ⇒
740
808
  // plan-fix, looping back THROUGH the citation floor so the amended plan
741
809
  // re-verifies. Route logic unchanged — merely shifted one hop later so the
@@ -777,7 +845,7 @@ const buildWorkflow = defineWorkflow({
777
845
  // duty-demotion write-back lands before this fold. `code-grade` is now a
778
846
  // simple always-hop edge to `code-demote`; the route body below is verbatim.
779
847
  "code-grade": "code-demote",
780
- // Pass ⇒ implement. A first blocking verdict ⇒ code-confirm (the plan
848
+ // Pass ⇒ implement. A fresh confirm-worthy blocking verdict ⇒ code-confirm (the plan
781
849
  // gate's confirm contract, on the code-verdicts channel); a confirmed
782
850
  // blocker or cite-floor-only failure ⇒ code-fix. Routes to `code-fix`, NOT
783
851
  // back to `code`: the gate fails on plan-text defects (edit anchors, line
@@ -833,15 +901,16 @@ const buildWorkflow = defineWorkflow({
833
901
  // it re-validated an unchanged tree until the guard halted the run).
834
902
  // A missing/unexpected verdict stays terminal STOP, so un-anticipated data
835
903
  // can never route INTO commit OR the repair arm. Safe by construction: the
836
- // sole path to commit is an explicit pass.
837
- validate: validateGate,
904
+ // sole path to commit is an explicit pass. No fix-round cap — the runner's
905
+ // backward-jump guard is build's remediation budget.
906
+ validate: validateGate(),
838
907
  // Re-entry after the repair arm: remediate's code-mutation is followed by a
839
908
  // fresh scope check → reconcile → validate pass, so a fix is re-verified
840
909
  // end-to-end before the gate re-folds. Now a decision edge (`validateFixGate`
841
910
  // folds the `remediation` channel's deterministic digest verdict): a
842
911
  // remediation that changed nothing STOPs here — progress is verified, not
843
912
  // assumed — while a real fix proceeds into the loop body.
844
- "validate-fix": validateFixGate,
913
+ "validate-fix": validateFixGate(),
845
914
  commit: "stop",
846
915
  },
847
916
  });
@@ -919,44 +988,68 @@ const shipGradeGate: EdgeFn = defineRoute(
919
988
 
920
989
  /**
921
990
  * ship — the lightweight `/wf` preset: the no-ceremony path for small-to-
922
- * midsize tasks whose approach is obvious. goal → research → plan →
923
- * plan-cite-check → grade → implement → implement-scope-check → reconcile →
924
- * validate → commit, stop-on-fail at every gate with NO backward edges: a red
925
- * gate terminates the run (the agent hand-repairs and re-invokes) instead of
926
- * looping a fix cycle. Research stays front-loaded — a ≤2-subagent grounding
927
- * pass (SHIP_RESEARCH_PROMPT, not a full `/skill:research` run) — because the
928
- * single PRE-implement grade's architecture-fit dimension needs its artifact as
929
- * `--context`. That grade is tier-independent: the bespoke SHIP_DIMENSION_FANOUT
930
- * always grades the full correctness/completeness/architecture-fit roster (no
931
- * gateTier/gateRoster light-tier drop), and SHIP's gate folds risk flags without
932
- * re-folding the citation floor (that floor folds at its own edge).
991
+ * midsize tasks whose approach is obvious. goal → research → acceptance →
992
+ * plan → plan-cite-check → grade → implement → implement-scope-check →
993
+ * reconcile → validate → (validate-fix, once) | commit, stop-on-fail at every gate: a red
994
+ * gate halts the run (the agent hand-repairs and RESUMES — `/wf @<runId>`
995
+ * re-runs the halted gate against the repaired tree, reusing every upstream
996
+ * artifact) instead of looping a fix cycle. The ONE concession to that
997
+ * identity is validate's single bounded remediation hop (run 7299: a
998
+ * remediable docs-gap `fail` at the last stage stranded ~50 min of verified
999
+ * implementation behind a terminal stop). Research stays front-loaded — a
1000
+ * brief-sized grounding pass (SHIP_RESEARCH_PROMPT, not a full
1001
+ * `/skill:research` run: at most one verify-only dispatch when the brief names
1002
+ * root cause, files, or fix — none when its anchors are plain file paths; at
1003
+ * most two targeted dispatches otherwise) — because the single PRE-implement
1004
+ * grade's architecture-fit dimension needs its artifact as `--context`. That
1005
+ * grade is tier-independent: the bespoke SHIP_DIMENSION_FANOUT always grades
1006
+ * the full correctness/completeness/architecture-fit roster (no
1007
+ * gateTier/gateRoster light-tier drop), and SHIP's gate folds risk flags
1008
+ * without re-folding the citation floor (that floor folds at its own edge).
933
1009
  */
934
1010
  const shipWorkflow = defineWorkflow({
935
1011
  name: "ship",
936
1012
  description:
937
- "Ship, unsliced: capture the verbatim brief as a goal artifact → ground it with at most two targeted codebase-analyzer dispatches (no /skill:research) → one lightweight quick-plan pass → deterministic citation floor (files: coverage gaps stop; citation-resolution findings are advisory and adjudicated by the grade panel) → single tier-independent quality gate (correctness/completeness/architecture-fit, stop-on-fail) → implement → implement-scope-check → reconcile → validate → commit. Every gate terminates the run on fail; no fix loops.",
1013
+ "Ship, unsliced: capture the verbatim brief as a goal artifact → ground it with a brief-sized research pass (none or one verify-only codebase-analyzer dispatch when the brief names root cause, files, or fix; at most two targeted dispatches otherwise — no /skill:research) → derive a goal-anchored acceptance inventory (the executable standard of completion, frozen before planning; quick-plan records a per-item disposition, the completeness gate anchors on it, validate executes its evidence commands) → one lightweight quick-plan pass → deterministic citation floor (files: coverage gaps stop; citation-resolution findings are advisory and adjudicated by the grade panel) → single tier-independent quality gate (correctness/completeness/architecture-fit, stop-on-fail) → implement → implement-scope-check → reconcile → validate → commit. Every gate halts the run on fail (hand-repair, then resume with /wf @<runId> to re-run the gate) — except a validate fail carrying structured remediable handles, which buys ONE bounded remediation hop before halting.",
938
1014
  start: "goal",
939
1015
  stages: {
940
1016
  // build's verbatim goal capture — the brief on its own channel, plus the
941
1017
  // run-start pre-existing-dirty snapshot the scope-check subtracts.
942
1018
  goal: produces.script({ run: captureGoal }),
943
1019
  // The lean grounding pass — SHIP_RESEARCH_PROMPT (a custom prompt, NOT
944
- // /skill:research): ≤2 sequential codebase-analyzer subagents, then one
945
- // grounding doc under .rpiv/artifacts/research/. A prompt stage, so the
946
- // stage name `research` drives outcome derivation (research contract →
947
- // `research` bucket) exactly as build's RESEARCH_BRIEF_PROMPT stage does.
1020
+ // /skill:research), sized to the brief's pre-chewedness: at most one
1021
+ // verify-only codebase-analyzer dispatch when the brief names root
1022
+ // cause, files, or fix (none when its anchors are plain file paths);
1023
+ // at most two targeted dispatches when it names only a symptom; then
1024
+ // one grounding doc under .rpiv/artifacts/research/. A prompt stage,
1025
+ // so the stage name `research` drives outcome derivation (research
1026
+ // contract → `research` bucket) exactly as build's
1027
+ // RESEARCH_BRIEF_PROMPT stage does.
948
1028
  research: produces({ prompt: SHIP_RESEARCH_PROMPT }),
1029
+ // The goal-derived acceptance inventory — the executable standard of
1030
+ // completion, authored BEFORE any plan exists so it cannot inherit the
1031
+ // plan's scope. Items enumerate the verbatim brief's asks (research
1032
+ // grounds only the evidence commands, never membership — the skill's
1033
+ // hard rule, since research routinely narrows the brief). Downstream:
1034
+ // quick-plan addresses-or-defers each item, the grade panel's
1035
+ // completeness unit anchors on the inventory (--acceptance), and
1036
+ // validate EXECUTES the evidence commands against the finished tree.
1037
+ // Outcome derives from the acceptance contract (artifactKind:
1038
+ // acceptance → `acceptance` bucket).
1039
+ acceptance: produces({ reads: ["goal", "research"] }),
949
1040
  // The lightweight planner — quick-plan: ONE targeted
950
1041
  // codebase-pattern-finder dispatch, one `status: ready` plan, no risks
951
1042
  // frontmatter, no multi-slice decomposition. Derives its `plans` outcome
952
- // from the quick-plan contract (artifactKind: plan). Reads BOTH channels
953
- // explicitly (`--research <path> --goal <path>`) — without `goal` the
954
- // stage falls to the rolling primary and the planner sees only the
955
- // research doc, whose grounding routinely narrows the brief; the grade
956
- // panel's completeness dimension anchors on the VERBATIM goal, so the
957
- // planner must anchor on the same artifact to defer narrowed-out asks
958
- // explicitly instead of silently inheriting the drop.
959
- plan: produces({ skill: "quick-plan", reads: ["research", "goal"] }),
1043
+ // from the quick-plan contract (artifactKind: plan). Reads all three
1044
+ // channels explicitly (`--research <path> --goal <path>
1045
+ // --acceptance <path>`) — without `goal` the stage falls to the rolling
1046
+ // primary and the planner sees only the research doc, whose grounding
1047
+ // routinely narrows the brief; the grade panel's completeness dimension
1048
+ // anchors on the VERBATIM goal and the acceptance inventory, so the
1049
+ // planner must anchor on the same artifacts and record a per-item
1050
+ // disposition (implemented or deferred) instead of silently inheriting
1051
+ // the drop.
1052
+ plan: produces({ skill: "quick-plan", reads: ["research", "goal", "acceptance"] }),
960
1053
  // Deterministic citation floor BEFORE the LLM gate — build's verifier
961
1054
  // verbatim. Only a `files:` coverage gap fails structurally and STOPs the
962
1055
  // run; every citation-resolution finding (unresolved path, ambiguity,
@@ -967,12 +1060,14 @@ const shipWorkflow = defineWorkflow({
967
1060
  // (SHIP_DIMENSION_FANOUT — tier-independent, no confirm/snapshot arms);
968
1061
  // verdicts on the `ship-verdicts` channel. `research` is read so the
969
1062
  // architecture-fit unit threads it as --context; `goal` so
970
- // completeness/correctness anchor on the verbatim brief.
1063
+ // completeness/correctness anchor on the verbatim brief; `acceptance` so
1064
+ // the completeness unit checks the plan's per-item dispositions against
1065
+ // the frozen inventory (--acceptance).
971
1066
  grade: produces({
972
1067
  skill: "grade",
973
1068
  loop: SHIP_DIMENSION_FANOUT,
974
1069
  outcome: shipVerdictOutcome,
975
- reads: ["plans", "research", "goal"],
1070
+ reads: ["plans", "research", "goal", "acceptance"],
976
1071
  }),
977
1072
  // Dep-gated DAG implement — build's lane verbatim.
978
1073
  implement: acts({ loop: IMPLEMENT_DAG_FANOUT, reads: ["plans"] }),
@@ -984,11 +1079,18 @@ const shipWorkflow = defineWorkflow({
984
1079
  // verbatim. Pass ⇒ validate; fail/missing ⇒ STOP (no fallback).
985
1080
  reconcile: produces.script({ reads: ["plans"], run: reconcile }),
986
1081
  validate: produces({ prompt: VALIDATE_GOAL_PROMPT }),
1082
+ // Repair arm — build's stage verbatim; ship's validate gate dispatches it
1083
+ // at most ONCE (maxFixRounds: 1). Kept because the terminal gate is where
1084
+ // a red verdict strands the most verified work over the least defect: the
1085
+ // arm acts only on the report's structured handles, and its own progress
1086
+ // gate stops a no-op remediation instead of re-validating an unchanged tree.
1087
+ "validate-fix": acts({ skill: "remediate", reads: ["plans", "validation"], outcome: remediationOutcome }),
987
1088
  commit: acts({ prompt: COMMIT_BASELINE_PROMPT, outcome: gitCommitOutcome }),
988
1089
  },
989
1090
  edges: {
990
1091
  goal: "research",
991
- research: "plan",
1092
+ research: "acceptance",
1093
+ acceptance: "plan",
992
1094
  plan: "plan-cite-check",
993
1095
  // Both gates are the named EdgeFns above — they attach a stop-reason
994
1096
  // ROUTE_NOTE the recap surfaces; routing semantics are unchanged.
@@ -1007,14 +1109,21 @@ const shipWorkflow = defineWorkflow({
1007
1109
  // Reconciliation gate — build's route verbatim: pass ⇒ validate;
1008
1110
  // fail/missing ⇒ STOP (plan-vs-tree drift the agent reconciles manually).
1009
1111
  reconcile: match("verdict", { validate: "pass" }, { from: "reconcile" }),
1010
- // Validate gate — build's validate edge (match verdict pass⇒commit,
1011
- // from "validation") minus the `validate-fix` arm: `pass` ⇒ commit; `fail`
1012
- // or missing ⇒ STOP — deliberately NO validate-fix/remediate repair arm
1013
- // (the lightweight preset does not loop). NOT vet's tail: vet's validate
1014
- // routes to code-review, which gates back to blueprint (a bounded backward
1015
- // loop, not stop-on-fail). Sourced from validate's published verdict
1016
- // channel (`from: "validation"`).
1017
- validate: match("verdict", { commit: "pass" }, { from: "validation" }),
1112
+ // Validate gate — build's classifying gate, capped at ONE remediation
1113
+ // round: `pass` ⇒ commit; a `fail` WITH structured remediable handles and
1114
+ // no remediation spent ⇒ validate-fix; every other fail (prose-only, or
1115
+ // the one round already used) ⇒ STOP with a route note. The cap is what
1116
+ // keeps ship's stop-on-fail identity: the arm is a single bounded hop,
1117
+ // not a loop — the runner's `remediation`-channel length enforces it
1118
+ // deterministically. NOT vet's tail: vet's validate routes to
1119
+ // code-review, which gates back to blueprint (a bounded backward loop).
1120
+ validate: validateGate({ maxFixRounds: 1 }),
1121
+ // Re-entry after the repair arm — build's edge: a remediation that
1122
+ // changed nothing STOPs (progress is verified, not assumed); a real fix
1123
+ // re-enters at implement-scope-check so it is re-verified end-to-end
1124
+ // (scope floor → reconcile → validate) before the gate re-folds — where
1125
+ // the spent round now stops any remaining fail.
1126
+ "validate-fix": validateFixGate(),
1018
1127
  commit: "stop",
1019
1128
  },
1020
1129
  });