@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,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,123 @@
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
+ on?: Record<string, string>;
23
+ next?: string;
24
+ retries?: number;
25
+ timeoutMs?: number;
26
+ usageLimitRetryMs?: number;
27
+ usageLimitMaxWaitMs?: number;
28
+ validate?: (result: NodeResult, handoff: NodeResult) => string | undefined;
29
+ }
30
+
31
+ export interface ScriptStateDef {
32
+ type: "script";
33
+ file: string;
34
+ on?: Record<string, string>;
35
+ next?: string;
36
+ retries?: number;
37
+ timeoutMs?: number;
38
+ usageLimitRetryMs?: number;
39
+ usageLimitMaxWaitMs?: number;
40
+ validate?: (result: NodeResult, handoff: NodeResult) => string | undefined;
41
+ }
42
+
43
+ export interface CompositeStateDef {
44
+ initial: string;
45
+ states: Record<string, StateDef>;
46
+ maxCycles?: number;
47
+ }
48
+
49
+ export type StateDef = AgentStateDef | ScriptStateDef | CompositeStateDef;
50
+
51
+ export interface WorkflowDef {
52
+ initial: string;
53
+ states: Record<string, StateDef>;
54
+ }
55
+
56
+ export interface DispatchInfo {
57
+ runId: string;
58
+ validEvents: string[];
59
+ hasFallback: boolean;
60
+ attempt: number;
61
+ sessionId?: string;
62
+ previousFailure?: CrashReason;
63
+ step: number;
64
+ rootDir: string;
65
+ }
66
+
67
+ export interface AgentRunner {
68
+ kind?: string;
69
+ run(id: string, def: AgentStateDef, handoff: NodeResult, info: DispatchInfo): Promise<NodeResult>;
70
+ }
71
+
72
+ export interface ScriptRunner {
73
+ run(id: string, def: ScriptStateDef, handoff: NodeResult, baseDir: string, info: DispatchInfo): Promise<NodeResult>;
74
+ }
75
+
76
+ export type NodeStatus =
77
+ | { phase: "pending" }
78
+ | { phase: "running"; attempt: number; startedAt: number; lastHeartbeat: number; sessionId?: string;
79
+ limitBackoff?: { probe: number; nextAttemptAt: number; waitedMs: number } }
80
+ | { phase: "succeeded"; result: NodeResult }
81
+ | { phase: "crashed"; reason: CrashReason; attempt: number };
82
+
83
+ export type CrashReason =
84
+ | { kind: "runner-error"; error: string }
85
+ | { kind: "usage-limit"; detail: string }
86
+ | { kind: "timeout"; elapsedMs: number }
87
+ | { kind: "malformed-result" }
88
+ | { kind: "validation-failed"; message: string }
89
+ | { kind: "no-transition"; state: string; event?: string }
90
+ | { kind: "unresolved-target"; from: string; target: string }
91
+ | { kind: "duplicate-id"; id: string }
92
+ | { kind: "max-steps"; steps: number; state: string }
93
+ | { kind: "cycle-limit"; composite: string; cycles: number };
94
+
95
+ export interface StepTrace {
96
+ state: string;
97
+ scopePath: string[];
98
+ result: NodeResult;
99
+ timestamp: number;
100
+ }
101
+
102
+ export interface NodeEvent {
103
+ runId: string;
104
+ state: string;
105
+ scopePath: string[];
106
+ status: NodeStatus;
107
+ timestamp: number;
108
+ }
109
+
110
+ export interface RunResult {
111
+ runId: string;
112
+ trace: StepTrace[];
113
+ node: NodeStatus;
114
+ }
115
+ ```
116
+
117
+ `NodeEvent` is the journal's own line shape — see [Journal](../../concepts/journal/).
118
+ `StepTrace` is narrower: one entry per succeeded leaf dispatch, used
119
+ for routing and debugging rather than the full transition history.
120
+
121
+ See [Node types](../../concepts/node-types/) and [Failure
122
+ modes](../../concepts/failure-modes/) for what these mean in use, not just
123
+ their shape.
@@ -0,0 +1,35 @@
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). Zero
16
+ runtime dependencies — nothing it depends on, by design.
17
+ - **`engine/`** — the interpreter. `run.ts` is the dispatch loop:
18
+ retries, per-attempt timeouts, the `validate` hook, usage-limit
19
+ backoff, cycle-limit and
20
+ `maxSteps` circuit breakers, unconditional journaling. Depends only
21
+ on `core/`.
22
+ - **`kit/`** — the workflow-authoring library: the two built-in
23
+ `AgentRunner` adapters (`claudeCodeRunner`, `opencodeRunner`), the
24
+ handoff contract, and the run registry/status helpers behind
25
+ [CLI commands](../cli-commands/). Depends on `core/` and `engine/`.
26
+ - **`cli/`** — the `darkf` binary itself. Depends on all three.
27
+ - **`darkf-opencode-plugin`** — an experimental OpenCode TUI integration
28
+ (a live pane showing run status inside the OpenCode editor). No public
29
+ release yet. Its own package,
30
+ because its peer dependencies (`@opencode-ai/plugin`, `@opentui/*`,
31
+ `solid-js`) are real and optional — no other consumer needs them.
32
+
33
+ A dependency-cruiser rule enforces the one-way chain
34
+ `core → engine → kit → cli` in CI; `core/` can never import any of its
35
+ 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,241 @@
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 live pane showing a
229
+ run's status, journal, and dwell warnings inside the editor while a
230
+ workflow executes, instead of needing a second terminal for `darkf
231
+ monitor`.
232
+
233
+ <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;">
234
+ Screenshot coming soon — OpenCode plugin status pane
235
+ </div>
236
+
237
+ It's part of this repo (`darkf-opencode-plugin`), not yet published or
238
+ documented as its own install step.
239
+
240
+ Next, read [Node types](../../concepts/node-types/), then write your own in
241
+ [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.5.0",
3
+ "version": "0.6.0",
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
  },
@@ -0,0 +1,92 @@
1
+ ---
2
+ name: darkf-usage
3
+ description: Use when starting, monitoring, or inspecting a darkf workflow run, checking whether a run is stuck, or reading a run report or journal
4
+ ---
5
+
6
+ # Using darkf
7
+
8
+ ## Overview
9
+
10
+ darkf runs a TypeScript workflow graph. It dispatches AI agents (Claude Code or opencode) against a target repo. Each run detaches from your terminal and writes a journal. One rule governs everything: run darkf from the target repo, never from the darkf checkout.
11
+
12
+ ## The cwd rule
13
+
14
+ `rootDir` is the run-artifact root and the agent working directory. It is the invocation cwd. Start every run from the repo the agents will edit. `darkf validate <ref>` fails when run inside the darkf checkout. It catches the wrong-directory mistake before you waste a run.
15
+
16
+ ## Quick reference
17
+
18
+ | Task | Command (from the target repo) |
19
+ |---|---|
20
+ | Preflight | `darkf validate <ref>` |
21
+ | List visible workflows | `darkf workflows` |
22
+ | Start a detached run | `darkf start <ref> "message"` |
23
+ | Run in foreground | `darkf run <ref> "message"` |
24
+ | One-shot status | `darkf status` (add `--run <id>` for a specific run) |
25
+ | Live tail | `darkf monitor --window 120` |
26
+ | Efficacy report | `darkf report` (add `--run <id>` for a specific run) |
27
+ | Show the graph | `darkf render <ref>` |
28
+
29
+ - `<ref>` resolves in order: a path, then `<cwd>/darkf/<ref>` (project workspace), then workflows shipped with darkf.
30
+ - There is no `--help` flag. Bare `darkf` is an error.
31
+ - There is no `resume` command. Resume semantics belong to each workflow. Check the journal and `git log` first. Never re-implement finished work by hand.
32
+ - `start` prints `{"runId":...,"pid":...}` and returns. The message is positional argument 2.
33
+ - `start` and `run` refuse to start when `darkf/` has uncommitted changes. Commit or stash first, or pass `--allow-dirty-workflow`.
34
+
35
+ ## Exit codes
36
+
37
+ Exit codes for `status`. `monitor` shares most of them:
38
+
39
+ | Code | `status` says | `monitor` says |
40
+ |---|---|---|
41
+ | 0 | succeeded | succeeded |
42
+ | 1 | crashed | crashed |
43
+ | 2 | orphaned | orphaned |
44
+ | 3 | running | failed |
45
+ | 4 | failed | host-died |
46
+ | 5 | host-died | failed-start |
47
+ | 6 | failed-start | window elapsed, run still going |
48
+ | 7 | no run | no run |
49
+
50
+ A wrong `--run <id>` also exits 4. Multiple cached `running` entries make `status` exit 5 and ask for `--run <id>`.
51
+
52
+ ## Run artifacts
53
+
54
+ Everything lands under the target repo:
55
+
56
+ - `.darkf/run/<runId>/journal.jsonl` is the event log. The journal is authoritative. The registry is only a pointer.
57
+ - `.darkf/run/<runId>/usage/` holds per-dispatch cost and token sidecars.
58
+ - `.darkf/registry/<runId>.json` is a pointer entry (runId, pid, rootDir).
59
+
60
+ Add `.darkf/` to the target repo `.gitignore`.
61
+
62
+ ## Is the run alive?
63
+
64
+ Open dispatches write a heartbeat to the journal every 30 seconds. `darkf status` shows advancing `elapsed` for the open node.
65
+
66
+ - No heartbeat for more than 90 seconds → status prints `warn: stall suspected`. The warning only informs.
67
+ - Worker process gone and no terminal journal marker → status reports `orphaned` (exit 2). The outcome is unknown. Re-run.
68
+ - Journal ends with a terminal marker → `succeeded` (exit 0) or `crashed` (exit 1). The pid state does not matter.
69
+
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
+
72
+ ## After launch
73
+
74
+ The run detaches. Watching is your job.
75
+
76
+ - Tail with `darkf monitor --window 120`. One-shot with `darkf status`. A silent 10 minutes is normal. Trust the heartbeat.
77
+ - Stay with the run until it reaches a terminal state.
78
+ - A terminal state is not a shipped feature. `succeeded` means the graph completed. What happened lives in the event of the last dispatch: `darkf report --run <id>`.
79
+ - Any event routed to `DONE` ends the run with exit 0. Whether an event means shipped, stopped, or a human gate is the decision of the workflow, recorded in its `on` routes.
80
+ - `darkf report` needs `--run <id>` for a finished run. The `runId` is in the `start` output and in `.darkf/registry/`.
81
+
82
+ ## Gotchas
83
+
84
+ - A workflow may hardcode spec paths in its prompts. Read the workflow first. Check that those paths still exist in the target repo.
85
+ - Check git history first. A workflow will re-implement work that already shipped.
86
+ - The `start` message is only a label for some workflows. Check the prompts.
87
+ - Agents run for minutes per dispatch. A silent 10 minutes is normal. Trust the heartbeat, not the silence.
88
+ - The journal is authoritative. If cached registry state and the journal disagree, trust the journal. Delete nothing by hand.
89
+
90
+ ## Deep reference
91
+
92
+ The darkf package ships its full docs. Find the package: `readlink -f "$(which darkf)"`. Start at `docs/guides/run-detached-and-monitor.md` inside that directory.