kaizen-agent 1.85.2 → 1.86.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
@@ -9,6 +9,7 @@ import { WebLinksAddon } from "@xterm/addon-web-links";
9
9
  import { SearchAddon } from "@xterm/addon-search";
10
10
  import { Unicode11Addon } from "@xterm/addon-unicode11";
11
11
  import { fontRead, fontSet, fontStep } from "./term-font.ts";
12
+ import { imageFiles, pathsText } from "./term-paste.ts";
12
13
 
13
14
  // Orca's defaults (its "Ghostty Default Style Dark" and "Builtin Tango Light"): a terminal's ANSI
14
15
  // palette is content, not board chrome, so these hex values are the one exception to design.md's
@@ -199,6 +200,57 @@ function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void
199
200
  onEnd?.();
200
201
  };
201
202
  };
203
+ // A terminal carries no pictures: an image is saved on the board's computer and its path
204
+ // typed in, which is how Claude Code and Codex take one. Used by desktop paste and drop, and
205
+ // by the phone's Paste and Pick image keys. A refused image says why instead of doing nothing.
206
+ const note = (text: string) => {
207
+ const n = document.createElement("div");
208
+ n.className = "termnote";
209
+ n.setAttribute("role", "status");
210
+ n.textContent = text;
211
+ n.style.cssText = "position:absolute;right:12px;bottom:12px;z-index:5;padding:6px 10px;border-radius:6px;font:12px system-ui,sans-serif;background:#000c;color:#fff;pointer-events:none";
212
+ (el.querySelector(".xterm") ?? el).append(n); // .xterm is position:relative
213
+ setTimeout(() => n.remove(), 4000);
214
+ };
215
+ const upload = async (b: Blob) => {
216
+ const r = await fetch("/term-image", { method: "POST", headers: { "content-type": b.type || "image/png" }, body: b }).catch(() => null);
217
+ if (r?.ok) return String((await r.json()).path ?? "");
218
+ const why = r ? String((await r.json().catch(() => ({}))).error ?? r.status) : "the board did not answer";
219
+ note(`Image not pasted: ${why}`);
220
+ return "";
221
+ };
222
+ const sendImages = async (files: Blob[]) => {
223
+ const text = pathsText(await Promise.all(files.map(upload)));
224
+ if (text) term.paste(text);
225
+ };
226
+ const sendImage = (b: Blob) => sendImages([b]);
227
+ // Ctrl+V / Cmd+V on a desktop: xterm reads only text from the clipboard, so a screenshot
228
+ // (Windows Snipping Tool, Print Screen, macOS Cmd+Ctrl+Shift+4) pasted nothing. Capture runs
229
+ // before xterm's own handler on its textarea. Text wins whenever there is any: Excel and Word
230
+ // put a picture of the selection beside its text, and the text is what was meant.
231
+ const pasteOff = new AbortController();
232
+ el.addEventListener("paste", (e) => {
233
+ if (e.clipboardData?.getData("text/plain")) return;
234
+ const files = imageFiles(e.clipboardData?.files);
235
+ if (!files.length) return;
236
+ e.preventDefault();
237
+ e.stopPropagation();
238
+ void sendImages(files);
239
+ }, { capture: true, signal: pasteOff.signal });
240
+ // Dropping image files onto the terminal does the same.
241
+ el.addEventListener("dragover", (e) => {
242
+ if (![...(e.dataTransfer?.items ?? [])].some((i) => i.kind === "file")) return;
243
+ e.preventDefault();
244
+ if (e.dataTransfer) e.dataTransfer.dropEffect = "copy";
245
+ }, { signal: pasteOff.signal });
246
+ el.addEventListener("drop", (e) => {
247
+ const all = [...(e.dataTransfer?.files ?? [])];
248
+ if (!all.length) return;
249
+ e.preventDefault();
250
+ const files = imageFiles(e.dataTransfer?.files);
251
+ if (files.length) void sendImages(files);
252
+ else note("Only images can be dropped here");
253
+ }, { signal: pasteOff.signal });
202
254
  // Phone/tablet: a row of chips for the keys a soft keyboard lacks, and a message box
203
255
  // that types into the agent and presses Enter. Alt is sticky for the next key. Ctrl
204
256
  // opens its own a-z pad instead of waiting on the native keyboard, whose IME can
@@ -214,13 +266,6 @@ function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void
214
266
  let stopViewport = () => {};
215
267
  if (matchMedia("(pointer: coarse)").matches) {
216
268
  const arrow = (c: string) => () => `\x1b${term.modes.applicationCursorKeysMode ? "O" : "["}${c}`;
217
- // A terminal carries no pictures: an image is saved on the board's computer and its path
218
- // typed in, which is how Claude Code and Codex take one.
219
- const sendImage = async (b: Blob) => {
220
- const r = await fetch("/term-image", { method: "POST", headers: { "content-type": b.type || "image/png" }, body: b }).catch(() => null);
221
- const path = r?.ok ? (await r.json()).path : "";
222
- if (path) term.paste(/\s/.test(path) ? `"${path}" ` : `${path} `);
223
- };
224
269
  const paste = async () => {
225
270
  const items = await navigator.clipboard?.read?.().catch(() => []) ?? [];
226
271
  for (const it of items) {
@@ -596,6 +641,7 @@ function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void
596
641
  term.focus();
597
642
 
598
643
  return () => {
644
+ pasteOff.abort();
599
645
  ro.disconnect();
600
646
  clearTimeout(resizing);
601
647
  cancelAnimationFrame(frame);