mta-mcp 2.5.0 → 2.7.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/dist/index.js CHANGED
@@ -1,425 +1,695 @@
1
1
  #!/usr/bin/env node
2
-
3
- // src/index.ts
4
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
5
- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
6
- import {
7
- CallToolRequestSchema,
8
- ListToolsRequestSchema,
9
- ListResourcesRequestSchema,
10
- ReadResourceRequestSchema
11
- } from "@modelcontextprotocol/sdk/types.js";
12
-
13
- // src/tools/analyzeProject.ts
14
- import * as fs3 from "fs";
15
- import * as path3 from "path";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __esm = (fn, res) => function __init() {
5
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
6
+ };
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
16
11
 
17
12
  // src/core/smartAgentMatcher.ts
18
13
  import * as fs from "fs";
19
14
  import * as path from "path";
20
15
  import glob from "fast-glob";
21
- var SmartAgentMatcher = class {
22
- constructor(logger3) {
23
- this.logger = logger3;
24
- }
25
- /**
26
- * 分析项目特征
27
- */
28
- async analyzeProject(workspaceFolder) {
29
- this.log(`\u{1F50D} \u5F00\u59CB\u5206\u6790\u9879\u76EE: ${workspaceFolder.name}`);
30
- const features = {
31
- frameworks: [],
32
- languages: [],
33
- tools: [],
34
- keywords: [],
35
- projectType: "unknown"
36
- };
37
- const rootPath = workspaceFolder.uri.fsPath;
38
- const pubspecPath = path.join(rootPath, "pubspec.yaml");
39
- if (fs.existsSync(pubspecPath)) {
40
- const pubspecFeatures = this.analyzePubspecYaml(pubspecPath);
41
- this.mergeFeatures(features, pubspecFeatures);
42
- features.projectType = "flutter";
43
- this.log(`\u2705 \u9879\u76EE\u5206\u6790\u5B8C\u6210: ${features.projectType}`);
44
- return features;
45
- }
46
- const packageJsonPath = path.join(rootPath, "package.json");
47
- if (fs.existsSync(packageJsonPath)) {
48
- const packageFeatures = this.analyzePackageJson(packageJsonPath);
49
- this.mergeFeatures(features, packageFeatures);
50
- }
51
- const structureFeatures = await this.analyzeFileStructure(rootPath);
52
- this.mergeFeatures(features, structureFeatures);
53
- features.projectType = this.inferProjectType(features);
54
- this.log(`\u2705 \u9879\u76EE\u5206\u6790\u5B8C\u6210: ${features.projectType}`);
55
- return features;
56
- }
57
- /**
58
- * 分析 package.json
59
- */
60
- analyzePackageJson(packageJsonPath) {
61
- var _a, _b;
62
- const features = {
63
- frameworks: [],
64
- languages: [],
65
- tools: [],
66
- keywords: []
67
- };
68
- try {
69
- const content = fs.readFileSync(packageJsonPath, "utf-8");
70
- const packageJson = JSON.parse(content);
71
- const allDeps = {
72
- ...packageJson.dependencies,
73
- ...packageJson.devDependencies
74
- };
75
- if (allDeps["vue"]) features.frameworks.push("Vue 3");
76
- if (allDeps["react"]) features.frameworks.push("React");
77
- if (allDeps["@angular/core"]) features.frameworks.push("Angular");
78
- if (allDeps["next"]) features.frameworks.push("Next.js");
79
- if (allDeps["nuxt"]) features.frameworks.push("Nuxt.js");
80
- if (allDeps["svelte"]) features.frameworks.push("Svelte");
81
- if (allDeps["solid-js"]) features.frameworks.push("Solid.js");
82
- if (allDeps["preact"]) features.frameworks.push("Preact");
83
- if (allDeps["remix"]) features.frameworks.push("Remix");
84
- if (allDeps["astro"]) features.frameworks.push("Astro");
85
- if (allDeps["express"]) features.frameworks.push("Express");
86
- if (allDeps["koa"]) features.frameworks.push("Koa");
87
- if (allDeps["fastify"]) features.frameworks.push("Fastify");
88
- if (allDeps["nestjs"] || allDeps["@nestjs/core"]) features.frameworks.push("NestJS");
89
- if (allDeps["egg"]) features.frameworks.push("Egg.js");
90
- if (allDeps["midway"]) features.frameworks.push("Midway");
91
- if (allDeps["hapi"]) features.frameworks.push("Hapi");
92
- if (allDeps["meteor"]) features.frameworks.push("Meteor");
93
- if (allDeps["blitz"]) features.frameworks.push("Blitz.js");
94
- if (allDeps["vite"]) features.tools.push("Vite");
95
- if (allDeps["webpack"]) features.tools.push("Webpack");
96
- if (allDeps["rollup"]) features.tools.push("Rollup");
97
- if (allDeps["parcel"]) features.tools.push("Parcel");
98
- if (allDeps["esbuild"]) features.tools.push("ESBuild");
99
- if (allDeps["turbopack"]) features.tools.push("Turbopack");
100
- if (allDeps["element-plus"]) features.tools.push("Element Plus");
101
- if (allDeps["ant-design-vue"]) features.tools.push("Ant Design Vue");
102
- if (allDeps["antd"]) features.tools.push("Ant Design");
103
- if (allDeps["@mui/material"]) features.tools.push("Material-UI");
104
- if (allDeps["naive-ui"]) features.tools.push("Naive UI");
105
- if (allDeps["vuetify"]) features.tools.push("Vuetify");
106
- if (allDeps["quasar"]) features.tools.push("Quasar");
107
- if (allDeps["primevue"]) features.tools.push("PrimeVue");
108
- if (allDeps["chakra-ui"]) features.tools.push("Chakra UI");
109
- if (allDeps["@headlessui/react"] || allDeps["@headlessui/vue"]) features.tools.push("Headless UI");
110
- if (allDeps["daisyui"]) features.tools.push("DaisyUI");
111
- if (allDeps["shadcn-ui"] || allDeps["@shadcn/ui"]) features.tools.push("Shadcn UI");
112
- if (allDeps["tailwindcss"]) features.tools.push("Tailwind CSS");
113
- if (allDeps["sass"] || allDeps["node-sass"]) features.tools.push("Sass");
114
- if (allDeps["less"]) features.tools.push("Less");
115
- if (allDeps["postcss"]) features.tools.push("PostCSS");
116
- if (allDeps["styled-components"]) features.tools.push("Styled Components");
117
- if (allDeps["emotion"]) features.tools.push("Emotion");
118
- if (allDeps["unocss"]) features.tools.push("UnoCSS");
119
- if (allDeps["@logicflow/core"]) features.tools.push("LogicFlow");
120
- if (allDeps["echarts"]) features.tools.push("ECharts");
121
- if (allDeps["d3"]) features.tools.push("D3.js");
122
- if (allDeps["chart.js"]) features.tools.push("Chart.js");
123
- if (allDeps["antv"] || allDeps["@antv/g6"]) features.tools.push("AntV");
124
- if (allDeps["typescript"]) features.languages.push("TypeScript");
125
- if (((_a = packageJson.dependencies) == null ? void 0 : _a["react"]) || ((_b = packageJson.devDependencies) == null ? void 0 : _b["react"])) {
126
- features.languages.push("JavaScript");
16
+ var SmartAgentMatcher;
17
+ var init_smartAgentMatcher = __esm({
18
+ "src/core/smartAgentMatcher.ts"() {
19
+ "use strict";
20
+ SmartAgentMatcher = class {
21
+ constructor(logger3) {
22
+ this.logger = logger3;
127
23
  }
128
- if (allDeps["vue-i18n"] || allDeps["react-i18n"] || allDeps["i18next"] || allDeps["react-intl"]) {
129
- features.keywords.push("i18n");
24
+ /**
25
+ * 分析项目特征
26
+ */
27
+ async analyzeProject(workspaceFolder) {
28
+ this.log(`\u{1F50D} \u5F00\u59CB\u5206\u6790\u9879\u76EE: ${workspaceFolder.name}`);
29
+ const features = {
30
+ frameworks: [],
31
+ languages: [],
32
+ tools: [],
33
+ keywords: [],
34
+ projectType: "unknown"
35
+ };
36
+ const rootPath = workspaceFolder.uri.fsPath;
37
+ const pubspecPath = path.join(rootPath, "pubspec.yaml");
38
+ if (fs.existsSync(pubspecPath)) {
39
+ const pubspecFeatures = this.analyzePubspecYaml(pubspecPath);
40
+ this.mergeFeatures(features, pubspecFeatures);
41
+ features.projectType = "flutter";
42
+ this.log(`\u2705 \u9879\u76EE\u5206\u6790\u5B8C\u6210: ${features.projectType}`);
43
+ return features;
44
+ }
45
+ const packageJsonPath = path.join(rootPath, "package.json");
46
+ if (fs.existsSync(packageJsonPath)) {
47
+ const packageFeatures = this.analyzePackageJson(packageJsonPath);
48
+ this.mergeFeatures(features, packageFeatures);
49
+ }
50
+ const structureFeatures = await this.analyzeFileStructure(rootPath);
51
+ this.mergeFeatures(features, structureFeatures);
52
+ features.projectType = this.inferProjectType(features);
53
+ this.log(`\u2705 \u9879\u76EE\u5206\u6790\u5B8C\u6210: ${features.projectType}`);
54
+ return features;
130
55
  }
131
- if (allDeps["pinia"] || allDeps["vuex"] || allDeps["redux"] || allDeps["@reduxjs/toolkit"] || allDeps["mobx"] || allDeps["zustand"] || allDeps["recoil"] || allDeps["jotai"]) {
132
- features.keywords.push("state-management");
56
+ /**
57
+ * 分析 package.json
58
+ */
59
+ analyzePackageJson(packageJsonPath) {
60
+ var _a, _b;
61
+ const features = {
62
+ frameworks: [],
63
+ languages: [],
64
+ tools: [],
65
+ keywords: []
66
+ };
67
+ try {
68
+ const content = fs.readFileSync(packageJsonPath, "utf-8");
69
+ const packageJson = JSON.parse(content);
70
+ const allDeps = {
71
+ ...packageJson.dependencies,
72
+ ...packageJson.devDependencies
73
+ };
74
+ if (allDeps["vue"]) features.frameworks.push("Vue 3");
75
+ if (allDeps["react"]) features.frameworks.push("React");
76
+ if (allDeps["@angular/core"]) features.frameworks.push("Angular");
77
+ if (allDeps["next"]) features.frameworks.push("Next.js");
78
+ if (allDeps["nuxt"]) features.frameworks.push("Nuxt.js");
79
+ if (allDeps["svelte"]) features.frameworks.push("Svelte");
80
+ if (allDeps["solid-js"]) features.frameworks.push("Solid.js");
81
+ if (allDeps["preact"]) features.frameworks.push("Preact");
82
+ if (allDeps["remix"]) features.frameworks.push("Remix");
83
+ if (allDeps["astro"]) features.frameworks.push("Astro");
84
+ if (allDeps["express"]) features.frameworks.push("Express");
85
+ if (allDeps["koa"]) features.frameworks.push("Koa");
86
+ if (allDeps["fastify"]) features.frameworks.push("Fastify");
87
+ if (allDeps["nestjs"] || allDeps["@nestjs/core"]) features.frameworks.push("NestJS");
88
+ if (allDeps["egg"]) features.frameworks.push("Egg.js");
89
+ if (allDeps["midway"]) features.frameworks.push("Midway");
90
+ if (allDeps["hapi"]) features.frameworks.push("Hapi");
91
+ if (allDeps["meteor"]) features.frameworks.push("Meteor");
92
+ if (allDeps["blitz"]) features.frameworks.push("Blitz.js");
93
+ if (allDeps["vite"]) features.tools.push("Vite");
94
+ if (allDeps["webpack"]) features.tools.push("Webpack");
95
+ if (allDeps["rollup"]) features.tools.push("Rollup");
96
+ if (allDeps["parcel"]) features.tools.push("Parcel");
97
+ if (allDeps["esbuild"]) features.tools.push("ESBuild");
98
+ if (allDeps["turbopack"]) features.tools.push("Turbopack");
99
+ if (allDeps["element-plus"]) features.tools.push("Element Plus");
100
+ if (allDeps["ant-design-vue"]) features.tools.push("Ant Design Vue");
101
+ if (allDeps["antd"]) features.tools.push("Ant Design");
102
+ if (allDeps["@mui/material"]) features.tools.push("Material-UI");
103
+ if (allDeps["naive-ui"]) features.tools.push("Naive UI");
104
+ if (allDeps["vuetify"]) features.tools.push("Vuetify");
105
+ if (allDeps["quasar"]) features.tools.push("Quasar");
106
+ if (allDeps["primevue"]) features.tools.push("PrimeVue");
107
+ if (allDeps["chakra-ui"]) features.tools.push("Chakra UI");
108
+ if (allDeps["@headlessui/react"] || allDeps["@headlessui/vue"]) features.tools.push("Headless UI");
109
+ if (allDeps["daisyui"]) features.tools.push("DaisyUI");
110
+ if (allDeps["shadcn-ui"] || allDeps["@shadcn/ui"]) features.tools.push("Shadcn UI");
111
+ if (allDeps["tailwindcss"]) features.tools.push("Tailwind CSS");
112
+ if (allDeps["sass"] || allDeps["node-sass"]) features.tools.push("Sass");
113
+ if (allDeps["less"]) features.tools.push("Less");
114
+ if (allDeps["postcss"]) features.tools.push("PostCSS");
115
+ if (allDeps["styled-components"]) features.tools.push("Styled Components");
116
+ if (allDeps["emotion"]) features.tools.push("Emotion");
117
+ if (allDeps["unocss"]) features.tools.push("UnoCSS");
118
+ if (allDeps["@logicflow/core"]) features.tools.push("LogicFlow");
119
+ if (allDeps["echarts"]) features.tools.push("ECharts");
120
+ if (allDeps["d3"]) features.tools.push("D3.js");
121
+ if (allDeps["chart.js"]) features.tools.push("Chart.js");
122
+ if (allDeps["antv"] || allDeps["@antv/g6"]) features.tools.push("AntV");
123
+ if (allDeps["typescript"]) features.languages.push("TypeScript");
124
+ if (((_a = packageJson.dependencies) == null ? void 0 : _a["react"]) || ((_b = packageJson.devDependencies) == null ? void 0 : _b["react"])) {
125
+ features.languages.push("JavaScript");
126
+ }
127
+ if (allDeps["vue-i18n"] || allDeps["react-i18n"] || allDeps["i18next"] || allDeps["react-intl"]) {
128
+ features.keywords.push("i18n");
129
+ }
130
+ if (allDeps["pinia"] || allDeps["vuex"] || allDeps["redux"] || allDeps["@reduxjs/toolkit"] || allDeps["mobx"] || allDeps["zustand"] || allDeps["recoil"] || allDeps["jotai"]) {
131
+ features.keywords.push("state-management");
132
+ }
133
+ if (allDeps["vue-router"] || allDeps["react-router"] || allDeps["react-router-dom"] || allDeps["@tanstack/react-router"]) {
134
+ features.keywords.push("routing");
135
+ }
136
+ if (allDeps["axios"] || allDeps["@tanstack/react-query"] || allDeps["@tanstack/vue-query"] || allDeps["swr"] || allDeps["urql"]) {
137
+ features.keywords.push("data-fetching");
138
+ }
139
+ if (allDeps["formik"] || allDeps["react-hook-form"] || allDeps["vee-validate"] || allDeps["@vuelidate/core"]) {
140
+ features.keywords.push("forms");
141
+ }
142
+ if (allDeps["vitest"] || allDeps["jest"] || allDeps["@testing-library/react"] || allDeps["@testing-library/vue"] || allDeps["cypress"] || allDeps["playwright"]) {
143
+ features.keywords.push("testing");
144
+ }
145
+ if (allDeps["vant"] || allDeps["@tarojs/taro"] || allDeps["react-native"] || allDeps["uni-app"] || allDeps["@nutui/nutui"]) {
146
+ features.keywords.push("mobile");
147
+ }
148
+ if (packageJson.miniprogram || allDeps["@tarojs/taro"] || allDeps["uni-app"]) {
149
+ features.keywords.push("miniprogram");
150
+ features.keywords.push("wechat");
151
+ }
152
+ if (allDeps["prisma"] || allDeps["typeorm"] || allDeps["sequelize"] || allDeps["mongoose"]) {
153
+ features.keywords.push("database");
154
+ }
155
+ if (allDeps["graphql"] || allDeps["apollo-client"] || allDeps["@apollo/client"]) {
156
+ features.keywords.push("graphql");
157
+ }
158
+ } catch (error) {
159
+ this.log(`\u89E3\u6790 package.json \u5931\u8D25: ${error}`);
160
+ }
161
+ return features;
133
162
  }
134
- if (allDeps["vue-router"] || allDeps["react-router"] || allDeps["react-router-dom"] || allDeps["@tanstack/react-router"]) {
135
- features.keywords.push("routing");
163
+ /**
164
+ * 分析 pubspec.yaml (Flutter 项目)
165
+ */
166
+ analyzePubspecYaml(pubspecPath) {
167
+ const features = {
168
+ frameworks: ["Flutter"],
169
+ languages: ["Dart"],
170
+ tools: [],
171
+ keywords: []
172
+ };
173
+ try {
174
+ const content = fs.readFileSync(pubspecPath, "utf-8");
175
+ if (content.includes("provider:")) features.keywords.push("state-management");
176
+ if (content.includes("riverpod:")) features.keywords.push("state-management");
177
+ if (content.includes("bloc:") || content.includes("flutter_bloc:")) features.keywords.push("state-management");
178
+ if (content.includes("get:") || content.includes("get_x:")) {
179
+ features.keywords.push("routing", "state-management");
180
+ }
181
+ if (content.includes("flutter_localizations:") || content.includes("intl:") || content.includes("easy_localization:")) {
182
+ features.keywords.push("i18n");
183
+ }
184
+ if (content.includes("go_router:") || content.includes("auto_route:")) features.keywords.push("routing");
185
+ if (content.includes("dio:") || content.includes("http:")) features.keywords.push("data-fetching");
186
+ if (content.includes("flutter_screenutil:")) features.tools.push("ScreenUtil");
187
+ if (content.includes("flutter_test:") || content.includes("mockito:") || content.includes("integration_test:")) {
188
+ features.keywords.push("testing");
189
+ }
190
+ } catch (error) {
191
+ this.log(`\u89E3\u6790 pubspec.yaml \u5931\u8D25: ${error}`);
192
+ }
193
+ return features;
136
194
  }
137
- if (allDeps["axios"] || allDeps["@tanstack/react-query"] || allDeps["@tanstack/vue-query"] || allDeps["swr"] || allDeps["urql"]) {
138
- features.keywords.push("data-fetching");
195
+ /**
196
+ * 分析文件结构
197
+ */
198
+ async analyzeFileStructure(rootPath) {
199
+ const features = {
200
+ frameworks: [],
201
+ languages: [],
202
+ tools: [],
203
+ keywords: []
204
+ };
205
+ try {
206
+ const patterns = [
207
+ "**/*.vue",
208
+ "**/*.ts",
209
+ "**/*.tsx",
210
+ "**/*.jsx",
211
+ "**/*.js",
212
+ "**/*.py",
213
+ "**/*.java",
214
+ "**/*.go",
215
+ "**/*.rs",
216
+ "**/*.cpp",
217
+ "**/*.c",
218
+ "**/locales/**",
219
+ "**/i18n/**",
220
+ "**/lang/**",
221
+ "**/stores/**",
222
+ "**/store/**",
223
+ "**/redux/**",
224
+ "**/*.test.*",
225
+ "**/*.spec.*",
226
+ "**/components/**",
227
+ "**/pages/**",
228
+ "**/views/**"
229
+ ];
230
+ const files = await glob(patterns, {
231
+ cwd: rootPath,
232
+ ignore: ["**/node_modules/**", "**/dist/**", "**/build/**", "**/.git/**"],
233
+ onlyFiles: true
234
+ });
235
+ if (files.some((f) => f.endsWith(".vue"))) features.frameworks.push("Vue");
236
+ if (files.some((f) => f.endsWith(".tsx"))) features.frameworks.push("React");
237
+ if (files.some((f) => f.endsWith(".svelte"))) features.frameworks.push("Svelte");
238
+ if (files.some((f) => f.endsWith(".ts") || f.endsWith(".tsx"))) features.languages.push("TypeScript");
239
+ if (files.some((f) => f.endsWith(".js") || f.endsWith(".jsx"))) features.languages.push("JavaScript");
240
+ if (files.some((f) => f.endsWith(".py"))) features.languages.push("Python");
241
+ if (files.some((f) => f.endsWith(".java"))) features.languages.push("Java");
242
+ if (files.some((f) => f.endsWith(".go"))) features.languages.push("Go");
243
+ if (files.some((f) => f.endsWith(".rs"))) features.languages.push("Rust");
244
+ if (files.some((f) => f.match(/\.(cpp|cc|cxx|c)$/))) features.languages.push("C/C++");
245
+ if (files.some((f) => f.includes("/locales/") || f.includes("/i18n/") || f.includes("/lang/"))) {
246
+ features.keywords.push("i18n");
247
+ }
248
+ if (files.some((f) => f.includes("/stores/") || f.includes("/store/") || f.includes("/redux/"))) {
249
+ features.keywords.push("state-management");
250
+ }
251
+ if (files.some((f) => f.includes(".test.") || f.includes(".spec."))) {
252
+ features.keywords.push("testing");
253
+ }
254
+ } catch (error) {
255
+ this.log(`\u626B\u63CF\u6587\u4EF6\u7ED3\u6784\u5931\u8D25: ${error}`);
256
+ }
257
+ return features;
139
258
  }
140
- if (allDeps["formik"] || allDeps["react-hook-form"] || allDeps["vee-validate"] || allDeps["@vuelidate/core"]) {
141
- features.keywords.push("forms");
259
+ /**
260
+ * 匹配 Agents
261
+ */
262
+ matchAgents(features, availableAgents) {
263
+ const scoredAgents = availableAgents.map((agent) => {
264
+ const score = this.calculateMatchScore(features, agent);
265
+ return { ...agent, score };
266
+ });
267
+ return scoredAgents.filter((a) => a.score > 0).sort((a, b) => (b.score || 0) - (a.score || 0));
142
268
  }
143
- if (allDeps["vitest"] || allDeps["jest"] || allDeps["@testing-library/react"] || allDeps["@testing-library/vue"] || allDeps["cypress"] || allDeps["playwright"]) {
144
- features.keywords.push("testing");
269
+ /**
270
+ * 计算匹配分数
271
+ */
272
+ calculateMatchScore(features, agent) {
273
+ let score = 0;
274
+ const WEIGHTS = {
275
+ framework: 10,
276
+ tool: 8,
277
+ language: 5,
278
+ keyword: 3,
279
+ tag: 2
280
+ };
281
+ features.frameworks.forEach((f) => {
282
+ var _a, _b;
283
+ if ((_b = (_a = agent.applicableWhen) == null ? void 0 : _a.frameworks) == null ? void 0 : _b.some((af) => af.toLowerCase().includes(f.toLowerCase()))) {
284
+ score += WEIGHTS.framework;
285
+ }
286
+ });
287
+ features.tools.forEach((t) => {
288
+ var _a, _b;
289
+ if ((_b = (_a = agent.applicableWhen) == null ? void 0 : _a.tools) == null ? void 0 : _b.some((at) => at.toLowerCase().includes(t.toLowerCase()))) {
290
+ score += WEIGHTS.tool;
291
+ }
292
+ });
293
+ features.languages.forEach((l) => {
294
+ var _a, _b;
295
+ if ((_b = (_a = agent.applicableWhen) == null ? void 0 : _a.languages) == null ? void 0 : _b.some((al) => al.toLowerCase().includes(l.toLowerCase()))) {
296
+ score += WEIGHTS.language;
297
+ }
298
+ });
299
+ features.keywords.forEach((k) => {
300
+ var _a, _b;
301
+ if ((_b = (_a = agent.applicableWhen) == null ? void 0 : _a.keywords) == null ? void 0 : _b.some((ak) => ak.toLowerCase().includes(k.toLowerCase()))) {
302
+ score += WEIGHTS.keyword;
303
+ }
304
+ });
305
+ features.frameworks.concat(features.tools, features.languages, features.keywords).forEach((feature) => {
306
+ if (agent.tags.some((tag) => tag.toLowerCase().includes(feature.toLowerCase()))) {
307
+ score += WEIGHTS.tag;
308
+ }
309
+ });
310
+ return score;
145
311
  }
146
- if (allDeps["vant"] || allDeps["@tarojs/taro"] || allDeps["react-native"] || allDeps["uni-app"] || allDeps["@nutui/nutui"]) {
147
- features.keywords.push("mobile");
312
+ /**
313
+ * 解析 Agent 元数据
314
+ */
315
+ parseAgentMetadata(filePath, content) {
316
+ const id = path.basename(filePath, ".agent.md");
317
+ let description = "";
318
+ let tags = [];
319
+ let frontmatter = "";
320
+ if (content.startsWith("---")) {
321
+ const endIndex = content.indexOf("---", 3);
322
+ if (endIndex > 0) {
323
+ frontmatter = content.substring(3, endIndex);
324
+ }
325
+ } else if (content.includes("```chatagent")) {
326
+ const chatagentMatch = content.match(/```chatagent[\s\S]*?---\n([\s\S]*?)\n---/);
327
+ if (chatagentMatch) {
328
+ frontmatter = chatagentMatch[1];
329
+ }
330
+ }
331
+ if (frontmatter) {
332
+ const descMatch = frontmatter.match(/description:\s*['"](.+)['"]/);
333
+ if (descMatch) description = descMatch[1];
334
+ const tagsMatch = frontmatter.match(/tags:\s*\[(.+)\]/);
335
+ if (tagsMatch) {
336
+ tags = tagsMatch[1].split(",").map((t) => t.trim().replace(/['"]/g, ""));
337
+ }
338
+ }
339
+ const titleMatch = content.match(/^#\s+(.+)$/m);
340
+ const title = titleMatch ? titleMatch[1] : id;
341
+ return {
342
+ id,
343
+ path: filePath,
344
+ title,
345
+ description,
346
+ tags,
347
+ applicableWhen: {
348
+ frameworks: tags.filter(
349
+ (t) => [
350
+ "vue",
351
+ "vue3",
352
+ "react",
353
+ "angular",
354
+ "next",
355
+ "nuxt",
356
+ "svelte",
357
+ "flutter",
358
+ "express",
359
+ "nestjs",
360
+ "koa",
361
+ "fastify"
362
+ ].includes(t.toLowerCase())
363
+ ),
364
+ languages: tags.filter(
365
+ (t) => ["typescript", "javascript", "python", "java", "go", "rust", "dart", "c++"].includes(t.toLowerCase())
366
+ ),
367
+ tools: tags.filter(
368
+ (t) => [
369
+ "vite",
370
+ "webpack",
371
+ "rollup",
372
+ "logicflow",
373
+ "element-plus",
374
+ "antd",
375
+ "tailwind",
376
+ "sass",
377
+ "echarts",
378
+ "prisma",
379
+ "graphql"
380
+ ].includes(t.toLowerCase())
381
+ ),
382
+ keywords: tags.filter(
383
+ (t) => [
384
+ "i18n",
385
+ "state-management",
386
+ "routing",
387
+ "testing",
388
+ "mobile",
389
+ "miniprogram",
390
+ "database",
391
+ "forms",
392
+ "data-fetching"
393
+ ].includes(t.toLowerCase())
394
+ )
395
+ }
396
+ };
148
397
  }
149
- if (packageJson.miniprogram || allDeps["@tarojs/taro"] || allDeps["uni-app"]) {
150
- features.keywords.push("miniprogram");
151
- features.keywords.push("wechat");
398
+ mergeFeatures(target, source) {
399
+ if (source.frameworks) target.frameworks.push(...source.frameworks);
400
+ if (source.languages) target.languages.push(...source.languages);
401
+ if (source.tools) target.tools.push(...source.tools);
402
+ if (source.keywords) target.keywords.push(...source.keywords);
152
403
  }
153
- if (allDeps["prisma"] || allDeps["typeorm"] || allDeps["sequelize"] || allDeps["mongoose"]) {
154
- features.keywords.push("database");
404
+ inferProjectType(features) {
405
+ if (features.frameworks.some((f) => f.toLowerCase().includes("vue"))) return "vue3";
406
+ if (features.frameworks.some((f) => f.toLowerCase().includes("react"))) return "react";
407
+ if (features.frameworks.some((f) => f.toLowerCase().includes("angular"))) return "angular";
408
+ if (features.frameworks.some((f) => f.toLowerCase().includes("svelte"))) return "svelte";
409
+ if (features.frameworks.some((f) => f.toLowerCase().includes("next"))) return "nextjs";
410
+ if (features.frameworks.some((f) => f.toLowerCase().includes("nuxt"))) return "nuxtjs";
411
+ if (features.frameworks.some((f) => f.toLowerCase().includes("flutter"))) return "flutter";
412
+ if (features.frameworks.some((f) => f.toLowerCase().includes("react-native"))) return "react-native";
413
+ if (features.keywords.includes("miniprogram")) return "miniprogram";
414
+ if (features.frameworks.some((f) => f.toLowerCase().includes("nest"))) return "nestjs";
415
+ if (features.frameworks.some((f) => f.toLowerCase().includes("express"))) return "express";
416
+ if (features.frameworks.some((f) => f.toLowerCase().includes("koa"))) return "koa";
417
+ if (features.frameworks.some((f) => f.toLowerCase().includes("fastify"))) return "fastify";
418
+ if (features.languages.includes("TypeScript")) return "typescript";
419
+ if (features.languages.includes("Python")) return "python";
420
+ if (features.languages.includes("Java")) return "java";
421
+ if (features.languages.includes("Go")) return "go";
422
+ if (features.languages.includes("Rust")) return "rust";
423
+ return "general";
155
424
  }
156
- if (allDeps["graphql"] || allDeps["apollo-client"] || allDeps["@apollo/client"]) {
157
- features.keywords.push("graphql");
425
+ log(message) {
426
+ var _a;
427
+ (_a = this.logger) == null ? void 0 : _a.log(message);
158
428
  }
159
- } catch (error) {
160
- this.log(`\u89E3\u6790 package.json \u5931\u8D25: ${error}`);
161
- }
162
- return features;
163
- }
164
- /**
165
- * 分析 pubspec.yaml (Flutter 项目)
166
- */
167
- analyzePubspecYaml(pubspecPath) {
168
- const features = {
169
- frameworks: ["Flutter"],
170
- languages: ["Dart"],
171
- tools: [],
172
- keywords: []
173
429
  };
174
- try {
175
- const content = fs.readFileSync(pubspecPath, "utf-8");
176
- if (content.includes("provider:")) features.keywords.push("state-management");
177
- if (content.includes("riverpod:")) features.keywords.push("state-management");
178
- if (content.includes("bloc:") || content.includes("flutter_bloc:")) features.keywords.push("state-management");
179
- if (content.includes("get:") || content.includes("get_x:")) {
180
- features.keywords.push("routing", "state-management");
430
+ }
431
+ });
432
+
433
+ // src/core/resourceLoader.ts
434
+ var resourceLoader_exports = {};
435
+ __export(resourceLoader_exports, {
436
+ ResourceLoader: () => ResourceLoader,
437
+ getResourceLoader: () => getResourceLoader
438
+ });
439
+ import * as fs4 from "fs";
440
+ import * as path4 from "path";
441
+ import { fileURLToPath } from "url";
442
+ function getResourceLoader(logger3) {
443
+ if (!resourceLoaderInstance) {
444
+ resourceLoaderInstance = new ResourceLoader(logger3);
445
+ }
446
+ return resourceLoaderInstance;
447
+ }
448
+ var __filename, __dirname2, ResourceLoader, resourceLoaderInstance;
449
+ var init_resourceLoader = __esm({
450
+ "src/core/resourceLoader.ts"() {
451
+ "use strict";
452
+ init_smartAgentMatcher();
453
+ __filename = fileURLToPath(import.meta.url);
454
+ __dirname2 = path4.dirname(__filename);
455
+ ResourceLoader = class {
456
+ constructor(logger3) {
457
+ this.initialized = false;
458
+ this.logger = logger3;
459
+ this.packageRoot = this.detectPackageRoot();
460
+ this.validateResources();
181
461
  }
182
- if (content.includes("flutter_localizations:") || content.includes("intl:") || content.includes("easy_localization:")) {
183
- features.keywords.push("i18n");
462
+ /**
463
+ * 检测包根目录
464
+ * 支持多种运行环境
465
+ */
466
+ detectPackageRoot() {
467
+ const rootFromDist = path4.resolve(__dirname2, "..");
468
+ const packageJsonPath = path4.join(rootFromDist, "package.json");
469
+ if (fs4.existsSync(packageJsonPath)) {
470
+ try {
471
+ const pkg = JSON.parse(fs4.readFileSync(packageJsonPath, "utf-8"));
472
+ if (pkg.name === "mta-mcp") {
473
+ this.log(`\u{1F4E6} \u68C0\u6D4B\u5230\u5305\u6839\u76EE\u5F55: ${rootFromDist}`);
474
+ return rootFromDist;
475
+ }
476
+ } catch {
477
+ }
478
+ }
479
+ this.log(`\u{1F4E6} \u4F7F\u7528\u9ED8\u8BA4\u5305\u6839\u76EE\u5F55: ${rootFromDist}`);
480
+ return rootFromDist;
184
481
  }
185
- if (content.includes("go_router:") || content.includes("auto_route:")) features.keywords.push("routing");
186
- if (content.includes("dio:") || content.includes("http:")) features.keywords.push("data-fetching");
187
- if (content.includes("flutter_screenutil:")) features.tools.push("ScreenUtil");
188
- if (content.includes("flutter_test:") || content.includes("mockito:") || content.includes("integration_test:")) {
189
- features.keywords.push("testing");
482
+ /**
483
+ * 验证资源目录是否存在
484
+ */
485
+ validateResources() {
486
+ const requiredDirs = ["agents", "standards"];
487
+ const missingDirs = [];
488
+ for (const dir of requiredDirs) {
489
+ const dirPath = path4.join(this.packageRoot, dir);
490
+ if (!fs4.existsSync(dirPath)) {
491
+ missingDirs.push(dir);
492
+ }
493
+ }
494
+ if (missingDirs.length > 0) {
495
+ this.error(`\u26A0\uFE0F \u4EE5\u4E0B\u8D44\u6E90\u76EE\u5F55\u7F3A\u5931: ${missingDirs.join(", ")}`);
496
+ this.error(` \u5305\u6839\u76EE\u5F55: ${this.packageRoot}`);
497
+ this.error(` \u8BF7\u786E\u4FDD npm \u5305\u5DF2\u6B63\u786E\u5B89\u88C5\u6216\u8FD0\u884C npm run sync`);
498
+ } else {
499
+ this.initialized = true;
500
+ this.log(`\u2705 \u8D44\u6E90\u76EE\u5F55\u9A8C\u8BC1\u901A\u8FC7`);
501
+ }
190
502
  }
191
- } catch (error) {
192
- this.log(`\u89E3\u6790 pubspec.yaml \u5931\u8D25: ${error}`);
193
- }
194
- return features;
195
- }
196
- /**
197
- * 分析文件结构
198
- */
199
- async analyzeFileStructure(rootPath) {
200
- const features = {
201
- frameworks: [],
202
- languages: [],
203
- tools: [],
204
- keywords: []
205
- };
206
- try {
207
- const patterns = [
208
- "**/*.vue",
209
- "**/*.ts",
210
- "**/*.tsx",
211
- "**/*.jsx",
212
- "**/*.js",
213
- "**/*.py",
214
- "**/*.java",
215
- "**/*.go",
216
- "**/*.rs",
217
- "**/*.cpp",
218
- "**/*.c",
219
- "**/locales/**",
220
- "**/i18n/**",
221
- "**/lang/**",
222
- "**/stores/**",
223
- "**/store/**",
224
- "**/redux/**",
225
- "**/*.test.*",
226
- "**/*.spec.*",
227
- "**/components/**",
228
- "**/pages/**",
229
- "**/views/**"
230
- ];
231
- const files = await glob(patterns, {
232
- cwd: rootPath,
233
- ignore: ["**/node_modules/**", "**/dist/**", "**/build/**", "**/.git/**"],
234
- onlyFiles: true
235
- });
236
- if (files.some((f) => f.endsWith(".vue"))) features.frameworks.push("Vue");
237
- if (files.some((f) => f.endsWith(".tsx"))) features.frameworks.push("React");
238
- if (files.some((f) => f.endsWith(".svelte"))) features.frameworks.push("Svelte");
239
- if (files.some((f) => f.endsWith(".ts") || f.endsWith(".tsx"))) features.languages.push("TypeScript");
240
- if (files.some((f) => f.endsWith(".js") || f.endsWith(".jsx"))) features.languages.push("JavaScript");
241
- if (files.some((f) => f.endsWith(".py"))) features.languages.push("Python");
242
- if (files.some((f) => f.endsWith(".java"))) features.languages.push("Java");
243
- if (files.some((f) => f.endsWith(".go"))) features.languages.push("Go");
244
- if (files.some((f) => f.endsWith(".rs"))) features.languages.push("Rust");
245
- if (files.some((f) => f.match(/\.(cpp|cc|cxx|c)$/))) features.languages.push("C/C++");
246
- if (files.some((f) => f.includes("/locales/") || f.includes("/i18n/") || f.includes("/lang/"))) {
247
- features.keywords.push("i18n");
503
+ /**
504
+ * 获取资源目录路径
505
+ */
506
+ getResourceDir(type) {
507
+ return path4.join(this.packageRoot, type);
248
508
  }
249
- if (files.some((f) => f.includes("/stores/") || f.includes("/store/") || f.includes("/redux/"))) {
250
- features.keywords.push("state-management");
509
+ /**
510
+ * 加载所有 Agents
511
+ */
512
+ loadAllAgents() {
513
+ const agentsDir = this.getResourceDir("agents");
514
+ const agents = [];
515
+ this.log(`\u{1F4C1} \u4ECE\u5305\u5185\u52A0\u8F7D Agents: ${agentsDir}`);
516
+ if (!fs4.existsSync(agentsDir)) {
517
+ this.error(`Agents \u76EE\u5F55\u4E0D\u5B58\u5728: ${agentsDir}`);
518
+ this.error(`\u5305\u6839\u76EE\u5F55: ${this.packageRoot}`);
519
+ this.error(`\u5F53\u524D __dirname: ${__dirname2}`);
520
+ return agents;
521
+ }
522
+ const matcher = new SmartAgentMatcher(this.logger);
523
+ const files = fs4.readdirSync(agentsDir);
524
+ for (const file of files) {
525
+ if (file.endsWith(".agent.md")) {
526
+ try {
527
+ const filePath = path4.join(agentsDir, file);
528
+ const content = fs4.readFileSync(filePath, "utf-8");
529
+ const metadata = matcher.parseAgentMetadata(`agents/${file}`, content);
530
+ agents.push(metadata);
531
+ this.log(`\u2705 \u52A0\u8F7D Agent: ${metadata.title}`);
532
+ } catch (error) {
533
+ this.error(`\u89E3\u6790 ${file} \u5931\u8D25: ${error}`);
534
+ }
535
+ }
536
+ }
537
+ this.log(`\u2705 \u6210\u529F\u52A0\u8F7D ${agents.length} \u4E2A Agents`);
538
+ return agents;
251
539
  }
252
- if (files.some((f) => f.includes(".test.") || f.includes(".spec."))) {
253
- features.keywords.push("testing");
540
+ /**
541
+ * 加载单个 Agent
542
+ */
543
+ loadAgent(agentId) {
544
+ const agentsDir = this.getResourceDir("agents");
545
+ const filePath = path4.join(agentsDir, `${agentId}.agent.md`);
546
+ if (!fs4.existsSync(filePath)) {
547
+ this.error(`Agent \u4E0D\u5B58\u5728: ${agentId}`);
548
+ return null;
549
+ }
550
+ try {
551
+ const content = fs4.readFileSync(filePath, "utf-8");
552
+ const matcher = new SmartAgentMatcher(this.logger);
553
+ const metadata = matcher.parseAgentMetadata(`agents/${agentId}.agent.md`, content);
554
+ return { content, metadata };
555
+ } catch (error) {
556
+ this.error(`\u52A0\u8F7D Agent ${agentId} \u5931\u8D25: ${error}`);
557
+ return null;
558
+ }
254
559
  }
255
- } catch (error) {
256
- this.log(`\u626B\u63CF\u6587\u4EF6\u7ED3\u6784\u5931\u8D25: ${error}`);
257
- }
258
- return features;
259
- }
260
- /**
261
- * 匹配 Agents
262
- */
263
- matchAgents(features, availableAgents) {
264
- const scoredAgents = availableAgents.map((agent) => {
265
- const score = this.calculateMatchScore(features, agent);
266
- return { ...agent, score };
267
- });
268
- return scoredAgents.filter((a) => a.score > 0).sort((a, b) => (b.score || 0) - (a.score || 0));
269
- }
270
- /**
271
- * 计算匹配分数
272
- */
273
- calculateMatchScore(features, agent) {
274
- let score = 0;
275
- const WEIGHTS = {
276
- framework: 10,
277
- tool: 8,
278
- language: 5,
279
- keyword: 3,
280
- tag: 2
281
- };
282
- features.frameworks.forEach((f) => {
283
- var _a, _b;
284
- if ((_b = (_a = agent.applicableWhen) == null ? void 0 : _a.frameworks) == null ? void 0 : _b.some((af) => af.toLowerCase().includes(f.toLowerCase()))) {
285
- score += WEIGHTS.framework;
560
+ /**
561
+ * 列出所有可用的 Agent ID
562
+ */
563
+ listAgentIds() {
564
+ const agentsDir = this.getResourceDir("agents");
565
+ if (!fs4.existsSync(agentsDir)) {
566
+ return [];
567
+ }
568
+ return fs4.readdirSync(agentsDir).filter((f) => f.endsWith(".agent.md")).map((f) => f.replace(".agent.md", ""));
286
569
  }
287
- });
288
- features.tools.forEach((t) => {
289
- var _a, _b;
290
- if ((_b = (_a = agent.applicableWhen) == null ? void 0 : _a.tools) == null ? void 0 : _b.some((at) => at.toLowerCase().includes(t.toLowerCase()))) {
291
- score += WEIGHTS.tool;
570
+ /**
571
+ * 加载规范文件
572
+ */
573
+ loadStandard(standardPath) {
574
+ const standardsDir = this.getResourceDir("standards");
575
+ const filePath = path4.join(standardsDir, standardPath);
576
+ if (!fs4.existsSync(filePath)) {
577
+ const commonPath = path4.join(this.getResourceDir("common"), standardPath);
578
+ if (fs4.existsSync(commonPath)) {
579
+ return fs4.readFileSync(commonPath, "utf-8");
580
+ }
581
+ this.error(`\u89C4\u8303\u6587\u4EF6\u4E0D\u5B58\u5728: ${standardPath}`);
582
+ return null;
583
+ }
584
+ return fs4.readFileSync(filePath, "utf-8");
292
585
  }
293
- });
294
- features.languages.forEach((l) => {
295
- var _a, _b;
296
- if ((_b = (_a = agent.applicableWhen) == null ? void 0 : _a.languages) == null ? void 0 : _b.some((al) => al.toLowerCase().includes(l.toLowerCase()))) {
297
- score += WEIGHTS.language;
586
+ /**
587
+ * 列出规范目录下的所有文件
588
+ */
589
+ listStandards(subDir) {
590
+ const standardsDir = this.getResourceDir("standards");
591
+ const targetDir = subDir ? path4.join(standardsDir, subDir) : standardsDir;
592
+ if (!fs4.existsSync(targetDir)) {
593
+ return [];
594
+ }
595
+ const results = [];
596
+ this.walkDir(targetDir, standardsDir, results);
597
+ return results;
298
598
  }
299
- });
300
- features.keywords.forEach((k) => {
301
- var _a, _b;
302
- if ((_b = (_a = agent.applicableWhen) == null ? void 0 : _a.keywords) == null ? void 0 : _b.some((ak) => ak.toLowerCase().includes(k.toLowerCase()))) {
303
- score += WEIGHTS.keyword;
599
+ /**
600
+ * 加载模板
601
+ */
602
+ loadTemplate(templatePath) {
603
+ const templatesDir = this.getResourceDir("templates");
604
+ const filePath = path4.join(templatesDir, templatePath);
605
+ if (!fs4.existsSync(filePath)) {
606
+ this.error(`\u6A21\u677F\u6587\u4EF6\u4E0D\u5B58\u5728: ${templatePath}`);
607
+ return null;
608
+ }
609
+ return fs4.readFileSync(filePath, "utf-8");
304
610
  }
305
- });
306
- features.frameworks.concat(features.tools, features.languages, features.keywords).forEach((feature) => {
307
- if (agent.tags.some((tag) => tag.toLowerCase().includes(feature.toLowerCase()))) {
308
- score += WEIGHTS.tag;
611
+ /**
612
+ * 列出模板目录
613
+ */
614
+ listTemplates(subDir) {
615
+ const templatesDir = this.getResourceDir("templates");
616
+ const targetDir = subDir ? path4.join(templatesDir, subDir) : templatesDir;
617
+ if (!fs4.existsSync(targetDir)) {
618
+ return [];
619
+ }
620
+ return fs4.readdirSync(targetDir);
309
621
  }
310
- });
311
- return score;
312
- }
313
- /**
314
- * 解析 Agent 元数据
315
- */
316
- parseAgentMetadata(filePath, content) {
317
- const id = path.basename(filePath, ".agent.md");
318
- let description = "";
319
- let tags = [];
320
- if (content.startsWith("---")) {
321
- const endIndex = content.indexOf("---", 3);
322
- if (endIndex > 0) {
323
- const frontmatter = content.substring(3, endIndex);
324
- const descMatch = frontmatter.match(/description:\s*['"](.+)['"]/);
325
- if (descMatch) description = descMatch[1];
326
- const tagsMatch = frontmatter.match(/tags:\s*\[(.+)\]/);
327
- if (tagsMatch) {
328
- tags = tagsMatch[1].split(",").map((t) => t.trim().replace(/['"]/g, ""));
622
+ /**
623
+ * 检查资源是否存在
624
+ */
625
+ resourceExists(type, relativePath) {
626
+ const baseDir = this.getResourceDir(type);
627
+ return fs4.existsSync(path4.join(baseDir, relativePath));
628
+ }
629
+ /**
630
+ * 获取包版本
631
+ */
632
+ getPackageVersion() {
633
+ try {
634
+ const packageJsonPath = path4.join(this.packageRoot, "package.json");
635
+ if (fs4.existsSync(packageJsonPath)) {
636
+ const packageJson = JSON.parse(fs4.readFileSync(packageJsonPath, "utf-8"));
637
+ return packageJson.version || "unknown";
638
+ }
639
+ } catch {
329
640
  }
641
+ return "unknown";
330
642
  }
331
- }
332
- const titleMatch = content.match(/^#\s+(.+)$/m);
333
- const title = titleMatch ? titleMatch[1] : id;
334
- return {
335
- id,
336
- path: filePath,
337
- title,
338
- description,
339
- tags,
340
- applicableWhen: {
341
- frameworks: tags.filter(
342
- (t) => [
343
- "vue",
344
- "vue3",
345
- "react",
346
- "angular",
347
- "next",
348
- "nuxt",
349
- "svelte",
350
- "flutter",
351
- "express",
352
- "nestjs",
353
- "koa",
354
- "fastify"
355
- ].includes(t.toLowerCase())
356
- ),
357
- languages: tags.filter(
358
- (t) => ["typescript", "javascript", "python", "java", "go", "rust", "dart", "c++"].includes(t.toLowerCase())
359
- ),
360
- tools: tags.filter(
361
- (t) => [
362
- "vite",
363
- "webpack",
364
- "rollup",
365
- "logicflow",
366
- "element-plus",
367
- "antd",
368
- "tailwind",
369
- "sass",
370
- "echarts",
371
- "prisma",
372
- "graphql"
373
- ].includes(t.toLowerCase())
374
- ),
375
- keywords: tags.filter(
376
- (t) => [
377
- "i18n",
378
- "state-management",
379
- "routing",
380
- "testing",
381
- "mobile",
382
- "miniprogram",
383
- "database",
384
- "forms",
385
- "data-fetching"
386
- ].includes(t.toLowerCase())
387
- )
643
+ /**
644
+ * 获取资源统计信息
645
+ */
646
+ getResourceStats() {
647
+ return {
648
+ agents: this.listAgentIds().length,
649
+ standards: this.listStandards().length,
650
+ templates: this.listTemplates().length,
651
+ version: this.getPackageVersion()
652
+ };
653
+ }
654
+ walkDir(dir, baseDir, results) {
655
+ const files = fs4.readdirSync(dir);
656
+ for (const file of files) {
657
+ const filePath = path4.join(dir, file);
658
+ const stat = fs4.statSync(filePath);
659
+ if (stat.isDirectory()) {
660
+ this.walkDir(filePath, baseDir, results);
661
+ } else if (file.endsWith(".md")) {
662
+ results.push(path4.relative(baseDir, filePath));
663
+ }
664
+ }
665
+ }
666
+ log(message) {
667
+ var _a;
668
+ (_a = this.logger) == null ? void 0 : _a.log(message);
669
+ }
670
+ error(message) {
671
+ var _a;
672
+ (_a = this.logger) == null ? void 0 : _a.error(message);
388
673
  }
389
674
  };
675
+ resourceLoaderInstance = null;
390
676
  }
391
- mergeFeatures(target, source) {
392
- if (source.frameworks) target.frameworks.push(...source.frameworks);
393
- if (source.languages) target.languages.push(...source.languages);
394
- if (source.tools) target.tools.push(...source.tools);
395
- if (source.keywords) target.keywords.push(...source.keywords);
396
- }
397
- inferProjectType(features) {
398
- if (features.frameworks.some((f) => f.toLowerCase().includes("vue"))) return "vue3";
399
- if (features.frameworks.some((f) => f.toLowerCase().includes("react"))) return "react";
400
- if (features.frameworks.some((f) => f.toLowerCase().includes("angular"))) return "angular";
401
- if (features.frameworks.some((f) => f.toLowerCase().includes("svelte"))) return "svelte";
402
- if (features.frameworks.some((f) => f.toLowerCase().includes("next"))) return "nextjs";
403
- if (features.frameworks.some((f) => f.toLowerCase().includes("nuxt"))) return "nuxtjs";
404
- if (features.frameworks.some((f) => f.toLowerCase().includes("flutter"))) return "flutter";
405
- if (features.frameworks.some((f) => f.toLowerCase().includes("react-native"))) return "react-native";
406
- if (features.keywords.includes("miniprogram")) return "miniprogram";
407
- if (features.frameworks.some((f) => f.toLowerCase().includes("nest"))) return "nestjs";
408
- if (features.frameworks.some((f) => f.toLowerCase().includes("express"))) return "express";
409
- if (features.frameworks.some((f) => f.toLowerCase().includes("koa"))) return "koa";
410
- if (features.frameworks.some((f) => f.toLowerCase().includes("fastify"))) return "fastify";
411
- if (features.languages.includes("TypeScript")) return "typescript";
412
- if (features.languages.includes("Python")) return "python";
413
- if (features.languages.includes("Java")) return "java";
414
- if (features.languages.includes("Go")) return "go";
415
- if (features.languages.includes("Rust")) return "rust";
416
- return "general";
417
- }
418
- log(message) {
419
- var _a;
420
- (_a = this.logger) == null ? void 0 : _a.log(message);
421
- }
422
- };
677
+ });
678
+
679
+ // src/index.ts
680
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
681
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
682
+ import {
683
+ CallToolRequestSchema,
684
+ ListToolsRequestSchema,
685
+ ListResourcesRequestSchema,
686
+ ReadResourceRequestSchema
687
+ } from "@modelcontextprotocol/sdk/types.js";
688
+
689
+ // src/tools/analyzeProject.ts
690
+ init_smartAgentMatcher();
691
+ import * as fs3 from "fs";
692
+ import * as path3 from "path";
423
693
 
424
694
  // src/core/i18nDetector.ts
425
695
  import * as fs2 from "fs";
@@ -797,87 +1067,16 @@ async function analyzeProject(args) {
797
1067
  }
798
1068
  }
799
1069
 
800
- // src/core/githubClient.ts
801
- import axios from "axios";
802
- var GitHubClient = class {
803
- constructor(logger3) {
804
- this.logger = logger3;
805
- this.owner = "ForLear";
806
- this.repo = "copilot-prompts";
807
- this.branch = "main";
808
- this.baseUrl = "https://api.github.com";
809
- this.rawBaseUrl = "https://raw.githubusercontent.com";
810
- }
811
- /**
812
- * 列出目录中的文件
813
- */
814
- async listDirectoryFiles(dirPath) {
815
- var _a;
816
- const url = `${this.baseUrl}/repos/${this.owner}/${this.repo}/contents/${dirPath}?ref=${this.branch}`;
817
- try {
818
- const response = await axios.get(url, {
819
- headers: {
820
- "Accept": "application/vnd.github.v3+json",
821
- "User-Agent": "Copilot-Prompts-MCP-Server"
822
- }
823
- });
824
- if (Array.isArray(response.data)) {
825
- return response.data.map((item) => ({
826
- name: item.name,
827
- path: item.path,
828
- type: item.type
829
- }));
830
- }
831
- return [];
832
- } catch (error) {
833
- (_a = this.logger) == null ? void 0 : _a.error(`\u83B7\u53D6\u76EE\u5F55\u5931\u8D25: ${error}`);
834
- return [];
835
- }
836
- }
837
- /**
838
- * 获取文件内容
839
- */
840
- async fetchFileContent(filePath) {
841
- var _a;
842
- const url = `${this.rawBaseUrl}/${this.owner}/${this.repo}/${this.branch}/${filePath}`;
843
- try {
844
- const response = await axios.get(url, {
845
- headers: {
846
- "User-Agent": "Copilot-Prompts-MCP-Server"
847
- }
848
- });
849
- return response.data;
850
- } catch (error) {
851
- (_a = this.logger) == null ? void 0 : _a.error(`\u83B7\u53D6\u6587\u4EF6\u5931\u8D25: ${filePath}`);
852
- throw error;
853
- }
854
- }
855
- };
856
-
857
1070
  // src/tools/matchAgents.ts
1071
+ init_smartAgentMatcher();
1072
+ init_resourceLoader();
858
1073
  async function matchAgents(args) {
859
1074
  const logger3 = new ConsoleLogger();
860
1075
  try {
861
1076
  const matcher = new SmartAgentMatcher(logger3);
862
- const githubClient = new GitHubClient(logger3);
863
- logger3.log("\u6B63\u5728\u4ECE GitHub \u83B7\u53D6\u53EF\u7528 Agents...");
864
- const availableAgents = [];
865
- try {
866
- const agentFiles = await githubClient.listDirectoryFiles("agents");
867
- for (const file of agentFiles) {
868
- if (file.name.endsWith(".agent.md")) {
869
- try {
870
- const content = await githubClient.fetchFileContent(file.path);
871
- const metadata = matcher.parseAgentMetadata(file.path, content);
872
- availableAgents.push(metadata);
873
- } catch (error) {
874
- logger3.error(`\u89E3\u6790 ${file.name} \u5931\u8D25: ${error}`);
875
- }
876
- }
877
- }
878
- } catch (error) {
879
- logger3.error(`\u83B7\u53D6 Agents \u5931\u8D25: ${error}`);
880
- }
1077
+ const resourceLoader = getResourceLoader(logger3);
1078
+ logger3.log("\u6B63\u5728\u4ECE\u5305\u5185\u52A0\u8F7D Agents...");
1079
+ const availableAgents = resourceLoader.loadAllAgents();
881
1080
  const matchedAgents = matcher.matchAgents(args.projectFeatures, availableAgents);
882
1081
  const limit = args.limit || 10;
883
1082
  const topAgents = matchedAgents.slice(0, limit);
@@ -914,60 +1113,30 @@ async function matchAgents(args) {
914
1113
  }
915
1114
 
916
1115
  // src/tools/listAgents.ts
1116
+ init_resourceLoader();
917
1117
  async function listAvailableAgents() {
918
1118
  const logger3 = new ConsoleLogger();
919
1119
  try {
920
- const githubClient = new GitHubClient(logger3);
921
- logger3.log("\u6B63\u5728\u4ECE GitHub \u83B7\u53D6 Agents \u5217\u8868...");
922
- const agentFiles = await githubClient.listDirectoryFiles("agents");
923
- const agents = agentFiles.filter((f) => f.name.endsWith(".agent.md"));
924
- const agentList = await Promise.all(
925
- agents.map(async (file) => {
926
- try {
927
- const content = await githubClient.fetchFileContent(file.path);
928
- const lines = content.split("\n");
929
- let title = file.name.replace(".agent.md", "");
930
- let description = "";
931
- if (lines[0] === "---") {
932
- const endIndex = lines.slice(1).findIndex((l) => l === "---");
933
- if (endIndex > 0) {
934
- const frontmatter = lines.slice(1, endIndex + 1).join("\n");
935
- const descMatch = frontmatter.match(/description:\s*['"](.+)['"]/);
936
- if (descMatch) {
937
- description = descMatch[1];
938
- }
939
- }
940
- }
941
- const titleLine = lines.find((l) => l.startsWith("# "));
942
- if (titleLine) {
943
- title = titleLine.replace("# ", "").trim();
944
- }
945
- return {
946
- id: file.name.replace(".agent.md", ""),
947
- name: file.name,
948
- title,
949
- description: description || "\u6682\u65E0\u63CF\u8FF0",
950
- path: file.path
951
- };
952
- } catch (error) {
953
- logger3.error(`\u89E3\u6790 ${file.name} \u5931\u8D25: ${error}`);
954
- return null;
955
- }
956
- })
957
- );
958
- const validAgents = agentList.filter((a) => a !== null);
1120
+ const resourceLoader = getResourceLoader(logger3);
1121
+ logger3.log("\u6B63\u5728\u4ECE\u5305\u5185\u52A0\u8F7D Agents \u5217\u8868...");
1122
+ const agents = resourceLoader.loadAllAgents();
1123
+ const agentList = agents.map((agent) => ({
1124
+ id: agent.id,
1125
+ name: `${agent.id}.agent.md`,
1126
+ title: agent.title,
1127
+ description: agent.description || "\u6682\u65E0\u63CF\u8FF0",
1128
+ path: agent.path,
1129
+ tags: agent.tags
1130
+ }));
959
1131
  return {
960
1132
  content: [{
961
1133
  type: "text",
962
1134
  text: JSON.stringify({
963
1135
  success: true,
964
- total: validAgents.length,
965
- agents: validAgents,
966
- categories: {
967
- general: validAgents.filter((a) => a.path.includes("common/")).length,
968
- frameworks: validAgents.filter((a) => a.path.includes("vue/") || a.path.includes("react/")).length,
969
- agents: validAgents.filter((a) => a.path.includes("agents/")).length
970
- }
1136
+ total: agentList.length,
1137
+ agents: agentList,
1138
+ source: "npm-package",
1139
+ version: resourceLoader.getPackageVersion()
971
1140
  }, null, 2)
972
1141
  }]
973
1142
  };
@@ -985,9 +1154,69 @@ async function listAvailableAgents() {
985
1154
  }
986
1155
 
987
1156
  // src/tools/generateConfig.ts
988
- import * as fs4 from "fs";
989
- import * as path4 from "path";
990
- import { fileURLToPath } from "url";
1157
+ import * as fs5 from "fs";
1158
+ import * as path5 from "path";
1159
+ import { fileURLToPath as fileURLToPath2 } from "url";
1160
+
1161
+ // src/core/githubClient.ts
1162
+ import axios from "axios";
1163
+ var GitHubClient = class {
1164
+ constructor(logger3) {
1165
+ this.logger = logger3;
1166
+ this.owner = "ForLear";
1167
+ this.repo = "copilot-prompts";
1168
+ this.branch = "main";
1169
+ this.baseUrl = "https://api.github.com";
1170
+ this.rawBaseUrl = "https://raw.githubusercontent.com";
1171
+ }
1172
+ /**
1173
+ * 列出目录中的文件
1174
+ */
1175
+ async listDirectoryFiles(dirPath) {
1176
+ var _a;
1177
+ const url = `${this.baseUrl}/repos/${this.owner}/${this.repo}/contents/${dirPath}?ref=${this.branch}`;
1178
+ try {
1179
+ const response = await axios.get(url, {
1180
+ headers: {
1181
+ "Accept": "application/vnd.github.v3+json",
1182
+ "User-Agent": "Copilot-Prompts-MCP-Server"
1183
+ }
1184
+ });
1185
+ if (Array.isArray(response.data)) {
1186
+ return response.data.map((item) => ({
1187
+ name: item.name,
1188
+ path: item.path,
1189
+ type: item.type
1190
+ }));
1191
+ }
1192
+ return [];
1193
+ } catch (error) {
1194
+ (_a = this.logger) == null ? void 0 : _a.error(`\u83B7\u53D6\u76EE\u5F55\u5931\u8D25: ${error}`);
1195
+ return [];
1196
+ }
1197
+ }
1198
+ /**
1199
+ * 获取文件内容
1200
+ */
1201
+ async fetchFileContent(filePath) {
1202
+ var _a;
1203
+ const url = `${this.rawBaseUrl}/${this.owner}/${this.repo}/${this.branch}/${filePath}`;
1204
+ try {
1205
+ const response = await axios.get(url, {
1206
+ headers: {
1207
+ "User-Agent": "Copilot-Prompts-MCP-Server"
1208
+ }
1209
+ });
1210
+ return response.data;
1211
+ } catch (error) {
1212
+ (_a = this.logger) == null ? void 0 : _a.error(`\u83B7\u53D6\u6587\u4EF6\u5931\u8D25: ${filePath}`);
1213
+ throw error;
1214
+ }
1215
+ }
1216
+ };
1217
+
1218
+ // src/tools/generateConfig.ts
1219
+ init_smartAgentMatcher();
991
1220
 
992
1221
  // src/core/codeValidator.ts
993
1222
  var CodeValidator = class {
@@ -1248,12 +1477,13 @@ var CodeValidator = class {
1248
1477
  };
1249
1478
 
1250
1479
  // src/tools/generateConfig.ts
1251
- var __filename = fileURLToPath(import.meta.url);
1252
- var __dirname2 = path4.dirname(__filename);
1480
+ init_resourceLoader();
1481
+ var __filename2 = fileURLToPath2(import.meta.url);
1482
+ var __dirname3 = path5.dirname(__filename2);
1253
1483
  async function generateConfig(args) {
1254
1484
  const logger3 = new ConsoleLogger();
1255
1485
  try {
1256
- if (!fs4.existsSync(args.projectPath)) {
1486
+ if (!fs5.existsSync(args.projectPath)) {
1257
1487
  return {
1258
1488
  content: [{
1259
1489
  type: "text",
@@ -1270,51 +1500,15 @@ async function generateConfig(args) {
1270
1500
  logger3.log("\u6B63\u5728\u5206\u6790\u9879\u76EE\u7279\u5F81...");
1271
1501
  const workspaceFolder = {
1272
1502
  uri: { fsPath: args.projectPath },
1273
- name: path4.basename(args.projectPath),
1503
+ name: path5.basename(args.projectPath),
1274
1504
  index: 0
1275
1505
  };
1276
1506
  const features = await matcher.analyzeProject(workspaceFolder);
1277
1507
  logger3.log("\u6B63\u5728\u5339\u914D Agents...");
1278
- const availableAgents = [];
1279
- try {
1280
- logger3.log("\u{1F4E1} \u4ECE GitHub \u83B7\u53D6 Agents...");
1281
- const agentFiles = await githubClient.listDirectoryFiles("agents");
1282
- for (const file of agentFiles) {
1283
- if (file.name.endsWith(".agent.md")) {
1284
- try {
1285
- const content2 = await githubClient.fetchFileContent(file.path);
1286
- const metadata = matcher.parseAgentMetadata(file.path, content2);
1287
- availableAgents.push(metadata);
1288
- logger3.log(`\u2705 \u52A0\u8F7D Agent: ${metadata.title}`);
1289
- } catch (error) {
1290
- logger3.error(`\u89E3\u6790 ${file.name} \u5931\u8D25`);
1291
- }
1292
- }
1293
- }
1294
- logger3.log(`\u2705 \u4ECE GitHub \u6210\u529F\u52A0\u8F7D ${availableAgents.length} \u4E2A Agents`);
1295
- } catch (githubError) {
1296
- logger3.log("\u26A0\uFE0F GitHub \u83B7\u53D6\u5931\u8D25\uFF0C\u5C1D\u8BD5\u4ECE\u672C\u5730\u52A0\u8F7D...");
1297
- const agentsDir = path4.join(__dirname2, "../../../agents");
1298
- if (fs4.existsSync(agentsDir)) {
1299
- const agentFiles = fs4.readdirSync(agentsDir);
1300
- logger3.log(`\u627E\u5230 ${agentFiles.length} \u4E2A\u672C\u5730\u6587\u4EF6`);
1301
- for (const file of agentFiles) {
1302
- if (file.endsWith(".agent.md")) {
1303
- try {
1304
- const filePath = path4.join(agentsDir, file);
1305
- const content2 = fs4.readFileSync(filePath, "utf-8");
1306
- const metadata = matcher.parseAgentMetadata(`agents/${file}`, content2);
1307
- availableAgents.push(metadata);
1308
- logger3.log(`\u2705 \u52A0\u8F7D Agent: ${metadata.title}`);
1309
- } catch (error) {
1310
- logger3.error(`\u89E3\u6790 ${file} \u5931\u8D25`);
1311
- }
1312
- }
1313
- }
1314
- logger3.log(`\u2705 \u4ECE\u672C\u5730\u6210\u529F\u52A0\u8F7D ${availableAgents.length} \u4E2A Agents`);
1315
- } else {
1316
- throw new Error("\u65E0\u6CD5\u4ECE GitHub \u6216\u672C\u5730\u83B7\u53D6 Agents");
1317
- }
1508
+ const resourceLoader = getResourceLoader(logger3);
1509
+ const availableAgents = resourceLoader.loadAllAgents();
1510
+ if (availableAgents.length === 0) {
1511
+ throw new Error("\u65E0\u6CD5\u52A0\u8F7D Agents\uFF0C\u8BF7\u68C0\u67E5 npm \u5305\u662F\u5426\u5B8C\u6574");
1318
1512
  }
1319
1513
  logger3.log(`\u6210\u529F\u52A0\u8F7D ${availableAgents.length} \u4E2A Agents`);
1320
1514
  selectedAgents = matcher.matchAgents(features, availableAgents);
@@ -1324,29 +1518,14 @@ async function generateConfig(args) {
1324
1518
  if (args.agentIds && args.agentIds.length > 0) {
1325
1519
  logger3.log(`\u4F7F\u7528\u6307\u5B9A\u7684 Agents: ${args.agentIds.join(", ")}`);
1326
1520
  selectedAgents = [];
1521
+ const resourceLoader = getResourceLoader(logger3);
1327
1522
  for (const id of args.agentIds) {
1328
- try {
1329
- let content2;
1330
- const agentPath = `agents/${id}.agent.md`;
1331
- try {
1332
- logger3.log(`\u4ECE GitHub \u83B7\u53D6 Agent: ${id}`);
1333
- content2 = await githubClient.fetchFileContent(agentPath);
1334
- logger3.log(`\u2705 \u4ECE GitHub \u52A0\u8F7D\u6210\u529F: ${id}`);
1335
- } catch (githubError) {
1336
- logger3.log(`GitHub \u83B7\u53D6\u5931\u8D25\uFF0C\u5C1D\u8BD5\u672C\u5730: ${id}`);
1337
- const agentsDir = path4.join(__dirname2, "../../../agents");
1338
- const localPath = path4.join(agentsDir, `${id}.agent.md`);
1339
- if (fs4.existsSync(localPath)) {
1340
- content2 = fs4.readFileSync(localPath, "utf-8");
1341
- logger3.log(`\u2705 \u4ECE\u672C\u5730\u52A0\u8F7D\u6210\u529F: ${id}`);
1342
- } else {
1343
- throw new Error(`Agent ${id} \u4E0D\u5B58\u5728\uFF08GitHub \u548C\u672C\u5730\u90FD\u672A\u627E\u5230\uFF09`);
1344
- }
1345
- }
1346
- const metadata = matcher.parseAgentMetadata(`agents/${id}.agent.md`, content2);
1347
- selectedAgents.push(metadata);
1348
- } catch (error) {
1349
- logger3.error(`\u83B7\u53D6 Agent ${id} \u5931\u8D25: ${error}`);
1523
+ const agentData = resourceLoader.loadAgent(id);
1524
+ if (agentData) {
1525
+ selectedAgents.push(agentData.metadata);
1526
+ logger3.log(`\u2705 \u52A0\u8F7D Agent: ${id}`);
1527
+ } else {
1528
+ logger3.error(`Agent ${id} \u4E0D\u5B58\u5728`);
1350
1529
  }
1351
1530
  }
1352
1531
  }
@@ -1361,19 +1540,19 @@ async function generateConfig(args) {
1361
1540
  };
1362
1541
  }
1363
1542
  logger3.log("\u6B63\u5728\u751F\u6210\u914D\u7F6E\u6587\u4EF6...");
1364
- const githubDir = path4.join(args.projectPath, ".github");
1365
- const configPath = path4.join(githubDir, "copilot-instructions.md");
1543
+ const githubDir = path5.join(args.projectPath, ".github");
1544
+ const configPath = path5.join(githubDir, "copilot-instructions.md");
1366
1545
  let existingCustomContent = "";
1367
1546
  let existingConfig = "";
1368
- if (fs4.existsSync(configPath)) {
1369
- existingConfig = fs4.readFileSync(configPath, "utf-8");
1547
+ if (fs5.existsSync(configPath)) {
1548
+ existingConfig = fs5.readFileSync(configPath, "utf-8");
1370
1549
  const customMatch = existingConfig.match(/<!-- CUSTOM_START -->([\s\S]*?)<!-- CUSTOM_END -->/g);
1371
1550
  if (customMatch) {
1372
1551
  existingCustomContent = customMatch.join("\n\n");
1373
1552
  }
1374
1553
  }
1375
- if (!fs4.existsSync(githubDir)) {
1376
- fs4.mkdirSync(githubDir, { recursive: true });
1554
+ if (!fs5.existsSync(githubDir)) {
1555
+ fs5.mkdirSync(githubDir, { recursive: true });
1377
1556
  }
1378
1557
  const updateMode = args.updateMode || "merge";
1379
1558
  let content = "";
@@ -1398,7 +1577,7 @@ async function generateConfig(args) {
1398
1577
 
1399
1578
  `;
1400
1579
  }
1401
- const projectName = path4.basename(args.projectPath);
1580
+ const projectName = path5.basename(args.projectPath);
1402
1581
  const projectPath = args.projectPath;
1403
1582
  content += `<!-- \u{1F3AF} \u4F5C\u7528\u57DF\uFF1A\u6B64\u914D\u7F6E\u4EC5\u9002\u7528\u4E8E\u5F53\u524D\u9879\u76EE -->
1404
1583
  `;
@@ -1491,9 +1670,9 @@ async function generateConfig(args) {
1491
1670
  `;
1492
1671
  if (args.configId) {
1493
1672
  try {
1494
- const configFilePath = path4.join(__dirname2, "../../../configs", `element-plus-${args.configId}.json`);
1495
- if (fs4.existsSync(configFilePath)) {
1496
- const configData = JSON.parse(fs4.readFileSync(configFilePath, "utf-8"));
1673
+ const configFilePath = path5.join(__dirname3, "../../../configs", `element-plus-${args.configId}.json`);
1674
+ if (fs5.existsSync(configFilePath)) {
1675
+ const configData = JSON.parse(fs5.readFileSync(configFilePath, "utf-8"));
1497
1676
  content += `## \u{1F4E6} \u914D\u7F6E\u65B9\u6848
1498
1677
 
1499
1678
  `;
@@ -1657,13 +1836,13 @@ async function generateConfig(args) {
1657
1836
  } else {
1658
1837
  logger3.log("\u2705 \u914D\u7F6E\u5185\u5BB9\u9A8C\u8BC1\u901A\u8FC7");
1659
1838
  }
1660
- fs4.writeFileSync(configPath, content, "utf-8");
1661
- const gitignorePath = path4.join(args.projectPath, ".gitignore");
1662
- if (fs4.existsSync(gitignorePath)) {
1663
- let gitignoreContent = fs4.readFileSync(gitignorePath, "utf-8");
1839
+ fs5.writeFileSync(configPath, content, "utf-8");
1840
+ const gitignorePath = path5.join(args.projectPath, ".gitignore");
1841
+ if (fs5.existsSync(gitignorePath)) {
1842
+ let gitignoreContent = fs5.readFileSync(gitignorePath, "utf-8");
1664
1843
  if (!gitignoreContent.includes(".github/copilot-instructions.md")) {
1665
1844
  gitignoreContent += "\n# Copilot Prompts (auto-generated)\n.github/copilot-instructions.md\n";
1666
- fs4.writeFileSync(gitignorePath, gitignoreContent, "utf-8");
1845
+ fs5.writeFileSync(gitignorePath, gitignoreContent, "utf-8");
1667
1846
  }
1668
1847
  }
1669
1848
  logger3.log(`\u2705 \u914D\u7F6E\u6587\u4EF6\u5DF2\u751F\u6210: ${configPath}`);
@@ -1696,14 +1875,14 @@ async function generateConfig(args) {
1696
1875
  }
1697
1876
 
1698
1877
  // src/tools/autoSetup.ts
1699
- import * as fs5 from "fs";
1700
- import * as path5 from "path";
1878
+ import * as fs6 from "fs";
1879
+ import * as path6 from "path";
1701
1880
  async function autoSetup(args) {
1702
- var _a, _b, _c, _d, _e, _f, _g;
1881
+ var _a, _b;
1703
1882
  const logger3 = new ConsoleLogger();
1704
1883
  try {
1705
1884
  const workspacePath = args.workspacePath || process.cwd();
1706
- if (!fs5.existsSync(workspacePath)) {
1885
+ if (!fs6.existsSync(workspacePath)) {
1707
1886
  return {
1708
1887
  content: [{
1709
1888
  type: "text",
@@ -1719,130 +1898,94 @@ async function autoSetup(args) {
1719
1898
  warnings: []
1720
1899
  };
1721
1900
  logger3.log("\u{1F680} \u5F00\u59CB\u81EA\u52A8\u914D\u7F6E MCP \u670D\u52A1\u5668...");
1722
- const vscodeDir = path5.join(workspacePath, ".vscode");
1723
- if (!fs5.existsSync(vscodeDir)) {
1724
- fs5.mkdirSync(vscodeDir, { recursive: true });
1901
+ const vscodeDir = path6.join(workspacePath, ".vscode");
1902
+ if (!fs6.existsSync(vscodeDir)) {
1903
+ fs6.mkdirSync(vscodeDir, { recursive: true });
1725
1904
  results.steps.push({ step: "\u521B\u5EFA .vscode \u76EE\u5F55", status: "success" });
1726
1905
  } else {
1727
1906
  results.steps.push({ step: "\u68C0\u6D4B\u5230\u5DF2\u6709 .vscode \u76EE\u5F55", status: "skip" });
1728
1907
  }
1729
- let mcpServerPath = "";
1730
- const possiblePaths = [
1731
- path5.join(workspacePath, "mcp-server/build/index.js"),
1732
- path5.join(workspacePath, "../copilot-prompts/mcp-server/build/index.js"),
1733
- path5.join(workspacePath, "copilot-prompts/mcp-server/build/index.js")
1734
- ];
1735
- for (const p of possiblePaths) {
1736
- if (fs5.existsSync(p)) {
1737
- mcpServerPath = p;
1738
- break;
1739
- }
1740
- }
1741
- if (!mcpServerPath) {
1742
- const srcPath = path5.join(workspacePath, "mcp-server/src/index.ts");
1743
- if (fs5.existsSync(srcPath)) {
1744
- results.warnings.push("\u68C0\u6D4B\u5230\u5F00\u53D1\u6A21\u5F0F\uFF0C\u8BF7\u5148\u8FD0\u884C npm run build \u7F16\u8BD1\u670D\u52A1\u5668");
1745
- mcpServerPath = "${workspaceFolder}/mcp-server/build/index.js";
1746
- } else {
1747
- return {
1748
- content: [{
1749
- type: "text",
1750
- text: JSON.stringify({
1751
- error: "MCP \u670D\u52A1\u5668\u672A\u627E\u5230",
1752
- hint: "\u8BF7\u786E\u4FDD mcp-server/build/index.js \u5B58\u5728\uFF0C\u6216\u8FD0\u884C npm run build"
1753
- }, null, 2)
1754
- }]
1755
- };
1756
- }
1757
- }
1758
- const relativePath = mcpServerPath.startsWith(workspacePath) ? "${workspaceFolder}/" + path5.relative(workspacePath, mcpServerPath) : mcpServerPath;
1759
1908
  results.steps.push({
1760
- step: "\u68C0\u6D4B MCP \u670D\u52A1\u5668\u8DEF\u5F84",
1909
+ step: "\u4F7F\u7528 npx mta-mcp \u914D\u7F6E",
1761
1910
  status: "success",
1762
- detail: relativePath
1911
+ detail: "\u901A\u8FC7 npm \u5305\u8FD0\u884C\uFF0C\u65E0\u9700\u672C\u5730\u5B89\u88C5"
1763
1912
  });
1764
- const mcpJsonPath = path5.join(vscodeDir, "mcp.json");
1913
+ const mcpJsonPath = path6.join(vscodeDir, "mcp.json");
1765
1914
  const mcpConfig = {
1766
1915
  servers: {
1767
- "copilot-prompts": {
1768
- command: "node",
1769
- args: [relativePath],
1770
- env: {},
1771
- autoStart: true
1916
+ "mta": {
1917
+ command: "npx",
1918
+ args: ["-y", "mta-mcp"],
1919
+ env: {}
1772
1920
  }
1773
1921
  }
1774
1922
  };
1775
- if (fs5.existsSync(mcpJsonPath)) {
1923
+ if (fs6.existsSync(mcpJsonPath)) {
1776
1924
  try {
1777
- const existingConfig = JSON.parse(fs5.readFileSync(mcpJsonPath, "utf-8"));
1925
+ const existingConfig = JSON.parse(fs6.readFileSync(mcpJsonPath, "utf-8"));
1778
1926
  if (existingConfig.mcpServers && !existingConfig.servers) {
1779
1927
  results.warnings.push("\u68C0\u6D4B\u5230\u65E7\u7248\u914D\u7F6E\u683C\u5F0F(mcpServers)\uFF0C\u5DF2\u81EA\u52A8\u5347\u7EA7\u4E3A\u65B0\u683C\u5F0F(servers)");
1780
1928
  existingConfig.servers = existingConfig.mcpServers;
1781
1929
  delete existingConfig.mcpServers;
1782
1930
  }
1783
- if ((_a = existingConfig.servers) == null ? void 0 : _a["copilot-prompts"]) {
1784
- existingConfig.servers["copilot-prompts"] = {
1785
- ...mcpConfig.servers["copilot-prompts"],
1786
- ...existingConfig.servers["copilot-prompts"]
1787
- };
1788
- fs5.writeFileSync(mcpJsonPath, JSON.stringify(existingConfig, null, 2));
1789
- results.steps.push({ step: "\u66F4\u65B0 mcp.json", status: "success" });
1931
+ if ((_a = existingConfig.servers) == null ? void 0 : _a.mta) {
1932
+ results.steps.push({ step: "mcp.json \u5DF2\u5305\u542B mta \u914D\u7F6E", status: "skip" });
1790
1933
  } else {
1791
1934
  existingConfig.servers = {
1792
1935
  ...existingConfig.servers,
1793
1936
  ...mcpConfig.servers
1794
1937
  };
1795
- fs5.writeFileSync(mcpJsonPath, JSON.stringify(existingConfig, null, 2));
1796
- results.steps.push({ step: "\u5408\u5E76\u914D\u7F6E\u5230 mcp.json", status: "success" });
1938
+ fs6.writeFileSync(mcpJsonPath, JSON.stringify(existingConfig, null, 2));
1939
+ results.steps.push({ step: "\u6DFB\u52A0 mta \u5230 mcp.json", status: "success" });
1797
1940
  }
1798
1941
  } catch (err) {
1799
- fs5.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 2));
1942
+ fs6.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 2));
1800
1943
  results.steps.push({ step: "\u91CD\u65B0\u521B\u5EFA mcp.json", status: "success" });
1801
1944
  results.warnings.push(`\u539F\u914D\u7F6E\u6587\u4EF6\u89E3\u6790\u5931\u8D25: ${err}`);
1802
1945
  }
1803
1946
  } else {
1804
- fs5.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 2));
1947
+ fs6.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 2));
1805
1948
  results.steps.push({ step: "\u521B\u5EFA mcp.json", status: "success" });
1806
1949
  }
1807
- const settingsJsonPath = path5.join(vscodeDir, "settings.json");
1950
+ const settingsJsonPath = path6.join(vscodeDir, "settings.json");
1808
1951
  const mcpSettings = {
1809
1952
  "github.copilot.chat.mcp.enabled": true,
1810
1953
  "github.copilot.chat.mcp.configFile": "${workspaceFolder}/.vscode/mcp.json",
1811
1954
  "github.copilot.chat.mcp.autoStart": true
1812
1955
  };
1813
- if (fs5.existsSync(settingsJsonPath)) {
1956
+ if (fs6.existsSync(settingsJsonPath)) {
1814
1957
  try {
1815
- const existingSettings = JSON.parse(fs5.readFileSync(settingsJsonPath, "utf-8"));
1958
+ const existingSettings = JSON.parse(fs6.readFileSync(settingsJsonPath, "utf-8"));
1816
1959
  const updated = { ...existingSettings, ...mcpSettings };
1817
- fs5.writeFileSync(settingsJsonPath, JSON.stringify(updated, null, 2) + "\n");
1960
+ fs6.writeFileSync(settingsJsonPath, JSON.stringify(updated, null, 2) + "\n");
1818
1961
  results.steps.push({ step: "\u66F4\u65B0 settings.json", status: "success" });
1819
1962
  } catch {
1820
- fs5.writeFileSync(settingsJsonPath, JSON.stringify(mcpSettings, null, 2) + "\n");
1963
+ fs6.writeFileSync(settingsJsonPath, JSON.stringify(mcpSettings, null, 2) + "\n");
1821
1964
  results.steps.push({ step: "\u91CD\u65B0\u521B\u5EFA settings.json", status: "success" });
1822
1965
  }
1823
1966
  } else {
1824
- fs5.writeFileSync(settingsJsonPath, JSON.stringify(mcpSettings, null, 2) + "\n");
1967
+ fs6.writeFileSync(settingsJsonPath, JSON.stringify(mcpSettings, null, 2) + "\n");
1825
1968
  results.steps.push({ step: "\u521B\u5EFA settings.json", status: "success" });
1826
1969
  }
1827
- const extensionsJsonPath = path5.join(vscodeDir, "extensions.json");
1970
+ const extensionsJsonPath = path6.join(vscodeDir, "extensions.json");
1828
1971
  const recommendedExtensions = {
1829
1972
  recommendations: [
1830
1973
  "github.copilot",
1831
1974
  "github.copilot-chat"
1832
1975
  ]
1833
1976
  };
1834
- if (!fs5.existsSync(extensionsJsonPath)) {
1835
- fs5.writeFileSync(extensionsJsonPath, JSON.stringify(recommendedExtensions, null, 2));
1977
+ if (!fs6.existsSync(extensionsJsonPath)) {
1978
+ fs6.writeFileSync(extensionsJsonPath, JSON.stringify(recommendedExtensions, null, 2));
1836
1979
  results.steps.push({ step: "\u521B\u5EFA extensions.json", status: "success" });
1837
1980
  } else {
1838
1981
  results.steps.push({ step: "extensions.json \u5DF2\u5B58\u5728", status: "skip" });
1839
1982
  }
1840
- const gitignorePath = path5.join(workspacePath, ".gitignore");
1841
- if (fs5.existsSync(gitignorePath)) {
1842
- const gitignoreContent = fs5.readFileSync(gitignorePath, "utf-8");
1983
+ const gitignorePath = path6.join(workspacePath, ".gitignore");
1984
+ if (fs6.existsSync(gitignorePath)) {
1985
+ const gitignoreContent = fs6.readFileSync(gitignorePath, "utf-8");
1843
1986
  if (!gitignoreContent.includes(".vscode/mcp.json")) {
1844
1987
  const updatedContent = gitignoreContent + "\n# MCP \u914D\u7F6E\uFF08\u672C\u5730\uFF09\n.vscode/mcp.json\n";
1845
- fs5.writeFileSync(gitignorePath, updatedContent);
1988
+ fs6.writeFileSync(gitignorePath, updatedContent);
1846
1989
  results.steps.push({ step: "\u6DFB\u52A0\u5230 .gitignore", status: "success" });
1847
1990
  } else {
1848
1991
  results.steps.push({ step: ".gitignore \u5DF2\u5305\u542B\u914D\u7F6E", status: "skip" });
@@ -1851,62 +1994,45 @@ async function autoSetup(args) {
1851
1994
  results.warnings.push("\u672A\u68C0\u6D4B\u5230 .gitignore\uFF0C\u5EFA\u8BAE\u624B\u52A8\u6DFB\u52A0 .vscode/mcp.json");
1852
1995
  }
1853
1996
  const generateInstructions = args.generateInstructions !== false;
1997
+ const instructionsPath = path6.join(workspacePath, ".github", "copilot-instructions.md");
1998
+ const hasExistingInstructions = fs6.existsSync(instructionsPath);
1854
1999
  if (generateInstructions) {
1855
- logger3.log("\u{1F50D} \u5206\u6790\u9879\u76EE\u5E76\u751F\u6210 copilot-instructions.md...");
1856
- try {
1857
- const analysisResult = await analyzeProject({ projectPath: workspacePath });
1858
- const analysisContent = analysisResult.content[0];
1859
- if (analysisContent.type === "text") {
1860
- const analysisData = JSON.parse(analysisContent.text);
1861
- if (analysisData.success && analysisData.features) {
1862
- const agentIds = [];
1863
- const features = analysisData.features;
1864
- if (((_b = features.frameworks) == null ? void 0 : _b.includes("Vue 3")) || ((_c = features.frameworks) == null ? void 0 : _c.includes("Vue"))) {
1865
- agentIds.push("vue3");
1866
- }
1867
- if ((_d = features.tools) == null ? void 0 : _d.includes("LogicFlow")) {
1868
- agentIds.push("logicflow");
1869
- }
1870
- if (((_e = features.keywords) == null ? void 0 : _e.includes("i18n")) || ((_f = features.keywords) == null ? void 0 : _f.includes("\u56FD\u9645\u5316"))) {
1871
- agentIds.push("i18n");
1872
- }
1873
- if (features.projectType === "flutter") {
1874
- agentIds.push("flutter");
1875
- }
1876
- if (features.projectType === "wechat-miniprogram") {
1877
- agentIds.push("wechat-miniprogram");
1878
- }
1879
- if (agentIds.length > 0) {
1880
- const configResult = await generateConfig({
1881
- projectPath: workspacePath,
1882
- agentIds,
1883
- autoMatch: false,
1884
- updateMode: "merge"
2000
+ if (hasExistingInstructions) {
2001
+ results.steps.push({
2002
+ step: "\u68C0\u6D4B\u5230\u5DF2\u6709 copilot-instructions.md",
2003
+ status: "skip",
2004
+ detail: "\u4FDD\u7559\u73B0\u6709\u914D\u7F6E\uFF0C\u4E0D\u81EA\u52A8\u8986\u76D6"
2005
+ });
2006
+ } else {
2007
+ logger3.log("\u{1F50D} \u672A\u68C0\u6D4B\u5230\u914D\u7F6E\u6587\u4EF6\uFF0C\u5F00\u59CB\u5206\u6790\u9879\u76EE...");
2008
+ try {
2009
+ const configResult = await generateConfig({
2010
+ projectPath: workspacePath,
2011
+ autoMatch: true,
2012
+ updateMode: "merge"
2013
+ });
2014
+ const configContent = configResult.content[0];
2015
+ if (configContent.type === "text") {
2016
+ const configData = JSON.parse(configContent.text);
2017
+ if (configData.success) {
2018
+ const agentIds = ((_b = configData.agents) == null ? void 0 : _b.map((a) => a.id || a.title)) || [];
2019
+ results.steps.push({
2020
+ step: "\u2705 \u81EA\u52A8\u751F\u6210 copilot-instructions.md",
2021
+ status: "success",
2022
+ detail: `\u5E94\u7528\u4E86 ${agentIds.length} \u4E2A Agents: ${agentIds.join(", ")}`
1885
2023
  });
1886
- const configContent = configResult.content[0];
1887
- if (configContent.type === "text") {
1888
- const configData = JSON.parse(configContent.text);
1889
- if (configData.success) {
1890
- results.steps.push({
1891
- step: "\u751F\u6210 copilot-instructions.md",
1892
- status: "success",
1893
- detail: `\u5E94\u7528\u4E86 ${((_g = configData.agents) == null ? void 0 : _g.length) || 0} \u4E2A Agents: ${agentIds.join(", ")}`
1894
- });
1895
- } else {
1896
- results.warnings.push(`\u914D\u7F6E\u751F\u6210\u5931\u8D25: ${configData.error || "\u672A\u77E5\u9519\u8BEF"}`);
1897
- }
1898
- }
1899
2024
  } else {
1900
- results.warnings.push("\u672A\u627E\u5230\u5339\u914D\u7684 Agents\uFF0C\u8DF3\u8FC7\u914D\u7F6E\u751F\u6210");
1901
- results.warnings.push("\u4F60\u53EF\u4EE5\u7A0D\u540E\u624B\u52A8\u8FD0\u884C generate_config \u5DE5\u5177\u5E76\u6307\u5B9A agentIds");
2025
+ results.warnings.push(`\u26A0\uFE0F \u914D\u7F6E\u751F\u6210\u5931\u8D25: ${configData.error || "\u672A\u77E5\u9519\u8BEF"}`);
2026
+ results.warnings.push("\u{1F4A1} \u5EFA\u8BAE\uFF1A\u624B\u52A8\u8C03\u7528 generate_config \u5DE5\u5177\u5E76\u6307\u5B9A agentIds");
2027
+ results.warnings.push(' \u4F8B\u5982: generate_config({ projectPath: "' + workspacePath + '", agentIds: ["vue3", "i18n"] })');
1902
2028
  }
1903
- } else {
1904
- results.warnings.push(`\u9879\u76EE\u5206\u6790\u5931\u8D25: ${analysisData.error || "\u672A\u77E5\u9519\u8BEF"}`);
1905
2029
  }
2030
+ } catch (error) {
2031
+ results.warnings.push(`\u26A0\uFE0F \u81EA\u52A8\u751F\u6210\u914D\u7F6E\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
2032
+ results.warnings.push("\u{1F4A1} \u4F60\u53EF\u4EE5\u7A0D\u540E\u624B\u52A8\u8FD0\u884C\u4EE5\u4E0B\u547D\u4EE4\uFF1A");
2033
+ results.warnings.push(' 1. analyze_project({ projectPath: "' + workspacePath + '" })');
2034
+ results.warnings.push(' 2. generate_config({ projectPath: "' + workspacePath + '", autoMatch: true })');
1906
2035
  }
1907
- } catch (error) {
1908
- results.warnings.push(`\u81EA\u52A8\u751F\u6210\u914D\u7F6E\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
1909
- results.warnings.push("\u4F60\u53EF\u4EE5\u7A0D\u540E\u624B\u52A8\u8FD0\u884C generate_config \u5DE5\u5177\u751F\u6210\u914D\u7F6E");
1910
2036
  }
1911
2037
  } else {
1912
2038
  results.steps.push({ step: "\u8DF3\u8FC7 copilot-instructions.md \u751F\u6210", status: "skip" });
@@ -1942,11 +2068,11 @@ async function autoSetup(args) {
1942
2068
  }
1943
2069
 
1944
2070
  // src/core/standardsManager.ts
1945
- import * as fs6 from "fs";
1946
- import * as path6 from "path";
1947
- import { fileURLToPath as fileURLToPath2 } from "url";
1948
- var __filename2 = fileURLToPath2(import.meta.url);
1949
- var __dirname3 = path6.dirname(__filename2);
2071
+ import * as fs7 from "fs";
2072
+ import * as path7 from "path";
2073
+ import { fileURLToPath as fileURLToPath3 } from "url";
2074
+ var __filename3 = fileURLToPath3(import.meta.url);
2075
+ var __dirname4 = path7.dirname(__filename3);
1950
2076
  var StandardsManager = class {
1951
2077
  constructor() {
1952
2078
  // v1.2.0: 底层必须加载的核心规范
@@ -1979,9 +2105,9 @@ var StandardsManager = class {
1979
2105
  averageResponseTime: 0,
1980
2106
  totalTokensSaved: 0
1981
2107
  };
1982
- const devPath = path6.resolve(__dirname3, "../../../standards");
1983
- const npmPath = path6.resolve(__dirname3, "../../standards");
1984
- this.standardsPath = fs6.existsSync(npmPath) ? npmPath : devPath;
2108
+ const devPath = path7.resolve(__dirname4, "../../../standards");
2109
+ const npmPath = path7.resolve(__dirname4, "../../standards");
2110
+ this.standardsPath = fs7.existsSync(npmPath) ? npmPath : devPath;
1985
2111
  }
1986
2112
  /**
1987
2113
  * 获取所有可用的规范资源
@@ -1995,11 +2121,11 @@ var StandardsManager = class {
1995
2121
  { dir: "patterns", name: "\u8BBE\u8BA1\u6A21\u5F0F" }
1996
2122
  ];
1997
2123
  categories.forEach(({ dir, name: categoryName }) => {
1998
- const categoryPath = path6.join(this.standardsPath, dir);
1999
- if (!fs6.existsSync(categoryPath)) {
2124
+ const categoryPath = path7.join(this.standardsPath, dir);
2125
+ if (!fs7.existsSync(categoryPath)) {
2000
2126
  return;
2001
2127
  }
2002
- const files = fs6.readdirSync(categoryPath).filter((file) => file.endsWith(".md"));
2128
+ const files = fs7.readdirSync(categoryPath).filter((file) => file.endsWith(".md"));
2003
2129
  files.forEach((file) => {
2004
2130
  const standardId = file.replace(".md", "");
2005
2131
  standards.push({
@@ -2029,11 +2155,11 @@ var StandardsManager = class {
2029
2155
  throw new Error(`Invalid standards URI: ${uri}`);
2030
2156
  }
2031
2157
  const [, category, standardId] = match;
2032
- const filePath = path6.join(this.standardsPath, category, `${standardId}.md`);
2033
- if (!fs6.existsSync(filePath)) {
2158
+ const filePath = path7.join(this.standardsPath, category, `${standardId}.md`);
2159
+ if (!fs7.existsSync(filePath)) {
2034
2160
  throw new Error(`Standard not found: ${uri}`);
2035
2161
  }
2036
- const content = fs6.readFileSync(filePath, "utf-8");
2162
+ const content = fs7.readFileSync(filePath, "utf-8");
2037
2163
  this.updateCache(uri, content);
2038
2164
  this.stats.individualStandards.set(
2039
2165
  uri,
@@ -2576,11 +2702,28 @@ async function listPresets() {
2576
2702
  }
2577
2703
 
2578
2704
  // src/tools/healthCheck.ts
2579
- import * as fs7 from "fs";
2580
- import * as path7 from "path";
2581
- import { fileURLToPath as fileURLToPath3 } from "url";
2582
- var __filename3 = fileURLToPath3(import.meta.url);
2583
- var __dirname4 = path7.dirname(__filename3);
2705
+ import * as fs8 from "fs";
2706
+ import * as path8 from "path";
2707
+ import { fileURLToPath as fileURLToPath4 } from "url";
2708
+ var __filename4 = fileURLToPath4(import.meta.url);
2709
+ var __dirname5 = path8.dirname(__filename4);
2710
+ function getServerRoot() {
2711
+ const possibleRoots = [
2712
+ path8.resolve(__dirname5, "../.."),
2713
+ // 从 dist/tools/ 向上两级
2714
+ path8.resolve(__dirname5, "../../.."),
2715
+ // npm 包场景
2716
+ path8.resolve(process.cwd())
2717
+ // 当前工作目录
2718
+ ];
2719
+ for (const root of possibleRoots) {
2720
+ const standardsPath = path8.join(root, "standards");
2721
+ if (fs8.existsSync(standardsPath)) {
2722
+ return root;
2723
+ }
2724
+ }
2725
+ return possibleRoots[0];
2726
+ }
2584
2727
  async function healthCheck(args) {
2585
2728
  var _a, _b, _c, _d;
2586
2729
  const logger3 = new ConsoleLogger();
@@ -2605,14 +2748,14 @@ async function healthCheck(args) {
2605
2748
  }
2606
2749
  logger3.log("\u{1F50D} \u68C0\u67E5\u914D\u7F6E\u6587\u4EF6...");
2607
2750
  const workspacePath = args.workspacePath || process.cwd();
2608
- const vscodeDir = path7.join(workspacePath, ".vscode");
2609
- if (fs7.existsSync(vscodeDir)) {
2751
+ const vscodeDir = path8.join(workspacePath, ".vscode");
2752
+ if (fs8.existsSync(vscodeDir)) {
2610
2753
  checks.workspace.status = "healthy";
2611
2754
  checks.workspace.details.push(`\u2705 \u5DE5\u4F5C\u533A\u8DEF\u5F84: ${workspacePath}`);
2612
- const mcpJsonPath = path7.join(vscodeDir, "mcp.json");
2613
- if (fs7.existsSync(mcpJsonPath)) {
2755
+ const mcpJsonPath = path8.join(vscodeDir, "mcp.json");
2756
+ if (fs8.existsSync(mcpJsonPath)) {
2614
2757
  try {
2615
- const config = JSON.parse(fs7.readFileSync(mcpJsonPath, "utf-8"));
2758
+ const config = JSON.parse(fs8.readFileSync(mcpJsonPath, "utf-8"));
2616
2759
  const hasNewFormat = (_a = config.servers) == null ? void 0 : _a["copilot-prompts"];
2617
2760
  const hasOldFormat = (_b = config.mcpServers) == null ? void 0 : _b["copilot-prompts"];
2618
2761
  if (hasNewFormat) {
@@ -2655,10 +2798,10 @@ async function healthCheck(args) {
2655
2798
  checks.configuration.details.push("\u26A0\uFE0F mcp.json \u4E0D\u5B58\u5728");
2656
2799
  checks.configuration.details.push("\u{1F4A1} \u5EFA\u8BAE: \u8FD0\u884C auto_setup \u5DE5\u5177\u81EA\u52A8\u914D\u7F6E");
2657
2800
  }
2658
- const settingsPath = path7.join(vscodeDir, "settings.json");
2659
- if (fs7.existsSync(settingsPath)) {
2801
+ const settingsPath = path8.join(vscodeDir, "settings.json");
2802
+ if (fs8.existsSync(settingsPath)) {
2660
2803
  try {
2661
- const settings = JSON.parse(fs7.readFileSync(settingsPath, "utf-8"));
2804
+ const settings = JSON.parse(fs8.readFileSync(settingsPath, "utf-8"));
2662
2805
  if (settings["github.copilot.chat.mcp.enabled"] === true) {
2663
2806
  checks.configuration.details.push("\u2705 VS Code MCP \u5DF2\u542F\u7528");
2664
2807
  } else {
@@ -2671,13 +2814,14 @@ async function healthCheck(args) {
2671
2814
  } else {
2672
2815
  checks.workspace.status = "error";
2673
2816
  checks.workspace.details.push("\u274C .vscode \u76EE\u5F55\u4E0D\u5B58\u5728");
2817
+ checks.workspace.details.push("\u{1F4A1} \u5EFA\u8BAE: \u8FD0\u884C auto_setup \u5DE5\u5177\u81EA\u52A8\u521B\u5EFA\u914D\u7F6E");
2674
2818
  }
2675
2819
  logger3.log("\u{1F50D} \u68C0\u67E5\u4F9D\u8D56...");
2676
- const serverRoot = path7.resolve(__dirname4, "../..");
2677
- const packageJsonPath = path7.join(serverRoot, "package.json");
2678
- if (fs7.existsSync(packageJsonPath)) {
2820
+ const serverRoot = getServerRoot();
2821
+ const packageJsonPath = path8.join(serverRoot, "package.json");
2822
+ if (fs8.existsSync(packageJsonPath)) {
2679
2823
  try {
2680
- const pkg = JSON.parse(fs7.readFileSync(packageJsonPath, "utf-8"));
2824
+ const pkg = JSON.parse(fs8.readFileSync(packageJsonPath, "utf-8"));
2681
2825
  checks.dependencies.status = "healthy";
2682
2826
  checks.dependencies.details.push(`\u2705 \u670D\u52A1\u5668\u7248\u672C: ${pkg.version}`);
2683
2827
  if (verbose && pkg.dependencies) {
@@ -2701,14 +2845,14 @@ async function healthCheck(args) {
2701
2845
  }
2702
2846
  }
2703
2847
  logger3.log("\u{1F50D} \u68C0\u67E5\u89C4\u8303\u6587\u4EF6...");
2704
- const standardsDir = path7.join(serverRoot, "standards");
2705
- if (fs7.existsSync(standardsDir)) {
2848
+ const standardsDir = path8.join(serverRoot, "standards");
2849
+ if (fs8.existsSync(standardsDir)) {
2706
2850
  const categories = ["core", "frameworks", "libraries", "patterns"];
2707
2851
  const foundStandards = [];
2708
2852
  for (const category of categories) {
2709
- const categoryPath = path7.join(standardsDir, category);
2710
- if (fs7.existsSync(categoryPath)) {
2711
- const files = fs7.readdirSync(categoryPath).filter((f) => f.endsWith(".md"));
2853
+ const categoryPath = path8.join(standardsDir, category);
2854
+ if (fs8.existsSync(categoryPath)) {
2855
+ const files = fs8.readdirSync(categoryPath).filter((f) => f.endsWith(".md"));
2712
2856
  foundStandards.push(...files.map((f) => `${category}/${f}`));
2713
2857
  }
2714
2858
  }
@@ -2785,7 +2929,7 @@ function generateRecommendations(checks) {
2785
2929
  }
2786
2930
 
2787
2931
  // src/tools/getCompactStandards.ts
2788
- import * as fs8 from "fs";
2932
+ import * as fs9 from "fs";
2789
2933
  async function getCompactStandards(args) {
2790
2934
  const logger3 = new ConsoleLogger();
2791
2935
  const manager = new StandardsManager();
@@ -2832,7 +2976,7 @@ function detectContext(args, logger3) {
2832
2976
  let fileType = "unknown";
2833
2977
  let imports = [];
2834
2978
  let scenario = "";
2835
- if (args.currentFile && fs8.existsSync(args.currentFile)) {
2979
+ if (args.currentFile && fs9.existsSync(args.currentFile)) {
2836
2980
  const ext = ((_a = args.currentFile.split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
2837
2981
  const extMap = {
2838
2982
  "vue": "vue",
@@ -2844,7 +2988,7 @@ function detectContext(args, logger3) {
2844
2988
  };
2845
2989
  fileType = extMap[ext] || "unknown";
2846
2990
  try {
2847
- const content = fs8.readFileSync(args.currentFile, "utf-8");
2991
+ const content = fs9.readFileSync(args.currentFile, "utf-8");
2848
2992
  imports = extractImports(content);
2849
2993
  scenario = inferScenario(content, fileType);
2850
2994
  } catch {
@@ -3115,8 +3259,8 @@ function inferScenario(content, fileType) {
3115
3259
  }
3116
3260
 
3117
3261
  // src/tools/getStandardById.ts
3118
- import * as fs9 from "fs";
3119
- import * as path8 from "path";
3262
+ import * as fs10 from "fs";
3263
+ import * as path9 from "path";
3120
3264
  var STANDARD_DIRS = [
3121
3265
  "standards/core",
3122
3266
  "standards/frameworks",
@@ -3154,7 +3298,7 @@ async function getStandardById(args) {
3154
3298
  continue;
3155
3299
  }
3156
3300
  try {
3157
- const fullContent = fs9.readFileSync(filePath, "utf-8");
3301
+ const fullContent = fs10.readFileSync(filePath, "utf-8");
3158
3302
  const content = formatContent(fullContent, mode);
3159
3303
  results.push({
3160
3304
  id,
@@ -3211,33 +3355,33 @@ function ensureCache() {
3211
3355
  standardsCache = /* @__PURE__ */ new Map();
3212
3356
  const baseDir = findBaseDir();
3213
3357
  for (const dir of STANDARD_DIRS) {
3214
- const fullDir = path8.join(baseDir, dir);
3215
- if (!fs9.existsSync(fullDir)) continue;
3358
+ const fullDir = path9.join(baseDir, dir);
3359
+ if (!fs10.existsSync(fullDir)) continue;
3216
3360
  scanDirectory(fullDir, standardsCache);
3217
3361
  }
3218
3362
  }
3219
3363
  function findBaseDir() {
3220
3364
  const possiblePaths = [
3221
3365
  process.cwd(),
3222
- path8.join(process.cwd(), ".."),
3223
- path8.join(__dirname, "..", "..", "..")
3366
+ path9.join(process.cwd(), ".."),
3367
+ path9.join(__dirname, "..", "..", "..")
3224
3368
  ];
3225
3369
  for (const p of possiblePaths) {
3226
- if (fs9.existsSync(path8.join(p, "standards"))) {
3370
+ if (fs10.existsSync(path9.join(p, "standards"))) {
3227
3371
  return p;
3228
3372
  }
3229
3373
  }
3230
3374
  return process.cwd();
3231
3375
  }
3232
3376
  function scanDirectory(dir, cache) {
3233
- const items = fs9.readdirSync(dir);
3377
+ const items = fs10.readdirSync(dir);
3234
3378
  for (const item of items) {
3235
- const fullPath = path8.join(dir, item);
3236
- const stat = fs9.statSync(fullPath);
3379
+ const fullPath = path9.join(dir, item);
3380
+ const stat = fs10.statSync(fullPath);
3237
3381
  if (stat.isDirectory()) {
3238
3382
  scanDirectory(fullPath, cache);
3239
3383
  } else if (item.endsWith(".md")) {
3240
- const id = path8.basename(item, ".md");
3384
+ const id = path9.basename(item, ".md");
3241
3385
  cache.set(id, fullPath);
3242
3386
  }
3243
3387
  }
@@ -3480,10 +3624,10 @@ async function listScenarios() {
3480
3624
  }
3481
3625
 
3482
3626
  // src/core/templates/discovery.ts
3483
- import * as fs10 from "fs";
3484
- import * as path9 from "path";
3485
- var TEMPLATES_DIR = path9.resolve(
3486
- path9.dirname(new URL(import.meta.url).pathname),
3627
+ import * as fs11 from "fs";
3628
+ import * as path10 from "path";
3629
+ var TEMPLATES_DIR = path10.resolve(
3630
+ path10.dirname(new URL(import.meta.url).pathname),
3487
3631
  "../../../../templates"
3488
3632
  );
3489
3633
  var templatesCache = null;
@@ -3493,15 +3637,15 @@ function ensureCache2() {
3493
3637
  scanTemplates(TEMPLATES_DIR, "");
3494
3638
  }
3495
3639
  function scanTemplates(dir, prefix) {
3496
- if (!fs10.existsSync(dir)) return;
3497
- const entries = fs10.readdirSync(dir, { withFileTypes: true });
3640
+ if (!fs11.existsSync(dir)) return;
3641
+ const entries = fs11.readdirSync(dir, { withFileTypes: true });
3498
3642
  for (const entry of entries) {
3499
3643
  if (!entry.isDirectory()) continue;
3500
3644
  if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
3501
- const fullPath = path9.join(dir, entry.name);
3645
+ const fullPath = path10.join(dir, entry.name);
3502
3646
  const templateId = prefix ? `${prefix}/${entry.name}` : entry.name;
3503
- const configPath = path9.join(fullPath, "_CONFIG.md");
3504
- if (fs10.existsSync(configPath)) {
3647
+ const configPath = path10.join(fullPath, "_CONFIG.md");
3648
+ if (fs11.existsSync(configPath)) {
3505
3649
  const metadata = parseConfigMd(configPath, templateId, fullPath);
3506
3650
  if (metadata) {
3507
3651
  templatesCache.set(templateId, metadata);
@@ -3512,7 +3656,7 @@ function scanTemplates(dir, prefix) {
3512
3656
  }
3513
3657
  function parseConfigMd(configPath, templateId, templateDir) {
3514
3658
  try {
3515
- const content = fs10.readFileSync(configPath, "utf-8");
3659
+ const content = fs11.readFileSync(configPath, "utf-8");
3516
3660
  const titleMatch = content.match(/^#\s+(.+)$/m);
3517
3661
  const name = titleMatch ? titleMatch[1].trim() : templateId;
3518
3662
  const descMatch = content.match(/^>\s*(.+)$/m);
@@ -3555,14 +3699,14 @@ function inferTemplateType(templateId, name) {
3555
3699
  }
3556
3700
  function getTemplateFiles(dir, prefix = "") {
3557
3701
  const files = [];
3558
- const entries = fs10.readdirSync(dir, { withFileTypes: true });
3702
+ const entries = fs11.readdirSync(dir, { withFileTypes: true });
3559
3703
  for (const entry of entries) {
3560
3704
  const relativePath = prefix ? `${prefix}/${entry.name}` : entry.name;
3561
3705
  if (entry.name === "_CONFIG.md" || entry.name === "_template.json") {
3562
3706
  continue;
3563
3707
  }
3564
3708
  if (entry.isDirectory()) {
3565
- files.push(...getTemplateFiles(path9.join(dir, entry.name), relativePath));
3709
+ files.push(...getTemplateFiles(path10.join(dir, entry.name), relativePath));
3566
3710
  } else {
3567
3711
  files.push(relativePath);
3568
3712
  }
@@ -3617,9 +3761,9 @@ function getTemplateById(templateId, includeFiles = false) {
3617
3761
  ensureCache2();
3618
3762
  const metadata = templatesCache.get(templateId);
3619
3763
  if (!metadata) return null;
3620
- const templateDir = path9.join(TEMPLATES_DIR, templateId);
3621
- const configPath = path9.join(templateDir, "_CONFIG.md");
3622
- const configGuide = fs10.existsSync(configPath) ? fs10.readFileSync(configPath, "utf-8") : "";
3764
+ const templateDir = path10.join(TEMPLATES_DIR, templateId);
3765
+ const configPath = path10.join(templateDir, "_CONFIG.md");
3766
+ const configGuide = fs11.existsSync(configPath) ? fs11.readFileSync(configPath, "utf-8") : "";
3623
3767
  const result = {
3624
3768
  metadata,
3625
3769
  configGuide
@@ -3627,11 +3771,11 @@ function getTemplateById(templateId, includeFiles = false) {
3627
3771
  if (includeFiles) {
3628
3772
  result.files = [];
3629
3773
  for (const filePath of metadata.files) {
3630
- const fullPath = path9.join(templateDir, filePath);
3631
- if (fs10.existsSync(fullPath)) {
3774
+ const fullPath = path10.join(templateDir, filePath);
3775
+ if (fs11.existsSync(fullPath)) {
3632
3776
  result.files.push({
3633
3777
  path: filePath,
3634
- content: fs10.readFileSync(fullPath, "utf-8"),
3778
+ content: fs11.readFileSync(fullPath, "utf-8"),
3635
3779
  isConfig: filePath.startsWith("_")
3636
3780
  });
3637
3781
  }
@@ -3642,7 +3786,7 @@ function getTemplateById(templateId, includeFiles = false) {
3642
3786
  function getTemplateDir(templateId) {
3643
3787
  ensureCache2();
3644
3788
  if (!templatesCache.has(templateId)) return null;
3645
- return path9.join(TEMPLATES_DIR, templateId);
3789
+ return path10.join(TEMPLATES_DIR, templateId);
3646
3790
  }
3647
3791
  function searchTemplates(query) {
3648
3792
  const lower = query.toLowerCase();
@@ -3927,8 +4071,86 @@ function createLogger(name) {
3927
4071
  return new Logger(name);
3928
4072
  }
3929
4073
 
4074
+ // src/core/autoConfig.ts
4075
+ import * as fs12 from "fs";
4076
+ import * as path11 from "path";
4077
+ var checkedWorkspaces = /* @__PURE__ */ new Map();
4078
+ var CACHE_DURATION = 5 * 60 * 1e3;
4079
+ function ensureWorkspaceConfig(workspacePath) {
4080
+ var _a, _b;
4081
+ const result = {
4082
+ needsSetup: false,
4083
+ wasFixed: false,
4084
+ workspacePath
4085
+ };
4086
+ if (!workspacePath || !fs12.existsSync(workspacePath)) {
4087
+ return result;
4088
+ }
4089
+ const cached = checkedWorkspaces.get(workspacePath);
4090
+ const now = Date.now();
4091
+ if (cached && cached.configured && now - cached.timestamp < CACHE_DURATION) {
4092
+ return result;
4093
+ }
4094
+ const vscodeDir = path11.join(workspacePath, ".vscode");
4095
+ const mcpJsonPath = path11.join(vscodeDir, "mcp.json");
4096
+ const settingsPath = path11.join(vscodeDir, "settings.json");
4097
+ let hasMtaConfig = false;
4098
+ if (fs12.existsSync(mcpJsonPath)) {
4099
+ try {
4100
+ const config = JSON.parse(fs12.readFileSync(mcpJsonPath, "utf-8"));
4101
+ hasMtaConfig = !!(((_a = config.servers) == null ? void 0 : _a.mta) || ((_b = config.mcpServers) == null ? void 0 : _b.mta));
4102
+ } catch {
4103
+ }
4104
+ }
4105
+ if (hasMtaConfig) {
4106
+ checkedWorkspaces.set(workspacePath, { configured: true, timestamp: now });
4107
+ return result;
4108
+ }
4109
+ result.needsSetup = true;
4110
+ try {
4111
+ if (!fs12.existsSync(vscodeDir)) {
4112
+ fs12.mkdirSync(vscodeDir, { recursive: true });
4113
+ }
4114
+ let mcpConfig = { servers: {} };
4115
+ if (fs12.existsSync(mcpJsonPath)) {
4116
+ try {
4117
+ mcpConfig = JSON.parse(fs12.readFileSync(mcpJsonPath, "utf-8"));
4118
+ if (!mcpConfig.servers) {
4119
+ mcpConfig.servers = {};
4120
+ }
4121
+ } catch {
4122
+ mcpConfig = { servers: {} };
4123
+ }
4124
+ }
4125
+ mcpConfig.servers.mta = {
4126
+ command: "npx",
4127
+ args: ["-y", "mta-mcp"],
4128
+ env: {}
4129
+ };
4130
+ fs12.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 2));
4131
+ let settings = {};
4132
+ if (fs12.existsSync(settingsPath)) {
4133
+ try {
4134
+ settings = JSON.parse(fs12.readFileSync(settingsPath, "utf-8"));
4135
+ } catch {
4136
+ settings = {};
4137
+ }
4138
+ }
4139
+ if (!settings["github.copilot.chat.mcp.enabled"]) {
4140
+ settings["github.copilot.chat.mcp.enabled"] = true;
4141
+ fs12.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
4142
+ }
4143
+ result.wasFixed = true;
4144
+ result.message = `\u2705 \u5DF2\u81EA\u52A8\u4E3A ${path11.basename(workspacePath)} \u914D\u7F6E MTA MCP\u3002\u8BF7\u91CD\u65B0\u52A0\u8F7D VS Code \u7A97\u53E3\u4F7F\u914D\u7F6E\u751F\u6548\u3002`;
4145
+ checkedWorkspaces.set(workspacePath, { configured: true, timestamp: now });
4146
+ } catch (error) {
4147
+ result.message = `\u26A0\uFE0F \u81EA\u52A8\u914D\u7F6E\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`;
4148
+ }
4149
+ return result;
4150
+ }
4151
+
3930
4152
  // src/index.ts
3931
- var SERVER_VERSION = "2.5.0";
4153
+ var SERVER_VERSION = "2.7.0";
3932
4154
  var logger2 = createLogger("Server");
3933
4155
  var CopilotPromptsMCPServer = class {
3934
4156
  constructor() {
@@ -3994,25 +4216,33 @@ var CopilotPromptsMCPServer = class {
3994
4216
  },
3995
4217
  {
3996
4218
  name: "auto_setup",
3997
- description: "\u4E00\u952E\u914D\u7F6E MCP \u548C\u9879\u76EE\u89C4\u8303\uFF0C\u751F\u6210 .vscode/mcp.json \u548C copilot-instructions.md",
4219
+ description: `\u3010\u914D\u7F6E MTA\u3011\u5F53\u7528\u6237\u8BF4"\u914D\u7F6E MTA"\u3001"\u8BBE\u7F6E MCP"\u3001"MTA \u4E0D\u5DE5\u4F5C"\u65F6\u8C03\u7528\u6B64\u5DE5\u5177\u3002
4220
+ \u529F\u80FD\uFF1A
4221
+ 1. \u81EA\u52A8\u521B\u5EFA .vscode/mcp.json \u548C settings.json
4222
+ 2. \u68C0\u6D4B\u9879\u76EE\u4E2D\u662F\u5426\u5B58\u5728 .github/copilot-instructions.md
4223
+ 3. \u5982\u679C\u4E0D\u5B58\u5728\uFF0C\u5219\u81EA\u52A8\u5206\u6790\u9879\u76EE\u6280\u672F\u6808\u5E76\u751F\u6210\u914D\u7F6E\u6587\u4EF6
4224
+ 4. \u4F7F\u7528\u5B8C\u6574\u7684 SmartAgentMatcher \u5339\u914D\u6700\u5408\u9002\u7684 Agents
4225
+
4226
+ \u914D\u7F6E\u5B8C\u6210\u540E\u9700\u63D0\u793A\u7528\u6237\u91CD\u65B0\u52A0\u8F7D\u7A97\u53E3\uFF08Cmd+Shift+P \u2192 Reload Window\uFF09`,
3998
4227
  inputSchema: {
3999
4228
  type: "object",
4000
4229
  properties: {
4001
4230
  workspacePath: {
4002
4231
  type: "string",
4003
- description: "\u5DE5\u4F5C\u533A\u8DEF\u5F84\uFF08\u53EF\u9009\uFF09"
4232
+ description: "\u5DE5\u4F5C\u533A\u7EDD\u5BF9\u8DEF\u5F84\uFF08\u5FC5\u987B\u63D0\u4F9B\uFF09"
4004
4233
  },
4005
4234
  generateInstructions: {
4006
4235
  type: "boolean",
4007
- description: "\u662F\u5426\u751F\u6210 copilot-instructions.md",
4236
+ description: "\u662F\u5426\u751F\u6210 copilot-instructions.md\uFF08\u9ED8\u8BA4 true\uFF0C\u4EC5\u5F53\u4E0D\u5B58\u5728\u65F6\u751F\u6210\uFF09",
4008
4237
  default: true
4009
4238
  }
4010
- }
4239
+ },
4240
+ required: ["workspacePath"]
4011
4241
  }
4012
4242
  },
4013
4243
  {
4014
4244
  name: "health_check",
4015
- description: "\u68C0\u67E5 MCP \u670D\u52A1\u5668\u72B6\u6001\uFF0C\u8BCA\u65AD\u914D\u7F6E\u95EE\u9898",
4245
+ description: "\u68C0\u67E5 MCP \u670D\u52A1\u5668\u72B6\u6001\u548C\u914D\u7F6E\u95EE\u9898\uFF0C\u8FD4\u56DE\u8BCA\u65AD\u62A5\u544A\u548C\u4FEE\u590D\u5EFA\u8BAE",
4016
4246
  inputSchema: {
4017
4247
  type: "object",
4018
4248
  properties: {
@@ -4258,42 +4488,81 @@ var CopilotPromptsMCPServer = class {
4258
4488
  ]
4259
4489
  }));
4260
4490
  this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
4491
+ var _a, _b;
4261
4492
  try {
4262
4493
  const { name, arguments: args } = request.params;
4263
4494
  logger2.debug(`\u8C03\u7528\u5DE5\u5177: ${name}`);
4264
4495
  logger2.debug(`\u53C2\u6570:`, args);
4496
+ const workspacePath = (args == null ? void 0 : args.workspacePath) || (args == null ? void 0 : args.projectPath);
4497
+ let autoConfigMessage = null;
4498
+ if (workspacePath) {
4499
+ const configResult = ensureWorkspaceConfig(workspacePath);
4500
+ if (configResult.wasFixed) {
4501
+ autoConfigMessage = configResult.message || null;
4502
+ logger2.info(`\u81EA\u52A8\u914D\u7F6E\u5DF2\u4FEE\u590D: ${workspacePath}`);
4503
+ }
4504
+ }
4505
+ let result;
4265
4506
  switch (name) {
4266
4507
  case "analyze_project":
4267
- return await analyzeProject(args);
4508
+ result = await analyzeProject(args);
4509
+ break;
4268
4510
  case "auto_setup":
4269
- return await autoSetup(args);
4511
+ result = await autoSetup(args);
4512
+ break;
4270
4513
  case "health_check":
4271
- return await healthCheck(args);
4514
+ result = await healthCheck(args);
4515
+ break;
4272
4516
  case "use_preset":
4273
- return await usePreset(args);
4517
+ result = await usePreset(args);
4518
+ break;
4274
4519
  case "list_presets":
4275
- return await listPresets();
4520
+ result = await listPresets();
4521
+ break;
4276
4522
  case "match_agents":
4277
- return await matchAgents(args);
4523
+ result = await matchAgents(args);
4524
+ break;
4278
4525
  case "list_available_agents":
4279
- return await listAvailableAgents();
4526
+ result = await listAvailableAgents();
4527
+ break;
4280
4528
  case "generate_config":
4281
- return await generateConfig(args);
4529
+ result = await generateConfig(args);
4530
+ break;
4282
4531
  case "get_compact_standards":
4283
- return await getCompactStandards(args);
4532
+ result = await getCompactStandards(args);
4533
+ break;
4284
4534
  case "get_standard_by_id":
4285
- return await getStandardById(args);
4535
+ result = await getStandardById(args);
4536
+ break;
4286
4537
  case "query_mappings":
4287
- return await queryMappings(args);
4538
+ result = await queryMappings(args);
4539
+ break;
4288
4540
  case "list_scenarios":
4289
- return await listScenarios();
4541
+ result = await listScenarios();
4542
+ break;
4290
4543
  case "list_templates":
4291
- return await listTemplates(args);
4544
+ result = await listTemplates(args);
4545
+ break;
4292
4546
  case "get_template":
4293
- return await getTemplate(args);
4547
+ result = await getTemplate(args);
4548
+ break;
4294
4549
  default:
4295
4550
  throw new Error(`\u672A\u77E5\u5DE5\u5177: ${name}`);
4296
4551
  }
4552
+ if (autoConfigMessage && ((_b = (_a = result == null ? void 0 : result.content) == null ? void 0 : _a[0]) == null ? void 0 : _b.text)) {
4553
+ try {
4554
+ const originalData = JSON.parse(result.content[0].text);
4555
+ result.content[0].text = JSON.stringify({
4556
+ ...originalData,
4557
+ _autoConfigured: {
4558
+ message: autoConfigMessage,
4559
+ action: "\u26A0\uFE0F \u8BF7\u91CD\u65B0\u52A0\u8F7D VS Code \u7A97\u53E3 (Cmd+Shift+P \u2192 Reload Window) \u4F7F\u914D\u7F6E\u751F\u6548"
4560
+ }
4561
+ }, null, 2);
4562
+ } catch {
4563
+ }
4564
+ }
4565
+ return result;
4297
4566
  } catch (error) {
4298
4567
  logger2.error(`\u5DE5\u5177\u6267\u884C\u5931\u8D25:`, error);
4299
4568
  return errorResponse(error);
@@ -4334,11 +4603,54 @@ var CopilotPromptsMCPServer = class {
4334
4603
  async run() {
4335
4604
  const transport = new StdioServerTransport();
4336
4605
  await this.server.connect(transport);
4337
- logger2.info(`Copilot Prompts MCP Server v${SERVER_VERSION} \u5DF2\u542F\u52A8`);
4606
+ const { getResourceLoader: getResourceLoader2 } = await Promise.resolve().then(() => (init_resourceLoader(), resourceLoader_exports));
4607
+ const resourceLoader = getResourceLoader2();
4608
+ const stats = resourceLoader.getResourceStats();
4609
+ const startupInfo = [
4610
+ `\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`,
4611
+ `\u{1F680} MTA MCP Server v${SERVER_VERSION} \u5DF2\u542F\u52A8`,
4612
+ `\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`,
4613
+ `\u{1F4C2} \u5DE5\u4F5C\u76EE\u5F55: ${process.cwd()}`,
4614
+ `\u{1F527} Node \u7248\u672C: ${process.version}`,
4615
+ `\u23F1\uFE0F \u542F\u52A8\u65F6\u95F4: ${(/* @__PURE__ */ new Date()).toLocaleString("zh-CN")}`,
4616
+ ``,
4617
+ `\u{1F4E6} \u5185\u7F6E\u8D44\u6E90:`,
4618
+ ` \u2022 Agents: ${stats.agents} \u4E2A`,
4619
+ ` \u2022 Standards: ${stats.standards} \u4E2A`,
4620
+ ` \u2022 Templates: ${stats.templates} \u4E2A`,
4621
+ ``,
4622
+ `\u{1F4CB} \u53EF\u7528\u5DE5\u5177:`,
4623
+ ` \u2022 analyze_project - \u5206\u6790\u9879\u76EE\u6280\u672F\u6808`,
4624
+ ` \u2022 auto_setup - \u4E00\u952E\u914D\u7F6E MCP`,
4625
+ ` \u2022 health_check - \u5065\u5EB7\u68C0\u67E5\u8BCA\u65AD`,
4626
+ ` \u2022 get_compact_standards - \u83B7\u53D6\u7F16\u7801\u89C4\u8303`,
4627
+ ` \u2022 use_preset - \u4F7F\u7528\u9884\u8BBE\u573A\u666F`,
4628
+ ` \u2022 match_agents - \u5339\u914D\u63A8\u8350 Agent`,
4629
+ ``,
4630
+ `\u{1F4A1} \u63D0\u793A: \u5728 Copilot Chat \u4E2D\u4F7F\u7528 @mta \u8C03\u7528\u670D\u52A1`,
4631
+ `\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`
4632
+ ];
4633
+ startupInfo.forEach((line) => console.error(line));
4634
+ logger2.info(`MCP Server \u5C31\u7EEA\uFF0C\u7B49\u5F85 Copilot Chat \u8FDE\u63A5...`);
4338
4635
  }
4339
4636
  };
4340
4637
  var server = new CopilotPromptsMCPServer();
4341
4638
  server.run().catch((error) => {
4639
+ console.error(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
4640
+ console.error(`\u274C MTA MCP Server \u542F\u52A8\u5931\u8D25`);
4641
+ console.error(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
4642
+ console.error(`\u9519\u8BEF\u4FE1\u606F: ${error instanceof Error ? error.message : String(error)}`);
4643
+ console.error(``);
4644
+ console.error(`\u{1F50D} \u53EF\u80FD\u7684\u539F\u56E0:`);
4645
+ console.error(` 1. Node.js \u7248\u672C\u8FC7\u4F4E\uFF08\u9700\u8981 16+\uFF09`);
4646
+ console.error(` 2. \u4F9D\u8D56\u5B89\u88C5\u4E0D\u5B8C\u6574`);
4647
+ console.error(` 3. \u7AEF\u53E3\u88AB\u5360\u7528`);
4648
+ console.error(``);
4649
+ console.error(`\u{1F4A1} \u89E3\u51B3\u5EFA\u8BAE:`);
4650
+ console.error(` \u2022 \u8FD0\u884C node --version \u68C0\u67E5\u7248\u672C`);
4651
+ console.error(` \u2022 \u8FD0\u884C npm install \u91CD\u65B0\u5B89\u88C5\u4F9D\u8D56`);
4652
+ console.error(` \u2022 \u68C0\u67E5\u662F\u5426\u6709\u5176\u4ED6 MCP \u670D\u52A1\u5668\u5B9E\u4F8B\u8FD0\u884C`);
4653
+ console.error(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
4342
4654
  logger2.error("\u670D\u52A1\u5668\u542F\u52A8\u5931\u8D25:", error);
4343
4655
  process.exit(1);
4344
4656
  });