Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Convert X (Twitter) tweets, threads, and articles to Markdown with YAML front matter via reverse-engineered API.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: baoyu-danger-x-to-markdown3description: 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.4version: 1.56.15metadata:6openclaw:7homepage: https://github.com/JimLiu/baoyu-skills#baoyu-danger-x-to-markdown8requires:9anyBins:10- bun11- npx12---1314# X to Markdown1516Converts X content to markdown:17- Tweets/threads → Markdown with YAML front matter18- X Articles → Full content extraction1920## User Input Tools2122When this skill prompts the user, follow this tool-selection rule (priority order):23241. **Prefer built-in user-input tools** exposed by the current agent runtime — e.g., `AskUserQuestion`, `request_user_input`, `clarify`, `ask_user`, or any equivalent.252. **Fallback**: if no such tool exists, emit a numbered plain-text message and ask the user to reply with the chosen number/answer for each question.263. **Batching**: if the tool supports multiple questions per call, combine all applicable questions into a single call; if only single-question, ask them one at a time in priority order.2728Concrete `AskUserQuestion` references below are examples — substitute the local equivalent in other runtimes.2930## Script Directory3132Scripts located in `scripts/` subdirectory.3334**Path Resolution**:351. `{baseDir}` = this SKILL.md's directory362. Script path = `{baseDir}/scripts/main.ts`373. Resolve `${BUN_X}` runtime: if `bun` installed → `bun`; if `npx` available → `npx -y bun`; else suggest installing bun3839## Consent Requirement4041**Before any conversion**, check and obtain consent.4243### Consent Flow4445**Step 1**: Check consent file4647```bash48# macOS49cat ~/Library/Application\ Support/baoyu-skills/x-to-markdown/consent.json5051# Linux52cat ~/.local/share/baoyu-skills/x-to-markdown/consent.json53```5455**Step 2**: If `accepted: true` and `disclaimerVersion: "1.0"` → print warning and proceed:56```57Warning: Using reverse-engineered X API. Accepted on: <acceptedAt>58```5960**Step 3**: If missing or version mismatch → display disclaimer:61```62DISCLAIMER6364This tool uses a reverse-engineered X API, NOT official.6566Risks:67- May break if X changes API68- No guarantees or support69- Possible account restrictions70- Use at your own risk7172Accept terms and continue?73```7475Use `AskUserQuestion` with options: "Yes, I accept" | "No, I decline"7677**Step 4**: On accept → create consent file:78```json79{80"version": 1,81"accepted": true,82"acceptedAt": "<ISO timestamp>",83"disclaimerVersion": "1.0"84}85```8687**Step 5**: On decline → output "User declined. Exiting." and stop.8889## Preferences (EXTEND.md)9091Check EXTEND.md in priority order — the first one found wins:9293| Priority | Path | Scope |94|----------|------|-------|95| 1 | `.baoyu-skills/baoyu-danger-x-to-markdown/EXTEND.md` | Project |96| 2 | `${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-danger-x-to-markdown/EXTEND.md` | XDG |97| 3 | `$HOME/.baoyu-skills/baoyu-danger-x-to-markdown/EXTEND.md` | User home |9899| Result | Action |100|--------|--------|101| Found | Read, parse, apply settings |102| Not found | **MUST** run first-time setup (see below) — do NOT silently create defaults |103104**EXTEND.md supports**: Download media by default, default output directory.105106### First-Time Setup (BLOCKING)107108**CRITICAL**: When EXTEND.md is not found, you **MUST use `AskUserQuestion`** to ask the user for their preferences before creating EXTEND.md. **NEVER** create EXTEND.md with defaults without asking. This is a **BLOCKING** operation — do NOT proceed with any conversion until setup is complete.109110Use `AskUserQuestion` with ALL questions in ONE call:111112**Question 1** — header: "Media", question: "How to handle images and videos in tweets?"113- "Ask each time (Recommended)" — After saving markdown, ask whether to download media114- "Always download" — Always download media to local imgs/ and videos/ directories115- "Never download" — Keep original remote URLs in markdown116117**Question 2** — header: "Output", question: "Default output directory?"118- "x-to-markdown (Recommended)" — Save to ./x-to-markdown/{username}/{tweet-id}.md119- (User may choose "Other" to type a custom path)120121**Question 3** — header: "Save", question: "Where to save preferences?"122- "User (Recommended)" — ~/.baoyu-skills/ (all projects)123- "Project" — .baoyu-skills/ (this project only)124125After user answers, create EXTEND.md at the chosen location, confirm "Preferences saved to [path]", then continue.126127Full reference: [references/config/first-time-setup.md](references/config/first-time-setup.md)128129### Supported Keys130131| Key | Default | Values | Description |132|-----|---------|--------|-------------|133| `download_media` | `ask` | `ask` / `1` / `0` | `ask` = prompt each time, `1` = always download, `0` = never |134| `default_output_dir` | empty | path or empty | Default output directory (empty = `./x-to-markdown/`) |135136**Value priority**:1371. CLI arguments (`--download-media`, `-o`)1382. EXTEND.md1393. Skill defaults140141## Usage142143```bash144${BUN_X} {baseDir}/scripts/main.ts <url>145${BUN_X} {baseDir}/scripts/main.ts <url> -o output.md146${BUN_X} {baseDir}/scripts/main.ts <url> --download-media147${BUN_X} {baseDir}/scripts/main.ts <url> --json148```149150## Options151152| Option | Description |153|--------|-------------|154| `<url>` | Tweet or article URL |155| `-o <path>` | Output path |156| `--json` | JSON output |157| `--download-media` | Download image/video assets to local `imgs/` and `videos/`, and rewrite markdown links to local relative paths |158| `--login` | Refresh cookies only |159160## Supported URLs161162- `https://x.com/<user>/status/<id>`163- `https://twitter.com/<user>/status/<id>`164- `https://x.com/i/article/<id>`165166## Output167168```markdown169---170url: "https://x.com/user/status/123"171author: "Name (@user)"172tweetCount: 3173coverImage: "https://pbs.twimg.com/media/example.jpg"174---175176Content...177```178179**File structure**: `x-to-markdown/{username}/{tweet-id}/{content-slug}.md`180181When `--download-media` is enabled:182- Images are saved to `imgs/` next to the markdown file183- Videos are saved to `videos/` next to the markdown file184- Markdown media links are rewritten to local relative paths185186## Media Download Workflow187188Based on `download_media` setting in EXTEND.md:189190| Setting | Behavior |191|---------|----------|192| `1` (always) | Run script with `--download-media` flag |193| `0` (never) | Run script without `--download-media` flag |194| `ask` (default) | Follow the ask-each-time flow below |195196### Ask-Each-Time Flow1971981. Run script **without** `--download-media` → markdown saved1992. Check saved markdown for remote media URLs (`https://` in image/video links)2003. **If no remote media found** → done, no prompt needed2014. **If remote media found** → use `AskUserQuestion`:202- header: "Media", question: "Download N images/videos to local files?"203- "Yes" — Download to local directories204- "No" — Keep remote URLs2055. If user confirms → run script **again** with `--download-media` (overwrites markdown with localized links)206207## Authentication2082091. **Environment variables** (preferred): `X_AUTH_TOKEN`, `X_CT0`2102. **Chrome login** (fallback): Auto-opens Chrome, caches cookies locally211212## Extension Support213214Custom configurations via EXTEND.md. See **Preferences** section for paths and supported options.215