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
|
@@ -9,12 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import type { ReportStore } from '../../infrastructure/report/ReportStore.js';
|
|
11
11
|
import type { SignalBus } from '../../infrastructure/signal/SignalBus.js';
|
|
12
|
-
|
|
13
|
-
prepare(sql: string): {
|
|
14
|
-
all(...params: unknown[]): Record<string, unknown>[];
|
|
15
|
-
get(...params: unknown[]): Record<string, unknown> | undefined;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
12
|
+
import type KnowledgeRepositoryImpl from '../../repository/knowledge/KnowledgeRepository.impl.js';
|
|
18
13
|
export type EnhancementType = 'missing_code_example' | 'low_adoption' | 'low_authority' | 'deprecated_reference';
|
|
19
14
|
export interface EnhancementSuggestion {
|
|
20
15
|
recipeId: string;
|
|
@@ -26,13 +21,12 @@ export interface EnhancementSuggestion {
|
|
|
26
21
|
}
|
|
27
22
|
export declare class EnhancementSuggester {
|
|
28
23
|
#private;
|
|
29
|
-
constructor(
|
|
24
|
+
constructor(knowledgeRepo: KnowledgeRepositoryImpl, options?: {
|
|
30
25
|
signalBus?: SignalBus;
|
|
31
26
|
reportStore?: ReportStore;
|
|
32
27
|
});
|
|
33
28
|
/**
|
|
34
29
|
* 运行全部 4 种增强策略
|
|
35
30
|
*/
|
|
36
|
-
analyzeAll(): EnhancementSuggestion[]
|
|
31
|
+
analyzeAll(): Promise<EnhancementSuggestion[]>;
|
|
37
32
|
}
|
|
38
|
-
export {};
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* ③ 同类知识中 authority 偏低 → 建议补充 whenClause
|
|
8
8
|
* ④ 关联 Recipe 已 deprecated → 建议检查引用是否过时
|
|
9
9
|
*/
|
|
10
|
+
import { Lifecycle, PUBLISHED_LIFECYCLES } from '../../domain/knowledge/Lifecycle.js';
|
|
10
11
|
import Logger from '../../infrastructure/logging/Logger.js';
|
|
11
12
|
/* ────────────────────── Constants ────────────────────── */
|
|
12
13
|
const GUARD_HIT_THRESHOLD = 5;
|
|
@@ -14,24 +15,25 @@ const SEARCH_HIT_THRESHOLD = 10;
|
|
|
14
15
|
const LOW_AUTHORITY_PERCENTILE = 0.25;
|
|
15
16
|
/* ────────────────────── Class ────────────────────── */
|
|
16
17
|
export class EnhancementSuggester {
|
|
17
|
-
#
|
|
18
|
+
#knowledgeRepo;
|
|
18
19
|
#signalBus;
|
|
19
20
|
#reportStore;
|
|
20
21
|
#logger = Logger.getInstance();
|
|
21
|
-
constructor(
|
|
22
|
-
this.#
|
|
22
|
+
constructor(knowledgeRepo, options = {}) {
|
|
23
|
+
this.#knowledgeRepo = knowledgeRepo;
|
|
23
24
|
this.#signalBus = options.signalBus ?? null;
|
|
24
25
|
this.#reportStore = options.reportStore ?? null;
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
28
|
* 运行全部 4 种增强策略
|
|
28
29
|
*/
|
|
29
|
-
analyzeAll() {
|
|
30
|
+
async analyzeAll() {
|
|
31
|
+
const entries = await this.#knowledgeRepo.findAllByLifecycles(PUBLISHED_LIFECYCLES);
|
|
30
32
|
const suggestions = [
|
|
31
|
-
...this.#checkMissingCodeExamples(),
|
|
32
|
-
...this.#checkLowAdoption(),
|
|
33
|
-
...this.#checkLowAuthority(),
|
|
34
|
-
...this.#checkDeprecatedReferences(),
|
|
33
|
+
...this.#checkMissingCodeExamples(entries),
|
|
34
|
+
...this.#checkLowAdoption(entries),
|
|
35
|
+
...this.#checkLowAuthority(entries),
|
|
36
|
+
...(await this.#checkDeprecatedReferences(entries)),
|
|
35
37
|
];
|
|
36
38
|
if (this.#reportStore && suggestions.length > 0) {
|
|
37
39
|
void this.#reportStore.write({
|
|
@@ -49,30 +51,20 @@ export class EnhancementSuggester {
|
|
|
49
51
|
return suggestions;
|
|
50
52
|
}
|
|
51
53
|
/* ── Strategy ①: Guard 频繁命中但无 coreCode ── */
|
|
52
|
-
#checkMissingCodeExamples() {
|
|
53
|
-
const
|
|
54
|
-
.prepare(`SELECT id, title, coreCode, stats
|
|
55
|
-
FROM knowledge_entries
|
|
56
|
-
WHERE lifecycle IN ('active', 'staging') AND kind = 'rule'`)
|
|
57
|
-
.all();
|
|
54
|
+
#checkMissingCodeExamples(entries) {
|
|
55
|
+
const rules = entries.filter((e) => e.kind === 'rule');
|
|
58
56
|
const suggestions = [];
|
|
59
|
-
for (const
|
|
60
|
-
const hasCode =
|
|
57
|
+
for (const entry of rules) {
|
|
58
|
+
const hasCode = entry.coreCode && entry.coreCode.trim().length > 10;
|
|
61
59
|
if (hasCode) {
|
|
62
60
|
continue;
|
|
63
61
|
}
|
|
64
|
-
|
|
65
|
-
try {
|
|
66
|
-
stats = JSON.parse(row.stats || '{}');
|
|
67
|
-
}
|
|
68
|
-
catch {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
62
|
+
const stats = (entry.stats ?? {});
|
|
71
63
|
const guardHits = stats.guardHits || 0;
|
|
72
64
|
if (guardHits >= GUARD_HIT_THRESHOLD) {
|
|
73
65
|
suggestions.push({
|
|
74
|
-
recipeId:
|
|
75
|
-
title:
|
|
66
|
+
recipeId: entry.id,
|
|
67
|
+
title: entry.title,
|
|
76
68
|
type: 'missing_code_example',
|
|
77
69
|
description: `Guard 已命中 ${guardHits} 次但无代码示例,建议补充 coreCode 帮助开发者理解正确用法`,
|
|
78
70
|
priority: guardHits >= GUARD_HIT_THRESHOLD * 3 ? 'high' : 'medium',
|
|
@@ -83,27 +75,16 @@ export class EnhancementSuggester {
|
|
|
83
75
|
return suggestions;
|
|
84
76
|
}
|
|
85
77
|
/* ── Strategy ②: Search 高频命中但 adoptions=0 ── */
|
|
86
|
-
#checkLowAdoption() {
|
|
87
|
-
const rows = this.#db
|
|
88
|
-
.prepare(`SELECT id, title, stats
|
|
89
|
-
FROM knowledge_entries
|
|
90
|
-
WHERE lifecycle IN ('active', 'staging')`)
|
|
91
|
-
.all();
|
|
78
|
+
#checkLowAdoption(entries) {
|
|
92
79
|
const suggestions = [];
|
|
93
|
-
for (const
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
stats = JSON.parse(row.stats || '{}');
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
80
|
+
for (const entry of entries) {
|
|
81
|
+
const stats = (entry.stats ?? {});
|
|
101
82
|
const searchHits = stats.searchHits || 0;
|
|
102
83
|
const adoptions = stats.adoptions || 0;
|
|
103
84
|
if (searchHits >= SEARCH_HIT_THRESHOLD && adoptions === 0) {
|
|
104
85
|
suggestions.push({
|
|
105
|
-
recipeId:
|
|
106
|
-
title:
|
|
86
|
+
recipeId: entry.id,
|
|
87
|
+
title: entry.title,
|
|
107
88
|
type: 'low_adoption',
|
|
108
89
|
description: `搜索命中 ${searchHits} 次但采纳为 0,建议改善 usageGuide 或 whenClause 使知识更具可操作性`,
|
|
109
90
|
priority: searchHits >= SEARCH_HIT_THRESHOLD * 3 ? 'high' : 'medium',
|
|
@@ -114,28 +95,16 @@ export class EnhancementSuggester {
|
|
|
114
95
|
return suggestions;
|
|
115
96
|
}
|
|
116
97
|
/* ── Strategy ③: 同类知识中 authority 偏低 ── */
|
|
117
|
-
#checkLowAuthority() {
|
|
118
|
-
const rows = this.#db
|
|
119
|
-
.prepare(`SELECT id, title, category, stats
|
|
120
|
-
FROM knowledge_entries
|
|
121
|
-
WHERE lifecycle IN ('active', 'staging')`)
|
|
122
|
-
.all();
|
|
123
|
-
// 按 category 分组计算 authority 分位
|
|
98
|
+
#checkLowAuthority(entries) {
|
|
124
99
|
const byCategory = new Map();
|
|
125
|
-
for (const
|
|
126
|
-
|
|
127
|
-
try {
|
|
128
|
-
stats = JSON.parse(row.stats || '{}');
|
|
129
|
-
}
|
|
130
|
-
catch {
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
100
|
+
for (const entry of entries) {
|
|
101
|
+
const stats = (entry.stats ?? {});
|
|
133
102
|
const authority = stats.authority || 0;
|
|
134
|
-
const cat =
|
|
103
|
+
const cat = entry.category || 'general';
|
|
135
104
|
if (!byCategory.has(cat)) {
|
|
136
105
|
byCategory.set(cat, []);
|
|
137
106
|
}
|
|
138
|
-
byCategory.get(cat)
|
|
107
|
+
byCategory.get(cat)?.push({ id: entry.id, title: entry.title, authority });
|
|
139
108
|
}
|
|
140
109
|
const suggestions = [];
|
|
141
110
|
for (const [category, entries] of byCategory) {
|
|
@@ -163,22 +132,10 @@ export class EnhancementSuggester {
|
|
|
163
132
|
return suggestions;
|
|
164
133
|
}
|
|
165
134
|
/* ── Strategy ④: 关联 Recipe 已 deprecated ── */
|
|
166
|
-
#checkDeprecatedReferences() {
|
|
167
|
-
const rows = this.#db
|
|
168
|
-
.prepare(`SELECT id, title, relations
|
|
169
|
-
FROM knowledge_entries
|
|
170
|
-
WHERE lifecycle IN ('active', 'staging')`)
|
|
171
|
-
.all();
|
|
135
|
+
async #checkDeprecatedReferences(entries) {
|
|
172
136
|
const suggestions = [];
|
|
173
|
-
for (const
|
|
174
|
-
|
|
175
|
-
try {
|
|
176
|
-
relations = JSON.parse(row.relations || '{}');
|
|
177
|
-
}
|
|
178
|
-
catch {
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
// 检查 related, depends_on 等关系桶中的 ID
|
|
137
|
+
for (const entry of entries) {
|
|
138
|
+
const relations = (entry.relations ?? {});
|
|
182
139
|
const relatedIds = [];
|
|
183
140
|
for (const [bucket, ids] of Object.entries(relations)) {
|
|
184
141
|
if (bucket === 'deprecated_by') {
|
|
@@ -192,19 +149,18 @@ export class EnhancementSuggester {
|
|
|
192
149
|
continue;
|
|
193
150
|
}
|
|
194
151
|
// 批量检查关联条目的 lifecycle
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
});
|
|
152
|
+
for (const relId of relatedIds) {
|
|
153
|
+
const relEntry = await this.#knowledgeRepo.findById(relId);
|
|
154
|
+
if (relEntry && relEntry.lifecycle === Lifecycle.DEPRECATED) {
|
|
155
|
+
suggestions.push({
|
|
156
|
+
recipeId: entry.id,
|
|
157
|
+
title: entry.title,
|
|
158
|
+
type: 'deprecated_reference',
|
|
159
|
+
description: `引用了已废弃的 Recipe "${relEntry.title}" (${relEntry.id}),建议检查引用是否过时`,
|
|
160
|
+
priority: 'high',
|
|
161
|
+
evidence: [`referenced: ${relEntry.id}`, `referenced_title: ${relEntry.title}`],
|
|
162
|
+
});
|
|
163
|
+
}
|
|
208
164
|
}
|
|
209
165
|
}
|
|
210
166
|
return suggestions;
|
|
@@ -68,17 +68,17 @@ export declare class KnowledgeMetabolism {
|
|
|
68
68
|
/**
|
|
69
69
|
* 执行完整治理周期
|
|
70
70
|
*/
|
|
71
|
-
runFullCycle(): MetabolismReport
|
|
71
|
+
runFullCycle(): Promise<MetabolismReport>;
|
|
72
72
|
/**
|
|
73
73
|
* 只执行衰退扫描
|
|
74
74
|
*/
|
|
75
|
-
checkDecay(): DecayScoreResult[]
|
|
75
|
+
checkDecay(): Promise<DecayScoreResult[]>;
|
|
76
76
|
/**
|
|
77
77
|
* 只执行矛盾检测
|
|
78
78
|
*/
|
|
79
|
-
checkContradictions(): ContradictionResult[]
|
|
79
|
+
checkContradictions(): Promise<ContradictionResult[]>;
|
|
80
80
|
/**
|
|
81
81
|
* 只执行冗余分析
|
|
82
82
|
*/
|
|
83
|
-
checkRedundancy(): RedundancyResult[]
|
|
83
|
+
checkRedundancy(): Promise<RedundancyResult[]>;
|
|
84
84
|
}
|
|
@@ -24,6 +24,7 @@ export class KnowledgeMetabolism {
|
|
|
24
24
|
#logger = Logger.getInstance();
|
|
25
25
|
#pendingTriggers = [];
|
|
26
26
|
#debounceTimer = null;
|
|
27
|
+
#running = false;
|
|
27
28
|
constructor(options) {
|
|
28
29
|
this.#contradictionDetector = options.contradictionDetector;
|
|
29
30
|
this.#redundancyAnalyzer = options.redundancyAnalyzer;
|
|
@@ -40,13 +41,17 @@ export class KnowledgeMetabolism {
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
#scheduleMetabolism() {
|
|
44
|
+
// 当前正在执行周期时,忽略信号(防止自身产出的信号导致无限循环)
|
|
45
|
+
if (this.#running) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
43
48
|
if (this.#debounceTimer) {
|
|
44
49
|
return;
|
|
45
50
|
}
|
|
46
51
|
this.#debounceTimer = setTimeout(() => {
|
|
47
52
|
this.#debounceTimer = null;
|
|
48
|
-
if (this.#pendingTriggers.length > 0) {
|
|
49
|
-
this.runFullCycle();
|
|
53
|
+
if (this.#pendingTriggers.length > 0 && !this.#running) {
|
|
54
|
+
void this.runFullCycle();
|
|
50
55
|
this.#pendingTriggers = [];
|
|
51
56
|
}
|
|
52
57
|
}, 30_000);
|
|
@@ -54,95 +59,121 @@ export class KnowledgeMetabolism {
|
|
|
54
59
|
/**
|
|
55
60
|
* 执行完整治理周期
|
|
56
61
|
*/
|
|
57
|
-
runFullCycle() {
|
|
58
|
-
this.#
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
62
|
+
async runFullCycle() {
|
|
63
|
+
if (this.#running) {
|
|
64
|
+
this.#logger.warn('KnowledgeMetabolism: cycle already in progress, skipping');
|
|
65
|
+
return {
|
|
66
|
+
contradictions: [],
|
|
67
|
+
redundancies: [],
|
|
68
|
+
decayResults: [],
|
|
69
|
+
proposals: [],
|
|
70
|
+
summary: {
|
|
71
|
+
totalScanned: 0,
|
|
72
|
+
contradictionCount: 0,
|
|
73
|
+
redundancyCount: 0,
|
|
74
|
+
decayingCount: 0,
|
|
75
|
+
proposalCount: 0,
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
this.#running = true;
|
|
80
|
+
// 清除执行期间积累的信号,避免周期结束后立刻再次触发
|
|
81
|
+
this.#pendingTriggers = [];
|
|
82
|
+
try {
|
|
83
|
+
this.#logger.info('KnowledgeMetabolism: starting full governance cycle');
|
|
84
|
+
// 1. 衰退检测
|
|
85
|
+
const decayResults = await this.#decayDetector.scanAll();
|
|
86
|
+
// 2. 矛盾检测
|
|
87
|
+
const contradictions = await this.#contradictionDetector.detectAll();
|
|
88
|
+
// 3. 冗余分析
|
|
89
|
+
const redundancies = await this.#redundancyAnalyzer.analyzeAll();
|
|
90
|
+
// 4. 生成进化提案
|
|
91
|
+
const proposals = [
|
|
92
|
+
...this.#proposalsFromContradictions(contradictions),
|
|
93
|
+
...this.#proposalsFromRedundancies(redundancies),
|
|
94
|
+
...this.#proposalsFromDecay(decayResults),
|
|
95
|
+
];
|
|
96
|
+
// 5. 持久化提案到 evolution_proposals 表
|
|
97
|
+
let persistedCount = 0;
|
|
98
|
+
if (this.#proposalRepo && proposals.length > 0) {
|
|
99
|
+
for (const p of proposals) {
|
|
100
|
+
const sourceMap = {
|
|
101
|
+
contradiction: 'metabolism',
|
|
102
|
+
redundancy: 'metabolism',
|
|
103
|
+
decay: 'decay-scan',
|
|
104
|
+
enhancement: 'metabolism',
|
|
105
|
+
};
|
|
106
|
+
const record = this.#proposalRepo.create({
|
|
107
|
+
type: p.type,
|
|
108
|
+
targetRecipeId: p.targetRecipeId,
|
|
109
|
+
relatedRecipeIds: p.relatedRecipeIds,
|
|
110
|
+
confidence: p.confidence,
|
|
111
|
+
source: sourceMap[p.source] ?? 'metabolism',
|
|
112
|
+
description: p.description,
|
|
113
|
+
evidence: p.evidence.map((e) => ({ detail: e })),
|
|
114
|
+
});
|
|
115
|
+
if (record) {
|
|
116
|
+
persistedCount++;
|
|
117
|
+
}
|
|
92
118
|
}
|
|
93
119
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
120
|
+
// 6. 写入治理报告(降级:同时写 ReportStore)
|
|
121
|
+
if (this.#reportStore && proposals.length > 0) {
|
|
122
|
+
void this.#reportStore.write({
|
|
123
|
+
category: 'governance',
|
|
124
|
+
type: 'metabolism_cycle',
|
|
125
|
+
producer: 'KnowledgeMetabolism',
|
|
126
|
+
data: {
|
|
127
|
+
proposalCount: proposals.length,
|
|
128
|
+
persistedCount,
|
|
129
|
+
contradictionCount: contradictions.length,
|
|
130
|
+
redundancyCount: redundancies.length,
|
|
131
|
+
decayingCount: decayResults.filter((d) => d.level !== 'healthy' && d.level !== 'watch')
|
|
132
|
+
.length,
|
|
133
|
+
},
|
|
134
|
+
timestamp: Date.now(),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const report = {
|
|
138
|
+
contradictions,
|
|
139
|
+
redundancies,
|
|
140
|
+
decayResults,
|
|
141
|
+
proposals,
|
|
142
|
+
summary: {
|
|
143
|
+
totalScanned: decayResults.length,
|
|
104
144
|
contradictionCount: contradictions.length,
|
|
105
145
|
redundancyCount: redundancies.length,
|
|
106
146
|
decayingCount: decayResults.filter((d) => d.level !== 'healthy' && d.level !== 'watch')
|
|
107
147
|
.length,
|
|
148
|
+
proposalCount: proposals.length,
|
|
108
149
|
},
|
|
109
|
-
|
|
110
|
-
});
|
|
150
|
+
};
|
|
151
|
+
this.#logger.info(`KnowledgeMetabolism: cycle complete — ${report.summary.proposalCount} proposals generated`);
|
|
152
|
+
return report;
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
this.#running = false;
|
|
156
|
+
// 清除周期期间积累的信号,防止自身产出的信号立即触发下一轮
|
|
157
|
+
this.#pendingTriggers = [];
|
|
111
158
|
}
|
|
112
|
-
const report = {
|
|
113
|
-
contradictions,
|
|
114
|
-
redundancies,
|
|
115
|
-
decayResults,
|
|
116
|
-
proposals,
|
|
117
|
-
summary: {
|
|
118
|
-
totalScanned: decayResults.length,
|
|
119
|
-
contradictionCount: contradictions.length,
|
|
120
|
-
redundancyCount: redundancies.length,
|
|
121
|
-
decayingCount: decayResults.filter((d) => d.level !== 'healthy' && d.level !== 'watch')
|
|
122
|
-
.length,
|
|
123
|
-
proposalCount: proposals.length,
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
this.#logger.info(`KnowledgeMetabolism: cycle complete — ${report.summary.proposalCount} proposals generated`);
|
|
127
|
-
return report;
|
|
128
159
|
}
|
|
129
160
|
/**
|
|
130
161
|
* 只执行衰退扫描
|
|
131
162
|
*/
|
|
132
|
-
checkDecay() {
|
|
133
|
-
return this.#decayDetector.scanAll();
|
|
163
|
+
async checkDecay() {
|
|
164
|
+
return await this.#decayDetector.scanAll();
|
|
134
165
|
}
|
|
135
166
|
/**
|
|
136
167
|
* 只执行矛盾检测
|
|
137
168
|
*/
|
|
138
|
-
checkContradictions() {
|
|
139
|
-
return this.#contradictionDetector.detectAll();
|
|
169
|
+
async checkContradictions() {
|
|
170
|
+
return await this.#contradictionDetector.detectAll();
|
|
140
171
|
}
|
|
141
172
|
/**
|
|
142
173
|
* 只执行冗余分析
|
|
143
174
|
*/
|
|
144
|
-
checkRedundancy() {
|
|
145
|
-
return this.#redundancyAnalyzer.analyzeAll();
|
|
175
|
+
async checkRedundancy() {
|
|
176
|
+
return await this.#redundancyAnalyzer.analyzeAll();
|
|
146
177
|
}
|
|
147
178
|
/* ── Proposal Generation ── */
|
|
148
179
|
#proposalsFromContradictions(results) {
|
|
@@ -17,17 +17,10 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import type { SignalBus } from '../../infrastructure/signal/SignalBus.js';
|
|
19
19
|
import type { ProposalRepository, ProposalType } from '../../repository/evolution/ProposalRepository.js';
|
|
20
|
+
import type { KnowledgeEdgeRepositoryImpl } from '../../repository/knowledge/KnowledgeEdgeRepository.js';
|
|
21
|
+
import type KnowledgeRepositoryImpl from '../../repository/knowledge/KnowledgeRepository.impl.js';
|
|
20
22
|
import type { ContentPatcher } from './ContentPatcher.js';
|
|
21
23
|
import type { RecipeLifecycleSupervisor } from './RecipeLifecycleSupervisor.js';
|
|
22
|
-
interface DatabaseLike {
|
|
23
|
-
prepare(sql: string): {
|
|
24
|
-
all(...params: unknown[]): Record<string, unknown>[];
|
|
25
|
-
get(...params: unknown[]): Record<string, unknown> | undefined;
|
|
26
|
-
run(...params: unknown[]): {
|
|
27
|
-
changes: number;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
24
|
export interface ProposalExecutionResult {
|
|
32
25
|
executed: {
|
|
33
26
|
id: string;
|
|
@@ -51,16 +44,16 @@ export interface ProposalExecutionResult {
|
|
|
51
44
|
}
|
|
52
45
|
export declare class ProposalExecutor {
|
|
53
46
|
#private;
|
|
54
|
-
constructor(
|
|
47
|
+
constructor(knowledgeRepo: KnowledgeRepositoryImpl, repo: ProposalRepository, options?: {
|
|
55
48
|
signalBus?: SignalBus;
|
|
56
49
|
contentPatcher?: ContentPatcher;
|
|
57
50
|
supervisor?: RecipeLifecycleSupervisor;
|
|
51
|
+
knowledgeEdgeRepo?: KnowledgeEdgeRepositoryImpl;
|
|
58
52
|
});
|
|
59
53
|
/**
|
|
60
54
|
* 定期调用(UiStartupTasks Stage 5)
|
|
61
55
|
*
|
|
62
56
|
* 扫描所有到期 Proposal → 评估 → 执行/拒绝/过期
|
|
63
57
|
*/
|
|
64
|
-
checkAndExecute(): ProposalExecutionResult
|
|
58
|
+
checkAndExecute(): Promise<ProposalExecutionResult>;
|
|
65
59
|
}
|
|
66
|
-
export {};
|