@juicesharp/rpiv-workflow 2.2.0 → 2.3.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 (49) hide show
  1. package/audit-ctx.ts +7 -7
  2. package/audit.ts +29 -29
  3. package/chain-state.ts +14 -3
  4. package/death-scene.ts +9 -9
  5. package/docs/workflow-authoring.md +2 -2
  6. package/events.ts +1 -1
  7. package/failure-memos.ts +4 -4
  8. package/handle.ts +16 -1
  9. package/host.ts +1 -1
  10. package/loop-def.ts +1 -1
  11. package/loop-kinds.ts +12 -12
  12. package/loop-parallel.ts +15 -15
  13. package/loop-waves.ts +3 -3
  14. package/loop.ts +32 -30
  15. package/messages.ts +30 -17
  16. package/outcomes/collectors/workspace-diff.ts +3 -3
  17. package/outcomes/git-commit.ts +11 -4
  18. package/output-spec.ts +7 -7
  19. package/package.json +2 -2
  20. package/preview.ts +8 -1
  21. package/registration.ts +3 -3
  22. package/routing.ts +1 -1
  23. package/runner/chain-advance.ts +49 -25
  24. package/runner/errors.ts +1 -1
  25. package/runner/failure.ts +22 -23
  26. package/runner/preflight.ts +3 -6
  27. package/runner/resolve-stage.ts +3 -3
  28. package/runner/resume-entry.ts +5 -5
  29. package/runner/resume-loop.ts +5 -5
  30. package/runner/resume.ts +1 -1
  31. package/runner/run-stage.ts +69 -64
  32. package/runner/runner.ts +4 -4
  33. package/runner/script-stage.ts +17 -17
  34. package/sessions/bash-strikes.ts +9 -9
  35. package/sessions/extraction.ts +19 -12
  36. package/sessions/halt-routing.ts +14 -14
  37. package/sessions/index.ts +1 -1
  38. package/sessions/reattach.ts +10 -10
  39. package/sessions/sessions.ts +29 -23
  40. package/sessions/spawn.ts +5 -5
  41. package/sessions/success-persist.ts +3 -3
  42. package/stage-def.ts +2 -2
  43. package/stage-errors.ts +1 -1
  44. package/state/index.ts +1 -1
  45. package/state/names.ts +1 -1
  46. package/state/reads.ts +1 -1
  47. package/state/state.ts +4 -4
  48. package/state/writes.ts +2 -2
  49. package/types.ts +16 -16
package/loop-parallel.ts CHANGED
@@ -78,7 +78,7 @@ const fanoutUnitRef = (e: LoopEntry, i: number): UnitRef => {
78
78
  * cycle-throw from `computeWaveLevels` can't leak it.
79
79
  */
80
80
  export async function runFanoutGeneration(
81
- curCtx: WorkflowHostContext,
81
+ hostCtx: WorkflowHostContext,
82
82
  e: LoopEntry,
83
83
  cursor: LoopCursor,
84
84
  run: RunContext,
@@ -111,14 +111,14 @@ export async function runFanoutGeneration(
111
111
  }
112
112
  const detach = () => run.signal?.removeEventListener("abort", onRunAbort);
113
113
 
114
- await dispatchGeneration(curCtx, e, cursor, run, deps, order, genAbort, idToIndex);
114
+ await dispatchGeneration(hostCtx, e, cursor, run, deps, order, genAbort, idToIndex);
115
115
  detach(); // generation settled — drop the run-lifetime listener BEFORE the tail
116
116
 
117
117
  // The same two gates the wave loop ran between levels, now once at the end: a
118
118
  // fail-fast halt already terminated state inside the worker and aborted its
119
119
  // siblings; a run abort drained the semaphore and rejected every later acquire.
120
120
  if (run.state.termination.status !== "running") return;
121
- if (run.signal?.aborted) return deps.recordAborted(curCtx, e.name, run); // mid-flight abort → FAIL_WORKFLOW_ABORTED
121
+ if (run.signal?.aborted) return deps.recordAborted(hostCtx, e.name, run); // mid-flight abort → FAIL_WORKFLOW_ABORTED
122
122
  return finalTail();
123
123
  }
124
124
 
@@ -129,7 +129,7 @@ export async function runFanoutGeneration(
129
129
  * `recordWorkerThrow`; allSettled guarantees every unit settled.
130
130
  */
131
131
  async function dispatchGeneration(
132
- curCtx: WorkflowHostContext,
132
+ hostCtx: WorkflowHostContext,
133
133
  e: LoopEntry,
134
134
  cursor: LoopCursor,
135
135
  run: RunContext,
@@ -143,14 +143,14 @@ async function dispatchGeneration(
143
143
  // `concurrency: 1`); floored at 1, never raised above the host cap.
144
144
  const loopCap = e.loop.kind === "fanout" ? e.loop.concurrency : undefined;
145
145
  const sem = new Semaphore(
146
- Math.max(1, Math.min(loopCap ?? curCtx.maxConcurrency, curCtx.maxConcurrency)),
146
+ Math.max(1, Math.min(loopCap ?? hostCtx.maxConcurrency, hostCtx.maxConcurrency)),
147
147
  genAbort.signal,
148
148
  ); // drains queued units on either abort
149
149
 
150
150
  // One readiness latch per DISPATCHED unit, index-addressed. A dep with no latch is
151
151
  // already settled: either it is outside `ops` (a resume whose prior invocation filled
152
152
  // the slot) or it is dangling (`computeWaveLevels` treats those as satisfied too —
153
- // `validateUnitDeps` owns the dangling report).
153
+ // `ensureUnitDeps` owns the dangling report).
154
154
  const latch = new Array<Promise<void> | undefined>(e.units!.length);
155
155
  const open = new Array<(() => void) | undefined>(e.units!.length);
156
156
  for (const i of ops)
@@ -173,9 +173,9 @@ async function dispatchGeneration(
173
173
  // Resolve `--upstream`-style dep-artifact injection from the slots this
174
174
  // unit's deps just filled. Empty when the loop sets no flag or no deps.
175
175
  const suffix = depArtifactSuffix(e, cursor, i, idToIndex);
176
- const out = await sem.run(() => dispatchUnitDetached(curCtx, e, i, run, deps, genAbort.signal, suffix));
176
+ const out = await sem.run(() => dispatchUnitDetached(hostCtx, e, i, run, deps, genAbort.signal, suffix));
177
177
  // ONE synchronous block, and its order is load-bearing. (1) A fail-fast
178
- // unit's worker terminated state via recordTerminalFailure — fire genAbort
178
+ // unit's worker terminated state via recordFatalFailure — fire genAbort
179
179
  // so in-flight siblings get session.abort()'d NOW and no dependent released
180
180
  // below can still slip into the semaphore. (2) Fold BEFORE the latch opens:
181
181
  // a dependent's `depArtifactSuffix` reads `cursor.slots`, so an early
@@ -187,7 +187,7 @@ async function dispatchGeneration(
187
187
  foldFanoutCompletion(run.state, cursor, e.def, e.name, i, e.units!.length, out);
188
188
  } catch (reason) {
189
189
  // aborted / never-started → unfilled slot (resume re-dispatches)
190
- if (!isAbortError(reason)) await deps.recordWorkerThrow(curCtx, fanoutUnitRef(e, i), e.skill, run, reason);
190
+ if (!isAbortError(reason)) await deps.recordWorkerThrow(hostCtx, fanoutUnitRef(e, i), e.skill, run, reason);
191
191
  } finally {
192
192
  // Dependents proceed even when this unit failed — `depArtifactSuffix` skips
193
193
  // a failed/unfilled slot, so they design blind for it rather than stalling.
@@ -202,7 +202,7 @@ async function dispatchGeneration(
202
202
  * dep whose slot is filled with a NON-FAILED output. A failed/sentinel or still-unfilled
203
203
  * dep slot is SKIPPED (the dependent designs blind for that dep) — so a failed upstream
204
204
  * degrades gracefully instead of injecting a broken path; synthesize stays the backstop.
205
- * Dangling ids never reach here (`validateUnitDeps` rejected them at the live entry); the
205
+ * Dangling ids never reach here (`ensureUnitDeps` rejected them at the live entry); the
206
206
  * `undefined` guard is defensive.
207
207
  */
208
208
  function depArtifactSuffix(e: LoopEntry, cursor: LoopCursor, index: number, idToIndex: Map<string, number>): string {
@@ -228,7 +228,7 @@ function depArtifactSuffix(e: LoopEntry, cursor: LoopCursor, index: number, idTo
228
228
  * from the pre-wave dispatcher: collect-all unit failure → sentinel; fail-fast halt →
229
229
  * placement sentinel + graceful return; ABORT → throws WorkflowAbortError → unfilled slot.) */
230
230
  async function dispatchUnitDetached(
231
- curCtx: WorkflowHostContext,
231
+ hostCtx: WorkflowHostContext,
232
232
  e: LoopEntry,
233
233
  index: number,
234
234
  run: RunContext,
@@ -239,16 +239,16 @@ async function dispatchUnitDetached(
239
239
  if (signal?.aborted) throw new WorkflowAbortError(); // never open a child after abort; isAbortError → unfilled slot
240
240
  const u = fanoutUnitAt(e, index, promptSuffix);
241
241
  await run.lifecycle.fire(
242
- curCtx,
242
+ hostCtx,
243
243
  "onUnitStart",
244
244
  skillStageRef(e.name, e.stageIdx + 1, u.skill),
245
245
  { role: u.role, index, unitId: u.id, label: u.label, skill: u.skill },
246
246
  lifecycleCtxFor(run),
247
247
  );
248
- const snapshot = await deps.captureSnapshot(curCtx, e.name, u.def, e.stageIdx, run);
248
+ const snapshot = await deps.captureSnapshot(hostCtx, e.name, u.def, e.stageIdx, run);
249
249
  let captured: Output | undefined;
250
- await deps.runStageSession(
251
- curCtx,
250
+ await deps.executeStageSession(
251
+ hostCtx,
252
252
  buildUnitSession(e, u, index, run, snapshot, signal, (_child, output) => {
253
253
  captured = output;
254
254
  return Promise.resolve();
package/loop-waves.ts CHANGED
@@ -44,8 +44,8 @@ export function unitIdIndex(units: readonly Unit[]): Map<string, number> {
44
44
  * (unlevellable) node ⇒ a dependency cycle ⇒ `invariantPreflight`.
45
45
  *
46
46
  * Dangling deps (an id matching no unit) are SKIPPED here (treated as satisfied) so
47
- * a single missing id can't masquerade as a cycle; `validateUnitDeps` is the one that
48
- * reports dangling refs. At the live entry `validateUnitDeps` runs first, so a cycle
47
+ * a single missing id can't masquerade as a cycle; `ensureUnitDeps` is the one that
48
+ * reports dangling refs. At the live entry `ensureUnitDeps` runs first, so a cycle
49
49
  * reaching here is post-validation/defensive; the throw still lands a clean halt.
50
50
  */
51
51
  export function computeWaveLevels(units: readonly Unit[], stage: string): number[][] {
@@ -86,7 +86,7 @@ export function computeWaveLevels(units: readonly Unit[], stage: string): number
86
86
  * `invariantPreflight` halt attributed to `stage`. Cheap; runs before dispatch so the
87
87
  * dispatcher never has to throw. Cycle detection delegates to `computeWaveLevels`.
88
88
  */
89
- export function validateUnitDeps(units: readonly Unit[], stage: string): void {
89
+ export function ensureUnitDeps(units: readonly Unit[], stage: string): void {
90
90
  const ids = new Set(units.map(unitTagOf));
91
91
  for (const u of units) {
92
92
  for (const d of u.deps ?? []) {
package/loop.ts CHANGED
@@ -11,7 +11,7 @@
11
11
  * a degenerate assess loop; verify-aware code is presentation only
12
12
  * (role/label flavoring keyed on `e.def.verify` inside the assess strategy).
13
13
  *
14
- * Every unit runs `runStageSession` with a pre-decorated session: `stageName`
14
+ * Every unit runs `executeStageSession` with a pre-decorated session: `stageName`
15
15
  * carries the DISPLAY decoration (`decorateStage`), `unit` carries the
16
16
  * machine identity that lands in the row's `parent`/`role`/`unitId`/`unitIndex`
17
17
  * fields and the `onUnitStart`/`onUnitEnd` payloads.
@@ -19,7 +19,7 @@
19
19
  * Continuation-style: each unit's `onSuccess` advances the cursor and
20
20
  * re-enters `step`. Everything is awaited up the stack, so a throw from a
21
21
  * user fn (`units`/`next`/`feedForward`/`done`/judge prompt) propagates to
22
- * `runStageOrRecordFailure`'s single catch — a thrown `StagePreflightError`
22
+ * `dispatchStageOrRecordFailure`'s single catch — a thrown `StagePreflightError`
23
23
  * (the `haltPreflight` consumer contract) keeps its own attribution.
24
24
  *
25
25
  * Capture semantics (the post-refactor bug class — pinned):
@@ -67,14 +67,14 @@ import type { RunContext, WorkflowHostContext } from "./types.js";
67
67
  * aligned by sharing this one helper.
68
68
  */
69
69
  export async function announceLoopStart(
70
- curCtx: WorkflowHostContext,
70
+ hostCtx: WorkflowHostContext,
71
71
  run: RunContext,
72
72
  e: Pick<LoopEntry, "stageIdx" | "name" | "skill" | "def" | "loop" | "units">,
73
73
  ): Promise<void> {
74
74
  const ref = skillStageRef(e.name, e.stageIdx + 1, e.skill);
75
- await run.lifecycle.fire(curCtx, "onStageStart", ref, lifecycleCtxFor(run));
75
+ await run.lifecycle.fire(hostCtx, "onStageStart", ref, lifecycleCtxFor(run));
76
76
  await run.lifecycle.fire(
77
- curCtx,
77
+ hostCtx,
78
78
  "onLoopStart",
79
79
  ref,
80
80
  { kind: presentedKindOf(e.def, e.loop), ...(e.units ? { units: e.units } : {}) },
@@ -90,7 +90,7 @@ const isPristine = (cursor: LoopCursor): boolean =>
90
90
 
91
91
  /** Run (or resume) one loop generation. The caller fired onStageStart/onLoopStart. */
92
92
  export async function runLoop(
93
- curCtx: WorkflowHostContext,
93
+ hostCtx: WorkflowHostContext,
94
94
  e: LoopEntry,
95
95
  cursor: LoopCursor,
96
96
  run: RunContext,
@@ -103,9 +103,9 @@ export async function runLoop(
103
103
  // fold. iterate/assess keep the sequential step()/advanceCursor.
104
104
  // (Live entry is always pristine; resume routes to runFanoutResume directly.)
105
105
  if (e.loop.kind === "fanout" && loopStrategyOf(e.loop.kind).parallelizable && isPristine(cursor)) {
106
- return runFanoutParallel(curCtx, e, cursor, cap, run, deps);
106
+ return runFanoutParallel(hostCtx, e, cursor, cap, run, deps);
107
107
  }
108
- await step(curCtx, e, cursor, cap, run, deps);
108
+ await step(hostCtx, e, cursor, cap, run, deps);
109
109
  }
110
110
 
111
111
  /**
@@ -116,7 +116,7 @@ export async function runLoop(
116
116
  * parallelizable).
117
117
  */
118
118
  function runFanoutParallel(
119
- curCtx: WorkflowHostContext,
119
+ hostCtx: WorkflowHostContext,
120
120
  e: LoopEntry,
121
121
  cursor: LoopCursor,
122
122
  cap: number,
@@ -124,8 +124,10 @@ function runFanoutParallel(
124
124
  deps: LoopDeps,
125
125
  ): Promise<void> {
126
126
  const active = Array.from({ length: Math.min(e.units!.length, cap) }, (_u, i) => i);
127
- return runFanoutGeneration(curCtx, e, cursor, run, deps, active, () =>
128
- e.units!.length > cap ? hitCap(curCtx, e, cursor, cap, cap, run, deps) : finishLoop(curCtx, e, cursor, run, deps),
127
+ return runFanoutGeneration(hostCtx, e, cursor, run, deps, active, () =>
128
+ e.units!.length > cap
129
+ ? hitCap(hostCtx, e, cursor, cap, cap, run, deps)
130
+ : finishLoop(hostCtx, e, cursor, run, deps),
129
131
  );
130
132
  }
131
133
 
@@ -151,14 +153,14 @@ export function pendingFanoutIndices(cursor: LoopCursor, total: number): number[
151
153
  * `locateSessionFile` serve the SINGLE-STAGE session-backed reattach path
152
154
  * (run-stage.ts), not this fanout re-dispatch. */
153
155
  export function runFanoutResume(
154
- curCtx: WorkflowHostContext,
156
+ hostCtx: WorkflowHostContext,
155
157
  e: LoopEntry,
156
158
  cursor: LoopCursor,
157
159
  run: RunContext,
158
160
  deps: LoopDeps,
159
161
  pending: readonly number[],
160
162
  ): Promise<void> {
161
- return runFanoutGeneration(curCtx, e, cursor, run, deps, pending, () => finishLoop(curCtx, e, cursor, run, deps));
163
+ return runFanoutGeneration(hostCtx, e, cursor, run, deps, pending, () => finishLoop(hostCtx, e, cursor, run, deps));
162
164
  }
163
165
 
164
166
  // ---------------------------------------------------------------------------
@@ -166,7 +168,7 @@ export function runFanoutResume(
166
168
  // ---------------------------------------------------------------------------
167
169
 
168
170
  async function step(
169
- curCtx: WorkflowHostContext,
171
+ hostCtx: WorkflowHostContext,
170
172
  e: LoopEntry,
171
173
  cursor: LoopCursor,
172
174
  cap: number,
@@ -174,14 +176,14 @@ async function step(
174
176
  deps: LoopDeps,
175
177
  ): Promise<void> {
176
178
  const next = await sequentialStrategyOf(e.loop.kind).pull(e, cursor, cap, run);
177
- if (next.kind === "complete") return finishLoop(curCtx, e, cursor, run, deps);
178
- if (next.kind === "cap") return hitCap(curCtx, e, cursor, next.count, cap, run, deps);
179
- return dispatchUnit(curCtx, e, cursor, next, cap, run, deps);
179
+ if (next.kind === "complete") return finishLoop(hostCtx, e, cursor, run, deps);
180
+ if (next.kind === "cap") return hitCap(hostCtx, e, cursor, next.count, cap, run, deps);
181
+ return dispatchUnit(hostCtx, e, cursor, next, cap, run, deps);
180
182
  }
181
183
 
182
184
  /** Dispatch one unit session; the onSuccess continuation advances the cursor and re-enters step. */
183
185
  async function dispatchUnit(
184
- curCtx: WorkflowHostContext,
186
+ hostCtx: WorkflowHostContext,
185
187
  e: LoopEntry,
186
188
  cursor: LoopCursor,
187
189
  u: Extract<NextStep, { kind: "unit" }>,
@@ -190,17 +192,17 @@ async function dispatchUnit(
190
192
  deps: LoopDeps,
191
193
  ): Promise<void> {
192
194
  await run.lifecycle.fire(
193
- curCtx,
195
+ hostCtx,
194
196
  "onUnitStart",
195
197
  skillStageRef(e.name, e.stageIdx + 1, u.skill),
196
198
  { role: u.role, index: cursor.index, unitId: u.id, label: u.label, skill: u.skill },
197
199
  lifecycleCtxFor(run),
198
200
  );
199
201
 
200
- const snapshot = await deps.captureSnapshot(curCtx, e.name, u.def, e.stageIdx, run);
202
+ const snapshot = await deps.captureSnapshot(hostCtx, e.name, u.def, e.stageIdx, run);
201
203
 
202
- await deps.runStageSession(
203
- curCtx,
204
+ await deps.executeStageSession(
205
+ hostCtx,
204
206
  buildUnitSession(e, u, cursor.index, run, snapshot, run.signal, (freshCtx, output) => {
205
207
  cursor.ranThisInvocation++;
206
208
  // Fanout owns its channel + cursor through the index-addressed
@@ -294,7 +296,7 @@ export function projectResult(
294
296
  * progress channel); a resumed finished loop stays silent too.
295
297
  */
296
298
  async function finishLoop(
297
- curCtx: WorkflowHostContext,
299
+ hostCtx: WorkflowHostContext,
298
300
  e: LoopEntry,
299
301
  cursor: LoopCursor,
300
302
  run: RunContext,
@@ -302,14 +304,14 @@ async function finishLoop(
302
304
  ): Promise<void> {
303
305
  projectResult(e.loop, e.entryPair, cursor, run.state);
304
306
  if (cursor.ranThisInvocation === 0 && cursor.accumulated.length === 0 && e.loop.kind === "iterate") {
305
- curCtx.ui.notify(MSG_LOOP_ZERO_UNITS(e.skill), "warning");
307
+ hostCtx.ui.notify(MSG_LOOP_ZERO_UNITS(e.skill), "warning");
306
308
  }
307
- await deps.advanceAfter(curCtx, e.name, e.stageIdx, run);
309
+ await deps.advanceAfter(hostCtx, e.name, e.stageIdx, run);
308
310
  }
309
311
 
310
312
  /** Cap trip: "halt" → terminal failure; "advance" → durable telemetry + event + projected advance. */
311
313
  async function hitCap(
312
- curCtx: WorkflowHostContext,
314
+ hostCtx: WorkflowHostContext,
313
315
  e: LoopEntry,
314
316
  cursor: LoopCursor,
315
317
  count: number,
@@ -317,15 +319,15 @@ async function hitCap(
317
319
  run: RunContext,
318
320
  deps: LoopDeps,
319
321
  ): Promise<void> {
320
- if (e.loop.onCap === "halt") return deps.haltLoop(curCtx, run, e, count, cap);
322
+ if (e.loop.onCap === "halt") return deps.haltLoop(hostCtx, run, e, count, cap);
321
323
  appendLoopCap(run.cwd, run.runId, { type: "loop-cap", stage: e.name, count, max: cap, ts: nowIso() });
322
- curCtx.ui.notify(MSG_LOOP_CAP_ADVANCE(e.skill, cap), "warning");
324
+ hostCtx.ui.notify(MSG_LOOP_CAP_ADVANCE(e.skill, cap), "warning");
323
325
  await run.lifecycle.fire(
324
- curCtx,
326
+ hostCtx,
325
327
  "onLoopCap",
326
328
  skillStageRef(e.name, e.stageIdx + 1, e.skill),
327
329
  { kind: e.loop.kind, count, max: cap, policy: "advance" as const },
328
330
  lifecycleCtxFor(run),
329
331
  );
330
- return finishLoop(curCtx, e, cursor, run, deps);
332
+ return finishLoop(hostCtx, e, cursor, run, deps);
331
333
  }
package/messages.ts CHANGED
@@ -72,10 +72,10 @@ export const ERR_VALIDATE_RETRY_UNCHANGED = (skill: string) =>
72
72
  * Validation-retry mechanism-2 — a schema-validated `produces` stage was re-dispatched against
73
73
  * a worktree unchanged since its last validation failure at the same progress
74
74
  * point (`stagesCompleted` unchanged). A `FailureText` consumed by `failedArgs`
75
- * (the sessionless `recordTerminalFailure` descriptor, mirroring
76
- * `checkBackwardJumpGuard` in `packages/rpiv-workflow/runner/chain-advance.ts`).
75
+ * (the sessionless `recordFatalFailure` descriptor, mirroring
76
+ * `ensureBackwardJumpGuard` in `packages/rpiv-workflow/runner/chain-advance.ts`).
77
77
  * The terminal skip carries the failure memo for free through the shared
78
- * `recordTerminalFailure` writer hooks at `packages/rpiv-workflow/audit.ts:134`.
78
+ * `recordFatalFailure` writer hooks at `packages/rpiv-workflow/audit.ts:134`.
79
79
  */
80
80
  export const FAIL_VALIDATE_GATE_SKIPPED = (skill: string): FailureText => ({
81
81
  toast: `✗ ${skill} re-dispatched with no observable change since its last validation failure — stopping workflow`,
@@ -121,6 +121,19 @@ export const FAIL_BACKWARD_JUMP_EXHAUSTED = (stage: string, revisits: number, ma
121
121
  error: `Backward-jump limit exceeded: stage "${stage}" re-entered ${revisits} times (max ${max})`,
122
122
  });
123
123
 
124
+ /**
125
+ * A decision edge terminated the chain because no branch matched — `match`
126
+ * without a fallback saw an unexpected value (typically a failed verdict on a
127
+ * gate whose only routes are pass arms). The run is blocked awaiting
128
+ * intervention, not complete; `note` is the edge's own no-match diagnostic
129
+ * (the ROUTE_NOTE `match` attaches), so the toast names the value that failed
130
+ * to route. The stage's own output (its verdict) holds the findings.
131
+ */
132
+ export const FAIL_GATE_STOP = (stage: string, note: string): FailureText => ({
133
+ toast: `✗ workflow stopped at "${stage}" — its routing gate matched no branch (${note}); see the stage's verdict for findings, then fix and re-run`,
134
+ error: `Routing gate after "${stage}" matched no branch: ${note}`,
135
+ });
136
+
124
137
  /**
125
138
  * A loop produced zero units (push: empty array handled upstream as
126
139
  * single-stage fall-through, so this fires only for a pull loop whose FIRST
@@ -180,8 +193,8 @@ export const MSG_CHAIN_ADVANCE_FAILED = (fromStage: string, reason: string) =>
180
193
 
181
194
  /**
182
195
  * Stage threw before it could record its own audit row — covers
183
- * `enforceSessionInvariants` violations, session-machinery errors, and any
184
- * other path that escapes `runStage` directly. Distinguished from
196
+ * `ensureLoopNotContinue` violations, session-machinery errors, and any
197
+ * other path that escapes `dispatchStage` directly. Distinguished from
185
198
  * `MSG_CHAIN_ADVANCE_FAILED` (which is about an edge throwing AFTER a stage
186
199
  * succeeded) — the user needs to see *which* stage failed, not which one
187
200
  * preceded the failure. Wording is deliberately neutral ("failed", not
@@ -389,7 +402,7 @@ export const MSG_NO_WORKFLOWS_REGISTERED =
389
402
  * Build via `failedArgs` / `abortedArgs` (or `stopFailureArgs`' switch, in
390
403
  * audit.ts) so a halt site can't mismatch status and notify level.
391
404
  */
392
- export interface TerminalFailureArgs {
405
+ export interface FatalFailureArgs {
393
406
  status: "failed" | "aborted";
394
407
  notifyMsg: string;
395
408
  notifyLevel: "warning" | "error";
@@ -402,27 +415,27 @@ export interface TerminalFailureArgs {
402
415
  * overload-resolution body for `failedArgs`/`abortedArgs` lives here once.
403
416
  * Modeled after `stopFailureArgs` (parameterize by status).
404
417
  */
405
- function terminalArgsOf(status: "failed" | "aborted", a: FailureText | string, b?: string): TerminalFailureArgs {
418
+ function fatalArgsOf(status: "failed" | "aborted", a: FailureText | string, b?: string): FatalFailureArgs {
406
419
  const f = typeof a === "string" ? { toast: a, error: b as string } : a;
407
420
  return { status, notifyMsg: f.toast, notifyLevel: status === "failed" ? "error" : "warning", errMsg: f.error };
408
421
  }
409
422
 
410
423
  /**
411
- * Argument constructors for `recordTerminalFailure` — the
424
+ * Argument constructors for `recordFatalFailure` — the
412
425
  * `{status, notifyMsg, notifyLevel, errMsg}` quadruple every halt site used
413
426
  * to spell by hand. One per terminal status: failures notify at `"error"`,
414
427
  * aborts at `"warning"` (cooperative cancellation is expected, not
415
- * exceptional). 1-line facades over `terminalArgsOf` so the status/level
428
+ * exceptional). 1-line facades over `fatalArgsOf` so the status/level
416
429
  * pairing lives once.
417
430
  */
418
- export function failedArgs(failure: FailureText): TerminalFailureArgs;
419
- export function failedArgs(notifyMsg: string, errMsg: string): TerminalFailureArgs;
420
- export function failedArgs(a: FailureText | string, b?: string): TerminalFailureArgs {
421
- return terminalArgsOf("failed", a, b);
431
+ export function failedArgs(failure: FailureText): FatalFailureArgs;
432
+ export function failedArgs(notifyMsg: string, errMsg: string): FatalFailureArgs;
433
+ export function failedArgs(a: FailureText | string, b?: string): FatalFailureArgs {
434
+ return fatalArgsOf("failed", a, b);
422
435
  }
423
436
 
424
- export function abortedArgs(failure: FailureText): TerminalFailureArgs;
425
- export function abortedArgs(notifyMsg: string, errMsg: string): TerminalFailureArgs;
426
- export function abortedArgs(a: FailureText | string, b?: string): TerminalFailureArgs {
427
- return terminalArgsOf("aborted", a, b);
437
+ export function abortedArgs(failure: FailureText): FatalFailureArgs;
438
+ export function abortedArgs(notifyMsg: string, errMsg: string): FatalFailureArgs;
439
+ export function abortedArgs(a: FailureText | string, b?: string): FatalFailureArgs {
440
+ return fatalArgsOf("aborted", a, b);
428
441
  }
@@ -23,7 +23,7 @@
23
23
  */
24
24
 
25
25
  import { type Artifact, fs as fsHandle } from "../../handle.js";
26
- import type { ArtifactCollector, CollectCtx, CollectResult, SnapshotCtx } from "../../output-spec.js";
26
+ import type { ArtifactCollector, CollectContext, CollectResult, SnapshotContext } from "../../output-spec.js";
27
27
  import { defineCollector } from "../../output-spec.js";
28
28
  import { execFileAsync, GIT_EXEC_TIMEOUT_MS } from "../exec.js";
29
29
 
@@ -53,14 +53,14 @@ export const workspaceDiffCollector = (
53
53
  // Snapshot + diff implementation
54
54
  // ---------------------------------------------------------------------------
55
55
 
56
- async function capturePorcelainSnapshot(ctx: SnapshotCtx): Promise<WorkspaceDiffSnapshot | undefined> {
56
+ async function capturePorcelainSnapshot(ctx: SnapshotContext): Promise<WorkspaceDiffSnapshot | undefined> {
57
57
  const status = await runGitStatus(ctx.cwd);
58
58
  if (status === undefined) return undefined;
59
59
  return { statusByPath: parsePorcelain(status) };
60
60
  }
61
61
 
62
62
  async function collectDiffArtifacts(
63
- ctx: CollectCtx<WorkspaceDiffSnapshot | undefined>,
63
+ ctx: CollectContext<WorkspaceDiffSnapshot | undefined>,
64
64
  filter: ((path: string) => boolean) | undefined,
65
65
  ): Promise<CollectResult> {
66
66
  const snapshot = ctx.snapshot;
@@ -27,7 +27,14 @@
27
27
 
28
28
  import { type Artifact, opaque } from "../handle.js";
29
29
  import type { Output } from "../output.js";
30
- import type { ArtifactCollector, ArtifactParser, CollectCtx, Outcome, ParseCtx, SnapshotCtx } from "../output-spec.js";
30
+ import type {
31
+ ArtifactCollector,
32
+ ArtifactParser,
33
+ CollectContext,
34
+ Outcome,
35
+ ParseContext,
36
+ SnapshotContext,
37
+ } from "../output-spec.js";
31
38
  import { execFileAsync, GIT_EXEC_TIMEOUT_MS } from "./exec.js";
32
39
 
33
40
  /**
@@ -104,7 +111,7 @@ async function git(cwd: string, ...args: string[]): Promise<string> {
104
111
  * `gitCommitCollector` handles `undefined` snapshot gracefully by
105
112
  * emitting an artifact carrying a `noOp: true` payload.
106
113
  */
107
- export async function gitHeadSnapshot(ctx: SnapshotCtx): Promise<GitHeadSnapshot | undefined> {
114
+ export async function gitHeadSnapshot(ctx: SnapshotContext): Promise<GitHeadSnapshot | undefined> {
108
115
  try {
109
116
  const sha = await git(ctx.cwd, "rev-parse", "HEAD");
110
117
  return sha ? { baselineSha: sha } : undefined;
@@ -126,7 +133,7 @@ export async function gitHeadSnapshot(ctx: SnapshotCtx): Promise<GitHeadSnapshot
126
133
  */
127
134
  export const gitCommitCollector: ArtifactCollector<GitHeadSnapshot | undefined> = {
128
135
  snapshot: gitHeadSnapshot,
129
- async collect(ctx: CollectCtx<GitHeadSnapshot | undefined>) {
136
+ async collect(ctx: CollectContext<GitHeadSnapshot | undefined>) {
130
137
  const baselineSha = ctx.snapshot?.baselineSha;
131
138
  if (!baselineSha) {
132
139
  // Deliberate degrade: the stage ran outside a (working) git repo.
@@ -236,7 +243,7 @@ function isGitCommitRecord(r: unknown): r is GitCommitRecord {
236
243
  * commit data) and projects it into `GitCommitData`. No I/O.
237
244
  */
238
245
  export const gitCommitParser: ArtifactParser<GitHeadSnapshot | undefined, "git-commit", GitCommitData> = {
239
- parse(ctx: ParseCtx<GitHeadSnapshot | undefined>) {
246
+ parse(ctx: ParseContext<GitHeadSnapshot | undefined>) {
240
247
  const artifact = ctx.artifacts[0];
241
248
  const meta = artifact?.meta;
242
249
  if (!isGitCommitMeta(meta)) {
package/output-spec.ts CHANGED
@@ -27,7 +27,7 @@ import type { BranchEntry } from "./transcript.js";
27
27
  // Snapshot — pre-stage reference capture (shared by collector + parser)
28
28
  // ---------------------------------------------------------------------------
29
29
 
30
- export interface SnapshotCtx {
30
+ export interface SnapshotContext {
31
31
  cwd: string;
32
32
  runId: string;
33
33
  stageIndex: number;
@@ -45,7 +45,7 @@ export interface SnapshotCtx {
45
45
  * prefix without re-materialising a slice. `snapshot` is whatever the
46
46
  * collector's optional `snapshot` hook returned.
47
47
  */
48
- export interface CollectCtx<Snapshot = unknown> extends SnapshotCtx {
48
+ export interface CollectContext<Snapshot = unknown> extends SnapshotContext {
49
49
  branch: BranchEntry[];
50
50
  branchOffset?: number;
51
51
  snapshot: Snapshot;
@@ -97,8 +97,8 @@ export type CollectResult = { kind: "ok"; artifacts: readonly Artifact[] } | { k
97
97
  * widening at every call site.
98
98
  */
99
99
  export interface ArtifactCollector<Snapshot = unknown> {
100
- snapshot?(ctx: SnapshotCtx): Promise<Snapshot> | Snapshot;
101
- collect(ctx: CollectCtx<Snapshot>): Promise<CollectResult> | CollectResult;
100
+ snapshot?(ctx: SnapshotContext): Promise<Snapshot> | Snapshot;
101
+ collect(ctx: CollectContext<Snapshot>): Promise<CollectResult> | CollectResult;
102
102
  }
103
103
 
104
104
  // ---------------------------------------------------------------------------
@@ -106,12 +106,12 @@ export interface ArtifactCollector<Snapshot = unknown> {
106
106
  // ---------------------------------------------------------------------------
107
107
 
108
108
  /**
109
- * Context handed to a parser's `parse`. Extends `CollectCtx` with the
109
+ * Context handed to a parser's `parse`. Extends `CollectContext` with the
110
110
  * `artifacts` the matching collector just returned, so parsers can
111
111
  * narrow on `artifacts[0].handle.kind` and inspect any `meta` the
112
112
  * collector attached. `snapshot` flows through unchanged.
113
113
  */
114
- export interface ParseCtx<Snapshot = unknown> extends CollectCtx<Snapshot> {
114
+ export interface ParseContext<Snapshot = unknown> extends CollectContext<Snapshot> {
115
115
  artifacts: readonly Artifact[];
116
116
  }
117
117
 
@@ -133,7 +133,7 @@ export type ParseResult<Kind extends string = string, Data = unknown> =
133
133
  * Method shorthand for the same bivariance reason as `ArtifactCollector`.
134
134
  */
135
135
  export interface ArtifactParser<Snapshot = unknown, Kind extends string = string, Data = unknown> {
136
- parse(ctx: ParseCtx<Snapshot>): Promise<ParseResult<Kind, Data>> | ParseResult<Kind, Data>;
136
+ parse(ctx: ParseContext<Snapshot>): Promise<ParseResult<Kind, Data>> | ParseResult<Kind, Data>;
137
137
  }
138
138
 
139
139
  // ---------------------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-workflow",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Pi extension. Chain skills into typed multi-stage workflows with audited JSONL state, predicate routing, and per-stage output validation. Skill-agnostic — bring your own skills.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -111,7 +111,7 @@
111
111
  ]
112
112
  },
113
113
  "dependencies": {
114
- "@juicesharp/rpiv-config": "^2.2.0",
114
+ "@juicesharp/rpiv-config": "^2.3.0",
115
115
  "jiti": "^2.7.0",
116
116
  "typebox": "^1.1.24"
117
117
  },
package/preview.ts CHANGED
@@ -24,8 +24,15 @@ export const CMD_USAGE_RUN = (name: string) => `Usage: /wf ${name} <description>
24
24
  // Public formatters
25
25
  // ===========================================================================
26
26
 
27
+ /**
28
+ * Description-truncation cap (characters) for the workflow-list view. Test-pinned
29
+ * at `preview.test.ts` ("truncates long descriptions at 50 characters with
30
+ * ellipsis"); the body reserves 3 chars for the trailing "...".
31
+ */
32
+ const DESC_TRUNCATE_LEN = 50;
33
+
27
34
  /** Truncate a description to `maxLen` characters, appending "..." if truncated. */
28
- function truncateDescription(desc: string, maxLen = 50): string {
35
+ function truncateDescription(desc: string, maxLen = DESC_TRUNCATE_LEN): string {
29
36
  if (desc.length <= maxLen) return desc;
30
37
  return `${desc.slice(0, maxLen - 3)}...`;
31
38
  }
package/registration.ts CHANGED
@@ -170,15 +170,15 @@ export type { Output, OutputMeta, RunView, Verdict } from "./output.js";
170
170
  export {
171
171
  type ArtifactCollector,
172
172
  type ArtifactParser,
173
- type CollectCtx,
173
+ type CollectContext,
174
174
  type CollectResult,
175
175
  defineCollector,
176
176
  defineParser,
177
177
  type Outcome,
178
178
  type OutputSpec,
179
- type ParseCtx,
179
+ type ParseContext,
180
180
  type ParseResult,
181
- type SnapshotCtx,
181
+ type SnapshotContext,
182
182
  } from "./output-spec.js";
183
183
  export { eq, gt, gte, lt, lte, type NumericPredicate, type Predicate } from "./predicates.js";
184
184
  export type {
package/routing.ts CHANGED
@@ -15,7 +15,7 @@
15
15
  * `terminal` export. The `kind: "stop"` literal is untouched.
16
16
  *
17
17
  * Errors are returned, not thrown. The caller (runner) switches on
18
- * `kind` and routes `"err"` through `recordTerminalFailure` — same as
18
+ * `kind` and routes `"err"` through `recordFatalFailure` — same as
19
19
  * any other halt site.
20
20
  */
21
21