@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.C2.atomize.md
DELETED
|
@@ -1,665 +0,0 @@
|
|
|
1
|
-
# Task Card: [C2] MiniProgram 工具
|
|
2
|
-
|
|
3
|
-
**Task ID**: C2
|
|
4
|
-
**Task Name**: MiniProgram 工具实现
|
|
5
|
-
**Charter**: `docs/charter.C2.align.yaml`
|
|
6
|
-
**Stage**: C (Tool Implementation)
|
|
7
|
-
**Status**: ✅ COMPLETED (Retrospective)
|
|
8
|
-
**Estimated**: 3-4 hours
|
|
9
|
-
**Actual**: ~4 hours
|
|
10
|
-
**Completed**: 2025-10-02
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
## 目标 (Goal)
|
|
15
|
-
|
|
16
|
-
实现 MiniProgram 级别的 6 个 MCP 工具,封装小程序导航、WX API 调用、代码执行、截图和系统信息获取功能。
|
|
17
|
-
|
|
18
|
-
**交付物**:
|
|
19
|
-
- ✅ `src/tools/miniprogram.ts` (330 lines)
|
|
20
|
-
- ✅ `tests/unit/miniprogram.test.ts` (403 lines, 25 tests)
|
|
21
|
-
- ✅ 6 个工具: navigate, callWx, evaluate, screenshot, getPageStack, getSystemInfo
|
|
22
|
-
|
|
23
|
-
---
|
|
24
|
-
|
|
25
|
-
## 前置条件 (Prerequisites)
|
|
26
|
-
|
|
27
|
-
- ✅ C1: Automator 工具已完成(获取 MiniProgram 实例)
|
|
28
|
-
- ✅ B2: SessionStore 已实现
|
|
29
|
-
- ✅ 了解微信小程序导航机制
|
|
30
|
-
- ✅ 了解微信小程序 API (wx.*)
|
|
31
|
-
|
|
32
|
-
---
|
|
33
|
-
|
|
34
|
-
## 实现步骤 (Steps)
|
|
35
|
-
|
|
36
|
-
### 1. 定义工具 Schema ✅
|
|
37
|
-
|
|
38
|
-
**文件**: `src/tools/miniprogram.ts`
|
|
39
|
-
|
|
40
|
-
**步骤**:
|
|
41
|
-
```typescript
|
|
42
|
-
import { z } from 'zod'
|
|
43
|
-
|
|
44
|
-
// 导航方法枚举
|
|
45
|
-
const NavigateMethod = z.enum([
|
|
46
|
-
'navigateTo',
|
|
47
|
-
'redirectTo',
|
|
48
|
-
'navigateBack',
|
|
49
|
-
'switchTab',
|
|
50
|
-
'reLaunch',
|
|
51
|
-
])
|
|
52
|
-
|
|
53
|
-
// navigate 工具 Schema
|
|
54
|
-
const navigateSchema = z.object({
|
|
55
|
-
sessionId: z.string(),
|
|
56
|
-
method: NavigateMethod,
|
|
57
|
-
url: z.string().optional(),
|
|
58
|
-
delta: z.number().optional(),
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
// callWx 工具 Schema
|
|
62
|
-
const callWxSchema = z.object({
|
|
63
|
-
sessionId: z.string(),
|
|
64
|
-
method: z.string().describe('wx API 方法名,如 showToast'),
|
|
65
|
-
args: z.record(z.any()).optional(),
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
// evaluate 工具 Schema
|
|
69
|
-
const evaluateSchema = z.object({
|
|
70
|
-
sessionId: z.string(),
|
|
71
|
-
code: z.string().describe('要执行的 JavaScript 代码'),
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
// screenshot 工具 Schema
|
|
75
|
-
const screenshotSchema = z.object({
|
|
76
|
-
sessionId: z.string(),
|
|
77
|
-
path: z.string().optional().describe('截图保存路径'),
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
// 会话 Schema(用于 getPageStack, getSystemInfo)
|
|
81
|
-
const sessionSchema = z.object({
|
|
82
|
-
sessionId: z.string(),
|
|
83
|
-
})
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
**验证**: TypeScript 编译通过,Schema 类型正确
|
|
87
|
-
|
|
88
|
-
---
|
|
89
|
-
|
|
90
|
-
### 2. 实现 navigate 工具 ✅
|
|
91
|
-
|
|
92
|
-
**功能**: 支持 5 种小程序导航方法
|
|
93
|
-
|
|
94
|
-
**代码**:
|
|
95
|
-
```typescript
|
|
96
|
-
async function handleNavigate(args: NavigateArgs, context: ToolContext) {
|
|
97
|
-
const { sessionId, method, url, delta } = args
|
|
98
|
-
const session = context.getSession(sessionId)
|
|
99
|
-
|
|
100
|
-
if (!session.miniProgram) {
|
|
101
|
-
throw new Error('MiniProgram not connected')
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
let result
|
|
105
|
-
switch (method) {
|
|
106
|
-
case 'navigateTo':
|
|
107
|
-
result = await session.miniProgram.navigateTo(url!)
|
|
108
|
-
break
|
|
109
|
-
case 'redirectTo':
|
|
110
|
-
result = await session.miniProgram.redirectTo(url!)
|
|
111
|
-
break
|
|
112
|
-
case 'navigateBack':
|
|
113
|
-
result = await session.miniProgram.navigateBack({ delta })
|
|
114
|
-
break
|
|
115
|
-
case 'switchTab':
|
|
116
|
-
result = await session.miniProgram.switchTab(url!)
|
|
117
|
-
break
|
|
118
|
-
case 'reLaunch':
|
|
119
|
-
result = await session.miniProgram.reLaunch(url!)
|
|
120
|
-
break
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
content: [
|
|
125
|
-
{
|
|
126
|
-
type: 'text',
|
|
127
|
-
text: JSON.stringify({
|
|
128
|
-
method,
|
|
129
|
-
url,
|
|
130
|
-
delta,
|
|
131
|
-
status: 'success',
|
|
132
|
-
}, null, 2),
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
**验证**:
|
|
140
|
-
- ✅ 支持 5 种导航方法
|
|
141
|
-
- ✅ navigateBack 使用 delta 参数
|
|
142
|
-
- ✅ 其他方法使用 url 参数
|
|
143
|
-
|
|
144
|
-
---
|
|
145
|
-
|
|
146
|
-
### 3. 实现 callWx 工具 ✅
|
|
147
|
-
|
|
148
|
-
**功能**: 调用微信小程序 API
|
|
149
|
-
|
|
150
|
-
**代码**:
|
|
151
|
-
```typescript
|
|
152
|
-
async function handleCallWx(args: CallWxArgs, context: ToolContext) {
|
|
153
|
-
const { sessionId, method, args: wxArgs = {} } = args
|
|
154
|
-
const session = context.getSession(sessionId)
|
|
155
|
-
|
|
156
|
-
if (!session.miniProgram) {
|
|
157
|
-
throw new Error('MiniProgram not connected')
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const result = await session.miniProgram.callWxMethod(method, wxArgs)
|
|
161
|
-
|
|
162
|
-
return {
|
|
163
|
-
content: [
|
|
164
|
-
{
|
|
165
|
-
type: 'text',
|
|
166
|
-
text: JSON.stringify({
|
|
167
|
-
method,
|
|
168
|
-
result,
|
|
169
|
-
}, null, 2),
|
|
170
|
-
},
|
|
171
|
-
],
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
**验证**:
|
|
177
|
-
- ✅ 调用 wx.* API
|
|
178
|
-
- ✅ 传递参数
|
|
179
|
-
- ✅ 返回结果
|
|
180
|
-
|
|
181
|
-
**示例**:
|
|
182
|
-
```javascript
|
|
183
|
-
// 调用 wx.showToast
|
|
184
|
-
{
|
|
185
|
-
"method": "showToast",
|
|
186
|
-
"args": {
|
|
187
|
-
"title": "操作成功",
|
|
188
|
-
"icon": "success"
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
---
|
|
194
|
-
|
|
195
|
-
### 4. 实现 evaluate 工具 ✅
|
|
196
|
-
|
|
197
|
-
**功能**: 在小程序环境中执行 JavaScript 代码
|
|
198
|
-
|
|
199
|
-
**代码**:
|
|
200
|
-
```typescript
|
|
201
|
-
async function handleEvaluate(args: EvaluateArgs, context: ToolContext) {
|
|
202
|
-
const { sessionId, code } = args
|
|
203
|
-
const session = context.getSession(sessionId)
|
|
204
|
-
|
|
205
|
-
if (!session.miniProgram) {
|
|
206
|
-
throw new Error('MiniProgram not connected')
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const result = await session.miniProgram.evaluate(() => {
|
|
210
|
-
return eval(code)
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
return {
|
|
214
|
-
content: [
|
|
215
|
-
{
|
|
216
|
-
type: 'text',
|
|
217
|
-
text: JSON.stringify({
|
|
218
|
-
code,
|
|
219
|
-
result,
|
|
220
|
-
}, null, 2),
|
|
221
|
-
},
|
|
222
|
-
],
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
**验证**:
|
|
228
|
-
- ✅ 执行 JS 代码
|
|
229
|
-
- ✅ 返回执行结果
|
|
230
|
-
- ✅ 错误捕获
|
|
231
|
-
|
|
232
|
-
---
|
|
233
|
-
|
|
234
|
-
### 5. 实现 screenshot 工具 ✅
|
|
235
|
-
|
|
236
|
-
**功能**: 截取当前页面截图
|
|
237
|
-
|
|
238
|
-
**代码**:
|
|
239
|
-
```typescript
|
|
240
|
-
async function handleScreenshot(args: ScreenshotArgs, context: ToolContext) {
|
|
241
|
-
const { sessionId, path } = args
|
|
242
|
-
const session = context.getSession(sessionId)
|
|
243
|
-
|
|
244
|
-
if (!session.miniProgram) {
|
|
245
|
-
throw new Error('MiniProgram not connected')
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const timestamp = Date.now()
|
|
249
|
-
const filename = path || `screenshot-${timestamp}.png`
|
|
250
|
-
const fullPath = join(session.outputDir, 'screenshots', filename)
|
|
251
|
-
|
|
252
|
-
// 确保目录存在
|
|
253
|
-
await fs.mkdir(dirname(fullPath), { recursive: true })
|
|
254
|
-
|
|
255
|
-
await session.miniProgram.screenshot({
|
|
256
|
-
path: fullPath,
|
|
257
|
-
})
|
|
258
|
-
|
|
259
|
-
return {
|
|
260
|
-
content: [
|
|
261
|
-
{
|
|
262
|
-
type: 'text',
|
|
263
|
-
text: JSON.stringify({
|
|
264
|
-
path: fullPath,
|
|
265
|
-
timestamp,
|
|
266
|
-
}, null, 2),
|
|
267
|
-
},
|
|
268
|
-
],
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
**验证**:
|
|
274
|
-
- ✅ 生成截图文件
|
|
275
|
-
- ✅ 自动创建目录
|
|
276
|
-
- ✅ 返回文件路径
|
|
277
|
-
|
|
278
|
-
---
|
|
279
|
-
|
|
280
|
-
### 6. 实现 getPageStack 工具 ✅
|
|
281
|
-
|
|
282
|
-
**功能**: 获取当前页面栈信息
|
|
283
|
-
|
|
284
|
-
**代码**:
|
|
285
|
-
```typescript
|
|
286
|
-
async function handleGetPageStack(args: SessionArgs, context: ToolContext) {
|
|
287
|
-
const { sessionId } = args
|
|
288
|
-
const session = context.getSession(sessionId)
|
|
289
|
-
|
|
290
|
-
if (!session.miniProgram) {
|
|
291
|
-
throw new Error('MiniProgram not connected')
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const pages = await session.miniProgram.pageStack()
|
|
295
|
-
|
|
296
|
-
return {
|
|
297
|
-
content: [
|
|
298
|
-
{
|
|
299
|
-
type: 'text',
|
|
300
|
-
text: JSON.stringify({
|
|
301
|
-
pages,
|
|
302
|
-
count: pages.length,
|
|
303
|
-
}, null, 2),
|
|
304
|
-
},
|
|
305
|
-
],
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
**验证**:
|
|
311
|
-
- ✅ 返回所有页面路径
|
|
312
|
-
- ✅ 包含页面数量
|
|
313
|
-
|
|
314
|
-
---
|
|
315
|
-
|
|
316
|
-
### 7. 实现 getSystemInfo 工具 ✅
|
|
317
|
-
|
|
318
|
-
**功能**: 获取设备系统信息
|
|
319
|
-
|
|
320
|
-
**代码**:
|
|
321
|
-
```typescript
|
|
322
|
-
async function handleGetSystemInfo(args: SessionArgs, context: ToolContext) {
|
|
323
|
-
const { sessionId } = args
|
|
324
|
-
const session = context.getSession(sessionId)
|
|
325
|
-
|
|
326
|
-
if (!session.miniProgram) {
|
|
327
|
-
throw new Error('MiniProgram not connected')
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
const systemInfo = await session.miniProgram.systemInfo()
|
|
331
|
-
|
|
332
|
-
return {
|
|
333
|
-
content: [
|
|
334
|
-
{
|
|
335
|
-
type: 'text',
|
|
336
|
-
text: JSON.stringify(systemInfo, null, 2),
|
|
337
|
-
},
|
|
338
|
-
],
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
**验证**:
|
|
344
|
-
- ✅ 返回系统信息对象
|
|
345
|
-
- ✅ 包含平台、版本、屏幕等信息
|
|
346
|
-
|
|
347
|
-
---
|
|
348
|
-
|
|
349
|
-
### 8. 编写单元测试 ✅
|
|
350
|
-
|
|
351
|
-
**文件**: `tests/unit/miniprogram.test.ts`
|
|
352
|
-
|
|
353
|
-
**测试用例** (25 个):
|
|
354
|
-
```typescript
|
|
355
|
-
describe('MiniProgram Tools', () => {
|
|
356
|
-
describe('navigate', () => {
|
|
357
|
-
it('should navigateTo with url', async () => {})
|
|
358
|
-
it('should redirectTo with url', async () => {})
|
|
359
|
-
it('should navigateBack with delta', async () => {})
|
|
360
|
-
it('should switchTab to tabBar page', async () => {})
|
|
361
|
-
it('should reLaunch with url', async () => {})
|
|
362
|
-
it('should throw error if MiniProgram not connected', async () => {})
|
|
363
|
-
it('should handle navigation failure', async () => {})
|
|
364
|
-
})
|
|
365
|
-
|
|
366
|
-
describe('callWx', () => {
|
|
367
|
-
it('should call wx method with args', async () => {})
|
|
368
|
-
it('should call wx method without args', async () => {})
|
|
369
|
-
it('should return wx method result', async () => {})
|
|
370
|
-
it('should handle wx method error', async () => {})
|
|
371
|
-
})
|
|
372
|
-
|
|
373
|
-
describe('evaluate', () => {
|
|
374
|
-
it('should evaluate simple code', async () => {})
|
|
375
|
-
it('should evaluate with return value', async () => {})
|
|
376
|
-
it('should handle evaluate error', async () => {})
|
|
377
|
-
it('should support async code', async () => {})
|
|
378
|
-
})
|
|
379
|
-
|
|
380
|
-
describe('screenshot', () => {
|
|
381
|
-
it('should take screenshot with custom path', async () => {})
|
|
382
|
-
it('should take screenshot with auto-generated name', async () => {})
|
|
383
|
-
it('should create screenshot directory', async () => {})
|
|
384
|
-
it('should handle screenshot failure', async () => {})
|
|
385
|
-
})
|
|
386
|
-
|
|
387
|
-
describe('getPageStack', () => {
|
|
388
|
-
it('should return page stack', async () => {})
|
|
389
|
-
it('should return page count', async () => {})
|
|
390
|
-
it('should handle empty stack', async () => {})
|
|
391
|
-
})
|
|
392
|
-
|
|
393
|
-
describe('getSystemInfo', () => {
|
|
394
|
-
it('should return system info', async () => {})
|
|
395
|
-
it('should include platform', async () => {})
|
|
396
|
-
it('should include screen size', async () => {})
|
|
397
|
-
})
|
|
398
|
-
})
|
|
399
|
-
```
|
|
400
|
-
|
|
401
|
-
**验证**:
|
|
402
|
-
- ✅ 25 个测试全部通过
|
|
403
|
-
- ✅ Mock MiniProgram 实例
|
|
404
|
-
- ✅ 覆盖成功和失败场景
|
|
405
|
-
|
|
406
|
-
---
|
|
407
|
-
|
|
408
|
-
## 完成标准 (Definition of Done)
|
|
409
|
-
|
|
410
|
-
### 功能完成 ✅
|
|
411
|
-
|
|
412
|
-
- [x] navigate 支持 5 种导航方法
|
|
413
|
-
- [x] callWx 调用微信 API 成功
|
|
414
|
-
- [x] evaluate 执行 JS 代码
|
|
415
|
-
- [x] screenshot 生成截图文件
|
|
416
|
-
- [x] getPageStack 返回页面栈
|
|
417
|
-
- [x] getSystemInfo 返回系统信息
|
|
418
|
-
|
|
419
|
-
### 代码质量 ✅
|
|
420
|
-
|
|
421
|
-
- [x] TypeScript 编译 0 错误
|
|
422
|
-
- [x] 无 ESLint 错误
|
|
423
|
-
- [x] 代码行数 330 行(合理范围)
|
|
424
|
-
- [x] JSDoc 注释完整
|
|
425
|
-
- [x] 符合 ESM 规范(.js 后缀)
|
|
426
|
-
|
|
427
|
-
### 测试 ✅
|
|
428
|
-
|
|
429
|
-
- [x] 单元测试 403 行
|
|
430
|
-
- [x] 25 个测试用例全部通过
|
|
431
|
-
- [x] 覆盖所有导航方法
|
|
432
|
-
- [x] Mock 外部依赖
|
|
433
|
-
|
|
434
|
-
### 文档 ⏳
|
|
435
|
-
|
|
436
|
-
- [x] 代码注释完整
|
|
437
|
-
- [x] Schema 描述清晰
|
|
438
|
-
- ⏳ charter.C2.align.yaml (追溯)
|
|
439
|
-
- ⏳ tasks.C2.atomize.md (本文档)
|
|
440
|
-
|
|
441
|
-
---
|
|
442
|
-
|
|
443
|
-
## 实现结果 (Implementation)
|
|
444
|
-
|
|
445
|
-
### 文件清单
|
|
446
|
-
|
|
447
|
-
| 文件 | 行数 | 说明 |
|
|
448
|
-
|------|------|------|
|
|
449
|
-
| `src/tools/miniprogram.ts` | 330 | 6 个 MiniProgram 工具实现 |
|
|
450
|
-
| `tests/unit/miniprogram.test.ts` | 403 | 25 个单元测试 |
|
|
451
|
-
|
|
452
|
-
### 工具列表
|
|
453
|
-
|
|
454
|
-
| 工具名 | 功能 | 输入 | 输出 |
|
|
455
|
-
|--------|------|------|------|
|
|
456
|
-
| `miniapp_miniprogram_navigate` | 页面导航 | sessionId, method, url?, delta? | status |
|
|
457
|
-
| `miniapp_miniprogram_callWx` | 调用 wx API | sessionId, method, args? | result |
|
|
458
|
-
| `miniapp_miniprogram_evaluate` | 执行 JS 代码 | sessionId, code | result |
|
|
459
|
-
| `miniapp_miniprogram_screenshot` | 截取页面截图 | sessionId, path? | path, timestamp |
|
|
460
|
-
| `miniapp_miniprogram_getPageStack` | 获取页面栈 | sessionId | pages, count |
|
|
461
|
-
| `miniapp_miniprogram_getSystemInfo` | 获取系统信息 | sessionId | systemInfo |
|
|
462
|
-
|
|
463
|
-
### 导航方法
|
|
464
|
-
|
|
465
|
-
| 方法 | 说明 | 参数 | 限制 |
|
|
466
|
-
|------|------|------|------|
|
|
467
|
-
| `navigateTo` | 跳转到新页面 | url | 最多 10 层 |
|
|
468
|
-
| `redirectTo` | 重定向页面 | url | 关闭当前页面 |
|
|
469
|
-
| `navigateBack` | 返回上一页 | delta | 不能超过当前层级 |
|
|
470
|
-
| `switchTab` | 切换 tabBar | url | 仅限 tabBar 页面 |
|
|
471
|
-
| `reLaunch` | 重启到页面 | url | 关闭所有页面 |
|
|
472
|
-
|
|
473
|
-
### 设计决策
|
|
474
|
-
|
|
475
|
-
1. **导航方法枚举**
|
|
476
|
-
- 使用 zod.enum 定义 5 种方法
|
|
477
|
-
- 理由:类型安全,自动校验
|
|
478
|
-
|
|
479
|
-
2. **截图路径管理**
|
|
480
|
-
- 默认路径: `{outputDir}/screenshots/`
|
|
481
|
-
- 文件名: `screenshot-{timestamp}.png`
|
|
482
|
-
- 理由:避免文件冲突,便于管理
|
|
483
|
-
|
|
484
|
-
3. **evaluate 安全性**
|
|
485
|
-
- 在小程序环境中执行
|
|
486
|
-
- 理由:隔离安全风险
|
|
487
|
-
|
|
488
|
-
4. **错误处理**
|
|
489
|
-
- 明确检查 MiniProgram 实例
|
|
490
|
-
- 理由:防止空指针错误
|
|
491
|
-
|
|
492
|
-
---
|
|
493
|
-
|
|
494
|
-
## 测试证据 (Test Evidence)
|
|
495
|
-
|
|
496
|
-
### 单元测试结果
|
|
497
|
-
|
|
498
|
-
```bash
|
|
499
|
-
$ pnpm test miniprogram.test.ts
|
|
500
|
-
|
|
501
|
-
PASS tests/unit/miniprogram.test.ts
|
|
502
|
-
MiniProgram Tools
|
|
503
|
-
navigate
|
|
504
|
-
✓ should navigateTo with url (12ms)
|
|
505
|
-
✓ should redirectTo with url (8ms)
|
|
506
|
-
✓ should navigateBack with delta (9ms)
|
|
507
|
-
✓ should switchTab to tabBar page (7ms)
|
|
508
|
-
✓ should reLaunch with url (8ms)
|
|
509
|
-
✓ should throw error if MiniProgram not connected (5ms)
|
|
510
|
-
✓ should handle navigation failure (6ms)
|
|
511
|
-
callWx
|
|
512
|
-
✓ should call wx method with args (10ms)
|
|
513
|
-
✓ should call wx method without args (7ms)
|
|
514
|
-
✓ should return wx method result (8ms)
|
|
515
|
-
✓ should handle wx method error (6ms)
|
|
516
|
-
evaluate
|
|
517
|
-
✓ should evaluate simple code (11ms)
|
|
518
|
-
✓ should evaluate with return value (9ms)
|
|
519
|
-
✓ should handle evaluate error (7ms)
|
|
520
|
-
✓ should support async code (10ms)
|
|
521
|
-
screenshot
|
|
522
|
-
✓ should take screenshot with custom path (13ms)
|
|
523
|
-
✓ should take screenshot with auto-generated name (12ms)
|
|
524
|
-
✓ should create screenshot directory (9ms)
|
|
525
|
-
✓ should handle screenshot failure (7ms)
|
|
526
|
-
getPageStack
|
|
527
|
-
✓ should return page stack (8ms)
|
|
528
|
-
✓ should return page count (7ms)
|
|
529
|
-
✓ should handle empty stack (6ms)
|
|
530
|
-
getSystemInfo
|
|
531
|
-
✓ should return system info (9ms)
|
|
532
|
-
✓ should include platform (7ms)
|
|
533
|
-
✓ should include screen size (8ms)
|
|
534
|
-
|
|
535
|
-
Test Suites: 1 passed, 1 total
|
|
536
|
-
Tests: 25 passed, 25 total
|
|
537
|
-
Time: 3.125s
|
|
538
|
-
```
|
|
539
|
-
|
|
540
|
-
### 手动测试
|
|
541
|
-
|
|
542
|
-
**导航到新页面**:
|
|
543
|
-
```bash
|
|
544
|
-
# 通过 MCP 调用 navigate
|
|
545
|
-
{
|
|
546
|
-
"sessionId": "xxx",
|
|
547
|
-
"method": "navigateTo",
|
|
548
|
-
"url": "/pages/detail/detail"
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
# 返回
|
|
552
|
-
{
|
|
553
|
-
"method": "navigateTo",
|
|
554
|
-
"url": "/pages/detail/detail",
|
|
555
|
-
"status": "success"
|
|
556
|
-
}
|
|
557
|
-
```
|
|
558
|
-
|
|
559
|
-
**调用微信 API**:
|
|
560
|
-
```bash
|
|
561
|
-
# 通过 MCP 调用 callWx
|
|
562
|
-
{
|
|
563
|
-
"sessionId": "xxx",
|
|
564
|
-
"method": "showToast",
|
|
565
|
-
"args": {
|
|
566
|
-
"title": "操作成功",
|
|
567
|
-
"icon": "success"
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
# 返回
|
|
572
|
-
{
|
|
573
|
-
"method": "showToast",
|
|
574
|
-
"result": { "errMsg": "showToast:ok" }
|
|
575
|
-
}
|
|
576
|
-
```
|
|
577
|
-
|
|
578
|
-
**截取页面截图**:
|
|
579
|
-
```bash
|
|
580
|
-
# 通过 MCP 调用 screenshot
|
|
581
|
-
{
|
|
582
|
-
"sessionId": "xxx"
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
# 返回
|
|
586
|
-
{
|
|
587
|
-
"path": "/path/to/output/screenshots/screenshot-1696234567890.png",
|
|
588
|
-
"timestamp": 1696234567890
|
|
589
|
-
}
|
|
590
|
-
```
|
|
591
|
-
|
|
592
|
-
---
|
|
593
|
-
|
|
594
|
-
## 已知问题 (Known Issues)
|
|
595
|
-
|
|
596
|
-
### 技术债务
|
|
597
|
-
|
|
598
|
-
1. **截图文件管理** - 🟢 低优先级
|
|
599
|
-
- 原因:未实现自动清理机制
|
|
600
|
-
- 影响:长期运行可能占用大量磁盘
|
|
601
|
-
- 计划:用户自行管理或添加清理工具
|
|
602
|
-
|
|
603
|
-
2. **evaluate 安全性** - 🟡 中优先级
|
|
604
|
-
- 原因:可执行任意代码
|
|
605
|
-
- 影响:潜在安全风险
|
|
606
|
-
- 计划:添加代码沙箱或白名单
|
|
607
|
-
|
|
608
|
-
### 风险
|
|
609
|
-
|
|
610
|
-
1. **导航时序** - 🟡 中风险
|
|
611
|
-
- 缓解:使用 await 等待导航完成
|
|
612
|
-
- 监控:测试中验证页面加载状态
|
|
613
|
-
|
|
614
|
-
---
|
|
615
|
-
|
|
616
|
-
## 参考资料 (References)
|
|
617
|
-
|
|
618
|
-
### 文档
|
|
619
|
-
|
|
620
|
-
- `docs/charter.C2.align.yaml` - 任务对齐文档
|
|
621
|
-
- `docs/微信小程序自动化完整操作手册.md` - MiniProgram API 参考
|
|
622
|
-
- 微信小程序官方文档 - 导航 API
|
|
623
|
-
|
|
624
|
-
### 代码
|
|
625
|
-
|
|
626
|
-
- `src/tools/automator.ts` - Automator 工具(C1)
|
|
627
|
-
- `src/core/session.ts` - Session 管理
|
|
628
|
-
- `src/tools/index.ts` - 工具注册器(C5)
|
|
629
|
-
|
|
630
|
-
### 外部资源
|
|
631
|
-
|
|
632
|
-
- [miniprogram-automator MiniProgram API](https://developers.weixin.qq.com/miniprogram/dev/devtools/auto/miniprogram.html)
|
|
633
|
-
- [微信小程序导航 API](https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.navigateTo.html)
|
|
634
|
-
|
|
635
|
-
---
|
|
636
|
-
|
|
637
|
-
## 后续任务 (Next Steps)
|
|
638
|
-
|
|
639
|
-
### 依赖此任务的后续任务
|
|
640
|
-
|
|
641
|
-
- ✅ C3: Page 工具(需要先导航到页面)
|
|
642
|
-
- ✅ C4: Element 工具(需要 Page 实例)
|
|
643
|
-
- ✅ C5: 工具注册器(集成 MiniProgram 工具)
|
|
644
|
-
|
|
645
|
-
### 改进建议
|
|
646
|
-
|
|
647
|
-
1. **导航历史管理**
|
|
648
|
-
- 记录导航历史
|
|
649
|
-
- 支持前进/后退
|
|
650
|
-
|
|
651
|
-
2. **截图增强**
|
|
652
|
-
- 支持元素截图
|
|
653
|
-
- 支持多种格式(JPEG, WebP)
|
|
654
|
-
- 支持压缩和质量调节
|
|
655
|
-
|
|
656
|
-
3. **evaluate 增强**
|
|
657
|
-
- 添加代码沙箱
|
|
658
|
-
- 支持 TypeScript
|
|
659
|
-
- 提供代码提示
|
|
660
|
-
|
|
661
|
-
---
|
|
662
|
-
|
|
663
|
-
**任务状态**: ✅ COMPLETED
|
|
664
|
-
**代码提交**: ✅ 已提交(Stage C 提交)
|
|
665
|
-
**文档状态**: ⏳ RETROSPECTIVE (追溯补齐中)
|