mta-mcp 1.9.0 → 2.2.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 (117) hide show
  1. package/README.md +140 -2
  2. package/build/core/analyzers/eslint.d.ts +51 -0
  3. package/build/core/analyzers/eslint.d.ts.map +1 -0
  4. package/build/core/analyzers/eslint.js +259 -0
  5. package/build/core/analyzers/eslint.js.map +1 -0
  6. package/build/core/analyzers/index.d.ts +9 -0
  7. package/build/core/analyzers/index.d.ts.map +1 -0
  8. package/build/core/analyzers/index.js +9 -0
  9. package/build/core/analyzers/index.js.map +1 -0
  10. package/build/core/analyzers/registry.d.ts +59 -0
  11. package/build/core/analyzers/registry.d.ts.map +1 -0
  12. package/build/core/analyzers/registry.js +241 -0
  13. package/build/core/analyzers/registry.js.map +1 -0
  14. package/build/core/analyzers/tsconfig.d.ts +45 -0
  15. package/build/core/analyzers/tsconfig.d.ts.map +1 -0
  16. package/build/core/analyzers/tsconfig.js +197 -0
  17. package/build/core/analyzers/tsconfig.js.map +1 -0
  18. package/build/core/analyzers/types.d.ts +176 -0
  19. package/build/core/analyzers/types.d.ts.map +1 -0
  20. package/build/core/analyzers/types.js +39 -0
  21. package/build/core/analyzers/types.js.map +1 -0
  22. package/build/core/analyzers/vite.d.ts +46 -0
  23. package/build/core/analyzers/vite.d.ts.map +1 -0
  24. package/build/core/analyzers/vite.js +211 -0
  25. package/build/core/analyzers/vite.js.map +1 -0
  26. package/build/core/enhancedProjectAnalyzer.d.ts +102 -0
  27. package/build/core/enhancedProjectAnalyzer.d.ts.map +1 -0
  28. package/build/core/enhancedProjectAnalyzer.js +312 -0
  29. package/build/core/enhancedProjectAnalyzer.js.map +1 -0
  30. package/build/core/errors.d.ts +84 -0
  31. package/build/core/errors.d.ts.map +1 -0
  32. package/build/core/errors.js +151 -0
  33. package/build/core/errors.js.map +1 -0
  34. package/build/core/index.d.ts +11 -0
  35. package/build/core/index.d.ts.map +1 -0
  36. package/build/core/index.js +14 -0
  37. package/build/core/index.js.map +1 -0
  38. package/build/core/logger.d.ts +91 -0
  39. package/build/core/logger.d.ts.map +1 -0
  40. package/build/core/logger.js +164 -0
  41. package/build/core/logger.js.map +1 -0
  42. package/build/core/mappings/index.d.ts +5 -0
  43. package/build/core/mappings/index.d.ts.map +1 -0
  44. package/build/core/mappings/index.js +5 -0
  45. package/build/core/mappings/index.js.map +1 -0
  46. package/build/core/mappings/scenarioMappings.d.ts +51 -0
  47. package/build/core/mappings/scenarioMappings.d.ts.map +1 -0
  48. package/build/core/mappings/scenarioMappings.js +105 -0
  49. package/build/core/mappings/scenarioMappings.js.map +1 -0
  50. package/build/core/matching/index.d.ts +8 -0
  51. package/build/core/matching/index.d.ts.map +1 -0
  52. package/build/core/matching/index.js +8 -0
  53. package/build/core/matching/index.js.map +1 -0
  54. package/build/core/matching/intentAnalyzer.d.ts +78 -0
  55. package/build/core/matching/intentAnalyzer.d.ts.map +1 -0
  56. package/build/core/matching/intentAnalyzer.js +255 -0
  57. package/build/core/matching/intentAnalyzer.js.map +1 -0
  58. package/build/core/matching/standardMatcher.d.ts +101 -0
  59. package/build/core/matching/standardMatcher.d.ts.map +1 -0
  60. package/build/core/matching/standardMatcher.js +299 -0
  61. package/build/core/matching/standardMatcher.js.map +1 -0
  62. package/build/core/matching/weights.d.ts +64 -0
  63. package/build/core/matching/weights.d.ts.map +1 -0
  64. package/build/core/matching/weights.js +334 -0
  65. package/build/core/matching/weights.js.map +1 -0
  66. package/build/core/scenarioDetector.d.ts +2 -0
  67. package/build/core/scenarioDetector.d.ts.map +1 -0
  68. package/build/core/scenarioDetector.js +2 -0
  69. package/build/core/scenarioDetector.js.map +1 -0
  70. package/build/core/templates/discovery.d.ts +41 -0
  71. package/build/core/templates/discovery.d.ts.map +1 -0
  72. package/build/core/templates/discovery.js +262 -0
  73. package/build/core/templates/discovery.js.map +1 -0
  74. package/build/core/templates/types.d.ts +80 -0
  75. package/build/core/templates/types.d.ts.map +1 -0
  76. package/build/core/templates/types.js +10 -0
  77. package/build/core/templates/types.js.map +1 -0
  78. package/build/core/types.d.ts +2 -0
  79. package/build/core/types.d.ts.map +1 -1
  80. package/build/core/types.js +4 -3
  81. package/build/core/types.js.map +1 -1
  82. package/build/index.js +136 -23
  83. package/build/index.js.map +1 -1
  84. package/build/tools/getStandardById.d.ts +42 -0
  85. package/build/tools/getStandardById.d.ts.map +1 -0
  86. package/build/tools/getStandardById.js +289 -0
  87. package/build/tools/getStandardById.js.map +1 -0
  88. package/build/tools/getTemplate.d.ts +37 -0
  89. package/build/tools/getTemplate.d.ts.map +1 -0
  90. package/build/tools/getTemplate.js +78 -0
  91. package/build/tools/getTemplate.js.map +1 -0
  92. package/build/tools/listTemplates.d.ts +41 -0
  93. package/build/tools/listTemplates.d.ts.map +1 -0
  94. package/build/tools/listTemplates.js +81 -0
  95. package/build/tools/listTemplates.js.map +1 -0
  96. package/build/tools/queryMappings.d.ts +55 -0
  97. package/build/tools/queryMappings.d.ts.map +1 -0
  98. package/build/tools/queryMappings.js +119 -0
  99. package/build/tools/queryMappings.js.map +1 -0
  100. package/package.json +25 -8
  101. package/src/core/autoInitializer.ts +0 -170
  102. package/src/core/codeValidator.ts +0 -357
  103. package/src/core/githubClient.ts +0 -64
  104. package/src/core/i18nDetector.ts +0 -357
  105. package/src/core/smartAgentMatcher.ts +0 -490
  106. package/src/core/standardsManager.ts +0 -769
  107. package/src/core/types.ts +0 -72
  108. package/src/index.ts +0 -519
  109. package/src/tools/analyzeProject.ts +0 -94
  110. package/src/tools/autoSetup.ts +0 -312
  111. package/src/tools/generateConfig.ts +0 -429
  112. package/src/tools/getCompactStandards.ts +0 -413
  113. package/src/tools/getSmartStandards.ts +0 -225
  114. package/src/tools/healthCheck.ts +0 -261
  115. package/src/tools/listAgents.ts +0 -91
  116. package/src/tools/matchAgents.ts +0 -80
  117. package/src/tools/usePreset.ts +0 -180
@@ -1,429 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import { fileURLToPath } from 'url';
4
- import { GitHubClient } from '../core/githubClient.js';
5
- import { SmartAgentMatcher } from '../core/smartAgentMatcher.js';
6
- import { ConsoleLogger, AgentMetadata } from '../core/types.js';
7
- import { CodeValidator } from '../core/codeValidator.js';
8
-
9
- // ES模块中获取__dirname
10
- const __filename = fileURLToPath(import.meta.url);
11
- const __dirname = path.dirname(__filename);
12
-
13
- /**
14
- * 生成配置文件工具
15
- */
16
- export async function generateConfig(args: {
17
- projectPath: string;
18
- agentIds?: string[];
19
- autoMatch?: boolean;
20
- updateMode?: 'merge' | 'overwrite'; // merge: 保留自定义内容, overwrite: 完全覆盖
21
- configId?: string; // 配置方案ID (如 strict)
22
- }): Promise<{
23
- content: Array<{ type: string; text: string }>;
24
- }> {
25
- const logger = new ConsoleLogger();
26
-
27
- try {
28
- // 验证路径
29
- if (!fs.existsSync(args.projectPath)) {
30
- return {
31
- content: [{
32
- type: 'text',
33
- text: JSON.stringify({
34
- error: `项目路径不存在: ${args.projectPath}`
35
- }, null, 2)
36
- }]
37
- };
38
- }
39
-
40
- const matcher = new SmartAgentMatcher(logger);
41
- const githubClient = new GitHubClient(logger);
42
-
43
- let selectedAgents: AgentMetadata[] = [];
44
-
45
- // 如果需要自动匹配
46
- if (args.autoMatch !== false) {
47
- logger.log('正在分析项目特征...');
48
-
49
- const workspaceFolder = {
50
- uri: { fsPath: args.projectPath },
51
- name: path.basename(args.projectPath),
52
- index: 0
53
- };
54
-
55
- const features = await matcher.analyzeProject(workspaceFolder as any);
56
-
57
- logger.log('正在匹配 Agents...');
58
-
59
- // 获取可用 Agents - 优先从 GitHub 获取(保证最新版本)
60
- const availableAgents: AgentMetadata[] = [];
61
-
62
- try {
63
- logger.log('📡 从 GitHub 获取 Agents...');
64
- const agentFiles = await githubClient.listDirectoryFiles('agents');
65
-
66
- for (const file of agentFiles) {
67
- if (file.name.endsWith('.agent.md')) {
68
- try {
69
- const content = await githubClient.fetchFileContent(file.path);
70
- const metadata = matcher.parseAgentMetadata(file.path, content);
71
- availableAgents.push(metadata);
72
- logger.log(`✅ 加载 Agent: ${metadata.title}`);
73
- } catch (error) {
74
- logger.error(`解析 ${file.name} 失败`);
75
- }
76
- }
77
- }
78
- logger.log(`✅ 从 GitHub 成功加载 ${availableAgents.length} 个 Agents`);
79
- } catch (githubError) {
80
- // GitHub 失败时尝试本地
81
- logger.log('⚠️ GitHub 获取失败,尝试从本地加载...');
82
- const agentsDir = path.join(__dirname, '../../../agents');
83
-
84
- if (fs.existsSync(agentsDir)) {
85
- const agentFiles = fs.readdirSync(agentsDir);
86
- logger.log(`找到 ${agentFiles.length} 个本地文件`);
87
-
88
- for (const file of agentFiles) {
89
- if (file.endsWith('.agent.md')) {
90
- try {
91
- const filePath = path.join(agentsDir, file);
92
- const content = fs.readFileSync(filePath, 'utf-8');
93
- const metadata = matcher.parseAgentMetadata(`agents/${file}`, content);
94
- availableAgents.push(metadata);
95
- logger.log(`✅ 加载 Agent: ${metadata.title}`);
96
- } catch (error) {
97
- logger.error(`解析 ${file} 失败`);
98
- }
99
- }
100
- }
101
- logger.log(`✅ 从本地成功加载 ${availableAgents.length} 个 Agents`);
102
- } else {
103
- throw new Error('无法从 GitHub 或本地获取 Agents');
104
- }
105
- }
106
-
107
- logger.log(`成功加载 ${availableAgents.length} 个 Agents`);
108
- selectedAgents = matcher.matchAgents(features, availableAgents);
109
- logger.log(`匹配到 ${selectedAgents.length} 个 Agents`);
110
- selectedAgents = selectedAgents.slice(0, 5); // 取前5个
111
- }
112
-
113
- // 如果指定了 agentIds,使用指定的
114
- if (args.agentIds && args.agentIds.length > 0) {
115
- logger.log(`使用指定的 Agents: ${args.agentIds.join(', ')}`);
116
-
117
- selectedAgents = [];
118
-
119
- for (const id of args.agentIds) {
120
- try {
121
- let content: string;
122
- const agentPath = `agents/${id}.agent.md`;
123
-
124
- // 优先从 GitHub 加载(保证最新版本)
125
- try {
126
- logger.log(`从 GitHub 获取 Agent: ${id}`);
127
- content = await githubClient.fetchFileContent(agentPath);
128
- logger.log(`✅ 从 GitHub 加载成功: ${id}`);
129
- } catch (githubError) {
130
- // GitHub 失败时尝试本地
131
- logger.log(`GitHub 获取失败,尝试本地: ${id}`);
132
- const agentsDir = path.join(__dirname, '../../../agents');
133
- const localPath = path.join(agentsDir, `${id}.agent.md`);
134
-
135
- if (fs.existsSync(localPath)) {
136
- content = fs.readFileSync(localPath, 'utf-8');
137
- logger.log(`✅ 从本地加载成功: ${id}`);
138
- } else {
139
- throw new Error(`Agent ${id} 不存在(GitHub 和本地都未找到)`);
140
- }
141
- }
142
-
143
- const metadata = matcher.parseAgentMetadata(`agents/${id}.agent.md`, content);
144
- selectedAgents.push(metadata);
145
- } catch (error) {
146
- logger.error(`获取 Agent ${id} 失败: ${error}`);
147
- }
148
- }
149
- }
150
-
151
- if (selectedAgents.length === 0) {
152
- return {
153
- content: [{
154
- type: 'text',
155
- text: JSON.stringify({
156
- error: '未找到合适的 Agents'
157
- }, null, 2)
158
- }]
159
- };
160
- }
161
-
162
- // 生成配置文件
163
- logger.log('正在生成配置文件...');
164
-
165
- const githubDir = path.join(args.projectPath, '.github');
166
- const configPath = path.join(githubDir, 'copilot-instructions.md');
167
-
168
- // 检测已有配置的自定义内容
169
- let existingCustomContent = '';
170
- let existingConfig = '';
171
- if (fs.existsSync(configPath)) {
172
- existingConfig = fs.readFileSync(configPath, 'utf-8');
173
-
174
- // 提取自定义章节(标记为 CUSTOM 的内容)
175
- const customMatch = existingConfig.match(/<!-- CUSTOM_START -->([\s\S]*?)<!-- CUSTOM_END -->/g);
176
- if (customMatch) {
177
- existingCustomContent = customMatch.join('\n\n');
178
- }
179
- }
180
-
181
- // 创建目录
182
- if (!fs.existsSync(githubDir)) {
183
- fs.mkdirSync(githubDir, { recursive: true });
184
- }
185
-
186
- const updateMode = args.updateMode || 'merge'; // 默认保护模式
187
-
188
- // 构建配置内容
189
- let content = '';
190
-
191
- if (updateMode === 'merge') {
192
- content += `<!-- ⚠️ 此文件由 Copilot Prompts MCP Server 生成 -->\n`;
193
- content += `<!-- ℹ️ 你可以添加自定义内容,使用 CUSTOM_START/CUSTOM_END 标记保护 -->\n`;
194
- content += `<!-- 示例: -->\n`;
195
- content += `<!-- CUSTOM_START -->\n`;
196
- content += `<!-- 你的自定义规范 -->\n`;
197
- content += `<!-- CUSTOM_END -->\n\n`;
198
- } else {
199
- content += `<!-- ⚠️ 此文件由 Copilot Prompts MCP Server 自动生成 -->\n`;
200
- content += `<!-- ⚠️ 使用 --update-mode merge 可保护自定义内容 -->\n\n`;
201
- }
202
-
203
- // 添加作用域声明 - 防止跨项目污染
204
- const projectName = path.basename(args.projectPath);
205
- const projectPath = args.projectPath;
206
-
207
- content += `<!-- 🎯 作用域:此配置仅适用于当前项目 -->\n`;
208
- content += `<!-- 项目名称: ${projectName} -->\n`;
209
- content += `<!-- 项目路径: ${projectPath} -->\n\n`;
210
-
211
- content += `# 项目开发规范 - Copilot 指令\n\n`;
212
-
213
- // ⚠️ 强制执行检查点 - 必须在最前面
214
- content += `## ⚠️ 强制执行检查点\n\n`;
215
- content += `> **此检查点的优先级高于本文件的所有其他内容**\n\n`;
216
- content += `在执行**任何**以下操作前,必须先完成规范加载验证:\n\n`;
217
- content += `### 受限操作清单\n\n`;
218
- content += `- ❌ 创建任何代码文件(.vue、.ts、.tsx、.js 等)\n`;
219
- content += `- ❌ 修改任何代码文件\n`;
220
- content += `- ❌ 使用 \`replace_string_in_file\` 或 \`multi_replace_string_in_file\`\n`;
221
- content += `- ❌ 生成任何代码片段\n\n`;
222
- content += `### 强制验证流程\n\n`;
223
- content += `1. **检查项目作用域** - 确认当前操作的文件路径包含 \`/${projectName}/\`\n`;
224
- content += `2. **加载相关规范** - 根据文件类型调用对应的 MCP 工具:\n`;
225
- content += ` - Vue 文件 → \`get_smart_standards\` 或 \`use_preset\`\n`;
226
- content += ` - TypeScript 文件 → \`get_smart_standards\` 或 \`use_preset\`\n`;
227
- content += ` - 其他文件 → 根据实际情况选择\n`;
228
- content += `3. **验证加载成功** - 确认工具返回了规范内容\n`;
229
- content += `4. **声明已加载** - 在响应中明确说明:\`✅ 已加载规范: [工具名称]\`\n\n`;
230
- content += `### 违规处理\n\n`;
231
- content += `- 如果未加载规范就生成代码 → **此操作无效,必须重新执行**\n`;
232
- content += `- 如果出现语法错误 → **深刻反思,检查是否遵循了规范**\n`;
233
- content += `- 如果出现低级错误 → **停止操作,重新加载规范后再继续**\n\n`;
234
- content += `---\n\n`;
235
-
236
- // 添加AI可识别的作用域限制
237
- content += `## 🎯 作用域限制\n\n`;
238
- content += `**⚠️ 此配置仅在以下情况生效:**\n\n`;
239
- content += `1. 当前编辑的文件路径包含: \`/${projectName}/\`\n`;
240
- content += `2. 或当前工作目录为: \`${projectPath}\`\n\n`;
241
- content += `**如果你在其他项目工作(如 ${projectName} 之外的项目),请完全忽略此配置文件中的所有规范和指令。**\n\n`;
242
- content += `---\n\n`;
243
-
244
- content += `> 📌 **自动配置信息**\n`;
245
- content += `> - 生成时间: ${new Date().toLocaleString('zh-CN')}\n`;
246
- content += `> - 匹配的 Agents: ${selectedAgents.length} 个\n\n`;
247
- content += `---\n\n`;
248
-
249
- // 加载配置方案的详细规则
250
- if (args.configId) {
251
- try {
252
- const configFilePath = path.join(__dirname, '../../../configs', `element-plus-${args.configId}.json`);
253
- if (fs.existsSync(configFilePath)) {
254
- const configData = JSON.parse(fs.readFileSync(configFilePath, 'utf-8'));
255
-
256
- content += `## 📦 配置方案\n\n`;
257
- content += `**方案ID**: ${configData.configId}\n`;
258
- content += `**名称**: ${configData.name}\n`;
259
- content += `**描述**: ${configData.description}\n`;
260
- content += `**维护者**: ${configData.maintainer}\n\n`;
261
-
262
- // 添加重要规则摘要
263
- if (configData.rules && configData.rules.table) {
264
- content += `### 表格组件规范\n\n`;
265
- const tableRules = configData.rules.table;
266
- if (tableRules.border) content += `- ✅ **必须添加 border**\n`;
267
- if (tableRules['highlight-current-row']) content += `- ✅ **必须高亮当前行**\n`;
268
- if (tableRules['v-loading']) content += `- ✅ **加载状态变量**: \`${tableRules['v-loading'].variable}\`\n`;
269
- content += `\n`;
270
- }
271
-
272
- content += `> 详细规则请参考: \`configs/element-plus-${args.configId}.json\`\n\n`;
273
- content += `---\n\n`;
274
-
275
- logger.log(`✅ 已加载配置方案: ${configData.name}`);
276
- }
277
- } catch (error) {
278
- logger.error(`加载配置方案失败: ${error}`);
279
- }
280
- }
281
-
282
- // 添加强制工作流说明
283
- content += `## ⚠️ 强制工作流\n\n`;
284
- content += `**在进行任何代码生成或修改之前,必须先调用 MCP 工具加载相关规范!**\n\n`;
285
- content += `根据文件类型和场景,调用相应的 MCP 工具:\n\n`;
286
- content += `1. **Vue 文件** → \`get_relevant_standards({ fileType: "vue" })\`\n`;
287
- content += `2. **TypeScript 文件** → \`get_relevant_standards({ fileType: "ts" })\`\n`;
288
- content += `3. **React 组件** → \`get_relevant_standards({ fileType: "tsx" })\`\n`;
289
- content += `4. **使用特定库时**:\n`;
290
- content += ` - Element Plus: \`get_relevant_standards({ imports: ["element-plus"] })\`\n`;
291
- content += ` - Pinia: \`get_relevant_standards({ imports: ["pinia"] })\`\n`;
292
- content += ` - Vue Router: \`get_relevant_standards({ imports: ["vue-router"] })\`\n`;
293
- content += ` - LogicFlow: \`get_relevant_standards({ imports: ["@logicflow/core"] })\`\n`;
294
- content += `5. **特定场景**:\n`;
295
- content += ` - API 调用: \`get_relevant_standards({ scenario: "API 调用" })\`\n`;
296
- content += ` - 国际化: \`get_relevant_standards({ scenario: "国际化" })\`\n\n`;
297
- content += `### 标准流程\n\n`;
298
- content += `1. ✅ **强制**: 加载规范 → 2. 理解需求 → 3. 编写代码 → 4. 验证规范\n\n`;
299
- content += `---\n\n`;
300
-
301
- // ⚠️ 核心设计原则:最小化配置 (选项 1)
302
- // 只记录 Agent 引用信息,不嵌入完整内容
303
- // Copilot 将通过 MCP 工具 get_relevant_standards 实时加载规范
304
- // 此设计为底层逻辑,除非明确要求,否则不可修改
305
-
306
- content += `## 📚 配置的 Agents\n\n`;
307
- content += `本项目使用以下 Agents(规范内容由 Copilot 通过 MCP 工具实时加载):\n\n`;
308
-
309
- for (const agent of selectedAgents) {
310
- content += `### ${agent.title}\n\n`;
311
- content += `- **Agent ID**: \`${agent.id}\`\n`;
312
- content += `- **描述**: ${agent.description || '暂无描述'}\n`;
313
- content += `- **来源**: \`${agent.path}\`\n`;
314
-
315
- // 如果有标签,显示标签
316
- if (agent.tags && agent.tags.length > 0) {
317
- content += `- **标签**: ${agent.tags.join(', ')}\n`;
318
- }
319
-
320
- content += `\n> 💡 **使用方式**: 在开发时,Copilot 会自动通过 MCP 工具加载此 Agent 的完整规范。\n\n`;
321
- }
322
-
323
- content += `---\n\n`;
324
-
325
- // 附加自定义内容(如果是merge模式)
326
- if (updateMode === 'merge' && existingCustomContent) {
327
- content += `\n\n## 📝 自定义规范\n\n`;
328
- content += existingCustomContent;
329
- logger.log('✅ 已保留自定义内容');
330
- }
331
-
332
- // 写入文件前进行验证 (v1.1.0)
333
- const validator = new CodeValidator(logger);
334
- const validation = validator.validateConfigContent(content);
335
-
336
- if (!validation.isValid) {
337
- logger.error('⚠️ 配置内容验证失败,尝试自动修复...');
338
-
339
- // 尝试自动修复
340
- const fixResult = validator.attemptAutoFix(content);
341
- if (fixResult.fixed) {
342
- content = fixResult.content;
343
- logger.log(`✅ 已自动修复 ${fixResult.changes.length} 个问题:`);
344
- fixResult.changes.forEach(change => logger.log(` - ${change}`));
345
-
346
- // 重新验证
347
- const revalidation = validator.validateConfigContent(content);
348
- if (!revalidation.isValid) {
349
- const report = validator.generateValidationReport(revalidation);
350
- logger.error('❌ 自动修复后仍存在问题:');
351
- logger.error(report);
352
-
353
- return {
354
- content: [{
355
- type: 'text',
356
- text: JSON.stringify({
357
- error: '配置文件验证失败',
358
- validationReport: report,
359
- message: '生成的配置文件存在语法错误,请检查并手动修复'
360
- }, null, 2)
361
- }]
362
- };
363
- }
364
- } else {
365
- const report = validator.generateValidationReport(validation);
366
- logger.error(report);
367
-
368
- return {
369
- content: [{
370
- type: 'text',
371
- text: JSON.stringify({
372
- error: '配置文件验证失败',
373
- validationReport: report,
374
- message: '生成的配置文件存在语法错误且无法自动修复'
375
- }, null, 2)
376
- }]
377
- };
378
- }
379
- } else if (validation.warnings.length > 0) {
380
- logger.log('⚠️ 配置内容验证通过,但有以下警告:');
381
- validation.warnings.forEach(warning => {
382
- logger.log(` - [${warning.type}] ${warning.message}`);
383
- });
384
- } else {
385
- logger.log('✅ 配置内容验证通过');
386
- }
387
-
388
- // 写入文件
389
- fs.writeFileSync(configPath, content, 'utf-8');
390
-
391
- // 更新 .gitignore
392
- const gitignorePath = path.join(args.projectPath, '.gitignore');
393
- if (fs.existsSync(gitignorePath)) {
394
- let gitignoreContent = fs.readFileSync(gitignorePath, 'utf-8');
395
- if (!gitignoreContent.includes('.github/copilot-instructions.md')) {
396
- gitignoreContent += '\n# Copilot Prompts (auto-generated)\n.github/copilot-instructions.md\n';
397
- fs.writeFileSync(gitignorePath, gitignoreContent, 'utf-8');
398
- }
399
- }
400
-
401
- logger.log(`✅ 配置文件已生成: ${configPath}`);
402
-
403
- return {
404
- content: [{
405
- type: 'text',
406
- text: JSON.stringify({
407
- success: true,
408
- configPath,
409
- agents: selectedAgents.map(a => ({
410
- id: a.id,
411
- title: a.title,
412
- score: a.score
413
- })),
414
- message: `已成功生成配置文件,应用了 ${selectedAgents.length} 个 Agents`
415
- }, null, 2)
416
- }]
417
- };
418
- } catch (error) {
419
- logger.error(`生成配置失败: ${error}`);
420
- return {
421
- content: [{
422
- type: 'text',
423
- text: JSON.stringify({
424
- error: error instanceof Error ? error.message : String(error)
425
- }, null, 2)
426
- }]
427
- };
428
- }
429
- }