mta-mcp 2.6.0 → 2.7.1

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,9 +1898,9 @@ 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" });
@@ -1731,7 +1910,7 @@ async function autoSetup(args) {
1731
1910
  status: "success",
1732
1911
  detail: "\u901A\u8FC7 npm \u5305\u8FD0\u884C\uFF0C\u65E0\u9700\u672C\u5730\u5B89\u88C5"
1733
1912
  });
1734
- const mcpJsonPath = path5.join(vscodeDir, "mcp.json");
1913
+ const mcpJsonPath = path6.join(vscodeDir, "mcp.json");
1735
1914
  const mcpConfig = {
1736
1915
  servers: {
1737
1916
  "mta": {
@@ -1741,9 +1920,9 @@ async function autoSetup(args) {
1741
1920
  }
1742
1921
  }
1743
1922
  };
1744
- if (fs5.existsSync(mcpJsonPath)) {
1923
+ if (fs6.existsSync(mcpJsonPath)) {
1745
1924
  try {
1746
- const existingConfig = JSON.parse(fs5.readFileSync(mcpJsonPath, "utf-8"));
1925
+ const existingConfig = JSON.parse(fs6.readFileSync(mcpJsonPath, "utf-8"));
1747
1926
  if (existingConfig.mcpServers && !existingConfig.servers) {
1748
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)");
1749
1928
  existingConfig.servers = existingConfig.mcpServers;
@@ -1756,57 +1935,57 @@ async function autoSetup(args) {
1756
1935
  ...existingConfig.servers,
1757
1936
  ...mcpConfig.servers
1758
1937
  };
1759
- fs5.writeFileSync(mcpJsonPath, JSON.stringify(existingConfig, null, 2));
1938
+ fs6.writeFileSync(mcpJsonPath, JSON.stringify(existingConfig, null, 2));
1760
1939
  results.steps.push({ step: "\u6DFB\u52A0 mta \u5230 mcp.json", status: "success" });
1761
1940
  }
1762
1941
  } catch (err) {
1763
- fs5.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 2));
1942
+ fs6.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 2));
1764
1943
  results.steps.push({ step: "\u91CD\u65B0\u521B\u5EFA mcp.json", status: "success" });
1765
1944
  results.warnings.push(`\u539F\u914D\u7F6E\u6587\u4EF6\u89E3\u6790\u5931\u8D25: ${err}`);
1766
1945
  }
1767
1946
  } else {
1768
- fs5.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 2));
1947
+ fs6.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 2));
1769
1948
  results.steps.push({ step: "\u521B\u5EFA mcp.json", status: "success" });
1770
1949
  }
1771
- const settingsJsonPath = path5.join(vscodeDir, "settings.json");
1950
+ const settingsJsonPath = path6.join(vscodeDir, "settings.json");
1772
1951
  const mcpSettings = {
1773
1952
  "github.copilot.chat.mcp.enabled": true,
1774
1953
  "github.copilot.chat.mcp.configFile": "${workspaceFolder}/.vscode/mcp.json",
1775
1954
  "github.copilot.chat.mcp.autoStart": true
1776
1955
  };
1777
- if (fs5.existsSync(settingsJsonPath)) {
1956
+ if (fs6.existsSync(settingsJsonPath)) {
1778
1957
  try {
1779
- const existingSettings = JSON.parse(fs5.readFileSync(settingsJsonPath, "utf-8"));
1958
+ const existingSettings = JSON.parse(fs6.readFileSync(settingsJsonPath, "utf-8"));
1780
1959
  const updated = { ...existingSettings, ...mcpSettings };
1781
- fs5.writeFileSync(settingsJsonPath, JSON.stringify(updated, null, 2) + "\n");
1960
+ fs6.writeFileSync(settingsJsonPath, JSON.stringify(updated, null, 2) + "\n");
1782
1961
  results.steps.push({ step: "\u66F4\u65B0 settings.json", status: "success" });
1783
1962
  } catch {
1784
- fs5.writeFileSync(settingsJsonPath, JSON.stringify(mcpSettings, null, 2) + "\n");
1963
+ fs6.writeFileSync(settingsJsonPath, JSON.stringify(mcpSettings, null, 2) + "\n");
1785
1964
  results.steps.push({ step: "\u91CD\u65B0\u521B\u5EFA settings.json", status: "success" });
1786
1965
  }
1787
1966
  } else {
1788
- fs5.writeFileSync(settingsJsonPath, JSON.stringify(mcpSettings, null, 2) + "\n");
1967
+ fs6.writeFileSync(settingsJsonPath, JSON.stringify(mcpSettings, null, 2) + "\n");
1789
1968
  results.steps.push({ step: "\u521B\u5EFA settings.json", status: "success" });
1790
1969
  }
1791
- const extensionsJsonPath = path5.join(vscodeDir, "extensions.json");
1970
+ const extensionsJsonPath = path6.join(vscodeDir, "extensions.json");
1792
1971
  const recommendedExtensions = {
1793
1972
  recommendations: [
1794
1973
  "github.copilot",
1795
1974
  "github.copilot-chat"
1796
1975
  ]
1797
1976
  };
1798
- if (!fs5.existsSync(extensionsJsonPath)) {
1799
- fs5.writeFileSync(extensionsJsonPath, JSON.stringify(recommendedExtensions, null, 2));
1977
+ if (!fs6.existsSync(extensionsJsonPath)) {
1978
+ fs6.writeFileSync(extensionsJsonPath, JSON.stringify(recommendedExtensions, null, 2));
1800
1979
  results.steps.push({ step: "\u521B\u5EFA extensions.json", status: "success" });
1801
1980
  } else {
1802
1981
  results.steps.push({ step: "extensions.json \u5DF2\u5B58\u5728", status: "skip" });
1803
1982
  }
1804
- const gitignorePath = path5.join(workspacePath, ".gitignore");
1805
- if (fs5.existsSync(gitignorePath)) {
1806
- 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");
1807
1986
  if (!gitignoreContent.includes(".vscode/mcp.json")) {
1808
1987
  const updatedContent = gitignoreContent + "\n# MCP \u914D\u7F6E\uFF08\u672C\u5730\uFF09\n.vscode/mcp.json\n";
1809
- fs5.writeFileSync(gitignorePath, updatedContent);
1988
+ fs6.writeFileSync(gitignorePath, updatedContent);
1810
1989
  results.steps.push({ step: "\u6DFB\u52A0\u5230 .gitignore", status: "success" });
1811
1990
  } else {
1812
1991
  results.steps.push({ step: ".gitignore \u5DF2\u5305\u542B\u914D\u7F6E", status: "skip" });
@@ -1815,62 +1994,45 @@ async function autoSetup(args) {
1815
1994
  results.warnings.push("\u672A\u68C0\u6D4B\u5230 .gitignore\uFF0C\u5EFA\u8BAE\u624B\u52A8\u6DFB\u52A0 .vscode/mcp.json");
1816
1995
  }
1817
1996
  const generateInstructions = args.generateInstructions !== false;
1997
+ const instructionsPath = path6.join(workspacePath, ".github", "copilot-instructions.md");
1998
+ const hasExistingInstructions = fs6.existsSync(instructionsPath);
1818
1999
  if (generateInstructions) {
1819
- logger3.log("\u{1F50D} \u5206\u6790\u9879\u76EE\u5E76\u751F\u6210 copilot-instructions.md...");
1820
- try {
1821
- const analysisResult = await analyzeProject({ projectPath: workspacePath });
1822
- const analysisContent = analysisResult.content[0];
1823
- if (analysisContent.type === "text") {
1824
- const analysisData = JSON.parse(analysisContent.text);
1825
- if (analysisData.success && analysisData.features) {
1826
- const agentIds = [];
1827
- const features = analysisData.features;
1828
- if (((_b = features.frameworks) == null ? void 0 : _b.includes("Vue 3")) || ((_c = features.frameworks) == null ? void 0 : _c.includes("Vue"))) {
1829
- agentIds.push("vue3");
1830
- }
1831
- if ((_d = features.tools) == null ? void 0 : _d.includes("LogicFlow")) {
1832
- agentIds.push("logicflow");
1833
- }
1834
- if (((_e = features.keywords) == null ? void 0 : _e.includes("i18n")) || ((_f = features.keywords) == null ? void 0 : _f.includes("\u56FD\u9645\u5316"))) {
1835
- agentIds.push("i18n");
1836
- }
1837
- if (features.projectType === "flutter") {
1838
- agentIds.push("flutter");
1839
- }
1840
- if (features.projectType === "wechat-miniprogram") {
1841
- agentIds.push("wechat-miniprogram");
1842
- }
1843
- if (agentIds.length > 0) {
1844
- const configResult = await generateConfig({
1845
- projectPath: workspacePath,
1846
- agentIds,
1847
- autoMatch: false,
1848
- 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(", ")}`
1849
2023
  });
1850
- const configContent = configResult.content[0];
1851
- if (configContent.type === "text") {
1852
- const configData = JSON.parse(configContent.text);
1853
- if (configData.success) {
1854
- results.steps.push({
1855
- step: "\u751F\u6210 copilot-instructions.md",
1856
- status: "success",
1857
- detail: `\u5E94\u7528\u4E86 ${((_g = configData.agents) == null ? void 0 : _g.length) || 0} \u4E2A Agents: ${agentIds.join(", ")}`
1858
- });
1859
- } else {
1860
- results.warnings.push(`\u914D\u7F6E\u751F\u6210\u5931\u8D25: ${configData.error || "\u672A\u77E5\u9519\u8BEF"}`);
1861
- }
1862
- }
1863
2024
  } else {
1864
- results.warnings.push("\u672A\u627E\u5230\u5339\u914D\u7684 Agents\uFF0C\u8DF3\u8FC7\u914D\u7F6E\u751F\u6210");
1865
- 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"] })');
1866
2028
  }
1867
- } else {
1868
- results.warnings.push(`\u9879\u76EE\u5206\u6790\u5931\u8D25: ${analysisData.error || "\u672A\u77E5\u9519\u8BEF"}`);
1869
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 })');
1870
2035
  }
1871
- } catch (error) {
1872
- results.warnings.push(`\u81EA\u52A8\u751F\u6210\u914D\u7F6E\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
1873
- results.warnings.push("\u4F60\u53EF\u4EE5\u7A0D\u540E\u624B\u52A8\u8FD0\u884C generate_config \u5DE5\u5177\u751F\u6210\u914D\u7F6E");
1874
2036
  }
1875
2037
  } else {
1876
2038
  results.steps.push({ step: "\u8DF3\u8FC7 copilot-instructions.md \u751F\u6210", status: "skip" });
@@ -1906,11 +2068,11 @@ async function autoSetup(args) {
1906
2068
  }
1907
2069
 
1908
2070
  // src/core/standardsManager.ts
1909
- import * as fs6 from "fs";
1910
- import * as path6 from "path";
1911
- import { fileURLToPath as fileURLToPath2 } from "url";
1912
- var __filename2 = fileURLToPath2(import.meta.url);
1913
- 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);
1914
2076
  var StandardsManager = class {
1915
2077
  constructor() {
1916
2078
  // v1.2.0: 底层必须加载的核心规范
@@ -1943,9 +2105,9 @@ var StandardsManager = class {
1943
2105
  averageResponseTime: 0,
1944
2106
  totalTokensSaved: 0
1945
2107
  };
1946
- const devPath = path6.resolve(__dirname3, "../../../standards");
1947
- const npmPath = path6.resolve(__dirname3, "../../standards");
1948
- 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;
1949
2111
  }
1950
2112
  /**
1951
2113
  * 获取所有可用的规范资源
@@ -1959,11 +2121,11 @@ var StandardsManager = class {
1959
2121
  { dir: "patterns", name: "\u8BBE\u8BA1\u6A21\u5F0F" }
1960
2122
  ];
1961
2123
  categories.forEach(({ dir, name: categoryName }) => {
1962
- const categoryPath = path6.join(this.standardsPath, dir);
1963
- if (!fs6.existsSync(categoryPath)) {
2124
+ const categoryPath = path7.join(this.standardsPath, dir);
2125
+ if (!fs7.existsSync(categoryPath)) {
1964
2126
  return;
1965
2127
  }
1966
- const files = fs6.readdirSync(categoryPath).filter((file) => file.endsWith(".md"));
2128
+ const files = fs7.readdirSync(categoryPath).filter((file) => file.endsWith(".md"));
1967
2129
  files.forEach((file) => {
1968
2130
  const standardId = file.replace(".md", "");
1969
2131
  standards.push({
@@ -1993,11 +2155,11 @@ var StandardsManager = class {
1993
2155
  throw new Error(`Invalid standards URI: ${uri}`);
1994
2156
  }
1995
2157
  const [, category, standardId] = match;
1996
- const filePath = path6.join(this.standardsPath, category, `${standardId}.md`);
1997
- if (!fs6.existsSync(filePath)) {
2158
+ const filePath = path7.join(this.standardsPath, category, `${standardId}.md`);
2159
+ if (!fs7.existsSync(filePath)) {
1998
2160
  throw new Error(`Standard not found: ${uri}`);
1999
2161
  }
2000
- const content = fs6.readFileSync(filePath, "utf-8");
2162
+ const content = fs7.readFileSync(filePath, "utf-8");
2001
2163
  this.updateCache(uri, content);
2002
2164
  this.stats.individualStandards.set(
2003
2165
  uri,
@@ -2540,23 +2702,23 @@ async function listPresets() {
2540
2702
  }
2541
2703
 
2542
2704
  // src/tools/healthCheck.ts
2543
- import * as fs7 from "fs";
2544
- import * as path7 from "path";
2545
- import { fileURLToPath as fileURLToPath3 } from "url";
2546
- var __filename3 = fileURLToPath3(import.meta.url);
2547
- 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);
2548
2710
  function getServerRoot() {
2549
2711
  const possibleRoots = [
2550
- path7.resolve(__dirname4, "../.."),
2712
+ path8.resolve(__dirname5, "../.."),
2551
2713
  // 从 dist/tools/ 向上两级
2552
- path7.resolve(__dirname4, "../../.."),
2714
+ path8.resolve(__dirname5, "../../.."),
2553
2715
  // npm 包场景
2554
- path7.resolve(process.cwd())
2716
+ path8.resolve(process.cwd())
2555
2717
  // 当前工作目录
2556
2718
  ];
2557
2719
  for (const root of possibleRoots) {
2558
- const standardsPath = path7.join(root, "standards");
2559
- if (fs7.existsSync(standardsPath)) {
2720
+ const standardsPath = path8.join(root, "standards");
2721
+ if (fs8.existsSync(standardsPath)) {
2560
2722
  return root;
2561
2723
  }
2562
2724
  }
@@ -2586,14 +2748,14 @@ async function healthCheck(args) {
2586
2748
  }
2587
2749
  logger3.log("\u{1F50D} \u68C0\u67E5\u914D\u7F6E\u6587\u4EF6...");
2588
2750
  const workspacePath = args.workspacePath || process.cwd();
2589
- const vscodeDir = path7.join(workspacePath, ".vscode");
2590
- if (fs7.existsSync(vscodeDir)) {
2751
+ const vscodeDir = path8.join(workspacePath, ".vscode");
2752
+ if (fs8.existsSync(vscodeDir)) {
2591
2753
  checks.workspace.status = "healthy";
2592
2754
  checks.workspace.details.push(`\u2705 \u5DE5\u4F5C\u533A\u8DEF\u5F84: ${workspacePath}`);
2593
- const mcpJsonPath = path7.join(vscodeDir, "mcp.json");
2594
- if (fs7.existsSync(mcpJsonPath)) {
2755
+ const mcpJsonPath = path8.join(vscodeDir, "mcp.json");
2756
+ if (fs8.existsSync(mcpJsonPath)) {
2595
2757
  try {
2596
- const config = JSON.parse(fs7.readFileSync(mcpJsonPath, "utf-8"));
2758
+ const config = JSON.parse(fs8.readFileSync(mcpJsonPath, "utf-8"));
2597
2759
  const hasNewFormat = (_a = config.servers) == null ? void 0 : _a["copilot-prompts"];
2598
2760
  const hasOldFormat = (_b = config.mcpServers) == null ? void 0 : _b["copilot-prompts"];
2599
2761
  if (hasNewFormat) {
@@ -2636,10 +2798,10 @@ async function healthCheck(args) {
2636
2798
  checks.configuration.details.push("\u26A0\uFE0F mcp.json \u4E0D\u5B58\u5728");
2637
2799
  checks.configuration.details.push("\u{1F4A1} \u5EFA\u8BAE: \u8FD0\u884C auto_setup \u5DE5\u5177\u81EA\u52A8\u914D\u7F6E");
2638
2800
  }
2639
- const settingsPath = path7.join(vscodeDir, "settings.json");
2640
- if (fs7.existsSync(settingsPath)) {
2801
+ const settingsPath = path8.join(vscodeDir, "settings.json");
2802
+ if (fs8.existsSync(settingsPath)) {
2641
2803
  try {
2642
- const settings = JSON.parse(fs7.readFileSync(settingsPath, "utf-8"));
2804
+ const settings = JSON.parse(fs8.readFileSync(settingsPath, "utf-8"));
2643
2805
  if (settings["github.copilot.chat.mcp.enabled"] === true) {
2644
2806
  checks.configuration.details.push("\u2705 VS Code MCP \u5DF2\u542F\u7528");
2645
2807
  } else {
@@ -2656,10 +2818,10 @@ async function healthCheck(args) {
2656
2818
  }
2657
2819
  logger3.log("\u{1F50D} \u68C0\u67E5\u4F9D\u8D56...");
2658
2820
  const serverRoot = getServerRoot();
2659
- const packageJsonPath = path7.join(serverRoot, "package.json");
2660
- if (fs7.existsSync(packageJsonPath)) {
2821
+ const packageJsonPath = path8.join(serverRoot, "package.json");
2822
+ if (fs8.existsSync(packageJsonPath)) {
2661
2823
  try {
2662
- const pkg = JSON.parse(fs7.readFileSync(packageJsonPath, "utf-8"));
2824
+ const pkg = JSON.parse(fs8.readFileSync(packageJsonPath, "utf-8"));
2663
2825
  checks.dependencies.status = "healthy";
2664
2826
  checks.dependencies.details.push(`\u2705 \u670D\u52A1\u5668\u7248\u672C: ${pkg.version}`);
2665
2827
  if (verbose && pkg.dependencies) {
@@ -2683,14 +2845,14 @@ async function healthCheck(args) {
2683
2845
  }
2684
2846
  }
2685
2847
  logger3.log("\u{1F50D} \u68C0\u67E5\u89C4\u8303\u6587\u4EF6...");
2686
- const standardsDir = path7.join(serverRoot, "standards");
2687
- if (fs7.existsSync(standardsDir)) {
2848
+ const standardsDir = path8.join(serverRoot, "standards");
2849
+ if (fs8.existsSync(standardsDir)) {
2688
2850
  const categories = ["core", "frameworks", "libraries", "patterns"];
2689
2851
  const foundStandards = [];
2690
2852
  for (const category of categories) {
2691
- const categoryPath = path7.join(standardsDir, category);
2692
- if (fs7.existsSync(categoryPath)) {
2693
- 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"));
2694
2856
  foundStandards.push(...files.map((f) => `${category}/${f}`));
2695
2857
  }
2696
2858
  }
@@ -2767,7 +2929,7 @@ function generateRecommendations(checks) {
2767
2929
  }
2768
2930
 
2769
2931
  // src/tools/getCompactStandards.ts
2770
- import * as fs8 from "fs";
2932
+ import * as fs9 from "fs";
2771
2933
  async function getCompactStandards(args) {
2772
2934
  const logger3 = new ConsoleLogger();
2773
2935
  const manager = new StandardsManager();
@@ -2814,7 +2976,7 @@ function detectContext(args, logger3) {
2814
2976
  let fileType = "unknown";
2815
2977
  let imports = [];
2816
2978
  let scenario = "";
2817
- if (args.currentFile && fs8.existsSync(args.currentFile)) {
2979
+ if (args.currentFile && fs9.existsSync(args.currentFile)) {
2818
2980
  const ext = ((_a = args.currentFile.split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
2819
2981
  const extMap = {
2820
2982
  "vue": "vue",
@@ -2826,7 +2988,7 @@ function detectContext(args, logger3) {
2826
2988
  };
2827
2989
  fileType = extMap[ext] || "unknown";
2828
2990
  try {
2829
- const content = fs8.readFileSync(args.currentFile, "utf-8");
2991
+ const content = fs9.readFileSync(args.currentFile, "utf-8");
2830
2992
  imports = extractImports(content);
2831
2993
  scenario = inferScenario(content, fileType);
2832
2994
  } catch {
@@ -3097,8 +3259,8 @@ function inferScenario(content, fileType) {
3097
3259
  }
3098
3260
 
3099
3261
  // src/tools/getStandardById.ts
3100
- import * as fs9 from "fs";
3101
- import * as path8 from "path";
3262
+ import * as fs10 from "fs";
3263
+ import * as path9 from "path";
3102
3264
  var STANDARD_DIRS = [
3103
3265
  "standards/core",
3104
3266
  "standards/frameworks",
@@ -3136,7 +3298,7 @@ async function getStandardById(args) {
3136
3298
  continue;
3137
3299
  }
3138
3300
  try {
3139
- const fullContent = fs9.readFileSync(filePath, "utf-8");
3301
+ const fullContent = fs10.readFileSync(filePath, "utf-8");
3140
3302
  const content = formatContent(fullContent, mode);
3141
3303
  results.push({
3142
3304
  id,
@@ -3193,33 +3355,33 @@ function ensureCache() {
3193
3355
  standardsCache = /* @__PURE__ */ new Map();
3194
3356
  const baseDir = findBaseDir();
3195
3357
  for (const dir of STANDARD_DIRS) {
3196
- const fullDir = path8.join(baseDir, dir);
3197
- if (!fs9.existsSync(fullDir)) continue;
3358
+ const fullDir = path9.join(baseDir, dir);
3359
+ if (!fs10.existsSync(fullDir)) continue;
3198
3360
  scanDirectory(fullDir, standardsCache);
3199
3361
  }
3200
3362
  }
3201
3363
  function findBaseDir() {
3202
3364
  const possiblePaths = [
3203
3365
  process.cwd(),
3204
- path8.join(process.cwd(), ".."),
3205
- path8.join(__dirname, "..", "..", "..")
3366
+ path9.join(process.cwd(), ".."),
3367
+ path9.join(__dirname, "..", "..", "..")
3206
3368
  ];
3207
3369
  for (const p of possiblePaths) {
3208
- if (fs9.existsSync(path8.join(p, "standards"))) {
3370
+ if (fs10.existsSync(path9.join(p, "standards"))) {
3209
3371
  return p;
3210
3372
  }
3211
3373
  }
3212
3374
  return process.cwd();
3213
3375
  }
3214
3376
  function scanDirectory(dir, cache) {
3215
- const items = fs9.readdirSync(dir);
3377
+ const items = fs10.readdirSync(dir);
3216
3378
  for (const item of items) {
3217
- const fullPath = path8.join(dir, item);
3218
- const stat = fs9.statSync(fullPath);
3379
+ const fullPath = path9.join(dir, item);
3380
+ const stat = fs10.statSync(fullPath);
3219
3381
  if (stat.isDirectory()) {
3220
3382
  scanDirectory(fullPath, cache);
3221
3383
  } else if (item.endsWith(".md")) {
3222
- const id = path8.basename(item, ".md");
3384
+ const id = path9.basename(item, ".md");
3223
3385
  cache.set(id, fullPath);
3224
3386
  }
3225
3387
  }
@@ -3462,10 +3624,10 @@ async function listScenarios() {
3462
3624
  }
3463
3625
 
3464
3626
  // src/core/templates/discovery.ts
3465
- import * as fs10 from "fs";
3466
- import * as path9 from "path";
3467
- var TEMPLATES_DIR = path9.resolve(
3468
- 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),
3469
3631
  "../../../../templates"
3470
3632
  );
3471
3633
  var templatesCache = null;
@@ -3475,15 +3637,15 @@ function ensureCache2() {
3475
3637
  scanTemplates(TEMPLATES_DIR, "");
3476
3638
  }
3477
3639
  function scanTemplates(dir, prefix) {
3478
- if (!fs10.existsSync(dir)) return;
3479
- const entries = fs10.readdirSync(dir, { withFileTypes: true });
3640
+ if (!fs11.existsSync(dir)) return;
3641
+ const entries = fs11.readdirSync(dir, { withFileTypes: true });
3480
3642
  for (const entry of entries) {
3481
3643
  if (!entry.isDirectory()) continue;
3482
3644
  if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
3483
- const fullPath = path9.join(dir, entry.name);
3645
+ const fullPath = path10.join(dir, entry.name);
3484
3646
  const templateId = prefix ? `${prefix}/${entry.name}` : entry.name;
3485
- const configPath = path9.join(fullPath, "_CONFIG.md");
3486
- if (fs10.existsSync(configPath)) {
3647
+ const configPath = path10.join(fullPath, "_CONFIG.md");
3648
+ if (fs11.existsSync(configPath)) {
3487
3649
  const metadata = parseConfigMd(configPath, templateId, fullPath);
3488
3650
  if (metadata) {
3489
3651
  templatesCache.set(templateId, metadata);
@@ -3494,7 +3656,7 @@ function scanTemplates(dir, prefix) {
3494
3656
  }
3495
3657
  function parseConfigMd(configPath, templateId, templateDir) {
3496
3658
  try {
3497
- const content = fs10.readFileSync(configPath, "utf-8");
3659
+ const content = fs11.readFileSync(configPath, "utf-8");
3498
3660
  const titleMatch = content.match(/^#\s+(.+)$/m);
3499
3661
  const name = titleMatch ? titleMatch[1].trim() : templateId;
3500
3662
  const descMatch = content.match(/^>\s*(.+)$/m);
@@ -3537,14 +3699,14 @@ function inferTemplateType(templateId, name) {
3537
3699
  }
3538
3700
  function getTemplateFiles(dir, prefix = "") {
3539
3701
  const files = [];
3540
- const entries = fs10.readdirSync(dir, { withFileTypes: true });
3702
+ const entries = fs11.readdirSync(dir, { withFileTypes: true });
3541
3703
  for (const entry of entries) {
3542
3704
  const relativePath = prefix ? `${prefix}/${entry.name}` : entry.name;
3543
3705
  if (entry.name === "_CONFIG.md" || entry.name === "_template.json") {
3544
3706
  continue;
3545
3707
  }
3546
3708
  if (entry.isDirectory()) {
3547
- files.push(...getTemplateFiles(path9.join(dir, entry.name), relativePath));
3709
+ files.push(...getTemplateFiles(path10.join(dir, entry.name), relativePath));
3548
3710
  } else {
3549
3711
  files.push(relativePath);
3550
3712
  }
@@ -3599,9 +3761,9 @@ function getTemplateById(templateId, includeFiles = false) {
3599
3761
  ensureCache2();
3600
3762
  const metadata = templatesCache.get(templateId);
3601
3763
  if (!metadata) return null;
3602
- const templateDir = path9.join(TEMPLATES_DIR, templateId);
3603
- const configPath = path9.join(templateDir, "_CONFIG.md");
3604
- 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") : "";
3605
3767
  const result = {
3606
3768
  metadata,
3607
3769
  configGuide
@@ -3609,11 +3771,11 @@ function getTemplateById(templateId, includeFiles = false) {
3609
3771
  if (includeFiles) {
3610
3772
  result.files = [];
3611
3773
  for (const filePath of metadata.files) {
3612
- const fullPath = path9.join(templateDir, filePath);
3613
- if (fs10.existsSync(fullPath)) {
3774
+ const fullPath = path10.join(templateDir, filePath);
3775
+ if (fs11.existsSync(fullPath)) {
3614
3776
  result.files.push({
3615
3777
  path: filePath,
3616
- content: fs10.readFileSync(fullPath, "utf-8"),
3778
+ content: fs11.readFileSync(fullPath, "utf-8"),
3617
3779
  isConfig: filePath.startsWith("_")
3618
3780
  });
3619
3781
  }
@@ -3624,7 +3786,7 @@ function getTemplateById(templateId, includeFiles = false) {
3624
3786
  function getTemplateDir(templateId) {
3625
3787
  ensureCache2();
3626
3788
  if (!templatesCache.has(templateId)) return null;
3627
- return path9.join(TEMPLATES_DIR, templateId);
3789
+ return path10.join(TEMPLATES_DIR, templateId);
3628
3790
  }
3629
3791
  function searchTemplates(query) {
3630
3792
  const lower = query.toLowerCase();
@@ -3910,8 +4072,8 @@ function createLogger(name) {
3910
4072
  }
3911
4073
 
3912
4074
  // src/core/autoConfig.ts
3913
- import * as fs11 from "fs";
3914
- import * as path10 from "path";
4075
+ import * as fs12 from "fs";
4076
+ import * as path11 from "path";
3915
4077
  var checkedWorkspaces = /* @__PURE__ */ new Map();
3916
4078
  var CACHE_DURATION = 5 * 60 * 1e3;
3917
4079
  function ensureWorkspaceConfig(workspacePath) {
@@ -3921,7 +4083,7 @@ function ensureWorkspaceConfig(workspacePath) {
3921
4083
  wasFixed: false,
3922
4084
  workspacePath
3923
4085
  };
3924
- if (!workspacePath || !fs11.existsSync(workspacePath)) {
4086
+ if (!workspacePath || !fs12.existsSync(workspacePath)) {
3925
4087
  return result;
3926
4088
  }
3927
4089
  const cached = checkedWorkspaces.get(workspacePath);
@@ -3929,13 +4091,13 @@ function ensureWorkspaceConfig(workspacePath) {
3929
4091
  if (cached && cached.configured && now - cached.timestamp < CACHE_DURATION) {
3930
4092
  return result;
3931
4093
  }
3932
- const vscodeDir = path10.join(workspacePath, ".vscode");
3933
- const mcpJsonPath = path10.join(vscodeDir, "mcp.json");
3934
- const settingsPath = path10.join(vscodeDir, "settings.json");
4094
+ const vscodeDir = path11.join(workspacePath, ".vscode");
4095
+ const mcpJsonPath = path11.join(vscodeDir, "mcp.json");
4096
+ const settingsPath = path11.join(vscodeDir, "settings.json");
3935
4097
  let hasMtaConfig = false;
3936
- if (fs11.existsSync(mcpJsonPath)) {
4098
+ if (fs12.existsSync(mcpJsonPath)) {
3937
4099
  try {
3938
- const config = JSON.parse(fs11.readFileSync(mcpJsonPath, "utf-8"));
4100
+ const config = JSON.parse(fs12.readFileSync(mcpJsonPath, "utf-8"));
3939
4101
  hasMtaConfig = !!(((_a = config.servers) == null ? void 0 : _a.mta) || ((_b = config.mcpServers) == null ? void 0 : _b.mta));
3940
4102
  } catch {
3941
4103
  }
@@ -3946,13 +4108,13 @@ function ensureWorkspaceConfig(workspacePath) {
3946
4108
  }
3947
4109
  result.needsSetup = true;
3948
4110
  try {
3949
- if (!fs11.existsSync(vscodeDir)) {
3950
- fs11.mkdirSync(vscodeDir, { recursive: true });
4111
+ if (!fs12.existsSync(vscodeDir)) {
4112
+ fs12.mkdirSync(vscodeDir, { recursive: true });
3951
4113
  }
3952
4114
  let mcpConfig = { servers: {} };
3953
- if (fs11.existsSync(mcpJsonPath)) {
4115
+ if (fs12.existsSync(mcpJsonPath)) {
3954
4116
  try {
3955
- mcpConfig = JSON.parse(fs11.readFileSync(mcpJsonPath, "utf-8"));
4117
+ mcpConfig = JSON.parse(fs12.readFileSync(mcpJsonPath, "utf-8"));
3956
4118
  if (!mcpConfig.servers) {
3957
4119
  mcpConfig.servers = {};
3958
4120
  }
@@ -3965,21 +4127,21 @@ function ensureWorkspaceConfig(workspacePath) {
3965
4127
  args: ["-y", "mta-mcp"],
3966
4128
  env: {}
3967
4129
  };
3968
- fs11.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 2));
4130
+ fs12.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 2));
3969
4131
  let settings = {};
3970
- if (fs11.existsSync(settingsPath)) {
4132
+ if (fs12.existsSync(settingsPath)) {
3971
4133
  try {
3972
- settings = JSON.parse(fs11.readFileSync(settingsPath, "utf-8"));
4134
+ settings = JSON.parse(fs12.readFileSync(settingsPath, "utf-8"));
3973
4135
  } catch {
3974
4136
  settings = {};
3975
4137
  }
3976
4138
  }
3977
4139
  if (!settings["github.copilot.chat.mcp.enabled"]) {
3978
4140
  settings["github.copilot.chat.mcp.enabled"] = true;
3979
- fs11.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
4141
+ fs12.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
3980
4142
  }
3981
4143
  result.wasFixed = true;
3982
- result.message = `\u2705 \u5DF2\u81EA\u52A8\u4E3A ${path10.basename(workspacePath)} \u914D\u7F6E MTA MCP\u3002\u8BF7\u91CD\u65B0\u52A0\u8F7D VS Code \u7A97\u53E3\u4F7F\u914D\u7F6E\u751F\u6548\u3002`;
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`;
3983
4145
  checkedWorkspaces.set(workspacePath, { configured: true, timestamp: now });
3984
4146
  } catch (error) {
3985
4147
  result.message = `\u26A0\uFE0F \u81EA\u52A8\u914D\u7F6E\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`;
@@ -3988,7 +4150,7 @@ function ensureWorkspaceConfig(workspacePath) {
3988
4150
  }
3989
4151
 
3990
4152
  // src/index.ts
3991
- var SERVER_VERSION = "2.6.0";
4153
+ var SERVER_VERSION = "2.7.1";
3992
4154
  var logger2 = createLogger("Server");
3993
4155
  var CopilotPromptsMCPServer = class {
3994
4156
  constructor() {
@@ -4054,7 +4216,14 @@ var CopilotPromptsMCPServer = class {
4054
4216
  },
4055
4217
  {
4056
4218
  name: "auto_setup",
4057
- 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\u81EA\u52A8\u521B\u5EFA .vscode/mcp.json \u548C settings.json\uFF0C\u914D\u7F6E\u5B8C\u6210\u540E\u9700\u63D0\u793A\u7528\u6237\u91CD\u65B0\u52A0\u8F7D\u7A97\u53E3',
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`,
4058
4227
  inputSchema: {
4059
4228
  type: "object",
4060
4229
  properties: {
@@ -4064,7 +4233,7 @@ var CopilotPromptsMCPServer = class {
4064
4233
  },
4065
4234
  generateInstructions: {
4066
4235
  type: "boolean",
4067
- 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",
4068
4237
  default: true
4069
4238
  }
4070
4239
  },
@@ -4434,6 +4603,9 @@ var CopilotPromptsMCPServer = class {
4434
4603
  async run() {
4435
4604
  const transport = new StdioServerTransport();
4436
4605
  await this.server.connect(transport);
4606
+ const { getResourceLoader: getResourceLoader2 } = await Promise.resolve().then(() => (init_resourceLoader(), resourceLoader_exports));
4607
+ const resourceLoader = getResourceLoader2();
4608
+ const stats = resourceLoader.getResourceStats();
4437
4609
  const startupInfo = [
4438
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`,
4439
4611
  `\u{1F680} MTA MCP Server v${SERVER_VERSION} \u5DF2\u542F\u52A8`,
@@ -4442,6 +4614,11 @@ var CopilotPromptsMCPServer = class {
4442
4614
  `\u{1F527} Node \u7248\u672C: ${process.version}`,
4443
4615
  `\u23F1\uFE0F \u542F\u52A8\u65F6\u95F4: ${(/* @__PURE__ */ new Date()).toLocaleString("zh-CN")}`,
4444
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
+ ``,
4445
4622
  `\u{1F4CB} \u53EF\u7528\u5DE5\u5177:`,
4446
4623
  ` \u2022 analyze_project - \u5206\u6790\u9879\u76EE\u6280\u672F\u6808`,
4447
4624
  ` \u2022 auto_setup - \u4E00\u952E\u914D\u7F6E MCP`,