mcp-probe-kit 3.0.23 → 3.1.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 +755 -779
- package/build/index.js +38 -40
- package/build/lib/__tests__/memory-injection.unit.test.js +1 -0
- package/build/lib/agents-md-template.js +32 -32
- package/build/lib/memory-client.d.ts +2 -0
- package/build/lib/memory-client.js +1 -0
- package/build/lib/memory-config.d.ts +2 -0
- package/build/lib/memory-config.js +1 -0
- package/build/lib/memory-orchestration.d.ts +4 -0
- package/build/lib/memory-orchestration.js +28 -5
- package/build/lib/skill-bridge.js +12 -12
- package/build/resources/index.d.ts +4 -0
- package/build/resources/index.js +4 -0
- package/build/resources/tool-params-guide.d.ts +571 -0
- package/build/resources/tool-params-guide.js +488 -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 +0 -22
- package/build/schemas/memory-tools.d.ts +0 -22
- package/build/schemas/memory-tools.js +0 -14
- package/build/tools/__tests__/read_memory_asset.unit.test.js +75 -0
- package/build/tools/__tests__/search_memory.unit.test.js +7 -1
- package/build/tools/analyze_project.d.ts +1 -0
- package/build/tools/analyze_project.js +527 -0
- package/build/tools/check_deps.d.ts +13 -0
- package/build/tools/check_deps.js +204 -0
- package/build/tools/code_insight.js +41 -41
- package/build/tools/convert.d.ts +13 -0
- package/build/tools/convert.js +599 -0
- package/build/tools/css_order.d.ts +13 -0
- package/build/tools/css_order.js +81 -0
- package/build/tools/debug.d.ts +13 -0
- package/build/tools/debug.js +131 -0
- package/build/tools/design2code.d.ts +20 -0
- package/build/tools/design2code.js +426 -0
- package/build/tools/detect_shell.d.ts +6 -0
- package/build/tools/detect_shell.js +151 -0
- package/build/tools/explain.d.ts +13 -0
- package/build/tools/explain.js +390 -0
- package/build/tools/fix.d.ts +13 -0
- package/build/tools/fix.js +303 -0
- package/build/tools/fix_bug.js +161 -161
- package/build/tools/gen_mock.d.ts +22 -0
- package/build/tools/gen_mock.js +269 -0
- package/build/tools/gen_skill.d.ts +13 -0
- package/build/tools/gen_skill.js +560 -0
- package/build/tools/genapi.d.ts +13 -0
- package/build/tools/genapi.js +174 -0
- package/build/tools/genchangelog.d.ts +13 -0
- package/build/tools/genchangelog.js +250 -0
- package/build/tools/gencommit.js +60 -60
- package/build/tools/gendoc.d.ts +13 -0
- package/build/tools/gendoc.js +232 -0
- package/build/tools/genpr.d.ts +13 -0
- package/build/tools/genpr.js +194 -0
- package/build/tools/genreadme.d.ts +13 -0
- package/build/tools/genreadme.js +626 -0
- package/build/tools/gensql.d.ts +13 -0
- package/build/tools/gensql.js +320 -0
- package/build/tools/genui.d.ts +13 -0
- package/build/tools/genui.js +803 -0
- package/build/tools/index.d.ts +0 -1
- package/build/tools/index.js +0 -1
- package/build/tools/init_component_catalog.d.ts +22 -0
- package/build/tools/init_component_catalog.js +809 -0
- package/build/tools/init_project_context.js +432 -432
- package/build/tools/init_setting.d.ts +13 -0
- package/build/tools/init_setting.js +47 -0
- package/build/tools/perf.d.ts +13 -0
- package/build/tools/perf.js +409 -0
- package/build/tools/read_memory_asset.js +2 -1
- package/build/tools/render_ui.d.ts +22 -0
- package/build/tools/render_ui.js +384 -0
- package/build/tools/resolve_conflict.d.ts +13 -0
- package/build/tools/resolve_conflict.js +349 -0
- package/build/tools/search_memory.js +1 -0
- package/build/tools/security_scan.d.ts +22 -0
- package/build/tools/security_scan.js +323 -0
- package/build/tools/split.d.ts +13 -0
- package/build/tools/split.js +599 -0
- package/build/tools/start_api.d.ts +13 -0
- package/build/tools/start_api.js +193 -0
- package/build/tools/start_bugfix.js +233 -233
- package/build/tools/start_doc.d.ts +13 -0
- package/build/tools/start_doc.js +207 -0
- package/build/tools/start_feature.js +117 -117
- package/build/tools/start_product.js +1 -1
- package/build/tools/start_refactor.d.ts +13 -0
- package/build/tools/start_refactor.js +188 -0
- package/build/tools/start_release.d.ts +13 -0
- package/build/tools/start_release.js +167 -0
- package/build/tools/start_review.d.ts +13 -0
- package/build/tools/start_review.js +175 -0
- package/build/tools/start_ui.js +399 -399
- package/build/tools/ui-ux-tools.js +290 -290
- package/build/utils/__tests__/vercel-guidelines-sync.unit.test.js +12 -12
- package/build/utils/themes-sync.js +8 -8
- package/package.json +81 -83
- package/build/lib/__tests__/memory-orchestration.unit.test.js +0 -84
- package/build/lib/__tests__/memory-payload.unit.test.js +0 -35
- package/build/lib/cursor-history-client.d.ts +0 -54
- package/build/lib/cursor-history-client.js +0 -240
- package/build/tools/__tests__/cursor-history.unit.test.js +0 -38
- package/build/tools/cursor_read_conversation.d.ts +0 -7
- package/build/tools/cursor_read_conversation.js +0 -36
- package/docs/.mcp-probe/layout.json +0 -11
- package/docs/CNAME +0 -1
- package/docs/assets/font/MaterialSymbolsOutlined.codepoints +0 -4102
- package/docs/assets/font/MaterialSymbolsOutlined.ttf +0 -0
- package/docs/assets/font/noto-sans-sc-400.ttf +0 -0
- package/docs/assets/font/noto-sans-sc-700.ttf +0 -0
- package/docs/assets/font/noto-sans-sc-900.ttf +0 -0
- package/docs/assets/js/i18n.js +0 -375
- package/docs/assets/js/tailwind.js +0 -83
- package/docs/assets/logo-zh.png +0 -0
- package/docs/assets/logo.png +0 -0
- package/docs/data/tools.js +0 -523
- package/docs/i18n/all-tools/en.json +0 -190
- package/docs/i18n/all-tools/ja.json +0 -171
- package/docs/i18n/all-tools/ko.json +0 -171
- package/docs/i18n/all-tools/zh-CN.json +0 -190
- package/docs/i18n/en.json +0 -626
- package/docs/i18n/ja.json +0 -602
- package/docs/i18n/ko.json +0 -602
- package/docs/i18n/zh-CN.json +0 -626
- package/docs/index.html +0 -327
- package/docs/memory-local-setup.md +0 -314
- package/docs/memory-local-setup.zh-CN.md +0 -283
- package/docs/pages/all-tools.html +0 -515
- package/docs/pages/examples.html +0 -717
- package/docs/pages/getting-started.html +0 -964
- package/docs/pages/migration.html +0 -308
- package/docs/specs/user-auth/design.md +0 -82
- package/docs/specs/user-auth/requirements.md +0 -52
- package/docs/specs/user-auth/tasks.md +0 -55
- /package/build/{lib/__tests__/memory-orchestration.unit.test.d.ts → tools/__tests__/read_memory_asset.unit.test.d.ts} +0 -0
- /package/build/{lib/__tests__/memory-payload.unit.test.d.ts → utils/design-docs-generator.d.ts} +0 -0
- /package/build/{tools/__tests__/cursor-history.unit.test.d.ts → utils/design-docs-generator.js} +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import { parseArgs, getString } from "../utils/parseArgs.js";
|
|
2
|
+
// perf 工具实现
|
|
3
|
+
export async function perf(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", "代码", "function"],
|
|
14
|
+
type: ["analysis_type", "category", "类型", "分析类型"],
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
const code = getString(parsedArgs.code);
|
|
18
|
+
const type = getString(parsedArgs.type) || "all"; // algorithm, memory, react, database
|
|
19
|
+
const message = `请分析以下代码的性能问题并提供优化建议:
|
|
20
|
+
|
|
21
|
+
📝 **代码内容**:
|
|
22
|
+
${code || "请提供需要性能分析的代码"}
|
|
23
|
+
|
|
24
|
+
🎯 **分析重点**:${type}
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 性能分析流程
|
|
29
|
+
|
|
30
|
+
### 第一步:识别性能瓶颈
|
|
31
|
+
|
|
32
|
+
**常见性能问题**:
|
|
33
|
+
1. **时间复杂度过高**
|
|
34
|
+
- 嵌套循环 O(n²) 或更差
|
|
35
|
+
- 未优化的算法
|
|
36
|
+
- 重复计算
|
|
37
|
+
|
|
38
|
+
2. **空间复杂度问题**
|
|
39
|
+
- 内存泄漏
|
|
40
|
+
- 大对象频繁创建
|
|
41
|
+
- 缓存滥用
|
|
42
|
+
|
|
43
|
+
3. **I/O 阻塞**
|
|
44
|
+
- 同步 I/O 操作
|
|
45
|
+
- 未使用连接池
|
|
46
|
+
- 缺少缓存机制
|
|
47
|
+
|
|
48
|
+
4. **渲染性能**
|
|
49
|
+
- 不必要的重渲染
|
|
50
|
+
- 大列表未虚拟化
|
|
51
|
+
- 图片未优化
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 性能优化指南
|
|
56
|
+
|
|
57
|
+
### 1️⃣ 算法优化
|
|
58
|
+
|
|
59
|
+
**复杂度分析**:
|
|
60
|
+
\`\`\`
|
|
61
|
+
O(1) - 常数时间 ✅ 最优
|
|
62
|
+
O(log n) - 对数时间 ✅ 很好
|
|
63
|
+
O(n) - 线性时间 ✅ 良好
|
|
64
|
+
O(n log n) - 线性对数 ⚠️ 可接受
|
|
65
|
+
O(n²) - 平方时间 ⚠️ 注意
|
|
66
|
+
O(2ⁿ) - 指数时间 ❌ 避免
|
|
67
|
+
O(n!) - 阶乘时间 ❌ 严禁
|
|
68
|
+
\`\`\`
|
|
69
|
+
|
|
70
|
+
**优化技巧**:
|
|
71
|
+
|
|
72
|
+
**示例 1:使用 Map 替代数组查找**
|
|
73
|
+
\`\`\`typescript
|
|
74
|
+
// Before - O(n²)
|
|
75
|
+
function findDuplicates(arr) {
|
|
76
|
+
const duplicates = [];
|
|
77
|
+
for (let i = 0; i < arr.length; i++) {
|
|
78
|
+
for (let j = i + 1; j < arr.length; j++) {
|
|
79
|
+
if (arr[i] === arr[j]) {
|
|
80
|
+
duplicates.push(arr[i]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return duplicates;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// After - O(n)
|
|
88
|
+
function findDuplicates(arr) {
|
|
89
|
+
const seen = new Map();
|
|
90
|
+
const duplicates = new Set();
|
|
91
|
+
|
|
92
|
+
for (const item of arr) {
|
|
93
|
+
if (seen.has(item)) {
|
|
94
|
+
duplicates.add(item);
|
|
95
|
+
} else {
|
|
96
|
+
seen.set(item, true);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return Array.from(duplicates);
|
|
101
|
+
}
|
|
102
|
+
\`\`\`
|
|
103
|
+
|
|
104
|
+
**示例 2:缓存计算结果**
|
|
105
|
+
\`\`\`typescript
|
|
106
|
+
// Before - 重复计算
|
|
107
|
+
function fibonacci(n) {
|
|
108
|
+
if (n <= 1) return n;
|
|
109
|
+
return fibonacci(n - 1) + fibonacci(n - 2);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// After - 使用 memoization
|
|
113
|
+
const memo = new Map();
|
|
114
|
+
function fibonacci(n) {
|
|
115
|
+
if (n <= 1) return n;
|
|
116
|
+
if (memo.has(n)) return memo.get(n);
|
|
117
|
+
|
|
118
|
+
const result = fibonacci(n - 1) + fibonacci(n - 2);
|
|
119
|
+
memo.set(n, result);
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
\`\`\`
|
|
123
|
+
|
|
124
|
+
### 2️⃣ 内存优化
|
|
125
|
+
|
|
126
|
+
**避免内存泄漏**:
|
|
127
|
+
\`\`\`typescript
|
|
128
|
+
// ❌ 内存泄漏
|
|
129
|
+
class EventManager {
|
|
130
|
+
listeners = [];
|
|
131
|
+
|
|
132
|
+
addEventListener(listener) {
|
|
133
|
+
this.listeners.push(listener);
|
|
134
|
+
// 忘记移除监听器
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ✅ 正确做法
|
|
139
|
+
class EventManager {
|
|
140
|
+
listeners = new Set();
|
|
141
|
+
|
|
142
|
+
addEventListener(listener) {
|
|
143
|
+
this.listeners.add(listener);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
removeEventListener(listener) {
|
|
147
|
+
this.listeners.delete(listener);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
destroy() {
|
|
151
|
+
this.listeners.clear();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
\`\`\`
|
|
155
|
+
|
|
156
|
+
**对象池复用**:
|
|
157
|
+
\`\`\`typescript
|
|
158
|
+
// ❌ 频繁创建对象
|
|
159
|
+
for (let i = 0; i < 10000; i++) {
|
|
160
|
+
const obj = { x: i, y: i * 2 };
|
|
161
|
+
process(obj);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// ✅ 对象池
|
|
165
|
+
class ObjectPool {
|
|
166
|
+
pool = [];
|
|
167
|
+
|
|
168
|
+
acquire() {
|
|
169
|
+
return this.pool.pop() || {};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
release(obj) {
|
|
173
|
+
this.pool.push(obj);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const pool = new ObjectPool();
|
|
178
|
+
for (let i = 0; i < 10000; i++) {
|
|
179
|
+
const obj = pool.acquire();
|
|
180
|
+
obj.x = i;
|
|
181
|
+
obj.y = i * 2;
|
|
182
|
+
process(obj);
|
|
183
|
+
pool.release(obj);
|
|
184
|
+
}
|
|
185
|
+
\`\`\`
|
|
186
|
+
|
|
187
|
+
### 3️⃣ React 性能优化
|
|
188
|
+
|
|
189
|
+
**useMemo 和 useCallback**:
|
|
190
|
+
\`\`\`typescript
|
|
191
|
+
// ❌ 每次渲染都创建新函数
|
|
192
|
+
function MyComponent({ data }) {
|
|
193
|
+
const processedData = expensiveComputation(data);
|
|
194
|
+
const handleClick = () => { /* ... */ };
|
|
195
|
+
|
|
196
|
+
return <ChildComponent data={processedData} onClick={handleClick} />;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// ✅ 使用 hooks 优化
|
|
200
|
+
function MyComponent({ data }) {
|
|
201
|
+
const processedData = useMemo(
|
|
202
|
+
() => expensiveComputation(data),
|
|
203
|
+
[data]
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
const handleClick = useCallback(() => {
|
|
207
|
+
/* ... */
|
|
208
|
+
}, []);
|
|
209
|
+
|
|
210
|
+
return <ChildComponent data={processedData} onClick={handleClick} />;
|
|
211
|
+
}
|
|
212
|
+
\`\`\`
|
|
213
|
+
|
|
214
|
+
**React.memo 避免重渲染**:
|
|
215
|
+
\`\`\`typescript
|
|
216
|
+
// ✅ 使用 memo
|
|
217
|
+
const ChildComponent = React.memo(({ data, onClick }) => {
|
|
218
|
+
return <div onClick={onClick}>{data}</div>;
|
|
219
|
+
});
|
|
220
|
+
\`\`\`
|
|
221
|
+
|
|
222
|
+
**虚拟列表**:
|
|
223
|
+
\`\`\`typescript
|
|
224
|
+
// ❌ 渲染 10000 个元素
|
|
225
|
+
function List({ items }) {
|
|
226
|
+
return (
|
|
227
|
+
<div>
|
|
228
|
+
{items.map(item => <Item key={item.id} data={item} />)}
|
|
229
|
+
</div>
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// ✅ 使用虚拟列表
|
|
234
|
+
import { FixedSizeList } from 'react-window';
|
|
235
|
+
|
|
236
|
+
function List({ items }) {
|
|
237
|
+
return (
|
|
238
|
+
<FixedSizeList
|
|
239
|
+
height={600}
|
|
240
|
+
itemCount={items.length}
|
|
241
|
+
itemSize={50}
|
|
242
|
+
>
|
|
243
|
+
{({ index, style }) => (
|
|
244
|
+
<div style={style}>
|
|
245
|
+
<Item data={items[index]} />
|
|
246
|
+
</div>
|
|
247
|
+
)}
|
|
248
|
+
</FixedSizeList>
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
\`\`\`
|
|
252
|
+
|
|
253
|
+
### 4️⃣ 数据库优化
|
|
254
|
+
|
|
255
|
+
**添加索引**:
|
|
256
|
+
\`\`\`sql
|
|
257
|
+
-- Before
|
|
258
|
+
SELECT * FROM users WHERE email = 'user@example.com';
|
|
259
|
+
|
|
260
|
+
-- After
|
|
261
|
+
CREATE INDEX idx_users_email ON users(email);
|
|
262
|
+
SELECT * FROM users WHERE email = 'user@example.com';
|
|
263
|
+
\`\`\`
|
|
264
|
+
|
|
265
|
+
**查询优化**:
|
|
266
|
+
\`\`\`typescript
|
|
267
|
+
// ❌ N+1 查询
|
|
268
|
+
const users = await User.findAll();
|
|
269
|
+
for (const user of users) {
|
|
270
|
+
user.posts = await Post.findAll({ where: { userId: user.id } });
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// ✅ 使用 JOIN
|
|
274
|
+
const users = await User.findAll({
|
|
275
|
+
include: [{ model: Post }]
|
|
276
|
+
});
|
|
277
|
+
\`\`\`
|
|
278
|
+
|
|
279
|
+
**批量操作**:
|
|
280
|
+
\`\`\`typescript
|
|
281
|
+
// ❌ 逐条插入
|
|
282
|
+
for (const item of items) {
|
|
283
|
+
await db.insert(item);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// ✅ 批量插入
|
|
287
|
+
await db.insertMany(items);
|
|
288
|
+
\`\`\`
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## 性能测试
|
|
293
|
+
|
|
294
|
+
### Benchmark 测试
|
|
295
|
+
\`\`\`typescript
|
|
296
|
+
console.time('operation');
|
|
297
|
+
// 执行操作
|
|
298
|
+
console.timeEnd('operation');
|
|
299
|
+
|
|
300
|
+
// 或使用 performance API
|
|
301
|
+
const start = performance.now();
|
|
302
|
+
// 执行操作
|
|
303
|
+
const end = performance.now();
|
|
304
|
+
console.log(\`耗时: \${end - start}ms\`);
|
|
305
|
+
\`\`\`
|
|
306
|
+
|
|
307
|
+
### 性能指标
|
|
308
|
+
|
|
309
|
+
**目标值**:
|
|
310
|
+
- 首屏加载:< 1s
|
|
311
|
+
- 交互响应:< 100ms
|
|
312
|
+
- 动画帧率:60 FPS
|
|
313
|
+
- API 响应:< 200ms
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## 性能优化报告模板
|
|
318
|
+
|
|
319
|
+
### 📊 性能分析
|
|
320
|
+
|
|
321
|
+
**当前性能**:
|
|
322
|
+
- 时间复杂度:O(n²)
|
|
323
|
+
- 内存占用:150MB
|
|
324
|
+
- 响应时间:800ms
|
|
325
|
+
|
|
326
|
+
**瓶颈识别**:
|
|
327
|
+
1. 嵌套循环导致复杂度过高
|
|
328
|
+
2. 未缓存计算结果
|
|
329
|
+
3. 数组查找效率低
|
|
330
|
+
|
|
331
|
+
### 🎯 优化方案
|
|
332
|
+
|
|
333
|
+
**方案 1:算法优化**
|
|
334
|
+
- 使用 Map 替代数组
|
|
335
|
+
- 预期提升:70%
|
|
336
|
+
|
|
337
|
+
**方案 2:添加缓存**
|
|
338
|
+
- 使用 memoization
|
|
339
|
+
- 预期提升:50%
|
|
340
|
+
|
|
341
|
+
### 📈 优化效果
|
|
342
|
+
|
|
343
|
+
**优化后性能**:
|
|
344
|
+
- 时间复杂度:O(n)
|
|
345
|
+
- 内存占用:50MB ↓ 67%
|
|
346
|
+
- 响应时间:200ms ↓ 75%
|
|
347
|
+
|
|
348
|
+
---
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## 📤 输出格式要求
|
|
353
|
+
|
|
354
|
+
请严格按以下 JSON 格式输出分析结果:
|
|
355
|
+
|
|
356
|
+
\`\`\`json
|
|
357
|
+
{
|
|
358
|
+
"summary": "性能评估总结(一句话)",
|
|
359
|
+
"overall_score": 70,
|
|
360
|
+
"bottlenecks": [
|
|
361
|
+
{
|
|
362
|
+
"type": "algorithm|memory|io|render|database",
|
|
363
|
+
"severity": "critical|high|medium|low",
|
|
364
|
+
"location": { "file": "文件路径", "line": 25 },
|
|
365
|
+
"current_complexity": "O(n²)",
|
|
366
|
+
"evidence": "问题证据描述",
|
|
367
|
+
"fix": "优化建议",
|
|
368
|
+
"expected_improvement": "70%",
|
|
369
|
+
"fix_example": "优化后代码示例"
|
|
370
|
+
}
|
|
371
|
+
],
|
|
372
|
+
"metrics": {
|
|
373
|
+
"time_complexity": "O(n²)",
|
|
374
|
+
"space_complexity": "O(n)",
|
|
375
|
+
"potential_improvement": "60-80%"
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
\`\`\`
|
|
379
|
+
|
|
380
|
+
## ⚠️ 边界约束
|
|
381
|
+
|
|
382
|
+
- ❌ 仅分析,不自动修改代码
|
|
383
|
+
- ❌ 不执行性能测试(仅静态分析)
|
|
384
|
+
- ❌ 不做精确的性能数值预测
|
|
385
|
+
- ✅ 输出结构化瓶颈清单和优化建议
|
|
386
|
+
|
|
387
|
+
现在请分析代码,提供详细的性能优化建议。`;
|
|
388
|
+
return {
|
|
389
|
+
content: [
|
|
390
|
+
{
|
|
391
|
+
type: "text",
|
|
392
|
+
text: message,
|
|
393
|
+
},
|
|
394
|
+
],
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
catch (error) {
|
|
398
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
399
|
+
return {
|
|
400
|
+
content: [
|
|
401
|
+
{
|
|
402
|
+
type: "text",
|
|
403
|
+
text: `❌ 性能分析失败: ${errorMessage}`,
|
|
404
|
+
},
|
|
405
|
+
],
|
|
406
|
+
isError: true,
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { okStructured } from '../lib/response.js';
|
|
2
2
|
import { createMemoryClient } from '../lib/memory-client.js';
|
|
3
|
+
import { formatReadMemoryAssetText } from '../lib/memory-orchestration.js';
|
|
3
4
|
import { handleToolError } from '../utils/error-handler.js';
|
|
4
5
|
export async function readMemoryAsset(args) {
|
|
5
6
|
try {
|
|
@@ -15,7 +16,7 @@ export async function readMemoryAsset(args) {
|
|
|
15
16
|
if (!asset) {
|
|
16
17
|
return okStructured(`未找到记忆资产: ${assetId}`, { enabled: true, asset: null });
|
|
17
18
|
}
|
|
18
|
-
return okStructured(
|
|
19
|
+
return okStructured(formatReadMemoryAssetText(asset), {
|
|
19
20
|
enabled: true,
|
|
20
21
|
asset,
|
|
21
22
|
});
|
|
@@ -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
|
+
}>;
|