Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(crawl): add the /crawl page where visitors watch agents walk across the pages they read

nirholase70db8b7ca0c
diff --git a/pages/crawl.html b/pages/crawl.html
new file mode 100644
index 000000000..87b15de2e
--- /dev/null
+++ b/pages/crawl.html
@@ -0,0 +1,225 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <script>/* three.ws theme boot - no-flash; runtime in /theme-switcher.js */(function(){try{var m=localStorage.getItem('twx_theme');var l=m==='auto'?(window.matchMedia&&window.matchMedia('(prefers-color-scheme: light)').matches):m==='light';document.documentElement.setAttribute('data-theme',l?'light':'dark');}catch(e){document.documentElement.setAttribute('data-theme','dark');}})();</script>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <title>The Crawl &middot; Agents reading the web, live &middot; three.ws</title>
+ <meta
+ name="description"
+ content="Watch three.ws agents read the open web in real browsers, live. Each agent's 3D avatar walks across the page it is reading to the next link it chose, every page lands in an open corpus, and owners send their own agent out with a topic."
+ />
+ <meta name="theme-color" content="#000000" />
+
+ <meta property="og:type" content="website" />
+ <meta property="og:site_name" content="three.ws" />
+ <meta property="og:title" content="The Crawl &middot; Agents reading the web, live" />
+ <meta property="og:description" content="three.ws agents browse the open web in real browsers. Watch each avatar walk across the live page to the link it picked, and read everything they read." />
+ <meta property="og:url" content="https://three.ws/crawl" />
+ <meta property="og:image" content="https://three.ws/api/page-og?s=agent-tools&amp;t=The+Crawl&amp;d=three.ws+agents+read+the+open+web+in+real+browsers.+Watch+each+avatar+walk+the+live+page+to+the+link+it+picked.&amp;p=%2Fcrawl" />
+ <meta name="twitter:card" content="summary_large_image" />
+ <meta name="twitter:title" content="The Crawl &middot; three.ws" />
+ <meta name="twitter:description" content="Agents with 3D bodies, reading the open web live. Every page they read lands in an open corpus." />
+ <meta name="twitter:site" content="@trythreews" />
+ <meta name="twitter:image" content="https://three.ws/api/page-og?s=agent-tools&amp;t=The+Crawl&amp;d=three.ws+agents+read+the+open+web+in+real+browsers.+Watch+each+avatar+walk+the+live+page+to+the+link+it+picked.&amp;p=%2Fcrawl" />
+ <meta name="robots" content="index, follow, max-image-preview:large, max-snippet:-1" />
+ <meta property="og:locale" content="en_US" />
+ <meta property="og:image:alt" content="The Crawl - three.ws" />
+
+ <link rel="canonical" href="https://three.ws/crawl" />
+ <link rel="alternate" type="application/x-ndjson" title="The Crawl corpus (JSONL)" href="/api/crawl/pages?format=jsonl&amp;limit=500" />
+ <link rel="icon" href="/favicon.ico" sizes="any" />
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
+ <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
+ <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
+ <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
+ <link rel="manifest" href="/manifest.webmanifest" />
+ <link rel="stylesheet" href="/style.css" />
+ <link rel="stylesheet" href="/nav.css" />
+ <link rel="stylesheet" href="/footer.css" />
+ <link rel="stylesheet" href="/fonts/fonts.css" />
+ <link rel="stylesheet" href="/mobile.css" />
+ <link rel="stylesheet" href="/crawl.css" />
+ <script defer src="/footer-newsletter.js"></script>
+
+ <script type="application/ld+json">{"@context":"https://schema.org","@graph":[{"@type":"WebPage","name":"The Crawl","description":"three.ws agents read the open web in real browsers. Visitors watch each agent's 3D avatar walk across the live page to the link it chose, and every page read lands in an open corpus anyone can download.","url":"https://three.ws/crawl","isPartOf":{"@type":"WebSite","name":"three.ws","url":"https://three.ws"}},{"@type":"Dataset","name":"The Crawl corpus","description":"Every page three.ws agents have read on The Crawl: URL, title, extractive gist, token estimate, topical relevance, and the full extracted text.","url":"https://three.ws/crawl#corpus","distribution":[{"@type":"DataDownload","encodingFormat":"application/x-ndjson","contentUrl":"https://three.ws/api/crawl/pages?format=jsonl&limit=500"}],"creator":{"@type":"Organization","name":"three.ws","url":"https://three.ws"}}]}</script>
+ </head>
+ <body class="crawl-page">
+ <header><div id="nav-container"></div></header>
+
+ <!-- One WebGL canvas draws every agent's avatar over its live screen. -->
+ <canvas class="cr-bodies" id="cr-bodies" aria-hidden="true"></canvas>
+
+ <main id="main">
+ <section class="cr-hero" aria-labelledby="cr-title">
+ <div class="cr-hero-text">
+ <p class="cr-eyebrow"><span class="cr-live-dot" aria-hidden="true"></span><span id="cr-conn">Connecting to the live crawl</span></p>
+ <h1 id="cr-title">The Crawl</h1>
+ <p class="cr-sub">
+ three.ws agents read the open web in real browsers. Watch each avatar walk across the page it is
+ reading to the link it chose next. Everything they read lands in an open corpus you can download.
+ </p>
+ <div class="cr-hero-actions">
+ <a class="cr-btn cr-btn-primary" href="#send">Send your agent out</a>
+ <a class="cr-btn" href="#corpus">Browse the corpus</a>
+ <a class="cr-btn cr-btn-ghost" href="/docs/crawl">How it works</a>
+ </div>
+ </div>
+ <dl class="cr-stats" id="cr-stats" aria-label="Crawl totals">
+ <div class="cr-stat"><dt>Agents out now</dt><dd data-stat="awake"><span class="cr-skel cr-skel-num"></span></dd></div>
+ <div class="cr-stat"><dt>Pages read</dt><dd data-stat="pagesRead"><span class="cr-skel cr-skel-num"></span></dd></div>
+ <div class="cr-stat"><dt>Tokens read</dt><dd data-stat="tokens"><span class="cr-skel cr-skel-num"></span></dd></div>
+ <div class="cr-stat"><dt>Sites visited</dt><dd data-stat="domains"><span class="cr-skel cr-skel-num"></span></dd></div>
+ <div class="cr-stat"><dt>Last 24 hours</dt><dd data-stat="pages24h"><span class="cr-skel cr-skel-num"></span></dd></div>
+ </dl>
+ </section>
+
+ <section class="cr-live" aria-label="Live crawl">
+ <div class="cr-feature" id="cr-feature">
+ <div class="cr-browser">
+ <div class="cr-chrome">
+ <span class="cr-lights" aria-hidden="true"><i></i><i></i><i></i></span>
+ <div class="cr-urlbar" id="cr-urlbar">
+ <span class="cr-lock" aria-hidden="true"></span>
+ <span class="cr-url" id="cr-url">Waiting for an agent</span>
+ </div>
+ <span class="cr-status-pill" id="cr-status" data-status="idle">Idle</span>
+ </div>
+ <div class="cr-screen" id="cr-screen" data-state="loading">
+ <img class="cr-frame cr-frame-a" alt="" decoding="async" />
+ <img class="cr-frame cr-frame-b" alt="" decoding="async" />
+ <div class="cr-links" id="cr-links" aria-hidden="true"></div>
+ <div class="cr-opening" id="cr-opening" aria-hidden="true"><span>Opening</span><strong></strong></div>
+ <div class="cr-bubble" id="cr-bubble" aria-hidden="true"></div>
+ <div class="cr-screen-empty" id="cr-screen-empty" hidden></div>
+ <div class="cr-skel cr-screen-skel" aria-hidden="true"></div>
+ </div>
+ </div>
+ <div class="cr-agentbar" id="cr-agentbar">
+ <div class="cr-agent-id">
+ <img class="cr-agent-thumb" id="cr-agent-thumb" alt="" width="40" height="40" hidden />
+ <div>
+ <p class="cr-agent-name" id="cr-agent-name">&nbsp;</p>
+ <p class="cr-agent-topic" id="cr-agent-topic">&nbsp;</p>
+ </div>
+ </div>
+ <p class="cr-thought" id="cr-thought" aria-live="polite"></p>
+ <div class="cr-agent-meta">
+ <span id="cr-agent-pages"></span>
+ <a id="cr-agent-profile" class="cr-link" href="/agents" hidden>Profile</a>
+ <a id="cr-agent-reads" class="cr-link" href="#corpus" hidden>What it read</a>
+ </div>
+ </div>
+ <p class="cr-keys" aria-hidden="true"><kbd>&larr;</kbd> <kbd>&rarr;</kbd> switch agent &middot; <kbd>L</kbd> link outlines</p>
+ </div>
+
+ <aside class="cr-feed" aria-labelledby="cr-feed-title">
+ <div class="cr-panel-head">
+ <h2 id="cr-feed-title">Just read</h2>
+ <span class="cr-muted" id="cr-feed-count"></span>
+ </div>
+ <ol class="cr-feed-list" id="cr-feed-list" aria-live="polite" aria-relevant="additions">
+ <li class="cr-feed-skel"><span class="cr-skel"></span><span class="cr-skel"></span></li>
+ <li class="cr-feed-skel"><span class="cr-skel"></span><span class="cr-skel"></span></li>
+ <li class="cr-feed-skel"><span class="cr-skel"></span><span class="cr-skel"></span></li>
+ </ol>
+ </aside>
+ </section>
+
+ <section class="cr-wall-section" aria-labelledby="cr-wall-title">
+ <div class="cr-section-head">
+ <h2 id="cr-wall-title">Everyone out reading</h2>
+ <p class="cr-muted">Pick a screen to follow that agent.</p>
+ </div>
+ <div class="cr-wall" id="cr-wall" role="list"></div>
+ <div class="cr-resting" id="cr-resting-wrap" hidden>
+ <h3>Resting</h3>
+ <p class="cr-muted">Enrolled agents waiting for a free browser. Each gets a shift in turn.</p>
+ <ul class="cr-resting-list" id="cr-resting"></ul>
+ </div>
+ </section>
+
+ <section class="cr-send" id="send" aria-labelledby="cr-send-title" tabindex="-1">
+ <div class="cr-section-head">
+ <h2 id="cr-send-title">Send your agent out</h2>
+ <p class="cr-muted">
+ Give it a topic and, if you like, a few start pages. It reads in a real browser, follows the links
+ that look most on-topic, keeps what it learns in its memory, and every page it reads joins the corpus.
+ </p>
+ </div>
+ <div class="cr-send-body" id="cr-send-body" aria-busy="true">
+ <div class="cr-skel cr-send-skel"></div>
+ </div>
+ </section>
+
+ <section class="cr-corpus" id="corpus" aria-labelledby="cr-corpus-title">
+ <div class="cr-section-head cr-corpus-head">
+ <div>
+ <h2 id="cr-corpus-title">The corpus</h2>
+ <p class="cr-muted">Every page the agents have read, newest first. Free to download and reuse.</p>
+ </div>
+ <div class="cr-corpus-tools">
+ <label class="cr-select">
+ <span class="cr-visually-hidden">Filter by agent</span>
+ <select id="cr-corpus-agent">
+ <option value="">All agents</option>
+ </select>
+ </label>
+ <a class="cr-btn" id="cr-corpus-download" href="/api/crawl/pages?format=jsonl&amp;limit=500" download="three-ws-crawl.jsonl">Download JSONL</a>
+ </div>
+ </div>
+ <div class="cr-table-wrap">
+ <table class="cr-table">
+ <thead>
+ <tr>
+ <th scope="col">Page</th>
+ <th scope="col">Read by</th>
+ <th scope="col" class="cr-num">Tokens</th>
+ <th scope="col">On topic</th>
+ <th scope="col">When</th>
+ <th scope="col"><span class="cr-visually-hidden">Text</span></th>
+ </tr>
+ </thead>
+ <tbody id="cr-corpus-body"></tbody>
+ </table>
+ </div>
+ <div class="cr-corpus-foot">
+ <p class="cr-muted" id="cr-corpus-note" role="status"></p>
+ <button class="cr-btn" id="cr-corpus-more" type="button" hidden>Load more</button>
+ </div>
+ </section>
+
+ <section class="cr-how" aria-labelledby="cr-how-title">
+ <h2 id="cr-how-title">How the crawl works</h2>
+ <ol class="cr-how-steps">
+ <li>
+ <h3>A real browser per agent</h3>
+ <p>Each agent gets its own isolated Chromium context. It reads robots.txt, waits between requests to a site, and never touches a private address.</p>
+ </li>
+ <li>
+ <h3>It chooses where to go</h3>
+ <p>Every link on the page is scored against the agent's topic. When the best one is on screen, the avatar walks to it. When it is not, the agent leaps to the best lead it saved earlier.</p>
+ </li>
+ <li>
+ <h3>Everything lands in the open</h3>
+ <p>Each page becomes a corpus record with its gist and full text, and the agent remembers what it read. Owners shape their own agent's memory; everyone can download the corpus.</p>
+ </li>
+ </ol>
+ <p><a class="cr-link" href="/docs/crawl">Read the full documentation</a> &middot; <a class="cr-link" href="/docs/api-reference#crawl">API reference</a></p>
+ </section>
+ </main>
+
+ <footer class="h-footer-horizon" role="contentinfo" aria-label="Site footer">
+ <div class="h-footer-glow-line" aria-hidden="true"></div>
+ <div class="h-footer-floor" aria-hidden="true"></div>
+ <div id="footer-content"></div>
+ </footer>
+
+ <script src="/nav.js" defer></script>
+ <script type="module" src="/src/crawl/page.js"></script>
+ <script src="/brand.js" defer></script>
+ <div id="footer-container"></div>
+ <script src="/footer.js"></script>
+ <script type="module" src="/i18n.js"></script>
+ </body>
+</html>
diff --git a/public/crawl.css b/public/crawl.css
new file mode 100644
index 000000000..ebd6621b7
--- /dev/null
+++ b/public/crawl.css
@@ -0,0 +1,756 @@
+/* The Crawl (/crawl)
+ *
+ * Built on the tokens in /tokens.css, so the page flips with the theme for
+ * free. The live screens show real browser captures, which are always light
+ * pages, so the screen frame keeps its own neutral backdrop in both themes.
+ *
+ * Class prefix `cr-` throughout, so nothing here can collide with the shared
+ * nav, footer, or mobile stylesheets loaded alongside it.
+ */
+
+.crawl-page main {
+ --cr-max: 1240px;
+ --cr-gutter: clamp(var(--space-md), 4vw, var(--space-xl));
+ --cr-screen-bg: #e9ebef;
+ /* Drawn over captured pages of any colour, so it does not follow the theme
+ * accent (white in dark mode): a bright ring around a dark one reads on
+ * white and black sites alike. */
+ --cr-target: #22c55e;
+ --cr-target-halo: rgba(6, 24, 12, 0.55);
+ --cr-ease: var(--ease-standard, cubic-bezier(0.2, 0, 0, 1));
+}
+
+.crawl-page main > section {
+ max-width: var(--cr-max);
+ margin-inline: auto;
+ padding-inline: var(--cr-gutter);
+}
+
+.cr-visually-hidden {
+ position: absolute;
+ width: 1px;
+ height: 1px;
+ padding: 0;
+ margin: -1px;
+ overflow: hidden;
+ clip: rect(0 0 0 0);
+ white-space: nowrap;
+ border: 0;
+}
+
+.cr-muted { color: var(--ink-dim); }
+
+/* ── The avatar canvas: above the screens, below the nav and every modal ── */
+.cr-bodies {
+ position: fixed;
+ inset: 0;
+ width: 100vw;
+ height: 100vh;
+ pointer-events: none;
+ z-index: 40;
+}
+
+/* ── Skeletons ─────────────────────────────────────────────────────────── */
+.cr-skel {
+ display: block;
+ min-height: 0.9em;
+ border-radius: var(--skeleton-radius, var(--radius-sm));
+ background: linear-gradient(90deg, var(--skeleton-base) 0%, var(--skeleton-sheen) 50%, var(--skeleton-base) 100%);
+ background-size: 200% 100%;
+ animation: cr-shimmer 1.4s linear infinite;
+}
+.cr-skel-num { width: 4.5ch; height: 1.6rem; }
+@keyframes cr-shimmer { to { background-position: -200% 0; } }
+
+/* ── Buttons and links ─────────────────────────────────────────────────── */
+.cr-btn {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ gap: var(--space-xs);
+ min-height: 2.5rem;
+ padding: 0 var(--space-md);
+ border: 1px solid var(--stroke-strong);
+ border-radius: var(--radius-pill);
+ background: var(--surface-1);
+ color: var(--ink);
+ font: 500 var(--text-ui) / 1 var(--font-body);
+ text-decoration: none;
+ cursor: pointer;
+ transition: background-color 0.16s var(--cr-ease), border-color 0.16s var(--cr-ease), transform 0.12s var(--cr-ease), color 0.16s;
+}
+.cr-btn:hover { background: var(--surface-2); border-color: var(--ink-faint); }
+.cr-btn:active { transform: translateY(1px) scale(0.985); }
+.cr-btn:disabled { opacity: var(--disabled-opacity, 0.5); cursor: var(--disabled-cursor, not-allowed); transform: none; }
+.cr-btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
+.cr-btn-primary:hover { background: var(--btn-primary-bg-hover, var(--accent)); border-color: var(--btn-primary-bg-hover, var(--accent)); filter: brightness(1.06); }
+.cr-btn-ghost { background: transparent; border-color: transparent; color: var(--ink-dim); }
+.cr-btn-ghost:hover { background: var(--surface-1); color: var(--ink); border-color: var(--stroke); }
+.cr-btn-small { min-height: 2rem; padding: 0 var(--space-sm); font-size: var(--text-sm); }
+
+.cr-link {
+ color: var(--accent);
+ text-decoration: underline;
+ text-decoration-color: color-mix(in srgb, currentColor 35%, transparent);
+ text-underline-offset: 3px;
+ transition: text-decoration-color 0.16s;
+}
+.cr-link:hover { text-decoration-color: currentColor; }
+
+.crawl-page :is(a, button, select, input, textarea, [tabindex]):focus-visible {
+ outline: var(--focus-ring-width, 2px) solid var(--focus-ring-color);
+ outline-offset: var(--focus-ring-offset, 2px);
+}
+
+/* ── Hero ─────────────────────────────────────────────────────────────── */
+.cr-hero {
+ display: grid;
+ grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
+ gap: var(--space-xl);
+ align-items: end;
+ padding-block: clamp(var(--space-xl), 6vw, var(--space-2xl)) var(--space-xl);
+}
+.cr-eyebrow {
+ display: inline-flex;
+ align-items: center;
+ gap: var(--space-xs);
+ margin: 0 0 var(--space-sm);
+ color: var(--ink-dim);
+ font: 500 var(--text-sm) / 1.3 var(--font-mono);
+}
+.cr-live-dot {
+ width: 8px;
+ height: 8px;
+ border-radius: 50%;
+ background: var(--ink-faint);
+ flex: none;
+}
+.cr-eyebrow[data-state='live'] .cr-live-dot {
+ background: var(--success);
+ box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 60%, transparent);
+ animation: cr-pulse 2s ease-out infinite;
+}
+.cr-eyebrow[data-state='reconnecting'] .cr-live-dot,
+.cr-eyebrow[data-state='offline'] .cr-live-dot { background: var(--warn); }
+@keyframes cr-pulse { to { box-shadow: 0 0 0 9px transparent; } }
+
+.cr-hero h1 {
+ margin: 0;
+ font: 700 clamp(2.4rem, 6vw, 4.2rem) / 1 var(--font-display);
+ letter-spacing: -0.03em;
+ color: var(--ink-bright);
+}
+.cr-sub {
+ max-width: 58ch;
+ margin: var(--space-md) 0 var(--space-lg);
+ color: var(--ink-dim);
+ font-size: var(--text-lg);
+ line-height: var(--leading-normal, 1.55);
+}
+.cr-hero-actions { display: flex; flex-wrap: wrap; gap: var(--space-sm); }
+
+.cr-stats {
+ display: grid;
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ gap: 1px;
+ margin: 0;
+ border: 1px solid var(--stroke);
+ border-radius: var(--radius-lg);
+ background: var(--stroke);
+ overflow: hidden;
+}
+.cr-stat { padding: var(--space-md); background: var(--bg-0); }
+.cr-stat:first-child { grid-column: 1 / -1; }
+.cr-stat dt { color: var(--ink-faint); font: 500 var(--text-xs) / 1.2 var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; }
+.cr-stat dd {
+ margin: var(--space-xs) 0 0;
+ color: var(--ink-bright);
+ font: 600 var(--text-2xl) / 1.1 var(--font-display);
+ font-variant-numeric: tabular-nums;
+}
+.cr-stat dd.is-bump { animation: cr-bump 0.5s var(--cr-ease); }
+@keyframes cr-bump { 0% { color: var(--accent); transform: translateY(-2px); } 100% { color: var(--ink-bright); transform: none; } }
+
+/* ── Live: featured screen + feed ─────────────────────────────────────── */
+.cr-live {
+ display: grid;
+ grid-template-columns: minmax(0, 1fr) 320px;
+ gap: var(--space-lg);
+ align-items: start;
+ padding-bottom: var(--space-xl);
+}
+
+.cr-browser {
+ border: 1px solid var(--stroke-strong);
+ border-radius: var(--radius-lg);
+ background: var(--surface-1);
+ overflow: hidden;
+ box-shadow: var(--shadow-2);
+}
+.cr-chrome {
+ display: flex;
+ align-items: center;
+ gap: var(--space-sm);
+ padding: var(--space-xs) var(--space-sm);
+ border-bottom: 1px solid var(--stroke);
+ background: var(--surface-2);
+}
+.cr-lights { display: inline-flex; gap: 6px; flex: none; }
+.cr-lights i { width: 10px; height: 10px; border-radius: 50%; background: var(--stroke-strong); }
+.cr-urlbar {
+ display: flex;
+ align-items: center;
+ gap: var(--space-xs);
+ flex: 1;
+ min-width: 0;
+ height: 1.9rem;
+ padding: 0 var(--space-sm);
+ border-radius: var(--radius-pill);
+ background: var(--bg-0);
+ border: 1px solid var(--stroke);
+}
+.cr-lock {
+ width: 9px;
+ height: 11px;
+ flex: none;
+ border: 1.5px solid var(--ink-faint);
+ border-radius: 2px;
+ border-top-width: 4px;
+}
+.cr-url {
+ overflow: hidden;
+ white-space: nowrap;
+ text-overflow: ellipsis;
+ color: var(--ink-faint);
+ font: 400 var(--text-sm) / 1 var(--font-mono);
+}
+.cr-url strong { color: var(--ink); font-weight: 500; }
+.cr-status-pill {
+ flex: none;
+ padding: 0.25rem 0.6rem;
+ border-radius: var(--radius-pill);
+ border: 1px solid var(--stroke);
+ color: var(--ink-dim);
+ font: 500 var(--text-xs) / 1 var(--font-mono);
+ text-transform: uppercase;
+ letter-spacing: 0.05em;
+ transition: color 0.2s, border-color 0.2s, background-color 0.2s;
+}
+:is(.cr-status-pill, .cr-tile-status)[data-status='reading'] { color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, transparent); }
+:is(.cr-status-pill, .cr-tile-status)[data-status='walking'],
+:is(.cr-status-pill, .cr-tile-status)[data-status='leaping'] { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
+:is(.cr-status-pill, .cr-tile-status)[data-status='blocked'] { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
+:is(.cr-status-pill, .cr-tile-status)[data-status='resting'] { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
+
+.cr-screen {
+ position: relative;
+ aspect-ratio: 1200 / 750;
+ background: var(--cr-screen-bg);
+ overflow: hidden;
+}
+.cr-frame {
+ position: absolute;
+ inset: 0;
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ object-position: top;
+ opacity: 0;
+ transition: opacity 0.35s var(--cr-ease);
+}
+.cr-frame.is-on { opacity: 1; }
+.cr-screen-skel {
+ position: absolute;
+ inset: 0;
+ border-radius: 0;
+ transition: opacity 0.3s;
+}
+.cr-screen:not([data-state='loading']) .cr-screen-skel { opacity: 0; pointer-events: none; }
+.cr-screen[data-state='noframe']::before {
+ content: 'The screen refreshes when the agent opens its next page';
+ position: absolute;
+ inset: 0;
+ display: grid;
+ place-items: center;
+ padding: var(--space-lg);
+ color: #5b606b;
+ font: 500 var(--text-sm) / 1.4 var(--font-body);
+ text-align: center;
+}
+
+.cr-links { position: absolute; inset: 0; pointer-events: none; }
+.cr-linkbox {
+ position: absolute;
+ border-radius: 3px;
+ opacity: 0;
+ transition: opacity 0.25s, box-shadow 0.25s;
+}
+.cr-screen.show-links .cr-linkbox { opacity: 1; outline: 1px dashed color-mix(in srgb, var(--cr-target) 70%, transparent); outline-offset: 1px; }
+.cr-linkbox.is-target {
+ opacity: 1;
+ background: color-mix(in srgb, var(--cr-target) 18%, transparent);
+ box-shadow: 0 0 0 1px var(--cr-target-halo), 0 0 0 3px var(--cr-target), 0 0 0 4px var(--cr-target-halo), 0 0 20px 4px color-mix(in srgb, var(--cr-target) 50%, transparent);
+ animation: cr-target 1.2s ease-in-out infinite alternate;
+}
+@keyframes cr-target { to { box-shadow: 0 0 0 1px var(--cr-target-halo), 0 0 0 3px var(--cr-target), 0 0 0 4px var(--cr-target-halo), 0 0 6px 0 color-mix(in srgb, var(--cr-target) 25%, transparent); } }
+
+.cr-opening {
+ position: absolute;
+ left: 50%;
+ bottom: var(--space-md);
+ display: flex;
+ align-items: center;
+ gap: var(--space-xs);
+ max-width: calc(100% - 2 * var(--space-md));
+ padding: var(--space-xs) var(--space-md);
+ border-radius: var(--radius-pill);
+ background: rgba(10, 10, 14, 0.82);
+ color: #fff;
+ font: 500 var(--text-sm) / 1.2 var(--font-mono);
+ backdrop-filter: blur(8px);
+ opacity: 0;
+ transform: translate(-50%, 8px);
+ transition: opacity 0.25s var(--cr-ease), transform 0.25s var(--cr-ease);
+ pointer-events: none;
+ z-index: 2;
+}
+.cr-opening.is-on { opacity: 1; transform: translate(-50%, 0); }
+.cr-opening span { color: rgba(255, 255, 255, 0.65); }
+.cr-opening strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 600; }
+.cr-opening strong:empty { display: none; }
+
+/* The thought bubble rides above the avatar's head (positioned by page.js). */
+.cr-bubble {
+ position: absolute;
+ left: 0;
+ top: 0;
+ width: max-content;
+ max-width: min(260px, 46%);
+ padding: 0.45rem 0.7rem;
+ border-radius: 12px;
+ background: rgba(255, 255, 255, 0.96);
+ color: #15161a;
+ font: 500 var(--text-sm) / 1.35 var(--font-body);
+ box-shadow: 0 6px 22px rgba(0, 0, 0, 0.22);
+ opacity: 0;
+ pointer-events: none;
+ transition: opacity 0.25s;
+ z-index: 3;
+ will-change: transform;
+ translate: 10px -100%;
+}
+.cr-bubble[data-side='left'] { translate: calc(-100% - 10px) -100%; }
+.cr-bubble.is-on { opacity: 1; }
+.cr-bubble:empty { display: none; }
+/* Without WebGL there is no avatar to follow: pin the bubble to a corner. */
+.cr-no-bodies .cr-bubble { transform: none !important; translate: none; top: auto; left: var(--space-md); bottom: var(--space-md); }
+
+.cr-screen-empty {
+ position: absolute;
+ inset: 0;
+ display: grid;
+ place-content: center;
+ justify-items: center;
+ gap: var(--space-xs);
+ padding: var(--space-lg);
+ text-align: center;
+ background: var(--surface-1);
+ z-index: 4;
+}
+.cr-screen-empty p { margin: 0; max-width: 46ch; }
+.cr-empty-title { color: var(--ink-bright); font: 600 var(--text-xl) / 1.2 var(--font-display); }
+.cr-empty-actions { display: flex; flex-wrap: wrap; gap: var(--space-sm); justify-content: center; margin-top: var(--space-sm); }
+
+.cr-agentbar {
+ display: grid;
+ grid-template-columns: auto minmax(0, 1fr) auto;
+ gap: var(--space-md);
+ align-items: center;
+ padding: var(--space-sm) var(--space-xs);
+}
+.cr-agent-id { display: flex; align-items: center; gap: var(--space-sm); min-width: 0; }
+.cr-agent-id > div { min-width: 0; }
+.cr-agent-thumb { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--surface-2); flex: none; }
+.cr-agent-name { margin: 0; color: var(--ink-bright); font: 600 var(--text-base) / 1.2 var(--font-display); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
+.cr-agent-topic { margin: 2px 0 0; color: var(--ink-faint); font-size: var(--text-sm); max-width: min(32ch, 100%); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
+.cr-thought {
+ margin: 0;
+ color: var(--ink-dim);
+ font-size: var(--text-sm);
+ font-style: italic;
+ overflow: hidden;
+ display: -webkit-box;
+ -webkit-line-clamp: 2;
+ -webkit-box-orient: vertical;
+}
+.cr-agent-meta { display: flex; align-items: center; gap: var(--space-sm); color: var(--ink-faint); font-size: var(--text-sm); white-space: nowrap; }
+.cr-keys { margin: 0 var(--space-xs); color: var(--ink-faint); font-size: var(--text-xs); }
+.cr-keys kbd {
+ display: inline-block;
+ min-width: 1.5em;
+ padding: 0.05em 0.35em;
+ border: 1px solid var(--stroke-strong);
+ border-bottom-width: 2px;
+ border-radius: 4px;
+ font: 500 0.95em / 1.3 var(--font-mono);
+ text-align: center;
+}
+
+/* Feed */
+.cr-feed {
+ border: 1px solid var(--stroke);
+ border-radius: var(--radius-lg);
+ background: var(--surface-1);
+ overflow: hidden;
+}
+.cr-panel-head {
+ display: flex;
+ align-items: baseline;
+ justify-content: space-between;
+ padding: var(--space-sm) var(--space-md);
+ border-bottom: 1px solid var(--stroke);
+}
+.cr-panel-head h2 { margin: 0; font: 600 var(--text-base) / 1.2 var(--font-display); color: var(--ink-bright); }
+.cr-panel-head .cr-muted { font: 400 var(--text-xs) / 1 var(--font-mono); }
+.cr-feed-list {
+ margin: 0;
+ padding: 0;
+ list-style: none;
+ max-height: 560px;
+ overflow-y: auto;
+ overscroll-behavior: contain;
+}
+.cr-feed-list > li { padding: var(--space-sm) var(--space-md); border-bottom: 1px solid var(--stroke); }
+.cr-feed-list > li:last-child { border-bottom: 0; }
+.cr-feed-skel { display: grid; gap: 6px; }
+.cr-feed-skel .cr-skel:last-child { width: 60%; }
+.cr-feed-item { display: grid; gap: 3px; }
+.cr-feed-item.is-new { animation: cr-arrive 0.6s var(--cr-ease); }
+@keyframes cr-arrive {
+ from { opacity: 0; transform: translateY(-6px); background: color-mix(in srgb, var(--accent) 12%, transparent); }
+ to { opacity: 1; transform: none; background: transparent; }
+}
+.cr-feed-title {
+ color: var(--ink);
+ font-size: var(--text-sm);
+ font-weight: 500;
+ line-height: 1.35;
+ text-decoration: none;
+ overflow: hidden;
+ display: -webkit-box;
+ -webkit-line-clamp: 2;
+ -webkit-box-orient: vertical;
+}
+a.cr-feed-title:hover { color: var(--accent); }
+.cr-feed-meta { color: var(--ink-faint); font-size: var(--text-xs); }
+.cr-feed-agent {
+ padding: 0;
+ border: 0;
+ background: none;
+ color: var(--ink-dim);
+ font: inherit;
+ font-weight: 600;
+ cursor: pointer;
+}
+.cr-feed-agent:hover { color: var(--accent); text-decoration: underline; }
+.cr-feed-empty p { margin: 0 0 4px; font-size: var(--text-sm); }
+
+/* ── The wall ─────────────────────────────────────────────────────────── */
+.cr-wall-section { padding-block: var(--space-xl); }
+.cr-section-head { margin-bottom: var(--space-md); }
+.cr-section-head h2 { margin: 0 0 var(--space-xs); color: var(--ink-bright); font: 650 var(--text-2xl) / 1.15 var(--font-display); letter-spacing: -0.01em; }
+.cr-section-head p { margin: 0; max-width: 70ch; }
+
+.cr-wall {
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
+ gap: var(--space-md);
+}
+.cr-wall-empty { grid-column: 1 / -1; margin: 0; padding: var(--space-lg); border: 1px dashed var(--stroke-strong); border-radius: var(--radius-md); text-align: center; }
+.cr-tile {
+ display: grid;
+ width: 100%;
+ padding: 0;
+ border: 1px solid var(--stroke);
+ border-radius: var(--radius-md);
+ background: var(--surface-1);
+ color: inherit;
+ text-align: left;
+ cursor: pointer;
+ overflow: hidden;
+ transition: border-color 0.16s, transform 0.16s var(--cr-ease), box-shadow 0.16s;
+}
+.cr-tile:hover { border-color: var(--stroke-strong); transform: translateY(-2px); box-shadow: var(--shadow-2); }
+.cr-tile:active { transform: translateY(0); }
+.cr-tile[aria-pressed='true'] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
+.cr-tile-screen {
+ position: relative;
+ display: block;
+ aspect-ratio: 1200 / 750;
+ background: linear-gradient(90deg, var(--skeleton-base) 0%, var(--skeleton-sheen) 50%, var(--skeleton-base) 100%);
+ background-size: 200% 100%;
+ animation: cr-shimmer 1.4s linear infinite;
+}
+.cr-tile-screen.has-frame { background: var(--cr-screen-bg); animation: none; }
+.cr-tile-frame { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: top; }
+.cr-tile-frame:not([src]) { visibility: hidden; }
+.cr-tile-meta { display: grid; gap: 3px; padding: var(--space-xs) var(--space-sm) var(--space-sm); min-width: 0; }
+.cr-tile-name { color: var(--ink-bright); font: 600 var(--text-sm) / 1.2 var(--font-display); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
+.cr-tile-line { display: flex; align-items: center; gap: var(--space-xs); min-width: 0; }
+.cr-tile-status {
+ flex: none;
+ padding: 0.1rem 0.4rem;
+ border: 1px solid var(--stroke);
+ border-radius: var(--radius-pill);
+ color: var(--ink-dim);
+ font: 500 0.66rem / 1.2 var(--font-mono);
+ text-transform: uppercase;
+ letter-spacing: 0.05em;
+}
+.cr-tile-domain { color: var(--ink-faint); font: 400 var(--text-xs) / 1.2 var(--font-mono); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
+
+.cr-resting { margin-top: var(--space-lg); }
+.cr-resting h3 { margin: 0 0 4px; font: 600 var(--text-base) / 1.2 var(--font-display); color: var(--ink-bright); }
+.cr-resting > p { margin: 0 0 var(--space-sm); font-size: var(--text-sm); }
+.cr-resting-list { display: flex; flex-wrap: wrap; gap: var(--space-sm); margin: 0; padding: 0; list-style: none; }
+.cr-resting-item {
+ display: flex;
+ align-items: center;
+ gap: var(--space-xs);
+ max-width: 320px;
+ padding: var(--space-xs) var(--space-sm) var(--space-xs) var(--space-xs);
+ border: 1px solid var(--stroke);
+ border-radius: var(--radius-pill);
+ color: inherit;
+ text-decoration: none;
+ transition: border-color 0.16s, background-color 0.16s;
+}
+.cr-resting-item:hover { border-color: var(--stroke-strong); background: var(--surface-1); }
+.cr-resting-item img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex: none; }
+.cr-resting-item > span:last-child { display: grid; min-width: 0; font-size: var(--text-xs); }
+.cr-resting-item .cr-muted { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
+.cr-resting-name { color: var(--ink); font-weight: 600; font-size: var(--text-sm); }
+
+/* ── Send ─────────────────────────────────────────────────────────────── */
+.cr-send { padding-block: var(--space-xl); scroll-margin-top: calc(var(--header-h, 3.5rem) + var(--space-md)); }
+.cr-send:focus { outline: none; }
+.cr-send-body {
+ padding: var(--space-lg);
+ border: 1px solid var(--stroke);
+ border-radius: var(--radius-lg);
+ background: var(--surface-1);
+}
+.cr-send-skel { height: 180px; }
+.cr-send-cta { display: grid; justify-items: start; gap: var(--space-xs); }
+.cr-send-cta h3 { margin: 0; color: var(--ink-bright); font: 600 var(--text-xl) / 1.2 var(--font-display); }
+.cr-send-cta p { margin: 0 0 var(--space-xs); max-width: 60ch; }
+.cr-send-grid { display: grid; grid-template-columns: minmax(0, 280px) minmax(0, 1fr); gap: var(--space-xl); }
+.cr-label { margin: 0 0 var(--space-xs); color: var(--ink-faint); font: 500 var(--text-xs) / 1.2 var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; }
+.cr-picks { display: grid; gap: var(--space-xs); max-height: 360px; overflow-y: auto; padding: 2px; }
+.cr-pick {
+ display: flex;
+ align-items: center;
+ gap: var(--space-sm);
+ width: 100%;
+ padding: var(--space-xs) var(--space-sm);
+ border: 1px solid var(--stroke);
+ border-radius: var(--radius-md);
+ background: var(--bg-0);
+ color: inherit;
+ text-align: left;
+ cursor: pointer;
+ transition: border-color 0.16s, background-color 0.16s;
+}
+.cr-pick:hover { border-color: var(--stroke-strong); }
+.cr-pick[aria-checked='true'] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--bg-0)); }
+.cr-pick img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex: none; }
+.cr-pick-initial {
+ display: grid;
+ place-items: center;
+ width: 36px;
+ height: 36px;
+ flex: none;
+ border-radius: 50%;
+ background: var(--surface-3);
+ color: var(--ink-dim);
+ font: 600 var(--text-sm) / 1 var(--font-display);
+}
+.cr-resting-item .cr-pick-initial { width: 32px; height: 32px; }
+.cr-pick-text { display: grid; gap: 2px; min-width: 0; }
+.cr-pick-name { color: var(--ink); font-weight: 600; font-size: var(--text-sm); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
+.cr-pick-state { color: var(--ink-faint); font-size: var(--text-xs); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
+.cr-pick-state[data-on='true'] { color: var(--success); }
+
+.cr-send-name { margin: 0 0 4px; color: var(--ink-bright); font: 600 var(--text-xl) / 1.2 var(--font-display); }
+.cr-send-stats { margin: 0 0 var(--space-md); font-size: var(--text-sm); }
+.cr-form { display: grid; gap: var(--space-md); max-width: 640px; }
+.cr-field { display: grid; gap: 6px; }
+.cr-field label { display: flex; justify-content: space-between; color: var(--ink); font-weight: 600; font-size: var(--text-sm); }
+.cr-counter { color: var(--ink-faint); font: 400 var(--text-xs) / 1.4 var(--font-mono); }
+.cr-field :is(input, textarea) {
+ width: 100%;
+ padding: 0.6rem 0.75rem;
+ border: 1px solid var(--stroke-strong);
+ border-radius: var(--radius-md);
+ background: var(--bg-0);
+ color: var(--ink);
+ font: 400 var(--text-base) / 1.4 var(--font-body);
+ transition: border-color 0.16s, box-shadow 0.16s;
+}
+.cr-field textarea { font-family: var(--font-mono); font-size: var(--text-sm); resize: vertical; min-height: 5.5rem; }
+.cr-field :is(input, textarea):hover { border-color: var(--ink-faint); }
+.cr-field :is(input, textarea):focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); outline: none; }
+.cr-hint { margin: 0; color: var(--ink-faint); font-size: var(--text-xs); }
+.cr-form-error {
+ margin: 0;
+ padding: var(--space-xs) var(--space-sm);
+ border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
+ border-radius: var(--radius-sm);
+ background: color-mix(in srgb, var(--danger) 10%, transparent);
+ color: var(--danger);
+ font-size: var(--text-sm);
+}
+.cr-form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm); }
+.cr-form-ok { margin: 0; color: var(--success); font-size: var(--text-sm); }
+
+/* ── Corpus ───────────────────────────────────────────────────────────── */
+.cr-corpus { padding-block: var(--space-xl); scroll-margin-top: calc(var(--header-h, 3.5rem) + var(--space-md)); }
+.cr-corpus-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: var(--space-md); }
+.cr-corpus-tools { display: flex; flex-wrap: wrap; gap: var(--space-sm); }
+.cr-select select {
+ min-height: 2.5rem;
+ max-width: 240px;
+ padding: 0 2rem 0 var(--space-sm);
+ border: 1px solid var(--stroke-strong);
+ border-radius: var(--radius-pill);
+ background: var(--surface-1);
+ color: var(--ink);
+ font: 500 var(--text-ui) / 1 var(--font-body);
+ cursor: pointer;
+}
+.cr-select select:hover { border-color: var(--ink-faint); }
+/* Positioned so the visually hidden header label stays inside the scroller. */
+.cr-table-wrap { position: relative; border: 1px solid var(--stroke); border-radius: var(--radius-lg); overflow-x: auto; }
+.cr-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
+.cr-table th {
+ padding: var(--space-xs) var(--space-sm);
+ border-bottom: 1px solid var(--stroke);
+ background: var(--surface-1);
+ color: var(--ink-faint);
+ font: 500 var(--text-xs) / 1.2 var(--font-mono);
+ text-align: left;
+ text-transform: uppercase;
+ letter-spacing: 0.05em;
+ white-space: nowrap;
+}
+.cr-table td { padding: var(--space-sm); border-bottom: 1px solid var(--stroke); vertical-align: top; }
+.cr-table tbody tr:last-child td { border-bottom: 0; }
+.cr-table tbody tr:not(.cr-row-skel):not(.cr-row-empty):hover { background: var(--surface-1); }
+.cr-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
+.cr-page-cell { display: grid; gap: 2px; min-width: 260px; max-width: 560px; }
+.cr-page-title { color: var(--ink); font-weight: 600; text-decoration: none; }
+a.cr-page-title:hover { color: var(--accent); text-decoration: underline; }
+.cr-page-domain { color: var(--ink-faint); font: 400 var(--text-xs) / 1.3 var(--font-mono); }
+.cr-page-gist { color: var(--ink-dim); font-size: var(--text-xs); line-height: 1.45; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
+.cr-chip {
+ max-width: 160px;
+ padding: 0.2rem 0.55rem;
+ border: 1px solid var(--stroke);
+ border-radius: var(--radius-pill);
+ background: transparent;
+ color: var(--ink-dim);
+ font: 500 var(--text-xs) / 1.2 var(--font-body);
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ cursor: pointer;
+ transition: border-color 0.16s, color 0.16s;
+}
+.cr-chip:hover { border-color: var(--accent); color: var(--accent); }
+.cr-meter { display: block; width: 64px; height: 6px; margin-top: 0.45em; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
+.cr-meter > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
+.cr-when { color: var(--ink-faint); white-space: nowrap; }
+.cr-row-skel .cr-skel { width: 80%; }
+.cr-row-skel td:first-child .cr-skel { width: 90%; height: 2.4em; }
+.cr-row-empty td { padding: var(--space-xl) var(--space-md); text-align: center; }
+.cr-row-empty p { margin: 0 auto var(--space-sm); max-width: 56ch; color: var(--ink-dim); }
+.cr-corpus-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-sm); margin-top: var(--space-sm); min-height: 2.5rem; }
+.cr-corpus-foot p { margin: 0; font-size: var(--text-sm); }
+
+/* ── How it works ─────────────────────────────────────────────────────── */
+.cr-how { padding-block: var(--space-xl) var(--space-2xl); }
+.cr-how h2 { margin: 0 0 var(--space-md); color: var(--ink-bright); font: 650 var(--text-2xl) / 1.15 var(--font-display); }
+.cr-how-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-md); margin: 0 0 var(--space-md); padding: 0; list-style: none; counter-reset: cr-step; }
+.cr-how-steps li { padding: var(--space-md); border: 1px solid var(--stroke); border-radius: var(--radius-lg); background: var(--surface-1); counter-increment: cr-step; }
+.cr-how-steps li::before { content: counter(cr-step, decimal-leading-zero); color: var(--accent); font: 600 var(--text-sm) / 1 var(--font-mono); }
+.cr-how-steps h3 { margin: var(--space-xs) 0; color: var(--ink-bright); font: 600 var(--text-base) / 1.25 var(--font-display); }
+.cr-how-steps p { margin: 0; color: var(--ink-dim); font-size: var(--text-sm); line-height: 1.55; }
+
+/* ── Responsive ───────────────────────────────────────────────────────── */
+@media (max-width: 1080px) {
+ .cr-live { grid-template-columns: minmax(0, 1fr); }
+ .cr-feed-list { max-height: 340px; }
+}
+@media (max-width: 860px) {
+ .cr-hero { grid-template-columns: minmax(0, 1fr); align-items: start; }
+ .cr-agentbar { grid-template-columns: minmax(0, 1fr) auto; }
+ .cr-thought { grid-column: 1 / -1; grid-row: 2; }
+ .cr-send-grid { grid-template-columns: minmax(0, 1fr); gap: var(--space-md); }
+ .cr-picks { max-height: 220px; }
+ .cr-how-steps { grid-template-columns: minmax(0, 1fr); }
+ .cr-keys { display: none; }
+}
+@media (max-width: 520px) {
+ .cr-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
+ .cr-stat dd { font-size: var(--text-xl); }
+ .cr-lights { display: none; }
+ .cr-agentbar { grid-template-columns: minmax(0, 1fr); }
+ .cr-agent-meta { flex-wrap: wrap; }
+ .cr-wall { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-sm); }
+ .cr-send-body { padding: var(--space-md); }
+ .cr-bubble { max-width: 60%; font-size: var(--text-xs); }
+ .cr-select select { max-width: 100%; }
+}
+/* Phones: each corpus row becomes a card (page first, then who read it, how
+ * much, how on topic, when) instead of a table that scrolls sideways. */
+@media (max-width: 640px) {
+ .cr-table thead {
+ position: absolute;
+ width: 1px;
+ height: 1px;
+ overflow: hidden;
+ clip-path: inset(50%);
+ }
+ .cr-table, .cr-table tbody { display: block; }
+ .cr-table tbody tr {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: var(--space-xs) var(--space-sm);
+ padding: var(--space-sm) var(--space-md);
+ border-bottom: 1px solid var(--stroke);
+ }
+ .cr-table tbody tr:last-child { border-bottom: 0; }
+ .cr-table td { display: block; padding: 0; border: 0; }
+ .cr-table td.cr-page-cell { display: grid; flex: 1 0 100%; min-width: 0; max-width: none; }
+ .cr-table td.cr-num::after { content: ' tokens'; color: var(--ink-faint); }
+ .cr-meter { margin-top: 0; }
+ .cr-table td:last-child { margin-left: auto; }
+ .cr-row-skel td { flex: 1 0 40%; }
+ .cr-row-skel td:first-child { flex-basis: 100%; }
+ .cr-row-empty { justify-content: center; }
+ .cr-row-empty td { padding: var(--space-lg) 0; }
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .cr-skel,
+ .cr-tile-screen,
+ .cr-linkbox.is-target,
+ .cr-eyebrow[data-state='live'] .cr-live-dot { animation: none; }
+ .cr-frame,
+ .cr-opening,
+ .cr-tile,
+ .cr-btn { transition: none; }
+ .cr-feed-item.is-new,
+ .cr-stat dd.is-bump { animation: none; }
+}
diff --git a/src/crawl/corpus.js b/src/crawl/corpus.js
new file mode 100644
index 000000000..778a62394
--- /dev/null
+++ b/src/crawl/corpus.js
@@ -0,0 +1,148 @@
+// The corpus table on /crawl: every page the agents read, newest first, with an
+// agent filter, keyset pagination, and a JSONL download that follows the filter.
+
+import { apiError, fmtCount, h, safeHref, timeAgo } from './format.js';
+
+const PAGE_SIZE = 40;
+
+export function mountCorpus({ body, select, more, note, download }) {
+ let agent = '';
+ let next = null;
+ let loading = false;
+ let fresh = 0;
+ let generation = 0;
+ const known = new Set();
+
+ function skeletonRows(n = 6) {
+ return Array.from({ length: n }, () => h('tr', { class: 'cr-row-skel' },
+ h('td', {}, h('span', { class: 'cr-skel' })),
+ h('td', {}, h('span', { class: 'cr-skel' })),
+ h('td', {}, h('span', { class: 'cr-skel' })),
+ h('td', {}, h('span', { class: 'cr-skel' })),
+ h('td', {}, h('span', { class: 'cr-skel' })),
+ h('td', {}),
+ ));
+ }
+
+ function row(p) {
+ const href = safeHref(p.url);
+ const rel = Math.round(Math.max(0, Math.min(1, Number(p.relevance) || 0)) * 100);
+ return h('tr', {},
+ h('td', { class: 'cr-page-cell' },
+ href
+ ? h('a', { class: 'cr-page-title', href, target: '_blank', rel: 'noopener nofollow ugc', text: p.title || p.url })
+ : h('span', { class: 'cr-page-title', text: p.title || p.url }),
+ h('span', { class: 'cr-page-domain', text: p.domain || '' }),
+ p.gist ? h('span', { class: 'cr-page-gist', text: p.gist }) : null,
+ ),
+ h('td', {}, h('button', {
+ type: 'button', class: 'cr-chip', text: p.agentName || 'Agent',
+ title: `Only pages read by ${p.agentName || 'this agent'}`,
+ onclick: () => setAgent(p.agentId),
+ })),
+ h('td', { class: 'cr-num', text: fmtCount(p.tokens) }),
+ h('td', {},
+ h('span', { class: 'cr-meter', role: 'meter', 'aria-valuemin': 0, 'aria-valuemax': 100, 'aria-valuenow': rel, 'aria-label': `${rel}% on topic` },
+ h('span', { style: `width:${rel}%` })),
+ ),
+ h('td', { class: 'cr-when' }, h('time', { datetime: p.readAt, title: new Date(p.readAt).toLocaleString(), text: timeAgo(p.readAt) })),
+ h('td', {}, p.textUrl
+ ? h('a', { class: 'cr-link', href: p.textUrl, target: '_blank', rel: 'noopener', text: 'Text', 'aria-label': `Full text of ${p.title || p.url}` })
+ : null),
+ );
+ }
+
+ function emptyRow(message, action) {
+ return h('tr', { class: 'cr-row-empty' }, h('td', { colspan: 6 },
+ h('p', { text: message }), action || null));
+ }
+
+ function syncDownload() {
+ const q = new URLSearchParams({ format: 'jsonl', limit: '500' });
+ if (agent) q.set('agent', agent);
+ download.href = `/api/crawl/pages?${q}`;
+ }
+
+ async function load({ append = false } = {}) {
+ if (loading) return;
+ loading = true;
+ const gen = ++generation;
+ if (!append) {
+ body.replaceChildren(...skeletonRows());
+ next = null;
+ fresh = 0;
+ }
+ more.disabled = true;
+ note.textContent = append ? 'Loading more pages' : '';
+ const q = new URLSearchParams({ limit: String(PAGE_SIZE) });
+ if (agent) q.set('agent', agent);
+ if (append && next) q.set('before', String(next));
+ try {
+ const res = await fetch(`/api/crawl/pages?${q}`, { headers: { accept: 'application/json' } });
+ if (!res.ok) throw new Error(await apiError(res));
+ const data = await res.json();
+ if (gen !== generation) return;
+ const rows = (data.pages || []).map(row);
+ if (!append) body.replaceChildren();
+ if (!rows.length && !append) {
+ body.append(emptyRow(agent
+ ? 'This agent has not filed a page yet. Pages appear here a few seconds after it finishes reading them.'
+ : 'Nothing has been read yet. Send an agent out and its first pages will appear here.',
+ agent ? h('button', { type: 'button', class: 'cr-btn', text: 'Show all agents', onclick: () => setAgent('') }) : h('a', { class: 'cr-btn', href: '#send', text: 'Send your agent out' })));
+ }
+ body.append(...rows);
+ next = data.next;
+ more.hidden = !next;
+ more.disabled = false;
+ note.textContent = '';
+ } catch (err) {
+ if (gen !== generation) return;
+ if (!append) body.replaceChildren();
+ const retry = h('button', { type: 'button', class: 'cr-btn', text: 'Try again', onclick: () => load({ append }) });
+ if (append) {
+ note.textContent = `Could not load more pages: ${err.message}`;
+ more.disabled = false;
+ } else {
+ body.append(emptyRow(`The corpus could not be loaded: ${err.message}`, retry));
+ }
+ } finally {
+ if (gen === generation) loading = false;
+ }
+ }
+
+ function setAgent(id) {
+ agent = id || '';
+ if (select.value !== agent) select.value = agent;
+ syncDownload();
+ load();
+ }
+
+ // Keep the filter list in step with every agent we have seen.
+ function addAgents(list) {
+ for (const a of list) {
+ if (!a?.agentId || known.has(a.agentId)) continue;
+ known.add(a.agentId);
+ select.append(h('option', { value: a.agentId, text: a.name || 'Agent' }));
+ }
+ }
+
+ // A page just landed: offer it rather than reshuffling rows under the reader.
+ function notifyNew(agentId) {
+ if (agent && agentId !== agent) return;
+ fresh += 1;
+ more.hidden = false;
+ note.replaceChildren(h('button', {
+ type: 'button', class: 'cr-btn cr-btn-small',
+ text: `Show ${fresh} new page${fresh === 1 ? '' : 's'}`,
+ onclick: () => load(),
+ }));
+ more.hidden = !next;
+ }
+
+ select.addEventListener('change', () => setAgent(select.value));
+ more.addEventListener('click', () => load({ append: true }));
+ syncDownload();
+ load();
+
+ return { setAgent, addAgents, notifyNew };
+}
diff --git a/src/crawl/format.js b/src/crawl/format.js
new file mode 100644
index 000000000..e0a34f2cd
--- /dev/null
+++ b/src/crawl/format.js
@@ -0,0 +1,72 @@
+// Small display helpers shared by the /crawl modules.
+
+const compact = new Intl.NumberFormat('en', { notation: 'compact', maximumFractionDigits: 1 });
+const whole = new Intl.NumberFormat('en');
+
+export function fmtCount(n) {
+ const v = Number(n) || 0;
+ return v >= 10_000 ? compact.format(v) : whole.format(v);
+}
+
+export function timeAgo(when) {
+ const t = typeof when === 'number' ? when : Date.parse(when);
+ if (!Number.isFinite(t)) return '';
+ const s = Math.max(0, Math.round((Date.now() - t) / 1000));
+ if (s < 45) return 'just now';
+ const m = Math.round(s / 60);
+ if (m < 60) return `${m}m ago`;
+ const h = Math.round(m / 60);
+ if (h < 24) return `${h}h ago`;
+ const d = Math.round(h / 24);
+ if (d < 30) return `${d}d ago`;
+ return new Date(t).toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' });
+}
+
+export function hostOf(url) {
+ try { return new URL(url).hostname.replace(/^www\./, ''); } catch { return ''; }
+}
+
+// "en.wikipedia.org" + "/wiki/WebGL" split, for a browser-style URL bar.
+export function splitUrl(url) {
+ try {
+ const u = new URL(url);
+ const rest = `${u.pathname === '/' ? '' : u.pathname}${u.search}`;
+ return { host: u.hostname.replace(/^www\./, ''), rest };
+ } catch {
+ return { host: String(url || ''), rest: '' };
+ }
+}
+
+// Build an element tree without innerHTML, so page titles and gists from the
+// open web can never inject markup.
+export function h(tag, attrs = {}, ...children) {
+ const el = document.createElement(tag);
+ for (const [k, v] of Object.entries(attrs)) {
+ if (v == null || v === false) continue;
+ if (k === 'class') el.className = v;
+ else if (k === 'text') el.textContent = v;
+ else if (k.startsWith('on') && typeof v === 'function') el.addEventListener(k.slice(2), v);
+ else if (k === 'dataset') Object.assign(el.dataset, v);
+ else el.setAttribute(k, v === true ? '' : String(v));
+ }
+ for (const c of children.flat()) {
+ if (c == null || c === false) continue;
+ el.append(c instanceof Node ? c : document.createTextNode(String(c)));
+ }
+ return el;
+}
+
+// Read an API error body into one readable sentence.
+export async function apiError(res) {
+ try {
+ const body = await res.json();
+ return body.error_description || body.message || body.error || `Request failed (${res.status})`;
+ } catch {
+ return `Request failed (${res.status})`;
+ }
+}
+
+// Only http(s) links from the corpus become hrefs.
+export function safeHref(url) {
+ return /^https?:\/\//i.test(String(url || '')) ? url : null;
+}
diff --git a/src/crawl/page.js b/src/crawl/page.js
new file mode 100644
index 000000000..5325b5872
--- /dev/null
+++ b/src/crawl/page.js
@@ -0,0 +1,573 @@
+// /crawl: agents reading the open web, live.
+//
+// Data flow:
+// /api/crawl/live (SSE) snapshot + step/sleep/page events -> crawler state
+// /api/crawl/crawlers names, topics, avatars, who is resting
+// /api/crawl/stats totals for the hero (refreshed, bumped on page events)
+// /api/crawl/frame the JPEG each step points at (?t=frameTs, cacheable)
+// Each crawler's step drives its avatar through stage.js: walking -> walk to the
+// target link, leaping -> hop out, reading -> land and face the page.
+
+import { createStage } from './stage.js';
+import { mountCorpus } from './corpus.js';
+import { mountSend } from './send.js';
+import { fmtCount, h, hostOf, safeHref, splitUrl, timeAgo } from './format.js';
+
+const STATS_REFRESH_MS = 30_000;
+const CRAWLERS_REFRESH_MS = 45_000;
+const FEED_CAP = 30;
+const LAND_AT = { x: 0.1, y: 0.92 };
+
+const STATUS_LABEL = {
+ reading: 'Reading',
+ walking: 'Walking',
+ leaping: 'Leaping',
+ blocked: 'Blocked',
+ resting: 'Resting',
+ asleep: 'Asleep',
+};
+
+const $ = (id) => document.getElementById(id);
+const el = {
+ conn: $('cr-conn'),
+ stats: $('cr-stats'),
+ url: $('cr-url'),
+ status: $('cr-status'),
+ screen: $('cr-screen'),
+ frames: [...document.querySelectorAll('#cr-screen .cr-frame')],
+ links: $('cr-links'),
+ opening: $('cr-opening'),
+ bubble: $('cr-bubble'),
+ empty: $('cr-screen-empty'),
+ thumb: $('cr-agent-thumb'),
+ name: $('cr-agent-name'),
+ topic: $('cr-agent-topic'),
+ thought: $('cr-thought'),
+ pages: $('cr-agent-pages'),
+ profile: $('cr-agent-profile'),
+ reads: $('cr-agent-reads'),
+ feed: $('cr-feed-list'),
+ feedCount: $('cr-feed-count'),
+ wall: $('cr-wall'),
+ restingWrap: $('cr-resting-wrap'),
+ resting: $('cr-resting'),
+};
+
+// ── state ───────────────────────────────────────────────────────────────────
+const info = new Map(); // agentId -> crawler row from /api/crawl/crawlers
+const live = new Map(); // agentId -> latest step from the live stream
+const tiles = new Map(); // agentId -> { root, button, img, status, domain, detach, frameTs }
+let featured = null;
+let featuredDetach = null;
+let featuredAvatar;
+let shownFrameTs = null;
+let frameFlip = 0;
+let feedItems = [];
+let stats = null;
+let liveState = 'connecting'; // connecting | live | offline | reconnecting
+let corpus = null;
+
+// ── the avatar stage ────────────────────────────────────────────────────────
+function headerBottom() {
+ const header = document.getElementById('nav-container');
+ return header ? Math.max(0, header.getBoundingClientRect().bottom) : 0;
+}
+
+const stage = createStage({ canvas: $('cr-bodies'), clipTop: headerBottom });
+if (!stage) document.body.classList.add('cr-no-bodies');
+
+// Place a crawler beside the link it is walking to: left of it facing right,
+// or right of it facing left when the link hugs the left edge.
+function standBeside(rect) {
+ const feet = Math.min(0.97, rect.y + rect.h);
+ if (rect.x > 0.14) return { to: { x: Math.max(0.05, rect.x - 0.035), y: feet }, face: 'link-right' };
+ return { to: { x: Math.min(0.95, rect.x + rect.w + 0.035), y: feet }, face: 'link-left' };
+}
+
+function driveAvatar(id, step) {
+ if (!stage) return;
+ if (step.status === 'walking' && step.target != null && step.links[step.target]) {
+ if (stage.isGone(id)) stage.land(id, 'viewer', LAND_AT);
+ const { to, face } = standBeside(step.links[step.target]);
+ stage.walk(id, to, face);
+ } else if (step.status === 'leaping') {
+ stage.hop(id);
+ } else if (step.status === 'reading') {
+ stage.land(id, 'page', LAND_AT);
+ } else {
+ stage.land(id, 'viewer', LAND_AT);
+ }
+}
+
+// ── live stream ─────────────────────────────────────────────────────────────
+function applyStep(step, { animate = true } = {}) {
+ const prev = live.get(step.agentId);
+ if (prev && prev.ts === step.ts) return;
+ // Walking/leaping steps carry no title; keep the page's title from reading.
+ const merged = { ...step, title: step.title || (prev && prev.url === step.url ? prev.title : '') };
+ live.set(step.agentId, merged);
+ if (!info.has(step.agentId)) scheduleCrawlers();
+ if (animate) driveAvatar(step.agentId, merged);
+ ensureTile(step.agentId);
+ updateTile(step.agentId);
+ if (!featured || !live.has(featured)) feature(pickDefault(), { replaceHash: true });
+ else if (featured === step.agentId) renderFeatured();
+ renderConn();
+}
+
+function sleep(agentId) {
+ live.delete(agentId);
+ removeTile(agentId);
+ if (featured === agentId) feature(pickDefault(), { replaceHash: true });
+ renderConn();
+ renderResting();
+}
+
+function connect() {
+ const es = new EventSource('/api/crawl/live');
+ es.addEventListener('snapshot', (e) => {
+ const snap = JSON.parse(e.data);
+ liveState = snap.live ? 'live' : 'offline';
+ const ids = new Set(snap.crawlers.map((c) => c.agentId));
+ for (const id of [...live.keys()]) if (!ids.has(id)) sleep(id);
+ for (const c of snap.crawlers) applyStep(c, { animate: live.has(c.agentId) });
+ for (const c of snap.crawlers) if (stage && c.status === 'reading') stage.face(c.agentId, 'page');
+ feedItems = snap.feed.slice(0, FEED_CAP);
+ renderFeed();
+ if (!featured || !live.has(featured)) feature(pickDefault(), { replaceHash: true });
+ renderConn();
+ });
+ es.addEventListener('step', (e) => applyStep(JSON.parse(e.data)));
+ es.addEventListener('sleep', (e) => sleep(JSON.parse(e.data).agentId));
+ es.addEventListener('page', (e) => {
+ const p = JSON.parse(e.data);
+ feedItems = [p, ...feedItems.filter((x) => !(x.url === p.url && x.agentId === p.agentId))].slice(0, FEED_CAP);
+ renderFeed(p);
+ bumpStats(p);
+ corpus?.notifyNew(p.agentId);
+ const row = info.get(p.agentId);
+ if (row) row.pagesRead += 1;
+ if (featured === p.agentId) renderFeatured();
+ });
+ es.addEventListener('open', () => {
+ if (liveState === 'reconnecting') liveState = 'connecting';
+ renderConn();
+ });
+ es.addEventListener('error', () => {
+ // EventSource reconnects on its own; the server also closes every few
+ // minutes on purpose, so this is usually a brief blip.
+ if (es.readyState === EventSource.CLOSED) setTimeout(connect, 5000);
+ liveState = 'reconnecting';
+ renderConn();
+ });
+}
+
+function renderConn() {
+ const n = live.size;
+ let text;
+ if (liveState === 'reconnecting') text = 'Reconnecting to the live crawl';
+ else if (liveState === 'connecting') text = 'Connecting to the live crawl';
+ else if (liveState === 'offline') text = 'Live view offline. The corpus is still open';
+ else text = n ? `Live: ${n} agent${n === 1 ? '' : 's'} reading now` : 'Live: no agent is out right now';
+ el.conn.textContent = text;
+ el.conn.parentElement.dataset.state = liveState === 'live' && n ? 'live' : liveState;
+ if (stats) setStat('awake', liveState === 'live' ? n : stats.crawlersAwake);
+ if (!live.size && liveState !== 'connecting') renderEmptyScreen();
+}
+
+// ── crawler roster ──────────────────────────────────────────────────────────
+let crawlersTimer = 0;
+function scheduleCrawlers() {
+ if (crawlersTimer) return;
+ crawlersTimer = setTimeout(() => { crawlersTimer = 0; loadCrawlers(); }, 600);
+}
+
+async function loadCrawlers() {
+ try {
+ const res = await fetch('/api/crawl/crawlers', { headers: { accept: 'application/json' } });
+ if (!res.ok) return;
+ const { crawlers } = await res.json();
+ for (const c of crawlers) {
+ info.set(c.agentId, c);
+ stage?.setAvatar(c.agentId, c.avatarUrl);
+ }
+ corpus?.addAgents(crawlers);
+ for (const id of live.keys()) { ensureTile(id); updateTile(id); }
+ if (featured) {
+ attachFeatured();
+ renderFeatured();
+ }
+ renderResting();
+ } catch {
+ // The roster only decorates the live stream (names, avatars); the
+ // next refresh retries.
+ }
+}
+
+function pickDefault() {
+ const wanted = new URLSearchParams(location.hash.slice(1)).get('agent');
+ if (wanted && live.has(wanted)) return wanted;
+ if (featured && live.has(featured)) return featured;
+ const awake = [...live.keys()];
+ awake.sort((a, b) => (info.get(b)?.pagesRead || 0) - (info.get(a)?.pagesRead || 0));
+ return awake[0] || null;
+}
+
+// ── featured screen ─────────────────────────────────────────────────────────
+function attachFeatured() {
+ if (!stage || !featured) return;
+ const url = info.get(featured)?.avatarUrl;
+ if (featuredDetach && featuredAvatar === url) return;
+ featuredDetach?.();
+ featuredAvatar = url;
+ featuredDetach = stage.attach(el.screen, featured, { onPlace: placeBubble });
+}
+
+function placeBubble(px, pyTop, motion) {
+ const hidden = motion.mode === 'gone' || motion.mode === 'hop' || !el.bubble.textContent;
+ el.bubble.classList.toggle('is-on', !hidden);
+ const w = el.screen.clientWidth;
+ const side = px > w * 0.62 ? 'left' : 'right';
+ el.bubble.dataset.side = side;
+ el.bubble.style.transform = `translate(${Math.round(px)}px, ${Math.round(pyTop)}px)`;
+}
+
+function feature(id, { replaceHash = false, focus = false } = {}) {
+ if (id === featured && featuredDetach) { renderFeatured(); return; }
+ featuredDetach?.();
+ featuredDetach = null;
+ featured = id;
+ shownFrameTs = null;
+ for (const img of el.frames) { img.classList.remove('is-on'); img.removeAttribute('src'); }
+ for (const [tid, t] of tiles) t.button.setAttribute('aria-pressed', tid === id ? 'true' : 'false');
+ if (id) {
+ const q = new URLSearchParams(location.hash.slice(1));
+ if (q.get('agent') !== id) {
+ q.set('agent', id);
+ const url = `${location.pathname}${location.search}#${q}`;
+ if (replaceHash) history.replaceState(null, '', url);
+ else history.pushState(null, '', url);
+ }
+ attachFeatured();
+ }
+ renderFeatured();
+ if (focus) el.screen.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
+}
+
+function renderEmptyScreen() {
+ el.screen.dataset.state = liveState === 'offline' ? 'offline' : 'empty';
+ el.empty.hidden = false;
+ el.empty.replaceChildren(
+ h('p', { class: 'cr-empty-title', text: liveState === 'offline' ? 'The live view is offline' : 'No agent is out reading right now' }),
+ h('p', { class: 'cr-muted', text: liveState === 'offline'
+ ? 'Agents keep reading, but their screens cannot be streamed at the moment. Everything they read is still in the corpus below.'
+ : 'Send yours out with a topic and you will watch it read here within a minute.' }),
+ h('div', { class: 'cr-empty-actions' },
+ h('a', { class: 'cr-btn cr-btn-primary', href: '#send', text: 'Send your agent out' }),
+ h('a', { class: 'cr-btn', href: '#corpus', text: 'Browse the corpus' })),
+ );
+ el.url.textContent = 'Waiting for an agent';
+ el.status.dataset.status = 'asleep';
+ el.status.textContent = liveState === 'offline' ? 'Offline' : STATUS_LABEL.asleep;
+ el.links.replaceChildren();
+ el.opening.classList.remove('is-on');
+ el.bubble.textContent = '';
+ el.bubble.classList.remove('is-on');
+ el.thought.textContent = '';
+ el.name.textContent = ' ';
+ el.topic.textContent = ' ';
+ el.pages.textContent = '';
+ el.thumb.hidden = true;
+ el.profile.hidden = true;
+ el.reads.hidden = true;
+}
+
+function showFrame(id, frameTs) {
+ if (!frameTs || frameTs === shownFrameTs) return;
+ shownFrameTs = frameTs;
+ const next = el.frames[frameFlip ^ 1];
+ const cur = el.frames[frameFlip];
+ next.onload = () => {
+ if (featured !== id || shownFrameTs !== frameTs) return;
+ next.classList.add('is-on');
+ cur.classList.remove('is-on');
+ frameFlip ^= 1;
+ el.screen.dataset.state = 'live';
+ };
+ next.onerror = () => {
+ if (shownFrameTs !== frameTs) return;
+ shownFrameTs = null;
+ // No picture for this step (it expired between push and fetch): keep the
+ // last frame if there is one, otherwise say so instead of shimmering.
+ if (featured === id && !el.frames.some((img) => img.classList.contains('is-on'))) el.screen.dataset.state = 'noframe';
+ };
+ next.src = `/api/crawl/frame?agent=${encodeURIComponent(id)}&t=${frameTs}`;
+}
+
+function renderLinks(step) {
+ const nodes = step.links.map((l, i) => h('span', {
+ class: i === step.target ? 'cr-linkbox is-target' : 'cr-linkbox',
+ style: `left:${l.x * 100}%;top:${l.y * 100}%;width:${l.w * 100}%;height:${l.h * 100}%`,
+ title: l.t || null,
+ }));
+ el.links.replaceChildren(...nodes);
+}
+
+function renderFeatured() {
+ if (!featured || !live.has(featured)) {
+ if (liveState !== 'connecting') renderEmptyScreen();
+ return;
+ }
+ const step = live.get(featured);
+ const row = info.get(featured);
+ el.empty.hidden = true;
+ if (el.screen.dataset.state !== 'live') el.screen.dataset.state = shownFrameTs ? 'live' : 'loading';
+ showFrame(featured, step.frameTs);
+
+ const { host, rest } = splitUrl(step.url);
+ el.url.replaceChildren(h('strong', { text: host }), h('span', { text: rest }));
+ el.url.title = step.url || '';
+ el.status.dataset.status = step.status;
+ el.status.textContent = STATUS_LABEL[step.status] || 'Reading';
+ el.screen.setAttribute('role', 'img');
+ el.screen.setAttribute('aria-label', `${step.name || 'An agent'} is ${(STATUS_LABEL[step.status] || 'reading').toLowerCase()} ${step.title || host || 'a page'}`);
+
+ renderLinks(step);
+ const leaping = step.status === 'leaping';
+ const leapHost = hostOf(step.nextUrl);
+ // A walked-to link names its host; a leap to a queued lead has none on this
+ // screen, so the overlay says where the agent is going instead.
+ el.opening.classList.toggle('is-on', leaping);
+ el.opening.querySelector('span').textContent = leapHost ? 'Opening' : 'Leaping to the next lead';
+ el.opening.querySelector('strong').textContent = leapHost || '';
+
+ el.bubble.textContent = step.thought || '';
+ if (!stage) el.bubble.classList.toggle('is-on', Boolean(step.thought));
+ el.thought.textContent = step.thought || '';
+
+ el.name.textContent = row?.name || step.name || 'Agent';
+ el.topic.textContent = `Reading about ${row?.topic || step.topic || 'the web'}`;
+ el.pages.textContent = `${fmtCount(row?.pagesRead ?? step.pagesRead ?? 0)} pages read`;
+ if (row?.thumbnail) {
+ el.thumb.src = row.thumbnail;
+ el.thumb.hidden = false;
+ } else {
+ el.thumb.hidden = true;
+ }
+ el.profile.href = `/agents/${encodeURIComponent(featured)}`;
+ el.profile.hidden = false;
+ el.reads.hidden = false;
+}
+
+el.reads.addEventListener('click', () => { if (featured) corpus?.setAgent(featured); });
+
+// ── the wall ────────────────────────────────────────────────────────────────
+const tileObserver = typeof IntersectionObserver === 'function'
+ ? new IntersectionObserver((entries) => {
+ for (const e of entries) {
+ const id = e.target.dataset.agent;
+ const t = tiles.get(id);
+ if (!t) continue;
+ t.visible = e.isIntersecting;
+ if (t.visible) updateTile(id);
+ }
+ }, { rootMargin: '200px' })
+ : null;
+
+function ensureTile(id) {
+ if (tiles.has(id)) {
+ const t = tiles.get(id);
+ const url = info.get(id)?.avatarUrl;
+ if (stage && t.avatar !== url && info.has(id)) {
+ t.detach?.();
+ t.avatar = url;
+ t.detach = stage.attach(t.screen, id);
+ }
+ return;
+ }
+ const img = h('img', { class: 'cr-tile-frame', alt: '', decoding: 'async', loading: 'lazy' });
+ const screen = h('span', { class: 'cr-tile-screen' }, img);
+ const name = h('span', { class: 'cr-tile-name' });
+ const status = h('span', { class: 'cr-tile-status' });
+ const domain = h('span', { class: 'cr-tile-domain' });
+ const button = h('button', {
+ type: 'button', class: 'cr-tile', 'aria-pressed': id === featured ? 'true' : 'false',
+ onclick: () => feature(id, { focus: true }),
+ }, screen, h('span', { class: 'cr-tile-meta' }, name, h('span', { class: 'cr-tile-line' }, status, domain)));
+ const root = h('div', { role: 'listitem', class: 'cr-tile-wrap', dataset: { agent: id } }, button);
+ el.wall.querySelector('.cr-wall-empty')?.remove();
+ el.wall.append(root);
+ const t = { root, button, screen, img, name, status, domain, detach: null, avatar: undefined, frameTs: null, visible: !tileObserver };
+ tiles.set(id, t);
+ tileObserver?.observe(root);
+ if (stage && info.has(id)) {
+ t.avatar = info.get(id).avatarUrl;
+ t.detach = stage.attach(screen, id);
+ }
+}
+
+function updateTile(id) {
+ const t = tiles.get(id);
+ const step = live.get(id);
+ if (!t || !step) return;
+ const row = info.get(id);
+ t.name.textContent = row?.name || step.name || 'Agent';
+ t.status.dataset.status = step.status;
+ t.status.textContent = STATUS_LABEL[step.status] || 'Reading';
+ t.domain.textContent = step.domain || hostOf(step.url);
+ t.button.setAttribute('aria-label', `Follow ${t.name.textContent}, ${t.status.textContent.toLowerCase()} ${t.domain.textContent}`);
+ if (t.visible && step.frameTs && step.frameTs !== t.frameTs) {
+ t.frameTs = step.frameTs;
+ const src = `/api/crawl/frame?agent=${encodeURIComponent(id)}&t=${step.frameTs}`;
+ const pre = new Image();
+ pre.onload = () => { if (t.frameTs === step.frameTs) { t.img.src = src; t.screen.classList.add('has-frame'); } };
+ pre.src = src;
+ }
+}
+
+function removeTile(id) {
+ const t = tiles.get(id);
+ if (!t) return;
+ t.detach?.();
+ tileObserver?.unobserve(t.root);
+ t.root.remove();
+ tiles.delete(id);
+ stage?.forget(id);
+}
+
+function renderResting() {
+ const resting = [...info.values()].filter((c) => !live.has(c.agentId));
+ el.restingWrap.hidden = !resting.length;
+ el.resting.replaceChildren(...resting.map((c) => h('li', {},
+ h('a', { class: 'cr-resting-item', href: `/agents/${encodeURIComponent(c.agentId)}` },
+ c.thumbnail
+ ? h('img', { src: c.thumbnail, alt: '', width: 32, height: 32, loading: 'lazy' })
+ : h('span', { class: 'cr-pick-initial', 'aria-hidden': 'true', text: (c.name || '?').slice(0, 1).toUpperCase() }),
+ h('span', {},
+ h('span', { class: 'cr-resting-name', text: c.name || 'Agent' }),
+ h('span', { class: 'cr-muted', text: `${c.topic}${c.lastAt ? `, last read ${timeAgo(c.lastAt)}` : ''}` }))),
+ )));
+ if (!live.size && !resting.length) {
+ el.wall.replaceChildren(h('p', { class: 'cr-wall-empty cr-muted', text: 'Screens appear here while agents are out reading.' }));
+ } else {
+ el.wall.querySelector('.cr-wall-empty')?.remove();
+ }
+}
+
+// ── feed ────────────────────────────────────────────────────────────────────
+function renderFeed(fresh) {
+ if (!feedItems.length) {
+ el.feed.replaceChildren(h('li', { class: 'cr-feed-empty' },
+ h('p', { text: 'No pages yet.' }),
+ h('p', { class: 'cr-muted', text: 'Each page an agent finishes reading shows up here the moment it lands.' })));
+ el.feedCount.textContent = '';
+ return;
+ }
+ el.feed.replaceChildren(...feedItems.map((p) => {
+ const href = safeHref(p.url);
+ return h('li', { class: p === fresh ? 'cr-feed-item is-new' : 'cr-feed-item' },
+ href
+ ? h('a', { class: 'cr-feed-title', href, target: '_blank', rel: 'noopener nofollow ugc', text: p.title || p.url })
+ : h('span', { class: 'cr-feed-title', text: p.title || p.url }),
+ h('span', { class: 'cr-feed-meta' },
+ h('button', { type: 'button', class: 'cr-feed-agent', text: p.name || 'Agent', title: `Follow ${p.name || 'this agent'}`, onclick: () => live.has(p.agentId) ? feature(p.agentId, { focus: true }) : corpus?.setAgent(p.agentId) }),
+ h('span', { text: ` on ${p.domain || hostOf(p.url)}` }),
+ h('span', { class: 'cr-feed-dot', 'aria-hidden': 'true', text: ' · ' }),
+ h('time', { datetime: new Date(p.ts).toISOString(), dataset: { ts: p.ts }, text: timeAgo(p.ts) }),
+ p.tokens ? h('span', { class: 'cr-feed-tokens', text: ` · ${fmtCount(p.tokens)} tokens` }) : null));
+ }));
+ el.feedCount.textContent = `last ${feedItems.length}`;
+}
+
+// Keep "2m ago" honest without re-rendering the list.
+setInterval(() => {
+ for (const t of el.feed.querySelectorAll('time[data-ts]')) t.textContent = timeAgo(Number(t.dataset.ts));
+}, 30_000);
+
+// ── stats ───────────────────────────────────────────────────────────────────
+function setStat(key, value) {
+ const dd = el.stats.querySelector(`[data-stat="${key}"]`);
+ if (!dd) return;
+ const text = fmtCount(value);
+ if (dd.textContent !== text) {
+ dd.textContent = text;
+ dd.classList.remove('is-bump');
+ void dd.offsetWidth;
+ dd.classList.add('is-bump');
+ }
+}
+
+function renderStats() {
+ setStat('awake', liveState === 'live' ? live.size : stats.crawlersAwake);
+ setStat('pagesRead', stats.pagesRead);
+ setStat('tokens', stats.tokens);
+ setStat('domains', stats.domains);
+ setStat('pages24h', stats.pages24h);
+}
+
+async function loadStats() {
+ try {
+ const res = await fetch('/api/crawl/stats', { headers: { accept: 'application/json' } });
+ if (!res.ok) throw new Error(String(res.status));
+ stats = await res.json();
+ renderStats();
+ } catch {
+ if (!stats) {
+ for (const dd of el.stats.querySelectorAll('dd')) {
+ dd.textContent = '-';
+ dd.title = 'Totals are unavailable right now';
+ }
+ }
+ }
+}
+
+function bumpStats(p) {
+ if (!stats) return;
+ stats.pagesRead += 1;
+ stats.pages24h += 1;
+ stats.tokens += Number(p.tokens) || 0;
+ renderStats();
+}
+
+// ── keyboard ────────────────────────────────────────────────────────────────
+function typing(target) {
+ return target instanceof HTMLElement && (target.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(target.tagName));
+}
+
+document.addEventListener('keydown', (e) => {
+ if (e.defaultPrevented || e.metaKey || e.ctrlKey || e.altKey || typing(e.target)) return;
+ if (e.key === 'l' || e.key === 'L') {
+ el.screen.classList.toggle('show-links');
+ return;
+ }
+ if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return;
+ if (e.target instanceof HTMLElement && e.target.closest('[role="radiogroup"]')) return;
+ const ids = [...tiles.keys()];
+ if (ids.length < 2) return;
+ const i = Math.max(0, ids.indexOf(featured));
+ const next = ids[(i + (e.key === 'ArrowRight' ? 1 : -1) + ids.length) % ids.length];
+ e.preventDefault();
+ feature(next);
+ tiles.get(next)?.button.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'nearest' });
+});
+
+window.addEventListener('popstate', () => {
+ const id = new URLSearchParams(location.hash.slice(1)).get('agent');
+ if (id && live.has(id) && id !== featured) feature(id, { replaceHash: true });
+});
+
+// ── boot ────────────────────────────────────────────────────────────────────
+corpus = mountCorpus({
+ body: $('cr-corpus-body'),
+ select: $('cr-corpus-agent'),
+ more: $('cr-corpus-more'),
+ note: $('cr-corpus-note'),
+ download: $('cr-corpus-download'),
+});
+
+mountSend($('cr-send-body'), { onChange: () => loadCrawlers() });
+
+loadStats();
+setInterval(() => { if (!document.hidden) loadStats(); }, STATS_REFRESH_MS);
+loadCrawlers().then(connect);
+setInterval(() => { if (!document.hidden) loadCrawlers(); }, CRAWLERS_REFRESH_MS);
diff --git a/src/crawl/send.js b/src/crawl/send.js
new file mode 100644
index 000000000..c4808f996
--- /dev/null
+++ b/src/crawl/send.js
@@ -0,0 +1,227 @@
+// "Send your agent out" on /crawl: the owner picks one of their agents, gives it
+// a topic and optional start pages, and enrolls it (PUT /api/crawl/mission) or
+// calls it home (DELETE). Every write fetches a fresh CSRF token, since tokens
+// are single use.
+
+import { apiError, fmtCount, h, timeAgo } from './format.js';
+
+const TOPIC_MIN = 2;
+const TOPIC_MAX = 120;
+const MAX_SEEDS = 8;
+
+async function csrfToken() {
+ const res = await fetch('/api/csrf-token', { credentials: 'include' });
+ if (!res.ok) throw new Error(await apiError(res));
+ const j = await res.json();
+ const token = j.data?.token || j.token;
+ if (!token) throw new Error('Could not start a secure request. Reload the page and try again.');
+ return token;
+}
+
+function parseSeeds(text) {
+ return String(text || '').split(/[\s,]+/).map((s) => s.trim()).filter(Boolean);
+}
+
+export function mountSend(root, { onChange } = {}) {
+ let agents = [];
+ let selected = null;
+
+ function setBusy(on) { root.setAttribute('aria-busy', on ? 'true' : 'false'); }
+
+ function cta(title, text, href, label) {
+ root.replaceChildren(h('div', { class: 'cr-send-cta' },
+ h('h3', { text: title }),
+ h('p', { class: 'cr-muted', text }),
+ h('a', { class: 'cr-btn cr-btn-primary', href, text: label }),
+ ));
+ }
+
+ function failed(message) {
+ root.replaceChildren(h('div', { class: 'cr-send-cta', role: 'alert' },
+ h('h3', { text: 'Your agents could not be loaded' }),
+ h('p', { class: 'cr-muted', text: message }),
+ h('button', { type: 'button', class: 'cr-btn', text: 'Try again', onclick: load }),
+ ));
+ }
+
+ function agentCard(a) {
+ const on = a.mission?.enabled;
+ const btn = h('button', {
+ type: 'button',
+ class: 'cr-pick',
+ role: 'radio',
+ 'aria-checked': a.agentId === selected?.agentId ? 'true' : 'false',
+ dataset: { agent: a.agentId },
+ onclick: () => select(a.agentId),
+ },
+ a.thumbnail
+ ? h('img', { src: a.thumbnail, alt: '', width: 36, height: 36, loading: 'lazy' })
+ : h('span', { class: 'cr-pick-initial', 'aria-hidden': 'true', text: (a.name || '?').slice(0, 1).toUpperCase() }),
+ h('span', { class: 'cr-pick-text' },
+ h('span', { class: 'cr-pick-name', text: a.name || 'Untitled agent' }),
+ h('span', { class: 'cr-pick-state', dataset: { on: on ? 'true' : 'false' }, text: on ? `Out reading: ${a.mission.topic}` : a.mission ? 'Home' : 'Never sent out' }),
+ ));
+ return btn;
+ }
+
+ function render() {
+ const a = selected;
+ const m = a.mission;
+ const on = Boolean(m?.enabled);
+ const error = h('p', { class: 'cr-form-error', role: 'alert', hidden: true });
+ const ok = h('p', { class: 'cr-form-ok', role: 'status' });
+ const topic = h('input', {
+ id: 'cr-topic', name: 'topic', type: 'text', required: true,
+ minlength: TOPIC_MIN, maxlength: TOPIC_MAX, autocomplete: 'off',
+ placeholder: 'e.g. Gaussian splatting for real-time avatars',
+ value: m?.topic || '',
+ });
+ const seeds = h('textarea', {
+ id: 'cr-seeds', name: 'seeds', rows: 3, spellcheck: 'false',
+ placeholder: 'https://en.wikipedia.org/wiki/Gaussian_splatting',
+ });
+ seeds.value = (m?.seeds || []).join('\n');
+ const counter = h('span', { class: 'cr-counter', 'aria-live': 'polite' });
+ const syncCount = () => { counter.textContent = `${topic.value.trim().length}/${TOPIC_MAX}`; };
+ topic.addEventListener('input', syncCount);
+ syncCount();
+
+ const submit = h('button', { type: 'submit', class: 'cr-btn cr-btn-primary', text: on ? 'Update mission' : 'Send it out' });
+ const home = on ? h('button', { type: 'button', class: 'cr-btn cr-btn-ghost', text: 'Call it home' }) : null;
+
+ function showError(msg) {
+ error.textContent = msg;
+ error.hidden = !msg;
+ ok.textContent = '';
+ }
+
+ async function write(methodName, url, body) {
+ const token = await csrfToken();
+ const res = await fetch(url, {
+ method: methodName,
+ credentials: 'include',
+ headers: { 'content-type': 'application/json', 'x-csrf-token': token },
+ body: body ? JSON.stringify(body) : undefined,
+ });
+ if (!res.ok) throw new Error(await apiError(res));
+ return res.json();
+ }
+
+ const form = h('form', { class: 'cr-form', novalidate: true },
+ h('div', { class: 'cr-field' },
+ h('label', { for: 'cr-topic' }, 'Topic ', counter),
+ topic,
+ h('p', { class: 'cr-hint', text: 'What it should read about. Links on each page are scored against this.' }),
+ ),
+ h('div', { class: 'cr-field' },
+ h('label', { for: 'cr-seeds', text: 'Start pages (optional)' }),
+ seeds,
+ h('p', { class: 'cr-hint', text: `Up to ${MAX_SEEDS} public web addresses, one per line. Leave empty and it starts from a search for the topic.` }),
+ ),
+ error,
+ h('div', { class: 'cr-form-actions' }, submit, home, ok),
+ );
+
+ form.addEventListener('submit', async (e) => {
+ e.preventDefault();
+ const t = topic.value.trim();
+ const s = parseSeeds(seeds.value);
+ if (t.length < TOPIC_MIN) { showError(`Give it a topic of at least ${TOPIC_MIN} characters.`); topic.focus(); return; }
+ if (s.length > MAX_SEEDS) { showError(`At most ${MAX_SEEDS} start pages.`); seeds.focus(); return; }
+ showError('');
+ submit.disabled = true;
+ submit.textContent = on ? 'Updating' : 'Sending';
+ try {
+ const { mission } = await write('PUT', '/api/crawl/mission', { agentId: a.agentId, topic: t, seeds: s });
+ a.mission = mission;
+ render();
+ root.querySelector('.cr-form-ok').textContent = on
+ ? 'Mission updated. It follows the new topic from its next page.'
+ : 'Sent. It joins the crawl as soon as a browser is free, usually within a minute.';
+ onChange?.(a);
+ } catch (err) {
+ showError(err.message);
+ submit.disabled = false;
+ submit.textContent = on ? 'Update mission' : 'Send it out';
+ }
+ });
+
+ home?.addEventListener('click', async () => {
+ home.disabled = true;
+ showError('');
+ try {
+ await write('DELETE', `/api/crawl/mission?agent=${encodeURIComponent(a.agentId)}`);
+ a.mission = { ...a.mission, enabled: false };
+ render();
+ root.querySelector('.cr-form-ok').textContent = 'Called home. Everything it read stays in the corpus and its memory.';
+ onChange?.(a);
+ } catch (err) {
+ showError(err.message);
+ home.disabled = false;
+ }
+ });
+
+ const stats = m
+ ? h('p', { class: 'cr-muted cr-send-stats' },
+ `${fmtCount(m.pagesRead)} pages, ${fmtCount(m.tokensRead)} tokens read`,
+ m.lastAt ? `, last page ${timeAgo(m.lastAt)}` : '',
+ '. ',
+ h('a', { class: 'cr-link', href: `/agents/${encodeURIComponent(a.agentId)}`, text: 'Open its profile' }))
+ : null;
+
+ const picker = h('div', { class: 'cr-picks', role: 'radiogroup', 'aria-label': 'Your agents' }, agents.map(agentCard));
+ picker.addEventListener('keydown', (e) => {
+ if (!['ArrowDown', 'ArrowUp', 'ArrowRight', 'ArrowLeft'].includes(e.key)) return;
+ e.preventDefault();
+ const i = agents.findIndex((x) => x.agentId === selected.agentId);
+ const d = e.key === 'ArrowDown' || e.key === 'ArrowRight' ? 1 : -1;
+ select(agents[(i + d + agents.length) % agents.length].agentId, true);
+ });
+ for (const b of picker.querySelectorAll('.cr-pick')) b.tabIndex = b.dataset.agent === a.agentId ? 0 : -1;
+
+ root.replaceChildren(h('div', { class: 'cr-send-grid' },
+ h('div', {}, h('p', { class: 'cr-label', text: 'Your agents' }), picker),
+ h('div', {}, h('h3', { class: 'cr-send-name', text: a.name || 'Untitled agent' }), stats, form),
+ ));
+ }
+
+ function select(id, focus = false) {
+ selected = agents.find((a) => a.agentId === id) || agents[0];
+ render();
+ if (focus) root.querySelector(`.cr-pick[data-agent="${CSS.escape(selected.agentId)}"]`)?.focus();
+ }
+
+ async function load() {
+ setBusy(true);
+ root.replaceChildren(h('div', { class: 'cr-skel cr-send-skel' }));
+ try {
+ const me = await fetch('/api/auth/me', { credentials: 'include' });
+ if (me.status === 401) {
+ cta('Sign in to send your agent out', 'Your agent reads in a real browser while you watch, and remembers what it learned.', '/login?next=%2Fcrawl%23send', 'Sign in');
+ return;
+ }
+ if (!me.ok) throw new Error(await apiError(me));
+ const body = await me.json();
+ if (!body?.user) {
+ cta('Sign in to send your agent out', 'Your agent reads in a real browser while you watch, and remembers what it learned.', '/login?next=%2Fcrawl%23send', 'Sign in');
+ return;
+ }
+ const res = await fetch('/api/crawl/mine', { credentials: 'include' });
+ if (!res.ok) throw new Error(await apiError(res));
+ agents = (await res.json()).agents || [];
+ if (!agents.length) {
+ cta('Make an agent first', 'Agents are what crawl. Create one with a 3D body, then come back and give it a topic.', '/create', 'Create an agent');
+ return;
+ }
+ const wanted = new URLSearchParams(location.hash.slice(1)).get('send');
+ select(agents.some((a) => a.agentId === wanted) ? wanted : agents[0].agentId);
+ } catch (err) {
+ failed(err.message);
+ } finally {
+ setBusy(false);
+ }
+ }
+
+ load();
+ return { reload: load };
+}
diff --git a/src/crawl/stage.js b/src/crawl/stage.js
new file mode 100644
index 000000000..3ea29dbaf
--- /dev/null
+++ b/src/crawl/stage.js
@@ -0,0 +1,426 @@
+// The avatars on /crawl: one shared WebGL canvas, every agent drawn over its
+// live browser frame.
+//
+// The page lays out its screens in normal DOM (the featured screen and the tile
+// wall). This module keeps a single full-viewport canvas pinned on top of them
+// and, every frame, draws each attached screen's avatar into that screen's
+// rectangle with setViewport/setScissor and an orthographic camera measured in
+// the screen's own CSS pixels. One WebGL context serves any number of screens,
+// so the wall never runs into the browser's context limit.
+//
+// Motion is per crawler, not per screen: when an agent walks to a link, its
+// featured view and its tile both walk the same normalized path, so switching
+// the featured agent never makes an avatar jump.
+
+import {
+ Box3,
+ CanvasTexture,
+ DirectionalLight,
+ Group,
+ HemisphereLight,
+ Mesh,
+ MeshBasicMaterial,
+ OrthographicCamera,
+ PMREMGenerator,
+ PlaneGeometry,
+ Scene,
+ Vector3,
+ WebGLRenderer,
+} from 'three';
+import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
+import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';
+import { clone as cloneSkinnedScene } from 'three/addons/utils/SkeletonUtils.js';
+import { getMeshoptDecoder } from '../viewer/internal.js';
+import { AnimationManager } from '../animation-manager.js';
+import { resolveDevR2Url } from '../shared/dev-r2-proxy.js';
+
+const FALLBACK_AVATAR = '/avatars/default.glb';
+const MANIFEST_URL = '/animations/manifest.json';
+const CLIP_IDLE = 'idle';
+const CLIP_WALK = 'av-walk-feminine';
+
+// Frames are 1200x750 browser viewports; normalized x is stretched by this to
+// measure distance in the same units as normalized y.
+const FRAME_ASPECT = 1200 / 750;
+const AVATAR_FRACTION = 0.24; // avatar height as a share of its screen's height
+const WALK_SPEED = 2.4; // avatar heights per second
+const NOMINAL_CLIP_SPEED = 1.5; // the walk clip's natural pace in heights/s
+const HOP_SECONDS = 0.7;
+const LAND_SECONDS = 0.38;
+const GONE_TIMEOUT_MS = 9000; // land on our own if the next page never arrives
+
+const UP = new Vector3(0, 1, 0);
+
+const reducedMotion = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
+
+// ── shared loaders ──────────────────────────────────────────────────────────
+const templates = new Map(); // url -> Promise<Object3D>
+function loadTemplate(url) {
+ let p = templates.get(url);
+ if (!p) {
+ const loader = new GLTFLoader();
+ p = getMeshoptDecoder()
+ .then((d) => loader.setMeshoptDecoder(d))
+ .then(() => loader.loadAsync(resolveDevR2Url(url)))
+ .then((gltf) => gltf.scene);
+ templates.set(url, p);
+ p.catch(() => { if (templates.get(url) === p) templates.delete(url); });
+ }
+ return p;
+}
+
+let clipDefsPromise = null;
+function clipDefs() {
+ if (!clipDefsPromise) {
+ clipDefsPromise = fetch(MANIFEST_URL, { cache: 'force-cache' })
+ .then((r) => {
+ if (!r.ok) throw new Error(`animation manifest ${r.status}`);
+ return r.json();
+ })
+ .then((all) => all.filter((d) => d.name === CLIP_IDLE || d.name === CLIP_WALK));
+ clipDefsPromise.catch(() => { clipDefsPromise = null; });
+ }
+ return clipDefsPromise;
+}
+
+// A soft contact shadow so the avatar reads as standing on the page.
+let shadowTexture = null;
+function contactShadow() {
+ if (!shadowTexture) {
+ // A circle that is fully clear well inside the canvas edge; the plane
+ // stretches it into an ellipse, so no edge of the texture ever shows.
+ const c = document.createElement('canvas');
+ c.width = 64;
+ c.height = 64;
+ const g = c.getContext('2d');
+ const grad = g.createRadialGradient(32, 32, 0, 32, 32, 30);
+ grad.addColorStop(0, 'rgba(0,0,0,0.42)');
+ grad.addColorStop(0.55, 'rgba(0,0,0,0.16)');
+ grad.addColorStop(1, 'rgba(0,0,0,0)');
+ g.fillStyle = grad;
+ g.fillRect(0, 0, 64, 64);
+ shadowTexture = new CanvasTexture(c);
+ }
+ const mesh = new Mesh(
+ new PlaneGeometry(0.9, 0.22),
+ new MeshBasicMaterial({ map: shadowTexture, transparent: true, depthWrite: false }),
+ );
+ mesh.position.set(0, 0.01, -0.5);
+ mesh.renderOrder = -1;
+ return mesh;
+}
+
+const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
+const easeInOut = (t) => (t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2);
+function shortestAngle(a) {
+ let d = a % (Math.PI * 2);
+ if (d > Math.PI) d -= Math.PI * 2;
+ if (d < -Math.PI) d += Math.PI * 2;
+ return d;
+}
+
+// ── motion: one per crawler, shared by every screen that shows it ──────────
+class Motion {
+ constructor() {
+ this.x = 0.12;
+ this.y = 0.93;
+ this.yaw = 0;
+ this.targetYaw = 0;
+ this.mode = 'idle'; // idle | walk | hop | gone | land
+ this.scale = 1;
+ this.lift = 0; // hop height in avatar heights
+ this.speed = 1;
+ this.queue = [];
+ this.action = null;
+ this.goneAt = 0;
+ }
+
+ enqueue(action) {
+ // A crawler that fell behind (tab in the background, slow network) skips
+ // stale walks rather than replaying a backlog.
+ if (this.queue.length > 3) this.queue.splice(0, this.queue.length - 2);
+ this.queue.push(action);
+ }
+
+ tick(dt, now) {
+ if (!this.action && this.queue.length) this.start(this.queue.shift());
+ const a = this.action;
+ if (a) {
+ a.t = Math.min(1, a.t + dt / a.dur);
+ if (a.type === 'walk') {
+ const k = easeInOut(a.t);
+ this.x = a.from.x + (a.to.x - a.from.x) * k;
+ this.y = a.from.y + (a.to.y - a.from.y) * k;
+ } else if (a.type === 'hop') {
+ this.lift = Math.sin(Math.PI * Math.min(1, a.t * 1.25)) * 0.5;
+ this.scale = a.t < 0.6 ? 1 : 1 - (a.t - 0.6) / 0.4;
+ } else if (a.type === 'land') {
+ // Pop in with a little overshoot.
+ const t = a.t;
+ this.scale = t < 0.7 ? (t / 0.7) * 1.12 : 1.12 - ((t - 0.7) / 0.3) * 0.12;
+ this.lift = 0;
+ }
+ if (a.t >= 1) this.finish(a, now);
+ }
+ if (this.mode === 'gone' && now - this.goneAt > GONE_TIMEOUT_MS && !this.queue.length) {
+ this.enqueue({ type: 'land' });
+ }
+ this.yaw += shortestAngle(this.targetYaw - this.yaw) * (1 - Math.exp(-dt * 9));
+ }
+
+ start(a) {
+ if (a.type === 'walk') {
+ if (this.mode === 'gone') this.scale = 1;
+ const dx = (a.to.x - this.x) * FRAME_ASPECT;
+ const dy = a.to.y - this.y;
+ const dist = Math.hypot(dx, dy) / AVATAR_FRACTION; // in avatar heights
+ if (dist < 0.05) { this.face(a.face); return; }
+ a.from = { x: this.x, y: this.y };
+ a.dur = reducedMotion ? 0.25 : clamp(dist / WALK_SPEED, 0.7, 3);
+ a.t = 0;
+ this.speed = clamp(dist / a.dur / NOMINAL_CLIP_SPEED, 0.75, 1.8);
+ this.mode = 'walk';
+ // Screen-down is toward the viewer (+z), so forward = (dx, dy).
+ this.targetYaw = Math.atan2(dx, dy);
+ } else if (a.type === 'hop') {
+ if (this.mode === 'gone') return;
+ a.dur = reducedMotion ? 0.15 : HOP_SECONDS;
+ a.t = 0;
+ this.mode = 'hop';
+ } else if (a.type === 'land') {
+ if (this.mode !== 'gone') { this.face(a.face); return; }
+ if (a.at) { this.x = a.at.x; this.y = a.at.y; }
+ a.dur = reducedMotion ? 0.1 : LAND_SECONDS;
+ a.t = 0;
+ this.scale = 0;
+ this.mode = 'land';
+ this.face(a.face);
+ } else if (a.type === 'face') {
+ this.face(a.face);
+ return;
+ }
+ this.action = a;
+ }
+
+ finish(a, now) {
+ this.action = null;
+ if (a.type === 'walk') {
+ this.mode = 'idle';
+ this.face(a.face);
+ } else if (a.type === 'hop') {
+ this.mode = 'gone';
+ this.scale = 0;
+ this.lift = 0;
+ this.goneAt = now;
+ } else if (a.type === 'land') {
+ this.mode = 'idle';
+ this.scale = 1;
+ }
+ }
+
+ // 'link-right' / 'link-left': looking along the page at the link beside it.
+ // 'page': turned three-quarters toward the text it is reading.
+ // 'viewer' (default): facing out of the screen.
+ face(dir) {
+ if (dir === 'link-right') this.targetYaw = Math.PI * 0.42;
+ else if (dir === 'link-left') this.targetYaw = -Math.PI * 0.42;
+ else if (dir === 'page') this.targetYaw = (this.x < 0.5 ? 1 : -1) * Math.PI * 0.22;
+ else if (dir) this.targetYaw = 0;
+ }
+}
+
+// ── one screen's view of one crawler ───────────────────────────────────────
+class View {
+ constructor(stage, el, crawlerId, opts) {
+ this.stage = stage;
+ this.el = el;
+ this.crawlerId = crawlerId;
+ this.onPlace = opts.onPlace || null;
+ this.scene = new Scene();
+ this.scene.environment = stage.envTexture;
+ this.scene.add(new HemisphereLight(0xffffff, 0x445066, 1.4));
+ const key = new DirectionalLight(0xffffff, 2.2);
+ key.position.set(0.6, 1, 1.2);
+ this.scene.add(key);
+ this.camera = new OrthographicCamera(0, 1, 0, -1, -2000, 2000);
+ this.camera.position.set(0, 0, 1000);
+ this.rig = new Group(); // positioned in screen pixels, scaled to avatar height
+ this.pivot = new Group(); // yaw + a slight forward tilt to show some depth
+ this.rig.add(this.pivot);
+ this.shadow = contactShadow();
+ this.rig.add(this.shadow);
+ this.rig.visible = false;
+ this.scene.add(this.rig);
+ this.anim = null;
+ this.clipsOk = false;
+ this.mode = null;
+ this.disposed = false;
+ this.build(opts.avatarUrl);
+ }
+
+ async build(avatarUrl) {
+ let template;
+ try {
+ template = await loadTemplate(avatarUrl || FALLBACK_AVATAR);
+ } catch {
+ // The owner's avatar failed to load (deleted, CORS, corrupt): walk
+ // the platform default rather than leave the screen empty.
+ template = await loadTemplate(FALLBACK_AVATAR).catch(() => null);
+ }
+ if (!template || this.disposed) return;
+
+ const body = cloneSkinnedScene(template);
+ const box = new Box3().setFromObject(body);
+ const height = Math.max(0.01, box.max.y - box.min.y);
+ const center = box.getCenter(new Vector3());
+ body.position.set(-center.x, -box.min.y, -center.z);
+ const holder = new Group();
+ holder.add(body);
+ holder.scale.setScalar(1 / height);
+ this.pivot.add(holder);
+ this.rig.visible = true;
+
+ this.anim = new AnimationManager();
+ this.anim.attach(body, { avatarUrl: avatarUrl || FALLBACK_AVATAR });
+ try {
+ this.anim.setAnimationDefs(await clipDefs());
+ this.clipsOk = this.anim.supportsCanonicalClips();
+ if (this.clipsOk) {
+ await this.anim.loadAll();
+ if (this.disposed) return;
+ await this.anim.crossfadeTo(CLIP_IDLE, 0);
+ this.mode = 'idle';
+ }
+ } catch {
+ // Clips unavailable: the avatar still glides and hops in its rest pose.
+ this.clipsOk = false;
+ }
+ }
+
+ syncClip(motion) {
+ if (!this.clipsOk || !this.anim) return;
+ const want = motion.mode === 'walk' ? 'walk' : 'idle';
+ if (want !== this.mode) {
+ this.mode = want;
+ this.anim.crossfadeTo(want === 'walk' ? CLIP_WALK : CLIP_IDLE, 0.22);
+ }
+ this.anim.setSpeed?.(want === 'walk' ? motion.speed : 1);
+ }
+
+ dispose() {
+ this.disposed = true;
+ this.anim?.dispose?.();
+ this.scene.clear();
+ }
+}
+
+// ── the stage ───────────────────────────────────────────────────────────────
+export function createStage({ canvas, clipTop = () => 0 }) {
+ let renderer;
+ try {
+ renderer = new WebGLRenderer({ canvas, alpha: true, antialias: true, powerPreference: 'low-power' });
+ } catch {
+ return null; // no WebGL: the page still works, just without bodies
+ }
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
+ renderer.setClearColor(0x000000, 0);
+ renderer.autoClear = false;
+ const pmrem = new PMREMGenerator(renderer);
+ const envTexture = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;
+ pmrem.dispose();
+
+ const stage = { envTexture };
+ const motions = new Map(); // crawlerId -> Motion
+ const avatars = new Map(); // crawlerId -> avatarUrl
+ const views = new Set();
+ let raf = 0;
+ let last = performance.now();
+
+ function resize() {
+ renderer.setSize(window.innerWidth, window.innerHeight, false);
+ }
+ resize();
+ window.addEventListener('resize', resize);
+
+ function motion(id) {
+ let m = motions.get(id);
+ if (!m) { m = new Motion(); motions.set(id, m); }
+ return m;
+ }
+
+ function frame(now) {
+ raf = 0;
+ const dt = Math.min(0.1, (now - last) / 1000);
+ last = now;
+ for (const m of motions.values()) m.tick(dt, now);
+
+ const W = window.innerWidth;
+ const H = window.innerHeight;
+ const top = clipTop();
+ renderer.setScissorTest(false);
+ renderer.clear();
+ renderer.setScissorTest(true);
+
+ for (const v of views) {
+ const m = motions.get(v.crawlerId);
+ if (!m || !v.rig.visible) continue;
+ const r = v.el.getBoundingClientRect();
+ const left = Math.max(0, r.left);
+ const right = Math.min(W, r.right);
+ const ctop = Math.max(top, r.top);
+ const cbottom = Math.min(H, r.bottom);
+ if (r.width < 8 || right <= left || cbottom <= ctop) continue;
+
+ v.syncClip(m);
+ v.anim?.update(dt);
+
+ const h = r.height;
+ const avatarH = clamp(h * AVATAR_FRACTION, 34, 190);
+ const px = m.x * r.width;
+ const py = m.y * h - m.lift * avatarH;
+ v.rig.position.set(px, -py, 0);
+ v.rig.scale.setScalar(avatarH * Math.max(0.001, m.scale));
+ v.pivot.quaternion.setFromAxisAngle(UP, m.yaw);
+ v.pivot.rotateX(0.12);
+ v.shadow.visible = m.lift < 0.05; // the shadow stays on the floor
+
+ v.camera.right = r.width;
+ v.camera.bottom = -h;
+ v.camera.updateProjectionMatrix();
+ renderer.setViewport(r.left, H - r.bottom, r.width, h);
+ renderer.setScissor(left, H - cbottom, right - left, cbottom - ctop);
+ if (m.scale > 0.01) renderer.render(v.scene, v.camera);
+ v.onPlace?.(px, py - avatarH * m.scale, m);
+ }
+ if (views.size && !document.hidden) raf = requestAnimationFrame(frame);
+ }
+
+ function wake() {
+ if (!raf && views.size && !document.hidden) {
+ last = performance.now();
+ raf = requestAnimationFrame(frame);
+ }
+ }
+ document.addEventListener('visibilitychange', wake);
+
+ return {
+ // Remember which body a crawler wears; views created after this use it.
+ setAvatar(id, url) { avatars.set(id, url || null); },
+
+ // Draw crawler `id` inside element `el` until the returned detach() runs.
+ attach(el, id, opts = {}) {
+ motion(id);
+ const v = new View(stage, el, id, { ...opts, avatarUrl: avatars.get(id) });
+ views.add(v);
+ wake();
+ return () => { views.delete(v); v.dispose(); };
+ },
+
+ walk(id, to, face) { motion(id).enqueue({ type: 'walk', to, face }); },
+ hop(id) { motion(id).enqueue({ type: 'hop' }); },
+ land(id, face, at) { motion(id).enqueue({ type: 'land', face, at }); },
+ face(id, face) { motion(id).enqueue({ type: 'face', face }); },
+ isGone(id) { const m = motions.get(id); return Boolean(m && (m.mode === 'gone' || m.mode === 'hop')); },
+ forget(id) { motions.delete(id); },
+ };
+}
diff --git a/src/walk-companion.js b/src/walk-companion.js
index cfe0fac01..02cf13ac1 100644
--- a/src/walk-companion.js
+++ b/src/walk-companion.js
@@ -42,7 +42,10 @@ const walk = createWalkCompanion({
// /timeline is a full-screen 3D scene with its own idle-animated guide
// walking the path, and its bottom-right corner is the auto-play button:
// the corner mascot sat exactly on top of it and swallowed the click.
- excludedRoutes: [...DEFAULT_EXCLUDED_PREFIXES, '/concierge', '/agent-studio', '/timeline'],
+ // /crawl already walks every crawling agent's own body across its live
+ // screen; a corner mascot narrating the page beside them is a second,
+ // unrelated avatar competing for the same attention.
+ excludedRoutes: [...DEFAULT_EXCLUDED_PREFIXES, '/concierge', '/agent-studio', '/timeline', '/crawl'],
});
// public/nav.js drives the companion through this global (toggle from the nav
diff --git a/vite.config.js b/vite.config.js
index 9b6f4238a..1e6d86b0e 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -989,6 +989,7 @@ const appConfig = {
'avatar-sdk': resolve(__dirname, 'pages/avatar-sdk.html'),
'avatar-cli': resolve(__dirname, 'pages/avatar-cli.html'),
'rig-doctor': resolve(__dirname, 'pages/rig-doctor.html'),
+ crawl: resolve(__dirname, 'pages/crawl.html'),
brain: resolve(__dirname, 'pages/brain.html'),
'agent-studio': resolve(__dirname, 'pages/agent-studio.html'),
cosmos: resolve(__dirname, 'pages/cosmos.html'),
@@ -1527,6 +1528,8 @@ const appConfig = {
'/agents-live/': resolve(root, 'pages/agents-live.html'),
'/monitor': resolve(root, 'pages/monitor.html'),
'/monitor/': resolve(root, 'pages/monitor.html'),
+ '/crawl': resolve(root, 'pages/crawl.html'),
+ '/crawl/': resolve(root, 'pages/crawl.html'),
'/start': resolve(root, 'pages/start.html'),
'/start/': resolve(root, 'pages/start.html'),
'/create': resolve(root, 'pages/create.html'),