Skip to content

feat(twitter): add --images flag to post command#666

Open
artshooter wants to merge 1 commit intojackwener:mainfrom
artshooter:feat/twitter-post-images
Open

feat(twitter): add --images flag to post command#666
artshooter wants to merge 1 commit intojackwener:mainfrom
artshooter:feat/twitter-post-images

Conversation

@artshooter
Copy link
Copy Markdown

@artshooter artshooter commented Apr 1, 2026

Summary

  • Add --images option to twitter post command, supporting up to 4 images (comma-separated paths)
  • Uses existing page.setFileInput() (CDP DOM.setFileInputFiles) to attach files to Twitter's file input
  • Includes file validation (statSync checks), graceful error handling for older extensions, and polling-based upload readiness detection

Usage

# Single image
opencli twitter post "Hello world" --images /path/to/image.png

# Multiple images (comma-separated, max 4)
opencli twitter post "Hello world" --images /path/a.png,/path/b.jpg,/path/c.png

Test plan

  • npx tsc --noEmit passes
  • npm test passes (456 passed)
  • Manual test: posted tweet with single image successfully
  • Manual test: post tweet with multiple images
  • Manual test: verify error message when file not found
  • Manual test: verify error message when >4 images provided

🤖 Generated with Claude Code

Support attaching up to 4 images when posting tweets via
`opencli twitter post "text" --images /path/a.png,/path/b.jpg`.

Uses the existing CDP DOM.setFileInputFiles mechanism (page.setFileInput)
to inject files into Twitter's file input. Includes proper file validation,
graceful error handling for older extensions, and polling-based upload
readiness detection instead of fixed delays.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Astro-Han
Copy link
Copy Markdown
Contributor

One concrete issue here: the new "wait for image upload" check is using the tweet button enabled state as the upload-complete signal, but text is still a required argument and the code pastes the text before starting the image upload.

That means [data-testid="tweetButton"] can already be enabled just because the tweet has text, even while the image upload is still in progress. In that case the uploaded polling loop returns true immediately, and the command goes on to click Post before the media is actually attached.

So for a text+image tweet this can silently post the text without the images, or with only a partially finished upload, while still reporting success. I think the wait condition needs to watch an actual media-upload completion signal in the DOM, not the generic button enabled state.

There also does not seem to be any test coverage for the new image path. The diff only changes src/clis/twitter/post.ts, with no added or updated tests around --images, file validation, upload waiting, or the "post only after media is attached" behavior. Given the change is adding a new side-effecting publish path, I think it should come with at least one focused test for the upload flow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants