@psimona/darkf 0.6.0 → 0.8.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/docs/concepts/failure-modes.md +23 -7
- package/docs/concepts/handoff.md +3 -3
- package/docs/concepts/node-types.md +44 -20
- package/docs/guides/pick-an-agent-runner.md +122 -4
- package/docs/guides/plan-with-a-task-queue.md +9 -7
- package/docs/guides/run-detached-and-monitor.md +3 -3
- package/docs/guides/write-your-first-workflow.md +14 -5
- package/docs/index.mdx +4 -0
- package/docs/reference/cli-commands.md +22 -6
- package/docs/reference/core-types.md +29 -4
- package/docs/reference/package-map.md +12 -8
- package/docs/start-here/quickstart.md +15 -7
- package/package.json +9 -2
- package/skills/darkf-writing-workflows/SKILL.md +141 -7
- package/src/cli/detached.test.ts +88 -2
- package/src/cli/doctor.test.ts +225 -10
- package/src/cli/index.ts +106 -27
- package/src/cli/setup.ts +4 -9
- package/src/cli/state-file.ts +14 -0
- package/src/cli/tarball.test.ts +3 -1
- package/src/cli/update.ts +4 -9
- package/src/core/graph.test.ts +124 -19
- package/src/core/graph.ts +51 -3
- package/src/core/tasks.ts +1 -1
- package/src/core/types.test.ts +52 -0
- package/src/core/types.ts +48 -18
- package/src/engine/run.test.ts +708 -18
- package/src/engine/run.ts +101 -16
- package/src/exports.ts +4 -0
- package/src/kit/agents/claude-code.test.ts +38 -2
- package/src/kit/agents/claude-code.ts +28 -37
- package/src/kit/agents/handoff.test.ts +12 -0
- package/src/kit/agents/handoff.ts +32 -8
- package/src/kit/agents/opencode.test.ts +1 -1
- package/src/kit/agents/opencode.ts +44 -28
- package/src/kit/specs.test.ts +247 -0
- package/src/kit/specs.ts +344 -0
- package/src/kit/status.test.ts +24 -0
- package/src/kit/status.ts +31 -14
- package/src/kit/validation/zod.test.ts +42 -0
- package/src/kit/validation/zod.ts +20 -0
- package/workflows/dev-loop/scripts/begin.ts +9 -6
- package/workflows/dev-loop/scripts/dispatch.ts +50 -0
- package/workflows/dev-loop/scripts/finish.ts +23 -21
- package/workflows/dev-loop/scripts/mark-done.ts +22 -0
- package/workflows/dev-loop/scripts/validate-plan.ts +30 -0
- package/workflows/dev-loop/workflow.ts +164 -68
- package/workflows/series-ordering/workflow.ts +1 -0
- /package/workflows/dev-loop/scripts/{check.ts → test.ts} +0 -0
package/src/kit/status.ts
CHANGED
|
@@ -22,18 +22,18 @@ export interface JournalDigest {
|
|
|
22
22
|
* don't report one. */
|
|
23
23
|
agentSessionId?: string;
|
|
24
24
|
/** Present while the engine is nudging this attempt (1..3) — see
|
|
25
|
-
* `nudgeWarning` and docs/specs/session-nudge/spec.md. */
|
|
25
|
+
* `nudgeWarning` and docs/specs/_built/session-nudge/spec.md. */
|
|
26
26
|
nudgeAttempt?: number;
|
|
27
27
|
/** The nudgeable `CrashReason` kind that triggered the current nudge. */
|
|
28
28
|
nudgeReason?: CrashReason["kind"];
|
|
29
29
|
/** Latest agent-reported step count, when the runner reports progress —
|
|
30
|
-
* see `agentStallWarning` and docs/specs/agent-liveness/spec.md. */
|
|
30
|
+
* see `agentStallWarning` and docs/specs/_built/agent-liveness/spec.md. */
|
|
31
31
|
agentStepCount?: number;
|
|
32
32
|
/** Milliseconds idle as of the last heartbeat — see `agentStallWarning`. */
|
|
33
33
|
agentIdleMs?: number;
|
|
34
34
|
/** Present while the engine is waiting out a provider usage-limit
|
|
35
35
|
* backoff for the current attempt — see `limitWarning` and
|
|
36
|
-
* docs/specs/usage-limit-backoff/spec.md. */
|
|
36
|
+
* docs/specs/_built/usage-limit-backoff/spec.md. */
|
|
37
37
|
limitBackoff?: { probe: number; nextAttemptAt: number; waitedMs: number };
|
|
38
38
|
} | null;
|
|
39
39
|
crash?: { attempt: number; reason: CrashReason };
|
|
@@ -120,7 +120,7 @@ export function foldJournal(journalText: string): JournalDigest {
|
|
|
120
120
|
return digest;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
// --- task lists (docs/specs/task-list-json/spec.md) ---
|
|
123
|
+
// --- task lists (docs/specs/_built/task-list-json/spec.md) ---
|
|
124
124
|
|
|
125
125
|
export interface TaskListDigest {
|
|
126
126
|
/** Strict count: only `done` tasks — pending, in-progress, and failed all
|
|
@@ -197,6 +197,10 @@ export interface ReportDispatch {
|
|
|
197
197
|
phase: "succeeded" | "failed" | "crashed";
|
|
198
198
|
event?: string;
|
|
199
199
|
reason?: unknown;
|
|
200
|
+
/** The runner name the state selected; absent for the default runner. */
|
|
201
|
+
runner?: string;
|
|
202
|
+
/** The resolved agent runner's `kind`; absent when it declares none. */
|
|
203
|
+
runnerKind?: string;
|
|
200
204
|
}
|
|
201
205
|
|
|
202
206
|
export interface ReportDigest {
|
|
@@ -215,7 +219,12 @@ export function foldReport(journalText: string): ReportDigest {
|
|
|
215
219
|
if (events.length === 0) return digest;
|
|
216
220
|
|
|
217
221
|
digest.spanMs = events.at(-1)!.timestamp - events[0]!.timestamp;
|
|
218
|
-
|
|
222
|
+
// The opening `running` event's timestamp and runner fields, until its
|
|
223
|
+
// terminal event turns them into a row.
|
|
224
|
+
const openAt = new Map<
|
|
225
|
+
string,
|
|
226
|
+
{ startedAt: number } & Pick<ReportDispatch, "runner" | "runnerKind">
|
|
227
|
+
>();
|
|
219
228
|
for (const e of events) {
|
|
220
229
|
// DONE's begin/end markers are skipped — neither is a real node's
|
|
221
230
|
// dispatch. FAILED's end marker is NOT skipped: it is `run_failure`'s
|
|
@@ -236,24 +245,32 @@ export function foldReport(journalText: string): ReportDigest {
|
|
|
236
245
|
// a dispatch opens (first attempt or retry): count attempt-1 opens as
|
|
237
246
|
// visits and start the duration clock
|
|
238
247
|
if (attempt === 1) digest.visits[e.state] = (digest.visits[e.state] ?? 0) + 1;
|
|
239
|
-
openAt.set(key,
|
|
248
|
+
openAt.set(key, {
|
|
249
|
+
startedAt: e.timestamp,
|
|
250
|
+
...(st.runner === undefined ? {} : { runner: st.runner }),
|
|
251
|
+
...(st.runnerKind === undefined ? {} : { runnerKind: st.runnerKind }),
|
|
252
|
+
});
|
|
240
253
|
} else if (st.phase === "succeeded") {
|
|
241
|
-
const
|
|
242
|
-
if (
|
|
254
|
+
const open = openAt.get(key);
|
|
255
|
+
if (open === undefined) continue;
|
|
243
256
|
openAt.delete(key);
|
|
257
|
+
const { startedAt, ...ran } = open;
|
|
244
258
|
digest.dispatches.push({
|
|
259
|
+
...ran,
|
|
245
260
|
state: e.state,
|
|
246
|
-
durationMs: e.timestamp -
|
|
261
|
+
durationMs: e.timestamp - startedAt,
|
|
247
262
|
phase: "succeeded",
|
|
248
263
|
event: st.result?.event,
|
|
249
264
|
});
|
|
250
265
|
} else if (st.phase === "crashed") {
|
|
251
|
-
const
|
|
252
|
-
if (
|
|
266
|
+
const open = openAt.get(key);
|
|
267
|
+
if (open === undefined) continue;
|
|
253
268
|
openAt.delete(key);
|
|
269
|
+
const { startedAt, ...ran } = open;
|
|
254
270
|
digest.dispatches.push({
|
|
271
|
+
...ran,
|
|
255
272
|
state: e.state,
|
|
256
|
-
durationMs: e.timestamp -
|
|
273
|
+
durationMs: e.timestamp - startedAt,
|
|
257
274
|
phase: "crashed",
|
|
258
275
|
reason: st.reason,
|
|
259
276
|
});
|
|
@@ -290,7 +307,7 @@ export function stallWarning(digest: JournalDigest, now: number = Date.now()): s
|
|
|
290
307
|
}
|
|
291
308
|
|
|
292
309
|
// Placeholder default, not yet measured against real runs — see
|
|
293
|
-
// docs/specs/agent-liveness/spec.md's open questions (a long tool-execution
|
|
310
|
+
// docs/specs/_built/agent-liveness/spec.md's open questions (a long tool-execution
|
|
294
311
|
// gap, e.g. a 10-minute build, looks identical to a hung provider; the
|
|
295
312
|
// warning's step count is what lets the supervisor tell them apart).
|
|
296
313
|
export const AGENT_STALL_MS = 15 * 60_000;
|
|
@@ -327,7 +344,7 @@ export function nudgeWarning(digest: JournalDigest): string | null {
|
|
|
327
344
|
return `nudging attempt ${nudgeAttempt}/3 (${nudgeReason}) — supervisor decides`;
|
|
328
345
|
}
|
|
329
346
|
|
|
330
|
-
// Display-only usage-limit config defaults (docs/specs/usage-limit-backoff/
|
|
347
|
+
// Display-only usage-limit config defaults (docs/specs/_built/usage-limit-backoff/
|
|
331
348
|
// spec.md), mirroring how this module already treats other engine constants
|
|
332
349
|
// as display knowledge, not a shared dependency. The denominator assumes the
|
|
333
350
|
// defaults; a leaf overriding usageLimitRetryMs/usageLimitMaxWaitMs renders
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { zodOutputType } from "./zod.ts";
|
|
4
|
+
|
|
5
|
+
function expectFailure(result: { success: true } | { success: false; message: string }): string {
|
|
6
|
+
if (result.success) throw new Error("expected a failing parse");
|
|
7
|
+
return result.message;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
describe("zodOutputType", () => {
|
|
11
|
+
test("a passing schema returns { success: true }, with no message field", () => {
|
|
12
|
+
const outputType = zodOutputType(z.object({ title: z.string() }));
|
|
13
|
+
const result = outputType.safeParse({ title: "hi" });
|
|
14
|
+
expect(result).toEqual({ success: true });
|
|
15
|
+
expect("message" in result).toBe(false);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("a failing schema with one bad field returns one issue, its path joined by dots", () => {
|
|
19
|
+
const outputType = zodOutputType(z.object({ tasks: z.array(z.object({ title: z.string() })) }));
|
|
20
|
+
const message = expectFailure(
|
|
21
|
+
outputType.safeParse({ tasks: [{ title: "a" }, { title: "b" }, {}] }),
|
|
22
|
+
);
|
|
23
|
+
// path ["tasks", 2, "title"] -> "tasks.2.title", one issue only (no "; " join)
|
|
24
|
+
expect(message.startsWith("tasks.2.title: ")).toBe(true);
|
|
25
|
+
expect(message).not.toContain("; ");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("a root-level failure, with no path, falls back to the word `output`", () => {
|
|
29
|
+
const outputType = zodOutputType(z.string());
|
|
30
|
+
const message = expectFailure(outputType.safeParse(42));
|
|
31
|
+
expect(message.startsWith("output: ")).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("a schema with two failing fields returns every issue, joined together, not just the first", () => {
|
|
35
|
+
const outputType = zodOutputType(z.object({ summary: z.string(), count: z.number() }));
|
|
36
|
+
const message = expectFailure(outputType.safeParse({ summary: 1, count: "two" }));
|
|
37
|
+
const parts = message.split("; ");
|
|
38
|
+
expect(parts).toHaveLength(2);
|
|
39
|
+
expect(parts[0].startsWith("summary: ")).toBe(true);
|
|
40
|
+
expect(parts[1].startsWith("count: ")).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { OutputSchema } from "../../core/index.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Adapter from a Zod schema to the engine's `OutputSchema` interface
|
|
6
|
+
* (`AgentStateDef.outputType`). Joins every issue from one failed parse
|
|
7
|
+
* into a single message, so one nudge can name all failing fields.
|
|
8
|
+
*/
|
|
9
|
+
export function zodOutputType<T>(schema: z.ZodType<T>): OutputSchema {
|
|
10
|
+
return {
|
|
11
|
+
safeParse: (value) => {
|
|
12
|
+
const result = schema.safeParse(value);
|
|
13
|
+
if (result.success) return { success: true };
|
|
14
|
+
const message = result.error.issues
|
|
15
|
+
.map((issue) => `${issue.path.join(".") || "output"}: ${issue.message}`)
|
|
16
|
+
.join("; ");
|
|
17
|
+
return { success: false, message };
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -5,17 +5,20 @@ import type { DispatchInfo } from "@psimona/darkf/src/core/index.ts";
|
|
|
5
5
|
// rides along on the branch — Finish commits it there before the squash.
|
|
6
6
|
// The slug is a workflow-file constant for the pilot; editing this file per
|
|
7
7
|
// feature is the contract until engine-side input plumbing exists.
|
|
8
|
-
const FEATURE = "
|
|
8
|
+
const FEATURE = "opencode-overlay-tiles";
|
|
9
9
|
|
|
10
|
-
function sh(...args: string[]): [string, number] {
|
|
11
|
-
const proc = Bun.spawnSync(args, { stdout: "pipe", stderr: "pipe" });
|
|
10
|
+
function sh(cwd: string, ...args: string[]): [string, number] {
|
|
11
|
+
const proc = Bun.spawnSync(args, { cwd, stdout: "pipe", stderr: "pipe" });
|
|
12
12
|
return [`${proc.stdout?.toString() ?? ""}${proc.stderr?.toString() ?? ""}`, proc.exitCode ?? 1];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export default function begin(_handoff: unknown,
|
|
15
|
+
export default function begin(_handoff: unknown, info: DispatchInfo) {
|
|
16
16
|
const target = `feature/${FEATURE}`;
|
|
17
|
-
const [, exists] = sh("git", "rev-parse", "--verify", target);
|
|
18
|
-
const co =
|
|
17
|
+
const [, exists] = sh(info.rootDir, "git", "rev-parse", "--verify", target);
|
|
18
|
+
const co =
|
|
19
|
+
exists === 0
|
|
20
|
+
? sh(info.rootDir, "git", "checkout", target)
|
|
21
|
+
: sh(info.rootDir, "git", "checkout", "-b", target);
|
|
19
22
|
return co[1] === 0
|
|
20
23
|
? { event: "started", output: { branch: target, reused: exists === 0 } }
|
|
21
24
|
: { event: "branch_failed", output: { reason: co[0] } };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { readFile, 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
|
+
// The node that walks the plan — darkf's item-loop-convention shape
|
|
10
|
+
// (docs/specs/item-loop-convention/spec.md), hand-rolled here because that
|
|
11
|
+
// spec's own darkf-core/kit helper isn't shipped yet; this follows its
|
|
12
|
+
// algorithm and vocabulary directly (pending → in-progress, picked once
|
|
13
|
+
// and re-verified by Review rather than trusted, status written back
|
|
14
|
+
// before the real work starts) without importing anything from it.
|
|
15
|
+
//
|
|
16
|
+
// Picks the first "pending" task out of this run's tasks.json, flips it
|
|
17
|
+
// "in-progress", and hands it to Implement as the one thing to build this
|
|
18
|
+
// pass. Re-entered once per task — by Review approving one, via MarkDone
|
|
19
|
+
// — until the plan is exhausted.
|
|
20
|
+
export default async function dispatch(
|
|
21
|
+
_handoff: NodeResult,
|
|
22
|
+
info: DispatchInfo,
|
|
23
|
+
): Promise<NodeResult> {
|
|
24
|
+
const path = join(info.rootDir, ".darkf", "run", info.runId, "tasks.json");
|
|
25
|
+
const parsed = parseTaskList(JSON.parse(await readFile(path, "utf8")));
|
|
26
|
+
if ("error" in parsed) {
|
|
27
|
+
return { event: "blocked", output: { reason: `tasks.json is invalid: ${parsed.error}` } };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const next = parsed.tasks.find((t) => t.status === "pending");
|
|
31
|
+
if (!next) {
|
|
32
|
+
const failed = parsed.tasks.filter((t) => t.status === "failed");
|
|
33
|
+
if (failed.length > 0) {
|
|
34
|
+
return {
|
|
35
|
+
event: "blocked",
|
|
36
|
+
output: { reason: `task(s) failed: ${failed.map((t) => t.id).join(", ")}` },
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return { event: "plan_exhausted", output: {} };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
next.status = "in-progress";
|
|
43
|
+
await writeFile(path, JSON.stringify(parsed, null, 2));
|
|
44
|
+
|
|
45
|
+
const done = parsed.tasks.filter((t) => t.status === "done").length;
|
|
46
|
+
return {
|
|
47
|
+
event: "next_item",
|
|
48
|
+
output: { task: next, itemIndex: done + 1, itemsTotal: parsed.tasks.length },
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -13,13 +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 = "
|
|
16
|
+
const FEATURE = "opencode-overlay-tiles";
|
|
17
17
|
const ALLOWED = [
|
|
18
18
|
"docs/",
|
|
19
19
|
"darkf/src/",
|
|
20
20
|
"darkf/skills/",
|
|
21
21
|
"darkf/docs/",
|
|
22
22
|
"darkf/package.json",
|
|
23
|
+
"bun.lock",
|
|
23
24
|
"darkf-opencode-plugin/",
|
|
24
25
|
"ROADMAP.md",
|
|
25
26
|
"README.md",
|
|
@@ -27,22 +28,23 @@ const ALLOWED = [
|
|
|
27
28
|
"darkf/workflows/",
|
|
28
29
|
];
|
|
29
30
|
|
|
30
|
-
function sh(...args: string[]): [string, number] {
|
|
31
|
-
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" });
|
|
32
33
|
return [`${proc.stdout?.toString() ?? ""}${proc.stderr?.toString() ?? ""}`, proc.exitCode ?? 1];
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
function prdTitle(): string | null {
|
|
36
|
-
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`);
|
|
37
38
|
if (rc !== 0) return null;
|
|
38
39
|
const line = out.trim();
|
|
39
40
|
return line.startsWith("# ") ? line.slice(2).trim() : null;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
export default function finishBranch(_handoff: NodeResult,
|
|
43
|
+
export default function finishBranch(_handoff: NodeResult, info: DispatchInfo): NodeResult {
|
|
43
44
|
const branch = `feature/${FEATURE}`;
|
|
45
|
+
const { rootDir } = info;
|
|
44
46
|
|
|
45
|
-
const [current, currentRc] = sh("git", "branch", "--show-current");
|
|
47
|
+
const [current, currentRc] = sh(rootDir, "git", "branch", "--show-current");
|
|
46
48
|
if (currentRc !== 0 || current.trim() !== branch) {
|
|
47
49
|
return {
|
|
48
50
|
event: "merge_failed",
|
|
@@ -50,7 +52,7 @@ export default function finishBranch(_handoff: NodeResult, _info: DispatchInfo):
|
|
|
50
52
|
};
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
const [status, statusRc] = sh("git", "status", "--porcelain");
|
|
55
|
+
const [status, statusRc] = sh(rootDir, "git", "status", "--porcelain");
|
|
54
56
|
if (statusRc !== 0) {
|
|
55
57
|
return { event: "merge_failed", output: { failure: "git status failed" } };
|
|
56
58
|
}
|
|
@@ -68,10 +70,10 @@ export default function finishBranch(_handoff: NodeResult, _info: DispatchInfo):
|
|
|
68
70
|
};
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
const title = prdTitle() ?? FEATURE;
|
|
73
|
+
const title = prdTitle(rootDir) ?? FEATURE;
|
|
72
74
|
const subject = `feat: ${title} (${FEATURE})`;
|
|
73
|
-
const add = sh("git", "add", "-A");
|
|
74
|
-
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];
|
|
75
77
|
if (commit[1] !== 0) {
|
|
76
78
|
return {
|
|
77
79
|
event: "merge_failed",
|
|
@@ -79,7 +81,7 @@ export default function finishBranch(_handoff: NodeResult, _info: DispatchInfo):
|
|
|
79
81
|
};
|
|
80
82
|
}
|
|
81
83
|
|
|
82
|
-
const [, ancestorRc] = sh("git", "merge-base", "--is-ancestor", "master", "HEAD");
|
|
84
|
+
const [, ancestorRc] = sh(rootDir, "git", "merge-base", "--is-ancestor", "master", "HEAD");
|
|
83
85
|
if (ancestorRc !== 0) {
|
|
84
86
|
return {
|
|
85
87
|
event: "merge_failed",
|
|
@@ -90,33 +92,33 @@ export default function finishBranch(_handoff: NodeResult, _info: DispatchInfo):
|
|
|
90
92
|
};
|
|
91
93
|
}
|
|
92
94
|
|
|
93
|
-
const [ahead] = sh("git", "log", "--oneline", `master..${branch}`);
|
|
95
|
+
const [ahead] = sh(rootDir, "git", "log", "--oneline", `master..${branch}`);
|
|
94
96
|
if (ahead.trim() === "") {
|
|
95
97
|
return { event: "merged", output: { note: "no commits ahead of master — nothing to merge" } };
|
|
96
98
|
}
|
|
97
99
|
|
|
98
|
-
const checkout = sh("git", "checkout", "master");
|
|
100
|
+
const checkout = sh(rootDir, "git", "checkout", "master");
|
|
99
101
|
if (checkout[1] !== 0) {
|
|
100
102
|
return { event: "merge_failed", output: { failure: `checkout master failed: ${checkout[0]}` } };
|
|
101
103
|
}
|
|
102
104
|
|
|
103
|
-
const merge = sh("git", "merge", "--squash", branch);
|
|
105
|
+
const merge = sh(rootDir, "git", "merge", "--squash", branch);
|
|
104
106
|
if (merge[1] !== 0) {
|
|
105
|
-
sh("git", "reset", "--hard", "HEAD");
|
|
106
|
-
sh("git", "checkout", branch);
|
|
107
|
+
sh(rootDir, "git", "reset", "--hard", "HEAD");
|
|
108
|
+
sh(rootDir, "git", "checkout", branch);
|
|
107
109
|
return { event: "merge_failed", output: { failure: `squash merge failed: ${merge[0]}` } };
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
const body =
|
|
111
113
|
"Landed via the dev-loop darkf workflow — check gate green, independent review approved.";
|
|
112
|
-
const final = sh("git", "commit", "-m", subject, "-m", body);
|
|
114
|
+
const final = sh(rootDir, "git", "commit", "-m", subject, "-m", body);
|
|
113
115
|
if (final[1] !== 0) {
|
|
114
|
-
sh("git", "reset", "--hard", "HEAD");
|
|
115
|
-
sh("git", "checkout", branch);
|
|
116
|
+
sh(rootDir, "git", "reset", "--hard", "HEAD");
|
|
117
|
+
sh(rootDir, "git", "checkout", branch);
|
|
116
118
|
return { event: "merge_failed", output: { failure: `squash commit failed: ${final[0]}` } };
|
|
117
119
|
}
|
|
118
120
|
|
|
119
|
-
const del = sh("git", "branch", "-D", branch);
|
|
121
|
+
const del = sh(rootDir, "git", "branch", "-D", branch);
|
|
120
122
|
const note =
|
|
121
123
|
del[1] === 0
|
|
122
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
|
+
}
|