@juicesharp/rpiv-workflow 2.2.0 → 2.3.1

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 (50) 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 +134 -91
  12. package/loop-parallel.ts +15 -15
  13. package/loop-waves.ts +3 -3
  14. package/loop.ts +54 -35
  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 +66 -26
  24. package/runner/errors.ts +1 -1
  25. package/runner/failure.ts +22 -23
  26. package/runner/preflight.ts +20 -20
  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 +198 -133
  31. package/runner/run-stage.ts +111 -88
  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 +135 -77
  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 +93 -53
  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
  50. package/validate/stage-rules.ts +42 -17
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):
@@ -36,11 +36,11 @@
36
36
  * no-op (pinned behavior).
37
37
  */
38
38
 
39
- import type { LoopDef } from "./api.js";
39
+ import type { AssessLoop, LoopDef } from "./api.js";
40
40
  import { applyCompletedStage } from "./chain-state.js";
41
41
  import { lifecycleCtxFor, skillStageRef } from "./events.js";
42
42
  import { nowIso } from "./internal-utils.js";
43
- import { isPanel } from "./judge.js";
43
+ import { type AnyJudge, isPanel, type PanelJudge } from "./judge.js";
44
44
  import { panelVerdictChannel, panelVerdictDef } from "./loop-constructors.js";
45
45
  import {
46
46
  advanceCursor,
@@ -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 } : {}) },
@@ -88,9 +88,26 @@ export async function announceLoopStart(
88
88
  const isPristine = (cursor: LoopCursor): boolean =>
89
89
  cursor.index === 0 && cursor.accumulated.length === 0 && cursor.slots === undefined;
90
90
 
91
+ /** Narrows `loop` to AssessLoop — the one bearing a `judge` field; the first
92
+ * publishPanelVerdict guard routes through this so `loop.judge` type-checks
93
+ * without a cast. */
94
+ const isAssessLoop = (loop: LoopDef): loop is AssessLoop => loop.kind === "assess";
95
+
96
+ /** The panel-closing transition — fires exactly once per round: the LAST member's
97
+ * judge advance clears `cursor.panel` and flips to `produce` with the folded
98
+ * verdict already on `lastVerdict`. The positive conjunction of the De Morgan
99
+ * dual of the original guard. */
100
+ const isPanelClosingTransition = (judge: AnyJudge, cursor: LoopCursor): judge is PanelJudge =>
101
+ isPanel(judge) && cursor.panel === undefined && cursor.phase === "produce";
102
+
103
+ /** A live empty pull (iterate) loop — no units ran this invocation and none
104
+ * accumulated — the one shape that earns the zero-unit warning. */
105
+ const isZeroUnitPullLoop = (cursor: LoopCursor, loop: LoopDef): boolean =>
106
+ cursor.ranThisInvocation === 0 && cursor.accumulated.length === 0 && loop.kind === "iterate";
107
+
91
108
  /** Run (or resume) one loop generation. The caller fired onStageStart/onLoopStart. */
92
109
  export async function runLoop(
93
- curCtx: WorkflowHostContext,
110
+ hostCtx: WorkflowHostContext,
94
111
  e: LoopEntry,
95
112
  cursor: LoopCursor,
96
113
  run: RunContext,
@@ -103,9 +120,9 @@ export async function runLoop(
103
120
  // fold. iterate/assess keep the sequential step()/advanceCursor.
104
121
  // (Live entry is always pristine; resume routes to runFanoutResume directly.)
105
122
  if (e.loop.kind === "fanout" && loopStrategyOf(e.loop.kind).parallelizable && isPristine(cursor)) {
106
- return runFanoutParallel(curCtx, e, cursor, cap, run, deps);
123
+ return runFanoutParallel(hostCtx, e, cursor, cap, run, deps);
107
124
  }
108
- await step(curCtx, e, cursor, cap, run, deps);
125
+ await step(hostCtx, e, cursor, cap, run, deps);
109
126
  }
110
127
 
111
128
  /**
@@ -116,7 +133,7 @@ export async function runLoop(
116
133
  * parallelizable).
117
134
  */
118
135
  function runFanoutParallel(
119
- curCtx: WorkflowHostContext,
136
+ hostCtx: WorkflowHostContext,
120
137
  e: LoopEntry,
121
138
  cursor: LoopCursor,
122
139
  cap: number,
@@ -124,8 +141,10 @@ function runFanoutParallel(
124
141
  deps: LoopDeps,
125
142
  ): Promise<void> {
126
143
  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),
144
+ return runFanoutGeneration(hostCtx, e, cursor, run, deps, active, () =>
145
+ e.units!.length > cap
146
+ ? hitCap(hostCtx, e, cursor, cap, cap, run, deps)
147
+ : finishLoop(hostCtx, e, cursor, run, deps),
129
148
  );
130
149
  }
131
150
 
@@ -151,14 +170,14 @@ export function pendingFanoutIndices(cursor: LoopCursor, total: number): number[
151
170
  * `locateSessionFile` serve the SINGLE-STAGE session-backed reattach path
152
171
  * (run-stage.ts), not this fanout re-dispatch. */
153
172
  export function runFanoutResume(
154
- curCtx: WorkflowHostContext,
173
+ hostCtx: WorkflowHostContext,
155
174
  e: LoopEntry,
156
175
  cursor: LoopCursor,
157
176
  run: RunContext,
158
177
  deps: LoopDeps,
159
178
  pending: readonly number[],
160
179
  ): Promise<void> {
161
- return runFanoutGeneration(curCtx, e, cursor, run, deps, pending, () => finishLoop(curCtx, e, cursor, run, deps));
180
+ return runFanoutGeneration(hostCtx, e, cursor, run, deps, pending, () => finishLoop(hostCtx, e, cursor, run, deps));
162
181
  }
163
182
 
164
183
  // ---------------------------------------------------------------------------
@@ -166,7 +185,7 @@ export function runFanoutResume(
166
185
  // ---------------------------------------------------------------------------
167
186
 
168
187
  async function step(
169
- curCtx: WorkflowHostContext,
188
+ hostCtx: WorkflowHostContext,
170
189
  e: LoopEntry,
171
190
  cursor: LoopCursor,
172
191
  cap: number,
@@ -174,14 +193,14 @@ async function step(
174
193
  deps: LoopDeps,
175
194
  ): Promise<void> {
176
195
  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);
196
+ if (next.kind === "complete") return finishLoop(hostCtx, e, cursor, run, deps);
197
+ if (next.kind === "cap") return hitCap(hostCtx, e, cursor, next.count, cap, run, deps);
198
+ return dispatchUnit(hostCtx, e, cursor, next, cap, run, deps);
180
199
  }
181
200
 
182
201
  /** Dispatch one unit session; the onSuccess continuation advances the cursor and re-enters step. */
183
202
  async function dispatchUnit(
184
- curCtx: WorkflowHostContext,
203
+ hostCtx: WorkflowHostContext,
185
204
  e: LoopEntry,
186
205
  cursor: LoopCursor,
187
206
  u: Extract<NextStep, { kind: "unit" }>,
@@ -190,17 +209,17 @@ async function dispatchUnit(
190
209
  deps: LoopDeps,
191
210
  ): Promise<void> {
192
211
  await run.lifecycle.fire(
193
- curCtx,
212
+ hostCtx,
194
213
  "onUnitStart",
195
214
  skillStageRef(e.name, e.stageIdx + 1, u.skill),
196
215
  { role: u.role, index: cursor.index, unitId: u.id, label: u.label, skill: u.skill },
197
216
  lifecycleCtxFor(run),
198
217
  );
199
218
 
200
- const snapshot = await deps.captureSnapshot(curCtx, e.name, u.def, e.stageIdx, run);
219
+ const snapshot = await deps.captureSnapshot(hostCtx, e.name, u.def, e.stageIdx, run);
201
220
 
202
- await deps.runStageSession(
203
- curCtx,
221
+ await deps.executeStageSession(
222
+ hostCtx,
204
223
  buildUnitSession(e, u, cursor.index, run, snapshot, run.signal, (freshCtx, output) => {
205
224
  cursor.ranThisInvocation++;
206
225
  // Fanout owns its channel + cursor through the index-addressed
@@ -246,9 +265,9 @@ export function publishPanelVerdict(
246
265
  cursor: LoopCursor,
247
266
  state: RunContext["state"],
248
267
  ): void {
249
- if (loop.kind !== "assess") return; // narrows `loop` to AssessLoop — no cast needed below
268
+ if (!isAssessLoop(loop)) return;
250
269
  const judge = loop.judge;
251
- if (!isPanel(judge) || cursor.panel !== undefined || cursor.phase !== "produce") return;
270
+ if (!isPanelClosingTransition(judge, cursor)) return;
252
271
  if (cursor.lastVerdict === undefined) return; // defensive — the fold always set it
253
272
  applyCompletedStage(
254
273
  state,
@@ -294,22 +313,22 @@ export function projectResult(
294
313
  * progress channel); a resumed finished loop stays silent too.
295
314
  */
296
315
  async function finishLoop(
297
- curCtx: WorkflowHostContext,
316
+ hostCtx: WorkflowHostContext,
298
317
  e: LoopEntry,
299
318
  cursor: LoopCursor,
300
319
  run: RunContext,
301
320
  deps: LoopDeps,
302
321
  ): Promise<void> {
303
322
  projectResult(e.loop, e.entryPair, cursor, run.state);
304
- if (cursor.ranThisInvocation === 0 && cursor.accumulated.length === 0 && e.loop.kind === "iterate") {
305
- curCtx.ui.notify(MSG_LOOP_ZERO_UNITS(e.skill), "warning");
323
+ if (isZeroUnitPullLoop(cursor, e.loop)) {
324
+ hostCtx.ui.notify(MSG_LOOP_ZERO_UNITS(e.skill), "warning");
306
325
  }
307
- await deps.advanceAfter(curCtx, e.name, e.stageIdx, run);
326
+ await deps.advanceAfter(hostCtx, e.name, e.stageIdx, run);
308
327
  }
309
328
 
310
329
  /** Cap trip: "halt" → terminal failure; "advance" → durable telemetry + event + projected advance. */
311
330
  async function hitCap(
312
- curCtx: WorkflowHostContext,
331
+ hostCtx: WorkflowHostContext,
313
332
  e: LoopEntry,
314
333
  cursor: LoopCursor,
315
334
  count: number,
@@ -317,15 +336,15 @@ async function hitCap(
317
336
  run: RunContext,
318
337
  deps: LoopDeps,
319
338
  ): Promise<void> {
320
- if (e.loop.onCap === "halt") return deps.haltLoop(curCtx, run, e, count, cap);
339
+ if (e.loop.onCap === "halt") return deps.haltLoop(hostCtx, run, e, count, cap);
321
340
  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");
341
+ hostCtx.ui.notify(MSG_LOOP_CAP_ADVANCE(e.skill, cap), "warning");
323
342
  await run.lifecycle.fire(
324
- curCtx,
343
+ hostCtx,
325
344
  "onLoopCap",
326
345
  skillStageRef(e.name, e.stageIdx + 1, e.skill),
327
346
  { kind: e.loop.kind, count, max: cap, policy: "advance" as const },
328
347
  lifecycleCtxFor(run),
329
348
  );
330
- return finishLoop(curCtx, e, cursor, run, deps);
349
+ return finishLoop(hostCtx, e, cursor, run, deps);
331
350
  }
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.1",
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.1",
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