autosnippet 3.3.6 → 3.3.8
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 +1 -0
- package/dashboard/dist/assets/icons-BMNb0V6L.js +1 -0
- package/dashboard/dist/assets/index-DHJ1Dj7u.css +1 -0
- package/dashboard/dist/assets/index-DV8biUkH.js +112 -0
- package/dashboard/dist/index.html +3 -3
- package/dist/bin/cli.js +8 -4
- package/dist/lib/agent/AgentRuntime.d.ts +2 -2
- package/dist/lib/agent/AgentRuntime.js +26 -18
- package/dist/lib/agent/core/ChatAgentPrompts.js +57 -21
- package/dist/lib/agent/core/LoopContext.d.ts +1 -0
- package/dist/lib/agent/core/ToolExecutionPipeline.js +13 -0
- package/dist/lib/agent/domain/ChatAgentTasks.js +4 -0
- package/dist/lib/agent/forced-summary.js +7 -2
- package/dist/lib/agent/memory/ActiveContext.d.ts +0 -2
- package/dist/lib/agent/memory/ActiveContext.js +0 -2
- package/dist/lib/agent/memory/MemoryEmbeddingStore.d.ts +49 -0
- package/dist/lib/agent/memory/MemoryEmbeddingStore.js +159 -0
- package/dist/lib/agent/memory/MemoryRetriever.d.ts +2 -0
- package/dist/lib/agent/memory/MemoryRetriever.js +25 -11
- package/dist/lib/agent/memory/MemoryStore.d.ts +8 -41
- package/dist/lib/agent/memory/MemoryStore.js +196 -261
- package/dist/lib/agent/memory/PersistentMemory.d.ts +2 -0
- package/dist/lib/agent/memory/PersistentMemory.js +4 -5
- package/dist/lib/agent/memory/SessionStore.d.ts +0 -2
- package/dist/lib/agent/memory/SessionStore.js +0 -2
- package/dist/lib/agent/tools/ast-graph.js +21 -19
- package/dist/lib/agent/tools/infrastructure.js +3 -2
- package/dist/lib/agent/tools/project-access.d.ts +2 -2
- package/dist/lib/agent/tools/project-access.js +5 -4
- package/dist/lib/bootstrap.js +2 -1
- package/dist/lib/cli/AiScanService.js +8 -21
- package/dist/lib/cli/KnowledgeSyncService.d.ts +7 -37
- package/dist/lib/cli/KnowledgeSyncService.js +23 -51
- package/dist/lib/core/ast/ProjectGraph.js +5 -27
- package/dist/lib/core/discovery/ConfigWatcher.d.ts +64 -0
- package/dist/lib/core/discovery/ConfigWatcher.js +336 -0
- package/dist/lib/core/discovery/CustomConfigDiscoverer.d.ts +28 -0
- package/dist/lib/core/discovery/CustomConfigDiscoverer.js +1303 -0
- package/dist/lib/core/discovery/DiscovererPreference.d.ts +44 -0
- package/dist/lib/core/discovery/DiscovererPreference.js +141 -0
- package/dist/lib/core/discovery/DiscovererRegistry.d.ts +10 -1
- package/dist/lib/core/discovery/DiscovererRegistry.js +42 -2
- package/dist/lib/core/discovery/ProjectDiscoverer.d.ts +19 -0
- package/dist/lib/core/discovery/index.d.ts +2 -0
- package/dist/lib/core/discovery/index.js +4 -0
- package/dist/lib/core/discovery/parsers/CMakeParser.d.ts +32 -0
- package/dist/lib/core/discovery/parsers/CMakeParser.js +148 -0
- package/dist/lib/core/discovery/parsers/GradleDslParser.d.ts +43 -0
- package/dist/lib/core/discovery/parsers/GradleDslParser.js +171 -0
- package/dist/lib/core/discovery/parsers/JsonConfigParser.d.ts +45 -0
- package/dist/lib/core/discovery/parsers/JsonConfigParser.js +122 -0
- package/dist/lib/core/discovery/parsers/RubyDslParser.d.ts +49 -0
- package/dist/lib/core/discovery/parsers/RubyDslParser.js +282 -0
- package/dist/lib/core/discovery/parsers/StarlarkParser.d.ts +33 -0
- package/dist/lib/core/discovery/parsers/StarlarkParser.js +229 -0
- package/dist/lib/core/discovery/parsers/YamlConfigParser.d.ts +37 -0
- package/dist/lib/core/discovery/parsers/YamlConfigParser.js +212 -0
- package/dist/lib/domain/dimension/DimensionRegistry.d.ts +0 -2
- package/dist/lib/domain/dimension/DimensionRegistry.js +0 -2
- package/dist/lib/domain/dimension/DimensionSop.js +44 -33
- package/dist/lib/domain/dimension/UnifiedDimension.d.ts +0 -2
- package/dist/lib/domain/dimension/UnifiedDimension.js +0 -2
- package/dist/lib/domain/knowledge/KnowledgeEntry.d.ts +7 -1
- package/dist/lib/domain/knowledge/KnowledgeEntry.js +17 -3
- package/dist/lib/domain/knowledge/Lifecycle.d.ts +26 -0
- package/dist/lib/domain/knowledge/Lifecycle.js +42 -0
- package/dist/lib/domain/knowledge/index.d.ts +2 -1
- package/dist/lib/domain/knowledge/index.js +1 -1
- package/dist/lib/external/ai/AiProvider.d.ts +12 -0
- package/dist/lib/external/ai/AiProvider.js +24 -0
- package/dist/lib/external/ai/AiProviderManager.d.ts +101 -0
- package/dist/lib/external/ai/AiProviderManager.js +193 -0
- package/dist/lib/external/ai/providers/ClaudeProvider.js +11 -0
- package/dist/lib/external/ai/providers/GoogleGeminiProvider.js +18 -0
- package/dist/lib/external/ai/providers/MockProvider.d.ts +21 -3
- package/dist/lib/external/ai/providers/MockProvider.js +290 -14
- package/dist/lib/external/ai/providers/OpenAiProvider.js +16 -0
- package/dist/lib/external/lark/LarkTransport.d.ts +5 -1
- package/dist/lib/external/lark/LarkTransport.js +10 -2
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/BootstrapSnapshot.d.ts +2 -1
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/BootstrapSnapshot.js +102 -153
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/mock-pipeline.d.ts +20 -0
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/mock-pipeline.js +432 -0
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/orchestrator.js +49 -24
- package/dist/lib/external/mcp/handlers/bootstrap/refine.js +8 -0
- package/dist/lib/external/mcp/handlers/bootstrap/shared/bootstrap-phases.d.ts +1 -1
- package/dist/lib/external/mcp/handlers/bootstrap/shared/bootstrap-phases.js +41 -37
- package/dist/lib/external/mcp/handlers/bootstrap-external.d.ts +9 -0
- package/dist/lib/external/mcp/handlers/bootstrap-external.js +3 -1
- package/dist/lib/external/mcp/handlers/bootstrap-internal.js +2 -0
- package/dist/lib/external/mcp/handlers/consolidated.js +2 -1
- package/dist/lib/external/mcp/handlers/dimension-complete-external.js +9 -4
- package/dist/lib/external/mcp/handlers/evolve-external.d.ts +1 -0
- package/dist/lib/external/mcp/handlers/evolve-external.js +18 -18
- package/dist/lib/external/mcp/handlers/guard.js +15 -24
- package/dist/lib/external/mcp/handlers/knowledge.js +5 -4
- package/dist/lib/external/mcp/handlers/panorama.js +9 -9
- package/dist/lib/external/mcp/handlers/rescan-external.js +7 -6
- package/dist/lib/external/mcp/handlers/rescan-internal.js +9 -5
- package/dist/lib/external/mcp/handlers/search.js +3 -1
- package/dist/lib/external/mcp/handlers/skill.js +4 -4
- package/dist/lib/external/mcp/handlers/structure.js +8 -12
- package/dist/lib/external/mcp/handlers/system.js +10 -34
- package/dist/lib/http/routes/ai.js +109 -30
- package/dist/lib/http/routes/candidates.js +11 -4
- package/dist/lib/http/routes/commands.js +10 -1
- package/dist/lib/http/routes/guardReport.js +3 -5
- package/dist/lib/http/routes/health.js +11 -0
- package/dist/lib/http/routes/modules.js +27 -0
- package/dist/lib/http/routes/panorama.js +12 -12
- package/dist/lib/http/routes/recipes.js +66 -8
- package/dist/lib/http/routes/remote.js +3 -13
- package/dist/lib/http/routes/search.js +11 -8
- package/dist/lib/http/utils/routeHelpers.js +2 -1
- package/dist/lib/infrastructure/audit/AuditLogger.d.ts +20 -3
- package/dist/lib/infrastructure/audit/AuditStore.d.ts +28 -29
- package/dist/lib/infrastructure/audit/AuditStore.js +81 -88
- package/dist/lib/infrastructure/database/drizzle/schema.d.ts +180 -2
- package/dist/lib/infrastructure/database/drizzle/schema.js +23 -3
- package/dist/lib/injection/ServiceContainer.d.ts +6 -5
- package/dist/lib/injection/ServiceContainer.js +18 -31
- package/dist/lib/injection/ServiceMap.d.ts +22 -0
- package/dist/lib/injection/modules/AiModule.d.ts +6 -9
- package/dist/lib/injection/modules/AiModule.js +82 -39
- package/dist/lib/injection/modules/AppModule.js +2 -1
- package/dist/lib/injection/modules/GuardModule.js +5 -5
- package/dist/lib/injection/modules/InfraModule.js +60 -0
- package/dist/lib/injection/modules/KnowledgeModule.js +86 -51
- package/dist/lib/injection/modules/PanoramaModule.js +16 -10
- package/dist/lib/injection/modules/VectorModule.js +3 -0
- package/dist/lib/repository/audit/AuditRepository.d.ts +107 -0
- package/dist/lib/repository/audit/AuditRepository.js +272 -0
- package/dist/lib/repository/base/RepositoryBase.d.ts +46 -0
- package/dist/lib/repository/base/RepositoryBase.js +32 -0
- package/dist/lib/repository/bootstrap/BootstrapRepository.d.ts +94 -0
- package/dist/lib/repository/bootstrap/BootstrapRepository.js +246 -0
- package/dist/lib/repository/code/CodeEntityRepository.d.ts +91 -0
- package/dist/lib/repository/code/CodeEntityRepository.js +361 -0
- package/dist/lib/repository/delivery/DeliveryRepoAdapter.d.ts +39 -0
- package/dist/lib/repository/delivery/DeliveryRepoAdapter.js +23 -0
- package/dist/lib/repository/evolution/LifecycleEventRepository.d.ts +51 -0
- package/dist/lib/repository/evolution/LifecycleEventRepository.js +119 -0
- package/dist/lib/repository/evolution/ProposalRepository.d.ts +9 -12
- package/dist/lib/repository/evolution/ProposalRepository.js +114 -57
- package/dist/lib/repository/guard/GuardViolationRepository.d.ts +104 -0
- package/dist/lib/repository/guard/GuardViolationRepository.js +217 -0
- package/dist/lib/repository/knowledge/KnowledgeEdgeRepository.d.ts +129 -0
- package/dist/lib/repository/knowledge/KnowledgeEdgeRepository.js +475 -0
- package/dist/lib/repository/knowledge/KnowledgeFileStore.d.ts +39 -0
- package/dist/lib/repository/knowledge/KnowledgeFileStore.js +12 -0
- package/dist/lib/repository/knowledge/KnowledgeRepository.impl.d.ts +295 -11
- package/dist/lib/repository/knowledge/KnowledgeRepository.impl.js +608 -13
- package/dist/lib/repository/knowledge/KnowledgeUnitOfWork.d.ts +61 -0
- package/dist/lib/repository/knowledge/KnowledgeUnitOfWork.js +156 -0
- package/dist/lib/repository/memory/MemoryRepository.d.ts +90 -0
- package/dist/lib/repository/memory/MemoryRepository.js +260 -0
- package/dist/lib/repository/search/SearchRepoAdapter.d.ts +92 -0
- package/dist/lib/repository/search/SearchRepoAdapter.js +124 -0
- package/dist/lib/repository/session/SessionRepository.d.ts +46 -0
- package/dist/lib/repository/session/SessionRepository.js +110 -0
- package/dist/lib/repository/sourceref/RecipeSourceRefRepository.d.ts +66 -0
- package/dist/lib/repository/sourceref/RecipeSourceRefRepository.js +182 -0
- package/dist/lib/repository/sync/SyncRepoAdapter.d.ts +58 -0
- package/dist/lib/repository/sync/SyncRepoAdapter.js +58 -0
- package/dist/lib/service/bootstrap/UiStartupTasks.js +5 -6
- package/dist/lib/service/bootstrap/bootstrap-event-types.d.ts +0 -1
- package/dist/lib/service/bootstrap/bootstrap-event-types.js +0 -1
- package/dist/lib/service/cleanup/CleanupService.d.ts +54 -7
- package/dist/lib/service/cleanup/CleanupService.js +291 -40
- package/dist/lib/service/delivery/CursorDeliveryPipeline.js +6 -8
- package/dist/lib/service/evolution/ConsolidationAdvisor.d.ts +4 -9
- package/dist/lib/service/evolution/ConsolidationAdvisor.js +34 -70
- package/dist/lib/service/evolution/ContentPatcher.d.ts +4 -12
- package/dist/lib/service/evolution/ContentPatcher.js +48 -19
- package/dist/lib/service/evolution/ContradictionDetector.d.ts +3 -7
- package/dist/lib/service/evolution/ContradictionDetector.js +17 -24
- package/dist/lib/service/evolution/DecayDetector.d.ts +10 -9
- package/dist/lib/service/evolution/DecayDetector.js +63 -57
- package/dist/lib/service/evolution/EnhancementSuggester.d.ts +3 -9
- package/dist/lib/service/evolution/EnhancementSuggester.js +42 -86
- package/dist/lib/service/evolution/KnowledgeMetabolism.d.ts +4 -4
- package/dist/lib/service/evolution/KnowledgeMetabolism.js +102 -71
- package/dist/lib/service/evolution/ProposalExecutor.d.ts +5 -12
- package/dist/lib/service/evolution/ProposalExecutor.js +64 -69
- package/dist/lib/service/evolution/RecipeLifecycleSupervisor.d.ts +9 -14
- package/dist/lib/service/evolution/RecipeLifecycleSupervisor.js +94 -155
- package/dist/lib/service/evolution/RecipeRelevanceAuditor.d.ts +4 -1
- package/dist/lib/service/evolution/RecipeRelevanceAuditor.js +50 -49
- package/dist/lib/service/evolution/RedundancyAnalyzer.d.ts +3 -7
- package/dist/lib/service/evolution/RedundancyAnalyzer.js +15 -22
- package/dist/lib/service/evolution/StagingManager.d.ts +6 -15
- package/dist/lib/service/evolution/StagingManager.js +37 -95
- package/dist/lib/service/evolution/createSupersedeProposal.d.ts +1 -1
- package/dist/lib/service/evolution/createSupersedeProposal.js +7 -8
- package/dist/lib/service/guard/CoverageAnalyzer.d.ts +3 -7
- package/dist/lib/service/guard/CoverageAnalyzer.js +9 -11
- package/dist/lib/service/guard/GuardCheckEngine.d.ts +3 -0
- package/dist/lib/service/guard/GuardCheckEngine.js +14 -22
- package/dist/lib/service/guard/ReverseGuard.d.ts +4 -7
- package/dist/lib/service/guard/ReverseGuard.js +21 -31
- package/dist/lib/service/guard/ViolationsStore.d.ts +15 -21
- package/dist/lib/service/guard/ViolationsStore.js +75 -69
- package/dist/lib/service/knowledge/CodeEntityGraph.d.ts +45 -63
- package/dist/lib/service/knowledge/CodeEntityGraph.js +418 -496
- package/dist/lib/service/knowledge/ConfidenceRouter.js +18 -9
- package/dist/lib/service/knowledge/KnowledgeFileWriter.d.ts +2 -1
- package/dist/lib/service/knowledge/KnowledgeGraphService.d.ts +18 -60
- package/dist/lib/service/knowledge/KnowledgeGraphService.js +58 -109
- package/dist/lib/service/knowledge/KnowledgeService.d.ts +15 -1
- package/dist/lib/service/knowledge/KnowledgeService.js +97 -46
- package/dist/lib/service/knowledge/RecipeProductionGateway.d.ts +0 -2
- package/dist/lib/service/knowledge/RecipeProductionGateway.js +0 -2
- package/dist/lib/service/knowledge/SourceRefReconciler.d.ts +5 -13
- package/dist/lib/service/knowledge/SourceRefReconciler.js +58 -78
- package/dist/lib/service/module/ModuleService.js +10 -19
- package/dist/lib/service/panorama/CouplingAnalyzer.d.ts +14 -3
- package/dist/lib/service/panorama/CouplingAnalyzer.js +137 -32
- package/dist/lib/service/panorama/DimensionAnalyzer.d.ts +7 -4
- package/dist/lib/service/panorama/DimensionAnalyzer.js +94 -33
- package/dist/lib/service/panorama/LayerInferrer.d.ts +16 -1
- package/dist/lib/service/panorama/LayerInferrer.js +118 -1
- package/dist/lib/service/panorama/ModuleDiscoverer.d.ts +14 -4
- package/dist/lib/service/panorama/ModuleDiscoverer.js +209 -61
- package/dist/lib/service/panorama/PanoramaAggregator.d.ts +15 -4
- package/dist/lib/service/panorama/PanoramaAggregator.js +128 -62
- package/dist/lib/service/panorama/PanoramaScanner.d.ts +5 -1
- package/dist/lib/service/panorama/PanoramaScanner.js +60 -31
- package/dist/lib/service/panorama/PanoramaService.d.ts +11 -8
- package/dist/lib/service/panorama/PanoramaService.js +49 -69
- package/dist/lib/service/panorama/PanoramaTypes.d.ts +41 -0
- package/dist/lib/service/panorama/RoleRefiner.d.ts +10 -5
- package/dist/lib/service/panorama/RoleRefiner.js +92 -282
- package/dist/lib/service/panorama/TechStackProfiler.d.ts +13 -0
- package/dist/lib/service/panorama/TechStackProfiler.js +79 -0
- package/dist/lib/service/quality/QualityScorer.d.ts +45 -26
- package/dist/lib/service/quality/QualityScorer.js +157 -83
- package/dist/lib/service/search/SearchEngine.d.ts +1 -0
- package/dist/lib/service/search/SearchEngine.js +32 -37
- package/dist/lib/service/signal/HitRecorder.js +5 -5
- package/dist/lib/service/skills/RuleRecallStrategy.js +7 -3
- package/dist/lib/service/skills/SignalCollector.d.ts +6 -8
- package/dist/lib/service/skills/SignalCollector.js +34 -60
- package/dist/lib/service/skills/SkillAdvisor.d.ts +7 -13
- package/dist/lib/service/skills/SkillAdvisor.js +30 -79
- package/dist/lib/service/vector/ContextualEnricher.d.ts +1 -0
- package/dist/lib/service/vector/ContextualEnricher.js +4 -0
- package/dist/lib/service/vector/SyncCoordinator.d.ts +3 -1
- package/dist/lib/service/vector/SyncCoordinator.js +25 -3
- package/dist/lib/service/vector/VectorService.d.ts +2 -0
- package/dist/lib/service/vector/VectorService.js +3 -0
- package/dist/lib/service/wiki/WikiGenerator.js +1 -1
- package/dist/lib/shared/LanguageProfiles.d.ts +109 -0
- package/dist/lib/shared/LanguageProfiles.js +939 -0
- package/dist/lib/shared/LanguageService.d.ts +6 -0
- package/dist/lib/shared/LanguageService.js +19 -0
- package/dist/lib/shared/constants.d.ts +19 -19
- package/dist/lib/shared/constants.js +10 -10
- package/dist/lib/shared/developer-identity.d.ts +18 -0
- package/dist/lib/shared/developer-identity.js +62 -0
- package/dist/lib/shared/schemas/http-requests.d.ts +8 -17
- package/dist/lib/shared/schemas/http-requests.js +9 -6
- package/dist/lib/shared/schemas/mcp-tools.d.ts +1 -1
- package/dist/lib/types/knowledge-wire.d.ts +1 -0
- package/dist/lib/types/project-snapshot-builder.d.ts +0 -1
- package/dist/lib/types/project-snapshot-builder.js +0 -1
- package/dist/lib/types/project-snapshot.d.ts +0 -1
- package/dist/lib/types/project-snapshot.js +0 -1
- package/dist/lib/types/snapshot-views.d.ts +0 -2
- package/dist/lib/types/snapshot-views.js +0 -1
- package/package.json +2 -1
- package/dashboard/dist/assets/icons-D1aVZYFW.js +0 -1
- package/dashboard/dist/assets/index-CxHOu8Hd.css +0 -1
- package/dashboard/dist/assets/index-DDdAOpYT.js +0 -128
- package/dist/lib/repository/base/BaseRepository.d.ts +0 -53
- package/dist/lib/repository/base/BaseRepository.js +0 -226
|
@@ -276,6 +276,10 @@ export class LarkTransport {
|
|
|
276
276
|
}
|
|
277
277
|
/** 远程命令执行 — 使用 remote-exec preset(含 SafetyPolicy 命令白名单) */
|
|
278
278
|
async #handleRemoteExec(command, messageId, chatId, senderId, senderName) {
|
|
279
|
+
if (this.#agentFactory.getAiProviderInfo().name === 'mock') {
|
|
280
|
+
await this.#reply(messageId, '⚠️ AI 服务未配置,当前为 Mock 模式。请先配置 API Key。');
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
279
283
|
await this.#reply(messageId, `⚡ 正在执行: \`${command.slice(0, 60)}\`...`);
|
|
280
284
|
try {
|
|
281
285
|
const history = this.#getHistory(chatId);
|
|
@@ -316,6 +320,10 @@ export class LarkTransport {
|
|
|
316
320
|
}
|
|
317
321
|
/** Bot Agent 知识任务 — 服务端 AgentRuntime 直接处理 */
|
|
318
322
|
async #handleBotAgent(text, messageId, chatId, senderId, senderName) {
|
|
323
|
+
if (this.#agentFactory.getAiProviderInfo().name === 'mock') {
|
|
324
|
+
await this.#reply(messageId, '⚠️ AI 服务未配置,当前为 Mock 模式。请先配置 API Key。');
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
319
327
|
// 进度提示
|
|
320
328
|
await this.#reply(messageId, '🤔 正在思考...');
|
|
321
329
|
try {
|
|
@@ -453,8 +461,8 @@ export class LarkTransport {
|
|
|
453
461
|
const history = this.#conversationHistory.get(chatId);
|
|
454
462
|
history.push({ role, content });
|
|
455
463
|
// 限制内存历史长度
|
|
456
|
-
if (history
|
|
457
|
-
history
|
|
464
|
+
if (history?.length > _a.MAX_HISTORY * 2) {
|
|
465
|
+
history?.splice(0, history?.length - _a.MAX_HISTORY * 2);
|
|
458
466
|
}
|
|
459
467
|
}
|
|
460
468
|
// ═══════════════════════════════════════════════════
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* 4. 提供增量 diff 计算
|
|
9
9
|
*
|
|
10
10
|
* 存储: SQLite bootstrap_snapshots + bootstrap_dim_files 表
|
|
11
|
+
* 所有操作使用 Drizzle 类型安全 API。
|
|
11
12
|
*
|
|
12
13
|
* @module pipeline/BootstrapSnapshot
|
|
13
14
|
*/
|
|
@@ -90,7 +91,7 @@ interface AffectedDimensionResult {
|
|
|
90
91
|
}
|
|
91
92
|
export declare class BootstrapSnapshot {
|
|
92
93
|
#private;
|
|
93
|
-
/** @param db better-sqlite3 实例 */
|
|
94
|
+
/** @param db DatabaseConnection 或 better-sqlite3 实例 */
|
|
94
95
|
constructor(db: unknown, { logger }?: {
|
|
95
96
|
logger?: LoggerLike | null;
|
|
96
97
|
});
|
|
@@ -8,12 +8,16 @@
|
|
|
8
8
|
* 4. 提供增量 diff 计算
|
|
9
9
|
*
|
|
10
10
|
* 存储: SQLite bootstrap_snapshots + bootstrap_dim_files 表
|
|
11
|
+
* 所有操作使用 Drizzle 类型安全 API。
|
|
11
12
|
*
|
|
12
13
|
* @module pipeline/BootstrapSnapshot
|
|
13
14
|
*/
|
|
14
15
|
import { createHash, randomUUID } from 'node:crypto';
|
|
15
16
|
import { readFileSync } from 'node:fs';
|
|
16
17
|
import { relative } from 'node:path';
|
|
18
|
+
import { and, desc, eq, sql } from 'drizzle-orm';
|
|
19
|
+
import { getDrizzle } from '../../../../../infrastructure/database/drizzle/index.js';
|
|
20
|
+
import { bootstrapDimFiles, bootstrapSnapshots, } from '../../../../../infrastructure/database/drizzle/schema.js';
|
|
17
21
|
// ──────────────────────────────────────────────────────────────
|
|
18
22
|
// 常量
|
|
19
23
|
// ──────────────────────────────────────────────────────────────
|
|
@@ -25,21 +29,18 @@ const FULL_REBUILD_THRESHOLD = 0.5;
|
|
|
25
29
|
// BootstrapSnapshot 类
|
|
26
30
|
// ──────────────────────────────────────────────────────────────
|
|
27
31
|
export class BootstrapSnapshot {
|
|
28
|
-
#
|
|
32
|
+
#drizzle;
|
|
29
33
|
#logger;
|
|
30
|
-
|
|
31
|
-
/** @param db better-sqlite3 实例 */
|
|
34
|
+
/** @param db DatabaseConnection 或 better-sqlite3 实例 */
|
|
32
35
|
constructor(db, { logger } = {}) {
|
|
33
36
|
if (!db) {
|
|
34
37
|
throw new Error('BootstrapSnapshot requires a database instance');
|
|
35
38
|
}
|
|
36
|
-
this.#
|
|
37
|
-
typeof db?.
|
|
38
|
-
? db.
|
|
39
|
-
:
|
|
39
|
+
this.#drizzle =
|
|
40
|
+
typeof db?.getDrizzle === 'function'
|
|
41
|
+
? db.getDrizzle()
|
|
42
|
+
: getDrizzle();
|
|
40
43
|
this.#logger = logger || null;
|
|
41
|
-
this.#ensureTable();
|
|
42
|
-
this.#prepareStatements();
|
|
43
44
|
}
|
|
44
45
|
// ─── 快照保存 ─────────────────────────────────────────
|
|
45
46
|
/**
|
|
@@ -77,28 +78,30 @@ export class BootstrapSnapshot {
|
|
|
77
78
|
durationMs: stat.durationMs || 0,
|
|
78
79
|
};
|
|
79
80
|
}
|
|
80
|
-
//
|
|
81
|
-
|
|
81
|
+
// 事务保存(Drizzle 类型安全)
|
|
82
|
+
this.#drizzle.transaction((tx) => {
|
|
82
83
|
// 主记录
|
|
83
|
-
|
|
84
|
+
tx.insert(bootstrapSnapshots)
|
|
85
|
+
.values({
|
|
84
86
|
id,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
87
|
+
sessionId: sessionId || null,
|
|
88
|
+
projectRoot,
|
|
89
|
+
createdAt: now,
|
|
90
|
+
durationMs: meta.durationMs || 0,
|
|
91
|
+
fileCount: allFiles.length,
|
|
92
|
+
dimensionCount: Object.keys(dimensionStats || {}).length,
|
|
93
|
+
candidateCount: meta.candidateCount || 0,
|
|
94
|
+
primaryLang: meta.primaryLang || null,
|
|
95
|
+
fileHashes: JSON.stringify(fileHashes),
|
|
96
|
+
dimensionMeta: JSON.stringify(dimensionMeta),
|
|
97
|
+
episodicData: episodicData ? JSON.stringify(episodicData) : null,
|
|
98
|
+
isIncremental: isIncremental ? 1 : 0,
|
|
99
|
+
parentId: parentId,
|
|
100
|
+
changedFiles: JSON.stringify(changedFiles),
|
|
101
|
+
affectedDims: JSON.stringify(affectedDims),
|
|
100
102
|
status: 'complete',
|
|
101
|
-
})
|
|
103
|
+
})
|
|
104
|
+
.run();
|
|
102
105
|
// 维度-文件关联
|
|
103
106
|
for (const [dimId, stat] of Object.entries(dimensionStats || {})) {
|
|
104
107
|
const refFiles = stat.referencedFilesList || [];
|
|
@@ -108,18 +111,20 @@ export class BootstrapSnapshot {
|
|
|
108
111
|
? relative(projectRoot, filePath)
|
|
109
112
|
: filePath
|
|
110
113
|
: filePath;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
tx.insert(bootstrapDimFiles)
|
|
115
|
+
.values({
|
|
116
|
+
snapshotId: id,
|
|
117
|
+
dimId,
|
|
118
|
+
filePath: rel,
|
|
115
119
|
role: 'referenced',
|
|
116
|
-
})
|
|
120
|
+
})
|
|
121
|
+
.onConflictDoNothing()
|
|
122
|
+
.run();
|
|
117
123
|
}
|
|
118
124
|
}
|
|
119
125
|
// 容量控制: 保留最新 N 个
|
|
120
|
-
this.#enforceCapacity(projectRoot);
|
|
126
|
+
this.#enforceCapacity(projectRoot, tx);
|
|
121
127
|
});
|
|
122
|
-
saveTransaction();
|
|
123
128
|
this.#log(`Snapshot saved: ${id} (${allFiles.length} files, ${Object.keys(dimensionStats || {}).length} dims)`);
|
|
124
129
|
return id;
|
|
125
130
|
}
|
|
@@ -127,9 +132,13 @@ export class BootstrapSnapshot {
|
|
|
127
132
|
/** 清除项目的所有快照 — 用于手动重新冷启动时强制全量 */
|
|
128
133
|
clearProject(projectRoot) {
|
|
129
134
|
try {
|
|
130
|
-
const rows = this.#
|
|
135
|
+
const rows = this.#drizzle
|
|
136
|
+
.select({ id: bootstrapSnapshots.id })
|
|
137
|
+
.from(bootstrapSnapshots)
|
|
138
|
+
.where(eq(bootstrapSnapshots.projectRoot, projectRoot))
|
|
139
|
+
.all();
|
|
131
140
|
for (const row of rows) {
|
|
132
|
-
this.#
|
|
141
|
+
this.#drizzle.delete(bootstrapSnapshots).where(eq(bootstrapSnapshots.id, row.id)).run();
|
|
133
142
|
}
|
|
134
143
|
this.#log(`Cleared ${rows.length} snapshots for project`);
|
|
135
144
|
}
|
|
@@ -144,7 +153,13 @@ export class BootstrapSnapshot {
|
|
|
144
153
|
* @returns 快照数据
|
|
145
154
|
*/
|
|
146
155
|
getLatest(projectRoot) {
|
|
147
|
-
const row = this.#
|
|
156
|
+
const row = this.#drizzle
|
|
157
|
+
.select()
|
|
158
|
+
.from(bootstrapSnapshots)
|
|
159
|
+
.where(and(eq(bootstrapSnapshots.projectRoot, projectRoot), eq(bootstrapSnapshots.status, 'complete')))
|
|
160
|
+
.orderBy(desc(bootstrapSnapshots.createdAt))
|
|
161
|
+
.limit(1)
|
|
162
|
+
.get();
|
|
148
163
|
if (!row) {
|
|
149
164
|
return null;
|
|
150
165
|
}
|
|
@@ -152,7 +167,11 @@ export class BootstrapSnapshot {
|
|
|
152
167
|
}
|
|
153
168
|
/** 根据 ID 加载快照 */
|
|
154
169
|
getById(id) {
|
|
155
|
-
const row = this.#
|
|
170
|
+
const row = this.#drizzle
|
|
171
|
+
.select()
|
|
172
|
+
.from(bootstrapSnapshots)
|
|
173
|
+
.where(eq(bootstrapSnapshots.id, id))
|
|
174
|
+
.get();
|
|
156
175
|
if (!row) {
|
|
157
176
|
return null;
|
|
158
177
|
}
|
|
@@ -160,8 +179,13 @@ export class BootstrapSnapshot {
|
|
|
160
179
|
}
|
|
161
180
|
/** 获取项目的所有快照 (按时间降序) */
|
|
162
181
|
list(projectRoot, limit = 10) {
|
|
163
|
-
return this.#
|
|
164
|
-
.
|
|
182
|
+
return this.#drizzle
|
|
183
|
+
.select()
|
|
184
|
+
.from(bootstrapSnapshots)
|
|
185
|
+
.where(eq(bootstrapSnapshots.projectRoot, projectRoot))
|
|
186
|
+
.orderBy(desc(bootstrapSnapshots.createdAt))
|
|
187
|
+
.limit(limit)
|
|
188
|
+
.all()
|
|
165
189
|
.map((r) => this.#deserialize(r));
|
|
166
190
|
}
|
|
167
191
|
// ─── 增量 Diff 计算 ──────────────────────────────────
|
|
@@ -277,13 +301,20 @@ export class BootstrapSnapshot {
|
|
|
277
301
|
// ─── 维度-文件映射查询 ──────────────────────────────
|
|
278
302
|
/** 获取某个快照中每个维度引用的文件集合 */
|
|
279
303
|
#getDimFileMap(snapshotId) {
|
|
280
|
-
const rows = this.#
|
|
304
|
+
const rows = this.#drizzle
|
|
305
|
+
.select({
|
|
306
|
+
dimId: bootstrapDimFiles.dimId,
|
|
307
|
+
filePath: bootstrapDimFiles.filePath,
|
|
308
|
+
})
|
|
309
|
+
.from(bootstrapDimFiles)
|
|
310
|
+
.where(eq(bootstrapDimFiles.snapshotId, snapshotId))
|
|
311
|
+
.all();
|
|
281
312
|
const map = {};
|
|
282
313
|
for (const row of rows) {
|
|
283
|
-
if (!map[row.
|
|
284
|
-
map[row.
|
|
314
|
+
if (!map[row.dimId]) {
|
|
315
|
+
map[row.dimId] = new Set();
|
|
285
316
|
}
|
|
286
|
-
map[row.
|
|
317
|
+
map[row.dimId].add(row.filePath);
|
|
287
318
|
}
|
|
288
319
|
return map;
|
|
289
320
|
}
|
|
@@ -367,9 +398,17 @@ export class BootstrapSnapshot {
|
|
|
367
398
|
return '';
|
|
368
399
|
}
|
|
369
400
|
}
|
|
370
|
-
#enforceCapacity(projectRoot) {
|
|
401
|
+
#enforceCapacity(projectRoot, db = this.#drizzle) {
|
|
371
402
|
try {
|
|
372
|
-
|
|
403
|
+
db.delete(bootstrapSnapshots)
|
|
404
|
+
.where(sql `${bootstrapSnapshots.projectRoot} = ${projectRoot}
|
|
405
|
+
AND ${bootstrapSnapshots.id} NOT IN (
|
|
406
|
+
SELECT ${bootstrapSnapshots.id} FROM ${bootstrapSnapshots}
|
|
407
|
+
WHERE ${bootstrapSnapshots.projectRoot} = ${projectRoot}
|
|
408
|
+
ORDER BY ${bootstrapSnapshots.createdAt} DESC
|
|
409
|
+
LIMIT ${MAX_SNAPSHOTS}
|
|
410
|
+
)`)
|
|
411
|
+
.run();
|
|
373
412
|
}
|
|
374
413
|
catch (err) {
|
|
375
414
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -379,22 +418,22 @@ export class BootstrapSnapshot {
|
|
|
379
418
|
#deserialize(row) {
|
|
380
419
|
return {
|
|
381
420
|
id: row.id,
|
|
382
|
-
sessionId: row.
|
|
383
|
-
projectRoot: row.
|
|
384
|
-
createdAt: row.
|
|
385
|
-
durationMs: row.
|
|
386
|
-
fileCount: row.
|
|
387
|
-
dimensionCount: row.
|
|
388
|
-
candidateCount: row.
|
|
389
|
-
primaryLang: row.
|
|
390
|
-
fileHashes: this.#safeParseJSON(row.
|
|
391
|
-
dimensionMeta: this.#safeParseJSON(row.
|
|
392
|
-
episodicData: this.#safeParseJSON(row.
|
|
393
|
-
isIncremental: !!row.
|
|
394
|
-
parentId: row.
|
|
395
|
-
changedFiles: this.#safeParseJSON(row.
|
|
396
|
-
affectedDims: this.#safeParseJSON(row.
|
|
397
|
-
status: row.status,
|
|
421
|
+
sessionId: row.sessionId ?? null,
|
|
422
|
+
projectRoot: row.projectRoot,
|
|
423
|
+
createdAt: row.createdAt,
|
|
424
|
+
durationMs: row.durationMs ?? 0,
|
|
425
|
+
fileCount: row.fileCount ?? 0,
|
|
426
|
+
dimensionCount: row.dimensionCount ?? 0,
|
|
427
|
+
candidateCount: row.candidateCount ?? 0,
|
|
428
|
+
primaryLang: row.primaryLang ?? null,
|
|
429
|
+
fileHashes: this.#safeParseJSON(row.fileHashes, {}),
|
|
430
|
+
dimensionMeta: this.#safeParseJSON(row.dimensionMeta, {}),
|
|
431
|
+
episodicData: this.#safeParseJSON(row.episodicData, null),
|
|
432
|
+
isIncremental: !!row.isIncremental,
|
|
433
|
+
parentId: row.parentId ?? null,
|
|
434
|
+
changedFiles: this.#safeParseJSON(row.changedFiles, []),
|
|
435
|
+
affectedDims: this.#safeParseJSON(row.affectedDims, []),
|
|
436
|
+
status: row.status ?? 'complete',
|
|
398
437
|
};
|
|
399
438
|
}
|
|
400
439
|
#safeParseJSON(str, fallback) {
|
|
@@ -410,95 +449,5 @@ export class BootstrapSnapshot {
|
|
|
410
449
|
this.#logger[level](`[BootstrapSnapshot] ${msg}`);
|
|
411
450
|
}
|
|
412
451
|
}
|
|
413
|
-
// ─── 初始化 ───────────────────────────────────────────
|
|
414
|
-
#ensureTable() {
|
|
415
|
-
this.#db.exec(`
|
|
416
|
-
CREATE TABLE IF NOT EXISTS bootstrap_snapshots (
|
|
417
|
-
id TEXT PRIMARY KEY,
|
|
418
|
-
session_id TEXT,
|
|
419
|
-
project_root TEXT NOT NULL,
|
|
420
|
-
created_at TEXT NOT NULL,
|
|
421
|
-
duration_ms INTEGER DEFAULT 0,
|
|
422
|
-
file_count INTEGER DEFAULT 0,
|
|
423
|
-
dimension_count INTEGER DEFAULT 0,
|
|
424
|
-
candidate_count INTEGER DEFAULT 0,
|
|
425
|
-
primary_lang TEXT,
|
|
426
|
-
file_hashes TEXT NOT NULL DEFAULT '{}',
|
|
427
|
-
dimension_meta TEXT NOT NULL DEFAULT '{}',
|
|
428
|
-
episodic_data TEXT,
|
|
429
|
-
is_incremental INTEGER DEFAULT 0,
|
|
430
|
-
parent_id TEXT,
|
|
431
|
-
changed_files TEXT DEFAULT '[]',
|
|
432
|
-
affected_dims TEXT DEFAULT '[]',
|
|
433
|
-
status TEXT DEFAULT 'complete'
|
|
434
|
-
);
|
|
435
|
-
|
|
436
|
-
CREATE TABLE IF NOT EXISTS bootstrap_dim_files (
|
|
437
|
-
snapshot_id TEXT NOT NULL,
|
|
438
|
-
dim_id TEXT NOT NULL,
|
|
439
|
-
file_path TEXT NOT NULL,
|
|
440
|
-
role TEXT DEFAULT 'referenced',
|
|
441
|
-
PRIMARY KEY (snapshot_id, dim_id, file_path),
|
|
442
|
-
FOREIGN KEY (snapshot_id) REFERENCES bootstrap_snapshots(id) ON DELETE CASCADE
|
|
443
|
-
);
|
|
444
|
-
|
|
445
|
-
CREATE INDEX IF NOT EXISTS idx_snapshots_project
|
|
446
|
-
ON bootstrap_snapshots(project_root, created_at DESC);
|
|
447
|
-
CREATE INDEX IF NOT EXISTS idx_dim_files_file
|
|
448
|
-
ON bootstrap_dim_files(file_path);
|
|
449
|
-
`);
|
|
450
|
-
}
|
|
451
|
-
#prepareStatements() {
|
|
452
|
-
this.#stmts = {
|
|
453
|
-
insertSnapshot: this.#db.prepare(`
|
|
454
|
-
INSERT INTO bootstrap_snapshots
|
|
455
|
-
(id, session_id, project_root, created_at, duration_ms,
|
|
456
|
-
file_count, dimension_count, candidate_count, primary_lang,
|
|
457
|
-
file_hashes, dimension_meta, episodic_data,
|
|
458
|
-
is_incremental, parent_id, changed_files, affected_dims, status)
|
|
459
|
-
VALUES
|
|
460
|
-
(@id, @session_id, @project_root, @created_at, @duration_ms,
|
|
461
|
-
@file_count, @dimension_count, @candidate_count, @primary_lang,
|
|
462
|
-
@file_hashes, @dimension_meta, @episodic_data,
|
|
463
|
-
@is_incremental, @parent_id, @changed_files, @affected_dims, @status)
|
|
464
|
-
`),
|
|
465
|
-
insertDimFile: this.#db.prepare(`
|
|
466
|
-
INSERT OR IGNORE INTO bootstrap_dim_files (snapshot_id, dim_id, file_path, role)
|
|
467
|
-
VALUES (@snapshot_id, @dim_id, @file_path, @role)
|
|
468
|
-
`),
|
|
469
|
-
getLatest: this.#db.prepare(`
|
|
470
|
-
SELECT * FROM bootstrap_snapshots
|
|
471
|
-
WHERE project_root = ? AND status = 'complete'
|
|
472
|
-
ORDER BY created_at DESC
|
|
473
|
-
LIMIT 1
|
|
474
|
-
`),
|
|
475
|
-
getById: this.#db.prepare(`
|
|
476
|
-
SELECT * FROM bootstrap_snapshots WHERE id = ?
|
|
477
|
-
`),
|
|
478
|
-
listByProject: this.#db.prepare(`
|
|
479
|
-
SELECT * FROM bootstrap_snapshots
|
|
480
|
-
WHERE project_root = ?
|
|
481
|
-
ORDER BY created_at DESC
|
|
482
|
-
LIMIT ?
|
|
483
|
-
`),
|
|
484
|
-
getDimFiles: this.#db.prepare(`
|
|
485
|
-
SELECT dim_id, file_path FROM bootstrap_dim_files
|
|
486
|
-
WHERE snapshot_id = ?
|
|
487
|
-
`),
|
|
488
|
-
enforceCapacity: this.#db.prepare(`
|
|
489
|
-
DELETE FROM bootstrap_snapshots
|
|
490
|
-
WHERE project_root = ?
|
|
491
|
-
AND id NOT IN (
|
|
492
|
-
SELECT id FROM bootstrap_snapshots
|
|
493
|
-
WHERE project_root = ?
|
|
494
|
-
ORDER BY created_at DESC
|
|
495
|
-
LIMIT ?
|
|
496
|
-
)
|
|
497
|
-
`),
|
|
498
|
-
deleteById: this.#db.prepare(`
|
|
499
|
-
DELETE FROM bootstrap_snapshots WHERE id = ?
|
|
500
|
-
`),
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
452
|
}
|
|
504
453
|
export default BootstrapSnapshot;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mock-pipeline.ts — Mock AI Bootstrap 轻量管线
|
|
3
|
+
*
|
|
4
|
+
* 当 AI Provider 为 mock 时,利用 Phase 1-4 已收集的真实数据
|
|
5
|
+
* (AST、依赖图、文件列表、Panorama) 为每个维度生成模板化候选知识。
|
|
6
|
+
*
|
|
7
|
+
* 不调用 AI,但走完完整的 submit → dimension_complete 流程,
|
|
8
|
+
* 使 Dashboard 能正常展示知识库、健康雷达等 UI。
|
|
9
|
+
*
|
|
10
|
+
* @module pipeline/mock-pipeline
|
|
11
|
+
*/
|
|
12
|
+
import type { DimensionDef } from '#types/project-snapshot.js';
|
|
13
|
+
import type { PipelineFillView } from '#types/snapshot-views.js';
|
|
14
|
+
/**
|
|
15
|
+
* fillDimensionsMock — Mock AI 轻量管线
|
|
16
|
+
*
|
|
17
|
+
* 利用 Phase 1-4 的真实数据(AST、文件列表、Panorama)自动生成候选知识,
|
|
18
|
+
* 不调用任何 AI API,但走完 submit → dimension_complete 的完整流程。
|
|
19
|
+
*/
|
|
20
|
+
export declare function fillDimensionsMock(view: PipelineFillView, dimensions: DimensionDef[]): Promise<void>;
|