@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/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/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
|