kaizen-agent 1.73.0 → 1.75.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/web/term.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  // The in-card terminal: xterm.js on the board's /pty WebSocket. Bundled into
2
2
  // web/term.js by `bun run build:web`; the board loads it (`termLoad` in web/board/agent-term.ts) the first time a card's
3
3
  // Terminal tab opens and calls window.kzTerm(el, key).
4
+ import { trackTerminalViewport } from "./board/terminal-viewport.ts";
4
5
  import { Terminal } from "@xterm/xterm";
5
6
  import { FitAddon } from "@xterm/addon-fit";
6
7
  import { WebglAddon } from "@xterm/addon-webgl";
@@ -144,6 +145,7 @@ function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void
144
145
  send({ t: "i", d });
145
146
  });
146
147
  let bar: HTMLElement | null = null;
148
+ let stopViewport = () => {};
147
149
  if (matchMedia("(pointer: coarse)").matches) {
148
150
  const arrow = (c: string) => () => `\x1b${term.modes.applicationCursorKeysMode ? "O" : "["}${c}`;
149
151
  // A terminal carries no pictures: an image is saved on the board's computer and its path
@@ -180,12 +182,12 @@ function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void
180
182
  // pointerdown + preventDefault: a tap must not move focus off the terminal, nor
181
183
  // close the soft keyboard while the message box is being typed in. The key itself
182
184
  // fires on click, which the browser drops when the touch becomes a swipe of the row.
183
- const key = (label: string, fn: () => void) => {
185
+ const key = (label: string, fn: () => void, focus = true) => {
184
186
  const b = document.createElement("button");
185
187
  b.type = "button";
186
188
  b.textContent = label;
187
189
  b.addEventListener("pointerdown", (e) => e.preventDefault());
188
- b.addEventListener("click", () => { fn(); if (document.activeElement !== msg) term.focus(); });
190
+ b.addEventListener("click", () => { fn(); if (focus && document.activeElement !== msg) term.focus(); });
189
191
  return b;
190
192
  };
191
193
  const chips = document.createElement("div");
@@ -209,14 +211,7 @@ function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void
209
211
  const more = document.createElement("div");
210
212
  more.className = "tmore";
211
213
  more.hidden = true;
212
- const raw = key("Raw keyboard", () => {
213
- more.hidden = true;
214
- if (!ta) return;
215
- const on = raw.classList.toggle("on");
216
- ta.inputMode = on ? "text" : "none";
217
- ta.blur(); // inputmode is read on focus; the key's term.focus() reopens it
218
- });
219
- more.append(key("Search", () => { more.hidden = true; openSearch(); }), key("Paste", () => { more.hidden = true; void paste(); }), key("Pick image", () => { more.hidden = true; picker.click(); }), raw);
214
+ more.append(key("Search", () => { more.hidden = true; openSearch(); }), key("Paste", () => { more.hidden = true; void paste(); }), key("Pick image", () => { more.hidden = true; picker.click(); }));
220
215
  for (const [label, v] of keys) {
221
216
  const b = key(label, () => {
222
217
  if (v === "alt") b.classList.toggle("on", (mods.alt = !mods.alt));
@@ -235,19 +230,148 @@ function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void
235
230
  msg.enterKeyHint = "send";
236
231
  msg.autocomplete = "off";
237
232
  msg.setAttribute("aria-label", "Message the agent");
238
- const go = document.createElement("button");
239
- go.textContent = "➤";
240
- go.setAttribute("aria-label", "Send");
241
- go.addEventListener("pointerdown", (e) => e.preventDefault()); // keep the keyboard up
242
- form.append(msg, go);
233
+ const rawKeyboard = document.createElement("button");
234
+ rawKeyboard.type = "button";
235
+ rawKeyboard.className = "rawkeyboard";
236
+ rawKeyboard.innerHTML = '<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><rect x="2" y="5" width="20" height="13" rx="2"/><path d="M6 9h.01M10 9h.01M14 9h.01M18 9h.01M6 12h.01M10 12h.01M14 12h.01M18 12h.01M7 15h10"/></svg>';
237
+ rawKeyboard.setAttribute("aria-label", "Type directly in terminal");
238
+ rawKeyboard.title = "Raw keyboard";
239
+ rawKeyboard.setAttribute("aria-pressed", "false");
240
+ rawKeyboard.onclick = () => {
241
+ showPanel("");
242
+ if (!ta) return;
243
+ const on = ta.inputMode !== "text";
244
+ ta.inputMode = on ? "text" : "none";
245
+ ta.blur();
246
+ rawKeyboard.setAttribute("aria-pressed", String(on));
247
+ if (on) term.focus();
248
+ };
249
+ rawKeyboard.addEventListener("pointerdown", (e) => e.preventDefault()); // keep the keyboard up
250
+ form.append(msg, rawKeyboard);
251
+ msg.addEventListener("keydown", (e) => {
252
+ if (e.key === "Enter" && !e.isComposing) { e.preventDefault(); form.requestSubmit(); }
253
+ });
243
254
  form.addEventListener("submit", (e) => {
244
255
  e.preventDefault();
245
- if (msg.value) send({ t: "i", d: msg.value });
256
+ if (msg.value) {
257
+ const text = msg.value;
258
+ try { localStorage.setItem("kz-term-history", JSON.stringify([text, ...readHistory().filter((s) => s !== text)].slice(0, 100))); } catch { /* typing works without storage */ }
259
+ send({ t: "i", d: text });
260
+ }
246
261
  msg.value = "";
247
262
  setTimeout(() => send({ t: "i", d: "\r" }), 60);
248
263
  });
249
- bar.append(pad, more, chips, form, picker);
264
+ // The rightmost composer toggle replaces the native keyboard with a compact
265
+ // accessory panel. History only loads the composer; it never executes a command.
266
+ const grid = document.createElement("div");
267
+ grid.className = "termgrid";
268
+ grid.hidden = true;
269
+ const extras: [string, string | (() => string)][] = [
270
+ ["⇧ Tab", "\x1b[Z"], ["?", "?"], ["/", "/"],
271
+ ["Esc", "\x1b"], ["Tab", "\t"],
272
+ ["^C", "\x03"], ["^D", "\x04"], ["^Z", "\x1a"],
273
+ ["↑", arrow("A")], ["↓", arrow("B")], ["←", arrow("D")], ["→", arrow("C")],
274
+ ["Home", "\x1b[H"], ["PgUp", "\x1b[5~"], ["PgDn", "\x1b[6~"], ["End", "\x1b[F"],
275
+ ..."= : ; ! * $ % ^ < > ( ) { } [ ] | ~ - @".split(" ").map((c): [string, string] => [c, c]),
276
+ ["Del", "\x1b[3~"], ["Ins", "\x1b[2~"], ["↵", "\r"],
277
+ ...Array.from({ length: 12 }, (_, i): [string, string] => [
278
+ `F${i + 1}`, i < 4 ? `\x1bO${"PQRS"[i]}` : `\x1b[${[15, 17, 18, 19, 20, 21, 23, 24][i - 4]}~`,
279
+ ]),
280
+ ];
281
+ for (const [label, value] of extras) grid.append(key(label, () => {
282
+ send({ t: "i", d: (mods.alt ? "\x1b" : "") + (typeof value === "function" ? value() : value) });
283
+ mods.alt = false;
284
+ bar?.querySelectorAll(".alt").forEach((b) => b.classList.remove("on"));
285
+ }));
286
+ grid.insertBefore(key("Image", () => picker.click()), grid.children[3]);
287
+ grid.insertBefore(key("Ctrl", () => { pad.hidden = !pad.hidden; }), grid.children[6]);
288
+ const alt = key("Alt", () => {
289
+ mods.alt = !mods.alt;
290
+ bar?.querySelectorAll(".alt").forEach((b) => b.classList.toggle("on", mods.alt));
291
+ });
292
+ alt.className = "alt";
293
+ grid.insertBefore(alt, grid.children[7]);
294
+ grid.append(key("Paste", () => { void paste(); }));
295
+ const history = document.createElement("div");
296
+ history.className = "termhistory";
297
+ history.hidden = true;
298
+ const filter = document.createElement("input");
299
+ filter.type = "search";
300
+ filter.placeholder = "Search history";
301
+ filter.setAttribute("aria-label", "Search terminal message history");
302
+ const list = document.createElement("div");
303
+ const readHistory = (): string[] => {
304
+ try {
305
+ const value = JSON.parse(localStorage.getItem("kz-term-history") ?? "[]");
306
+ return Array.isArray(value) ? value.filter((s): s is string => typeof s === "string").slice(0, 100) : [];
307
+ } catch { return []; }
308
+ };
309
+ const drawHistory = () => {
310
+ list.replaceChildren();
311
+ for (const text of readHistory().filter((s) => s.toLowerCase().includes(filter.value.toLowerCase()))) {
312
+ const use = document.createElement("button");
313
+ use.type = "button";
314
+ use.textContent = text;
315
+ use.title = "Load into message field";
316
+ use.onclick = () => { msg.value = text; showPanel(""); msg.focus(); };
317
+ list.append(use);
318
+ }
319
+ if (!list.childElementCount) list.textContent = "No messages in history.";
320
+ };
321
+ filter.oninput = drawHistory;
322
+ history.append(filter, list);
323
+ const dock = document.createElement("nav");
324
+ dock.className = "termdock";
325
+ dock.hidden = true;
326
+ dock.setAttribute("aria-label", "Terminal accessory panel");
327
+ const icon = (paths: string) => `<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${paths}</svg>`;
328
+ const keyboardIcon = icon('<rect x="3" y="4" width="7" height="7" rx="1"/><rect x="14" y="4" width="7" height="7" rx="1"/><rect x="3" y="15" width="7" height="7" rx="1"/><rect x="14" y="15" width="7" height="7" rx="1"/>');
329
+ const historyIcon = icon('<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>');
330
+ const toggle = key("", () => showPanel(panel ? "" : "keys"), false);
331
+ toggle.className = "termtoggle";
332
+ toggle.innerHTML = keyboardIcon;
333
+ toggle.setAttribute("aria-label", "Show keyboard and history");
334
+ toggle.setAttribute("aria-expanded", "false");
335
+ form.append(toggle);
336
+ let panel = "";
337
+ const showPanel = (next: string) => {
338
+ panel = next;
339
+ grid.hidden = next !== "keys";
340
+ history.hidden = next !== "history";
341
+ dock.hidden = !next;
342
+ chips.hidden = !!next;
343
+ pad.hidden = more.hidden = true;
344
+ toggle.classList.toggle("on", !!next);
345
+ toggle.setAttribute("aria-expanded", String(!!next));
346
+ for (const b of dock.querySelectorAll<HTMLButtonElement>("[data-panel]")) {
347
+ const active = b.dataset.panel === next;
348
+ b.classList.toggle("on", active);
349
+ b.setAttribute("aria-pressed", String(active));
350
+ }
351
+ if (next) {
352
+ if (ta) ta.inputMode = "none";
353
+ rawKeyboard.setAttribute("aria-pressed", "false");
354
+ msg.blur();
355
+ ta?.blur();
356
+ }
357
+ if (next === "history") drawHistory();
358
+ };
359
+ for (const [label, name, svg] of [["Keyboard", "keys", keyboardIcon], ["History", "history", historyIcon]]) {
360
+ const b = key("", () => showPanel(name), false);
361
+ b.innerHTML = svg;
362
+ b.dataset.panel = name;
363
+ b.setAttribute("aria-label", label);
364
+ b.title = label;
365
+ dock.append(b);
366
+ }
367
+ msg.addEventListener("focus", () => {
368
+ showPanel("");
369
+ if (ta) ta.inputMode = "none";
370
+ rawKeyboard.setAttribute("aria-pressed", "false");
371
+ });
372
+ bar.append(form, pad, more, chips, grid, history, dock, picker);
250
373
  el.after(bar);
374
+ stopViewport = trackTerminalViewport();
251
375
  }
252
376
  // xterm.js has no touch scrolling, so on a phone a swipe did nothing. Each line's
253
377
  // worth of swipe scrolls the buffer, or — when the agent tracks the mouse, as a
@@ -369,6 +493,7 @@ function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void
369
493
  el.removeEventListener("touchstart", touchStart);
370
494
  el.removeEventListener("touchmove", touchMove);
371
495
  typed.dispose();
496
+ stopViewport();
372
497
  bar?.remove();
373
498
  tools.remove();
374
499
  clearTimeout(retry);
package/web/video.html CHANGED
@@ -141,7 +141,7 @@ body .rail a.upd::after{left:calc(50% + 6px);top:4px}body .toast{left:16px;botto
141
141
  @media(max-width:640px){
142
142
  .rail a.it:is([data-view=board],[data-view=tasks],[data-view=sources]),#foot,#ctx-open,body .rail .rbot .rib{display:none!important}
143
143
  .rail a.it.ponly{display:flex}
144
- .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]{display:none}
144
+ .rail a.it[data-view=device]{order:1}.rail a.it.gs-it{order:2}.rail a.it[data-view=home]{order:3}.rail a.it[data-view=chat]{order:4}.rail a.it[data-view=terminal]{order:5}.rail a.it[data-view=settings]{display:none}
145
145
  .rail,[data-rail=min] .rail{padding:8px 8px max(2px,calc(env(safe-area-inset-bottom) - 8px));border-top:1px solid color-mix(in srgb,var(--line) 70%,transparent)}
146
146
  .rail a.it,[data-rail=min] .rail a.it{min-height:46px;gap:3px;font-size:10.5px;letter-spacing:.01em}
147
147
  .rail a.it svg{width:44px;height:26px;padding:4px 12px;box-sizing:border-box;border-radius:13px;transition:background .15s}
@@ -380,11 +380,13 @@ pre.mark span:nth-child(1){color:var(--ink-hi)}pre.mark span:nth-child(2){color:
380
380
  <symbol id="r-desk" viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="12" rx="2"/><path d="M8 20h8M12 16v4"/></symbol>
381
381
  <symbol id="r-chat" viewBox="0 0 24 24"><path d="M21 12a8 8 0 0 1-11.6 7.1L4 20l1-4.6A8 8 0 1 1 21 12z"/></symbol>
382
382
  <symbol id="r-runs" viewBox="0 0 24 24"><path d="M9 6h11M9 12h11M9 18h11"/><circle cx="4.5" cy="6" r="1.2"/><circle cx="4.5" cy="12" r="1.2"/><circle cx="4.5" cy="18" r="1.2"/></symbol>
383
+ <symbol id="r-term" viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="16" rx="2"/><path d="m7 9 3 3-3 3M13 15h4"/></symbol>
383
384
  </defs></svg>
384
385
  <a class="it gs-it" href="#" id="gsearch" title="Search everything"><svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="7" fill="none" stroke="currentColor" stroke-width="2"/><path d="M20 20l-4-4" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg><span class="lbl">Search</span></a>
385
386
  <a class="it" href="/" data-view="home" title="Home: chat with the project's agent"><svg><use href="#i-home"/></svg><span class="lbl">Home</span></a>
386
387
  <a class="it ponly" href="/?view=chat" data-view="chat" title="Chat with kaizen's agent"><svg><use href="#r-chat"/></svg><span class="lbl">Chat</span></a>
387
388
  <a class="it ponly" href="/?view=device" data-view="device" title="This computer's runs"><svg><use href="#r-runs"/></svg><span class="lbl">Runs</span></a>
389
+ <a class="it ponly" href="/?view=terminal" data-view="terminal" title="Open terminals across all projects"><svg><use href="#r-term"/></svg><span class="lbl">Terminal</span></a>
388
390
  <a class="it fold" href="/?view=icebox" data-view="sources" title="Icebox: requests gathered from your sources"><svg><use href="#r-tray"/></svg><span class="lbl">Icebox</span><span class="srcs" id="rail-srcs"></span><span class="n" id="ice-n"></span></a>
389
391
  <a class="it" href="/?view=tasks" data-view="tasks" title="Tasks: every task and run, filtered"><svg><use href="#r-bulb"/></svg><span class="lbl">Tasks</span></a>
390
392
  <a class="it" href="/?setup=1" id="rsetup" hidden title="Continue setup"><span class="ring"></span><span class="lbl">Setup</span></a>