kaizen-agent 1.87.2 → 1.87.4

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 (76) hide show
  1. package/cli/activity.ts +86 -0
  2. package/cli/add-project.ts +64 -1
  3. package/cli/auto-update.ts +33 -0
  4. package/cli/browser.ts +21 -0
  5. package/cli/chat.ts +88 -13
  6. package/cli/chatgpt.ts +1 -1
  7. package/cli/dashboard.ts +1 -1
  8. package/cli/install.ts +65 -36
  9. package/cli/look.ts +1 -0
  10. package/cli/models.ts +94 -0
  11. package/cli/onboarding.ts +9 -4
  12. package/cli/pty.ts +27 -12
  13. package/cli/release.ts +13 -1
  14. package/cli/settings.ts +39 -7
  15. package/cli/sources.ts +84 -20
  16. package/cli/state.ts +56 -3
  17. package/cli/task-service.ts +10 -3
  18. package/cli/usage.ts +15 -2
  19. package/cli/web.ts +119 -47
  20. package/cli/whats-new.json +38 -0
  21. package/cli/whats-new.ts +43 -0
  22. package/cli/workers.ts +2 -2
  23. package/package.json +1 -1
  24. package/skills/kaizen/config.default.yml +3 -0
  25. package/skills/kaizen/spec.md +6 -0
  26. package/skills/kaizen-explore/SKILL.md +7 -0
  27. package/web/components/home/home-window.tsx +0 -36
  28. package/web/components/home/index.ts +1 -0
  29. package/web/components/home/onboarding-dialog.tsx +44 -7
  30. package/web/components/home/works-flow.tsx +119 -0
  31. package/web/components/icebox/capture-box.tsx +11 -2
  32. package/web/components/icebox/request-card.tsx +33 -11
  33. package/web/components/project/add-project-dialog.tsx +1 -1
  34. package/web/components/rail/rail-list.tsx +51 -7
  35. package/web/components/run/doc-body.tsx +43 -0
  36. package/web/components/settings/agent-rows.tsx +15 -11
  37. package/web/components/settings/browser-row.tsx +1 -1
  38. package/web/components/settings/setting-row.tsx +10 -6
  39. package/web/components/settings/settings-section.tsx +5 -3
  40. package/web/components/settings/skill-card.tsx +32 -2
  41. package/web/components/settings/update-bar.tsx +53 -35
  42. package/web/components/settings/whats-new-card.tsx +70 -0
  43. package/web/components/shared/picker.tsx +21 -1
  44. package/web/components/shell/rail.tsx +8 -4
  45. package/web/dist/annotate.js +1 -1
  46. package/web/dist/board.css +6 -11
  47. package/web/dist/board.js +83 -56
  48. package/web/dist/boot.js +1 -1
  49. package/web/dist/notebook.css +2 -2
  50. package/web/dist/notebook.js +34 -34
  51. package/web/dist/popup.css +1 -1
  52. package/web/dist/popup.js +1 -1
  53. package/web/dist/term.js +1 -1
  54. package/web/dist/ui.css +2 -2
  55. package/web/dist/video.js +1 -1
  56. package/web/lib/footer/footer-rules.ts +8 -2
  57. package/web/lib/footer/footer-store.ts +2 -2
  58. package/web/lib/home/onboarding.ts +63 -17
  59. package/web/lib/icebox/icebox-actions.ts +24 -2
  60. package/web/lib/icebox/icebox-store.ts +7 -1
  61. package/web/lib/icebox/icebox-view.ts +3 -2
  62. package/web/lib/icebox/icebox.ts +24 -4
  63. package/web/lib/icebox/use-ice-keys.ts +5 -0
  64. package/web/lib/project/add-project.ts +6 -0
  65. package/web/lib/rail/rules.ts +4 -1
  66. package/web/lib/run/panel-derive.ts +1 -1
  67. package/web/lib/run/panel-store.ts +1 -0
  68. package/web/lib/settings/index.ts +2 -0
  69. package/web/lib/settings/settings-actions.ts +8 -0
  70. package/web/lib/settings/settings.ts +6 -4
  71. package/web/lib/settings/use-model-choices.ts +31 -0
  72. package/web/lib/settings/whats-new.ts +36 -0
  73. package/web/pages/board/App.tsx +3 -10
  74. package/web/pages/icebox-page.tsx +173 -125
  75. package/web/pages/task-page.tsx +17 -4
  76. package/web/ui/legacy/board.css +4 -9
package/cli/state.ts CHANGED
@@ -10,6 +10,7 @@ import { join, dirname, sep, win32, posix } from "node:path";
10
10
  import { homedir, arch, cpus, release, totalmem, version as osVersion } from "node:os";
11
11
  import { startPty, ptySupported, killTmux, tmuxName } from "./pty.ts";
12
12
  import { codeDir, projectFromWorktree, wsOf } from "./worktree.ts";
13
+ import { activityMtime } from "./activity.ts";
13
14
 
14
15
  // The real path: process.cwd() is always physical, so a raw $HOME that crosses a
15
16
  // symlink (/home -> var/home) would never compare equal to it.
@@ -96,6 +97,52 @@ export const YOLO_FLAGS: Record<string, string[]> = {
96
97
  codex: ["--dangerously-bypass-approvals-and-sandbox"], gemini: ["--yolo"], opencode: ["--auto"],
97
98
  };
98
99
 
100
+ // The folder that holds kaizen's skills as Claude Code reads them: the real path of the global `kaizen` skill link, one level up
101
+ // (the clone's `skills/`). null when kaizen is not linked there. Only this folder is added to a launch, not the home folder.
102
+ export function skillsReadDir(home = homedir()): string | null {
103
+ try { return dirname(realpathSync(join(home, ".claude", "skills", "kaizen"))); } catch { return null; }
104
+ }
105
+
106
+ // What a bypass (Yolo) launch of `cmd` passes: its skip-everything flag, and for Claude Code also the acceptance of its own first-run
107
+ // "Bypass Permissions mode" warning (No, exit is its default), which a board user would never see. The user chose Yolo here, so the launch
108
+ // accepts it from a settings file for this launch only, not by editing the user's own Claude settings. Every place that starts an agent in
109
+ // bypass (a run, a worker, a board terminal) uses this.
110
+ export function bypassFlags(cmd: string): string[] {
111
+ const accepted = cmd === "claude" ? bypassAcceptedFile() : null;
112
+ return [...(YOLO_FLAGS[cmd] ?? []), ...(accepted ? ["--settings", accepted] : [])];
113
+ }
114
+
115
+ // A settings file that only says the bypass-mode warning is accepted, for `claude --settings` on a Yolo launch. Lives in kaizen's own
116
+ // folder; null if it cannot be written (Claude then asks, as before).
117
+ export function bypassAcceptedFile(home = homedir()): string | null {
118
+ try {
119
+ const f = join(home, ".kaizen", "claude-bypass.json");
120
+ if (!existsSync(f)) { mkdirSync(dirname(f), { recursive: true }); writeFileSync(f, JSON.stringify({ skipDangerousModePermissionPrompt: true }) + "\n"); }
121
+ return f;
122
+ } catch { return null; }
123
+ }
124
+
125
+ // The settings file for a run launch of Claude Code: the hooks that report every tool call to cli/activity.ts (live build activity on the
126
+ // board), and for a Yolo launch also the acceptance of the bypass-mode warning. Claude takes one --settings, so both ride in one file.
127
+ // Written when missing or when its text changed (a moved checkout, another bun). null if it cannot be written: the run then starts
128
+ // without the feed, as before. ponytail: the command is a POSIX-quoted line; Windows hook shells may need another form.
129
+ export function runHooksFile(yolo: boolean, home = homedir()): string | null {
130
+ try {
131
+ const cmd = `${shq(process.execPath)} ${shq(join(import.meta.dir, "activity.ts"))}`;
132
+ const hook = (matcher: string) => [{ matcher, hooks: [{ type: "command", command: cmd, timeout: 5 }] }];
133
+ const text = JSON.stringify({ hooks: { PreToolUse: hook("*"), PostToolUse: hook("Bash") }, ...(yolo ? { skipDangerousModePermissionPrompt: true } : {}) }) + "\n";
134
+ const f = join(home, ".kaizen", yolo ? "claude-run-hooks-bypass.json" : "claude-run-hooks.json");
135
+ if (!existsSync(f) || readFileSync(f, "utf8") !== text) { mkdirSync(dirname(f), { recursive: true }); writeFileSync(f, text); }
136
+ return f;
137
+ } catch { return null; }
138
+ }
139
+ // What a run launch passes for its settings: Claude gets the hooks file (bypass flags without their own --settings when Yolo).
140
+ export function runSettingsFlags(cmd: string, yolo: boolean, home = homedir()): string[] {
141
+ if (cmd !== "claude") return yolo ? bypassFlags(cmd) : [];
142
+ const f = runHooksFile(yolo, home);
143
+ return f ? [...(yolo ? YOLO_FLAGS[cmd] ?? [] : []), "--settings", f] : yolo ? bypassFlags(cmd) : [];
144
+ }
145
+
99
146
  // How each tool takes the opening prompt and stays interactive. agy refuses a bare
100
147
  // argument and exits; opencode reads one as the project folder to open.
101
148
  const PROMPT_FLAGS: Record<string, string[]> = { agy: ["-i"], opencode: ["--prompt"] };
@@ -511,6 +558,8 @@ export function readRuns(state: string): Run[] {
511
558
  let moved = 0;
512
559
  try { moved = statSync(file).mtimeMs; } catch { /* vanished mid-read */ }
513
560
  try { moved = Math.max(moved, statSync(join(dir, id, "progress.md")).mtimeMs); } catch { /* no progress kept */ }
561
+ // And the agent's own tool calls (cli/activity.ts): the surest sign that it is working.
562
+ moved = Math.max(moved, activityMtime(state, s.session));
514
563
  // Done without the user's acceptance is not done: every reader sees it waiting on approval.
515
564
  const unapproved = s.stage === "done" && accepted(state, id).accept === "needs";
516
565
  const run = { id, iteration: Number(s.iteration) || 0, stage: unapproved ? "review" : s.stage ?? "?", awaiting: unapproved ? "approvals.review" : s.awaiting ?? null, moved, runner: s.runner, agent: s.agent, branch: typeof s.branch === "string" ? s.branch : undefined, worktree: typeof s.worktree === "string" ? s.worktree : undefined, workspace: typeof s.workspace === "string" ? s.workspace : undefined, healed: unapproved || (s.healed === true && s.awaiting === "approvals.review") || undefined };
@@ -565,9 +614,9 @@ export function backlog(state: string) {
565
614
  export function version(repo: string) {
566
615
  try { return JSON.parse(readText(join(repo, "package.json"))).version; } catch { return ""; }
567
616
  }
568
- // The global state directory is not a project and has no parent worth naming.
617
+ // The global state directory is not a project: it is Home, your own space.
569
618
  export function label(stateDir: string) {
570
- return stateDir === join(home, ".kaizen") ? "no project" : tilde(dirname(stateDir));
619
+ return stateDir === join(home, ".kaizen") ? "Home" : tilde(dirname(stateDir));
571
620
  }
572
621
 
573
622
  export function tilde(p: string) { return p.startsWith(home) ? "~" + p.slice(home.length) : p; }
@@ -1854,7 +1903,11 @@ export function launchRun(it: Item, from: string, run?: string, pick: { agent?:
1854
1903
  const wasYolo = yoloRecs.some((s) => ownerOf(st, s, idx) === run);
1855
1904
  // Settings' bypass takes the same road, so the session record and the card's mark follow.
1856
1905
  const yolo = (wasYolo || (!!pick.yolo && agent.cmd === pick.agent) || prefersBypass(agent.cmd, prefs)) && !!YOLO_FLAGS[agent.cmd];
1857
- const flags = [...agentFlags(projectDir, agent.cmd, undefined, model), ...(yolo ? YOLO_FLAGS[agent.cmd] : []), ...argsOf(agent.cmd, prefs)];
1906
+ // Claude reads kaizen's skill files (spec.md and the others) from the folder its global link points at, outside every project, and
1907
+ // would stop on a read prompt for each run; with that folder added it does not. `--` ends the flags, because --add-dir takes a list
1908
+ // and would otherwise swallow the prompt that follows as one more folder.
1909
+ const skills = agent.cmd === "claude" && prompt ? skillsReadDir() : null;
1910
+ const flags = [...agentFlags(projectDir, agent.cmd, undefined, model), ...runSettingsFlags(agent.cmd, yolo), ...argsOf(agent.cmd, prefs), ...(skills ? [`--add-dir=${skills}`, "--"] : [])];
1858
1911
  // The task as its run's request will hold it: without the runner word in front.
1859
1912
  // Session lookups read the tool's folder from the environment; for this launch it's the account's.
1860
1913
  const prior = acct.envVar ? process.env[acct.envVar] : undefined;
@@ -14,6 +14,11 @@ type Hooks = { launch: (state:string, run:string, text:string, task:T.Task, pick
14
14
  // The agent stopped on a permission/choice prompt, and the user's yes or no typed into it.
15
15
  asking?:(pty:string)=>boolean; idle?:(pty:string)=>number; answer?:(pty:string,yes:boolean)=>void };
16
16
  export const HUNG_MS=5*60_000;
17
+ // A run left at review with nothing awaited, its result published and its agent quiet this long (or gone), is over:
18
+ // Looks good comes back and finishes it as the review approval. While the agent prints, the review is still running.
19
+ export const QUIET_MS=2*60_000;
20
+ const leftInReview=(run:any,task:T.Task,key:string|undefined,hooks?:Hooks)=>run.stage==='review'&&!run.awaiting&&!!task.currentResult
21
+ &&(!key||!hooks?.alive(key)||(hooks.idle?.(key)??0)>=QUIET_MS);
17
22
  const runtimeLaunches = new Set<string>();
18
23
  const parse = (file:string) => { try { return JSON.parse(readFileSync(file,'utf8')); } catch { return null; } };
19
24
  const put = (file:string,value:unknown) => { const temp = file + `.${process.pid}.${randomUUID()}.tmp`; writeFileSync(temp,JSON.stringify(value,null,2)+'\n'); renameSync(temp,file); };
@@ -31,8 +36,8 @@ export function allowedActions(state:string,task:T.Task,hooks?:Hooks) {
31
36
  let accept=false,acceptWhy:string|undefined;
32
37
  try{T.acceptTask(structuredClone(task),task.currentResult??'');accept=true;}catch{/* not acceptable now */}
33
38
  // Looks good on a run that waits for its review approval (or open findings) is that approval: it is sent to the run.
34
- const approvable=!!run&&!run.healed&&['approvals.review','findings'].includes(run.awaiting)&&!!hooks?.approve;
35
- if(accept&&run&&!finished&&!approvable){accept=false;acceptWhy=run.awaiting?'Resolve the blocking workflow decision first.':'The workflow is still reviewing this result';}
39
+ const approvable=!!run&&!run.healed&&(['approvals.review','findings'].includes(run.awaiting)||leftInReview(run,task,key,hooks))&&!!hooks?.approve;
40
+ if(accept&&run&&!finished&&!approvable){accept=false;acceptWhy=run.awaiting?'Resolve the blocking workflow decision first.':run.stage==='review'&&task.currentResult?'The workflow is still reviewing this result. Looks good appears once the agent has been quiet for two minutes.':'The workflow is still reviewing this result';}
36
41
  return {accept,...(acceptWhy?{acceptWhy}:{}),
37
42
  stop:(live&&['draft','waiting','working','ready'].includes(task.status))||(['failed','interrupted','working'].includes(task.status)&&alive),
38
43
  // A ready task whose run is still in review but whose agent is gone can only finish by relaunching it.
@@ -152,8 +157,10 @@ export function taskAction(state:string,body:any,hooks:Hooks):{state:string;task
152
157
  }else{t.status='interrupted';t.error='This earlier run has no typed result or Preview output. Its files and evidence remain in Technical details. Resume to publish a result.';}
153
158
  }else{
154
159
  const plan=readTextSafe(join(state,'runs',l.id,'01-plan.md'));
160
+ const exploreBrief=readTextSafe(join(state,'runs',l.id,'00-explore.md'));
155
161
  put(file,{...run,task_id:t.id,task_policy:{requirePlanConfirmation:run.awaiting==='approvals.plan'}});
156
162
  if(run.awaiting==='approvals.plan'&&plan){t.pendingDecision={id:randomUUID(),kind:'proposal',text:'Review the existing plan before production continues.',details:plan,run:l.id,iteration:run.iteration??0,result:null};t.status='waiting';t.safe=true;}
163
+ else if(run.awaiting==='explore'&&exploreBrief){t.pendingDecision={id:randomUUID(),kind:'question',text:'Explore finished. Continue to Plan, or explore further?',details:exploreBrief,options:['Continue to Plan','Explore further'],run:l.id,iteration:run.iteration??0,result:null};t.status='waiting';t.safe=true;}
157
164
  else{t.status='interrupted';t.error='Existing work is preserved. Review its current session in Technical details before resuming.';}
158
165
  }
159
166
  });
@@ -206,7 +213,7 @@ export function taskAction(state:string,body:any,hooks:Hooks):{state:string;task
206
213
  const run=runState(state,t);
207
214
  if(run&&t.activeRun){
208
215
  if(run.healed||run.stage==='done'){if(gateOf(state,t.activeRun)==='needs'){const why=recordAcceptance(state,t.activeRun,'board');if(why)throw new T.TaskError(why,409);}if(run.healed){const why=finishRun(state,t.activeRun);if(why)throw new T.TaskError(why,409);}}
209
- else if(['approvals.review','findings'].includes(run.awaiting)){const why=hooks.approve?hooks.approve(state,t.activeRun,run.awaiting):'This board cannot approve the run';if(why)throw new T.TaskError(why,409);}
216
+ else if(['approvals.review','findings'].includes(run.awaiting)||run.stage==='review'){const why=hooks.approve?hooks.approve(state,t.activeRun,run.awaiting||'approvals.review'):'This board cannot approve the run';if(why)throw new T.TaskError(why,409);}
210
217
  }
211
218
  T.acceptTask(t,String(body.resultId??''));
212
219
  }else if(op==='confirm'){
package/cli/usage.ts CHANGED
@@ -58,14 +58,27 @@ export async function claudeUsageAt(dir: string, get: typeof fetch = fetch): Pro
58
58
  }
59
59
  }
60
60
 
61
+ // A phone's name: iOS reports its hostname as "localhost", so it comes from the DNS name ("iphone-11-1" -> "iPhone 11").
62
+ // ponytail: a lone trailing "-<digit>" is taken as Tailscale's duplicate suffix, so "iphone-8" reads "iPhone"; use the
63
+ // admin API's device name if that matters.
64
+ export function phoneName(p: any): string {
65
+ const host = String(p?.HostName ?? "");
66
+ if (host && host !== "localhost") return host;
67
+ const label = String(p?.DNSName ?? "").split(".")[0].replace(/-\d$/, "");
68
+ return label.split("-").filter(Boolean).map((w) => (w === "iphone" ? "iPhone" : w[0].toUpperCase() + w.slice(1))).join(" ") || host;
69
+ }
70
+
61
71
  // Phones on the tailnet from `tailscale status --json`: iOS and Android peers.
62
72
  export type Computer = { name: string; dns: string; os: string; online: boolean };
63
- export function phonePeers(json: string): { running: boolean; phones: { name: string; online: boolean }[]; computers: Computer[]; self: Computer | null } {
73
+ export function phonePeers(json: string): { running: boolean; phones: { name: string; os: string; online: boolean }[]; computers: Computer[]; self: Computer | null } {
64
74
  try {
65
75
  const s = JSON.parse(json);
66
76
  const peers = Object.values<any>(s?.Peer ?? {});
67
77
  const isPhone = (p) => /^(ios|android)$/i.test(p?.OS ?? "");
68
- const phones = peers.filter(isPhone).map((p) => ({ name: String(p.HostName ?? p.DNSName ?? ""), online: !!p.Online }));
78
+ // Your own phones when you have one: a phone another account shared onto the tailnet is not yours.
79
+ const all = peers.filter(isPhone);
80
+ const own = all.filter((p) => s?.Self?.UserID != null && p.UserID === s.Self.UserID);
81
+ const phones = (own.length ? own : all).map((p) => ({ name: phoneName(p), os: String(p.OS), online: !!p.Online }));
69
82
  // The other computers on the tailnet: the phone's Home lists them, a tap opens their board.
70
83
  const comp = (p, online = !!p.Online): Computer => ({ name: String(p.HostName ?? ""), dns: String(p.DNSName ?? "").replace(/\.$/, ""), os: String(p.OS ?? ""), online });
71
84
  const computers = peers.filter((p) => p?.OS && !isPhone(p)).map((p) => comp(p));
package/cli/web.ts CHANGED
@@ -17,7 +17,7 @@ import { MAX_FILE, MAX_IMAGE, saveFile, saveImage } from "./term-image.ts";
17
17
  import { shellHistory } from "./term-history.ts";
18
18
  import { bundledSkills, repairSkill, setSkill, skillsHeld, skillsOff, skillStatus } from "./skills.ts";
19
19
  import * as rea from "./rea.ts";
20
- import { accountEnv, accountForRun, agentUsable, CHILD_ENV, promptArgs, heartbeatMinutes, keepAwake, launchPreview, trustFolder, YOLO_FLAGS } from "./state.ts";
20
+ import { accountEnv, accountForRun, agentUsable, CHILD_ENV, detectDefaultAgent, promptArgs, heartbeatMinutes, keepAwake, launchPreview, trustFolder, YOLO_FLAGS, bypassFlags } from "./state.ts";
21
21
  import { agentLine, failStart, handoffModel, markRunning, readWorkers, requested, startWorker, sweep, workerStale } from "./workers.ts";
22
22
  import { childDied, childQuiet, markWoken, move, requestOpen, readHandoff, refused, started, wakeAction, wakeLine, type Handoff } from "./handoff.ts";
23
23
  import { processTable, storage, systemMemory, treeRss, type Root } from "./resources.ts";
@@ -25,9 +25,12 @@ import { attachPty, frames, writePty, submitPty, resizePty, exitPty, killPty, pa
25
25
  import { conflictPort, holders, inProjects, isKaizenProcess, listeners, stopPort } from "./ports.ts";
26
26
  import { snapshot, snapWorker } from "./state-snap.ts";
27
27
  import { claudeUsage, claudeUsageAt, codexUsage, codexUsageAt, phonePeers, type Usage } from "./usage.ts";
28
- import { readSources, addSource, removeSource, moveSource, setCategory, setWriteback, setPaused, readIcebox, applySort, promote, dismiss, restore, capture, editItem, setKind, setTags, setBoard, saveBoard, removeBoard, snooze, unsnooze, readBoards, kindOf, isSnoozed, markDone, markReplied, gatherSource, freshImages, gatherAll, gatherDirs, due, socialUrl, socialOf } from "./sources.ts";
28
+ import { readSources, addSource, removeSource, moveSource, setCategory, setWriteback, setPaused, readIcebox, applySort, setLinkMedia, redditPost, iceDir, promote, dismiss, restore, capture, editItem, setKind, setTags, setBoard, saveBoard, removeBoard, snooze, unsnooze, readBoards, kindOf, isSnoozed, markDone, markReplied, gatherSource, freshImages, gatherAll, gatherDirs, due, socialUrl, socialOf } from "./sources.ts";
29
29
  import { projectLogo, LOGO_TYPES } from "./logo.ts";
30
30
  import * as chatgpt from "./chatgpt.ts";
31
+ import { whatsNew, markSeen } from "./whats-new.ts";
32
+ import { autoUpdateTick } from "./auto-update.ts";
33
+ import { readActivity } from "./activity.ts";
31
34
  import * as google from "./google.ts";
32
35
  import { writeBacks } from "./writeback.ts";
33
36
  import { postLink, sendReply } from "./browser.ts";
@@ -45,7 +48,7 @@ import { workspaces, workspacesNow, forgetWorkspaces, workspacesAge, addWorktree
45
48
  import * as tasks from "./tasks.ts";
46
49
  import * as taskService from "./task-service.ts";
47
50
  import { artifactResponse as taskArtifactResponse } from "./task-results.ts";
48
- import { gitUrl, destDir, winBad, cloneInto, branchesOf, ignoreKaizen } from "./add-project.ts";
51
+ import { gitUrl, destDir, winBad, cloneInto, branchesOf, ignoreKaizen, writePointer } from "./add-project.ts";
49
52
 
50
53
  const PAGE = join(dirname(import.meta.dir), "web", "html", "board.html");
51
54
  // The board's script: web/pages/board/main.ts with web/lib and web/components, bundled into one file by `bun run build:web`.
@@ -60,6 +63,8 @@ const NOTES_JS = join(dirname(import.meta.dir), "web", "dist", "notebook.js");
60
63
  const TERM_JS = join(dirname(import.meta.dir), "web", "dist", "term.js");
61
64
  const ANNOTATE_JS = join(dirname(import.meta.dir), "web", "dist", "annotate.js");
62
65
  const TERM_CSS = join(dirname(import.meta.dir), "web", "dist", "term.css");
66
+ // A project added from the board gets the kaizen note (what plain chat offers), as `kaizen init` writes it; a folder that cannot be written still adds.
67
+ const notePointer = (dir: string) => { try { writePointer(dir, KNOWN_AGENTS.filter((a) => agentUsable(a.cmd)).map((a) => a.cmd)); } catch { /* the project still works */ } };
63
68
  // The Video page (kaizen-video's library, editor and renders) and its bundle.
64
69
  const VIDEO_PAGE = join(dirname(import.meta.dir), "web", "html", "video.html");
65
70
  const POPUP_PAGE = join(dirname(import.meta.dir), "web", "html", "popup.html");
@@ -279,6 +284,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
279
284
  // A failed git init leaves a project without a repository: said, not rolled back.
280
285
  const inited = git ? run(["git", "init", "-q", "--", to], to).ok : undefined;
281
286
  if (inited) try { ignoreKaizen(to); } catch { /* the project still works */ }
287
+ notePointer(to);
282
288
  remember(to);
283
289
  changed();
284
290
  return { dir: join(to, ".kaizen"), ...(git ? { git: inited } : {}) };
@@ -677,7 +683,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
677
683
  const fingerprint = () => {
678
684
  let sum = 0;
679
685
  for (const dir of states(true)) {
680
- for (const f of ["inbox.md", "backlog.md", "archive.md", "sources.json", "icebox.json"]) { try { sum += statSync(join(dir, f)).mtimeMs; } catch { /* absent */ } }
686
+ for (const f of ["inbox.md", "backlog.md", "archive.md", "sources.json", "icebox.json", "boards.json"]) { try { sum += statSync(join(f.endsWith(".json") ? iceDir(dir) : dir, f)).mtimeMs; } catch { /* absent */ } }
681
687
  const runs = join(dir, "runs");
682
688
  if (!existsSync(runs)) continue;
683
689
  for (const id of readdirSync(runs)) { try { sum += statSync(join(runs, id, "state.json")).mtimeMs; } catch { /* absent */ } }
@@ -715,6 +721,19 @@ export async function web(repoDir: string, opts: Opts = {}) {
715
721
  const next = (sorting.get(dir) ?? Promise.resolve()).then(run, run).catch((e) => console.error("[icebox] sort", e));
716
722
  sorting.set(dir, next);
717
723
  };
724
+ // A Reddit link's own pictures, read by the kaizen browser after the capture is saved (it takes seconds and may
725
+ // be busy gathering). One browser at a time; a failure leaves the card on Reddit's preview picture.
726
+ let reading: Promise<unknown> = Promise.resolve();
727
+ const mediaLater = (dir: string, id: string) => {
728
+ const run = async () => {
729
+ const it = readIcebox(dir).find((x) => x.id === id);
730
+ if (!it?.link || !redditPost(it.link.url)) return;
731
+ const r = await (await import("./browser.ts")).redditMedia(it.link.url);
732
+ if (r.ok && setLinkMedia(dir, id, r)) changed();
733
+ else if (!r.ok) console.error(`[icebox] pictures ${id}: ${r.note}`);
734
+ };
735
+ reading = reading.then(run, run).catch((e) => console.error("[icebox] pictures", e));
736
+ };
718
737
  const setting = async (key: string) => {
719
738
  const { listSettings } = await import("./settings.ts");
720
739
  return listSettings(repoDir).rows.find((r) => r.key === key)?.value ?? "";
@@ -755,6 +774,59 @@ export async function web(repoDir: string, opts: Opts = {}) {
755
774
 
756
775
  // Automations: a due rule starts a run in its own project. Own busy flag; a fire may wait on a precheck.
757
776
  let autoBusy = false;
777
+ // `kaizen upgrade`, then a new board on this port. The Update button and the automatic update (below) both run it.
778
+ const runUpgrade = async (): Promise<{ ok: true; version?: string } | { error: string; status: number }> => {
779
+ if (upgrading) return { error: "an upgrade is already running", status: 409 };
780
+ if (DESKTOP_BUNDLED) return { error: "this board is the desktop app's copy; the app updates itself", status: 409 };
781
+ // Windows will not rename ~/kaizen while this board holds files in it, so the
782
+ // upgrade waits in its own process for this one to exit, then starts the board
783
+ // again; ~/.kaizen/upgrade.log keeps what it said. It runs from a copy of cli/,
784
+ // so nothing runs out of ~/kaizen while it is renamed.
785
+ if (process.platform === "win32") {
786
+ const helper = join(home, ".kaizen", "upgrader");
787
+ rmSync(helper, { recursive: true, force: true });
788
+ cpSync(join(repoDir, "cli"), join(helper, "cli"), { recursive: true });
789
+ const log = Bun.file(UPGRADE_LOG);
790
+ Bun.spawn([process.execPath, join(helper, "cli", "install.ts"), "upgrade", "--wait", String(process.pid), "--restart", String(srv.port)], {
791
+ cwd: home, detached: true, stdio: ["ignore", log, log], windowsHide: true,
792
+ }).unref();
793
+ saveLive();
794
+ setTimeout(() => process.exit(0), 300);
795
+ return { ok: true as const };
796
+ }
797
+ upgrading = true;
798
+ try {
799
+ const p = Bun.spawn([process.execPath, join(repoDir, "cli", "install.ts"), "upgrade"], { stdin: "ignore", stdout: "pipe", stderr: "pipe", windowsHide: true });
800
+ const [out, err, code] = await Promise.all([new Response(p.stdout).text(), new Response(p.stderr).text(), p.exited]);
801
+ const why = (out + err).replace(/\x1b\[[0-9;]*m/g, "").split("\n").map((l) => l.trim()).filter((l) => l && !l.startsWith("+")).slice(-2).join(" — ");
802
+ if (code !== 0) return { error: why || `kaizen upgrade exited ${code}`, status: 500 };
803
+ if (installed() === VERSION) return { error: why || "Already up to date", status: 400 };
804
+ const port = srv.port;
805
+ saveLive();
806
+ setTimeout(() => {
807
+ Bun.spawn([process.execPath, join(repoDir, "cli", "install.ts"), "web", "--port", String(port), "--no-open", "--foreground"], {
808
+ detached: true, stdio: ["ignore", "ignore", "ignore"], windowsHide: true,
809
+ }).unref();
810
+ }, 300);
811
+ return { ok: true as const, version: installed() };
812
+ } finally { upgrading = false; }
813
+
814
+ };
815
+ // Update automatically (Settings → General → Updates): every 30 minutes, and once shortly after the board starts, when the switch is
816
+ // on, npm has a newer version, no terminal is alive and no board page is open (an update restarts the board).
817
+ const autoUpd = () => autoUpdateTick({
818
+ on: async () => (await setting("board.auto_update")) === "true",
819
+ latest: () => npmLatest(),
820
+ newer: (v) => newer(v, VERSION),
821
+ desktop: DESKTOP_BUNDLED,
822
+ upgrading: () => upgrading,
823
+ terminalsAlive: () => ptyKeys().some((k) => ptyState(k)?.alive),
824
+ pagesOpen: () => clients.size > 0,
825
+ upgrade: runUpgrade,
826
+ }).catch(() => "off" as const); // the next tick tries again
827
+ const autoUpdate = setInterval(autoUpd, 30 * 60_000);
828
+ const autoFirst = setTimeout(autoUpd, 90_000);
829
+
758
830
  const automate = setInterval(async () => {
759
831
  if (autoBusy) return;
760
832
  autoBusy = true;
@@ -1093,6 +1165,8 @@ export async function web(repoDir: string, opts: Opts = {}) {
1093
1165
  let body: any;
1094
1166
  try { body = await req.json(); } catch { return bad("json body expected"); }
1095
1167
  // Home: kaizen's own folder, the one place outside a project. No worktree, dev server or run to resume there.
1168
+ // The side menu's Home row is the global queue (~/.kaizen) as a workspace: a shell from it is a Home shell.
1169
+ if (body.home !== true && typeof body.dir === "string" && canonState(body.dir) === join(home, ".kaizen") && body.dev !== true && body.resume !== true) { body.home = true; delete body.ws; }
1096
1170
  const homeWs = body.home === true;
1097
1171
  if (homeWs && (body.ws != null || body.dev === true || body.resume === true)) return bad("not in the Home workspace", 400);
1098
1172
  const dir = homeWs ? HOME_WS : canonState(String(body.dir ?? ""));
@@ -1144,7 +1218,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
1144
1218
  // A first message for the agent (the Storage panel's Cleanup: "/disk-cleanup"), passed as its
1145
1219
  // argument the way a run's prompt is (promptArgs), never through a shell.
1146
1220
  const first = !signIn && typeof body.prompt === "string" && body.prompt.trim() && body.prompt.length <= 2000 ? body.prompt.trim() : "";
1147
- const line = signIn ? [commandOf(a.cmd), ...(a.cmd === "codex" ? ["login"] : [])] : withEnv([commandOf(a.cmd), ...(bypass ? YOLO_FLAGS[a.cmd]! : []), ...argsOf(a.cmd), ...promptArgs(a.cmd, first)], a.cmd);
1221
+ const line = signIn ? [commandOf(a.cmd), ...(a.cmd === "codex" ? ["login"] : [])] : withEnv([commandOf(a.cmd), ...(bypass ? bypassFlags(a.cmd) : []), ...argsOf(a.cmd), ...promptArgs(a.cmd, first)], a.cmd);
1148
1222
  cmd = acct.dir ? ["env", ...accountEnv(acct), ...line] : line;
1149
1223
  }
1150
1224
  // A workspace folder: only an exact path from this project's own `git worktree list`.
@@ -1267,6 +1341,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
1267
1341
  const already = knownProjects().includes(d.dir);
1268
1342
  try { mkdirSync(join(d.dir, ".kaizen"), { recursive: true }); }
1269
1343
  catch (e) { return bad(`could not set up ${d.dir}: ${(e as Error).message}`); }
1344
+ notePointer(d.dir);
1270
1345
  remember(d.dir);
1271
1346
  changed();
1272
1347
  return json({ ok: true, dir: join(d.dir, ".kaizen"), already });
@@ -1285,6 +1360,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
1285
1360
  const c = await cloneInto(g.url, to);
1286
1361
  if (!c.ok) return bad(c.why, 500);
1287
1362
  mkdirSync(join(to, ".kaizen"), { recursive: true });
1363
+ notePointer(to);
1288
1364
  remember(to);
1289
1365
  changed();
1290
1366
  return json({ ok: true, dir: join(to, ".kaizen") });
@@ -1491,7 +1567,8 @@ export async function web(repoDir: string, opts: Opts = {}) {
1491
1567
  const out: Usage[] = [];
1492
1568
  if (onPath("claude")) { const u = await claudeUsage(home); if (u) out.push(u); }
1493
1569
  if (onPath("codex")) { const u = codexUsage(home); if (u) out.push(u); }
1494
- usageCache = out;
1570
+ // A rate-limit or network error keeps the last good reading instead of blanking the chip.
1571
+ usageCache = out.map((u) => (u.error ? usageCache.find((o) => o.agent === u.agent && !o.error) ?? u : u));
1495
1572
  usageAt = Date.now();
1496
1573
  }
1497
1574
  return json(usageCache);
@@ -1532,7 +1609,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
1532
1609
  await p.exited;
1533
1610
  } catch { return json({ tailscale: false }); }
1534
1611
  const r = phonePeers(out);
1535
- return json({ tailscale: r.running, phones: r.phones.length, online: r.phones.some((x) => x.online), self: r.self, computers: r.computers });
1612
+ return json({ tailscale: r.running, phones: r.phones.length, online: r.phones.some((x) => x.online), devices: r.phones.filter((x) => x.online), self: r.self, computers: r.computers });
1536
1613
  }
1537
1614
 
1538
1615
  // Every note of one project, text included: search, tags and backlinks are the page's.
@@ -1643,7 +1720,8 @@ export async function web(repoDir: string, opts: Opts = {}) {
1643
1720
  const inside = fold(root.endsWith(sep) ? root : root + sep);
1644
1721
  const picker = states(true).filter((d) => {
1645
1722
  const p = dirname(d);
1646
- return !root || d === state || (fold(p).startsWith(inside)
1723
+ // Home (the global queue) is always listed: it is your own icebox and tasks, in no project.
1724
+ return !root || d === state || d === join(home, ".kaizen") || (fold(p).startsWith(inside)
1647
1725
  && (!isGroup(p) || filled(d) || fold(dirname(p)) !== fold(root)));
1648
1726
  });
1649
1727
  // What an agent printed goes only to a viewer on this machine, not to a tailnet host or a phone.
@@ -1683,12 +1761,13 @@ export async function web(repoDir: string, opts: Opts = {}) {
1683
1761
  cards.forEach((c, i) => { for (const k of ptys[i]?.all ?? []) addAgent(k, c.state, c.ws, pty.cmd(k) ?? KNOWN_AGENTS.find((a) => c.tags?.includes(a.cmd))?.cmd, c.kind === "run" ? c.id : undefined); });
1684
1762
  // A failed land marks the run's agents, and the terminal that ran it (often the first agent, in another workspace).
1685
1763
  for (const c of cards) if (c.land) for (const a of agents) if ((a.dir === c.state && a.run === c.id) || a.key === c.land.term) a.land = c.land.kind;
1686
- const entry = (d: string) => ({ dir: d, label: label(d), logo: !!projectLogo(d),
1764
+ const entry = (d: string) => ({ dir: d, label: label(d), logo: !!projectLogo(d), ...(d === join(home, ".kaizen") ? { home: true } : {}),
1687
1765
  workspaces: d === join(home, ".kaizen") ? [{ path: d, branch: "", main: true }] : workspacesNow(projectOf(d)) });
1688
1766
  const body = JSON.stringify({
1689
1767
  project, all, dir: state,
1690
1768
  // Each project's workspaces (git worktrees, or the one folder); the global queue is its own one.
1691
- projects: picker.map(entry),
1769
+ // Home first: every picker on the page lists it above the projects.
1770
+ projects: picker.map(entry).sort((a, b) => +!!b.home - +!!a.home),
1692
1771
  // Dirs with a card the picker leaves out (the global queue, a project outside the
1693
1772
  // Projects folder): the rail still needs their workspaces so a waiting run shows.
1694
1773
  rail: [...new Set(cards.map((c) => c.state))].filter((d) => !picker.includes(d)).map(entry),
@@ -1726,6 +1805,8 @@ export async function web(repoDir: string, opts: Opts = {}) {
1726
1805
  request: read("00-request.md"), explore: read("00-explore.md"), plan: read("01-plan.md"), approval: read("02-approval.md"),
1727
1806
  impl: read("03-impl.md"), review: read("04-review.md"), backlog: read("06-backlog.md"),
1728
1807
  notes: read("notes.md"), progress: read("progress.md"),
1808
+ // What the agent is doing right now, from its own hooks (cli/activity.ts); empty for any other agent.
1809
+ activity: readActivity(dir, (() => { try { return JSON.parse(readText(join(base, "state.json"))).session; } catch { return null; } })()),
1729
1810
  // Notebook notes whose [[run:…]] links name this run.
1730
1811
  linkedFrom: linksTo(dir, id),
1731
1812
  // Nothing to pick in the global state dir: /fix refuses it.
@@ -1783,7 +1864,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
1783
1864
  }
1784
1865
  const projects = states(true).filter((d) => d !== join(home, ".kaizen")).length;
1785
1866
  const ch = agentChoices(repoDir);
1786
- return json({ ...onboardingView(home, projects), default: ch.default, installed: ch.agents.map((a) => a.cmd), agents: KNOWN_AGENTS.map((a) => ({ cmd: a.cmd, name: a.name })), install: installHelp(process.platform === "win32") });
1867
+ return json({ ...onboardingView(home, projects), preset: (await setting("preset")) || "medium", default: ch.default, installed: ch.agents.map((a) => a.cmd), agents: KNOWN_AGENTS.map((a) => ({ cmd: a.cmd, name: a.name })), install: installHelp(process.platform === "win32") });
1787
1868
  }
1788
1869
 
1789
1870
  // Names, folders' sign-in lines and usage only: tokens stay in the tools' own files.
@@ -1991,6 +2072,13 @@ export async function web(repoDir: string, opts: Opts = {}) {
1991
2072
  });
1992
2073
  }
1993
2074
 
2075
+ // The models one agent tool offers, read from the tool itself (cli/models.ts). Only a KNOWN_AGENTS command is taken.
2076
+ if (req.method === "GET" && path === "/models") {
2077
+ const cmd = url.searchParams.get("agent") ?? "";
2078
+ if (!KNOWN_AGENTS.some((a) => a.cmd === cmd)) return bad("unknown agent", 404);
2079
+ return json({ models: await (await import("./models.ts")).modelsOf(cmd) });
2080
+ }
2081
+
1994
2082
  if (req.method === "GET" && path === "/agents") {
1995
2083
  if (url.searchParams.get("home") === "1") return json(agentChoices(HOME_WS));
1996
2084
  const dir = qdir();
@@ -2044,6 +2132,20 @@ export async function web(repoDir: string, opts: Opts = {}) {
2044
2132
  }
2045
2133
 
2046
2134
  // What this board runs and what npm has: the page shows an Update button on a newer one.
2135
+ // What's New under Settings → General → About: the installed version's highlights and fixes, and whether this machine has seen them
2136
+ // (cli/whats-new.ts). A brand-new install (no project yet) gets none: it has the welcome. POST records it as seen.
2137
+ if (path === "/whats-new" && (req.method === "GET" || req.method === "POST")) {
2138
+ const fresh = states(true).filter((d) => d !== join(home, ".kaizen")).length === 0;
2139
+ if (req.method === "POST") {
2140
+ const refused = strict(req);
2141
+ if (refused) return refused;
2142
+ if (!local(req)) return bad("cross-origin write refused", 403);
2143
+ const w = whatsNew(home, VERSION, fresh);
2144
+ if (w.entry) markSeen(home, w.entry.version);
2145
+ }
2146
+ return json(whatsNew(home, VERSION, fresh));
2147
+ }
2148
+
2047
2149
  if (req.method === "GET" && path === "/version") {
2048
2150
  const v = await npmLatest(url.searchParams.has("fresh"));
2049
2151
  // The desktop app's own copy is read-only and updates with the app, so no
@@ -2060,40 +2162,8 @@ export async function web(repoDir: string, opts: Opts = {}) {
2060
2162
  // this board running and says why.
2061
2163
  if (req.method === "POST" && path === "/upgrade") {
2062
2164
  if (!local(req)) return bad("cross-origin write refused", 403);
2063
- if (upgrading) return bad("an upgrade is already running", 409);
2064
- if (DESKTOP_BUNDLED) return bad("this board is the desktop app's copy; the app updates itself", 409);
2065
- // Windows will not rename ~/kaizen while this board holds files in it, so the
2066
- // upgrade waits in its own process for this one to exit, then starts the board
2067
- // again; ~/.kaizen/upgrade.log keeps what it said. It runs from a copy of cli/,
2068
- // so nothing runs out of ~/kaizen while it is renamed.
2069
- if (process.platform === "win32") {
2070
- const helper = join(home, ".kaizen", "upgrader");
2071
- rmSync(helper, { recursive: true, force: true });
2072
- cpSync(join(repoDir, "cli"), join(helper, "cli"), { recursive: true });
2073
- const log = Bun.file(UPGRADE_LOG);
2074
- Bun.spawn([process.execPath, join(helper, "cli", "install.ts"), "upgrade", "--wait", String(process.pid), "--restart", String(srv.port)], {
2075
- cwd: home, detached: true, stdio: ["ignore", log, log], windowsHide: true,
2076
- }).unref();
2077
- saveLive();
2078
- setTimeout(() => process.exit(0), 300);
2079
- return json({ ok: true });
2080
- }
2081
- upgrading = true;
2082
- try {
2083
- const p = Bun.spawn([process.execPath, join(repoDir, "cli", "install.ts"), "upgrade"], { stdin: "ignore", stdout: "pipe", stderr: "pipe", windowsHide: true });
2084
- const [out, err, code] = await Promise.all([new Response(p.stdout).text(), new Response(p.stderr).text(), p.exited]);
2085
- const why = (out + err).replace(/\x1b\[[0-9;]*m/g, "").split("\n").map((l) => l.trim()).filter((l) => l && !l.startsWith("+")).slice(-2).join(" — ");
2086
- if (code !== 0) return bad(why || `kaizen upgrade exited ${code}`, 500);
2087
- if (installed() === VERSION) return bad(why || "Already up to date");
2088
- const port = srv.port;
2089
- saveLive();
2090
- setTimeout(() => {
2091
- Bun.spawn([process.execPath, join(repoDir, "cli", "install.ts"), "web", "--port", String(port), "--no-open", "--foreground"], {
2092
- detached: true, stdio: ["ignore", "ignore", "ignore"], windowsHide: true,
2093
- }).unref();
2094
- }, 300);
2095
- return json({ ok: true, version: installed() });
2096
- } finally { upgrading = false; }
2165
+ const r = await runUpgrade();
2166
+ return "error" in r ? bad(r.error, r.status) : json(r);
2097
2167
  }
2098
2168
 
2099
2169
  // The user's Firecrawl key for `kaizen search` / `kaizen scrape` (cli/research.ts).
@@ -2269,6 +2339,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
2269
2339
  return "error" in r ? { error: r.error } : { dir: (r as { dir: string }).dir };
2270
2340
  },
2271
2341
  agents: KNOWN_AGENTS.filter((a) => agentUsable(a.cmd)).map((a) => a.cmd),
2342
+ defaultAgent: detectDefaultAgent(repoDir).cmd,
2272
2343
  // A draft task: saved on the Tasks list, no agent started (the task page starts it).
2273
2344
  task: (d: string, goal: string) => {
2274
2345
  try { tasks.createTask(d, { goal, project: dirname(d) }, `chat:${Date.now()}:${Math.random().toString(36).slice(2, 8)}`); changed(); return { ok: true as const }; }
@@ -2579,13 +2650,14 @@ export async function web(repoDir: string, opts: Opts = {}) {
2579
2650
  : body.op === "board" ? setBoard(body.dir, ids, str(body.board))
2580
2651
  : body.op === "snooze" ? snooze(body.dir, ids, str(body.until))
2581
2652
  : body.op === "unsnooze" ? unsnooze(body.dir, ids)
2582
- // A board on its own, for the page's "+ Board": make it (a client's or not), mark it a client's, or remove an empty one.
2653
+ // A board on its own, for the page's "+ Board": make it (a client's or not), mark it a client's, or remove it (its items go to the Inbox).
2583
2654
  : body.op === "boards" ? (body.act === "add" ? saveBoard(body.dir, str(body.name), body.client === true) : body.act === "client" ? saveBoard(body.dir, str(body.name), true) : body.act === "remove" ? removeBoard(body.dir, str(body.name)) : "act is one of: add, client, remove")
2584
2655
  : body.op === "dismiss" ? dismiss(body.dir, ids) : body.op === "restore" ? restore(body.dir, ids) : "unknown op";
2585
2656
  if (why) return bad(why, why === "no such item" ? 404 : why === "unknown op" ? 400 : 409);
2586
2657
  // A capture with no kind of its own is sorted by ChatGPT after this answer, never before it.
2587
2658
  if (added && "id" in added) addedId = added.id;
2588
2659
  if (addedId && !str(body.kind) && chatgpt.status().connected) sortLater(body.dir, addedId);
2660
+ if (addedId) mediaLater(body.dir, addedId);
2589
2661
  } catch (e) { return bad((e as Error).message, 500); }
2590
2662
  changed();
2591
2663
  return json({ ok: true, ...(addedId ? { id: addedId } : {}) });
@@ -3031,7 +3103,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
3031
3103
  saveLive();
3032
3104
  awake.stop();
3033
3105
  closeAllProxies();
3034
- clearInterval(poll); clearInterval(ping); clearInterval(gather); clearInterval(automate); clearInterval(loop); clearInterval(keepList);
3106
+ clearInterval(autoUpdate); clearTimeout(autoFirst); clearInterval(poll); clearInterval(ping); clearInterval(gather); clearInterval(automate); clearInterval(loop); clearInterval(keepList);
3035
3107
  for (const w of watchers) { try { w.close(); } catch { /* gone */ } }
3036
3108
  setTimeout(() => { server.stop(true); resolve(); }, live ? 400 : 0);
3037
3109
  };
@@ -0,0 +1,38 @@
1
+ [
2
+ {
3
+ "version": "1.87.4",
4
+ "highlights": [
5
+ {
6
+ "title": "What's New, right in Settings",
7
+ "text": "After an update, Settings → General → About shows what changed in this release, with a dot on the Settings gear until you have seen it."
8
+ },
9
+ {
10
+ "title": "See what the agent is doing, live",
11
+ "text": "While Claude Code builds a task, its panel shows the file it is editing or the command it is running right now, with the last few actions below."
12
+ },
13
+ {
14
+ "title": "Update automatically",
15
+ "text": "A new switch under Settings → General → Updates lets kaizen update itself when nothing is running and no board page is open. Off by default."
16
+ },
17
+ {
18
+ "title": "A welcome that explains how kaizen works",
19
+ "text": "New users see how a run goes, from ask to review, and the setup no longer ends until a project is added."
20
+ },
21
+ {
22
+ "title": "Agents offer kaizen's skills",
23
+ "text": "Ask for a video, a deck or a plan in plain chat and the matching skill is offered first."
24
+ },
25
+ {
26
+ "title": "Permission prompts on the task page",
27
+ "text": "When an agent waits for permission, Allow and Deny are on the task. Kaizen's own file reads no longer ask."
28
+ }
29
+ ],
30
+ "fixes": [
31
+ "A task no longer gets stuck after its review; \"Looks good\" comes back and finishes it.",
32
+ "Explore asks its questions before it starts investigating.",
33
+ "Steam Deck: the app uses software rendering, which stops the GPU crash.",
34
+ "The footer checks your connected phone every 15 seconds.",
35
+ "The last Claude usage reading is kept when its endpoint errors."
36
+ ]
37
+ }
38
+ ]
@@ -0,0 +1,43 @@
1
+ // What's New: a short, hand-written list of a release's big improvements and its fixes (cli/whats-new.json, newest first), shown once
2
+ // per machine under Settings → General → About after an update. The text is written at release time (`bun run release` refuses to
3
+ // publish a version that has no entry, unless told `--no-notes`); what a machine has seen lives in ~/.kaizen/whats-new-seen.json.
4
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
5
+ import { dirname, join } from "node:path";
6
+
7
+ export type Entry = { version: string; highlights: { title: string; text: string }[]; fixes: string[] };
8
+
9
+ const here = join(dirname(import.meta.path), "whats-new.json");
10
+ export const entries = (): Entry[] => { try { return JSON.parse(readFileSync(here, "utf8")); } catch { return []; } };
11
+
12
+ // 1.10.0 is newer than 1.9.0: numbers, not text.
13
+ export const cmp = (a: string, b: string) => {
14
+ const x = a.split(".").map(Number), y = b.split(".").map(Number);
15
+ for (let i = 0; i < 3; i++) if ((x[i] || 0) !== (y[i] || 0)) return (x[i] || 0) - (y[i] || 0);
16
+ return 0;
17
+ };
18
+ // The entry a machine on `installed` shows: the one for exactly that version, nothing otherwise. A release with no entry of its own shows
19
+ // nothing, rather than the notes of an older release under a newer version (`bun run release` refuses to publish without one).
20
+ export const entryFor = (list: Entry[], installed: string): Entry | null => list.find((e) => e.version === installed) ?? null;
21
+
22
+ const file = (home: string) => join(home, ".kaizen", "whats-new-seen.json");
23
+ export const seenVersion = (home: string): string | null => {
24
+ try { const v = JSON.parse(readFileSync(file(home), "utf8"))?.version; return typeof v === "string" ? v : null; } catch { return null; }
25
+ };
26
+ export function markSeen(home: string, version: string) {
27
+ const cur = seenVersion(home);
28
+ if (cur && cmp(cur, version) >= 0) return;
29
+ mkdirSync(dirname(file(home)), { recursive: true });
30
+ writeFileSync(file(home) + ".tmp", JSON.stringify({ version }) + "\n");
31
+ renameSync(file(home) + ".tmp", file(home));
32
+ }
33
+
34
+ // What the page gets. `fresh`: a brand-new install (no project yet), which has the welcome instead and is recorded as having seen
35
+ // this version, so the card never greets it; someone who already has projects sees it once, the first time.
36
+ export function whatsNew(home: string, installed: string, fresh: boolean, list: Entry[] = entries()) {
37
+ const entry = entryFor(list, installed);
38
+ if (!entry) return { version: installed, entry: null, unseen: false };
39
+ const seen = seenVersion(home);
40
+ if (seen === null && fresh) { markSeen(home, entry.version); return { version: installed, entry, unseen: false }; }
41
+ return { version: installed, entry, unseen: seen === null || cmp(entry.version, seen) > 0 };
42
+ }
43
+ export const hasEntry = (version: string, list: Entry[] = entries()) => list.some((e) => e.version === version);
package/cli/workers.ts CHANGED
@@ -9,7 +9,7 @@ import { join } from "node:path";
9
9
  import { argsOf, commandOf, readPrefs, withEnv, type Prefs } from "./agent-prefs.ts";
10
10
  import { clip, reportBlocked, reportUnblock, validId } from "./report.ts";
11
11
  import { read } from "./settings.ts";
12
- import { accountEnv, accountForRun, agentFlags, agentUsable, detectDefaultAgent, MODEL_FLAGS, plainModel, promptArgs, readText, runAgent, subagentEnv, YOLO_FLAGS } from "./state.ts";
12
+ import { accountEnv, accountForRun, agentFlags, agentUsable, detectDefaultAgent, MODEL_FLAGS, plainModel, promptArgs, readText, runAgent, subagentEnv, YOLO_FLAGS, bypassFlags } from "./state.ts";
13
13
  import { branchFor, branchOf, run as sh } from "./worktree.ts";
14
14
 
15
15
  export type Status = "planned" | "requested" | "running" | "blocked" | "succeeded" | "failed" | "unverified" | "conflict" | "merged" | "stopped";
@@ -222,7 +222,7 @@ export function agentLine(project: string, id: string, prompt: string, permissio
222
222
  const acct = accountForRun(project, id, agent.cmd);
223
223
  if (acct.error) return acct.error;
224
224
  const bypass = permissions === "bypass" && !!YOLO_FLAGS[agent.cmd];
225
- const flags = [...agentFlags(project, agent.cmd, undefined, model), ...(bypass ? YOLO_FLAGS[agent.cmd]! : []), ...argsOf(agent.cmd, prefs)];
225
+ const flags = [...agentFlags(project, agent.cmd, undefined, model), ...(bypass ? bypassFlags(agent.cmd) : []), ...argsOf(agent.cmd, prefs)];
226
226
  const line = withEnv([commandOf(agent.cmd, prefs), ...flags, ...promptArgs(agent.cmd, prompt)], agent.cmd, prefs);
227
227
  // Windows has no env command: there only an account, as before, gets one.
228
228
  const vars = [...(process.platform !== "win32" ? subagentEnv(project, agent.cmd) : []), ...accountEnv(acct)];