@psimona/darkf 0.5.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/concepts/failure-modes.md +177 -0
- package/docs/concepts/handoff.md +91 -0
- package/docs/concepts/journal.md +92 -0
- package/docs/concepts/node-types.md +177 -0
- package/docs/guides/pick-an-agent-runner.md +57 -0
- package/docs/guides/plan-with-a-task-queue.md +411 -0
- package/docs/guides/render-to-mermaid.md +22 -0
- package/docs/guides/run-detached-and-monitor.md +76 -0
- package/docs/guides/test-your-workflow.md +20 -0
- package/docs/guides/write-your-first-workflow.md +101 -0
- package/docs/index.mdx +68 -0
- package/docs/reference/cli-commands.md +105 -0
- package/docs/reference/core-types.md +128 -0
- package/docs/reference/package-map.md +39 -0
- package/docs/start-here/install.md +71 -0
- package/docs/start-here/quickstart.md +248 -0
- package/package.json +15 -2
- package/skills/darkf-usage/SKILL.md +92 -0
- package/skills/darkf-writing-workflows/SKILL.md +213 -0
- package/src/cli/doctor.test.ts +338 -0
- package/src/cli/index.ts +139 -15
- package/src/cli/setup.test.ts +384 -0
- package/src/cli/setup.ts +281 -0
- package/src/cli/state-file.ts +14 -0
- package/src/cli/tarball.test.ts +127 -0
- package/src/cli/update.test.ts +82 -0
- package/src/cli/update.ts +24 -9
- package/src/core/tasks.ts +1 -1
- package/src/core/types.test.ts +52 -0
- package/src/core/types.ts +33 -16
- package/src/engine/run.test.ts +462 -3
- package/src/engine/run.ts +114 -8
- 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 +232 -2
- package/src/kit/agents/opencode.ts +80 -31
- package/src/kit/specs.test.ts +247 -0
- package/src/kit/specs.ts +344 -0
- package/src/kit/status.test.ts +67 -0
- package/src/kit/status.ts +29 -4
- 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 +26 -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 +171 -64
- package/bunfig.toml +0 -13
- package/examples/article-classifier/data/articles.ts +0 -38
- package/examples/article-classifier/scripts/next.ts +0 -7
- package/examples/article-classifier/scripts/queue.ts +0 -33
- package/examples/article-classifier/scripts/record.ts +0 -9
- package/examples/article-classifier/workflow.ts +0 -44
- package/examples/haiku-commit/scripts/check.ts +0 -24
- package/examples/haiku-commit/workflow.ts +0 -28
- package/examples/haiku-readme/scripts/test.ts +0 -13
- package/examples/haiku-readme/scripts/write.ts +0 -10
- package/examples/haiku-readme/workflow.ts +0 -41
- package/examples/task-queue/scripts/next.ts +0 -20
- package/examples/task-queue/scripts/record.ts +0 -20
- package/examples/task-queue/supervise.ts +0 -57
- package/examples/task-queue/workflow.ts +0 -33
- package/feedback/2026-10-30-self-update.md +0 -29
- package/feedback/2026-10-31-task-list-json.md +0 -26
- package/tsconfig.json +0 -4
- /package/workflows/dev-loop/scripts/{check.ts → test.ts} +0 -0
package/src/cli/setup.ts
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// Skill setup (docs/specs/_built/skill-setup): the shared skills-check core, the
|
|
2
|
+
// `darkf setup` sync, and the daily first-invocation probe. The bundled
|
|
3
|
+
// darkf-* skills ship inside the package (darkf/skills/); every dependency
|
|
4
|
+
// arrives via deps objects, so the whole module runs in tests without a real
|
|
5
|
+
// HOME, PATH, or the packaged skills dir. No module-level mutable state.
|
|
6
|
+
import {
|
|
7
|
+
cpSync,
|
|
8
|
+
type Dirent,
|
|
9
|
+
existsSync,
|
|
10
|
+
mkdirSync,
|
|
11
|
+
readdirSync,
|
|
12
|
+
readFileSync,
|
|
13
|
+
renameSync,
|
|
14
|
+
rmSync,
|
|
15
|
+
} from "node:fs";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import { writeJsonState } from "./state-file.ts";
|
|
18
|
+
|
|
19
|
+
// The known harnesses are a table in code — adding one is a row plus a test
|
|
20
|
+
// fixture, not a feature (spec: Host detection). `dir` is relative to HOME;
|
|
21
|
+
// a host is detected when its skills dir exists OR its binary is on PATH.
|
|
22
|
+
// A harness whose skills support or path cannot be confirmed drops from the
|
|
23
|
+
// table rather than creating dirs nothing reads.
|
|
24
|
+
export interface KnownHost {
|
|
25
|
+
name: string;
|
|
26
|
+
dir: string; // relative to HOME
|
|
27
|
+
binary: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const KNOWN_HOSTS: KnownHost[] = [
|
|
31
|
+
{ name: "claude", dir: ".claude/skills", binary: "claude" },
|
|
32
|
+
{ name: "opencode", dir: ".opencode/skills", binary: "opencode" },
|
|
33
|
+
{ name: "codex", dir: ".codex/skills", binary: "codex" },
|
|
34
|
+
{ name: "gemini", dir: ".gemini/skills", binary: "gemini" },
|
|
35
|
+
{ name: "cursor", dir: ".cursor/skills", binary: "cursor-agent" },
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
export type SkillState = "missing" | "ok" | "differs";
|
|
39
|
+
|
|
40
|
+
export interface SkillsDeps {
|
|
41
|
+
home: string; // expands the table's ~/. paths
|
|
42
|
+
bundledDir: string; // the package's skills/ dir
|
|
43
|
+
existsBinary(name: string): boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface SyncDeps extends SkillsDeps {
|
|
47
|
+
log?(line: string): void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface ProbeDeps extends SkillsDeps {
|
|
51
|
+
stateFile: string; // injectable last-skills-check location
|
|
52
|
+
today?(): string; // injectable local calendar date
|
|
53
|
+
log?(line: string): void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Bundled skill names: subdirs of bundledDir containing a SKILL.md, sorted. */
|
|
57
|
+
export function bundledSkills(bundledDir: string): string[] {
|
|
58
|
+
try {
|
|
59
|
+
return readdirSync(bundledDir, { withFileTypes: true })
|
|
60
|
+
.filter((e) => e.isDirectory() && existsSync(join(bundledDir, e.name, "SKILL.md")))
|
|
61
|
+
.map((e) => e.name)
|
|
62
|
+
.sort();
|
|
63
|
+
} catch {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The three per-skill states, by byte equality on SKILL.md — the only file
|
|
70
|
+
* either skill has. A dir without SKILL.md is a partial install: missing.
|
|
71
|
+
*/
|
|
72
|
+
export function skillState(skillsDir: string, skill: string, bundledDir: string): SkillState {
|
|
73
|
+
try {
|
|
74
|
+
const installed = readFileSync(join(skillsDir, skill, "SKILL.md"));
|
|
75
|
+
const bundled = readFileSync(join(bundledDir, skill, "SKILL.md"));
|
|
76
|
+
return installed.equals(bundled) ? "ok" : "differs";
|
|
77
|
+
} catch {
|
|
78
|
+
return "missing";
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface HostSkills {
|
|
83
|
+
host: string;
|
|
84
|
+
dir: string; // absolute, HOME-expanded
|
|
85
|
+
display: string; // the ~/. form for output lines
|
|
86
|
+
present: boolean;
|
|
87
|
+
/** Per bundled skill; empty for an absent host. */
|
|
88
|
+
states: Record<string, SkillState>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The read-only skills check every consumer shares (doctor's skills section,
|
|
93
|
+
* the daily probe, setup's state model): one entry per known harness, every
|
|
94
|
+
* harness always named. Reads nothing outside darkf-* skill dirs; writes
|
|
95
|
+
* nothing.
|
|
96
|
+
*/
|
|
97
|
+
export function skillsCheck(deps: SkillsDeps): HostSkills[] {
|
|
98
|
+
const skills = bundledSkills(deps.bundledDir);
|
|
99
|
+
return KNOWN_HOSTS.map((host) => {
|
|
100
|
+
const dir = join(deps.home, host.dir);
|
|
101
|
+
const present = existsSync(dir) || deps.existsBinary(host.binary);
|
|
102
|
+
const states: Record<string, SkillState> = {};
|
|
103
|
+
if (present) {
|
|
104
|
+
for (const skill of skills) states[skill] = skillState(dir, skill, deps.bundledDir);
|
|
105
|
+
}
|
|
106
|
+
return { host: host.name, dir, display: `~/${host.dir}`, present, states };
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Per-skill failing names for a checked host, in reporting order. */
|
|
111
|
+
export function failingSkills(h: HostSkills): Array<[string, SkillState]> {
|
|
112
|
+
return Object.entries(h.states).filter(([, state]) => state !== "ok") as Array<
|
|
113
|
+
[string, SkillState]
|
|
114
|
+
>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** "darkf-usage differs from bundled" / "darkf-usage missing". */
|
|
118
|
+
export function describeFailure(skill: string, state: SkillState): string {
|
|
119
|
+
return state === "missing" ? `${skill} missing` : `${skill} differs from bundled`;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// The write itself is dir replacement, not a file-by-file merge: copy the
|
|
123
|
+
// bundled dir to a dot-prefixed temp dir inside the skills dir (hosts ignore
|
|
124
|
+
// dot-dirs when listing skills), remove the installed dir, rename the temp
|
|
125
|
+
// into place. The swap is one rename; a crash mid-copy at worst leaves a
|
|
126
|
+
// temp dir that the next sync replaces. The destination is an exact mirror
|
|
127
|
+
// of the bundled dir after every sync.
|
|
128
|
+
const TEMP_PREFIX = ".darkf-tmp-";
|
|
129
|
+
|
|
130
|
+
function copySkill(skillsDir: string, skill: string, bundledDir: string): void {
|
|
131
|
+
const temp = join(skillsDir, `${TEMP_PREFIX}${skill}`);
|
|
132
|
+
rmSync(temp, { recursive: true, force: true });
|
|
133
|
+
cpSync(join(bundledDir, skill), temp, { recursive: true });
|
|
134
|
+
rmSync(join(skillsDir, skill), { recursive: true, force: true });
|
|
135
|
+
renameSync(temp, join(skillsDir, skill));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Dot-prefixed temp dirs are darkf's namespace too — the next sync replaces them. */
|
|
139
|
+
function clearTempDirs(skillsDir: string): void {
|
|
140
|
+
let entries: Dirent[];
|
|
141
|
+
try {
|
|
142
|
+
entries = readdirSync(skillsDir, { withFileTypes: true });
|
|
143
|
+
} catch {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
for (const e of entries) {
|
|
147
|
+
if (e.isDirectory() && e.name.startsWith(TEMP_PREFIX)) {
|
|
148
|
+
rmSync(join(skillsDir, e.name), { recursive: true, force: true });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Sync every bundled darkf-* skill into every detected host: copy when
|
|
155
|
+
* missing, replace when differs, no-op when ok. One host-detection line, then
|
|
156
|
+
* one line per host per skill. An undetected host is skipped without creating
|
|
157
|
+
* anything. Foreign skill dirs (no darkf- prefix) are never read or written.
|
|
158
|
+
* Returns 0 on success; 1 when a present host still ends missing/differs
|
|
159
|
+
* after the sync attempt.
|
|
160
|
+
*/
|
|
161
|
+
export function syncAll(deps: SyncDeps): number {
|
|
162
|
+
const log = deps.log ?? ((line: string) => console.log(line));
|
|
163
|
+
const skills = bundledSkills(deps.bundledDir);
|
|
164
|
+
const width = Math.max(...skills.map((s) => s.length), 0);
|
|
165
|
+
let failed = false;
|
|
166
|
+
for (const host of KNOWN_HOSTS) {
|
|
167
|
+
const dir = join(deps.home, host.dir);
|
|
168
|
+
if (!existsSync(dir) && !deps.existsBinary(host.binary)) {
|
|
169
|
+
log(`host ${host.name} — harness not present`);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
log(`host ${host.name} (~/${host.dir})`);
|
|
173
|
+
try {
|
|
174
|
+
mkdirSync(dir, { recursive: true, mode: 0o755 });
|
|
175
|
+
clearTempDirs(dir);
|
|
176
|
+
for (const skill of skills) {
|
|
177
|
+
const before = skillState(dir, skill, deps.bundledDir);
|
|
178
|
+
let after = before;
|
|
179
|
+
if (before !== "ok") {
|
|
180
|
+
try {
|
|
181
|
+
copySkill(dir, skill, deps.bundledDir);
|
|
182
|
+
after = skillState(dir, skill, deps.bundledDir);
|
|
183
|
+
} catch (err) {
|
|
184
|
+
log(
|
|
185
|
+
` ${skill.padEnd(width)} failed (${err instanceof Error ? err.message : String(err)})`,
|
|
186
|
+
);
|
|
187
|
+
failed = true;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const label =
|
|
192
|
+
after === "ok"
|
|
193
|
+
? before === "missing"
|
|
194
|
+
? "installed"
|
|
195
|
+
: before === "differs"
|
|
196
|
+
? "updated (was stale)"
|
|
197
|
+
: "ok"
|
|
198
|
+
: after;
|
|
199
|
+
if (after !== "ok") failed = true;
|
|
200
|
+
log(` ${skill.padEnd(width)} ${label}`);
|
|
201
|
+
}
|
|
202
|
+
} catch (err) {
|
|
203
|
+
log(` failed (${err instanceof Error ? err.message : String(err)})`);
|
|
204
|
+
failed = true;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return failed ? 1 : 0;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// --- daily probe (spec: Daily probe on first invocation) ---
|
|
211
|
+
|
|
212
|
+
export interface ProbeState {
|
|
213
|
+
lastProbe?: string; // local calendar date YYYY-MM-DD of the last probe attempt
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Absent or corrupt file returns {}. Never throws. */
|
|
217
|
+
export function readProbeState(file: string): ProbeState {
|
|
218
|
+
try {
|
|
219
|
+
const parsed: unknown = JSON.parse(readFileSync(file, "utf8"));
|
|
220
|
+
if (typeof parsed !== "object" || parsed === null) return {};
|
|
221
|
+
const rec = (parsed as Record<string, unknown>).lastProbe;
|
|
222
|
+
return typeof rec === "string" ? { lastProbe: rec } : {};
|
|
223
|
+
} catch {
|
|
224
|
+
return {};
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** mkdir -p on the parent; best-effort — swallow write errors. */
|
|
229
|
+
export function writeProbeState(file: string, state: ProbeState): void {
|
|
230
|
+
writeJsonState(file, state);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** The local calendar date — the day a probe compares against, not UTC. */
|
|
234
|
+
export function todayLocal(now: Date = new Date()): string {
|
|
235
|
+
const y = now.getFullYear();
|
|
236
|
+
const m = String(now.getMonth() + 1).padStart(2, "0");
|
|
237
|
+
const d = String(now.getDate()).padStart(2, "0");
|
|
238
|
+
return `${y}-${m}-${d}`;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* One compact block for the failing harnesses plus the fix hint; null when
|
|
243
|
+
* every present harness is ok (and for absent ones — silent by contract).
|
|
244
|
+
*/
|
|
245
|
+
export function probeBlock(checks: HostSkills[]): string[] | null {
|
|
246
|
+
const lines: string[] = [];
|
|
247
|
+
for (const h of checks) {
|
|
248
|
+
if (!h.present) continue;
|
|
249
|
+
const failing = failingSkills(h).map(([skill, state]) => describeFailure(skill, state));
|
|
250
|
+
if (failing.length > 0) lines.push(`skills (${h.host}): ${failing.join(", ")}`);
|
|
251
|
+
}
|
|
252
|
+
if (lines.length === 0) return null;
|
|
253
|
+
lines.push("fix: run darkf setup");
|
|
254
|
+
return lines;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* The startup path, called from main() after the update gate. First
|
|
259
|
+
* invocation of a local calendar day probes; same-day invocations skip
|
|
260
|
+
* silently. Missing or corrupt state counts as never probed. `setup` and
|
|
261
|
+
* `upgrade` skip the probe and refresh the state file so the next command
|
|
262
|
+
* starts a fresh day window. Never fatal: a slow or erroring probe is
|
|
263
|
+
* swallowed and never changes the invoking command's exit code.
|
|
264
|
+
*/
|
|
265
|
+
export async function skillsProbeGate(cmd: string | undefined, deps: ProbeDeps): Promise<void> {
|
|
266
|
+
const today = deps.today ?? (() => todayLocal());
|
|
267
|
+
const stamp = () => writeProbeState(deps.stateFile, { lastProbe: today() });
|
|
268
|
+
if (cmd === "setup" || cmd === "upgrade") {
|
|
269
|
+
stamp();
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const state = readProbeState(deps.stateFile);
|
|
273
|
+
if (state.lastProbe === today()) return;
|
|
274
|
+
try {
|
|
275
|
+
const block = probeBlock(skillsCheck(deps));
|
|
276
|
+
if (block) for (const line of block) (deps.log ?? console.log)(line);
|
|
277
|
+
} catch {
|
|
278
|
+
// swallowed — today's run matters more than the report
|
|
279
|
+
}
|
|
280
|
+
stamp();
|
|
281
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
|
|
4
|
+
/** mkdir -p on the parent; best-effort — swallow write errors. Shared by
|
|
5
|
+
* `setup.ts`'s probe state and `update.ts`'s update-check state; both
|
|
6
|
+
* degrade to re-running next invocation when the location is unwritable. */
|
|
7
|
+
export function writeJsonState<T>(file: string, state: T): void {
|
|
8
|
+
try {
|
|
9
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
10
|
+
writeFileSync(file, JSON.stringify(state));
|
|
11
|
+
} catch {
|
|
12
|
+
// An unwritable state location degrades to re-probing/re-checking next invocation.
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
import { todayLocal, writeProbeState } from "./setup.ts";
|
|
6
|
+
|
|
7
|
+
// Tarball smoke test (skill-setup spec: Testing): npm pack the package, then
|
|
8
|
+
// install the tarball into a temp prefix and run the installed CLI — proving
|
|
9
|
+
// the files allowlist ships every runtime dir (src, workflows, skills, docs)
|
|
10
|
+
// and nothing the CLI reads was dropped. Skipped when npm is absent.
|
|
11
|
+
|
|
12
|
+
const pkgDir = resolve(import.meta.dir, "..", "..");
|
|
13
|
+
|
|
14
|
+
test("tarball smoke: allowlist ships the runtime dirs and the installed CLI works", async () => {
|
|
15
|
+
const npm = Bun.which("npm");
|
|
16
|
+
if (!npm) {
|
|
17
|
+
console.warn("npm not on PATH — skipping tarball smoke test");
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const root = mkdtempSync(join(tmpdir(), "darkf-tarball-"));
|
|
22
|
+
try {
|
|
23
|
+
// Pack and inspect the tarball's contents.
|
|
24
|
+
const pack = Bun.spawnSync([npm, "pack", "--json", "--pack-destination", root], {
|
|
25
|
+
cwd: pkgDir,
|
|
26
|
+
stdout: "pipe",
|
|
27
|
+
stderr: "pipe",
|
|
28
|
+
});
|
|
29
|
+
expect(pack.exitCode).toBe(0);
|
|
30
|
+
const filename = (
|
|
31
|
+
JSON.parse(new TextDecoder().decode(pack.stdout)) as Array<{ filename: string }>
|
|
32
|
+
)[0]?.filename;
|
|
33
|
+
expect(filename).toBeTruthy();
|
|
34
|
+
const tgz = join(root, filename!);
|
|
35
|
+
const list = Bun.spawnSync(["tar", "-tzf", tgz], { stdout: "pipe", stderr: "pipe" });
|
|
36
|
+
expect(list.exitCode).toBe(0);
|
|
37
|
+
const entries = new TextDecoder()
|
|
38
|
+
.decode(list.stdout)
|
|
39
|
+
.split("\n")
|
|
40
|
+
.filter((l) => l.startsWith("package/"));
|
|
41
|
+
const top = new Set(entries.map((l) => l.split("/")[1]).filter(Boolean));
|
|
42
|
+
// Exactly the allowlist plus the auto-included package.json and README.
|
|
43
|
+
expect(top).toEqual(
|
|
44
|
+
new Set(["README.md", "docs", "package.json", "skills", "src", "workflows"]),
|
|
45
|
+
);
|
|
46
|
+
const all = entries.join("\n");
|
|
47
|
+
expect(all).not.toContain("package/examples/");
|
|
48
|
+
expect(all).not.toContain("bunfig.toml");
|
|
49
|
+
expect(all).not.toContain("tsconfig.json");
|
|
50
|
+
expect(all).not.toContain("package/feedback/");
|
|
51
|
+
|
|
52
|
+
// Install into a temp prefix — the offline global-install shape.
|
|
53
|
+
const prefix = join(root, "prefix");
|
|
54
|
+
const install = Bun.spawnSync(
|
|
55
|
+
[npm, "install", "-g", "--prefix", prefix, "--no-audit", "--no-fund", tgz],
|
|
56
|
+
{ stdout: "pipe", stderr: "pipe" },
|
|
57
|
+
);
|
|
58
|
+
expect(install.exitCode).toBe(0);
|
|
59
|
+
const libRoot = join(prefix, "lib", "node_modules", "@psimona", "darkf");
|
|
60
|
+
expect(existsSync(join(libRoot, "src", "cli", "index.ts"))).toBe(true);
|
|
61
|
+
expect(existsSync(join(prefix, "bin", "darkf"))).toBe(true);
|
|
62
|
+
|
|
63
|
+
// Temp HOME and state; the probe stamped so its block stays out of the way.
|
|
64
|
+
// The home carries a .claude/skills dir so host detection works by dir
|
|
65
|
+
// alone — CI runners have no claude binary on PATH.
|
|
66
|
+
const home = join(root, "home");
|
|
67
|
+
mkdirSync(join(home, ".claude", "skills"), { recursive: true });
|
|
68
|
+
const stateHome = join(root, "state");
|
|
69
|
+
mkdirSync(stateHome, { recursive: true });
|
|
70
|
+
writeProbeState(join(stateHome, "darkf", "last-skills-check.json"), {
|
|
71
|
+
lastProbe: todayLocal(),
|
|
72
|
+
});
|
|
73
|
+
const env = {
|
|
74
|
+
...process.env,
|
|
75
|
+
HOME: home,
|
|
76
|
+
XDG_STATE_HOME: stateHome,
|
|
77
|
+
DARKF_NO_UPDATE_CHECK: "1",
|
|
78
|
+
};
|
|
79
|
+
const runBin = (args: string[]) => {
|
|
80
|
+
const proc = Bun.spawnSync(
|
|
81
|
+
[process.execPath, join(libRoot, "src", "cli", "index.ts"), ...args],
|
|
82
|
+
{
|
|
83
|
+
cwd: root,
|
|
84
|
+
stdout: "pipe",
|
|
85
|
+
stderr: "pipe",
|
|
86
|
+
env,
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
return {
|
|
90
|
+
code: proc.exitCode,
|
|
91
|
+
out: new TextDecoder().decode(proc.stdout),
|
|
92
|
+
err: new TextDecoder().decode(proc.stderr),
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// `setup` installs both skills into a detected host.
|
|
97
|
+
const setup = runBin(["setup"]);
|
|
98
|
+
expect(setup.code).toBe(0);
|
|
99
|
+
expect(setup.out).toContain("host claude (~/.claude/skills)");
|
|
100
|
+
expect(existsSync(join(home, ".claude", "skills", "darkf-usage", "SKILL.md"))).toBe(true);
|
|
101
|
+
expect(existsSync(join(home, ".claude", "skills", "darkf-writing-workflows", "SKILL.md"))).toBe(
|
|
102
|
+
true,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
// `doctor` renders the skills section from the installed package's bundle.
|
|
106
|
+
const doctor = runBin(["doctor"]);
|
|
107
|
+
expect(doctor.out).toContain("skills (claude) — 2/2 installed");
|
|
108
|
+
|
|
109
|
+
// `render` loads a built-in workflow from the packaged workflows/.
|
|
110
|
+
const render = runBin(["render", "series-ordering"]);
|
|
111
|
+
expect(render.code).toBe(0);
|
|
112
|
+
expect(render.out).toContain("stateDiagram-v2");
|
|
113
|
+
|
|
114
|
+
// Every skill-referenced docs path resolves inside the installed package,
|
|
115
|
+
// offline — the deep-reference pointers work for a global install.
|
|
116
|
+
for (const skill of ["darkf-usage", "darkf-writing-workflows"]) {
|
|
117
|
+
const text = readFileSync(join(libRoot, "skills", skill, "SKILL.md"), "utf8");
|
|
118
|
+
const refs = [...text.matchAll(/docs\/[A-Za-z0-9][A-Za-z0-9/._-]*\.md/g)].map((m) => m[0]!);
|
|
119
|
+
expect(refs.length).toBeGreaterThan(0);
|
|
120
|
+
for (const ref of refs) {
|
|
121
|
+
expect(existsSync(join(libRoot, ref))).toBe(true);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
} finally {
|
|
125
|
+
rmSync(root, { recursive: true, force: true });
|
|
126
|
+
}
|
|
127
|
+
}, 240_000);
|
package/src/cli/update.test.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { afterAll, expect, test } from "bun:test";
|
|
|
2
2
|
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
import type { SkillsDeps } from "./setup.ts";
|
|
5
6
|
import {
|
|
6
7
|
checkRegistry,
|
|
7
8
|
isDue,
|
|
@@ -10,6 +11,7 @@ import {
|
|
|
10
11
|
type UpdateDeps,
|
|
11
12
|
updateGate,
|
|
12
13
|
upgradeCmd,
|
|
14
|
+
upgradeWithSkills,
|
|
13
15
|
writeState,
|
|
14
16
|
} from "./update.ts";
|
|
15
17
|
|
|
@@ -484,3 +486,83 @@ test("real CLI with a fresh not-due record: the notice is the first stdout line,
|
|
|
484
486
|
`darkf 99.0.0 available (installed ${installedVersion}) — run 'darkf upgrade'`,
|
|
485
487
|
);
|
|
486
488
|
});
|
|
489
|
+
|
|
490
|
+
// --- upgrade + skills sync (skill-setup spec) ---
|
|
491
|
+
|
|
492
|
+
const SKILL_BUNDLED = "bundled skill body\n";
|
|
493
|
+
const SKILL_STALE = "a stale installed copy\n";
|
|
494
|
+
|
|
495
|
+
/** Fixture skills bundle + a home with a stale claude copy installed. */
|
|
496
|
+
function skillsFixture(): { skills: SkillsDeps; installed: string } {
|
|
497
|
+
const bundledDir = tempDir();
|
|
498
|
+
mkdirSync(join(bundledDir, "darkf-usage"), { recursive: true });
|
|
499
|
+
writeFileSync(join(bundledDir, "darkf-usage", "SKILL.md"), SKILL_BUNDLED);
|
|
500
|
+
const home = tempDir();
|
|
501
|
+
const installed = join(home, ".claude", "skills", "darkf-usage", "SKILL.md");
|
|
502
|
+
mkdirSync(dirname(installed), { recursive: true });
|
|
503
|
+
writeFileSync(installed, SKILL_STALE);
|
|
504
|
+
return {
|
|
505
|
+
installed,
|
|
506
|
+
skills: { home, bundledDir, existsBinary: () => false },
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
test("upgrade runs the sync after the install, under the skills: header", async () => {
|
|
511
|
+
const file = tempStateFile();
|
|
512
|
+
const { skills, installed } = skillsFixture();
|
|
513
|
+
const { spawnImpl } = spawnStub((cmd) => {
|
|
514
|
+
if (cmd[1] === "pm") return { exitCode: 0, stdout: "└── @psimona/darkf@0.3.0" };
|
|
515
|
+
if (cmd[1] === "install") return { exitCode: 0 };
|
|
516
|
+
return undefined;
|
|
517
|
+
});
|
|
518
|
+
const { fetchImpl } = fetchReturning('{"latest":"9.9.9"}');
|
|
519
|
+
|
|
520
|
+
const { result, out } = await captured(() =>
|
|
521
|
+
upgradeWithSkills(deps({ stateFile: file, spawnImpl, fetchImpl }), skills),
|
|
522
|
+
);
|
|
523
|
+
|
|
524
|
+
expect(result).toBe(0);
|
|
525
|
+
const skillsIdx = out.indexOf("skills:");
|
|
526
|
+
expect(skillsIdx).toBeGreaterThanOrEqual(0);
|
|
527
|
+
expect(out.slice(skillsIdx).some((l) => l.includes("updated (was stale)"))).toBe(true);
|
|
528
|
+
expect(readFileSync(installed, "utf8")).toBe(SKILL_BUNDLED); // stale copy replaced
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
test("a failed upgrade skips the sync — never a skills: block, stale copy untouched", async () => {
|
|
532
|
+
const { skills, installed } = skillsFixture();
|
|
533
|
+
const { spawnImpl } = spawnStub((cmd) => {
|
|
534
|
+
if (cmd[1] === "pm") return { exitCode: 0, stdout: "└── @psimona/darkf@0.3.0" };
|
|
535
|
+
if (cmd[1] === "install") return { exitCode: 7 };
|
|
536
|
+
return undefined;
|
|
537
|
+
});
|
|
538
|
+
const { fetchImpl } = fetchReturning('{"latest":"9.9.9"}');
|
|
539
|
+
|
|
540
|
+
const { result, out } = await captured(() =>
|
|
541
|
+
upgradeWithSkills(deps({ spawnImpl, fetchImpl }), skills),
|
|
542
|
+
);
|
|
543
|
+
|
|
544
|
+
expect(result).toBe(7); // the upgrade's own exit code, unmasked
|
|
545
|
+
expect(out).not.toContain("skills:");
|
|
546
|
+
expect(readFileSync(installed, "utf8")).toBe(SKILL_STALE);
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
test("a sync failure after a good upgrade is reported and exits non-zero", async () => {
|
|
550
|
+
const { skills } = skillsFixture();
|
|
551
|
+
// The claude skills "dir" is a file — the sync cannot write.
|
|
552
|
+
rmSync(join(skills.home, ".claude", "skills"), { recursive: true });
|
|
553
|
+
writeFileSync(join(skills.home, ".claude", "skills"), "a file, not a dir");
|
|
554
|
+
const { spawnImpl } = spawnStub((cmd) => {
|
|
555
|
+
if (cmd[1] === "pm") return { exitCode: 0, stdout: "└── @psimona/darkf@0.3.0" };
|
|
556
|
+
if (cmd[1] === "install") return { exitCode: 0 };
|
|
557
|
+
return undefined;
|
|
558
|
+
});
|
|
559
|
+
const { fetchImpl } = fetchReturning('{"latest":"9.9.9"}');
|
|
560
|
+
|
|
561
|
+
const { result, out, err } = await captured(() =>
|
|
562
|
+
upgradeWithSkills(deps({ spawnImpl, fetchImpl }), skills),
|
|
563
|
+
);
|
|
564
|
+
|
|
565
|
+
expect(result).toBe(1); // best-effort: reported, non-zero, upgrade unmasked
|
|
566
|
+
expect(out).toContain("skills:");
|
|
567
|
+
expect(err.join("\n")).not.toContain("skills"); // the failure is in the sync lines, not stderr noise
|
|
568
|
+
});
|
package/src/cli/update.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
// CLI self-update (docs/specs/self-update): a daily startup version check and
|
|
1
|
+
// CLI self-update (docs/specs/_built/self-update): a daily startup version check and
|
|
2
2
|
// the `darkf upgrade` command. Every dependency arrives via UpdateDeps, so the
|
|
3
3
|
// whole module runs in tests without network, a real clock, or a real package
|
|
4
4
|
// manager. No module-level mutable state.
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
6
|
+
import { type SkillsDeps, syncAll } from "./setup.ts";
|
|
7
|
+
import { writeJsonState } from "./state-file.ts";
|
|
7
8
|
|
|
8
9
|
const PACKAGE_SPEC = "@psimona/darkf";
|
|
9
10
|
const REGISTRY_URL = "https://registry.npmjs.org/-/package/@psimona%2Fdarkf/dist-tags";
|
|
@@ -46,12 +47,7 @@ export function readState(file: string): UpdateState {
|
|
|
46
47
|
|
|
47
48
|
/** mkdir -p on the parent; best-effort — swallow write errors (REQ-4). */
|
|
48
49
|
export function writeState(file: string, state: UpdateState): void {
|
|
49
|
-
|
|
50
|
-
mkdirSync(dirname(file), { recursive: true });
|
|
51
|
-
writeFileSync(file, JSON.stringify(state));
|
|
52
|
-
} catch {
|
|
53
|
-
// An unwritable state location degrades to re-checking next invocation.
|
|
54
|
-
}
|
|
50
|
+
writeJsonState(file, state);
|
|
55
51
|
}
|
|
56
52
|
|
|
57
53
|
/** True when lastCheck is missing, unparseable, or older than 24 h. */
|
|
@@ -189,3 +185,22 @@ export async function upgradeCmd(deps: UpdateDeps): Promise<number> {
|
|
|
189
185
|
}
|
|
190
186
|
return code;
|
|
191
187
|
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* `darkf upgrade` end-to-end (skill-setup spec): install the new package
|
|
191
|
+
* version, then sync the skills it now ships — after the install, the
|
|
192
|
+
* running process resolves the new bundled copies on disk, so skills can
|
|
193
|
+
* never be stale relative to the engine they teach. Same code path as
|
|
194
|
+
* `darkf setup`. Best-effort: a sync failure is reported and exits non-zero,
|
|
195
|
+
* but never masks the upgrade's own exit code.
|
|
196
|
+
*/
|
|
197
|
+
export async function upgradeWithSkills(
|
|
198
|
+
update: UpdateDeps,
|
|
199
|
+
skills: SkillsDeps,
|
|
200
|
+
log: (line: string) => void = console.log,
|
|
201
|
+
): Promise<number> {
|
|
202
|
+
const code = await upgradeCmd(update);
|
|
203
|
+
if (code !== 0) return code;
|
|
204
|
+
log("skills:");
|
|
205
|
+
return syncAll({ ...skills, log });
|
|
206
|
+
}
|
package/src/core/tasks.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Task, TaskList, TaskPriority, TaskRequirement, TaskStatus } from "./types.ts";
|
|
2
2
|
|
|
3
|
-
// Hand-written narrowing of unknown JSON to a TaskList (docs/specs/task-list-json/spec.md,
|
|
3
|
+
// Hand-written narrowing of unknown JSON to a TaskList (docs/specs/_built/task-list-json/spec.md,
|
|
4
4
|
// Decisions: Validation) — zero deps, no dual-schema tolerance: the legacy
|
|
5
5
|
// names (`moscow`, task-side `requirements`) are simply not read, and the
|
|
6
6
|
// result is either a TaskList or `{ error }`. The item-loop path and the
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { isNodeResult } from "./types.ts";
|
|
3
|
+
|
|
4
|
+
describe("isNodeResult", () => {
|
|
5
|
+
test("accepts the full envelope: typed event, output, agentSessionId", () => {
|
|
6
|
+
expect(isNodeResult({ event: "done", output: { ok: true }, agentSessionId: "ses_1" })).toBe(
|
|
7
|
+
true,
|
|
8
|
+
);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("accepts a bare object with no fields at all — everything is optional", () => {
|
|
12
|
+
expect(isNodeResult({})).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("accepts partial envelopes: event only, output only, agentSessionId only", () => {
|
|
16
|
+
expect(isNodeResult({ event: "planned" })).toBe(true);
|
|
17
|
+
expect(isNodeResult({ output: [1, 2, 3] })).toBe(true);
|
|
18
|
+
expect(isNodeResult({ agentSessionId: "ses_abc" })).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("accepts extra fields — the check is non-strict", () => {
|
|
22
|
+
expect(isNodeResult({ event: "done", agentSessionId: "ses_1", extra: "ignored" })).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("rejects null", () => {
|
|
26
|
+
expect(isNodeResult(null)).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("rejects other non-object values", () => {
|
|
30
|
+
expect(isNodeResult(undefined)).toBe(false);
|
|
31
|
+
expect(isNodeResult("done")).toBe(false);
|
|
32
|
+
expect(isNodeResult(42)).toBe(false);
|
|
33
|
+
expect(isNodeResult(true)).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("rejects a wrong-typed event", () => {
|
|
37
|
+
expect(isNodeResult({ event: 7 })).toBe(false);
|
|
38
|
+
expect(isNodeResult({ event: null })).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("rejects a wrong-typed agentSessionId", () => {
|
|
42
|
+
expect(isNodeResult({ agentSessionId: 42 })).toBe(false);
|
|
43
|
+
expect(isNodeResult({ agentSessionId: null })).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("rejects an array — new behavior; the hand-rolled check let it through", () => {
|
|
47
|
+
expect(isNodeResult(["done"])).toBe(false);
|
|
48
|
+
expect(isNodeResult([])).toBe(false);
|
|
49
|
+
// An array carrying the right keys on its elements still is not a NodeResult.
|
|
50
|
+
expect(isNodeResult([{ event: "done", agentSessionId: "ses_1" }])).toBe(false);
|
|
51
|
+
});
|
|
52
|
+
});
|