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
|
@@ -49,7 +49,8 @@ const MAX_INTERVAL_MS = 24 * 60 * 60 * 1000; // 最长 24 小时
|
|
|
49
49
|
const SNAPSHOT_FILE = 'signal-snapshot.json';
|
|
50
50
|
export class SignalCollector {
|
|
51
51
|
#projectRoot;
|
|
52
|
-
#
|
|
52
|
+
#knowledgeRepo;
|
|
53
|
+
#auditRepo;
|
|
53
54
|
#agentFactory;
|
|
54
55
|
#container;
|
|
55
56
|
#mode;
|
|
@@ -74,9 +75,10 @@ export class SignalCollector {
|
|
|
74
75
|
* @param [opts.intervalMs] 初始收集间隔(毫秒),后续由 AI 动态调整
|
|
75
76
|
* @param [opts.onSuggestions] 新建议回调 (suggestions[]) => void
|
|
76
77
|
*/
|
|
77
|
-
constructor({ projectRoot,
|
|
78
|
+
constructor({ projectRoot, knowledgeRepo = null, auditRepo = null, agentFactory = null, container = null, signalBus = null, mode = 'auto', intervalMs = DEFAULT_INTERVAL_MS, onSuggestions = null, }) {
|
|
78
79
|
this.#projectRoot = projectRoot;
|
|
79
|
-
this.#
|
|
80
|
+
this.#knowledgeRepo = knowledgeRepo;
|
|
81
|
+
this.#auditRepo = auditRepo;
|
|
80
82
|
this.#agentFactory = agentFactory;
|
|
81
83
|
this.#container = container;
|
|
82
84
|
this.#mode = ['off', 'suggest', 'auto'].includes(mode) ? mode : 'auto';
|
|
@@ -112,8 +114,8 @@ export class SignalCollector {
|
|
|
112
114
|
this.#logger.info('[SignalCollector] mode=off, skipping start');
|
|
113
115
|
return;
|
|
114
116
|
}
|
|
115
|
-
const
|
|
116
|
-
if (
|
|
117
|
+
const manager = this.#container?.singletons?._aiProviderManager;
|
|
118
|
+
if (manager?.isMock) {
|
|
117
119
|
this.#logger.info('[SignalCollector] no AI provider available, starting in rule-fallback mode');
|
|
118
120
|
}
|
|
119
121
|
if (this.#timer) {
|
|
@@ -209,24 +211,25 @@ export class SignalCollector {
|
|
|
209
211
|
try {
|
|
210
212
|
// 1. 多维度收集信号
|
|
211
213
|
const signals = {
|
|
212
|
-
guard: this.#collectGuardSignals(),
|
|
214
|
+
guard: await this.#collectGuardSignals(),
|
|
213
215
|
memory: this.#collectMemorySignals(),
|
|
214
|
-
recipes: this.#collectRecipeSignals(),
|
|
215
|
-
candidates: this.#collectCandidateSignals(),
|
|
216
|
-
actions: this.#collectRecentActions(),
|
|
216
|
+
recipes: await this.#collectRecipeSignals(),
|
|
217
|
+
candidates: await this.#collectCandidateSignals(),
|
|
218
|
+
actions: await this.#collectRecentActions(),
|
|
217
219
|
codeChanges: this.#collectCodeChangeSignals(),
|
|
218
220
|
};
|
|
219
221
|
// ── 离线 Fallback: 当 AI 不可用时,降级到 SkillAdvisor 规则引擎 ──
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
+
const isMock = this.#container?.singletons?._aiProviderManager
|
|
223
|
+
?.isMock ?? true;
|
|
224
|
+
if (!this.#agentFactory || isMock) {
|
|
222
225
|
this.#logger.info('[SignalCollector] AI unavailable, falling back to rule-based analysis');
|
|
223
|
-
return this.#ruleFallback();
|
|
226
|
+
return await this.#ruleFallback();
|
|
224
227
|
}
|
|
225
228
|
// 2. 构造分析 prompt
|
|
226
229
|
const prompt = this.#buildAnalysisPrompt(signals);
|
|
227
230
|
// 3. 调用 Agent 系统进行 AI 分析
|
|
228
231
|
this.#logger.debug('[SignalCollector] invoking Agent for analysis...');
|
|
229
|
-
const agent = this.#agentFactory
|
|
232
|
+
const agent = this.#agentFactory?.createChat({ lang: 'en' });
|
|
230
233
|
const { AgentMessage } = await import('#agent/AgentMessage.js');
|
|
231
234
|
const message = AgentMessage.internal(prompt, { source: 'signal_collector' });
|
|
232
235
|
const result = await agent.execute(message);
|
|
@@ -329,10 +332,13 @@ export class SignalCollector {
|
|
|
329
332
|
*
|
|
330
333
|
* 零延迟、零 token 消耗 — 确保推荐系统始终有输出
|
|
331
334
|
*/
|
|
332
|
-
#ruleFallback() {
|
|
335
|
+
async #ruleFallback() {
|
|
333
336
|
try {
|
|
334
|
-
const advisor = new SkillAdvisor(this.#projectRoot, {
|
|
335
|
-
|
|
337
|
+
const advisor = new SkillAdvisor(this.#projectRoot, {
|
|
338
|
+
knowledgeRepo: this.#knowledgeRepo,
|
|
339
|
+
auditRepo: this.#auditRepo,
|
|
340
|
+
});
|
|
341
|
+
const result = await advisor.suggest();
|
|
336
342
|
const newSuggestions = result.suggestions.filter((s) => !this.#snapshot.pushedNames.includes(s.name));
|
|
337
343
|
// 更新快照
|
|
338
344
|
this.#snapshot.lastRun = new Date().toISOString();
|
|
@@ -388,23 +394,12 @@ export class SignalCollector {
|
|
|
388
394
|
// ═══════════════════════════════════════════════════════
|
|
389
395
|
// 信号收集器(6 维度)
|
|
390
396
|
// ═══════════════════════════════════════════════════════
|
|
391
|
-
#collectGuardSignals() {
|
|
397
|
+
async #collectGuardSignals() {
|
|
392
398
|
try {
|
|
393
|
-
if (!this.#
|
|
399
|
+
if (!this.#auditRepo) {
|
|
394
400
|
return [];
|
|
395
401
|
}
|
|
396
|
-
|
|
397
|
-
const rows = this.#db
|
|
398
|
-
.prepare(`SELECT json_extract(operation_data, '$.ruleName') as ruleName,
|
|
399
|
-
COUNT(*) as cnt,
|
|
400
|
-
MAX(timestamp) as last_at
|
|
401
|
-
FROM audit_logs
|
|
402
|
-
WHERE action LIKE 'guard%'
|
|
403
|
-
AND result = 'violation'
|
|
404
|
-
GROUP BY ruleName
|
|
405
|
-
HAVING cnt > 0
|
|
406
|
-
ORDER BY cnt DESC LIMIT 20`)
|
|
407
|
-
.all();
|
|
402
|
+
const rows = await this.#auditRepo.findGuardViolationSignals(20);
|
|
408
403
|
return rows;
|
|
409
404
|
}
|
|
410
405
|
catch {
|
|
@@ -434,61 +429,40 @@ export class SignalCollector {
|
|
|
434
429
|
return [];
|
|
435
430
|
}
|
|
436
431
|
}
|
|
437
|
-
#collectRecipeSignals() {
|
|
432
|
+
async #collectRecipeSignals() {
|
|
438
433
|
try {
|
|
439
|
-
if (!this.#
|
|
434
|
+
if (!this.#knowledgeRepo) {
|
|
440
435
|
return [];
|
|
441
436
|
}
|
|
442
|
-
|
|
443
|
-
const rows = this.#db
|
|
444
|
-
.prepare(`SELECT id, title, knowledgeType, category, language,
|
|
445
|
-
json_extract(stats, '$.adoptions') as adoption_count,
|
|
446
|
-
json_extract(stats, '$.applications') as application_count,
|
|
447
|
-
json_extract(quality, '$.overall') as quality_overall,
|
|
448
|
-
updatedAt
|
|
449
|
-
FROM knowledge_entries
|
|
450
|
-
WHERE lifecycle = 'active'
|
|
451
|
-
ORDER BY updatedAt DESC LIMIT 30`)
|
|
452
|
-
.all();
|
|
437
|
+
const rows = await this.#knowledgeRepo.findActiveRecipeSignals(30);
|
|
453
438
|
return rows;
|
|
454
439
|
}
|
|
455
440
|
catch {
|
|
456
441
|
return [];
|
|
457
442
|
}
|
|
458
443
|
}
|
|
459
|
-
#collectCandidateSignals() {
|
|
444
|
+
async #collectCandidateSignals() {
|
|
460
445
|
try {
|
|
461
|
-
if (!this.#
|
|
446
|
+
if (!this.#knowledgeRepo) {
|
|
462
447
|
return [];
|
|
463
448
|
}
|
|
464
|
-
|
|
465
|
-
const rows = this.#db
|
|
466
|
-
.prepare(`SELECT id, source, lifecycle as status, language, category,
|
|
467
|
-
title, createdAt
|
|
468
|
-
FROM knowledge_entries WHERE lifecycle = 'pending'
|
|
469
|
-
ORDER BY createdAt DESC LIMIT 30`)
|
|
470
|
-
.all();
|
|
449
|
+
const rows = await this.#knowledgeRepo.findPendingCandidates(30);
|
|
471
450
|
return rows;
|
|
472
451
|
}
|
|
473
452
|
catch {
|
|
474
453
|
return [];
|
|
475
454
|
}
|
|
476
455
|
}
|
|
477
|
-
#collectRecentActions() {
|
|
456
|
+
async #collectRecentActions() {
|
|
478
457
|
try {
|
|
479
|
-
if (!this.#
|
|
458
|
+
if (!this.#auditRepo) {
|
|
480
459
|
return [];
|
|
481
460
|
}
|
|
482
|
-
// audit_logs.timestamp 是 INTEGER (epoch seconds)
|
|
483
461
|
const sinceStr = this.#snapshot.lastRun;
|
|
484
462
|
const sinceTs = sinceStr
|
|
485
463
|
? Math.floor(new Date(sinceStr).getTime() / 1000)
|
|
486
464
|
: Math.floor((Date.now() - 24 * 3600 * 1000) / 1000);
|
|
487
|
-
const rows = this.#
|
|
488
|
-
.prepare(`SELECT actor, action, resource, result, timestamp
|
|
489
|
-
FROM audit_logs WHERE timestamp > ?
|
|
490
|
-
ORDER BY timestamp DESC LIMIT 50`)
|
|
491
|
-
.all(sinceTs);
|
|
465
|
+
const rows = await this.#auditRepo.findRecentActions(sinceTs, 50);
|
|
492
466
|
return rows;
|
|
493
467
|
}
|
|
494
468
|
catch {
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
* - 推荐结果包含 draft 草稿(name + description + rationale),
|
|
15
15
|
* Agent 可直接调用 create_skill 创建
|
|
16
16
|
*/
|
|
17
|
+
import type { AuditRepositoryImpl } from '../../repository/audit/AuditRepository.js';
|
|
18
|
+
import type { KnowledgeRepositoryImpl } from '../../repository/knowledge/KnowledgeRepository.impl.js';
|
|
17
19
|
export interface SkillSuggestion {
|
|
18
20
|
name: string;
|
|
19
21
|
description: string;
|
|
@@ -23,20 +25,12 @@ export interface SkillSuggestion {
|
|
|
23
25
|
signals: Record<string, unknown>;
|
|
24
26
|
}
|
|
25
27
|
interface SkillAdvisorOpts {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
all(...args: unknown[]): Record<string, unknown>[];
|
|
29
|
-
get(...args: unknown[]): Record<string, unknown> | undefined;
|
|
30
|
-
};
|
|
31
|
-
} | null;
|
|
28
|
+
knowledgeRepo?: KnowledgeRepositoryImpl | null;
|
|
29
|
+
auditRepo?: AuditRepositoryImpl | null;
|
|
32
30
|
}
|
|
33
31
|
export declare class SkillAdvisor {
|
|
34
32
|
#private;
|
|
35
|
-
|
|
36
|
-
* @param projectRoot 用户项目根目录
|
|
37
|
-
* @param [opts.database] better-sqlite3 实例(可选)
|
|
38
|
-
*/
|
|
39
|
-
constructor(projectRoot: string, { database }?: SkillAdvisorOpts);
|
|
33
|
+
constructor(projectRoot: string, { knowledgeRepo, auditRepo }?: SkillAdvisorOpts);
|
|
40
34
|
/**
|
|
41
35
|
* 生成 Skill 推荐列表
|
|
42
36
|
*
|
|
@@ -52,11 +46,11 @@ export declare class SkillAdvisor {
|
|
|
52
46
|
* analysisContext: object
|
|
53
47
|
* }}
|
|
54
48
|
*/
|
|
55
|
-
suggest(): {
|
|
49
|
+
suggest(): Promise<{
|
|
56
50
|
suggestions: SkillSuggestion[];
|
|
57
51
|
existingProjectSkills: unknown[];
|
|
58
52
|
analysisContext: Record<string, unknown>;
|
|
59
53
|
hint: string;
|
|
60
|
-
}
|
|
54
|
+
}>;
|
|
61
55
|
}
|
|
62
56
|
export default SkillAdvisor;
|
|
@@ -19,14 +19,12 @@ import path from 'node:path';
|
|
|
19
19
|
import { getProjectSkillsPath } from '../../infrastructure/config/Paths.js';
|
|
20
20
|
export class SkillAdvisor {
|
|
21
21
|
#projectRoot;
|
|
22
|
-
#
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* @param [opts.database] better-sqlite3 实例(可选)
|
|
26
|
-
*/
|
|
27
|
-
constructor(projectRoot, { database } = {}) {
|
|
22
|
+
#knowledgeRepo;
|
|
23
|
+
#auditRepo;
|
|
24
|
+
constructor(projectRoot, { knowledgeRepo, auditRepo } = {}) {
|
|
28
25
|
this.#projectRoot = projectRoot;
|
|
29
|
-
this.#
|
|
26
|
+
this.#knowledgeRepo = knowledgeRepo || null;
|
|
27
|
+
this.#auditRepo = auditRepo || null;
|
|
30
28
|
}
|
|
31
29
|
/**
|
|
32
30
|
* 生成 Skill 推荐列表
|
|
@@ -43,13 +41,13 @@ export class SkillAdvisor {
|
|
|
43
41
|
* analysisContext: object
|
|
44
42
|
* }}
|
|
45
43
|
*/
|
|
46
|
-
suggest() {
|
|
44
|
+
async suggest() {
|
|
47
45
|
const existingSkills = this.#listExistingProjectSkills();
|
|
48
46
|
const suggestions = [];
|
|
49
47
|
const analysisContext = {};
|
|
50
48
|
// ── 维度 1: Guard 违规模式 ──
|
|
51
49
|
try {
|
|
52
|
-
const guardInsights = this.#analyzeGuardPatterns();
|
|
50
|
+
const guardInsights = await this.#analyzeGuardPatterns();
|
|
53
51
|
analysisContext.guard = guardInsights.summary;
|
|
54
52
|
suggestions.push(...guardInsights.suggestions.filter((s) => !existingSkills.has(s.name)));
|
|
55
53
|
}
|
|
@@ -67,7 +65,7 @@ export class SkillAdvisor {
|
|
|
67
65
|
}
|
|
68
66
|
// ── 维度 3: Recipe 分布与使用 ──
|
|
69
67
|
try {
|
|
70
|
-
const recipeInsights = this.#analyzeRecipePatterns();
|
|
68
|
+
const recipeInsights = await this.#analyzeRecipePatterns();
|
|
71
69
|
analysisContext.recipes = recipeInsights.summary;
|
|
72
70
|
suggestions.push(...recipeInsights.suggestions.filter((s) => !existingSkills.has(s.name)));
|
|
73
71
|
}
|
|
@@ -76,7 +74,7 @@ export class SkillAdvisor {
|
|
|
76
74
|
}
|
|
77
75
|
// ── 维度 4: 候选积压 ──
|
|
78
76
|
try {
|
|
79
|
-
const candidateInsights = this.#analyzeCandidatePatterns();
|
|
77
|
+
const candidateInsights = await this.#analyzeCandidatePatterns();
|
|
80
78
|
analysisContext.candidates = candidateInsights.summary;
|
|
81
79
|
suggestions.push(...candidateInsights.suggestions.filter((s) => !existingSkills.has(s.name)));
|
|
82
80
|
}
|
|
@@ -99,26 +97,13 @@ export class SkillAdvisor {
|
|
|
99
97
|
// ═══════════════════════════════════════════════════════
|
|
100
98
|
// 维度 1: Guard 违规模式分析
|
|
101
99
|
// ═══════════════════════════════════════════════════════
|
|
102
|
-
#analyzeGuardPatterns() {
|
|
100
|
+
async #analyzeGuardPatterns() {
|
|
103
101
|
const suggestions = [];
|
|
104
|
-
if (!this.#
|
|
105
|
-
return { summary: '
|
|
102
|
+
if (!this.#auditRepo) {
|
|
103
|
+
return { summary: 'AuditRepo 不可用', suggestions };
|
|
106
104
|
}
|
|
107
105
|
try {
|
|
108
|
-
|
|
109
|
-
const rows = this.#db
|
|
110
|
-
.prepare(`
|
|
111
|
-
SELECT json_extract(operation_data, '$.ruleName') as ruleName,
|
|
112
|
-
COUNT(*) as cnt
|
|
113
|
-
FROM audit_logs
|
|
114
|
-
WHERE action LIKE 'guard%'
|
|
115
|
-
AND result = 'violation'
|
|
116
|
-
GROUP BY ruleName
|
|
117
|
-
HAVING cnt >= 3
|
|
118
|
-
ORDER BY cnt DESC
|
|
119
|
-
LIMIT 5
|
|
120
|
-
`)
|
|
121
|
-
.all();
|
|
106
|
+
const rows = await this.#auditRepo.findTopGuardViolationRules(3, 5);
|
|
122
107
|
if (rows.length > 0) {
|
|
123
108
|
const topRule = rows[0];
|
|
124
109
|
suggestions.push({
|
|
@@ -192,32 +177,16 @@ export class SkillAdvisor {
|
|
|
192
177
|
// ═══════════════════════════════════════════════════════
|
|
193
178
|
// 维度 3: Recipe 分布与使用热度
|
|
194
179
|
// ═══════════════════════════════════════════════════════
|
|
195
|
-
#analyzeRecipePatterns() {
|
|
180
|
+
async #analyzeRecipePatterns() {
|
|
196
181
|
const suggestions = [];
|
|
197
|
-
if (!this.#
|
|
198
|
-
return { summary: '
|
|
182
|
+
if (!this.#knowledgeRepo) {
|
|
183
|
+
return { summary: 'KnowledgeRepo 不可用', suggestions };
|
|
199
184
|
}
|
|
200
185
|
try {
|
|
201
186
|
// 按 category 分布
|
|
202
|
-
const categories = this.#
|
|
203
|
-
.prepare(`
|
|
204
|
-
SELECT category, COUNT(*) as cnt
|
|
205
|
-
FROM knowledge_entries
|
|
206
|
-
WHERE lifecycle = 'active' AND category IS NOT NULL AND category != ''
|
|
207
|
-
GROUP BY category
|
|
208
|
-
ORDER BY cnt DESC
|
|
209
|
-
`)
|
|
210
|
-
.all();
|
|
187
|
+
const categories = await this.#knowledgeRepo.countGroupByCategory();
|
|
211
188
|
// 按 language 分布
|
|
212
|
-
const languages = this.#
|
|
213
|
-
.prepare(`
|
|
214
|
-
SELECT language, COUNT(*) as cnt
|
|
215
|
-
FROM knowledge_entries
|
|
216
|
-
WHERE lifecycle = 'active' AND language IS NOT NULL AND language != ''
|
|
217
|
-
GROUP BY language
|
|
218
|
-
ORDER BY cnt DESC
|
|
219
|
-
`)
|
|
220
|
-
.all();
|
|
189
|
+
const languages = await this.#knowledgeRepo.countGroupByLanguage();
|
|
221
190
|
// 高频使用但无自定义 Skill 的 category
|
|
222
191
|
const topCategory = categories[0];
|
|
223
192
|
if (topCategory && topCategory.cnt >= 10) {
|
|
@@ -235,20 +204,10 @@ export class SkillAdvisor {
|
|
|
235
204
|
},
|
|
236
205
|
});
|
|
237
206
|
}
|
|
238
|
-
// 高使用量 Recipe
|
|
207
|
+
// 高使用量 Recipe 统计
|
|
239
208
|
let hotRecipes = [];
|
|
240
209
|
try {
|
|
241
|
-
hotRecipes = this.#
|
|
242
|
-
.prepare(`
|
|
243
|
-
SELECT title, category,
|
|
244
|
-
(COALESCE(json_extract(stats, '$.adoptions'), 0) + COALESCE(json_extract(stats, '$.applications'), 0)) as total_usage
|
|
245
|
-
FROM knowledge_entries
|
|
246
|
-
WHERE lifecycle = 'active'
|
|
247
|
-
AND (COALESCE(json_extract(stats, '$.adoptions'), 0) + COALESCE(json_extract(stats, '$.applications'), 0)) >= 5
|
|
248
|
-
ORDER BY total_usage DESC
|
|
249
|
-
LIMIT 10
|
|
250
|
-
`)
|
|
251
|
-
.all();
|
|
210
|
+
hotRecipes = await this.#knowledgeRepo.findHotRecipesByUsage(5, 10);
|
|
252
211
|
}
|
|
253
212
|
catch {
|
|
254
213
|
/* 查询失败时降级为空 */
|
|
@@ -265,31 +224,23 @@ export class SkillAdvisor {
|
|
|
265
224
|
// ═══════════════════════════════════════════════════════
|
|
266
225
|
// 维度 4: 候选积压分析
|
|
267
226
|
// ═══════════════════════════════════════════════════════
|
|
268
|
-
#analyzeCandidatePatterns() {
|
|
227
|
+
async #analyzeCandidatePatterns() {
|
|
269
228
|
const suggestions = [];
|
|
270
|
-
if (!this.#
|
|
271
|
-
return { summary: '
|
|
229
|
+
if (!this.#knowledgeRepo) {
|
|
230
|
+
return { summary: 'KnowledgeRepo 不可用', suggestions };
|
|
272
231
|
}
|
|
273
232
|
try {
|
|
274
|
-
|
|
275
|
-
const
|
|
276
|
-
.prepare(`
|
|
277
|
-
SELECT
|
|
278
|
-
COUNT(*) as total,
|
|
279
|
-
SUM(CASE WHEN lifecycle='pending' THEN 1 ELSE 0 END) as pending,
|
|
280
|
-
SUM(CASE WHEN lifecycle='deprecated' THEN 1 ELSE 0 END) as rejected
|
|
281
|
-
FROM knowledge_entries
|
|
282
|
-
`)
|
|
283
|
-
.get();
|
|
233
|
+
const stats = await this.#knowledgeRepo.getLifecycleCounts();
|
|
234
|
+
const rejected = stats?.deprecated ?? 0;
|
|
284
235
|
// 大量被拒绝 → 提示候选质量 Skill
|
|
285
|
-
if (
|
|
236
|
+
if (rejected >= 10) {
|
|
286
237
|
suggestions.push({
|
|
287
238
|
name: 'project-candidate-quality',
|
|
288
|
-
description: `候选提交质量指南 — ${
|
|
289
|
-
rationale: `已有 ${
|
|
239
|
+
description: `候选提交质量指南 — ${rejected} 条候选被拒,建议创建提交标准 Skill`,
|
|
240
|
+
rationale: `已有 ${rejected} 条候选被驳回(总计 ${stats?.total ?? 0} 条)。创建一个 Skill 明确项目的候选提交标准(哪些代码值得提取、必填字段要求、质量标杆),可以减少返工。`,
|
|
290
241
|
source: 'candidate_rejection',
|
|
291
|
-
priority:
|
|
292
|
-
signals: { total: stats
|
|
242
|
+
priority: rejected >= 20 ? 'high' : 'medium',
|
|
243
|
+
signals: { total: stats?.total ?? 0, pending: stats?.pending ?? 0, rejected },
|
|
293
244
|
});
|
|
294
245
|
}
|
|
295
246
|
return {
|
|
@@ -40,6 +40,10 @@ export class ContextualEnricher {
|
|
|
40
40
|
if (chunks.length === 0) {
|
|
41
41
|
return [];
|
|
42
42
|
}
|
|
43
|
+
// Mock 模式下跳过 AI enrichment,直接返回原始 chunks
|
|
44
|
+
if (this.#aiProvider.name === 'mock') {
|
|
45
|
+
return chunks;
|
|
46
|
+
}
|
|
43
47
|
const systemPrompt = this.#buildSystemPrompt(document);
|
|
44
48
|
const enriched = [];
|
|
45
49
|
for (const chunk of chunks) {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @module service/vector/SyncCoordinator
|
|
13
13
|
*/
|
|
14
|
+
import type { DrizzleDB } from '../../infrastructure/database/drizzle/index.js';
|
|
14
15
|
import type { EventBus } from '../../infrastructure/event/EventBus.js';
|
|
15
16
|
import type { VectorStore } from '../../infrastructure/vector/VectorStore.js';
|
|
16
17
|
import type { ContextualEnricher } from './ContextualEnricher.js';
|
|
@@ -21,6 +22,7 @@ export interface SyncCoordinatorConfig {
|
|
|
21
22
|
contextualEnricher: ContextualEnricher | null;
|
|
22
23
|
debounceMs: number;
|
|
23
24
|
maxBatchSize?: number;
|
|
25
|
+
drizzle?: DrizzleDB;
|
|
24
26
|
}
|
|
25
27
|
export declare class SyncCoordinator {
|
|
26
28
|
#private;
|
|
@@ -37,7 +39,7 @@ export declare class SyncCoordinator {
|
|
|
37
39
|
* @param db - 数据库连接 (better-sqlite3 style)
|
|
38
40
|
* @returns 对账结果
|
|
39
41
|
*/
|
|
40
|
-
reconcile(db
|
|
42
|
+
reconcile(db?: {
|
|
41
43
|
prepare(sql: string): {
|
|
42
44
|
all(...args: unknown[]): Array<{
|
|
43
45
|
id: string;
|
|
@@ -11,7 +11,10 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @module service/vector/SyncCoordinator
|
|
13
13
|
*/
|
|
14
|
+
import { ne } from 'drizzle-orm';
|
|
15
|
+
import { knowledgeEntries } from '../../infrastructure/database/drizzle/schema.js';
|
|
14
16
|
import Logger from '../../infrastructure/logging/Logger.js';
|
|
17
|
+
import { queryNonDeprecatedEntries } from '../../repository/search/SearchRepoAdapter.js';
|
|
15
18
|
// ── Coordinator ──
|
|
16
19
|
export class SyncCoordinator {
|
|
17
20
|
#vectorStore;
|
|
@@ -19,6 +22,7 @@ export class SyncCoordinator {
|
|
|
19
22
|
#contextualEnricher;
|
|
20
23
|
#debounceMs;
|
|
21
24
|
#maxBatchSize;
|
|
25
|
+
#drizzle;
|
|
22
26
|
#pendingChanges = new Map();
|
|
23
27
|
#debounceTimer = null;
|
|
24
28
|
#processing = false;
|
|
@@ -31,6 +35,7 @@ export class SyncCoordinator {
|
|
|
31
35
|
this.#contextualEnricher = config.contextualEnricher;
|
|
32
36
|
this.#debounceMs = config.debounceMs;
|
|
33
37
|
this.#maxBatchSize = config.maxBatchSize ?? 20;
|
|
38
|
+
this.#drizzle = config.drizzle ?? null;
|
|
34
39
|
}
|
|
35
40
|
/** 绑定 EventBus,开始监听知识变更事件 */
|
|
36
41
|
bindEventBus(eventBus) {
|
|
@@ -76,9 +81,26 @@ export class SyncCoordinator {
|
|
|
76
81
|
// 2. 获取 DB 中所有 active 知识条目 ID
|
|
77
82
|
let dbEntries = [];
|
|
78
83
|
try {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
if (this.#drizzle) {
|
|
85
|
+
// Drizzle 类型安全查询
|
|
86
|
+
dbEntries = this.#drizzle
|
|
87
|
+
.select({
|
|
88
|
+
id: knowledgeEntries.id,
|
|
89
|
+
title: knowledgeEntries.title,
|
|
90
|
+
content: knowledgeEntries.content,
|
|
91
|
+
kind: knowledgeEntries.kind,
|
|
92
|
+
})
|
|
93
|
+
.from(knowledgeEntries)
|
|
94
|
+
.where(ne(knowledgeEntries.lifecycle, 'deprecated'))
|
|
95
|
+
.all();
|
|
96
|
+
}
|
|
97
|
+
else if (db) {
|
|
98
|
+
// 向后兼容: 测试时可传入 mock db
|
|
99
|
+
dbEntries = queryNonDeprecatedEntries(db);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
82
104
|
}
|
|
83
105
|
catch {
|
|
84
106
|
// 表可能不存在
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* @module service/vector/VectorService
|
|
14
14
|
*/
|
|
15
|
+
import type { DrizzleDB } from '../../infrastructure/database/drizzle/index.js';
|
|
15
16
|
import type { EventBus } from '../../infrastructure/event/EventBus.js';
|
|
16
17
|
import type { IndexingPipeline } from '../../infrastructure/vector/IndexingPipeline.js';
|
|
17
18
|
import type { VectorStore } from '../../infrastructure/vector/VectorStore.js';
|
|
@@ -29,6 +30,7 @@ export interface VectorServiceConfig {
|
|
|
29
30
|
contextualEnricher: ContextualEnricher | null;
|
|
30
31
|
autoSyncOnCrud: boolean;
|
|
31
32
|
syncDebounceMs: number;
|
|
33
|
+
drizzle?: DrizzleDB;
|
|
32
34
|
}
|
|
33
35
|
export interface BuildResult {
|
|
34
36
|
scanned: number;
|
|
@@ -24,6 +24,7 @@ export class VectorService {
|
|
|
24
24
|
#syncCoordinator = null;
|
|
25
25
|
#autoSyncOnCrud;
|
|
26
26
|
#syncDebounceMs;
|
|
27
|
+
#drizzle;
|
|
27
28
|
#logger = Logger.getInstance();
|
|
28
29
|
#initialized = false;
|
|
29
30
|
// ── Embed circuit breaker ──
|
|
@@ -40,6 +41,7 @@ export class VectorService {
|
|
|
40
41
|
this.#contextualEnricher = config.contextualEnricher;
|
|
41
42
|
this.#autoSyncOnCrud = config.autoSyncOnCrud;
|
|
42
43
|
this.#syncDebounceMs = config.syncDebounceMs;
|
|
44
|
+
this.#drizzle = config.drizzle ?? null;
|
|
43
45
|
}
|
|
44
46
|
// ═══ Lifecycle ═══
|
|
45
47
|
/** 初始化: 绑定 EventBus 事件监听 */
|
|
@@ -55,6 +57,7 @@ export class VectorService {
|
|
|
55
57
|
embedProvider: this.#embedProvider,
|
|
56
58
|
contextualEnricher: this.#contextualEnricher,
|
|
57
59
|
debounceMs: this.#syncDebounceMs,
|
|
60
|
+
drizzle: this.#drizzle ?? undefined,
|
|
58
61
|
});
|
|
59
62
|
this.#syncCoordinator.bindEventBus(this.#eventBus);
|
|
60
63
|
this.#logger.info('[VectorService] SyncCoordinator bound to EventBus');
|
|
@@ -291,7 +291,7 @@ export class WikiGenerator {
|
|
|
291
291
|
/** AST 分析 — 利用已有 ProjectGraph 或重新构建 */
|
|
292
292
|
async _analyzeAST() {
|
|
293
293
|
if (this.projectGraph) {
|
|
294
|
-
const overview = this.projectGraph.getOverview();
|
|
294
|
+
const overview = await this.projectGraph.getOverview();
|
|
295
295
|
const allClasses = this.projectGraph.getAllClassNames();
|
|
296
296
|
const allProtocols = this.projectGraph.getAllProtocolNames();
|
|
297
297
|
// 按模块分组类名和协议名 (通过 filePath 推断所属模块)
|