@psimona/darkf 0.9.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.
@@ -670,7 +670,7 @@ test("threads agentSessionId and previousFailure into DispatchInfo across nudges
670
670
  previousFailure: undefined,
671
671
  });
672
672
  // A validate rejection with a session nudges in-session (up to three,
673
- // docs/specs/output-validation): the attempt stays 1 while previousFailure
673
+ // docs/specs/_built/output-validation): the attempt stays 1 while previousFailure
674
674
  // and the carried session id thread through every nudge dispatch.
675
675
  expect(infos).toHaveLength(5); // fresh + 3 nudges + the capped fallback
676
676
  for (const info of infos.slice(1, 4)) {
@@ -964,6 +964,93 @@ test("nudges a handoff-missing AgentFailure in-session, consuming no retry", asy
964
964
  });
965
965
  });
966
966
 
967
+ // --- runner-failure-identity (docs/specs/_built/runner-failure-identity/spec.md) ---
968
+
969
+ // A workflow outside the package loads its runner from its own copy of the
970
+ // package, so the `AgentFailure` it throws is not an instance of the engine's
971
+ // class. A query string on the specifier gives a second module instance in one
972
+ // process, which is the same situation.
973
+ async function secondCopyOfAgentFailure(): Promise<typeof AgentFailure> {
974
+ const copy = (await import(`../core/types.ts?copy=${Math.random()}`)) as {
975
+ AgentFailure: typeof AgentFailure;
976
+ };
977
+ expect(copy.AgentFailure).not.toBe(AgentFailure);
978
+ return copy.AgentFailure;
979
+ }
980
+
981
+ test("nudges an AgentFailure whose class comes from a second module copy", async () => {
982
+ const OtherAgentFailure = await secondCopyOfAgentFailure();
983
+ const workflow: WorkflowDef = {
984
+ initial: "Agentic",
985
+ states: {
986
+ Agentic: {
987
+ type: "agent",
988
+ outputType: okOutputType,
989
+ agent: { model: "test-model" },
990
+ prompt: "do it",
991
+ on: { ok: EXIT },
992
+ },
993
+ },
994
+ };
995
+
996
+ const infos: DispatchInfo[] = [];
997
+ const agentRunner: AgentRunner = {
998
+ run: async (_id, _def, _handoff, info) => {
999
+ infos.push(info);
1000
+ if (infos.length === 1) {
1001
+ throw new OtherAgentFailure("handoff not written", {
1002
+ agentSessionId: "sess-1",
1003
+ crashReason: { kind: "handoff-missing" },
1004
+ });
1005
+ }
1006
+ return { event: "ok" };
1007
+ },
1008
+ };
1009
+
1010
+ const result = await run({ workflow, agentRunner, scriptRunner: noopScript });
1011
+
1012
+ // Same outcome as the single-copy test above: nudged in-session, no retry spent.
1013
+ expect(result.node.phase).toBe("succeeded");
1014
+ expect(infos.length).toBe(2);
1015
+ expect(infos[1]).toMatchObject({
1016
+ attempt: 1,
1017
+ agentSessionId: "sess-1",
1018
+ previousFailure: { kind: "handoff-missing" },
1019
+ });
1020
+ });
1021
+
1022
+ test("records the crash reason of an AgentFailure from a second module copy", async () => {
1023
+ const OtherAgentFailure = await secondCopyOfAgentFailure();
1024
+ const workflow: WorkflowDef = {
1025
+ initial: "Agentic",
1026
+ states: {
1027
+ Agentic: {
1028
+ type: "agent",
1029
+ outputType: okOutputType,
1030
+ agent: { model: "test-model" },
1031
+ prompt: "do it",
1032
+ retries: 0,
1033
+ on: { ok: EXIT },
1034
+ },
1035
+ },
1036
+ };
1037
+ const agentRunner: AgentRunner = {
1038
+ run: async () => {
1039
+ throw new OtherAgentFailure("boom", {
1040
+ agentSessionId: "sess-9",
1041
+ crashReason: { kind: "handoff-unparseable", parseError: "bad json" },
1042
+ });
1043
+ },
1044
+ };
1045
+
1046
+ const result = await run({ workflow, agentRunner, scriptRunner: noopScript });
1047
+
1048
+ expect(result.node).toMatchObject({
1049
+ phase: "crashed",
1050
+ reason: { kind: "handoff-unparseable", parseError: "bad json" },
1051
+ });
1052
+ });
1053
+
967
1054
  test("nudges no-transition when an unroutable event comes back in a returned NodeResult", async () => {
968
1055
  const workflow: WorkflowDef = {
969
1056
  initial: "Agentic",
@@ -1158,7 +1245,7 @@ test("a shared per-attempt deadline bounds the whole nudge sequence, not a fresh
1158
1245
  }
1159
1246
  });
1160
1247
 
1161
- // --- output-validation (docs/specs/output-validation/spec.md) ---
1248
+ // --- output-validation (docs/specs/_built/output-validation/spec.md) ---
1162
1249
 
1163
1250
  test("a failing outputType nudges in-session with the message in previousFailure, capped at three before the fresh retry", async () => {
1164
1251
  const workflow: WorkflowDef = {
@@ -1261,7 +1348,7 @@ test("a failing validate nudges in-session with the script's message in previous
1261
1348
 
1262
1349
  test("regression: a validate-only leaf still rejects the same inputs, now nudging before it retries", async () => {
1263
1350
  // The Compatibility contract, checked directly
1264
- // (docs/specs/output-validation/spec.md): a leaf with `validate` and no
1351
+ // (docs/specs/_built/output-validation/spec.md): a leaf with `validate` and no
1265
1352
  // `outputType` — the pre-spec shape — rejects the same inputs with the
1266
1353
  // same message and ends in the same `validation-failed` crash shape as
1267
1354
  // before. Only the path there changed: with a session, up to three
package/src/engine/run.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { join } from "node:path";
2
2
  import { pathToFileURL } from "node:url";
3
3
  import {
4
- AgentFailure,
5
4
  type AgentProgress,
6
5
  type AgentRunner,
7
6
  type AgentRunnerKind,
@@ -14,6 +13,7 @@ import {
14
13
  effectiveAgent,
15
14
  enter,
16
15
  FAILED,
16
+ isAgentFailure,
17
17
  isComposite,
18
18
  isNodeResult,
19
19
  type NodeEvent,
@@ -330,7 +330,7 @@ export async function run(opts: RunOptions): Promise<RunResult> {
330
330
  // outputType (agent leaves only) — a shape check on the payload,
331
331
  // run before `validate` so a validate script can read the output
332
332
  // without re-checking its shape
333
- // (docs/specs/output-validation/spec.md, "Order"). Same inline
333
+ // (docs/specs/_built/output-validation/spec.md, "Order"). Same inline
334
334
  // nudge form as no-transition below: this reason comes from a
335
335
  // return value, not a thrown AgentFailure, so the catch block's
336
336
  // isNudgeable path never sees it.
@@ -354,7 +354,7 @@ export async function run(opts: RunOptions): Promise<RunResult> {
354
354
  // catch block's isNudgeable path never sees it. Up to
355
355
  // NUDGE_LIMIT nudges consume no retry; only the fallback to a
356
356
  // fresh attempt does
357
- // (docs/specs/output-validation/spec.md, "Where this plugs
357
+ // (docs/specs/_built/output-validation/spec.md, "Where this plugs
358
358
  // into the dispatch loop").
359
359
  if (agentSessionId && nudgeAttempt < NUDGE_LIMIT) {
360
360
  nudgeAttempt++;
@@ -382,7 +382,7 @@ export async function run(opts: RunOptions): Promise<RunResult> {
382
382
  reason = { kind: "timeout", elapsedMs: timeoutMs };
383
383
  continue attemptLoop;
384
384
  }
385
- if (err instanceof AgentFailure) {
385
+ if (isAgentFailure(err)) {
386
386
  agentSessionId = err.agentSessionId ?? agentSessionId;
387
387
  reason = err.crashReason ?? { kind: "runner-error", error: err.message };
388
388
  } else {
@@ -59,7 +59,7 @@ export function buildPrompt(
59
59
 
60
60
  /**
61
61
  * Shared same-session repair text for the nudgeable `CrashReason` kinds
62
- * (docs/specs/_built/session-nudge/spec.md, docs/specs/output-validation/spec.md).
62
+ * (docs/specs/_built/session-nudge/spec.md, docs/specs/_built/output-validation/spec.md).
63
63
  * `undefined` means "don't nudge" — either there's no `previousFailure`, no
64
64
  * `agentSessionId` to resume, or the failure isn't one of the repairable
65
65
  * kinds. Both runners call this identically; only the CLI invocation that
@@ -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
@@ -143,10 +143,10 @@ describe("parseBacklog", () => {
143
143
  describe("parseProjectConfig", () => {
144
144
  const full: ProjectConfig = {
145
145
  version: 1,
146
- title: "darkf backplane",
146
+ title: "example project",
147
147
  harness: { runner: "opencode", model: "openai/gpt-5" },
148
148
  sandbox: {
149
- image: "ghcr.io/psimona/backplane-ci:latest",
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 backplane spec workspace contract (D15, D16). One spec per folder under
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 backplane does.
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 backplane file does not match the format. */
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("; ")}`);
@@ -2,7 +2,7 @@ import type { OutputSchema } from "../core/index.ts";
2
2
 
3
3
  // The minimal schema every test fixture's agent leaf declares once
4
4
  // validateWorkflow rejects a missing outputType
5
- // (docs/specs/mandatory-agent-output-types/). Fixtures exercise routing,
5
+ // (docs/specs/_built/mandatory-agent-output-types/). Fixtures exercise routing,
6
6
  // retries, nudges, and the journal — never their output shape — so the
7
7
  // declaration is deliberately the most permissive one the rule accepts
8
8
  // (a schema that rejects nothing). A test-local convenience, not kit API.
@@ -35,7 +35,7 @@ export const planOutput = zodOutputType(taskList);
35
35
  // The other agent leaves route by event; their consumers (Test, MarkDone,
36
36
  // Finish) read the working tree and tasks.json, never the handoff output.
37
37
  // Their declarations stay permissive — the rule guarantees a declaration,
38
- // not a good one (docs/specs/mandatory-agent-output-types/, NG-1).
38
+ // not a good one (docs/specs/_built/mandatory-agent-output-types/, NG-1).
39
39
  export const implementOutput = zodOutputType(z.unknown());
40
40
  export const fixOutput = zodOutputType(z.unknown());
41
41
  export const reviewOutput = zodOutputType(z.unknown());
@@ -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 — darkf's item-loop-convention shape
10
- // (docs/specs/item-loop-convention/spec.md), hand-rolled here because that
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) without importing anything from it.
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
@@ -54,9 +54,8 @@ import {
54
54
  // compile-time constant like FEATURE. An invalid candidate loops back to
55
55
  // Plan; budget is a small, fixed number of retry rounds.
56
56
  //
57
- // - Dispatch/Task is darkf's item-loop-convention shape
58
- // (docs/specs/item-loop-convention/spec.md — a design, not shipped code
59
- // 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
60
59
  // Dispatch kept OUTSIDE the Task composite on purpose. Dispatch (a
61
60
  // script) is the node that actually walks the plan — it picks the
62
61
  // first "pending" task out of tasks.json, flips it "in-progress", and
@@ -81,11 +80,11 @@ import {
81
80
  // maxCycles below therefore budgets one task's worst case only, never
82
81
  // multiplied by how many tasks the plan turns out to have. Dispatch
83
82
  // itself carries no maxCycles of its own — the engine-wide maxSteps is
84
- // the only backstop on the item-to-item loop, matching
85
- // item-loop-convention's own Non-goals ("automatic maxCycles wiring"
86
- // is explicitly out of scope: a workflow author still sizes a lane's
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
87
86
  // own budget by hand, but never has to also guess the plan's total
88
- // size to do it). This replaces the pilot's original shape, where
87
+ // size to do it. This replaces the pilot's original shape, where
89
88
  // Dispatch lived inside the same composite as the lane and the budget
90
89
  // had to cover the whole plan — sized for "≤8 tasks × ≤9 dispatches,"
91
90
  // it crashed on cycle-limit the first time a real plan came out to 17
@@ -161,9 +160,8 @@ Finish with event "planned". If the contract is missing, contradictory, or too v
161
160
  Task: {
162
161
  initial: "Implement",
163
162
  // Sized for one task's worst case only (Implement + Test + 2
164
- // Fix/Test rounds + Review + MarkDone = 8), with item-loop-
165
- // convention's own estimateMaxCycles(n, slack=1.5) rounding: 8 *
166
- // 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
167
165
  // the top comment) so this budget resets fresh on every task,
168
166
  // never multiplied by the plan's task count.
169
167
  maxCycles: 12,
@@ -4,6 +4,6 @@ import { z } from "zod";
4
4
  // Verify runs Gradle against the working tree; nothing reads the handoff
5
5
  // output. The declarations stay permissive — the rule guarantees a
6
6
  // declaration, not a good one
7
- // (docs/specs/mandatory-agent-output-types/, NG-1).
7
+ // (docs/specs/_built/mandatory-agent-output-types/, NG-1).
8
8
  export const implementOutput = zodOutputType(z.unknown());
9
9
  export const reviewOutput = zodOutputType(z.unknown());