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.

fix(discovery): stand the passive feature prompt down whenever the Walk Companion owns the corner

nirholasde441e30395d
diff --git a/public/feature-discovery.js b/public/feature-discovery.js
index 545453be0..84969bb08 100644
--- a/public/feature-discovery.js
+++ b/public/feature-discovery.js
@@ -45,6 +45,8 @@
var K_VISITED = 'threews:fd:visited'; // routes the user has opened (array)
var K_TRIED = 'threews:fd:tried'; // dismissed "have you tried" prompts (map)
var REVEAL_DELAY_MS = 6500; // let the page settle before suggesting
+ // Owned by the Walk Companion (walk-sdk config keys.enabled), read-only here.
+ var K_WALK_ENABLED = 'walk:companion:enabled';
// ── Feature catalog — friendly labels + plain-language copy (aligns C02). ──
// Routes are confirmed live (vercel.json). This is descriptive metadata only;
@@ -151,6 +153,35 @@
var CURRENT = normPath(location.pathname);
+ // ── The other ambient helper ───────────────────────────────────────────────
+ // The Walk Companion greets, narrates and answers ⌘K, and it owns the same
+ // corner. Two of them talking at once is clutter, so the passive prompt
+ // stands down whenever the companion is live.
+ //
+ // A single read of the enabled flag is not enough: nav.js summons the
+ // companion for first-time visitors from an idle callback (load + 2s, idle
+ // timeout 4s) that regularly lands AFTER our 6.5s reveal, so the flag is
+ // still absent when we look. Checking the mounted host as well closes the
+ // early half of the race; retractOnCompanion() below closes the late half.
+ function companionLive() {
+ try { if (localStorage.getItem(K_WALK_ENABLED) === '1') return true; } catch (_) {}
+ return !!document.querySelector('.walk-companion');
+ }
+
+ // A suggestion the visitor can already see is noise, not discovery: /create
+ // puts a "Generate a 3D model" card on screen that goes straight to /forge.
+ // Only content links count: the nav and footer link to nearly everything,
+ // and counting them would silence the prompt site-wide.
+ function pageLinksTo(route) {
+ var anchors = document.querySelectorAll('a[href^="/"]');
+ for (var i = 0; i < anchors.length; i++) {
+ var a = anchors[i];
+ if (a.closest('#nav-container, nav, footer, #tws-corner-stack')) continue;
+ if (normPath(a.getAttribute('href')) === route) return true;
+ }
+ return false;
+ }
+
function visitedSet() {
var arr = read(K_VISITED, []);
var set = Object.create(null);
@@ -345,6 +376,7 @@
if (visited[r]) continue;
if (isTriedDismissed(r)) continue;
if (!FEATURES[r]) continue;
+ if (pageLinksTo(r)) continue;
return r;
}
return null;
@@ -367,7 +399,7 @@
// When the companion agent is live it owns ambient discovery (it greets,
// narrates, and reacts to ⌘K commands) — don't stack a competing toast in
// the same corner. Contextual after-action cross-links still show.
- try { if (localStorage.getItem('walk:companion:enabled') === '1') return; } catch (_) {}
+ if (companionLive()) return;
var route = pickSuggestion();
if (!route) return;
var f = FEATURES[route];
@@ -382,7 +414,17 @@
// timeout is not a rejection, so it does NOT mark the feature tried —
// the session throttle already prevents re-prompting until next visit.
autoDismissMs: 13000,
- });
+ }).setAttribute('data-fd-passive', '1');
+ }
+
+ // The late half of the companion race: the prompt is already on screen when
+ // the companion mounts. Retract it the way a timeout does (no "tried" mark,
+ // the feature was never actually rejected) and leave the corner to the
+ // companion. Contextual cross-links are user-earned, so they stay put.
+ function retractOnCompanion() {
+ if (!_card || _card.getAttribute('data-fd-passive') !== '1') return;
+ if (!companionLive()) return;
+ dismissCard();
}
// ── Contextual cross-links after a feature completes ───────────────────────
@@ -481,6 +523,10 @@
showCrossLinks(feature, e.detail);
});
+ // nav.js fires this when it auto-summons the companion for a first-time
+ // visitor, and the SDK fires it on every enable/disable.
+ window.addEventListener('walk-companion:change', retractOnCompanion);
+
_revealTimer = setTimeout(showPassivePrompt, REVEAL_DELAY_MS);
}
diff --git a/tests/feature-discovery.test.js b/tests/feature-discovery.test.js
new file mode 100644
index 000000000..cef692654
--- /dev/null
+++ b/tests/feature-discovery.test.js
@@ -0,0 +1,144 @@
+/**
+ * The in-product feature-discovery layer (public/feature-discovery.js).
+ *
+ * The passive "Have you tried…" prompt shares the bottom-right corner with the
+ * Walk Companion, and both auto-start for a first-time visitor. Two regressions
+ * are pinned here, both observed on the live /create page:
+ *
+ * 1. The companion guard read `walk:companion:enabled` once, 6.5s in. nav.js
+ * summons the companion from an idle callback that lands later than that,
+ * so the flag was still absent and BOTH helpers ended up on screen, the
+ * pair of them covering the fourth intent card.
+ * 2. The prompt suggested a feature the page already links to (/create shows
+ * a "Generate a 3D model" card pointing at /forge), which is noise rather
+ * than discovery.
+ *
+ * The module is a plain IIFE served straight from public/, so it is exercised
+ * here the way a browser does: evaluated inside a JSDOM window.
+ */
+
+import { readFileSync } from 'node:fs';
+import { resolve } from 'node:path';
+import { describe, it, expect } from 'vitest';
+import { JSDOM } from 'jsdom';
+
+const root = resolve(__dirname, '..');
+const SOURCE = readFileSync(resolve(root, 'public/feature-discovery.js'), 'utf8');
+
+const REVEAL_MS = 6500; // must match REVEAL_DELAY_MS in the module
+
+/**
+ * Boot a window with the module evaluated in it, holding every timer the module
+ * schedules so the test drives the clock instead of waiting on it.
+ */
+async function boot(bodyHtml = '') {
+ const dom = new JSDOM(`<!doctype html><html><body>${bodyHtml}</body></html>`, {
+ runScripts: 'outside-only',
+ url: 'https://three.ws/create',
+ pretendToBeVisual: true,
+ });
+ const win = dom.window;
+ const timers = [];
+ win.setTimeout = function (fn, ms) {
+ timers.push({ fn, ms });
+ return timers.length;
+ };
+ win.clearTimeout = function () {};
+ win.eval(SOURCE);
+ // The module defers init to DOMContentLoaded, which JSDOM fires a tick after
+ // construction, exactly like a browser parsing the document.
+ if (win.document.readyState === 'loading') {
+ await new Promise((done) => win.addEventListener('DOMContentLoaded', done, { once: true }));
+ }
+ const run = (ms) => {
+ timers.filter((t) => t.ms === ms).forEach((t) => t.fn());
+ };
+ return { win, doc: win.document, run, reveal: () => run(REVEAL_MS) };
+}
+
+const card = (doc) => doc.querySelector('.tws-disc-card');
+const companionHost = '<div class="walk-companion" role="complementary"></div>';
+
+describe('feature discovery: passive prompt vs. the walk companion', () => {
+ it('stands down when the companion is already mounted, flag or no flag', async () => {
+ // The early half of the race: the companion beat us onto the page but
+ // nav.js has not written the enabled key yet.
+ const { doc, reveal } = await boot(companionHost);
+ reveal();
+ expect(card(doc)).toBeNull();
+ });
+
+ it('stands down when the companion flag is set', async () => {
+ const { win, doc, reveal } = await boot();
+ win.localStorage.setItem('walk:companion:enabled', '1');
+ reveal();
+ expect(card(doc)).toBeNull();
+ });
+
+ it('retracts an on-screen prompt when the companion arrives late', async () => {
+ const { win, doc, reveal, run } = await boot();
+ reveal();
+ expect(card(doc)).not.toBeNull();
+
+ // nav.js: sets the flag, then announces the summon.
+ win.localStorage.setItem('walk:companion:enabled', '1');
+ win.dispatchEvent(new win.CustomEvent('walk-companion:change'));
+ run(240); // the dismissal transition
+ expect(card(doc)).toBeNull();
+ });
+
+ it('does not mark the retracted feature as tried', async () => {
+ // A retraction is not a rejection: the visitor never saw a choice, so the
+ // suggestion must remain available on a later visit.
+ const { win, doc, reveal, run } = await boot();
+ reveal();
+ win.localStorage.setItem('walk:companion:enabled', '1');
+ win.dispatchEvent(new win.CustomEvent('walk-companion:change'));
+ run(240);
+ expect(card(doc)).toBeNull();
+ expect(win.localStorage.getItem('threews:fd:tried')).toBeNull();
+ });
+
+ it('leaves a contextual cross-link card alone when the companion arrives', async () => {
+ // Cross-links are user-earned (they follow a finished generation), so they
+ // are not the ambient clutter the retraction targets.
+ const { win, doc, run } = await boot();
+ win.twsDiscovery.crossLink('forge');
+ expect(card(doc)).not.toBeNull();
+ win.localStorage.setItem('walk:companion:enabled', '1');
+ win.dispatchEvent(new win.CustomEvent('walk-companion:change'));
+ run(240);
+ expect(card(doc)).not.toBeNull();
+ });
+});
+
+describe('feature discovery: suggestion picking', () => {
+ it('skips a feature the page already links to in its content', async () => {
+ // /forge is the first hidden gem; /create links straight to it.
+ const { doc, reveal } = await boot('<main><a href="/forge">Generate a 3D model</a></main>');
+ reveal();
+ const c = card(doc);
+ expect(c).not.toBeNull();
+ expect(c.querySelector('.tws-disc-cta').getAttribute('href')).not.toBe('/forge');
+ });
+
+ it('still suggests a feature that only the nav and footer link to', async () => {
+ // The nav links to nearly everything; counting it would silence the prompt
+ // site-wide.
+ const { doc, reveal } = await boot(
+ '<div id="nav-container"><a href="/forge">Forge</a></div><footer><a href="/forge">Forge</a></footer>',
+ );
+ reveal();
+ expect(card(doc).querySelector('.tws-disc-cta').getAttribute('href')).toBe('/forge');
+ });
+
+ it('suggests nothing twice in a session', async () => {
+ const { win, doc, reveal, run } = await boot();
+ reveal();
+ expect(card(doc)).not.toBeNull();
+ win.twsDiscovery.dismiss();
+ run(240);
+ reveal();
+ expect(card(doc)).toBeNull();
+ });
+});