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,860 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// ============================================
|
|
3
|
+
// 记忆图谱 - SQLite 持久化 + 流式索引恢复
|
|
4
|
+
// ============================================
|
|
5
|
+
import Database from 'bun:sqlite';
|
|
6
|
+
import { createHash } from 'crypto';
|
|
7
|
+
import { IMPORTANCE_STABILITY_MAP } from './ImportanceLevels.js';
|
|
8
|
+
import { ENTITY_TYPE_LEXICON, extractIssueRankingTokensFromText, extractRelativeReferences, normalizeLexiconText } from '../lexicon/coreMemoryLexicon.js';
|
|
9
|
+
import { logger } from '../utils/Logger.js';
|
|
10
|
+
export class MemoryGraph {
|
|
11
|
+
db;
|
|
12
|
+
timeIndex = new Map();
|
|
13
|
+
projectIndex = new Map();
|
|
14
|
+
anchorIndex = new Map();
|
|
15
|
+
topicReclassifiedListeners = new Set();
|
|
16
|
+
constructor(dbPath = ':memory:') {
|
|
17
|
+
try {
|
|
18
|
+
this.db = new Database(dbPath);
|
|
19
|
+
this.initializeSchema();
|
|
20
|
+
this.rebuildIndexes();
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
logger.error('Failed to initialize MemoryGraph:', error);
|
|
24
|
+
throw new Error(`MemoryGraph initialization failed: ${error}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
initializeSchema() {
|
|
28
|
+
this.db.exec(`
|
|
29
|
+
PRAGMA journal_mode = WAL;
|
|
30
|
+
PRAGMA synchronous = NORMAL;
|
|
31
|
+
PRAGMA foreign_keys = ON;
|
|
32
|
+
PRAGMA busy_timeout = 5000;
|
|
33
|
+
|
|
34
|
+
CREATE TABLE IF NOT EXISTS neurons (
|
|
35
|
+
id TEXT PRIMARY KEY,
|
|
36
|
+
content TEXT NOT NULL,
|
|
37
|
+
prev_hash TEXT NOT NULL,
|
|
38
|
+
self_hash TEXT NOT NULL,
|
|
39
|
+
timestamp INTEGER NOT NULL,
|
|
40
|
+
spatial_x REAL NOT NULL,
|
|
41
|
+
spatial_y REAL NOT NULL,
|
|
42
|
+
spatial_z REAL NOT NULL,
|
|
43
|
+
vector_blob BLOB,
|
|
44
|
+
project_id TEXT,
|
|
45
|
+
topic_path TEXT,
|
|
46
|
+
file_id TEXT,
|
|
47
|
+
file_path TEXT,
|
|
48
|
+
type TEXT NOT NULL,
|
|
49
|
+
created_at INTEGER NOT NULL,
|
|
50
|
+
updated_at INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
51
|
+
last_activated INTEGER,
|
|
52
|
+
activation_count INTEGER NOT NULL DEFAULT 0,
|
|
53
|
+
aaak_summary TEXT,
|
|
54
|
+
status TEXT NOT NULL DEFAULT 'active',
|
|
55
|
+
tags TEXT,
|
|
56
|
+
file_size INTEGER,
|
|
57
|
+
mime_type TEXT,
|
|
58
|
+
original_name TEXT,
|
|
59
|
+
blob_path TEXT,
|
|
60
|
+
confidence REAL NOT NULL DEFAULT 1.0,
|
|
61
|
+
source_type TEXT,
|
|
62
|
+
source_event_id TEXT,
|
|
63
|
+
importance_level TEXT NOT NULL DEFAULT 'normal',
|
|
64
|
+
is_pinned INTEGER NOT NULL DEFAULT 0 CHECK (is_pinned IN (0, 1)),
|
|
65
|
+
stability REAL NOT NULL DEFAULT 1.0,
|
|
66
|
+
repetitions INTEGER NOT NULL DEFAULT 0,
|
|
67
|
+
procedural_link_json TEXT,
|
|
68
|
+
community_id TEXT,
|
|
69
|
+
last_reinforced_at INTEGER,
|
|
70
|
+
is_deleted INTEGER NOT NULL DEFAULT 0 CHECK (is_deleted IN (0, 1))
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
CREATE INDEX IF NOT EXISTS idx_neurons_temporal ON neurons(timestamp);
|
|
74
|
+
CREATE INDEX IF NOT EXISTS idx_neurons_project ON neurons(project_id);
|
|
75
|
+
CREATE INDEX IF NOT EXISTS idx_neurons_type_project_created ON neurons(type, project_id, created_at DESC);
|
|
76
|
+
CREATE INDEX IF NOT EXISTS idx_neurons_status ON neurons(status, last_activated DESC);
|
|
77
|
+
CREATE INDEX IF NOT EXISTS idx_neurons_stability ON neurons(stability DESC);
|
|
78
|
+
CREATE INDEX IF NOT EXISTS idx_neurons_repetitions ON neurons(repetitions DESC);
|
|
79
|
+
CREATE INDEX IF NOT EXISTS idx_neurons_not_deleted ON neurons(is_deleted, updated_at DESC);
|
|
80
|
+
|
|
81
|
+
CREATE TABLE IF NOT EXISTS synapses (
|
|
82
|
+
source_id TEXT NOT NULL,
|
|
83
|
+
target_id TEXT NOT NULL,
|
|
84
|
+
type TEXT NOT NULL,
|
|
85
|
+
weight REAL NOT NULL,
|
|
86
|
+
created_at INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
87
|
+
updated_at INTEGER NOT NULL DEFAULT (unixepoch() * 1000),
|
|
88
|
+
PRIMARY KEY (source_id, target_id, type)
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
CREATE INDEX IF NOT EXISTS idx_synapses_source ON synapses(source_id);
|
|
92
|
+
CREATE INDEX IF NOT EXISTS idx_synapses_target ON synapses(target_id);
|
|
93
|
+
|
|
94
|
+
CREATE TABLE IF NOT EXISTS anchors (
|
|
95
|
+
id TEXT PRIMARY KEY,
|
|
96
|
+
neuron_count INTEGER NOT NULL,
|
|
97
|
+
created_at INTEGER NOT NULL,
|
|
98
|
+
prev_anchor_id TEXT,
|
|
99
|
+
summary_hash TEXT NOT NULL,
|
|
100
|
+
project_id TEXT,
|
|
101
|
+
version TEXT NOT NULL
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS neurons_fts USING fts5(
|
|
105
|
+
id UNINDEXED,
|
|
106
|
+
content,
|
|
107
|
+
aaak_summary,
|
|
108
|
+
project_id UNINDEXED,
|
|
109
|
+
file_path UNINDEXED,
|
|
110
|
+
tokenize='unicode61'
|
|
111
|
+
);
|
|
112
|
+
`);
|
|
113
|
+
this.ensureCompatibilityColumns();
|
|
114
|
+
}
|
|
115
|
+
ensureCompatibilityColumns() {
|
|
116
|
+
const columns = this.db.prepare(`PRAGMA table_info(neurons)`).all();
|
|
117
|
+
const names = new Set(columns.map((column) => column.name));
|
|
118
|
+
if (!names.has('topic_path')) {
|
|
119
|
+
this.db.exec(`ALTER TABLE neurons ADD COLUMN topic_path TEXT;`);
|
|
120
|
+
}
|
|
121
|
+
if (!names.has('importance_level')) {
|
|
122
|
+
this.db.exec(`ALTER TABLE neurons ADD COLUMN importance_level TEXT NOT NULL DEFAULT 'normal';`);
|
|
123
|
+
}
|
|
124
|
+
if (!names.has('is_pinned')) {
|
|
125
|
+
this.db.exec(`ALTER TABLE neurons ADD COLUMN is_pinned INTEGER NOT NULL DEFAULT 0 CHECK (is_pinned IN (0, 1));`);
|
|
126
|
+
}
|
|
127
|
+
if (!names.has('procedural_link_json')) {
|
|
128
|
+
this.db.exec(`ALTER TABLE neurons ADD COLUMN procedural_link_json TEXT;`);
|
|
129
|
+
}
|
|
130
|
+
if (!names.has('community_id')) {
|
|
131
|
+
this.db.exec(`ALTER TABLE neurons ADD COLUMN community_id TEXT;`);
|
|
132
|
+
}
|
|
133
|
+
if (!names.has('last_reinforced_at')) {
|
|
134
|
+
this.db.exec(`ALTER TABLE neurons ADD COLUMN last_reinforced_at INTEGER;`);
|
|
135
|
+
}
|
|
136
|
+
this.db.exec(`CREATE INDEX IF NOT EXISTS idx_neurons_topic_path ON neurons(project_id, topic_path);`);
|
|
137
|
+
this.db.exec(`CREATE INDEX IF NOT EXISTS idx_neurons_pinned ON neurons(is_pinned) WHERE is_pinned = 1;`);
|
|
138
|
+
}
|
|
139
|
+
addNeuron(neuron) {
|
|
140
|
+
this.insertNeuron(neuron);
|
|
141
|
+
this.insertIntoFTS(neuron);
|
|
142
|
+
this.updateMemoryIndexes(neuron);
|
|
143
|
+
for (const synapse of neuron.synapses)
|
|
144
|
+
this.addSynapse(neuron.id, synapse);
|
|
145
|
+
}
|
|
146
|
+
addNeuronInTransaction(neuron) {
|
|
147
|
+
this.insertNeuron(neuron);
|
|
148
|
+
this.insertIntoFTS(neuron);
|
|
149
|
+
for (const synapse of neuron.synapses)
|
|
150
|
+
this.addSynapse(neuron.id, synapse);
|
|
151
|
+
}
|
|
152
|
+
insertNeuron(neuron) {
|
|
153
|
+
const vectorBuffer = neuron.coordinates.V.length > 0
|
|
154
|
+
? Buffer.from(new Float32Array(neuron.coordinates.V).buffer)
|
|
155
|
+
: null;
|
|
156
|
+
const importanceLevel = neuron.metadata.importanceLevel || 'normal';
|
|
157
|
+
const isPinned = neuron.metadata.isPinned ?? (importanceLevel !== 'normal' && importanceLevel !== 'low');
|
|
158
|
+
const stability = neuron.metadata.type === 'semantic_consolidation'
|
|
159
|
+
? (neuron.metadata.stability ?? 1)
|
|
160
|
+
: importanceLevel === 'normal'
|
|
161
|
+
? (neuron.metadata.stability ?? IMPORTANCE_STABILITY_MAP.normal)
|
|
162
|
+
: IMPORTANCE_STABILITY_MAP[importanceLevel];
|
|
163
|
+
this.db.prepare(`
|
|
164
|
+
INSERT INTO neurons (
|
|
165
|
+
id, content, prev_hash, self_hash, timestamp, spatial_x, spatial_y, spatial_z,
|
|
166
|
+
vector_blob, project_id, topic_path, file_id, file_path, type, created_at, updated_at,
|
|
167
|
+
last_activated, activation_count, aaak_summary, status, tags, file_size,
|
|
168
|
+
mime_type, original_name, blob_path, confidence, source_type, source_event_id,
|
|
169
|
+
importance_level, is_pinned, stability, repetitions, procedural_link_json, community_id, last_reinforced_at, is_deleted
|
|
170
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
171
|
+
`).run(neuron.id, neuron.content, neuron.prev_hash, neuron.self_hash, neuron.coordinates.T, neuron.coordinates.S[0], neuron.coordinates.S[1], neuron.coordinates.S[2], vectorBuffer, neuron.metadata.projectId || null, neuron.metadata.topicPath || null, neuron.metadata.fileId || null, neuron.metadata.filePath || null, neuron.metadata.type, neuron.metadata.createdAt, neuron.metadata.updatedAt || neuron.metadata.createdAt, neuron.metadata.lastActivated || null, neuron.metadata.activationCount || 0, this.encodeAaakSummary(neuron.metadata) || null, neuron.metadata.status || 'active', neuron.metadata.tags?.join(',') || null, neuron.metadata.fileSize || null, neuron.metadata.mimeType || null, neuron.metadata.originalName || null, neuron.metadata.blobPath || null, neuron.metadata.confidence ?? 1, neuron.metadata.sourceType || null, neuron.metadata.sourceEventId || null, importanceLevel, isPinned ? 1 : 0, stability, neuron.metadata.repetitions ?? 0, neuron.metadata.proceduralLink ? JSON.stringify(neuron.metadata.proceduralLink) : null, neuron.metadata.communityId || null, neuron.metadata.lastReinforcedAt || null, 0);
|
|
172
|
+
}
|
|
173
|
+
insertIntoFTS(neuron) {
|
|
174
|
+
this.db.prepare(`
|
|
175
|
+
INSERT INTO neurons_fts (id, content, aaak_summary, project_id, file_path)
|
|
176
|
+
VALUES (?, ?, ?, ?, ?)
|
|
177
|
+
`).run(neuron.id, neuron.content, neuron.metadata.aaak_summary || null, neuron.metadata.projectId || null, neuron.metadata.filePath || null);
|
|
178
|
+
}
|
|
179
|
+
rebuildIndexes() {
|
|
180
|
+
this.timeIndex.clear();
|
|
181
|
+
this.projectIndex.clear();
|
|
182
|
+
const rows = this.db.prepare(`
|
|
183
|
+
SELECT id, timestamp, project_id
|
|
184
|
+
FROM neurons
|
|
185
|
+
WHERE is_deleted = 0
|
|
186
|
+
`).all();
|
|
187
|
+
for (const row of rows) {
|
|
188
|
+
const dateKey = new Date(row.timestamp).toDateString();
|
|
189
|
+
if (!this.timeIndex.has(dateKey))
|
|
190
|
+
this.timeIndex.set(dateKey, new Set());
|
|
191
|
+
this.timeIndex.get(dateKey).add(row.id);
|
|
192
|
+
if (row.project_id) {
|
|
193
|
+
if (!this.projectIndex.has(row.project_id))
|
|
194
|
+
this.projectIndex.set(row.project_id, new Set());
|
|
195
|
+
this.projectIndex.get(row.project_id).add(row.id);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
updateMemoryIndexes(neuron) {
|
|
200
|
+
const dateKey = new Date(neuron.coordinates.T).toDateString();
|
|
201
|
+
if (!this.timeIndex.has(dateKey))
|
|
202
|
+
this.timeIndex.set(dateKey, new Set());
|
|
203
|
+
this.timeIndex.get(dateKey).add(neuron.id);
|
|
204
|
+
if (neuron.metadata.projectId) {
|
|
205
|
+
if (!this.projectIndex.has(neuron.metadata.projectId))
|
|
206
|
+
this.projectIndex.set(neuron.metadata.projectId, new Set());
|
|
207
|
+
this.projectIndex.get(neuron.metadata.projectId).add(neuron.id);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
addSynapse(sourceId, synapse) {
|
|
211
|
+
this.db.prepare(`
|
|
212
|
+
INSERT OR REPLACE INTO synapses (source_id, target_id, type, weight, updated_at)
|
|
213
|
+
VALUES (?, ?, ?, ?, ?)
|
|
214
|
+
`).run(sourceId, synapse.targetId, synapse.type, synapse.weight, Date.now());
|
|
215
|
+
}
|
|
216
|
+
getNeuron(id) {
|
|
217
|
+
const row = this.db.prepare(`SELECT * FROM neurons WHERE id = ? AND is_deleted = 0`).get(id);
|
|
218
|
+
return row ? this.mapNeuron(row) : null;
|
|
219
|
+
}
|
|
220
|
+
getNeuronIdsByProject(projectId) {
|
|
221
|
+
const ids = this.projectIndex.get(projectId);
|
|
222
|
+
if (ids)
|
|
223
|
+
return Array.from(ids);
|
|
224
|
+
return this.db.prepare(`
|
|
225
|
+
SELECT id FROM neurons
|
|
226
|
+
WHERE project_id = ? AND is_deleted = 0
|
|
227
|
+
ORDER BY created_at DESC
|
|
228
|
+
`).all(projectId).map((row) => row.id);
|
|
229
|
+
}
|
|
230
|
+
getSynapses(sourceId) {
|
|
231
|
+
const rows = this.db.prepare(`SELECT * FROM synapses WHERE source_id = ?`).all(sourceId);
|
|
232
|
+
return rows.map((row) => ({ targetId: row.target_id, type: row.type, weight: row.weight }));
|
|
233
|
+
}
|
|
234
|
+
getAllNeurons() {
|
|
235
|
+
const rows = this.db.prepare(`SELECT * FROM neurons WHERE is_deleted = 0`).all();
|
|
236
|
+
return rows.map((row) => this.mapNeuron(row));
|
|
237
|
+
}
|
|
238
|
+
findNeuronsByType(type, options = {}) {
|
|
239
|
+
const limit = options.limit ?? 10;
|
|
240
|
+
const clauses = ['is_deleted = 0', 'type = ?'];
|
|
241
|
+
const values = [type];
|
|
242
|
+
if (options.projectId) {
|
|
243
|
+
clauses.push('project_id = ?');
|
|
244
|
+
values.push(options.projectId);
|
|
245
|
+
}
|
|
246
|
+
if (options.topicPath) {
|
|
247
|
+
clauses.push(`(
|
|
248
|
+
topic_path = ?
|
|
249
|
+
OR (tags IS NOT NULL AND (',' || tags || ',') LIKE ?)
|
|
250
|
+
)`);
|
|
251
|
+
values.push(options.topicPath, `%,topic:${options.topicPath},%`);
|
|
252
|
+
}
|
|
253
|
+
values.push(limit);
|
|
254
|
+
const rows = this.db.prepare(`
|
|
255
|
+
SELECT *
|
|
256
|
+
FROM neurons
|
|
257
|
+
WHERE ${clauses.join(' AND ')}
|
|
258
|
+
ORDER BY created_at DESC, id DESC
|
|
259
|
+
LIMIT ?
|
|
260
|
+
`).all(...values);
|
|
261
|
+
return rows.map((row) => this.mapNeuron(row));
|
|
262
|
+
}
|
|
263
|
+
listNeuronsByTimeRange(startTime, endTime, projectId) {
|
|
264
|
+
const rows = projectId
|
|
265
|
+
? this.db.prepare(`
|
|
266
|
+
SELECT *
|
|
267
|
+
FROM neurons
|
|
268
|
+
WHERE is_deleted = 0
|
|
269
|
+
AND timestamp >= ?
|
|
270
|
+
AND timestamp < ?
|
|
271
|
+
AND project_id = ?
|
|
272
|
+
ORDER BY timestamp ASC, created_at ASC
|
|
273
|
+
`).all(startTime, endTime, projectId)
|
|
274
|
+
: this.db.prepare(`
|
|
275
|
+
SELECT *
|
|
276
|
+
FROM neurons
|
|
277
|
+
WHERE is_deleted = 0
|
|
278
|
+
AND timestamp >= ?
|
|
279
|
+
AND timestamp < ?
|
|
280
|
+
ORDER BY timestamp ASC, created_at ASC
|
|
281
|
+
`).all(startTime, endTime);
|
|
282
|
+
return rows.map((row) => this.mapNeuron(row));
|
|
283
|
+
}
|
|
284
|
+
mapNeuron(row) {
|
|
285
|
+
const synapses = this.getSynapses(row.id);
|
|
286
|
+
const V = row.vector_blob ? this.decodeVectorBlob(row.vector_blob) : [];
|
|
287
|
+
const parsedAaak = this.decodeAaakSummary(row.aaak_summary || undefined, row.type);
|
|
288
|
+
return {
|
|
289
|
+
id: row.id,
|
|
290
|
+
content: row.content,
|
|
291
|
+
prev_hash: row.prev_hash,
|
|
292
|
+
self_hash: row.self_hash,
|
|
293
|
+
coordinates: {
|
|
294
|
+
T: row.timestamp,
|
|
295
|
+
S: [row.spatial_x, row.spatial_y, row.spatial_z],
|
|
296
|
+
V
|
|
297
|
+
},
|
|
298
|
+
synapses,
|
|
299
|
+
metadata: {
|
|
300
|
+
projectId: row.project_id || undefined,
|
|
301
|
+
topicPath: row.topic_path || undefined,
|
|
302
|
+
fileId: row.file_id || undefined,
|
|
303
|
+
filePath: row.file_path || undefined,
|
|
304
|
+
type: row.type,
|
|
305
|
+
createdAt: row.created_at,
|
|
306
|
+
updatedAt: row.updated_at,
|
|
307
|
+
lastActivated: row.last_activated || undefined,
|
|
308
|
+
activationCount: row.activation_count,
|
|
309
|
+
aaak_summary: parsedAaak.aaakSummary,
|
|
310
|
+
status: row.status,
|
|
311
|
+
tags: row.tags ? String(row.tags).split(',').filter(Boolean) : undefined,
|
|
312
|
+
fileSize: row.file_size || undefined,
|
|
313
|
+
mimeType: row.mime_type || undefined,
|
|
314
|
+
originalName: row.original_name || undefined,
|
|
315
|
+
blobPath: row.blob_path || undefined,
|
|
316
|
+
confidence: row.confidence ?? 1,
|
|
317
|
+
sourceType: row.source_type || undefined,
|
|
318
|
+
sourceEventId: row.source_event_id || undefined,
|
|
319
|
+
importanceLevel: row.importance_level || 'normal',
|
|
320
|
+
isPinned: Boolean(row.is_pinned),
|
|
321
|
+
stability: row.stability ?? 1,
|
|
322
|
+
repetitions: row.repetitions ?? 0,
|
|
323
|
+
skillMeta: parsedAaak.skillMeta,
|
|
324
|
+
proceduralLink: this.decodeProceduralLink(row.procedural_link_json || undefined),
|
|
325
|
+
communityId: row.community_id || undefined,
|
|
326
|
+
lastReinforcedAt: row.last_reinforced_at || undefined
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
encodeAaakSummary(metadata) {
|
|
331
|
+
if (metadata.skillMeta) {
|
|
332
|
+
return `skill_meta:${JSON.stringify(metadata.skillMeta)}`;
|
|
333
|
+
}
|
|
334
|
+
return metadata.aaak_summary || undefined;
|
|
335
|
+
}
|
|
336
|
+
decodeAaakSummary(value, type) {
|
|
337
|
+
if (type === 'skill' && value?.startsWith('skill_meta:')) {
|
|
338
|
+
try {
|
|
339
|
+
const skillMeta = JSON.parse(value.slice('skill_meta:'.length));
|
|
340
|
+
return { aaakSummary: skillMeta?.description, skillMeta };
|
|
341
|
+
}
|
|
342
|
+
catch {
|
|
343
|
+
return { aaakSummary: value };
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return { aaakSummary: value || undefined };
|
|
347
|
+
}
|
|
348
|
+
decodeProceduralLink(value) {
|
|
349
|
+
if (!value)
|
|
350
|
+
return undefined;
|
|
351
|
+
try {
|
|
352
|
+
const parsed = JSON.parse(value);
|
|
353
|
+
return parsed?.skillId && parsed?.linkType ? parsed : undefined;
|
|
354
|
+
}
|
|
355
|
+
catch {
|
|
356
|
+
return undefined;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
decodeVectorBlob(blob) {
|
|
360
|
+
if (blob instanceof ArrayBuffer)
|
|
361
|
+
return Array.from(new Float32Array(blob));
|
|
362
|
+
const bytes = blob instanceof Uint8Array ? blob : new Uint8Array(blob.buffer, blob.byteOffset, blob.byteLength);
|
|
363
|
+
const arrayBuffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
364
|
+
return Array.from(new Float32Array(arrayBuffer));
|
|
365
|
+
}
|
|
366
|
+
createAnchor(neuronIds, projectId) {
|
|
367
|
+
const anchor = {
|
|
368
|
+
id: `anchor-${Date.now()}`,
|
|
369
|
+
neuronCount: neuronIds.length,
|
|
370
|
+
createdAt: Date.now(),
|
|
371
|
+
summaryHash: this.computeAnchorSummary(neuronIds, projectId),
|
|
372
|
+
metadata: { projectId, version: '0.3.0' }
|
|
373
|
+
};
|
|
374
|
+
this.db.prepare(`
|
|
375
|
+
INSERT INTO anchors (id, neuron_count, created_at, prev_anchor_id, summary_hash, project_id, version)
|
|
376
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
377
|
+
`).run(anchor.id, anchor.neuronCount, anchor.createdAt, anchor.prevAnchorId || null, anchor.summaryHash, anchor.metadata.projectId || null, anchor.metadata.version);
|
|
378
|
+
this.anchorIndex.set(anchor.id, anchor);
|
|
379
|
+
return anchor;
|
|
380
|
+
}
|
|
381
|
+
computeAnchorSummary(neuronIds, projectId) {
|
|
382
|
+
return createHash('sha256')
|
|
383
|
+
.update(JSON.stringify({ neuronIds: [...neuronIds].sort(), projectId, timestamp: Date.now() }))
|
|
384
|
+
.digest('hex');
|
|
385
|
+
}
|
|
386
|
+
getLatestAnchor(projectId) {
|
|
387
|
+
const query = projectId
|
|
388
|
+
? `SELECT * FROM anchors WHERE project_id = ? ORDER BY created_at DESC LIMIT 1`
|
|
389
|
+
: `SELECT * FROM anchors ORDER BY created_at DESC LIMIT 1`;
|
|
390
|
+
const row = projectId ? this.db.prepare(query).get(projectId) : this.db.prepare(query).get();
|
|
391
|
+
if (!row)
|
|
392
|
+
return null;
|
|
393
|
+
return {
|
|
394
|
+
id: row.id,
|
|
395
|
+
neuronCount: row.neuron_count,
|
|
396
|
+
createdAt: row.created_at,
|
|
397
|
+
prevAnchorId: row.prev_anchor_id || undefined,
|
|
398
|
+
summaryHash: row.summary_hash,
|
|
399
|
+
metadata: { projectId: row.project_id || undefined, version: row.version }
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
getLatestNeuronSelfHash(projectId) {
|
|
403
|
+
const sql = projectId
|
|
404
|
+
? `SELECT self_hash FROM neurons WHERE project_id = ? ORDER BY created_at DESC, id DESC LIMIT 1`
|
|
405
|
+
: `SELECT self_hash FROM neurons ORDER BY created_at DESC, id DESC LIMIT 1`;
|
|
406
|
+
const row = projectId
|
|
407
|
+
? this.db.prepare(sql).get(projectId)
|
|
408
|
+
: this.db.prepare(sql).get();
|
|
409
|
+
return row?.self_hash || null;
|
|
410
|
+
}
|
|
411
|
+
fullTextSearch(query, projectId, limit = 10) {
|
|
412
|
+
const sanitizedQuery = this.toFTSQuery(query);
|
|
413
|
+
const fallbackTokens = this.extractFallbackSearchTokens(query);
|
|
414
|
+
if (!sanitizedQuery)
|
|
415
|
+
return this.fallbackTextSearch(fallbackTokens, projectId, limit);
|
|
416
|
+
let sql = `SELECT id FROM neurons_fts WHERE neurons_fts MATCH ?`;
|
|
417
|
+
const params = [sanitizedQuery];
|
|
418
|
+
if (projectId) {
|
|
419
|
+
sql += ` AND project_id = ?`;
|
|
420
|
+
params.push(projectId);
|
|
421
|
+
}
|
|
422
|
+
sql += ` LIMIT ?`;
|
|
423
|
+
params.push(limit);
|
|
424
|
+
const ids = this.db.prepare(sql).all(...params).map((row) => row.id);
|
|
425
|
+
if (ids.length > 0 || fallbackTokens.length === 0)
|
|
426
|
+
return ids;
|
|
427
|
+
return this.fallbackTextSearch(fallbackTokens, projectId, limit);
|
|
428
|
+
}
|
|
429
|
+
toFTSQuery(query) {
|
|
430
|
+
const tokens = normalizeLexiconText(query)
|
|
431
|
+
.toLowerCase()
|
|
432
|
+
.split(/[\s,,。!?、::??!!/]+/)
|
|
433
|
+
.map((token) => token.replace(/[^\p{L}\p{N}_\-.]/gu, '').trim())
|
|
434
|
+
.filter((token) => token.length >= 2);
|
|
435
|
+
if (tokens.length === 0)
|
|
436
|
+
return '';
|
|
437
|
+
return tokens.map((token) => `"${token}"`).join(' OR ');
|
|
438
|
+
}
|
|
439
|
+
extractFallbackSearchTokens(query) {
|
|
440
|
+
const normalized = normalizeLexiconText(query).toLowerCase();
|
|
441
|
+
const splitTokens = normalized
|
|
442
|
+
.split(/[\s,,。!?、::??!!/]+/)
|
|
443
|
+
.map((token) => token.replace(/[^\p{L}\p{N}_\-.]/gu, '').trim())
|
|
444
|
+
.filter((token) => token.length >= 2);
|
|
445
|
+
const lexiconTokens = Object.values(ENTITY_TYPE_LEXICON)
|
|
446
|
+
.flat()
|
|
447
|
+
.filter((token) => normalized.includes(token.toLowerCase()));
|
|
448
|
+
return Array.from(new Set([
|
|
449
|
+
...splitTokens,
|
|
450
|
+
...extractRelativeReferences(query).map((token) => normalizeLexiconText(token).toLowerCase()),
|
|
451
|
+
...extractIssueRankingTokensFromText(query),
|
|
452
|
+
...lexiconTokens.map((token) => token.toLowerCase())
|
|
453
|
+
]));
|
|
454
|
+
}
|
|
455
|
+
fallbackTextSearch(tokens, projectId, limit) {
|
|
456
|
+
if (tokens.length === 0)
|
|
457
|
+
return [];
|
|
458
|
+
const rows = projectId
|
|
459
|
+
? this.db.prepare(`
|
|
460
|
+
SELECT id, content, aaak_summary
|
|
461
|
+
FROM neurons
|
|
462
|
+
WHERE is_deleted = 0 AND project_id = ?
|
|
463
|
+
ORDER BY created_at DESC
|
|
464
|
+
LIMIT 200
|
|
465
|
+
`).all(projectId)
|
|
466
|
+
: this.db.prepare(`
|
|
467
|
+
SELECT id, content, aaak_summary
|
|
468
|
+
FROM neurons
|
|
469
|
+
WHERE is_deleted = 0
|
|
470
|
+
ORDER BY created_at DESC
|
|
471
|
+
LIMIT 200
|
|
472
|
+
`).all();
|
|
473
|
+
return rows
|
|
474
|
+
.map((row) => {
|
|
475
|
+
const haystack = normalizeLexiconText(`${row.content} ${row.aaak_summary || ''}`).toLowerCase();
|
|
476
|
+
const score = tokens.filter((token) => haystack.includes(token)).length;
|
|
477
|
+
return { id: row.id, score };
|
|
478
|
+
})
|
|
479
|
+
.filter((row) => row.score > 0)
|
|
480
|
+
.sort((a, b) => b.score - a.score)
|
|
481
|
+
.slice(0, limit)
|
|
482
|
+
.map((row) => row.id);
|
|
483
|
+
}
|
|
484
|
+
transaction(fn) {
|
|
485
|
+
this.db.transaction(fn)();
|
|
486
|
+
}
|
|
487
|
+
close() {
|
|
488
|
+
try {
|
|
489
|
+
this.db.close();
|
|
490
|
+
}
|
|
491
|
+
catch (error) {
|
|
492
|
+
logger.error('Failed to close database:', error);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
getStats() {
|
|
496
|
+
return {
|
|
497
|
+
neuronCount: this.db.prepare(`SELECT COUNT(*) AS count FROM neurons WHERE is_deleted = 0`).get().count,
|
|
498
|
+
synapseCount: this.db.prepare(`SELECT COUNT(*) AS count FROM synapses`).get().count,
|
|
499
|
+
anchorCount: this.db.prepare(`SELECT COUNT(*) AS count FROM anchors`).get().count
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
findSimilarNeurons(vector, topK) {
|
|
503
|
+
const results = [];
|
|
504
|
+
for (const page of this.iterateNeuronVectors(500, { includeStatuses: ['active'], onlyNotDeleted: true })) {
|
|
505
|
+
for (const neuron of page) {
|
|
506
|
+
if (neuron.vector.length !== vector.length)
|
|
507
|
+
continue;
|
|
508
|
+
const score = this.cosineSimilarity(vector, neuron.vector);
|
|
509
|
+
if (score > 0.5)
|
|
510
|
+
results.push({ id: neuron.id, score });
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
return results.sort((a, b) => b.score - a.score).slice(0, topK);
|
|
514
|
+
}
|
|
515
|
+
cosineSimilarity(a, b) {
|
|
516
|
+
const dotProduct = a.reduce((sum, value, index) => sum + value * (b[index] || 0), 0);
|
|
517
|
+
const magnitudeA = Math.sqrt(a.reduce((sum, value) => sum + value * value, 0));
|
|
518
|
+
const magnitudeB = Math.sqrt(b.reduce((sum, value) => sum + value * value, 0));
|
|
519
|
+
if (magnitudeA === 0 || magnitudeB === 0)
|
|
520
|
+
return 0;
|
|
521
|
+
return dotProduct / (magnitudeA * magnitudeB);
|
|
522
|
+
}
|
|
523
|
+
updateNeuronStatus(neuronId, status) {
|
|
524
|
+
this.db.prepare(`
|
|
525
|
+
UPDATE neurons
|
|
526
|
+
SET status = ?, updated_at = ?
|
|
527
|
+
WHERE id = ?
|
|
528
|
+
`).run(status, Date.now(), neuronId);
|
|
529
|
+
}
|
|
530
|
+
updateNeuronMetadata(neuronId, metadata) {
|
|
531
|
+
const updates = [];
|
|
532
|
+
const values = [];
|
|
533
|
+
const previousNeuron = metadata.topicPath !== undefined ? this.getNeuron(neuronId) : null;
|
|
534
|
+
if (metadata.projectId !== undefined) {
|
|
535
|
+
updates.push('project_id = ?');
|
|
536
|
+
values.push(metadata.projectId || null);
|
|
537
|
+
}
|
|
538
|
+
if (metadata.topicPath !== undefined) {
|
|
539
|
+
updates.push('topic_path = ?');
|
|
540
|
+
values.push(metadata.topicPath || null);
|
|
541
|
+
}
|
|
542
|
+
if (metadata.fileId !== undefined) {
|
|
543
|
+
updates.push('file_id = ?');
|
|
544
|
+
values.push(metadata.fileId || null);
|
|
545
|
+
}
|
|
546
|
+
if (metadata.filePath !== undefined) {
|
|
547
|
+
updates.push('file_path = ?');
|
|
548
|
+
values.push(metadata.filePath || null);
|
|
549
|
+
}
|
|
550
|
+
if (metadata.lastActivated !== undefined) {
|
|
551
|
+
updates.push('last_activated = ?');
|
|
552
|
+
values.push(metadata.lastActivated || null);
|
|
553
|
+
}
|
|
554
|
+
if (metadata.activationCount !== undefined) {
|
|
555
|
+
updates.push('activation_count = ?');
|
|
556
|
+
values.push(metadata.activationCount);
|
|
557
|
+
}
|
|
558
|
+
if (metadata.aaak_summary !== undefined || metadata.skillMeta !== undefined) {
|
|
559
|
+
updates.push('aaak_summary = ?');
|
|
560
|
+
values.push(this.encodeAaakSummary(metadata) || null);
|
|
561
|
+
}
|
|
562
|
+
if (metadata.status !== undefined) {
|
|
563
|
+
updates.push('status = ?');
|
|
564
|
+
values.push(metadata.status);
|
|
565
|
+
}
|
|
566
|
+
if (metadata.tags !== undefined) {
|
|
567
|
+
updates.push('tags = ?');
|
|
568
|
+
values.push(metadata.tags ? metadata.tags.join(',') : null);
|
|
569
|
+
}
|
|
570
|
+
if (metadata.fileSize !== undefined) {
|
|
571
|
+
updates.push('file_size = ?');
|
|
572
|
+
values.push(metadata.fileSize || null);
|
|
573
|
+
}
|
|
574
|
+
if (metadata.mimeType !== undefined) {
|
|
575
|
+
updates.push('mime_type = ?');
|
|
576
|
+
values.push(metadata.mimeType || null);
|
|
577
|
+
}
|
|
578
|
+
if (metadata.originalName !== undefined) {
|
|
579
|
+
updates.push('original_name = ?');
|
|
580
|
+
values.push(metadata.originalName || null);
|
|
581
|
+
}
|
|
582
|
+
if (metadata.blobPath !== undefined) {
|
|
583
|
+
updates.push('blob_path = ?');
|
|
584
|
+
values.push(metadata.blobPath || null);
|
|
585
|
+
}
|
|
586
|
+
if (metadata.confidence !== undefined) {
|
|
587
|
+
updates.push('confidence = ?');
|
|
588
|
+
values.push(metadata.confidence);
|
|
589
|
+
}
|
|
590
|
+
if (metadata.sourceType !== undefined) {
|
|
591
|
+
updates.push('source_type = ?');
|
|
592
|
+
values.push(metadata.sourceType || null);
|
|
593
|
+
}
|
|
594
|
+
if (metadata.sourceEventId !== undefined) {
|
|
595
|
+
updates.push('source_event_id = ?');
|
|
596
|
+
values.push(metadata.sourceEventId || null);
|
|
597
|
+
}
|
|
598
|
+
if (metadata.importanceLevel !== undefined) {
|
|
599
|
+
updates.push('importance_level = ?');
|
|
600
|
+
values.push(metadata.importanceLevel);
|
|
601
|
+
}
|
|
602
|
+
if (metadata.isPinned !== undefined) {
|
|
603
|
+
updates.push('is_pinned = ?');
|
|
604
|
+
values.push(metadata.isPinned ? 1 : 0);
|
|
605
|
+
}
|
|
606
|
+
if (metadata.stability !== undefined) {
|
|
607
|
+
updates.push('stability = ?');
|
|
608
|
+
values.push(metadata.stability);
|
|
609
|
+
}
|
|
610
|
+
if (metadata.repetitions !== undefined) {
|
|
611
|
+
updates.push('repetitions = ?');
|
|
612
|
+
values.push(metadata.repetitions);
|
|
613
|
+
}
|
|
614
|
+
if (metadata.proceduralLink !== undefined) {
|
|
615
|
+
updates.push('procedural_link_json = ?');
|
|
616
|
+
values.push(metadata.proceduralLink ? JSON.stringify(metadata.proceduralLink) : null);
|
|
617
|
+
}
|
|
618
|
+
if (metadata.communityId !== undefined) {
|
|
619
|
+
updates.push('community_id = ?');
|
|
620
|
+
values.push(metadata.communityId || null);
|
|
621
|
+
}
|
|
622
|
+
if (metadata.lastReinforcedAt !== undefined) {
|
|
623
|
+
updates.push('last_reinforced_at = ?');
|
|
624
|
+
values.push(metadata.lastReinforcedAt || null);
|
|
625
|
+
}
|
|
626
|
+
if (metadata.updatedAt !== undefined) {
|
|
627
|
+
updates.push('updated_at = ?');
|
|
628
|
+
values.push(metadata.updatedAt);
|
|
629
|
+
}
|
|
630
|
+
if (updates.length === 0)
|
|
631
|
+
return;
|
|
632
|
+
if (metadata.updatedAt === undefined) {
|
|
633
|
+
updates.push('updated_at = ?');
|
|
634
|
+
values.push(Date.now());
|
|
635
|
+
}
|
|
636
|
+
values.push(neuronId);
|
|
637
|
+
this.db.prepare(`UPDATE neurons SET ${updates.join(', ')} WHERE id = ?`).run(...values);
|
|
638
|
+
if (metadata.topicPath !== undefined && previousNeuron) {
|
|
639
|
+
const updatedNeuron = this.getNeuron(neuronId);
|
|
640
|
+
const from = previousNeuron.metadata.topicPath;
|
|
641
|
+
const to = updatedNeuron?.metadata.topicPath;
|
|
642
|
+
if (from !== to) {
|
|
643
|
+
const observation = {
|
|
644
|
+
type: 'TopicReclassified',
|
|
645
|
+
neuronId,
|
|
646
|
+
projectId: updatedNeuron?.metadata.projectId ?? previousNeuron.metadata.projectId,
|
|
647
|
+
from,
|
|
648
|
+
to,
|
|
649
|
+
content: updatedNeuron?.content ?? previousNeuron.content,
|
|
650
|
+
timestamp: Date.now()
|
|
651
|
+
};
|
|
652
|
+
for (const listener of this.topicReclassifiedListeners) {
|
|
653
|
+
listener(observation);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
onTopicReclassified(listener) {
|
|
659
|
+
this.topicReclassifiedListeners.add(listener);
|
|
660
|
+
return () => this.topicReclassifiedListeners.delete(listener);
|
|
661
|
+
}
|
|
662
|
+
getTopicPaths(projectId) {
|
|
663
|
+
const rows = projectId
|
|
664
|
+
? this.db.prepare(`
|
|
665
|
+
SELECT topic_path, COUNT(*) AS count
|
|
666
|
+
FROM neurons
|
|
667
|
+
WHERE is_deleted = 0 AND project_id = ? AND topic_path IS NOT NULL AND topic_path <> ''
|
|
668
|
+
GROUP BY topic_path
|
|
669
|
+
ORDER BY count DESC, topic_path ASC
|
|
670
|
+
`).all(projectId)
|
|
671
|
+
: this.db.prepare(`
|
|
672
|
+
SELECT topic_path, COUNT(*) AS count
|
|
673
|
+
FROM neurons
|
|
674
|
+
WHERE is_deleted = 0 AND topic_path IS NOT NULL AND topic_path <> ''
|
|
675
|
+
GROUP BY topic_path
|
|
676
|
+
ORDER BY count DESC, topic_path ASC
|
|
677
|
+
`).all();
|
|
678
|
+
return rows.map((row) => row.topic_path);
|
|
679
|
+
}
|
|
680
|
+
getNeuronIdsByTopicPrefix(prefix, projectId) {
|
|
681
|
+
const normalized = prefix.replace(/^\/+|\/+$/g, '');
|
|
682
|
+
if (!normalized)
|
|
683
|
+
return [];
|
|
684
|
+
const likePrefix = `${normalized}/%`;
|
|
685
|
+
const rows = projectId
|
|
686
|
+
? this.db.prepare(`
|
|
687
|
+
SELECT id
|
|
688
|
+
FROM neurons
|
|
689
|
+
WHERE is_deleted = 0
|
|
690
|
+
AND project_id = ?
|
|
691
|
+
AND (topic_path = ? OR topic_path LIKE ?)
|
|
692
|
+
ORDER BY created_at DESC, id DESC
|
|
693
|
+
`).all(projectId, normalized, likePrefix)
|
|
694
|
+
: this.db.prepare(`
|
|
695
|
+
SELECT id
|
|
696
|
+
FROM neurons
|
|
697
|
+
WHERE is_deleted = 0
|
|
698
|
+
AND (topic_path = ? OR topic_path LIKE ?)
|
|
699
|
+
ORDER BY created_at DESC, id DESC
|
|
700
|
+
`).all(normalized, likePrefix);
|
|
701
|
+
return rows.map((row) => row.id);
|
|
702
|
+
}
|
|
703
|
+
buildTopicTree(projectId) {
|
|
704
|
+
return this.getTopicPaths(projectId).map((path) => ({
|
|
705
|
+
path,
|
|
706
|
+
segments: path.split('/').filter(Boolean),
|
|
707
|
+
neuronCount: this.getNeuronIdsByTopicPrefix(path, projectId).length,
|
|
708
|
+
projectId
|
|
709
|
+
}));
|
|
710
|
+
}
|
|
711
|
+
updateNeuronContent(neuronId, content) {
|
|
712
|
+
const now = Date.now();
|
|
713
|
+
this.db.prepare(`
|
|
714
|
+
UPDATE neurons
|
|
715
|
+
SET content = ?, updated_at = ?
|
|
716
|
+
WHERE id = ? AND is_deleted = 0
|
|
717
|
+
`).run(content, now, neuronId);
|
|
718
|
+
this.db.prepare(`DELETE FROM neurons_fts WHERE id = ?`).run(neuronId);
|
|
719
|
+
const neuron = this.getNeuron(neuronId);
|
|
720
|
+
if (neuron)
|
|
721
|
+
this.insertIntoFTS(neuron);
|
|
722
|
+
}
|
|
723
|
+
updateNeuronImportance(neuronId, importanceLevel, isPinned = importanceLevel !== 'normal' && importanceLevel !== 'low') {
|
|
724
|
+
this.updateNeuronMetadata(neuronId, {
|
|
725
|
+
importanceLevel,
|
|
726
|
+
isPinned,
|
|
727
|
+
stability: IMPORTANCE_STABILITY_MAP[importanceLevel],
|
|
728
|
+
status: isPinned ? 'active' : undefined
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
listPinnedNeurons(options = 20) {
|
|
732
|
+
const limit = typeof options === 'number' ? options : options.limit ?? 20;
|
|
733
|
+
const projectId = typeof options === 'number' ? undefined : options.projectId;
|
|
734
|
+
const rows = projectId
|
|
735
|
+
? this.db.prepare(`
|
|
736
|
+
SELECT *
|
|
737
|
+
FROM neurons
|
|
738
|
+
WHERE is_deleted = 0 AND is_pinned = 1 AND project_id = ?
|
|
739
|
+
ORDER BY created_at DESC, id DESC
|
|
740
|
+
LIMIT ?
|
|
741
|
+
`).all(projectId, limit)
|
|
742
|
+
: this.db.prepare(`
|
|
743
|
+
SELECT *
|
|
744
|
+
FROM neurons
|
|
745
|
+
WHERE is_deleted = 0 AND is_pinned = 1
|
|
746
|
+
ORDER BY created_at DESC, id DESC
|
|
747
|
+
LIMIT ?
|
|
748
|
+
`).all(limit);
|
|
749
|
+
return rows.map((row) => this.mapNeuron(row));
|
|
750
|
+
}
|
|
751
|
+
getRecentNeurons(options = {}) {
|
|
752
|
+
const limit = options.limit ?? 20;
|
|
753
|
+
const since = Date.now() - (options.sinceMs ?? 5 * 60 * 1000);
|
|
754
|
+
const rows = options.projectId
|
|
755
|
+
? this.db.prepare(`
|
|
756
|
+
SELECT *
|
|
757
|
+
FROM neurons
|
|
758
|
+
WHERE is_deleted = 0 AND project_id = ? AND created_at >= ?
|
|
759
|
+
ORDER BY created_at DESC, id DESC
|
|
760
|
+
LIMIT ?
|
|
761
|
+
`).all(options.projectId, since, limit)
|
|
762
|
+
: this.db.prepare(`
|
|
763
|
+
SELECT *
|
|
764
|
+
FROM neurons
|
|
765
|
+
WHERE is_deleted = 0 AND created_at >= ?
|
|
766
|
+
ORDER BY created_at DESC, id DESC
|
|
767
|
+
LIMIT ?
|
|
768
|
+
`).all(since, limit);
|
|
769
|
+
return rows.map((row) => this.mapNeuron(row));
|
|
770
|
+
}
|
|
771
|
+
hasSynapse(sourceId, targetId) {
|
|
772
|
+
const row = this.db.prepare(`
|
|
773
|
+
SELECT 1 FROM synapses WHERE source_id = ? AND target_id = ? LIMIT 1
|
|
774
|
+
`).get(sourceId, targetId);
|
|
775
|
+
return row !== null && row !== undefined;
|
|
776
|
+
}
|
|
777
|
+
getNeuronEnergy(neuronId) {
|
|
778
|
+
return this.getSynapses(neuronId).reduce((sum, synapse) => sum + synapse.weight, 0);
|
|
779
|
+
}
|
|
780
|
+
getOrphanNeuronIds(limit) {
|
|
781
|
+
const rows = this.db.prepare(`
|
|
782
|
+
SELECT n.id
|
|
783
|
+
FROM neurons n
|
|
784
|
+
LEFT JOIN synapses s ON n.id = s.source_id
|
|
785
|
+
WHERE s.source_id IS NULL AND n.status = 'active' AND n.is_deleted = 0
|
|
786
|
+
ORDER BY COALESCE(n.last_activated, n.created_at) ASC
|
|
787
|
+
LIMIT ?
|
|
788
|
+
`).all(limit);
|
|
789
|
+
return rows.map((row) => row.id);
|
|
790
|
+
}
|
|
791
|
+
getNeuronIdsForReinforcement(limit) {
|
|
792
|
+
const rows = this.db.prepare(`
|
|
793
|
+
SELECT id
|
|
794
|
+
FROM neurons
|
|
795
|
+
WHERE activation_count >= 10 AND status = 'active' AND is_deleted = 0
|
|
796
|
+
ORDER BY COALESCE(last_activated, created_at) ASC
|
|
797
|
+
LIMIT ?
|
|
798
|
+
`).all(limit);
|
|
799
|
+
return rows.map((row) => row.id);
|
|
800
|
+
}
|
|
801
|
+
getNeuronIdsForTransition(limit) {
|
|
802
|
+
const rows = this.db.prepare(`
|
|
803
|
+
SELECT id
|
|
804
|
+
FROM neurons
|
|
805
|
+
WHERE (status IN ('active', 'cold') OR is_pinned = 1) AND is_deleted = 0
|
|
806
|
+
ORDER BY COALESCE(last_activated, created_at) ASC
|
|
807
|
+
LIMIT ?
|
|
808
|
+
`).all(limit);
|
|
809
|
+
return rows.map((row) => row.id);
|
|
810
|
+
}
|
|
811
|
+
getArchivedFileNeurons() {
|
|
812
|
+
const rows = this.db.prepare(`
|
|
813
|
+
SELECT * FROM neurons
|
|
814
|
+
WHERE type = 'file' AND status = 'archived' AND is_deleted = 0
|
|
815
|
+
`).all();
|
|
816
|
+
return rows.map((row) => this.mapNeuron(row));
|
|
817
|
+
}
|
|
818
|
+
iterateNeuronVectors(pageSize, options = {}) {
|
|
819
|
+
const includeStatuses = options.includeStatuses ?? ['active', 'cold'];
|
|
820
|
+
const onlyNotDeleted = options.onlyNotDeleted ?? true;
|
|
821
|
+
const statusPlaceholders = includeStatuses.map(() => '?').join(', ');
|
|
822
|
+
const sql = `
|
|
823
|
+
SELECT id, vector_blob
|
|
824
|
+
FROM neurons
|
|
825
|
+
WHERE id > ?
|
|
826
|
+
AND vector_blob IS NOT NULL
|
|
827
|
+
${onlyNotDeleted ? 'AND is_deleted = 0' : ''}
|
|
828
|
+
${options.projectId ? 'AND project_id = ?' : ''}
|
|
829
|
+
AND status IN (${statusPlaceholders})
|
|
830
|
+
ORDER BY id ASC
|
|
831
|
+
LIMIT ?
|
|
832
|
+
`;
|
|
833
|
+
const stmt = this.db.prepare(sql);
|
|
834
|
+
let lastId = '';
|
|
835
|
+
const self = this;
|
|
836
|
+
return (function* iterate() {
|
|
837
|
+
while (true) {
|
|
838
|
+
const params = [lastId];
|
|
839
|
+
if (options.projectId)
|
|
840
|
+
params.push(options.projectId);
|
|
841
|
+
params.push(...includeStatuses);
|
|
842
|
+
params.push(pageSize);
|
|
843
|
+
const rows = stmt.all(...params);
|
|
844
|
+
if (rows.length === 0)
|
|
845
|
+
return;
|
|
846
|
+
const page = rows.map((row) => ({
|
|
847
|
+
id: row.id,
|
|
848
|
+
vector: self.decodeVectorBlob(row.vector_blob)
|
|
849
|
+
}));
|
|
850
|
+
yield page;
|
|
851
|
+
lastId = rows[rows.length - 1].id;
|
|
852
|
+
}
|
|
853
|
+
})();
|
|
854
|
+
}
|
|
855
|
+
async forEachNeuronVectorPage(pageSize, onPage, options) {
|
|
856
|
+
for (const page of this.iterateNeuronVectors(pageSize, options)) {
|
|
857
|
+
await onPage(page);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
}
|