@relayflows/sdk 2.0.30 → 2.0.31

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 (295) hide show
  1. package/dist/agent-artifacts.d.ts.map +1 -1
  2. package/dist/agent-artifacts.js +2 -9
  3. package/dist/agent-artifacts.js.map +1 -1
  4. package/dist/agent-cwd.d.ts +69 -0
  5. package/dist/agent-cwd.d.ts.map +1 -0
  6. package/dist/agent-cwd.js +140 -0
  7. package/dist/agent-cwd.js.map +1 -0
  8. package/dist/artifact-scan-policy.d.ts +35 -0
  9. package/dist/artifact-scan-policy.d.ts.map +1 -0
  10. package/dist/artifact-scan-policy.js +49 -0
  11. package/dist/artifact-scan-policy.js.map +1 -0
  12. package/dist/authored-completion-record.d.ts +35 -0
  13. package/dist/authored-completion-record.d.ts.map +1 -0
  14. package/dist/authored-completion-record.js +92 -0
  15. package/dist/authored-completion-record.js.map +1 -0
  16. package/dist/authored-completion.d.ts +99 -0
  17. package/dist/authored-completion.d.ts.map +1 -0
  18. package/dist/authored-completion.js +184 -0
  19. package/dist/authored-completion.js.map +1 -0
  20. package/dist/authored-flow-error.d.ts +13 -1
  21. package/dist/authored-flow-error.d.ts.map +1 -1
  22. package/dist/authored-flow-error.js +12 -0
  23. package/dist/authored-flow-error.js.map +1 -1
  24. package/dist/authored-flow-executor.d.ts +7 -30
  25. package/dist/authored-flow-executor.d.ts.map +1 -1
  26. package/dist/authored-flow-executor.js +54 -47
  27. package/dist/authored-flow-executor.js.map +1 -1
  28. package/dist/authored-human.d.ts.map +1 -1
  29. package/dist/authored-human.js +1 -3
  30. package/dist/authored-human.js.map +1 -1
  31. package/dist/authored-node-entry.js +4 -1
  32. package/dist/authored-node-entry.js.map +1 -1
  33. package/dist/authored-node-runner.d.ts +9 -1
  34. package/dist/authored-node-runner.d.ts.map +1 -1
  35. package/dist/authored-node-runner.js +92 -17
  36. package/dist/authored-node-runner.js.map +1 -1
  37. package/dist/authored-root.d.ts +5 -0
  38. package/dist/authored-root.d.ts.map +1 -1
  39. package/dist/authored-root.js +20 -2
  40. package/dist/authored-root.js.map +1 -1
  41. package/dist/authored-step-output.d.ts +35 -10
  42. package/dist/authored-step-output.d.ts.map +1 -1
  43. package/dist/authored-step-output.js +108 -40
  44. package/dist/authored-step-output.js.map +1 -1
  45. package/dist/authored-verdict.d.ts +28 -0
  46. package/dist/authored-verdict.d.ts.map +1 -0
  47. package/dist/authored-verdict.js +79 -0
  48. package/dist/authored-verdict.js.map +1 -0
  49. package/dist/authored-worker-step.d.ts +5 -2
  50. package/dist/authored-worker-step.d.ts.map +1 -1
  51. package/dist/authored-worker-step.js +48 -11
  52. package/dist/authored-worker-step.js.map +1 -1
  53. package/dist/cli/check-worker-surface.d.ts +27 -0
  54. package/dist/cli/check-worker-surface.d.ts.map +1 -0
  55. package/dist/cli/check-worker-surface.js +63 -0
  56. package/dist/cli/check-worker-surface.js.map +1 -0
  57. package/dist/cli/check.d.ts +19 -2
  58. package/dist/cli/check.d.ts.map +1 -1
  59. package/dist/cli/check.js +12 -4
  60. package/dist/cli/check.js.map +1 -1
  61. package/dist/cli/cloud-format.d.ts +9 -0
  62. package/dist/cli/cloud-format.d.ts.map +1 -0
  63. package/dist/cli/cloud-format.js +77 -0
  64. package/dist/cli/cloud-format.js.map +1 -0
  65. package/dist/cli/cloud-live.d.ts +39 -0
  66. package/dist/cli/cloud-live.d.ts.map +1 -0
  67. package/dist/cli/cloud-live.js +325 -0
  68. package/dist/cli/cloud-live.js.map +1 -0
  69. package/dist/cli/cloud-read.d.ts +3 -7
  70. package/dist/cli/cloud-read.d.ts.map +1 -1
  71. package/dist/cli/cloud-read.js +14 -266
  72. package/dist/cli/cloud-read.js.map +1 -1
  73. package/dist/cli/cloud-refusal.d.ts +39 -0
  74. package/dist/cli/cloud-refusal.d.ts.map +1 -0
  75. package/dist/cli/cloud-refusal.js +95 -0
  76. package/dist/cli/cloud-refusal.js.map +1 -0
  77. package/dist/cli/cloud-status-view.d.ts +7 -0
  78. package/dist/cli/cloud-status-view.d.ts.map +1 -0
  79. package/dist/cli/cloud-status-view.js +214 -0
  80. package/dist/cli/cloud-status-view.js.map +1 -0
  81. package/dist/cli/direct-run.d.ts.map +1 -1
  82. package/dist/cli/direct-run.js +16 -2
  83. package/dist/cli/direct-run.js.map +1 -1
  84. package/dist/cli/hn-monitor.d.ts +0 -13
  85. package/dist/cli/hn-monitor.d.ts.map +1 -1
  86. package/dist/cli/hn-monitor.js +2 -1
  87. package/dist/cli/hn-monitor.js.map +1 -1
  88. package/dist/cli/local-agent-remedy.d.ts +80 -0
  89. package/dist/cli/local-agent-remedy.d.ts.map +1 -0
  90. package/dist/cli/local-agent-remedy.js +116 -0
  91. package/dist/cli/local-agent-remedy.js.map +1 -0
  92. package/dist/cli/observer-session.d.ts +41 -0
  93. package/dist/cli/observer-session.d.ts.map +1 -0
  94. package/dist/cli/observer-session.js +78 -0
  95. package/dist/cli/observer-session.js.map +1 -0
  96. package/dist/cli/run.d.ts +30 -2
  97. package/dist/cli/run.d.ts.map +1 -1
  98. package/dist/cli/run.js +186 -24
  99. package/dist/cli/run.js.map +1 -1
  100. package/dist/cli/status.d.ts +9 -0
  101. package/dist/cli/status.d.ts.map +1 -1
  102. package/dist/cli/status.js +31 -2
  103. package/dist/cli/status.js.map +1 -1
  104. package/dist/cli/step-evidence.d.ts +90 -0
  105. package/dist/cli/step-evidence.d.ts.map +1 -0
  106. package/dist/cli/step-evidence.js +259 -0
  107. package/dist/cli/step-evidence.js.map +1 -0
  108. package/dist/cli/step-failure.d.ts +14 -4
  109. package/dist/cli/step-failure.d.ts.map +1 -1
  110. package/dist/cli/step-failure.js +41 -76
  111. package/dist/cli/step-failure.js.map +1 -1
  112. package/dist/cli-commands.d.ts +6 -0
  113. package/dist/cli-commands.d.ts.map +1 -1
  114. package/dist/cli-commands.js +2 -0
  115. package/dist/cli-commands.js.map +1 -1
  116. package/dist/cli.d.ts +10 -0
  117. package/dist/cli.d.ts.map +1 -1
  118. package/dist/cli.js +53 -42
  119. package/dist/cli.js.map +1 -1
  120. package/dist/cloud-read.d.ts +15 -0
  121. package/dist/cloud-read.d.ts.map +1 -1
  122. package/dist/cloud-read.js +20 -1
  123. package/dist/cloud-read.js.map +1 -1
  124. package/dist/cloud-run-record.d.ts +27 -0
  125. package/dist/cloud-run-record.d.ts.map +1 -0
  126. package/dist/cloud-run-record.js +56 -0
  127. package/dist/cloud-run-record.js.map +1 -0
  128. package/dist/cloud-run.d.ts +2 -9
  129. package/dist/cloud-run.d.ts.map +1 -1
  130. package/dist/cloud-run.js +3 -20
  131. package/dist/cloud-run.js.map +1 -1
  132. package/dist/communication/local.d.ts.map +1 -1
  133. package/dist/communication/local.js +2 -1
  134. package/dist/communication/local.js.map +1 -1
  135. package/dist/communication/worker.d.ts +1 -1
  136. package/dist/communication/worker.d.ts.map +1 -1
  137. package/dist/communication/worker.js +13 -5
  138. package/dist/communication/worker.js.map +1 -1
  139. package/dist/compile.d.ts.map +1 -1
  140. package/dist/compile.js +28 -6
  141. package/dist/compile.js.map +1 -1
  142. package/dist/direct-input.d.ts.map +1 -1
  143. package/dist/direct-input.js +21 -1
  144. package/dist/direct-input.js.map +1 -1
  145. package/dist/failure-kinds.d.ts +96 -6
  146. package/dist/failure-kinds.d.ts.map +1 -1
  147. package/dist/failure-kinds.js +29 -2
  148. package/dist/failure-kinds.js.map +1 -1
  149. package/dist/flow-requirements.d.ts.map +1 -1
  150. package/dist/flow-requirements.js +24 -9
  151. package/dist/flow-requirements.js.map +1 -1
  152. package/dist/gate-contract.d.ts +7 -0
  153. package/dist/gate-contract.d.ts.map +1 -1
  154. package/dist/gate-contract.js +6 -1
  155. package/dist/gate-contract.js.map +1 -1
  156. package/dist/helper-preflight.d.ts.map +1 -1
  157. package/dist/helper-preflight.js +10 -3
  158. package/dist/helper-preflight.js.map +1 -1
  159. package/dist/helper-reference.d.ts +25 -0
  160. package/dist/helper-reference.d.ts.map +1 -0
  161. package/dist/helper-reference.js +129 -0
  162. package/dist/helper-reference.js.map +1 -0
  163. package/dist/index.d.ts +1 -1
  164. package/dist/index.d.ts.map +1 -1
  165. package/dist/index.js.map +1 -1
  166. package/dist/journal-client.d.ts +3 -1
  167. package/dist/journal-client.d.ts.map +1 -1
  168. package/dist/journal-client.js +17 -2
  169. package/dist/journal-client.js.map +1 -1
  170. package/dist/journal-projection.d.ts +16 -0
  171. package/dist/journal-projection.d.ts.map +1 -0
  172. package/dist/journal-projection.js +108 -0
  173. package/dist/journal-projection.js.map +1 -0
  174. package/dist/llm-worker.js +1 -1
  175. package/dist/llm-worker.js.map +1 -1
  176. package/dist/local-agent.d.ts +1 -1
  177. package/dist/local-agent.d.ts.map +1 -1
  178. package/dist/local-agent.js +4 -3
  179. package/dist/local-agent.js.map +1 -1
  180. package/dist/named-gate-lowering.js +35 -5
  181. package/dist/named-gate-lowering.js.map +1 -1
  182. package/dist/named-gate-preflight.d.ts +27 -0
  183. package/dist/named-gate-preflight.d.ts.map +1 -0
  184. package/dist/named-gate-preflight.js +47 -0
  185. package/dist/named-gate-preflight.js.map +1 -0
  186. package/dist/named-gates.d.ts +1 -1
  187. package/dist/named-gates.d.ts.map +1 -1
  188. package/dist/named-gates.js +3 -0
  189. package/dist/named-gates.js.map +1 -1
  190. package/dist/observer-link.d.ts +7 -0
  191. package/dist/observer-link.d.ts.map +1 -1
  192. package/dist/observer-link.js +3 -1
  193. package/dist/observer-link.js.map +1 -1
  194. package/dist/preflight.d.ts.map +1 -1
  195. package/dist/preflight.js +7 -0
  196. package/dist/preflight.js.map +1 -1
  197. package/dist/protocol.d.ts +2 -0
  198. package/dist/protocol.d.ts.map +1 -1
  199. package/dist/redact.d.ts +42 -0
  200. package/dist/redact.d.ts.map +1 -1
  201. package/dist/redact.js +128 -0
  202. package/dist/redact.js.map +1 -1
  203. package/dist/run-projection.d.ts +83 -0
  204. package/dist/run-projection.d.ts.map +1 -0
  205. package/dist/run-projection.js +199 -0
  206. package/dist/run-projection.js.map +1 -0
  207. package/dist/shell-word.d.ts +19 -0
  208. package/dist/shell-word.d.ts.map +1 -0
  209. package/dist/shell-word.js +23 -0
  210. package/dist/shell-word.js.map +1 -0
  211. package/dist/spec.d.ts +52 -3
  212. package/dist/spec.d.ts.map +1 -1
  213. package/dist/spec.js.map +1 -1
  214. package/dist/step-fields.d.ts +1 -1
  215. package/dist/step-fields.js +1 -1
  216. package/dist/step-fields.js.map +1 -1
  217. package/dist/steps-green.d.ts +27 -0
  218. package/dist/steps-green.d.ts.map +1 -0
  219. package/dist/steps-green.js +164 -0
  220. package/dist/steps-green.js.map +1 -0
  221. package/dist/validate.d.ts.map +1 -1
  222. package/dist/validate.js +39 -8
  223. package/dist/validate.js.map +1 -1
  224. package/dist/worker-lease.d.ts +8 -1
  225. package/dist/worker-lease.d.ts.map +1 -1
  226. package/dist/worker-lease.js +34 -4
  227. package/dist/worker-lease.js.map +1 -1
  228. package/dist/worker.d.ts +8 -0
  229. package/dist/worker.d.ts.map +1 -1
  230. package/dist/worker.js +17 -9
  231. package/dist/worker.js.map +1 -1
  232. package/package.json +3 -7
  233. package/src/agent-artifacts.ts +2 -10
  234. package/src/agent-cwd.ts +139 -0
  235. package/src/artifact-scan-policy.ts +51 -0
  236. package/src/authored-completion-record.ts +119 -0
  237. package/src/authored-completion.ts +203 -0
  238. package/src/authored-flow-error.ts +13 -1
  239. package/src/authored-flow-executor.ts +91 -58
  240. package/src/authored-human.ts +1 -4
  241. package/src/authored-node-entry.ts +4 -1
  242. package/src/authored-node-runner.ts +96 -22
  243. package/src/authored-root.ts +20 -2
  244. package/src/authored-step-output.ts +139 -42
  245. package/src/authored-verdict.ts +87 -0
  246. package/src/authored-worker-step.ts +60 -12
  247. package/src/cli/check-worker-surface.ts +66 -0
  248. package/src/cli/check.ts +35 -4
  249. package/src/cli/cloud-format.ts +82 -0
  250. package/src/cli/cloud-live.ts +366 -0
  251. package/src/cli/cloud-read.ts +13 -282
  252. package/src/cli/cloud-refusal.ts +113 -0
  253. package/src/cli/cloud-status-view.ts +213 -0
  254. package/src/cli/direct-run.ts +19 -2
  255. package/src/cli/hn-monitor.ts +2 -1
  256. package/src/cli/local-agent-remedy.ts +160 -0
  257. package/src/cli/observer-session.ts +107 -0
  258. package/src/cli/run.ts +233 -28
  259. package/src/cli/status.ts +59 -3
  260. package/src/cli/step-evidence.ts +310 -0
  261. package/src/cli/step-failure.ts +57 -81
  262. package/src/cli-commands.ts +2 -0
  263. package/src/cli.ts +64 -44
  264. package/src/cloud-read.ts +25 -1
  265. package/src/cloud-run-record.ts +64 -0
  266. package/src/cloud-run.ts +5 -24
  267. package/src/communication/local.ts +2 -1
  268. package/src/communication/worker.ts +13 -5
  269. package/src/compile.ts +28 -6
  270. package/src/direct-input.ts +22 -1
  271. package/src/failure-kinds.ts +104 -2
  272. package/src/flow-requirements.ts +24 -9
  273. package/src/gate-contract.ts +13 -1
  274. package/src/helper-preflight.ts +10 -3
  275. package/src/helper-reference.ts +130 -0
  276. package/src/index.ts +2 -0
  277. package/src/journal-client.ts +19 -2
  278. package/src/journal-projection.ts +106 -0
  279. package/src/llm-worker.ts +1 -1
  280. package/src/local-agent.ts +4 -2
  281. package/src/named-gate-lowering.ts +35 -5
  282. package/src/named-gate-preflight.ts +47 -0
  283. package/src/named-gates.ts +3 -0
  284. package/src/observer-link.ts +10 -1
  285. package/src/preflight.ts +7 -0
  286. package/src/protocol.ts +2 -0
  287. package/src/redact.ts +111 -0
  288. package/src/run-projection.ts +247 -0
  289. package/src/shell-word.ts +24 -0
  290. package/src/spec.ts +54 -3
  291. package/src/step-fields.ts +1 -1
  292. package/src/steps-green.ts +168 -0
  293. package/src/validate.ts +35 -8
  294. package/src/worker-lease.ts +35 -5
  295. package/src/worker.ts +27 -11
@@ -74,6 +74,15 @@ export const CHECK_FAILURE_KINDS = [
74
74
  * (#442). Warning-only by design: the declaration stays legal and the flow
75
75
  * still runs, but an author who wrote one must not be left believing it
76
76
  * sandboxes the step.
77
+ *
78
+ * `gate_path_unscanned` names an `artifact_exists` path inside a prefix the
79
+ * bundled agent worker's artifact scan excludes, so the scan can never put it
80
+ * in the journaled `output.artifacts` the gate reads. It warns rather than
81
+ * refuses because the scan is not the only writer of that list — the same
82
+ * worker promotes JSON stdout and completed Relay task output verbatim, and a
83
+ * custom worker may journal anything — so such a gate is unproven, not
84
+ * unsatisfiable. Temporary: it describes #513, and retires with
85
+ * `named-gate-preflight.ts` when the scan stops excluding those paths.
77
86
  */
78
87
  export const PREFLIGHT_WARNING_KINDS = [
79
88
  'unprovable_effects',
@@ -83,6 +92,7 @@ export const PREFLIGHT_WARNING_KINDS = [
83
92
  'vacuous_gate',
84
93
  'budget_unmetered',
85
94
  'permissions_unenforced',
95
+ 'gate_path_unscanned',
86
96
  ] as const;
87
97
 
88
98
  /**
@@ -124,6 +134,14 @@ export const RUN_FAILURE_KINDS = [
124
134
  'gate_failed',
125
135
  /** `flows answer` named a wait the run is not asking: unknown, or already answered. */
126
136
  'human_wait_unknown',
137
+ /**
138
+ * `--local-agent` cannot be honoured for this invocation, so it is refused
139
+ * rather than accepted and ignored. A local agent worker is admitted at run
140
+ * start and pinned into the authored root's metadata; a resume can only
141
+ * reproduce the surface the root was started with. Exit 2, before any worker
142
+ * attaches and before the resume touches the journal.
143
+ */
144
+ 'local_agent_unavailable',
127
145
  ] as const;
128
146
 
129
147
  /**
@@ -136,8 +154,17 @@ export const RUN_WARNING_KINDS = [
136
154
  'connection_file_stale',
137
155
  ] as const;
138
156
 
139
- /** File-level editor hints emitted by flows check, outside pure preflight. */
140
- export const CHECK_WARNING_KINDS = ['editor_schema_missing'] as const;
157
+ /**
158
+ * Warnings emitted by flows check, outside pure preflight.
159
+ *
160
+ * `editor_schema_missing` is a file-level editor hint. `agent_worker_unresolved`
161
+ * is a property of the *invocation*, not of the spec: a spec with `agent`
162
+ * steps needs a worker attached for step type `agent`, and only the caller
163
+ * knows whether it attaches one. `flows check` attaches none and, being
164
+ * daemon-free, can see none either — so it opts in, while `flows run`, `flows
165
+ * build` and SDK submissions do not (cli/check-worker-surface.ts).
166
+ */
167
+ export const CHECK_WARNING_KINDS = ['editor_schema_missing', 'agent_worker_unresolved'] as const;
141
168
  export type CheckWarningKind = (typeof CHECK_WARNING_KINDS)[number];
142
169
 
143
170
  export type PreflightFailureKind = (typeof PREFLIGHT_FAILURE_KINDS)[number];
@@ -146,6 +173,69 @@ export type PreflightWarningKind = (typeof PREFLIGHT_WARNING_KINDS)[number];
146
173
  export type RunFailureKind = (typeof RUN_FAILURE_KINDS)[number];
147
174
  export type RunWarningKind = (typeof RUN_WARNING_KINDS)[number];
148
175
 
176
+ /**
177
+ * One failed attempt of a step, as the journal recorded it.
178
+ *
179
+ * The kernel appends a `step.completed` PER ATTEMPT (relayflowd-core/src/machine.rs
180
+ * `completion_actions`), so a step that was retried leaves an ordered account
181
+ * of every failure — not just the one that ran out of budget. Reporting only
182
+ * the last is how a push rejected by a pre-receive hook was reported as
183
+ * "nothing staged inside the declared scope": the retry failed for a different
184
+ * reason than the original attempt, and the original reason was the diagnosis.
185
+ *
186
+ * Excerpts here are bounded harder than the terminal attempt's (256 bytes
187
+ * rather than 1,024): this is history beside the primary account, not a
188
+ * replacement for it.
189
+ */
190
+ export interface StepAttemptFailure {
191
+ /**
192
+ * The journal entry envelope's attempt number. Absent when the journal did
193
+ * not carry one; the position in the list is not a substitute, because a
194
+ * crashed attempt that consumed no iteration is still its own record.
195
+ */
196
+ attempt?: number;
197
+ /** The kernel's label for THIS attempt, e.g. `verification_failed`. */
198
+ completionReason?: string;
199
+ /** `retry`, `step_done` or `park`: what the kernel did next, not why it failed. */
200
+ disposition?: string;
201
+ exitCode?: number;
202
+ /** Redacted, terminal-safe UTF-8 excerpt, at most 256 bytes. */
203
+ stdoutTail?: string;
204
+ /** Redacted, terminal-safe UTF-8 excerpt, at most 256 bytes. */
205
+ stderrTail?: string;
206
+ /** This attempt's own account, from the same fields the terminal one reads. */
207
+ detail?: string;
208
+ /** Set when an excerpt above was cut to fit the per-attempt bound. */
209
+ truncated?: boolean;
210
+ }
211
+
212
+ /**
213
+ * What comparing the attempts' recorded evidence established — and no more.
214
+ *
215
+ * `differs` means the journal's own failure evidence is not the same across
216
+ * attempts, which usually means an earlier attempt had a side effect the retry
217
+ * then tripped over. `unchanged` is a statement about the RECORD, not a proof
218
+ * that the underlying causes were identical. `unknown` is the honest answer
219
+ * when an attempt journaled no account of itself, or when its account was
220
+ * already truncated by its producer: equal evidence that was never complete is
221
+ * not evidence of equality.
222
+ */
223
+ export type AttemptEvidenceComparison = 'differs' | 'unchanged' | 'unknown';
224
+
225
+ /**
226
+ * Why a run parked, for the reporting side that has to name a remedy.
227
+ *
228
+ * `worker_unavailable` is a step nothing is attached to run — the one case
229
+ * `--local-agent` fixes. `needs_human` is the kernel's manual-recovery wait
230
+ * after a worker attempt already failed, and attaching a worker does not clear
231
+ * it. Both arrive as exit 3 under `run_parked`, so the distinction has to
232
+ * travel as a value: it lives here, beside the run vocabulary, because the
233
+ * classifier (cli/run.ts), the authored error boundary (authored-flow-error.ts)
234
+ * and the remedy formatter (cli/local-agent-remedy.ts) all need the same one
235
+ * and none of them may depend on the others.
236
+ */
237
+ export type ParkCause = 'worker_unavailable' | 'needs_human';
238
+
149
239
  /**
150
240
  * Optional evidence on the existing step_failed diagnostic, not a new kind.
151
241
  *
@@ -154,6 +244,9 @@ export type RunWarningKind = (typeof RUN_WARNING_KINDS)[number];
154
244
  * agent or llm step leaves `completionReason` and whatever the daemon captured
155
245
  * into `detail` (see cli/step-failure.ts). Absent means "not journaled", never
156
246
  * "zero" — an exit code is only ever reported when one was actually recorded.
247
+ *
248
+ * The scalar evidence fields always describe the TERMINAL attempt. `attempts`
249
+ * is additive history and is present only when the step failed more than once.
157
250
  */
158
251
  export interface StepFailedDetails {
159
252
  stepId?: string;
@@ -197,6 +290,15 @@ export interface StepFailedDetails {
197
290
  detail?: string;
198
291
  /** The attempt's redacted `stream-json` transcript on disk, when the worker wrote one. */
199
292
  transcriptPath?: string;
293
+ /**
294
+ * Every failed attempt of the step this failure names, oldest first, present
295
+ * only when there was more than one. The last element is the same attempt the
296
+ * scalar fields above describe; the first is the one `retries_exhausted`
297
+ * alone used to hide.
298
+ */
299
+ attempts?: StepAttemptFailure[];
300
+ /** What comparing those attempts' recorded evidence established. */
301
+ attemptEvidence?: AttemptEvidenceComparison;
200
302
  /** A runnable `flows replay` invocation for this run. */
201
303
  hint?: string;
202
304
  /** The on-disk journal for this run, when the data dir is known. */
@@ -4,6 +4,7 @@ import type { TriggerSource } from '@relayflows/surface';
4
4
  import { providerDeclaration } from './provider-trigger-contract.js';
5
5
  import type { FlowSpec } from './spec.js';
6
6
  import { helperCall } from './yaml-helpers.js';
7
+ import { helperNamespacesUsed } from './helper-reference.js';
7
8
 
8
9
  /**
9
10
  * What a flow needs from the workspace it deploys into, read from inert
@@ -155,10 +156,14 @@ export function flowRequirements(
155
156
  // payload as input, and handler bodies are not dispatched yet (flows #301).
156
157
  // A handler's *trigger* is still a requirement — it is what wakes the flow.
157
158
  const text = typeof flow.body === 'function' ? Function.prototype.toString.call(flow.body) : '';
158
- const root = contextParameter(text);
159
- if (root !== undefined) {
159
+ const rootName = contextParameter(text);
160
+ const root = rootName === undefined ? undefined : escapeRegExp(rootName);
161
+ if (root !== undefined && rootName !== undefined) {
162
+ // The AST walk compares against an Identifier name, so it needs the raw
163
+ // parameter; the regex scanners below need the escaped one.
164
+ const referenced = helperNamespacesUsed(text, rootName);
160
165
  for (const { provider, namespace } of helperProviders) {
161
- if (helperReference(root, namespace).test(text)) declare({ provider, from: 'helper', detail: `f.${namespace}` });
166
+ if (referenced.has(namespace)) declare({ provider, from: 'helper', detail: `f.${namespace}` });
162
167
  }
163
168
  for (const use of workerCalls(root, text)) need(use.cli === undefined ? fallback : harnessFromCli(use.cli), use.detail);
164
169
  // `f.human(q, { to: "slack:#eng" })` is delivered by Cloud through that
@@ -219,15 +224,25 @@ function stringList(value: unknown): string[] {
219
224
  return Array.isArray(value) ? value.filter((entry): entry is string => typeof entry === 'string') : [];
220
225
  }
221
226
 
222
- /** The body's first parameter (`f` in `async (f, input) => …`), escaped for a pattern. */
227
+ /**
228
+ * The body's first parameter (`f` in `async (f, input) => …`), RAW.
229
+ *
230
+ * Returned unescaped because the AST walk compares it to an `Identifier`
231
+ * name: escaping turned a legal parameter like `f$` into `f\$`, which matches
232
+ * no identifier and hid every helper call in that flow. Callers that build a
233
+ * pattern escape it themselves with `escapeRegExp`.
234
+ */
223
235
  function contextParameter(body: string): string | undefined {
224
- const parameter = body.match(/^(?:async\s+)?(?:function(?:\s+[\w$]+)?\s*)?(?:\(\s*([\w$]+)|([\w$]+)\s*=>)/u);
225
- return (parameter?.[1] ?? parameter?.[2])?.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
236
+ // The third alternative is an object-literal method (`async post(f) { … }`),
237
+ // a shape `Function.prototype.toString()` can return and which the first two
238
+ // do not match — leaving `root` undefined and the body unscanned entirely.
239
+ const parameter = body.match(/^(?:async\s+)?(?:function\s*\*?\s*(?:[\w$]+)?\s*)?(?:\(\s*([\w$]+)|([\w$]+)\s*=>|\*?\s*[\w$]+\s*\(\s*([\w$]+))/u);
240
+ return parameter?.[1] ?? parameter?.[2] ?? parameter?.[3];
226
241
  }
227
242
 
228
- /** Same recognition as `preflightHelpers`: `f.slack`, `f .slack`, `f["slack"]`. */
229
- function helperReference(root: string, namespace: string): RegExp {
230
- return new RegExp(`(?:^|[^\\w$.])${root}\\s*(?:\\.\\s*${namespace}\\b|\\[\\s*['"]${namespace}['"]\\s*\\])`, 'u');
243
+ /** Escape a literal for embedding in a RegExp source. */
244
+ function escapeRegExp(value: string): string {
245
+ return value.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
231
246
  }
232
247
 
233
248
  /**
@@ -24,6 +24,13 @@ export interface StepGateInspection extends DataGateClassification {
24
24
  * identically to a gate that judges something.
25
25
  */
26
26
  acceptsAnyOutput?: true;
27
+ /**
28
+ * Present when the step declares `onNonZero: 'record'`. The `exit_code`
29
+ * check is still applied and still journaled, but a positive code satisfies
30
+ * it instead of failing the step. Without this a recording step reads
31
+ * exactly like a gated one — the `|| true` ambiguity, moved into the report.
32
+ */
33
+ recordsNonZeroExit?: true;
27
34
  }
28
35
 
29
36
  /** Annotation-only keywords: present, they still constrain no instance. */
@@ -55,11 +62,15 @@ export function acceptsAnyOutput(schema: unknown): boolean {
55
62
  /** Describe the exact named checks the existing kernel applies to a step. */
56
63
  export function inspectStepGate(step: StepSpec): StepGateInspection {
57
64
  const checks: JournalGateCheck[] = [];
65
+ // A policy for the step's own exit code, not a gate of its own: it never
66
+ // adds or removes a check, it changes what a positive code means to one.
67
+ const recording = step.type === 'deterministic' && step.onNonZero === 'record'
68
+ ? { recordsNonZeroExit: true as const } : {};
58
69
  if (isNamedGate(step.verification)) {
59
70
  checks.push('exit_code');
60
71
  if (step.verification.type === 'references_input') checks.push('output_contains');
61
72
  if (step.verification.type === 'word_count_bounds') checks.push('json_schema');
62
- return { stepId: step.id, kind: 'data', checks, evaluator: 'kernel', preflightable: true, replayable: true };
73
+ return { stepId: step.id, kind: 'data', checks, evaluator: 'kernel', preflightable: true, replayable: true, ...recording };
63
74
  }
64
75
  if (step.type === 'deterministic') checks.push('exit_code');
65
76
  if (step.verification?.type === 'output_contains') checks.push('output_contains');
@@ -75,5 +86,6 @@ export function inspectStepGate(step: StepSpec): StepGateInspection {
75
86
  preflightable: true,
76
87
  replayable: true,
77
88
  ...(vacuous ? { acceptsAnyOutput: true as const } : {}),
89
+ ...recording,
78
90
  };
79
91
  }
@@ -1,5 +1,6 @@
1
1
  import { helperProviders } from '@relayflows/surface/runtime';
2
2
  import type { PreflightResult, PreflightDiagnostic } from './preflight.js';
3
+ import { helperNamespacesUsed } from './helper-reference.js';
3
4
 
4
5
  /** Static discovery never executes the body; dynamic aliases are checked at call time. */
5
6
  export function preflightHelpers(
@@ -8,12 +9,18 @@ export function preflightHelpers(
8
9
  providers?: Readonly<Record<string, { mount: boolean; mock: boolean; token?: string }>> },
9
10
  ): PreflightResult {
10
11
  const body = typeof definition.body === 'function' ? Function.prototype.toString.call(definition.body) : '';
11
- const parameter = body.match(/^(?:async\s+)?(?:function(?:\s+[\w$]+)?\s*)?(?:\(\s*([\w$]+)|([\w$]+)\s*=>)/);
12
- const root = (parameter?.[1] ?? parameter?.[2])?.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
12
+ const parameter = body.match(/^(?:async\s+)?(?:function\s*\*?\s*(?:[\w$]+)?\s*)?(?:\(\s*([\w$]+)|([\w$]+)\s*=>|\*?\s*[\w$]+\s*\(\s*([\w$]+))/u);
13
+ // NOT regex-escaped: this is compared to an AST Identifier name, so a legal
14
+ // parameter like `f$` must stay `f$`. Escaping it hid every helper call.
15
+ const root = parameter?.[1] ?? parameter?.[2] ?? parameter?.[3];
13
16
  const diagnostics: PreflightDiagnostic[] = [];
17
+ // Read from a parse, not from the text: a helper named inside a string,
18
+ // comment, template quasi or regex is not used, and refusing on one demands
19
+ // a mount the flow never touches.
20
+ const referenced = root === undefined ? new Set<string>() : helperNamespacesUsed(body, root);
14
21
  for (const { provider, namespace, supported } of helperProviders) {
15
22
  const used = definition.header?.tools?.[namespace] === true
16
- || (root !== undefined && new RegExp(`(?:^|[^\\w$.])${root}\\s*(?:\\.\\s*${namespace}\\b|\\[\\s*['"]${namespace}['"]\\s*\\])`).test(body));
23
+ || referenced.has(namespace);
17
24
  if (!used) continue;
18
25
  const fact = facts.providers?.[provider] ?? (provider === 'slack'
19
26
  ? { mount: facts.slackMount, mock: facts.slackMock, token: facts.slackToken }
@@ -0,0 +1,130 @@
1
+ import { parse, parseExpressionAt } from 'acorn';
2
+
3
+ /**
4
+ * Which `f.<namespace>` helpers a flow body actually USES.
5
+ *
6
+ * Read from a parse, not from the text. A helper merely NAMED in a string, a
7
+ * comment, a template quasi or a regex is not used, and declaring a
8
+ * requirement from one refuses a flow for a mount it never touches:
9
+ * `f.run("echo f.gitlab")`, an agent prompt naming `f.slack`, or a PR title in
10
+ * a commit message were each enough to demand a GitLab mount.
11
+ *
12
+ * This was first written as a lexer that blanked comments, strings and
13
+ * regexes. That is the wrong tool: `/` is a regex or a division depending on
14
+ * whether the preceding token ends an expression, which is not decidable
15
+ * without parse context, and the two shapes that ambiguity broke —
16
+ * interpolations (`${await f.gitlab…}`) and a quote inside a regex (`/'/`) —
17
+ * both HID real helper use, deploying a flow without its mount to fail at
18
+ * runtime. A parser settles every one of those by construction.
19
+ *
20
+ * What a parser still cannot see is indirection: `const p = 'gitlab';
21
+ * f[p].issues…` is invisible to any static reading, because it needs value
22
+ * tracking. This scan is therefore a convenience for the literal case, never
23
+ * the authority — `header.tools[namespace] === true` is the declaration that
24
+ * is, and it short-circuits this entirely.
25
+ */
26
+ export function helperNamespacesUsed(body: string, root: string): ReadonlySet<string> {
27
+ const program = parseFlowBody(body);
28
+ if (program === null) return textFallback(body, root);
29
+ const used = new Set<string>();
30
+ walk(program, (node) => {
31
+ if (node.type !== 'MemberExpression') return;
32
+ const object = node.object as AstNode | undefined;
33
+ if (object?.type !== 'Identifier' || object.name !== root) return;
34
+ const namespace = memberName(node);
35
+ if (namespace !== undefined) used.add(namespace);
36
+ });
37
+ return used;
38
+ }
39
+
40
+ /** `f.slack`, `f["slack"]`, `f?.slack` — but not `f[variable]`, which is unknowable. */
41
+ function memberName(node: AstNode): string | undefined {
42
+ const property = node.property as AstNode | undefined;
43
+ if (property === undefined) return undefined;
44
+ if (node.computed !== true) return property.type === 'Identifier' ? property.name : undefined;
45
+ return property.type === 'Literal' && typeof property.value === 'string' ? property.value : undefined;
46
+ }
47
+
48
+ /**
49
+ * Parse whatever `Function.prototype.toString()` produced.
50
+ *
51
+ * It can be an arrow, a function expression, an async method shorthand from an
52
+ * object literal, or a declaration — only some of which are expressions, so
53
+ * each shape gets a try. Types are already stripped by the time a body reaches
54
+ * here (Node strips before evaluating, and bundlers transpile), so this is
55
+ * plain JavaScript.
56
+ */
57
+ function parseFlowBody(body: string): AstNode | null {
58
+ const options = { ecmaVersion: 'latest' as const, allowAwaitOutsideFunction: true, allowReturnOutsideFunction: true };
59
+ // `parseExpressionAt` stops at the end of the first expression and does not
60
+ // object to what follows, so `async post(f) { … }` parses as the identifier
61
+ // `async` and reports success having read three characters. Every attempt
62
+ // must therefore consume the whole source, or a method body would be walked
63
+ // as its own name and declare no helpers at all.
64
+ const whole = (source: string, node: AstNode): AstNode => {
65
+ const end = typeof node.end === 'number' ? node.end : -1;
66
+ if (end < 0 || source.slice(end).trim() !== '') throw new SyntaxError('unconsumed input');
67
+ return node;
68
+ };
69
+ for (const attempt of [
70
+ () => whole(body, parseExpressionAt(body, 0, options) as unknown as AstNode),
71
+ () => whole(`(${body})`, parseExpressionAt(`(${body})`, 0, options) as unknown as AstNode),
72
+ () => parse(body, options) as unknown as AstNode,
73
+ // An object-literal method (`async post(f) { … }`) is neither expression
74
+ // nor statement on its own; it only parses inside an object.
75
+ () => whole(`({${body}})`, parseExpressionAt(`({${body}})`, 0, options) as unknown as AstNode),
76
+ ]) {
77
+ try {
78
+ return attempt();
79
+ } catch {
80
+ continue;
81
+ }
82
+ }
83
+ return null;
84
+ }
85
+
86
+ /**
87
+ * Last resort when nothing parses: match the text.
88
+ *
89
+ * Deliberately the permissive direction. An unparseable body is a shape this
90
+ * code does not understand, and under-reporting would deploy a flow without a
91
+ * mount it needs and fail at the call; over-reporting only asks for a mount
92
+ * that may go unused. Reaching here at all is a bug worth hearing about.
93
+ */
94
+ function textFallback(body: string, root: string): ReadonlySet<string> {
95
+ const used = new Set<string>();
96
+ const escaped = root.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
97
+ const pattern = new RegExp(`(?:^|[^\\w$.])${escaped}\\s*(?:\\.\\s*([\\w$]+)|\\[\\s*['"]([^'"]+)['"]\\s*\\])`, 'gu');
98
+ for (const match of body.matchAll(pattern)) {
99
+ const namespace = match[1] ?? match[2];
100
+ if (namespace !== undefined) used.add(namespace);
101
+ }
102
+ return used;
103
+ }
104
+
105
+ type AstNode = {
106
+ type: string;
107
+ end?: number;
108
+ name?: string;
109
+ value?: unknown;
110
+ computed?: boolean;
111
+ [key: string]: unknown;
112
+ };
113
+
114
+ /** Depth-first over every child node, without pulling in a second package. */
115
+ function walk(node: AstNode, visit: (node: AstNode) => void): void {
116
+ visit(node);
117
+ for (const key of Object.keys(node)) {
118
+ if (key === 'type' || key === 'start' || key === 'end' || key === 'loc') continue;
119
+ const child = node[key];
120
+ if (Array.isArray(child)) {
121
+ for (const entry of child) if (isNode(entry)) walk(entry, visit);
122
+ } else if (isNode(child)) {
123
+ walk(child, visit);
124
+ }
125
+ }
126
+ }
127
+
128
+ function isNode(value: unknown): value is AstNode {
129
+ return typeof value === 'object' && value !== null && typeof (value as { type?: unknown }).type === 'string';
130
+ }
package/src/index.ts CHANGED
@@ -34,6 +34,8 @@ export type {
34
34
  LlmStepSpec,
35
35
  NamedAgentSpec,
36
36
  NamedDataGate,
37
+ OnNonZero,
38
+ StepsGreenGate,
37
39
  ReferencesInputGate,
38
40
  SubprocessGate,
39
41
  WordCountBoundsGate,
@@ -51,6 +51,7 @@ interface Pending {
51
51
  /** A structured rejection returned by relayflowd over the journal protocol. */
52
52
  export class JournalProtocolError extends Error {
53
53
  readonly code: string;
54
+ verb?: string;
54
55
 
55
56
  constructor(code: string, message: string) {
56
57
  super(`${code}: ${message}`);
@@ -223,12 +224,19 @@ export class JournalClient extends EventEmitter {
223
224
  * Validate a compiled kernel-dialect spec (zero-agent flows legal), create
224
225
  * the run file, and append `run.spawned`. Authoring specs must be compiled
225
226
  * with `toKernelSpec` before crossing this journal-protocol boundary.
227
+ * `watch` streams the run's entries as `'entry'` events while it runs.
226
228
  */
227
- runStart(spec: KernelRunSpec, reuseFromRunId?: string, admissionKey?: string): Promise<VerbContract['run.start']['result']> {
229
+ runStart(
230
+ spec: KernelRunSpec,
231
+ reuseFromRunId?: string,
232
+ admissionKey?: string,
233
+ watch = false,
234
+ ): Promise<VerbContract['run.start']['result']> {
228
235
  return this.request('run.start', {
229
236
  spec,
230
237
  ...(reuseFromRunId === undefined ? {} : { reuse_from_run_id: reuseFromRunId }),
231
238
  ...(admissionKey === undefined ? {} : { admission_key: admissionKey }),
239
+ ...(watch ? { watch: true } : {}),
232
240
  }, null);
233
241
  }
234
242
 
@@ -370,6 +378,9 @@ export class JournalClient extends EventEmitter {
370
378
  step_id: stepId,
371
379
  attempt,
372
380
  lease_id: leaseId,
381
+ }).catch(error => {
382
+ if (error instanceof JournalProtocolError) error.verb = 'step.heartbeat';
383
+ throw error;
373
384
  });
374
385
  }
375
386
 
@@ -401,7 +412,10 @@ export class JournalClient extends EventEmitter {
401
412
  idempotency_key: idempotencyKey,
402
413
  completionReason,
403
414
  ...extra,
404
- }, null);
415
+ }, null).catch(error => {
416
+ if (error instanceof JournalProtocolError) error.verb = 'step.complete';
417
+ throw error;
418
+ });
405
419
  }
406
420
 
407
421
  /** Satisfy `wait.event`; a human response arrives here too. */
@@ -422,6 +436,9 @@ export class JournalClient extends EventEmitter {
422
436
  attempt,
423
437
  idempotency_key: idempotencyKey,
424
438
  ...wait,
439
+ }).catch(error => {
440
+ if (error instanceof JournalProtocolError) error.verb = 'step.wait';
441
+ throw error;
425
442
  });
426
443
  }
427
444
 
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Fold a run's journal entries, as `run.start {watch}` or `run.watch` pushes
3
+ * them, into a `RunProjection`: `run.spawned` opens it with the declared step
4
+ * graph, attempt starts and completions become step transitions, and
5
+ * `run.completed` closes it. Entries journaled before `liveSinceMs` (a resume
6
+ * replaying history) update the snapshot without publishing a message each.
7
+ */
8
+
9
+ import type { JournalEvent } from './journal-reader.js';
10
+ import type { ProgressEvent } from './progress.js';
11
+ import type { DeclaredStep, RunProjection, RunSnapshot } from './run-projection.js';
12
+ import type { StepType } from './spec.js';
13
+
14
+ export type OpenProjection = (run: { runId: string; flow: string; steps: DeclaredStep[] }) => RunProjection;
15
+
16
+ export function createJournalProjector(open: OpenProjection, liveSinceMs = 0): (entry: JournalEvent) => void {
17
+ let projection: RunProjection | undefined;
18
+ const types = new Map<string, StepType>();
19
+ const started = new Map<string, number>();
20
+ const parked = new Set<string>();
21
+
22
+ return entry => {
23
+ const payload = (entry.payload ?? {}) as Record<string, unknown>;
24
+ const live = entry.at_ms >= liveSinceMs;
25
+ if (entry.entry_type === 'run.spawned') {
26
+ if (projection !== undefined) return;
27
+ const spec = (payload['spec'] ?? {}) as { name?: unknown; steps?: unknown };
28
+ const steps = (Array.isArray(spec.steps) ? spec.steps : []).flatMap(declaredStep);
29
+ for (const step of steps) types.set(step.id, step.type);
30
+ projection = open({ runId: entry.run_id, flow: typeof spec.name === 'string' ? spec.name : 'flow', steps });
31
+ return;
32
+ }
33
+ if (projection === undefined) return;
34
+ if (entry.entry_type === 'epoch.summary') {
35
+ started.clear();
36
+ parked.clear();
37
+ const done = (payload['steps_done'] ?? {}) as Record<string, { completionReason?: string }>;
38
+ const pending = (payload['steps_open'] ?? {}) as Record<string, { state?: string; attempt?: number }>;
39
+ projection.epoch([
40
+ ...Object.entries(done).map(([id, value]) => ({ id,
41
+ state: value.completionReason === 'success' ? 'completed' as const : 'failed' as const,
42
+ completionReason: value.completionReason })),
43
+ ...Object.entries(pending).map(([id, value]) => ({ id, attempt: value.attempt,
44
+ state: value.state === 'running' ? 'running' as const : value.state === 'needs_human' ? 'parked' as const : 'pending' as const })),
45
+ ], live);
46
+ return;
47
+ }
48
+ if (entry.step_id === null && entry.entry_type !== 'run.completed') return;
49
+ const stepId = entry.step_id ?? '';
50
+ const stepType = types.get(stepId) ?? 'deterministic';
51
+ const attempt = entry.attempt ?? undefined;
52
+ const key = `${stepId}#${attempt ?? 0}`;
53
+ const event = (type: ProgressEvent['type'], completionReason?: string): void => {
54
+ const elapsedMs = type === 'step.started' ? 0 : entry.at_ms - (started.get(key) ?? entry.at_ms);
55
+ projection!.step({
56
+ type, stepId, stepType, elapsedMs,
57
+ ...(attempt === undefined ? {} : { attempt }),
58
+ ...(completionReason === undefined ? {} : { completionReason: completionReason as never }),
59
+ }, live);
60
+ };
61
+ switch (entry.entry_type) {
62
+ case 'step.attempt.started':
63
+ parked.delete(key);
64
+ started.set(key, entry.at_ms);
65
+ event('step.started');
66
+ return;
67
+ case 'wait.human':
68
+ if (parked.has(key)) return;
69
+ parked.add(key);
70
+ event('step.parked');
71
+ return;
72
+ case 'step.completed': {
73
+ const reason = typeof payload['completionReason'] === 'string' ? payload['completionReason'] : undefined;
74
+ const isParked = payload['disposition'] === 'park';
75
+ if (isParked && parked.has(key)) return;
76
+ if (isParked) parked.add(key);
77
+ event(isParked ? 'step.parked' : reason === 'success' ? 'step.completed' : 'step.failed', reason);
78
+ return;
79
+ }
80
+ case 'run.completed': {
81
+ // Historical outcomes belong to earlier epochs. The current resume's
82
+ // report closes the projection if no new terminal entry is appended.
83
+ if (!live) return;
84
+ const reason = typeof payload['completionReason'] === 'string' ? payload['completionReason'] : undefined;
85
+ projection.finish({ status: runStatus(reason), ...(reason === undefined ? {} : { completionReason: reason }) });
86
+ return;
87
+ }
88
+ }
89
+ };
90
+ }
91
+
92
+ function declaredStep(value: unknown): DeclaredStep[] {
93
+ if (typeof value !== 'object' || value === null) return [];
94
+ const step = value as { id?: unknown; type?: unknown; depends_on?: unknown };
95
+ if (typeof step.id !== 'string') return [];
96
+ const type = step.type === 'llm' || step.type === 'agent' ? step.type : 'deterministic';
97
+ const dependsOn = Array.isArray(step.depends_on)
98
+ ? step.depends_on.filter((id): id is string => typeof id === 'string') : [];
99
+ return [{ id: step.id, type, dependsOn }];
100
+ }
101
+
102
+ function runStatus(reason: string | undefined): RunSnapshot['status'] {
103
+ if (reason === 'success') return 'completed';
104
+ if (reason === 'canceled') return 'canceled';
105
+ return 'failed';
106
+ }
package/src/llm-worker.ts CHANGED
@@ -46,7 +46,7 @@ export class LlmWorker extends EventEmitter {
46
46
 
47
47
  private readonly onDispatch = (dispatch: StepDispatchEvent): void => {
48
48
  if (this.closing || dispatch.step_type !== 'llm') return;
49
- const running = this.execute(dispatch).catch(error => { this.emit('error', error); });
49
+ const running = this.execute(dispatch).catch(error => { this.emit('error', error, dispatch); });
50
50
  this.inFlight.add(running);
51
51
  void running.finally(() => { this.inFlight.delete(running); });
52
52
  };
@@ -1,3 +1,4 @@
1
+ import { onWorkerFailure } from './worker-lease.js';
1
2
  import { randomUUID } from 'node:crypto';
2
3
  import type { JournalClient } from './journal-client.js';
3
4
  import { AgentWorker } from './worker.js';
@@ -10,6 +11,7 @@ export async function attachLocalAgent(
10
11
  onPtyReady?: (path: string) => void,
11
12
  requestedStream?: string,
12
13
  capacity: number = DEFAULT_LOCAL_AGENT_CAPACITY,
14
+ runRoot?: string,
13
15
  ): Promise<{
14
16
  stream: string;
15
17
  readonly failure: unknown;
@@ -24,12 +26,12 @@ export async function attachLocalAgent(
24
26
  // second parking behind the first. Authored bodies size their admission to
25
27
  // this same number (worker-slots.ts), so they never ask for more.
26
28
  capacity,
27
- dataDir, onPtyReady,
29
+ dataDir, onPtyReady, runRoot,
28
30
  pins: { workspace: [], streams: [{ stream, read_offset: 0 }] },
29
31
  });
30
32
  let failure: unknown;
31
33
  // The cause travels with the close, so the flow's next request names it.
32
- worker.on('error', error => { failure = error; client.close(error); });
34
+ worker.on('error', onWorkerFailure('local-agent', error => { failure = error; client.close(error); }));
33
35
  await worker.attach();
34
36
  return {
35
37
  stream,