Skip to content

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.

feat(dino): game wrapper, DinoNode component, and styles

enes393d0be40350
diff --git a/src/renderer/nodes/DinoNode.tsx b/src/renderer/nodes/DinoNode.tsx
new file mode 100644
index 000000000..1231c7cdc
--- /dev/null
+++ b/src/renderer/nodes/DinoNode.tsx
@@ -0,0 +1,62 @@
+import { useEffect, useRef } from 'react'
+import { NodeResizer, useReactFlow, type NodeProps } from '@xyflow/react'
+import { type CanvasNode } from '../state/workspace'
+import { createDinoGame } from './dino/dino-game'
+
+const GAME_KEYS = new Set([' ', 'ArrowUp', 'ArrowDown', 'Spacebar'])
+
+/**
+ * A dino node: Chromium's offline T-Rex Runner on a canvas. No PTY. The game is
+ * created once on mount and destroyed on unmount (React Flow keys nodes by id, so
+ * the instance survives re-renders). High score persists via data.highScore — we
+ * seed the engine with it and store new records back silently; the player sees the
+ * authentic on-canvas "HI" rather than a header chip (the engine's raw highestScore
+ * doesn't match the canvas digits, which apply a coefficient).
+ */
+export function DinoNode({ id, data, selected }: NodeProps<CanvasNode>) {
+ const { updateNodeData, deleteElements } = useReactFlow()
+ const hostRef = useRef<HTMLDivElement>(null)
+
+ useEffect(() => {
+ const host = hostRef.current
+ if (!host) return
+ const game = createDinoGame(host, {
+ initialHighScore: data.highScore ?? 0,
+ onHighScore: (score) => updateNodeData(id, { highScore: score })
+ })
+ return () => game.destroy()
+ // Mount once; never re-run (would respawn the game). data.highScore is read
+ // as the seed only.
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [])
+
+ // Keep game keys from reaching React Flow (pan/scroll) while hovering the body.
+ const onKeyDown = (e: React.KeyboardEvent) => {
+ if (GAME_KEYS.has(e.key)) e.stopPropagation()
+ }
+
+ return (
+ <div className={`dino-node${selected ? ' selected' : ''}`} style={{ borderColor: data.color }}>
+ <NodeResizer minWidth={400} minHeight={160} isVisible={selected} color={data.color} />
+
+ <div className="dino-node__header" style={{ background: `${data.color}33` }}>
+ <button className="term-node__color" style={{ background: data.color }} title="Color" disabled />
+ <input
+ className="term-node__title nodrag"
+ value={data.title}
+ spellCheck={false}
+ onChange={(e) => updateNodeData(id, { title: e.target.value })}
+ />
+ <button
+ className="term-node__close"
+ title="Close"
+ onClick={() => deleteElements({ nodes: [{ id }] })}
+ >
+ ×
+ </button>
+ </div>
+
+ <div ref={hostRef} className="dino-node__body nodrag nowheel" tabIndex={0} onKeyDown={onKeyDown} />
+ </div>
+ )
+}
diff --git a/src/renderer/nodes/dino/dino-game.ts b/src/renderer/nodes/dino/dino-game.ts
new file mode 100644
index 000000000..e7dcbc335
--- /dev/null
+++ b/src/renderer/nodes/dino/dino-game.ts
@@ -0,0 +1,101 @@
+import { Runner } from './trex-runner'
+import { DINO_SOUNDS } from './sounds'
+import sprite1x from './sprite-1x.png'
+import sprite2x from './sprite-2x.png'
+
+/**
+ * Mounts a T-Rex Runner game inside `host`. The vendored engine resolves its
+ * resources from the document by FIXED ids: sprite <img> elements
+ * (`offline-resources-1x` / `-2x`, picked by devicePixelRatio) loaded at
+ * construction, and sound <audio> elements read on first play from a
+ * <template id="audio-resources">.content. It mounts its own <canvas> into the
+ * selector we hand it and binds keydown/keyup/mouse on document. We build that
+ * scaffold scoped under `host`, give the wrapper a unique selector, and tear it
+ * all down on destroy(). The engine keeps its own high score; we mirror it out.
+ */
+export function createDinoGame(
+ host: HTMLElement,
+ opts: { initialHighScore: number; onHighScore: (score: number) => void }
+): { destroy: () => void } {
+ // Unique class so multiple dino nodes don't collide on the engine's selector.
+ const wrapperClass = `dino-wrapper-${Math.floor(performance.now())}-${Math.round(Math.random() * 1e6)}`
+
+ // --- Sprite resources: loose <img> by fixed id (engine uses getElementById).
+ const makeSprite = (id: string, src: string): HTMLImageElement => {
+ const el = document.createElement('img')
+ el.id = id
+ el.src = src
+ el.style.display = 'none'
+ return el
+ }
+ const sprites: HTMLImageElement[] = [
+ makeSprite('offline-resources-1x', sprite1x),
+ makeSprite('offline-resources-2x', sprite2x)
+ ]
+ sprites.forEach((el) => host.appendChild(el))
+
+ // --- Sound resources: MUST live inside a <template id="audio-resources">.
+ // The engine reads `getElementById('audio-resources').content` then
+ // `.getElementById('offline-sound-*')` on first play; loose <audio> would
+ // throw. The src must carry the `data:audio/mpeg;base64,` prefix — loadSounds
+ // strips everything up to the comma before decoding.
+ const template = document.createElement('template')
+ template.id = 'audio-resources'
+ const makeAudio = (id: string, b64: string): HTMLAudioElement => {
+ const el = document.createElement('audio')
+ el.id = id
+ el.src = `data:audio/mpeg;base64,${b64}`
+ return el
+ }
+ template.content.appendChild(makeAudio('offline-sound-press', DINO_SOUNDS.press))
+ template.content.appendChild(makeAudio('offline-sound-hit', DINO_SOUNDS.hit))
+ template.content.appendChild(makeAudio('offline-sound-reached', DINO_SOUNDS.reached))
+ host.appendChild(template)
+
+ // The engine does `document.querySelector(selector)` for its outer container.
+ const wrapper = document.createElement('div')
+ wrapper.className = wrapperClass
+ host.appendChild(wrapper)
+
+ // The constructor returns the existing singleton if one is set; clear it so
+ // each node gets its own instance. Do NOT pass opt_config — the engine would
+ // REPLACE (not merge) its default config and break.
+ Runner.instance_ = undefined
+ const runner = new Runner(`.${wrapperClass}`)
+
+ // Seed the engine's persisted high score with ours (it reflects it in its own
+ // on-canvas HI after the first run/crash), then poll for new records and
+ // report them out — the engine has no high-score callback.
+ let best = opts.initialHighScore
+ runner.highestScore = best
+ const poll = window.setInterval(() => {
+ const hs = Math.round(runner.highestScore)
+ if (hs > best) {
+ best = hs
+ opts.onHighScore(best)
+ }
+ }, 1000)
+
+ return {
+ destroy() {
+ window.clearInterval(poll)
+ try {
+ runner.stop()
+ // Removes the gameplay keydown/keyup/mouse listeners (engine uses a
+ // `handleEvent` method, so removeEventListener(…, this) works).
+ ;(runner as unknown as { stopListening: () => void }).stopListening()
+ } catch {
+ /* engine already torn down */
+ }
+ // Drop the singleton ref so a fresh node can construct cleanly.
+ if (Runner.instance_ === runner) Runner.instance_ = undefined
+ wrapper.remove()
+ sprites.forEach((el) => el.remove())
+ template.remove()
+ // NOTE: the engine also binds window resize/visibility/blur/focus and one
+ // anonymous document keydown that it has no API to remove — an accepted
+ // minor leak. stopListening() drops the gameplay keys, which is what
+ // matters for input not bleeding into other nodes.
+ }
+ }
+}
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index 4465257b0..338f06a46 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -4030,3 +4030,37 @@ body,
.sessions-icon-cluster { position: absolute; top: 54px; left: 14px; z-index: 11; }
.sessions-icon-cluster button { width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; background: rgba(40, 40, 42, 0.92); border: 1px solid var(--border); border-radius: 9px; color: var(--text); cursor: pointer; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); }
.sessions-icon-cluster button:hover { background: var(--panel-header); }
+
+/* --- Dino node (T-Rex Runner game) --------------------------------------- */
+.dino-node {
+ display: flex;
+ flex-direction: column;
+ width: 100%;
+ height: 100%;
+ background: #f7f7f7;
+ border: 1px solid var(--separator, #3a3a3c);
+ border-radius: 10px;
+ overflow: hidden;
+}
+.dino-node.selected {
+ box-shadow: 0 0 0 2px var(--accent);
+}
+.dino-node__header {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ padding: 4px 6px;
+ background: #2a2a2c;
+}
+.dino-node__body {
+ flex: 1;
+ min-height: 0;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ background: #f7f7f7;
+}
+/* The engine sizes its own canvas; keep it from overflowing the node. */
+.dino-node__body canvas {
+ max-width: 100%;
+}