kaizen-agent 1.75.0 → 1.76.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
@@ -226,7 +226,7 @@ function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void
226
226
  // pair as a paste and keeps the newline in its input instead of submitting.
227
227
  const form = document.createElement("form");
228
228
  form.className = "compose";
229
- msg.placeholder = "Message the agent…";
229
+ msg.placeholder = "Paste text here...";
230
230
  msg.enterKeyHint = "send";
231
231
  msg.autocomplete = "off";
232
232
  msg.setAttribute("aria-label", "Message the agent");
@@ -266,32 +266,52 @@ function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void
266
266
  const grid = document.createElement("div");
267
267
  grid.className = "termgrid";
268
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, () => {
269
+ const press = (value: string | (() => string)) => {
282
270
  send({ t: "i", d: (mods.alt ? "\x1b" : "") + (typeof value === "function" ? value() : value) });
283
271
  mods.alt = false;
284
272
  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]);
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");
288
294
  const alt = key("Alt", () => {
289
295
  mods.alt = !mods.alt;
290
296
  bar?.querySelectorAll(".alt").forEach((b) => b.classList.toggle("on", mods.alt));
291
297
  });
292
298
  alt.className = "alt";
293
- grid.insertBefore(alt, grid.children[7]);
294
- grid.append(key("Paste", () => { void paste(); }));
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]}~`);
295
315
  const history = document.createElement("div");
296
316
  history.className = "termhistory";
297
317
  history.hidden = true;
@@ -306,9 +326,24 @@ function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void
306
326
  return Array.isArray(value) ? value.filter((s): s is string => typeof s === "string").slice(0, 100) : [];
307
327
  } catch { return []; }
308
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
+ };
309
343
  const drawHistory = () => {
310
344
  list.replaceChildren();
311
- for (const text of readHistory().filter((s) => s.toLowerCase().includes(filter.value.toLowerCase()))) {
345
+ const entries = [...new Set([...readHistory(), ...savedHistory])];
346
+ for (const text of entries.filter((s) => s.toLowerCase().includes(filter.value.toLowerCase()))) {
312
347
  const use = document.createElement("button");
313
348
  use.type = "button";
314
349
  use.textContent = text;
@@ -316,7 +351,11 @@ function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void
316
351
  use.onclick = () => { msg.value = text; showPanel(""); msg.focus(); };
317
352
  list.append(use);
318
353
  }
319
- if (!list.childElementCount) list.textContent = "No messages in history.";
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.";
320
359
  };
321
360
  filter.oninput = drawHistory;
322
361
  history.append(filter, list);
@@ -354,7 +393,7 @@ function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void
354
393
  msg.blur();
355
394
  ta?.blur();
356
395
  }
357
- if (next === "history") drawHistory();
396
+ if (next === "history") void loadHistory();
358
397
  };
359
398
  for (const [label, name, svg] of [["Keyboard", "keys", keyboardIcon], ["History", "history", historyIcon]]) {
360
399
  const b = key("", () => showPanel(name), false);