@psimona/darkf 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/concepts/failure-modes.md +5 -2
- package/docs/concepts/handoff.md +3 -3
- package/docs/concepts/node-types.md +40 -18
- package/docs/guides/pick-an-agent-runner.md +122 -4
- package/docs/guides/plan-with-a-task-queue.md +3 -2
- package/docs/guides/run-detached-and-monitor.md +3 -3
- package/docs/guides/write-your-first-workflow.md +6 -3
- package/docs/reference/cli-commands.md +22 -6
- package/docs/reference/core-types.md +24 -4
- package/docs/start-here/quickstart.md +3 -2
- package/package.json +1 -1
- package/skills/darkf-writing-workflows/SKILL.md +11 -2
- package/src/cli/detached.test.ts +88 -2
- package/src/cli/doctor.test.ts +224 -9
- package/src/cli/index.ts +81 -12
- package/src/core/graph.test.ts +124 -19
- package/src/core/graph.ts +51 -3
- package/src/core/types.ts +21 -0
- package/src/engine/run.test.ts +425 -17
- package/src/engine/run.ts +50 -7
- package/src/kit/agents/claude-code.test.ts +38 -2
- package/src/kit/agents/claude-code.ts +24 -3
- package/src/kit/agents/opencode.ts +30 -0
- package/src/kit/status.test.ts +24 -0
- package/src/kit/status.ts +25 -8
- package/workflows/series-ordering/workflow.ts +1 -0
package/src/engine/run.test.ts
CHANGED
|
@@ -32,9 +32,19 @@ test("runs a flat workflow to completion via on/next", async () => {
|
|
|
32
32
|
const workflow: WorkflowDef = {
|
|
33
33
|
initial: "Plan",
|
|
34
34
|
states: {
|
|
35
|
-
Plan: {
|
|
35
|
+
Plan: {
|
|
36
|
+
type: "agent",
|
|
37
|
+
agent: { model: "test-model" },
|
|
38
|
+
prompt: "plan",
|
|
39
|
+
on: { approved: "Build" },
|
|
40
|
+
},
|
|
36
41
|
Build: { type: "script", file: "build.ts", next: "Review" },
|
|
37
|
-
Review: {
|
|
42
|
+
Review: {
|
|
43
|
+
type: "agent",
|
|
44
|
+
agent: { model: "test-model" },
|
|
45
|
+
prompt: "review",
|
|
46
|
+
on: { done: EXIT, changes_requested: "Build" },
|
|
47
|
+
},
|
|
38
48
|
},
|
|
39
49
|
};
|
|
40
50
|
|
|
@@ -57,7 +67,12 @@ test("supports a cross-scope edge directly out of a composite", async () => {
|
|
|
57
67
|
const workflow: WorkflowDef = {
|
|
58
68
|
initial: "Plan",
|
|
59
69
|
states: {
|
|
60
|
-
Plan: {
|
|
70
|
+
Plan: {
|
|
71
|
+
type: "agent",
|
|
72
|
+
agent: { model: "test-model" },
|
|
73
|
+
prompt: "plan",
|
|
74
|
+
on: { approved: "Implement" },
|
|
75
|
+
},
|
|
61
76
|
Implement: {
|
|
62
77
|
initial: "Write",
|
|
63
78
|
states: {
|
|
@@ -65,7 +80,12 @@ test("supports a cross-scope edge directly out of a composite", async () => {
|
|
|
65
80
|
Test: { type: "script", file: "test.ts", on: { passed: "Review" } },
|
|
66
81
|
},
|
|
67
82
|
},
|
|
68
|
-
Review: {
|
|
83
|
+
Review: {
|
|
84
|
+
type: "agent",
|
|
85
|
+
agent: { model: "test-model" },
|
|
86
|
+
prompt: "review",
|
|
87
|
+
on: { done: EXIT },
|
|
88
|
+
},
|
|
69
89
|
},
|
|
70
90
|
};
|
|
71
91
|
|
|
@@ -93,7 +113,12 @@ test("supports re-entry into a leaf inside a different composite", async () => {
|
|
|
93
113
|
Test: { type: "script", file: "test.ts", on: { passed: "Review", failed: "Write" } },
|
|
94
114
|
},
|
|
95
115
|
},
|
|
96
|
-
Review: {
|
|
116
|
+
Review: {
|
|
117
|
+
type: "agent",
|
|
118
|
+
agent: { model: "test-model" },
|
|
119
|
+
prompt: "review",
|
|
120
|
+
on: { done: EXIT, changes_requested: "Write" },
|
|
121
|
+
},
|
|
97
122
|
},
|
|
98
123
|
};
|
|
99
124
|
|
|
@@ -586,6 +611,7 @@ test("threads agentSessionId and previousFailure into DispatchInfo across nudges
|
|
|
586
611
|
states: {
|
|
587
612
|
Agentic: {
|
|
588
613
|
type: "agent",
|
|
614
|
+
agent: { model: "test-model" },
|
|
589
615
|
prompt: "do it",
|
|
590
616
|
retries: 1,
|
|
591
617
|
on: { ok: EXIT },
|
|
@@ -637,6 +663,7 @@ test("threads step and rootDir into DispatchInfo, step constant across retries o
|
|
|
637
663
|
states: {
|
|
638
664
|
Plan: {
|
|
639
665
|
type: "agent",
|
|
666
|
+
agent: { model: "test-model" },
|
|
640
667
|
prompt: "plan",
|
|
641
668
|
retries: 1,
|
|
642
669
|
on: { approved: "Build" },
|
|
@@ -793,7 +820,9 @@ test("script nodes receive DispatchInfo (rootDir) as their second argument", asy
|
|
|
793
820
|
test("an agent runner's onProgress is folded into the running heartbeat as agentStepCount/agentIdleMs", async () => {
|
|
794
821
|
const workflow: WorkflowDef = {
|
|
795
822
|
initial: "Agentic",
|
|
796
|
-
states: {
|
|
823
|
+
states: {
|
|
824
|
+
Agentic: { type: "agent", agent: { model: "test-model" }, prompt: "go", next: EXIT },
|
|
825
|
+
},
|
|
797
826
|
};
|
|
798
827
|
const agentRunner: AgentRunner = {
|
|
799
828
|
run: async (_id, _def, _handoff, _info, onProgress) => {
|
|
@@ -854,7 +883,9 @@ test("open dispatches heartbeat the journal (live runtime)", async () => {
|
|
|
854
883
|
test("nudges a handoff-missing AgentFailure in-session, consuming no retry", async () => {
|
|
855
884
|
const workflow: WorkflowDef = {
|
|
856
885
|
initial: "Agentic",
|
|
857
|
-
states: {
|
|
886
|
+
states: {
|
|
887
|
+
Agentic: { type: "agent", agent: { model: "test-model" }, prompt: "do it", on: { ok: EXIT } },
|
|
888
|
+
},
|
|
858
889
|
};
|
|
859
890
|
|
|
860
891
|
const infos: DispatchInfo[] = [];
|
|
@@ -891,7 +922,9 @@ test("nudges a handoff-missing AgentFailure in-session, consuming no retry", asy
|
|
|
891
922
|
test("nudges no-transition when an unroutable event comes back in a returned NodeResult", async () => {
|
|
892
923
|
const workflow: WorkflowDef = {
|
|
893
924
|
initial: "Agentic",
|
|
894
|
-
states: {
|
|
925
|
+
states: {
|
|
926
|
+
Agentic: { type: "agent", agent: { model: "test-model" }, prompt: "do it", on: { ok: EXIT } },
|
|
927
|
+
},
|
|
895
928
|
};
|
|
896
929
|
|
|
897
930
|
const infos: DispatchInfo[] = [];
|
|
@@ -917,7 +950,15 @@ test("nudges no-transition when an unroutable event comes back in a returned Nod
|
|
|
917
950
|
test("exhausts the 3-nudge budget, then falls through and spends one def.retries slot", async () => {
|
|
918
951
|
const workflow: WorkflowDef = {
|
|
919
952
|
initial: "Agentic",
|
|
920
|
-
states: {
|
|
953
|
+
states: {
|
|
954
|
+
Agentic: {
|
|
955
|
+
type: "agent",
|
|
956
|
+
agent: { model: "test-model" },
|
|
957
|
+
prompt: "do it",
|
|
958
|
+
retries: 1,
|
|
959
|
+
on: { ok: EXIT },
|
|
960
|
+
},
|
|
961
|
+
},
|
|
921
962
|
};
|
|
922
963
|
|
|
923
964
|
const infos: DispatchInfo[] = [];
|
|
@@ -947,7 +988,9 @@ test("exhausts the 3-nudge budget, then falls through and spends one def.retries
|
|
|
947
988
|
test("a nudge that fails with runner-error ends the nudge loop without spending further nudges", async () => {
|
|
948
989
|
const workflow: WorkflowDef = {
|
|
949
990
|
initial: "Agentic",
|
|
950
|
-
states: {
|
|
991
|
+
states: {
|
|
992
|
+
Agentic: { type: "agent", agent: { model: "test-model" }, prompt: "do it", on: { ok: EXIT } },
|
|
993
|
+
},
|
|
951
994
|
};
|
|
952
995
|
|
|
953
996
|
let calls = 0;
|
|
@@ -976,7 +1019,9 @@ test("a nudge that fails with runner-error ends the nudge loop without spending
|
|
|
976
1019
|
test("nudge-start is emitted immediately with nudgeAttempt/nudgeReason, not gated behind a heartbeat", async () => {
|
|
977
1020
|
const workflow: WorkflowDef = {
|
|
978
1021
|
initial: "Agentic",
|
|
979
|
-
states: {
|
|
1022
|
+
states: {
|
|
1023
|
+
Agentic: { type: "agent", agent: { model: "test-model" }, prompt: "do it", on: { ok: EXIT } },
|
|
1024
|
+
},
|
|
980
1025
|
};
|
|
981
1026
|
|
|
982
1027
|
let calls = 0;
|
|
@@ -1010,7 +1055,15 @@ test("nudge-start is emitted immediately with nudgeAttempt/nudgeReason, not gate
|
|
|
1010
1055
|
test("a shared per-attempt deadline bounds the whole nudge sequence, not a fresh timeout per nudge", async () => {
|
|
1011
1056
|
const workflow: WorkflowDef = {
|
|
1012
1057
|
initial: "Agentic",
|
|
1013
|
-
states: {
|
|
1058
|
+
states: {
|
|
1059
|
+
Agentic: {
|
|
1060
|
+
type: "agent",
|
|
1061
|
+
agent: { model: "test-model" },
|
|
1062
|
+
prompt: "do it",
|
|
1063
|
+
timeoutMs: 100,
|
|
1064
|
+
on: { ok: EXIT },
|
|
1065
|
+
},
|
|
1066
|
+
},
|
|
1014
1067
|
};
|
|
1015
1068
|
|
|
1016
1069
|
let calls = 0;
|
|
@@ -1048,6 +1101,7 @@ test("a failing outputType nudges in-session with the message in previousFailure
|
|
|
1048
1101
|
states: {
|
|
1049
1102
|
Shaped: {
|
|
1050
1103
|
type: "agent",
|
|
1104
|
+
agent: { model: "test-model" },
|
|
1051
1105
|
prompt: "shape it",
|
|
1052
1106
|
retries: 1,
|
|
1053
1107
|
on: { ok: EXIT },
|
|
@@ -1101,6 +1155,7 @@ test("a failing validate nudges in-session with the script's message in previous
|
|
|
1101
1155
|
states: {
|
|
1102
1156
|
Picky: {
|
|
1103
1157
|
type: "agent",
|
|
1158
|
+
agent: { model: "test-model" },
|
|
1104
1159
|
prompt: "be good",
|
|
1105
1160
|
retries: 1,
|
|
1106
1161
|
on: { ok: EXIT },
|
|
@@ -1152,6 +1207,7 @@ test("regression: a validate-only leaf still rejects the same inputs, now nudgin
|
|
|
1152
1207
|
states: {
|
|
1153
1208
|
Picky: {
|
|
1154
1209
|
type: "agent",
|
|
1210
|
+
agent: { model: "test-model" },
|
|
1155
1211
|
prompt: "be good",
|
|
1156
1212
|
retries: 1,
|
|
1157
1213
|
on: { ok: EXIT },
|
|
@@ -1248,7 +1304,13 @@ test("a usage-limit failure waits the interval, then re-dispatches the SAME atte
|
|
|
1248
1304
|
const workflow: WorkflowDef = {
|
|
1249
1305
|
initial: "Agentic",
|
|
1250
1306
|
states: {
|
|
1251
|
-
Agentic: {
|
|
1307
|
+
Agentic: {
|
|
1308
|
+
type: "agent",
|
|
1309
|
+
agent: { model: "test-model" },
|
|
1310
|
+
prompt: "do it",
|
|
1311
|
+
usageLimitRetryMs: 100,
|
|
1312
|
+
on: { ok: EXIT },
|
|
1313
|
+
},
|
|
1252
1314
|
},
|
|
1253
1315
|
};
|
|
1254
1316
|
|
|
@@ -1284,7 +1346,13 @@ test("while waiting, running heartbeats carry limitBackoff (probe, nextAttemptAt
|
|
|
1284
1346
|
const workflow: WorkflowDef = {
|
|
1285
1347
|
initial: "Agentic",
|
|
1286
1348
|
states: {
|
|
1287
|
-
Agentic: {
|
|
1349
|
+
Agentic: {
|
|
1350
|
+
type: "agent",
|
|
1351
|
+
agent: { model: "test-model" },
|
|
1352
|
+
prompt: "do it",
|
|
1353
|
+
usageLimitRetryMs: 100,
|
|
1354
|
+
on: { ok: EXIT },
|
|
1355
|
+
},
|
|
1288
1356
|
},
|
|
1289
1357
|
};
|
|
1290
1358
|
|
|
@@ -1333,6 +1401,7 @@ test("exhausting usageLimitMaxWaitMs crashes with the last usage-limit reason; p
|
|
|
1333
1401
|
states: {
|
|
1334
1402
|
Agentic: {
|
|
1335
1403
|
type: "agent",
|
|
1404
|
+
agent: { model: "test-model" },
|
|
1336
1405
|
prompt: "do it",
|
|
1337
1406
|
usageLimitRetryMs: 50,
|
|
1338
1407
|
usageLimitMaxWaitMs: 120,
|
|
@@ -1386,6 +1455,7 @@ test("the attempt deadline is recomputed after each usage-limit wait, so a slept
|
|
|
1386
1455
|
states: {
|
|
1387
1456
|
Agentic: {
|
|
1388
1457
|
type: "agent",
|
|
1458
|
+
agent: { model: "test-model" },
|
|
1389
1459
|
prompt: "do it",
|
|
1390
1460
|
timeoutMs: 80,
|
|
1391
1461
|
usageLimitRetryMs: 50,
|
|
@@ -1422,7 +1492,7 @@ test("wraps an event-less agent result as { output: payload }", async () => {
|
|
|
1422
1492
|
const workflow: WorkflowDef = {
|
|
1423
1493
|
initial: "Work",
|
|
1424
1494
|
states: {
|
|
1425
|
-
Work: { type: "agent", prompt: "work", next: "Gate" },
|
|
1495
|
+
Work: { type: "agent", agent: { model: "test-model" }, prompt: "work", next: "Gate" },
|
|
1426
1496
|
Gate: { type: "script", file: "gate.ts", next: EXIT },
|
|
1427
1497
|
},
|
|
1428
1498
|
};
|
|
@@ -1449,7 +1519,7 @@ test("hybrid payload: flat claim plus nested output survives to handoff.output",
|
|
|
1449
1519
|
const workflow: WorkflowDef = {
|
|
1450
1520
|
initial: "Verify",
|
|
1451
1521
|
states: {
|
|
1452
|
-
Verify: { type: "agent", prompt: "verify", next: "Gate" },
|
|
1522
|
+
Verify: { type: "agent", agent: { model: "test-model" }, prompt: "verify", next: "Gate" },
|
|
1453
1523
|
Gate: { type: "script", file: "gate.ts", next: EXIT },
|
|
1454
1524
|
},
|
|
1455
1525
|
};
|
|
@@ -1481,7 +1551,7 @@ test("envelope results (event present) are passed through untouched", async () =
|
|
|
1481
1551
|
const workflow: WorkflowDef = {
|
|
1482
1552
|
initial: "Work",
|
|
1483
1553
|
states: {
|
|
1484
|
-
Work: { type: "agent", prompt: "work", on: { done: "Gate" } },
|
|
1554
|
+
Work: { type: "agent", agent: { model: "test-model" }, prompt: "work", on: { done: "Gate" } },
|
|
1485
1555
|
Gate: { type: "script", file: "gate.ts", next: EXIT },
|
|
1486
1556
|
},
|
|
1487
1557
|
};
|
|
@@ -1525,3 +1595,341 @@ test("script results are never coerced", async () => {
|
|
|
1525
1595
|
expect(result.node.phase).toBe("succeeded");
|
|
1526
1596
|
expect(seen).toEqual({ probe: 1 }); // raw handoff, not wrapped
|
|
1527
1597
|
});
|
|
1598
|
+
|
|
1599
|
+
// Records what each dispatch received, tagged with the stub runner that got it.
|
|
1600
|
+
function recordingRunner(
|
|
1601
|
+
tag: string,
|
|
1602
|
+
calls: { tag: string; id: string; agent: unknown; sessionId?: string }[],
|
|
1603
|
+
): AgentRunner {
|
|
1604
|
+
return {
|
|
1605
|
+
run: async (id, def, _handoff, info) => {
|
|
1606
|
+
calls.push({ tag, id, agent: def.agent, sessionId: info.agentSessionId });
|
|
1607
|
+
return {};
|
|
1608
|
+
},
|
|
1609
|
+
};
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
test("dispatches each state to the runner it resolves to, with that state's agent bag", async () => {
|
|
1613
|
+
const workflow: WorkflowDef = {
|
|
1614
|
+
initial: "Plan",
|
|
1615
|
+
states: {
|
|
1616
|
+
Plan: {
|
|
1617
|
+
type: "agent",
|
|
1618
|
+
prompt: "plan",
|
|
1619
|
+
runner: "other",
|
|
1620
|
+
agent: { model: "model-a" },
|
|
1621
|
+
next: "Build",
|
|
1622
|
+
},
|
|
1623
|
+
Build: { type: "agent", prompt: "build", agent: { model: "model-b" }, next: EXIT },
|
|
1624
|
+
},
|
|
1625
|
+
};
|
|
1626
|
+
const calls: Parameters<typeof recordingRunner>[1] = [];
|
|
1627
|
+
|
|
1628
|
+
const result = await run({
|
|
1629
|
+
workflow,
|
|
1630
|
+
agentRunner: recordingRunner("default", calls),
|
|
1631
|
+
agentRunners: { other: recordingRunner("other", calls) },
|
|
1632
|
+
});
|
|
1633
|
+
|
|
1634
|
+
expect(result.node.phase).toBe("succeeded");
|
|
1635
|
+
expect(calls).toMatchObject([
|
|
1636
|
+
{ tag: "other", id: "Plan", agent: { model: "model-a" } },
|
|
1637
|
+
{ tag: "default", id: "Build", agent: { model: "model-b" } },
|
|
1638
|
+
]);
|
|
1639
|
+
});
|
|
1640
|
+
|
|
1641
|
+
test("a workflow whose agent states all name a runner needs no agentRunner", async () => {
|
|
1642
|
+
const workflow: WorkflowDef = {
|
|
1643
|
+
initial: "Plan",
|
|
1644
|
+
states: {
|
|
1645
|
+
Plan: {
|
|
1646
|
+
type: "agent",
|
|
1647
|
+
agent: { model: "test-model" },
|
|
1648
|
+
prompt: "plan",
|
|
1649
|
+
runner: "other",
|
|
1650
|
+
next: EXIT,
|
|
1651
|
+
},
|
|
1652
|
+
},
|
|
1653
|
+
};
|
|
1654
|
+
|
|
1655
|
+
const result = await run({ workflow, agentRunners: { other: noopAgent } });
|
|
1656
|
+
|
|
1657
|
+
expect(result.node.phase).toBe("succeeded");
|
|
1658
|
+
});
|
|
1659
|
+
|
|
1660
|
+
test.each(["typo", "toString"])("runner %p never falls back to the default", async (name) => {
|
|
1661
|
+
const workflow: WorkflowDef = {
|
|
1662
|
+
initial: "Plan",
|
|
1663
|
+
states: {
|
|
1664
|
+
Plan: {
|
|
1665
|
+
type: "agent",
|
|
1666
|
+
agent: { model: "test-model" },
|
|
1667
|
+
prompt: "plan",
|
|
1668
|
+
runner: name,
|
|
1669
|
+
next: EXIT,
|
|
1670
|
+
},
|
|
1671
|
+
},
|
|
1672
|
+
};
|
|
1673
|
+
const calls: Parameters<typeof recordingRunner>[1] = [];
|
|
1674
|
+
|
|
1675
|
+
const result = await run({
|
|
1676
|
+
workflow,
|
|
1677
|
+
agentRunner: recordingRunner("default", calls),
|
|
1678
|
+
agentRunners: {},
|
|
1679
|
+
});
|
|
1680
|
+
|
|
1681
|
+
expect(result.node).toMatchObject({
|
|
1682
|
+
phase: "crashed",
|
|
1683
|
+
reason: {
|
|
1684
|
+
kind: "invalid-workflow",
|
|
1685
|
+
errors: [{ kind: "unknown-runner", state: "Plan", runner: name, known: [] }],
|
|
1686
|
+
},
|
|
1687
|
+
});
|
|
1688
|
+
expect(calls).toEqual([]);
|
|
1689
|
+
});
|
|
1690
|
+
|
|
1691
|
+
test("an unknown runner on a later state crashes before the first dispatch", async () => {
|
|
1692
|
+
const workflow: WorkflowDef = {
|
|
1693
|
+
initial: "Plan",
|
|
1694
|
+
states: {
|
|
1695
|
+
Plan: { type: "agent", agent: { model: "test-model" }, prompt: "p", next: "Build" },
|
|
1696
|
+
Build: {
|
|
1697
|
+
type: "agent",
|
|
1698
|
+
agent: { model: "test-model" },
|
|
1699
|
+
prompt: "p",
|
|
1700
|
+
runner: "typo",
|
|
1701
|
+
next: EXIT,
|
|
1702
|
+
},
|
|
1703
|
+
},
|
|
1704
|
+
};
|
|
1705
|
+
const calls: Parameters<typeof recordingRunner>[1] = [];
|
|
1706
|
+
const runner = recordingRunner("default", calls);
|
|
1707
|
+
|
|
1708
|
+
const result = await run({ workflow, agentRunner: runner, agentRunners: { other: runner } });
|
|
1709
|
+
|
|
1710
|
+
expect(result.node).toMatchObject({
|
|
1711
|
+
phase: "crashed",
|
|
1712
|
+
reason: {
|
|
1713
|
+
kind: "invalid-workflow",
|
|
1714
|
+
errors: [{ kind: "unknown-runner", state: "Build", runner: "typo", known: ["other"] }],
|
|
1715
|
+
},
|
|
1716
|
+
});
|
|
1717
|
+
expect(calls).toEqual([]);
|
|
1718
|
+
});
|
|
1719
|
+
|
|
1720
|
+
test("without a default runner, a state naming none crashes before any dispatch", async () => {
|
|
1721
|
+
const workflow: WorkflowDef = {
|
|
1722
|
+
initial: "Plan",
|
|
1723
|
+
states: {
|
|
1724
|
+
Plan: {
|
|
1725
|
+
type: "agent",
|
|
1726
|
+
agent: { model: "test-model" },
|
|
1727
|
+
prompt: "p",
|
|
1728
|
+
runner: "other",
|
|
1729
|
+
retries: 2,
|
|
1730
|
+
next: "Build",
|
|
1731
|
+
},
|
|
1732
|
+
Build: { type: "agent", agent: { model: "test-model" }, prompt: "p", retries: 2, next: EXIT },
|
|
1733
|
+
},
|
|
1734
|
+
};
|
|
1735
|
+
const calls: Parameters<typeof recordingRunner>[1] = [];
|
|
1736
|
+
|
|
1737
|
+
const result = await run({
|
|
1738
|
+
workflow,
|
|
1739
|
+
agentRunners: { other: recordingRunner("other", calls) },
|
|
1740
|
+
});
|
|
1741
|
+
|
|
1742
|
+
expect(result.node).toMatchObject({
|
|
1743
|
+
phase: "crashed",
|
|
1744
|
+
attempt: 0,
|
|
1745
|
+
reason: { kind: "invalid-workflow", errors: [{ kind: "missing-runner", state: "Build" }] },
|
|
1746
|
+
});
|
|
1747
|
+
expect(calls).toEqual([]);
|
|
1748
|
+
});
|
|
1749
|
+
|
|
1750
|
+
test("merges the workflow's agent bag under default-runner states only, without modifying the workflow", async () => {
|
|
1751
|
+
const shared = { model: "default-model", auto: true, extra: { a: 1 } };
|
|
1752
|
+
const workflow: WorkflowDef = {
|
|
1753
|
+
initial: "Inherit",
|
|
1754
|
+
agent: shared,
|
|
1755
|
+
states: {
|
|
1756
|
+
Inherit: { type: "agent", prompt: "p", next: "Override" },
|
|
1757
|
+
Override: {
|
|
1758
|
+
type: "agent",
|
|
1759
|
+
prompt: "p",
|
|
1760
|
+
agent: { model: "own-model", extra: { b: 2 } },
|
|
1761
|
+
next: "Named",
|
|
1762
|
+
},
|
|
1763
|
+
Named: {
|
|
1764
|
+
type: "agent",
|
|
1765
|
+
prompt: "p",
|
|
1766
|
+
runner: "same",
|
|
1767
|
+
agent: { model: "named-model" },
|
|
1768
|
+
next: EXIT,
|
|
1769
|
+
},
|
|
1770
|
+
},
|
|
1771
|
+
};
|
|
1772
|
+
const before = structuredClone(workflow);
|
|
1773
|
+
const calls: Parameters<typeof recordingRunner>[1] = [];
|
|
1774
|
+
// The named runner is the very same object as the default one.
|
|
1775
|
+
const runner = recordingRunner("same", calls);
|
|
1776
|
+
|
|
1777
|
+
const result = await run({ workflow, agentRunner: runner, agentRunners: { same: runner } });
|
|
1778
|
+
|
|
1779
|
+
expect(result.node.phase).toBe("succeeded");
|
|
1780
|
+
expect(calls.map((c) => c.agent)).toStrictEqual([
|
|
1781
|
+
shared,
|
|
1782
|
+
{ model: "own-model", auto: true, extra: { b: 2 } },
|
|
1783
|
+
{ model: "named-model" },
|
|
1784
|
+
]);
|
|
1785
|
+
expect(workflow).toStrictEqual(before);
|
|
1786
|
+
});
|
|
1787
|
+
|
|
1788
|
+
test("a runner writing to its def.agent reaches neither the workflow nor the next attempt", async () => {
|
|
1789
|
+
const workflow: WorkflowDef = {
|
|
1790
|
+
initial: "Plan",
|
|
1791
|
+
agent: { model: "default-model" },
|
|
1792
|
+
states: {
|
|
1793
|
+
Plan: {
|
|
1794
|
+
type: "agent",
|
|
1795
|
+
prompt: "p",
|
|
1796
|
+
runner: "other",
|
|
1797
|
+
agent: { model: "own" },
|
|
1798
|
+
retries: 1,
|
|
1799
|
+
next: EXIT,
|
|
1800
|
+
},
|
|
1801
|
+
},
|
|
1802
|
+
};
|
|
1803
|
+
const seen: unknown[] = [];
|
|
1804
|
+
const mutating: AgentRunner = {
|
|
1805
|
+
run: async (_id, def, _handoff, info) => {
|
|
1806
|
+
seen.push(def.agent?.model);
|
|
1807
|
+
if (def.agent) def.agent.model = "mutated";
|
|
1808
|
+
if (info.attempt === 1) throw new Error("boom");
|
|
1809
|
+
return {};
|
|
1810
|
+
},
|
|
1811
|
+
};
|
|
1812
|
+
|
|
1813
|
+
const result = await run({ workflow, agentRunners: { other: mutating } });
|
|
1814
|
+
|
|
1815
|
+
expect(result.node.phase).toBe("succeeded");
|
|
1816
|
+
expect(seen).toEqual(["own", "own"]);
|
|
1817
|
+
expect((workflow.states.Plan as { agent: unknown }).agent).toEqual({ model: "own" });
|
|
1818
|
+
});
|
|
1819
|
+
|
|
1820
|
+
test("a session id from one runner never reaches the next state's runner", async () => {
|
|
1821
|
+
const workflow: WorkflowDef = {
|
|
1822
|
+
initial: "Plan",
|
|
1823
|
+
states: {
|
|
1824
|
+
Plan: {
|
|
1825
|
+
type: "agent",
|
|
1826
|
+
agent: { model: "test-model" },
|
|
1827
|
+
prompt: "p",
|
|
1828
|
+
runner: "first",
|
|
1829
|
+
next: "Build",
|
|
1830
|
+
},
|
|
1831
|
+
Build: { type: "agent", agent: { model: "test-model" }, prompt: "p", next: EXIT },
|
|
1832
|
+
},
|
|
1833
|
+
};
|
|
1834
|
+
const calls: Parameters<typeof recordingRunner>[1] = [];
|
|
1835
|
+
|
|
1836
|
+
const result = await run({
|
|
1837
|
+
workflow,
|
|
1838
|
+
agentRunner: recordingRunner("default", calls),
|
|
1839
|
+
agentRunners: {
|
|
1840
|
+
first: { run: async () => ({ event: "planned", agentSessionId: "sess-first" }) },
|
|
1841
|
+
},
|
|
1842
|
+
});
|
|
1843
|
+
|
|
1844
|
+
expect(result.node.phase).toBe("succeeded");
|
|
1845
|
+
expect(result.trace[0]?.result.agentSessionId).toBe("sess-first");
|
|
1846
|
+
expect(calls).toMatchObject([{ id: "Build" }]);
|
|
1847
|
+
expect(calls[0]?.sessionId).toBeUndefined();
|
|
1848
|
+
});
|
|
1849
|
+
|
|
1850
|
+
test.each([undefined, "", 7])("a model of %p crashes before any dispatch", async (model) => {
|
|
1851
|
+
const workflow: WorkflowDef = {
|
|
1852
|
+
initial: "Plan",
|
|
1853
|
+
states: {
|
|
1854
|
+
Plan: { type: "agent", agent: { model: "test-model" }, prompt: "p", next: "Build" },
|
|
1855
|
+
Build: { type: "agent", agent: { model }, prompt: "p", retries: 2, next: EXIT },
|
|
1856
|
+
},
|
|
1857
|
+
};
|
|
1858
|
+
const calls: Parameters<typeof recordingRunner>[1] = [];
|
|
1859
|
+
|
|
1860
|
+
const result = await run({ workflow, agentRunner: recordingRunner("default", calls) });
|
|
1861
|
+
|
|
1862
|
+
expect(result.node).toMatchObject({
|
|
1863
|
+
phase: "crashed",
|
|
1864
|
+
attempt: 0,
|
|
1865
|
+
reason: { kind: "invalid-workflow", errors: [{ kind: "missing-model", state: "Build" }] },
|
|
1866
|
+
});
|
|
1867
|
+
expect(calls).toEqual([]);
|
|
1868
|
+
});
|
|
1869
|
+
|
|
1870
|
+
test("the default bag's model satisfies default-runner states only", async () => {
|
|
1871
|
+
const workflow: WorkflowDef = {
|
|
1872
|
+
initial: "Plan",
|
|
1873
|
+
agent: { model: "default-model" },
|
|
1874
|
+
states: {
|
|
1875
|
+
Plan: { type: "agent", prompt: "p", next: "Build" },
|
|
1876
|
+
Build: { type: "agent", prompt: "p", runner: "other", next: EXIT },
|
|
1877
|
+
},
|
|
1878
|
+
};
|
|
1879
|
+
const calls: Parameters<typeof recordingRunner>[1] = [];
|
|
1880
|
+
const runner = recordingRunner("same", calls);
|
|
1881
|
+
|
|
1882
|
+
const result = await run({ workflow, agentRunner: runner, agentRunners: { other: runner } });
|
|
1883
|
+
|
|
1884
|
+
expect(result.node).toMatchObject({
|
|
1885
|
+
phase: "crashed",
|
|
1886
|
+
reason: { kind: "invalid-workflow", errors: [{ kind: "missing-model", state: "Build" }] },
|
|
1887
|
+
});
|
|
1888
|
+
expect(calls).toEqual([]);
|
|
1889
|
+
});
|
|
1890
|
+
|
|
1891
|
+
test("every running status of an agent dispatch records the selected runner and its kind", async () => {
|
|
1892
|
+
const agent = { model: "test-model" };
|
|
1893
|
+
const workflow: WorkflowDef = {
|
|
1894
|
+
initial: "Default",
|
|
1895
|
+
states: {
|
|
1896
|
+
Default: { type: "agent", agent, prompt: "p", next: "Named" },
|
|
1897
|
+
Named: { type: "agent", agent, prompt: "p", runner: "claude", next: "Kindless" },
|
|
1898
|
+
Kindless: { type: "agent", agent, prompt: "p", runner: "custom", next: "BareDefault" },
|
|
1899
|
+
BareDefault: { type: "script", file: "a.ts", next: EXIT },
|
|
1900
|
+
},
|
|
1901
|
+
};
|
|
1902
|
+
const slow: AgentRunner["run"] = async () => {
|
|
1903
|
+
await new Promise((r) => setTimeout(r, 120));
|
|
1904
|
+
return {};
|
|
1905
|
+
};
|
|
1906
|
+
const events: NodeEvent[] = [];
|
|
1907
|
+
|
|
1908
|
+
const result = await run({
|
|
1909
|
+
workflow,
|
|
1910
|
+
agentRunner: { kind: "opencode", run: slow },
|
|
1911
|
+
agentRunners: { claude: { kind: "claude-code", run: slow }, custom: { run: slow } },
|
|
1912
|
+
scriptRunner: noopScript,
|
|
1913
|
+
heartbeatMs: 25,
|
|
1914
|
+
onEvent: (e) => events.push(e),
|
|
1915
|
+
});
|
|
1916
|
+
|
|
1917
|
+
expect(result.node.phase).toBe("succeeded");
|
|
1918
|
+
const recorded = (state: string) =>
|
|
1919
|
+
events.flatMap((e) =>
|
|
1920
|
+
e.state === state && e.status.phase === "running"
|
|
1921
|
+
? [{ runner: e.status.runner, runnerKind: e.status.runnerKind }]
|
|
1922
|
+
: [],
|
|
1923
|
+
);
|
|
1924
|
+
const expected = {
|
|
1925
|
+
Default: { runner: undefined, runnerKind: "opencode" },
|
|
1926
|
+
Named: { runner: "claude", runnerKind: "claude-code" },
|
|
1927
|
+
Kindless: { runner: "custom", runnerKind: undefined },
|
|
1928
|
+
};
|
|
1929
|
+
for (const [state, record] of Object.entries(expected)) {
|
|
1930
|
+
const statuses = recorded(state);
|
|
1931
|
+
expect(statuses.length).toBeGreaterThanOrEqual(2); // the open plus heartbeats
|
|
1932
|
+
for (const status of statuses) expect(status).toEqual(record);
|
|
1933
|
+
}
|
|
1934
|
+
expect(recorded("BareDefault")[0]).toEqual({ runner: undefined, runnerKind: undefined });
|
|
1935
|
+
});
|