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,40 +0,0 @@
1
- import { test, expect } from "bun:test";
2
- import { mkdtempSync, mkdirSync, writeFileSync, symlinkSync, rmSync } from "node:fs";
3
- import { join } from "node:path";
4
- import { tmpdir } from "node:os";
5
-
6
- test("project tree and text preview stay inside a registered project", async () => {
7
- const home = mkdtempSync(join(tmpdir(), "kaizen-tree-"));
8
- const project = join(home, "project");
9
- mkdirSync(join(home, ".kaizen"));
10
- mkdirSync(join(project, ".kaizen"), { recursive: true });
11
- mkdirSync(join(project, "src"));
12
- writeFileSync(join(home, ".kaizen", "projects"), project + "\n");
13
- writeFileSync(join(project, "src", "good.txt"), "<script>alert(1)</script>\n");
14
- writeFileSync(join(project, "binary.dat"), Buffer.from([0, 1, 2]));
15
- writeFileSync(join(project, "big.txt"), "x".repeat(65537));
16
- writeFileSync(join(project, ".secret"), "hidden");
17
- symlinkSync(join(home, ".kaizen", "projects"), join(project, "link"));
18
- const port = 20000 + Math.floor(Math.random() * 20000);
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
21
- const proc = Bun.spawn([process.execPath, join(repo, "cli", "install.ts"), "web", "--port", String(port), "--no-open", "--foreground"], {
22
- cwd: project, env: { ...process.env, HOME: home, USERPROFILE: home, KAIZEN_HOME: repo }, stdout: "ignore", stderr: "ignore",
23
- });
24
- try {
25
- const base = `http://127.0.0.1:${port}`;
26
- for (let i = 0; ; i++) { try { await fetch(base + "/state"); break; } catch { if (i > 100) throw new Error("board did not start"); await Bun.sleep(50); } }
27
- const get = (route: string, path: string, dir = join(project, ".kaizen")) => fetch(base + route + "?dir=" + encodeURIComponent(dir) + "&path=" + encodeURIComponent(path));
28
- const root = await (await get("/project-tree", "")).json() as any;
29
- expect(root.entries.map((e: any) => e.name)).toContain("src");
30
- expect(root.entries.map((e: any) => e.name)).not.toContain(".secret");
31
- expect(root.entries.map((e: any) => e.name)).not.toContain("link");
32
- expect((await (await get("/project-text", "src/good.txt")).json()).content).toBe("<script>alert(1)</script>\n");
33
- for (const path of ["../.kaizen/projects", "/etc/passwd", "C:/Windows/win.ini", ".secret", "link", "src/../../.secret"]) expect((await get("/project-text", path)).status).toBeGreaterThanOrEqual(400);
34
- for (const path of ["binary.dat", "big.txt"]) expect((await get("/project-text", path)).status).toBe(415);
35
- expect((await get("/project-tree", "", join(home, "elsewhere", ".kaizen"))).status).toBe(404);
36
- const download = await fetch(base + "/project-text?dir=" + encodeURIComponent(join(project, ".kaizen")) + "&path=src%2Fgood.txt&download=1");
37
- expect(download.headers.get("content-type")).toContain("text/plain");
38
- expect(download.headers.get("content-disposition")).toContain("attachment");
39
- } finally { proc.kill(); await proc.exited; rmSync(home, { recursive: true, force: true }); }
40
- });
package/cli/pty.test.ts DELETED
@@ -1,330 +0,0 @@
1
- // The in-card agent (agent.launch: card): the setting, and the real board running a
2
- // fake agent in a pseudo-terminal, reached only from its own origin.
3
- import { test, expect } from "bun:test";
4
- import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, realpathSync, rmSync, utimesSync } from "node:fs";
5
- import { tmpdir } from "node:os";
6
- import { join } from "node:path";
7
- import { launchMode, closeSessions, readSessions, sweepSessions } from "./state.ts";
8
- import { loginEnv, startPty, writePty, submitPty, attachPty, ptyState, exitPty, lastLine } from "./pty.ts";
9
- import { conptyHost, innerCommand, resizeSeq } from "./conpty.ts";
10
-
11
- const root = realpathSync(mkdtempSync(join(tmpdir(), "kaizen-pty-")));
12
-
13
- test("agent.launch: card unless the config chain says terminal, comments between keys allowed", () => {
14
- const p = join(root, "mode");
15
- mkdirSync(join(p, ".kaizen"), { recursive: true });
16
- // The global file is the real one, so only the project file is varied here.
17
- writeFileSync(join(p, ".kaizen", "config.yml"), "agent:\n # where\n default: auto\n # the board\n launch: terminal\n");
18
- expect(launchMode(p)).toBe("terminal");
19
- writeFileSync(join(p, ".kaizen", "config.yml"), "agent:\n launch: card\n");
20
- expect(launchMode(p)).toBe("card");
21
- writeFileSync(join(p, ".kaizen", "config.yml"), "agent.launch: terminal\n");
22
- expect(launchMode(p)).toBe("terminal");
23
- });
24
-
25
- test.skipIf(process.platform === "win32")("the board runs the agent in the card: output, input, origin check, and closing", async () => {
26
- const homeDir = join(root, "home"), proj = join(homeDir, "a"), st = join(proj, ".kaizen"), bin = join(root, "bin");
27
- for (const d of [st, join(homeDir, ".kaizen"), join(homeDir, ".claude"), bin]) mkdirSync(d, { recursive: true });
28
- writeFileSync(join(homeDir, ".kaizen", "projects"), proj + "\n");
29
- writeFileSync(join(st, "config.yml"), "agent:\n default: claude\n launch: card\n");
30
- writeFileSync(join(st, "inbox.md"), "# Inbox\n\n- open: say hello\n");
31
- // A stand-in for Claude Code: says how it was called, then echoes each line it is sent.
32
- writeFileSync(join(bin, "claude"), '#!/bin/sh\necho "args:$*"; echo "⏺ reply ready"\nwhile read x; do echo "got:$x"; done\n', { mode: 0o755 });
33
- // Started as a launcher starts it: a bare PATH, the agent reachable only through
34
- // the PATH the user's login shell builds.
35
- const sh = join(root, "loginsh");
36
- writeFileSync(sh, `#!/bin/sh\nPATH=${bin}:$PATH exec /bin/sh -c "$4"\n`, { mode: 0o755 });
37
- const port = 20000 + Math.floor(Math.random() * 20000);
38
- const repo = join(import.meta.dir, "..");
39
- const proc = Bun.spawn([process.execPath, join(repo, "cli", "install.ts"), "web", "--port", String(port), "--no-open", "--foreground"], {
40
- cwd: proj, stdout: "ignore", stderr: "ignore",
41
- env: { ...process.env, HOME: homeDir, USERPROFILE: homeDir, KAIZEN_HOME: repo, CLAUDE_CONFIG_DIR: join(homeDir, ".claude"),
42
- PATH: "/usr/bin:/bin", KAIZEN_WEB_HOSTS: "remote.ts.net", SHELL: sh, DISPLAY: "", WAYLAND_DISPLAY: "", TERMINAL: "", TMUX: "" },
43
- });
44
- try {
45
- const at = `http://127.0.0.1:${port}`;
46
- 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); } }
47
-
48
- // G-02: no terminal window anywhere (none could be found), yet the launch worked.
49
- const r = await (await fetch(at + "/run", { method: "POST", body: JSON.stringify({ dir: st, text: "say hello" }) })).json() as any;
50
- expect(r.ok).toBe(true);
51
- expect(r.pty).toMatch(/^[\w-]+$/);
52
- const card = ((await (await fetch(at + "/state")).json()) as any).cards.find((c: any) => c.text === "say hello");
53
- expect(card.pty).toMatchObject({ key: r.pty, alive: true, asking: false, all: [r.pty] });
54
-
55
- // The agent's output line goes to a viewer on this machine only, never a tailnet host; nothing typed is in it.
56
- const agentsOf = async (h?: string) => ((await (await fetch(at + "/state", { headers: h ? { host: h } : {} })).json()) as any).agents;
57
- expect((await agentsOf())[0].last).toBe("reply ready");
58
- const far = (await agentsOf("remote.ts.net"))[0];
59
- expect(far.key).toBe(r.pty);
60
- expect(far.last).toBeUndefined();
61
- // Host 127.0.0.1 behind a proxy (tailscale serve adds these headers) gets no line either.
62
- for (const h of ["x-forwarded-for", "tailscale-user-login"]) {
63
- const via = ((await (await fetch(at + "/state", { headers: { [h]: "100.64.0.9" } })).json()) as any).agents[0];
64
- expect(via.last).toBeUndefined();
65
- }
66
-
67
- // G-01: no Origin, a foreign one, and another local port are all refused.
68
- const url = `${at}/pty?key=${r.pty}`, up = { upgrade: "websocket", connection: "Upgrade", "sec-websocket-version": "13", "sec-websocket-key": "dGhlIHNhbXBsZSBub25jZQ==" };
69
- expect((await fetch(url, { headers: up })).status).toBe(403);
70
- expect((await fetch(url, { headers: { ...up, origin: "https://evil.example" } })).status).toBe(403);
71
- expect((await fetch(url, { headers: { ...up, origin: `http://127.0.0.1:${port + 1}` } })).status).toBe(403);
72
- expect((await fetch(`${at}/pty?key=nope`, { headers: { ...up, origin: at } })).status).toBe(404);
73
-
74
- // The board's own origin: the screen so far, then typing goes through.
75
- let seen = "";
76
- const ws = new WebSocket(url.replace("http", "ws"), { headers: { origin: at } } as any);
77
- const closed = new Promise((ok) => { ws.onclose = ok; });
78
- ws.onmessage = (e) => { seen += String(e.data); };
79
- await new Promise((ok, no) => { ws.onopen = ok; ws.onerror = no; });
80
- const until = async (re: RegExp) => { for (let i = 0; i < 100 && !re.test(seen); i++) await Bun.sleep(30); expect(seen).toMatch(re); };
81
- await until(/args:.*--session-id [\w-]+ .*\/kaizen say hello/);
82
- ws.send(JSON.stringify({ t: "r", c: 100, r: 30 }));
83
- ws.send(JSON.stringify({ t: "i", d: "ping\r" }));
84
- await until(/got:ping/);
85
-
86
- // G-03: the session record is the usual one, its PID file the agent's own, so a
87
- // run that owns it closes it like a terminal launch.
88
- const [s] = readSessions(st);
89
- expect(s!.cmd).toBe("claude");
90
- const pid = Number(readFileSync(join(st, "sessions", s!.key + ".pid"), "utf8"));
91
- expect(process.kill(pid, 0)).toBe(true);
92
- mkdirSync(join(st, "runs", "r1"), { recursive: true });
93
- writeFileSync(join(st, "runs", "r1", "00-request.md"), "say hello\n");
94
- expect(closeSessions(st, "r1")).toBe(1);
95
- // The page tells an agent that ended from a board that went away by this reason.
96
- expect(((await closed) as CloseEvent).reason).toBe("ended");
97
- expect(existsSync(join(st, "sessions", s!.key + ".pid"))).toBe(false);
98
- let gone = false;
99
- for (let i = 0; i < 50 && !gone; i++) { try { process.kill(pid, 0); await Bun.sleep(30); } catch { gone = true; } }
100
- expect(gone).toBe(true);
101
-
102
- // Resume: refused while the run waits on a decision, then the run's own conversation
103
- // continues in a new in-card session, and a second press is refused while it lives.
104
- const resume = async () => { const x = await fetch(at + "/resume", { method: "POST", body: JSON.stringify({ dir: st, id: "r1" }) }); return { status: x.status, ...(await x.json() as any) }; };
105
- writeFileSync(join(st, "runs", "r1", "state.json"), JSON.stringify({ id: "r1", stage: "plan", awaiting: "approvals.plan" }));
106
- expect((await resume()).status).toBe(409);
107
- writeFileSync(join(st, "runs", "r1", "state.json"), JSON.stringify({ id: "r1", stage: "build", awaiting: null }));
108
- // Claude resumes by id only when the conversation's transcript is on disk.
109
- const tr = join(homeDir, ".claude", "projects", proj.replace(/[^A-Za-z0-9]/g, "-"));
110
- mkdirSync(tr, { recursive: true });
111
- writeFileSync(join(tr, s!.sessionId + ".jsonl"), "{}\n");
112
- const again = await resume();
113
- expect(again).toMatchObject({ status: 200, ok: true });
114
- seen = "";
115
- const ws2 = new WebSocket(`${at}/pty?key=${again.pty}`.replace("http", "ws"), { headers: { origin: at } } as any);
116
- ws2.onmessage = (e) => { seen += String(e.data); };
117
- await new Promise((ok, no) => { ws2.onopen = ok; ws2.onerror = no; });
118
- await until(new RegExp(`args:.*--resume ${s!.sessionId} .*/kaizen run r1: continue`));
119
- expect((await resume()).status).toBe(409);
120
-
121
- // Its agent ended while the run waits on a decision: the conversation reopens with
122
- // nothing sent to it. With no conversation on disk, a done run is refused, never a blank session.
123
- const ended2 = new Promise((ok) => { ws2.onclose = ok; });
124
- expect(closeSessions(st, "r1")).toBe(1);
125
- await ended2;
126
- writeFileSync(join(st, "runs", "r1", "state.json"), JSON.stringify({ id: "r1", stage: "plan", awaiting: "approvals.plan" }));
127
- const quiet = await resume();
128
- expect(quiet).toMatchObject({ status: 200, ok: true });
129
- seen = "";
130
- const ws3 = new WebSocket(`${at}/pty?key=${quiet.pty}`.replace("http", "ws"), { headers: { origin: at } } as any);
131
- ws3.onmessage = (e) => { seen += String(e.data); };
132
- await new Promise((ok, no) => { ws3.onopen = ok; ws3.onerror = no; });
133
- await until(new RegExp(`args:.*--resume ${s!.sessionId}`));
134
- expect(seen).not.toContain("/kaizen");
135
- const ended3 = new Promise((ok) => { ws3.onclose = ok; });
136
- expect(closeSessions(st, "r1")).toBe(1);
137
- await ended3;
138
- rmSync(join(tr, s!.sessionId + ".jsonl"));
139
- writeFileSync(join(st, "runs", "r1", "state.json"), JSON.stringify({ id: "r1", stage: "done", awaiting: null }));
140
- expect(await resume()).toMatchObject({ status: 409, error: "no conversation of this run to resume" });
141
- } finally { proc.kill(); await proc.exited; }
142
- }, 30_000);
143
-
144
- test.skipIf(process.platform === "win32")("a board started from a launcher takes the login shell's PATH and exports, not its own bare ones", () => {
145
- const bin = join(root, "shells");
146
- mkdirSync(bin, { recursive: true });
147
- // A profile that greets on stdout before the environment, as many do.
148
- writeFileSync(join(bin, "fakesh"), '#!/bin/sh\necho "welcome back"\n[ "$1 $2 $3" = "-l -i -c" ] || exit 9\nFROM_PROFILE=yes PATH=/opt/brew/bin:$PATH PWD=/elsewhere exec /bin/sh -c "$4"\n', { mode: 0o755 });
149
- writeFileSync(join(bin, "badsh"), "#!/bin/sh\nexit 1\n", { mode: 0o755 });
150
- const e = loginEnv(join(bin, "fakesh"))!;
151
- expect(e.FROM_PROFILE).toBe("yes");
152
- expect(e.PATH.split(":")[0]).toBe("/opt/brew/bin");
153
- expect(loginEnv(join(bin, "badsh"))).toBeNull();
154
- expect(loginEnv(join(bin, "missing"))).toBeNull();
155
- // Into a process started with a launcher's bare PATH and its own setting: the
156
- // board's PATH first, the profile's added after it, the board's own variable not overridden,
157
- // the shell's PWD not taken.
158
- const pty = JSON.stringify(join(import.meta.dir, "pty.ts"));
159
- const out = Bun.spawnSync([process.execPath, "-e", `import { adoptLoginEnv } from ${pty}; adoptLoginEnv(); console.log(JSON.stringify([process.env.PATH, process.env.FROM_PROFILE, process.env.KEEP, process.env.PWD]))`], {
160
- env: { SHELL: join(bin, "fakesh"), PATH: "/usr/bin:/bin", KEEP: "mine", FROM_PROFILE: undefined as any, HOME: root },
161
- }).stdout.toString();
162
- const [path, from, keep, pwd] = JSON.parse(out);
163
- expect(path.split(":").slice(0, 3)).toEqual(["/usr/bin", "/bin", "/opt/brew/bin"]);
164
- expect([from, keep]).toEqual(["yes", "mine"]);
165
- expect(pwd).not.toBe("/elsewhere");
166
- });
167
-
168
- test.skipIf(process.platform === "win32")("the sweep leaves a done run's agent running", async () => {
169
- const st = join(root, "typed", ".kaizen"), ses = join(st, "sessions"), runDir = join(st, "runs", "r1");
170
- mkdirSync(ses, { recursive: true });
171
- mkdirSync(runDir, { recursive: true });
172
- writeFileSync(join(st, "config.yml"), "agent:\n close: on\n");
173
- writeFileSync(join(runDir, "state.json"), JSON.stringify({ id: "r1", stage: "done", awaiting: null }));
174
- utimesSync(join(runDir, "state.json"), new Date(0), new Date(0));
175
- writeFileSync(join(ses, "idle.json"), JSON.stringify({ run: "r1", text: "x", cmd: "sh", sessionId: null, started: 0 }));
176
- const idle = startPty("idle", ["sh", "-c", "while read l; do echo got:$l; done"], root, join(ses, "idle.pid"));
177
- await Bun.sleep(200);
178
- sweepSessions(st);
179
- await Bun.sleep(200);
180
- expect(() => process.kill(idle, 0)).not.toThrow();
181
- process.kill(idle, "SIGTERM");
182
- });
183
-
184
- test.skipIf(process.platform === "win32")("exitPty types /exit, and ends an agent that ignores it", async () => {
185
- const wait = async (k: string) => { for (let i = 0; i < 100 && ptyState(k)!.alive; i++) await Bun.sleep(30); return ptyState(k)!.alive; };
186
- startPty("polite", ["sh", "-c", "while read l; do case $l in */exit*) exit 0;; esac; done"], root);
187
- expect(exitPty("polite", 60_000)).toBe(true);
188
- expect(await wait("polite")).toBe(false);
189
- startPty("stubborn", ["sh", "-c", "trap '' INT; while read l; do :; done"], root);
190
- await Bun.sleep(100);
191
- exitPty("stubborn", 300);
192
- expect(await wait("stubborn")).toBe(false);
193
- expect(exitPty("stubborn")).toBe(false);
194
- });
195
-
196
- test("asking: Claude Code and Codex prompts count as a question, ordinary output does not", async () => {
197
- const { asking } = await import("./pty.ts");
198
- expect(asking("\x1b[1mWould you like to run the following command?\x1b[0m")).toBe(true);
199
- expect(asking("What behavior do you want?\r\n\x1b[36m❯ 1. Retry with backoff\x1b[0m\r\n 2. Fail\r\n 4. Type something.")).toBe(true);
200
- expect(asking("Do you want to make this edit to cli/pty.ts?")).toBe(true);
201
- expect(asking("Reading cli/pty.ts\r\n\x1b[2K✻ Thinking… 1. step one done")).toBe(false);
202
- // Answered: the working line drawn after the question clears it.
203
- expect(asking("Do you want to make this edit?\r\n\x1b[2K✻ Contemplating… (1m 4s · ↓ 4.4k tokens)")).toBe(false);
204
- expect(asking("Would you like to run the following command?\r\n• Working (12s • esc to interrupt)")).toBe(false);
205
- expect(asking("Do you want to proceed?\r\n⠋ Reading files (esc to cancel, 4s)")).toBe(false);
206
- expect(asking("Do you want to proceed?\r\n esc interrupt")).toBe(false);
207
- expect(asking("Do you want to proceed?\r\n❯ 1. Yes\r\n 2. No\r\n\r\nEsc to cancel · Tab to amend")).toBe(true);
208
- expect(asking("✻ Thinking… (3s · esc to interrupt)\r\nDo you want to proceed?\r\n❯ 1. Yes")).toBe(true);
209
- });
210
-
211
- test("Windows ConPTY host: resize travels in-band, the agent command survives quotes and newlines", () => {
212
- expect(resizeSeq(100, 40)).toBe("\x1b]kzr;100;40\x07");
213
- const line = innerCommand("C:\\ps.exe", ["claude", "it's\nhere"]);
214
- const enc = line.split(" ").pop()!;
215
- expect(line.startsWith('"C:\\ps.exe" -NoProfile -ExecutionPolicy Bypass -EncodedCommand ')).toBe(true);
216
- expect(Buffer.from(enc, "base64").toString("utf16le")).toBe("& 'claude' 'it''s\nhere'");
217
- // The host script decodes to PowerShell carrying the C# whole.
218
- expect(Buffer.from(conptyHost(), "base64").toString("utf16le")).toContain("CreatePseudoConsole");
219
- });
220
-
221
- test.skipIf(process.platform !== "win32")("on Windows a card agent runs in a pseudo console and takes typed input", async () => {
222
- const key = `win-${Date.now()}`;
223
- const out: string[] = [];
224
- startPty(key, ["cmd.exe", "/q", "/k", "echo ready"], root);
225
- attachPty(key, (d) => { if (d) out.push(d); });
226
- const until = async (re: RegExp) => { for (let i = 0; i < 300 && !re.test(out.join("")); i++) await Bun.sleep(100); return out.join(""); };
227
- expect(await until(/ready/)).toContain("ready");
228
- writePty(key, "echo typed-%OS%\r");
229
- expect(await until(/typed-Windows_NT/)).toContain("typed-Windows_NT");
230
- writePty(key, "exit\r");
231
- for (let i = 0; i < 100 && ptyState(key)?.alive; i++) await Bun.sleep(100);
232
- expect(ptyState(key)?.alive).toBe(false);
233
- }, 60_000);
234
-
235
- test.skipIf(process.platform === "win32")("submit: Enter reaches the agent on its own, not in the text's burst", async () => {
236
- const key = "submit-" + Date.now(), log = join(root, "chunks-" + key), script = join(root, "chunks.js");
237
- writeFileSync(script, `process.stdin.setRawMode(true); process.stdin.on("data", (d) => require("fs").appendFileSync(${JSON.stringify(log)}, JSON.stringify(d.toString()) + "\\n")); console.log("ready");`);
238
- const out: string[] = [];
239
- startPty(key, [process.execPath, script], root);
240
- attachPty(key, (d) => { if (d) out.push(d); });
241
- for (let i = 0; i < 100 && !out.join("").includes("ready"); i++) await Bun.sleep(50);
242
- submitPty(key, "hello", 100);
243
- let chunks = "";
244
- for (let i = 0; i < 40 && !chunks.includes("\\r"); i++) { await Bun.sleep(50); try { chunks = readFileSync(log, "utf8"); } catch { /* not yet */ } }
245
- expect(chunks.trim().split("\n").map((l) => JSON.parse(l))).toEqual(["hello", "\r"]);
246
- exitPty(key, 100);
247
- });
248
-
249
- test("busy: on while the agent draws its working line, off once it goes quiet; other output is not work", async () => {
250
- const key = "busy-" + Date.now();
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
- // 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);
254
- expect(ptyState(key)!.busy).toBe(true);
255
- await Bun.sleep(1800);
256
- expect(ptyState(key)).toMatchObject({ alive: true, busy: false });
257
- exitPty(key);
258
- const idle = "idle-" + Date.now();
259
- startPty(idle, ["sh", "-c", "for i in 1 2 3 4 5 6; do echo statusline; sleep 0.1; done; read l"], root);
260
- await Bun.sleep(250);
261
- expect(ptyState(idle)!.busy).toBe(false);
262
- exitPty(idle);
263
- });
264
-
265
- test("lastLine: only the agent's own marked reply lines, never input", () => {
266
- expect(lastLine("\x1b[2K\x1b[1;32m⏺ Done: fixed the bug\x1b[0m\r\n╭────╮\r\n│ ✻ │\r\n⠋ \r\n? for shortcuts\r\n✻ Thinking… (12s · esc to interrupt)")).toBe("Done: fixed the bug");
267
- expect(lastLine("• Ran the tests, 12 pass")).toBe("Ran the tests, 12 pass");
268
- expect(lastLine("✦ Updated the parser")).toBe("Updated the parser");
269
- // Unmarked output (a plain shell, an unknown agent) gives nothing: the card shows status only.
270
- expect(lastLine("Build passed\r\n12 pass 0 fail")).toBe("");
271
- // Typed or pasted text is never shown, whatever the prompt looks like.
272
- const leaks = [
273
- "│ > hey there │",
274
- "⏺ Done: fixed it\r\n╭──────╮\r\n│ > pasted-token-9 │\r\n│ ⏺ fake-token-9 │\r\n╰──────╯",
275
- "❯ pasted-token-9",
276
- "rzr@host:~$ export KEY=sk-secret-9",
277
- "user@host ~/a b/c (main) $ export KEY=sk-secret-9",
278
- "user@host ~/proj> sk-secret-9",
279
- "PS C:\\Users\\me> sk-secret-9",
280
- ">>> sk-secret-9",
281
- "▌ sk-secret-9",
282
- " ~/proj main sk-secret-9",
283
- "sk-secret-9 continued in a later chunk",
284
- ];
285
- leaks.push("──────\r\n❯ please fix\r\n • sk-secret-9 token\r\n⏺ token-9 pasted\r\n──────\r\n");
286
- for (const t of leaks) expect(lastLine(t)).not.toContain("secret-9"), expect(lastLine(t)).not.toContain("token-9");
287
- // The newest marked line wins over older ones; a marked line with an unmarked line below it still counts.
288
- expect(lastLine("⏺ Fixed issue # 42 in parser\r\nrzr@host:~$ sk-secret-9")).toBe("Fixed issue # 42 in parser");
289
- // Output above the input rules is still read; a tool call shows its name, not its arguments.
290
- expect(lastLine("⏺ Fixed the parser\r\n──────\r\n❯ next\r\n──────")).toBe("Fixed the parser");
291
- expect(lastLine("⏺ Bash(curl -H 'Authorization: Bearer sk-secret-9')")).toBe("Bash");
292
- expect(lastLine("╰───╯ ⠙ ✻")).toBe("");
293
- expect(lastLine("⏺ " + "x".repeat(200)).length).toBe(80);
294
- });
295
-
296
- test("last: only the agent's output, never what was typed or echoed right after a keystroke", async () => {
297
- const key = "last-" + Date.now();
298
- startPty(key, ["sh", "-c", "echo '⏺ agent-said-this'; stty echo; read a; sleep 2; echo '⏺ later-agent-line'; sleep 5"], root);
299
- await Bun.sleep(1000);
300
- expect(ptyState(key)!.last).toBe("agent-said-this");
301
- writePty(key, "hunter2-secret\r"); // the tty echoes it back at once
302
- await Bun.sleep(1200);
303
- expect(JSON.stringify(ptyState(key))).not.toContain("hunter2");
304
- expect(ptyState(key)!.last).toBe("agent-said-this");
305
- await Bun.sleep(2200);
306
- expect(ptyState(key)!.last).toBe("later-agent-line");
307
- expect(JSON.stringify(ptyState(key))).not.toContain("hunter2");
308
- exitPty(key, 100);
309
- });
310
-
311
- test("last: a pasted token in the input box is never the last line, redraw or quiet read", async () => {
312
- const key = "box-" + Date.now();
313
- startPty(key, ["sh", "-c", "echo '⏺ agent-said-this'; sleep 2; printf '╭────╮\\n│ > pasted-token-9 │\\n╰────╯\\n'; sleep 3; printf '\\r│ > pasted-token-9 │\\n'; sleep 5"], root);
314
- await Bun.sleep(2600);
315
- expect(ptyState(key)!.last).toBe("agent-said-this");
316
- await Bun.sleep(2400);
317
- expect(JSON.stringify(ptyState(key))).not.toContain("pasted-token");
318
- exitPty(key, 100);
319
- }, 15000);
320
-
321
- test("last: nothing is read while the terminal is asking", async () => {
322
- const key = "ask-" + Date.now();
323
- startPty(key, ["sh", "-c", "echo 'Do you want to proceed? (y/n)'; read a; echo ok-done-now; read b; sleep 5"], root);
324
- for (let i = 0; i < 40 && !ptyState(key)!.asking; i++) await Bun.sleep(100);
325
- expect(ptyState(key)!.asking).toBe(true);
326
- writePty(key, "hunter2\r");
327
- await Bun.sleep(1200);
328
- expect(JSON.stringify(ptyState(key))).not.toContain("hunter2");
329
- exitPty(key, 100);
330
- });
@@ -1,12 +0,0 @@
1
- import { test, expect } from "bun:test";
2
- import { nextVersion, levelOf, summaryOf } from "./release.ts";
3
-
4
- test("release picks the bump from the commits and names it from them", () => {
5
- expect(levelOf("fix(board): x\ndocs: y")).toBe("patch");
6
- expect(levelOf("docs: y\nfeat(board): x")).toBe("minor");
7
- expect(levelOf("feat: x\n\nBREAKING: config moved")).toBe("major");
8
- expect(nextVersion("1.43.3", "patch")).toBe("1.43.4");
9
- expect(nextVersion("1.43.3", "minor")).toBe("1.44.0");
10
- expect(nextVersion("1.43.3", "major")).toBe("2.0.0");
11
- expect(summaryOf(["feat(board): a", "docs(notes): b", "fix: c"])).toBe("a; c");
12
- });
@@ -1,59 +0,0 @@
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
- });
@@ -1,50 +0,0 @@
1
- import { expect, it } from "bun:test";
2
- import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
5
- import { folderSize, measure, parsePs, systemMemory, treeRss } from "./resources.ts";
6
-
7
- it("reads available memory, so page cache is not shown as used", () => {
8
- const m = systemMemory("MemTotal: 1 kB\nMemAvailable: 1024 kB\n");
9
- expect(m.total - m.used).toBe(1024 * 1024);
10
- });
11
-
12
- it("adds a process tree once, whichever roots reach it", () => {
13
- const t = parsePs(" 1 0 10\n 2 1 20\n 3 2 30\n 4 1 40\njunk\n 9 0 90\n");
14
- expect(t).toHaveLength(5);
15
- expect(treeRss(t, [2])).toBe(50 * 1024);
16
- expect(treeRss(t, [1, 2, 3])).toBe(100 * 1024);
17
- expect(treeRss(t, [777])).toBe(0);
18
- });
19
-
20
- const scratch = () => mkdtempSync(join(tmpdir(), "kz-res-"));
21
-
22
- it("does not follow symlinks", async () => {
23
- const d = scratch();
24
- try {
25
- mkdirSync(join(d, "a")); mkdirSync(join(d, "big"));
26
- writeFileSync(join(d, "big", "f"), Buffer.alloc(1 << 20));
27
- const before = await folderSize(join(d, "a"));
28
- symlinkSync(join(d, "big"), join(d, "a", "link"));
29
- expect(await folderSize(join(d, "a"))).toBeLessThan(before + 65536);
30
- expect(await folderSize(join(d, "big"))).toBeGreaterThanOrEqual(1 << 20);
31
- } finally { rmSync(d, { recursive: true, force: true }); }
32
- });
33
-
34
- it("counts a real folder once and a nested root only in its own row", async () => {
35
- const d = scratch();
36
- try {
37
- mkdirSync(join(d, "inst", ".kaizen"), { recursive: true });
38
- writeFileSync(join(d, "inst", ".kaizen", "f"), Buffer.alloc(1 << 20));
39
- symlinkSync(join(d, "inst", ".kaizen"), join(d, "alias"));
40
- const r = await measure([
41
- { name: "inst", dir: "", path: join(d, "inst"), kind: "install" },
42
- { name: "p", dir: "x", path: join(d, "inst", ".kaizen"), kind: "project" },
43
- { name: "again", dir: "y", path: join(d, "alias"), kind: "project" },
44
- { name: "gone", dir: "z", path: join(d, "missing"), kind: "project" },
45
- ]);
46
- expect(r.rows.map((x) => x.name)).toEqual(["p", "inst"]);
47
- expect(r.rows[1].bytes).toBeLessThan(1 << 20);
48
- expect(r.total).toBe(r.rows[0].bytes + r.rows[1].bytes);
49
- } finally { rmSync(d, { recursive: true, force: true }); }
50
- });