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,574 @@
|
|
|
1
|
+
import { ConversationMarkdownAdapter, HermesStateDbAdapter, MarkdownSourceLoader, OpenClawDailyMemoryAdapter, OpenClawMemoryIndexAdapter, OpenClawPersonaAdapter, OpenClawSessionAdapter, OpenClawUserProfileAdapter, SoulMarkdownAdapter } from '../adapters/index.js';
|
|
2
|
+
import { LocalSemanticCompiler } from '../engine/LocalSemanticCompiler.js';
|
|
3
|
+
import { normalizeLexiconText } from '../lexicon/coreMemoryLexicon.js';
|
|
4
|
+
import { logger } from '../utils/Logger.js';
|
|
5
|
+
import { config as globalConfig } from '../utils/Config.js';
|
|
6
|
+
import { isRecallableMemoryEvidence } from './RecallGovernance.js';
|
|
7
|
+
export class BrainRecall {
|
|
8
|
+
deps;
|
|
9
|
+
semanticCompiler = new LocalSemanticCompiler();
|
|
10
|
+
loader = new MarkdownSourceLoader();
|
|
11
|
+
adapters = new Map([
|
|
12
|
+
['conversation_markdown', new ConversationMarkdownAdapter()],
|
|
13
|
+
['hermes_state_db', new HermesStateDbAdapter()],
|
|
14
|
+
['soul_markdown', new SoulMarkdownAdapter()],
|
|
15
|
+
['openclaw_daily_memory', new OpenClawDailyMemoryAdapter()],
|
|
16
|
+
['openclaw_session', new OpenClawSessionAdapter()],
|
|
17
|
+
['openclaw_memory_index', new OpenClawMemoryIndexAdapter()],
|
|
18
|
+
['openclaw_user_profile', new OpenClawUserProfileAdapter()],
|
|
19
|
+
['openclaw_persona', new OpenClawPersonaAdapter()]
|
|
20
|
+
]);
|
|
21
|
+
constructor(deps) {
|
|
22
|
+
this.deps = deps;
|
|
23
|
+
}
|
|
24
|
+
recall(query, options = {}) {
|
|
25
|
+
const prepared = this.prepareRecallCandidates(query, options);
|
|
26
|
+
const vectorSearchUsed = this.appendVectorResults(prepared.candidateNeuronIds, query, options.projectId, prepared.limit, prepared.vectorTopicPath);
|
|
27
|
+
return this.finishRecall(query, options, prepared, vectorSearchUsed);
|
|
28
|
+
}
|
|
29
|
+
async recallAsync(query, options = {}) {
|
|
30
|
+
const prepared = this.prepareRecallCandidates(query, options);
|
|
31
|
+
const vectorSearchUsed = await this.appendVectorResultsAsync(prepared.candidateNeuronIds, query, options.projectId, prepared.limit, prepared.vectorTopicPath);
|
|
32
|
+
return this.finishRecall(query, options, prepared, vectorSearchUsed);
|
|
33
|
+
}
|
|
34
|
+
prepareRecallCandidates(query, options) {
|
|
35
|
+
const limit = options.limit ?? 6;
|
|
36
|
+
const compiledQuery = this.semanticCompiler.compileQuery({ text: query, projectId: options.projectId });
|
|
37
|
+
const resolvedEntityIds = compiledQuery.entities
|
|
38
|
+
.flatMap((entity) => {
|
|
39
|
+
const direct = this.deps.entityStore.findByCanonicalName(entity.text, entity.type);
|
|
40
|
+
const alias = direct || this.deps.entityStore.findByAlias(entity.text, entity.type);
|
|
41
|
+
return alias ? [alias.entityId] : [];
|
|
42
|
+
});
|
|
43
|
+
const candidateEntityIds = this.expandEntityIdsViaPersistentGainEdges(Array.from(new Set(resolvedEntityIds)), options.enablePersistentGainEdges !== false, options.enableDeepWriteEdges === true);
|
|
44
|
+
const candidateNeuronIds = Array.from(new Set([
|
|
45
|
+
...this.deps.memoryGraph.fullTextSearch(query, options.projectId, limit * 4),
|
|
46
|
+
...this.deps.factStore.listNeuronIdsByEntityIds(candidateEntityIds, limit * 6)
|
|
47
|
+
]));
|
|
48
|
+
const topicRouteResult = this.routeByTopic(query, options.projectId, options.topicPath, candidateNeuronIds);
|
|
49
|
+
this.retainRecallableNeuronIds(candidateNeuronIds);
|
|
50
|
+
const vectorTopicPath = topicRouteResult && !topicRouteResult.fallbackToGlobal
|
|
51
|
+
? topicRouteResult.matchedTopicPath ?? options.topicPath
|
|
52
|
+
: undefined;
|
|
53
|
+
return {
|
|
54
|
+
limit,
|
|
55
|
+
candidateEntityIds,
|
|
56
|
+
candidateNeuronIds,
|
|
57
|
+
topicRouteResult,
|
|
58
|
+
vectorTopicPath
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
finishRecall(query, options, prepared, vectorSearchUsed) {
|
|
62
|
+
const { limit, candidateEntityIds, candidateNeuronIds, topicRouteResult } = prepared;
|
|
63
|
+
const beliefs = this.deps.beliefStore.getActiveBeliefsForQuery({
|
|
64
|
+
query,
|
|
65
|
+
projectId: options.projectId,
|
|
66
|
+
limit
|
|
67
|
+
});
|
|
68
|
+
const facts = this.rankFacts(query, [
|
|
69
|
+
...this.deps.factStore.listFactsByNeuronIds(candidateNeuronIds, limit * 8),
|
|
70
|
+
...this.deps.factStore.listFactsByEntityIds(candidateEntityIds, { limit: limit * 8 })
|
|
71
|
+
]).slice(0, limit);
|
|
72
|
+
const events = this.rankEvents(query, this.deps.factStore.listEventsByNeuronIds(candidateNeuronIds, limit * 6)).slice(0, limit);
|
|
73
|
+
const entityTimeline = this.deps.entityStore.getEntityTimeline({
|
|
74
|
+
projectId: options.projectId,
|
|
75
|
+
entityIds: candidateEntityIds.length > 0 ? candidateEntityIds : undefined,
|
|
76
|
+
limit: limit * 3
|
|
77
|
+
});
|
|
78
|
+
const compiledHitCount = beliefs.length + facts.length + events.length + entityTimeline.length;
|
|
79
|
+
const rawEvidence = options.includeRawEvidence === false
|
|
80
|
+
? []
|
|
81
|
+
: this.toRecallableNeurons(candidateNeuronIds, limit);
|
|
82
|
+
this._expandByCommunity(rawEvidence, limit);
|
|
83
|
+
if (topicRouteResult && !topicRouteResult.fallbackToGlobal && options.includeRawEvidence !== false) {
|
|
84
|
+
const summaryTopicPath = topicRouteResult.matchedTopicPath ?? options.topicPath ?? rawEvidence[0]?.metadata.topicPath ?? '';
|
|
85
|
+
const summary = this.deps.topicSummaryBoard?.getSummaryNeuron(summaryTopicPath, options.projectId);
|
|
86
|
+
const index = summary ? rawEvidence.findIndex((item) => item.id === summary.id) : -1;
|
|
87
|
+
if (summary && this.isRecallableNeuron(summary) && index >= 0)
|
|
88
|
+
rawEvidence.unshift(...rawEvidence.splice(index, 1));
|
|
89
|
+
else if (summary && this.isRecallableNeuron(summary))
|
|
90
|
+
rawEvidence.unshift(summary);
|
|
91
|
+
}
|
|
92
|
+
this._prependSemanticConsolidations(rawEvidence, options.projectId, topicRouteResult?.matchedTopicPath ?? options.topicPath);
|
|
93
|
+
this._prependCrossDomainPrinciples(rawEvidence, options.projectId);
|
|
94
|
+
const profileSignals = this.collectProfileSignals(query, options.projectId, limit);
|
|
95
|
+
const profileSurface = this.collectProfileSurface(query, options.projectId, limit);
|
|
96
|
+
const totalStructuredHits = compiledHitCount + profileSignals.length + profileSurface.userProfile.length + profileSurface.agentPersona.length;
|
|
97
|
+
const fallbackSnippets = totalStructuredHits > 0 || options.includeUnprocessedFallback === false
|
|
98
|
+
? []
|
|
99
|
+
: this.collectFallbackSnippets(query, options.projectId, limit);
|
|
100
|
+
const result = {
|
|
101
|
+
query,
|
|
102
|
+
strategy: {
|
|
103
|
+
primaryLevel: totalStructuredHits > 0
|
|
104
|
+
? 'compiled_memory'
|
|
105
|
+
: rawEvidence.length > 0
|
|
106
|
+
? 'raw_evidence'
|
|
107
|
+
: 'recent_unprocessed_sources',
|
|
108
|
+
fallbackUsed: fallbackSnippets.length > 0,
|
|
109
|
+
vectorSearchUsed
|
|
110
|
+
},
|
|
111
|
+
compiledMemory: {
|
|
112
|
+
beliefs,
|
|
113
|
+
facts,
|
|
114
|
+
events,
|
|
115
|
+
entityTimeline
|
|
116
|
+
},
|
|
117
|
+
rawEvidence,
|
|
118
|
+
fallbackSnippets,
|
|
119
|
+
profileSignals,
|
|
120
|
+
profileSurface
|
|
121
|
+
};
|
|
122
|
+
if (topicRouteResult) {
|
|
123
|
+
result.topicRouteInfo = {
|
|
124
|
+
matchedTopicPath: topicRouteResult.matchedTopicPath,
|
|
125
|
+
confidence: topicRouteResult.confidence,
|
|
126
|
+
fallbackToGlobal: topicRouteResult.fallbackToGlobal
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
const withOptionalSkillCandidates = this.withSkillCandidates(result, query, options.projectId, limit);
|
|
130
|
+
return this.withFileEvidence(this.withSummaries(withOptionalSkillCandidates, options.projectId, limit));
|
|
131
|
+
}
|
|
132
|
+
_prependSemanticConsolidations(rawEvidence, projectId, topicPath) {
|
|
133
|
+
const semantic = this.findDurableNeuronsByType('semantic_consolidation', {
|
|
134
|
+
projectId,
|
|
135
|
+
topicPath,
|
|
136
|
+
limit: 3
|
|
137
|
+
}).filter((neuron) => this.isRecallableNeuron(neuron));
|
|
138
|
+
for (const neuron of semantic) {
|
|
139
|
+
const index = rawEvidence.findIndex((item) => item.id === neuron.id);
|
|
140
|
+
if (index >= 0)
|
|
141
|
+
rawEvidence.splice(index, 1);
|
|
142
|
+
}
|
|
143
|
+
rawEvidence.unshift(...semantic);
|
|
144
|
+
}
|
|
145
|
+
_prependCrossDomainPrinciples(rawEvidence, projectId) {
|
|
146
|
+
const principles = this.findDurableNeuronsByType('cross_domain_principle', {
|
|
147
|
+
projectId,
|
|
148
|
+
limit: 2
|
|
149
|
+
}).filter((neuron) => this.isRecallableNeuron(neuron));
|
|
150
|
+
for (const neuron of principles) {
|
|
151
|
+
const index = rawEvidence.findIndex((item) => item.id === neuron.id);
|
|
152
|
+
if (index >= 0)
|
|
153
|
+
rawEvidence.splice(index, 1);
|
|
154
|
+
}
|
|
155
|
+
rawEvidence.unshift(...principles);
|
|
156
|
+
}
|
|
157
|
+
findDurableNeuronsByType(type, options) {
|
|
158
|
+
const indexedLookup = this.deps.memoryGraph.findNeuronsByType;
|
|
159
|
+
if (typeof indexedLookup !== 'function')
|
|
160
|
+
return [];
|
|
161
|
+
return indexedLookup.call(this.deps.memoryGraph, type, options);
|
|
162
|
+
}
|
|
163
|
+
_expandByCommunity(rawEvidence, limit) {
|
|
164
|
+
const ids = new Set(rawEvidence.map((n) => n.id));
|
|
165
|
+
const communityIds = Array.from(new Set(rawEvidence.map((n) => n.metadata.communityId).filter(Boolean)));
|
|
166
|
+
for (const communityId of communityIds)
|
|
167
|
+
for (const id of this.deps.graphCommunityEngine?.getCommunityMembers(communityId) || []) {
|
|
168
|
+
if (ids.has(id) || rawEvidence.length >= limit + 3)
|
|
169
|
+
continue;
|
|
170
|
+
const neuron = this.deps.memoryGraph.getNeuron(id);
|
|
171
|
+
if (this.isRecallableNeuron(neuron)) {
|
|
172
|
+
rawEvidence.push(neuron);
|
|
173
|
+
ids.add(id);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
routeByTopic(query, projectId, topicPath, candidateNeuronIds) {
|
|
178
|
+
if (!this.deps.hierarchicalRouter && !topicPath)
|
|
179
|
+
return undefined;
|
|
180
|
+
const routed = this.deps.hierarchicalRouter?.route(query, projectId, topicPath);
|
|
181
|
+
if (!routed || routed.fallbackToGlobal)
|
|
182
|
+
return routed;
|
|
183
|
+
const allowed = new Set(routed.candidateNeuronIds);
|
|
184
|
+
for (let index = candidateNeuronIds.length - 1; index >= 0; index--) {
|
|
185
|
+
if (!allowed.has(candidateNeuronIds[index]))
|
|
186
|
+
candidateNeuronIds.splice(index, 1);
|
|
187
|
+
}
|
|
188
|
+
const existing = new Set(candidateNeuronIds);
|
|
189
|
+
for (const id of routed.candidateNeuronIds) {
|
|
190
|
+
if (!existing.has(id)) {
|
|
191
|
+
candidateNeuronIds.push(id);
|
|
192
|
+
existing.add(id);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return routed;
|
|
196
|
+
}
|
|
197
|
+
withSkillCandidates(result, query, projectId, limit) {
|
|
198
|
+
if (!this.deps.skillDiscoveryEngine)
|
|
199
|
+
return result;
|
|
200
|
+
return {
|
|
201
|
+
...result,
|
|
202
|
+
skillCandidates: this.deps.skillDiscoveryEngine.findCandidates(query, projectId, Math.min(5, limit))
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
withFileEvidence(result) {
|
|
206
|
+
if (!this.deps.fileChunkStore || result.rawEvidence.length === 0)
|
|
207
|
+
return result;
|
|
208
|
+
const evidence = this.deps.fileChunkStore.listEvidenceByNeuronIds(result.rawEvidence.map((neuron) => neuron.id));
|
|
209
|
+
if (evidence.length === 0)
|
|
210
|
+
return result;
|
|
211
|
+
return {
|
|
212
|
+
...result,
|
|
213
|
+
fileEvidence: this.deps.fileChunkStore.groupEvidenceByAsset(evidence)
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
expandEntityIdsViaPersistentGainEdges(resolvedEntityIds, enabled, enableDeepWriteEdges = false) {
|
|
217
|
+
if (!enabled || resolvedEntityIds.length === 0 || !this.deps.graphEdgeStore?.listActiveNeighborEdges) {
|
|
218
|
+
return resolvedEntityIds;
|
|
219
|
+
}
|
|
220
|
+
try {
|
|
221
|
+
const edgeTypes = [
|
|
222
|
+
'persistent_gain',
|
|
223
|
+
...(enableDeepWriteEdges ? ['deep_write_relation', 'deep_write_causal'] : [])
|
|
224
|
+
];
|
|
225
|
+
const activePersistentGainEdges = this.deps.graphEdgeStore.listActiveNeighborEdges(resolvedEntityIds, edgeTypes, Math.max(32, resolvedEntityIds.length * 8));
|
|
226
|
+
const relevantEdges = activePersistentGainEdges.filter((edge) => (edge.fromNodeId !== undefined && resolvedEntityIds.includes(edge.fromNodeId))
|
|
227
|
+
|| (edge.toNodeId !== undefined && resolvedEntityIds.includes(edge.toNodeId)));
|
|
228
|
+
if (relevantEdges.length === 0) {
|
|
229
|
+
logger.debug('RPI-2 persistent_gain expansion fell back to baseline: reason=no_edges_for_resolved_entities');
|
|
230
|
+
return resolvedEntityIds;
|
|
231
|
+
}
|
|
232
|
+
const ambiguityReason = this.detectPersistentGainAmbiguity(relevantEdges, resolvedEntityIds);
|
|
233
|
+
if (ambiguityReason) {
|
|
234
|
+
logger.warn(`RPI-2 persistent_gain expansion fell back to baseline: reason=${ambiguityReason}`);
|
|
235
|
+
return resolvedEntityIds;
|
|
236
|
+
}
|
|
237
|
+
const expandedEntityIds = new Set(resolvedEntityIds);
|
|
238
|
+
for (const edge of relevantEdges) {
|
|
239
|
+
if (edge.fromNodeId !== undefined && edge.toNodeId !== undefined && resolvedEntityIds.includes(edge.fromNodeId)) {
|
|
240
|
+
expandedEntityIds.add(edge.toNodeId);
|
|
241
|
+
}
|
|
242
|
+
if (edge.fromNodeId !== undefined && edge.toNodeId !== undefined && resolvedEntityIds.includes(edge.toNodeId)) {
|
|
243
|
+
expandedEntityIds.add(edge.fromNodeId);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const expanded = Array.from(expandedEntityIds);
|
|
247
|
+
logger.info('RPI-2 persistent_gain expansion applied', {
|
|
248
|
+
resolvedEntityIds,
|
|
249
|
+
expandedEntityIds: expanded,
|
|
250
|
+
traversedEdges: relevantEdges.map((edge) => ({
|
|
251
|
+
fromNodeId: edge.fromNodeId,
|
|
252
|
+
toNodeId: edge.toNodeId,
|
|
253
|
+
weight: edge.weight
|
|
254
|
+
}))
|
|
255
|
+
});
|
|
256
|
+
return expanded;
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
logger.warn('RPI-2 persistent_gain expansion fell back to baseline: reason=edge_read_failed', error);
|
|
260
|
+
return resolvedEntityIds;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
withSummaries(result, projectId, limit) {
|
|
264
|
+
if (!this.deps.summaryStore)
|
|
265
|
+
return result;
|
|
266
|
+
const summaries = this.deps.summaryStore.findRelevant(result.query, projectId, Math.min(3, limit))
|
|
267
|
+
.map((summary) => ({
|
|
268
|
+
summaryId: summary.summaryId,
|
|
269
|
+
text: summary.text,
|
|
270
|
+
scope: summary.scope,
|
|
271
|
+
windowStart: summary.windowStart,
|
|
272
|
+
windowEnd: summary.windowEnd,
|
|
273
|
+
confidence: summary.confidence
|
|
274
|
+
}));
|
|
275
|
+
return summaries.length > 0 ? { ...result, summaries } : result;
|
|
276
|
+
}
|
|
277
|
+
detectPersistentGainAmbiguity(edges, resolvedEntityIds) {
|
|
278
|
+
const neighborSets = new Map();
|
|
279
|
+
for (const edge of edges) {
|
|
280
|
+
if (!edge.fromNodeId || !edge.toNodeId || edge.fromNodeId === edge.toNodeId) {
|
|
281
|
+
return 'ambiguous_edge_payload';
|
|
282
|
+
}
|
|
283
|
+
if (!this.deps.entityStore.findByEntityId(edge.fromNodeId) || !this.deps.entityStore.findByEntityId(edge.toNodeId)) {
|
|
284
|
+
return 'ambiguous_unknown_target_entity';
|
|
285
|
+
}
|
|
286
|
+
if (resolvedEntityIds.includes(edge.fromNodeId)) {
|
|
287
|
+
const neighbors = neighborSets.get(edge.fromNodeId) || new Set();
|
|
288
|
+
neighbors.add(edge.toNodeId);
|
|
289
|
+
neighborSets.set(edge.fromNodeId, neighbors);
|
|
290
|
+
}
|
|
291
|
+
if (resolvedEntityIds.includes(edge.toNodeId)) {
|
|
292
|
+
const neighbors = neighborSets.get(edge.toNodeId) || new Set();
|
|
293
|
+
neighbors.add(edge.fromNodeId);
|
|
294
|
+
neighborSets.set(edge.toNodeId, neighbors);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
for (const neighbors of neighborSets.values()) {
|
|
298
|
+
if (neighbors.size > 1)
|
|
299
|
+
return 'ambiguous_multiple_hop_targets';
|
|
300
|
+
}
|
|
301
|
+
return undefined;
|
|
302
|
+
}
|
|
303
|
+
collectProfileSignals(query, projectId, limit) {
|
|
304
|
+
return this.deps.memoryGraph.fullTextSearch(query, projectId, limit * 6)
|
|
305
|
+
.map((neuronId) => this.deps.memoryGraph.getNeuron(neuronId))
|
|
306
|
+
.filter((item) => Boolean(item))
|
|
307
|
+
.filter((neuron) => this.isRecallableNeuron(neuron))
|
|
308
|
+
.filter((neuron) => {
|
|
309
|
+
const tags = neuron.metadata.tags || [];
|
|
310
|
+
return tags.includes('namespace:user_profile') || tags.includes('namespace:agent_persona');
|
|
311
|
+
})
|
|
312
|
+
.slice(0, limit)
|
|
313
|
+
.map((neuron) => ({
|
|
314
|
+
neuronId: neuron.id,
|
|
315
|
+
sourcePath: neuron.metadata.filePath,
|
|
316
|
+
text: neuron.content,
|
|
317
|
+
tags: neuron.metadata.tags || [],
|
|
318
|
+
namespace: (neuron.metadata.tags || []).includes('namespace:user_profile')
|
|
319
|
+
? 'user_profile'
|
|
320
|
+
: 'agent_persona'
|
|
321
|
+
}));
|
|
322
|
+
}
|
|
323
|
+
collectFallbackSnippets(query, projectId, limit) {
|
|
324
|
+
const tokens = this.extractTokens(query);
|
|
325
|
+
const sources = this.deps.cursorStore
|
|
326
|
+
.listRecentUnprocessedSources(Date.now() - 72 * 60 * 60 * 1000)
|
|
327
|
+
.filter((source) => !projectId || source.projectId === projectId);
|
|
328
|
+
const snippets = [];
|
|
329
|
+
for (const sourceCursor of sources) {
|
|
330
|
+
if (snippets.length >= limit)
|
|
331
|
+
break;
|
|
332
|
+
const source = {
|
|
333
|
+
sourceId: sourceCursor.sourceId,
|
|
334
|
+
adapterKind: sourceCursor.sourceType,
|
|
335
|
+
sourcePath: sourceCursor.sourcePath,
|
|
336
|
+
projectId: sourceCursor.projectId
|
|
337
|
+
};
|
|
338
|
+
const adapter = this.adapters.get(source.adapterKind);
|
|
339
|
+
if (!adapter)
|
|
340
|
+
continue;
|
|
341
|
+
const snapshot = this.loader.read(source);
|
|
342
|
+
const adapted = adapter.adapt(source, snapshot);
|
|
343
|
+
const matched = adapted.records
|
|
344
|
+
.filter((record) => this.scoreRecord(tokens, record) > 0)
|
|
345
|
+
.sort((a, b) => this.scoreRecord(tokens, b) - this.scoreRecord(tokens, a))
|
|
346
|
+
.slice(0, limit - snippets.length);
|
|
347
|
+
for (const record of matched) {
|
|
348
|
+
snippets.push({
|
|
349
|
+
sourceId: source.sourceId,
|
|
350
|
+
sourcePath: source.sourcePath,
|
|
351
|
+
text: record.text,
|
|
352
|
+
timestamp: record.timestamp,
|
|
353
|
+
sourceType: source.adapterKind
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return snippets;
|
|
358
|
+
}
|
|
359
|
+
collectProfileSurface(query, projectId, limit) {
|
|
360
|
+
const profileSignals = this.collectProfileSignals(query, projectId, limit * 2);
|
|
361
|
+
const userProfile = [];
|
|
362
|
+
const agentPersona = [];
|
|
363
|
+
for (const signal of profileSignals) {
|
|
364
|
+
const facets = this.extractProfileFacets(signal.text);
|
|
365
|
+
for (const facet of facets) {
|
|
366
|
+
const entry = {
|
|
367
|
+
neuronId: signal.neuronId,
|
|
368
|
+
sourcePath: signal.sourcePath,
|
|
369
|
+
label: facet.label,
|
|
370
|
+
value: facet.value,
|
|
371
|
+
section: facet.section
|
|
372
|
+
};
|
|
373
|
+
if (signal.namespace === 'user_profile')
|
|
374
|
+
userProfile.push(entry);
|
|
375
|
+
else
|
|
376
|
+
agentPersona.push(entry);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return {
|
|
380
|
+
userProfile: userProfile.slice(0, limit),
|
|
381
|
+
agentPersona: agentPersona.slice(0, limit)
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
rankFacts(query, facts) {
|
|
385
|
+
const tokens = this.extractTokens(query);
|
|
386
|
+
return Array.from(new Map(facts.map((fact) => [fact.factId, fact])).values())
|
|
387
|
+
.map((fact) => ({
|
|
388
|
+
fact,
|
|
389
|
+
score: this.scoreText(tokens, [
|
|
390
|
+
fact.subject,
|
|
391
|
+
fact.predicateFamily,
|
|
392
|
+
fact.predicateValue,
|
|
393
|
+
fact.object,
|
|
394
|
+
fact.sourceText
|
|
395
|
+
].filter(Boolean).join(' ')) + fact.confidence
|
|
396
|
+
}))
|
|
397
|
+
.filter((item) => item.score > 0)
|
|
398
|
+
.sort((a, b) => b.score - a.score)
|
|
399
|
+
.map((item) => item.fact);
|
|
400
|
+
}
|
|
401
|
+
rankEvents(query, events) {
|
|
402
|
+
const tokens = this.extractTokens(query);
|
|
403
|
+
return Array.from(new Map(events.map((event) => [event.eventId, event])).values())
|
|
404
|
+
.map((event) => ({
|
|
405
|
+
event,
|
|
406
|
+
score: this.scoreText(tokens, [
|
|
407
|
+
event.eventType,
|
|
408
|
+
event.actor,
|
|
409
|
+
event.target,
|
|
410
|
+
JSON.stringify(event.payload || {})
|
|
411
|
+
].filter(Boolean).join(' ')) + event.confidence
|
|
412
|
+
}))
|
|
413
|
+
.filter((item) => item.score > 0)
|
|
414
|
+
.sort((a, b) => b.score - a.score)
|
|
415
|
+
.map((item) => item.event);
|
|
416
|
+
}
|
|
417
|
+
scoreRecord(tokens, record) {
|
|
418
|
+
return this.scoreText(tokens, `${record.text} ${(record.tags || []).join(' ')}`) + record.confidenceHint;
|
|
419
|
+
}
|
|
420
|
+
scoreText(tokens, text) {
|
|
421
|
+
const haystack = normalizeLexiconText(text).toLowerCase();
|
|
422
|
+
return tokens.filter((token) => haystack.includes(token)).length;
|
|
423
|
+
}
|
|
424
|
+
extractProfileFacets(text) {
|
|
425
|
+
const facets = [];
|
|
426
|
+
const seen = new Set();
|
|
427
|
+
let currentSection;
|
|
428
|
+
for (const rawLine of text.split('\n')) {
|
|
429
|
+
const line = rawLine.trim();
|
|
430
|
+
if (!line)
|
|
431
|
+
continue;
|
|
432
|
+
const heading = line.match(/^#{1,6}\s+(.+)$/);
|
|
433
|
+
if (heading) {
|
|
434
|
+
currentSection = heading[1].trim();
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
const normalized = line
|
|
438
|
+
.replace(/^[-*]\s+/, '')
|
|
439
|
+
.replace(/^\d+\.\s+/, '')
|
|
440
|
+
.trim();
|
|
441
|
+
if (!normalized)
|
|
442
|
+
continue;
|
|
443
|
+
const keyValue = normalized.match(/^([^::]{1,40})[::]\s*(.+)$/);
|
|
444
|
+
if (keyValue) {
|
|
445
|
+
const label = this.normalizeProfileLabel(keyValue[1].trim(), currentSection);
|
|
446
|
+
const value = keyValue[2].trim();
|
|
447
|
+
const dedupeKey = `${label}::${value}`.toLowerCase();
|
|
448
|
+
if (!seen.has(dedupeKey)) {
|
|
449
|
+
seen.add(dedupeKey);
|
|
450
|
+
facets.push({
|
|
451
|
+
label,
|
|
452
|
+
value,
|
|
453
|
+
section: currentSection
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
const label = this.normalizeProfileLabel(currentSection || 'profile_statement', currentSection);
|
|
459
|
+
const value = normalized;
|
|
460
|
+
const dedupeKey = `${label}::${value}`.toLowerCase();
|
|
461
|
+
if (!seen.has(dedupeKey)) {
|
|
462
|
+
seen.add(dedupeKey);
|
|
463
|
+
facets.push({
|
|
464
|
+
label,
|
|
465
|
+
value,
|
|
466
|
+
section: currentSection
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return facets;
|
|
471
|
+
}
|
|
472
|
+
normalizeProfileLabel(label, section) {
|
|
473
|
+
const token = normalizeLexiconText(`${section || ''} ${label}`).toLowerCase();
|
|
474
|
+
if (/(prefer|preference|偏好|喜欢)/.test(token))
|
|
475
|
+
return 'preference';
|
|
476
|
+
if (/(priority|priorities|重点|关注)/.test(token))
|
|
477
|
+
return 'priority';
|
|
478
|
+
if (/(constraint|constraints|boundary|边界|限制)/.test(token))
|
|
479
|
+
return 'constraint';
|
|
480
|
+
if (/(style|voice|tone|语气|风格)/.test(token))
|
|
481
|
+
return 'style';
|
|
482
|
+
if (/(persona|identity|人格|身份)/.test(token))
|
|
483
|
+
return 'persona';
|
|
484
|
+
if (/(profile|user|画像|用户)/.test(token))
|
|
485
|
+
return 'profile';
|
|
486
|
+
return label || 'profile_statement';
|
|
487
|
+
}
|
|
488
|
+
extractTokens(text) {
|
|
489
|
+
return Array.from(new Set(normalizeLexiconText(text)
|
|
490
|
+
.toLowerCase()
|
|
491
|
+
.split(/[\s,,。!?、::/]+/)
|
|
492
|
+
.map((token) => token.trim())
|
|
493
|
+
.filter((token) => token.length >= 2)));
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* v1.1: Appends vector semantic search results to candidateNeuronIds when the
|
|
497
|
+
* existing FTS5 results are sparse (below vectorFallbackThreshold).
|
|
498
|
+
*
|
|
499
|
+
* @returns true if vector search was triggered and produced results.
|
|
500
|
+
*/
|
|
501
|
+
appendVectorResults(candidateNeuronIds, query, projectId, limit, topicPath) {
|
|
502
|
+
const recallCfg = globalConfig.recall;
|
|
503
|
+
if (!recallCfg.vectorEnabled)
|
|
504
|
+
return false;
|
|
505
|
+
if (!this.deps.vectorSearchFn && !(this.deps.neuronEmbeddingStore && this.deps.embeddingProvider))
|
|
506
|
+
return false;
|
|
507
|
+
if (candidateNeuronIds.length >= recallCfg.vectorFallbackThreshold)
|
|
508
|
+
return false;
|
|
509
|
+
const syncEmbed = this.deps.embeddingProvider?.embedSync;
|
|
510
|
+
const rawVectorIds = this.deps.neuronEmbeddingStore && this.deps.embeddingProvider && syncEmbed
|
|
511
|
+
? this.deps.neuronEmbeddingStore.findNearest(syncEmbed(query), projectId, limit * 4, this.deps.embeddingProvider.modelId).map((item) => item.neuronId)
|
|
512
|
+
: this.deps.vectorSearchFn?.(query, projectId, limit * 4) ?? [];
|
|
513
|
+
return this.appendVectorResultIds(candidateNeuronIds, rawVectorIds, projectId, topicPath, query);
|
|
514
|
+
}
|
|
515
|
+
async appendVectorResultsAsync(candidateNeuronIds, query, projectId, limit, topicPath) {
|
|
516
|
+
const recallCfg = globalConfig.recall;
|
|
517
|
+
if (!recallCfg.vectorEnabled)
|
|
518
|
+
return false;
|
|
519
|
+
if (!this.deps.vectorSearchFn && !(this.deps.neuronEmbeddingStore && this.deps.embeddingProvider))
|
|
520
|
+
return false;
|
|
521
|
+
if (candidateNeuronIds.length >= recallCfg.vectorFallbackThreshold)
|
|
522
|
+
return false;
|
|
523
|
+
try {
|
|
524
|
+
const rawVectorIds = this.deps.neuronEmbeddingStore && this.deps.embeddingProvider
|
|
525
|
+
? this.deps.neuronEmbeddingStore
|
|
526
|
+
.findNearest(await this.deps.embeddingProvider.embed(query), projectId, limit * 4, this.deps.embeddingProvider.modelId)
|
|
527
|
+
.map((item) => item.neuronId)
|
|
528
|
+
: this.deps.vectorSearchFn?.(query, projectId, limit * 4) ?? [];
|
|
529
|
+
return this.appendVectorResultIds(candidateNeuronIds, rawVectorIds, projectId, topicPath, query);
|
|
530
|
+
}
|
|
531
|
+
catch (error) {
|
|
532
|
+
logger.warn('BrainRecall async vector fallback skipped', { error });
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
appendVectorResultIds(candidateNeuronIds, rawVectorIds, projectId, topicPath, query) {
|
|
537
|
+
const vectorIds = this.deps.vectorCandidateFilter
|
|
538
|
+
? this.deps.vectorCandidateFilter.filter(rawVectorIds, { projectId, topicPath, queryTime: Date.now() })
|
|
539
|
+
: rawVectorIds;
|
|
540
|
+
const recallableVectorIds = this.filterRecallableNeuronIds(vectorIds);
|
|
541
|
+
if (recallableVectorIds.length === 0)
|
|
542
|
+
return false;
|
|
543
|
+
const existingSet = new Set(candidateNeuronIds);
|
|
544
|
+
for (const id of recallableVectorIds) {
|
|
545
|
+
if (!existingSet.has(id)) {
|
|
546
|
+
candidateNeuronIds.push(id);
|
|
547
|
+
existingSet.add(id);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return true;
|
|
551
|
+
}
|
|
552
|
+
toRecallableNeurons(neuronIds, limit) {
|
|
553
|
+
return neuronIds
|
|
554
|
+
.map((neuronId) => this.deps.memoryGraph.getNeuron(neuronId))
|
|
555
|
+
.filter((item) => this.isRecallableNeuron(item))
|
|
556
|
+
.slice(0, limit);
|
|
557
|
+
}
|
|
558
|
+
retainRecallableNeuronIds(neuronIds) {
|
|
559
|
+
for (let index = neuronIds.length - 1; index >= 0; index--) {
|
|
560
|
+
if (!this.isRecallableNeuronId(neuronIds[index]))
|
|
561
|
+
neuronIds.splice(index, 1);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
filterRecallableNeuronIds(neuronIds) {
|
|
565
|
+
return neuronIds.filter((id) => this.isRecallableNeuronId(id));
|
|
566
|
+
}
|
|
567
|
+
isRecallableNeuronId(neuronId) {
|
|
568
|
+
const neuron = this.deps.memoryGraph.getNeuron(neuronId);
|
|
569
|
+
return !neuron || this.isRecallableNeuron(neuron);
|
|
570
|
+
}
|
|
571
|
+
isRecallableNeuron(neuron) {
|
|
572
|
+
return isRecallableMemoryEvidence(neuron);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { MemoryGraph } from '../core/MemoryGraph.js';
|
|
2
|
+
export interface TopicRouteResult {
|
|
3
|
+
matchedTopicPath: string | null;
|
|
4
|
+
confidence: number;
|
|
5
|
+
candidateNeuronIds: string[];
|
|
6
|
+
fallbackToGlobal: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface HierarchicalRecallRouterOptions {
|
|
9
|
+
minConfidence?: number;
|
|
10
|
+
maxCandidates?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class HierarchicalRecallRouter {
|
|
13
|
+
private readonly memoryGraph;
|
|
14
|
+
private readonly options;
|
|
15
|
+
constructor(memoryGraph: MemoryGraph, options?: HierarchicalRecallRouterOptions);
|
|
16
|
+
route(query: string, projectId?: string, hintTopicPath?: string): TopicRouteResult;
|
|
17
|
+
scoreTopics(query: string, topics: string[]): Array<{
|
|
18
|
+
path: string;
|
|
19
|
+
score: number;
|
|
20
|
+
}>;
|
|
21
|
+
topicScore(query: string, topicPath: string): number;
|
|
22
|
+
}
|
|
23
|
+
export declare function normalizeTopicPath(topicPath?: string): string | undefined;
|
|
24
|
+
//# sourceMappingURL=HierarchicalRecallRouter.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { lexicalSimilarity } from '../utils/text.js';
|
|
2
|
+
export class HierarchicalRecallRouter {
|
|
3
|
+
memoryGraph;
|
|
4
|
+
options;
|
|
5
|
+
constructor(memoryGraph, options = {}) {
|
|
6
|
+
this.memoryGraph = memoryGraph;
|
|
7
|
+
this.options = options;
|
|
8
|
+
}
|
|
9
|
+
route(query, projectId, hintTopicPath) {
|
|
10
|
+
const maxCandidates = this.options.maxCandidates ?? 500;
|
|
11
|
+
const normalizedHint = normalizeTopicPath(hintTopicPath);
|
|
12
|
+
if (normalizedHint) {
|
|
13
|
+
const ids = this.memoryGraph.getNeuronIdsByTopicPrefix(normalizedHint, projectId).slice(0, maxCandidates);
|
|
14
|
+
return ids.length > 0
|
|
15
|
+
? { matchedTopicPath: normalizedHint, confidence: 1, candidateNeuronIds: ids, fallbackToGlobal: false }
|
|
16
|
+
: { matchedTopicPath: null, confidence: 0, candidateNeuronIds: [], fallbackToGlobal: true };
|
|
17
|
+
}
|
|
18
|
+
if (!query.trim()) {
|
|
19
|
+
return { matchedTopicPath: null, confidence: 0, candidateNeuronIds: [], fallbackToGlobal: true };
|
|
20
|
+
}
|
|
21
|
+
const scored = this.scoreTopics(query, this.memoryGraph.getTopicPaths(projectId));
|
|
22
|
+
const best = scored[0];
|
|
23
|
+
const minConfidence = this.options.minConfidence ?? 0.15;
|
|
24
|
+
if (!best || best.score < minConfidence) {
|
|
25
|
+
return { matchedTopicPath: null, confidence: best?.score ?? 0, candidateNeuronIds: [], fallbackToGlobal: true };
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
matchedTopicPath: best.path,
|
|
29
|
+
confidence: best.score,
|
|
30
|
+
candidateNeuronIds: this.memoryGraph.getNeuronIdsByTopicPrefix(best.path, projectId).slice(0, maxCandidates),
|
|
31
|
+
fallbackToGlobal: false
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
scoreTopics(query, topics) {
|
|
35
|
+
return topics
|
|
36
|
+
.map((path) => ({ path, score: this.topicScore(query, path) }))
|
|
37
|
+
.sort((a, b) => b.score - a.score || a.path.localeCompare(b.path));
|
|
38
|
+
}
|
|
39
|
+
topicScore(query, topicPath) {
|
|
40
|
+
const normalizedQuery = query.toLowerCase();
|
|
41
|
+
const segments = topicPath.split('/').map((segment) => segment.trim()).filter(Boolean);
|
|
42
|
+
const segmentHits = segments.filter((segment) => normalizedQuery.includes(segment.toLowerCase())).length;
|
|
43
|
+
const lexical = lexicalSimilarity(query, topicPath);
|
|
44
|
+
return Math.min(1, lexical * 0.7 + Math.min(segmentHits * 0.2, 0.3));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function normalizeTopicPath(topicPath) {
|
|
48
|
+
if (!topicPath)
|
|
49
|
+
return undefined;
|
|
50
|
+
const normalized = topicPath
|
|
51
|
+
.trim()
|
|
52
|
+
.replace(/\\/g, '/')
|
|
53
|
+
.replace(/\/+/g, '/')
|
|
54
|
+
.replace(/^\/+|\/+$/g, '')
|
|
55
|
+
.split('/')
|
|
56
|
+
.map((segment) => segment.trim())
|
|
57
|
+
.filter(Boolean)
|
|
58
|
+
.slice(0, 5)
|
|
59
|
+
.map((segment) => segment.replace(/[A-Za-z]+/g, (match) => match.toLowerCase()))
|
|
60
|
+
.join('/');
|
|
61
|
+
return normalized || undefined;
|
|
62
|
+
}
|