mta-mcp 1.8.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.
Files changed (112) hide show
  1. package/CHANGELOG.md +457 -0
  2. package/README.md +680 -0
  3. package/archive/docs/CLAUDE_SETUP.md +103 -0
  4. package/archive/docs/DEVELOPMENT_ROADMAP.md +186 -0
  5. package/archive/docs/GETTING_STARTED.md +337 -0
  6. package/archive/docs/MIGRATION_GUIDE.md +189 -0
  7. package/archive/docs/TROUBLESHOOTING.md +386 -0
  8. package/archive/docs/USAGE_GUIDE.md +739 -0
  9. package/archive/tests/test-cloud-dev.cjs +158 -0
  10. package/archive/tests/test-mcp.sh +46 -0
  11. package/archive/tests/test-miniprogram.cjs +94 -0
  12. package/archive/tests/test-phase2.cjs +144 -0
  13. package/archive/tests/test-phase3.cjs +121 -0
  14. package/archive/tests/test-phase4.cjs +249 -0
  15. package/archive/tests/test-standards.cjs +111 -0
  16. package/archive/tests/test-vitasage-config.cjs +25 -0
  17. package/build/core/agentTemplate.d.ts +33 -0
  18. package/build/core/agentTemplate.d.ts.map +1 -0
  19. package/build/core/agentTemplate.js +158 -0
  20. package/build/core/agentTemplate.js.map +1 -0
  21. package/build/core/codeValidator.d.ts +82 -0
  22. package/build/core/codeValidator.d.ts.map +1 -0
  23. package/build/core/codeValidator.js +287 -0
  24. package/build/core/codeValidator.js.map +1 -0
  25. package/build/core/githubClient.d.ts +26 -0
  26. package/build/core/githubClient.d.ts.map +1 -0
  27. package/build/core/githubClient.js +60 -0
  28. package/build/core/githubClient.js.map +1 -0
  29. package/build/core/i18nDetector.d.ts +47 -0
  30. package/build/core/i18nDetector.d.ts.map +1 -0
  31. package/build/core/i18nDetector.js +314 -0
  32. package/build/core/i18nDetector.js.map +1 -0
  33. package/build/core/projectContextManager.d.ts +39 -0
  34. package/build/core/projectContextManager.d.ts.map +1 -0
  35. package/build/core/projectContextManager.js +147 -0
  36. package/build/core/projectContextManager.js.map +1 -0
  37. package/build/core/smartAgentMatcher.d.ts +51 -0
  38. package/build/core/smartAgentMatcher.d.ts.map +1 -0
  39. package/build/core/smartAgentMatcher.js +493 -0
  40. package/build/core/smartAgentMatcher.js.map +1 -0
  41. package/build/core/standardsManager.d.ts +130 -0
  42. package/build/core/standardsManager.d.ts.map +1 -0
  43. package/build/core/standardsManager.js +595 -0
  44. package/build/core/standardsManager.js.map +1 -0
  45. package/build/core/types.d.ts +55 -0
  46. package/build/core/types.d.ts.map +1 -0
  47. package/build/core/types.js +21 -0
  48. package/build/core/types.js.map +1 -0
  49. package/build/index.d.ts +3 -0
  50. package/build/index.d.ts.map +1 -0
  51. package/build/index.js +463 -0
  52. package/build/index.js.map +1 -0
  53. package/build/tools/analyzeProject.d.ts +12 -0
  54. package/build/tools/analyzeProject.d.ts.map +1 -0
  55. package/build/tools/analyzeProject.js +85 -0
  56. package/build/tools/analyzeProject.js.map +1 -0
  57. package/build/tools/autoSetup.d.ts +15 -0
  58. package/build/tools/autoSetup.d.ts.map +1 -0
  59. package/build/tools/autoSetup.js +291 -0
  60. package/build/tools/autoSetup.js.map +1 -0
  61. package/build/tools/generateConfig.d.ts +16 -0
  62. package/build/tools/generateConfig.d.ts.map +1 -0
  63. package/build/tools/generateConfig.js +379 -0
  64. package/build/tools/generateConfig.js.map +1 -0
  65. package/build/tools/generateProjectAgent.d.ts +15 -0
  66. package/build/tools/generateProjectAgent.d.ts.map +1 -0
  67. package/build/tools/generateProjectAgent.js +348 -0
  68. package/build/tools/generateProjectAgent.js.map +1 -0
  69. package/build/tools/getCompactStandards.d.ts +20 -0
  70. package/build/tools/getCompactStandards.d.ts.map +1 -0
  71. package/build/tools/getCompactStandards.js +367 -0
  72. package/build/tools/getCompactStandards.js.map +1 -0
  73. package/build/tools/getSmartStandards.d.ts +14 -0
  74. package/build/tools/getSmartStandards.d.ts.map +1 -0
  75. package/build/tools/getSmartStandards.js +184 -0
  76. package/build/tools/getSmartStandards.js.map +1 -0
  77. package/build/tools/healthCheck.d.ts +14 -0
  78. package/build/tools/healthCheck.d.ts.map +1 -0
  79. package/build/tools/healthCheck.js +237 -0
  80. package/build/tools/healthCheck.js.map +1 -0
  81. package/build/tools/listAgents.d.ts +10 -0
  82. package/build/tools/listAgents.d.ts.map +1 -0
  83. package/build/tools/listAgents.js +79 -0
  84. package/build/tools/listAgents.js.map +1 -0
  85. package/build/tools/matchAgents.d.ts +14 -0
  86. package/build/tools/matchAgents.d.ts.map +1 -0
  87. package/build/tools/matchAgents.js +70 -0
  88. package/build/tools/matchAgents.js.map +1 -0
  89. package/build/tools/usePreset.d.ts +23 -0
  90. package/build/tools/usePreset.d.ts.map +1 -0
  91. package/build/tools/usePreset.js +163 -0
  92. package/build/tools/usePreset.js.map +1 -0
  93. package/generate-project-config.cjs +97 -0
  94. package/package.json +45 -0
  95. package/regenerate-vitasage.sh +30 -0
  96. package/src/core/codeValidator.ts +357 -0
  97. package/src/core/githubClient.ts +64 -0
  98. package/src/core/i18nDetector.ts +357 -0
  99. package/src/core/smartAgentMatcher.ts +490 -0
  100. package/src/core/standardsManager.ts +763 -0
  101. package/src/core/types.ts +72 -0
  102. package/src/index.ts +519 -0
  103. package/src/tools/analyzeProject.ts +94 -0
  104. package/src/tools/autoSetup.ts +312 -0
  105. package/src/tools/generateConfig.ts +429 -0
  106. package/src/tools/getCompactStandards.ts +413 -0
  107. package/src/tools/getSmartStandards.ts +205 -0
  108. package/src/tools/healthCheck.ts +261 -0
  109. package/src/tools/listAgents.ts +91 -0
  110. package/src/tools/matchAgents.ts +80 -0
  111. package/src/tools/usePreset.ts +180 -0
  112. package/tsconfig.json +20 -0
@@ -0,0 +1,158 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * 微信小程序云开发相关功能测试
5
+ * 测试 StandardsManager 对云开发关键词的识别能力
6
+ */
7
+
8
+ const { StandardsManager } = require('./build/core/standardsManager.js');
9
+
10
+ const manager = new StandardsManager();
11
+
12
+ console.log('🧪 微信小程序云开发功能测试\n');
13
+ console.log('=' .repeat(60));
14
+
15
+ // 测试计数器
16
+ let passed = 0;
17
+ let failed = 0;
18
+
19
+ /**
20
+ * 测试辅助函数
21
+ */
22
+ function test(name, fn) {
23
+ try {
24
+ fn();
25
+ console.log(`✅ ${name}`);
26
+ passed++;
27
+ } catch (error) {
28
+ console.log(`❌ ${name}`);
29
+ console.log(` 错误: ${error.message}`);
30
+ failed++;
31
+ }
32
+ }
33
+
34
+ // 测试1: 云函数场景检测
35
+ test('云函数场景检测', () => {
36
+ const result = manager.getRelevantStandards({ scenario: '云函数开发' });
37
+ if (!result.includes('standards://frameworks/wechat-miniprogram')) {
38
+ throw new Error('未检测到微信小程序规范');
39
+ }
40
+ });
41
+
42
+ // 测试2: 云数据库场景检测
43
+ test('云数据库场景检测', () => {
44
+ const result = manager.getRelevantStandards({ scenario: '云数据库操作' });
45
+ if (!result.includes('standards://frameworks/wechat-miniprogram')) {
46
+ throw new Error('未检测到微信小程序规范');
47
+ }
48
+ });
49
+
50
+ // 测试3: 云存储场景检测
51
+ test('云存储场景检测', () => {
52
+ const result = manager.getRelevantStandards({ scenario: '云存储管理' });
53
+ if (!result.includes('standards://frameworks/wechat-miniprogram')) {
54
+ throw new Error('未检测到微信小程序规范');
55
+ }
56
+ });
57
+
58
+ // 测试4: wx.cloud API 调用检测
59
+ test('wx.cloud API 调用检测', () => {
60
+ const result = manager.getRelevantStandards({
61
+ fileContent: `
62
+ wx.cloud.callFunction({
63
+ name: 'getUserInfo',
64
+ data: { userId: '123' }
65
+ })
66
+ `
67
+ });
68
+ if (!result.includes('standards://frameworks/wechat-miniprogram')) {
69
+ throw new Error('未检测到微信小程序规范');
70
+ }
71
+ });
72
+
73
+ // 测试5: 云函数代码内容检测
74
+ test('云函数代码内容检测', () => {
75
+ const result = manager.getRelevantStandards({
76
+ fileContent: `
77
+ const cloud = require('wx-server-sdk')
78
+ cloud.init()
79
+
80
+ exports.main = async (event, context) => {
81
+ const db = cloud.database()
82
+ return await db.collection('users').get()
83
+ }
84
+ `
85
+ });
86
+ if (!result.includes('standards://frameworks/wechat-miniprogram')) {
87
+ throw new Error('未检测到微信小程序规范');
88
+ }
89
+ });
90
+
91
+ // 测试6: 云数据库操作代码检测
92
+ test('云数据库操作代码检测', () => {
93
+ const result = manager.getRelevantStandards({
94
+ fileContent: `
95
+ const db = wx.cloud.database()
96
+ const users = await db.collection('users')
97
+ .where({ status: 'active' })
98
+ .get()
99
+ `
100
+ });
101
+ if (!result.includes('standards://frameworks/wechat-miniprogram')) {
102
+ throw new Error('未检测到微信小程序规范');
103
+ }
104
+ });
105
+
106
+ // 测试7: 云存储上传代码检测
107
+ test('云存储上传代码检测', () => {
108
+ const result = manager.getRelevantStandards({
109
+ fileContent: `
110
+ wx.cloud.uploadFile({
111
+ cloudPath: 'images/avatar.jpg',
112
+ filePath: tempFilePath
113
+ })
114
+ `
115
+ });
116
+ if (!result.includes('standards://frameworks/wechat-miniprogram')) {
117
+ throw new Error('未检测到微信小程序规范');
118
+ }
119
+ });
120
+
121
+ // 测试8: 组合检测 - 场景 + 导入
122
+ test('组合检测 - 云开发场景 + wx 导入', () => {
123
+ const result = manager.getRelevantStandards({
124
+ scenario: '云函数开发',
125
+ imports: ['wx']
126
+ });
127
+ if (!result.includes('standards://frameworks/wechat-miniprogram')) {
128
+ throw new Error('未检测到微信小程序规范');
129
+ }
130
+ });
131
+
132
+ // 测试9: 组合检测 - 文件类型 + 内容
133
+ test('组合检测 - .js 文件 + wx.cloud 内容', () => {
134
+ const result = manager.getRelevantStandards({
135
+ fileType: 'js',
136
+ fileContent: 'wx.cloud.init({ env: "prod" })'
137
+ });
138
+ if (!result.includes('standards://frameworks/wechat-miniprogram')) {
139
+ throw new Error('未检测到微信小程序规范');
140
+ }
141
+ });
142
+
143
+ // 测试10: callFunction 关键词检测
144
+ test('callFunction 关键词检测', () => {
145
+ const result = manager.getRelevantStandards({
146
+ fileContent: 'const res = await callFunction({ name: "login" })'
147
+ });
148
+ if (!result.includes('standards://frameworks/wechat-miniprogram')) {
149
+ throw new Error('未检测到微信小程序规范');
150
+ }
151
+ });
152
+
153
+ console.log('=' .repeat(60));
154
+ console.log(`\n📊 测试结果: ${passed} 通过, ${failed} 失败\n`);
155
+
156
+ if (failed > 0) {
157
+ process.exit(1);
158
+ }
@@ -0,0 +1,46 @@
1
+ #!/bin/bash
2
+
3
+ # Copilot Prompts MCP Server 测试脚本
4
+
5
+ echo "🧪 测试 MCP 服务器..."
6
+ echo ""
7
+
8
+ # 测试项目路径
9
+ TEST_PROJECT="/Users/pailasi/Work/VitaSage"
10
+
11
+ if [ ! -d "$TEST_PROJECT" ]; then
12
+ echo "❌ 测试项目不存在: $TEST_PROJECT"
13
+ exit 1
14
+ fi
15
+
16
+ echo "✅ 测试项目存在: $TEST_PROJECT"
17
+ echo ""
18
+
19
+ # 检查编译产物
20
+ if [ ! -f "build/index.js" ]; then
21
+ echo "❌ MCP 服务器未编译,正在编译..."
22
+ npm run build
23
+ fi
24
+
25
+ echo "✅ MCP 服务器已编译"
26
+ echo ""
27
+
28
+ # 测试 analyze_project 工具
29
+ echo "📊 测试 1: 分析项目"
30
+ echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"analyze_project","arguments":{"projectPath":"'$TEST_PROJECT'"}}}' | node build/index.js 2>&1 | head -n 20
31
+
32
+ echo ""
33
+ echo "---"
34
+ echo ""
35
+
36
+ # 测试 list_available_agents 工具
37
+ echo "📋 测试 2: 列出可用 Agents"
38
+ echo '{"jsonrpc":"2.0","id":2,"method":"tools/list"}' | node build/index.js 2>&1 | head -n 30
39
+
40
+ echo ""
41
+ echo "✅ 测试完成!"
42
+ echo ""
43
+ echo "💡 下一步:"
44
+ echo "1. 重启 Claude Desktop"
45
+ echo "2. 在对话中尝试: '分析 $TEST_PROJECT 项目'"
46
+ echo "3. 或尝试: '为 $TEST_PROJECT 生成 Copilot 配置'"
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * 测试微信小程序规范加载
5
+ */
6
+
7
+ const path = require('path');
8
+ const buildPath = path.join(__dirname, 'build');
9
+ const { StandardsManager } = require(path.join(buildPath, 'core/standardsManager.js'));
10
+
11
+ const manager = new StandardsManager();
12
+
13
+ console.log('=== 测试微信小程序规范 ===\n');
14
+
15
+ // 测试 1: 通过文件类型检测
16
+ console.log('测试 1: WXML 文件类型');
17
+ const test1 = manager.getRelevantStandards({
18
+ fileType: 'wxml'
19
+ });
20
+ console.log('匹配的规范:', test1);
21
+ console.log('');
22
+
23
+ // 测试 2: 通过导入检测
24
+ console.log('测试 2: 检测 wx 导入');
25
+ const test2 = manager.getRelevantStandards({
26
+ fileType: 'js',
27
+ imports: ['wx']
28
+ });
29
+ console.log('匹配的规范:', test2);
30
+ console.log('');
31
+
32
+ // 测试 3: 通过场景检测
33
+ console.log('测试 3: 小程序页面开发场景');
34
+ const test3 = manager.getRelevantStandards({
35
+ scenario: '小程序页面开发'
36
+ });
37
+ console.log('匹配的规范:', test3);
38
+ console.log('');
39
+
40
+ // 测试 4: 通过文件内容检测
41
+ console.log('测试 4: 检测小程序代码内容');
42
+ const test4 = manager.getRelevantStandards({
43
+ fileType: 'js',
44
+ fileContent: `
45
+ Page({
46
+ data: {
47
+ list: []
48
+ },
49
+ onLoad() {
50
+ this.fetchData()
51
+ },
52
+ fetchData() {
53
+ wx.request({
54
+ url: '/api/data',
55
+ success: (res) => {
56
+ this.setData({
57
+ list: res.data
58
+ })
59
+ }
60
+ })
61
+ }
62
+ })
63
+ `
64
+ });
65
+ console.log('匹配的规范:', test4);
66
+ console.log('');
67
+
68
+ // 测试 5: 读取微信小程序规范内容
69
+ console.log('测试 5: 读取规范内容');
70
+ try {
71
+ const content = manager.readStandard('standards://frameworks/wechat-miniprogram');
72
+ console.log('规范内容长度:', content.length, '字符');
73
+ console.log('前 200 字符:', content.substring(0, 200) + '...');
74
+ console.log('');
75
+ } catch (error) {
76
+ console.error('读取规范失败:', error.message);
77
+ }
78
+
79
+ // 测试 6: 获取所有可用规范(检查是否包含微信小程序)
80
+ console.log('测试 6: 检查可用规范列表');
81
+ const availableStandards = manager.getAvailableStandards();
82
+ const miniProgramStandard = availableStandards.find(s =>
83
+ s.uri.includes('wechat-miniprogram')
84
+ );
85
+ if (miniProgramStandard) {
86
+ console.log('✅ 找到微信小程序规范:');
87
+ console.log(' URI:', miniProgramStandard.uri);
88
+ console.log(' 名称:', miniProgramStandard.name);
89
+ console.log(' 描述:', miniProgramStandard.description);
90
+ } else {
91
+ console.log('❌ 未找到微信小程序规范');
92
+ }
93
+
94
+ console.log('\n=== 测试完成 ===');
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Phase 2 增强功能测试
4
+ * 测试文件内容检测、自动导入分析、权重匹配算法
5
+ */
6
+
7
+ const { Client } = require('@modelcontextprotocol/sdk/client/index.js');
8
+ const { StdioClientTransport } = require('@modelcontextprotocol/sdk/client/stdio.js');
9
+
10
+ console.log('🚀 测试 Phase 2: 增强上下文分析\n');
11
+
12
+ const transport = new StdioClientTransport({
13
+ command: 'node',
14
+ args: ['build/index.js'],
15
+ });
16
+
17
+ const client = new Client({
18
+ name: 'test-client',
19
+ version: '1.0.0',
20
+ }, {
21
+ capabilities: {},
22
+ });
23
+
24
+ async function test() {
25
+ await client.connect(transport);
26
+
27
+ // 测试 1: 自动检测 imports(提供文件内容)
28
+ console.log('📋 测试 1: 自动检测 Vue 组件的 imports\n');
29
+ const vueFileContent = `
30
+ <script setup lang="ts">
31
+ import { ref, computed } from 'vue'
32
+ import { useUserStore } from '@/stores/user'
33
+ import { ElMessage } from 'element-plus'
34
+
35
+ const userStore = useUserStore()
36
+ const count = ref(0)
37
+ </script>
38
+ `;
39
+
40
+ const result1 = await client.callTool({
41
+ name: 'get_relevant_standards',
42
+ arguments: {
43
+ fileType: 'vue',
44
+ fileContent: vueFileContent
45
+ }
46
+ });
47
+ console.log('📤 响应:', JSON.stringify(result1, null, 2).substring(0, 500) + '...\n');
48
+
49
+ // 测试 2: 权重算法 - API 层开发(多个信号)
50
+ console.log('📋 测试 2: API 层开发(场景 + 文件内容 + imports)\n');
51
+ const apiFileContent = `
52
+ import axios from 'axios'
53
+ import type { AxiosInstance } from 'axios'
54
+
55
+ const instance: AxiosInstance = axios.create({
56
+ baseURL: '/api',
57
+ timeout: 10000
58
+ })
59
+
60
+ instance.interceptors.request.use(config => {
61
+ return config
62
+ })
63
+ `;
64
+
65
+ const result2 = await client.callTool({
66
+ name: 'get_relevant_standards',
67
+ arguments: {
68
+ fileType: 'ts',
69
+ scenario: 'API 请求封装',
70
+ fileContent: apiFileContent
71
+ }
72
+ });
73
+ console.log('📤 响应:', JSON.stringify(result2, null, 2).substring(0, 500) + '...\n');
74
+
75
+ // 测试 3: 复杂场景 - 表单组件(多技术栈)
76
+ console.log('📋 测试 3: 表单组件(Vue + Pinia + Element Plus + i18n)\n');
77
+ const formContent = `
78
+ <script setup lang="ts">
79
+ import { ref } from 'vue'
80
+ import { ElForm, ElMessage } from 'element-plus'
81
+ import type { FormInstance, FormRules } from 'element-plus'
82
+ import { useI18n } from 'vue-i18n'
83
+ import { useFormStore } from '@/stores/form'
84
+
85
+ const { t } = useI18n()
86
+ const formStore = useFormStore()
87
+ const formRef = ref<FormInstance>()
88
+
89
+ const rules: FormRules = {
90
+ username: [{ required: true, message: t('form.required') }]
91
+ }
92
+ </script>
93
+ `;
94
+
95
+ const result3 = await client.callTool({
96
+ name: 'get_relevant_standards',
97
+ arguments: {
98
+ fileType: 'vue',
99
+ scenario: '创建表单组件',
100
+ fileContent: formContent
101
+ }
102
+ });
103
+ console.log('📤 响应:', JSON.stringify(result3, null, 2).substring(0, 800) + '...\n');
104
+
105
+ // 测试 4: 对比 - 只提供 imports vs 提供完整内容
106
+ console.log('📋 测试 4: 对比测试(仅 imports vs 完整内容)\n');
107
+
108
+ const result4a = await client.callTool({
109
+ name: 'get_relevant_standards',
110
+ arguments: {
111
+ fileType: 'vue',
112
+ imports: ['vue', 'pinia']
113
+ }
114
+ });
115
+
116
+ const result4b = await client.callTool({
117
+ name: 'get_relevant_standards',
118
+ arguments: {
119
+ fileType: 'vue',
120
+ fileContent: `
121
+ import { ref } from 'vue'
122
+ import { defineStore } from 'pinia'
123
+
124
+ const useStore = defineStore('main', () => {
125
+ const state = ref({})
126
+ return { state }
127
+ })
128
+ `
129
+ }
130
+ });
131
+
132
+ console.log('仅 imports:', JSON.stringify(result4a, null, 2).substring(0, 300));
133
+ console.log('\n完整内容:', JSON.stringify(result4b, null, 2).substring(0, 300) + '\n');
134
+
135
+ console.log('✅ Phase 2 测试完成!');
136
+
137
+ await client.close();
138
+ process.exit(0);
139
+ }
140
+
141
+ test().catch(error => {
142
+ console.error('❌ 测试失败:', error);
143
+ process.exit(1);
144
+ });
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Phase 3 性能与缓存优化测试
4
+ * 测试缓存机制、使用统计、性能监控
5
+ */
6
+
7
+ const { Client } = require('@modelcontextprotocol/sdk/client/index.js');
8
+ const { StdioClientTransport } = require('@modelcontextprotocol/sdk/client/stdio.js');
9
+
10
+ console.log('🚀 测试 Phase 3: 性能与缓存优化\n');
11
+
12
+ const transport = new StdioClientTransport({
13
+ command: 'node',
14
+ args: ['build/index.js'],
15
+ });
16
+
17
+ const client = new Client({
18
+ name: 'test-client',
19
+ version: '1.0.0',
20
+ }, {
21
+ capabilities: {},
22
+ });
23
+
24
+ async function test() {
25
+ await client.connect(transport);
26
+
27
+ // 测试 1: 缓存效果 - 多次请求相同规范
28
+ console.log('📋 测试 1: 缓存效果(连续3次请求相同规范)\n');
29
+
30
+ const testContext = {
31
+ fileType: 'vue',
32
+ imports: ['vue', 'element-plus'],
33
+ scenario: '表单组件'
34
+ };
35
+
36
+ console.log('第 1 次请求(冷启动,缓存未命中)...');
37
+ await client.callTool({
38
+ name: 'get_relevant_standards',
39
+ arguments: testContext
40
+ });
41
+
42
+ console.log('第 2 次请求(应该从缓存读取)...');
43
+ await client.callTool({
44
+ name: 'get_relevant_standards',
45
+ arguments: testContext
46
+ });
47
+
48
+ console.log('第 3 次请求(应该从缓存读取)...\n');
49
+ await client.callTool({
50
+ name: 'get_relevant_standards',
51
+ arguments: testContext
52
+ });
53
+
54
+ // 测试 2: 不同场景(建立使用统计)
55
+ console.log('📋 测试 2: 多场景使用(建立使用统计)\n');
56
+
57
+ const scenarios = [
58
+ { fileType: 'ts', imports: ['axios'], scenario: 'API 调用' },
59
+ { fileType: 'vue', imports: ['pinia'], scenario: '状态管理' },
60
+ { fileType: 'vue', imports: ['vue-i18n'], scenario: '国际化' },
61
+ { fileType: 'vue', imports: ['vue', 'element-plus'], scenario: '表单组件' }, // 重复
62
+ ];
63
+
64
+ for (const scenario of scenarios) {
65
+ console.log(`请求: ${scenario.scenario}...`);
66
+ await client.callTool({
67
+ name: 'get_relevant_standards',
68
+ arguments: scenario
69
+ });
70
+ }
71
+
72
+ console.log('');
73
+
74
+ // 测试 3: 查看统计信息(不含缓存详情)
75
+ console.log('📋 测试 3: 查看使用统计和性能指标\n');
76
+
77
+ const stats = await client.callTool({
78
+ name: 'get_standards_stats',
79
+ arguments: { includeCache: false }
80
+ });
81
+
82
+ console.log('📊 统计信息:');
83
+ console.log(JSON.stringify(JSON.parse(stats.content[0].text), null, 2).substring(0, 1000) + '...\n');
84
+
85
+ // 测试 4: 查看缓存详情
86
+ console.log('📋 测试 4: 查看缓存详细信息\n');
87
+
88
+ const cacheStats = await client.callTool({
89
+ name: 'get_standards_stats',
90
+ arguments: { includeCache: true }
91
+ });
92
+
93
+ const cacheData = JSON.parse(cacheStats.content[0].text);
94
+
95
+ console.log('💾 缓存状态:');
96
+ console.log(`- 缓存大小: ${cacheData.cache.size}/${cacheData.cache.maxSize}`);
97
+ console.log(`- 缓存命中率: ${cacheData.performance.cacheHitRate}`);
98
+ console.log(`- 平均响应时间: ${cacheData.summary.averageResponseTime}`);
99
+ console.log(`- Token 节省总计: ${cacheData.performance.totalTokensSaved}`);
100
+
101
+ console.log('\n🔥 热门规范:');
102
+ cacheData.usage.topStandards.forEach((item, index) => {
103
+ console.log(`${index + 1}. ${item.standard} - 使用 ${item.count} 次`);
104
+ });
105
+
106
+ console.log('\n🎯 常用组合:');
107
+ cacheData.usage.topCombinations.slice(0, 3).forEach((item, index) => {
108
+ const standards = item.combination.split('|').map(s => s.split('/').pop());
109
+ console.log(`${index + 1}. ${standards.join(' + ')} - ${item.count} 次`);
110
+ });
111
+
112
+ console.log('\n✅ Phase 3 测试完成!');
113
+
114
+ await client.close();
115
+ process.exit(0);
116
+ }
117
+
118
+ test().catch(error => {
119
+ console.error('❌ 测试失败:', error);
120
+ process.exit(1);
121
+ });