@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.
- package/audit-ctx.ts +7 -7
- package/audit.ts +29 -29
- package/chain-state.ts +14 -3
- package/death-scene.ts +9 -9
- package/docs/workflow-authoring.md +2 -2
- package/events.ts +1 -1
- package/failure-memos.ts +4 -4
- package/handle.ts +16 -1
- package/host.ts +1 -1
- package/loop-def.ts +1 -1
- package/loop-kinds.ts +12 -12
- package/loop-parallel.ts +15 -15
- package/loop-waves.ts +3 -3
- package/loop.ts +32 -30
- package/messages.ts +30 -17
- package/outcomes/collectors/workspace-diff.ts +3 -3
- package/outcomes/git-commit.ts +11 -4
- package/output-spec.ts +7 -7
- package/package.json +2 -2
- package/preview.ts +8 -1
- package/registration.ts +3 -3
- package/routing.ts +1 -1
- package/runner/chain-advance.ts +49 -25
- package/runner/errors.ts +1 -1
- package/runner/failure.ts +22 -23
- package/runner/preflight.ts +3 -6
- package/runner/resolve-stage.ts +3 -3
- package/runner/resume-entry.ts +5 -5
- package/runner/resume-loop.ts +5 -5
- package/runner/resume.ts +1 -1
- package/runner/run-stage.ts +69 -64
- package/runner/runner.ts +4 -4
- package/runner/script-stage.ts +17 -17
- package/sessions/bash-strikes.ts +9 -9
- package/sessions/extraction.ts +19 -12
- package/sessions/halt-routing.ts +14 -14
- package/sessions/index.ts +1 -1
- package/sessions/reattach.ts +10 -10
- package/sessions/sessions.ts +29 -23
- package/sessions/spawn.ts +5 -5
- package/sessions/success-persist.ts +3 -3
- package/stage-def.ts +2 -2
- package/stage-errors.ts +1 -1
- package/state/index.ts +1 -1
- package/state/names.ts +1 -1
- package/state/reads.ts +1 -1
- package/state/state.ts +4 -4
- package/state/writes.ts +2 -2
- package/types.ts +16 -16
package/audit-ctx.ts
CHANGED
|
@@ -19,10 +19,10 @@ import type { RunContext, SessionContext, UnitRef } from "./types.js";
|
|
|
19
19
|
/**
|
|
20
20
|
* Minimal bookkeeping ctx. Structurally derived from `SessionContext` so any
|
|
21
21
|
* future field added to the base lands here too — no duplicate
|
|
22
|
-
* maintenance. Every `
|
|
22
|
+
* maintenance. Every `StageSessionContext` (single stage or loop unit) collapses to this.
|
|
23
23
|
*
|
|
24
24
|
* `isScript` toggles the `onStageError` ref construction in
|
|
25
|
-
* `
|
|
25
|
+
* `recordFatalFailure` from `skillStageRef` to `scriptStageRef` (the
|
|
26
26
|
* script branch carries no `skill` field). Defaulting to `undefined`
|
|
27
27
|
* preserves the skill-path behaviour for every existing caller.
|
|
28
28
|
*
|
|
@@ -35,7 +35,7 @@ import type { RunContext, SessionContext, UnitRef } from "./types.js";
|
|
|
35
35
|
* lands verbatim on the JSONL row (`WorkflowStage.session`), which is what
|
|
36
36
|
* session-backed resume dispatches on.
|
|
37
37
|
*/
|
|
38
|
-
export type
|
|
38
|
+
export type AuditContext = Pick<
|
|
39
39
|
SessionContext,
|
|
40
40
|
| "cwd"
|
|
41
41
|
| "runId"
|
|
@@ -54,7 +54,7 @@ export type AuditCtx = Pick<
|
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* The read-only run identity (`workflow` name + `totalStages` + `trigger`)
|
|
57
|
-
* threaded onto every `SessionContext` and `
|
|
57
|
+
* threaded onto every `SessionContext` and `AuditContext`. Single source for the
|
|
58
58
|
* `runIdentity` sub-literal that session/audit constructions across the runner
|
|
59
59
|
* would otherwise re-spell by hand.
|
|
60
60
|
*/
|
|
@@ -63,7 +63,7 @@ export function runIdentityOf(run: RunContext): SessionContext["runIdentity"] {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
-
* Build the `
|
|
66
|
+
* Build the `AuditContext` `recordFatalFailure` needs for a stage failure that
|
|
67
67
|
* escaped a session (preflight halts, downstream throws, routing errors,
|
|
68
68
|
* resume-time refusals). One source for the shape so every halt path records
|
|
69
69
|
* a uniform row. `isScript: true` drops the `skill` field from the JSONL row
|
|
@@ -72,7 +72,7 @@ export function runIdentityOf(run: RunContext): SessionContext["runIdentity"] {
|
|
|
72
72
|
* `session` is pinned to `null` here BY CONSTRUCTION: every caller of this
|
|
73
73
|
* builder records a failure that escaped (or never reached) a session —
|
|
74
74
|
* preflight halts, seam aborts, entry throws, routing errors, resume drift,
|
|
75
|
-
* script halts. In-session writers build their `
|
|
75
|
+
* script halts. In-session writers build their `AuditContext` via `auditFor`
|
|
76
76
|
* (sessions/sessions.ts), which threads the captured `SessionRef`.
|
|
77
77
|
*/
|
|
78
78
|
export function auditCtxFor(
|
|
@@ -80,7 +80,7 @@ export function auditCtxFor(
|
|
|
80
80
|
stageName: string,
|
|
81
81
|
skill: string,
|
|
82
82
|
opts?: { isScript?: boolean; unit?: UnitRef; allocatedStageNumber?: number },
|
|
83
|
-
):
|
|
83
|
+
): AuditContext {
|
|
84
84
|
return {
|
|
85
85
|
cwd: run.cwd,
|
|
86
86
|
runId: run.runId,
|
package/audit.ts
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* the `onStageError` lifecycle fire.
|
|
7
7
|
*
|
|
8
8
|
* Depends on audit-rows + audit-ctx + state + messages + events + handle.
|
|
9
|
-
* The pure ctx half (`
|
|
9
|
+
* The pure ctx half (`AuditContext`, `runIdentityOf`, `auditCtxFor`,
|
|
10
10
|
* `currentStageRef`) now lives in `audit-ctx.ts`; the terminal-args builders
|
|
11
|
-
* (`failedArgs`/`abortedArgs`/`
|
|
11
|
+
* (`failedArgs`/`abortedArgs`/`FatalFailureArgs`) live in `messages.ts`.
|
|
12
12
|
* Both are re-exported below so existing audit-layer consumers keep one
|
|
13
13
|
* import site; new code may import `audit-ctx.ts` / `messages.ts` directly.
|
|
14
14
|
* Shared by the runner + sessions; neither imports back. Pure row
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* `audit-rows.ts`.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import type {
|
|
19
|
+
import type { AuditContext } from "./audit-ctx.js";
|
|
20
20
|
import { recordStage, unitRowFields } from "./audit-rows.js";
|
|
21
21
|
import { writeDeathSceneArtifact } from "./death-scene.js";
|
|
22
22
|
import { lifecycleCtxFromSession, scriptStageRef, skillStageRef } from "./events.js";
|
|
@@ -30,12 +30,12 @@ import {
|
|
|
30
30
|
FAIL_STAGE_NO_RESPONSE,
|
|
31
31
|
FAIL_STAGE_TOOL_STALLED,
|
|
32
32
|
FAIL_STAGE_TRUNCATED,
|
|
33
|
+
type FatalFailureArgs,
|
|
33
34
|
failedArgs,
|
|
34
35
|
MSG_FAILURE_ROW_DROPPED,
|
|
35
36
|
MSG_PARTIAL_ARTIFACTS,
|
|
36
37
|
MSG_STAGE_FAILED,
|
|
37
38
|
MSG_WORKFLOW_CANCELLED,
|
|
38
|
-
type TerminalFailureArgs,
|
|
39
39
|
} from "./messages.js";
|
|
40
40
|
import { listArtifacts } from "./state/index.js";
|
|
41
41
|
import type { StopSignal } from "./transcript.js";
|
|
@@ -43,20 +43,20 @@ import type { RunState, RunTermination, WorkflowHostContext } from "./types.js";
|
|
|
43
43
|
|
|
44
44
|
// Preserving barrel — the pre-split import surface is unchanged. Consumers
|
|
45
45
|
// (`sessions/`, `runner/`, `loop-kinds`, `loop-parallel`, `internal.ts`,
|
|
46
|
-
// `audit.test.ts`) keep importing `
|
|
47
|
-
// `currentStageRef`/`failedArgs`/`abortedArgs`/`
|
|
46
|
+
// `audit.test.ts`) keep importing `AuditContext`/`runIdentityOf`/`auditCtxFor`/
|
|
47
|
+
// `currentStageRef`/`failedArgs`/`abortedArgs`/`FatalFailureArgs` from
|
|
48
48
|
// "./audit.js" with no edit. Symbols now live in their post-split homes:
|
|
49
|
-
export type {
|
|
49
|
+
export type { AuditContext } from "./audit-ctx.js";
|
|
50
50
|
export { auditCtxFor, currentStageRef, runIdentityOf } from "./audit-ctx.js";
|
|
51
51
|
// Re-export the persistence half so existing audit-layer consumers keep one
|
|
52
52
|
// import site; new code may import audit-rows.js directly.
|
|
53
53
|
export { allocateStageNumber, decorateStage, recordStage, unitRowFields } from "./audit-rows.js";
|
|
54
|
-
export type {
|
|
54
|
+
export type { FatalFailureArgs } from "./messages.js";
|
|
55
55
|
export { abortedArgs, failedArgs } from "./messages.js";
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* `state.termination` mutator. Every terminal path — completion
|
|
59
|
-
* (`finalizeWorkflow`), failure/abort (`
|
|
59
|
+
* (`finalizeWorkflow`), failure/abort (`recordFatalFailure`), cancellation
|
|
60
60
|
* (`recordCancellation`), audit-write halts — lands its outcome through here,
|
|
61
61
|
* so the union can never be half-set and a new outcome variant has one
|
|
62
62
|
* write-site to thread through. Last write wins (a failure recorded after an
|
|
@@ -92,7 +92,7 @@ export function notifyPartialArtifacts(ctx: WorkflowHostContext, cwd: string, ru
|
|
|
92
92
|
/**
|
|
93
93
|
* Terminal/halt/cancellation row-write authority. `recordStage` + the
|
|
94
94
|
* dropped-row guard (notify + telemetry) — the side effects the three writers
|
|
95
|
-
* (`
|
|
95
|
+
* (`recordFatalFailure` / `recordUnitHalt` / `recordCancellation`) share.
|
|
96
96
|
* Each caller builds its row fields (terminal `args.status`; halt
|
|
97
97
|
* `collected:true`; cancellation `status:"skipped"`) and delegates the write +
|
|
98
98
|
* guard here, so the dropped-failure-row invariant — a dropped row corrupts
|
|
@@ -106,9 +106,9 @@ export function notifyPartialArtifacts(ctx: WorkflowHostContext, cwd: string, ru
|
|
|
106
106
|
* the graph-sink `edge.mode: "terminal"` (loop-constructors.ts). See the
|
|
107
107
|
* glossary on `stage-def.ts`'s `terminal` export.
|
|
108
108
|
*/
|
|
109
|
-
function
|
|
109
|
+
function recordFailureRow(
|
|
110
110
|
ctx: WorkflowHostContext,
|
|
111
|
-
audit:
|
|
111
|
+
audit: AuditContext,
|
|
112
112
|
row: Parameters<typeof recordStage>[2],
|
|
113
113
|
): number | undefined {
|
|
114
114
|
const written = recordStage(audit.cwd, audit.runId, row, audit.state, audit.allocatedStageNumber);
|
|
@@ -123,8 +123,8 @@ function writeFailureRow(
|
|
|
123
123
|
* Record the two failure-forensics sidecars for a failed stage/unit — the
|
|
124
124
|
* in-memory failure memo (`appendFailureMemo`) and the death-scene `.md`
|
|
125
125
|
* artifact (`writeDeathSceneArtifact`) — immediately after the failure-row
|
|
126
|
-
* write. Peer helper to `
|
|
127
|
-
* (`
|
|
126
|
+
* write. Peer helper to `recordFailureRow`; the two terminal writers
|
|
127
|
+
* (`recordFatalFailure`, `recordUnitHalt`) both delegate here.
|
|
128
128
|
*
|
|
129
129
|
* Fail-soft: the death-scene artifact reads the just-failed session's persisted
|
|
130
130
|
* JSONL via the host-injected `audit.readSessionBranch`; skips silently when
|
|
@@ -132,15 +132,15 @@ function writeFailureRow(
|
|
|
132
132
|
* already-persisted failure row is never masked. The memo append is in-memory
|
|
133
133
|
* only and does not throw.
|
|
134
134
|
*/
|
|
135
|
-
function recordFailureForensics(ctx: WorkflowHostContext, audit:
|
|
135
|
+
function recordFailureForensics(ctx: WorkflowHostContext, audit: AuditContext, errMsg: string): void {
|
|
136
136
|
appendFailureMemo(audit.state, audit, errMsg);
|
|
137
137
|
writeDeathSceneArtifact(ctx, audit, errMsg);
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
export async function
|
|
140
|
+
export async function recordFatalFailure(
|
|
141
141
|
ctx: WorkflowHostContext,
|
|
142
|
-
audit:
|
|
143
|
-
args:
|
|
142
|
+
audit: AuditContext,
|
|
143
|
+
args: FatalFailureArgs,
|
|
144
144
|
onFailure?: (ctx: WorkflowHostContext) => void,
|
|
145
145
|
): Promise<void> {
|
|
146
146
|
// First-failure-wins: under parallel fanout dispatch with
|
|
@@ -151,7 +151,7 @@ export async function recordTerminalFailure(
|
|
|
151
151
|
// Harmless on the sequential path (always `"running"` at the
|
|
152
152
|
// first and only terminal failure).
|
|
153
153
|
if (audit.state.termination.status !== "running") return;
|
|
154
|
-
|
|
154
|
+
recordFailureRow(ctx, audit, {
|
|
155
155
|
stage: audit.stageName,
|
|
156
156
|
// Script-stage failure rows omit `skill` (the row split landed in A.0);
|
|
157
157
|
// skill rows continue to carry it. `undefined` is dropped by JSON.stringify.
|
|
@@ -177,15 +177,15 @@ export async function recordTerminalFailure(
|
|
|
177
177
|
/**
|
|
178
178
|
* Persist a NON-TERMINAL failed unit row (collect-all fanout): the unit halted,
|
|
179
179
|
* but the run survives and the synthesis stage sees a failed slot. Mirrors
|
|
180
|
-
* `
|
|
180
|
+
* `recordFatalFailure`'s `recordStage` write (same unit fields, same
|
|
181
181
|
* pre-allocated number) WITHOUT `terminate()` (the only state mutation it skips)
|
|
182
182
|
* and WITHOUT the `onStageError` fire (this is not a hard fail). The row carries
|
|
183
183
|
* `collected: true` so the resume fold can tell it apart from a hard
|
|
184
|
-
* `
|
|
184
|
+
* `recordFatalFailure` row (byte-identical otherwise) and rebuild the
|
|
185
185
|
* `failedOutput` sentinel by `unitIndex` instead of re-dispatching it.
|
|
186
186
|
*/
|
|
187
|
-
export function recordUnitHalt(ctx: WorkflowHostContext, audit:
|
|
188
|
-
|
|
187
|
+
export function recordUnitHalt(ctx: WorkflowHostContext, audit: AuditContext, errMsg: string): void {
|
|
188
|
+
recordFailureRow(ctx, audit, {
|
|
189
189
|
stage: audit.stageName,
|
|
190
190
|
skill: audit.isScript ? undefined : audit.skill,
|
|
191
191
|
status: "failed",
|
|
@@ -206,15 +206,15 @@ export function recordUnitHalt(ctx: WorkflowHostContext, audit: AuditCtx, errMsg
|
|
|
206
206
|
*/
|
|
207
207
|
export async function recordStopFailure(
|
|
208
208
|
ctx: WorkflowHostContext,
|
|
209
|
-
audit:
|
|
209
|
+
audit: AuditContext,
|
|
210
210
|
stop: Exclude<StopSignal, "stop">,
|
|
211
211
|
errorMessage: string,
|
|
212
212
|
onFailure?: (ctx: WorkflowHostContext) => void,
|
|
213
213
|
): Promise<void> {
|
|
214
|
-
await
|
|
214
|
+
await recordFatalFailure(ctx, audit, stopFailureArgs(audit.skill, stop, errorMessage), onFailure);
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
function stopFailureArgs(skill: string, stop: Exclude<StopSignal, "stop">, errorMessage: string):
|
|
217
|
+
function stopFailureArgs(skill: string, stop: Exclude<StopSignal, "stop">, errorMessage: string): FatalFailureArgs {
|
|
218
218
|
switch (stop) {
|
|
219
219
|
case "aborted":
|
|
220
220
|
return abortedArgs(FAIL_STAGE_ABORTED(skill));
|
|
@@ -231,16 +231,16 @@ function stopFailureArgs(skill: string, stop: Exclude<StopSignal, "stop">, error
|
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
export function recordCancellation(ctx: WorkflowHostContext, audit:
|
|
234
|
+
export function recordCancellation(ctx: WorkflowHostContext, audit: AuditContext): void {
|
|
235
235
|
// Cancellation is a first-class termination outcome: the canonical in-memory
|
|
236
236
|
// name is `RunTermination.status: "cancelled"` (types.ts), but the JSONL row
|
|
237
237
|
// is written with the FROZEN `StageStatus: "skipped"` (state/state.ts) — a
|
|
238
238
|
// deliberate split (the row value is a versioned on-disk contract; renaming
|
|
239
239
|
// it would break resume + every past-run reader). THIS is the sole writer of
|
|
240
240
|
// a `"skipped"` row. `errMsg` is mirrored into the row so post-mortems work
|
|
241
|
-
// from the trail alone (same posture as `
|
|
241
|
+
// from the trail alone (same posture as `recordFatalFailure`).
|
|
242
242
|
const errMsg = `${audit.skill} cancelled by user`;
|
|
243
|
-
|
|
243
|
+
recordFailureRow(ctx, audit, {
|
|
244
244
|
stage: audit.stageName,
|
|
245
245
|
skill: audit.skill,
|
|
246
246
|
status: "skipped",
|
package/chain-state.ts
CHANGED
|
@@ -59,6 +59,17 @@ const usesOriginalInput = (def: StageDef, stageName: string, startStage: string)
|
|
|
59
59
|
const hasReads = (def: StageDef): def is StageDef & { reads: NonNullable<StageDef["reads"]> } =>
|
|
60
60
|
def.reads !== undefined && def.reads.length > 0;
|
|
61
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Separator between the channel `name` and the `handle` in the stageEntryArgs
|
|
64
|
+
* dedup key (`${name}${DEDUP_KEY_SEPARATOR}${handle}`). The NUL byte cannot
|
|
65
|
+
* occur in either half — handles are inline-artifact strings or file paths,
|
|
66
|
+
* and names are channel identifiers — so two distinct (name, handle) pairs
|
|
67
|
+
* ("ab"+"cd" vs "a"+"bcd") can never concatenate into the same key; carrying
|
|
68
|
+
* `name` additionally preserves a cross-name fan-in repeat whose entries
|
|
69
|
+
* share a handle.
|
|
70
|
+
*/
|
|
71
|
+
const DEDUP_KEY_SEPARATOR = "\0";
|
|
72
|
+
|
|
62
73
|
/**
|
|
63
74
|
* The single arg-projection authority: the string a stage's
|
|
64
75
|
* `/skill:<name> <args>` prompt carries, derived purely from
|
|
@@ -86,8 +97,8 @@ export function stageEntryArgs(
|
|
|
86
97
|
// Duplicate-flag dedup: collapse two entries on the SAME channel whose
|
|
87
98
|
// handles stringify identically (the a777 cite-check symptom — a re-run
|
|
88
99
|
// fanout channel re-published the same fs path, emitting a duplicate
|
|
89
|
-
// `--code-cite-check <path>` flag). The key is `${name}
|
|
90
|
-
// the
|
|
100
|
+
// `--code-cite-check <path>` flag). The key is `${name}${DEDUP_KEY_SEPARATOR}${handle}`:
|
|
101
|
+
// the DEDUP_KEY_SEPARATOR (NUL byte) avoids a concatenation collision (name "ab" + handle
|
|
91
102
|
// "cd" vs "a" + "bcd"), and carrying the channel `name` preserves a fanin
|
|
92
103
|
// repeat whose entries carry DISTINCT paths (e.g. per-cluster subplans) and
|
|
93
104
|
// a multi-artifact entry whose artifacts differ. The set spans every read
|
|
@@ -116,7 +127,7 @@ export function stageEntryArgs(
|
|
|
116
127
|
if (!entry || isFailedOutput(entry)) continue; // unfilled (pending) or failed → no args
|
|
117
128
|
for (const artifact of entry.artifacts) {
|
|
118
129
|
const handle = handleToString(artifact.handle);
|
|
119
|
-
const key = `${name}
|
|
130
|
+
const key = `${name}${DEDUP_KEY_SEPARATOR}${handle}`;
|
|
120
131
|
if (seen.has(key)) continue;
|
|
121
132
|
seen.add(key);
|
|
122
133
|
parts.push(`--${name}`, handle);
|
package/death-scene.ts
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
* death-scene.ts — forensic Markdown artifact written on stage/unit failure.
|
|
3
3
|
*
|
|
4
4
|
* On any transition to failed (terminal failure or a collect-all unit soft-halt),
|
|
5
|
-
* the two failure-record writers (`
|
|
5
|
+
* the two failure-record writers (`recordFatalFailure` /
|
|
6
6
|
* `recordUnitHalt` in `audit.ts`) call `writeDeathSceneArtifact` immediately
|
|
7
7
|
* after they persist the JSONL failure row. The writer locates the just-failed
|
|
8
8
|
* session's persisted JSONL, re-reads its branch through the host-injected
|
|
9
|
-
* `
|
|
9
|
+
* `AuditContext.readSessionBranch` (NO live-session re-query — the child is already
|
|
10
10
|
* torn down), extracts the forensic scene, and writes a sidecar `.md` under
|
|
11
11
|
* `<cwd>/.rpiv/artifacts/failures/`.
|
|
12
12
|
*
|
|
13
13
|
* Fail-soft throughout and SYNCHRONOUS: the entire body is try/caught, and on
|
|
14
14
|
* ANY failure (locate miss, reader throw, write error) it warns via
|
|
15
15
|
* `ctx.ui.notify(..., "warning")` and
|
|
16
|
-
* continues — the original failure (already persisted by `
|
|
16
|
+
* continues — the original failure (already persisted by `recordFailureRow`)
|
|
17
17
|
* is never masked. Skips SILENTLY (no throw, no artifact, no warning) when
|
|
18
18
|
* `audit.session === null` (sessionless failures: entry throws, seam aborts
|
|
19
19
|
* via `auditCtxFor`) or `audit.readSessionBranch === undefined` (programmatic
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
27
27
|
import { dirname, join } from "node:path";
|
|
28
|
-
import type {
|
|
28
|
+
import type { AuditContext } from "./audit-ctx.js";
|
|
29
29
|
import type { WorkflowHostContext } from "./host.js";
|
|
30
30
|
import { locateSessionFile } from "./sessions/locate.js";
|
|
31
31
|
import { type BranchEntry, iterToolUses, lastAssistantText } from "./transcript.js";
|
|
@@ -76,7 +76,7 @@ function sanitizeSegment(segment: string): string {
|
|
|
76
76
|
* (`"phase 2/5"`), which would otherwise nest the artifact in a surprise
|
|
77
77
|
* subdirectory. Pure — no I/O.
|
|
78
78
|
*/
|
|
79
|
-
export function deathSceneFilePath(cwd: string, audit:
|
|
79
|
+
export function deathSceneFilePath(cwd: string, audit: AuditContext): string {
|
|
80
80
|
const stageNumber = audit.allocatedStageNumber ?? audit.state.lastAllocatedStageNumber;
|
|
81
81
|
// `unit.id` is the stable disambiguator when present (fanout/iterate). Assess-loop units
|
|
82
82
|
// carry no id (identified by `(role, round)`); append `_u<index>` so filename uniqueness
|
|
@@ -112,7 +112,7 @@ function truncateArgs(input: Record<string, unknown>): string {
|
|
|
112
112
|
* joined text parts (via `lastAssistantText`), omitted when empty.
|
|
113
113
|
*/
|
|
114
114
|
export function extractDeathScene(
|
|
115
|
-
audit:
|
|
115
|
+
audit: AuditContext,
|
|
116
116
|
errMsg: string,
|
|
117
117
|
branch: BranchEntry[],
|
|
118
118
|
sessionFile: string,
|
|
@@ -190,14 +190,14 @@ export function formatDeathScene(scene: DeathScene): string {
|
|
|
190
190
|
* WARNS + continues (`ctx.ui.notify(..., "warning")`) when
|
|
191
191
|
* `locateSessionFile` returns null, the reader returns
|
|
192
192
|
* undefined/an empty branch, or any step throws — the original failure, already
|
|
193
|
-
* persisted by `
|
|
193
|
+
* persisted by `recordFailureRow`, is never masked.
|
|
194
194
|
*
|
|
195
|
-
* Synchronous by design: the caller (`
|
|
195
|
+
* Synchronous by design: the caller (`recordFatalFailure` /
|
|
196
196
|
* `recordUnitHalt`) has already persisted the failure row; the artifact is a
|
|
197
197
|
* best-effort sidecar, not a reconstruction input, so it never blocks the run's
|
|
198
198
|
* terminal bookkeeping.
|
|
199
199
|
*/
|
|
200
|
-
export function writeDeathSceneArtifact(ctx: WorkflowHostContext, audit:
|
|
200
|
+
export function writeDeathSceneArtifact(ctx: WorkflowHostContext, audit: AuditContext, errMsg: string): void {
|
|
201
201
|
// Sessionless failures carry no persisted session — nothing to read, no artifact.
|
|
202
202
|
if (audit.session === null) return;
|
|
203
203
|
// No host-injected reader ⇒ degrade silently (programmatic embedder / no provider).
|
|
@@ -628,7 +628,7 @@ edges: {
|
|
|
628
628
|
}
|
|
629
629
|
```
|
|
630
630
|
|
|
631
|
-
**No-match is explicit, never silent.** With `opts.fallback` the unmatched value routes there; without one it terminates
|
|
631
|
+
**No-match is explicit, never silent.** With `opts.fallback` the unmatched value routes there; without one it terminates the run as **failed** — the runner records the `stop` routing decision (note included) plus a terminal failure row naming the gate's stage, so the run reads as blocked-awaiting-intervention, never as a completed ✓. Either way the no-match lands a routing-audit `note`.
|
|
632
632
|
|
|
633
633
|
**Routing on a panel's verdict** — `opts.from` reads the field from a named channel's latest output (`state.named[from].at(-1).data[field]`) instead of the stage's projected `output.data`. This is how `match` branches on a [panel](#adversarial-verification-panel)'s published fold (the fold lands on a channel, never on the stage's projected output):
|
|
634
634
|
|
|
@@ -806,7 +806,7 @@ This determines `sessionPolicy`.
|
|
|
806
806
|
| Nothing, and downstream must not inherit | `terminal()` | — | — |
|
|
807
807
|
| Session memory only | Upstream `acts`, downstream `sessionPolicy: "continue"` | — (no outcome on upstream) | — |
|
|
808
808
|
|
|
809
|
-
**When to author a custom collector.** The built-in collectors cover transcript scanning, tool-call observation, filesystem diffing, and git state. If the skill's output pattern doesn't map cleanly to any of these — for example, it writes a structured artifact with frontmatter you want to parse, or it produces an identifier embedded in a branch name — author a custom collector via `defineCollector` and an optional `defineParser`. Custom collectors are first-class; they receive the same `
|
|
809
|
+
**When to author a custom collector.** The built-in collectors cover transcript scanning, tool-call observation, filesystem diffing, and git state. If the skill's output pattern doesn't map cleanly to any of these — for example, it writes a structured artifact with frontmatter you want to parse, or it produces an identifier embedded in a branch name — author a custom collector via `defineCollector` and an optional `defineParser`. Custom collectors are first-class; they receive the same `CollectContext` and emit the same artifact shapes as built-ins.
|
|
810
810
|
|
|
811
811
|
### Validation decision rules
|
|
812
812
|
|
package/events.ts
CHANGED
|
@@ -342,7 +342,7 @@ export function lifecycleCtxFor(run: {
|
|
|
342
342
|
}
|
|
343
343
|
|
|
344
344
|
/**
|
|
345
|
-
* Build a `LifecycleContext` from any SessionContext/
|
|
345
|
+
* Build a `LifecycleContext` from any SessionContext/AuditContext-shaped object
|
|
346
346
|
* (cwd + runId + the frozen `runIdentity` + live state). The session, audit,
|
|
347
347
|
* and extraction layers all fire through this projection instead of
|
|
348
348
|
* re-spelling the six-field literal.
|
package/failure-memos.ts
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
* failure-memos.ts — bounded log of stage/unit failures, surfaced as an
|
|
3
3
|
* additive prompt suffix on every subsequently-built stage/unit session.
|
|
4
4
|
*
|
|
5
|
-
* Two writers feed it: `
|
|
5
|
+
* Two writers feed it: `recordFatalFailure` (the terminal path — first
|
|
6
6
|
* failure wins) and `recordUnitHalt` (a collect-all fanout soft-halt). The
|
|
7
7
|
* suffix is appended at the two session-construction chokepoints
|
|
8
8
|
* (`buildSingleStageSession` + `buildUnitSession`). Zero memos ⇒ the suffix
|
|
9
9
|
* is `""` ⇒ byte-identical prompt to a clean run.
|
|
10
10
|
*
|
|
11
11
|
* Leaf module: type-only imports of `RunState`/`FailureMemo` (types.js) and
|
|
12
|
-
* `
|
|
12
|
+
* `AuditContext` (audit-ctx.js), value import of `nowIso` (internal-utils.js).
|
|
13
13
|
* No back-edges — the value-import DAG stays acyclic.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import type {
|
|
16
|
+
import type { AuditContext } from "./audit-ctx.js";
|
|
17
17
|
import { nowIso } from "./internal-utils.js";
|
|
18
18
|
import type { FailureMemo, RunState } from "./types.js";
|
|
19
19
|
|
|
@@ -40,7 +40,7 @@ export const MAX_FAILURE_MEMO_ERR_LEN = 500;
|
|
|
40
40
|
* failure and to the audit `stageName` for a non-unit failure. `unitId` is set
|
|
41
41
|
* only for a loop-unit failure (the unit's stable audit id).
|
|
42
42
|
*/
|
|
43
|
-
export function appendFailureMemo(state: RunState, audit:
|
|
43
|
+
export function appendFailureMemo(state: RunState, audit: AuditContext, errMsg: string): void {
|
|
44
44
|
const memo: FailureMemo = {
|
|
45
45
|
stage: audit.unit?.parent ?? audit.stageName,
|
|
46
46
|
...(audit.unit?.id ? { unitId: audit.unit.id } : {}),
|
package/handle.ts
CHANGED
|
@@ -49,6 +49,21 @@ export const opaque = (id: string): ArtifactHandle => ({ kind: "opaque", id });
|
|
|
49
49
|
export const inline = (bytes: Uint8Array, mime?: string): ArtifactHandle =>
|
|
50
50
|
mime !== undefined ? { kind: "inline", bytes, mime } : { kind: "inline", bytes };
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Inline-handle wire format — the lossy placeholder `handleToString`
|
|
54
|
+
* emits for inline artifact bytes. Inline content is gathered directly
|
|
55
|
+
* by the collector and is not meaningfully promptable, so the serialised
|
|
56
|
+
* form reports only its byte length (plus an optional mime suffix).
|
|
57
|
+
*
|
|
58
|
+
* `inline:` — kind discriminator (mirrors the `kind` literal)
|
|
59
|
+
* <byteLength> — number of bytes the collector gathered
|
|
60
|
+
* `b` — unit marking the preceding number as a byte length
|
|
61
|
+
* `;` <mime> — delimiter + optional mime type, emitted when present
|
|
62
|
+
*/
|
|
63
|
+
const INLINE_HANDLE_PREFIX = "inline:";
|
|
64
|
+
const INLINE_HANDLE_BYTE_UNIT = "b";
|
|
65
|
+
const INLINE_HANDLE_MIME_SEPARATOR = ";";
|
|
66
|
+
|
|
52
67
|
/**
|
|
53
68
|
* Serialise a handle to a human-readable string — used by the runner
|
|
54
69
|
* when threading the primary artifact into a downstream stage's prompt
|
|
@@ -65,6 +80,6 @@ export function handleToString(h: ArtifactHandle): string {
|
|
|
65
80
|
case "opaque":
|
|
66
81
|
return h.id;
|
|
67
82
|
case "inline":
|
|
68
|
-
return
|
|
83
|
+
return `${INLINE_HANDLE_PREFIX}${h.bytes.byteLength}${INLINE_HANDLE_BYTE_UNIT}${h.mime ? `${INLINE_HANDLE_MIME_SEPARATOR}${h.mime}` : ""}`;
|
|
69
84
|
}
|
|
70
85
|
}
|
package/host.ts
CHANGED
|
@@ -157,7 +157,7 @@ export interface WorkflowHostContext {
|
|
|
157
157
|
/**
|
|
158
158
|
* The fan-out unit index for this spawn, surfaced so a lane-aware host can
|
|
159
159
|
* publish the child under a per-unit registry slot (rpiv-pi's lane dock/viewer).
|
|
160
|
-
* Set by `openChild` from `
|
|
160
|
+
* Set by `openChild` from `StageSessionContext.unit?.index`; undefined for a non-fan-out
|
|
161
161
|
* single stage (and for reattach/fork), which the host maps to its reserved
|
|
162
162
|
* single-unit slot. Purely an observability hint — a non-lane host ignores it and
|
|
163
163
|
* it NEVER affects execution.
|
package/loop-def.ts
CHANGED
|
@@ -30,7 +30,7 @@ export interface Unit {
|
|
|
30
30
|
* edges: a unit dispatches only after every unit it lists here has completed
|
|
31
31
|
* (its slot filled). Absent/empty ⇒ a root (wave 0). A reference that matches
|
|
32
32
|
* no unit's `id ?? label`, or any cycle, halts the stage at the live entry
|
|
33
|
-
* (`
|
|
33
|
+
* (`ensureUnitDeps`). Ignored by the sequential kinds (iterate/assess
|
|
34
34
|
* consume the prior unit, so ordering is implicit).
|
|
35
35
|
*/
|
|
36
36
|
deps?: readonly string[];
|
package/loop-kinds.ts
CHANGED
|
@@ -36,7 +36,7 @@ import { isPanel, type Judge, type PanelJudge, panelMembers, resolveJudgePrompt
|
|
|
36
36
|
import { MSG_LOOP_CURSOR_CORRUPT } from "./messages.js";
|
|
37
37
|
import { finalizeOutput, isFailedOutput, type Output, type OutputMeta } from "./output.js";
|
|
38
38
|
import { invariantPreflight } from "./stage-errors.js";
|
|
39
|
-
import type { RunContext, RunState,
|
|
39
|
+
import type { RunContext, RunState, StageSessionContext, UnitRef, WorkflowHostContext } from "./types.js";
|
|
40
40
|
|
|
41
41
|
// ---------------------------------------------------------------------------
|
|
42
42
|
// Cursor + entry vocabulary (kind-agnostic, shared live + fold)
|
|
@@ -96,21 +96,21 @@ export function buildLoopEntry(
|
|
|
96
96
|
*/
|
|
97
97
|
export interface LoopDeps {
|
|
98
98
|
/** Dispatch one unit through the standard stage-session path. */
|
|
99
|
-
|
|
99
|
+
executeStageSession: (ctx: WorkflowHostContext, s: StageSessionContext) => Promise<void>;
|
|
100
100
|
/**
|
|
101
101
|
* Resume the chain after the loop finishes — receives the loop node's REAL
|
|
102
102
|
* name. `Promise<unknown>` so the walk's `ChainOutcome`-returning composed
|
|
103
103
|
* advance plugs in directly (the driver only awaits settlement).
|
|
104
104
|
*/
|
|
105
105
|
advanceAfter: (
|
|
106
|
-
|
|
106
|
+
hostCtx: WorkflowHostContext,
|
|
107
107
|
completedName: string,
|
|
108
108
|
completedIdx: number,
|
|
109
109
|
run: RunContext,
|
|
110
110
|
) => Promise<unknown>;
|
|
111
111
|
/** Re-capture the outcome's pre-stage snapshot per unit (ctx + stage name for the fail-soft warning). */
|
|
112
112
|
captureSnapshot: (
|
|
113
|
-
|
|
113
|
+
hostCtx: WorkflowHostContext,
|
|
114
114
|
stageName: string,
|
|
115
115
|
def: StageDef,
|
|
116
116
|
idx: number,
|
|
@@ -118,7 +118,7 @@ export interface LoopDeps {
|
|
|
118
118
|
) => Promise<unknown>;
|
|
119
119
|
/** Record the terminal failure when `onCap: "halt"` trips — verify-worded for verify stages. */
|
|
120
120
|
haltLoop: (
|
|
121
|
-
|
|
121
|
+
hostCtx: WorkflowHostContext,
|
|
122
122
|
run: RunContext,
|
|
123
123
|
e: Pick<LoopEntry, "name" | "def">,
|
|
124
124
|
count: number,
|
|
@@ -126,14 +126,14 @@ export interface LoopDeps {
|
|
|
126
126
|
) => Promise<void>;
|
|
127
127
|
/** Record a mid-flight run abort at the loop seam (FAIL_WORKFLOW_ABORTED).
|
|
128
128
|
* Keeps the drivers free of engine imports; wired to `recordAbortedAtSeam`. */
|
|
129
|
-
recordAborted: (
|
|
129
|
+
recordAborted: (hostCtx: WorkflowHostContext, name: string, run: RunContext) => Promise<void>;
|
|
130
130
|
/** Funnel an UNEXPECTED worker rejection (not a workflow halt) to a
|
|
131
131
|
* terminal-failure row + onStageError, terminating state WITHOUT re-throwing,
|
|
132
132
|
* so entry() resolves and onWorkflowEnd still fires. Wraps recordEntryThrow.
|
|
133
133
|
* The unit's identity (`unit` + its `skill`) lands as STRUCTURED row fields —
|
|
134
134
|
* the row's `stage` stays the parent graph identity. */
|
|
135
135
|
recordWorkerThrow: (
|
|
136
|
-
|
|
136
|
+
hostCtx: WorkflowHostContext,
|
|
137
137
|
unit: UnitRef,
|
|
138
138
|
skill: string,
|
|
139
139
|
run: RunContext,
|
|
@@ -353,7 +353,7 @@ export type NextStep =
|
|
|
353
353
|
* key to `(index, memberIndex)` for assess panels — within one round all member
|
|
354
354
|
* rows share `index`, so the member dimension is what tells them apart.
|
|
355
355
|
*/
|
|
356
|
-
export interface
|
|
356
|
+
export interface GenerationGuardContext {
|
|
357
357
|
loop: LoopDef;
|
|
358
358
|
entryArtifact: Artifact | undefined;
|
|
359
359
|
cursor: LoopCursor;
|
|
@@ -414,7 +414,7 @@ export interface SequentialStrategy extends LoopKindStrategy {
|
|
|
414
414
|
* (role, unitIndex) arithmetic matched. Returns false on drift. May invoke
|
|
415
415
|
* user fns — a throw becomes drift in the caller (`guarded`).
|
|
416
416
|
*/
|
|
417
|
-
guardExpectation(gen:
|
|
417
|
+
guardExpectation(gen: GenerationGuardContext, row: UnitRowFacts, cwd: string, state: RunState): Promise<boolean>;
|
|
418
418
|
/**
|
|
419
419
|
* Resume re-entry pending-work probe — never dispatches; gates the
|
|
420
420
|
* announce only. The iterate arm re-pulls `next()` at the cursor (the
|
|
@@ -475,7 +475,7 @@ const shouldCollectAll = (loop: LoopDef): boolean => loop.kind === "fanout" && !
|
|
|
475
475
|
* fan-out index (the same value `unit.index` carries). */
|
|
476
476
|
const laneIndexFor = (loop: LoopDef, index: number): number | undefined => (loop.kind === "fanout" ? index : undefined);
|
|
477
477
|
|
|
478
|
-
/** Factored unit
|
|
478
|
+
/** Factored unit StageSessionContext — shared by the sequential `dispatchUnit` (loop.ts)
|
|
479
479
|
* and the parallel `dispatchUnitDetached` (loop-parallel.ts); differs only in
|
|
480
480
|
* `onSuccess` and the threaded `signal`. Populates the per-child execution
|
|
481
481
|
* controls (lane/model/signal). The sequential path passes `run.signal`
|
|
@@ -488,8 +488,8 @@ export function buildUnitSession(
|
|
|
488
488
|
run: RunContext,
|
|
489
489
|
snapshot: unknown,
|
|
490
490
|
signal: AbortSignal | undefined,
|
|
491
|
-
onSuccess:
|
|
492
|
-
):
|
|
491
|
+
onSuccess: StageSessionContext["onSuccess"],
|
|
492
|
+
): StageSessionContext {
|
|
493
493
|
return {
|
|
494
494
|
cwd: run.cwd,
|
|
495
495
|
runId: run.runId,
|