Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(verse): paint the takeover terminal as it is typed (#1054)

Ruben Lütke9977d2ebff88
diff --git a/dodaios/ui/web/frontend/src/components/agentic/AgenticTerminal.offscreen.test.tsx b/dodaios/ui/web/frontend/src/components/agentic/AgenticTerminal.offscreen.test.tsx
index 94beb1ab4e..512d41d704 100644
--- a/dodaios/ui/web/frontend/src/components/agentic/AgenticTerminal.offscreen.test.tsx
+++ b/dodaios/ui/web/frontend/src/components/agentic/AgenticTerminal.offscreen.test.tsx
@@ -83,6 +83,7 @@ vi.mock("@xterm/xterm", () => ({
harness.writes.push(RESET);
}
resize() {}
+ refresh() {}
dispose() {}
clearTextureAtlas() {}
},
@@ -119,6 +120,7 @@ vi.mock("@/lib/agenticIdeApi", () => ({ attachToTerminal: vi.fn() }));
import { AgenticTerminal } from "./AgenticTerminal";
import { OFFSCREEN_MAX_HOLD_MS } from "./offscreenBuffer";
+import { presentTerminal } from "@/lib/liveTerminals";
class ResizeObserverHarness implements ResizeObserver {
constructor(_callback: ResizeObserverCallback) {}
@@ -199,6 +201,32 @@ describe("AgenticTerminal off-screen output", () => {
expect(harness.writes).toEqual(["frame one frame two frame three"]);
});
+ it("writes immediately while the Verse window is showing a parked pane", () => {
+ // The IDE tile is off the stage for the whole time the office covers it.
+ // Holding the echo until OFFSCREEN_MAX_HOLD_MS is the one-second lag.
+ const view = render(
+ <AgenticTerminal
+ name="Dana"
+ workspaceId="ws"
+ displayName="Claude Code"
+ appearance="dark"
+ fontSize={13}
+ active={false}
+ />,
+ );
+ const host = document.createElement("div");
+ const release = presentTerminal("ws", ["Dana"], host);
+ expect(release).toEqual(expect.any(Function));
+ act(() => harness.fire?.(false));
+ harness.writes = [];
+
+ act(() => harness.handlers?.onOutput("echo"));
+
+ expect(harness.writes).toContain("echo");
+ release?.();
+ view.unmount();
+ });
+
it("writes a flooded hidden pane out rather than losing its frame", () => {
// The bytes that DREW the agent's interface sit at the FRONT of the
// stream, and an Ink-based TUI never repaints it unprompted. A hidden pane
diff --git a/dodaios/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx b/dodaios/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
index 2de67c4aa5..e15f5dcd6e 100644
--- a/dodaios/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
+++ b/dodaios/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
@@ -145,6 +145,7 @@ import {
} from "./offscreenBuffer";
import { installQuerySuppression } from "./terminalQueries";
import { installSynchronizedOutput } from "./terminalSynchronizedOutput";
+import { keepPresentedRendererAwake, wakePresentedRenderer } from "./presentedRenderer";
import { FULL_SCREEN_ERASE_SCAN_TAIL, hasFullScreenErase } from "./terminalRepaint";
import {
bindTerminalScrollRegion,
@@ -1396,8 +1397,16 @@ export function AgenticTerminal({
const showPane = (afterFlush?: () => void) => {
// The Verse window is a reader even while the IDE tile is off the stage.
if (!activeRef.current && !presentedHost) return;
+ // Output held for a size the hidden tile never had would sit until the
+ // offscreen deadline — about a second — while the user is already
+ // typing into the window. The window is measurable; the report is not
+ // what they are waiting on.
+ if (presentedHost && awaitingSizeReport && measurable()) {
+ awaitingSizeReport = false;
+ }
if (paneVisible) {
- afterFlush?.();
+ if (awaitingSizeReport) afterFlush?.();
+ else flushHeld(afterFlush);
return;
}
paneVisible = true;
@@ -1426,6 +1435,12 @@ export function AgenticTerminal({
* state: the document becoming visible again, and the pane being resized.
*/
const revealIfOnScreen = () => {
+ // The IDE tile is off the stage on purpose while the window has the
+ // xterm. That must not count as "nobody is looking".
+ if (presentedHost) {
+ showPane();
+ return;
+ }
if (!activeRef.current) return;
if (paneVisible) return;
const box = container.getBoundingClientRect();
@@ -1566,8 +1581,21 @@ export function AgenticTerminal({
// offscreen still counts as painted. It has a screen; nobody is looking
// at it. Cheap to call per chunk: React bails out on an unchanged value.
setPainted(true);
- if (!paneVisible) recheckParked();
- if (paneVisible && !awaitingSizeReport) {
+ // The Verse window is the reader. Parking its bytes until
+ // OFFSCREEN_MAX_HOLD_MS is the pause between a keystroke and the glyph:
+ // the hidden IDE tile is not the surface being watched, and a paused
+ // xterm renderer would keep the previous frame even after the write.
+ if (presentedHost && awaitingSizeReport && measurable()) {
+ awaitingSizeReport = false;
+ }
+ // Recheck BEFORE the decision. A parked pane that is actually on screen
+ // un-parks itself here, and this same chunk is what the user is waiting
+ // to see — reading the flag from before the recheck parked it again.
+ if (!paneVisible && !presentedHost) recheckParked();
+ if ((paneVisible || presentedHost !== null) && !awaitingSizeReport) {
+ if (presentedHost) wakePresentedRenderer(term);
+ // Older parked bytes belong under this chunk, never after it.
+ if (offscreen.pending > 0) flushHeld();
writeToTerminal(text, afterWrite);
return;
}
@@ -1994,6 +2022,7 @@ export function AgenticTerminal({
let presentedWatch: ResizeObserver | null = null;
let presentedTimer: number | undefined;
let releasePresentedExtras = () => {};
+ let releasePresentedRenderer = () => {};
const releasePresented = () => {
if (!presentedHost) return;
if (presentedTimer !== undefined) window.clearTimeout(presentedTimer);
@@ -2001,6 +2030,8 @@ export function AgenticTerminal({
presentedWatch?.disconnect();
presentedWatch = null;
presentedHost = null;
+ releasePresentedRenderer();
+ releasePresentedRenderer = () => {};
releasePresentedExtras();
releasePresentedExtras = () => {};
const element = term.element;
@@ -2014,6 +2045,9 @@ export function AgenticTerminal({
presentedHost = host;
const element = term.element;
if (element && element.parentElement !== host) host.appendChild(element);
+ // Before the flush below, so the bytes just released actually land on
+ // the canvas and a late intersection entry cannot pause them again.
+ releasePresentedRenderer = keepPresentedRendererAwake(term);
attachTerminalBridge(host, {
getSelection: () => term.getSelection(),
paste: (text) => term.paste(text),
@@ -2033,7 +2067,10 @@ export function AgenticTerminal({
presentedTimer = window.setTimeout(() => {
presentedTimer = undefined;
// This window is the one the user is reading, so it takes the size.
- if (presentedHost) sendResize(true);
+ if (!presentedHost) return;
+ wakePresentedRenderer(term);
+ showPane();
+ sendResize(true);
}, 80);
});
presentedWatch.observe(host);
diff --git a/dodaios/ui/web/frontend/src/components/agentic/presentedRenderer.test.ts b/dodaios/ui/web/frontend/src/components/agentic/presentedRenderer.test.ts
new file mode 100644
index 0000000000..59984f5a73
--- /dev/null
+++ b/dodaios/ui/web/frontend/src/components/agentic/presentedRenderer.test.ts
@@ -0,0 +1,59 @@
+import { describe, expect, it, vi } from "vitest";
+import type { Terminal } from "@xterm/xterm";
+import { keepPresentedRendererAwake, wakePresentedRenderer } from "./presentedRenderer";
+
+interface FakeService {
+ _isPaused: boolean;
+ _needsFullRefresh: boolean;
+ _rowCount: number;
+ _pausedResizeTask: { flush: ReturnType<typeof vi.fn> };
+ _handleIntersectionChange: (entry: { isIntersecting?: boolean }) => void;
+ refreshRows: ReturnType<typeof vi.fn>;
+}
+
+function fakeTerm(paused: boolean) {
+ const service: FakeService = {
+ _isPaused: paused,
+ _needsFullRefresh: paused,
+ _rowCount: 24,
+ _pausedResizeTask: { flush: vi.fn() },
+ _handleIntersectionChange(entry) {
+ this._isPaused = entry.isIntersecting === false;
+ },
+ refreshRows: vi.fn(),
+ };
+ const term = {
+ rows: 24,
+ refresh: vi.fn(),
+ _core: { _renderService: service },
+ };
+ return { term: term as unknown as Terminal, service };
+}
+
+describe("presented renderer", () => {
+ it("unpauses a renderer that still thinks it is off screen", () => {
+ const { term, service } = fakeTerm(true);
+ wakePresentedRenderer(term);
+ expect(service._isPaused).toBe(false);
+ expect(service._pausedResizeTask.flush).toHaveBeenCalledOnce();
+ expect(service.refreshRows).toHaveBeenCalledWith(0, 23);
+ });
+
+ it("leaves a renderer that is already drawing alone", () => {
+ const { term, service } = fakeTerm(false);
+ wakePresentedRenderer(term);
+ expect(service.refreshRows).not.toHaveBeenCalled();
+ });
+
+ it("ignores a late not-intersecting entry until the window lets go", () => {
+ const { term, service } = fakeTerm(true);
+ const release = keepPresentedRendererAwake(term);
+ expect(service._isPaused).toBe(false);
+ expect(service.refreshRows).toHaveBeenCalled();
+ service._handleIntersectionChange({ isIntersecting: false });
+ expect(service._isPaused).toBe(false);
+ release();
+ service._handleIntersectionChange({ isIntersecting: false });
+ expect(service._isPaused).toBe(true);
+ });
+});
diff --git a/dodaios/ui/web/frontend/src/components/agentic/presentedRenderer.ts b/dodaios/ui/web/frontend/src/components/agentic/presentedRenderer.ts
new file mode 100644
index 0000000000..3a624c5428
--- /dev/null
+++ b/dodaios/ui/web/frontend/src/components/agentic/presentedRenderer.ts
@@ -0,0 +1,100 @@
+/**
+ * Keep a borrowed xterm painting while the Verse window shows it.
+ *
+ * xterm's RenderService pauses itself when its own IntersectionObserver says
+ * the screen element is off screen, and `refresh` then draws nothing. The
+ * IDE tile is off screen for the whole time the office covers it, and moving
+ * the element into the window does not reliably deliver a new "intersecting"
+ * entry in the desktop WebView. The buffer still takes the bytes — including
+ * the echo of a key the user just typed — and the canvas keeps the previous
+ * frame. Waking it, and ignoring that observer until the window gives the
+ * element back, is what makes the window update on the same frame as the IDE.
+ */
+import type { Terminal } from "@xterm/xterm";
+
+interface PausableRenderService {
+ _isPaused?: boolean;
+ _needsFullRefresh?: boolean;
+ _rowCount?: number;
+ _pausedResizeTask?: { flush?: () => void };
+ _handleIntersectionChange?: (entry: IntersectionObserverEntry) => void;
+ refreshRows?: (start: number, end: number, isRedrawOnly?: boolean) => void;
+}
+
+function renderService(term: Terminal): PausableRenderService | undefined {
+ return (term as unknown as { _core?: { _renderService?: PausableRenderService } })._core
+ ?._renderService;
+}
+
+function paintNow(term: Terminal, service: PausableRenderService): void {
+ const rows = service._rowCount ?? term.rows;
+ service._needsFullRefresh = false;
+ try {
+ if (typeof service.refreshRows === "function" && rows > 0) {
+ service.refreshRows(0, rows - 1);
+ return;
+ }
+ } catch {
+ /* the renderer is being torn down — nothing left to paint */
+ }
+ if (rows > 0) {
+ try {
+ term.refresh(0, rows - 1);
+ } catch {
+ /* same teardown */
+ }
+ }
+}
+
+/** Unpause a renderer that still believes it is off screen. A no-op while it is already drawing. */
+export function wakePresentedRenderer(term: Terminal): void {
+ const service = renderService(term);
+ if (!service || service._isPaused !== true) return;
+ service._isPaused = false;
+ try {
+ service._pausedResizeTask?.flush?.();
+ } catch {
+ /* a resize queued while paused belongs to a renderer that is going away */
+ }
+ paintNow(term, service);
+}
+
+/**
+ * Hold the renderer awake for the life of a presentation.
+ *
+ * The observer stays attached to the screen element. A late "not intersecting"
+ * entry — queued while the element still sat in the hidden tile — would pause
+ * it again between keystrokes. Returns the restore, which the release of the
+ * window calls so the tile can park normally once the element is back.
+ */
+export function keepPresentedRendererAwake(term: Terminal): () => void {
+ const service = renderService(term);
+ if (!service || typeof service._handleIntersectionChange !== "function") {
+ wakePresentedRenderer(term);
+ if (term.rows > 0) {
+ try {
+ term.refresh(0, term.rows - 1);
+ } catch {
+ /* tearing down */
+ }
+ }
+ return () => {};
+ }
+ const original = service._handleIntersectionChange;
+ const ignore = function (this: PausableRenderService) {
+ this._isPaused = false;
+ };
+ service._handleIntersectionChange = ignore;
+ service._isPaused = false;
+ try {
+ service._pausedResizeTask?.flush?.();
+ } catch {
+ /* see wakePresentedRenderer */
+ }
+ paintNow(term, service);
+ return () => {
+ if (service._handleIntersectionChange === ignore) {
+ service._handleIntersectionChange = original;
+ }
+ };
+}
diff --git a/dodaios/ui/web/frontend/src/components/society/verse/verse.css b/dodaios/ui/web/frontend/src/components/society/verse/verse.css
index 931cf25b8e..aea7d9ce44 100644
--- a/dodaios/ui/web/frontend/src/components/society/verse/verse.css
+++ b/dodaios/ui/web/frontend/src/components/society/verse/verse.css
@@ -586,6 +586,10 @@
}
.verse-takeover-host { position: absolute; inset: 0; z-index: 1; }
.verse-takeover-host:empty { pointer-events: none; }
+/* Once the xterm is in the window its canvas is transparent, and the polled
+ replay sits underneath. An opaque host keeps that replay from showing
+ through and reading as a one-second-late copy of the screen. */
+.verse-takeover-host:not(:empty) { background: #0b0c0f; }
.verse-takeover-host > .xterm { width: 100%; height: 100%; }
/* The server's replay, until the pane's own xterm is in the window. Same face as the terminal: monospace on black. */
.verse-takeover-replay {