@psimona/darkf 0.5.0 → 0.6.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.
Files changed (54) hide show
  1. package/docs/concepts/failure-modes.md +164 -0
  2. package/docs/concepts/handoff.md +91 -0
  3. package/docs/concepts/journal.md +92 -0
  4. package/docs/concepts/node-types.md +175 -0
  5. package/docs/guides/pick-an-agent-runner.md +57 -0
  6. package/docs/guides/plan-with-a-task-queue.md +410 -0
  7. package/docs/guides/render-to-mermaid.md +22 -0
  8. package/docs/guides/run-detached-and-monitor.md +76 -0
  9. package/docs/guides/test-your-workflow.md +20 -0
  10. package/docs/guides/write-your-first-workflow.md +95 -0
  11. package/docs/index.mdx +64 -0
  12. package/docs/reference/cli-commands.md +105 -0
  13. package/docs/reference/core-types.md +123 -0
  14. package/docs/reference/package-map.md +35 -0
  15. package/docs/start-here/install.md +71 -0
  16. package/docs/start-here/quickstart.md +241 -0
  17. package/package.json +7 -1
  18. package/skills/darkf-usage/SKILL.md +92 -0
  19. package/skills/darkf-writing-workflows/SKILL.md +88 -0
  20. package/src/cli/doctor.test.ts +338 -0
  21. package/src/cli/index.ts +123 -9
  22. package/src/cli/setup.test.ts +384 -0
  23. package/src/cli/setup.ts +286 -0
  24. package/src/cli/tarball.test.ts +125 -0
  25. package/src/cli/update.test.ts +82 -0
  26. package/src/cli/update.ts +20 -0
  27. package/src/core/types.ts +8 -0
  28. package/src/engine/run.test.ts +177 -0
  29. package/src/engine/run.ts +66 -2
  30. package/src/kit/agents/opencode.test.ts +232 -2
  31. package/src/kit/agents/opencode.ts +69 -6
  32. package/src/kit/status.test.ts +67 -0
  33. package/src/kit/status.ts +25 -0
  34. package/workflows/dev-loop/scripts/begin.ts +1 -1
  35. package/workflows/dev-loop/scripts/finish.ts +4 -1
  36. package/workflows/dev-loop/workflow.ts +30 -19
  37. package/bunfig.toml +0 -13
  38. package/examples/article-classifier/data/articles.ts +0 -38
  39. package/examples/article-classifier/scripts/next.ts +0 -7
  40. package/examples/article-classifier/scripts/queue.ts +0 -33
  41. package/examples/article-classifier/scripts/record.ts +0 -9
  42. package/examples/article-classifier/workflow.ts +0 -44
  43. package/examples/haiku-commit/scripts/check.ts +0 -24
  44. package/examples/haiku-commit/workflow.ts +0 -28
  45. package/examples/haiku-readme/scripts/test.ts +0 -13
  46. package/examples/haiku-readme/scripts/write.ts +0 -10
  47. package/examples/haiku-readme/workflow.ts +0 -41
  48. package/examples/task-queue/scripts/next.ts +0 -20
  49. package/examples/task-queue/scripts/record.ts +0 -20
  50. package/examples/task-queue/supervise.ts +0 -57
  51. package/examples/task-queue/workflow.ts +0 -33
  52. package/feedback/2026-10-30-self-update.md +0 -29
  53. package/feedback/2026-10-31-task-list-json.md +0 -26
  54. package/tsconfig.json +0 -4
@@ -0,0 +1,410 @@
1
+ ---
2
+ title: Plan with a task queue
3
+ description: A durable Next/Work/Record loop, watched by hand, then by a supervisor.
4
+ ---
5
+
6
+ The quickstart's `haiku-commit` is two states that run once each. Most real
7
+ work isn't that — it's a list of things to do, worked one at a time until
8
+ the list is empty. This guide builds that shape as its own example,
9
+ `task-queue`, then watches a real run of it two ways: by hand with the CLI,
10
+ and by a small script that reacts to what the CLI only warns about.
11
+
12
+ If you haven't yet, read [Write your first workflow](../write-your-first-workflow/)
13
+ first — this guide assumes you already know what `on`/`next`, `retries`,
14
+ and a script's `(handoff, info)` signature mean.
15
+
16
+ ## The pattern
17
+
18
+ A queue needs three states that keep looping until there's nothing left:
19
+
20
+ - **Next** — script. Picks the next pending item. Nothing left → exit.
21
+ Found one → hand it to `Work`.
22
+ - **Work** — agent. Does the item.
23
+ - **Record** — script. Marks the item done, then loops back to `Next`.
24
+
25
+ the `article-classifier` example in `darkf/examples/` already has this exact shape,
26
+ but tracks its queue in plain module-scope variables — fine for one
27
+ blocking `darkf run`, since the whole run lives in one process. The moment
28
+ you want to `darkf start` a queue and check on it later from a *different*
29
+ process (which is the entire point of the next section), in-memory state
30
+ doesn't survive — the queue has to be a file. `task-queue` is that version:
31
+ the queue lives in `tasks.json`, in the target project's own directory, not
32
+ in memory.
33
+
34
+ ## The example
35
+
36
+ ```ts
37
+ // workflow.ts
38
+ import { EXIT, type WorkflowDef } from "@psimona/darkf/src/core/index.ts";
39
+ import { claudeCodeRunner } from "../../src/kit/agents/claude-code.ts";
40
+
41
+ export const agentRunner = claudeCodeRunner;
42
+
43
+ export const workflow: WorkflowDef = {
44
+ initial: "Next",
45
+ states: {
46
+ Next: {
47
+ type: "script",
48
+ file: "next.ts",
49
+ on: { found: "Work", empty: EXIT },
50
+ },
51
+ Work: {
52
+ type: "agent",
53
+ prompt:
54
+ 'Do the task named in the handoff\'s "title" field: append one ' +
55
+ "sentence to notes.md describing what you did, creating the file " +
56
+ "if it doesn't exist yet. Don't overwrite what's already there.",
57
+ next: "Record",
58
+ },
59
+ Record: {
60
+ type: "script",
61
+ file: "record.ts",
62
+ next: "Next",
63
+ },
64
+ },
65
+ };
66
+ ```
67
+
68
+ `next.ts` and `record.ts` are the only two places that touch `tasks.json`,
69
+ and they agree on one convention: `"in-progress"` means "the item `Next`
70
+ handed out, that `Record` hasn't closed out yet" — so a crash between the
71
+ two is visible as a stuck `in-progress` row, not a silently lost item.
72
+
73
+ This project-level `tasks.json` is the workflow's own durable, committed
74
+ queue. It is not the file the OpenCode plugin's tasks tab renders. That tab
75
+ reads `.darkf/run/<runId>/tasks.json`, colocated with the run's journal.
76
+ If you want the tab, have `Record` write a copy there too — `info.runId`
77
+ carries the run id. The plugin is experimental: bundled in this repo, no
78
+ public release.
79
+
80
+ ```ts
81
+ // scripts/next.ts
82
+ import { readFileSync, writeFileSync } from "node:fs";
83
+ import { join } from "node:path";
84
+ import type { DispatchInfo, NodeResult } from "@psimona/darkf/src/core/index.ts";
85
+
86
+ interface Task {
87
+ id: string;
88
+ title: string;
89
+ status: "pending" | "in-progress" | "done";
90
+ }
91
+
92
+ export default function next(_handoff: NodeResult, info: DispatchInfo): NodeResult {
93
+ const path = join(info.rootDir, "tasks.json");
94
+ const tasks: Task[] = JSON.parse(readFileSync(path, "utf8"));
95
+ const task = tasks.find((t) => t.status === "pending");
96
+ if (!task) return { event: "empty" };
97
+
98
+ task.status = "in-progress";
99
+ writeFileSync(path, JSON.stringify(tasks, null, 2));
100
+ return { event: "found", output: { title: task.title } };
101
+ }
102
+ ```
103
+
104
+ ```ts
105
+ // scripts/record.ts
106
+ import { readFileSync, writeFileSync } from "node:fs";
107
+ import { join } from "node:path";
108
+ import type { DispatchInfo, NodeResult } from "@psimona/darkf/src/core/index.ts";
109
+
110
+ interface Task {
111
+ id: string;
112
+ title: string;
113
+ status: "pending" | "in-progress" | "done";
114
+ }
115
+
116
+ export default function record(_handoff: NodeResult, info: DispatchInfo): NodeResult {
117
+ const path = join(info.rootDir, "tasks.json");
118
+ const tasks: Task[] = JSON.parse(readFileSync(path, "utf8"));
119
+ const task = tasks.find((t) => t.status === "in-progress");
120
+ if (!task) throw new Error("no in-progress task to record");
121
+
122
+ task.status = "done";
123
+ writeFileSync(path, JSON.stringify(tasks, null, 2));
124
+ return { event: "recorded" };
125
+ }
126
+ ```
127
+
128
+ `Work`'s own result is never consulted to decide whether the item is
129
+ done — same rule as the quickstart's `check.ts`. Only `Record`'s read of
130
+ `tasks.json` does. Nothing here bounds the loop with `maxCycles`: a
131
+ finite, file-backed queue already terminates on its own once every item is
132
+ `"done"`. A loop with no such ground truth (two agents going back and
133
+ forth, e.g. an implement/review cycle) is the case `maxCycles` exists for
134
+ instead — wrap that kind of loop in a composite, as the reference docs
135
+ on [core types](../../reference/core-types/) describe.
136
+
137
+ Render it:
138
+
139
+ ```sh
140
+ bunx darkf render darkf/examples/task-queue
141
+ ```
142
+
143
+ ```
144
+ stateDiagram-v2
145
+ [*] --> Next
146
+ Next : ▸ Next
147
+ Next --> Work : found
148
+ Next --> [*] : empty
149
+ Work : 🤖 Work
150
+ Work --> Record
151
+ Record : ▸ Record
152
+ Record --> Next
153
+ classDef darkfAgent fill:#6d8dfa
154
+ classDef darkfScript fill:#3fae6a
155
+ class Work darkfAgent
156
+ class Next,Record darkfScript
157
+ ```
158
+
159
+ ```mermaid
160
+ stateDiagram-v2
161
+ [*] --> Next
162
+ Next : ▸ Next
163
+ Next --> Work : found
164
+ Next --> [*] : empty
165
+ Work : 🤖 Work
166
+ Work --> Record
167
+ Record : ▸ Record
168
+ Record --> Next
169
+ classDef darkfAgent fill:#6d8dfa
170
+ classDef darkfScript fill:#3fae6a
171
+ class Work darkfAgent
172
+ class Next,Record darkfScript
173
+ ```
174
+
175
+ ## Run it
176
+
177
+ Same deal as the quickstart: a real agent dispatch per item, real cost.
178
+ Seed a queue with two items in a scratch git repo first:
179
+
180
+ ```sh
181
+ mkdir my-project && cd my-project
182
+ git init
183
+ cat > tasks.json <<'EOF'
184
+ [
185
+ { "id": "welcome", "title": "Write a one-sentence welcome note for new contributors", "status": "pending" },
186
+ { "id": "changelog", "title": "Write a one-sentence changelog entry for today", "status": "pending" }
187
+ ]
188
+ EOF
189
+ git add tasks.json && git commit -m "seed tasks"
190
+ ```
191
+
192
+ `darkf validate` is worth running first here — it checks the workflow
193
+ resolves and loads. A missing `tasks.json` or bad JSON in it fails fast
194
+ as a script crash rather than silently doing nothing. `darkf doctor`
195
+ checks the machine side — the target is a git repo, among other things:
196
+
197
+ ```sh
198
+ bunx darkf validate darkf/examples/task-queue
199
+ ```
200
+
201
+ ## Watch it manually
202
+
203
+ This is the part a single `darkf run` doesn't show: the point of
204
+ `darkf start` is that nothing is blocking, so you check in on your own
205
+ schedule.
206
+
207
+ ```sh
208
+ bunx darkf start darkf/examples/task-queue
209
+ ```
210
+
211
+ ```json
212
+ {"runId":"49d35b19-c9c5-436c-8dbc-8cc737420c3b","pid":712518}
213
+ ```
214
+
215
+ ```sh
216
+ bunx darkf status --run 49d35b19-c9c5-436c-8dbc-8cc737420c3b
217
+ ```
218
+
219
+ ```
220
+ run: 49d35b19-c9c5-436c-8dbc-8cc737420c3b
221
+ root: /path/to/my-project
222
+ state: running
223
+ current node: Work (running)
224
+ visits: {"Next":1,"Work":1}
225
+ elapsed: 3.7s (node Work)
226
+ runtime: 1ms
227
+ ```
228
+
229
+ Caught mid-`Work`: `Next` already ran once (found the first item), `Work`
230
+ is 3.7s into actually doing it. Tail it instead of polling by hand:
231
+
232
+ ```sh
233
+ bunx darkf monitor --run 49d35b19-c9c5-436c-8dbc-8cc737420c3b --window 90
234
+ ```
235
+
236
+ ```
237
+ started with: {}
238
+ Work succeeded event=done (dwell 20079ms)
239
+ Record running attempt=1 (dwell 0ms)
240
+ Record succeeded event=recorded (dwell 1ms)
241
+ Next running attempt=1 (dwell 0ms)
242
+ Next succeeded event=found (dwell 0ms)
243
+ Work running attempt=1 (dwell 0ms)
244
+ Work succeeded event=done (dwell 17770ms)
245
+ Record running attempt=1 (dwell 0ms)
246
+ Record succeeded event=recorded (dwell 0ms)
247
+ Next running attempt=1 (dwell 0ms)
248
+ Next succeeded event=empty (dwell 0ms)
249
+ [*] succeeded event=empty (dwell 0ms)
250
+ succeeded
251
+ ```
252
+
253
+ Two full `Next → Work → Record` laps, then `Next` finds nothing left and
254
+ the run exits. `tasks.json` and `notes.md` on disk now agree with that:
255
+
256
+ ```json
257
+ [
258
+ { "id": "welcome", "title": "Write a one-sentence welcome note for new contributors", "status": "done" },
259
+ { "id": "changelog", "title": "Write a one-sentence changelog entry for today", "status": "done" }
260
+ ]
261
+ ```
262
+
263
+ ```
264
+ Wrote a one-sentence welcome note for new contributors: "Welcome aboard — we're glad you're here, and we can't wait to see what you'll build with us!"
265
+
266
+ 2026-10-13: Added a one-sentence changelog entry summarizing today's work.
267
+ ```
268
+
269
+ ```sh
270
+ bunx darkf report --run 49d35b19-c9c5-436c-8dbc-8cc737420c3b
271
+ ```
272
+
273
+ ```
274
+ run: 49d35b19-c9c5-436c-8dbc-8cc737420c3b
275
+ message: (none)
276
+ span: 37.9s, 7 dispatches
277
+ visits: {"Next":3,"Work":2,"Record":2}
278
+
279
+ dispatches:
280
+ Next 0.0s -> found
281
+ Work 20.1s -> done
282
+ Record 0.0s -> recorded
283
+ Next 0.0s -> found
284
+ Work 17.8s -> done
285
+ Record 0.0s -> recorded
286
+ Next 0.0s -> empty
287
+ usage (2 agent dispatches): $0.22, 369441 in (334480 cache-read, 34941 cache-write), 1724 out
288
+ ```
289
+
290
+ Two items, two agent dispatches, $0.22. `status`'s `visits` counts distinct
291
+ states touched; `report`'s counts actual dispatches — that's why they
292
+ disagree (`{"Next":1,...}` mid-run vs. `{"Next":3,...}` after two full laps
293
+ plus the final empty check).
294
+
295
+ ## The supervisor pattern
296
+
297
+ Everything above is a human doing the checking. darkf's own CLI output
298
+ already assumes something else might be doing it instead —
299
+ `status`/`monitor` describe a stalled heartbeat as "stall suspected ...
300
+ supervisor decides" and never act on it themselves. That something is
301
+ called a **supervisor**: whatever started the run and is now watching it,
302
+ ready to do something darkf itself won't — restart a worker that died
303
+ without a clean exit, escalate a real crash, keep polling a slow one.
304
+
305
+ A supervisor can be as small as a loop around the same three commands you
306
+ just ran by hand:
307
+
308
+ ```ts
309
+ // examples/task-queue/supervise.ts
310
+ const WORKFLOW = new URL(".", import.meta.url).pathname;
311
+ const POLL_MS = 5_000;
312
+
313
+ async function darkf(...args: string[]): Promise<number> {
314
+ const proc = Bun.spawn(["bunx", "darkf", ...args], { stdout: "inherit", stderr: "inherit" });
315
+ return await proc.exited;
316
+ }
317
+
318
+ async function start(): Promise<string> {
319
+ const proc = Bun.spawn(["bunx", "darkf", "start", WORKFLOW], {
320
+ stdout: "pipe",
321
+ stderr: "inherit",
322
+ });
323
+ const stdout = await new Response(proc.stdout).text();
324
+ await proc.exited;
325
+ return (JSON.parse(stdout) as { runId: string }).runId;
326
+ }
327
+
328
+ let runId = await start();
329
+ console.log(`started run ${runId}`);
330
+
331
+ for (;;) {
332
+ const code = await darkf("monitor", "--run", runId, "--once");
333
+ if (code === 0) {
334
+ console.log("succeeded");
335
+ await darkf("report", "--run", runId);
336
+ break;
337
+ }
338
+ if (code === 1) {
339
+ console.log("crashed — see report before deciding whether to resume");
340
+ await darkf("report", "--run", runId);
341
+ break;
342
+ }
343
+ if (code === 2) {
344
+ console.log("orphaned — worker died without a terminal journal entry; restarting");
345
+ runId = await start();
346
+ continue;
347
+ }
348
+ // 6: still running. A real supervisor would check `darkf status --run`
349
+ // here too, for the stall warning the plain exit code doesn't carry.
350
+ await Bun.sleep(POLL_MS);
351
+ }
352
+ ```
353
+
354
+ Run for real, against a queue with one item:
355
+
356
+ ```
357
+ started run 6f0179e9-4c53-4498-8b51-4c59545d4cfd
358
+ started with: {}
359
+ still running
360
+ started with: {}
361
+ still running
362
+ started with: {}
363
+ still running
364
+ succeeded
365
+ succeeded
366
+ run: 6f0179e9-4c53-4498-8b51-4c59545d4cfd
367
+ message: (none)
368
+ span: 27.1s, 4 dispatches
369
+ visits: {"Next":2,"Work":1,"Record":1}
370
+
371
+ dispatches:
372
+ Next 0.0s -> found
373
+ Work 27.1s -> done
374
+ Record 0.0s -> recorded
375
+ Next 0.0s -> empty
376
+ usage (1 agent dispatches): $0.11, 186088 in (170902 cache-read, 15176 cache-write), 1219 out
377
+ ```
378
+
379
+ (The two `succeeded` lines aren't a bug in the capture above — one is
380
+ `darkf monitor`'s own stdout, inherited straight through; the other is this
381
+ script's own `console.log` right after. A quieter version would capture
382
+ `monitor`'s output instead of inheriting it.)
383
+
384
+ This script has to exist as *something* calling `darkf start` from outside
385
+ — but that something doesn't have to be a hand-rolled loop. It can equally
386
+ be an agent harness itself, mid-session, deciding to kick off a workflow
387
+ and check on it between other turns. darkf already distinguishes that
388
+ case: `darkf start`/`run` check `process.env` for a short table of
389
+ "invoked from inside harness X" signals (`SUPERVISOR_ENV_SIGNALS` in
390
+ @psimona/darkf/src/kit/registry.ts` — today just `CLAUDE_CODE_SESSION_ID`) and, if
391
+ one matches, record which session is supervising the run. The experimental
392
+ OpenCode plugin (bundled in this repo, no public release) reads that back to
393
+ show which session owns a run in its sidebar.
394
+ Nothing about the exit-code loop above changes because of it — the
395
+ difference is purely who's watching.
396
+
397
+ If you're packaging this as something a Claude Code agent reaches for
398
+ repeatedly rather than something a human runs once, this is the shape a
399
+ Claude Code **Skill** is for: the polling loop and its reactions become
400
+ the skill's instructions, and the agent supplies the judgment calls
401
+ (`darkf report` says the crash was a timeout — retry once? escalate?) that
402
+ this script's `if` statements hard-code instead.
403
+
404
+ ## Next
405
+
406
+ [Test your workflow](../test-your-workflow/) covers exercising this same
407
+ `Next`/`Work`/`Record` routing without spending anything, by swapping in a
408
+ stub `agentRunner` for `Work`. [Journal](../../concepts/journal/)
409
+ explains exactly what `status`/`monitor`/`report` are reading to produce
410
+ everything shown above.
@@ -0,0 +1,22 @@
1
+ ---
2
+ title: Render a workflow to mermaid
3
+ description: See a workflow's shape before — or while — it runs.
4
+ ---
5
+
6
+ ```sh
7
+ bunx darkf render my-workflow
8
+ ```
9
+
10
+ prints a mermaid `stateDiagram-v2` block straight to stdout — paste it into
11
+ any mermaid-aware viewer (GitHub renders mermaid code blocks natively) to
12
+ see the graph. This reads only `workflow.ts`; it never runs anything, so
13
+ it's safe to use on a workflow that calls a real paid agent.
14
+
15
+ Every `darkf run` also writes `.darkf/last-run.mmd` next to the workflow —
16
+ the same render, with the trace's last-visited state highlighted. That
17
+ file is what the quickstart's diagram in this site was generated from.
18
+
19
+ The mermaid definition is a render target, never a parsed input — darkf
20
+ never reads a `.mmd` file back as a workflow. The `WorkflowDef` object in
21
+ `workflow.ts` is the only source of truth; mermaid is strictly one-way,
22
+ generated from it.
@@ -0,0 +1,76 @@
1
+ ---
2
+ title: Run detached and monitor it
3
+ description: Start a long-running workflow in the background, then watch it.
4
+ ---
5
+
6
+ `darkf run` blocks until the workflow finishes — fine for a quick demo,
7
+ not for a workflow that runs longer than you want to keep a terminal open.
8
+ `darkf start` launches the same workflow as a detached worker that
9
+ survives the launching process exiting, and returns immediately.
10
+
11
+ ```sh
12
+ bunx darkf start my-workflow "optional seed message"
13
+ ```
14
+
15
+ ```json
16
+ {"runId":"7e1c9b2a-...","pid":48213}
17
+ ```
18
+
19
+ If the worker dies during its own startup (bad import, missing workflow
20
+ export), `start` catches that and reports failure instead of leaving a
21
+ stale "running" entry behind.
22
+
23
+ ### Checking in
24
+
25
+ ```sh
26
+ bunx darkf status
27
+ ```
28
+
29
+ Reads the journal directly — no connection to the worker process is
30
+ needed. Exit code doubles as the answer: `0` succeeded, `1` crashed, `2`
31
+ orphaned (worker PID is gone, journal has no terminal marker), `3`
32
+ running. Pass `--run <runId>` when more than one run is live.
33
+
34
+ While a node is waiting out a provider usage limit, the digest prints a
35
+ wait line — `warn: usage limit — probe 3/48, next attempt in 22m` — so
36
+ an overnight quota wall reads as a wait, not silence. The run is alive;
37
+ the exit code stays `3` ("running") until the limit lifts or the wait
38
+ budget runs out.
39
+
40
+ ### Watching live
41
+
42
+ ```sh
43
+ bunx darkf monitor --window 60
44
+ ```
45
+
46
+ Tails the journal and prints each transition as it's written, for up to
47
+ `--window` seconds (default 30) before returning `6` ("still running") so
48
+ a calling script can decide whether to keep waiting. `--once` checks and
49
+ returns immediately instead of polling. Exit codes match `status`'s.
50
+ During a usage-limit wait, the wait line re-prints each time the probe
51
+ count advances.
52
+
53
+ ### After it's done
54
+
55
+ ```sh
56
+ bunx darkf report
57
+ ```
58
+
59
+ Prints a timeline of every dispatch (state, duration, outcome), visit
60
+ counts, any crash reasons, and — if any agent dispatch wrote a usage
61
+ sidecar — a token/cost summary. Useful after the fact, whether the run
62
+ succeeded or crashed.
63
+
64
+ ### Before any of this
65
+
66
+ ```sh
67
+ bunx darkf validate my-workflow
68
+ ```
69
+
70
+ Checks that the workflow resolves and that `workflow.ts` loads and exports
71
+ `workflow` (and `agentRunner`, if any state needs one). For the machine
72
+ side, run `bunx darkf doctor`: the `claude` and `opencode` binaries on
73
+ `PATH`, and that you're not accidentally running from inside the darkf
74
+ checkout itself (a workflow's agent runner uses the invocation `cwd` as
75
+ its working directory — a common mistake when first wiring a workflow
76
+ against another repo).
@@ -0,0 +1,20 @@
1
+ ---
2
+ title: Test your workflow
3
+ description: Exercising a workflow's routing and retry logic without a real agent.
4
+ ---
5
+
6
+ :::note[Coming soon]
7
+ Not written yet — a placeholder for a planned advanced guide.
8
+ :::
9
+
10
+ The [Quickstart](../../start-here/quickstart/)'s `haiku-commit` example
11
+ wires a real `agentRunner` (`claudeCodeRunner`) directly into
12
+ `workflow.ts`, so every `bunx darkf run` costs something. Testing a
13
+ workflow's actual logic — does `Check` really route `missing` back to
14
+ `Write`, does the loop terminate, does `validate` reject what it should —
15
+ shouldn't require a real LLM call every time.
16
+
17
+ This guide will cover swapping in a stub `AgentRunner`/`ScriptRunner` for
18
+ tests (the same pattern the `haiku-readme` example's bundled stub shows),
19
+ and what's worth asserting on: the run's `trace`, the final `NodeStatus`,
20
+ or the journal itself.
@@ -0,0 +1,95 @@
1
+ ---
2
+ title: Write your first workflow
3
+ description: The minimum shape darkf needs to run.
4
+ ---
5
+
6
+ A workflow is a directory containing a `workflow.ts` that exports a
7
+ `WorkflowDef`, plus a `scripts/` directory holding anything your `script`
8
+ states reference.
9
+
10
+ ```ts
11
+ // darkf/my-workflow/workflow.ts
12
+ import { EXIT, type WorkflowDef } from "@psimona/darkf/src/core/index.ts";
13
+
14
+ export const workflow: WorkflowDef = {
15
+ initial: "Greet",
16
+ states: {
17
+ Greet: {
18
+ type: "script",
19
+ file: "greet.ts",
20
+ next: EXIT,
21
+ },
22
+ },
23
+ };
24
+ ```
25
+
26
+ ```ts
27
+ // darkf/my-workflow/scripts/greet.ts
28
+ import type { NodeResult } from "@psimona/darkf/src/core/index.ts";
29
+
30
+ export default function greet(handoff: NodeResult): NodeResult {
31
+ return { output: { greeting: "hello" } };
32
+ }
33
+ ```
34
+
35
+ `darkf/` (no dot) is where this lives in your project — commit it like any
36
+ other source. It's a different directory from `.darkf/` (dot-prefixed),
37
+ which darkf writes its own run artifacts into (journal, handoff files,
38
+ registry) and which you gitignore wholesale.
39
+
40
+ Render it before running anything — this catches unresolved targets and
41
+ duplicate ids without spending an agent call:
42
+
43
+ ```sh
44
+ bunx darkf render my-workflow
45
+ ```
46
+
47
+ Run it:
48
+
49
+ ```sh
50
+ bunx darkf run my-workflow
51
+ ```
52
+
53
+ A workflow module can also export `input` (the seed `NodeResult` for the
54
+ first dispatch), `agentRunner` (required if any state is `type: "agent"`),
55
+ and `scriptRunner` (optional — only needed if a script needs run-aware
56
+ `DispatchInfo`, not just the plain handoff).
57
+
58
+ ### Adding an agent state
59
+
60
+ An `agent` state needs a `prompt` and a configured `agentRunner`:
61
+
62
+ ```ts
63
+ Greet: {
64
+ type: "agent",
65
+ prompt: "Write a one-sentence greeting.",
66
+ on: { done: EXIT },
67
+ },
68
+ ```
69
+
70
+ ```ts
71
+ export const agentRunner: AgentRunner = claudeCodeRunner; // or opencodeRunner
72
+ ```
73
+
74
+ See [Pick an agent runner](../pick-an-agent-runner/) for the two
75
+ built-in options.
76
+
77
+ ### Branching and retrying
78
+
79
+ - `on: { eventName: "NextState" }` routes by the event a node's result
80
+ carries; `next: "NextState"` is the unconditional shorthand for a node
81
+ that always has exactly one way forward.
82
+ - `retries: 2` on a leaf bounds reattempts after a crash (default: 0, no
83
+ retry).
84
+ - `timeoutMs` caps one dispatch attempt (default: 1 hour).
85
+ - `usageLimitRetryMs` / `usageLimitMaxWaitMs` tune how a leaf waits out
86
+ a provider usage limit (defaults: re-probe every 30 minutes, give up
87
+ after 24 hours). A wait consumes no retry attempt and no `timeoutMs`
88
+ budget; see [Failure modes](../../concepts/failure-modes/).
89
+ - `validate(result, handoff)` runs a plain code check against a result
90
+ before it's accepted as `succeeded`; returning a string rejects it as a
91
+ crash, consuming a retry attempt exactly like a runner throwing would.
92
+
93
+ There is no condition-expression or YAML config layer here on purpose — see
94
+ the repo's `PHILOSOPHY.md` for why. Anything more conditional than a plain
95
+ `on` map belongs in a script's own code.
package/docs/index.mdx ADDED
@@ -0,0 +1,64 @@
1
+ ---
2
+ title: darkf
3
+ description: A typed workflow engine for deterministic automation with LLM agents. Build your dark factory on agent + script state graphs.
4
+ hero:
5
+ tagline: Deterministic automation with LLM agents. The engine for your dark factory.
6
+ actions:
7
+ - text: Quickstart
8
+ link: start-here/quickstart/
9
+ icon: right-arrow
10
+ - text: Concepts
11
+ link: concepts/node-types/
12
+ icon: right-arrow
13
+ variant: minimal
14
+ ---
15
+
16
+ import { Card, CardGrid } from '@astrojs/starlight/components';
17
+
18
+ darkf runs your automation as a workflow: a simple description of steps
19
+ and what happens next.
20
+
21
+ Some steps ask an AI agent to do the work. Some steps are plain code.
22
+ You decide which is which.
23
+
24
+ Everything the run does is written to a file as it happens. Finished,
25
+ failed, or stuck — the answer is on disk, not in a terminal you forgot
26
+ to watch. You can check yesterday's run the same way as today's.
27
+
28
+ When a step fails, the run stops right there. You see which step and
29
+ why. The engine handles the boring parts of failure: trying again,
30
+ waiting out rate limits, stopping before a loop runs away. You never
31
+ write that code.
32
+
33
+ Writing a workflow needs no setup. Describe the steps in plain words,
34
+ and a skill writes the workflow for you — best practices included. Every
35
+ workflow shows as a diagram, so the whole path stays visible and you
36
+ stay in control.
37
+
38
+ Start with one workflow. Grow it into your dark factory.
39
+
40
+ <CardGrid>
41
+ <Card title="Install" icon="download">
42
+ `bun install -g @psimona/darkf`. See [Install](start-here/install/).
43
+ </Card>
44
+ <Card title="Quickstart" icon="rocket">
45
+ One real agent call, a rendered mermaid graph, a finished run.
46
+ See [Quickstart](start-here/quickstart/).
47
+ </Card>
48
+ <Card title="Two node types" icon="puzzle">
49
+ Every leaf is `agent` or `script`; the engine dispatches both the same
50
+ way. See [Node types](concepts/node-types/).
51
+ </Card>
52
+ <Card title="The journal" icon="file-text">
53
+ Every step lands on disk. Replay, inspect, and audit after the fact.
54
+ See [The journal](concepts/journal/).
55
+ </Card>
56
+ <Card title="Failure modes" icon="shield">
57
+ What happens when an agent fails, times out, or hits a usage limit.
58
+ See [Failure modes](concepts/failure-modes/).
59
+ </Card>
60
+ <Card title="CLI + tooling" icon="seti:shell">
61
+ `setup`, `render`, `run`, `start`, `status`, `monitor`, `doctor`, `validate`, `report`.
62
+ See [CLI commands](reference/cli-commands/).
63
+ </Card>
64
+ </CardGrid>