Skip to content

jackwener/opencli

Repository files navigation

OpenCLI

Make any website or Electron App your CLI.
Zero risk Β· Reuse Chrome login Β· AI-powered discovery Β· Browser + Desktop automation

δΈ­ζ–‡ζ–‡ζ‘£

npm Node.js Version License

A CLI tool that turns any website or Electron app into a command-line interface β€” Bilibili, Zhihu, 小纒书, Twitter/X, Reddit, YouTube, Antigravity, and many more β€” powered by browser session reuse and AI-native discovery.

πŸ”₯ CLI All Electron Apps! The Most Powerful Update Has Arrived! πŸ”₯ Turn ANY Electron application into a CLI tool! Recombine, script, and extend applications like Antigravity Ultra seamlessly. Now AI can control itself natively. Unlimited possibilities await!


Table of Contents


Highlights

  • CLI All Electron β€” CLI-ify apps like Antigravity Ultra! Now AI can control itself natively using cc/openclaw!
  • Account-safe β€” Reuses Chrome's logged-in state; your credentials never leave the browser.
  • AI Agent ready β€” explore discovers APIs, synthesize generates adapters, cascade finds auth strategies.
  • Self-healing setup β€” opencli setup auto-discovers tokens; opencli doctor diagnoses config across 10+ tools; --fix repairs them all.
  • Dynamic Loader β€” Simply drop .ts or .yaml adapters into the clis/ folder for auto-registration.
  • Dual-Engine Architecture β€” Supports both YAML declarative data pipelines and robust browser runtime TypeScript injections.

Prerequisites

  • Node.js: >= 20.0.0
  • Chrome running and logged into the target site (e.g. bilibili.com, zhihu.com, xiaohongshu.com).

⚠️ Important: Browser commands reuse your Chrome login session. You must be logged into the target website in Chrome before running commands. If you get empty data or errors, check your login status first.

OpenCLI connects to your browser through the Playwright MCP Bridge extension. It prefers an existing local/global @playwright/mcp install and falls back to npx -y @playwright/mcp@latest automatically when no local MCP server is found.

Playwright MCP Bridge Extension Setup

  1. Install Playwright MCP Bridge extension in Chrome.
  2. Run opencli setup β€” discovers the token, distributes it to your tools, and verifies connectivity:
opencli setup

The interactive TUI will:

  • πŸ” Auto-discover PLAYWRIGHT_MCP_EXTENSION_TOKEN from Chrome (no manual copy needed)
  • β˜‘οΈ Show all detected tools (Codex, Cursor, Claude Code, Gemini CLI, etc.)
  • ✏️ Update only the files you select (Space to toggle, Enter to confirm)
  • πŸ”Œ Auto-verify browser connectivity after writing configs

Tip: Use opencli doctor for ongoing diagnosis and maintenance:

opencli doctor            # Read-only token & config diagnosis
opencli doctor --live     # Also test live browser connectivity
opencli doctor --fix      # Fix mismatched configs (interactive)
opencli doctor --fix -y   # Fix all configs non-interactively

Alternative: CDP Mode (For Servers/Headless) If you cannot install the browser extension (e.g. running OpenCLI on a remote headless server), you can connect OpenCLI to your local Chrome via CDP using SSH tunnels or reverse proxies. See the CDP Connection Guide for detailed instructions.

Manual setup (alternative)

Add token to your MCP client config (e.g. Claude/Cursor):

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["-y", "@playwright/mcp@latest", "--extension"],
      "env": {
        "PLAYWRIGHT_MCP_EXTENSION_TOKEN": "<your-token-here>"
      }
    }
  }
}

Export in shell (e.g. ~/.zshrc):

export PLAYWRIGHT_MCP_EXTENSION_TOKEN="<your-token-here>"

Quick Start

Install via npm (recommended)

npm install -g @jackwener/opencli
opencli setup   # One-time: configure Playwright MCP token

Then use directly:

opencli list                              # See all commands
opencli list -f yaml                      # List commands as YAML
opencli hackernews top --limit 5          # Public API, no browser
opencli bilibili hot --limit 5            # Browser command
opencli zhihu hot -f json                 # JSON output
opencli zhihu hot -f yaml                 # YAML output

Install from source (for developers)

git clone git@github.com:jackwener/opencli.git
cd opencli 
npm install
npm run build
npm link      # Link binary globally
opencli list  # Now you can use it anywhere!

Update

npm install -g @jackwener/opencli@latest

Built-in Commands

Run opencli list for the live registry.

Site Commands Mode
twitter trending bookmarks profile search timeline thread following followers notifications post reply delete like article follow unfollow bookmark unbookmark download πŸ” Browser
reddit hot frontpage popular search subreddit read user user-posts user-comments upvote save comment subscribe saved upvoted πŸ” Browser
cursor status send read new dump composer model extract-code ask screenshot history export πŸ–₯️ Desktop
bilibili hot search me favorite history feed subtitle dynamic ranking following user-videos download πŸ” Browser
codex status send read new extract-diff model ask screenshot history export πŸ–₯️ Desktop
chatwise status new send read ask model history export screenshot πŸ–₯️ Desktop
notion status search read new write sidebar favorites export πŸ–₯️ Desktop
discord-app status send read channels servers search members πŸ–₯️ Desktop
v2ex hot latest topic daily me notifications 🌐 / πŸ”
xueqiu feed hot-stock hot search stock watchlist πŸ” Browser
antigravity status send read new evaluate πŸ–₯️ Desktop
chatgpt status new send read ask πŸ–₯️ Desktop
xiaohongshu search notifications feed me user download πŸ” Browser
xiaoyuzhou podcast podcast-episodes episode 🌐 Public
zhihu hot search question download πŸ” Browser
youtube search video transcript πŸ” Browser
boss search detail πŸ” Browser
coupang search add-to-cart πŸ” Browser
bbc news 🌐 Public
ctrip search πŸ” Browser
github search 🌐 Public
hackernews top 🌐 Public
linkedin search πŸ” Browser
reuters search πŸ” Browser
smzdm search πŸ” Browser
weibo hot πŸ” Browser
yahoo-finance quote πŸ” Browser

Download Support

OpenCLI supports downloading images, videos, and articles from supported platforms.

Supported Platforms

Platform Content Types Notes
xiaohongshu Images, Videos Downloads all media from a note
bilibili Videos Requires yt-dlp installed
twitter Images, Videos Downloads from user media tab or single tweet
zhihu Articles (Markdown) Exports articles with optional image download

Prerequisites

For video downloads from streaming platforms, you need to install yt-dlp:

# Install yt-dlp
pip install yt-dlp
# or
brew install yt-dlp

Usage Examples

# Download images/videos from Xiaohongshu note
opencli xiaohongshu download --note-id abc123 --output ./xhs

# Download Bilibili video (requires yt-dlp)
opencli bilibili download --bvid BV1xxx --output ./bilibili
opencli bilibili download --bvid BV1xxx --quality 1080p  # Specify quality

# Download Twitter media from user
opencli twitter download --username elonmusk --limit 20 --output ./twitter

# Download single tweet media
opencli twitter download --tweet-url "https://x.com/user/status/123" --output ./twitter

# Export Zhihu article to Markdown
opencli zhihu download --url "https://zhuanlan.zhihu.com/p/xxx" --output ./zhihu

# Export with local images
opencli zhihu download --url "https://zhuanlan.zhihu.com/p/xxx" --download-images

Pipeline Step (for YAML adapters)

The download step can be used in YAML pipelines:

pipeline:
  - fetch: https://api.example.com/media
  - download:
      url: ${{ item.imageUrl }}
      dir: ./downloads
      filename: ${{ item.title | sanitize }}.jpg
      concurrency: 5
      skip_existing: true

Output Formats

All built-in commands support --format / -f with table, json, yaml, md, and csv. The list command supports the same format options, and keeps --json for backward compatibility.

opencli list -f yaml            # Command registry as YAML
opencli bilibili hot -f table   # Default: rich terminal table
opencli bilibili hot -f json    # JSON (pipe to jq or LLMs)
opencli bilibili hot -f yaml    # YAML (human-readable structured output)
opencli bilibili hot -f md      # Markdown
opencli bilibili hot -f csv     # CSV
opencli bilibili hot -v         # Verbose: show pipeline debug steps

For AI Agents (Developer Guide)

If you are an AI assistant tasked with creating a new command adapter for opencli, please follow the AI Agent workflow below:

Quick mode: To generate a single command for a specific page URL, see CLI-ONESHOT.md β€” just a URL + one-line goal, 4 steps done.

Full mode: Before writing any adapter code, read CLI-EXPLORER.md. It contains the complete browser exploration workflow, the 5-tier authentication strategy decision tree, and debugging guide.

# 1. Deep Explore β€” discover APIs, infer capabilities, detect framework
opencli explore https://example.com --site mysite

# 2. Synthesize β€” generate YAML adapters from explore artifacts
opencli synthesize mysite

# 3. Generate β€” one-shot: explore β†’ synthesize β†’ register
opencli generate https://example.com --goal "hot"

# 4. Strategy Cascade β€” auto-probe: PUBLIC β†’ COOKIE β†’ HEADER
opencli cascade https://api.example.com/data

Explore outputs to .opencli/explore/<site>/ (manifest.json, endpoints.json, capabilities.json, auth.json).

Testing

See TESTING.md for the full testing guide, including:

  • Current test coverage (unit + E2E tests across browser and desktop adapters)
  • How to run tests locally
  • How to add tests when creating new adapters
  • CI/CD pipeline with sharding
  • Headless browser mode (OPENCLI_HEADLESS=1)
# Quick start
npm run build
npx vitest run                              # All tests
npx vitest run src/                          # Unit tests only
npx vitest run tests/e2e/                    # E2E tests

Troubleshooting

  • "Failed to connect to Playwright MCP Bridge"
    • Ensure the Playwright MCP extension is installed and enabled in your running Chrome.
    • Restart the Chrome browser if you just installed the extension.
  • Empty data returns or 'Unauthorized' error
    • Your login session in Chrome might have expired. Open a normal Chrome tab, navigate to the target site, and log in or refresh the page to prove you are human.
  • Node API errors
    • Make sure you are using Node.js >= 20. Some dependencies require modern Node APIs.
  • Token issues
    • Run opencli doctor to diagnose token configuration across all tools.

Releasing New Versions

npm version patch   # 0.1.0 β†’ 0.1.1
npm version minor   # 0.1.0 β†’ 0.2.0
git push --follow-tags

The CI will automatically build, create a GitHub release, and publish to npm.

License

Apache-2.0

About

Make any website your CLI. A powerful, AI-native runtime for seamless browser automation and dynamic web data extraction.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors