@psimona/darkf 0.8.0 → 0.10.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 +13 -3
- package/docs/concepts/handoff.md +5 -1
- package/docs/concepts/node-types.md +7 -5
- package/docs/guides/pick-an-agent-runner.md +24 -3
- package/docs/guides/plan-with-a-task-queue.md +15 -0
- package/docs/guides/run-detached-and-monitor.md +2 -1
- package/docs/guides/write-your-first-workflow.md +19 -3
- package/docs/reference/cli-commands.md +19 -0
- package/docs/reference/core-types.md +17 -2
- package/docs/start-here/quickstart.md +19 -0
- package/package.json +1 -1
- package/skills/darkf-usage/SKILL.md +17 -0
- package/skills/darkf-writing-workflows/SKILL.md +16 -18
- package/src/cli/changelog.test.ts +44 -0
- package/src/cli/changelog.ts +26 -0
- package/src/cli/detached.test.ts +27 -5
- package/src/cli/doctor.test.ts +67 -8
- package/src/cli/help.test.ts +92 -0
- package/src/cli/help.ts +164 -0
- package/src/cli/index.ts +119 -3
- package/src/cli/tarball.test.ts +8 -2
- package/src/cli/update.test.ts +85 -17
- package/src/cli/update.ts +41 -7
- package/src/core/graph.test.ts +154 -13
- package/src/core/graph.ts +13 -3
- package/src/core/types.ts +21 -1
- package/src/engine/identity-guard.test.ts +47 -0
- package/src/engine/run.test.ts +268 -25
- package/src/engine/run.ts +4 -4
- package/src/kit/agents/handoff.ts +1 -1
- package/src/kit/agents/opencode.test.ts +89 -12
- package/src/kit/agents/opencode.ts +73 -8
- package/src/kit/registry.ts +5 -0
- package/src/kit/specs.test.ts +2 -2
- package/src/kit/specs.ts +3 -6
- package/src/test/ok-output.ts +11 -0
- package/workflows/dev-loop/output-types.ts +43 -0
- package/workflows/dev-loop/scripts/begin.ts +2 -2
- package/workflows/dev-loop/scripts/dispatch.ts +3 -5
- package/workflows/dev-loop/scripts/finish.ts +2 -36
- package/workflows/dev-loop/workflow.ts +26 -14
- package/workflows/series-ordering/output-types.ts +9 -0
- package/workflows/series-ordering/workflow.ts +3 -0
|
@@ -54,7 +54,7 @@ describe("scanStepFinish", () => {
|
|
|
54
54
|
test("ignores lines that aren't step-finish or aren't parseable JSON", () => {
|
|
55
55
|
const stdout = ndjson([
|
|
56
56
|
{ type: "message", part: { sessionID: "sess-x" } },
|
|
57
|
-
{ type: "
|
|
57
|
+
{ type: "step_finish", part: { reason: "stop", sessionID: "sess-1" } },
|
|
58
58
|
]);
|
|
59
59
|
const scan = scanStepFinish(`not json\n${stdout}\n`);
|
|
60
60
|
expect(scan.stepCount).toBe(1);
|
|
@@ -64,9 +64,9 @@ describe("scanStepFinish", () => {
|
|
|
64
64
|
|
|
65
65
|
test("counts every step-finish event and keeps the LAST reason/sessionID seen", () => {
|
|
66
66
|
const stdout = ndjson([
|
|
67
|
-
{ type: "
|
|
68
|
-
{ type: "
|
|
69
|
-
{ type: "
|
|
67
|
+
{ type: "step_finish", part: { reason: "tool-calls", sessionID: "sess-1" } },
|
|
68
|
+
{ type: "step_finish", part: { reason: "stop", sessionID: "sess-1" } },
|
|
69
|
+
{ type: "step_finish", part: { reason: "length" } }, // no sessionID on this one
|
|
70
70
|
]);
|
|
71
71
|
const scan = scanStepFinish(stdout);
|
|
72
72
|
expect(scan.stepCount).toBe(3);
|
|
@@ -75,11 +75,13 @@ describe("scanStepFinish", () => {
|
|
|
75
75
|
expect(scan.sessionId).toBe("sess-1");
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
-
test("
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
expect(scan.
|
|
78
|
+
test("reads a captured opencode 2.3.0 event: outer step_finish, inner part.type step-finish", () => {
|
|
79
|
+
const captured =
|
|
80
|
+
'{"type":"step_finish","timestamp":1795852863406,"sessionID":"ses_dded41c03ffe0K2HQarugg1jY8","part":{"id":"prt_2212c07ae001VpNCu4zfPKY2pA","sessionID":"ses_dded41c03ffe0K2HQarugg1jY8","messageID":"msg_2212be8c80010pl7Mc2TCmrkp5","type":"step-finish","reason":"tool-calls","cost":0,"tokens":{"input":11196,"output":106,"reasoning":93,"cache":{"read":0,"write":0}}}}';
|
|
81
|
+
const scan = scanStepFinish(captured);
|
|
82
|
+
expect(scan.stepCount).toBe(1);
|
|
83
|
+
expect(scan.sessionId).toBe("ses_dded41c03ffe0K2HQarugg1jY8");
|
|
84
|
+
expect(scan.reason).toBe("tool-calls");
|
|
83
85
|
});
|
|
84
86
|
|
|
85
87
|
test("stepCount is the positive-evidence gate: zero means no session id should ever be attached", () => {
|
|
@@ -181,7 +183,7 @@ describe("matchUsageLimit", () => {
|
|
|
181
183
|
|
|
182
184
|
test("an ordinary non-limit API error does not match", () => {
|
|
183
185
|
expect(matchUsageLimit("opencode: API error 500: backend exploded\n", "")).toBeUndefined();
|
|
184
|
-
expect(matchUsageLimit("", '{"type":"
|
|
186
|
+
expect(matchUsageLimit("", '{"type":"step_finish","part":{"reason":"stop"}}')).toBeUndefined();
|
|
185
187
|
});
|
|
186
188
|
});
|
|
187
189
|
|
|
@@ -250,7 +252,7 @@ describe("opencodeRunner usage-limit classification + resume", () => {
|
|
|
250
252
|
const handoffFile = handoffPath(rootDir, RUN_ID, 1, "N");
|
|
251
253
|
return [
|
|
252
254
|
`printf '%s\\0' "$@" > "${argvFile}"`,
|
|
253
|
-
`echo '{"type":"
|
|
255
|
+
`echo '{"type":"step_finish","part":{"reason":"stop","sessionID":"${sessionId}"}}'`,
|
|
254
256
|
`mkdir -p "$(dirname "${handoffFile}")"`,
|
|
255
257
|
`echo '{"event":"ok"}' > "${handoffFile}"`,
|
|
256
258
|
].join("\n");
|
|
@@ -260,7 +262,7 @@ describe("opencodeRunner usage-limit classification + resume", () => {
|
|
|
260
262
|
const { rootDir } = install((_rootDir, _argvFile) =>
|
|
261
263
|
[
|
|
262
264
|
`echo 'Usage limit reached for 5 hour. Your limit will reset at 2026-11-01 06:58:19' 1>&2`,
|
|
263
|
-
`echo '{"type":"
|
|
265
|
+
`echo '{"type":"step_finish","part":{"reason":"stop","sessionID":"sess-wall"}}'`,
|
|
264
266
|
`exit 3`,
|
|
265
267
|
].join("\n"),
|
|
266
268
|
);
|
|
@@ -303,6 +305,81 @@ describe("opencodeRunner usage-limit classification + resume", () => {
|
|
|
303
305
|
rmSync(rootDir, { recursive: true, force: true });
|
|
304
306
|
});
|
|
305
307
|
|
|
308
|
+
async function failWith(script: string): Promise<AgentFailure> {
|
|
309
|
+
const { rootDir } = install(() => script);
|
|
310
|
+
let thrown: unknown;
|
|
311
|
+
try {
|
|
312
|
+
await opencodeRunner.run("N", def, {}, info(rootDir));
|
|
313
|
+
} catch (err) {
|
|
314
|
+
thrown = err;
|
|
315
|
+
}
|
|
316
|
+
rmSync(rootDir, { recursive: true, force: true });
|
|
317
|
+
expect(thrown).toBeInstanceOf(AgentFailure);
|
|
318
|
+
return thrown as AgentFailure;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const errorEvent = (type: string, message: string, status?: number) =>
|
|
322
|
+
`echo '${JSON.stringify({ type: "error", sessionID: "ses_1", error: { type, message, ...(status ? { status } : {}) } })}'\nexit 1`;
|
|
323
|
+
|
|
324
|
+
test("captured provider.auth event: message in the crash reason, runner-error", async () => {
|
|
325
|
+
const failure = await failWith(
|
|
326
|
+
`echo '{"type":"step_start"}'\n${errorEvent("provider.auth", "This API key has expired.", 401)}`,
|
|
327
|
+
);
|
|
328
|
+
expect(failure.crashReason).toEqual({
|
|
329
|
+
kind: "runner-error",
|
|
330
|
+
error: "opencode exited 1: provider.auth (401): This API key has expired.",
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
test("captured provider.no-route event: message in the crash reason, runner-error", async () => {
|
|
335
|
+
const failure = await failWith(errorEvent("provider.no-route", "Model unavailable: foo"));
|
|
336
|
+
expect(failure.crashReason).toEqual({
|
|
337
|
+
kind: "runner-error",
|
|
338
|
+
error: "opencode exited 1: provider.no-route: Model unavailable: foo",
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
for (const type of [
|
|
343
|
+
"provider.quota",
|
|
344
|
+
"provider.rate-limit",
|
|
345
|
+
"provider.go-limit",
|
|
346
|
+
"provider.chatgpt-limit",
|
|
347
|
+
"provider.chatgpt-workspace-limit",
|
|
348
|
+
"provider.budget-limit",
|
|
349
|
+
]) {
|
|
350
|
+
test(`${type} error event classifies usage-limit`, async () => {
|
|
351
|
+
const failure = await failWith(
|
|
352
|
+
`echo '{"type":"step_finish","part":{"reason":"stop","sessionID":"sess-q"}}'\n${errorEvent(type, "Plan exhausted, wait.")}`,
|
|
353
|
+
);
|
|
354
|
+
expect(failure.crashReason).toEqual({ kind: "usage-limit", detail: "Plan exhausted, wait." });
|
|
355
|
+
expect(failure.agentSessionId).toBe("sess-q");
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
for (const type of ["provider.free-limit", "provider.model-budget-limit", "provider.mystery"]) {
|
|
360
|
+
test(`${type} error event does not wait`, async () => {
|
|
361
|
+
const failure = await failWith(errorEvent(type, "usage limit hit, switch models"));
|
|
362
|
+
expect(failure.crashReason?.kind).toBe("runner-error");
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
test("an untyped error event with a limit marker classifies usage-limit", async () => {
|
|
367
|
+
const failure = await failWith(
|
|
368
|
+
`echo '{"type":"error","error":{"message":"Usage limit reached for 5 hour."}}'\nexit 1`,
|
|
369
|
+
);
|
|
370
|
+
expect(failure.crashReason).toEqual({
|
|
371
|
+
kind: "usage-limit",
|
|
372
|
+
detail: "Usage limit reached for 5 hour.",
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
test("a non-error JSON event mentioning a limit never matches on a non-zero exit", async () => {
|
|
377
|
+
const failure = await failWith(
|
|
378
|
+
`echo '{"type":"text","part":{"text":"usage limit reached"}}'\nexit 1`,
|
|
379
|
+
);
|
|
380
|
+
expect(failure.crashReason?.kind).toBe("runner-error");
|
|
381
|
+
});
|
|
382
|
+
|
|
306
383
|
test("an exit-0 + missing-handoff output with a limit string inside an agent JSON line stays handoff-missing", async () => {
|
|
307
384
|
const { rootDir } = install((_rootDir, _argvFile) =>
|
|
308
385
|
[
|
|
@@ -35,10 +35,10 @@ export interface StepFinishScan {
|
|
|
35
35
|
// mid-turn death) all surfaced as `exit 0` + missing handoff → a bare
|
|
36
36
|
// ENOENT minutes after the real failure. Capture the reason and make a
|
|
37
37
|
// missing handoff fail loudly with it, so retries and RCA start from facts.
|
|
38
|
-
// NB: the type
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
38
|
+
// NB: the stream's outer `type` is `step_finish` (underscore). The
|
|
39
|
+
// hyphenated "step-finish" appears only one level down, in `part.type`
|
|
40
|
+
// (captured from opencode 2.3.0, 2026-11-28). The SDK's part types use the
|
|
41
|
+
// hyphen, which is not what `run --format json` puts on the outer event.
|
|
42
42
|
//
|
|
43
43
|
// Extended (docs/specs/_built/session-nudge/spec.md) to also pull `part.sessionID`
|
|
44
44
|
// and a count of step-finish events seen, in the same single pass:
|
|
@@ -58,7 +58,7 @@ export function scanStepFinish(stdout: string): StepFinishScan {
|
|
|
58
58
|
type?: string;
|
|
59
59
|
part?: { reason?: string; sessionID?: string };
|
|
60
60
|
};
|
|
61
|
-
if (event.type === "
|
|
61
|
+
if (event.type === "step_finish") {
|
|
62
62
|
stepCount++;
|
|
63
63
|
if (event.part?.reason) reason = event.part.reason;
|
|
64
64
|
if (event.part?.sessionID) sessionId = event.part.sessionID;
|
|
@@ -170,6 +170,65 @@ export function matchUsageLimit(stderr: string, stdout: string): string | undefi
|
|
|
170
170
|
return undefined;
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
+
// Provider errors (docs/roadmap/run-resilience/tickets/opencode-provider-error-lost.md):
|
|
174
|
+
// with `--format json`, opencode reports a provider failure as a top-level
|
|
175
|
+
// `error` event on stdout, exits 1 and writes nothing to stderr. The event is
|
|
176
|
+
// opencode's own, not agent-authored, so reading it does not reopen the
|
|
177
|
+
// false-positive hazard `matchUsageLimit` guards against. Re-check the type
|
|
178
|
+
// table against opencode's source (core/src/session/to-session-error.ts)
|
|
179
|
+
// when upgrading the supported version.
|
|
180
|
+
export interface ProviderError {
|
|
181
|
+
type?: string;
|
|
182
|
+
message?: string;
|
|
183
|
+
status?: number;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const WAITING_ERROR_TYPES = new Set([
|
|
187
|
+
"provider.quota",
|
|
188
|
+
"provider.rate-limit",
|
|
189
|
+
"provider.go-limit",
|
|
190
|
+
"provider.chatgpt-limit",
|
|
191
|
+
"provider.chatgpt-workspace-limit",
|
|
192
|
+
"provider.budget-limit",
|
|
193
|
+
]);
|
|
194
|
+
|
|
195
|
+
/** The last top-level `error` event on stdout, if any. */
|
|
196
|
+
export function scanProviderError(stdout: string): ProviderError | undefined {
|
|
197
|
+
let found: ProviderError | undefined;
|
|
198
|
+
for (const line of stdout.split("\n")) {
|
|
199
|
+
if (!line.trim()) continue;
|
|
200
|
+
try {
|
|
201
|
+
const event = JSON.parse(line) as { type?: unknown; error?: unknown };
|
|
202
|
+
if (event.type !== "error" || event.error === null || typeof event.error !== "object") {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
const err = event.error as Record<string, unknown>;
|
|
206
|
+
found = {
|
|
207
|
+
type: typeof err.type === "string" ? err.type : undefined,
|
|
208
|
+
message: typeof err.message === "string" ? err.message : undefined,
|
|
209
|
+
status: typeof err.status === "number" ? err.status : undefined,
|
|
210
|
+
};
|
|
211
|
+
} catch {
|
|
212
|
+
// ignore: not every line is guaranteed parseable
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return found;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function describeProviderError(err: ProviderError): string {
|
|
219
|
+
const head = `${err.type ?? "error"}${err.status !== undefined ? ` (${err.status})` : ""}`;
|
|
220
|
+
return err.message ? `${head}: ${err.message}` : head;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** A waiting limit: a known waiting type, or an untyped error whose message
|
|
224
|
+
* holds one of the plain-text markers. Everything else is not waited on. */
|
|
225
|
+
function providerLimitDetail(err: ProviderError): string | undefined {
|
|
226
|
+
const text = err.message ?? describeProviderError(err);
|
|
227
|
+
if (err.type !== undefined) return WAITING_ERROR_TYPES.has(err.type) ? text : undefined;
|
|
228
|
+
const lowered = text.toLowerCase();
|
|
229
|
+
return USAGE_LIMIT_MARKERS.some((marker) => lowered.includes(marker)) ? text : undefined;
|
|
230
|
+
}
|
|
231
|
+
|
|
173
232
|
// `opencode models` answers in about a second; this only bounds a hung one.
|
|
174
233
|
const MODEL_LIST_TIMEOUT_MS = 20_000;
|
|
175
234
|
|
|
@@ -329,7 +388,7 @@ export const opencodeRunner: AgentRunner = {
|
|
|
329
388
|
try {
|
|
330
389
|
const event = JSON.parse(line) as { type?: string };
|
|
331
390
|
if (event.type) lastEvent = event.type;
|
|
332
|
-
if (event.type === "
|
|
391
|
+
if (event.type === "step_finish") stepCount++;
|
|
333
392
|
} catch {
|
|
334
393
|
// ignore: not every line is guaranteed parseable (same tolerance
|
|
335
394
|
// scanStepFinish's final pass already has)
|
|
@@ -348,7 +407,11 @@ export const opencodeRunner: AgentRunner = {
|
|
|
348
407
|
|
|
349
408
|
if (exitCode !== 0) {
|
|
350
409
|
const stderr = await new Response(proc.stderr).text();
|
|
351
|
-
const
|
|
410
|
+
const providerError = scanProviderError(stdout);
|
|
411
|
+
const detailText = [stderr.trim(), providerError ? describeProviderError(providerError) : ""]
|
|
412
|
+
.filter(Boolean)
|
|
413
|
+
.join("\n");
|
|
414
|
+
const reason = `opencode exited ${exitCode}: ${detailText.slice(-400)}`;
|
|
352
415
|
lastFailures.set(dispatchKey, reason);
|
|
353
416
|
const scan = scanStepFinish(stdout);
|
|
354
417
|
// Usage-limit classification (docs/specs/_built/usage-limit-backoff/spec.md):
|
|
@@ -357,7 +420,9 @@ export const opencodeRunner: AgentRunner = {
|
|
|
357
420
|
// waits it out instead of burning retries against it. The session id
|
|
358
421
|
// stays evidence-gated (stepCount > 0) exactly as below. No match
|
|
359
422
|
// keeps the existing runner-error throw unchanged.
|
|
360
|
-
const limitLine =
|
|
423
|
+
const limitLine =
|
|
424
|
+
matchUsageLimit(stderr, stdout) ??
|
|
425
|
+
(providerError ? providerLimitDetail(providerError) : undefined);
|
|
361
426
|
if (limitLine !== undefined) {
|
|
362
427
|
throw new AgentFailure(reason, {
|
|
363
428
|
agentSessionId: scan.stepCount > 0 ? scan.sessionId : undefined,
|
package/src/kit/registry.ts
CHANGED
|
@@ -45,6 +45,11 @@ export interface RegistryEntry {
|
|
|
45
45
|
* `worker.log` — the worker process's own captured stderr — so the
|
|
46
46
|
* failure self-documents without a foreground reproduction. */
|
|
47
47
|
startFailureDetail?: string;
|
|
48
|
+
/** Version of the darkf engine that started this run, recorded at
|
|
49
|
+
* `start`/`run` time. Absent on entries written before this field
|
|
50
|
+
* existed. `darkf status` and `darkf report` print it so a postmortem
|
|
51
|
+
* knows which engine executed the run without archaeology. */
|
|
52
|
+
engineVersion?: string;
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
// Small, extensible table of "this env var means we're running under harness
|
package/src/kit/specs.test.ts
CHANGED
|
@@ -143,10 +143,10 @@ describe("parseBacklog", () => {
|
|
|
143
143
|
describe("parseProjectConfig", () => {
|
|
144
144
|
const full: ProjectConfig = {
|
|
145
145
|
version: 1,
|
|
146
|
-
title: "
|
|
146
|
+
title: "example project",
|
|
147
147
|
harness: { runner: "opencode", model: "openai/gpt-5" },
|
|
148
148
|
sandbox: {
|
|
149
|
-
image: "
|
|
149
|
+
image: "example/ci:latest",
|
|
150
150
|
runtimeClass: "gvisor",
|
|
151
151
|
mounts: [{ name: "bun-cache", mountPath: "/root/.bun", size: "10Gi" }],
|
|
152
152
|
},
|
package/src/kit/specs.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
// The
|
|
1
|
+
// The spec workspace contract (D15, D16). One spec per folder under
|
|
2
2
|
// `docs/specs/`, a single ordered `backlog.json`, and a `project.json` for
|
|
3
3
|
// harness and sandbox defaults. Every file is typed here, and validators reject
|
|
4
4
|
// anything the format does not name — so a workflow that imports this module
|
|
5
|
-
// sees the same shape the
|
|
6
|
-
//
|
|
7
|
-
// Format rules live in the backplane repo at
|
|
8
|
-
// `docs/specs/0001-spec-format/spec.md`. Keep this module in sync with it.
|
|
5
|
+
// sees the same shape as any other tool that reads the format.
|
|
9
6
|
|
|
10
7
|
export const SPEC_FORMAT_VERSION = 1;
|
|
11
8
|
|
|
@@ -61,7 +58,7 @@ export interface SpecDocument {
|
|
|
61
58
|
body: string;
|
|
62
59
|
}
|
|
63
60
|
|
|
64
|
-
/** Raised when a
|
|
61
|
+
/** Raised when a spec workspace file does not match the format. */
|
|
65
62
|
export class SpecFormatError extends Error {
|
|
66
63
|
constructor(readonly issues: string[]) {
|
|
67
64
|
super(`invalid spec workspace file: ${issues.join("; ")}`);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { OutputSchema } from "../core/index.ts";
|
|
2
|
+
|
|
3
|
+
// The minimal schema every test fixture's agent leaf declares once
|
|
4
|
+
// validateWorkflow rejects a missing outputType
|
|
5
|
+
// (docs/specs/_built/mandatory-agent-output-types/). Fixtures exercise routing,
|
|
6
|
+
// retries, nudges, and the journal — never their output shape — so the
|
|
7
|
+
// declaration is deliberately the most permissive one the rule accepts
|
|
8
|
+
// (a schema that rejects nothing). A test-local convenience, not kit API.
|
|
9
|
+
export const okOutputType: OutputSchema = {
|
|
10
|
+
safeParse: () => ({ success: true }),
|
|
11
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { zodOutputType } from "@psimona/darkf/src/kit/validation/zod.ts";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
// Plan's handoff output is the one dev-loop claim a consumer actually
|
|
5
|
+
// reads: ValidatePlan runs parseTaskList on it and persists tasks.json.
|
|
6
|
+
// This schema mirrors that narrowing
|
|
7
|
+
// (docs/specs/_built/task-list-json/spec.md), so a malformed list costs an
|
|
8
|
+
// in-session nudge instead of a full Plan/ValidatePlan loop round.
|
|
9
|
+
const priority = z.enum(["must", "should", "could", "won't"]);
|
|
10
|
+
const taskList = z.object({
|
|
11
|
+
id: z.string(),
|
|
12
|
+
spec: z.object({ prd: z.string().optional(), design: z.string().optional() }).optional(),
|
|
13
|
+
requirements: z
|
|
14
|
+
.array(
|
|
15
|
+
z.object({
|
|
16
|
+
id: z.string(),
|
|
17
|
+
kind: z.enum(["req", "nfr", "ng"]),
|
|
18
|
+
text: z.string(),
|
|
19
|
+
priority: priority.optional(),
|
|
20
|
+
}),
|
|
21
|
+
)
|
|
22
|
+
.optional(),
|
|
23
|
+
tasks: z.array(
|
|
24
|
+
z.object({
|
|
25
|
+
id: z.string(),
|
|
26
|
+
title: z.string(),
|
|
27
|
+
status: z.enum(["pending", "in-progress", "done", "failed"]),
|
|
28
|
+
satisfies: z.array(z.string()).optional(),
|
|
29
|
+
priority: priority.optional(),
|
|
30
|
+
}),
|
|
31
|
+
),
|
|
32
|
+
});
|
|
33
|
+
export const planOutput = zodOutputType(taskList);
|
|
34
|
+
|
|
35
|
+
// The other agent leaves route by event; their consumers (Test, MarkDone,
|
|
36
|
+
// Finish) read the working tree and tasks.json, never the handoff output.
|
|
37
|
+
// Their declarations stay permissive — the rule guarantees a declaration,
|
|
38
|
+
// not a good one (docs/specs/_built/mandatory-agent-output-types/, NG-1).
|
|
39
|
+
export const implementOutput = zodOutputType(z.unknown());
|
|
40
|
+
export const fixOutput = zodOutputType(z.unknown());
|
|
41
|
+
export const reviewOutput = zodOutputType(z.unknown());
|
|
42
|
+
export const documentOutput = zodOutputType(z.unknown());
|
|
43
|
+
export const feedbackOutput = zodOutputType(z.unknown());
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { DispatchInfo } from "@psimona/darkf/src/core/index.ts";
|
|
2
2
|
|
|
3
|
-
// Ported from
|
|
3
|
+
// Ported from a sibling project's build-backend create_branch: cut feature/<slug>
|
|
4
4
|
// from the current tree. Uncommitted work (the feature under construction)
|
|
5
5
|
// rides along on the branch — Finish commits it there before the squash.
|
|
6
6
|
// The slug is a workflow-file constant for the pilot; editing this file per
|
|
7
7
|
// feature is the contract until engine-side input plumbing exists.
|
|
8
|
-
const FEATURE = "
|
|
8
|
+
const FEATURE = "mandatory-agent-output-types";
|
|
9
9
|
|
|
10
10
|
function sh(cwd: string, ...args: string[]): [string, number] {
|
|
11
11
|
const proc = Bun.spawnSync(args, { cwd, stdout: "pipe", stderr: "pipe" });
|
|
@@ -6,12 +6,10 @@ import {
|
|
|
6
6
|
parseTaskList,
|
|
7
7
|
} from "@psimona/darkf/src/core/index.ts";
|
|
8
8
|
|
|
9
|
-
// The node that walks the plan —
|
|
10
|
-
//
|
|
11
|
-
// spec's own darkf-core/kit helper isn't shipped yet; this follows its
|
|
12
|
-
// algorithm and vocabulary directly (pending → in-progress, picked once
|
|
9
|
+
// The node that walks the plan — the item-loop shape, hand-rolled here
|
|
10
|
+
// because darkf ships no helper for it: pending → in-progress, picked once
|
|
13
11
|
// and re-verified by Review rather than trusted, status written back
|
|
14
|
-
// before the real work starts
|
|
12
|
+
// before the real work starts.
|
|
15
13
|
//
|
|
16
14
|
// Picks the first "pending" task out of this run's tasks.json, flips it
|
|
17
15
|
// "in-progress", and hands it to Implement as the one thing to build this
|
|
@@ -1,32 +1,16 @@
|
|
|
1
1
|
import type { DispatchInfo, NodeResult } from "@psimona/darkf/src/core/index.ts";
|
|
2
2
|
|
|
3
|
-
// Ported from
|
|
3
|
+
// Ported from a sibling project's build-backend finish_branch (node 4): commit the
|
|
4
4
|
// loop's work on the feature branch, squash-merge onto master as one commit
|
|
5
5
|
// (subject from the prd H1), delete the branch. The run ends with the work
|
|
6
6
|
// merged; no supervisor merge.
|
|
7
7
|
//
|
|
8
8
|
// Safety rails:
|
|
9
9
|
// - only runs on feature/<slug>;
|
|
10
|
-
// - refuses when the dirty tree touches paths outside the loop's known
|
|
11
|
-
// surface (the anti-sweep rail — a blind `git add -A` once wiped a
|
|
12
|
-
// repo's .darkf state in the registry-lifecycle incident);
|
|
13
10
|
// - refuses unless master is an ancestor of the branch (master must not
|
|
14
11
|
// have moved mid-run — the only case where the squash could conflict);
|
|
15
12
|
// - rolls back (reset --hard + checkout back) on any git failure.
|
|
16
|
-
const FEATURE = "
|
|
17
|
-
const ALLOWED = [
|
|
18
|
-
"docs/",
|
|
19
|
-
"darkf/src/",
|
|
20
|
-
"darkf/skills/",
|
|
21
|
-
"darkf/docs/",
|
|
22
|
-
"darkf/package.json",
|
|
23
|
-
"bun.lock",
|
|
24
|
-
"darkf-opencode-plugin/",
|
|
25
|
-
"ROADMAP.md",
|
|
26
|
-
"README.md",
|
|
27
|
-
"site/",
|
|
28
|
-
"darkf/workflows/",
|
|
29
|
-
];
|
|
13
|
+
const FEATURE = "mandatory-agent-output-types";
|
|
30
14
|
|
|
31
15
|
function sh(cwd: string, ...args: string[]): [string, number] {
|
|
32
16
|
const proc = Bun.spawnSync(args, { cwd, stdout: "pipe", stderr: "pipe" });
|
|
@@ -52,24 +36,6 @@ export default function finishBranch(_handoff: NodeResult, info: DispatchInfo):
|
|
|
52
36
|
};
|
|
53
37
|
}
|
|
54
38
|
|
|
55
|
-
const [status, statusRc] = sh(rootDir, "git", "status", "--porcelain");
|
|
56
|
-
if (statusRc !== 0) {
|
|
57
|
-
return { event: "merge_failed", output: { failure: "git status failed" } };
|
|
58
|
-
}
|
|
59
|
-
const dirty = status
|
|
60
|
-
.split("\n")
|
|
61
|
-
.map((l) => l.slice(3).trim())
|
|
62
|
-
.filter(Boolean);
|
|
63
|
-
const foreign = dirty.filter((p) => !ALLOWED.some((prefix) => p.startsWith(prefix)));
|
|
64
|
-
if (foreign.length > 0) {
|
|
65
|
-
return {
|
|
66
|
-
event: "merge_failed",
|
|
67
|
-
output: {
|
|
68
|
-
failure: `dirty paths outside the loop's surface — human decision:\n${foreign.join("\n")}`,
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
39
|
const title = prdTitle(rootDir) ?? FEATURE;
|
|
74
40
|
const subject = `feat: ${title} (${FEATURE})`;
|
|
75
41
|
const add = sh(rootDir, "git", "add", "-A");
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { DONE, type WorkflowDef } from "@psimona/darkf/src/core/index.ts";
|
|
2
2
|
import { opencodeRunner } from "@psimona/darkf/src/kit/agents/opencode.ts";
|
|
3
|
+
import {
|
|
4
|
+
documentOutput,
|
|
5
|
+
feedbackOutput,
|
|
6
|
+
fixOutput,
|
|
7
|
+
implementOutput,
|
|
8
|
+
planOutput,
|
|
9
|
+
reviewOutput,
|
|
10
|
+
} from "./output-types.ts";
|
|
3
11
|
|
|
4
12
|
// dev-loop — begin → PlanPhase{plan → validate} → (dispatch →
|
|
5
13
|
// Task{implement → test → [fix → test]* → review → mark done})* →
|
|
@@ -7,8 +15,8 @@ import { opencodeRunner } from "@psimona/darkf/src/kit/agents/opencode.ts";
|
|
|
7
15
|
//
|
|
8
16
|
// The darkf-on-darkf pilot, expanded after its first real run built the CLI
|
|
9
17
|
// self-update feature (docs/specs/_built/self-update/). Shape ported from
|
|
10
|
-
//
|
|
11
|
-
// squash-merges onto master with
|
|
18
|
+
// a sibling project's build-backend: Begin cuts the feature branch, Finish
|
|
19
|
+
// squash-merges onto master with a sibling project's rails, Feedback writes the run
|
|
12
20
|
// retrospective under darkf/feedback/.
|
|
13
21
|
//
|
|
14
22
|
// Run from the target repo root with the released engine from the npm
|
|
@@ -46,9 +54,8 @@ import { opencodeRunner } from "@psimona/darkf/src/kit/agents/opencode.ts";
|
|
|
46
54
|
// compile-time constant like FEATURE. An invalid candidate loops back to
|
|
47
55
|
// Plan; budget is a small, fixed number of retry rounds.
|
|
48
56
|
//
|
|
49
|
-
// - Dispatch/Task is
|
|
50
|
-
//
|
|
51
|
-
// yet, so this hand-rolls the algorithm rather than importing it), with
|
|
57
|
+
// - Dispatch/Task is the item-loop shape (darkf ships no helper for it, so
|
|
58
|
+
// this hand-rolls the algorithm), with
|
|
52
59
|
// Dispatch kept OUTSIDE the Task composite on purpose. Dispatch (a
|
|
53
60
|
// script) is the node that actually walks the plan — it picks the
|
|
54
61
|
// first "pending" task out of tasks.json, flips it "in-progress", and
|
|
@@ -73,11 +80,11 @@ import { opencodeRunner } from "@psimona/darkf/src/kit/agents/opencode.ts";
|
|
|
73
80
|
// maxCycles below therefore budgets one task's worst case only, never
|
|
74
81
|
// multiplied by how many tasks the plan turns out to have. Dispatch
|
|
75
82
|
// itself carries no maxCycles of its own — the engine-wide maxSteps is
|
|
76
|
-
// the only backstop on the item-to-item loop,
|
|
77
|
-
// item-loop
|
|
78
|
-
//
|
|
83
|
+
// the only backstop on the item-to-item loop, so
|
|
84
|
+
// the item-loop shape has no automatic maxCycles wiring: a workflow
|
|
85
|
+
// author still sizes a lane's
|
|
79
86
|
// own budget by hand, but never has to also guess the plan's total
|
|
80
|
-
// size to do it
|
|
87
|
+
// size to do it. This replaces the pilot's original shape, where
|
|
81
88
|
// Dispatch lived inside the same composite as the lane and the budget
|
|
82
89
|
// had to cover the whole plan — sized for "≤8 tasks × ≤9 dispatches,"
|
|
83
90
|
// it crashed on cycle-limit the first time a real plan came out to 17
|
|
@@ -98,8 +105,8 @@ import { opencodeRunner } from "@psimona/darkf/src/kit/agents/opencode.ts";
|
|
|
98
105
|
export const agentRunner = opencodeRunner;
|
|
99
106
|
|
|
100
107
|
const MODEL = "zai-coding-plan/glm-5.3-flash";
|
|
101
|
-
const RUN_DATE = "2026-
|
|
102
|
-
const FEATURE = "
|
|
108
|
+
const RUN_DATE = "2026-12-03";
|
|
109
|
+
const FEATURE = "mandatory-agent-output-types";
|
|
103
110
|
|
|
104
111
|
export const workflow: WorkflowDef = {
|
|
105
112
|
initial: "Begin",
|
|
@@ -119,6 +126,7 @@ export const workflow: WorkflowDef = {
|
|
|
119
126
|
states: {
|
|
120
127
|
Plan: {
|
|
121
128
|
type: "agent",
|
|
129
|
+
outputType: planOutput,
|
|
122
130
|
agent: { model: MODEL },
|
|
123
131
|
retries: 1,
|
|
124
132
|
prompt: `You are planning the ${FEATURE} run. Do not write or modify any code.
|
|
@@ -152,15 +160,15 @@ Finish with event "planned". If the contract is missing, contradictory, or too v
|
|
|
152
160
|
Task: {
|
|
153
161
|
initial: "Implement",
|
|
154
162
|
// Sized for one task's worst case only (Implement + Test + 2
|
|
155
|
-
// Fix/Test rounds + Review + MarkDone = 8), with
|
|
156
|
-
//
|
|
157
|
-
// 1.5 = 12. Dispatch is deliberately outside this composite (see
|
|
163
|
+
// Fix/Test rounds + Review + MarkDone = 8), with a 1.5 slack
|
|
164
|
+
// factor: 8 * 1.5 = 12. Dispatch is deliberately outside this composite (see
|
|
158
165
|
// the top comment) so this budget resets fresh on every task,
|
|
159
166
|
// never multiplied by the plan's task count.
|
|
160
167
|
maxCycles: 12,
|
|
161
168
|
states: {
|
|
162
169
|
Implement: {
|
|
163
170
|
type: "agent",
|
|
171
|
+
outputType: implementOutput,
|
|
164
172
|
agent: { model: MODEL },
|
|
165
173
|
retries: 1,
|
|
166
174
|
prompt: `Implement exactly the one task you were handed for the ${FEATURE} feature — see "Input from the previous step" below for its id, title, and which requirements it satisfies. Nothing else.
|
|
@@ -182,6 +190,7 @@ Finish with event "implemented". If the task cannot be implemented as specified,
|
|
|
182
190
|
},
|
|
183
191
|
Fix: {
|
|
184
192
|
type: "agent",
|
|
193
|
+
outputType: fixOutput,
|
|
185
194
|
agent: { model: MODEL },
|
|
186
195
|
retries: 1,
|
|
187
196
|
prompt: `You are repairing the ${FEATURE} implementation after a failed gate.
|
|
@@ -193,6 +202,7 @@ Finish with event "fixed". If the failure exposes a spec defect you cannot resol
|
|
|
193
202
|
},
|
|
194
203
|
Review: {
|
|
195
204
|
type: "agent",
|
|
205
|
+
outputType: reviewOutput,
|
|
196
206
|
agent: { model: MODEL },
|
|
197
207
|
retries: 1,
|
|
198
208
|
prompt: `You are an independent reviewer. Do not modify any files.
|
|
@@ -218,6 +228,7 @@ Finish with event "approved" or event "changes_requested".`,
|
|
|
218
228
|
},
|
|
219
229
|
Document: {
|
|
220
230
|
type: "agent",
|
|
231
|
+
outputType: documentOutput,
|
|
221
232
|
agent: { model: MODEL },
|
|
222
233
|
retries: 1,
|
|
223
234
|
prompt: `You are updating user-facing documentation for the ${FEATURE} feature, after every task in its plan was implemented and independently reviewed. Do not modify code or tests.
|
|
@@ -245,6 +256,7 @@ If nothing user-facing changed and no doc drifted, finish with event "skipped" a
|
|
|
245
256
|
},
|
|
246
257
|
Feedback: {
|
|
247
258
|
type: "agent",
|
|
259
|
+
outputType: feedbackOutput,
|
|
248
260
|
agent: { model: MODEL },
|
|
249
261
|
retries: 1,
|
|
250
262
|
prompt: `Write the run retrospective for the ${FEATURE} dev-loop run, in the style of a post-run feedback note.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { zodOutputType } from "@psimona/darkf/src/kit/validation/zod.ts";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
// Verify runs Gradle against the working tree; nothing reads the handoff
|
|
5
|
+
// output. The declarations stay permissive — the rule guarantees a
|
|
6
|
+
// declaration, not a good one
|
|
7
|
+
// (docs/specs/_built/mandatory-agent-output-types/, NG-1).
|
|
8
|
+
export const implementOutput = zodOutputType(z.unknown());
|
|
9
|
+
export const reviewOutput = zodOutputType(z.unknown());
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// darkf start <this dir> "<bug id>"
|
|
10
10
|
import { type AgentRunner, DONE, type WorkflowDef } from "@psimona/darkf/src/core/index.ts";
|
|
11
11
|
import { claudeCodeRunner } from "@psimona/darkf/src/kit/agents/claude-code.ts";
|
|
12
|
+
import { implementOutput, reviewOutput } from "./output-types.ts";
|
|
12
13
|
|
|
13
14
|
export const agentRunner: AgentRunner = claudeCodeRunner;
|
|
14
15
|
|
|
@@ -60,6 +61,7 @@ export const workflow: WorkflowDef = {
|
|
|
60
61
|
states: {
|
|
61
62
|
Implement: {
|
|
62
63
|
type: "agent",
|
|
64
|
+
outputType: implementOutput,
|
|
63
65
|
retries: 1,
|
|
64
66
|
prompt: IMPLEMENT_PROMPT,
|
|
65
67
|
on: { implemented: "Verify", blocked: DONE, disputed: DONE },
|
|
@@ -73,6 +75,7 @@ export const workflow: WorkflowDef = {
|
|
|
73
75
|
},
|
|
74
76
|
Review: {
|
|
75
77
|
type: "agent",
|
|
78
|
+
outputType: reviewOutput,
|
|
76
79
|
retries: 1,
|
|
77
80
|
prompt: REVIEW_PROMPT,
|
|
78
81
|
on: { done: DONE, changes_requested: "Implement" },
|