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(guards): enforce check-rules at push time and wire the dormant auditors into npm

nirholas9a99c0fe667f
diff --git a/.claude/workflows/docs-drift.js b/.claude/workflows/docs-drift.js
index a1589a001..ed47eb7a9 100644
--- a/.claude/workflows/docs-drift.js
+++ b/.claude/workflows/docs-drift.js
@@ -39,7 +39,7 @@ const VERDICT_SCHEMA = {
phase('Scan')
const scan = await agent(
- `In /workspaces/three.ws, find every directory that the CLAUDE.md documentation rules require to have a README.md but that has none (or an empty/stub one). Check: every directory under packages/, every directory under workers/, the SDK dirs (sdk/, solana-agent-sdk/, agent-payments-sdk/), and every surface listed in STRUCTURE.md whose mapped directory lacks a README. Read enough of each candidate's code to write a one-line summary of what it actually does. Exclude node_modules, dist, build output, and scratch dirs. Return the full list.`,
+ `In the repository root (your current working directory), find every directory that the CLAUDE.md documentation rules require to have a README.md but that has none (or an empty/stub one). Check: every directory under packages/, every directory under workers/, the SDK dirs (sdk/, solana-agent-sdk/, agent-payments-sdk/), and every surface listed in STRUCTURE.md whose mapped directory lacks a README. Read enough of each candidate's code to write a one-line summary of what it actually does. Exclude node_modules, dist, build output, and scratch dirs. Return the full list.`,
{ label: 'scan:readme-gaps', schema: SCAN_SCHEMA }
)
@@ -52,11 +52,11 @@ if (scan.missing.length > targets.length) {
const results = await pipeline(
targets,
t => agent(
- `Write a real README.md at /workspaces/three.ws/${t.dir}/README.md for this ${t.kind}: ${t.summary}. Follow the three.ws CLAUDE.md documentation rules exactly: explain what it does and why it exists, how to install/use it, its public API or exports, and ONE runnable example taken from the actual code (verify the entry points and export names by reading the source; never invent an API). Match the tone and structure of neighboring READMEs in the repo. Every link must resolve to a real path. No TODOs, no placeholders, no em-dash or en-dash characters anywhere. Write the file, then return the repo-relative path you wrote.`,
+ `Write a real README.md at ${t.dir}/README.md (repo-relative, from the repository root you are running in) for this ${t.kind}: ${t.summary}. Follow the three.ws CLAUDE.md documentation rules exactly: explain what it does and why it exists, how to install/use it, its public API or exports, and ONE runnable example taken from the actual code (verify the entry points and export names by reading the source; never invent an API). Match the tone and structure of neighboring READMEs in the repo. Every link must resolve to a real path. No TODOs, no placeholders, no em-dash or en-dash characters anywhere. Write the file, then return the repo-relative path you wrote.`,
{ label: `write:${t.dir}`, phase: 'Write' }
),
(written, t) => agent(
- `Adversarially review /workspaces/three.ws/${t.dir}/README.md. Verify against the source code in that directory: (1) every named export/function/endpoint in the doc exists in the code, (2) the example would actually run as written, (3) every relative link resolves to an existing file, (4) no TODO/placeholder text and no em-dash or en-dash characters. Fix small problems directly in the file; report anything you could not fix.`,
+ `Adversarially review ${t.dir}/README.md (repo-relative, from the repository root you are running in). Verify against the source code in that directory: (1) every named export/function/endpoint in the doc exists in the code, (2) the example would actually run as written, (3) every relative link resolves to an existing file, (4) no TODO/placeholder text and no em-dash or en-dash characters. Fix small problems directly in the file; report anything you could not fix.`,
{ label: `verify:${t.dir}`, phase: 'Verify', schema: VERDICT_SCHEMA }
).then(v => ({ dir: t.dir, ...v }))
)
diff --git a/CLAUDE.md b/CLAUDE.md
index ea5fe4e90..29518b62a 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -198,7 +198,7 @@ Three subagents live in `.claude/agents/` and encode checklists you would otherw
This file is the operating brain for every agent here, and agents execute what it says verbatim. A stale line in it does not read as stale, it reads as an instruction, and the cost is a wasted session per drift. Treat it as load-bearing code:
-- **`npm run check:rules` enforces the hard rules on the lines you changed** (`scripts/check-rules.mjs`). It reads added lines only, so your change is held to the rules while the legacy around it is left alone: em-dashes, TODO/FIXME comments, not-implemented throws, commented-out code, and `sampleFoo = [...]` fallback arrays all fail it. Because concurrent agents share this worktree, scope it to your own work: `npm run check:rules -- --paths <files you touched>`. It also reads brand-new untracked files, which a bare `git diff` cannot see.
+- **`npm run check:rules` enforces the hard rules on the lines you changed** (`scripts/check-rules.mjs`). It reads added lines only, so your change is held to the rules while the legacy around it is left alone: em-dashes, TODO/FIXME comments, not-implemented throws, commented-out code, and `sampleFoo = [...]` fallback arrays all fail it. Because concurrent agents share this worktree, scope it to your own work: `npm run check:rules -- --paths <files you touched>`. It also reads brand-new untracked files, which a bare `git diff` cannot see. It is also enforced mechanically at push time: the pre-push hook (installed into `.git/hooks` by `scripts/setup-git-hooks.mjs`, which `postinstall` runs on every `npm install`) runs it with `--base <remote sha> --head <local sha>` per pushed ref, so it judges exactly the commits leaving the machine and never the shared working tree. Emergency bypass: `SKIP_PUSH_CHECKS=1 git push`. The hook deliberately runs ONLY this diff-scoped check, never `npm run gate` or other worktree-state audits, because those would block a requested push on other agents' in-flight work.
- **`npm run check:claude` guards it** (`scripts/check-claude-md.mjs`, wired into `npm run gate`). It re-derives the checkable claims from their source of truth on every run: every npm script and repo path named here must exist, the cron count must match `vercel.json`, the deploy runbook must list the real `build:gcp` chain in the real order, the `db:migrate` warning must match what the script actually does, the README-coverage standard must hold, and the em-dash ban must be honored by this file itself. Run it after editing this file.
- **If you change a load-bearing script, update this file in the same change.** Renaming a script, reordering `build:gcp`, adding a cron, or flipping a default is a documentation change too. The guard will catch most of it; do not make it do your job.
- **Never add a claim here you have not verified.** Numbers, dates, and "X is automatic" statements are the ones that rot. If a claim cannot be checked mechanically, prefer wording that stays true (name the source of truth instead of quoting a number from it).
diff --git a/package.json b/package.json
index b546a3aee..0a2a81f74 100644
--- a/package.json
+++ b/package.json
@@ -102,7 +102,7 @@
]
},
"scripts": {
- "postinstall": "(node scripts/build-cache.mjs check agent-payments-sdk agent-payments-sdk/src agent-payments-sdk/package.json || (npm run build --prefix agent-payments-sdk && node scripts/build-cache.mjs stamp agent-payments-sdk agent-payments-sdk/src agent-payments-sdk/package.json)) && (node scripts/build-cache.mjs check solana-agent-sdk solana-agent-sdk/src solana-agent-sdk/package.json || (npm run build:dist --prefix solana-agent-sdk && node scripts/build-cache.mjs stamp solana-agent-sdk solana-agent-sdk/src solana-agent-sdk/package.json)) && (node scripts/build-cache.mjs check walk-sdk walk-sdk/src walk-sdk/package.json || (npm run build --prefix walk-sdk && node scripts/build-cache.mjs stamp walk-sdk walk-sdk/src walk-sdk/package.json)) && (node scripts/fix-pump-sdk-esm.mjs & node scripts/fix-x402-extensions-esm.mjs & node scripts/fix-zauth-sdk-solana-esm.mjs & node scripts/fix-colyseus-storage.mjs & node scripts/fix-colyseus-send.mjs & node scripts/fix-rapier-init-warning.mjs & node scripts/copy-three-decoders.mjs & node scripts/setup-claude-skills.mjs & wait)",
+ "postinstall": "(node scripts/build-cache.mjs check agent-payments-sdk agent-payments-sdk/src agent-payments-sdk/package.json || (npm run build --prefix agent-payments-sdk && node scripts/build-cache.mjs stamp agent-payments-sdk agent-payments-sdk/src agent-payments-sdk/package.json)) && (node scripts/build-cache.mjs check solana-agent-sdk solana-agent-sdk/src solana-agent-sdk/package.json || (npm run build:dist --prefix solana-agent-sdk && node scripts/build-cache.mjs stamp solana-agent-sdk solana-agent-sdk/src solana-agent-sdk/package.json)) && (node scripts/build-cache.mjs check walk-sdk walk-sdk/src walk-sdk/package.json || (npm run build --prefix walk-sdk && node scripts/build-cache.mjs stamp walk-sdk walk-sdk/src walk-sdk/package.json)) && (node scripts/fix-pump-sdk-esm.mjs & node scripts/fix-x402-extensions-esm.mjs & node scripts/fix-zauth-sdk-solana-esm.mjs & node scripts/fix-colyseus-storage.mjs & node scripts/fix-colyseus-send.mjs & node scripts/fix-rapier-init-warning.mjs & node scripts/copy-three-decoders.mjs & node scripts/setup-claude-skills.mjs & node scripts/setup-git-hooks.mjs & wait)",
"setup": "node scripts/setup-dev.mjs",
"dev": "vite --port 3000",
"dev:multi": "npm run dev --prefix multiplayer",
@@ -149,6 +149,14 @@
"audit:mcp-golden": "node scripts/audit-mcp-golden.mjs",
"audit:hidden-guard": "node scripts/audit-hidden-guard.mjs",
"audit:tokens": "node scripts/audit-token-drift.mjs",
+ "audit:console": "node scripts/audit-console.mjs",
+ "audit:links": "node scripts/audit-links.mjs",
+ "audit:rig-coverage": "node scripts/audit-rig-coverage.mjs",
+ "audit:service-wallets": "node --env-file=.env scripts/audit-service-wallets.mjs",
+ "audit:wallet-flows": "node --env-file=.env scripts/audit-wallet-flows.mjs",
+ "check:cron-drift": "node scripts/check-cron-drift.mjs",
+ "check:erc7710": "node scripts/check-erc7710-addresses.js",
+ "check:relayer-balances": "node scripts/check-relayer-balances.mjs",
"export:examples": "node scripts/export-examples.mjs",
"guard:hidden": "node scripts/inject-hidden-guard.mjs --write",
"check:images": "node scripts/audit-image-loading.mjs --strict",
diff --git a/scripts/check-rules.mjs b/scripts/check-rules.mjs
index c2a7f70f7..b06422028 100644
--- a/scripts/check-rules.mjs
+++ b/scripts/check-rules.mjs
@@ -16,6 +16,7 @@
// node scripts/check-rules.mjs working tree + staged, vs HEAD
// node scripts/check-rules.mjs --staged staged only (pre-commit)
// node scripts/check-rules.mjs --base <ref> everything since <ref> (branch review)
+// node scripts/check-rules.mjs --base <ref> --head <ref> a pushed ref that is not HEAD (pre-push hook)
// node scripts/check-rules.mjs --paths a.js b.js only these files
//
// --paths matters here: concurrent agents share this worktree, so a bare
@@ -33,6 +34,8 @@ const argv = process.argv.slice(2);
const staged = argv.includes('--staged');
const baseIdx = argv.indexOf('--base');
const base = baseIdx === -1 ? null : argv[baseIdx + 1];
+const headIdx = argv.indexOf('--head');
+const head = headIdx === -1 ? 'HEAD' : argv[headIdx + 1];
const pathsIdx = argv.indexOf('--paths');
const paths = pathsIdx === -1 ? [] : argv.slice(pathsIdx + 1).filter((a) => !a.startsWith('--'));
@@ -104,7 +107,7 @@ const RULES = [
];
let diffArgs;
-if (base) diffArgs = ['diff', '--unified=0', `${base}...HEAD`];
+if (base) diffArgs = ['diff', '--unified=0', `${base}...${head}`];
else if (staged) diffArgs = ['diff', '--unified=0', '--staged'];
else diffArgs = ['diff', '--unified=0', 'HEAD'];
if (paths.length) diffArgs = [...diffArgs, '--', ...paths];
diff --git a/scripts/setup-git-hooks.mjs b/scripts/setup-git-hooks.mjs
new file mode 100644
index 000000000..91be3a92b
--- /dev/null
+++ b/scripts/setup-git-hooks.mjs
@@ -0,0 +1,95 @@
+#!/usr/bin/env node
+// Install the repo's pre-push hook into .git/hooks.
+//
+// Why this exists: scripts/check-rules.mjs (the diff-scoped CLAUDE.md hard-rules
+// guard) was enforced by nothing. It existed, it worked, and no mandatory path
+// ran it, so violations shipped anyway. A guard that is not wired into an
+// unavoidable path decays into documentation. The unavoidable path for
+// commit-content rules is pre-push: it sees exactly the commits leaving the
+// machine, after all local churn has settled.
+//
+// Design constraints, in order:
+// 1. Scoped to the push. The hook runs check-rules with --base <remote sha>
+// --head <local sha> per pushed ref, so it judges only the commits being
+// pushed. Concurrent agents' in-flight worktree edits are invisible to it.
+// This is why the hook does NOT run `npm run gate` or working-tree checks:
+// on a worktree shared by several agents those block your push on someone
+// else's red, and the owner's rule is that a requested push executes
+// immediately.
+// 2. Fast. One node process per pushed ref, seconds not minutes.
+// 3. Escapable. SKIP_PUSH_CHECKS=1 git push bypasses it for emergencies.
+// 4. Composes with git-lfs. The stock LFS hook lived here first; ours replays
+// the refs on stdin to `git lfs pre-push` after the rules pass.
+//
+// Runs from postinstall, so every `npm install` (re)installs it. Safe to run
+// anywhere: exits quietly when there is no git repo (tarball installs, CI).
+//
+// Usage: node scripts/setup-git-hooks.mjs
+
+import { execFileSync } from 'node:child_process';
+import { readFileSync, writeFileSync, chmodSync, existsSync } from 'node:fs';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
+const MARKER = 'three.ws pre-push hook v1';
+
+const HOOK = `#!/bin/sh
+# ${MARKER} (installed by scripts/setup-git-hooks.mjs; edits here are overwritten
+# on the next npm install, change the installer instead).
+#
+# Enforces the CLAUDE.md hard rules on the commits being pushed, scoped to
+# exactly those commits (never the shared working tree), then hands the refs to
+# git-lfs. Emergency bypass: SKIP_PUSH_CHECKS=1 git push
+input="$(cat)"
+
+zero=0000000000000000000000000000000000000000
+
+if [ -z "$SKIP_PUSH_CHECKS" ] && command -v node >/dev/null 2>&1; then
+ echo "$input" | {
+ status=0
+ while read -r local_ref local_sha remote_ref remote_sha; do
+ [ -z "$local_ref" ] && continue
+ # Deleting a remote ref pushes no commits.
+ [ "$local_sha" = "$zero" ] && continue
+ # New remote branch or unknown remote tip: no base to diff against.
+ [ "$remote_sha" = "$zero" ] && continue
+ git cat-file -e "$remote_sha" 2>/dev/null || continue
+ node scripts/check-rules.mjs --base "$remote_sha" --head "$local_sha" || { status=1; break; }
+ done
+ exit "$status"
+ } || {
+ echo >&2 ""
+ echo >&2 "pre-push: CLAUDE.md hard-rule violations in the commits being pushed."
+ echo >&2 "pre-push: fix them, or bypass once with: SKIP_PUSH_CHECKS=1 git push"
+ exit 1
+ }
+fi
+
+command -v git-lfs >/dev/null 2>&1 || { printf >&2 "\\n%s\\n\\n" "This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'pre-push' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks')."; exit 2; }
+echo "$input" | git lfs pre-push "$@"
+`;
+
+let hooksDir;
+try {
+ hooksDir = execFileSync('git', ['rev-parse', '--git-path', 'hooks'], { cwd: root, encoding: 'utf8' }).trim();
+} catch {
+ process.exit(0); // not a git repo (tarball install, exported source); nothing to do
+}
+hooksDir = path.resolve(root, hooksDir);
+const hookPath = path.join(hooksDir, 'pre-push');
+
+const existing = existsSync(hookPath) ? readFileSync(hookPath, 'utf8') : '';
+if (existing.includes(MARKER)) {
+ if (existing === HOOK) process.exit(0); // current version already installed
+} else if (existing && !/git lfs pre-push/.test(existing)) {
+ // A hand-written hook we do not recognize. Clobbering it would silently
+ // disable whatever it guards, so refuse and say so.
+ console.error(`[setup-git-hooks] ${hookPath} exists and is not the stock git-lfs hook; not overwriting.`);
+ console.error('[setup-git-hooks] Merge scripts/setup-git-hooks.mjs\'s template into it by hand.');
+ process.exit(1);
+}
+
+writeFileSync(hookPath, HOOK);
+chmodSync(hookPath, 0o755);
+console.log(`[setup-git-hooks] installed pre-push hook at ${path.relative(root, hookPath)}`);