@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.
Files changed (69) hide show
  1. package/docs/concepts/failure-modes.md +177 -0
  2. package/docs/concepts/handoff.md +91 -0
  3. package/docs/concepts/journal.md +92 -0
  4. package/docs/concepts/node-types.md +177 -0
  5. package/docs/guides/pick-an-agent-runner.md +57 -0
  6. package/docs/guides/plan-with-a-task-queue.md +411 -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 +101 -0
  11. package/docs/index.mdx +68 -0
  12. package/docs/reference/cli-commands.md +105 -0
  13. package/docs/reference/core-types.md +128 -0
  14. package/docs/reference/package-map.md +39 -0
  15. package/docs/start-here/install.md +71 -0
  16. package/docs/start-here/quickstart.md +248 -0
  17. package/package.json +15 -2
  18. package/skills/darkf-usage/SKILL.md +92 -0
  19. package/skills/darkf-writing-workflows/SKILL.md +213 -0
  20. package/src/cli/doctor.test.ts +338 -0
  21. package/src/cli/index.ts +139 -15
  22. package/src/cli/setup.test.ts +384 -0
  23. package/src/cli/setup.ts +281 -0
  24. package/src/cli/state-file.ts +14 -0
  25. package/src/cli/tarball.test.ts +127 -0
  26. package/src/cli/update.test.ts +82 -0
  27. package/src/cli/update.ts +24 -9
  28. package/src/core/tasks.ts +1 -1
  29. package/src/core/types.test.ts +52 -0
  30. package/src/core/types.ts +33 -16
  31. package/src/engine/run.test.ts +462 -3
  32. package/src/engine/run.ts +114 -8
  33. package/src/exports.ts +4 -0
  34. package/src/kit/agents/claude-code.ts +4 -34
  35. package/src/kit/agents/handoff.test.ts +12 -0
  36. package/src/kit/agents/handoff.ts +32 -8
  37. package/src/kit/agents/opencode.test.ts +232 -2
  38. package/src/kit/agents/opencode.ts +80 -31
  39. package/src/kit/specs.test.ts +247 -0
  40. package/src/kit/specs.ts +344 -0
  41. package/src/kit/status.test.ts +67 -0
  42. package/src/kit/status.ts +29 -4
  43. package/src/kit/validation/zod.test.ts +42 -0
  44. package/src/kit/validation/zod.ts +20 -0
  45. package/workflows/dev-loop/scripts/begin.ts +9 -6
  46. package/workflows/dev-loop/scripts/dispatch.ts +50 -0
  47. package/workflows/dev-loop/scripts/finish.ts +26 -21
  48. package/workflows/dev-loop/scripts/mark-done.ts +22 -0
  49. package/workflows/dev-loop/scripts/validate-plan.ts +30 -0
  50. package/workflows/dev-loop/workflow.ts +171 -64
  51. package/bunfig.toml +0 -13
  52. package/examples/article-classifier/data/articles.ts +0 -38
  53. package/examples/article-classifier/scripts/next.ts +0 -7
  54. package/examples/article-classifier/scripts/queue.ts +0 -33
  55. package/examples/article-classifier/scripts/record.ts +0 -9
  56. package/examples/article-classifier/workflow.ts +0 -44
  57. package/examples/haiku-commit/scripts/check.ts +0 -24
  58. package/examples/haiku-commit/workflow.ts +0 -28
  59. package/examples/haiku-readme/scripts/test.ts +0 -13
  60. package/examples/haiku-readme/scripts/write.ts +0 -10
  61. package/examples/haiku-readme/workflow.ts +0 -41
  62. package/examples/task-queue/scripts/next.ts +0 -20
  63. package/examples/task-queue/scripts/record.ts +0 -20
  64. package/examples/task-queue/supervise.ts +0 -57
  65. package/examples/task-queue/workflow.ts +0 -33
  66. package/feedback/2026-10-30-self-update.md +0 -29
  67. package/feedback/2026-10-31-task-list-json.md +0 -26
  68. package/tsconfig.json +0 -4
  69. /package/workflows/dev-loop/scripts/{check.ts → test.ts} +0 -0
@@ -13,10 +13,14 @@ import type { DispatchInfo, NodeResult } from "@psimona/darkf/src/core/index.ts"
13
13
  // - refuses unless master is an ancestor of the branch (master must not
14
14
  // have moved mid-run — the only case where the squash could conflict);
15
15
  // - rolls back (reset --hard + checkout back) on any git failure.
16
- const FEATURE = "task-list-json";
16
+ const FEATURE = "opencode-overlay-tiles";
17
17
  const ALLOWED = [
18
18
  "docs/",
19
19
  "darkf/src/",
20
+ "darkf/skills/",
21
+ "darkf/docs/",
22
+ "darkf/package.json",
23
+ "bun.lock",
20
24
  "darkf-opencode-plugin/",
21
25
  "ROADMAP.md",
22
26
  "README.md",
@@ -24,22 +28,23 @@ const ALLOWED = [
24
28
  "darkf/workflows/",
25
29
  ];
26
30
 
27
- function sh(...args: string[]): [string, number] {
28
- const proc = Bun.spawnSync(args, { stdout: "pipe", stderr: "pipe" });
31
+ function sh(cwd: string, ...args: string[]): [string, number] {
32
+ const proc = Bun.spawnSync(args, { cwd, stdout: "pipe", stderr: "pipe" });
29
33
  return [`${proc.stdout?.toString() ?? ""}${proc.stderr?.toString() ?? ""}`, proc.exitCode ?? 1];
30
34
  }
31
35
 
32
- function prdTitle(): string | null {
33
- const [out, rc] = sh("head", "-1", `docs/specs/${FEATURE}/prd.md`);
36
+ function prdTitle(rootDir: string): string | null {
37
+ const [out, rc] = sh(rootDir, "head", "-1", `docs/specs/${FEATURE}/prd.md`);
34
38
  if (rc !== 0) return null;
35
39
  const line = out.trim();
36
40
  return line.startsWith("# ") ? line.slice(2).trim() : null;
37
41
  }
38
42
 
39
- export default function finishBranch(_handoff: NodeResult, _info: DispatchInfo): NodeResult {
43
+ export default function finishBranch(_handoff: NodeResult, info: DispatchInfo): NodeResult {
40
44
  const branch = `feature/${FEATURE}`;
45
+ const { rootDir } = info;
41
46
 
42
- const [current, currentRc] = sh("git", "branch", "--show-current");
47
+ const [current, currentRc] = sh(rootDir, "git", "branch", "--show-current");
43
48
  if (currentRc !== 0 || current.trim() !== branch) {
44
49
  return {
45
50
  event: "merge_failed",
@@ -47,7 +52,7 @@ export default function finishBranch(_handoff: NodeResult, _info: DispatchInfo):
47
52
  };
48
53
  }
49
54
 
50
- const [status, statusRc] = sh("git", "status", "--porcelain");
55
+ const [status, statusRc] = sh(rootDir, "git", "status", "--porcelain");
51
56
  if (statusRc !== 0) {
52
57
  return { event: "merge_failed", output: { failure: "git status failed" } };
53
58
  }
@@ -65,10 +70,10 @@ export default function finishBranch(_handoff: NodeResult, _info: DispatchInfo):
65
70
  };
66
71
  }
67
72
 
68
- const title = prdTitle() ?? FEATURE;
73
+ const title = prdTitle(rootDir) ?? FEATURE;
69
74
  const subject = `feat: ${title} (${FEATURE})`;
70
- const add = sh("git", "add", "-A");
71
- const commit = add[1] === 0 ? sh("git", "commit", "-m", subject) : [add[0], 1];
75
+ const add = sh(rootDir, "git", "add", "-A");
76
+ const commit = add[1] === 0 ? sh(rootDir, "git", "commit", "-m", subject) : [add[0], 1];
72
77
  if (commit[1] !== 0) {
73
78
  return {
74
79
  event: "merge_failed",
@@ -76,7 +81,7 @@ export default function finishBranch(_handoff: NodeResult, _info: DispatchInfo):
76
81
  };
77
82
  }
78
83
 
79
- const [, ancestorRc] = sh("git", "merge-base", "--is-ancestor", "master", "HEAD");
84
+ const [, ancestorRc] = sh(rootDir, "git", "merge-base", "--is-ancestor", "master", "HEAD");
80
85
  if (ancestorRc !== 0) {
81
86
  return {
82
87
  event: "merge_failed",
@@ -87,33 +92,33 @@ export default function finishBranch(_handoff: NodeResult, _info: DispatchInfo):
87
92
  };
88
93
  }
89
94
 
90
- const [ahead] = sh("git", "log", "--oneline", `master..${branch}`);
95
+ const [ahead] = sh(rootDir, "git", "log", "--oneline", `master..${branch}`);
91
96
  if (ahead.trim() === "") {
92
97
  return { event: "merged", output: { note: "no commits ahead of master — nothing to merge" } };
93
98
  }
94
99
 
95
- const checkout = sh("git", "checkout", "master");
100
+ const checkout = sh(rootDir, "git", "checkout", "master");
96
101
  if (checkout[1] !== 0) {
97
102
  return { event: "merge_failed", output: { failure: `checkout master failed: ${checkout[0]}` } };
98
103
  }
99
104
 
100
- const merge = sh("git", "merge", "--squash", branch);
105
+ const merge = sh(rootDir, "git", "merge", "--squash", branch);
101
106
  if (merge[1] !== 0) {
102
- sh("git", "reset", "--hard", "HEAD");
103
- sh("git", "checkout", branch);
107
+ sh(rootDir, "git", "reset", "--hard", "HEAD");
108
+ sh(rootDir, "git", "checkout", branch);
104
109
  return { event: "merge_failed", output: { failure: `squash merge failed: ${merge[0]}` } };
105
110
  }
106
111
 
107
112
  const body =
108
113
  "Landed via the dev-loop darkf workflow — check gate green, independent review approved.";
109
- const final = sh("git", "commit", "-m", subject, "-m", body);
114
+ const final = sh(rootDir, "git", "commit", "-m", subject, "-m", body);
110
115
  if (final[1] !== 0) {
111
- sh("git", "reset", "--hard", "HEAD");
112
- sh("git", "checkout", branch);
116
+ sh(rootDir, "git", "reset", "--hard", "HEAD");
117
+ sh(rootDir, "git", "checkout", branch);
113
118
  return { event: "merge_failed", output: { failure: `squash commit failed: ${final[0]}` } };
114
119
  }
115
120
 
116
- const del = sh("git", "branch", "-D", branch);
121
+ const del = sh(rootDir, "git", "branch", "-D", branch);
117
122
  const note =
118
123
  del[1] === 0
119
124
  ? `squashed ${branch} to master as ${subject}; branch deleted`
@@ -0,0 +1,22 @@
1
+ import { readFile, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import type { DispatchInfo, NodeResult, TaskList } from "@psimona/darkf/src/core/index.ts";
4
+
5
+ // The deterministic half of Review's approval: Review judges whether the
6
+ // in-progress task's claim actually holds (it never touches files to do
7
+ // so); this script does the one mechanical write that follows — agent for
8
+ // judgment, script for the bookkeeping, per darkf-writing-workflows. Only
9
+ // Dispatch and this script ever write tasks.json, and Dispatch always
10
+ // just wrote a valid one before handing off, so there is nothing here to
11
+ // re-validate.
12
+ export default async function markDone(
13
+ _handoff: NodeResult,
14
+ info: DispatchInfo,
15
+ ): Promise<NodeResult> {
16
+ const path = join(info.rootDir, ".darkf", "run", info.runId, "tasks.json");
17
+ const list = JSON.parse(await readFile(path, "utf8")) as TaskList;
18
+ const current = list.tasks.find((t) => t.status === "in-progress");
19
+ if (current) current.status = "done";
20
+ await writeFile(path, JSON.stringify(list, null, 2));
21
+ return { event: "marked", output: {} };
22
+ }
@@ -0,0 +1,30 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import {
4
+ type DispatchInfo,
5
+ type NodeResult,
6
+ parseTaskList,
7
+ } from "@psimona/darkf/src/core/index.ts";
8
+
9
+ // Plan (agent) distills the spec into a candidate TaskList and hands it on
10
+ // as its own output — judgment work, free-form prose in, structured JSON
11
+ // out, not something a deterministic script could do. Persisting it to the
12
+ // canonical .darkf/run/<runId>/tasks.json path (docs/specs/_built/task-list-json/spec.md,
13
+ // Decisions: Colocation) needs info.rootDir/info.runId — only a script
14
+ // gets those; a static agent prompt can't interpolate a per-dispatch runId.
15
+ // Validating once here with parseTaskList means every downstream node
16
+ // (Implement, Fix, Review) trusts the file on disk instead of re-checking
17
+ // Plan's own judgment call.
18
+ export default async function validatePlan(
19
+ handoff: NodeResult,
20
+ info: DispatchInfo,
21
+ ): Promise<NodeResult> {
22
+ const parsed = parseTaskList(handoff.output);
23
+ if ("error" in parsed) {
24
+ return { event: "invalid", output: { error: parsed.error } };
25
+ }
26
+ const dir = join(info.rootDir, ".darkf", "run", info.runId);
27
+ await mkdir(dir, { recursive: true });
28
+ await writeFile(join(dir, "tasks.json"), JSON.stringify(parsed, null, 2));
29
+ return { event: "valid", output: parsed };
30
+ }
@@ -1,41 +1,105 @@
1
1
  import { DONE, type WorkflowDef } from "@psimona/darkf/src/core/index.ts";
2
2
  import { opencodeRunner } from "@psimona/darkf/src/kit/agents/opencode.ts";
3
3
 
4
- // dev-loop — begin → implement → check → review → document → finish(squash) →
5
- // feedback.
4
+ // dev-loop — begin → PlanPhase{plan → validate} → (dispatch →
5
+ // Task{implement → test → [fix → test]* → review → mark done})* →
6
+ // document → finish(squash) → feedback.
6
7
  //
7
8
  // The darkf-on-darkf pilot, expanded after its first real run built the CLI
8
- // self-update feature (docs/specs/self-update/). Shape ported from
9
- // blueprint's build-backend: Begin cuts the feature branch, the composite
10
- // bounds the implement/fix/review cycle, Finish squash-merges onto master
11
- // with blueprint's rails, Feedback writes the run retrospective under
12
- // darkf/feedback/.
9
+ // self-update feature (docs/specs/_built/self-update/). Shape ported from
10
+ // blueprint's build-backend: Begin cuts the feature branch, Finish
11
+ // squash-merges onto master with blueprint's rails, Feedback writes the run
12
+ // retrospective under darkf/feedback/.
13
13
  //
14
- // Run from the target repo root with a globally installed darkf (never the
15
- // workspace symlink — doctor's selfRoot guard fails inside the checkout):
14
+ // Run from the target repo root with the released engine from the npm
15
+ // registry (never the workspace symlink — doctor's selfRoot guard fails
16
+ // inside the checkout; never a source-tarball install — repeated
17
+ // install:global runs corrupt bun's global manifest with duplicate
18
+ // dependency keys):
16
19
  //
17
- // bun run install:global # once, to refresh the global binary
18
- // darkf doctor darkf/workflows/dev-loop
20
+ // bun install -g @psimona/darkf@latest # released engine; the working
21
+ // # tree's workflow rides the branch
22
+ // darkf validate darkf/workflows/dev-loop
19
23
  // darkf start darkf/workflows/dev-loop "message" --allow-dirty-workflow
20
24
  //
21
25
  // Editing the FEATURE / RUN_DATE constants at the top of the begin/finish
22
- // scripts and this file's agent prompts is the per-feature contract until
23
- // engine-side input plumbing exists. Resume is the fresh-run semantics: a
24
- // second run on an already-implemented tree verifies and ships it (see the
25
- // Implement prompt). No other git automation: the human curates what the
26
- // workflow leaves behind (spec archive, roadmap entry, feedback note).
26
+ // scripts and this file is the per-feature contract until engine-side input
27
+ // plumbing exists — but the agent prompts below are feature-agnostic, so
28
+ // that's the only edit a new dispatch needs. Resume is the fresh-run
29
+ // semantics: a second run on an already-implemented tree verifies and ships
30
+ // it. No other git automation: the human curates what the workflow leaves
31
+ // behind (spec archive, roadmap entry, feedback note).
27
32
  //
28
- // The implementer, fixer, reviewer, and documenter are separate dispatches.
29
- // Their only
30
- // shared channels are the repo itself (files, git diff, the spec docs) and
31
- // the one-hop handoff — matching PHILOSOPHY.md: nothing rides along for
32
- // free.
33
+ // Two bounded-loop composites, not one shared "whole build" composite,
34
+ // because they bound two unrelated kinds of backward routing (Bounded
35
+ // loops rule, darkf-writing-workflows) and need very different maxCycles
36
+ // budgets:
37
+ //
38
+ // - PlanPhase: Plan (an agent — distilling free-form spec prose into a
39
+ // task list takes judgment, not parsing) emits a candidate TaskList in
40
+ // its output, reusing darkf-core's existing shared vocabulary
41
+ // (docs/specs/_built/task-list-json/spec.md) rather than a one-off
42
+ // shape. ValidatePlan (a script) runs parseTaskList on it and, once
43
+ // valid, persists it at the canonical .darkf/run/<runId>/tasks.json — a
44
+ // script gets info.rootDir/info.runId to compute that path; a static
45
+ // agent prompt cannot interpolate a per-dispatch runId, only a
46
+ // compile-time constant like FEATURE. An invalid candidate loops back to
47
+ // Plan; budget is a small, fixed number of retry rounds.
48
+ //
49
+ // - Dispatch/Task is darkf's item-loop-convention shape
50
+ // (docs/specs/item-loop-convention/spec.md — a design, not shipped code
51
+ // yet, so this hand-rolls the algorithm rather than importing it), with
52
+ // Dispatch kept OUTSIDE the Task composite on purpose. Dispatch (a
53
+ // script) is the node that actually walks the plan — it picks the
54
+ // first "pending" task out of tasks.json, flips it "in-progress", and
55
+ // hands it to Implement as the one thing to build this pass. Task is
56
+ // the per-task lane: Implement → Test → (Fix → Test)* → Review →
57
+ // MarkDone. Review (an agent, reads tasks.json itself to find the
58
+ // in-progress task — it never receives it via handoff, which is
59
+ // several hops away by the time Review runs) verifies the task's claim
60
+ // against the actual working tree and never edits anything; MarkDone
61
+ // (a script) does the one mechanical write that follows an approval,
62
+ // then routes back out to Dispatch for the next task — a flat edge
63
+ // across the composite boundary (buildRegistry is one flat map keyed
64
+ // by state id; routing doesn't care which composite either side lives
65
+ // in).
66
+ //
67
+ // That flat edge is what makes the sizing per-task instead of
68
+ // per-plan: every time Dispatch (outside Task) hands off into Task
69
+ // again, that is a fresh entry into the composite, because the engine
70
+ // resets a composite's cycle counter whenever the immediately
71
+ // preceding dispatch's scope did not already include it
72
+ // (CompositeStateDef.maxCycles's doc, src/core/types.ts). Task's
73
+ // maxCycles below therefore budgets one task's worst case only, never
74
+ // multiplied by how many tasks the plan turns out to have. Dispatch
75
+ // itself carries no maxCycles of its own — the engine-wide maxSteps is
76
+ // the only backstop on the item-to-item loop, matching
77
+ // item-loop-convention's own Non-goals ("automatic maxCycles wiring"
78
+ // is explicitly out of scope: a workflow author still sizes a lane's
79
+ // own budget by hand, but never has to also guess the plan's total
80
+ // size to do it). This replaces the pilot's original shape, where
81
+ // Dispatch lived inside the same composite as the lane and the budget
82
+ // had to cover the whole plan — sized for "≤8 tasks × ≤9 dispatches,"
83
+ // it crashed on cycle-limit the first time a real plan came out to 17
84
+ // tasks, even though no single task was anywhere near a runaway.
85
+ //
86
+ // Every node's only shared channels are the repo itself (files, git diff,
87
+ // the spec docs, the run's tasks.json) and the one-hop handoff — matching
88
+ // PHILOSOPHY.md: nothing rides along for free. A node several hops past
89
+ // whoever produced something it needs (Review past Dispatch; Document past
90
+ // everything) rediscovers it from disk — "the task with status
91
+ // in-progress," "the directory under .darkf/run/ with the latest mtime" —
92
+ // never by a value hand-threaded through every intervening node's output.
93
+ // See darkf-writing-workflows's "Keep prompts feature-agnostic". The same
94
+ // tasks.json also feeds the OpenCode plugin's live "tasks nn/mm" tab for
95
+ // free, since MarkDone flips a task's status the moment its claim is
96
+ // actually verified, not merely claimed.
33
97
 
34
98
  export const agentRunner = opencodeRunner;
35
99
 
36
100
  const MODEL = "zai-coding-plan/glm-5.3-flash";
37
- const RUN_DATE = "2026-10-31";
38
- const FEATURE = "task-list-json";
101
+ const RUN_DATE = "2026-11-19";
102
+ const FEATURE = "opencode-overlay-tiles";
39
103
 
40
104
  export const workflow: WorkflowDef = {
41
105
  initial: "Begin",
@@ -44,41 +108,75 @@ export const workflow: WorkflowDef = {
44
108
  type: "script",
45
109
  file: "begin.ts",
46
110
  retries: 1,
47
- on: { started: "Loop", branch_failed: DONE },
111
+ on: { started: "Plan", branch_failed: DONE },
48
112
  },
49
- Loop: {
113
+ PlanPhase: {
114
+ initial: "Plan",
115
+ // Two dispatches per round (Plan, ValidatePlan); budget three full
116
+ // retry rounds. Unrelated to Task's budget — see the top comment
117
+ // on why these are two composites, not one.
118
+ maxCycles: 6,
119
+ states: {
120
+ Plan: {
121
+ type: "agent",
122
+ agent: { model: MODEL },
123
+ retries: 1,
124
+ prompt: `You are planning the ${FEATURE} run. Do not write or modify any code.
125
+
126
+ Read docs/specs/${FEATURE}/. It holds the contract as either a single spec.md, or a split prd.md (requirements) + design.md (implementation) pair — read whichever is present.
127
+
128
+ Distill the contract into one TaskList JSON object (shape: id, optional spec: { prd?, design? }, requirements?: TaskRequirement[], tasks: Task[] — TaskRequirement is { id, kind: "req"|"nfr"|"ng", text, priority? }; Task is { id, title, status, satisfies?, priority? }; priority is one of "must"|"should"|"could"|"won't"; status starts "pending" for every task):
129
+
130
+ - requirements: one entry per concrete requirement, NFR, or non-goal in the contract, kind "req"/"nfr"/"ng" accordingly, text stated the way the contract states it — don't paraphrase, don't add anything beyond it.
131
+ - tasks: one entry per concrete file to create or change and concrete behavior to add that the contract calls for. Each task's satisfies lists the requirement ids it implements. id is a short kebab-case slug; title is one line.
132
+
133
+ Put this object directly in your output — do not write any file yourself; the next step persists and validates it.
134
+
135
+ Finish with event "planned". If the contract is missing, contradictory, or too vague to distill a concrete task list from, finish with event "blocked" and the reason.`,
136
+ on: { planned: "ValidatePlan", blocked: DONE },
137
+ },
138
+ ValidatePlan: {
139
+ type: "script",
140
+ file: "validate-plan.ts",
141
+ retries: 1,
142
+ on: { valid: "Dispatch", invalid: "Plan" },
143
+ },
144
+ },
145
+ },
146
+ Dispatch: {
147
+ type: "script",
148
+ file: "dispatch.ts",
149
+ retries: 1,
150
+ on: { next_item: "Implement", plan_exhausted: "Document", blocked: DONE },
151
+ },
152
+ Task: {
50
153
  initial: "Implement",
51
- // The normal path is one cycle (Implement → Check → Review → Document
52
- // → Finish). Each Fix → Check re-entry costs another. 8 leaves room
53
- // for two fix rounds including the terminal Document dispatch before
54
- // the engine calls the run stuck.
55
- maxCycles: 8,
154
+ // Sized for one task's worst case only (Implement + Test + 2
155
+ // Fix/Test rounds + Review + MarkDone = 8), with item-loop-
156
+ // convention's own estimateMaxCycles(n, slack=1.5) rounding: 8 *
157
+ // 1.5 = 12. Dispatch is deliberately outside this composite (see
158
+ // the top comment) so this budget resets fresh on every task,
159
+ // never multiplied by the plan's task count.
160
+ maxCycles: 12,
56
161
  states: {
57
162
  Implement: {
58
163
  type: "agent",
59
164
  agent: { model: MODEL },
60
165
  retries: 1,
61
- prompt: `Implement the ${FEATURE} feature in this repository.
62
-
63
- First read docs/specs/${FEATURE}/spec.md. It is the contract: its Design sketch and both Decisions sections are locked — implement exactly what they specify, nothing more.
166
+ prompt: `Implement exactly the one task you were handed for the ${FEATURE} feature — see "Input from the previous step" below for its id, title, and which requirements it satisfies. Nothing else.
64
167
 
65
- Resume semantics: if the working tree already implements the spec, verify that instead of re-implementing — read the existing darkf/src/core/tasks.ts and darkf-opencode-plugin/src/digest.ts, confirm they match the spec, and finish "implemented" without rewriting.
168
+ First read docs/specs/${FEATURE}/. It holds the contract as either a single spec.md, or a split prd.md (requirements) + design.md (implementation) pair — read whichever is present. Use it to understand what the handed-off task actually requires; its locked decisions and explicit non-goals bound the work.
66
169
 
67
- Deliverables (when not already present):
68
- - the TaskList type family in darkf/src/core/types.ts per the spec's Design sketch (TaskStatus, TaskPriority, Task, TaskRequirement, TaskList), re-exported from darkf/src/core/index.ts
69
- - parseTaskList in darkf/src/core/tasks.ts: hand-written, zero-dependency, narrowing unknown JSON to TaskList | { error } (Decisions: Validation)
70
- - foldTaskList alongside foldJournal in darkf/src/kit/status.ts: a pure function returning done/total counts, the current in-progress item, and stall state
71
- - the plugin (darkf-opencode-plugin/src/): TaskListView in digest.ts; store.ts reads .darkf/run/<runId>/tasks.json on the existing poll with an fs.watch next to the journal watcher; overlay.tsx grows a tab bar — tab "workflow" (today's PlanGraph, unchanged, the default) and tab "tasks nn/mm" (strict done/total in the title, hidden while tasks.json is absent, "?" counter plus the inline parse error when invalid); task rows per the plugin Decisions (glyph + id + title, "!" before the title for must priority, the active row's dim "↳ REQ-…" satisfies line, ○ pending / ● in-progress accent bold / ✓ done dim / ✗ failed error); keys "1"/"2" and clicking a tab title switch tabs; the supervisor pane stays below, shared by both tabs
72
- - tests: parseTaskList narrowing cases (valid list, missing/wrong-typed fields, bad status and priority unions, tasks not an array), foldTaskList counts/current/stall, and the TaskListView digest in darkf-opencode-plugin/src/digest.test.ts
170
+ Resume semantics: if the working tree already implements this task, verify it instead of re-implementing.
73
171
 
74
- Follow the existing code style of darkf/src/kit/status.ts and darkf-opencode-plugin/src/. Do not commit. Do not touch files outside darkf/src/, darkf-opencode-plugin/src/, and docs/specs/${FEATURE}/.
172
+ Do not commit. Do not touch tasks.json — Review verifies your claim and MarkDone updates it once that verification passes.
75
173
 
76
- Finish with event "implemented". If the spec cannot be implemented as written, finish with event "blocked" and put the reason in the output. If a review demand contradicts the spec, finish with event "disputed" and ground the objection in the spec text.`,
77
- on: { implemented: "Check", blocked: DONE, disputed: DONE },
174
+ Finish with event "implemented". If the task cannot be implemented as specified, finish with event "blocked" and put the reason in the output. If a review demand contradicts the spec, finish with event "disputed" and ground the objection in the spec text.`,
175
+ on: { implemented: "Test", blocked: DONE, disputed: DONE },
78
176
  },
79
- Check: {
177
+ Test: {
80
178
  type: "script",
81
- file: "check.ts",
179
+ file: "test.ts",
82
180
  retries: 1,
83
181
  on: { passed: "Review", failed: "Fix" },
84
182
  },
@@ -88,10 +186,10 @@ Finish with event "implemented". If the spec cannot be implemented as written, f
88
186
  retries: 1,
89
187
  prompt: `You are repairing the ${FEATURE} implementation after a failed gate.
90
188
 
91
- The handoff you received carries either the failing tail of "bun run check" or the reviewer's change list. Read docs/specs/${FEATURE}/spec.md for the contract. Fix the code minimally. Do not redesign. Do not commit. Do not touch files outside darkf/src/ and darkf-opencode-plugin/src/.
189
+ The handoff you received carries either the failing tail of "bun run check" or the reviewer's change list. Read docs/specs/${FEATURE}/'s contract (spec.md if present, otherwise prd.md + design.md). Fix the code minimally. Do not redesign. Do not commit.
92
190
 
93
191
  Finish with event "fixed". If the failure exposes a spec defect you cannot resolve in code, finish with event "blocked" and the reason. If the demand contradicts the spec, finish with event "disputed" and ground the objection in the spec text.`,
94
- on: { fixed: "Check", blocked: DONE, disputed: DONE },
192
+ on: { fixed: "Test", blocked: DONE, disputed: DONE },
95
193
  },
96
194
  Review: {
97
195
  type: "agent",
@@ -99,36 +197,45 @@ Finish with event "fixed". If the failure exposes a spec defect you cannot resol
99
197
  retries: 1,
100
198
  prompt: `You are an independent reviewer. Do not modify any files.
101
199
 
102
- Verify the working tree against docs/specs/${FEATURE}/spec.md:
200
+ Find the run directory under .darkf/run/ with the latest mtime and read its tasks.json. Find the one task whose status is "in-progress" — that is the task just implemented and tested. A task reaching you is a claim to verify, not a fact to trust:
201
+
103
202
  - inspect git status --porcelain in addition to git diff — agent-authored new files are invisible to git diff alone
104
- - check the types match the spec's Design sketch field for field, and that both Decisions sections are each reflected in code (parseTaskList zero-dep narrowing; tasks.json read from .darkf/run/<runId>/; satisfies + lowercase MoSCoW; row format, glyph mapping, strict done/total counter, hidden-when-absent tab, file-status active row)
105
- - check the test suites cover the spec: parseTaskList narrowing, foldTaskList, and the TaskListView digest
106
- - you may run "bun test darkf/src/core darkf/src/kit darkf-opencode-plugin/src" yourself
203
+ - read docs/specs/${FEATURE}/'s contract (spec.md if present, otherwise prd.md + design.md) for what each id in the task's "satisfies" list actually requires, and confirm the working tree genuinely satisfies every one of them
204
+ - you may run the project's own test/lint commands yourself
107
205
 
108
- Approve only if the implementation fulfills the spec. Otherwise list every required change concretely in the output.
206
+ Approve only if the task's claim holds in full. Otherwise list every required change concretely in the output.
109
207
 
110
208
  Finish with event "approved" or event "changes_requested".`,
111
- on: { approved: "Document", changes_requested: "Fix" },
209
+ on: { approved: "MarkDone", changes_requested: "Fix" },
112
210
  },
113
- Document: {
114
- type: "agent",
115
- agent: { model: MODEL },
211
+ MarkDone: {
212
+ type: "script",
213
+ file: "mark-done.ts",
116
214
  retries: 1,
117
- prompt: `You are updating user-facing documentation for the ${FEATURE} feature, after an independent review approved the implementation. Do not modify code or tests.
215
+ on: { marked: "Dispatch" },
216
+ },
217
+ },
218
+ },
219
+ Document: {
220
+ type: "agent",
221
+ agent: { model: MODEL },
222
+ retries: 1,
223
+ prompt: `You are updating user-facing documentation for the ${FEATURE} feature, after every task in its plan was implemented and independently reviewed. Do not modify code or tests.
118
224
 
119
225
  Read docs/specs/${FEATURE}/spec.md (or prd.md/design.md when present) for what the feature does, and run git diff master plus git status --porcelain to see what shipped.
120
226
 
121
- Update only what the feature's user-facing surface touches:
227
+ Docs must match the spec when this run lands — drift accumulates one stale page at a time. Update everything the feature's surface touches:
122
228
  - README.md — CLI flags/commands, plugin behavior, setup steps that changed
123
- - docs-site pages under site/src/content/docs/ — the affected guide or reference page; add a short new guide only for a genuinely user-visible capability
124
- - cross-references in docs/ that now point at moved or renamed paths
229
+ - packaged docs under darkf/docs/ — the site renders from these files, so they are the docs:
230
+ - reference/cli-commands.md for any CLI surface change (new command, flag, exit code, default)
231
+ - the guides and concepts pages the feature's surface touches — re-read them and fix stale paths, stale command names, and claims the feature made wrong
232
+ - start-here/install.md when setup, packaging, or install steps changed
233
+ - cross-references anywhere in darkf/docs/ or README.md that now point at moved or renamed paths
125
234
 
126
235
  Do NOT touch: ROADMAP.md, darkf/feedback/, docs/specs/ (the spec archive move and roadmap entry are post-merge human curation), any file under darkf/src/ or darkf-opencode-plugin/.
127
236
 
128
- If nothing user-facing changed, or the docs need no edit, finish with event "skipped" and put the one-line reason in the output. Otherwise make the edits and finish with event "documented". If the docs cannot be updated (for example the site is broken), finish with event "blocked" and the reason.`,
129
- on: { documented: "Finish", skipped: "Finish", blocked: DONE },
130
- },
131
- },
237
+ If nothing user-facing changed and no doc drifted, finish with event "skipped" and put the one-line reason in the output. Otherwise make the edits and finish with event "documented". If the docs cannot be updated (for example the site is broken), finish with event "blocked" and the reason.`,
238
+ on: { documented: "Finish", skipped: "Finish", blocked: DONE },
132
239
  },
133
240
  Finish: {
134
241
  type: "script",
package/bunfig.toml DELETED
@@ -1,13 +0,0 @@
1
- # One merged suite, one threshold. `darkf-core`, `darkf-engine`, and the
2
- # old `darkf-cli` coverage configs (0.85/0.80 engine, 0.30/0.30 cli) died
3
- # with the package merge — the package-boundaries spec moved all sources
4
- # under one roof, so coverage is measured once, across the whole tree.
5
- #
6
- # kit/agents is excluded because the runners' real code paths execute
7
- # inside spawned worker subprocesses (see src/cli/detached.test.ts), which
8
- # the in-process profiler cannot see; their harness-side logic is still
9
- # covered in-process (handoff, registry, status).
10
- [test]
11
- coverage = true
12
- coveragePathIgnorePatterns = ["src/kit/agents/**"]
13
- coverageThreshold = { lines = 0.30, functions = 0.30 }
@@ -1,38 +0,0 @@
1
- export interface Article {
2
- id: string;
3
- title: string;
4
- text: string;
5
- }
6
-
7
- export const articles: Article[] = [
8
- {
9
- id: "a1",
10
- title: "New chip promises 10x inference speedup",
11
- text: "A startup unveiled a chip design claiming an order-of-magnitude improvement in inference throughput for large language models, at a fraction of the power draw of current GPUs.",
12
- },
13
- {
14
- id: "a2",
15
- title: "Exoplanet found in habitable zone of nearby star",
16
- text: "Astronomers using a new survey telescope identified a rocky exoplanet orbiting within the habitable zone of a star 40 light-years away, a strong candidate for atmospheric follow-up.",
17
- },
18
- {
19
- id: "a3",
20
- title: "Retailer reports record quarterly earnings",
21
- text: "A national retail chain posted its strongest quarterly earnings in a decade, citing holiday demand and improved supply chain efficiency across its distribution network.",
22
- },
23
- {
24
- id: "a4",
25
- title: "Local bakery wins regional sourdough award",
26
- text: "A family-run bakery took first place in the region's annual bread competition, praised by judges for a distinctive tang developed over a decade-old starter culture.",
27
- },
28
- {
29
- id: "a5",
30
- title: "Open-source database project reaches 1.0",
31
- text: "After four years of development, a community-maintained embedded database project shipped its first stable 1.0 release, adding transactional guarantees and a new query planner.",
32
- },
33
- {
34
- id: "a6",
35
- title: "Study links sleep patterns to memory consolidation",
36
- text: "Researchers tracking sleep stages in a longitudinal study found a strong correlation between deep sleep duration and next-day recall performance in memory tasks.",
37
- },
38
- ];
@@ -1,7 +0,0 @@
1
- import type { NodeResult } from "@psimona/darkf/src/core/index.ts";
2
- import { allResults, currentArticle, isDone } from "./queue.ts";
3
-
4
- export default function next(_handoff: NodeResult): NodeResult {
5
- if (isDone()) return { event: "done", output: { results: allResults() } };
6
- return { event: "have_item", output: { article: currentArticle() } };
7
- }
@@ -1,33 +0,0 @@
1
- import { type Article, articles } from "../data/articles.ts";
2
-
3
- export interface ClassifiedArticle extends Article {
4
- category: string;
5
- }
6
-
7
- // This is run-scoped bookkeeping shared by next.ts and record.ts via plain
8
- // module scope — not the handoff, and not a file. It doesn't need to be a
9
- // file: it's private coordination between two script nodes, invisible to the
10
- // engine, and doesn't need to survive past this one process. See
11
- // PHILOSOPHY.md's "no global, accumulating context" — this is the sanctioned
12
- // escape hatch (a node's own code choosing to carry state), scoped as
13
- // narrowly as possible instead of riding through the handoff or the agent.
14
- let index = 0;
15
- const results: ClassifiedArticle[] = [];
16
-
17
- export function isDone(): boolean {
18
- return index >= articles.length;
19
- }
20
-
21
- export function currentArticle(): Article {
22
- return articles[index]!;
23
- }
24
-
25
- export function recordCategory(category: string): ClassifiedArticle[] {
26
- results.push({ ...currentArticle(), category });
27
- index++;
28
- return results;
29
- }
30
-
31
- export function allResults(): ClassifiedArticle[] {
32
- return results;
33
- }
@@ -1,9 +0,0 @@
1
- import type { NodeResult } from "@psimona/darkf/src/core/index.ts";
2
- import { recordCategory } from "./queue.ts";
3
-
4
- export default function record(handoff: NodeResult): NodeResult {
5
- // Classify's event IS the category — this script's only job is the
6
- // "useful thing to do" with it (here: file it away for the final report).
7
- const results = recordCategory(handoff.event ?? "other");
8
- return { output: { results } };
9
- }