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.
- package/README.md +231 -324
- package/bin/api-server.js +1 -1
- package/bin/cli.js +204 -244
- package/bin/mcp-server.js +17 -4
- package/config/knowledge-base.config.js +132 -132
- package/dashboard/dist/assets/{icons-CEfgGaZi.js → icons-Cdq22n2i.js} +95 -100
- package/dashboard/dist/assets/index-ClkyPkDX.js +133 -0
- package/dashboard/dist/assets/index-t4QrJwv1.css +1 -0
- package/dashboard/dist/index.html +3 -3
- package/lib/bootstrap.js +8 -8
- package/lib/cli/AiScanService.js +86 -40
- package/lib/cli/KnowledgeSyncService.js +113 -74
- package/lib/cli/SetupService.js +441 -282
- package/lib/cli/UpgradeService.js +68 -107
- package/lib/core/AstAnalyzer.js +276 -597
- package/lib/core/ast/ProjectGraph.js +101 -40
- package/lib/core/ast/ensure-grammars.js +232 -0
- package/lib/core/ast/index.js +115 -0
- package/lib/core/ast/lang-dart.js +661 -0
- package/lib/core/ast/lang-go.js +530 -0
- package/lib/core/ast/lang-java.js +435 -0
- package/lib/core/ast/lang-javascript.js +272 -0
- package/lib/core/ast/lang-kotlin.js +423 -0
- package/lib/core/ast/lang-objc.js +388 -0
- package/lib/core/ast/lang-python.js +371 -0
- package/lib/core/ast/lang-swift.js +337 -0
- package/lib/core/ast/lang-typescript.js +503 -0
- package/lib/core/capability/CapabilityProbe.js +18 -9
- package/lib/core/constitution/Constitution.js +2 -3
- package/lib/core/constitution/ConstitutionValidator.js +65 -24
- package/lib/core/discovery/DartDiscoverer.js +534 -0
- package/lib/core/discovery/DiscovererRegistry.js +83 -0
- package/lib/core/discovery/GenericDiscoverer.js +225 -0
- package/lib/core/discovery/GoDiscoverer.js +541 -0
- package/lib/core/discovery/JvmDiscoverer.js +506 -0
- package/lib/core/discovery/NodeDiscoverer.js +466 -0
- package/lib/core/discovery/ProjectDiscoverer.js +93 -0
- package/lib/core/discovery/PythonDiscoverer.js +338 -0
- package/lib/core/discovery/SpmDiscoverer.js +5 -0
- package/lib/core/discovery/index.js +53 -0
- package/lib/core/enhancement/EnhancementPack.js +71 -0
- package/lib/core/enhancement/EnhancementRegistry.js +47 -0
- package/lib/core/enhancement/android-enhancement.js +102 -0
- package/lib/core/enhancement/django-enhancement.js +70 -0
- package/lib/core/enhancement/fastapi-enhancement.js +63 -0
- package/lib/core/enhancement/go-grpc-enhancement.js +152 -0
- package/lib/core/enhancement/go-web-enhancement.js +201 -0
- package/lib/core/enhancement/index.js +65 -0
- package/lib/core/enhancement/node-server-enhancement.js +88 -0
- package/lib/core/enhancement/react-enhancement.js +86 -0
- package/lib/core/enhancement/spring-enhancement.js +112 -0
- package/lib/core/enhancement/vue-enhancement.js +96 -0
- package/lib/core/gateway/Gateway.js +8 -9
- package/lib/core/gateway/GatewayActionRegistry.js +1 -1
- package/lib/core/permission/PermissionManager.js +12 -8
- package/lib/domain/index.js +13 -9
- package/lib/domain/knowledge/KnowledgeEntry.js +111 -101
- package/lib/domain/knowledge/KnowledgeRepository.js +0 -1
- package/lib/domain/knowledge/Lifecycle.js +22 -22
- package/lib/domain/knowledge/index.js +9 -12
- package/lib/domain/knowledge/values/Constraints.js +31 -21
- package/lib/domain/knowledge/values/Content.js +21 -13
- package/lib/domain/knowledge/values/Quality.js +31 -18
- package/lib/domain/knowledge/values/Reasoning.js +20 -12
- package/lib/domain/knowledge/values/Relations.js +37 -25
- package/lib/domain/knowledge/values/Stats.js +18 -12
- package/lib/domain/knowledge/values/index.js +4 -3
- package/lib/domain/snippet/Snippet.js +35 -10
- package/lib/external/ai/AiFactory.js +48 -16
- package/lib/external/ai/AiProvider.js +184 -90
- package/lib/external/ai/providers/ClaudeProvider.js +25 -12
- package/lib/external/ai/providers/GoogleGeminiProvider.js +59 -30
- package/lib/external/ai/providers/MockProvider.js +9 -3
- package/lib/external/ai/providers/OpenAiProvider.js +51 -29
- package/lib/external/mcp/McpServer.js +66 -36
- package/lib/external/mcp/errorHandler.js +23 -11
- package/lib/external/mcp/handlers/LanguageExtensions.js +138 -53
- package/lib/external/mcp/handlers/TargetClassifier.js +52 -16
- package/lib/external/mcp/handlers/bootstrap/pipeline/BootstrapSnapshot.js +81 -20
- package/lib/external/mcp/handlers/bootstrap/pipeline/EpisodicMemory.js +71 -42
- package/lib/external/mcp/handlers/bootstrap/pipeline/IncrementalBootstrap.js +9 -17
- package/lib/external/mcp/handlers/bootstrap/pipeline/ToolResultCache.js +14 -9
- package/lib/external/mcp/handlers/bootstrap/pipeline/dimension-context.js +15 -7
- package/lib/external/mcp/handlers/bootstrap/pipeline/orchestrator.js +352 -153
- package/lib/external/mcp/handlers/bootstrap/pipeline/tier-scheduler.js +52 -12
- package/lib/external/mcp/handlers/bootstrap/skills.js +143 -39
- package/lib/external/mcp/handlers/bootstrap.js +691 -168
- package/lib/external/mcp/handlers/browse.js +66 -22
- package/lib/external/mcp/handlers/candidate.js +118 -35
- package/lib/external/mcp/handlers/consolidated.js +49 -17
- package/lib/external/mcp/handlers/guard.js +104 -39
- package/lib/external/mcp/handlers/knowledge.js +60 -36
- package/lib/external/mcp/handlers/search.js +43 -14
- package/lib/external/mcp/handlers/skill.js +120 -45
- package/lib/external/mcp/handlers/structure.js +240 -86
- package/lib/external/mcp/handlers/system.js +42 -12
- package/lib/external/mcp/handlers/wiki.js +58 -33
- package/lib/external/mcp/tools.js +306 -123
- package/lib/http/HttpServer.js +72 -47
- package/lib/http/middleware/RateLimiter.js +5 -3
- package/lib/http/middleware/errorHandler.js +6 -1
- package/lib/http/middleware/requestLogger.js +14 -3
- package/lib/http/middleware/roleResolver.js +30 -23
- package/lib/http/routes/ai.js +387 -265
- package/lib/http/routes/auth.js +81 -61
- package/lib/http/routes/candidates.js +430 -320
- package/lib/http/routes/commands.js +289 -189
- package/lib/http/routes/extract.js +158 -125
- package/lib/http/routes/guardRules.js +309 -217
- package/lib/http/routes/knowledge.js +213 -154
- package/lib/http/routes/modules.js +578 -0
- package/lib/http/routes/monitoring.js +6 -6
- package/lib/http/routes/recipes.js +104 -93
- package/lib/http/routes/search.js +361 -305
- package/lib/http/routes/skills.js +145 -98
- package/lib/http/routes/snippets.js +42 -30
- package/lib/http/routes/spm.js +3 -405
- package/lib/http/routes/violations.js +113 -93
- package/lib/http/routes/wiki.js +211 -170
- package/lib/http/utils/routeHelpers.js +3 -1
- package/lib/http/utils/sse-sessions.js +16 -6
- package/lib/http/utils/sse.js +15 -5
- package/lib/infrastructure/audit/AuditLogger.js +5 -2
- package/lib/infrastructure/audit/AuditStore.js +10 -7
- package/lib/infrastructure/cache/CacheService.js +3 -1
- package/lib/infrastructure/cache/GraphCache.js +8 -4
- package/lib/infrastructure/cache/UnifiedCacheAdapter.js +1 -1
- package/lib/infrastructure/config/ConfigLoader.js +9 -5
- package/lib/infrastructure/config/Defaults.js +30 -10
- package/lib/infrastructure/config/Paths.js +28 -8
- package/lib/infrastructure/config/TriggerSymbol.js +22 -10
- package/lib/infrastructure/database/DatabaseConnection.js +15 -10
- package/lib/infrastructure/database/migrations/001_initial_schema.js +0 -1
- package/lib/infrastructure/external/ClipboardManager.js +6 -2
- package/lib/infrastructure/external/NativeUi.js +50 -43
- package/lib/infrastructure/external/OpenBrowser.js +14 -17
- package/lib/infrastructure/external/XcodeAutomation.js +14 -258
- package/lib/infrastructure/logging/Logger.js +46 -30
- package/lib/infrastructure/monitoring/ErrorTracker.js +7 -5
- package/lib/infrastructure/monitoring/PerformanceMonitor.js +12 -4
- package/lib/infrastructure/paths/HeaderResolver.js +25 -9
- package/lib/infrastructure/paths/PathFinder.js +34 -12
- package/lib/infrastructure/plugin/PluginManager.js +26 -8
- package/lib/infrastructure/realtime/RealtimeService.js +2 -2
- package/lib/infrastructure/vector/Chunker.js +22 -7
- package/lib/infrastructure/vector/IndexingPipeline.js +46 -22
- package/lib/infrastructure/vector/JsonVectorAdapter.js +90 -53
- package/lib/infrastructure/vector/VectorStore.js +28 -10
- package/lib/injection/ServiceContainer.js +247 -93
- package/lib/platform/ios/index.js +63 -0
- package/lib/platform/ios/routes/spm.js +437 -0
- package/lib/platform/ios/snippet/PlaceholderConverter.js +55 -0
- package/lib/platform/ios/snippet/XcodeCodec.js +112 -0
- package/lib/{service → platform/ios}/spm/DependencyGraph.js +41 -17
- package/lib/{service → platform/ios}/spm/PackageSwiftParser.js +41 -14
- package/lib/{service → platform/ios}/spm/PolicyEngine.js +9 -4
- package/lib/platform/ios/spm/SpmDiscoverer.js +122 -0
- package/lib/{service → platform/ios}/spm/SpmService.js +385 -127
- package/lib/{service/automation → platform/ios/xcode}/SaveEventFilter.js +8 -7
- package/lib/platform/ios/xcode/XcodeAutomation.js +350 -0
- package/lib/{service/automation → platform/ios/xcode}/XcodeIntegration.js +325 -145
- package/lib/repository/base/BaseRepository.js +7 -9
- package/lib/repository/knowledge/KnowledgeRepository.impl.js +98 -75
- package/lib/repository/token/TokenUsageStore.js +4 -2
- package/lib/service/automation/ActionPipeline.js +1 -1
- package/lib/service/automation/AutomationOrchestrator.js +8 -4
- package/lib/service/automation/ContextCollector.js +7 -5
- package/lib/service/automation/DirectiveDetector.js +23 -16
- package/lib/service/automation/FileWatcher.js +112 -56
- package/lib/service/automation/TriggerResolver.js +6 -4
- package/lib/service/automation/handlers/AlinkHandler.js +24 -12
- package/lib/service/automation/handlers/CreateHandler.js +19 -20
- package/lib/service/automation/handlers/DraftHandler.js +14 -8
- package/lib/service/automation/handlers/GuardHandler.js +93 -63
- package/lib/service/automation/handlers/HeaderHandler.js +1 -6
- package/lib/service/automation/handlers/SearchHandler.js +155 -88
- package/lib/service/bootstrap/BootstrapTaskManager.js +77 -35
- package/lib/service/candidate/SimilarityService.js +25 -9
- package/lib/service/chat/AnalystAgent.js +50 -24
- package/lib/service/chat/CandidateGuardrail.js +143 -17
- package/lib/service/chat/ChatAgent.js +655 -260
- package/lib/service/chat/ContextWindow.js +116 -71
- package/lib/service/chat/ConversationStore.js +77 -36
- package/lib/service/chat/EpisodicConsolidator.js +47 -23
- package/lib/service/chat/HandoffProtocol.js +98 -22
- package/lib/service/chat/Memory.js +34 -14
- package/lib/service/chat/ProducerAgent.js +40 -20
- package/lib/service/chat/ProjectSemanticMemory.js +109 -78
- package/lib/service/chat/ReasoningLayer.js +148 -70
- package/lib/service/chat/ReasoningTrace.js +44 -32
- package/lib/service/chat/TaskPipeline.js +39 -19
- package/lib/service/chat/ToolRegistry.js +48 -29
- package/lib/service/chat/WorkingMemory.js +44 -18
- package/lib/service/chat/tools.js +1096 -494
- package/lib/service/context/RecipeExtractor.js +132 -51
- package/lib/service/cursor/CursorDeliveryPipeline.js +82 -37
- package/lib/service/cursor/KnowledgeCompressor.js +25 -22
- package/lib/service/cursor/RulesGenerator.js +13 -7
- package/lib/service/cursor/SkillsSyncer.js +77 -27
- package/lib/service/cursor/TokenBudget.js +2 -2
- package/lib/service/cursor/TopicClassifier.js +54 -20
- package/lib/service/guard/ComplianceReporter.js +55 -43
- package/lib/service/guard/ExclusionManager.js +67 -29
- package/lib/service/guard/GuardCheckEngine.js +381 -86
- package/lib/service/guard/GuardFeedbackLoop.js +22 -10
- package/lib/service/guard/GuardService.js +29 -19
- package/lib/service/guard/RuleLearner.js +55 -23
- package/lib/service/guard/SourceFileCollector.js +27 -20
- package/lib/service/guard/ViolationsStore.js +43 -38
- package/lib/service/knowledge/CodeEntityGraph.js +147 -82
- package/lib/service/knowledge/ConfidenceRouter.js +12 -10
- package/lib/service/knowledge/KnowledgeFileWriter.js +147 -56
- package/lib/service/knowledge/KnowledgeGraphService.js +81 -34
- package/lib/service/knowledge/KnowledgeService.js +222 -112
- package/lib/service/module/ModuleService.js +969 -0
- package/lib/service/quality/FeedbackCollector.js +27 -15
- package/lib/service/quality/QualityScorer.js +78 -24
- package/lib/service/recipe/RecipeCandidateValidator.js +110 -44
- package/lib/service/recipe/RecipeParser.js +78 -45
- package/lib/service/search/CoarseRanker.js +43 -28
- package/lib/service/search/CrossEncoderReranker.js +32 -21
- package/lib/service/search/InvertedIndex.js +21 -7
- package/lib/service/search/MultiSignalRanker.js +90 -28
- package/lib/service/search/RetrievalFunnel.js +45 -24
- package/lib/service/search/SearchEngine.js +255 -103
- package/lib/service/skills/EventAggregator.js +32 -15
- package/lib/service/skills/SignalCollector.js +140 -64
- package/lib/service/skills/SkillAdvisor.js +79 -42
- package/lib/service/skills/SkillHooks.js +16 -14
- package/lib/service/snippet/PlaceholderConverter.js +5 -0
- package/lib/service/snippet/SnippetFactory.js +116 -99
- package/lib/service/snippet/SnippetInstaller.js +234 -62
- package/lib/service/snippet/codecs/SnippetCodec.js +67 -0
- package/lib/service/snippet/codecs/VSCodeCodec.js +102 -0
- package/lib/service/snippet/codecs/XcodeCodec.js +5 -0
- package/lib/service/wiki/WikiGenerator.js +637 -263
- package/lib/shared/DimensionCopyRegistry.js +472 -0
- package/lib/shared/LanguageService.js +399 -0
- package/lib/shared/PathGuard.js +45 -28
- package/lib/shared/RecipeReadinessChecker.js +72 -12
- package/lib/shared/constants.js +41 -41
- package/lib/shared/errors/BaseError.js +2 -2
- package/lib/shared/errors/index.js +4 -4
- package/lib/shared/similarity.js +25 -8
- package/lib/shared/token-utils.js +6 -2
- package/lib/shared/utils/common.js +12 -4
- package/package.json +49 -13
- package/scripts/bench-real-projects.mjs +256 -0
- package/scripts/build-native-ui.js +30 -30
- package/scripts/clear-old-vector-index.js +5 -35
- package/scripts/clear-vector-cache.js +7 -37
- package/scripts/collect-test-project-stats.mjs +160 -0
- package/scripts/diagnose-mcp.js +41 -32
- package/scripts/ensure-parse-package.js +6 -9
- package/scripts/generate-recipe-drafts.js +116 -77
- package/scripts/init-db.js +3 -20
- package/scripts/init-snippets.js +305 -0
- package/scripts/init-vector-db.js +173 -170
- package/scripts/install-cursor-skill.js +148 -104
- package/scripts/install-full.js +8 -21
- package/scripts/install-vscode-copilot.js +106 -170
- package/scripts/migrate-md-to-knowledge.mjs +139 -151
- package/scripts/postinstall-safe.js +5 -17
- package/scripts/recipe-audit.js +106 -82
- package/scripts/release.js +283 -323
- package/scripts/setup-mcp-config.js +62 -72
- package/scripts/verify-context-api.js +20 -20
- package/skills/autosnippet-analysis/SKILL.md +10 -6
- package/skills/autosnippet-candidates/SKILL.md +27 -26
- package/skills/autosnippet-coldstart/SKILL.md +555 -38
- package/skills/autosnippet-concepts/SKILL.md +349 -337
- package/skills/autosnippet-create/SKILL.md +5 -5
- package/skills/autosnippet-reference-dart/SKILL.md +543 -0
- package/skills/autosnippet-reference-go/SKILL.md +539 -0
- package/skills/autosnippet-reference-java/SKILL.md +534 -0
- package/skills/autosnippet-reference-jsts/SKILL.md +41 -9
- package/skills/autosnippet-reference-kotlin/SKILL.md +526 -0
- package/skills/autosnippet-reference-objc/SKILL.md +29 -6
- package/skills/autosnippet-reference-python/SKILL.md +800 -0
- package/skills/autosnippet-reference-swift/SKILL.md +70 -14
- package/skills/autosnippet-structure/SKILL.md +4 -4
- package/templates/cursor-rules/autosnippet-conventions.mdc +2 -2
- package/templates/recipes-setup/README.md +2 -2
- package/templates/recipes-setup/_template.md +1 -1
- package/dashboard/dist/assets/index-Bun3ld_J.css +0 -1
- package/dashboard/dist/assets/index-_Sk_Dmg3.js +0 -143
- package/resources/asd-entry/main.swift +0 -159
- package/scripts/build-asd-entry.js +0 -51
- package/scripts/init-xcode-snippets.js +0 -311
- package/template.json +0 -39
package/README.md
CHANGED
|
@@ -2,420 +2,327 @@
|
|
|
2
2
|
|
|
3
3
|
# AutoSnippet
|
|
4
4
|
|
|
5
|
-
**
|
|
5
|
+
**Knowledge Engine for Code — Turn your team's patterns into AI-searchable recipes.**
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
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
|
[](https://www.npmjs.com/package/autosnippet)
|
|
11
11
|
[](https://github.com/GxFn/AutoSnippet/blob/main/LICENSE)
|
|
12
12
|
[](https://nodejs.org)
|
|
13
13
|
|
|
14
|
+
[中文文档](README_CN.md)
|
|
15
|
+
|
|
14
16
|
</div>
|
|
15
17
|
|
|
16
18
|
---
|
|
17
19
|
|
|
18
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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** |
|
|
35
|
-
| **Candidate** |
|
|
36
|
-
| **
|
|
37
|
-
| **
|
|
38
|
-
| **
|
|
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
|
-
#
|
|
49
|
+
# Install globally
|
|
48
50
|
npm install -g autosnippet
|
|
49
51
|
|
|
50
|
-
#
|
|
52
|
+
# Initialize in your project
|
|
51
53
|
cd /path/to/your-project
|
|
52
|
-
asd setup
|
|
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
|
-
#
|
|
58
|
-
asd
|
|
56
|
+
# Cold-start: scan your codebase and extract patterns
|
|
57
|
+
asd coldstart # 9-dimension AI analysis → Candidates
|
|
59
58
|
|
|
60
|
-
#
|
|
61
|
-
asd
|
|
59
|
+
# Launch Dashboard to review and manage knowledge
|
|
60
|
+
asd ui # Web dashboard + API server
|
|
62
61
|
```
|
|
63
62
|
|
|
64
|
-
>
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
91
|
+
### 🔍 Multi-Strategy Search Engine
|
|
108
92
|
|
|
109
|
-
|
|
93
|
+
4-layer retrieval funnel with 5 search modes:
|
|
110
94
|
|
|
111
|
-
|
|
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
|
-
|
|
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
|
-
|
|
115
|
+
### 🛡️ Guard — Code Compliance
|
|
123
116
|
|
|
124
|
-
-
|
|
125
|
-
-
|
|
126
|
-
-
|
|
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
|
-
|
|
125
|
+
Full-featured web UI launched with `asd ui`:
|
|
133
126
|
|
|
134
|
-
Recipe
|
|
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
|
-
|
|
139
|
+
#### MCP Server (16 Tools)
|
|
143
140
|
|
|
144
|
-
|
|
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
|
-
|
|
148
|
+
12 Agent-tier tools (search, knowledge, structure, graph, guard, submit, skills, bootstrap, etc.) + 4 Admin tools.
|
|
166
149
|
|
|
167
|
-
|
|
150
|
+
#### VS Code Extension
|
|
168
151
|
|
|
169
|
-
|
|
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
|
-
|
|
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
|
-
|
|
168
|
+
### 📝 File Directives
|
|
190
169
|
|
|
191
|
-
|
|
170
|
+
Write directives as comments in any source file:
|
|
192
171
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
-
###
|
|
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
|
-
|
|
183
|
+
Tree-sitter powered code intelligence:
|
|
214
184
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
-
|
|
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
|
-
|
|
193
|
+
Plus 11 framework enhancement packs (React, Vue, Spring, Django, FastAPI, gRPC, Android, etc.).
|
|
220
194
|
|
|
221
|
-
|
|
222
|
-
asd install:vscode-copilot # 配置 MCP 和 Copilot 指令
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
### Xcode
|
|
195
|
+
### 🏛️ Constitution & Governance
|
|
226
196
|
|
|
227
|
-
|
|
197
|
+
Three-layer permission model:
|
|
228
198
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
-
|
|
203
|
+
Every write operation passes through the Gateway: role check → constitution rules → audit log.
|
|
236
204
|
|
|
237
|
-
|
|
205
|
+
### 🧠 Agent Memory (4 Tiers)
|
|
238
206
|
|
|
239
|
-
|
|
|
240
|
-
|
|
241
|
-
|
|
|
242
|
-
|
|
|
243
|
-
|
|
|
244
|
-
|
|
|
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
|
-
##
|
|
214
|
+
## CLI Reference
|
|
254
215
|
|
|
255
|
-
|
|
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
|
-
|
|
233
|
+
## Architecture
|
|
258
234
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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
|
-
|
|
268
|
+
Create `.env` in your project root (or configure via Dashboard → LLM Config):
|
|
284
269
|
|
|
285
270
|
```env
|
|
286
|
-
|
|
287
|
-
ASD_GOOGLE_API_KEY=your-key
|
|
288
|
-
|
|
289
|
-
|
|
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
|
-
|
|
293
|
-
|
|
294
|
-
### 项目目录结构
|
|
282
|
+
### Project Structure After Setup
|
|
295
283
|
|
|
296
284
|
```
|
|
297
285
|
your-project/
|
|
298
|
-
├── AutoSnippet/
|
|
299
|
-
│ ├──
|
|
300
|
-
│ ├──
|
|
301
|
-
│
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
│
|
|
305
|
-
├── .
|
|
306
|
-
│
|
|
307
|
-
|
|
308
|
-
├── .
|
|
309
|
-
│ ├──
|
|
310
|
-
│
|
|
311
|
-
|
|
312
|
-
├── .
|
|
313
|
-
|
|
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
|
-
|
|
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
|
-
|
|
312
|
+
## Requirements
|
|
379
313
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
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
|
-
|
|
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
|