@creatoria/miniapp-mcp 0.1.2 → 0.2.0
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/README.md +14 -3
- package/dist/app/cli/index.d.ts +6 -0
- package/dist/app/cli/index.d.ts.map +1 -0
- package/dist/app/cli/index.js +6 -0
- package/dist/app/cli/index.js.map +1 -0
- package/dist/app/index.d.ts +6 -0
- package/dist/app/index.d.ts.map +1 -0
- package/dist/app/index.js +6 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/server/index.d.ts +7 -0
- package/dist/app/server/index.d.ts.map +1 -0
- package/dist/app/server/index.js +6 -0
- package/dist/app/server/index.js.map +1 -0
- package/dist/capabilities/assert/index.d.ts +5 -0
- package/dist/capabilities/assert/index.d.ts.map +1 -0
- package/dist/capabilities/assert/index.js +5 -0
- package/dist/capabilities/assert/index.js.map +1 -0
- package/dist/capabilities/automator/index.d.ts +6 -0
- package/dist/capabilities/automator/index.d.ts.map +1 -0
- package/dist/capabilities/automator/index.js +6 -0
- package/dist/capabilities/automator/index.js.map +1 -0
- package/dist/capabilities/automator/schemas/close.d.ts +5 -0
- package/dist/capabilities/automator/schemas/close.d.ts.map +1 -0
- package/dist/capabilities/automator/schemas/close.js +11 -0
- package/dist/capabilities/automator/schemas/close.js.map +1 -0
- package/dist/capabilities/automator/schemas/connect.d.ts +11 -0
- package/dist/capabilities/automator/schemas/connect.d.ts.map +1 -0
- package/dist/capabilities/automator/schemas/connect.js +19 -0
- package/dist/capabilities/automator/schemas/connect.js.map +1 -0
- package/dist/capabilities/automator/schemas/disconnect.d.ts +5 -0
- package/dist/capabilities/automator/schemas/disconnect.d.ts.map +1 -0
- package/dist/capabilities/automator/schemas/disconnect.js +11 -0
- package/dist/capabilities/automator/schemas/disconnect.js.map +1 -0
- package/dist/capabilities/automator/schemas/index.d.ts +4 -0
- package/dist/capabilities/automator/schemas/index.d.ts.map +1 -0
- package/dist/capabilities/automator/schemas/index.js +12 -0
- package/dist/capabilities/automator/schemas/index.js.map +1 -0
- package/dist/capabilities/automator/schemas/launch.d.ts +17 -0
- package/dist/capabilities/automator/schemas/launch.d.ts.map +1 -0
- package/dist/capabilities/automator/schemas/launch.js +26 -0
- package/dist/capabilities/automator/schemas/launch.js.map +1 -0
- package/dist/capabilities/element/index.d.ts +5 -0
- package/dist/capabilities/element/index.d.ts.map +1 -0
- package/dist/capabilities/element/index.js +5 -0
- package/dist/capabilities/element/index.js.map +1 -0
- package/dist/capabilities/index.d.ts +15 -0
- package/dist/capabilities/index.d.ts.map +1 -0
- package/dist/capabilities/index.js +14 -0
- package/dist/capabilities/index.js.map +1 -0
- package/dist/capabilities/miniprogram/index.d.ts +5 -0
- package/dist/capabilities/miniprogram/index.d.ts.map +1 -0
- package/dist/capabilities/miniprogram/index.js +5 -0
- package/dist/capabilities/miniprogram/index.js.map +1 -0
- package/dist/capabilities/network/index.d.ts +5 -0
- package/dist/capabilities/network/index.d.ts.map +1 -0
- package/dist/capabilities/network/index.js +5 -0
- package/dist/capabilities/network/index.js.map +1 -0
- package/dist/capabilities/page/index.d.ts +5 -0
- package/dist/capabilities/page/index.d.ts.map +1 -0
- package/dist/capabilities/page/index.js +5 -0
- package/dist/capabilities/page/index.js.map +1 -0
- package/dist/capabilities/record/index.d.ts +5 -0
- package/dist/capabilities/record/index.d.ts.map +1 -0
- package/dist/capabilities/record/index.js +5 -0
- package/dist/capabilities/record/index.js.map +1 -0
- package/dist/capabilities/schema-registry.d.ts +4 -0
- package/dist/capabilities/schema-registry.d.ts.map +1 -0
- package/dist/capabilities/schema-registry.js +18 -0
- package/dist/capabilities/schema-registry.js.map +1 -0
- package/dist/capabilities/schema-types.d.ts +22 -0
- package/dist/capabilities/schema-types.d.ts.map +1 -0
- package/dist/capabilities/schema-types.js +2 -0
- package/dist/capabilities/schema-types.js.map +1 -0
- package/dist/capabilities/snapshot/index.d.ts +5 -0
- package/dist/capabilities/snapshot/index.d.ts.map +1 -0
- package/dist/capabilities/snapshot/index.js +5 -0
- package/dist/capabilities/snapshot/index.js.map +1 -0
- package/dist/config/loader.js +1 -1
- package/dist/config/loader.js.map +1 -1
- package/dist/core/element-ref.d.ts +1 -43
- package/dist/core/element-ref.d.ts.map +1 -1
- package/dist/core/element-ref.js +1 -212
- package/dist/core/element-ref.js.map +1 -1
- package/dist/core/logger.d.ts +1 -54
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +1 -377
- package/dist/core/logger.js.map +1 -1
- package/dist/core/output.d.ts +1 -20
- package/dist/core/output.d.ts.map +1 -1
- package/dist/core/output.js +1 -55
- package/dist/core/output.js.map +1 -1
- package/dist/core/report-generator.d.ts +1 -23
- package/dist/core/report-generator.d.ts.map +1 -1
- package/dist/core/report-generator.js +1 -211
- package/dist/core/report-generator.js.map +1 -1
- package/dist/core/session.d.ts +2 -82
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +2 -305
- package/dist/core/session.js.map +1 -1
- package/dist/core/timeout.d.ts +1 -48
- package/dist/core/timeout.d.ts.map +1 -1
- package/dist/core/timeout.js +1 -66
- package/dist/core/timeout.js.map +1 -1
- package/dist/core/tool-logger.d.ts +1 -82
- package/dist/core/tool-logger.d.ts.map +1 -1
- package/dist/core/tool-logger.js +1 -452
- package/dist/core/tool-logger.js.map +1 -1
- package/dist/core/validation.d.ts +1 -38
- package/dist/core/validation.d.ts.map +1 -1
- package/dist/core/validation.js +1 -92
- package/dist/core/validation.js.map +1 -1
- package/dist/runtime/element/element-ref.d.ts +44 -0
- package/dist/runtime/element/element-ref.d.ts.map +1 -0
- package/dist/runtime/element/element-ref.js +214 -0
- package/dist/runtime/element/element-ref.js.map +1 -0
- package/dist/runtime/element/index.d.ts +2 -0
- package/dist/runtime/element/index.d.ts.map +1 -0
- package/dist/runtime/element/index.js +2 -0
- package/dist/runtime/element/index.js.map +1 -0
- package/dist/runtime/index.d.ts +10 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +10 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/logging/index.d.ts +3 -0
- package/dist/runtime/logging/index.d.ts.map +1 -0
- package/dist/runtime/logging/index.js +3 -0
- package/dist/runtime/logging/index.js.map +1 -0
- package/dist/runtime/logging/logger.d.ts +55 -0
- package/dist/runtime/logging/logger.d.ts.map +1 -0
- package/dist/runtime/logging/logger.js +379 -0
- package/dist/runtime/logging/logger.js.map +1 -0
- package/dist/runtime/logging/tool-logger.d.ts +83 -0
- package/dist/runtime/logging/tool-logger.d.ts.map +1 -0
- package/dist/runtime/logging/tool-logger.js +454 -0
- package/dist/runtime/logging/tool-logger.js.map +1 -0
- package/dist/runtime/outputs/index.d.ts +3 -0
- package/dist/runtime/outputs/index.d.ts.map +1 -0
- package/dist/runtime/outputs/index.js +3 -0
- package/dist/runtime/outputs/index.js.map +1 -0
- package/dist/runtime/outputs/output-manager.d.ts +12 -0
- package/dist/runtime/outputs/output-manager.d.ts.map +1 -0
- package/dist/runtime/outputs/output-manager.js +39 -0
- package/dist/runtime/outputs/output-manager.js.map +1 -0
- package/dist/runtime/outputs/report-generator.d.ts +5 -0
- package/dist/runtime/outputs/report-generator.d.ts.map +1 -0
- package/dist/runtime/outputs/report-generator.js +175 -0
- package/dist/runtime/outputs/report-generator.js.map +1 -0
- package/dist/runtime/session/index.d.ts +3 -0
- package/dist/runtime/session/index.d.ts.map +1 -0
- package/dist/runtime/session/index.js +3 -0
- package/dist/runtime/session/index.js.map +1 -0
- package/dist/runtime/session/store.d.ts +28 -0
- package/dist/runtime/session/store.d.ts.map +1 -0
- package/dist/runtime/session/store.js +154 -0
- package/dist/runtime/session/store.js.map +1 -0
- package/dist/runtime/session/utils/cleanup.d.ts +3 -0
- package/dist/runtime/session/utils/cleanup.d.ts.map +1 -0
- package/dist/runtime/session/utils/cleanup.js +78 -0
- package/dist/runtime/session/utils/cleanup.js.map +1 -0
- package/dist/runtime/timeout/index.d.ts +2 -0
- package/dist/runtime/timeout/index.d.ts.map +1 -0
- package/dist/runtime/timeout/index.js +2 -0
- package/dist/runtime/timeout/index.js.map +1 -0
- package/dist/runtime/timeout/timeout.d.ts +49 -0
- package/dist/runtime/timeout/timeout.d.ts.map +1 -0
- package/dist/runtime/timeout/timeout.js +67 -0
- package/dist/runtime/timeout/timeout.js.map +1 -0
- package/dist/runtime/validation/index.d.ts +2 -0
- package/dist/runtime/validation/index.d.ts.map +1 -0
- package/dist/runtime/validation/index.js +2 -0
- package/dist/runtime/validation/index.js.map +1 -0
- package/dist/runtime/validation/validation.d.ts +39 -0
- package/dist/runtime/validation/validation.d.ts.map +1 -0
- package/dist/runtime/validation/validation.js +93 -0
- package/dist/runtime/validation/validation.js.map +1 -0
- package/dist/schemas/automator/miniprogram_close.json +12 -0
- package/dist/schemas/automator/miniprogram_connect.json +19 -0
- package/dist/schemas/automator/miniprogram_disconnect.json +12 -0
- package/dist/schemas/automator/miniprogram_launch.json +30 -0
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +3 -3
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/miniprogram.d.ts +2 -1
- package/dist/tools/miniprogram.d.ts.map +1 -1
- package/dist/tools/miniprogram.js +19 -24
- package/dist/tools/miniprogram.js.map +1 -1
- package/dist/tools/page.js +2 -2
- package/dist/tools/page.js.map +1 -1
- package/docs/directory-structure-and-code-style-best-practices.md +91 -0
- package/docs/migration/README.md +34 -0
- package/docs/migration/TC-ALIGN-01-notes.md +35 -0
- package/docs/migration/runtime-skeleton.md +50 -0
- package/docs/migration/tool-schema-strategy.md +75 -0
- package/docs//345/256/214/346/225/264/345/256/236/347/216/260/346/226/271/346/241/210.md +14 -14
- package/docs//347/254/254/344/270/200/347/211/210/346/234/254/346/226/271/346/241/210.md +7 -7
- package/package.json +4 -2
- package/docs/SIMPLE_USAGE.md +0 -210
- package/docs/architecture.E-Docs.md +0 -1359
- package/docs/architecture.F1.md +0 -720
- package/docs/architecture.F2.md +0 -871
- package/docs/architecture.F3.md +0 -905
- package/docs/architecture.md +0 -90
- package/docs/charter.A1.align.yaml +0 -170
- package/docs/charter.A2.align.yaml +0 -199
- package/docs/charter.A3.align.yaml +0 -242
- package/docs/charter.A4.align.yaml +0 -227
- package/docs/charter.B1.align.yaml +0 -179
- package/docs/charter.B2.align.yaml +0 -200
- package/docs/charter.B3.align.yaml +0 -200
- package/docs/charter.B4.align.yaml +0 -188
- package/docs/charter.C1.align.yaml +0 -190
- package/docs/charter.C2.align.yaml +0 -202
- package/docs/charter.C3.align.yaml +0 -211
- package/docs/charter.C4.align.yaml +0 -263
- package/docs/charter.C5.align.yaml +0 -220
- package/docs/charter.D1.align.yaml +0 -190
- package/docs/charter.D2.align.yaml +0 -234
- package/docs/charter.D3.align.yaml +0 -206
- package/docs/charter.E-Docs.align.yaml +0 -294
- package/docs/charter.F1.align.yaml +0 -193
- package/docs/charter.F2.align.yaml +0 -248
- package/docs/charter.F3.align.yaml +0 -287
- package/docs/charter.G.align.yaml +0 -174
- package/docs/charter.align.yaml +0 -111
- package/docs/maintenance.md +0 -682
- package/docs/playwright-mcp/350/260/203/347/240/224.md +0 -53
- package/docs/setup-guide.md +0 -775
- package/docs/tasks.A1.atomize.md +0 -296
- package/docs/tasks.A2.atomize.md +0 -408
- package/docs/tasks.A3.atomize.md +0 -564
- package/docs/tasks.A4.atomize.md +0 -496
- package/docs/tasks.B1.atomize.md +0 -352
- package/docs/tasks.B2.atomize.md +0 -561
- package/docs/tasks.B3.atomize.md +0 -508
- package/docs/tasks.B4.atomize.md +0 -504
- package/docs/tasks.C1.atomize.md +0 -540
- package/docs/tasks.C2.atomize.md +0 -665
- package/docs/tasks.C3.atomize.md +0 -745
- package/docs/tasks.C4.atomize.md +0 -908
- package/docs/tasks.C5.atomize.md +0 -755
- package/docs/tasks.D1.atomize.md +0 -547
- package/docs/tasks.D2.atomize.md +0 -619
- package/docs/tasks.D3.atomize.md +0 -790
- package/docs/tasks.E-Docs.atomize.md +0 -1204
- package/docs/tasks.atomize.md +0 -189
package/docs/tasks.C1.atomize.md
DELETED
|
@@ -1,540 +0,0 @@
|
|
|
1
|
-
# Task Card: [C1] Automator 工具
|
|
2
|
-
|
|
3
|
-
**Task ID**: C1
|
|
4
|
-
**Task Name**: Automator 工具实现
|
|
5
|
-
**Charter**: `docs/charter.C1.align.yaml`
|
|
6
|
-
**Stage**: C (Tool Implementation)
|
|
7
|
-
**Status**: ✅ COMPLETED (Retrospective)
|
|
8
|
-
**Estimated**: 2-3 hours
|
|
9
|
-
**Actual**: ~3 hours
|
|
10
|
-
**Completed**: 2025-10-02
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
## 目标 (Goal)
|
|
15
|
-
|
|
16
|
-
实现 Automator 级别的 4 个 MCP 工具,封装微信开发者工具的启动、连接、断开和关闭功能。
|
|
17
|
-
|
|
18
|
-
**交付物**:
|
|
19
|
-
- ✅ `src/tools/automator.ts` (252 lines)
|
|
20
|
-
- ✅ `tests/unit/automator.test.ts` (364 lines, 20 tests)
|
|
21
|
-
- ✅ 4 个工具: launch, connect, disconnect, close
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
## 前置条件 (Prerequisites)
|
|
26
|
-
|
|
27
|
-
- ✅ B1: MCP Server 骨架已完成
|
|
28
|
-
- ✅ B2: SessionStore 已实现
|
|
29
|
-
- ✅ `miniprogram-automator` 已安装
|
|
30
|
-
- ✅ 微信开发者工具已安装
|
|
31
|
-
- ✅ 了解 miniprogram-automator API
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
## 实现步骤 (Steps)
|
|
36
|
-
|
|
37
|
-
### 1. 定义工具 Schema ✅
|
|
38
|
-
|
|
39
|
-
**文件**: `src/tools/automator.ts`
|
|
40
|
-
|
|
41
|
-
**步骤**:
|
|
42
|
-
```typescript
|
|
43
|
-
import { z } from 'zod'
|
|
44
|
-
|
|
45
|
-
// launch 工具 Schema
|
|
46
|
-
const launchSchema = z.object({
|
|
47
|
-
projectPath: z.string().describe('小程序项目路径'),
|
|
48
|
-
port: z.number().optional().default(9420).describe('自动化端口'),
|
|
49
|
-
cliPath: z.string().optional().describe('CLI 路径'),
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
// connect 工具 Schema
|
|
53
|
-
const connectSchema = z.object({
|
|
54
|
-
port: z.number().optional().default(9420).describe('自动化端口'),
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
// disconnect/close 工具 Schema
|
|
58
|
-
const sessionSchema = z.object({
|
|
59
|
-
sessionId: z.string().describe('会话 ID'),
|
|
60
|
-
})
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
**验证**: TypeScript 编译通过,Schema 类型正确
|
|
64
|
-
|
|
65
|
-
---
|
|
66
|
-
|
|
67
|
-
### 2. 实现 launch 工具 ✅
|
|
68
|
-
|
|
69
|
-
**功能**: 启动微信开发者工具并打开小程序项目
|
|
70
|
-
|
|
71
|
-
**代码**:
|
|
72
|
-
```typescript
|
|
73
|
-
async function handleLaunch(args: LaunchArgs, context: ToolContext) {
|
|
74
|
-
const { projectPath, port, cliPath } = args
|
|
75
|
-
const sessionId = uuidv4()
|
|
76
|
-
|
|
77
|
-
const session = context.getSession(sessionId)
|
|
78
|
-
|
|
79
|
-
const automator = await launch({
|
|
80
|
-
projectPath,
|
|
81
|
-
port,
|
|
82
|
-
cliPath: cliPath || DEFAULT_CLI_PATH,
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
session.automator = automator
|
|
86
|
-
session.ideProcess = automator.process
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
content: [
|
|
90
|
-
{
|
|
91
|
-
type: 'text',
|
|
92
|
-
text: JSON.stringify({
|
|
93
|
-
sessionId,
|
|
94
|
-
port,
|
|
95
|
-
projectPath,
|
|
96
|
-
status: 'launched',
|
|
97
|
-
}, null, 2),
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
**验证**:
|
|
105
|
-
- ✅ 启动微信开发者工具
|
|
106
|
-
- ✅ 返回正确的 sessionId
|
|
107
|
-
- ✅ Session 中保存 automator 和 ideProcess
|
|
108
|
-
|
|
109
|
-
---
|
|
110
|
-
|
|
111
|
-
### 3. 实现 connect 工具 ✅
|
|
112
|
-
|
|
113
|
-
**功能**: 连接到已启动的开发者工具
|
|
114
|
-
|
|
115
|
-
**代码**:
|
|
116
|
-
```typescript
|
|
117
|
-
async function handleConnect(args: ConnectArgs, context: ToolContext) {
|
|
118
|
-
const { port } = args
|
|
119
|
-
const sessionId = uuidv4()
|
|
120
|
-
|
|
121
|
-
const session = context.getSession(sessionId)
|
|
122
|
-
|
|
123
|
-
const miniProgram = await connect({ port })
|
|
124
|
-
|
|
125
|
-
session.miniProgram = miniProgram
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
content: [
|
|
129
|
-
{
|
|
130
|
-
type: 'text',
|
|
131
|
-
text: JSON.stringify({
|
|
132
|
-
sessionId,
|
|
133
|
-
port,
|
|
134
|
-
status: 'connected',
|
|
135
|
-
}, null, 2),
|
|
136
|
-
},
|
|
137
|
-
],
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
**验证**:
|
|
143
|
-
- ✅ 连接成功获取 MiniProgram 实例
|
|
144
|
-
- ✅ Session 中保存 miniProgram
|
|
145
|
-
- ✅ 返回正确的 sessionId
|
|
146
|
-
|
|
147
|
-
---
|
|
148
|
-
|
|
149
|
-
### 4. 实现 disconnect 工具 ✅
|
|
150
|
-
|
|
151
|
-
**功能**: 断开连接但保留 IDE 进程
|
|
152
|
-
|
|
153
|
-
**代码**:
|
|
154
|
-
```typescript
|
|
155
|
-
async function handleDisconnect(args: SessionArgs, context: ToolContext) {
|
|
156
|
-
const { sessionId } = args
|
|
157
|
-
const session = context.getSession(sessionId)
|
|
158
|
-
|
|
159
|
-
if (session.miniProgram) {
|
|
160
|
-
await session.miniProgram.disconnect()
|
|
161
|
-
session.miniProgram = null
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return {
|
|
165
|
-
content: [
|
|
166
|
-
{
|
|
167
|
-
type: 'text',
|
|
168
|
-
text: JSON.stringify({
|
|
169
|
-
sessionId,
|
|
170
|
-
status: 'disconnected',
|
|
171
|
-
}, null, 2),
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
**验证**:
|
|
179
|
-
- ✅ MiniProgram 实例断开
|
|
180
|
-
- ✅ IDE 进程继续运行
|
|
181
|
-
- ✅ Session 中 miniProgram 设为 null
|
|
182
|
-
|
|
183
|
-
---
|
|
184
|
-
|
|
185
|
-
### 5. 实现 close 工具 ✅
|
|
186
|
-
|
|
187
|
-
**功能**: 完全关闭 IDE 并清理会话
|
|
188
|
-
|
|
189
|
-
**代码**:
|
|
190
|
-
```typescript
|
|
191
|
-
async function handleClose(args: SessionArgs, context: ToolContext) {
|
|
192
|
-
const { sessionId } = args
|
|
193
|
-
const session = context.getSession(sessionId)
|
|
194
|
-
|
|
195
|
-
if (session.miniProgram) {
|
|
196
|
-
await session.miniProgram.disconnect()
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (session.automator) {
|
|
200
|
-
await session.automator.close()
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
context.deleteSession(sessionId)
|
|
204
|
-
|
|
205
|
-
return {
|
|
206
|
-
content: [
|
|
207
|
-
{
|
|
208
|
-
type: 'text',
|
|
209
|
-
text: JSON.stringify({
|
|
210
|
-
sessionId,
|
|
211
|
-
status: 'closed',
|
|
212
|
-
}, null, 2),
|
|
213
|
-
},
|
|
214
|
-
],
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
**验证**:
|
|
220
|
-
- ✅ MiniProgram 断开
|
|
221
|
-
- ✅ Automator 关闭
|
|
222
|
-
- ✅ Session 删除
|
|
223
|
-
- ✅ IDE 进程终止
|
|
224
|
-
|
|
225
|
-
---
|
|
226
|
-
|
|
227
|
-
### 6. 编写单元测试 ✅
|
|
228
|
-
|
|
229
|
-
**文件**: `tests/unit/automator.test.ts`
|
|
230
|
-
|
|
231
|
-
**测试用例** (20 个):
|
|
232
|
-
```typescript
|
|
233
|
-
describe('Automator Tools', () => {
|
|
234
|
-
describe('launch', () => {
|
|
235
|
-
it('should launch with default port', async () => {})
|
|
236
|
-
it('should launch with custom port', async () => {})
|
|
237
|
-
it('should launch with custom cliPath', async () => {})
|
|
238
|
-
it('should throw error if projectPath missing', async () => {})
|
|
239
|
-
it('should handle launch failure', async () => {})
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
describe('connect', () => {
|
|
243
|
-
it('should connect with default port', async () => {})
|
|
244
|
-
it('should connect with custom port', async () => {})
|
|
245
|
-
it('should handle connection failure', async () => {})
|
|
246
|
-
it('should create new session', async () => {})
|
|
247
|
-
})
|
|
248
|
-
|
|
249
|
-
describe('disconnect', () => {
|
|
250
|
-
it('should disconnect successfully', async () => {})
|
|
251
|
-
it('should handle missing miniProgram', async () => {})
|
|
252
|
-
it('should throw error if session not found', async () => {})
|
|
253
|
-
it('should keep IDE process running', async () => {})
|
|
254
|
-
})
|
|
255
|
-
|
|
256
|
-
describe('close', () => {
|
|
257
|
-
it('should close automator and session', async () => {})
|
|
258
|
-
it('should handle missing automator', async () => {})
|
|
259
|
-
it('should delete session', async () => {})
|
|
260
|
-
it('should terminate IDE process', async () => {})
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
describe('error handling', () => {
|
|
264
|
-
it('should handle invalid sessionId', async () => {})
|
|
265
|
-
it('should handle network errors', async () => {})
|
|
266
|
-
it('should handle timeout errors', async () => {})
|
|
267
|
-
})
|
|
268
|
-
})
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
**验证**:
|
|
272
|
-
- ✅ 20 个测试全部通过
|
|
273
|
-
- ✅ Mock miniprogram-automator
|
|
274
|
-
- ✅ 覆盖成功和失败场景
|
|
275
|
-
|
|
276
|
-
---
|
|
277
|
-
|
|
278
|
-
### 7. 工具注册集成 ✅
|
|
279
|
-
|
|
280
|
-
**文件**: `src/tools/index.ts` (在 C5 中完成)
|
|
281
|
-
|
|
282
|
-
**代码**:
|
|
283
|
-
```typescript
|
|
284
|
-
export const AUTOMATOR_TOOLS = [
|
|
285
|
-
'miniapp_automator_launch',
|
|
286
|
-
'miniapp_automator_connect',
|
|
287
|
-
'miniapp_automator_disconnect',
|
|
288
|
-
'miniapp_automator_close',
|
|
289
|
-
]
|
|
290
|
-
|
|
291
|
-
// 在 registerTools 中注册
|
|
292
|
-
if (capabilities.includes('core')) {
|
|
293
|
-
registerAutomatorTools(server, context)
|
|
294
|
-
}
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
**验证**: 工具在 capabilities='core' 时正确注册
|
|
298
|
-
|
|
299
|
-
---
|
|
300
|
-
|
|
301
|
-
## 完成标准 (Definition of Done)
|
|
302
|
-
|
|
303
|
-
### 功能完成 ✅
|
|
304
|
-
|
|
305
|
-
- [x] launch 工具启动开发者工具
|
|
306
|
-
- [x] connect 工具连接并获取 MiniProgram
|
|
307
|
-
- [x] disconnect 工具断开连接保留 IDE
|
|
308
|
-
- [x] close 工具完全关闭并清理
|
|
309
|
-
- [x] 所有工具返回正确的响应格式
|
|
310
|
-
|
|
311
|
-
### 代码质量 ✅
|
|
312
|
-
|
|
313
|
-
- [x] TypeScript 编译 0 错误
|
|
314
|
-
- [x] 无 ESLint 错误
|
|
315
|
-
- [x] 代码行数 252 行(合理范围)
|
|
316
|
-
- [x] JSDoc 注释完整
|
|
317
|
-
- [x] 符合 ESM 规范(.js 后缀)
|
|
318
|
-
|
|
319
|
-
### 测试 ✅
|
|
320
|
-
|
|
321
|
-
- [x] 单元测试 364 行
|
|
322
|
-
- [x] 20 个测试用例全部通过
|
|
323
|
-
- [x] 覆盖成功和失败场景
|
|
324
|
-
- [x] Mock 外部依赖
|
|
325
|
-
|
|
326
|
-
### 文档 ⏳
|
|
327
|
-
|
|
328
|
-
- [x] 代码注释完整
|
|
329
|
-
- [x] Schema 描述清晰
|
|
330
|
-
- ⏳ charter.C1.align.yaml (追溯)
|
|
331
|
-
- ⏳ tasks.C1.atomize.md (本文档)
|
|
332
|
-
|
|
333
|
-
---
|
|
334
|
-
|
|
335
|
-
## 实现结果 (Implementation)
|
|
336
|
-
|
|
337
|
-
### 文件清单
|
|
338
|
-
|
|
339
|
-
| 文件 | 行数 | 说明 |
|
|
340
|
-
|------|------|------|
|
|
341
|
-
| `src/tools/automator.ts` | 252 | 4 个 Automator 工具实现 |
|
|
342
|
-
| `tests/unit/automator.test.ts` | 364 | 20 个单元测试 |
|
|
343
|
-
|
|
344
|
-
### 工具列表
|
|
345
|
-
|
|
346
|
-
| 工具名 | 功能 | 输入 | 输出 |
|
|
347
|
-
|--------|------|------|------|
|
|
348
|
-
| `miniapp_automator_launch` | 启动开发者工具 | projectPath, port?, cliPath? | sessionId, status |
|
|
349
|
-
| `miniapp_automator_connect` | 连接到开发者工具 | port? | sessionId, status |
|
|
350
|
-
| `miniapp_automator_disconnect` | 断开连接 | sessionId | status |
|
|
351
|
-
| `miniapp_automator_close` | 关闭开发者工具 | sessionId | status |
|
|
352
|
-
|
|
353
|
-
### 关键代码片段
|
|
354
|
-
|
|
355
|
-
**默认配置**:
|
|
356
|
-
```typescript
|
|
357
|
-
const DEFAULT_CLI_PATH = '/Applications/wechatwebdevtools.app/Contents/MacOS/cli'
|
|
358
|
-
const DEFAULT_PORT = 9420
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
**Session 清理**:
|
|
362
|
-
```typescript
|
|
363
|
-
// disconnect - 保留 IDE
|
|
364
|
-
session.miniProgram = null
|
|
365
|
-
|
|
366
|
-
// close - 完全清理
|
|
367
|
-
await session.automator.close()
|
|
368
|
-
context.deleteSession(sessionId)
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
### 设计决策
|
|
372
|
-
|
|
373
|
-
1. **Session ID 生成**
|
|
374
|
-
- 使用 UUID v4 自动生成
|
|
375
|
-
- 理由:避免冲突,便于追踪
|
|
376
|
-
|
|
377
|
-
2. **默认 CLI 路径**
|
|
378
|
-
- macOS: `/Applications/wechatwebdevtools.app/Contents/MacOS/cli`
|
|
379
|
-
- 理由:官方标准路径,覆盖大多数场景
|
|
380
|
-
|
|
381
|
-
3. **disconnect vs close**
|
|
382
|
-
- disconnect: 断开连接但保留 IDE
|
|
383
|
-
- close: 完全关闭 IDE 和清理 Session
|
|
384
|
-
- 理由:灵活性,支持重连场景
|
|
385
|
-
|
|
386
|
-
4. **错误处理**
|
|
387
|
-
- 明确区分启动失败、连接失败、会话不存在
|
|
388
|
-
- 理由:便于调试和问题定位
|
|
389
|
-
|
|
390
|
-
---
|
|
391
|
-
|
|
392
|
-
## 测试证据 (Test Evidence)
|
|
393
|
-
|
|
394
|
-
### 单元测试结果
|
|
395
|
-
|
|
396
|
-
```bash
|
|
397
|
-
$ pnpm test automator.test.ts
|
|
398
|
-
|
|
399
|
-
PASS tests/unit/automator.test.ts
|
|
400
|
-
Automator Tools
|
|
401
|
-
launch
|
|
402
|
-
✓ should launch with default port (15ms)
|
|
403
|
-
✓ should launch with custom port (8ms)
|
|
404
|
-
✓ should launch with custom cliPath (7ms)
|
|
405
|
-
✓ should throw error if projectPath missing (5ms)
|
|
406
|
-
✓ should handle launch failure (6ms)
|
|
407
|
-
connect
|
|
408
|
-
✓ should connect with default port (9ms)
|
|
409
|
-
✓ should connect with custom port (7ms)
|
|
410
|
-
✓ should handle connection failure (8ms)
|
|
411
|
-
✓ should create new session (6ms)
|
|
412
|
-
disconnect
|
|
413
|
-
✓ should disconnect successfully (10ms)
|
|
414
|
-
✓ should handle missing miniProgram (7ms)
|
|
415
|
-
✓ should throw error if session not found (6ms)
|
|
416
|
-
✓ should keep IDE process running (8ms)
|
|
417
|
-
close
|
|
418
|
-
✓ should close automator and session (11ms)
|
|
419
|
-
✓ should handle missing automator (7ms)
|
|
420
|
-
✓ should delete session (9ms)
|
|
421
|
-
✓ should terminate IDE process (10ms)
|
|
422
|
-
error handling
|
|
423
|
-
✓ should handle invalid sessionId (6ms)
|
|
424
|
-
✓ should handle network errors (8ms)
|
|
425
|
-
✓ should handle timeout errors (7ms)
|
|
426
|
-
|
|
427
|
-
Test Suites: 1 passed, 1 total
|
|
428
|
-
Tests: 20 passed, 20 total
|
|
429
|
-
Time: 2.453s
|
|
430
|
-
```
|
|
431
|
-
|
|
432
|
-
### 手动测试
|
|
433
|
-
|
|
434
|
-
**启动开发者工具**:
|
|
435
|
-
```bash
|
|
436
|
-
# 通过 MCP 调用 launch
|
|
437
|
-
{
|
|
438
|
-
"projectPath": "/path/to/miniprogram",
|
|
439
|
-
"port": 9420
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
# 返回
|
|
443
|
-
{
|
|
444
|
-
"sessionId": "550e8400-e29b-41d4-a716-446655440000",
|
|
445
|
-
"port": 9420,
|
|
446
|
-
"status": "launched"
|
|
447
|
-
}
|
|
448
|
-
```
|
|
449
|
-
|
|
450
|
-
**连接已启动的工具**:
|
|
451
|
-
```bash
|
|
452
|
-
# 通过 MCP 调用 connect
|
|
453
|
-
{
|
|
454
|
-
"port": 9420
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
# 返回
|
|
458
|
-
{
|
|
459
|
-
"sessionId": "660e9511-f39c-52e5-b827-557766551111",
|
|
460
|
-
"port": 9420,
|
|
461
|
-
"status": "connected"
|
|
462
|
-
}
|
|
463
|
-
```
|
|
464
|
-
|
|
465
|
-
---
|
|
466
|
-
|
|
467
|
-
## 已知问题 (Known Issues)
|
|
468
|
-
|
|
469
|
-
### 技术债务
|
|
470
|
-
|
|
471
|
-
1. **仅支持 macOS** - 🟡 中优先级
|
|
472
|
-
- 原因:CLI 路径硬编码 macOS 路径
|
|
473
|
-
- 影响:Windows/Linux 用户需手动指定 cliPath
|
|
474
|
-
- 计划:未来扩展跨平台支持
|
|
475
|
-
|
|
476
|
-
2. **无自动重连** - 🟢 低优先级
|
|
477
|
-
- 原因:简化实现
|
|
478
|
-
- 影响:连接断开需手动重连
|
|
479
|
-
- 计划:未来添加重试机制
|
|
480
|
-
|
|
481
|
-
### 风险
|
|
482
|
-
|
|
483
|
-
1. **端口冲突** - 🟡 中风险
|
|
484
|
-
- 缓解:明确错误提示
|
|
485
|
-
- 监控:用户反馈端口问题
|
|
486
|
-
|
|
487
|
-
2. **CLI 路径变化** - 🟢 低风险
|
|
488
|
-
- 缓解:允许自定义 cliPath
|
|
489
|
-
- 监控:关注微信开发者工具更新
|
|
490
|
-
|
|
491
|
-
---
|
|
492
|
-
|
|
493
|
-
## 参考资料 (References)
|
|
494
|
-
|
|
495
|
-
### 文档
|
|
496
|
-
|
|
497
|
-
- `docs/charter.C1.align.yaml` - 任务对齐文档
|
|
498
|
-
- `docs/微信小程序自动化完整操作手册.md` - Automator API 参考
|
|
499
|
-
- `docs/完整实现方案.md` - 工具分层设计
|
|
500
|
-
|
|
501
|
-
### 代码
|
|
502
|
-
|
|
503
|
-
- `src/core/session.ts` - Session 管理
|
|
504
|
-
- `src/tools/index.ts` - 工具注册器(C5)
|
|
505
|
-
- `src/types.ts` - 类型定义
|
|
506
|
-
|
|
507
|
-
### 外部资源
|
|
508
|
-
|
|
509
|
-
- [miniprogram-automator 文档](https://developers.weixin.qq.com/miniprogram/dev/devtools/auto/)
|
|
510
|
-
- [微信开发者工具下载](https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html)
|
|
511
|
-
|
|
512
|
-
---
|
|
513
|
-
|
|
514
|
-
## 后续任务 (Next Steps)
|
|
515
|
-
|
|
516
|
-
### 依赖此任务的后续任务
|
|
517
|
-
|
|
518
|
-
- ✅ C2: MiniProgram 工具(需要 MiniProgram 实例)
|
|
519
|
-
- ✅ C3: Page 工具(需要 MiniProgram 导航)
|
|
520
|
-
- ✅ C5: 工具注册器(集成 Automator 工具)
|
|
521
|
-
|
|
522
|
-
### 改进建议
|
|
523
|
-
|
|
524
|
-
1. **跨平台支持**
|
|
525
|
-
- 自动检测操作系统
|
|
526
|
-
- 提供 Windows/Linux 默认路径
|
|
527
|
-
|
|
528
|
-
2. **健康检查**
|
|
529
|
-
- 添加 ping 工具检测连接状态
|
|
530
|
-
- 自动重连机制
|
|
531
|
-
|
|
532
|
-
3. **多实例支持**
|
|
533
|
-
- 支持多个小程序同时运行
|
|
534
|
-
- 端口池管理
|
|
535
|
-
|
|
536
|
-
---
|
|
537
|
-
|
|
538
|
-
**任务状态**: ✅ COMPLETED
|
|
539
|
-
**代码提交**: ✅ 已提交(Stage C 提交)
|
|
540
|
-
**文档状态**: ⏳ RETROSPECTIVE (追溯补齐中)
|