kaizen-agent 1.61.5 → 1.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/agents/kaizen-builder.md +3 -0
- package/agents/kaizen-planner.md +3 -0
- package/agents/kaizen-reviewer.md +2 -0
- package/assets/kaizen-logo.png +0 -0
- package/assets/kaizen.ico +0 -0
- package/cli/__pycache__/computer-helper.cpython-314.pyc +0 -0
- package/cli/accounts.test.ts +126 -0
- package/cli/accounts.ts +116 -0
- package/cli/add-project.ts +4 -2
- package/cli/agent-prefs.test.ts +127 -0
- package/cli/agent-prefs.ts +106 -0
- package/cli/board.test.ts +4 -5
- package/cli/computer-helper.py +299 -0
- package/cli/computer.test.ts +155 -0
- package/cli/computer.ts +66 -0
- package/cli/dashboard.ts +14 -15
- package/cli/install.ts +67 -4
- package/cli/keep-awake.ts +30 -0
- package/cli/notes.test.ts +9 -0
- package/cli/project-tree.test.ts +1 -0
- package/cli/pty.test.ts +2 -1
- package/cli/pty.ts +6 -5
- package/cli/report.test.ts +59 -0
- package/cli/report.ts +62 -0
- package/cli/restart.test.ts +1 -0
- package/cli/settings.test.ts +21 -1
- package/cli/settings.ts +19 -11
- package/cli/setup.test.ts +2 -2
- package/cli/skills.test.ts +89 -0
- package/cli/skills.ts +112 -0
- package/cli/state.test.ts +46 -4
- package/cli/state.ts +127 -41
- package/cli/term-image.test.ts +23 -0
- package/cli/term-image.ts +26 -0
- package/cli/usage.test.ts +8 -2
- package/cli/usage.ts +8 -6
- package/cli/video.test.ts +5 -5
- package/cli/web-accept.test.ts +1 -0
- package/cli/web-decide.test.ts +1 -0
- package/cli/web-pr.test.ts +1 -0
- package/cli/web-skills.test.ts +32 -0
- package/cli/web-symlink.test.ts +1 -0
- package/cli/web.ts +179 -20
- package/cli/workers.test.ts +319 -0
- package/cli/workers.ts +380 -0
- package/cli/worktree.test.ts +21 -2
- package/cli/worktree.ts +21 -2
- package/package.json +1 -1
- package/skills/kaizen/config.default.yml +33 -1
- package/skills/kaizen/settings.md +1 -1
- package/skills/kaizen/skill.json +1 -0
- package/skills/kaizen/spec-build.md +22 -2
- package/skills/kaizen/spec-main.md +9 -0
- package/skills/kaizen/spec-plan.md +18 -1
- package/skills/kaizen/spec-review.md +4 -0
- package/skills/kaizen/spec.md +15 -0
- package/skills/kaizen-help/SKILL.md +1 -0
- package/skills/kaizen-help/skill.json +1 -0
- package/skills/media/kaizen-book/skill.json +1 -0
- package/skills/media/kaizen-deck/skill.json +1 -0
- package/skills/media/kaizen-video/skill.json +1 -0
- package/skills/optional/kaizen-computer/SKILL.md +38 -0
- package/skills/optional/kaizen-computer/skill.json +1 -0
- package/web/board/add-project.ts +3 -3
- package/web/board/agent-favicons.ts +9 -0
- package/web/board/agent-term.ts +1 -1
- package/web/board/api.ts +1 -1
- package/web/board/approvals.ts +1 -1
- package/web/board/cards.ts +50 -7
- package/web/board/dictation.ts +46 -3
- package/web/board/fixes.ts +1 -1
- package/web/board/home.ts +1 -1
- package/web/board/icebox.ts +1 -1
- package/web/board/keys.ts +5 -15
- package/web/board/onboarding.ts +1 -1
- package/web/board/panel.ts +24 -20
- package/web/board/phone.ts +4 -1
- package/web/board/run-view.ts +11 -6
- package/web/board/settings-accounts.ts +60 -0
- package/web/board/settings-agents.ts +102 -0
- package/web/board/settings-orchestration.ts +32 -0
- package/web/board/settings-pages.test.ts +5 -0
- package/web/board/settings-pages.ts +10 -4
- package/web/board/settings-skills.ts +47 -0
- package/web/board/settings-voice.test.ts +18 -0
- package/web/board/settings-voice.ts +28 -0
- package/web/board/settings.ts +40 -4
- package/web/board/terms.ts +2 -2
- package/web/board/update.ts +1 -1
- package/web/board/views.ts +1 -0
- package/web/board/ws-board.test.ts +6 -0
- package/web/board/ws-board.ts +2 -0
- package/web/board.html +21 -7
- package/web/board.js +134 -84
- package/web/notebook.js +2 -2
- package/web/notes.html +8 -6
- package/web/term.js +27 -27
- package/web/term.ts +25 -3
- package/web/video.html +7 -5
- package/web/video.js +2 -2
package/cli/install.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
+
import { bundledSkills, skillsHeld, skillsOff, skillsToLink } from "./skills.ts";
|
|
2
3
|
import {
|
|
3
4
|
symlinkSync, mkdirSync, readdirSync, lstatSync, unlinkSync,
|
|
4
5
|
existsSync, copyFileSync, readFileSync, appendFileSync, rmSync, writeFileSync, renameSync,
|
|
@@ -49,7 +50,11 @@ const c = {
|
|
|
49
50
|
|
|
50
51
|
// Skill folders shipped in skills/ and linked into every agent, by their last
|
|
51
52
|
// path segment: media/kaizen-deck is linked as skills/kaizen-deck.
|
|
52
|
-
const SKILLS =
|
|
53
|
+
const SKILLS = bundledSkills(dirname(import.meta.dir)).map((s) => s.rel);
|
|
54
|
+
// What an install links and checks: a skill turned off in Settings stays off through upgrades.
|
|
55
|
+
// A skill that ships off by default (desktop control) stays unlinked until it is turned on.
|
|
56
|
+
const HELD = skillsHeld(dirname(import.meta.dir), homedir());
|
|
57
|
+
const ON_SKILLS = skillsToLink(SKILLS, skillsOff(homedir()), true, HELD);
|
|
53
58
|
// Skill names an older release linked; uninstall drops them and install
|
|
54
59
|
// clears them when they are still our links.
|
|
55
60
|
const RENAMED_SKILLS = ["story-deck", "story-video", "kaizen-motion"];
|
|
@@ -117,6 +122,63 @@ if (Bun.argv[2] === "card") {
|
|
|
117
122
|
process.exit(0);
|
|
118
123
|
}
|
|
119
124
|
|
|
125
|
+
// `kaizen computer <verb> ...`: desktop control through the accessibility tree, only while
|
|
126
|
+
// the kaizen-computer skill is on. One JSON line out. See cli/computer.ts.
|
|
127
|
+
if (Bun.argv[2] === "computer") {
|
|
128
|
+
const { computer } = await import("./computer.ts");
|
|
129
|
+
const { out, code } = await computer(Bun.argv.slice(3), { home: homedir() });
|
|
130
|
+
console.log(JSON.stringify(out));
|
|
131
|
+
process.exit(code);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// `kaizen report`: how an agent tells the board about its run. See cli/report.ts.
|
|
135
|
+
if (Bun.argv[2] === "report") {
|
|
136
|
+
const { locate } = await import("./state.ts");
|
|
137
|
+
const r = await import("./report.ts");
|
|
138
|
+
const a = Bun.argv.slice(3), flag = (n: string) => { const i = a.indexOf(n); return i < 0 ? undefined : a.splice(i, 2)[1]; };
|
|
139
|
+
const usage = "kaizen report phase <text> | blocked <question> [--options a,b] | unblock | done --outcome succeeded|failed --summary <text> [--files a,b] [--stage s] [--run id]";
|
|
140
|
+
const id = flag("--run") ?? process.env.KAIZEN_RUN_ID, options = flag("--options"), outcome = flag("--outcome"), summary = flag("--summary"), files = flag("--files"), stage = flag("--stage") ?? process.env.KAIZEN_STAGE;
|
|
141
|
+
const state = r.stateOf(process.cwd(), locate()) ?? join(home, ".kaizen");
|
|
142
|
+
const [verb, ...rest] = a, text = rest.join(" ");
|
|
143
|
+
if (!id) { console.log(`\n ${usage}\n no run: pass --run <id>\n`); process.exit(1); }
|
|
144
|
+
const why = verb === "phase" && text ? r.reportPhase(state, id, text)
|
|
145
|
+
: verb === "blocked" && text ? r.reportBlocked(state, id, text, options?.split(",") ?? [])
|
|
146
|
+
: verb === "unblock" ? r.reportUnblock(state, id)
|
|
147
|
+
: verb === "done" && outcome && summary && stage ? r.reportDone(state, id, stage, outcome, summary, files?.split(",") ?? [])
|
|
148
|
+
: usage;
|
|
149
|
+
if (why) { console.log(`\n ${why}\n`); process.exit(1); }
|
|
150
|
+
process.exit(0);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// `kaizen worker`: a run split into workers, off by default. See cli/workers.ts.
|
|
154
|
+
if (Bun.argv[2] === "worker") {
|
|
155
|
+
const { locate } = await import("./state.ts");
|
|
156
|
+
const { stateOf } = await import("./report.ts");
|
|
157
|
+
const w = await import("./workers.ts");
|
|
158
|
+
const a = Bun.argv.slice(3), flag = (n: string) => { const i = a.indexOf(n); return i < 0 ? undefined : a.splice(i, 2)[1]; };
|
|
159
|
+
const usage = "kaizen worker init [run] | start <wid> | status | config | report phase <text> | blocked <q> [--options a,b] | unblock | done --outcome succeeded|failed --summary <text> [--files a,b] | merge | set <run> on|off|clear [--run id] [--worker wid]";
|
|
160
|
+
const state = stateOf(process.cwd(), locate()) ?? join(home, ".kaizen"), project = dirname(state);
|
|
161
|
+
const runId = flag("--run"), worker = flag("--worker") ?? process.env.KAIZEN_WORKER, options = flag("--options"), outcome = flag("--outcome"), summary = flag("--summary"), files = flag("--files");
|
|
162
|
+
const [verb, ...rest] = a;
|
|
163
|
+
const id = (verb === "init" || verb === "set" ? rest[0] : undefined) ?? runId ?? process.env.KAIZEN_RUN_ID;
|
|
164
|
+
const fail = (why: string) => { console.log(`\n ${why}\n`); process.exit(1); };
|
|
165
|
+
const say = (text: string) => { console.log(`\n ${text.replace(/\n/g, "\n ")}\n`); process.exit(0); };
|
|
166
|
+
if (!verb) fail(usage);
|
|
167
|
+
if (!id) fail(`${usage}\n no run: pass --run <id>`);
|
|
168
|
+
if (verb === "init") { const r = w.init(project, id!); r.ok ? say(`${r.n} workers planned. Next: kaizen worker start <wid>`) : fail(r.why); }
|
|
169
|
+
else if (verb === "start") { const r = w.requestStart(project, id!, rest[0] ?? ""); r.ok ? say(r.why) : fail(r.why); }
|
|
170
|
+
else if (verb === "status") say(w.statusText(project, id!));
|
|
171
|
+
else if (verb === "config") { const r = w.resolve(project, id!); say(r.on ? `on · max ${r.max} · permissions ${r.permissions} · model ${r.model}` : `off · ${r.why}`); }
|
|
172
|
+
else if (verb === "merge") { const r = w.merge(project, id!); r.ok ? say(`merged ${r.shas.length} workers into the run's branch. Next: the usual checks, then 03-impl.md${r.left.length ? `\nleft behind (remove by hand):\n${r.left.join("\n")}` : ""}`) : fail(r.why); }
|
|
173
|
+
else if (verb === "set") { const why = w.setRun(project, id!, rest[1] ?? ""); why ? fail(why) : say(`${id}: orchestration ${rest[1]}`); }
|
|
174
|
+
else if (verb === "report") {
|
|
175
|
+
const [kind, ...t] = rest;
|
|
176
|
+
if (!worker) fail("report: which worker? run it from the worker's terminal, or pass --worker <wid>");
|
|
177
|
+
const why = w.report(project, id!, worker!, kind ?? "", { text: t.join(" "), options: options?.split(","), outcome, summary, files: files?.split(",") });
|
|
178
|
+
why ? fail(why) : say("reported");
|
|
179
|
+
} else fail(usage);
|
|
180
|
+
}
|
|
181
|
+
|
|
120
182
|
// `kaizen done <run id> [--user-approved]`: how an agent finishes a run. Refuses while
|
|
121
183
|
// the review gate waits on the user; --user-approved is for a clear yes in chat.
|
|
122
184
|
if (Bun.argv[2] === "done") {
|
|
@@ -472,12 +534,13 @@ if (wantSettings) {
|
|
|
472
534
|
if (args.has("worktree")) {
|
|
473
535
|
const [, verb = "", id = ""] = Bun.argv.slice(2).filter((a) => !a.startsWith("-"));
|
|
474
536
|
const { locate } = await import("./state.ts");
|
|
475
|
-
const { startWorktree, landWorktree, adoptWorkspace } = await import("./worktree.ts");
|
|
537
|
+
const { startWorktree, landWorktree, adoptWorkspace, linkTerm } = await import("./worktree.ts");
|
|
476
538
|
const state = locate();
|
|
477
539
|
if (!state || (verb !== "start" && verb !== "land")) { console.log("\n usage: kaizen worktree start|land <run-id>, in a project with .kaizen\n"); process.exit(1); }
|
|
478
540
|
const project = dirname(state);
|
|
479
541
|
// Started inside another workspace of the project (a board worktree): the run is placed there.
|
|
480
542
|
const r = verb === "start" ? adoptWorkspace(project, id, process.cwd()) ?? startWorktree(project, id) : landWorktree(project, id);
|
|
543
|
+
if (r.ok && verb === "start") linkTerm(state, process.env.KAIZEN_TERM, id);
|
|
481
544
|
console.log(r.ok ? `\n ${verb === "start" ? `worktree ready: ${(r as { path: string }).path}` : `landed by ${(r as { how: string }).how}`}\n` : `\n ${r.why}\n`);
|
|
482
545
|
process.exit(r.ok ? 0 : 1);
|
|
483
546
|
}
|
|
@@ -639,7 +702,7 @@ if (interactive && !upgrade && Bun.argv.length === 2) {
|
|
|
639
702
|
if (!stale) {
|
|
640
703
|
const here = found(home);
|
|
641
704
|
const linked = here.length > 0 && here.every((a) =>
|
|
642
|
-
|
|
705
|
+
ON_SKILLS.every((n) => existsSync(join(home, a.dir, "skills", basename(n)))));
|
|
643
706
|
if (linked) {
|
|
644
707
|
const { dashboard } = await import("./dashboard.ts");
|
|
645
708
|
await dashboard(repoDir, here.map((a) => a.name), async (action) => {
|
|
@@ -950,7 +1013,7 @@ function dirEntries(sub: string) {
|
|
|
950
1013
|
}
|
|
951
1014
|
|
|
952
1015
|
const links = targets.flatMap((a) => [
|
|
953
|
-
...SKILLS.map((n) => [join(repo, "skills", n), join(a.dir, "skills")] as const),
|
|
1016
|
+
...skillsToLink(SKILLS, skillsOff(homedir()), resolve(a.dir) === resolve(home, basename(a.dir)), HELD).map((n) => [join(repo, "skills", n), join(a.dir, "skills")] as const),
|
|
954
1017
|
...(a.full ? [
|
|
955
1018
|
...dirEntries("agents").map((f) => [f, join(a.dir, "agents")] as const),
|
|
956
1019
|
...dirEntries("commands").map((f) => [f, join(a.dir, "commands")] as const),
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// agent.keep_awake: an idle and sleep inhibitor held as a child of the board. Each one
|
|
2
|
+
// watches the board's pid, so a crashed board cannot leave the computer held awake.
|
|
3
|
+
export type Awake = "off" | "auto" | "on";
|
|
4
|
+
|
|
5
|
+
export function inhibitArgv(platform = process.platform as string, pid = process.pid): string[] | null {
|
|
6
|
+
if (platform === "linux") return ["systemd-inhibit", "--what=idle:sleep", "--who=kaizen", "--why=Agents are running", "tail", `--pid=${pid}`, "-f", "/dev/null"];
|
|
7
|
+
if (platform === "darwin") return ["caffeinate", "-i", "-w", String(pid)];
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const wantAwake = (mode: string, agentsRunning: boolean) => mode === "on" || (mode === "auto" && agentsRunning);
|
|
12
|
+
|
|
13
|
+
export function awakeHolder(start: (argv: string[]) => { kill: () => void; exited?: Promise<unknown> } = (a) => Bun.spawn(a, { stdin: "ignore", stdout: "ignore", stderr: "ignore" }), argv = inhibitArgv()) {
|
|
14
|
+
let held: { kill: () => void } | null = null;
|
|
15
|
+
const stop = () => { held?.kill(); held = null; };
|
|
16
|
+
return {
|
|
17
|
+
stop,
|
|
18
|
+
held: () => !!held,
|
|
19
|
+
sync(want: boolean) {
|
|
20
|
+
if (!want) return stop();
|
|
21
|
+
if (held || !argv) return;
|
|
22
|
+
try {
|
|
23
|
+
const p = start(argv);
|
|
24
|
+
held = p;
|
|
25
|
+
// No systemd-inhibit session, say: next tick tries again.
|
|
26
|
+
p.exited?.then(() => { if (held === p) held = null; });
|
|
27
|
+
} catch { held = null; }
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
package/cli/notes.test.ts
CHANGED
|
@@ -238,3 +238,12 @@ test("web/notebook.js, web/term.js, web/board.js, web/video.js and bot/web/app.j
|
|
|
238
238
|
expect(readFileSync(BOT_OUT, "utf8").split("\n", 1)[0]!).toContain(`kaizen bot page ${sourceHash()} `);
|
|
239
239
|
expect(readFileSync(VIDEO_OUT, "utf8").split("\n", 1)[0]!).toContain(`kaizen video page ${sourceHash()} `);
|
|
240
240
|
});
|
|
241
|
+
|
|
242
|
+
test("an installed app fits the window, not the screen", () => {
|
|
243
|
+
for (const f of ["board.html", "notes.html", "video.html"]) {
|
|
244
|
+
const s = readFileSync(join(root, "web", f), "utf8");
|
|
245
|
+
expect(s).not.toMatch(/--sh\b(?!a)/);
|
|
246
|
+
expect(s).toContain("inset:0 0 auto;height:100dvh");
|
|
247
|
+
expect(s).toContain("body::after{content");
|
|
248
|
+
}
|
|
249
|
+
});
|
package/cli/project-tree.test.ts
CHANGED
|
@@ -17,6 +17,7 @@ test("project tree and text preview stay inside a registered project", async ()
|
|
|
17
17
|
symlinkSync(join(home, ".kaizen", "projects"), join(project, "link"));
|
|
18
18
|
const port = 20000 + Math.floor(Math.random() * 20000);
|
|
19
19
|
const repo = join(import.meta.dir, "..");
|
|
20
|
+
mkdirSync(join(home, ".claude"), { recursive: true }); // an agent, or `kaizen web` stops at its no-agent notice
|
|
20
21
|
const proc = Bun.spawn([process.execPath, join(repo, "cli", "install.ts"), "web", "--port", String(port), "--no-open", "--foreground"], {
|
|
21
22
|
cwd: project, env: { ...process.env, HOME: home, USERPROFILE: home, KAIZEN_HOME: repo }, stdout: "ignore", stderr: "ignore",
|
|
22
23
|
});
|
package/cli/pty.test.ts
CHANGED
|
@@ -249,7 +249,8 @@ test.skipIf(process.platform === "win32")("submit: Enter reaches the agent on it
|
|
|
249
249
|
test("busy: on while the agent draws its working line, off once it goes quiet; other output is not work", async () => {
|
|
250
250
|
const key = "busy-" + Date.now();
|
|
251
251
|
startPty(key, ["sh", "-c", "for i in 1 2 3 4 5 6; do echo 'Thinking (3s · esc to interrupt)'; sleep 0.1; done; read l"], root);
|
|
252
|
-
|
|
252
|
+
// ConPTY delivers the first line later than a Unix pty.
|
|
253
|
+
for (let i = 0; i < 30 && !ptyState(key)!.busy; i++) await Bun.sleep(50);
|
|
253
254
|
expect(ptyState(key)!.busy).toBe(true);
|
|
254
255
|
await Bun.sleep(1800);
|
|
255
256
|
expect(ptyState(key)).toMatchObject({ alive: true, busy: false });
|
package/cli/pty.ts
CHANGED
|
@@ -11,7 +11,7 @@ const WIN = process.platform === "win32";
|
|
|
11
11
|
// Windows PowerShell, which every Windows has, both hosts the console and runs the agent in it.
|
|
12
12
|
const winPs = () => join(process.env.SystemRoot ?? "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
13
13
|
|
|
14
|
-
type Pty = { proc: Bun.Subprocess; out: string[]; size: number; listeners: Set<(d: string | null) => void>; exit: number | null; asking: boolean; busy: boolean; quiet?: Timer; total: number; since: number; onChange?: () => void; tmux?: string; last: string; lastAt: number; typedAt: number; born: number };
|
|
14
|
+
type Pty = { lastOut?: number; proc: Bun.Subprocess; out: string[]; size: number; listeners: Set<(d: string | null) => void>; exit: number | null; asking: boolean; busy: boolean; quiet?: Timer; total: number; since: number; onChange?: () => void; tmux?: string; last: string; lastAt: number; typedAt: number; born: number };
|
|
15
15
|
|
|
16
16
|
// What a page attaching late gets replayed. A full-screen tool redraws often, so the
|
|
17
17
|
// tail of its output is enough to rebuild the screen.
|
|
@@ -94,7 +94,7 @@ export const ptySupported = WIN || typeof (Bun as any).Terminal === "function";
|
|
|
94
94
|
// seed: what the card showed before the board restarted, replayed ahead of the new output.
|
|
95
95
|
// tmux: run cmd inside a tmux session of that name on kaizen's own server (tmuxCmd), which
|
|
96
96
|
// outlives the board; null where tmux cannot be used, and the agent runs plainly.
|
|
97
|
-
export function startPty(key: string, cmd: string[], cwd: string, pidFile?: string, onChange?: () => void, opts: { seed?: string; tmux?: string; attach?: boolean } = {}): number {
|
|
97
|
+
export function startPty(key: string, cmd: string[], cwd: string, pidFile?: string, onChange?: () => void, opts: { seed?: string; tmux?: string; attach?: boolean; env?: Record<string, string> } = {}): number {
|
|
98
98
|
const dec = new TextDecoder();
|
|
99
99
|
const p: Pty = { proc: null as unknown as Bun.Subprocess, out: opts.seed ? [opts.seed] : [], size: opts.seed?.length ?? 0, listeners: new Set(), exit: null, asking: false, busy: false, total: 0, since: 0, onChange, last: "", lastAt: 0, typedAt: 0, born: Date.now() };
|
|
100
100
|
// attach: the session already runs (kept from a board before this one); only a client is started.
|
|
@@ -105,6 +105,7 @@ export function startPty(key: string, cmd: string[], cwd: string, pidFile?: stri
|
|
|
105
105
|
const work = (v: boolean) => { if (p.busy !== v) { p.busy = v; onChange?.(); } };
|
|
106
106
|
const push = (d: string) => {
|
|
107
107
|
p.out.push(d);
|
|
108
|
+
p.lastOut = Date.now();
|
|
108
109
|
p.size += d.length;
|
|
109
110
|
p.total += d.length;
|
|
110
111
|
while (p.size > CAP && p.out.length > 1) p.size -= p.out.shift()!.length;
|
|
@@ -125,7 +126,7 @@ export function startPty(key: string, cmd: string[], cwd: string, pidFile?: stri
|
|
|
125
126
|
const ps = winPs();
|
|
126
127
|
p.proc = Bun.spawn([ps, "-NoProfile", "-NonInteractive", "-EncodedCommand", conptyHost()], {
|
|
127
128
|
cwd,
|
|
128
|
-
env: { ...colorEnv(), KAIZEN_BOARD_PID: String(process.pid), KZ_PTY_CMD: innerCommand(ps, cmd), KZ_PTY_CWD: cwd, KZ_PTY_COLS: "120", KZ_PTY_ROWS: "32" },
|
|
129
|
+
env: { ...colorEnv(), ...opts.env, KAIZEN_BOARD_PID: String(process.pid), KZ_PTY_CMD: innerCommand(ps, cmd), KZ_PTY_CWD: cwd, KZ_PTY_COLS: "120", KZ_PTY_ROWS: "32" },
|
|
129
130
|
stdin: "pipe", stdout: "pipe", stderr: "pipe", windowsHide: true,
|
|
130
131
|
});
|
|
131
132
|
const read = async (s: ReadableStream<Uint8Array>) => {
|
|
@@ -137,7 +138,7 @@ export function startPty(key: string, cmd: string[], cwd: string, pidFile?: stri
|
|
|
137
138
|
read(p.proc.stderr as ReadableStream<Uint8Array>).catch(() => {});
|
|
138
139
|
} else p.proc = Bun.spawn(cmd, {
|
|
139
140
|
cwd,
|
|
140
|
-
env: { ...colorEnv(), TERM: "xterm-256color", COLORTERM: "truecolor", KAIZEN_BOARD_PID: String(process.pid) },
|
|
141
|
+
env: { ...colorEnv(), ...opts.env, TERM: "xterm-256color", COLORTERM: "truecolor", KAIZEN_BOARD_PID: String(process.pid) },
|
|
141
142
|
terminal: { cols: 120, rows: 32, data: (_t, d) => push(dec.decode(d, { stream: true })) },
|
|
142
143
|
});
|
|
143
144
|
if (opts.tmux && cmd[0] === tmuxBin()) p.tmux = opts.tmux;
|
|
@@ -284,7 +285,7 @@ export const ptyKeys = () => [...ptys.keys()];
|
|
|
284
285
|
|
|
285
286
|
export const ptyState = (key: string) => {
|
|
286
287
|
const p = ptys.get(key);
|
|
287
|
-
return p ? { pid: p.proc.pid, alive: p.exit === null, exit: p.exit, asking: p.asking, busy: p.busy, total: p.total, last: p.last, at: p.lastAt, born: p.born } : null;
|
|
288
|
+
return p ? { pid: p.proc.pid, alive: p.exit === null, exit: p.exit, asking: p.asking, busy: p.busy, total: p.total, last: p.last, at: p.lastAt, born: p.born, lastOut: p.lastOut } : null;
|
|
288
289
|
};
|
|
289
290
|
|
|
290
291
|
// The environment the user's login shell builds: PATH and anything exported in their
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { afterEach, beforeEach, expect, test } from "bun:test";
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { readReport, reportBlocked, reportDone, reportPhase, reportUnblock, signalOf, stateOf } from "./report.ts";
|
|
6
|
+
|
|
7
|
+
let st: string;
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
st = mkdtempSync(join(tmpdir(), "kz-report-"));
|
|
10
|
+
mkdirSync(join(st, "runs", "r1"), { recursive: true });
|
|
11
|
+
writeFileSync(join(st, "runs", "r1", "state.json"), "{}");
|
|
12
|
+
});
|
|
13
|
+
afterEach(() => rmSync(st, { recursive: true, force: true }));
|
|
14
|
+
const now = 1e12, old = now - 11 * 60_000, build = { stage: "build", awaiting: null };
|
|
15
|
+
|
|
16
|
+
test("no report and no board terminal: no signal, so the card is as before", () => {
|
|
17
|
+
expect(signalOf(build, null, undefined, now, 5)).toBeNull();
|
|
18
|
+
expect(signalOf(build, null, { alive: true }, now, 5)).toBeNull();
|
|
19
|
+
});
|
|
20
|
+
test("an ended terminal with no hand-back for this stage and round is unverified, report or none", () => {
|
|
21
|
+
const h = (stage: string, iteration = 0) => ({ at: old, handback: { stage, iteration, outcome: "succeeded" as const, summary: "", files: [] } });
|
|
22
|
+
expect(signalOf(build, null, { alive: false }, now, 5)).toBe("unverified");
|
|
23
|
+
expect(signalOf(build, { at: old }, { alive: false }, now, 5)).toBe("unverified");
|
|
24
|
+
expect(signalOf(build, h("plan"), { alive: false }, now, 5)).toBe("unverified");
|
|
25
|
+
expect(signalOf(build, h("build"), { alive: false }, now, 5)).toBeNull();
|
|
26
|
+
expect(signalOf({ ...build, iteration: 1 }, h("build"), { alive: false }, now, 5)).toBe("unverified");
|
|
27
|
+
expect(signalOf({ ...build, iteration: 1 }, h("build", 1), { alive: false }, now, 5)).toBeNull();
|
|
28
|
+
expect(signalOf({ stage: "plan" }, null, { alive: false }, now, 5)).toBeNull();
|
|
29
|
+
expect(signalOf({ stage: "done" }, { at: old }, { alive: false }, now, 5)).toBeNull();
|
|
30
|
+
});
|
|
31
|
+
test("stale needs a live, silent board terminal", () => {
|
|
32
|
+
expect(signalOf(build, { at: old }, { alive: true, busy: true }, now, 5)).toBeNull();
|
|
33
|
+
expect(signalOf(build, { at: old }, { alive: true, asking: true }, now, 5)).toBeNull();
|
|
34
|
+
expect(signalOf(build, { at: old }, { alive: true, lastOut: now - 60_000 }, now, 5)).toBeNull();
|
|
35
|
+
expect(signalOf(build, { at: old }, undefined, now, 5)).toBeNull();
|
|
36
|
+
expect(signalOf(build, { at: old }, { alive: true, lastOut: old }, now, 5)).toBe("stale");
|
|
37
|
+
});
|
|
38
|
+
test("blocked shows until cleared, is bounded, and a hand-back clears it", () => {
|
|
39
|
+
reportBlocked(st, "r1", "x".repeat(900) + "\n<b>", ["a", "b", "c", "d", "e"]);
|
|
40
|
+
const r = readReport(st, "r1")!;
|
|
41
|
+
expect(r.blocked!.question.length).toBe(300);
|
|
42
|
+
expect(r.blocked!.options.length).toBe(4);
|
|
43
|
+
expect(signalOf({ stage: "build", awaiting: "approvals.plan" }, r, undefined, now, 5)).toBe("blocked");
|
|
44
|
+
reportUnblock(st, "r1");
|
|
45
|
+
expect(readReport(st, "r1")!.blocked).toBeUndefined();
|
|
46
|
+
reportBlocked(st, "r1", "q");
|
|
47
|
+
expect(reportDone(st, "r1", "build", "maybe", "s", [])).toBeTruthy();
|
|
48
|
+
expect(reportDone(st, "r1", "build", "failed", "s", ["a.ts"])).toBeNull();
|
|
49
|
+
expect(readReport(st, "r1")!.blocked).toBeUndefined();
|
|
50
|
+
});
|
|
51
|
+
test("an id can't leave the state dir", () => {
|
|
52
|
+
for (const id of ["../x", "a/b", "..", "nope", "/etc"]) expect(reportPhase(st, id, "x")).toBeTruthy();
|
|
53
|
+
expect(existsSync(join(st, "report.json"))).toBe(false);
|
|
54
|
+
expect(reportPhase(st, "r1", "building")).toBeNull();
|
|
55
|
+
});
|
|
56
|
+
test("from a worktree, reports go to the project's state dir", () => {
|
|
57
|
+
expect(stateOf("/p/.kaizen/wt/r1/cli", "/p/.kaizen/wt/r1/.kaizen")).toBe("/p/.kaizen");
|
|
58
|
+
expect(stateOf("/p", "/p/.kaizen")).toBe("/p/.kaizen");
|
|
59
|
+
});
|
package/cli/report.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// What an agent says about its own run: runs/<id>/report.json, written by `kaizen report`.
|
|
2
|
+
// A file, so it works with no board up, in any tool, with no secret to hand out.
|
|
3
|
+
// The board reads it; a run with no report behaves exactly as before.
|
|
4
|
+
import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
|
|
7
|
+
export type Handback = { stage: string; iteration?: number; outcome: "succeeded" | "failed"; summary: string; files: string[] };
|
|
8
|
+
export type Report = { phase?: string; at: number; blocked?: { question: string; options: string[] }; handback?: Handback };
|
|
9
|
+
export type Signal = "blocked" | "stale" | "unverified" | null;
|
|
10
|
+
|
|
11
|
+
export const clip = (s: unknown, n: number) => String(s ?? "").replace(/[\0-\x1f\x7f]+/g, " ").trim().slice(0, n);
|
|
12
|
+
export const validId = (id: string) => /^[A-Za-z0-9][\w.-]{0,127}$/.test(id) && !id.includes("..");
|
|
13
|
+
|
|
14
|
+
// A worktree carries its own committed .kaizen with no runs: the project's holds them.
|
|
15
|
+
export const stateOf = (cwd: string, found: string | null) => /^(.*[\\/]\.kaizen)[\\/]wt[\\/]/.exec(cwd)?.[1] ?? found;
|
|
16
|
+
|
|
17
|
+
export function readReport(state: string, id: string): Report | null {
|
|
18
|
+
try {
|
|
19
|
+
const r = JSON.parse(readFileSync(join(state, "runs", id, "report.json"), "utf8"));
|
|
20
|
+
return r && typeof r.at === "number" ? r : null;
|
|
21
|
+
} catch { return null; }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function write(state: string, id: string, patch: (r: Report) => void): string | null {
|
|
25
|
+
if (!validId(id) || !existsSync(join(state, "runs", id, "state.json"))) return `no run ${clip(id, 80)}`;
|
|
26
|
+
const r = readReport(state, id) ?? { at: 0 };
|
|
27
|
+
patch(r);
|
|
28
|
+
r.at = Date.now();
|
|
29
|
+
const file = join(state, "runs", id, "report.json"), tmp = `${file}.${process.pid}.tmp`;
|
|
30
|
+
writeFileSync(tmp, JSON.stringify(r, null, 2));
|
|
31
|
+
renameSync(tmp, file);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const reportPhase = (state: string, id: string, text: string) => write(state, id, (r) => { r.phase = clip(text, 120); });
|
|
36
|
+
export const reportBlocked = (state: string, id: string, question: string, options: string[] = []) =>
|
|
37
|
+
write(state, id, (r) => { r.blocked = { question: clip(question, 300), options: options.slice(0, 4).map((o) => clip(o, 80)) }; });
|
|
38
|
+
export const reportUnblock = (state: string, id: string) => write(state, id, (r) => { delete r.blocked; });
|
|
39
|
+
export function reportDone(state: string, id: string, stage: string, outcome: string, summary: string, files: string[]) {
|
|
40
|
+
if (outcome !== "succeeded" && outcome !== "failed") return "outcome is succeeded or failed";
|
|
41
|
+
let iteration = 0;
|
|
42
|
+
try { iteration = Number(JSON.parse(readFileSync(join(state, "runs", id, "state.json"), "utf8")).iteration) || 0; } catch { /* write() reports it */ }
|
|
43
|
+
return write(state, id, (r) => { r.handback = { stage: clip(stage, 20), iteration, outcome, summary: clip(summary, 600), files: files.slice(0, 200).map((f) => clip(f, 300)) }; delete r.blocked; });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// What the card shows. `pty` is the board's terminal for the run; without one the agent
|
|
47
|
+
// runs elsewhere, so nothing here can tell quiet from dead and no signal is given. A
|
|
48
|
+
// terminal that ended mid-stage is unverified, report or none, and each fix round owes its
|
|
49
|
+
// own hand-back.
|
|
50
|
+
type RunView = { stage?: string; awaiting?: string | null; iteration?: number };
|
|
51
|
+
type PtyView = { alive?: boolean; busy?: boolean; asking?: boolean; lastOut?: number };
|
|
52
|
+
export function signalOf(run: RunView, r: Report | null, pty: PtyView | undefined, now: number, minutes: number): Signal {
|
|
53
|
+
if (run.stage === "done" || run.stage === "abandoned") return null;
|
|
54
|
+
if (r?.blocked) return "blocked";
|
|
55
|
+
if (run.awaiting || !pty) return null;
|
|
56
|
+
if (!pty.alive) {
|
|
57
|
+
const h = r?.handback;
|
|
58
|
+
return (run.stage === "build" || run.stage === "review") && !(h?.stage === run.stage && (h.iteration ?? 0) === (run.iteration ?? 0)) ? "unverified" : null;
|
|
59
|
+
}
|
|
60
|
+
if (!r || pty.busy || pty.asking) return null;
|
|
61
|
+
return now - Math.max(r.at, pty.lastOut ?? 0) > 2 * minutes * 60_000 ? "stale" : null;
|
|
62
|
+
}
|
package/cli/restart.test.ts
CHANGED
|
@@ -180,6 +180,7 @@ process.on("SIGTERM", () => setTimeout(() => process.exit(0), 1500));
|
|
|
180
180
|
console.log("up");`);
|
|
181
181
|
const old = Bun.spawn([process.execPath, script], { stdout: "pipe" });
|
|
182
182
|
await new Response(old.stdout).body!.getReader().read();
|
|
183
|
+
mkdirSync(join(home, ".claude"), { recursive: true }); // an agent, or `kaizen web` stops at its no-agent notice
|
|
183
184
|
const fresh = Bun.spawn([process.execPath, join(import.meta.dir, "install.ts"), "web", "--port", String(port), "--no-open", "--foreground"], {
|
|
184
185
|
cwd: home, env: { ...process.env, HOME: home, USERPROFILE: home }, stdin: "ignore", stdout: "ignore", stderr: "ignore",
|
|
185
186
|
});
|
package/cli/settings.test.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { test, expect, beforeAll, afterAll } from "bun:test";
|
|
|
6
6
|
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, copyFileSync, rmSync } from "node:fs";
|
|
7
7
|
import { join, dirname } from "node:path";
|
|
8
8
|
import { tmpdir } from "node:os";
|
|
9
|
-
import { applyPreset, detectPreset } from "./settings.ts";
|
|
9
|
+
import { applyPreset, detectPreset, read } from "./settings.ts";
|
|
10
10
|
|
|
11
11
|
const repo = join(dirname(import.meta.path), "..");
|
|
12
12
|
const defaults = join(repo, "skills/kaizen/config.default.yml");
|
|
@@ -131,3 +131,23 @@ test("a project scope reads over All projects, starts its own file empty, and re
|
|
|
131
131
|
expect(r.left).not.toContain("auto_commit");
|
|
132
132
|
expect(r.kept).toBe("# my team's git rules\ngit:\n # mine\n");
|
|
133
133
|
});
|
|
134
|
+
|
|
135
|
+
test("the orchestration keys read at their exact nesting, off by default, comments between lines allowed", () => {
|
|
136
|
+
const d = readFileSync(defaults, "utf8");
|
|
137
|
+
expect(["enabled", "max_workers", "permissions", "worker_model.claude", "worker_model.codex"].map((k) => read(d, `orchestration.${k}`))).toEqual(["false", "3", "own", "", ""]);
|
|
138
|
+
const mine = "orchestration:\n # why\n enabled: true # on\n\n # a comment\n max_workers: 2\n";
|
|
139
|
+
expect([read(mine, "orchestration.enabled"), read(mine, "orchestration.max_workers"), read(mine, "orchestration.permissions")]).toEqual(["true", "2", null]);
|
|
140
|
+
expect(read("git:\n enabled: true\n", "orchestration.enabled")).toBeNull();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test("a worker model written into a config that has no such block lands under orchestration, not a second header", () => {
|
|
144
|
+
const file = join(project, ".kaizen", "config.yml"), keep = readFileSync(file, "utf8");
|
|
145
|
+
try {
|
|
146
|
+
writeFileSync(file, "orchestration:\n enabled: true\n");
|
|
147
|
+
expect(inProject(`return setSetting(repo, "orchestration.worker_model.claude", "haiku")`)).toEqual({ ok: true });
|
|
148
|
+
const text = readFileSync(file, "utf8");
|
|
149
|
+
expect((text.match(/^orchestration:/gm) ?? []).length).toBe(1);
|
|
150
|
+
expect(read(text, "orchestration.worker_model.claude")).toBe("haiku");
|
|
151
|
+
expect(read(text, "orchestration.enabled")).toBe("true");
|
|
152
|
+
} finally { writeFileSync(file, keep); }
|
|
153
|
+
});
|
package/cli/settings.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { existsSync, writeFileSync, copyFileSync, mkdirSync } from "node:fs";
|
|
4
4
|
import { join, dirname, basename } from "node:path";
|
|
5
5
|
import { homedir } from "node:os";
|
|
6
|
-
import { readText, knownProjects } from "./state.ts";
|
|
6
|
+
import { readText, knownProjects, KNOWN_AGENTS, MODEL_FLAGS } from "./state.ts";
|
|
7
7
|
|
|
8
8
|
// `text` is a value typed rather than chosen: a path. It has no values to cycle.
|
|
9
9
|
// `when`: the row only has an effect while that other key holds that value; both
|
|
@@ -50,7 +50,7 @@ export const PRESETS: Record<PresetName, {
|
|
|
50
50
|
"auto_fix.min_severity": "low",
|
|
51
51
|
"auto_fix.max_iterations": "2",
|
|
52
52
|
"git.auto_commit": "false",
|
|
53
|
-
"git.worktree_per_run": "
|
|
53
|
+
"git.worktree_per_run": "ask",
|
|
54
54
|
},
|
|
55
55
|
},
|
|
56
56
|
ultra: {
|
|
@@ -113,13 +113,20 @@ const SETTINGS: Setting[] = [
|
|
|
113
113
|
{ key: "agent.default", label: "Tool the board launches", group: "Agents", values: ["auto", "claude", "codex", "agy", "opencode", "gemini"], help: "" },
|
|
114
114
|
{ key: "agent.launch", label: "Where the board runs agents", group: "Agents", values: ["card", "terminal"], help: "" },
|
|
115
115
|
{ key: "agent.keep_alive", label: "Keep agents through a board restart", group: "Agents", values: ["off", "tmux"], help: "tmux: Linux and macOS with tmux installed", when: ["agent.launch", "card"] },
|
|
116
|
+
{ key: "agent.keep_awake", label: "Keep computer awake", group: "Board", values: ["off", "auto", "on"], help: "auto: while the board runs agents · on: while the board is open. Linux and macOS" },
|
|
117
|
+
{ key: "agent.heartbeat_minutes", label: "Agent heartbeat", group: "Board", values: ["2", "5", "10", "30"], help: "Minutes. A card says stale after two quiet intervals" },
|
|
116
118
|
{ key: "subagents.model", label: "Model for subagents", group: "Agents", values: ["inherit", "opus", "sonnet", "haiku"], help: "Planner, builder, reviewer", when: ["runner", "full"] },
|
|
117
119
|
{ key: "subagents.effort", label: "Effort for subagents", group: "Agents", values: ["inherit", "low", "medium", "high"], help: "Planner, builder, reviewer", when: ["runner", "full"] },
|
|
118
120
|
{ key: "auto_fix.enabled", label: "Fix findings automatically", group: "Auto-fix", values: ["true", "false"], help: "" },
|
|
119
121
|
{ key: "auto_fix.min_severity", label: "Lowest severity to fix", group: "Auto-fix", values: ["critical", "high", "medium", "low"], help: "", when: ["auto_fix.enabled", "true"] },
|
|
120
122
|
{ key: "auto_fix.max_iterations", label: "Max fix rounds", group: "Auto-fix", values: ["1", "2", "3", "4", "5"], help: "", when: ["auto_fix.enabled", "true"] },
|
|
121
123
|
{ key: "git.auto_commit", label: "Commit when done", group: "Git", values: ["false", "true"], help: "Never pushes" },
|
|
122
|
-
{ key: "git.worktree_per_run", label: "Branch and folder per run", group: "Git", values: ["true", "false"], help: "" },
|
|
124
|
+
{ key: "git.worktree_per_run", label: "Branch and folder per run", group: "Git", values: ["ask", "true", "false"], help: "" },
|
|
125
|
+
{ key: "orchestration.enabled", label: "Build with workers", group: "Orchestration", values: ["false", "true"], help: "Off by default. A plan may split into workers, each in its own terminal and folder. Linux and macOS only" },
|
|
126
|
+
{ key: "orchestration.max_workers", label: "Max workers per run", group: "Orchestration", values: ["1", "2", "3", "4", "5", "6"], help: "Total per run", when: ["orchestration.enabled", "true"] },
|
|
127
|
+
{ key: "orchestration.permissions", label: "Worker permissions", group: "Orchestration", values: ["own", "bypass"], help: "own: each agent's own prompts. Bypass skips every prompt in every worker", when: ["orchestration.enabled", "true"] },
|
|
128
|
+
// One per tool that takes a model flag; a run freezes its own agent's. Empty: the run's own model.
|
|
129
|
+
...KNOWN_AGENTS.filter((a) => MODEL_FLAGS[a.cmd]).map((a): Setting => ({ key: `orchestration.worker_model.${a.cmd}`, label: `Worker model: ${a.name}`, group: "Orchestration", values: [], text: true, help: "The tool's own model name. Empty: the run's own model", when: ["orchestration.enabled", "true"] })),
|
|
123
130
|
{ key: "review.write_memory", label: "Remember lessons", group: "Project", values: ["true", "false"], help: "" },
|
|
124
131
|
{ key: "review.memory_max_lines", label: "Memory size cap", group: "Project", values: ["50", "100", "200", "400"], help: "" },
|
|
125
132
|
{ key: "state.keep_runs", label: "Runs to keep", group: "Project", values: ["5", "10", "20", "50"], help: "" },
|
|
@@ -485,7 +492,7 @@ function lineOf(text: string, key: string) {
|
|
|
485
492
|
return { lines, index: from - 1, indent: depth - 2 };
|
|
486
493
|
}
|
|
487
494
|
|
|
488
|
-
function read(text: string, key: string) {
|
|
495
|
+
export function read(text: string, key: string) {
|
|
489
496
|
const { lines, index } = lineOf(text, key);
|
|
490
497
|
if (index < 0) return null;
|
|
491
498
|
const v = lines[index]!.split(":").slice(1).join(":").split("#")[0]!.trim();
|
|
@@ -530,16 +537,17 @@ function insert(text: string, key: string, shown: string, defaults: string) {
|
|
|
530
537
|
return [...lines, "", ...block, ""].join("\n");
|
|
531
538
|
}
|
|
532
539
|
|
|
533
|
-
// Nested: put it under
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
540
|
+
// Nested: put it under the deepest parent that is there, writing the missing ones too.
|
|
541
|
+
let k = parts.length - 1;
|
|
542
|
+
while (k > 0 && lineOf(text, parts.slice(0, k).join(".")).index < 0) k--;
|
|
543
|
+
const add = [...parts.slice(k, -1).map((p, i) => `${" ".repeat((k + i) * 2)}${p}:`), ...block];
|
|
544
|
+
if (k === 0) {
|
|
537
545
|
while (lines.length && !lines[lines.length - 1]!.trim()) lines.pop();
|
|
538
|
-
return [...lines, "",
|
|
546
|
+
return [...lines, "", ...add, ""].join("\n");
|
|
539
547
|
}
|
|
540
|
-
let end =
|
|
548
|
+
let end = lineOf(text, parts.slice(0, k).join(".")).index + 1;
|
|
541
549
|
while (end < lines.length && (/^\s+\S/.test(lines[end]!) || !lines[end]!.trim())) end++;
|
|
542
|
-
lines.splice(end, 0, ...
|
|
550
|
+
lines.splice(end, 0, ...add);
|
|
543
551
|
return lines.join("\n");
|
|
544
552
|
}
|
|
545
553
|
|
package/cli/setup.test.ts
CHANGED
|
@@ -38,8 +38,8 @@ test("kaizen setup without a terminal prints the manual steps and writes nothing
|
|
|
38
38
|
const out = await new Response(p.stdout).text();
|
|
39
39
|
expect(await p.exited).toBe(0);
|
|
40
40
|
expect(out).toContain("tailscale serve --bg 127.0.0.1:7420");
|
|
41
|
-
// Bun
|
|
42
|
-
expect(readdirSync(homeDir).filter((n) => n !== ".bun")).toEqual([]);
|
|
41
|
+
// Bun's cache (~/.bun) and macOS's ~/Library land in HOME; only what kaizen writes counts.
|
|
42
|
+
expect(readdirSync(homeDir).filter((n) => n !== ".bun" && !(process.platform === "darwin" && n === "Library"))).toEqual([]);
|
|
43
43
|
expect(existsSync(join(homeDir, ".kaizen"))).toBe(false);
|
|
44
44
|
} finally { rmSync(homeDir, { recursive: true, force: true }); }
|
|
45
45
|
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { afterEach, beforeEach, expect, test } from "bun:test";
|
|
2
|
+
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readlinkSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { bundledSkills, setSkill, skillsOff, skillStatus, skillsToLink, SKILL_HOMES } from "./skills.ts";
|
|
6
|
+
|
|
7
|
+
let t: string, repo: string, home: string;
|
|
8
|
+
const skill = (rel: string, json?: object) => {
|
|
9
|
+
mkdirSync(join(repo, "skills", rel), { recursive: true });
|
|
10
|
+
writeFileSync(join(repo, "skills", rel, "SKILL.md"), `---\nname: x\ndescription: Does a thing. And more.\n---\n`);
|
|
11
|
+
if (json) writeFileSync(join(repo, "skills", rel, "skill.json"), JSON.stringify(json));
|
|
12
|
+
};
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
t = mkdtempSync(join(tmpdir(), "kz-skills-"));
|
|
15
|
+
repo = join(t, "repo"); home = join(t, "home");
|
|
16
|
+
mkdirSync(join(repo, "cli"), { recursive: true });
|
|
17
|
+
writeFileSync(join(repo, "cli", "install.ts"), "");
|
|
18
|
+
skill("kaizen", { group: "core" });
|
|
19
|
+
skill("media/kaizen-deck", { title: "Create deck", needs: ["x"] });
|
|
20
|
+
mkdirSync(join(home, ".claude", "skills"), { recursive: true });
|
|
21
|
+
symlinkSync(join(repo, "skills/media/kaizen-deck"), join(home, ".claude/skills/kaizen-deck"));
|
|
22
|
+
symlinkSync(join(repo, "skills/kaizen"), join(home, ".claude/skills/kaizen"));
|
|
23
|
+
});
|
|
24
|
+
afterEach(() => rmSync(t, { recursive: true, force: true }));
|
|
25
|
+
const link = () => join(home, ".claude/skills/kaizen-deck");
|
|
26
|
+
|
|
27
|
+
test("a new folder appears by itself, with its description; real skills all parse", () => {
|
|
28
|
+
skill("media/new-one");
|
|
29
|
+
const s = bundledSkills(repo).find((x) => x.id === "new-one")!;
|
|
30
|
+
expect([s.group, s.description]).toEqual(["media", "Does a thing."]);
|
|
31
|
+
const real = bundledSkills(join(import.meta.dir, ".."));
|
|
32
|
+
expect(real.map((x) => x.id).sort()).toEqual(["kaizen", "kaizen-book", "kaizen-computer", "kaizen-deck", "kaizen-help", "kaizen-video"]);
|
|
33
|
+
expect(real.filter((x) => x.group === "core").length).toBe(2);
|
|
34
|
+
for (const x of real) expect(x.description.length).toBeGreaterThan(10);
|
|
35
|
+
});
|
|
36
|
+
test("off removes our link and remembers; on restores it", () => {
|
|
37
|
+
expect(setSkill(repo, home, "kaizen-deck", false)).toBeNull();
|
|
38
|
+
expect(existsSync(link())).toBe(false);
|
|
39
|
+
expect(existsSync(join(repo, "skills/media/kaizen-deck/SKILL.md"))).toBe(true);
|
|
40
|
+
expect(skillsOff(home)).toEqual(["kaizen-deck"]);
|
|
41
|
+
expect(setSkill(repo, home, "kaizen-deck", true)).toBeNull();
|
|
42
|
+
expect(lstatSync(link()).isSymbolicLink()).toBe(true);
|
|
43
|
+
expect(skillsOff(home)).toEqual([]);
|
|
44
|
+
});
|
|
45
|
+
test("a real folder and a foreign link under the name stay", () => {
|
|
46
|
+
rmSync(link());
|
|
47
|
+
mkdirSync(link());
|
|
48
|
+
writeFileSync(join(link(), "mine"), "x");
|
|
49
|
+
setSkill(repo, home, "kaizen-deck", false);
|
|
50
|
+
expect(readFileSync(join(link(), "mine"), "utf8")).toBe("x");
|
|
51
|
+
expect(skillStatus(bundledSkills(repo)[1]!, home)[0]!.state).toBe("other");
|
|
52
|
+
rmSync(link(), { recursive: true });
|
|
53
|
+
mkdirSync(join(t, "skills/media/kaizen-deck"), { recursive: true }); // not a clone: no cli/install.ts
|
|
54
|
+
symlinkSync(join(t, "skills/media/kaizen-deck"), link());
|
|
55
|
+
setSkill(repo, home, "kaizen-deck", false);
|
|
56
|
+
expect(lstatSync(link()).isSymbolicLink()).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
test("core and unknown names are refused", () => {
|
|
59
|
+
expect(setSkill(repo, home, "kaizen", false)).toMatch(/Core/);
|
|
60
|
+
expect(existsSync(join(home, ".claude/skills/kaizen"))).toBe(true);
|
|
61
|
+
expect(setSkill(repo, home, "../../x", false)).toBe("unknown skill");
|
|
62
|
+
});
|
|
63
|
+
test("the agent list stays the installer's, and install filters the off-list", () => {
|
|
64
|
+
const src = readFileSync(join(import.meta.dir, "install.ts"), "utf8");
|
|
65
|
+
for (const h of SKILL_HOMES) expect(src).toContain(`dir: "${h.dir}"`);
|
|
66
|
+
expect(dirname(link())).toContain(".claude");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("install: off skills stay out globally, not in a project, and core always links", () => {
|
|
70
|
+
const rels = ["kaizen", "media/kaizen-deck"], off = ["kaizen", "kaizen-deck"];
|
|
71
|
+
expect(skillsToLink(rels, off, true)).toEqual(["kaizen"]);
|
|
72
|
+
expect(skillsToLink(rels, off, false)).toEqual(rels);
|
|
73
|
+
});
|
|
74
|
+
test("core holds with no manifest; a whole description is read; a restore follows the installed clone", () => {
|
|
75
|
+
rmSync(join(repo, "skills/kaizen/skill.json"));
|
|
76
|
+
expect(setSkill(repo, home, "kaizen", false)).toMatch(/Core/);
|
|
77
|
+
writeFileSync(join(repo, "skills/kaizen/SKILL.md"), "---\nname: x\ndescription: One line\n goes on here. Next.\nother: y\n---\n");
|
|
78
|
+
expect(bundledSkills(repo)[0]!.description).toBe("One line goes on here.");
|
|
79
|
+
const other = join(t, "clone");
|
|
80
|
+
mkdirSync(join(other, "cli"), { recursive: true });
|
|
81
|
+
writeFileSync(join(other, "cli", "install.ts"), "");
|
|
82
|
+
mkdirSync(join(other, "skills/media/kaizen-deck"), { recursive: true });
|
|
83
|
+
mkdirSync(join(other, "skills/kaizen"), { recursive: true });
|
|
84
|
+
rmSync(join(home, ".claude/skills/kaizen"));
|
|
85
|
+
symlinkSync(join(other, "skills/kaizen"), join(home, ".claude/skills/kaizen"));
|
|
86
|
+
rmSync(link());
|
|
87
|
+
setSkill(repo, home, "kaizen-deck", true);
|
|
88
|
+
expect(readlinkSync(link())).toBe(join(other, "skills/media/kaizen-deck"));
|
|
89
|
+
});
|