autosnippet 1.5.9 → 1.6.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.
- package/README.md +43 -29
- package/bin/api-server.js +84 -0
- package/bin/asd +2 -2
- package/bin/asd-cli.js +86 -0
- package/bin/cli-commands.js +623 -0
- package/bin/cli-helpers.js +241 -0
- package/bin/{create.js → create-snippet.js} +22 -15
- package/bin/dashboard/helpers.js +12 -0
- package/bin/dashboard/routes/ai.js +180 -0
- package/bin/dashboard/routes/candidates.js +75 -0
- package/bin/dashboard/routes/commands.js +42 -0
- package/bin/dashboard/routes/core.js +187 -0
- package/bin/dashboard/routes/extract.js +158 -0
- package/bin/dashboard/routes/guard.js +117 -0
- package/bin/dashboard/routes/index.js +27 -0
- package/bin/dashboard/routes/recipes.js +228 -0
- package/bin/dashboard/routes/search.js +908 -0
- package/bin/dashboard/routes/search.js.bak +1005 -0
- package/bin/dashboard/routes/snippets.js +108 -0
- package/bin/dashboard/routes/spm.js +160 -0
- package/bin/dashboard-server.js +259 -0
- package/bin/init-spec.js +117 -0
- package/checksums.json +10 -3
- package/dashboard/dist/assets/index-BvG0go78.css +1 -0
- package/dashboard/dist/assets/index-xYTasTfI.js +54 -0
- package/dashboard/dist/assets/{markdown-DO_keoHJ.js → markdown-C9NwMkin.js} +1 -1
- package/dashboard/dist/assets/{vendor-DEnC4MH_.js → vendor-lTi5QT2P.js} +95 -65
- package/dashboard/dist/index.html +4 -4
- package/lib/agent/AdvancedCacheLayer.js +462 -0
- package/lib/agent/Agent.js +402 -0
- package/lib/agent/AgentCoordinator.js +679 -0
- package/lib/agent/BenchmarkRunner.js +450 -0
- package/lib/agent/ContextMapper.js +440 -0
- package/lib/agent/ConversationManager.js +429 -0
- package/lib/agent/ConversationMemory.js +469 -0
- package/lib/agent/CrossSessionLearner.js +421 -0
- package/lib/agent/DataSourceAdapter.js +407 -0
- package/lib/agent/ErrorHandler.js +377 -0
- package/lib/agent/IntentClassifier.js +524 -0
- package/lib/agent/MemoryManager.js +420 -0
- package/lib/agent/ResultFusion.js +562 -0
- package/lib/agent/Task.js +337 -0
- package/lib/agent/TokenBudget.js +451 -0
- package/lib/agent/UserPreferenceManager.js +383 -0
- package/lib/agent/agents/GenerateAgent.js +706 -0
- package/lib/agent/agents/LearnAgent.js +708 -0
- package/lib/agent/agents/LintAgent.js +553 -0
- package/lib/agent/agents/SearchAgent.js +610 -0
- package/lib/ai/AiFactory.js +5 -4
- package/lib/ai/candidateService.js +14 -2
- package/lib/ai/headerResolution.js +1 -1
- package/lib/ai/providers/ClaudeProvider.js +32 -21
- package/lib/ai/providers/OpenAiProvider.js +114 -51
- package/lib/ai/vectorStore.js +6 -8
- package/lib/api/APIGateway.js +689 -0
- package/lib/application/services/CandidateServiceV2.js +307 -0
- package/lib/application/services/ContextServiceCompat.js +319 -0
- package/lib/application/services/ContextServiceV2.js +362 -0
- package/lib/application/services/GuardServiceV2.js +308 -0
- package/lib/application/services/InjectionServiceV2.js +404 -0
- package/lib/application/services/IntelligentServiceLayer.js +803 -0
- package/lib/application/services/RecipeServiceV2.js +476 -0
- package/lib/application/services/SearchServiceV2.js +763 -0
- package/lib/application/services/SnippetFactoryV2.js +250 -0
- package/lib/application/services/SpecRepositoryV2.js +624 -0
- package/lib/application/usecases/guard/ValidateGuard.js +84 -0
- package/lib/application/usecases/index.js +18 -0
- package/lib/application/usecases/injection/InjectCode.js +78 -0
- package/lib/application/usecases/recipe/SearchRecipe.js +63 -0
- package/lib/application/usecases/snippet/CreateSnippet.js +83 -0
- package/lib/automation/ActionPipeline.js +13 -0
- package/lib/automation/AutomationOrchestrator.js +23 -0
- package/lib/automation/ContextCollector.js +10 -0
- package/lib/automation/OutputApplier.js +10 -0
- package/lib/automation/TriggerResolver.js +13 -0
- package/lib/bootstrap.js +243 -0
- package/lib/business/metrics/MetricsHub.js +442 -0
- package/lib/business/recipe/RecipeHub.js +460 -0
- package/lib/business/search/SearchHub.js +484 -0
- package/lib/candidate/CandidateServiceV2.js +8 -0
- package/lib/candidate/similarityService.js +57 -32
- package/lib/cli/README.md +226 -0
- package/lib/cli/candidateCommand.js +143 -0
- package/lib/cli/commands/BaseCommand.js +65 -0
- package/lib/cli/embedCommand.js +47 -0
- package/lib/cli/searchCommand.js +138 -0
- package/lib/cli/statusCommand.js +256 -0
- package/lib/cli/utils/cliHelpers.js +76 -0
- package/lib/cli/utils/clipboardHandler.js +92 -0
- package/lib/cli/utils/presetLoader.js +70 -0
- package/lib/context/ContextServiceCompat.js +8 -0
- package/lib/context/ContextServiceV2.js +8 -0
- package/lib/context/IndexingPipeline.js +14 -2
- package/lib/context/KnowledgeGraph.js +627 -0
- package/lib/context/RecipeExtractor.js +787 -0
- package/lib/context/adapters/JsonAdapter.js +136 -20
- package/lib/context/adapters/MilvusAdapter.js +518 -0
- package/lib/context/autoEmbed.js +3 -3
- package/lib/context/chunker.js +1 -1
- package/lib/context/constants.js +1 -1
- package/lib/context/index.js +17 -4
- package/lib/context/persistence.js +1 -1
- package/lib/context/recipe-schema.js +482 -0
- package/lib/core/BasePlugin.js +164 -0
- package/lib/core/ConfigManager.js +291 -0
- package/lib/core/EventBus.js +128 -0
- package/lib/core/Logger.js +198 -0
- package/lib/core/PluginLoader.js +306 -0
- package/lib/core/ServiceContainer.js +214 -0
- package/lib/dashboard/README.md +303 -0
- package/lib/domain/entities/Agent.js +103 -0
- package/lib/domain/entities/Memory.js +112 -0
- package/lib/domain/entities/Recipe.js +196 -0
- package/lib/domain/entities/Snippet.js +121 -0
- package/lib/domain/entities/v2/GuardRuleV2.js +118 -0
- package/lib/domain/entities/v2/LegacyAdapter.js +50 -0
- package/lib/domain/entities/v2/RecipeV2.js +122 -0
- package/lib/domain/entities/v2/SnippetV2.js +118 -0
- package/lib/domain/entities/v2/id.js +13 -0
- package/lib/domain/entities/v2/index.js +14 -0
- package/lib/guard/EnhancedGuardChecker.js +163 -0
- package/lib/guard/GuardExclusionManager.js +216 -0
- package/lib/guard/GuardRuleLearner.js +180 -0
- package/lib/guard/GuardRuleMigrator.js +229 -0
- package/lib/guard/GuardServiceV2.js +8 -0
- package/lib/guard/guardRules-iOS.js +25 -797
- package/lib/guard/guardViolations.js +5 -4
- package/lib/guard/index.js +15 -0
- package/lib/guard/ios/audit.js +266 -0
- package/lib/guard/ios/codeChecks.js +159 -0
- package/lib/guard/ios/defaultRules.js +268 -0
- package/lib/guard/ios/staticCheck.js +79 -0
- package/lib/guard/ios/utils.js +19 -0
- package/lib/infra/vectorCache.js +365 -0
- package/lib/infrastructure/cache/CacheHub.js +243 -0
- package/lib/{infra/cacheStore.js → infrastructure/cache/CacheStore.js} +2 -2
- package/lib/{infra/defaults.js → infrastructure/config/Defaults.js} +8 -6
- package/lib/{infra/paths.js → infrastructure/config/Paths.js} +62 -7
- package/lib/infrastructure/error/ErrorManager.js +453 -0
- package/lib/infrastructure/errors/AiError.js +73 -0
- package/lib/infrastructure/errors/BaseError.js +50 -0
- package/lib/infrastructure/errors/ContextError.js +58 -0
- package/lib/infrastructure/errors/ErrorHandler.js +113 -0
- package/lib/infrastructure/errors/GuardError.js +14 -0
- package/lib/infrastructure/errors/InjectionError.js +14 -0
- package/lib/infrastructure/errors/ValidationError.js +49 -0
- package/lib/infrastructure/errors/index.js +14 -0
- package/lib/{infra/openBrowser.js → infrastructure/external/OpenBrowser.js} +32 -6
- package/lib/infrastructure/external/spm/DepFixer.js +164 -0
- package/lib/infrastructure/external/spm/DepGraphAnalyzer.js +98 -0
- package/lib/infrastructure/external/spm/DepGraphService.js +208 -0
- package/lib/infrastructure/external/spm/DepPolicyEngine.js +49 -0
- package/lib/infrastructure/external/spm/DepReport.js +10 -0
- package/lib/infrastructure/external/spm/PackageParserV2.js +322 -0
- package/lib/infrastructure/external/spm/SpmDepsServiceV2.js +466 -0
- package/lib/infrastructure/external/spm/spmDepGraphPatch.js +4 -0
- package/lib/infrastructure/external/spm/spmDepMapUpdater.js +476 -0
- package/lib/infrastructure/external/spm/swiftParserClient.js +311 -0
- package/lib/infrastructure/external/spm/targetScanner.js +214 -0
- package/lib/infrastructure/logging/LogFactory.js +160 -0
- package/lib/infrastructure/logging/LoggerAdapter.js +114 -0
- package/lib/infrastructure/logging/index.js +18 -0
- package/lib/infrastructure/notification/ClipboardManager.js +137 -0
- package/lib/{infra/nativeUi.js → infrastructure/notification/NativeUi.js} +79 -12
- package/lib/infrastructure/notification/Notifier.js +115 -0
- package/{bin/findPath.js → lib/infrastructure/paths/PathFinder.js} +46 -173
- package/lib/infrastructure/paths/ProjectStructure.js +222 -0
- package/lib/infrastructure/process/ProcessHub.js +452 -0
- package/lib/{infra/vectorMath.js → infrastructure/vector/VectorMath.js} +2 -2
- package/lib/injection/DirectiveParserV2.js +217 -0
- package/lib/injection/ImportDecisionEngine.js +39 -0
- package/lib/injection/ImportWriterV2.js +707 -0
- package/lib/injection/InjectionServiceV2.js +8 -0
- package/lib/injection/ModuleResolverV2.js +261 -0
- package/lib/injection/injectionService.js +228 -35
- package/lib/migration/knowledgeBaseMigrator.js +203 -0
- package/lib/quality/FeedbackCollector.js +18 -0
- package/lib/quality/QualityScorer.js +62 -0
- package/lib/quality/config/default.js +16 -0
- package/lib/quality/dimensions/CodeQualityDimension.js +24 -0
- package/lib/quality/dimensions/CompletenessDimension.js +21 -0
- package/lib/quality/dimensions/EngagementDimension.js +20 -0
- package/lib/quality/dimensions/FormatDimension.js +18 -0
- package/lib/quality/dimensions/MetadataDimension.js +15 -0
- package/lib/quality/index.js +7 -0
- package/lib/rateLimit.js +11 -2
- package/lib/recipe/RecipeServiceV2.js +8 -0
- package/lib/recipe/parseRecipeMd.js +57 -1
- package/lib/recipe/recipeStats.js +5 -4
- package/lib/search/MultiSignalRanker.js +517 -0
- package/lib/search/SearchServiceV2.js +8 -0
- package/lib/search/bm25.js +63 -0
- package/lib/search/coarseRanker.js +169 -0
- package/lib/search/contextAnalyzer.js +135 -0
- package/lib/search/featureExtractor.js +24 -0
- package/lib/search/fineRanker.js +26 -0
- package/lib/search/indexStore.js +31 -0
- package/lib/search/indexer.js +64 -0
- package/lib/search/invertedIndex.js +32 -0
- package/lib/search/ltrModel.js +11 -0
- package/lib/search/queryOptimizer.js +11 -0
- package/lib/search/rankingEngine.js +44 -0
- package/lib/search/recallEngine.js +70 -0
- package/lib/search/searchCache.js +45 -0
- package/lib/search/unifiedSearch.js +245 -0
- package/lib/services/agent/AgentManager.js +417 -0
- package/lib/services/agent/AgentPool.js +336 -0
- package/lib/services/agent/AgentService.js +330 -0
- package/lib/services/agent/BaseAgent.js +356 -0
- package/lib/services/agent/ChainManager.js +294 -0
- package/lib/services/agent/ConversationManager.js +363 -0
- package/lib/services/agent/IAgent.js +198 -0
- package/lib/services/agent/ITool.js +118 -0
- package/lib/services/agent/MemoryStore.js +378 -0
- package/lib/services/agent/ToolOrchestrator.js +505 -0
- package/lib/services/agent/ToolRegistry.js +365 -0
- package/lib/services/agent/agents/CodeAgent.js +71 -0
- package/lib/services/agent/agents/GuardAgent.js +76 -0
- package/lib/services/agent/agents/RecipeAgent.js +75 -0
- package/lib/services/agent/agents/SearchAgent.js +58 -0
- package/lib/services/agent/tools/CodeAnalysisTool.js +80 -0
- package/lib/services/agent/tools/GuardCheckTool.js +98 -0
- package/lib/services/agent/tools/SemanticSearchTool.js +95 -0
- package/lib/services/ai/AiService.js +312 -0
- package/lib/services/ai/BaseAiProvider.js +175 -0
- package/lib/services/ai/EXAMPLES.md +346 -0
- package/lib/services/ai/IAiProvider.js +104 -0
- package/lib/services/ai/LegacyProviderAdapter.js +148 -0
- package/lib/services/ai/OpenAiCompatibleProvider.js +266 -0
- package/lib/services/ai/ProviderManager.js +215 -0
- package/lib/services/context/AdapterManager.js +254 -0
- package/lib/services/context/BaseContextAdapter.js +212 -0
- package/lib/services/context/ContextService.js +378 -0
- package/lib/services/context/IContextAdapter.js +142 -0
- package/lib/snippet/MarkerLineV2.js +175 -0
- package/lib/snippet/SnippetFactoryV2.js +8 -0
- package/lib/snippet/SpecRepositoryV2.js +8 -0
- package/lib/snippet/snippetInstaller.js +2 -2
- package/lib/spm/PackageParserV2.js +8 -0
- package/lib/spm/SpmDepsServiceV2.js +8 -0
- package/lib/spm/spmDepMapUpdater.js +2 -464
- package/lib/spm/swiftParserClient.js +2 -308
- package/lib/spm/targetScanner.js +2 -162
- package/lib/watch/DirectiveDetector.js +109 -0
- package/lib/watch/FileDebouncer.js +34 -0
- package/lib/watch/FileWatchConfig.js +49 -0
- package/lib/watch/FileWatchService.js +210 -0
- package/lib/watch/fileWatcher.js +2 -796
- package/lib/watch/handlers/AlinkHandler.js +55 -0
- package/lib/watch/handlers/CreateHandler.js +219 -0
- package/lib/watch/handlers/DraftHandler.js +113 -0
- package/lib/watch/handlers/GuardHandler.js +194 -0
- package/lib/watch/handlers/HeaderHandler.js +62 -0
- package/lib/watch/handlers/SearchHandler.js +1018 -0
- package/lib/writeGuard.js +179 -23
- package/lib/xcode-search-cache-fix.js +236 -0
- package/package.json +30 -17
- package/recipes/README.md +22 -8
- package/resources/asd-entry/main.swift +4 -4
- package/resources/native-ui/main.swift +301 -57
- package/resources/openChrome.applescript +2 -2
- package/scripts/build-asd-entry.js +1 -1
- package/scripts/build-knowledge-graph.js +363 -0
- package/scripts/check-paths.js +206 -0
- package/scripts/cursor-rules/autosnippet-conventions.mdc +16 -1
- package/scripts/generate-checksums.js +25 -2
- package/scripts/generate-recipe-drafts.js +151 -0
- package/scripts/init-vector-db.js +269 -0
- package/scripts/init-xcode-snippets.js +310 -0
- package/scripts/install-cursor-skill.js +59 -29
- package/scripts/install-full.js +2 -11
- package/scripts/install-vscode-copilot.js +436 -0
- package/scripts/mcp-server.js +198 -8
- package/scripts/migrate-guard-rules.js +117 -0
- package/scripts/migrate-recipes-metadata.js +338 -0
- package/scripts/migration/MigrationFramework.js +102 -0
- package/scripts/migration/fix.js +83 -0
- package/scripts/migration/index.js +11 -0
- package/scripts/migration/run.js +83 -0
- package/scripts/migration/strategies/GuardRuleMigrator.js +33 -0
- package/scripts/migration/strategies/RecipeMigrator.js +22 -0
- package/scripts/migration/strategies/SnippetMigrator.js +21 -0
- package/scripts/migration/validate.js +88 -0
- package/scripts/random-search-test.js +142 -0
- package/scripts/recipe-migration-complete.js +528 -0
- package/scripts/recipe-migration-diagnose.js +405 -0
- package/scripts/setup-mcp-config.js +147 -0
- package/scripts/test-ai-failure-handling.js +79 -0
- package/scripts/test-google-models.js +85 -0
- package/scripts/test-hybrid-comprehensive.js +120 -0
- package/scripts/test-hybrid-search.js +54 -0
- package/scripts/test-search-modes.js +364 -0
- package/scripts/test-sentence-search.js +80 -0
- package/scripts/verify-code-upgrade.js +409 -0
- package/scripts/verify-mcp-vscode.sh +300 -0
- package/skills/autosnippet-batch-scan/SKILL.md +11 -1
- package/skills/autosnippet-concepts/SKILL.md +485 -18
- package/skills/autosnippet-create/SKILL.md +21 -13
- package/skills/autosnippet-dep-graph/SKILL.md +4 -4
- package/skills/autosnippet-guard/SKILL.md +5 -5
- package/skills/autosnippet-recipe-candidates/SKILL.md +168 -0
- package/skills/autosnippet-recipes/SKILL.md +37 -9
- package/skills/autosnippet-when/SKILL.md +4 -2
- package/bin/asnip.js +0 -1169
- package/bin/init.js +0 -218
- package/bin/share.js +0 -282
- package/bin/ui.js +0 -1291
- package/dashboard/dist/assets/index-BAx2yiFr.css +0 -1
- package/dashboard/dist/assets/index-ETHRlGPL.js +0 -44
- package/lib/context/ContextService.js +0 -188
- package/lib/context/adapters/LanceAdapter.js +0 -247
- package/lib/infra/notifier.js +0 -63
- package/lib/injection/directiveParser.js +0 -78
- package/lib/injection/importWriter.js +0 -276
- package/lib/injection/moduleResolver.js +0 -66
- package/lib/search/searchService.js +0 -136
- package/lib/snippet/markerLine.js +0 -26
- package/lib/snippet/snippetFactory.js +0 -69
- package/lib/snippet/specRepository.js +0 -378
- package/lib/spm/packageParser.js +0 -247
- package/lib/spm/spmDepsService.js +0 -762
- /package/lib/{infra/triggerSymbol.js → infrastructure/config/TriggerSymbol.js} +0 -0
- /package/lib/{infra → infrastructure/filesystem}/FileFinder.js +0 -0
package/README.md
CHANGED
|
@@ -20,15 +20,30 @@
|
|
|
20
20
|
|
|
21
21
|
## 安装与快速开始
|
|
22
22
|
|
|
23
|
+
### 1. 安装 AutoSnippet
|
|
24
|
+
|
|
23
25
|
```bash
|
|
24
26
|
npm install -g autosnippet
|
|
25
27
|
```
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
### 2. 在你的项目中初始化
|
|
30
|
+
|
|
31
|
+
**重要**:在**你的项目目录**(不是 AutoSnippet 源码目录)执行:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
cd /path/to/your-project # 进入你的项目
|
|
35
|
+
|
|
36
|
+
asd setup # 一键初始化
|
|
37
|
+
# ✅ 创建 AutoSnippet/ 目录和配置
|
|
38
|
+
# ✅ 自动配置 VSCode (.vscode/settings.json)
|
|
39
|
+
# ✅ 自动配置 Cursor (.cursor/mcp.json)
|
|
40
|
+
# ✅ 放置 Recipe 模板
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 3. 启动 Dashboard
|
|
28
44
|
|
|
29
45
|
```bash
|
|
30
|
-
asd
|
|
31
|
-
asd ui # 启动 Dashboard(建议常驻)
|
|
46
|
+
asd ui # 启动 Dashboard + watch
|
|
32
47
|
```
|
|
33
48
|
|
|
34
49
|
`asd ui` 会启动 Web 管理后台并后台 watch;首次运行若前端不存在会自动构建。浏览器会自动打开 Dashboard。
|
|
@@ -39,7 +54,7 @@ asd ui # 启动 Dashboard(建议常驻)
|
|
|
39
54
|
|
|
40
55
|
1. **组建知识库**:`asd ais <Target>` 或 `asd ais --all` → Dashboard Candidates 审核 → Recipe 入库
|
|
41
56
|
2. **依赖关系**:`asd spm-map` 或 Dashboard 刷新
|
|
42
|
-
3. **Cursor 集成**:`asd install:cursor-skill --mcp`(安装 Skills + Cursor 规则 `.cursor/rules/` + MCP
|
|
57
|
+
3. **Cursor 集成**:`asd install:cursor-skill --mcp`(安装 Skills + Cursor 规则 `.cursor/rules/` + MCP;MCP 工具使用时需 `asd ui` 运行)
|
|
43
58
|
4. **语义索引**:`asd ui` 启动时自动 embed;也可手动 `asd embed`
|
|
44
59
|
|
|
45
60
|
### 闭环
|
|
@@ -57,7 +72,7 @@ asd ui # 启动 Dashboard(建议常驻)
|
|
|
57
72
|
| 指令 | 作用 |
|
|
58
73
|
|------|------|
|
|
59
74
|
| `// as:create` / `// as:c` | 无选项时只打开 Dashboard(路径已填),由用户点 Scan File 或 Use Copied Code。`-c` 强制用剪切板(静默创建或打开);`-f` 强制用路径(打开 Dashboard 并自动执行 Scan File) |
|
|
60
|
-
| `// as:
|
|
75
|
+
| `// as:audit` / `// as:a` [关键词或规模] | 按知识库 AI 审查;无后缀时仅检查当前文件;后缀 **file** / **target** / **project** 可扩大范围(target=当前 Target 内所有源文件,project=项目内所有源文件);其他为检索关键词 |
|
|
61
76
|
| `// as:search` / `// as:s` [关键词] | 从知识库检索并插入 Recipe/Snippet |
|
|
62
77
|
| `// as:include` / `// as:import` | Snippet 内头文件/模块标记,保存时自动注入 |
|
|
63
78
|
|
|
@@ -68,17 +83,17 @@ asd ui # 启动 Dashboard(建议常驻)
|
|
|
68
83
|
|
|
69
84
|
| 命令 | 说明 |
|
|
70
85
|
|------|------|
|
|
71
|
-
| `asd setup` | 初始化项目根(创建
|
|
86
|
+
| `asd setup` | 初始化项目根(创建 AutoSnippet/AutoSnippet.boxspec.json) |
|
|
72
87
|
| `asd ui` | 启动 Dashboard + watch |
|
|
73
88
|
| `asd status` | 环境自检(含项目根、AI、索引、Dashboard/Watch、Native UI) |
|
|
74
89
|
| `asd create --clipboard` | 从剪贴板创建 Recipe/Snippet |
|
|
75
90
|
| `asd candidate` | 从剪贴板创建候选(Dashboard 审核) |
|
|
76
|
-
| `asd
|
|
91
|
+
| `asd extract` / `asd e` | 同步 Snippets 到 Xcode |
|
|
77
92
|
| `asd ais [Target]` | AI 扫描 Target → Candidates |
|
|
78
93
|
| `asd search [keyword] --copy` | 搜索并复制第一条到剪贴板 |
|
|
79
94
|
| `asd search [keyword] --pick` | 交互选择后复制/插入 |
|
|
80
95
|
| `asd install:cursor-skill --mcp` | 安装 Skills、Cursor 规则(`.cursor/rules/*.mdc`)并配置 MCP。配置时可运行;MCP 工具使用时需 `asd ui` 已启动 |
|
|
81
|
-
| `asd install:full` | 全量安装;`--parser` 含 Swift
|
|
96
|
+
| `asd install:full` | 全量安装;`--parser` 含 Swift 解析器 |
|
|
82
97
|
| `asd embed` | 手动构建语义向量索引(`asd ui` 启动时也会自动执行) |
|
|
83
98
|
| `asd spm-map` | 刷新 SPM 依赖映射(依赖关系图数据来源) |
|
|
84
99
|
|
|
@@ -86,24 +101,23 @@ asd ui # 启动 Dashboard(建议常驻)
|
|
|
86
101
|
|
|
87
102
|
除 `asd ais [Target]`(项目内 AI)外,可用 **Cursor 作为批量扫描工具**:在 Cursor 里让 Agent 通过 **MCP 工具**(`autosnippet_get_targets` → `autosnippet_get_target_files` → 按文件提取 → `autosnippet_submit_candidates`)扫描指定 Target,用 Cursor 模型提取候选并提交到 Dashboard,再到 **Candidates** 页审核入库。
|
|
88
103
|
|
|
89
|
-
简单一句:「扫描 BDNetwork ,生成 Recipes
|
|
104
|
+
简单一句:「扫描 BDNetwork ,生成 Recipes 到候选」。话又说回来,最好还是详细点,先候选一两个文件,确认 cursor 认清字段,就可以在当前会话多文件执行了。
|
|
105
|
+
|
|
106
|
+
## 可选依赖
|
|
90
107
|
|
|
91
|
-
|
|
108
|
+
### Swift 解析器(可选)
|
|
92
109
|
|
|
93
|
-
|
|
110
|
+
AutoSnippet 默认使用 `swift package dump-package` 解析 SPM 依赖。如需更准确的解析,可安装 Swift 解析器:
|
|
94
111
|
|
|
95
112
|
```bash
|
|
96
|
-
|
|
97
|
-
asd install:full --parser # 上述 + Swift 解析器(ParsePackage,SPM 解析更准确)
|
|
98
|
-
asd install:full --lancedb # 仅安装 LanceDB(向量检索更快)
|
|
113
|
+
npm run build:parser # 构建 ParsePackage(需本机已安装 Swift)
|
|
99
114
|
```
|
|
100
115
|
|
|
101
|
-
|
|
116
|
+
构建后会在 `tools/parse-package/.build/release/` 生成解析器,SPM 解析将更准确可靠。未安装时自动回退到 `dump-package`,功能正常。
|
|
102
117
|
|
|
103
118
|
## 配置
|
|
104
119
|
|
|
105
120
|
- **AI**:项目根 `.env`,参考 `.env.example` 配置 `ASD_GOOGLE_API_KEY` 等。可选 `ASD_AI_PROVIDER`、代理等。
|
|
106
|
-
- **LanceDB**:`asd install:full --lancedb`,在 boxspec 的 `context.storage.adapter` 中配置 `"lance"`。
|
|
107
121
|
- **Native UI**(可选):macOS 上 `npm install` 会尝试构建 `resources/native-ui/native-ui`(需本机 Swift);未构建时回退到 AppleScript/inquirer,功能正常。
|
|
108
122
|
- **权限设置**(可选):写权限探针(在子仓库执行 `git push --dry-run`,通过才允许保存 Recipe/Snippet,否则 403)+ 完整性校验(`asd` 启动前关键文件 SHA-256)。详见 [权限设置说明](docs/权限设置说明.md)。
|
|
109
123
|
|
|
@@ -111,13 +125,13 @@ asd install:full --lancedb # 仅安装 LanceDB(向量检索更快)
|
|
|
111
125
|
|
|
112
126
|
| 术语 | 说明 |
|
|
113
127
|
|------|------|
|
|
114
|
-
| **Recipe** | `
|
|
128
|
+
| **Recipe** | `AutoSnippet/recipes/` 下的 Markdown 知识(配方):含代码块 + 使用说明,供 AI 检索、Guard、搜索,**默认位置,用户可通过 boxspec `knowledgeBase.dir` 配置改成 `Knowledge/` 等**
|
|
115
129
|
| **Snippet** | Xcode 代码片段,通过 trigger(默认 `@`)补全,可与 Recipe 关联 |
|
|
116
130
|
| **Candidate(候选)** | 待审核入库的项;来自 `as:create`、MCP 提交、`asd ais` 扫描等,经 Dashboard 审核后保存为 Recipe/Snippet |
|
|
117
|
-
| **Knowledge
|
|
131
|
+
| **Knowledge(AutoSnippet)** | 项目知识库目录,包含 `recipes/`、`.autosnippet/`(索引、candidates、guard 配置等);Snippet 配置在 root spec 的 list 中。|
|
|
118
132
|
| **Dashboard** | Web 管理后台(`asd ui` 启动),含 Recipes、Candidates、Guard、Snippets 等页面 |
|
|
119
|
-
| **watch** | 文件监听进程(`asd ui` 或 `asd watch` 启动),保存时触发 `as:create`、`as:
|
|
120
|
-
| **Guard** | 按 Recipe 知识库对代码做 AI 审查;`// as:
|
|
133
|
+
| **watch** | 文件监听进程(`asd ui` 或 `asd watch` 启动),保存时触发 `as:create`、`as:audit`、`as:search` |
|
|
134
|
+
| **Guard** | 按 Recipe 知识库对代码做 AI 审查;`// as:audit` 触发 |
|
|
121
135
|
| **embed** | 语义向量索引构建;`asd embed` 或 `asd ui` 启动时自动执行,供语义检索与 MCP 使用 |
|
|
122
136
|
| **MCP** | Model Context Protocol;Cursor 通过 MCP 调用 `autosnippet_context_search` 等工具 |
|
|
123
137
|
| **Skills** | Cursor Agent Skills(`.cursor/skills/`),描述何时用、如何用 AutoSnippet 能力 |
|
|
@@ -125,22 +139,22 @@ asd install:full --lancedb # 仅安装 LanceDB(向量检索更快)
|
|
|
125
139
|
| **项目根** | 含 `AutoSnippetRoot.boxspec.json` 的目录 |
|
|
126
140
|
| **Target** | SPM 模块/编译单元;`asd ais <Target>` 扫描该 Target 下的源码提取候选 |
|
|
127
141
|
|
|
128
|
-
**详细介绍**:启动 `asd ui` 后访问 Dashboard → **使用说明**
|
|
142
|
+
**详细介绍**:启动 `asd ui` 后访问 Dashboard → **使用说明** 页;
|
|
129
143
|
|
|
130
|
-
##
|
|
144
|
+
## AutoSnippet 目录与 Git
|
|
131
145
|
|
|
132
|
-
|
|
146
|
+
AutoSnippet 下各路径与版本控制的关系建议如下(可按项目需要调整):
|
|
133
147
|
|
|
134
148
|
| 路径 | 说明 | 建议 |
|
|
135
149
|
|------|------|------|
|
|
136
|
-
| **
|
|
137
|
-
| **
|
|
138
|
-
| **
|
|
139
|
-
| **
|
|
140
|
-
| **
|
|
150
|
+
| **AutoSnippet/recipes/** | Recipe 的 Markdown 文件 | **Git 子仓库**:单独建远程仓库并 `git submodule add <url> AutoSnippet/recipes`,用于权限拦截(仅能 push 子仓库的人可保存/上传 Recipe)。详见 [权限设置说明](docs/权限设置说明.md) 中「只把 AutoSnippet/recipes 作为子仓库」。 |
|
|
151
|
+
| **AutoSnippet/.autosnippet/** | Guard 规则、违反记录、candidates、recipe-stats、context 配置等 | **跟随主仓库 Git**:规则与配置建议提交到主仓库,便于团队共享。 |
|
|
152
|
+
| **AutoSnippet/.autosnippet/context/index/** | 语义向量索引(embed 生成) | **不跟随 Git**:体积大、机器相关,建议加入 `.gitignore`(如 `AutoSnippet/.autosnippet/context/index/`)。 |
|
|
153
|
+
| **AutoSnippet/.autosnippet/candidates/**(若存在) | 候选数据等 | 视需要:若仅本地缓存可不提交;若团队共享可跟随主仓库或单独子仓库。 |
|
|
154
|
+
| **AutoSnippet/AutoSnippet.spmmap.json**(若存在) | SPM 依赖映射 | **跟随主仓库 Git**:便于依赖关系图一致。 |
|
|
141
155
|
|
|
142
156
|
- **跟随主仓库 Git**:由主项目 `git add/commit/push` 管理,所有人按主仓库权限读写。
|
|
143
|
-
- **Git 子仓库**:`
|
|
157
|
+
- **Git 子仓库**:`AutoSnippet/recipes` 为单独仓库(submodule),Recipe 上传(git push)由 Git 服务端权限拦截。配合 `.env` 中 `ASD_RECIPES_WRITE_DIR=AutoSnippet/recipes` 是为了保识管理员(有 push 权限者)能够正确提交 Recipe:探针目录与 Recipe 写入目录一致,保存后可正常推送。
|
|
144
158
|
- **不跟随 Git**:在 `.gitignore` 中忽略,不提交、不推送。
|
|
145
159
|
|
|
146
160
|
---
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
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> 配置文件路径
|
|
11
|
+
*/
|
|
12
|
+
|
|
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');
|
|
18
|
+
|
|
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
|
+
}
|
|
36
|
+
|
|
37
|
+
return options;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 启动 API 服务器
|
|
42
|
+
*/
|
|
43
|
+
async function startServer() {
|
|
44
|
+
const options = parseArgs();
|
|
45
|
+
|
|
46
|
+
// 创建 Agent
|
|
47
|
+
const agent = new Agent({ name: 'APIAgent' });
|
|
48
|
+
|
|
49
|
+
// 注册 Hub
|
|
50
|
+
agent.registerHub('recipe', new RecipeHub());
|
|
51
|
+
agent.registerHub('search', new SearchHub());
|
|
52
|
+
agent.registerHub('metric', new MetricsHub());
|
|
53
|
+
|
|
54
|
+
// 创建 API Gateway
|
|
55
|
+
const gateway = new APIGateway(agent, {
|
|
56
|
+
port: options.port,
|
|
57
|
+
host: options.host,
|
|
58
|
+
});
|
|
59
|
+
|
|
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 停止服务器`);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error('❌ 启动服务器失败:', error);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 处理信号
|
|
73
|
+
process.on('SIGINT', async () => {
|
|
74
|
+
console.log('\n🛑 停止服务器...');
|
|
75
|
+
await gateway.stop();
|
|
76
|
+
console.log('✅ 服务器已停止');
|
|
77
|
+
process.exit(0);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
startServer().catch(error => {
|
|
82
|
+
console.error('Fatal error:', error);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
});
|
package/bin/asd
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env sh
|
|
2
|
-
# AutoSnippet 入口:优先使用原生校验入口(bin/asd-verify),否则回退到 node bin/
|
|
2
|
+
# AutoSnippet 入口:优先使用原生校验入口(bin/asd-verify),否则回退到 node bin/asd-cli.js
|
|
3
3
|
# 解析 $0 的符号链接,使 DIR 指向包内 bin 目录(npm install -g 时 $0 可能是 global bin 下的 symlink)
|
|
4
4
|
SCRIPT="$0"
|
|
5
5
|
while [ -L "$SCRIPT" ]; do
|
|
@@ -17,5 +17,5 @@ export ASD_CWD
|
|
|
17
17
|
if [ -x "$DIR/asd-verify" ]; then
|
|
18
18
|
exec "$DIR/asd-verify" "$@"
|
|
19
19
|
else
|
|
20
|
-
exec node "$DIR/
|
|
20
|
+
exec node "$DIR/asd-cli.js" "$@"
|
|
21
21
|
fi
|
package/bin/asd-cli.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 职责:
|
|
5
|
+
* - AutoSnippet CLI 入口(命令行 asd)
|
|
6
|
+
* - 负责解析参数/路由子命令,并串联 install/create/extract/watch 等能力
|
|
7
|
+
*
|
|
8
|
+
* 核心流程:
|
|
9
|
+
* - commander 解析命令与全局参数(--preset/--yes)
|
|
10
|
+
* - 读取/查找 spec(AutoSnippet.boxspec.json)
|
|
11
|
+
* - 调用对应模块执行实际逻辑(create/install/extract/watch/...)
|
|
12
|
+
*
|
|
13
|
+
* 核心方法:
|
|
14
|
+
* - loadPresetConfig(presetPath): 读取预置输入 JSON(用于非交互)
|
|
15
|
+
* - getSpecFile(callback): 向上查找 AutoSnippet.boxspec.json
|
|
16
|
+
*
|
|
17
|
+
* 主要命令:
|
|
18
|
+
* - setup / init
|
|
19
|
+
* - install(i) / create(c) / extract(e) / watch(w)
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const fs = require('fs');
|
|
23
|
+
const path = require('path');
|
|
24
|
+
|
|
25
|
+
// 入口校验:包内存在 checksums.json 且未经过 asd-verify(无 ASD_VERIFIED)时,可拒跑或警告,避免绕过完整性校验直接运行 node bin/asd-cli.js
|
|
26
|
+
// 开发环境可设 ASD_SKIP_CHECKSUMS=1 或 ASD_SKIP_ENTRY_CHECK=1 来跳过检查
|
|
27
|
+
const pkgRoot = path.join(__dirname, '..');
|
|
28
|
+
const checksumsPath = path.join(pkgRoot, 'checksums.json');
|
|
29
|
+
if (fs.existsSync(checksumsPath) && process.env.ASD_VERIFIED !== '1' && process.env.ASD_SKIP_CHECKSUMS !== '1') {
|
|
30
|
+
const msg = 'asd: 未经过完整性校验入口(请使用 asd 命令,勿直接运行 node bin/asd-cli.js)。开发/调试可设 ASD_SKIP_CHECKSUMS=1 或 ASD_SKIP_ENTRY_CHECK=1 跳过。';
|
|
31
|
+
if (process.env.ASD_STRICT_ENTRY === '1') {
|
|
32
|
+
console.error(msg);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
if (process.env.ASD_SKIP_ENTRY_CHECK !== '1') {
|
|
36
|
+
console.warn('⚠️ ' + msg);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 读取输入命令
|
|
41
|
+
const inquirer = require('inquirer');
|
|
42
|
+
// 命令行工具
|
|
43
|
+
const commander = require('commander');
|
|
44
|
+
// 全局路径:优先用 shell 传入的 ASD_CWD(asd 脚本里 $(pwd)),避免 dev:link / 符号链接等场景下 process.cwd() 与用户所在目录不一致
|
|
45
|
+
const CMD_PATH = process.env.ASD_CWD || process.cwd();
|
|
46
|
+
const pjson = require('../package.json');
|
|
47
|
+
const findPath = require('../lib/infrastructure/paths/PathFinder');
|
|
48
|
+
const install = require('../lib/snippet/snippetInstaller.js');
|
|
49
|
+
const create = require('./create-snippet.js');
|
|
50
|
+
const watch = require('../lib/watch/fileWatcher.js');
|
|
51
|
+
const cache = require('../lib/infrastructure/cache/CacheStore.js');
|
|
52
|
+
const ui = require('./dashboard-server.js');
|
|
53
|
+
const defaults = require('../lib/infrastructure/config/Defaults');
|
|
54
|
+
const spmDepMapUpdater = require('../lib/spm/spmDepMapUpdater.js');
|
|
55
|
+
const { execSync } = require('child_process');
|
|
56
|
+
const { createCliHelpers } = require('./cli-helpers');
|
|
57
|
+
const { registerCommands } = require('./cli-commands');
|
|
58
|
+
const helpers = createCliHelpers({
|
|
59
|
+
CMD_PATH,
|
|
60
|
+
findPath,
|
|
61
|
+
cache,
|
|
62
|
+
create,
|
|
63
|
+
inquirer,
|
|
64
|
+
defaults,
|
|
65
|
+
commander,
|
|
66
|
+
execSync,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
registerCommands(commander, {
|
|
70
|
+
pjson,
|
|
71
|
+
CMD_PATH,
|
|
72
|
+
findPath,
|
|
73
|
+
install,
|
|
74
|
+
create,
|
|
75
|
+
watch,
|
|
76
|
+
cache,
|
|
77
|
+
ui,
|
|
78
|
+
defaults,
|
|
79
|
+
spmDepMapUpdater,
|
|
80
|
+
helpers,
|
|
81
|
+
inquirer,
|
|
82
|
+
fs,
|
|
83
|
+
path,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
commander.parse(process.argv);
|