@psimona/darkf 0.4.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 (56) 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/index.ts +1 -0
  28. package/src/core/tasks.test.ts +146 -0
  29. package/src/core/tasks.ts +158 -0
  30. package/src/core/types.ts +42 -0
  31. package/src/engine/run.test.ts +177 -0
  32. package/src/engine/run.ts +66 -2
  33. package/src/kit/agents/opencode.test.ts +232 -2
  34. package/src/kit/agents/opencode.ts +69 -6
  35. package/src/kit/status.test.ts +118 -1
  36. package/src/kit/status.ts +67 -1
  37. package/workflows/dev-loop/scripts/begin.ts +1 -1
  38. package/workflows/dev-loop/scripts/finish.ts +13 -2
  39. package/workflows/dev-loop/workflow.ts +57 -23
  40. package/bunfig.toml +0 -13
  41. package/examples/article-classifier/data/articles.ts +0 -38
  42. package/examples/article-classifier/scripts/next.ts +0 -7
  43. package/examples/article-classifier/scripts/queue.ts +0 -33
  44. package/examples/article-classifier/scripts/record.ts +0 -9
  45. package/examples/article-classifier/workflow.ts +0 -44
  46. package/examples/haiku-commit/scripts/check.ts +0 -24
  47. package/examples/haiku-commit/workflow.ts +0 -28
  48. package/examples/haiku-readme/scripts/test.ts +0 -13
  49. package/examples/haiku-readme/scripts/write.ts +0 -10
  50. package/examples/haiku-readme/workflow.ts +0 -41
  51. package/examples/task-queue/scripts/next.ts +0 -20
  52. package/examples/task-queue/scripts/record.ts +0 -20
  53. package/examples/task-queue/supervise.ts +0 -57
  54. package/examples/task-queue/workflow.ts +0 -33
  55. package/feedback/2026-10-30-self-update.md +0 -29
  56. package/tsconfig.json +0 -4
@@ -1,10 +0,0 @@
1
- import type { NodeResult } from "@psimona/darkf/src/core/index.ts";
2
-
3
- interface WriteHandoff {
4
- writeAttempts?: number;
5
- }
6
-
7
- export default function write(handoff: NodeResult): NodeResult {
8
- const writeAttempts = ((handoff.output as WriteHandoff | undefined)?.writeAttempts ?? 0) + 1;
9
- return { output: { writeAttempts } };
10
- }
@@ -1,41 +0,0 @@
1
- import { type AgentRunner, DONE, type WorkflowDef } from "@psimona/darkf/src/core/index.ts";
2
-
3
- let reviewCalls = 0;
4
-
5
- export const agentRunner: AgentRunner = {
6
- async run(id) {
7
- if (id === "Plan") return { event: "approved" };
8
- // Review
9
- reviewCalls++;
10
- return { event: reviewCalls === 1 ? "changes_requested" : "done" };
11
- },
12
- };
13
-
14
- export const workflow: WorkflowDef = {
15
- initial: "Plan",
16
- states: {
17
- Plan: {
18
- type: "agent",
19
- // The goal is a durable fact about this workflow, not per-run data —
20
- // it belongs in the prompt an author wrote, not in a data channel.
21
- prompt: "Plan the change needed to add a haiku to the README.",
22
- on: { approved: "Implement" },
23
- },
24
- Implement: {
25
- initial: "Write",
26
- states: {
27
- Write: { type: "script", file: "write.ts", next: "Test" },
28
- Test: {
29
- type: "script",
30
- file: "test.ts",
31
- on: { passed: "Review", failed: "Write" },
32
- },
33
- },
34
- },
35
- Review: {
36
- type: "agent",
37
- prompt: "Review the implementation against the goal.",
38
- on: { done: DONE, changes_requested: "Write" },
39
- },
40
- },
41
- };
@@ -1,20 +0,0 @@
1
- import { readFileSync, writeFileSync } from "node:fs";
2
- import { join } from "node:path";
3
- import type { DispatchInfo, NodeResult } from "@psimona/darkf/src/core/index.ts";
4
-
5
- interface Task {
6
- id: string;
7
- title: string;
8
- status: "pending" | "in-progress" | "done";
9
- }
10
-
11
- export default function next(_handoff: NodeResult, info: DispatchInfo): NodeResult {
12
- const path = join(info.rootDir, "tasks.json");
13
- const tasks: Task[] = JSON.parse(readFileSync(path, "utf8"));
14
- const task = tasks.find((t) => t.status === "pending");
15
- if (!task) return { event: "empty" };
16
-
17
- task.status = "in-progress";
18
- writeFileSync(path, JSON.stringify(tasks, null, 2));
19
- return { event: "found", output: { title: task.title } };
20
- }
@@ -1,20 +0,0 @@
1
- import { readFileSync, writeFileSync } from "node:fs";
2
- import { join } from "node:path";
3
- import type { DispatchInfo, NodeResult } from "@psimona/darkf/src/core/index.ts";
4
-
5
- interface Task {
6
- id: string;
7
- title: string;
8
- status: "pending" | "in-progress" | "done";
9
- }
10
-
11
- export default function record(_handoff: NodeResult, info: DispatchInfo): NodeResult {
12
- const path = join(info.rootDir, "tasks.json");
13
- const tasks: Task[] = JSON.parse(readFileSync(path, "utf8"));
14
- const task = tasks.find((t) => t.status === "in-progress");
15
- if (!task) throw new Error("no in-progress task to record");
16
-
17
- task.status = "done";
18
- writeFileSync(path, JSON.stringify(tasks, null, 2));
19
- return { event: "recorded" };
20
- }
@@ -1,57 +0,0 @@
1
- #!/usr/bin/env bun
2
- // A minimal supervisor: start the workflow, then react to things `darkf
3
- // monitor` only warns about (a stalled or orphaned worker) instead of
4
- // leaving a human to notice. Run from the same directory as tasks.json —
5
- // the workflow's rootDir — exactly like `darkf start` itself:
6
- //
7
- // bunx bun examples/task-queue/supervise.ts
8
- //
9
- // This is the "supervisor" the rest of darkf's CLI output already assumes
10
- // exists (status/monitor call stalls "warn-only — the supervisor decides").
11
- // It doesn't have to be a script like this one — an agent harness invoking
12
- // `darkf start` directly is a supervisor too, and darkf detects that case
13
- // (see SUPERVISOR_ENV_SIGNALS in darkf-cli/src/registry.ts) so a UI like the
14
- // OpenCode plugin can show which session is driving a run.
15
- const WORKFLOW = new URL(".", import.meta.url).pathname;
16
- const POLL_MS = 5_000;
17
-
18
- async function darkf(...args: string[]): Promise<number> {
19
- const proc = Bun.spawn(["bunx", "darkf", ...args], { stdout: "inherit", stderr: "inherit" });
20
- return await proc.exited;
21
- }
22
-
23
- async function start(): Promise<string> {
24
- const proc = Bun.spawn(["bunx", "darkf", "start", WORKFLOW], {
25
- stdout: "pipe",
26
- stderr: "inherit",
27
- });
28
- const stdout = await new Response(proc.stdout).text();
29
- await proc.exited;
30
- return (JSON.parse(stdout) as { runId: string }).runId;
31
- }
32
-
33
- let runId = await start();
34
- console.log(`started run ${runId}`);
35
-
36
- for (;;) {
37
- const code = await darkf("monitor", "--run", runId, "--once");
38
- if (code === 0) {
39
- console.log("succeeded");
40
- await darkf("report", "--run", runId);
41
- break;
42
- }
43
- if (code === 1) {
44
- console.log("crashed — see report before deciding whether to resume");
45
- await darkf("report", "--run", runId);
46
- break;
47
- }
48
- if (code === 2) {
49
- console.log("orphaned — worker died without a terminal journal entry; restarting");
50
- runId = await start();
51
- continue;
52
- }
53
- // 6: the run is still going. darkf status --run would also show a
54
- // stall-suspected warning here once a dispatch sits past its heartbeat
55
- // window — that's this script's cue to act, not darkf's.
56
- await Bun.sleep(POLL_MS);
57
- }
@@ -1,33 +0,0 @@
1
- import { DONE, type WorkflowDef } from "@psimona/darkf/src/core/index.ts";
2
- import { claudeCodeRunner } from "@psimona/darkf/src/kit/agents/claude-code.ts";
3
-
4
- // The durable-queue version of the Next/Work/Record loop: article-classifier
5
- // (../article-classifier) tracks its queue in in-memory module state, fine
6
- // for a single blocking `darkf run`. This one tracks it in tasks.json on
7
- // disk instead, so the same run survives being detached (`darkf start`) and
8
- // re-entered by a different process checking status.
9
- export const agentRunner = claudeCodeRunner;
10
-
11
- export const workflow: WorkflowDef = {
12
- initial: "Next",
13
- states: {
14
- Next: {
15
- type: "script",
16
- file: "next.ts",
17
- on: { found: "Work", empty: DONE },
18
- },
19
- Work: {
20
- type: "agent",
21
- prompt:
22
- 'Do the task named in the handoff\'s "title" field: append one ' +
23
- "sentence to notes.md describing what you did, creating the file " +
24
- "if it doesn't exist yet. Don't overwrite what's already there.",
25
- next: "Record",
26
- },
27
- Record: {
28
- type: "script",
29
- file: "record.ts",
30
- next: "Next",
31
- },
32
- },
33
- };
@@ -1,29 +0,0 @@
1
- # Run feedback — self-update dev-loop run
2
-
3
- - **Date:** 2026-10-30
4
- - **Engine/workflow:** darkf dev-loop
5
- - **Run:** c078c63d-399e-41b1-b0d3-90edccdec766
6
- - **Final outcome:** Merged. `feature/self-update` squashed to master as `feat: self-update (self-update)` (2651989); branch deleted. Every state succeeded on attempt 1.
7
- - **Scopes:** Shipped `darkf/src/cli/update.ts` and its test suite (24h gate, `DARKF_NO_UPDATE_CHECK` opt-out, one-line notice before dispatch, `upgrade` command), wired into `index.ts`, plus specs under `docs/specs/self-update/`.
8
-
9
- ## What worked
10
-
11
- - The full loop ran clean: Begin → Implement → Check → Review → Finish, one attempt per state, no retries.
12
- - Implement detected the working tree already matched `docs/specs/self-update/design.md` and verified instead of rewriting.
13
- - All gates passed on the first pass: 25/25 in `update.test.ts`, 162/162 across the full suite, secret-scan, typecheck, lint, arch-check clean.
14
- - Coverage held at 95.61% funcs / 95.72% lines; `update.ts` at 100% funcs.
15
- - Zero new dependencies; only `fetch`, `Bun.semver`, `node:fs`, `Bun.spawnSync`; `bun.lock` untouched.
16
- - Review independently re-ran the tests and mapped REQ-1 through REQ-5 to code-level line references before approving.
17
- - The real-CLI smoke tests keep the suite network-free by setting `DARKF_NO_UPDATE_CHECK=1`.
18
-
19
- ## Failures and root causes
20
-
21
- none observed
22
-
23
- ## Notes
24
-
25
- - The dev-loop workflow itself (`darkf/workflows/dev-loop/`) is untracked. It sits outside the self-update design scope, so the merge did not include it. Commit it separately so future runs are reproducible.
26
- - This run's Implement step shortcut worked because the working tree already held the implementation. A run from a clean checkout will pay the full implementation cost; plan attempts accordingly.
27
- - Total wall clock was about 3 minutes; heartbeats show roughly 30-60s of agent idle time per agent state (Implement, Review). Harmless, but it is most of the run time.
28
- - `update.ts` lines 131 and 177-178 stay uncovered: a defensive semver re-check already guaranteed by `checkRegistry`. The reviewer accepted this; do not chase it.
29
- - The implementer shipped two real-CLI smoke tests where the design says "one optional smoke test may". Permissive wording, no action needed.
package/tsconfig.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "extends": "../tsconfig.base.json",
3
- "include": ["src", "examples", "workflows"]
4
- }