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(extension): declare the checkout companion manifest and finish its motion deps

nirholas94b72cb0f654
diff --git a/extensions/checkout-companion/content.js b/extensions/checkout-companion/content.js
new file mode 100644
index 000000000..a02a3c882
--- /dev/null
+++ b/extensions/checkout-companion/content.js
@@ -0,0 +1,135 @@
+// The content script: notice a checkout, read it, show what it found.
+//
+// Runs on every page, does almost nothing on nearly all of them. The order of
+// operations is deliberate and is the privacy design:
+//
+// 1. Cheap local check. Does this page even look like a checkout? A URL
+// pattern and a page-language score, both computed in the tab. A news
+// article never gets past this line and never touches the network.
+// 2. Read visible text only, refusing every input (extract.js).
+// 3. Redact in the tab, before anything is sent.
+// 4. Send to three.ws only if the person turned the extension on, only for a
+// page that passed step 1, and only once per page.
+//
+// A page that is not a checkout produces no request, no storage write, and no
+// UI. Silence is the correct behaviour almost all of the time, and an extension
+// that announces itself on every page would be uninstalled within a day.
+
+const STATE = {
+ ran: false,
+ panel: null,
+};
+
+const SETTINGS_DEFAULTS = {
+ enabled: true,
+ speak: true,
+ rememberPrices: true,
+};
+
+async function settings() {
+ const stored = await chrome.storage.local.get(SETTINGS_DEFAULTS);
+ return { ...SETTINGS_DEFAULTS, ...stored };
+}
+
+/**
+ * The price this site last showed before checkout, kept per origin.
+ *
+ * This is the honest version of "the agent follows you across the flow": no
+ * screen reading, no cross-app surveillance, just one number per site so the
+ * total on the payment page can be compared against the price on the page that
+ * sent you there. It expires after an hour, because a price you saw yesterday
+ * is not what you think you are buying today, and it never leaves the browser
+ * except as the single integer sent with the checkout read.
+ */
+const PRICE_TTL_MS = 60 * 60 * 1000;
+
+async function rememberedPrice(origin) {
+ const { prices = {} } = await chrome.storage.local.get({ prices: {} });
+ const entry = prices[origin];
+ if (!entry) return null;
+ if (Date.now() - entry.at > PRICE_TTL_MS) return null;
+ return { value: entry.value, currency: entry.currency };
+}
+
+async function rememberPrice(origin, amount) {
+ const { prices = {} } = await chrome.storage.local.get({ prices: {} });
+ prices[origin] = { value: amount.value, currency: amount.currency, at: Date.now() };
+ // Keep the map small: twenty origins is more than a browsing session needs
+ // and stops this from becoming a shopping history by accident.
+ const entries = Object.entries(prices).sort((a, b) => b[1].at - a[1].at).slice(0, 20);
+ await chrome.storage.local.set({ prices: Object.fromEntries(entries) });
+}
+
+async function run() {
+ if (STATE.ran) return;
+ const config = await settings();
+ if (!config.enabled) return;
+
+ const extract = await import(chrome.runtime.getURL('extract.js'));
+ const text = extract.collectText(document.body, { view: window });
+ const url = location.href;
+ const origin = location.origin;
+
+ const amounts = extract.collectAmounts(document.body, { view: window });
+ const total = extract.primaryTotal(amounts);
+
+ if (!extract.looksLikeCheckout({ url, text })) {
+ // Not a checkout. The only thing worth doing on a product page is
+ // noting the price for later, and only if the person allowed it.
+ if (config.rememberPrices && total) await rememberPrice(origin, total);
+ return;
+ }
+
+ STATE.ran = true;
+ const quoted = config.rememberPrices ? await rememberedPrice(origin) : null;
+ const payload = extract.buildExtract({ url, title: document.title, text, amounts, quoted });
+
+ const panel = await import(chrome.runtime.getURL('panel.js'));
+ STATE.panel = panel.mount({ speak: config.speak });
+ STATE.panel.setState('reading');
+
+ const reply = await chrome.runtime.sendMessage({ type: 'checkout:analyze', payload });
+
+ if (!reply || reply.error) {
+ STATE.panel.setState('error', reply?.error || { code: 'unknown', message: 'The read did not complete.' });
+ return;
+ }
+ STATE.panel.setState('done', reply.result);
+}
+
+// A checkout is usually rendered after the first paint and often replaced in
+// place by a single-page flow, so one pass at document_idle would miss most of
+// them. Re-check on url change and on a settled DOM, and stop once a real
+// checkout has been read: one payment page is one reading.
+function watch() {
+ let lastUrl = location.href;
+ let timer = null;
+ const schedule = () => {
+ if (STATE.ran) return;
+ clearTimeout(timer);
+ timer = setTimeout(() => {
+ run().catch(() => {
+ // A page that breaks the read gets no panel rather than a broken
+ // one. Nothing here is important enough to interrupt a checkout
+ // with an extension error.
+ });
+ }, 700);
+ };
+
+ schedule();
+ new MutationObserver(() => {
+ if (location.href !== lastUrl) {
+ lastUrl = location.href;
+ STATE.ran = false;
+ STATE.panel?.destroy();
+ STATE.panel = null;
+ }
+ schedule();
+ }).observe(document.documentElement, { childList: true, subtree: true });
+}
+
+if (document.readyState === 'loading') {
+ document.addEventListener('DOMContentLoaded', watch, { once: true });
+} else {
+ watch();
+}
diff --git a/extensions/checkout-companion/manifest.json b/extensions/checkout-companion/manifest.json
new file mode 100644
index 000000000..eb606f9be
--- /dev/null
+++ b/extensions/checkout-companion/manifest.json
@@ -0,0 +1,60 @@
+{
+ "manifest_version": 3,
+ "name": "three.ws Checkout Companion",
+ "short_name": "Checkout Companion",
+ "version": "1.0.0",
+ "description": "Your agent reads the checkout before you pay: what it really costs, whether it repeats, and what the fine print commits you to.",
+ "homepage_url": "https://three.ws/checkout-companion",
+
+ "icons": {
+ "16": "icons/icon-16.png",
+ "32": "icons/icon-32.png",
+ "48": "icons/icon-48.png",
+ "128": "icons/icon-128.png"
+ },
+
+ "action": {
+ "default_popup": "popup.html",
+ "default_icon": {
+ "16": "icons/icon-16.png",
+ "32": "icons/icon-32.png",
+ "48": "icons/icon-48.png",
+ "128": "icons/icon-128.png"
+ },
+ "default_title": "three.ws Checkout Companion"
+ },
+
+ "background": {
+ "service_worker": "background.js",
+ "type": "module"
+ },
+
+ "content_scripts": [
+ {
+ "matches": ["http://*/*", "https://*/*"],
+ "js": ["content.js"],
+ "css": ["panel.css"],
+ "run_at": "document_idle",
+ "all_frames": false
+ }
+ ],
+
+ "web_accessible_resources": [
+ {
+ "resources": ["extract.js", "panel.js", "avatar.svg"],
+ "matches": ["http://*/*", "https://*/*"]
+ }
+ ],
+
+ "permissions": ["storage", "alarms"],
+
+ "host_permissions": ["https://three.ws/*"],
+
+ "options_page": "options.html",
+
+ "content_security_policy": {
+ "extension_pages": "script-src 'self'; object-src 'self'"
+ },
+
+ "minimum_chrome_version": "109"
+}
diff --git a/packages/motion/src/compose.js b/packages/motion/src/compose.js
index 9a1b1fd90..ad8be9d37 100644
--- a/packages/motion/src/compose.js
+++ b/packages/motion/src/compose.js
@@ -22,6 +22,13 @@
import { EFFORTS } from './vocabulary.js';
+// Both hands resting on the thighs: the shape a body makes sitting down or
+// bracing on its legs, reused by every posture that needs it.
+const HANDS_ON_THIGHS = Object.freeze({
+ left: { at: 'thigh', forward: 0.04, palm: 'down', hand: 'relaxed', elbow: 'down' },
+ right: { at: 'thigh', forward: 0.04, palm: 'down', hand: 'relaxed', elbow: 'down' },
+});
+
/**
* Actions this lane can build without a model. Each is a function of the
* parsed modifiers, returning beats.
@@ -82,13 +89,15 @@ const ACTIONS = {
],
point: ({ side, direction, effort }) => {
- const at = direction === 'down' ? 'floor' : direction === 'up' ? 'overhead' : 'front';
+ // Pointing down means aiming an arm at the floor, not putting a wrist on
+ // it: the target stays inside the arm's reach and the finger does the rest.
+ const at = direction === 'up' ? 'overhead' : 'front';
return [
{ label: 'ready', posture: 'easy', in: 0.2, effort },
{
label: 'point',
posture: direction === 'down' ? 'lean_in' : 'easy',
- arms: { [side]: { at, forward: direction === 'forward' ? 0.12 : 0, palm: 'down', point: direction === 'up' ? 'up' : 'forward', hand: 'point', elbow: 'down' } },
+ arms: { [side]: { at, up: direction === 'down' ? -0.3 : 0, forward: direction === 'forward' ? 0.12 : 0.04, palm: 'down', point: direction === 'up' ? 'up' : direction === 'down' ? 'down' : 'forward', hand: 'point', elbow: 'down' } },
gaze: direction === 'down' ? 'down' : direction === 'up' ? 'up' : 'forward',
in: 0.3,
hold: 0.6,
@@ -125,11 +134,11 @@ const ACTIONS = {
sit: ({ effort }) => [
{ label: 'stand', posture: 'easy', in: 0.25, effort },
{ label: 'lower', posture: 'crouch', gaze: 'down', in: 0.55, effort },
- { label: 'seated', posture: 'sit', gaze: 'forward', arms: { left: { at: 'knee', forward: 0.06, hand: 'relaxed' }, right: { at: 'knee', forward: 0.06, hand: 'relaxed' } }, in: 0.5, hold: 0.9, effort },
+ { label: 'seated', posture: 'sit', torso: { lean: 18 }, gaze: 'forward', arms: { left: HANDS_ON_THIGHS.left, right: HANDS_ON_THIGHS.right }, in: 0.5, hold: 0.9, effort },
],
stand_up: ({ effort }) => [
- { label: 'seated', posture: 'sit', arms: { left: { at: 'knee', forward: 0.06, hand: 'relaxed' }, right: { at: 'knee', forward: 0.06, hand: 'relaxed' } }, in: 0.25, effort },
+ { label: 'seated', posture: 'sit', torso: { lean: 18 }, arms: { left: HANDS_ON_THIGHS.left, right: HANDS_ON_THIGHS.right }, in: 0.25, effort },
{ label: 'lean out', posture: 'sit', torso: { lean: 26 }, gaze: 'down', in: 0.4, effort },
{ label: 'rise', posture: 'crouch', in: 0.45, effort },
{ label: 'stand', posture: 'easy', gaze: 'forward', in: 0.5, hold: 0.3, effort },
@@ -137,7 +146,7 @@ const ACTIONS = {
crouch: ({ effort }) => [
{ label: 'stand', posture: 'easy', in: 0.25, effort },
- { label: 'down', posture: 'crouch', gaze: 'down', arms: { left: { at: 'knee', hand: 'relaxed' }, right: { at: 'knee', hand: 'relaxed' } }, in: 0.55, hold: 0.7, effort },
+ { label: 'down', posture: 'crouch', torso: { lean: 30 }, gaze: 'down', arms: { left: HANDS_ON_THIGHS.left, right: HANDS_ON_THIGHS.right }, in: 0.55, hold: 0.7, effort },
{ label: 'up', posture: 'easy', gaze: 'forward', in: 0.6, hold: 0.2, effort },
],
@@ -219,7 +228,7 @@ const ACTIONS = {
{
label: 'reach',
posture: direction === 'down' ? 'crouch' : 'lean_in',
- arms: { [side]: { at: direction === 'up' ? 'overhead' : direction === 'down' ? 'floor' : 'front', forward: 0.1, palm: direction === 'down' ? 'down' : 'up', hand: 'open', elbow: 'down' } },
+ arms: { [side]: { at: direction === 'up' ? 'overhead' : 'front', up: direction === 'down' ? -0.3 : 0, forward: 0.1, palm: direction === 'down' ? 'down' : 'up', hand: 'open', elbow: 'down' } },
gaze: direction === 'down' ? 'down' : direction === 'up' ? 'up' : 'forward',
in: 0.5,
hold: 0.4,
diff --git a/packages/motion/src/rig/anchors.js b/packages/motion/src/rig/anchors.js
index cab4e2b79..57bbfdb51 100644
--- a/packages/motion/src/rig/anchors.js
+++ b/packages/motion/src/rig/anchors.js
@@ -7,7 +7,7 @@
// owns it, so "at the chin" is still at the chin after the torso has turned
// forty degrees and the hips have dropped into a crouch.
-import { qConj, qRotate, vAdd, vScale, vSub } from './math.js';
+import { qConj, qRotate, vAdd, vLerp, vScale, vSub } from './math.js';
import {
ARM_REACH,
BODY_FORWARD,
@@ -96,7 +96,16 @@ export const ANCHORS = Object.freeze({
Left: vAdd(shoulderL, vAdd(above(-hang * 0.86), vAdd(lateral(-0.02), ahead(-hang * 0.42)))),
Right: vAdd(shoulderR, vAdd(above(-hang * 0.86), vAdd(lateral(0.02), ahead(-hang * 0.42)))),
},
- /** Knee height in front: reaching down without the hips moving. */
+ /**
+ * On the thigh, a third of the way from hip to knee: where a hand actually
+ * rests when someone sits down or leans on their legs. The knee itself is
+ * past a wrist's reach on a human skeleton, which is why hands go here.
+ */
+ thigh: {
+ Left: vLerp(restPos('LeftUpLeg'), restPos('LeftLeg'), 0.35),
+ Right: vLerp(restPos('RightUpLeg'), restPos('RightLeg'), 0.35),
+ },
+ /** The knee joint itself: a place to look at, or to reach for in a crouch. */
knee: {
Left: vAdd(restPos('LeftLeg'), ahead(0.12)),
Right: vAdd(restPos('RightLeg'), ahead(0.12)),
@@ -126,9 +135,10 @@ const ANCHOR_BONE = Object.freeze({
waist: 'Spine',
hips: 'Hips',
hip: 'Hips',
- side: 'Hips',
- behind: 'Hips',
+ side: 'Spine2',
+ behind: 'Spine2',
knee: { Left: 'LeftLeg', Right: 'RightLeg' },
+ thigh: { Left: 'LeftUpLeg', Right: 'RightUpLeg' },
shoulder: 'Spine2',
// The floor does not follow the body: that is what makes it the floor.
floor: null,