canghe-danger-x-to-markdown
Converts X (Twitter) tweets and articles to markdown with YAML front matter. Uses reverse-engineered API requiring user consent. Use when user mentions "X to markdown", "tweet to markdown", "save tweet", or provides x.com/twitter.com URLs for conversion.
1How It Works & Mechanism
Core mechanism relies on a reverse-engineered X API: SKILL.md states it uses a reverse-engineered X API to extract tweets, threads, and Articles into markdown.
This tool uses a reverse-engineered X API, NOT official.
Distinct extraction paths for three content types: Regular tweets and threads are converted into markdown with YAML front matter, while X Articles undergo full-text entity extraction.
- Tweets/threads → Markdown with YAML front matter
Implementation of Article full-text extraction: It first attempts to use the embedded article entity in the tweet; if unavailable, it parses the article id from the URL and fetches it independently via fetchXArticle.
const fetched = await fetchXArticle(articleId, cookieMap, false);
Authentication relies on user account cookies: It prioritizes environment variables X_AUTH_TOKEN / X_CT0, falling back to Chrome login and local cookie caching.
1. **Environment variables** (preferred): `X_AUTH_TOKEN`, `X_CT0`
Retrieved cookies are persisted to cookies.json: cookie-file.ts writes JSON in the structure version/updatedAt/cookieMap, with paths resolved cross-platform by paths.ts.
await writeFile(p, JSON.stringify(payload, null, 2), "utf8");
Media localization is optional: Enabling --download-media downloads images/videos to imgs/ and videos/ alongside the markdown, rewriting links to relative paths.
| `--download-media` | Download image/video assets to local `imgs/` and `videos/`, and rewrite markdown links to local relative paths |
Media processing defaults to "generate markdown first, ask later": It first runs without download parameters, asks only if remote media URLs remain in the output, and reruns to overwrite links upon confirmation.
5. If user confirms → run script **again** with `--download-media` (overwrites markdown with localized links)
EXTEND.md first-time setup is implemented as a blocking operation: When missing, it must interactively prompt for preferences (media policy, output directory, save location); silent defaults are prohibited.
**CRITICAL**: When EXTEND.md is not found, you **MUST use `AskUserQuestion`** to ask the user for their preferences before creating EXTEND.md.
Reverse-engineering usage requires a consent gate: If the consent file is missing or versions mismatch, a disclaimer is displayed; if the user rejects it, an exit message is printed and execution stops.
**Step 5**: On decline → output "User declined. Exiting." and stop.
Data directory is resolved per platform: paths.ts uses XDG_DATA_HOME (or ~/.local/share) on Linux, Application Support on macOS, and APPDATA on Windows.
return process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share");
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| network | x.com(登录流程与逆向 API 请求) |
| network | pbs.twimg.com(推文图片资源,出现在输出样例 coverImage) |
| cli | bun / npx(以 npx -y bun 运行脚本) |
| cli | 本机 Chrome/Chromium(回落到浏览器登录时 spawn 以取 cookie) |
4Recommended Governance & Evidence
- SKILL.md / 脚本: Calls undisclosed or reverse-engineered private APIs / spoofs client identifiers
- SKILL.md / 脚本参数: Contains logic to bypass automation detection, disable host sandboxes, or skip SSL certificate validation
- SKILL.md / 会话存储: Reads or reuses browser user session cookies and login states
- 本地凭据 / 浏览器配置: Reads user login cookies/sessions/keyrings: Account cookies: X_AUTH_TOKEN / X_CT0 (env prioritized), local cookies.json next, and finally via Chrome login retrieval (sk
- scripts/: Executes local scripts or commands: scripts/main.ts (run via npx -y bun; spawns Chrome to read cookies during browser login fallback)
- 网络端点: Declares external network access: https://x.com/home (login flow, X_LOGIN_URL in constants.ts)
- 本地工作目录: File read/write and artifact output: x-to-markdown/{username}/{tweet-id}.md (or path specified by -o)
5Second-Pass Verification
- [ok] 逆向 API 而非官方 API(red 主因之一) — SKILL.md 有 DISCLAIMER「This tool uses a reverse-engineered X API, NOT official.」,并据此设 consent 门禁。
- [ok] 读取账号 cookie(red 主因之二) — SKILL.md 列出环境变量 X_AUTH_TOKEN/X_CT0 为首选来源、Chrome 登录为兜底;cookies.ts 内含 child_process spawn。
- [ok] 媒体下载范围受限 — --download-media 为显式开关,ask 流程要求先出 markdown 再询问,非默认批量下载。
- [ok] 两道用户门禁 — consent.json(accepted + disclaimerVersion)与 EXTEND.md 首次设置(BLOCKING,禁止静默默认)均在 SKILL.md 写明。
- [ok] 数据目录跨平台解析 — paths.ts 按 win32/darwin/其他分派 APPDATA / Application Support / XDG_DATA_HOME,并支持 X_DATA_DIR 等覆盖。
- [unlocatable] GraphQL 与媒体模块内部实现 — graphql.ts / media-localizer.ts 正文未在证据包展开,仅依据 §1 文件清单与 §3 扫描行定位其存在与职责;未据此提升或降低档位。
6Verdict & Scenarios
f839fffff58e69c9…