kaizen-agent 1.59.2 → 1.60.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/cli/add-project.test.ts +169 -0
  2. package/cli/add-project.ts +132 -0
  3. package/cli/board.test.ts +15 -0
  4. package/cli/chat.ts +1 -1
  5. package/cli/dashboard.ts +6 -2
  6. package/cli/install.test.ts +1 -1
  7. package/cli/install.ts +18 -9
  8. package/cli/pty.test.ts +89 -5
  9. package/cli/pty.ts +126 -9
  10. package/cli/restart.test.ts +169 -0
  11. package/cli/settings.test.ts +35 -0
  12. package/cli/settings.ts +69 -18
  13. package/cli/state.test.ts +119 -3
  14. package/cli/state.ts +171 -13
  15. package/cli/usage.test.ts +130 -1
  16. package/cli/web-accept.test.ts +54 -0
  17. package/cli/web-pr.test.ts +51 -0
  18. package/cli/web-symlink.test.ts +28 -0
  19. package/cli/web.ts +349 -100
  20. package/cli/worktree.test.ts +146 -1
  21. package/cli/worktree.ts +214 -4
  22. package/cli/writeback.ts +1 -1
  23. package/package.json +1 -1
  24. package/skills/kaizen/SKILL.md +5 -1
  25. package/skills/kaizen/config.default.yml +15 -2
  26. package/skills/kaizen/settings.md +1 -0
  27. package/skills/kaizen/spec-main.md +28 -2
  28. package/skills/kaizen-help/SKILL.md +1 -0
  29. package/web/board/add-project.ts +136 -0
  30. package/web/board/api.ts +1 -1
  31. package/web/board/badge.ts +5 -5
  32. package/web/board/cards.ts +11 -3
  33. package/web/board/context.ts +1 -0
  34. package/web/board/fixes.ts +3 -2
  35. package/web/board/git.ts +309 -60
  36. package/web/board/home.ts +7 -1
  37. package/web/board/ideas.ts +20 -3
  38. package/web/board/live.ts +1 -1
  39. package/web/board/main.ts +26 -9
  40. package/web/board/panel.ts +31 -16
  41. package/web/board/projects.ts +6 -85
  42. package/web/board/run-pick.ts +41 -0
  43. package/web/board/run-view.ts +286 -110
  44. package/web/board/search-match.ts +20 -0
  45. package/web/board/search.test.ts +20 -0
  46. package/web/board/search.ts +324 -0
  47. package/web/board/settings.ts +42 -5
  48. package/web/board/store.ts +3 -1
  49. package/web/board/toast.ts +4 -1
  50. package/web/board/views.ts +3 -1
  51. package/web/board/workspace.ts +127 -38
  52. package/web/board/ws-board-ui.ts +95 -0
  53. package/web/board/ws-board.test.ts +71 -0
  54. package/web/board/ws-board.ts +45 -0
  55. package/web/board/ws-tabs.test.ts +181 -0
  56. package/web/board/ws-tabs.ts +173 -0
  57. package/web/board.html +86 -36
  58. package/web/board.js +129 -44
  59. package/web/notebook.js +41 -24
  60. package/web/notes.html +26 -20
  61. package/web/term.js +1 -1
  62. package/web/video.html +26 -20
  63. package/web/video.js +76 -59
@@ -0,0 +1,20 @@
1
+ // The search palette's matcher, apart from the page so a test can load it.
2
+ export type Item = { group: string; title: string; sub?: string; when?: string; hay: string; at?: number; dot?: string; ico: string; act: () => void };
3
+
4
+ // Every word of the query in the item; a title that starts with it ranks first, then a title
5
+ // holding it, then the rest by recency.
6
+ export function match(list: Item[], q: string): Item[] {
7
+ const words = q.toLowerCase().split(/\s+/).filter(Boolean);
8
+ if (!words.length) return list;
9
+ const lq = q.trim().toLowerCase();
10
+ const score = (i: Item) => {
11
+ const t = i.title.toLowerCase();
12
+ return t.startsWith(lq) ? 0 : t.includes(lq) ? 1 : 2;
13
+ };
14
+ return list
15
+ .filter((i) => {
16
+ const h = (i.title + " " + (i.sub ?? "") + " " + i.hay).toLowerCase();
17
+ return words.every((w) => h.includes(w));
18
+ })
19
+ .sort((a, b) => score(a) - score(b) || (b.at ?? 0) - (a.at ?? 0));
20
+ }
@@ -0,0 +1,20 @@
1
+ import { expect, test } from "bun:test";
2
+ import { match } from "./search-match.ts";
3
+
4
+ const it = (title: string, at = 0, hay = "") => ({ group: "g", title, hay, at, ico: "run", act: () => {} });
5
+
6
+ test("an empty query keeps every item", () => {
7
+ const l = [it("a"), it("b")];
8
+ expect(match(l, " ")).toBe(l);
9
+ });
10
+
11
+ test("every word must be present, in title, sub or keywords", () => {
12
+ const l = [it("Global search", 0, "kaizen"), it("Search tests"), it("Board")];
13
+ expect(match(l, "search kaizen").map((i) => i.title)).toEqual(["Global search"]);
14
+ expect(match(l, "SEARCH").map((i) => i.title).sort()).toEqual(["Global search", "Search tests"]);
15
+ });
16
+
17
+ test("title prefix beats title contains beats keywords, then recency", () => {
18
+ const l = [it("Old board", 5, ""), it("Notes", 9, "board"), it("Board new", 1), it("Board recent", 3)];
19
+ expect(match(l, "board").map((i) => i.title)).toEqual(["Board recent", "Board new", "Old board", "Notes"]);
20
+ });
@@ -0,0 +1,324 @@
1
+ // Global search: the "Search" entry on top of the side menu, and Ctrl/Cmd+K anywhere, open
2
+ // one palette over workspaces, runs and ideas, chats, agent terminals, projects, pages and
3
+ // actions (modelled on Orca's "Jump to..." palette). Nothing is fetched but /chats; the rest
4
+ // is what the side menu already holds. Stands alone like workspace.ts, so the notebook and
5
+ // video pages carry it too: a pick the page cannot do in place navigates instead.
6
+ import { $, html, raw } from "./dom.ts";
7
+ import { age } from "./labels.ts";
8
+ import { openAdd } from "./add-project.ts";
9
+ import { cardHref, projName, railData, stateOf, titleOf, wsHref, wsLabel, wsOfCard } from "./workspace.ts";
10
+ import { match, type Item } from "./search-match.ts";
11
+ import { leaves, wsKey } from "./ws-tabs.ts";
12
+
13
+ // The pages that can open a thing in place answer this event and cancel it.
14
+ const ask = (name: string, detail: any) => !dispatchEvent(new CustomEvent(name, { cancelable: true, detail }));
15
+ // A menu entry's own click: in place on the board, a page load elsewhere.
16
+ const page = (v: string, href: string) => () => {
17
+ const a = document.querySelector<HTMLElement>(`.rail a.it[data-view="${v}"]`);
18
+ a ? a.click() : (location.href = href);
19
+ };
20
+ const openWs = (dir: string, ws: string) => {
21
+ if (!ask("kz-open-ws", { dir, ws })) location.href = wsHref(dir, ws);
22
+ };
23
+ // The run view's saved layouts (run-view.ts keeps them here per workspace).
24
+ const layouts = (): Record<string, any> => {
25
+ try {
26
+ return JSON.parse(localStorage.getItem("kz-runtabs") || "{}");
27
+ } catch {
28
+ return {};
29
+ }
30
+ };
31
+ // A tab: the board opens it in place; elsewhere its screen is chosen in storage, then the workspace loads.
32
+ const openTab = (dir: string, ws: string, id: string) => {
33
+ if (ask("kz-open-tab", { dir, ws, id })) return;
34
+ const all = layouts(),
35
+ s = all[wsKey(dir, ws)],
36
+ sc = s?.screens?.find((x) => leaves(x.tree).includes(id));
37
+ if (sc)
38
+ try {
39
+ s.on = sc.id;
40
+ localStorage.setItem("kz-runtabs", JSON.stringify(all));
41
+ } catch {}
42
+ location.href = wsHref(dir, ws);
43
+ };
44
+ // The run view's own tabs worth jumping to; agent tabs are listed with the terminals.
45
+ const TAB_KINDS = ["local", "preview", "note", "history", "shell"];
46
+ const browsed = (k: string) => {
47
+ try {
48
+ return localStorage.getItem("kz-browse:" + k)?.replace(/^https?:\/\//, "").replace(/\/$/, "");
49
+ } catch {}
50
+ };
51
+ const ICO = {
52
+ ws: '<circle cx="6" cy="6" r="2"/><circle cx="6" cy="18" r="2"/><circle cx="18" cy="8" r="2"/><path d="M6 8v8M18 10c0 4-6 3-12 6"/>',
53
+ run: '<path d="M5 4l14 8-14 8z"/>',
54
+ idea: '<path d="M9 18h6M10 21h4M12 3a6 6 0 0 0-4 10.5c.7.7 1 1.5 1 2.5h6c0-1 .3-1.8 1-2.5A6 6 0 0 0 12 3z"/>',
55
+ chat: '<path d="M21 12a8 8 0 0 1-11.6 7.1L4 20l1-4.6A8 8 0 1 1 21 12z"/>',
56
+ term: '<path d="M4 17l6-5-6-5M12 19h8"/>',
57
+ proj: '<path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>',
58
+ page: '<rect x="4" y="4" width="16" height="16" rx="2"/><path d="M4 9h16"/>',
59
+ act: '<path d="M13 3L5 14h6l-1 7 8-11h-6z"/>',
60
+ tab: '<rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3 9h8V5"/>',
61
+ plus: '<path d="M12 5v14M5 12h14"/>',
62
+ search: '<circle cx="11" cy="11" r="7"/><path d="M20 20l-4-4"/>',
63
+ };
64
+ const svg = (k: string) => raw(`<svg viewBox="0 0 24 24" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${ICO[k]}</g></svg>`);
65
+
66
+ let chats: any[] = [];
67
+ function items(): Item[] {
68
+ const { cards, projects = [], agents = [] } = railData();
69
+ const now = Date.now();
70
+ const cur = new URLSearchParams(location.search);
71
+ // The workspace open now: named by the address, or the one holding the run it names.
72
+ const curRun = cur.get("id") && cards.find((c) => c.kind === "run" && c.state === cur.get("dir") && c.id === cur.get("id"));
73
+ const curWs = cur.get("ws") ?? (curRun ? wsOfCard(curRun, projects) : null);
74
+ const out: Item[] = [];
75
+ const saved = layouts();
76
+ // Workspaces, the one open now first; then by their latest run.
77
+ const latest = new Map<string, number>();
78
+ for (const c of cards) {
79
+ const k = c.state + "\0" + wsOfCard(c, projects);
80
+ latest.set(k, Math.max(latest.get(k) ?? 0, c.moved ?? 0));
81
+ }
82
+ for (const p of projects) {
83
+ const name = projName(p.dir, projects);
84
+ for (const w of p.workspaces ?? []) {
85
+ const here = cur.get("dir") === p.dir && curWs === w.path;
86
+ const at = latest.get(p.dir + "\0" + w.path);
87
+ out.push({
88
+ group: here ? "Current" : "Workspaces",
89
+ title: wsLabel(w),
90
+ sub: name,
91
+ when: at ? age(at, now) : undefined,
92
+ hay: `${wsLabel(w)} ${name} ${w.path} workspace`,
93
+ at: here ? Infinity : at ?? 0,
94
+ ico: "ws",
95
+ act: () => openWs(p.dir, w.path),
96
+ });
97
+ const k = wsKey(p.dir, w.path),
98
+ lay = saved[k];
99
+ for (const t of lay?.tabs ?? []) {
100
+ if (!TAB_KINDS.includes(t.kind) || lay.hidden?.includes(t.id)) continue;
101
+ const title = (t.kind === "local" && browsed(k)) || t.title;
102
+ out.push({ group: "Tabs", title, sub: `${wsLabel(w)} · ${name}`, hay: `${title} ${t.title} ${t.kind} ${t.note ?? ""} ${wsLabel(w)} ${name} tab`, ico: "tab", act: () => openTab(p.dir, w.path, t.id) });
103
+ }
104
+ }
105
+ out.push({ group: "Projects", title: name, hay: `${name} ${p.dir} project`, ico: "proj", act: () => {
106
+ const main = p.workspaces?.find((w) => w.main) ?? p.workspaces?.[0];
107
+ main ? openWs(p.dir, main.path) : page("board", "/?view=board")();
108
+ } });
109
+ }
110
+ // Runs and ideas, not archived.
111
+ for (const c of cards.filter((c) => !c.archived)) {
112
+ const st = stateOf(c);
113
+ out.push({
114
+ group: c.kind === "run" ? "Runs" : "Ideas",
115
+ title: titleOf(c) || c.id,
116
+ sub: projName(c.state, projects),
117
+ when: c.moved ? age(c.moved, now) : undefined,
118
+ hay: `${titleOf(c)} ${c.id ?? ""} ${c.text ?? ""} ${projName(c.state, projects)} ${st}`,
119
+ at: c.moved ?? 0,
120
+ dot: st,
121
+ ico: c.kind === "run" ? "run" : "idea",
122
+ act: () => {
123
+ if (!ask("kz-open-card", { dir: c.state, id: c.kind === "run" ? c.id : undefined, text: c.text })) location.href = cardHref(c);
124
+ },
125
+ });
126
+ }
127
+ for (const c of chats) {
128
+ // updated is an ISO date string.
129
+ const at = Date.parse(c.updated) || 0;
130
+ out.push({
131
+ group: "Chats & terminals",
132
+ title: c.title || "Chat",
133
+ sub: c.project ? projName(c.project, projects) : undefined,
134
+ when: at ? age(at, now) : undefined,
135
+ hay: `${c.title} chat ${c.project ?? ""}`,
136
+ at,
137
+ dot: c.busy ? "build" : undefined,
138
+ ico: "chat",
139
+ act: () => {
140
+ try {
141
+ sessionStorage.setItem("kz-chat", c.id);
142
+ } catch {}
143
+ page("home", "/")();
144
+ },
145
+ });
146
+ }
147
+ for (const a of agents)
148
+ out.push({
149
+ group: "Chats & terminals",
150
+ title: a.name || a.agent || "Terminal",
151
+ sub: projName(a.dir, projects),
152
+ hay: `${a.name} ${a.agent ?? ""} ${a.run ?? ""} ${a.last ?? ""} ${projName(a.dir, projects)} terminal agent`,
153
+ at: a.at ?? a.born ?? 0,
154
+ dot: a.asking ? "wait" : a.busy ? "build" : "done",
155
+ ico: "term",
156
+ act: () => {
157
+ if (!ask("kz-open-term", { dir: a.dir, ws: a.ws, key: a.key })) location.href = wsHref(a.dir, a.ws ?? "");
158
+ },
159
+ });
160
+ // Pages and actions. Each clicks the side menu's own control, so it behaves the same.
161
+ const click = (id: string) => () => $(id)?.click();
162
+ const acts: [string, string, () => void, string?][] = [
163
+ ["Home", "page", page("home", "/"), "chat"],
164
+ ["Icebox", "page", page("sources", "/?view=icebox"), "requests sources gathered"],
165
+ ["Ideas", "page", page("ideas", "/?view=ideas"), "backlog"],
166
+ ["Board", "page", page("board", "/?view=board"), "kanban runs"],
167
+ ["Notes", "page", () => (location.href = "/notebook"), "notebook docs"],
168
+ ["Settings", "page", page("settings", "/?view=settings"), "preferences config"],
169
+ ["New idea", "act", () => ($("newtop") ? $("newtop").click() : (location.href = "/?view=board")), "create add run"],
170
+ ["Add a project", "act", () => openAdd({ dir: null }), "clone folder create workspace"],
171
+ ["Toggle theme", "act", click("themet"), "dark light"],
172
+ ["Collapse or expand menu", "act", click("fold"), "sidebar rail"],
173
+ ["Keyboard shortcuts", "act", click("kbd"), "keys help"],
174
+ ["Report an issue", "act", () => open("/issue", "_blank", "noopener"), "bug feedback"],
175
+ ];
176
+ for (const [title, ico, act, kw] of acts) out.push({ group: "Actions", title, hay: `${title} ${kw ?? ""}`, ico, act });
177
+ return out;
178
+ }
179
+
180
+ const ORDER = ["Current", "Workspaces", "Tabs", "Chats & terminals", "Runs", "Ideas", "Projects", "Actions"];
181
+ // With nothing typed each group shows its most recent few, as Orca's does.
182
+ const CAP = { Workspaces: 5, Tabs: 4, "Chats & terminals": 5, Runs: 5, Ideas: 3, Projects: 5 };
183
+
184
+ let dl: HTMLDialogElement | null = null;
185
+ let shown: Item[] = [];
186
+ let sel = 0;
187
+ function draw() {
188
+ const q = (dl!.querySelector("input") as HTMLInputElement).value;
189
+ const all = items();
190
+ const hit = q.trim() ? match(all, q) : all.slice().sort((a, b) => (b.at ?? 0) - (a.at ?? 0));
191
+ shown = [];
192
+ // Typed: the group holding the best match comes first, so Enter takes it.
193
+ const order = q.trim() ? [...new Set(hit.map((i) => i.group))] : ORDER;
194
+ for (const g of order) {
195
+ const rows = hit.filter((i) => i.group === g);
196
+ shown.push(...rows.slice(0, q.trim() ? 8 : CAP[g] ?? rows.length));
197
+ }
198
+ // Orca offers to create what was typed; here that is a new idea.
199
+ if (q.trim())
200
+ shown.push({ group: "Create", title: `New idea "${q.trim()}"`, hay: "", ico: "plus", act: () => newIdeaWith(q.trim()) });
201
+ sel = Math.min(sel, shown.length - 1);
202
+ const list = dl!.querySelector(".gs-list")!;
203
+ let g = "";
204
+ list.innerHTML = String(
205
+ html`${shown.map((i, n) => {
206
+ const head = i.group !== g ? ((g = i.group), html`<div class="gs-h" role="presentation">${i.group}</div>`) : "";
207
+ return html`${head}<div class="gs-i" role="option" id="gs-${n}" data-n="${n}" aria-selected="${String(n === sel)}">${svg(i.ico)}${i.dot ? html`<span class="si ${i.dot}"></span>` : ""}<span class="gs-t">${i.title}</span>${i.sub ? html`<span class="gs-s">${i.sub}</span>` : ""}${i.when ? html`<span class="gs-w">${i.when}</span>` : ""}</div>`;
208
+ })}${shown.length === 1 && q.trim() ? html`<div class="gs-none">No results</div>` : ""}`,
209
+ );
210
+ mark(sel);
211
+ dl!.querySelector(".gs-live")!.textContent = `${shown.length} result${shown.length === 1 ? "" : "s"} found`;
212
+ }
213
+ // Moves the selection without rebuilding the list.
214
+ function mark(n: number) {
215
+ dl!.querySelector(`#gs-${sel}`)?.setAttribute("aria-selected", "false");
216
+ sel = n;
217
+ const r = dl!.querySelector(`#gs-${n}`);
218
+ r?.setAttribute("aria-selected", "true");
219
+ dl!.querySelector("input")!.setAttribute("aria-activedescendant", "gs-" + n);
220
+ r?.scrollIntoView({ block: "nearest" });
221
+ }
222
+ function newIdeaWith(text: string) {
223
+ if (!$("newtop")) return void (location.href = "/?view=board");
224
+ $("newtop").click();
225
+ const t = document.querySelector<HTMLTextAreaElement>("dialog[open] textarea");
226
+ if (t) (t.value = text), t.dispatchEvent(new Event("input", { bubbles: true }));
227
+ }
228
+ function pick(n: number) {
229
+ const i = shown[n];
230
+ if (!i) return;
231
+ dl!.close();
232
+ i.act();
233
+ }
234
+
235
+ export function openSearch() {
236
+ if (dl) return dl.querySelector("input")!.focus();
237
+ dl = document.createElement("dialog");
238
+ dl.className = "gs";
239
+ dl.setAttribute("aria-label", "Search");
240
+ dl.innerHTML = String(
241
+ html`<div class="gs-box"><div class="gs-q">${svg("search")}<input type="text" placeholder="Search" aria-label="Search" role="combobox" aria-expanded="true" aria-controls="gs-list" autocomplete="off" spellcheck="false"></div><div class="gs-list" id="gs-list" role="listbox"></div><span class="gs-live" role="status" aria-live="polite"></span></div>`,
242
+ );
243
+ document.body.append(dl);
244
+ const q = dl.querySelector("input")!;
245
+ sel = 0;
246
+ q.oninput = () => ((sel = 0), draw());
247
+ q.onkeydown = (e) => {
248
+ const d = { ArrowDown: 1, ArrowUp: -1 }[e.key] ?? (e.ctrlKey && e.key === "n" ? 1 : e.ctrlKey && e.key === "p" ? -1 : 0);
249
+ if (d) {
250
+ e.preventDefault();
251
+ mark((sel + d + shown.length) % shown.length);
252
+ } else if (e.key === "Enter") {
253
+ e.preventDefault();
254
+ pick(sel);
255
+ }
256
+ };
257
+ const list = dl.querySelector<HTMLElement>(".gs-list")!;
258
+ list.onclick = (e) => {
259
+ const r = (e.target as Element).closest<HTMLElement>(".gs-i");
260
+ if (r) pick(+r.dataset.n!);
261
+ };
262
+ list.onpointermove = (e) => {
263
+ const r = (e.target as Element).closest<HTMLElement>(".gs-i");
264
+ if (r && +r.dataset.n! !== sel) mark(+r.dataset.n!);
265
+ };
266
+ dl.onclick = (e) => e.target === dl && dl!.close();
267
+ dl.onclose = () => (dl!.remove(), (dl = null));
268
+ dl.showModal();
269
+ draw();
270
+ // Chats live behind one fetch; the list redraws when they land.
271
+ fetch("/chats")
272
+ .then((r) => r.json())
273
+ .then((d) => {
274
+ chats = d.chats ?? [];
275
+ if (dl) draw();
276
+ })
277
+ .catch(() => {});
278
+ }
279
+
280
+ const CSS = `dialog.gs{border:0;padding:0;margin:14vh auto auto;background:none;width:min(560px,calc(100vw - 32px));color:var(--ink);overflow:visible}
281
+ dialog.gs::backdrop{background:rgb(0 0 0/.35)}
282
+ .gs-box{display:flex;flex-direction:column;max-height:min(480px,72vh);background:var(--bg);border:1px solid var(--line);border-radius:10px;box-shadow:0 16px 40px rgb(0 0 0/.25);overflow:hidden}
283
+ .gs-q{display:flex;align-items:center;gap:8px;padding:0 12px;border-bottom:1px solid var(--line)}
284
+ .gs-q svg{width:15px;height:15px;color:var(--dim);flex:none}
285
+ .gs-q input{flex:1;min-width:0;height:40px;border:0;outline:0;background:none;color:var(--ink);font:inherit;font-size:var(--fs-l,14px)}
286
+ .gs-list{flex:1;overflow:auto;padding:4px}
287
+ .gs-h{padding:10px 8px 4px;font-size:var(--fs-xs,11px);color:var(--dim)}
288
+ .gs-i{display:flex;align-items:center;gap:8px;height:var(--btn-s,32px);padding:0 var(--padx,8px);border-radius:var(--r-s,4px);cursor:pointer;font-size:var(--fs,13px)}
289
+ .gs-i[aria-selected=true]{background:var(--hover)}
290
+ .gs-i svg{width:var(--ico,14px);height:var(--ico,14px);color:var(--dim);flex:none}
291
+ .gs-i .si{flex:none}
292
+ .gs-t{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0}
293
+ .gs-s{color:var(--dim);font-size:var(--fs-s,12px);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;min-width:0;flex:0 1 auto}
294
+ .gs-w{margin-left:auto;padding-left:8px;color:var(--dim);font-size:var(--fs-xs,11px);flex:none}
295
+ .gs-none{padding:14px 8px;text-align:center;color:var(--dim);font-size:var(--fs-s,12px)}
296
+ .gs-live{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}
297
+ @media(max-width:640px){.rail a.it.gs-it{display:none}}`;
298
+
299
+ export function initSearch() {
300
+ const st = document.createElement("style");
301
+ st.textContent = CSS;
302
+ document.head.append(st);
303
+ const mac = /Mac|iP(hone|ad)/.test(navigator.platform);
304
+ const it = $("gsearch");
305
+ if (it) it.onclick = (e) => (e.preventDefault(), openSearch());
306
+ // Opened before the menu's data came in: fill in as it lands.
307
+ addEventListener("kz-rail", () => dl && draw());
308
+ // Ctrl/Cmd+K anywhere, and Orca's own Cmd+J (Ctrl+Shift+J is the browser's console).
309
+ addEventListener(
310
+ "keydown",
311
+ (e) => {
312
+ // A terminal keeps its keys: Ctrl+K there is the shell's kill-line.
313
+ if ((e.target as Element)?.closest?.(".xterm")) return;
314
+ const mod = mac ? e.metaKey : e.ctrlKey;
315
+ const k = e.key.toLowerCase();
316
+ if (mod && !e.altKey && ((k === "k" && !e.shiftKey) || (mac && k === "j" && !e.shiftKey))) {
317
+ e.preventDefault();
318
+ e.stopPropagation();
319
+ dl ? dl.close() : openSearch();
320
+ }
321
+ },
322
+ true,
323
+ );
324
+ }
@@ -26,6 +26,7 @@ export async function openSettings() {
26
26
  if (!$("panel").classList.contains("open") || $("ptitle").textContent !== "Settings") {
27
27
  $("pbody").innerHTML = SKEL;
28
28
  $("psub").textContent = "";
29
+ store.setScope = store.all ? "all" : store.dir || store.S.dir || "all";
29
30
  }
30
31
  termStop();
31
32
  store.openKey = null;
@@ -37,9 +38,14 @@ export async function openSettings() {
37
38
  $("ptabs").innerHTML = "";
38
39
  $("pfoot").innerHTML = "";
39
40
  const cur = document.documentElement.dataset.theme || "system";
40
- const cfg = await fetch("/settings")
41
- .then((r) => r.json())
41
+ let cfg = await fetch("/settings?scope=" + encodeURIComponent(store.setScope))
42
+ .then((r) => (r.ok ? r.json() : null))
42
43
  .catch(() => null);
44
+ // A project the board no longer knows: fall back to All projects.
45
+ if (!cfg && store.setScope !== "all") {
46
+ store.setScope = "all";
47
+ return openSettings();
48
+ }
43
49
  const gg = await fetch("/google")
44
50
  .then((r) => r.json())
45
51
  .catch(() => ({}));
@@ -65,20 +71,40 @@ export async function openSettings() {
65
71
  return html`<span class="step" id="${id}" role="group" aria-labelledby="${id}-l"><button id="${id}-prev" aria-label="Previous">‹</button><output aria-live="polite">${on === "" ? "—" : on}</output><button id="${id}-next" aria-label="Next">›</button></span>`;
66
72
  };
67
73
  // `off`: the row has no effect while another setting stands as it is; dimmed, still editable.
74
+ const onOff = (v) => (v === "true" ? "on" : v === "false" ? "off" : v === "" ? "—" : v);
75
+ const scoped = cfg && cfg.scope !== "all";
76
+ // What else a row says about its scope: projects that set it otherwise, or a Reset
77
+ // for a value this project sets itself.
78
+ const scopeNote = (r, id) =>
79
+ r.own
80
+ ? html`Set for this project · <button class="sreset" id="${id}-reset" type="button">Reset</button>`
81
+ : r.overrides?.length
82
+ ? r.overrides.map((o) => `${o.label}: ${onOff(o.value)}`).join(", ")
83
+ : "";
68
84
  const row = (label, control, hint, id, q, off = false) =>
69
85
  html`<div class="srow${off ? " off" : ""}" data-q="${q.toLowerCase()}"><label for="${id}" id="${id}-l">${label}</label>${control}${hint ? html`<p class="hint">${hint}</p>` : ""}</div>`;
70
86
  const hadFocus = document.activeElement?.id === "sq";
71
87
  const np = typeof Notification === "undefined" ? null : Notification.permission;
72
88
  const nton = notifyOn();
73
89
  const ntHelp = !nton ? "Off in this browser" : np === "granted" ? "" : np === "denied" ? "Pop-ups blocked by this browser; the sound still plays" : np ? "Pop-ups wait for the browser to ask; the sound still plays" : "Pop-ups not supported here; the sound still plays";
90
+ const scopeRow = cfg
91
+ ? html`<div class="sgrp">${row(
92
+ "Settings for",
93
+ html`<select class="sel" id="s-scope">${[{ dir: "all", label: "All projects" }, ...cfg.projects].map((p) => html`<option value="${p.dir}"${p.dir === cfg.scope ? " selected" : ""}>${p.label}</option>`)}</select>`,
94
+ scoped ? "This project's own .kaizen/config.yml; anything it does not set comes from All projects." : "~/.kaizen/config.yml; a project's own config wins where it sets a value.",
95
+ "s-scope",
96
+ "settings for scope project all projects",
97
+ )}</div>`
98
+ : "";
74
99
  $("pbody").innerHTML = html`<div class="sq"><input class="sel" id="sq" type="search" placeholder="Search settings" aria-label="Search settings" spellcheck="false" autocomplete="off" value="${store.setQ}"></div>
100
+ ${scopeRow}
75
101
  <h3 class="sg">Phone</h3><div class="sgrp">${row("Phone address", cfg?.phoneUrls?.length ? html`<span class="phoneurls">${cfg.phoneUrls.map((url) => html`<a href="${url}" target="_blank" rel="noopener">${url}</a>`)}</span>` : html`<span>Not set</span>`, cfg?.phoneUrls?.length ? "Configured address; Tailscale must be running on both devices." : "Run kaizen setup on this PC to connect your phone.", "phone-url", "phone address url tailscale setup")}</div>
76
102
  ${
77
103
  cfg
78
104
  ? groups(cfg.rows)
79
105
  .map(
80
106
  ([g, rows]) =>
81
- html`<h3 class="sg">${g}</h3><div class="sgrp">${rows
107
+ html`<h3 class="sg">${g}${scoped && g === "Board" ? " · all projects" : ""}</h3><div class="sgrp">${rows
82
108
  .map((r) => {
83
109
  const id = "s-" + r.key.replace(/\./g, "-");
84
110
  return row(
@@ -88,7 +114,7 @@ export async function openSettings() {
88
114
  ? html`<span class="fpick"><input class="sel" id="${id}" value="${r.value}" placeholder="not set" spellcheck="false"><button class="btn" id="${id}-pick" type="button">Browse…</button></span>`
89
115
  : html`<input class="sel" id="${id}" value="${r.value}" placeholder="not set" spellcheck="false">`
90
116
  : ctl(id, r.values, r.value),
91
- [r.help, r.idle].filter(Boolean).join(" · "),
117
+ ((t, n) => (t && n ? html`${t} · ${n}` : n || t))([r.help, r.idle].filter(Boolean).join(" · "), scopeNote(r, id)),
92
118
  id,
93
119
  [r.label, r.help, r.key, g, ...r.values].join(" "),
94
120
  !!r.idle,
@@ -203,12 +229,23 @@ export async function openSettings() {
203
229
  } catch (e) {}
204
230
  playSound(v);
205
231
  });
232
+ if (cfg)
233
+ $("s-scope").onchange = (e) => {
234
+ store.setScope = e.target.value;
235
+ openSettings();
236
+ };
206
237
  if (cfg)
207
238
  cfg.rows.forEach((r) => {
208
239
  const el = $("s-" + r.key.replace(/\./g, "-"));
240
+ if (r.own)
241
+ $(el.id + "-reset").onclick = async () => {
242
+ const j = await post("/settings", { key: r.key, scope: cfg.scope, reset: true });
243
+ toast(j.ok ? "Reset to All projects" : j.error || "Could not reset");
244
+ openSettings();
245
+ };
209
246
  const save = async (v) => {
210
247
  const f = document.activeElement?.id;
211
- const j = await post("/settings", { key: r.key, value: v });
248
+ const j = await post("/settings", { key: r.key, value: v, scope: cfg.scope });
212
249
  if (j.ok) toast("Saved");
213
250
  await refocus(f);
214
251
  };
@@ -2,7 +2,7 @@
2
2
  // panel's tab and doc, and the page filters. Everything else lives in the module that
3
3
  // owns it.
4
4
  export const store = {
5
- S: { project: null, projects: [], cards: [], now: Date.now(), all: false },
5
+ S: { project: null, projects: [], cards: [], now: Date.now(), all: false, dir: null as string | null },
6
6
  all: new URLSearchParams(location.search).get("all") !== "0",
7
7
  // The project this page picked; null is wherever the board started.
8
8
  dir: null,
@@ -23,6 +23,8 @@ export const store = {
23
23
  shells: [] as { key: string; dir: string; title: string; agent: string }[],
24
24
  // The settings search survives the re-render each save does; the gear button starts it empty.
25
25
  setQ: "",
26
+ // Settings' scope: "all" or a project's state dir. Set on opening; never moves the board.
27
+ setScope: "all",
26
28
  // Settings and the Icebox fill the same panel after a fetch: a fill only lands if no other view
27
29
  // or fill started since, or a slow answer paints one page under the other's title.
28
30
  pageGen: 0,
@@ -44,7 +44,10 @@ let actx;
44
44
  export function playSound(name = soundPick()) {
45
45
  try {
46
46
  if (SAMPLES.includes(name)) {
47
- new Audio(`/sounds/${name}.mp3`).play().catch(() => {});
47
+ const a = new Audio(`/sounds/${name}.mp3`);
48
+ // The samples peak at 0 dBFS and clip on desktop speakers at full volume; about -9 dB.
49
+ a.volume = 0.35;
50
+ a.play().catch(() => {});
48
51
  return;
49
52
  }
50
53
  if (!NOTES[name]) return;
@@ -27,6 +27,8 @@ export const markView = (v) => {
27
27
  export function go(v, push) {
28
28
  store.pageGen++;
29
29
  if (v === "icebox") v = "sources";
30
+ // A workspace address shows in the run view, which resolves it to a card.
31
+ if (v === "ws") v = "run";
30
32
  if (!["settings", "sources", "terminal", "board", "ideas", "run", "chat", "device"].includes(v)) v = "home";
31
33
  // A phone has Home, Chat, Runs and Settings: the board, Ideas and the Icebox are set up on a computer,
32
34
  // whose Home is the chat.
@@ -61,7 +63,7 @@ export function go(v, push) {
61
63
  openPhone(ph ? "home" : v === "device" ? "device" : null);
62
64
  if (v === "ideas") openIdeas();
63
65
  // After the panel handling below, which closes the board's panel on the way in.
64
- if (v === "run") queueMicrotask(() => void showRunView());
66
+ if (v === "run") queueMicrotask(() => void showRunView(true));
65
67
  // The Terminal page is the board's own area, not the docked panel: the panel closes as on the board.
66
68
  if (AREA.includes(v)) {
67
69
  if (AREA.includes(was)) {