One Template, Two Surfaces: How Antigravity Sidecars, Artifacts & Hook Hydration Work
If you build coding harnesses or agent orchestrators, plain chat hits a wall the moment your agent does real background work. Dumping branch tables, pending approvals, and token logs into every reply burns thousands of output tokens and buries the actual conversation.
But moving that dashboard to http://127.0.0.1:4242 reveals a second wall the minute you walk away from your desk: your phone cannot reach 127.0.0.1.
While building github.com/zjshen14/agy-hq (our zero-dependency Go companion harness for Google Antigravity), I had to wire one UI architecture across two very different delivery surfaces: desktop IDE sidebars next to your code, and offline conversation HTML artifacts synced automatically to mobile Remote Control.
This post covers three things: how Antigravity’s two UI surfaces work, why we deleted an 841-line second renderer (console_space.go) and made one ~110 KB template serve both, and how a ~60-token pre-tool hook placeholder stopped the model from re-typing HTML on its first turn.
1. Antigravity in 30 Seconds: Sidecar Webviews vs. HTML Artifacts
If you come from Claude Code, Cursor, or OpenCode, here is the short mental model. Antigravity gives plugins two places to show UI:
- On your desktop, a sidecar is a live web panel next to the chat—like a cockpit wired directly to your machine.
- On your phone, an artifact (a file saved inside
<appDataDir>/brain/<conversation-id>/) travels with the conversation over Antigravity’s cloud relay—like a printed snapshot that cannot call back to127.0.0.1on your laptop.
So the engineering trick is to make one HTML page work cleanly as both.
One Go backend feeds two delivery paths: live loopback sidecars on desktop, and self-contained HTML artifacts on mobile.
Surface A: Desktop IDE Sidecar Plugin (AUX_PANE)
In .agents/plugins/agy-hq/sidecars/agy-hq-console/, the plugin registers a UI sidecar via sidecar.json:
- Auxiliary pane registration: Declaring
SIDECAR_UI_ENTRYPOINT_AUX_PANEtells Antigravity to host the panel beside the chat and open it via a native pill ([Interactive Console](sidecar://agy-hq-console/)). - Go-first launcher (
launch.sh): Tries our compiledhq sidecar consoleproxy first, falling back cleanly to Nodemain.mjsonly if nohqbinary is found on the machine. - Auth and theming come for free (
preload.js): Antigravity hands each sidecar session its own secret token (x-sidecar-token), andpreload.jsattaches it to every request throughwindow.sidecar.fetch. The same script forwards IDEtheme-changeevents as CSS variables, so the panel matches light or dark mode automatically. - Live loopback proxy (
127.0.0.1:4242): On desktop, the panel polls/api/stateon our Go server (hq webui) every 5 seconds with full interactive buttons for approvals, pausing daemons, and triggering runs.
Surface B: HTML Artifacts & the Mobile localhost Cliff
Why not just tell mobile users to set up Tailscale or Cloudflare Tunnels and open :4242 in Safari?
Because two everyday constraints break port forwarding cleanly:
- Workstations sleep and close lids: Even with a mesh VPN, a sleeping laptop isn’t serving HTTP requests while you check alerts away from your desk.
- Managed devices block inbound tunnels: Corporate laptops and locked-down phones often forbid reverse tunnels or third-party mesh daemons altogether.
Antigravity solves transport for conversation Artifacts out of the box: any standalone HTML file written inside the session’s artifact directory (hq_console_live.html) syncs automatically as an embedded preview in the mobile Artifact Pane—no SSH tunnel, no exposed ports.
The catch is network isolation. Because an HTML Artifact has zero access to 127.0.0.1:4242, any button expecting POST /api/approve would fail silently on mobile unless the page itself adapts.
2. Retiring an 841-Line Adapter (console_space.go) with StaticMode
Our first attempt built two separate renderers: console.html for 127.0.0.1:4242, and an 841-line Living Space adapter (internal/webui/console_space.go) solely to emit the offline hq_console_live.html snapshot. Very quickly, every new badge or telemetry card landed on desktop first and drifted behind on mobile.
So we deleted all 841 lines of console_space.go (commit 2a03953) and unified both surfaces behind one dual-mode ~110 KB Go template (console.html) toggled by a single StaticMode boolean:
- One Go state pass: Desktop webviews and mobile snapshots read from the exact same Go state loader (
loadState/RenderStaticConsoleHTML) and enforce the samelocal/private/credential omission. - Everything ships inside one file: When
StaticModeistrue, Go pre-renders every tab into plain SSR HTML and tucks compact observability/memory bootstrap JSON into an inline<script id="hq-bootstrap-state">tag so charts and search filters run offline with zero external requests. The desktop’s green LIVE pill swaps to a cyan SNAPSHOT badge, and the 5-second/api/statepoller stays off. - Offline tabs stay interactive: Switching across Needs Me, Work, Memory, Tokens, and Ops or expanding accordions works instantaneously in the mobile viewer.
- Safe clipboard fallback for writes: Clicking Approve, Reject, or Run Now in a static snapshot copies the verified CLI command—complete with its SHA-256 digest (
hq approve ... --sha256=...)—to your phone clipboard and pops a green toast at the top of the screen (“Copied command (paste in chat)…”) so you can paste and execute directly in mobile chat.

Real --demo 390×800 render of hq_console_live.html in StaticMode: identical layout to desktop, with a cyan SNAPSHOT pill and top clipboard fallback banner.
3. Cut Turn-1 Token Waste by 99%: Pre-Tool Sentinel Hydration
Unifying desktop and mobile HTML solved template drift, but exposed a silly bottleneck on the very first turn of [HQ] Front Desk—our long-lived coordinator chat pinned to the sidebar that routes incoming work.
To surface artifacts in Antigravity’s Artifact Pane automatically, the coordinator writes hq_console.md and hq_console_live.html via write_file. Originally, the model read our console summary and re-typed thousands of tokens of Markdown tables and HTML back into tool arguments, burning ~9,500 output tokens on Turn 1 and risking typos inside SHA-256 digests.
The principle: If Go already has the exact bytes, the model shouldn’t re-type them. Re-typing burns output tokens and introduces typos—and a single typo in a SHA-256 prefix breaks approval. This same hook pattern works in any harness with a pre-tool hook, including Claude Code hooks and OpenCode plugins.
Intercepting {{HQ_SYNC}} in PreToolUse drops Turn-1 UI hydration from ~9,500 output tokens to ~60 while eliminating copy-paste drift.
Here is how the three-step handoff works:
- Turn 1 emits a sentinel: The coordinator sends two tiny parallel
write_filecalls targetinghq_console.mdandhq_console_live.htmlwithContent: "{{HQ_SYNC}}", costing ~60 tokens total. PreToolUseswaps bytes in-place: Before Antigravity writes either file, our GoPreToolUsehook (hydrateConsoleSyncContent) spots the placeholder, reads the console files Go has already rendered to disk, and returns them inside the hook response’soverwritefield. Antigravity writes the real bytes directly—the model never had to generate them.- Zero-token updates afterward: CLI actions (
hq status,hq approve, goal updates) keep both artifact files synced via atomic swaps in 0 LLM tokens, so your mobile Artifact Pane always reflects current state.
Putting It Together & Quickstart
Desktop gets a low-latency loopback cockpit, and the phone gets only what travels with the conversation. Every local-first agent harness eventually hits that boundary. One ~110 KB template with a StaticMode switch—paired with a pre-tool hook that hydrates a sentinel—gives you one UI across both surfaces with near-zero first-turn cost.
Spin up an isolated demo sandbox locally (your real ~/.gemini and vaults stay untouched), then click the Interactive Console sidecar link in chat or open hq_console_live.html in the Artifact Pane:
./bin/hq init --demo && ./bin/hq webui
(When inspecting a real vault without starting background dispatchers or enabling HTTP writes, pass ./bin/hq webui --read-only, which implies --no-heartbeat.)
Related Reading
- Part 2 — Inside the Dashboard: Inside HQ Console Live: The 5-Tab Monitoring Dashboard for Personal Agent Systems
- Part 3 — Composable Micro-Apps: Living Spaces: Why and How We Compile Zero-Token Interactive Micro-Apps
- Earlier Harness Notes: Hooks & Microkernel · Four-Layer Memory · Safe Self-Improvement (RSI)
- Source Code: github.com/zjshen14/agy-hq
Scan with WeChat
Scan this QR code with WeChat to read or share on mobile.