@juicesharp/rpiv-pi 2.6.3 → 2.7.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/docs/workflows.md +1 -1
  2. package/extensions/rpiv-core/agents.ts +10 -13
  3. package/extensions/rpiv-core/artifact-collector.ts +111 -6
  4. package/extensions/rpiv-core/bash-timeout.ts +12 -2
  5. package/extensions/rpiv-core/built-in-workflows.ts +233 -3514
  6. package/extensions/rpiv-core/built-ins/citations.ts +357 -0
  7. package/extensions/rpiv-core/built-ins/gates.ts +613 -0
  8. package/extensions/rpiv-core/built-ins/goal-baseline.ts +269 -0
  9. package/extensions/rpiv-core/built-ins/grade-panel.ts +199 -0
  10. package/extensions/rpiv-core/built-ins/index.ts +46 -0
  11. package/extensions/rpiv-core/built-ins/plan-cite.ts +219 -0
  12. package/extensions/rpiv-core/built-ins/plan-phases.ts +424 -0
  13. package/extensions/rpiv-core/built-ins/priors.ts +352 -0
  14. package/extensions/rpiv-core/built-ins/reconcile.ts +283 -0
  15. package/extensions/rpiv-core/built-ins/scope-checks.ts +378 -0
  16. package/extensions/rpiv-core/built-ins/shared.ts +17 -1
  17. package/extensions/rpiv-core/built-ins/slice-checks.ts +420 -0
  18. package/extensions/rpiv-core/built-ins/slices.ts +288 -0
  19. package/extensions/rpiv-core/constants.ts +5 -1
  20. package/extensions/rpiv-core/lane-console.ts +9 -2
  21. package/extensions/rpiv-core/lane-list.ts +10 -1
  22. package/extensions/rpiv-core/question-lifecycle.ts +2 -2
  23. package/extensions/rpiv-core/register-built-in-workflows.ts +2 -2
  24. package/extensions/rpiv-core/run-lane-registry.ts +83 -83
  25. package/package.json +2 -2
  26. package/skills/elaborate/SKILL.md +1 -1
  27. package/skills/grade/SKILL.md +1 -1
  28. package/skills/implement/SKILL.md +1 -0
  29. package/skills/plan/SKILL.md +3 -1
  30. package/skills/remediate/SKILL.md +1 -0
  31. package/skills/synthesize/SKILL.md +1 -0
  32. package/skills/validate/SKILL.md +25 -19
  33. package/skills/validate/templates/validation.md +1 -1
@@ -0,0 +1,269 @@
1
+ /**
2
+ * The goal channel (verbatim brief capture) and the run-start git baseline the
3
+ * scope floors and the validate/commit prompts consume.
4
+ */
5
+ import { execFileSync } from "node:child_process";
6
+ import { mkdirSync, writeFileSync } from "node:fs";
7
+ import { dirname, join } from "node:path";
8
+ import {
9
+ handleToString,
10
+ type Output,
11
+ type PromptFn,
12
+ type RunView,
13
+ type ScriptContext,
14
+ } from "@juicesharp/rpiv-workflow/registration";
15
+ import { latestFsArtifact, readArtifactFile } from "./shared.js";
16
+
17
+ /** Bucket directory the goal capture writes into — build's verbatim-brief channel. */
18
+ const GOAL_DIR = ".rpiv/artifacts/goal";
19
+
20
+ /**
21
+ * Capture the user's brief VERBATIM as build's `goal` channel — the north-star
22
+ * artifact the judgment seams anchor against (the grade panels'
23
+ * completeness/correctness dimensions and `validate`). A script stage (no LLM)
24
+ * so nothing refracts the wording: `research` carries the goal's intent,
25
+ * grounded and expanded, but explicit user constraints ("keep it minimal",
26
+ * "don't touch auth") routinely don't survive that refraction — the raw file
27
+ * is the only artifact that holds them. The body is the brief byte-for-byte;
28
+ * added frontmatter or headers would pollute "the user's exact words".
29
+ *
30
+ * Publishes under its record key (`goal`): a script stage may not carry an
31
+ * `outcome` (`script-with-outcome` is a load error) and needs none — the
32
+ * returned envelope IS the output. Timestamped filename so concurrent/repeat
33
+ * runs never collide; on resume the recorded path replays from the JSONL
34
+ * trail, so the fanout `units()` closures reading the channel stay
35
+ * deterministic.
36
+ */
37
+ const captureGoal = ({ state, cwd }: ScriptContext): Omit<Output, "meta"> => {
38
+ const stamp = new Date().toISOString().replace(/[:.]/g, "-");
39
+ const rel = join(GOAL_DIR, `goal-${stamp}.md`);
40
+ mkdirSync(join(cwd, GOAL_DIR), { recursive: true });
41
+ writeFileSync(join(cwd, rel), state.originalInput, "utf-8");
42
+ // Snapshot the paths ALREADY dirty before the run touched anything — the
43
+ // validate stage judges working-tree scope criteria against the run's own
44
+ // delta, and the commit skill fences these paths off its commit. Timestamped
45
+ // like the goal file itself (concurrent/repeat runs never read each other's
46
+ // snapshot — there is NO fixed rendezvous path) and published on the goal
47
+ // channel with role "baseline", so the JSONL trail carries the exact path to
48
+ // every consumer and replays it deterministically on resume. Best-effort: a
49
+ // non-repo / git-unavailable cwd writes an empty snapshot, so consumers
50
+ // degrade to baseline-less behavior rather than failing the goal capture.
51
+ const baselineRel = join(GOAL_DIR, `baseline-${stamp}.json`);
52
+ writeCommitBaseline(cwd, baselineRel);
53
+ return {
54
+ kind: "md",
55
+ // Order is load-bearing: `latestFsArtifact(state, "goal")` takes the FIRST
56
+ // fs artifact — the goal md stays the channel's face (grade --goal flags,
57
+ // rolling primary); the baseline rides behind it under its role.
58
+ artifacts: [
59
+ { handle: { kind: "fs", path: rel } },
60
+ { handle: { kind: "fs", path: baselineRel }, role: "baseline" },
61
+ ],
62
+ data: {},
63
+ };
64
+ };
65
+
66
+ /** One parsed `git status --porcelain`/`--short` line: the 2-char `XY` status
67
+ * code plus the resolved path. `xy === "??"` is the untracked class — the only
68
+ * code whose content cannot have overwritten anything a phase owns, which is
69
+ * what the scope floor's quarantine partition keys on. */
70
+ interface GitStatusEntry {
71
+ xy: string;
72
+ path: string;
73
+ }
74
+
75
+ /** Parse `git status --porcelain`/`--short` output into `{ xy, path }` entries.
76
+ * Keeps the 2-char `XY` status code and resolves rename targets
77
+ * (`XY old -> new` → `new`), so the two output forms (`--porcelain`, `--short`)
78
+ * normalize identically. A porcelain line is always `XY <path>` or
79
+ * `XY <old> -> <new>`; blank lines drop. */
80
+ const parseGitStatusEntries = (out: string): GitStatusEntry[] =>
81
+ out
82
+ .split("\n")
83
+ .filter((l) => l.trim() !== "")
84
+ .map((l) => {
85
+ const rest = l.slice(3).trim();
86
+ const arrow = rest.indexOf(" -> ");
87
+ return { xy: l.slice(0, 2), path: arrow >= 0 ? rest.slice(arrow + 4).trim() : rest };
88
+ });
89
+
90
+ /** Path-only projection of `parseGitStatusEntries` — the baseline writer's shape. */
91
+ const parseGitStatusPaths = (out: string): string[] => parseGitStatusEntries(out).map((e) => e.path);
92
+
93
+ /** Record the paths dirty before the run to `rel` (best-effort; empty on any git failure). */
94
+ const writeCommitBaseline = (cwd: string, rel: string): void => {
95
+ let paths: string[] = [];
96
+ try {
97
+ // stdio: stderr ignored — without this, git's "fatal: not a git repository"
98
+ // leaks to the parent's stderr even though the catch treats it as a
99
+ // supported silent degrade (best-effort baseline, empty on failure).
100
+ // -uall: git collapses an untracked directory to one `dir/` entry by
101
+ // default, so a phase's brand-new files under a new directory would never
102
+ // string-match their `files:` declarations at the scope floor. Enumerate
103
+ // every file; the baseline and both scope checks MUST share this flag or
104
+ // their path universes diverge.
105
+ const out = execFileSync("git", ["status", "--short", "--untracked-files=all"], {
106
+ cwd,
107
+ encoding: "utf-8",
108
+ stdio: ["ignore", "pipe", "ignore"],
109
+ });
110
+ paths = parseGitStatusPaths(out);
111
+ } catch {
112
+ paths = [];
113
+ }
114
+ mkdirSync(dirname(join(cwd, rel)), { recursive: true });
115
+ writeFileSync(join(cwd, rel), JSON.stringify({ paths }, null, 2), "utf-8");
116
+ };
117
+
118
+ /** The run-start pre-existing-dirty snapshot riding the goal channel (role "baseline"). */
119
+ const goalBaselinePath = (state: RunView): string | undefined => {
120
+ const a = state.named.goal?.at(-1)?.artifacts.find((x) => x.role === "baseline" && x.handle.kind === "fs");
121
+ return a ? handleToString(a.handle) : undefined;
122
+ };
123
+
124
+ /**
125
+ * Read the run-start pre-existing-dirty baseline off the goal channel's
126
+ * "baseline" artifact: the `{ paths }` JSON the baseline writer records. Best-
127
+ * effort — `[]` on no path (no `goal` stage), an unreadable file, or a `paths`
128
+ * value that isn't a string array, so the scope floor degrades to baseline-less
129
+ * (nothing subtracted) rather than throwing.
130
+ */
131
+ const readGoalBaseline = (path: string | undefined, cwd: string): string[] => {
132
+ if (!path) return [];
133
+ try {
134
+ const parsed = JSON.parse(readArtifactFile(path, cwd)) as { paths?: unknown };
135
+ const p = parsed.paths;
136
+ return Array.isArray(p) ? p.filter((x): x is string => typeof x === "string") : [];
137
+ } catch {
138
+ return [];
139
+ }
140
+ };
141
+
142
+ /**
143
+ * Current dirty set via `git status --porcelain`, as `{ xy, path }` entries
144
+ * (rename targets resolved by the shared parser) — the scope floors read the
145
+ * paths AND partition on the `??` untracked code. Best-effort — `[]` on a
146
+ * non-repo / git-missing tree (the scope floor degrades to unguarded rather
147
+ * than failing a non-repo run; the catch treats that as a supported silent
148
+ * degrade). stdio: stderr is ignored, otherwise git's "fatal: not a git
149
+ * repository" leaks to the parent's stderr despite the catch. `-uall`
150
+ * enumerates untracked files individually (a collapsed `newdir/` entry can
151
+ * never string-match a declared `files:` path) — the baseline writer and both
152
+ * scope checks MUST share this flag or their path universes diverge.
153
+ */
154
+ const gitDirtyEntries = (cwd: string): GitStatusEntry[] => {
155
+ try {
156
+ const out = execFileSync("git", ["status", "--porcelain", "--untracked-files=all"], {
157
+ cwd,
158
+ encoding: "utf-8",
159
+ stdio: ["ignore", "pipe", "ignore"],
160
+ });
161
+ return parseGitStatusEntries(out);
162
+ } catch {
163
+ return [];
164
+ }
165
+ };
166
+
167
+ /** Paths under these run-bookkeeping trees are NEVER a scope violation — the run
168
+ * legitimately writes its artifacts/notes/trails here regardless of phase scope. */
169
+ const SCOPE_BOOKKEEPING_DIRS: ReadonlySet<string> = new Set([".rpiv", "thoughts"]);
170
+
171
+ /**
172
+ * The lane-level scope floor's pure core. Returns the dirty paths that are NOT
173
+ * explained by the run's declared write-set: a path is excess when it is outside
174
+ * `declared`, was NOT dirty at the run-start `baseline`, and is NOT under a
175
+ * bookkeeping tree (`.rpiv/`, `thoughts/`). The `implement` lane declared-set is
176
+ * the union of its plan's per-phase `files:`; `validate`'s whole-repo
177
+ * build/test writes are owned by a later stage, never by a phase.
178
+ *
179
+ * Empty `declared` ⇒ `[]` (degradation): a `files:`-less plan is serial-by-
180
+ * construction under the DAG fanout's missing-`files:` clause (full dep chain ⇒
181
+ * one phase per wave), so there is no concurrent sibling to corrupt and nothing
182
+ * to guard — the floor returns no excess and never false-fails a legacy plan.
183
+ * `validate`'s whole-repo writes are out of scope here regardless: they belong
184
+ * to `validate`, which runs AFTER this gate, so the lane's dirty set never
185
+ * carries them at the scope-check's read time.
186
+ *
187
+ * This is deliberately LANE-level, not per-phase: under concurrency, a dirty
188
+ * path cannot be attributed to the specific phase that wrote it, so per-phase
189
+ * enforcement would be unsound. The per-phase discipline is enforced upstream
190
+ * by the plan-authoring write-scope rule + the plan-time coverage floor;
191
+ * this lane floor is the structural backstop that catches a phase that escaped
192
+ * upstream discipline. Returns one entry per excess path.
193
+ */
194
+ const scopeExcess = (dirty: readonly string[], baseline: readonly string[], declared: readonly string[]): string[] => {
195
+ if (declared.length === 0) return [];
196
+ const declaredSet = new Set(declared);
197
+ const baselineSet = new Set(baseline);
198
+ const excess: string[] = [];
199
+ for (const path of dirty) {
200
+ if (declaredSet.has(path) || baselineSet.has(path)) continue;
201
+ const top = path.split("/")[0];
202
+ if (SCOPE_BOOKKEEPING_DIRS.has(top)) continue;
203
+ excess.push(path);
204
+ }
205
+ return excess;
206
+ };
207
+
208
+ /**
209
+ * Build's validate dispatch: the latest synthesized plan plus the goal and
210
+ * run-start-baseline flags. Sourcing the plan from the NAMED channel (not the
211
+ * rolling primary) is load-bearing: `code-grade` is a produces-fanout, so
212
+ * after the code gate the rolling primary is the LAST VERDICT JSON
213
+ * (`placeFanoutOutput` advances it per unit) and `implement` (acts) leaves it
214
+ * there — a plain `produces()` validate would receive a verdict path as its
215
+ * "plan". A prompt stage owns its whole message, so the `/skill:validate`
216
+ * prefix is explicit (polish precedent).
217
+ *
218
+ * `--baseline` threads the pre-existing-dirty snapshot `goal` captured at run
219
+ * start, so validate judges working-tree scope criteria ("only these files
220
+ * touched") against the RUN'S OWN delta instead of failing on dirt that was
221
+ * on disk before stage one — the same fence the commit dispatch applies. The
222
+ * path comes off the goal channel (this run's snapshot, replayed from the
223
+ * JSONL trail on resume), never a shared file another run could overwrite.
224
+ *
225
+ * `--scope` threads the scope floor's latest verdict JSON so validate
226
+ * ADJUDICATES tracked-excess findings the floor demoted instead of halting on
227
+ * (the `--cite-check` pattern: the deterministic floor produces evidence, the
228
+ * LLM judge rules). Absent ONLY when the floor never ran — `writeScopeVerdict`
229
+ * publishes on a clean pass too, so every post-floor dispatch carries the flag
230
+ * and the skill's adjudication step (verdict read + unconditional
231
+ * quarantine-manifest check) decides what there is to rule.
232
+ */
233
+ const VALIDATE_GOAL_PROMPT: PromptFn = ({ state }) => {
234
+ const parts = ["/skill:validate"];
235
+ const plan = latestFsArtifact(state, "plans");
236
+ if (plan?.handle.kind === "fs") parts.push(handleToString(plan.handle));
237
+ const goal = latestFsArtifact(state, "goal");
238
+ if (goal?.handle.kind === "fs") parts.push(`--goal ${handleToString(goal.handle)}`);
239
+ const baseline = goalBaselinePath(state);
240
+ if (baseline) parts.push(`--baseline ${baseline}`);
241
+ const scope = latestFsArtifact(state, "implement-scope-check");
242
+ if (scope?.handle.kind === "fs") parts.push(`--scope ${handleToString(scope.handle)}`);
243
+ return parts.join(" ");
244
+ };
245
+
246
+ /**
247
+ * Build's commit dispatch: thread the run-start baseline so the commit skill
248
+ * fences pre-existing dirt off the commit — `git-changes.mjs` takes the path
249
+ * as a flag, so there is no fixed rendezvous file for concurrent/repeat runs
250
+ * to clobber. Prompt-dispatched deliberately: the inherited rolling primary
251
+ * (the validation report path) was reaching the skill as a meaningless
252
+ * message-hint argument anyway; owning the message replaces that noise with
253
+ * the one flag the skill actually consumes.
254
+ */
255
+ const COMMIT_BASELINE_PROMPT: PromptFn = ({ state }) => {
256
+ const baseline = goalBaselinePath(state);
257
+ return baseline ? `/skill:commit --baseline ${baseline}` : "/skill:commit";
258
+ };
259
+
260
+ export type { GitStatusEntry };
261
+ export {
262
+ COMMIT_BASELINE_PROMPT,
263
+ captureGoal,
264
+ gitDirtyEntries,
265
+ goalBaselinePath,
266
+ readGoalBaseline,
267
+ scopeExcess,
268
+ VALIDATE_GOAL_PROMPT,
269
+ };
@@ -0,0 +1,199 @@
1
+ /**
2
+ * The grade panels: the shared tiered panel factory, its build-lane instances,
3
+ * and ship's bespoke tier-independent panel and verdict channel.
4
+ */
5
+ import { directoryPathCollector, fanout, handleToString, jsonBodyParser } from "@juicesharp/rpiv-workflow/registration";
6
+ import {
7
+ dimensionsToRegrade,
8
+ freshVerdicts,
9
+ GOAL_DIMENSIONS,
10
+ gateRoster,
11
+ gateTier,
12
+ latestVerdictPerDimension,
13
+ PLAN_DIMENSIONS,
14
+ planAuthoredRisks,
15
+ SHIP_DIMENSIONS,
16
+ SLICE_DIMENSIONS,
17
+ } from "./gates.js";
18
+ import { isSurgicalFix, priorArtifact } from "./priors.js";
19
+ import { latestFsArtifact } from "./shared.js";
20
+
21
+ /**
22
+ * A grade panel: one `grade` session per dimension over the latest artifact on
23
+ * `channel`. Each unit's prompt is the `grade` skill's flags
24
+ * (`--dimension <d> --artifact <path>`); the per-dimension verdicts fold via
25
+ * `allDimensionsPass`. Shared by the slice gate (over `slices`) and the plan +
26
+ * code gates (over `plans`), each on its own `verdictChannel`.
27
+ *
28
+ * The panel grades the tier's ROSTER (`gateTier`/`gateRoster`), over verdicts
29
+ * still FRESH for the current artifact (`freshVerdicts`) — a light run grades
30
+ * two dimensions, a regenerated artifact re-grades from scratch. On a re-grade
31
+ * it emits ONLY the dimensions `dimensionsToRegrade` says still need it (the
32
+ * rest carry their prior passing verdict forward) — but never an EMPTY set: an
33
+ * empty `units()` return falls through to a single dimensionless `grade`
34
+ * dispatch, so when nothing needs re-grading we fall back to the full roster.
35
+ * The route into the stage already skips it entirely when the accumulated
36
+ * verdicts clear the gate (see `plan-cite-check`/`code-cite-check`/`slice-check`
37
+ * edges), so this fallback only fires in the degenerate case where a fix left the
38
+ * cite floor red while every dimension passed.
39
+ *
40
+ * `architecture-fit` is the one dimension `grade` requires a `--context` for: it
41
+ * grades the plan against the research the slices rest on. The build flow always
42
+ * front-loads a `research` stage, so we thread the latest `research` artifact in
43
+ * as `--context` for that dimension only; likewise the latest `goal` artifact
44
+ * threads in as `--goal` for the `GOAL_DIMENSIONS` only. Every other dimension
45
+ * (and the slice gate's `design-readiness`, which never grades fit or
46
+ * goal-completeness) gets the bare flags.
47
+ *
48
+ * A CONFIRM panel (`confirm: true`) additionally threads each still-blocking
49
+ * dimension's latest verdict in as `--prior`: the confirming grader must
50
+ * adjudicate the prior round's findings — uphold or refute each with cited
51
+ * evidence — instead of silently out-voting them (a blind second opinion once
52
+ * rationalized past a checkable fact and its pass overwrote a correct fail at
53
+ * the latest-per-dimension fold). Only PENDING dimensions get the flag: in the
54
+ * degenerate full-roster fallback a carried passing verdict has nothing to
55
+ * adjudicate, and a first grade has no prior at all.
56
+ */
57
+ const gradePanelFanout = (
58
+ channel: string,
59
+ dimensions: readonly string[],
60
+ verdictChannel: string,
61
+ { confirm = false, priorChannel }: { confirm?: boolean; priorChannel?: string } = {},
62
+ ) =>
63
+ fanout({
64
+ source: channel,
65
+ unit: { by: "dimension-list", pattern: "dimensions" },
66
+ max: dimensions.length,
67
+ units: ({ state, cwd }) => {
68
+ const doc = latestFsArtifact(state, channel);
69
+ if (doc?.handle.kind !== "fs") return [];
70
+ const target = handleToString(doc.handle);
71
+ const research = latestFsArtifact(state, "research");
72
+ const contextFlag = research?.handle.kind === "fs" ? ` --context ${handleToString(research.handle)}` : "";
73
+ const goal = latestFsArtifact(state, "goal");
74
+ const goalFlag = goal?.handle.kind === "fs" ? ` --goal ${handleToString(goal.handle)}` : "";
75
+ const roster = gateRoster(gateTier(state, verdictChannel), dimensions);
76
+ const latest = latestVerdictPerDimension(freshVerdicts(state.named[verdictChannel], target));
77
+ const risks = planAuthoredRisks(state, channel);
78
+ const pending = dimensionsToRegrade(roster, latest, risks);
79
+ // Delta re-grade fallback guard (plan/code gates only — `priorChannel`
80
+ // is unset for the slice gate and both confirm panels). When the snapshot
81
+ // stage published a prior, compare it to the current plan: a SURGICAL
82
+ // amend (touched only sections a failing finding cited, ≤ threshold
83
+ // lines) re-grades only the still-pending dimensions; a NON-surgical
84
+ // amend (broad / out-of-scope / over-threshold / unreadable / unparseable)
85
+ // re-grades the FULL roster — a broad amend may have regressed a passing
86
+ // dimension the carry-forward would otherwise trust. With NO prior
87
+ // (round 1 / first re-grade) the carry-forward applies unchanged. See
88
+ // `isSurgicalFix` for the fail-closed contract.
89
+ const surgical =
90
+ !confirm && priorChannel !== undefined && isSurgicalFix(state, priorChannel, cwd, target, latest, pending);
91
+ const priorPresent = priorChannel !== undefined && priorArtifact(state, priorChannel) !== undefined;
92
+ const priorFlag = (d: string): string => {
93
+ if (!confirm || !pending.includes(d)) return "";
94
+ const handle = latest.get(d)?.artifacts.find((a) => a.handle.kind === "fs")?.handle;
95
+ return handle ? ` --prior ${handleToString(handle)}` : "";
96
+ };
97
+ const carryForward = pending.length > 0 ? pending : roster;
98
+ // A non-surgical result WITH a prior present re-grades the FULL roster;
99
+ // with NO prior the carry-forward applies (never an empty unit set —
100
+ // empty ⇒ single dimensionless grade fall-through).
101
+ const toGrade = surgical ? carryForward : priorPresent ? roster : carryForward;
102
+ return toGrade.map((d) => ({
103
+ prompt: `--dimension ${d} --artifact ${target}${d === "architecture-fit" ? contextFlag : ""}${GOAL_DIMENSIONS.has(d) ? goalFlag : ""}${priorFlag(d)}`,
104
+ label: d,
105
+ id: `${channel}-dim-${d}`,
106
+ }));
107
+ },
108
+ });
109
+
110
+ const SLICE_DIMENSION_FANOUT = gradePanelFanout("slices", SLICE_DIMENSIONS, "slice-verdicts");
111
+ const PLAN_DIMENSION_FANOUT = gradePanelFanout("plans", PLAN_DIMENSIONS, "plan-verdicts", {
112
+ priorChannel: "plan-snapshot",
113
+ });
114
+ // The post-splice code gate re-grades the SAME `plans` artifact on its own
115
+ // `code-verdicts` channel, so its carry-forward reads the code gate's verdicts,
116
+ // never the pre-elaborate plan gate's.
117
+ const CODE_DIMENSION_FANOUT = gradePanelFanout("plans", PLAN_DIMENSIONS, "code-verdicts", {
118
+ priorChannel: "code-snapshot",
119
+ });
120
+ // The confirm stages re-run the SAME panel machinery on the SAME verdict
121
+ // channel: with the failing dimensions the only ones pending, the panel emits
122
+ // exactly the blocking dimensions — one second judgment each, in confirm mode:
123
+ // each unit carries the blocking verdict as `--prior`, and the grade skill is
124
+ // contract-bound to rule on every prior finding (uphold, or refute with cited
125
+ // evidence) so a confirming pass records WHY the fail died instead of silently
126
+ // out-voting it at the latest-per-dimension fold.
127
+ // Distinct fanout instances (not aliases) so each stage owns its loop object.
128
+ const PLAN_CONFIRM_FANOUT = gradePanelFanout("plans", PLAN_DIMENSIONS, "plan-verdicts", { confirm: true });
129
+ const CODE_CONFIRM_FANOUT = gradePanelFanout("plans", PLAN_DIMENSIONS, "code-verdicts", { confirm: true });
130
+
131
+ /**
132
+ * Ship's grade panel — a bespoke `fanout({...})` mirroring `gradePanelFanout`'s
133
+ * body but binding the roster to `SHIP_DIMENSIONS` DIRECTLY (no
134
+ * `gateRoster(gateTier(...))` wrap) and dropping the confirm / `priorChannel`
135
+ * / surgical-fix machinery ship's single-pass grade does not carry. Kept: the
136
+ * `latestFsArtifact` guard (no plan → no units), the dimension-keyed
137
+ * `--context` (architecture-fit only, sourced from the front-loaded `research`
138
+ * artifact), the `--goal` flag for `GOAL_DIMENSIONS` (completeness/
139
+ * correctness), and the `freshVerdicts` / `latestVerdictPerDimension` /
140
+ * `dimensionsToRegrade` carry-forward so a re-grade emits only still-pending
141
+ * dimensions. Tier-independence is structural: the roster never shrinks, so a
142
+ * light run still grades `architecture-fit`. Ship-only addition: the
143
+ * correctness unit carries `--cite-check <verdict>` when the deterministic
144
+ * citation floor recorded findings — advisory by construction here, since a
145
+ * blocking finding STOPs at the cite gate before grade ever runs — so the
146
+ * grader adjudicates them rather than leaving them unread.
147
+ */
148
+ export const SHIP_DIMENSION_FANOUT = fanout({
149
+ source: "plans",
150
+ unit: { by: "dimension-list", pattern: "dimensions" },
151
+ max: SHIP_DIMENSIONS.length,
152
+ units: ({ state }) => {
153
+ const doc = latestFsArtifact(state, "plans");
154
+ if (doc?.handle.kind !== "fs") return [];
155
+ const target = handleToString(doc.handle);
156
+ const research = latestFsArtifact(state, "research");
157
+ const contextFlag = research?.handle.kind === "fs" ? ` --context ${handleToString(research.handle)}` : "";
158
+ const goal = latestFsArtifact(state, "goal");
159
+ const goalFlag = goal?.handle.kind === "fs" ? ` --goal ${handleToString(goal.handle)}` : "";
160
+ // The floor's findings (advisory by construction — see the fanout doc
161
+ // above) thread as `--cite-check`; no findings ⇒ no flag.
162
+ const cite = latestFsArtifact(state, "plan-cite-check");
163
+ const citeFindings = (state.named["plan-cite-check"]?.at(-1)?.data as { findings?: unknown[] } | undefined)
164
+ ?.findings;
165
+ const citeFlag =
166
+ cite?.handle.kind === "fs" && Array.isArray(citeFindings) && citeFindings.length > 0
167
+ ? ` --cite-check ${handleToString(cite.handle)}`
168
+ : "";
169
+ // Tier-independent roster: SHIP_DIMENSIONS verbatim — never gateRoster(gateTier(...)).
170
+ const roster = SHIP_DIMENSIONS;
171
+ const latest = latestVerdictPerDimension(freshVerdicts(state.named["ship-verdicts"], target));
172
+ const risks = planAuthoredRisks(state, "plans");
173
+ const pending = dimensionsToRegrade(roster, latest, risks);
174
+ const carryForward = pending.length > 0 ? pending : roster;
175
+ return carryForward.map((d) => ({
176
+ prompt: `--dimension ${d} --artifact ${target}${d === "architecture-fit" ? contextFlag : ""}${GOAL_DIMENSIONS.has(d) ? goalFlag : ""}${d === "correctness" ? citeFlag : ""}`,
177
+ label: d,
178
+ id: `plans-dim-${d}`,
179
+ }));
180
+ },
181
+ });
182
+
183
+ // Ship's grade panel writes its verdicts to a DISTINCT channel (same
184
+ // directory, different artifact basenames) so they never mix with build's
185
+ // plan/code verdicts — named for the workflow, completing the slice-verdicts
186
+ // / plan-verdicts / code-verdicts / ship-verdicts parallel.
187
+ export const shipVerdictOutcome = {
188
+ name: "ship-verdicts",
189
+ collector: directoryPathCollector({ dir: ".rpiv/artifacts/verdicts", ext: "json" }),
190
+ parser: jsonBodyParser,
191
+ };
192
+
193
+ export {
194
+ CODE_CONFIRM_FANOUT,
195
+ CODE_DIMENSION_FANOUT,
196
+ PLAN_CONFIRM_FANOUT,
197
+ PLAN_DIMENSION_FANOUT,
198
+ SLICE_DIMENSION_FANOUT,
199
+ };
@@ -3,6 +3,39 @@
3
3
  * `../built-in-workflows.ts` imports its relocated helpers from here. Each
4
4
  * re-export targets a `.js` specifier (Node16 ESM, source stays `.ts`).
5
5
  */
6
+
7
+ export {
8
+ allDimensionsPass,
9
+ anchorNitsOnly,
10
+ codeGatePasses,
11
+ confirmDue,
12
+ freshVerdicts,
13
+ latestArtifactPath,
14
+ latestVerdictPerDimension,
15
+ PLAN_DIMENSIONS,
16
+ planAuthoredRisks,
17
+ planGatePasses,
18
+ rulingEffectivePass,
19
+ SHIP_DIMENSIONS,
20
+ shipGatePasses,
21
+ sliceGatePasses,
22
+ subplanGatePasses,
23
+ verdictRiskRulings,
24
+ } from "./gates.js";
25
+ export {
26
+ COMMIT_BASELINE_PROMPT,
27
+ captureGoal,
28
+ VALIDATE_GOAL_PROMPT,
29
+ } from "./goal-baseline.js";
30
+ export {
31
+ CODE_CONFIRM_FANOUT,
32
+ CODE_DIMENSION_FANOUT,
33
+ PLAN_CONFIRM_FANOUT,
34
+ PLAN_DIMENSION_FANOUT,
35
+ SHIP_DIMENSION_FANOUT,
36
+ SLICE_DIMENSION_FANOUT,
37
+ shipVerdictOutcome,
38
+ } from "./grade-panel.js";
6
39
  export {
7
40
  closesFence,
8
41
  countHeadingsOutsideFences,
@@ -10,6 +43,17 @@ export {
10
43
  fencedSpans,
11
44
  forEachLineOutsideFences,
12
45
  } from "./markdown-fence.js";
46
+ export { planCitationCheck } from "./plan-cite.js";
47
+ export {
48
+ FRONTMATTER_PHASE_FANOUT,
49
+ IMPLEMENT_DAG_FANOUT,
50
+ IMPLEMENT_PLANS_FANOUT,
51
+ latestPlans,
52
+ REVIEW_PHASE_ITERATE,
53
+ } from "./plan-phases.js";
54
+ export { codeDemote, codeSnapshot, planDemote, planSnapshot } from "./priors.js";
55
+ export { reconcile } from "./reconcile.js";
56
+ export { implementScopeCheck, implementScopeCheckVet, ScopeVerdict, scopeQuarantine } from "./scope-checks.js";
13
57
  export {
14
58
  FILE_LINE_CITATION_RE,
15
59
  FsArtifact,
@@ -25,3 +69,5 @@ export {
25
69
  VERDICT_PASS_SCORE,
26
70
  writeStructureVerdict,
27
71
  } from "./shared.js";
72
+ export { sliceStructureCheck, subplanCoverageCheck } from "./slice-checks.js";
73
+ export { SLICE_DESIGN_FANOUT, SYNTH_CLUSTER_FANOUT } from "./slices.js";