autosnippet 1.7.4 → 2.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 (508) hide show
  1. package/README.md +13 -17
  2. package/bin/api-server.js +84 -70
  3. package/bin/cli.js +613 -0
  4. package/bin/mcp-server.js +27 -0
  5. package/config/constitution.yaml +134 -0
  6. package/config/default.json +51 -0
  7. package/config/knowledge-base.config.js +173 -0
  8. package/dashboard/dist/assets/axios-C0Zqfgkc.js +6 -0
  9. package/dashboard/dist/assets/icons-B4FfLfBA.js +446 -0
  10. package/dashboard/dist/assets/index-ChxJxX4B.js +154 -0
  11. package/dashboard/dist/assets/index-DwAp1mx5.css +1 -0
  12. package/dashboard/dist/assets/{react-markdown-DEEoHGnk.js → react-markdown-Bp8u1wRC.js} +1 -1
  13. package/dashboard/dist/assets/{syntax-highlighter-4Pe1PNPg.js → syntax-highlighter-C6bvFtpx.js} +1 -1
  14. package/dashboard/dist/assets/{vendor-CJtnAZ4B.js → vendor-Cky7Jynh.js} +47 -362
  15. package/dashboard/dist/index.html +7 -6
  16. package/dashboard/dist/manifest.json +85 -0
  17. package/dashboard/dist/service-worker.js +129 -0
  18. package/dashboard/dist/vite.svg +1 -0
  19. package/lib/bootstrap.js +193 -199
  20. package/lib/cli/AiScanService.js +238 -0
  21. package/lib/cli/CandidateSyncService.js +261 -0
  22. package/lib/cli/SetupService.js +666 -0
  23. package/lib/cli/SyncService.js +356 -0
  24. package/lib/cli/UpgradeService.js +222 -0
  25. package/lib/core/AstAnalyzer.js +994 -0
  26. package/lib/core/capability/CapabilityProbe.js +247 -0
  27. package/lib/core/constitution/Constitution.js +124 -0
  28. package/lib/core/constitution/ConstitutionValidator.js +260 -0
  29. package/lib/core/gateway/Gateway.js +323 -0
  30. package/lib/core/gateway/GatewayActionRegistry.js +235 -0
  31. package/lib/core/permission/PermissionManager.js +248 -0
  32. package/lib/core/session/SessionManager.js +232 -0
  33. package/lib/domain/candidate/Candidate.js +196 -0
  34. package/lib/domain/candidate/CandidateRepository.js +107 -0
  35. package/lib/domain/candidate/Reasoning.js +52 -0
  36. package/lib/domain/index.js +20 -0
  37. package/lib/domain/recipe/Recipe.js +418 -0
  38. package/lib/domain/recipe/RecipeRepository.js +54 -0
  39. package/lib/domain/snippet/Snippet.js +82 -0
  40. package/lib/domain/types/CandidateStatus.js +52 -0
  41. package/lib/external/ai/AiFactory.js +217 -0
  42. package/lib/external/ai/AiProvider.js +546 -0
  43. package/lib/external/ai/providers/ClaudeProvider.js +85 -0
  44. package/lib/external/ai/providers/GoogleGeminiProvider.js +95 -0
  45. package/lib/external/ai/providers/MockProvider.js +58 -0
  46. package/lib/external/ai/providers/OpenAiProvider.js +99 -0
  47. package/lib/external/mcp/McpServer.js +217 -0
  48. package/lib/external/mcp/envelope.js +35 -0
  49. package/lib/external/mcp/handlers/LanguageExtensions.js +270 -0
  50. package/lib/external/mcp/handlers/TargetClassifier.js +38 -0
  51. package/lib/external/mcp/handlers/bootstrap.js +2028 -0
  52. package/lib/external/mcp/handlers/browse.js +159 -0
  53. package/lib/external/mcp/handlers/candidate.js +439 -0
  54. package/lib/external/mcp/handlers/guard.js +183 -0
  55. package/lib/external/mcp/handlers/search.js +322 -0
  56. package/lib/external/mcp/handlers/skill.js +187 -0
  57. package/lib/external/mcp/handlers/structure.js +404 -0
  58. package/lib/external/mcp/handlers/system.js +202 -0
  59. package/lib/external/mcp/tools.js +646 -0
  60. package/lib/http/HttpServer.js +397 -0
  61. package/lib/http/api-spec.js +575 -0
  62. package/lib/http/middleware/RateLimiter.js +67 -0
  63. package/lib/http/middleware/errorHandler.js +91 -0
  64. package/lib/http/middleware/gatewayMiddleware.js +61 -0
  65. package/lib/http/middleware/requestLogger.js +25 -0
  66. package/lib/http/middleware/roleResolver.js +114 -0
  67. package/lib/http/routes/ai.js +245 -0
  68. package/lib/http/routes/auth.js +140 -0
  69. package/lib/http/routes/candidates.js +535 -0
  70. package/lib/http/routes/commands.js +194 -0
  71. package/lib/http/routes/extract.js +121 -0
  72. package/lib/http/routes/guardRules.js +309 -0
  73. package/lib/http/routes/health.js +35 -0
  74. package/lib/http/routes/monitoring.js +329 -0
  75. package/lib/http/routes/recipes.js +318 -0
  76. package/lib/http/routes/search.js +254 -0
  77. package/lib/http/routes/snippets.js +87 -0
  78. package/lib/http/routes/spm.js +290 -0
  79. package/lib/http/routes/violations.js +127 -0
  80. package/lib/infrastructure/audit/AuditLogger.js +120 -0
  81. package/lib/infrastructure/audit/AuditStore.js +198 -0
  82. package/lib/infrastructure/cache/CacheService.js +149 -0
  83. package/lib/infrastructure/cache/RedisService.js +365 -0
  84. package/lib/infrastructure/cache/UnifiedCacheAdapter.js +202 -0
  85. package/lib/infrastructure/config/ConfigLoader.js +110 -0
  86. package/lib/infrastructure/config/Defaults.js +48 -70
  87. package/lib/infrastructure/config/Paths.js +64 -95
  88. package/lib/infrastructure/config/TriggerSymbol.js +24 -33
  89. package/lib/infrastructure/database/DatabaseConnection.js +118 -0
  90. package/lib/infrastructure/database/migrations/005_unified_schema_reset.js +181 -0
  91. package/lib/infrastructure/database/migrations/006_add_kind_column.js +41 -0
  92. package/lib/infrastructure/database/migrations/007_guard_violations_table.js +38 -0
  93. package/lib/infrastructure/database/migrations/008_add_source_file_column.js +59 -0
  94. package/lib/infrastructure/database/migrations/009_recipes_v2_columns.js +44 -0
  95. package/lib/infrastructure/database/migrations/010_create_audit_and_sessions.js +58 -0
  96. package/lib/infrastructure/database/migrations/011_recipe_i18n_columns.js +61 -0
  97. package/lib/infrastructure/database/migrations/012_add_trigger_column.js +55 -0
  98. package/lib/infrastructure/database/migrations/013_create_knowledge_edges.js +80 -0
  99. package/lib/infrastructure/database/migrations/014_add_candidate_indexes.js +14 -0
  100. package/lib/infrastructure/event/EventBus.js +83 -0
  101. package/lib/infrastructure/external/ClipboardManager.js +55 -0
  102. package/lib/infrastructure/external/NativeUi.js +230 -0
  103. package/lib/infrastructure/external/OpenBrowser.js +96 -86
  104. package/lib/infrastructure/external/XcodeAutomation.js +175 -0
  105. package/lib/infrastructure/logging/Logger.js +84 -0
  106. package/lib/infrastructure/logging/ReasoningLogger.js +269 -0
  107. package/lib/infrastructure/monitoring/ErrorTracker.js +339 -0
  108. package/lib/infrastructure/monitoring/PerformanceMonitor.js +272 -0
  109. package/lib/infrastructure/monitoring/RoleDriftMonitor.js +259 -0
  110. package/lib/infrastructure/paths/HeaderResolver.js +99 -0
  111. package/lib/infrastructure/paths/PathFinder.js +81 -389
  112. package/lib/infrastructure/plugin/PluginManager.js +121 -0
  113. package/lib/infrastructure/quality/ComplianceEvaluator.js +326 -0
  114. package/lib/infrastructure/realtime/RealtimeService.js +170 -0
  115. package/lib/infrastructure/vector/Chunker.js +167 -0
  116. package/lib/infrastructure/vector/IndexingPipeline.js +176 -0
  117. package/lib/infrastructure/vector/JsonVectorAdapter.js +224 -0
  118. package/lib/infrastructure/vector/VectorStore.js +76 -0
  119. package/lib/injection/ServiceContainer.js +576 -0
  120. package/lib/repository/base/BaseRepository.js +257 -0
  121. package/lib/repository/candidate/CandidateRepository.impl.js +230 -0
  122. package/lib/repository/recipe/RecipeRepository.impl.js +498 -0
  123. package/lib/service/automation/ActionPipeline.js +63 -0
  124. package/lib/service/automation/AutomationOrchestrator.js +72 -0
  125. package/lib/service/automation/ContextCollector.js +35 -0
  126. package/lib/service/automation/DirectiveDetector.js +137 -0
  127. package/lib/service/automation/FileWatcher.js +340 -0
  128. package/lib/service/automation/SaveEventFilter.js +164 -0
  129. package/lib/service/automation/TriggerResolver.js +69 -0
  130. package/lib/service/automation/XcodeIntegration.js +346 -0
  131. package/lib/service/automation/handlers/AlinkHandler.js +29 -0
  132. package/lib/service/automation/handlers/CreateHandler.js +161 -0
  133. package/lib/service/automation/handlers/DraftHandler.js +70 -0
  134. package/lib/service/automation/handlers/GuardHandler.js +56 -0
  135. package/lib/service/automation/handlers/HeaderHandler.js +56 -0
  136. package/lib/service/automation/handlers/SearchHandler.js +146 -0
  137. package/lib/service/candidate/CandidateAggregator.js +52 -0
  138. package/lib/service/candidate/CandidateFileWriter.js +338 -0
  139. package/lib/service/candidate/CandidateService.js +816 -0
  140. package/lib/service/candidate/SimilarityService.js +112 -0
  141. package/lib/service/chat/ChatAgent.js +717 -0
  142. package/lib/service/chat/TaskPipeline.js +337 -0
  143. package/lib/service/chat/ToolRegistry.js +104 -0
  144. package/lib/service/chat/tools.js +1214 -0
  145. package/lib/service/context/RecipeExtractor.js +263 -0
  146. package/lib/service/guard/ExclusionManager.js +216 -0
  147. package/lib/service/guard/GuardCheckEngine.js +499 -0
  148. package/lib/service/guard/GuardService.js +247 -0
  149. package/lib/service/guard/RuleLearner.js +171 -0
  150. package/lib/service/guard/ViolationsStore.js +173 -0
  151. package/lib/service/knowledge/KnowledgeGraphService.js +206 -0
  152. package/lib/service/quality/FeedbackCollector.js +132 -0
  153. package/lib/service/quality/QualityScorer.js +153 -0
  154. package/lib/service/recipe/RecipeCandidateValidator.js +145 -0
  155. package/lib/service/recipe/RecipeFileWriter.js +499 -0
  156. package/lib/service/recipe/RecipeParser.js +285 -0
  157. package/lib/service/recipe/RecipeService.js +778 -0
  158. package/lib/service/recipe/RecipeStatsTracker.js +146 -0
  159. package/lib/service/search/CoarseRanker.js +91 -0
  160. package/lib/service/search/InvertedIndex.js +90 -0
  161. package/lib/service/search/MultiSignalRanker.js +160 -0
  162. package/lib/service/search/RetrievalFunnel.js +140 -0
  163. package/lib/service/search/SearchEngine.js +418 -0
  164. package/lib/service/snippet/SnippetFactory.js +175 -0
  165. package/lib/service/snippet/SnippetInstaller.js +133 -0
  166. package/lib/service/spm/DependencyGraph.js +210 -0
  167. package/lib/service/spm/PackageSwiftParser.js +229 -0
  168. package/lib/service/spm/PolicyEngine.js +86 -0
  169. package/lib/service/spm/SpmService.js +1122 -0
  170. package/lib/shared/RecipeReadinessChecker.js +99 -0
  171. package/lib/shared/errors/BaseError.js +94 -0
  172. package/lib/shared/errors/index.js +14 -0
  173. package/package.json +50 -38
  174. package/scripts/build-asd-entry.js +10 -5
  175. package/scripts/build-native-ui.js +9 -4
  176. package/scripts/clear-old-vector-index.js +3 -3
  177. package/scripts/clear-vector-cache.js +5 -2
  178. package/scripts/diagnose-mcp.js +3 -3
  179. package/scripts/ensure-parse-package.js +9 -4
  180. package/scripts/generate-recipe-drafts.js +2 -3
  181. package/scripts/init-db.js +48 -0
  182. package/scripts/init-vector-db.js +9 -4
  183. package/scripts/init-xcode-snippets.js +7 -6
  184. package/scripts/install-cursor-skill.js +148 -97
  185. package/scripts/install-full.js +9 -4
  186. package/scripts/install-vscode-copilot.js +12 -5
  187. package/scripts/postinstall-safe.js +7 -15
  188. package/scripts/recipe-audit.js +2 -3
  189. package/scripts/release.js +9 -3
  190. package/scripts/setup-mcp-config.js +9 -7
  191. package/scripts/verify-context-api.js +2 -2
  192. package/skills/autosnippet-analysis/SKILL.md +152 -0
  193. package/skills/autosnippet-candidates/SKILL.md +344 -96
  194. package/skills/autosnippet-coldstart/SKILL.md +468 -0
  195. package/skills/autosnippet-concepts/SKILL.md +26 -17
  196. package/skills/autosnippet-create/SKILL.md +21 -15
  197. package/skills/autosnippet-guard/SKILL.md +104 -18
  198. package/skills/autosnippet-intent/SKILL.md +23 -13
  199. package/skills/autosnippet-lifecycle/SKILL.md +105 -0
  200. package/skills/autosnippet-recipes/SKILL.md +116 -99
  201. package/skills/autosnippet-reference-jsts/SKILL.md +440 -0
  202. package/skills/autosnippet-reference-objc/SKILL.md +427 -0
  203. package/skills/autosnippet-reference-swift/SKILL.md +461 -0
  204. package/skills/autosnippet-structure/SKILL.md +67 -16
  205. package/templates/constitution.yaml +134 -0
  206. package/templates/copilot-instructions.md +59 -18
  207. package/templates/cursor-rules/autosnippet-conventions.mdc +55 -15
  208. package/templates/recipes-setup/README.md +60 -75
  209. package/templates/recipes-setup/_template.md +5 -4
  210. package/templates/recipes-setup/example.md +2 -1
  211. package/templates/recipes-setup/seed-error-handling.md +58 -0
  212. package/templates/recipes-setup/seed-naming-convention.md +62 -0
  213. package/templates/recipes-setup/seed-thread-safety.md +65 -0
  214. package/bin/asd +0 -21
  215. package/bin/asd-cli.js +0 -86
  216. package/bin/cli-commands.js +0 -627
  217. package/bin/cli-helpers.js +0 -241
  218. package/bin/create-snippet.js +0 -528
  219. package/bin/dashboard/helpers.js +0 -12
  220. package/bin/dashboard/routes/ai.js +0 -202
  221. package/bin/dashboard/routes/candidates.js +0 -75
  222. package/bin/dashboard/routes/commands.js +0 -42
  223. package/bin/dashboard/routes/core.js +0 -535
  224. package/bin/dashboard/routes/extract.js +0 -158
  225. package/bin/dashboard/routes/guard.js +0 -117
  226. package/bin/dashboard/routes/index.js +0 -27
  227. package/bin/dashboard/routes/recipes.js +0 -242
  228. package/bin/dashboard/routes/search.js +0 -942
  229. package/bin/dashboard/routes/snippets.js +0 -109
  230. package/bin/dashboard/routes/spm.js +0 -160
  231. package/bin/dashboard-server.js +0 -259
  232. package/bin/init-spec.js +0 -117
  233. package/checksums.json +0 -12
  234. package/dashboard/dist/assets/axios-D5GkNzM3.js +0 -6
  235. package/dashboard/dist/assets/index-BoYBT7s4.js +0 -76
  236. package/dashboard/dist/assets/index-ZqaWRulp.css +0 -1
  237. package/index.js +0 -0
  238. package/lib/agent/AdvancedCacheLayer.js +0 -462
  239. package/lib/agent/Agent.js +0 -402
  240. package/lib/agent/AgentCoordinator.js +0 -689
  241. package/lib/agent/BenchmarkRunner.js +0 -450
  242. package/lib/agent/ContextMapper.js +0 -440
  243. package/lib/agent/ConversationManager.js +0 -429
  244. package/lib/agent/ConversationMemory.js +0 -469
  245. package/lib/agent/CrossSessionLearner.js +0 -421
  246. package/lib/agent/DataSourceAdapter.js +0 -407
  247. package/lib/agent/ErrorHandler.js +0 -377
  248. package/lib/agent/IntentClassifier.js +0 -524
  249. package/lib/agent/MemoryManager.js +0 -420
  250. package/lib/agent/ResultFusion.js +0 -562
  251. package/lib/agent/Task.js +0 -337
  252. package/lib/agent/TokenBudget.js +0 -451
  253. package/lib/agent/UserPreferenceManager.js +0 -383
  254. package/lib/agent/agents/GenerateAgent.js +0 -706
  255. package/lib/agent/agents/LearnAgent.js +0 -708
  256. package/lib/agent/agents/LintAgent.js +0 -553
  257. package/lib/agent/agents/SearchAgent.js +0 -610
  258. package/lib/ai/AiFactory.js +0 -195
  259. package/lib/ai/AiProvider.js +0 -35
  260. package/lib/ai/candidateService.js +0 -185
  261. package/lib/ai/headerResolution.js +0 -89
  262. package/lib/ai/jsonParse.js +0 -115
  263. package/lib/ai/providers/ClaudeProvider.js +0 -303
  264. package/lib/ai/providers/GoogleGeminiProvider.js +0 -402
  265. package/lib/ai/providers/MockProvider.js +0 -104
  266. package/lib/ai/providers/OpenAiProvider.js +0 -387
  267. package/lib/ai/vectorStore.js +0 -89
  268. package/lib/api/APIGateway.js +0 -689
  269. package/lib/application/services/CandidateServiceV2.js +0 -307
  270. package/lib/application/services/ContextServiceCompat.js +0 -319
  271. package/lib/application/services/ContextServiceV2.js +0 -368
  272. package/lib/application/services/GuardServiceV2.js +0 -308
  273. package/lib/application/services/InjectionServiceV2.js +0 -404
  274. package/lib/application/services/IntelligentServiceLayer.js +0 -803
  275. package/lib/application/services/RecipeServiceV2.js +0 -476
  276. package/lib/application/services/SearchServiceV2.js +0 -770
  277. package/lib/application/services/SnippetFactoryV2.js +0 -250
  278. package/lib/application/services/SpecRepositoryV2.js +0 -624
  279. package/lib/application/usecases/guard/ValidateGuard.js +0 -84
  280. package/lib/application/usecases/index.js +0 -18
  281. package/lib/application/usecases/injection/InjectCode.js +0 -78
  282. package/lib/application/usecases/recipe/SearchRecipe.js +0 -63
  283. package/lib/application/usecases/snippet/CreateSnippet.js +0 -83
  284. package/lib/automation/ActionPipeline.js +0 -13
  285. package/lib/automation/AutomationOrchestrator.js +0 -23
  286. package/lib/automation/ContextCollector.js +0 -10
  287. package/lib/automation/OutputApplier.js +0 -10
  288. package/lib/automation/TriggerResolver.js +0 -13
  289. package/lib/business/metrics/MetricsHub.js +0 -442
  290. package/lib/business/recipe/RecipeHub.js +0 -460
  291. package/lib/business/search/SearchHub.js +0 -484
  292. package/lib/candidate/CandidateServiceV2.js +0 -8
  293. package/lib/candidate/aggregateCandidates.js +0 -79
  294. package/lib/candidate/qualityRules.js +0 -55
  295. package/lib/candidate/similarityService.js +0 -99
  296. package/lib/cli/README.md +0 -226
  297. package/lib/cli/candidateCommand.js +0 -143
  298. package/lib/cli/commands/BaseCommand.js +0 -65
  299. package/lib/cli/embedCommand.js +0 -47
  300. package/lib/cli/searchCommand.js +0 -138
  301. package/lib/cli/statusCommand.js +0 -256
  302. package/lib/cli/utils/cliHelpers.js +0 -76
  303. package/lib/cli/utils/clipboardHandler.js +0 -92
  304. package/lib/cli/utils/presetLoader.js +0 -70
  305. package/lib/context/ContextServiceCompat.js +0 -8
  306. package/lib/context/ContextServiceV2.js +0 -8
  307. package/lib/context/IndexingPipeline.js +0 -279
  308. package/lib/context/KnowledgeGraph.js +0 -627
  309. package/lib/context/RecipeExtractor.js +0 -787
  310. package/lib/context/WindowContextManager.js +0 -374
  311. package/lib/context/adapters/BaseAdapter.js +0 -116
  312. package/lib/context/adapters/JsonAdapter.js +0 -346
  313. package/lib/context/adapters/MilvusAdapter.js +0 -518
  314. package/lib/context/autoEmbed.js +0 -98
  315. package/lib/context/chunker.js +0 -195
  316. package/lib/context/constants.js +0 -100
  317. package/lib/context/index.js +0 -40
  318. package/lib/context/persistence.js +0 -168
  319. package/lib/context/recipe-schema.js +0 -482
  320. package/lib/core/BasePlugin.js +0 -164
  321. package/lib/core/ConfigManager.js +0 -291
  322. package/lib/core/EventBus.js +0 -128
  323. package/lib/core/Logger.js +0 -198
  324. package/lib/core/PluginLoader.js +0 -306
  325. package/lib/core/ServiceContainer.js +0 -214
  326. package/lib/dashboard/README.md +0 -303
  327. package/lib/domain/entities/Agent.js +0 -103
  328. package/lib/domain/entities/Memory.js +0 -112
  329. package/lib/domain/entities/Recipe.js +0 -196
  330. package/lib/domain/entities/Snippet.js +0 -121
  331. package/lib/domain/entities/v2/GuardRuleV2.js +0 -118
  332. package/lib/domain/entities/v2/LegacyAdapter.js +0 -50
  333. package/lib/domain/entities/v2/RecipeV2.js +0 -122
  334. package/lib/domain/entities/v2/SnippetV2.js +0 -118
  335. package/lib/domain/entities/v2/id.js +0 -13
  336. package/lib/domain/entities/v2/index.js +0 -14
  337. package/lib/guard/EnhancedGuardChecker.js +0 -163
  338. package/lib/guard/GuardExclusionManager.js +0 -216
  339. package/lib/guard/GuardRuleLearner.js +0 -180
  340. package/lib/guard/GuardRuleMigrator.js +0 -229
  341. package/lib/guard/GuardServiceV2.js +0 -8
  342. package/lib/guard/guardRules-iOS.js +0 -45
  343. package/lib/guard/guardRules.js +0 -102
  344. package/lib/guard/guardViolations.js +0 -113
  345. package/lib/guard/index.js +0 -15
  346. package/lib/guard/ios/audit.js +0 -266
  347. package/lib/guard/ios/codeChecks.js +0 -159
  348. package/lib/guard/ios/defaultRules.js +0 -268
  349. package/lib/guard/ios/staticCheck.js +0 -79
  350. package/lib/guard/ios/utils.js +0 -19
  351. package/lib/infrastructure/cache/CacheHub.js +0 -243
  352. package/lib/infrastructure/cache/CacheStore.js +0 -130
  353. package/lib/infrastructure/cache/vectorCache.js +0 -365
  354. package/lib/infrastructure/error/ErrorManager.js +0 -453
  355. package/lib/infrastructure/errors/AiError.js +0 -73
  356. package/lib/infrastructure/errors/BaseError.js +0 -50
  357. package/lib/infrastructure/errors/ContextError.js +0 -58
  358. package/lib/infrastructure/errors/ErrorHandler.js +0 -113
  359. package/lib/infrastructure/errors/GuardError.js +0 -14
  360. package/lib/infrastructure/errors/InjectionError.js +0 -14
  361. package/lib/infrastructure/errors/ValidationError.js +0 -49
  362. package/lib/infrastructure/errors/index.js +0 -14
  363. package/lib/infrastructure/external/spm/DepFixer.js +0 -164
  364. package/lib/infrastructure/external/spm/DepGraphAnalyzer.js +0 -98
  365. package/lib/infrastructure/external/spm/DepGraphService.js +0 -208
  366. package/lib/infrastructure/external/spm/DepPolicyEngine.js +0 -49
  367. package/lib/infrastructure/external/spm/DepReport.js +0 -10
  368. package/lib/infrastructure/external/spm/PackageParserV2.js +0 -322
  369. package/lib/infrastructure/external/spm/SpmDepsServiceV2.js +0 -466
  370. package/lib/infrastructure/external/spm/spmDepGraphPatch.js +0 -4
  371. package/lib/infrastructure/external/spm/spmDepMapUpdater.js +0 -476
  372. package/lib/infrastructure/external/spm/swiftParserClient.js +0 -311
  373. package/lib/infrastructure/external/spm/targetScanner.js +0 -214
  374. package/lib/infrastructure/filesystem/FileFinder.js +0 -111
  375. package/lib/infrastructure/logging/LogFactory.js +0 -160
  376. package/lib/infrastructure/logging/LoggerAdapter.js +0 -114
  377. package/lib/infrastructure/logging/index.js +0 -18
  378. package/lib/infrastructure/notification/ClipboardManager.js +0 -137
  379. package/lib/infrastructure/notification/NativeUi.js +0 -229
  380. package/lib/infrastructure/notification/Notifier.js +0 -115
  381. package/lib/infrastructure/paths/ProjectStructure.js +0 -222
  382. package/lib/infrastructure/process/ProcessHub.js +0 -452
  383. package/lib/infrastructure/vector/VectorMath.js +0 -131
  384. package/lib/injection/DirectiveParserV2.js +0 -217
  385. package/lib/injection/ImportDecisionEngine.js +0 -39
  386. package/lib/injection/ImportWriterV2.js +0 -707
  387. package/lib/injection/InjectionServiceV2.js +0 -8
  388. package/lib/injection/ModuleResolverV2.js +0 -261
  389. package/lib/injection/injectionService.js +0 -560
  390. package/lib/mcp/envelope.js +0 -21
  391. package/lib/mcp/schemas.js +0 -46
  392. package/lib/migration/knowledgeBaseMigrator.js +0 -203
  393. package/lib/quality/FeedbackCollector.js +0 -18
  394. package/lib/quality/QualityScorer.js +0 -62
  395. package/lib/quality/config/default.js +0 -16
  396. package/lib/quality/dimensions/CodeQualityDimension.js +0 -24
  397. package/lib/quality/dimensions/CompletenessDimension.js +0 -21
  398. package/lib/quality/dimensions/EngagementDimension.js +0 -20
  399. package/lib/quality/dimensions/FormatDimension.js +0 -18
  400. package/lib/quality/dimensions/MetadataDimension.js +0 -15
  401. package/lib/quality/index.js +0 -7
  402. package/lib/rateLimit.js +0 -49
  403. package/lib/recipe/RecipeServiceV2.js +0 -8
  404. package/lib/recipe/parseRecipeMd.js +0 -206
  405. package/lib/recipe/recipeStats.js +0 -199
  406. package/lib/recipe/validateRecipeCandidate.js +0 -54
  407. package/lib/search/MultiSignalRanker.js +0 -517
  408. package/lib/search/SearchServiceV2.js +0 -8
  409. package/lib/search/bm25.js +0 -63
  410. package/lib/search/coarseRanker.js +0 -169
  411. package/lib/search/contextAnalyzer.js +0 -135
  412. package/lib/search/featureExtractor.js +0 -24
  413. package/lib/search/fineRanker.js +0 -26
  414. package/lib/search/indexStore.js +0 -31
  415. package/lib/search/indexer.js +0 -64
  416. package/lib/search/invertedIndex.js +0 -32
  417. package/lib/search/ltrModel.js +0 -11
  418. package/lib/search/queryOptimizer.js +0 -11
  419. package/lib/search/rankingEngine.js +0 -44
  420. package/lib/search/recallEngine.js +0 -70
  421. package/lib/search/searchCache.js +0 -45
  422. package/lib/search/unifiedSearch.js +0 -243
  423. package/lib/services/agent/AgentManager.js +0 -417
  424. package/lib/services/agent/AgentPool.js +0 -336
  425. package/lib/services/agent/AgentService.js +0 -330
  426. package/lib/services/agent/BaseAgent.js +0 -356
  427. package/lib/services/agent/ChainManager.js +0 -294
  428. package/lib/services/agent/ConversationManager.js +0 -363
  429. package/lib/services/agent/IAgent.js +0 -198
  430. package/lib/services/agent/ITool.js +0 -118
  431. package/lib/services/agent/MemoryStore.js +0 -378
  432. package/lib/services/agent/ToolOrchestrator.js +0 -505
  433. package/lib/services/agent/ToolRegistry.js +0 -365
  434. package/lib/services/agent/agentServiceHelper.js +0 -32
  435. package/lib/services/agent/agents/CodeAgent.js +0 -71
  436. package/lib/services/agent/agents/GuardAgent.js +0 -76
  437. package/lib/services/agent/agents/RecipeAgent.js +0 -77
  438. package/lib/services/agent/agents/SearchAgent.js +0 -59
  439. package/lib/services/agent/tools/CodeAnalysisTool.js +0 -80
  440. package/lib/services/agent/tools/GuardCheckTool.js +0 -98
  441. package/lib/services/agent/tools/SemanticSearchTool.js +0 -95
  442. package/lib/services/ai/AiService.js +0 -449
  443. package/lib/services/ai/BaseAiProvider.js +0 -175
  444. package/lib/services/ai/EXAMPLES.md +0 -346
  445. package/lib/services/ai/IAiProvider.js +0 -104
  446. package/lib/services/ai/LegacyProviderAdapter.js +0 -148
  447. package/lib/services/ai/OpenAiCompatibleProvider.js +0 -266
  448. package/lib/services/ai/ProviderManager.js +0 -215
  449. package/lib/services/context/AdapterManager.js +0 -254
  450. package/lib/services/context/BaseContextAdapter.js +0 -212
  451. package/lib/services/context/ContextService.js +0 -378
  452. package/lib/services/context/IContextAdapter.js +0 -142
  453. package/lib/simulation/DirectiveEmulator.js +0 -323
  454. package/lib/simulation/EditorState.js +0 -389
  455. package/lib/simulation/OperationExecutor.js +0 -430
  456. package/lib/simulation/PermissionManager.js +0 -269
  457. package/lib/simulation/SimulatorInsertionManager.js +0 -93
  458. package/lib/simulation/VirtualFileSystem.js +0 -313
  459. package/lib/simulation/XcodeSimulator.js +0 -431
  460. package/lib/simulation/XcodeSimulatorAPIClient.js +0 -345
  461. package/lib/simulation/index.js +0 -15
  462. package/lib/snippet/MarkerLineV2.js +0 -175
  463. package/lib/snippet/SnippetFactoryV2.js +0 -8
  464. package/lib/snippet/SpecRepositoryV2.js +0 -8
  465. package/lib/snippet/snippetInstaller.js +0 -258
  466. package/lib/spm/PackageParserV2.js +0 -8
  467. package/lib/spm/SpmDepsServiceV2.js +0 -8
  468. package/lib/spm/spmDepMapUpdater.js +0 -4
  469. package/lib/spm/swiftParserClient.js +0 -4
  470. package/lib/spm/targetScanner.js +0 -4
  471. package/lib/watch/DirectiveDetector.js +0 -109
  472. package/lib/watch/FileDebouncer.js +0 -34
  473. package/lib/watch/FileWatchConfig.js +0 -49
  474. package/lib/watch/FileWatchService.js +0 -221
  475. package/lib/watch/fileWatcher.js +0 -18
  476. package/lib/watch/handlers/AlinkHandler.js +0 -55
  477. package/lib/watch/handlers/CreateHandler.js +0 -219
  478. package/lib/watch/handlers/DraftHandler.js +0 -113
  479. package/lib/watch/handlers/GuardHandler.js +0 -194
  480. package/lib/watch/handlers/HeaderHandler.js +0 -270
  481. package/lib/watch/handlers/SearchHandler.js +0 -1081
  482. package/lib/writeGuard.js +0 -219
  483. package/lib/xcode-search-cache-fix.js +0 -236
  484. package/scripts/build-knowledge-graph.js +0 -363
  485. package/scripts/check-paths.js +0 -206
  486. package/scripts/demo-candidates-submit.js +0 -76
  487. package/scripts/demo-permission-system.js +0 -390
  488. package/scripts/generate-checksums.js +0 -59
  489. package/scripts/mcp-server.js +0 -910
  490. package/scripts/migrate-recipes-metadata.js +0 -338
  491. package/scripts/recipe-migration-complete.js +0 -528
  492. package/scripts/recipe-migration-diagnose.js +0 -405
  493. package/scripts/test-permission-manager.js +0 -193
  494. package/scripts/test-xcode-simulator-advanced.js +0 -265
  495. package/scripts/test-xcode-simulator.js +0 -308
  496. package/scripts/verify-checksums.js +0 -77
  497. package/scripts/verify-code-upgrade.js +0 -409
  498. package/scripts/verify-mcp-vscode.sh +0 -300
  499. package/skills/autosnippet-batch-scan/SKILL.md +0 -67
  500. package/skills/autosnippet-candidates/SKILL_REDESIGNED.md +0 -823
  501. package/skills/autosnippet-dep-graph/SKILL.md +0 -69
  502. package/skills/autosnippet-recipe-candidates/SKILL.md +0 -204
  503. package/skills/autosnippet-search/SKILL.md +0 -39
  504. package/skills/autosnippet-when/SKILL.md +0 -50
  505. package/tools/parse-package/Package.resolved +0 -14
  506. package/tools/parse-package/Package.swift +0 -25
  507. package/tools/parse-package/README.md +0 -31
  508. package/tools/parse-package/Sources/ParsePackage/main.swift +0 -277
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # AutoSnippet
1
+ # AutoSnippet — Project Knowledge Engine
2
2
 
3
3
  连接开发者、AI 与项目知识库:人工审核沉淀标准,知识库存储 Recipe + Snippet,AI 按规范生成代码。基于 SPM,打通 Xcode 补全与 Cursor 按需检索。
4
4
 
@@ -22,6 +22,8 @@
22
22
 
23
23
  ### 1. 安装 AutoSnippet
24
24
 
25
+ > **要求**:Node.js ≥ 20
26
+
25
27
  ```bash
26
28
  npm install -g autosnippet
27
29
  ```
@@ -48,13 +50,14 @@ asd ui # 启动 Dashboard + watch
48
50
 
49
51
  `asd ui` 会启动 Web 管理后台并后台 watch;首次运行若前端不存在会自动构建。浏览器会自动打开 Dashboard。
50
52
 
51
- ![Dashboard 概览](./images/20260205232116_66_167.png)
53
+ ![Dashboard 概览](https://cdn.jsdelivr.net/gh/GxFn/blog-images@main/autosnippet-manual/20260205232116_66_167.png)
54
+
52
55
 
53
56
  ## 核心流程
54
57
 
55
58
  **智能 AI 优先 → 前端操作 → 命令行补充**
56
59
 
57
- 1. **Cursor AI 快捷扫描**(推荐):在 Cursor 中输入自然语言(如「扫描这个 Target」、「批量提取代码候选」),AI 智能触发 `autosnippet-batch-scan` Skill,通过 MCP 工具 `autosnippet_get_targets` → `autosnippet_get_target_files` → 按文件提取 → `autosnippet_submit_candidates` 一键批量扫描,自动提交候选到 Dashboard Candidates
60
+ 1. **Cursor AI 智能扫描**(推荐):在 Cursor 中输入自然语言(如「扫描这个 Target」、「批量提取代码候选」),AI 智能触发 `autosnippet-candidates` Skill,通过 MCP 工具 `autosnippet_get_targets` → `autosnippet_get_target_files` → 按文件提取 → `autosnippet_submit_candidates` 一键批量扫描,自动提交候选到 Dashboard Candidates
58
61
  2. **前端审核与入库**:Dashboard Candidates 页面人工审核 → 保存 Recipe 入库(优先前端操作,无需命令行)
59
62
  3. **依赖关系**(可选):Dashboard 刷新自动分析,或使用 `asd spm-map` 命令行更新
60
63
  4. **语义索引**(自动):`asd ui` 启动时自动 embed;也可手动 `asd embed`
@@ -96,23 +99,14 @@ Cursor 在编辑器内通过自然语言交互触发 Skill,使用 MCP 工具
96
99
  | `asd ais [Target]` | AI 扫描 Target → Candidates |
97
100
  | `asd search [keyword] --copy` | 搜索并复制第一条到剪贴板 |
98
101
  | `asd search [keyword] --pick` | 交互选择后复制/插入 |
102
+ | `asd sync` | 增量同步 `recipes/*.md` → DB(.md = Source of Truth) |
103
+ | `asd compliance` | 生成宪法合规评估报告(P1-P4 加权评分) |
104
+ | `asd upgrade` | 升级 IDE 集成文件(MCP/Skills/Cursor Rules/Copilot) |
99
105
  | `asd install:cursor-skill --mcp` | 安装 Skills、Cursor 规则(`.cursor/rules/*.mdc`)并配置 MCP。配置时可运行;MCP 工具使用时需 `asd ui` 已启动 |
100
- | `asd install:full` | 全量安装;`--parser` Swift 解析器 |
106
+ | `asd install:full` | 全量安装(Skills、MCP、Native UI) |
101
107
  | `asd embed` | 手动构建语义向量索引(`asd ui` 启动时也会自动执行) |
102
108
  | `asd spm-map` | 刷新 SPM 依赖映射(依赖关系图数据来源) |
103
109
 
104
- ## 可选依赖
105
-
106
- ### Swift 解析器(可选)
107
-
108
- AutoSnippet 默认使用 `swift package dump-package` 解析 SPM 依赖。如需更准确的解析,可安装 Swift 解析器:
109
-
110
- ```bash
111
- asd install:full --parser # 全量安装(含 Swift 解析器)
112
- ```
113
-
114
- 构建后会在 `tools/parse-package/.build/release/` 生成解析器,SPM 解析将更准确可靠。未安装时自动回退到 `dump-package`,功能正常。
115
-
116
110
  ## 配置
117
111
 
118
112
  - **AI**:项目根 `.env`,参考 `.env.example` 配置 `ASD_GOOGLE_API_KEY` 等。可选 `ASD_AI_PROVIDER`、代理等。
@@ -131,9 +125,11 @@ asd install:full --parser # 全量安装(含 Swift 解析器)
131
125
  | **watch** | 文件监听进程(`asd ui` 或 `asd watch` 启动),保存时触发 `as:create`、`as:audit`、`as:search` |
132
126
  | **Guard** | 按 Recipe 知识库对代码做 AI 审查;`// as:audit` 触发 |
133
127
  | **embed** | 语义向量索引构建;`asd embed` 或 `asd ui` 启动时自动执行,供语义检索与 MCP 使用 |
134
- | **MCP** | Model Context Protocol;Cursor 通过 MCP 调用 `autosnippet_context_search` 等工具 |
128
+ | **MCP** | Model Context Protocol;Cursor 通过 MCP 调用 31 个工具(7 个写操作经 Gateway 权限保护) |
135
129
  | **Skills** | Cursor Agent Skills(`.cursor/skills/`),描述何时用、如何用 AutoSnippet 能力 |
136
130
  | **trigger** | Snippet 触发前缀,默认 `@`,输入后 Xcode 联想补全 |
131
+ | **Gateway** | V2 控制平面,统一调度 27 个 Action:validate → permission → constitution → plugin → dispatch → audit |
132
+ | **Constitution** | 宪法体系:6 角色、P1-P4 四优先级、能力探测,见 `config/constitution.yaml` |
137
133
  | **项目根** | 含 `AutoSnippetRoot.boxspec.json` 的目录 |
138
134
  | **Target** | SPM 模块/编译单元;`asd ais <Target>` 扫描该 Target 下的源码提取候选 |
139
135
 
package/bin/api-server.js CHANGED
@@ -1,84 +1,98 @@
1
+ #!/usr/bin/env node
2
+
1
3
  /**
2
- * API Server 启动脚本
3
- *
4
- * 用法:
5
- * node bin/api-server.js [options]
6
- *
7
- * 选项:
8
- * --port <port> API 服务器端口 (默认: 8080)
9
- * --host <host> API 服务器主机 (默认: localhost)
10
- * --config <path> 配置文件路径
4
+ * HTTP API 服务器启动脚本
5
+ * 用于开发和测试 REST API
11
6
  */
12
7
 
13
- const { APIGateway } = require('../lib/api/APIGateway');
14
- const { Agent } = require('../lib/agent/Agent');
15
- const { RecipeHub } = require('../lib/business/recipe/RecipeHub');
16
- const { SearchHub } = require('../lib/business/search/SearchHub');
17
- const { MetricsHub } = require('../lib/business/metrics/MetricsHub');
8
+ import HttpServer from '../lib/http/HttpServer.js';
9
+ import Bootstrap from '../lib/bootstrap.js';
10
+ import Logger from '../lib/infrastructure/logging/Logger.js';
11
+ import { getServiceContainer } from '../lib/injection/ServiceContainer.js';
18
12
 
19
- /**
20
- * 解析命令行参数
21
- */
22
- function parseArgs() {
23
- const args = process.argv.slice(2);
24
- const options = {
25
- port: 8080,
26
- host: 'localhost',
27
- };
28
-
29
- for (let i = 0; i < args.length; i++) {
30
- if (args[i] === '--port') {
31
- options.port = parseInt(args[++i], 10);
32
- } else if (args[i] === '--host') {
33
- options.host = args[++i];
34
- }
35
- }
13
+ async function main() {
14
+ const logger = Logger.getInstance();
15
+ const port = process.env.PORT || 3000;
16
+ const host = process.env.HOST || 'localhost';
36
17
 
37
- return options;
38
- }
18
+ try {
19
+ logger.info('Initializing AutoSnippet HTTP API Server...', {
20
+ port,
21
+ host,
22
+ timestamp: new Date().toISOString(),
23
+ });
39
24
 
40
- /**
41
- * 启动 API 服务器
42
- */
43
- async function startServer() {
44
- const options = parseArgs();
25
+ // 初始化应用程序引导
26
+ const bootstrap = new Bootstrap({ env: process.env.NODE_ENV || 'development' });
27
+ const components = await bootstrap.initialize();
28
+ logger.info('Bootstrap initialized successfully');
45
29
 
46
- // 创建 Agent
47
- const agent = new Agent({ name: 'APIAgent' });
30
+ // 初始化 DI 容器,注入 Bootstrap 组件
31
+ const container = getServiceContainer();
32
+ await container.initialize({
33
+ db: components.db,
34
+ auditLogger: components.auditLogger,
35
+ gateway: components.gateway,
36
+ reasoningLogger: components.reasoningLogger,
37
+ roleDriftMonitor: components.roleDriftMonitor,
38
+ complianceEvaluator: components.complianceEvaluator,
39
+ sessionManager: components.sessionManager,
40
+ });
41
+ logger.info('Service container initialized successfully');
48
42
 
49
- // 注册 Hub
50
- agent.registerHub('recipe', new RecipeHub());
51
- agent.registerHub('search', new SearchHub());
52
- agent.registerHub('metric', new MetricsHub());
43
+ // 创建和启动 HTTP 服务器
44
+ const httpServer = new HttpServer({ port, host });
45
+ await httpServer.initialize(); // 改为 async 调用
46
+ await httpServer.start();
53
47
 
54
- // 创建 API Gateway
55
- const gateway = new APIGateway(agent, {
56
- port: options.port,
57
- host: options.host,
58
- });
48
+ logger.info('HTTP API Server is running', {
49
+ url: `http://${host}:${port}`,
50
+ documentation: `http://${host}:${port}/api-spec`,
51
+ health: `http://${host}:${port}/api/v1/health`,
52
+ });
59
53
 
60
- // 启动服务器
61
- try {
62
- await gateway.start();
63
- console.log(`✨ API 服务器运行中...`);
64
- console.log(`📝 API 文档: http://${options.host}:${options.port}/api/docs`);
65
- console.log(`🏥 健康检查: http://${options.host}:${options.port}/api/health`);
66
- console.log(`\n按 Ctrl+C 停止服务器`);
54
+ // 优雅关闭
55
+ const handleShutdown = async (signal) => {
56
+ logger.info(`Received ${signal}, shutting down gracefully...`, {
57
+ timestamp: new Date().toISOString(),
58
+ });
59
+
60
+ await httpServer.stop();
61
+ await bootstrap.shutdown();
62
+
63
+ logger.info('HTTP API Server shut down successfully', {
64
+ timestamp: new Date().toISOString(),
65
+ });
66
+
67
+ process.exit(0);
68
+ };
69
+
70
+ process.on('SIGTERM', () => handleShutdown('SIGTERM'));
71
+ process.on('SIGINT', () => handleShutdown('SIGINT'));
72
+
73
+ // 处理未捕获的异常
74
+ process.on('uncaughtException', (error) => {
75
+ logger.error('Uncaught Exception', {
76
+ message: error.message,
77
+ stack: error.stack,
78
+ });
79
+ process.exit(1);
80
+ });
81
+
82
+ process.on('unhandledRejection', (reason, promise) => {
83
+ logger.error('Unhandled Rejection', {
84
+ reason,
85
+ promise,
86
+ });
87
+ process.exit(1);
88
+ });
67
89
  } catch (error) {
68
- console.error(' 启动服务器失败:', error);
69
- process.exit(1);
90
+ logger.error('Failed to start HTTP API Server', {
91
+ message: error.message,
92
+ stack: error.stack,
93
+ });
94
+ process.exit(1);
70
95
  }
71
-
72
- // 处理信号
73
- process.on('SIGINT', async () => {
74
- console.log('\n🛑 停止服务器...');
75
- await gateway.stop();
76
- console.log('✅ 服务器已停止');
77
- process.exit(0);
78
- });
79
96
  }
80
97
 
81
- startServer().catch(error => {
82
- console.error('Fatal error:', error);
83
- process.exit(1);
84
- });
98
+ main();