@psimona/darkf 0.7.1 → 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 +18 -5
- package/docs/concepts/handoff.md +8 -4
- package/docs/concepts/node-types.md +45 -21
- package/docs/guides/pick-an-agent-runner.md +143 -4
- package/docs/guides/plan-with-a-task-queue.md +18 -2
- package/docs/guides/run-detached-and-monitor.md +4 -3
- package/docs/guides/write-your-first-workflow.md +24 -5
- package/docs/reference/cli-commands.md +24 -6
- package/docs/reference/core-types.md +41 -6
- package/docs/start-here/quickstart.md +22 -2
- package/package.json +1 -1
- package/skills/darkf-usage/SKILL.md +17 -0
- package/skills/darkf-writing-workflows/SKILL.md +25 -18
- package/src/cli/detached.test.ts +92 -2
- package/src/cli/doctor.test.ts +224 -9
- package/src/cli/index.ts +83 -12
- package/src/cli/tarball.test.ts +8 -2
- package/src/core/graph.test.ts +266 -20
- package/src/core/graph.ts +61 -3
- package/src/core/types.ts +21 -0
- package/src/engine/run.test.ts +581 -17
- package/src/engine/run.ts +50 -7
- package/src/kit/agents/claude-code.test.ts +38 -2
- package/src/kit/agents/claude-code.ts +24 -3
- package/src/kit/agents/opencode.test.ts +89 -12
- package/src/kit/agents/opencode.ts +103 -8
- package/src/kit/status.test.ts +24 -0
- package/src/kit/status.ts +25 -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 +4 -0
|
@@ -10,7 +10,7 @@ the repo is built on top of them.
|
|
|
10
10
|
export interface NodeResult {
|
|
11
11
|
event?: string;
|
|
12
12
|
output?: unknown;
|
|
13
|
-
|
|
13
|
+
agentSessionId?: string;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export const EXIT = "[*]" as const;
|
|
@@ -19,7 +19,8 @@ export interface AgentStateDef {
|
|
|
19
19
|
type: "agent";
|
|
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; required by validateWorkflow — an agent leaf without a usable one is rejected (missing-output-type)
|
|
23
24
|
on?: Record<string, string>;
|
|
24
25
|
next?: string;
|
|
25
26
|
retries?: number;
|
|
@@ -56,6 +57,7 @@ export type StateDef = AgentStateDef | ScriptStateDef | CompositeStateDef;
|
|
|
56
57
|
export interface WorkflowDef {
|
|
57
58
|
initial: string;
|
|
58
59
|
states: Record<string, StateDef>;
|
|
60
|
+
agent?: Record<string, unknown>; // default `agent` bag for states on the default runner
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
export interface DispatchInfo {
|
|
@@ -63,14 +65,22 @@ export interface DispatchInfo {
|
|
|
63
65
|
validEvents: string[];
|
|
64
66
|
hasFallback: boolean;
|
|
65
67
|
attempt: number;
|
|
66
|
-
|
|
68
|
+
agentSessionId?: string;
|
|
67
69
|
previousFailure?: CrashReason;
|
|
68
70
|
step: number;
|
|
69
71
|
rootDir: string;
|
|
70
72
|
}
|
|
71
73
|
|
|
74
|
+
export type AgentRunnerKind = "claude-code" | "opencode" | (string & {});
|
|
75
|
+
|
|
76
|
+
export interface ModelWarning {
|
|
77
|
+
model: string;
|
|
78
|
+
message: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
72
81
|
export interface AgentRunner {
|
|
73
|
-
kind?:
|
|
82
|
+
kind?: AgentRunnerKind;
|
|
83
|
+
checkModels?(models: string[], rootDir: string): Promise<ModelWarning[]>; // `darkf validate` only
|
|
74
84
|
run(id: string, def: AgentStateDef, handoff: NodeResult, info: DispatchInfo): Promise<NodeResult>;
|
|
75
85
|
}
|
|
76
86
|
|
|
@@ -80,7 +90,8 @@ export interface ScriptRunner {
|
|
|
80
90
|
|
|
81
91
|
export type NodeStatus =
|
|
82
92
|
| { phase: "pending" }
|
|
83
|
-
| { phase: "running"; attempt: number; startedAt: number; lastHeartbeat: number;
|
|
93
|
+
| { phase: "running"; attempt: number; startedAt: number; lastHeartbeat: number; agentSessionId?: string;
|
|
94
|
+
runner?: string; runnerKind?: AgentRunnerKind;
|
|
84
95
|
limitBackoff?: { probe: number; nextAttemptAt: number; waitedMs: number } }
|
|
85
96
|
| { phase: "succeeded"; result: NodeResult }
|
|
86
97
|
| { phase: "crashed"; reason: CrashReason; attempt: number };
|
|
@@ -95,7 +106,18 @@ export type CrashReason =
|
|
|
95
106
|
| { kind: "unresolved-target"; from: string; target: string }
|
|
96
107
|
| { kind: "duplicate-id"; id: string }
|
|
97
108
|
| { kind: "max-steps"; steps: number; state: string }
|
|
98
|
-
| { 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 };
|
|
99
121
|
|
|
100
122
|
export interface StepTrace {
|
|
101
123
|
state: string;
|
|
@@ -119,6 +141,19 @@ export interface RunResult {
|
|
|
119
141
|
}
|
|
120
142
|
```
|
|
121
143
|
|
|
144
|
+
On a `running` agent dispatch, `runner` is the name the state selected
|
|
145
|
+
(absent for the default runner) and `runnerKind` is the resolved runner's
|
|
146
|
+
`kind` (absent when it declares none). Script dispatches carry neither.
|
|
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
|
+
|
|
152
|
+
The runner objects are not part of a `WorkflowDef`. A workflow module
|
|
153
|
+
exports them, and `run()` takes them as `RunOptions.agentRunner` (the
|
|
154
|
+
default) and `RunOptions.agentRunners?: Record<string, AgentRunner>` (the
|
|
155
|
+
ones a state selects by name). `RunOptions` belongs to `engine`.
|
|
156
|
+
|
|
122
157
|
`NodeEvent` is the journal's own line shape — see [Journal](../../concepts/journal/).
|
|
123
158
|
`StepTrace` is narrower: one entry per succeeded leaf dispatch, used
|
|
124
159
|
for routing and debugging rather than the full transition history.
|
|
@@ -54,14 +54,17 @@ 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
|
|
|
60
61
|
export const workflow: WorkflowDef = {
|
|
61
62
|
initial: "Write",
|
|
63
|
+
agent: { model: "claude-haiku-5-5" },
|
|
62
64
|
states: {
|
|
63
65
|
Write: {
|
|
64
66
|
type: "agent",
|
|
67
|
+
outputType: writeOutput,
|
|
65
68
|
prompt:
|
|
66
69
|
"Add a haiku about darkf to README.md, wrapped in HTML comments " +
|
|
67
70
|
"<!-- haiku:start --> and <!-- haiku:end --> on their own lines, " +
|
|
@@ -79,6 +82,23 @@ export const workflow: WorkflowDef = {
|
|
|
79
82
|
};
|
|
80
83
|
```
|
|
81
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
|
+
|
|
82
102
|
`check.ts` is plain code — no LLM involved in deciding whether the job is
|
|
83
103
|
actually done:
|
|
84
104
|
|
|
@@ -189,7 +209,7 @@ line per transition, JSON per line. This run's, in full:
|
|
|
189
209
|
```
|
|
190
210
|
{"runId":"...","state":"[*]","scopePath":[],"status":{"phase":"succeeded","result":{}},"timestamp":...}
|
|
191
211
|
{"runId":"...","state":"Write","scopePath":[],"status":{"phase":"running","attempt":1,...},"timestamp":...}
|
|
192
|
-
{"runId":"...","state":"Write","scopePath":[],"status":{"phase":"succeeded","result":{"event":"done","output":{...},"
|
|
212
|
+
{"runId":"...","state":"Write","scopePath":[],"status":{"phase":"succeeded","result":{"event":"done","output":{...},"agentSessionId":"..."}},"timestamp":...}
|
|
193
213
|
{"runId":"...","state":"Check","scopePath":[],"status":{"phase":"running","attempt":1,...},"timestamp":...}
|
|
194
214
|
{"runId":"...","state":"Check","scopePath":[],"status":{"phase":"succeeded","result":{"event":"committed"}},"timestamp":...}
|
|
195
215
|
{"runId":"...","state":"[*]","scopePath":[],"status":{"phase":"succeeded","result":{"event":"committed"}},"timestamp":...}
|
|
@@ -213,7 +233,7 @@ message: (none)
|
|
|
213
233
|
span: 19.8s, 2 dispatches
|
|
214
234
|
|
|
215
235
|
dispatches:
|
|
216
|
-
Write 19.8s -> done
|
|
236
|
+
Write 19.8s -> done kind=claude-code
|
|
217
237
|
Check 0.0s -> committed
|
|
218
238
|
usage (1 agent dispatches): $0.13, 222581 in (201997 cache-read, 20572 cache-write), 1072 out
|
|
219
239
|
```
|
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,11 +24,14 @@ 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
|
|
|
30
31
|
export const workflow: WorkflowDef = {
|
|
31
32
|
initial: "Loop",
|
|
33
|
+
// Every agent state needs a model: set it here, or in the state's own `agent`.
|
|
34
|
+
agent: { model: "claude-sonnet-5-5" },
|
|
32
35
|
states: {
|
|
33
36
|
Loop: {
|
|
34
37
|
initial: "Implement",
|
|
@@ -38,7 +41,7 @@ export const workflow: WorkflowDef = {
|
|
|
38
41
|
maxCycles: 24,
|
|
39
42
|
states: {
|
|
40
43
|
Implement: {
|
|
41
|
-
type: "agent", retries: 1, prompt: IMPL,
|
|
44
|
+
type: "agent", retries: 1, prompt: IMPL, outputType: implementOutputType,
|
|
42
45
|
on: { implemented: "Verify", disputed: DONE, blocked: DONE },
|
|
43
46
|
},
|
|
44
47
|
Verify: {
|
|
@@ -48,7 +51,7 @@ export const workflow: WorkflowDef = {
|
|
|
48
51
|
on: { green: "Review", red: "Implement", blocked: DONE },
|
|
49
52
|
},
|
|
50
53
|
Review: {
|
|
51
|
-
type: "agent", retries: 1, prompt: REVIEW,
|
|
54
|
+
type: "agent", retries: 1, prompt: REVIEW, outputType: reviewOutputType,
|
|
52
55
|
on: { done: DONE, changes_requested: "Implement" },
|
|
53
56
|
},
|
|
54
57
|
},
|
|
@@ -64,24 +67,22 @@ Workflows outside the darkf package use absolute paths into the package, as in t
|
|
|
64
67
|
## Runners and the handoff contract
|
|
65
68
|
|
|
66
69
|
- Use the built-in runners (`claudeCodeRunner`, `opencodeRunner` from `src/kit/agents/`). Never parse agent stdout. The runner injects the event contract into the prompt and reads the handoff JSON file the agent writes.
|
|
70
|
+
- To run one state on another harness, export `agentRunners = { claude: claudeCodeRunner }` beside `agentRunner` and set `runner: "claude"` on the state. That state inherits nothing from `workflow.agent`, so give it its own `agent: { model }`.
|
|
67
71
|
- The handoff contains only the immediate predecessor result. If Verify must report what Implement did, Verify must relay it in its own output. Nothing carries forward unless each node re-emits it.
|
|
68
72
|
- Do not ask the agent to echo events in prose. Describe the event semantics. The runner appends the mechanics.
|
|
69
73
|
|
|
70
74
|
### Reading an agent claim off the handoff
|
|
71
75
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
`behavior_ok: true`
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
(c) => c != null && typeof (c as Claim).verdict_field === "boolean",
|
|
83
|
-
);
|
|
84
|
-
```
|
|
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.
|
|
85
86
|
|
|
86
87
|
Pair this with the maxCycles rule above: one false rejection costs a full
|
|
87
88
|
repair round, and the budget counts dispatches, not repairs.
|
|
@@ -92,7 +93,7 @@ A script default export receives `(handoff, info)` and returns a `NodeResult`. `
|
|
|
92
93
|
|
|
93
94
|
## Validate agent output with `outputType`
|
|
94
95
|
|
|
95
|
-
|
|
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.
|
|
96
97
|
|
|
97
98
|
### The `OutputSchema` interface
|
|
98
99
|
|
|
@@ -138,7 +139,13 @@ export const planOutputType = zodOutputType(PlanOutputSchema);
|
|
|
138
139
|
// workflow.ts
|
|
139
140
|
import { planOutputType } from "./schemas/plan-output.ts";
|
|
140
141
|
|
|
141
|
-
Plan: {
|
|
142
|
+
Plan: {
|
|
143
|
+
type: "agent",
|
|
144
|
+
agent: { model: "claude-sonnet-5-5" },
|
|
145
|
+
prompt: PLAN_PROMPT,
|
|
146
|
+
outputType: planOutputType,
|
|
147
|
+
on: { planned: "ValidatePlan" },
|
|
148
|
+
},
|
|
142
149
|
```
|
|
143
150
|
|
|
144
151
|
A failed check rejects the dispatch as `validation-failed`, with the joined message as the reason. It nudges before it retries: up to three corrective nudges in the same agent session, each fed the message, then a fresh attempt against `retries`. The whole sequence is one node visit — no extra `retries` consumed, no extra `maxCycles` count — but each nudge is still a full dispatch call.
|
|
@@ -210,4 +217,4 @@ Agent-authored extra files are invisible to `git diff`. Every review prompt must
|
|
|
210
217
|
|
|
211
218
|
## Verify before you run
|
|
212
219
|
|
|
213
|
-
From the target repo: `darkf validate <ref>`, then `darkf render <ref>`. The packaged guide is the long form: `docs/guides/write-your-first-workflow.md` inside the darkf package.
|
|
220
|
+
From the target repo: `darkf validate <ref>`, then `darkf render <ref>`. Read any `warn agent models` line: it does not fail validation, but the model may be misspelled or belong to another harness. The packaged guide is the long form: `docs/guides/write-your-first-workflow.md` inside the darkf package.
|
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", 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", 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
|
`,
|
|
@@ -302,6 +306,92 @@ test("status and monitor report succeeded for a run of the haiku-readme example"
|
|
|
302
306
|
expect(mon.stdout).toContain("succeeded");
|
|
303
307
|
});
|
|
304
308
|
|
|
309
|
+
// --- per-state runners ---
|
|
310
|
+
|
|
311
|
+
// Two stubs that report which one ran, and a default `kind` unlike the named one.
|
|
312
|
+
const TWO_RUNNERS: Record<string, string> = {
|
|
313
|
+
"workflow.ts": `import { type AgentRunner, EXIT, type WorkflowDef } from "@psimona/darkf/src/core/index.ts";
|
|
314
|
+
export const agentRunner: AgentRunner = {
|
|
315
|
+
kind: "opencode",
|
|
316
|
+
async run() { return { by: "default" }; },
|
|
317
|
+
};
|
|
318
|
+
export const agentRunners: Record<string, AgentRunner> = {
|
|
319
|
+
other: {
|
|
320
|
+
kind: "claude-code",
|
|
321
|
+
async run(_id, _def, handoff) { return { first: handoff.output, second: "other" }; },
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
export const workflow: WorkflowDef = {
|
|
325
|
+
initial: "A",
|
|
326
|
+
states: {
|
|
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 },
|
|
329
|
+
},
|
|
330
|
+
};
|
|
331
|
+
`,
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
test("run passes agentRunners to the engine and records the default runner's kind", async () => {
|
|
335
|
+
const root = makeProjectRoot();
|
|
336
|
+
writeFixture(root, "two-runners", TWO_RUNNERS);
|
|
337
|
+
|
|
338
|
+
const res = await runCli(["run", "two-runners"], root);
|
|
339
|
+
|
|
340
|
+
expect(res.stdout).toContain("status: succeeded");
|
|
341
|
+
expect(res.stdout).toContain('by: "default"');
|
|
342
|
+
expect(res.stdout).toContain('second: "other"');
|
|
343
|
+
expect(listEntries(root)[0]?.agentRunnerKind).toBe("opencode");
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
test("the detached worker passes agentRunners and records the default runner's kind", async () => {
|
|
347
|
+
const root = makeProjectRoot();
|
|
348
|
+
writeFixture(root, "two-runners", TWO_RUNNERS);
|
|
349
|
+
// The entry exists before the worker starts, so its `kind` merge has a target.
|
|
350
|
+
const runId = randomUUID();
|
|
351
|
+
writeEntry(root, {
|
|
352
|
+
schemaVersion: SCHEMA_VERSION,
|
|
353
|
+
runId,
|
|
354
|
+
pid: process.pid,
|
|
355
|
+
rootDir: root,
|
|
356
|
+
startedAt: Date.now(),
|
|
357
|
+
status: "running",
|
|
358
|
+
finishedAt: null,
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
const worker = await runCli(["__worker", "two-runners", runId], root);
|
|
362
|
+
|
|
363
|
+
expect(worker.code).toBe(0);
|
|
364
|
+
expect(journalTerminalState(root, runId)).toBe("succeeded");
|
|
365
|
+
expect(readEntry(root, runId)?.agentRunnerKind).toBe("opencode");
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
test("report shows the runner name and kind of each agent dispatch", async () => {
|
|
369
|
+
const root = makeProjectRoot();
|
|
370
|
+
writeFixture(root, "two-runners", TWO_RUNNERS);
|
|
371
|
+
await runCli(["run", "two-runners"], root);
|
|
372
|
+
const runId = listEntries(root)[0]!.runId;
|
|
373
|
+
|
|
374
|
+
const res = await runCli(["report", "--run", runId], root);
|
|
375
|
+
|
|
376
|
+
expect(res.code).toBe(0);
|
|
377
|
+
expect(res.stdout).toMatch(/^ {2}A .*-> \(no event\) {2}kind=opencode$/m);
|
|
378
|
+
expect(res.stdout).toMatch(/^ {2}B .*-> \(no event\) {2}runner=other {2}kind=claude-code$/m);
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
test("run crashes on an unknown runner name before any dispatch", async () => {
|
|
382
|
+
const root = makeProjectRoot();
|
|
383
|
+
const workflow = TWO_RUNNERS["workflow.ts"]!.replace('runner: "other"', 'runner: "typo"');
|
|
384
|
+
writeFixture(root, "typo", { "workflow.ts": workflow });
|
|
385
|
+
|
|
386
|
+
const res = await runCli(["run", "typo"], root);
|
|
387
|
+
|
|
388
|
+
expect(res.stdout).toContain("status: crashed");
|
|
389
|
+
expect(res.stdout).toContain(
|
|
390
|
+
'{"kind":"unknown-runner","state":"B","runner":"typo","known":["other"]}',
|
|
391
|
+
);
|
|
392
|
+
expect(res.stdout).not.toContain("A -> event=");
|
|
393
|
+
});
|
|
394
|
+
|
|
305
395
|
// --- crashed ---
|
|
306
396
|
|
|
307
397
|
test("status and monitor report crashed (with reason) for a run that crashes mid-run", async () => {
|