The core implementation lives in extension/algo.js. It is written as plain JavaScript so the same logic can run in the Chrome extension and in Node tests.
This document is an implementation map. Product-level Top Takes rules live in top_takes.md.
Most algorithm entry points receive:
- tweet id or artifact input
- cache/storage adapter
- X API client
- optional progress callback
- workflow options
The content script extracts tweet ids from the page. The background service worker loads config, creates adapters, and calls into algo.js.
createTweetClient(...) wraps X API requests.
Endpoints used:
GET /2/tweets/{id}for single tweet lookupGET /2/tweetsfor batch tweet lookupGET /2/tweets/search/recentfor conversation/reply collectionGET /2/tweets/search/allwhen available for conversation/reply collectionGET /2/tweets/{id}/quote_tweetsfor Top Takes quote collection
Requested tweet fields include author, conversation, creation time, entities, reply/quote references, public metrics, and text.
Requested user fields include id, username, name, profile image, description, public metrics, and verification metadata.
Rate-limited X requests emit progress and retry when possible.
Primary entry point: resolveRootPath(...).
For each path step:
- Normalize tweet id.
- Read tweet cache.
- Fetch from X only on cache miss.
- Normalize payload.
- Select parent:
- quoted tweet first
- replied-to tweet second
- stop otherwise
- Stop on root or cycle.
- Reverse the raw path to root-to-clicked order.
The quote-first parent rule keeps quote-of-reply chains deterministic.
After the raw path is known:
buildReferenceArtifact(...)canonicalizes external URLs from path tweets.buildPeopleArtifact(...)dedupes authors and mentioned users.collectReplyChainsForAnchorTweets(...)collects local reply pockets where path authors appear.
Reference rules are documented in references.md.
Primary entry point: resolveTopTakes(...).
Implementation stages:
- Read final artifact cache.
- Fetch or cache-hit the source tweet.
- Fetch or cache-hit quote tweets.
- Normalize and dedupe candidates.
- Attach optional top direct replies as context.
- Read OpenAI analysis cache.
- Classify uncached batches with OpenAI.
- Record OpenAI batch timing.
- Add deterministic discourse-quality scores for reasoning density, grounding, and perspective uniqueness.
- Score and select representative quote tweets with a small role/domain coverage bonus.
- Write analysis and artifact caches.
Important helpers:
readQuoteTweetsForSource(...)dedupeQuoteTweets(...)attachTopCommentsToQuoteTweets(...)selectThreadContinuationsForTweet(...)selectQuotesForConversationContext(...)buildTopTakesCandidateBatch(...)normalizeTopTakesClassification(...)groupTopTakes(...)summarizeOpenAiBatchTimings(...)estimateOpenAiRemainingMs(...)
See top_takes.md for candidate rules, ranking formula, objective-ranking constraints, caching, and progress behavior.
Progress events are workflow-specific and should map to visible user stages.
Explore Path emits:
- start
- path walking
- reference canonicalization
- people aggregation
- reply collection
- done
Top Takes emits:
- source/quote cache hit and miss events
- X rate-limit waits
- discourse normalization
- optional reply-context collection
- OpenAI batch start/finish/timing estimates
- grouping and selection
- ready
The content script owns user-facing text for these events.
AriadeX prefers explicit failure over silent invention.
- Missing X token stops X API workflows.
- Missing OpenAI key stops model-backed workflows.
- X
429rate limits retry with visible waits. - Top Takes can continue without reply context when that optional stage remains rate-limited.
- Top Takes can fall back from a disconnected progress port to a normal runtime message.
- Empty or invalid OpenAI output is treated as an error.
Algorithm code should stay testable without Chrome. Chrome-specific behavior belongs in thin content/background adapters and is tested with small mocks.