@psimona/darkf 0.7.1 → 0.9.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 +18 -5
- package/docs/concepts/handoff.md +8 -4
- package/docs/concepts/node-types.md +45 -21
- package/docs/guides/pick-an-agent-runner.md +143 -4
- package/docs/guides/plan-with-a-task-queue.md +18 -2
- package/docs/guides/run-detached-and-monitor.md +4 -3
- package/docs/guides/write-your-first-workflow.md +24 -5
- package/docs/reference/cli-commands.md +24 -6
- package/docs/reference/core-types.md +41 -6
- package/docs/start-here/quickstart.md +22 -2
- package/package.json +1 -1
- package/skills/darkf-usage/SKILL.md +17 -0
- package/skills/darkf-writing-workflows/SKILL.md +25 -18
- package/src/cli/detached.test.ts +92 -2
- package/src/cli/doctor.test.ts +224 -9
- package/src/cli/index.ts +83 -12
- package/src/cli/tarball.test.ts +8 -2
- package/src/core/graph.test.ts +266 -20
- package/src/core/graph.ts +61 -3
- package/src/core/types.ts +21 -0
- package/src/engine/run.test.ts +581 -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.test.ts +89 -12
- package/src/kit/agents/opencode.ts +103 -8
- package/src/kit/status.test.ts +24 -0
- package/src/kit/status.ts +25 -8
- 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/finish.ts +2 -36
- package/workflows/dev-loop/workflow.ts +18 -4
- package/workflows/series-ordering/output-types.ts +9 -0
- package/workflows/series-ordering/workflow.ts +4 -0
package/src/core/graph.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { expect, test } from "bun:test";
|
|
2
|
+
import { okOutputType } from "../test/ok-output.ts";
|
|
2
3
|
import { buildRegistry, validateWorkflow } from "./graph.ts";
|
|
3
|
-
import { DONE, EXIT, FAILED, type WorkflowDef } from "./types.ts";
|
|
4
|
+
import { DONE, EXIT, FAILED, type OutputSchema, type WorkflowDef } from "./types.ts";
|
|
4
5
|
|
|
5
6
|
function registryFor(workflow: WorkflowDef) {
|
|
6
7
|
return buildRegistry(workflow);
|
|
@@ -11,11 +12,17 @@ test("reports no errors for a well-formed workflow", () => {
|
|
|
11
12
|
initial: "A",
|
|
12
13
|
states: {
|
|
13
14
|
A: { type: "script", file: "a.ts", next: "B" },
|
|
14
|
-
B: {
|
|
15
|
+
B: {
|
|
16
|
+
type: "agent",
|
|
17
|
+
outputType: okOutputType,
|
|
18
|
+
agent: { model: "m" },
|
|
19
|
+
prompt: "b",
|
|
20
|
+
on: { ok: DONE, bad: FAILED },
|
|
21
|
+
},
|
|
15
22
|
},
|
|
16
23
|
};
|
|
17
24
|
|
|
18
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
25
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([]);
|
|
19
26
|
});
|
|
20
27
|
|
|
21
28
|
test("flags an unresolved top-level initial, with from: null", () => {
|
|
@@ -24,7 +31,7 @@ test("flags an unresolved top-level initial, with from: null", () => {
|
|
|
24
31
|
states: { A: { type: "script", file: "a.ts", next: DONE } },
|
|
25
32
|
};
|
|
26
33
|
|
|
27
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
34
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
28
35
|
{ kind: "unresolved-target", from: null, target: "Nope" },
|
|
29
36
|
]);
|
|
30
37
|
});
|
|
@@ -35,7 +42,7 @@ test("flags an unresolved leaf on/next target", () => {
|
|
|
35
42
|
states: { A: { type: "script", file: "a.ts", on: { ok: "Missing" }, next: "AlsoMissing" } },
|
|
36
43
|
};
|
|
37
44
|
|
|
38
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
45
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
39
46
|
{ kind: "unresolved-target", from: "A", target: "Missing" },
|
|
40
47
|
{ kind: "unresolved-target", from: "A", target: "AlsoMissing" },
|
|
41
48
|
]);
|
|
@@ -49,7 +56,7 @@ test("flags an unresolved composite initial", () => {
|
|
|
49
56
|
},
|
|
50
57
|
};
|
|
51
58
|
|
|
52
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
59
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
53
60
|
{ kind: "unresolved-target", from: "Outer", target: "Missing" },
|
|
54
61
|
]);
|
|
55
62
|
});
|
|
@@ -62,18 +69,18 @@ test("DONE/FAILED/deprecated-EXIT-alias are valid leaf on/next targets", () => {
|
|
|
62
69
|
},
|
|
63
70
|
};
|
|
64
71
|
|
|
65
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
72
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([]);
|
|
66
73
|
});
|
|
67
74
|
|
|
68
75
|
test("DONE/FAILED are never valid as a top-level initial", () => {
|
|
69
76
|
const states: WorkflowDef["states"] = { A: { type: "script", file: "a.ts", next: DONE } };
|
|
70
77
|
|
|
71
|
-
expect(
|
|
72
|
-
{
|
|
73
|
-
]);
|
|
74
|
-
expect(
|
|
75
|
-
{
|
|
76
|
-
]);
|
|
78
|
+
expect(
|
|
79
|
+
validateWorkflow(registryFor({ initial: DONE, states }), { initial: DONE, states }),
|
|
80
|
+
).toEqual([{ kind: "unresolved-target", from: null, target: DONE }]);
|
|
81
|
+
expect(
|
|
82
|
+
validateWorkflow(registryFor({ initial: FAILED, states }), { initial: FAILED, states }),
|
|
83
|
+
).toEqual([{ kind: "unresolved-target", from: null, target: FAILED }]);
|
|
77
84
|
});
|
|
78
85
|
|
|
79
86
|
test("DONE/FAILED are never valid as a composite initial", () => {
|
|
@@ -84,7 +91,7 @@ test("DONE/FAILED are never valid as a composite initial", () => {
|
|
|
84
91
|
},
|
|
85
92
|
};
|
|
86
93
|
|
|
87
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
94
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
88
95
|
{ kind: "unresolved-target", from: "Outer", target: FAILED },
|
|
89
96
|
]);
|
|
90
97
|
});
|
|
@@ -95,7 +102,7 @@ test("flags a dead-end leaf with neither on nor next", () => {
|
|
|
95
102
|
states: { A: { type: "script", file: "a.ts" } },
|
|
96
103
|
};
|
|
97
104
|
|
|
98
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
105
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
99
106
|
{ kind: "dead-end-leaf", state: "A" },
|
|
100
107
|
]);
|
|
101
108
|
});
|
|
@@ -106,7 +113,7 @@ test("an empty on map with no next is still a dead-end leaf", () => {
|
|
|
106
113
|
states: { A: { type: "script", file: "a.ts", on: {} } },
|
|
107
114
|
};
|
|
108
115
|
|
|
109
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
116
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
110
117
|
{ kind: "dead-end-leaf", state: "A" },
|
|
111
118
|
]);
|
|
112
119
|
});
|
|
@@ -120,7 +127,7 @@ test("finds a two-composite initial cycle exactly once, regardless of which feed
|
|
|
120
127
|
},
|
|
121
128
|
};
|
|
122
129
|
|
|
123
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
130
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
124
131
|
{ kind: "initial-cycle", cycle: ["A", "B"] },
|
|
125
132
|
]);
|
|
126
133
|
});
|
|
@@ -131,7 +138,7 @@ test("finds a self-referential composite initial cycle", () => {
|
|
|
131
138
|
states: { A: { initial: "A", states: { Leaf: { type: "script", file: "l.ts", next: DONE } } } },
|
|
132
139
|
};
|
|
133
140
|
|
|
134
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
141
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
135
142
|
{ kind: "initial-cycle", cycle: ["A"] },
|
|
136
143
|
]);
|
|
137
144
|
});
|
|
@@ -145,7 +152,7 @@ test("a cycle mid-chain that resolves to an unresolved id reports unresolved-tar
|
|
|
145
152
|
},
|
|
146
153
|
};
|
|
147
154
|
|
|
148
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
155
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
149
156
|
{ kind: "unresolved-target", from: "B", target: "Missing" },
|
|
150
157
|
]);
|
|
151
158
|
});
|
|
@@ -160,7 +167,7 @@ test("collects every problem in one pass instead of stopping at the first", () =
|
|
|
160
167
|
},
|
|
161
168
|
};
|
|
162
169
|
|
|
163
|
-
const errors = validateWorkflow(registryFor(workflow), workflow
|
|
170
|
+
const errors = validateWorkflow(registryFor(workflow), workflow);
|
|
164
171
|
expect(errors).toEqual(
|
|
165
172
|
expect.arrayContaining([
|
|
166
173
|
{ kind: "unresolved-target", from: "A", target: "Missing1" },
|
|
@@ -170,3 +177,242 @@ test("collects every problem in one pass instead of stopping at the first", () =
|
|
|
170
177
|
);
|
|
171
178
|
expect(errors.length).toBe(3);
|
|
172
179
|
});
|
|
180
|
+
|
|
181
|
+
const runnerWorkflow: WorkflowDef = {
|
|
182
|
+
initial: "Group",
|
|
183
|
+
states: {
|
|
184
|
+
Group: {
|
|
185
|
+
initial: "Named",
|
|
186
|
+
states: {
|
|
187
|
+
Named: {
|
|
188
|
+
type: "agent",
|
|
189
|
+
outputType: okOutputType,
|
|
190
|
+
agent: { model: "m" },
|
|
191
|
+
prompt: "p",
|
|
192
|
+
runner: "other",
|
|
193
|
+
next: "Bare",
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
next: DONE,
|
|
197
|
+
},
|
|
198
|
+
Bare: {
|
|
199
|
+
type: "agent",
|
|
200
|
+
outputType: okOutputType,
|
|
201
|
+
agent: { model: "m" },
|
|
202
|
+
prompt: "p",
|
|
203
|
+
next: "Script",
|
|
204
|
+
},
|
|
205
|
+
Script: { type: "script", file: "a.ts", next: DONE },
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
function runnerErrors(names: string[], hasDefault: boolean, workflow = runnerWorkflow) {
|
|
210
|
+
return validateWorkflow(registryFor(workflow), workflow, { names, hasDefault });
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
test("accepts agent states that each resolve to a runner", () => {
|
|
214
|
+
expect(runnerErrors(["other"], true)).toEqual([]);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test("flags an unregistered runner name, with the known names", () => {
|
|
218
|
+
expect(runnerErrors(["a", "b"], true)).toEqual([
|
|
219
|
+
{ kind: "unknown-runner", state: "Named", runner: "other", known: ["a", "b"] },
|
|
220
|
+
]);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test("flags a state naming no runner when there is no default, ignoring scripts", () => {
|
|
224
|
+
expect(runnerErrors(["other"], false)).toEqual([{ kind: "missing-runner", state: "Bare" }]);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test("needs no default when every agent state names a registered runner", () => {
|
|
228
|
+
const workflow: WorkflowDef = {
|
|
229
|
+
initial: "A",
|
|
230
|
+
states: {
|
|
231
|
+
A: {
|
|
232
|
+
type: "agent",
|
|
233
|
+
outputType: okOutputType,
|
|
234
|
+
agent: { model: "m" },
|
|
235
|
+
prompt: "p",
|
|
236
|
+
runner: "other",
|
|
237
|
+
next: DONE,
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
expect(runnerErrors(["other"], false, workflow)).toEqual([]);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test("reports an inherited object key such as toString as unknown", () => {
|
|
246
|
+
const workflow: WorkflowDef = {
|
|
247
|
+
initial: "A",
|
|
248
|
+
states: {
|
|
249
|
+
A: {
|
|
250
|
+
type: "agent",
|
|
251
|
+
outputType: okOutputType,
|
|
252
|
+
agent: { model: "m" },
|
|
253
|
+
prompt: "p",
|
|
254
|
+
runner: "toString",
|
|
255
|
+
next: DONE,
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
expect(runnerErrors([], true, workflow)).toEqual([
|
|
261
|
+
{ kind: "unknown-runner", state: "A", runner: "toString", known: [] },
|
|
262
|
+
]);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test("skips the runner checks without the runners argument", () => {
|
|
266
|
+
expect(validateWorkflow(registryFor(runnerWorkflow), runnerWorkflow)).toEqual([]);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
function modelErrors(workflow: WorkflowDef) {
|
|
270
|
+
return validateWorkflow(registryFor(workflow), workflow);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
test("flags every agent state without a non-empty string model, ignoring scripts", () => {
|
|
274
|
+
const workflow: WorkflowDef = {
|
|
275
|
+
initial: "Group",
|
|
276
|
+
states: {
|
|
277
|
+
Group: {
|
|
278
|
+
initial: "Bare",
|
|
279
|
+
states: { Bare: { type: "agent", outputType: okOutputType, prompt: "p", next: "Empty" } },
|
|
280
|
+
next: DONE,
|
|
281
|
+
},
|
|
282
|
+
Empty: {
|
|
283
|
+
type: "agent",
|
|
284
|
+
outputType: okOutputType,
|
|
285
|
+
prompt: "p",
|
|
286
|
+
agent: { model: "" },
|
|
287
|
+
next: "NotString",
|
|
288
|
+
},
|
|
289
|
+
NotString: {
|
|
290
|
+
type: "agent",
|
|
291
|
+
outputType: okOutputType,
|
|
292
|
+
prompt: "p",
|
|
293
|
+
agent: { model: 7 },
|
|
294
|
+
next: "Pinned",
|
|
295
|
+
},
|
|
296
|
+
Pinned: {
|
|
297
|
+
type: "agent",
|
|
298
|
+
outputType: okOutputType,
|
|
299
|
+
prompt: "p",
|
|
300
|
+
agent: { model: "m" },
|
|
301
|
+
next: "Script",
|
|
302
|
+
},
|
|
303
|
+
Script: { type: "script", file: "a.ts", next: DONE },
|
|
304
|
+
},
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
expect(modelErrors(workflow)).toEqual([
|
|
308
|
+
{ kind: "missing-model", state: "Bare" },
|
|
309
|
+
{ kind: "missing-model", state: "Empty" },
|
|
310
|
+
{ kind: "missing-model", state: "NotString" },
|
|
311
|
+
]);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
test("takes the model from the default bag for default-runner states only", () => {
|
|
315
|
+
const workflow: WorkflowDef = {
|
|
316
|
+
initial: "Inherit",
|
|
317
|
+
agent: { model: "m" },
|
|
318
|
+
states: {
|
|
319
|
+
Inherit: {
|
|
320
|
+
type: "agent",
|
|
321
|
+
outputType: okOutputType,
|
|
322
|
+
prompt: "p",
|
|
323
|
+
agent: { auto: true },
|
|
324
|
+
next: "Cleared",
|
|
325
|
+
},
|
|
326
|
+
Cleared: {
|
|
327
|
+
type: "agent",
|
|
328
|
+
outputType: okOutputType,
|
|
329
|
+
prompt: "p",
|
|
330
|
+
agent: { model: undefined },
|
|
331
|
+
next: "Named",
|
|
332
|
+
},
|
|
333
|
+
Named: { type: "agent", outputType: okOutputType, prompt: "p", runner: "other", next: DONE },
|
|
334
|
+
},
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
expect(modelErrors(workflow)).toEqual([
|
|
338
|
+
{ kind: "missing-model", state: "Cleared" },
|
|
339
|
+
{ kind: "missing-model", state: "Named" },
|
|
340
|
+
]);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
// --- mandatory outputType on agent leaves (docs/specs/mandatory-agent-output-types/) ---
|
|
344
|
+
|
|
345
|
+
function outputTypeErrors(workflow: WorkflowDef) {
|
|
346
|
+
return validateWorkflow(registryFor(workflow), workflow);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
test("flags an agent leaf without an outputType, ignoring scripts", () => {
|
|
350
|
+
const workflow: WorkflowDef = {
|
|
351
|
+
initial: "Script",
|
|
352
|
+
states: {
|
|
353
|
+
Script: { type: "script", file: "a.ts", next: "Bare" },
|
|
354
|
+
Bare: { type: "agent", agent: { model: "m" }, prompt: "p", next: DONE },
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
expect(outputTypeErrors(workflow)).toEqual([{ kind: "missing-output-type", state: "Bare" }]);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
test("flags an outputType that is not an object with a safeParse function", () => {
|
|
362
|
+
const malformed = (value: unknown) => value as OutputSchema;
|
|
363
|
+
const workflow: WorkflowDef = {
|
|
364
|
+
initial: "NotAnObject",
|
|
365
|
+
states: {
|
|
366
|
+
NotAnObject: {
|
|
367
|
+
type: "agent",
|
|
368
|
+
agent: { model: "m" },
|
|
369
|
+
prompt: "p",
|
|
370
|
+
outputType: malformed("schema"),
|
|
371
|
+
next: "NoSafeParse",
|
|
372
|
+
},
|
|
373
|
+
NoSafeParse: {
|
|
374
|
+
type: "agent",
|
|
375
|
+
agent: { model: "m" },
|
|
376
|
+
prompt: "p",
|
|
377
|
+
outputType: malformed({}),
|
|
378
|
+
next: DONE,
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
expect(outputTypeErrors(workflow)).toEqual([
|
|
384
|
+
{ kind: "missing-output-type", state: "NotAnObject" },
|
|
385
|
+
{ kind: "missing-output-type", state: "NoSafeParse" },
|
|
386
|
+
]);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
test("flags an agent leaf nested in a composite", () => {
|
|
390
|
+
const workflow: WorkflowDef = {
|
|
391
|
+
initial: "Outer",
|
|
392
|
+
states: {
|
|
393
|
+
Outer: {
|
|
394
|
+
initial: "Bare",
|
|
395
|
+
states: { Bare: { type: "agent", agent: { model: "m" }, prompt: "p", next: DONE } },
|
|
396
|
+
next: DONE,
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
expect(outputTypeErrors(workflow)).toEqual([{ kind: "missing-output-type", state: "Bare" }]);
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
test("collects every agent leaf without an outputType in one pass", () => {
|
|
405
|
+
const workflow: WorkflowDef = {
|
|
406
|
+
initial: "A",
|
|
407
|
+
states: {
|
|
408
|
+
A: { type: "agent", agent: { model: "m" }, prompt: "p", next: "B" },
|
|
409
|
+
B: { type: "agent", agent: { model: "m" }, prompt: "p", next: "Script" },
|
|
410
|
+
Script: { type: "script", file: "a.ts", next: DONE },
|
|
411
|
+
},
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
expect(outputTypeErrors(workflow)).toEqual([
|
|
415
|
+
{ kind: "missing-output-type", state: "A" },
|
|
416
|
+
{ kind: "missing-output-type", state: "B" },
|
|
417
|
+
]);
|
|
418
|
+
});
|
package/src/core/graph.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// async. Anything that just wants to know the graph's shape (a renderer, a
|
|
3
3
|
// validator, a future web viewer) depends on this, not on the execution loop.
|
|
4
4
|
import {
|
|
5
|
+
type AgentStateDef,
|
|
5
6
|
DONE,
|
|
6
7
|
FAILED,
|
|
7
8
|
isComposite,
|
|
@@ -61,20 +62,49 @@ export function resolveTarget(def: StateDef, event: string | undefined): Target
|
|
|
61
62
|
export type WorkflowValidationError =
|
|
62
63
|
| { kind: "unresolved-target"; from: string | null; target: string }
|
|
63
64
|
| { kind: "initial-cycle"; cycle: string[] }
|
|
64
|
-
| { kind: "dead-end-leaf"; state: string }
|
|
65
|
+
| { kind: "dead-end-leaf"; state: string }
|
|
66
|
+
| { kind: "unknown-runner"; state: string; runner: string; known: string[] }
|
|
67
|
+
| { kind: "missing-runner"; state: string }
|
|
68
|
+
| { kind: "missing-model"; state: string }
|
|
69
|
+
| { kind: "missing-output-type"; state: string };
|
|
70
|
+
|
|
71
|
+
/** The runners a workflow has available, as names only — `core` never sees the objects. */
|
|
72
|
+
export interface AvailableRunners {
|
|
73
|
+
/** Names an agent state can select through `runner`. */
|
|
74
|
+
names: string[];
|
|
75
|
+
/** Whether a default runner exists for agent states that name none. */
|
|
76
|
+
hasDefault: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The `agent` bag a state dispatches with. The workflow's default bag belongs
|
|
81
|
+
* to the default runner only: a state that names a runner keeps its own bag, so
|
|
82
|
+
* no model or permission setting carries over to another harness. Always a new
|
|
83
|
+
* object, merged shallowly.
|
|
84
|
+
*/
|
|
85
|
+
export function effectiveAgent(
|
|
86
|
+
def: AgentStateDef,
|
|
87
|
+
defaultAgent?: WorkflowDef["agent"],
|
|
88
|
+
): Record<string, unknown> {
|
|
89
|
+
return { ...(def.runner === undefined ? defaultAgent : undefined), ...def.agent };
|
|
90
|
+
}
|
|
65
91
|
|
|
66
92
|
/**
|
|
67
93
|
* Eager, whole-graph structural check over an already-built registry — a
|
|
68
94
|
* second, cheap pass over the same flat `Map` `buildRegistry` produced, not
|
|
69
95
|
* a second tree-walk. Collects every problem found; never stops at the
|
|
70
96
|
* first. `DONE`/`FAILED` are valid targets only for a leaf's `on`/`next`,
|
|
71
|
-
* never for any `initial` (composite or top-level).
|
|
97
|
+
* never for any `initial` (composite or top-level). Every agent leaf must
|
|
98
|
+
* declare an `outputType` (docs/specs/mandatory-agent-output-types/). Without
|
|
99
|
+
* `runners`, the runner checks are skipped.
|
|
72
100
|
*/
|
|
73
101
|
export function validateWorkflow(
|
|
74
102
|
registry: Map<string, RegistryEntry>,
|
|
75
|
-
|
|
103
|
+
workflow: WorkflowDef,
|
|
104
|
+
runners?: AvailableRunners,
|
|
76
105
|
): WorkflowValidationError[] {
|
|
77
106
|
const errors: WorkflowValidationError[] = [];
|
|
107
|
+
const { initial } = workflow;
|
|
78
108
|
|
|
79
109
|
if (!registry.has(initial)) {
|
|
80
110
|
errors.push({ kind: "unresolved-target", from: null, target: initial });
|
|
@@ -100,6 +130,34 @@ export function validateWorkflow(
|
|
|
100
130
|
if (Object.keys(def.on ?? {}).length === 0 && def.next === undefined) {
|
|
101
131
|
errors.push({ kind: "dead-end-leaf", state: id });
|
|
102
132
|
}
|
|
133
|
+
|
|
134
|
+
if (def.type === "agent") {
|
|
135
|
+
const { model } = effectiveAgent(def, workflow.agent);
|
|
136
|
+
if (typeof model !== "string" || model === "") {
|
|
137
|
+
errors.push({ kind: "missing-model", state: id });
|
|
138
|
+
}
|
|
139
|
+
const { outputType } = def;
|
|
140
|
+
if (
|
|
141
|
+
typeof outputType !== "object" ||
|
|
142
|
+
outputType === null ||
|
|
143
|
+
typeof outputType.safeParse !== "function"
|
|
144
|
+
) {
|
|
145
|
+
errors.push({ kind: "missing-output-type", state: id });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (runners && def.type === "agent") {
|
|
150
|
+
if (def.runner === undefined) {
|
|
151
|
+
if (!runners.hasDefault) errors.push({ kind: "missing-runner", state: id });
|
|
152
|
+
} else if (!runners.names.includes(def.runner)) {
|
|
153
|
+
errors.push({
|
|
154
|
+
kind: "unknown-runner",
|
|
155
|
+
state: id,
|
|
156
|
+
runner: def.runner,
|
|
157
|
+
known: runners.names,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
103
161
|
}
|
|
104
162
|
|
|
105
163
|
// Every composite in the registry is a chain-walk start, plus the
|
package/src/core/types.ts
CHANGED
|
@@ -73,6 +73,8 @@ export interface AgentStateDef extends BaseLeafDef {
|
|
|
73
73
|
type: "agent";
|
|
74
74
|
prompt: string;
|
|
75
75
|
agent?: Record<string, unknown>;
|
|
76
|
+
/** Key into the workflow's `agentRunners`. Absent: the default `agentRunner`. */
|
|
77
|
+
runner?: string;
|
|
76
78
|
outputType?: OutputSchema; // checks result.output, before `validate` runs
|
|
77
79
|
}
|
|
78
80
|
|
|
@@ -110,6 +112,8 @@ export type StateDef = AgentStateDef | ScriptStateDef | CompositeStateDef;
|
|
|
110
112
|
export interface WorkflowDef {
|
|
111
113
|
initial: string;
|
|
112
114
|
states: Record<string, StateDef>;
|
|
115
|
+
/** Default `agent` bag for states on the default runner. */
|
|
116
|
+
agent?: Record<string, unknown>;
|
|
113
117
|
}
|
|
114
118
|
|
|
115
119
|
export function isComposite(def: StateDef): def is CompositeStateDef {
|
|
@@ -173,12 +177,24 @@ export interface AgentProgress {
|
|
|
173
177
|
lastEvent: string;
|
|
174
178
|
}
|
|
175
179
|
|
|
180
|
+
/** One model id a runner does not recognize, and why. */
|
|
181
|
+
export interface ModelWarning {
|
|
182
|
+
model: string;
|
|
183
|
+
message: string;
|
|
184
|
+
}
|
|
185
|
+
|
|
176
186
|
export interface AgentRunner {
|
|
177
187
|
/** Self-identification (e.g. `"opencode"`, `"claude-code"`), set once per
|
|
178
188
|
* runner implementation. Read by darkf-cli at run-start time to record
|
|
179
189
|
* which runner executed a run; absent for runners that don't identify
|
|
180
190
|
* themselves. */
|
|
181
191
|
kind?: AgentRunnerKind;
|
|
192
|
+
/**
|
|
193
|
+
* Optional advisory check, used by `darkf validate`: which of these model
|
|
194
|
+
* ids does this harness not recognize? Never called during a run, and must
|
|
195
|
+
* not call a model. Throw when the check itself cannot be done.
|
|
196
|
+
*/
|
|
197
|
+
checkModels?(models: string[], rootDir: string): Promise<ModelWarning[]>;
|
|
182
198
|
run(
|
|
183
199
|
id: string,
|
|
184
200
|
def: AgentStateDef,
|
|
@@ -213,6 +229,11 @@ export type NodeStatus =
|
|
|
213
229
|
startedAt: number;
|
|
214
230
|
lastHeartbeat: number;
|
|
215
231
|
agentSessionId?: string;
|
|
232
|
+
/** The runner name an agent state selected. Absent for the default
|
|
233
|
+
* runner and for script dispatches. */
|
|
234
|
+
runner?: string;
|
|
235
|
+
/** The resolved agent runner's `kind`. Absent when it declares none. */
|
|
236
|
+
runnerKind?: AgentRunnerKind;
|
|
216
237
|
/** Latest step count from the agent's own event stream, when the
|
|
217
238
|
* runner reports progress (`AgentRunner.run`'s optional
|
|
218
239
|
* `onProgress`) — see docs/specs/_built/agent-liveness/spec.md. Absent for
|