@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/cli/doctor.test.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
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";
|
|
6
15
|
|
|
7
16
|
// doctor/validate split, `darkf setup`, and the daily probe — the CLI-level
|
|
8
|
-
// wiring from docs/specs/skill-setup. These spawn the real CLI entrypoint:
|
|
17
|
+
// wiring from docs/specs/_built/skill-setup. These spawn the real CLI entrypoint:
|
|
9
18
|
// a temp HOME (host skill dirs), a temp XDG_STATE_HOME (probe stamp), and a
|
|
10
19
|
// temp cwd keep the suite off the real ~ and off the network.
|
|
11
20
|
|
|
@@ -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,
|
|
@@ -133,12 +138,12 @@ function resolveWorkflowDir(ref: string): string {
|
|
|
133
138
|
process.exit(1);
|
|
134
139
|
}
|
|
135
140
|
|
|
136
|
-
interface WorkflowListing {
|
|
141
|
+
export interface WorkflowListing {
|
|
137
142
|
name: string;
|
|
138
143
|
source: "workspace" | "built-in";
|
|
139
144
|
}
|
|
140
145
|
|
|
141
|
-
function listWorkflows(): WorkflowListing[] {
|
|
146
|
+
export function listWorkflows(): WorkflowListing[] {
|
|
142
147
|
const roots: Array<[string, WorkflowListing["source"]]> = [
|
|
143
148
|
[resolve(process.cwd(), "darkf"), "workspace"],
|
|
144
149
|
[resolve(selfRoot(), "workflows"), "built-in"],
|
|
@@ -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
|
|
|
@@ -245,13 +258,67 @@ function describeValidationError(err: WorkflowValidationError): string {
|
|
|
245
258
|
* not checked here — a workflow can be sound on a machine whose skills are
|
|
246
259
|
* stale; the two verdicts stay independent.
|
|
247
260
|
*/
|
|
248
|
-
|
|
249
|
-
|
|
261
|
+
/** Shared ok/FAIL line printer for `validate` and `doctor`: logs each check
|
|
262
|
+
* as it runs and remembers whether any of them failed. */
|
|
263
|
+
function makeChecker(): {
|
|
264
|
+
check: (label: string, ok: boolean, detail?: string) => void;
|
|
265
|
+
failed: () => boolean;
|
|
266
|
+
} {
|
|
250
267
|
let fail = false;
|
|
251
268
|
const check = (label: string, ok: boolean, detail?: string) => {
|
|
252
269
|
console.log(`${ok ? "ok " : "FAIL"} ${label}${detail ? ` — ${detail}` : ""}`);
|
|
253
270
|
if (!ok) fail = true;
|
|
254
271
|
};
|
|
272
|
+
return { check, failed: () => fail };
|
|
273
|
+
}
|
|
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
|
+
|
|
319
|
+
async function validateCmd(args: string[]): Promise<number> {
|
|
320
|
+
const ref = args[0];
|
|
321
|
+
const { check, failed } = makeChecker();
|
|
255
322
|
|
|
256
323
|
// 1. workflow resolution
|
|
257
324
|
if (ref === undefined) {
|
|
@@ -277,15 +344,21 @@ async function validateCmd(args: string[]): Promise<number> {
|
|
|
277
344
|
"exports `workflow`",
|
|
278
345
|
typeof mod.workflow?.states === "object" && typeof mod.workflow?.initial === "string",
|
|
279
346
|
);
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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
|
+
}
|
|
285
355
|
if (typeof mod.workflow?.states === "object" && typeof mod.workflow?.initial === "string") {
|
|
286
356
|
try {
|
|
287
357
|
const registry = buildRegistry(mod.workflow);
|
|
288
|
-
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
|
+
});
|
|
289
362
|
if (errors.length === 0) {
|
|
290
363
|
check("workflow structure", true);
|
|
291
364
|
} else {
|
|
@@ -293,6 +366,10 @@ async function validateCmd(args: string[]): Promise<number> {
|
|
|
293
366
|
check("workflow structure", false, describeValidationError(err));
|
|
294
367
|
}
|
|
295
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
|
+
}
|
|
296
373
|
} catch (err) {
|
|
297
374
|
check("workflow structure", false, err instanceof Error ? err.message : String(err));
|
|
298
375
|
}
|
|
@@ -302,16 +379,16 @@ async function validateCmd(args: string[]): Promise<number> {
|
|
|
302
379
|
} catch (err) {
|
|
303
380
|
check("workflow.ts loads", false, err instanceof Error ? err.message : String(err));
|
|
304
381
|
check("exports `workflow`", false, "skipped — module failed to load");
|
|
305
|
-
check("
|
|
382
|
+
check("agent runners", false, "skipped — module failed to load");
|
|
306
383
|
check("workflow structure", false, "skipped — module failed to load");
|
|
307
384
|
}
|
|
308
385
|
} else {
|
|
309
386
|
check("workflow.ts loads", false, "skipped — no resolved workflow");
|
|
310
387
|
check("exports `workflow`", false, "skipped — no resolved workflow");
|
|
311
|
-
check("
|
|
388
|
+
check("agent runners", false, "skipped — no resolved workflow");
|
|
312
389
|
}
|
|
313
390
|
|
|
314
|
-
return Promise.resolve(
|
|
391
|
+
return Promise.resolve(failed() ? 1 : 0);
|
|
315
392
|
}
|
|
316
393
|
|
|
317
394
|
/**
|
|
@@ -325,11 +402,7 @@ function doctorCmd(args: string[]): number {
|
|
|
325
402
|
console.log("usage: darkf doctor takes no ref — darkf validate <ref> for workflow checks");
|
|
326
403
|
return 1;
|
|
327
404
|
}
|
|
328
|
-
|
|
329
|
-
const check = (label: string, ok: boolean, detail?: string) => {
|
|
330
|
-
console.log(`${ok ? "ok " : "FAIL"} ${label}${detail ? ` — ${detail}` : ""}`);
|
|
331
|
-
if (!ok) fail = true;
|
|
332
|
-
};
|
|
405
|
+
const { check, failed } = makeChecker();
|
|
333
406
|
|
|
334
407
|
// 1. agent binaries
|
|
335
408
|
for (const bin of ["claude", "opencode"]) {
|
|
@@ -369,7 +442,7 @@ function doctorCmd(args: string[]): number {
|
|
|
369
442
|
}
|
|
370
443
|
}
|
|
371
444
|
|
|
372
|
-
return
|
|
445
|
+
return failed() ? 1 : 0;
|
|
373
446
|
}
|
|
374
447
|
|
|
375
448
|
function workflowsCmd(): void {
|
|
@@ -436,7 +509,7 @@ function inputFor(
|
|
|
436
509
|
}
|
|
437
510
|
|
|
438
511
|
async function runCmd(dir: string, message?: string): Promise<void> {
|
|
439
|
-
const { workflow, input, agentRunner, scriptRunner } = await loadWorkflow(dir);
|
|
512
|
+
const { workflow, input, agentRunner, agentRunners, scriptRunner } = await loadWorkflow(dir);
|
|
440
513
|
|
|
441
514
|
// Pre-generated (rather than left to `run()`'s own default) and written to
|
|
442
515
|
// the registry *before* dispatch starts, mirroring `startCmd`'s own
|
|
@@ -465,6 +538,7 @@ async function runCmd(dir: string, message?: string): Promise<void> {
|
|
|
465
538
|
workflow,
|
|
466
539
|
input: inputFor(message, input),
|
|
467
540
|
agentRunner,
|
|
541
|
+
agentRunners,
|
|
468
542
|
scriptRunner,
|
|
469
543
|
baseDir: resolve(dir, "scripts"),
|
|
470
544
|
// Run artifacts live under the invocation cwd (RunOptions' documented
|
|
@@ -634,7 +708,7 @@ async function startCmd(
|
|
|
634
708
|
// one durable record — so a registry-update failure is swallowed, not fatal.
|
|
635
709
|
async function workerCmd(dir: string, runId: string, message?: string): Promise<void> {
|
|
636
710
|
const rootDir = process.cwd();
|
|
637
|
-
const { workflow, input, agentRunner, scriptRunner } = await loadWorkflow(dir);
|
|
711
|
+
const { workflow, input, agentRunner, agentRunners, scriptRunner } = await loadWorkflow(dir);
|
|
638
712
|
|
|
639
713
|
// The one piece of positive evidence `startCmd`'s readiness wait is
|
|
640
714
|
// watching for — written only once the workflow module has actually
|
|
@@ -659,6 +733,7 @@ async function workerCmd(dir: string, runId: string, message?: string): Promise<
|
|
|
659
733
|
workflow,
|
|
660
734
|
input: inputFor(message, input),
|
|
661
735
|
agentRunner,
|
|
736
|
+
agentRunners,
|
|
662
737
|
scriptRunner,
|
|
663
738
|
baseDir: resolve(dir, "scripts"),
|
|
664
739
|
rootDir,
|
|
@@ -744,7 +819,7 @@ function printDigest(entry: RegistryEntry, state: TerminalState, journalText: st
|
|
|
744
819
|
}
|
|
745
820
|
if (digest.current?.phase === "running" && digest.current.startedAt !== undefined) {
|
|
746
821
|
// Live elapsed, computed at print time — journal-frozen runtime goes stale
|
|
747
|
-
// during long nodes (spec: docs/specs/live-runtime).
|
|
822
|
+
// during long nodes (spec: docs/specs/_built/live-runtime).
|
|
748
823
|
console.log(
|
|
749
824
|
`elapsed: ${formatMs(Date.now() - digest.current.startedAt)} (node ${digest.current.state})`,
|
|
750
825
|
);
|
|
@@ -813,7 +888,7 @@ function printTransition(e: NodeEvent, prevTs: number | null, isHeartbeat = fals
|
|
|
813
888
|
const idle = startedAt !== undefined ? e.timestamp - startedAt : 0;
|
|
814
889
|
let line = `${e.state} still running — ${(idle / 1000).toFixed(0)}s elapsed`;
|
|
815
890
|
// Agent-level liveness, distinct from the engine-heartbeat idle above —
|
|
816
|
-
// see docs/specs/agent-liveness/spec.md. Absent for script dispatches or
|
|
891
|
+
// see docs/specs/_built/agent-liveness/spec.md. Absent for script dispatches or
|
|
817
892
|
// runners that don't report progress.
|
|
818
893
|
if (status.phase === "running" && status.agentIdleMs !== undefined) {
|
|
819
894
|
const agentIdleSec = Math.round(status.agentIdleMs / 1000);
|
|
@@ -916,7 +991,7 @@ async function monitorRun(entry: RegistryEntry, windowSec: number, once: boolean
|
|
|
916
991
|
lastSeen = events.length;
|
|
917
992
|
dwellHint(events, entry.runId, hinted);
|
|
918
993
|
|
|
919
|
-
// Usage-limit wait (docs/specs/usage-limit-backoff/spec.md): re-render
|
|
994
|
+
// Usage-limit wait (docs/specs/_built/usage-limit-backoff/spec.md): re-render
|
|
920
995
|
// the wait line when the probe advances, so a monitored wait shows the
|
|
921
996
|
// countdown instead of silence — same one-line warn style as the status
|
|
922
997
|
// digest's stallWarning/nudgeWarning.
|
|
@@ -1151,4 +1226,8 @@ async function main(): Promise<void> {
|
|
|
1151
1226
|
await runCmd(resolveWorkflowDir(cmd ?? "."), undefined);
|
|
1152
1227
|
}
|
|
1153
1228
|
|
|
1154
|
-
|
|
1229
|
+
// Dispatch only when this file is the process entry point — the `darkf` bin,
|
|
1230
|
+
// or the spawned `__worker` (startCmd spawns this same file directly). The
|
|
1231
|
+
// package public surface (src/exports.ts) re-exports `listWorkflows` from
|
|
1232
|
+
// here; importing it must not execute the CLI against the host's own argv.
|
|
1233
|
+
if (import.meta.main) main();
|
package/src/cli/setup.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Skill setup (docs/specs/skill-setup): the shared skills-check core, the
|
|
1
|
+
// Skill setup (docs/specs/_built/skill-setup): the shared skills-check core, the
|
|
2
2
|
// `darkf setup` sync, and the daily first-invocation probe. The bundled
|
|
3
3
|
// darkf-* skills ship inside the package (darkf/skills/); every dependency
|
|
4
4
|
// arrives via deps objects, so the whole module runs in tests without a real
|
|
@@ -12,9 +12,9 @@ import {
|
|
|
12
12
|
readFileSync,
|
|
13
13
|
renameSync,
|
|
14
14
|
rmSync,
|
|
15
|
-
writeFileSync,
|
|
16
15
|
} from "node:fs";
|
|
17
|
-
import {
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import { writeJsonState } from "./state-file.ts";
|
|
18
18
|
|
|
19
19
|
// The known harnesses are a table in code — adding one is a row plus a test
|
|
20
20
|
// fixture, not a feature (spec: Host detection). `dir` is relative to HOME;
|
|
@@ -227,12 +227,7 @@ export function readProbeState(file: string): ProbeState {
|
|
|
227
227
|
|
|
228
228
|
/** mkdir -p on the parent; best-effort — swallow write errors. */
|
|
229
229
|
export function writeProbeState(file: string, state: ProbeState): void {
|
|
230
|
-
|
|
231
|
-
mkdirSync(dirname(file), { recursive: true });
|
|
232
|
-
writeFileSync(file, JSON.stringify(state));
|
|
233
|
-
} catch {
|
|
234
|
-
// An unwritable state location degrades to re-probing next invocation.
|
|
235
|
-
}
|
|
230
|
+
writeJsonState(file, state);
|
|
236
231
|
}
|
|
237
232
|
|
|
238
233
|
/** The local calendar date — the day a probe compares against, not UTC. */
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
|
|
4
|
+
/** mkdir -p on the parent; best-effort — swallow write errors. Shared by
|
|
5
|
+
* `setup.ts`'s probe state and `update.ts`'s update-check state; both
|
|
6
|
+
* degrade to re-running next invocation when the location is unwritable. */
|
|
7
|
+
export function writeJsonState<T>(file: string, state: T): void {
|
|
8
|
+
try {
|
|
9
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
10
|
+
writeFileSync(file, JSON.stringify(state));
|
|
11
|
+
} catch {
|
|
12
|
+
// An unwritable state location degrades to re-probing/re-checking next invocation.
|
|
13
|
+
}
|
|
14
|
+
}
|
package/src/cli/tarball.test.ts
CHANGED
|
@@ -61,8 +61,10 @@ test("tarball smoke: allowlist ships the runtime dirs and the installed CLI work
|
|
|
61
61
|
expect(existsSync(join(prefix, "bin", "darkf"))).toBe(true);
|
|
62
62
|
|
|
63
63
|
// Temp HOME and state; the probe stamped so its block stays out of the way.
|
|
64
|
+
// The home carries a .claude/skills dir so host detection works by dir
|
|
65
|
+
// alone — CI runners have no claude binary on PATH.
|
|
64
66
|
const home = join(root, "home");
|
|
65
|
-
mkdirSync(home);
|
|
67
|
+
mkdirSync(join(home, ".claude", "skills"), { recursive: true });
|
|
66
68
|
const stateHome = join(root, "state");
|
|
67
69
|
mkdirSync(stateHome, { recursive: true });
|
|
68
70
|
writeProbeState(join(stateHome, "darkf", "last-skills-check.json"), {
|
package/src/cli/update.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
// CLI self-update (docs/specs/self-update): a daily startup version check and
|
|
1
|
+
// CLI self-update (docs/specs/_built/self-update): a daily startup version check and
|
|
2
2
|
// the `darkf upgrade` command. Every dependency arrives via UpdateDeps, so the
|
|
3
3
|
// whole module runs in tests without network, a real clock, or a real package
|
|
4
4
|
// manager. No module-level mutable state.
|
|
5
|
-
import {
|
|
6
|
-
import { dirname } from "node:path";
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
7
6
|
import { type SkillsDeps, syncAll } from "./setup.ts";
|
|
7
|
+
import { writeJsonState } from "./state-file.ts";
|
|
8
8
|
|
|
9
9
|
const PACKAGE_SPEC = "@psimona/darkf";
|
|
10
10
|
const REGISTRY_URL = "https://registry.npmjs.org/-/package/@psimona%2Fdarkf/dist-tags";
|
|
@@ -47,12 +47,7 @@ export function readState(file: string): UpdateState {
|
|
|
47
47
|
|
|
48
48
|
/** mkdir -p on the parent; best-effort — swallow write errors (REQ-4). */
|
|
49
49
|
export function writeState(file: string, state: UpdateState): void {
|
|
50
|
-
|
|
51
|
-
mkdirSync(dirname(file), { recursive: true });
|
|
52
|
-
writeFileSync(file, JSON.stringify(state));
|
|
53
|
-
} catch {
|
|
54
|
-
// An unwritable state location degrades to re-checking next invocation.
|
|
55
|
-
}
|
|
50
|
+
writeJsonState(file, state);
|
|
56
51
|
}
|
|
57
52
|
|
|
58
53
|
/** True when lastCheck is missing, unparseable, or older than 24 h. */
|