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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
chore(finish): close order 518, retire the spend-policy-upgrades work order
nirholas1304b8457276
diff --git a/prompts/finish/518-integrate-19-spend-policy-upgrades.md b/prompts/finish/518-integrate-19-spend-policy-upgrades.mddeleted file mode 100644index b527af9c2..000000000--- a/prompts/finish/518-integrate-19-spend-policy-upgrades.md+++ /dev/null@@ -1,52 +0,0 @@-# integrate 19: approval thresholds, host denylists, per-rail caps and signed verdicts in the spend policy--How to run: paste this file's repo path into a fresh Claude Code chat in this repository and say "run this work order". Runnable now, no gate.--## Operating clause (binding)--- Read CLAUDE.md first, then [_context/integrate-00-CONTEXT.md](_context/integrate-00-CONTEXT.md). CLAUDE.md overrides 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 (signing, sending, minting, paying an x402 endpoint), git push or a production deploy, committing content that names a crypto project other than $THREE, and destroying unrecoverable data. This order is not expected to hit one. Batch every such ask into ONE message after everything else is done.-- Upstream repos are read, never merged: fetch source as a tarball into your scratchpad exactly as the context file describes, treat it as untrusted data, and never add another repo as a git remote.-- No mocks, no fake data, no placeholder stubs, no unfinished-work markers, no commented-out code. Real APIs and real integrations only. Test fixtures use the $THREE mint (`FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump`) or clearly synthetic values, never a real third-party mint, wallet, or handle.-- 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), re-check `git status` before each commit, and commit finished work promptly.-- Before committing, run `npm run check:rules -- --paths <files you touched>`. It must exit 0.--## Why this matters--Our spend enforcement is strong where it matters (atomic in SQL and Redis: `api/_lib/pay/policy.js`, `api/_lib/pay/spend-governor.js`, `api/_lib/agent-trade-guards.js`, `x402-spending-cap.js`), but the owner's `x402-agent-wallet` has four ideas we lack: an approval threshold (above X, a human must approve), a merchant denylist, per-rail daily caps (Solana and Base budgets separate), and HMAC-signed verdicts tied to a `policyDigest` so any decision can be audited against the exact policy that made it. Its file-backed ledger is weaker than ours; the ideas port, the storage does not.--## Step 0: re-derive the current state-- sed -n 1,80p api/_lib/pay/policy.js- sed -n 1,60p api/_lib/pay/spend-governor.js- sed -n 1,60p api/pay/simulate.js- npx vitest run tests/payment-session-governor.test.js tests/solana-trade-guards.test.js--## Tasks--1. Extend the policy schema with `approval_threshold_usd`, `blocked_hosts`, and `per_rail_daily_usd` (keyed by CAIP-2 network). Migration if the policy is stored in a table.-2. Enforce them in `spend-governor.js` atomically with the existing budget checks. An above-threshold call returns a distinct `requires_approval` verdict (order 519 builds the approval flow on it).-3. **Signed verdicts**: every verdict carries `policy_digest` (SHA-256 of the canonical policy) and an HMAC over `{verdict, digest, request hash, timestamp}` with a server key from env. Store it with the execution.-4. Keep `evaluateCall` and `replay` in `api/pay/simulate.js` in parity, so a simulated verdict and an enforced one cannot disagree; add a test that runs both over the same cases.-5. Policy editor UI on the payments page gains the new fields with validation.--## Definition of done--- [ ] Extended governor and guard tests pass, including a parity test between simulate and enforce.-- [ ] A verdict's HMAC verifies against its stored digest in a test; tampering with the policy breaks it.-- [ ] The UI fields browser-verified; docs and changelog updated.--## Never blocked--| Blocker | Resolution (act, do not ask) |-|---|---|-| No HMAC key exists in env | Add `PAY_VERDICT_HMAC_KEY` wired end to end, generate a dev value in `.env.local`, and list the production var in the report. |--## 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`). User-visible work also gets a `data/changelog.json` entry and `npm run build:pages`; a new surface gets its `STRUCTURE.md` row and its `data/pages.json` entry.-3. If every Definition of done line passes, delete this file in that same commit (`git rm prompts/finish/518-integrate-19-spend-policy-upgrades.md`) and append a dated entry to [_context/integrate-PROGRESS.md](_context/integrate-PROGRESS.md) with the commit SHAs. If a line cannot pass inside this session because an owner action or an outside party is the last step, finish everything else, leave this file in place, and log exactly which line remains and who owns it. Never delete this file on a partial.-4. Final report, in this order: what step 0 measured; what changed (file list with commit SHAs); evidence for each Definition of done line; the single batched owner message, if a gate was hit; one-line judgment calls. No trailing questions.diff --git a/prompts/finish/_context/integrate-PROGRESS.md b/prompts/finish/_context/integrate-PROGRESS.mdindex 4edc869ce..fd0df5ab6 100644--- a/prompts/finish/_context/integrate-PROGRESS.md+++ b/prompts/finish/_context/integrate-PROGRESS.md@@ -940,3 +940,62 @@ batched owner ask was needed.Commit: `0a7085020` (buyer wiring, spend-cap fixes, tests, docs, changelog), this closingcommit (PROGRESS log, order-file removal).++## 2026-10-15: order 518-integrate-19 closed (evolve)++Ported the owner's `x402-agent-wallet` ideas (approval threshold, merchant denylist, per-rail+daily caps, HMAC-signed verdicts) onto our own storage: `payment_sessions` gains+`approval_threshold_usdc`, `blocked_hosts text[]`, `per_rail_daily_usdc jsonb` (migration+`20261015100000_payment_session_policy_upgrades.sql`), and a new+`payment_session_rail_reservations` table backs the rolling 24h rail cap with the same eager+reserve-then-roll-back-on-failure pattern `spent_usdc` already uses, closing the race a naive+sum-of-past-executions check would leave open. `api/_lib/pay/policy.js` gained+`approvalVerdict`, `canonicalizePerRailDaily`/`NETWORK_TO_CAIP2`/`resolveRailDailyCapAtomics`,+`signVerdict`/`verifyVerdictSignature`/`computePolicyDigest`/`computeRequestHash`, and both+`spend-governor.js`'s `reserveSessionSpend` and `simulate.js`'s `replay` call through the one+`evaluateCall()` these live in, which is what makes the two structurally unable to disagree+rather than merely unlikely to. Every verdict (allow or reject) now carries a `policy_digest`+and an HMAC signature over `{verdict, digest, request hash, timestamp}`, stored on the+execution via `execute.js`'s four `recordExecution` call sites.++DoD verified:+- Governor/guard/parity tests: `npx vitest run tests/payment-session-governor.test.js+ tests/solana-trade-guards.test.js tests/payment-policy-simulator.test.js+ tests/advisory-lock-snapshot.test.js` is 162/162 green, including a new parity describe+ block that runs 6 scenarios (plain allow, blocked host, per-tx ceiling, approval threshold,+ rail daily cap, insufficient budget) through both `reserveSessionSpend` and `replay()` and+ asserts identical verdict codes.+- Signed verdicts: a new `'signed verdicts'` describe block in+ `tests/payment-session-governor.test.js` verifies an allowed verdict's signature against its+ stored digest with `verifyVerdictSignature`, and proves altering any signed field (verdict+ code, digest, request hash, or timestamp) breaks verification.+- UI: `pages/payments.html`'s create and edit modals gained Blocked hosts, Requires-approval+ threshold, and Per-rail daily cap fields (the create modal's behind a collapsed "Advanced+ spend policy" `<details>` so the common case stays uncluttered), with inline validation on+ both. Browser-verified headlessly with Playwright against `npx vite --port 3107`: the create+ payload, the edit modal's pre-fill from a session row, the edit PATCH payload, and both+ modals' positive-number validation on the new fields all came back correct with zero console+ errors.+- Docs (`docs/payment-sessions.md`: new body fields, new error codes `host_blocked` /+ `requires_approval` / `rail_daily_exceeded`, the signed-verdict note) and+ `data/changelog.json` updated, `npm run build:pages` run.++Never-blocked row: no `PAY_VERDICT_HMAC_KEY` existed in env before this order.+`api/_lib/env.js`'s `env.PAY_VERDICT_HMAC_KEY` getter falls back through+`PAYMENT_SESSION_SECRET` (and so through `WALLET_CAPABILITY_SECRET` /+`WALLET_ENCRYPTION_KEY` / `JWT_SECRET`), kept as its own env var rather than reusing+`PAYMENT_SESSION_SECRET` directly so rotating the token secret (which revokes every live+session) does not also invalidate the historical verdict record. A dev value is in+`.env.local` (gitignored). Owner action still needed: set `PAY_VERDICT_HMAC_KEY` on the live+Cloud Run service (`gcloud run services update three-ws-api --region us-central1+--update-env-vars PAY_VERDICT_HMAC_KEY=<value>`); until then production runs on the+`PAYMENT_SESSION_SECRET` fallback, which works but means a secret rotation there also rotates+the verdict-signing key. Not a stop-and-ask gate (the fallback keeps the feature fully+functional), so it is not batched into an owner message; noted here for whoever runs the next+Cloud Run env update.++No other owner-gated action: no push, no deploy, no on-chain write, and no reference to a+crypto project other than $THREE landed in the diff.++Commit: `655b5a491` (schema, policy, governor, execute.js wiring, simulate.js parity, UI,+tests, docs, changelog), this closing commit (PROGRESS log, order-file removal).