@jackwener/opencli 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLI-CREATOR.md +10 -10
- package/LICENSE +28 -0
- package/README.md +113 -63
- package/README.zh-CN.md +114 -63
- package/SKILL.md +21 -4
- package/dist/browser.d.ts +21 -2
- package/dist/browser.js +269 -15
- package/dist/browser.test.d.ts +1 -0
- package/dist/browser.test.js +43 -0
- package/dist/build-manifest.js +4 -0
- package/dist/cli-manifest.json +279 -3
- package/dist/clis/boss/search.js +186 -30
- package/dist/clis/twitter/delete.d.ts +1 -0
- package/dist/clis/twitter/delete.js +73 -0
- package/dist/clis/twitter/followers.d.ts +1 -0
- package/dist/clis/twitter/followers.js +104 -0
- package/dist/clis/twitter/following.d.ts +1 -0
- package/dist/clis/twitter/following.js +90 -0
- package/dist/clis/twitter/like.d.ts +1 -0
- package/dist/clis/twitter/like.js +69 -0
- package/dist/clis/twitter/notifications.d.ts +1 -0
- package/dist/clis/twitter/notifications.js +109 -0
- package/dist/clis/twitter/post.d.ts +1 -0
- package/dist/clis/twitter/post.js +63 -0
- package/dist/clis/twitter/reply.d.ts +1 -0
- package/dist/clis/twitter/reply.js +57 -0
- package/dist/clis/v2ex/daily.d.ts +1 -0
- package/dist/clis/v2ex/daily.js +98 -0
- package/dist/clis/v2ex/me.d.ts +1 -0
- package/dist/clis/v2ex/me.js +99 -0
- package/dist/clis/v2ex/notifications.d.ts +1 -0
- package/dist/clis/v2ex/notifications.js +72 -0
- package/dist/doctor.d.ts +50 -0
- package/dist/doctor.js +372 -0
- package/dist/doctor.test.d.ts +1 -0
- package/dist/doctor.test.js +114 -0
- package/dist/main.js +47 -5
- package/dist/output.test.d.ts +1 -0
- package/dist/output.test.js +20 -0
- package/dist/registry.d.ts +4 -0
- package/dist/registry.js +1 -0
- package/dist/runtime.d.ts +3 -1
- package/dist/runtime.js +2 -2
- package/package.json +2 -2
- package/src/browser.test.ts +51 -0
- package/src/browser.ts +318 -22
- package/src/build-manifest.ts +4 -0
- package/src/clis/boss/search.ts +196 -29
- package/src/clis/twitter/delete.ts +78 -0
- package/src/clis/twitter/followers.ts +119 -0
- package/src/clis/twitter/following.ts +105 -0
- package/src/clis/twitter/like.ts +74 -0
- package/src/clis/twitter/notifications.ts +119 -0
- package/src/clis/twitter/post.ts +68 -0
- package/src/clis/twitter/reply.ts +62 -0
- package/src/clis/v2ex/daily.ts +105 -0
- package/src/clis/v2ex/me.ts +103 -0
- package/src/clis/v2ex/notifications.ts +77 -0
- package/src/doctor.test.ts +133 -0
- package/src/doctor.ts +424 -0
- package/src/main.ts +47 -4
- package/src/output.test.ts +27 -0
- package/src/registry.ts +5 -0
- package/src/runtime.ts +2 -1
package/CLI-CREATOR.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## AI Agent 开发者必读:用 Playwright MCP Bridge 探索
|
|
9
9
|
|
|
10
10
|
> [!CAUTION]
|
|
11
11
|
> **你(AI Agent)必须通过 Playwright MCP Bridge 打开浏览器去访问目标网站!**
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
| 遇到 HTTP 200 但空数据就放弃 | 检查是否需要 Wbi 签名或 Cookie 鉴权 |
|
|
39
39
|
| 完全依赖 `__INITIAL_STATE__` 拿所有数据 | `__INITIAL_STATE__` 只有首屏数据,深层数据要调 API |
|
|
40
40
|
|
|
41
|
-
###
|
|
41
|
+
### 实战成功案例:5 分钟实现「关注列表」适配器
|
|
42
42
|
|
|
43
43
|
以下是用上述工作流实际发现 Bilibili 关注列表 API 的完整过程:
|
|
44
44
|
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
fetch('/x/relation/followings?vmid=137702077&pn=1&ps=5', {credentials:'include'})
|
|
52
52
|
→ { code: 0, data: { total: 1342, list: [{mid, uname, sign, ...}] } }
|
|
53
53
|
4. 结论:标准 Cookie API,无需 Wbi 签名
|
|
54
|
-
5. 写 following.ts → 一次构建通过
|
|
54
|
+
5. 写 following.ts → 一次构建通过
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
**关键决策点**:
|
|
@@ -174,7 +174,7 @@ opencli cascade https://api.example.com/hot
|
|
|
174
174
|
|
|
175
175
|
## Step 2.5: 准备工作(写代码之前)
|
|
176
176
|
|
|
177
|
-
###
|
|
177
|
+
### 先找模板:从最相似的现有适配器开始
|
|
178
178
|
|
|
179
179
|
**不要从零开始写**。先看看同站点已有哪些适配器:
|
|
180
180
|
|
|
@@ -207,7 +207,7 @@ cat src/clis/<site>/feed.ts # 读最相似的那个
|
|
|
207
207
|
- 含 `/wbi/` 或 `w_rid=` → 必须用 `apiGet(..., { signed: true })`
|
|
208
208
|
- 不含 → 直接用 `fetchJson`
|
|
209
209
|
|
|
210
|
-
>
|
|
210
|
+
> 其他站点(Twitter、小红书等)暂无专用 SDK,直接用 `page.evaluate` + `fetch` 即可。
|
|
211
211
|
|
|
212
212
|
---
|
|
213
213
|
|
|
@@ -252,7 +252,7 @@ func: async (page, kwargs) => {
|
|
|
252
252
|
},
|
|
253
253
|
```
|
|
254
254
|
|
|
255
|
-
>
|
|
255
|
+
> 大多数站点的 `ps` 上限是 20~50。超过会被静默截断或返回错误。
|
|
256
256
|
|
|
257
257
|
### 方式 A: YAML Pipeline(声明式,推荐)
|
|
258
258
|
|
|
@@ -530,13 +530,13 @@ cli({
|
|
|
530
530
|
|
|
531
531
|
> **拦截核心思路**:不自己构造签名,而是利用 `installInterceptor` 劫持网站自己的 `XMLHttpRequest` 和 `fetch`,让网站发请求,我们直接在底层取出解析好的 `response.json()`。
|
|
532
532
|
|
|
533
|
-
>
|
|
533
|
+
> **级联请求**(如 BVID→CID→字幕)的完整模板和要点见下方[进阶模式: 级联请求](#进阶模式-级联请求-cascading-requests)章节。
|
|
534
534
|
|
|
535
535
|
---
|
|
536
536
|
|
|
537
537
|
## Step 4: 测试
|
|
538
538
|
|
|
539
|
-
>
|
|
539
|
+
> **构建通过 ≠ 功能正常**。`npm run build` 只验证 TypeScript / YAML 语法,不验证运行时行为。
|
|
540
540
|
> 每个新命令 **必须实际运行** 并确认输出正确后才算完成。
|
|
541
541
|
|
|
542
542
|
### 必做清单
|
|
@@ -555,7 +555,7 @@ opencli mysite hot --limit 3 -f json # JSON 输出确认字段完整
|
|
|
555
555
|
|
|
556
556
|
### tap 步骤调试(intercept 策略专用)
|
|
557
557
|
|
|
558
|
-
>
|
|
558
|
+
> **不要猜 store name / action name**。先用 evaluate 探索,再写 YAML。
|
|
559
559
|
|
|
560
560
|
#### Step 1: 列出所有 Pinia store
|
|
561
561
|
|
|
@@ -614,7 +614,7 @@ opencli list | grep mysite # 确认注册
|
|
|
614
614
|
git add src/clis/mysite/ && git commit -m "feat(mysite): add hot" && git push
|
|
615
615
|
```
|
|
616
616
|
|
|
617
|
-
>
|
|
617
|
+
> **架构理念**:OpenCLI 内建 **Zero-Dependency jq** 数据流 — 所有解析在 `evaluate` 的原生 JS 内完成,外层 YAML 用 `select`/`map` 提取,无需依赖系统 `jq` 二进制。
|
|
618
618
|
|
|
619
619
|
---
|
|
620
620
|
|
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025, jackwener
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -5,20 +5,84 @@
|
|
|
5
5
|
|
|
6
6
|
[中文文档](./README.zh-CN.md)
|
|
7
7
|
|
|
8
|
-
[](https://www.npmjs.com/package/@jackwener/opencli)
|
|
8
|
+
[](https://www.npmjs.com/package/@jackwener/opencli)
|
|
9
|
+
[](https://nodejs.org)
|
|
10
|
+
[](./LICENSE)
|
|
9
11
|
|
|
10
|
-
A CLI tool that turns **any website** into a command-line interface. **
|
|
12
|
+
A CLI tool that turns **any website** into a command-line interface. **57 commands** across **17 sites** — bilibili, zhihu, xiaohongshu, twitter, reddit, xueqiu, github, v2ex, hackernews, bbc, weibo, boss, yahoo-finance, reuters, smzdm, ctrip, youtube — powered by browser session reuse and AI-native discovery.
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
---
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
- 🤖 **AI Agent ready** — `explore` discovers APIs, `synthesize` generates adapters, `cascade` finds auth strategies
|
|
16
|
-
- 🚀 **Dynamic Loader** — Simply drop `.ts` or `.yaml` adapters into the `clis/` folder for auto-registration
|
|
17
|
-
- 📝 **Dual-Engine Architecture**:
|
|
18
|
-
- **YAML Declarative Engine**: Most adapters are minimal ~30 lines of YAML pipeline
|
|
19
|
-
- **Native Browser Injection Engine**: Advanced TypeScript utilities (`installInterceptor`, `autoScroll`) for XHR hijacking, GraphQL unwrapping, and store mutation
|
|
16
|
+
## Table of Contents
|
|
20
17
|
|
|
21
|
-
|
|
18
|
+
- [Highlights](#highlights)
|
|
19
|
+
- [Prerequisites](#prerequisites)
|
|
20
|
+
- [Quick Start](#quick-start)
|
|
21
|
+
- [Built-in Commands](#built-in-commands)
|
|
22
|
+
- [Output Formats](#output-formats)
|
|
23
|
+
- [For AI Agents (Developer Guide)](#for-ai-agents-developer-guide)
|
|
24
|
+
- [Troubleshooting](#troubleshooting)
|
|
25
|
+
- [Releasing New Versions](#releasing-new-versions)
|
|
26
|
+
- [License](#license)
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Highlights
|
|
31
|
+
|
|
32
|
+
- **Account-safe** — Reuses Chrome's logged-in state; your credentials never leave the browser.
|
|
33
|
+
- **AI Agent ready** — `explore` discovers APIs, `synthesize` generates adapters, `cascade` finds auth strategies.
|
|
34
|
+
- **Dynamic Loader** — Simply drop `.ts` or `.yaml` adapters into the `clis/` folder for auto-registration.
|
|
35
|
+
- **Dual-Engine Architecture** — Supports both YAML declarative data pipelines and robust browser runtime typescript injections.
|
|
36
|
+
|
|
37
|
+
## Prerequisites
|
|
38
|
+
|
|
39
|
+
- **Node.js**: >= 18.0.0
|
|
40
|
+
- **Chrome** running **and logged into the target site** (e.g. bilibili.com, zhihu.com, xiaohongshu.com).
|
|
41
|
+
|
|
42
|
+
> **⚠️ 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.
|
|
43
|
+
|
|
44
|
+
OpenCLI needs a way to communicate with your browser. We highly recommend configuring **both** of the following methods for maximum reliability.
|
|
45
|
+
|
|
46
|
+
### Connection Method A: Playwright MCP Bridge Extension (Primary)
|
|
47
|
+
|
|
48
|
+
1. Install **[Playwright MCP Bridge](https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm)** extension in Chrome.
|
|
49
|
+
2. Obtain your token by clicking the extension icon in the browser toolbar or from the extension settings page.
|
|
50
|
+
|
|
51
|
+
**You must configure this token in BOTH your MCP configuration and system environment variables.**
|
|
52
|
+
|
|
53
|
+
First, add it to your MCP client config (e.g. Claude/Cursor):
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"mcpServers": {
|
|
58
|
+
"playwright": {
|
|
59
|
+
"command": "npx",
|
|
60
|
+
"args": ["-y", "@playwright/mcp@latest", "--extension"],
|
|
61
|
+
"env": {
|
|
62
|
+
"PLAYWRIGHT_MCP_EXTENSION_TOKEN": "<your-token-here>"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
And, so that `opencli` commands can use it directly in the terminal, export it in your shell environment (e.g. `~/.zshrc`):
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
export PLAYWRIGHT_MCP_EXTENSION_TOKEN="<your-token-here>"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Connection Method B: Chrome 144+ Auto-Discovery (Fallback)
|
|
76
|
+
|
|
77
|
+
No extensions needed. Just enable Chrome's built-in remote debugging:
|
|
78
|
+
|
|
79
|
+
1. Open `chrome://inspect#remote-debugging` in Chrome
|
|
80
|
+
2. Check **"Allow remote debugging for this browser instance"**
|
|
81
|
+
3. Set `OPENCLI_USE_CDP=1` before running opencli
|
|
82
|
+
|
|
83
|
+
*You can also manually specify an endpoint via `OPENCLI_CDP_ENDPOINT` env var.*
|
|
84
|
+
|
|
85
|
+
## Quick Start
|
|
22
86
|
|
|
23
87
|
### Install via npm (recommended)
|
|
24
88
|
|
|
@@ -30,63 +94,39 @@ Then use directly:
|
|
|
30
94
|
|
|
31
95
|
```bash
|
|
32
96
|
opencli list # See all commands
|
|
97
|
+
opencli list -f yaml # List commands as YAML
|
|
33
98
|
opencli hackernews top --limit 5 # Public API, no browser
|
|
34
99
|
opencli bilibili hot --limit 5 # Browser command
|
|
35
100
|
opencli zhihu hot -f json # JSON output
|
|
101
|
+
opencli zhihu hot -f yaml # YAML output
|
|
36
102
|
```
|
|
37
103
|
|
|
38
|
-
### Install from source
|
|
104
|
+
### Install from source (for developers)
|
|
39
105
|
|
|
40
106
|
```bash
|
|
41
107
|
git clone git@github.com:jackwener/opencli.git
|
|
42
|
-
cd opencli
|
|
43
|
-
|
|
108
|
+
cd opencli
|
|
109
|
+
npm install
|
|
110
|
+
npm run build
|
|
111
|
+
npm link # Link binary globally
|
|
112
|
+
opencli list # Now you can use it anywhere!
|
|
44
113
|
```
|
|
45
114
|
|
|
46
115
|
### Update
|
|
47
116
|
|
|
48
117
|
```bash
|
|
49
|
-
# npm global
|
|
50
|
-
npm update -g @jackwener/opencli
|
|
51
|
-
|
|
52
|
-
# Or reinstall to latest
|
|
53
118
|
npm install -g @jackwener/opencli@latest
|
|
54
119
|
```
|
|
55
120
|
|
|
56
|
-
##
|
|
57
|
-
|
|
58
|
-
Browser commands need:
|
|
59
|
-
1. **Chrome** running **and logged into the target site** (e.g. bilibili.com, zhihu.com, xiaohongshu.com)
|
|
60
|
-
2. **[Playwright MCP Bridge](https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm)** extension installed
|
|
61
|
-
3. Configure `PLAYWRIGHT_MCP_EXTENSION_TOKEN` (from the extension settings page) in your MCP config:
|
|
62
|
-
|
|
63
|
-
```json
|
|
64
|
-
{
|
|
65
|
-
"mcpServers": {
|
|
66
|
-
"playwright": {
|
|
67
|
-
"command": "npx",
|
|
68
|
-
"args": ["@playwright/mcp@latest", "--extension"],
|
|
69
|
-
"env": {
|
|
70
|
-
"PLAYWRIGHT_MCP_EXTENSION_TOKEN": "<your-token>"
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
Public API commands (`hackernews`, `github search`, `v2ex`) need no browser at all.
|
|
78
|
-
|
|
79
|
-
> **⚠️ 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.
|
|
80
|
-
|
|
81
|
-
## 📦 Built-in Commands
|
|
121
|
+
## Built-in Commands
|
|
82
122
|
|
|
83
123
|
| Site | Commands | Mode |
|
|
84
124
|
|------|----------|------|
|
|
85
|
-
| **bilibili** | `hot` `search` `me` `favorite`
|
|
125
|
+
| **bilibili** | `hot` `search` `me` `favorite` ... (11 commands) | 🔐 Browser |
|
|
86
126
|
| **zhihu** | `hot` `search` `question` | 🔐 Browser |
|
|
87
127
|
| **xiaohongshu** | `search` `notifications` `feed` `me` `user` | 🔐 Browser |
|
|
88
128
|
| **xueqiu** | `feed` `hot-stock` `hot` `search` `stock` `watchlist` | 🔐 Browser |
|
|
89
|
-
| **twitter** | `trending` `bookmarks` `profile` `search` `timeline` | 🔐 Browser |
|
|
129
|
+
| **twitter** | `trending` `bookmarks` `profile` `search` `timeline` `following` `followers` `notifications` `post` `reply` `delete` `like` | 🔐 Browser |
|
|
90
130
|
| **reddit** | `hot` `frontpage` `search` `subreddit` | 🔐 Browser |
|
|
91
131
|
| **weibo** | `hot` | 🔐 Browser |
|
|
92
132
|
| **boss** | `search` | 🔐 Browser |
|
|
@@ -100,17 +140,27 @@ Public API commands (`hackernews`, `github search`, `v2ex`) need no browser at a
|
|
|
100
140
|
| **hackernews** | `top` | 🌐 Public |
|
|
101
141
|
| **bbc** | `news` | 🌐 Public |
|
|
102
142
|
|
|
103
|
-
##
|
|
143
|
+
## Output Formats
|
|
144
|
+
|
|
145
|
+
All built-in commands support `--format` / `-f` with `table`, `json`, `yaml`, `md`, and `csv`.
|
|
146
|
+
The `list` command supports the same format options, and keeps `--json` for backward compatibility.
|
|
104
147
|
|
|
105
148
|
```bash
|
|
106
|
-
opencli
|
|
107
|
-
opencli bilibili hot -f
|
|
149
|
+
opencli list -f yaml # Command registry as YAML
|
|
150
|
+
opencli bilibili hot -f table # Default: rich terminal table
|
|
151
|
+
opencli bilibili hot -f json # JSON (pipe to jq or LLMs)
|
|
152
|
+
opencli bilibili hot -f yaml # YAML (human-readable structured output)
|
|
108
153
|
opencli bilibili hot -f md # Markdown
|
|
109
154
|
opencli bilibili hot -f csv # CSV
|
|
110
|
-
opencli bilibili hot -v # Verbose: show pipeline steps
|
|
155
|
+
opencli bilibili hot -v # Verbose: show pipeline debug steps
|
|
111
156
|
```
|
|
112
157
|
|
|
113
|
-
##
|
|
158
|
+
## For AI Agents (Developer Guide)
|
|
159
|
+
|
|
160
|
+
If you are an AI assistant tasked with creating a new command adapter for `opencli`, please follow the AI Agent workflow below:
|
|
161
|
+
|
|
162
|
+
> **Information for AI:**
|
|
163
|
+
> Before writing any adapter code, you **must** read [CLI-CREATOR.md](./CLI-CREATOR.md). It contains the complete browser exploration workflow, the 5-tier authentication strategy decision tree, and debugging guide. Skipping this will lead to preventable errors.
|
|
114
164
|
|
|
115
165
|
```bash
|
|
116
166
|
# 1. Deep Explore — discover APIs, infer capabilities, detect framework
|
|
@@ -126,30 +176,30 @@ opencli generate https://example.com --goal "hot"
|
|
|
126
176
|
opencli cascade https://api.example.com/data
|
|
127
177
|
```
|
|
128
178
|
|
|
129
|
-
Explore outputs to `.opencli/explore/<site
|
|
130
|
-
- `manifest.json` — site metadata, framework detection
|
|
131
|
-
- `endpoints.json` — scored API endpoints with response schemas
|
|
132
|
-
- `capabilities.json` — inferred capabilities with confidence scores
|
|
133
|
-
- `auth.json` — authentication strategy recommendations
|
|
179
|
+
Explore outputs to `.opencli/explore/<site>/` (manifest.json, endpoints.json, capabilities.json, auth.json).
|
|
134
180
|
|
|
135
|
-
##
|
|
181
|
+
## Troubleshooting
|
|
136
182
|
|
|
137
|
-
|
|
183
|
+
- **"Failed to connect to Playwright MCP Bridge"**
|
|
184
|
+
- Ensure the Playwright MCP extension is installed and **enabled** in your running Chrome.
|
|
185
|
+
- Restart the Chrome browser if you just installed the extension.
|
|
186
|
+
- **"CDP command failed" or "boss search blocked"**
|
|
187
|
+
- Some sites (like BOSS Zhipin) actively block Chrome DevTools Protocol connections. OpenCLI falls back to cookie extraction, but ensure you didn't force `--chrome-mode` unnecessarily.
|
|
188
|
+
- **Empty data returns or 'Unauthorized' error**
|
|
189
|
+
- 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.
|
|
190
|
+
- **Node API errors**
|
|
191
|
+
- Make sure you are using Node.js >= 18. Some dependencies require modern Node APIs.
|
|
138
192
|
|
|
139
193
|
## Releasing New Versions
|
|
140
194
|
|
|
141
195
|
```bash
|
|
142
|
-
# Bump version
|
|
143
196
|
npm version patch # 0.1.0 → 0.1.1
|
|
144
197
|
npm version minor # 0.1.0 → 0.2.0
|
|
145
|
-
npm version major # 0.1.0 → 1.0.0
|
|
146
|
-
|
|
147
|
-
# Push tag to trigger GitHub Actions auto-release
|
|
148
198
|
git push --follow-tags
|
|
149
199
|
```
|
|
150
200
|
|
|
151
201
|
The CI will automatically build, create a GitHub release, and publish to npm.
|
|
152
202
|
|
|
153
|
-
##
|
|
203
|
+
## License
|
|
154
204
|
|
|
155
|
-
|
|
205
|
+
[BSD-3-Clause](./LICENSE)
|
package/README.zh-CN.md
CHANGED
|
@@ -5,21 +5,84 @@
|
|
|
5
5
|
|
|
6
6
|
[English](./README.md)
|
|
7
7
|
|
|
8
|
-
[](https://www.npmjs.com/package/@jackwener/opencli)
|
|
8
|
+
[](https://www.npmjs.com/package/@jackwener/opencli)
|
|
9
|
+
[](https://nodejs.org)
|
|
10
|
+
[](./LICENSE)
|
|
9
11
|
|
|
10
|
-
OpenCLI 通过 Chrome 浏览器 + [Playwright MCP Bridge](https://github.com/nichochar/playwright-mcp)
|
|
12
|
+
OpenCLI 通过 Chrome 浏览器 + [Playwright MCP Bridge](https://github.com/nichochar/playwright-mcp) 扩展,将任何网站变成命令行工具。57个内置命令。不存密码、不泄 token,直接复用浏览器已登录状态。
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
---
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
- 🔐 **零风控** — 复用 Chrome 登录态,无需存储任何凭证
|
|
16
|
-
- 🤖 **AI 原生** — `explore` 自动发现 API,`synthesize` 生成适配器,`cascade` 探测认证策略
|
|
17
|
-
- 🚀 **动态加载引擎** — 只需将 `.ts` 或 `.yaml` 适配器放入 `clis/` 文件夹即可自动注册生效
|
|
18
|
-
- 📝 **双引擎架构设计**:
|
|
19
|
-
- **YAML 声明式引擎**:大部分适配器只需极简的 ~30 行 YAML 声明
|
|
20
|
-
- **原生浏览器注入引擎**:提供高级 TS API(`installInterceptor`、`autoScroll`)轻松实现 XHR 劫持、GraphQL 解包及状态库注入
|
|
16
|
+
## 目录
|
|
21
17
|
|
|
22
|
-
|
|
18
|
+
- [亮点](#亮点)
|
|
19
|
+
- [前置要求](#前置要求)
|
|
20
|
+
- [快速开始](#快速开始)
|
|
21
|
+
- [内置命令](#内置命令)
|
|
22
|
+
- [输出格式](#输出格式)
|
|
23
|
+
- [致 AI Agent(开发者指南)](#致-ai-agent开发者指南)
|
|
24
|
+
- [常见问题排查](#常见问题排查)
|
|
25
|
+
- [版本发布](#版本发布)
|
|
26
|
+
- [License](#license)
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 亮点
|
|
31
|
+
|
|
32
|
+
- **57 个命令,17 个站点** — B站、知乎、小红书、Twitter、Reddit、雪球(xueqiu)、GitHub、V2EX、Hacker News、BBC、微博、BOSS直聘、Yahoo Finance、路透社、什么值得买、携程、YouTube
|
|
33
|
+
- **零风控** — 复用 Chrome 登录态,无需存储任何凭证
|
|
34
|
+
- **AI 原生** — `explore` 自动发现 API,`synthesize` 生成适配器,`cascade` 探测认证策略
|
|
35
|
+
- **动态加载引擎** — 声明式的 `.yaml` 或者底层定制的 `.ts` 适配器,放入 `clis/` 文件夹即可自动注册生效
|
|
36
|
+
|
|
37
|
+
## 前置要求
|
|
38
|
+
|
|
39
|
+
- **Node.js**: >= 18.0.0
|
|
40
|
+
- **Chrome** 浏览器正在运行,且**已登录目标网站**(如 bilibili.com、zhihu.com、xiaohongshu.com)
|
|
41
|
+
|
|
42
|
+
> **⚠️ 重要**:大多数命令复用你的 Chrome 登录状态。运行命令前,你必须已在 Chrome 中打开目标网站并完成登录。如果获取到空数据或报错,请先检查你的浏览器登录状态。
|
|
43
|
+
|
|
44
|
+
为了让 OpenCLI 能够联通你的浏览器,你需要配置连接方式。**强烈建议以下两种方式都配置上**,互为后备:
|
|
45
|
+
|
|
46
|
+
### 连接方式 A:Playwright MCP Bridge 扩展(首选)
|
|
47
|
+
|
|
48
|
+
1. 安装 **[Playwright MCP Bridge](https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm)** 扩展
|
|
49
|
+
2. 在浏览器插件栏点击该插件,或者在插件设置页获取你的 Extension Token。
|
|
50
|
+
|
|
51
|
+
**你必须将这个 Token 同时配置到你的 MCP 配置文件以及环境变量中。**
|
|
52
|
+
|
|
53
|
+
首先,配置你的 MCP 客户端(如 Claude/Cursor 等):
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"mcpServers": {
|
|
58
|
+
"playwright": {
|
|
59
|
+
"command": "npx",
|
|
60
|
+
"args": ["-y", "@playwright/mcp@latest", "--extension"],
|
|
61
|
+
"env": {
|
|
62
|
+
"PLAYWRIGHT_MCP_EXTENSION_TOKEN": "<你的-token>"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
并且,为了让 `opencli` 命令行也能直接使用它,你必须在你的终端系统环境变量中导出它(建议写进 `~/.zshrc` 或 `~/.bashrc`):
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
export PLAYWRIGHT_MCP_EXTENSION_TOKEN="<你的-token>"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 连接方式 B:Chrome 144+ CDP 自动发现(备选)
|
|
76
|
+
|
|
77
|
+
无需安装任何扩展。只需开启 Chrome 内置的远程调试:
|
|
78
|
+
|
|
79
|
+
1. 在 Chrome 中打开 `chrome://inspect#remote-debugging`
|
|
80
|
+
2. 勾选 **"允许对此浏览器实例进行远程调试" (Allow remote debugging for this browser instance)**
|
|
81
|
+
3. 运行时设置环境变量 `OPENCLI_USE_CDP=1`
|
|
82
|
+
|
|
83
|
+
*也可通过 `OPENCLI_CDP_ENDPOINT` 环境变量手动指定 CDP endpoint 地址。*
|
|
84
|
+
|
|
85
|
+
## 快速开始
|
|
23
86
|
|
|
24
87
|
### npm 全局安装(推荐)
|
|
25
88
|
|
|
@@ -31,63 +94,39 @@ npm install -g @jackwener/opencli
|
|
|
31
94
|
|
|
32
95
|
```bash
|
|
33
96
|
opencli list # 查看所有命令
|
|
97
|
+
opencli list -f yaml # 以 YAML 列出所有命令
|
|
34
98
|
opencli hackernews top --limit 5 # 公共 API,无需浏览器
|
|
35
99
|
opencli bilibili hot --limit 5 # 浏览器命令
|
|
36
100
|
opencli zhihu hot -f json # JSON 输出
|
|
101
|
+
opencli zhihu hot -f yaml # YAML 输出
|
|
37
102
|
```
|
|
38
103
|
|
|
39
|
-
###
|
|
104
|
+
### 从源码安装(面向开发者)
|
|
40
105
|
|
|
41
106
|
```bash
|
|
42
107
|
git clone git@github.com:jackwener/opencli.git
|
|
43
|
-
cd opencli
|
|
44
|
-
|
|
108
|
+
cd opencli
|
|
109
|
+
npm install
|
|
110
|
+
npm run build
|
|
111
|
+
npm link # 链接到全局环境
|
|
112
|
+
opencli list # 可以在任何地方使用了!
|
|
45
113
|
```
|
|
46
114
|
|
|
47
115
|
### 更新
|
|
48
116
|
|
|
49
117
|
```bash
|
|
50
|
-
# npm 全局更新
|
|
51
|
-
npm update -g @jackwener/opencli
|
|
52
|
-
|
|
53
|
-
# 或直接安装最新版
|
|
54
118
|
npm install -g @jackwener/opencli@latest
|
|
55
119
|
```
|
|
56
120
|
|
|
57
|
-
##
|
|
58
|
-
|
|
59
|
-
浏览器命令需要:
|
|
60
|
-
1. **Chrome** 浏览器正在运行,且**已登录目标网站**(如 bilibili.com、zhihu.com、xiaohongshu.com)
|
|
61
|
-
2. 安装 **[Playwright MCP Bridge](https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm)** 扩展
|
|
62
|
-
3. 在 MCP 配置中设置 `PLAYWRIGHT_MCP_EXTENSION_TOKEN`(从扩展设置页获取):
|
|
63
|
-
|
|
64
|
-
```json
|
|
65
|
-
{
|
|
66
|
-
"mcpServers": {
|
|
67
|
-
"playwright": {
|
|
68
|
-
"command": "npx",
|
|
69
|
-
"args": ["@playwright/mcp@latest", "--extension"],
|
|
70
|
-
"env": {
|
|
71
|
-
"PLAYWRIGHT_MCP_EXTENSION_TOKEN": "<your-token>"
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
公共 API 命令(`hackernews`、`github search`、`v2ex`)无需浏览器。
|
|
79
|
-
|
|
80
|
-
> **⚠️ 重要**:浏览器命令复用你的 Chrome 登录状态。运行命令前,你必须已在 Chrome 中登录目标网站。如果获取到空数据或报错,请先检查登录状态。
|
|
81
|
-
|
|
82
|
-
## 📦 内置命令
|
|
121
|
+
## 内置命令
|
|
83
122
|
|
|
84
123
|
| 站点 | 命令 | 模式 |
|
|
85
124
|
|------|------|------|
|
|
86
|
-
| **bilibili** | `hot` `search` `me` `favorite`
|
|
125
|
+
| **bilibili** | `hot` `search` `me` `favorite` ...(共11个) | 🔐 浏览器 |
|
|
87
126
|
| **zhihu** | `hot` `search` `question` | 🔐 浏览器 |
|
|
88
127
|
| **xiaohongshu** | `search` `notifications` `feed` `me` `user` | 🔐 浏览器 |
|
|
89
128
|
| **xueqiu** | `feed` `hot-stock` `hot` `search` `stock` `watchlist` | 🔐 浏览器 |
|
|
90
|
-
| **twitter** | `trending` `bookmarks` `profile` `search` `timeline` | 🔐 浏览器 |
|
|
129
|
+
| **twitter** | `trending` `bookmarks` `profile` `search` `timeline` `following` `followers` `notifications` `post` `reply` `delete` `like` | 🔐 浏览器 |
|
|
91
130
|
| **reddit** | `hot` `frontpage` `search` `subreddit` | 🔐 浏览器 |
|
|
92
131
|
| **weibo** | `hot` | 🔐 浏览器 |
|
|
93
132
|
| **boss** | `search` | 🔐 浏览器 |
|
|
@@ -101,17 +140,27 @@ npm install -g @jackwener/opencli@latest
|
|
|
101
140
|
| **hackernews** | `top` | 🌐 公共 API |
|
|
102
141
|
| **bbc** | `news` | 🌐 公共 API |
|
|
103
142
|
|
|
104
|
-
##
|
|
143
|
+
## 输出格式
|
|
144
|
+
|
|
145
|
+
所有内置命令都支持 `--format` / `-f`,可选值为 `table`、`json`、`yaml`、`md`、`csv`。
|
|
146
|
+
`list` 命令也支持同样的格式参数,同时继续兼容 `--json`。
|
|
105
147
|
|
|
106
148
|
```bash
|
|
107
|
-
opencli
|
|
108
|
-
opencli bilibili hot -f
|
|
149
|
+
opencli list -f yaml # 用 YAML 列出命令注册表
|
|
150
|
+
opencli bilibili hot -f table # 默认:富文本表格
|
|
151
|
+
opencli bilibili hot -f json # JSON(适合传给 jq 或者各类 AI Agent)
|
|
152
|
+
opencli bilibili hot -f yaml # YAML(更适合人类直接阅读)
|
|
109
153
|
opencli bilibili hot -f md # Markdown
|
|
110
154
|
opencli bilibili hot -f csv # CSV
|
|
111
|
-
opencli bilibili hot -v #
|
|
155
|
+
opencli bilibili hot -v # 详细模式:展示管线执行步骤调试信息
|
|
112
156
|
```
|
|
113
157
|
|
|
114
|
-
##
|
|
158
|
+
## 致 AI Agent(开发者指南)
|
|
159
|
+
|
|
160
|
+
如果你是一个被要求查阅代码并编写新 `opencli` 适配器的 AI,请遵守以下工作流。
|
|
161
|
+
|
|
162
|
+
> **给 AI 的提示:**
|
|
163
|
+
> 在编写任何新代码前,你**必须首先阅读 [CLI-CREATOR.md](./CLI-CREATOR.md)**。它包含了完整的适配器开发指南、API 探测流程、5级认证策略以及常见陷阱。如果你跳过这一步直接写代码,会导致很多不必要的错误。
|
|
115
164
|
|
|
116
165
|
```bash
|
|
117
166
|
# 1. Deep Explore — 网络拦截 → 响应分析 → 能力推理 → 框架检测
|
|
@@ -127,28 +176,30 @@ opencli generate https://example.com --goal "hot"
|
|
|
127
176
|
opencli cascade https://api.example.com/data
|
|
128
177
|
```
|
|
129
178
|
|
|
130
|
-
探索结果输出到 `.opencli/explore/<site
|
|
131
|
-
- `manifest.json` — 站点元数据、框架检测结果
|
|
132
|
-
- `endpoints.json` — 评分排序的 API 端点,含响应 schema
|
|
133
|
-
- `capabilities.json` — 推理出的能力及置信度
|
|
134
|
-
- `auth.json` — 认证策略建议
|
|
179
|
+
探索结果输出到 `.opencli/explore/<site>/`。
|
|
135
180
|
|
|
136
|
-
##
|
|
181
|
+
## 常见问题排查
|
|
137
182
|
|
|
138
|
-
|
|
183
|
+
- **"Failed to connect to Playwright MCP Bridge"** 报错
|
|
184
|
+
- 确保你当前的 Chrome 已安装且**开启了** Playwright MCP Bridge 浏览器插件。
|
|
185
|
+
- 如果是刚装完插件,需要重启 Chrome 浏览器。
|
|
186
|
+
- **"CDP command failed" / "被风控拦截"**
|
|
187
|
+
- 有些网站(例如 BOSS 直聘)会因为开了 DevTools 或者 CDP 端口拦截验证。OpenCLI 有 cookie 降级机制,通常不需要干预,不用去强行加上 CDP 标识参数即可。
|
|
188
|
+
- **返回空数据,或者报错 "Unauthorized"**
|
|
189
|
+
- Chrome 里的登录态可能已经过期(甚至被要求过滑动验证码)。请打开当前 Chrome 页面,在新标签页重新手工登录或刷新该页面。
|
|
190
|
+
- **Node API 错误 (如 parseArgs, fs 等)**
|
|
191
|
+
- 确保 Node.js 版本 `>= 18`。旧版不支持我们使用的现代核心库 API。
|
|
139
192
|
|
|
140
193
|
## 版本发布
|
|
141
194
|
|
|
142
195
|
```bash
|
|
143
|
-
# 升级版本号
|
|
144
196
|
npm version patch # 0.1.0 → 0.1.1
|
|
145
197
|
npm version minor # 0.1.0 → 0.2.0
|
|
146
|
-
npm version major # 0.1.0 → 1.0.0
|
|
147
198
|
|
|
148
|
-
# 推送 tag,GitHub Actions
|
|
199
|
+
# 推送 tag,GitHub Actions 将自动执行发版和 npm 发布
|
|
149
200
|
git push --follow-tags
|
|
150
201
|
```
|
|
151
202
|
|
|
152
|
-
##
|
|
203
|
+
## License
|
|
153
204
|
|
|
154
|
-
|
|
205
|
+
[BSD-3-Clause](./LICENSE)
|