@psimona/darkf 0.9.0 → 0.10.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/reference/cli-commands.md +17 -0
- package/package.json +1 -1
- package/skills/darkf-writing-workflows/SKILL.md +2 -2
- package/src/cli/changelog.test.ts +44 -0
- package/src/cli/changelog.ts +26 -0
- package/src/cli/detached.test.ts +19 -1
- package/src/cli/doctor.test.ts +59 -0
- package/src/cli/help.test.ts +92 -0
- package/src/cli/help.ts +164 -0
- package/src/cli/index.ts +117 -3
- package/src/cli/update.test.ts +85 -17
- package/src/cli/update.ts +41 -7
- package/src/core/graph.test.ts +1 -1
- package/src/core/graph.ts +1 -1
- package/src/core/types.ts +21 -1
- package/src/engine/identity-guard.test.ts +47 -0
- package/src/engine/run.test.ts +90 -3
- package/src/engine/run.ts +4 -4
- package/src/kit/agents/handoff.ts +1 -1
- package/src/kit/registry.ts +5 -0
- package/src/kit/specs.test.ts +2 -2
- package/src/kit/specs.ts +3 -6
- package/src/test/ok-output.ts +1 -1
- package/workflows/dev-loop/output-types.ts +1 -1
- package/workflows/dev-loop/scripts/dispatch.ts +3 -5
- package/workflows/dev-loop/workflow.ts +8 -10
- package/workflows/series-ordering/output-types.ts +1 -1
package/src/cli/index.ts
CHANGED
|
@@ -51,6 +51,8 @@ import {
|
|
|
51
51
|
stallWarning,
|
|
52
52
|
type TerminalState,
|
|
53
53
|
} from "../kit/status.ts";
|
|
54
|
+
import { changelogHead } from "./changelog.ts";
|
|
55
|
+
import { resolveHelp } from "./help.ts";
|
|
54
56
|
import {
|
|
55
57
|
describeFailure,
|
|
56
58
|
failingSkills,
|
|
@@ -60,7 +62,7 @@ import {
|
|
|
60
62
|
skillsProbeGate,
|
|
61
63
|
syncAll,
|
|
62
64
|
} from "./setup.ts";
|
|
63
|
-
import { type UpdateDeps, updateGate, upgradeWithSkills } from "./update.ts";
|
|
65
|
+
import { readState, type UpdateDeps, updateGate, upgradeWithSkills } from "./update.ts";
|
|
64
66
|
|
|
65
67
|
const INDEX_PATH = fileURLToPath(import.meta.url);
|
|
66
68
|
// Fixed, not yet measured against a cold `bun` import on real hosts — see
|
|
@@ -178,6 +180,7 @@ async function reportCmd(args: string[]): Promise<void> {
|
|
|
178
180
|
const seconds = (ms: number) => `${(ms / 1000).toFixed(1)}s`;
|
|
179
181
|
console.log(`run: ${entry.runId}`);
|
|
180
182
|
console.log(`message: ${entry.message ?? "(none)"}`);
|
|
183
|
+
if (entry.engineVersion) console.log(`engine: ${entry.engineVersion}`);
|
|
181
184
|
console.log(`span: ${seconds(report.spanMs)}, ${report.dispatches.length} dispatches`);
|
|
182
185
|
const visits = Object.entries(report.visits);
|
|
183
186
|
if (visits.length) console.log(`visits: ${JSON.stringify(Object.fromEntries(visits))}`);
|
|
@@ -444,9 +447,65 @@ function doctorCmd(args: string[]): number {
|
|
|
444
447
|
}
|
|
445
448
|
}
|
|
446
449
|
|
|
450
|
+
// 4. version skew (self-update 2026-12-05): this CLI vs the @psimona/darkf
|
|
451
|
+
// this repo resolves, vs the newest release the update gate has recorded.
|
|
452
|
+
// The workflow code imports the project copy while the engine executing it
|
|
453
|
+
// is this CLI — a minor-version drift between them means validate and the
|
|
454
|
+
// run can disagree about structure rules. Offline: the published-newest
|
|
455
|
+
// side reads the recorded `latestSeen`, never the network.
|
|
456
|
+
const { installed, latestSeen } = updateVersions();
|
|
457
|
+
const published =
|
|
458
|
+
latestSeen !== undefined && Bun.semver.order(installed, latestSeen) < 0
|
|
459
|
+
? `, published ${latestSeen} available — run: darkf upgrade`
|
|
460
|
+
: "";
|
|
461
|
+
const depVersion = readProjectDarkfVersion(projectRoot());
|
|
462
|
+
if (depVersion === undefined) {
|
|
463
|
+
check(
|
|
464
|
+
"darkf version skew",
|
|
465
|
+
true,
|
|
466
|
+
`engine ${installed}${published ? `${published}, no @psimona/darkf dependency here` : " current, no @psimona/darkf dependency here"}`,
|
|
467
|
+
);
|
|
468
|
+
} else {
|
|
469
|
+
const skew = skewBetween(installed, depVersion);
|
|
470
|
+
const detail = `engine ${installed}, dependency ${depVersion}${published}`;
|
|
471
|
+
check(
|
|
472
|
+
"darkf version skew",
|
|
473
|
+
skew === undefined,
|
|
474
|
+
skew === undefined ? detail : `${detail} — ${skew}`,
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
|
|
447
478
|
return failed() ? 1 : 0;
|
|
448
479
|
}
|
|
449
480
|
|
|
481
|
+
/** The version of the @psimona/darkf this repo resolves, or undefined when
|
|
482
|
+
* there is none (or its package.json is unreadable). */
|
|
483
|
+
function readProjectDarkfVersion(root: string): string | undefined {
|
|
484
|
+
try {
|
|
485
|
+
const pkg = JSON.parse(
|
|
486
|
+
readFileSync(join(root, "node_modules", "@psimona", "darkf", "package.json"), "utf8"),
|
|
487
|
+
) as { version?: unknown };
|
|
488
|
+
return typeof pkg.version === "string" ? pkg.version : undefined;
|
|
489
|
+
} catch {
|
|
490
|
+
return undefined;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/** The engine's own version and the newest recorded published release. */
|
|
495
|
+
function updateVersions(): { installed: string; latestSeen?: string } {
|
|
496
|
+
return {
|
|
497
|
+
installed: packageJson.version,
|
|
498
|
+
latestSeen: readState(updateStateFile()).latestSeen,
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/** Why the engine and the dependency versions disagree, or undefined when
|
|
503
|
+
* they agree on major.minor (patch drift is normal under a caret range). */
|
|
504
|
+
function skewBetween(engine: string, dep: string): string | undefined {
|
|
505
|
+
const mm = (v: string) => v.split(".").slice(0, 2).join(".");
|
|
506
|
+
return mm(engine) === mm(dep) ? undefined : "engine and dependency minor versions drift";
|
|
507
|
+
}
|
|
508
|
+
|
|
450
509
|
function workflowsCmd(): void {
|
|
451
510
|
const workflows = listWorkflows();
|
|
452
511
|
if (workflows.length === 0) {
|
|
@@ -458,6 +517,20 @@ function workflowsCmd(): void {
|
|
|
458
517
|
for (const w of workflows) console.log(`${w.name.padEnd(24)} ${w.source}`);
|
|
459
518
|
}
|
|
460
519
|
|
|
520
|
+
/** The newest section of the installed package's changelog — the answer the
|
|
521
|
+
* upgrade notice points at. Read-only; a missing file prints one line, it
|
|
522
|
+
* never fails the command. */
|
|
523
|
+
function changelogCmd(): void {
|
|
524
|
+
let text: string;
|
|
525
|
+
try {
|
|
526
|
+
text = readFileSync(installedChangelogPath(), "utf8");
|
|
527
|
+
} catch {
|
|
528
|
+
console.log(`no changelog found at ${installedChangelogPath()}`);
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
console.log(changelogHead(text));
|
|
532
|
+
}
|
|
533
|
+
|
|
461
534
|
async function renderCmd(dir: string): Promise<void> {
|
|
462
535
|
const { workflow } = await loadWorkflow(dir);
|
|
463
536
|
console.log(renderMermaid(workflow));
|
|
@@ -533,6 +606,7 @@ async function runCmd(dir: string, message?: string): Promise<void> {
|
|
|
533
606
|
status: "running",
|
|
534
607
|
finishedAt: null,
|
|
535
608
|
agentRunnerKind: agentRunner?.kind,
|
|
609
|
+
engineVersion: packageJson.version,
|
|
536
610
|
...detectSupervisorSignal(),
|
|
537
611
|
});
|
|
538
612
|
|
|
@@ -669,6 +743,7 @@ async function startCmd(
|
|
|
669
743
|
finishedAt: Date.now(),
|
|
670
744
|
startFailureDetail: tail,
|
|
671
745
|
bootId,
|
|
746
|
+
engineVersion: packageJson.version,
|
|
672
747
|
...detectSupervisorSignal(),
|
|
673
748
|
});
|
|
674
749
|
return 1;
|
|
@@ -698,6 +773,7 @@ async function startCmd(
|
|
|
698
773
|
status: "running",
|
|
699
774
|
finishedAt: null,
|
|
700
775
|
bootId,
|
|
776
|
+
engineVersion: packageJson.version,
|
|
701
777
|
...detectSupervisorSignal(),
|
|
702
778
|
});
|
|
703
779
|
|
|
@@ -801,6 +877,7 @@ function printDigest(entry: RegistryEntry, state: TerminalState, journalText: st
|
|
|
801
877
|
console.log(`run: ${entry.runId}`);
|
|
802
878
|
console.log(`root: ${entry.rootDir}`);
|
|
803
879
|
if (entry.message) console.log(`message: ${entry.message}`);
|
|
880
|
+
if (entry.engineVersion) console.log(`engine: ${entry.engineVersion}`);
|
|
804
881
|
console.log(`state: ${state}`);
|
|
805
882
|
if (digest.current) {
|
|
806
883
|
console.log(`current node: ${digest.current.state} (${digest.current.phase})`);
|
|
@@ -1127,6 +1204,21 @@ function updateStateFile(): string {
|
|
|
1127
1204
|
return join(process.env.HOME ?? "", ".local", "state", "darkf", "last-update-check.json");
|
|
1128
1205
|
}
|
|
1129
1206
|
|
|
1207
|
+
// The update cadence tunable (self-update 2026-12-05): XDG config semantics —
|
|
1208
|
+
// `~/.config/darkf/config.json`, `{"checkIntervalHours": 24}` restores the
|
|
1209
|
+
// once-per-interval check for hosts that must not pay a registry request per
|
|
1210
|
+
// command. Absent file = check every invocation.
|
|
1211
|
+
function updateConfigFile(): string {
|
|
1212
|
+
const xdg = process.env.XDG_CONFIG_HOME;
|
|
1213
|
+
if (xdg) return join(xdg, "darkf", "config.json");
|
|
1214
|
+
return join(process.env.HOME ?? "", ".config", "darkf", "config.json");
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
// The installed package's own changelog, for `darkf changelog`.
|
|
1218
|
+
function installedChangelogPath(): string {
|
|
1219
|
+
return resolve(dirname(INDEX_PATH), "..", "..", "CHANGELOG.md");
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1130
1222
|
// Same XDG state scheme, for the daily skills probe (skill-setup spec).
|
|
1131
1223
|
function skillsProbeStateFile(): string {
|
|
1132
1224
|
const xdg = process.env.XDG_STATE_HOME;
|
|
@@ -1152,6 +1244,15 @@ function probeDeps(): ProbeDeps {
|
|
|
1152
1244
|
async function main(): Promise<void> {
|
|
1153
1245
|
const [cmd, ...rest] = process.argv.slice(2);
|
|
1154
1246
|
|
|
1247
|
+
// Help (docs/specs/_built/cli-help/spec.md): answered before the gates below, so
|
|
1248
|
+
// it stays offline and writes no state (REQ-4).
|
|
1249
|
+
const help = resolveHelp(process.argv.slice(2));
|
|
1250
|
+
if (help) {
|
|
1251
|
+
if (help.stdout) process.stdout.write(help.stdout);
|
|
1252
|
+
if (help.stderr) process.stderr.write(help.stderr);
|
|
1253
|
+
process.exit(help.code);
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1155
1256
|
// Self-update gate (REQ-1..REQ-5, REQ-11): runs before every dispatch, so
|
|
1156
1257
|
// its notice is the first line of stdout (NFR-3). The gate itself skips
|
|
1157
1258
|
// `upgrade`, which fetches on its own. Silent by contract (REQ-4).
|
|
@@ -1160,6 +1261,7 @@ async function main(): Promise<void> {
|
|
|
1160
1261
|
fetchImpl: fetch,
|
|
1161
1262
|
spawnImpl: Bun.spawnSync,
|
|
1162
1263
|
stateFile: updateStateFile(),
|
|
1264
|
+
configFile: updateConfigFile(),
|
|
1163
1265
|
installed: packageJson.version,
|
|
1164
1266
|
};
|
|
1165
1267
|
await updateGate(cmd, updateDeps);
|
|
@@ -1186,6 +1288,10 @@ async function main(): Promise<void> {
|
|
|
1186
1288
|
workflowsCmd();
|
|
1187
1289
|
return;
|
|
1188
1290
|
}
|
|
1291
|
+
if (cmd === "changelog") {
|
|
1292
|
+
changelogCmd();
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1189
1295
|
if (cmd === "report") {
|
|
1190
1296
|
await reportCmd(rest);
|
|
1191
1297
|
return;
|
|
@@ -1224,8 +1330,16 @@ async function main(): Promise<void> {
|
|
|
1224
1330
|
await workerCmd(rest[0] ?? ".", rest[1] ?? "", rest[2]);
|
|
1225
1331
|
return;
|
|
1226
1332
|
}
|
|
1227
|
-
//
|
|
1228
|
-
|
|
1333
|
+
// A bare `darkf` keeps running the workflow in the current directory.
|
|
1334
|
+
// Any other unknown word is not a workflow reference: `darkf run` is the
|
|
1335
|
+
// only way to run one.
|
|
1336
|
+
if (cmd === undefined) {
|
|
1337
|
+
await runCmd(resolveWorkflowDir("."), undefined);
|
|
1338
|
+
return;
|
|
1339
|
+
}
|
|
1340
|
+
console.error(`darkf: unknown command '${cmd}'. To run a workflow: darkf run ${cmd}`);
|
|
1341
|
+
console.error(" list the commands: darkf --help");
|
|
1342
|
+
process.exit(2);
|
|
1229
1343
|
}
|
|
1230
1344
|
|
|
1231
1345
|
// Dispatch only when this file is the process entry point — the `darkf` bin,
|
package/src/cli/update.test.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
isDue,
|
|
9
9
|
isNewer,
|
|
10
10
|
readState,
|
|
11
|
+
readUpdateConfig,
|
|
11
12
|
type UpdateDeps,
|
|
12
13
|
updateGate,
|
|
13
14
|
upgradeCmd,
|
|
@@ -21,6 +22,10 @@ const NOW = 1_793_000_000_000; // fixed epoch ms; every test's "today"
|
|
|
21
22
|
const INSTALLED = "0.3.0";
|
|
22
23
|
const HOUR_MS = 60 * 60 * 1000;
|
|
23
24
|
|
|
25
|
+
// The one notice line (REQ-3), with the changelog pointer (2026-12-05).
|
|
26
|
+
const NOTICE = (latest: string) =>
|
|
27
|
+
`darkf ${latest} available (installed ${INSTALLED}) — run 'darkf upgrade'; 'darkf changelog' shows what changed`;
|
|
28
|
+
|
|
24
29
|
const roots: string[] = [];
|
|
25
30
|
afterAll(() => {
|
|
26
31
|
for (const root of roots) rmSync(root, { recursive: true, force: true });
|
|
@@ -60,11 +65,17 @@ function deps(overrides: Partial<UpdateDeps> = {}): UpdateDeps {
|
|
|
60
65
|
throw new Error("unexpected spawn");
|
|
61
66
|
}) as unknown as typeof Bun.spawnSync,
|
|
62
67
|
stateFile: tempStateFile(),
|
|
68
|
+
configFile: join(tempDir(), "config", "darkf", "config.json"), // absent by default
|
|
63
69
|
installed: INSTALLED,
|
|
64
70
|
...overrides,
|
|
65
71
|
};
|
|
66
72
|
}
|
|
67
73
|
|
|
74
|
+
function seedConfig(file: string, body: string): void {
|
|
75
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
76
|
+
writeFileSync(file, body);
|
|
77
|
+
}
|
|
78
|
+
|
|
68
79
|
/** 200-with-body fetch unless a status is given; records the requested URLs. */
|
|
69
80
|
function fetchReturning(body: string, status = 200): { fetchImpl: typeof fetch; urls: string[] } {
|
|
70
81
|
const urls: string[] = [];
|
|
@@ -158,13 +169,43 @@ test("isNewer: older, equal, newer, prerelease", () => {
|
|
|
158
169
|
expect(isNewer("0.3.0", "0.4.0-beta.1")).toBe(true);
|
|
159
170
|
});
|
|
160
171
|
|
|
161
|
-
test("isDue:
|
|
172
|
+
test("isDue: no interval (default config) — every invocation is due", () => {
|
|
162
173
|
expect(isDue({}, NOW)).toBe(true);
|
|
163
|
-
|
|
164
|
-
expect(isDue(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
174
|
+
const fresh = { lastCheck: new Date(NOW - 1000).toISOString() };
|
|
175
|
+
expect(isDue(fresh, NOW)).toBe(true);
|
|
176
|
+
expect(isDue(fresh, NOW, 0)).toBe(true);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test("isDue: with a configured interval, the 24h boundary governs", () => {
|
|
180
|
+
const day = 24 * HOUR_MS * 1000;
|
|
181
|
+
expect(isDue({}, NOW, day)).toBe(true);
|
|
182
|
+
expect(isDue({ lastCheck: "not a timestamp" }, NOW, day)).toBe(true);
|
|
183
|
+
expect(isDue({ lastCheck: new Date(NOW - 23 * HOUR_MS).toISOString() }, NOW, day)).toBe(false);
|
|
184
|
+
// Data model: now - lastCheck >= interval — exactly one day is due again.
|
|
185
|
+
expect(isDue({ lastCheck: new Date(NOW - day).toISOString() }, NOW, day)).toBe(true);
|
|
186
|
+
expect(isDue({ lastCheck: new Date(NOW - day + 1000).toISOString() }, NOW, day)).toBe(false);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// --- config file ---
|
|
190
|
+
|
|
191
|
+
test("readUpdateConfig: absent, corrupt, and wrong-shaped files read as no interval", () => {
|
|
192
|
+
expect(readUpdateConfig(join(tempDir(), "absent.json"))).toEqual({});
|
|
193
|
+
const dir = tempDir();
|
|
194
|
+
const corrupt = join(dir, "config.json");
|
|
195
|
+
writeFileSync(corrupt, "{not json");
|
|
196
|
+
expect(readUpdateConfig(corrupt)).toEqual({});
|
|
197
|
+
const wrong = join(dir, "wrong.json");
|
|
198
|
+
writeFileSync(wrong, JSON.stringify({ checkIntervalHours: "24" }));
|
|
199
|
+
expect(readUpdateConfig(wrong)).toEqual({});
|
|
200
|
+
const zero = join(dir, "zero.json");
|
|
201
|
+
writeFileSync(zero, JSON.stringify({ checkIntervalHours: 0 }));
|
|
202
|
+
expect(readUpdateConfig(zero)).toEqual({});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test("readUpdateConfig: a positive interval round-trips", () => {
|
|
206
|
+
const file = join(tempDir(), "config.json");
|
|
207
|
+
seedConfig(file, JSON.stringify({ checkIntervalHours: 24 }));
|
|
208
|
+
expect(readUpdateConfig(file)).toEqual({ checkIntervalHours: 24 });
|
|
168
209
|
});
|
|
169
210
|
|
|
170
211
|
// --- state file ---
|
|
@@ -238,7 +279,7 @@ test("gate on a due day: one request, stamped, newer latestSeen recorded, one no
|
|
|
238
279
|
);
|
|
239
280
|
|
|
240
281
|
expect(urls).toEqual(["https://registry.npmjs.org/-/package/@psimona%2Fdarkf/dist-tags"]);
|
|
241
|
-
expect(out).toEqual([
|
|
282
|
+
expect(out).toEqual([NOTICE("9.9.9")]);
|
|
242
283
|
expect(err).toEqual([]);
|
|
243
284
|
expect(readState(file)).toEqual({
|
|
244
285
|
lastCheck: new Date(NOW).toISOString(),
|
|
@@ -246,19 +287,32 @@ test("gate on a due day: one request, stamped, newer latestSeen recorded, one no
|
|
|
246
287
|
});
|
|
247
288
|
});
|
|
248
289
|
|
|
249
|
-
test("gate
|
|
290
|
+
test("gate with the default config: every invocation checks", async () => {
|
|
250
291
|
const file = tempStateFile();
|
|
251
292
|
const { fetchImpl, count } = fetchCounting('{"latest":"9.9.9"}');
|
|
252
293
|
await captured(() => updateGate("run", deps({ stateFile: file, fetchImpl })));
|
|
253
294
|
expect(count()).toBe(1);
|
|
254
295
|
|
|
255
296
|
const later = await captured(() =>
|
|
256
|
-
updateGate("run", deps({ stateFile: file, fetchImpl, now: () => NOW +
|
|
297
|
+
updateGate("run", deps({ stateFile: file, fetchImpl, now: () => NOW + 1000 })),
|
|
257
298
|
);
|
|
258
|
-
expect(count()).toBe(
|
|
259
|
-
expect(later.out).toEqual([
|
|
260
|
-
|
|
261
|
-
|
|
299
|
+
expect(count()).toBe(2); // no 24h gate without a configured interval
|
|
300
|
+
expect(later.out).toEqual([NOTICE("9.9.9")]);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test("gate with a configured 24h interval: one request per day, notice from the record between checks", async () => {
|
|
304
|
+
const file = tempStateFile();
|
|
305
|
+
const config = join(tempDir(), "config.json");
|
|
306
|
+
seedConfig(config, JSON.stringify({ checkIntervalHours: 24 }));
|
|
307
|
+
const { fetchImpl, count } = fetchCounting('{"latest":"9.9.9"}');
|
|
308
|
+
const base = deps({ stateFile: file, configFile: config, fetchImpl });
|
|
309
|
+
|
|
310
|
+
await captured(() => updateGate("run", base));
|
|
311
|
+
expect(count()).toBe(1);
|
|
312
|
+
|
|
313
|
+
const later = await captured(() => updateGate("run", { ...base, now: () => NOW + 3 * HOUR_MS }));
|
|
314
|
+
expect(count()).toBe(1); // no second request within the configured interval
|
|
315
|
+
expect(later.out).toEqual([NOTICE("9.9.9")]);
|
|
262
316
|
});
|
|
263
317
|
|
|
264
318
|
test("gate: a failed check still stamps and prints nothing (REQ-2, REQ-4)", async () => {
|
|
@@ -276,7 +330,7 @@ test("gate: a stale notice survives a failed check (REQ-11)", async () => {
|
|
|
276
330
|
|
|
277
331
|
const { out } = await captured(() => updateGate("status", deps({ stateFile: file })));
|
|
278
332
|
|
|
279
|
-
expect(out).toEqual([
|
|
333
|
+
expect(out).toEqual([NOTICE("9.9.9")]);
|
|
280
334
|
expect(readState(file)).toEqual({
|
|
281
335
|
lastCheck: new Date(NOW).toISOString(), // restamped by the failed attempt
|
|
282
336
|
latestSeen: "9.9.9", // untouched by the null result
|
|
@@ -470,23 +524,37 @@ test("real CLI with the opt-out: no notice line and no state file (REQ-5, wiring
|
|
|
470
524
|
expect(rawFile(join(stateHome, "darkf", "last-update-check.json"))).toBeNull();
|
|
471
525
|
});
|
|
472
526
|
|
|
473
|
-
test("real CLI
|
|
527
|
+
test("real CLI, configured interval, fresh record: the notice is the first stdout line, no request (REQ-3, REQ-11, NFR-3)", async () => {
|
|
474
528
|
const stateHome = tempDir();
|
|
529
|
+
const configHome = tempDir();
|
|
475
530
|
seedState(join(stateHome, "darkf", "last-update-check.json"), {
|
|
476
531
|
// Fresh stamp: the gate must print from the record without any registry request.
|
|
477
532
|
lastCheck: new Date().toISOString(),
|
|
478
533
|
latestSeen: "99.0.0",
|
|
479
534
|
});
|
|
535
|
+
// The 24h interval keeps the real CLI off the network — the seeded record
|
|
536
|
+
// drives the notice. This also proves the config file wiring end to end.
|
|
537
|
+
seedConfig(join(configHome, "darkf", "config.json"), JSON.stringify({ checkIntervalHours: 24 }));
|
|
480
538
|
|
|
481
|
-
const res = await runRealCli(["workflows"], stateHome, {
|
|
539
|
+
const res = await runRealCli(["workflows"], stateHome, {
|
|
540
|
+
DARKF_NO_UPDATE_CHECK: "",
|
|
541
|
+
XDG_CONFIG_HOME: configHome,
|
|
542
|
+
});
|
|
482
543
|
|
|
483
544
|
expect(res.code).toBe(0);
|
|
484
545
|
const firstLine = res.stdout.split("\n")[0];
|
|
485
546
|
expect(firstLine).toBe(
|
|
486
|
-
`darkf 99.0.0 available (installed ${installedVersion}) — run 'darkf upgrade'`,
|
|
547
|
+
`darkf 99.0.0 available (installed ${installedVersion}) — run 'darkf upgrade'; 'darkf changelog' shows what changed`,
|
|
487
548
|
);
|
|
488
549
|
});
|
|
489
550
|
|
|
551
|
+
test("real CLI, no config: the gate checks and the record notice still names the changelog command", async () => {
|
|
552
|
+
const stateHome = tempDir();
|
|
553
|
+
const res = await runRealCli(["workflows"], stateHome, { DARKF_NO_UPDATE_CHECK: "1" });
|
|
554
|
+
expect(res.code).toBe(0);
|
|
555
|
+
expect(res.stdout.split("\n")[0]).not.toContain("available");
|
|
556
|
+
});
|
|
557
|
+
|
|
490
558
|
// --- upgrade + skills sync (skill-setup spec) ---
|
|
491
559
|
|
|
492
560
|
const SKILL_BUNDLED = "bundled skill body\n";
|
package/src/cli/update.ts
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
// CLI self-update (docs/specs/_built/self-update): a
|
|
1
|
+
// CLI self-update (docs/specs/_built/self-update): a 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
|
+
//
|
|
6
|
+
// 2026-12-05 revision: the check runs on EVERY invocation by default (a
|
|
7
|
+
// release lands, and the very next darkf command knows about it). A config
|
|
8
|
+
// file can restore the old once-per-24h cadence for hosts that must not pay
|
|
9
|
+
// the registry request per command (`updateCheckIntervalHours`). The notice
|
|
10
|
+
// itself never needs the network — it prints from the recorded `latestSeen`.
|
|
5
11
|
import { readFileSync } from "node:fs";
|
|
6
12
|
import { type SkillsDeps, syncAll } from "./setup.ts";
|
|
7
13
|
import { writeJsonState } from "./state-file.ts";
|
|
8
14
|
|
|
9
15
|
const PACKAGE_SPEC = "@psimona/darkf";
|
|
10
16
|
const REGISTRY_URL = "https://registry.npmjs.org/-/package/@psimona%2Fdarkf/dist-tags";
|
|
11
|
-
const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
12
17
|
const CHECK_TIMEOUT_MS = 2_000;
|
|
13
18
|
// Design-originated: no REQ covers probe duration; the cap bounds a hung
|
|
14
19
|
// package manager.
|
|
@@ -22,11 +27,19 @@ export interface UpdateState {
|
|
|
22
27
|
latestSeen?: string; // newest version known to exist; drives the notice
|
|
23
28
|
}
|
|
24
29
|
|
|
30
|
+
/** The one tunable. Absent, zero, or corrupt → check every invocation.
|
|
31
|
+
* A positive value restores the once-per-interval cadence (24 h in the
|
|
32
|
+
* pre-2026-12-05 releases). */
|
|
33
|
+
export interface UpdateConfig {
|
|
34
|
+
checkIntervalHours?: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
25
37
|
export interface UpdateDeps {
|
|
26
38
|
now(): number; // injectable clock
|
|
27
39
|
fetchImpl: typeof fetch; // injectable registry access
|
|
28
40
|
spawnImpl: typeof Bun.spawnSync; // injectable probes and installer
|
|
29
41
|
stateFile: string; // injectable state location
|
|
42
|
+
configFile: string; // injectable config location
|
|
30
43
|
installed: string; // version from the package package.json
|
|
31
44
|
}
|
|
32
45
|
|
|
@@ -45,17 +58,36 @@ export function readState(file: string): UpdateState {
|
|
|
45
58
|
}
|
|
46
59
|
}
|
|
47
60
|
|
|
61
|
+
/** Absent, corrupt, or wrong-shaped config reads as "no interval set". */
|
|
62
|
+
export function readUpdateConfig(file: string): UpdateConfig {
|
|
63
|
+
try {
|
|
64
|
+
const parsed: unknown = JSON.parse(readFileSync(file, "utf8"));
|
|
65
|
+
if (typeof parsed !== "object" || parsed === null) return {};
|
|
66
|
+
const rec = parsed as Record<string, unknown>;
|
|
67
|
+
const value = rec.checkIntervalHours;
|
|
68
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0
|
|
69
|
+
? { checkIntervalHours: value }
|
|
70
|
+
: {};
|
|
71
|
+
} catch {
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
48
76
|
/** mkdir -p on the parent; best-effort — swallow write errors (REQ-4). */
|
|
49
77
|
export function writeState(file: string, state: UpdateState): void {
|
|
50
78
|
writeJsonState(file, state);
|
|
51
79
|
}
|
|
52
80
|
|
|
53
|
-
/** True when
|
|
54
|
-
|
|
81
|
+
/** True when the check should run now. With `intervalMs` 0 (the default
|
|
82
|
+
* config) every invocation is due. With a positive interval, the first
|
|
83
|
+
* invocation ever, an unparseable stamp, and an interval-old stamp are due
|
|
84
|
+
* — exactly one day is due again. */
|
|
85
|
+
export function isDue(state: UpdateState, now: number, intervalMs = 0): boolean {
|
|
86
|
+
if (intervalMs <= 0) return true;
|
|
55
87
|
if (state.lastCheck === undefined) return true;
|
|
56
88
|
const last = Date.parse(state.lastCheck);
|
|
57
89
|
if (Number.isNaN(last)) return true;
|
|
58
|
-
return now - last >=
|
|
90
|
+
return now - last >= intervalMs;
|
|
59
91
|
}
|
|
60
92
|
|
|
61
93
|
/** Bun.semver.order(installed, latest) < 0. */
|
|
@@ -95,8 +127,10 @@ export async function updateGate(cmd: string | undefined, deps: UpdateDeps): Pro
|
|
|
95
127
|
// Opt-out (REQ-5): no state read, no request, no print.
|
|
96
128
|
if (process.env.DARKF_NO_UPDATE_CHECK) return;
|
|
97
129
|
|
|
130
|
+
const config = readUpdateConfig(deps.configFile);
|
|
131
|
+
const intervalMs = (config.checkIntervalHours ?? 0) * 60 * 60 * 1000;
|
|
98
132
|
const state = readState(deps.stateFile);
|
|
99
|
-
if (isDue(state, deps.now())) {
|
|
133
|
+
if (isDue(state, deps.now(), intervalMs)) {
|
|
100
134
|
const latest = await checkRegistry(deps.fetchImpl);
|
|
101
135
|
// null (failed check): leave latestSeen untouched — a stale notice survives.
|
|
102
136
|
if (latest !== null) {
|
|
@@ -111,7 +145,7 @@ export async function updateGate(cmd: string | undefined, deps: UpdateDeps): Pro
|
|
|
111
145
|
// printed before dispatch so it is the first line of stdout (NFR-3).
|
|
112
146
|
if (state.latestSeen !== undefined && isNewer(deps.installed, state.latestSeen)) {
|
|
113
147
|
console.log(
|
|
114
|
-
`darkf ${state.latestSeen} available (installed ${deps.installed}) — run 'darkf upgrade'`,
|
|
148
|
+
`darkf ${state.latestSeen} available (installed ${deps.installed}) — run 'darkf upgrade'; 'darkf changelog' shows what changed`,
|
|
115
149
|
);
|
|
116
150
|
}
|
|
117
151
|
}
|
package/src/core/graph.test.ts
CHANGED
|
@@ -340,7 +340,7 @@ test("takes the model from the default bag for default-runner states only", () =
|
|
|
340
340
|
]);
|
|
341
341
|
});
|
|
342
342
|
|
|
343
|
-
// --- mandatory outputType on agent leaves (docs/specs/mandatory-agent-output-types/) ---
|
|
343
|
+
// --- mandatory outputType on agent leaves (docs/specs/_built/mandatory-agent-output-types/) ---
|
|
344
344
|
|
|
345
345
|
function outputTypeErrors(workflow: WorkflowDef) {
|
|
346
346
|
return validateWorkflow(registryFor(workflow), workflow);
|
package/src/core/graph.ts
CHANGED
|
@@ -95,7 +95,7 @@ export function effectiveAgent(
|
|
|
95
95
|
* a second tree-walk. Collects every problem found; never stops at the
|
|
96
96
|
* first. `DONE`/`FAILED` are valid targets only for a leaf's `on`/`next`,
|
|
97
97
|
* never for any `initial` (composite or top-level). Every agent leaf must
|
|
98
|
-
* declare an `outputType` (docs/specs/mandatory-agent-output-types/). Without
|
|
98
|
+
* declare an `outputType` (docs/specs/_built/mandatory-agent-output-types/). Without
|
|
99
99
|
* `runners`, the runner checks are skipped.
|
|
100
100
|
*/
|
|
101
101
|
export function validateWorkflow(
|
package/src/core/types.ts
CHANGED
|
@@ -23,7 +23,7 @@ export interface NodeResult {
|
|
|
23
23
|
// checking added. Non-strict on purpose: extra fields pass, the same as the
|
|
24
24
|
// hand-rolled check this replaced. One deliberate behavior change: an array
|
|
25
25
|
// now fails, where the hand-rolled check let it through
|
|
26
|
-
// (docs/specs/output-validation/spec.md, "Extending `isNodeResult` to the
|
|
26
|
+
// (docs/specs/_built/output-validation/spec.md, "Extending `isNodeResult` to the
|
|
27
27
|
// same pattern").
|
|
28
28
|
const NodeResultSchema = z.object({
|
|
29
29
|
event: z.string().optional(),
|
|
@@ -273,6 +273,8 @@ export type CrashReason =
|
|
|
273
273
|
| { kind: "cycle-limit"; composite: string; cycles: number }
|
|
274
274
|
| { kind: "invalid-workflow"; errors: WorkflowValidationError[] };
|
|
275
275
|
|
|
276
|
+
const AGENT_FAILURE = Symbol.for("darkf.AgentFailure");
|
|
277
|
+
|
|
276
278
|
/**
|
|
277
279
|
* Thrown by an `AgentRunner` in place of a plain `Error` when the harness
|
|
278
280
|
* session may still be resumable despite the failure. Carries what a plain
|
|
@@ -284,6 +286,10 @@ export type CrashReason =
|
|
|
284
286
|
export class AgentFailure extends Error {
|
|
285
287
|
agentSessionId?: string;
|
|
286
288
|
crashReason?: CrashReason;
|
|
289
|
+
/** Brand that every copy of this class shares. `instanceof` fails across
|
|
290
|
+
* module copies (a workflow that resolves its own install of the package),
|
|
291
|
+
* so the engine tests the brand through `isAgentFailure`. */
|
|
292
|
+
readonly [AGENT_FAILURE]: true = true;
|
|
287
293
|
constructor(message: string, opts?: { agentSessionId?: string; crashReason?: CrashReason }) {
|
|
288
294
|
super(message);
|
|
289
295
|
this.agentSessionId = opts?.agentSessionId;
|
|
@@ -291,6 +297,20 @@ export class AgentFailure extends Error {
|
|
|
291
297
|
}
|
|
292
298
|
}
|
|
293
299
|
|
|
300
|
+
/**
|
|
301
|
+
* True for an `AgentFailure` from any module copy of this package: an error
|
|
302
|
+
* that carries the shared brand, or (for a runner of an earlier release, which
|
|
303
|
+
* has no brand) an `Error` whose constructor is named `AgentFailure`. Use this
|
|
304
|
+
* instead of `instanceof AgentFailure` (docs/specs/_built/runner-failure-identity).
|
|
305
|
+
*/
|
|
306
|
+
export function isAgentFailure(err: unknown): err is AgentFailure {
|
|
307
|
+
if (!(err instanceof Error)) return false;
|
|
308
|
+
return (
|
|
309
|
+
(err as unknown as Record<symbol, unknown>)[AGENT_FAILURE] === true ||
|
|
310
|
+
err.constructor.name === "AgentFailure"
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
294
314
|
export interface StepTrace {
|
|
295
315
|
state: string;
|
|
296
316
|
scopePath: string[];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
// docs/specs/_built/runner-failure-identity/spec.md, REQ-6: a class that the package
|
|
6
|
+
// exports is not the same class in a second module copy, so the engine must
|
|
7
|
+
// not test it with `instanceof`. Classes private to one engine module are fine.
|
|
8
|
+
const engineDir = import.meta.dir;
|
|
9
|
+
const coreDir = join(engineDir, "..", "core");
|
|
10
|
+
|
|
11
|
+
// Exported classes that the engine throws and catches itself, never across a
|
|
12
|
+
// workflow or runner boundary, so they always share the engine's copy.
|
|
13
|
+
const sameCopyOnly: Record<string, string> = {
|
|
14
|
+
DuplicateStateIdError: "thrown by buildRegistry, which run.ts imports itself",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function sourceFiles(dir: string): string[] {
|
|
18
|
+
return readdirSync(dir)
|
|
19
|
+
.filter((n) => n.endsWith(".ts") && !n.endsWith(".test.ts"))
|
|
20
|
+
.map((n) => join(dir, n));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function exportedClasses(): string[] {
|
|
24
|
+
const names = new Set<string>();
|
|
25
|
+
for (const file of sourceFiles(coreDir)) {
|
|
26
|
+
for (const m of readFileSync(file, "utf8").matchAll(/^export class (\w+)/gm)) names.add(m[1]!);
|
|
27
|
+
}
|
|
28
|
+
return [...names];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
test("the engine never tests an exported core class with instanceof", () => {
|
|
32
|
+
const classes = exportedClasses().filter((c) => !(c in sameCopyOnly));
|
|
33
|
+
expect(classes).toContain("AgentFailure"); // the scan finds the class it exists for
|
|
34
|
+
const offenders: string[] = [];
|
|
35
|
+
for (const file of sourceFiles(engineDir)) {
|
|
36
|
+
readFileSync(file, "utf8")
|
|
37
|
+
.split("\n")
|
|
38
|
+
.forEach((line, i) => {
|
|
39
|
+
for (const cls of classes) {
|
|
40
|
+
if (new RegExp(`instanceof\\s+${cls}\\b`).test(line)) {
|
|
41
|
+
offenders.push(`${file.slice(engineDir.length + 1)}:${i + 1} ${cls}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
expect(offenders).toEqual([]);
|
|
47
|
+
});
|