domains / marketing / post-to-x / baoyu-post-to-x
The two copies describe the same task but diverge on how the browser is controlled. JimLiu/baoyu-skills is the more complete, upstream-style skill: it defines three distinct execution modes (Codex Chrome plugin, Chrome Computer Use, CDP script), a required mode-selection rule, and detailed recovery/permission steps for the Chrome plugin path. anbeime/skill is a shorter, CDP-only variant that adds an EXTEND.md preferences mechanism and explicit per-script CLI examples, but it omits the Chrome plugin and Computer Use paths entirely. Because each copy contains material steps the other lacks, crowning one would hide a real alternative.
| Repository | Path |
|---|---|
| JimLiu/baoyu-skills | skills/baoyu-post-to-x/SKILL.md |
| anbeime/skill | skills/content-creation-publisher/baoyu-post-to-x/SKILL.md |
| Role | Repository | Path |
|---|---|---|
| peer | JimLiu/baoyu-skills | skills/baoyu-post-to-x/SKILL.md |
| peer | anbeime/skill | skills/content-creation-publisher/baoyu-post-to-x/SKILL.md |
---
name: baoyu-post-to-x
description: Posts content and articles to X (Twitter). Supports regular posts with images/videos, quote tweets, and X Articles (long-form Markdown). Use when user asks to "post to X", "tweet", "publish to Twitter", or "share on X".
---
# Post to X (Twitter)
Posts text, images, videos, quote tweets, and long-form articles to X via a real Chrome browser.
## Script Directory
All scripts are in the `scripts/` subdirectory of this skill.
1. Determine this SKILL.md file's directory path as `{baseDir}`.
2. Script path = `{baseDir}/scripts/<script-name>.ts`.
3. Resolve `${BUN_X}` runtime: if `bun` is installed use `bun`; if `npx` is available use `npx -y bun`; otherwise suggest installing bun.
| Script | Purpose |
|--------|---------|
| `scripts/x-browser.ts` | Regular posts (text + images) |
| `scripts/x-video.ts` | Video posts (text + video) |
| `scripts/x-quote.ts` | Quote tweet with comment |
| `scripts/x-article.ts` | Long-form article publishing (Markdown) |
| `scripts/md-to-html.ts` | Markdown to HTML conversion |
| `scripts/copy-to-clipboard.ts` | Copy content to clipboard |
| `scripts/paste-from-clipboard.ts` | Send real paste keystroke |
| `scripts/check-paste-permissions.ts` | Verify environment and permissions |
## Preferences (EXTEND.md)
Check for EXTEND.md in this priority order:
```bash
test -f .baoyu-skills/baoyu-post-to-x/EXTEND.md && echo "project"
test -f "$HOME/.baoyu-skills/baoyu-post-to-x/EXTEND.md" && echo "user"
```
If found, read and apply settings (default Chrome profile, auto-submit preference). If not found, use defaults.
## Prerequisites
- Google Chrome or Chromium
- `bun` runtime
- First run: log in to X manually (session saved)
## Execution Mode Selection (Required)
Choose exactly one mode before interacting with X:
1. If the user explicitly asks for the Codex Chrome plugin, `@chrome`, the Chrome extension, or "Codex 自带的 Chrome 插件", use **Codex Chrome Plugin Mode**. Do not call Computer Use first.
2. If the user explicitly asks for Chrome Computer Use, use **Chrome Computer Use Mode**. Do not fall back to CDP, Playwright, the in-app Browser, or the Chrome plugin without telling the user and getting approval.
3. If the user explicitly asks for CDP/script mode, use **CDP Script Mode**.
4. Otherwise, prefer **Chrome Computer Use Mode**. For Markdown X Articles with local content images, use the tested X editor flow: insert each body image from the toolbar (`Insert` -> `Media` -> dialog icon button `Add photos or video`) at its placeholder, then delete the placeholder text. Use CDP Script Mode only when the selected browser-control mode is unavailable or the UI upload/selection flow is unreliable.
Never use the in-app Browser for X publishing workflows.
## Codex Chrome Plugin Mode
Use this mode whenever the user requests the Codex Chrome plugin, `@chrome`, or the Chrome Extension path.
**Setup**
1. Load the `chrome:Chrome` skill before browser work.
2. Use `tool_search` for `node_repl js` if the Node REPL `js` tool is not already visible.
3. Initialize the Chrome browser client exactly as the Chrome skill specifies, then run a lightweight call such as `browser.user.openTabs()` to verify the extension connection.
4. If the first lightweight call fails, wait 2 seconds and retry once. If it still fails, follow the Chrome skill's extension checks and recovery steps. If checks pass but communication still fails, ask the user before opening a new Chrome window. Do not switch to Computer Use or CDP silently.
**General rules**
- Use the Chrome plugin's `browser.tabs.*`, `tab.playwright.*`, `tab.cua.*`, and file chooser APIs for X UI actions.
- Shell commands are allowed for Markdown preprocessing and rich-HTML clipboard preparation. For X Article body images, do not rely on image clipboard paste; use the editor's `Insert` -> `Media` upload flow.
- If a file upload fails with `Not allowed`, tell the user: `To enable file upload, go to chrome://extensions in Chrome, click Details under the Codex extension, and enable "Allow access to file URLs." See https://developers.openai.com/codex/app/chrome-extension#upload-files for details.`
- If the Chrome plugin reports `native pipe is closed`, retry the lightweight browser call once after 2 seconds, then run the Chrome skill health checks. If Chrome is running, the extension is enabled, and the native host manifest is correct, ask permission to open a new Chrome window and retry. Do not keep sending browser actions through the broken pipe.
- Never click `Publish`, `Post`, or any externally visible submit action without explicit final confirmation from the user in the current conversation.
**X Articles**
1. Convert Markdown and keep the image map:
```bash
${BUN_X} {baseDir}/scripts/md-to-html.ts article.md --save-html /tmp/x-article-body.html > /tmp/x-article.json
```
2. Read the JSON output for `title`, `coverImage`, and `contentImages` (`placeholder` to `localPath`).
3. Open or create the article draft at `https://x.com/compose/articles`.
4. Upload the cover with the Chrome plugin file chooser flow. If upload is blocked by extension permissions, stop and report the error.
## Chrome Computer Use Mode
Use `mcp__computer_use__.*` against the visible Google Chrome UI. Follow the same preview-before-submit rule and the X Article image insertion flow described above.
## CDP Script Mode
Use the bundled TypeScript scripts via CDP. This is the fallback mode when the selected browser-control mode is unavailable or the user explicitly requests CDP/script mode.
### Regular Posts
Text + up to 4 images.
```bash
${BUN_X} {baseDir}/scripts/x-browser.ts "Hello!" --image ./photo.png # Preview
${BUN_X} {baseDir}/scripts/x-browser.ts "Hello!" --image ./photo.png --submit # Post
```
| Parameter | Description |
|-----------|-------------|
| `<text>` | Post content (positional) |
| `--image <path>` | Image file (repeatable, max 4) |
| `--submit` | Post (default: preview) |
| `--profile <dir>` | Custom Chrome profile |
### Video Posts
Text + video file.
```bash
${BUN_X} {baseDir}/scripts/x-video.ts "Check this out!" --video ./clip.mp4 # Preview
${BUN_X} {baseDir}/scripts/x-video.ts "Amazing content" --video ./demo.mp4 --submit # Post
```
| Parameter | Description |
|-----------|-------------|
| `<text>` | Post content (positional) |
| `--video <path>` | Video file (MP4, MOV, WebM) |
| `--submit` | Post (default: preview) |
| `--profile <dir>` | Custom Chrome profile |
Limits: Regular 140s max, Premium 60min. Processing: 30-60s.
### Quote Tweets
Quote an existing tweet with comment.
```bash
${BUN_X} {baseDir}/scripts/x-quote.ts https://x.com/user/status/123 "Great insight!" # Preview
${BUN_X} {baseDir}/scripts/x-quote.ts https://x.com/user/status/123 "I agree!" --submit # Post
```
| Parameter | Description |
|-----------|-------------|
| `<tweet-url>` | URL to quote (positional) |
| `<comment>` | Comment text (positional, optional) |
| `--submit` | Post (default: preview) |
| `--profile <dir>` | Custom Chrome profile |
### X Articles
Long-form Markdown articles (requires X Premium).
```bash
${BUN_X} {baseDir}/scripts/x-article.ts article.md # Preview
${BUN_X} {baseDir}/scripts/x-article.ts article.md --cover ./cover.jpg # With cover
${BUN_X} {baseDir}/scripts/x-article.ts article.md --submit # Publish
```
| Parameter | Description |
|-----------|-------------|
| `<markdown>` | Markdown file (positional) |
| `--cover <path>` | Cover image |
| `--title <text>` | Override title |
| `--submit` | Publish (default: preview) |
Frontmatter: `title`, `cover_image` supported in YAML front matter.
## Notes
- First run: manual login required (session persists)
- Always preview before `--submit`
- Cross-platform: macOS, Linux, Windows
## References
- **Regular Posts**: See `references/regular-posts.md` for manual workflow, troubleshooting, and technical details
- **X Articles**: See `references/articles.md` for long-form article publishing guide