{"id":"baoyu-danger-x-to-markdown","name":"baoyu-danger-x-to-markdown","summary":"X(Twitter)のツイートや記事をYAMLのフロントマターで割引価格に変換します。ユーザーの同意を必要とするリバースエンジニアリングAPIを使用しています。","body":"# X to Markdown\n\nConverts X content to markdown:\n- Tweets/threads → Markdown with YAML front matter\n- X Articles → Full content extraction\n\n## User Input Tools\n\nWhen this skill prompts the user, follow this tool-selection rule (priority order):\n\n1. **Prefer built-in user-input tools** exposed by the current agent runtime — e.g., `AskUserQuestion`, `request_user_input`, `clarify`, `ask_user`, or any equivalent.\n2. **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.\n3. **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.\n\nConcrete `AskUserQuestion` references below are examples — substitute the local equivalent in other runtimes.\n\n## Script Directory\n\nScripts located in `scripts/` subdirectory.\n\n**Path Resolution**:\n1. `{baseDir}` = this SKILL.md's directory\n2. Script path = `{baseDir}/scripts/main.ts`\n3. Resolve `${BUN_X}` runtime: if `bun` installed → `bun`; if `npx` available → `npx -y bun`; else suggest installing bun\n\n## Consent Requirement\n\n**Before any conversion**, check and obtain consent.\n\n### Consent Flow\n\n**Step 1**: Check consent file\n\n```bash\n# macOS\ncat ~/Library/Application\\ Support/baoyu-skills/x-to-markdown/consent.json\n\n# Linux\ncat ~/.local/share/baoyu-skills/x-to-markdown/consent.json\n```\n\n**Step 2**: If `accepted: true` and `disclaimerVersion: \"1.0\"` → print warning and proceed:\n```\nWarning: Using reverse-engineered X API. Accepted on: <acceptedAt>\n```\n\n**Step 3**: If missing or version mismatch → display disclaimer:\n```\nDISCLAIMER\n\nThis tool uses a reverse-engineered X API, NOT official.\n\nRisks:\n- May break if X changes API\n- No guarantees or support\n- Possible account restrictions\n- Use at your own risk\n\nAccept terms and continue?\n```\n\nUse `AskUserQuestion` with options: \"Yes, I accept\" | \"No, I decline\"\n\n**Step 4**: On accept → create consent file:\n```json\n{\n  \"version\": 1,\n  \"accepted\": true,\n  \"acceptedAt\": \"<ISO timestamp>\",\n  \"disclaimerVersion\": \"1.0\"\n}\n```\n\n**Step 5**: On decline → output \"User declined. Exiting.\" and stop.\n\n## Preferences (EXTEND.md)\n\nCheck EXTEND.md in priority order — the first one found wins:\n\n| Priority | Path | Scope |\n|----------|------|-------|\n| 1 | `.baoyu-skills/baoyu-danger-x-to-markdown/EXTEND.md` | Project |\n| 2 | `${XDG_CONFIG_HOME:-$HOME/.config}/baoyu-skills/baoyu-danger-x-to-markdown/EXTEND.md` | XDG |\n| 3 | `$HOME/.baoyu-skills/baoyu-danger-x-to-markdown/EXTEND.md` | User home |\n\n| Result | Action |\n|--------|--------|\n| Found | Read, parse, apply settings |\n| Not found | **MUST** run first-time setup (see below) — do NOT silently create defaults |\n\n**EXTEND.md supports**: Download media by default, default output directory.\n\n### First-Time Setup (BLOCKING)\n\n**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.\n\nUse `AskUserQuestion` with ALL questions in ONE call:\n\n**Question 1** — header: \"Media\", question: \"How to handle images and videos in tweets?\"\n- \"Ask each time (Recommended)\" — After saving markdown, ask whether to download media\n- \"Always download\" — Always download media to local imgs/ and videos/ directories\n- \"Never download\" — Keep original remote URLs in markdown\n\n**Question 2** — header: \"Output\", question: \"Default output directory?\"\n- \"x-to-markdown (Recommended)\" — Save to ./x-to-markdown/{username}/{tweet-id}.md\n- (User may choose \"Other\" to type a custom path)\n\n**Question 3** — header: \"Save\", question: \"Where to save preferences?\"\n- \"User (Recommended)\" — ~/.baoyu-skills/ (all projects)\n- \"Project\" — .baoyu-skills/ (this project only)\n\nAfter user answers, create EXTEND.md at the chosen location, confirm \"Preferences saved to [path]\", then continue.\n\nFull reference: [references/config/first-time-setup.md](references/config/first-time-setup.md)\n\n### Supported Keys\n\n| Key | Default | Values | Description |\n|-----|---------|--------|-------------|\n| `download_media` | `ask` | `ask` / `1` / `0` | `ask` = prompt each time, `1` = always download, `0` = never |\n| `default_output_dir` | empty | path or empty | Default output directory (empty = `./x-to-markdown/`) |\n\n**Value priority**:\n1. CLI arguments (`--download-media`, `-o`)\n2. EXTEND.md\n3. Skill defaults\n\n## Usage\n\n```bash\n${BUN_X} {baseDir}/scripts/main.ts <url>\n${BUN_X} {baseDir}/scripts/main.ts <url> -o output.md\n${BUN_X} {baseDir}/scripts/main.ts <url> --download-media\n${BUN_X} {baseDir}/scripts/main.ts <url> --json\n```\n\n## Options\n\n| Option | Description |\n|--------|-------------|\n| `<url>` | Tweet or article URL |\n| `-o <path>` | Output path |\n| `--json` | JSON output |\n| `--download-media` | Download image/video assets to local `imgs/` and `videos/`, and rewrite markdown links to local relative paths |\n| `--login` | Refresh cookies only |\n\n## Supported URLs\n\n- `https://x.com/<user>/status/<id>`\n- `https://twitter.com/<user>/status/<id>`\n- `https://x.com/i/article/<id>`\n\n## Output\n\n```markdown\n---\nurl: \"https://x.com/user/status/123\"\nauthor: \"Name (@user)\"\ntweetCount: 3\ncoverImage: \"https://pbs.twimg.com/media/example.jpg\"\n---\n\nContent...\n```\n\n**File structure**: `x-to-markdown/{username}/{tweet-id}/{content-slug}.md`\n\nWhen `--download-media` is enabled:\n- Images are saved to `imgs/` next to the markdown file\n- Videos are saved to `videos/` next to the markdown file\n- Markdown media links are rewritten to local relative paths\n\n## Media Download Workflow\n\nBased on `download_media` setting in EXTEND.md:\n\n| Setting | Behavior |\n|---------|----------|\n| `1` (always) | Run script with `--download-media` flag |\n| `0` (never) | Run script without `--download-media` flag |\n| `ask` (default) | Follow the ask-each-time flow below |\n\n### Ask-Each-Time Flow\n\n1. Run script **without** `--download-media` → markdown saved\n2. Check saved markdown for remote media URLs (`https://` in image/video links)\n3. **If no remote media found** → done, no prompt needed\n4. **If remote media found** → use `AskUserQuestion`:\n   - header: \"Media\", question: \"Download N images/videos to local files?\"\n   - \"Yes\" — Download to local directories\n   - \"No\" — Keep remote URLs\n5. If user confirms → run script **again** with `--download-media` (overwrites markdown with localized links)\n\n## Authentication\n\n1. **Environment variables** (preferred): `X_AUTH_TOKEN`, `X_CT0`\n2. **Chrome login** (fallback): Auto-opens Chrome, caches cookies locally\n\n## Extension Support\n\nCustom configurations via EXTEND.md. See **Preferences** section for paths and supported options.","author":"@JimLiu","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/JimLiu/baoyu-skills/tree/main/skills/baoyu-danger-x-to-markdown","license":"MIT","category":null,"lang":"en","tokens":1793,"stars":0,"calls30d":1,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[{"path":"references/config/first-time-setup.md","size":2491,"sha256":"61db3aa0512d452163903d0b40c7d4062372e10df2053570a1a89ed656718800"},{"path":"scripts/bun.lock","size":392,"sha256":"c8cc8b87fd2f0513b7ce773237c47378712dd0690a1f6af457e933dfe85cf798"},{"path":"scripts/constants.ts","size":6708,"sha256":"67a30bea893af9a23ae6c8525bcff2466dcf11a1663bd74718dc7234ad63d758"},{"path":"scripts/cookie-file.ts","size":2449,"sha256":"03a69efeef0f1d5311db55e30f5df2e06417fd4f8fd509e7995a411bfab4a63c"},{"path":"scripts/cookies.ts","size":9537,"sha256":"4350c38fa5cb68d4440a4b2bb573878e0b711e33268f3b6887d56555c71f8e59"},{"path":"scripts/graphql.ts","size":12854,"sha256":"eaed8a9076de6b5ab4dce081e8abccc291bdb29dfc477addfa9f4decb5505492"},{"path":"scripts/http.ts","size":3527,"sha256":"196a9ab00495bb8eec1865464499758c64dd504946363d021aa6c49be41096e9"},{"path":"scripts/main.ts","size":19074,"sha256":"06968fd6e6fac6d13546b8d3e216b813dd5f57b1d418a83b6e67cfdd71268a6b"},{"path":"scripts/markdown.test.ts","size":4804,"sha256":"8349944b839ea8bbd6b108121256621b0c8daf3f623fa0a20e29a96a18a3dd01"},{"path":"scripts/markdown.ts","size":21046,"sha256":"6a40cfe26385c06e88f71a0bac6e7bfb8709bde0c819b04a4c298bd3562f09a9"},{"path":"scripts/media-localizer.ts","size":10440,"sha256":"2ede3b587e3dd11af050a984ba94b813a5d16c9d58ff28e5404ae9fb3ba95c87"},{"path":"scripts/package.json","size":148,"sha256":"211764bb2c6867b0773b17a3ed7b9a28b42c583a0dfe066b902c012847ec61b3"},{"path":"scripts/paths.ts","size":2233,"sha256":"ca6e752e5d9389dcfc87f69ff944a77db23c8abd7e423719d52d518e89d5ca6c"},{"path":"scripts/referenced-tweets.ts","size":2261,"sha256":"f2518fb1860509cc541d2d3aa00043cb1c7ddf425082c51c507848a612fda1cc"},{"path":"scripts/thread-markdown.ts","size":8212,"sha256":"2b1b4cd9722915b65cb7a38f18b035daf8a95a631370ff6eb9b4530cf9a8eae3"},{"path":"scripts/thread.ts","size":8942,"sha256":"5eb50c075d1aca32a8a30966b09440800b4cf83136772f832752fb35e5d3ab76"},{"path":"scripts/tweet-article.ts","size":2936,"sha256":"564ae4ac1381e768c3622fcab7d736088cba80cb78e6e2e2386336a948510176"},{"path":"scripts/tweet-to-markdown.ts","size":6393,"sha256":"38c2d44f2260ed218bc9c924ed03b7d5aa55a7c9bdd99d53e4cec35e27e6c3b3"},{"path":"scripts/types.ts","size":1526,"sha256":"520d6462cf38c36194cf9bde0e42098750fc7fb07d010c4ce9b93af64c77c107"}],"requires":{"mcp":[],"tools":[]},"safety":{"flags":[{"code":"code.eval","kind":"dangerous-code","where":"scripts/media-localizer.ts:227","excerpt":"exec(","message":"evaluates code at runtime","severity":"warn"},{"code":"net.endpoints","kind":"exfiltration","excerpt":"abs.twimg.com, pbs.twimg.com, twitter.com, video.twimg.com, x.com","message":"bundled scripts reach 5 external host(s)","severity":"warn"}],"scannedAt":"2026-08-22","hasScripts":true,"networkEndpoints":["abs.twimg.com","pbs.twimg.com","twitter.com","video.twimg.com","x.com"]}}