kaizen-agent 1.61.6 → 1.63.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 (120) hide show
  1. package/README.md +2 -2
  2. package/agents/kaizen-builder.md +3 -0
  3. package/agents/kaizen-planner.md +3 -0
  4. package/agents/kaizen-reviewer.md +2 -0
  5. package/assets/kaizen-logo.png +0 -0
  6. package/assets/kaizen.ico +0 -0
  7. package/cli/__pycache__/computer-helper.cpython-314.pyc +0 -0
  8. package/cli/accounts.test.ts +126 -0
  9. package/cli/accounts.ts +116 -0
  10. package/cli/add-project.ts +4 -2
  11. package/cli/agent-prefs.test.ts +127 -0
  12. package/cli/agent-prefs.ts +106 -0
  13. package/cli/automations.test.ts +167 -0
  14. package/cli/automations.ts +298 -0
  15. package/cli/board.test.ts +4 -5
  16. package/cli/computer-helper.py +299 -0
  17. package/cli/computer.test.ts +155 -0
  18. package/cli/computer.ts +66 -0
  19. package/cli/dashboard.ts +15 -22
  20. package/cli/install.test.ts +16 -0
  21. package/cli/install.ts +134 -193
  22. package/cli/keep-awake.ts +30 -0
  23. package/cli/look.ts +33 -0
  24. package/cli/project-tree.test.ts +1 -0
  25. package/cli/pty.test.ts +2 -1
  26. package/cli/pty.ts +6 -5
  27. package/cli/report.test.ts +59 -0
  28. package/cli/report.ts +62 -0
  29. package/cli/restart.test.ts +1 -0
  30. package/cli/settings.test.ts +21 -1
  31. package/cli/settings.ts +22 -13
  32. package/cli/setup.test.ts +24 -4
  33. package/cli/setup.ts +101 -51
  34. package/cli/skills.test.ts +89 -0
  35. package/cli/skills.ts +112 -0
  36. package/cli/sources.ts +1 -1
  37. package/cli/state.test.ts +53 -4
  38. package/cli/state.ts +132 -42
  39. package/cli/term-image.test.ts +23 -0
  40. package/cli/term-image.ts +26 -0
  41. package/cli/usage.test.ts +8 -2
  42. package/cli/usage.ts +8 -6
  43. package/cli/video.test.ts +5 -5
  44. package/cli/web-accept.test.ts +1 -0
  45. package/cli/web-decide.test.ts +1 -0
  46. package/cli/web-pr.test.ts +1 -0
  47. package/cli/web-skills.test.ts +32 -0
  48. package/cli/web-symlink.test.ts +1 -0
  49. package/cli/web.ts +227 -21
  50. package/cli/workers.test.ts +319 -0
  51. package/cli/workers.ts +380 -0
  52. package/cli/worktree.test.ts +21 -2
  53. package/cli/worktree.ts +21 -2
  54. package/package.json +1 -1
  55. package/skills/kaizen/config.default.yml +40 -1
  56. package/skills/kaizen/settings.md +2 -1
  57. package/skills/kaizen/skill.json +1 -0
  58. package/skills/kaizen/spec-build.md +22 -2
  59. package/skills/kaizen/spec-main.md +9 -0
  60. package/skills/kaizen/spec-plan.md +18 -1
  61. package/skills/kaizen/spec-review.md +4 -0
  62. package/skills/kaizen/spec.md +15 -0
  63. package/skills/kaizen-help/SKILL.md +2 -0
  64. package/skills/kaizen-help/skill.json +1 -0
  65. package/skills/media/kaizen-book/skill.json +1 -0
  66. package/skills/media/kaizen-deck/SKILL.md +21 -2
  67. package/skills/media/kaizen-deck/scripts/motion.py +99 -0
  68. package/skills/media/kaizen-deck/skill.json +1 -0
  69. package/skills/media/kaizen-video/scripts/__pycache__/intake.cpython-314.pyc +0 -0
  70. package/skills/media/kaizen-video/scripts/__pycache__/make_film.cpython-314.pyc +0 -0
  71. package/skills/media/kaizen-video/scripts/__pycache__/make_tiktok.cpython-314.pyc +0 -0
  72. package/skills/media/kaizen-video/scripts/__pycache__/render_cut.cpython-314.pyc +0 -0
  73. package/skills/media/kaizen-video/scripts/__pycache__/sfx.cpython-314.pyc +0 -0
  74. package/skills/media/kaizen-video/scripts/__pycache__/srt.cpython-314.pyc +0 -0
  75. package/skills/media/kaizen-video/scripts/__pycache__/transcribe.cpython-314.pyc +0 -0
  76. package/skills/media/kaizen-video/scripts/__pycache__/vo.cpython-314.pyc +0 -0
  77. package/skills/media/kaizen-video/skill.json +1 -0
  78. package/skills/optional/kaizen-computer/SKILL.md +38 -0
  79. package/skills/optional/kaizen-computer/skill.json +1 -0
  80. package/web/board/add-project.ts +3 -3
  81. package/web/board/agent-favicons.ts +9 -0
  82. package/web/board/agent-term.ts +1 -1
  83. package/web/board/api.ts +1 -1
  84. package/web/board/approvals.ts +1 -1
  85. package/web/board/cards.ts +50 -7
  86. package/web/board/dictation.ts +46 -3
  87. package/web/board/fixes.ts +1 -1
  88. package/web/board/home.ts +1 -1
  89. package/web/board/icebox.ts +1 -1
  90. package/web/board/keys.ts +5 -15
  91. package/web/board/onboarding.ts +1 -1
  92. package/web/board/panel.ts +24 -20
  93. package/web/board/phone.ts +6 -1
  94. package/web/board/run-view.ts +118 -7
  95. package/web/board/search.ts +6 -0
  96. package/web/board/settings-accounts.ts +60 -0
  97. package/web/board/settings-agents.ts +102 -0
  98. package/web/board/settings-automations.ts +71 -0
  99. package/web/board/settings-orchestration.ts +32 -0
  100. package/web/board/settings-pages.test.ts +9 -0
  101. package/web/board/settings-pages.ts +11 -4
  102. package/web/board/settings-skills.ts +47 -0
  103. package/web/board/settings-voice.test.ts +18 -0
  104. package/web/board/settings-voice.ts +28 -0
  105. package/web/board/settings.ts +48 -5
  106. package/web/board/terms.ts +2 -2
  107. package/web/board/update.ts +1 -1
  108. package/web/board/workspace.ts +5 -1
  109. package/web/board/ws-board.test.ts +6 -0
  110. package/web/board/ws-board.ts +2 -0
  111. package/web/board/ws-tabs.test.ts +12 -1
  112. package/web/board/ws-tabs.ts +18 -0
  113. package/web/board.html +22 -5
  114. package/web/board.js +156 -85
  115. package/web/notebook.js +22 -22
  116. package/web/notes.html +3 -3
  117. package/web/term.js +27 -27
  118. package/web/term.ts +25 -3
  119. package/web/video.html +2 -2
  120. package/web/video.js +31 -31
package/cli/install.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env bun
2
+ import { bundledSkills, skillsHeld, skillsOff, skillsToLink } from "./skills.ts";
2
3
  import {
3
4
  symlinkSync, mkdirSync, readdirSync, lstatSync, unlinkSync,
4
5
  existsSync, copyFileSync, readFileSync, appendFileSync, rmSync, writeFileSync, renameSync,
@@ -8,6 +9,7 @@ import { join, dirname, basename, resolve } from "node:path";
8
9
  import { homedir, tmpdir } from "node:os";
9
10
  import { ignoreKaizen } from "./add-project.ts";
10
11
  import { applyPreset, detectPreset, PRESETS, type PresetName } from "./settings.ts";
12
+ import { banner, c, nextSteps } from "./look.ts";
11
13
 
12
14
  // The real path: process.cwd() is always physical, so a raw $HOME that crosses a
13
15
  // symlink (/home -> var/home) would never compare equal to it, and the home
@@ -40,16 +42,13 @@ function parsePresetArg(): PresetName | null {
40
42
  }
41
43
  const presetArg = parsePresetArg();
42
44
 
43
- const c = {
44
- dim: (s: string) => `\x1b[2m${s}\x1b[0m`,
45
- bold: (s: string) => `\x1b[1m${s}\x1b[0m`,
46
- cyan: (s: string) => `\x1b[36m${s}\x1b[0m`,
47
- green: (s: string) => `\x1b[32m${s}\x1b[0m`,
48
- };
49
-
50
45
  // Skill folders shipped in skills/ and linked into every agent, by their last
51
46
  // path segment: media/kaizen-deck is linked as skills/kaizen-deck.
52
- const SKILLS = ["kaizen", "kaizen-help", "media/kaizen-deck", "media/kaizen-video", "media/kaizen-book"];
47
+ const SKILLS = bundledSkills(dirname(import.meta.dir)).map((s) => s.rel);
48
+ // What an install links and checks: a skill turned off in Settings stays off through upgrades.
49
+ // A skill that ships off by default (desktop control) stays unlinked until it is turned on.
50
+ const HELD = skillsHeld(dirname(import.meta.dir), homedir());
51
+ const ON_SKILLS = skillsToLink(SKILLS, skillsOff(homedir()), true, HELD);
53
52
  // Skill names an older release linked; uninstall drops them and install
54
53
  // clears them when they are still our links.
55
54
  const RENAMED_SKILLS = ["story-deck", "story-video", "kaizen-motion"];
@@ -117,6 +116,96 @@ if (Bun.argv[2] === "card") {
117
116
  process.exit(0);
118
117
  }
119
118
 
119
+ // `kaizen computer <verb> ...`: desktop control through the accessibility tree, only while
120
+ // the kaizen-computer skill is on. One JSON line out. See cli/computer.ts.
121
+ // `kaizen automation list | add | run | pause | resume | rm | runs`: schedules that start a run in this
122
+ // project. Fires happen while a board runs; `run` starts one now, in a terminal, without the precheck.
123
+ if (Bun.argv[2] === "automation") {
124
+ const A = await import("./automations.ts");
125
+ const { locate } = await import("./state.ts");
126
+ const state = locate() ?? join(home, ".kaizen");
127
+ const [verb, ...rest] = Bun.argv.slice(3);
128
+ const flag = (n: string) => { const i = rest.indexOf("--" + n); return i >= 0 ? rest.splice(i, 2)[1] : undefined; };
129
+ const fail = (m: string): never => { console.log(`\n ${m}\n`); process.exit(1); };
130
+ const rules = () => { try { return A.readRules(state); } catch (e: any) { return fail(e.message); } };
131
+ const find = (id?: string) => rules().find((r) => r.id === id) ?? fail("No such automation. See: kaizen automation list");
132
+ if (verb === "add") {
133
+ const input = { text: flag("text"), kind: flag("every"), time: flag("time"), day: flag("day"), cron: flag("cron"), precheck: flag("precheck"), grace_minutes: flag("grace"), agent: flag("agent"), name: rest.join(" ") };
134
+ if (input.cron && !input.kind) input.kind = "cron";
135
+ const r = A.addRule(state, input);
136
+ if (typeof r === "string") fail(`${r}\n kaizen automation add "<name>" --text "<request>" --every hourly|daily|weekdays|weekly [--time HH:MM] [--day mon] | --cron "<5 fields>" [--precheck "<cmd>"] [--grace N] [--agent <tool>]`);
137
+ else console.log(`\n ${c.green("added")} ${r.name} ${c.dim(`${r.id} · ${r.cron}`)}\n ${c.dim("Runs unattended in auto mode: it changes code and spends tokens with nobody watching.")}\n${r.precheck ? ` ${c.dim("precheck, runs on this computer every time it fires:")} ${r.precheck}\n` : ""}`);
138
+ } else if (verb === "list" || !verb) {
139
+ for (const r of rules()) { const n = A.nextRun(r.cron, Date.now()); console.log(` ${r.id} ${r.enabled ? "on " : "off"} ${r.cron.padEnd(14)} next ${n ? new Date(n).toLocaleString() : "never"} ${r.name}`); }
140
+ } else if (verb === "pause" || verb === "resume") {
141
+ const r = A.setEnabled(state, find(rest[0]).id, verb === "resume"); if (typeof r === "string") fail(r); console.log(`\n ${verb}d ${rest[0]}\n`);
142
+ } else if (verb === "rm") {
143
+ const r = A.removeRule(state, find(rest[0]).id); if (r) fail(r); console.log(`\n removed ${rest[0]}\n`);
144
+ } else if (verb === "run") {
145
+ const h = await A.fire(state, find(rest[0]), "manual", Date.now());
146
+ console.log(`\n ${h?.status}${h?.reason ? `: ${h.reason}` : ""}\n`); process.exit(h?.status === "launched" ? 0 : 1);
147
+ } else if (verb === "runs") {
148
+ const id = find(rest[0]).id;
149
+ for (const h of A.readHistory(state).filter((x) => x.rule === id).sort((a, b) => b.at - a.at)) { const v = A.shown(state, h); console.log(` ${new Date(h.at).toLocaleString()} ${h.kind.padEnd(9)} ${v.status}${v.run ? " " + v.run : ""}${h.reason ? " " + h.reason : ""}`); }
150
+ } else fail("kaizen automation list | add | run <id> | pause <id> | resume <id> | rm <id> | runs <id>");
151
+ process.exit(0);
152
+ }
153
+
154
+ if (Bun.argv[2] === "computer") {
155
+ const { computer } = await import("./computer.ts");
156
+ const { out, code } = await computer(Bun.argv.slice(3), { home: homedir() });
157
+ console.log(JSON.stringify(out));
158
+ process.exit(code);
159
+ }
160
+
161
+ // `kaizen report`: how an agent tells the board about its run. See cli/report.ts.
162
+ if (Bun.argv[2] === "report") {
163
+ const { locate } = await import("./state.ts");
164
+ const r = await import("./report.ts");
165
+ const a = Bun.argv.slice(3), flag = (n: string) => { const i = a.indexOf(n); return i < 0 ? undefined : a.splice(i, 2)[1]; };
166
+ const usage = "kaizen report phase <text> | blocked <question> [--options a,b] | unblock | done --outcome succeeded|failed --summary <text> [--files a,b] [--stage s] [--run id]";
167
+ const id = flag("--run") ?? process.env.KAIZEN_RUN_ID, options = flag("--options"), outcome = flag("--outcome"), summary = flag("--summary"), files = flag("--files"), stage = flag("--stage") ?? process.env.KAIZEN_STAGE;
168
+ const state = r.stateOf(process.cwd(), locate()) ?? join(home, ".kaizen");
169
+ const [verb, ...rest] = a, text = rest.join(" ");
170
+ if (!id) { console.log(`\n ${usage}\n no run: pass --run <id>\n`); process.exit(1); }
171
+ const why = verb === "phase" && text ? r.reportPhase(state, id, text)
172
+ : verb === "blocked" && text ? r.reportBlocked(state, id, text, options?.split(",") ?? [])
173
+ : verb === "unblock" ? r.reportUnblock(state, id)
174
+ : verb === "done" && outcome && summary && stage ? r.reportDone(state, id, stage, outcome, summary, files?.split(",") ?? [])
175
+ : usage;
176
+ if (why) { console.log(`\n ${why}\n`); process.exit(1); }
177
+ process.exit(0);
178
+ }
179
+
180
+ // `kaizen worker`: a run split into workers, off by default. See cli/workers.ts.
181
+ if (Bun.argv[2] === "worker") {
182
+ const { locate } = await import("./state.ts");
183
+ const { stateOf } = await import("./report.ts");
184
+ const w = await import("./workers.ts");
185
+ const a = Bun.argv.slice(3), flag = (n: string) => { const i = a.indexOf(n); return i < 0 ? undefined : a.splice(i, 2)[1]; };
186
+ const usage = "kaizen worker init [run] | start <wid> | status | config | report phase <text> | blocked <q> [--options a,b] | unblock | done --outcome succeeded|failed --summary <text> [--files a,b] | merge | set <run> on|off|clear [--run id] [--worker wid]";
187
+ const state = stateOf(process.cwd(), locate()) ?? join(home, ".kaizen"), project = dirname(state);
188
+ const runId = flag("--run"), worker = flag("--worker") ?? process.env.KAIZEN_WORKER, options = flag("--options"), outcome = flag("--outcome"), summary = flag("--summary"), files = flag("--files");
189
+ const [verb, ...rest] = a;
190
+ const id = (verb === "init" || verb === "set" ? rest[0] : undefined) ?? runId ?? process.env.KAIZEN_RUN_ID;
191
+ const fail = (why: string) => { console.log(`\n ${why}\n`); process.exit(1); };
192
+ const say = (text: string) => { console.log(`\n ${text.replace(/\n/g, "\n ")}\n`); process.exit(0); };
193
+ if (!verb) fail(usage);
194
+ if (!id) fail(`${usage}\n no run: pass --run <id>`);
195
+ if (verb === "init") { const r = w.init(project, id!); r.ok ? say(`${r.n} workers planned. Next: kaizen worker start <wid>`) : fail(r.why); }
196
+ else if (verb === "start") { const r = w.requestStart(project, id!, rest[0] ?? ""); r.ok ? say(r.why) : fail(r.why); }
197
+ else if (verb === "status") say(w.statusText(project, id!));
198
+ else if (verb === "config") { const r = w.resolve(project, id!); say(r.on ? `on · max ${r.max} · permissions ${r.permissions} · model ${r.model}` : `off · ${r.why}`); }
199
+ else if (verb === "merge") { const r = w.merge(project, id!); r.ok ? say(`merged ${r.shas.length} workers into the run's branch. Next: the usual checks, then 03-impl.md${r.left.length ? `\nleft behind (remove by hand):\n${r.left.join("\n")}` : ""}`) : fail(r.why); }
200
+ else if (verb === "set") { const why = w.setRun(project, id!, rest[1] ?? ""); why ? fail(why) : say(`${id}: orchestration ${rest[1]}`); }
201
+ else if (verb === "report") {
202
+ const [kind, ...t] = rest;
203
+ if (!worker) fail("report: which worker? run it from the worker's terminal, or pass --worker <wid>");
204
+ const why = w.report(project, id!, worker!, kind ?? "", { text: t.join(" "), options: options?.split(","), outcome, summary, files: files?.split(",") });
205
+ why ? fail(why) : say("reported");
206
+ } else fail(usage);
207
+ }
208
+
120
209
  // `kaizen done <run id> [--user-approved]`: how an agent finishes a run. Refuses while
121
210
  // the review gate waits on the user; --user-approved is for a clear yes in chat.
122
211
  if (Bun.argv[2] === "done") {
@@ -226,7 +315,7 @@ if (Bun.argv[2] === "issue") {
226
315
  if (args.has("--env")) { console.log(systemInfo()); process.exit(0); }
227
316
  const what = Bun.argv.slice(3).join(" ");
228
317
  const url = issueUrl({ title: what.split("\n")[0], what });
229
- console.log(`\n ${c.cyan(url)}\n`);
318
+ console.log(`\n ${c.accent(url)}\n`);
230
319
  console.log(await openUrl(url)
231
320
  ? ` ${c.dim("Opened in your browser. Check it, then submit it on GitHub.")}\n`
232
321
  : ` ${c.dim("Open that link to file the issue.")}\n`);
@@ -274,6 +363,8 @@ async function removeEverything() {
274
363
  // projects live on other drives entirely. Every project kaizen knows about is
275
364
  // checked, plus whatever a drive-wide scan turns up.
276
365
  const { knownProjects, searchRoots, findProjects } = await import("./state.ts");
366
+ // Loaded now: the launcher runs this file from ~/kaizen, which is deleted below.
367
+ const { removeSessionHook } = await import("./knowledge.ts");
277
368
  step("looking for project installs");
278
369
  const roots = [home, process.cwd(), ...knownProjects(),
279
370
  ...searchRoots([process.cwd()]).flatMap((r) => findProjects(r))]
@@ -318,7 +409,6 @@ async function removeEverything() {
318
409
  drop(join(process.env.BUN_INSTALL ?? join(home, ".bun"), "bin", "kaizen.cmd"));
319
410
  drop(join(home, ".local", "bin", "kaizen"));
320
411
  {
321
- const { removeSessionHook } = await import("./knowledge.ts");
322
412
  if (removeSessionHook(join(home, ".claude", "settings.json"))) gone.push("the kaizen recall hook in ~/.claude/settings.json");
323
413
  }
324
414
  await clearBunxCache();
@@ -338,7 +428,7 @@ async function removeEverything() {
338
428
  }
339
429
  console.log(purge
340
430
  ? `\n ${c.dim("Runs and settings deleted too.")}\n`
341
- : `\n ${c.dim("Runs and settings kept in")} ${c.cyan(tilde(join(home, ".kaizen")))}${c.dim(" — add --purge to delete them.")}\n`);
431
+ : `\n ${c.dim("Runs and settings kept in")} ${c.accent(tilde(join(home, ".kaizen")))}${c.dim(" — add --purge to delete them.")}\n`);
342
432
  console.log(` ${c.dim("The CLAUDE.md / AGENTS.md line in each project is left for you to remove.")}\n`);
343
433
  }
344
434
 
@@ -388,11 +478,11 @@ async function noAgent(): Promise<boolean> {
388
478
  const docs = async (why = "") => {
389
479
  if (why) console.log(` ${why}`);
390
480
  console.log(` ${c.bold(pick.name)}`);
391
- console.log(` ${c.cyan(pick.docs)}\n`);
481
+ console.log(` ${c.accent(pick.docs)}\n`);
392
482
  const opened = await openUrl(pick.docs);
393
483
  console.log(opened
394
- ? ` ${c.dim("Opened in your browser. Install it, then run")} ${c.cyan("kaizen")} ${c.dim("again.")}`
395
- : ` ${c.dim("Open that page to install it, then run")} ${c.cyan("kaizen")} ${c.dim("again.")}`);
484
+ ? ` ${c.dim("Opened in your browser. Install it, then run")} ${c.accent("kaizen")} ${c.dim("again.")}`
485
+ : ` ${c.dim("Open that page to install it, then run")} ${c.accent("kaizen")} ${c.dim("again.")}`);
396
486
  return false;
397
487
  };
398
488
 
@@ -401,7 +491,7 @@ async function noAgent(): Promise<boolean> {
401
491
  if (!cmd) return docs();
402
492
  if (cmd.startsWith("npm ") && !Bun.which("npm")) return docs(c.dim(`${pick.name} installs with npm, which needs Node.js: https://nodejs.org`));
403
493
 
404
- console.log(`\n ${c.dim("Official installer:")} ${c.cyan(cmd)}`);
494
+ console.log(`\n ${c.dim("Official installer:")} ${c.accent(cmd)}`);
405
495
  if (!(await select(`Install ${pick.name} now?`, [
406
496
  { label: "Yes", hint: "run the command above", value: true },
407
497
  { label: "No", hint: "open the docs page instead", value: false },
@@ -416,7 +506,7 @@ async function noAgent(): Promise<boolean> {
416
506
  if (code !== 0 || !bin) {
417
507
  return docs(code !== 0
418
508
  ? `${c.bold("The install did not finish")} ${c.dim(`(exit ${code}).`)}`
419
- : `${c.bold(`${pick.name} installed, but`)} ${c.cyan(pick.cmd)} ${c.bold("is not on PATH yet.")} ${c.dim("Open a new terminal and run kaizen again.")}`);
509
+ : `${c.bold(`${pick.name} installed, but`)} ${c.accent(pick.cmd)} ${c.bold("is not on PATH yet.")} ${c.dim("Open a new terminal and run kaizen again.")}`);
420
510
  }
421
511
  step(`installed ${pick.name}`);
422
512
 
@@ -472,12 +562,13 @@ if (wantSettings) {
472
562
  if (args.has("worktree")) {
473
563
  const [, verb = "", id = ""] = Bun.argv.slice(2).filter((a) => !a.startsWith("-"));
474
564
  const { locate } = await import("./state.ts");
475
- const { startWorktree, landWorktree, adoptWorkspace } = await import("./worktree.ts");
565
+ const { startWorktree, landWorktree, adoptWorkspace, linkTerm } = await import("./worktree.ts");
476
566
  const state = locate();
477
567
  if (!state || (verb !== "start" && verb !== "land")) { console.log("\n usage: kaizen worktree start|land <run-id>, in a project with .kaizen\n"); process.exit(1); }
478
568
  const project = dirname(state);
479
569
  // Started inside another workspace of the project (a board worktree): the run is placed there.
480
570
  const r = verb === "start" ? adoptWorkspace(project, id, process.cwd()) ?? startWorktree(project, id) : landWorktree(project, id);
571
+ if (r.ok && verb === "start") linkTerm(state, process.env.KAIZEN_TERM, id);
481
572
  console.log(r.ok ? `\n ${verb === "start" ? `worktree ready: ${(r as { path: string }).path}` : `landed by ${(r as { how: string }).how}`}\n` : `\n ${r.why}\n`);
482
573
  process.exit(r.ok ? 0 : 1);
483
574
  }
@@ -493,7 +584,7 @@ if (args.has("prune")) {
493
584
  const apply = args.has("--yes");
494
585
  const gone = pruneRuns(state, keep, apply);
495
586
  console.log(gone.length
496
- ? `\n ${apply ? "pruned" : "would prune"} ${gone.length} finished run(s), keeping the newest ${keep}:\n${gone.map((g) => ` ${g.id}${g.rescued ? c.dim(` ${g.rescued} open item(s) ${apply ? "moved" : "to move"} to backlog.md`) : ""}`).join("\n")}\n${apply ? "" : `\n ${c.dim("nothing deleted — run:")} ${c.cyan("kaizen prune --yes")}\n`}`
587
+ ? `\n ${apply ? "pruned" : "would prune"} ${gone.length} finished run(s), keeping the newest ${keep}:\n${gone.map((g) => ` ${g.id}${g.rescued ? c.dim(` ${g.rescued} open item(s) ${apply ? "moved" : "to move"} to backlog.md`) : ""}`).join("\n")}\n${apply ? "" : `\n ${c.dim("nothing deleted — run:")} ${c.accent("kaizen prune --yes")}\n`}`
497
588
  : `\n nothing to prune ${c.dim(`(${keep} finished runs are kept)`)}\n`);
498
589
  process.exit(0);
499
590
  }
@@ -639,7 +730,7 @@ if (interactive && !upgrade && Bun.argv.length === 2) {
639
730
  if (!stale) {
640
731
  const here = found(home);
641
732
  const linked = here.length > 0 && here.every((a) =>
642
- SKILLS.every((n) => existsSync(join(home, a.dir, "skills", basename(n)))));
733
+ ON_SKILLS.every((n) => existsSync(join(home, a.dir, "skills", basename(n)))));
643
734
  if (linked) {
644
735
  const { dashboard } = await import("./dashboard.ts");
645
736
  await dashboard(repoDir, here.map((a) => a.name), async (action) => {
@@ -704,7 +795,7 @@ if (upgrade) {
704
795
  if (after !== latest) {
705
796
  console.log(`\n ${c.bold(`could not install kaizen ${latest}`)}`);
706
797
  // npm names a new version before it serves it (its review takes minutes).
707
- console.log(` ${c.dim("npm may still be publishing it: try again in a few minutes, or run")} ${c.cyan(`bunx kaizen-agent@${latest}`)}\n`);
798
+ console.log(` ${c.dim("npm may still be publishing it: try again in a few minutes, or run")} ${c.accent(`bunx kaizen-agent@${latest}`)}\n`);
708
799
  finish(1);
709
800
  }
710
801
  console.log(`\n ${c.bold("Upgraded")} ${c.dim(now)} → ${c.green(after)}\n ${c.dim("Restart Claude Code to pick up any new slash commands.")}\n`);
@@ -713,107 +804,15 @@ if (upgrade) {
713
804
  if (!check && !upgrade) await welcome();
714
805
 
715
806
  async function welcome() {
716
- const rgb = (r: number, g: number, b: number, s: string) =>
717
- `\x1b[38;2;${r};${g};${b}m${s}\x1b[0m`;
718
-
719
- // Fuji: snow on the peak, deepening blue down the slope.
720
- const WORD = [
721
- "██╗ ██╗ █████╗ ██╗███████╗███████╗███╗ ██╗",
722
- "██║ ██╔╝██╔══██╗██║╚══███╔╝██╔════╝████╗ ██║",
723
- "█████╔╝ ███████║██║ ███╔╝ █████╗ ██╔██╗ ██║",
724
- "██╔═██╗ ██╔══██║██║ ███╔╝ ██╔══╝ ██║╚██╗██║",
725
- "██║ ██╗██║ ██║██║███████╗███████╗██║ ╚████║",
726
- "╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚══════╝╚══════╝╚═╝ ╚═══╝",
727
- ];
728
- const W = 69, C = 34, SNOW = 3;
729
- // One constant slope, three columns per row, all the way down. The rows behind
730
- // the wordmark keep the same rate, so the edge that goes in above the letters
731
- // comes out below them on the same line -- vary it and the cone reads broken.
732
- const H = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34];
733
-
734
- // Anything that would wrap is worse than the smaller thing that fits: the
735
- // mountain needs the full width, the wordmark needs 47, below that use words.
736
- const cols = process.stdout.columns || 80;
737
- const wide = cols >= W + 4;
738
- if (cols < 49) {
739
- console.log(`\n ${c.bold("kaizen")}`);
740
- } else {
741
-
742
- const cell: string[][] = H.map(() => Array(W).fill(" "));
743
- const isWord: boolean[][] = H.map(() => Array(W).fill(false));
744
-
745
- if (wide) {
746
- for (const [i, h] of H.entries()) {
747
- const l = C - h, r = C + h;
748
- if (i < SNOW) { // solid cap
749
- cell[i]![l] = "▄"; cell[i]![r] = "▄";
750
- for (let x = l + 1; x < r; x++) cell[i]![x] = "█";
751
- } else { // slope, drawn as two edges
752
- // Below the wordmark's top row the letters own the middle, so draw an
753
- // edge only where all three of its characters clear them.
754
- const band = i >= H.length - WORD.length;
755
- const gap = Math.floor((W - 45) / 2) - 2;
756
- if (!band || l + 2 < gap) {
757
- cell[i]![l] = "▄"; cell[i]![l + 1] = "█"; cell[i]![l + 2] = "▀";
758
- cell[i]![r - 2] = "▀"; cell[i]![r - 1] = "█"; cell[i]![r] = "▄";
759
- }
760
- }
761
- }
762
- }
763
-
764
- const top = H.length - WORD.length, left = Math.floor((W - 45) / 2);
765
- for (let r = top; r < H.length; r++) // air around the letters
766
- for (let x = left - 2; x < left + 47; x++) if (x >= 0 && x < W) cell[r]![x] = " ";
767
- for (const [r, line] of WORD.entries())
768
- for (const [x, ch] of [...line].entries())
769
- if (ch !== " ") { cell[top + r]![left + x] = ch; isWord[top + r]![left + x] = true; }
770
-
771
- console.log();
772
- for (const [i, row] of cell.entries()) {
773
- if (!wide && i < top) continue; // no mountain to draw, no blank rows
774
- const slope = Math.max(0, i - SNOW) / (H.length - SNOW);
775
- const mountain: [number, number, number] = i < SNOW
776
- ? [255 - i * 8, 255 - i * 5, 255]
777
- : [Math.round(150 - slope * 105), Math.round(190 - slope * 110), Math.round(245 - slope * 80)];
778
-
779
- // With no mountain there is nothing to sit under, so drop its left margin.
780
- const off = wide ? 0 : left;
781
- const chars = row.slice(off), flags = isWord[i]!.slice(off);
782
-
783
- let out = " ", run = "", runWord = flags[0]!;
784
- const flush = () => {
785
- if (!run) return;
786
- const t = (i - top) / (WORD.length - 1);
787
- const col: [number, number, number] = runWord
788
- ? [Math.round(214 - t * 150), Math.round(232 - t * 130), Math.round(255 - t * 45)]
789
- : mountain;
790
- out += rgb(col[0], col[1], col[2], run);
791
- run = "";
792
- };
793
- for (const [x, ch] of chars.entries()) {
794
- if (flags[x] !== runWord) { flush(); runWord = flags[x]!; }
795
- run += ch;
796
- }
797
- flush();
798
- console.log(out.replace(/\s+$/, ""));
799
- }
800
- if (wide) console.log(" " + rgb(38, 66, 130, "▀".repeat(W)));
801
- }
802
-
803
- console.log(`
804
- ${c.bold("改善")} ${c.dim("kaizen — continuous improvement")}
805
-
806
- ${c.dim("A staged workflow for AI agents — code, writing, research, operations:")}
807
- ${c.dim("plan -> you approve -> build -> independent review -> bounded fix loop")}
808
- `);
809
-
807
+ console.log(banner());
808
+ console.log(` ${c.dim("A staged workflow for AI agents: plan, you approve, build, independent review.")}\n`);
810
809
  if (interactive) await anyKey();
811
810
  }
812
811
 
813
812
  // A pause before anything touches the filesystem, and the place to back out.
814
813
  async function anyKey() {
815
814
  const { stdin, stdout } = process;
816
- stdout.write(` ${c.dim("press")} ${c.cyan("enter")} ${c.dim("to install, or")} ${c.cyan("ctrl-c")} ${c.dim("to leave")}`);
815
+ stdout.write(` ${c.dim("Press")} ${c.accent("Enter")} ${c.dim("to install, or")} ${c.accent("Ctrl-C")} ${c.dim("to leave")}`);
817
816
  stdin.setRawMode(true);
818
817
  stdin.resume();
819
818
  await new Promise<void>((resolve) => {
@@ -830,35 +829,12 @@ async function anyKey() {
830
829
  }
831
830
 
832
831
  const repo = await resolveRepo();
833
- const root = await chooseRoot();
834
- const presetChoice = await choosePreset();
832
+ // Global unless asked otherwise; the project and the preset are `kaizen setup`'s questions.
833
+ const root = args.has("--project") ? process.cwd() : home;
834
+ // null means "leave the config alone": answering for the user would overwrite their preset.
835
+ const presetChoice: PresetName | null = presetArg;
835
836
  const targets = found(root);
836
837
 
837
- // null means "leave the config alone": an upgrade or a --yes run never asked, and
838
- // answering "medium" for the user overwrote whatever preset they had chosen.
839
- async function choosePreset(): Promise<PresetName | null> {
840
- if (presetArg) return presetArg;
841
- if (!interactive) return null;
842
-
843
- return select("Choose workflow preset", [
844
- {
845
- label: "Medium (Recommended)",
846
- hint: "balanced — subagents, plan approval, auto-fix high/critical",
847
- value: "medium",
848
- },
849
- {
850
- label: "Low",
851
- hint: "inline & manual — lite runner, inline builder, manual approvals, no auto-fix",
852
- value: "low",
853
- },
854
- {
855
- label: "Ultra",
856
- hint: "autonomous — subagents, auto mode, auto-fix all findings (up to 4 rounds)",
857
- value: "ultra",
858
- },
859
- ]);
860
- }
861
-
862
838
  // ---------------------------------------------------------------- repo
863
839
 
864
840
  // Settings only needs the clone's default config, not a pull.
@@ -925,22 +901,6 @@ async function resolveRepo() {
925
901
  return dest;
926
902
  }
927
903
 
928
- async function chooseRoot() {
929
- if (args.has("--project")) return process.cwd();
930
- if (args.has("--global") || !interactive) return home;
931
- // A project install only means something in a project. Standing in the home
932
- // directory it is the global install under another name; any other folder is
933
- // a project worth installing into, git repository or not.
934
- const cwd = process.cwd();
935
- if (cwd === home) return home;
936
-
937
- const names = (r: string) => found(r).map((a) => a.name).join(", ");
938
- return select("Install kaizen for", [
939
- { label: "Globally", hint: `every project \u2014 ${names(home)}`, value: home },
940
- { label: "This project only", hint: `${basename(cwd)}/ \u2014 ${names(cwd)}`, value: cwd },
941
- ]);
942
- }
943
-
944
904
  // ---------------------------------------------------------------- linking
945
905
 
946
906
  function dirEntries(sub: string) {
@@ -950,7 +910,7 @@ function dirEntries(sub: string) {
950
910
  }
951
911
 
952
912
  const links = targets.flatMap((a) => [
953
- ...SKILLS.map((n) => [join(repo, "skills", n), join(a.dir, "skills")] as const),
913
+ ...skillsToLink(SKILLS, skillsOff(homedir()), resolve(a.dir) === resolve(home, basename(a.dir)), HELD).map((n) => [join(repo, "skills", n), join(a.dir, "skills")] as const),
954
914
  ...(a.full ? [
955
915
  ...dirEntries("agents").map((f) => [f, join(a.dir, "agents")] as const),
956
916
  ...dirEntries("commands").map((f) => [f, join(a.dir, "commands")] as const),
@@ -1044,10 +1004,6 @@ step(
1044
1004
  : wrote ? `linked ${wrote} files into ${into}`
1045
1005
  : `already installed for ${into} ${c.dim("(nothing to change)")}`,
1046
1006
  );
1047
- if (targets.length === 1) {
1048
- console.log(` ${c.dim("Codex, Antigravity, OpenCode, Cursor and Gemini CLI get it too,")}`);
1049
- console.log(` ${c.dim("if their directory exists when you install.")}`);
1050
- }
1051
1007
 
1052
1008
  // Global knowledge reaches plain Claude Code sessions through a SessionStart hook
1053
1009
  // that prints only the lessons matching the project's stack (cli/knowledge.ts).
@@ -1089,7 +1045,7 @@ function installLauncher() {
1089
1045
  const onPath = (process.env.PATH ?? "").split(win ? ";" : ":")
1090
1046
  .some((p) => p.replace(/[\\/]+$/, "").toLowerCase() === binDir.replace(/[\\/]+$/, "").toLowerCase());
1091
1047
  step(onPath
1092
- ? `${c.cyan("kaizen upgrade")} is now on your PATH`
1048
+ ? `${c.accent("kaizen upgrade")} is now on your PATH`
1093
1049
  : `wrote ${tilde(bin)} ${c.dim(`— add ${tilde(binDir)} to PATH to use it`)}`);
1094
1050
  } catch {
1095
1051
  /* a read-only home is not worth failing the install over */
@@ -1139,17 +1095,7 @@ function kaizenAbove() {
1139
1095
  }
1140
1096
 
1141
1097
  if (inProject && !kaizenAbove()) {
1142
- const now = root === process.cwd() || args.has("--init-project")
1143
- ? true
1144
- : interactive
1145
- ? await select(`Set up ${basename(process.cwd())}/ for kaizen now`, [
1146
- // "Not now" leads: the offer now appears in any folder outside home, so the
1147
- // safe answer is the one under the cursor.
1148
- { label: "Not now", hint: "the first /kaizen run will do it", value: false },
1149
- { label: "Yes", hint: "writes .kaizen/ and a CLAUDE.md line so it runs by default", value: true },
1150
- ])
1151
- : false;
1152
- if (now) initProject();
1098
+ if (root === process.cwd() || args.has("--init-project")) initProject();
1153
1099
  } else if (existsSync(kaizenDir)) {
1154
1100
  const drift = specDrift();
1155
1101
  for (const f of drift) copyFileSync(join(repo, "skills/kaizen", f), join(kaizenDir, f));
@@ -1196,20 +1142,12 @@ function writePointer() {
1196
1142
 
1197
1143
  // ---------------------------------------------------------------- done
1198
1144
 
1199
- {
1200
- console.log(`
1201
- ${c.bold("Next")}
1202
- 1 restart Claude Code ${c.dim("— skills load live, slash commands only at session start")}
1203
- 2 ${c.cyan("/kaizen <what you want done>")} ${c.dim("in any project — it sets itself up on first run")}
1204
- 3 ${c.cyan("kaizen setup")} ${c.dim("— settings, the board, and the phone app, any time")}
1205
-
1206
- ${c.dim("/kaizen-help lists every command. kaizen upgrade updates all of this.")}
1207
- `);
1208
- if (interactive && !blocked && await select("Run setup now?", [
1209
- { label: "Not now", hint: "kaizen setup runs it later", value: false },
1210
- { label: "Yes", hint: "a project folder, settings, the board, the phone", value: true },
1211
- ])) await runSetup();
1212
- }
1145
+ // Setup ends by printing the next steps itself.
1146
+ if (interactive && !blocked && await select("Set up kaizen now? It takes about a minute.", [
1147
+ { label: "Yes", hint: "your project, how much kaizen asks you, the Kaizen App", value: true },
1148
+ { label: "Later", hint: "run kaizen setup any time", value: false },
1149
+ ])) await runSetup();
1150
+ else console.log(nextSteps());
1213
1151
  if (blocked) process.exit(1);
1214
1152
 
1215
1153
  // ---------------------------------------------------------------- helpers
@@ -1344,14 +1282,17 @@ async function select<T>(question: string, options: { label: string; hint: strin
1344
1282
  if (!first) stdout.write(`\x1b[${options.length}A`);
1345
1283
  for (const [i, o] of options.entries()) {
1346
1284
  const on = i === active;
1285
+ // A wrapped row would break the redraw, which moves up one line per option.
1286
+ const room = Math.max(0, (stdout.columns || 80) - o.label.length - 9);
1287
+ const hint = o.hint.length > room ? `${o.hint.slice(0, Math.max(0, room - 1))}…` : o.hint;
1347
1288
  stdout.write(
1348
- `\x1b[2K ${on ? c.cyan(">") : " "} ${on ? c.bold(o.label) : c.dim(o.label)}` +
1349
- ` ${c.dim(o.hint)}\n`,
1289
+ `\x1b[2K ${on ? c.bold(">") : " "} ${on ? c.bold(o.label) : c.dim(o.label)}` +
1290
+ ` ${c.dim(hint)}\n`,
1350
1291
  );
1351
1292
  }
1352
1293
  };
1353
1294
 
1354
- stdout.write(`\n ${c.bold(question)} ${c.dim("(arrows, enter)")}\n`);
1295
+ stdout.write(`\n ${c.bold(question)}\n ${c.dim("Up and down to move, Enter to choose")}\n`);
1355
1296
  stdout.write("\x1b[?25l");
1356
1297
  draw(true);
1357
1298
  stdin.setRawMode(true);
@@ -1367,7 +1308,7 @@ async function select<T>(question: string, options: { label: string; hint: strin
1367
1308
  const keys = chunk.toString();
1368
1309
  for (let i = 0; i < keys.length; i++) {
1369
1310
  const rest = keys.slice(i);
1370
- if (rest.startsWith("\x03")) { stdout.write("\ncancelled\n"); process.exit(130); }
1311
+ if (rest.startsWith("\x03")) { stdout.write("\x1b[?25h\ncancelled\n"); process.exit(130); }
1371
1312
  if (rest.startsWith("\r") || rest.startsWith("\n")) {
1372
1313
  stdin.off("data", onData);
1373
1314
  return resolve();
@@ -0,0 +1,30 @@
1
+ // agent.keep_awake: an idle and sleep inhibitor held as a child of the board. Each one
2
+ // watches the board's pid, so a crashed board cannot leave the computer held awake.
3
+ export type Awake = "off" | "auto" | "on";
4
+
5
+ export function inhibitArgv(platform = process.platform as string, pid = process.pid): string[] | null {
6
+ if (platform === "linux") return ["systemd-inhibit", "--what=idle:sleep", "--who=kaizen", "--why=Agents are running", "tail", `--pid=${pid}`, "-f", "/dev/null"];
7
+ if (platform === "darwin") return ["caffeinate", "-i", "-w", String(pid)];
8
+ return null;
9
+ }
10
+
11
+ export const wantAwake = (mode: string, agentsRunning: boolean) => mode === "on" || (mode === "auto" && agentsRunning);
12
+
13
+ export function awakeHolder(start: (argv: string[]) => { kill: () => void; exited?: Promise<unknown> } = (a) => Bun.spawn(a, { stdin: "ignore", stdout: "ignore", stderr: "ignore" }), argv = inhibitArgv()) {
14
+ let held: { kill: () => void } | null = null;
15
+ const stop = () => { held?.kill(); held = null; };
16
+ return {
17
+ stop,
18
+ held: () => !!held,
19
+ sync(want: boolean) {
20
+ if (!want) return stop();
21
+ if (held || !argv) return;
22
+ try {
23
+ const p = start(argv);
24
+ held = p;
25
+ // No systemd-inhibit session, say: next tick tries again.
26
+ p.exited?.then(() => { if (held === p) held = null; });
27
+ } catch { held = null; }
28
+ },
29
+ };
30
+ }
package/cli/look.ts ADDED
@@ -0,0 +1,33 @@
1
+ // How the installer and `kaizen setup` look: the current monochrome brand. Emphasis is
2
+ // bold, not a colour, so it follows the terminal's own theme, light or dark, as the
3
+ // board's default palette does (design.md, section 2). Green stays for success.
4
+ export const c = {
5
+ dim: (s: string) => `\x1b[2m${s}\x1b[0m`,
6
+ bold: (s: string) => `\x1b[1m${s}\x1b[0m`,
7
+ accent: (s: string) => `\x1b[1m${s}\x1b[0m`,
8
+ green: (s: string) => `\x1b[32m${s}\x1b[0m`,
9
+ };
10
+
11
+ // The pixel K of site/media/favicon.svg, drawn in half blocks so its squares stay square.
12
+ const K = ["█ ▄▀", "██ ", "█ ▀▄"];
13
+
14
+ // Compact block wordmark (27 columns x 3 rows).
15
+ export const WORDMARK = [
16
+ "█ █ ▄▀█ █ ▀▀█ █▀▀ █▄ █",
17
+ "█▀▄ █▀█ █ ▄▀ ██▄ █ ▀█",
18
+ "█ █ █ █ █ █▄▄ █▄▄ █ █",
19
+ ];
20
+
21
+ export function banner() {
22
+ return `\n${K.map((row) => ` ${c.bold(row)}`).join("\n")}\n\n ${c.bold("改善")} ${c.dim("continuous improvement")}\n`;
23
+ }
24
+
25
+ export function nextSteps() {
26
+ return `
27
+ ${c.bold("You're ready")}
28
+ 1 Restart Claude Code ${c.dim("so it picks up the new commands")}
29
+ 2 Ask for something: ${c.accent("/kaizen <what you want done>")}
30
+
31
+ ${c.dim("Change anything later:")} ${c.accent("kaizen setup")}${c.dim(". Every command:")} ${c.accent("/kaizen-help")}
32
+ `;
33
+ }
@@ -17,6 +17,7 @@ test("project tree and text preview stay inside a registered project", async ()
17
17
  symlinkSync(join(home, ".kaizen", "projects"), join(project, "link"));
18
18
  const port = 20000 + Math.floor(Math.random() * 20000);
19
19
  const repo = join(import.meta.dir, "..");
20
+ mkdirSync(join(home, ".claude"), { recursive: true }); // an agent, or `kaizen web` stops at its no-agent notice
20
21
  const proc = Bun.spawn([process.execPath, join(repo, "cli", "install.ts"), "web", "--port", String(port), "--no-open", "--foreground"], {
21
22
  cwd: project, env: { ...process.env, HOME: home, USERPROFILE: home, KAIZEN_HOME: repo }, stdout: "ignore", stderr: "ignore",
22
23
  });
package/cli/pty.test.ts CHANGED
@@ -249,7 +249,8 @@ test.skipIf(process.platform === "win32")("submit: Enter reaches the agent on it
249
249
  test("busy: on while the agent draws its working line, off once it goes quiet; other output is not work", async () => {
250
250
  const key = "busy-" + Date.now();
251
251
  startPty(key, ["sh", "-c", "for i in 1 2 3 4 5 6; do echo 'Thinking (3s · esc to interrupt)'; sleep 0.1; done; read l"], root);
252
- await Bun.sleep(250);
252
+ // ConPTY delivers the first line later than a Unix pty.
253
+ for (let i = 0; i < 30 && !ptyState(key)!.busy; i++) await Bun.sleep(50);
253
254
  expect(ptyState(key)!.busy).toBe(true);
254
255
  await Bun.sleep(1800);
255
256
  expect(ptyState(key)).toMatchObject({ alive: true, busy: false });