@psimona/darkf 0.8.0 → 0.10.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 +13 -3
- package/docs/concepts/handoff.md +5 -1
- package/docs/concepts/node-types.md +7 -5
- package/docs/guides/pick-an-agent-runner.md +24 -3
- package/docs/guides/plan-with-a-task-queue.md +15 -0
- package/docs/guides/run-detached-and-monitor.md +2 -1
- package/docs/guides/write-your-first-workflow.md +19 -3
- package/docs/reference/cli-commands.md +19 -0
- package/docs/reference/core-types.md +17 -2
- package/docs/start-here/quickstart.md +19 -0
- package/package.json +1 -1
- package/skills/darkf-usage/SKILL.md +17 -0
- package/skills/darkf-writing-workflows/SKILL.md +16 -18
- package/src/cli/changelog.test.ts +44 -0
- package/src/cli/changelog.ts +26 -0
- package/src/cli/detached.test.ts +27 -5
- package/src/cli/doctor.test.ts +67 -8
- package/src/cli/help.test.ts +92 -0
- package/src/cli/help.ts +164 -0
- package/src/cli/index.ts +119 -3
- package/src/cli/tarball.test.ts +8 -2
- package/src/cli/update.test.ts +85 -17
- package/src/cli/update.ts +41 -7
- package/src/core/graph.test.ts +154 -13
- package/src/core/graph.ts +13 -3
- package/src/core/types.ts +21 -1
- package/src/engine/identity-guard.test.ts +47 -0
- package/src/engine/run.test.ts +268 -25
- package/src/engine/run.ts +4 -4
- package/src/kit/agents/handoff.ts +1 -1
- package/src/kit/agents/opencode.test.ts +89 -12
- package/src/kit/agents/opencode.ts +73 -8
- package/src/kit/registry.ts +5 -0
- package/src/kit/specs.test.ts +2 -2
- package/src/kit/specs.ts +3 -6
- package/src/test/ok-output.ts +11 -0
- package/workflows/dev-loop/output-types.ts +43 -0
- package/workflows/dev-loop/scripts/begin.ts +2 -2
- package/workflows/dev-loop/scripts/dispatch.ts +3 -5
- package/workflows/dev-loop/scripts/finish.ts +2 -36
- package/workflows/dev-loop/workflow.ts +26 -14
- package/workflows/series-ordering/output-types.ts +9 -0
- package/workflows/series-ordering/workflow.ts +3 -0
package/src/engine/run.test.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
type ScriptRunner,
|
|
15
15
|
type WorkflowDef,
|
|
16
16
|
} from "../core/index.ts";
|
|
17
|
+
import { okOutputType } from "../test/ok-output.ts";
|
|
17
18
|
import { run as engineRun, type RunOptions } from "./run.ts";
|
|
18
19
|
|
|
19
20
|
const noopAgent: AgentRunner = { run: async () => ({}) };
|
|
@@ -34,6 +35,7 @@ test("runs a flat workflow to completion via on/next", async () => {
|
|
|
34
35
|
states: {
|
|
35
36
|
Plan: {
|
|
36
37
|
type: "agent",
|
|
38
|
+
outputType: okOutputType,
|
|
37
39
|
agent: { model: "test-model" },
|
|
38
40
|
prompt: "plan",
|
|
39
41
|
on: { approved: "Build" },
|
|
@@ -41,6 +43,7 @@ test("runs a flat workflow to completion via on/next", async () => {
|
|
|
41
43
|
Build: { type: "script", file: "build.ts", next: "Review" },
|
|
42
44
|
Review: {
|
|
43
45
|
type: "agent",
|
|
46
|
+
outputType: okOutputType,
|
|
44
47
|
agent: { model: "test-model" },
|
|
45
48
|
prompt: "review",
|
|
46
49
|
on: { done: EXIT, changes_requested: "Build" },
|
|
@@ -69,6 +72,7 @@ test("supports a cross-scope edge directly out of a composite", async () => {
|
|
|
69
72
|
states: {
|
|
70
73
|
Plan: {
|
|
71
74
|
type: "agent",
|
|
75
|
+
outputType: okOutputType,
|
|
72
76
|
agent: { model: "test-model" },
|
|
73
77
|
prompt: "plan",
|
|
74
78
|
on: { approved: "Implement" },
|
|
@@ -82,6 +86,7 @@ test("supports a cross-scope edge directly out of a composite", async () => {
|
|
|
82
86
|
},
|
|
83
87
|
Review: {
|
|
84
88
|
type: "agent",
|
|
89
|
+
outputType: okOutputType,
|
|
85
90
|
agent: { model: "test-model" },
|
|
86
91
|
prompt: "review",
|
|
87
92
|
on: { done: EXIT },
|
|
@@ -115,6 +120,7 @@ test("supports re-entry into a leaf inside a different composite", async () => {
|
|
|
115
120
|
},
|
|
116
121
|
Review: {
|
|
117
122
|
type: "agent",
|
|
123
|
+
outputType: okOutputType,
|
|
118
124
|
agent: { model: "test-model" },
|
|
119
125
|
prompt: "review",
|
|
120
126
|
on: { done: EXIT, changes_requested: "Write" },
|
|
@@ -232,6 +238,31 @@ test("crashes eagerly with invalid-workflow for a composite initial-cycle, inste
|
|
|
232
238
|
}
|
|
233
239
|
});
|
|
234
240
|
|
|
241
|
+
test("crashes eagerly with invalid-workflow for an agent leaf without an outputType, before any dispatch", async () => {
|
|
242
|
+
const workflow: WorkflowDef = {
|
|
243
|
+
initial: "Solo",
|
|
244
|
+
states: { Solo: { type: "agent", agent: { model: "test-model" }, prompt: "p", next: EXIT } },
|
|
245
|
+
};
|
|
246
|
+
let calls = 0;
|
|
247
|
+
const agentRunner: AgentRunner = {
|
|
248
|
+
run: async () => {
|
|
249
|
+
calls++;
|
|
250
|
+
return {};
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const result = await run({ workflow, agentRunner, scriptRunner: noopScript });
|
|
255
|
+
|
|
256
|
+
expect(calls).toBe(0); // never dispatched — caught before the first enter()
|
|
257
|
+
expect(result.node.phase).toBe("crashed");
|
|
258
|
+
if (result.node.phase === "crashed") {
|
|
259
|
+
expect(result.node.reason).toEqual({
|
|
260
|
+
kind: "invalid-workflow",
|
|
261
|
+
errors: [{ kind: "missing-output-type", state: "Solo" }],
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
235
266
|
test("crashes with a duplicate-id reason instead of throwing", async () => {
|
|
236
267
|
const workflow: WorkflowDef = {
|
|
237
268
|
initial: "A",
|
|
@@ -611,6 +642,7 @@ test("threads agentSessionId and previousFailure into DispatchInfo across nudges
|
|
|
611
642
|
states: {
|
|
612
643
|
Agentic: {
|
|
613
644
|
type: "agent",
|
|
645
|
+
outputType: okOutputType,
|
|
614
646
|
agent: { model: "test-model" },
|
|
615
647
|
prompt: "do it",
|
|
616
648
|
retries: 1,
|
|
@@ -638,7 +670,7 @@ test("threads agentSessionId and previousFailure into DispatchInfo across nudges
|
|
|
638
670
|
previousFailure: undefined,
|
|
639
671
|
});
|
|
640
672
|
// A validate rejection with a session nudges in-session (up to three,
|
|
641
|
-
// docs/specs/output-validation): the attempt stays 1 while previousFailure
|
|
673
|
+
// docs/specs/_built/output-validation): the attempt stays 1 while previousFailure
|
|
642
674
|
// and the carried session id thread through every nudge dispatch.
|
|
643
675
|
expect(infos).toHaveLength(5); // fresh + 3 nudges + the capped fallback
|
|
644
676
|
for (const info of infos.slice(1, 4)) {
|
|
@@ -663,6 +695,7 @@ test("threads step and rootDir into DispatchInfo, step constant across retries o
|
|
|
663
695
|
states: {
|
|
664
696
|
Plan: {
|
|
665
697
|
type: "agent",
|
|
698
|
+
outputType: okOutputType,
|
|
666
699
|
agent: { model: "test-model" },
|
|
667
700
|
prompt: "plan",
|
|
668
701
|
retries: 1,
|
|
@@ -821,7 +854,13 @@ test("an agent runner's onProgress is folded into the running heartbeat as agent
|
|
|
821
854
|
const workflow: WorkflowDef = {
|
|
822
855
|
initial: "Agentic",
|
|
823
856
|
states: {
|
|
824
|
-
Agentic: {
|
|
857
|
+
Agentic: {
|
|
858
|
+
type: "agent",
|
|
859
|
+
outputType: okOutputType,
|
|
860
|
+
agent: { model: "test-model" },
|
|
861
|
+
prompt: "go",
|
|
862
|
+
next: EXIT,
|
|
863
|
+
},
|
|
825
864
|
},
|
|
826
865
|
};
|
|
827
866
|
const agentRunner: AgentRunner = {
|
|
@@ -884,7 +923,13 @@ test("nudges a handoff-missing AgentFailure in-session, consuming no retry", asy
|
|
|
884
923
|
const workflow: WorkflowDef = {
|
|
885
924
|
initial: "Agentic",
|
|
886
925
|
states: {
|
|
887
|
-
Agentic: {
|
|
926
|
+
Agentic: {
|
|
927
|
+
type: "agent",
|
|
928
|
+
outputType: okOutputType,
|
|
929
|
+
agent: { model: "test-model" },
|
|
930
|
+
prompt: "do it",
|
|
931
|
+
on: { ok: EXIT },
|
|
932
|
+
},
|
|
888
933
|
},
|
|
889
934
|
};
|
|
890
935
|
|
|
@@ -919,11 +964,104 @@ test("nudges a handoff-missing AgentFailure in-session, consuming no retry", asy
|
|
|
919
964
|
});
|
|
920
965
|
});
|
|
921
966
|
|
|
967
|
+
// --- runner-failure-identity (docs/specs/_built/runner-failure-identity/spec.md) ---
|
|
968
|
+
|
|
969
|
+
// A workflow outside the package loads its runner from its own copy of the
|
|
970
|
+
// package, so the `AgentFailure` it throws is not an instance of the engine's
|
|
971
|
+
// class. A query string on the specifier gives a second module instance in one
|
|
972
|
+
// process, which is the same situation.
|
|
973
|
+
async function secondCopyOfAgentFailure(): Promise<typeof AgentFailure> {
|
|
974
|
+
const copy = (await import(`../core/types.ts?copy=${Math.random()}`)) as {
|
|
975
|
+
AgentFailure: typeof AgentFailure;
|
|
976
|
+
};
|
|
977
|
+
expect(copy.AgentFailure).not.toBe(AgentFailure);
|
|
978
|
+
return copy.AgentFailure;
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
test("nudges an AgentFailure whose class comes from a second module copy", async () => {
|
|
982
|
+
const OtherAgentFailure = await secondCopyOfAgentFailure();
|
|
983
|
+
const workflow: WorkflowDef = {
|
|
984
|
+
initial: "Agentic",
|
|
985
|
+
states: {
|
|
986
|
+
Agentic: {
|
|
987
|
+
type: "agent",
|
|
988
|
+
outputType: okOutputType,
|
|
989
|
+
agent: { model: "test-model" },
|
|
990
|
+
prompt: "do it",
|
|
991
|
+
on: { ok: EXIT },
|
|
992
|
+
},
|
|
993
|
+
},
|
|
994
|
+
};
|
|
995
|
+
|
|
996
|
+
const infos: DispatchInfo[] = [];
|
|
997
|
+
const agentRunner: AgentRunner = {
|
|
998
|
+
run: async (_id, _def, _handoff, info) => {
|
|
999
|
+
infos.push(info);
|
|
1000
|
+
if (infos.length === 1) {
|
|
1001
|
+
throw new OtherAgentFailure("handoff not written", {
|
|
1002
|
+
agentSessionId: "sess-1",
|
|
1003
|
+
crashReason: { kind: "handoff-missing" },
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
return { event: "ok" };
|
|
1007
|
+
},
|
|
1008
|
+
};
|
|
1009
|
+
|
|
1010
|
+
const result = await run({ workflow, agentRunner, scriptRunner: noopScript });
|
|
1011
|
+
|
|
1012
|
+
// Same outcome as the single-copy test above: nudged in-session, no retry spent.
|
|
1013
|
+
expect(result.node.phase).toBe("succeeded");
|
|
1014
|
+
expect(infos.length).toBe(2);
|
|
1015
|
+
expect(infos[1]).toMatchObject({
|
|
1016
|
+
attempt: 1,
|
|
1017
|
+
agentSessionId: "sess-1",
|
|
1018
|
+
previousFailure: { kind: "handoff-missing" },
|
|
1019
|
+
});
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
test("records the crash reason of an AgentFailure from a second module copy", async () => {
|
|
1023
|
+
const OtherAgentFailure = await secondCopyOfAgentFailure();
|
|
1024
|
+
const workflow: WorkflowDef = {
|
|
1025
|
+
initial: "Agentic",
|
|
1026
|
+
states: {
|
|
1027
|
+
Agentic: {
|
|
1028
|
+
type: "agent",
|
|
1029
|
+
outputType: okOutputType,
|
|
1030
|
+
agent: { model: "test-model" },
|
|
1031
|
+
prompt: "do it",
|
|
1032
|
+
retries: 0,
|
|
1033
|
+
on: { ok: EXIT },
|
|
1034
|
+
},
|
|
1035
|
+
},
|
|
1036
|
+
};
|
|
1037
|
+
const agentRunner: AgentRunner = {
|
|
1038
|
+
run: async () => {
|
|
1039
|
+
throw new OtherAgentFailure("boom", {
|
|
1040
|
+
agentSessionId: "sess-9",
|
|
1041
|
+
crashReason: { kind: "handoff-unparseable", parseError: "bad json" },
|
|
1042
|
+
});
|
|
1043
|
+
},
|
|
1044
|
+
};
|
|
1045
|
+
|
|
1046
|
+
const result = await run({ workflow, agentRunner, scriptRunner: noopScript });
|
|
1047
|
+
|
|
1048
|
+
expect(result.node).toMatchObject({
|
|
1049
|
+
phase: "crashed",
|
|
1050
|
+
reason: { kind: "handoff-unparseable", parseError: "bad json" },
|
|
1051
|
+
});
|
|
1052
|
+
});
|
|
1053
|
+
|
|
922
1054
|
test("nudges no-transition when an unroutable event comes back in a returned NodeResult", async () => {
|
|
923
1055
|
const workflow: WorkflowDef = {
|
|
924
1056
|
initial: "Agentic",
|
|
925
1057
|
states: {
|
|
926
|
-
Agentic: {
|
|
1058
|
+
Agentic: {
|
|
1059
|
+
type: "agent",
|
|
1060
|
+
outputType: okOutputType,
|
|
1061
|
+
agent: { model: "test-model" },
|
|
1062
|
+
prompt: "do it",
|
|
1063
|
+
on: { ok: EXIT },
|
|
1064
|
+
},
|
|
927
1065
|
},
|
|
928
1066
|
};
|
|
929
1067
|
|
|
@@ -953,6 +1091,7 @@ test("exhausts the 3-nudge budget, then falls through and spends one def.retries
|
|
|
953
1091
|
states: {
|
|
954
1092
|
Agentic: {
|
|
955
1093
|
type: "agent",
|
|
1094
|
+
outputType: okOutputType,
|
|
956
1095
|
agent: { model: "test-model" },
|
|
957
1096
|
prompt: "do it",
|
|
958
1097
|
retries: 1,
|
|
@@ -989,7 +1128,13 @@ test("a nudge that fails with runner-error ends the nudge loop without spending
|
|
|
989
1128
|
const workflow: WorkflowDef = {
|
|
990
1129
|
initial: "Agentic",
|
|
991
1130
|
states: {
|
|
992
|
-
Agentic: {
|
|
1131
|
+
Agentic: {
|
|
1132
|
+
type: "agent",
|
|
1133
|
+
outputType: okOutputType,
|
|
1134
|
+
agent: { model: "test-model" },
|
|
1135
|
+
prompt: "do it",
|
|
1136
|
+
on: { ok: EXIT },
|
|
1137
|
+
},
|
|
993
1138
|
},
|
|
994
1139
|
};
|
|
995
1140
|
|
|
@@ -1020,7 +1165,13 @@ test("nudge-start is emitted immediately with nudgeAttempt/nudgeReason, not gate
|
|
|
1020
1165
|
const workflow: WorkflowDef = {
|
|
1021
1166
|
initial: "Agentic",
|
|
1022
1167
|
states: {
|
|
1023
|
-
Agentic: {
|
|
1168
|
+
Agentic: {
|
|
1169
|
+
type: "agent",
|
|
1170
|
+
outputType: okOutputType,
|
|
1171
|
+
agent: { model: "test-model" },
|
|
1172
|
+
prompt: "do it",
|
|
1173
|
+
on: { ok: EXIT },
|
|
1174
|
+
},
|
|
1024
1175
|
},
|
|
1025
1176
|
};
|
|
1026
1177
|
|
|
@@ -1058,6 +1209,7 @@ test("a shared per-attempt deadline bounds the whole nudge sequence, not a fresh
|
|
|
1058
1209
|
states: {
|
|
1059
1210
|
Agentic: {
|
|
1060
1211
|
type: "agent",
|
|
1212
|
+
outputType: okOutputType,
|
|
1061
1213
|
agent: { model: "test-model" },
|
|
1062
1214
|
prompt: "do it",
|
|
1063
1215
|
timeoutMs: 100,
|
|
@@ -1093,7 +1245,7 @@ test("a shared per-attempt deadline bounds the whole nudge sequence, not a fresh
|
|
|
1093
1245
|
}
|
|
1094
1246
|
});
|
|
1095
1247
|
|
|
1096
|
-
// --- output-validation (docs/specs/output-validation/spec.md) ---
|
|
1248
|
+
// --- output-validation (docs/specs/_built/output-validation/spec.md) ---
|
|
1097
1249
|
|
|
1098
1250
|
test("a failing outputType nudges in-session with the message in previousFailure, capped at three before the fresh retry", async () => {
|
|
1099
1251
|
const workflow: WorkflowDef = {
|
|
@@ -1155,6 +1307,7 @@ test("a failing validate nudges in-session with the script's message in previous
|
|
|
1155
1307
|
states: {
|
|
1156
1308
|
Picky: {
|
|
1157
1309
|
type: "agent",
|
|
1310
|
+
outputType: okOutputType,
|
|
1158
1311
|
agent: { model: "test-model" },
|
|
1159
1312
|
prompt: "be good",
|
|
1160
1313
|
retries: 1,
|
|
@@ -1195,7 +1348,7 @@ test("a failing validate nudges in-session with the script's message in previous
|
|
|
1195
1348
|
|
|
1196
1349
|
test("regression: a validate-only leaf still rejects the same inputs, now nudging before it retries", async () => {
|
|
1197
1350
|
// The Compatibility contract, checked directly
|
|
1198
|
-
// (docs/specs/output-validation/spec.md): a leaf with `validate` and no
|
|
1351
|
+
// (docs/specs/_built/output-validation/spec.md): a leaf with `validate` and no
|
|
1199
1352
|
// `outputType` — the pre-spec shape — rejects the same inputs with the
|
|
1200
1353
|
// same message and ends in the same `validation-failed` crash shape as
|
|
1201
1354
|
// before. Only the path there changed: with a session, up to three
|
|
@@ -1207,6 +1360,7 @@ test("regression: a validate-only leaf still rejects the same inputs, now nudgin
|
|
|
1207
1360
|
states: {
|
|
1208
1361
|
Picky: {
|
|
1209
1362
|
type: "agent",
|
|
1363
|
+
outputType: okOutputType,
|
|
1210
1364
|
agent: { model: "test-model" },
|
|
1211
1365
|
prompt: "be good",
|
|
1212
1366
|
retries: 1,
|
|
@@ -1306,6 +1460,7 @@ test("a usage-limit failure waits the interval, then re-dispatches the SAME atte
|
|
|
1306
1460
|
states: {
|
|
1307
1461
|
Agentic: {
|
|
1308
1462
|
type: "agent",
|
|
1463
|
+
outputType: okOutputType,
|
|
1309
1464
|
agent: { model: "test-model" },
|
|
1310
1465
|
prompt: "do it",
|
|
1311
1466
|
usageLimitRetryMs: 100,
|
|
@@ -1348,6 +1503,7 @@ test("while waiting, running heartbeats carry limitBackoff (probe, nextAttemptAt
|
|
|
1348
1503
|
states: {
|
|
1349
1504
|
Agentic: {
|
|
1350
1505
|
type: "agent",
|
|
1506
|
+
outputType: okOutputType,
|
|
1351
1507
|
agent: { model: "test-model" },
|
|
1352
1508
|
prompt: "do it",
|
|
1353
1509
|
usageLimitRetryMs: 100,
|
|
@@ -1401,6 +1557,7 @@ test("exhausting usageLimitMaxWaitMs crashes with the last usage-limit reason; p
|
|
|
1401
1557
|
states: {
|
|
1402
1558
|
Agentic: {
|
|
1403
1559
|
type: "agent",
|
|
1560
|
+
outputType: okOutputType,
|
|
1404
1561
|
agent: { model: "test-model" },
|
|
1405
1562
|
prompt: "do it",
|
|
1406
1563
|
usageLimitRetryMs: 50,
|
|
@@ -1455,6 +1612,7 @@ test("the attempt deadline is recomputed after each usage-limit wait, so a slept
|
|
|
1455
1612
|
states: {
|
|
1456
1613
|
Agentic: {
|
|
1457
1614
|
type: "agent",
|
|
1615
|
+
outputType: okOutputType,
|
|
1458
1616
|
agent: { model: "test-model" },
|
|
1459
1617
|
prompt: "do it",
|
|
1460
1618
|
timeoutMs: 80,
|
|
@@ -1492,7 +1650,13 @@ test("wraps an event-less agent result as { output: payload }", async () => {
|
|
|
1492
1650
|
const workflow: WorkflowDef = {
|
|
1493
1651
|
initial: "Work",
|
|
1494
1652
|
states: {
|
|
1495
|
-
Work: {
|
|
1653
|
+
Work: {
|
|
1654
|
+
type: "agent",
|
|
1655
|
+
outputType: okOutputType,
|
|
1656
|
+
agent: { model: "test-model" },
|
|
1657
|
+
prompt: "work",
|
|
1658
|
+
next: "Gate",
|
|
1659
|
+
},
|
|
1496
1660
|
Gate: { type: "script", file: "gate.ts", next: EXIT },
|
|
1497
1661
|
},
|
|
1498
1662
|
};
|
|
@@ -1519,7 +1683,13 @@ test("hybrid payload: flat claim plus nested output survives to handoff.output",
|
|
|
1519
1683
|
const workflow: WorkflowDef = {
|
|
1520
1684
|
initial: "Verify",
|
|
1521
1685
|
states: {
|
|
1522
|
-
Verify: {
|
|
1686
|
+
Verify: {
|
|
1687
|
+
type: "agent",
|
|
1688
|
+
outputType: okOutputType,
|
|
1689
|
+
agent: { model: "test-model" },
|
|
1690
|
+
prompt: "verify",
|
|
1691
|
+
next: "Gate",
|
|
1692
|
+
},
|
|
1523
1693
|
Gate: { type: "script", file: "gate.ts", next: EXIT },
|
|
1524
1694
|
},
|
|
1525
1695
|
};
|
|
@@ -1551,7 +1721,13 @@ test("envelope results (event present) are passed through untouched", async () =
|
|
|
1551
1721
|
const workflow: WorkflowDef = {
|
|
1552
1722
|
initial: "Work",
|
|
1553
1723
|
states: {
|
|
1554
|
-
Work: {
|
|
1724
|
+
Work: {
|
|
1725
|
+
type: "agent",
|
|
1726
|
+
outputType: okOutputType,
|
|
1727
|
+
agent: { model: "test-model" },
|
|
1728
|
+
prompt: "work",
|
|
1729
|
+
on: { done: "Gate" },
|
|
1730
|
+
},
|
|
1555
1731
|
Gate: { type: "script", file: "gate.ts", next: EXIT },
|
|
1556
1732
|
},
|
|
1557
1733
|
};
|
|
@@ -1615,12 +1791,19 @@ test("dispatches each state to the runner it resolves to, with that state's agen
|
|
|
1615
1791
|
states: {
|
|
1616
1792
|
Plan: {
|
|
1617
1793
|
type: "agent",
|
|
1794
|
+
outputType: okOutputType,
|
|
1618
1795
|
prompt: "plan",
|
|
1619
1796
|
runner: "other",
|
|
1620
1797
|
agent: { model: "model-a" },
|
|
1621
1798
|
next: "Build",
|
|
1622
1799
|
},
|
|
1623
|
-
Build: {
|
|
1800
|
+
Build: {
|
|
1801
|
+
type: "agent",
|
|
1802
|
+
outputType: okOutputType,
|
|
1803
|
+
prompt: "build",
|
|
1804
|
+
agent: { model: "model-b" },
|
|
1805
|
+
next: EXIT,
|
|
1806
|
+
},
|
|
1624
1807
|
},
|
|
1625
1808
|
};
|
|
1626
1809
|
const calls: Parameters<typeof recordingRunner>[1] = [];
|
|
@@ -1644,6 +1827,7 @@ test("a workflow whose agent states all name a runner needs no agentRunner", asy
|
|
|
1644
1827
|
states: {
|
|
1645
1828
|
Plan: {
|
|
1646
1829
|
type: "agent",
|
|
1830
|
+
outputType: okOutputType,
|
|
1647
1831
|
agent: { model: "test-model" },
|
|
1648
1832
|
prompt: "plan",
|
|
1649
1833
|
runner: "other",
|
|
@@ -1663,6 +1847,7 @@ test.each(["typo", "toString"])("runner %p never falls back to the default", asy
|
|
|
1663
1847
|
states: {
|
|
1664
1848
|
Plan: {
|
|
1665
1849
|
type: "agent",
|
|
1850
|
+
outputType: okOutputType,
|
|
1666
1851
|
agent: { model: "test-model" },
|
|
1667
1852
|
prompt: "plan",
|
|
1668
1853
|
runner: name,
|
|
@@ -1692,9 +1877,16 @@ test("an unknown runner on a later state crashes before the first dispatch", asy
|
|
|
1692
1877
|
const workflow: WorkflowDef = {
|
|
1693
1878
|
initial: "Plan",
|
|
1694
1879
|
states: {
|
|
1695
|
-
Plan: {
|
|
1880
|
+
Plan: {
|
|
1881
|
+
type: "agent",
|
|
1882
|
+
outputType: okOutputType,
|
|
1883
|
+
agent: { model: "test-model" },
|
|
1884
|
+
prompt: "p",
|
|
1885
|
+
next: "Build",
|
|
1886
|
+
},
|
|
1696
1887
|
Build: {
|
|
1697
1888
|
type: "agent",
|
|
1889
|
+
outputType: okOutputType,
|
|
1698
1890
|
agent: { model: "test-model" },
|
|
1699
1891
|
prompt: "p",
|
|
1700
1892
|
runner: "typo",
|
|
@@ -1723,13 +1915,21 @@ test("without a default runner, a state naming none crashes before any dispatch"
|
|
|
1723
1915
|
states: {
|
|
1724
1916
|
Plan: {
|
|
1725
1917
|
type: "agent",
|
|
1918
|
+
outputType: okOutputType,
|
|
1726
1919
|
agent: { model: "test-model" },
|
|
1727
1920
|
prompt: "p",
|
|
1728
1921
|
runner: "other",
|
|
1729
1922
|
retries: 2,
|
|
1730
1923
|
next: "Build",
|
|
1731
1924
|
},
|
|
1732
|
-
Build: {
|
|
1925
|
+
Build: {
|
|
1926
|
+
type: "agent",
|
|
1927
|
+
outputType: okOutputType,
|
|
1928
|
+
agent: { model: "test-model" },
|
|
1929
|
+
prompt: "p",
|
|
1930
|
+
retries: 2,
|
|
1931
|
+
next: EXIT,
|
|
1932
|
+
},
|
|
1733
1933
|
},
|
|
1734
1934
|
};
|
|
1735
1935
|
const calls: Parameters<typeof recordingRunner>[1] = [];
|
|
@@ -1753,15 +1953,17 @@ test("merges the workflow's agent bag under default-runner states only, without
|
|
|
1753
1953
|
initial: "Inherit",
|
|
1754
1954
|
agent: shared,
|
|
1755
1955
|
states: {
|
|
1756
|
-
Inherit: { type: "agent", prompt: "p", next: "Override" },
|
|
1956
|
+
Inherit: { type: "agent", outputType: okOutputType, prompt: "p", next: "Override" },
|
|
1757
1957
|
Override: {
|
|
1758
1958
|
type: "agent",
|
|
1959
|
+
outputType: okOutputType,
|
|
1759
1960
|
prompt: "p",
|
|
1760
1961
|
agent: { model: "own-model", extra: { b: 2 } },
|
|
1761
1962
|
next: "Named",
|
|
1762
1963
|
},
|
|
1763
1964
|
Named: {
|
|
1764
1965
|
type: "agent",
|
|
1966
|
+
outputType: okOutputType,
|
|
1765
1967
|
prompt: "p",
|
|
1766
1968
|
runner: "same",
|
|
1767
1969
|
agent: { model: "named-model" },
|
|
@@ -1769,7 +1971,13 @@ test("merges the workflow's agent bag under default-runner states only, without
|
|
|
1769
1971
|
},
|
|
1770
1972
|
},
|
|
1771
1973
|
};
|
|
1772
|
-
|
|
1974
|
+
// structuredClone cannot carry outputType's safeParse function — the one
|
|
1975
|
+
// function every agent leaf now declares. Serialize with functions stubbed
|
|
1976
|
+
// instead: the assertion is about def.agent mutation, and any other change
|
|
1977
|
+
// to the def still changes the string.
|
|
1978
|
+
const snapshot = (value: unknown) =>
|
|
1979
|
+
JSON.stringify(value, (_key, v) => (typeof v === "function" ? "fn" : v));
|
|
1980
|
+
const before = snapshot(workflow);
|
|
1773
1981
|
const calls: Parameters<typeof recordingRunner>[1] = [];
|
|
1774
1982
|
// The named runner is the very same object as the default one.
|
|
1775
1983
|
const runner = recordingRunner("same", calls);
|
|
@@ -1782,7 +1990,7 @@ test("merges the workflow's agent bag under default-runner states only, without
|
|
|
1782
1990
|
{ model: "own-model", auto: true, extra: { b: 2 } },
|
|
1783
1991
|
{ model: "named-model" },
|
|
1784
1992
|
]);
|
|
1785
|
-
expect(workflow).
|
|
1993
|
+
expect(snapshot(workflow)).toBe(before);
|
|
1786
1994
|
});
|
|
1787
1995
|
|
|
1788
1996
|
test("a runner writing to its def.agent reaches neither the workflow nor the next attempt", async () => {
|
|
@@ -1792,6 +2000,7 @@ test("a runner writing to its def.agent reaches neither the workflow nor the nex
|
|
|
1792
2000
|
states: {
|
|
1793
2001
|
Plan: {
|
|
1794
2002
|
type: "agent",
|
|
2003
|
+
outputType: okOutputType,
|
|
1795
2004
|
prompt: "p",
|
|
1796
2005
|
runner: "other",
|
|
1797
2006
|
agent: { model: "own" },
|
|
@@ -1823,12 +2032,19 @@ test("a session id from one runner never reaches the next state's runner", async
|
|
|
1823
2032
|
states: {
|
|
1824
2033
|
Plan: {
|
|
1825
2034
|
type: "agent",
|
|
2035
|
+
outputType: okOutputType,
|
|
1826
2036
|
agent: { model: "test-model" },
|
|
1827
2037
|
prompt: "p",
|
|
1828
2038
|
runner: "first",
|
|
1829
2039
|
next: "Build",
|
|
1830
2040
|
},
|
|
1831
|
-
Build: {
|
|
2041
|
+
Build: {
|
|
2042
|
+
type: "agent",
|
|
2043
|
+
outputType: okOutputType,
|
|
2044
|
+
agent: { model: "test-model" },
|
|
2045
|
+
prompt: "p",
|
|
2046
|
+
next: EXIT,
|
|
2047
|
+
},
|
|
1832
2048
|
},
|
|
1833
2049
|
};
|
|
1834
2050
|
const calls: Parameters<typeof recordingRunner>[1] = [];
|
|
@@ -1851,8 +2067,21 @@ test.each([undefined, "", 7])("a model of %p crashes before any dispatch", async
|
|
|
1851
2067
|
const workflow: WorkflowDef = {
|
|
1852
2068
|
initial: "Plan",
|
|
1853
2069
|
states: {
|
|
1854
|
-
Plan: {
|
|
1855
|
-
|
|
2070
|
+
Plan: {
|
|
2071
|
+
type: "agent",
|
|
2072
|
+
outputType: okOutputType,
|
|
2073
|
+
agent: { model: "test-model" },
|
|
2074
|
+
prompt: "p",
|
|
2075
|
+
next: "Build",
|
|
2076
|
+
},
|
|
2077
|
+
Build: {
|
|
2078
|
+
type: "agent",
|
|
2079
|
+
outputType: okOutputType,
|
|
2080
|
+
agent: { model },
|
|
2081
|
+
prompt: "p",
|
|
2082
|
+
retries: 2,
|
|
2083
|
+
next: EXIT,
|
|
2084
|
+
},
|
|
1856
2085
|
},
|
|
1857
2086
|
};
|
|
1858
2087
|
const calls: Parameters<typeof recordingRunner>[1] = [];
|
|
@@ -1872,8 +2101,8 @@ test("the default bag's model satisfies default-runner states only", async () =>
|
|
|
1872
2101
|
initial: "Plan",
|
|
1873
2102
|
agent: { model: "default-model" },
|
|
1874
2103
|
states: {
|
|
1875
|
-
Plan: { type: "agent", prompt: "p", next: "Build" },
|
|
1876
|
-
Build: { type: "agent", prompt: "p", runner: "other", next: EXIT },
|
|
2104
|
+
Plan: { type: "agent", outputType: okOutputType, prompt: "p", next: "Build" },
|
|
2105
|
+
Build: { type: "agent", outputType: okOutputType, prompt: "p", runner: "other", next: EXIT },
|
|
1877
2106
|
},
|
|
1878
2107
|
};
|
|
1879
2108
|
const calls: Parameters<typeof recordingRunner>[1] = [];
|
|
@@ -1893,9 +2122,23 @@ test("every running status of an agent dispatch records the selected runner and
|
|
|
1893
2122
|
const workflow: WorkflowDef = {
|
|
1894
2123
|
initial: "Default",
|
|
1895
2124
|
states: {
|
|
1896
|
-
Default: { type: "agent", agent, prompt: "p", next: "Named" },
|
|
1897
|
-
Named: {
|
|
1898
|
-
|
|
2125
|
+
Default: { type: "agent", outputType: okOutputType, agent, prompt: "p", next: "Named" },
|
|
2126
|
+
Named: {
|
|
2127
|
+
type: "agent",
|
|
2128
|
+
outputType: okOutputType,
|
|
2129
|
+
agent,
|
|
2130
|
+
prompt: "p",
|
|
2131
|
+
runner: "claude",
|
|
2132
|
+
next: "Kindless",
|
|
2133
|
+
},
|
|
2134
|
+
Kindless: {
|
|
2135
|
+
type: "agent",
|
|
2136
|
+
outputType: okOutputType,
|
|
2137
|
+
agent,
|
|
2138
|
+
prompt: "p",
|
|
2139
|
+
runner: "custom",
|
|
2140
|
+
next: "BareDefault",
|
|
2141
|
+
},
|
|
1899
2142
|
BareDefault: { type: "script", file: "a.ts", next: EXIT },
|
|
1900
2143
|
},
|
|
1901
2144
|
};
|
package/src/engine/run.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
3
|
import {
|
|
4
|
-
AgentFailure,
|
|
5
4
|
type AgentProgress,
|
|
6
5
|
type AgentRunner,
|
|
7
6
|
type AgentRunnerKind,
|
|
@@ -14,6 +13,7 @@ import {
|
|
|
14
13
|
effectiveAgent,
|
|
15
14
|
enter,
|
|
16
15
|
FAILED,
|
|
16
|
+
isAgentFailure,
|
|
17
17
|
isComposite,
|
|
18
18
|
isNodeResult,
|
|
19
19
|
type NodeEvent,
|
|
@@ -330,7 +330,7 @@ export async function run(opts: RunOptions): Promise<RunResult> {
|
|
|
330
330
|
// outputType (agent leaves only) — a shape check on the payload,
|
|
331
331
|
// run before `validate` so a validate script can read the output
|
|
332
332
|
// without re-checking its shape
|
|
333
|
-
// (docs/specs/output-validation/spec.md, "Order"). Same inline
|
|
333
|
+
// (docs/specs/_built/output-validation/spec.md, "Order"). Same inline
|
|
334
334
|
// nudge form as no-transition below: this reason comes from a
|
|
335
335
|
// return value, not a thrown AgentFailure, so the catch block's
|
|
336
336
|
// isNudgeable path never sees it.
|
|
@@ -354,7 +354,7 @@ export async function run(opts: RunOptions): Promise<RunResult> {
|
|
|
354
354
|
// catch block's isNudgeable path never sees it. Up to
|
|
355
355
|
// NUDGE_LIMIT nudges consume no retry; only the fallback to a
|
|
356
356
|
// fresh attempt does
|
|
357
|
-
// (docs/specs/output-validation/spec.md, "Where this plugs
|
|
357
|
+
// (docs/specs/_built/output-validation/spec.md, "Where this plugs
|
|
358
358
|
// into the dispatch loop").
|
|
359
359
|
if (agentSessionId && nudgeAttempt < NUDGE_LIMIT) {
|
|
360
360
|
nudgeAttempt++;
|
|
@@ -382,7 +382,7 @@ export async function run(opts: RunOptions): Promise<RunResult> {
|
|
|
382
382
|
reason = { kind: "timeout", elapsedMs: timeoutMs };
|
|
383
383
|
continue attemptLoop;
|
|
384
384
|
}
|
|
385
|
-
if (err
|
|
385
|
+
if (isAgentFailure(err)) {
|
|
386
386
|
agentSessionId = err.agentSessionId ?? agentSessionId;
|
|
387
387
|
reason = err.crashReason ?? { kind: "runner-error", error: err.message };
|
|
388
388
|
} else {
|
|
@@ -59,7 +59,7 @@ export function buildPrompt(
|
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* Shared same-session repair text for the nudgeable `CrashReason` kinds
|
|
62
|
-
* (docs/specs/_built/session-nudge/spec.md, docs/specs/output-validation/spec.md).
|
|
62
|
+
* (docs/specs/_built/session-nudge/spec.md, docs/specs/_built/output-validation/spec.md).
|
|
63
63
|
* `undefined` means "don't nudge" — either there's no `previousFailure`, no
|
|
64
64
|
* `agentSessionId` to resume, or the failure isn't one of the repairable
|
|
65
65
|
* kinds. Both runners call this identically; only the CLI invocation that
|