autosnippet 3.0.0 → 3.0.2

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 (290) hide show
  1. package/README.md +230 -324
  2. package/bin/api-server.js +1 -1
  3. package/bin/cli.js +204 -244
  4. package/bin/mcp-server.js +5 -3
  5. package/config/knowledge-base.config.js +132 -132
  6. package/dashboard/dist/assets/{icons-CEfgGaZi.js → icons-Cdq22n2i.js} +95 -100
  7. package/dashboard/dist/assets/index-ClkyPkDX.js +133 -0
  8. package/dashboard/dist/assets/index-t4QrJwv1.css +1 -0
  9. package/dashboard/dist/index.html +3 -3
  10. package/lib/bootstrap.js +8 -8
  11. package/lib/cli/AiScanService.js +86 -40
  12. package/lib/cli/KnowledgeSyncService.js +113 -74
  13. package/lib/cli/SetupService.js +439 -277
  14. package/lib/cli/UpgradeService.js +63 -100
  15. package/lib/core/AstAnalyzer.js +276 -597
  16. package/lib/core/ast/ProjectGraph.js +101 -40
  17. package/lib/core/ast/ensure-grammars.js +232 -0
  18. package/lib/core/ast/index.js +115 -0
  19. package/lib/core/ast/lang-dart.js +661 -0
  20. package/lib/core/ast/lang-go.js +530 -0
  21. package/lib/core/ast/lang-java.js +435 -0
  22. package/lib/core/ast/lang-javascript.js +272 -0
  23. package/lib/core/ast/lang-kotlin.js +423 -0
  24. package/lib/core/ast/lang-objc.js +388 -0
  25. package/lib/core/ast/lang-python.js +371 -0
  26. package/lib/core/ast/lang-swift.js +337 -0
  27. package/lib/core/ast/lang-typescript.js +503 -0
  28. package/lib/core/capability/CapabilityProbe.js +18 -9
  29. package/lib/core/constitution/Constitution.js +2 -3
  30. package/lib/core/constitution/ConstitutionValidator.js +65 -24
  31. package/lib/core/discovery/DartDiscoverer.js +534 -0
  32. package/lib/core/discovery/DiscovererRegistry.js +83 -0
  33. package/lib/core/discovery/GenericDiscoverer.js +225 -0
  34. package/lib/core/discovery/GoDiscoverer.js +541 -0
  35. package/lib/core/discovery/JvmDiscoverer.js +506 -0
  36. package/lib/core/discovery/NodeDiscoverer.js +466 -0
  37. package/lib/core/discovery/ProjectDiscoverer.js +93 -0
  38. package/lib/core/discovery/PythonDiscoverer.js +338 -0
  39. package/lib/core/discovery/SpmDiscoverer.js +5 -0
  40. package/lib/core/discovery/index.js +53 -0
  41. package/lib/core/enhancement/EnhancementPack.js +71 -0
  42. package/lib/core/enhancement/EnhancementRegistry.js +47 -0
  43. package/lib/core/enhancement/android-enhancement.js +102 -0
  44. package/lib/core/enhancement/django-enhancement.js +70 -0
  45. package/lib/core/enhancement/fastapi-enhancement.js +63 -0
  46. package/lib/core/enhancement/go-grpc-enhancement.js +152 -0
  47. package/lib/core/enhancement/go-web-enhancement.js +201 -0
  48. package/lib/core/enhancement/index.js +65 -0
  49. package/lib/core/enhancement/node-server-enhancement.js +88 -0
  50. package/lib/core/enhancement/react-enhancement.js +86 -0
  51. package/lib/core/enhancement/spring-enhancement.js +112 -0
  52. package/lib/core/enhancement/vue-enhancement.js +96 -0
  53. package/lib/core/gateway/Gateway.js +8 -9
  54. package/lib/core/gateway/GatewayActionRegistry.js +1 -1
  55. package/lib/core/permission/PermissionManager.js +12 -8
  56. package/lib/domain/index.js +13 -9
  57. package/lib/domain/knowledge/KnowledgeEntry.js +111 -101
  58. package/lib/domain/knowledge/KnowledgeRepository.js +0 -1
  59. package/lib/domain/knowledge/Lifecycle.js +22 -22
  60. package/lib/domain/knowledge/index.js +9 -12
  61. package/lib/domain/knowledge/values/Constraints.js +31 -21
  62. package/lib/domain/knowledge/values/Content.js +21 -13
  63. package/lib/domain/knowledge/values/Quality.js +31 -18
  64. package/lib/domain/knowledge/values/Reasoning.js +20 -12
  65. package/lib/domain/knowledge/values/Relations.js +37 -25
  66. package/lib/domain/knowledge/values/Stats.js +18 -12
  67. package/lib/domain/knowledge/values/index.js +4 -3
  68. package/lib/domain/snippet/Snippet.js +35 -10
  69. package/lib/external/ai/AiFactory.js +48 -16
  70. package/lib/external/ai/AiProvider.js +184 -90
  71. package/lib/external/ai/providers/ClaudeProvider.js +25 -12
  72. package/lib/external/ai/providers/GoogleGeminiProvider.js +59 -30
  73. package/lib/external/ai/providers/MockProvider.js +9 -3
  74. package/lib/external/ai/providers/OpenAiProvider.js +51 -29
  75. package/lib/external/mcp/McpServer.js +66 -36
  76. package/lib/external/mcp/errorHandler.js +23 -11
  77. package/lib/external/mcp/handlers/LanguageExtensions.js +138 -53
  78. package/lib/external/mcp/handlers/TargetClassifier.js +52 -16
  79. package/lib/external/mcp/handlers/bootstrap/pipeline/BootstrapSnapshot.js +81 -20
  80. package/lib/external/mcp/handlers/bootstrap/pipeline/EpisodicMemory.js +71 -42
  81. package/lib/external/mcp/handlers/bootstrap/pipeline/IncrementalBootstrap.js +9 -17
  82. package/lib/external/mcp/handlers/bootstrap/pipeline/ToolResultCache.js +14 -9
  83. package/lib/external/mcp/handlers/bootstrap/pipeline/dimension-context.js +15 -7
  84. package/lib/external/mcp/handlers/bootstrap/pipeline/orchestrator.js +352 -153
  85. package/lib/external/mcp/handlers/bootstrap/pipeline/tier-scheduler.js +52 -12
  86. package/lib/external/mcp/handlers/bootstrap/skills.js +143 -39
  87. package/lib/external/mcp/handlers/bootstrap.js +691 -168
  88. package/lib/external/mcp/handlers/browse.js +66 -22
  89. package/lib/external/mcp/handlers/candidate.js +118 -35
  90. package/lib/external/mcp/handlers/consolidated.js +49 -17
  91. package/lib/external/mcp/handlers/guard.js +104 -39
  92. package/lib/external/mcp/handlers/knowledge.js +60 -36
  93. package/lib/external/mcp/handlers/search.js +43 -14
  94. package/lib/external/mcp/handlers/skill.js +120 -45
  95. package/lib/external/mcp/handlers/structure.js +240 -86
  96. package/lib/external/mcp/handlers/system.js +42 -12
  97. package/lib/external/mcp/handlers/wiki.js +58 -33
  98. package/lib/external/mcp/tools.js +306 -123
  99. package/lib/http/HttpServer.js +72 -47
  100. package/lib/http/middleware/RateLimiter.js +5 -3
  101. package/lib/http/middleware/errorHandler.js +6 -1
  102. package/lib/http/middleware/requestLogger.js +14 -3
  103. package/lib/http/middleware/roleResolver.js +30 -23
  104. package/lib/http/routes/ai.js +387 -265
  105. package/lib/http/routes/auth.js +81 -61
  106. package/lib/http/routes/candidates.js +430 -320
  107. package/lib/http/routes/commands.js +289 -189
  108. package/lib/http/routes/extract.js +158 -125
  109. package/lib/http/routes/guardRules.js +309 -217
  110. package/lib/http/routes/knowledge.js +213 -154
  111. package/lib/http/routes/modules.js +578 -0
  112. package/lib/http/routes/monitoring.js +6 -6
  113. package/lib/http/routes/recipes.js +104 -93
  114. package/lib/http/routes/search.js +361 -305
  115. package/lib/http/routes/skills.js +145 -98
  116. package/lib/http/routes/snippets.js +42 -30
  117. package/lib/http/routes/spm.js +3 -405
  118. package/lib/http/routes/violations.js +113 -93
  119. package/lib/http/routes/wiki.js +211 -170
  120. package/lib/http/utils/routeHelpers.js +3 -1
  121. package/lib/http/utils/sse-sessions.js +16 -6
  122. package/lib/http/utils/sse.js +15 -5
  123. package/lib/infrastructure/audit/AuditLogger.js +5 -2
  124. package/lib/infrastructure/audit/AuditStore.js +10 -7
  125. package/lib/infrastructure/cache/CacheService.js +3 -1
  126. package/lib/infrastructure/cache/GraphCache.js +8 -4
  127. package/lib/infrastructure/cache/UnifiedCacheAdapter.js +1 -1
  128. package/lib/infrastructure/config/ConfigLoader.js +9 -5
  129. package/lib/infrastructure/config/Defaults.js +30 -10
  130. package/lib/infrastructure/config/Paths.js +28 -8
  131. package/lib/infrastructure/config/TriggerSymbol.js +22 -10
  132. package/lib/infrastructure/database/DatabaseConnection.js +15 -10
  133. package/lib/infrastructure/database/migrations/001_initial_schema.js +0 -1
  134. package/lib/infrastructure/external/ClipboardManager.js +6 -2
  135. package/lib/infrastructure/external/NativeUi.js +50 -43
  136. package/lib/infrastructure/external/OpenBrowser.js +14 -17
  137. package/lib/infrastructure/external/XcodeAutomation.js +14 -258
  138. package/lib/infrastructure/logging/Logger.js +46 -30
  139. package/lib/infrastructure/monitoring/ErrorTracker.js +7 -5
  140. package/lib/infrastructure/monitoring/PerformanceMonitor.js +12 -4
  141. package/lib/infrastructure/paths/HeaderResolver.js +25 -9
  142. package/lib/infrastructure/paths/PathFinder.js +34 -12
  143. package/lib/infrastructure/plugin/PluginManager.js +26 -8
  144. package/lib/infrastructure/realtime/RealtimeService.js +2 -2
  145. package/lib/infrastructure/vector/Chunker.js +22 -7
  146. package/lib/infrastructure/vector/IndexingPipeline.js +46 -22
  147. package/lib/infrastructure/vector/JsonVectorAdapter.js +90 -53
  148. package/lib/infrastructure/vector/VectorStore.js +28 -10
  149. package/lib/injection/ServiceContainer.js +247 -93
  150. package/lib/platform/ios/index.js +63 -0
  151. package/lib/platform/ios/routes/spm.js +437 -0
  152. package/lib/platform/ios/snippet/PlaceholderConverter.js +55 -0
  153. package/lib/platform/ios/snippet/XcodeCodec.js +112 -0
  154. package/lib/{service → platform/ios}/spm/DependencyGraph.js +41 -17
  155. package/lib/{service → platform/ios}/spm/PackageSwiftParser.js +41 -14
  156. package/lib/{service → platform/ios}/spm/PolicyEngine.js +9 -4
  157. package/lib/platform/ios/spm/SpmDiscoverer.js +122 -0
  158. package/lib/{service → platform/ios}/spm/SpmService.js +385 -127
  159. package/lib/{service/automation → platform/ios/xcode}/SaveEventFilter.js +8 -7
  160. package/lib/platform/ios/xcode/XcodeAutomation.js +350 -0
  161. package/lib/{service/automation → platform/ios/xcode}/XcodeIntegration.js +325 -145
  162. package/lib/repository/base/BaseRepository.js +7 -9
  163. package/lib/repository/knowledge/KnowledgeRepository.impl.js +98 -75
  164. package/lib/repository/token/TokenUsageStore.js +4 -2
  165. package/lib/service/automation/ActionPipeline.js +1 -1
  166. package/lib/service/automation/AutomationOrchestrator.js +8 -4
  167. package/lib/service/automation/ContextCollector.js +7 -5
  168. package/lib/service/automation/DirectiveDetector.js +23 -16
  169. package/lib/service/automation/FileWatcher.js +112 -56
  170. package/lib/service/automation/TriggerResolver.js +6 -4
  171. package/lib/service/automation/handlers/AlinkHandler.js +24 -12
  172. package/lib/service/automation/handlers/CreateHandler.js +19 -20
  173. package/lib/service/automation/handlers/DraftHandler.js +14 -8
  174. package/lib/service/automation/handlers/GuardHandler.js +93 -63
  175. package/lib/service/automation/handlers/HeaderHandler.js +1 -6
  176. package/lib/service/automation/handlers/SearchHandler.js +155 -88
  177. package/lib/service/bootstrap/BootstrapTaskManager.js +77 -35
  178. package/lib/service/candidate/SimilarityService.js +25 -9
  179. package/lib/service/chat/AnalystAgent.js +50 -24
  180. package/lib/service/chat/CandidateGuardrail.js +143 -17
  181. package/lib/service/chat/ChatAgent.js +759 -243
  182. package/lib/service/chat/ContextWindow.js +116 -71
  183. package/lib/service/chat/ConversationStore.js +77 -36
  184. package/lib/service/chat/EpisodicConsolidator.js +47 -23
  185. package/lib/service/chat/HandoffProtocol.js +98 -22
  186. package/lib/service/chat/Memory.js +34 -14
  187. package/lib/service/chat/ProducerAgent.js +40 -20
  188. package/lib/service/chat/ProjectSemanticMemory.js +109 -78
  189. package/lib/service/chat/ReasoningLayer.js +148 -70
  190. package/lib/service/chat/ReasoningTrace.js +44 -32
  191. package/lib/service/chat/TaskPipeline.js +39 -19
  192. package/lib/service/chat/ToolRegistry.js +48 -29
  193. package/lib/service/chat/WorkingMemory.js +44 -18
  194. package/lib/service/chat/tools.js +1096 -494
  195. package/lib/service/context/RecipeExtractor.js +132 -51
  196. package/lib/service/cursor/CursorDeliveryPipeline.js +82 -37
  197. package/lib/service/cursor/KnowledgeCompressor.js +25 -22
  198. package/lib/service/cursor/RulesGenerator.js +13 -7
  199. package/lib/service/cursor/SkillsSyncer.js +77 -27
  200. package/lib/service/cursor/TokenBudget.js +2 -2
  201. package/lib/service/cursor/TopicClassifier.js +54 -20
  202. package/lib/service/guard/ComplianceReporter.js +55 -43
  203. package/lib/service/guard/ExclusionManager.js +67 -29
  204. package/lib/service/guard/GuardCheckEngine.js +381 -86
  205. package/lib/service/guard/GuardFeedbackLoop.js +22 -10
  206. package/lib/service/guard/GuardService.js +29 -19
  207. package/lib/service/guard/RuleLearner.js +55 -23
  208. package/lib/service/guard/SourceFileCollector.js +27 -20
  209. package/lib/service/guard/ViolationsStore.js +43 -38
  210. package/lib/service/knowledge/CodeEntityGraph.js +147 -82
  211. package/lib/service/knowledge/ConfidenceRouter.js +12 -10
  212. package/lib/service/knowledge/KnowledgeFileWriter.js +147 -56
  213. package/lib/service/knowledge/KnowledgeGraphService.js +81 -34
  214. package/lib/service/knowledge/KnowledgeService.js +222 -112
  215. package/lib/service/module/ModuleService.js +969 -0
  216. package/lib/service/quality/FeedbackCollector.js +27 -15
  217. package/lib/service/quality/QualityScorer.js +78 -24
  218. package/lib/service/recipe/RecipeCandidateValidator.js +110 -44
  219. package/lib/service/recipe/RecipeParser.js +78 -45
  220. package/lib/service/search/CoarseRanker.js +43 -28
  221. package/lib/service/search/CrossEncoderReranker.js +32 -21
  222. package/lib/service/search/InvertedIndex.js +21 -7
  223. package/lib/service/search/MultiSignalRanker.js +90 -28
  224. package/lib/service/search/RetrievalFunnel.js +45 -24
  225. package/lib/service/search/SearchEngine.js +255 -103
  226. package/lib/service/skills/EventAggregator.js +32 -15
  227. package/lib/service/skills/SignalCollector.js +140 -64
  228. package/lib/service/skills/SkillAdvisor.js +79 -42
  229. package/lib/service/skills/SkillHooks.js +16 -14
  230. package/lib/service/snippet/PlaceholderConverter.js +5 -0
  231. package/lib/service/snippet/SnippetFactory.js +116 -99
  232. package/lib/service/snippet/SnippetInstaller.js +234 -62
  233. package/lib/service/snippet/codecs/SnippetCodec.js +67 -0
  234. package/lib/service/snippet/codecs/VSCodeCodec.js +102 -0
  235. package/lib/service/snippet/codecs/XcodeCodec.js +5 -0
  236. package/lib/service/wiki/WikiGenerator.js +637 -263
  237. package/lib/shared/DimensionCopyRegistry.js +472 -0
  238. package/lib/shared/LanguageService.js +399 -0
  239. package/lib/shared/PathGuard.js +45 -28
  240. package/lib/shared/RecipeReadinessChecker.js +72 -12
  241. package/lib/shared/constants.js +41 -41
  242. package/lib/shared/errors/BaseError.js +2 -2
  243. package/lib/shared/errors/index.js +4 -4
  244. package/lib/shared/similarity.js +25 -8
  245. package/lib/shared/token-utils.js +6 -2
  246. package/lib/shared/utils/common.js +12 -4
  247. package/package.json +49 -13
  248. package/scripts/bench-real-projects.mjs +256 -0
  249. package/scripts/build-native-ui.js +30 -30
  250. package/scripts/clear-old-vector-index.js +5 -35
  251. package/scripts/clear-vector-cache.js +7 -37
  252. package/scripts/collect-test-project-stats.mjs +160 -0
  253. package/scripts/diagnose-mcp.js +41 -32
  254. package/scripts/ensure-parse-package.js +6 -9
  255. package/scripts/generate-recipe-drafts.js +116 -77
  256. package/scripts/init-db.js +3 -20
  257. package/scripts/init-snippets.js +305 -0
  258. package/scripts/init-vector-db.js +173 -170
  259. package/scripts/install-cursor-skill.js +148 -104
  260. package/scripts/install-full.js +8 -21
  261. package/scripts/install-vscode-copilot.js +146 -145
  262. package/scripts/migrate-md-to-knowledge.mjs +139 -151
  263. package/scripts/postinstall-safe.js +5 -17
  264. package/scripts/recipe-audit.js +106 -82
  265. package/scripts/release.js +283 -323
  266. package/scripts/setup-mcp-config.js +60 -52
  267. package/scripts/verify-context-api.js +20 -20
  268. package/skills/autosnippet-analysis/SKILL.md +10 -6
  269. package/skills/autosnippet-candidates/SKILL.md +27 -26
  270. package/skills/autosnippet-coldstart/SKILL.md +555 -38
  271. package/skills/autosnippet-concepts/SKILL.md +349 -337
  272. package/skills/autosnippet-create/SKILL.md +5 -5
  273. package/skills/autosnippet-reference-dart/SKILL.md +543 -0
  274. package/skills/autosnippet-reference-go/SKILL.md +539 -0
  275. package/skills/autosnippet-reference-java/SKILL.md +534 -0
  276. package/skills/autosnippet-reference-jsts/SKILL.md +41 -9
  277. package/skills/autosnippet-reference-kotlin/SKILL.md +526 -0
  278. package/skills/autosnippet-reference-objc/SKILL.md +29 -6
  279. package/skills/autosnippet-reference-python/SKILL.md +800 -0
  280. package/skills/autosnippet-reference-swift/SKILL.md +70 -14
  281. package/skills/autosnippet-structure/SKILL.md +4 -4
  282. package/templates/cursor-rules/autosnippet-conventions.mdc +2 -2
  283. package/templates/recipes-setup/README.md +2 -2
  284. package/templates/recipes-setup/_template.md +1 -1
  285. package/dashboard/dist/assets/index-Bun3ld_J.css +0 -1
  286. package/dashboard/dist/assets/index-_Sk_Dmg3.js +0 -143
  287. package/resources/asd-entry/main.swift +0 -159
  288. package/scripts/build-asd-entry.js +0 -51
  289. package/scripts/init-xcode-snippets.js +0 -311
  290. package/template.json +0 -39
@@ -3,16 +3,16 @@
3
3
  /**
4
4
  * VSCode/Cursor MCP 配置辅助脚本
5
5
  * 帮助用户快速配置 AutoSnippet MCP 集成
6
- *
6
+ *
7
7
  * 使用:
8
8
  * node scripts/setup-mcp-config.js [--editor vscode|cursor] [--path /path/to/project]
9
9
  */
10
10
 
11
- import { execSync } from 'node:child_process';
12
11
  import fs from 'node:fs';
13
- import path from 'node:path';
14
- import os from 'node:os';
15
12
  import { createRequire } from 'node:module';
13
+ import os from 'node:os';
14
+ import path from 'node:path';
15
+
16
16
  const require = createRequire(import.meta.url);
17
17
 
18
18
  const args = require('minimist')(process.argv.slice(2));
@@ -26,15 +26,13 @@ const isCursor = editor === 'cursor';
26
26
  const isQuiet = process.env.ASD_QUIET === 'true';
27
27
 
28
28
  // 检测是否在 AutoSnippet 仓库内执行
29
- const isAutoSnippetRepo = fs.existsSync(path.join(projectPath, 'bin/mcp-server.js')) &&
29
+ const isAutoSnippetRepo =
30
+ fs.existsSync(path.join(projectPath, 'bin/mcp-server.js')) &&
30
31
  fs.existsSync(path.join(projectPath, 'bin/asd')) &&
31
32
  fs.existsSync(path.join(projectPath, 'package.json'));
32
33
 
33
34
  if (isAutoSnippetRepo && !args.path) {
34
35
  if (!isQuiet) {
35
- console.log('⚠️ 检测到在 AutoSnippet 仓库内执行');
36
- console.log(' AutoSnippet 仓库不应配置 MCP 服务器');
37
- console.log(' 如需为其他项目配置,请使用: --path /path/to/project');
38
36
  }
39
37
  process.exit(0);
40
38
  }
@@ -44,7 +42,9 @@ if (isAutoSnippetRepo && !args.path) {
44
42
  // 检查 MCP Server
45
43
  const mcpServerPath = path.join(projectPath, 'bin/mcp-server.js');
46
44
  if (!fs.existsSync(mcpServerPath)) {
47
- if (!isQuiet) console.error(`✗ MCP Server 未找到: ${mcpServerPath}`);
45
+ if (!isQuiet) {
46
+ console.error(`✗ MCP Server 未找到: ${mcpServerPath}`);
47
+ }
48
48
  process.exit(1);
49
49
  }
50
50
 
@@ -57,65 +57,72 @@ if (isVSCode) {
57
57
  } else if (isCursor) {
58
58
  configureCursor();
59
59
  } else {
60
- if (!isQuiet) console.error('✗ 未知编辑器,使用 --editor vscode 或 --editor cursor');
60
+ if (!isQuiet) {
61
+ console.error('✗ 未知编辑器,使用 --editor vscode 或 --editor cursor');
62
+ }
61
63
  process.exit(1);
62
64
  }
63
65
 
64
66
  function configureVSCode() {
65
67
  // 找到 settings.json 路径
66
68
  if (os.platform() === 'darwin') {
67
- settingsPath = path.join(os.homedir(), 'Library/Application Support/Code/User/settings.json');
69
+ settingsPath = path.join(os.homedir(), 'Library/Application Support/Code/User/settings.json');
68
70
  } else if (os.platform() === 'win32') {
69
- settingsPath = path.join(os.getenv('APPDATA'), 'Code/User/settings.json');
71
+ settingsPath = path.join(os.getenv('APPDATA'), 'Code/User/settings.json');
70
72
  } else {
71
- settingsPath = path.join(os.homedir(), '.config/Code/User/settings.json');
73
+ settingsPath = path.join(os.homedir(), '.config/Code/User/settings.json');
72
74
  }
73
75
 
74
76
  // 读取现有设置
75
77
  let settings = {};
76
78
  if (fs.existsSync(settingsPath)) {
77
- try {
78
- const content = fs.readFileSync(settingsPath, 'utf8');
79
- settings = JSON.parse(content);
80
- } catch (e) {
81
- // 忽略解析错误
82
- }
79
+ try {
80
+ const content = fs.readFileSync(settingsPath, 'utf8');
81
+ settings = JSON.parse(content);
82
+ } catch (_e) {
83
+ // 忽略解析错误
84
+ }
83
85
  }
84
86
 
85
87
  // 添加 MCP 配置
86
88
  if (!settings['github.copilot.mcp']) {
87
- settings['github.copilot.mcp'] = {};
89
+ settings['github.copilot.mcp'] = {};
88
90
  }
89
91
  if (!settings['github.copilot.mcp'].servers) {
90
- settings['github.copilot.mcp'].servers = [];
92
+ settings['github.copilot.mcp'].servers = [];
91
93
  }
92
94
 
93
95
  // 检查 autosnippet 是否已存在
94
- const existingIndex = settings['github.copilot.mcp'].servers.findIndex(s => s.name === 'autosnippet');
95
-
96
+ const existingIndex = settings['github.copilot.mcp'].servers.findIndex(
97
+ (s) => s.name === 'autosnippet'
98
+ );
99
+
96
100
  const mcpConfig = {
97
- name: 'autosnippet',
98
- command: 'node',
99
- args: [mcpServerPath],
100
- env: {
101
- ASD_UI_URL: 'http://localhost:3000'
102
- }
101
+ name: 'autosnippet',
102
+ command: 'node',
103
+ args: [mcpServerPath],
104
+ env: {
105
+ ASD_UI_URL: 'http://localhost:3000',
106
+ },
103
107
  };
104
108
 
105
109
  if (existingIndex >= 0) {
106
- settings['github.copilot.mcp'].servers[existingIndex] = mcpConfig;
110
+ settings['github.copilot.mcp'].servers[existingIndex] = mcpConfig;
107
111
  } else {
108
- settings['github.copilot.mcp'].servers.push(mcpConfig);
112
+ settings['github.copilot.mcp'].servers.push(mcpConfig);
109
113
  }
110
114
 
111
115
  // 写入设置
112
116
  try {
113
- fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
114
- fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
115
- if (!isQuiet) console.log('✅ VSCode MCP 配置完成');
117
+ fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
118
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
119
+ if (!isQuiet) {
120
+ }
116
121
  } catch (e) {
117
- if (!isQuiet) console.error(`✗ 保存设置失败: ${e.message}`);
118
- process.exit(1);
122
+ if (!isQuiet) {
123
+ console.error(`✗ 保存设置失败: ${e.message}`);
124
+ }
125
+ process.exit(1);
119
126
  }
120
127
  }
121
128
 
@@ -125,25 +132,26 @@ function configureCursor() {
125
132
 
126
133
  // 创建配置
127
134
  const config = {
128
- mcpServers: {
129
- autosnippet: {
130
- command: 'node',
131
- args: [
132
- path.relative(projectPath, mcpServerPath) || './bin/mcp-server.js'
133
- ],
134
- env: {
135
- ASD_UI_URL: 'http://localhost:3000'
136
- }
137
- }
138
- }
135
+ mcpServers: {
136
+ autosnippet: {
137
+ command: 'node',
138
+ args: [path.relative(projectPath, mcpServerPath) || './bin/mcp-server.js'],
139
+ env: {
140
+ ASD_UI_URL: 'http://localhost:3000',
141
+ },
142
+ },
143
+ },
139
144
  };
140
145
 
141
146
  try {
142
- fs.mkdirSync(cursorConfigDir, { recursive: true });
143
- fs.writeFileSync(cursorConfigPath, JSON.stringify(config, null, 2), 'utf8');
144
- if (!isQuiet) console.log('✅ Cursor MCP 配置完成');
147
+ fs.mkdirSync(cursorConfigDir, { recursive: true });
148
+ fs.writeFileSync(cursorConfigPath, JSON.stringify(config, null, 2), 'utf8');
149
+ if (!isQuiet) {
150
+ }
145
151
  } catch (e) {
146
- if (!isQuiet) console.error(`✗ 保存配置失败: ${e.message}`);
147
- process.exit(1);
152
+ if (!isQuiet) {
153
+ console.error(`✗ 保存配置失败: ${e.message}`);
154
+ }
155
+ process.exit(1);
148
156
  }
149
157
  }
@@ -21,33 +21,33 @@ const opts = {
21
21
  path: url.pathname,
22
22
  method: 'POST',
23
23
  headers: {
24
- 'Content-Type': 'application/json',
25
- 'Content-Length': Buffer.byteLength(body)
26
- }
24
+ 'Content-Type': 'application/json',
25
+ 'Content-Length': Buffer.byteLength(body),
26
+ },
27
27
  };
28
28
 
29
29
  const req = client.request(opts, (res) => {
30
30
  let data = '';
31
- res.on('data', (ch) => { data += ch; });
31
+ res.on('data', (ch) => {
32
+ data += ch;
33
+ });
32
34
  res.on('end', () => {
33
- if (res.statusCode !== 200) {
34
- console.error(`❌ API 返回 ${res.statusCode}`);
35
- process.exit(1);
36
- }
37
- try {
38
- const json = JSON.parse(data);
39
- if (!json.items || !Array.isArray(json.items)) {
40
- console.error('❌ 返回结构异常,缺少 items 数组');
41
- process.exit(1);
35
+ if (res.statusCode !== 200) {
36
+ console.error(`❌ API 返回 ${res.statusCode}`);
37
+ process.exit(1);
42
38
  }
43
- console.log(`✅ /api/context/search 可用,返回 ${json.items.length} 条`);
44
- if (json.items.length > 0) {
45
- console.log(' 示例:', json.items[0].metadata?.sourcePath || json.items[0].id);
39
+ try {
40
+ const json = JSON.parse(data);
41
+ if (!json.items || !Array.isArray(json.items)) {
42
+ console.error('❌ 返回结构异常,缺少 items 数组');
43
+ process.exit(1);
44
+ }
45
+ if (json.items.length > 0) {
46
+ }
47
+ } catch (e) {
48
+ console.error('❌ 解析响应失败:', e.message);
49
+ process.exit(1);
46
50
  }
47
- } catch (e) {
48
- console.error('❌ 解析响应失败:', e.message);
49
- process.exit(1);
50
- }
51
51
  });
52
52
  });
53
53
 
@@ -143,17 +143,21 @@ autosnippet_bootstrap(operation=refine, candidateIds: ["id1", "id2", ...])
143
143
  | 字段 | 重要性 | AI 可填? |
144
144
  |------|-------|---------|
145
145
  | title | ★★★ 必填 | ✅ |
146
- | code | ★★★ 必填 | ✅ |
146
+ | content (markdown+pattern+rationale) | ★★★ 必填 | ✅ |
147
147
  | language | ★★★ 必填 | ✅ |
148
- | rationale | ★★★ 强烈推荐 | ✅ |
149
- | knowledgeType | ★★★ 强烈推荐 | ✅ |
148
+ | kind (rule/pattern/fact) | ★★★ 必填 | ✅ |
149
+ | doClause | ★★★ 必填 | ✅ |
150
+ | category | ★★★ 必填 | ✅ |
151
+ | trigger | ★★★ 必填 | ✅ |
152
+ | description | ★★★ 必填 | ✅ |
153
+ | headers | ★★★ 必填 | ✅ |
154
+ | usageGuide | ★★★ 必填 | ✅ |
155
+ | knowledgeType | ★★★ 必填 | ✅ |
156
+ | reasoning | ★★★ 必填 | Agent 必须自己填 |
150
157
  | complexity | ★★☆ 推荐 | ✅ |
151
158
  | scope | ★★☆ 推荐 | ✅ |
152
159
  | steps | ★★☆ 推荐 | ✅ |
153
160
  | constraints.preconditions | ★★☆ 推荐 | ✅ |
154
- | summary / description | ★★★ 强烈推荐 | ✅ |
155
- | usageGuide | ★★☆ 推荐 | ⚠️ 需人工审核 |
156
- | reasoning | ★★★ 必填 | Agent 必须自己填 |
157
161
 
158
162
  ---
159
163
 
@@ -78,8 +78,16 @@ Every candidate submitted via `submit_candidate` or `submit_candidates` supports
78
78
  | Field | Type | Example |
79
79
  |-------|------|---------|
80
80
  | **title** | string | "网络请求统一封装 - APIClient" |
81
- | **code** | string | The code pattern (maps to `content.pattern`). Use Xcode placeholders `<#name#>` for variables. |
81
+ | **content** | object | `{ markdown: "≥200字 Markdown 正文", pattern: "核心代码模式", rationale: "设计原理" }` |
82
82
  | **language** | string | swift / objc / javascript / python etc. |
83
+ | **kind** | string | `rule` / `pattern` / `fact` |
84
+ | **doClause** | string | 英文祈使句正向指令(≠60 tokens)|
85
+ | **trigger** | string | `@` 开头 kebab-case,如 `@api-client` |
86
+ | **description** | string | 中文摘要 ≤80字 |
87
+ | **category** | string | View / Service / Tool / Model / Network / Storage / UI / Utility |
88
+ | **headers** | string[] | 完整 import 语句数组,无 import 传 `[]` |
89
+ | **usageGuide** | string | Markdown ### 章节格式的使用指南 |
90
+ | **knowledgeType** | string | `code-pattern` / `architecture` / `best-practice` 等 |
83
91
 
84
92
  ### Layer 2: Classification (strongly recommended — enables filtering & search)
85
93
 
@@ -91,20 +99,9 @@ Every candidate submitted via `submit_candidate` or `submit_candidates` supports
91
99
  | **scope** | string | `universal` (通用) \| `project-specific` (本项目) \| `target-specific` (特定 Target) |
92
100
  | **tags** | string[] | `["networking", "async-await", "error-handling"]` |
93
101
 
94
- ### Layer 3: Description & Documentation (强烈建议含双语字段)
95
-
96
- | Field | Type | Description |
97
- |-------|------|-------------|
98
- | **description** | string | 一句话功能描述 |
99
- | **summary** | string | 中文详细摘要(等同 summary_cn,Markdown),含功能介绍、设计背景 |
100
- | **summary_cn** | string | 中文摘要(≤100字)— 与 summary 二选一 |
101
- | **summary_en** | string | 英文摘要(≤100 words)— **强烈建议**,提升检索与 AI 理解 |
102
- | **trigger** | string | 触发关键词,**必须** `@` 开头。如 `@api-client` |
103
- | **usageGuide** | string | 中文使用指南(等同 usageGuide_cn,Markdown),包含 `###` 章节 |
104
- | **usageGuide_cn** | string | 中文使用指南 — 与 usageGuide 二选一 |
105
- | **usageGuide_en** | string | 英文使用指南(Markdown ### 章节)— **推荐** |
102
+ ### Layer 3: Structured Content (high value 代码变更与实施步骤)
106
103
 
107
- ### Layer 4: Structured Content (high value enables step-by-step guidance & code diff)
104
+ > **注意**: Layer 1 已包含 V3 全部必填字段(title, content, language, kind, doClause, trigger, description, category, headers, usageGuide, knowledgeType)。本层为可选的高价值补充字段。
108
105
 
109
106
  | Field | Type | Structure |
110
107
  |-------|------|-----------|
@@ -259,7 +256,7 @@ Severity: `error` (must fix) | `warning` (should fix) | `info` (suggestion)
259
256
  2. **Maximize information density** — Agent's primary value is extracting structured metadata that humans would skip
260
257
  3. **Always fill Layer 1-3 + Reasoning + Recipe-Ready Checklist** at minimum; Layer 4-7 for complex patterns
261
258
  4. **Reasoning is mandatory** — Every candidate MUST include `reasoning.whyStandard` + `reasoning.sources` + `reasoning.confidence`. No exceptions.
262
- 5. **Bilingual recommended**`summary_cn` + `summary_en`, `usageGuide` + `usageGuide_en`. English improves AI understanding and search.
259
+ 5. **V3 必填字段**title, content(markdown+pattern+rationale), trigger, kind, doClause, description, language, category, headers, knowledgeType, usageGuide, reasoning
263
260
  6. **Check `recipeReadyHints` in submit response** — If not empty, supplement fields and resubmit
264
261
  7. **Parallel query existing Recipes** during generation to reduce duplicates and fill `relations`
265
262
  6. **Code examples**: use Xcode placeholders (`<#URL#>`, `<#Token#>`), explain in `usageGuide`
@@ -304,15 +301,15 @@ Recommended sections: When to use / When not to use / Key points / Dependencies
304
301
 
305
302
  ### 备选:二次补全流程
306
303
 
307
- Step 1: 提交基本字段(title, code, language)→ 获得 candidate ID(`autosnippet_submit_knowledge` 内置自动校验 + 去重检查)
304
+ Step 1: 提交基本字段(title, content, language)→ 获得 candidate ID(`autosnippet_submit_knowledge` 内置自动校验 + 去重检查)
308
305
  Step 2: 根据提交返回的校验结果补全缺失字段
309
306
  Step 3: 重新提交完整候选
310
307
 
311
308
  > 注:`autosnippet_enrich_candidates` / `autosnippet_validate_candidate` / `autosnippet_check_duplicate` 已移入 admin 层级。Agent 层级的 `autosnippet_submit_knowledge` 已内置自动校验 + 去重,无需额外调用。
312
309
 
313
- 需要补全的两层字段:
314
- - **语义字段**: rationale, knowledgeType, complexity, scope, steps, constraints
315
- - **Recipe 必填**: category, trigger, summary_cn, summary_en, headers, usageGuide
310
+ 需要补全的字段:
311
+ - **语义字段**: content.rationale, knowledgeType, complexity, scope, steps, constraints
312
+ - **Recipe 必填**: kind, doClause, category, trigger, description, headers, usageGuide, reasoning
316
313
 
317
314
  ---
318
315
 
@@ -324,18 +321,23 @@ Step 3: 重新提交完整候选
324
321
  "items": [
325
322
  {
326
323
  "title": "BiliAPI 网络请求封装",
327
- "code": "class BiliAPI {\n static func request<T: Decodable>(_ endpoint: Endpoint) async throws -> T {\n let (data, response) = try await URLSession.shared.data(for: endpoint.urlRequest)\n guard let http = response as? HTTPURLResponse, 200..<300 ~= http.statusCode else {\n throw BiliError.invalidResponse\n }\n return try JSONDecoder().decode(T.self, from: data)\n }\n}",
324
+ "content": {
325
+ "markdown": "## BiliAPI 网络请求统一封装\n\n### ✅ 标准用法\n```swift\nclass BiliAPI {\n static func request<T: Decodable>(_ endpoint: Endpoint) async throws -> T {\n let (data, response) = try await URLSession.shared.data(for: endpoint.urlRequest)\n guard let http = response as? HTTPURLResponse, 200..<300 ~= http.statusCode else {\n throw BiliError.invalidResponse\n }\n return try JSONDecoder().decode(T.self, from: data)\n }\n}\n```\n\n### 使用示例\n```swift\nlet user: UserInfo = try await BiliAPI.request(UserInfoEndpoint(uid: uid))\n```\n\n### 要点\n- 所有网络请求统一通过 BiliAPI.request()\n- 支持泛型解码,自动 JSON → Model\n- 统一错误处理和响应验证",
326
+ "pattern": "class BiliAPI {\n static func request<T: Decodable>(_ endpoint: Endpoint) async throws -> T {\n let (data, response) = try await URLSession.shared.data(for: endpoint.urlRequest)\n guard let http = response as? HTTPURLResponse, 200..<300 ~= http.statusCode else {\n throw BiliError.invalidResponse\n }\n return try JSONDecoder().decode(T.self, from: data)\n }\n}",
327
+ "rationale": "统一网络层避免各模块各自实现 URLSession 调用,减少重复代码并统一错误处理策略。"
328
+ },
329
+ "description": "统一的 API 请求封装,支持泛型解码和错误处理",
330
+ "kind": "pattern",
331
+ "doClause": "Use BiliAPI.request() for all network calls with type-safe Decodable responses",
328
332
  "language": "swift",
329
333
  "category": "Network",
334
+ "trigger": "@bili-api-request",
335
+ "headers": ["import Foundation", "import BiliKit"],
330
336
  "knowledgeType": "code-pattern",
337
+ "usageGuide": "### When to use\n- 所有 B 站 API 调用\n- 需要类型安全的响应解码\n\n### Dependencies\n- Foundation\n- BiliKit/Models (Endpoint, BiliError)\n\n### Core steps\n1. 定义 Endpoint\n2. 调用 BiliAPI.request(endpoint)\n3. 处理 Result",
331
338
  "complexity": "intermediate",
332
339
  "scope": "project-specific",
333
340
  "tags": ["networking", "async-await", "generic", "decodable"],
334
- "description": "统一的 API 请求封装,支持泛型解码和错误处理",
335
- "summary": "基于 async/await 的网络请求封装层,提供类型安全的 API 调用接口。统一错误处理、响应验证和 JSON 解码。",
336
- "trigger": "@bili-api-request",
337
- "usageGuide": "### When to use\n- 所有 B 站 API 调用\n- 需要类型安全的响应解码\n\n### Dependencies\n- Foundation\n- BiliKit/Models (Endpoint, BiliError)\n\n### Core steps\n1. 定义 Endpoint\n2. 调用 BiliAPI.request(endpoint)\n3. 处理 Result",
338
- "rationale": "统一网络层避免各模块各自实现 URLSession 调用,减少重复代码并统一错误处理策略。",
339
341
  "steps": [
340
342
  {"title": "定义 Endpoint", "description": "创建符合 Endpoint 协议的请求描述", "code": "struct UserInfoEndpoint: Endpoint { ... }"},
341
343
  {"title": "发起请求", "description": "调用统一 API 方法", "code": "let user: UserInfo = try await BiliAPI.request(UserInfoEndpoint(uid: uid))"}
@@ -343,7 +345,6 @@ Step 3: 重新提交完整候选
343
345
  "codeChanges": [
344
346
  {"file": "Sources/Network/OldAPI.swift", "before": "URLSession.shared.dataTask(with: url) { ... }", "after": "let result: T = try await BiliAPI.request(endpoint)", "explanation": "替换回调式为 async/await"}
345
347
  ],
346
- "headers": ["import Foundation", "import BiliKit"],
347
348
  "constraints": {
348
349
  "preconditions": ["需要有效的网络连接", "Endpoint 必须实现 urlRequest 属性"],
349
350
  "sideEffects": ["发起网络请求"],