kaizen-agent 1.64.3 → 1.65.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.
Files changed (81) hide show
  1. package/cli/install.ts +9 -0
  2. package/cli/roadmap.ts +74 -0
  3. package/cli/skills.ts +1 -1
  4. package/cli/web.ts +55 -1
  5. package/commands/kaizen-concept.md +6 -0
  6. package/commands/kaizen-roadmap.md +6 -0
  7. package/package.json +4 -2
  8. package/skills/kaizen/SKILL.md +12 -0
  9. package/skills/kaizen/roadmap.md +25 -0
  10. package/skills/kaizen/spec-main.md +27 -0
  11. package/skills/kaizen/spec-plan.md +37 -11
  12. package/skills/kaizen-concept/SKILL.md +262 -0
  13. package/skills/kaizen-concept/skill.json +1 -0
  14. package/skills/kaizen-help/SKILL.md +2 -0
  15. package/web/board/chat.ts +4 -3
  16. package/web/board/run-view.ts +18 -3
  17. package/web/board/ws-tabs.ts +9 -0
  18. package/web/board.js +102 -102
  19. package/web/notebook.js +1 -1
  20. package/web/term.js +1 -1
  21. package/web/video.js +1 -1
  22. package/cli/__pycache__/computer-helper.cpython-314.pyc +0 -0
  23. package/cli/accounts.test.ts +0 -126
  24. package/cli/add-project.test.ts +0 -169
  25. package/cli/agent-prefs.test.ts +0 -127
  26. package/cli/automations.test.ts +0 -167
  27. package/cli/backlog.test.ts +0 -133
  28. package/cli/board.test.ts +0 -381
  29. package/cli/browser.test.ts +0 -132
  30. package/cli/chat.test.ts +0 -274
  31. package/cli/chatgpt.test.ts +0 -158
  32. package/cli/computer.test.ts +0 -155
  33. package/cli/docs.test.ts +0 -94
  34. package/cli/handoff.test.ts +0 -133
  35. package/cli/html.test.ts +0 -19
  36. package/cli/install.test.ts +0 -237
  37. package/cli/knowledge.test.ts +0 -179
  38. package/cli/localsend.test.ts +0 -84
  39. package/cli/logo.test.ts +0 -18
  40. package/cli/notes.test.ts +0 -249
  41. package/cli/onboarding.test.ts +0 -70
  42. package/cli/project-tree.test.ts +0 -40
  43. package/cli/pty.test.ts +0 -330
  44. package/cli/release.test.ts +0 -12
  45. package/cli/report.test.ts +0 -59
  46. package/cli/resources.test.ts +0 -50
  47. package/cli/restart.test.ts +0 -222
  48. package/cli/settings.test.ts +0 -168
  49. package/cli/setup.test.ts +0 -78
  50. package/cli/shell-agent.test.ts +0 -23
  51. package/cli/skills.test.ts +0 -95
  52. package/cli/sources.test.ts +0 -851
  53. package/cli/state.test.ts +0 -1639
  54. package/cli/term-image.test.ts +0 -23
  55. package/cli/usage.test.ts +0 -291
  56. package/cli/versions.test.ts +0 -154
  57. package/cli/video.test.ts +0 -545
  58. package/cli/web-accept.test.ts +0 -55
  59. package/cli/web-decide.test.ts +0 -54
  60. package/cli/web-pr.test.ts +0 -52
  61. package/cli/web-skills.test.ts +0 -32
  62. package/cli/web-symlink.test.ts +0 -29
  63. package/cli/workers.test.ts +0 -319
  64. package/cli/worktree.test.ts +0 -452
  65. package/cli/writeback.test.ts +0 -102
  66. package/skills/media/kaizen-video/scripts/__pycache__/intake.cpython-314.pyc +0 -0
  67. package/skills/media/kaizen-video/scripts/__pycache__/make_film.cpython-314.pyc +0 -0
  68. package/skills/media/kaizen-video/scripts/__pycache__/make_tiktok.cpython-314.pyc +0 -0
  69. package/skills/media/kaizen-video/scripts/__pycache__/render_cut.cpython-314.pyc +0 -0
  70. package/skills/media/kaizen-video/scripts/__pycache__/sfx.cpython-314.pyc +0 -0
  71. package/skills/media/kaizen-video/scripts/__pycache__/srt.cpython-314.pyc +0 -0
  72. package/skills/media/kaizen-video/scripts/__pycache__/transcribe.cpython-314.pyc +0 -0
  73. package/skills/media/kaizen-video/scripts/__pycache__/vo.cpython-314.pyc +0 -0
  74. package/web/board/search.test.ts +0 -20
  75. package/web/board/settings-pages.test.ts +0 -28
  76. package/web/board/settings-voice.test.ts +0 -18
  77. package/web/board/toast.test.ts +0 -77
  78. package/web/board/ws-board.test.ts +0 -77
  79. package/web/board/ws-name.test.ts +0 -10
  80. package/web/board/ws-tabs.test.ts +0 -213
  81. package/web/term-font.test.ts +0 -22
@@ -1,167 +0,0 @@
1
- import { expect, test } from "bun:test";
2
- import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
5
- import { addRule, DAILY_CAP, dueSince, fire, nextRun, parseCron, patchRule, presetCron, promptOf, readHistory, readRules, runOf, shellArgv, shown, tickAutomations, type Rule } from "./automations.ts";
6
-
7
- // Nothing here starts an agent or a terminal: every launch is the fake below.
8
- const proj = () => { const d = mkdtempSync(join(tmpdir(), "kz-auto-")); const st = join(d, ".kaizen"); mkdirSync(join(st, "runs"), { recursive: true }); return st; };
9
- const at = (y: number, mo: number, d: number, h = 0, mi = 0) => new Date(y, mo - 1, d, h, mi).getTime();
10
- const spy = (ok = true) => { const calls: { it: any; from: string; pick: any }[] = []; return { calls, launch: ((it: any, from: string, _r: any, pick: any) => { calls.push({ it, from, pick }); return ok ? { ok: true } : { ok: false, why: "no terminal" }; }) as any }; };
11
- const mk = (st: string, o: any = {}): Rule => { const r = addRule(st, { name: "n", text: "check things", kind: "hourly", time: "09:05", ...o }); if (typeof r === "string") throw new Error(r); return r; };
12
- const run = (st: string, id: string, text: string, stage = "plan", awaiting?: string) => { mkdirSync(join(st, "runs", id), { recursive: true }); writeFileSync(join(st, "runs", id, "00-request.md"), text); writeFileSync(join(st, "runs", id, "state.json"), JSON.stringify({ stage, awaiting })); };
13
-
14
- test("G-01 cron parse and next run", () => {
15
- expect(nextRun("*/15 * * * *", at(2026, 1, 5, 10, 1))).toBe(at(2026, 1, 5, 10, 15));
16
- expect(nextRun("0 9 * * 1-5", at(2026, 1, 9, 10))).toBe(at(2026, 1, 12, 9)); // Fri -> Mon
17
- expect(nextRun("0 9 * * 0", at(2026, 1, 5))).toBe(at(2026, 1, 11, 9));
18
- expect(nextRun("0 9 * * 7", at(2026, 1, 5))).toBe(at(2026, 1, 11, 9));
19
- expect(nextRun("0 9 1,15 * 1", at(2026, 1, 2))).toBe(at(2026, 1, 5, 9)); // dom or dow
20
- expect(nextRun("0 9 1-3 * *", at(2026, 1, 4))).toBe(at(2026, 2, 1, 9));
21
- for (const bad of ["@daily", "0 9 * * mon", "61 * * * *", "0 0 ? * *", "* * * *", "0 0 L * *", "*/0 * * * *"]) expect(typeof parseCron(bad)).toBe("string");
22
- expect(nextRun("0 0 31 2 *", Date.now())).toBeNull();
23
- expect(typeof addRule(proj(), { name: "x", text: "abc", kind: "cron", cron: "0 0 31 2 *" })).toBe("string");
24
- expect(presetCron("weekdays", "09:30", "mon")).toBe("30 9 * * 1-5");
25
- expect(presetCron("weekly", "09:30", "fri")).toBe("30 9 * * 5");
26
- expect(presetCron("hourly", "09:05", "")).toBe("5 * * * *");
27
- // the minute walk keeps a daily time across a DST change (whatever the machine's zone does)
28
- const a = nextRun("0 9 * * *", at(2026, 3, 7, 12))!, b = nextRun("0 9 * * *", at(2026, 11, 1, 12))!;
29
- expect([new Date(a).getHours(), new Date(b).getHours()]).toEqual([9, 9]);
30
- });
31
-
32
- test("G-02/G-03 one fire per due minute, even from two boards", async () => {
33
- const st = proj(), r = mk(st), s = spy(), due = at(2026, 1, 5, 9, 5);
34
- const out = await Promise.all([fire(st, r, "scheduled", due, { launch: s.launch }), fire(st, r, "scheduled", due, { launch: s.launch })]);
35
- expect(out.filter(Boolean).length).toBe(1);
36
- expect(s.calls.length).toBe(1);
37
- expect(readHistory(st).length).toBe(1);
38
- expect(await fire(st, r, "scheduled", due, { launch: s.launch })).toBeNull();
39
- });
40
-
41
- test("G-04 grace: a short outage fires once, a long one is skipped, a new rule never fires for the past", async () => {
42
- const st = proj(), r = mk(st), s = spy();
43
- const base = r.last_fired_for;
44
- await tickAutomations([st], { launch: s.launch, now: () => base + 30_000 });
45
- expect(s.calls.length).toBe(0);
46
- const st2 = proj(); const r2 = mk(st2, { kind: "daily", time: "09:00" }); const s2 = spy();
47
- patchRule(st2, r2.id, (x) => ({ ...x, last_fired_for: at(2026, 1, 1) }));
48
- await tickAutomations([st2], { launch: s2.launch, now: () => at(2026, 1, 4, 9, 30) }); // three days: only the last slot, 30 min old
49
- expect(s2.calls.length).toBe(1);
50
- const st3 = proj(); const r3 = mk(st3, { kind: "daily", time: "09:00" }); const s3 = spy();
51
- patchRule(st3, r3.id, (x) => ({ ...x, last_fired_for: at(2026, 1, 1) }));
52
- await tickAutomations([st3], { launch: s3.launch, now: () => at(2026, 1, 4, 23, 0) }); // 14 h > 12 h grace
53
- expect(s3.calls.length).toBe(0);
54
- expect(readHistory(st3)[0]!.status).toBe("skipped_missed");
55
- await tickAutomations([st3], { launch: s3.launch, now: () => at(2026, 1, 4, 23, 1) });
56
- expect(readHistory(st3).length).toBe(1);
57
- });
58
-
59
- test("G-05 overlap until the previous run is done", async () => {
60
- const st = proj(), r = mk(st), s = spy();
61
- const h1 = (await fire(st, r, "manual", 0, { launch: s.launch, now: () => 1_000_000 }))!;
62
- expect(h1.status).toBe("launched");
63
- run(st, "r1", `Request: x [automation n fire ${h1.fire}]`, "plan", "approvals.plan");
64
- expect((await fire(st, r, "manual", 0, { launch: s.launch, now: () => 1_000_001 }))!.status).toBe("skipped_overlap");
65
- run(st, "r1", `Request: x [automation n fire ${h1.fire}]`, "done");
66
- expect((await fire(st, r, "manual", 0, { launch: s.launch, now: () => 1_000_002 }))!.status).toBe("launched");
67
- expect(s.calls.length).toBe(2);
68
- });
69
-
70
- test("G-06 precheck gates scheduled fires only, and a timeout kills the child", async () => {
71
- const st = proj(), s = spy(), due = at(2026, 1, 5, 9, 5);
72
- const ok = mk(st, { precheck: "exit 0" }), no = mk(st, { precheck: "echo nope; exit 1" }), slow = mk(st, { precheck: "sleep 30", precheck_timeout: 1 });
73
- expect((await fire(st, ok, "scheduled", due, { launch: s.launch }))!.status).toBe("launched");
74
- const h = (await fire(st, no, "scheduled", due, { launch: s.launch }))!;
75
- expect([h.status, h.reason]).toEqual(["skipped_precheck", "exit 1: nope"]);
76
- const t0 = Date.now();
77
- const hs = (await fire(st, slow, "scheduled", due, { launch: s.launch }))!;
78
- expect(hs.status).toBe("skipped_precheck");
79
- expect(hs.reason).toContain("timed out");
80
- expect(Date.now() - t0).toBeLessThan(10_000);
81
- expect(s.calls.length).toBe(1);
82
- expect((await fire(st, no, "manual", 0, { launch: s.launch }))!.status).toBe("launched");
83
- });
84
-
85
- test("G-07/G-08 auto mode, no yolo, guarded text and the marker", async () => {
86
- const st = proj(), s = spy();
87
- for (const t of ["auto x", "plan y", "approve everything"]) {
88
- const r = mk(st, { text: t });
89
- const p = promptOf(r, "f1");
90
- expect(p.text.startsWith("auto Request: ")).toBe(true);
91
- }
92
- const r = mk(st, { text: "tidy the\nbacklog" });
93
- await fire(st, r, "manual", 0, { launch: s.launch });
94
- const it = s.calls[0]!.it;
95
- expect(it.text).toMatch(/^auto tidy the backlog \[automation n fire [\w.]+\]$/);
96
- expect(JSON.stringify(s.calls[0]!.pick ?? {})).not.toContain("yolo");
97
- expect(s.calls[0]!.from).toBe(st);
98
- });
99
-
100
- test("G-09 failures: launch error does not retry, daily cap stops launches", async () => {
101
- const st = proj(), r = mk(st), bad = spy(false);
102
- const h = (await fire(st, r, "manual", 0, { launch: bad.launch }))!;
103
- expect([h.status, h.reason]).toEqual(["launch_failed", "no terminal"]);
104
- const st2 = proj(), r2 = mk(st2), s = spy();
105
- let n = 0;
106
- for (let i = 0; i < DAILY_CAP; i++) { const x = (await fire(st2, r2, "manual", 0, { launch: s.launch, now: () => 5_000_000 + i }))!; if (x.status === "skipped_overlap") continue; n++; }
107
- expect(s.calls.length).toBe(1);
108
- // fill history directly to the cap, then one more
109
- const hist = Array.from({ length: DAILY_CAP }, (_, i) => ({ rule: r2.id, fire: `x${i}`, due: 0, at: 9_000_000 + i, kind: "manual", status: "launch_failed" }));
110
- writeFileSync(join(st2, "automation-runs.json"), JSON.stringify(hist));
111
- expect((await fire(st2, r2, "manual", 0, { launch: s.launch, now: () => 9_100_000 }))!.status).toBe("skipped_cap");
112
- expect(n).toBeGreaterThan(0);
113
- });
114
-
115
- test("G-10 files: a corrupt rules file is not overwritten; history keeps 100", async () => {
116
- const st = proj();
117
- writeFileSync(join(st, "automations.json"), "{nope");
118
- expect(await tickAutomations([st], { launch: spy().launch })).toBe(false);
119
- expect(readFileSync(join(st, "automations.json"), "utf8")).toBe("{nope");
120
- expect(typeof addRule(st, { name: "x", text: "abc", kind: "hourly" })).toBe("string");
121
- expect(() => readRules(st)).toThrow();
122
- const st2 = proj(), r = mk(st2), s = spy();
123
- for (let i = 0; i < 105; i++) await fire(st2, r, "manual", 0, { launch: s.launch, now: () => 1_000 + i * 2 * 86_400_000 }).catch(() => 0);
124
- expect(readHistory(st2).length).toBeLessThanOrEqual(100);
125
- });
126
-
127
- test("G-11 a rule launches in its own project only", async () => {
128
- const a = proj(), b = proj(), s = spy();
129
- const r = mk(a);
130
- await fire(a, r, "manual", 0, { launch: s.launch });
131
- expect(s.calls[0]!.from).toBe(a);
132
- expect(readHistory(b).length).toBe(0);
133
- });
134
-
135
- test("G-12 a history line follows its run", async () => {
136
- const st = proj(), r = mk(st), s = spy();
137
- const h = (await fire(st, r, "manual", 0, { launch: s.launch }))!;
138
- expect(runOf(st, h.fire)).toBeNull();
139
- expect(shown(st, h, h.at + 60_000).status).toBe("launched");
140
- expect(shown(st, h, h.at + 16 * 60_000).status).toBe("launch_failed");
141
- run(st, "r9", `auto Request: x [automation n fire ${h.fire}]`, "build");
142
- expect(shown(st, h)).toEqual({ status: "running", run: "r9" });
143
- expect(runOf(st, h.fire.slice(0, -1))).toBeNull(); // a longer id is not a prefix match
144
- });
145
-
146
- test("G-13 the module never approves, passes yolo or runs kaizen approve", () => {
147
- const src = readFileSync(join(import.meta.dir, "automations.ts"), "utf8").split("\n").filter((l) => !l.trim().startsWith("//")).join("\n");
148
- expect(src).not.toMatch(/yolo:|\bapprove\w*\(|kaizen approve|"\/approve/i);
149
- expect(dueSince("* * * * *", 0, 0)).toBeNull();
150
- });
151
-
152
- test("fix: a launch that lost its marker still blocks for a day; a live terminal blocks a done run", async () => {
153
- const st = proj(), r = mk(st), s = spy();
154
- const h1 = (await fire(st, r, "manual", 0, { launch: s.launch, now: () => 1_000_000 }))!;
155
- const t = h1.at + 2 * 3_600_000; // marker never reached 00-request.md, past the 15 minute mark
156
- expect((await fire(st, r, "manual", 0, { launch: s.launch, now: () => t }))!.status).toBe("skipped_overlap");
157
- const h = h1.at + 25 * 3_600_000;
158
- expect((await fire(st, r, "manual", 0, { launch: s.launch, now: () => h }))!.status).toBe("launched");
159
- const st2 = proj(), r2 = mk(st2), h2 = (await fire(st2, r2, "manual", 0, { launch: s.launch, now: () => 1_000_000 }))!;
160
- run(st2, "r1", `Request: x [automation n fire ${h2.fire}]`, "done");
161
- expect((await fire(st2, r2, "manual", 0, { launch: s.launch, now: () => 1_000_001, live: (_s, id) => id === "r1" }))!.status).toBe("skipped_overlap");
162
- });
163
-
164
- test("fix: the precheck shell per platform", () => {
165
- expect(shellArgv("echo hi", true)).toEqual(["cmd", "/c", "echo hi"]);
166
- expect(shellArgv("echo hi", false)).toEqual(["sh", "-c", "echo hi"]);
167
- });
@@ -1,133 +0,0 @@
1
- // Backlog items as cards in the board's Tasks column: numbering, hiding while a run
2
- // started from one lives, closing in place, and the board routes that drive them.
3
- import { test, expect } from "bun:test";
4
- import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, statSync } from "node:fs";
5
- import { join, dirname } from "node:path";
6
- import { tmpdir } from "node:os";
7
- import { backlogLines, backlogCards, startedBacklog, closeBacklog, markBacklogDone, backlogItem } from "./state.ts";
8
- import { boardIndex } from "./notes.ts";
9
-
10
- const scratch = () => {
11
- const state = join(mkdtempSync(join(tmpdir(), "kz-bl-")), ".kaizen");
12
- const run = (id: string, stage: string, files: Record<string, string> = {}) => {
13
- const dir = join(state, "runs", id);
14
- mkdirSync(dir, { recursive: true });
15
- writeFileSync(join(dir, "state.json"), JSON.stringify({ id, stage, awaiting: null }));
16
- for (const [f, t] of Object.entries(files)) writeFileSync(join(dir, f), t);
17
- return dir;
18
- };
19
- return { state, run };
20
- };
21
-
22
- const BACKLOG = "# Backlog\n\n- open: `cli/x.ts:12`: low: first thing. Fix: do it.\n- done: closed one | run y\n- open: high: urgent thing\n a note under it\n- rejected: no | why\n- open: plain item\n";
23
-
24
- test("backlogLines numbers every open, done and rejected line as boardIndex does", () => {
25
- const { state, run } = scratch();
26
- run("2026-10-01-src", "done", { "06-backlog.md": BACKLOG });
27
- const lines = backlogLines(join(state, "runs", "2026-10-01-src", "06-backlog.md"));
28
- expect(lines.map((l) => [l.n, l.status])).toEqual([[1, "open"], [2, "done"], [3, "open"], [4, "rejected"], [5, "open"]]);
29
- const idx = boardIndex(state).runs.find((r) => r.id === "2026-10-01-src")!.backlog;
30
- expect(idx).toEqual(lines.map(({ n, status, text }) => ({ n, status, text })));
31
- expect(backlogLines(join(state, "nope.md"))).toEqual([]);
32
- });
33
-
34
- test("backlogCards: open items of live runs and the orphanage, most severe first; abandoned runs skipped", () => {
35
- const { state, run } = scratch();
36
- run("2026-10-01-src", "done", { "06-backlog.md": BACKLOG });
37
- run("2026-10-02-gone", "abandoned", { "06-backlog.md": "- open: critical: from an abandoned run\n" });
38
- writeFileSync(join(state, "backlog.md"), "- open: rescued item | from 2026-09-01-old\n");
39
- const cards = backlogCards([state]);
40
- expect(cards.map((c) => [c.source, c.n, c.severity])).toEqual([
41
- ["2026-10-01-src", 3, "high"], ["2026-10-01-src", 1, "low"], ["2026-10-01-src", 5, null], ["orphan", 1, null],
42
- ]);
43
- expect(cards[1]).toMatchObject({ text: "first thing.", at: "x.ts:12", raw: "`cli/x.ts:12`: low: first thing. Fix: do it." });
44
- });
45
-
46
- test("a run started from an item hides its card; an abandoned one gives it back", () => {
47
- const { state, run } = scratch();
48
- run("2026-10-01-src", "done", { "06-backlog.md": BACKLOG });
49
- const kid = run("2026-10-03-kid", "plan", { "00-request.md": "/kaizen urgent thing\n\nParent: 2026-10-01-src\nBacklog: 2026-10-01-src#3\n" });
50
- expect(startedBacklog(state).get("2026-10-01-src#3")).toEqual([{ id: "2026-10-03-kid", stage: "plan" }]);
51
- expect(backlogCards([state]).some((c) => c.n === 3)).toBe(false);
52
- writeFileSync(join(kid, "state.json"), JSON.stringify({ stage: "abandoned" }));
53
- expect(backlogCards([state]).some((c) => c.n === 3)).toBe(true);
54
- });
55
-
56
- test("markBacklogDone closes only the line its done run names, once, and touches no state.json", () => {
57
- const { state, run } = scratch();
58
- const src = run("2026-10-01-src", "done", { "06-backlog.md": BACKLOG });
59
- run("2026-10-03-kid", "build", { "00-request.md": "x\n\nBacklog: 2026-10-01-src#3\n" });
60
- run("2026-10-04-orph", "done", { "00-request.md": "y\n\nBacklog: orphan#1\n" });
61
- writeFileSync(join(state, "backlog.md"), "- open: rescued item | from 2026-09-01-old\n");
62
- markBacklogDone(state);
63
- expect(readFileSync(join(src, "06-backlog.md"), "utf8")).toBe(BACKLOG); // still building
64
- expect(readFileSync(join(state, "backlog.md"), "utf8")).toBe("- open: rescued item | from 2026-09-01-old | 2026-10-04-orph\n".replace("open", "done"));
65
- const kidState = join(state, "runs", "2026-10-03-kid", "state.json");
66
- writeFileSync(kidState, JSON.stringify({ stage: "done" }));
67
- const before = statSync(kidState).mtimeMs;
68
- markBacklogDone(state);
69
- markBacklogDone(state);
70
- expect(readFileSync(join(src, "06-backlog.md"), "utf8")).toBe(BACKLOG.replace("- open: high: urgent thing", "- done: high: urgent thing | 2026-10-03-kid"));
71
- expect(statSync(kidState).mtimeMs).toBe(before);
72
- expect(backlogCards([state]).map((c) => c.n)).toEqual([1, 5]);
73
- });
74
-
75
- test("closeBacklog rewrites one open line in place and keeps CRLF; refuses closed or missing lines", () => {
76
- const { state, run } = scratch();
77
- const src = run("2026-10-01-src", "done", { "06-backlog.md": BACKLOG.replace(/\n/g, "\r\n") });
78
- expect(closeBacklog(state, "2026-10-01-src", 5, "rejected", "not worth it")).toBeNull();
79
- expect(readFileSync(join(src, "06-backlog.md"), "utf8")).toBe(BACKLOG.replace("- open: plain item", "- rejected: plain item | not worth it").replace(/\n/g, "\r\n"));
80
- expect(closeBacklog(state, "2026-10-01-src", 2, "rejected", "x")).toBe("that item is already closed");
81
- expect(closeBacklog(state, "2026-10-01-src", 9, "rejected", "x")).toBe("no such backlog item");
82
- expect(closeBacklog(state, "../../etc", 1, "rejected", "x")).toBe("no such backlog");
83
- expect(backlogItem(state, "2026-10-01-src", 5)?.status).toBe("rejected");
84
- });
85
-
86
- // The real server in a scratch home. Linux only: launching is made to fail before any
87
- // terminal or agent opens (no display, no terminal on PATH, terminal launch mode), and
88
- // the manual command it hands back is the request a run would have been given.
89
- test.skipIf(process.platform !== "linux")("board routes: /state lists backlog cards, /backlog rejects, /run carries the item's source", async () => {
90
- const homeDir = mkdtempSync(join(tmpdir(), "kz-bl-home-")), proj = join(homeDir, "p"), state = join(proj, ".kaizen");
91
- for (const d of [state, join(homeDir, ".kaizen"), join(homeDir, ".claude")]) mkdirSync(d, { recursive: true });
92
- writeFileSync(join(homeDir, ".kaizen", "projects"), proj + "\n");
93
- writeFileSync(join(homeDir, ".kaizen", "config.yml"), "agent:\n launch: terminal\n");
94
- const src = join(state, "runs", "2026-10-01-src");
95
- mkdirSync(src, { recursive: true });
96
- writeFileSync(join(src, "state.json"), JSON.stringify({ stage: "done", awaiting: null }));
97
- writeFileSync(join(src, "06-backlog.md"), BACKLOG);
98
- const port = 20000 + Math.floor(Math.random() * 20000);
99
- const repo = join(import.meta.dir, "..");
100
- const env: Record<string, string> = { HOME: homeDir, USERPROFILE: homeDir, KAIZEN_HOME: repo, PATH: dirname(process.execPath), DISPLAY: "", WAYLAND_DISPLAY: "", TERMINAL: "", TMUX: "" };
101
- const proc = Bun.spawn([process.execPath, join(repo, "cli", "install.ts"), "web", "--port", String(port), "--no-open", "--foreground"], { cwd: proj, env, stdout: "ignore", stderr: "ignore" });
102
- try {
103
- const at = `http://127.0.0.1:${port}`;
104
- for (let i = 0; ; i++) { try { await fetch(at + "/state"); break; } catch { if (i > 100) throw new Error("board did not start"); await Bun.sleep(50); } }
105
- const post = async (path: string, body: object) => { const r = await fetch(at + path, { method: "POST", body: JSON.stringify({ dir: state, ...body }) }); return { status: r.status, ...(await r.json() as any) }; };
106
- const listed = async () => ((await (await fetch(at + "/state?all=1")).json()) as any).backlog.map((b: any) => [b.source, b.n]);
107
- expect(await listed()).toEqual([["2026-10-01-src", 3], ["2026-10-01-src", 1], ["2026-10-01-src", 5]]);
108
-
109
- expect(await post("/backlog", { op: "reject", source: "2026-10-01-src", n: 5, reason: "" })).toMatchObject({ status: 400 });
110
- expect(await post("/backlog", { op: "reject", source: "2026-10-01-src", n: 5, reason: "not now" })).toMatchObject({ status: 200 });
111
- expect(await post("/backlog", { op: "reject", source: "2026-10-01-src", n: 5, reason: "again" })).toMatchObject({ status: 409 });
112
- expect(await post("/backlog", { op: "reject", source: "2026-10-01-src", n: 42, reason: "x" })).toMatchObject({ status: 404 });
113
- expect(readFileSync(join(src, "06-backlog.md"), "utf8")).toContain("- rejected: plain item | not now\n");
114
- expect(await listed()).toEqual([["2026-10-01-src", 3], ["2026-10-01-src", 1]]);
115
-
116
- expect(await post("/run", { backlog: { source: "2026-10-01-src", n: 2 } })).toMatchObject({ status: 409 });
117
- expect(await post("/run", { backlog: { source: "2026-10-01-src", n: 42 } })).toMatchObject({ status: 404 });
118
- const r = await post("/run", { kind: "lite", backlog: { source: "2026-10-01-src", n: 1 } });
119
- expect(r).toMatchObject({ status: 500, ok: false });
120
- expect(r.manual).toContain("/kaizen lite first thing. (x.ts:12)");
121
- expect(r.manual).toContain("Parent: 2026-10-01-src");
122
- expect(r.manual).toContain("Backlog: 2026-10-01-src#1");
123
- expect(r.manual).toContain("Backlog item: `cli/x.ts:12`: low: first thing. Fix: do it.");
124
-
125
- // Once a run carries the line, a second start is refused and the card is gone.
126
- const kid = join(state, "runs", "2026-10-05-kid");
127
- mkdirSync(kid, { recursive: true });
128
- writeFileSync(join(kid, "state.json"), JSON.stringify({ stage: "plan", awaiting: null }));
129
- writeFileSync(join(kid, "00-request.md"), "first thing\n\nParent: 2026-10-01-src\nBacklog: 2026-10-01-src#1\n");
130
- expect(await post("/run", { backlog: { source: "2026-10-01-src", n: 1 } })).toMatchObject({ status: 409 });
131
- expect(await listed()).toEqual([["2026-10-01-src", 3]]);
132
- } finally { proc.kill(); await proc.exited; }
133
- }, 30_000);