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,435 @@
1
+ # 请求监控系统文档
2
+
3
+ ## 概述
4
+
5
+ Electron MCP 提供了完整的网络请求监控和存储系统,自动捕获所有 HTTP 请求/响应并保存到本地文件。
6
+
7
+ ## 核心特性
8
+
9
+ - ✅ 自动捕获所有请求和响应
10
+ - ✅ 智能文件保存(JSON/JS/CSS/HTML 自动格式化)
11
+ - ✅ 双数据结构(queue + map)
12
+ - ✅ 同一 URL 多次请求支持
13
+ - ✅ 文件路径长度保护
14
+ - ✅ 扩展名根据 content-type 确定
15
+
16
+ ## 数据结构
17
+
18
+ ### 目录结构
19
+
20
+ ```
21
+ ~/request-data/
22
+ └── win-{id}/
23
+ ├── queue.json # URL 列表(按时间顺序)
24
+ ├── map.json # 请求详情映射
25
+ └── {domain}/ # 域名目录(hostname)
26
+ └── {pathname}/ # 路径目录(保持原样)
27
+ ├── {file}-{ts}-{idx}-header-req.json
28
+ ├── {file}-{ts}-{idx}-header-res.json
29
+ ├── {file}-{ts}-{idx}-body-req.txt
30
+ └── {file}-{ts}-{idx}-body-res.js
31
+ ```
32
+
33
+ ### 文件命名格式
34
+
35
+ ```
36
+ {basename}-{timestamp}-{index}-{part}-{direction}.{ext}
37
+ ```
38
+
39
+ **参数说明:**
40
+ - `basename`: URL 路径的文件名(去除扩展名)
41
+ - `timestamp`: 时间戳(毫秒)
42
+ - `index`: 计数器(同一 URL 的第 N 个请求)
43
+ - `part`: `header` 或 `body`
44
+ - `direction`: `req`(请求)或 `res`(响应)
45
+ - `ext`: 根据 content-type 确定的扩展名
46
+
47
+ **示例:**
48
+ ```
49
+ api-1770405397441-1-header-req.json
50
+ api-1770405397441-1-body-req.json
51
+ api-1770405397442-1-header-res.json
52
+ api-1770405397442-1-body-res.json
53
+ ```
54
+
55
+ ### queue.json
56
+
57
+ URL 列表,按请求时间顺序排列:
58
+
59
+ ```json
60
+ [
61
+ "https://example.com/api/users",
62
+ "https://example.com/api/posts",
63
+ "https://example.com/static/app.js"
64
+ ]
65
+ ```
66
+
67
+ ### map.json
68
+
69
+ URL 到请求/响应详情的映射:
70
+
71
+ ```json
72
+ {
73
+ "https://example.com/api/users": {
74
+ "requests": [
75
+ {
76
+ "__file": "/path/to/users-1770405397441-1-header-req.json",
77
+ "__size": 1234,
78
+ "__binary": false
79
+ }
80
+ ],
81
+ "responses": [
82
+ {
83
+ "__file": "/path/to/users-1770405397442-1-header-res.json",
84
+ "__size": 5678,
85
+ "__binary": false
86
+ }
87
+ ]
88
+ }
89
+ }
90
+ ```
91
+
92
+ ## 文件保存策略
93
+
94
+ ### 自动保存规则
95
+
96
+ 1. **JSON/JS/CSS/HTML**:即使 <1KB 也保存到文件并格式化
97
+ 2. **其他类型**:>1KB 或二进制数据才保存
98
+ 3. **小数据**:<1KB 的非代码数据直接存储在 map.json 中
99
+
100
+ ### 格式化
101
+
102
+ 使用 `js-beautify` 自动格式化:
103
+ - JSON - 2 空格缩进
104
+ - JavaScript - 2 空格缩进
105
+ - CSS - 2 空格缩进
106
+ - HTML - 2 空格缩进
107
+
108
+ ### 扩展名映射
109
+
110
+ 根据 `Content-Type` 确定文件扩展名:
111
+
112
+ | Content-Type | 扩展名 |
113
+ |--------------|--------|
114
+ | application/json | .json |
115
+ | text/javascript | .js |
116
+ | application/javascript | .js |
117
+ | text/css | .css |
118
+ | text/html | .html |
119
+ | image/png | .png |
120
+ | image/jpeg | .jpg |
121
+ | video/mp4 | .mp4 |
122
+ | font/woff2 | .bin |
123
+ | 其他 | .txt 或 .bin |
124
+
125
+ ## MCP 工具
126
+
127
+ ### get_request_urls
128
+
129
+ 获取窗口的所有请求 URL 列表。
130
+
131
+ **参数:**
132
+ ```javascript
133
+ {
134
+ win_id: number, // 窗口 ID
135
+ page?: number, // 页码(默认 1)
136
+ page_size?: number, // 每页数量(默认 100)
137
+ filter?: string // URL 过滤(支持正则)
138
+ }
139
+ ```
140
+
141
+ **返回:**
142
+ ```json
143
+ {
144
+ "total": 150,
145
+ "page": 1,
146
+ "page_size": 100,
147
+ "total_pages": 2,
148
+ "urls": ["https://...", "https://..."]
149
+ }
150
+ ```
151
+
152
+ **示例:**
153
+ ```javascript
154
+ // 获取所有 URL
155
+ { win_id: 1 }
156
+
157
+ // 过滤包含 "api" 的 URL
158
+ { win_id: 1, filter: "api" }
159
+
160
+ // 过滤所有 .js 文件
161
+ { win_id: 1, filter: "\\.js$" }
162
+ ```
163
+
164
+ ### get_requests
165
+
166
+ 获取窗口的所有请求详情。
167
+
168
+ **参数:**
169
+ ```javascript
170
+ {
171
+ win_id: number, // 窗口 ID
172
+ page?: number, // 页码(默认 1)
173
+ page_size?: number, // 每页数量(默认 50)
174
+ filter?: string // URL 过滤(支持正则)
175
+ }
176
+ ```
177
+
178
+ **返回:**
179
+ ```json
180
+ {
181
+ "total": 150,
182
+ "page": 1,
183
+ "page_size": 50,
184
+ "total_pages": 3,
185
+ "data": [
186
+ {
187
+ "url": "https://example.com/api",
188
+ "requestCount": 2,
189
+ "responseCount": 2,
190
+ "requests": [
191
+ {
192
+ "__file": "/path/to/req-1.json",
193
+ "__size": 1234,
194
+ "__binary": false
195
+ }
196
+ ],
197
+ "responses": [
198
+ {
199
+ "__file": "/path/to/res-1.json",
200
+ "__size": 5678,
201
+ "__binary": false
202
+ }
203
+ ]
204
+ }
205
+ ]
206
+ }
207
+ ```
208
+
209
+ ### get_request_detail_by_url
210
+
211
+ 根据 URL 获取特定请求的详情。
212
+
213
+ **参数:**
214
+ ```javascript
215
+ {
216
+ win_id: number, // 窗口 ID
217
+ url: string // 完整 URL
218
+ }
219
+ ```
220
+
221
+ **返回:**
222
+ ```json
223
+ {
224
+ "url": "https://example.com/api",
225
+ "requestCount": 2,
226
+ "responseCount": 2,
227
+ "requests": [...],
228
+ "responses": [...]
229
+ }
230
+ ```
231
+
232
+ ### clear_requests
233
+
234
+ 清空窗口的所有请求记录(仅清空内存,不删除文件)。
235
+
236
+ **参数:**
237
+ ```javascript
238
+ {
239
+ win_id: number // 窗口 ID
240
+ }
241
+ ```
242
+
243
+ ## 请求/响应文件格式
244
+
245
+ ### Request Header 文件
246
+
247
+ ```json
248
+ {
249
+ "timestamp": 1770405397441,
250
+ "url": "https://example.com/api",
251
+ "method": "POST",
252
+ "resourceType": "xhr",
253
+ "headers": {
254
+ "Content-Type": "application/json",
255
+ "Authorization": "Bearer ..."
256
+ },
257
+ "postData": {
258
+ "__file": "/path/to/body-req.json",
259
+ "__size": 1234
260
+ }
261
+ }
262
+ ```
263
+
264
+ ### Response Header 文件
265
+
266
+ ```json
267
+ {
268
+ "timestamp": 1770405397442,
269
+ "status": 200,
270
+ "statusText": "OK",
271
+ "headers": {
272
+ "Content-Type": "application/json",
273
+ "Cache-Control": "no-cache"
274
+ },
275
+ "mimeType": "application/json",
276
+ "encodedDataLength": 5678,
277
+ "body": {
278
+ "__file": "/path/to/body-res.json",
279
+ "__size": 5678,
280
+ "__binary": false
281
+ }
282
+ }
283
+ ```
284
+
285
+ ### Body 文件
286
+
287
+ 根据 content-type 自动格式化:
288
+
289
+ **JSON:**
290
+ ```json
291
+ {
292
+ "id": 123,
293
+ "name": "example"
294
+ }
295
+ ```
296
+
297
+ **JavaScript:**
298
+ ```javascript
299
+ function example() {
300
+ console.log("formatted");
301
+ }
302
+ ```
303
+
304
+ **CSS:**
305
+ ```css
306
+ body {
307
+ margin: 0;
308
+ padding: 0;
309
+ }
310
+ ```
311
+
312
+ ## 路径长度保护
313
+
314
+ 系统自动处理超长路径:
315
+
316
+ - **pathname** 最大 200 字符
317
+ - **basename** 最大 100 字符
318
+ - 超长部分截断并添加 MD5 哈希(8位)
319
+
320
+ **示例:**
321
+ ```
322
+ 原始: /very/long/path/with/many/segments/...(300字符)
323
+ 处理: /very/long/path/with/many/segments/...-a1b2c3d4
324
+ ```
325
+
326
+ ## 错误处理
327
+
328
+ 文件保存失败时返回错误信息:
329
+
330
+ ```json
331
+ {
332
+ "__error": "ENAMETOOLONG: name too long",
333
+ "__url": "https://...",
334
+ "__size": 12345
335
+ }
336
+ ```
337
+
338
+ ## 性能优化
339
+
340
+ - **节流保存**:1 秒延迟批量写入 map.json 和 queue.json
341
+ - **分离文件**:大数据保存到独立文件,减少 JSON 体积
342
+ - **计数器缓存**:内存中维护文件计数器,避免重复扫描
343
+
344
+ ## 使用示例
345
+
346
+ ### 捕获网页请求
347
+
348
+ ```javascript
349
+ // 打开窗口
350
+ const win = await openWindow({ url: "https://example.com" });
351
+
352
+ // 等待页面加载
353
+ await sleep(10000);
354
+
355
+ // 获取所有请求
356
+ const requests = await getRequests(win.id);
357
+ console.log(`捕获了 ${requests.total} 个请求`);
358
+
359
+ // 过滤 API 请求
360
+ const apiRequests = await getRequests(win.id, { filter: "api" });
361
+
362
+ // 获取特定 URL 的详情
363
+ const detail = await getRequestDetailByUrl(win.id, "https://example.com/api/users");
364
+ ```
365
+
366
+ ### 读取保存的文件
367
+
368
+ ```javascript
369
+ const fs = require('fs');
370
+
371
+ // 读取 request header
372
+ const reqHeader = JSON.parse(fs.readFileSync('/path/to/req-header.json'));
373
+
374
+ // 读取 response body
375
+ const resBody = fs.readFileSync('/path/to/res-body.json', 'utf8');
376
+ const data = JSON.parse(resBody);
377
+ ```
378
+
379
+ ## 常见问题
380
+
381
+ ### Q: 如何删除已保存的文件?
382
+
383
+ A: 手动删除 `~/request-data/win-{id}/` 目录。`clear_requests` 工具只清空内存。
384
+
385
+ ### Q: 文件保存在哪里?
386
+
387
+ A: `~/request-data/win-{id}/` 目录,每个窗口独立目录。
388
+
389
+ ### Q: 如何过滤特定类型的请求?
390
+
391
+ A: 使用 `filter` 参数,支持正则表达式:
392
+ ```javascript
393
+ { filter: "\\.js$" } // JS 文件
394
+ { filter: "api" } // 包含 api
395
+ { filter: "google|facebook" } // 多个关键词
396
+ ```
397
+
398
+ ### Q: 同一个 URL 多次请求会覆盖吗?
399
+
400
+ A: 不会。每次请求都会保存为独立文件,使用时间戳和计数器区分。
401
+
402
+ ### Q: 支持哪些文件类型?
403
+
404
+ A: 支持所有类型。文本文件会格式化,二进制文件直接保存。
405
+
406
+ ## 技术细节
407
+
408
+ ### 监听机制
409
+
410
+ - `onBeforeSendHeaders` - 捕获请求
411
+ - `Network.loadingFinished` - 捕获响应
412
+ - `Network.getResponseBody` - 获取响应体
413
+
414
+ ### 数据流
415
+
416
+ ```
417
+ Request → onBeforeSendHeaders → handleData → saveDataToFile
418
+
419
+ queue.json (URL)
420
+
421
+ Response → loadingFinished → handleData → saveDataToFile
422
+
423
+ map.json (详情)
424
+ ```
425
+
426
+ ## 更新日志
427
+
428
+ ### v1.0.0 (2026-02-07)
429
+
430
+ - ✅ 初始版本
431
+ - ✅ 双数据结构(queue + map)
432
+ - ✅ 自动格式化代码
433
+ - ✅ 路径长度保护
434
+ - ✅ 扩展名智能识别
435
+ - ✅ MCP 工具集成
@@ -0,0 +1,155 @@
1
+ # REST API Feature
2
+
3
+ ## ✅ Completed
4
+
5
+ Added REST API endpoints for all MCP tools with Swagger documentation.
6
+
7
+ ## Features
8
+
9
+ ### 1. REST Endpoints
10
+
11
+ Each tool now has its own REST endpoint:
12
+
13
+ ```
14
+ POST /rpc/{toolName}
15
+ ```
16
+
17
+ Examples:
18
+ - `POST /rpc/ping` - Health check
19
+ - `POST /rpc/open_window` - Open browser window
20
+ - `POST /rpc/get_windows` - List all windows
21
+ - `POST /rpc/close_window` - Close window
22
+ - `POST /rpc/exec_js` - Execute JavaScript
23
+ - `POST /rpc/cdp_click` - Click element
24
+ - `POST /rpc/cdp_screenshot` - Take screenshot
25
+
26
+ ### 2. Swagger UI
27
+
28
+ Interactive API documentation at:
29
+
30
+ ```
31
+ http://localhost:8101/api-docs
32
+ ```
33
+
34
+ Features:
35
+ - Browse all available tools
36
+ - View request/response schemas
37
+ - Try out APIs directly in browser
38
+ - Authentication support
39
+
40
+ ### 3. Tool Discovery
41
+
42
+ List all available tools:
43
+
44
+ ```bash
45
+ GET /rpc/tools
46
+ ```
47
+
48
+ Returns:
49
+ ```json
50
+ {
51
+ "tools": [
52
+ {"name": "ping", "description": "..."},
53
+ {"name": "open_window", "description": "..."},
54
+ ...
55
+ ]
56
+ }
57
+ ```
58
+
59
+ ## Usage
60
+
61
+ ### Quick Start
62
+
63
+ ```bash
64
+ # Run demo script
65
+ bash examples/rest-api-demo.sh
66
+ ```
67
+
68
+ ### Manual Testing
69
+
70
+ ```bash
71
+ # Ping
72
+ curl -X POST http://localhost:8101/rpc/ping \
73
+ -H "Content-Type: application/json" \
74
+ -H "Authorization: Bearer $(cat ~/data/electron/token.txt)" \
75
+ -d '{}'
76
+
77
+ # Open window
78
+ curl -X POST http://localhost:8101/rpc/open_window \
79
+ -H "Content-Type: application/json" \
80
+ -H "Authorization: Bearer $(cat ~/data/electron/token.txt)" \
81
+ -d '{"url":"https://example.com","accountIdx":0}'
82
+ ```
83
+
84
+ ### Automated Tests
85
+
86
+ ```bash
87
+ cd tests/rpc
88
+ npm test rest-api.test.js
89
+ ```
90
+
91
+ ## Documentation
92
+
93
+ - **Full API Docs**: `docs/REST-API.md`
94
+ - **Swagger UI**: http://localhost:8101/api-docs
95
+ - **Examples**: `examples/rest-api-demo.sh`
96
+
97
+ ## Benefits
98
+
99
+ 1. **Simpler URLs**: `/rpc/ping` vs `/rpc` with JSON-RPC payload
100
+ 2. **Standard HTTP**: Use any HTTP client
101
+ 3. **Self-documenting**: Swagger UI for exploration
102
+ 4. **Easy testing**: Direct curl commands
103
+ 5. **Language agnostic**: Works with any HTTP library
104
+
105
+ ## Comparison
106
+
107
+ ### Before (JSON-RPC)
108
+
109
+ ```bash
110
+ POST /rpc
111
+ {
112
+ "jsonrpc": "2.0",
113
+ "id": 1,
114
+ "method": "tools/call",
115
+ "params": {
116
+ "name": "ping",
117
+ "arguments": {}
118
+ }
119
+ }
120
+ ```
121
+
122
+ ### After (REST)
123
+
124
+ ```bash
125
+ POST /rpc/ping
126
+ {}
127
+ ```
128
+
129
+ ## Implementation
130
+
131
+ - Added dynamic route: `POST /rpc/:toolName`
132
+ - Integrated swagger-ui-express and swagger-jsdoc
133
+ - Added OpenAPI 3.0 annotations
134
+ - Maintained backward compatibility with JSON-RPC endpoint
135
+
136
+ ## Files Changed
137
+
138
+ - `src/main.js` - Added REST routes and Swagger
139
+ - `tests/rpc/rest-api.test.js` - REST API tests
140
+ - `docs/REST-API.md` - Complete documentation
141
+ - `examples/rest-api-demo.sh` - Usage examples
142
+
143
+ ## Next Steps
144
+
145
+ - ✅ REST endpoints working
146
+ - ✅ Swagger UI accessible
147
+ - ✅ Documentation complete
148
+ - ✅ Examples provided
149
+ - ⚠️ Test stability (service crashes on repeated window operations)
150
+
151
+ ## Known Issues
152
+
153
+ - Service may crash when running full test suite (window operations)
154
+ - Individual REST calls work perfectly
155
+ - Recommend using service restart between test runs