@psimona/darkf 0.6.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.
- package/docs/concepts/failure-modes.md +18 -5
- package/docs/concepts/node-types.md +4 -2
- package/docs/guides/plan-with-a-task-queue.md +6 -5
- package/docs/guides/write-your-first-workflow.md +8 -2
- package/docs/index.mdx +4 -0
- package/docs/reference/core-types.md +5 -0
- package/docs/reference/package-map.md +12 -8
- package/docs/start-here/quickstart.md +12 -5
- package/package.json +9 -2
- package/skills/darkf-writing-workflows/SKILL.md +131 -6
- package/src/cli/doctor.test.ts +1 -1
- package/src/cli/index.ts +25 -15
- 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/tasks.ts +1 -1
- package/src/core/types.test.ts +52 -0
- package/src/core/types.ts +27 -18
- package/src/engine/run.test.ts +286 -4
- package/src/engine/run.ts +51 -9
- package/src/exports.ts +4 -0
- package/src/kit/agents/claude-code.ts +4 -34
- 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 +14 -28
- package/src/kit/specs.test.ts +247 -0
- package/src/kit/specs.ts +344 -0
- package/src/kit/status.ts +6 -6
- 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/dev-loop/scripts/{check.ts → test.ts} +0 -0
package/src/kit/specs.ts
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
// The backplane spec workspace contract (D15, D16). One spec per folder under
|
|
2
|
+
// `docs/specs/`, a single ordered `backlog.json`, and a `project.json` for
|
|
3
|
+
// harness and sandbox defaults. Every file is typed here, and validators reject
|
|
4
|
+
// anything the format does not name — so a workflow that imports this module
|
|
5
|
+
// sees the same shape the backplane does.
|
|
6
|
+
//
|
|
7
|
+
// Format rules live in the backplane repo at
|
|
8
|
+
// `docs/specs/0001-spec-format/spec.md`. Keep this module in sync with it.
|
|
9
|
+
|
|
10
|
+
export const SPEC_FORMAT_VERSION = 1;
|
|
11
|
+
|
|
12
|
+
/** Frontmatter of a `spec.md`. Unknown fields are rejected. */
|
|
13
|
+
export interface SpecFrontmatter {
|
|
14
|
+
/** UUIDv4 identity. Generated at creation, never changes. */
|
|
15
|
+
id: string;
|
|
16
|
+
/** Human key for URLs, search, and chat. Safe to change. */
|
|
17
|
+
slug: string;
|
|
18
|
+
/** The one person accountable for this spec. */
|
|
19
|
+
owner: string;
|
|
20
|
+
/** UUIDs of specs this one waits for. Satisfied when those ship. */
|
|
21
|
+
depends_on?: string[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** `docs/specs/backlog.json` — the only planning state stored (D16). */
|
|
25
|
+
export interface BacklogFile {
|
|
26
|
+
version: 1;
|
|
27
|
+
/** Spec UUIDs in priority order. Unlisted specs sort after these. */
|
|
28
|
+
order: string[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** An allowlisted pod volume mount for a project's sandbox (D3). */
|
|
32
|
+
export interface SandboxMount {
|
|
33
|
+
name: string;
|
|
34
|
+
mountPath: string;
|
|
35
|
+
/** Optional size hint, e.g. "10Gi". */
|
|
36
|
+
size?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** `project.json` — harness and sandbox defaults (D2, D3). */
|
|
40
|
+
export interface ProjectConfig {
|
|
41
|
+
version: 1;
|
|
42
|
+
title?: string;
|
|
43
|
+
harness?: {
|
|
44
|
+
/** Agent runner kind, e.g. "claude-code" or "opencode". */
|
|
45
|
+
runner: string;
|
|
46
|
+
/** Optional model hint passed to the runner. */
|
|
47
|
+
model?: string;
|
|
48
|
+
};
|
|
49
|
+
sandbox?: {
|
|
50
|
+
/** Project-supplied image, normally the CI image (D3). */
|
|
51
|
+
image?: string;
|
|
52
|
+
/** Isolation runtime from the allowlist, e.g. "kata" or "gvisor". */
|
|
53
|
+
runtimeClass?: string;
|
|
54
|
+
mounts?: SandboxMount[];
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A parsed `spec.md`: frontmatter plus the untouched body. */
|
|
59
|
+
export interface SpecDocument {
|
|
60
|
+
frontmatter: SpecFrontmatter;
|
|
61
|
+
body: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Raised when a backplane file does not match the format. */
|
|
65
|
+
export class SpecFormatError extends Error {
|
|
66
|
+
constructor(readonly issues: string[]) {
|
|
67
|
+
super(`invalid spec workspace file: ${issues.join("; ")}`);
|
|
68
|
+
this.name = "SpecFormatError";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const UUID_V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
73
|
+
const SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
74
|
+
|
|
75
|
+
const SPEC_FIELDS = new Set(["id", "slug", "owner", "depends_on"]);
|
|
76
|
+
const BACKLOG_FIELDS = new Set(["version", "order"]);
|
|
77
|
+
const PROJECT_FIELDS = new Set(["version", "title", "harness", "sandbox"]);
|
|
78
|
+
const HARNESS_FIELDS = new Set(["runner", "model"]);
|
|
79
|
+
const SANDBOX_FIELDS = new Set(["image", "runtimeClass", "mounts"]);
|
|
80
|
+
const MOUNT_FIELDS = new Set(["name", "mountPath", "size"]);
|
|
81
|
+
|
|
82
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
83
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function unknownFields(
|
|
87
|
+
value: Record<string, unknown>,
|
|
88
|
+
allowed: Set<string>,
|
|
89
|
+
where: string,
|
|
90
|
+
): string[] {
|
|
91
|
+
return Object.keys(value)
|
|
92
|
+
.filter((key) => !allowed.has(key))
|
|
93
|
+
.map((key) => `${where}: unknown field "${key}"`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function isUuid(value: unknown): value is string {
|
|
97
|
+
return typeof value === "string" && UUID_V4.test(value);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function collectUnique(values: string[], label: string): string[] {
|
|
101
|
+
const seen = new Set<string>();
|
|
102
|
+
const issues: string[] = [];
|
|
103
|
+
for (const value of values) {
|
|
104
|
+
if (seen.has(value)) issues.push(`${label}: duplicate "${value}"`);
|
|
105
|
+
seen.add(value);
|
|
106
|
+
}
|
|
107
|
+
return issues;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Parse and validate `spec.md` frontmatter. Throws {@link SpecFormatError}. */
|
|
111
|
+
export function parseSpecFrontmatter(value: unknown): SpecFrontmatter {
|
|
112
|
+
if (!isRecord(value)) throw new SpecFormatError(["frontmatter must be a YAML object"]);
|
|
113
|
+
|
|
114
|
+
const issues = unknownFields(value, SPEC_FIELDS, "frontmatter");
|
|
115
|
+
const { id, slug, owner, depends_on } = value;
|
|
116
|
+
|
|
117
|
+
if (!isUuid(id)) issues.push('frontmatter: "id" must be a UUIDv4 string');
|
|
118
|
+
if (typeof slug !== "string" || !SLUG.test(slug)) {
|
|
119
|
+
issues.push('frontmatter: "slug" must be lowercase kebab-case');
|
|
120
|
+
}
|
|
121
|
+
if (typeof owner !== "string" || owner.trim() === "") {
|
|
122
|
+
issues.push('frontmatter: "owner" must be a non-empty string');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
let deps: string[] | undefined;
|
|
126
|
+
if (depends_on !== undefined) {
|
|
127
|
+
if (!Array.isArray(depends_on)) {
|
|
128
|
+
issues.push('frontmatter: "depends_on" must be an array of spec UUIDs');
|
|
129
|
+
} else {
|
|
130
|
+
for (const dep of depends_on) {
|
|
131
|
+
if (!isUuid(dep))
|
|
132
|
+
issues.push(`frontmatter: depends_on entry "${String(dep)}" is not a UUIDv4`);
|
|
133
|
+
}
|
|
134
|
+
issues.push(...collectUnique(depends_on as string[], "frontmatter: depends_on"));
|
|
135
|
+
if (depends_on.includes(id as string))
|
|
136
|
+
issues.push("frontmatter: a spec cannot depend on itself");
|
|
137
|
+
deps = [...(depends_on as string[])];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (issues.length > 0) throw new SpecFormatError(issues);
|
|
142
|
+
const spec: SpecFrontmatter = { id: id as string, slug: slug as string, owner: owner as string };
|
|
143
|
+
if (deps !== undefined) spec.depends_on = deps;
|
|
144
|
+
return spec;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Parse a `spec.md` file: YAML frontmatter plus body. Throws {@link SpecFormatError}. */
|
|
148
|
+
export function parseSpecDocument(text: string): SpecDocument {
|
|
149
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(text);
|
|
150
|
+
if (!match) {
|
|
151
|
+
throw new SpecFormatError(["spec.md must start with a --- frontmatter block"]);
|
|
152
|
+
}
|
|
153
|
+
let raw: unknown;
|
|
154
|
+
try {
|
|
155
|
+
raw = Bun.YAML.parse(match[1] ?? "");
|
|
156
|
+
} catch (error) {
|
|
157
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
158
|
+
throw new SpecFormatError([`frontmatter is not valid YAML: ${reason}`]);
|
|
159
|
+
}
|
|
160
|
+
return { frontmatter: parseSpecFrontmatter(raw), body: text.slice(match[0].length) };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Parse and validate `docs/specs/backlog.json`. Throws {@link SpecFormatError}. */
|
|
164
|
+
export function parseBacklog(value: unknown): BacklogFile {
|
|
165
|
+
if (!isRecord(value)) throw new SpecFormatError(["backlog must be a JSON object"]);
|
|
166
|
+
|
|
167
|
+
const issues = unknownFields(value, BACKLOG_FIELDS, "backlog");
|
|
168
|
+
if (value.version !== SPEC_FORMAT_VERSION) {
|
|
169
|
+
issues.push(`backlog: "version" must be ${SPEC_FORMAT_VERSION}`);
|
|
170
|
+
}
|
|
171
|
+
if (!Array.isArray(value.order)) {
|
|
172
|
+
issues.push('backlog: "order" must be an array of spec UUIDs');
|
|
173
|
+
} else {
|
|
174
|
+
for (const id of value.order) {
|
|
175
|
+
if (!isUuid(id)) issues.push(`backlog: order entry "${String(id)}" is not a UUIDv4`);
|
|
176
|
+
}
|
|
177
|
+
issues.push(...collectUnique(value.order as string[], "backlog: order"));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (issues.length > 0) throw new SpecFormatError(issues);
|
|
181
|
+
return { version: SPEC_FORMAT_VERSION, order: [...(value.order as string[])] };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Parse backlog.json text. Throws {@link SpecFormatError}. */
|
|
185
|
+
export function parseBacklogJson(text: string): BacklogFile {
|
|
186
|
+
return parseBacklog(parseJson(text, "backlog.json"));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Parse and validate project.json. Throws {@link SpecFormatError}. */
|
|
190
|
+
export function parseProjectConfig(value: unknown): ProjectConfig {
|
|
191
|
+
if (!isRecord(value)) throw new SpecFormatError(["project config must be a JSON object"]);
|
|
192
|
+
|
|
193
|
+
const issues = unknownFields(value, PROJECT_FIELDS, "project");
|
|
194
|
+
if (value.version !== SPEC_FORMAT_VERSION) {
|
|
195
|
+
issues.push(`project: "version" must be ${SPEC_FORMAT_VERSION}`);
|
|
196
|
+
}
|
|
197
|
+
if (value.title !== undefined && typeof value.title !== "string") {
|
|
198
|
+
issues.push('project: "title" must be a string');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (value.harness !== undefined) {
|
|
202
|
+
if (!isRecord(value.harness)) {
|
|
203
|
+
issues.push('project: "harness" must be an object');
|
|
204
|
+
} else {
|
|
205
|
+
const harness = value.harness;
|
|
206
|
+
issues.push(...unknownFields(harness, HARNESS_FIELDS, "project.harness"));
|
|
207
|
+
if (typeof harness.runner !== "string" || harness.runner.trim() === "") {
|
|
208
|
+
issues.push('project.harness: "runner" must be a non-empty string');
|
|
209
|
+
}
|
|
210
|
+
if (harness.model !== undefined && typeof harness.model !== "string") {
|
|
211
|
+
issues.push('project.harness: "model" must be a string');
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (value.sandbox !== undefined) {
|
|
217
|
+
if (!isRecord(value.sandbox)) {
|
|
218
|
+
issues.push('project: "sandbox" must be an object');
|
|
219
|
+
} else {
|
|
220
|
+
const sandbox = value.sandbox;
|
|
221
|
+
issues.push(...unknownFields(sandbox, SANDBOX_FIELDS, "project.sandbox"));
|
|
222
|
+
for (const key of ["image", "runtimeClass"] as const) {
|
|
223
|
+
if (sandbox[key] !== undefined && typeof sandbox[key] !== "string") {
|
|
224
|
+
issues.push(`project.sandbox: "${key}" must be a string`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (sandbox.mounts !== undefined) {
|
|
228
|
+
if (!Array.isArray(sandbox.mounts)) {
|
|
229
|
+
issues.push('project.sandbox: "mounts" must be an array');
|
|
230
|
+
} else {
|
|
231
|
+
sandbox.mounts.forEach((mount, index) => {
|
|
232
|
+
if (!isRecord(mount)) {
|
|
233
|
+
issues.push(`project.sandbox.mounts[${index}] must be an object`);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
issues.push(...unknownFields(mount, MOUNT_FIELDS, `project.sandbox.mounts[${index}]`));
|
|
237
|
+
if (typeof mount.name !== "string" || mount.name.trim() === "") {
|
|
238
|
+
issues.push(`project.sandbox.mounts[${index}]: "name" must be a non-empty string`);
|
|
239
|
+
}
|
|
240
|
+
if (typeof mount.mountPath !== "string" || !mount.mountPath.startsWith("/")) {
|
|
241
|
+
issues.push(`project.sandbox.mounts[${index}]: "mountPath" must be an absolute path`);
|
|
242
|
+
}
|
|
243
|
+
if (mount.size !== undefined && typeof mount.size !== "string") {
|
|
244
|
+
issues.push(`project.sandbox.mounts[${index}]: "size" must be a string`);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (issues.length > 0) throw new SpecFormatError(issues);
|
|
253
|
+
|
|
254
|
+
const project: ProjectConfig = { version: SPEC_FORMAT_VERSION };
|
|
255
|
+
if (typeof value.title === "string") project.title = value.title;
|
|
256
|
+
if (isRecord(value.harness)) {
|
|
257
|
+
const harness: NonNullable<ProjectConfig["harness"]> = {
|
|
258
|
+
runner: value.harness.runner as string,
|
|
259
|
+
};
|
|
260
|
+
if (typeof value.harness.model === "string") harness.model = value.harness.model;
|
|
261
|
+
project.harness = harness;
|
|
262
|
+
}
|
|
263
|
+
if (isRecord(value.sandbox)) {
|
|
264
|
+
const sandbox: NonNullable<ProjectConfig["sandbox"]> = {};
|
|
265
|
+
if (typeof value.sandbox.image === "string") sandbox.image = value.sandbox.image;
|
|
266
|
+
if (typeof value.sandbox.runtimeClass === "string") {
|
|
267
|
+
sandbox.runtimeClass = value.sandbox.runtimeClass;
|
|
268
|
+
}
|
|
269
|
+
if (Array.isArray(value.sandbox.mounts)) {
|
|
270
|
+
sandbox.mounts = value.sandbox.mounts.map((mount) => {
|
|
271
|
+
const raw = mount as Record<string, unknown>;
|
|
272
|
+
const parsed: SandboxMount = {
|
|
273
|
+
name: raw.name as string,
|
|
274
|
+
mountPath: raw.mountPath as string,
|
|
275
|
+
};
|
|
276
|
+
if (typeof raw.size === "string") parsed.size = raw.size;
|
|
277
|
+
return parsed;
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
project.sandbox = sandbox;
|
|
281
|
+
}
|
|
282
|
+
return project;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Parse project.json text. Throws {@link SpecFormatError}. */
|
|
286
|
+
export function parseProjectJson(text: string): ProjectConfig {
|
|
287
|
+
return parseProjectConfig(parseJson(text, "project.json"));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Validate a set of specs as a graph: unique ids and slugs, existing
|
|
292
|
+
* dependency targets, and no cycles. Throws {@link SpecFormatError}.
|
|
293
|
+
*/
|
|
294
|
+
export function validateSpecGraph(specs: SpecFrontmatter[]): void {
|
|
295
|
+
const issues: string[] = [];
|
|
296
|
+
issues.push(
|
|
297
|
+
...collectUnique(
|
|
298
|
+
specs.map((spec) => spec.id),
|
|
299
|
+
"spec graph: id",
|
|
300
|
+
),
|
|
301
|
+
);
|
|
302
|
+
issues.push(
|
|
303
|
+
...collectUnique(
|
|
304
|
+
specs.map((spec) => spec.slug),
|
|
305
|
+
"spec graph: slug",
|
|
306
|
+
),
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
const byId = new Map(specs.map((spec) => [spec.id, spec]));
|
|
310
|
+
for (const spec of specs) {
|
|
311
|
+
for (const dep of spec.depends_on ?? []) {
|
|
312
|
+
if (!byId.has(dep))
|
|
313
|
+
issues.push(`spec ${spec.slug}: depends_on target "${dep}" does not exist`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const state = new Map<string, "visiting" | "done">();
|
|
318
|
+
const visit = (id: string, path: string[]): void => {
|
|
319
|
+
const mark = state.get(id);
|
|
320
|
+
if (mark === "done") return;
|
|
321
|
+
if (mark === "visiting") {
|
|
322
|
+
const cycle = [...path.slice(path.indexOf(id)), id]
|
|
323
|
+
.map((specId) => byId.get(specId)?.slug ?? specId)
|
|
324
|
+
.join(" -> ");
|
|
325
|
+
issues.push(`spec graph: dependency cycle ${cycle}`);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
state.set(id, "visiting");
|
|
329
|
+
for (const dep of byId.get(id)?.depends_on ?? []) visit(dep, [...path, id]);
|
|
330
|
+
state.set(id, "done");
|
|
331
|
+
};
|
|
332
|
+
for (const spec of specs) visit(spec.id, []);
|
|
333
|
+
|
|
334
|
+
if (issues.length > 0) throw new SpecFormatError(issues);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function parseJson(text: string, file: string): unknown {
|
|
338
|
+
try {
|
|
339
|
+
return JSON.parse(text);
|
|
340
|
+
} catch (error) {
|
|
341
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
342
|
+
throw new SpecFormatError([`${file} is not valid JSON: ${reason}`]);
|
|
343
|
+
}
|
|
344
|
+
}
|
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
|
|
@@ -290,7 +290,7 @@ export function stallWarning(digest: JournalDigest, now: number = Date.now()): s
|
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
// Placeholder default, not yet measured against real runs — see
|
|
293
|
-
// docs/specs/agent-liveness/spec.md's open questions (a long tool-execution
|
|
293
|
+
// docs/specs/_built/agent-liveness/spec.md's open questions (a long tool-execution
|
|
294
294
|
// gap, e.g. a 10-minute build, looks identical to a hung provider; the
|
|
295
295
|
// warning's step count is what lets the supervisor tell them apart).
|
|
296
296
|
export const AGENT_STALL_MS = 15 * 60_000;
|
|
@@ -327,7 +327,7 @@ export function nudgeWarning(digest: JournalDigest): string | null {
|
|
|
327
327
|
return `nudging attempt ${nudgeAttempt}/3 (${nudgeReason}) — supervisor decides`;
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
-
// Display-only usage-limit config defaults (docs/specs/usage-limit-backoff/
|
|
330
|
+
// Display-only usage-limit config defaults (docs/specs/_built/usage-limit-backoff/
|
|
331
331
|
// spec.md), mirroring how this module already treats other engine constants
|
|
332
332
|
// as display knowledge, not a shared dependency. The denominator assumes the
|
|
333
333
|
// 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`
|