@psimona/darkf 0.6.0 → 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 +23 -7
- package/docs/concepts/handoff.md +3 -3
- package/docs/concepts/node-types.md +44 -20
- package/docs/guides/pick-an-agent-runner.md +122 -4
- package/docs/guides/plan-with-a-task-queue.md +9 -7
- package/docs/guides/run-detached-and-monitor.md +3 -3
- package/docs/guides/write-your-first-workflow.md +14 -5
- package/docs/index.mdx +4 -0
- package/docs/reference/cli-commands.md +22 -6
- package/docs/reference/core-types.md +29 -4
- package/docs/reference/package-map.md +12 -8
- package/docs/start-here/quickstart.md +15 -7
- package/package.json +9 -2
- package/skills/darkf-writing-workflows/SKILL.md +141 -7
- package/src/cli/detached.test.ts +88 -2
- package/src/cli/doctor.test.ts +225 -10
- package/src/cli/index.ts +106 -27
- package/src/cli/setup.ts +4 -9
- package/src/cli/state-file.ts +14 -0
- package/src/cli/tarball.test.ts +3 -1
- package/src/cli/update.ts +4 -9
- package/src/core/graph.test.ts +124 -19
- package/src/core/graph.ts +51 -3
- package/src/core/tasks.ts +1 -1
- package/src/core/types.test.ts +52 -0
- package/src/core/types.ts +48 -18
- package/src/engine/run.test.ts +708 -18
- package/src/engine/run.ts +101 -16
- package/src/exports.ts +4 -0
- package/src/kit/agents/claude-code.test.ts +38 -2
- package/src/kit/agents/claude-code.ts +28 -37
- package/src/kit/agents/handoff.test.ts +12 -0
- package/src/kit/agents/handoff.ts +32 -8
- package/src/kit/agents/opencode.test.ts +1 -1
- package/src/kit/agents/opencode.ts +44 -28
- package/src/kit/specs.test.ts +247 -0
- package/src/kit/specs.ts +344 -0
- package/src/kit/status.test.ts +24 -0
- package/src/kit/status.ts +31 -14
- package/src/kit/validation/zod.test.ts +42 -0
- package/src/kit/validation/zod.ts +20 -0
- package/workflows/dev-loop/scripts/begin.ts +9 -6
- package/workflows/dev-loop/scripts/dispatch.ts +50 -0
- package/workflows/dev-loop/scripts/finish.ts +23 -21
- package/workflows/dev-loop/scripts/mark-done.ts +22 -0
- package/workflows/dev-loop/scripts/validate-plan.ts +30 -0
- package/workflows/dev-loop/workflow.ts +164 -68
- package/workflows/series-ordering/workflow.ts +1 -0
- /package/workflows/dev-loop/scripts/{check.ts → test.ts} +0 -0
package/src/core/graph.test.ts
CHANGED
|
@@ -11,11 +11,11 @@ test("reports no errors for a well-formed workflow", () => {
|
|
|
11
11
|
initial: "A",
|
|
12
12
|
states: {
|
|
13
13
|
A: { type: "script", file: "a.ts", next: "B" },
|
|
14
|
-
B: { type: "agent", prompt: "b", on: { ok: DONE, bad: FAILED } },
|
|
14
|
+
B: { type: "agent", agent: { model: "m" }, prompt: "b", on: { ok: DONE, bad: FAILED } },
|
|
15
15
|
},
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
18
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([]);
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
test("flags an unresolved top-level initial, with from: null", () => {
|
|
@@ -24,7 +24,7 @@ test("flags an unresolved top-level initial, with from: null", () => {
|
|
|
24
24
|
states: { A: { type: "script", file: "a.ts", next: DONE } },
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
27
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
28
28
|
{ kind: "unresolved-target", from: null, target: "Nope" },
|
|
29
29
|
]);
|
|
30
30
|
});
|
|
@@ -35,7 +35,7 @@ test("flags an unresolved leaf on/next target", () => {
|
|
|
35
35
|
states: { A: { type: "script", file: "a.ts", on: { ok: "Missing" }, next: "AlsoMissing" } },
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
38
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
39
39
|
{ kind: "unresolved-target", from: "A", target: "Missing" },
|
|
40
40
|
{ kind: "unresolved-target", from: "A", target: "AlsoMissing" },
|
|
41
41
|
]);
|
|
@@ -49,7 +49,7 @@ test("flags an unresolved composite initial", () => {
|
|
|
49
49
|
},
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
52
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
53
53
|
{ kind: "unresolved-target", from: "Outer", target: "Missing" },
|
|
54
54
|
]);
|
|
55
55
|
});
|
|
@@ -62,18 +62,18 @@ test("DONE/FAILED/deprecated-EXIT-alias are valid leaf on/next targets", () => {
|
|
|
62
62
|
},
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
65
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([]);
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
test("DONE/FAILED are never valid as a top-level initial", () => {
|
|
69
69
|
const states: WorkflowDef["states"] = { A: { type: "script", file: "a.ts", next: DONE } };
|
|
70
70
|
|
|
71
|
-
expect(
|
|
72
|
-
{
|
|
73
|
-
]);
|
|
74
|
-
expect(
|
|
75
|
-
{
|
|
76
|
-
]);
|
|
71
|
+
expect(
|
|
72
|
+
validateWorkflow(registryFor({ initial: DONE, states }), { initial: DONE, states }),
|
|
73
|
+
).toEqual([{ kind: "unresolved-target", from: null, target: DONE }]);
|
|
74
|
+
expect(
|
|
75
|
+
validateWorkflow(registryFor({ initial: FAILED, states }), { initial: FAILED, states }),
|
|
76
|
+
).toEqual([{ kind: "unresolved-target", from: null, target: FAILED }]);
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
test("DONE/FAILED are never valid as a composite initial", () => {
|
|
@@ -84,7 +84,7 @@ test("DONE/FAILED are never valid as a composite initial", () => {
|
|
|
84
84
|
},
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
87
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
88
88
|
{ kind: "unresolved-target", from: "Outer", target: FAILED },
|
|
89
89
|
]);
|
|
90
90
|
});
|
|
@@ -95,7 +95,7 @@ test("flags a dead-end leaf with neither on nor next", () => {
|
|
|
95
95
|
states: { A: { type: "script", file: "a.ts" } },
|
|
96
96
|
};
|
|
97
97
|
|
|
98
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
98
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
99
99
|
{ kind: "dead-end-leaf", state: "A" },
|
|
100
100
|
]);
|
|
101
101
|
});
|
|
@@ -106,7 +106,7 @@ test("an empty on map with no next is still a dead-end leaf", () => {
|
|
|
106
106
|
states: { A: { type: "script", file: "a.ts", on: {} } },
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
109
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
110
110
|
{ kind: "dead-end-leaf", state: "A" },
|
|
111
111
|
]);
|
|
112
112
|
});
|
|
@@ -120,7 +120,7 @@ test("finds a two-composite initial cycle exactly once, regardless of which feed
|
|
|
120
120
|
},
|
|
121
121
|
};
|
|
122
122
|
|
|
123
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
123
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
124
124
|
{ kind: "initial-cycle", cycle: ["A", "B"] },
|
|
125
125
|
]);
|
|
126
126
|
});
|
|
@@ -131,7 +131,7 @@ test("finds a self-referential composite initial cycle", () => {
|
|
|
131
131
|
states: { A: { initial: "A", states: { Leaf: { type: "script", file: "l.ts", next: DONE } } } },
|
|
132
132
|
};
|
|
133
133
|
|
|
134
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
134
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
135
135
|
{ kind: "initial-cycle", cycle: ["A"] },
|
|
136
136
|
]);
|
|
137
137
|
});
|
|
@@ -145,7 +145,7 @@ test("a cycle mid-chain that resolves to an unresolved id reports unresolved-tar
|
|
|
145
145
|
},
|
|
146
146
|
};
|
|
147
147
|
|
|
148
|
-
expect(validateWorkflow(registryFor(workflow), workflow
|
|
148
|
+
expect(validateWorkflow(registryFor(workflow), workflow)).toEqual([
|
|
149
149
|
{ kind: "unresolved-target", from: "B", target: "Missing" },
|
|
150
150
|
]);
|
|
151
151
|
});
|
|
@@ -160,7 +160,7 @@ test("collects every problem in one pass instead of stopping at the first", () =
|
|
|
160
160
|
},
|
|
161
161
|
};
|
|
162
162
|
|
|
163
|
-
const errors = validateWorkflow(registryFor(workflow), workflow
|
|
163
|
+
const errors = validateWorkflow(registryFor(workflow), workflow);
|
|
164
164
|
expect(errors).toEqual(
|
|
165
165
|
expect.arrayContaining([
|
|
166
166
|
{ kind: "unresolved-target", from: "A", target: "Missing1" },
|
|
@@ -170,3 +170,108 @@ test("collects every problem in one pass instead of stopping at the first", () =
|
|
|
170
170
|
);
|
|
171
171
|
expect(errors.length).toBe(3);
|
|
172
172
|
});
|
|
173
|
+
|
|
174
|
+
const runnerWorkflow: WorkflowDef = {
|
|
175
|
+
initial: "Group",
|
|
176
|
+
states: {
|
|
177
|
+
Group: {
|
|
178
|
+
initial: "Named",
|
|
179
|
+
states: {
|
|
180
|
+
Named: { type: "agent", agent: { model: "m" }, prompt: "p", runner: "other", next: "Bare" },
|
|
181
|
+
},
|
|
182
|
+
next: DONE,
|
|
183
|
+
},
|
|
184
|
+
Bare: { type: "agent", agent: { model: "m" }, prompt: "p", next: "Script" },
|
|
185
|
+
Script: { type: "script", file: "a.ts", next: DONE },
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
function runnerErrors(names: string[], hasDefault: boolean, workflow = runnerWorkflow) {
|
|
190
|
+
return validateWorkflow(registryFor(workflow), workflow, { names, hasDefault });
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
test("accepts agent states that each resolve to a runner", () => {
|
|
194
|
+
expect(runnerErrors(["other"], true)).toEqual([]);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test("flags an unregistered runner name, with the known names", () => {
|
|
198
|
+
expect(runnerErrors(["a", "b"], true)).toEqual([
|
|
199
|
+
{ kind: "unknown-runner", state: "Named", runner: "other", known: ["a", "b"] },
|
|
200
|
+
]);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test("flags a state naming no runner when there is no default, ignoring scripts", () => {
|
|
204
|
+
expect(runnerErrors(["other"], false)).toEqual([{ kind: "missing-runner", state: "Bare" }]);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test("needs no default when every agent state names a registered runner", () => {
|
|
208
|
+
const workflow: WorkflowDef = {
|
|
209
|
+
initial: "A",
|
|
210
|
+
states: {
|
|
211
|
+
A: { type: "agent", agent: { model: "m" }, prompt: "p", runner: "other", next: DONE },
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
expect(runnerErrors(["other"], false, workflow)).toEqual([]);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test("reports an inherited object key such as toString as unknown", () => {
|
|
219
|
+
const workflow: WorkflowDef = {
|
|
220
|
+
initial: "A",
|
|
221
|
+
states: {
|
|
222
|
+
A: { type: "agent", agent: { model: "m" }, prompt: "p", runner: "toString", next: DONE },
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
expect(runnerErrors([], true, workflow)).toEqual([
|
|
227
|
+
{ kind: "unknown-runner", state: "A", runner: "toString", known: [] },
|
|
228
|
+
]);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test("skips the runner checks without the runners argument", () => {
|
|
232
|
+
expect(validateWorkflow(registryFor(runnerWorkflow), runnerWorkflow)).toEqual([]);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
function modelErrors(workflow: WorkflowDef) {
|
|
236
|
+
return validateWorkflow(registryFor(workflow), workflow);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
test("flags every agent state without a non-empty string model, ignoring scripts", () => {
|
|
240
|
+
const workflow: WorkflowDef = {
|
|
241
|
+
initial: "Group",
|
|
242
|
+
states: {
|
|
243
|
+
Group: {
|
|
244
|
+
initial: "Bare",
|
|
245
|
+
states: { Bare: { type: "agent", prompt: "p", next: "Empty" } },
|
|
246
|
+
next: DONE,
|
|
247
|
+
},
|
|
248
|
+
Empty: { type: "agent", prompt: "p", agent: { model: "" }, next: "NotString" },
|
|
249
|
+
NotString: { type: "agent", prompt: "p", agent: { model: 7 }, next: "Pinned" },
|
|
250
|
+
Pinned: { type: "agent", prompt: "p", agent: { model: "m" }, next: "Script" },
|
|
251
|
+
Script: { type: "script", file: "a.ts", next: DONE },
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
expect(modelErrors(workflow)).toEqual([
|
|
256
|
+
{ kind: "missing-model", state: "Bare" },
|
|
257
|
+
{ kind: "missing-model", state: "Empty" },
|
|
258
|
+
{ kind: "missing-model", state: "NotString" },
|
|
259
|
+
]);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
test("takes the model from the default bag for default-runner states only", () => {
|
|
263
|
+
const workflow: WorkflowDef = {
|
|
264
|
+
initial: "Inherit",
|
|
265
|
+
agent: { model: "m" },
|
|
266
|
+
states: {
|
|
267
|
+
Inherit: { type: "agent", prompt: "p", agent: { auto: true }, next: "Cleared" },
|
|
268
|
+
Cleared: { type: "agent", prompt: "p", agent: { model: undefined }, next: "Named" },
|
|
269
|
+
Named: { type: "agent", prompt: "p", runner: "other", next: DONE },
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
expect(modelErrors(workflow)).toEqual([
|
|
274
|
+
{ kind: "missing-model", state: "Cleared" },
|
|
275
|
+
{ kind: "missing-model", state: "Named" },
|
|
276
|
+
]);
|
|
277
|
+
});
|
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,47 @@ 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
|
+
|
|
70
|
+
/** The runners a workflow has available, as names only — `core` never sees the objects. */
|
|
71
|
+
export interface AvailableRunners {
|
|
72
|
+
/** Names an agent state can select through `runner`. */
|
|
73
|
+
names: string[];
|
|
74
|
+
/** Whether a default runner exists for agent states that name none. */
|
|
75
|
+
hasDefault: boolean;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The `agent` bag a state dispatches with. The workflow's default bag belongs
|
|
80
|
+
* to the default runner only: a state that names a runner keeps its own bag, so
|
|
81
|
+
* no model or permission setting carries over to another harness. Always a new
|
|
82
|
+
* object, merged shallowly.
|
|
83
|
+
*/
|
|
84
|
+
export function effectiveAgent(
|
|
85
|
+
def: AgentStateDef,
|
|
86
|
+
defaultAgent?: WorkflowDef["agent"],
|
|
87
|
+
): Record<string, unknown> {
|
|
88
|
+
return { ...(def.runner === undefined ? defaultAgent : undefined), ...def.agent };
|
|
89
|
+
}
|
|
65
90
|
|
|
66
91
|
/**
|
|
67
92
|
* Eager, whole-graph structural check over an already-built registry — a
|
|
68
93
|
* second, cheap pass over the same flat `Map` `buildRegistry` produced, not
|
|
69
94
|
* a second tree-walk. Collects every problem found; never stops at the
|
|
70
95
|
* first. `DONE`/`FAILED` are valid targets only for a leaf's `on`/`next`,
|
|
71
|
-
* never for any `initial` (composite or top-level).
|
|
96
|
+
* never for any `initial` (composite or top-level). Without `runners`, the
|
|
97
|
+
* runner checks are skipped.
|
|
72
98
|
*/
|
|
73
99
|
export function validateWorkflow(
|
|
74
100
|
registry: Map<string, RegistryEntry>,
|
|
75
|
-
|
|
101
|
+
workflow: WorkflowDef,
|
|
102
|
+
runners?: AvailableRunners,
|
|
76
103
|
): WorkflowValidationError[] {
|
|
77
104
|
const errors: WorkflowValidationError[] = [];
|
|
105
|
+
const { initial } = workflow;
|
|
78
106
|
|
|
79
107
|
if (!registry.has(initial)) {
|
|
80
108
|
errors.push({ kind: "unresolved-target", from: null, target: initial });
|
|
@@ -100,6 +128,26 @@ export function validateWorkflow(
|
|
|
100
128
|
if (Object.keys(def.on ?? {}).length === 0 && def.next === undefined) {
|
|
101
129
|
errors.push({ kind: "dead-end-leaf", state: id });
|
|
102
130
|
}
|
|
131
|
+
|
|
132
|
+
if (def.type === "agent") {
|
|
133
|
+
const { model } = effectiveAgent(def, workflow.agent);
|
|
134
|
+
if (typeof model !== "string" || model === "") {
|
|
135
|
+
errors.push({ kind: "missing-model", state: id });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (runners && def.type === "agent") {
|
|
140
|
+
if (def.runner === undefined) {
|
|
141
|
+
if (!runners.hasDefault) errors.push({ kind: "missing-runner", state: id });
|
|
142
|
+
} else if (!runners.names.includes(def.runner)) {
|
|
143
|
+
errors.push({
|
|
144
|
+
kind: "unknown-runner",
|
|
145
|
+
state: id,
|
|
146
|
+
runner: def.runner,
|
|
147
|
+
known: runners.names,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
103
151
|
}
|
|
104
152
|
|
|
105
153
|
// Every composite in the registry is a chain-walk start, plus the
|
package/src/core/tasks.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Task, TaskList, TaskPriority, TaskRequirement, TaskStatus } from "./types.ts";
|
|
2
2
|
|
|
3
|
-
// Hand-written narrowing of unknown JSON to a TaskList (docs/specs/task-list-json/spec.md,
|
|
3
|
+
// Hand-written narrowing of unknown JSON to a TaskList (docs/specs/_built/task-list-json/spec.md,
|
|
4
4
|
// Decisions: Validation) — zero deps, no dual-schema tolerance: the legacy
|
|
5
5
|
// names (`moscow`, task-side `requirements`) are simply not read, and the
|
|
6
6
|
// result is either a TaskList or `{ error }`. The item-loop path and the
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { isNodeResult } from "./types.ts";
|
|
3
|
+
|
|
4
|
+
describe("isNodeResult", () => {
|
|
5
|
+
test("accepts the full envelope: typed event, output, agentSessionId", () => {
|
|
6
|
+
expect(isNodeResult({ event: "done", output: { ok: true }, agentSessionId: "ses_1" })).toBe(
|
|
7
|
+
true,
|
|
8
|
+
);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("accepts a bare object with no fields at all — everything is optional", () => {
|
|
12
|
+
expect(isNodeResult({})).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("accepts partial envelopes: event only, output only, agentSessionId only", () => {
|
|
16
|
+
expect(isNodeResult({ event: "planned" })).toBe(true);
|
|
17
|
+
expect(isNodeResult({ output: [1, 2, 3] })).toBe(true);
|
|
18
|
+
expect(isNodeResult({ agentSessionId: "ses_abc" })).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("accepts extra fields — the check is non-strict", () => {
|
|
22
|
+
expect(isNodeResult({ event: "done", agentSessionId: "ses_1", extra: "ignored" })).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("rejects null", () => {
|
|
26
|
+
expect(isNodeResult(null)).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("rejects other non-object values", () => {
|
|
30
|
+
expect(isNodeResult(undefined)).toBe(false);
|
|
31
|
+
expect(isNodeResult("done")).toBe(false);
|
|
32
|
+
expect(isNodeResult(42)).toBe(false);
|
|
33
|
+
expect(isNodeResult(true)).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("rejects a wrong-typed event", () => {
|
|
37
|
+
expect(isNodeResult({ event: 7 })).toBe(false);
|
|
38
|
+
expect(isNodeResult({ event: null })).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("rejects a wrong-typed agentSessionId", () => {
|
|
42
|
+
expect(isNodeResult({ agentSessionId: 42 })).toBe(false);
|
|
43
|
+
expect(isNodeResult({ agentSessionId: null })).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("rejects an array — new behavior; the hand-rolled check let it through", () => {
|
|
47
|
+
expect(isNodeResult(["done"])).toBe(false);
|
|
48
|
+
expect(isNodeResult([])).toBe(false);
|
|
49
|
+
// An array carrying the right keys on its elements still is not a NodeResult.
|
|
50
|
+
expect(isNodeResult([{ event: "done", agentSessionId: "ses_1" }])).toBe(false);
|
|
51
|
+
});
|
|
52
|
+
});
|
package/src/core/types.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import type { WorkflowValidationError } from "./graph.ts";
|
|
2
3
|
|
|
3
4
|
// What a leaf node's dispatch produces when it succeeds. This is also the
|
|
@@ -18,17 +19,20 @@ export interface NodeResult {
|
|
|
18
19
|
agentSessionId?: string;
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
// Same shape as the NodeResult interface above, one level of runtime
|
|
23
|
+
// checking added. Non-strict on purpose: extra fields pass, the same as the
|
|
24
|
+
// hand-rolled check this replaced. One deliberate behavior change: an array
|
|
25
|
+
// now fails, where the hand-rolled check let it through
|
|
26
|
+
// (docs/specs/output-validation/spec.md, "Extending `isNodeResult` to the
|
|
27
|
+
// same pattern").
|
|
28
|
+
const NodeResultSchema = z.object({
|
|
29
|
+
event: z.string().optional(),
|
|
30
|
+
output: z.unknown().optional(),
|
|
31
|
+
agentSessionId: z.string().optional(),
|
|
32
|
+
});
|
|
33
|
+
|
|
21
34
|
export function isNodeResult(value: unknown): value is NodeResult {
|
|
22
|
-
|
|
23
|
-
const v = value as Record<string, unknown>;
|
|
24
|
-
if ("event" in v && v.event !== undefined && typeof v.event !== "string") return false;
|
|
25
|
-
if (
|
|
26
|
-
"agentSessionId" in v &&
|
|
27
|
-
v.agentSessionId !== undefined &&
|
|
28
|
-
typeof v.agentSessionId !== "string"
|
|
29
|
-
)
|
|
30
|
-
return false;
|
|
31
|
-
return true;
|
|
35
|
+
return NodeResultSchema.safeParse(value).success;
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
// Sentinel target meaning "the whole workflow completed its work". Renders
|
|
@@ -39,7 +43,7 @@ export const DONE = "[*]" as const;
|
|
|
39
43
|
// since `[-]` has no built-in meaning to stateDiagram-v2 the way `[*]` does.
|
|
40
44
|
export const FAILED = "[-]" as const;
|
|
41
45
|
// Deprecated alias — kept only for a consumer repo's give-up edges, which still
|
|
42
|
-
// route to EXIT on its own schedule (docs/specs/failed-terminal/spec.md).
|
|
46
|
+
// route to EXIT on its own schedule (docs/specs/_built/failed-terminal/spec.md).
|
|
43
47
|
// Removed in the same change that lands the `run_failure` node + retarget
|
|
44
48
|
// table there; any surviving `EXIT` import then fails to compile.
|
|
45
49
|
export { DONE as EXIT };
|
|
@@ -53,7 +57,7 @@ export interface BaseLeafDef {
|
|
|
53
57
|
retries?: number;
|
|
54
58
|
/** Engine-enforced ceiling on one dispatch attempt. Default 1h. */
|
|
55
59
|
timeoutMs?: number;
|
|
56
|
-
/** Fixed interval between usage-limit re-probes after a provider quota wall. Default 30 min. See docs/specs/usage-limit-backoff/spec.md. */
|
|
60
|
+
/** Fixed interval between usage-limit re-probes after a provider quota wall. Default 30 min. See docs/specs/_built/usage-limit-backoff/spec.md. */
|
|
57
61
|
usageLimitRetryMs?: number;
|
|
58
62
|
/** Total wait budget per node visit for usage-limit backoff. At the cap the run crashes with the last usage-limit reason. Default 24h. */
|
|
59
63
|
usageLimitMaxWaitMs?: number;
|
|
@@ -69,6 +73,13 @@ export interface AgentStateDef extends BaseLeafDef {
|
|
|
69
73
|
type: "agent";
|
|
70
74
|
prompt: string;
|
|
71
75
|
agent?: Record<string, unknown>;
|
|
76
|
+
/** Key into the workflow's `agentRunners`. Absent: the default `agentRunner`. */
|
|
77
|
+
runner?: string;
|
|
78
|
+
outputType?: OutputSchema; // checks result.output, before `validate` runs
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface OutputSchema {
|
|
82
|
+
safeParse(value: unknown): { success: true } | { success: false; message: string };
|
|
72
83
|
}
|
|
73
84
|
|
|
74
85
|
export interface ScriptStateDef extends BaseLeafDef {
|
|
@@ -101,6 +112,8 @@ export type StateDef = AgentStateDef | ScriptStateDef | CompositeStateDef;
|
|
|
101
112
|
export interface WorkflowDef {
|
|
102
113
|
initial: string;
|
|
103
114
|
states: Record<string, StateDef>;
|
|
115
|
+
/** Default `agent` bag for states on the default runner. */
|
|
116
|
+
agent?: Record<string, unknown>;
|
|
104
117
|
}
|
|
105
118
|
|
|
106
119
|
export function isComposite(def: StateDef): def is CompositeStateDef {
|
|
@@ -150,7 +163,7 @@ export type AgentRunnerKind = "claude-code" | "opencode" | (string & {});
|
|
|
150
163
|
/**
|
|
151
164
|
* Incremental liveness signal a runner may report via `AgentRunner.run`'s
|
|
152
165
|
* optional `onProgress` callback, throttled to roughly once per 30s —
|
|
153
|
-
* see docs/specs/agent-liveness/spec.md. The engine owns the journal: a
|
|
166
|
+
* see docs/specs/_built/agent-liveness/spec.md. The engine owns the journal: a
|
|
154
167
|
* runner only ever reports its latest snapshot, never writes anything
|
|
155
168
|
* itself.
|
|
156
169
|
*/
|
|
@@ -164,12 +177,24 @@ export interface AgentProgress {
|
|
|
164
177
|
lastEvent: string;
|
|
165
178
|
}
|
|
166
179
|
|
|
180
|
+
/** One model id a runner does not recognize, and why. */
|
|
181
|
+
export interface ModelWarning {
|
|
182
|
+
model: string;
|
|
183
|
+
message: string;
|
|
184
|
+
}
|
|
185
|
+
|
|
167
186
|
export interface AgentRunner {
|
|
168
187
|
/** Self-identification (e.g. `"opencode"`, `"claude-code"`), set once per
|
|
169
188
|
* runner implementation. Read by darkf-cli at run-start time to record
|
|
170
189
|
* which runner executed a run; absent for runners that don't identify
|
|
171
190
|
* themselves. */
|
|
172
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[]>;
|
|
173
198
|
run(
|
|
174
199
|
id: string,
|
|
175
200
|
def: AgentStateDef,
|
|
@@ -204,9 +229,14 @@ export type NodeStatus =
|
|
|
204
229
|
startedAt: number;
|
|
205
230
|
lastHeartbeat: number;
|
|
206
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;
|
|
207
237
|
/** Latest step count from the agent's own event stream, when the
|
|
208
238
|
* runner reports progress (`AgentRunner.run`'s optional
|
|
209
|
-
* `onProgress`) — see docs/specs/agent-liveness/spec.md. Absent for
|
|
239
|
+
* `onProgress`) — see docs/specs/_built/agent-liveness/spec.md. Absent for
|
|
210
240
|
* script dispatches or runners that don't report progress. */
|
|
211
241
|
agentStepCount?: number;
|
|
212
242
|
/** Milliseconds since the last agent-reported progress event, as of
|
|
@@ -216,12 +246,12 @@ export type NodeStatus =
|
|
|
216
246
|
* conditions as `agentStepCount`. */
|
|
217
247
|
agentIdleMs?: number;
|
|
218
248
|
/** Set only while the engine is nudging this attempt (1..3) — see
|
|
219
|
-
* docs/specs/session-nudge/spec.md. Absent on an ordinary dispatch. */
|
|
249
|
+
* docs/specs/_built/session-nudge/spec.md. Absent on an ordinary dispatch. */
|
|
220
250
|
nudgeAttempt?: number;
|
|
221
251
|
/** The nudgeable `CrashReason` kind that triggered this nudge. */
|
|
222
252
|
nudgeReason?: CrashReason["kind"];
|
|
223
253
|
/** Present only while the engine is waiting out a provider usage-limit
|
|
224
|
-
* backoff for this attempt — see docs/specs/usage-limit-backoff/spec.md. */
|
|
254
|
+
* backoff for this attempt — see docs/specs/_built/usage-limit-backoff/spec.md. */
|
|
225
255
|
limitBackoff?: { probe: number; nextAttemptAt: number; waitedMs: number };
|
|
226
256
|
}
|
|
227
257
|
| { phase: "succeeded"; result: NodeResult }
|
|
@@ -249,7 +279,7 @@ export type CrashReason =
|
|
|
249
279
|
* `Error` can't: the session id to resume, and which `CrashReason` kind this
|
|
250
280
|
* is — so the engine can route the correct nudge template without
|
|
251
281
|
* inspecting the error message string. See
|
|
252
|
-
* docs/specs/session-nudge/spec.md.
|
|
282
|
+
* docs/specs/_built/session-nudge/spec.md.
|
|
253
283
|
*/
|
|
254
284
|
export class AgentFailure extends Error {
|
|
255
285
|
agentSessionId?: string;
|
|
@@ -288,7 +318,7 @@ export interface RunResult {
|
|
|
288
318
|
|
|
289
319
|
// --- Task lists ---
|
|
290
320
|
//
|
|
291
|
-
// One shared vocabulary for plan/dispatch task lists (docs/specs/task-list-json/spec.md):
|
|
321
|
+
// One shared vocabulary for plan/dispatch task lists (docs/specs/_built/task-list-json/spec.md):
|
|
292
322
|
// workflows write it, `parseTaskList` narrows it, the OpenCode plugin renders it.
|
|
293
323
|
// Lowercase MoSCoW and `satisfies` are the locked names — the validator has no
|
|
294
324
|
// tolerance for the legacy shapes (`moscow`, task-side `requirements`).
|