kaizen-agent 1.40.0 → 1.40.2

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
@@ -3,6 +3,7 @@
3
3
  // Terminal tab opens and calls window.kzTerm(el, key).
4
4
  import { Terminal } from "@xterm/xterm";
5
5
  import { FitAddon } from "@xterm/addon-fit";
6
+ import { WebglAddon } from "@xterm/addon-webgl";
6
7
 
7
8
  function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void {
8
9
  const css = getComputedStyle(el);
@@ -22,6 +23,13 @@ function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void
22
23
  const fit = new FitAddon();
23
24
  term.loadAddon(fit);
24
25
  term.open(el);
26
+ // The DOM renderer lags on a full-screen agent's constant redraws; WebGL keeps up.
27
+ // No WebGL, or the context lost: xterm.js falls back to the DOM renderer by itself.
28
+ try {
29
+ const gl = new WebglAddon();
30
+ gl.onContextLoss(() => gl.dispose());
31
+ term.loadAddon(gl);
32
+ } catch { /* DOM renderer */ }
25
33
 
26
34
  const ws = new WebSocket(
27
35
  `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}/pty?key=${encodeURIComponent(key)}`,
@@ -140,12 +148,16 @@ function mountTerm(el: HTMLElement, key: string, onEnd?: () => void): () => void
140
148
  };
141
149
  el.addEventListener("touchstart", touchStart, { passive: true });
142
150
  el.addEventListener("touchmove", touchMove, { passive: false });
143
- const ro = new ResizeObserver(size);
151
+ // Each resize makes the agent redraw its whole screen, so a panel animating or a
152
+ // soft keyboard opening sends one, not dozens.
153
+ let resizing: Timer | undefined;
154
+ const ro = new ResizeObserver(() => { clearTimeout(resizing); resizing = setTimeout(size, 100); });
144
155
  ro.observe(el);
145
156
  term.focus();
146
157
 
147
158
  return () => {
148
159
  ro.disconnect();
160
+ clearTimeout(resizing);
149
161
  el.removeEventListener("touchstart", touchStart);
150
162
  el.removeEventListener("touchmove", touchMove);
151
163
  typed.dispose();