kaizen-agent 1.64.3 → 1.66.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 (82) hide show
  1. package/cli/install.ts +13 -2
  2. package/cli/roadmap.ts +74 -0
  3. package/cli/skills.ts +1 -1
  4. package/cli/web.ts +64 -2
  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 +416 -0
  13. package/skills/kaizen-concept/skill.json +1 -0
  14. package/skills/kaizen-concept/ux-rules.md +272 -0
  15. package/skills/kaizen-help/SKILL.md +2 -0
  16. package/web/board/chat.ts +4 -3
  17. package/web/board/run-view.ts +18 -3
  18. package/web/board/ws-tabs.ts +9 -0
  19. package/web/board.js +102 -102
  20. package/web/notebook.js +1 -1
  21. package/web/term.js +1 -1
  22. package/web/video.js +1 -1
  23. package/cli/__pycache__/computer-helper.cpython-314.pyc +0 -0
  24. package/cli/accounts.test.ts +0 -126
  25. package/cli/add-project.test.ts +0 -169
  26. package/cli/agent-prefs.test.ts +0 -127
  27. package/cli/automations.test.ts +0 -167
  28. package/cli/backlog.test.ts +0 -133
  29. package/cli/board.test.ts +0 -381
  30. package/cli/browser.test.ts +0 -132
  31. package/cli/chat.test.ts +0 -274
  32. package/cli/chatgpt.test.ts +0 -158
  33. package/cli/computer.test.ts +0 -155
  34. package/cli/docs.test.ts +0 -94
  35. package/cli/handoff.test.ts +0 -133
  36. package/cli/html.test.ts +0 -19
  37. package/cli/install.test.ts +0 -237
  38. package/cli/knowledge.test.ts +0 -179
  39. package/cli/localsend.test.ts +0 -84
  40. package/cli/logo.test.ts +0 -18
  41. package/cli/notes.test.ts +0 -249
  42. package/cli/onboarding.test.ts +0 -70
  43. package/cli/project-tree.test.ts +0 -40
  44. package/cli/pty.test.ts +0 -330
  45. package/cli/release.test.ts +0 -12
  46. package/cli/report.test.ts +0 -59
  47. package/cli/resources.test.ts +0 -50
  48. package/cli/restart.test.ts +0 -222
  49. package/cli/settings.test.ts +0 -168
  50. package/cli/setup.test.ts +0 -78
  51. package/cli/shell-agent.test.ts +0 -23
  52. package/cli/skills.test.ts +0 -95
  53. package/cli/sources.test.ts +0 -851
  54. package/cli/state.test.ts +0 -1639
  55. package/cli/term-image.test.ts +0 -23
  56. package/cli/usage.test.ts +0 -291
  57. package/cli/versions.test.ts +0 -154
  58. package/cli/video.test.ts +0 -545
  59. package/cli/web-accept.test.ts +0 -55
  60. package/cli/web-decide.test.ts +0 -54
  61. package/cli/web-pr.test.ts +0 -52
  62. package/cli/web-skills.test.ts +0 -32
  63. package/cli/web-symlink.test.ts +0 -29
  64. package/cli/workers.test.ts +0 -319
  65. package/cli/worktree.test.ts +0 -452
  66. package/cli/writeback.test.ts +0 -102
  67. package/skills/media/kaizen-video/scripts/__pycache__/intake.cpython-314.pyc +0 -0
  68. package/skills/media/kaizen-video/scripts/__pycache__/make_film.cpython-314.pyc +0 -0
  69. package/skills/media/kaizen-video/scripts/__pycache__/make_tiktok.cpython-314.pyc +0 -0
  70. package/skills/media/kaizen-video/scripts/__pycache__/render_cut.cpython-314.pyc +0 -0
  71. package/skills/media/kaizen-video/scripts/__pycache__/sfx.cpython-314.pyc +0 -0
  72. package/skills/media/kaizen-video/scripts/__pycache__/srt.cpython-314.pyc +0 -0
  73. package/skills/media/kaizen-video/scripts/__pycache__/transcribe.cpython-314.pyc +0 -0
  74. package/skills/media/kaizen-video/scripts/__pycache__/vo.cpython-314.pyc +0 -0
  75. package/web/board/search.test.ts +0 -20
  76. package/web/board/settings-pages.test.ts +0 -28
  77. package/web/board/settings-voice.test.ts +0 -18
  78. package/web/board/toast.test.ts +0 -77
  79. package/web/board/ws-board.test.ts +0 -77
  80. package/web/board/ws-name.test.ts +0 -10
  81. package/web/board/ws-tabs.test.ts +0 -213
  82. package/web/term-font.test.ts +0 -22
@@ -1,452 +0,0 @@
1
- // A real bare remote, two clones and real git: the landing is only as good as git says.
2
- import { test, expect, beforeEach } from "bun:test";
3
- import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, realpathSync } from "node:fs";
4
- import { join } from "node:path";
5
- import { tmpdir } from "node:os";
6
- import { notice } from "./state.ts";
7
- import { linkTerm, linkedWs, startWorktree, landWorktree, landRun, codeDir, projectFromWorktree, run, runAsync, workspaces, workspacesNow, addWorktree, wsOf, adoptWorkspace, branchState, openPr, mergePr, removeWorktree, type Run, type AsyncRun } from "./worktree.ts";
8
-
9
- const ID = "2026-10-17-demo";
10
- // CI runners have no git identity, and landWorktree's rebase writes commits.
11
- const idRun: Run = (cmd, cwd) => run(cmd[0] === "git" ? ["git", "-c", "user.email=a@b.c", "-c", "user.name=t", ...cmd.slice(1)] : cmd, cwd);
12
- let remote: string, project: string, other: string;
13
- const g = (cwd: string, ...a: string[]) => { const r = run(["git", "-c", "user.email=a@b.c", "-c", "user.name=t", ...a], cwd); if (!r.ok) throw new Error(r.why); return r.out; };
14
- const commit = (cwd: string, f: string, text: string) => { writeFileSync(join(cwd, f), text); g(cwd, "add", f); g(cwd, "commit", "-qm", `feat: ${f}`); };
15
- const state = () => JSON.parse(readFileSync(join(project, ".kaizen/runs", ID, "state.json"), "utf8"));
16
-
17
- beforeEach(() => {
18
- const root = mkdtempSync(join(tmpdir(), "wt-"));
19
- remote = join(root, "remote.git"); project = join(root, "project"); other = join(root, "other");
20
- g(root, "init", "-q", "--bare", "-b", "main", remote);
21
- g(root, "clone", "-q", remote, project);
22
- commit(project, "a.txt", "a"); g(project, "push", "-q", "origin", "HEAD:main");
23
- g(root, "clone", "-q", remote, other);
24
- mkdirSync(join(project, ".kaizen/runs", ID), { recursive: true });
25
- writeFileSync(join(project, ".kaizen/runs", ID, "state.json"), JSON.stringify({ id: ID, stage: "build" }));
26
- writeFileSync(join(project, ".gitignore"), ".kaizen/*\n");
27
- });
28
-
29
- test("G-01 start leaves the project folder alone and records the worktree", () => {
30
- writeFileSync(join(project, "dirty.txt"), "someone else's edit");
31
- const head = g(project, "rev-parse", "HEAD"), br = g(project, "branch", "--show-current");
32
- const r = startWorktree(project, ID);
33
- expect(r.ok).toBe(true);
34
- expect(g(project, "rev-parse", "HEAD")).toBe(head);
35
- expect(g(project, "branch", "--show-current")).toBe(br);
36
- expect(readFileSync(join(project, "dirty.txt"), "utf8")).toBe("someone else's edit");
37
- expect(state().branch).toBe(`kaizen/${ID}`);
38
- expect(codeDir(project, ID)).toBe(state().worktree);
39
- expect(startWorktree(project, ID).ok).toBe(true); // a resume
40
- });
41
-
42
- test("G-06 a run id is a slug before it reaches a path or a branch", () => {
43
- expect(startWorktree(project, "../evil").ok).toBe(false);
44
- expect(startWorktree(project, "x; rm -rf").ok).toBe(false);
45
- expect(landWorktree(project, "../evil").ok).toBe(false);
46
- });
47
-
48
- test("G-02 lands by rebase and push after main moved on", () => {
49
- const w = (startWorktree(project, ID) as { path: string }).path;
50
- commit(w, "run.txt", "mine");
51
- commit(other, "theirs.txt", "x"); g(other, "push", "-q", "origin", "HEAD:main"); // main moves ahead
52
- const r = landWorktree(project, ID, idRun, false);
53
- expect(r).toEqual({ ok: true, how: "push", url: undefined });
54
- g(project, "fetch", "-q", "origin");
55
- expect(g(project, "ls-tree", "--name-only", "origin/main").split("\n")).toEqual(["a.txt", "run.txt", "theirs.txt"]);
56
- expect(existsSync(w)).toBe(false); // G-04: gone only after landing
57
- expect(state().worktree).toBeUndefined();
58
- });
59
-
60
- test("G-02 lands by pull request when gh is there", () => {
61
- const w = (startWorktree(project, ID) as { path: string }).path;
62
- commit(w, "run.txt", "mine");
63
- const calls: string[][] = [];
64
- const sh: Run = (cmd, cwd) => {
65
- if (cmd[0] !== "gh") return run(cmd, cwd);
66
- calls.push(cmd);
67
- if (cmd[2] === "create") return { ok: true, out: "https://github.com/x/y/pull/1", why: "" };
68
- // gh's rebase-merge, done by hand: the work reaches main under new hashes
69
- g(cwd, "fetch", "-q", "origin"); g(cwd, "rebase", "-q", "origin/main");
70
- g(cwd, "push", "-q", "origin", "HEAD:main");
71
- return { ok: true, out: "", why: "" };
72
- };
73
- commit(other, "theirs.txt", "x"); g(other, "push", "-q", "origin", "HEAD:main");
74
- const r = landWorktree(project, ID, sh, true);
75
- expect(r).toEqual({ ok: true, how: "pr", url: "https://github.com/x/y/pull/1" });
76
- expect(calls.map((c) => c.slice(0, 4).join(" "))).toEqual(["gh pr create --base", "gh pr merge kaizen/" + ID]);
77
- expect(existsSync(w)).toBe(false);
78
- });
79
-
80
- test("G-03 a conflict keeps the worktree and branch and says so", () => {
81
- const w = (startWorktree(project, ID) as { path: string }).path;
82
- commit(w, "a.txt", "mine");
83
- commit(other, "a.txt", "theirs"); g(other, "push", "-q", "origin", "HEAD:main");
84
- const r = landWorktree(project, ID, run, false);
85
- expect(r.ok).toBe(false);
86
- expect(existsSync(w)).toBe(true);
87
- expect(g(project, "branch", "--list", `kaizen/${ID}`)).toContain(ID);
88
- expect(g(w, "status", "--porcelain")).toBe(""); // rebase aborted, tree clean
89
- });
90
-
91
- test("G-03 a pull request that will not merge is left open", () => {
92
- const w = (startWorktree(project, ID) as { path: string }).path;
93
- commit(w, "run.txt", "mine");
94
- const sh: Run = (cmd, cwd) => cmd[0] !== "gh" ? run(cmd, cwd)
95
- : cmd[2] === "create" ? { ok: true, out: "url", why: "" } : { ok: false, out: "", why: "not mergeable" };
96
- const r = landWorktree(project, ID, sh, true);
97
- expect(r.ok).toBe(false);
98
- expect(existsSync(w)).toBe(true);
99
- });
100
-
101
- test("G-03 uncommitted work in the worktree is never landed or removed", () => {
102
- const w = (startWorktree(project, ID) as { path: string }).path;
103
- writeFileSync(join(w, "wip.txt"), "unsaved");
104
- expect(landWorktree(project, ID, run, false).ok).toBe(false);
105
- expect(existsSync(join(w, "wip.txt"))).toBe(true);
106
- });
107
-
108
- test("G-05 a run with no worktree has none to land and codeDir is the project", () => {
109
- expect(codeDir(project, ID)).toBe(project);
110
- expect(landWorktree(project, ID, run, false)).toEqual({ ok: false, why: "this run has no worktree" });
111
- });
112
-
113
- test("projectFromWorktree finds the project from inside a run's folder", () => {
114
- expect(projectFromWorktree("/p/.kaizen/wt/2026-10-17-x/cli")).toBe("/p");
115
- expect(projectFromWorktree("/p/cli")).toBe("/p/cli");
116
- });
117
-
118
- test("workspaces: the main checkout, then each worktree; a folder that is not git is one workspace", () => {
119
- expect(addWorktree(project, "-x", idRun).ok).toBe(false);
120
- expect(addWorktree(project, "bad..name", idRun)).toMatchObject({ ok: false });
121
- const r = addWorktree(project, "feat/two", idRun);
122
- expect(r.ok).toBe(true);
123
- expect(existsSync(join(project, ".kaizen/wt/feat-two"))).toBe(true);
124
- expect(addWorktree(project, "feat/two", idRun).ok).toBe(false); // folder exists
125
- const ws = workspaces(project, idRun);
126
- expect(ws[0]).toEqual({ path: project, branch: "main", main: true });
127
- expect(ws.slice(1)).toEqual([{ path: (r as any).path, branch: "feat/two", main: false }]);
128
- const plain = mkdtempSync(join(tmpdir(), "nogit-"));
129
- expect(workspaces(plain, idRun)).toEqual([{ path: plain, branch: "", main: true }]);
130
- // A run's workspace: its worktree while on disk, else the main checkout.
131
- expect(wsOf(project, { worktree: (r as any).path })).toBe((r as any).path);
132
- expect(wsOf(project, { worktree: join(project, ".kaizen/wt/gone") })).toBe(project);
133
- expect(wsOf(project, {})).toBe(project);
134
- });
135
-
136
- test("adoptWorkspace: a run started inside another workspace is placed there, with no worktree of its own", () => {
137
- const r = addWorktree(project, "feat/two", idRun) as { path: string };
138
- expect(adoptWorkspace(project, ID, project)).toBeNull(); // the main checkout: a normal start
139
- mkdirSync(join(r.path, "sub"));
140
- expect(adoptWorkspace(project, ID, join(r.path, "sub"))).toEqual({ ok: true, path: r.path });
141
- expect(state().workspace).toBe(r.path);
142
- expect(state().worktree).toBeUndefined(); // land must never remove a folder the user made
143
- expect(wsOf(project, state())).toBe(r.path);
144
- expect(codeDir(project, ID)).toBe(project);
145
- });
146
-
147
- test("workspacesNow: answers at once, refreshes git in the background, one call at a time", async () => {
148
- const p = mkdtempSync(join(tmpdir(), "wsnow-"));
149
- let calls = 0, done!: (o: { ok: boolean; out: string; why: string }) => void;
150
- const slow = () => { calls++; return new Promise<any>((r) => (done = r)); };
151
- expect(workspacesNow(p, slow)).toEqual([{ path: p, branch: "", main: true }]); // git still running
152
- expect(workspacesNow(p, slow)).toEqual([{ path: p, branch: "", main: true }]);
153
- expect(calls).toBe(1);
154
- done({ ok: true, out: `worktree ${p}\nHEAD abc\nbranch refs/heads/dev`, why: "" });
155
- await Bun.sleep(0);
156
- expect(workspacesNow(p, slow)).toEqual([{ path: p, branch: "dev", main: true }]);
157
- expect(calls).toBe(1);
158
- });
159
-
160
- // ---- the Git tab (2026-10-30-run-git-tab)
161
-
162
- // gh faked, git real: GitHub is never asked, the branch and the worktree are real.
163
- const fakeGh = (answer: (cmd: string[], cwd: string) => { ok: boolean; out: string; why: string }) => {
164
- const calls: string[][] = [];
165
- const ash: AsyncRun = async (cmd, cwd) => {
166
- if (cmd[0] !== "gh") return runAsync(cmd[0] === "git" ? ["git", "-c", "user.email=a@b.c", "-c", "user.name=t", ...cmd.slice(1)] : cmd, cwd);
167
- calls.push(cmd);
168
- return answer(cmd, cwd);
169
- };
170
- return { ash, calls };
171
- };
172
- const ghRun: Run = (cmd, cwd) => { if (cmd[0] === "gh") throw new Error("gh run on the request path"); return idRun(cmd, cwd); };
173
- const tick = () => new Promise((r) => setTimeout(r, 50));
174
-
175
- test("G-03 branchState never asks GitHub on the request path and shows the PR once the look lands", async () => {
176
- const id = "2026-10-30-look";
177
- mkdirSync(join(project, ".kaizen/runs", id), { recursive: true });
178
- writeFileSync(join(project, ".kaizen/runs", id, "state.json"), JSON.stringify({ id, stage: "done" }));
179
- startWorktree(project, id);
180
- const pr = { number: 7, url: "https://github.com/x/y/pull/7", state: "OPEN", isDraft: false };
181
- const { ash, calls } = fakeGh(() => ({ ok: true, out: JSON.stringify(pr), why: "" }));
182
- let changed = 0;
183
- const first = branchState(project, id, () => changed++, ghRun, ash, true)!;
184
- expect(first).toMatchObject({ branch: `kaizen/${id}`, base: "main", upstream: false, landed: false, pr: null, checking: true });
185
- await tick();
186
- expect(calls.map((c) => c.slice(0, 4).join(" "))).toEqual([`gh pr view kaizen/${id}`]);
187
- expect(changed).toBe(1);
188
- const again = branchState(project, id, () => changed++, ghRun, ash, true)!;
189
- expect(again.pr).toEqual({ number: 7, url: pr.url, state: "OPEN", draft: false });
190
- expect(again.checking).toBe(false);
191
- await tick();
192
- expect(calls.length).toBe(1); // cached: no second look inside 30 s
193
- });
194
-
195
- test("G-02 a run with no worktree has no branch state; one with no commits of its own is not landed", () => {
196
- expect(branchState(project, ID, () => {}, ghRun, runAsync, false)).toBeNull();
197
- startWorktree(project, ID);
198
- expect(branchState(project, ID, () => {}, ghRun, runAsync, false)!.landed).toBe(false);
199
- });
200
-
201
- test("G-06 openPr pushes, then creates the PR with title and body as separate arguments", async () => {
202
- const w = (startWorktree(project, ID) as { path: string }).path;
203
- commit(w, "run.txt", "mine");
204
- const { ash, calls } = fakeGh((cmd) => cmd[2] === "view"
205
- ? { ok: true, out: JSON.stringify({ number: 3, url: "u", state: "OPEN", isDraft: true }), why: "" }
206
- : { ok: true, out: "u", why: "" });
207
- const r = await openPr(project, ID, "feat: a; rm -rf /", "Run x.\n$(id)", true, idRun, ash, true);
208
- expect(r).toEqual({ ok: true, pr: { number: 3, url: "u", state: "OPEN", draft: true } });
209
- expect(calls[0]).toEqual(["gh", "pr", "create", "--base", "main", "--head", `kaizen/${ID}`, "--title", "feat: a; rm -rf /", "--body", "Run x.\n$(id)", "--draft"]);
210
- expect(g(project, "ls-remote", "--heads", "origin", `kaizen/${ID}`)).toContain(ID); // pushed first
211
- });
212
-
213
- test("G-06 openPr refuses a dirty worktree, no gh, an empty title, and a run without a branch", async () => {
214
- const { ash, calls } = fakeGh(() => ({ ok: true, out: "", why: "" }));
215
- expect((await openPr(project, ID, "t", "", false, idRun, ash, true)).ok).toBe(false); // no worktree
216
- const w = (startWorktree(project, ID) as { path: string }).path;
217
- expect((await openPr(project, ID, "t", "", false, idRun, ash, false)).ok).toBe(false);
218
- expect((await openPr(project, ID, " ", "", false, idRun, ash, true)).ok).toBe(false);
219
- writeFileSync(join(w, "dirty.txt"), "x");
220
- const r = await openPr(project, ID, "t", "", false, idRun, ash, true);
221
- expect(r).toEqual({ ok: false, why: "Commit the changes first." });
222
- expect(calls).toEqual([]);
223
- });
224
-
225
- test("G-06 mergePr merges by rebase with the branch name", async () => {
226
- startWorktree(project, ID);
227
- const { ash, calls } = fakeGh(() => ({ ok: true, out: "", why: "" }));
228
- expect(await mergePr(project, ID, idRun, ash, true)).toEqual({ ok: true });
229
- expect(calls).toEqual([["gh", "pr", "merge", `kaizen/${ID}`, "--rebase"]]);
230
- });
231
-
232
- test("G-04 removeWorktree refuses dirty or unlanded work and cleans up once it is on the base", async () => {
233
- const w = (startWorktree(project, ID) as { path: string }).path;
234
- commit(w, "run.txt", "mine");
235
- writeFileSync(join(w, "wip.txt"), "x");
236
- expect((await removeWorktree(project, ID, idRun)).ok).toBe(false);
237
- g(w, "add", "wip.txt"); g(w, "commit", "-qm", "feat: wip");
238
- const unlanded = await removeWorktree(project, ID, idRun);
239
- expect(unlanded.ok).toBe(false);
240
- expect(existsSync(w)).toBe(true);
241
- // GitHub's rebase-merge, by hand: the work reaches main under new hashes.
242
- commit(other, "theirs.txt", "x"); g(other, "push", "-q", "origin", "HEAD:main");
243
- g(w, "fetch", "-q", "origin"); g(w, "rebase", "-q", "origin/main"); g(w, "push", "-q", "origin", "HEAD:main");
244
- g(w, "push", "-q", "origin", `HEAD:refs/heads/kaizen/${ID}`);
245
- expect(await removeWorktree(project, ID, idRun)).toEqual({ ok: true });
246
- expect(existsSync(w)).toBe(false);
247
- expect(g(project, "branch", "--list", `kaizen/${ID}`)).toBe("");
248
- expect(g(project, "ls-remote", "--heads", "origin", `kaizen/${ID}`)).toBe("");
249
- expect(state().worktree).toBeUndefined();
250
- expect(state().branch).toBeUndefined();
251
- });
252
-
253
- test("G-04 removeWorktree keeps unmerged work when nothing can prove it landed (no origin)", async () => {
254
- const w = (startWorktree(project, ID) as { path: string }).path;
255
- commit(w, "run.txt", "mine");
256
- g(project, "remote", "remove", "origin");
257
- const r = await removeWorktree(project, ID, idRun);
258
- expect(r.ok).toBe(false);
259
- expect(existsSync(w)).toBe(true);
260
- expect(g(project, "branch", "--list", `kaizen/${ID}`)).toContain(ID);
261
- });
262
-
263
- test("a linked terminal shows its live run's worktree, then falls back", () => {
264
- const p = realpathSync(mkdtempSync(join(tmpdir(), "kz-link-"))), state = join(p, ".kaizen"), id = "r1", wt = join(p, "wt");
265
- mkdirSync(join(state, "runs", id), { recursive: true }); mkdirSync(wt);
266
- const put = (s: object) => writeFileSync(join(state, "runs", id, "state.json"), JSON.stringify(s));
267
- put({ stage: "build", worktree: wt });
268
- linkTerm(state, "bad key", id);
269
- linkTerm(state, "sh-0123abcd", id);
270
- expect(linkedWs(state, "sh-0123abcd")).toBe(wt);
271
- expect(linkedWs(state, "sh-ffffffff")).toBeNull(); // an unlinked terminal stays put
272
- put({ stage: "done", worktree: wt });
273
- expect(linkedWs(state, "sh-0123abcd")).toBeNull();
274
- put({ stage: "abandoned", worktree: wt });
275
- expect(linkedWs(state, "sh-0123abcd")).toBeNull();
276
- put({ stage: "build", worktree: join(p, "gone") });
277
- expect(linkedWs(state, "sh-0123abcd")).toBeNull();
278
- put({ stage: "build" }); // a current-folder run has no worktree
279
- expect(linkedWs(state, "sh-0123abcd")).toBeNull();
280
- });
281
-
282
- const feature = () => { g(project, "switch", "-qc", "feature-x"); commit(project, "f.txt", "unpushed"); };
283
-
284
- test("G-02 on a feature branch the worktree holds unpushed commits and lands by a local merge", () => {
285
- feature();
286
- const r = startWorktree(project, ID);
287
- expect(r.ok).toBe(true);
288
- expect(state().base_branch).toBe("feature-x");
289
- expect(existsSync(join(state().worktree, "f.txt"))).toBe(true);
290
- commit(state().worktree, "b.txt", "b");
291
- const dir = state().worktree;
292
- expect(landWorktree(project, ID, idRun)).toMatchObject({ ok: true, how: "merge" });
293
- expect(existsSync(join(project, "b.txt"))).toBe(true);
294
- expect(existsSync(dir)).toBe(false);
295
- expect(run(["git", "rev-parse", "--verify", "--quiet", "refs/remotes/origin/feature-x"], project).ok).toBe(false);
296
- });
297
-
298
- test("G-03 a conflict, or the project on another branch, keeps the worktree and branch", () => {
299
- feature();
300
- startWorktree(project, ID);
301
- const dir = state().worktree;
302
- commit(dir, "f.txt", "theirs"); commit(project, "f.txt", "ours");
303
- const c = landWorktree(project, ID, idRun);
304
- expect(c.ok).toBe(false);
305
- expect(g(project, "status", "--porcelain").includes("U")).toBe(false);
306
- g(project, "switch", "-q", "main");
307
- const o = landWorktree(project, ID, idRun);
308
- expect(!o.ok && o.why).toContain("feature-x");
309
- expect(existsSync(dir)).toBe(true);
310
- expect(run(["git", "rev-parse", "--verify", "--quiet", "refs/heads/kaizen/" + ID], project).ok).toBe(true);
311
- });
312
-
313
- test("G-02 uncommitted changes on the feature branch are warned about", () => {
314
- feature(); writeFileSync(join(project, "wip.txt"), "wip");
315
- const r = startWorktree(project, ID);
316
- expect(r.ok && r.warn).toContain("wip.txt");
317
- });
318
-
319
- test("G-01 on the default branch no base_branch is recorded", () => {
320
- startWorktree(project, ID);
321
- expect(state().base_branch).toBeUndefined();
322
- });
323
-
324
- test("land again after a merge whose cleanup failed only cleans up", () => {
325
- feature(); startWorktree(project, ID);
326
- commit(state().worktree, "b.txt", "b");
327
- g(project, "merge", "--no-edit", "kaizen/" + ID);
328
- const head = g(project, "rev-parse", "HEAD");
329
- expect(landWorktree(project, ID, idRun)).toMatchObject({ ok: true, how: "merge" });
330
- expect(g(project, "rev-parse", "HEAD")).toBe(head);
331
- });
332
-
333
- test("cold 6: a run with no commits is not landed, and a feature base offers no pull request", async () => {
334
- feature(); startWorktree(project, ID);
335
- const r = landWorktree(project, ID, idRun);
336
- expect(!r.ok && r.why).toContain("no commits");
337
- expect(existsSync(state().worktree)).toBe(true);
338
- const b = branchState(project, ID, () => {}, idRun, runAsync, true)!;
339
- expect(b).toMatchObject({ base: "feature-x", local: true, gh: false });
340
- expect((await openPr(project, ID, "t", "b", false, idRun, runAsync, true)).ok).toBe(false);
341
- });
342
-
343
- // ---- land: rebase first, resolve only what is generated, record what stops it
344
- const land = () => landWorktree(project, ID, idRun, false);
345
- const cfg = (t: string) => writeFileSync(join(project, ".kaizen/config.yml"), t);
346
- const upstream = (f: string, t: string) => { commit(other, f, t); g(other, "pull", "-q", "--rebase", "origin", "main"); g(other, "push", "-q", "origin", "HEAD:main"); };
347
- const wt = () => state().worktree as string;
348
-
349
- test("L-01 a stale branch that was never pushed lands with no force", () => {
350
- startWorktree(project, ID); commit(wt(), "b.txt", "b"); upstream("c.txt", "c");
351
- const seen: string[][] = [];
352
- const r = landWorktree(project, ID, (c, d, m) => (seen.push(c), idRun(c, d, m)), false);
353
- expect(r.ok).toBe(true);
354
- expect(seen.flat().join(" ")).not.toContain("force");
355
- expect(g(other, "ls-remote", "origin", "main")).toBeTruthy();
356
- });
357
-
358
- test("L-02 conflicts only in generated files land, rebuilt in one commit", () => {
359
- cfg('git:\n generated: "*.js"\n rebuild_on_land: "echo rebuilt > app.js"\n land_check: off\n');
360
- commit(project, "app.js", "0"); g(project, "push", "-q", "origin", "HEAD:main"); g(other, "pull", "-q", "origin", "main");
361
- startWorktree(project, ID); writeFileSync(join(wt(), "app.js"), "mine"); writeFileSync(join(wt(), "b.txt"), "b"); g(wt(), "add", "."); g(wt(), "commit", "-qm", "feat: b");
362
- upstream("app.js", "theirs");
363
- expect(land().ok).toBe(true);
364
- g(other, "pull", "-q", "origin", "main");
365
- expect(readFileSync(join(other, "app.js"), "utf8").trim()).toBe("rebuilt");
366
- expect(g(other, "log", "--format=%s", "-3")).toContain("chore: rebuild generated files");
367
- expect(readFileSync(join(other, "b.txt"), "utf8")).toBe("b");
368
- });
369
-
370
- test("L-03 any other conflict aborts with branch, worktree and commits intact; default settings resolve nothing", () => {
371
- startWorktree(project, ID); commit(wt(), "a.txt", "mine"); const tip = g(wt(), "rev-parse", "HEAD");
372
- upstream("a.txt", "theirs");
373
- const r = land();
374
- expect(r).toMatchObject({ ok: false, kind: "conflict", paths: ["a.txt"] });
375
- expect(g(wt(), "rev-parse", "HEAD")).toBe(tip);
376
- expect(g(wt(), "status", "--porcelain")).toBe("");
377
- expect(existsSync(wt())).toBe(true);
378
- });
379
-
380
- test("L-04 a failing check stops the land and puts the branch back; off and no pulled commits skip it", () => {
381
- cfg('git:\n land_check: "exit 3"\n');
382
- startWorktree(project, ID); commit(wt(), "b.txt", "b"); const tip = g(wt(), "rev-parse", "HEAD");
383
- upstream("c.txt", "c");
384
- expect(land()).toMatchObject({ ok: false, kind: "check" });
385
- expect(g(wt(), "rev-parse", "HEAD")).toBe(tip);
386
- cfg('git:\n land_check: off\n');
387
- expect(land().ok).toBe(true);
388
- });
389
-
390
- test("L-04b no pulled commits skip the check", () => {
391
- cfg('git:\n land_check: "exit 3"\n');
392
- startWorktree(project, ID); commit(wt(), "b.txt", "b");
393
- expect(land().ok).toBe(true);
394
- });
395
-
396
- test("L-05 merge=union keeps both lines of the log", () => {
397
- commit(project, ".gitattributes", "Log.md merge=union\n"); commit(project, "Log.md", "0\n"); g(project, "push", "-q", "origin", "HEAD:main"); g(other, "pull", "-q", "origin", "main");
398
- startWorktree(project, ID); commit(wt(), "Log.md", "0\nmine\n"); upstream("Log.md", "0\ntheirs\n");
399
- expect(land().ok).toBe(true);
400
- g(other, "pull", "-q", "origin", "main");
401
- const log = readFileSync(join(other, "Log.md"), "utf8");
402
- expect(log).toContain("mine"); expect(log).toContain("theirs");
403
- });
404
-
405
- test("L-06 a rebased pushed branch force pushes under a lease, on its own branch only", () => {
406
- startWorktree(project, ID); commit(wt(), "b.txt", "b"); g(wt(), "push", "-q", "origin", `HEAD:refs/heads/kaizen/${ID}`); upstream("c.txt", "c");
407
- const pushes: string[][] = [];
408
- const r = landWorktree(project, ID, (c, d, m) => { if (c.includes("push")) pushes.push(c); return c.includes("gh") ? { ok: true, out: "", why: "" } : idRun(c, d, m); }, true);
409
- const forced = pushes.filter((p) => p.some((a) => a.includes("force")));
410
- expect(forced.length).toBe(1);
411
- expect(forced[0]!.some((a) => a.startsWith(`--force-with-lease=refs/heads/kaizen/${ID}:`))).toBe(true);
412
- expect(forced[0]!.at(-1)).toBe(`HEAD:refs/heads/kaizen/${ID}`);
413
- expect(r.ok).toBe(false); // the stub gh merged nothing
414
- });
415
-
416
- test("L-07 land.json records a failure and clears on success", () => {
417
- startWorktree(project, ID); commit(wt(), "a.txt", "mine");
418
- const f = join(project, ".kaizen/runs", ID, "land.json");
419
- writeFileSync(f, JSON.stringify({ kind: "conflict", why: "old" }));
420
- const r = landRun(project, ID);
421
- // No git identity in CI matters only for a rebase; nothing was pulled here.
422
- expect(r.ok).toBe(true);
423
- expect(existsSync(f)).toBe(false);
424
- });
425
-
426
- test("L-08 land.json holds what stopped the land, and the board card reads it", () => {
427
- // landRun uses the plain runner: give this repo the identity CI lacks.
428
- g(project, "config", "user.email", "a@b.c"); g(project, "config", "user.name", "t");
429
- startWorktree(project, ID); commit(wt(), "a.txt", "mine"); upstream("a.txt", "theirs");
430
- expect(landRun(project, ID, "sh-12345678").ok).toBe(false);
431
- const l = JSON.parse(readFileSync(join(project, ".kaizen/runs", ID, "land.json"), "utf8"));
432
- expect(l).toMatchObject({ kind: "conflict", paths: ["a.txt"], term: "sh-12345678" });
433
- expect(notice({ kind: "run", text: "x", where: "p", status: "done", land: l } as any)).toBe("x — conflict: a.txt\np");
434
- });
435
-
436
- test("L-09 generated conflict with no rebuild command stops the land", () => {
437
- cfg('git:\n generated: "*.js"\n land_check: off\n');
438
- commit(project, "app.js", "0"); g(project, "push", "-q", "origin", "HEAD:main"); g(other, "pull", "-q", "origin", "main");
439
- startWorktree(project, ID); commit(wt(), "app.js", "mine"); const tip = g(wt(), "rev-parse", "HEAD"); upstream("app.js", "theirs");
440
- expect(land()).toMatchObject({ ok: false, kind: "conflict", paths: ["app.js"] });
441
- expect(g(wt(), "rev-parse", "HEAD")).toBe(tip);
442
- });
443
-
444
- test("L-10 a failure with no kind replaces an old Conflict; a run with no worktree records nothing", () => {
445
- const f = join(project, ".kaizen/runs", ID, "land.json");
446
- expect(landRun(project, ID).ok).toBe(false);
447
- expect(existsSync(f)).toBe(false);
448
- startWorktree(project, ID); writeFileSync(f, JSON.stringify({ kind: "conflict", why: "old" }));
449
- writeFileSync(join(wt(), "dirty.txt"), "x");
450
- expect(landRun(project, ID).ok).toBe(false);
451
- expect(JSON.parse(readFileSync(f, "utf8")).kind).toBe("merge");
452
- });
@@ -1,102 +0,0 @@
1
- // Write-back against a throwaway .kaizen/: gh and Google are injected, nothing leaves the machine.
2
- import { test, expect, beforeEach, afterAll } from "bun:test";
3
- import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, realpathSync } from "node:fs";
4
- import { join } from "node:path";
5
- import { tmpdir } from "node:os";
6
- import { readIcebox, writeIcebox, writeSources, sift } from "./sources.ts";
7
- import { writeBacks } from "./writeback.ts";
8
-
9
- const root = realpathSync(mkdtempSync(join(tmpdir(), "kaizen-wb-")));
10
- let state: string;
11
- let n = 0;
12
- beforeEach(() => { state = join(root, String(n++), ".kaizen"); mkdirSync(state, { recursive: true }); });
13
- afterAll(() => rmSync(root, { recursive: true, force: true }));
14
-
15
- const GH = "https://github.com/acme/app/issues";
16
- const SHEET = "https://docs.google.com/spreadsheets/d/abc123/edit#gid=7";
17
- const item = (source: string, extra = {}) => ({ id: "a1", text: "Dark mode", source, at: "2026-10-17", status: "done" as const, run: "r1", ...extra });
18
- const source = (url: string, writeback = true) => writeSources(state, [{ url, added: "x", seen: [], ...(writeback ? { writeback } : {}) }]);
19
-
20
- test("github: a done item closes its issue once, with fixed text", async () => {
21
- source(GH);
22
- writeIcebox(state, [item(GH, { notes: "#12 · https://github.com/acme/app/issues/12" })]);
23
- const calls: string[][] = [];
24
- const gh = async (a: string[]) => { calls.push(a); return { code: 0, err: "" }; };
25
- await writeBacks(state, { gh });
26
- await writeBacks(state, { gh });
27
- expect(calls).toEqual([["issue", "close", "12", "--repo", "acme/app", "--comment", "Done in kaizen run r1."]]);
28
- expect(readIcebox(state)[0]!.written).toBeTruthy();
29
- });
30
-
31
- test("off by default: nothing is sent", async () => {
32
- source(GH, false);
33
- writeIcebox(state, [item(GH, { notes: "#12 · x" })]);
34
- let sent = 0;
35
- await writeBacks(state, { gh: async () => { sent++; return { code: 0, err: "" }; } });
36
- expect(sent).toBe(0);
37
- });
38
-
39
- test("a failed write stays done, keeps the error and is tried again", async () => {
40
- source(GH);
41
- writeIcebox(state, [item(GH, { notes: "#12 · x" })]);
42
- await writeBacks(state, { gh: async () => ({ code: 1, err: "boom\nHTTP 401" }) });
43
- expect(readIcebox(state)[0]).toMatchObject({ status: "done", writeError: "HTTP 401" });
44
- expect(readIcebox(state)[0]!.written).toBeUndefined();
45
- await writeBacks(state, { gh: async () => ({ code: 0, err: "" }) });
46
- expect(readIcebox(state)[0]!.written).toBeTruthy();
47
- expect(readIcebox(state)[0]!.writeError).toBeUndefined();
48
- });
49
-
50
- function google(rows: string[][]) {
51
- const puts: { url: string; body: any }[] = [];
52
- const doFetch = (async (url: string, init: any = {}) => {
53
- if (init.method === "PUT") { puts.push({ url: decodeURIComponent(url), body: JSON.parse(init.body) }); return Response.json({}); }
54
- if (url.includes("fields=sheets")) return Response.json({ sheets: [{ properties: { sheetId: 7, title: "Req" } }] });
55
- const range = /values\/([^?]+)/.exec(decodeURIComponent(url))![1]!;
56
- const m = /!(\d+):(\d+)$/.exec(range)!;
57
- return Response.json({ values: rows.slice(+m[1]! - 1, +m[2]!) });
58
- }) as unknown as typeof fetch;
59
- return { puts, doFetch };
60
- }
61
-
62
- test("sift records the sheet row an item came from", () => {
63
- const { items } = sift("sheet", "Request\tStatus\nDark mode\topen\nFaster search\topen\n");
64
- expect(items.map((i) => [i.text, i.row])).toEqual([["Dark mode", 2], ["Faster search", 3]]);
65
- });
66
-
67
- const token = async () => "t";
68
-
69
- test("sheet: adds a Status column when missing, then writes Done in the row", async () => {
70
- source(SHEET);
71
- writeIcebox(state, [item(SHEET, { row: 2 })]);
72
- const g = google([["Request"], ["Dark mode"]]);
73
- await writeBacks(state, { fetch: g.doFetch, token });
74
- expect(g.puts.map((p) => [p.url.split("values/")[1]!.split("?")[0], p.body.values[0][0]])).toEqual([["'Req'!B1", "Status"], ["'Req'!B2", "Done in kaizen run r1."]]);
75
- expect(readIcebox(state)[0]!.written).toBeTruthy();
76
- });
77
-
78
- test("sheet: a row that no longer holds the request is left alone", async () => {
79
- source(SHEET);
80
- writeIcebox(state, [item(SHEET, { row: 2 })]);
81
- const g = google([["Request", "Status"], ["Something else", ""]]);
82
- await writeBacks(state, { fetch: g.doFetch, token });
83
- expect(g.puts).toEqual([]);
84
- expect(readIcebox(state)[0]).toMatchObject({ writeError: "the row has changed since it was gathered" });
85
- });
86
-
87
- test("sheet: uses the existing Status column", async () => {
88
- source(SHEET);
89
- writeIcebox(state, [item(SHEET, { row: 2 })]);
90
- const g = google([["Request", "Owner", "Status"], ["Dark mode", "x", ""]]);
91
- await writeBacks(state, { fetch: g.doFetch, token });
92
- expect(g.puts.map((p) => p.url.split("values/")[1]!.split("?")[0])).toEqual(["'Req'!C2"]);
93
- });
94
-
95
- test("sheet: a header below row 10 is still found", async () => {
96
- source(SHEET);
97
- const rows = [...Array.from({ length: 14 }, () => [""]), ["Request", "Status"], ["Dark mode", ""]];
98
- writeIcebox(state, [item(SHEET, { row: 16 })]);
99
- const g = google(rows);
100
- await writeBacks(state, { fetch: g.doFetch, token });
101
- expect(g.puts.map((p) => p.url.split("values/")[1]!.split("?")[0])).toEqual(["'Req'!B16"]);
102
- });
@@ -1,20 +0,0 @@
1
- import { expect, test } from "bun:test";
2
- import { match } from "./search-match.ts";
3
-
4
- const it = (title: string, at = 0, hay = "") => ({ group: "g", title, hay, at, ico: "run", act: () => {} });
5
-
6
- test("an empty query keeps every item", () => {
7
- const l = [it("a"), it("b")];
8
- expect(match(l, " ")).toBe(l);
9
- });
10
-
11
- test("every word must be present, in title, sub or keywords", () => {
12
- const l = [it("Global search", 0, "kaizen"), it("Search tests"), it("Board")];
13
- expect(match(l, "search kaizen").map((i) => i.title)).toEqual(["Global search"]);
14
- expect(match(l, "SEARCH").map((i) => i.title).sort()).toEqual(["Global search", "Search tests"]);
15
- });
16
-
17
- test("title prefix beats title contains beats keywords, then recency", () => {
18
- const l = [it("Old board", 5, ""), it("Notes", 9, "board"), it("Board new", 1), it("Board recent", 3)];
19
- expect(match(l, "board").map((i) => i.title)).toEqual(["Board recent", "Board new", "Old board", "Notes"]);
20
- });
@@ -1,28 +0,0 @@
1
- import { expect, test } from "bun:test";
2
- import { readFileSync } from "node:fs";
3
- import { placeOf, SETTINGS_NAV } from "./settings-pages.ts";
4
-
5
- const pages = new Set(SETTINGS_NAV.flatMap(([, ps]) => ps.map((p) => p.id)));
6
- const keys = [...readFileSync(new URL("../../cli/settings.ts", import.meta.url), "utf8").matchAll(/\{ key: "([\w.]+)", label:/g)].map((m) => m[1]);
7
-
8
- test("every setting lands on a real page, under a named subsection", () => {
9
- expect(keys.length).toBeGreaterThan(30);
10
- for (const k of keys) {
11
- const [page, sub] = placeOf(k);
12
- expect(pages.has(page)).toBe(true);
13
- expect([k, sub === "Other"]).toEqual([k, false]);
14
- }
15
- });
16
-
17
- test("a setting not placed yet falls back to General", () => {
18
- expect(placeOf("new.thing")).toEqual(["general", "Other"]);
19
- });
20
-
21
- test("the Orchestration page exists and holds its three settings", () => {
22
- expect(pages.has("orchestration")).toBe(true);
23
- for (const k of ["enabled", "max_workers", "permissions", "worker_model.claude"]) expect(placeOf(`orchestration.${k}`)).toEqual(["orchestration", "Workers"]);
24
- });
25
-
26
- test("the Automations page sits under Workflows", () => {
27
- expect(SETTINGS_NAV.find(([g]) => g === "Workflows")![1].some((p) => p.id === "automations")).toBe(true);
28
- });
@@ -1,18 +0,0 @@
1
- import { expect, test } from "bun:test";
2
- import { micAudio, openMic } from "./settings-voice.ts";
3
-
4
- test("no saved device asks for the default microphone; a saved one is exact", () => {
5
- expect(micAudio().deviceId).toBeUndefined();
6
- expect(micAudio("abc").deviceId).toEqual({ exact: "abc" });
7
- expect(micAudio("abc").channelCount).toBe(1);
8
- });
9
-
10
- test("an unplugged microphone falls back to the default and says so; a refusal does not", async () => {
11
- const asked: any[] = [], said: string[] = [];
12
- const gone = async (a: any) => { asked.push(a); if (a.deviceId) throw Object.assign(new Error(), { name: "OverconstrainedError" }); return "ok" as any; };
13
- expect(await openMic(gone, "abc", (m) => said.push(m))).toBe("ok");
14
- expect(asked.length).toBe(2);
15
- expect(said.length).toBe(1);
16
- const refused = async () => { throw Object.assign(new Error(), { name: "NotAllowedError" }); };
17
- await expect(openMic(refused, "abc", () => {})).rejects.toThrow();
18
- });