kaizen-agent 1.59.2 → 1.60.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 (59) 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 +82 -3
  9. package/cli/pty.ts +122 -6
  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-symlink.test.ts +28 -0
  18. package/cli/web.ts +320 -100
  19. package/cli/worktree.test.ts +43 -1
  20. package/cli/worktree.ts +97 -2
  21. package/cli/writeback.ts +1 -1
  22. package/package.json +1 -1
  23. package/skills/kaizen/SKILL.md +5 -1
  24. package/skills/kaizen/config.default.yml +15 -2
  25. package/skills/kaizen/settings.md +1 -0
  26. package/skills/kaizen/spec-main.md +28 -2
  27. package/skills/kaizen-help/SKILL.md +1 -0
  28. package/web/board/add-project.ts +136 -0
  29. package/web/board/api.ts +1 -1
  30. package/web/board/badge.ts +5 -5
  31. package/web/board/cards.ts +11 -3
  32. package/web/board/context.ts +1 -0
  33. package/web/board/fixes.ts +3 -2
  34. package/web/board/git.ts +2 -0
  35. package/web/board/home.ts +7 -1
  36. package/web/board/ideas.ts +20 -3
  37. package/web/board/live.ts +1 -1
  38. package/web/board/main.ts +26 -9
  39. package/web/board/panel.ts +18 -3
  40. package/web/board/projects.ts +6 -85
  41. package/web/board/run-pick.ts +41 -0
  42. package/web/board/run-view.ts +261 -106
  43. package/web/board/settings.ts +42 -5
  44. package/web/board/store.ts +3 -1
  45. package/web/board/toast.ts +4 -1
  46. package/web/board/views.ts +3 -1
  47. package/web/board/workspace.ts +125 -38
  48. package/web/board/ws-board-ui.ts +84 -0
  49. package/web/board/ws-board.test.ts +71 -0
  50. package/web/board/ws-board.ts +45 -0
  51. package/web/board/ws-tabs.test.ts +171 -0
  52. package/web/board/ws-tabs.ts +170 -0
  53. package/web/board.html +80 -36
  54. package/web/board.js +44 -43
  55. package/web/notebook.js +24 -25
  56. package/web/notes.html +25 -20
  57. package/web/term.js +1 -1
  58. package/web/video.html +25 -20
  59. package/web/video.js +56 -57
@@ -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,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);