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.

docs(animations): correct the clip-library count from ~2,000 to the real ~2,900

nirholas1d975e1acfc7
diff --git a/api/sniper/strategy.js b/api/sniper/strategy.js
index 046fdc1e9..70f6f18d7 100644
--- a/api/sniper/strategy.js
+++ b/api/sniper/strategy.js
@@ -50,7 +50,11 @@ const optInt = z.union([z.string(), z.number()]).nullable().optional();
const optLamports = z.union([z.string(), z.number()]).nullable().optional();
-const STRATEGY_SCHEMA = z.object({
+// Exported so tests can pin the accepted field set: zod strips unknown keys, so
+// a knob missing from this schema is silently dropped from every write while the
+// caller still gets a 200. That is exactly how the laddered-exit fields below
+// spent weeks unsettable through the only API that is supposed to set them.
+export const STRATEGY_SCHEMA = z.object({
agent_id: z.string().uuid(),
network: z.enum(['mainnet', 'devnet']).default('mainnet'),
enabled: z.boolean().optional(),
@@ -116,6 +120,11 @@ const STRATEGY_SCHEMA = z.object({
llm_max_confidence: z.union([z.string(), z.number()]).nullable().optional(),
llm_strict_model: z.boolean().optional(),
moonbag_always: z.boolean().optional(),
+ // Laddered take-initials exit. An explicit null on initials_out_multiple opts
+ // back into the classic single-shot exit; moonbag_min_pct is NOT NULL in the
+ // schema, so it clamps rather than clears.
+ initials_out_multiple: z.union([z.string(), z.number()]).nullable().optional(),
+ moonbag_min_pct: z.union([z.string(), z.number()]).optional(),
label: z.string().max(80).nullable().optional(),
experiment_group: z.string().max(80).nullable().optional(),
});
@@ -155,6 +164,13 @@ const clampInt = (v, min, max, def) => {
if (!Number.isFinite(n)) return def;
return Math.min(max, Math.max(min, n));
};
+// Fractional sibling of clampInt, for the knobs that are multiples or percentages
+// rather than counts. Both fall back rather than pass NaN into a numeric column.
+const clampNum = (v, min, max, def) => {
+ const n = Number(v);
+ if (!Number.isFinite(n)) return def;
+ return Math.min(max, Math.max(min, n));
+};
export default wrap(async (req, res) => {
if (cors(req, res, { methods: 'GET,POST,OPTIONS' })) return;
@@ -252,6 +268,11 @@ async function listStrategies(req, res, userId) {
alpha_max_mcap_usd: s.alpha_max_mcap_usd != null ? Number(s.alpha_max_mcap_usd) : null,
alpha_narrative_keywords: s.alpha_narrative_keywords || null,
alpha_min_quality_score: s.alpha_min_quality_score != null ? Number(s.alpha_min_quality_score) : null,
+ // Read-only here (operator-granted, see upsertStrategy), but the dashboard
+ // still has to show whether the treasury is allowed to refill this wallet.
+ auto_fund_enabled: s.auto_fund_enabled ?? false,
+ initials_out_multiple: s.initials_out_multiple != null ? Number(s.initials_out_multiple) : null,
+ moonbag_min_pct: s.moonbag_min_pct != null ? Number(s.moonbag_min_pct) : 15,
decision_mode: s.decision_mode || 'rules',
llm_model: s.llm_model || null,
llm_min_confidence: s.llm_min_confidence != null ? Number(s.llm_min_confidence) : null,
@@ -282,6 +303,14 @@ async function upsertStrategy(req, res, userId) {
if (!(await requireCsrf(req, res, userId))) return;
const body = await readJson(req);
+ // Treasury auto-funding moves SOL from the platform's launcher master into an
+ // agent wallet, so consent for it is granted by an operator against the row
+ // (scripts/seed-sniper-experiments.mjs, scripts/trading-experiment-setup.mjs),
+ // never by the owner of the agent through this endpoint. Say so out loud: a
+ // silently-stripped flag reads as "opted in" to whoever sent it.
+ if (body && typeof body === 'object' && 'auto_fund_enabled' in body) {
+ return error(res, 400, 'bad_request', 'auto_fund_enabled is not settable here: treasury auto-funding is operator-granted');
+ }
const parsed = STRATEGY_SCHEMA.safeParse(body);
if (!parsed.success) {
return error(res, 400, 'bad_request', parsed.error.issues[0]?.message || 'invalid strategy');
@@ -365,17 +394,18 @@ async function upsertStrategy(req, res, userId) {
alpha_max_mcap_usd: 'alpha_max_mcap_usd' in p ? (p.alpha_max_mcap_usd == null ? null : Math.max(0, Number(p.alpha_max_mcap_usd))) : (cur.alpha_max_mcap_usd != null ? Number(cur.alpha_max_mcap_usd) : null),
alpha_narrative_keywords: 'alpha_narrative_keywords' in p ? (Array.isArray(p.alpha_narrative_keywords) ? p.alpha_narrative_keywords.filter(Boolean).slice(0, 10) : null) : (cur.alpha_narrative_keywords || null),
alpha_min_quality_score: 'alpha_min_quality_score' in p ? (p.alpha_min_quality_score == null ? null : Math.min(100, Math.max(0, Math.round(Number(p.alpha_min_quality_score))))) : (cur.alpha_min_quality_score != null ? Number(cur.alpha_min_quality_score) : null),
- // Explicit, off-by-default consent for the auto-funder to top this agent's
- // wallet up from the launcher master. Arming a strategy never moves money
- // on its own — this must be turned on deliberately.
- auto_fund_enabled: 'auto_fund_enabled' in p ? Boolean(p.auto_fund_enabled) : (cur.auto_fund_enabled ?? false),
+ // Off-by-default consent for the auto-funder to top this agent's wallet up
+ // from the launcher master. Arming a strategy never moves money on its own,
+ // and this endpoint never grants the consent either (rejected above): the
+ // write only carries the stored value through the upsert unchanged.
+ auto_fund_enabled: cur.auto_fund_enabled ?? false,
// Laddered take-initials exit (fleet default, owner rule 2026-07-25): at
// initials_out_multiple × entry, sell exactly enough to recover the cost
// basis and let the rest ride behind the trailing stop. New strategies get
// 2× unless the creator sets a value; an explicit null opts back into the
// classic single-shot exit. moonbag_min_pct = the floor always kept.
- initials_out_multiple: 'initials_out_multiple' in p ? (p.initials_out_multiple == null || p.initials_out_multiple === '' ? null : Math.max(1.01, Number(p.initials_out_multiple))) : (cur.initials_out_multiple != null ? Number(cur.initials_out_multiple) : null),
- moonbag_min_pct: 'moonbag_min_pct' in p ? Math.max(0, Math.min(95, Number(p.moonbag_min_pct))) : (cur.moonbag_min_pct != null ? Number(cur.moonbag_min_pct) : 15),
+ initials_out_multiple: 'initials_out_multiple' in p ? (p.initials_out_multiple == null || p.initials_out_multiple === '' ? null : clampNum(p.initials_out_multiple, 1.01, 1000, 2)) : (cur.initials_out_multiple != null ? Number(cur.initials_out_multiple) : null),
+ moonbag_min_pct: 'moonbag_min_pct' in p && p.moonbag_min_pct !== '' ? clampNum(p.moonbag_min_pct, 0, 95, 15) : (cur.moonbag_min_pct != null ? Number(cur.moonbag_min_pct) : 15),
// Experiment identity + decision mode. 'llm' replaces the rule shields with
// a per-launch model verdict; safety rails still hold at executeBuy.
decision_mode: p.decision_mode ?? cur.decision_mode ?? 'rules',
diff --git a/docs/agent-sniper.md b/docs/agent-sniper.md
index c800ee974..dafe6e78a 100644
--- a/docs/agent-sniper.md
+++ b/docs/agent-sniper.md
@@ -117,6 +117,8 @@ The strategy row (`agent_sniper_strategies`, armed via `POST /api/sniper/strateg
| `initials_out_multiple` / `moonbag_min_pct` | The laddered exit: recover cost at N times entry, let the rest ride |
| `kill_switch` / `enabled` | Two independent off switches |
+Every field in that table is settable through `POST /api/sniper/strategy`; an omitted field keeps its stored value, and an explicit `null` clears the ones documented as clearable (`initials_out_multiple` back to the classic single-shot exit, the entry filters back to "no filter"). One column is deliberately not settable there: `auto_fund_enabled`, the consent for the platform's launcher master to top this agent's wallet up, is operator-granted against the row. Sending it in the body returns `400 bad_request` rather than being silently ignored, and `GET /api/sniper/strategy` reports it read-only so a dashboard can still show whether the treasury may refill the wallet.
+
Exit rules are evaluated in a fixed order (stop-loss, signal-flip, trailing-stop, take-profit, timeout) by a pure, unit-tested function (`workers/agent-sniper/exit-logic.js`), so a backtest and the live worker agree on exactly when a position closes.
### The `oracle_crossing` trigger
diff --git a/prompts/swarm-100/api-sniper-02.md b/prompts/swarm-100/api-sniper-02.md
deleted file mode 100644
index 173d6035d..000000000
--- a/prompts/swarm-100/api-sniper-02.md
+++ /dev/null
@@ -1,104 +0,0 @@
-# API audit: api/sniper batch 02 (4 files)
-
-How to run: paste this file's repo path into a fresh Claude Code chat in this
-repository and say "run this work order". This file is fully self-contained:
-it depends on no other prompt file anywhere. If neighboring files in
-prompts/swarm-100/ are gone, that work is done; if present, ignore them.
-Every claim below rots; step 0 re-measures, and what you measure wins.
-
-## Operating clause (binding)
-
-- Read CLAUDE.md first. Its rules override everything, including this file.
-- Finish 100% in this session. Never end the turn with a question, an option
- list, or an unexecuted plan. A judgment call goes in one line of the final
- report; it never becomes a question that halts work.
-- The only permitted stops are the CLAUDE.md stop-and-ask gates: spending real
- funds or any irreversible on-chain write, git push or a production deploy,
- committing content that references a crypto project other than $THREE, and
- destroying unrecoverable data.
-- No mocks, no fake data, no placeholder stubs, no unfinished-work markers, no
- commented-out code. Real APIs and real integrations only.
-- The em-dash and en-dash characters are banned in everything you write.
-- Concurrent agents share this worktree: stage explicit paths only (never a
- bare add-everything), and commit finished work promptly.
-- Before committing, run: npm run check:rules -- --paths <files you touched>.
- It must exit 0.
-
-## Step 0: re-derive the current state
-
-1. Confirm each file below still exists; deleted ones are done, skip them.
-2. For each, decide routability: grep its path in vercel.json and read how
- server/index.mjs maps filesystem handlers. Routed files get an endpoint
- audit; internal modules get a code and test audit.
-3. Start a local server for endpoint checks: node server/index.mjs with .env
- loaded, on a free PORT if 3000 is busy.
-
-## Task: audit these api files, then fix everything found
-
-Files in this batch:
-
-- api/sniper/status.js
-- api/sniper/strategy.js
-- api/sniper/stream.js
-- api/sniper/trader.js
-
-For every routed handler:
-
-1. Exercise it with curl against the local server: the success path returns
- real data with the correct status; malformed input returns a 4xx JSON
- error, never a stack trace or an HTML error page; auth is enforced where
- the code intends it; CORS matches neighboring handlers.
-2. Hard-rule scan: no mock fallbacks, no fake-data arrays, no stubbed
- responses, no unfinished markers. Errors are handled at the boundary and
- internal code trusts itself.
-3. Do not spend funds or sign anything on-chain while probing. Payment and
- trading handlers get their validation and error paths exercised, never a
- live settlement.
-
-For every internal (non-routed) module:
-
-4. Something must import it; if nothing does, delete it as dead code (verify
- with a repo-wide grep first).
-5. Its main path and one failure path must be covered in tests/; add the
- missing test if not.
-
-## Definition of done
-
-- [ ] Every listed file has recorded evidence: a curl transcript for routed
- handlers, a passing test or a deletion for internal modules.
-- [ ] Zero hard-rule violations remain in these files.
-- [ ] vitest run passes; npm run check:rules -- --paths <touched files>
- exits 0.
-
-## Never blocked
-
-| Blocker | Resolution (act, do not ask) |
-|---|---|
-| Missing env var or credential | Check .env and .env.local, then the Cloud Run service env, then Secret Manager (the CLAUDE.md self-unblock playbook has the exact commands). If it truly exists nowhere, wire the code fully behind the env var, prove the wiring with a dry run, and name the single missing var in the report. |
-| gcloud not on PATH | Run: export PATH="$HOME/google-cloud-sdk/bin:$PATH" |
-| Dev server port 3000 busy | Another agent may be serving this repo; probe it and reuse if so. Otherwise start your own on a free port: npx vite --port 3101 |
-| Playwright browser missing | npx playwright install chromium |
-| A surface needs a signed-in user | Register a fresh account through the real /register flow against the real API and use it. Never mock the session. |
-| A defect sits in code you did not touch | Fix it if it blocks a Definition of done line (root cause it, never mask it). Otherwise note it in the report and continue. |
-| An unrelated test is red | Same rule. Never pipe npm test through tail; it masks exit codes. |
-
-## Close out (required)
-
-1. Verify every Definition of done line with the actual command output in
- front of you. Never claim a line you did not verify.
-2. Commit with explicit paths and a subject that describes the diff (house
- style: type(scope): what changed and why a reader cares).
-3. Delete this prompt file in that same commit:
-
- git rm prompts/swarm-100/api-sniper-02.md
-
- The shrinking directory is this campaign's only progress ledger; there is
- no progress log to update.
-4. Final report: what step 0 measured, what changed (file list), evidence per
- Definition of done line, and any one-line judgment calls. No trailing
- questions, no unexecuted plans.
-
-If a line genuinely cannot pass inside this session (an external party must
-respond, or an owner-gated action is the final step), finish everything else,
-leave this file in place, and state exactly which line remains and who owns
-it. Never delete this file on a partial.
diff --git a/tests/sniper-strategy-schema.test.js b/tests/sniper-strategy-schema.test.js
new file mode 100644
index 000000000..598d50800
--- /dev/null
+++ b/tests/sniper-strategy-schema.test.js
@@ -0,0 +1,67 @@
+import { describe, it, expect } from 'vitest';
+import { STRATEGY_SCHEMA } from '../api/sniper/strategy.js';
+
+// POST /api/sniper/strategy parses its body with zod, and zod STRIPS unknown
+// keys. A knob the handler writes but the schema does not declare is therefore
+// dropped in silence: the caller sends it, gets a 200 back, and the stored row
+// keeps its old value. That is what happened to the laddered-exit fields. The
+// 20260725133000 migration documents "setting initials_out_multiple to null
+// through the API" as the opt-out, while the API could not read the field at
+// all. These tests pin the accepted field set so it cannot rot again.
+
+const base = { agent_id: '11111111-1111-4111-8111-111111111111' };
+
+describe('STRATEGY_SCHEMA: laddered exit knobs are settable', () => {
+ it('keeps initials_out_multiple and moonbag_min_pct', () => {
+ const r = STRATEGY_SCHEMA.safeParse({ ...base, initials_out_multiple: 3, moonbag_min_pct: 25 });
+ expect(r.success).toBe(true);
+ expect(r.data.initials_out_multiple).toBe(3);
+ expect(r.data.moonbag_min_pct).toBe(25);
+ });
+
+ it('accepts them as strings, the way an HTML form posts them', () => {
+ const r = STRATEGY_SCHEMA.safeParse({ ...base, initials_out_multiple: '2.5', moonbag_min_pct: '10' });
+ expect(r.success).toBe(true);
+ expect(r.data.initials_out_multiple).toBe('2.5');
+ expect(r.data.moonbag_min_pct).toBe('10');
+ });
+
+ it('carries an explicit null through, so the ladder can be turned off', () => {
+ const r = STRATEGY_SCHEMA.safeParse({ ...base, initials_out_multiple: null });
+ expect(r.success).toBe(true);
+ expect('initials_out_multiple' in r.data).toBe(true);
+ expect(r.data.initials_out_multiple).toBe(null);
+ });
+
+ it('omits an absent knob entirely, which the handler reads as "leave unchanged"', () => {
+ const r = STRATEGY_SCHEMA.safeParse(base);
+ expect(r.success).toBe(true);
+ expect('initials_out_multiple' in r.data).toBe(false);
+ expect('moonbag_min_pct' in r.data).toBe(false);
+ });
+});
+
+describe('STRATEGY_SCHEMA: the boundary', () => {
+ it('strips auto_fund_enabled, which is why the handler rejects it before parsing', () => {
+ // Treasury auto-funding is operator-granted. The schema dropping it is the
+ // safe outcome; the handler 400s on it so the caller is never told a
+ // consent flag landed when it did not.
+ const r = STRATEGY_SCHEMA.safeParse({ ...base, auto_fund_enabled: true });
+ expect(r.success).toBe(true);
+ expect('auto_fund_enabled' in r.data).toBe(false);
+ });
+
+ it('rejects a body with no agent_id', () => {
+ expect(STRATEGY_SCHEMA.safeParse({}).success).toBe(false);
+ });
+
+ it('rejects an unknown trigger', () => {
+ const r = STRATEGY_SCHEMA.safeParse({ ...base, trigger: 'rugpull' });
+ expect(r.success).toBe(false);
+ expect(r.error.issues[0].path).toEqual(['trigger']);
+ });
+
+ it('rejects a non-numeric telegram chat id', () => {
+ expect(STRATEGY_SCHEMA.safeParse({ ...base, telegram_chat_id: 'not-a-number' }).success).toBe(false);
+ });
+});