Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(glyphgrid): clamp the shared camera, so a stored zoom of 0 cannot blank the board
enes237a65ec8e6c
diff --git a/src/renderer/canvas/SharedGlyphLayer.tsx b/src/renderer/canvas/SharedGlyphLayer.tsxindex dbad9421a..703a9be4c 100644--- a/src/renderer/canvas/SharedGlyphLayer.tsx+++ b/src/renderer/canvas/SharedGlyphLayer.tsx@@ -40,7 +40,7 @@ import {type GlyphAtlasSubscription,type GlyphSlotAllocation} from '../glyphgrid/atlas'-import type { Camera } from '../glyphgrid/camera'+import { sanitizeCamera, type Camera } from '../glyphgrid/camera'import { GlyphGridEngine } from '../glyphgrid/engine'import { setBlankCellProbe } from '../glyphgrid/feed'import { createFrameLoop, type FrameLoop } from '../glyphgrid/frame-driver'@@ -1284,9 +1284,15 @@ export function getSharedGlyphContext(deviceCell?: DeviceCell): SharedGlyphConte}/** Camera feed. Always records (so a context created later opens at the right place) and only- * reaches the engine — which change-gates it — when one exists. */+ * reaches the engine — which change-gates it — when one exists.+ *+ * SANITIZED HERE, at the boundary, rather than at any one call site: the camera arrives from a live+ * React Flow gesture (already clamped) AND from a persisted project viewport (clamped by nothing),+ * and a zoom of 0 or NaN from the second blanks every terminal on the canvas at once. See+ * `sanitizeCamera` for why that is invisible everywhere else. One funnel means a future third+ * caller cannot reintroduce it. */export function setSharedGlyphCamera(cam: Camera): void {- lastCamera = { x: cam.x, y: cam.y, zoom: cam.zoom }+ lastCamera = sanitizeCamera(cam)live?.engine.setCamera(lastCamera)}diff --git a/src/renderer/glyphgrid/camera.test.ts b/src/renderer/glyphgrid/camera.test.tsindex 5813b936c..0ee11ffd2 100644--- a/src/renderer/glyphgrid/camera.test.ts+++ b/src/renderer/glyphgrid/camera.test.ts@@ -1,6 +1,8 @@import { describe, expect, it } from 'vitest'import {+ MIN_CAMERA_ZOOM,rectsIntersect,+ sanitizeCamera,screenToWorld,snapPanToDevicePx,visibleWorldRect,@@ -83,3 +85,54 @@ describe('snapPanToDevicePx', () => {expect(snapped.x).toBe(1)})})++/**+ * The WHOLE-CANVAS blank, from a persisted viewport. A project saved with `zoom: 0` (or a viewport+ * that reached the file as NaN) makes `visibleWorldRect` infinite or NaN, `rectsIntersect` false for+ * every grid, and every terminal on the board empty — while the DOM node chrome looks perfect,+ * because React Flow clamps its own transform and the glyph camera used not to.+ */+describe('sanitizeCamera', () => {+ it('passes an ordinary camera through unchanged', () => {+ expect(sanitizeCamera({ x: -120.5, y: 40, zoom: 0.75 })).toEqual({+ x: -120.5,+ y: 40,+ zoom: 0.75+ })+ })++ it('clamps a zoom of 0 to the floor, which is what stops visibleWorldRect going infinite', () => {+ const cam = sanitizeCamera({ x: 0, y: 0, zoom: 0 })+ expect(cam.zoom).toBe(MIN_CAMERA_ZOOM)+ const rect = visibleWorldRect(cam, 1600, 900)+ expect(Number.isFinite(rect.w)).toBe(true)+ expect(Number.isFinite(rect.h)).toBe(true)+ })++ it('clamps a NaN / non-finite / negative zoom, so culling never compares against NaN', () => {+ for (const zoom of [NaN, Infinity, -Infinity, -1]) {+ const cam = sanitizeCamera({ x: 0, y: 0, zoom })+ expect(cam.zoom).toBe(MIN_CAMERA_ZOOM)+ // The blank canvas IS this comparison: with a NaN rect every grid answers false and nothing+ // is ever drawn.+ const r = visibleWorldRect(cam, 1600, 900)+ expect(rectsIntersect(r, { x: 0, y: 0, w: 800, h: 600 })).toBe(true)+ }+ })++ it('replaces a non-finite PAN with 0 rather than letting it poison the rect origin', () => {+ expect(sanitizeCamera({ x: NaN, y: Infinity, zoom: 1 })).toEqual({ x: 0, y: 0, zoom: 1 })+ })++ it('accepts the floor itself, and anything above it', () => {+ expect(sanitizeCamera({ x: 0, y: 0, zoom: MIN_CAMERA_ZOOM }).zoom).toBe(MIN_CAMERA_ZOOM)+ expect(sanitizeCamera({ x: 0, y: 0, zoom: 4 }).zoom).toBe(4)+ })++ it('is idempotent and returns a COPY', () => {+ const cam: Camera = { x: 1, y: 2, zoom: 0 }+ const once = sanitizeCamera(cam)+ expect(sanitizeCamera(once)).toEqual(once)+ expect(sanitizeCamera(cam)).not.toBe(cam)+ })+})diff --git a/src/renderer/glyphgrid/camera.ts b/src/renderer/glyphgrid/camera.tsindex a9a770ad9..227b1a405 100644--- a/src/renderer/glyphgrid/camera.ts+++ b/src/renderer/glyphgrid/camera.ts@@ -53,6 +53,39 @@ export function snapPanToDevicePx(cam: Camera, dpr: number): Camera {}}+/**+ * The smallest zoom the glyph camera will hold — React Flow's own `minZoom` default, deliberately+ * the same number, because the two cameras are supposed to describe the same view.+ */+export const MIN_CAMERA_ZOOM = 0.01++/**+ * Make a camera SAFE to compute with, whatever it came from.+ *+ * THE BLANK CANVAS THIS ANSWERS. A camera reaches this module from a persisted project viewport as+ * well as from a live gesture, and a stored `zoom: 0` (or a viewport that reached the file as NaN+ * through some earlier edit) is not caught anywhere on the way in: `visibleWorldRect` divides the+ * viewport by the zoom, so the visible rect goes Infinity or NaN, `rectsIntersect` answers false for+ * EVERY grid, and every terminal on the board is empty at once — permanently, since nothing+ * recomputes the camera until the user pans. The DOM chrome looks perfect throughout, because React+ * Flow clamps its own transform to `minZoom` and this camera did not, which is exactly the shape the+ * "all my terminals went blank but the app is fine" reports have.+ *+ * Clamping rather than rejecting: a camera we refuse to adopt leaves the canvas drawing against the+ * PREVIOUS project's view, which is the same blank screen by another road. A zoom of `MIN_CAMERA_ZOOM`+ * draws the world microscopically small, which is at least honest about what was asked for, and one+ * real gesture replaces it.+ */+export function sanitizeCamera(cam: Camera): Camera {+ return {+ x: Number.isFinite(cam.x) ? cam.x : 0,+ y: Number.isFinite(cam.y) ? cam.y : 0,+ // `!(zoom >= MIN)` rather than `<`, so NaN (which compares false against everything) lands on+ // the floor instead of falling through as "big enough".+ zoom: Number.isFinite(cam.zoom) && cam.zoom >= MIN_CAMERA_ZOOM ? cam.zoom : MIN_CAMERA_ZOOM+ }+}+/** Strict overlap (shared edge does not count — an edge-touching grid draws zero pixels). */export function rectsIntersect(a: Rect, b: Rect): boolean {return a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h