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(avatar-page): mount the back link before the entity fetch can fail

nirholas2af17a0df60f
diff --git a/STRUCTURE.md b/STRUCTURE.md
index 6738fcbe1..e9dd707e3 100644
--- a/STRUCTURE.md
+++ b/STRUCTURE.md
@@ -178,6 +178,7 @@ bottom.
| Money flow map | [pages/flow.html](pages/flow.html) `→ /flow`, pure graph math + force layout [src/flow-map-core.js](src/flow-map-core.js), canvas/DOM layer [src/flow-map.js](src/flow-map.js), styles [src/flow-map.css](src/flow-map.css), backend view [api/pulse.js](api/pulse.js) `→ GET /api/pulse?view=graph` | Live | The TOPOLOGY of the agent economy, which every other economy surface here misses because a leaderboard cannot show shape. A force-directed canvas map of who paid whom, for which skill, and how much, built from two already-public on-chain sources: agent-to-agent x402 skill payments (`meta.to` payee wallet + `meta.service`) and tips (`meta.from` payer wallet). Every edge is a settled transfer with an explorer-verifiable signature; no inferred or estimated edges exist. Nodes are classified `source` / `hub` / `relay` / `sink` / `quiet` from flow asymmetry, which makes capital dispersion (value entering agent wallets and never circulating out) visible at a glance and puts a number on it as "stuck capital". Counterparty privacy matches the live feed: a wallet is NAMED only when it resolves to a public, non-opted-out agent, otherwise it stays an address-only dashed node. Keyboard and screen-reader parity is structural, not a bolt-on: the table below the canvas renders from the same filtered data and selecting a row selects the node. Docs: [docs/money-flow-map.md](docs/money-flow-map.md). Tests: [tests/flow-map-core.test.js](tests/flow-map-core.test.js) |
| Economy funding root (master wallet) | [api/_lib/economy-master.js](api/_lib/economy-master.js), cron [api/cron/treasury-topup.js](api/cron/treasury-topup.js), registry [api/_lib/solana-signers.js](api/_lib/solana-signers.js) | In-repo (inert until keyed) | One master wallet (`WwwuGbq…T3WwW`, `ECONOMY_MASTER_SECRET_BASE58`) auto-tops-up every other Solana engine below its floor. Funder-only — never trades/settles; reserve/per-engine/per-run guarded; allowlisted to registry wallets; fee-minimized. See [docs/economy-master.md](docs/economy-master.md) + the signer registry [api/_lib/solana-signers.js](api/_lib/solana-signers.js) |
| Economy master audit ledger + breach monitor | ledger [api/_lib/economy-ledger.js](api/_lib/economy-ledger.js) ([schema](api/_lib/migrations/20260702010000_economy_master_ledger.sql)), reconcile cron [api/cron/economy-reconcile.js](api/cron/economy-reconcile.js), export [scripts/economy-ledger-export.mjs](scripts/economy-ledger-export.mjs) | In-repo | Tamper-evident (SHA-256 hash-chained) accounting book of every SOL movement from the master, with running balance + USD-at-transfer-time. The reconcile cron checks it every 30 min for tamper, unrecorded on-chain outbound (breach/key-compromise), and on-chain integrity; findings land in `payment_reconciliation`. Accounting CSV/JSON export. See [docs/economy-master.md](docs/economy-master.md#audit-accounting--breach-monitoring) |
+| Economy wallet registry + rotation | schema [api/_lib/migrations/20260819010000_economy_wallet_registry.sql](api/_lib/migrations/20260819010000_economy_wallet_registry.sql), operator script [scripts/economy-wallets.mjs](scripts/economy-wallets.mjs) (`npm run economy:wallets`), runbook [docs/ops/economy-wallet-rotation.md](docs/ops/economy-wallet-rotation.md) | Live | A durable log of every wallet each economy role has ever held, with lineage between them. [api/_lib/solana-signers.js](api/_lib/solana-signers.js) says what the economy uses now; rotating a signer overwrote an env var and the previous address survived nowhere, so reconciling an old settle meant guessing on-chain. `economy_wallet_registry` keeps one active wallet per role (enforced by a partial unique index, so a half-finished rotation cannot be left behind) plus the full retired history. Generates fresh vanity-prefixed keypairs, writes the secret to a 0600 file outside the repo, and prints the funding and cutover steps; it never stores secret material and never installs a key into production itself. |
| Earned autonomy (sniper fleet) | tier engine [api/_lib/sniper-autonomy.js](api/_lib/sniper-autonomy.js), tier-scaled optimizer [api/_lib/sniper-optimizer.js](api/_lib/sniper-optimizer.js) + cron [api/cron/sniper-optimize.js](api/cron/sniper-optimize.js), tier-weighted portfolio layer [scripts/sniper-evolve.mjs](scripts/sniper-evolve.mjs) + cron [api/cron/sniper-evolve.js](api/cron/sniper-evolve.js), judge knowledge pack [workers/agent-sniper/judge-knowledge.js](workers/agent-sniper/judge-knowledge.js) → [workers/agent-sniper/llm-judge.js](workers/agent-sniper/llm-judge.js), board [api/sniper/experiments.js](api/sniper/experiments.js) + [src/sniper-experiments.js](src/sniper-experiments.js) `→ /sniper/experiments` | Live | A trading arm's own realized record decides how much rope it gets, recomputed every optimizer run: `probation → standard → trusted → autonomous`. The tier scales how far and how fast the optimizer may move a knob, which fields it may touch at all (trusted unlocks the entry universe, the LLM confidence bar, and the take-initials ladder), how much of the fixed fleet budget the evolution loop concentrates on the arm, and how much real evidence the LLM judge is handed before it rules (base rate, learned signal weights, the arm's own record, the realized win-rate table, the model's own calibration). Decided on realized net P&L and average edge, never win rate, so a 36%-hit-rate arm that actually makes money earns room while a 60%-hit-rate arm that loses money does not. Symmetric: an arm that stops paying loses its tier on the next pass. No tier can reach a safety rail (firewall, Mayhem exclusion, price impact, concurrency, loss cap, fleet ceiling) and a bounded stop-loss survives every tier. Tests: [tests/sniper-autonomy.test.js](tests/sniper-autonomy.test.js), [tests/sniper-optimizer.test.js](tests/sniper-optimizer.test.js), [tests/sniper-judge-knowledge.test.js](tests/sniper-judge-knowledge.test.js). See [docs/sniper-autonomy.md](docs/sniper-autonomy.md) |
| Fleet stall diagnosis (why an arm is not trading) | policy [api/_lib/sniper-stall.js](api/_lib/sniper-stall.js), funding invariant [api/_lib/agent-funding-policy.js](api/_lib/agent-funding-policy.js), operational floor `MIN_OPERATIONAL_WALLET_SOL` in [api/_lib/agent-trade-guards.js](api/_lib/agent-trade-guards.js), board field on [api/sniper/experiments.js](api/sniper/experiments.js) + [src/sniper-experiments.js](src/sniper-experiments.js) `→ /sniper/experiments`, ops page [workers/agent-sniper/alerts.js](workers/agent-sniper/alerts.js) | Live | An armed arm can evaluate every launch and still never buy, because a skipped evaluation writes no row: four arms sat dead for a week behind a bare `0`. Each armed strategy now reports a `stall` code the executor actually enforces (`wallet_dry`, `mcap_band_unreachable`, `mcap_band_tight`, `strict_model_offline`, `size_over_budget`, `kill_switch`, `no_qualifying_launch`), and the two arithmetic deadlocks behind them are gone: an entry clamps to the day's remaining budget instead of sitting out when size drifted above the cap, and the reclaim that pulls idle SOL back to the treasury can no longer take a trading wallet below one complete trade or below the level the auto-funder will instantly restore (the two crons were ping-ponging 0.24 SOL six times in 15 minutes). Tests: [tests/sniper-stall.test.js](tests/sniper-stall.test.js), [tests/economy-sweepback.test.js](tests/economy-sweepback.test.js). See [docs/trading-experiment.md](docs/trading-experiment.md), [docs/economy-master.md](docs/economy-master.md) |
| Autonomous trading experiment | policy [scripts/trading-experiment-setup.mjs](scripts/trading-experiment-setup.mjs), laddered exit [workers/agent-sniper/exit-logic.js](workers/agent-sniper/exit-logic.js) (`decideLadderedExit`), no-Mayhem gate [workers/agent-sniper/mayhem-gate.js](workers/agent-sniper/mayhem-gate.js), journal [workers/agent-sniper/journal.js](workers/agent-sniper/journal.js) → [api/sniper/journal.js](api/sniper/journal.js) | In-repo | One agent, ~10 SOL, newer pump.fun launches ($10k–$100k mcap, no Mayhem). Take-initials-at-2× laddered exit keeps a moon bag (never a 100% exit up), hard stop-loss underneath. Every decision journaled with its reasoning. UI-funded, simulate-first. See [docs/trading-experiment.md](docs/trading-experiment.md) |
diff --git a/data/guards.json b/data/guards.json
index cab946798..e17e76209 100644
--- a/data/guards.json
+++ b/data/guards.json
@@ -542,6 +542,29 @@
"expect": "node:util"
}
},
+ {
+ "id": "check-tdz-bootstrap",
+ "script": "scripts/check-tdz-bootstrap.mjs",
+ "npm": "check:tdz-bootstrap",
+ "title": "Bootstrap ordering",
+ "protects": "No page calls its own entry point above the state that entry point writes.",
+ "why": "JavaScriptCore checks an assignment target's temporal dead zone before it evaluates the right-hand side and V8 checks it afterwards, so a module that bootstraps itself above its own `let`s renders correctly in Chrome and throws \"Cannot access uninitialized variable.\" in every Safari. That shipped: each /avatars/:id page was dead on iOS and macOS while review, the page audit and the production smoke sweep all stayed green, because every one of them looks only at V8. A synchronous read of a later-declared binding is worse still and throws everywhere.",
+ "stages": [
+ "gate",
+ "build:gcp"
+ ],
+ "needs": "none",
+ "proof": {
+ "summary": "A page whose top-level bootstrap writes a `let` declared further down the module.",
+ "stage": true,
+ "violation": {
+ "write": {
+ "src/guard-proof-tdz.js": "init().catch(() => {});\n\nasync function init() {\n\tavatar = await Promise.resolve(null);\n}\n\nlet avatar = null;\n"
+ }
+ },
+ "expect": "src/guard-proof-tdz.js"
+ }
+ },
{
"id": "check-dist",
"script": "scripts/check-dist.mjs",
diff --git a/public/guards.json b/public/guards.json
index cab946798..e17e76209 100644
--- a/public/guards.json
+++ b/public/guards.json
@@ -542,6 +542,29 @@
"expect": "node:util"
}
},
+ {
+ "id": "check-tdz-bootstrap",
+ "script": "scripts/check-tdz-bootstrap.mjs",
+ "npm": "check:tdz-bootstrap",
+ "title": "Bootstrap ordering",
+ "protects": "No page calls its own entry point above the state that entry point writes.",
+ "why": "JavaScriptCore checks an assignment target's temporal dead zone before it evaluates the right-hand side and V8 checks it afterwards, so a module that bootstraps itself above its own `let`s renders correctly in Chrome and throws \"Cannot access uninitialized variable.\" in every Safari. That shipped: each /avatars/:id page was dead on iOS and macOS while review, the page audit and the production smoke sweep all stayed green, because every one of them looks only at V8. A synchronous read of a later-declared binding is worse still and throws everywhere.",
+ "stages": [
+ "gate",
+ "build:gcp"
+ ],
+ "needs": "none",
+ "proof": {
+ "summary": "A page whose top-level bootstrap writes a `let` declared further down the module.",
+ "stage": true,
+ "violation": {
+ "write": {
+ "src/guard-proof-tdz.js": "init().catch(() => {});\n\nasync function init() {\n\tavatar = await Promise.resolve(null);\n}\n\nlet avatar = null;\n"
+ }
+ },
+ "expect": "src/guard-proof-tdz.js"
+ }
+ },
{
"id": "check-dist",
"script": "scripts/check-dist.mjs",
diff --git a/src/avatar-page.js b/src/avatar-page.js
index 44a4c276f..98740f43c 100644
--- a/src/avatar-page.js
+++ b/src/avatar-page.js
@@ -77,6 +77,8 @@ if (isEmbed) {
.forEach((el) => { el.style.display = 'none'; });
}
+mountBackLink();
+
// Stop the wallet-aura live poll and free its rAF when the page unloads.
window.addEventListener('pagehide', () => {
netWorthAura?.destroy?.(); netWorthAura = null;
@@ -152,7 +154,6 @@ async function init() {
updateOg();
renderShell(glbUrl);
- mountBackLink();
mountSwitcher();
bindShareButtons();
bindTabs();
@@ -216,6 +217,8 @@ function renderInitFailure(err) {
}
// The action bar's back link points at the directory this entity came from.
+// Called before the entity resolves, because it depends only on the route:
+// an agent page must not spend its loading second offering "Marketplace".
function mountBackLink() {
const back = document.querySelector('.av-back');
if (!back || mode !== 'agent') return;