kaizen-agent 1.63.0 → 1.64.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 (77) hide show
  1. package/README.md +10 -10
  2. package/agents/kaizen-planner.md +2 -2
  3. package/cli/backlog.test.ts +1 -1
  4. package/cli/board.test.ts +24 -24
  5. package/cli/dashboard.ts +15 -15
  6. package/cli/handoff.test.ts +133 -0
  7. package/cli/handoff.ts +122 -0
  8. package/cli/install.ts +31 -5
  9. package/cli/notes.test.ts +3 -3
  10. package/cli/notes.ts +1 -1
  11. package/cli/pty.ts +16 -2
  12. package/cli/resources.test.ts +50 -0
  13. package/cli/resources.ts +113 -0
  14. package/cli/restart.test.ts +28 -1
  15. package/cli/settings.ts +8 -5
  16. package/cli/sources.test.ts +32 -32
  17. package/cli/sources.ts +15 -15
  18. package/cli/state.test.ts +74 -51
  19. package/cli/state.ts +77 -49
  20. package/cli/usage.test.ts +11 -0
  21. package/cli/web.ts +139 -38
  22. package/cli/workers.ts +11 -4
  23. package/cli/worktree.test.ts +174 -1
  24. package/cli/worktree.ts +190 -35
  25. package/commands/kaizen-discover.md +1 -1
  26. package/package.json +1 -1
  27. package/skills/kaizen/README.md +2 -2
  28. package/skills/kaizen/SKILL.md +2 -2
  29. package/skills/kaizen/config.default.yml +32 -22
  30. package/skills/kaizen/discover.md +8 -8
  31. package/skills/kaizen/gather.md +2 -2
  32. package/skills/kaizen/settings.md +3 -0
  33. package/skills/kaizen/spec-build.md +13 -0
  34. package/skills/kaizen/spec-main.md +13 -0
  35. package/skills/kaizen/spec-plan.md +1 -1
  36. package/skills/kaizen/spec.md +1 -1
  37. package/skills/kaizen-help/SKILL.md +2 -2
  38. package/web/board/api.ts +10 -10
  39. package/web/board/cards.ts +47 -46
  40. package/web/board/git.ts +4 -4
  41. package/web/board/icebox.ts +14 -14
  42. package/web/board/keys.ts +3 -3
  43. package/web/board/labels.ts +2 -2
  44. package/web/board/live.ts +3 -3
  45. package/web/board/main.ts +1 -1
  46. package/web/board/markdown.ts +1 -1
  47. package/web/board/panel.ts +17 -17
  48. package/web/board/phone.ts +10 -12
  49. package/web/board/projects.ts +6 -6
  50. package/web/board/resources.ts +152 -0
  51. package/web/board/run-view.ts +5 -5
  52. package/web/board/search.ts +11 -11
  53. package/web/board/settings-cleanup.ts +42 -0
  54. package/web/board/settings-pages.ts +1 -1
  55. package/web/board/settings.ts +13 -0
  56. package/web/board/store.ts +1 -1
  57. package/web/board/{ideas.ts → tasks.ts} +22 -22
  58. package/web/board/terms.ts +3 -3
  59. package/web/board/views.ts +23 -12
  60. package/web/board/workspace.ts +9 -7
  61. package/web/board/ws-board-ui.ts +1 -1
  62. package/web/board/ws-board.test.ts +1 -1
  63. package/web/board/ws-board.ts +1 -1
  64. package/web/board/ws-tabs.test.ts +10 -2
  65. package/web/board/ws-tabs.ts +10 -9
  66. package/web/board.html +46 -34
  67. package/web/board.js +107 -97
  68. package/web/notebook.js +22 -22
  69. package/web/notebook.ts +5 -5
  70. package/web/notes-lib.ts +2 -2
  71. package/web/notes.html +12 -11
  72. package/web/term-font.test.ts +22 -0
  73. package/web/term-font.ts +30 -0
  74. package/web/term.js +38 -38
  75. package/web/term.ts +13 -2
  76. package/web/video.html +12 -11
  77. package/web/video.js +48 -48
package/cli/state.test.ts CHANGED
@@ -7,10 +7,10 @@ import { tmpdir } from "node:os";
7
7
  import { issueUrl, systemInfo, scrubHome, REPO_URL, home as realHome, trustFolder } from "./state.ts";
8
8
  import * as stateModule from "./state.ts";
9
9
  import {
10
- readRuns, readInbox, writeInbox, replaceIdea, moveIdea, abandonRun, runToIdea, allBacklog, backlog,
10
+ readRuns, readInbox, writeInbox, replaceTask, moveTask, abandonRun, runToTask, allBacklog, backlog,
11
11
  requestTitle, statusOf, columnOf, parseItem, startedRuns, boardCards, parentOf, addCard, readArchive, setArchived,
12
12
  requestOf, agentFlags, plainModel, readNotes, writeNotes, manualCommand, parseNotes, formatNote, appendNote, saveAttachment,
13
- gitStatus, reviewFindings, pickFindings, fixPrompt, approvalPrompt, sessionLaunch, closeSessions, sweepSessions, readSessions, ownerOf, gitStatus, runGit, cardsGit, commitPush, commitStaged, stageFiles, suggestMessage, readCommit, findTerminal, nativePath, pruneRuns, unrechecked, notice, notifier, notifyArgs, winToastArgs, LOGO, type Card,
13
+ gitStatus, reviewFindings, pickFindings, fixPrompt, approvalPrompt, sessionLaunch, closeSessions, sweepSessions, readSessions, ownerOf, gitStatus, runGit, cardsGit, commitPush, commitStaged, stageFiles, suggestMessage, readCommit, findTerminal, nativePath, pruneRuns, pruneSessions, unrechecked, notice, notifier, notifyArgs, winToastArgs, LOGO, type Card,
14
14
  } from "./state.ts";
15
15
 
16
16
  let state: string;
@@ -91,9 +91,9 @@ test("inbox round-trips and ignores malformed lines", () => {
91
91
  expect(readInbox(state).map((l) => l.status)).toEqual(["open", "open", "started", "rejected"]);
92
92
  });
93
93
 
94
- test("inbox reads a bullet typed by hand as an open idea", () => {
94
+ test("inbox reads a bullet typed by hand as an open task", () => {
95
95
  const dir = mkdtempSync(join(tmpdir(), "kz-inbox-"));
96
- writeFileSync(join(dir, "inbox.md"), "# Ideas\n- Add dark mode\n* [ ] Faster search\n- done: shipped\n a note\n");
96
+ writeFileSync(join(dir, "inbox.md"), "# Tasks\n- Add dark mode\n* [ ] Faster search\n- done: shipped\n a note\n");
97
97
  expect(readInbox(dir).map((l) => [l.status, l.text, l.notes])).toEqual([
98
98
  ["open", "Add dark mode", undefined],
99
99
  ["open", "Faster search", undefined],
@@ -102,15 +102,15 @@ test("inbox reads a bullet typed by hand as an open idea", () => {
102
102
  rmSync(dir, { recursive: true, force: true });
103
103
  });
104
104
 
105
- test("boardCards: idea retired once a run's request contains it; started idea sits in planning", () => {
105
+ test("boardCards: task retired once a run's request contains it; started task sits in planning", () => {
106
106
  const cards = boardCards([state], Date.now());
107
- const ideas = cards.filter((k) => k.kind === "idea").map((k) => [k.text, k.column, k.status]);
108
- expect(ideas).toEqual([["retry failed webhooks", 0, "idea"], ["nightly digest", 1, "starting"]]);
107
+ const tasks = cards.filter((k) => k.kind === "idea").map((k) => [k.text, k.column, k.status]);
108
+ expect(tasks).toEqual([["retry failed webhooks", 0, "idea"], ["nightly digest", 1, "starting"]]);
109
109
  const runs = cards.filter((k) => k.kind === "run").map((k) => [k.id, k.column, k.status]);
110
110
  expect(runs).toEqual([["2026-09-03-stale", 2, "stalled"], ["2026-09-02-done", 4, "done"], ["2026-09-01-waiting", 1, "waiting"]]);
111
111
  });
112
112
 
113
- test("boardCards: a started idea stays until its run has a state.json", () => {
113
+ test("boardCards: a started task stays until its run has a state.json", () => {
114
114
  const dir = join(mkdtempSync(join(tmpdir(), "kaizen-")), ".kaizen");
115
115
  const r = join(dir, "runs", "2026-01-01-new");
116
116
  mkdirSync(r, { recursive: true });
@@ -123,7 +123,7 @@ test("boardCards: a started idea stays until its run has a state.json", () => {
123
123
  rmSync(join(dir, ".."), { recursive: true, force: true });
124
124
  });
125
125
 
126
- test("boardCards: a started idea retires into the run its launch's session wrote, however reworded", () => {
126
+ test("boardCards: a started task retires into the run its launch's session wrote, however reworded", () => {
127
127
  const dir = join(mkdtempSync(join(tmpdir(), "kaizen-")), ".kaizen");
128
128
  const r = join(dir, "runs", "2026-01-01-reworded");
129
129
  mkdirSync(r, { recursive: true });
@@ -139,7 +139,7 @@ test("boardCards: a started idea retires into the run its launch's session wrote
139
139
  rmSync(join(dir, ".."), { recursive: true, force: true });
140
140
  });
141
141
 
142
- test("boardCards: a run older than the idea does not retire it", () => {
142
+ test("boardCards: a run older than the task does not retire it", () => {
143
143
  const dir = join(mkdtempSync(join(tmpdir(), "kaizen-")), ".kaizen");
144
144
  const r = join(dir, "runs", "2026-01-01-old");
145
145
  mkdirSync(r, { recursive: true });
@@ -150,29 +150,29 @@ test("boardCards: a run older than the idea does not retire it", () => {
150
150
  writeInbox(dir, [{ status: "open", text: "fix this bugs" }]);
151
151
  expect(readFileSync(join(dir, "inbox.md"), "utf8")).toMatch(/- open: fix this bugs <!-- added:\d+ -->/);
152
152
  expect(readInbox(dir)[0]!.text).toBe("fix this bugs");
153
- const ideas = () => boardCards([dir], Date.now()).filter((k) => k.kind === "idea").map((k) => k.text);
154
- expect(ideas()).toEqual(["fix this bugs"]);
153
+ const tasks = () => boardCards([dir], Date.now()).filter((k) => k.kind === "idea").map((k) => k.text);
154
+ expect(tasks()).toEqual(["fix this bugs"]);
155
155
  // Rewriting keeps the stamp, so an edit to notes does not make it vanish.
156
156
  writeInbox(dir, readInbox(dir).map((l) => ({ status: l.status, text: l.text, notes: "n" })));
157
- expect(ideas()).toEqual(["fix this bugs"]);
157
+ expect(tasks()).toEqual(["fix this bugs"]);
158
158
  // A run started after it retires it as before.
159
159
  utimesSync(join(r, "00-request.md"), new Date(), new Date(Date.now() + 5000));
160
- expect(ideas()).toEqual([]);
161
- // Re-adding the same words while an old line holds them is a new idea with its
160
+ expect(tasks()).toEqual([]);
161
+ // Re-adding the same words while an old line holds them is a new task with its
162
162
  // own stamp, not the old line's (or no) stamp.
163
163
  writeFileSync(join(dir, "inbox.md"), "- done: fix this bugs\n");
164
164
  writeInbox(dir, [...readInbox(dir), { status: "open", text: "fix this bugs" }]);
165
165
  utimesSync(join(r, "00-request.md"), then, then);
166
- expect(ideas()).toEqual(["fix this bugs"]);
166
+ expect(tasks()).toEqual(["fix this bugs"]);
167
167
 
168
168
  rmSync(join(dir, ".."), { recursive: true, force: true });
169
169
  });
170
170
 
171
- test("replaceIdea edits, rejects, deletes by text", () => {
172
- replaceIdea(state, "retry failed webhooks", { status: "open", text: "retry failed webhooks twice" });
171
+ test("replaceTask edits, rejects, deletes by text", () => {
172
+ replaceTask(state, "retry failed webhooks", { status: "open", text: "retry failed webhooks twice" });
173
173
  expect(readInbox(state).some((l) => l.text === "retry failed webhooks twice")).toBe(true);
174
- replaceIdea(state, "retry failed webhooks twice", { status: "rejected", text: "retry failed webhooks twice | no" });
175
- replaceIdea(state, "nightly digest", null);
174
+ replaceTask(state, "retry failed webhooks twice", { status: "rejected", text: "retry failed webhooks twice | no" });
175
+ replaceTask(state, "nightly digest", null);
176
176
  expect(readInbox(state).map((l) => l.status)).toEqual(["open", "rejected", "rejected"]);
177
177
  });
178
178
 
@@ -201,7 +201,7 @@ test("backlog: an abandoned run's items are neither listed nor counted", () => {
201
201
  rmSync(dir, { recursive: true });
202
202
  });
203
203
 
204
- test("runToIdea: a planning run goes back to its idea, newer than the run", () => {
204
+ test("runToTask: a planning run goes back to its task, newer than the run", () => {
205
205
  const id = "2026-09-04-planning", dir = join(state, "runs", id);
206
206
  mkdirSync(dir, { recursive: true });
207
207
  writeFileSync(join(dir, "state.json"), JSON.stringify({ id, stage: "plan", awaiting: "approvals.plan" }));
@@ -209,18 +209,18 @@ test("runToIdea: a planning run goes back to its idea, newer than the run", () =
209
209
  const then = new Date(Date.now() - 30_000);
210
210
  utimesSync(join(dir, "00-request.md"), then, then);
211
211
  writeInbox(state, [...readInbox(state), { status: "started", text: "export invoices", added: Date.now() - 60_000 }, { status: "started", text: "export invoices as csv", notes: "see #12", added: Date.now() - 60_000 }]);
212
- expect(runToIdea(state, id)).toBeNull();
212
+ expect(runToTask(state, id)).toBeNull();
213
213
  expect(JSON.parse(readFileSync(join(dir, "state.json"), "utf8")).stage).toBe("abandoned");
214
214
  const cards = boardCards([state], Date.now());
215
215
  expect(cards.find((c) => c.kind === "idea" && c.text === "export invoices as csv")).toMatchObject({ status: "idea", notes: "see #12" });
216
216
  expect(cards.find((c) => c.kind === "run" && c.id === id)?.archived).toBe(true);
217
217
  expect(readInbox(state).filter((l) => l.text === "export invoices as csv").length).toBe(1);
218
218
  expect(readInbox(state).find((l) => l.text === "export invoices")?.status).toBe("started");
219
- expect(runToIdea(state, id)).toMatch(/planning/);
219
+ expect(runToTask(state, id)).toMatch(/planning/);
220
220
  writeFileSync(join(dir, "state.json"), JSON.stringify({ id, stage: "plan" }));
221
221
  rmSync(join(dir, "00-request.md"));
222
- expect(runToIdea(state, id)).toMatch(/no request/);
223
- replaceIdea(state, "export invoices", null);
222
+ expect(runToTask(state, id)).toMatch(/no request/);
223
+ replaceTask(state, "export invoices", null);
224
224
  setArchived(state, id, false);
225
225
  rmSync(dir, { recursive: true });
226
226
  });
@@ -314,10 +314,10 @@ test("archive: a run is listed, hidden by flag, never moved", () => {
314
314
  expect(boardCards([state], Date.now()).find((k) => k.id === "2026-09-02-done")!.archived).toBe(false);
315
315
  });
316
316
 
317
- test("archive: an idea keeps its line with status archived", () => {
317
+ test("archive: a task keeps its line with status archived", () => {
318
318
  writeInbox(state, [{ status: "open", text: "park this", notes: "kept" }, { status: "archived", text: "parked zq7" }]);
319
- const ideas = boardCards([state], Date.now()).filter((k) => k.kind === "idea");
320
- expect(ideas.map((k) => [k.text, k.archived])).toEqual([["park this", false], ["parked zq7", true]]);
319
+ const tasks = boardCards([state], Date.now()).filter((k) => k.kind === "idea");
320
+ expect(tasks.map((k) => [k.text, k.archived])).toEqual([["park this", false], ["parked zq7", true]]);
321
321
  });
322
322
 
323
323
  test("notes: indented lines under a bullet round-trip; a legacy file is untouched", () => {
@@ -332,11 +332,11 @@ test("notes: indented lines under a bullet round-trip; a legacy file is untouche
332
332
  });
333
333
 
334
334
  test("notes: survive reject and started; edit can replace or clear them", () => {
335
- replaceIdea(state, "with notes", { status: "started", text: "with notes" });
335
+ replaceTask(state, "with notes", { status: "started", text: "with notes" });
336
336
  expect(readInbox(state)[0]!.notes).toContain("https://x.y/z");
337
- replaceIdea(state, "with notes", { status: "rejected", text: "with notes | no" });
337
+ replaceTask(state, "with notes", { status: "rejected", text: "with notes | no" });
338
338
  expect(readInbox(state)[0]!.notes).toContain("https://x.y/z");
339
- replaceIdea(state, "plain zq8", { status: "open", text: "plain zq8", notes: "" });
339
+ replaceTask(state, "plain zq8", { status: "open", text: "plain zq8", notes: "" });
340
340
  expect(readInbox(state)[1]!.notes).toBeUndefined();
341
341
  expect(boardCards([state], Date.now()).find((k) => k.text === "plain zq8")!.notes).toBeUndefined();
342
342
  });
@@ -378,18 +378,18 @@ test("notes log: stamped entries, continuation lines, unstamped preamble", () =>
378
378
  expect(formatNote("a\nb", "2026-09-14 10:00")).toBe("[2026-09-14 10:00] a\n b");
379
379
  });
380
380
 
381
- test("notes log: append to a run and to an idea; attachments saved and made absolute in the prompt", () => {
381
+ test("notes log: append to a run and to a task; attachments saved and made absolute in the prompt", () => {
382
382
  expect(appendNote(state, { id: "2026-09-01-waiting" }, "run note")).toBeNull();
383
383
  expect(parseNotes(readNotes(state, "2026-09-01-waiting")).map((n) => n.text)).toEqual(["run note"]);
384
384
  writeInbox(state, [{ status: "open", text: "chatty zq6" }]);
385
385
  expect(appendNote(state, { text: "chatty zq6" }, "one")).toBeNull();
386
386
  expect(appendNote(state, { text: "chatty zq6" }, "two\nlines")).toBeNull();
387
- expect(appendNote(state, { text: "nope zq6" }, "x")).toBe("no such idea");
387
+ expect(appendNote(state, { text: "nope zq6" }, "x")).toBe("no such task");
388
388
  expect(parseNotes(readInbox(state)[0]!.notes!).map((n) => n.text)).toEqual(["one", "two\nlines"]);
389
389
  const rel = saveAttachment(state, null, "../evil name.png", new Uint8Array([1]));
390
390
  expect(rel).toMatch(/^attachments\/\w+-_evil_name\.png$/);
391
391
  expect(requestOf("x", `![s](${rel})`, state)).toBe(`x\n\n![s](${join(state, rel)})`);
392
- // The New idea form's path: idea first, then its files as a note; a plain file reaches the run by absolute path.
392
+ // The New task form's path: task first, then its files as a note; a plain file reaches the run by absolute path.
393
393
  const doc = saveAttachment(state, null, "spec.pdf", new Uint8Array([3]));
394
394
  expect(appendNote(state, { text: "chatty zq6" }, `[spec.pdf](${doc})`)).toBeNull();
395
395
  expect(requestOf("/kaizen chatty zq6", readInbox(state)[0]!.notes, state)).toContain(`[spec.pdf](${join(state, doc)})`);
@@ -446,9 +446,9 @@ out.missing = S.detectDefaultAgent(P, "gemini");
446
446
  out.pick = [S.detectDefaultAgent(P, "codex").cmd, S.agentFlags(P, "codex", undefined, "gpt-5.1")];
447
447
  out.choices = S.agentChoices(P);
448
448
  // No terminal on PATH or display in env: the launch fails and hands back its manual line.
449
- const idea = { severity: null, where: null, text: "x", raw: "x" };
449
+ const task = { severity: null, where: null, text: "x", raw: "x" };
450
450
  // macOS always drives Terminal.app, which would open a real window: Linux only.
451
- if (process.platform === "linux") out.yolo = [S.launchRun(idea, P, undefined, { agent: "codex", yolo: true }), S.launchRun(idea, P, undefined, { agent: "codex" }), S.launchRun(idea, P, undefined, { agent: "gemini", yolo: true })].map((r) => [r.ok, r.agent.cmd, /--dangerously-bypass|--dangerously-skip|--yolo/.test(r.manual)]);
451
+ if (process.platform === "linux") out.yolo = [S.launchRun(task, P, undefined, { agent: "codex", yolo: true }), S.launchRun(task, P, undefined, { agent: "codex" }), S.launchRun(task, P, undefined, { agent: "gemini", yolo: true })].map((r) => [r.ok, r.agent.cmd, /--dangerously-bypass|--dangerously-skip|--yolo/.test(r.manual)]);
452
452
  fs.writeFileSync(join(st, "runs", "r1", "state.json"), JSON.stringify({ agent: "codex" }));
453
453
  out.fromState = S.runAgent(st, "r1");
454
454
  S.sessionLaunch(P, "codex", ["codex"], "/kaizen x", "x", "r1", "gpt-5.1");
@@ -479,7 +479,7 @@ console.log(JSON.stringify(out));`;
479
479
  } finally { rmSync(home, { recursive: true, force: true }); rmSync(bin, { recursive: true, force: true }); }
480
480
  });
481
481
 
482
- test("boardCards: a short idea is not retired by a request that merely contains the word", () => {
482
+ test("boardCards: a short task is not retired by a request that merely contains the word", () => {
483
483
  const dir = join(mkdtempSync(join(tmpdir(), "kz-")), ".kaizen");
484
484
  mkdirSync(join(dir, "runs", "2026-09-01-a"), { recursive: true });
485
485
  writeFileSync(join(dir, "runs", "2026-09-01-a", "state.json"), JSON.stringify({ id: "2026-09-01-a", stage: "plan", awaiting: null }));
@@ -847,13 +847,13 @@ test("notifier: only a run seen before, saying something new, and not a done the
847
847
  expect(readFileSync(join(import.meta.dir, "..", "web", "board.html"), "utf8")).toContain("(/*notifier*/)()");
848
848
  });
849
849
 
850
- test("files written by Windows PowerShell, with a byte order mark, still read: the run shows, the first idea is an idea", () => {
850
+ test("files written by Windows PowerShell, with a byte order mark, still read: the run shows, the first task is a task", () => {
851
851
  const st = join(mkdtempSync(join(tmpdir(), "kaizen-bom-")), ".kaizen");
852
852
  mkdirSync(join(st, "runs", "r1"), { recursive: true });
853
853
  writeFileSync(join(st, "runs", "r1", "state.json"), "" + JSON.stringify({ id: "r1", stage: "plan", awaiting: "approvals.plan" }));
854
- writeFileSync(join(st, "inbox.md"), "- open: first idea\n");
854
+ writeFileSync(join(st, "inbox.md"), "- open: first task\n");
855
855
  expect(readRuns(st).map((r) => [r.id, r.stage])).toEqual([["r1", "plan"]]);
856
- expect(readInbox(st)).toEqual([{ status: "open", text: "first idea" }]);
856
+ expect(readInbox(st)).toEqual([{ status: "open", text: "first task" }]);
857
857
  });
858
858
 
859
859
  test("remember on Windows stores one spelling per folder, the one knownProjects returns", () => {
@@ -926,11 +926,11 @@ test("sessionLaunch: claude gets a conversation id, a decision resumes it while
926
926
  const saved = process.env.CLAUDE_CONFIG_DIR;
927
927
  process.env.CLAUDE_CONFIG_DIR = mkdtempSync(join(tmpdir(), "kz-claude-"));
928
928
  try {
929
- const idea = sessionLaunch(p, "claude", ["/bin/claude", "--model", "opus"], "/kaizen tidy logs", "tidy logs");
929
+ const task = sessionLaunch(p, "claude", ["/bin/claude", "--model", "opus"], "/kaizen tidy logs", "tidy logs");
930
930
  const [rec] = readSessions(st);
931
931
  expect(rec.sessionId).toMatch(/^[0-9a-f-]{36}$/);
932
- expect(idea.fullCmd).toEqual(["/bin/claude", "--session-id", rec.sessionId!, "--model", "opus", "/kaizen tidy logs"]);
933
- expect(idea.pidFile).toBe(join(st, "sessions", rec.key + ".pid"));
932
+ expect(task.fullCmd).toEqual(["/bin/claude", "--session-id", rec.sessionId!, "--model", "opus", "/kaizen tidy logs"]);
933
+ expect(task.pidFile).toBe(join(st, "sessions", rec.key + ".pid"));
934
934
  newRun(p, "2026-10-01-tidy-logs", "/kaizen tidy logs");
935
935
  expect(ownerOf(st, rec)).toBe("2026-10-01-tidy-logs");
936
936
 
@@ -957,7 +957,7 @@ test("sessionLaunch: claude gets a conversation id, a decision resumes it while
957
957
  expect(existsSync(join(bare, ".kaizen"))).toBe(false);
958
958
  });
959
959
 
960
- test("ownerOf: an idea's session belongs to the first run created after it, not an older one with the same words", () => {
960
+ test("ownerOf: a task's session belongs to the first run created after it, not an older one with the same words", () => {
961
961
  const p = sessionProject(), st = join(p, ".kaizen");
962
962
  newRun(p, "2026-09-01-old", "/kaizen fix the login page");
963
963
  const rec = { key: "k", run: null, text: "fix the login page", cmd: "claude", sessionId: null, started: Date.now() + 5000 };
@@ -1269,20 +1269,20 @@ test("trustFolder: marks the repo root trusted in a temp config, keeps the rest,
1269
1269
  rmSync(t, { recursive: true, force: true });
1270
1270
  });
1271
1271
 
1272
- test("moveIdea carries notes and linked attachments, leaves the old inbox without it", () => {
1272
+ test("moveTask carries notes and linked attachments, leaves the old inbox without it", () => {
1273
1273
  const root = mkdtempSync(join(tmpdir(), "kaizen-mv-"));
1274
1274
  const a = join(root, "a", ".kaizen"), b = join(root, "b", ".kaizen");
1275
1275
  mkdirSync(join(a, "attachments"), { recursive: true });
1276
1276
  writeFileSync(join(a, "attachments", "x-shot.png"), "png");
1277
1277
  writeInbox(a, [{ status: "open", text: "keep" }, { status: "open", text: "go", notes: "see [shot](attachments/x-shot.png)" }]);
1278
- expect(moveIdea(a, a, "go")).toBe("already in that project");
1279
- expect(moveIdea(a, b, "nope")).toBe("no such idea");
1280
- expect(moveIdea(a, b, "go")).toBeNull();
1278
+ expect(moveTask(a, a, "go")).toBe("already in that project");
1279
+ expect(moveTask(a, b, "nope")).toBe("no such task");
1280
+ expect(moveTask(a, b, "go")).toBeNull();
1281
1281
  expect(readInbox(a).map((l) => l.text)).toEqual(["keep"]);
1282
1282
  expect(readInbox(b)).toMatchObject([{ status: "open", text: "go", notes: "see [shot](attachments/x-shot.png)" }]);
1283
1283
  expect(readFileSync(join(b, "attachments", "x-shot.png"), "utf8")).toBe("png");
1284
1284
  writeInbox(a, [{ status: "open", text: "go" }]);
1285
- expect(moveIdea(a, b, "go")).toBe("that project already has this idea");
1285
+ expect(moveTask(a, b, "go")).toBe("that project already has this task");
1286
1286
  rmSync(root, { recursive: true, force: true });
1287
1287
  });
1288
1288
 
@@ -1350,7 +1350,7 @@ test("requestTitle: a follow-up opened from an approval question titles from its
1350
1350
  expect(requestTitle(q + "Roadmap line: 2. Accounts & access — OTP\n")).toBe("Accounts & access — OTP");
1351
1351
  });
1352
1352
 
1353
- test("parent/child: a Parent line links a run and an idea to the run that filed them", () => {
1353
+ test("parent/child: a Parent line links a run and a task to the run that filed them", () => {
1354
1354
  expect(parentOf("do x\nFollow-up of: 2026-01-01-a.")).toBe("2026-01-01-a");
1355
1355
  expect(parentOf(" [2026-10-18 20:57] Parent: 2026-01-01-a")).toBe("2026-01-01-a");
1356
1356
  expect(parentOf("no parent here")).toBeUndefined();
@@ -1360,7 +1360,7 @@ test("parent/child: a Parent line links a run and an idea to the run that filed
1360
1360
  writeFileSync(join(st, "runs", id, "00-request.md"), req + "\n");
1361
1361
  writeFileSync(join(st, "runs", id, "state.json"), JSON.stringify({ stage: "done", awaiting: null }));
1362
1362
  }
1363
- writeFileSync(join(st, "inbox.md"), "# Inbox\n\n- open: follow-on idea\n Parent: 2026-01-01-a\n");
1363
+ writeFileSync(join(st, "inbox.md"), "# Inbox\n\n- open: follow-on task\n Parent: 2026-01-01-a\n");
1364
1364
  const cards = boardCards([st], Date.now());
1365
1365
  expect(cards.find((k) => k.id === "2026-01-01-a")!.children).toEqual(["2026-01-02-b"]);
1366
1366
  expect(cards.find((k) => k.id === "2026-01-02-b")!.parent).toBe("2026-01-01-a");
@@ -1614,3 +1614,26 @@ test("a tool's Settings model reaches its launch flag, ahead of a hand-written b
1614
1614
  expect(agentFlags("/x", "codex", "agent:\n codex: { model: old, effort: low }\n model:\n codex: new\n")).toEqual(["-m", "new", "-c", "model_reasoning_effort=low"]);
1615
1615
  expect(agentFlags("/x", "codex", "agent:\n codex: { model: old }\n")).toEqual(["-m", "old"]);
1616
1616
  });
1617
+
1618
+ test("pruneSessions drops only old records nothing can use, with their files", () => {
1619
+ const st = join(mkdtempSync(join(tmpdir(), "kz-prunes-")), ".kaizen");
1620
+ const now = Date.now(), old = now - 8 * 864e5, sessions = join(st, "sessions");
1621
+ mkdirSync(sessions, { recursive: true });
1622
+ const run = (id: string, state: string) => { mkdirSync(join(st, "runs", id), { recursive: true }); writeFileSync(join(st, "runs", id, "state.json"), state); };
1623
+ run("gave-up", '{"stage":"abandoned"}'); run("finished", '{"stage":"done"}'); run("going", '{"stage":"build"}'); run("garbled", "{");
1624
+ const rec = (key: string, r: string | null, started = old) => writeFileSync(join(sessions, key + ".json"), JSON.stringify({ run: r, text: key, cmd: "claude", sessionId: null, started }));
1625
+ rec("abandoned", "gave-up"); rec("unowned", null); rec("missing", "pruned-away");
1626
+ writeFileSync(join(sessions, "abandoned.run"), "gave-up");
1627
+ rec("done", "finished"); rec("flight", "going"); rec("unreadable", "garbled"); rec("young", null, now - 6 * 864e5); rec("live", null);
1628
+ writeFileSync(join(sessions, "live.pid"), String(process.pid));
1629
+ const dead = ["abandoned", "missing", "unowned"];
1630
+ // This test process stands in for the agent: its record names bun, or the PID reads as a stranger's.
1631
+ writeFileSync(join(sessions, "live.json"), JSON.stringify({ run: null, text: "live", cmd: "bun", sessionId: null, started: old }));
1632
+
1633
+ expect(pruneSessions(st, false, now).map((g) => g.key + ":" + g.reason).sort()).toEqual(["abandoned:abandoned", "missing:gone", "unowned:unowned"]);
1634
+ expect(readdirSync(sessions)).toContain("abandoned.json");
1635
+ expect(pruneSessions(st, true, now).map((g) => g.key).sort()).toEqual(dead);
1636
+ expect(readdirSync(sessions).filter((f) => f.endsWith(".json")).sort()).toEqual(["done.json", "flight.json", "live.json", "unreadable.json", "young.json"]);
1637
+ expect(readdirSync(sessions)).not.toContain("abandoned.run");
1638
+ rmSync(dirname(st), { recursive: true, force: true });
1639
+ });