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,261 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import { fileURLToPath } from 'url';
4
- import { ConsoleLogger } from '../core/types.js';
5
-
6
- // ES 模块中获取 __dirname
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = path.dirname(__filename);
9
-
10
- /**
11
- * 健康检查工具
12
- * 诊断 MCP 服务器配置和运行状态
13
- */
14
- export async function healthCheck(args: {
15
- workspacePath?: string;
16
- verbose?: boolean;
17
- }): Promise<{
18
- content: Array<{ type: string; text: string }>;
19
- }> {
20
- const logger = new ConsoleLogger();
21
- const verbose = args.verbose ?? false;
22
-
23
- try {
24
- const checks = {
25
- server: { status: 'unknown', details: [] as string[] },
26
- configuration: { status: 'unknown', details: [] as string[] },
27
- dependencies: { status: 'unknown', details: [] as string[] },
28
- standards: { status: 'unknown', details: [] as string[] },
29
- workspace: { status: 'unknown', details: [] as string[] }
30
- };
31
-
32
- // Check 1: 服务器运行状态
33
- logger.log('🔍 检查服务器状态...');
34
- try {
35
- checks.server.status = 'healthy';
36
- checks.server.details.push('✅ MCP 服务器正在运行');
37
- checks.server.details.push(`📍 进程 PID: ${process.pid}`);
38
- checks.server.details.push(`🕐 运行时间: ${Math.floor(process.uptime())}秒`);
39
- } catch {
40
- checks.server.status = 'error';
41
- checks.server.details.push('❌ 服务器未响应');
42
- }
43
-
44
- // Check 2: 配置文件
45
- logger.log('🔍 检查配置文件...');
46
- const workspacePath = args.workspacePath || process.cwd();
47
- const vscodeDir = path.join(workspacePath, '.vscode');
48
-
49
- if (fs.existsSync(vscodeDir)) {
50
- checks.workspace.status = 'healthy';
51
- checks.workspace.details.push(`✅ 工作区路径: ${workspacePath}`);
52
-
53
- // mcp.json
54
- const mcpJsonPath = path.join(vscodeDir, 'mcp.json');
55
- if (fs.existsSync(mcpJsonPath)) {
56
- try {
57
- const config = JSON.parse(fs.readFileSync(mcpJsonPath, 'utf-8'));
58
-
59
- // 检查新格式 (servers) 和旧格式 (mcpServers)
60
- const hasNewFormat = config.servers?.['copilot-prompts'];
61
- const hasOldFormat = config.mcpServers?.['copilot-prompts'];
62
-
63
- if (hasNewFormat) {
64
- checks.configuration.status = 'healthy';
65
- checks.configuration.details.push('✅ mcp.json 配置正确 (使用新格式)');
66
-
67
- const serverConfig = config.servers['copilot-prompts'];
68
- if (verbose) {
69
- checks.configuration.details.push(` Command: ${serverConfig.command}`);
70
- checks.configuration.details.push(` Args: ${serverConfig.args?.join(' ')}`);
71
- checks.configuration.details.push(` AutoStart: ${serverConfig.autoStart ?? 'undefined'}`);
72
- checks.configuration.details.push(` Env: ${JSON.stringify(serverConfig.env ?? {})}`);
73
- }
74
-
75
- // 检查是否包含推荐字段
76
- if (!serverConfig.env) {
77
- checks.configuration.details.push('💡 建议: 添加 "env": {} 字段');
78
- }
79
- if (!serverConfig.autoStart) {
80
- checks.configuration.details.push('💡 建议: 添加 "autoStart": true 字段');
81
- }
82
- } else if (hasOldFormat) {
83
- checks.configuration.status = 'warning';
84
- checks.configuration.details.push('⚠️ mcp.json 使用旧格式 (mcpServers)');
85
- checks.configuration.details.push('💡 建议: 运行 auto_setup 工具升级到新格式 (servers)');
86
-
87
- if (verbose) {
88
- const serverConfig = config.mcpServers['copilot-prompts'];
89
- checks.configuration.details.push(` Command: ${serverConfig.command}`);
90
- checks.configuration.details.push(` Args: ${serverConfig.args?.join(' ')}`);
91
- }
92
- } else {
93
- checks.configuration.status = 'warning';
94
- checks.configuration.details.push('⚠️ mcp.json 缺少 copilot-prompts 配置');
95
- checks.configuration.details.push('💡 建议: 运行 auto_setup 工具添加配置');
96
- }
97
- } catch (error) {
98
- checks.configuration.status = 'error';
99
- checks.configuration.details.push(`❌ mcp.json 格式错误: ${error}`);
100
- checks.configuration.details.push('💡 修复: 运行 auto_setup 工具重新生成配置');
101
- }
102
- } else {
103
- checks.configuration.status = 'warning';
104
- checks.configuration.details.push('⚠️ mcp.json 不存在');
105
- checks.configuration.details.push('💡 建议: 运行 auto_setup 工具自动配置');
106
- }
107
-
108
- // settings.json
109
- const settingsPath = path.join(vscodeDir, 'settings.json');
110
- if (fs.existsSync(settingsPath)) {
111
- try {
112
- const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
113
- if (settings['github.copilot.chat.mcp.enabled'] === true) {
114
- checks.configuration.details.push('✅ VS Code MCP 已启用');
115
- } else {
116
- checks.configuration.details.push('⚠️ VS Code MCP 未启用');
117
- }
118
- } catch {
119
- checks.configuration.details.push('⚠️ settings.json 格式错误');
120
- }
121
- }
122
- } else {
123
- checks.workspace.status = 'error';
124
- checks.workspace.details.push('❌ .vscode 目录不存在');
125
- }
126
-
127
- // Check 3: 依赖检查
128
- logger.log('🔍 检查依赖...');
129
- const serverRoot = path.resolve(__dirname, '../..');
130
- const packageJsonPath = path.join(serverRoot, 'package.json');
131
-
132
- if (fs.existsSync(packageJsonPath)) {
133
- try {
134
- const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
135
- checks.dependencies.status = 'healthy';
136
- checks.dependencies.details.push(`✅ 服务器版本: ${pkg.version}`);
137
-
138
- if (verbose && pkg.dependencies) {
139
- const deps = Object.entries(pkg.dependencies).slice(0, 3);
140
- deps.forEach(([name, version]) => {
141
- checks.dependencies.details.push(` ${name}: ${version}`);
142
- });
143
- }
144
-
145
- // 检查关键依赖
146
- const requiredDeps = ['@modelcontextprotocol/sdk'];
147
- const missing = requiredDeps.filter(dep => !pkg.dependencies?.[dep]);
148
- if (missing.length > 0) {
149
- checks.dependencies.status = 'error';
150
- checks.dependencies.details.push(`❌ 缺少依赖: ${missing.join(', ')}`);
151
- }
152
- } catch {
153
- checks.dependencies.status = 'error';
154
- checks.dependencies.details.push('❌ 无法读取 package.json');
155
- }
156
- }
157
-
158
- // Check 4: 规范文件
159
- logger.log('🔍 检查规范文件...');
160
- const standardsDir = path.join(serverRoot, 'standards');
161
-
162
- if (fs.existsSync(standardsDir)) {
163
- const categories = ['core', 'frameworks', 'libraries', 'patterns'];
164
- const foundStandards: string[] = [];
165
-
166
- for (const category of categories) {
167
- const categoryPath = path.join(standardsDir, category);
168
- if (fs.existsSync(categoryPath)) {
169
- const files = fs.readdirSync(categoryPath).filter(f => f.endsWith('.md'));
170
- foundStandards.push(...files.map(f => `${category}/${f}`));
171
- }
172
- }
173
-
174
- if (foundStandards.length > 0) {
175
- checks.standards.status = 'healthy';
176
- checks.standards.details.push(`✅ 找到 ${foundStandards.length} 个规范文件`);
177
- if (verbose) {
178
- foundStandards.slice(0, 5).forEach(s => {
179
- checks.standards.details.push(` 📄 ${s}`);
180
- });
181
- if (foundStandards.length > 5) {
182
- checks.standards.details.push(` ... 还有 ${foundStandards.length - 5} 个文件`);
183
- }
184
- }
185
- } else {
186
- checks.standards.status = 'warning';
187
- checks.standards.details.push('⚠️ 未找到规范文件');
188
- }
189
- } else {
190
- checks.standards.status = 'error';
191
- checks.standards.details.push('❌ standards 目录不存在');
192
- }
193
-
194
- // 生成总体健康状态
195
- const allStatuses = Object.values(checks).map(c => c.status);
196
- const overallStatus = allStatuses.includes('error') ? 'error'
197
- : allStatuses.includes('warning') ? 'warning'
198
- : 'healthy';
199
-
200
- const statusEmoji = {
201
- healthy: '✅',
202
- warning: '⚠️',
203
- error: '❌',
204
- unknown: '❓'
205
- };
206
-
207
- logger.log(`${statusEmoji[overallStatus]} 健康检查完成`);
208
-
209
- return {
210
- content: [{
211
- type: 'text',
212
- text: JSON.stringify({
213
- success: true,
214
- overallStatus,
215
- summary: `${statusEmoji[overallStatus]} MCP 服务器状态: ${overallStatus}`,
216
- checks,
217
- recommendations: generateRecommendations(checks)
218
- }, null, 2)
219
- }]
220
- };
221
- } catch (error) {
222
- logger.error(`健康检查失败: ${error}`);
223
- return {
224
- content: [{
225
- type: 'text',
226
- text: JSON.stringify({
227
- error: error instanceof Error ? error.message : String(error)
228
- }, null, 2)
229
- }]
230
- };
231
- }
232
- }
233
-
234
- /**
235
- * 根据检查结果生成建议
236
- */
237
- function generateRecommendations(checks: any): string[] {
238
- const recommendations: string[] = [];
239
-
240
- if (checks.configuration.status !== 'healthy') {
241
- recommendations.push('🔧 运行 auto_setup 工具自动配置 MCP 服务器');
242
- }
243
-
244
- if (checks.workspace.status === 'error') {
245
- recommendations.push('📁 确保在正确的工作区目录中运行');
246
- }
247
-
248
- if (checks.dependencies.status === 'error') {
249
- recommendations.push('📦 运行 npm install 安装依赖');
250
- }
251
-
252
- if (checks.standards.status !== 'healthy') {
253
- recommendations.push('📚 检查 standards 目录是否存在规范文件');
254
- }
255
-
256
- if (recommendations.length === 0) {
257
- recommendations.push('🎉 一切正常!您可以开始使用 MCP 服务器了');
258
- }
259
-
260
- return recommendations;
261
- }
@@ -1,91 +0,0 @@
1
- import { GitHubClient } from '../core/githubClient.js';
2
- import { ConsoleLogger } from '../core/types.js';
3
-
4
- /**
5
- * 列出所有可用的 Agents
6
- */
7
- export async function listAvailableAgents(): Promise<{
8
- content: Array<{ type: string; text: string }>;
9
- }> {
10
- const logger = new ConsoleLogger();
11
-
12
- try {
13
- const githubClient = new GitHubClient(logger);
14
-
15
- logger.log('正在从 GitHub 获取 Agents 列表...');
16
-
17
- const agentFiles = await githubClient.listDirectoryFiles('agents');
18
- const agents = agentFiles.filter(f => f.name.endsWith('.agent.md'));
19
-
20
- // 获取每个 Agent 的基本信息
21
- const agentList = await Promise.all(
22
- agents.map(async (file) => {
23
- try {
24
- const content = await githubClient.fetchFileContent(file.path);
25
-
26
- // 简单解析标题和描述
27
- const lines = content.split('\n');
28
- let title = file.name.replace('.agent.md', '');
29
- let description = '';
30
-
31
- // 尝试从 frontmatter 提取
32
- if (lines[0] === '---') {
33
- const endIndex = lines.slice(1).findIndex(l => l === '---');
34
- if (endIndex > 0) {
35
- const frontmatter = lines.slice(1, endIndex + 1).join('\n');
36
- const descMatch = frontmatter.match(/description:\s*['"](.+)['"]/);
37
- if (descMatch) {
38
- description = descMatch[1];
39
- }
40
- }
41
- }
42
-
43
- // 提取标题(第一个 # 开头的行)
44
- const titleLine = lines.find(l => l.startsWith('# '));
45
- if (titleLine) {
46
- title = titleLine.replace('# ', '').trim();
47
- }
48
-
49
- return {
50
- id: file.name.replace('.agent.md', ''),
51
- name: file.name,
52
- title,
53
- description: description || '暂无描述',
54
- path: file.path
55
- };
56
- } catch (error) {
57
- logger.error(`解析 ${file.name} 失败: ${error}`);
58
- return null;
59
- }
60
- })
61
- );
62
-
63
- const validAgents = agentList.filter(a => a !== null);
64
-
65
- return {
66
- content: [{
67
- type: 'text',
68
- text: JSON.stringify({
69
- success: true,
70
- total: validAgents.length,
71
- agents: validAgents,
72
- categories: {
73
- general: validAgents.filter(a => a!.path.includes('common/')).length,
74
- frameworks: validAgents.filter(a => a!.path.includes('vue/') || a!.path.includes('react/')).length,
75
- agents: validAgents.filter(a => a!.path.includes('agents/')).length
76
- }
77
- }, null, 2)
78
- }]
79
- };
80
- } catch (error) {
81
- logger.error(`获取 Agents 列表失败: ${error}`);
82
- return {
83
- content: [{
84
- type: 'text',
85
- text: JSON.stringify({
86
- error: error instanceof Error ? error.message : String(error)
87
- }, null, 2)
88
- }]
89
- };
90
- }
91
- }
@@ -1,80 +0,0 @@
1
- import { GitHubClient } from '../core/githubClient.js';
2
- import { SmartAgentMatcher } from '../core/smartAgentMatcher.js';
3
- import { ProjectFeatures, AgentMetadata, ConsoleLogger } from '../core/types.js';
4
-
5
- /**
6
- * 匹配 Agents 工具
7
- */
8
- export async function matchAgents(args: {
9
- projectFeatures: ProjectFeatures;
10
- limit?: number;
11
- }): Promise<{
12
- content: Array<{ type: string; text: string }>;
13
- }> {
14
- const logger = new ConsoleLogger();
15
-
16
- try {
17
- const matcher = new SmartAgentMatcher(logger);
18
- const githubClient = new GitHubClient(logger);
19
-
20
- logger.log('正在从 GitHub 获取可用 Agents...');
21
-
22
- // 获取所有可用的 Agents
23
- const availableAgents: AgentMetadata[] = [];
24
-
25
- try {
26
- const agentFiles = await githubClient.listDirectoryFiles('agents');
27
-
28
- for (const file of agentFiles) {
29
- if (file.name.endsWith('.agent.md')) {
30
- try {
31
- const content = await githubClient.fetchFileContent(file.path);
32
- const metadata = matcher.parseAgentMetadata(file.path, content);
33
- availableAgents.push(metadata);
34
- } catch (error) {
35
- logger.error(`解析 ${file.name} 失败: ${error}`);
36
- }
37
- }
38
- }
39
- } catch (error) {
40
- logger.error(`获取 Agents 失败: ${error}`);
41
- }
42
-
43
- // 匹配 Agents
44
- const matchedAgents = matcher.matchAgents(args.projectFeatures, availableAgents);
45
-
46
- // 限制返回数量
47
- const limit = args.limit || 10;
48
- const topAgents = matchedAgents.slice(0, limit);
49
-
50
- return {
51
- content: [{
52
- type: 'text',
53
- text: JSON.stringify({
54
- success: true,
55
- totalAvailable: availableAgents.length,
56
- matched: topAgents.length,
57
- agents: topAgents.map(agent => ({
58
- id: agent.id,
59
- title: agent.title,
60
- description: agent.description,
61
- score: agent.score,
62
- tags: agent.tags,
63
- path: agent.path
64
- })),
65
- recommendations: topAgents.slice(0, 5).map(a => a.title)
66
- }, null, 2)
67
- }]
68
- };
69
- } catch (error) {
70
- logger.error(`匹配 Agents 失败: ${error}`);
71
- return {
72
- content: [{
73
- type: 'text',
74
- text: JSON.stringify({
75
- error: error instanceof Error ? error.message : String(error)
76
- }, null, 2)
77
- }]
78
- };
79
- }
80
- }
@@ -1,180 +0,0 @@
1
- import { StandardsManager } from '../core/standardsManager.js';
2
- import { ConsoleLogger } from '../core/types.js';
3
-
4
- /**
5
- * 预设场景定义
6
- */
7
- const PRESETS = {
8
- 'vue3-component': {
9
- name: 'Vue 3 组件开发',
10
- fileType: 'vue',
11
- imports: ['vue', 'element-plus'],
12
- scenario: '组件开发',
13
- description: '开发 Vue 3 单文件组件,包含 Composition API 和 Element Plus'
14
- },
15
- 'vue3-form': {
16
- name: 'Vue 3 表单开发',
17
- fileType: 'vue',
18
- imports: ['vue', 'element-plus'],
19
- scenario: '表单组件',
20
- description: 'Element Plus 表单组件开发,包含验证和国际化'
21
- },
22
- 'vue3-table': {
23
- name: 'Vue 3 表格开发',
24
- fileType: 'vue',
25
- imports: ['vue', 'element-plus'],
26
- scenario: '表格组件',
27
- description: 'Element Plus 表格组件开发,包含分页和操作'
28
- },
29
- 'pinia-store': {
30
- name: 'Pinia 状态管理',
31
- fileType: 'ts',
32
- imports: ['vue', 'pinia'],
33
- scenario: '状态管理',
34
- description: 'Pinia store 定义,包含 actions、getters 和持久化'
35
- },
36
- 'api-call': {
37
- name: 'API 调用层',
38
- fileType: 'ts',
39
- imports: ['axios'],
40
- scenario: 'API 调用',
41
- description: 'RESTful API 调用封装,包含错误处理和类型定义'
42
- },
43
- 'typescript-strict': {
44
- name: 'TypeScript 严格模式',
45
- fileType: 'ts',
46
- imports: [],
47
- scenario: '类型定义',
48
- description: 'TypeScript 严格类型定义和类型守卫'
49
- },
50
- 'i18n': {
51
- name: '国际化开发',
52
- fileType: 'vue',
53
- imports: ['vue', 'vue-i18n'],
54
- scenario: '国际化',
55
- description: 'Vue I18n 多语言支持,包含翻译文件管理'
56
- },
57
- 'composable': {
58
- name: 'Vue 3 Composable',
59
- fileType: 'ts',
60
- imports: ['vue'],
61
- scenario: '可组合函数',
62
- description: 'Vue 3 组合式函数开发,复用逻辑'
63
- }
64
- } as const;
65
-
66
- type PresetId = keyof typeof PRESETS;
67
-
68
- /**
69
- * 预设场景快捷工具
70
- * 使用预定义的场景配置快速获取规范
71
- */
72
- export async function usePreset(args: {
73
- preset: string;
74
- customImports?: string[];
75
- }): Promise<{
76
- content: Array<{ type: string; text: string }>;
77
- }> {
78
- const logger = new ConsoleLogger();
79
- const manager = new StandardsManager();
80
-
81
- try {
82
- // 验证预设
83
- if (!(args.preset in PRESETS)) {
84
- return {
85
- content: [{
86
- type: 'text',
87
- text: JSON.stringify({
88
- error: `未知的预设: ${args.preset}`,
89
- availablePresets: Object.keys(PRESETS).map(id => ({
90
- id,
91
- name: PRESETS[id as PresetId].name,
92
- description: PRESETS[id as PresetId].description
93
- }))
94
- }, null, 2)
95
- }]
96
- };
97
- }
98
-
99
- const preset = PRESETS[args.preset as PresetId];
100
- logger.log(`🎯 使用预设: ${preset.name}`);
101
-
102
- // 合并自定义导入
103
- const imports = args.customImports
104
- ? [...preset.imports, ...args.customImports]
105
- : [...preset.imports]; // 创建新数组避免只读问题
106
-
107
- // 获取相关规范
108
- const standards = manager.getRelevantStandards({
109
- fileType: preset.fileType,
110
- imports: imports.length > 0 ? imports : undefined,
111
- scenario: preset.scenario
112
- });
113
-
114
- const combinedContent = manager.combineStandards(standards);
115
-
116
- return {
117
- content: [{
118
- type: 'text',
119
- text: JSON.stringify({
120
- success: true,
121
- preset: {
122
- id: args.preset,
123
- name: preset.name,
124
- description: preset.description
125
- },
126
- applied: {
127
- fileType: preset.fileType,
128
- imports,
129
- scenario: preset.scenario
130
- },
131
- standards: standards,
132
- content: combinedContent,
133
- stats: {
134
- standardsCount: standards.length,
135
- contentLength: combinedContent.length,
136
- estimatedTokens: Math.ceil(combinedContent.length / 4)
137
- }
138
- }, null, 2)
139
- }]
140
- };
141
- } catch (error) {
142
- logger.error(`使用预设失败: ${error}`);
143
- return {
144
- content: [{
145
- type: 'text',
146
- text: JSON.stringify({
147
- error: error instanceof Error ? error.message : String(error)
148
- }, null, 2)
149
- }]
150
- };
151
- }
152
- }
153
-
154
- /**
155
- * 列出所有可用预设
156
- */
157
- export async function listPresets(): Promise<{
158
- content: Array<{ type: string; text: string }>;
159
- }> {
160
- const presetList = Object.entries(PRESETS).map(([id, preset]) => ({
161
- id,
162
- name: preset.name,
163
- description: preset.description,
164
- fileType: preset.fileType,
165
- imports: preset.imports,
166
- scenario: preset.scenario
167
- }));
168
-
169
- return {
170
- content: [{
171
- type: 'text',
172
- text: JSON.stringify({
173
- success: true,
174
- total: presetList.length,
175
- presets: presetList,
176
- usage: '使用方式: 调用 use_preset 工具并指定 preset 参数'
177
- }, null, 2)
178
- }]
179
- };
180
- }