kaizen-agent 1.59.2 → 1.60.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/cli/add-project.test.ts +169 -0
  2. package/cli/add-project.ts +132 -0
  3. package/cli/board.test.ts +15 -0
  4. package/cli/chat.ts +1 -1
  5. package/cli/dashboard.ts +6 -2
  6. package/cli/install.test.ts +1 -1
  7. package/cli/install.ts +18 -9
  8. package/cli/pty.test.ts +89 -5
  9. package/cli/pty.ts +126 -9
  10. package/cli/restart.test.ts +169 -0
  11. package/cli/settings.test.ts +35 -0
  12. package/cli/settings.ts +69 -18
  13. package/cli/state.test.ts +119 -3
  14. package/cli/state.ts +171 -13
  15. package/cli/usage.test.ts +130 -1
  16. package/cli/web-accept.test.ts +54 -0
  17. package/cli/web-pr.test.ts +51 -0
  18. package/cli/web-symlink.test.ts +28 -0
  19. package/cli/web.ts +349 -100
  20. package/cli/worktree.test.ts +146 -1
  21. package/cli/worktree.ts +214 -4
  22. package/cli/writeback.ts +1 -1
  23. package/package.json +1 -1
  24. package/skills/kaizen/SKILL.md +5 -1
  25. package/skills/kaizen/config.default.yml +15 -2
  26. package/skills/kaizen/settings.md +1 -0
  27. package/skills/kaizen/spec-main.md +28 -2
  28. package/skills/kaizen-help/SKILL.md +1 -0
  29. package/web/board/add-project.ts +136 -0
  30. package/web/board/api.ts +1 -1
  31. package/web/board/badge.ts +5 -5
  32. package/web/board/cards.ts +11 -3
  33. package/web/board/context.ts +1 -0
  34. package/web/board/fixes.ts +3 -2
  35. package/web/board/git.ts +309 -60
  36. package/web/board/home.ts +7 -1
  37. package/web/board/ideas.ts +20 -3
  38. package/web/board/live.ts +1 -1
  39. package/web/board/main.ts +26 -9
  40. package/web/board/panel.ts +31 -16
  41. package/web/board/projects.ts +6 -85
  42. package/web/board/run-pick.ts +41 -0
  43. package/web/board/run-view.ts +286 -110
  44. package/web/board/search-match.ts +20 -0
  45. package/web/board/search.test.ts +20 -0
  46. package/web/board/search.ts +324 -0
  47. package/web/board/settings.ts +42 -5
  48. package/web/board/store.ts +3 -1
  49. package/web/board/toast.ts +4 -1
  50. package/web/board/views.ts +3 -1
  51. package/web/board/workspace.ts +127 -38
  52. package/web/board/ws-board-ui.ts +95 -0
  53. package/web/board/ws-board.test.ts +71 -0
  54. package/web/board/ws-board.ts +45 -0
  55. package/web/board/ws-tabs.test.ts +181 -0
  56. package/web/board/ws-tabs.ts +173 -0
  57. package/web/board.html +86 -36
  58. package/web/board.js +129 -44
  59. package/web/notebook.js +41 -24
  60. package/web/notes.html +26 -20
  61. package/web/term.js +1 -1
  62. package/web/video.html +26 -20
  63. package/web/video.js +76 -59
@@ -0,0 +1,54 @@
1
+ import { expect, test } from "bun:test";
2
+ import { existsSync, mkdtempSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { healRuns } from "./state.ts";
6
+
7
+ // A healed run (done by its agent, never approved) is approved by /accept: the line and
8
+ // the finish, no agent launched. A genuine review is refused there and goes through /decide.
9
+ test.skipIf(process.platform === "win32")("board /accept finishes a healed run without launching an agent", async () => {
10
+ const home = realpathSync(mkdtempSync(join(tmpdir(), "kz-acc-")));
11
+ const proj = join(home, "proj"), st = join(proj, ".kaizen");
12
+ mkdirSync(join(proj, "cli"), { recursive: true });
13
+ writeFileSync(join(proj, "cli", "a.ts"), "");
14
+ mkdirSync(join(home, ".kaizen"), { recursive: true });
15
+ writeFileSync(join(home, ".kaizen", "projects"), proj + "\n");
16
+ const mk = (id: string, state: object) => {
17
+ const d = join(st, "runs", id);
18
+ mkdirSync(d, { recursive: true });
19
+ writeFileSync(join(d, "state.json"), JSON.stringify(state));
20
+ writeFileSync(join(d, "03-impl.md"), "## Changed\n- `cli/a.ts`\n");
21
+ };
22
+ mkdirSync(st, { recursive: true });
23
+ writeFileSync(join(st, "config.yml"), "approvals:\n review: true\n");
24
+ mk("2026-10-29-healed", { stage: "done" });
25
+ mk("2026-10-29-healed2", { stage: "done" });
26
+ mk("2026-10-29-real", { stage: "review", awaiting: "approvals.review" });
27
+ expect(healRuns(st).sort()).toEqual(["2026-10-29-healed", "2026-10-29-healed2"]);
28
+ const run = (id: string) => JSON.parse(readFileSync(join(st, "runs", id, "state.json"), "utf8"));
29
+ expect(run("2026-10-29-healed").healed).toBe(true);
30
+ const port = 20000 + Math.floor(Math.random() * 20000);
31
+ const p = Bun.spawn([process.execPath, join(import.meta.dir, "install.ts"), "web", "--foreground", "--no-open", "--port", String(port)],
32
+ { env: { ...process.env, HOME: home, USERPROFILE: home, KAIZEN_HOME: join(home, "kz") }, stdout: "ignore", stderr: "ignore" });
33
+ try {
34
+ const base = `http://127.0.0.1:${port}`;
35
+ for (let i = 0; i < 100; i++) { try { if ((await fetch(base + "/")).ok) break; } catch { /* not up yet */ } await Bun.sleep(100); }
36
+ const post = (path: string, id: string) => fetch(base + path, { method: "POST", headers: { origin: base, "content-type": "application/json" }, body: JSON.stringify({ dir: st, id, awaiting: "approvals.review" }) });
37
+ expect((await post("/accept", "2026-10-29-real")).status).toBe(409); // genuine review: not here
38
+ expect(run("2026-10-29-real").stage).toBe("review");
39
+ expect((await post("/accept", "2026-10-29-healed")).status).toBe(200);
40
+ expect(run("2026-10-29-healed")).toMatchObject({ stage: "done", awaiting: null });
41
+ expect(run("2026-10-29-healed").healed).toBeUndefined();
42
+ expect(readFileSync(join(st, "runs", "2026-10-29-healed", "02-approval.md"), "utf8")).toContain("by user via board");
43
+ expect(existsSync(join(st, "runs", "2026-10-29-healed", "terminals.json"))).toBe(false); // nothing launched
44
+ // /decide on a healed run: a revise is refused; an approve is the same accept, no launch.
45
+ const dec = (id: string, why?: string) => fetch(base + "/decide", { method: "POST", headers: { origin: base, "content-type": "application/json" }, body: JSON.stringify({ dir: st, id, awaiting: "approvals.review", why }) });
46
+ expect((await dec("2026-10-29-healed2", "redo")).status).toBe(409);
47
+ expect((await dec("2026-10-29-healed2")).status).toBe(200);
48
+ expect(run("2026-10-29-healed2")).toMatchObject({ stage: "done", awaiting: null });
49
+ expect(readFileSync(join(st, "runs", "2026-10-29-healed2", "02-approval.md"), "utf8")).toContain("by user via board");
50
+ expect(existsSync(join(st, "runs", "2026-10-29-healed2", "terminals.json"))).toBe(false);
51
+ // /decide still takes the genuine review (here the launch itself fails: no agent in the scratch HOME).
52
+ expect((await post("/decide", "2026-10-29-real")).status).not.toBe(409);
53
+ } finally { p.kill(); }
54
+ }, 30000);
@@ -0,0 +1,51 @@
1
+ import { expect, test } from "bun:test";
2
+ import { mkdtempSync, mkdirSync, realpathSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+
6
+ // The Git tab's /pr takes the runs /commit takes: finished (or at the final approval),
7
+ // never the global state dir, and create/merge only once the final approval is given.
8
+ test.skipIf(process.platform === "win32")("board /pr refuses unfinished, unapproved and global runs", async () => {
9
+ const home = realpathSync(mkdtempSync(join(tmpdir(), "kz-pr-")));
10
+ const proj = join(home, "proj"), st = join(proj, ".kaizen");
11
+ mkdirSync(join(proj, "cli"), { recursive: true });
12
+ writeFileSync(join(proj, "cli", "a.ts"), "");
13
+ mkdirSync(join(home, ".kaizen", "runs", "2026-10-30-global"), { recursive: true });
14
+ writeFileSync(join(home, ".kaizen", "runs", "2026-10-30-global", "state.json"), JSON.stringify({ stage: "done" }));
15
+ writeFileSync(join(home, ".kaizen", "projects"), proj + "\n");
16
+ const mk = (id: string, state: object) => {
17
+ const d = join(st, "runs", id);
18
+ mkdirSync(d, { recursive: true });
19
+ writeFileSync(join(d, "state.json"), JSON.stringify(state));
20
+ writeFileSync(join(d, "03-impl.md"), "## Changed\n- `cli/a.ts`\n");
21
+ };
22
+ mkdirSync(st, { recursive: true });
23
+ writeFileSync(join(st, "config.yml"), "approvals:\n review: true\n");
24
+ mk("2026-10-30-building", { stage: "build" });
25
+ mk("2026-10-30-unapproved", { stage: "done" }); // done with changed files, no accepted: line
26
+ const port = 20000 + Math.floor(Math.random() * 20000);
27
+ const p = Bun.spawn([process.execPath, join(import.meta.dir, "install.ts"), "web", "--foreground", "--no-open", "--port", String(port)],
28
+ { env: { ...process.env, HOME: home, USERPROFILE: home, KAIZEN_HOME: join(home, "kz") }, stdout: "ignore", stderr: "ignore" });
29
+ try {
30
+ const base = `http://127.0.0.1:${port}`;
31
+ for (let i = 0; i < 100; i++) { try { if ((await fetch(base + "/")).ok) break; } catch { /* not up yet */ } await Bun.sleep(100); }
32
+ const pr = async (dir: string, id: string, op: string) => {
33
+ const r = await fetch(base + "/pr", { method: "POST", headers: { origin: base, "content-type": "application/json" }, body: JSON.stringify({ dir, id, op, title: "feat: x" }) });
34
+ return { status: r.status, body: await r.json() };
35
+ };
36
+ for (const op of ["create", "merge", "remove"]) {
37
+ expect((await pr(st, "2026-10-30-building", op)).status).toBe(409);
38
+ expect((await pr(join(home, ".kaizen"), "2026-10-30-global", op)).status).toBe(409);
39
+ }
40
+ for (const op of ["create", "merge"]) {
41
+ const r = await pr(st, "2026-10-30-unapproved", op);
42
+ expect(r.status).toBe(409);
43
+ expect(JSON.stringify(r.body)).toContain("not approved");
44
+ }
45
+ // remove is not gated on the approval, but a run with no worktree has nothing to remove.
46
+ const rm = await pr(st, "2026-10-30-unapproved", "remove");
47
+ expect(rm.status).toBe(409);
48
+ expect(JSON.stringify(rm.body)).toContain("no worktree");
49
+ expect((await pr(st, "../x", "create")).status).toBe(400);
50
+ } finally { p.kill(); }
51
+ }, 30000);
@@ -0,0 +1,28 @@
1
+ import { expect, test } from "bun:test";
2
+ import { mkdtempSync, mkdirSync, symlinkSync, writeFileSync, realpathSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+
6
+ // A project registered under its realpath must still be reached by the symlink spelling
7
+ // the board was offered; a dir that was never registered stays refused.
8
+ test.skipIf(process.platform === "win32")("board accepts a symlink spelling of a registered project", async () => {
9
+ const home = realpathSync(mkdtempSync(join(tmpdir(), "kz-sym-")));
10
+ const real = join(home, "real", "proj"), link = join(home, "link");
11
+ mkdirSync(join(real, ".kaizen"), { recursive: true });
12
+ mkdirSync(join(home, ".kaizen"), { recursive: true });
13
+ mkdirSync(join(home, "other", ".kaizen"), { recursive: true });
14
+ symlinkSync(real, link);
15
+ writeFileSync(join(home, ".kaizen", "projects"), real + "\n");
16
+ const port = 20000 + Math.floor(Math.random() * 20000);
17
+ const p = Bun.spawn([process.execPath, join(import.meta.dir, "install.ts"), "web", "--foreground", "--no-open", "--port", String(port)],
18
+ { env: { ...process.env, HOME: home, USERPROFILE: home, KAIZEN_HOME: join(home, "kz") }, stdout: "ignore", stderr: "ignore" });
19
+ try {
20
+ const base = `http://127.0.0.1:${port}`;
21
+ for (let i = 0; i < 100; i++) { try { if ((await fetch(base + "/")).ok) break; } catch { /* not up yet */ } await Bun.sleep(100); }
22
+ const post = (dir: string) => fetch(base + "/cd", { method: "POST", headers: { origin: base, "content-type": "application/json" }, body: JSON.stringify({ dir }) });
23
+ const ok = await post(join(link, ".kaizen"));
24
+ expect(ok.status).toBe(200);
25
+ const no = await post(join(home, "other", ".kaizen"));
26
+ expect(no.status).toBe(404);
27
+ } finally { p.kill(); }
28
+ }, 20000);