[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6CZ7HFKP8VPSB6J07YN4WCR":3,"skill-same:01M6CZ7HFKP8VPSB6J07YN4WCR":77},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":23,"publishedAt":42,"linkOnly":43,"markdownContent":44,"markdownBody":45,"frontMatter":46,"refName":54,"commitSha":55,"skillDirectory":56,"forksCount":57,"repositoryHtmlUrl":58,"repositoryHomepageUrl":59,"ownerHtmlUrl":60,"ownerBlogUrl":59,"ownerDescription":61,"updatedAt":62,"install":63,"resources":76},"01M6CZ7HFKP8VPSB6J07YN4WCR","fetch-tweets",null,"Search and curate X\u002FTwitter behind one selector - keyword, topic roundup, a single or tracked-account digest, an X list, or the AI-agent buzz preset - clustered into signal-scored sub-narratives.","aeonfun\u002Faeon","aeonfun","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F287715280?v=4","01M6CZ23C6MXGMF4N0V1DZ1247","aeon","01M6CZ23GMZP1BR424J8Y8K3DG",793,"MIT","https:\u002F\u002Fgithub.com\u002Faeonfun\u002Faeon\u002Fblob\u002Fmain\u002Fskills\u002Ffetch-tweets\u002FSKILL.md",[18],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发","SCENARIO","使用场景",[24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41],"fetch tweets","fetch","basics","single","signal","selector","buzz","digest","social","ai-agent","preset","curate","list","twitter","xai","api","roundup","search","2026-11-10 10:12:30",false,"---\nname: fetch-tweets\ndescription: Search and curate X\u002FTwitter behind one selector - keyword, topic roundup, a single or tracked-account digest, an X list, or the AI-agent buzz preset - clustered into signal-scored sub-narratives.\nmetadata:\n  title: Fetch Tweets\n  category: basics\n  var: \"\"\n  tags:\n    - social\n  requires:\n    - TWITTER_API_KEY\n    - XAI_API_KEY?\n---\n\u003C!-- autoresearch: variation B — sharper output via clustering + signal scoring + insight extraction. Merged HUB: absorbs tweet-digest, tweet-roundup, list-digest, refresh-x, agent-buzz behind a `source:` selector. -->\n> **${var}** — `\u003Csource>:\u003Carg>` where `\u003Csource>` ∈ `keyword | topic | account | list | agent-buzz`. The `\u003Carg>` is source-specific (a query, a topic, a handle, comma-separated list IDs, or an optional focus). If no `source:` prefix is given, the source is inferred from the shape of `\u003Carg>` (see **Source selector**). **Required** for `keyword` and `list`; optional for `topic`, `account`, and `agent-buzz`.\n\nToday is ${today}. This skill fetches X\u002FTwitter content along one of five **source axes** and produces a *curated* digest — clustered by sub-narrative, ranked by signal, one insight per item — never a flat chronological dump.\n\n## Source selector\n\nParse `${var}` into `SOURCE` and `ARG` before doing anything else.\n\n**Explicit form (recommended):** `\u003Csource>:\u003Carg>`\n- `keyword:$SOL OR solana OR \"solana network\"` - raw X search query, passed to the search **verbatim** (OR\u002FAND honored; twitterapi advanced_search primary, Grok x_search fallback).\n- `topic:brain-computer interfaces` — a single topic roundup. `topic:` (empty arg) → resolve a topic **list** from MEMORY.md, then built-in defaults.\n- `account:vitalikbuterin` — one account's recent tweets. `account:` (empty arg) → digest **every** handle in `memory\u002Ftopics\u002Ftracked-accounts.yml`.\n- `list:1953536336675365173,1937207796270829766` — one or more numeric X list IDs. Append `|\u003Ctopic>` for a topic booster: `list:195...,193...|AI agents`.\n- `agent-buzz` — the curated AI-agent-ecosystem preset. `agent-buzz:MCP protocol` prioritizes a project\u002Ftopic within the preset.\n\n**Implicit form (back-compat with migrated bare-var configs):** when `${var}` has **no** recognized `source:` prefix, infer `SOURCE` in this order:\n1. `${var}` is empty → `topic` (default multi-topic roundup).\n2. `${var}` is all-digits, or comma-separated all-digits (optionally with a `|\u003Ctopic>` suffix) → `list`.\n3. `${var}` is `@handle` or matches `^[A-Za-z0-9_]{1,15}$` (a bare handle) → `account`.\n4. Anything else → `keyword`.\n\nNote: `agent-buzz` has **no** distinct implicit shape (its arg looks like a keyword\u002Ftopic), so it is **only** selectable via the explicit `agent-buzz` \u002F `agent-buzz:...` prefix.\n\nOnce `SOURCE` and `ARG` are set, jump to the matching branch below. Only one branch runs per invocation.\n\n## Shared preamble (all branches)\n\n1. Read `memory\u002FMEMORY.md` for context and the recent `memory\u002Flogs\u002F` (each branch specifies its lookback window — 2 or 3 days) to dedup already-reported tweets.\n2. **Load the dedup set `SEEN_TWEETS`** by unioning two sources:\n   - The branch's **persistent seen-file** (per-mode path below), if it exists — read all URLs.\n   - The branch's **log lookback window** — grep each `memory\u002Flogs\u002F*.md` file in range for lines matching `https:\u002F\u002Fx.com\u002F`.\n\n   Per-mode seen-files (kept at their legacy paths so dedup history survives the merge):\n   | mode | seen-file | log lookback |\n   |---|---|---|\n   | keyword | `memory\u002Ffetch-tweets-seen.txt` | 3 days |\n   | topic | `memory\u002Ftweet-roundup-seen.txt` | 3 days |\n   | account | *(logs only — see branch)* | 2 days |\n   | list | `memory\u002Flist-digest-seen.txt` | 2 days |\n   | agent-buzz | *(logs only — 3-day `status\u002F\u003Cid>` set)* | 3 days |\n3. Formatting invariants shared by **every** branch's notification:\n   - Use `x.com\u002Fhandle` (**never** `@handle`) so Telegram doesn't ping\u002Ftag users. *(Exception: the account-digest and agent-buzz formats below historically use `@handle` in-body; keep their documented format but prefer `x.com\u002Fhandle` when practical.)*\n   - Every surviving tweet gets a tappable Markdown link — `[View](url)` \u002F `[View tweet](url)`. If a URL is unavailable, drop the link and say \"(link unavailable)\".\n   - Never fabricate engagement counts. Missing → `0`, not a guess.\n   - **Notify only on signal.** A legitimately empty or all-duplicate run logs its status and sends **nothing**.\n\n## Voice\n\nUsed by the `account` and `agent-buzz` branches for one-line takes\u002Finsights. If `soul\u002FSOUL.md` and `soul\u002FSTYLE.md` are populated, read both and match the operator's voice. If they are empty templates or absent, write in a clear, direct, neutral tone — state what the tweet says, no hedging or editorializing beyond the tweet itself.\n\n---\n\n## Branch: keyword (`source:keyword`)\n\nSearch X for tweets matching `ARG` and produce a curated digest grouped by sub-narrative.\n\n**Seen set:** `memory\u002Ffetch-tweets-seen.txt` + last 3 days of logs (loaded in preamble).\n\n1. **Build the search prompt.** Pass `ARG` to Grok **verbatim** as the query — do NOT narrow it to a single angle; broad coverage is the goal. Ask for **at least 15–20 candidate tweets** (you'll cull to ~7–10). Always require explicit engagement counts (likes, retweets, replies) so ranking is data-driven.\n\n2. **Fetch tweets.** Record `SOURCE_PATH=twitterapi|api|websearch` for the log.\n\n   Get the window dates first, each `date` as its own Bash call (see **Shell shape** below):\n   ```bash\n   date -u -d yesterday +%Y-%m-%d\n   ```\n   ```bash\n   date -u +%Y-%m-%d\n   ```\n   The first prints FROM_DATE, the second TO_DATE.\n\n   **Path A - twitterapi.io (primary; see the **Fetching (all branches)** contract):** structured X search, no prompt. Put the date window inside the query with `since:`. Pass `ARG` as the query **verbatim** (OR\u002FAND honored) plus `since:\u003CFROM_DATE>`, both written in literally:\n   ```bash\n   .\u002Fsecretcurl -s -o \u002Ftmp\u002Ftw-keyword.json -w 'twitterapi http=%{http_code} bytes=%{size_download}\\n' --max-time 60 -G \"https:\u002F\u002Fapi.twitterapi.io\u002Ftwitter\u002Ftweet\u002Fadvanced_search\" \\\n     --data-urlencode \"query=\u003CARG> since:\u003CFROM_DATE>\" --data-urlencode \"queryType=Latest\" \\\n     -H \"X-API-Key: {TWITTER_API_KEY}\"\n   ```\n   On `HTTP=200` with a non-empty `.tweets[]`, parse and mark `SOURCE_PATH=twitterapi`:\n   ```bash\n   jq -r '.tweets[] | [.id, .author.userName, .text, .url, .createdAt, .likeCount, .retweetCount, .replyCount] | @tsv' \u002Ftmp\u002Ftw-keyword.json\n   ```\n   Paginate with `&cursor=\u003Cnext_cursor>` (from `.next_cursor` while `.has_next_page`) only if you need more than the first page to reach ~15-20 candidates. Engagement counts are exact ground-truth; permalinks are the real `.url`.\n\n   **Path B - xAI Grok x_search (fallback)** (only if Path A returned non-2xx \u002F empty \u002F timeout, or `TWITTER_API_KEY` is unset; see the contract - set the Bash tool `timeout` >=180000, capture the HTTP status):\n   ```bash\n   jq -n '{model:\"grok-4.7\", input:[{role:\"user\",content:\"Search X for tweets about: \u003CARG>. Date range: \u003CFROM_DATE> to \u003CTO_DATE>. Return at least 15-20 candidate tweets - mix of high-engagement posts and smaller accounts that add a distinct angle. For each tweet include: @handle, the full text, date posted, exact engagement counts (likes, retweets, replies - never N\u002FA; if unknown, say 0), and the direct link (https:\u002F\u002Fx.com\u002Fhandle\u002Fstatus\u002FID). Return as a numbered list.\"}], tools:[{type:\"x_search\"}]}' \\\n     | .\u002Fsecretcurl -s -o \u002Ftmp\u002Fxai.json -w '%{http_code}' --max-time 150 -X POST \"https:\u002F\u002Fapi.x.ai\u002Fv1\u002Fresponses\" \\\n     -H \"Content-Type: application\u002Fjson\" \\\n     -H \"Authorization: Bearer {XAI_API_KEY}\" \\\n     --data-binary @-\n   ```\n   On `HTTP=200`, parse `\u002Ftmp\u002Fxai.json` with: `jq -r '.output[] | select(.type == \"message\") | .content[] | select(.type == \"output_text\") | .text'` and mark `SOURCE_PATH=api`.\n\n   **Path C - WebSearch (last resort)** (only if Paths A and B both gave a non-2xx \u002F empty \u002F timeout, or no key is set): use the built-in WebSearch tool with `site:x.com \"\u003Cquery terms>\" after:${FROM_DATE}`. Note at the top of the log the **true reason** (`http-\u003Ccode>` \u002F `timeout` \u002F `empty`, never \"unavailable\" when a key was set) and \"results compiled via WebSearch - quality lower than usual\". WebSearch favours high-engagement older tweets - **prioritise results dated within the last 48 hours**. Mark `SOURCE_PATH=websearch`.\n\n3. **Empty vs. error handling** (distinguish):\n   - **Legitimate empty** (0 tweets): log `FETCH_TWEETS_EMPTY (source=${SOURCE_PATH})` and **stop — no notification**.\n   - **API\u002Fcache error** (HTTP error, malformed JSON, all paths failed): log `FETCH_TWEETS_ERROR (last_path=${SOURCE_PATH}, reason=...)` and **stop — no notification**.\n\n4. **Deduplicate** each candidate URL against `SEEN_TWEETS`. If ALL are dupes: log `FETCH_TWEETS_NO_NEW: all results already reported` and **stop — no notification**.\n\n5. **Curate** (the core step):\n   a. **Cluster** survivors into 2–4 sub-narratives by what they're claiming\u002Fdiscussing (e.g. for a token: \"price action\", \"team announcement\", \"criticism\u002FFUD\", \"ecosystem integration\"). Name the *angle*, not the topic.\n   b. **Rank within each cluster by signal** (not raw engagement): `signal = likes + 2×retweets + replies`, but **demote** pure replies, generic shilling, and near-duplicate paraphrases. Drop tweets with \u003C5 total engagement unless they add a unique angle.\n   c. **Cap each cluster at 2–3 tweets, total 7–10.** Quality over quantity — if only 5 pass, send 5. Don't pad.\n   d. **Extract the claim\u002Fsignal** per tweet — *what's new or interesting*, not a literal paraphrase. Bad: \"User says token is going up.\" Good: \"Calls out the team's silence on the postponed unlock — first major holder to do so publicly.\"\n   e. **Compute a one-line signal** for the top of the notification — one observation about the *shape* of the conversation (e.g. \"Sentiment split — 4 bullish on the launch, 3 critical of the unlock terms.\").\n\n6. **Save + update seen-file** (see Log). Append each kept tweet URL (one per line) to `memory\u002Ffetch-tweets-seen.txt` (create if missing).\n\n7. **Notify via `.\u002Fnotify`** with the clustered output:\n   ```\n   *Top Tweets - ${ARG} (${today})*\n   _${signal_one_liner}_\n\n   *${cluster_1_name}*\n   1. x.com\u002Fhandle - [insight summary]\n   Likes: X | RTs: Y | Replies: Z\n   [View tweet](https:\u002F\u002Fx.com\u002Fhandle\u002Fstatus\u002FID)\n\n   2. x.com\u002Fhandle - [insight summary]\n   Likes: X | RTs: Y | Replies: Z\n   [View tweet](https:\u002F\u002Fx.com\u002Fhandle\u002Fstatus\u002FID)\n\n   *${cluster_2_name}*\n   3. x.com\u002Fhandle - [insight summary]\n   ...\n   ```\n   The signal one-liner is italic (`_..._`) directly under the title; cluster headers are `*bold*`.\n\n**Status codes:** `FETCH_TWEETS_OK` (notified) | `FETCH_TWEETS_EMPTY` | `FETCH_TWEETS_ERROR` | `FETCH_TWEETS_NO_NEW`.\n\n---\n\n## Branch: topic (`source:topic`)\n\nGist of the latest X chatter on one or more configurable topics.\n\n**Seen set:** `memory\u002Ftweet-roundup-seen.txt` + last 3 days of logs.\n\n1. **Resolve the topic list** (priority order):\n   1. `ARG` set → `TOPICS=(\"$ARG\")` (single-topic mode).\n   2. Else if MEMORY.md has a `## Tweet Roundup Topics` section → use its bulleted lines, one query per line.\n   3. Else built-in defaults:\n      - `artificial intelligence OR AI agents OR LLM`\n      - `crypto OR bitcoin OR DeFi`\n      - `technology OR startups OR open source`\n\n2. **Fetch per topic** - track `SOURCE ∈ {twitterapi, api, websearch, failed}` per topic.\n\n   Get the window dates first, each `date` as its own Bash call (see **Shell shape** below):\n   ```bash\n   date -u -d yesterday +%Y-%m-%d\n   ```\n   ```bash\n   date -u +%Y-%m-%d\n   ```\n   The first prints FROM_DATE, the second TO_DATE.\n\n   **Path A - twitterapi.io (primary):** for each topic, one call with the topic as the query and the window inside it via `since:`, both written in literally:\n   ```bash\n   .\u002Fsecretcurl -s -o \u002Ftmp\u002Ftw-topic.json -w 'twitterapi http=%{http_code} bytes=%{size_download}\\n' --max-time 60 -G \"https:\u002F\u002Fapi.twitterapi.io\u002Ftwitter\u002Ftweet\u002Fadvanced_search\" \\\n     --data-urlencode \"query=\u003CTOPIC> since:\u003CFROM_DATE>\" --data-urlencode \"queryType=Latest\" \\\n     -H \"X-API-Key: {TWITTER_API_KEY}\"\n   ```\n   On `HTTP=200` with a non-empty `.tweets[]`, parse and mark `SOURCE=twitterapi`. Extract each tweet's handle (`.author.userName`), text, engagement counts (`.likeCount`\u002F`.retweetCount`\u002F`.replyCount`), and permalink (`.url`); take up to the first 8 substantive tweets:\n   ```bash\n   jq -r '.tweets[] | [.id, .author.userName, .text, .url, .createdAt, .likeCount, .retweetCount, .replyCount] | @tsv' \u002Ftmp\u002Ftw-topic.json\n   ```\n\n   **Path B - xAI Grok x_search (fallback)** (only if Path A returned non-2xx \u002F empty \u002F timeout, or `TWITTER_API_KEY` unset): for each topic, call Grok's `x_search`.\n   ```bash\n   jq -n '{model:\"grok-4.7\", input:[{role:\"user\",content:\"Search X for recent tweets about: \u003CTOPIC>. Date range: \u003CFROM_DATE> to \u003CTO_DATE>. Return up to 8 substantive tweets. For each: @handle, full text, date, exact engagement counts (likes, retweets, replies; 0 if unknown), and the direct link https:\u002F\u002Fx.com\u002Fhandle\u002Fstatus\u002FID.\"}], tools:[{type:\"x_search\"}]}' \\\n     | .\u002Fsecretcurl -s -o \u002Ftmp\u002Fxai-topic-out.json -X POST \"https:\u002F\u002Fapi.x.ai\u002Fv1\u002Fresponses\" \\\n     -H \"Content-Type: application\u002Fjson\" \\\n     -H \"Authorization: Bearer {XAI_API_KEY}\" \\\n     --data-binary @-\n   ```\n   Parse with the standard `jq` extractor. If it yields text, `SOURCE=api`. Extract each tweet's `@handle`, text, engagement counts, and permalink.\n\n   **Path C - WebSearch (last resort)** (only if Paths A and B both error\u002Fempty, or no key set): `site:x.com \"\u003Ctopic keywords>\" after:\u003CYESTERDAY>`. Always include the word \"today\" and `${today}` to force fresh results. Discard any result whose visible date is older than 48h. Collect up to 5 candidates per topic. Mark `SOURCE=websearch`. If all paths return nothing, mark `SOURCE=failed`.\n\n3. **Score and filter.** Require: a known `@handle`; a `https:\u002F\u002Fx.com\u002F\u003Chandle>\u002Fstatus\u002F\u003Cid>` URL (if missing, keep but mark \"link unavailable\"); posted within 48h; URL **not** in `SEEN_TWEETS`. Compute `signal_score = likes + 2×retweets + replies` (on WebSearch path with no counts, use result rank as a weak proxy). **Demote −50%**: replies to a parent tweet; near-duplicates of a higher-scoring tweet (>70% text overlap or same linked URL).\n\n4. **Curate per topic:**\n   - **0 survivors** → drop the topic. Do NOT pad.\n   - **1–3 survivors** → list ranked by `signal_score`, highest first.\n   - **4+ survivors** → group into 2–3 sub-narratives (shared keywords\u002Fentity\u002Fclaim); label each, surface the top-1 tweet per narrative as exemplar.\n   Write an **insight** per reported tweet (what it asserts\u002Freveals, not a headline paraphrase). Write a one-line **conversation shape** per topic (\"bullish momentum, dissenters quiet\", \"split opinion on X's launch\", \"single story dominating — Y\").\n\n5. **Notify.** If every topic dropped: log `TWEET_ROUNDUP_EMPTY` and **stop — no notify**. Otherwise send via `.\u002Fnotify` (≤4000 chars):\n   ```\n   *Tweet Roundup - ${today}*\n   _Source: api:X websearch:Y failed:Z_\n\n   *[Topic 1]* - _conversation shape_\n   - x.com\u002Fhandle - insight (signal: 12.3k) [View](https:\u002F\u002Fx.com\u002Fhandle\u002Fstatus\u002FID)\n   - x.com\u002Fhandle - insight (signal: 4.1k) [View](https:\u002F\u002Fx.com\u002Fhandle\u002Fstatus\u002FID)\n\n   *[Topic 2]* - _conversation shape_\n   - x.com\u002Fhandle - insight (signal: 8k) [View](https:\u002F\u002Fx.com\u002Fhandle\u002Fstatus\u002FID)\n   ```\n   Show `signal: \u003Cscore>` only when engagement counts were available (api path); omit silently on WebSearch.\n\n6. **Persist + log** (see Log). Append each reported URL (one per line) to `memory\u002Ftweet-roundup-seen.txt` (create if missing).\n\n**Constraints:** never notify an empty roundup (silence beats filler); never `@handle` anyone; never report a URL already in `SEEN_TWEETS`. **Status codes:** `TWEET_ROUNDUP_OK` | `TWEET_ROUNDUP_EMPTY`.\n\n---\n\n## Branch: account (`source:account`)\n\nTwo sub-modes: **single handle** (decision-ready gist of one account) vs. **all tracked accounts** (theme-grouped digest of a watchlist). Choose by `ARG`.\n\n**Seen set:** last 2 days of logs — extract every `https:\u002F\u002Fx.com\u002F` URL under a prior `### fetch-tweets` account entry into `SEEN_URLS`.\n\n### account — single handle (`ARG` is one @handle)\n\n1. **Normalize `ARG`.** Strip leading `@`, `https:\u002F\u002Fx.com\u002F`, `https:\u002F\u002Ftwitter.com\u002F`, `https:\u002F\u002Fnitter.net\u002F`, trailing slash \u002F `\u002Fstatus\u002F...`. Lowercase. Reject if empty, contains whitespace, or >15 chars. On reject → `REFRESH_X_NO_VAR`: send `.\u002Fnotify \"fetch-tweets: REFRESH_X_NO_VAR — set an X handle\"` and exit 0. Store the cleaned handle as `ACCOUNT`.\n\n2. **Load tweets:**\n   - **Path A - twitterapi.io (primary):** pull this account's recent timeline directly, then filter to the last 2 days client-side (no server-side date filter on this endpoint):\n     First `date -u -d '2 days ago' +%Y-%m-%d` as its own call (prints FROM_2D), then one call with the handle written in literally:\n     ```bash\n     .\u002Fsecretcurl -s -o \u002Ftmp\u002Ftw-account.json -w 'twitterapi http=%{http_code} bytes=%{size_download}\\n' --max-time 60 -G \"https:\u002F\u002Fapi.twitterapi.io\u002Ftwitter\u002Fuser\u002Flast_tweets\" \\\n       --data-urlencode \"userName=\u003CACCOUNT>\" -H \"X-API-Key: {TWITTER_API_KEY}\"\n     ```\n     On `HTTP=200` with a non-empty `.data.tweets[]`, parse and mark `source=twitterapi`. Filter on `.createdAt` (drop tweets older than the window) and use `.isReply` to tag reply vs original (this endpoint has no quote flag - treat non-reply as original; if you need reliable quote detection fall back to Path B). One `jq` per call, FROM_2D written in literally:\n     ```bash\n     jq -r '.data.tweets[] | select((try (.createdAt | strptime(\"%a %b %d %H:%M:%S %z %Y\") | strftime(\"%Y-%m-%d\")) catch \"0000-00-00\") >= \"\u003CFROM_2D>\") | [.id, .author.userName, .text, .url, .createdAt, .likeCount, .retweetCount, .replyCount, .isReply] | @tsv' \u002Ftmp\u002Ftw-account.json\n     ```\n   - **Path B - xAI Grok x_search (fallback)** (only if Path A returned non-2xx \u002F empty \u002F timeout, or `TWITTER_API_KEY` unset): search this account's recent tweets via Grok's `x_search`.\n     ```bash\n     jq -n '{model:\"grok-4.7\", input:[{role:\"user\",content:\"Search X for the latest tweets, replies, and quote tweets from @\u003CACCOUNT> in the last 2 days. Return each with full text, timestamp, type (original|reply|quote), what it replies to\u002Fquotes if any, exact engagement counts (likes, retweets, replies; 0 if unknown), and the permalink https:\u002F\u002Fx.com\u002F\u003CACCOUNT>\u002Fstatus\u002FID. Skip retweets of others. Return chronological.\"}], tools:[{type:\"x_search\"}]}' \\\n       | .\u002Fsecretcurl -m 30 -s -o \u002Ftmp\u002Fxai-account-out.json -X POST \"https:\u002F\u002Fapi.x.ai\u002Fv1\u002Fresponses\" \\\n       -H \"Content-Type: application\u002Fjson\" \\\n       -H \"Authorization: Bearer {XAI_API_KEY}\" \\\n       --data-binary @-\n     ```\n     Parse with the standard `jq` extractor. Record `source=api`.\n   - **Path C - WebFetch (last resort)** (only if Paths A and B both failed \u002F returned nothing): WebFetch `https:\u002F\u002Fx.com\u002F${ACCOUNT}` with prompt: *\"List every tweet, reply, and quote tweet visible on this profile with its full text, timestamp, engagement counts (likes\u002Fretweets\u002Freplies) if shown, and the permalink https:\u002F\u002Fx.com\u002Fhandle\u002Fstatus\u002FID. Return a chronological list.\"* Record `source=webfetch`.\n   - **Degraded**: if no key is set and WebFetch returns nothing → skip to step 8 with status `REFRESH_X_NO_API_KEY` (no key present) or `REFRESH_X_ERROR` (a key was set but all paths failed).\n\n3. **Parse into structured tweets:** `url`, `text`, `timestamp`, `type` (original\u002Freply\u002Fquote), `reply_to`, `quoted_text`, `likes`, `retweets`, `replies`. Drop retweets of others. Missing counts → 0. Compute `signal_score = likes + 2*retweets + replies − (3 if type=reply else 0)`.\n\n4. **Dedup and gate:** drop any tweet whose `url` is in `SEEN_URLS` (`deduped_count`). If fewer than 3 tweets survive AND no thread is detectable (step 5) → skip to step 8 with `REFRESH_X_NO_NEW` (everything deduped) or `REFRESH_X_EMPTY` (account posted nothing).\n\n5. **Detect threads:** a thread = 2+ tweets by `ACCOUNT` within 30 minutes where later tweets reply to earlier ones OR share ≥2 meaningful keywords with the opener. Thread tweets are atomic units regardless of individual score. Record `{opener_url, tweet_count, combined_signal}`.\n\n6. **Cluster and extract insights:** group survivors (threads = one unit) into **2–4 sub-narratives** by topic overlap; if \u003C2 emerge, use one cluster. Per cluster: **Title** (3–8 words), **Top tweet(s)** (1–3 excerpts ≤200 chars each, with permalink + engagement), **Insight** (one sentence — what the cluster reveals about the author's stance\u002Fclaim\u002Fshift; not a paraphrase — if you can't beat paraphrase, drop the cluster). Per thread: a 1–2 sentence landing summary + opener URL.\n\n7. **Write the verdict** (pick exactly one) + a ≤20-word lede:\n   | Verdict | When |\n   |---|---|\n   | `ANNOUNCEMENT` | launch, hire, policy, or product drop |\n   | `ARGUMENT` | majority signal from contrarian takes or fights |\n   | `BUILDING` | ships\u002Fcode\u002Ftech-progress clusters dominate |\n   | `SHITPOST` | jokes, memes, low-stakes banter dominate |\n   | `CONTEXT` | mostly reacting to a news cycle, not driving one |\n   | `QUIET` | \u003C3 originals and no thread |\n\n8. **Save gist** (see Log). On empty\u002Fno-new\u002Ferror\u002Fno-var statuses, write only the account header + status footer, skip cluster sections.\n\n9. **Update MEMORY.md (conditional):** only if a cluster carries an announcement, specific claim, named project, or stance shift — add one bullet under a `## Tracked X Accounts` section (create if missing): `- @ACCOUNT YYYY-MM-DD: [one-sentence claim] — [permalink]`. No paraphrases\u002Fmemes\u002Fgeneric opinions.\n\n10. **Notify via `.\u002Fnotify`.** On `REFRESH_X_OK`:\n    ```\n    x refresh - @ACCOUNT ([VERDICT])\n    [lede]\n    top cluster: [title] - \"[≤80 char excerpt]\" ([likes]❤)\n    [N tweets, T threads, K deduped]\n    ```\n    On `REFRESH_X_EMPTY` \u002F `REFRESH_X_NO_NEW`: **skip notify** (write the log entry only). On `REFRESH_X_NO_API_KEY` \u002F `REFRESH_X_ERROR` \u002F `REFRESH_X_NO_VAR`: notify with the status code + a one-line hint (e.g. `\"fetch-tweets: REFRESH_X_NO_API_KEY — set XAI_API_KEY in workflow secrets\"`).\n\n**Constraints:** never fabricate engagement; never include a `SEEN_URLS` URL; an insight that only paraphrases is not an insight (drop the cluster); MEMORY.md updates are one line each. **Status codes:** `REFRESH_X_OK` | `REFRESH_X_EMPTY` | `REFRESH_X_NO_NEW` | `REFRESH_X_NO_API_KEY` | `REFRESH_X_ERROR` | `REFRESH_X_NO_VAR`.\n\n### account — all tracked accounts (`ARG` empty)\n\nUse this to answer \"what did *these specific people* post\" across a watchlist.\n\n1. **Read config** `memory\u002Ftopics\u002Ftracked-accounts.yml`. If missing or `accounts: []` → log `TWEET_DIGEST_NO_CONFIG` and exit (no notification). Schema:\n   ```yaml\n   accounts:\n     - handle: vitalikbuterin\n       why: ethereum core thinking      # optional — grouping\u002Fcontext label\n     - handle: balajis\n       why: macro + tech narratives\n   ```\n\n2. **Fetch recent tweets per account.** For each `handle`:\n   - **Path A - twitterapi.io (primary):** pull the handle's recent timeline, filter to the last 3 days client-side, take the 5 most substantive; drop retweets of others:\n     Run `date -u -d '3 days ago' +%Y-%m-%d` once, as its own call (prints FROM_3D). Then per handle, one call with the handle written in literally:\n     ```bash\n     .\u002Fsecretcurl -s -o \u002Ftmp\u002Ftw-acct1.json -w 'twitterapi http=%{http_code} bytes=%{size_download}\\n' --max-time 60 -G \"https:\u002F\u002Fapi.twitterapi.io\u002Ftwitter\u002Fuser\u002Flast_tweets\" \\\n       --data-urlencode \"userName=\u003CHANDLE>\" -H \"X-API-Key: {TWITTER_API_KEY}\"\n     ```\n     On `HTTP=200` with a non-empty `.data.tweets[]`, parse and mark `source=twitterapi`. One `jq` per call, FROM_3D written in literally; if you also want a count, `jq '.data.tweets | length' \u002Ftmp\u002Ftw-acct1.json` is its own call, never joined with `;`:\n     ```bash\n     jq -r '.data.tweets[] | select((try (.createdAt | strptime(\"%a %b %d %H:%M:%S %z %Y\") | strftime(\"%Y-%m-%d\")) catch \"0000-00-00\") >= \"\u003CFROM_3D>\") | [.id, .author.userName, .text, .url, .createdAt, .likeCount, .retweetCount, .replyCount] | @tsv' \u002Ftmp\u002Ftw-acct1.json\n     ```\n   - **Path B - xAI Grok x_search (fallback)** (only if Path A returned non-2xx \u002F empty \u002F timeout, or `TWITTER_API_KEY` unset):\n     ```bash\n     jq -n '{model:\"grok-4.7\", input:[{role:\"user\",content:\"Search X for the latest tweets from:\u003CHANDLE> in the last 3 days. Return the 5 most interesting or substantive tweets. For each: full text, date, direct link (https:\u002F\u002Fx.com\u002F\u003CHANDLE>\u002Fstatus\u002FID). Skip retweets of others.\"}], tools:[{type:\"x_search\"}]}' \\\n       | .\u002Fsecretcurl -m 30 -s -o \u002Ftmp\u002Fxai-acct1-out.json -X POST \"https:\u002F\u002Fapi.x.ai\u002Fv1\u002Fresponses\" \\\n       -H \"Content-Type: application\u002Fjson\" \\\n       -H \"Authorization: Bearer {XAI_API_KEY}\" \\\n       --data-binary @-\n     ```\n     Parse with the standard `jq` extractor.\n   If neither `TWITTER_API_KEY` nor `XAI_API_KEY` is set, log `TWEET_DIGEST_NO_KEY: skill requires TWITTER_API_KEY (or XAI_API_KEY)` and exit (no notification).\n   **Dedup:** drop any candidate URL already in `SEEN_URLS` (last 2 days of logs).\n\n3. **Group by theme, not by account.** Walk the full candidate set; identify 2–4 themes (e.g. \"L2 design decisions\", \"macro \u002F rates\", \"AI model releases\", \"regulation\"). Each tweet maps to one theme; a `why:` label can seed theme naming for single-topic feeds.\n\n4. **Write a one-sentence take per notable tweet** — what the tweet says, not your opinion of it. Voice per the **Voice** section.\n\n5. **Notify** via `.\u002Fnotify`:\n   ```\n   *Tweet Digest - ${today}*\n\n   *Theme: \u003Ctheme>*\n   @handle: \u003Cone-sentence summary> - [link](url)\n   @handle: \u003Cone-sentence summary> - [link](url)\n\n   *Theme: \u003Ctheme>*\n   ...\n   ```\n   If no notable tweets across all accounts: log `TWEET_DIGEST_OK` and end (no notification).\n\n**Status codes:** `TWEET_DIGEST_OK` (notified or clean) | `TWEET_DIGEST_NO_CONFIG` | `TWEET_DIGEST_NO_KEY`.\n\n---\n\n## Branch: list (`source:list`)\n\nCross-list narrative resonance + signal-scored top tweets from tracked X lists in the past 24h. Lists are *curator signal* — the value is cross-list resonance + insight + a verdict, not a flat top-N-per-list dump.\n\n**Seen set:** `memory\u002Flist-digest-seen.txt` + last 2 days of logs.\n\n1. **Parse and validate `ARG`** in your head, not in a shell script (an `if`\u002F`for` block is refused):\n   - `ARG` empty: log `LIST_DIGEST_NO_CONFIG: var must contain at least one X list ID` to today's `memory\u002Flogs\u002F\u003Cdate>.md` and stop.\n   - `IDS_PART` = the text before the first `|`; `TOPIC_FILTER` = the text after it (empty when there is no `|`).\n   - Split `IDS_PART` on commas into `LIST_ID`s. Any ID that is not all digits: log `LIST_DIGEST_NO_CONFIG: invalid list ID '\u003Cid>' (must be numeric)` and stop.\n\n   If `XAI_API_KEY` is unset, fall back to Path B. If no path returns data, log `LIST_DIGEST_NO_CONFIG: XAI_API_KEY required` and stop without notifying.\n\n2. **Fetch each list's top tweets (past 24h)** - xAI primary, WebSearch fallback.\n   > Note: twitterapi.io has **no `list:` operator** (its advanced_search supports `from:` `to:` `url:` `lang:` `#tag` `@mention` `since:` `until:` only), so this branch keeps the xAI Grok `x_search` path as primary - it is the only path that can read an X list by ID. `TWITTER_API_KEY` does not apply to the `list` source.\n   **Path A - X.AI Responses API** (primary). Get the window dates first, each `date` as its own Bash call: `date -u -d yesterday +%Y-%m-%d` (FROM_DATE) and `date -u +%Y-%m-%d` (TO_DATE). Then build the body and send it in one call (jq piped straight into `.\u002Fsecretcurl`), with the list ID and both dates written in literally:\n   ```bash\n   jq -n '{model:\"grok-4.7\", input:[{role:\"user\",content:\"Look at X list https:\u002F\u002Fx.com\u002Fi\u002Flists\u002F\u003CLIST_ID>. Step 1: report the list name and a one-line description. Step 2: identify the most engaging tweets posted by members of this list between \u003CFROM_DATE> and \u003CTO_DATE> UTC. Return the top 12 tweets ranked by engagement (likes, retweets, replies). For EACH tweet you MUST return: (a) @handle, (b) the full tweet text (not a paraphrase), (c) explicit engagement counts as separate fields - likes:N, retweets:N, replies:N, views:N if available, (d) the direct permalink in the form https:\u002F\u002Fx.com\u002F\u003Chandle>\u002Fstatus\u002F\u003Cid>, (e) media type (image|video|none), (f) one-line context if it is a reply or quote tweet (who\u002Fwhat). Skip retweets of accounts NOT on this list. If a tweet has an image and you can analyze it, include a one-line image description.\"}], tools:[{type:\"x_search\", from_date:\"\u003CFROM_DATE>\", to_date:\"\u003CTO_DATE>\", enable_image_understanding:true}]}' \\\n     | .\u002Fsecretcurl -s -o \u002Ftmp\u002Fxai-list-out.json --max-time 180 -X POST \"https:\u002F\u002Fapi.x.ai\u002Fv1\u002Fresponses\" \\\n     -H \"Content-Type: application\u002Fjson\" \\\n     -H \"Authorization: Bearer {XAI_API_KEY}\" \\\n     --data-binary @-\n   ```\n   Parse with the standard `jq` extractor.\n   **Path B — WebSearch fallback** (only if `XAI_API_KEY` unset, OR Path A errors \u002F returns nothing): `site:x.com \"i\u002Flists\u002F${LIST_ID}\" OR list:${LIST_ID} after:${FROM_DATE}`. Lower quality; mark this list's source as `websearch`.\n   **Per-list outcome:** `ok` (≥3 tweets) | `quiet` (1–2) | `empty` (0, list found but no posts) | `error` (API\u002Faccess failure — note reason).\n\n3. **Build the candidate pool.** Record per tweet `{handle, text, likes, retweets, replies, views, url, list_ids_seen_on:[], list_names_seen_on:[], media, is_reply, is_quote}`. **Dedup by URL across lists** — same tweet on multiple lists → merge records, keep both `list_ids_seen_on` and `list_names_seen_on` (cross-list appearance is a signal). **Dedup against history** — drop URLs in `memory\u002Flist-digest-seen.txt` or the last 2 days of logs.\n\n4. **Score every candidate** (natural-log engagement to stop one viral tweet dominating):\n   ```\n   base = ln(1+likes) + 2.0*ln(1+retweets) + 1.5*ln(1+replies)\n   bonuses:\n     +2.0  appeared on ≥2 distinct lists (cross-list resonance)\n     +1.5  appeared on ≥3 distinct lists\n     +1.0  topic_filter set AND tweet text\u002Fcontext matches (case-insensitive substring or obvious semantic match)\n     +0.5  small-account-signal (≤25k followers per Grok's note OR no follower data + technical\u002Finsider content)\n     +0.3  media is image OR video\n   penalties:\n     -1.0  is_reply AND replied-to NOT on any tracked list\n     -0.5  pure link share with \u003C10 words of original commentary\n   score = base + sum(bonuses) - sum(penalties)\n   ```\n\n5. **Cluster into cross-list narratives** when ALL hold: ≥2 tweets from ≥2 distinct lists; shared ≥2 substantive keywords\u002Fentities (proper nouns, project names, tickers, technical terms — ignore stop words); posted within the same 24h window. `narrative score = sum of constituent tweet scores`; **narrative title** ≤80 chars capturing what the cluster collectively says. Pick an **anchor tweet** (highest individual score) + up to 2 supporting. **Cluster-count cap:** if clustering yields \u003C2 or >4 clusters, fall back to a flat ranked list with inline `[cluster-name]` labels (no \"? Cross-list narratives\" section).\n\n6. **Compose the digest** (cap 4000 chars): up to **3 narratives** at top (by narrative score); then up to **5 standalone tweets per list** (highest individual score, not already in a narrative); hard total cap **12 items** — cut from the bottom of standalones. **Insight discipline:** every item needs a one-line **so-what** (implication, contrarian angle, missing number, deal-flow signal); a paraphrase must be rewritten. **Quiet-list rule:** if a list's top surviving tweet scores \u003C2.0 (≈\u003C8 likes raw), write a one-line \"quiet day\" for that list. **Topic filter** is a scoring booster (step 4), NOT a hard filter. **Verdict line:** one line at the very top capturing what today's lists collectively say.\n\n7. **Send the notification** via `.\u002Fnotify`, verbatim format (`x.com\u002Fhandle`, `[label](url)`):\n   ```\n   *List Digest - ${today}*\n\n   [VERDICT LINE - one line, ≤140 chars, plain text]\n\n   ? *Cross-list narratives*\n   1. *[narrative title]* - appeared on [List A] + [List B]\n      x.com\u002Fhandle: [insight, not paraphrase] (♥ likes, ↻ rt) - [View](url)\n      x.com\u002Fhandle2: [insight] (♥ likes, ↻ rt) - [View](url)\n\n   2. *[narrative title]* - appeared on [List A] + [List C]\n      ...\n\n   *[List Name 1]*\n   - x.com\u002Fhandle - [insight] (♥ likes, ↻ rt) - [View](url)\n   - x.com\u002Fhandle - [insight] (♥ likes, ↻ rt) - [View](url)\n\n   *[List Name 2]*\n   - quiet day\n\n   ---\n   sources: list1=ok | list2=quiet | list3=error(no-access)\n   status: LIST_DIGEST_OK\n   ```\n   If cross-list narratives is empty, drop that whole section. If every list is `quiet`\u002F`empty`, send a single-line \"*List Digest — ${today}* — quiet across all tracked lists\" instead of padding.\n\n8. **Log and persist** (see Log). Append every reported URL (one per line) to `memory\u002Flist-digest-seen.txt` (create if missing).\n\n**Exit taxonomy:** `LIST_DIGEST_NO_CONFIG` (var empty\u002Finvalid OR no fetch path — log only) | `LIST_DIGEST_EMPTY` (every list 0 tweets OR all candidates already seen — log only) | `LIST_DIGEST_PARTIAL` (some lists succeeded\u002Fsome failed — notify survivors, surface failures) | `LIST_DIGEST_OK` (≥1 fresh tweet — notify).\n\n---\n\n## Branch: agent-buzz (`source:agent-buzz`)\n\nA topic-filtered preset: a curated, narrative-aware read on what the AI-agent scene on X talked about in the last 24h. **Curation, not aggregation** — 6 high-signal tweets in 2 clusters beats 10 of mixed noise. `ARG` (optional) is a project\u002Ftopic to prioritize.\n\n**Seen set:** last 3 days of logs — extract every `https:\u002F\u002Fx.com\u002F...\u002Fstatus\u002F\u003Cid>` already posted by this skill; treat those IDs as the dedup set.\n\n1. **Fetch candidates:**\n   Get the window dates first, each `date` as its own Bash call (see **Shell shape** below):\n   ```bash\n   date -u -d '1 day ago' +%Y-%m-%d\n   ```\n   ```bash\n   date -u +%Y-%m-%d\n   ```\n   The first prints FROM_DATE, the second TO_DATE.\n\n   **Path A - twitterapi.io (primary):** structured search over the AI-agents conversation, window inside the query via `since:`, FROM_DATE written in literally:\n   ```bash\n   .\u002Fsecretcurl -s -o \u002Ftmp\u002Ftw-buzz.json -w 'twitterapi http=%{http_code} bytes=%{size_download}\\n' --max-time 60 -G \"https:\u002F\u002Fapi.twitterapi.io\u002Ftwitter\u002Ftweet\u002Fadvanced_search\" \\\n     --data-urlencode 'query=(\"AI agents\" OR \"autonomous agents\" OR \"agent framework\" OR \"agent frameworks\" OR MCP OR \"agent protocol\" OR \"agent benchmark\") since:\u003CFROM_DATE>' \\\n     --data-urlencode \"queryType=Latest\" -H \"X-API-Key: {TWITTER_API_KEY}\"\n   ```\n   On `HTTP=200` with a non-empty `.tweets[]`, parse and mark `source=twitterapi`. Collect up to ~40 candidates (paginate with `&cursor=\u003Cnext_cursor>` while `.has_next_page` if the first page is thin):\n   ```bash\n   jq -r '.tweets[] | [.id, .author.userName, .author.isBlueVerified, .text, .url, .createdAt, .likeCount, .retweetCount, .replyCount] | @tsv' \u002Ftmp\u002Ftw-buzz.json\n   ```\n   Note: advanced_search does **not** return `follower_count` or `role_guess`. On this path treat both as null (the step-3 role multiplier and the follower-ratio skip-gates simply don't fire); use `.author.isBlueVerified` as a weak credibility proxy and lean on raw engagement. If `ARG` is set, append its terms to the query (AND) or issue a second constrained search and merge.\n\n   **Path B - xAI Grok x_search (fallback)** (only if Path A returned non-2xx \u002F empty \u002F timeout, or `TWITTER_API_KEY` unset; the response for each tweet **must** include explicit engagement counts + follower count, or step 3 scoring can't run):\n   ```bash\n   jq -n '{model:\"grok-4.7\", input:[{role:\"user\",content:\"Search X from \u003CFROM_DATE> to \u003CTO_DATE> for tweets in the AI-agents conversation: autonomous agents, agent frameworks, MCP \u002F agent protocols, agent products, agent benchmarks, agent research papers. Return up to 40 candidates. For EACH candidate you MUST return: @handle, follower_count (integer or null), role_guess (builder|founder|researcher|investor|commentator|anon), one-line claim (what they actually said - not a paraphrase, the thesis), likes (int), retweets (int), replies (int), posted_at (ISO), direct_link (https:\u002F\u002Fx.com\u002Fusername\u002Fstatus\u002FID). Prefer builders\u002Ffounders\u002Fresearchers. Skip obvious engagement-farming threads (\\\"RT if you agree\\\", reply-guy pileons, giveaways).\"}], tools:[{type:\"x_search\", from_date:\"\u003CFROM_DATE>\", to_date:\"\u003CTO_DATE>\"}]}' \\\n     | .\u002Fsecretcurl -s -o \u002Ftmp\u002Fxai-buzz-out.json -X POST \"https:\u002F\u002Fapi.x.ai\u002Fv1\u002Fresponses\" \\\n     -H \"Content-Type: application\u002Fjson\" \\\n     -H \"Authorization: Bearer {XAI_API_KEY}\" \\\n     --data-binary @-\n   ```\n   Parse with the standard `jq` extractor. Record `source=xai`.\n   **Path C - WebSearch (last resort)** (only if Paths A and B both error\u002Fempty, or no key set): forced-fresh query `\"AI agents twitter today ${today}\"` - discard anything >48h old, expect degraded metadata. Record `source=websearch`.\n\n   If `ARG` is set, also issue a second call constrained to that topic with the same schema; merge results.\n\n2. **Skip-gates** (before clustering) — drop any candidate matching ANY:\n   - **Dup:** `status\u002F\u003Cid>` already in the 3-day dedup set.\n   - **Engagement-farming:** poll threads, \"bookmark this\", \"drop a ?\", reply-guy pileons with \u003Cfollower_count\u002F10 likes.\n   - **Self-promo only:** pure product shill with no claim\u002Fbenchmark\u002Fdatapoint. Launch tweets OK IF they include a concrete capability claim or number.\n   - **Staleness:** `posted_at` older than 30h.\n   - **Anon + low engagement:** role_guess=anon AND (likes+retweets) \u003C 200.\n\n3. **Signal scoring:** `signal = likes + 2*retweets + replies`, then × 1.3 if role_guess ∈ {builder, founder, researcher}; × 0.7 if a pure hot-take with no concrete referent (no named project, number, paper, or bench); × 0.5 if near-duplicate of another survivor (keep the higher-scored one only).\n\n4. **Narrative clustering:** group survivors into **2–4 narrative clusters** — a cluster is a shared *thesis*, not a keyword (\"MCP vendor lock-in debate\", not \"MCP\"). Name each ≤5 words. If one cluster holds >60% of tweets, split it. A tweet fitting no cluster is dropped unless its signal is top-3 overall. Target: **2–4 clusters, 2–3 tweets each, 6–9 total (strictly ≤10).**\n\n5. **Insight extraction** — per tweet, a one-line **insight** (≤20 words): the actual claim\u002Fdatapoint, not a paraphrase; if opinion, state *what they're arguing against*; if an announcement, state *what's new vs. prior art* (not \"X launched\"). **Anti-hype lint** — rewrite any insight containing: `game-changing`, `revolutionary`, `mind-blowing`, `wild`, `huge`, `massive`, `unreal`, `insane`, vague \"AI agents are evolving\", \"the future of X\".\n\n6. **Conversation-shape lead** — one opening sentence (≤25 words) naming what the conversation was actually about (\"Mostly protocol debate — MCP vs. A2A — with two concrete launches on the side.\"). If you can't characterize it honestly in one sentence, the clustering is wrong — redo step 4.\n\n7. **Notify** via `.\u002Fnotify`:\n   ```\n   *Agent Buzz - ${today}*\n   _\u003Cconversation-shape one-liner>_\n\n   **\u003CCluster 1 name>**\n   • @handle - \u003Cinsight>\n     \u003Clink>\n   • @handle - \u003Cinsight>\n     \u003Clink>\n\n   **\u003CCluster 2 name>**\n   • @handle - \u003Cinsight>\n     \u003Clink>\n\n   \u003C!-- _src: xai|websearch · candidates: N → kept: M_ -->\n   ```\n   Keep the footer — it's how future self-audits debug empty days. Never pad to hit 10. 6 good > 10 mid.\n\n**Status codes:** `AGENT_BUZZ_OK` (≥1 cluster notified) | `AGENT_BUZZ_EMPTY` (fetch succeeded, nothing survived — send `Agent Buzz — ${today}: quiet day, no survivors.`) | `AGENT_BUZZ_ERROR` (all sources failed — notify `Agent Buzz — ${today}: all sources failed (${error summary}).` and log the per-source failure).\n\n---\n\n## Log (all branches)\n\nAppend ONE entry per run to `memory\u002Flogs\u002F${today}.md` under a single `### fetch-tweets` heading (the health loop parses this shape). The first bullet is the **discriminator** naming the branch\u002Fmode that ran; the rest are branch-specific bullets. Always include the reported tweet URLs as bullets (for next-run dedup).\n\n```\n### fetch-tweets\n- mode: \u003Ckeyword|topic|account|list|agent-buzz>\n- status: \u003CSTATUS_CODE for the branch that ran>\n- source: \u003CSOURCE_PATH \u002F per-source counts \u002F per-list outcome, as applicable>\n- \u003Cbranch-specific bullets - carry over each branch's fields:>\n    - keyword:     signal one-liner; per-cluster URLs with `likes:N rts:N replies:N` + insight\n    - topic:       `topics: [t1: N tweets, t2: 0 (dropped)]`; `source: cache:X websearch:Y failed:Z`\n    - account(1):  Verdict + lede; Counts (N tweets, X orig\u002FY reply\u002FZ quote, T threads, deduped K); Clusters; Threads; Vibe\n    - account(all):themes covered; per-account tweet counts\n    - list:        Lists tracked; Per-list `list1=ok(N) | list2=quiet(N) | list3=error`; Verdict; Narratives count\n    - agent-buzz:  source used; candidates N → kept M; cluster names\n- urls:\n    - https:\u002F\u002Fx.com\u002Fhandle1\u002Fstatus\u002F...\n    - https:\u002F\u002Fx.com\u002Fhandle2\u002Fstatus\u002F...\n```\n\nOn empty\u002Fno-new\u002Ferror\u002Fno-config statuses, write the `### fetch-tweets` heading + `mode:` + `status:` bullets only (skip the detail sections) so skill-health still observes the run. After logging, update the branch's persistent seen-file where one exists (keyword \u002F topic \u002F list — see the seen-file table).\n\n## Output shape note\n\nNo chain consumes this skill's output as of this commit (no `consume: [fetch-tweets]` references). If a downstream chain step starts consuming it, emit a flat list of URLs before the clustered\u002Fbranch output so consumers aren't broken by cluster or narrative headers.\n\n## Fetching (all branches)\n\n**Shell shape.** Each Bash call is one allowed command (pipes are fine). The run refuses a call that sets a variable (`FROM_DATE=$(date ...)`, `HTTP=$(.\u002Fsecretcurl ...)`), uses `if` \u002F `for` \u002F `while`, or joins commands with `;`, `&&` or `||`, and each refusal costs a model turn. So get a date with a bare `date` call and write the printed value into later commands; write `ARG`, handles, topics and dates into each command literally (the `\u003CFROM_DATE>`, `\u003CHANDLE>` style placeholders in the snippets); run one `jq` per call; loop over handles or topics by making one call per item. The run also refuses any redirect into a file (`> \u002Ftmp\u002Fx.json`, `cat > f`) and any `$name` in a jq filter (`--arg FROM ... '... $FROM'`), in both tiers: write each value into the jq filter as a JSON string (`>= \"\u003CFROM_2D>\"`; a `\"` inside a value becomes `\\\"`, and reword any `'`), and pipe a request body straight into `.\u002Fsecretcurl ... --data-binary @-`.\n\nEvery branch fetches X in a **three-tier cascade**. Attempt each tier in order; only drop to the next on a *real* failure (non-2xx, empty body, or timeout), and always record the true reason.\n\n**Path A - twitterapi.io (primary).** `TWITTER_API_KEY` is **injected into your environment** for this skill (declared in `requires:`). The primary fetch path in every branch (except `list`, which has no twitterapi list operator) is a direct `curl` to `https:\u002F\u002Fapi.twitterapi.io\u002Ftwitter\u002F...` with the `X-API-Key: {TWITTER_API_KEY}` header. It is fast (~700ms), returns **structured ground-truth** JSON with **exact engagement counts** and **real permalinks** (`.url`) - so there is no fabrication risk and no prompt to coax. Two endpoints:\n- **Search:** `GET \u002Ftweet\u002Fadvanced_search?query=\u003Cq>&queryType=Latest` -> `{tweets:[...], has_next_page, next_cursor}`. Put date windows **inside** the query with X operators `since:YYYY-MM-DD until:YYYY-MM-DD`; other operators: `from:` `to:` `url:` `lang:` `#tag` `@mention`, plus OR\u002FAND and quotes. Tweets are under `.tweets[]`. (There is **no** `list:` operator - see the `list` branch.)\n- **Timeline:** `GET \u002Fuser\u002Flast_tweets?userName=\u003Chandle>` -> `{status:\"success\", data:{tweets:[...]}, has_next_page, next_cursor}`. No server-side date filter - filter client-side on `.createdAt` or paginate with `&cursor=\u003Cnext_cursor>`. Tweets are under `.data.tweets[]`.\n\nFields: `id, text, url, createdAt, likeCount, retweetCount, replyCount, quoteCount, viewCount, author.userName, author.name, author.isBlueVerified` (last_tweets also `isReply`, `author.followers`). Capture the status with `-w 'twitterapi http=%{http_code} bytes=%{size_download}\\n'` (curl prints it, so no `HTTP=$(...)` wrapper) and **read the `http=\u003Ccode>` line before deciding anything.** `HTTP=200` with a non-empty tweet array -> use it (`SOURCE_PATH=twitterapi`). No prefetch, no cache - just make the call.\n\n**Path B - xAI Grok x_search (fallback).** Only when Path A fails (non-2xx \u002F empty \u002F timeout) or `TWITTER_API_KEY` is unset. Direct `curl` to `https:\u002F\u002Fapi.x.ai\u002Fv1\u002Fresponses` with `Authorization: Bearer {XAI_API_KEY}` using Grok's `x_search` tool. The `x_search` call typically takes 30-120s (it searches X live), so **set the Bash tool `timeout` to at least 180000 (180s)** and add **`--max-time 150`** to the curl so it fails cleanly rather than hanging. A slow curl is **not** a missing key. Build the JSON body with `jq -n` (prompt and dates written into the filter literally) and pipe it straight into `.\u002Fsecretcurl` in the same call (its body flag reads stdin) - every `.\u002Fsecretcurl` command must be 100% literal (no shell variables, or the permission layer blocks it). Parse with the standard extractor:\n   ```bash\n   jq -r '.output[] | select(.type == \"message\") | .content[] | select(.type == \"output_text\") | .text' \u002Ftmp\u002Fxai.json\n   ```\n`HTTP=200` with a non-empty body -> use it (`SOURCE_PATH=api`).\n\n**Path C - WebSearch \u002F WebFetch (last resort).** Only when both A and B fail (or no key is set at all). Lowest quality (WebSearch favours old high-engagement tweets; WebFetch reads a public profile page). Never reach for it while a key works.\n\n**Reason codes** (record the true one on every fallback - never write \"XAI_API_KEY unavailable\" \u002F \"sandbox\" \u002F \"expansion blocked\" when a key was set): `key-unset` (the relevant key was actually empty), `http-\u003Ccode>` (non-2xx), `empty` (200 but no tweets parsed), `timeout` (curl exceeded `--max-time`).\n\n## Environment Variables\n\n- `TWITTER_API_KEY` - twitterapi.io API key (sent as the `X-API-Key` header). Declared in `requires:`, so it is **injected into this skill's environment**; it is the **primary** fetch path for every branch except `list` (twitterapi has no list operator). Fast, structured ground-truth with exact engagement counts and real permalinks.\n- `XAI_API_KEY` - X.AI API key for Grok's `x_search` tool (declared `XAI_API_KEY?`, optional). The **fallback** path when `TWITTER_API_KEY` is unset or twitterapi returns non-2xx \u002F empty \u002F timeout, and the **primary** path for the `list` branch. If both keys are unset, branches degrade to WebSearch\u002FWebFetch at lower quality; the `account (all)` sub-mode instead hard-exits (`TWEET_DIGEST_NO_KEY`).\n","\u003C!-- autoresearch: variation B — sharper output via clustering + signal scoring + insight extraction. Merged HUB: absorbs tweet-digest, tweet-roundup, list-digest, refresh-x, agent-buzz behind a `source:` selector. -->\n> **${var}** — `\u003Csource>:\u003Carg>` where `\u003Csource>` ∈ `keyword | topic | account | list | agent-buzz`. The `\u003Carg>` is source-specific (a query, a topic, a handle, comma-separated list IDs, or an optional focus). If no `source:` prefix is given, the source is inferred from the shape of `\u003Carg>` (see **Source selector**). **Required** for `keyword` and `list`; optional for `topic`, `account`, and `agent-buzz`.\n\nToday is ${today}. This skill fetches X\u002FTwitter content along one of five **source axes** and produces a *curated* digest — clustered by sub-narrative, ranked by signal, one insight per item — never a flat chronological dump.\n\n## Source selector\n\nParse `${var}` into `SOURCE` and `ARG` before doing anything else.\n\n**Explicit form (recommended):** `\u003Csource>:\u003Carg>`\n- `keyword:$SOL OR solana OR \"solana network\"` - raw X search query, passed to the search **verbatim** (OR\u002FAND honored; twitterapi advanced_search primary, Grok x_search fallback).\n- `topic:brain-computer interfaces` — a single topic roundup. `topic:` (empty arg) → resolve a topic **list** from MEMORY.md, then built-in defaults.\n- `account:vitalikbuterin` — one account's recent tweets. `account:` (empty arg) → digest **every** handle in `memory\u002Ftopics\u002Ftracked-accounts.yml`.\n- `list:1953536336675365173,1937207796270829766` — one or more numeric X list IDs. Append `|\u003Ctopic>` for a topic booster: `list:195...,193...|AI agents`.\n- `agent-buzz` — the curated AI-agent-ecosystem preset. `agent-buzz:MCP protocol` prioritizes a project\u002Ftopic within the preset.\n\n**Implicit form (back-compat with migrated bare-var configs):** when `${var}` has **no** recognized `source:` prefix, infer `SOURCE` in this order:\n1. `${var}` is empty → `topic` (default multi-topic roundup).\n2. `${var}` is all-digits, or comma-separated all-digits (optionally with a `|\u003Ctopic>` suffix) → `list`.\n3. `${var}` is `@handle` or matches `^[A-Za-z0-9_]{1,15}$` (a bare handle) → `account`.\n4. Anything else → `keyword`.\n\nNote: `agent-buzz` has **no** distinct implicit shape (its arg looks like a keyword\u002Ftopic), so it is **only** selectable via the explicit `agent-buzz` \u002F `agent-buzz:...` prefix.\n\nOnce `SOURCE` and `ARG` are set, jump to the matching branch below. Only one branch runs per invocation.\n\n## Shared preamble (all branches)\n\n1. Read `memory\u002FMEMORY.md` for context and the recent `memory\u002Flogs\u002F` (each branch specifies its lookback window — 2 or 3 days) to dedup already-reported tweets.\n2. **Load the dedup set `SEEN_TWEETS`** by unioning two sources:\n   - The branch's **persistent seen-file** (per-mode path below), if it exists — read all URLs.\n   - The branch's **log lookback window** — grep each `memory\u002Flogs\u002F*.md` file in range for lines matching `https:\u002F\u002Fx.com\u002F`.\n\n   Per-mode seen-files (kept at their legacy paths so dedup history survives the merge):\n   | mode | seen-file | log lookback |\n   |---|---|---|\n   | keyword | `memory\u002Ffetch-tweets-seen.txt` | 3 days |\n   | topic | `memory\u002Ftweet-roundup-seen.txt` | 3 days |\n   | account | *(logs only — see branch)* | 2 days |\n   | list | `memory\u002Flist-digest-seen.txt` | 2 days |\n   | agent-buzz | *(logs only — 3-day `status\u002F\u003Cid>` set)* | 3 days |\n3. Formatting invariants shared by **every** branch's notification:\n   - Use `x.com\u002Fhandle` (**never** `@handle`) so Telegram doesn't ping\u002Ftag users. *(Exception: the account-digest and agent-buzz formats below historically use `@handle` in-body; keep their documented format but prefer `x.com\u002Fhandle` when practical.)*\n   - Every surviving tweet gets a tappable Markdown link — `[View](url)` \u002F `[View tweet](url)`. If a URL is unavailable, drop the link and say \"(link unavailable)\".\n   - Never fabricate engagement counts. Missing → `0`, not a guess.\n   - **Notify only on signal.** A legitimately empty or all-duplicate run logs its status and sends **nothing**.\n\n## Voice\n\nUsed by the `account` and `agent-buzz` branches for one-line takes\u002Finsights. If `soul\u002FSOUL.md` and `soul\u002FSTYLE.md` are populated, read both and match the operator's voice. If they are empty templates or absent, write in a clear, direct, neutral tone — state what the tweet says, no hedging or editorializing beyond the tweet itself.\n\n---\n\n## Branch: keyword (`source:keyword`)\n\nSearch X for tweets matching `ARG` and produce a curated digest grouped by sub-narrative.\n\n**Seen set:** `memory\u002Ffetch-tweets-seen.txt` + last 3 days of logs (loaded in preamble).\n\n1. **Build the search prompt.** Pass `ARG` to Grok **verbatim** as the query — do NOT narrow it to a single angle; broad coverage is the goal. Ask for **at least 15–20 candidate tweets** (you'll cull to ~7–10). Always require explicit engagement counts (likes, retweets, replies) so ranking is data-driven.\n\n2. **Fetch tweets.** Record `SOURCE_PATH=twitterapi|api|websearch` for the log.\n\n   Get the window dates first, each `date` as its own Bash call (see **Shell shape** below):\n   ```bash\n   date -u -d yesterday +%Y-%m-%d\n   ```\n   ```bash\n   date -u +%Y-%m-%d\n   ```\n   The first prints FROM_DATE, the second TO_DATE.\n\n   **Path A - twitterapi.io (primary; see the **Fetching (all branches)** contract):** structured X search, no prompt. Put the date window inside the query with `since:`. Pass `ARG` as the query **verbatim** (OR\u002FAND honored) plus `since:\u003CFROM_DATE>`, both written in literally:\n   ```bash\n   .\u002Fsecretcurl -s -o \u002Ftmp\u002Ftw-keyword.json -w 'twitterapi http=%{http_code} bytes=%{size_download}\\n' --max-time 60 -G \"https:\u002F\u002Fapi.twitterapi.io\u002Ftwitter\u002Ftweet\u002Fadvanced_search\" \\\n     --data-urlencode \"query=\u003CARG> since:\u003CFROM_DATE>\" --data-urlencode \"queryType=Latest\" \\\n     -H \"X-API-Key: {TWITTER_API_KEY}\"\n   ```\n   On `HTTP=200` with a non-empty `.tweets[]`, parse and mark `SOURCE_PATH=twitterapi`:\n   ```bash\n   jq -r '.tweets[] | [.id, .author.userName, .text, .url, .createdAt, .likeCount, .retweetCount, .replyCount] | @tsv' \u002Ftmp\u002Ftw-keyword.json\n   ```\n   Paginate with `&cursor=\u003Cnext_cursor>` (from `.next_cursor` while `.has_next_page`) only if you need more than the first page to reach ~15-20 candidates. Engagement counts are exact ground-truth; permalinks are the real `.url`.\n\n   **Path B - xAI Grok x_search (fallback)** (only if Path A returned non-2xx \u002F empty \u002F timeout, or `TWITTER_API_KEY` is unset; see the contract - set the Bash tool `timeout` >=180000, capture the HTTP status):\n   ```bash\n   jq -n '{model:\"grok-4.7\", input:[{role:\"user\",content:\"Search X for tweets about: \u003CARG>. Date range: \u003CFROM_DATE> to \u003CTO_DATE>. Return at least 15-20 candidate tweets - mix of high-engagement posts and smaller accounts that add a distinct angle. For each tweet include: @handle, the full text, date posted, exact engagement counts (likes, retweets, replies - never N\u002FA; if unknown, say 0), and the direct link (https:\u002F\u002Fx.com\u002Fhandle\u002Fstatus\u002FID). Return as a numbered list.\"}], tools:[{type:\"x_search\"}]}' \\\n     | .\u002Fsecretcurl -s -o \u002Ftmp\u002Fxai.json -w '%{http_code}' --max-time 150 -X POST \"https:\u002F\u002Fapi.x.ai\u002Fv1\u002Fresponses\" \\\n     -H \"Content-Type: application\u002Fjson\" \\\n     -H \"Authorization: Bearer {XAI_API_KEY}\" \\\n     --data-binary @-\n   ```\n   On `HTTP=200`, parse `\u002Ftmp\u002Fxai.json` with: `jq -r '.output[] | select(.type == \"message\") | .content[] | select(.type == \"output_text\") | .text'` and mark `SOURCE_PATH=api`.\n\n   **Path C - WebSearch (last resort)** (only if Paths A and B both gave a non-2xx \u002F empty \u002F timeout, or no key is set): use the built-in WebSearch tool with `site:x.com \"\u003Cquery terms>\" after:${FROM_DATE}`. Note at the top of the log the **true reason** (`http-\u003Ccode>` \u002F `timeout` \u002F `empty`, never \"unavailable\" when a key was set) and \"results compiled via WebSearch - quality lower than usual\". WebSearch favours high-engagement older tweets - **prioritise results dated within the last 48 hours**. Mark `SOURCE_PATH=websearch`.\n\n3. **Empty vs. error handling** (distinguish):\n   - **Legitimate empty** (0 tweets): log `FETCH_TWEETS_EMPTY (source=${SOURCE_PATH})` and **stop — no notification**.\n   - **API\u002Fcache error** (HTTP error, malformed JSON, all paths failed): log `FETCH_TWEETS_ERROR (last_path=${SOURCE_PATH}, reason=...)` and **stop — no notification**.\n\n4. **Deduplicate** each candidate URL against `SEEN_TWEETS`. If ALL are dupes: log `FETCH_TWEETS_NO_NEW: all results already reported` and **stop — no notification**.\n\n5. **Curate** (the core step):\n   a. **Cluster** survivors into 2–4 sub-narratives by what they're claiming\u002Fdiscussing (e.g. for a token: \"price action\", \"team announcement\", \"criticism\u002FFUD\", \"ecosystem integration\"). Name the *angle*, not the topic.\n   b. **Rank within each cluster by signal** (not raw engagement): `signal = likes + 2×retweets + replies`, but **demote** pure replies, generic shilling, and near-duplicate paraphrases. Drop tweets with \u003C5 total engagement unless they add a unique angle.\n   c. **Cap each cluster at 2–3 tweets, total 7–10.** Quality over quantity — if only 5 pass, send 5. Don't pad.\n   d. **Extract the claim\u002Fsignal** per tweet — *what's new or interesting*, not a literal paraphrase. Bad: \"User says token is going up.\" Good: \"Calls out the team's silence on the postponed unlock — first major holder to do so publicly.\"\n   e. **Compute a one-line signal** for the top of the notification — one observation about the *shape* of the conversation (e.g. \"Sentiment split — 4 bullish on the launch, 3 critical of the unlock terms.\").\n\n6. **Save + update seen-file** (see Log). Append each kept tweet URL (one per line) to `memory\u002Ffetch-tweets-seen.txt` (create if missing).\n\n7. **Notify via `.\u002Fnotify`** with the clustered output:\n   ```\n   *Top Tweets - ${ARG} (${today})*\n   _${signal_one_liner}_\n\n   *${cluster_1_name}*\n   1. x.com\u002Fhandle - [insight summary]\n   Likes: X | RTs: Y | Replies: Z\n   [View tweet](https:\u002F\u002Fx.com\u002Fhandle\u002Fstatus\u002FID)\n\n   2. x.com\u002Fhandle - [insight summary]\n   Likes: X | RTs: Y | Replies: Z\n   [View tweet](https:\u002F\u002Fx.com\u002Fhandle\u002Fstatus\u002FID)\n\n   *${cluster_2_name}*\n   3. x.com\u002Fhandle - [insight summary]\n   ...\n   ```\n   The signal one-liner is italic (`_..._`) directly under the title; cluster headers are `*bold*`.\n\n**Status codes:** `FETCH_TWEETS_OK` (notified) | `FETCH_TWEETS_EMPTY` | `FETCH_TWEETS_ERROR` | `FETCH_TWEETS_NO_NEW`.\n\n---\n\n## Branch: topic (`source:topic`)\n\nGist of the latest X chatter on one or more configurable topics.\n\n**Seen set:** `memory\u002Ftweet-roundup-seen.txt` + last 3 days of logs.\n\n1. **Resolve the topic list** (priority order):\n   1. `ARG` set → `TOPICS=(\"$ARG\")` (single-topic mode).\n   2. Else if MEMORY.md has a `## Tweet Roundup Topics` section → use its bulleted lines, one query per line.\n   3. Else built-in defaults:\n      - `artificial intelligence OR AI agents OR LLM`\n      - `crypto OR bitcoin OR DeFi`\n      - `technology OR startups OR open source`\n\n2. **Fetch per topic** - track `SOURCE ∈ {twitterapi, api, websearch, failed}` per topic.\n\n   Get the window dates first, each `date` as its own Bash call (see **Shell shape** below):\n   ```bash\n   date -u -d yesterday +%Y-%m-%d\n   ```\n   ```bash\n   date -u +%Y-%m-%d\n   ```\n   The first prints FROM_DATE, the second TO_DATE.\n\n   **Path A - twitterapi.io (primary):** for each topic, one call with the topic as the query and the window inside it via `since:`, both written in literally:\n   ```bash\n   .\u002Fsecretcurl -s -o \u002Ftmp\u002Ftw-topic.json -w 'twitterapi http=%{http_code} bytes=%{size_download}\\n' --max-time 60 -G \"https:\u002F\u002Fapi.twitterapi.io\u002Ftwitter\u002Ftweet\u002Fadvanced_search\" \\\n     --data-urlencode \"query=\u003CTOPIC> since:\u003CFROM_DATE>\" --data-urlencode \"queryType=Latest\" \\\n     -H \"X-API-Key: {TWITTER_API_KEY}\"\n   ```\n   On `HTTP=200` with a non-empty `.tweets[]`, parse and mark `SOURCE=twitterapi`. Extract each tweet's handle (`.author.userName`), text, engagement counts (`.likeCount`\u002F`.retweetCount`\u002F`.replyCount`), and permalink (`.url`); take up to the first 8 substantive tweets:\n   ```bash\n   jq -r '.tweets[] | [.id, .author.userName, .text, .url, .createdAt, .likeCount, .retweetCount, .replyCount] | @tsv' \u002Ftmp\u002Ftw-topic.json\n   ```\n\n   **Path B - xAI Grok x_search (fallback)** (only if Path A returned non-2xx \u002F empty \u002F timeout, or `TWITTER_API_KEY` unset): for each topic, call Grok's `x_search`.\n   ```bash\n   jq -n '{model:\"grok-4.7\", input:[{role:\"user\",content:\"Search X for recent tweets about: \u003CTOPIC>. Date range: \u003CFROM_DATE> to \u003CTO_DATE>. Return up to 8 substantive tweets. For each: @handle, full text, date, exact engagement counts (likes, retweets, replies; 0 if unknown), and the direct link https:\u002F\u002Fx.com\u002Fhandle\u002Fstatus\u002FID.\"}], tools:[{type:\"x_search\"}]}' \\\n     | .\u002Fsecretcurl -s -o \u002Ftmp\u002Fxai-topic-out.json -X POST \"https:\u002F\u002Fapi.x.ai\u002Fv1\u002Fresponses\" \\\n     -H \"Content-Type: application\u002Fjson\" \\\n     -H \"Authorization: Bearer {XAI_API_KEY}\" \\\n     --data-binary @-\n   ```\n   Parse with the standard `jq` extractor. If it yields text, `SOURCE=api`. Extract each tweet's `@handle`, text, engagement counts, and permalink.\n\n   **Path C - WebSearch (last resort)** (only if Paths A and B both error\u002Fempty, or no key set): `site:x.com \"\u003Ctopic keywords>\" after:\u003CYESTERDAY>`. Always include the word \"today\" and `${today}` to force fresh results. Discard any result whose visible date is older than 48h. Collect up to 5 candidates per topic. Mark `SOURCE=websearch`. If all paths return nothing, mark `SOURCE=failed`.\n\n3. **Score and filter.** Require: a known `@handle`; a `https:\u002F\u002Fx.com\u002F\u003Chandle>\u002Fstatus\u002F\u003Cid>` URL (if missing, keep but mark \"link unavailable\"); posted within 48h; URL **not** in `SEEN_TWEETS`. Compute `signal_score = likes + 2×retweets + replies` (on WebSearch path with no counts, use result rank as a weak proxy). **Demote −50%**: replies to a parent tweet; near-duplicates of a higher-scoring tweet (>70% text overlap or same linked URL).\n\n4. **Curate per topic:**\n   - **0 survivors** → drop the topic. Do NOT pad.\n   - **1–3 survivors** → list ranked by `signal_score`, highest first.\n   - **4+ survivors** → group into 2–3 sub-narratives (shared keywords\u002Fentity\u002Fclaim); label each, surface the top-1 tweet per narrative as exemplar.\n   Write an **insight** per reported tweet (what it asserts\u002Freveals, not a headline paraphrase). Write a one-line **conversation shape** per topic (\"bullish momentum, dissenters quiet\", \"split opinion on X's launch\", \"single story dominating — Y\").\n\n5. **Notify.** If every topic dropped: log `TWEET_ROUNDUP_EMPTY` and **stop — no notify**. Otherwise send via `.\u002Fnotify` (≤4000 chars):\n   ```\n   *Tweet Roundup - ${today}*\n   _Source: api:X websearch:Y failed:Z_\n\n   *[Topic 1]* - _conversation shape_\n   - x.com\u002Fhandle - insight (signal: 12.3k) [View](https:\u002F\u002Fx.com\u002Fhandle\u002Fstatus\u002FID)\n   - x.com\u002Fhandle - insight (signal: 4.1k) [View](https:\u002F\u002Fx.com\u002Fhandle\u002Fstatus\u002FID)\n\n   *[Topic 2]* - _conversation shape_\n   - x.com\u002Fhandle - insight (signal: 8k) [View](https:\u002F\u002Fx.com\u002Fhandle\u002Fstatus\u002FID)\n   ```\n   Show `signal: \u003Cscore>` only when engagement counts were available (api path); omit silently on WebSearch.\n\n6. **Persist + log** (see Log). Append each reported URL (one per line) to `memory\u002Ftweet-roundup-seen.txt` (create if missing).\n\n**Constraints:** never notify an empty roundup (silence beats filler); never `@handle` anyone; never report a URL already in `SEEN_TWEETS`. **Status codes:** `TWEET_ROUNDUP_OK` | `TWEET_ROUNDUP_EMPTY`.\n\n---\n\n## Branch: account (`source:account`)\n\nTwo sub-modes: **single handle** (decision-ready gist of one account) vs. **all tracked accounts** (theme-grouped digest of a watchlist). Choose by `ARG`.\n\n**Seen set:** last 2 days of logs — extract every `https:\u002F\u002Fx.com\u002F` URL under a prior `### fetch-tweets` account entry into `SEEN_URLS`.\n\n### account — single handle (`ARG` is one @handle)\n\n1. **Normalize `ARG`.** Strip leading `@`, `https:\u002F\u002Fx.com\u002F`, `https:\u002F\u002Ftwitter.com\u002F`, `https:\u002F\u002Fnitter.net\u002F`, trailing slash \u002F `\u002Fstatus\u002F...`. Lowercase. Reject if empty, contains whitespace, or >15 chars. On reject → `REFRESH_X_NO_VAR`: send `.\u002Fnotify \"fetch-tweets: REFRESH_X_NO_VAR — set an X handle\"` and exit 0. Store the cleaned handle as `ACCOUNT`.\n\n2. **Load tweets:**\n   - **Path A - twitterapi.io (primary):** pull this account's recent timeline directly, then filter to the last 2 days client-side (no server-side date filter on this endpoint):\n     First `date -u -d '2 days ago' +%Y-%m-%d` as its own call (prints FROM_2D), then one call with the handle written in literally:\n     ```bash\n     .\u002Fsecretcurl -s -o \u002Ftmp\u002Ftw-account.json -w 'twitterapi http=%{http_code} bytes=%{size_download}\\n' --max-time 60 -G \"https:\u002F\u002Fapi.twitterapi.io\u002Ftwitter\u002Fuser\u002Flast_tweets\" \\\n       --data-urlencode \"userName=\u003CACCOUNT>\" -H \"X-API-Key: {TWITTER_API_KEY}\"\n     ```\n     On `HTTP=200` with a non-empty `.data.tweets[]`, parse and mark `source=twitterapi`. Filter on `.createdAt` (drop tweets older than the window) and use `.isReply` to tag reply vs original (this endpoint has no quote flag - treat non-reply as original; if you need reliable quote detection fall back to Path B). One `jq` per call, FROM_2D written in literally:\n     ```bash\n     jq -r '.data.tweets[] | select((try (.createdAt | strptime(\"%a %b %d %H:%M:%S %z %Y\") | strftime(\"%Y-%m-%d\")) catch \"0000-00-00\") >= \"\u003CFROM_2D>\") | [.id, .author.userName, .text, .url, .createdAt, .likeCount, .retweetCount, .replyCount, .isReply] | @tsv' \u002Ftmp\u002Ftw-account.json\n     ```\n   - **Path B - xAI Grok x_search (fallback)** (only if Path A returned non-2xx \u002F empty \u002F timeout, or `TWITTER_API_KEY` unset): search this account's recent tweets via Grok's `x_search`.\n     ```bash\n     jq -n '{model:\"grok-4.7\", input:[{role:\"user\",content:\"Search X for the latest tweets, replies, and quote tweets from @\u003CACCOUNT> in the last 2 days. Return each with full text, timestamp, type (original|reply|quote), what it replies to\u002Fquotes if any, exact engagement counts (likes, retweets, replies; 0 if unknown), and the permalink https:\u002F\u002Fx.com\u002F\u003CACCOUNT>\u002Fstatus\u002FID. Skip retweets of others. Return chronological.\"}], tools:[{type:\"x_search\"}]}' \\\n       | .\u002Fsecretcurl -m 30 -s -o \u002Ftmp\u002Fxai-account-out.json -X POST \"https:\u002F\u002Fapi.x.ai\u002Fv1\u002Fresponses\" \\\n       -H \"Content-Type: application\u002Fjson\" \\\n       -H \"Authorization: Bearer {XAI_API_KEY}\" \\\n       --data-binary @-\n     ```\n     Parse with the standard `jq` extractor. Record `source=api`.\n   - **Path C - WebFetch (last resort)** (only if Paths A and B both failed \u002F returned nothing): WebFetch `https:\u002F\u002Fx.com\u002F${ACCOUNT}` with prompt: *\"List every tweet, reply, and quote tweet visible on this profile with its full text, timestamp, engagement counts (likes\u002Fretweets\u002Freplies) if shown, and the permalink https:\u002F\u002Fx.com\u002Fhandle\u002Fstatus\u002FID. Return a chronological list.\"* Record `source=webfetch`.\n   - **Degraded**: if no key is set and WebFetch returns nothing → skip to step 8 with status `REFRESH_X_NO_API_KEY` (no key present) or `REFRESH_X_ERROR` (a key was set but all paths failed).\n\n3. **Parse into structured tweets:** `url`, `text`, `timestamp`, `type` (original\u002Freply\u002Fquote), `reply_to`, `quoted_text`, `likes`, `retweets`, `replies`. Drop retweets of others. Missing counts → 0. Compute `signal_score = likes + 2*retweets + replies − (3 if type=reply else 0)`.\n\n4. **Dedup and gate:** drop any tweet whose `url` is in `SEEN_URLS` (`deduped_count`). If fewer than 3 tweets survive AND no thread is detectable (step 5) → skip to step 8 with `REFRESH_X_NO_NEW` (everything deduped) or `REFRESH_X_EMPTY` (account posted nothing).\n\n5. **Detect threads:** a thread = 2+ tweets by `ACCOUNT` within 30 minutes where later tweets reply to earlier ones OR share ≥2 meaningful keywords with the opener. Thread tweets are atomic units regardless of individual score. Record `{opener_url, tweet_count, combined_signal}`.\n\n6. **Cluster and extract insights:** group survivors (threads = one unit) into **2–4 sub-narratives** by topic overlap; if \u003C2 emerge, use one cluster. Per cluster: **Title** (3–8 words), **Top tweet(s)** (1–3 excerpts ≤200 chars each, with permalink + engagement), **Insight** (one sentence — what the cluster reveals about the author's stance\u002Fclaim\u002Fshift; not a paraphrase — if you can't beat paraphrase, drop the cluster). Per thread: a 1–2 sentence landing summary + opener URL.\n\n7. **Write the verdict** (pick exactly one) + a ≤20-word lede:\n   | Verdict | When |\n   |---|---|\n   | `ANNOUNCEMENT` | launch, hire, policy, or product drop |\n   | `ARGUMENT` | majority signal from contrarian takes or fights |\n   | `BUILDING` | ships\u002Fcode\u002Ftech-progress clusters dominate |\n   | `SHITPOST` | jokes, memes, low-stakes banter dominate |\n   | `CONTEXT` | mostly reacting to a news cycle, not driving one |\n   | `QUIET` | \u003C3 originals and no thread |\n\n8. **Save gist** (see Log). On empty\u002Fno-new\u002Ferror\u002Fno-var statuses, write only the account header + status footer, skip cluster sections.\n\n9. **Update MEMORY.md (conditional):** only if a cluster carries an announcement, specific claim, named project, or stance shift — add one bullet under a `## Tracked X Accounts` section (create if missing): `- @ACCOUNT YYYY-MM-DD: [one-sentence claim] — [permalink]`. No paraphrases\u002Fmemes\u002Fgeneric opinions.\n\n10. **Notify via `.\u002Fnotify`.** On `REFRESH_X_OK`:\n    ```\n    x refresh - @ACCOUNT ([VERDICT])\n    [lede]\n    top cluster: [title] - \"[≤80 char excerpt]\" ([likes]❤)\n    [N tweets, T threads, K deduped]\n    ```\n    On `REFRESH_X_EMPTY` \u002F `REFRESH_X_NO_NEW`: **skip notify** (write the log entry only). On `REFRESH_X_NO_API_KEY` \u002F `REFRESH_X_ERROR` \u002F `REFRESH_X_NO_VAR`: notify with the status code + a one-line hint (e.g. `\"fetch-tweets: REFRESH_X_NO_API_KEY — set XAI_API_KEY in workflow secrets\"`).\n\n**Constraints:** never fabricate engagement; never include a `SEEN_URLS` URL; an insight that only paraphrases is not an insight (drop the cluster); MEMORY.md updates are one line each. **Status codes:** `REFRESH_X_OK` | `REFRESH_X_EMPTY` | `REFRESH_X_NO_NEW` | `REFRESH_X_NO_API_KEY` | `REFRESH_X_ERROR` | `REFRESH_X_NO_VAR`.\n\n### account — all tracked accounts (`ARG` empty)\n\nUse this to answer \"what did *these specific people* post\" across a watchlist.\n\n1. **Read config** `memory\u002Ftopics\u002Ftracked-accounts.yml`. If missing or `accounts: []` → log `TWEET_DIGEST_NO_CONFIG` and exit (no notification). Schema:\n   ```yaml\n   accounts:\n     - handle: vitalikbuterin\n       why: ethereum core thinking      # optional — grouping\u002Fcontext label\n     - handle: balajis\n       why: macro + tech narratives\n   ```\n\n2. **Fetch recent tweets per account.** For each `handle`:\n   - **Path A - twitterapi.io (primary):** pull the handle's recent timeline, filter to the last 3 days client-side, take the 5 most substantive; drop retweets of others:\n     Run `date -u -d '3 days ago' +%Y-%m-%d` once, as its own call (prints FROM_3D). Then per handle, one call with the handle written in literally:\n     ```bash\n     .\u002Fsecretcurl -s -o \u002Ftmp\u002Ftw-acct1.json -w 'twitterapi http=%{http_code} bytes=%{size_download}\\n' --max-time 60 -G \"https:\u002F\u002Fapi.twitterapi.io\u002Ftwitter\u002Fuser\u002Flast_tweets\" \\\n       --data-urlencode \"userName=\u003CHANDLE>\" -H \"X-API-Key: {TWITTER_API_KEY}\"\n     ```\n     On `HTTP=200` with a non-empty `.data.tweets[]`, parse and mark `source=twitterapi`. One `jq` per call, FROM_3D written in literally; if you also want a count, `jq '.data.tweets | length' \u002Ftmp\u002Ftw-acct1.json` is its own call, never joined with `;`:\n     ```bash\n     jq -r '.data.tweets[] | select((try (.createdAt | strptime(\"%a %b %d %H:%M:%S %z %Y\") | strftime(\"%Y-%m-%d\")) catch \"0000-00-00\") >= \"\u003CFROM_3D>\") | [.id, .author.userName, .text, .url, .createdAt, .likeCount, .retweetCount, .replyCount] | @tsv' \u002Ftmp\u002Ftw-acct1.json\n     ```\n   - **Path B - xAI Grok x_search (fallback)** (only if Path A returned non-2xx \u002F empty \u002F timeout, or `TWITTER_API_KEY` unset):\n     ```bash\n     jq -n '{model:\"grok-4.7\", input:[{role:\"user\",content:\"Search X for the latest tweets from:\u003CHANDLE> in the last 3 days. Return the 5 most interesting or substantive tweets. For each: full text, date, direct link (https:\u002F\u002Fx.com\u002F\u003CHANDLE>\u002Fstatus\u002FID). Skip retweets of others.\"}], tools:[{type:\"x_search\"}]}' \\\n       | .\u002Fsecretcurl -m 30 -s -o \u002Ftmp\u002Fxai-acct1-out.json -X POST \"https:\u002F\u002Fapi.x.ai\u002Fv1\u002Fresponses\" \\\n       -H \"Content-Type: application\u002Fjson\" \\\n       -H \"Authorization: Bearer {XAI_API_KEY}\" \\\n       --data-binary @-\n     ```\n     Parse with the standard `jq` extractor.\n   If neither `TWITTER_API_KEY` nor `XAI_API_KEY` is set, log `TWEET_DIGEST_NO_KEY: skill requires TWITTER_API_KEY (or XAI_API_KEY)` and exit (no notification).\n   **Dedup:** drop any candidate URL already in `SEEN_URLS` (last 2 days of logs).\n\n3. **Group by theme, not by account.** Walk the full candidate set; identify 2–4 themes (e.g. \"L2 design decisions\", \"macro \u002F rates\", \"AI model releases\", \"regulation\"). Each tweet maps to one theme; a `why:` label can seed theme naming for single-topic feeds.\n\n4. **Write a one-sentence take per notable tweet** — what the tweet says, not your opinion of it. Voice per the **Voice** section.\n\n5. **Notify** via `.\u002Fnotify`:\n   ```\n   *Tweet Digest - ${today}*\n\n   *Theme: \u003Ctheme>*\n   @handle: \u003Cone-sentence summary> - [link](url)\n   @handle: \u003Cone-sentence summary> - [link](url)\n\n   *Theme: \u003Ctheme>*\n   ...\n   ```\n   If no notable tweets across all accounts: log `TWEET_DIGEST_OK` and end (no notification).\n\n**Status codes:** `TWEET_DIGEST_OK` (notified or clean) | `TWEET_DIGEST_NO_CONFIG` | `TWEET_DIGEST_NO_KEY`.\n\n---\n\n## Branch: list (`source:list`)\n\nCross-list narrative resonance + signal-scored top tweets from tracked X lists in the past 24h. Lists are *curator signal* — the value is cross-list resonance + insight + a verdict, not a flat top-N-per-list dump.\n\n**Seen set:** `memory\u002Flist-digest-seen.txt` + last 2 days of logs.\n\n1. **Parse and validate `ARG`** in your head, not in a shell script (an `if`\u002F`for` block is refused):\n   - `ARG` empty: log `LIST_DIGEST_NO_CONFIG: var must contain at least one X list ID` to today's `memory\u002Flogs\u002F\u003Cdate>.md` and stop.\n   - `IDS_PART` = the text before the first `|`; `TOPIC_FILTER` = the text after it (empty when there is no `|`).\n   - Split `IDS_PART` on commas into `LIST_ID`s. Any ID that is not all digits: log `LIST_DIGEST_NO_CONFIG: invalid list ID '\u003Cid>' (must be numeric)` and stop.\n\n   If `XAI_API_KEY` is unset, fall back to Path B. If no path returns data, log `LIST_DIGEST_NO_CONFIG: XAI_API_KEY required` and stop without notifying.\n\n2. **Fetch each list's top tweets (past 24h)** - xAI primary, WebSearch fallback.\n   > Note: twitterapi.io has **no `list:` operator** (its advanced_search supports `from:` `to:` `url:` `lang:` `#tag` `@mention` `since:` `until:` only), so this branch keeps the xAI Grok `x_search` path as primary - it is the only path that can read an X list by ID. `TWITTER_API_KEY` does not apply to the `list` source.\n   **Path A - X.AI Responses API** (primary). Get the window dates first, each `date` as its own Bash call: `date -u -d yesterday +%Y-%m-%d` (FROM_DATE) and `date -u +%Y-%m-%d` (TO_DATE). Then build the body and send it in one call (jq piped straight into `.\u002Fsecretcurl`), with the list ID and both dates written in literally:\n   ```bash\n   jq -n '{model:\"grok-4.7\", input:[{role:\"user\",content:\"Look at X list https:\u002F\u002Fx.com\u002Fi\u002Flists\u002F\u003CLIST_ID>. Step 1: report the list name and a one-line description. Step 2: identify the most engaging tweets posted by members of this list between \u003CFROM_DATE> and \u003CTO_DATE> UTC. Return the top 12 tweets ranked by engagement (likes, retweets, replies). For EACH tweet you MUST return: (a) @handle, (b) the full tweet text (not a paraphrase), (c) explicit engagement counts as separate fields - likes:N, retweets:N, replies:N, views:N if available, (d) the direct permalink in the form https:\u002F\u002Fx.com\u002F\u003Chandle>\u002Fstatus\u002F\u003Cid>, (e) media type (image|video|none), (f) one-line context if it is a reply or quote tweet (who\u002Fwhat). Skip retweets of accounts NOT on this list. If a tweet has an image and you can analyze it, include a one-line image description.\"}], tools:[{type:\"x_search\", from_date:\"\u003CFROM_DATE>\", to_date:\"\u003CTO_DATE>\", enable_image_understanding:true}]}' \\\n     | .\u002Fsecretcurl -s -o \u002Ftmp\u002Fxai-list-out.json --max-time 180 -X POST \"https:\u002F\u002Fapi.x.ai\u002Fv1\u002Fresponses\" \\\n     -H \"Content-Type: application\u002Fjson\" \\\n     -H \"Authorization: Bearer {XAI_API_KEY}\" \\\n     --data-binary @-\n   ```\n   Parse with the standard `jq` extractor.\n   **Path B — WebSearch fallback** (only if `XAI_API_KEY` unset, OR Path A errors \u002F returns nothing): `site:x.com \"i\u002Flists\u002F${LIST_ID}\" OR list:${LIST_ID} after:${FROM_DATE}`. Lower quality; mark this list's source as `websearch`.\n   **Per-list outcome:** `ok` (≥3 tweets) | `quiet` (1–2) | `empty` (0, list found but no posts) | `error` (API\u002Faccess failure — note reason).\n\n3. **Build the candidate pool.** Record per tweet `{handle, text, likes, retweets, replies, views, url, list_ids_seen_on:[], list_names_seen_on:[], media, is_reply, is_quote}`. **Dedup by URL across lists** — same tweet on multiple lists → merge records, keep both `list_ids_seen_on` and `list_names_seen_on` (cross-list appearance is a signal). **Dedup against history** — drop URLs in `memory\u002Flist-digest-seen.txt` or the last 2 days of logs.\n\n4. **Score every candidate** (natural-log engagement to stop one viral tweet dominating):\n   ```\n   base = ln(1+likes) + 2.0*ln(1+retweets) + 1.5*ln(1+replies)\n   bonuses:\n     +2.0  appeared on ≥2 distinct lists (cross-list resonance)\n     +1.5  appeared on ≥3 distinct lists\n     +1.0  topic_filter set AND tweet text\u002Fcontext matches (case-insensitive substring or obvious semantic match)\n     +0.5  small-account-signal (≤25k followers per Grok's note OR no follower data + technical\u002Finsider content)\n     +0.3  media is image OR video\n   penalties:\n     -1.0  is_reply AND replied-to NOT on any tracked list\n     -0.5  pure link share with \u003C10 words of original commentary\n   score = base + sum(bonuses) - sum(penalties)\n   ```\n\n5. **Cluster into cross-list narratives** when ALL hold: ≥2 tweets from ≥2 distinct lists; shared ≥2 substantive keywords\u002Fentities (proper nouns, project names, tickers, technical terms — ignore stop words); posted within the same 24h window. `narrative score = sum of constituent tweet scores`; **narrative title** ≤80 chars capturing what the cluster collectively says. Pick an **anchor tweet** (highest individual score) + up to 2 supporting. **Cluster-count cap:** if clustering yields \u003C2 or >4 clusters, fall back to a flat ranked list with inline `[cluster-name]` labels (no \"? Cross-list narratives\" section).\n\n6. **Compose the digest** (cap 4000 chars): up to **3 narratives** at top (by narrative score); then up to **5 standalone tweets per list** (highest individual score, not already in a narrative); hard total cap **12 items** — cut from the bottom of standalones. **Insight discipline:** every item needs a one-line **so-what** (implication, contrarian angle, missing number, deal-flow signal); a paraphrase must be rewritten. **Quiet-list rule:** if a list's top surviving tweet scores \u003C2.0 (≈\u003C8 likes raw), write a one-line \"quiet day\" for that list. **Topic filter** is a scoring booster (step 4), NOT a hard filter. **Verdict line:** one line at the very top capturing what today's lists collectively say.\n\n7. **Send the notification** via `.\u002Fnotify`, verbatim format (`x.com\u002Fhandle`, `[label](url)`):\n   ```\n   *List Digest - ${today}*\n\n   [VERDICT LINE - one line, ≤140 chars, plain text]\n\n   ? *Cross-list narratives*\n   1. *[narrative title]* - appeared on [List A] + [List B]\n      x.com\u002Fhandle: [insight, not paraphrase] (♥ likes, ↻ rt) - [View](url)\n      x.com\u002Fhandle2: [insight] (♥ likes, ↻ rt) - [View](url)\n\n   2. *[narrative title]* - appeared on [List A] + [List C]\n      ...\n\n   *[List Name 1]*\n   - x.com\u002Fhandle - [insight] (♥ likes, ↻ rt) - [View](url)\n   - x.com\u002Fhandle - [insight] (♥ likes, ↻ rt) - [View](url)\n\n   *[List Name 2]*\n   - quiet day\n\n   ---\n   sources: list1=ok | list2=quiet | list3=error(no-access)\n   status: LIST_DIGEST_OK\n   ```\n   If cross-list narratives is empty, drop that whole section. If every list is `quiet`\u002F`empty`, send a single-line \"*List Digest — ${today}* — quiet across all tracked lists\" instead of padding.\n\n8. **Log and persist** (see Log). Append every reported URL (one per line) to `memory\u002Flist-digest-seen.txt` (create if missing).\n\n**Exit taxonomy:** `LIST_DIGEST_NO_CONFIG` (var empty\u002Finvalid OR no fetch path — log only) | `LIST_DIGEST_EMPTY` (every list 0 tweets OR all candidates already seen — log only) | `LIST_DIGEST_PARTIAL` (some lists succeeded\u002Fsome failed — notify survivors, surface failures) | `LIST_DIGEST_OK` (≥1 fresh tweet — notify).\n\n---\n\n## Branch: agent-buzz (`source:agent-buzz`)\n\nA topic-filtered preset: a curated, narrative-aware read on what the AI-agent scene on X talked about in the last 24h. **Curation, not aggregation** — 6 high-signal tweets in 2 clusters beats 10 of mixed noise. `ARG` (optional) is a project\u002Ftopic to prioritize.\n\n**Seen set:** last 3 days of logs — extract every `https:\u002F\u002Fx.com\u002F...\u002Fstatus\u002F\u003Cid>` already posted by this skill; treat those IDs as the dedup set.\n\n1. **Fetch candidates:**\n   Get the window dates first, each `date` as its own Bash call (see **Shell shape** below):\n   ```bash\n   date -u -d '1 day ago' +%Y-%m-%d\n   ```\n   ```bash\n   date -u +%Y-%m-%d\n   ```\n   The first prints FROM_DATE, the second TO_DATE.\n\n   **Path A - twitterapi.io (primary):** structured search over the AI-agents conversation, window inside the query via `since:`, FROM_DATE written in literally:\n   ```bash\n   .\u002Fsecretcurl -s -o \u002Ftmp\u002Ftw-buzz.json -w 'twitterapi http=%{http_code} bytes=%{size_download}\\n' --max-time 60 -G \"https:\u002F\u002Fapi.twitterapi.io\u002Ftwitter\u002Ftweet\u002Fadvanced_search\" \\\n     --data-urlencode 'query=(\"AI agents\" OR \"autonomous agents\" OR \"agent framework\" OR \"agent frameworks\" OR MCP OR \"agent protocol\" OR \"agent benchmark\") since:\u003CFROM_DATE>' \\\n     --data-urlencode \"queryType=Latest\" -H \"X-API-Key: {TWITTER_API_KEY}\"\n   ```\n   On `HTTP=200` with a non-empty `.tweets[]`, parse and mark `source=twitterapi`. Collect up to ~40 candidates (paginate with `&cursor=\u003Cnext_cursor>` while `.has_next_page` if the first page is thin):\n   ```bash\n   jq -r '.tweets[] | [.id, .author.userName, .author.isBlueVerified, .text, .url, .createdAt, .likeCount, .retweetCount, .replyCount] | @tsv' \u002Ftmp\u002Ftw-buzz.json\n   ```\n   Note: advanced_search does **not** return `follower_count` or `role_guess`. On this path treat both as null (the step-3 role multiplier and the follower-ratio skip-gates simply don't fire); use `.author.isBlueVerified` as a weak credibility proxy and lean on raw engagement. If `ARG` is set, append its terms to the query (AND) or issue a second constrained search and merge.\n\n   **Path B - xAI Grok x_search (fallback)** (only if Path A returned non-2xx \u002F empty \u002F timeout, or `TWITTER_API_KEY` unset; the response for each tweet **must** include explicit engagement counts + follower count, or step 3 scoring can't run):\n   ```bash\n   jq -n '{model:\"grok-4.7\", input:[{role:\"user\",content:\"Search X from \u003CFROM_DATE> to \u003CTO_DATE> for tweets in the AI-agents conversation: autonomous agents, agent frameworks, MCP \u002F agent protocols, agent products, agent benchmarks, agent research papers. Return up to 40 candidates. For EACH candidate you MUST return: @handle, follower_count (integer or null), role_guess (builder|founder|researcher|investor|commentator|anon), one-line claim (what they actually said - not a paraphrase, the thesis), likes (int), retweets (int), replies (int), posted_at (ISO), direct_link (https:\u002F\u002Fx.com\u002Fusername\u002Fstatus\u002FID). Prefer builders\u002Ffounders\u002Fresearchers. Skip obvious engagement-farming threads (\\\"RT if you agree\\\", reply-guy pileons, giveaways).\"}], tools:[{type:\"x_search\", from_date:\"\u003CFROM_DATE>\", to_date:\"\u003CTO_DATE>\"}]}' \\\n     | .\u002Fsecretcurl -s -o \u002Ftmp\u002Fxai-buzz-out.json -X POST \"https:\u002F\u002Fapi.x.ai\u002Fv1\u002Fresponses\" \\\n     -H \"Content-Type: application\u002Fjson\" \\\n     -H \"Authorization: Bearer {XAI_API_KEY}\" \\\n     --data-binary @-\n   ```\n   Parse with the standard `jq` extractor. Record `source=xai`.\n   **Path C - WebSearch (last resort)** (only if Paths A and B both error\u002Fempty, or no key set): forced-fresh query `\"AI agents twitter today ${today}\"` - discard anything >48h old, expect degraded metadata. Record `source=websearch`.\n\n   If `ARG` is set, also issue a second call constrained to that topic with the same schema; merge results.\n\n2. **Skip-gates** (before clustering) — drop any candidate matching ANY:\n   - **Dup:** `status\u002F\u003Cid>` already in the 3-day dedup set.\n   - **Engagement-farming:** poll threads, \"bookmark this\", \"drop a ?\", reply-guy pileons with \u003Cfollower_count\u002F10 likes.\n   - **Self-promo only:** pure product shill with no claim\u002Fbenchmark\u002Fdatapoint. Launch tweets OK IF they include a concrete capability claim or number.\n   - **Staleness:** `posted_at` older than 30h.\n   - **Anon + low engagement:** role_guess=anon AND (likes+retweets) \u003C 200.\n\n3. **Signal scoring:** `signal = likes + 2*retweets + replies`, then × 1.3 if role_guess ∈ {builder, founder, researcher}; × 0.7 if a pure hot-take with no concrete referent (no named project, number, paper, or bench); × 0.5 if near-duplicate of another survivor (keep the higher-scored one only).\n\n4. **Narrative clustering:** group survivors into **2–4 narrative clusters** — a cluster is a shared *thesis*, not a keyword (\"MCP vendor lock-in debate\", not \"MCP\"). Name each ≤5 words. If one cluster holds >60% of tweets, split it. A tweet fitting no cluster is dropped unless its signal is top-3 overall. Target: **2–4 clusters, 2–3 tweets each, 6–9 total (strictly ≤10).**\n\n5. **Insight extraction** — per tweet, a one-line **insight** (≤20 words): the actual claim\u002Fdatapoint, not a paraphrase; if opinion, state *what they're arguing against*; if an announcement, state *what's new vs. prior art* (not \"X launched\"). **Anti-hype lint** — rewrite any insight containing: `game-changing`, `revolutionary`, `mind-blowing`, `wild`, `huge`, `massive`, `unreal`, `insane`, vague \"AI agents are evolving\", \"the future of X\".\n\n6. **Conversation-shape lead** — one opening sentence (≤25 words) naming what the conversation was actually about (\"Mostly protocol debate — MCP vs. A2A — with two concrete launches on the side.\"). If you can't characterize it honestly in one sentence, the clustering is wrong — redo step 4.\n\n7. **Notify** via `.\u002Fnotify`:\n   ```\n   *Agent Buzz - ${today}*\n   _\u003Cconversation-shape one-liner>_\n\n   **\u003CCluster 1 name>**\n   • @handle - \u003Cinsight>\n     \u003Clink>\n   • @handle - \u003Cinsight>\n     \u003Clink>\n\n   **\u003CCluster 2 name>**\n   • @handle - \u003Cinsight>\n     \u003Clink>\n\n   \u003C!-- _src: xai|websearch · candidates: N → kept: M_ -->\n   ```\n   Keep the footer — it's how future self-audits debug empty days. Never pad to hit 10. 6 good > 10 mid.\n\n**Status codes:** `AGENT_BUZZ_OK` (≥1 cluster notified) | `AGENT_BUZZ_EMPTY` (fetch succeeded, nothing survived — send `Agent Buzz — ${today}: quiet day, no survivors.`) | `AGENT_BUZZ_ERROR` (all sources failed — notify `Agent Buzz — ${today}: all sources failed (${error summary}).` and log the per-source failure).\n\n---\n\n## Log (all branches)\n\nAppend ONE entry per run to `memory\u002Flogs\u002F${today}.md` under a single `### fetch-tweets` heading (the health loop parses this shape). The first bullet is the **discriminator** naming the branch\u002Fmode that ran; the rest are branch-specific bullets. Always include the reported tweet URLs as bullets (for next-run dedup).\n\n```\n### fetch-tweets\n- mode: \u003Ckeyword|topic|account|list|agent-buzz>\n- status: \u003CSTATUS_CODE for the branch that ran>\n- source: \u003CSOURCE_PATH \u002F per-source counts \u002F per-list outcome, as applicable>\n- \u003Cbranch-specific bullets - carry over each branch's fields:>\n    - keyword:     signal one-liner; per-cluster URLs with `likes:N rts:N replies:N` + insight\n    - topic:       `topics: [t1: N tweets, t2: 0 (dropped)]`; `source: cache:X websearch:Y failed:Z`\n    - account(1):  Verdict + lede; Counts (N tweets, X orig\u002FY reply\u002FZ quote, T threads, deduped K); Clusters; Threads; Vibe\n    - account(all):themes covered; per-account tweet counts\n    - list:        Lists tracked; Per-list `list1=ok(N) | list2=quiet(N) | list3=error`; Verdict; Narratives count\n    - agent-buzz:  source used; candidates N → kept M; cluster names\n- urls:\n    - https:\u002F\u002Fx.com\u002Fhandle1\u002Fstatus\u002F...\n    - https:\u002F\u002Fx.com\u002Fhandle2\u002Fstatus\u002F...\n```\n\nOn empty\u002Fno-new\u002Ferror\u002Fno-config statuses, write the `### fetch-tweets` heading + `mode:` + `status:` bullets only (skip the detail sections) so skill-health still observes the run. After logging, update the branch's persistent seen-file where one exists (keyword \u002F topic \u002F list — see the seen-file table).\n\n## Output shape note\n\nNo chain consumes this skill's output as of this commit (no `consume: [fetch-tweets]` references). If a downstream chain step starts consuming it, emit a flat list of URLs before the clustered\u002Fbranch output so consumers aren't broken by cluster or narrative headers.\n\n## Fetching (all branches)\n\n**Shell shape.** Each Bash call is one allowed command (pipes are fine). The run refuses a call that sets a variable (`FROM_DATE=$(date ...)`, `HTTP=$(.\u002Fsecretcurl ...)`), uses `if` \u002F `for` \u002F `while`, or joins commands with `;`, `&&` or `||`, and each refusal costs a model turn. So get a date with a bare `date` call and write the printed value into later commands; write `ARG`, handles, topics and dates into each command literally (the `\u003CFROM_DATE>`, `\u003CHANDLE>` style placeholders in the snippets); run one `jq` per call; loop over handles or topics by making one call per item. The run also refuses any redirect into a file (`> \u002Ftmp\u002Fx.json`, `cat > f`) and any `$name` in a jq filter (`--arg FROM ... '... $FROM'`), in both tiers: write each value into the jq filter as a JSON string (`>= \"\u003CFROM_2D>\"`; a `\"` inside a value becomes `\\\"`, and reword any `'`), and pipe a request body straight into `.\u002Fsecretcurl ... --data-binary @-`.\n\nEvery branch fetches X in a **three-tier cascade**. Attempt each tier in order; only drop to the next on a *real* failure (non-2xx, empty body, or timeout), and always record the true reason.\n\n**Path A - twitterapi.io (primary).** `TWITTER_API_KEY` is **injected into your environment** for this skill (declared in `requires:`). The primary fetch path in every branch (except `list`, which has no twitterapi list operator) is a direct `curl` to `https:\u002F\u002Fapi.twitterapi.io\u002Ftwitter\u002F...` with the `X-API-Key: {TWITTER_API_KEY}` header. It is fast (~700ms), returns **structured ground-truth** JSON with **exact engagement counts** and **real permalinks** (`.url`) - so there is no fabrication risk and no prompt to coax. Two endpoints:\n- **Search:** `GET \u002Ftweet\u002Fadvanced_search?query=\u003Cq>&queryType=Latest` -> `{tweets:[...], has_next_page, next_cursor}`. Put date windows **inside** the query with X operators `since:YYYY-MM-DD until:YYYY-MM-DD`; other operators: `from:` `to:` `url:` `lang:` `#tag` `@mention`, plus OR\u002FAND and quotes. Tweets are under `.tweets[]`. (There is **no** `list:` operator - see the `list` branch.)\n- **Timeline:** `GET \u002Fuser\u002Flast_tweets?userName=\u003Chandle>` -> `{status:\"success\", data:{tweets:[...]}, has_next_page, next_cursor}`. No server-side date filter - filter client-side on `.createdAt` or paginate with `&cursor=\u003Cnext_cursor>`. Tweets are under `.data.tweets[]`.\n\nFields: `id, text, url, createdAt, likeCount, retweetCount, replyCount, quoteCount, viewCount, author.userName, author.name, author.isBlueVerified` (last_tweets also `isReply`, `author.followers`). Capture the status with `-w 'twitterapi http=%{http_code} bytes=%{size_download}\\n'` (curl prints it, so no `HTTP=$(...)` wrapper) and **read the `http=\u003Ccode>` line before deciding anything.** `HTTP=200` with a non-empty tweet array -> use it (`SOURCE_PATH=twitterapi`). No prefetch, no cache - just make the call.\n\n**Path B - xAI Grok x_search (fallback).** Only when Path A fails (non-2xx \u002F empty \u002F timeout) or `TWITTER_API_KEY` is unset. Direct `curl` to `https:\u002F\u002Fapi.x.ai\u002Fv1\u002Fresponses` with `Authorization: Bearer {XAI_API_KEY}` using Grok's `x_search` tool. The `x_search` call typically takes 30-120s (it searches X live), so **set the Bash tool `timeout` to at least 180000 (180s)** and add **`--max-time 150`** to the curl so it fails cleanly rather than hanging. A slow curl is **not** a missing key. Build the JSON body with `jq -n` (prompt and dates written into the filter literally) and pipe it straight into `.\u002Fsecretcurl` in the same call (its body flag reads stdin) - every `.\u002Fsecretcurl` command must be 100% literal (no shell variables, or the permission layer blocks it). Parse with the standard extractor:\n   ```bash\n   jq -r '.output[] | select(.type == \"message\") | .content[] | select(.type == \"output_text\") | .text' \u002Ftmp\u002Fxai.json\n   ```\n`HTTP=200` with a non-empty body -> use it (`SOURCE_PATH=api`).\n\n**Path C - WebSearch \u002F WebFetch (last resort).** Only when both A and B fail (or no key is set at all). Lowest quality (WebSearch favours old high-engagement tweets; WebFetch reads a public profile page). Never reach for it while a key works.\n\n**Reason codes** (record the true one on every fallback - never write \"XAI_API_KEY unavailable\" \u002F \"sandbox\" \u002F \"expansion blocked\" when a key was set): `key-unset` (the relevant key was actually empty), `http-\u003Ccode>` (non-2xx), `empty` (200 but no tweets parsed), `timeout` (curl exceeded `--max-time`).\n\n## Environment Variables\n\n- `TWITTER_API_KEY` - twitterapi.io API key (sent as the `X-API-Key` header). Declared in `requires:`, so it is **injected into this skill's environment**; it is the **primary** fetch path for every branch except `list` (twitterapi has no list operator). Fast, structured ground-truth with exact engagement counts and real permalinks.\n- `XAI_API_KEY` - X.AI API key for Grok's `x_search` tool (declared `XAI_API_KEY?`, optional). The **fallback** path when `TWITTER_API_KEY` is unset or twitterapi returns non-2xx \u002F empty \u002F timeout, and the **primary** path for the `list` branch. If both keys are unset, branches degrade to WebSearch\u002FWebFetch at lower quality; the `account (all)` sub-mode instead hard-exits (`TWEET_DIGEST_NO_KEY`).\n",{"name":5,"metadata":47,"description":7},{"var":48,"tags":49,"title":50,"category":26,"requires":51},"",[32],"Fetch Tweets",[52,53],"TWITTER_API_KEY","XAI_API_KEY?","main","504a21d53c0c9b485f6e90c43db83000825e1d3c","skills\u002Ffetch-tweets",308,"https:\u002F\u002Fgithub.com\u002Faeonfun\u002Faeon","https:\u002F\u002Fwww.aeon.fun\u002F","https:\u002F\u002Fgithub.com\u002Faeonfun","The most autonomous agent framework.","2026-11-15 03:40:18",{"source":8,"skillName":5,"commands":64,"prompt":74,"zipAvailable":75},[65,68,71],{"tool":66,"command":67},"npx","npx skills add aeonfun\u002Faeon --skill fetch-tweets",{"tool":69,"command":70},"bunx","bunx skills add aeonfun\u002Faeon --skill fetch-tweets",{"tool":72,"command":73},"pnpm","pnpm dlx skills add aeonfun\u002Faeon --skill fetch-tweets","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Faeonfun\u002Faeon\u002Fblob\u002Fmain\u002Fskills\u002Ffetch-tweets\u002FSKILL.md",true,[],[78,85,91,97,103,109],{"skillNo":79,"name":80,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":84},"01M7DSM3QWBJ44FKRMDDRAGNET","Warn Mixed Script","https:\u002F\u002Fgithub.com\u002Faeonfun\u002Faeon\u002Fblob\u002Fmain\u002Fscripts\u002Ftests\u002Fskill-scan-fixtures\u002Fwarn-mixed-script\u002FSKILL.md",[],[],"2026-11-15 14:19:17",{"skillNo":86,"name":87,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":84},"01M7DSM0496DRYYW5A4NAAHZDX","Warn Hidden CSS","https:\u002F\u002Fgithub.com\u002Faeonfun\u002Faeon\u002Fblob\u002Fmain\u002Fscripts\u002Ftests\u002Fskill-scan-fixtures\u002Fwarn-hidden-css\u002FSKILL.md",[],[],{"skillNo":92,"name":93,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":84},"01M7DSKWCGDVYZSDJM31YHS2JB","Malicious Injection Uppercase","https:\u002F\u002Fgithub.com\u002Faeonfun\u002Faeon\u002Fblob\u002Fmain\u002Fscripts\u002Ftests\u002Fskill-scan-fixtures\u002Fmalicious-injection-uppercase\u002FSKILL.md",[],[],{"skillNo":98,"name":99,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":100,"categories":101,"keywords":102,"publishedAt":84},"01M7DSKRV2RRA1V0HK13KYWJXD","Malicious Injection Homoglyph","https:\u002F\u002Fgithub.com\u002Faeonfun\u002Faeon\u002Fblob\u002Fmain\u002Fscripts\u002Ftests\u002Fskill-scan-fixtures\u002Fmalicious-injection-homoglyph\u002FSKILL.md",[],[],{"skillNo":104,"name":105,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":106,"categories":107,"keywords":108,"publishedAt":84},"01M7DSKMXJKY0167YHVCKF7B49","Malicious Injection Disregard Prior","https:\u002F\u002Fgithub.com\u002Faeonfun\u002Faeon\u002Fblob\u002Fmain\u002Fscripts\u002Ftests\u002Fskill-scan-fixtures\u002Fmalicious-injection-disregard-prior\u002FSKILL.md",[],[],{"skillNo":110,"name":111,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":112,"categories":113,"keywords":114,"publishedAt":84},"01M7DSKGFQ5V2VNSA4K97CVFMB","Benign Greek Math","https:\u002F\u002Fgithub.com\u002Faeonfun\u002Faeon\u002Fblob\u002Fmain\u002Fscripts\u002Ftests\u002Fskill-scan-fixtures\u002Fbenign-greek-math\u002FSKILL.md",[],[]]