@harness.farm/social-cli 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 (2) hide show
  1. package/README.md +213 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,213 @@
1
+ # social-cli
2
+
3
+ 基于 Chrome DevTools Protocol (CDP) 的社交媒体自动化 CLI,支持 X(推特)、小红书、抖音、B站,无需安装浏览器插件或 Playwright,直接连接你已有的 Chrome。
4
+
5
+ ## 工作原理
6
+
7
+ ```
8
+ Chrome (--remote-debugging-port=9222)
9
+ ↕ WebSocket / CDP
10
+ social-cli
11
+ ├── adapters/<platform>.yaml ← YAML 适配器(优先)
12
+ └── src/adapters/<platform>.ts ← TypeScript 适配器(兜底)
13
+ ```
14
+
15
+ - **YAML 适配器**:声明式步骤描述,易于阅读和修改,无需编译
16
+ - **TypeScript 适配器**:适合复杂逻辑,编译后运行
17
+ - **登录状态管理**:首次运行时引导登录,自动保存 session cookie,后续免登录
18
+
19
+ ## 快速开始
20
+
21
+ ### 1. 启动 Chrome(开启远程调试)
22
+
23
+ ```bash
24
+ # macOS
25
+ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
26
+ --remote-debugging-port=9222 \
27
+ --user-data-dir=$HOME/.cdp-scraper/chrome-profile
28
+
29
+ # Windows
30
+ chrome.exe --remote-debugging-port=9222 --user-data-dir=%USERPROFILE%\.cdp-scraper\chrome-profile
31
+
32
+ # Linux
33
+ google-chrome --remote-debugging-port=9222 --user-data-dir=~/.cdp-scraper/chrome-profile
34
+ ```
35
+
36
+ ### 2. 安装依赖
37
+
38
+ ```bash
39
+ npm install
40
+ ```
41
+
42
+ ### 3. 运行命令
43
+
44
+ ```bash
45
+ # 开发模式(tsx,无需编译)
46
+ tsx src/cli.ts <platform> <command> [args...]
47
+
48
+ # 或使用 package.json 快捷脚本
49
+ npm run xhs -- search 法律ai
50
+ npm run x -- search "claude ai"
51
+ ```
52
+
53
+ ## 支持的平台和命令
54
+
55
+ ### X(推特)
56
+
57
+ | 命令 | 参数 | 说明 |
58
+ |------|------|------|
59
+ | `search` | `keyword` | 搜索推文 |
60
+ | `like` | `url` | 点赞 / 取消点赞 |
61
+ | `reply` | `url text` | 回复推文 |
62
+ | `post` | `text` | 发推 |
63
+ | `retweet` | `url` | 转推 |
64
+
65
+ ```bash
66
+ tsx src/cli.ts x search "claude ai"
67
+ tsx src/cli.ts x like "https://x.com/user/status/123"
68
+ tsx src/cli.ts x reply "https://x.com/user/status/123" "很有意思!"
69
+ tsx src/cli.ts x post "Hello from social-cli!"
70
+ tsx src/cli.ts x retweet "https://x.com/user/status/123"
71
+ ```
72
+
73
+ ### 小红书(xhs / xiaohongshu)
74
+
75
+ | 命令 | 参数 | 说明 |
76
+ |------|------|------|
77
+ | `search` | `keyword` | 搜索笔记 |
78
+ | `hot` | — | 获取首页热门笔记 |
79
+ | `like` | `url` | 点赞 / 取消点赞 |
80
+ | `comment` | `url text` | 发表评论 |
81
+ | `post` | `title content` | 发布图文笔记 |
82
+
83
+ ```bash
84
+ tsx src/cli.ts xhs search 法律ai
85
+ tsx src/cli.ts xhs hot
86
+ tsx src/cli.ts xhs like "https://www.xiaohongshu.com/explore/..."
87
+ tsx src/cli.ts xhs comment "https://..." "太棒了!"
88
+ tsx src/cli.ts xhs post --title "我的标题" --content "正文内容"
89
+ ```
90
+
91
+ ### 抖音(douyin)
92
+
93
+ | 命令 | 参数 | 说明 |
94
+ |------|------|------|
95
+ | `search` | `keyword` | 搜索视频 |
96
+ | `like` | `url` | 点赞(Z 键) |
97
+ | `comment` | `url text` | 发表评论 |
98
+ | `follow` | `url` | 关注用户 |
99
+ | `post` | `video title desc` | 发布视频 |
100
+
101
+ ```bash
102
+ tsx src/cli.ts douyin search 猫咪
103
+ tsx src/cli.ts douyin like "https://www.douyin.com/video/..."
104
+ tsx src/cli.ts douyin comment "https://..." "哈哈哈"
105
+ tsx src/cli.ts douyin post /path/to/video.mp4 "标题" "描述"
106
+ ```
107
+
108
+ ### B站(bilibili)
109
+
110
+ | 命令 | 参数 | 说明 |
111
+ |------|------|------|
112
+ | `search` | `keyword` | 搜索视频 |
113
+ | `like` | `url` | 点赞视频 |
114
+ | `follow` | `url` | 关注 UP 主 |
115
+ | `comment` | `url text` | 发表评论 |
116
+ | `reply` | `url text` | 回复第一条评论 |
117
+ | `post` | `video title desc` | 投稿视频 |
118
+
119
+ ```bash
120
+ tsx src/cli.ts bilibili search TypeScript教程
121
+ tsx src/cli.ts bilibili like "https://www.bilibili.com/video/BV..."
122
+ tsx src/cli.ts bilibili comment "https://..." "讲得很好!"
123
+ tsx src/cli.ts bilibili post /path/to/video.mp4 "视频标题" "视频描述"
124
+ ```
125
+
126
+ ## YAML 适配器格式
127
+
128
+ YAML 适配器位于 `adapters/` 目录,无需编译即可生效,支持热修改。
129
+
130
+ ```yaml
131
+ platform: myplatform
132
+ login_url: https://example.com
133
+ login_check:
134
+ cookie: session_cookie_name # 用于判断是否已登录
135
+
136
+ commands:
137
+ search:
138
+ args: [keyword] # 位置参数名
139
+ steps:
140
+ - open: "https://example.com/search?q={{keyword}}"
141
+ - wait: 3000
142
+ - extract:
143
+ selector: ".item"
144
+ fields:
145
+ title: ".title"
146
+ link:
147
+ selector: "a"
148
+ attr: href
149
+ ```
150
+
151
+ ### 支持的 Step 类型
152
+
153
+ | Step | 说明 |
154
+ |------|------|
155
+ | `open: url` | 导航到 URL |
156
+ | `wait: ms` | 等待毫秒数 |
157
+ | `wait: { selector }` | 等待元素出现 |
158
+ | `click: selector` | 点击元素 |
159
+ | `click: { text: "..." }` | 按文本内容点击 |
160
+ | `fill: { selector, value }` | 填写 input 表单 |
161
+ | `type_rich: { selector, value }` | 输入到 contenteditable 元素 |
162
+ | `eval: "js"` | 执行 JavaScript |
163
+ | `capture: { name, eval }` | 执行 JS 并保存结果到变量 |
164
+ | `extract: { selector, fields }` | 批量抓取列表数据 |
165
+ | `return: [{ field, value }]` | 输出结果表格 |
166
+ | `upload: { selector, file }` | 上传本地文件 |
167
+ | `screenshot: path` | 截图保存 |
168
+ | `key: "key"` | 模拟按键(如 `Enter`, `z`, `x`) |
169
+ | `keyboard_insert: text` | 逐字符发送(适用于 Draft.js / React 输入框) |
170
+ | `insert_text: text` | CDP 直接插入文本(可穿透 shadow DOM) |
171
+ | `assert: { eval, message }` | 断言,失败则报错 |
172
+
173
+ 模板变量使用 `{{varName}}` 语法,也支持 JS 表达式:`{{a === 'true' ? '是' : '否'}}`
174
+
175
+ ## 编译发布
176
+
177
+ ```bash
178
+ npm run build # 编译 TypeScript → dist/
179
+ ```
180
+
181
+ 编译后可作为 `social-cli` 命令使用(需全局安装或 `npx`)。
182
+
183
+ ## 项目结构
184
+
185
+ ```
186
+ cdp-scraper/
187
+ ├── adapters/ # YAML 适配器(运行时读取,优先生效)
188
+ │ ├── x.yaml
189
+ │ ├── xhs.yaml
190
+ │ ├── xiaohongshu.yaml
191
+ │ ├── douyin.yaml
192
+ │ └── bilibili.yaml
193
+ ├── src/
194
+ │ ├── cli.ts # CLI 入口,适配器解析与路由
195
+ │ ├── runner/
196
+ │ │ ├── yaml-runner.ts # YAML 步骤执行引擎
197
+ │ │ └── step-executor.ts
198
+ │ ├── browser/
199
+ │ │ ├── cdp.ts # CDP WebSocket 客户端
200
+ │ │ ├── session.ts # Cookie session 持久化
201
+ │ │ └── runner.ts # TS 适配器运行器
202
+ │ ├── adapters/ # TypeScript 适配器(兜底)
203
+ │ │ ├── base.ts
204
+ │ │ ├── xiaohongshu.ts
205
+ │ │ └── index.ts
206
+ │ └── output/
207
+ │ └── table.ts # 终端表格渲染
208
+ └── package.json
209
+ ```
210
+
211
+ ## License
212
+
213
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harness.farm/social-cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "CDP-based social media automation CLI — X, 小红书, 抖音, B站, Temu",
5
5
  "type": "module",
6
6
  "publishConfig": {