kaizen-agent 1.74.0 → 1.75.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.
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));
@@ -231,23 +226,191 @@ function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void
231
226
  // pair as a paste and keeps the newline in its input instead of submitting.
232
227
  const form = document.createElement("form");
233
228
  form.className = "compose";
234
- msg.placeholder = "Message the agent…";
229
+ msg.placeholder = "Paste text here...";
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 press = (value: string | (() => string)) => {
270
+ send({ t: "i", d: (mods.alt ? "\x1b" : "") + (typeof value === "function" ? value() : value) });
271
+ mods.alt = false;
272
+ bar?.querySelectorAll(".alt").forEach((b) => b.classList.remove("on"));
273
+ };
274
+ const group = (name: string) => {
275
+ const section = document.createElement("div");
276
+ section.className = "termkeygroup " + name;
277
+ grid.append(section);
278
+ return section;
279
+ };
280
+ const add = (parent: HTMLElement, label: string, value: string | (() => string), position?: string) => {
281
+ const b = key(label, () => press(value));
282
+ if (position) b.style.gridArea = position;
283
+ parent.append(b);
284
+ return b;
285
+ };
286
+ const primary = group("primary");
287
+ add(primary, "Esc", "\x1b", "1 / 1");
288
+ add(primary, "Tab", "\t", "1 / 2");
289
+ add(primary, "⇧ Tab", "\x1b[Z", "1 / 3");
290
+ primary.append(key("Ctrl", () => { pad.hidden = !pad.hidden; }));
291
+ add(primary, "^C", "\x03", "2 / 1");
292
+ add(primary, "^D", "\x04", "2 / 2");
293
+ add(primary, "^Z", "\x1a", "2 / 3");
294
+ const alt = key("Alt", () => {
295
+ mods.alt = !mods.alt;
296
+ bar?.querySelectorAll(".alt").forEach((b) => b.classList.toggle("on", mods.alt));
297
+ });
298
+ alt.className = "alt";
299
+ alt.style.gridArea = "2 / 4";
300
+ primary.append(alt);
301
+ add(primary, "↑", arrow("A"), "1 / 6");
302
+ add(primary, "←", arrow("D"), "2 / 5");
303
+ add(primary, "↓", arrow("B"), "2 / 6");
304
+ add(primary, "→", arrow("C"), "2 / 7");
305
+ const enter = add(primary, "↵", "\r", "1 / 8 / span 2 / 9");
306
+ enter.setAttribute("aria-label", "Enter");
307
+ enter.className = "enter";
308
+ const navigation = group("navigation");
309
+ for (const [label, value] of [["Home", "\x1b[H"], ["End", "\x1b[F"], ["PgUp", "\x1b[5~"], ["PgDn", "\x1b[6~"], ["Ins", "\x1b[2~"], ["Del", "\x1b[3~"]]) add(navigation, label, value);
310
+ navigation.append(key("Paste", () => { void paste(); }), key("Image", () => picker.click()));
311
+ const symbols = group("symbols");
312
+ for (const c of "? / = : ; ! * $ % ^ < > ( ) { } [ ] | ~ - @".split(" ")) add(symbols, c, c);
313
+ const functions = group("functions");
314
+ for (let i = 0; i < 12; i++) add(functions, `F${i + 1}`, i < 4 ? `\x1bO${"PQRS"[i]}` : `\x1b[${[15, 17, 18, 19, 20, 21, 23, 24][i - 4]}~`);
315
+ const history = document.createElement("div");
316
+ history.className = "termhistory";
317
+ history.hidden = true;
318
+ const filter = document.createElement("input");
319
+ filter.type = "search";
320
+ filter.placeholder = "Search history";
321
+ filter.setAttribute("aria-label", "Search terminal message history");
322
+ const list = document.createElement("div");
323
+ const readHistory = (): string[] => {
324
+ try {
325
+ const value = JSON.parse(localStorage.getItem("kz-term-history") ?? "[]");
326
+ return Array.isArray(value) ? value.filter((s): s is string => typeof s === "string").slice(0, 100) : [];
327
+ } catch { return []; }
328
+ };
329
+ let savedHistory: string[] = [];
330
+ let historyStatus = "";
331
+ const loadHistory = async () => {
332
+ historyStatus = "Loading shell history…";
333
+ drawHistory();
334
+ try {
335
+ const response = await fetch("/pty/history", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ key }) });
336
+ if (!response.ok) throw new Error("history unavailable");
337
+ const data = await response.json();
338
+ savedHistory = Array.isArray(data.history) ? data.history.filter((s: unknown): s is string => typeof s === "string") : [];
339
+ historyStatus = "";
340
+ } catch { historyStatus = "Could not load shell history. Reopen History to retry."; }
341
+ drawHistory();
342
+ };
343
+ const drawHistory = () => {
344
+ list.replaceChildren();
345
+ const entries = [...new Set([...readHistory(), ...savedHistory])];
346
+ for (const text of entries.filter((s) => s.toLowerCase().includes(filter.value.toLowerCase()))) {
347
+ const use = document.createElement("button");
348
+ use.type = "button";
349
+ use.textContent = text;
350
+ use.title = "Load into message field";
351
+ use.onclick = () => { msg.value = text; showPanel(""); msg.focus(); };
352
+ list.append(use);
353
+ }
354
+ if (historyStatus) {
355
+ const status = document.createElement("p");
356
+ status.textContent = historyStatus;
357
+ list.append(status);
358
+ } else if (!list.childElementCount) list.textContent = filter.value ? "No matching commands." : "No saved shell commands or messages yet.";
359
+ };
360
+ filter.oninput = drawHistory;
361
+ history.append(filter, list);
362
+ const dock = document.createElement("nav");
363
+ dock.className = "termdock";
364
+ dock.hidden = true;
365
+ dock.setAttribute("aria-label", "Terminal accessory panel");
366
+ 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>`;
367
+ 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"/>');
368
+ const historyIcon = icon('<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>');
369
+ const toggle = key("", () => showPanel(panel ? "" : "keys"), false);
370
+ toggle.className = "termtoggle";
371
+ toggle.innerHTML = keyboardIcon;
372
+ toggle.setAttribute("aria-label", "Show keyboard and history");
373
+ toggle.setAttribute("aria-expanded", "false");
374
+ form.append(toggle);
375
+ let panel = "";
376
+ const showPanel = (next: string) => {
377
+ panel = next;
378
+ grid.hidden = next !== "keys";
379
+ history.hidden = next !== "history";
380
+ dock.hidden = !next;
381
+ chips.hidden = !!next;
382
+ pad.hidden = more.hidden = true;
383
+ toggle.classList.toggle("on", !!next);
384
+ toggle.setAttribute("aria-expanded", String(!!next));
385
+ for (const b of dock.querySelectorAll<HTMLButtonElement>("[data-panel]")) {
386
+ const active = b.dataset.panel === next;
387
+ b.classList.toggle("on", active);
388
+ b.setAttribute("aria-pressed", String(active));
389
+ }
390
+ if (next) {
391
+ if (ta) ta.inputMode = "none";
392
+ rawKeyboard.setAttribute("aria-pressed", "false");
393
+ msg.blur();
394
+ ta?.blur();
395
+ }
396
+ if (next === "history") void loadHistory();
397
+ };
398
+ for (const [label, name, svg] of [["Keyboard", "keys", keyboardIcon], ["History", "history", historyIcon]]) {
399
+ const b = key("", () => showPanel(name), false);
400
+ b.innerHTML = svg;
401
+ b.dataset.panel = name;
402
+ b.setAttribute("aria-label", label);
403
+ b.title = label;
404
+ dock.append(b);
405
+ }
406
+ msg.addEventListener("focus", () => {
407
+ showPanel("");
408
+ if (ta) ta.inputMode = "none";
409
+ rawKeyboard.setAttribute("aria-pressed", "false");
410
+ });
411
+ bar.append(form, pad, more, chips, grid, history, dock, picker);
250
412
  el.after(bar);
413
+ stopViewport = trackTerminalViewport();
251
414
  }
252
415
  // xterm.js has no touch scrolling, so on a phone a swipe did nothing. Each line's
253
416
  // worth of swipe scrolls the buffer, or — when the agent tracks the mouse, as a
@@ -369,6 +532,7 @@ function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void
369
532
  el.removeEventListener("touchstart", touchStart);
370
533
  el.removeEventListener("touchmove", touchMove);
371
534
  typed.dispose();
535
+ stopViewport();
372
536
  bar?.remove();
373
537
  tools.remove();
374
538
  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>