cicy-desktop 1.0.8

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 (66) hide show
  1. package/.github/workflows/build.yml +85 -0
  2. package/.kiro/steering/dev-workflow.md +166 -0
  3. package/AGENTS.md +247 -0
  4. package/CLAUDE.md +162 -0
  5. package/DOCKER.md +85 -0
  6. package/Dockerfile +46 -0
  7. package/README.md +720 -0
  8. package/TODO-anti-detection.md +326 -0
  9. package/bin/cicy +176 -0
  10. package/bin/preinstall.sh +32 -0
  11. package/copy-to-desktop.sh +26 -0
  12. package/docs/AUTOMATION-API.md +342 -0
  13. package/docs/REQUEST_MONITORING.md +435 -0
  14. package/docs/REST-API-FEATURE.md +155 -0
  15. package/docs/REST-API.md +319 -0
  16. package/docs/feature-distributed-multi-agent.md +555 -0
  17. package/docs/yaml.md +255 -0
  18. package/electron-mcp-fixed.command +134 -0
  19. package/electron-mcp-simple.command +135 -0
  20. package/electron-mcp.command +92 -0
  21. package/generate-openapi.js +158 -0
  22. package/jest.config.js +10 -0
  23. package/jest.setup.global.js +13 -0
  24. package/jest.teardown.global.js +7 -0
  25. package/package.json +75 -0
  26. package/service.sh +164 -0
  27. package/src/config.js +8 -0
  28. package/src/extension/inject.js +135 -0
  29. package/src/main-old.js +837 -0
  30. package/src/main.js +403 -0
  31. package/src/preload-rpc.js +4 -0
  32. package/src/server/args-parser.js +37 -0
  33. package/src/server/electron-setup.js +33 -0
  34. package/src/server/express-app.js +166 -0
  35. package/src/server/logging.js +58 -0
  36. package/src/server/mcp-server.js +53 -0
  37. package/src/server/tool-registry.js +77 -0
  38. package/src/server/ui-routes.js +81 -0
  39. package/src/swagger-ui.html +41 -0
  40. package/src/tools/account-tools.js +194 -0
  41. package/src/tools/automation-tools.js +297 -0
  42. package/src/tools/cdp-tools.js +444 -0
  43. package/src/tools/clipboard-tools.js +180 -0
  44. package/src/tools/download-tools.js +57 -0
  45. package/src/tools/exec-js.js +297 -0
  46. package/src/tools/exec-tools.js +139 -0
  47. package/src/tools/file-tools.js +212 -0
  48. package/src/tools/hook-chatgpt.js +489 -0
  49. package/src/tools/hook-gemini.js +454 -0
  50. package/src/tools/index.js +19 -0
  51. package/src/tools/ipc-bridge.js +31 -0
  52. package/src/tools/ping.js +60 -0
  53. package/src/tools/r-reset.js +28 -0
  54. package/src/tools/screenshot-tools.js +28 -0
  55. package/src/tools/system-tools.js +531 -0
  56. package/src/tools/window-tools.js +882 -0
  57. package/src/ui.html +914 -0
  58. package/src/utils/auth.js +81 -0
  59. package/src/utils/cdp-utils.js +8 -0
  60. package/src/utils/download-manager.js +41 -0
  61. package/src/utils/process-utils.js +185 -0
  62. package/src/utils/snapshot-utils.js +56 -0
  63. package/src/utils/window-monitor.js +605 -0
  64. package/src/utils/window-state.js +137 -0
  65. package/src/utils/window-utils.js +336 -0
  66. package/update-desktop.sh +33 -0
@@ -0,0 +1,342 @@
1
+ # Electron 自动化 API 文档
2
+
3
+ ## 概述
4
+
5
+ Electron MCP 自动化系统提供完整的浏览器自动化能力,支持窗口管理、页面导航、元素操作、JavaScript执行等功能。
6
+
7
+ **服务端口**: 8101
8
+ **基础URL**: `http://localhost:8101`
9
+
10
+ ## 认证
11
+
12
+ 所有API需要Bearer Token认证:
13
+
14
+ ```bash
15
+ Authorization: Bearer YOUR_TOKEN
16
+ ```
17
+
18
+ ## API端点
19
+
20
+ ### 1. 窗口管理
21
+
22
+ #### 创建窗口
23
+ ```bash
24
+ POST /rpc/open_window
25
+ Content-Type: application/json
26
+
27
+ {
28
+ "url": "https://www.google.com",
29
+ "accountIdx": 0,
30
+ "reuseWindow": true
31
+ }
32
+ ```
33
+
34
+ #### 获取窗口列表
35
+ ```bash
36
+ POST /rpc/get_windows
37
+ Content-Type: application/json
38
+
39
+ {}
40
+ ```
41
+
42
+ #### 获取窗口信息
43
+ ```bash
44
+ POST /rpc/get_window_info
45
+ Content-Type: application/json
46
+
47
+ {
48
+ "win_id": 1
49
+ }
50
+ ```
51
+
52
+ #### 关闭窗口
53
+ ```bash
54
+ POST /rpc/close_window
55
+ Content-Type: application/json
56
+
57
+ {
58
+ "win_id": 1
59
+ }
60
+ ```
61
+
62
+ ### 2. 页面导航
63
+
64
+ #### 加载URL
65
+ ```bash
66
+ POST /rpc/load_url
67
+ Content-Type: application/json
68
+
69
+ {
70
+ "win_id": 1,
71
+ "url": "https://www.youtube.com"
72
+ }
73
+ ```
74
+
75
+ #### 获取页面标题
76
+ ```bash
77
+ POST /rpc/get_title
78
+ Content-Type: application/json
79
+
80
+ {
81
+ "win_id": 1
82
+ }
83
+ ```
84
+
85
+ ### 3. 元素操作
86
+
87
+ #### 点击元素
88
+ ```bash
89
+ POST /rpc/electron_click
90
+ Content-Type: application/json
91
+
92
+ {
93
+ "win_id": 1,
94
+ "selector": "button[aria-label='close']",
95
+ "waitTimeout": 5000
96
+ }
97
+ ```
98
+
99
+ **参数说明**:
100
+ - `win_id`: 窗口ID(可选,默认1)
101
+ - `selector`: CSS选择器
102
+ - `waitTimeout`: 等待超时时间(毫秒,默认5000)
103
+
104
+ #### 输入文字
105
+ ```bash
106
+ POST /rpc/electron_type
107
+ Content-Type: application/json
108
+
109
+ {
110
+ "win_id": 1,
111
+ "selector": "input[name='username']",
112
+ "text": "Hello World",
113
+ "clear": true,
114
+ "waitTimeout": 5000
115
+ }
116
+ ```
117
+
118
+ **参数说明**:
119
+ - `selector`: CSS选择器
120
+ - `text`: 要输入的文字
121
+ - `clear`: 是否清空原有内容(默认true)
122
+ - `waitTimeout`: 等待超时时间(毫秒,默认5000)
123
+
124
+ #### 选择下拉框
125
+ ```bash
126
+ POST /rpc/electron_select
127
+ Content-Type: application/json
128
+
129
+ {
130
+ "win_id": 1,
131
+ "selector": "select[name='country']",
132
+ "value": "US"
133
+ }
134
+ ```
135
+
136
+ #### 获取元素属性
137
+ ```bash
138
+ POST /rpc/electron_get_attribute
139
+ Content-Type: application/json
140
+
141
+ {
142
+ "win_id": 1,
143
+ "selector": "a.link",
144
+ "attribute": "href"
145
+ }
146
+ ```
147
+
148
+ ### 4. 页面信息
149
+
150
+ #### 获取页面内容
151
+ ```bash
152
+ POST /rpc/electron_get_content
153
+ Content-Type: application/json
154
+
155
+ {
156
+ "win_id": 1,
157
+ "selector": "div.content",
158
+ "type": "text"
159
+ }
160
+ ```
161
+
162
+ **参数说明**:
163
+ - `selector`: CSS选择器(可选,不指定则获取整个页面)
164
+ - `type`: 返回类型,`text`或`html`(默认text)
165
+
166
+ ### 5. JavaScript执行
167
+
168
+ #### 执行JavaScript代码
169
+ ```bash
170
+ POST /rpc/electron_evaluate
171
+ Content-Type: application/json
172
+
173
+ {
174
+ "win_id": 1,
175
+ "code": "document.querySelector('button').click()"
176
+ }
177
+ ```
178
+
179
+ **示例**:
180
+ ```bash
181
+ # 获取页面标题
182
+ {
183
+ "code": "document.title"
184
+ }
185
+
186
+ # 获取所有链接
187
+ {
188
+ "code": "Array.from(document.querySelectorAll('a')).map(a => a.href)"
189
+ }
190
+ ```
191
+
192
+ ### 6. 等待和同步
193
+
194
+ #### 等待元素出现
195
+ ```bash
196
+ POST /rpc/electron_wait_for
197
+ Content-Type: application/json
198
+
199
+ {
200
+ "win_id": 1,
201
+ "selector": "div.loaded",
202
+ "timeout": 10000
203
+ }
204
+ ```
205
+
206
+ ### 7. 截图
207
+
208
+ #### 窗口截图
209
+ ```bash
210
+ POST /rpc/electron_screenshot
211
+ Content-Type: application/json
212
+
213
+ {
214
+ "win_id": 1,
215
+ "format": "png"
216
+ }
217
+ ```
218
+
219
+ **返回格式**:
220
+ ```json
221
+ {
222
+ "content": [
223
+ {
224
+ "type": "text",
225
+ "text": "{\"format\":\"png\",\"size\":12345,\"base64\":\"data:image/png;base64,...\"}"
226
+ }
227
+ ]
228
+ }
229
+ ```
230
+
231
+ ## 使用示例
232
+
233
+ ### 示例1:自动化登录流程
234
+
235
+ ```bash
236
+ # 1. 打开登录页面
237
+ curl -X POST http://localhost:8101/rpc/open_window \
238
+ -H "Authorization: Bearer YOUR_TOKEN" \
239
+ -H "Content-Type: application/json" \
240
+ -d '{"url": "https://example.com/login"}'
241
+
242
+ # 2. 等待页面加载
243
+ curl -X POST http://localhost:8101/rpc/electron_wait_for \
244
+ -H "Authorization: Bearer YOUR_TOKEN" \
245
+ -H "Content-Type: application/json" \
246
+ -d '{"selector": "input[name=\"username\"]"}'
247
+
248
+ # 3. 输入用户名
249
+ curl -X POST http://localhost:8101/rpc/electron_type \
250
+ -H "Authorization: Bearer YOUR_TOKEN" \
251
+ -H "Content-Type: application/json" \
252
+ -d '{"selector": "input[name=\"username\"]", "text": "myuser"}'
253
+
254
+ # 4. 输入密码
255
+ curl -X POST http://localhost:8101/rpc/electron_type \
256
+ -H "Authorization: Bearer YOUR_TOKEN" \
257
+ -H "Content-Type: application/json" \
258
+ -d '{"selector": "input[name=\"password\"]", "text": "mypass"}'
259
+
260
+ # 5. 点击登录按钮
261
+ curl -X POST http://localhost:8101/rpc/electron_click \
262
+ -H "Authorization: Bearer YOUR_TOKEN" \
263
+ -H "Content-Type: application/json" \
264
+ -d '{"selector": "button[type=\"submit\"]"}'
265
+ ```
266
+
267
+ ### 示例2:数据抓取
268
+
269
+ ```bash
270
+ # 1. 打开目标页面
271
+ curl -X POST http://localhost:8101/rpc/load_url \
272
+ -H "Authorization: Bearer YOUR_TOKEN" \
273
+ -H "Content-Type: application/json" \
274
+ -d '{"url": "https://example.com/data"}'
275
+
276
+ # 2. 等待内容加载
277
+ curl -X POST http://localhost:8101/rpc/electron_wait_for \
278
+ -H "Authorization: Bearer YOUR_TOKEN" \
279
+ -H "Content-Type: application/json" \
280
+ -d '{"selector": "div.data-container"}'
281
+
282
+ # 3. 获取页面内容
283
+ curl -X POST http://localhost:8101/rpc/electron_get_content \
284
+ -H "Authorization: Bearer YOUR_TOKEN" \
285
+ -H "Content-Type: application/json" \
286
+ -d '{"selector": "div.data-container", "type": "text"}'
287
+
288
+ # 4. 执行自定义JavaScript提取数据
289
+ curl -X POST http://localhost:8101/rpc/electron_evaluate \
290
+ -H "Authorization: Bearer YOUR_TOKEN" \
291
+ -H "Content-Type: application/json" \
292
+ -d '{"code": "Array.from(document.querySelectorAll(\".item\")).map(el => ({title: el.querySelector(\".title\").innerText, price: el.querySelector(\".price\").innerText}))"}'
293
+ ```
294
+
295
+ ### 示例3:截图和监控
296
+
297
+ ```bash
298
+ # 1. 打开页面
299
+ curl -X POST http://localhost:8101/rpc/load_url \
300
+ -H "Authorization: Bearer YOUR_TOKEN" \
301
+ -H "Content-Type: application/json" \
302
+ -d '{"url": "https://example.com"}'
303
+
304
+ # 2. 等待加载完成
305
+ sleep 3
306
+
307
+ # 3. 截图
308
+ curl -X POST http://localhost:8101/rpc/electron_screenshot \
309
+ -H "Authorization: Bearer YOUR_TOKEN" \
310
+ -H "Content-Type: application/json" \
311
+ -d '{"format": "jpeg"}'
312
+ ```
313
+
314
+ ## 错误处理
315
+
316
+ 所有API在出错时返回以下格式:
317
+
318
+ ```json
319
+ {
320
+ "content": [
321
+ {
322
+ "type": "text",
323
+ "text": "Error: Element not found: button.submit"
324
+ }
325
+ ],
326
+ "isError": true
327
+ }
328
+ ```
329
+
330
+ ## 最佳实践
331
+
332
+ 1. **使用等待**: 在操作元素前使用 `electron_wait_for` 确保元素已加载
333
+ 2. **错误处理**: 检查返回的 `isError` 字段
334
+ 3. **超时设置**: 根据网络情况调整 `waitTimeout` 参数
335
+ 4. **选择器优化**: 使用精确的CSS选择器避免误操作
336
+ 5. **窗口管理**: 使用 `accountIdx` 实现多账户隔离
337
+
338
+ ## 技术支持
339
+
340
+ - 项目地址: `/home/w3c_offical/projects/electron-mcp`
341
+ - 端口: 8101
342
+ - 协议: HTTP REST API + MCP