autosnippet 3.0.1 → 3.0.3

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 +231 -324
  2. package/bin/api-server.js +1 -1
  3. package/bin/cli.js +204 -244
  4. package/bin/mcp-server.js +17 -4
  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 +441 -282
  14. package/lib/cli/UpgradeService.js +68 -107
  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 +655 -260
  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 +106 -170
  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 +62 -72
  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
package/README.md CHANGED
@@ -2,420 +2,327 @@
2
2
 
3
3
  # AutoSnippet
4
4
 
5
- **Project Knowledge Engine for iOS / Swift Teams**
5
+ **Knowledge Engine for Code Turn your team's patterns into AI-searchable recipes.**
6
6
 
7
- 将团队的代码模式、最佳实践沉淀为 AI 可检索的知识库,<br>
8
- CursorTrae、Copilot、Qoder Xcode 都按你的项目规范生成代码。
7
+ Capture code patterns, best practices, and architecture decisions as a structured knowledge base.
8
+ Then let Cursor, Copilot, Trae, Qoder, Xcode, and VS Code generate code that follows *your* standards.
9
9
 
10
10
  [![npm version](https://img.shields.io/npm/v/autosnippet.svg?style=flat-square)](https://www.npmjs.com/package/autosnippet)
11
11
  [![License](https://img.shields.io/npm/l/autosnippet.svg?style=flat-square)](https://github.com/GxFn/AutoSnippet/blob/main/LICENSE)
12
12
  [![Node](https://img.shields.io/badge/node-%E2%89%A520-brightgreen?style=flat-square)](https://nodejs.org)
13
13
 
14
+ [中文文档](README_CN.md)
15
+
14
16
  </div>
15
17
 
16
18
  ---
17
19
 
18
- ## 为什么需要 AutoSnippet?
20
+ ## The Problem
21
+
22
+ AI coding assistants generate code in a vacuum — they don't know your team's conventions, architecture patterns, or coding standards. Every AI-generated PR becomes a review burden.
19
23
 
20
- AI 编码助手生成的代码往往脱离项目上下文——不知道团队约定、不了解架构模式、也不遵守代码规范。AutoSnippet 在你的项目中建立一个**活的知识库**,让所有 AI 工具都能检索并遵循团队沉淀的最佳实践。
24
+ **AutoSnippet** bridges this gap by building a living knowledge base inside your project, making your team's expertise queryable by any AI tool.
21
25
 
22
26
  ```
23
- 你的项目代码 ──→ AI 扫描提取 ──→ 人工审核 ──→ 知识库 (Recipe)
24
-
25
- ┌───────────────────────────────────────┘
26
-
27
- Cursor / Trae / Copilot / Qoder / Xcode ──→ 按规范生成代码
27
+ Your Codebase ──→ AI Scan & Extract ──→ Human Review ──→ Knowledge Base (Recipes)
28
+
29
+ ┌─────────────────────────────────────────────────────┘
30
+
31
+ Cursor / Copilot / Trae / Qoder / Xcode / VS Code
32
+
33
+ Code generated following YOUR standards
28
34
  ```
29
35
 
30
- ## 核心概念
36
+ ## Key Concepts
31
37
 
32
- | 概念 | 说明 |
33
- |------|------|
34
- | **Recipe** | 知识库的基本单元——一段代码模式 + 使用说明 + 元数据,以 Markdown 文件(`AutoSnippet/recipes/*.md`)为 Source of Truth,SQLite 作为检索缓存 |
35
- | **Candidate** | 待审核的候选知识——来自 AI 扫描、手动提交、剪贴板或 Bootstrap 冷启动,经 Dashboard 人工审核后晋升为 Recipe |
36
- | **Dashboard** | Web 管理后台(`asd ui`),10+ 功能视图:Recipes / Candidates / Knowledge / AI Chat / SPM Explorer / 知识图谱 / 依赖图 / Guard / Skills / Xcode 模拟器 / Help |
37
- | **Guard** | 代码审查引擎——基于知识库中的规则对代码做合规检查,支持文件 / Target / 项目三级范围 |
38
- | **Skills** | 13 Agent 技能包——覆盖候选生成、冷启动、Guard 审计、意图路由、生命周期管理等场景,支持 Cursor Qoder |
39
- | **Bootstrap** | 冷启动引擎——自动扫描 SPM Target + AST 分析,9 维度启发式提取代码模式,AI 精炼后生成 Candidate;支持增量模式(IncrementalBootstrap),文件变更检测 + 受影响维度重跑 |
40
- | **Agent Memory** | 四层记忆架构——WorkingMemory(会话级)→ EpisodicMemory(跨维度共享)→ ProjectSemanticMemory(项目级永久语义记忆)→ ToolResultCache(工具结果去重),支撑 Bootstrap 和 ChatAgent 的跨对话知识积累 |
41
- | **ChatAgent** | 多 Agent 协作对话系统(Analyst + Producer),支持项目感知、信心信号、组合工具链和跨对话记忆 |
42
- | **CodeEntityGraph** | 代码实体关系图谱——基于 AST 解析构建 class / protocol / category / module 间的继承、遵循、依赖、数据流等关系,供 Bootstrap 和搜索使用 |
38
+ | Concept | Description |
39
+ |---------|-------------|
40
+ | **Recipe** | The atomic unit of knowledge — a code pattern + explanation + metadata. Stored as Markdown in `AutoSnippet/recipes/`, cached in SQLite for fast retrieval |
41
+ | **Candidate** | A pending knowledge entry awaiting human review — from AI scans, manual submission, or bootstrap. Promoted to Recipe after approval |
42
+ | **Guard** | Code compliance engine checks source files against knowledge-derived rules at file, target, or project scope |
43
+ | **Skill** | Agent instruction sets (18 built-in) — guide AI agents to correctly invoke knowledge base operations |
44
+ | **Bootstrap** | Cold-start engine 9-dimension heuristic scan + dual-agent AI analysis, generating dozens of candidates in one pass |
43
45
 
44
- ## 快速开始
46
+ ## Quick Start
45
47
 
46
48
  ```bash
47
- # 1. 全局安装
49
+ # Install globally
48
50
  npm install -g autosnippet
49
51
 
50
- # 2. 在你的项目目录初始化
52
+ # Initialize in your project
51
53
  cd /path/to/your-project
52
- asd setup # 创建 AutoSnippet/ 目录,配置 VSCode / Cursor / Qoder
53
-
54
- # 3. 安装 IDE 集成(Skills + MCP + Cursor Rules)
55
- asd install:full
54
+ asd setup # Creates workspace, DB, IDE integrations, installs VS Code extension
56
55
 
57
- # 4. 启动 Dashboard
58
- asd ui # 启动 Web 后台 + 文件监听 + 语义索引
56
+ # Cold-start: scan your codebase and extract patterns
57
+ asd coldstart # 9-dimension AI analysis Candidates
59
58
 
60
- # 5. 检查环境状态
61
- asd status # 自检项目根、AI Provider、索引、Dashboard
59
+ # Launch Dashboard to review and manage knowledge
60
+ asd ui # Web dashboard + API server
62
61
  ```
63
62
 
64
- > **注意**:始终在**你的项目目录**中执行 `asd` 命令,而非 AutoSnippet 源码仓库。
63
+ > **Important**: Always run `asd` commands inside your project directory, not in the AutoSnippet source repo.
65
64
 
66
- ## 工作流
65
+ ## How It Works
67
66
 
68
- ### 端到端使用流程
69
-
70
- 从零开始到知识库持续运转的完整路径——以 Cursor 为例:
71
-
72
- ```
73
- ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
74
- │ ① 初始化 │──→│ ② 冷启动 │──→│ ③ 逐Target │──→│ ④ 审核发布 │──→│ ⑤ 注入 IDE │
75
- │ asd setup │ │ Bootstrap │ │ 扫描 │ │ Dashboard │ │ Cursor │
76
- └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ └──────┬──────┘
77
-
78
- ┌───────────────────────────────────────────────────────────────────────┘
79
-
80
- ┌─────────────┐ ┌─────────────┐
81
- │ ⑥ AI 按 │──→│ ⑦ 新模式 │──→ 回到 ③
82
- │ 规范生成 │ │ 再沉淀 │
83
- └─────────────┘ └─────────────┘
84
67
  ```
85
-
86
- **① 初始化项目**
87
-
88
- ```bash
89
- cd /path/to/your-project
90
- asd setup # 创建 AutoSnippet/ 目录、数据库、配置文件
91
- asd install:full # 安装 Cursor Skills (13个) + MCP 配置 + Cursor Rules
92
- asd ui # 启动 Dashboard + API 服务 + 文件监听
68
+ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐
69
+ │ ① Setup │──→ │ ② Cold │──→ │ ③ Target │──→ │ ④ Review │──→ │ ⑤ IDE │
70
+ │ asd setup │ │ Start │ │ Scan │ │ Dashboard │ │ Delivery │
71
+ └────────────┘ └────────────┘ └────────────┘ └────────────┘ └─────┬──────┘
72
+
73
+ ┌───────────────────────────────────────────────────────────────────────┘
74
+
75
+ ┌────────────┐ ┌────────────┐
76
+ │ ⑥ AI Codes │──→ │ ⑦ New │──→ Back to ③
77
+ │ by Rules │ │ Patterns │
78
+ └────────────┘ └────────────┘
93
79
  ```
94
80
 
95
- 完成后,你的项目目录下会生成 `.cursor/mcp.json`、`.cursor/skills/`、`.cursor/rules/` 等集成文件,Cursor 已经可以通过 MCP AutoSnippet 通信。
96
-
97
- **② 冷启动——全局扫描建立基线**
98
-
99
- Cursor 中用自然语言触发冷启动:
81
+ 1. **Setup** — `asd setup` creates the workspace structure, SQLite database, MCP configs for Cursor/VS Code/Qoder/Trae, and installs the VS Code extension
82
+ 2. **Cold Start** — Bootstrap engine scans your codebase across 9 dimensions (architecture, naming, networking, data flow, error handling, etc.) using a dual-agent system (Analyst → Producer)
83
+ 3. **Target Scan** — `asd ais <target>` performs focused extraction on specific modules
84
+ 4. **Review** — Dashboard provides card-based review UI with AI confidence scoring, batch approve/reject, and inline editing
85
+ 5. **IDE Delivery** — Recipes are delivered via MCP tools (real-time), Cursor Rules (`.cursor/rules/`), and Agent Skills
86
+ 6. **AI Generation** — IDE AI assistants query the knowledge base and generate code following your team's patterns
87
+ 7. **Continuous Capture** — File watchers detect new patterns, creating a feedback loop
100
88
 
101
- ```
102
- 你:「对项目做一次全量冷启动,提取所有代码模式」
103
- ```
104
-
105
- Bootstrap 引擎自动完成:SPM Target 发现 → 文件收集 → AST 结构分析 → 9 维度启发式扫描(架构 / 命名 / 网络 / 数据流 / 错误处理等) → Analyst Agent 深度分析 → Producer Agent 格式化提交。
89
+ ## Features
106
90
 
107
- 冷启动结束后,Dashboard Candidates 页面会出现数十条候选知识条目。
91
+ ### 🔍 Multi-Strategy Search Engine
108
92
 
109
- **③ Target 精细扫描**
93
+ 4-layer retrieval funnel with 5 search modes:
110
94
 
111
- 冷启动覆盖全局,但每个 Target 的独特模式需要针对性提取:
95
+ | Layer | Strategy | Purpose |
96
+ |-------|----------|---------|
97
+ | L1 | Inverted Index + BM25 | Fast keyword recall with CJK support |
98
+ | L2 | Cross-Encoder Reranker | AI-powered semantic reranking |
99
+ | L2.5 | Coarse Ranker (E-E-A-T) | 5-dimension quality scoring |
100
+ | L3 | Multi-Signal Ranker | 6-signal weighted ranking (relevance, authority, recency, popularity, difficulty, seasonality) |
112
101
 
113
- ```
114
- 你:「扫描 NetworkModule 这个 Target,把里面的请求封装模式提取出来」
115
- 你:「分析 UIComponents Target 的自定义控件实现」
116
- ```
102
+ ### 🤖 AI Integration (6 Providers)
117
103
 
118
- Cursor 调用 `structure({ operation: "targets" })` → `structure({ operation: "files" })` → 逐文件 AI 分析 → `submit_knowledge_batch`,将发现的代码模式作为 Candidate 提交到知识库。你可以逐个 Target 推进,每个 Target 的扫描结果会独立进入审核队列。
104
+ | Provider | Notes |
105
+ |----------|-------|
106
+ | Google Gemini | Native tool calling + structured output |
107
+ | OpenAI | GPT-4o, GPT-4, etc. |
108
+ | Claude (Anthropic) | Native tool calling |
109
+ | DeepSeek | OpenAI-compatible |
110
+ | Ollama | Local models, no API key needed |
111
+ | Mock | Auto-fallback when no AI configured |
119
112
 
120
- **④ 审核发布——人工把关质量**
113
+ Auto-detection, priority-based fallback, and context window adaptation.
121
114
 
122
- 打开 Dashboard(`asd ui`),进入 **Candidates** 页面:
115
+ ### 🛡️ Guard Code Compliance
123
116
 
124
- - 候选按置信度排序,高信心的排在前面
125
- - 点击候选卡片展开详情:查看代码片段、AI 分析理由、来源文件
126
- - **接受** 候选晋升为 Recipe,进入活跃知识库
127
- - **编辑后接受** 审核时可修改标题、描述、代码、标签
128
- - **拒绝**低质量或重复的候选直接归档
117
+ - **Regex + AST semantic rules** (mustCallThrough, mustNotUseInContext, mustConformToProtocol)
118
+ - **3 scopes**: file / target / project
119
+ - **CI/CD ready**: `asd guard:ci` with Quality Gate, `asd guard:staged` for pre-commit hooks
120
+ - **Rule learning**: Auto-suggest rules from violation patterns (14-day effectiveness tracking)
121
+ - **Feedback loop**: Guard violations Recipe usage confirmation
129
122
 
130
- 批量操作:一键接受所有高信心候选,或一键拒绝低质量条目。
123
+ ### 📊 Dashboard (18 Views)
131
124
 
132
- **⑤ 注入 Cursor——知识即规则**
125
+ Full-featured web UI launched with `asd ui`:
133
126
 
134
- Recipe 发布后,Cursor 立即可以通过三种通道获取知识:
127
+ - **Knowledge Management** — Recipe browser, candidate review, batch operations
128
+ - **AI Chat** — ReAct-loop conversation with 54 internal tools
129
+ - **Knowledge Graph** — Visual relationship explorer
130
+ - **Guard Dashboard** — Rule management, violation tracking, compliance reports
131
+ - **SPM / Module Explorer** — Dependency analysis across language ecosystems
132
+ - **Wiki Generator** — Auto-generated project documentation with Mermaid diagrams
133
+ - **Bootstrap Progress** — Real-time 9-dimension progress with time estimates
134
+ - **Skills Manager** — Browse, create, and manage agent skills
135
+ - **LLM Config** — Visual AI provider/model/key configuration
135
136
 
136
- | 通道 | 机制 | 时效 |
137
- |------|------|------|
138
- | **MCP 工具检索** | Cursor 通过 `autosnippet_search` 等 16 个工具实时查询知识库 | 实时 |
139
- | **Cursor Rules** | `asd upgrade` 将 Recipe 导出为 `.cursor/rules/autosnippet-*.mdc` 文件 | 手动触发 |
140
- | **Agent Skills** | 13 个 Skill 文档引导 Cursor 在正确场景自动调用知识库 | 常驻 |
137
+ ### 🔌 IDE Integrations
141
138
 
142
- **⑥ AI 按规范生成代码**
139
+ #### MCP Server (16 Tools)
143
140
 
144
- 当你在 Cursor 中编写代码时,AI 会自动检索知识库:
141
+ Works with any MCP-compatible IDE (Cursor, VS Code Copilot, Qoder, Trae):
145
142
 
143
+ ```bash
144
+ # Automatically configured by asd setup
145
+ # Or manually: asd setup:mcp
146
146
  ```
147
- 你:「写一个网络请求方法,获取用户信息」
148
- Cursor → 检索知识库 → 命中 Recipe: "Network Layer Pattern"
149
- → 按团队封装的 NetworkManager 生成代码,而非裸调 URLSession
150
- ```
151
-
152
- Guard 规则也在同步工作——如果生成的代码违反了知识库中的规则(如 `kind=rule` 的条目),会实时提醒和纠正。
153
-
154
- **⑦ 持续沉淀——知识库越用越好**
155
-
156
- 日常开发中发现新的代码模式或团队约定?随时沉淀:
157
-
158
- - 在 Cursor 中:`「把这段 error handling 模式提取为知识库条目」`
159
- - 在 Xcode 中:代码注释写 `// as:create` 然后 `⌘S`
160
- - 在 Dashboard 中:AI Chat 对话式提交
161
- - 通过剪贴板:复制代码后自动检测并建议入库
162
-
163
- 知识库形成飞轮:**代码沉淀 → Recipe 增长 → AI 生成质量提升 → 团队效率提高 → 更多代码模式沉淀**。
164
147
 
165
- ## Dashboard
148
+ 12 Agent-tier tools (search, knowledge, structure, graph, guard, submit, skills, bootstrap, etc.) + 4 Admin tools.
166
149
 
167
- `asd ui` 启动后访问 Web 管理后台:
150
+ #### VS Code Extension
168
151
 
169
- ![Dashboard](./resources/ASImage02.png)
152
+ Installed automatically by `asd setup`. Features:
170
153
 
171
- **功能视图**:
154
+ - **Search & Insert** — `Cmd+Shift+F5` opens QuickPick with code preview, inserts at cursor
155
+ - **Directive Detection** — Auto-detects `// as:s`, `// as:c`, `// as:a` directives on save
156
+ - **CodeLens** — Inline action buttons above directives
157
+ - **Guard Audit** — Run compliance checks on files or entire project
158
+ - **Create Candidate** — Submit selected code as a knowledge candidate
159
+ - **Status Bar** — Real-time API server connection indicator
172
160
 
173
- | 视图 | 说明 |
174
- |------|------|
175
- | **Recipes** | 浏览、编辑、发布、弃用知识条目;详情抽屉支持 Markdown 编辑与关联关系管理 |
176
- | **Candidates** | 审核 AI / 手动提交的候选,一键入库或批量操作,支持 AI 润色 |
177
- | **Knowledge** | 统一知识条目浏览(V3 格式),双列卡片布局,代码预览 + 详情抽屉 |
178
- | **AI Chat** | ChatAgent 智能对话(Analyst 分析 + Producer 生产),项目感知 + 四层记忆架构 |
179
- | **SPM Explorer** | SPM Target 浏览与扫描,候选 vs Recipe 对比抽屉,头文件编辑 |
180
- | **Dep Graph** | 依赖关系图可视化 |
181
- | **Knowledge Graph** | Recipe 关联关系的知识图谱可视化(依赖 / 扩展 / 冲突等),AI 自动发现关系,按 category 分组 |
182
- | **Guard** | 代码合规审查,查看违规记录与修复建议 |
183
- | **Skills** | 浏览与管理 Agent Skill 文档 |
184
- | **Xcode Simulator** | 在浏览器中模拟 `as:search` / `as:create` / `as:audit` 指令 |
185
- | **Help** | 使用帮助与快捷键参考 |
161
+ #### Xcode Integration
186
162
 
187
- **辅助功能**:全局搜索面板、LLM 配置弹窗、Bootstrap 进度视图、实时 WebSocket 更新。
163
+ - **File Watcher** `asd watch` monitors files for `// as:` directives
164
+ - **Auto-Insertion** — osascript-driven code insertion preserving Undo history
165
+ - **Header Management** — Automatic `#import`/`@import` deduplication with SPM-aware decisions
166
+ - **Snippet Sync** — Export recipes as native Xcode `.codesnippet` files
188
167
 
189
- ## IDE 集成
168
+ ### 📝 File Directives
190
169
 
191
- ### Cursor(推荐)
170
+ Write directives as comments in any source file:
192
171
 
193
- AutoSnippet 为 Cursor 提供完整的 MCP + Skills 集成:
194
-
195
- - **16 MCP 工具**(12 agent + 4 admin):search / knowledge / structure / graph / guard / bootstrap / skill 等参数化统合入口,覆盖搜索、审查、候选管理、冷启动等场景
196
- - **13 Agent Skills**:`autosnippet-candidates`、`autosnippet-guard`、`autosnippet-coldstart`、`autosnippet-intent` 等,引导 AI 正确使用工具
197
- - **写操作 Gateway 保护**:写操作经过权限 / 宪法 / 审计三重检查
198
-
199
- ```bash
200
- asd install:cursor-skill --mcp # 安装 Skills + MCP 配置
172
+ ```objc
173
+ // as:s network request timeout → Search & insert matching recipe
174
+ // as:c → Create candidate from surrounding code
175
+ // as:c -c → Create candidate from clipboard
176
+ // as:a → Run Guard audit on this file
177
+ // as:include "MyHeader.h" → ObjC header import
178
+ // as:import UIKit → Module import
201
179
  ```
202
180
 
203
- ### Qoder
204
-
205
- AutoSnippet 对 Qoder 的支持通过镜像 Cursor 交付物料到 `.qoder/`:
206
-
207
- - **Skills**(`.qoder/skills/`):与 `.cursor/skills/` 相同的 Agent Skills
208
- - **Rules**(`.qoder/rules/*.md`):从 `.cursor/rules/*.mdc` 自动转换为标准 Markdown
209
- - **MCP**:不支持项目级 `.qoder/mcp.json`,需通过 Qoder IDE 界面 Your Settings → MCP → "+ Add" 配置。
210
-
211
- ### Trae
181
+ ### 🧬 AST Analysis (9 Languages)
212
182
 
213
- AutoSnippet Trae 的支持通过镜像 Cursor 交付物料到 `.trae/`:
183
+ Tree-sitter powered code intelligence:
214
184
 
215
- - **Skills**(`.trae/skills/`):与 `.cursor/skills/` 相同的 Agent Skills
216
- - **Rules**(`.trae/rules/*.md`):从 `.cursor/rules/*.mdc` 自动转换为标准 Markdown
217
- - **MCP**:不支持项目级 `.trae/mcp.json`,需通过 Trae IDE 界面 设置 MCP "+ 添加" 手动配置。
185
+ | Language | Capabilities |
186
+ |----------|-------------|
187
+ | Objective-C, Swift | Full: classes, protocols, categories, extensions, design patterns |
188
+ | TypeScript, JavaScript, TSX | Classes, functions, React components, imports |
189
+ | Python | Classes, functions, decorators, imports |
190
+ | Java, Kotlin | Classes, interfaces, annotations |
191
+ | Go | Structs, interfaces, functions |
218
192
 
219
- ### VSCode Copilot
193
+ Plus 11 framework enhancement packs (React, Vue, Spring, Django, FastAPI, gRPC, Android, etc.).
220
194
 
221
- ```bash
222
- asd install:vscode-copilot # 配置 MCP 和 Copilot 指令
223
- ```
224
-
225
- ### Xcode
195
+ ### 🏛️ Constitution & Governance
226
196
 
227
- 通过 Xcode Code Snippet 触发:
197
+ Three-layer permission model:
228
198
 
229
- | 触发关键词 | 作用 |
230
- |-----------|------|
231
- | `ass` | 搜索知识库并插入代码(最快捷的联想方式) |
232
- | `asc` | 创建候选——打开 Dashboard 或从剪贴板静默提交 |
233
- | `asa` | 按知识库审查当前代码 |
199
+ 1. **Capability Layer** `git push --dry-run` probes write access (physical signal)
200
+ 2. **Role Layer** — 3 roles (developer / external_agent / chat_agent) with permission matrix
201
+ 3. **Governance Layer** 4 inviolable rules enforced by Constitution engine
234
202
 
235
- > 执行 `asd setup` 注册 Snippet 后,需**重启 Xcode** 才生效。
203
+ Every write operation passes through the Gateway: role check → constitution rules → audit log.
236
204
 
237
- ## CLI 命令参考
205
+ ### 🧠 Agent Memory (4 Tiers)
238
206
 
239
- | 命令 | 说明 | 常用选项 |
240
- |------|------|----------|
241
- | `asd setup` | 初始化项目(创建 AutoSnippet/ 目录和配置) | `--force`、`--seed` |
242
- | `asd ui` | 启动 Dashboard + API 服务 | `-p <port>`、`-b`(浏览器)、`--api-only` |
243
- | `asd status` | 环境自检(项目根、AI、索引、Dashboard 状态) | |
244
- | `asd ais [target]` | AI 扫描 Target 生成 Candidates | `-m <max-files>`、`--dry-run`、`--json` |
245
- | `asd search <query>` | 搜索知识库 | `-t <type>`、`-m <mode>`(keyword/bm25/semantic)、`-l <limit>` |
246
- | `asd guard <file>` | 对文件运行 Guard 规则检查 | `-s <scope>`(file/target/project)、`--json` |
247
- | `asd watch` | 启动文件监控(`as:c` / `as:s` / `as:a` 指令) | `-e <exts>`、`--guard` |
248
- | `asd server` | 单独启动 API 服务器 | `-p <port>`、`-H <host>` |
249
- | `asd sync` | 增量同步 `recipes/*.md` → DB(Markdown = Source of Truth) | `--dry-run`、`--force` |
250
- | `asd upgrade` | 升级 IDE 集成(MCP / Skills / Cursor Rules) | `--skills-only`、`--mcp-only` |
251
- | `asd install:full` | 全量安装(Skills + MCP + Native UI + Cursor Rules) | — |
207
+ | Tier | Scope | Persistent | Purpose |
208
+ |------|-------|-----------|---------|
209
+ | Working Memory | Session | No | Scratchpad + context compression |
210
+ | Episodic Memory | Cross-dimension | No | Discovery sharing between bootstrap dimensions |
211
+ | Project Semantic Memory | Project | SQLite | Permanent facts, insights, preferences (importance scoring + TTL) |
212
+ | Tool Result Cache | Cross-dimension | No | Deduplication of tool calls |
252
213
 
253
- ## MCP 工具一览
214
+ ## CLI Reference
254
215
 
255
- 16 MCP 工具按功能分组(省略了 **autosnippet_** 前缀):
216
+ | Command | Description |
217
+ |---------|-------------|
218
+ | `asd setup` | Initialize workspace, DB, IDE configs, install VS Code extension |
219
+ | `asd coldstart` | Bootstrap knowledge base (9-dimension AI scan) |
220
+ | `asd ais [target]` | AI scan source files → extract and publish recipes |
221
+ | `asd ui` | Launch Dashboard + API server |
222
+ | `asd watch` | Start Xcode file watcher for directives |
223
+ | `asd search <query>` | Search knowledge base |
224
+ | `asd guard <file>` | Run Guard compliance check |
225
+ | `asd guard:ci` | CI/CD full-project Guard + Quality Gate |
226
+ | `asd guard:staged` | Check git staged files (pre-commit hook) |
227
+ | `asd sync` | Sync `recipes/*.md` → SQLite database |
228
+ | `asd upgrade` | Update IDE integrations (MCP, Skills, Rules) |
229
+ | `asd cursor-rules` | Generate Cursor 4-channel delivery artifacts |
230
+ | `asd server` | Start API server standalone |
231
+ | `asd status` | Check environment health |
256
232
 
257
- **Agent 层(12 个)**——默认对外暴露:
233
+ ## Architecture
258
234
 
259
- | 分类 | 工具 | 说明 |
260
- |------|------|------|
261
- | **系统** | `health` | 服务健康检查 |
262
- | **系统** | `capabilities` | 服务能力清单(Agent 自发现) |
263
- | **搜索** | `search` | 统合入口,`mode` 参数路由 auto / keyword / semantic / context 四种模式 |
264
- | **知识浏览** | `knowledge` | `operation` 参数路由 list / get / insights / confirm_usage |
265
- | **项目结构** | `structure` | `operation` 参数路由 targets / files / metadata |
266
- | **知识图谱** | `graph` | `operation` 参数路由 query / impact / path / stats |
267
- | **Guard** | `guard` | `code` 参数审查单文件代码,`files` 参数批量审查文件 |
268
- | **知识提交** | `submit_knowledge` / `submit_knowledge_batch` / `save_document` | 提交候选 / 批量提交 / 保存开发文档 |
269
- | **Skill 管理** | `skill` | `operation` 参数路由 list / load / create / update / delete / suggest |
270
- | **冷启动** | `bootstrap` | `operation` 参数路由 knowledge / refine / scan |
271
-
272
- **Admin 层(4 个)**——需设置 `ASD_MCP_TIER=admin`:
273
-
274
- | 分类 | 工具 | 说明 |
275
- |------|------|------|
276
- | **候选管理** | `enrich_candidates` / `validate_candidate` / `check_duplicate` | AI 润色 / 校验 / 查重 |
277
- | **知识管理** | `knowledge_lifecycle` | 批量生命周期操作 |
235
+ ```
236
+ ┌─────────────────────────────────────────────────────────┐
237
+ │ IDE Layer │
238
+ │ Cursor VS Code Trae Qoder │ Xcode │ Dashboard │
239
+ └────────────────────────┬────────────────────────────────┘
240
+
241
+ ┌──────────┴──────────┐
242
+ │ MCP Server (16) │──── HTTP API (REST + WebSocket)
243
+ └──────────┬──────────┘
244
+
245
+ ┌────────────────────────┴────────────────────────────────┐
246
+ │ Service Layer │
247
+ │ SearchEngine │ KnowledgeService │ GuardEngine │ Chat │
248
+ │ Bootstrap │ WikiGenerator │ Skills │ SPM │
249
+ └────────────────────────┬────────────────────────────────┘
250
+
251
+ ┌────────────────────────┴────────────────────────────────┐
252
+ │ Core Layer │
253
+ │ AstAnalyzer (9 lang) KnowledgeGraph CodeEntityGraph│
254
+ │ RetrievalFunnel │ QualityScorer │ ConfidenceRouter│
255
+ └────────────────────────┬────────────────────────────────┘
256
+
257
+ ┌────────────────────────┴────────────────────────────────┐
258
+ │ Infrastructure Layer │
259
+ │ SQLite │ VectorStore │ EventBus │ AuditLog │ Gateway │
260
+ │ DI Container (40+ services) │ Constitution │ PathGuard │
261
+ └─────────────────────────────────────────────────────────┘
262
+ ```
278
263
 
279
- ## 配置
264
+ ## Configuration
280
265
 
281
- ### AI Provider
266
+ ### AI Provider Setup
282
267
 
283
- 在项目根目录创建 `.env` 文件(参考 `.env.example`):
268
+ Create `.env` in your project root (or configure via Dashboard → LLM Config):
284
269
 
285
270
  ```env
286
- ASD_AI_PROVIDER=gemini # gemini / openai / anthropic
287
- ASD_GOOGLE_API_KEY=your-key # Gemini API Key
288
- # ASD_OPENAI_API_KEY=your-key # OpenAI API Key
289
- # ASD_ANTHROPIC_API_KEY=your-key # Claude API Key
271
+ # Pick one (or more for fallback)
272
+ ASD_GOOGLE_API_KEY=your-gemini-key
273
+ ASD_OPENAI_API_KEY=your-openai-key
274
+ ASD_CLAUDE_API_KEY=your-claude-key
275
+ ASD_DEEPSEEK_API_KEY=your-deepseek-key
276
+
277
+ # Or use local Ollama (no key needed)
278
+ ASD_AI_PROVIDER=ollama
279
+ ASD_AI_MODEL=llama3
290
280
  ```
291
281
 
292
- 支持的 AI Provider:**Gemini**(推荐)、**OpenAI**、**Claude (Anthropic)**。
293
-
294
- ### 项目目录结构
282
+ ### Project Structure After Setup
295
283
 
296
284
  ```
297
285
  your-project/
298
- ├── AutoSnippet/ # 知识库目录(建议整体作为 Git 子仓库)
299
- │ ├── recipes/ # Recipe Markdown 导出(Source of Truth)
300
- │ ├── skills/ # 项目级 Agent Skills
301
- └── .autosnippet/ # 数据库、索引、Guard 配置等
302
- ├── .trae/
303
- ├── rules/ # Trae Rules(从 .cursor/rules/ 镜像)
304
- └── skills/ # Trae Skills(从 .cursor/skills/ 镜像)
305
- ├── .qoder/
306
- ├── rules/ # Qoder Rules(从 .cursor/rules/ 镜像)
307
- │ └── skills/ # Qoder Skills(从 .cursor/skills/ 镜像)
308
- ├── .cursor/
309
- │ ├── mcp.json # MCP 配置(asd setup 自动生成)
310
- ├── rules/ # Cursor Rules(asd install 生成)
311
- └── skills/ # Agent Skills(asd install 生成)
312
- ├── .vscode/
313
- └── settings.json # VSCode MCP 配置
314
- └── .env # AI Provider 配置
315
- ```
316
-
317
- ### Git 策略建议
318
-
319
- | 路径 | 建议 |
320
- |------|------|
321
- | `AutoSnippet/` | **整体作为 Git 子仓库**——独立权限控制,写权限探针(`git push --dry-run`)在此目录执行,仅知识管理员可 push |
322
- | `AutoSnippet/.autosnippet/context/index/` | 加入 `.gitignore`——体积大、机器相关 |
323
-
324
- ## 架构概览
325
-
326
- ```
327
- ┌──────────────────────────────────────────────────────────┐
328
- │ IDE Layer │
329
- │ Cursor (Skills + MCP) │ Qoder (Skills + Rules) │ Trae (Skills + Rules + MCP) │ VSCode (Copilot) │ Xcode │
330
- └────────────┬────────────────────┬─────────────────────────┘
331
- │ MCP (stdio) │ HTTP API
332
- ┌────────────┴────────────────────┴─────────────────────────┐
333
- │ AutoSnippet Core │
334
- │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌─────────────┐ │
335
- │ │ Gateway │ │ ChatAgent│ │ Bootstrap│ │ Dashboard │ │
336
- │ │ (权限/ │ │ (Dual │ │ (Incremen│ │ (React 19 +│ │
337
- │ │ 宪法/ │ │ Agent + │ │ tal + │ │ Vite 6 + │ │
338
- │ │ 审计) │ │ Memory) │ │ AST+AI) │ │ Tailwind) │ │
339
- │ └──────────┘ └──────────┘ └──────────┘ └─────────────┘ │
340
- │ ┌────────────────────────────────────────────────────┐ │
341
- │ │ Agent Memory (4-Tier): │ │
342
- │ │ WorkingMemory → EpisodicMemory → │ │
343
- │ │ ProjectSemanticMemory → ToolResultCache │ │
344
- │ └────────────────────────────────────────────────────┘ │
345
- │ ┌────────────────────────────────────────────────────┐ │
346
- │ │ 14 Services: Recipe │ Candidate │ Guard │ Search │ │
347
- │ │ Knowledge Graph │ SPM │ Bootstrap │ Chat │ Skills │ │
348
- │ │ Quality │ Context │ Automation │ Snippet │ Cursor │ │
349
- │ └────────────────────────────────────────────────────┘ │
350
- │ ┌────────────────────────────────────────────────────┐ │
351
- │ │ Core: Gateway │ Constitution │ Permission │ AST │ │
352
- │ │ Session │ Capability │ CodeEntityGraph │ │
353
- │ └────────────────────────────────────────────────────┘ │
354
- │ ┌────────────────────────────────────────────────────┐ │
355
- │ │ Storage: SQLite (better-sqlite3) + 向量索引 │ │
356
- │ │ Search: InvertedIndex → CoarseRanker → │ │
357
- │ │ MultiSignalRanker → RetrievalFunnel │ │
358
- │ └────────────────────────────────────────────────────┘ │
359
- └───────────────────────────────────────────────────────────┘
286
+ ├── AutoSnippet/ # Core data (git sub-repo = Source of Truth)
287
+ │ ├── constitution.yaml # Permission rules
288
+ │ ├── recipes/ # Knowledge entries (Markdown)
289
+ ├── candidates/ # Pending entries
290
+ │ └── skills/ # Project-specific skills
291
+ ├── .autosnippet/ # Runtime (gitignored)
292
+ ├── config.json # Project config
293
+ ├── autosnippet.db # SQLite cache
294
+ └── context/ # Vector index cache
295
+ ├── .cursor/ # Cursor IDE integration
296
+ ├── mcp.json
297
+ │ ├── rules/
298
+ └── skills/
299
+ └── .vscode/ # VS Code integration
300
+ ├── mcp.json # MCP server config
301
+ └── extensions.json # Recommended extensions
360
302
  ```
361
303
 
362
- ## 技术栈
363
-
364
- | 层级 | 技术 |
365
- |------|------|
366
- | **Runtime** | Node.js ≥ 20,ESM |
367
- | **后端** | Express + better-sqlite3 + MCP SDK + Socket.IO |
368
- | **前端** | React 19 + TypeScript 5 + Vite 6 + Tailwind CSS 4 |
369
- | **AI** | Gemini / OpenAI / Claude(通过 AiProvider 抽象层) |
370
- | **AST** | Tree-sitter(Swift / ObjC) |
371
- | **搜索** | 5 层检索管线:InvertedIndex → Semantic Rerank → CoarseRanker (E-E-A-T) → MultiSignalRanker → RetrievalFunnel |
372
- | **实时通信** | WebSocket(Socket.IO),Dashboard 实时更新 |
373
- | **动画** | Framer Motion |
374
- | **代码高亮** | Prism.js + react-syntax-highlighter |
304
+ ## Security
375
305
 
376
- ## Xcode 深度集成
306
+ - **PathGuard**: 2-layer boundary protection — blocks writes outside project root + whitelist-only allowed paths
307
+ - **Constitution**: 4 inviolable rules enforced on every write operation
308
+ - **Audit Trail**: Full audit logging with 90-day TTL auto-cleanup
309
+ - **No External Calls in postinstall**: Build scripts are purely local (macOS Swift compilation)
310
+ - **Gateway**: Every mutation goes through role verification → constitution check → audit log
377
311
 
378
- AutoSnippet 不依赖 Xcode 插件,通过 **AppleScript + FileWatcher + 原生 macOS UI** 实现深度集成。
312
+ ## Requirements
379
313
 
380
- | 能力 | 说明 |
381
- |------|------|
382
- | **保存即触发** | FileWatcher 监听源码目录;在代码中写入 `// as:search`、`// as:create`、`// as:audit` 后按 `⌘S`,自动执行对应操作 |
383
- | **AppleScript 自动化** | 通过 `osascript` 驱动 Xcode——行号跳转、行选中、剪切/粘贴替换、前台检测;搜索结果直接替换触发行 |
384
- | **原生 macOS UI** | Swift 原生弹窗展示搜索结果列表(降级为 AppleScript `choose from list`);系统通知反馈操作结果 |
385
- | **智能 import 注入** | 插入代码时自动分析所需 `import`,检查 SPM 模块可达性,确认后通过 AppleScript 注入头文件 |
386
- | **三层防误触** | Self-write 冷却 + 内容哈希去重 + Xcode 焦点检测,区分手动保存与自动保存 |
387
- | **Code Snippet** | `ass`(搜索插入)、`asc`(创建候选)、`asa`(代码审查),`asd setup` 注册后重启 Xcode 生效 |
314
+ - **Node.js** 20.0.0
315
+ - **macOS** recommended (required for Xcode integration; other platforms work without Xcode features)
316
+ - **SQLite** via better-sqlite3 (bundled)
388
317
 
389
- ## 开发
390
-
391
- ```bash
392
- # 克隆仓库
393
- git clone https://github.com/GxFn/AutoSnippet.git
394
- cd AutoSnippet
395
- npm install
396
-
397
- # 链接开发版到全局
398
- npm run dev:link
399
-
400
- # 运行测试
401
- npm test # 全部测试
402
- npm run test:unit # 单元测试
403
- npm run test:integration # 集成测试
404
- npm run test:e2e # 端到端测试
405
- npm run test:coverage # 覆盖率报告
406
-
407
- # 构建 Dashboard
408
- npm run build:dashboard
409
-
410
- # 发布
411
- npm run release:check # 发布前检查
412
- npm run release:patch # 补丁版本
413
- ```
318
+ ## Contributing
414
319
 
415
- ## 贡献
320
+ Contributions are welcome. Please ensure:
416
321
 
417
- 欢迎 [Issue](https://github.com/GxFn/AutoSnippet/issues) [PR](https://github.com/GxFn/AutoSnippet/pulls)。
322
+ 1. Run `npm test` before submitting
323
+ 2. Follow existing code patterns (ESM, domain-driven structure)
324
+ 3. Guard rules and knowledge entries go through the standard review process
418
325
 
419
326
  ## License
420
327
 
421
- [MIT](LICENSE)
328
+ [MIT](LICENSE) © gaoxuefeng