@psimona/darkf 0.5.0 → 0.7.1
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 +177 -0
- package/docs/concepts/handoff.md +91 -0
- package/docs/concepts/journal.md +92 -0
- package/docs/concepts/node-types.md +177 -0
- package/docs/guides/pick-an-agent-runner.md +57 -0
- package/docs/guides/plan-with-a-task-queue.md +411 -0
- package/docs/guides/render-to-mermaid.md +22 -0
- package/docs/guides/run-detached-and-monitor.md +76 -0
- package/docs/guides/test-your-workflow.md +20 -0
- package/docs/guides/write-your-first-workflow.md +101 -0
- package/docs/index.mdx +68 -0
- package/docs/reference/cli-commands.md +105 -0
- package/docs/reference/core-types.md +128 -0
- package/docs/reference/package-map.md +39 -0
- package/docs/start-here/install.md +71 -0
- package/docs/start-here/quickstart.md +248 -0
- package/package.json +15 -2
- package/skills/darkf-usage/SKILL.md +92 -0
- package/skills/darkf-writing-workflows/SKILL.md +213 -0
- package/src/cli/doctor.test.ts +338 -0
- package/src/cli/index.ts +139 -15
- package/src/cli/setup.test.ts +384 -0
- package/src/cli/setup.ts +281 -0
- package/src/cli/state-file.ts +14 -0
- package/src/cli/tarball.test.ts +127 -0
- package/src/cli/update.test.ts +82 -0
- package/src/cli/update.ts +24 -9
- package/src/core/tasks.ts +1 -1
- package/src/core/types.test.ts +52 -0
- package/src/core/types.ts +33 -16
- package/src/engine/run.test.ts +462 -3
- package/src/engine/run.ts +114 -8
- package/src/exports.ts +4 -0
- package/src/kit/agents/claude-code.ts +4 -34
- package/src/kit/agents/handoff.test.ts +12 -0
- package/src/kit/agents/handoff.ts +32 -8
- package/src/kit/agents/opencode.test.ts +232 -2
- package/src/kit/agents/opencode.ts +80 -31
- package/src/kit/specs.test.ts +247 -0
- package/src/kit/specs.ts +344 -0
- package/src/kit/status.test.ts +67 -0
- package/src/kit/status.ts +29 -4
- package/src/kit/validation/zod.test.ts +42 -0
- package/src/kit/validation/zod.ts +20 -0
- package/workflows/dev-loop/scripts/begin.ts +9 -6
- package/workflows/dev-loop/scripts/dispatch.ts +50 -0
- package/workflows/dev-loop/scripts/finish.ts +26 -21
- package/workflows/dev-loop/scripts/mark-done.ts +22 -0
- package/workflows/dev-loop/scripts/validate-plan.ts +30 -0
- package/workflows/dev-loop/workflow.ts +171 -64
- package/bunfig.toml +0 -13
- package/examples/article-classifier/data/articles.ts +0 -38
- package/examples/article-classifier/scripts/next.ts +0 -7
- package/examples/article-classifier/scripts/queue.ts +0 -33
- package/examples/article-classifier/scripts/record.ts +0 -9
- package/examples/article-classifier/workflow.ts +0 -44
- package/examples/haiku-commit/scripts/check.ts +0 -24
- package/examples/haiku-commit/workflow.ts +0 -28
- package/examples/haiku-readme/scripts/test.ts +0 -13
- package/examples/haiku-readme/scripts/write.ts +0 -10
- package/examples/haiku-readme/workflow.ts +0 -41
- package/examples/task-queue/scripts/next.ts +0 -20
- package/examples/task-queue/scripts/record.ts +0 -20
- package/examples/task-queue/supervise.ts +0 -57
- package/examples/task-queue/workflow.ts +0 -33
- package/feedback/2026-10-30-self-update.md +0 -29
- package/feedback/2026-10-31-task-list-json.md +0 -26
- package/tsconfig.json +0 -4
- /package/workflows/dev-loop/scripts/{check.ts → test.ts} +0 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: CLI commands
|
|
3
|
+
description: Every darkf subcommand, its arguments, and its exit codes.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
All commands take a workflow reference as their directory argument: a
|
|
7
|
+
filesystem path, or a bare name resolved against
|
|
8
|
+
`<cwd>/darkf/<name>` first, then `<darkf>/workflows/<name>`.
|
|
9
|
+
|
|
10
|
+
`darkf/` (no dot) is where your own workflow config lives — commit it.
|
|
11
|
+
`.darkf/` (dot-prefixed) is a different directory entirely: darkf's own
|
|
12
|
+
runtime/run-storage, gitignore it wholesale.
|
|
13
|
+
|
|
14
|
+
### `darkf render <dir>`
|
|
15
|
+
|
|
16
|
+
Prints the workflow's mermaid `stateDiagram-v2` to stdout. Never executes
|
|
17
|
+
anything.
|
|
18
|
+
|
|
19
|
+
### `darkf run <dir> [message]`
|
|
20
|
+
|
|
21
|
+
Runs the workflow in-process, blocking until it finishes. `message`
|
|
22
|
+
overrides the workflow module's own `input` export, becoming
|
|
23
|
+
`{ output: { message } }` for the first dispatch. Prints each dispatch's
|
|
24
|
+
event, the final status, and the journal path. Writes `.darkf/last-run.mmd`.
|
|
25
|
+
|
|
26
|
+
### `darkf start <dir> [message]`
|
|
27
|
+
|
|
28
|
+
Launches the workflow as a detached worker (survives the launching
|
|
29
|
+
process exiting) and returns immediately. Prints `{"runId", "pid"}` as
|
|
30
|
+
JSON. Exits `1` if the worker dies during its own startup.
|
|
31
|
+
|
|
32
|
+
### `darkf status [--run <runId>]`
|
|
33
|
+
|
|
34
|
+
Reads the journal for the given run and prints a digest: current node,
|
|
35
|
+
visit counts, any crash reason, elapsed/runtime. While a node is
|
|
36
|
+
waiting out a provider usage limit, the digest also carries a
|
|
37
|
+
`warn: usage limit — probe N/48, next attempt in Xm` line. Without
|
|
38
|
+
`--run`, resolves to whichever run is currently cached as `running` —
|
|
39
|
+
once a run has finished, pass its id explicitly (exit `7`, "nothing to
|
|
40
|
+
monitor", names the most recent finished run as a hint if omitted).
|
|
41
|
+
|
|
42
|
+
| Exit code | Meaning |
|
|
43
|
+
|---|---|
|
|
44
|
+
| `0` | succeeded |
|
|
45
|
+
| `1` | crashed |
|
|
46
|
+
| `2` | orphaned — worker PID gone, journal has no terminal marker |
|
|
47
|
+
| `3` | running |
|
|
48
|
+
| `4` | no such run for the given `--run` |
|
|
49
|
+
| `5` | ambiguous — multiple runs cached as running; pass `--run` |
|
|
50
|
+
| `7` | nothing to monitor |
|
|
51
|
+
|
|
52
|
+
### `darkf monitor [--run <runId>] [--window <seconds>] [--once]`
|
|
53
|
+
|
|
54
|
+
Tails the journal, printing each new transition as it's written, until the
|
|
55
|
+
run finishes, `--window` elapses (default 30s), or `--once` is set. While
|
|
56
|
+
a node waits out a provider usage limit, the wait line re-prints each
|
|
57
|
+
time the probe count advances.
|
|
58
|
+
Returns `6` ("still running") if the window elapses or `--once` is passed
|
|
59
|
+
without the run finishing; otherwise the same exit codes as `status`.
|
|
60
|
+
|
|
61
|
+
### `darkf report [--run <runId>]`
|
|
62
|
+
|
|
63
|
+
Prints a full dispatch timeline (state, duration, outcome per step), visit
|
|
64
|
+
counts, crash reasons, and a token/cost summary if any agent dispatch
|
|
65
|
+
wrote a usage sidecar. Works on any resolvable run, finished or not — but,
|
|
66
|
+
like `status`, needs `--run <runId>` once that run is no longer cached as
|
|
67
|
+
`running`.
|
|
68
|
+
|
|
69
|
+
### `darkf doctor`
|
|
70
|
+
|
|
71
|
+
Environment checks, no target argument: the `claude`/`opencode` binaries
|
|
72
|
+
are on `PATH`, the current working directory isn't inside the darkf
|
|
73
|
+
checkout itself, and it's inside a git repo (every run's artifacts live
|
|
74
|
+
under `.darkf/` in whatever directory you invoke from — this catches
|
|
75
|
+
running from somewhere that isn't actually a project). Also reports the
|
|
76
|
+
state of the bundled `darkf-*` skills for every known harness (claude,
|
|
77
|
+
opencode, codex, gemini, cursor): `ok`, `missing`, or `differs` for a
|
|
78
|
+
present harness, `harness not present` for an absent one. Writes
|
|
79
|
+
nothing — fixing skill drift is always `darkf setup`. Exits `0` if every
|
|
80
|
+
check passes, `1` otherwise.
|
|
81
|
+
|
|
82
|
+
### `darkf validate <ref>`
|
|
83
|
+
|
|
84
|
+
Workflow checks, no environment: the workflow resolves, `workflow.ts`
|
|
85
|
+
loads, it exports `workflow` and (if needed) `agentRunner`, and the state
|
|
86
|
+
graph structure validates. Exits `0` if every check passes, `1`
|
|
87
|
+
otherwise.
|
|
88
|
+
|
|
89
|
+
### `darkf setup`
|
|
90
|
+
|
|
91
|
+
Installs the bundled `darkf-*` skills (`darkf-usage`,
|
|
92
|
+
`darkf-writing-workflows`) into every detected skill host's skills dir
|
|
93
|
+
(claude, opencode, codex, gemini, cursor — detected by its skills dir
|
|
94
|
+
existing or its binary being on `PATH`, creating the dir when needed).
|
|
95
|
+
Writes only inside the `darkf-*` namespace: a missing copy is installed,
|
|
96
|
+
a stale one is replaced, so the installed dir always mirrors what the
|
|
97
|
+
package ships — local edits to a `darkf-*` skill do not survive a setup.
|
|
98
|
+
Foreign skill dirs are never touched. Re-running a converged setup is a
|
|
99
|
+
no-op. Takes no flags. Exits `0` on success, `1` if a copy failed.
|
|
100
|
+
|
|
101
|
+
### `darkf workflows`
|
|
102
|
+
|
|
103
|
+
Lists every workflow darkf can resolve by bare name, from both
|
|
104
|
+
`<cwd>/darkf/` and the darkf package's own `workflows/`,
|
|
105
|
+
tagged `workspace` or `built-in`.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Core types
|
|
3
|
+
description: The shared vocabulary every darkf folder builds on — @psimona/darkf/src/core/types.ts.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
These types are `core`'s whole public surface. Everything else in
|
|
7
|
+
the repo is built on top of them.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
export interface NodeResult {
|
|
11
|
+
event?: string;
|
|
12
|
+
output?: unknown;
|
|
13
|
+
sessionId?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const EXIT = "[*]" as const;
|
|
17
|
+
|
|
18
|
+
export interface AgentStateDef {
|
|
19
|
+
type: "agent";
|
|
20
|
+
prompt: string;
|
|
21
|
+
agent?: Record<string, unknown>;
|
|
22
|
+
outputType?: OutputSchema; // checks result.output, before `validate` runs
|
|
23
|
+
on?: Record<string, string>;
|
|
24
|
+
next?: string;
|
|
25
|
+
retries?: number;
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
usageLimitRetryMs?: number;
|
|
28
|
+
usageLimitMaxWaitMs?: number;
|
|
29
|
+
validate?: (result: NodeResult, handoff: NodeResult) => string | undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface OutputSchema {
|
|
33
|
+
safeParse(value: unknown): { success: true } | { success: false; message: string };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ScriptStateDef {
|
|
37
|
+
type: "script";
|
|
38
|
+
file: string;
|
|
39
|
+
on?: Record<string, string>;
|
|
40
|
+
next?: string;
|
|
41
|
+
retries?: number;
|
|
42
|
+
timeoutMs?: number;
|
|
43
|
+
usageLimitRetryMs?: number;
|
|
44
|
+
usageLimitMaxWaitMs?: number;
|
|
45
|
+
validate?: (result: NodeResult, handoff: NodeResult) => string | undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface CompositeStateDef {
|
|
49
|
+
initial: string;
|
|
50
|
+
states: Record<string, StateDef>;
|
|
51
|
+
maxCycles?: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type StateDef = AgentStateDef | ScriptStateDef | CompositeStateDef;
|
|
55
|
+
|
|
56
|
+
export interface WorkflowDef {
|
|
57
|
+
initial: string;
|
|
58
|
+
states: Record<string, StateDef>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface DispatchInfo {
|
|
62
|
+
runId: string;
|
|
63
|
+
validEvents: string[];
|
|
64
|
+
hasFallback: boolean;
|
|
65
|
+
attempt: number;
|
|
66
|
+
sessionId?: string;
|
|
67
|
+
previousFailure?: CrashReason;
|
|
68
|
+
step: number;
|
|
69
|
+
rootDir: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface AgentRunner {
|
|
73
|
+
kind?: string;
|
|
74
|
+
run(id: string, def: AgentStateDef, handoff: NodeResult, info: DispatchInfo): Promise<NodeResult>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface ScriptRunner {
|
|
78
|
+
run(id: string, def: ScriptStateDef, handoff: NodeResult, baseDir: string, info: DispatchInfo): Promise<NodeResult>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type NodeStatus =
|
|
82
|
+
| { phase: "pending" }
|
|
83
|
+
| { phase: "running"; attempt: number; startedAt: number; lastHeartbeat: number; sessionId?: string;
|
|
84
|
+
limitBackoff?: { probe: number; nextAttemptAt: number; waitedMs: number } }
|
|
85
|
+
| { phase: "succeeded"; result: NodeResult }
|
|
86
|
+
| { phase: "crashed"; reason: CrashReason; attempt: number };
|
|
87
|
+
|
|
88
|
+
export type CrashReason =
|
|
89
|
+
| { kind: "runner-error"; error: string }
|
|
90
|
+
| { kind: "usage-limit"; detail: string }
|
|
91
|
+
| { kind: "timeout"; elapsedMs: number }
|
|
92
|
+
| { kind: "malformed-result" }
|
|
93
|
+
| { kind: "validation-failed"; message: string }
|
|
94
|
+
| { kind: "no-transition"; state: string; event?: string }
|
|
95
|
+
| { kind: "unresolved-target"; from: string; target: string }
|
|
96
|
+
| { kind: "duplicate-id"; id: string }
|
|
97
|
+
| { kind: "max-steps"; steps: number; state: string }
|
|
98
|
+
| { kind: "cycle-limit"; composite: string; cycles: number };
|
|
99
|
+
|
|
100
|
+
export interface StepTrace {
|
|
101
|
+
state: string;
|
|
102
|
+
scopePath: string[];
|
|
103
|
+
result: NodeResult;
|
|
104
|
+
timestamp: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface NodeEvent {
|
|
108
|
+
runId: string;
|
|
109
|
+
state: string;
|
|
110
|
+
scopePath: string[];
|
|
111
|
+
status: NodeStatus;
|
|
112
|
+
timestamp: number;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface RunResult {
|
|
116
|
+
runId: string;
|
|
117
|
+
trace: StepTrace[];
|
|
118
|
+
node: NodeStatus;
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
`NodeEvent` is the journal's own line shape — see [Journal](../../concepts/journal/).
|
|
123
|
+
`StepTrace` is narrower: one entry per succeeded leaf dispatch, used
|
|
124
|
+
for routing and debugging rather than the full transition history.
|
|
125
|
+
|
|
126
|
+
See [Node types](../../concepts/node-types/) and [Failure
|
|
127
|
+
modes](../../concepts/failure-modes/) for what these mean in use, not just
|
|
128
|
+
their shape.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Package map
|
|
3
|
+
description: What each package and source folder is responsible for.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
darkf ships two packages:
|
|
7
|
+
|
|
8
|
+
- **`@psimona/darkf`** — everything a workflow author or the `darkf` binary
|
|
9
|
+
needs (npm publishes the unscoped `darkf` name as blocked).
|
|
10
|
+
One package, four source folders under `src/`, laid out as one strict
|
|
11
|
+
dependency chain:
|
|
12
|
+
- **`core/`** — the shared vocabulary: `types.ts` (every type on this
|
|
13
|
+
site's [Core types](../core-types/) page), `graph.ts`
|
|
14
|
+
(registry-building and target resolution), `mermaid.ts` (render-only,
|
|
15
|
+
never parsed back), `journal.ts` (the JSONL event shape). One
|
|
16
|
+
runtime dependency, Zod — `types.ts` uses it for the fixed
|
|
17
|
+
`NodeResult` envelope check; no public type references a schema
|
|
18
|
+
library.
|
|
19
|
+
- **`engine/`** — the interpreter. `run.ts` is the dispatch loop:
|
|
20
|
+
retries, per-attempt timeouts, the `outputType` shape check and
|
|
21
|
+
`validate` hook, usage-limit backoff, cycle-limit and
|
|
22
|
+
`maxSteps` circuit breakers, unconditional journaling. Depends only
|
|
23
|
+
on `core/`.
|
|
24
|
+
- **`kit/`** — the workflow-authoring library: the two built-in
|
|
25
|
+
`AgentRunner` adapters (`claudeCodeRunner`, `opencodeRunner`), the
|
|
26
|
+
handoff contract, the Zod adapter for `outputType` shape checks
|
|
27
|
+
(`validation/zod.ts`), and the run registry/status helpers behind
|
|
28
|
+
[CLI commands](../cli-commands/). Depends on `core/` and `engine/`.
|
|
29
|
+
- **`cli/`** — the `darkf` binary itself. Depends on all three.
|
|
30
|
+
- **`darkf-opencode-plugin`** — an experimental OpenCode TUI integration
|
|
31
|
+
(a non-modal panel inside the OpenCode editor: workflow definitions and
|
|
32
|
+
run status, with active runs tiled side by side). No public release
|
|
33
|
+
yet. Its own package,
|
|
34
|
+
because its peer dependencies (`@opencode/plugin`, `@opentui/*`,
|
|
35
|
+
`solid-js`) are real and optional — no other consumer needs them.
|
|
36
|
+
|
|
37
|
+
A dependency-cruiser rule enforces the one-way chain
|
|
38
|
+
`core → engine → kit → cli` in CI; `core/` can never import any of its
|
|
39
|
+
own consumers, and `engine/` can never import the harness.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Install
|
|
3
|
+
description: Install the darkf CLI and add darkf to a project.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
darkf publishes to npm as **`@psimona/darkf`** (the unscoped `darkf` name
|
|
7
|
+
is blocked by npm's typosquat filter). The binary it installs is `darkf`.
|
|
8
|
+
|
|
9
|
+
## Global install
|
|
10
|
+
|
|
11
|
+
Requires [Bun](https://bun.sh) — darkf ships as source and runs on the Bun
|
|
12
|
+
runtime:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
bun install -g @psimona/darkf
|
|
16
|
+
darkf --help
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Skills
|
|
20
|
+
|
|
21
|
+
The package bundles two agent skills — `darkf-usage` and
|
|
22
|
+
`darkf-writing-workflows` — for writing and running workflows. Install
|
|
23
|
+
them into your agent host:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
darkf setup
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Setup copies both skills into every detected host's skills dir (claude,
|
|
30
|
+
opencode, codex, gemini, cursor — a host is detected by its skills dir
|
|
31
|
+
existing or its binary being on `PATH`). The installed copies always
|
|
32
|
+
mirror what the package ships: the next setup or upgrade replaces local
|
|
33
|
+
edits to a `darkf-*` skill. `darkf doctor` reports the state without
|
|
34
|
+
writing anything.
|
|
35
|
+
|
|
36
|
+
## Add to a Bun project
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
bun add @psimona/darkf
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Workflow files import the API by deep path:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { EXIT, type WorkflowDef } from "@psimona/darkf/src/core/index.ts";
|
|
46
|
+
import { claudeCodeRunner } from "@psimona/darkf/src/kit/agents/claude-code.ts";
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Sibling checkout (development)
|
|
50
|
+
|
|
51
|
+
To track darkf's source live instead of a published version, clone the
|
|
52
|
+
repo next to your project and depend on the folder:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
git clone https://github.com/psimona/darkf ../darkf
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"workspaces": ["../darkf/darkf"],
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"@psimona/darkf": "workspace:*"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Two different directories named `darkf` show up here — don't conflate them:
|
|
68
|
+
`../darkf` above is the clone of this repo; `darkf/my-workflow` is a
|
|
69
|
+
directory *inside your own project*, holding your own workflow config.
|
|
70
|
+
(A third, `.darkf/`, dot-prefixed, is darkf's runtime directory inside your
|
|
71
|
+
project — gitignore that one; never gitignore `darkf/`.)
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Quickstart
|
|
3
|
+
description: Run a real agent that writes a haiku and commits it, end to end.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
darkf ships a working example — `haiku-commit` — that uses a real agent
|
|
7
|
+
(Claude Code), not a stub. One cheap LLM call, so you see what an actual
|
|
8
|
+
run looks like instead of a canned demo. It's two states: an agent writes
|
|
9
|
+
a haiku into `README.md`, and a script checks it actually landed there
|
|
10
|
+
before committing.
|
|
11
|
+
|
|
12
|
+
## How a node works
|
|
13
|
+
|
|
14
|
+
Every node — agent or script — produces a **handoff**: a small JSON object
|
|
15
|
+
carrying the node's output and, optionally, an event naming what happened.
|
|
16
|
+
|
|
17
|
+
An agent gets a prompt describing the job and that schema; if its reply
|
|
18
|
+
doesn't comply, the engine retries before giving up.
|
|
19
|
+
|
|
20
|
+
A script is plain code — it must already return a compliant handoff,
|
|
21
|
+
since there's no prompt to retry against. Once the handoff validates, the
|
|
22
|
+
engine routes on its event to the next node, or exits if no node matches
|
|
23
|
+
or retries run out.
|
|
24
|
+
|
|
25
|
+
```mermaid
|
|
26
|
+
flowchart LR
|
|
27
|
+
start-->|"dispatch"| node
|
|
28
|
+
|
|
29
|
+
subgraph node["WorkflowNode"]
|
|
30
|
+
direction LR
|
|
31
|
+
agent
|
|
32
|
+
script
|
|
33
|
+
|
|
34
|
+
agent --> handoff
|
|
35
|
+
script --> handoff
|
|
36
|
+
|
|
37
|
+
handoff
|
|
38
|
+
|
|
39
|
+
handoff --> validate
|
|
40
|
+
validate -->|"validation fails for agent execution"| agent
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
exit
|
|
44
|
+
validate -->|"no node exists"| exit
|
|
45
|
+
validate -->|"agent retries exhausted"| exit
|
|
46
|
+
|
|
47
|
+
next
|
|
48
|
+
validate -->|"next node from on map"| next
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## The example
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
// workflow.ts
|
|
55
|
+
import { EXIT, type WorkflowDef } from "@psimona/darkf/src/core/index.ts";
|
|
56
|
+
import { claudeCodeRunner } from "@psimona/darkf/src/kit/agents/claude-code.ts";
|
|
57
|
+
|
|
58
|
+
export const agentRunner = claudeCodeRunner;
|
|
59
|
+
|
|
60
|
+
export const workflow: WorkflowDef = {
|
|
61
|
+
initial: "Write",
|
|
62
|
+
states: {
|
|
63
|
+
Write: {
|
|
64
|
+
type: "agent",
|
|
65
|
+
prompt:
|
|
66
|
+
"Add a haiku about darkf to README.md, wrapped in HTML comments " +
|
|
67
|
+
"<!-- haiku:start --> and <!-- haiku:end --> on their own lines, " +
|
|
68
|
+
"so an automated check can find it.",
|
|
69
|
+
// Unconditional: Check decides what actually happened by reading the
|
|
70
|
+
// file, not by trusting whatever event the agent reports.
|
|
71
|
+
next: "Check",
|
|
72
|
+
},
|
|
73
|
+
Check: {
|
|
74
|
+
type: "script",
|
|
75
|
+
file: "check.ts",
|
|
76
|
+
on: { committed: EXIT, missing: "Write" },
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`check.ts` is plain code — no LLM involved in deciding whether the job is
|
|
83
|
+
actually done:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
// scripts/check.ts
|
|
87
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
88
|
+
import { join } from "node:path";
|
|
89
|
+
import type { DispatchInfo, NodeResult } from "@psimona/darkf/src/core/index.ts";
|
|
90
|
+
|
|
91
|
+
const START_MARKER = "<!-- haiku:start -->";
|
|
92
|
+
const END_MARKER = "<!-- haiku:end -->";
|
|
93
|
+
|
|
94
|
+
export default async function check(_handoff: NodeResult, info: DispatchInfo): Promise<NodeResult> {
|
|
95
|
+
const readmePath = join(info.rootDir, "README.md");
|
|
96
|
+
const text = existsSync(readmePath) ? readFileSync(readmePath, "utf8") : "";
|
|
97
|
+
if (!text.includes(START_MARKER) || !text.includes(END_MARKER)) {
|
|
98
|
+
return { event: "missing" };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const add = Bun.spawn(["git", "add", "README.md"], { cwd: info.rootDir });
|
|
102
|
+
if ((await add.exited) !== 0) throw new Error("git add README.md failed");
|
|
103
|
+
|
|
104
|
+
const commit = Bun.spawn(["git", "commit", "-m", "Add haiku to README"], {
|
|
105
|
+
cwd: info.rootDir,
|
|
106
|
+
});
|
|
107
|
+
if ((await commit.exited) !== 0) throw new Error("git commit failed");
|
|
108
|
+
|
|
109
|
+
return { event: "committed" };
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Render it to see the shape before running anything:
|
|
114
|
+
|
|
115
|
+
```sh
|
|
116
|
+
bunx darkf render darkf/examples/haiku-commit
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
stateDiagram-v2
|
|
121
|
+
[*] --> Write
|
|
122
|
+
Write : 🤖 Write
|
|
123
|
+
Write --> Check
|
|
124
|
+
Check : ▸ Check
|
|
125
|
+
Check --> [*] : committed
|
|
126
|
+
Check --> Write : missing
|
|
127
|
+
classDef darkfAgent fill:#6d8dfa
|
|
128
|
+
classDef darkfScript fill:#3fae6a
|
|
129
|
+
class Write darkfAgent
|
|
130
|
+
class Check darkfScript
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Rendered, that's:
|
|
134
|
+
|
|
135
|
+
```mermaid
|
|
136
|
+
stateDiagram-v2
|
|
137
|
+
[*] --> Write
|
|
138
|
+
Write : 🤖 Write
|
|
139
|
+
Write --> Check
|
|
140
|
+
Check : ▸ Check
|
|
141
|
+
Check --> [*] : committed
|
|
142
|
+
Check --> Write : missing
|
|
143
|
+
classDef darkfAgent fill:#6d8dfa
|
|
144
|
+
classDef darkfScript fill:#3fae6a
|
|
145
|
+
class Write darkfAgent
|
|
146
|
+
class Check darkfScript
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Run it
|
|
150
|
+
|
|
151
|
+
This makes one real `claude` call — real cost, typically around $0.10–$0.15
|
|
152
|
+
for a single haiku, not free. Needs the `claude` CLI installed and
|
|
153
|
+
authenticated. Run it from a scratch git repo with a `README.md`, not from
|
|
154
|
+
inside the darkf checkout itself (the agent's working directory follows
|
|
155
|
+
wherever you invoke `darkf` from):
|
|
156
|
+
|
|
157
|
+
```sh
|
|
158
|
+
mkdir my-project && cd my-project
|
|
159
|
+
git init
|
|
160
|
+
echo "# my-project" > README.md
|
|
161
|
+
git add README.md && git commit -m "initial"
|
|
162
|
+
bunx darkf run darkf/examples/haiku-commit
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
```
|
|
166
|
+
Write -> event=done
|
|
167
|
+
Check -> event=committed
|
|
168
|
+
|
|
169
|
+
status: succeeded
|
|
170
|
+
output: undefined
|
|
171
|
+
journal: .darkf/run/<runId>/journal.jsonl
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
`README.md` now has a haiku, committed:
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
<!-- haiku:start -->
|
|
178
|
+
Hidden branch of code,
|
|
179
|
+
dark-f weaves through silent logs—
|
|
180
|
+
truth waits in the shade.
|
|
181
|
+
<!-- haiku:end -->
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## The journal
|
|
185
|
+
|
|
186
|
+
Every run writes its journal to `.darkf/run/<runId>/journal.jsonl` — one
|
|
187
|
+
line per transition, JSON per line. This run's, in full:
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
{"runId":"...","state":"[*]","scopePath":[],"status":{"phase":"succeeded","result":{}},"timestamp":...}
|
|
191
|
+
{"runId":"...","state":"Write","scopePath":[],"status":{"phase":"running","attempt":1,...},"timestamp":...}
|
|
192
|
+
{"runId":"...","state":"Write","scopePath":[],"status":{"phase":"succeeded","result":{"event":"done","output":{...},"sessionId":"..."}},"timestamp":...}
|
|
193
|
+
{"runId":"...","state":"Check","scopePath":[],"status":{"phase":"running","attempt":1,...},"timestamp":...}
|
|
194
|
+
{"runId":"...","state":"Check","scopePath":[],"status":{"phase":"succeeded","result":{"event":"committed"}},"timestamp":...}
|
|
195
|
+
{"runId":"...","state":"[*]","scopePath":[],"status":{"phase":"succeeded","result":{"event":"committed"}},"timestamp":...}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Notice `Write`'s own result says `"event":"done"` — not `"committed"`.
|
|
199
|
+
That's the agent's self-report, and the workflow ignores it (`next`, not
|
|
200
|
+
`on`); only `Check`'s mechanical read of the file decides what happens
|
|
201
|
+
next. See [Journal](../../concepts/journal/) for what the begin/end
|
|
202
|
+
markers mean and why this file alone answers "did it finish, and how."
|
|
203
|
+
|
|
204
|
+
Inspect a finished run directly:
|
|
205
|
+
|
|
206
|
+
```sh
|
|
207
|
+
bunx darkf report --run <runId>
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
run: <runId>
|
|
212
|
+
message: (none)
|
|
213
|
+
span: 19.8s, 2 dispatches
|
|
214
|
+
|
|
215
|
+
dispatches:
|
|
216
|
+
Write 19.8s -> done
|
|
217
|
+
Check 0.0s -> committed
|
|
218
|
+
usage (1 agent dispatches): $0.13, 222581 in (201997 cache-read, 20572 cache-write), 1072 out
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
That's the real cost of the run above: one agent dispatch, $0.13, mostly
|
|
222
|
+
cache reads. See [CLI commands](../../reference/cli-commands/) for every
|
|
223
|
+
flag, and [Test your workflow](../../guides/test-your-workflow/) for how to
|
|
224
|
+
exercise this same routing logic without spending anything.
|
|
225
|
+
|
|
226
|
+
## See it in an editor
|
|
227
|
+
|
|
228
|
+
darkf also ships an experimental OpenCode plugin — a panel inside the
|
|
229
|
+
editor, instead of a second terminal for `darkf monitor`. Chat stays
|
|
230
|
+
visible beside it. A `panel │ full` toggle flips the panel full-screen,
|
|
231
|
+
and a narrow terminal always gets full-screen. Two tabs: `workflows`
|
|
232
|
+
catalogs every workflow definition as an expandable state graph, and
|
|
233
|
+
`runs` shows your runs. Active runs tile side by side, as many as the
|
|
234
|
+
width fits, and each drops out of the grid the moment it finishes. With
|
|
235
|
+
none active, `runs` falls back to a plain list — active runs first, each
|
|
236
|
+
with a spinner, with a search box. Selecting a run shows its live graph,
|
|
237
|
+
task tree, and dwell warnings. `Tab` cycles focus across the tab strip,
|
|
238
|
+
the content, and each tile.
|
|
239
|
+
|
|
240
|
+
<div style="border: 2px dashed var(--sl-color-gray-4); border-radius: 0.5rem; padding: 3rem 1.5rem; text-align: center; color: var(--sl-color-gray-3); margin: 1.5rem 0;">
|
|
241
|
+
Screenshot coming soon — OpenCode plugin overlay
|
|
242
|
+
</div>
|
|
243
|
+
|
|
244
|
+
It's part of this repo (`darkf-opencode-plugin`), not yet published or
|
|
245
|
+
documented as its own install step.
|
|
246
|
+
|
|
247
|
+
Next, read [Node types](../../concepts/node-types/), then write your own in
|
|
248
|
+
[Write your first workflow](../../guides/write-your-first-workflow/).
|
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@psimona/darkf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "A small, typed workflow engine for agent + script state graphs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Patrizio Simona <patriziosimona@gmail.com>",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "src/exports.ts",
|
|
9
9
|
"types": "src/exports.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"workflows",
|
|
13
|
+
"skills",
|
|
14
|
+
"docs"
|
|
15
|
+
],
|
|
10
16
|
"bin": {
|
|
11
17
|
"darkf": "src/cli/index.ts"
|
|
12
18
|
},
|
|
@@ -24,9 +30,16 @@
|
|
|
24
30
|
"state-graph",
|
|
25
31
|
"claude-code",
|
|
26
32
|
"opencode",
|
|
27
|
-
"bun"
|
|
33
|
+
"bun",
|
|
34
|
+
"dark-factory",
|
|
35
|
+
"software-factory",
|
|
36
|
+
"automation",
|
|
37
|
+
"llm-agents"
|
|
28
38
|
],
|
|
29
39
|
"engines": {
|
|
30
40
|
"bun": ">=1.2"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"zod": "^4.6.7"
|
|
31
44
|
}
|
|
32
45
|
}
|