@osolmaz/pi-workflows 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +182 -0
  3. package/dist/extension/executor.d.ts +58 -0
  4. package/dist/extension/executor.js +201 -0
  5. package/dist/extension/executor.js.map +1 -0
  6. package/dist/extension/index.d.ts +17 -0
  7. package/dist/extension/index.js +504 -0
  8. package/dist/extension/index.js.map +1 -0
  9. package/dist/extension/widget.d.ts +21 -0
  10. package/dist/extension/widget.js +142 -0
  11. package/dist/extension/widget.js.map +1 -0
  12. package/dist/render/ansi.d.ts +16 -0
  13. package/dist/render/ansi.js +42 -0
  14. package/dist/render/ansi.js.map +1 -0
  15. package/dist/render/canvas.d.ts +40 -0
  16. package/dist/render/canvas.js +177 -0
  17. package/dist/render/canvas.js.map +1 -0
  18. package/dist/render/format.d.ts +3 -0
  19. package/dist/render/format.js +17 -0
  20. package/dist/render/format.js.map +1 -0
  21. package/dist/render/graph-render.d.ts +22 -0
  22. package/dist/render/graph-render.js +520 -0
  23. package/dist/render/graph-render.js.map +1 -0
  24. package/dist/render/graph.d.ts +46 -0
  25. package/dist/render/graph.js +272 -0
  26. package/dist/render/graph.js.map +1 -0
  27. package/dist/viewer/cli.d.ts +10 -0
  28. package/dist/viewer/cli.js +132 -0
  29. package/dist/viewer/cli.js.map +1 -0
  30. package/dist/viewer/render.d.ts +19 -0
  31. package/dist/viewer/render.js +162 -0
  32. package/dist/viewer/render.js.map +1 -0
  33. package/dist/viewer/tui.d.ts +11 -0
  34. package/dist/viewer/tui.js +140 -0
  35. package/dist/viewer/tui.js.map +1 -0
  36. package/dist/viewer/watch.d.ts +9 -0
  37. package/dist/viewer/watch.js +46 -0
  38. package/dist/viewer/watch.js.map +1 -0
  39. package/dist/workflows/decision.d.ts +25 -0
  40. package/dist/workflows/decision.js +96 -0
  41. package/dist/workflows/decision.js.map +1 -0
  42. package/dist/workflows/definition.d.ts +9 -0
  43. package/dist/workflows/definition.js +61 -0
  44. package/dist/workflows/definition.js.map +1 -0
  45. package/dist/workflows/engine.d.ts +65 -0
  46. package/dist/workflows/engine.js +574 -0
  47. package/dist/workflows/engine.js.map +1 -0
  48. package/dist/workflows/errors.d.ts +9 -0
  49. package/dist/workflows/errors.js +24 -0
  50. package/dist/workflows/errors.js.map +1 -0
  51. package/dist/workflows/graph.d.ts +17 -0
  52. package/dist/workflows/graph.js +127 -0
  53. package/dist/workflows/graph.js.map +1 -0
  54. package/dist/workflows/index.d.ts +11 -0
  55. package/dist/workflows/index.js +11 -0
  56. package/dist/workflows/index.js.map +1 -0
  57. package/dist/workflows/json.d.ts +14 -0
  58. package/dist/workflows/json.js +134 -0
  59. package/dist/workflows/json.js.map +1 -0
  60. package/dist/workflows/loader.d.ts +28 -0
  61. package/dist/workflows/loader.js +94 -0
  62. package/dist/workflows/loader.js.map +1 -0
  63. package/dist/workflows/schema.d.ts +7 -0
  64. package/dist/workflows/schema.js +176 -0
  65. package/dist/workflows/schema.js.map +1 -0
  66. package/dist/workflows/shell.d.ts +9 -0
  67. package/dist/workflows/shell.js +177 -0
  68. package/dist/workflows/shell.js.map +1 -0
  69. package/dist/workflows/store.d.ts +35 -0
  70. package/dist/workflows/store.js +181 -0
  71. package/dist/workflows/store.js.map +1 -0
  72. package/dist/workflows/text.d.ts +10 -0
  73. package/dist/workflows/text.js +32 -0
  74. package/dist/workflows/text.js.map +1 -0
  75. package/dist/workflows/types.d.ts +280 -0
  76. package/dist/workflows/types.js +2 -0
  77. package/dist/workflows/types.js.map +1 -0
  78. package/docs/development.md +130 -0
  79. package/docs/run-bundles.md +114 -0
  80. package/docs/workflows.md +311 -0
  81. package/examples/workflows/autoimplement.workflow.ts +92 -0
  82. package/examples/workflows/autoresearch.workflow.ts +139 -0
  83. package/examples/workflows/branch.workflow.ts +63 -0
  84. package/examples/workflows/echo.workflow.ts +23 -0
  85. package/examples/workflows/elegant-solution.workflow.ts +95 -0
  86. package/examples/workflows/shell.workflow.ts +31 -0
  87. package/examples/workflows/two-turn.workflow.ts +64 -0
  88. package/package.json +80 -0
  89. package/src/extension/executor.ts +251 -0
  90. package/src/extension/index.ts +627 -0
  91. package/src/extension/widget.ts +183 -0
  92. package/src/render/ansi.ts +47 -0
  93. package/src/render/canvas.ts +196 -0
  94. package/src/render/format.ts +19 -0
  95. package/src/render/graph-render.ts +738 -0
  96. package/src/render/graph.ts +341 -0
  97. package/src/viewer/cli.ts +150 -0
  98. package/src/viewer/render.ts +236 -0
  99. package/src/viewer/tui.ts +159 -0
  100. package/src/viewer/watch.ts +55 -0
  101. package/src/workflows/decision.ts +127 -0
  102. package/src/workflows/definition.ts +104 -0
  103. package/src/workflows/engine.ts +793 -0
  104. package/src/workflows/errors.ts +27 -0
  105. package/src/workflows/graph.ts +161 -0
  106. package/src/workflows/index.ts +76 -0
  107. package/src/workflows/json.ts +155 -0
  108. package/src/workflows/loader.ts +123 -0
  109. package/src/workflows/schema.ts +218 -0
  110. package/src/workflows/shell.ts +199 -0
  111. package/src/workflows/store.ts +234 -0
  112. package/src/workflows/text.ts +34 -0
  113. package/src/workflows/types.ts +318 -0
@@ -0,0 +1,574 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { isDeepStrictEqual } from "node:util";
3
+ import { CancelledError, errorMessage, isAbortLikeError, TimeoutError } from "./errors.js";
4
+ import { resolveNext, resolveNextForOutcome, validateWorkflowDefinition } from "./graph.js";
5
+ import { extractJsonValue } from "./json.js";
6
+ import { runShellAction, shellResultFromError } from "./shell.js";
7
+ import { WorkflowRunStore, createRunId } from "./store.js";
8
+ const DEFAULT_NODE_TIMEOUT_MS = 15 * 60_000;
9
+ const DEFAULT_MAX_STEPS = 100;
10
+ const TITLE_TIMEOUT_MS = 30_000;
11
+ // Covers the shell SIGTERM → SIGKILL escalation (1s) plus stdio close.
12
+ const ABORT_CLEANUP_GRACE_MS = 2_000;
13
+ /**
14
+ * Executes a workflow graph step by step. Agent steps are delegated to the
15
+ * configured executor; compute/action/checkpoint nodes run inline. Every
16
+ * state transition is persisted to the run bundle before the engine moves on,
17
+ * so a live viewer can follow along by watching the bundle directory.
18
+ */
19
+ export class WorkflowEngine {
20
+ executor;
21
+ store;
22
+ defaultNodeTimeoutMs;
23
+ maxSteps;
24
+ onEvent;
25
+ activeAbort = null;
26
+ cancelled = false;
27
+ paused = false;
28
+ wakePause = null;
29
+ constructor(options) {
30
+ this.executor = options.executor;
31
+ this.store = new WorkflowRunStore(options.outputRoot);
32
+ this.defaultNodeTimeoutMs = options.defaultNodeTimeoutMs ?? DEFAULT_NODE_TIMEOUT_MS;
33
+ this.maxSteps = options.maxSteps ?? DEFAULT_MAX_STEPS;
34
+ this.onEvent = options.onEvent;
35
+ }
36
+ get outputRoot() {
37
+ return this.store.outputRoot;
38
+ }
39
+ /** Abort the currently running node and mark the run cancelled. */
40
+ cancel() {
41
+ this.cancelled = true;
42
+ this.activeAbort?.abort(new CancelledError());
43
+ // A run held at a pause boundary has no active node to abort; wake it so
44
+ // it can observe the cancellation.
45
+ this.wakePause?.();
46
+ }
47
+ /**
48
+ * Request a pause. The current step finishes normally; the engine then
49
+ * holds before dispatching the next node until `resume` (or `cancel`).
50
+ */
51
+ pause() {
52
+ this.paused = true;
53
+ }
54
+ /** Release a pause requested with `pause`. */
55
+ resume() {
56
+ this.paused = false;
57
+ this.wakePause?.();
58
+ }
59
+ /** True when a pause has been requested or the run is already held. */
60
+ get pauseRequested() {
61
+ return this.paused;
62
+ }
63
+ async run(workflow, input, options = {}) {
64
+ validateWorkflowDefinition(workflow);
65
+ // Fail before any bundle exists so bad input cannot leave a partial run
66
+ // on disk or silently change shape when state.json round-trips.
67
+ const normalizedInput = input === undefined ? null : input;
68
+ assertJsonSerializable(normalizedInput, "Workflow run input");
69
+ this.cancelled = false;
70
+ this.paused = false;
71
+ const state = await this.createRunState(workflow, normalizedInput, options.workflowPath);
72
+ const runDir = await this.store.initializeRunBundle(workflow, state);
73
+ await this.persist(runDir, state, {
74
+ scope: "run",
75
+ type: "run_started",
76
+ payload: {
77
+ workflowName: workflow.name,
78
+ ...(state.runTitle ? { runTitle: state.runTitle } : {}),
79
+ },
80
+ });
81
+ try {
82
+ await this.executeGraph(workflow, state, runDir);
83
+ }
84
+ catch (error) {
85
+ const cancelled = this.cancelled || isAbortLikeError(error);
86
+ await this.finishRun(runDir, state, cancelled ? "cancelled" : "failed", {
87
+ error: errorMessage(error),
88
+ });
89
+ return { runDir, state };
90
+ }
91
+ return { runDir, state };
92
+ }
93
+ /**
94
+ * Resolve the run title inside a cancellation and timeout boundary. This
95
+ * runs before any node abort controller exists, so without it a hung async
96
+ * `title` callback would leave the session permanently occupied.
97
+ */
98
+ async resolveTitleBounded(workflow, input) {
99
+ if (typeof workflow.title !== "function") {
100
+ return resolveRunTitle(workflow, input);
101
+ }
102
+ const abort = new AbortController();
103
+ this.activeAbort = abort;
104
+ const timer = setTimeout(() => abort.abort(new TimeoutError(TITLE_TIMEOUT_MS)), TITLE_TIMEOUT_MS);
105
+ try {
106
+ return await Promise.race([resolveRunTitle(workflow, input), abortRejection(abort.signal)]);
107
+ }
108
+ finally {
109
+ clearTimeout(timer);
110
+ this.activeAbort = null;
111
+ }
112
+ }
113
+ async createRunState(workflow, input, workflowPath) {
114
+ const now = new Date().toISOString();
115
+ return {
116
+ runId: createRunId(workflow.name),
117
+ workflowName: workflow.name,
118
+ ...(await this.resolveTitleBounded(workflow, input)),
119
+ ...(workflowPath !== undefined ? { workflowPath } : {}),
120
+ startedAt: now,
121
+ updatedAt: now,
122
+ status: "running",
123
+ input,
124
+ outputs: {},
125
+ results: {},
126
+ steps: [],
127
+ };
128
+ }
129
+ async executeGraph(workflow, state, runDir) {
130
+ const maxSteps = workflow.maxSteps ?? this.maxSteps;
131
+ let currentNodeId = workflow.startAt;
132
+ let executedSteps = 0;
133
+ let lastOutput;
134
+ while (currentNodeId !== null) {
135
+ await this.holdWhilePaused(state, runDir);
136
+ executedSteps += 1;
137
+ if (executedSteps > maxSteps) {
138
+ throw new Error(`Workflow exceeded maxSteps=${maxSteps}; aborting to avoid an unbounded loop`);
139
+ }
140
+ const node = workflow.nodes[currentNodeId];
141
+ if (!node) {
142
+ throw new Error(`Workflow node is missing: ${currentNodeId}`);
143
+ }
144
+ const attempt = await this.executeNode(workflow, state, runDir, currentNodeId, node);
145
+ this.recordAttempt(state, attempt);
146
+ await this.persist(runDir, state, {
147
+ scope: "node",
148
+ type: attempt.result.outcome === "ok" ? "node_finished" : "node_failed",
149
+ nodeId: attempt.result.nodeId,
150
+ attemptId: attempt.result.attemptId,
151
+ payload: {
152
+ outcome: attempt.result.outcome,
153
+ durationMs: attempt.result.durationMs,
154
+ ...(attempt.result.error !== undefined ? { error: attempt.result.error } : {}),
155
+ },
156
+ });
157
+ if (attempt.result.outcome !== "ok") {
158
+ currentNodeId = this.routeAfterFailure(workflow, state, attempt);
159
+ continue;
160
+ }
161
+ lastOutput = attempt.result.output;
162
+ if (node.nodeType === "checkpoint") {
163
+ await this.finishRun(runDir, state, "waiting", {
164
+ waitingOn: attempt.result.nodeId,
165
+ finalOutput: lastOutput,
166
+ });
167
+ return;
168
+ }
169
+ currentNodeId = resolveNext(workflow.edges, attempt.result.nodeId, attempt.result.output, attempt.result);
170
+ }
171
+ await this.finishRun(runDir, state, "completed", { finalOutput: lastOutput });
172
+ }
173
+ /**
174
+ * Hold the run at the step boundary while a pause is in effect. Pausing
175
+ * never interrupts a node mid-flight; it only delays the next dispatch.
176
+ */
177
+ async holdWhilePaused(state, runDir) {
178
+ if (this.cancelled) {
179
+ throw new CancelledError();
180
+ }
181
+ if (!this.paused) {
182
+ return;
183
+ }
184
+ state.paused = true;
185
+ await this.persist(runDir, state, { scope: "run", type: "run_paused", payload: {} });
186
+ while (this.paused && !this.cancelled) {
187
+ await new Promise((resolve) => {
188
+ this.wakePause = resolve;
189
+ });
190
+ }
191
+ this.wakePause = null;
192
+ delete state.paused;
193
+ if (this.cancelled) {
194
+ throw new CancelledError();
195
+ }
196
+ await this.persist(runDir, state, { scope: "run", type: "run_resumed", payload: {} });
197
+ }
198
+ routeAfterFailure(workflow, state, attempt) {
199
+ const next = resolveNextForOutcome(workflow.edges, attempt.result.nodeId, attempt.result);
200
+ if (next !== null) {
201
+ return next;
202
+ }
203
+ if (attempt.result.outcome === "cancelled" || this.cancelled) {
204
+ throw new CancelledError();
205
+ }
206
+ if (attempt.result.outcome === "timed_out") {
207
+ state.status = "timed_out";
208
+ }
209
+ throw attempt.error instanceof Error
210
+ ? attempt.error
211
+ : new Error(attempt.result.error ?? `Workflow node failed: ${attempt.result.nodeId}`);
212
+ }
213
+ recordAttempt(state, attempt) {
214
+ state.results[attempt.result.nodeId] = attempt.result;
215
+ if (attempt.result.outcome === "ok") {
216
+ state.outputs[attempt.result.nodeId] = attempt.result.output;
217
+ }
218
+ else {
219
+ // A failed repeat attempt supersedes an earlier success; stale output
220
+ // must not survive next to a non-ok latest result.
221
+ delete state.outputs[attempt.result.nodeId];
222
+ }
223
+ const step = {
224
+ attemptId: attempt.result.attemptId,
225
+ nodeId: attempt.result.nodeId,
226
+ nodeType: attempt.result.nodeType,
227
+ outcome: attempt.result.outcome,
228
+ startedAt: attempt.result.startedAt,
229
+ finishedAt: attempt.result.finishedAt,
230
+ promptText: attempt.execution?.promptText ?? null,
231
+ // `undefined` would drop the required field during JSON serialization.
232
+ output: attempt.result.output ?? null,
233
+ ...(attempt.result.error !== undefined ? { error: attempt.result.error } : {}),
234
+ ...(attempt.execution?.action !== undefined ? { action: attempt.execution.action } : {}),
235
+ };
236
+ state.steps.push(step);
237
+ delete state.currentNode;
238
+ delete state.currentAttemptId;
239
+ delete state.currentNodeType;
240
+ delete state.currentNodeStartedAt;
241
+ delete state.statusDetail;
242
+ }
243
+ async executeNode(workflow, state, runDir, nodeId, node) {
244
+ const attemptId = randomUUID();
245
+ const startedAt = new Date().toISOString();
246
+ state.currentNode = nodeId;
247
+ state.currentAttemptId = attemptId;
248
+ state.currentNodeType = node.nodeType;
249
+ state.currentNodeStartedAt = startedAt;
250
+ if (node.statusDetail !== undefined) {
251
+ state.statusDetail = node.statusDetail;
252
+ }
253
+ await this.persist(runDir, state, {
254
+ scope: "node",
255
+ type: "node_started",
256
+ nodeId,
257
+ attemptId,
258
+ payload: { nodeType: node.nodeType },
259
+ });
260
+ const meta = { promptText: null };
261
+ try {
262
+ const execution = await this.runNodeWithTimeout(workflow, state, runDir, nodeId, attemptId, node, meta);
263
+ return {
264
+ result: this.createNodeResult(nodeId, node, attemptId, startedAt, "ok", execution.output),
265
+ execution,
266
+ };
267
+ }
268
+ catch (error) {
269
+ const outcome = this.outcomeForError(error);
270
+ return {
271
+ result: {
272
+ ...this.createNodeResult(nodeId, node, attemptId, startedAt, outcome, undefined),
273
+ error: errorMessage(error),
274
+ },
275
+ // Keep whatever metadata the node produced before failing so the
276
+ // audit history retains the agent prompt and action receipt.
277
+ execution: {
278
+ output: null,
279
+ promptText: meta.promptText,
280
+ ...(meta.action !== undefined ? { action: meta.action } : {}),
281
+ },
282
+ error,
283
+ };
284
+ }
285
+ }
286
+ outcomeForError(error) {
287
+ if (error instanceof TimeoutError) {
288
+ return "timed_out";
289
+ }
290
+ if (this.cancelled || isAbortLikeError(error)) {
291
+ return "cancelled";
292
+ }
293
+ return "failed";
294
+ }
295
+ createNodeResult(nodeId, node, attemptId, startedAt, outcome, output) {
296
+ const finishedAt = new Date().toISOString();
297
+ return {
298
+ attemptId,
299
+ nodeId,
300
+ nodeType: node.nodeType,
301
+ outcome,
302
+ startedAt,
303
+ finishedAt,
304
+ durationMs: Date.parse(finishedAt) - Date.parse(startedAt),
305
+ ...(output !== undefined ? { output } : {}),
306
+ };
307
+ }
308
+ async runNodeWithTimeout(workflow, state, runDir, nodeId, attemptId, node, meta) {
309
+ const timeoutMs = node.timeoutMs ?? this.defaultNodeTimeoutMs;
310
+ const abort = new AbortController();
311
+ this.activeAbort = abort;
312
+ if (this.cancelled) {
313
+ throw new CancelledError();
314
+ }
315
+ const timer = setTimeout(() => {
316
+ abort.abort(new TimeoutError(timeoutMs));
317
+ }, timeoutMs);
318
+ const dispatched = this.dispatchNode(workflow, state, runDir, nodeId, attemptId, node, abort.signal, meta);
319
+ const dispatchSettled = dispatched.then(() => undefined, () => undefined);
320
+ try {
321
+ // Race the dispatch against the abort signal so timeouts and cancel
322
+ // take effect even for node callbacks that never observe the signal.
323
+ const execution = await Promise.race([dispatched, abortRejection(abort.signal)]);
324
+ if (execution.output === undefined) {
325
+ // JSON cannot represent undefined; normalize so the in-memory state
326
+ // matches what the persisted bundle round-trips to.
327
+ execution.output = null;
328
+ }
329
+ assertJsonSerializable(execution.output, `Node ${nodeId} output`);
330
+ return execution;
331
+ }
332
+ catch (error) {
333
+ if (node.nodeType === "action" && "exec" in node) {
334
+ // Give the killed shell command a short grace period to close so its
335
+ // action receipt lands in `meta` before the failed attempt persists.
336
+ await Promise.race([
337
+ dispatchSettled,
338
+ new Promise((resolve) => setTimeout(resolve, ABORT_CLEANUP_GRACE_MS)),
339
+ ]);
340
+ }
341
+ const reason = abort.signal.aborted ? abort.signal.reason : undefined;
342
+ throw reason instanceof TimeoutError || reason instanceof CancelledError ? reason : error;
343
+ }
344
+ finally {
345
+ clearTimeout(timer);
346
+ this.activeAbort = null;
347
+ }
348
+ }
349
+ async dispatchNode(workflow, state, runDir, nodeId, attemptId, node, signal, meta) {
350
+ const context = this.createNodeContext(state, signal);
351
+ switch (node.nodeType) {
352
+ case "agent":
353
+ return await this.runAgentNode(workflow, state, runDir, nodeId, attemptId, node, context, signal, meta);
354
+ case "compute":
355
+ return { output: await node.run(context), promptText: null };
356
+ case "action":
357
+ return await this.runActionNode(node, context, signal, meta);
358
+ case "checkpoint":
359
+ return await runCheckpointNode(node, context);
360
+ }
361
+ }
362
+ createNodeContext(state, signal) {
363
+ return {
364
+ input: state.input,
365
+ outputs: state.outputs,
366
+ results: state.results,
367
+ state,
368
+ signal,
369
+ };
370
+ }
371
+ async runAgentNode(workflow, state, runDir, nodeId, attemptId, node, context, signal, meta) {
372
+ const basePrompt = await node.prompt(context);
373
+ if (signal.aborted) {
374
+ // The node timed out or the run was cancelled while the async prompt
375
+ // builder ran; a late continuation must not write into a bundle that
376
+ // may already be terminal.
377
+ throw abortError(signal);
378
+ }
379
+ const prompt = appendStepContract(basePrompt, workflow.name, nodeId, attemptId, node.expectedOutput);
380
+ meta.promptText = prompt;
381
+ await this.persist(runDir, state, {
382
+ scope: "agent",
383
+ type: "agent_prompt_sent",
384
+ nodeId,
385
+ attemptId,
386
+ payload: { prompt },
387
+ });
388
+ const submission = await this.executor.runAgentStep({
389
+ contract: {
390
+ runId: state.runId,
391
+ workflowName: workflow.name,
392
+ nodeId,
393
+ attemptId,
394
+ ...(node.expectedOutput !== undefined ? { expectedOutput: node.expectedOutput } : {}),
395
+ },
396
+ prompt,
397
+ accept: async (output) => await this.acceptSubmission(node, context, output),
398
+ }, signal);
399
+ return { output: submission.output, promptText: prompt };
400
+ }
401
+ async acceptSubmission(node, context, output) {
402
+ try {
403
+ const normalized = normalizeAgentOutput(output);
404
+ const validated = node.validate ? await node.validate(normalized, context) : normalized;
405
+ const value = validated === undefined ? null : validated;
406
+ // Check here rather than after acceptance so a non-JSON validator
407
+ // result comes back as a validation error the model can retry.
408
+ assertJsonSerializable(value, "Step output");
409
+ return { ok: true, value };
410
+ }
411
+ catch (error) {
412
+ return { ok: false, error: errorMessage(error) };
413
+ }
414
+ }
415
+ async runActionNode(node, context, signal, meta) {
416
+ if ("exec" in node) {
417
+ return await runShellActionNode(node, context, signal, meta);
418
+ }
419
+ meta.action = { actionType: "function" };
420
+ const output = await node.run(context);
421
+ return { output, promptText: null, action: { actionType: "function" } };
422
+ }
423
+ async persist(runDir, state, event) {
424
+ const traceEvent = await this.store.writeSnapshot(runDir, state, event);
425
+ try {
426
+ this.onEvent?.(traceEvent, state);
427
+ }
428
+ catch {
429
+ // Observers (UI updates, loggers) must never determine workflow
430
+ // correctness; a throwing observer would otherwise fail the run.
431
+ }
432
+ }
433
+ async finishRun(runDir, state, status, fields) {
434
+ if (status === "failed" && state.status === "timed_out") {
435
+ status = "timed_out";
436
+ }
437
+ state.status = status;
438
+ state.finishedAt = new Date().toISOString();
439
+ if (fields.error !== undefined) {
440
+ state.error = fields.error;
441
+ }
442
+ if (fields.waitingOn !== undefined) {
443
+ state.waitingOn = fields.waitingOn;
444
+ }
445
+ if (fields.finalOutput !== undefined) {
446
+ state.finalOutput = fields.finalOutput;
447
+ }
448
+ delete state.currentNode;
449
+ delete state.currentAttemptId;
450
+ delete state.currentNodeType;
451
+ delete state.currentNodeStartedAt;
452
+ await this.persist(runDir, state, {
453
+ scope: "run",
454
+ type: `run_${status}`,
455
+ payload: {
456
+ status,
457
+ ...(fields.error !== undefined ? { error: fields.error } : {}),
458
+ ...(fields.waitingOn !== undefined ? { waitingOn: fields.waitingOn } : {}),
459
+ },
460
+ });
461
+ }
462
+ }
463
+ async function runCheckpointNode(node, context) {
464
+ const output = node.run ? await node.run(context) : { summary: node.summary ?? "checkpoint" };
465
+ return { output, promptText: null };
466
+ }
467
+ function shellReceipt(result) {
468
+ return {
469
+ actionType: "shell",
470
+ command: result.command,
471
+ args: result.args,
472
+ cwd: result.cwd,
473
+ exitCode: result.exitCode,
474
+ signal: result.signal,
475
+ durationMs: result.durationMs,
476
+ };
477
+ }
478
+ async function runShellActionNode(node, context, signal, meta) {
479
+ const spec = await node.exec(context);
480
+ let result;
481
+ try {
482
+ result = await runShellAction(spec, signal);
483
+ }
484
+ catch (error) {
485
+ const failed = shellResultFromError(error);
486
+ if (failed) {
487
+ meta.action = shellReceipt(failed);
488
+ }
489
+ throw error;
490
+ }
491
+ meta.action = shellReceipt(result);
492
+ const output = node.parse ? await node.parse(result, context) : result;
493
+ return { output, promptText: null, action: shellReceipt(result) };
494
+ }
495
+ /** Rejects with the abort reason once the signal fires; never resolves. */
496
+ /** The error carried by an aborted signal, normalized to an Error. */
497
+ function abortError(signal) {
498
+ const reason = signal.reason ?? new CancelledError();
499
+ return reason instanceof Error ? reason : new CancelledError(String(reason));
500
+ }
501
+ function abortRejection(signal) {
502
+ return new Promise((_resolve, reject) => {
503
+ const onAbort = () => {
504
+ reject(abortError(signal));
505
+ };
506
+ if (signal.aborted) {
507
+ onAbort();
508
+ return;
509
+ }
510
+ signal.addEventListener("abort", onAbort, { once: true });
511
+ });
512
+ }
513
+ /**
514
+ * Outputs are persisted to the run bundle, so they must be JSON-serializable.
515
+ * Failing here turns a bad callback return value into a normal node failure
516
+ * instead of corrupting the run state.
517
+ */
518
+ function assertJsonSerializable(value, what) {
519
+ let encoded;
520
+ try {
521
+ encoded = JSON.stringify(value);
522
+ }
523
+ catch (error) {
524
+ throw new Error(`${what} is non-JSON-serializable: ${errorMessage(error)}`);
525
+ }
526
+ if (encoded === undefined || !isDeepStrictEqual(JSON.parse(encoded), value)) {
527
+ throw new Error(`${what} does not survive a JSON round-trip. ` +
528
+ `Use plain JSON values (no functions, dates, NaN, or undefined properties).`);
529
+ }
530
+ }
531
+ /**
532
+ * Models occasionally submit the step output as a JSON-encoded string. Accept
533
+ * that by parsing tolerantly, falling back to the raw string.
534
+ */
535
+ function normalizeAgentOutput(output) {
536
+ if (typeof output !== "string") {
537
+ return output;
538
+ }
539
+ try {
540
+ return extractJsonValue(output);
541
+ }
542
+ catch {
543
+ return output;
544
+ }
545
+ }
546
+ /**
547
+ * The step contract appended to every agent-node prompt. This is the
548
+ * documented standard for how the model completes a workflow step.
549
+ */
550
+ export function appendStepContract(prompt, workflowName, nodeId, attemptId, expectedOutput) {
551
+ return [
552
+ prompt.trimEnd(),
553
+ "",
554
+ "---",
555
+ `Workflow step contract (workflow: ${workflowName}, step: ${nodeId}, attempt: ${attemptId})`,
556
+ "",
557
+ "Complete this step by calling the `workflow` tool exactly once with:",
558
+ `{"step": ${JSON.stringify(nodeId)}, "attempt": ${JSON.stringify(attemptId)}, "output": <your result>}`,
559
+ `Expected output: ${expectedOutput ?? "a JSON object with your result"}`,
560
+ "The step is complete only after the workflow tool accepts the output.",
561
+ "If the tool reports a validation error, correct the output and call it again.",
562
+ ].join("\n");
563
+ }
564
+ async function resolveRunTitle(workflow, input) {
565
+ if (typeof workflow.title === "string") {
566
+ return { runTitle: workflow.title };
567
+ }
568
+ if (typeof workflow.title === "function") {
569
+ const title = await workflow.title({ input, workflowName: workflow.name });
570
+ return title !== undefined ? { runTitle: title } : {};
571
+ }
572
+ return {};
573
+ }
574
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/workflows/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3F,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAqB3D,MAAM,uBAAuB,GAAG,EAAE,GAAG,MAAM,CAAC;AAC5C,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,uEAAuE;AACvE,MAAM,sBAAsB,GAAG,KAAK,CAAC;AAuBrC;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IACR,QAAQ,CAAoB;IAC5B,KAAK,CAAmB;IACxB,oBAAoB,CAAS;IAC7B,QAAQ,CAAS;IACjB,OAAO,CAAoC;IACpD,WAAW,GAA2B,IAAI,CAAC;IAC3C,SAAS,GAAG,KAAK,CAAC;IAClB,MAAM,GAAG,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,CAAC;IACD,IAAI,OAAO,QAAQ,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;QACzC,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QAC3E,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACxD,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
@@ -0,0 +1,9 @@
1
+ export declare class TimeoutError extends Error {
2
+ readonly timeoutMs: number;
3
+ constructor(timeoutMs: number);
4
+ }
5
+ export declare class CancelledError extends Error {
6
+ constructor(message?: string);
7
+ }
8
+ export declare function isAbortLikeError(error: unknown): boolean;
9
+ export declare function errorMessage(error: unknown): string;
@@ -0,0 +1,24 @@
1
+ export class TimeoutError extends Error {
2
+ timeoutMs;
3
+ constructor(timeoutMs) {
4
+ super(`Timed out after ${timeoutMs}ms`);
5
+ this.name = "TimeoutError";
6
+ this.timeoutMs = timeoutMs;
7
+ }
8
+ }
9
+ export class CancelledError extends Error {
10
+ constructor(message = "Workflow run was cancelled") {
11
+ super(message);
12
+ this.name = "CancelledError";
13
+ }
14
+ }
15
+ export function isAbortLikeError(error) {
16
+ return error instanceof CancelledError || (error instanceof Error && error.name === "AbortError");
17
+ }
18
+ export function errorMessage(error) {
19
+ if (error instanceof Error) {
20
+ return error.message;
21
+ }
22
+ return String(error);
23
+ }
24
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/workflows/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,SAAS,CAAS;IAE3B,YAAY,SAAiB;QAC3B,KAAK,CAAC,mBAAmB,SAAS,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAO,GAAG,4BAA4B;QAChD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,KAAK,YAAY,cAAc,IAAI,CAAC,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC;AACpG,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { WorkflowDefinition, WorkflowEdge, WorkflowNodeResult } from "./types.js";
2
+ /**
3
+ * Validate the full graph: shape, known start node, known edge targets, and
4
+ * at most one outgoing edge per node.
5
+ */
6
+ export declare function validateWorkflowDefinition(workflow: WorkflowDefinition): void;
7
+ /**
8
+ * Resolve the next node after `from` completed with `output`. Switch edges
9
+ * route on a JSON path into the output (`$.field` or `$output.field`) or the
10
+ * node result (`$result.outcome`).
11
+ */
12
+ export declare function resolveNext(edges: WorkflowEdge[], from: string, output: unknown, result?: WorkflowNodeResult): string | null;
13
+ /**
14
+ * Resolve routing for a failed node. Only `$result.` switch edges apply, so a
15
+ * workflow can explicitly route on outcomes like `failed` or `timed_out`.
16
+ */
17
+ export declare function resolveNextForOutcome(edges: WorkflowEdge[], from: string, result: WorkflowNodeResult): string | null;