mcp-probe-kit 3.1.0 → 3.3.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 +15 -5
- package/build/index.js +5 -2
- package/build/lib/__tests__/memory-orchestration.unit.test.js +88 -0
- package/build/lib/__tests__/memory-payload.unit.test.js +35 -0
- package/build/lib/__tests__/quality-constraints.unit.test.d.ts +1 -0
- package/build/lib/__tests__/quality-constraints.unit.test.js +54 -0
- package/build/lib/__tests__/spec-validator.unit.test.d.ts +1 -0
- package/build/lib/__tests__/spec-validator.unit.test.js +147 -0
- package/build/lib/agents-md-template.js +32 -32
- package/build/lib/cursor-history-client.d.ts +54 -0
- package/build/lib/cursor-history-client.js +240 -0
- package/build/lib/memory-orchestration.js +29 -8
- package/build/lib/quality-constraints.d.ts +54 -0
- package/build/lib/quality-constraints.js +155 -0
- package/build/lib/skill-bridge.js +12 -12
- package/build/lib/spec-validator.d.ts +36 -0
- package/build/lib/spec-validator.js +116 -0
- package/build/lib/template-loader.js +223 -61
- package/build/lib/tool-annotations.d.ts +30 -0
- package/build/lib/tool-annotations.js +55 -0
- package/build/lib/toolset-manager.js +2 -0
- package/build/resources/ui-ux-data/guidelines/vercel-web-interface.json +1632 -1632
- package/build/resources/ui-ux-data/metadata.json +30 -30
- package/build/resources/ui-ux-data/shadcn/blocks.json +2541 -2541
- package/build/resources/ui-ux-data/shadcn/components.json +997 -997
- package/build/resources/ui-ux-data/themes/presets.json +483 -483
- package/build/schemas/index.d.ts +22 -0
- package/build/schemas/project-tools.d.ts +22 -0
- package/build/schemas/project-tools.js +23 -0
- package/build/tools/__tests__/cursor-history.unit.test.d.ts +1 -0
- package/build/tools/__tests__/cursor-history.unit.test.js +38 -0
- package/build/tools/check_spec.d.ts +7 -0
- package/build/tools/check_spec.js +81 -0
- package/build/tools/code_insight.js +41 -41
- package/build/tools/code_review.js +11 -4
- package/build/tools/cursor_read_conversation.d.ts +7 -0
- package/build/tools/cursor_read_conversation.js +36 -0
- package/build/tools/fix_bug.js +161 -161
- package/build/tools/gencommit.js +60 -60
- package/build/tools/index.d.ts +1 -0
- package/build/tools/index.js +1 -0
- package/build/tools/init_project_context.js +432 -432
- package/build/tools/start_bugfix.js +21 -10
- package/build/tools/start_feature.js +46 -11
- package/build/tools/start_product.js +1 -1
- package/build/tools/start_ui.js +44 -13
- package/build/tools/ui-ux-tools.d.ts +3 -0
- package/build/tools/ui-ux-tools.js +302 -290
- package/build/utils/__tests__/vercel-guidelines-sync.unit.test.js +12 -12
- package/build/utils/design-reasoning-engine.d.ts +2 -0
- package/build/utils/design-reasoning-engine.js +3 -0
- package/build/utils/themes-sync.js +8 -8
- package/package.json +4 -3
- package/build/resources/index.d.ts +0 -4
- package/build/resources/index.js +0 -4
- package/build/resources/tool-params-guide.d.ts +0 -571
- package/build/resources/tool-params-guide.js +0 -488
- package/build/tools/analyze_project.d.ts +0 -1
- package/build/tools/analyze_project.js +0 -527
- package/build/tools/check_deps.d.ts +0 -13
- package/build/tools/check_deps.js +0 -204
- package/build/tools/convert.d.ts +0 -13
- package/build/tools/convert.js +0 -599
- package/build/tools/css_order.d.ts +0 -13
- package/build/tools/css_order.js +0 -81
- package/build/tools/debug.d.ts +0 -13
- package/build/tools/debug.js +0 -131
- package/build/tools/design2code.d.ts +0 -20
- package/build/tools/design2code.js +0 -426
- package/build/tools/detect_shell.d.ts +0 -6
- package/build/tools/detect_shell.js +0 -151
- package/build/tools/explain.d.ts +0 -13
- package/build/tools/explain.js +0 -390
- package/build/tools/fix.d.ts +0 -13
- package/build/tools/fix.js +0 -303
- package/build/tools/gen_mock.d.ts +0 -22
- package/build/tools/gen_mock.js +0 -269
- package/build/tools/gen_skill.d.ts +0 -13
- package/build/tools/gen_skill.js +0 -560
- package/build/tools/genapi.d.ts +0 -13
- package/build/tools/genapi.js +0 -174
- package/build/tools/genchangelog.d.ts +0 -13
- package/build/tools/genchangelog.js +0 -250
- package/build/tools/gendoc.d.ts +0 -13
- package/build/tools/gendoc.js +0 -232
- package/build/tools/genpr.d.ts +0 -13
- package/build/tools/genpr.js +0 -194
- package/build/tools/genreadme.d.ts +0 -13
- package/build/tools/genreadme.js +0 -626
- package/build/tools/gensql.d.ts +0 -13
- package/build/tools/gensql.js +0 -320
- package/build/tools/genui.d.ts +0 -13
- package/build/tools/genui.js +0 -803
- package/build/tools/init_component_catalog.d.ts +0 -22
- package/build/tools/init_component_catalog.js +0 -809
- package/build/tools/init_setting.d.ts +0 -13
- package/build/tools/init_setting.js +0 -47
- package/build/tools/perf.d.ts +0 -13
- package/build/tools/perf.js +0 -409
- package/build/tools/render_ui.d.ts +0 -22
- package/build/tools/render_ui.js +0 -384
- package/build/tools/resolve_conflict.d.ts +0 -13
- package/build/tools/resolve_conflict.js +0 -349
- package/build/tools/security_scan.d.ts +0 -22
- package/build/tools/security_scan.js +0 -323
- package/build/tools/split.d.ts +0 -13
- package/build/tools/split.js +0 -599
- package/build/tools/start_api.d.ts +0 -13
- package/build/tools/start_api.js +0 -193
- package/build/tools/start_doc.d.ts +0 -13
- package/build/tools/start_doc.js +0 -207
- package/build/tools/start_refactor.d.ts +0 -13
- package/build/tools/start_refactor.js +0 -188
- package/build/tools/start_release.d.ts +0 -13
- package/build/tools/start_release.js +0 -167
- package/build/tools/start_review.d.ts +0 -13
- package/build/tools/start_review.js +0 -175
- /package/build/{utils/design-docs-generator.d.ts → lib/__tests__/memory-orchestration.unit.test.d.ts} +0 -0
- /package/build/{utils/design-docs-generator.js → lib/__tests__/memory-payload.unit.test.d.ts} +0 -0
package/build/tools/fix.js
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import { parseArgs, getString } from "../utils/parseArgs.js";
|
|
2
|
-
// fix 工具实现
|
|
3
|
-
export async function fix(args) {
|
|
4
|
-
try {
|
|
5
|
-
// 智能参数解析,支持自然语言输入
|
|
6
|
-
const parsedArgs = parseArgs(args, {
|
|
7
|
-
defaultValues: {
|
|
8
|
-
code: "",
|
|
9
|
-
type: "all",
|
|
10
|
-
},
|
|
11
|
-
primaryField: "code", // 纯文本输入默认映射到 code 字段
|
|
12
|
-
fieldAliases: {
|
|
13
|
-
code: ["source", "src", "代码", "content"],
|
|
14
|
-
type: ["fix_type", "category", "类型", "修复类型"],
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
const code = getString(parsedArgs.code);
|
|
18
|
-
const type = getString(parsedArgs.type) || "all"; // lint, type, format, import, unused
|
|
19
|
-
const message = `请自动修复以下代码问题:
|
|
20
|
-
|
|
21
|
-
📝 **代码内容**:
|
|
22
|
-
${code || "请提供需要修复的代码"}
|
|
23
|
-
|
|
24
|
-
🎯 **修复类型**:${type}
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
## 自动修复步骤
|
|
29
|
-
|
|
30
|
-
### 第一步:识别问题
|
|
31
|
-
|
|
32
|
-
执行以下检查:
|
|
33
|
-
\`\`\`bash
|
|
34
|
-
# Lint 检查
|
|
35
|
-
npm run lint
|
|
36
|
-
|
|
37
|
-
# TypeScript 类型检查
|
|
38
|
-
tsc --noEmit
|
|
39
|
-
|
|
40
|
-
# 格式化检查
|
|
41
|
-
npm run format:check
|
|
42
|
-
\`\`\`
|
|
43
|
-
|
|
44
|
-
### 第二步:问题分类
|
|
45
|
-
|
|
46
|
-
**1️⃣ Lint 错误**
|
|
47
|
-
- ESLint 规则违反
|
|
48
|
-
- 代码质量问题
|
|
49
|
-
- 潜在 Bug
|
|
50
|
-
|
|
51
|
-
**2️⃣ TypeScript 类型错误**
|
|
52
|
-
- 类型不匹配
|
|
53
|
-
- 缺少类型定义
|
|
54
|
-
- 隐式 any
|
|
55
|
-
|
|
56
|
-
**3️⃣ 格式化问题**
|
|
57
|
-
- 缩进不一致
|
|
58
|
-
- 引号风格
|
|
59
|
-
- 分号使用
|
|
60
|
-
- 换行规则
|
|
61
|
-
|
|
62
|
-
**4️⃣ Import 问题**
|
|
63
|
-
- 未使用的 import
|
|
64
|
-
- 重复 import
|
|
65
|
-
- Import 顺序混乱
|
|
66
|
-
- 相对路径 vs 绝对路径
|
|
67
|
-
|
|
68
|
-
**5️⃣ 未使用代码**
|
|
69
|
-
- 未使用的变量
|
|
70
|
-
- 未使用的函数
|
|
71
|
-
- 死代码(Dead Code)
|
|
72
|
-
|
|
73
|
-
---
|
|
74
|
-
|
|
75
|
-
## 修复策略
|
|
76
|
-
|
|
77
|
-
### 🔧 Lint 错误修复
|
|
78
|
-
|
|
79
|
-
**常见问题和修复:**
|
|
80
|
-
|
|
81
|
-
1. **no-unused-vars**
|
|
82
|
-
\`\`\`typescript
|
|
83
|
-
// ❌ Before
|
|
84
|
-
const unusedVar = 123;
|
|
85
|
-
function test() {
|
|
86
|
-
const result = compute();
|
|
87
|
-
return 42;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// ✅ After
|
|
91
|
-
function test() {
|
|
92
|
-
return 42;
|
|
93
|
-
}
|
|
94
|
-
\`\`\`
|
|
95
|
-
|
|
96
|
-
2. **no-console**
|
|
97
|
-
\`\`\`typescript
|
|
98
|
-
// ❌ Before
|
|
99
|
-
console.log('debug info');
|
|
100
|
-
|
|
101
|
-
// ✅ After (开发环境)
|
|
102
|
-
if (process.env.NODE_ENV === 'development') {
|
|
103
|
-
console.log('debug info');
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// ✅ After (使用 logger)
|
|
107
|
-
logger.debug('debug info');
|
|
108
|
-
\`\`\`
|
|
109
|
-
|
|
110
|
-
3. **prefer-const**
|
|
111
|
-
\`\`\`typescript
|
|
112
|
-
// ❌ Before
|
|
113
|
-
let value = 10;
|
|
114
|
-
const result = value * 2;
|
|
115
|
-
|
|
116
|
-
// ✅ After
|
|
117
|
-
const value = 10;
|
|
118
|
-
const result = value * 2;
|
|
119
|
-
\`\`\`
|
|
120
|
-
|
|
121
|
-
### 🔧 TypeScript 类型错误修复
|
|
122
|
-
|
|
123
|
-
**常见问题和修复:**
|
|
124
|
-
|
|
125
|
-
1. **隐式 any**
|
|
126
|
-
\`\`\`typescript
|
|
127
|
-
// ❌ Before
|
|
128
|
-
function process(data) {
|
|
129
|
-
return data.value;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// ✅ After
|
|
133
|
-
function process(data: { value: string }): string {
|
|
134
|
-
return data.value;
|
|
135
|
-
}
|
|
136
|
-
\`\`\`
|
|
137
|
-
|
|
138
|
-
2. **类型不匹配**
|
|
139
|
-
\`\`\`typescript
|
|
140
|
-
// ❌ Before
|
|
141
|
-
const num: number = "123";
|
|
142
|
-
|
|
143
|
-
// ✅ After
|
|
144
|
-
const num: number = 123;
|
|
145
|
-
// 或
|
|
146
|
-
const num: number = parseInt("123");
|
|
147
|
-
\`\`\`
|
|
148
|
-
|
|
149
|
-
3. **可能为 null/undefined**
|
|
150
|
-
\`\`\`typescript
|
|
151
|
-
// ❌ Before
|
|
152
|
-
function getName(user) {
|
|
153
|
-
return user.name.toUpperCase();
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// ✅ After
|
|
157
|
-
function getName(user: User | null): string {
|
|
158
|
-
return user?.name?.toUpperCase() ?? 'Unknown';
|
|
159
|
-
}
|
|
160
|
-
\`\`\`
|
|
161
|
-
|
|
162
|
-
### 🔧 Import 优化
|
|
163
|
-
|
|
164
|
-
**修复策略:**
|
|
165
|
-
|
|
166
|
-
\`\`\`typescript
|
|
167
|
-
// ❌ Before
|
|
168
|
-
import { useState, useEffect, useMemo } from 'react';
|
|
169
|
-
import { Button } from './components/Button';
|
|
170
|
-
import React from 'react';
|
|
171
|
-
import { formatDate } from '../utils/date';
|
|
172
|
-
import { api } from '../../services/api';
|
|
173
|
-
|
|
174
|
-
// ✅ After
|
|
175
|
-
// 外部依赖
|
|
176
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
177
|
-
|
|
178
|
-
// 内部模块(按层级从远到近)
|
|
179
|
-
import { api } from '../../services/api';
|
|
180
|
-
import { formatDate } from '../utils/date';
|
|
181
|
-
import { Button } from './components/Button';
|
|
182
|
-
\`\`\`
|
|
183
|
-
|
|
184
|
-
### 🔧 格式化修复
|
|
185
|
-
|
|
186
|
-
**自动格式化:**
|
|
187
|
-
\`\`\`bash
|
|
188
|
-
# Prettier
|
|
189
|
-
npm run format
|
|
190
|
-
|
|
191
|
-
# ESLint 自动修复
|
|
192
|
-
npm run lint:fix
|
|
193
|
-
\`\`\`
|
|
194
|
-
|
|
195
|
-
---
|
|
196
|
-
|
|
197
|
-
## 批量修复命令
|
|
198
|
-
|
|
199
|
-
**一键修复所有可自动修复的问题:**
|
|
200
|
-
\`\`\`bash
|
|
201
|
-
# 1. 格式化代码
|
|
202
|
-
npm run format
|
|
203
|
-
|
|
204
|
-
# 2. ESLint 自动修复
|
|
205
|
-
npm run lint:fix
|
|
206
|
-
|
|
207
|
-
# 3. 整理 import
|
|
208
|
-
npx organize-imports-cli 'src/**/*.ts'
|
|
209
|
-
|
|
210
|
-
# 4. 移除未使用的 import
|
|
211
|
-
npx ts-unused-exports tsconfig.json --deleteUnusedFile
|
|
212
|
-
|
|
213
|
-
# 5. TypeScript 类型检查
|
|
214
|
-
tsc --noEmit
|
|
215
|
-
\`\`\`
|
|
216
|
-
|
|
217
|
-
---
|
|
218
|
-
|
|
219
|
-
## 修复报告
|
|
220
|
-
|
|
221
|
-
### 📊 问题统计
|
|
222
|
-
- Lint 错误: X 个
|
|
223
|
-
- 类型错误: Y 个
|
|
224
|
-
- 格式问题: Z 个
|
|
225
|
-
- Import 问题: W 个
|
|
226
|
-
|
|
227
|
-
### ✅ 已自动修复
|
|
228
|
-
1. [文件:行号] 问题描述 → 已修复
|
|
229
|
-
2. [文件:行号] 问题描述 → 已修复
|
|
230
|
-
|
|
231
|
-
### ⚠️ 需要手动处理
|
|
232
|
-
1. [文件:行号] 问题描述 → 修复建议
|
|
233
|
-
2. [文件:行号] 问题描述 → 修复建议
|
|
234
|
-
|
|
235
|
-
### 📝 修复后的代码
|
|
236
|
-
\`\`\`typescript
|
|
237
|
-
// 完整的修复后代码
|
|
238
|
-
\`\`\`
|
|
239
|
-
|
|
240
|
-
---
|
|
241
|
-
|
|
242
|
-
## 预防措施
|
|
243
|
-
|
|
244
|
-
**配置自动修复:**
|
|
245
|
-
|
|
246
|
-
\`\`\`.vscode/settings.json
|
|
247
|
-
{
|
|
248
|
-
"editor.formatOnSave": true,
|
|
249
|
-
"editor.codeActionsOnSave": {
|
|
250
|
-
"source.fixAll.eslint": true,
|
|
251
|
-
"source.organizeImports": true
|
|
252
|
-
},
|
|
253
|
-
"eslint.validate": [
|
|
254
|
-
"javascript",
|
|
255
|
-
"typescript",
|
|
256
|
-
"javascriptreact",
|
|
257
|
-
"typescriptreact"
|
|
258
|
-
]
|
|
259
|
-
}
|
|
260
|
-
\`\`\`
|
|
261
|
-
|
|
262
|
-
**Git Hooks(Husky):**
|
|
263
|
-
\`\`\`json
|
|
264
|
-
{
|
|
265
|
-
"husky": {
|
|
266
|
-
"hooks": {
|
|
267
|
-
"pre-commit": "lint-staged"
|
|
268
|
-
}
|
|
269
|
-
},
|
|
270
|
-
"lint-staged": {
|
|
271
|
-
"*.{js,ts,tsx}": [
|
|
272
|
-
"eslint --fix",
|
|
273
|
-
"prettier --write"
|
|
274
|
-
]
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
\`\`\`
|
|
278
|
-
|
|
279
|
-
---
|
|
280
|
-
|
|
281
|
-
现在请开始分析代码问题并自动修复。`;
|
|
282
|
-
return {
|
|
283
|
-
content: [
|
|
284
|
-
{
|
|
285
|
-
type: "text",
|
|
286
|
-
text: message,
|
|
287
|
-
},
|
|
288
|
-
],
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
catch (error) {
|
|
292
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
293
|
-
return {
|
|
294
|
-
content: [
|
|
295
|
-
{
|
|
296
|
-
type: "text",
|
|
297
|
-
text: `❌ 自动修复失败: ${errorMessage}`,
|
|
298
|
-
},
|
|
299
|
-
],
|
|
300
|
-
isError: true,
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* gen_mock 工具
|
|
3
|
-
*
|
|
4
|
-
* 功能:根据数据结构生成 Mock 数据
|
|
5
|
-
* 模式:指令生成器模式 - 返回生成指南,由 AI 执行实际生成
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* gen_mock 工具实现
|
|
9
|
-
*/
|
|
10
|
-
export declare function genMock(args: any): Promise<{
|
|
11
|
-
content: {
|
|
12
|
-
type: string;
|
|
13
|
-
text: string;
|
|
14
|
-
}[];
|
|
15
|
-
isError?: undefined;
|
|
16
|
-
} | {
|
|
17
|
-
content: {
|
|
18
|
-
type: string;
|
|
19
|
-
text: string;
|
|
20
|
-
}[];
|
|
21
|
-
isError: boolean;
|
|
22
|
-
}>;
|
package/build/tools/gen_mock.js
DELETED
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* gen_mock 工具
|
|
3
|
-
*
|
|
4
|
-
* 功能:根据数据结构生成 Mock 数据
|
|
5
|
-
* 模式:指令生成器模式 - 返回生成指南,由 AI 执行实际生成
|
|
6
|
-
*/
|
|
7
|
-
const PROMPT_TEMPLATE = `# Mock 数据生成指南
|
|
8
|
-
|
|
9
|
-
## 🎯 生成目标
|
|
10
|
-
|
|
11
|
-
**数据结构**:
|
|
12
|
-
\`\`\`
|
|
13
|
-
{schema}
|
|
14
|
-
\`\`\`
|
|
15
|
-
|
|
16
|
-
**生成配置**:
|
|
17
|
-
- 数量: {count} 条
|
|
18
|
-
- 格式: {format}
|
|
19
|
-
- 语言: {locale}
|
|
20
|
-
{seed_section}
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
## 📋 生成步骤
|
|
25
|
-
|
|
26
|
-
### 步骤 1: 解析数据结构
|
|
27
|
-
|
|
28
|
-
分析输入的数据结构,识别:
|
|
29
|
-
1. 字段名称和类型
|
|
30
|
-
2. 必填/可选字段(?标记)
|
|
31
|
-
3. 嵌套结构
|
|
32
|
-
4. 数组类型
|
|
33
|
-
|
|
34
|
-
### 步骤 2: 字段语义识别
|
|
35
|
-
|
|
36
|
-
根据字段名自动匹配语义,生成符合语义的数据:
|
|
37
|
-
|
|
38
|
-
| 字段名模式 | 生成规则 | 中文示例 | 英文示例 |
|
|
39
|
-
|------------|----------|----------|----------|
|
|
40
|
-
| id, _id | UUID/自增ID | uuid-xxx | uuid-xxx |
|
|
41
|
-
| name, 姓名 | 人名 | 张三、李四 | John Doe |
|
|
42
|
-
| email, 邮箱 | 邮箱格式 | zhangsan@example.com | john@example.com |
|
|
43
|
-
| phone, mobile, 手机 | 手机号 | 138xxxx1234 | +1-xxx-xxx-xxxx |
|
|
44
|
-
| avatar, 头像 | 图片URL | https://api.dicebear.com/... | |
|
|
45
|
-
| address, 地址 | 地址 | 北京市朝阳区xxx | 123 Main St |
|
|
46
|
-
| city, 城市 | 城市名 | 北京、上海 | New York |
|
|
47
|
-
| country, 国家 | 国家名 | 中国 | United States |
|
|
48
|
-
| date, 日期 | 日期 | 2024-01-15 | 2024-01-15 |
|
|
49
|
-
| createdAt, created_at | 过去时间 | 2024-01-01T10:00:00Z | |
|
|
50
|
-
| updatedAt, updated_at | 最近时间 | 2024-01-15T15:30:00Z | |
|
|
51
|
-
| title, 标题 | 短句 | 这是一个标题 | A Sample Title |
|
|
52
|
-
| description, desc, 描述 | 段落 | 这是描述内容... | Lorem ipsum... |
|
|
53
|
-
| content, 内容 | 长文本 | 文章内容... | Article content... |
|
|
54
|
-
| price, 价格 | 金额 | 99.00 | 99.00 |
|
|
55
|
-
| amount, 数量 | 整数 | 10 | 10 |
|
|
56
|
-
| status, 状态 | 枚举 | active/inactive | active/inactive |
|
|
57
|
-
| type, 类型 | 枚举 | 根据上下文 | |
|
|
58
|
-
| url, 链接 | URL | https://example.com | |
|
|
59
|
-
| image, 图片 | 图片URL | https://picsum.photos/... | |
|
|
60
|
-
| age, 年龄 | 18-60 | 25 | 25 |
|
|
61
|
-
| gender, 性别 | 性别 | 男/女 | male/female |
|
|
62
|
-
| username, 用户名 | 用户名 | user_123 | user_123 |
|
|
63
|
-
| password, 密码 | 密码占位 | ******** | ******** |
|
|
64
|
-
| token | Token | tok_xxx | tok_xxx |
|
|
65
|
-
| code, 编码 | 编码 | CODE001 | CODE001 |
|
|
66
|
-
| sort, order, 排序 | 序号 | 1, 2, 3 | 1, 2, 3 |
|
|
67
|
-
| enabled, active | 布尔 | true/false | true/false |
|
|
68
|
-
| tags, 标签 | 标签数组 | ["标签1", "标签2"] | ["tag1", "tag2"] |
|
|
69
|
-
|
|
70
|
-
### 步骤 3: 类型映射
|
|
71
|
-
|
|
72
|
-
基础类型的默认生成规则:
|
|
73
|
-
|
|
74
|
-
| 类型 | 生成规则 |
|
|
75
|
-
|------|----------|
|
|
76
|
-
| string | 根据字段名语义,或随机字符串 |
|
|
77
|
-
| number | 1-100 的随机整数 |
|
|
78
|
-
| boolean | true/false 随机 |
|
|
79
|
-
| Date | 最近30天内的随机时间 |
|
|
80
|
-
| string[] | 3-5个随机字符串 |
|
|
81
|
-
| number[] | 3-5个随机数字 |
|
|
82
|
-
| enum | 从枚举值中随机选择 |
|
|
83
|
-
| union | 从联合类型中随机选择 |
|
|
84
|
-
|
|
85
|
-
### 步骤 4: 生成数据
|
|
86
|
-
|
|
87
|
-
根据识别结果生成 {count} 条数据。
|
|
88
|
-
|
|
89
|
-
**注意事项**:
|
|
90
|
-
- 确保数据多样性,避免重复
|
|
91
|
-
- 数值类型保持合理范围
|
|
92
|
-
- 日期类型保持合理顺序(createdAt < updatedAt)
|
|
93
|
-
- 关联字段保持一致性
|
|
94
|
-
|
|
95
|
-
---
|
|
96
|
-
|
|
97
|
-
## 📊 输出格式
|
|
98
|
-
|
|
99
|
-
### JSON 格式
|
|
100
|
-
\`\`\`json
|
|
101
|
-
[
|
|
102
|
-
{
|
|
103
|
-
"field1": "value1",
|
|
104
|
-
"field2": 123
|
|
105
|
-
}
|
|
106
|
-
]
|
|
107
|
-
\`\`\`
|
|
108
|
-
|
|
109
|
-
### TypeScript 格式
|
|
110
|
-
\`\`\`typescript
|
|
111
|
-
const mockData: YourType[] = [
|
|
112
|
-
{
|
|
113
|
-
field1: "value1",
|
|
114
|
-
field2: 123
|
|
115
|
-
}
|
|
116
|
-
];
|
|
117
|
-
|
|
118
|
-
export default mockData;
|
|
119
|
-
\`\`\`
|
|
120
|
-
|
|
121
|
-
### JavaScript 格式
|
|
122
|
-
\`\`\`javascript
|
|
123
|
-
const mockData = [
|
|
124
|
-
{
|
|
125
|
-
field1: "value1",
|
|
126
|
-
field2: 123
|
|
127
|
-
}
|
|
128
|
-
];
|
|
129
|
-
|
|
130
|
-
module.exports = mockData;
|
|
131
|
-
\`\`\`
|
|
132
|
-
|
|
133
|
-
### CSV 格式(仅扁平数据)
|
|
134
|
-
\`\`\`csv
|
|
135
|
-
field1,field2
|
|
136
|
-
value1,123
|
|
137
|
-
\`\`\`
|
|
138
|
-
|
|
139
|
-
---
|
|
140
|
-
|
|
141
|
-
## 🔧 高级功能
|
|
142
|
-
|
|
143
|
-
### 自定义规则
|
|
144
|
-
|
|
145
|
-
在 schema 注释中指定规则:
|
|
146
|
-
|
|
147
|
-
\`\`\`typescript
|
|
148
|
-
interface User {
|
|
149
|
-
id: string; // UUID
|
|
150
|
-
age: number; // range: 18-60
|
|
151
|
-
status: string; // enum: active, inactive, pending
|
|
152
|
-
score: number; // range: 0-100, decimal: 2
|
|
153
|
-
tags: string[]; // count: 3-5
|
|
154
|
-
level: number; // enum: 1, 2, 3
|
|
155
|
-
}
|
|
156
|
-
\`\`\`
|
|
157
|
-
|
|
158
|
-
### 关联数据
|
|
159
|
-
|
|
160
|
-
生成有关联关系的数据:
|
|
161
|
-
|
|
162
|
-
\`\`\`json
|
|
163
|
-
// 先生成 users
|
|
164
|
-
[
|
|
165
|
-
{ "id": "user-1", "name": "张三" },
|
|
166
|
-
{ "id": "user-2", "name": "李四" }
|
|
167
|
-
]
|
|
168
|
-
|
|
169
|
-
// 再生成 orders,引用 user_id
|
|
170
|
-
[
|
|
171
|
-
{ "id": "order-1", "user_id": "user-1", "amount": 100 },
|
|
172
|
-
{ "id": "order-2", "user_id": "user-2", "amount": 200 }
|
|
173
|
-
]
|
|
174
|
-
\`\`\`
|
|
175
|
-
|
|
176
|
-
### 固定值
|
|
177
|
-
|
|
178
|
-
某些字段使用固定值:
|
|
179
|
-
|
|
180
|
-
\`\`\`typescript
|
|
181
|
-
interface Config {
|
|
182
|
-
version: string; // fixed: "1.0.0"
|
|
183
|
-
env: string; // fixed: "development"
|
|
184
|
-
}
|
|
185
|
-
\`\`\`
|
|
186
|
-
|
|
187
|
-
---
|
|
188
|
-
|
|
189
|
-
## ✅ 生成检查清单
|
|
190
|
-
|
|
191
|
-
- [ ] 数据结构已正确解析
|
|
192
|
-
- [ ] 字段语义已识别
|
|
193
|
-
- [ ] 数据类型正确
|
|
194
|
-
- [ ] 数量符合要求: {count} 条
|
|
195
|
-
- [ ] 格式正确: {format}
|
|
196
|
-
- [ ] 语言符合设置: {locale}
|
|
197
|
-
- [ ] 数据具有多样性
|
|
198
|
-
- [ ] 关联数据一致(如有)
|
|
199
|
-
|
|
200
|
-
---
|
|
201
|
-
|
|
202
|
-
*指南版本: 1.0.0*
|
|
203
|
-
*工具: MCP Probe Kit - gen_mock*
|
|
204
|
-
`;
|
|
205
|
-
import { parseArgs, getString, getNumber } from "../utils/parseArgs.js";
|
|
206
|
-
/**
|
|
207
|
-
* gen_mock 工具实现
|
|
208
|
-
*/
|
|
209
|
-
export async function genMock(args) {
|
|
210
|
-
try {
|
|
211
|
-
// 智能参数解析,支持自然语言输入
|
|
212
|
-
const parsedArgs = parseArgs(args, {
|
|
213
|
-
defaultValues: {
|
|
214
|
-
schema: "",
|
|
215
|
-
count: 1,
|
|
216
|
-
format: "json",
|
|
217
|
-
locale: "zh-CN",
|
|
218
|
-
seed: 0,
|
|
219
|
-
},
|
|
220
|
-
primaryField: "schema", // 纯文本输入默认映射到 schema 字段
|
|
221
|
-
fieldAliases: {
|
|
222
|
-
schema: ["type", "interface", "structure", "类型", "数据结构"],
|
|
223
|
-
count: ["num", "amount", "number", "数量"],
|
|
224
|
-
format: ["output", "type", "格式", "输出格式"],
|
|
225
|
-
locale: ["lang", "language", "语言", "区域"],
|
|
226
|
-
seed: ["random_seed", "种子"],
|
|
227
|
-
},
|
|
228
|
-
});
|
|
229
|
-
const schema = getString(parsedArgs.schema);
|
|
230
|
-
const count = getNumber(parsedArgs.count, 1);
|
|
231
|
-
const format = getString(parsedArgs.format) || "json";
|
|
232
|
-
const locale = getString(parsedArgs.locale) || "zh-CN";
|
|
233
|
-
const seed = getNumber(parsedArgs.seed, 0);
|
|
234
|
-
if (!schema) {
|
|
235
|
-
throw new Error("缺少必填参数: schema(数据结构定义)");
|
|
236
|
-
}
|
|
237
|
-
if (count < 1 || count > 1000) {
|
|
238
|
-
throw new Error("count 参数必须在 1-1000 之间");
|
|
239
|
-
}
|
|
240
|
-
const formatMap = {
|
|
241
|
-
json: "JSON",
|
|
242
|
-
typescript: "TypeScript",
|
|
243
|
-
javascript: "JavaScript",
|
|
244
|
-
csv: "CSV",
|
|
245
|
-
};
|
|
246
|
-
const localeMap = {
|
|
247
|
-
"zh-CN": "中文(简体)",
|
|
248
|
-
"en-US": "英文(美国)",
|
|
249
|
-
"ja-JP": "日文",
|
|
250
|
-
};
|
|
251
|
-
const seedSection = seed ? `- 随机种子: ${seed}(可重复生成)` : "";
|
|
252
|
-
const guide = PROMPT_TEMPLATE
|
|
253
|
-
.replace(/{schema}/g, schema)
|
|
254
|
-
.replace(/{count}/g, String(count))
|
|
255
|
-
.replace(/{format}/g, formatMap[format] || format)
|
|
256
|
-
.replace(/{locale}/g, localeMap[locale] || locale)
|
|
257
|
-
.replace(/{seed_section}/g, seedSection);
|
|
258
|
-
return {
|
|
259
|
-
content: [{ type: "text", text: guide }],
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
catch (error) {
|
|
263
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
264
|
-
return {
|
|
265
|
-
content: [{ type: "text", text: `❌ Mock 数据生成失败: ${errorMsg}` }],
|
|
266
|
-
isError: true,
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
}
|