mirror of
https://github.com/JimLiu/baoyu-skills.git
synced 2026-07-13 22:29:48 +08:00
045fe5e57e
In Codex, prefer the bundled Chrome Computer Use path for all X UI actions (compose, article, quote, video). CDP scripts become a fallback when Computer Use is unavailable or explicitly not requested.
8.2 KiB
8.2 KiB
X Articles - Detailed Guide
Publish Markdown articles to X Articles editor with rich text formatting and images.
Mode Selection
In Codex, prefer Chrome Computer Use when available:
- If Computer Use tools are already visible, call
get_app_stateforGoogle Chrome. - If not, use
tool_searchforcomputer-use get_app_state click press_key drag scroll Google Chrome, then callget_app_state. - If that succeeds, use the Computer Use workflow below.
- Use the CDP script workflow only when Computer Use is unavailable or explicitly requested.
If the user explicitly asks for Chrome Computer Use, do not fall back to CDP, Playwright, or the in-app Browser without approval.
Prerequisites
- X Premium subscription (required for Articles)
- Google Chrome installed
buninstalled
Usage
Chrome Computer Use (Codex Preferred)
Prepare the article HTML and image map:
${BUN_X} {baseDir}/scripts/md-to-html.ts article.md --save-html /tmp/x-article-body.html > /tmp/x-article.json
Copy the generated HTML as rich text:
${BUN_X} {baseDir}/scripts/copy-to-clipboard.ts html --file /tmp/x-article-body.html
Then use Codex Computer Use against Google Chrome for all X UI operations.
CDP Script Fallback
# Publish markdown article (preview mode)
${BUN_X} {baseDir}/scripts/x-article.ts article.md
# With custom cover image
${BUN_X} {baseDir}/scripts/x-article.ts article.md --cover ./cover.jpg
# Actually publish
${BUN_X} {baseDir}/scripts/x-article.ts article.md --submit
Do not use --submit unless the user has explicitly confirmed the final public publish action.
Markdown Format
---
title: My Article Title
cover_image: /path/to/cover.jpg
---
# Title (becomes article title)
Regular paragraph text with **bold** and *italic*.
## Section Header
More content here.

- List item 1
- List item 2
1. Numbered item
2. Another item
> Blockquote text
[Link text](https://example.com)
\`\`\`
Code blocks become blockquotes (X doesn't support code)
\`\`\`
Frontmatter Fields
| Field | Description |
|---|---|
title |
Article title (or uses first H1) |
cover_image |
Cover image path or URL |
cover |
Alias for cover_image |
image |
Alias for cover_image |
Image Handling
- Cover Image: First image or
cover_imagefrom frontmatter - Remote Images: Automatically downloaded to temp directory
- Placeholders: Images in content use
XIMGPH_Nformat - Insertion: Placeholders are found, selected, and replaced with actual images
Markdown to HTML Script
Convert markdown and inspect structure:
# Get JSON with all metadata
${BUN_X} {baseDir}/scripts/md-to-html.ts article.md
# Output HTML only
${BUN_X} {baseDir}/scripts/md-to-html.ts article.md --html-only
# Save HTML to file
${BUN_X} {baseDir}/scripts/md-to-html.ts article.md --save-html /tmp/article.html
JSON output:
{
"title": "Article Title",
"coverImage": "/path/to/cover.jpg",
"contentImages": [
{
"placeholder": "XIMGPH_1",
"localPath": "/tmp/x-article-images/img.png",
"blockIndex": 5
}
],
"html": "<p>Content...</p>",
"totalBlocks": 20
}
Supported Formatting
| Markdown | HTML Output |
|---|---|
# H1 |
Title only (not in body) |
## H2 - ###### H6 |
<h2> |
**bold** |
<strong> |
*italic* |
<em> |
[text](url) |
<a href> |
> quote |
<blockquote> |
`code` |
<code> |
``` |
<blockquote> (X limitation) |
- item |
<ul><li> |
1. item |
<ol><li> |
 |
Image placeholder |
Computer Use Workflow (Preferred in Codex)
- Detect Computer Use: call
get_app_stateforGoogle Chrome; usetool_searchfirst if the tools are not visible. - Parse Markdown: run
md-to-html.ts --save-html /tmp/x-article-body.html > /tmp/x-article.json. - Read the map: use
/tmp/x-article.jsonfortitle,coverImage, andcontentImages. - Open X Articles: use Chrome Computer Use to navigate to
https://x.com/compose/articles. - Create Draft: click the create/write button if needed, or open the target draft.
- Upload Cover: if
coverImageexists, use Chrome's visible upload/file picker UI. If the file picker cannot be operated reliably, stop and ask for help rather than switching to CDP silently. - Fill Title: type the title into the title field.
- Paste Content:
- Run
copy-to-clipboard.ts html --file /tmp/x-article-body.html. - Click the article body.
- Press
super+von macOS orcontrol+von Windows/Linux with Computer Use.
- Run
- Insert Images: for each
contentImagesitem in placeholder order:- Run
copy-to-clipboard.ts image <localPath>. - Select the exact placeholder text (
XIMGPH_N) in the editor. - Press
super+v/control+vwith Computer Use. - Wait for X to finish uploading media.
- If
XIMGPH_Nremains above the inserted image, reselect that exact text and pressBackSpace. - Do not press
BackSpaceunless the Computer Use state confirms the selected text is exactly the placeholder.
- Run
- Verify:
- Inspect the Computer Use state for
XIMGPH_residue. - Confirm the expected number of image blocks is visible.
- Open Preview and verify title, cover, body, links, and images.
- Publish Safety: ask the user for explicit final confirmation before clicking
Publish.
CDP Script Workflow (Fallback)
- Parse Markdown: Extract title, cover, content images, generate HTML
- Launch Chrome: Real browser with CDP, persistent login
- Navigate: Open
x.com/compose/articles - Create Article: Click create button if on list page
- Upload Cover: Use file input for cover image
- Fill Title: Type title into title field
- Paste Content: Copy HTML to clipboard, paste into editor
- Insert Images: For each placeholder (reverse order):
- Find placeholder text in editor
- Select the placeholder
- Copy image to clipboard
- Paste to replace selection
- Post-Composition Check (automatic):
- Scan editor for remaining
XIMGPH_placeholders - Compare expected vs actual image count
- Warn if issues found
- Scan editor for remaining
- Review: Browser stays open for 60s preview
- Publish: Only with
--submitflag and explicit user confirmation
Example Session
User: /post-to-x article ./blog/my-post.md --cover ./thumbnail.png
Claude:
1. Detects Chrome Computer Use
2. Parses markdown: title="My Post", 3 content images
3. Saves `/tmp/x-article-body.html` and `/tmp/x-article.json`
4. Uses Chrome Computer Use to open X Articles and create a draft
5. Uploads thumbnail.png as cover
6. Fills title "My Post"
7. Pastes HTML content with a real Chrome paste
8. Inserts 3 images at placeholder positions
9. Opens Preview and asks before publishing
Troubleshooting
- No create button: Ensure X Premium subscription is active
- Cover upload fails: Check file path and format (PNG, JPEG)
- Images not inserting: Verify placeholders exist in pasted content
- Content not pasting: Check HTML clipboard:
${BUN_X} {baseDir}/scripts/copy-to-clipboard.ts html --file /tmp/test.html - Computer Use unavailable: Use the CDP fallback script, unless the user explicitly required Chrome Computer Use.
- Placeholder remains after paste: Select only the placeholder text and press BackSpace after upload completes.
How It Works
-
md-to-html.tsconverts Markdown to HTML:- Extracts frontmatter (title, cover)
- Converts markdown to HTML
- Replaces images with unique placeholders
- Downloads remote images locally
- Returns structured JSON
-
Chrome Computer Use publishes through the user's visible Chrome UI:
- Uses the user's active Chrome profile and logged-in X session
- Uses
copy-to-clipboard.tsfor rich HTML and image clipboard payloads - Uses real keystrokes (
super+v/control+v) through Codex Computer Use - Keeps the final publish click under user confirmation
-
x-article.tspublishes via CDP as a fallback:- Launches real Chrome (bypasses detection)
- Uses persistent profile (saved login)
- Navigates and fills editor via DOM manipulation
- Pastes HTML from system clipboard
- Finds/selects/replaces each image placeholder