mcp-probe-kit 1.0.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 (51) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +607 -0
  3. package/build/index.d.ts +2 -0
  4. package/build/index.js +553 -0
  5. package/build/tools/check_deps.d.ts +13 -0
  6. package/build/tools/check_deps.js +204 -0
  7. package/build/tools/code_review.d.ts +13 -0
  8. package/build/tools/code_review.js +138 -0
  9. package/build/tools/convert.d.ts +13 -0
  10. package/build/tools/convert.js +575 -0
  11. package/build/tools/debug.d.ts +13 -0
  12. package/build/tools/debug.js +78 -0
  13. package/build/tools/detect_shell.d.ts +6 -0
  14. package/build/tools/detect_shell.js +138 -0
  15. package/build/tools/explain.d.ts +13 -0
  16. package/build/tools/explain.js +369 -0
  17. package/build/tools/fix.d.ts +13 -0
  18. package/build/tools/fix.js +290 -0
  19. package/build/tools/genapi.d.ts +13 -0
  20. package/build/tools/genapi.js +152 -0
  21. package/build/tools/genchangelog.d.ts +13 -0
  22. package/build/tools/genchangelog.js +227 -0
  23. package/build/tools/gencommit.d.ts +13 -0
  24. package/build/tools/gencommit.js +95 -0
  25. package/build/tools/gendoc.d.ts +13 -0
  26. package/build/tools/gendoc.js +208 -0
  27. package/build/tools/genpr.d.ts +13 -0
  28. package/build/tools/genpr.js +173 -0
  29. package/build/tools/genreadme.d.ts +13 -0
  30. package/build/tools/genreadme.js +613 -0
  31. package/build/tools/gensql.d.ts +13 -0
  32. package/build/tools/gensql.js +307 -0
  33. package/build/tools/gentest.d.ts +13 -0
  34. package/build/tools/gentest.js +155 -0
  35. package/build/tools/genui.d.ts +13 -0
  36. package/build/tools/genui.js +781 -0
  37. package/build/tools/index.d.ts +22 -0
  38. package/build/tools/index.js +22 -0
  39. package/build/tools/init_project.d.ts +13 -0
  40. package/build/tools/init_project.js +142 -0
  41. package/build/tools/init_setting.d.ts +13 -0
  42. package/build/tools/init_setting.js +47 -0
  43. package/build/tools/perf.d.ts +13 -0
  44. package/build/tools/perf.js +359 -0
  45. package/build/tools/refactor.d.ts +13 -0
  46. package/build/tools/refactor.js +318 -0
  47. package/build/tools/resolve_conflict.d.ts +13 -0
  48. package/build/tools/resolve_conflict.js +338 -0
  49. package/build/tools/split.d.ts +13 -0
  50. package/build/tools/split.js +577 -0
  51. package/package.json +66 -0
@@ -0,0 +1,318 @@
1
+ // refactor 工具实现
2
+ export async function refactor(args) {
3
+ try {
4
+ const code = args?.code || "";
5
+ const goal = args?.goal || ""; // improve_readability, reduce_complexity, extract_function, etc.
6
+ const message = `请为以下代码提供重构建议:
7
+
8
+ 📝 **代码内容**:
9
+ ${code || "请提供需要重构的代码"}
10
+
11
+ 🎯 **重构目标**:${goal || "全面优化"}
12
+
13
+ ---
14
+
15
+ ## 重构分析流程
16
+
17
+ ### 第一步:识别代码坏味道
18
+
19
+ **常见问题**:
20
+ 1. **重复代码(Duplicated Code)**
21
+ - 相同或相似的代码出现多次
22
+ - 建议:提取公共函数/方法
23
+
24
+ 2. **过长函数(Long Function)**
25
+ - 函数超过 30 行
26
+ - 建议:拆分为多个小函数
27
+
28
+ 3. **过大类(Large Class)**
29
+ - 类职责过多
30
+ - 建议:按职责拆分类
31
+
32
+ 4. **过长参数列表(Long Parameter List)**
33
+ - 参数超过 3-4 个
34
+ - 建议:使用对象封装参数
35
+
36
+ 5. **复杂条件判断(Complex Conditional)**
37
+ - 嵌套超过 3 层
38
+ - 建议:提前返回、使用策略模式
39
+
40
+ 6. **魔法数字(Magic Numbers)**
41
+ - 硬编码的数字
42
+ - 建议:使用常量
43
+
44
+ 7. **紧耦合(Tight Coupling)**
45
+ - 模块间依赖过强
46
+ - 建议:依赖注入、接口抽象
47
+
48
+ ### 第二步:重构建议
49
+
50
+ **优先级分类**:
51
+ - 🔴 **Critical**:严重影响可维护性
52
+ - 🟡 **Important**:建议尽快处理
53
+ - 🟢 **Nice-to-have**:可选优化
54
+
55
+ ---
56
+
57
+ ## 重构技术清单
58
+
59
+ ### 1️⃣ 提取函数(Extract Function)
60
+
61
+ **场景**:一段代码可以被独立理解
62
+
63
+ **示例**:
64
+ \`\`\`typescript
65
+ // Before
66
+ function processOrder(order) {
67
+ // 验证订单
68
+ if (!order.id || !order.items || order.items.length === 0) {
69
+ throw new Error('Invalid order');
70
+ }
71
+
72
+ // 计算总价
73
+ let total = 0;
74
+ for (const item of order.items) {
75
+ total += item.price * item.quantity;
76
+ }
77
+
78
+ // 应用折扣
79
+ if (order.coupon) {
80
+ total = total * (1 - order.coupon.discount);
81
+ }
82
+
83
+ return total;
84
+ }
85
+
86
+ // After
87
+ function processOrder(order) {
88
+ validateOrder(order);
89
+ const subtotal = calculateSubtotal(order.items);
90
+ const total = applyDiscount(subtotal, order.coupon);
91
+ return total;
92
+ }
93
+
94
+ function validateOrder(order) {
95
+ if (!order.id || !order.items || order.items.length === 0) {
96
+ throw new Error('Invalid order');
97
+ }
98
+ }
99
+
100
+ function calculateSubtotal(items) {
101
+ return items.reduce((sum, item) => sum + item.price * item.quantity, 0);
102
+ }
103
+
104
+ function applyDiscount(amount, coupon) {
105
+ return coupon ? amount * (1 - coupon.discount) : amount;
106
+ }
107
+ \`\`\`
108
+
109
+ ### 2️⃣ 简化条件表达式
110
+
111
+ **技巧**:
112
+ - 使用提前返回(Early Return)
113
+ - 合并条件
114
+ - 使用三元运算符
115
+ - 策略模式替代 switch
116
+
117
+ **示例**:
118
+ \`\`\`typescript
119
+ // Before
120
+ function getDiscount(user) {
121
+ if (user) {
122
+ if (user.isPremium) {
123
+ if (user.orderCount > 10) {
124
+ return 0.3;
125
+ } else {
126
+ return 0.2;
127
+ }
128
+ } else {
129
+ return 0.1;
130
+ }
131
+ } else {
132
+ return 0;
133
+ }
134
+ }
135
+
136
+ // After
137
+ function getDiscount(user) {
138
+ if (!user) return 0;
139
+ if (!user.isPremium) return 0.1;
140
+ return user.orderCount > 10 ? 0.3 : 0.2;
141
+ }
142
+ \`\`\`
143
+
144
+ ### 3️⃣ 引入参数对象
145
+
146
+ **场景**:参数过多
147
+
148
+ **示例**:
149
+ \`\`\`typescript
150
+ // Before
151
+ function createUser(name, email, age, address, phone, country) {
152
+ // ...
153
+ }
154
+
155
+ // After
156
+ interface UserData {
157
+ name: string;
158
+ email: string;
159
+ age: number;
160
+ address: string;
161
+ phone: string;
162
+ country: string;
163
+ }
164
+
165
+ function createUser(userData: UserData) {
166
+ // ...
167
+ }
168
+ \`\`\`
169
+
170
+ ### 4️⃣ 替换魔法数字
171
+
172
+ **示例**:
173
+ \`\`\`typescript
174
+ // Before
175
+ if (status === 1) {
176
+ // ...
177
+ } else if (status === 2) {
178
+ // ...
179
+ }
180
+
181
+ // After
182
+ enum OrderStatus {
183
+ PENDING = 1,
184
+ PROCESSING = 2,
185
+ COMPLETED = 3
186
+ }
187
+
188
+ if (status === OrderStatus.PENDING) {
189
+ // ...
190
+ } else if (status === OrderStatus.PROCESSING) {
191
+ // ...
192
+ }
193
+ \`\`\`
194
+
195
+ ### 5️⃣ 组合函数调用
196
+
197
+ **示例**:
198
+ \`\`\`typescript
199
+ // Before
200
+ const data = getData();
201
+ const filtered = filterData(data);
202
+ const sorted = sortData(filtered);
203
+ const formatted = formatData(sorted);
204
+
205
+ // After
206
+ const result = getData()
207
+ .then(filterData)
208
+ .then(sortData)
209
+ .then(formatData);
210
+
211
+ // Or using pipe
212
+ const result = pipe(
213
+ getData,
214
+ filterData,
215
+ sortData,
216
+ formatData
217
+ )();
218
+ \`\`\`
219
+
220
+ ---
221
+
222
+ ## 重构计划模板
223
+
224
+ ### 🎯 重构目标
225
+ 简要说明重构的目的和预期效果
226
+
227
+ ### 📋 问题清单
228
+ 1. **问题 1**:重复代码
229
+ - 位置:第 10-20 行、第 50-60 行
230
+ - 影响:可维护性差
231
+ - 优先级:🔴 Critical
232
+
233
+ 2. **问题 2**:函数过长
234
+ - 位置:processData() 函数
235
+ - 影响:难以理解和测试
236
+ - 优先级:🟡 Important
237
+
238
+ ### 🔧 重构步骤
239
+
240
+ **步骤 1:准备**
241
+ - [x] 确保测试覆盖率 > 80%
242
+ - [x] 备份当前代码
243
+ - [x] 创建重构分支
244
+
245
+ **步骤 2:小步重构**
246
+ 1. 提取 calculateTotal 函数
247
+ - 风险:低
248
+ - 预计时间:10 分钟
249
+ - 测试:运行单元测试
250
+
251
+ 2. 简化条件判断
252
+ - 风险:低
253
+ - 预计时间:15 分钟
254
+ - 测试:运行集成测试
255
+
256
+ 3. 引入参数对象
257
+ - 风险:中
258
+ - 预计时间:30 分钟
259
+ - 测试:全量测试
260
+
261
+ **步骤 3:验证**
262
+ - [ ] 所有测试通过
263
+ - [ ] 代码审查
264
+ - [ ] 性能对比
265
+ - [ ] 部署到测试环境
266
+
267
+ ### ⚠️ 风险评估
268
+
269
+ **高风险操作**:
270
+ - 修改公共 API
271
+ - 改变数据结构
272
+ - 调整核心算法
273
+
274
+ **降低风险的措施**:
275
+ - 渐进式重构(小步快跑)
276
+ - 每步都运行测试
277
+ - 保持功能不变
278
+ - Code Review
279
+
280
+ ### 📊 预期收益
281
+
282
+ **可维护性**:⬆️ 30%
283
+ - 代码行数减少 20%
284
+ - 圈复杂度降低 40%
285
+
286
+ **可测试性**:⬆️ 50%
287
+ - 函数职责单一
288
+ - 依赖可注入
289
+
290
+ **性能**:⬆️ 10%
291
+ - 减少重复计算
292
+ - 优化算法复杂度
293
+
294
+ ---
295
+
296
+ 现在请分析代码,提供详细的重构建议和实施计划。`;
297
+ return {
298
+ content: [
299
+ {
300
+ type: "text",
301
+ text: message,
302
+ },
303
+ ],
304
+ };
305
+ }
306
+ catch (error) {
307
+ const errorMessage = error instanceof Error ? error.message : String(error);
308
+ return {
309
+ content: [
310
+ {
311
+ type: "text",
312
+ text: `❌ 重构分析失败: ${errorMessage}`,
313
+ },
314
+ ],
315
+ isError: true,
316
+ };
317
+ }
318
+ }
@@ -0,0 +1,13 @@
1
+ export declare function resolveConflict(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
+ }>;
@@ -0,0 +1,338 @@
1
+ // resolve_conflict 工具实现
2
+ export async function resolveConflict(args) {
3
+ try {
4
+ const conflicts = args?.conflicts || "";
5
+ const message = `请分析并解决以下 Git 冲突:
6
+
7
+ ⚔️ **冲突内容**:
8
+ ${conflicts || "请提供 git diff 或冲突文件内容"}
9
+
10
+ ---
11
+
12
+ ## Git 冲突解决流程
13
+
14
+ ### 第一步:识别冲突
15
+
16
+ 执行以下命令查看冲突:
17
+ \`\`\`bash
18
+ # 查看冲突文件列表
19
+ git status
20
+
21
+ # 查看具体冲突
22
+ git diff
23
+
24
+ # 或查看单个文件冲突
25
+ git diff --ours --theirs filename
26
+ \`\`\`
27
+
28
+ ### 第二步:理解冲突标记
29
+
30
+ **冲突格式:**
31
+ \`\`\`
32
+ <<<<<<< HEAD (当前分支)
33
+ 你的修改
34
+ =======
35
+ 他人的修改
36
+ >>>>>>> branch-name (合并的分支)
37
+ \`\`\`
38
+
39
+ **示例冲突:**
40
+ \`\`\`javascript
41
+ function calculateTotal(items) {
42
+ <<<<<<< HEAD
43
+ // 你的修改:添加了折扣
44
+ const subtotal = items.reduce((sum, item) => sum + item.price, 0);
45
+ return subtotal * 0.9; // 10% 折扣
46
+ =======
47
+ // 他人的修改:添加了税费
48
+ const subtotal = items.reduce((sum, item) => sum + item.price * item.quantity, 0);
49
+ return subtotal * 1.1; // 10% 税费
50
+ >>>>>>> feature/add-tax
51
+ }
52
+ \`\`\`
53
+
54
+ ---
55
+
56
+ ## 冲突分析
57
+
58
+ ### 🔍 冲突类型识别
59
+
60
+ **1️⃣ 简单冲突(二选一)**
61
+ - 两个分支修改了同一行
62
+ - 通常选择其中一个版本
63
+
64
+ **2️⃣ 复杂冲突(需要合并)**
65
+ - 两个分支都添加了有用的功能
66
+ - 需要整合双方的修改
67
+
68
+ **3️⃣ 语义冲突**
69
+ - 语法上没冲突,但逻辑上不兼容
70
+ - 需要重新设计
71
+
72
+ **4️⃣ 结构冲突**
73
+ - 文件被移动或删除
74
+ - 需要决定文件的最终状态
75
+
76
+ ---
77
+
78
+ ## 解决策略
79
+
80
+ ### 策略 1:保留当前分支(ours)
81
+ \`\`\`bash
82
+ git checkout --ours filename
83
+ git add filename
84
+ \`\`\`
85
+
86
+ ### 策略 2:保留对方分支(theirs)
87
+ \`\`\`bash
88
+ git checkout --theirs filename
89
+ git add filename
90
+ \`\`\`
91
+
92
+ ### 策略 3:手动合并(推荐)
93
+
94
+ **步骤:**
95
+ 1. 分析双方的修改意图
96
+ 2. 整合有价值的修改
97
+ 3. 删除冲突标记
98
+ 4. 测试合并后的代码
99
+
100
+ **合并示例:**
101
+ \`\`\`javascript
102
+ // 原始冲突
103
+ function calculateTotal(items) {
104
+ <<<<<<< HEAD
105
+ const subtotal = items.reduce((sum, item) => sum + item.price, 0);
106
+ return subtotal * 0.9; // 10% 折扣
107
+ =======
108
+ const subtotal = items.reduce((sum, item) => sum + item.price * item.quantity, 0);
109
+ return subtotal * 1.1; // 10% 税费
110
+ >>>>>>> feature/add-tax
111
+ }
112
+
113
+ // ✅ 合并后(整合双方修改)
114
+ function calculateTotal(items, { discount = 0, taxRate = 0.1 } = {}) {
115
+ // 整合了数量计算(theirs)和参数化设计(改进)
116
+ const subtotal = items.reduce((sum, item) => sum + item.price * item.quantity, 0);
117
+ const afterDiscount = subtotal * (1 - discount);
118
+ return afterDiscount * (1 + taxRate);
119
+ }
120
+ \`\`\`
121
+
122
+ ---
123
+
124
+ ## 常见冲突场景
125
+
126
+ ### 场景 1:Import 语句冲突
127
+ \`\`\`typescript
128
+ <<<<<<< HEAD
129
+ import { Button, Input } from './components';
130
+ import { api } from './services';
131
+ =======
132
+ import { Button, Select } from './components';
133
+ import { fetchData } from './utils';
134
+ >>>>>>> feature/add-select
135
+
136
+ // ✅ 合并后
137
+ import { Button, Input, Select } from './components';
138
+ import { api } from './services';
139
+ import { fetchData } from './utils';
140
+ \`\`\`
141
+
142
+ ### 场景 2:配置文件冲突
143
+ \`\`\`json
144
+ <<<<<<< HEAD
145
+ {
146
+ "name": "my-app",
147
+ "version": "1.2.0",
148
+ "scripts": {
149
+ "dev": "vite",
150
+ "build": "vite build"
151
+ }
152
+ }
153
+ =======
154
+ {
155
+ "name": "my-app",
156
+ "version": "1.1.0",
157
+ "scripts": {
158
+ "dev": "vite",
159
+ "build": "vite build",
160
+ "test": "jest"
161
+ }
162
+ }
163
+ >>>>>>> feature/add-tests
164
+
165
+ // ✅ 合并后(保留最新版本号和所有脚本)
166
+ {
167
+ "name": "my-app",
168
+ "version": "1.2.0",
169
+ "scripts": {
170
+ "dev": "vite",
171
+ "build": "vite build",
172
+ "test": "jest"
173
+ }
174
+ }
175
+ \`\`\`
176
+
177
+ ### 场景 3:函数重构冲突
178
+ \`\`\`typescript
179
+ <<<<<<< HEAD
180
+ // 你将同步改为异步
181
+ async function getUserData(id) {
182
+ const response = await fetch(\`/api/users/\${id}\`);
183
+ return response.json();
184
+ }
185
+ =======
186
+ // 他人添加了缓存
187
+ function getUserData(id) {
188
+ if (cache.has(id)) {
189
+ return cache.get(id);
190
+ }
191
+ const data = fetchUser(id);
192
+ cache.set(id, data);
193
+ return data;
194
+ }
195
+ >>>>>>> feature/add-cache
196
+
197
+ // ✅ 合并后(异步 + 缓存)
198
+ async function getUserData(id) {
199
+ if (cache.has(id)) {
200
+ return cache.get(id);
201
+ }
202
+ const response = await fetch(\`/api/users/\${id}\`);
203
+ const data = await response.json();
204
+ cache.set(id, data);
205
+ return data;
206
+ }
207
+ \`\`\`
208
+
209
+ ---
210
+
211
+ ## 解决步骤
212
+
213
+ ### Step 1: 备份
214
+ \`\`\`bash
215
+ # 创建备份分支
216
+ git branch backup-before-merge
217
+ \`\`\`
218
+
219
+ ### Step 2: 分析冲突
220
+ \`\`\`bash
221
+ # 查看冲突统计
222
+ git diff --stat
223
+
224
+ # 使用可视化工具
225
+ git mergetool
226
+ \`\`\`
227
+
228
+ ### Step 3: 解决冲突
229
+ 1. 打开冲突文件
230
+ 2. 分析双方修改
231
+ 3. 手动合并代码
232
+ 4. 删除冲突标记(<<<, ===, >>>)
233
+
234
+ ### Step 4: 测试
235
+ \`\`\`bash
236
+ # 运行测试
237
+ npm test
238
+
239
+ # 运行 linter
240
+ npm run lint
241
+
242
+ # 构建检查
243
+ npm run build
244
+ \`\`\`
245
+
246
+ ### Step 5: 提交
247
+ \`\`\`bash
248
+ # 标记冲突已解决
249
+ git add .
250
+
251
+ # 完成合并
252
+ git commit
253
+
254
+ # Git 会自动生成合并消息,或自定义:
255
+ git commit -m "chore: 解决 feature/xxx 合并冲突
256
+
257
+ - 整合了折扣和税费计算
258
+ - 保留了所有新增功能
259
+ - 所有测试通过"
260
+ \`\`\`
261
+
262
+ ---
263
+
264
+ ## 预防冲突
265
+
266
+ ### 1️⃣ 频繁同步
267
+ \`\`\`bash
268
+ # 每天同步主分支
269
+ git fetch origin
270
+ git rebase origin/main
271
+ \`\`\`
272
+
273
+ ### 2️⃣ 小步提交
274
+ - 提交粒度要小
275
+ - 功能尽量独立
276
+ - 避免大范围重构
277
+
278
+ ### 3️⃣ 代码审查
279
+ - PR 及时 Review
280
+ - 避免长期未合并的分支
281
+
282
+ ### 4️⃣ 使用工具
283
+ - VSCode Git Lens
284
+ - GitKraken
285
+ - Sourcetree
286
+
287
+ ---
288
+
289
+ ## 复杂冲突处理
290
+
291
+ ### 使用 Git Rerere(重用已记录的解决方案)
292
+ \`\`\`bash
293
+ # 启用 rerere
294
+ git config --global rerere.enabled true
295
+
296
+ # Git 会记住你的冲突解决方式
297
+ # 下次遇到相同冲突时自动应用
298
+ \`\`\`
299
+
300
+ ### 使用三路合并工具
301
+ \`\`\`bash
302
+ # 配置 VSCode 作为合并工具
303
+ git config --global merge.tool vscode
304
+ git config --global mergetool.vscode.cmd 'code --wait $MERGED'
305
+
306
+ # 使用
307
+ git mergetool
308
+ \`\`\`
309
+
310
+ ---
311
+
312
+ 现在请分析冲突内容,提供:
313
+ 1. 冲突原因分析
314
+ 2. 双方修改意图
315
+ 3. 推荐的合并方案
316
+ 4. 完整的解决后代码`;
317
+ return {
318
+ content: [
319
+ {
320
+ type: "text",
321
+ text: message,
322
+ },
323
+ ],
324
+ };
325
+ }
326
+ catch (error) {
327
+ const errorMessage = error instanceof Error ? error.message : String(error);
328
+ return {
329
+ content: [
330
+ {
331
+ type: "text",
332
+ text: `❌ 冲突解决失败: ${errorMessage}`,
333
+ },
334
+ ],
335
+ isError: true,
336
+ };
337
+ }
338
+ }
@@ -0,0 +1,13 @@
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
+ }>;