@psimona/darkf 0.0.0-stage → 0.3.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.
- package/README.md +28 -2
- package/bunfig.toml +13 -0
- package/examples/article-classifier/data/articles.ts +38 -0
- package/examples/article-classifier/scripts/next.ts +7 -0
- package/examples/article-classifier/scripts/queue.ts +33 -0
- package/examples/article-classifier/scripts/record.ts +9 -0
- package/examples/article-classifier/workflow.ts +44 -0
- package/examples/haiku-commit/scripts/check.ts +24 -0
- package/examples/haiku-commit/workflow.ts +28 -0
- package/examples/haiku-readme/scripts/test.ts +13 -0
- package/examples/haiku-readme/scripts/write.ts +10 -0
- package/examples/haiku-readme/workflow.ts +41 -0
- package/examples/task-queue/scripts/next.ts +20 -0
- package/examples/task-queue/scripts/record.ts +20 -0
- package/examples/task-queue/supervise.ts +57 -0
- package/examples/task-queue/workflow.ts +33 -0
- package/package.json +30 -4
- package/src/cli/detached.test.ts +557 -0
- package/src/cli/index.ts +1012 -0
- package/src/core/graph.test.ts +172 -0
- package/src/core/graph.ts +148 -0
- package/src/core/index.ts +4 -0
- package/src/core/journal.ts +21 -0
- package/src/core/mermaid.test.ts +34 -0
- package/src/core/mermaid.ts +95 -0
- package/src/core/types.ts +279 -0
- package/src/engine/eventLog.ts +17 -0
- package/src/engine/index.ts +2 -0
- package/src/engine/run.test.ts +1068 -0
- package/src/engine/run.ts +359 -0
- package/src/exports.ts +2 -0
- package/src/kit/agents/claude-code.test.ts +37 -0
- package/src/kit/agents/claude-code.ts +180 -0
- package/src/kit/agents/handoff.test.ts +128 -0
- package/src/kit/agents/handoff.ts +69 -0
- package/src/kit/agents/opencode.test.ts +136 -0
- package/src/kit/agents/opencode.ts +327 -0
- package/src/kit/registry.test.ts +386 -0
- package/src/kit/registry.ts +296 -0
- package/src/kit/status.test.ts +423 -0
- package/src/kit/status.ts +282 -0
- package/tsconfig.json +4 -0
- package/workflows/series-ordering/scripts/verify.ts +18 -0
- package/workflows/series-ordering/workflow.ts +79 -0
package/README.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# darkf
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A small, typed workflow engine for agent + script state graphs.
|
|
4
|
+
|
|
5
|
+
darkf runs a workflow — a plain TypeScript object describing states and
|
|
6
|
+
transitions — as a sequence of **agent** nodes (an LLM call) and **script**
|
|
7
|
+
nodes (a plain function), dispatched through one shared contract. It
|
|
8
|
+
journals every step to disk, so "did it finish, and how" is always
|
|
9
|
+
answerable from a file, not a live process.
|
|
10
|
+
|
|
11
|
+
This package carries the whole engine as source: `src/core` (shared
|
|
12
|
+
vocabulary), `src/engine` (the dispatch loop), `src/kit` (agent runners,
|
|
13
|
+
handoff contract, registry), and `src/cli` (the `darkf` binary). It has
|
|
14
|
+
zero runtime dependencies and runs on Bun.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
bun install -g @psimona/darkf
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Docs
|
|
23
|
+
|
|
24
|
+
<https://psimona.github.io/darkf> — quickstart, concepts, guides, and the
|
|
25
|
+
CLI reference.
|
|
26
|
+
|
|
27
|
+
## License
|
|
28
|
+
|
|
29
|
+
MIT
|
package/bunfig.toml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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 }
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
];
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
// Real LLM calls, one per article in data/articles.ts (6 by default) — this
|
|
5
|
+
// example is the one demo actually wired to claudeCodeRunner. See
|
|
6
|
+
// docs/specs/_built/agent-handoff/spec.md.
|
|
7
|
+
export const agentRunner = claudeCodeRunner;
|
|
8
|
+
|
|
9
|
+
export const workflow: WorkflowDef = {
|
|
10
|
+
initial: "Loop",
|
|
11
|
+
states: {
|
|
12
|
+
Loop: {
|
|
13
|
+
initial: "Next",
|
|
14
|
+
// Safety net for the whole Next/Classify/Record cycle, not a tuning
|
|
15
|
+
// knob: 6 articles x 3 leaf dispatches each + the final "done" check
|
|
16
|
+
// is 19 in the normal case, so 30 never trips unless something is
|
|
17
|
+
// actually stuck flapping.
|
|
18
|
+
maxCycles: 30,
|
|
19
|
+
states: {
|
|
20
|
+
Next: {
|
|
21
|
+
type: "script",
|
|
22
|
+
file: "next.ts",
|
|
23
|
+
on: { have_item: "Classify", done: DONE },
|
|
24
|
+
},
|
|
25
|
+
Classify: {
|
|
26
|
+
type: "agent",
|
|
27
|
+
prompt: "Classify the topic of the given article.",
|
|
28
|
+
retries: 1,
|
|
29
|
+
on: {
|
|
30
|
+
tech: "Record",
|
|
31
|
+
science: "Record",
|
|
32
|
+
business: "Record",
|
|
33
|
+
other: "Record",
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
Record: {
|
|
37
|
+
type: "script",
|
|
38
|
+
file: "record.ts",
|
|
39
|
+
next: "Next",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import type { DispatchInfo, NodeResult } from "@psimona/darkf/src/core/index.ts";
|
|
4
|
+
|
|
5
|
+
const START_MARKER = "<!-- haiku:start -->";
|
|
6
|
+
const END_MARKER = "<!-- haiku:end -->";
|
|
7
|
+
|
|
8
|
+
export default async function check(_handoff: NodeResult, info: DispatchInfo): Promise<NodeResult> {
|
|
9
|
+
const readmePath = join(info.rootDir, "README.md");
|
|
10
|
+
const text = existsSync(readmePath) ? readFileSync(readmePath, "utf8") : "";
|
|
11
|
+
if (!text.includes(START_MARKER) || !text.includes(END_MARKER)) {
|
|
12
|
+
return { event: "missing" };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const add = Bun.spawn(["git", "add", "README.md"], { cwd: info.rootDir });
|
|
16
|
+
if ((await add.exited) !== 0) throw new Error("git add README.md failed");
|
|
17
|
+
|
|
18
|
+
const commit = Bun.spawn(["git", "commit", "-m", "Add haiku to README"], {
|
|
19
|
+
cwd: info.rootDir,
|
|
20
|
+
});
|
|
21
|
+
if ((await commit.exited) !== 0) throw new Error("git commit failed");
|
|
22
|
+
|
|
23
|
+
return { event: "committed" };
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
// A real LLM call, not a stub — the docs site's Quickstart example. One
|
|
5
|
+
// cheap agent dispatch per attempt, so the cost is trivial; see
|
|
6
|
+
// docs/specs/docs-site/spec.md.
|
|
7
|
+
export const agentRunner = claudeCodeRunner;
|
|
8
|
+
|
|
9
|
+
export const workflow: WorkflowDef = {
|
|
10
|
+
initial: "Write",
|
|
11
|
+
states: {
|
|
12
|
+
Write: {
|
|
13
|
+
type: "agent",
|
|
14
|
+
prompt:
|
|
15
|
+
"Add a haiku about darkf to README.md, wrapped in HTML comments " +
|
|
16
|
+
"<!-- haiku:start --> and <!-- haiku:end --> on their own lines, " +
|
|
17
|
+
"so an automated check can find it.",
|
|
18
|
+
// Unconditional: Check decides what actually happened by reading the
|
|
19
|
+
// file, not by trusting whatever event the agent reports.
|
|
20
|
+
next: "Check",
|
|
21
|
+
},
|
|
22
|
+
Check: {
|
|
23
|
+
type: "script",
|
|
24
|
+
file: "check.ts",
|
|
25
|
+
on: { committed: DONE, missing: "Write" },
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NodeResult } from "@psimona/darkf/src/core/index.ts";
|
|
2
|
+
|
|
3
|
+
interface TestHandoff {
|
|
4
|
+
writeAttempts?: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export default function test(handoff: NodeResult): NodeResult {
|
|
8
|
+
const writeAttempts = (handoff.output as TestHandoff | undefined)?.writeAttempts ?? 0;
|
|
9
|
+
// Must re-emit writeAttempts: if Test fails and routes back to Write, Write
|
|
10
|
+
// only ever sees THIS result as its next handoff — nothing carries forward
|
|
11
|
+
// unless this node's own code chooses to relay it.
|
|
12
|
+
return { event: writeAttempts >= 2 ? "passed" : "failed", output: { writeAttempts } };
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@psimona/darkf",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "A small, typed workflow engine for agent + script state graphs.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Patrizio Simona <patriziosimona@gmail.com>",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "src/exports.ts",
|
|
9
|
+
"types": "src/exports.ts",
|
|
10
|
+
"bin": {
|
|
11
|
+
"darkf": "src/cli/index.ts"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/psimona/darkf.git"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://psimona.github.io/darkf",
|
|
21
|
+
"keywords": [
|
|
22
|
+
"workflow",
|
|
23
|
+
"agent",
|
|
24
|
+
"state-graph",
|
|
25
|
+
"claude-code",
|
|
26
|
+
"opencode",
|
|
27
|
+
"bun"
|
|
28
|
+
],
|
|
29
|
+
"engines": {
|
|
30
|
+
"bun": ">=1.2"
|
|
31
|
+
}
|
|
32
|
+
}
|