mcp-probe-kit 2.3.0 → 2.5.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 (186) hide show
  1. package/README.md +131 -48
  2. package/build/index.js +1 -7
  3. package/build/lib/guidance.d.ts +8 -0
  4. package/build/lib/guidance.js +30 -0
  5. package/build/lib/orchestration-guidance.d.ts +8 -0
  6. package/build/lib/orchestration-guidance.js +16 -0
  7. package/build/lib/template-loader.d.ts +25 -0
  8. package/build/lib/template-loader.js +473 -0
  9. package/build/lib/toolset-manager.d.ts +4 -4
  10. package/build/lib/toolset-manager.js +10 -13
  11. package/build/schemas/code-analysis-tools.d.ts +0 -18
  12. package/build/schemas/code-analysis-tools.js +0 -19
  13. package/build/schemas/doc-util-tools.d.ts +0 -9
  14. package/build/schemas/doc-util-tools.js +0 -10
  15. package/build/schemas/index.d.ts +46 -47
  16. package/build/schemas/orchestration-tools.d.ts +42 -2
  17. package/build/schemas/orchestration-tools.js +42 -2
  18. package/build/schemas/output/core-tools.d.ts +1 -117
  19. package/build/schemas/output/core-tools.js +1 -60
  20. package/build/schemas/output/index.d.ts +5 -4
  21. package/build/schemas/output/index.js +6 -4
  22. package/build/schemas/output/product-design-tools.d.ts +160 -0
  23. package/build/schemas/output/product-design-tools.js +75 -0
  24. package/build/schemas/output/project-tools.d.ts +1 -217
  25. package/build/schemas/output/project-tools.js +1 -103
  26. package/build/schemas/project-tools.d.ts +4 -18
  27. package/build/schemas/project-tools.js +4 -19
  28. package/build/schemas/structured-output.d.ts +309 -99
  29. package/build/schemas/structured-output.js +174 -72
  30. package/build/schemas/ui-ux-schemas.d.ts +26 -0
  31. package/build/schemas/ui-ux-schemas.js +26 -0
  32. package/build/tools/__tests__/add_feature.template.test.d.ts +4 -0
  33. package/build/tools/__tests__/add_feature.template.test.js +47 -0
  34. package/build/tools/__tests__/start_bugfix.unit.test.d.ts +4 -0
  35. package/build/tools/__tests__/start_bugfix.unit.test.js +85 -0
  36. package/build/tools/__tests__/start_feature.unit.test.d.ts +4 -0
  37. package/build/tools/__tests__/start_feature.unit.test.js +83 -0
  38. package/build/tools/__tests__/start_ui.integration.test.js +4 -3
  39. package/build/tools/__tests__/start_ui.loop.test.d.ts +4 -0
  40. package/build/tools/__tests__/start_ui.loop.test.js +24 -0
  41. package/build/tools/__tests__/start_ui.unit.test.js +39 -1
  42. package/build/tools/add_feature.js +184 -406
  43. package/build/tools/ask_user.js +18 -5
  44. package/build/tools/code_review.js +8 -1
  45. package/build/tools/estimate.js +9 -2
  46. package/build/tools/fix_bug.js +9 -2
  47. package/build/tools/gen_mock.js +8 -1
  48. package/build/tools/gen_prd.d.ts +1 -7
  49. package/build/tools/gen_prd.js +41 -27
  50. package/build/tools/gen_prototype.d.ts +1 -7
  51. package/build/tools/gen_prototype.js +47 -27
  52. package/build/tools/genapi.js +8 -1
  53. package/build/tools/genchangelog.js +8 -1
  54. package/build/tools/gencommit.d.ts +1 -1
  55. package/build/tools/gencommit.js +49 -18
  56. package/build/tools/gendoc.js +9 -1
  57. package/build/tools/genpr.js +8 -1
  58. package/build/tools/genreadme.js +8 -1
  59. package/build/tools/gensql.js +8 -1
  60. package/build/tools/gentest.js +8 -1
  61. package/build/tools/index.d.ts +0 -3
  62. package/build/tools/index.js +0 -3
  63. package/build/tools/interview.d.ts +1 -13
  64. package/build/tools/interview.js +96 -31
  65. package/build/tools/perf.js +8 -1
  66. package/build/tools/refactor.js +8 -1
  67. package/build/tools/resolve_conflict.js +8 -1
  68. package/build/tools/security_scan.js +9 -2
  69. package/build/tools/start_api.js +44 -4
  70. package/build/tools/start_bugfix.js +377 -15
  71. package/build/tools/start_doc.js +40 -4
  72. package/build/tools/start_feature.js +287 -92
  73. package/build/tools/start_onboard.js +83 -100
  74. package/build/tools/start_product.d.ts +1 -1
  75. package/build/tools/start_product.js +183 -6
  76. package/build/tools/start_ralph.js +51 -2
  77. package/build/tools/start_refactor.js +39 -4
  78. package/build/tools/start_release.js +33 -4
  79. package/build/tools/start_review.js +39 -4
  80. package/build/tools/start_ui.js +669 -52
  81. package/build/utils/design-reasoning-engine.d.ts +5 -0
  82. package/build/utils/design-reasoning-engine.js +85 -5
  83. package/docs/data/tools.js +308 -478
  84. package/docs/index.html +1 -1
  85. package/docs/pages/all-tools.html +37 -22
  86. package/docs/pages/examples.html +100 -35
  87. package/docs/pages/getting-started.html +43 -3
  88. package/docs/pages/migration.html +14 -8
  89. package/package.json +79 -79
  90. package/build/lib/analysis-tasks.d.ts +0 -35
  91. package/build/lib/analysis-tasks.js +0 -788
  92. package/build/lib/elicitation-helper.d.ts +0 -73
  93. package/build/lib/elicitation-helper.js +0 -130
  94. package/build/lib/task-generator.d.ts +0 -11
  95. package/build/lib/task-generator.js +0 -109
  96. package/build/lib/template-generator.d.ts +0 -14
  97. package/build/lib/template-generator.js +0 -62
  98. package/build/lib/templates/backend-templates.d.ts +0 -8
  99. package/build/lib/templates/backend-templates.js +0 -26
  100. package/build/resources/index.d.ts +0 -4
  101. package/build/resources/index.js +0 -4
  102. package/build/resources/tool-params-guide.d.ts +0 -571
  103. package/build/resources/tool-params-guide.js +0 -488
  104. package/build/tools/analyze_project.d.ts +0 -1
  105. package/build/tools/analyze_project.js +0 -566
  106. package/build/tools/check_deps.d.ts +0 -1
  107. package/build/tools/check_deps.js +0 -213
  108. package/build/tools/convert.d.ts +0 -13
  109. package/build/tools/convert.js +0 -599
  110. package/build/tools/css_order.d.ts +0 -13
  111. package/build/tools/css_order.js +0 -81
  112. package/build/tools/debug.d.ts +0 -1
  113. package/build/tools/debug.js +0 -133
  114. package/build/tools/design2code.d.ts +0 -20
  115. package/build/tools/design2code.js +0 -426
  116. package/build/tools/detect_shell.d.ts +0 -6
  117. package/build/tools/detect_shell.js +0 -151
  118. package/build/tools/explain.d.ts +0 -13
  119. package/build/tools/explain.js +0 -390
  120. package/build/tools/fix.d.ts +0 -13
  121. package/build/tools/fix.js +0 -303
  122. package/build/tools/gen_skill.d.ts +0 -13
  123. package/build/tools/gen_skill.js +0 -560
  124. package/build/tools/genui.d.ts +0 -13
  125. package/build/tools/genui.js +0 -803
  126. package/build/tools/init_setting.d.ts +0 -13
  127. package/build/tools/init_setting.js +0 -47
  128. package/build/tools/split.d.ts +0 -13
  129. package/build/tools/split.js +0 -599
  130. package/build/tools/templates/architecture-template.d.ts +0 -5
  131. package/build/tools/templates/architecture-template.js +0 -42
  132. package/build/tools/templates/coding-standards-template.d.ts +0 -5
  133. package/build/tools/templates/coding-standards-template.js +0 -41
  134. package/build/tools/templates/dependencies-template.d.ts +0 -5
  135. package/build/tools/templates/dependencies-template.js +0 -38
  136. package/build/tools/templates/index-template.d.ts +0 -5
  137. package/build/tools/templates/index-template.js +0 -64
  138. package/build/tools/templates/tech-stack-template.d.ts +0 -5
  139. package/build/tools/templates/tech-stack-template.js +0 -35
  140. package/build/tools/templates/workflows-template.d.ts +0 -5
  141. package/build/tools/templates/workflows-template.js +0 -31
  142. package/docs/specs/algorithm-enhancement/roadmap.md +0 -619
  143. package/docs/specs/project-context-modular/design.md +0 -722
  144. package/docs/specs/project-context-modular/example-output.md +0 -123
  145. package/docs/specs/project-context-modular/implementation-v2.md +0 -275
  146. package/docs/specs/project-context-modular/requirements.md +0 -234
  147. package/docs/specs/project-context-modular/tasks.md +0 -386
  148. package/docs/specs/v2.1-planning.md +0 -335
  149. package/docs/specs/vnext-upgrade/00-OVERVIEW.md +0 -258
  150. package/docs/specs/vnext-upgrade/BETA_RELEASE_GUIDE.md +0 -328
  151. package/docs/specs/vnext-upgrade/GITHUB_DISCUSSION_TEMPLATE.md +0 -236
  152. package/docs/specs/vnext-upgrade/M8.9-PROGRESS-UPDATE.md +0 -248
  153. package/docs/specs/vnext-upgrade/PROGRESS-SUMMARY.md +0 -195
  154. package/docs/specs/vnext-upgrade/QUICK_REFERENCE.md +0 -338
  155. package/docs/specs/vnext-upgrade/README.md +0 -125
  156. package/docs/specs/vnext-upgrade/STATUS-UPDATE-2026-01-26.md +0 -230
  157. package/docs/specs/vnext-upgrade/TOOL_CLEANUP.md +0 -343
  158. package/docs/specs/vnext-upgrade/completed/M1-M2-SUMMARY.md +0 -27
  159. package/docs/specs/vnext-upgrade/completed/M3_COMPLETION_SUMMARY.md +0 -273
  160. package/docs/specs/vnext-upgrade/completed/M4-SUMMARY.md +0 -19
  161. package/docs/specs/vnext-upgrade/completed/M5_COMPLETION_SUMMARY.md +0 -0
  162. package/docs/specs/vnext-upgrade/completed/M8.1-SUMMARY.md +0 -247
  163. package/docs/specs/vnext-upgrade/completed/M8.2-SUMMARY.md +0 -296
  164. package/docs/specs/vnext-upgrade/completed/M8.3-SUMMARY.md +0 -241
  165. package/docs/specs/vnext-upgrade/completed/M8.3-TEST-SUMMARY.md +0 -216
  166. package/docs/specs/vnext-upgrade/completed/M8.4-SUMMARY.md +0 -217
  167. package/docs/specs/vnext-upgrade/completed/M8.4-TEST-SUMMARY.md +0 -198
  168. package/docs/specs/vnext-upgrade/completed/M8.5-SUMMARY.md +0 -202
  169. package/docs/specs/vnext-upgrade/completed/M8.5-TEST-SUMMARY.md +0 -223
  170. package/docs/specs/vnext-upgrade/completed/M8.6-SUMMARY.md +0 -299
  171. package/docs/specs/vnext-upgrade/completed/M8.8-TEST-SUMMARY.md +0 -216
  172. package/docs/specs/vnext-upgrade/completed/TOOL-CLEANUP-SUMMARY.md +0 -210
  173. package/docs/specs/vnext-upgrade/design.md +0 -848
  174. package/docs/specs/vnext-upgrade/requirements.md +0 -221
  175. package/docs/specs/vnext-upgrade/tasks/00-INDEX.md +0 -335
  176. package/docs/specs/vnext-upgrade/tasks/M8.1-SCHEMA-DEFINITION.md +0 -300
  177. package/docs/specs/vnext-upgrade/tasks/M8.2-P1-TOOLS.md +0 -249
  178. package/docs/specs/vnext-upgrade/tasks/M8.3-GENERATION-TOOLS.md +0 -49
  179. package/docs/specs/vnext-upgrade/tasks/M8.4-ORCHESTRATION-TOOLS.md +0 -28
  180. package/docs/specs/vnext-upgrade/tasks/M8.5-PROJECT-TOOLS.md +0 -29
  181. package/docs/specs/vnext-upgrade/tasks/M8.6-UI-TOOLS.md +0 -66
  182. package/docs/specs/vnext-upgrade/tasks/M8.7-HELPER-TOOLS.md +0 -24
  183. package/docs/specs/vnext-upgrade/tasks/M8.8-INTEGRATION-TESTS.md +0 -90
  184. package/docs/specs/vnext-upgrade/tasks/M8.9-DOCUMENTATION.md +0 -103
  185. package/docs/vnext/MCP_2025-11-25_GUIDE.md +0 -276
  186. package/docs/vnext/vNext-PRD.md +0 -488
@@ -1,13 +0,0 @@
1
- export declare function initSetting(args: any): Promise<{
2
- content: {
3
- type: string;
4
- text: string;
5
- }[];
6
- isError?: undefined;
7
- } | {
8
- content: {
9
- type: string;
10
- text: string;
11
- }[];
12
- isError: boolean;
13
- }>;
@@ -1,47 +0,0 @@
1
- // init_setting 工具实现
2
- export async function initSetting(args) {
3
- try {
4
- // 要写入的配置
5
- const settings = {
6
- // 统一使用 Claude-4.5-Sonnet(Chat / Composer / Edit 三处都钉死,便于复现)
7
- "ai.chatModel": "claude-sonnet-4-5",
8
- "ai.composerModel": "claude-sonnet-4-5",
9
- "ai.editModel": "claude-sonnet-4-5",
10
- // 采样温度:0 更"严格/确定",适合生成结构化/按规范的代码与 JSON
11
- "ai.temperature": 0,
12
- // 单次生成的最大 token(上限按平台限制,4096 对大多数修改/重构足够)
13
- // "ai.maxTokens": 4096, // 保守:4096 平衡:8192 激进:16384
14
- // ======================= 代码库上下文(让模型更懂你的项目) =======================
15
- // 语义检索:用向量搜索理解项目,而不是仅靠邻近几行
16
- "ai.contextEngine": "semantic",
17
- // 检索深度:high 提高命中率(更"聪明"地找引用/类型/API 使用示例)
18
- "ai.contextDepth": "high",
19
- // 是否将代码库上下文喂给模型:日常开发建议开启
20
- "ai.includeCodebaseContext": true, // 做模型指纹/一致性实验时 设置成:false
21
- // 语义与邻近的折中策略:balanced(常用且稳)
22
- "ai.contextStrategy": "balanced", // 做模型指纹/一致性实验时 设置成:neighboring
23
- };
24
- const message = `你要在项目的根目录下 .cursor/settings.json 文件内容追加以下内容,不要替换原有内容:
25
- ${JSON.stringify(settings, null, 2)}`;
26
- return {
27
- content: [
28
- {
29
- type: "text",
30
- text: message,
31
- },
32
- ],
33
- };
34
- }
35
- catch (error) {
36
- const errorMessage = error instanceof Error ? error.message : String(error);
37
- return {
38
- content: [
39
- {
40
- type: "text",
41
- text: `❌ 初始化配置失败: ${errorMessage}\n\n可能原因:\n- 没有文件写入权限\n- 不在 Cursor 工作区中\n- 路径错误`,
42
- },
43
- ],
44
- isError: true,
45
- };
46
- }
47
- }
@@ -1,13 +0,0 @@
1
- export declare function split(args: any): Promise<{
2
- content: {
3
- type: string;
4
- text: string;
5
- }[];
6
- isError?: undefined;
7
- } | {
8
- content: {
9
- type: string;
10
- text: string;
11
- }[];
12
- isError: boolean;
13
- }>;
@@ -1,599 +0,0 @@
1
- import { parseArgs, getString } from "../utils/parseArgs.js";
2
- // split 工具实现
3
- export async function split(args) {
4
- try {
5
- // 智能参数解析,支持自然语言输入
6
- const parsedArgs = parseArgs(args, {
7
- defaultValues: {
8
- file: "",
9
- strategy: "auto",
10
- },
11
- primaryField: "file", // 纯文本输入默认映射到 file 字段
12
- fieldAliases: {
13
- file: ["code", "source", "content", "文件", "代码"],
14
- strategy: ["method", "type", "策略", "拆分策略"],
15
- },
16
- });
17
- const file = getString(parsedArgs.file);
18
- const strategy = getString(parsedArgs.strategy) || "auto"; // auto, type, function, component, feature
19
- const message = `请拆分以下文件:
20
-
21
- 📝 **文件内容**:
22
- ${file || "请提供需要拆分的文件内容或路径"}
23
-
24
- 🎯 **拆分策略**:${strategy}
25
-
26
- ---
27
-
28
- ## 文件拆分指南
29
-
30
- ### 拆分策略
31
-
32
- #### 1️⃣ 按类型拆分(type)
33
- 适用于工具类、常量、类型定义混在一起的文件。
34
-
35
- **示例场景**:
36
- \`\`\`typescript
37
- // ❌ utils.ts (500 行)
38
- export const API_URL = 'https://api.example.com';
39
- export const MAX_RETRY = 3;
40
-
41
- export interface User {
42
- id: string;
43
- name: string;
44
- }
45
-
46
- export function formatDate(date: Date): string { }
47
- export function validateEmail(email: string): boolean { }
48
- \`\`\`
49
-
50
- **拆分后**:
51
- \`\`\`
52
- src/
53
- ├── constants/
54
- │ └── api.ts # API_URL, MAX_RETRY
55
- ├── types/
56
- │ └── user.ts # User interface
57
- └── utils/
58
- ├── date.ts # formatDate
59
- └── validation.ts # validateEmail
60
- \`\`\`
61
-
62
- ---
63
-
64
- #### 2️⃣ 按功能拆分(function)
65
- 适用于一个文件包含多个独立函数。
66
-
67
- **示例场景**:
68
- \`\`\`typescript
69
- // ❌ helpers.ts (800 行)
70
- export function userHelpers() { }
71
- export function orderHelpers() { }
72
- export function paymentHelpers() { }
73
- \`\`\`
74
-
75
- **拆分后**:
76
- \`\`\`
77
- src/helpers/
78
- ├── user.ts # 用户相关
79
- ├── order.ts # 订单相关
80
- └── payment.ts # 支付相关
81
- \`\`\`
82
-
83
- ---
84
-
85
- #### 3️⃣ 按组件拆分(component)
86
- 适用于 React/Vue 组件过大,需要拆分为子组件。
87
-
88
- **示例场景**:
89
- \`\`\`tsx
90
- // ❌ UserProfile.tsx (600 行)
91
- export function UserProfile() {
92
- return (
93
- <div>
94
- {/* Header 100 行 */}
95
- {/* Sidebar 150 行 */}
96
- {/* Content 200 行 */}
97
- {/* Footer 150 行 */}
98
- </div>
99
- );
100
- }
101
- \`\`\`
102
-
103
- **拆分后**:
104
- \`\`\`
105
- src/components/UserProfile/
106
- ├── index.tsx # 主组件(组装)
107
- ├── UserProfileHeader.tsx
108
- ├── UserProfileSidebar.tsx
109
- ├── UserProfileContent.tsx
110
- ├── UserProfileFooter.tsx
111
- └── styles.module.css
112
- \`\`\`
113
-
114
- ---
115
-
116
- #### 4️⃣ 按功能模块拆分(feature)
117
- 适用于功能模块混在一起的大文件。
118
-
119
- **示例场景**:
120
- \`\`\`typescript
121
- // ❌ store.ts (1000 行)
122
- // 用户模块 state, actions, reducers
123
- // 订单模块 state, actions, reducers
124
- // 购物车模块 state, actions, reducers
125
- \`\`\`
126
-
127
- **拆分后**:
128
- \`\`\`
129
- src/store/
130
- ├── index.ts # 组装所有模块
131
- ├── user/
132
- │ ├── state.ts
133
- │ ├── actions.ts
134
- │ └── reducers.ts
135
- ├── order/
136
- │ ├── state.ts
137
- │ ├── actions.ts
138
- │ └── reducers.ts
139
- └── cart/
140
- ├── state.ts
141
- ├── actions.ts
142
- └── reducers.ts
143
- \`\`\`
144
-
145
- ---
146
-
147
- #### 5️⃣ 自动分析拆分(auto)
148
- AI 分析代码结构,自动选择最佳拆分策略。
149
-
150
- ---
151
-
152
- ## 拆分原则
153
-
154
- ### ✅ 应该拆分的信号
155
-
156
- 1. **文件行数过多**
157
- - 超过 300 行:考虑拆分
158
- - 超过 500 行:强烈建议拆分
159
- - 超过 1000 行:必须拆分
160
-
161
- 2. **职责过多**
162
- - 处理多个不相关的业务逻辑
163
- - 混合了类型定义、工具函数、组件
164
-
165
- 3. **难以维护**
166
- - 滚动半天找不到函数
167
- - 修改一个功能影响其他功能
168
- - Git 冲突频繁
169
-
170
- 4. **复用性差**
171
- - 只能整体导入,无法按需导入
172
- - 想复用某个函数,必须导入整个文件
173
-
174
- ### ⚠️ 不应该过度拆分
175
-
176
- 1. **避免碎片化**
177
- - 不要拆成几十个只有几行的文件
178
- - 保持相关代码的内聚性
179
-
180
- 2. **避免循环依赖**
181
- - 拆分后注意依赖关系
182
- - 使用依赖注入或中间层解耦
183
-
184
- ---
185
-
186
- ## 拆分实战示例
187
-
188
- ### 示例 1:大型 React 组件拆分
189
-
190
- **原始文件(UserDashboard.tsx - 800 行)**:
191
- \`\`\`tsx
192
- import React, { useState, useEffect } from 'react';
193
- import './styles.css';
194
-
195
- export function UserDashboard() {
196
- const [user, setUser] = useState(null);
197
- const [orders, setOrders] = useState([]);
198
- const [stats, setStats] = useState({});
199
-
200
- // 150 行:用户信息相关逻辑
201
- useEffect(() => { /* 获取用户信息 */ }, []);
202
- const updateUserProfile = () => { /* 更新用户 */ };
203
-
204
- // 200 行:订单相关逻辑
205
- useEffect(() => { /* 获取订单 */ }, []);
206
- const filterOrders = () => { /* 过滤订单 */ };
207
-
208
- // 150 行:统计相关逻辑
209
- useEffect(() => { /* 获取统计 */ }, []);
210
- const calculateStats = () => { /* 计算统计 */ };
211
-
212
- // 300 行:渲染逻辑
213
- return (
214
- <div className="dashboard">
215
- {/* Header */}
216
- <div className="header">
217
- {/* 50 行 */}
218
- </div>
219
-
220
- {/* Sidebar */}
221
- <div className="sidebar">
222
- {/* 100 行 */}
223
- </div>
224
-
225
- {/* Main Content */}
226
- <div className="main">
227
- {/* User Info Section - 80 行 */}
228
- <div className="user-info">
229
- <h2>{user?.name}</h2>
230
- {/* ... */}
231
- </div>
232
-
233
- {/* Orders Section - 100 行 */}
234
- <div className="orders">
235
- <h3>我的订单</h3>
236
- {/* ... */}
237
- </div>
238
-
239
- {/* Stats Section - 70 行 */}
240
- <div className="stats">
241
- <h3>统计数据</h3>
242
- {/* ... */}
243
- </div>
244
- </div>
245
- </div>
246
- );
247
- }
248
- \`\`\`
249
-
250
- **拆分方案**:
251
-
252
- **1. 拆分自定义 Hooks**
253
- \`\`\`typescript
254
- // hooks/useUser.ts
255
- export function useUser() {
256
- const [user, setUser] = useState(null);
257
-
258
- useEffect(() => {
259
- // 获取用户信息
260
- }, []);
261
-
262
- const updateUserProfile = () => {
263
- // 更新用户
264
- };
265
-
266
- return { user, updateUserProfile };
267
- }
268
-
269
- // hooks/useOrders.ts
270
- export function useOrders() {
271
- const [orders, setOrders] = useState([]);
272
-
273
- useEffect(() => {
274
- // 获取订单
275
- }, []);
276
-
277
- const filterOrders = () => {
278
- // 过滤订单
279
- };
280
-
281
- return { orders, filterOrders };
282
- }
283
-
284
- // hooks/useStats.ts
285
- export function useStats() {
286
- const [stats, setStats] = useState({});
287
-
288
- useEffect(() => {
289
- // 获取统计
290
- }, []);
291
-
292
- const calculateStats = () => {
293
- // 计算统计
294
- };
295
-
296
- return { stats, calculateStats };
297
- }
298
- \`\`\`
299
-
300
- **2. 拆分子组件**
301
- \`\`\`tsx
302
- // components/DashboardHeader.tsx
303
- export function DashboardHeader({ user }) {
304
- return (
305
- <div className="header">
306
- {/* 50 行 */}
307
- </div>
308
- );
309
- }
310
-
311
- // components/DashboardSidebar.tsx
312
- export function DashboardSidebar() {
313
- return (
314
- <div className="sidebar">
315
- {/* 100 行 */}
316
- </div>
317
- );
318
- }
319
-
320
- // components/UserInfoSection.tsx
321
- export function UserInfoSection({ user, onUpdate }) {
322
- return (
323
- <div className="user-info">
324
- <h2>{user?.name}</h2>
325
- {/* 80 行 */}
326
- </div>
327
- );
328
- }
329
-
330
- // components/OrdersSection.tsx
331
- export function OrdersSection({ orders, onFilter }) {
332
- return (
333
- <div className="orders">
334
- <h3>我的订单</h3>
335
- {/* 100 行 */}
336
- </div>
337
- );
338
- }
339
-
340
- // components/StatsSection.tsx
341
- export function StatsSection({ stats }) {
342
- return (
343
- <div className="stats">
344
- <h3>统计数据</h3>
345
- {/* 70 行 */}
346
- </div>
347
- );
348
- }
349
- \`\`\`
350
-
351
- **3. 重构主组件(只有 50 行)**
352
- \`\`\`tsx
353
- // components/UserDashboard/index.tsx
354
- import React from 'react';
355
- import { useUser } from './hooks/useUser';
356
- import { useOrders } from './hooks/useOrders';
357
- import { useStats } from './hooks/useStats';
358
- import { DashboardHeader } from './DashboardHeader';
359
- import { DashboardSidebar } from './DashboardSidebar';
360
- import { UserInfoSection } from './UserInfoSection';
361
- import { OrdersSection } from './OrdersSection';
362
- import { StatsSection } from './StatsSection';
363
- import './styles.css';
364
-
365
- export function UserDashboard() {
366
- const { user, updateUserProfile } = useUser();
367
- const { orders, filterOrders } = useOrders();
368
- const { stats } = useStats();
369
-
370
- return (
371
- <div className="dashboard">
372
- <DashboardHeader user={user} />
373
- <DashboardSidebar />
374
- <div className="main">
375
- <UserInfoSection user={user} onUpdate={updateUserProfile} />
376
- <OrdersSection orders={orders} onFilter={filterOrders} />
377
- <StatsSection stats={stats} />
378
- </div>
379
- </div>
380
- );
381
- }
382
- \`\`\`
383
-
384
- **最终目录结构**:
385
- \`\`\`
386
- src/components/UserDashboard/
387
- ├── index.tsx # 主组件 (50 行)
388
- ├── DashboardHeader.tsx # 子组件 (50 行)
389
- ├── DashboardSidebar.tsx # 子组件 (100 行)
390
- ├── UserInfoSection.tsx # 子组件 (80 行)
391
- ├── OrdersSection.tsx # 子组件 (100 行)
392
- ├── StatsSection.tsx # 子组件 (70 行)
393
- ├── hooks/
394
- │ ├── useUser.ts # Hook (60 行)
395
- │ ├── useOrders.ts # Hook (80 行)
396
- │ └── useStats.ts # Hook (60 行)
397
- └── styles.css
398
- \`\`\`
399
-
400
- **优势**:
401
- - ✅ 每个文件职责单一,易于理解
402
- - ✅ 组件可独立测试
403
- - ✅ 逻辑可复用(Hooks)
404
- - ✅ 多人协作减少冲突
405
- - ✅ 按需导入,优化打包体积
406
-
407
- ---
408
-
409
- ### 示例 2:工具函数文件拆分
410
-
411
- **原始文件(utils.ts - 600 行)**:
412
- \`\`\`typescript
413
- // 字符串工具 (150 行)
414
- export function capitalize(str: string): string { }
415
- export function truncate(str: string, length: number): string { }
416
- export function slugify(str: string): string { }
417
-
418
- // 日期工具 (150 行)
419
- export function formatDate(date: Date): string { }
420
- export function parseDate(str: string): Date { }
421
- export function addDays(date: Date, days: number): Date { }
422
-
423
- // 数组工具 (100 行)
424
- export function unique<T>(arr: T[]): T[] { }
425
- export function groupBy<T>(arr: T[], key: keyof T): Record<string, T[]> { }
426
-
427
- // 验证工具 (100 行)
428
- export function isEmail(str: string): boolean { }
429
- export function isURL(str: string): boolean { }
430
-
431
- // 数学工具 (100 行)
432
- export function round(num: number, decimals: number): number { }
433
- export function clamp(num: number, min: number, max: number): number { }
434
- \`\`\`
435
-
436
- **拆分后**:
437
- \`\`\`
438
- src/utils/
439
- ├── index.ts # 统一导出
440
- ├── string.ts # 字符串工具
441
- ├── date.ts # 日期工具
442
- ├── array.ts # 数组工具
443
- ├── validation.ts # 验证工具
444
- └── math.ts # 数学工具
445
- \`\`\`
446
-
447
- \`\`\`typescript
448
- // utils/index.ts (统一导出)
449
- export * from './string';
450
- export * from './date';
451
- export * from './array';
452
- export * from './validation';
453
- export * from './math';
454
-
455
- // 使用方式不变
456
- import { capitalize, formatDate, unique } from '@/utils';
457
- \`\`\`
458
-
459
- ---
460
-
461
- ### 示例 3:Vue 组件拆分
462
-
463
- **原始文件(ProductList.vue - 700 行)**:
464
- \`\`\`vue
465
- <template>
466
- <div class="product-list">
467
- <!-- Filter Section - 150 行 -->
468
- <div class="filters">
469
- <!-- 过滤器 UI -->
470
- </div>
471
-
472
- <!-- Product Grid - 300 行 -->
473
- <div class="products">
474
- <!-- 产品列表 -->
475
- </div>
476
-
477
- <!-- Pagination - 100 行 -->
478
- <div class="pagination">
479
- <!-- 分页 -->
480
- </div>
481
- </div>
482
- </template>
483
-
484
- <script setup lang="ts">
485
- // 250 行逻辑
486
- const products = ref([]);
487
- const filters = ref({});
488
- // ...
489
- </script>
490
-
491
- <style scoped>
492
- /* 100 行样式 */
493
- </style>
494
- \`\`\`
495
-
496
- **拆分后**:
497
- \`\`\`
498
- src/components/ProductList/
499
- ├── ProductList.vue # 主组件 (100 行)
500
- ├── ProductFilters.vue # 过滤器组件 (150 行)
501
- ├── ProductGrid.vue # 产品网格 (200 行)
502
- ├── ProductCard.vue # 产品卡片 (100 行)
503
- ├── ProductPagination.vue # 分页组件 (100 行)
504
- ├── composables/
505
- │ ├── useProducts.ts # 产品数据逻辑
506
- │ └── useFilters.ts # 过滤逻辑
507
- └── styles.module.css
508
- \`\`\`
509
-
510
- ---
511
-
512
- ## 拆分步骤
513
-
514
- ### Step 1: 分析依赖关系
515
- \`\`\`bash
516
- # 使用工具分析依赖
517
- npx madge --circular src/
518
-
519
- # 或手动绘制依赖图
520
- \`\`\`
521
-
522
- ### Step 2: 识别独立模块
523
- - 找出职责单一的代码块
524
- - 识别可复用的逻辑
525
- - 标记高内聚低耦合的部分
526
-
527
- ### Step 3: 制定拆分计划
528
- - 确定目录结构
529
- - 规划文件命名
530
- - 设计导出策略
531
-
532
- ### Step 4: 逐步拆分
533
- - 从最独立的模块开始
534
- - 先拆分,后重构
535
- - 每次拆分后运行测试
536
-
537
- ### Step 5: 更新导入
538
- - 批量替换 import 路径
539
- - 使用 IDE 的重构功能
540
- - 验证所有引用
541
-
542
- ### Step 6: 清理优化
543
- - 删除未使用的导出
544
- - 优化重复代码
545
- - 添加文档注释
546
-
547
- ---
548
-
549
- ## 拆分工具推荐
550
-
551
- ### VS Code 扩展
552
- - **Move TS** - 自动更新 import
553
- - **JavaScript Refactor** - 快速提取函数/组件
554
- - **Path Intellisense** - 路径自动补全
555
-
556
- ### CLI 工具
557
- - **madge** - 依赖分析
558
- - **jscodeshift** - 代码自动化重构
559
- - **ts-morph** - TypeScript AST 操作
560
-
561
- ---
562
-
563
- ---
564
-
565
- ## ⚠️ 边界约束
566
-
567
- - ❌ 仅输出拆分方案和代码,不自动创建文件
568
- - ❌ 不执行代码或命令
569
- - ✅ 尽量保持对外导出与行为不变
570
- - ✅ 输出完整的文件结构和代码
571
-
572
- 现在请分析文件并提供详细的拆分方案,包括:
573
- 1. 拆分策略分析
574
- 2. 建议的目录结构
575
- 3. 每个新文件的内容
576
- 4. 导入导出关系
577
- 5. 迁移步骤`;
578
- return {
579
- content: [
580
- {
581
- type: "text",
582
- text: message,
583
- },
584
- ],
585
- };
586
- }
587
- catch (error) {
588
- const errorMessage = error instanceof Error ? error.message : String(error);
589
- return {
590
- content: [
591
- {
592
- type: "text",
593
- text: `❌ 文件拆分失败: ${errorMessage}`,
594
- },
595
- ],
596
- isError: true,
597
- };
598
- }
599
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * 架构模板
3
- * 用于生成 architecture.md(架构和项目结构)
4
- */
5
- export declare const architectureTemplate = "# \u67B6\u6784\u8BBE\u8BA1\n\n> \u672C\u6587\u6863\u63CF\u8FF0 [\u9879\u76EE\u540D\u79F0] \u7684\u67B6\u6784\u548C\u9879\u76EE\u7ED3\u6784\u3002\n\n## \u9879\u76EE\u4FE1\u606F\n\n| \u5C5E\u6027 | \u503C |\n|------|-----|\n| \u9879\u76EE\u540D\u79F0 | [\u9879\u76EE\u540D\u79F0] |\n| \u7248\u672C | [\u7248\u672C\u53F7] |\n\n## \u9879\u76EE\u7ED3\u6784\n\n```\n[\u751F\u6210\u76EE\u5F55\u6811]\n```\n\n## \u4E3B\u8981\u76EE\u5F55\u8BF4\u660E\n\n| \u76EE\u5F55 | \u7528\u9014 |\n|------|------|\n| [\u76EE\u5F55\u540D] | [\u7528\u9014\u8BF4\u660E] |\n\n## \u5165\u53E3\u6587\u4EF6\n\n- \u4E3B\u5165\u53E3: [\u5165\u53E3\u6587\u4EF6\u8DEF\u5F84]\n\n## \u67B6\u6784\u6A21\u5F0F\n\n- **\u9879\u76EE\u7C7B\u578B**: [\u9879\u76EE\u7C7B\u578B]\n- **\u8BBE\u8BA1\u6A21\u5F0F**: [\u4F7F\u7528\u7684\u8BBE\u8BA1\u6A21\u5F0F]\n- **\u6A21\u5757\u5212\u5206**: [\u6A21\u5757\u5212\u5206\u8BF4\u660E]\n\n---\n\n*\u751F\u6210\u65F6\u95F4: [\u65F6\u95F4\u6233]* \n*\u8FD4\u56DE\u7D22\u5F15: [../project-context.md](../project-context.md)*\n";