cogmem 3.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BENCHMARKS.md +62 -0
- package/CHANGELOG.md +215 -0
- package/CONCURRENT_ACCESS.md +27 -0
- package/CONTRIBUTING.md +32 -0
- package/LICENSE +21 -0
- package/MEMORY_ATLAS.md +101 -0
- package/MEMORY_MODEL.md +179 -0
- package/README.md +751 -0
- package/RECALL_EXPLAINABILITY.md +152 -0
- package/RELEASE_CHECKLIST.md +92 -0
- package/SECURITY.md +21 -0
- package/dist/adapters/MarkdownSourceLoader.d.ts +5 -0
- package/dist/adapters/MarkdownSourceLoader.js +19 -0
- package/dist/adapters/conversation/ConversationMarkdownAdapter.d.ts +9 -0
- package/dist/adapters/conversation/ConversationMarkdownAdapter.js +233 -0
- package/dist/adapters/hermes/HermesStateDbAdapter.d.ts +10 -0
- package/dist/adapters/hermes/HermesStateDbAdapter.js +268 -0
- package/dist/adapters/hermes/HermesWorkspaceProfile.d.ts +15 -0
- package/dist/adapters/hermes/HermesWorkspaceProfile.js +82 -0
- package/dist/adapters/index.d.ts +15 -0
- package/dist/adapters/index.js +12 -0
- package/dist/adapters/openclaw/OpenClawAdapterSupport.d.ts +14 -0
- package/dist/adapters/openclaw/OpenClawAdapterSupport.js +29 -0
- package/dist/adapters/openclaw/OpenClawDailyMemoryAdapter.d.ts +8 -0
- package/dist/adapters/openclaw/OpenClawDailyMemoryAdapter.js +35 -0
- package/dist/adapters/openclaw/OpenClawMemoryIndexAdapter.d.ts +8 -0
- package/dist/adapters/openclaw/OpenClawMemoryIndexAdapter.js +23 -0
- package/dist/adapters/openclaw/OpenClawPersonaAdapter.d.ts +8 -0
- package/dist/adapters/openclaw/OpenClawPersonaAdapter.js +24 -0
- package/dist/adapters/openclaw/OpenClawSessionAdapter.d.ts +8 -0
- package/dist/adapters/openclaw/OpenClawSessionAdapter.js +15 -0
- package/dist/adapters/openclaw/OpenClawUserProfileAdapter.d.ts +8 -0
- package/dist/adapters/openclaw/OpenClawUserProfileAdapter.js +24 -0
- package/dist/adapters/openclaw/OpenClawWorkspaceProfile.d.ts +38 -0
- package/dist/adapters/openclaw/OpenClawWorkspaceProfile.js +199 -0
- package/dist/adapters/soul/SoulMarkdownAdapter.d.ts +14 -0
- package/dist/adapters/soul/SoulMarkdownAdapter.js +255 -0
- package/dist/adapters/types.d.ts +97 -0
- package/dist/adapters/types.js +185 -0
- package/dist/agent/AgentMemoryBackend.d.ts +291 -0
- package/dist/agent/AgentMemoryBackend.js +1272 -0
- package/dist/agent/AgentRecallQueryCompiler.d.ts +20 -0
- package/dist/agent/AgentRecallQueryCompiler.js +289 -0
- package/dist/agent/ContextHygiene.d.ts +9 -0
- package/dist/agent/ContextHygiene.js +20 -0
- package/dist/agent/MemoryUsageReceipt.d.ts +35 -0
- package/dist/agent/MemoryUsageReceipt.js +136 -0
- package/dist/agent/SessionWorkingState.d.ts +20 -0
- package/dist/agent/SessionWorkingState.js +94 -0
- package/dist/agent/index.d.ts +6 -0
- package/dist/agent/index.js +5 -0
- package/dist/algorithm/AlgorithmReviewBackend.d.ts +84 -0
- package/dist/algorithm/AlgorithmReviewBackend.js +261 -0
- package/dist/algorithm/AlgorithmReviewMetrics.d.ts +23 -0
- package/dist/algorithm/AlgorithmReviewMetrics.js +25 -0
- package/dist/algorithm/Phase2ModelAlgorithmReviewBackend.d.ts +38 -0
- package/dist/algorithm/Phase2ModelAlgorithmReviewBackend.js +372 -0
- package/dist/assets/FileAssetIngestionService.d.ts +32 -0
- package/dist/assets/FileAssetIngestionService.js +133 -0
- package/dist/assets/FileAssetStore.d.ts +36 -0
- package/dist/assets/FileAssetStore.js +152 -0
- package/dist/assets/FileBlockStore.d.ts +12 -0
- package/dist/assets/FileBlockStore.js +110 -0
- package/dist/assets/FileChunkStore.d.ts +23 -0
- package/dist/assets/FileChunkStore.js +179 -0
- package/dist/assets/FileChunker.d.ts +10 -0
- package/dist/assets/FileChunker.js +69 -0
- package/dist/assets/FileLoaderRegistry.d.ts +8 -0
- package/dist/assets/FileLoaderRegistry.js +21 -0
- package/dist/assets/FileLoaders.d.ts +37 -0
- package/dist/assets/FileLoaders.js +268 -0
- package/dist/assets/index.d.ts +10 -0
- package/dist/assets/index.js +7 -0
- package/dist/assets/providers/types.d.ts +47 -0
- package/dist/assets/providers/types.js +1 -0
- package/dist/assets/types.d.ts +159 -0
- package/dist/assets/types.js +1 -0
- package/dist/atlas/ActionFrameExtractor.d.ts +15 -0
- package/dist/atlas/ActionFrameExtractor.js +135 -0
- package/dist/atlas/MemoryAtlasIndexer.d.ts +32 -0
- package/dist/atlas/MemoryAtlasIndexer.js +74 -0
- package/dist/atlas/MemoryAtlasQueryCompiler.d.ts +23 -0
- package/dist/atlas/MemoryAtlasQueryCompiler.js +55 -0
- package/dist/atlas/MemoryAtlasService.d.ts +25 -0
- package/dist/atlas/MemoryAtlasService.js +216 -0
- package/dist/atlas/MemoryAtlasTypes.d.ts +107 -0
- package/dist/atlas/MemoryAtlasTypes.js +1 -0
- package/dist/atlas/index.d.ts +6 -0
- package/dist/atlas/index.js +5 -0
- package/dist/backend/SemanticBackend.d.ts +40 -0
- package/dist/backend/SemanticBackend.js +107 -0
- package/dist/batch/IngestionCursorStore.d.ts +52 -0
- package/dist/batch/IngestionCursorStore.js +153 -0
- package/dist/batch/InstalledBatchProcessor.d.ts +88 -0
- package/dist/batch/InstalledBatchProcessor.js +179 -0
- package/dist/batch/SourceOnboarding.d.ts +56 -0
- package/dist/batch/SourceOnboarding.js +366 -0
- package/dist/belief/BeliefGovernanceService.d.ts +59 -0
- package/dist/belief/BeliefGovernanceService.js +183 -0
- package/dist/belief/BeliefStore.d.ts +78 -0
- package/dist/belief/BeliefStore.js +898 -0
- package/dist/benchmark/BenchmarkRegistry.d.ts +16 -0
- package/dist/benchmark/BenchmarkRegistry.js +97 -0
- package/dist/benchmark/BenchmarkReport.d.ts +23 -0
- package/dist/benchmark/BenchmarkReport.js +62 -0
- package/dist/benchmark/BenchmarkRunner.d.ts +27 -0
- package/dist/benchmark/BenchmarkRunner.js +64 -0
- package/dist/benchmark/BrainEval.d.ts +134 -0
- package/dist/benchmark/BrainEval.js +252 -0
- package/dist/benchmark/ExternalBenchmarkRunner.d.ts +8 -0
- package/dist/benchmark/ExternalBenchmarkRunner.js +12 -0
- package/dist/benchmark/LongMemEvalAdapter.d.ts +46 -0
- package/dist/benchmark/LongMemEvalAdapter.js +88 -0
- package/dist/benchmark/LongMemEvalCli.d.ts +6 -0
- package/dist/benchmark/LongMemEvalCli.js +26 -0
- package/dist/bin/CliJson.d.ts +17 -0
- package/dist/bin/CliJson.js +20 -0
- package/dist/bin/brain-eval.d.ts +3 -0
- package/dist/bin/brain-eval.js +46 -0
- package/dist/bin/cogmem.d.ts +3 -0
- package/dist/bin/cogmem.js +95 -0
- package/dist/bin/compact.d.ts +3 -0
- package/dist/bin/compact.js +96 -0
- package/dist/bin/connect.d.ts +3 -0
- package/dist/bin/connect.js +398 -0
- package/dist/bin/doctor.d.ts +3 -0
- package/dist/bin/doctor.js +171 -0
- package/dist/bin/dream.d.ts +3 -0
- package/dist/bin/dream.js +65 -0
- package/dist/bin/episode.d.ts +3 -0
- package/dist/bin/episode.js +268 -0
- package/dist/bin/explain-recall.d.ts +3 -0
- package/dist/bin/explain-recall.js +139 -0
- package/dist/bin/import-hermes.d.ts +3 -0
- package/dist/bin/import-hermes.js +6 -0
- package/dist/bin/import-openclaw.d.ts +3 -0
- package/dist/bin/import-openclaw.js +6 -0
- package/dist/bin/import-support.d.ts +43 -0
- package/dist/bin/import-support.js +528 -0
- package/dist/bin/init.d.ts +30 -0
- package/dist/bin/init.js +761 -0
- package/dist/bin/mcp.d.ts +3 -0
- package/dist/bin/mcp.js +52 -0
- package/dist/bin/memory.d.ts +3 -0
- package/dist/bin/memory.js +803 -0
- package/dist/bin/migrate-vectors.d.ts +3 -0
- package/dist/bin/migrate-vectors.js +74 -0
- package/dist/bin/migrate.d.ts +3 -0
- package/dist/bin/migrate.js +95 -0
- package/dist/bin/normalize-transcript.d.ts +16 -0
- package/dist/bin/normalize-transcript.js +153 -0
- package/dist/bin/openclaw.d.ts +3 -0
- package/dist/bin/openclaw.js +78 -0
- package/dist/bin/prospective.d.ts +3 -0
- package/dist/bin/prospective.js +115 -0
- package/dist/bin/re-embed.d.ts +3 -0
- package/dist/bin/re-embed.js +46 -0
- package/dist/bin/repair.d.ts +3 -0
- package/dist/bin/repair.js +118 -0
- package/dist/bin/snapshot.d.ts +3 -0
- package/dist/bin/snapshot.js +100 -0
- package/dist/bin/strategy.d.ts +3 -0
- package/dist/bin/strategy.js +66 -0
- package/dist/bin/update-release.d.ts +15 -0
- package/dist/bin/update-release.js +62 -0
- package/dist/bin/update.d.ts +3 -0
- package/dist/bin/update.js +215 -0
- package/dist/binding/BindingClassifier.d.ts +19 -0
- package/dist/binding/BindingClassifier.js +270 -0
- package/dist/binding/BindingDecisionEngine.d.ts +11 -0
- package/dist/binding/BindingDecisionEngine.js +13 -0
- package/dist/binding/ClaimKeyGenerator.d.ts +4 -0
- package/dist/binding/ClaimKeyGenerator.js +21 -0
- package/dist/binding/MemoryBindingService.d.ts +28 -0
- package/dist/binding/MemoryBindingService.js +283 -0
- package/dist/binding/MemoryBindingTypes.d.ts +140 -0
- package/dist/binding/MemoryBindingTypes.js +1 -0
- package/dist/binding/TopicPathRegistry.d.ts +5 -0
- package/dist/binding/TopicPathRegistry.js +33 -0
- package/dist/binding/index.d.ts +12 -0
- package/dist/binding/index.js +6 -0
- package/dist/boards/ApprovalBoard.d.ts +14 -0
- package/dist/boards/ApprovalBoard.js +32 -0
- package/dist/boards/Board.d.ts +23 -0
- package/dist/boards/Board.js +1 -0
- package/dist/boards/BoardEventBuffer.d.ts +10 -0
- package/dist/boards/BoardEventBuffer.js +22 -0
- package/dist/boards/BoardEventBus.d.ts +15 -0
- package/dist/boards/BoardEventBus.js +38 -0
- package/dist/boards/BoardEventFilter.d.ts +5 -0
- package/dist/boards/BoardEventFilter.js +1 -0
- package/dist/boards/BoardRegistry.d.ts +11 -0
- package/dist/boards/BoardRegistry.js +15 -0
- package/dist/boards/ContextBoard.d.ts +15 -0
- package/dist/boards/ContextBoard.js +33 -0
- package/dist/boards/MemoryBoard.d.ts +13 -0
- package/dist/boards/MemoryBoard.js +30 -0
- package/dist/boards/ProcessBoard.d.ts +16 -0
- package/dist/boards/ProcessBoard.js +56 -0
- package/dist/boards/ProposalBoard.d.ts +13 -0
- package/dist/boards/ProposalBoard.js +37 -0
- package/dist/boards/ReasoningTraceBoard.d.ts +11 -0
- package/dist/boards/ReasoningTraceBoard.js +34 -0
- package/dist/boards/TaskBoard.d.ts +14 -0
- package/dist/boards/TaskBoard.js +37 -0
- package/dist/boards/index.d.ts +13 -0
- package/dist/boards/index.js +12 -0
- package/dist/config/CogmemConfig.d.ts +43 -0
- package/dist/config/CogmemConfig.js +247 -0
- package/dist/config/VectorDimension.d.ts +13 -0
- package/dist/config/VectorDimension.js +53 -0
- package/dist/context/ContextCortex.d.ts +71 -0
- package/dist/context/ContextCortex.js +156 -0
- package/dist/context/index.d.ts +2 -0
- package/dist/context/index.js +1 -0
- package/dist/core/ImportanceLevels.d.ts +4 -0
- package/dist/core/ImportanceLevels.js +6 -0
- package/dist/core/IntentParser.d.ts +12 -0
- package/dist/core/IntentParser.js +211 -0
- package/dist/core/MemoryGraph.d.ts +100 -0
- package/dist/core/MemoryGraph.js +860 -0
- package/dist/core/Metabolism.d.ts +43 -0
- package/dist/core/Metabolism.js +196 -0
- package/dist/core/Neuron.d.ts +20 -0
- package/dist/core/Neuron.js +51 -0
- package/dist/core/QueryClassifier.d.ts +36 -0
- package/dist/core/QueryClassifier.js +161 -0
- package/dist/core/Reflection.d.ts +42 -0
- package/dist/core/Reflection.js +183 -0
- package/dist/core/ResonanceCore.d.ts +26 -0
- package/dist/core/ResonanceCore.js +115 -0
- package/dist/core/Synapse.d.ts +10 -0
- package/dist/core/Synapse.js +27 -0
- package/dist/core/TwoStagePulseRanker.d.ts +16 -0
- package/dist/core/TwoStagePulseRanker.js +120 -0
- package/dist/dream/DreamScheduler.d.ts +47 -0
- package/dist/dream/DreamScheduler.js +156 -0
- package/dist/dream/index.d.ts +2 -0
- package/dist/dream/index.js +1 -0
- package/dist/embedding/EmbeddingProvider.d.ts +16 -0
- package/dist/embedding/EmbeddingProvider.js +12 -0
- package/dist/embedding/NeuronEmbeddingStore.d.ts +38 -0
- package/dist/embedding/NeuronEmbeddingStore.js +193 -0
- package/dist/embedding/OllamaEmbeddingProvider.d.ts +21 -0
- package/dist/embedding/OllamaEmbeddingProvider.js +65 -0
- package/dist/embedding/QwenAPIEmbeddingProvider.d.ts +26 -0
- package/dist/embedding/QwenAPIEmbeddingProvider.js +53 -0
- package/dist/embedding/ReEmbeddingPipeline.d.ts +30 -0
- package/dist/embedding/ReEmbeddingPipeline.js +119 -0
- package/dist/embedding/ReEmbeddingStatus.d.ts +10 -0
- package/dist/embedding/ReEmbeddingStatus.js +1 -0
- package/dist/embedding/index.d.ts +11 -0
- package/dist/embedding/index.js +5 -0
- package/dist/encryption/AesGcmEncryptionProvider.d.ts +9 -0
- package/dist/encryption/AesGcmEncryptionProvider.js +42 -0
- package/dist/encryption/EncryptionProvider.d.ts +6 -0
- package/dist/encryption/EncryptionProvider.js +3 -0
- package/dist/encryption/index.d.ts +4 -0
- package/dist/encryption/index.js +2 -0
- package/dist/engine/BeliefExtractor.d.ts +48 -0
- package/dist/engine/BeliefExtractor.js +1189 -0
- package/dist/engine/CognitiveGraphCompiler.d.ts +24 -0
- package/dist/engine/CognitiveGraphCompiler.js +243 -0
- package/dist/engine/ConsolidationPipeline.d.ts +66 -0
- package/dist/engine/ConsolidationPipeline.js +376 -0
- package/dist/engine/ConsolidationTrigger.d.ts +18 -0
- package/dist/engine/ConsolidationTrigger.js +41 -0
- package/dist/engine/CrossTopicSynthesizer.d.ts +28 -0
- package/dist/engine/CrossTopicSynthesizer.js +70 -0
- package/dist/engine/CrossTopicTrigger.d.ts +17 -0
- package/dist/engine/CrossTopicTrigger.js +29 -0
- package/dist/engine/DeepWriteConfig.d.ts +14 -0
- package/dist/engine/DeepWriteConfig.js +37 -0
- package/dist/engine/DeepWriteMemoryCompiler.d.ts +43 -0
- package/dist/engine/DeepWriteMemoryCompiler.js +42 -0
- package/dist/engine/DeepWriteMemoryOrchestrator.d.ts +60 -0
- package/dist/engine/DeepWriteMemoryOrchestrator.js +175 -0
- package/dist/engine/DeepWritePromotionPolicy.d.ts +48 -0
- package/dist/engine/DeepWritePromotionPolicy.js +514 -0
- package/dist/engine/DeepWriteRedactor.d.ts +14 -0
- package/dist/engine/DeepWriteRedactor.js +53 -0
- package/dist/engine/DreamCuratorSchedule.d.ts +18 -0
- package/dist/engine/DreamCuratorSchedule.js +95 -0
- package/dist/engine/DreamCuratorWorker.d.ts +67 -0
- package/dist/engine/DreamCuratorWorker.js +908 -0
- package/dist/engine/EntityResolutionEngine.d.ts +45 -0
- package/dist/engine/EntityResolutionEngine.js +105 -0
- package/dist/engine/EpisodicSemanticDistiller.d.ts +25 -0
- package/dist/engine/EpisodicSemanticDistiller.js +68 -0
- package/dist/engine/EvolutionVerifier.d.ts +39 -0
- package/dist/engine/EvolutionVerifier.js +104 -0
- package/dist/engine/FactCompiler.d.ts +41 -0
- package/dist/engine/FactCompiler.js +820 -0
- package/dist/engine/GraphCommunityEngine.d.ts +20 -0
- package/dist/engine/GraphCommunityEngine.js +91 -0
- package/dist/engine/ImportanceSignalDetector.d.ts +11 -0
- package/dist/engine/ImportanceSignalDetector.js +51 -0
- package/dist/engine/IngestionEngine.d.ts +44 -0
- package/dist/engine/IngestionEngine.js +182 -0
- package/dist/engine/InteractionBinder.d.ts +16 -0
- package/dist/engine/InteractionBinder.js +87 -0
- package/dist/engine/LocalSemanticCompiler.d.ts +40 -0
- package/dist/engine/LocalSemanticCompiler.js +111 -0
- package/dist/engine/MemoryConsolidationEngine.d.ts +11 -0
- package/dist/engine/MemoryConsolidationEngine.js +21 -0
- package/dist/engine/MemoryGate.d.ts +10 -0
- package/dist/engine/MemoryGate.js +34 -0
- package/dist/engine/OfflineConsolidationPipeline.d.ts +148 -0
- package/dist/engine/OfflineConsolidationPipeline.js +670 -0
- package/dist/engine/OrphanCleaner.d.ts +15 -0
- package/dist/engine/OrphanCleaner.js +27 -0
- package/dist/engine/PipelineMetrics.d.ts +32 -0
- package/dist/engine/PipelineMetrics.js +126 -0
- package/dist/engine/PrincipleDecayPolicy.d.ts +17 -0
- package/dist/engine/PrincipleDecayPolicy.js +64 -0
- package/dist/engine/TopologyCompiler.d.ts +25 -0
- package/dist/engine/TopologyCompiler.js +276 -0
- package/dist/engine/WorkingMemoryDelta.d.ts +23 -0
- package/dist/engine/WorkingMemoryDelta.js +63 -0
- package/dist/entity/EntityGovernanceService.d.ts +47 -0
- package/dist/entity/EntityGovernanceService.js +215 -0
- package/dist/entity/index.d.ts +3 -0
- package/dist/entity/index.js +1 -0
- package/dist/episode/CogmemBlockStripper.d.ts +11 -0
- package/dist/episode/CogmemBlockStripper.js +58 -0
- package/dist/episode/CorrectionResolver.d.ts +30 -0
- package/dist/episode/CorrectionResolver.js +17 -0
- package/dist/episode/EpisodeAssembler.d.ts +54 -0
- package/dist/episode/EpisodeAssembler.js +203 -0
- package/dist/episode/EpisodeImportIdentity.d.ts +7 -0
- package/dist/episode/EpisodeImportIdentity.js +17 -0
- package/dist/episode/EpisodeSemanticSummarizer.d.ts +4 -0
- package/dist/episode/EpisodeSemanticSummarizer.js +31 -0
- package/dist/episode/EpisodeStore.d.ts +189 -0
- package/dist/episode/EpisodeStore.js +680 -0
- package/dist/episode/EpisodeTypes.d.ts +96 -0
- package/dist/episode/EpisodeTypes.js +1 -0
- package/dist/episode/TurnRelationClassifier.d.ts +40 -0
- package/dist/episode/TurnRelationClassifier.js +205 -0
- package/dist/episode/index.d.ts +9 -0
- package/dist/episode/index.js +8 -0
- package/dist/eval/datasets/contradiction_injection.d.ts +3 -0
- package/dist/eval/datasets/contradiction_injection.js +56 -0
- package/dist/eval/datasets/noisy_tool_output_corpus.d.ts +16 -0
- package/dist/eval/datasets/noisy_tool_output_corpus.js +59 -0
- package/dist/eval/datasets/synthetic_long_conversation.d.ts +40 -0
- package/dist/eval/datasets/synthetic_long_conversation.js +136 -0
- package/dist/eval/runners/EvalRunner.d.ts +12 -0
- package/dist/eval/runners/EvalRunner.js +66 -0
- package/dist/eval/runners/ReportFormatter.d.ts +13 -0
- package/dist/eval/runners/ReportFormatter.js +59 -0
- package/dist/eval/strategy/ContextOutcomeStore.d.ts +12 -0
- package/dist/eval/strategy/ContextOutcomeStore.js +44 -0
- package/dist/eval/strategy/ContextPolicyScorer.d.ts +25 -0
- package/dist/eval/strategy/ContextPolicyScorer.js +58 -0
- package/dist/eval/strategy/MemoryUseJudge.d.ts +49 -0
- package/dist/eval/strategy/MemoryUseJudge.js +75 -0
- package/dist/eval/strategy/StrategyDiversitySelector.d.ts +8 -0
- package/dist/eval/strategy/StrategyDiversitySelector.js +44 -0
- package/dist/eval/strategy/StrategyRolloutEvaluator.d.ts +15 -0
- package/dist/eval/strategy/StrategyRolloutEvaluator.js +30 -0
- package/dist/eval/strategy/index.d.ts +6 -0
- package/dist/eval/strategy/index.js +5 -0
- package/dist/factory.d.ts +726 -0
- package/dist/factory.js +2118 -0
- package/dist/governance/CandidateReviewService.d.ts +33 -0
- package/dist/governance/CandidateReviewService.js +126 -0
- package/dist/governance/ContradictionResolver.d.ts +22 -0
- package/dist/governance/ContradictionResolver.js +54 -0
- package/dist/governance/CredibilityScorer.d.ts +10 -0
- package/dist/governance/CredibilityScorer.js +29 -0
- package/dist/governance/DecayPolicy.d.ts +18 -0
- package/dist/governance/DecayPolicy.js +28 -0
- package/dist/governance/MemoryExplain.d.ts +46 -0
- package/dist/governance/MemoryExplain.js +62 -0
- package/dist/governance/MemoryGovernanceExecutor.d.ts +18 -0
- package/dist/governance/MemoryGovernanceExecutor.js +37 -0
- package/dist/governance/MemoryGovernancePlan.d.ts +36 -0
- package/dist/governance/MemoryGovernancePlan.js +1 -0
- package/dist/governance/MemoryGovernanceValidator.d.ts +13 -0
- package/dist/governance/MemoryGovernanceValidator.js +53 -0
- package/dist/governance/ObservationHygieneRules.d.ts +17 -0
- package/dist/governance/ObservationHygieneRules.js +28 -0
- package/dist/governance/PiiRedactor.d.ts +20 -0
- package/dist/governance/PiiRedactor.js +37 -0
- package/dist/governance/SupersedeChain.d.ts +21 -0
- package/dist/governance/SupersedeChain.js +107 -0
- package/dist/governance/index.d.ts +14 -0
- package/dist/governance/index.js +6 -0
- package/dist/graph/BrainGraphView.d.ts +20 -0
- package/dist/graph/BrainGraphView.js +45 -0
- package/dist/host/openclaw/AutoMemoryPluginInstaller.d.ts +45 -0
- package/dist/host/openclaw/AutoMemoryPluginInstaller.js +1904 -0
- package/dist/internal.d.ts +148 -0
- package/dist/internal.js +144 -0
- package/dist/lexicon/coreMemoryLexicon.d.ts +96 -0
- package/dist/lexicon/coreMemoryLexicon.js +525 -0
- package/dist/lexicon/language-packs/en.d.ts +42 -0
- package/dist/lexicon/language-packs/en.js +41 -0
- package/dist/lexicon/language-packs/zh.d.ts +42 -0
- package/dist/lexicon/language-packs/zh.js +41 -0
- package/dist/lexicon/zh/entities.d.ts +2 -0
- package/dist/lexicon/zh/entities.js +17 -0
- package/dist/lexicon/zh/index.d.ts +5 -0
- package/dist/lexicon/zh/index.js +3 -0
- package/dist/lexicon/zh/stopwords.d.ts +2 -0
- package/dist/lexicon/zh/stopwords.js +22 -0
- package/dist/lexicon/zh/topics.d.ts +6 -0
- package/dist/lexicon/zh/topics.js +52 -0
- package/dist/mcp/CoreMcpTools.d.ts +33 -0
- package/dist/mcp/CoreMcpTools.js +832 -0
- package/dist/mcp/server.d.ts +5 -0
- package/dist/mcp/server.js +29 -0
- package/dist/meta/MetaObservationCollector.d.ts +37 -0
- package/dist/meta/MetaObservationCollector.js +348 -0
- package/dist/meta/PolicyProposalGenerator.d.ts +11 -0
- package/dist/meta/PolicyProposalGenerator.js +159 -0
- package/dist/meta/ProposalApplier.d.ts +18 -0
- package/dist/meta/ProposalApplier.js +91 -0
- package/dist/meta/ProposalConfigOverlay.d.ts +13 -0
- package/dist/meta/ProposalConfigOverlay.js +27 -0
- package/dist/meta/ProposalEvalRunner.d.ts +31 -0
- package/dist/meta/ProposalEvalRunner.js +62 -0
- package/dist/meta/ProposalLedger.d.ts +34 -0
- package/dist/meta/ProposalLedger.js +242 -0
- package/dist/meta/types.d.ts +63 -0
- package/dist/meta/types.js +1 -0
- package/dist/migrations/0001_init.d.ts +4 -0
- package/dist/migrations/0001_init.js +67 -0
- package/dist/migrations/0002_v06_platform.d.ts +10 -0
- package/dist/migrations/0002_v06_platform.js +103 -0
- package/dist/migrations/0003_v07_dialogues.d.ts +9 -0
- package/dist/migrations/0003_v07_dialogues.js +53 -0
- package/dist/migrations/0004_v09_self_improvement.d.ts +9 -0
- package/dist/migrations/0004_v09_self_improvement.js +100 -0
- package/dist/migrations/0005_dialogue_buffer.d.ts +8 -0
- package/dist/migrations/0005_dialogue_buffer.js +44 -0
- package/dist/migrations/0006_deep_write_memory.d.ts +3 -0
- package/dist/migrations/0006_deep_write_memory.js +54 -0
- package/dist/migrations/0007_deep_write_summaries.d.ts +3 -0
- package/dist/migrations/0007_deep_write_summaries.js +24 -0
- package/dist/migrations/0009_memory_importance.d.ts +3 -0
- package/dist/migrations/0009_memory_importance.js +18 -0
- package/dist/migrations/0010_skill_neurons.d.ts +3 -0
- package/dist/migrations/0010_skill_neurons.js +19 -0
- package/dist/migrations/0011_topic_path.d.ts +3 -0
- package/dist/migrations/0011_topic_path.js +19 -0
- package/dist/migrations/0012_governance_security.d.ts +3 -0
- package/dist/migrations/0012_governance_security.js +23 -0
- package/dist/migrations/0015_memory_governance.d.ts +3 -0
- package/dist/migrations/0015_memory_governance.js +74 -0
- package/dist/migrations/0016_entity_governance.d.ts +3 -0
- package/dist/migrations/0016_entity_governance.js +40 -0
- package/dist/migrations/0017_belief_graph.d.ts +3 -0
- package/dist/migrations/0017_belief_graph.js +41 -0
- package/dist/migrations/0018_temporal_memory.d.ts +3 -0
- package/dist/migrations/0018_temporal_memory.js +25 -0
- package/dist/migrations/0019_context_cortex.d.ts +3 -0
- package/dist/migrations/0019_context_cortex.js +19 -0
- package/dist/migrations/0020_prospective_memory.d.ts +3 -0
- package/dist/migrations/0020_prospective_memory.js +42 -0
- package/dist/migrations/0021_strategy_cortex.d.ts +3 -0
- package/dist/migrations/0021_strategy_cortex.js +23 -0
- package/dist/migrations/0022_episode_dream_engine.d.ts +3 -0
- package/dist/migrations/0022_episode_dream_engine.js +74 -0
- package/dist/migrations/0023_episode_dream_hardening.d.ts +3 -0
- package/dist/migrations/0023_episode_dream_hardening.js +65 -0
- package/dist/migrations/0024_episode_ontology_reliability.d.ts +3 -0
- package/dist/migrations/0024_episode_ontology_reliability.js +70 -0
- package/dist/migrations/0025_memory_atlas.d.ts +6 -0
- package/dist/migrations/0025_memory_atlas.js +268 -0
- package/dist/migrations/0026_runtime_governance_atlas_reliability.d.ts +3 -0
- package/dist/migrations/0026_runtime_governance_atlas_reliability.js +72 -0
- package/dist/migrations/0027_openclaw_upgrade_hotfix.d.ts +3 -0
- package/dist/migrations/0027_openclaw_upgrade_hotfix.js +21 -0
- package/dist/migrations/SchemaMigrationRunner.d.ts +21 -0
- package/dist/migrations/SchemaMigrationRunner.js +67 -0
- package/dist/migrations/index.d.ts +36 -0
- package/dist/migrations/index.js +57 -0
- package/dist/models/ModelCapabilityRouter.d.ts +17 -0
- package/dist/models/ModelCapabilityRouter.js +75 -0
- package/dist/models/ModelRegistry.d.ts +15 -0
- package/dist/models/ModelRegistry.js +132 -0
- package/dist/models/ModelRole.d.ts +19 -0
- package/dist/models/ModelRole.js +1 -0
- package/dist/models/UserInsight.d.ts +16 -0
- package/dist/models/UserInsight.js +9 -0
- package/dist/models/UserInsightExtractor.d.ts +19 -0
- package/dist/models/UserInsightExtractor.js +99 -0
- package/dist/models/UserModelManager.d.ts +21 -0
- package/dist/models/UserModelManager.js +41 -0
- package/dist/models/UserModelStore.d.ts +20 -0
- package/dist/models/UserModelStore.js +136 -0
- package/dist/models/WorkingMemoryReporter.d.ts +16 -0
- package/dist/models/WorkingMemoryReporter.js +38 -0
- package/dist/models/adapters/MemoryReviewAdapter.d.ts +12 -0
- package/dist/models/adapters/MemoryReviewAdapter.js +77 -0
- package/dist/models/index.d.ts +8 -0
- package/dist/models/index.js +5 -0
- package/dist/models/providers/AnthropicClient.d.ts +17 -0
- package/dist/models/providers/AnthropicClient.js +40 -0
- package/dist/models/providers/OpenAICompatibleClient.d.ts +24 -0
- package/dist/models/providers/OpenAICompatibleClient.js +76 -0
- package/dist/observability/DecisionExplainer.d.ts +5 -0
- package/dist/observability/DecisionExplainer.js +62 -0
- package/dist/observability/TraceEvent.d.ts +11 -0
- package/dist/observability/TraceEvent.js +1 -0
- package/dist/observability/TraceQuery.d.ts +15 -0
- package/dist/observability/TraceQuery.js +28 -0
- package/dist/observability/TraceStore.d.ts +15 -0
- package/dist/observability/TraceStore.js +110 -0
- package/dist/observability/TraceWriter.d.ts +8 -0
- package/dist/observability/TraceWriter.js +14 -0
- package/dist/ontology/MemoryOntology.d.ts +4 -0
- package/dist/ontology/MemoryOntology.js +7 -0
- package/dist/prospective/ProspectiveMemoryService.d.ts +79 -0
- package/dist/prospective/ProspectiveMemoryService.js +258 -0
- package/dist/prospective/index.d.ts +2 -0
- package/dist/prospective/index.js +1 -0
- package/dist/public.d.ts +160 -0
- package/dist/public.js +115 -0
- package/dist/recall/BrainRecall.d.ts +96 -0
- package/dist/recall/BrainRecall.js +574 -0
- package/dist/recall/HierarchicalRecallRouter.d.ts +24 -0
- package/dist/recall/HierarchicalRecallRouter.js +62 -0
- package/dist/recall/RecallExplanation.d.ts +59 -0
- package/dist/recall/RecallExplanation.js +244 -0
- package/dist/recall/RecallGovernance.d.ts +10 -0
- package/dist/recall/RecallGovernance.js +83 -0
- package/dist/recall/RecallSufficiencyGate.d.ts +40 -0
- package/dist/recall/RecallSufficiencyGate.js +208 -0
- package/dist/recall/SourceContextMetadata.d.ts +49 -0
- package/dist/recall/SourceContextMetadata.js +134 -0
- package/dist/recall/TopicClassifier.d.ts +33 -0
- package/dist/recall/TopicClassifier.js +138 -0
- package/dist/recall/TopicDecayPolicy.d.ts +15 -0
- package/dist/recall/TopicDecayPolicy.js +46 -0
- package/dist/recall/TopicRegistry.d.ts +12 -0
- package/dist/recall/TopicRegistry.js +26 -0
- package/dist/recall/TopicSummaryBoard.d.ts +27 -0
- package/dist/recall/TopicSummaryBoard.js +139 -0
- package/dist/recall/VectorCandidateFilter.d.ts +50 -0
- package/dist/recall/VectorCandidateFilter.js +78 -0
- package/dist/retrieval/ConditionDslEvaluator.d.ts +33 -0
- package/dist/retrieval/ConditionDslEvaluator.js +160 -0
- package/dist/retrieval/EntityActivationIndex.d.ts +14 -0
- package/dist/retrieval/EntityActivationIndex.js +19 -0
- package/dist/retrieval/EvidenceFusionPolicy.d.ts +30 -0
- package/dist/retrieval/EvidenceFusionPolicy.js +112 -0
- package/dist/retrieval/EvidenceFusionRanker.d.ts +13 -0
- package/dist/retrieval/EvidenceFusionRanker.js +17 -0
- package/dist/retrieval/NarrativeRecallAssembler.d.ts +32 -0
- package/dist/retrieval/NarrativeRecallAssembler.js +27 -0
- package/dist/retrieval/NativeQueryParser.d.ts +23 -0
- package/dist/retrieval/NativeQueryParser.js +135 -0
- package/dist/retrieval/PlanDslExecutor.d.ts +67 -0
- package/dist/retrieval/PlanDslExecutor.js +194 -0
- package/dist/retrieval/PolicyRuntimeEvaluator.d.ts +48 -0
- package/dist/retrieval/PolicyRuntimeEvaluator.js +96 -0
- package/dist/retrieval/PolicySideEffectExecutor.d.ts +50 -0
- package/dist/retrieval/PolicySideEffectExecutor.js +202 -0
- package/dist/retrieval/PulseRetrievalEngine.d.ts +37 -0
- package/dist/retrieval/PulseRetrievalEngine.js +51 -0
- package/dist/retrieval/QueryCompiler.d.ts +18 -0
- package/dist/retrieval/QueryCompiler.js +97 -0
- package/dist/retrieval/QueryTimePendingEntityResolver.d.ts +67 -0
- package/dist/retrieval/QueryTimePendingEntityResolver.js +260 -0
- package/dist/retrieval/RetrievalPlanner.d.ts +42 -0
- package/dist/retrieval/RetrievalPlanner.js +209 -0
- package/dist/retrieval/TemporalBranchSearch.d.ts +38 -0
- package/dist/retrieval/TemporalBranchSearch.js +109 -0
- package/dist/retrieval/UniverseNavigator.d.ts +43 -0
- package/dist/retrieval/UniverseNavigator.js +75 -0
- package/dist/retrieval/UniverseTraversalExecutor.d.ts +21 -0
- package/dist/retrieval/UniverseTraversalExecutor.js +77 -0
- package/dist/routing/AnswerEvidenceTrace.d.ts +18 -0
- package/dist/routing/AnswerEvidenceTrace.js +1 -0
- package/dist/routing/BrainToolDispatcher.d.ts +37 -0
- package/dist/routing/BrainToolDispatcher.js +163 -0
- package/dist/routing/ConfidenceGate.d.ts +26 -0
- package/dist/routing/ConfidenceGate.js +40 -0
- package/dist/routing/ConfirmationPhraseMatcher.d.ts +9 -0
- package/dist/routing/ConfirmationPhraseMatcher.js +43 -0
- package/dist/routing/DirectReplyFormatter.d.ts +5 -0
- package/dist/routing/DirectReplyFormatter.js +55 -0
- package/dist/routing/EvidenceBudgetManager.d.ts +30 -0
- package/dist/routing/EvidenceBudgetManager.js +55 -0
- package/dist/routing/ExecutionLoop.d.ts +79 -0
- package/dist/routing/ExecutionLoop.js +234 -0
- package/dist/routing/IntentClassifier.d.ts +15 -0
- package/dist/routing/IntentClassifier.js +97 -0
- package/dist/routing/IntentPatternMatcher.d.ts +12 -0
- package/dist/routing/IntentPatternMatcher.js +206 -0
- package/dist/routing/IterativeLLMClarifier.d.ts +80 -0
- package/dist/routing/IterativeLLMClarifier.js +408 -0
- package/dist/routing/LLMToolSchema.d.ts +60 -0
- package/dist/routing/LLMToolSchema.js +143 -0
- package/dist/routing/MessageRouter.d.ts +20 -0
- package/dist/routing/MessageRouter.js +58 -0
- package/dist/routing/SessionContextSelector.d.ts +12 -0
- package/dist/routing/SessionContextSelector.js +86 -0
- package/dist/routing/SystemIntentClassifier.d.ts +15 -0
- package/dist/routing/SystemIntentClassifier.js +50 -0
- package/dist/routing/TaskPlan.d.ts +31 -0
- package/dist/routing/TaskPlan.js +1 -0
- package/dist/routing/TaskRouter.d.ts +13 -0
- package/dist/routing/TaskRouter.js +111 -0
- package/dist/routing/ToolCallParser.d.ts +16 -0
- package/dist/routing/ToolCallParser.js +123 -0
- package/dist/routing/ToolEvidenceNormalizer.d.ts +13 -0
- package/dist/routing/ToolEvidenceNormalizer.js +96 -0
- package/dist/routing/ToolEvidencePack.d.ts +36 -0
- package/dist/routing/ToolEvidencePack.js +84 -0
- package/dist/routing/ToolResultSanitizer.d.ts +19 -0
- package/dist/routing/ToolResultSanitizer.js +58 -0
- package/dist/routing/ToolUsePolicy.d.ts +78 -0
- package/dist/routing/ToolUsePolicy.js +163 -0
- package/dist/routing/index.d.ts +32 -0
- package/dist/routing/index.js +19 -0
- package/dist/routing/templates/ability_template.d.ts +2 -0
- package/dist/routing/templates/ability_template.js +34 -0
- package/dist/routing/templates/approvals_template.d.ts +2 -0
- package/dist/routing/templates/approvals_template.js +43 -0
- package/dist/routing/templates/context_template.d.ts +2 -0
- package/dist/routing/templates/context_template.js +25 -0
- package/dist/routing/templates/contradictions_template.d.ts +2 -0
- package/dist/routing/templates/contradictions_template.js +36 -0
- package/dist/routing/templates/importance_template.d.ts +2 -0
- package/dist/routing/templates/importance_template.js +23 -0
- package/dist/routing/templates/memory_template.d.ts +2 -0
- package/dist/routing/templates/memory_template.js +37 -0
- package/dist/routing/templates/self_manifest_template.d.ts +5 -0
- package/dist/routing/templates/self_manifest_template.js +64 -0
- package/dist/routing/templates/tasks_template.d.ts +2 -0
- package/dist/routing/templates/tasks_template.js +41 -0
- package/dist/routing/templates/trace_template.d.ts +2 -0
- package/dist/routing/templates/trace_template.js +37 -0
- package/dist/routing/tools/EntityExpandTool.d.ts +25 -0
- package/dist/routing/tools/EntityExpandTool.js +59 -0
- package/dist/routing/tools/NeuronContextTool.d.ts +32 -0
- package/dist/routing/tools/NeuronContextTool.js +66 -0
- package/dist/routing/tools/SecondaryRecallTool.d.ts +27 -0
- package/dist/routing/tools/SecondaryRecallTool.js +30 -0
- package/dist/routing/tools/SkillDiscoveryTool.d.ts +13 -0
- package/dist/routing/tools/SkillDiscoveryTool.js +11 -0
- package/dist/snapshot/SnapshotExporter.d.ts +13 -0
- package/dist/snapshot/SnapshotExporter.js +70 -0
- package/dist/snapshot/SnapshotHeader.d.ts +15 -0
- package/dist/snapshot/SnapshotHeader.js +1 -0
- package/dist/snapshot/SnapshotImporter.d.ts +20 -0
- package/dist/snapshot/SnapshotImporter.js +40 -0
- package/dist/snapshot/errors.d.ts +18 -0
- package/dist/snapshot/errors.js +34 -0
- package/dist/snapshot/index.d.ts +5 -0
- package/dist/snapshot/index.js +3 -0
- package/dist/storage/StorageCompactor.d.ts +30 -0
- package/dist/storage/StorageCompactor.js +95 -0
- package/dist/store/ActivationStore.d.ts +45 -0
- package/dist/store/ActivationStore.js +135 -0
- package/dist/store/BackgroundJobStore.d.ts +49 -0
- package/dist/store/BackgroundJobStore.js +156 -0
- package/dist/store/CandidateReviewStore.d.ts +33 -0
- package/dist/store/CandidateReviewStore.js +67 -0
- package/dist/store/CognitiveGraphStore.d.ts +42 -0
- package/dist/store/CognitiveGraphStore.js +193 -0
- package/dist/store/CompilerConfidenceStore.d.ts +20 -0
- package/dist/store/CompilerConfidenceStore.js +76 -0
- package/dist/store/DeepWriteCandidateStore.d.ts +94 -0
- package/dist/store/DeepWriteCandidateStore.js +290 -0
- package/dist/store/DeterministicEmbedder.d.ts +10 -0
- package/dist/store/DeterministicEmbedder.js +24 -0
- package/dist/store/DreamLedgerStore.d.ts +22 -0
- package/dist/store/DreamLedgerStore.js +84 -0
- package/dist/store/Embedder.d.ts +14 -0
- package/dist/store/Embedder.js +52 -0
- package/dist/store/EmbedderFactory.d.ts +12 -0
- package/dist/store/EmbedderFactory.js +51 -0
- package/dist/store/EntityStore.d.ts +195 -0
- package/dist/store/EntityStore.js +941 -0
- package/dist/store/EventStore.d.ts +118 -0
- package/dist/store/EventStore.js +699 -0
- package/dist/store/FactStore.d.ts +76 -0
- package/dist/store/FactStore.js +356 -0
- package/dist/store/HnswlibVectorStore.d.ts +2 -0
- package/dist/store/HnswlibVectorStore.js +1 -0
- package/dist/store/IVectorStore.d.ts +32 -0
- package/dist/store/IVectorStore.js +1 -0
- package/dist/store/InteractionUnitStore.d.ts +52 -0
- package/dist/store/InteractionUnitStore.js +167 -0
- package/dist/store/MemoryAtlasStore.d.ts +60 -0
- package/dist/store/MemoryAtlasStore.js +500 -0
- package/dist/store/MemoryBindingStore.d.ts +77 -0
- package/dist/store/MemoryBindingStore.js +608 -0
- package/dist/store/MemoryGovernanceStore.d.ts +23 -0
- package/dist/store/MemoryGovernanceStore.js +103 -0
- package/dist/store/MemoryInspectionStore.d.ts +61 -0
- package/dist/store/MemoryInspectionStore.js +215 -0
- package/dist/store/PlanRuntimeStore.d.ts +83 -0
- package/dist/store/PlanRuntimeStore.js +257 -0
- package/dist/store/PolicyExecutionProjector.d.ts +17 -0
- package/dist/store/PolicyExecutionProjector.js +115 -0
- package/dist/store/PolicyExecutionStore.d.ts +62 -0
- package/dist/store/PolicyExecutionStore.js +290 -0
- package/dist/store/PolicyProjectionStore.d.ts +18 -0
- package/dist/store/PolicyProjectionStore.js +61 -0
- package/dist/store/ProjectionObservabilityStore.d.ts +38 -0
- package/dist/store/ProjectionObservabilityStore.js +310 -0
- package/dist/store/ReasoningChainStore.d.ts +13 -0
- package/dist/store/ReasoningChainStore.js +74 -0
- package/dist/store/RuntimeProjectionStore.d.ts +18 -0
- package/dist/store/RuntimeProjectionStore.js +61 -0
- package/dist/store/RuntimeProjector.d.ts +17 -0
- package/dist/store/RuntimeProjector.js +119 -0
- package/dist/store/SqliteVecStore.d.ts +25 -0
- package/dist/store/SqliteVecStore.js +126 -0
- package/dist/store/SummaryStore.d.ts +56 -0
- package/dist/store/SummaryStore.js +225 -0
- package/dist/store/TemporalAdjacencyStore.d.ts +49 -0
- package/dist/store/TemporalAdjacencyStore.js +300 -0
- package/dist/store/TopologyStore.d.ts +89 -0
- package/dist/store/TopologyStore.js +657 -0
- package/dist/store/VectorProjector.d.ts +22 -0
- package/dist/store/VectorProjector.js +125 -0
- package/dist/store/VectorStore.d.ts +35 -0
- package/dist/store/VectorStore.js +201 -0
- package/dist/strategy/StrategyCapsule.d.ts +44 -0
- package/dist/strategy/StrategyCapsule.js +1 -0
- package/dist/strategy/StrategyConditionedCandidateBuilder.d.ts +9 -0
- package/dist/strategy/StrategyConditionedCandidateBuilder.js +11 -0
- package/dist/strategy/StrategyContextFormatter.d.ts +3 -0
- package/dist/strategy/StrategyContextFormatter.js +25 -0
- package/dist/strategy/StrategyCortex.d.ts +28 -0
- package/dist/strategy/StrategyCortex.js +78 -0
- package/dist/strategy/StrategyTemplateRegistry.d.ts +9 -0
- package/dist/strategy/StrategyTemplateRegistry.js +78 -0
- package/dist/strategy/index.d.ts +6 -0
- package/dist/strategy/index.js +5 -0
- package/dist/temporal/TemporalMemoryService.d.ts +62 -0
- package/dist/temporal/TemporalMemoryService.js +128 -0
- package/dist/temporal/index.d.ts +2 -0
- package/dist/temporal/index.js +1 -0
- package/dist/topic/TopicAliasRegistry.d.ts +21 -0
- package/dist/topic/TopicAliasRegistry.js +67 -0
- package/dist/topic/TopicGovernance.d.ts +21 -0
- package/dist/topic/TopicGovernance.js +173 -0
- package/dist/topic/TopicPathRegistry.d.ts +36 -0
- package/dist/topic/TopicPathRegistry.js +105 -0
- package/dist/topic/TopicRelationGraph.d.ts +23 -0
- package/dist/topic/TopicRelationGraph.js +55 -0
- package/dist/topic/TopicTypes.d.ts +73 -0
- package/dist/topic/TopicTypes.js +1 -0
- package/dist/topic/index.d.ts +6 -0
- package/dist/topic/index.js +5 -0
- package/dist/types/AsyncEnrichment.d.ts +62 -0
- package/dist/types/AsyncEnrichment.js +7 -0
- package/dist/types/BrainRecallResult.d.ts +66 -0
- package/dist/types/BrainRecallResult.js +1 -0
- package/dist/types/ExtensionPoints.d.ts +116 -0
- package/dist/types/ExtensionPoints.js +1 -0
- package/dist/types/Migration.d.ts +22 -0
- package/dist/types/Migration.js +1 -0
- package/dist/types/QueryTimePendingEntityResolution.d.ts +11 -0
- package/dist/types/QueryTimePendingEntityResolution.js +23 -0
- package/dist/types/index.d.ts +855 -0
- package/dist/types/index.js +24 -0
- package/dist/types/query-ir.d.ts +71 -0
- package/dist/types/query-ir.js +4 -0
- package/dist/types/reasoning.d.ts +16 -0
- package/dist/types/reasoning.js +4 -0
- package/dist/utils/AAAKGenerator.d.ts +57 -0
- package/dist/utils/AAAKGenerator.js +212 -0
- package/dist/utils/Config.d.ts +78 -0
- package/dist/utils/Config.js +91 -0
- package/dist/utils/ConversationMarkdownNormalization.d.ts +88 -0
- package/dist/utils/ConversationMarkdownNormalization.js +567 -0
- package/dist/utils/Logger.d.ts +22 -0
- package/dist/utils/Logger.js +77 -0
- package/dist/utils/hash.d.ts +33 -0
- package/dist/utils/hash.js +53 -0
- package/dist/utils/text.d.ts +2 -0
- package/dist/utils/text.js +19 -0
- package/dist/utils/vector.d.ts +26 -0
- package/dist/utils/vector.js +38 -0
- package/examples/hermes-backend/AGENTS.md +218 -0
- package/examples/hermes-backend/README.md +153 -0
- package/examples/hermes-backend/SKILL.md +365 -0
- package/examples/hermes-backend/references/operations.md +202 -0
- package/examples/openclaw-backend/AGENTS.md +195 -0
- package/examples/openclaw-backend/README.md +228 -0
- package/examples/openclaw-backend/SKILL.md +464 -0
- package/examples/openclaw-backend/references/operations.md +269 -0
- package/install.sh +84 -0
- package/package.json +90 -0
|
@@ -0,0 +1,898 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import Database from 'bun:sqlite';
|
|
3
|
+
import { randomUUID } from 'crypto';
|
|
4
|
+
import { ConditionDslEvaluator } from '../retrieval/ConditionDslEvaluator.js';
|
|
5
|
+
import { PlanDslExecutor } from '../retrieval/PlanDslExecutor.js';
|
|
6
|
+
import { PolicyRuntimeEvaluator } from '../retrieval/PolicyRuntimeEvaluator.js';
|
|
7
|
+
export class BeliefStore {
|
|
8
|
+
eventStore;
|
|
9
|
+
static SOURCE_TRUST = {
|
|
10
|
+
verified_fact: 1.0,
|
|
11
|
+
external_tool: 0.9,
|
|
12
|
+
user_input: 0.85,
|
|
13
|
+
llm_inference: 0.55
|
|
14
|
+
};
|
|
15
|
+
static SCOPE_PRIORITY = {
|
|
16
|
+
file: 5,
|
|
17
|
+
session: 4,
|
|
18
|
+
project: 3,
|
|
19
|
+
agent: 2,
|
|
20
|
+
global: 1
|
|
21
|
+
};
|
|
22
|
+
db;
|
|
23
|
+
closed = false;
|
|
24
|
+
constructor(dbPath = ':memory:', eventStore) {
|
|
25
|
+
this.eventStore = eventStore;
|
|
26
|
+
this.db = new Database(dbPath);
|
|
27
|
+
this.initializeSchema();
|
|
28
|
+
}
|
|
29
|
+
initializeSchema() {
|
|
30
|
+
this.db.exec(`
|
|
31
|
+
CREATE TABLE IF NOT EXISTS beliefs (
|
|
32
|
+
id TEXT PRIMARY KEY,
|
|
33
|
+
project_id TEXT,
|
|
34
|
+
scope TEXT NOT NULL,
|
|
35
|
+
subject TEXT NOT NULL,
|
|
36
|
+
predicate TEXT NOT NULL,
|
|
37
|
+
object_value TEXT NOT NULL,
|
|
38
|
+
object_type TEXT NOT NULL DEFAULT 'string',
|
|
39
|
+
canonical_key TEXT NOT NULL,
|
|
40
|
+
confidence REAL NOT NULL DEFAULT 1.0,
|
|
41
|
+
trust_score REAL NOT NULL DEFAULT 1.0,
|
|
42
|
+
source_neuron_id TEXT,
|
|
43
|
+
source_event_id TEXT,
|
|
44
|
+
source_type TEXT NOT NULL DEFAULT 'user_input',
|
|
45
|
+
validity_kind TEXT NOT NULL DEFAULT 'open',
|
|
46
|
+
valid_from INTEGER NOT NULL,
|
|
47
|
+
valid_to INTEGER,
|
|
48
|
+
supersedes_belief_id TEXT,
|
|
49
|
+
superseded_by_belief_id TEXT,
|
|
50
|
+
contradiction_group TEXT,
|
|
51
|
+
status TEXT NOT NULL DEFAULT 'active',
|
|
52
|
+
explanation TEXT,
|
|
53
|
+
metadata_json TEXT,
|
|
54
|
+
created_at INTEGER NOT NULL,
|
|
55
|
+
updated_at INTEGER NOT NULL
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
CREATE INDEX IF NOT EXISTS idx_beliefs_canonical ON beliefs(canonical_key, status, valid_from DESC);
|
|
59
|
+
CREATE INDEX IF NOT EXISTS idx_beliefs_subject_predicate ON beliefs(subject, predicate, status, valid_from DESC);
|
|
60
|
+
|
|
61
|
+
CREATE TABLE IF NOT EXISTS belief_evidence (
|
|
62
|
+
belief_id TEXT NOT NULL,
|
|
63
|
+
neuron_id TEXT,
|
|
64
|
+
event_id TEXT,
|
|
65
|
+
evidence_type TEXT NOT NULL,
|
|
66
|
+
weight REAL NOT NULL DEFAULT 1.0,
|
|
67
|
+
created_at INTEGER NOT NULL,
|
|
68
|
+
PRIMARY KEY (belief_id, neuron_id, event_id, evidence_type)
|
|
69
|
+
);
|
|
70
|
+
`);
|
|
71
|
+
}
|
|
72
|
+
findByCanonicalKey(canonicalKey) {
|
|
73
|
+
const rows = this.db.prepare(`
|
|
74
|
+
SELECT * FROM beliefs
|
|
75
|
+
WHERE canonical_key = ?
|
|
76
|
+
ORDER BY valid_from DESC, created_at DESC
|
|
77
|
+
`).all(canonicalKey);
|
|
78
|
+
return rows.map((row) => this.mapBelief(row));
|
|
79
|
+
}
|
|
80
|
+
countActive(projectId) {
|
|
81
|
+
const row = this.db.prepare(`
|
|
82
|
+
SELECT COUNT(*) AS count
|
|
83
|
+
FROM beliefs
|
|
84
|
+
WHERE status = 'active'
|
|
85
|
+
AND (? IS NULL OR project_id = ?)
|
|
86
|
+
`).get(projectId || null, projectId || null);
|
|
87
|
+
return row.count;
|
|
88
|
+
}
|
|
89
|
+
listByTimeRange(startTime, endTime, options) {
|
|
90
|
+
const statuses = options?.statuses ?? ['active', 'superseded', 'suspect', 'expired', 'revoked'];
|
|
91
|
+
const rows = this.db.prepare(`
|
|
92
|
+
SELECT *
|
|
93
|
+
FROM beliefs
|
|
94
|
+
WHERE valid_from >= ?
|
|
95
|
+
AND valid_from < ?
|
|
96
|
+
AND (? IS NULL OR project_id = ?)
|
|
97
|
+
AND status IN (${statuses.map(() => '?').join(', ')})
|
|
98
|
+
ORDER BY valid_from DESC, updated_at DESC
|
|
99
|
+
LIMIT ?
|
|
100
|
+
`).all(startTime, endTime, options?.projectId || null, options?.projectId || null, ...statuses, options?.limit ?? 200);
|
|
101
|
+
return rows.map((row) => this.mapBelief(row));
|
|
102
|
+
}
|
|
103
|
+
getActiveBeliefsForQuery(input) {
|
|
104
|
+
const query = input.query.toLowerCase().trim();
|
|
105
|
+
const atTime = input.atTime ?? Date.now();
|
|
106
|
+
const tokens = this.extractQueryTokens(query, input.entities, input.mustMatch, input.shouldMatch);
|
|
107
|
+
const structuredTargets = this.extractStructuredTargets(query, input.intent, tokens, input.semantics);
|
|
108
|
+
const rows = this.db.prepare(`
|
|
109
|
+
SELECT *
|
|
110
|
+
FROM beliefs
|
|
111
|
+
WHERE status = 'active'
|
|
112
|
+
AND valid_from <= ?
|
|
113
|
+
AND (valid_to IS NULL OR valid_to > ?)
|
|
114
|
+
AND (? IS NULL OR project_id = ? OR scope = 'global')
|
|
115
|
+
ORDER BY updated_at DESC, confidence DESC
|
|
116
|
+
LIMIT 200
|
|
117
|
+
`).all(atTime, atTime, input.projectId || null, input.projectId || null);
|
|
118
|
+
const scored = rows
|
|
119
|
+
.map((row) => this.mapBelief(row))
|
|
120
|
+
.map((belief) => ({
|
|
121
|
+
belief,
|
|
122
|
+
score: this.scoreBeliefForQuery(belief, {
|
|
123
|
+
query,
|
|
124
|
+
tokens,
|
|
125
|
+
projectId: input.projectId,
|
|
126
|
+
intent: input.intent,
|
|
127
|
+
structuredTargets,
|
|
128
|
+
semantics: input.semantics
|
|
129
|
+
})
|
|
130
|
+
}))
|
|
131
|
+
.filter((item) => item.score > 0)
|
|
132
|
+
.sort((a, b) => b.score - a.score)
|
|
133
|
+
.slice(0, input.limit ?? 8);
|
|
134
|
+
return scored.map((item) => item.belief);
|
|
135
|
+
}
|
|
136
|
+
getBeliefHistoryForCanonicalKeys(canonicalKeys, options = {}) {
|
|
137
|
+
if (canonicalKeys.length === 0)
|
|
138
|
+
return new Map();
|
|
139
|
+
const includeStatuses = options.includeStatuses ?? ['active', 'superseded', 'suspect', 'expired', 'revoked'];
|
|
140
|
+
const keyPlaceholders = canonicalKeys.map(() => '?').join(', ');
|
|
141
|
+
const statusPlaceholders = includeStatuses.map(() => '?').join(', ');
|
|
142
|
+
const rows = this.db.prepare(`
|
|
143
|
+
SELECT *
|
|
144
|
+
FROM beliefs
|
|
145
|
+
WHERE canonical_key IN (${keyPlaceholders})
|
|
146
|
+
AND status IN (${statusPlaceholders})
|
|
147
|
+
ORDER BY updated_at DESC, valid_from DESC, created_at DESC
|
|
148
|
+
`).all(...canonicalKeys, ...includeStatuses);
|
|
149
|
+
const grouped = new Map();
|
|
150
|
+
for (const row of rows) {
|
|
151
|
+
const belief = this.mapBelief(row);
|
|
152
|
+
const bucket = grouped.get(belief.canonicalKey) || [];
|
|
153
|
+
if (bucket.length >= (options.limitPerCanonical ?? 6))
|
|
154
|
+
continue;
|
|
155
|
+
bucket.push(belief);
|
|
156
|
+
grouped.set(belief.canonicalKey, bucket);
|
|
157
|
+
}
|
|
158
|
+
return grouped;
|
|
159
|
+
}
|
|
160
|
+
getExecutionFeedbackNeuronSignals(records) {
|
|
161
|
+
if (records.length === 0)
|
|
162
|
+
return [];
|
|
163
|
+
const rows = this.db.prepare(`
|
|
164
|
+
SELECT *
|
|
165
|
+
FROM beliefs
|
|
166
|
+
WHERE status = 'active'
|
|
167
|
+
AND source_neuron_id IS NOT NULL
|
|
168
|
+
ORDER BY updated_at DESC
|
|
169
|
+
`).all();
|
|
170
|
+
const signals = new Map();
|
|
171
|
+
for (const row of rows) {
|
|
172
|
+
const belief = this.mapBelief(row);
|
|
173
|
+
if (!belief.sourceNeuronId)
|
|
174
|
+
continue;
|
|
175
|
+
const feedback = this.computeExecutionFeedbackForBelief(belief, records);
|
|
176
|
+
if (!feedback)
|
|
177
|
+
continue;
|
|
178
|
+
const current = signals.get(belief.sourceNeuronId) || {
|
|
179
|
+
neuronId: belief.sourceNeuronId,
|
|
180
|
+
matchedExecutions: 0,
|
|
181
|
+
executed: 0,
|
|
182
|
+
failed: 0,
|
|
183
|
+
latestUpdatedAt: undefined
|
|
184
|
+
};
|
|
185
|
+
current.matchedExecutions += feedback.matchedExecutions;
|
|
186
|
+
current.executed += feedback.executed;
|
|
187
|
+
current.failed += feedback.failed;
|
|
188
|
+
current.latestUpdatedAt = Math.max(current.latestUpdatedAt || 0, feedback.latestUpdatedAt || 0) || undefined;
|
|
189
|
+
signals.set(belief.sourceNeuronId, current);
|
|
190
|
+
}
|
|
191
|
+
return Array.from(signals.values());
|
|
192
|
+
}
|
|
193
|
+
applyExecutionFeedbackCalibration(records, now = Date.now()) {
|
|
194
|
+
if (records.length === 0)
|
|
195
|
+
return 0;
|
|
196
|
+
const rows = this.db.prepare(`
|
|
197
|
+
SELECT *
|
|
198
|
+
FROM beliefs
|
|
199
|
+
WHERE status = 'active'
|
|
200
|
+
ORDER BY updated_at DESC
|
|
201
|
+
`).all();
|
|
202
|
+
let updated = 0;
|
|
203
|
+
for (const row of rows) {
|
|
204
|
+
const belief = this.mapBelief(row);
|
|
205
|
+
const feedback = this.computeExecutionFeedbackForBelief(belief, records);
|
|
206
|
+
if (!feedback)
|
|
207
|
+
continue;
|
|
208
|
+
const nextTrust = this.clamp(belief.trustScore + feedback.executed * 0.02 - feedback.failed * 0.03, 0.1, 1.0);
|
|
209
|
+
const nextUpdatedAt = Math.max(belief.updatedAt, feedback.latestUpdatedAt || belief.updatedAt);
|
|
210
|
+
if (Math.abs(nextTrust - belief.trustScore) < 0.0001 && nextUpdatedAt === belief.updatedAt)
|
|
211
|
+
continue;
|
|
212
|
+
const metadata = {
|
|
213
|
+
...(belief.metadata || {}),
|
|
214
|
+
executionFeedbackCalibration: {
|
|
215
|
+
matchedExecutions: feedback.matchedExecutions,
|
|
216
|
+
executed: feedback.executed,
|
|
217
|
+
failed: feedback.failed,
|
|
218
|
+
latestUpdatedAt: feedback.latestUpdatedAt,
|
|
219
|
+
calibratedAt: now
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
this.db.prepare(`
|
|
223
|
+
UPDATE beliefs
|
|
224
|
+
SET trust_score = ?, metadata_json = ?, updated_at = ?
|
|
225
|
+
WHERE id = ?
|
|
226
|
+
`).run(nextTrust, JSON.stringify(metadata), nextUpdatedAt, belief.id);
|
|
227
|
+
updated += 1;
|
|
228
|
+
this.eventStore?.append({
|
|
229
|
+
streamId: belief.id,
|
|
230
|
+
streamType: 'belief',
|
|
231
|
+
eventType: 'BELIEF_RECALIBRATED',
|
|
232
|
+
projectId: belief.projectId,
|
|
233
|
+
sourceNeuronId: belief.sourceNeuronId,
|
|
234
|
+
occurredAt: now,
|
|
235
|
+
payload: {
|
|
236
|
+
beliefId: belief.id,
|
|
237
|
+
previousTrustScore: belief.trustScore,
|
|
238
|
+
nextTrustScore: nextTrust,
|
|
239
|
+
matchedExecutions: feedback.matchedExecutions,
|
|
240
|
+
executed: feedback.executed,
|
|
241
|
+
failed: feedback.failed
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
return updated;
|
|
246
|
+
}
|
|
247
|
+
getEvidenceNeuronIds(beliefIds, limitPerBelief = 3) {
|
|
248
|
+
if (beliefIds.length === 0)
|
|
249
|
+
return [];
|
|
250
|
+
const placeholders = beliefIds.map(() => '?').join(', ');
|
|
251
|
+
const rows = this.db.prepare(`
|
|
252
|
+
SELECT belief_id, neuron_id
|
|
253
|
+
FROM belief_evidence
|
|
254
|
+
WHERE belief_id IN (${placeholders})
|
|
255
|
+
AND neuron_id IS NOT NULL
|
|
256
|
+
ORDER BY weight DESC, created_at DESC
|
|
257
|
+
`).all(...beliefIds);
|
|
258
|
+
const limited = new Map();
|
|
259
|
+
for (const row of rows) {
|
|
260
|
+
if (!row.neuron_id)
|
|
261
|
+
continue;
|
|
262
|
+
const bucket = limited.get(row.belief_id) || [];
|
|
263
|
+
if (bucket.length >= limitPerBelief)
|
|
264
|
+
continue;
|
|
265
|
+
if (!bucket.includes(row.neuron_id))
|
|
266
|
+
bucket.push(row.neuron_id);
|
|
267
|
+
limited.set(row.belief_id, bucket);
|
|
268
|
+
}
|
|
269
|
+
return Array.from(new Set(Array.from(limited.values()).flat()));
|
|
270
|
+
}
|
|
271
|
+
upsert(candidate, now = Date.now()) {
|
|
272
|
+
const canonicalKey = this.toCanonicalKey(candidate.subject, candidate.predicate, candidate.scope);
|
|
273
|
+
const conflicts = this.findByCanonicalKey(canonicalKey).map((existing) => ({
|
|
274
|
+
existing,
|
|
275
|
+
incoming: candidate,
|
|
276
|
+
reason: this.isSameBeliefValue(candidate.objectValue, existing.objectValue) ? 'same_value' : 'contradictory_value'
|
|
277
|
+
}));
|
|
278
|
+
const decision = this.resolveConflict(candidate, conflicts, now);
|
|
279
|
+
if (decision.action === 'reject_incoming') {
|
|
280
|
+
return { belief: null, decision };
|
|
281
|
+
}
|
|
282
|
+
const beliefId = `belief-${randomUUID()}`;
|
|
283
|
+
const belief = {
|
|
284
|
+
id: beliefId,
|
|
285
|
+
projectId: candidate.projectId,
|
|
286
|
+
scope: candidate.scope,
|
|
287
|
+
subject: candidate.subject,
|
|
288
|
+
predicate: candidate.predicate,
|
|
289
|
+
objectValue: candidate.objectValue,
|
|
290
|
+
canonicalKey,
|
|
291
|
+
confidence: candidate.confidence,
|
|
292
|
+
trustScore: candidate.trustScore ?? this.getSourceTrust(candidate.sourceType),
|
|
293
|
+
sourceNeuronId: candidate.sourceNeuronId,
|
|
294
|
+
sourceEventId: candidate.sourceEventId,
|
|
295
|
+
sourceType: candidate.sourceType,
|
|
296
|
+
validityKind: candidate.validityKind ?? 'open',
|
|
297
|
+
validFrom: candidate.validFrom ?? now,
|
|
298
|
+
validTo: candidate.validTo,
|
|
299
|
+
supersedesBeliefId: decision.supersedeBeliefIds?.[0],
|
|
300
|
+
supersededByBeliefId: undefined,
|
|
301
|
+
contradictionGroup: decision.contradictionGroup,
|
|
302
|
+
status: 'active',
|
|
303
|
+
explanation: candidate.explanation,
|
|
304
|
+
metadata: {
|
|
305
|
+
...candidate.metadata,
|
|
306
|
+
...decision.normalizedMetadata
|
|
307
|
+
},
|
|
308
|
+
createdAt: now,
|
|
309
|
+
updatedAt: now
|
|
310
|
+
};
|
|
311
|
+
this.db.transaction(() => {
|
|
312
|
+
if (decision.supersedeBeliefIds?.length) {
|
|
313
|
+
for (const supersededId of decision.supersedeBeliefIds) {
|
|
314
|
+
this.db.prepare(`
|
|
315
|
+
UPDATE beliefs
|
|
316
|
+
SET status = 'superseded', superseded_by_belief_id = ?, valid_to = ?, updated_at = ?
|
|
317
|
+
WHERE id = ?
|
|
318
|
+
`).run(belief.id, belief.validFrom, now, supersededId);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
this.db.prepare(`
|
|
322
|
+
INSERT INTO beliefs (
|
|
323
|
+
id, project_id, scope, subject, predicate, object_value, object_type,
|
|
324
|
+
canonical_key, confidence, trust_score, source_neuron_id, source_event_id,
|
|
325
|
+
source_type, validity_kind, valid_from, valid_to, supersedes_belief_id,
|
|
326
|
+
superseded_by_belief_id, contradiction_group, status, explanation,
|
|
327
|
+
metadata_json, created_at, updated_at
|
|
328
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
329
|
+
`).run(belief.id, belief.projectId || null, belief.scope, belief.subject, belief.predicate, belief.objectValue.normalized || belief.objectValue.raw, belief.objectValue.type, belief.canonicalKey, belief.confidence, belief.trustScore, belief.sourceNeuronId || null, belief.sourceEventId || null, belief.sourceType, belief.validityKind, belief.validFrom, belief.validTo || null, belief.supersedesBeliefId || null, null, belief.contradictionGroup || null, belief.status, belief.explanation || null, belief.metadata ? JSON.stringify(belief.metadata) : null, belief.createdAt, belief.updatedAt);
|
|
330
|
+
if (belief.sourceNeuronId || belief.sourceEventId) {
|
|
331
|
+
this.attachEvidence([
|
|
332
|
+
{
|
|
333
|
+
beliefId: belief.id,
|
|
334
|
+
neuronId: belief.sourceNeuronId,
|
|
335
|
+
eventId: belief.sourceEventId,
|
|
336
|
+
evidenceType: 'source',
|
|
337
|
+
weight: 1,
|
|
338
|
+
createdAt: now
|
|
339
|
+
}
|
|
340
|
+
]);
|
|
341
|
+
}
|
|
342
|
+
})();
|
|
343
|
+
if (this.eventStore) {
|
|
344
|
+
this.eventStore.append({
|
|
345
|
+
streamId: belief.id,
|
|
346
|
+
streamType: 'belief',
|
|
347
|
+
eventType: 'BELIEF_UPSERTED',
|
|
348
|
+
projectId: belief.projectId,
|
|
349
|
+
sourceNeuronId: belief.sourceNeuronId,
|
|
350
|
+
occurredAt: now,
|
|
351
|
+
payload: {
|
|
352
|
+
beliefId: belief.id,
|
|
353
|
+
canonicalKey: belief.canonicalKey,
|
|
354
|
+
action: decision.action,
|
|
355
|
+
supersedeBeliefIds: decision.supersedeBeliefIds || []
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
return { belief, decision };
|
|
360
|
+
}
|
|
361
|
+
attachEvidence(records) {
|
|
362
|
+
const stmt = this.db.prepare(`
|
|
363
|
+
INSERT OR REPLACE INTO belief_evidence (
|
|
364
|
+
belief_id, neuron_id, event_id, evidence_type, weight, created_at
|
|
365
|
+
) VALUES (?, ?, ?, ?, ?, ?)
|
|
366
|
+
`);
|
|
367
|
+
for (const record of records) {
|
|
368
|
+
stmt.run(record.beliefId, record.neuronId || null, record.eventId || null, record.evidenceType, record.weight, record.createdAt);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
resolveConflict(incoming, conflicts, now = Date.now()) {
|
|
372
|
+
if (conflicts.length === 0)
|
|
373
|
+
return { action: 'insert' };
|
|
374
|
+
const activeConflicts = conflicts
|
|
375
|
+
.map((conflict) => conflict.existing)
|
|
376
|
+
.filter((belief) => belief.status === 'active' || belief.status === 'suspect');
|
|
377
|
+
if (activeConflicts.length === 0)
|
|
378
|
+
return { action: 'insert' };
|
|
379
|
+
const incomingStrength = this.computeBeliefStrength({
|
|
380
|
+
confidence: incoming.confidence,
|
|
381
|
+
trustScore: incoming.trustScore ?? this.getSourceTrust(incoming.sourceType),
|
|
382
|
+
sourceType: incoming.sourceType,
|
|
383
|
+
validFrom: incoming.validFrom ?? now,
|
|
384
|
+
scope: incoming.scope,
|
|
385
|
+
predicate: incoming.predicate,
|
|
386
|
+
now
|
|
387
|
+
});
|
|
388
|
+
let supersedeIds = [];
|
|
389
|
+
let strongerExistingCount = 0;
|
|
390
|
+
let sameValueCount = 0;
|
|
391
|
+
let narrowerExistingCount = 0;
|
|
392
|
+
for (const existing of activeConflicts) {
|
|
393
|
+
if (this.isSameBeliefValue(incoming.objectValue, existing.objectValue)) {
|
|
394
|
+
sameValueCount += 1;
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
const compare = this.compareBeliefs(incoming, existing, now);
|
|
398
|
+
if (this.getScopePriority(existing.scope) > this.getScopePriority(incoming.scope)) {
|
|
399
|
+
narrowerExistingCount += 1;
|
|
400
|
+
}
|
|
401
|
+
if (compare === 'incoming')
|
|
402
|
+
supersedeIds.push(existing.id);
|
|
403
|
+
else if (compare === 'existing')
|
|
404
|
+
strongerExistingCount += 1;
|
|
405
|
+
}
|
|
406
|
+
if (sameValueCount === activeConflicts.length) {
|
|
407
|
+
return incomingStrength >= 0.72
|
|
408
|
+
? {
|
|
409
|
+
action: 'coexist_conditional',
|
|
410
|
+
contradictionGroup: this.buildContradictionGroup(incoming),
|
|
411
|
+
normalizedMetadata: { mergeEvidenceOnly: true, reason: 'same_value_additional_evidence' }
|
|
412
|
+
}
|
|
413
|
+
: {
|
|
414
|
+
action: 'reject_incoming',
|
|
415
|
+
rejectReason: 'duplicate_or_lower_value_restatement'
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
if (narrowerExistingCount > 0 && supersedeIds.length > 0 && this.getScopePriority(incoming.scope) < 5) {
|
|
419
|
+
return {
|
|
420
|
+
action: 'coexist_conditional',
|
|
421
|
+
contradictionGroup: this.buildContradictionGroup(incoming),
|
|
422
|
+
normalizedMetadata: {
|
|
423
|
+
preserveExistingScope: true,
|
|
424
|
+
attemptedSupersedeIds: supersedeIds,
|
|
425
|
+
reason: 'incoming_scope_too_broad'
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
if (supersedeIds.length > 0 && strongerExistingCount === 0) {
|
|
430
|
+
return {
|
|
431
|
+
action: 'supersede_existing',
|
|
432
|
+
supersedeBeliefIds: supersedeIds,
|
|
433
|
+
contradictionGroup: this.buildContradictionGroup(incoming),
|
|
434
|
+
normalizedMetadata: { reason: 'incoming_has_higher_strength', incomingStrength }
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
if (strongerExistingCount === activeConflicts.length) {
|
|
438
|
+
return {
|
|
439
|
+
action: 'reject_incoming',
|
|
440
|
+
rejectReason: 'existing_beliefs_have_higher_strength'
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
return {
|
|
444
|
+
action: 'coexist_conditional',
|
|
445
|
+
contradictionGroup: this.buildContradictionGroup(incoming),
|
|
446
|
+
normalizedMetadata: {
|
|
447
|
+
reason: 'conditional_or_temporal_coexistence',
|
|
448
|
+
incomingStrength,
|
|
449
|
+
strongerExistingCount,
|
|
450
|
+
supersedeIds
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
compareBeliefs(incoming, existing, now) {
|
|
455
|
+
const incomingStrength = this.computeBeliefStrength({
|
|
456
|
+
confidence: incoming.confidence,
|
|
457
|
+
trustScore: incoming.trustScore ?? this.getSourceTrust(incoming.sourceType),
|
|
458
|
+
sourceType: incoming.sourceType,
|
|
459
|
+
validFrom: incoming.validFrom ?? now,
|
|
460
|
+
scope: incoming.scope,
|
|
461
|
+
predicate: incoming.predicate,
|
|
462
|
+
now
|
|
463
|
+
});
|
|
464
|
+
const existingStrength = this.computeBeliefStrength({
|
|
465
|
+
confidence: existing.confidence,
|
|
466
|
+
trustScore: existing.trustScore,
|
|
467
|
+
sourceType: existing.sourceType,
|
|
468
|
+
validFrom: existing.validFrom,
|
|
469
|
+
scope: existing.scope,
|
|
470
|
+
predicate: existing.predicate,
|
|
471
|
+
now
|
|
472
|
+
});
|
|
473
|
+
const delta = incomingStrength - existingStrength;
|
|
474
|
+
const incomingValidFrom = incoming.validFrom ?? now;
|
|
475
|
+
const sameSourceFamily = incoming.sourceType === existing.sourceType;
|
|
476
|
+
const newerPreferenceRevision = ((incoming.predicate.startsWith('preference.') || incoming.predicate.startsWith('decision.')) &&
|
|
477
|
+
incomingValidFrom > existing.validFrom &&
|
|
478
|
+
sameSourceFamily &&
|
|
479
|
+
delta > -0.05);
|
|
480
|
+
if (newerPreferenceRevision)
|
|
481
|
+
return 'incoming';
|
|
482
|
+
if (delta >= 0.12)
|
|
483
|
+
return 'incoming';
|
|
484
|
+
if (delta <= -0.12)
|
|
485
|
+
return 'existing';
|
|
486
|
+
return 'tie';
|
|
487
|
+
}
|
|
488
|
+
computeBeliefStrength(input) {
|
|
489
|
+
const sourceTrust = this.getSourceTrust(input.sourceType);
|
|
490
|
+
const effectiveTrust = this.clamp((input.trustScore + sourceTrust) / 2, 0, 1);
|
|
491
|
+
const freshness = this.computeTemporalFreshness((input.now - input.validFrom) / 3600000, input.predicate, input.sourceType);
|
|
492
|
+
const scopeWeight = this.computeScopeWeight(input.scope, input.predicate);
|
|
493
|
+
const weights = this.resolveWeightMatrix(input.predicate, input.sourceType);
|
|
494
|
+
return input.confidence * weights.confidenceW
|
|
495
|
+
+ effectiveTrust * weights.trustW
|
|
496
|
+
+ freshness * weights.freshnessW
|
|
497
|
+
+ scopeWeight * weights.scopeW;
|
|
498
|
+
}
|
|
499
|
+
resolveWeightMatrix(predicate, sourceType) {
|
|
500
|
+
if (predicate.startsWith('preference.') || predicate.startsWith('decision.')) {
|
|
501
|
+
return { confidenceW: 0.28, trustW: 0.22, freshnessW: 0.38, scopeW: 0.12 };
|
|
502
|
+
}
|
|
503
|
+
if (predicate.startsWith('constraint.') || predicate.startsWith('workflow.')) {
|
|
504
|
+
return { confidenceW: 0.3, trustW: 0.3, freshnessW: 0.24, scopeW: 0.16 };
|
|
505
|
+
}
|
|
506
|
+
if (sourceType === 'verified_fact') {
|
|
507
|
+
return { confidenceW: 0.24, trustW: 0.46, freshnessW: 0.18, scopeW: 0.12 };
|
|
508
|
+
}
|
|
509
|
+
return { confidenceW: 0.3, trustW: 0.34, freshnessW: 0.24, scopeW: 0.12 };
|
|
510
|
+
}
|
|
511
|
+
computeTemporalFreshness(ageHours, predicate, sourceType) {
|
|
512
|
+
let halfLifeHours = 24 * 30;
|
|
513
|
+
if (predicate.startsWith('preference.'))
|
|
514
|
+
halfLifeHours = 24 * 10;
|
|
515
|
+
else if (predicate.startsWith('decision.'))
|
|
516
|
+
halfLifeHours = 24 * 14;
|
|
517
|
+
else if (predicate.startsWith('constraint.'))
|
|
518
|
+
halfLifeHours = 24 * 21;
|
|
519
|
+
else if (sourceType === 'verified_fact')
|
|
520
|
+
halfLifeHours = 24 * 90;
|
|
521
|
+
return Math.exp(-Math.log(2) * Math.max(ageHours, 0) / halfLifeHours);
|
|
522
|
+
}
|
|
523
|
+
computeScopeWeight(scope, predicate) {
|
|
524
|
+
const base = {
|
|
525
|
+
global: 0.45,
|
|
526
|
+
agent: 0.5,
|
|
527
|
+
project: 0.68,
|
|
528
|
+
session: 0.82,
|
|
529
|
+
file: 0.92
|
|
530
|
+
}[scope];
|
|
531
|
+
if (predicate.startsWith('fact.') && scope === 'global')
|
|
532
|
+
return 0.8;
|
|
533
|
+
if (predicate.startsWith('fact.') && scope === 'file')
|
|
534
|
+
return 0.6;
|
|
535
|
+
return base;
|
|
536
|
+
}
|
|
537
|
+
buildContradictionGroup(candidate) {
|
|
538
|
+
return `${candidate.subject}|${candidate.predicate}|${candidate.scope}`;
|
|
539
|
+
}
|
|
540
|
+
mapBelief(row) {
|
|
541
|
+
return {
|
|
542
|
+
id: row.id,
|
|
543
|
+
projectId: row.project_id || undefined,
|
|
544
|
+
scope: row.scope,
|
|
545
|
+
subject: row.subject,
|
|
546
|
+
predicate: row.predicate,
|
|
547
|
+
objectValue: {
|
|
548
|
+
raw: row.object_value,
|
|
549
|
+
normalized: row.object_value,
|
|
550
|
+
type: row.object_type
|
|
551
|
+
},
|
|
552
|
+
canonicalKey: row.canonical_key,
|
|
553
|
+
confidence: row.confidence,
|
|
554
|
+
trustScore: row.trust_score,
|
|
555
|
+
sourceNeuronId: row.source_neuron_id || undefined,
|
|
556
|
+
sourceEventId: row.source_event_id || undefined,
|
|
557
|
+
sourceType: row.source_type,
|
|
558
|
+
validityKind: row.validity_kind,
|
|
559
|
+
validFrom: row.valid_from,
|
|
560
|
+
validTo: row.valid_to || undefined,
|
|
561
|
+
supersedesBeliefId: row.supersedes_belief_id || undefined,
|
|
562
|
+
supersededByBeliefId: row.superseded_by_belief_id || undefined,
|
|
563
|
+
contradictionGroup: row.contradiction_group || undefined,
|
|
564
|
+
status: row.status,
|
|
565
|
+
explanation: row.explanation || undefined,
|
|
566
|
+
metadata: row.metadata_json ? JSON.parse(row.metadata_json) : undefined,
|
|
567
|
+
createdAt: row.created_at,
|
|
568
|
+
updatedAt: row.updated_at
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
isSameBeliefValue(a, b) {
|
|
572
|
+
return (a.normalized || a.raw) === (b.normalized || b.raw);
|
|
573
|
+
}
|
|
574
|
+
toCanonicalKey(subject, predicate, scope) {
|
|
575
|
+
return `${subject}|${predicate}|${scope}`;
|
|
576
|
+
}
|
|
577
|
+
getSourceTrust(sourceType) {
|
|
578
|
+
return BeliefStore.SOURCE_TRUST[sourceType] ?? 0.5;
|
|
579
|
+
}
|
|
580
|
+
getScopePriority(scope) {
|
|
581
|
+
return BeliefStore.SCOPE_PRIORITY[scope] ?? 0;
|
|
582
|
+
}
|
|
583
|
+
scoreBeliefForQuery(belief, input) {
|
|
584
|
+
let score = 0;
|
|
585
|
+
let matchedLexicalSignal = false;
|
|
586
|
+
let matchedStructuredSignal = false;
|
|
587
|
+
let matchedRuntimeSignal = false;
|
|
588
|
+
const query = input.query;
|
|
589
|
+
const tokens = input.tokens;
|
|
590
|
+
const haystacks = [
|
|
591
|
+
belief.subject.toLowerCase(),
|
|
592
|
+
belief.predicate.toLowerCase(),
|
|
593
|
+
(belief.objectValue.normalized || belief.objectValue.raw).toLowerCase(),
|
|
594
|
+
belief.explanation?.toLowerCase() || ''
|
|
595
|
+
];
|
|
596
|
+
for (const token of tokens) {
|
|
597
|
+
if (haystacks.some((haystack) => haystack.includes(token))) {
|
|
598
|
+
score += 1.2;
|
|
599
|
+
matchedLexicalSignal = true;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
if (input.structuredTargets.subject && belief.subject === input.structuredTargets.subject) {
|
|
603
|
+
score += 1.4;
|
|
604
|
+
}
|
|
605
|
+
if (input.structuredTargets.predicatePrefix && belief.predicate.startsWith(input.structuredTargets.predicatePrefix)) {
|
|
606
|
+
score += 3.2;
|
|
607
|
+
matchedStructuredSignal = true;
|
|
608
|
+
}
|
|
609
|
+
if (input.structuredTargets.entity && belief.predicate.includes(input.structuredTargets.entity)) {
|
|
610
|
+
score += 2.4;
|
|
611
|
+
matchedStructuredSignal = true;
|
|
612
|
+
}
|
|
613
|
+
if (input.structuredTargets.expectedValue) {
|
|
614
|
+
const value = (belief.objectValue.normalized || belief.objectValue.raw).toLowerCase();
|
|
615
|
+
if (value === input.structuredTargets.expectedValue) {
|
|
616
|
+
score += 1.1;
|
|
617
|
+
matchedStructuredSignal = true;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
if (input.structuredTargets.asksForHistory && belief.status !== 'active') {
|
|
621
|
+
score += 0.9;
|
|
622
|
+
matchedStructuredSignal = true;
|
|
623
|
+
}
|
|
624
|
+
if (input.intent === 'preference_lookup' && belief.predicate.startsWith('preference.')) {
|
|
625
|
+
score += 1.8;
|
|
626
|
+
matchedStructuredSignal = true;
|
|
627
|
+
}
|
|
628
|
+
if (input.intent === 'decision_lookup' && belief.predicate.startsWith('decision.')) {
|
|
629
|
+
score += 1.8;
|
|
630
|
+
matchedStructuredSignal = true;
|
|
631
|
+
}
|
|
632
|
+
if (input.intent === 'constraint_lookup' && (belief.predicate.startsWith('constraint.') || belief.predicate.startsWith('workflow.'))) {
|
|
633
|
+
score += 1.8;
|
|
634
|
+
matchedStructuredSignal = true;
|
|
635
|
+
}
|
|
636
|
+
if (input.intent === 'fact_lookup' && belief.predicate.startsWith('fact.')) {
|
|
637
|
+
score += 1.6;
|
|
638
|
+
matchedStructuredSignal = true;
|
|
639
|
+
}
|
|
640
|
+
const conditionDsl = belief.metadata?.conditionDsl;
|
|
641
|
+
if (conditionDsl) {
|
|
642
|
+
const conditionResult = ConditionDslEvaluator.evaluate(conditionDsl, {
|
|
643
|
+
projectId: input.projectId,
|
|
644
|
+
rawQuery: input.query,
|
|
645
|
+
conditionHints: input.semantics?.conditionHints,
|
|
646
|
+
entityHints: input.semantics?.entityHints,
|
|
647
|
+
environmentHints: input.semantics?.environmentHints,
|
|
648
|
+
stateHints: input.semantics?.stateHints,
|
|
649
|
+
policyHints: input.semantics?.policyHints
|
|
650
|
+
});
|
|
651
|
+
if (conditionResult.matched) {
|
|
652
|
+
score += 3.2 + conditionResult.score * 0.8;
|
|
653
|
+
matchedRuntimeSignal = true;
|
|
654
|
+
}
|
|
655
|
+
else
|
|
656
|
+
score -= 3.2;
|
|
657
|
+
}
|
|
658
|
+
const planDsl = belief.metadata?.planDsl;
|
|
659
|
+
if (planDsl && input.structuredTargets.predicatePrefix === 'workflow.plan.') {
|
|
660
|
+
const planText = JSON.stringify(planDsl).toLowerCase();
|
|
661
|
+
for (const hint of input.semantics?.entityHints || []) {
|
|
662
|
+
if (planText.includes(hint.toLowerCase()))
|
|
663
|
+
score += 0.7;
|
|
664
|
+
}
|
|
665
|
+
for (const hint of input.semantics?.environmentHints || []) {
|
|
666
|
+
if (planText.includes(hint.toLowerCase()))
|
|
667
|
+
score += 0.55;
|
|
668
|
+
}
|
|
669
|
+
for (const hint of input.semantics?.stateHints || []) {
|
|
670
|
+
if (planText.includes(hint.toLowerCase()))
|
|
671
|
+
score += 0.75;
|
|
672
|
+
}
|
|
673
|
+
for (const hint of input.semantics?.policyHints || []) {
|
|
674
|
+
if (planText.includes(hint.toLowerCase()))
|
|
675
|
+
score += 0.75;
|
|
676
|
+
}
|
|
677
|
+
for (const hint of input.semantics?.guardHints || []) {
|
|
678
|
+
if (planText.includes(hint.toLowerCase()))
|
|
679
|
+
score += 0.65;
|
|
680
|
+
}
|
|
681
|
+
for (const hint of input.semantics?.executorHints || []) {
|
|
682
|
+
if (planText.includes(hint.toLowerCase()))
|
|
683
|
+
score += 0.75;
|
|
684
|
+
}
|
|
685
|
+
for (const hint of input.semantics?.validationHints || []) {
|
|
686
|
+
if (planText.includes(hint.toLowerCase()))
|
|
687
|
+
score += 0.65;
|
|
688
|
+
}
|
|
689
|
+
for (const hint of input.semantics?.mergeHints || []) {
|
|
690
|
+
if (planText.includes(hint.toLowerCase()))
|
|
691
|
+
score += 0.65;
|
|
692
|
+
}
|
|
693
|
+
for (const hint of input.semantics?.valueHints || []) {
|
|
694
|
+
if (planText.includes(hint.toLowerCase()))
|
|
695
|
+
score += 0.6;
|
|
696
|
+
}
|
|
697
|
+
if (Array.isArray(planDsl.executionGuards) && /guard|approval|批准|审批/i.test(input.query)) {
|
|
698
|
+
score += 0.8;
|
|
699
|
+
}
|
|
700
|
+
if (Array.isArray(planDsl.stateMachines) && (input.semantics?.stateHints?.length || 0) > 0) {
|
|
701
|
+
score += 0.9;
|
|
702
|
+
}
|
|
703
|
+
if (Array.isArray(planDsl.policyRuntime) && (input.semantics?.policyHints?.length || 0) > 0) {
|
|
704
|
+
score += 0.9;
|
|
705
|
+
}
|
|
706
|
+
if (Array.isArray(planDsl.mergeConstraints) && /merge|合并|constraint|约束/i.test(input.query)) {
|
|
707
|
+
score += 0.7;
|
|
708
|
+
}
|
|
709
|
+
if (Array.isArray(planDsl.runtimeValidation) && /validate|校验|check/i.test(input.query)) {
|
|
710
|
+
score += 0.7;
|
|
711
|
+
}
|
|
712
|
+
if (Array.isArray(planDsl.executorBindings) && /execute|executor|执行/i.test(input.query)) {
|
|
713
|
+
score += 0.8;
|
|
714
|
+
}
|
|
715
|
+
if (Array.isArray(planDsl.mergePropagation) && /propagate|传播|merge/i.test(input.query)) {
|
|
716
|
+
score += 0.8;
|
|
717
|
+
}
|
|
718
|
+
const defaultEntityStateKey = input.structuredTargets.entity || 'service';
|
|
719
|
+
const executionAnalysis = PlanDslExecutor.analyze(planDsl, {
|
|
720
|
+
completedSteps: input.semantics?.mergeHints,
|
|
721
|
+
availableChecks: input.semantics?.validationHints,
|
|
722
|
+
approvals: input.semantics?.guardHints,
|
|
723
|
+
availableExecutors: input.semantics?.executorHints,
|
|
724
|
+
activePolicies: input.semantics?.policyHints,
|
|
725
|
+
entityStates: Object.fromEntries((input.semantics?.stateHints || []).map((state) => [defaultEntityStateKey, state])),
|
|
726
|
+
mergeArtifacts: input.semantics?.mergeHints
|
|
727
|
+
});
|
|
728
|
+
if (executionAnalysis.executableSteps.length > 0) {
|
|
729
|
+
score += Math.min(executionAnalysis.executableSteps.length, 3) * 0.25;
|
|
730
|
+
matchedRuntimeSignal = true;
|
|
731
|
+
}
|
|
732
|
+
if (executionAnalysis.blockedSteps.length > 0)
|
|
733
|
+
score -= Math.min(executionAnalysis.blockedSteps.length, 3) * 0.18;
|
|
734
|
+
if (executionAnalysis.mergeReadiness.some((item) => item.ready)) {
|
|
735
|
+
score += 0.45;
|
|
736
|
+
matchedRuntimeSignal = true;
|
|
737
|
+
}
|
|
738
|
+
if (executionAnalysis.validationReadiness.some((item) => item.ready)) {
|
|
739
|
+
score += 0.35;
|
|
740
|
+
matchedRuntimeSignal = true;
|
|
741
|
+
}
|
|
742
|
+
if (executionAnalysis.executorMatches.some((item) => item.matched)) {
|
|
743
|
+
score += 0.45;
|
|
744
|
+
matchedRuntimeSignal = true;
|
|
745
|
+
}
|
|
746
|
+
if (executionAnalysis.policyCoverage.some((item) => item.matched)) {
|
|
747
|
+
score += 0.4;
|
|
748
|
+
matchedRuntimeSignal = true;
|
|
749
|
+
}
|
|
750
|
+
const runtimeDecision = PolicyRuntimeEvaluator.evaluate({
|
|
751
|
+
conditionDsl: belief.metadata?.conditionDsl,
|
|
752
|
+
planDsl
|
|
753
|
+
}, {
|
|
754
|
+
projectId: input.projectId,
|
|
755
|
+
rawQuery: input.query,
|
|
756
|
+
conditionHints: input.semantics?.conditionHints,
|
|
757
|
+
entityHints: input.semantics?.entityHints,
|
|
758
|
+
environmentHints: input.semantics?.environmentHints,
|
|
759
|
+
stateHints: input.semantics?.stateHints,
|
|
760
|
+
policyHints: input.semantics?.policyHints,
|
|
761
|
+
completedSteps: input.semantics?.mergeHints,
|
|
762
|
+
availableChecks: input.semantics?.validationHints,
|
|
763
|
+
approvals: input.semantics?.guardHints,
|
|
764
|
+
availableExecutors: input.semantics?.executorHints,
|
|
765
|
+
activePolicies: input.semantics?.policyHints,
|
|
766
|
+
entityStates: Object.fromEntries((input.semantics?.stateHints || []).map((state) => [defaultEntityStateKey, state])),
|
|
767
|
+
mergeArtifacts: input.semantics?.mergeHints
|
|
768
|
+
});
|
|
769
|
+
if (runtimeDecision.allowed) {
|
|
770
|
+
score += 0.9;
|
|
771
|
+
matchedRuntimeSignal = true;
|
|
772
|
+
}
|
|
773
|
+
else
|
|
774
|
+
score -= 0.5;
|
|
775
|
+
}
|
|
776
|
+
if (belief.canonicalKey.toLowerCase().includes(query)) {
|
|
777
|
+
score += 1.5;
|
|
778
|
+
matchedLexicalSignal = true;
|
|
779
|
+
}
|
|
780
|
+
if (!matchedLexicalSignal && !matchedStructuredSignal && !matchedRuntimeSignal) {
|
|
781
|
+
return 0;
|
|
782
|
+
}
|
|
783
|
+
if (input.projectId && belief.projectId === input.projectId)
|
|
784
|
+
score += 0.8;
|
|
785
|
+
if (belief.scope === 'project')
|
|
786
|
+
score += 0.3;
|
|
787
|
+
if (belief.scope === 'global')
|
|
788
|
+
score += 0.1;
|
|
789
|
+
score += belief.confidence * 0.6;
|
|
790
|
+
score += belief.trustScore * 0.6;
|
|
791
|
+
if (belief.status === 'active')
|
|
792
|
+
score += 0.4;
|
|
793
|
+
return score;
|
|
794
|
+
}
|
|
795
|
+
computeExecutionFeedbackForBelief(belief, records) {
|
|
796
|
+
const planDsl = belief.metadata?.planDsl;
|
|
797
|
+
if (!planDsl)
|
|
798
|
+
return null;
|
|
799
|
+
const policyGroup = typeof planDsl.policyGroup === 'string'
|
|
800
|
+
? planDsl.policyGroup
|
|
801
|
+
: typeof belief.metadata?.policyGroup === 'string'
|
|
802
|
+
? String(belief.metadata.policyGroup)
|
|
803
|
+
: undefined;
|
|
804
|
+
const serialized = JSON.stringify(planDsl);
|
|
805
|
+
const policies = Array.from(new Set([...serialized.matchAll(/"(?:policy|name)"\s*:\s*"([^"]+)"/g)].map((match) => match[1] || ''))).filter(Boolean);
|
|
806
|
+
const matched = records.filter((record) => {
|
|
807
|
+
if (policyGroup && record.policyGroup === policyGroup)
|
|
808
|
+
return true;
|
|
809
|
+
if (policies.includes(record.policy))
|
|
810
|
+
return true;
|
|
811
|
+
return false;
|
|
812
|
+
});
|
|
813
|
+
if (matched.length === 0)
|
|
814
|
+
return null;
|
|
815
|
+
return {
|
|
816
|
+
matchedExecutions: matched.length,
|
|
817
|
+
executed: matched.filter((record) => record.status === 'executed').length,
|
|
818
|
+
failed: matched.filter((record) => record.status === 'failed').length,
|
|
819
|
+
latestUpdatedAt: matched.reduce((max, record) => Math.max(max, record.updatedAt), 0) || undefined
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
extractQueryTokens(query, entities, mustMatch, shouldMatch) {
|
|
823
|
+
const baseTokens = query
|
|
824
|
+
.split(/[\s,,。!?、::/]+/)
|
|
825
|
+
.map((token) => token.trim())
|
|
826
|
+
.filter((token) => token.length >= 2);
|
|
827
|
+
return Array.from(new Set([
|
|
828
|
+
...baseTokens,
|
|
829
|
+
...(entities || []),
|
|
830
|
+
...(mustMatch || []),
|
|
831
|
+
...(shouldMatch || [])
|
|
832
|
+
].map((token) => token.toLowerCase()).filter((token) => token.length >= 2)));
|
|
833
|
+
}
|
|
834
|
+
extractStructuredTargets(query, intent, tokens, semantics) {
|
|
835
|
+
const target = {};
|
|
836
|
+
target.subject = semantics?.subjectHint || (/(我|i|my|mine)/i.test(query) ? 'user' : undefined);
|
|
837
|
+
target.asksForHistory = semantics?.asksForHistory;
|
|
838
|
+
const predicateHint = semantics?.predicateHint;
|
|
839
|
+
if (intent === 'preference_lookup' || predicateHint === 'preference') {
|
|
840
|
+
target.predicatePrefix = 'preference.';
|
|
841
|
+
if (/(喜欢|prefer|like)/i.test(query))
|
|
842
|
+
target.expectedValue = 'like';
|
|
843
|
+
if (/(讨厌|dislike|不喜欢)/i.test(query))
|
|
844
|
+
target.expectedValue = 'dislike';
|
|
845
|
+
}
|
|
846
|
+
else if (intent === 'decision_lookup' || predicateHint === 'decision') {
|
|
847
|
+
target.predicatePrefix = 'decision.';
|
|
848
|
+
target.expectedValue = 'selected';
|
|
849
|
+
}
|
|
850
|
+
else if (intent === 'constraint_lookup' || predicateHint === 'constraint') {
|
|
851
|
+
target.predicatePrefix = 'constraint.';
|
|
852
|
+
}
|
|
853
|
+
else if (intent === 'fact_lookup' || predicateHint === 'fact') {
|
|
854
|
+
target.predicatePrefix = 'fact.';
|
|
855
|
+
}
|
|
856
|
+
else if (predicateHint === 'workflow') {
|
|
857
|
+
target.predicatePrefix = 'workflow.';
|
|
858
|
+
}
|
|
859
|
+
else if (predicateHint === 'graph') {
|
|
860
|
+
target.predicatePrefix = 'fact.graph.';
|
|
861
|
+
}
|
|
862
|
+
else if (predicateHint === 'sequence') {
|
|
863
|
+
target.predicatePrefix = 'workflow.sequence.';
|
|
864
|
+
}
|
|
865
|
+
else if (predicateHint === 'plan') {
|
|
866
|
+
target.predicatePrefix = 'workflow.plan.';
|
|
867
|
+
}
|
|
868
|
+
target.entity = semantics?.entityHints?.[0] || this.pickEntityToken(tokens, query, intent);
|
|
869
|
+
if (!target.expectedValue && semantics?.valueHints?.[0])
|
|
870
|
+
target.expectedValue = semantics.valueHints[0];
|
|
871
|
+
return target;
|
|
872
|
+
}
|
|
873
|
+
pickEntityToken(tokens, query, intent) {
|
|
874
|
+
const stopwords = new Set([
|
|
875
|
+
'what', 'which', '喜欢', '讨厌', '偏好', 'prefer', 'preference', 'like', 'dislike',
|
|
876
|
+
'决定', '选择', 'decide', 'decision', 'choose', '约束', '限制', '必须', '不能',
|
|
877
|
+
'constraint', 'rule', 'debug', 'error', 'trace', 'project'
|
|
878
|
+
]);
|
|
879
|
+
const preferred = tokens.find((token) => !stopwords.has(token) && !/^(我|i)$/i.test(token));
|
|
880
|
+
if (preferred)
|
|
881
|
+
return preferred.toLowerCase();
|
|
882
|
+
if (intent === 'preference_lookup' || intent === 'decision_lookup') {
|
|
883
|
+
const match = query.match(/(?:喜欢|讨厌|偏好|prefer|like|dislike|决定|选择|choose|decide(?:\s+to\s+use)?)\s+([\w\-./]+)/i);
|
|
884
|
+
if (match?.[1])
|
|
885
|
+
return match[1].toLowerCase();
|
|
886
|
+
}
|
|
887
|
+
return undefined;
|
|
888
|
+
}
|
|
889
|
+
clamp(value, min, max) {
|
|
890
|
+
return Math.max(min, Math.min(max, value));
|
|
891
|
+
}
|
|
892
|
+
close() {
|
|
893
|
+
if (this.closed)
|
|
894
|
+
return;
|
|
895
|
+
this.db.close();
|
|
896
|
+
this.closed = true;
|
|
897
|
+
}
|
|
898
|
+
}
|