@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/cli/detached.test.ts
CHANGED
|
@@ -134,7 +134,7 @@ export const agentRunner: AgentRunner = {
|
|
|
134
134
|
export const workflow: WorkflowDef = {
|
|
135
135
|
initial: "Plan",
|
|
136
136
|
states: {
|
|
137
|
-
Plan: { type: "agent", prompt: "plan", on: { approved: "Implement" } },
|
|
137
|
+
Plan: { type: "agent", agent: { model: "test-model" }, prompt: "plan", on: { approved: "Implement" } },
|
|
138
138
|
Implement: {
|
|
139
139
|
initial: "Write",
|
|
140
140
|
states: {
|
|
@@ -142,7 +142,7 @@ export const workflow: WorkflowDef = {
|
|
|
142
142
|
Test: { type: "script", file: "test.ts", on: { passed: "Review" } },
|
|
143
143
|
},
|
|
144
144
|
},
|
|
145
|
-
Review: { type: "agent", prompt: "review", on: { done: EXIT } },
|
|
145
|
+
Review: { type: "agent", agent: { model: "test-model" }, prompt: "review", on: { done: EXIT } },
|
|
146
146
|
},
|
|
147
147
|
};
|
|
148
148
|
`,
|
|
@@ -302,6 +302,92 @@ test("status and monitor report succeeded for a run of the haiku-readme example"
|
|
|
302
302
|
expect(mon.stdout).toContain("succeeded");
|
|
303
303
|
});
|
|
304
304
|
|
|
305
|
+
// --- per-state runners ---
|
|
306
|
+
|
|
307
|
+
// Two stubs that report which one ran, and a default `kind` unlike the named one.
|
|
308
|
+
const TWO_RUNNERS: Record<string, string> = {
|
|
309
|
+
"workflow.ts": `import { type AgentRunner, EXIT, type WorkflowDef } from "@psimona/darkf/src/core/index.ts";
|
|
310
|
+
export const agentRunner: AgentRunner = {
|
|
311
|
+
kind: "opencode",
|
|
312
|
+
async run() { return { by: "default" }; },
|
|
313
|
+
};
|
|
314
|
+
export const agentRunners: Record<string, AgentRunner> = {
|
|
315
|
+
other: {
|
|
316
|
+
kind: "claude-code",
|
|
317
|
+
async run(_id, _def, handoff) { return { first: handoff.output, second: "other" }; },
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
export const workflow: WorkflowDef = {
|
|
321
|
+
initial: "A",
|
|
322
|
+
states: {
|
|
323
|
+
A: { type: "agent", agent: { model: "test-model" }, prompt: "a", next: "B" },
|
|
324
|
+
B: { type: "agent", runner: "other", agent: { model: "test-model" }, prompt: "b", next: EXIT },
|
|
325
|
+
},
|
|
326
|
+
};
|
|
327
|
+
`,
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
test("run passes agentRunners to the engine and records the default runner's kind", async () => {
|
|
331
|
+
const root = makeProjectRoot();
|
|
332
|
+
writeFixture(root, "two-runners", TWO_RUNNERS);
|
|
333
|
+
|
|
334
|
+
const res = await runCli(["run", "two-runners"], root);
|
|
335
|
+
|
|
336
|
+
expect(res.stdout).toContain("status: succeeded");
|
|
337
|
+
expect(res.stdout).toContain('by: "default"');
|
|
338
|
+
expect(res.stdout).toContain('second: "other"');
|
|
339
|
+
expect(listEntries(root)[0]?.agentRunnerKind).toBe("opencode");
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
test("the detached worker passes agentRunners and records the default runner's kind", async () => {
|
|
343
|
+
const root = makeProjectRoot();
|
|
344
|
+
writeFixture(root, "two-runners", TWO_RUNNERS);
|
|
345
|
+
// The entry exists before the worker starts, so its `kind` merge has a target.
|
|
346
|
+
const runId = randomUUID();
|
|
347
|
+
writeEntry(root, {
|
|
348
|
+
schemaVersion: SCHEMA_VERSION,
|
|
349
|
+
runId,
|
|
350
|
+
pid: process.pid,
|
|
351
|
+
rootDir: root,
|
|
352
|
+
startedAt: Date.now(),
|
|
353
|
+
status: "running",
|
|
354
|
+
finishedAt: null,
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
const worker = await runCli(["__worker", "two-runners", runId], root);
|
|
358
|
+
|
|
359
|
+
expect(worker.code).toBe(0);
|
|
360
|
+
expect(journalTerminalState(root, runId)).toBe("succeeded");
|
|
361
|
+
expect(readEntry(root, runId)?.agentRunnerKind).toBe("opencode");
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
test("report shows the runner name and kind of each agent dispatch", async () => {
|
|
365
|
+
const root = makeProjectRoot();
|
|
366
|
+
writeFixture(root, "two-runners", TWO_RUNNERS);
|
|
367
|
+
await runCli(["run", "two-runners"], root);
|
|
368
|
+
const runId = listEntries(root)[0]!.runId;
|
|
369
|
+
|
|
370
|
+
const res = await runCli(["report", "--run", runId], root);
|
|
371
|
+
|
|
372
|
+
expect(res.code).toBe(0);
|
|
373
|
+
expect(res.stdout).toMatch(/^ {2}A .*-> \(no event\) {2}kind=opencode$/m);
|
|
374
|
+
expect(res.stdout).toMatch(/^ {2}B .*-> \(no event\) {2}runner=other {2}kind=claude-code$/m);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
test("run crashes on an unknown runner name before any dispatch", async () => {
|
|
378
|
+
const root = makeProjectRoot();
|
|
379
|
+
const workflow = TWO_RUNNERS["workflow.ts"]!.replace('runner: "other"', 'runner: "typo"');
|
|
380
|
+
writeFixture(root, "typo", { "workflow.ts": workflow });
|
|
381
|
+
|
|
382
|
+
const res = await runCli(["run", "typo"], root);
|
|
383
|
+
|
|
384
|
+
expect(res.stdout).toContain("status: crashed");
|
|
385
|
+
expect(res.stdout).toContain(
|
|
386
|
+
'{"kind":"unknown-runner","state":"B","runner":"typo","known":["other"]}',
|
|
387
|
+
);
|
|
388
|
+
expect(res.stdout).not.toContain("A -> event=");
|
|
389
|
+
});
|
|
390
|
+
|
|
305
391
|
// --- crashed ---
|
|
306
392
|
|
|
307
393
|
test("status and monitor report crashed (with reason) for a run that crashes mid-run", async () => {
|
package/src/cli/doctor.test.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { afterAll, expect, test } from "bun:test";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
cpSync,
|
|
4
|
+
existsSync,
|
|
5
|
+
mkdirSync,
|
|
6
|
+
mkdtempSync,
|
|
7
|
+
readdirSync,
|
|
8
|
+
readFileSync,
|
|
9
|
+
rmSync,
|
|
10
|
+
writeFileSync,
|
|
11
|
+
} from "node:fs";
|
|
3
12
|
import { tmpdir } from "node:os";
|
|
4
13
|
import { join, resolve } from "node:path";
|
|
5
14
|
import { todayLocal, writeProbeState } from "./setup.ts";
|
|
@@ -160,19 +169,23 @@ import { claudeCodeRunner } from "${pkgDir}/src/kit/agents/claude-code.ts";
|
|
|
160
169
|
export const agentRunner: AgentRunner = claudeCodeRunner;
|
|
161
170
|
`;
|
|
162
171
|
|
|
163
|
-
function writeFixture(env: Env, name: string, states: string): string {
|
|
172
|
+
function writeFixture(env: Env, name: string, states: string, extra = ""): string {
|
|
164
173
|
const dir = join(env.cwd, name);
|
|
165
174
|
mkdirSync(dir, { recursive: true });
|
|
166
175
|
writeFileSync(
|
|
167
176
|
join(dir, "workflow.ts"),
|
|
168
|
-
`${RUNNER_IMPORTS}\nexport const workflow: WorkflowDef = {\n initial: "A",\n states: { ${states} },\n};\n`,
|
|
177
|
+
`${RUNNER_IMPORTS}\nexport const workflow: WorkflowDef = {\n initial: "A",\n ${extra}\n states: { ${states} },\n};\n`,
|
|
169
178
|
);
|
|
170
179
|
return dir;
|
|
171
180
|
}
|
|
172
181
|
|
|
173
182
|
test("validate inherits the workflow checks: happy path, same lines, exit 0", async () => {
|
|
174
183
|
const env = makeEnv();
|
|
175
|
-
const dir = writeFixture(
|
|
184
|
+
const dir = writeFixture(
|
|
185
|
+
env,
|
|
186
|
+
"happy",
|
|
187
|
+
`A: { type: "agent", agent: { model: "claude-test-model" }, prompt: "p", on: { done: EXIT } }`,
|
|
188
|
+
);
|
|
176
189
|
|
|
177
190
|
const res = await runCli(["validate", dir], env);
|
|
178
191
|
|
|
@@ -182,7 +195,7 @@ test("validate inherits the workflow checks: happy path, same lines, exit 0", as
|
|
|
182
195
|
`ok workflow resolves — ${dir}`,
|
|
183
196
|
"ok workflow.ts loads",
|
|
184
197
|
"ok exports `workflow`",
|
|
185
|
-
"ok
|
|
198
|
+
"ok agent runners",
|
|
186
199
|
"ok workflow structure",
|
|
187
200
|
]);
|
|
188
201
|
expect(res.code).toBe(0);
|
|
@@ -193,16 +206,214 @@ test("validate reports unresolved targets", async () => {
|
|
|
193
206
|
const dir = writeFixture(
|
|
194
207
|
env,
|
|
195
208
|
"unresolved",
|
|
196
|
-
`A: { type: "agent", prompt: "p", on: { done: "nope" } }`,
|
|
209
|
+
`A: { type: "agent", agent: { model: "claude-test-model" }, prompt: "p", on: { done: "nope" } }`,
|
|
197
210
|
);
|
|
198
211
|
const res = await runCli(["validate", dir], env);
|
|
199
212
|
expect(lines(res.stdout)).toContain('FAIL workflow structure — A -> "nope": no such state');
|
|
200
213
|
expect(res.code).toBe(1);
|
|
201
214
|
});
|
|
202
215
|
|
|
216
|
+
test("validate reports an agent state with no model, and accepts the workflow default", async () => {
|
|
217
|
+
const env = makeEnv();
|
|
218
|
+
const bare = writeFixture(
|
|
219
|
+
env,
|
|
220
|
+
"no-model",
|
|
221
|
+
`A: { type: "agent", prompt: "p", on: { done: EXIT } }`,
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const res = await runCli(["validate", bare], env);
|
|
225
|
+
|
|
226
|
+
expect(lines(res.stdout)).toContain(
|
|
227
|
+
'FAIL workflow structure — "A": no model, pin agent: { model } on the state or, without a runner, on the workflow',
|
|
228
|
+
);
|
|
229
|
+
expect(res.code).toBe(1);
|
|
230
|
+
|
|
231
|
+
const defaulted = writeFixture(
|
|
232
|
+
env,
|
|
233
|
+
"default-model",
|
|
234
|
+
`A: { type: "agent", prompt: "p", on: { done: EXIT } }`,
|
|
235
|
+
`agent: { model: "claude-test-model" },`,
|
|
236
|
+
);
|
|
237
|
+
expect((await runCli(["validate", defaulted], env)).code).toBe(0);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// --- validate: per-state runners (stub runners, never dispatched) ---
|
|
241
|
+
|
|
242
|
+
const STUB = `{ async run() { return { event: "done" }; } }`;
|
|
243
|
+
|
|
244
|
+
/** A workflow module with exactly the runner exports given, none implied. */
|
|
245
|
+
function writeRunnerFixture(env: Env, name: string, exports: string, states: string): string {
|
|
246
|
+
const dir = join(env.cwd, name);
|
|
247
|
+
mkdirSync(dir, { recursive: true });
|
|
248
|
+
writeFileSync(
|
|
249
|
+
join(dir, "workflow.ts"),
|
|
250
|
+
`import { EXIT, type WorkflowDef } from "${pkgDir}/src/core/index.ts";\n${exports}\nexport const workflow: WorkflowDef = {\n initial: "A",\n states: { ${states} },\n};\n`,
|
|
251
|
+
);
|
|
252
|
+
return dir;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function agentState(runner?: string, next = "EXIT"): string {
|
|
256
|
+
const selected = runner === undefined ? "" : `runner: "${runner}", `;
|
|
257
|
+
return `{ type: "agent", ${selected}agent: { model: "claude-test-model" }, prompt: "p", next: ${next} }`;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
test("validate reports an unknown runner name with the state and the known names", async () => {
|
|
261
|
+
const env = makeEnv();
|
|
262
|
+
const dir = writeRunnerFixture(
|
|
263
|
+
env,
|
|
264
|
+
"unknown-runner",
|
|
265
|
+
`export const agentRunner = ${STUB};\nexport const agentRunners = { claude: ${STUB}, other: ${STUB} };`,
|
|
266
|
+
`A: ${agentState("typo", `"B"`)}, B: ${agentState("toString")}`,
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
const res = await runCli(["validate", dir], env);
|
|
270
|
+
|
|
271
|
+
const out = lines(res.stdout);
|
|
272
|
+
expect(out).toContain(
|
|
273
|
+
'FAIL workflow structure — "A": unknown runner "typo", known: claude, other',
|
|
274
|
+
);
|
|
275
|
+
expect(out).toContain(
|
|
276
|
+
'FAIL workflow structure — "B": unknown runner "toString", known: claude, other',
|
|
277
|
+
);
|
|
278
|
+
expect(res.code).toBe(1);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test("validate needs no default runner when every agent state names a registered one", async () => {
|
|
282
|
+
const env = makeEnv();
|
|
283
|
+
const exports = `export const agentRunners = { claude: ${STUB} };`;
|
|
284
|
+
const named = writeRunnerFixture(env, "all-named", exports, `A: ${agentState("claude")}`);
|
|
285
|
+
|
|
286
|
+
const passing = await runCli(["validate", named], env);
|
|
287
|
+
|
|
288
|
+
expect(lines(passing.stdout)).toContain("ok agent runners");
|
|
289
|
+
expect(passing.code).toBe(0);
|
|
290
|
+
|
|
291
|
+
const bare = writeRunnerFixture(
|
|
292
|
+
env,
|
|
293
|
+
"one-bare",
|
|
294
|
+
exports,
|
|
295
|
+
`A: ${agentState("claude", `"B"`)}, B: ${agentState()}`,
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
const failing = await runCli(["validate", bare], env);
|
|
299
|
+
|
|
300
|
+
expect(lines(failing.stdout)).toContain(
|
|
301
|
+
'FAIL workflow structure — "B": names no runner and the workflow has no default agentRunner',
|
|
302
|
+
);
|
|
303
|
+
expect(failing.code).toBe(1);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test("validate needs no runner for a workflow without agent states", async () => {
|
|
307
|
+
const env = makeEnv();
|
|
308
|
+
const dir = writeRunnerFixture(
|
|
309
|
+
env,
|
|
310
|
+
"scripts-only",
|
|
311
|
+
"",
|
|
312
|
+
`A: { type: "script", file: "a.ts", next: EXIT }`,
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
expect((await runCli(["validate", dir], env)).code).toBe(0);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test("validate fails each present runner export that has no run function", async () => {
|
|
319
|
+
const env = makeEnv();
|
|
320
|
+
const dir = writeRunnerFixture(
|
|
321
|
+
env,
|
|
322
|
+
"no-run",
|
|
323
|
+
`export const agentRunner = {};\nexport const agentRunners = { good: ${STUB}, bad: { kind: "x" }, empty: undefined };`,
|
|
324
|
+
`A: ${agentState("good")}`,
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
const res = await runCli(["validate", dir], env);
|
|
328
|
+
|
|
329
|
+
expect(lines(res.stdout).filter((l) => l.includes("agent runners"))).toEqual([
|
|
330
|
+
"FAIL agent runners — agentRunner has no run function",
|
|
331
|
+
"FAIL agent runners — agentRunners.bad has no run function",
|
|
332
|
+
"FAIL agent runners — agentRunners.empty has no run function",
|
|
333
|
+
]);
|
|
334
|
+
expect(res.code).toBe(1);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
// --- validate: advisory model checks (a fake `opencode` on PATH) ---
|
|
338
|
+
|
|
339
|
+
/** PATH extension holding an `opencode` stand-in that runs `script`. */
|
|
340
|
+
function fakeOpencode(script: string): Record<string, string> {
|
|
341
|
+
const bin = tempDir();
|
|
342
|
+
writeFileSync(join(bin, "opencode"), `#!/bin/sh\n${script}\n`, { mode: 0o755 });
|
|
343
|
+
return { PATH: `${bin}:${process.env.PATH}` };
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function writeModelFixture(env: Env): string {
|
|
347
|
+
const state = (model: string, next: string, runner = "") =>
|
|
348
|
+
`{ type: "agent", ${runner}agent: { model: "${model}" }, prompt: "p", next: ${next} }`;
|
|
349
|
+
return writeRunnerFixture(
|
|
350
|
+
env,
|
|
351
|
+
"models",
|
|
352
|
+
[
|
|
353
|
+
`import { claudeCodeRunner } from "${pkgDir}/src/kit/agents/claude-code.ts";`,
|
|
354
|
+
`import { opencodeRunner } from "${pkgDir}/src/kit/agents/opencode.ts";`,
|
|
355
|
+
"export const agentRunner = opencodeRunner;",
|
|
356
|
+
"export const agentRunners = { claude: claudeCodeRunner };",
|
|
357
|
+
].join("\n"),
|
|
358
|
+
[
|
|
359
|
+
`A: ${state("acme/listed#high", '"B"')}`,
|
|
360
|
+
`B: ${state("acme/typo", '"C"')}`,
|
|
361
|
+
`C: ${state("acme/listed", '"D"', 'runner: "claude", ')}`,
|
|
362
|
+
`D: ${state("claude-sonnet-5-5", "EXIT", 'runner: "claude", ')}`,
|
|
363
|
+
].join(", "),
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
test("validate warns about unrecognized models without failing", async () => {
|
|
368
|
+
const env = makeEnv();
|
|
369
|
+
const dir = writeModelFixture(env);
|
|
370
|
+
|
|
371
|
+
const res = await runCli(["validate", dir], env, fakeOpencode("echo acme/listed"));
|
|
372
|
+
|
|
373
|
+
expect(lines(res.stdout).filter((l) => l.startsWith("warn"))).toEqual([
|
|
374
|
+
'warn agent models — "B": model "acme/typo" is not in `opencode models`',
|
|
375
|
+
'warn agent models — "C": model "acme/listed" is neither a Claude Code alias nor a "claude-" id',
|
|
376
|
+
]);
|
|
377
|
+
expect(res.code).toBe(0);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
test("validate warns when the model list is unavailable", async () => {
|
|
381
|
+
const env = makeEnv();
|
|
382
|
+
const dir = writeModelFixture(env);
|
|
383
|
+
|
|
384
|
+
const res = await runCli(["validate", dir], env, fakeOpencode("exit 3"));
|
|
385
|
+
|
|
386
|
+
expect(lines(res.stdout)).toContain(
|
|
387
|
+
'warn agent models — "A", "B": could not check the model: `opencode models` exited 3 with 0 models',
|
|
388
|
+
);
|
|
389
|
+
expect(res.code).toBe(0);
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
test("every shipped workflow and example passes validate", async () => {
|
|
393
|
+
const env = makeEnv();
|
|
394
|
+
// Keeps the suite off the real opencode CLI.
|
|
395
|
+
const path = fakeOpencode("echo zai-coding-plan/glm-5.3-flash");
|
|
396
|
+
const dirs = ["workflows", "examples"].flatMap((root) =>
|
|
397
|
+
readdirSync(join(pkgDir, root))
|
|
398
|
+
.map((name) => join(pkgDir, root, name))
|
|
399
|
+
.filter((dir) => existsSync(join(dir, "workflow.ts"))),
|
|
400
|
+
);
|
|
401
|
+
expect(dirs.length).toBeGreaterThan(0);
|
|
402
|
+
|
|
403
|
+
const results = await Promise.all(
|
|
404
|
+
dirs.map(async (dir) => ({ dir, ...(await runCli(["validate", dir], env, path)) })),
|
|
405
|
+
);
|
|
406
|
+
|
|
407
|
+
expect(results.filter((r) => r.code !== 0).map((r) => `${r.dir}\n${r.stdout}`)).toEqual([]);
|
|
408
|
+
}, 30_000);
|
|
409
|
+
|
|
203
410
|
test("validate reports dead-end leaves", async () => {
|
|
204
411
|
const env = makeEnv();
|
|
205
|
-
const dir = writeFixture(
|
|
412
|
+
const dir = writeFixture(
|
|
413
|
+
env,
|
|
414
|
+
"dead-end",
|
|
415
|
+
`A: { type: "agent", agent: { model: "claude-test-model" }, prompt: "p" }`,
|
|
416
|
+
);
|
|
206
417
|
const res = await runCli(["validate", dir], env);
|
|
207
418
|
expect(lines(res.stdout)).toContain('FAIL workflow structure — "A": dead end, no on/next');
|
|
208
419
|
expect(res.code).toBe(1);
|
|
@@ -244,7 +455,7 @@ test("validate with an unresolvable ref skips the load and exports checks", asyn
|
|
|
244
455
|
expect(out[0]).toContain("FAIL workflow resolves");
|
|
245
456
|
expect(out).toContain("FAIL workflow.ts loads — skipped — no resolved workflow");
|
|
246
457
|
expect(out).toContain("FAIL exports `workflow` — skipped — no resolved workflow");
|
|
247
|
-
expect(out).toContain("FAIL
|
|
458
|
+
expect(out).toContain("FAIL agent runners — skipped — no resolved workflow");
|
|
248
459
|
expect(out).toHaveLength(4);
|
|
249
460
|
expect(res.code).toBe(1);
|
|
250
461
|
});
|
|
@@ -252,7 +463,11 @@ test("validate with an unresolvable ref skips the load and exports checks", asyn
|
|
|
252
463
|
test("validate does not check skills — stale copies never touch its verdict", async () => {
|
|
253
464
|
const env = makeEnv();
|
|
254
465
|
seedStale(env, ".claude", "darkf-usage");
|
|
255
|
-
const dir = writeFixture(
|
|
466
|
+
const dir = writeFixture(
|
|
467
|
+
env,
|
|
468
|
+
"happy",
|
|
469
|
+
`A: { type: "agent", agent: { model: "claude-test-model" }, prompt: "p", on: { done: EXIT } }`,
|
|
470
|
+
);
|
|
256
471
|
|
|
257
472
|
const res = await runCli(["validate", dir], env);
|
|
258
473
|
|
package/src/cli/index.ts
CHANGED
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
type AgentRunner,
|
|
10
10
|
buildRegistry,
|
|
11
11
|
DONE,
|
|
12
|
+
effectiveAgent,
|
|
13
|
+
isComposite,
|
|
12
14
|
type NodeEvent,
|
|
13
15
|
type NodeResult,
|
|
14
16
|
parseEventLog,
|
|
@@ -19,7 +21,7 @@ import {
|
|
|
19
21
|
type WorkflowDef,
|
|
20
22
|
type WorkflowValidationError,
|
|
21
23
|
} from "../core/index.ts";
|
|
22
|
-
import { run } from "../engine/index.ts";
|
|
24
|
+
import { run, selectRunner } from "../engine/index.ts";
|
|
23
25
|
import {
|
|
24
26
|
currentBootId,
|
|
25
27
|
detectSupervisorSignal,
|
|
@@ -73,7 +75,10 @@ const WORKER_LOG_TAIL_CHARS = 2000;
|
|
|
73
75
|
interface WorkflowModule {
|
|
74
76
|
workflow: WorkflowDef;
|
|
75
77
|
input?: NodeResult;
|
|
78
|
+
/** Default runner, for agent states that name none. */
|
|
76
79
|
agentRunner?: AgentRunner;
|
|
80
|
+
/** Runners an agent state selects by name through `runner`. */
|
|
81
|
+
agentRunners?: Record<string, AgentRunner>;
|
|
77
82
|
/** Opt-in override for run-aware script dispatch — e.g. a script needing
|
|
78
83
|
* `.darkf/run/<runId>/...` for its own artifacts (see DispatchInfo's own
|
|
79
84
|
* docs in darkf-core). Omitted: falls back to darkf-engine's default,
|
|
@@ -185,7 +190,9 @@ async function reportCmd(args: string[]): Promise<void> {
|
|
|
185
190
|
: d.phase === "failed"
|
|
186
191
|
? `-> FAILED${d.event ? ` ${d.event}` : ""}`
|
|
187
192
|
: `-> CRASHED ${d.reason ? JSON.stringify(d.reason) : ""}`;
|
|
188
|
-
|
|
193
|
+
const ran =
|
|
194
|
+
(d.runner ? ` runner=${d.runner}` : "") + (d.runnerKind ? ` kind=${d.runnerKind}` : "");
|
|
195
|
+
console.log(` ${d.state.padEnd(12)} ${seconds(d.durationMs).padStart(9)} ${outcome}${ran}`);
|
|
189
196
|
}
|
|
190
197
|
if (report.crashReasons.length) {
|
|
191
198
|
console.log(`crashes: ${report.crashReasons.length}`);
|
|
@@ -235,6 +242,12 @@ function describeValidationError(err: WorkflowValidationError): string {
|
|
|
235
242
|
return `initial cycle: ${err.cycle.join(" -> ")} -> ${err.cycle[0]}`;
|
|
236
243
|
case "dead-end-leaf":
|
|
237
244
|
return `"${err.state}": dead end, no on/next`;
|
|
245
|
+
case "unknown-runner":
|
|
246
|
+
return `"${err.state}": unknown runner "${err.runner}", known: ${err.known.join(", ") || "none"}`;
|
|
247
|
+
case "missing-runner":
|
|
248
|
+
return `"${err.state}": names no runner and the workflow has no default agentRunner`;
|
|
249
|
+
case "missing-model":
|
|
250
|
+
return `"${err.state}": no model, pin agent: { model } on the state or, without a runner, on the workflow`;
|
|
238
251
|
}
|
|
239
252
|
}
|
|
240
253
|
|
|
@@ -259,6 +272,50 @@ function makeChecker(): {
|
|
|
259
272
|
return { check, failed: () => fail };
|
|
260
273
|
}
|
|
261
274
|
|
|
275
|
+
/** Every runner export that is present but cannot be dispatched to. */
|
|
276
|
+
function unrunnableRunners({ agentRunner, agentRunners }: WorkflowModule): string[] {
|
|
277
|
+
const present: Array<[string, unknown]> = Object.entries(agentRunners ?? {}).map(
|
|
278
|
+
([name, runner]) => [`agentRunners.${name}`, runner],
|
|
279
|
+
);
|
|
280
|
+
if (agentRunner !== undefined) present.unshift(["agentRunner", agentRunner]);
|
|
281
|
+
return present
|
|
282
|
+
.filter(([, runner]) => typeof (runner as Partial<AgentRunner> | null)?.run !== "function")
|
|
283
|
+
.map(([name]) => name);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** Asks each runner about the models its agent states use, one call per runner. */
|
|
287
|
+
async function modelWarnings(
|
|
288
|
+
mod: WorkflowModule,
|
|
289
|
+
registry: ReturnType<typeof buildRegistry>,
|
|
290
|
+
rootDir: string,
|
|
291
|
+
): Promise<string[]> {
|
|
292
|
+
// runner -> model -> the states that use it
|
|
293
|
+
const used = new Map<AgentRunner, Map<string, string[]>>();
|
|
294
|
+
for (const [state, { def }] of registry) {
|
|
295
|
+
if (isComposite(def) || def.type !== "agent") continue;
|
|
296
|
+
const runner = selectRunner(mod, def);
|
|
297
|
+
const { model } = effectiveAgent(def, mod.workflow.agent);
|
|
298
|
+
if (typeof runner?.checkModels !== "function" || typeof model !== "string" || !model) continue;
|
|
299
|
+
const models = used.get(runner) ?? new Map<string, string[]>();
|
|
300
|
+
models.set(model, [...(models.get(model) ?? []), state]);
|
|
301
|
+
used.set(runner, models);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const warnings: string[] = [];
|
|
305
|
+
for (const [runner, models] of used) {
|
|
306
|
+
try {
|
|
307
|
+
for (const { model, message } of await runner.checkModels!([...models.keys()], rootDir)) {
|
|
308
|
+
for (const state of models.get(model) ?? []) warnings.push(`"${state}": ${message}`);
|
|
309
|
+
}
|
|
310
|
+
} catch (err) {
|
|
311
|
+
const states = [...models.values()].flat().map((state) => `"${state}"`);
|
|
312
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
313
|
+
warnings.push(`${states.join(", ")}: could not check the model: ${detail}`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return warnings;
|
|
317
|
+
}
|
|
318
|
+
|
|
262
319
|
async function validateCmd(args: string[]): Promise<number> {
|
|
263
320
|
const ref = args[0];
|
|
264
321
|
const { check, failed } = makeChecker();
|
|
@@ -287,15 +344,21 @@ async function validateCmd(args: string[]): Promise<number> {
|
|
|
287
344
|
"exports `workflow`",
|
|
288
345
|
typeof mod.workflow?.states === "object" && typeof mod.workflow?.initial === "string",
|
|
289
346
|
);
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
347
|
+
const unrunnable = unrunnableRunners(mod);
|
|
348
|
+
if (unrunnable.length === 0) {
|
|
349
|
+
check("agent runners", true);
|
|
350
|
+
} else {
|
|
351
|
+
for (const name of unrunnable) {
|
|
352
|
+
check("agent runners", false, `${name} has no run function`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
295
355
|
if (typeof mod.workflow?.states === "object" && typeof mod.workflow?.initial === "string") {
|
|
296
356
|
try {
|
|
297
357
|
const registry = buildRegistry(mod.workflow);
|
|
298
|
-
const errors = validateWorkflow(registry, mod.workflow
|
|
358
|
+
const errors = validateWorkflow(registry, mod.workflow, {
|
|
359
|
+
names: Object.keys(mod.agentRunners ?? {}),
|
|
360
|
+
hasDefault: mod.agentRunner !== undefined,
|
|
361
|
+
});
|
|
299
362
|
if (errors.length === 0) {
|
|
300
363
|
check("workflow structure", true);
|
|
301
364
|
} else {
|
|
@@ -303,6 +366,10 @@ async function validateCmd(args: string[]): Promise<number> {
|
|
|
303
366
|
check("workflow structure", false, describeValidationError(err));
|
|
304
367
|
}
|
|
305
368
|
}
|
|
369
|
+
// Advisory only: a warning never changes the exit code.
|
|
370
|
+
for (const warning of await modelWarnings(mod, registry, process.cwd())) {
|
|
371
|
+
console.log(`warn agent models — ${warning}`);
|
|
372
|
+
}
|
|
306
373
|
} catch (err) {
|
|
307
374
|
check("workflow structure", false, err instanceof Error ? err.message : String(err));
|
|
308
375
|
}
|
|
@@ -312,13 +379,13 @@ async function validateCmd(args: string[]): Promise<number> {
|
|
|
312
379
|
} catch (err) {
|
|
313
380
|
check("workflow.ts loads", false, err instanceof Error ? err.message : String(err));
|
|
314
381
|
check("exports `workflow`", false, "skipped — module failed to load");
|
|
315
|
-
check("
|
|
382
|
+
check("agent runners", false, "skipped — module failed to load");
|
|
316
383
|
check("workflow structure", false, "skipped — module failed to load");
|
|
317
384
|
}
|
|
318
385
|
} else {
|
|
319
386
|
check("workflow.ts loads", false, "skipped — no resolved workflow");
|
|
320
387
|
check("exports `workflow`", false, "skipped — no resolved workflow");
|
|
321
|
-
check("
|
|
388
|
+
check("agent runners", false, "skipped — no resolved workflow");
|
|
322
389
|
}
|
|
323
390
|
|
|
324
391
|
return Promise.resolve(failed() ? 1 : 0);
|
|
@@ -442,7 +509,7 @@ function inputFor(
|
|
|
442
509
|
}
|
|
443
510
|
|
|
444
511
|
async function runCmd(dir: string, message?: string): Promise<void> {
|
|
445
|
-
const { workflow, input, agentRunner, scriptRunner } = await loadWorkflow(dir);
|
|
512
|
+
const { workflow, input, agentRunner, agentRunners, scriptRunner } = await loadWorkflow(dir);
|
|
446
513
|
|
|
447
514
|
// Pre-generated (rather than left to `run()`'s own default) and written to
|
|
448
515
|
// the registry *before* dispatch starts, mirroring `startCmd`'s own
|
|
@@ -471,6 +538,7 @@ async function runCmd(dir: string, message?: string): Promise<void> {
|
|
|
471
538
|
workflow,
|
|
472
539
|
input: inputFor(message, input),
|
|
473
540
|
agentRunner,
|
|
541
|
+
agentRunners,
|
|
474
542
|
scriptRunner,
|
|
475
543
|
baseDir: resolve(dir, "scripts"),
|
|
476
544
|
// Run artifacts live under the invocation cwd (RunOptions' documented
|
|
@@ -640,7 +708,7 @@ async function startCmd(
|
|
|
640
708
|
// one durable record — so a registry-update failure is swallowed, not fatal.
|
|
641
709
|
async function workerCmd(dir: string, runId: string, message?: string): Promise<void> {
|
|
642
710
|
const rootDir = process.cwd();
|
|
643
|
-
const { workflow, input, agentRunner, scriptRunner } = await loadWorkflow(dir);
|
|
711
|
+
const { workflow, input, agentRunner, agentRunners, scriptRunner } = await loadWorkflow(dir);
|
|
644
712
|
|
|
645
713
|
// The one piece of positive evidence `startCmd`'s readiness wait is
|
|
646
714
|
// watching for — written only once the workflow module has actually
|
|
@@ -665,6 +733,7 @@ async function workerCmd(dir: string, runId: string, message?: string): Promise<
|
|
|
665
733
|
workflow,
|
|
666
734
|
input: inputFor(message, input),
|
|
667
735
|
agentRunner,
|
|
736
|
+
agentRunners,
|
|
668
737
|
scriptRunner,
|
|
669
738
|
baseDir: resolve(dir, "scripts"),
|
|
670
739
|
rootDir,
|