@juicesharp/rpiv-workflow 2.0.0 → 2.2.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.
@@ -5,22 +5,62 @@ A workflow chains Pi skills into a typed multi-stage graph with audited JSONL st
5
5
  ## Table of Contents
6
6
 
7
7
  - [Running workflows](#running-workflows)
8
+ - [When `/wf` refuses](#when-wf-refuses)
8
9
  - [File structure](#file-structure)
10
+ - [Where files resolve](#where-files-resolve)
9
11
  - [Layer merging](#layer-merging)
10
12
  - [Config files](#config-files)
11
13
  - [Pack files](#pack-files)
12
14
  - [Skill aliases](#skill-aliases)
15
+ - [Run state](#run-state)
16
+ - [Run caps](#run-caps)
17
+ - [Trusting overlay files](#trusting-overlay-files)
18
+ - [Legacy layouts](#legacy-layouts)
13
19
  - [Example](#example)
20
+ - [Glossary](#glossary)
14
21
 
15
22
  ## Running workflows
16
23
 
17
24
  ```bash
18
- /wf # Preview every loaded workflow
19
- /wf <name> # Preview one workflow's stage graph
20
- /wf <name> <input> # Run a workflow with <input> piped to the start stage
25
+ /wf # Preview every loaded workflow
26
+ /wf <name> # Preview one workflow's stage graph
27
+ /wf <name> <input> # Run a workflow with <input> piped to the start stage
28
+ /wf <input> # Run the default workflow with <input>
29
+ /wf <name> <input> --name <slug> # Run under a human-readable alias
30
+ /wf @<ref> # Resume a past run
21
31
  ```
22
32
 
23
- Running `/wf` without arguments shows a list of every loaded workflow and its stages. Running `/wf <name>` without input shows that workflow's stage graph in detail. The `<input>` string becomes the start stage's prompt.
33
+ Running `/wf` without arguments shows a list of every loaded workflow and its stages. Running `/wf <name>` without input shows that workflow's stage graph in detail. The `<input>` string becomes the start stage's prompt. When the first token is not a recognised workflow name, the whole argument is treated as input for the resolved default workflow.
34
+
35
+ `/wf` floats the run off the prompt and returns immediately — stages execute detached in their own child sessions.
36
+
37
+ ### `--name <slug>`
38
+
39
+ Assigns a human-readable alias to the run, stored in the JSONL header and the sidecar `names.json` index. It is honored **only** in the leading or trailing token position (leading wins if both are present) — a `--name` in the middle of your input stays as prompt text (`/wf fix the --name handling bug`) and `/wf` warns that the flag was ignored.
40
+
41
+ Slugs must match `/^[a-zA-Z_][a-zA-Z0-9_-]{0,63}$/`. A slug already in use is rejected, and the error names the run that holds it.
42
+
43
+ ### `@<ref>` — resume
44
+
45
+ ```bash
46
+ /wf @2026-07-21_14-03-22-9f2a
47
+ /wf @nightly-docs
48
+ /wf @.rpiv/workflows/runs/2026-07-21_14-03-22-9f2a.jsonl
49
+ ```
50
+
51
+ The `@` sigil on the first token resumes a past run. `<ref>` is a run-id, a run name assigned with `--name`, or a path to a `.jsonl` trail. A leading space after `@` is tolerated; trailing tokens are ignored. `--name` has no meaning on a resume — it is dropped with a warning.
52
+
53
+ Resume folds the JSONL trail back into run state and re-enters at the pending step. Completed fan-out units replay from their journaled output instead of re-running.
54
+
55
+ ## When `/wf` refuses
56
+
57
+ | Condition | What you see |
58
+ | --- | --- |
59
+ | Non-interactive session | `/wf requires interactive mode` |
60
+ | No workflows registered | A message telling you to install a sibling that bundles workflows or author one in `.rpiv/workflows/config.ts`. This is the standalone-install default state — the package ships zero workflows |
61
+ | Any load issue with `severity: "error"` | `/wf: N config errors — see warnings above (fix and re-run)`; execution is blocked until the config loads clean |
62
+ | A run recorded under an older state schema | Resume is refused with a version mismatch. `STATE_SCHEMA_VERSION` is `2`; there is no in-place migration |
63
+ | First `/wf` before the runtime pre-warms | One toast: `rpiv: loading workflow runtime (first /wf after load)…`. The runtime pre-warms 2000 ms after extension load |
24
64
 
25
65
  ## File structure
26
66
 
@@ -30,7 +70,10 @@ Running `/wf` without arguments shows a list of every loaded workflow and its st
30
70
  ├── packs/ # Pack files (installable bundles)
31
71
  │ ├── my-pipeline.ts
32
72
  │ └── ship.ts
33
- └── runs/ # Audited JSONL run state (<run-id>.jsonl)
73
+ └── runs/ # Audited JSONL run state
74
+ ├── <run-id>.jsonl
75
+ ├── names.json # --name → run-id index
76
+ └── <run-id>/sessions/ # Child session files for the run's stages
34
77
 
35
78
  ~/.config/rpiv-workflow/
36
79
  ├── config.ts # User-level config
@@ -43,6 +86,18 @@ Every workflow file is TypeScript, loaded via `jiti` (no build step required). I
43
86
  import { defineWorkflow, produces, acts, gate, gt, eq } from "@juicesharp/rpiv-workflow";
44
87
  ```
45
88
 
89
+ ## Where files resolve
90
+
91
+ | Layer | Path |
92
+ | --- | --- |
93
+ | User config | `$XDG_CONFIG_HOME/rpiv-workflow/config.ts`, defaulting to `~/.config/rpiv-workflow/config.ts` |
94
+ | User packs | `$XDG_CONFIG_HOME/rpiv-workflow/packs/*.ts`, defaulting to `~/.config/rpiv-workflow/packs/*.ts` |
95
+ | Project config | `<cwd>/.rpiv/workflows/config.ts` |
96
+ | Project packs | `<cwd>/.rpiv/workflows/packs/*.ts` |
97
+ | Run state | `<cwd>/.rpiv/workflows/runs/` |
98
+
99
+ `XDG_CONFIG_HOME` governs the **user** layer only. Unset, empty after trimming, whitespace-only, or **relative** values fall back to `~/.config`. `~` and `~/…` are tilde-expanded and then required to resolve absolute; `~user/…` is not expanded and routes to the default. Absolute values are used verbatim. Pi's own paths (`~/.pi/…`, `PI_CODING_AGENT_DIR`) are deliberately *not* unified with this. `XDG_CONFIG_HOME` is the only environment variable this package reads.
100
+
46
101
  ## Layer merging
47
102
 
48
103
  The loader merges workflows from five layers. Each later layer overrides earlier by workflow name:
@@ -55,7 +110,7 @@ built-in (registered by sibling packages like rpiv-pi)
55
110
  ← project config (<cwd>/.rpiv/workflows/config.ts)
56
111
  ```
57
112
 
58
- Within a layer, the config file wins by workflow name over pack files. Only the config file may set the `default` workflow (the one `/wf <input>` runs without specifying a name). Defaults cascade: `project config > user config > first registered workflow`.
113
+ Within a layer, the config file wins by workflow name over pack files. Only the config file may set the `default` workflow (the one `/wf <input>` runs without specifying a name). Defaults cascade: `project config > user config > first registered workflow`. With nothing registered anywhere, there is no default.
59
114
 
60
115
  ## Config files
61
116
 
@@ -81,12 +136,14 @@ export default {
81
136
  };
82
137
  ```
83
138
 
139
+ The envelope needs at least one of `workflows`, `default`, or `skillAliases`.
140
+
84
141
  ## Pack files
85
142
 
86
- Pack files (`packs/*.ts`) are installable bundles others can drop in. They accept only `Workflow | Workflow[]`. Packs **cannot** set `default` — that lives in the config file.
143
+ Pack files (`packs/*.ts`) are installable bundles others can drop in. They accept only `Workflow | Workflow[]` — the envelope form is rejected, and both `default` and `skillAliases` are hard-rejected.
87
144
 
88
145
  ```typescript
89
- // workflows/my-pipeline.ts
146
+ // .rpiv/workflows/packs/my-pipeline.ts
90
147
  import { defineWorkflow, produces, acts } from "@juicesharp/rpiv-workflow";
91
148
  export default defineWorkflow({
92
149
  name: "my-pipeline",
@@ -100,7 +157,7 @@ This is what makes installable workflow packs safe: a pack contributes new workf
100
157
 
101
158
  ## Skill aliases
102
159
 
103
- `skillAliases` remaps a skill name everywhere — across built-in, user, and project workflows — with one declarative config entry. It lives in the config-file envelope (packs can't set it) and is applied at load time, so `/wf` preview, the JSONL audit, and the runtime skill-registry preflight all see the final skill:
160
+ `skillAliases` remaps a skill name everywhere — across built-in, user, and project workflows — with one declarative config entry. It lives in the config-file envelope (packs can't set it) and is applied at load time **before validation**, so `/wf` preview, the JSONL audit, and the runtime skill-registry preflight all see the final skill:
104
161
 
105
162
  ```typescript
106
163
  // .rpiv/workflows/config.ts
@@ -118,6 +175,48 @@ export default {
118
175
 
119
176
  Every dispatching stage whose effective skill (`stage.skill ?? <stage key>`) matches an alias key is remapped to the target — note the key is the **skill** name, not the stage id. The mapping is one hop only (no transitive chains), skips `run`/`prompt` stages (they don't dispatch a `/skill:`), and merges **project over user** per key. An alias-only config (no `workflows`) is valid. `/wf` shows a `Skill aliases in effect: commit → attributed-commit` banner; an alias key that matches no dispatched skill in any workflow surfaces a load-time warning (a harmless no-op). A bad alias **target** (a skill that doesn't exist) is caught by the existing runtime "skill not found" preflight.
120
177
 
178
+ ## Run state
179
+
180
+ Each `/wf` invocation appends one row per step to `<cwd>/.rpiv/workflows/runs/<run-id>.jsonl` — the append-only system of record that makes runs resumable. Run ids are `YYYY-MM-DD_HH-MM-SS-<4 hex>`, e.g. `2026-07-21_14-03-22-9f2a`.
181
+
182
+ Alongside the trail:
183
+
184
+ - `runs/names.json` — the `--name` slug → run-id index.
185
+ - `runs/<run-id>/sessions/` — the child session files backing that run's stages.
186
+
187
+ Trails carry `STATE_SCHEMA_VERSION`, currently `2`. A run recorded under a different version cannot be resumed.
188
+
189
+ The package sets no explicit file modes; writes use the process umask. If a write fails, the error tells you to check filesystem permissions for `.rpiv/workflows/runs/`.
190
+
191
+ ## Run caps
192
+
193
+ Two backstops bound every run regardless of what a workflow declares:
194
+
195
+ | Cap | Default | Effect |
196
+ | --- | --- | --- |
197
+ | `maxIterations` | `32` | Run-wide ceiling on loop units of every kind. The effective loop cap is `min(loop.max, run.maxIterations)` |
198
+ | Backward-jump budget | `2` per destination stage | At most 3 executions of any one stage across decision-edge loop-backs |
199
+
200
+ ## Trusting overlay files
201
+
202
+ `config.ts` and `packs/*.ts` are TypeScript modules, loaded through `jiti`, which **synchronously evaluates each file's top-level code** on first load and again on every edit (invalidation is mtime-driven). The threat boundary is the same as `npm install` post-install scripts or `tsx script.ts`.
203
+
204
+ If you run Pi in a freshly-cloned repository you do not control, diff `.rpiv/workflows/config.ts` and `.rpiv/workflows/packs/*.ts` before running `/wf`.
205
+
206
+ ## Legacy layouts
207
+
208
+ Three stale layouts from before the unified `.rpiv/workflows/` tree are probed at load time. Each fires a **warning** only — nothing blocks the run — and the old locations are **not** read:
209
+
210
+ | Detected | Migration |
211
+ | --- | --- |
212
+ | `<cwd>/.rpiv-workflow/` | Move `workflows.config.ts` → `.rpiv/workflows/config.ts` and `workflows/*.ts` → `.rpiv/workflows/packs/`, then `rm -rf .rpiv-workflow`. The full shell command is in the warning text |
213
+ | Top-level `*.jsonl` directly under `<cwd>/.rpiv/workflows/` | `mkdir -p .rpiv/workflows/runs && mv .rpiv/workflows/*.jsonl .rpiv/workflows/runs/` |
214
+ | `<userConfigDir>/workflows.config.ts` | `mv <userConfigDir>/workflows.config.ts <userConfigDir>/config.ts` |
215
+
216
+ `.rpiv/workflows/` is commonly gitignored because it holds run state, so a moved `config.ts` may be silently uncommittable. Add `!.rpiv/workflows/config.ts` and `!.rpiv/workflows/packs/` to your `.gitignore` to version-control team workflow config.
217
+
218
+ These advisories sunset roughly three release cycles after 1.0.
219
+
121
220
  ## Example
122
221
 
123
222
  A minimal workflow that chains two skills:
@@ -141,4 +240,20 @@ export default defineWorkflow({
141
240
 
142
241
  Save this as `.rpiv/workflows/config.ts` in your project, then run `/wf review-and-ship implement auth feature`.
143
242
 
144
- For the full DSL reference (all stage factories, routing, outcomes, validators), see [workflow-authoring.md](./workflow-authoring.md).
243
+ ## Glossary
244
+
245
+ One canonical name per concept. Where two words exist for the same thing, the split is deliberate: one is the **authoring surface** (what you type in a workflow file), the other is the **data vocabulary** (what lands in rows, envelopes, and types).
246
+
247
+ | Term | Meaning |
248
+ |------|---------|
249
+ | **Workflow** | The typed graph: a name, a `start` stage, a `stages` record, an `edges` table. Built with `defineWorkflow`, loaded from config layers or registered programmatically. |
250
+ | **Stage** | One node of the graph — a unit of dispatch (skill session, prompt, or script). Two kinds: `"produces"` and `"side-effect"`. |
251
+ | **Kind vs. factory** | `kind` is the persisted data discriminator (`"produces"` \| `"side-effect"`); the factories are authoring verbs: `produces()` → `"produces"`, `acts()` → `"side-effect"`, `terminal()` → `"side-effect"` + `inheritsArtifacts: false`. `acts` is a verb because it reads naturally in a stage record (`commit: acts()`); `"side-effect"` is descriptive because it reads naturally in rows and output envelopes. `terminal` is **not** a third kind — it's `acts` plus an artifact-isolation flag. |
252
+ | **Run** | One execution of a workflow: a `runId`, an append-only JSONL run file (the system of record for resume), and the in-memory state the runner threads. |
253
+ | **Chain** | The path a run walks through the graph — stage activations following `edges` from `start` until `"stop"` or a halt. Loops add generations *within* one chain position. |
254
+ | **Output** | The envelope one stage activation hands downstream: `{ kind, data, meta, artifacts }` (`Output<K, D>`, `output.ts`). What predicates, routes, downstream prompts, and the audit log see. |
255
+ | **Outcome** | The producer-side declaration of *how* a stage's Output gets built from a session: `{ collector, parser? }` (`Outcome`, `output-spec.ts`). The collector enumerates artifacts; the parser interprets them into `data`. |
256
+ | **Verdict** | A judge's Output (`type Verdict = Output`). In `assess` / `verify` loops the judge emits a verdict that `done` reads; verdicts are recorded for resume but never become the stage result. |
257
+ | **Contract** | A skill contract — what a skill `consumes` / `produces`. Declared by the skill's owner or harvested from stage declarations; adjudicated at load time (`canCompose`, the validator) to check composition. |
258
+
259
+ For the full DSL reference (all stage factories, loops, routing, outcomes, validators), see [workflow-authoring.md](./workflow-authoring.md). To drive the runtime from code, see [embedding.md](./embedding.md).
package/events.ts CHANGED
@@ -47,21 +47,6 @@ export interface LifecycleContext {
47
47
  /** What triggered this run; defaulted at `runWorkflow` entry if `options.trigger` was omitted. */
48
48
  trigger: RunTrigger;
49
49
  state: RunView;
50
- /**
51
- * Distinct stage names already executed in this run — the engine's
52
- * authoritative `RunContext.visited`, RECONSTRUCTED from the JSONL trail on a
53
- * resume. Populated only on the run-level projection (`lifecycleCtxFor`, which
54
- * backs `onWorkflowStart`/`onWorkflowEnd`, script-stage `onStageStart`, and the
55
- * loop/route fires); UNDEFINED on session-fired events (`lifecycleCtxFromSession`
56
- * carries `runIdentity` only, never the live visited set).
57
- *
58
- * Exists so a status-line bridge can SEED its own distinct-visited accumulator
59
- * at `onWorkflowStart`: a resumed run kicks the chain at its reconstructed walk
60
- * position (a deep `stageNumber`), but only re-fires per-stage events from that
61
- * point forward — without this, the bridge would recount `visited` from zero and
62
- * a near-done resume would render a misleadingly tiny `visited/totalStages`.
63
- */
64
- visited?: readonly string[];
65
50
  }
66
51
 
67
52
  /**
@@ -185,13 +170,9 @@ export interface LifecycleListeners {
185
170
 
186
171
  /**
187
172
  * After an `EdgeFn` picks and its routing-decision row lands. `to` may be the
188
- * `STOP` sentinel literal `"stop"`. `bypassed` lists the decision edge's
189
- * not-taken RECOVERY arms — failure loops the chosen arm skipped for good (see
190
- * `bypassedRecoveryArms` in routing.ts). A progress listener credits them so
191
- * the bar reaches full while the terminal stage runs; empty for deterministic
192
- * (string) edges and gates with no loop-back alternative.
173
+ * `STOP` sentinel literal `"stop"`.
193
174
  */
194
- onRoute?(from: StageRef, to: string, ctx: LifecycleContext, bypassed?: readonly string[]): void | Promise<void>;
175
+ onRoute?(from: StageRef, to: string, ctx: LifecycleContext): void | Promise<void>;
195
176
 
196
177
  /** After `onStageStart`, before unit 1's session (after the unit list is computed for fanout). */
197
178
  onLoopStart?(stage: StageRef, info: LoopStartInfo, ctx: LifecycleContext): void | Promise<void>;
@@ -330,7 +311,6 @@ export function buildLifecycleContext(args: {
330
311
  totalStages: number;
331
312
  trigger: RunTrigger;
332
313
  state: RunView;
333
- visited?: readonly string[];
334
314
  }): LifecycleContext {
335
315
  return args;
336
316
  }
@@ -350,7 +330,6 @@ export function lifecycleCtxFor(run: {
350
330
  totalStages: number;
351
331
  trigger: RunTrigger;
352
332
  state: RunView;
353
- visited: ReadonlySet<string>;
354
333
  }): LifecycleContext {
355
334
  return buildLifecycleContext({
356
335
  cwd: run.cwd,
@@ -359,9 +338,6 @@ export function lifecycleCtxFor(run: {
359
338
  totalStages: run.totalStages,
360
339
  trigger: run.trigger,
361
340
  state: run.state,
362
- // Snapshot the live set — listeners must not mutate the engine's accumulator,
363
- // and a fired ctx is captured per fire so a later `visited.add` is irrelevant.
364
- visited: [...run.visited],
365
341
  });
366
342
  }
367
343
 
package/execution-host.ts CHANGED
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import type { ModelSelection, WorkflowHostContext } from "./host.js";
10
10
  import { globalSlot } from "./internal-utils.js";
11
+ import type { BranchEntry } from "./transcript.js";
11
12
 
12
13
  /** What the provider hands back per run: the detached executor, an optional
13
14
  * cancellation `signal` (rpiv-pi wires it from `ctx.ui.onTerminalInput`),
@@ -42,6 +43,14 @@ export interface WorkflowExecutionProvider {
42
43
  /** Per-stage model resolution (rpiv-pi's resolveStageModel) — threaded onto
43
44
  * RunContext.resolveModel so the dispatcher fills each child's ModelSelection. */
44
45
  resolveModel?(id: { stage: string; skill: string }): ModelSelection | undefined;
46
+ /** Re-open a persisted child-session JSONL and return its branch
47
+ * (`SessionManager.open(file).getBranch()` on the rpiv-pi side), narrowed
48
+ * to `BranchEntry[]`. Threaded onto `RunContext.readSessionBranch` so the
49
+ * death-scene artifact writer can read the just-failed session's transcript
50
+ * WITHOUT re-querying the live child (which is already torn down). Returns
51
+ * `undefined` on any open/read failure (fail-soft). Absent for programmatic
52
+ * embedders / no provider ⇒ the writer degrades silently. */
53
+ readSessionBranch?(file: string): BranchEntry[] | undefined;
45
54
  }
46
55
 
47
56
  // Use the SAME globalThis[Symbol.for(...)] slot mechanism as
@@ -0,0 +1,74 @@
1
+ /**
2
+ * failure-memos.ts — bounded log of stage/unit failures, surfaced as an
3
+ * additive prompt suffix on every subsequently-built stage/unit session.
4
+ *
5
+ * Two writers feed it: `recordTerminalFailure` (the terminal path — first
6
+ * failure wins) and `recordUnitHalt` (a collect-all fanout soft-halt). The
7
+ * suffix is appended at the two session-construction chokepoints
8
+ * (`buildSingleStageSession` + `buildUnitSession`). Zero memos ⇒ the suffix
9
+ * is `""` ⇒ byte-identical prompt to a clean run.
10
+ *
11
+ * Leaf module: type-only imports of `RunState`/`FailureMemo` (types.js) and
12
+ * `AuditCtx` (audit-ctx.js), value import of `nowIso` (internal-utils.js).
13
+ * No back-edges — the value-import DAG stays acyclic.
14
+ */
15
+
16
+ import type { AuditCtx } from "./audit-ctx.js";
17
+ import { nowIso } from "./internal-utils.js";
18
+ import type { FailureMemo, RunState } from "./types.js";
19
+
20
+ /**
21
+ * Maximum number of memos retained on `RunState.failureMemos`. The array is
22
+ * bounded so a long collect-all fanout with many failing units does not grow
23
+ * the suffix without limit; the OLDEST entry is dropped when the cap is
24
+ * exceeded. The rendered block lists at most this many, newest-first.
25
+ */
26
+ export const MAX_FAILURE_MEMOS = 3;
27
+
28
+ /**
29
+ * Maximum character length of a single memo's `errMsg`. Longer messages are
30
+ * truncated to this length with a trailing ellipsis so the prompt suffix stays
31
+ * bounded even when the failure reason is a multi-KB stack trace.
32
+ */
33
+ export const MAX_FAILURE_MEMO_ERR_LEN = 500;
34
+
35
+ /**
36
+ * Append a failure memo to `state.failureMemos`, bounded by `MAX_FAILURE_MEMOS`
37
+ * (oldest dropped) and with `errMsg` length-bounded by `MAX_FAILURE_MEMO_ERR_LEN`.
38
+ *
39
+ * `stage` resolves to the unit's PARENT (machine identity) for a loop-unit
40
+ * failure and to the audit `stageName` for a non-unit failure. `unitId` is set
41
+ * only for a loop-unit failure (the unit's stable audit id).
42
+ */
43
+ export function appendFailureMemo(state: RunState, audit: AuditCtx, errMsg: string): void {
44
+ const memo: FailureMemo = {
45
+ stage: audit.unit?.parent ?? audit.stageName,
46
+ ...(audit.unit?.id ? { unitId: audit.unit.id } : {}),
47
+ errMsg: truncateErr(errMsg),
48
+ ts: nowIso(),
49
+ };
50
+ state.failureMemos.push(memo);
51
+ if (state.failureMemos.length > MAX_FAILURE_MEMOS) {
52
+ state.failureMemos.shift(); // drop oldest — newest memos win the bounded slot
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Render the additive prompt suffix for `state.failureMemos`, newest-first.
58
+ * Returns `""` when there are no memos so the host prompt is byte-identical to
59
+ * a clean run (no separator, no fence, no newline).
60
+ */
61
+ export function failureMemoSuffix(state: RunState): string {
62
+ const memos = state.failureMemos;
63
+ if (memos.length === 0) return "";
64
+ const lines = [...memos]
65
+ .reverse()
66
+ .map((m) => `- ${m.unitId ? `${m.stage} (unit ${m.unitId})` : m.stage}: ${m.errMsg}`);
67
+ return `\n\nPrior failures in this run (do not repeat these — the run already tried them and they failed):\n${lines.join("\n")}`;
68
+ }
69
+
70
+ /** Truncate `errMsg` to `MAX_FAILURE_MEMO_ERR_LEN` with a trailing ellipsis when longer. */
71
+ function truncateErr(errMsg: string): string {
72
+ if (errMsg.length <= MAX_FAILURE_MEMO_ERR_LEN) return errMsg;
73
+ return `${errMsg.slice(0, MAX_FAILURE_MEMO_ERR_LEN)}…`;
74
+ }
package/host.ts CHANGED
@@ -192,4 +192,16 @@ export interface WorkflowSessionContext extends WorkflowHostContext {
192
192
  * watchdog omits it and every abort stays a plain abort.
193
193
  */
194
194
  toolTimeout?(): { reason: string } | undefined;
195
+
196
+ /**
197
+ * Recovery-side twin of `toolTimeout`: clears the recorded verdict so the runner can
198
+ * re-arm the watchdog for the resumed turn's next bash call. Set by a watchdog-equipped
199
+ * host (rpiv-pi) alongside `toolTimeout`. The strike-recovery branch consumes a strike
200
+ * BEFORE calling this, then re-prompts the SAME child; omitting it on a watchdog host
201
+ * would leave a stale verdict that re-halts immediately. Optional + safe to widen: only
202
+ * two implementors of this port exist (the SDK host + the test mock), and a host without
203
+ * a watchdog still routes every abort as a plain abort (the strike branch never fires
204
+ * because `toolTimeout()` returns `undefined`).
205
+ */
206
+ resetToolTimeout?(): void;
195
207
  }
package/internal.ts CHANGED
@@ -35,6 +35,7 @@ export { __resetBuiltIns, flushBuiltInProviders, getBuiltIns } from "./built-ins
35
35
  export { __resetLifecycleRegistry } from "./events.js";
36
36
  export { __resetWorkflowExecutionHost } from "./execution-host.js";
37
37
  export { __resetLoadCache } from "./load/cache.js";
38
+ export { __resetStrikeBudgets } from "./sessions/bash-strikes.js";
38
39
  export {
39
40
  __resetSkillContracts,
40
41
  buildEffectiveContracts,
package/loop-def.ts CHANGED
@@ -216,10 +216,14 @@ export interface FanoutLoop extends LoopCommon {
216
216
  units: FanoutFn;
217
217
  /** Per-fanout concurrency ceiling. Caps in-flight units to
218
218
  * `min(concurrency, host maxConcurrency)`; `1` SERIALIZES the loop — the safe
219
- * model for a stage that mutates SHARED state (e.g. `implement` applying a plan
220
- * to one working tree, where parallel phases race on a shared file and a
221
- * dependent phase can run before its prerequisite has landed). Absent ⇒ the host
222
- * cap governs. Must be an integer ≥ 1 (validated at construction + load). */
219
+ * model for a fanout whose units mutate SHARED state AND whose write-sets are
220
+ * unknown (so the scheduler cannot derive dep edges and no lane-level scope
221
+ * floor guards the declared set). Absent ⇒ the host cap governs. A fanout
222
+ * whose units carry a declared write-set (`files:`) AND derived `deps` edges
223
+ * AND a lane-level scope floor MAY omit `concurrency`: disjoint-write units run
224
+ * concurrently, a write-overlap edge orders the waves, and the scope floor
225
+ * guards the declared set. Must be an integer ≥ 1 (validated at construction +
226
+ * load). */
223
227
  concurrency?: number;
224
228
  /** Opt out of collect-all: any unit failure halts the run. Default (absent) ⇒
225
229
  * collect-all. Under parallel dispatch, the first failing unit halts the
package/loop-kinds.ts CHANGED
@@ -30,6 +30,7 @@ import { decorateStage, runIdentityOf } from "./audit.js";
30
30
  // reconstruct byte-identical declared-order state regardless of
31
31
  // completion/resume order. iterate/assess keep advanceCursor (sequential).
32
32
  import { placeFanoutOutput, resolveStagePrompt } from "./chain-state.js";
33
+ import { failureMemoSuffix } from "./failure-memos.js";
33
34
  import { type Artifact, handleToString } from "./handle.js";
34
35
  import { isPanel, type Judge, type PanelJudge, panelMembers, resolveJudgePrompt } from "./judge.js";
35
36
  import { MSG_LOOP_CURSOR_CORRUPT } from "./messages.js";
@@ -493,7 +494,7 @@ export function buildUnitSession(
493
494
  cwd: run.cwd,
494
495
  runId: run.runId,
495
496
  state: run.state,
496
- prompt: u.prompt,
497
+ prompt: u.prompt + failureMemoSuffix(run.state),
497
498
  stageName: decorateStage(e.name, u.tag), // DISPLAY only — machine identity is `unit`
498
499
  skill: u.skill,
499
500
  lifecycle: run.lifecycle,
@@ -506,6 +507,8 @@ export function buildUnitSession(
506
507
  unit: { parent: e.name, role: u.role, index, id: u.id, label: u.label },
507
508
  model: run.resolveModel?.({ stage: e.name, skill: u.skill }),
508
509
  signal,
510
+ readSessionBranch: run.readSessionBranch,
511
+ worktreeDigest: run.worktreeDigest,
509
512
  collectAll: shouldCollectAll(e.loop),
510
513
  laneUnitIndex: laneIndexFor(e.loop, index),
511
514
  onFailure: undefined,