@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.
- package/dist/agent-artifacts.d.ts.map +1 -1
- package/dist/agent-artifacts.js +2 -9
- package/dist/agent-artifacts.js.map +1 -1
- package/dist/agent-cwd.d.ts +69 -0
- package/dist/agent-cwd.d.ts.map +1 -0
- package/dist/agent-cwd.js +140 -0
- package/dist/agent-cwd.js.map +1 -0
- package/dist/artifact-scan-policy.d.ts +35 -0
- package/dist/artifact-scan-policy.d.ts.map +1 -0
- package/dist/artifact-scan-policy.js +49 -0
- package/dist/artifact-scan-policy.js.map +1 -0
- package/dist/authored-completion-record.d.ts +35 -0
- package/dist/authored-completion-record.d.ts.map +1 -0
- package/dist/authored-completion-record.js +92 -0
- package/dist/authored-completion-record.js.map +1 -0
- package/dist/authored-completion.d.ts +99 -0
- package/dist/authored-completion.d.ts.map +1 -0
- package/dist/authored-completion.js +184 -0
- package/dist/authored-completion.js.map +1 -0
- package/dist/authored-flow-error.d.ts +13 -1
- package/dist/authored-flow-error.d.ts.map +1 -1
- package/dist/authored-flow-error.js +12 -0
- package/dist/authored-flow-error.js.map +1 -1
- package/dist/authored-flow-executor.d.ts +7 -30
- package/dist/authored-flow-executor.d.ts.map +1 -1
- package/dist/authored-flow-executor.js +54 -47
- package/dist/authored-flow-executor.js.map +1 -1
- package/dist/authored-human.d.ts.map +1 -1
- package/dist/authored-human.js +1 -3
- package/dist/authored-human.js.map +1 -1
- package/dist/authored-node-entry.js +4 -1
- package/dist/authored-node-entry.js.map +1 -1
- package/dist/authored-node-runner.d.ts +9 -1
- package/dist/authored-node-runner.d.ts.map +1 -1
- package/dist/authored-node-runner.js +92 -17
- package/dist/authored-node-runner.js.map +1 -1
- package/dist/authored-root.d.ts +5 -0
- package/dist/authored-root.d.ts.map +1 -1
- package/dist/authored-root.js +20 -2
- package/dist/authored-root.js.map +1 -1
- package/dist/authored-step-output.d.ts +35 -10
- package/dist/authored-step-output.d.ts.map +1 -1
- package/dist/authored-step-output.js +108 -40
- package/dist/authored-step-output.js.map +1 -1
- package/dist/authored-verdict.d.ts +28 -0
- package/dist/authored-verdict.d.ts.map +1 -0
- package/dist/authored-verdict.js +79 -0
- package/dist/authored-verdict.js.map +1 -0
- package/dist/authored-worker-step.d.ts +5 -2
- package/dist/authored-worker-step.d.ts.map +1 -1
- package/dist/authored-worker-step.js +48 -11
- package/dist/authored-worker-step.js.map +1 -1
- package/dist/cli/check-worker-surface.d.ts +27 -0
- package/dist/cli/check-worker-surface.d.ts.map +1 -0
- package/dist/cli/check-worker-surface.js +63 -0
- package/dist/cli/check-worker-surface.js.map +1 -0
- package/dist/cli/check.d.ts +19 -2
- package/dist/cli/check.d.ts.map +1 -1
- package/dist/cli/check.js +12 -4
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/cloud-format.d.ts +9 -0
- package/dist/cli/cloud-format.d.ts.map +1 -0
- package/dist/cli/cloud-format.js +77 -0
- package/dist/cli/cloud-format.js.map +1 -0
- package/dist/cli/cloud-live.d.ts +39 -0
- package/dist/cli/cloud-live.d.ts.map +1 -0
- package/dist/cli/cloud-live.js +325 -0
- package/dist/cli/cloud-live.js.map +1 -0
- package/dist/cli/cloud-read.d.ts +3 -7
- package/dist/cli/cloud-read.d.ts.map +1 -1
- package/dist/cli/cloud-read.js +14 -266
- package/dist/cli/cloud-read.js.map +1 -1
- package/dist/cli/cloud-refusal.d.ts +39 -0
- package/dist/cli/cloud-refusal.d.ts.map +1 -0
- package/dist/cli/cloud-refusal.js +95 -0
- package/dist/cli/cloud-refusal.js.map +1 -0
- package/dist/cli/cloud-status-view.d.ts +7 -0
- package/dist/cli/cloud-status-view.d.ts.map +1 -0
- package/dist/cli/cloud-status-view.js +214 -0
- package/dist/cli/cloud-status-view.js.map +1 -0
- package/dist/cli/direct-run.d.ts.map +1 -1
- package/dist/cli/direct-run.js +16 -2
- package/dist/cli/direct-run.js.map +1 -1
- package/dist/cli/hn-monitor.d.ts +0 -13
- package/dist/cli/hn-monitor.d.ts.map +1 -1
- package/dist/cli/hn-monitor.js +2 -1
- package/dist/cli/hn-monitor.js.map +1 -1
- package/dist/cli/local-agent-remedy.d.ts +80 -0
- package/dist/cli/local-agent-remedy.d.ts.map +1 -0
- package/dist/cli/local-agent-remedy.js +116 -0
- package/dist/cli/local-agent-remedy.js.map +1 -0
- package/dist/cli/observer-session.d.ts +41 -0
- package/dist/cli/observer-session.d.ts.map +1 -0
- package/dist/cli/observer-session.js +78 -0
- package/dist/cli/observer-session.js.map +1 -0
- package/dist/cli/run.d.ts +30 -2
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +186 -24
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/status.d.ts +9 -0
- package/dist/cli/status.d.ts.map +1 -1
- package/dist/cli/status.js +31 -2
- package/dist/cli/status.js.map +1 -1
- package/dist/cli/step-evidence.d.ts +90 -0
- package/dist/cli/step-evidence.d.ts.map +1 -0
- package/dist/cli/step-evidence.js +259 -0
- package/dist/cli/step-evidence.js.map +1 -0
- package/dist/cli/step-failure.d.ts +14 -4
- package/dist/cli/step-failure.d.ts.map +1 -1
- package/dist/cli/step-failure.js +41 -76
- package/dist/cli/step-failure.js.map +1 -1
- package/dist/cli-commands.d.ts +6 -0
- package/dist/cli-commands.d.ts.map +1 -1
- package/dist/cli-commands.js +2 -0
- package/dist/cli-commands.js.map +1 -1
- package/dist/cli.d.ts +10 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +53 -42
- package/dist/cli.js.map +1 -1
- package/dist/cloud-read.d.ts +15 -0
- package/dist/cloud-read.d.ts.map +1 -1
- package/dist/cloud-read.js +20 -1
- package/dist/cloud-read.js.map +1 -1
- package/dist/cloud-run-record.d.ts +27 -0
- package/dist/cloud-run-record.d.ts.map +1 -0
- package/dist/cloud-run-record.js +56 -0
- package/dist/cloud-run-record.js.map +1 -0
- package/dist/cloud-run.d.ts +2 -9
- package/dist/cloud-run.d.ts.map +1 -1
- package/dist/cloud-run.js +3 -20
- package/dist/cloud-run.js.map +1 -1
- package/dist/communication/local.d.ts.map +1 -1
- package/dist/communication/local.js +2 -1
- package/dist/communication/local.js.map +1 -1
- package/dist/communication/worker.d.ts +1 -1
- package/dist/communication/worker.d.ts.map +1 -1
- package/dist/communication/worker.js +13 -5
- package/dist/communication/worker.js.map +1 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +28 -6
- package/dist/compile.js.map +1 -1
- package/dist/direct-input.d.ts.map +1 -1
- package/dist/direct-input.js +21 -1
- package/dist/direct-input.js.map +1 -1
- package/dist/failure-kinds.d.ts +96 -6
- package/dist/failure-kinds.d.ts.map +1 -1
- package/dist/failure-kinds.js +29 -2
- package/dist/failure-kinds.js.map +1 -1
- package/dist/flow-requirements.d.ts.map +1 -1
- package/dist/flow-requirements.js +24 -9
- package/dist/flow-requirements.js.map +1 -1
- package/dist/gate-contract.d.ts +7 -0
- package/dist/gate-contract.d.ts.map +1 -1
- package/dist/gate-contract.js +6 -1
- package/dist/gate-contract.js.map +1 -1
- package/dist/helper-preflight.d.ts.map +1 -1
- package/dist/helper-preflight.js +10 -3
- package/dist/helper-preflight.js.map +1 -1
- package/dist/helper-reference.d.ts +25 -0
- package/dist/helper-reference.d.ts.map +1 -0
- package/dist/helper-reference.js +129 -0
- package/dist/helper-reference.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/journal-client.d.ts +3 -1
- package/dist/journal-client.d.ts.map +1 -1
- package/dist/journal-client.js +17 -2
- package/dist/journal-client.js.map +1 -1
- package/dist/journal-projection.d.ts +16 -0
- package/dist/journal-projection.d.ts.map +1 -0
- package/dist/journal-projection.js +108 -0
- package/dist/journal-projection.js.map +1 -0
- package/dist/llm-worker.js +1 -1
- package/dist/llm-worker.js.map +1 -1
- package/dist/local-agent.d.ts +1 -1
- package/dist/local-agent.d.ts.map +1 -1
- package/dist/local-agent.js +4 -3
- package/dist/local-agent.js.map +1 -1
- package/dist/named-gate-lowering.js +35 -5
- package/dist/named-gate-lowering.js.map +1 -1
- package/dist/named-gate-preflight.d.ts +27 -0
- package/dist/named-gate-preflight.d.ts.map +1 -0
- package/dist/named-gate-preflight.js +47 -0
- package/dist/named-gate-preflight.js.map +1 -0
- package/dist/named-gates.d.ts +1 -1
- package/dist/named-gates.d.ts.map +1 -1
- package/dist/named-gates.js +3 -0
- package/dist/named-gates.js.map +1 -1
- package/dist/observer-link.d.ts +7 -0
- package/dist/observer-link.d.ts.map +1 -1
- package/dist/observer-link.js +3 -1
- package/dist/observer-link.js.map +1 -1
- package/dist/preflight.d.ts.map +1 -1
- package/dist/preflight.js +7 -0
- package/dist/preflight.js.map +1 -1
- package/dist/protocol.d.ts +2 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/redact.d.ts +42 -0
- package/dist/redact.d.ts.map +1 -1
- package/dist/redact.js +128 -0
- package/dist/redact.js.map +1 -1
- package/dist/run-projection.d.ts +83 -0
- package/dist/run-projection.d.ts.map +1 -0
- package/dist/run-projection.js +199 -0
- package/dist/run-projection.js.map +1 -0
- package/dist/shell-word.d.ts +19 -0
- package/dist/shell-word.d.ts.map +1 -0
- package/dist/shell-word.js +23 -0
- package/dist/shell-word.js.map +1 -0
- package/dist/spec.d.ts +52 -3
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js.map +1 -1
- package/dist/step-fields.d.ts +1 -1
- package/dist/step-fields.js +1 -1
- package/dist/step-fields.js.map +1 -1
- package/dist/steps-green.d.ts +27 -0
- package/dist/steps-green.d.ts.map +1 -0
- package/dist/steps-green.js +164 -0
- package/dist/steps-green.js.map +1 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +39 -8
- package/dist/validate.js.map +1 -1
- package/dist/worker-lease.d.ts +8 -1
- package/dist/worker-lease.d.ts.map +1 -1
- package/dist/worker-lease.js +34 -4
- package/dist/worker-lease.js.map +1 -1
- package/dist/worker.d.ts +8 -0
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +17 -9
- package/dist/worker.js.map +1 -1
- package/package.json +3 -7
- package/src/agent-artifacts.ts +2 -10
- package/src/agent-cwd.ts +139 -0
- package/src/artifact-scan-policy.ts +51 -0
- package/src/authored-completion-record.ts +119 -0
- package/src/authored-completion.ts +203 -0
- package/src/authored-flow-error.ts +13 -1
- package/src/authored-flow-executor.ts +91 -58
- package/src/authored-human.ts +1 -4
- package/src/authored-node-entry.ts +4 -1
- package/src/authored-node-runner.ts +96 -22
- package/src/authored-root.ts +20 -2
- package/src/authored-step-output.ts +139 -42
- package/src/authored-verdict.ts +87 -0
- package/src/authored-worker-step.ts +60 -12
- package/src/cli/check-worker-surface.ts +66 -0
- package/src/cli/check.ts +35 -4
- package/src/cli/cloud-format.ts +82 -0
- package/src/cli/cloud-live.ts +366 -0
- package/src/cli/cloud-read.ts +13 -282
- package/src/cli/cloud-refusal.ts +113 -0
- package/src/cli/cloud-status-view.ts +213 -0
- package/src/cli/direct-run.ts +19 -2
- package/src/cli/hn-monitor.ts +2 -1
- package/src/cli/local-agent-remedy.ts +160 -0
- package/src/cli/observer-session.ts +107 -0
- package/src/cli/run.ts +233 -28
- package/src/cli/status.ts +59 -3
- package/src/cli/step-evidence.ts +310 -0
- package/src/cli/step-failure.ts +57 -81
- package/src/cli-commands.ts +2 -0
- package/src/cli.ts +64 -44
- package/src/cloud-read.ts +25 -1
- package/src/cloud-run-record.ts +64 -0
- package/src/cloud-run.ts +5 -24
- package/src/communication/local.ts +2 -1
- package/src/communication/worker.ts +13 -5
- package/src/compile.ts +28 -6
- package/src/direct-input.ts +22 -1
- package/src/failure-kinds.ts +104 -2
- package/src/flow-requirements.ts +24 -9
- package/src/gate-contract.ts +13 -1
- package/src/helper-preflight.ts +10 -3
- package/src/helper-reference.ts +130 -0
- package/src/index.ts +2 -0
- package/src/journal-client.ts +19 -2
- package/src/journal-projection.ts +106 -0
- package/src/llm-worker.ts +1 -1
- package/src/local-agent.ts +4 -2
- package/src/named-gate-lowering.ts +35 -5
- package/src/named-gate-preflight.ts +47 -0
- package/src/named-gates.ts +3 -0
- package/src/observer-link.ts +10 -1
- package/src/preflight.ts +7 -0
- package/src/protocol.ts +2 -0
- package/src/redact.ts +111 -0
- package/src/run-projection.ts +247 -0
- package/src/shell-word.ts +24 -0
- package/src/spec.ts +54 -3
- package/src/step-fields.ts +1 -1
- package/src/steps-green.ts +168 -0
- package/src/validate.ts +35 -8
- package/src/worker-lease.ts +35 -5
- package/src/worker.ts +27 -11
package/src/failure-kinds.ts
CHANGED
|
@@ -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
|
-
/**
|
|
140
|
-
|
|
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. */
|
package/src/flow-requirements.ts
CHANGED
|
@@ -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
|
|
159
|
-
|
|
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 (
|
|
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
|
-
/**
|
|
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
|
-
|
|
225
|
-
|
|
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
|
-
/**
|
|
229
|
-
function
|
|
230
|
-
return
|
|
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
|
/**
|
package/src/gate-contract.ts
CHANGED
|
@@ -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
|
}
|
package/src/helper-preflight.ts
CHANGED
|
@@ -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(
|
|
12
|
-
|
|
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
|
-
|| (
|
|
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
package/src/journal-client.ts
CHANGED
|
@@ -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(
|
|
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
|
};
|
package/src/local-agent.ts
CHANGED
|
@@ -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,
|