kaizen-agent 1.64.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 (62) 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/install.ts +6 -3
  7. package/cli/notes.test.ts +3 -3
  8. package/cli/notes.ts +1 -1
  9. package/cli/settings.ts +5 -5
  10. package/cli/sources.test.ts +32 -32
  11. package/cli/sources.ts +15 -15
  12. package/cli/state.test.ts +74 -51
  13. package/cli/state.ts +69 -48
  14. package/cli/web.ts +53 -33
  15. package/commands/kaizen-discover.md +1 -1
  16. package/package.json +1 -1
  17. package/skills/kaizen/README.md +2 -2
  18. package/skills/kaizen/SKILL.md +2 -2
  19. package/skills/kaizen/config.default.yml +22 -22
  20. package/skills/kaizen/discover.md +8 -8
  21. package/skills/kaizen/gather.md +2 -2
  22. package/skills/kaizen/spec-plan.md +1 -1
  23. package/skills/kaizen/spec.md +1 -1
  24. package/skills/kaizen-help/SKILL.md +2 -2
  25. package/web/board/api.ts +10 -10
  26. package/web/board/cards.ts +46 -46
  27. package/web/board/icebox.ts +14 -14
  28. package/web/board/keys.ts +3 -3
  29. package/web/board/labels.ts +2 -2
  30. package/web/board/live.ts +3 -3
  31. package/web/board/main.ts +1 -1
  32. package/web/board/markdown.ts +1 -1
  33. package/web/board/panel.ts +17 -17
  34. package/web/board/phone.ts +7 -7
  35. package/web/board/projects.ts +6 -6
  36. package/web/board/run-view.ts +5 -5
  37. package/web/board/search.ts +11 -11
  38. package/web/board/settings-cleanup.ts +42 -0
  39. package/web/board/settings-pages.ts +1 -1
  40. package/web/board/settings.ts +13 -0
  41. package/web/board/store.ts +1 -1
  42. package/web/board/{ideas.ts → tasks.ts} +22 -22
  43. package/web/board/terms.ts +3 -3
  44. package/web/board/views.ts +23 -12
  45. package/web/board/workspace.ts +7 -7
  46. package/web/board/ws-board-ui.ts +1 -1
  47. package/web/board/ws-board.test.ts +1 -1
  48. package/web/board/ws-board.ts +1 -1
  49. package/web/board/ws-tabs.test.ts +2 -2
  50. package/web/board/ws-tabs.ts +2 -2
  51. package/web/board.html +33 -33
  52. package/web/board.js +101 -101
  53. package/web/notebook.js +17 -17
  54. package/web/notebook.ts +5 -5
  55. package/web/notes-lib.ts +2 -2
  56. package/web/notes.html +11 -11
  57. package/web/term-font.test.ts +22 -0
  58. package/web/term-font.ts +30 -0
  59. package/web/term.js +38 -38
  60. package/web/term.ts +13 -2
  61. package/web/video.html +11 -11
  62. package/web/video.js +24 -24
package/cli/state.ts CHANGED
@@ -628,7 +628,7 @@ export function parseItem(raw: string): Item {
628
628
  // and a severity tag in brackets ("Finding 1 (medium) — …", "(review 2, low)",
629
629
  // "[low] …"). A severity loose in prose ("too low") is not one.
630
630
  const at = /^(.{1,160}?)\s*[:—-]\s*(critical|high|medium|low)\s*[:—-]\s*(.+)$/i.exec(raw);
631
- // Only a real place counts as one (a path, or a line number): an idea's own words
631
+ // Only a real place counts as one (a path, or a line number): a task's own words
632
632
  // before a severity stay its words.
633
633
  if (at && /\/|:\d/.test(at[1]!)) return { severity: at[2]!.toLowerCase(), where: at[1]!.replace(/`/g, "").trim().split("/").pop()!, text: tidy(at[3]!), raw };
634
634
  const num = /^\d+\.\s*(critical|high|medium|low)\s*[:—-]\s*(.+)$/i.exec(raw);
@@ -720,7 +720,7 @@ export type BacklogCard = { state: string; where: string; source: string; n: num
720
720
  const SEVERITY_RANK: Record<string, number> = { critical: 0, high: 1, medium: 2, low: 3 };
721
721
 
722
722
  // The open backlog items of every non-abandoned run and the orphanage, as cards for the
723
- // board's Ideas column: most severe first, then newest run first, then file order. An
723
+ // board's Tasks column: most severe first, then newest run first, then file order. An
724
724
  // item a live run was started from is not shown; an abandoned one gives it back.
725
725
  export function backlogCards(states: string[]): BacklogCard[] {
726
726
  const out: BacklogCard[] = [];
@@ -795,8 +795,8 @@ export type Card = {
795
795
  awaiting: string | null;
796
796
  dim: boolean;
797
797
  moved?: number; // runs only: state.json mtime
798
- added?: number; // ideas only: when the inbox line first appeared (ms)
799
- inboxIndex?: number; // ideas only: line in the project's inbox
798
+ added?: number; // tasks only: when the inbox line first appeared (ms)
799
+ inboxIndex?: number; // tasks only: line in the project's inbox
800
800
  title?: string; // runs only: first line of the request
801
801
  archived: boolean; // hidden from the board unless asked for
802
802
  branch?: string; // runs only: the run's own branch while it has a worktree
@@ -810,7 +810,7 @@ export type Card = {
810
810
  };
811
811
 
812
812
  // A `Parent: <run id>` line (or the older `Follow-up of: <run id>`) in a request or
813
- // an idea's notes is what links a card to the run it came from.
813
+ // a task's notes is what links a card to the run it came from.
814
814
  export function parentOf(text?: string) {
815
815
  return /^\s*(?:\[[^\]]*\]\s*)?(?:Parent|Follow-up of):\s*(\S+)/im.exec(text ?? "")?.[1]?.replace(/[.,]$/, "");
816
816
  }
@@ -819,7 +819,7 @@ export function parentOf(text?: string) {
819
819
  // to ask. Anything in flight and older than this is stalled, not running -- the
820
820
  // difference the board exists to show.
821
821
 
822
- // The verbatim request of every run, normalised, so an idea that has become a run
822
+ // The verbatim request of every run, normalised, so a task that has become a run
823
823
  // can be retired from the board.
824
824
  // ponytail: reads each run's 00-request.md on every refresh; fine at tens of runs,
825
825
  // cache by mtime if a project ever has hundreds.
@@ -869,7 +869,7 @@ export function columnOf(stage: string, awaiting: string | null = null) {
869
869
  // `added` is when the line first appeared (ms), kept as a hidden comment on its bullet.
870
870
  export type InboxLine = { status: string; text: string; notes?: string; added?: number };
871
871
 
872
- // Ideas with no run yet. Deliberately not backlog.md, which the spec defines as
872
+ // Tasks with no run yet. Deliberately not backlog.md, which the spec defines as
873
873
  // an orphanage for items rescued from pruned runs, and not a run stub each.
874
874
  export function readInbox(state: string): InboxLine[] {
875
875
  const f = join(state, "inbox.md");
@@ -882,7 +882,7 @@ export function readInbox(state: string): InboxLine[] {
882
882
  out.push(a ? { status: m[1]!, text: m[2]!.slice(0, a.index).trim(), added: +a[1]! } : { status: m[1]!, text: m[2]!.trim() });
883
883
  continue;
884
884
  }
885
- // A bullet typed by hand, without a status, is an open idea.
885
+ // A bullet typed by hand, without a status, is an open task.
886
886
  const b = /^[-*]\s+(?:\[ \]\s+)?(.+)$/.exec(raw);
887
887
  if (b) {
888
888
  out.push({ status: "open", text: b[1]!.trim() });
@@ -903,7 +903,7 @@ export function writeInbox(state: string, lines: InboxLine[]) {
903
903
  // A line already in the file keeps its stamp; a text the file never had is new now.
904
904
  // Lines from before stamps existed stay unstamped rather than looking new.
905
905
  // Stamps queue per text and each is used once: re-adding words the file already
906
- // holds (a done or rejected line, or an open duplicate) is a new idea, not the old
906
+ // holds (a done or rejected line, or an open duplicate) is a new task, not the old
907
907
  // one's stamp, which an older run with those words would retire.
908
908
  const had = new Map<string, (number | undefined)[]>();
909
909
  for (const l of readInbox(state)) had.set(l.text, [...(had.get(l.text) ?? []), l.added]);
@@ -934,7 +934,7 @@ export function requestOf(text: string, notes?: string, state?: string) {
934
934
  return n ? `${text}\n\n${n}` : text;
935
935
  }
936
936
 
937
- // Free text beside a run -- what the user learned after the idea became a run.
937
+ // Free text beside a run -- what the user learned after the task became a run.
938
938
  // Its own file, never state.json: that shape is the resume contract.
939
939
  export function readNotes(state: string, id: string) {
940
940
  try { return readText(join(state, "runs", id, "notes.md")); } catch { return ""; }
@@ -973,7 +973,7 @@ export function formatNote(text: string, at = stamp()) {
973
973
  return `[${at}] ${text.trim().replace(/\n/g, "\n ")}`;
974
974
  }
975
975
 
976
- // Append one entry: to runs/<id>/notes.md for a run, or under the idea's inbox
976
+ // Append one entry: to runs/<id>/notes.md for a run, or under the task's inbox
977
977
  // bullet. Attachments arrive as markdown links already written into text.
978
978
  export function appendNote(state: string, target: { id: string } | { text: string; index?: number }, text: string): string | null {
979
979
  if (!text.trim()) return "empty note";
@@ -984,16 +984,16 @@ export function appendNote(state: string, target: { id: string } | { text: strin
984
984
  }
985
985
  const lines = readInbox(state);
986
986
  const at = target.index === undefined ? lines.findIndex((l) => l.status === "open" && l.text === target.text) : target.index;
987
- if (lines[at]?.status !== "open" || lines[at]?.text !== target.text) return "no such idea";
987
+ if (lines[at]?.status !== "open" || lines[at]?.text !== target.text) return "no such task";
988
988
  const prev = lines[at]!.notes;
989
989
  lines[at] = { ...lines[at]!, notes: (prev ? prev + "\n" : "") + formatNote(text) };
990
990
  writeInbox(state, lines);
991
991
  return null;
992
992
  }
993
993
 
994
- // A card filed by a run: an open idea whose note names the run as its parent. The
994
+ // A card filed by a run: an open task whose note names the run as its parent. The
995
995
  // parent is the one named, else the newest run still in flight. `details` go in the
996
- // idea's notes below the Parent line, so the title stays a title.
996
+ // task's notes below the Parent line, so the title stays a title.
997
997
  export function addCard(state: string, text: string, parent?: string, details?: string): { parent: string } | string {
998
998
  text = text.trim().replace(/\s+/g, " ");
999
999
  if (!text) return "empty card";
@@ -1007,7 +1007,7 @@ export function addCard(state: string, text: string, parent?: string, details?:
1007
1007
  }
1008
1008
 
1009
1009
  // A file beside the notes it belongs to: runs/<id>/attachments/ for a run,
1010
- // <state>/attachments/ for an idea. Returns the path relative to the state dir,
1010
+ // <state>/attachments/ for a task. Returns the path relative to the state dir,
1011
1011
  // which is what the note links and what /file serves.
1012
1012
  // ponytail: no dedupe, no size accounting beyond the request cap in web.ts.
1013
1013
  export function saveAttachment(state: string, id: string | null, name: string, bytes: Uint8Array) {
@@ -1106,33 +1106,33 @@ export function abandonRun(st: string, id: string, why: string): string | null {
1106
1106
  }
1107
1107
  }
1108
1108
 
1109
- // A run still planning, back to the idea it came from: abandoned and archived (the
1110
- // record stays), and the idea open again. Its fresh stamp is newer than the run's
1109
+ // A run still planning, back to the task it came from: abandoned and archived (the
1110
+ // record stays), and the task open again. Its fresh stamp is newer than the run's
1111
1111
  // request, so the old run no longer retires it.
1112
- export function runToIdea(st: string, id: string): string | null {
1112
+ export function runToTask(st: string, id: string): string | null {
1113
1113
  let stage = "";
1114
1114
  try { stage = JSON.parse(readText(join(st, "runs", id, "state.json"))).stage; } catch {}
1115
- if (stage !== "plan") return "Only a run still in planning goes back to an idea.";
1115
+ if (stage !== "plan") return "Only a run still in planning goes back to a task.";
1116
1116
  let req = "";
1117
1117
  try { req = readText(join(st, "runs", id, "00-request.md")).trim(); } catch {}
1118
1118
  const lines = readInbox(st);
1119
- // The longest started idea the request holds: "test" must not stand in for "test login".
1119
+ // The longest started task the request holds: "test" must not stand in for "test login".
1120
1120
  let at = -1;
1121
1121
  lines.forEach((l, i) => { if (l.status === "started" && normalise(req).includes(normalise(l.text)) && (at < 0 || l.text.length > lines[at]!.text.length)) at = i; });
1122
1122
  const [first = "", ...rest] = req.split("\n");
1123
- const idea: InboxLine = at >= 0
1123
+ const task: InboxLine = at >= 0
1124
1124
  ? { ...lines[at]!, status: "open", added: Date.now() }
1125
1125
  : { status: "open", text: first.replace(/^\/kaizen(?:-\w+)?\s+(?:(?:lite|full|auto|plan)\s+)?/i, "").trim(), notes: rest.join("\n").trim() || undefined, added: Date.now() };
1126
- if (!idea.text) return "That run has no request to make an idea of.";
1127
- const failed = abandonRun(st, id, "Sent back to ideas from the board.");
1126
+ if (!task.text) return "That run has no request to make a task of.";
1127
+ const failed = abandonRun(st, id, "Sent back to tasks from the board.");
1128
1128
  if (failed) return failed;
1129
1129
  setArchived(st, id, true);
1130
1130
  if (at >= 0) lines.splice(at, 1);
1131
- writeInbox(st, [...lines, idea]);
1131
+ writeInbox(st, [...lines, task]);
1132
1132
  return null;
1133
1133
  }
1134
1134
 
1135
- export function replaceIdea(state: string, text: string, next: InboxLine | null, index?: number) {
1135
+ export function replaceTask(state: string, text: string, next: InboxLine | null, index?: number) {
1136
1136
  const lines = readInbox(state);
1137
1137
  const at = index === undefined ? lines.findIndex((l) => (l.status === "open" || l.status === "started") && l.text === text) : index;
1138
1138
  if (!lines[at] || !["open", "started"].includes(lines[at]!.status) || lines[at]!.text !== text) return false;
@@ -1141,24 +1141,24 @@ export function replaceIdea(state: string, text: string, next: InboxLine | null,
1141
1141
  return true;
1142
1142
  }
1143
1143
 
1144
- // An open idea, notes and all, from one project's inbox to another's. Files its notes
1144
+ // An open task, notes and all, from one project's inbox to another's. Files its notes
1145
1145
  // link (attachments/...) are copied along, so the links resolve from the new state dir.
1146
1146
  // Written to the new project first and taken back out if the old one cannot be
1147
1147
  // written, like moveSource: a crash between the two leaves it listed twice, never lost.
1148
- export function moveIdea(from: string, to: string, text: string): string | null {
1148
+ export function moveTask(from: string, to: string, text: string): string | null {
1149
1149
  if (from === to) return "already in that project";
1150
1150
  const src = readInbox(from);
1151
1151
  const at = src.findIndex((l) => l.status === "open" && l.text === text);
1152
- if (at < 0) return "no such idea";
1152
+ if (at < 0) return "no such task";
1153
1153
  const dest = readInbox(to);
1154
- if (dest.some((l) => l.status === "open" && l.text === text)) return "that project already has this idea";
1155
- const idea = src[at]!;
1156
- for (const m of (idea.notes ?? "").matchAll(/\]\((attachments\/[^)\/]+)\)/g)) {
1154
+ if (dest.some((l) => l.status === "open" && l.text === text)) return "that project already has this task";
1155
+ const task = src[at]!;
1156
+ for (const m of (task.notes ?? "").matchAll(/\]\((attachments\/[^)\/]+)\)/g)) {
1157
1157
  if (!existsSync(join(from, m[1]!)) || !statSync(join(from, m[1]!)).isFile()) continue;
1158
1158
  mkdirSync(join(to, "attachments"), { recursive: true });
1159
1159
  copyFileSync(join(from, m[1]!), join(to, m[1]!));
1160
1160
  }
1161
- writeInbox(to, [...dest, idea]);
1161
+ writeInbox(to, [...dest, task]);
1162
1162
  try { writeInbox(from, src.filter((_, i) => i !== at)); }
1163
1163
  catch (e) { writeInbox(to, dest); throw e; }
1164
1164
  return null;
@@ -1207,8 +1207,8 @@ export function requestTitle(text: string) {
1207
1207
  return first.length > 90 ? first.slice(0, 89).trimEnd() + "…" : first;
1208
1208
  }
1209
1209
 
1210
- // Every card on the board, for the state dirs asked for. Retirement of an idea is
1211
- // checked against every known project's runs, not just these: an idea in the global
1210
+ // Every card on the board, for the state dirs asked for. Retirement of a task is
1211
+ // checked against every known project's runs, not just these: a task in the global
1212
1212
  // inbox becomes a run in whichever project the agent was started in.
1213
1213
  // The gate reads a done run's reports on every refresh: kept per run until one of the
1214
1214
  // files it reads changes (stat only), so a project of many done runs costs no reads.
@@ -1240,14 +1240,14 @@ export function boardCards(states: string[], now: number): Card[] {
1240
1240
  if (!bodies.has(f)) { try { bodies.set(f, readText(f)); } catch { bodies.set(f, ""); } }
1241
1241
  return bodies.get(f)!;
1242
1242
  };
1243
- // Each request with when it was written, so a run older than an idea cannot retire it.
1243
+ // Each request with when it was written, so a run older than a task cannot retire it.
1244
1244
  const requests: { at: number; text: string }[] = [];
1245
- // Each request line on its own, quote and list markers stripped: what an idea
1245
+ // Each request line on its own, quote and list markers stripped: what a task
1246
1246
  // nobody launched from the board is matched against.
1247
1247
  const lines: { at: number; text: string }[] = [];
1248
1248
  for (const st of [...states, ...knownProjects().map((d) => join(d, ".kaizen")), join(home, ".kaizen")]
1249
1249
  .filter((d, i, all) => all.indexOf(d) === i && existsSync(join(d, "runs")))) {
1250
- // A run with no state.json yet has no card either: retiring the idea against it
1250
+ // A run with no state.json yet has no card either: retiring the task against it
1251
1251
  // leaves the board showing neither until the agent writes one.
1252
1252
  for (const id of readdirSync(join(st, "runs"))) { const b = body(st, id); if (!b || !existsSync(join(st, "runs", id, "state.json"))) continue;
1253
1253
  let at = 0;
@@ -1256,7 +1256,7 @@ export function boardCards(states: string[], now: number): Card[] {
1256
1256
  for (const l of b.split("\n")) lines.push({ at, text: normalise(l.replace(/^[\s>*"'`-]+|[\s"'`.]+$/g, "")) });
1257
1257
  }
1258
1258
  }
1259
- // A launched idea whose run reworded the request: the board's own launch record,
1259
+ // A launched task whose run reworded the request: the board's own launch record,
1260
1260
  // owned by a run (session id in its state.json, see ownerOf), retires it all the same.
1261
1261
  const indexes = new Map<string, RunIndex>(), indexOf = (st: string) => indexes.get(st) ?? indexes.set(st, runIndex(st)).get(st)!;
1262
1262
  const launchedInto = (st: string, t: string) => readSessions(st).some((s) => !s.run && normalise(s.text.replace(/^(lite|full|auto|plan)\s+/i, "")) === t.replace(/^(lite|full|auto|plan)\s+/i, "") && ownerOf(st, s, indexOf(st)) !== null);
@@ -1266,16 +1266,16 @@ export function boardCards(states: string[], now: number): Card[] {
1266
1266
  for (const [inboxIndex, it] of readInbox(st).entries()) {
1267
1267
  if (it.status !== "open" && it.status !== "started" && it.status !== "archived") continue;
1268
1268
  // Retired once any run's request contains this text -- whoever started it.
1269
- // Checking `started` items only would leave every idea acted on outside the
1269
+ // Checking `started` items only would leave every task acted on outside the
1270
1270
  // board sitting in IDEA forever, and typing `/kaizen ...` in a terminal is
1271
1271
  // the common way a run begins.
1272
- // An idea that was launched only has to appear somewhere in a request. One
1272
+ // A task that was launched only has to appear somewhere in a request. One
1273
1273
  // that was not must be what a request line says (after any `/kaizen lite`
1274
- // prefix): a short idea like "test" is a substring of half the requests
1274
+ // prefix): a short task like "test" is a substring of half the requests
1275
1275
  // ever written, and would vanish the moment it was added.
1276
1276
  const t = normalise(it.text);
1277
- // A run written before the idea existed is not this idea's run: an old request
1278
- // titled "fix this bugs" must not swallow a new idea with the same words.
1277
+ // A run written before the task existed is not this task's run: an old request
1278
+ // titled "fix this bugs" must not swallow a new task with the same words.
1279
1279
  // ponytail: 2s slack for coarse filesystem clocks.
1280
1280
  const after = (r: { at: number }) => !it.added || r.at >= it.added - 2000;
1281
1281
  if (it.status === "started" ? requests.some((r) => after(r) && r.text.includes(t)) || launchedInto(st, t) : lines.some((l) => after(l) && (l.text === t || l.text.endsWith(" " + t)))) continue;
@@ -1497,9 +1497,9 @@ export function runIndex(st: string): RunIndex {
1497
1497
  return { bySession, requests };
1498
1498
  }
1499
1499
 
1500
- // Whose session a record is. A decision's launch names its run. An idea's launch came
1500
+ // Whose session a record is. A decision's launch names its run. A task's launch came
1501
1501
  // before its run existed, so it belongs to the first run created after it whose
1502
- // request holds the idea's text: one run per record, never every run that mentions it.
1502
+ // request holds the task's text: one run per record, never every run that mentions it.
1503
1503
  // A caller asking about many sessions passes runIndex(st) once: built per call, it
1504
1504
  // reads every run's state.json and request each time.
1505
1505
  export function ownerOf(st: string, s: Session, idx?: RunIndex): string | null {
@@ -1637,6 +1637,27 @@ const openSessions = (st: string) => readSessions(st).filter((s) => {
1637
1637
  return true;
1638
1638
  });
1639
1639
 
1640
+ // Launch records nothing can use again, oldest first; with `apply`, deleted with their
1641
+ // PID and link files. Past a week and with no live agent, a record goes when no run
1642
+ // owns it, its run is abandoned, or its run no longer exists. A done run's records stay:
1643
+ // a follow-up resumes its conversation from them. An unreadable state.json keeps them too.
1644
+ const SESSION_KEEP_MS = 7 * 24 * 3600_000;
1645
+ export function pruneSessions(state: string, apply = false, now = Date.now()): { key: string; reason: "abandoned" | "unowned" | "gone" }[] {
1646
+ const idx = runIndex(state), live = new Set(openSessions(state).map((s) => s.key));
1647
+ const why = (run: string | null) => {
1648
+ if (!run) return "unowned" as const;
1649
+ const dir = join(state, "runs", run);
1650
+ if (!existsSync(dir)) return "gone" as const;
1651
+ try { return JSON.parse(readText(join(dir, "state.json"))).stage === "abandoned" ? "abandoned" as const : null; } catch { return null; }
1652
+ };
1653
+ const gone = readSessions(state).filter((s) => now - s.started > SESSION_KEEP_MS && !live.has(s.key)).flatMap((s) => {
1654
+ const reason = why(ownerOf(state, s, idx));
1655
+ return reason ? [{ key: s.key, reason }] : [];
1656
+ });
1657
+ if (apply) for (const { key } of gone) for (const ext of [".json", ".pid", ".run"]) rmSync(join(sessionsDir(state), key + ext), { force: true });
1658
+ return gone;
1659
+ }
1660
+
1640
1661
  // Close every session kaizen opened for a run, those launched before `before` only,
1641
1662
  // so a decision's own successor is never caught. The record stays: it holds the
1642
1663
  // conversation id the next decision resumes. Never throws.
@@ -1745,7 +1766,7 @@ export function trustFolder(dir: string, cfg = join(process.env.CLAUDE_CONFIG_DI
1745
1766
  } catch { /* Claude asks as before */ }
1746
1767
  }
1747
1768
 
1748
- // run: the run a decision is for. Without it, an idea starting a new run.
1769
+ // run: the run a decision is for. Without it, a task starting a new run.
1749
1770
  // pick: the tool, model and yolo chosen for a new run; a decision takes the run's own
1750
1771
  // tool and model, and stays in Yolo when the run was started in it. card: run it inside the board (agent.launch: card),
1751
1772
  // where a pseudo-terminal exists; onChange is told when that agent ends.
@@ -1756,7 +1777,7 @@ export const CHILD_ENV = /^(CLAUDECODE|CLAUDE_PID|CLAUDE_CODE_(SESSION_ID|CHILD_
1756
1777
  // written only where that folder has a .kaizen (a project place does; the library usually not).
1757
1778
  export function launchRun(it: Item, from: string, run?: string, pick: { agent?: string; account?: string; model?: string; yolo?: boolean; card?: boolean; onChange?: () => void; skill?: "kaizen-video"; cwd?: string; seed?: string } = {}): Launch {
1758
1779
  const projectDir = pick.cwd ?? projectOf(from);
1759
- // The run will be born here; the board must know the dir or the idea never retires.
1780
+ // The run will be born here; the board must know the dir or the task never retires.
1760
1781
  if (!pick.cwd) remember(projectDir);
1761
1782
  const own = run && !pick.agent ? runAgent(join(projectDir, ".kaizen"), run) : null;
1762
1783
  const agent = detectDefaultAgent(projectDir, pick.agent ?? own?.cmd);
@@ -1787,7 +1808,7 @@ export function launchRun(it: Item, from: string, run?: string, pick: { agent?:
1787
1808
  // Settings' bypass takes the same road, so the session record and the card's mark follow.
1788
1809
  const yolo = (wasYolo || (!!pick.yolo && agent.cmd === pick.agent) || prefersBypass(agent.cmd, prefs)) && !!YOLO_FLAGS[agent.cmd];
1789
1810
  const flags = [...agentFlags(projectDir, agent.cmd, undefined, model), ...(yolo ? YOLO_FLAGS[agent.cmd] : []), ...argsOf(agent.cmd, prefs)];
1790
- // The idea as its run's request will hold it: without the runner word in front.
1811
+ // The task as its run's request will hold it: without the runner word in front.
1791
1812
  // Session lookups read the tool's folder from the environment; for this launch it's the account's.
1792
1813
  const prior = acct.envVar ? process.env[acct.envVar] : undefined;
1793
1814
  if (acct.envVar) process.env[acct.envVar] = acct.dir;
package/cli/web.ts CHANGED
@@ -6,10 +6,10 @@ import { existsSync, readdirSync, statSync, lstatSync, realpathSync, readFileSyn
6
6
  import { join, dirname, resolve, sep, basename } from "node:path";
7
7
  import {
8
8
  home, type Item, type Card, knownProjects, remember, canonPath, locate, label, tilde, searchRoots, findProjects,
9
- readInbox, writeInbox, replaceIdea, moveIdea, abandonRun, runToIdea, launchRun, parseItem, agentChoices, onPath, projectOf, KNOWN_AGENTS, plainModel, short, setArchived, writeNotes,
9
+ readInbox, writeInbox, replaceTask, moveTask, abandonRun, runToTask, launchRun, parseItem, agentChoices, onPath, projectOf, KNOWN_AGENTS, plainModel, short, setArchived, writeNotes,
10
10
  appendNote, saveAttachment, pidOnPort, readText, cmdExe, sysExe, powershellExe, runGit, readCommit, commitPush, commitStaged, stageFiles, suggestMessage, notice, notifier, LOGO,
11
11
  reviewFindings, pickFindings, backlogItem, startedBacklog, closeBacklog, markBacklogDone, fixPrompt, approvalPrompt, canApproveAwaiting, gateOf, recordAcceptance, healRuns, finishRun, nativePath, closeSessions, sweepSessions, issueUrl,
12
- launchMode, readSessions, ownerOf, runIndex, resumePrompt, runAgent, firstSession, webHosts,
12
+ launchMode, pruneRuns, pruneSessions, readSessions, ownerOf, runIndex, resumePrompt, runAgent, firstSession, webHosts,
13
13
  } from "./state.ts";
14
14
  import { ACCOUNT_VAR, accountDir, addAccount, readAccounts, renameAccount, signedIn, removeAccount, resolveAccount, setDefaultAccount } from "./accounts.ts";
15
15
  import { readReport, signalOf } from "./report.ts";
@@ -344,7 +344,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
344
344
 
345
345
  // Runs whose in-card agent was live when the board stopped (Settings' Update, Ctrl-C,
346
346
  // systemd) or died: the agents end with the old board, so the new one starts them
347
- // again (resumeRun). Each entry keeps its session key, so an idea whose run had not
347
+ // again (resumeRun). Each entry keeps its session key, so a task whose run had not
348
348
  // written state.json yet is matched to its run by the new board, once that run exists.
349
349
  // On a stop the agents are ended here, not left to the board's exit, so none outlives
350
350
  // it beside its resumed self; a tmux-kept one is only detached and is attached again.
@@ -369,7 +369,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
369
369
  return;
370
370
  }
371
371
  // Which project and run each session belongs to, found once: a run owns its session
372
- // for good, so only new sessions and ideas' ones send the walk through every project.
372
+ // for good, so only new sessions and tasks' ones send the walk through every project.
373
373
  // A key no project records (a Terminal page shell) is looked for once.
374
374
  for (const m of [owners, written, autoResumed]) for (const k of m.keys()) if (!live.has(k)) m.delete(k);
375
375
  for (const k of unrecorded) if (!live.has(k)) unrecorded.delete(k);
@@ -400,10 +400,10 @@ export async function web(repoDir: string, opts: Opts = {}) {
400
400
  };
401
401
  // ponytail: a 3s tick, so a crash loses up to 3s of screen; hook push() if that matters.
402
402
  const keepList = setInterval(() => saveLive(true), 3000);
403
- // An idea's session, until its run exists and owns it (ownerOf).
404
- const ideaPty = new Map<string, string>();
403
+ // A task's session, until its run exists and owns it (ownerOf).
404
+ const taskPty = new Map<string, string>();
405
405
  // Backlog items this board launched whose run has not written its state.json yet:
406
- // shown as starting, like a started idea. Forgotten on restart; the card then offers Run again.
406
+ // shown as starting, like a started task. Forgotten on restart; the card then offers Run again.
407
407
  const backlogLaunched = new Set<string>();
408
408
  // The card's newest in-card session, live or recently ended. Sessions are only read
409
409
  // while this board has any, so /state costs nothing more for terminal launches.
@@ -416,20 +416,20 @@ export async function web(repoDir: string, opts: Opts = {}) {
416
416
  const cmdOf = new Map<string, string>();
417
417
  for (const d of new Set(cards.map((c) => c.state))) for (const s of readSessions(d)) if (live.has(s.key) && s.cmd) cmdOf.set(s.key, s.cmd);
418
418
  const runs = new Map<string, string[]>();
419
- const planKeys = new Set(ideaPty.values());
419
+ const planKeys = new Set(taskPty.values());
420
420
  for (const d of new Set(cards.filter((c) => c.kind === "run").map((c) => c.state))) {
421
421
  const ids = runIndex(d);
422
422
  for (const s of readSessions(d))
423
423
  if (live.has(s.key)) {
424
424
  const owner = ownerOf(d, s, ids);
425
425
  const k = `${d}\0${owner}`;
426
- // The idea's agent that began this run is its plan terminal: recorded once the run exists.
426
+ // The task's agent that began this run is its plan terminal: recorded once the run exists.
427
427
  if (owner && planKeys.has(s.key) && !stagesOf(d, owner).plan) markStage(d, owner, "plan", s.key);
428
428
  runs.set(k, [...(runs.get(k) ?? []), s.key]); // oldest first: the newest is the card's
429
429
  }
430
430
  }
431
431
  return Object.assign((c: Card) => {
432
- const keys = c.kind === "run" ? runs.get(`${c.state}\0${c.id}`) ?? [] : [ideaPty.get(`${c.state}\0${c.text}`)].filter((k): k is string => !!k && live.has(k));
432
+ const keys = c.kind === "run" ? runs.get(`${c.state}\0${c.id}`) ?? [] : [taskPty.get(`${c.state}\0${c.text}`)].filter((k): k is string => !!k && live.has(k));
433
433
  const key = keys.at(-1);
434
434
  if (!key) return undefined;
435
435
  const st = ptyState(key)!;
@@ -1150,7 +1150,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
1150
1150
  } catch { return bad("file not found", 404); }
1151
1151
  }
1152
1152
 
1153
- // What a note can link to on this project's board: runs, findings, backlog, ideas.
1153
+ // What a note can link to on this project's board: runs, findings, backlog, tasks.
1154
1154
  if (req.method === "GET" && path === "/links") {
1155
1155
  const dir = qdir() ?? state ?? join(home, ".kaizen");
1156
1156
  if (!states(true).includes(dir)) return bad("unknown state dir", 404);
@@ -1364,6 +1364,26 @@ export async function web(repoDir: string, opts: Opts = {}) {
1364
1364
  return json({ accounts: rows, windows: process.platform === "win32", ...(added ? { added } : {}) });
1365
1365
  }
1366
1366
 
1367
+ // Settings → General → Cleanup: what `kaizen prune` would remove from this page's project,
1368
+ // one kind at a time. Deletion is decided here, on the current files, not on the page's counts.
1369
+ if (path === "/cleanup" && (req.method === "GET" || req.method === "POST")) {
1370
+ if (!state) return bad("no project", 404);
1371
+ const { listSettings } = await import("./settings.ts");
1372
+ const keep = Number(listSettings(repoDir, dirname(state)).rows.find((r) => r.key === "state.keep_runs")?.value) || 20;
1373
+ if (req.method === "POST") {
1374
+ if (!local(req)) return bad("cross-origin write refused", 403);
1375
+ let body: any;
1376
+ try { body = await req.json(); } catch { return bad("json body expected"); }
1377
+ if (body.what === "records") return json({ removed: pruneSessions(state, true).length });
1378
+ if (body.what === "runs") return json({ removed: pruneRuns(state, keep, true).length });
1379
+ return bad("unknown cleanup");
1380
+ }
1381
+ const records = { abandoned: 0, unowned: 0, gone: 0 };
1382
+ for (const r of pruneSessions(state)) records[r.reason]++;
1383
+ const runs = pruneRuns(state, keep);
1384
+ return json({ project, keep, records, runs: runs.length, rescued: runs.reduce((n, r) => n + r.rescued, 0) });
1385
+ }
1386
+
1367
1387
  if (path === "/automations" && (req.method === "GET" || req.method === "POST")) {
1368
1388
  if (!state || state === join(home, ".kaizen")) return json({ error: "Open a project first." }, 404);
1369
1389
  let rules: auto.Rule[];
@@ -1680,7 +1700,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
1680
1700
  return "error" in r ? { error: r.error } : { dir: (r as { dir: string }).dir };
1681
1701
  },
1682
1702
  agents: KNOWN_AGENTS.filter((a) => agentUsable(a.cmd)).map((a) => a.cmd),
1683
- // As POST /run starts an idea, without one on the inbox.
1703
+ // As POST /run starts a task, without one on the inbox.
1684
1704
  run: async (d: string, runner: "lite" | "full", agent: string, text: string) => {
1685
1705
  const r = launchRun(parseItem(`${runner} ${text}`), d, undefined, { agent, ...inCard(d) });
1686
1706
  changed();
@@ -1801,7 +1821,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
1801
1821
  return json({ ok: true, added: knownProjects().length - before });
1802
1822
  }
1803
1823
 
1804
- // No project here means the global inbox, which is where the TUI puts ideas too.
1824
+ // No project here means the global inbox, which is where the TUI puts tasks too.
1805
1825
  let dir: string = body.dir ?? state ?? join(home, ".kaizen");
1806
1826
  // Choosing a folder from the projects folder is what sets it up: an empty
1807
1827
  // .kaizen, which the first run fills in. Only folders the board offered.
@@ -1832,32 +1852,32 @@ export async function web(repoDir: string, opts: Opts = {}) {
1832
1852
 
1833
1853
  if (path === "/inbox") {
1834
1854
  const text = String(body.text ?? "").trim();
1835
- // Absent means untouched; an empty string clears. replaceIdea keeps the
1855
+ // Absent means untouched; an empty string clears. replaceTask keeps the
1836
1856
  // old notes for any op that does not send them.
1837
1857
  const notes = typeof body.notes === "string" ? body.notes.trim() : undefined;
1838
1858
  if (body.op === "add") {
1839
- if (!text) return bad("empty idea");
1859
+ if (!text) return bad("empty task");
1840
1860
  writeInbox(dir, [...readInbox(dir), { status: "open", text, notes }]);
1841
1861
  } else if (body.op === "edit") {
1842
1862
  const next = String(body.next ?? "").trim();
1843
- if (!text || !next) return bad("empty idea");
1844
- replaceIdea(dir, text, notes === undefined ? { status: "open", text: next } : { status: "open", text: next, notes });
1863
+ if (!text || !next) return bad("empty task");
1864
+ replaceTask(dir, text, notes === undefined ? { status: "open", text: next } : { status: "open", text: next, notes });
1845
1865
  } else if (body.op === "reject") {
1846
1866
  const why = String(body.reason ?? "").trim();
1847
1867
  if (!why) return bad("a rejection needs a reason");
1848
- replaceIdea(dir, text, { status: "rejected", text: `${text} | ${why}` });
1868
+ replaceTask(dir, text, { status: "rejected", text: `${text} | ${why}` });
1849
1869
  } else if (body.op === "delete") {
1850
- replaceIdea(dir, text, null);
1870
+ replaceTask(dir, text, null);
1851
1871
  } else if (body.op === "move") {
1852
1872
  if (typeof body.to !== "string" || !states(true).includes(body.to)) return bad("unknown state dir", 404);
1853
- const why = moveIdea(dir, body.to, text);
1854
- if (why) return bad(why, why === "no such idea" ? 404 : 409);
1873
+ const why = moveTask(dir, body.to, text);
1874
+ if (why) return bad(why, why === "no such task" ? 404 : 409);
1855
1875
  } else return bad("unknown op");
1856
1876
  changed();
1857
1877
  return json({ ok: true });
1858
1878
  }
1859
1879
 
1860
- // Request sources. Gathering fills the icebox and nothing else: no idea is
1880
+ // Request sources. Gathering fills the icebox and nothing else: no task is
1861
1881
  // made and no run starts here.
1862
1882
  if (path === "/sources") {
1863
1883
  // A social source arrives as a platform and what to follow; the link is built here.
@@ -1925,8 +1945,8 @@ export async function web(repoDir: string, opts: Opts = {}) {
1925
1945
  return (/\.(png|jpe?g|gif|webp|svg)$/i.test(rel) ? "!" : "") + `[${String(f.name ?? "file")}](${rel})`;
1926
1946
  });
1927
1947
  };
1928
- // The icebox: the only way gathered text becomes an idea, one explicit click
1929
- // (or agent call) at a time. An idea is made; no run starts.
1948
+ // The icebox: the only way gathered text becomes a task, one explicit click
1949
+ // (or agent call) at a time. A task is made; no run starts.
1930
1950
  if (path === "/icebox") {
1931
1951
  if (typeof body.dir !== "string" || !states(true).includes(body.dir)) return bad("say which project's icebox this is");
1932
1952
  const ids = Array.isArray(body.ids) ? body.ids.filter((i: unknown) => typeof i === "string") : [];
@@ -1974,12 +1994,12 @@ export async function web(repoDir: string, opts: Opts = {}) {
1974
1994
  if (path === "/run") {
1975
1995
  const text = String(body.text ?? "").trim();
1976
1996
  const kind = body.kind === "full" || body.kind === "lite" ? body.kind : "";
1977
- if (!text && !body.backlog) return bad("empty idea");
1997
+ if (!text && !body.backlog) return bad("empty task");
1978
1998
  const agent = typeof body.agent === "string" && body.agent ? body.agent : undefined;
1979
1999
  if (agent && !KNOWN_AGENTS.some((a) => a.cmd === agent)) return bad("unknown agent");
1980
2000
  const model = typeof body.model === "string" ? body.model.trim() : "";
1981
2001
  if (model && !plainModel(model)) return bad("A model name is letters, digits and . : / @ _ - only");
1982
- // A backlog item runs as an idea would, its text read here from the file, never
2002
+ // A backlog item runs as a task would, its text read here from the file, never
1983
2003
  // from the page. The request names its source, which is how the board finds the
1984
2004
  // line again: to hide the card while the run lives, and to close it when done.
1985
2005
  if (body.backlog) {
@@ -1999,14 +2019,14 @@ export async function web(repoDir: string, opts: Opts = {}) {
1999
2019
  : { ok: false, why: r.why, manual: r.manual, agent: r.agent }, r.ok ? 200 : 500);
2000
2020
  }
2001
2021
  const it: Item = parseItem(`${kind} ${text}`.trim());
2002
- // A `started` idea may be run again: the terminal the first launch opened
2022
+ // A `started` task may be run again: the terminal the first launch opened
2003
2023
  // can come up empty, and nothing else tells the board a run never began.
2004
2024
  it.notes = readInbox(dir).find((l) => (l.status === "open" || l.status === "started") && l.text === text)?.notes;
2005
2025
  const r = launchRun(it, dir, undefined, { agent, account: typeof body.account === "string" ? body.account : undefined, model: model || undefined, yolo: body.yolo === true, ...inCard(dir) });
2006
- if (r.ok) replaceIdea(dir, text, { status: "started", text });
2026
+ if (r.ok) replaceTask(dir, text, { status: "started", text });
2007
2027
  if (r.ok && r.pty) {
2008
- for (const [k, v] of ideaPty) if (!ptyState(v)) ideaPty.delete(k); // sessions already dropped
2009
- ideaPty.set(`${dir}\0${text}`, r.pty);
2028
+ for (const [k, v] of taskPty) if (!ptyState(v)) taskPty.delete(k); // sessions already dropped
2029
+ taskPty.set(`${dir}\0${text}`, r.pty);
2010
2030
  }
2011
2031
  changed();
2012
2032
  return json(r.ok
@@ -2025,7 +2045,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
2025
2045
  const text = body.text.trim();
2026
2046
  const lines = readInbox(dir);
2027
2047
  const at = lines.findIndex((l) => l.text === text && (archived ? l.status === "open" : l.status === "archived"));
2028
- if (at < 0) return bad("no such idea", 404);
2048
+ if (at < 0) return bad("no such task", 404);
2029
2049
  lines[at] = { ...lines[at]!, status: archived ? "archived" : "open" };
2030
2050
  writeInbox(dir, lines);
2031
2051
  } else return bad("id or text required");
@@ -2251,10 +2271,10 @@ export async function web(repoDir: string, opts: Opts = {}) {
2251
2271
  : { ok: false, why: r.why, manual: r.manual, agent: r.agent }, r.ok ? 200 : 500);
2252
2272
  }
2253
2273
 
2254
- if (path === "/to-idea") {
2274
+ if (path === "/to-task" || path === "/to-idea") { // /to-idea: the old name, kept for open tabs
2255
2275
  const id = String(body.id ?? "");
2256
2276
  if (!/^[\w.-]+$/.test(id)) return bad("bad run id");
2257
- const failed = runToIdea(dir, id);
2277
+ const failed = runToTask(dir, id);
2258
2278
  changed();
2259
2279
  return failed ? bad(failed, 409) : json({ ok: true });
2260
2280
  }
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: Read the kaizen icebox, group what was gathered, and promote what you pick to ideas
2
+ description: Read the kaizen icebox, group what was gathered, and promote what you pick to tasks
3
3
  ---
4
4
 
5
5
  Invoke the `kaizen` skill with argument `discover`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kaizen-agent",
3
- "version": "1.64.0",
3
+ "version": "1.64.1",
4
4
  "description": "Staged workflow for AI agents — code, writing, research, operations: plan, human approval, build, independent review, bounded fix loop.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -99,7 +99,7 @@ remember.
99
99
 
100
100
  Every item is `open`, `done`, or `rejected`. **Rejected is a real answer**: most
101
101
  suggestions are not worth doing, and without a way to decline one it stays on the list
102
- forever. Rejecting takes a reason, which is what stops the same idea coming back three
102
+ forever. Rejecting takes a reason, which is what stops the same task coming back three
103
103
  runs later. Closed items stay in their run's file as record and are never printed
104
104
  again.
105
105
 
@@ -226,7 +226,7 @@ even in `auto`.
226
226
  memory.md # cross-run lessons, appended by the reviewer
227
227
  backlog.md # orphanage only: open items rescued before pruning
228
228
  sources.json # request sources: the links, and what was already gathered
229
- icebox.json # gathered requests, waiting to be promoted to ideas or dismissed
229
+ icebox.json # gathered requests, waiting to be promoted to tasks or dismissed
230
230
  runs/
231
231
  2026-09-02-add-oauth/
232
232
  00-request.md # the original request, verbatim
@@ -49,7 +49,7 @@ Porting the workflow to Codex or Antigravity is covered in [`adapters.md`](adapt
49
49
  | `/kaizen status` | List every run grouped waiting-on-you / in flight / done / abandoned, plus the open backlog count |
50
50
  | `/kaizen backlog` | Print the open backlog items across all runs, grouped by source run, with rescued items last under `Orphaned` |
51
51
  | `/kaizen gather` | Read the request sources kaizen cannot read by itself and hand their requests over to the icebox |
52
- | `/kaizen discover` | Read the icebox, group what was gathered, propose ideas, and promote the ones the user picks |
52
+ | `/kaizen discover` | Read the icebox, group what was gathered, propose tasks, and promote the ones the user picks |
53
53
  | `/kaizen docs` | Write this project's documentation into the notebook as a vault agents read first, or bring it up to date |
54
54
  | `/kaizen docs lint` | Run the read-only `kaizen docs lint` CLI command; report broken links, missing sources and stale notes |
55
55
  | `/kaizen approve` | Approve whatever the current run is waiting on |
@@ -72,7 +72,7 @@ If the user typed `/kaizen` with no argument and a run is in progress, treat it
72
72
  work, run `/kaizen init` first: it creates `.kaizen/` with a copy of the `spec*.md`
73
73
  files and — where the folder is a git repository — the gitignore entry
74
74
  (see [`adapters.md`](adapters.md)). Also append the project folder's absolute path
75
- to `~/.kaizen/projects` if not already listed: the board only retires an idea when
75
+ to `~/.kaizen/projects` if not already listed: the board only retires a task when
76
76
  it can see the run, and it only looks in projects it knows.
77
77
  2. Read the config in this order, each file filling in the keys the one before it
78
78
  does not set: `.kaizen/config.yml`, then `~/.kaizen/config.yml`, then