@jackwener/opencli 0.1.0 → 0.1.1

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.
Files changed (52) hide show
  1. package/CLI-CREATOR.md +594 -0
  2. package/README.md +116 -38
  3. package/README.zh-CN.md +143 -0
  4. package/SKILL.md +154 -102
  5. package/dist/browser.d.ts +1 -0
  6. package/dist/browser.js +35 -1
  7. package/dist/cascade.d.ts +45 -0
  8. package/dist/cascade.js +180 -0
  9. package/dist/clis/bilibili/hot.yaml +38 -0
  10. package/dist/clis/github/trending.yaml +58 -0
  11. package/dist/clis/hackernews/top.yaml +36 -0
  12. package/dist/clis/index.d.ts +2 -1
  13. package/dist/clis/index.js +3 -1
  14. package/dist/clis/reddit/hot.yaml +46 -0
  15. package/dist/clis/twitter/trending.yaml +40 -0
  16. package/dist/clis/v2ex/hot.yaml +25 -0
  17. package/dist/clis/v2ex/latest.yaml +25 -0
  18. package/dist/clis/v2ex/topic.yaml +27 -0
  19. package/dist/clis/xiaohongshu/feed.yaml +32 -0
  20. package/dist/clis/xiaohongshu/notifications.yaml +38 -0
  21. package/dist/clis/xiaohongshu/search.d.ts +5 -0
  22. package/dist/clis/xiaohongshu/search.js +68 -0
  23. package/dist/clis/zhihu/hot.yaml +42 -0
  24. package/dist/clis/zhihu/question.js +39 -0
  25. package/dist/clis/zhihu/search.yaml +55 -0
  26. package/dist/explore.d.ts +23 -13
  27. package/dist/explore.js +293 -422
  28. package/dist/main.js +17 -0
  29. package/dist/pipeline.js +238 -2
  30. package/dist/synthesize.d.ts +11 -8
  31. package/dist/synthesize.js +142 -118
  32. package/package.json +4 -2
  33. package/src/browser.ts +33 -1
  34. package/src/cascade.ts +217 -0
  35. package/src/clis/index.ts +4 -1
  36. package/src/clis/reddit/hot.yaml +46 -0
  37. package/src/clis/v2ex/hot.yaml +5 -9
  38. package/src/clis/v2ex/latest.yaml +5 -8
  39. package/src/clis/v2ex/topic.yaml +27 -0
  40. package/src/clis/xiaohongshu/feed.yaml +32 -0
  41. package/src/clis/xiaohongshu/notifications.yaml +38 -0
  42. package/src/clis/xiaohongshu/search.ts +71 -0
  43. package/src/clis/zhihu/hot.yaml +22 -8
  44. package/src/clis/zhihu/question.ts +45 -0
  45. package/src/clis/zhihu/search.yaml +55 -0
  46. package/src/explore.ts +303 -465
  47. package/src/main.ts +14 -0
  48. package/src/pipeline.ts +239 -2
  49. package/src/synthesize.ts +142 -137
  50. package/dist/clis/zhihu/search.js +0 -58
  51. package/src/clis/zhihu/search.ts +0 -65
  52. /package/dist/clis/zhihu/{search.d.ts → question.d.ts} +0 -0
package/README.md CHANGED
@@ -1,66 +1,144 @@
1
1
  # OpenCLI
2
2
 
3
- > **Make any website your CLI.** 操控 Chrome 无风控风险,复用登录,CLI 化全部网站。
3
+ > **Make any website your CLI.**
4
+ > Zero risk · Reuse Chrome login · AI-powered discovery
4
5
 
5
- OpenCLI 是一个 AI Native 的 CLI 工具,通过 Chrome 浏览器 + Playwright MCP Bridge 扩展,将任何网站变成命令行工具。
6
+ [中文文档](./README.zh-CN.md)
6
7
 
7
- ## ✨ 特性
8
+ [![npm](https://img.shields.io/npm/v/@jackwener/opencli)](https://www.npmjs.com/package/@jackwener/opencli)
8
9
 
9
- - 🌐 **CLI 化全部网站**支持 Bilibili、知乎、GitHub、Twitter、V2EX、Hacker News
10
- - 🔐 **零风控风险** — 复用 Chrome 已登录状态,无需存储密码
11
- - 🤖 **AI Native** — AI agent 可直接探索网站并自动生成新命令
12
- - 📝 **声明式 YAML** — 用 YAML 定义 pipeline,无需写代码
13
- - 🔌 **TypeScript 扩展** — 复杂场景用 TS 编写适配器
10
+ OpenCLI turns any website into a command-line tool by bridging your Chrome browser through [Playwright MCP](https://github.com/nichochar/playwright-mcp). No passwords stored, no tokens leaked it just rides your existing browser session.
14
11
 
15
- ## 🚀 快速开始
12
+ ## Highlights
13
+
14
+ - 🌐 **25+ commands, 8 sites** — Bilibili, Zhihu, GitHub, Twitter/X, Reddit, V2EX, Xiaohongshu, Hacker News
15
+ - 🔐 **Account-safe** — Reuses Chrome's logged-in state; your credentials never leave the browser
16
+ - 🤖 **AI Agent ready** — `explore` discovers APIs, `synthesize` generates adapters, `cascade` finds auth strategies
17
+ - 📝 **Declarative YAML** — Most adapters are ~30 lines of YAML pipeline
18
+ - 🔌 **TypeScript escape hatch** — Complex adapters (XHR interception, GraphQL) in TS
19
+
20
+ ## 🚀 Quick Start
21
+
22
+ ### Install via npm (recommended)
23
+
24
+ ```bash
25
+ npm install -g @jackwener/opencli
26
+ ```
27
+
28
+ Then use directly:
16
29
 
17
30
  ```bash
18
- # 安装依赖
19
- cd ~/code/ai-native-cli && npm install
31
+ opencli list # See all commands
32
+ opencli hackernews top --limit 5 # Public API, no browser
33
+ opencli bilibili hot --limit 5 # Browser command
34
+ opencli zhihu hot -f json # JSON output
35
+ ```
20
36
 
21
- # 列出所有命令
37
+ ### Install from source
38
+
39
+ ```bash
40
+ git clone git@github.com:jackwener/opencli.git
41
+ cd opencli && npm install
22
42
  npx tsx src/main.ts list
43
+ ```
44
+
45
+ ### Update
23
46
 
24
- # 公共 API(无需浏览器)
25
- npx tsx src/main.ts hackernews top --limit 10
26
- npx tsx src/main.ts github search --keyword "typescript"
47
+ ```bash
48
+ # npm global
49
+ npm update -g @jackwener/opencli
50
+
51
+ # Or reinstall to latest
52
+ npm install -g @jackwener/opencli@latest
53
+ ```
27
54
 
28
- # 浏览器命令(需要 Chrome + Playwright MCP Bridge 扩展)
29
- npx tsx src/main.ts bilibili hot --limit 10
30
- npx tsx src/main.ts zhihu hot --limit 10
31
- npx tsx src/main.ts twitter trending --limit 10
55
+ ## 📋 Prerequisites
56
+
57
+ Browser commands need:
58
+ 1. **Chrome** running **and logged into the target site** (e.g. bilibili.com, zhihu.com, xiaohongshu.com)
59
+ 2. **[Playwright MCP Bridge](https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm)** extension installed
60
+ 3. Configure `PLAYWRIGHT_MCP_EXTENSION_TOKEN` (from the extension settings page) in your MCP config:
61
+
62
+ ```json
63
+ {
64
+ "mcpServers": {
65
+ "playwright": {
66
+ "command": "npx",
67
+ "args": ["@playwright/mcp@latest", "--extension"],
68
+ "env": {
69
+ "PLAYWRIGHT_MCP_EXTENSION_TOKEN": "<your-token>"
70
+ }
71
+ }
72
+ }
73
+ }
32
74
  ```
33
75
 
34
- ## 📋 前置要求
76
+ Public API commands (`hackernews`, `github search`, `v2ex`) need no browser at all.
35
77
 
36
- 浏览器命令需要:
37
- 1. Chrome 浏览器正在运行
38
- 2. 安装 [Playwright MCP Bridge](https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm) 扩展
39
- 3. 首次使用时点击扩展图标批准连接
78
+ > **⚠️ 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.
40
79
 
41
- ## 📦 内置命令
80
+ ## 📦 Built-in Commands
42
81
 
43
- | 站点 | 命令 | 说明 | 模式 |
44
- |------|------|------|------|
45
- | bilibili | hot, search, me, favorite, history, feed, user-videos | 热门 / 搜索 / 个人 / 收藏 / 历史 / 动态 / 投稿 | 🔐 浏览器 |
46
- | zhihu | hot, search | 热榜 / 搜索 | 🔐 浏览器 |
47
- | github | trending, search | Trending / 搜索 | 🔐 / 🌐 公共 |
48
- | twitter | trending | 热门话题 | 🔐 浏览器 |
49
- | v2ex | hot, latest | 热门 / 最新 | 🔐 浏览器 |
50
- | hackernews | top | 热门故事 | 🌐 公共 API |
82
+ | Site | Commands | Mode |
83
+ |------|----------|------|
84
+ | **bilibili** | `hot` `search` `me` `favorite` `history` `feed` `user-videos` | 🔐 Browser |
85
+ | **zhihu** | `hot` `search` `question` | 🔐 Browser |
86
+ | **xiaohongshu** | `search` `notifications` `feed` | 🔐 Browser |
87
+ | **twitter** | `trending` | 🔐 Browser |
88
+ | **reddit** | `hot` | 🔐 Browser |
89
+ | **github** | `trending` `search` | 🔐 / 🌐 |
90
+ | **v2ex** | `hot` `latest` `topic` | 🌐 Public |
91
+ | **hackernews** | `top` | 🌐 Public |
51
92
 
52
- ## 🎨 输出格式
93
+ ## 🎨 Output Formats
53
94
 
54
95
  ```bash
55
- opencli bilibili hot -f table # 默认表格
56
- opencli bilibili hot -f json # JSON(适合管道和 AI agent)
96
+ opencli bilibili hot -f table # Default: rich table
97
+ opencli bilibili hot -f json # JSON (pipe to jq, feed to AI)
57
98
  opencli bilibili hot -f md # Markdown
58
99
  opencli bilibili hot -f csv # CSV
100
+ opencli bilibili hot -v # Verbose: show pipeline steps
59
101
  ```
60
102
 
61
- ## 🔧 创建新命令
103
+ ## 🧠 AI Agent Workflow
104
+
105
+ ```bash
106
+ # 1. Deep Explore — discover APIs, infer capabilities, detect framework
107
+ opencli explore https://example.com --site mysite
108
+
109
+ # 2. Synthesize — generate YAML adapters from explore artifacts
110
+ opencli synthesize mysite
111
+
112
+ # 3. Generate — one-shot: explore → synthesize → register
113
+ opencli generate https://example.com --goal "hot"
114
+
115
+ # 4. Strategy Cascade — auto-probe: PUBLIC → COOKIE → HEADER
116
+ opencli cascade https://api.example.com/data
117
+ ```
118
+
119
+ Explore outputs to `.opencli/explore/<site>/`:
120
+ - `manifest.json` — site metadata, framework detection
121
+ - `endpoints.json` — scored API endpoints with response schemas
122
+ - `capabilities.json` — inferred capabilities with confidence scores
123
+ - `auth.json` — authentication strategy recommendations
124
+
125
+ ## 🔧 Create New Commands
126
+
127
+ See **[SKILL.md](./SKILL.md)** for the full adapter guide (YAML pipeline + TypeScript).
128
+
129
+ ## Releasing New Versions
130
+
131
+ ```bash
132
+ # Bump version
133
+ npm version patch # 0.1.0 → 0.1.1
134
+ npm version minor # 0.1.0 → 0.2.0
135
+ npm version major # 0.1.0 → 1.0.0
136
+
137
+ # Push tag to trigger GitHub Actions auto-release
138
+ git push --follow-tags
139
+ ```
62
140
 
63
- 参考 [SKILL.md](./SKILL.md) 了解 YAML TypeScript 两种方式创建新的 CLI 适配器。
141
+ The CI will automatically build, create a GitHub release, and publish to npm.
64
142
 
65
143
  ## 📄 License
66
144
 
@@ -0,0 +1,143 @@
1
+ # OpenCLI
2
+
3
+ > **把任何网站变成你的命令行工具。**
4
+ > 零风控 · 复用 Chrome 登录 · AI 自动发现接口
5
+
6
+ [English](./README.md)
7
+
8
+ [![npm](https://img.shields.io/npm/v/@jackwener/opencli)](https://www.npmjs.com/package/@jackwener/opencli)
9
+
10
+ OpenCLI 通过 Chrome 浏览器 + [Playwright MCP Bridge](https://github.com/nichochar/playwright-mcp) 扩展,将任何网站变成命令行工具。不存密码、不泄 token,直接复用浏览器已登录状态。
11
+
12
+ ## ✨ 亮点
13
+
14
+ - 🌐 **25+ 命令,8 个站点** — B站、知乎、GitHub、Twitter/X、Reddit、V2EX、小红书、Hacker News
15
+ - 🔐 **零风控** — 复用 Chrome 登录态,无需存储任何凭证
16
+ - 🤖 **AI 原生** — `explore` 自动发现 API,`synthesize` 生成适配器,`cascade` 探测认证策略
17
+ - 📝 **声明式 YAML** — 大部分适配器只需 ~30 行 YAML
18
+ - 🔌 **TypeScript 扩展** — 复杂场景(XHR 拦截、GraphQL)可用 TS 编写
19
+
20
+ ## 🚀 快速开始
21
+
22
+ ### npm 全局安装(推荐)
23
+
24
+ ```bash
25
+ npm install -g @jackwener/opencli
26
+ ```
27
+
28
+ 直接使用:
29
+
30
+ ```bash
31
+ opencli list # 查看所有命令
32
+ opencli hackernews top --limit 5 # 公共 API,无需浏览器
33
+ opencli bilibili hot --limit 5 # 浏览器命令
34
+ opencli zhihu hot -f json # JSON 输出
35
+ ```
36
+
37
+ ### 从源码安装
38
+
39
+ ```bash
40
+ git clone git@github.com:jackwener/opencli.git
41
+ cd opencli && npm install
42
+ npx tsx src/main.ts list
43
+ ```
44
+
45
+ ### 更新
46
+
47
+ ```bash
48
+ # npm 全局更新
49
+ npm update -g @jackwener/opencli
50
+
51
+ # 或直接安装最新版
52
+ npm install -g @jackwener/opencli@latest
53
+ ```
54
+
55
+ ## 📋 前置要求
56
+
57
+ 浏览器命令需要:
58
+ 1. **Chrome** 浏览器正在运行,且**已登录目标网站**(如 bilibili.com、zhihu.com、xiaohongshu.com)
59
+ 2. 安装 **[Playwright MCP Bridge](https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm)** 扩展
60
+ 3. 在 MCP 配置中设置 `PLAYWRIGHT_MCP_EXTENSION_TOKEN`(从扩展设置页获取):
61
+
62
+ ```json
63
+ {
64
+ "mcpServers": {
65
+ "playwright": {
66
+ "command": "npx",
67
+ "args": ["@playwright/mcp@latest", "--extension"],
68
+ "env": {
69
+ "PLAYWRIGHT_MCP_EXTENSION_TOKEN": "<your-token>"
70
+ }
71
+ }
72
+ }
73
+ }
74
+ ```
75
+
76
+ 公共 API 命令(`hackernews`、`github search`、`v2ex`)无需浏览器。
77
+
78
+ > **⚠️ 重要**:浏览器命令复用你的 Chrome 登录状态。运行命令前,你必须已在 Chrome 中登录目标网站。如果获取到空数据或报错,请先检查登录状态。
79
+
80
+ ## 📦 内置命令
81
+
82
+ | 站点 | 命令 | 模式 |
83
+ |------|------|------|
84
+ | **bilibili** | `hot` `search` `me` `favorite` `history` `feed` `user-videos` | 🔐 浏览器 |
85
+ | **zhihu** | `hot` `search` `question` | 🔐 浏览器 |
86
+ | **xiaohongshu** | `search` `notifications` `feed` | 🔐 浏览器 |
87
+ | **twitter** | `trending` | 🔐 浏览器 |
88
+ | **reddit** | `hot` | 🔐 浏览器 |
89
+ | **github** | `trending` `search` | 🔐 / 🌐 |
90
+ | **v2ex** | `hot` `latest` `topic` | 🌐 公共 API |
91
+ | **hackernews** | `top` | 🌐 公共 API |
92
+
93
+ ## 🎨 输出格式
94
+
95
+ ```bash
96
+ opencli bilibili hot -f table # 默认:表格
97
+ opencli bilibili hot -f json # JSON(可 pipe 给 jq 或 AI agent)
98
+ opencli bilibili hot -f md # Markdown
99
+ opencli bilibili hot -f csv # CSV
100
+ opencli bilibili hot -v # 详细模式:展示 pipeline 每步数据
101
+ ```
102
+
103
+ ## 🧠 AI Agent 工作流
104
+
105
+ ```bash
106
+ # 1. Deep Explore — 网络拦截 → 响应分析 → 能力推理 → 框架检测
107
+ opencli explore https://example.com --site mysite
108
+
109
+ # 2. Synthesize — 从探索成果物生成 evaluate-based YAML 适配器
110
+ opencli synthesize mysite
111
+
112
+ # 3. Generate — 一键完成:探索 → 合成 → 注册
113
+ opencli generate https://example.com --goal "hot"
114
+
115
+ # 4. Strategy Cascade — 自动降级探测:PUBLIC → COOKIE → HEADER
116
+ opencli cascade https://api.example.com/data
117
+ ```
118
+
119
+ 探索结果输出到 `.opencli/explore/<site>/`:
120
+ - `manifest.json` — 站点元数据、框架检测结果
121
+ - `endpoints.json` — 评分排序的 API 端点,含响应 schema
122
+ - `capabilities.json` — 推理出的能力及置信度
123
+ - `auth.json` — 认证策略建议
124
+
125
+ ## 🔧 创建新命令
126
+
127
+ 查看 **[SKILL.md](./SKILL.md)** 了解完整的适配器开发指南(YAML pipeline + TypeScript)。
128
+
129
+ ## 版本发布
130
+
131
+ ```bash
132
+ # 升级版本号
133
+ npm version patch # 0.1.0 → 0.1.1
134
+ npm version minor # 0.1.0 → 0.2.0
135
+ npm version major # 0.1.0 → 1.0.0
136
+
137
+ # 推送 tag,GitHub Actions 自动发 release 并发布到 npm
138
+ git push --follow-tags
139
+ ```
140
+
141
+ ## 📄 License
142
+
143
+ MIT