kaizen-agent 1.59.0 → 1.59.2

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.
package/cli/docs.test.ts CHANGED
@@ -15,8 +15,10 @@ const fixture = (updated = "2026-10-28") => {
15
15
  };
16
16
 
17
17
  test("clean vault, nested CLI invocation, and no writes", () => {
18
- const f = fixture();
18
+ const f = fixture("2020-01-01");
19
19
  try {
20
+ // A source written today would be stale against any fixed date: back-date it.
21
+ utimesSync(join(f.root, "app.ts"), new Date("2020-01-01T10:00:00"), new Date("2020-01-01T10:00:00"));
20
22
  const nested = join(f.root, "inside"); mkdirSync(nested);
21
23
  const before = readFileSync(join(f.vault, "App.md"));
22
24
  const p = Bun.spawnSync([process.execPath, join(import.meta.dir, "install.ts"), "docs", "lint"], { cwd: nested });
package/cli/web.ts CHANGED
@@ -226,7 +226,7 @@ export async function web(repoDir: string, opts: Opts = {}) {
226
226
  // works and a slow poll where it does not.
227
227
  const clients = new Set<ReadableStreamDefaultController>();
228
228
  // Shells the board started (POST /shell), by /pty key; dead ones drop on the next /shells.
229
- const shells = new Map<string, { key: string; dir: string; title: string; agent: string; run: string }>();
229
+ const shells = new Map<string, { key: string; dir: string; title: string; agent: string; run: string; pid?: number }>();
230
230
  const SHELL_CAP = 8;
231
231
  let usageCache: Usage[] = [];
232
232
  let usageAt = 0;
@@ -651,6 +651,14 @@ export async function web(repoDir: string, opts: Opts = {}) {
651
651
  // transcript-age check alone would miss it where there is no /proc.
652
652
  const idx = runIndex(dir);
653
653
  if (readSessions(dir).some((x) => ptyState(x.key)?.alive && ownerOf(dir, x, idx) === id)) return json({ live: true }, 409);
654
+ // Running in a board terminal (the Terminal page's shell, opened by another run or
655
+ // none): that terminal becomes this run's, so the run view shows it.
656
+ const host = [...shells.values()].find((x) => x.dir === dir && x.pid && ptyState(x.key)?.alive && shellHosts(x.pid, sid));
657
+ if (host) {
658
+ host.run = runKey;
659
+ changed();
660
+ return json(host);
661
+ }
654
662
  if (sessionLive(sid)) return json({ live: true }, 409);
655
663
  agent = "claude";
656
664
  cmd = ["claude", "--resume", sid];
@@ -664,9 +672,9 @@ export async function web(repoDir: string, opts: Opts = {}) {
664
672
  if ([...shells.values()].filter((x) => x.dir === dir).length >= SHELL_CAP) return bad(`at most ${SHELL_CAP} terminals per project: close one first`, 429);
665
673
  const key = "sh-" + crypto.randomUUID().slice(0, 8);
666
674
  const title = agent ? KNOWN_AGENTS.find((k) => k.cmd === agent)!.name : "shell";
667
- startPty(key, cmd, projectOf(dir), undefined, changed);
675
+ const pid = startPty(key, cmd, projectOf(dir), undefined, changed);
668
676
  // The run workspace that opened it (its card key), so each run keeps its own centre.
669
- shells.set(key, { key, dir, title, agent, run: runKey });
677
+ shells.set(key, { key, dir, title, agent, run: runKey, pid });
670
678
  changed();
671
679
  return json(shells.get(key));
672
680
  }
@@ -1705,6 +1713,24 @@ export function sessionLive(id: string): boolean {
1705
1713
  return false;
1706
1714
  }
1707
1715
 
1716
+ // Whether Claude Code session `id` runs as process `root` or under it: Claude Code records
1717
+ // each running session as ~/.claude/sessions/<pid>.json; /proc gives the parent chain.
1718
+ // Linux only; elsewhere false, and the run view says the session runs elsewhere.
1719
+ export function shellHosts(root: number, id: string): boolean {
1720
+ try {
1721
+ for (const f of readdirSync(join(home, ".claude", "sessions"))) {
1722
+ if (!/^\d+\.json$/.test(f)) continue;
1723
+ let pid = Number(f.slice(0, -5));
1724
+ try { if (JSON.parse(readFileSync(join(home, ".claude", "sessions", f), "utf8")).sessionId !== id) continue; } catch { continue; }
1725
+ for (let i = 0; i < 20 && pid > 1; i++) {
1726
+ if (pid === root) return true;
1727
+ try { pid = Number(readFileSync(`/proc/${pid}/stat`, "utf8").replace(/^.*\) /, "").split(" ")[1]); } catch { break; }
1728
+ }
1729
+ }
1730
+ } catch { /* no sessions folder or no /proc */ }
1731
+ return false;
1732
+ }
1733
+
1708
1734
  export async function openApp(url: string, profile?: string) {
1709
1735
  // Kaizen Bot's window (a profile) is always an app; the board asks the setting.
1710
1736
  if (!profile) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kaizen-agent",
3
- "version": "1.59.0",
3
+ "version": "1.59.2",
4
4
  "description": "Staged workflow for AI agents — code, writing, research, operations: plan, human approval, build, independent review, bounded fix loop.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -87,9 +87,6 @@ export function open(c, keepTab) {
87
87
  if (!keepTab)
88
88
  store.lastTab = store.tab =
89
89
  c.status === "abandoned" ? "plan" : { 1: "plan", 2: "backlog", 3: "review", 4: "preview" }[c.column] || "request";
90
- // A run its agent is working on in this board, while planning, building or reviewing, opens on that agent.
91
- // Not in the run workspace: there the agent is a centre tab.
92
- if (!keepTab && c.pty && c.pty.alive && c.column >= 1 && c.column <= 3 && view !== "run") store.tab = "term";
93
90
  openRun(c, false);
94
91
  }
95
92
  // A building run's Backlog tab opens with its progress, above the deferred items. The
@@ -173,12 +170,9 @@ export async function openRun(c, refresh, again) {
173
170
  ? preview(store.runDoc.impl)
174
171
  : store.runDoc[t[1]] || (t[1] === "backlog" && c.column === 2 && store.runDoc.progress)),
175
172
  );
176
- if (c.pty && store.wantTerm === key(c)) {
177
- store.wantTerm = null;
178
- store.tab = "term";
179
- }
180
- // In the run workspace the agent is a centre tab, so the panel never shows a terminal.
181
- if (store.tab === "term" && (!c.pty || view === "run")) store.tab = store.lastTab;
173
+ if (store.wantTerm === key(c)) store.wantTerm = null;
174
+ // The agent is a centre tab of the run workspace only: the panel never shows a terminal.
175
+ if (store.tab === "term") store.tab = store.lastTab;
182
176
  // In the run workspace Preview is a centre tab, so the panel never shows it.
183
177
  if (view === "run" && store.tab === "preview") store.tab = "review";
184
178
  // A tab not written yet falls back to the latest one that is.
@@ -187,7 +181,7 @@ export async function openRun(c, refresh, again) {
187
181
  if (store.tab !== "term") store.lastTab = store.tab;
188
182
  $("panel").classList.toggle("wide", store.tab === "term");
189
183
  const pt = $("pterm");
190
- pt.hidden = !c.pty || view === "run";
184
+ pt.hidden = true;
191
185
  pt.classList.toggle("on", store.tab === "term");
192
186
  pt.setAttribute("aria-pressed", store.tab === "term");
193
187
  pt.title = pt.ariaLabel = store.tab === "term" ? "Close terminal" : "Terminal";
@@ -13,6 +13,9 @@ let mode: "home" | "device" | null = null;
13
13
 
14
14
  const chev = raw(`<svg class="pchev" viewBox="0 0 24 24" aria-hidden="true"><path d="M9 6l6 6-6 6"/></svg>`);
15
15
  const runs = () => railData().cards.filter((c) => c.kind === "run" && !c.archived);
16
+ // Ideas not started yet: a phone has no Ideas page, so the Runs page lists them.
17
+ const ideas = () => railData().cards.filter((c) => c.kind === "idea" && !c.archived);
18
+ const rowKey = (c) => (c.kind === "run" ? c.id : c.text);
16
19
  const projName = (dir: string) => {
17
20
  const l = railData().projects?.find((p) => p.dir === dir)?.label || dir.replace(/[\\/]\.kaizen$/, "");
18
21
  return l.split(/[\\/]/).pop() || l;
@@ -20,7 +23,7 @@ const projName = (dir: string) => {
20
23
 
21
24
  function row(c, now: number) {
22
25
  const name = projName(c.state);
23
- return html`<a class="prow" href="${cardHref(c)}" data-dir="${c.state}" data-id="${c.id}"><span class="si ${stateOf(c)}"></span><span class="pmain"><b>${titleOf(c)}</b><small>${logo(c.state, name, railData().projects)}${name}</small><code>${subline(c, now)}</code></span></a>`;
26
+ return html`<a class="prow" href="${cardHref(c)}" data-dir="${c.state}" data-id="${rowKey(c)}"><span class="si ${stateOf(c)}"></span><span class="pmain"><b>${titleOf(c)}</b><small>${logo(c.state, name, railData().projects)}${name}</small><code>${subline(c, now)}</code></span></a>`;
24
27
  }
25
28
 
26
29
  function home() {
@@ -47,7 +50,8 @@ function device() {
47
50
  const active = all.filter((c) => !wait.includes(c) && !done.includes(c));
48
51
  const group = (title: string, cs: any[], shut = false) =>
49
52
  cs.length ? html`<details class="pgrp"${raw(shut ? "" : " open")}><summary>${title}<span>${cs.length}</span></summary><div class="plist2">${cs.map((c) => row(c, now))}</div></details>` : "";
50
- return html`${group("Waiting on you", wait)}${group("Active", active)}${group("Done", done, true)}${all.length ? "" : html`<p class="pnote">No runs yet.</p>`}`;
53
+ const idle = ideas().sort((a, b) => (b.moved ?? b.added ?? 0) - (a.moved ?? a.added ?? 0));
54
+ return html`${group("Waiting on you", wait)}${group("Active", active)}${group("Ideas", idle)}${group("Done", done, true)}${all.length || idle.length ? "" : html`<p class="pnote">No runs yet.</p>`}`;
51
55
  }
52
56
 
53
57
  function draw() {
@@ -75,8 +79,27 @@ export function openPhone(m: "home" | "device" | null) {
75
79
  if (m === "home") void fetchNet();
76
80
  }
77
81
 
82
+ // A light tick on every tap of something pressable. Android has vibrate; iOS (18+) has none,
83
+ // but Safari ticks when a switch checkbox toggles, so a hidden one is toggled through its label.
84
+ let tick: HTMLLabelElement | null = null;
85
+ function haptic() {
86
+ if (navigator.vibrate) return void navigator.vibrate(8);
87
+ if (!tick) {
88
+ tick = document.createElement("label");
89
+ tick.hidden = true;
90
+ tick.innerHTML = `<input type="checkbox" switch>`;
91
+ document.body.append(tick);
92
+ }
93
+ tick.click();
94
+ }
95
+
78
96
  export function initPhone(go: (v: string, push?: boolean) => void, openRun: (c) => void) {
79
97
  addEventListener("kz-cards", draw);
98
+ addEventListener(
99
+ "click",
100
+ (e) => isPhone() && e.isTrusted && (e.target as HTMLElement).closest?.("button,a,summary,label,select,[role=button],input[type=checkbox]") && haptic(),
101
+ true,
102
+ );
80
103
  $("phome")?.addEventListener("click", (e) => {
81
104
  if ((e as MouseEvent).ctrlKey || (e as MouseEvent).metaKey) return;
82
105
  const a = (e.target as HTMLElement).closest<HTMLAnchorElement>("a");
@@ -84,7 +107,7 @@ export function initPhone(go: (v: string, push?: boolean) => void, openRun: (c)
84
107
  if (a.dataset.dev) return (e.preventDefault(), go("device", true));
85
108
  if (a.getAttribute("aria-disabled")) return e.preventDefault();
86
109
  if (a.classList.contains("prow")) {
87
- const c = runs().find((x) => x.state === a.dataset.dir && x.id === a.dataset.id);
110
+ const c = [...runs(), ...ideas()].find((x) => x.state === a.dataset.dir && rowKey(x) === a.dataset.id);
88
111
  if (c) (e.preventDefault(), openRun(c));
89
112
  }
90
113
  });
@@ -13,7 +13,7 @@ import { termLoad } from "./agent-term.ts";
13
13
  import { load, post } from "./api.ts";
14
14
  import { attach, md, preview } from "./markdown.ts";
15
15
  import { layout } from "./terms.ts";
16
- import { cardHref, markCurrent, railData } from "./workspace.ts";
16
+ import { cardHref, markCurrent, railData, titleOf } from "./workspace.ts";
17
17
  import { go } from "./views.ts";
18
18
 
19
19
  type Tab = { id: string; kind: "agent" | "shell" | "local" | "preview" | "note" | "wait"; title: string; key?: string; note?: string; agent?: string };
@@ -133,6 +133,8 @@ export async function showRunView() {
133
133
  // Each run has its own centre: switching runs unmounts this one's panes (its shells keep running on the server).
134
134
  if (fresh) stopPanes();
135
135
  card = c;
136
+ // A phone titles the workspace with the run, in the page header.
137
+ document.querySelector(".hdr h1")!.textContent = titleOf(c);
136
138
  if (fresh || store.openKey !== key(c)) open(c);
137
139
  try {
138
140
  const r = await fetch("/shells?dir=" + encodeURIComponent(c.state));
@@ -14,10 +14,12 @@ export let view = "board";
14
14
  // The board's own area, not the docked panel.
15
15
  const AREA = ["board", "terminal", "home", "ideas", "run", "chat", "device"];
16
16
  export const markView = (v) => {
17
+ // A phone's run workspace belongs to its Runs tab.
18
+ const lit = v === "run" && isPhone() ? "device" : v;
17
19
  document
18
20
  .querySelectorAll(".rail a.it")
19
21
  .forEach((a) =>
20
- a.dataset.view === v ? a.setAttribute("aria-current", "page") : a.removeAttribute("aria-current"),
22
+ a.dataset.view === lit ? a.setAttribute("aria-current", "page") : a.removeAttribute("aria-current"),
21
23
  );
22
24
  // The Icebox is titled in the header, top left, like the board.
23
25
  document.querySelector(".hdr h1").textContent = v === "sources" ? "Icebox" : v === "ideas" ? "Ideas" : v === "run" ? "Run" : v === "terminal" ? "Terminal" : v === "home" ? (isPhone() ? "kaizen" : "Home") : v === "chat" ? "Chat" : v === "device" ? "Runs" : "Board";
package/web/board.html CHANGED
@@ -27,6 +27,8 @@
27
27
  body{margin:0;background:var(--canvas);color:var(--ink);font:13px/1.5 var(--font);-webkit-font-smoothing:antialiased;-webkit-text-size-adjust:100%;height:100vh;height:100dvh;overflow:hidden;display:flex}
28
28
  html{background:var(--canvas);touch-action:manipulation}
29
29
  @media(display-mode:standalone){body{position:fixed;inset:0;height:auto;overscroll-behavior:none;touch-action:pan-x pan-y;-webkit-text-size-adjust:100%}}
30
+ /* iOS 26 stops a fixed inset:0 body short of the screen bottom on phones, leaving a strip under the tab bar */
31
+ @media(display-mode:standalone) and (max-width:640px){body{bottom:auto;height:100lvh}}
30
32
  @media(max-width:640px),(display-mode:standalone){body{padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)}}
31
33
  /* iOS 26 blurs the page under the status bar unless a fixed bar touches the top edge: give it one in the page colour */
32
34
  @media(display-mode:standalone){body::before{content:"";position:fixed;top:0;left:0;right:0;height:env(safe-area-inset-top);background:inherit;z-index:100;pointer-events:none}}
@@ -125,7 +127,7 @@ body .rail a.upd::after{left:calc(50% + 6px);top:4px}body .toast{left:16px;botto
125
127
  .rail a.it:is([data-view=board],[data-view=ideas],[data-view=sources]),#foot,#ctx-open,body .rail .rbot .rib{display:none!important}
126
128
  .rail a.it.ponly{display:flex}
127
129
  .rail a.it[data-view=home]{order:1}.rail a.it[data-view=chat]{order:2}.rail a.it[data-view=device]{order:3}.rail a.it[data-view=settings]{order:4}
128
- .rail,[data-rail=min] .rail{padding:6px 8px calc(6px + env(safe-area-inset-bottom));border-top:1px solid color-mix(in srgb,var(--line) 70%,transparent)}
130
+ .rail,[data-rail=min] .rail{padding:6px 8px max(4px,calc(env(safe-area-inset-bottom) - 10px));border-top:1px solid color-mix(in srgb,var(--line) 70%,transparent)}
129
131
  .rail a.it,[data-rail=min] .rail a.it{min-height:50px;gap:3px;font-size:10.5px;letter-spacing:.01em}
130
132
  .rail a.it svg{width:44px;height:26px;padding:4px 12px;box-sizing:border-box;border-radius:13px;transition:background .15s}
131
133
  .rail a.it[aria-current=page] svg{background:color-mix(in srgb,var(--accent) 16%,transparent)}
@@ -133,13 +135,16 @@ body .rail a.upd::after{left:calc(50% + 6px);top:4px}body .toast{left:16px;botto
133
135
  }
134
136
  /* end side menu */
135
137
  @media(max-width:640px){
136
- body .hdr{padding:12px 16px 10px;gap:8px;border-bottom:0}
138
+ body .hdr{padding:28px 16px 12px;gap:8px;border-bottom:0}
137
139
  body.paged:is(.phomev,.homev) .hdr{display:flex!important;flex-wrap:nowrap}
138
- body .hdr h1{flex:1 1 auto;font-size:19px;letter-spacing:-.01em}
139
- body.homev #hnewtop{border-radius:19px}
140
+ body .hdr h1{flex:1 1 auto;min-width:0;font-size:20px;line-height:30px;letter-spacing:-.01em;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
141
+ /* one round + on every phone page; -4px keeps the header as tall as Settings' */
142
+ body.homev #hsidetop{margin:-4px 0}body.homev #hnewtop,body.phomev #newtop{display:inline-grid;place-items:center;flex:none;width:38px;height:38px;margin:-4px 0;padding:0;border-radius:19px;box-shadow:var(--shadow-2)}
143
+ body.homev #hnewtop svg,body.phomev #newtop svg{display:block;width:18px;height:18px}body.phomev #newtop span{display:none}
144
+ /* the run workspace: a page header with the run's title, the Runs tab lit; a lone pane drops its own header */
145
+ html body.runv .app{grid-template-rows:auto minmax(0,1fr)}html body.runv .hdr{display:flex!important;grid-area:1/1}html body.runv .hdr>:not(h1){display:none!important}html body.runv #runv{grid-area:2/1}
146
+ html body.runv #rtabs{padding:0 10px 6px}body.runv .rpane:not(.split)>.ph{display:none}
140
147
  body.phomev .hdr>:not(h1):not(#newtop),body.phomev #board{display:none!important}
141
- body.phomev #newtop{display:inline-grid;place-items:center;width:38px;height:38px;padding:0;font-size:0;border-radius:19px}
142
- body.phomev #newtop::before{content:"+";display:block;height:38px;font-size:24px;font-weight:300;line-height:36px}
143
148
  body.pdevv #newtop{display:none!important}
144
149
  body.phomev #phome{display:block;flex:1;min-height:0;overflow:auto;padding:4px 16px 24px;animation:fi .2s}
145
150
  }
@@ -795,7 +800,7 @@ body.ideav.paged .hdr{display:flex}body.ideav.paged #bq{display:block}body.ideav
795
800
  @media(min-width:641px){.app .hdr,#ideasv .hdr.ihdr,#rtabs,#panel.docked>header{height:52px;min-height:52px;box-sizing:border-box;padding-top:0;padding-bottom:0;border-bottom:1px solid var(--line);align-items:center;flex-wrap:nowrap}.itable th{border-bottom-color:var(--line)}}
796
801
 
797
802
  /* Ideas header on a small laptop: one row, nothing wraps; the search box gives way first. */
798
- #newtop{white-space:nowrap}@media(min-width:641px) and (max-width:1440px){body.ideav .app .hdr{gap:8px;padding:8px 12px 8px 20px;height:auto;flex-wrap:wrap}body.ideav #bq{flex:1 1 120px;width:auto;min-width:90px}body.ideav #hx{gap:6px;min-width:0}body.ideav #hx .iseg{gap:2px}body.ideav #hx .pill{padding:4px 8px}body.ideav #hx .ipop .sel{max-width:130px}}
803
+ #newtop{white-space:nowrap}#newtop svg{display:none}@media(min-width:641px) and (max-width:1440px){body.ideav .app .hdr{gap:8px;padding:8px 12px 8px 20px;height:auto;flex-wrap:wrap}body.ideav #bq{flex:1 1 120px;width:auto;min-width:90px}body.ideav #hx{gap:6px;min-width:0}body.ideav #hx .iseg{gap:2px}body.ideav #hx .pill{padding:4px 8px}body.ideav #hx .ipop .sel{max-width:130px}}
799
804
  </style>
800
805
  </head>
801
806
  <body>
@@ -937,7 +942,7 @@ body.ideav.paged .hdr{display:flex}body.ideav.paged #bq{display:block}body.ideav
937
942
  <span class="hx" id="hx"></span>
938
943
  <span class="sp"></span>
939
944
  <span class="bar" id="tmodes" role="group" aria-label="Layout"></span>
940
- <button class="btn pri" id="newtop">New idea</button>
945
+ <button class="btn pri" id="newtop"><svg><use href="#i-plus"/></svg><span>New idea</span></button>
941
946
  <button class="ib" id="ctx-open" aria-label="Open side panel" title="Notes, files and terminals"><svg><use href="#i-side"/></svg></button>
942
947
  <button class="ib" id="hpop" title="Pop out chat" aria-label="Pop out chat"><svg><use href="#i-popout"/></svg></button>
943
948
  <button class="btn pri" id="hnewtop" aria-label="New chat"><svg><use href="#i-plus"/></svg><span>New chat</span></button>