DevLog
← Back to Blog

Living Spaces: Why and How We Compile Zero-Token Interactive Micro-Apps

By • 11 min read
This article is also available in Chinese: 🌐 阅读中文版 →

For quick answers, code diffs, and one-off lookups, plain chat and Markdown files are unbeatable.

But once you start managing something that evolves over days—a multi-region release cutover, a 5-day Kyoto family trip, an architecture comparison matrix, or a long-running research tracker—linear chat fights you at every step. Finding Tuesday’s schedule means scrolling past 40 messages. Checking off one blocker means making the model burn thousands of tokens regenerating a whole Markdown wall, wiping out whatever filters or sort order you had open.

Inside github.com/zjshen14/agy-hq (following Part 1 and Part 2), we built Living Spaces (internal/living/): interactive, single-file web micro-apps compiled deterministically from a small space.json file and locked inside a three-layer browser sandbox.

This post explains why you would want a compiled micro-app instead of Markdown or ad-hoc LLM-generated HTML, and how you actually create, use, check off, and keep one updated day to day at 0 LLM tokens after creation.


1. Why Use a Micro-App Instead of Chat, Markdown, or LLM-Written HTML?

If an agent can already write Markdown tables—or generate a custom React page on the spot—why build a compiler in between?

ApproachUpdates cost tokens?Stays interactive across days?Safe next to local agent tools?Works offline on phone?
Plain Chat / MarkdownEvery table rewrite costs tokensStatic prose only; no filters, map pins, or sortingSafe, read-only textReadable, not interactive
Ad-Hoc LLM HTML / ReactEvery edit asks the model to regenerate markupFragile; layout, dark mode, and filters drift per runUnsafe if hosted beside localhost APIs/tokensBreaks if it relies on external CDNs or localhost
Living Space (space.json -> Go)Model writes space.json once; refreshes cost 0 tokensPersists in vault/ with audience views, sort, search & sync3-layer CSP + opaque null-origin sandboxExports a single self-contained HTML artifact (space_<slug>.html)

Two real-world patterns made the difference clear for us:

  1. Multi-view plans need lightweight interaction, not another chat turn: During a deployment cutover, engineers want P99 POP latency bars and live workspace status, while a lead just wants the readiness gauge (2 / 3) and go/no-go checklist. On a family trip itinerary, parents may want a 中文 mobile view while you toggle Adult vs. Kids stops. Regenerating separate chat replies for each stakeholder is tedious; clicking a filter pill or language button takes milliseconds.
  2. State shouldn’t die when a conversation wraps: Single chats compact or get archived. A Living Space sits in your private vault (<vault>/living_spaces/<slug>/index.html), links directly to a multi-day goal (hq goals), and refreshes live underlying data via deterministic CLI commands without ever waking the LLM again.

When not to use one: Keep single-turn coding help, PR reviews, and quick research notes in plain chat or Markdown. Reach for a Living Space when you expect to revisit, filter, sort, or check off the same structured plan across multiple sessions.


2. How You Actually Use a Living Space (Day 1 to Day N)

Here is the real workflow from first prompt to daily updates on both desktop and phone:

Step 1 — Start from a normal prompt (the model writes space.json once)

You don’t write HTML or hand-craft big schemas yourself. You just describe the multi-day plan in conversation—for example:

  • “Build a Q4 Edge Proxy Cutover space tracking US-West, EU-Central, and APAC with a go-live checklist.”
  • “Plan our 5-day Kyoto family trip with Adult/Kids perspectives and English/中文 support.”

Following its workspace heuristic (AGENTS.md), the coordinator creates or links an hq goal (q4-edge-cutover), translates your structure into one compact space.json (arrays trimmed below for readability), and compiles it in Go:

{
  "schemaVersion": 1,
  "slug": "q4-edge-cutover",
  "theme": "heritage",
  "goalSlug": "q4-edge-cutover",
  "title": { "en": "Q4 Edge Proxy Cutover (Demo)", "zh": "Q4 边缘网关切换作战室(演示)" },
  "locales": ["en", "zh"],
  "perspectives": [
    { "id": "eng",  "label": { "en": "Engineering Detail", "zh": "工程实施视角" } },
    { "id": "exec", "label": { "en": "Executive Summary",  "zh": "负责人概览" } }
  ],
  "dataSources": [
    { "id": "ds-ws", "kind": "hq_builtin", "target": "workspaces" }
  ],
  "blocks": [
    { "id": "readiness-kpis", "type": "kpi_strip", "countdownAt": "2026-12-05T17:00:00Z", "showReadiness": true },
    { "id": "topology-map",   "type": "interactive_map", "map": { "zones": [], "paths": [], "pins": [] } },
    { "id": "checklist",      "type": "checklist_ledger", "title": { "en": "Cutover Gate Checklist" } },
    { "id": "region-matrix",  "type": "comparison_table", "columns": [], "rows": [] },
    { "id": "lat-bars",       "type": "metric_bars", "bars": [] }
  ]
}

Compiling that spec via hq space create --from-json=space.json builds <vault>/living_spaces/q4-edge-cutover/index.html in 0 additional LLM tokens. For trips or active regional cutovers, passing --tz=<IANA> --window-start=... --window-end=... (say --tz=Asia/Tokyo for the Kyoto trip) also scaffolds a linked timezone Goal automatically so countdowns, briefs, and quiet hours shift to local time.

Step 2 — Open it on Desktop or Phone

Once compiled, the micro-app shows up automatically in two places (using the dual-surface transport built in Part 1):

  • On Desktop: Open the Work tab in HQ Console (Part 2) and click Open Sandboxed Space ↗ to view it right inside your IDE sidebar or browser.
  • On Phone (Remote Control): Run hq space export-artifact q4-edge-cutover to copy space_q4-edge-cutover.html into the active conversation’s artifact directory so it renders offline inside Antigravity’s mobile Artifact Pane—no localhost tunnel needed.

Live Desktop screenshot of the compiled q4-edge-cutover Living Space in the heritage theme showing Hero banner, EN/中文 language toggle, light/dark toggle, perspective and region filter pills, live Cutover Window countdown (7d 0h 59m), 2/3 readiness bar (with 1 open and 1 skipped excluded from denominator), and pure-SVG Rollout Traffic Topology interactive_map with Pin 2 selected and Previous/Next inspector card.

Step 3 — Slice views, sort telemetry, and check off milestones safely

Inside the compiled page, every control works locally in the browser with zero network calls:

  • Filter and translate on the fly: Toggle Engineering Detail vs. Executive Summary, switch English / 中文, click SVG map pins (← Prev / Next →), or sort table columns (P99 LATENCY ↑).
  • Check off work without silent writes: Clicking an item in checklist_ledger marks it visually and reveals the burgundy Local checklist updated bar with a Copy Sync Cmd button (hq goals check-off <goalSlug> <itemID>). Paste that command into chat (or run it in terminal) to update your vault—a Living Space never mutates your vault directly from JavaScript.

Lower half of the compiled q4-edge-cutover Living Space after checking off the open milestone: showing the burgundy Local checklist updated sync bar with Copy Sync Cmd button, confirmed and collapsed Skipped rows, p99-sorted Regional POP Telemetry table, and SLO Headroom metric bars with warn and crit cutoff markers.

Real --demo desktop compilation of q4-edge-cutover after ticking an open milestone: notice READINESS reads 2 / 3 (66%) cleanly before confirmation, because the Skipped (“won’t re-suggest”) item is excluded from the denominator.

Because layout uses responsive CSS grids inline, the exact same file stacks cleanly at phone width (390×840) inside mobile Remote Control with zero horizontal scroll:

Mobile 390x840 responsive screenshot of the q4-edge-cutover Living Space showing stacked hero language pills, wrapped perspective filters, search bar, and KPI readiness cards showing 3/3 (100%) after checking off the open gate.

Mobile viewport (390×840): opens offline via space_<slug>.html in Remote Control with full filtering and readiness progress.

Step 4 — Keep it live across days in 0 LLM tokens

Think of dataSources in space.json like spreadsheet formulas. Instead of re-prompting the agent whenever branches merge, live URLs/statuses change, or checklist gates clear, four instant Go commands keep the page fresh:

  • hq space refresh <slug>: Re-evaluates declared data sources (workspaces, active goals, delegates queues, obs task counts, live monitors, or allowlisted trusted_argv binaries) and recompiles index.html.
  • hq space sync-goal <slug>: Pulls updated three-state milestones (Open / Confirmed / Skipped) from the linked goal straight into kpi_strip and checklist_ledger.
  • hq space note <slug> --title=... --text=... --tone=...: Appends a timestamped update card (info, warn, or ok) directly into the Space’s owner-notes block and rebuilds without touching raw JSON.
  • hq space export-artifact <slug>: Writes the updated self-contained space_<slug>.html to your conversation artifact folder for mobile viewing.

Every { "en": "...", "zh": "..." } string compiles into inline data-i18n dictionaries switched immediately via English / 中文. (Honest boundary: built-in compiler chrome like “All Views”, “Filter this space…”, and single-string items synced from goals.json still render in English today.)


3. Inside the Compiler: 8 Blocks & 5 Built-In Themes

Keeping the model constrained to typed JSON blocks gives you consistent light/dark UX, predictable mobile layout, and zero brittle CSS generation. Mix any combination of eight blocks across five themes (modern, editorial, heritage, ocean, forest, plus ◐ dark/light toggle):

BlockWhat it’s for
kpi_stripHeadline metrics, timezone countdown timer, and live goal readiness meter
interactive_mapSVG zones and paths with clickable numbered pins and a ← Prev / Next → tour
checklist_ledgerThree-state ledger (Open / Confirmed / Skipped tombstones) with copy-to-sync CLI banner
comparison_tableClient-side sortable multi-column matrix (click ↑/↓ on any header)
metric_barsPercentage bars overlaid with warn and critical threshold ticks
timeline_accordionStep-by-step runbooks or daily trip itineraries with Expand All toggle
callout_notesAction cards with deep links and copy-to-clipboard CLI buttons
story_cardsNarrative highlight cards filtered jointly alongside map pins by perspective and tag

4. Security Architecture: Keeping Model-Authored Apps Away from HQ Secrets

If your local console (127.0.0.1:4242) can stage GitHub PR merges, Gmail drafts, Google Chat messages, and SHA-256 approvals, any model-compiled HTML page must be treated as untrusted code. Even if a malicious PDF inside inbox/ tricked the model into sneaking payloads into space.json, it must never be able to read a CSRF token or trigger Approve.

agy-hq puts three independent walls between a Living Space and its host console:

Three-layer defense-in-depth architecture diagram: space.json compiles via Go strings.Builder and html.EscapeString plus SVG/URL allowlists into standalone index.html, renders inside an iframe omitting allow-same-origin for an isolated null origin at /living-spaces/<slug>/raw, and locks down network egress with Content-Security-Policy default-src 'none'.

Three enforcement boundaries between a Living Space and agy-hq’s privileged control plane.

  1. Layer 1 — Strict Compile-Time Escaping & Allowlists (internal/living/):
    Every string passes through Go’s strings.Builder and html.EscapeString, with zero raw HTML template holes. Model-supplied attributes are validated strictly (via safeHref and SVG/tone validators in internal/living/):

    • Color tones: lowercase letters, digits, - and _ only—cannot break out of a CSS class.
    • SVG geometry: finite numbers only—cannot inject arbitrary tags into map geometry.
    • Links: http://, https://, or conversation:// only (javascript: and data: links are rejected).
    • Images: verified inline Base64 images only—no external image URLs.
  2. Layer 2 — Opaque null-Origin <iframe> Sandbox on :4242:
    Clicking Open Sandboxed Space ↗ in HQ Console renders the compiled page inside:

    <iframe sandbox="allow-scripts" src="/living-spaces/q4-edge-cutover/raw"></iframe>

    We deliberately omit allow-same-origin. Without it, the browser isolates the frame into an anonymous null origin—like a guest locked in a room with no keys. Even if script somehow slipped past Layer 1, it cannot read parent cookies, touch window.parent, read x-sidecar-token, or reach Console write routes. (Because localStorage throws SecurityError inside a null origin, checklist state gracefully falls back to in-memory JS via try/catch.)

  3. Layer 3 — Outbound Network Lockdown (Content-Security-Policy):
    Every /living-spaces/<slug>/raw HTTP response attaches a strict zero-egress CSP header:

    default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; img-src data:; base-uri 'none'; form-action 'none'

    Even if opened directly in its own browser tab outside the iframe, fetch(), XMLHttpRequest, WebSockets, remote fonts/images, <base> hijacking, and HTML form submissions are all blocked at runtime.


Trade-Offs, Quickstart & Series Takeaways

Two practical trade-offs keep Living Spaces honest:

  • Re-compiles are explicit & single-file apps use 'unsafe-inline': Live state updates happen when you run hq space refresh or sync-goal (0 tokens) rather than background sockets inside the iframe, and packing CSS/JS into one portable HTML file requires script-src 'unsafe-inline'—which is why Layers 2 and 3 lock down host privileges and network egress completely.
  • Reach for Markdown first on short tasks: Single-turn questions and code diffs belong in plain chat or notes; Living Spaces earn their keep on multi-day plans you revisit repeatedly.

Across all three parts: Part 1 put one template across desktop and phone surfaces, Part 2 turned that UI into an honest 5-plane monitoring dashboard, and Part 3 gave long-lived plans an interactive, 0-token micro-app runtime without handing HTML or secrets to the model. The common thread: the model decides what; deterministic code handles how, every time, for free.

Try It Locally in 30 Seconds

Spin up an isolated demo environment, compile a minimal dataSources-bound Living Space into it, open Work → Open Sandboxed Space ↗ in the console, and test a zero-token refresh:

./bin/hq init --demo
cat > cutover.json <<'EOF'
{
  "schemaVersion": 1,
  "slug": "q4-edge-cutover",
  "theme": "heritage",
  "title": { "en": "Q4 Edge Proxy Cutover", "zh": "Q4 边缘网关切换作战室" },
  "locales": ["en", "zh"],
  "dataSources": [
    { "id": "ds-ws", "kind": "hq_builtin", "target": "workspaces" }
  ],
  "blocks": [
    { "id": "kpis", "type": "kpi_strip", "dataSourceId": "ds-ws", "countdownAt": "2026-12-05T17:00:00Z" },
    { "id": "ws-table", "type": "comparison_table", "title": { "en": "Live Workspaces", "zh": "工作区状态" }, "dataSourceId": "ds-ws" }
  ]
}
EOF
./bin/hq space create --from-json=cutover.json
./bin/hq space refresh q4-edge-cutover && ./bin/hq webui

Full Series

Share this post

Scan with WeChat

Scan this QR code with WeChat to read or share on mobile.

Link copied to clipboard!