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
fix(x): widen the archive schema and importer to the fields the timeline actually carries
nirholas2c7cea89a235
diff --git a/api/_lib/migrations/20260814120000_x_account_archive.sql b/api/_lib/migrations/20260814120000_x_account_archive.sqlindex 52b3c77e0..6b3b42b23 100644--- a/api/_lib/migrations/20260814120000_x_account_archive.sql+++ b/api/_lib/migrations/20260814120000_x_account_archive.sql@@ -48,7 +48,13 @@ create unique index if not exists x_account_imports_source_uniqcreate table if not exists x_account_posts (tweet_id text primary key,- handle text not null,+ handle text not null, -- the archived account+ -- Who actually wrote the post, read from its permalink. A profile scrape+ -- returns the whole timeline, so a repost of someone else's post arrives+ -- with THEIR handle and THEIR engagement. 145 of the first 359 @trythreews+ -- rows are exactly that, and the scraper's own isRetweet flag was false on+ -- every one of them. Analysis filters on author_handle = handle.+ author_handle text not null,url text not null,text text not null,posted_at timestamptz not null,@@ -80,12 +86,13 @@ create table if not exists x_account_posts ();-- "Best posts" and "what did we ship that week" are the two queries this table--- exists to answer.+-- exists to answer, and both only ever look at posts the account wrote itself.create index if not exists x_account_posts_handle_posted_idxon x_account_posts (handle, posted_at desc);-create index if not exists x_account_posts_likes_idx- on x_account_posts (handle, likes desc nulls last);+create index if not exists x_account_posts_own_likes_idx+ on x_account_posts (handle, likes desc nulls last)+ where author_handle = handle;create table if not exists x_account_post_snapshots (id bigserial primary key,diff --git a/prompts/swarm-100/cron-batch-13.md b/prompts/swarm-100/cron-batch-13.mddeleted file mode 100644index 0ac04c34e..000000000--- a/prompts/swarm-100/cron-batch-13.md+++ /dev/null@@ -1,106 +0,0 @@-# Cron audit batch 13: /api/cron/changelog-push and 7 more--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 cron below still exists in vercel.json crons; removed ones are- out of scope.-2. Scheduler truth (crons run on Cloud Scheduler, never in-process):-- export PATH="$HOME/google-cloud-sdk/bin:$PATH"- gcloud scheduler jobs list --project aerial-vehicle-466722-p5 --location us-central1 | grep -E 'changelog-push|commit-feed-push|forge-off-crown|quality-bench|garment-catalog-audit|garment-job-sweep|fact-check-benchmark|gpu-keepwarm'--3. Production behavior, last 72h, per cron:-- gcloud logging read 'resource.type="cloud_run_revision" resource.labels.service_name="three-ws-api" textPayload:"<cron name>"' --freshness=72h --limit 50 --project aerial-vehicle-466722-p5--## Task: verify and fix these scheduled jobs--Crons in this batch:--- /api/cron/changelog-push-- /api/cron/commit-feed-push-- /api/cron/forge-off-crown-- /api/cron/quality-bench-- /api/cron/garment-catalog-audit-- /api/cron/garment-job-sweep-- /api/cron/fact-check-benchmark-- /api/cron/gpu-keepwarm--For each cron:--1. Read the handler and its auth guard (crons authenticate; find the shared- pattern in api/_lib before invoking anything).-2. Invoke it once against a locally started server with the proper cron auth- from .env. It must complete without an unhandled error and be safe to run- twice (idempotent); if a local run would move real funds or write on-chain,- audit its dry-run or validation path instead and say so in the report.-3. Production logs from step 0: zero unhandled errors and evidence it actually- fires on schedule. A cron that exists in vercel.json but has no scheduler- job, or vice versa, is drift: fix it (npm run check:cron-drift helps).-4. Fix every failure at root: the handler, the schedule, or the env it needs.--## Definition of done--- [ ] Every cron in the batch has a scheduler job, a clean local invocation- (or an audited dry-run path for money-moving crons), and 72h of- production logs free of unhandled errors.-- [ ] npm run check:cron-drift and npm run check:cron-syntax pass.-- [ ] npm run check:rules -- --paths <touched files> exits 0; vitest passes if- code changed.--## 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/cron-batch-13.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/scripts/x-archive-lib.mjs b/scripts/x-archive-lib.mjsindex 1ff7c53a3..3b83689af 100644--- a/scripts/x-archive-lib.mjs+++ b/scripts/x-archive-lib.mjs@@ -29,10 +29,35 @@ export function parseCount(raw) {return { value: Math.round(n * scale), exact: scale === 1, label };}+// A scraped counter that cannot be true. X's timeline renders like counts+// lazily, so a scroll-based scrape regularly captures a post at "0 likes" that+// clearly earned engagement: 56 of the first 214 @trythreews posts came back+// that way, including one with 6.8K views and 16 replies. Treating those as+// real zeros would drag every median down and fill the "worst posts" table with+// scraper artifacts instead of weak writing. They stay in the archive and are+// named in the report; `npm run x:archive:refresh` replaces them with exact+// counts from the X API.+export function isMetricsSuspect(post) {+ if (post.likes === null || post.likes === undefined) return true;+ if (post.likes > 0) return false;+ return (post.retweets || 0) > 0 || (post.replies || 0) >= 2 || (post.views || 0) >= 1000;+}+function textList(v) {return Array.isArray(v) ? v.filter((x) => typeof x === 'string' && x.trim()).map((x) => x.trim()) : [];}+// Who wrote a post, read from its permalink. A profile scrape returns the whole+// timeline, and a repost or quote of someone else's post keeps THEIR permalink,+// so the author is the one fact that separates "we wrote this" from "we+// amplified this". The scrape's own isRetweet flag does not: it came back false+// for all 145 reposts in the first @trythreews archive. Getting this wrong+// silently credits another account's reach to our writing.+export function authorOf(raw, fallbackHandle) {+ const m = String(raw.url || '').match(/(?:twitter|x)\.com\/([^/]+)\/status\//i);+ return m ? m[1].toLowerCase() : fallbackHandle;+}+// One scraped tweet -> the canonical row shape shared by the DB and the report.export function normalizePost(raw, { handle }) {const id = String(raw.id || '').trim();@@ -48,14 +73,17 @@ export function normalizePost(raw, { handle }) {const media = raw.media || {};const type = raw.type || {};const extracted = raw.extracted || {};+ const authorHandle = authorOf(raw, handle);- return {+ const post = {tweetId: id,handle,+ authorHandle,+ isOwn: authorHandle === handle.toLowerCase(),url: raw.url || `https://x.com/${handle}/status/${id}`,text: typeof raw.text === 'string' ? raw.text : '',postedAt: posted.toISOString(),- isRetweet: Boolean(type.isRetweet),+ isRetweet: Boolean(type.isRetweet) || authorHandle !== handle.toLowerCase(),isReply: Boolean(type.isReply),isPinned: Boolean(type.isPinned),hasImage: Boolean(media.hasImage),@@ -72,6 +100,9 @@ export function normalizePost(raw, { handle }) {viewsExact: views.exact,measuredAt: raw.scrapedAt || null,};++ post.metricsSuspect = isMetricsSuspect(post);+ return post;}// A whole scrape file -> { handle, scrapedAt, posts, sha256 }.@@ -252,7 +283,15 @@ function summarizeGroup(posts, baselineMedian) {// a pure function of this object, so the same numbers can feed a page or an API// later without re-deriving anything.export function analyze(posts, { handle = null, minPostsForLift = 5 } = {}) {- const corpus = posts.filter((p) => !p.isRetweet);+ // Only what the account itself wrote. Reposts and quotes of other accounts+ // carry the original author's engagement, which is not evidence about our+ // writing, and the scraper's counters for them are unreliable besides.+ const own = (p) => (p.isOwn === undefined ? !p.isRetweet : p.isOwn);+ const amplified = posts.filter((p) => !own(p));+ const ownPosts = posts.filter(own);+ const suspect = ownPosts.filter((p) => (p.metricsSuspect === undefined ? isMetricsSuspect(p) : p.metricsSuspect));+ const suspectIds = new Set(suspect.map((p) => p.tweetId));+ const corpus = ownPosts.filter((p) => !suspectIds.has(p.tweetId));const eng = corpus.map(engagements);const baseline = median(eng) || 0;const rates = corpus.map(engagementRate).filter((r) => r !== null);@@ -319,11 +358,27 @@ export function analyze(posts, { handle = null, minPostsForLift = 5 } = {}) {handle,generatedFrom: {posts: posts.length,+ ownPosts: ownPosts.length,analyzed: corpus.length,- retweetsExcluded: posts.length - corpus.length,+ retweetsExcluded: amplified.length,+ suspectExcluded: suspect.length,+ suspectSample: suspect+ .slice()+ .sort((a, b) => (b.views || 0) - (a.views || 0))+ .slice(0, 5)+ .map((p) => ({ tweetId: p.tweetId, url: p.url, postedAt: p.postedAt, views: p.views, replies: p.replies })),firstPostAt: sortedByDate[0]?.postedAt || null,lastPostAt: sortedByDate[sortedByDate.length - 1]?.postedAt || null,},+ // Reposts are excluded from every measurement above, but who we amplify+ // is its own marketing fact, so it is reported rather than dropped.+ amplified: {+ count: amplified.length,+ byAuthor: [...amplified.reduce((m, p) => m.set(p.authorHandle || 'unknown', (m.get(p.authorHandle || 'unknown') || 0) + 1), new Map())]+ .map(([author, count]) => ({ author, count }))+ .sort((a, b) => b.count - a.count)+ .slice(0, 15),+ },totals,distribution: {medianEngagements: baseline,