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
|
@@ -87,20 +87,29 @@ export class ConfidenceRouter {
|
|
|
87
87
|
let qualityScore = null;
|
|
88
88
|
if (this._qualityScorer) {
|
|
89
89
|
try {
|
|
90
|
+
const content = entry.content && typeof entry.content === 'object'
|
|
91
|
+
? entry.content
|
|
92
|
+
: {};
|
|
93
|
+
const reasoning = entry.reasoning && typeof entry.reasoning === 'object'
|
|
94
|
+
? entry.reasoning
|
|
95
|
+
: {};
|
|
90
96
|
const scorerInput = {
|
|
91
97
|
title: entry.title,
|
|
92
98
|
trigger: entry.trigger,
|
|
93
|
-
|
|
99
|
+
description: entry.description || '',
|
|
94
100
|
language: entry.language,
|
|
95
101
|
category: entry.category,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
usageGuide: entry.usageGuide ||
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
doClause: entry.doClause || '',
|
|
103
|
+
dontClause: entry.dontClause || '',
|
|
104
|
+
whenClause: entry.whenClause || '',
|
|
105
|
+
coreCode: entry.coreCode || '',
|
|
106
|
+
usageGuide: entry.usageGuide || content.markdown || '',
|
|
107
|
+
contentMarkdown: content.markdown || '',
|
|
108
|
+
contentRationale: content.rationale || '',
|
|
109
|
+
reasoningWhyStandard: reasoning.whyStandard || '',
|
|
110
|
+
reasoningSources: reasoning.sources || [],
|
|
111
|
+
reasoningConfidence: reasoning.confidence || 0,
|
|
112
|
+
source: entry.source || '',
|
|
104
113
|
headers: entry.headers || [],
|
|
105
114
|
tags: entry.tags || [],
|
|
106
115
|
};
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import type { KnowledgeEntry } from '../../domain/knowledge/KnowledgeEntry.js';
|
|
21
21
|
import Logger from '../../infrastructure/logging/Logger.js';
|
|
22
|
-
|
|
22
|
+
import type { KnowledgeFileStore } from '../../repository/knowledge/KnowledgeFileStore.js';
|
|
23
|
+
export declare class KnowledgeFileWriter implements KnowledgeFileStore {
|
|
23
24
|
candidatesDir: string;
|
|
24
25
|
logger: ReturnType<typeof Logger.getInstance>;
|
|
25
26
|
projectRoot: string;
|
|
@@ -4,68 +4,34 @@
|
|
|
4
4
|
* 管理 Recipe 之间的关系(统一模型,包含所有知识类型)
|
|
5
5
|
* 支持关系查询、路径分析、PageRank 权重计算
|
|
6
6
|
*/
|
|
7
|
-
import type { Database } from 'better-sqlite3';
|
|
8
7
|
import { RelationType } from '../../domain/index.js';
|
|
9
8
|
import Logger from '../../infrastructure/logging/Logger.js';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
id: number;
|
|
13
|
-
from_id: string;
|
|
14
|
-
from_type: string;
|
|
15
|
-
to_id: string;
|
|
16
|
-
to_type: string;
|
|
17
|
-
relation: string;
|
|
18
|
-
weight: number;
|
|
19
|
-
metadata_json: string;
|
|
20
|
-
created_at: number;
|
|
21
|
-
updated_at: number;
|
|
22
|
-
}
|
|
23
|
-
interface MappedEdge {
|
|
24
|
-
id: number;
|
|
25
|
-
fromId: string;
|
|
26
|
-
fromType: string;
|
|
27
|
-
toId: string;
|
|
28
|
-
toType: string;
|
|
29
|
-
relation: string;
|
|
30
|
-
weight: number;
|
|
31
|
-
metadata: Record<string, unknown>;
|
|
32
|
-
createdAt: number;
|
|
33
|
-
updatedAt: number;
|
|
34
|
-
}
|
|
35
|
-
interface DbLike {
|
|
36
|
-
getDb?: () => Database;
|
|
37
|
-
prepare(sql: string): {
|
|
38
|
-
run(...params: unknown[]): {
|
|
39
|
-
changes: number;
|
|
40
|
-
};
|
|
41
|
-
get(...params: unknown[]): EdgeRow;
|
|
42
|
-
all(...params: unknown[]): EdgeRow[];
|
|
43
|
-
};
|
|
44
|
-
}
|
|
9
|
+
import type { KnowledgeEdgeRepositoryImpl } from '../../repository/knowledge/KnowledgeEdgeRepository.js';
|
|
10
|
+
type EdgeRepoLike = Pick<KnowledgeEdgeRepositoryImpl, 'upsertEdge' | 'removeEdge' | 'findOutgoing' | 'findIncoming' | 'findIncomingByRelations' | 'findByRelation' | 'findAll' | 'getStats'>;
|
|
45
11
|
export { RelationType };
|
|
46
12
|
export declare class KnowledgeGraphService {
|
|
47
|
-
|
|
13
|
+
#private;
|
|
48
14
|
logger: ReturnType<typeof Logger.getInstance>;
|
|
49
|
-
constructor(
|
|
15
|
+
constructor(edgeRepo: EdgeRepoLike);
|
|
50
16
|
/** 添加关系边 */
|
|
51
|
-
addEdge(fromId: string, fromType: string, toId: string, toType: string, relation: string, metadata?: Record<string, unknown>): {
|
|
17
|
+
addEdge(fromId: string, fromType: string, toId: string, toType: string, relation: string, metadata?: Record<string, unknown>): Promise<{
|
|
52
18
|
success: boolean;
|
|
53
19
|
error?: undefined;
|
|
54
20
|
} | {
|
|
55
21
|
success: boolean;
|
|
56
22
|
error: string;
|
|
57
|
-
}
|
|
23
|
+
}>;
|
|
58
24
|
/** 删除关系边 */
|
|
59
|
-
removeEdge(fromId: string, fromType: string, toId: string, toType: string, relation: string): void
|
|
25
|
+
removeEdge(fromId: string, fromType: string, toId: string, toType: string, relation: string): Promise<void>;
|
|
60
26
|
/** 查询某个节点的所有关系 */
|
|
61
|
-
getEdges(nodeId: string, nodeType: string, direction?: string): {
|
|
62
|
-
outgoing:
|
|
63
|
-
incoming:
|
|
64
|
-
}
|
|
27
|
+
getEdges(nodeId: string, nodeType: string, direction?: string): Promise<{
|
|
28
|
+
outgoing: import("../../repository/knowledge/KnowledgeEdgeRepository.js").KnowledgeEdge[];
|
|
29
|
+
incoming: import("../../repository/knowledge/KnowledgeEdgeRepository.js").KnowledgeEdge[];
|
|
30
|
+
}>;
|
|
65
31
|
/** 查询指定关系类型的连接 */
|
|
66
|
-
getRelated(nodeId: string, nodeType: string, relation: string):
|
|
32
|
+
getRelated(nodeId: string, nodeType: string, relation: string): Promise<import("../../repository/knowledge/KnowledgeEdgeRepository.js").KnowledgeEdge[]>;
|
|
67
33
|
/** 查找两个节点之间的路径 (BFS, 最大深度 5) */
|
|
68
|
-
findPath(fromId: string, fromType: string, toId: string, toType: string, maxDepth?: number): {
|
|
34
|
+
findPath(fromId: string, fromType: string, toId: string, toType: string, maxDepth?: number): Promise<{
|
|
69
35
|
found: boolean;
|
|
70
36
|
path: {
|
|
71
37
|
from: {
|
|
@@ -79,26 +45,18 @@ export declare class KnowledgeGraphService {
|
|
|
79
45
|
relation: string;
|
|
80
46
|
}[];
|
|
81
47
|
depth: number;
|
|
82
|
-
}
|
|
48
|
+
}>;
|
|
83
49
|
/** 获取节点的影响范围(下游依赖分析) */
|
|
84
|
-
getImpactAnalysis(nodeId: string, nodeType: string, maxDepth?: number): any[]
|
|
50
|
+
getImpactAnalysis(nodeId: string, nodeType: string, maxDepth?: number): Promise<any[]>;
|
|
85
51
|
/** 获取图谱整体统计 */
|
|
86
|
-
|
|
87
|
-
getStats(nodeType?: string): {
|
|
88
|
-
totalEdges: number;
|
|
89
|
-
byRelation: {
|
|
90
|
-
[k: string]: unknown;
|
|
91
|
-
};
|
|
92
|
-
nodeTypes: EdgeRow[];
|
|
93
|
-
};
|
|
52
|
+
getStats(nodeType?: string): Promise<import("../../repository/knowledge/KnowledgeEdgeRepository.js").EdgeStats>;
|
|
94
53
|
/**
|
|
95
54
|
* 获取全量边(供 Dashboard 图谱可视化)
|
|
96
55
|
* @param [limit=500] 最大返回条数
|
|
97
56
|
* @param [nodeType] 过滤节点类型(如 'recipe'),为空则返回全部
|
|
98
57
|
*/
|
|
99
|
-
getAllEdges(limit?: number, nodeType?: string):
|
|
100
|
-
_mapEdge(row: EdgeRow): MappedEdge;
|
|
58
|
+
getAllEdges(limit?: number, nodeType?: string): Promise<import("../../repository/knowledge/KnowledgeEdgeRepository.js").KnowledgeEdge[]>;
|
|
101
59
|
}
|
|
102
|
-
export declare function initKnowledgeGraphService(
|
|
60
|
+
export declare function initKnowledgeGraphService(edgeRepo: EdgeRepoLike): KnowledgeGraphService;
|
|
103
61
|
export declare function getKnowledgeGraphService(): KnowledgeGraphService | null;
|
|
104
62
|
export default KnowledgeGraphService;
|
|
@@ -9,22 +9,24 @@ import Logger from '../../infrastructure/logging/Logger.js';
|
|
|
9
9
|
// Re-export unified RelationType for backward compatibility
|
|
10
10
|
export { RelationType };
|
|
11
11
|
export class KnowledgeGraphService {
|
|
12
|
-
|
|
12
|
+
#edgeRepo;
|
|
13
13
|
logger;
|
|
14
|
-
constructor(
|
|
15
|
-
this
|
|
14
|
+
constructor(edgeRepo) {
|
|
15
|
+
this.#edgeRepo = edgeRepo;
|
|
16
16
|
this.logger = Logger.getInstance();
|
|
17
17
|
}
|
|
18
18
|
/** 添加关系边 */
|
|
19
|
-
addEdge(fromId, fromType, toId, toType, relation, metadata = {}) {
|
|
20
|
-
const now = Math.floor(Date.now() / 1000);
|
|
19
|
+
async addEdge(fromId, fromType, toId, toType, relation, metadata = {}) {
|
|
21
20
|
try {
|
|
22
|
-
this.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
await this.#edgeRepo.upsertEdge({
|
|
22
|
+
fromId,
|
|
23
|
+
fromType,
|
|
24
|
+
toId,
|
|
25
|
+
toType,
|
|
26
|
+
relation,
|
|
27
|
+
weight: metadata.weight || 1.0,
|
|
28
|
+
metadata,
|
|
29
|
+
});
|
|
28
30
|
return { success: true };
|
|
29
31
|
}
|
|
30
32
|
catch (error) {
|
|
@@ -34,43 +36,25 @@ export class KnowledgeGraphService {
|
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
/** 删除关系边 */
|
|
37
|
-
removeEdge(fromId, fromType, toId, toType, relation) {
|
|
38
|
-
this.
|
|
39
|
-
.prepare(`
|
|
40
|
-
DELETE FROM knowledge_edges WHERE from_id = ? AND from_type = ? AND to_id = ? AND to_type = ? AND relation = ?
|
|
41
|
-
`)
|
|
42
|
-
.run(fromId, fromType, toId, toType, relation);
|
|
39
|
+
async removeEdge(fromId, fromType, toId, toType, relation) {
|
|
40
|
+
await this.#edgeRepo.removeEdge(fromId, fromType, toId, toType, relation);
|
|
43
41
|
}
|
|
44
42
|
/** 查询某个节点的所有关系 */
|
|
45
|
-
getEdges(nodeId, nodeType, direction = 'both') {
|
|
43
|
+
async getEdges(nodeId, nodeType, direction = 'both') {
|
|
46
44
|
const outgoing = direction === 'both' || direction === 'out'
|
|
47
|
-
? this.
|
|
48
|
-
.prepare(`SELECT * FROM knowledge_edges WHERE from_id = ? AND from_type = ?`)
|
|
49
|
-
.all(nodeId, nodeType)
|
|
45
|
+
? await this.#edgeRepo.findOutgoing(nodeId, nodeType)
|
|
50
46
|
: [];
|
|
51
47
|
const incoming = direction === 'both' || direction === 'in'
|
|
52
|
-
? this.
|
|
53
|
-
.prepare(`SELECT * FROM knowledge_edges WHERE to_id = ? AND to_type = ?`)
|
|
54
|
-
.all(nodeId, nodeType)
|
|
48
|
+
? await this.#edgeRepo.findIncoming(nodeId, nodeType)
|
|
55
49
|
: [];
|
|
56
|
-
return {
|
|
57
|
-
outgoing: outgoing.map((row) => this._mapEdge(row)),
|
|
58
|
-
incoming: incoming.map((row) => this._mapEdge(row)),
|
|
59
|
-
};
|
|
50
|
+
return { outgoing, incoming };
|
|
60
51
|
}
|
|
61
52
|
/** 查询指定关系类型的连接 */
|
|
62
|
-
getRelated(nodeId, nodeType, relation) {
|
|
63
|
-
|
|
64
|
-
.prepare(`
|
|
65
|
-
SELECT * FROM knowledge_edges WHERE from_id = ? AND from_type = ? AND relation = ?
|
|
66
|
-
UNION ALL
|
|
67
|
-
SELECT * FROM knowledge_edges WHERE to_id = ? AND to_type = ? AND relation = ?
|
|
68
|
-
`)
|
|
69
|
-
.all(nodeId, nodeType, relation, nodeId, nodeType, relation);
|
|
70
|
-
return rows.map((row) => this._mapEdge(row));
|
|
53
|
+
async getRelated(nodeId, nodeType, relation) {
|
|
54
|
+
return this.#edgeRepo.findByRelation(nodeId, nodeType, relation);
|
|
71
55
|
}
|
|
72
56
|
/** 查找两个节点之间的路径 (BFS, 最大深度 5) */
|
|
73
|
-
findPath(fromId, fromType, toId, toType, maxDepth = 5) {
|
|
57
|
+
async findPath(fromId, fromType, toId, toType, maxDepth = 5) {
|
|
74
58
|
const visited = new Set();
|
|
75
59
|
const queue = [
|
|
76
60
|
{
|
|
@@ -80,7 +64,11 @@ export class KnowledgeGraphService {
|
|
|
80
64
|
},
|
|
81
65
|
];
|
|
82
66
|
while (queue.length > 0) {
|
|
83
|
-
const
|
|
67
|
+
const current = queue.shift();
|
|
68
|
+
if (!current) {
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
const { id, type, path } = current;
|
|
84
72
|
if (path.length >= maxDepth) {
|
|
85
73
|
continue;
|
|
86
74
|
}
|
|
@@ -89,24 +77,20 @@ export class KnowledgeGraphService {
|
|
|
89
77
|
continue;
|
|
90
78
|
}
|
|
91
79
|
visited.add(key);
|
|
92
|
-
const neighbors = this.
|
|
93
|
-
.prepare(`
|
|
94
|
-
SELECT to_id, to_type, relation, weight FROM knowledge_edges WHERE from_id = ? AND from_type = ?
|
|
95
|
-
`)
|
|
96
|
-
.all(id, type);
|
|
80
|
+
const neighbors = await this.#edgeRepo.findOutgoing(id, type);
|
|
97
81
|
for (const neighbor of neighbors) {
|
|
98
82
|
const newPath = [
|
|
99
83
|
...path,
|
|
100
84
|
{
|
|
101
85
|
from: { id, type },
|
|
102
|
-
to: { id: neighbor.
|
|
86
|
+
to: { id: neighbor.toId, type: neighbor.toType },
|
|
103
87
|
relation: neighbor.relation,
|
|
104
88
|
},
|
|
105
89
|
];
|
|
106
|
-
if (neighbor.
|
|
90
|
+
if (neighbor.toId === toId && neighbor.toType === toType) {
|
|
107
91
|
return { found: true, path: newPath, depth: newPath.length };
|
|
108
92
|
}
|
|
109
|
-
queue.push({ id: neighbor.
|
|
93
|
+
queue.push({ id: neighbor.toId, type: neighbor.toType, path: newPath });
|
|
110
94
|
}
|
|
111
95
|
}
|
|
112
96
|
return {
|
|
@@ -116,95 +100,60 @@ export class KnowledgeGraphService {
|
|
|
116
100
|
};
|
|
117
101
|
}
|
|
118
102
|
/** 获取节点的影响范围(下游依赖分析) */
|
|
119
|
-
getImpactAnalysis(nodeId, nodeType, maxDepth = 3) {
|
|
103
|
+
async getImpactAnalysis(nodeId, nodeType, maxDepth = 3) {
|
|
104
|
+
const impactRelations = [
|
|
105
|
+
'requires',
|
|
106
|
+
'extends',
|
|
107
|
+
'enforces',
|
|
108
|
+
'depends_on',
|
|
109
|
+
'inherits',
|
|
110
|
+
'implements',
|
|
111
|
+
'calls',
|
|
112
|
+
'prerequisite',
|
|
113
|
+
];
|
|
120
114
|
const impacted = new Map();
|
|
121
115
|
const queue = [{ id: nodeId, type: nodeType, depth: 0 }];
|
|
122
116
|
while (queue.length > 0) {
|
|
123
|
-
const
|
|
117
|
+
const current = queue.shift();
|
|
118
|
+
if (!current) {
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
const { id, type, depth } = current;
|
|
124
122
|
if (depth >= maxDepth) {
|
|
125
123
|
continue;
|
|
126
124
|
}
|
|
127
|
-
const dependents = this.
|
|
128
|
-
.prepare(`
|
|
129
|
-
SELECT from_id, from_type, relation FROM knowledge_edges
|
|
130
|
-
WHERE to_id = ? AND to_type = ? AND relation IN ('requires', 'extends', 'enforces', 'depends_on', 'inherits', 'implements', 'calls', 'prerequisite')
|
|
131
|
-
`)
|
|
132
|
-
.all(id, type);
|
|
125
|
+
const dependents = await this.#edgeRepo.findIncomingByRelations(id, type, impactRelations);
|
|
133
126
|
for (const dep of dependents) {
|
|
134
|
-
const key = `${dep.
|
|
127
|
+
const key = `${dep.fromType}:${dep.fromId}`;
|
|
135
128
|
if (!impacted.has(key)) {
|
|
136
129
|
impacted.set(key, {
|
|
137
|
-
id: dep.
|
|
138
|
-
type: dep.
|
|
130
|
+
id: dep.fromId,
|
|
131
|
+
type: dep.fromType,
|
|
139
132
|
relation: dep.relation,
|
|
140
133
|
depth: depth + 1,
|
|
141
134
|
});
|
|
142
|
-
queue.push({ id: dep.
|
|
135
|
+
queue.push({ id: dep.fromId, type: dep.fromType, depth: depth + 1 });
|
|
143
136
|
}
|
|
144
137
|
}
|
|
145
138
|
}
|
|
146
139
|
return Array.from(impacted.values());
|
|
147
140
|
}
|
|
148
141
|
/** 获取图谱整体统计 */
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const typeFilter = nodeType
|
|
152
|
-
? ` WHERE from_type = '${nodeType}' AND to_type = '${nodeType}'`
|
|
153
|
-
: '';
|
|
154
|
-
const edgeCount = this.db
|
|
155
|
-
.prepare(`SELECT COUNT(*) as total FROM knowledge_edges${typeFilter}`)
|
|
156
|
-
.get();
|
|
157
|
-
const byRelation = this.db
|
|
158
|
-
.prepare(`SELECT relation, COUNT(*) as count FROM knowledge_edges${typeFilter} GROUP BY relation`)
|
|
159
|
-
.all();
|
|
160
|
-
const byType = this.db
|
|
161
|
-
.prepare(`SELECT from_type as type, COUNT(DISTINCT from_id) as count FROM knowledge_edges${typeFilter} GROUP BY from_type
|
|
162
|
-
UNION
|
|
163
|
-
SELECT to_type as type, COUNT(DISTINCT to_id) as count FROM knowledge_edges${typeFilter} GROUP BY to_type`)
|
|
164
|
-
.all();
|
|
165
|
-
return {
|
|
166
|
-
totalEdges: edgeCount.total,
|
|
167
|
-
byRelation: Object.fromEntries(byRelation.map((r) => [r.relation, r.count])),
|
|
168
|
-
nodeTypes: byType,
|
|
169
|
-
};
|
|
142
|
+
async getStats(nodeType) {
|
|
143
|
+
return this.#edgeRepo.getStats(nodeType);
|
|
170
144
|
}
|
|
171
145
|
/**
|
|
172
146
|
* 获取全量边(供 Dashboard 图谱可视化)
|
|
173
147
|
* @param [limit=500] 最大返回条数
|
|
174
148
|
* @param [nodeType] 过滤节点类型(如 'recipe'),为空则返回全部
|
|
175
149
|
*/
|
|
176
|
-
getAllEdges(limit = 500, nodeType) {
|
|
177
|
-
|
|
178
|
-
if (nodeType) {
|
|
179
|
-
sql = `SELECT * FROM knowledge_edges WHERE from_type = ? AND to_type = ? ORDER BY updated_at DESC LIMIT ?`;
|
|
180
|
-
params = [nodeType, nodeType, limit];
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
sql = `SELECT * FROM knowledge_edges ORDER BY updated_at DESC LIMIT ?`;
|
|
184
|
-
params = [limit];
|
|
185
|
-
}
|
|
186
|
-
const rows = this.db.prepare(sql).all(...params);
|
|
187
|
-
return rows.map((row) => this._mapEdge(row));
|
|
188
|
-
}
|
|
189
|
-
// Private
|
|
190
|
-
_mapEdge(row) {
|
|
191
|
-
return {
|
|
192
|
-
id: row.id,
|
|
193
|
-
fromId: row.from_id,
|
|
194
|
-
fromType: row.from_type,
|
|
195
|
-
toId: row.to_id,
|
|
196
|
-
toType: row.to_type,
|
|
197
|
-
relation: row.relation,
|
|
198
|
-
weight: row.weight,
|
|
199
|
-
metadata: JSON.parse(row.metadata_json || '{}'),
|
|
200
|
-
createdAt: row.created_at,
|
|
201
|
-
updatedAt: row.updated_at,
|
|
202
|
-
};
|
|
150
|
+
async getAllEdges(limit = 500, nodeType) {
|
|
151
|
+
return this.#edgeRepo.findAll({ nodeType, limit });
|
|
203
152
|
}
|
|
204
153
|
}
|
|
205
154
|
let instance = null;
|
|
206
|
-
export function initKnowledgeGraphService(
|
|
207
|
-
instance = new KnowledgeGraphService(
|
|
155
|
+
export function initKnowledgeGraphService(edgeRepo) {
|
|
156
|
+
instance = new KnowledgeGraphService(edgeRepo);
|
|
208
157
|
return instance;
|
|
209
158
|
}
|
|
210
159
|
export function getKnowledgeGraphService() {
|
|
@@ -23,12 +23,21 @@ interface QualityScorerLike {
|
|
|
23
23
|
interface EventBusLike {
|
|
24
24
|
emit(event: string | symbol, ...args: unknown[]): boolean;
|
|
25
25
|
}
|
|
26
|
+
interface EdgeRepoLike {
|
|
27
|
+
deleteOutgoing(fromId: string, fromType: string): Promise<number>;
|
|
28
|
+
deleteByEntryId(entryId: string): Promise<number>;
|
|
29
|
+
}
|
|
30
|
+
interface ProposalRepoLike {
|
|
31
|
+
deleteByTargetRecipeId(targetRecipeId: string): number;
|
|
32
|
+
}
|
|
26
33
|
interface KnowledgeServiceOptions {
|
|
27
34
|
fileWriter?: KnowledgeFileWriter | null;
|
|
28
35
|
skillHooks?: SkillHooksLike | null;
|
|
29
36
|
confidenceRouter?: ConfidenceRouter | null;
|
|
30
37
|
qualityScorer?: QualityScorerLike | null;
|
|
31
38
|
eventBus?: EventBusLike | null;
|
|
39
|
+
edgeRepo?: EdgeRepoLike | null;
|
|
40
|
+
proposalRepo?: ProposalRepoLike | null;
|
|
32
41
|
}
|
|
33
42
|
interface ServiceContext {
|
|
34
43
|
userId: string;
|
|
@@ -59,9 +68,11 @@ interface PaginationOptions {
|
|
|
59
68
|
*/
|
|
60
69
|
export declare class KnowledgeService {
|
|
61
70
|
_confidenceRouter: ConfidenceRouter | null;
|
|
71
|
+
_edgeRepo: EdgeRepoLike | null;
|
|
62
72
|
_eventBus: EventBusLike | null;
|
|
63
73
|
_fileWriter: KnowledgeFileWriter | null;
|
|
64
74
|
_knowledgeGraphService: KnowledgeGraphService | null;
|
|
75
|
+
_proposalRepo: ProposalRepoLike | null;
|
|
65
76
|
_qualityScorer: QualityScorerLike | null;
|
|
66
77
|
_skillHooks: SkillHooksLike | null;
|
|
67
78
|
auditLogger: AuditLoggerLike;
|
|
@@ -166,7 +177,10 @@ export declare class KnowledgeService {
|
|
|
166
177
|
_validateCreateInput(data: KnowledgeEntryProps): void;
|
|
167
178
|
/**
|
|
168
179
|
* 为 QualityScorer 适配输入
|
|
169
|
-
* QualityScorer
|
|
180
|
+
* QualityScorer v2 needs: title, trigger, description, language, category,
|
|
181
|
+
* doClause, dontClause, whenClause, coreCode, usageGuide,
|
|
182
|
+
* contentMarkdown, contentRationale, reasoningWhyStandard, reasoningSources,
|
|
183
|
+
* reasoningConfidence, source, headers, tags, views, clicks, rating
|
|
170
184
|
*/
|
|
171
185
|
_adaptForScorer(entry: KnowledgeEntry): Record<string, unknown>;
|
|
172
186
|
/**
|