mcp-probe-kit 1.13.0 → 1.15.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.
Files changed (49) hide show
  1. package/README.md +54 -3
  2. package/build/index.js +14 -1
  3. package/build/schemas/index.d.ts +108 -0
  4. package/build/schemas/index.js +2 -0
  5. package/build/schemas/ui-ux-schemas.d.ts +248 -0
  6. package/build/schemas/ui-ux-schemas.js +147 -0
  7. package/build/tools/__tests__/start_ui.integration.test.d.ts +6 -0
  8. package/build/tools/__tests__/start_ui.integration.test.js +179 -0
  9. package/build/tools/__tests__/start_ui.property.test.d.ts +6 -0
  10. package/build/tools/__tests__/start_ui.property.test.js +263 -0
  11. package/build/tools/__tests__/start_ui.unit.test.d.ts +6 -0
  12. package/build/tools/__tests__/start_ui.unit.test.js +109 -0
  13. package/build/tools/css_order.js +55 -55
  14. package/build/tools/index.d.ts +4 -0
  15. package/build/tools/index.js +5 -0
  16. package/build/tools/init_component_catalog.d.ts +22 -0
  17. package/build/tools/init_component_catalog.js +809 -0
  18. package/build/tools/render_ui.d.ts +22 -0
  19. package/build/tools/render_ui.js +384 -0
  20. package/build/tools/start_ui.d.ts +25 -0
  21. package/build/tools/start_ui.js +299 -0
  22. package/build/tools/ui-ux-tools.d.ts +116 -0
  23. package/build/tools/ui-ux-tools.js +756 -0
  24. package/build/tools/ui-ux-tools.test.d.ts +6 -0
  25. package/build/tools/ui-ux-tools.test.js +132 -0
  26. package/build/utils/ascii-box-formatter.d.ts +29 -0
  27. package/build/utils/ascii-box-formatter.js +195 -0
  28. package/build/utils/bm25.d.ts +60 -0
  29. package/build/utils/bm25.js +139 -0
  30. package/build/utils/cache-manager.d.ts +65 -0
  31. package/build/utils/cache-manager.js +156 -0
  32. package/build/utils/design-docs-generator.d.ts +1 -0
  33. package/build/utils/design-docs-generator.js +1 -0
  34. package/build/utils/design-reasoning-engine.d.ts +158 -0
  35. package/build/utils/design-reasoning-engine.js +363 -0
  36. package/build/utils/design-system-json-formatter.d.ts +41 -0
  37. package/build/utils/design-system-json-formatter.js +165 -0
  38. package/build/utils/ui-data-loader.d.ts +56 -0
  39. package/build/utils/ui-data-loader.js +164 -0
  40. package/build/utils/ui-search-engine.d.ts +57 -0
  41. package/build/utils/ui-search-engine.js +123 -0
  42. package/build/utils/ui-sync.d.ts +13 -0
  43. package/build/utils/ui-sync.js +241 -0
  44. package/docs/BEST_PRACTICES.md +257 -1
  45. package/docs/HOW_TO_TRIGGER.md +71 -1
  46. package/docs/MCP-Probe-Kit-/344/275/277/347/224/250/346/211/213/345/206/214.html +89 -29
  47. package/docs/MCP-Probe-Kit-/344/275/277/347/224/250/346/211/213/345/206/214.md +582 -1
  48. package/package.json +18 -5
  49. package/docs/HOW_TO_TRIGGER.html +0 -255
@@ -0,0 +1,22 @@
1
+ /**
2
+ * UI 渲染工具
3
+ *
4
+ * 将 JSON 模板渲染为最终代码
5
+ * 自动应用设计规范,确保样式统一
6
+ */
7
+ /**
8
+ * UI 渲染工具
9
+ */
10
+ export declare function renderUi(args: any): Promise<{
11
+ content: {
12
+ type: string;
13
+ text: string;
14
+ }[];
15
+ isError: boolean;
16
+ } | {
17
+ content: {
18
+ type: string;
19
+ text: string;
20
+ }[];
21
+ isError?: undefined;
22
+ }>;
@@ -0,0 +1,384 @@
1
+ /**
2
+ * UI 渲染工具
3
+ *
4
+ * 将 JSON 模板渲染为最终代码
5
+ * 自动应用设计规范,确保样式统一
6
+ */
7
+ const PROMPT_TEMPLATE = `# 🎨 UI 代码渲染
8
+
9
+ ## 🎯 任务目标
10
+
11
+ 将 JSON 模板渲染为最终代码,自动应用设计规范。
12
+
13
+ **输入文件**: \`{templatePath}\`
14
+ **框架**: {framework}
15
+
16
+ ---
17
+
18
+ ## 📋 执行流程
19
+
20
+ ### 第1步:读取必要文件
21
+
22
+ **操作**:
23
+ 1. 读取 UI 模板: \`{templatePath}\`
24
+ 2. 读取组件目录: \`docs/component-catalog.json\`
25
+ 3. 读取设计指南: \`docs/design-system.md\` ✨
26
+ 4. 读取设计规范: \`docs/design-system.json\`
27
+
28
+ **为什么要读取 design-system.md?**
29
+ - 理解设计理念和原则(如:专业、现代、简洁)
30
+ - 了解配色方案的使用场景(主色用于主要操作,辅色用于次要操作)
31
+ - 理解字体配对逻辑(标题用什么字体、正文用什么字体)
32
+ - 学习间距系统规则(什么时候用大间距、小间距)
33
+ - 查看反模式警告(避免什么样的设计)
34
+ - 确保生成的代码符合设计理念
35
+
36
+ **验证**:
37
+ - [ ] 所有文件都存在
38
+ - [ ] JSON 格式正确
39
+ - [ ] 模板引用的组件在组件目录中存在
40
+ - [ ] 理解了 design-system.md 中的设计理念
41
+
42
+ ---
43
+
44
+ ### 第2步:解析模板结构
45
+
46
+ **操作**:
47
+ 1. 解析 JSON 模板的 layout 结构
48
+ 2. 识别所有使用的组件
49
+ 3. 提取组件的 props
50
+
51
+ **示例模板**:
52
+ \`\`\`json
53
+ {
54
+ "name": "LoginForm",
55
+ "layout": {
56
+ "type": "Container",
57
+ "props": { "maxWidth": "sm" },
58
+ "children": [
59
+ {
60
+ "type": "Card",
61
+ "props": { "title": "登录" },
62
+ "children": [
63
+ {
64
+ "type": "Input",
65
+ "props": { "label": "用户名", "type": "text" }
66
+ },
67
+ {
68
+ "type": "Button",
69
+ "props": { "variant": "primary", "label": "登录" }
70
+ }
71
+ ]
72
+ }
73
+ ]
74
+ }
75
+ }
76
+ \`\`\`
77
+
78
+ ---
79
+
80
+ ### 第3步:替换占位符
81
+
82
+ **操作**:
83
+ 对每个组件,从组件目录中获取样式定义,然后替换占位符。
84
+
85
+ **占位符替换规则**:
86
+
87
+ 1. **颜色占位符**:
88
+ - \`{colors.primary.500}\` → 从 design-system.json 读取 \`colors.primary["500"]\`
89
+ - 示例: \`bg-[{colors.primary.500}]\` → \`bg-[#3b82f6]\`
90
+
91
+ 2. **字体占位符**:
92
+ - \`{typography.fontSize.base}\` → 从 design-system.json 读取
93
+ - 示例: \`text-[{typography.fontSize.base}]\` → \`text-[1rem]\`
94
+
95
+ 3. **间距占位符**:
96
+ - \`{spacing.scale.4}\` → 从 design-system.json 读取 \`spacing.scale[4]\`
97
+ - 示例: \`space-y-[{spacing.scale.4}]\` → \`space-y-4\`
98
+
99
+ 4. **圆角占位符**:
100
+ - \`{borderRadius.md}\` → 从 design-system.json 读取
101
+ - 示例: \`rounded-[{borderRadius.md}]\` → \`rounded-md\`
102
+
103
+ 5. **阴影占位符**:
104
+ - \`{shadows.md}\` → 从 design-system.json 读取
105
+ - 示例: \`shadow-[{shadows.md}]\` → \`shadow-md\`
106
+
107
+ **替换算法**:
108
+ \`\`\`typescript
109
+ function replacePlaceholders(styleString: string, designSystem: any): string {
110
+ // 匹配 {path.to.value} 格式
111
+ return styleString.replace(/\\{([^}]+)\\}/g, (match, path) => {
112
+ const value = getValueByPath(designSystem, path);
113
+ return value || match; // 找不到则保留原样
114
+ });
115
+ }
116
+
117
+ function getValueByPath(obj: any, path: string): any {
118
+ return path.split('.').reduce((current, key) => {
119
+ if (current && typeof current === 'object') {
120
+ // 处理数组索引,如 spacing.scale.4
121
+ if (!isNaN(Number(key)) && Array.isArray(current)) {
122
+ return current[Number(key)];
123
+ }
124
+ return current[key];
125
+ }
126
+ return undefined;
127
+ }, obj);
128
+ }
129
+ \`\`\`
130
+
131
+ ---
132
+
133
+ ### 第4步:生成代码
134
+
135
+ 根据框架生成对应的代码。
136
+
137
+ #### React 代码生成
138
+
139
+ \`\`\`tsx
140
+ import React from 'react';
141
+
142
+ export const {componentName}: React.FC = () => {
143
+ return (
144
+ <div className="{containerClasses}">
145
+ {/* 递归渲染子组件 */}
146
+ <div className="{cardClasses}">
147
+ <h2 className="text-2xl font-semibold mb-4">{title}</h2>
148
+
149
+ <div className="space-y-4">
150
+ {/* Input 组件 */}
151
+ <div>
152
+ <label className="block text-sm font-medium text-gray-700 mb-1">
153
+ {label}
154
+ </label>
155
+ <input
156
+ type="{type}"
157
+ className="{inputClasses}"
158
+ />
159
+ </div>
160
+
161
+ {/* Button 组件 */}
162
+ <button className="{buttonClasses}">
163
+ {buttonLabel}
164
+ </button>
165
+ </div>
166
+ </div>
167
+ </div>
168
+ );
169
+ };
170
+ \`\`\`
171
+
172
+ **关键点**:
173
+ - 所有 className 都是替换占位符后的实际值
174
+ - 颜色、间距、圆角都来自设计规范
175
+ - 保证样式统一
176
+
177
+ #### Vue 3 代码生成
178
+
179
+ \`\`\`vue
180
+ <template>
181
+ <div :class="containerClasses">
182
+ <div :class="cardClasses">
183
+ <h2 class="text-2xl font-semibold mb-4">{{ title }}</h2>
184
+
185
+ <div class="space-y-4">
186
+ <div>
187
+ <label class="block text-sm font-medium text-gray-700 mb-1">
188
+ {{ label }}
189
+ </label>
190
+ <input
191
+ :type="type"
192
+ :class="inputClasses"
193
+ />
194
+ </div>
195
+
196
+ <button :class="buttonClasses">
197
+ {{ buttonLabel }}
198
+ </button>
199
+ </div>
200
+ </div>
201
+ </div>
202
+ </template>
203
+
204
+ <script setup lang="ts">
205
+ import { ref } from 'vue';
206
+
207
+ const title = ref('{title}');
208
+ const label = ref('{label}');
209
+ const type = ref('{type}');
210
+ const buttonLabel = ref('{buttonLabel}');
211
+
212
+ const containerClasses = '{containerClasses}';
213
+ const cardClasses = '{cardClasses}';
214
+ const inputClasses = '{inputClasses}';
215
+ const buttonClasses = '{buttonClasses}';
216
+ </script>
217
+ \`\`\`
218
+
219
+ ---
220
+
221
+ ### 第5步:代码优化
222
+
223
+ **操作**:
224
+ 1. 格式化代码(缩进、换行)
225
+ 2. 添加 TypeScript 类型
226
+ 3. 添加注释说明
227
+ 4. 提取可复用的样式类
228
+
229
+ **优化示例**:
230
+ \`\`\`tsx
231
+ // 提取常量
232
+ const BUTTON_CLASSES = {
233
+ primary: 'bg-[#3b82f6] text-white hover:bg-[#2563eb]',
234
+ secondary: 'bg-[#8b5cf6] text-white hover:bg-[#7c3aed]',
235
+ } as const;
236
+
237
+ // 使用常量
238
+ <button className={\`\${baseClasses} \${BUTTON_CLASSES[variant]}\`}>
239
+ {label}
240
+ </button>
241
+ \`\`\`
242
+
243
+ ---
244
+
245
+ ## ✅ 输出结果
246
+
247
+ 生成的代码包含:
248
+
249
+ 1. **完整的组件实现**
250
+ - React: Hooks + TypeScript
251
+ - Vue: Composition API + TypeScript
252
+ - HTML: 原生 JavaScript
253
+
254
+ 2. **自动应用的设计规范**
255
+ - ✅ 设计理念来自 design-system.md(UI 风格、设计原则)
256
+ - ✅ 颜色来自 design-system.json(精确的色值)
257
+ - ✅ 字体来自 design-system.json(字体族和大小)
258
+ - ✅ 间距来自 design-system.json(间距比例)
259
+ - ✅ 圆角来自 design-system.json(圆角大小)
260
+ - ✅ 阴影来自 design-system.json(阴影效果)
261
+ - ✅ 最佳实践来自 design-system.md(使用建议)
262
+
263
+ 3. **代码特点**
264
+ - ✅ 类型安全(TypeScript)
265
+ - ✅ 可访问性(A11y)
266
+ - ✅ 响应式设计
267
+ - ✅ 样式统一
268
+ - ✅ 符合设计理念
269
+
270
+ ---
271
+
272
+ ## 📌 注意事项
273
+
274
+ 1. **占位符格式**: 必须严格遵循 \`{path.to.value}\` 格式
275
+ 2. **路径正确性**: 确保路径在 design-system.json 中存在
276
+ 3. **组件存在性**: 模板中的组件必须在 component-catalog.json 中定义
277
+ 4. **嵌套处理**: 正确处理组件的嵌套关系
278
+
279
+ ---
280
+
281
+ ## 🚀 使用示例
282
+
283
+ ### 示例 1:渲染登录表单
284
+
285
+ \`\`\`bash
286
+ # 假设已有 docs/ui/login-form.json
287
+ render_ui docs/ui/login-form.json --framework=react
288
+ \`\`\`
289
+
290
+ **输出**:
291
+ - 完整的 React 组件代码
292
+ - 自动应用设计规范
293
+ - 可直接使用
294
+
295
+ ### 示例 2:渲染数据表格
296
+
297
+ \`\`\`bash
298
+ render_ui docs/ui/data-table.json --framework=vue
299
+ \`\`\`
300
+
301
+ **输出**:
302
+ - 完整的 Vue 3 组件代码
303
+ - 自动应用设计规范
304
+ - 包含 TypeScript 类型
305
+
306
+ ---
307
+
308
+ ## ⚠️ 边界约束
309
+
310
+ - ❌ 仅输出代码,不自动创建文件
311
+ - ❌ 不执行代码或命令
312
+ - ✅ 输出完整可用的组件代码
313
+ - ✅ 自动应用设计规范
314
+ - ✅ 保证样式统一
315
+
316
+ ---
317
+
318
+ ## 🔗 相关工具
319
+
320
+ - **ui_design_system**: 生成设计规范
321
+ - **init_component_catalog**: 生成组件目录
322
+ - **ui_search --mode=template**: 获取 UI 模板
323
+ - **start_ui**: 一键完成整个流程(推荐)
324
+ `;
325
+ /**
326
+ * UI 渲染工具
327
+ */
328
+ export async function renderUi(args) {
329
+ try {
330
+ // 解析参数
331
+ const templatePath = args.template || args.path || args.input || '';
332
+ const framework = args.framework || 'react';
333
+ if (!templatePath) {
334
+ return {
335
+ content: [
336
+ {
337
+ type: "text",
338
+ text: `❌ 缺少必要参数
339
+
340
+ **用法**:
341
+ \`\`\`
342
+ render_ui <template-path> [--framework=react|vue|html]
343
+ \`\`\`
344
+
345
+ **示例**:
346
+ \`\`\`
347
+ render_ui docs/ui/login-form.json
348
+ render_ui docs/ui/login-form.json --framework=vue
349
+ \`\`\`
350
+
351
+ **提示**:
352
+ - 模板文件应该是 JSON 格式
353
+ - 确保已运行 \`ui_design_system\` 和 \`init_component_catalog\`
354
+ `,
355
+ },
356
+ ],
357
+ isError: true,
358
+ };
359
+ }
360
+ const guide = PROMPT_TEMPLATE
361
+ .replace(/{templatePath}/g, templatePath)
362
+ .replace(/{framework}/g, framework);
363
+ return {
364
+ content: [
365
+ {
366
+ type: "text",
367
+ text: guide,
368
+ },
369
+ ],
370
+ };
371
+ }
372
+ catch (error) {
373
+ const errorMessage = error instanceof Error ? error.message : String(error);
374
+ return {
375
+ content: [
376
+ {
377
+ type: "text",
378
+ text: `❌ UI 渲染失败: ${errorMessage}`,
379
+ },
380
+ ],
381
+ isError: true,
382
+ };
383
+ }
384
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * 统一 UI 开发编排工具
3
+ *
4
+ * 一键完成整个 UI 开发流程:
5
+ * 1. 检查设计规范
6
+ * 2. 检查/生成组件目录
7
+ * 3. 搜索/生成 UI 模板
8
+ * 4. 渲染最终代码
9
+ */
10
+ /**
11
+ * 统一 UI 开发编排工具
12
+ */
13
+ export declare function startUi(args: any): Promise<{
14
+ content: {
15
+ type: string;
16
+ text: string;
17
+ }[];
18
+ isError: boolean;
19
+ } | {
20
+ content: {
21
+ type: string;
22
+ text: string;
23
+ }[];
24
+ isError?: undefined;
25
+ }>;