@psimona/darkf 0.8.0 → 0.9.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 +2 -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 +14 -16
- package/src/cli/detached.test.ts +8 -4
- package/src/cli/doctor.test.ts +8 -8
- package/src/cli/index.ts +2 -0
- package/src/cli/tarball.test.ts +8 -2
- package/src/core/graph.test.ts +154 -13
- package/src/core/graph.ts +13 -3
- package/src/engine/run.test.ts +178 -22
- package/src/kit/agents/opencode.test.ts +89 -12
- package/src/kit/agents/opencode.ts +73 -8
- 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/finish.ts +2 -36
- package/workflows/dev-loop/workflow.ts +18 -4
- package/workflows/series-ordering/output-types.ts +9 -0
- package/workflows/series-ordering/workflow.ts +3 -0
|
@@ -31,7 +31,7 @@ all of them are required:
|
|
|
31
31
|
| `running` | `runner` | No | The runner name an agent state selected. Absent for the default runner and for script dispatches. |
|
|
32
32
|
| `running` | `runnerKind` | No | The resolved agent runner's `kind`. Absent when it declares none, and for script dispatches. |
|
|
33
33
|
| `running` | `limitBackoff` | No | Present only while the engine is waiting out a provider usage limit — which probe this is, when the next one fires, and the total waited so far. |
|
|
34
|
-
| `crashed` | `reason` | Yes | A `CrashReason` — which of the
|
|
34
|
+
| `crashed` | `reason` | Yes | A `CrashReason` — which of the eleven shapes below. |
|
|
35
35
|
| `crashed` | `attempt` | Yes | Which attempt number crashed. |
|
|
36
36
|
|
|
37
37
|
A **crash** means the mechanism itself failed. It doesn't mean the
|
|
@@ -48,7 +48,8 @@ export type CrashReason =
|
|
|
48
48
|
| { kind: "unresolved-target"; from: string; target: string }
|
|
49
49
|
| { kind: "duplicate-id"; id: string }
|
|
50
50
|
| { kind: "max-steps"; steps: number; state: string }
|
|
51
|
-
| { kind: "cycle-limit"; composite: string; cycles: number }
|
|
51
|
+
| { kind: "cycle-limit"; composite: string; cycles: number }
|
|
52
|
+
| { kind: "invalid-workflow"; errors: WorkflowValidationError[] };
|
|
52
53
|
```
|
|
53
54
|
|
|
54
55
|
Every variant's `kind` is required — it's the discriminant. The rest
|
|
@@ -66,6 +67,7 @@ of each variant's payload is required too, with one exception:
|
|
|
66
67
|
| `duplicate-id` | `id` (required) | `buildRegistry` found two states sharing an id. |
|
|
67
68
|
| `max-steps` | `steps` (required), `state` (required) | The engine-wide `maxSteps` backstop tripped. |
|
|
68
69
|
| `cycle-limit` | `composite` (required), `cycles` (required) | A composite's own `maxCycles` tripped. |
|
|
70
|
+
| `invalid-workflow` | `errors` (required) | `validateWorkflow` rejected the workflow before the first dispatch — the run crashes on the initial state at attempt 0, and no leaf ever runs. `errors` holds one entry per problem, each naming a state — e.g. `missing-output-type` for an agent leaf whose `outputType` is absent or has no `safeParse` function. |
|
|
69
71
|
|
|
70
72
|
`validation-failed` nudges before it retries. When a result fails one
|
|
71
73
|
of these checks, the engine keeps the same session alive and sends a
|
|
@@ -165,7 +167,15 @@ alive the whole time — the supervisor can kill it at any moment, and
|
|
|
165
167
|
the journal says exactly where the wait stopped. Classification is
|
|
166
168
|
runner-side: the opencode runner recognizes limit-shaped errors
|
|
167
169
|
(`usage limit`, `rate limit`, `limit exceeded`, `429`) on a non-zero
|
|
168
|
-
exit
|
|
170
|
+
exit, and it reads the provider's `error` event that opencode prints on
|
|
171
|
+
stdout. Quota and throttle types (`provider.quota`, `provider.rate-limit`,
|
|
172
|
+
`provider.go-limit`, `provider.chatgpt-limit`,
|
|
173
|
+
`provider.chatgpt-workspace-limit`, `provider.budget-limit`) start the wait.
|
|
174
|
+
Other provider errors (`provider.auth`, `provider.no-route`,
|
|
175
|
+
`provider.free-limit`, `provider.model-budget-limit`) are not waited on: the
|
|
176
|
+
dispatch crashes as `runner-error` with the provider's message in `error`,
|
|
177
|
+
for example `opencode exited 1: provider.auth (401): This API key has
|
|
178
|
+
expired.` A script that calls an LLM itself owns its error handling.
|
|
169
179
|
|
|
170
180
|
**A thrash, not (yet) a `cycle-limit` crash.** If one state's visit
|
|
171
181
|
count is the run's highest and reaches 4 or more, `status` prints a
|
package/docs/concepts/handoff.md
CHANGED
|
@@ -69,7 +69,11 @@ artifacts. No in-memory visit map of its own required.
|
|
|
69
69
|
## What's needed, what's handled
|
|
70
70
|
|
|
71
71
|
Your own code decides, every single time, what belongs in `output` for
|
|
72
|
-
the next node to see. darkf never infers this.
|
|
72
|
+
the next node to see. darkf never infers this. For an agent leaf, the
|
|
73
|
+
shape you decided on is declared up front as the state's `outputType` —
|
|
74
|
+
required, checked by `darkf validate` — so the next node can read
|
|
75
|
+
`handoff.output` as that schema's type instead of guessing; see
|
|
76
|
+
[Node types](../node-types/). A value not re-emitted
|
|
73
77
|
this hop simply isn't there next hop — even a value the node itself
|
|
74
78
|
just received.
|
|
75
79
|
|
|
@@ -32,7 +32,7 @@ export interface AgentStateDef {
|
|
|
32
32
|
prompt: string;
|
|
33
33
|
agent?: Record<string, unknown>;
|
|
34
34
|
runner?: string;
|
|
35
|
-
outputType?: OutputSchema;
|
|
35
|
+
outputType?: OutputSchema; // optional to the compiler; required by validateWorkflow
|
|
36
36
|
on?: Record<string, string>;
|
|
37
37
|
next?: string;
|
|
38
38
|
retries?: number;
|
|
@@ -55,10 +55,10 @@ export interface AgentStateDef {
|
|
|
55
55
|
| `timeoutMs` | No | 1 hour | Ceiling on a single dispatch attempt. Exceeding it is a `timeout` crash, consuming a retry attempt like any other. |
|
|
56
56
|
| `usageLimitRetryMs` | No | 30 minutes | Interval between re-probes after a dispatch fails on the provider's usage limit. The wait runs outside `timeoutMs` — each re-probe starts with a fresh per-attempt budget — and consumes no retry attempt. |
|
|
57
57
|
| `usageLimitMaxWaitMs` | No | 24 hours | Total wait budget per node visit for usage-limit backoff. Spending it crashes the run with a `usage-limit` crash — see [Failure modes](../failure-modes/). |
|
|
58
|
-
| `outputType` |
|
|
58
|
+
| `outputType` | Yes | — | Shape check on the reply's `output`, run before `validate`. Any object with a `safeParse(value)` method returning `{ success: true }` or `{ success: false, message }` — build one from a Zod schema with `zodOutputType()` (`src/kit/validation/zod.ts`) and import only that built value, never Zod itself. Required with a validation error: `validateWorkflow` rejects an agent leaf without a usable `outputType` as `missing-output-type`, so `darkf validate` fails and a run crashes `invalid-workflow` before the first dispatch — even though the TypeScript field stays optional. Agent leaves only — an agent's `output` comes from text an LLM wrote, a script's from code you already control. A failure rejects the dispatch exactly like a failed `validate` — see [Failure modes](../failure-modes/). |
|
|
59
59
|
| `validate` | No | — | `(result, handoff) => string \| undefined`, run after the reply already parses as a well-formed `NodeResult` — and after `outputType`, when set. Return a string to reject it as `validation-failed`, or `undefined` to accept. A rejection nudges before it retries — up to three corrective prompts in the live session, none costing a retry — then falls back to a fresh attempt like any crash; see [Failure modes](../failure-modes/). |
|
|
60
60
|
|
|
61
|
-
A workflow author must always supply `prompt`,
|
|
61
|
+
A workflow author must always supply `prompt`, a `model` — in the state's own `agent` bag or, for a state with no `runner`, in `WorkflowDef.agent` — and an `outputType` declaring the shape of the handoff output. Everything else is safe to omit.
|
|
62
62
|
|
|
63
63
|
## Script
|
|
64
64
|
|
|
@@ -87,7 +87,7 @@ export interface ScriptStateDef {
|
|
|
87
87
|
| `usageLimitRetryMs` / `usageLimitMaxWaitMs` | No | 30 min / 24 h | Present on both leaf kinds, but only a failure classified as `usage-limit` starts a wait — only `opencodeRunner` does that classification (`claudeCodeRunner` does not, so its quota failures are `runner-error`), and a script's own throws are `runner-error`. A script that calls an LLM itself owns its error handling. |
|
|
88
88
|
| `validate` | No | — | Same contract as the agent case, minus the nudging — a script has no session to resume, so a rejection spends a retry attempt directly. Rarely needed, since a script's own result is usually correct by construction — but useful for confirming a side effect (a file actually got written) before the dispatch counts as done. |
|
|
89
89
|
|
|
90
|
-
`type` and `file` are the only two a script state can't do without
|
|
90
|
+
`type` and `file` are the only two a script state can't do without — a script leaves every other field optional. An agent state additionally requires `prompt` and an `outputType`, as the agent table above shows.
|
|
91
91
|
|
|
92
92
|
## Composite
|
|
93
93
|
|
|
@@ -120,6 +120,7 @@ a top-level state. `Implement` is nested inside `Fix`. `Review`'s
|
|
|
120
120
|
|
|
121
121
|
```ts
|
|
122
122
|
// darkf/workflows/series-ordering/workflow.ts (prompts and retries omitted)
|
|
123
|
+
import { implementOutput, reviewOutput } from "./output-types.ts";
|
|
123
124
|
export const workflow: WorkflowDef = {
|
|
124
125
|
initial: "Fix",
|
|
125
126
|
agent: { model: "claude-sonnet-5-5" },
|
|
@@ -128,12 +129,13 @@ export const workflow: WorkflowDef = {
|
|
|
128
129
|
initial: "Implement",
|
|
129
130
|
maxCycles: 8,
|
|
130
131
|
states: {
|
|
131
|
-
Implement: { type: "agent", on: { implemented: "Verify", blocked: DONE, disputed: DONE } },
|
|
132
|
+
Implement: { type: "agent", outputType: implementOutput, on: { implemented: "Verify", blocked: DONE, disputed: DONE } },
|
|
132
133
|
Verify: { type: "script", file: "verify.ts", on: { green: "Review", red: "Implement" } },
|
|
133
134
|
},
|
|
134
135
|
},
|
|
135
136
|
Review: {
|
|
136
137
|
type: "agent",
|
|
138
|
+
outputType: reviewOutput,
|
|
137
139
|
on: { done: DONE, changes_requested: "Implement" },
|
|
138
140
|
},
|
|
139
141
|
},
|
|
@@ -31,6 +31,10 @@ the agent is instructed to fill in, and reads that file back as the
|
|
|
31
31
|
```ts
|
|
32
32
|
import { DONE, type WorkflowDef } from "@psimona/darkf/src/core/index.ts";
|
|
33
33
|
import { claudeCodeRunner } from "@psimona/darkf/src/kit/agents/claude-code.ts";
|
|
34
|
+
import { zodOutputType } from "@psimona/darkf/src/kit/validation/zod.ts";
|
|
35
|
+
import { z } from "zod";
|
|
36
|
+
|
|
37
|
+
const greetOutput = zodOutputType(z.object({ greeting: z.string() }));
|
|
34
38
|
|
|
35
39
|
export const agentRunner = claudeCodeRunner;
|
|
36
40
|
|
|
@@ -38,7 +42,7 @@ export const workflow: WorkflowDef = {
|
|
|
38
42
|
initial: "Greet",
|
|
39
43
|
agent: { model: "claude-sonnet-5-5" },
|
|
40
44
|
states: {
|
|
41
|
-
Greet: { type: "agent", prompt: "Write a one-sentence greeting.", next: DONE },
|
|
45
|
+
Greet: { type: "agent", outputType: greetOutput, prompt: "Write a one-sentence greeting.", next: DONE },
|
|
42
46
|
},
|
|
43
47
|
};
|
|
44
48
|
```
|
|
@@ -56,6 +60,10 @@ a missing handoff file.
|
|
|
56
60
|
```ts
|
|
57
61
|
import { DONE, type WorkflowDef } from "@psimona/darkf/src/core/index.ts";
|
|
58
62
|
import { opencodeRunner } from "@psimona/darkf/src/kit/agents/opencode.ts";
|
|
63
|
+
import { zodOutputType } from "@psimona/darkf/src/kit/validation/zod.ts";
|
|
64
|
+
import { z } from "zod";
|
|
65
|
+
|
|
66
|
+
const greetOutput = zodOutputType(z.object({ greeting: z.string() }));
|
|
59
67
|
|
|
60
68
|
export const agentRunner = opencodeRunner;
|
|
61
69
|
|
|
@@ -63,7 +71,7 @@ export const workflow: WorkflowDef = {
|
|
|
63
71
|
initial: "Greet",
|
|
64
72
|
agent: { model: "zai-coding-plan/glm-5.3-flash" },
|
|
65
73
|
states: {
|
|
66
|
-
Greet: { type: "agent", prompt: "Write a one-sentence greeting.", next: DONE },
|
|
74
|
+
Greet: { type: "agent", outputType: greetOutput, prompt: "Write a one-sentence greeting.", next: DONE },
|
|
67
75
|
},
|
|
68
76
|
};
|
|
69
77
|
```
|
|
@@ -78,10 +86,17 @@ another one, register it by name in an `agentRunners` export and set
|
|
|
78
86
|
import { DONE, type WorkflowDef } from "@psimona/darkf/src/core/index.ts";
|
|
79
87
|
import { claudeCodeRunner } from "@psimona/darkf/src/kit/agents/claude-code.ts";
|
|
80
88
|
import { opencodeRunner } from "@psimona/darkf/src/kit/agents/opencode.ts";
|
|
89
|
+
import { zodOutputType } from "@psimona/darkf/src/kit/validation/zod.ts";
|
|
90
|
+
import { z } from "zod";
|
|
81
91
|
|
|
82
92
|
export const agentRunner = opencodeRunner; // default
|
|
83
93
|
export const agentRunners = { claude: claudeCodeRunner }; // selectable by name
|
|
84
94
|
|
|
95
|
+
// One outputType per agent state — shapes elided, this guide is about runners.
|
|
96
|
+
const planOutput = zodOutputType(z.unknown());
|
|
97
|
+
const buildOutput = zodOutputType(z.unknown());
|
|
98
|
+
const reviewOutput = zodOutputType(z.unknown());
|
|
99
|
+
|
|
85
100
|
export const workflow: WorkflowDef = {
|
|
86
101
|
initial: "plan",
|
|
87
102
|
agent: { model: "zai-coding-plan/glm-5.3-flash", auto: true }, // default
|
|
@@ -90,17 +105,20 @@ export const workflow: WorkflowDef = {
|
|
|
90
105
|
type: "agent",
|
|
91
106
|
runner: "claude",
|
|
92
107
|
agent: { model: "claude-sonnet-5-5" },
|
|
108
|
+
outputType: planOutput,
|
|
93
109
|
prompt: "Plan the change.",
|
|
94
110
|
next: "build",
|
|
95
111
|
},
|
|
96
112
|
build: {
|
|
97
113
|
type: "agent", // inherits the default runner, model and auto
|
|
114
|
+
outputType: buildOutput,
|
|
98
115
|
prompt: "Implement the plan.",
|
|
99
116
|
next: "review",
|
|
100
117
|
},
|
|
101
118
|
review: {
|
|
102
119
|
type: "agent",
|
|
103
120
|
agent: { model: "zai-coding-plan/glm-5.3" }, // new model, keeps auto
|
|
121
|
+
outputType: reviewOutput,
|
|
104
122
|
prompt: "Review the change.",
|
|
105
123
|
next: DONE,
|
|
106
124
|
},
|
|
@@ -134,6 +152,7 @@ another runner can change what its agent may do.
|
|
|
134
152
|
| `unknown-runner` | A state names a runner that is not an own key of `agentRunners`. It never falls back to the default. |
|
|
135
153
|
| `missing-runner` | A state names no runner and the workflow has no `agentRunner`. A workflow whose agent states all name one needs no default. |
|
|
136
154
|
| `missing-model` | A state's effective bag has no non-empty string `model`. This applies to custom runners too. |
|
|
155
|
+
| `missing-output-type` | An agent state has no `outputType`, or its value has no `safeParse` method. Scripts don't need one. |
|
|
137
156
|
|
|
138
157
|
`darkf validate` also fails on an `agentRunner` or `agentRunners` entry with
|
|
139
158
|
no `run` function. If you call `run()` yourself, pass both as
|
|
@@ -172,4 +191,6 @@ in core or engine is specific to either shipped adapter.
|
|
|
172
191
|
For demos and tests, skip a real harness entirely — a plain object
|
|
173
192
|
satisfying `AgentRunner` is enough, as the `haiku-readme` example's stub
|
|
174
193
|
runner shows (see [Quickstart](../../start-here/quickstart/)). Its states still
|
|
175
|
-
need a `model` value, such as `agent: { model: "stub" }
|
|
194
|
+
need a `model` value, such as `agent: { model: "stub" }`, and an
|
|
195
|
+
`outputType` on every agent state — validateWorkflow doesn't care that
|
|
196
|
+
the runner is a stub.
|
|
@@ -37,6 +37,7 @@ in memory.
|
|
|
37
37
|
// workflow.ts
|
|
38
38
|
import { EXIT, type WorkflowDef } from "@psimona/darkf/src/core/index.ts";
|
|
39
39
|
import { claudeCodeRunner } from "../../src/kit/agents/claude-code.ts";
|
|
40
|
+
import { workOutput } from "./output-types.ts";
|
|
40
41
|
|
|
41
42
|
export const agentRunner = claudeCodeRunner;
|
|
42
43
|
|
|
@@ -51,6 +52,7 @@ export const workflow: WorkflowDef = {
|
|
|
51
52
|
},
|
|
52
53
|
Work: {
|
|
53
54
|
type: "agent",
|
|
55
|
+
outputType: workOutput,
|
|
54
56
|
prompt:
|
|
55
57
|
'Do the task named in the handoff\'s "title" field: append one ' +
|
|
56
58
|
"sentence to notes.md describing what you did, creating the file " +
|
|
@@ -66,6 +68,19 @@ export const workflow: WorkflowDef = {
|
|
|
66
68
|
};
|
|
67
69
|
```
|
|
68
70
|
|
|
71
|
+
`Work` is an agent state, so it needs an `outputType` — every agent leaf
|
|
72
|
+
does; `darkf validate` rejects the workflow without one. `Record` reads
|
|
73
|
+
`tasks.json` from disk, not the handoff, so the declaration stays
|
|
74
|
+
permissive on purpose:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
// output-types.ts
|
|
78
|
+
import { zodOutputType } from "@psimona/darkf/src/kit/validation/zod.ts";
|
|
79
|
+
import { z } from "zod";
|
|
80
|
+
|
|
81
|
+
export const workOutput = zodOutputType(z.unknown());
|
|
82
|
+
```
|
|
83
|
+
|
|
69
84
|
`next.ts` and `record.ts` are the only two places that touch `tasks.json`,
|
|
70
85
|
and they agree on one convention: `"in-progress"` means "the item `Next`
|
|
71
86
|
handed out, that `Record` hasn't closed out yet" — so a crash between the
|
|
@@ -69,7 +69,8 @@ bunx darkf validate my-workflow
|
|
|
69
69
|
|
|
70
70
|
Checks that the workflow resolves, that `workflow.ts` loads and exports
|
|
71
71
|
`workflow`, that the state graph is sound, and that every agent state
|
|
72
|
-
resolves to a runner and a model
|
|
72
|
+
resolves to a runner and a model and declares an `outputType` for its
|
|
73
|
+
handoff output. For the machine side, run `bunx darkf doctor`: the `claude` and `opencode` binaries on
|
|
73
74
|
`PATH`, and that you're not accidentally running from inside the darkf
|
|
74
75
|
checkout itself (a workflow's agent runner uses the invocation `cwd` as
|
|
75
76
|
its working directory — a common mistake when first wiring a workflow
|
|
@@ -59,13 +59,28 @@ and `scriptRunner` (optional — only needed if a script needs run-aware
|
|
|
59
59
|
|
|
60
60
|
### Adding an agent state
|
|
61
61
|
|
|
62
|
-
An `agent` state needs a `prompt`, a model, and a
|
|
62
|
+
An `agent` state needs a `prompt`, a model, an `outputType`, and a
|
|
63
|
+
configured `agentRunner`. Define the schema first — the `outputType`
|
|
64
|
+
declares the shape of the state's handoff output. Put it in its own
|
|
65
|
+
file, built with `zodOutputType()`, and import only the built value:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
// output-types.ts
|
|
69
|
+
import { z } from "zod";
|
|
70
|
+
import { zodOutputType } from "@psimona/darkf/src/kit/validation/zod.ts";
|
|
71
|
+
|
|
72
|
+
const GreetOutputSchema = z.object({ greeting: z.string() });
|
|
73
|
+
export const greetOutput = zodOutputType(GreetOutputSchema);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Then add the agent state, pointing `outputType` at the built value:
|
|
63
77
|
|
|
64
78
|
```ts
|
|
65
79
|
Greet: {
|
|
66
80
|
type: "agent",
|
|
67
81
|
agent: { model: "claude-haiku-5-5" }, // required: every agent state needs a model
|
|
68
82
|
prompt: "Write a one-sentence greeting.",
|
|
83
|
+
outputType: greetOutput, // required: validateWorkflow rejects an agent leaf without one
|
|
69
84
|
on: { done: EXIT },
|
|
70
85
|
},
|
|
71
86
|
```
|
|
@@ -90,8 +105,9 @@ built-in options and for choosing a runner per state.
|
|
|
90
105
|
after 24 hours). A wait consumes no retry attempt and no `timeoutMs`
|
|
91
106
|
budget; see [Failure modes](../../concepts/failure-modes/).
|
|
92
107
|
- `outputType` checks the shape of an agent's `output` payload before
|
|
93
|
-
`validate` runs —
|
|
94
|
-
|
|
108
|
+
`validate` runs — every agent leaf must declare one (`darkf validate`
|
|
109
|
+
rejects the workflow otherwise); build one from a Zod schema with
|
|
110
|
+
`zodOutputType()` (`@psimona/darkf/src/kit/validation/zod.ts`); see
|
|
95
111
|
[Node types](../../concepts/node-types/).
|
|
96
112
|
- `validate(result, handoff)` runs a plain code check against a result
|
|
97
113
|
before it's accepted as `succeeded`; returning a string rejects it as
|
|
@@ -93,6 +93,8 @@ graph structure validates. Structure includes, for each agent state:
|
|
|
93
93
|
- its `runner` is a key of `agentRunners`
|
|
94
94
|
- without a `runner`, the module exports `agentRunner`
|
|
95
95
|
- its effective `agent` bag has a non-empty string `model`
|
|
96
|
+
- it declares a usable `outputType` — an object with a `safeParse`
|
|
97
|
+
method — naming the schema of its handoff output (`missing-output-type`)
|
|
96
98
|
|
|
97
99
|
A runner can also report models it does not recognize, as `warn agent models`
|
|
98
100
|
lines. Warnings never change the exit code. `opencodeRunner` compares against
|
|
@@ -20,7 +20,7 @@ export interface AgentStateDef {
|
|
|
20
20
|
prompt: string;
|
|
21
21
|
agent?: Record<string, unknown>;
|
|
22
22
|
runner?: string; // key into the workflow's `agentRunners`; absent: the default `agentRunner`
|
|
23
|
-
outputType?: OutputSchema; // checks result.output, before `validate` runs
|
|
23
|
+
outputType?: OutputSchema; // checks result.output, before `validate` runs; required by validateWorkflow — an agent leaf without a usable one is rejected (missing-output-type)
|
|
24
24
|
on?: Record<string, string>;
|
|
25
25
|
next?: string;
|
|
26
26
|
retries?: number;
|
|
@@ -106,7 +106,18 @@ export type CrashReason =
|
|
|
106
106
|
| { kind: "unresolved-target"; from: string; target: string }
|
|
107
107
|
| { kind: "duplicate-id"; id: string }
|
|
108
108
|
| { kind: "max-steps"; steps: number; state: string }
|
|
109
|
-
| { kind: "cycle-limit"; composite: string; cycles: number }
|
|
109
|
+
| { kind: "cycle-limit"; composite: string; cycles: number }
|
|
110
|
+
| { kind: "invalid-workflow"; errors: WorkflowValidationError[] };
|
|
111
|
+
|
|
112
|
+
// from graph.ts — the problems `validateWorkflow` collects, one per state
|
|
113
|
+
export type WorkflowValidationError =
|
|
114
|
+
| { kind: "unresolved-target"; from: string | null; target: string }
|
|
115
|
+
| { kind: "initial-cycle"; cycle: string[] }
|
|
116
|
+
| { kind: "dead-end-leaf"; state: string }
|
|
117
|
+
| { kind: "unknown-runner"; state: string; runner: string; known: string[] }
|
|
118
|
+
| { kind: "missing-runner"; state: string }
|
|
119
|
+
| { kind: "missing-model"; state: string }
|
|
120
|
+
| { kind: "missing-output-type"; state: string };
|
|
110
121
|
|
|
111
122
|
export interface StepTrace {
|
|
112
123
|
state: string;
|
|
@@ -134,6 +145,10 @@ On a `running` agent dispatch, `runner` is the name the state selected
|
|
|
134
145
|
(absent for the default runner) and `runnerKind` is the resolved runner's
|
|
135
146
|
`kind` (absent when it declares none). Script dispatches carry neither.
|
|
136
147
|
|
|
148
|
+
An `invalid-workflow` crash means `validateWorkflow` rejected the
|
|
149
|
+
workflow before the first dispatch — see [Failure
|
|
150
|
+
modes](../../concepts/failure-modes/) for when that happens.
|
|
151
|
+
|
|
137
152
|
The runner objects are not part of a `WorkflowDef`. A workflow module
|
|
138
153
|
exports them, and `run()` takes them as `RunOptions.agentRunner` (the
|
|
139
154
|
default) and `RunOptions.agentRunners?: Record<string, AgentRunner>` (the
|
|
@@ -54,6 +54,7 @@ flowchart LR
|
|
|
54
54
|
// workflow.ts
|
|
55
55
|
import { EXIT, type WorkflowDef } from "@psimona/darkf/src/core/index.ts";
|
|
56
56
|
import { claudeCodeRunner } from "@psimona/darkf/src/kit/agents/claude-code.ts";
|
|
57
|
+
import { writeOutput } from "./output-types.ts";
|
|
57
58
|
|
|
58
59
|
export const agentRunner = claudeCodeRunner;
|
|
59
60
|
|
|
@@ -63,6 +64,7 @@ export const workflow: WorkflowDef = {
|
|
|
63
64
|
states: {
|
|
64
65
|
Write: {
|
|
65
66
|
type: "agent",
|
|
67
|
+
outputType: writeOutput,
|
|
66
68
|
prompt:
|
|
67
69
|
"Add a haiku about darkf to README.md, wrapped in HTML comments " +
|
|
68
70
|
"<!-- haiku:start --> and <!-- haiku:end --> on their own lines, " +
|
|
@@ -80,6 +82,23 @@ export const workflow: WorkflowDef = {
|
|
|
80
82
|
};
|
|
81
83
|
```
|
|
82
84
|
|
|
85
|
+
Every agent leaf must declare an `outputType` — the schema of its
|
|
86
|
+
handoff output. `darkf validate` rejects the workflow without one
|
|
87
|
+
(`missing-output-type`), and a run crashes `invalid-workflow` before the
|
|
88
|
+
first dispatch. The declaration lives in its own file, built from a Zod
|
|
89
|
+
schema with `zodOutputType()`:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
// output-types.ts
|
|
93
|
+
import { zodOutputType } from "@psimona/darkf/src/kit/validation/zod.ts";
|
|
94
|
+
import { z } from "zod";
|
|
95
|
+
|
|
96
|
+
// Check judges the README by reading the file from disk, not the handoff
|
|
97
|
+
// output. The declaration stays permissive — the rule guarantees a
|
|
98
|
+
// declaration, not a good one.
|
|
99
|
+
export const writeOutput = zodOutputType(z.unknown());
|
|
100
|
+
```
|
|
101
|
+
|
|
83
102
|
`check.ts` is plain code — no LLM involved in deciding whether the job is
|
|
84
103
|
actually done:
|
|
85
104
|
|
package/package.json
CHANGED
|
@@ -69,6 +69,23 @@ Open dispatches write a heartbeat to the journal every 30 seconds. `darkf status
|
|
|
69
69
|
|
|
70
70
|
`darkf report` shows per-dispatch spans, a visit histogram, and usage totals. Four or more visits to one state hints at a cycle.
|
|
71
71
|
|
|
72
|
+
## Supervisor session is recorded
|
|
73
|
+
|
|
74
|
+
**Warning:** `darkf start` and `darkf run` record the session that calls them as
|
|
75
|
+
the supervisor. With trace capture (planned, not built yet), darkf keeps the
|
|
76
|
+
**whole** supervisor session, with the parts that are not about the run. Uploaded
|
|
77
|
+
traces are kept without a time limit and are not redacted.
|
|
78
|
+
|
|
79
|
+
Before you start a run, tell the user this. To keep the session out, override
|
|
80
|
+
the signal with an empty value:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
CLAUDE_CODE_SESSION_ID= darkf start <workflow-dir> "<message>"
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The override applies to one command. Use it on every `start` and `run` that must
|
|
87
|
+
stay private. Detection reads only `CLAUDE_CODE_SESSION_ID`.
|
|
88
|
+
|
|
72
89
|
## After launch
|
|
73
90
|
|
|
74
91
|
The run detaches. Watching is your job.
|
|
@@ -24,6 +24,7 @@ Every state that can route backward must live inside ONE composite. `maxCycles`
|
|
|
24
24
|
```ts
|
|
25
25
|
import { DONE, type AgentRunner, type WorkflowDef } from "/abs/path/to/darkf/src/core/index.ts";
|
|
26
26
|
import { claudeCodeRunner } from "/abs/path/to/darkf/src/kit/agents/claude-code.ts";
|
|
27
|
+
import { implementOutputType, reviewOutputType } from "./output-types.ts";
|
|
27
28
|
|
|
28
29
|
export const agentRunner: AgentRunner = claudeCodeRunner;
|
|
29
30
|
|
|
@@ -40,7 +41,7 @@ export const workflow: WorkflowDef = {
|
|
|
40
41
|
maxCycles: 24,
|
|
41
42
|
states: {
|
|
42
43
|
Implement: {
|
|
43
|
-
type: "agent", retries: 1, prompt: IMPL,
|
|
44
|
+
type: "agent", retries: 1, prompt: IMPL, outputType: implementOutputType,
|
|
44
45
|
on: { implemented: "Verify", disputed: DONE, blocked: DONE },
|
|
45
46
|
},
|
|
46
47
|
Verify: {
|
|
@@ -50,7 +51,7 @@ export const workflow: WorkflowDef = {
|
|
|
50
51
|
on: { green: "Review", red: "Implement", blocked: DONE },
|
|
51
52
|
},
|
|
52
53
|
Review: {
|
|
53
|
-
type: "agent", retries: 1, prompt: REVIEW,
|
|
54
|
+
type: "agent", retries: 1, prompt: REVIEW, outputType: reviewOutputType,
|
|
54
55
|
on: { done: DONE, changes_requested: "Implement" },
|
|
55
56
|
},
|
|
56
57
|
},
|
|
@@ -72,19 +73,16 @@ Workflows outside the darkf package use absolute paths into the package, as in t
|
|
|
72
73
|
|
|
73
74
|
### Reading an agent claim off the handoff
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
`behavior_ok: true`
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
(c) => c != null && typeof (c as Claim).verdict_field === "boolean",
|
|
86
|
-
);
|
|
87
|
-
```
|
|
76
|
+
Every agent state declares `outputType`, so a consumer knows the claim's
|
|
77
|
+
shape at type-check time: read `handoff.output` as that declared schema's
|
|
78
|
+
type. Do not scan candidate shapes. The scan — guessing flat vs nested vs
|
|
79
|
+
hybrid at the consumer — is the historical anti-pattern (run `0a1b2ca3`: a
|
|
80
|
+
hybrid verdict, a passing `behavior_ok: true` plus a nested summary block,
|
|
81
|
+
was read as invalid; the verify step crashed `bad_verdict` on a healthy
|
|
82
|
+
tree, and the repair loop tripped the composite's cycle budget).
|
|
83
|
+
`validateWorkflow` rejects any agent leaf without `outputType`, so a
|
|
84
|
+
producer that stops promising a shape fails at `darkf validate` — seconds,
|
|
85
|
+
not a dispatch.
|
|
88
86
|
|
|
89
87
|
Pair this with the maxCycles rule above: one false rejection costs a full
|
|
90
88
|
repair round, and the budget counts dispatches, not repairs.
|
|
@@ -95,7 +93,7 @@ A script default export receives `(handoff, info)` and returns a `NodeResult`. `
|
|
|
95
93
|
|
|
96
94
|
## Validate agent output with `outputType`
|
|
97
95
|
|
|
98
|
-
|
|
96
|
+
Every agent state requires an `outputType`: a shape check the engine runs against the node's `output` payload, before `validate`. `validateWorkflow` rejects an agent leaf without one — `darkf validate` fails with `agent leaf has no outputType`, and a run of the same workflow crashes `invalid-workflow` before the first dispatch. Use it for structure ("does the output have these fields?"), keep `validate` for logic ("is the value acceptable?"). A state may set both. Type runs first, so a `validate` script can read `output.tasks[2].title` without re-checking the shape itself. `outputType` is agent-only: a script's output comes from code you already wrote and control, so its leaf needs no declaration. `validate` stays available on both agent and script states.
|
|
99
97
|
|
|
100
98
|
### The `OutputSchema` interface
|
|
101
99
|
|
package/src/cli/detached.test.ts
CHANGED
|
@@ -40,6 +40,10 @@ function makeProjectRoot(): string {
|
|
|
40
40
|
mkdirSync(join(root, ".git"));
|
|
41
41
|
mkdirSync(join(root, "node_modules", "@psimona"), { recursive: true });
|
|
42
42
|
symlinkSync(join(repoRoot, "darkf"), join(root, "node_modules", "@psimona", "darkf"));
|
|
43
|
+
// A real install of @psimona/darkf pulls its one runtime dependency (zod)
|
|
44
|
+
// into the project's node_modules; the shipped examples' schema files
|
|
45
|
+
// import it, so the simulated root needs it too.
|
|
46
|
+
symlinkSync(join(repoRoot, "darkf", "node_modules", "zod"), join(root, "node_modules", "zod"));
|
|
43
47
|
return root;
|
|
44
48
|
}
|
|
45
49
|
|
|
@@ -134,7 +138,7 @@ export const agentRunner: AgentRunner = {
|
|
|
134
138
|
export const workflow: WorkflowDef = {
|
|
135
139
|
initial: "Plan",
|
|
136
140
|
states: {
|
|
137
|
-
Plan: { type: "agent", agent: { model: "test-model" }, prompt: "plan", on: { approved: "Implement" } },
|
|
141
|
+
Plan: { type: "agent", agent: { model: "test-model" }, prompt: "plan", outputType: { safeParse: () => ({ success: true }) }, on: { approved: "Implement" } },
|
|
138
142
|
Implement: {
|
|
139
143
|
initial: "Write",
|
|
140
144
|
states: {
|
|
@@ -142,7 +146,7 @@ export const workflow: WorkflowDef = {
|
|
|
142
146
|
Test: { type: "script", file: "test.ts", on: { passed: "Review" } },
|
|
143
147
|
},
|
|
144
148
|
},
|
|
145
|
-
Review: { type: "agent", agent: { model: "test-model" }, prompt: "review", on: { done: EXIT } },
|
|
149
|
+
Review: { type: "agent", agent: { model: "test-model" }, prompt: "review", outputType: { safeParse: () => ({ success: true }) }, on: { done: EXIT } },
|
|
146
150
|
},
|
|
147
151
|
};
|
|
148
152
|
`,
|
|
@@ -320,8 +324,8 @@ export const agentRunners: Record<string, AgentRunner> = {
|
|
|
320
324
|
export const workflow: WorkflowDef = {
|
|
321
325
|
initial: "A",
|
|
322
326
|
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 },
|
|
327
|
+
A: { type: "agent", agent: { model: "test-model" }, prompt: "a", outputType: { safeParse: () => ({ success: true }) }, next: "B" },
|
|
328
|
+
B: { type: "agent", runner: "other", agent: { model: "test-model" }, prompt: "b", outputType: { safeParse: () => ({ success: true }) }, next: EXIT },
|
|
325
329
|
},
|
|
326
330
|
};
|
|
327
331
|
`,
|
package/src/cli/doctor.test.ts
CHANGED
|
@@ -184,7 +184,7 @@ test("validate inherits the workflow checks: happy path, same lines, exit 0", as
|
|
|
184
184
|
const dir = writeFixture(
|
|
185
185
|
env,
|
|
186
186
|
"happy",
|
|
187
|
-
`A: { type: "agent", agent: { model: "claude-test-model" }, prompt: "p", on: { done: EXIT } }`,
|
|
187
|
+
`A: { type: "agent", agent: { model: "claude-test-model" }, prompt: "p", outputType: { safeParse: () => ({ success: true }) }, on: { done: EXIT } }`,
|
|
188
188
|
);
|
|
189
189
|
|
|
190
190
|
const res = await runCli(["validate", dir], env);
|
|
@@ -206,7 +206,7 @@ test("validate reports unresolved targets", async () => {
|
|
|
206
206
|
const dir = writeFixture(
|
|
207
207
|
env,
|
|
208
208
|
"unresolved",
|
|
209
|
-
`A: { type: "agent", agent: { model: "claude-test-model" }, prompt: "p", on: { done: "nope" } }`,
|
|
209
|
+
`A: { type: "agent", agent: { model: "claude-test-model" }, prompt: "p", outputType: { safeParse: () => ({ success: true }) }, on: { done: "nope" } }`,
|
|
210
210
|
);
|
|
211
211
|
const res = await runCli(["validate", dir], env);
|
|
212
212
|
expect(lines(res.stdout)).toContain('FAIL workflow structure — A -> "nope": no such state');
|
|
@@ -218,7 +218,7 @@ test("validate reports an agent state with no model, and accepts the workflow de
|
|
|
218
218
|
const bare = writeFixture(
|
|
219
219
|
env,
|
|
220
220
|
"no-model",
|
|
221
|
-
`A: { type: "agent", prompt: "p", on: { done: EXIT } }`,
|
|
221
|
+
`A: { type: "agent", prompt: "p", outputType: { safeParse: () => ({ success: true }) }, on: { done: EXIT } }`,
|
|
222
222
|
);
|
|
223
223
|
|
|
224
224
|
const res = await runCli(["validate", bare], env);
|
|
@@ -231,7 +231,7 @@ test("validate reports an agent state with no model, and accepts the workflow de
|
|
|
231
231
|
const defaulted = writeFixture(
|
|
232
232
|
env,
|
|
233
233
|
"default-model",
|
|
234
|
-
`A: { type: "agent", prompt: "p", on: { done: EXIT } }`,
|
|
234
|
+
`A: { type: "agent", prompt: "p", outputType: { safeParse: () => ({ success: true }) }, on: { done: EXIT } }`,
|
|
235
235
|
`agent: { model: "claude-test-model" },`,
|
|
236
236
|
);
|
|
237
237
|
expect((await runCli(["validate", defaulted], env)).code).toBe(0);
|
|
@@ -254,7 +254,7 @@ function writeRunnerFixture(env: Env, name: string, exports: string, states: str
|
|
|
254
254
|
|
|
255
255
|
function agentState(runner?: string, next = "EXIT"): string {
|
|
256
256
|
const selected = runner === undefined ? "" : `runner: "${runner}", `;
|
|
257
|
-
return `{ type: "agent", ${selected}agent: { model: "claude-test-model" }, prompt: "p", next: ${next} }`;
|
|
257
|
+
return `{ type: "agent", ${selected}agent: { model: "claude-test-model" }, prompt: "p", outputType: { safeParse: () => ({ success: true }) }, next: ${next} }`;
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
test("validate reports an unknown runner name with the state and the known names", async () => {
|
|
@@ -345,7 +345,7 @@ function fakeOpencode(script: string): Record<string, string> {
|
|
|
345
345
|
|
|
346
346
|
function writeModelFixture(env: Env): string {
|
|
347
347
|
const state = (model: string, next: string, runner = "") =>
|
|
348
|
-
`{ type: "agent", ${runner}agent: { model: "${model}" }, prompt: "p", next: ${next} }`;
|
|
348
|
+
`{ type: "agent", ${runner}agent: { model: "${model}" }, prompt: "p", outputType: { safeParse: () => ({ success: true }) }, next: ${next} }`;
|
|
349
349
|
return writeRunnerFixture(
|
|
350
350
|
env,
|
|
351
351
|
"models",
|
|
@@ -412,7 +412,7 @@ test("validate reports dead-end leaves", async () => {
|
|
|
412
412
|
const dir = writeFixture(
|
|
413
413
|
env,
|
|
414
414
|
"dead-end",
|
|
415
|
-
`A: { type: "agent", agent: { model: "claude-test-model" }, prompt: "p" }`,
|
|
415
|
+
`A: { type: "agent", agent: { model: "claude-test-model" }, prompt: "p", outputType: { safeParse: () => ({ success: true }) } }`,
|
|
416
416
|
);
|
|
417
417
|
const res = await runCli(["validate", dir], env);
|
|
418
418
|
expect(lines(res.stdout)).toContain('FAIL workflow structure — "A": dead end, no on/next');
|
|
@@ -466,7 +466,7 @@ test("validate does not check skills — stale copies never touch its verdict",
|
|
|
466
466
|
const dir = writeFixture(
|
|
467
467
|
env,
|
|
468
468
|
"happy",
|
|
469
|
-
`A: { type: "agent", agent: { model: "claude-test-model" }, prompt: "p", on: { done: EXIT } }`,
|
|
469
|
+
`A: { type: "agent", agent: { model: "claude-test-model" }, prompt: "p", outputType: { safeParse: () => ({ success: true }) }, on: { done: EXIT } }`,
|
|
470
470
|
);
|
|
471
471
|
|
|
472
472
|
const res = await runCli(["validate", dir], env);
|
package/src/cli/index.ts
CHANGED
|
@@ -248,6 +248,8 @@ function describeValidationError(err: WorkflowValidationError): string {
|
|
|
248
248
|
return `"${err.state}": names no runner and the workflow has no default agentRunner`;
|
|
249
249
|
case "missing-model":
|
|
250
250
|
return `"${err.state}": no model, pin agent: { model } on the state or, without a runner, on the workflow`;
|
|
251
|
+
case "missing-output-type":
|
|
252
|
+
return `"${err.state}": agent leaf has no outputType — declare the schema of its handoff output (OutputSchema, see output-validation)`;
|
|
251
253
|
}
|
|
252
254
|
}
|
|
253
255
|
|
package/src/cli/tarball.test.ts
CHANGED
|
@@ -13,8 +13,14 @@ const pkgDir = resolve(import.meta.dir, "..", "..");
|
|
|
13
13
|
|
|
14
14
|
test("tarball smoke: allowlist ships the runtime dirs and the installed CLI works", async () => {
|
|
15
15
|
const npm = Bun.which("npm");
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// Some boxes carry an npm shim that only forwards run/test/build to bun
|
|
17
|
+
// (node/npm not installed). The smoke test needs a real `npm pack`, so a
|
|
18
|
+
// shim that cannot even report a version skips it, same as no npm.
|
|
19
|
+
const probe = npm
|
|
20
|
+
? Bun.spawnSync([npm, "--version"], { stdout: "pipe", stderr: "pipe" })
|
|
21
|
+
: undefined;
|
|
22
|
+
if (!npm || probe?.exitCode !== 0) {
|
|
23
|
+
console.warn("npm not usable — skipping tarball smoke test");
|
|
18
24
|
return;
|
|
19
25
|
}
|
|
20
26
|
|