Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
description: Existing release tag to publish or retry
required: true
type: choice
options: [ext-v0.4.2, terminal-v0.4.3, terminal-v0.4.2, ext-v0.4.1, terminal-v0.4.1, dsh-v0.4.0, terminal-v0.4.0, ext-v0.4.0, dsh-v0.3.0, terminal-v0.3.0, ext-v0.3.0, dsh-v0.2.0, terminal-v0.2.0, terminal-v0.2.1, ext-v0.2.0, ext-v0.2.1]
options: [terminal-v0.4.4, ext-v0.4.2, terminal-v0.4.3, terminal-v0.4.2, ext-v0.4.1, terminal-v0.4.1, dsh-v0.4.0, terminal-v0.4.0, ext-v0.4.0, dsh-v0.3.0, terminal-v0.3.0, ext-v0.3.0, dsh-v0.2.0, terminal-v0.2.0, terminal-v0.2.1, ext-v0.2.0, ext-v0.2.1]
push:
tags: ["ext-v*", "dsh-v*", "terminal-v*"]

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Terminal host 0.4.4 — 2026-11-05

- Keep a WebGL terminal renderer across Focus and Chill modes to improve typing and scrolling under dense output. Preserve translucent ANSI/truecolor backgrounds, opaque text, selection and cursor, with a DOM fallback when GPU rendering is unavailable.
- Bound large output writes, coalesce cumulative acknowledgements and drain the host output queue in linear time. Avoid redundant PTY pause/resume calls, viewport updates and presentation changes.
- Preserve ordinary text selection, copy, TUI mouse input and keyboard mode switching. Keep 3,000 lines of scrollback.
- This patch ships with terminal host 0.4.4. Extension 0.4.2, DSH 0.4.0 and connector protocol 1 remain unchanged. Finish live shells, then run `aow update` from a separate macOS Terminal.

## Extension 0.4.2 — 2026-10-29

- Drag the floating AgentOnWeb icon with a mouse, trackpad or touch to uncover page controls. Remember its position across pages and reloads, and adapt it when the window changes size.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ For Pi 1.1+, run `pi` in the same terminal. Setup adds `extensions/agentonweb.ts

Use **+** in the terminal tab bar to open another project, click a tab to switch, double-click its name to rename it, or click **×** to close it. Hiding the workspace or refreshing the page keeps your sessions running.

Terminal host 0.4.3 checks for stable npm updates daily and shows reminders in its private management page. Use `aow check-update` to check now or `aow check-update --disable` to turn automatic checks off. After closing live terminals, run `aow update` in a separate macOS Terminal; `aow service restart` reloads already-installed code. CLI 0.4.3 also supports `aow update --force` to reinstall and restart a verified older service, ending its live tasks. If an older CLI cannot prepare an update, finish terminal work, run `aow service uninstall`, then rerun the installer once.
Terminal host 0.4.4 checks for stable npm updates daily and shows reminders in its private management page. Use `aow check-update` to check now or `aow check-update --disable` to turn automatic checks off. After closing live terminals, run `aow update` in a separate macOS Terminal; `aow service restart` reloads already-installed code. CLI 0.4.3 also supports `aow update --force` to reinstall and restart a verified older service, ending its live tasks. If an older CLI cannot prepare an update, finish terminal work, run `aow service uninstall`, then rerun the installer once.

[Setup and troubleshooting](docs/one-command-setup.md) · [Terminal guide](packages/terminal-host/README.md)

Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ codex

点击终端标签栏的 **+** 打开另一个项目,点击标签切换,双击名称重命名,点击 **×** 关闭。隐藏工作区或刷新网页不会中断正在运行的会话。

终端主机 0.4.3 每天检查 npm 正式版,并在本地管理页显示更新提醒。运行 `aow check-update` 可立即检查,`aow check-update --disable` 可关闭自动检查。退出或关闭所有终端后,在 Mac 的独立“终端”窗口运行 `aow update` 升级;`aow service restart` 用于加载已安装的新代码。CLI 0.4.3 还支持通过 `aow update --force` 重新安装并重启已核实归属的旧服务,这会结束其活动任务。如果旧 CLI 提示无法准备更新,请先完成终端任务,运行 `aow service uninstall`,再重新运行安装命令一次。
终端主机 0.4.4 每天检查 npm 正式版,并在本地管理页显示更新提醒。运行 `aow check-update` 可立即检查,`aow check-update --disable` 可关闭自动检查。退出或关闭所有终端后,在 Mac 的独立“终端”窗口运行 `aow update` 升级;`aow service restart` 用于加载已安装的新代码。CLI 0.4.3 还支持通过 `aow update --force` 重新安装并重启已核实归属的旧服务,这会结束其活动任务。如果旧 CLI 提示无法准备更新,请先完成终端任务,运行 `aow service uninstall`,再重新运行安装命令一次。

[安装与常见问题](docs/one-command-setup.md) · [终端指南](packages/terminal-host/README.md)

Expand Down
5 changes: 3 additions & 2 deletions apps/terminal-surface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"build": "node ../../scripts/build-terminal-surface.mjs"
},
"dependencies": {
"@xterm/xterm": "^5.5.0",
"@xterm/addon-fit": "^0.10.0"
"@xterm/addon-fit": "^0.10.0",
"@xterm/addon-webgl": "0.18.0",
"@xterm/xterm": "5.5.0"
},
"devDependencies": {
"@agentonweb/connector-contract": "workspace:*"
Expand Down
26 changes: 26 additions & 0 deletions apps/terminal-surface/src/cell-backgrounds.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { JSDOM } from "jsdom";
import type { Terminal } from "@xterm/xterm";
import { afterEach, expect, it, vi } from "vitest";
import { installCellBackgroundOpacity } from "./cell-backgrounds.js";

let dom: JSDOM;
afterEach(() => { dom?.window.close(); });
it("does no cell traversal for opaque output or unchanged presentation", () => {
dom = new JSDOM('<main><div class="xterm-rows"><div><span style="background-color:rgb(32,71,51)">Text</span></div></div></main>');
const container = dom.window.document.querySelector("main")!;
let render!: (range: { start: number; end: number }) => void;
const setOpacity = installCellBackgroundOpacity({ onRender(fn: typeof render) { render = fn; } } as Terminal, container);
const query = vi.spyOn(container, "querySelector");
for (let i = 0; i < 100; i++) render({ start: 0, end: 0 });
setOpacity(1);
expect(query).not.toHaveBeenCalled();
setOpacity(0.4);
query.mockClear();
setOpacity(0.4);
expect(query).not.toHaveBeenCalled();
setOpacity(1);
expect(container.querySelector("span")!.style.backgroundColor).toBe("rgb(32, 71, 51)");
query.mockClear();
render({ start: 0, end: 0 });
expect(query).not.toHaveBeenCalled();
});
90 changes: 61 additions & 29 deletions apps/terminal-surface/src/cell-backgrounds.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,81 @@
import type { Terminal } from "@xterm/xterm";

// xterm's DOM renderer paints ANSI cell backgrounds independently of the theme
// background. Adjust only their rendered colors, leaving PTY attributes intact.
function translucent(color: string, opacity: number): string | undefined {
const hex = /^#([\da-f]{6})$/iu.exec(color);
if (hex) {
const value = Number.parseInt(hex[1]!, 16);
return `rgba(${value >> 16}, ${(value >> 8) & 255}, ${value & 255}, ${opacity})`;
}
const rgb = /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)$/u.exec(color);
if (rgb) return `rgba(${rgb[1]}, ${rgb[2]}, ${rgb[3]}, ${Number(rgb[4] ?? 1) * opacity})`;
return undefined;
}

// Palette backgrounds are shared CSS rules, so changing their opacity must not
// read computed styles and rewrite thousands of cells on every frame. Only
// truecolor backgrounds need per-cell work. PTY attributes stay untouched.
export function installCellBackgroundOpacity(terminal: Terminal, container: HTMLElement) {
let opacity = 1;
const originals = new WeakMap<HTMLElement, { inline: string; channels: string[] }>();
const originals = new WeakMap<HTMLElement, string>();
const style = container.ownerDocument.createElement("style");
container.append(style);
let themeStyle: HTMLStyleElement | undefined;
let observer: MutationObserver | undefined;
function updatePalette() {
const rules: string[] = [];
if (opacity !== 1) {
for (const rule of themeStyle?.sheet?.cssRules ?? []) {
const css = rule as CSSStyleRule;
if (!/\.xterm-bg-\d+$/u.test(css.selectorText ?? "")) continue;
const color = translucent(css.style.getPropertyValue("background-color"), opacity);
if (color) rules.push(`${css.selectorText}:not(.xterm-cursor):not(.xterm-decoration-top){background-color:${color}}`);
}
}
const text = rules.join("\n");
if (style.textContent !== text) style.textContent = text;
}
function ensurePalette() {
if (themeStyle?.isConnected) return;
observer?.disconnect();
themeStyle = [...container.querySelectorAll<HTMLStyleElement>(".xterm-screen style")]
.find(candidate => candidate.textContent?.includes(".xterm-bg-"));
if (themeStyle) {
observer = new container.ownerDocument.defaultView!.MutationObserver(updatePalette);
observer.observe(themeStyle, { childList: true, characterData: true, subtree: true });
}
updatePalette();
}
function render(start = 0, end = Infinity) {
const rows = container.querySelector(".xterm-rows")?.children;
if (!rows) return;
const palette = new Map<string, string>();
// Reuse conversions within each frame without retaining arbitrary RGB colors.
const colors = new Map<string, string | undefined>();
for (let row = start; row <= end && row < rows.length; row++) {
for (const cell of rows[row]!.querySelectorAll<HTMLElement>("span")) {
// Preserve xterm's cursor and selection contrast.
if (cell.matches(".xterm-cursor, .xterm-decoration-top")) continue;
let original = originals.get(cell);
for (const cell of rows[row]!.querySelectorAll<HTMLElement>('span[style*="background-color"]:not(.xterm-cursor):not(.xterm-decoration-top)')) {
const saved = originals.get(cell);
if (opacity === 1) {
if (original) {
cell.style.backgroundColor = original.inline;
originals.delete(cell);
}
if (saved !== undefined) { cell.style.backgroundColor = saved; originals.delete(cell); }
continue;
}
if (!original) {
const inline = cell.style.backgroundColor;
let color = inline;
if (!color) {
const colorClass = [...cell.classList].find(name => name.startsWith("xterm-bg-"));
if (!colorClass) continue;
color = palette.get(colorClass) ?? container.ownerDocument.defaultView!.getComputedStyle(cell).backgroundColor;
palette.set(colorClass, color);
}
const match = /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)$/u.exec(color);
if (!match || Number(match[4] ?? 1) === 0) continue;
original = { inline, channels: match.slice(1) };
originals.set(cell, original);
}
const [red, green, blue, alpha] = original.channels;
const color = `rgba(${red}, ${green}, ${blue}, ${Number(alpha ?? 1) * opacity})`;
const original = saved ?? cell.style.backgroundColor;
if (!colors.has(original)) colors.set(original, translucent(original, opacity));
const color = colors.get(original);
if (!color) continue;
originals.set(cell, original);
if (cell.style.backgroundColor !== color) cell.style.backgroundColor = color;
}
}
}
terminal.onRender(({ start, end }) => render(start, end));
terminal.onRender(({ start, end }) => {
if (opacity === 1) return;
ensurePalette();
render(start, end);
});
return (nextOpacity: number) => {
if (nextOpacity === opacity) return;
opacity = nextOpacity;
ensurePalette();
updatePalette();
render();
};
}
56 changes: 51 additions & 5 deletions apps/terminal-surface/src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { JSDOM } from "jsdom";
import { afterEach, expect, it, vi } from "vitest";
const terminalMock = vi.hoisted(() => ({
focus: vi.fn(),
theme: vi.fn(),
writes: [] as (() => void)[],
input: undefined as ((data: string) => void) | undefined,
binary: undefined as ((data: string) => void) | undefined,
}));
vi.mock("@xterm/xterm", () => ({
Terminal: class {
options: any = {};
options: any = Object.defineProperty({}, "theme", { set: terminalMock.theme });
modes = { mouseTrackingMode: "none" };
parser = { registerCsiHandler() {}, registerOscHandler() {} };
loadAddon() {}
Expand All @@ -36,6 +37,7 @@ vi.mock("@xterm/addon-fit", () => ({
}
},
}));
vi.mock("@xterm/addon-webgl", () => ({ WebglAddon: class {} }));
let dom: JSDOM;
afterEach(() => {
dom.window.close();
Expand All @@ -44,20 +46,22 @@ afterEach(() => {
vi.resetModules();
terminalMock.writes.length = 0;
terminalMock.focus.mockClear();
terminalMock.theme.mockClear();
terminalMock.input = terminalMock.binary = undefined;
});
async function terminalFixture() {
dom = new JSDOM(await readFile(new URL("./index.html", import.meta.url), "utf8"), { url: "http://localhost:1234/" });
async function terminalFixture(hash = "") {
dom = new JSDOM(await readFile(new URL("./index.html", import.meta.url), "utf8"), { url: "http://localhost:1234/" + hash });
for (const key of ["window", "document", "location", "sessionStorage"]) vi.stubGlobal(key, (dom.window as any)[key]);
vi.stubGlobal("parent", dom.window);
vi.stubGlobal("ResizeObserver", class { observe() {} });
vi.useFakeTimers({ toFake: ["setTimeout", "setInterval"] });
vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout", "setInterval", "clearInterval"] });
const sockets: any[] = [];
vi.stubGlobal("WebSocket", class {
static OPEN = 1;
readyState = 1;
constructor() { sockets.push(this); }
send() {}
sent: any[] = [];
send(data: string) { this.sent.push(JSON.parse(data)); }
close() { this.readyState = 3; }
});
let failure = 0;
Expand All @@ -74,6 +78,48 @@ async function terminalFixture() {
return { sockets, list, fetch, fail: (status: number) => { failure = status; } };
}

it("coalesces parsed output ACKs while keyboard input is sent immediately", async () => {
const { sockets } = await terminalFixture();
const socket = sockets[0];
const emit = (message: object) => socket.onmessage({ data: JSON.stringify(message) });
emit({ type: "snapshot", epoch: "one", cols: 80, rows: 24, data: "" });
terminalMock.writes.shift()!();
emit({ type: "control", epoch: "one", lease: 1, active: true });
socket.sent.length = 0;
for (let sequence = 1; sequence <= 100; sequence++) {
emit({ type: "output", epoch: "one", sequence, data: "x" });
terminalMock.writes.shift()!();
}
terminalMock.input!("typed now");
expect(socket.sent).toEqual([{ type: "input", epoch: "one", lease: 1, data: "typed now" }]);
await vi.advanceTimersByTimeAsync(0);
expect(socket.sent.at(-1)).toEqual({ type: "ack", sequence: 100 });
expect(socket.sent).toHaveLength(2);
emit({ type: "output", epoch: "one", sequence: 101, data: "late" });
terminalMock.writes.shift()!();
socket.onclose({ code: 1006 });
await vi.advanceTimersByTimeAsync(0);
expect(socket.sent).toHaveLength(2);
});

it("does not repaint on focus messages, duplicate modes or inactive opacity changes", async () => {
await terminalFixture("#agentonweb=fixture");
const emit = (extra: object) => dom.window.dispatchEvent(new dom.window.MessageEvent("message", {
source: dom.window as unknown as Window, origin: "chrome-extension://fixture",
data: { source: "agentonweb-extension", nonce: "fixture", ...extra },
}));
emit({ type: "surface.focus" });
emit({ type: "mode.set", mode: "focus" });
emit({ type: "opacity.set", opacity: 0.4 });
expect(terminalMock.theme).not.toHaveBeenCalled();
emit({ type: "mode.set", mode: "chill" });
emit({ type: "mode.set", mode: "chill" });
emit({ type: "opacity.set", opacity: 0.4 });
expect(terminalMock.theme).toHaveBeenCalledTimes(1);
emit({ type: "mode.set", mode: "focus" });
expect(terminalMock.theme).toHaveBeenCalledTimes(2);
});

it("continues automatic retries after a temporary HTTP failure and stops on revoked access", async () => {
const fixture = await terminalFixture();
fixture.fail(503);
Expand Down
Loading