surreal-memory 2.0.0__py3-none-any.whl
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.
- surreal_memory/__init__.py +48 -0
- surreal_memory/cli/__init__.py +15 -0
- surreal_memory/cli/__main__.py +6 -0
- surreal_memory/cli/_helpers.py +192 -0
- surreal_memory/cli/commands/__init__.py +1 -0
- surreal_memory/cli/commands/brain.py +612 -0
- surreal_memory/cli/commands/codebase.py +107 -0
- surreal_memory/cli/commands/config_cmd.py +134 -0
- surreal_memory/cli/commands/habits.py +305 -0
- surreal_memory/cli/commands/info.py +490 -0
- surreal_memory/cli/commands/listing.py +427 -0
- surreal_memory/cli/commands/memory.py +590 -0
- surreal_memory/cli/commands/project.py +427 -0
- surreal_memory/cli/commands/shared.py +376 -0
- surreal_memory/cli/commands/shortcuts.py +401 -0
- surreal_memory/cli/commands/storage.py +72 -0
- surreal_memory/cli/commands/telegram.py +127 -0
- surreal_memory/cli/commands/tools.py +1102 -0
- surreal_memory/cli/commands/train.py +117 -0
- surreal_memory/cli/commands/update.py +224 -0
- surreal_memory/cli/commands/version.py +280 -0
- surreal_memory/cli/commands/watch.py +125 -0
- surreal_memory/cli/config.py +231 -0
- surreal_memory/cli/doctor.py +1022 -0
- surreal_memory/cli/embedding_setup.py +199 -0
- surreal_memory/cli/full_setup.py +425 -0
- surreal_memory/cli/graph_export.py +455 -0
- surreal_memory/cli/ide_rules.py +243 -0
- surreal_memory/cli/main.py +149 -0
- surreal_memory/cli/markdown_export.py +249 -0
- surreal_memory/cli/setup.py +426 -0
- surreal_memory/cli/storage.py +178 -0
- surreal_memory/cli/tui.py +471 -0
- surreal_memory/cli/update_check.py +181 -0
- surreal_memory/cli/wizard.py +258 -0
- surreal_memory/config_presets.py +175 -0
- surreal_memory/core/__init__.py +57 -0
- surreal_memory/core/action_event.py +39 -0
- surreal_memory/core/alert.py +69 -0
- surreal_memory/core/brain.py +416 -0
- surreal_memory/core/brain_mode.py +273 -0
- surreal_memory/core/eternal_context.py +273 -0
- surreal_memory/core/fiber.py +312 -0
- surreal_memory/core/memory_types.py +606 -0
- surreal_memory/core/neuron.py +235 -0
- surreal_memory/core/project.py +279 -0
- surreal_memory/core/review_schedule.py +89 -0
- surreal_memory/core/source.py +103 -0
- surreal_memory/core/synapse.py +357 -0
- surreal_memory/core/trigger_engine.py +226 -0
- surreal_memory/engine/__init__.py +29 -0
- surreal_memory/engine/activation.py +534 -0
- surreal_memory/engine/arousal.py +220 -0
- surreal_memory/engine/associative_inference.py +246 -0
- surreal_memory/engine/brain_evolution.py +479 -0
- surreal_memory/engine/brain_transplant.py +353 -0
- surreal_memory/engine/brain_versioning.py +438 -0
- surreal_memory/engine/causal_traversal.py +304 -0
- surreal_memory/engine/chart_generator.py +319 -0
- surreal_memory/engine/chunking.py +148 -0
- surreal_memory/engine/citation.py +150 -0
- surreal_memory/engine/clustering.py +41 -0
- surreal_memory/engine/codebase_encoder.py +258 -0
- surreal_memory/engine/cognitive.py +192 -0
- surreal_memory/engine/compression.py +1002 -0
- surreal_memory/engine/conflict_auto_resolve.py +143 -0
- surreal_memory/engine/conflict_detection.py +602 -0
- surreal_memory/engine/connection_explainer.py +249 -0
- surreal_memory/engine/consolidation.py +1795 -0
- surreal_memory/engine/consolidation_delta.py +227 -0
- surreal_memory/engine/context_merger.py +151 -0
- surreal_memory/engine/context_optimizer.py +467 -0
- surreal_memory/engine/context_retrieval.py +142 -0
- surreal_memory/engine/cross_brain.py +227 -0
- surreal_memory/engine/db_introspector.py +415 -0
- surreal_memory/engine/db_knowledge.py +638 -0
- surreal_memory/engine/db_trainer.py +421 -0
- surreal_memory/engine/decision_intel.py +330 -0
- surreal_memory/engine/dedup/__init__.py +12 -0
- surreal_memory/engine/dedup/config.py +104 -0
- surreal_memory/engine/dedup/llm_judge.py +154 -0
- surreal_memory/engine/dedup/pipeline.py +262 -0
- surreal_memory/engine/dedup/prompts.py +44 -0
- surreal_memory/engine/depth_prior.py +355 -0
- surreal_memory/engine/diagnostics.py +743 -0
- surreal_memory/engine/doc_chunker.py +414 -0
- surreal_memory/engine/doc_extractor.py +593 -0
- surreal_memory/engine/doc_trainer.py +664 -0
- surreal_memory/engine/dream.py +138 -0
- surreal_memory/engine/drift_detection.py +502 -0
- surreal_memory/engine/embedding/__init__.py +10 -0
- surreal_memory/engine/embedding/config.py +47 -0
- surreal_memory/engine/embedding/gemini_embedding.py +109 -0
- surreal_memory/engine/embedding/ollama_embedding.py +113 -0
- surreal_memory/engine/embedding/openai_embedding.py +95 -0
- surreal_memory/engine/embedding/openrouter_embedding.py +38 -0
- surreal_memory/engine/embedding/provider.py +46 -0
- surreal_memory/engine/embedding/sentence_transformer.py +72 -0
- surreal_memory/engine/encoder.py +475 -0
- surreal_memory/engine/enrichment.py +240 -0
- surreal_memory/engine/fidelity.py +538 -0
- surreal_memory/engine/file_watcher.py +369 -0
- surreal_memory/engine/fuzzy_match.py +110 -0
- surreal_memory/engine/fuzzy_query.py +251 -0
- surreal_memory/engine/gromov.py +238 -0
- surreal_memory/engine/hippocampal_replay.py +174 -0
- surreal_memory/engine/hooks.py +112 -0
- surreal_memory/engine/idf_anchor.py +100 -0
- surreal_memory/engine/importance.py +99 -0
- surreal_memory/engine/interference.py +274 -0
- surreal_memory/engine/koopman.py +227 -0
- surreal_memory/engine/learning_rule.py +230 -0
- surreal_memory/engine/lifecycle.py +436 -0
- surreal_memory/engine/memory_stages.py +247 -0
- surreal_memory/engine/merge.py +379 -0
- surreal_memory/engine/narrative.py +255 -0
- surreal_memory/engine/pattern_extraction.py +205 -0
- surreal_memory/engine/pipeline.py +126 -0
- surreal_memory/engine/pipeline_steps.py +1694 -0
- surreal_memory/engine/ppr_activation.py +291 -0
- surreal_memory/engine/prediction_error.py +259 -0
- surreal_memory/engine/priming.py +518 -0
- surreal_memory/engine/quality_scorer.py +294 -0
- surreal_memory/engine/query_expander.py +212 -0
- surreal_memory/engine/query_expansion.py +106 -0
- surreal_memory/engine/query_pattern_mining.py +408 -0
- surreal_memory/engine/reconsolidation.py +221 -0
- surreal_memory/engine/reconstruction.py +374 -0
- surreal_memory/engine/reflection.py +148 -0
- surreal_memory/engine/reflex_activation.py +389 -0
- surreal_memory/engine/reranker.py +216 -0
- surreal_memory/engine/retrieval.py +1849 -0
- surreal_memory/engine/retrieval_context.py +485 -0
- surreal_memory/engine/retrieval_types.py +95 -0
- surreal_memory/engine/schema_assimilation.py +357 -0
- surreal_memory/engine/score_fusion.py +117 -0
- surreal_memory/engine/semantic_discovery.py +303 -0
- surreal_memory/engine/sequence_mining.py +414 -0
- surreal_memory/engine/session_state.py +306 -0
- surreal_memory/engine/spaced_repetition.py +136 -0
- surreal_memory/engine/stabilization.py +165 -0
- surreal_memory/engine/sufficiency.py +503 -0
- surreal_memory/engine/temporal_binding.py +107 -0
- surreal_memory/engine/tier_engine.py +286 -0
- surreal_memory/engine/token_budget.py +231 -0
- surreal_memory/engine/token_normalizer.py +159 -0
- surreal_memory/engine/tool_memory.py +377 -0
- surreal_memory/engine/topology_analysis.py +233 -0
- surreal_memory/engine/watch_state.py +206 -0
- surreal_memory/engine/workflow_suggest.py +108 -0
- surreal_memory/engine/write_queue.py +147 -0
- surreal_memory/extraction/__init__.py +51 -0
- surreal_memory/extraction/codebase.py +580 -0
- surreal_memory/extraction/entities.py +697 -0
- surreal_memory/extraction/keywords.py +457 -0
- surreal_memory/extraction/llm_provider.py +98 -0
- surreal_memory/extraction/parser.py +385 -0
- surreal_memory/extraction/relations.py +514 -0
- surreal_memory/extraction/router.py +435 -0
- surreal_memory/extraction/sentiment.py +576 -0
- surreal_memory/extraction/structure_detector.py +334 -0
- surreal_memory/extraction/temporal.py +440 -0
- surreal_memory/git_context.py +76 -0
- surreal_memory/hooks/__init__.py +4 -0
- surreal_memory/hooks/post_tool_use.py +201 -0
- surreal_memory/hooks/pre_compact.py +309 -0
- surreal_memory/hooks/session_start.py +91 -0
- surreal_memory/hooks/stop.py +535 -0
- surreal_memory/integration/__init__.py +30 -0
- surreal_memory/integration/adapter.py +78 -0
- surreal_memory/integration/adapters/__init__.py +138 -0
- surreal_memory/integration/adapters/awf_adapter.py +335 -0
- surreal_memory/integration/adapters/chromadb_adapter.py +212 -0
- surreal_memory/integration/adapters/cognee_adapter.py +192 -0
- surreal_memory/integration/adapters/graphiti_adapter.py +342 -0
- surreal_memory/integration/adapters/llamaindex_adapter.py +194 -0
- surreal_memory/integration/adapters/mem0_adapter.py +261 -0
- surreal_memory/integration/mapper.py +273 -0
- surreal_memory/integration/models.py +180 -0
- surreal_memory/integration/sync_engine.py +240 -0
- surreal_memory/integration/telegram.py +235 -0
- surreal_memory/integrations/__init__.py +1 -0
- surreal_memory/integrations/nanobot/__init__.py +32 -0
- surreal_memory/integrations/nanobot/base_tool.py +58 -0
- surreal_memory/integrations/nanobot/context.py +33 -0
- surreal_memory/integrations/nanobot/memory_store.py +206 -0
- surreal_memory/integrations/nanobot/protocol.py +34 -0
- surreal_memory/integrations/nanobot/setup.py +80 -0
- surreal_memory/integrations/nanobot/tools.py +374 -0
- surreal_memory/integrations/openclaw_config.py +226 -0
- surreal_memory/mcp/__init__.py +9 -0
- surreal_memory/mcp/__main__.py +6 -0
- surreal_memory/mcp/alert_handler.py +196 -0
- surreal_memory/mcp/auto_capture.py +317 -0
- surreal_memory/mcp/auto_handler.py +440 -0
- surreal_memory/mcp/budget_handler.py +214 -0
- surreal_memory/mcp/cognitive_handler.py +1570 -0
- surreal_memory/mcp/conflict_handler.py +318 -0
- surreal_memory/mcp/connection_handler.py +73 -0
- surreal_memory/mcp/constants.py +14 -0
- surreal_memory/mcp/db_train_handler.py +157 -0
- surreal_memory/mcp/drift_handler.py +134 -0
- surreal_memory/mcp/eternal_handler.py +206 -0
- surreal_memory/mcp/evolution_handler.py +426 -0
- surreal_memory/mcp/expiry_cleanup_handler.py +149 -0
- surreal_memory/mcp/http_transport.py +159 -0
- surreal_memory/mcp/index_handler.py +208 -0
- surreal_memory/mcp/instruction_handler.py +246 -0
- surreal_memory/mcp/lifecycle_handler.py +383 -0
- surreal_memory/mcp/maintenance_handler.py +609 -0
- surreal_memory/mcp/mem0_sync_handler.py +172 -0
- surreal_memory/mcp/narrative_handler.py +142 -0
- surreal_memory/mcp/onboarding_handler.py +155 -0
- surreal_memory/mcp/prompt.py +523 -0
- surreal_memory/mcp/provenance_handler.py +363 -0
- surreal_memory/mcp/recall_handler.py +911 -0
- surreal_memory/mcp/remember_handler.py +806 -0
- surreal_memory/mcp/response_compactor.py +280 -0
- surreal_memory/mcp/review_handler.py +122 -0
- surreal_memory/mcp/scheduled_consolidation_handler.py +141 -0
- surreal_memory/mcp/server.py +656 -0
- surreal_memory/mcp/session_handler.py +361 -0
- surreal_memory/mcp/stats_handler.py +374 -0
- surreal_memory/mcp/surface_handler.py +116 -0
- surreal_memory/mcp/sync_handler.py +599 -0
- surreal_memory/mcp/telegram_handler.py +75 -0
- surreal_memory/mcp/tier_handler.py +153 -0
- surreal_memory/mcp/tool_handler_utils.py +133 -0
- surreal_memory/mcp/tool_handlers.py +66 -0
- surreal_memory/mcp/tool_schemas.py +1940 -0
- surreal_memory/mcp/train_handler.py +218 -0
- surreal_memory/mcp/version_check_handler.py +235 -0
- surreal_memory/mcp/visualize_handler.py +133 -0
- surreal_memory/mcp/watch_handler.py +225 -0
- surreal_memory/plugins/__init__.py +138 -0
- surreal_memory/plugins/base.py +69 -0
- surreal_memory/plugins/community.py +203 -0
- surreal_memory/py.typed +0 -0
- surreal_memory/safety/__init__.py +37 -0
- surreal_memory/safety/encryption.py +162 -0
- surreal_memory/safety/freshness.py +240 -0
- surreal_memory/safety/input_firewall.py +305 -0
- surreal_memory/safety/sensitive.py +400 -0
- surreal_memory/server/__init__.py +5 -0
- surreal_memory/server/app.py +682 -0
- surreal_memory/server/dependencies.py +116 -0
- surreal_memory/server/models.py +348 -0
- surreal_memory/server/routes/__init__.py +25 -0
- surreal_memory/server/routes/brain.py +328 -0
- surreal_memory/server/routes/consolidation.py +115 -0
- surreal_memory/server/routes/dashboard_api.py +1573 -0
- surreal_memory/server/routes/hub.py +387 -0
- surreal_memory/server/routes/integration_status.py +177 -0
- surreal_memory/server/routes/memory.py +896 -0
- surreal_memory/server/routes/oauth.py +240 -0
- surreal_memory/server/routes/openclaw_api.py +208 -0
- surreal_memory/server/routes/sync.py +415 -0
- surreal_memory/server/static/dist/assets/DiagramsPage-BZV40eAE.css +1 -0
- surreal_memory/server/static/dist/assets/DiagramsPage-DxGbFDqh.js +7 -0
- surreal_memory/server/static/dist/assets/EvolutionPage-BCt3Gjlg.js +1 -0
- surreal_memory/server/static/dist/assets/GraphPage-Bn2XnYSM.js +312 -0
- surreal_memory/server/static/dist/assets/HealthPage-BOvDCRq_.js +1 -0
- surreal_memory/server/static/dist/assets/OraclePage-Cx309IS8.js +1 -0
- surreal_memory/server/static/dist/assets/OverviewPage-C9zanzbn.js +1 -0
- surreal_memory/server/static/dist/assets/ProGate-CWdLKxhy.js +1 -0
- surreal_memory/server/static/dist/assets/SettingsPage-Co7mL5ao.js +1 -0
- surreal_memory/server/static/dist/assets/StoragePage-ChOPs2Io.js +1 -0
- surreal_memory/server/static/dist/assets/SyncPage-XHo3B9mj.js +1 -0
- surreal_memory/server/static/dist/assets/TimelinePage-D7a4yM0C.js +1 -0
- surreal_memory/server/static/dist/assets/ToolStatsPage-DSbdcAxV.js +1 -0
- surreal_memory/server/static/dist/assets/VisualizePage-CQRwt661.js +2 -0
- surreal_memory/server/static/dist/assets/card-DMi3iNIj.js +1 -0
- surreal_memory/server/static/dist/assets/embed-gLOWnRXV.js +193 -0
- surreal_memory/server/static/dist/assets/index-C4hAA6lf.css +1 -0
- surreal_memory/server/static/dist/assets/index-eqEVe4jF.js +54 -0
- surreal_memory/server/static/dist/assets/skeleton-CMgwRZUe.js +1 -0
- surreal_memory/server/static/dist/assets/timer-DWAvo6M8.js +1 -0
- surreal_memory/server/static/dist/assets/vendor-icons-ILWTDAJI.js +1 -0
- surreal_memory/server/static/dist/assets/vendor-motion-Ct_HHbYW.js +1 -0
- surreal_memory/server/static/dist/assets/vendor-query-CqA1cBNl.js +1 -0
- surreal_memory/server/static/dist/assets/vendor-react-BfuodpLv.js +3 -0
- surreal_memory/server/static/dist/assets/vendor-recharts-BkwZfCWA.js +33 -0
- surreal_memory/server/static/dist/assets/vendor-ui-Qm4_4bAc.js +1 -0
- surreal_memory/server/static/dist/index.html +19 -0
- surreal_memory/skills/__init__.py +10 -0
- surreal_memory/skills/memory-audit/SKILL.md +226 -0
- surreal_memory/skills/memory-evolution/SKILL.md +317 -0
- surreal_memory/skills/memory-intake/SKILL.md +179 -0
- surreal_memory/storage/__init__.py +18 -0
- surreal_memory/storage/base.py +1814 -0
- surreal_memory/storage/factory.py +391 -0
- surreal_memory/storage/memory_brain_ops.py +291 -0
- surreal_memory/storage/memory_collections.py +339 -0
- surreal_memory/storage/memory_reviews.py +69 -0
- surreal_memory/storage/memory_store.py +764 -0
- surreal_memory/storage/neuron_cache.py +97 -0
- surreal_memory/storage/read_pool.py +87 -0
- surreal_memory/storage/shared_store.py +468 -0
- surreal_memory/storage/shared_store_collections.py +210 -0
- surreal_memory/storage/shared_store_mappers.py +139 -0
- surreal_memory/storage/sqlite_action_log.py +153 -0
- surreal_memory/storage/sqlite_alerts.py +203 -0
- surreal_memory/storage/sqlite_brain_ops.py +522 -0
- surreal_memory/storage/sqlite_calibration.py +356 -0
- surreal_memory/storage/sqlite_change_log.py +287 -0
- surreal_memory/storage/sqlite_coactivation.py +112 -0
- surreal_memory/storage/sqlite_cognitive.py +477 -0
- surreal_memory/storage/sqlite_compression.py +187 -0
- surreal_memory/storage/sqlite_depth_priors.py +136 -0
- surreal_memory/storage/sqlite_devices.py +138 -0
- surreal_memory/storage/sqlite_drift.py +219 -0
- surreal_memory/storage/sqlite_entity_refs.py +103 -0
- surreal_memory/storage/sqlite_fibers.py +527 -0
- surreal_memory/storage/sqlite_maturation.py +147 -0
- surreal_memory/storage/sqlite_merkle.py +301 -0
- surreal_memory/storage/sqlite_neurons.py +752 -0
- surreal_memory/storage/sqlite_projects.py +148 -0
- surreal_memory/storage/sqlite_reviews.py +162 -0
- surreal_memory/storage/sqlite_row_mappers.py +287 -0
- surreal_memory/storage/sqlite_schema.py +1289 -0
- surreal_memory/storage/sqlite_sessions.py +141 -0
- surreal_memory/storage/sqlite_sources.py +246 -0
- surreal_memory/storage/sqlite_store.py +370 -0
- surreal_memory/storage/sqlite_synapses.py +484 -0
- surreal_memory/storage/sqlite_sync_state.py +117 -0
- surreal_memory/storage/sqlite_tool_events.py +264 -0
- surreal_memory/storage/sqlite_training_files.py +183 -0
- surreal_memory/storage/sqlite_typed.py +380 -0
- surreal_memory/storage/sqlite_versioning.py +153 -0
- surreal_memory/storage/surrealdb/__init__.py +22 -0
- surreal_memory/storage/surrealdb/activity.py +219 -0
- surreal_memory/storage/surrealdb/alerts.py +248 -0
- surreal_memory/storage/surrealdb/cognitive.py +512 -0
- surreal_memory/storage/surrealdb/compression.py +233 -0
- surreal_memory/storage/surrealdb/depth_priors.py +157 -0
- surreal_memory/storage/surrealdb/keyword_entity.py +202 -0
- surreal_memory/storage/surrealdb/review_schedules.py +175 -0
- surreal_memory/storage/surrealdb/schema.py +376 -0
- surreal_memory/storage/surrealdb/sources.py +234 -0
- surreal_memory/storage/surrealdb/store.py +1741 -0
- surreal_memory/storage/surrealdb/typed_memory.py +464 -0
- surreal_memory/storage/surrealdb/versions.py +199 -0
- surreal_memory/surface/__init__.py +57 -0
- surreal_memory/surface/generator.py +609 -0
- surreal_memory/surface/lifecycle.py +112 -0
- surreal_memory/surface/models.py +146 -0
- surreal_memory/surface/parser.py +401 -0
- surreal_memory/surface/resolver.py +154 -0
- surreal_memory/surface/serializer.py +180 -0
- surreal_memory/surface/token_budget.py +114 -0
- surreal_memory/sync/__init__.py +48 -0
- surreal_memory/sync/client.py +461 -0
- surreal_memory/sync/device.py +85 -0
- surreal_memory/sync/incremental_merge.py +203 -0
- surreal_memory/sync/merkle.py +217 -0
- surreal_memory/sync/protocol.py +115 -0
- surreal_memory/sync/sync_engine.py +719 -0
- surreal_memory/unified_config.py +1878 -0
- surreal_memory/utils/__init__.py +6 -0
- surreal_memory/utils/config.py +115 -0
- surreal_memory/utils/consolidation_lock.py +140 -0
- surreal_memory/utils/simhash.py +109 -0
- surreal_memory/utils/ssl_helper.py +49 -0
- surreal_memory/utils/tag_normalizer.py +164 -0
- surreal_memory/utils/timeutils.py +33 -0
- surreal_memory-2.0.0.dist-info/METADATA +484 -0
- surreal_memory-2.0.0.dist-info/RECORD +371 -0
- surreal_memory-2.0.0.dist-info/WHEEL +4 -0
- surreal_memory-2.0.0.dist-info/entry_points.txt +7 -0
- surreal_memory-2.0.0.dist-info/licenses/LICENSE +21 -0
- surreal_memory-2.0.0.dist-info/licenses/NOTICE +26 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Surreal-Memory - Reflex-based memory system for AI agents."""
|
|
2
|
+
|
|
3
|
+
from surreal_memory.core.brain import Brain, BrainConfig
|
|
4
|
+
from surreal_memory.core.brain_mode import (
|
|
5
|
+
BrainMode,
|
|
6
|
+
BrainModeConfig,
|
|
7
|
+
SharedConfig,
|
|
8
|
+
SyncStrategy,
|
|
9
|
+
)
|
|
10
|
+
from surreal_memory.core.fiber import Fiber
|
|
11
|
+
from surreal_memory.core.neuron import Neuron, NeuronState, NeuronType
|
|
12
|
+
from surreal_memory.core.synapse import Direction, Synapse, SynapseType
|
|
13
|
+
from surreal_memory.engine.brain_transplant import TransplantFilter, TransplantResult
|
|
14
|
+
from surreal_memory.engine.brain_versioning import BrainVersion, VersionDiff, VersioningEngine
|
|
15
|
+
from surreal_memory.engine.encoder import EncodingResult, MemoryEncoder
|
|
16
|
+
from surreal_memory.engine.reflex_activation import CoActivation, ReflexActivation
|
|
17
|
+
from surreal_memory.engine.retrieval import DepthLevel, ReflexPipeline, RetrievalResult
|
|
18
|
+
|
|
19
|
+
__version__ = "2.0.0"
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"__version__",
|
|
23
|
+
"Brain",
|
|
24
|
+
"BrainConfig",
|
|
25
|
+
"BrainMode",
|
|
26
|
+
"BrainModeConfig",
|
|
27
|
+
"BrainVersion",
|
|
28
|
+
"CoActivation",
|
|
29
|
+
"DepthLevel",
|
|
30
|
+
"Direction",
|
|
31
|
+
"EncodingResult",
|
|
32
|
+
"Fiber",
|
|
33
|
+
"MemoryEncoder",
|
|
34
|
+
"Neuron",
|
|
35
|
+
"NeuronState",
|
|
36
|
+
"NeuronType",
|
|
37
|
+
"ReflexActivation",
|
|
38
|
+
"ReflexPipeline",
|
|
39
|
+
"RetrievalResult",
|
|
40
|
+
"SharedConfig",
|
|
41
|
+
"Synapse",
|
|
42
|
+
"SynapseType",
|
|
43
|
+
"SyncStrategy",
|
|
44
|
+
"TransplantFilter",
|
|
45
|
+
"TransplantResult",
|
|
46
|
+
"VersionDiff",
|
|
47
|
+
"VersioningEngine",
|
|
48
|
+
]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Surreal-Memory CLI.
|
|
2
|
+
|
|
3
|
+
Simple command-line interface for storing and retrieving memories.
|
|
4
|
+
|
|
5
|
+
Usage:
|
|
6
|
+
smem remember "content" Store a memory
|
|
7
|
+
smem recall "query" Query memories
|
|
8
|
+
smem context Get recent context
|
|
9
|
+
smem brain list List brains
|
|
10
|
+
smem brain use <name> Switch brain
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from surreal_memory.cli.main import app, main
|
|
14
|
+
|
|
15
|
+
__all__ = ["app", "main"]
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"""Shared CLI helpers for configuration, storage, and output formatting."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import json
|
|
7
|
+
import logging
|
|
8
|
+
from collections.abc import Coroutine
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Any, TypeVar
|
|
11
|
+
|
|
12
|
+
import typer
|
|
13
|
+
|
|
14
|
+
from surreal_memory.cli.config import CLIConfig
|
|
15
|
+
from surreal_memory.cli.storage import PersistentStorage
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
T = TypeVar("T")
|
|
20
|
+
|
|
21
|
+
# Track storages created during a CLI command so we can close them before
|
|
22
|
+
# the event loop shuts down (prevents "Event loop is closed" noise from
|
|
23
|
+
# aiosqlite's background thread).
|
|
24
|
+
_active_storages: list[Any] = []
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def get_config() -> CLIConfig:
|
|
28
|
+
"""Get CLI configuration."""
|
|
29
|
+
return CLIConfig.load()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def run_async(coro: Coroutine[Any, Any, T]) -> T:
|
|
33
|
+
"""Run an async CLI command with proper storage cleanup.
|
|
34
|
+
|
|
35
|
+
Replaces bare ``asyncio.run()`` to ensure aiosqlite connections are
|
|
36
|
+
closed *before* the event loop is torn down.
|
|
37
|
+
"""
|
|
38
|
+
from surreal_memory.utils.sandbox import ensure_aiosqlite_or_exit_cli
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
ensure_aiosqlite_or_exit_cli()
|
|
42
|
+
except BaseException:
|
|
43
|
+
coro.close()
|
|
44
|
+
raise
|
|
45
|
+
|
|
46
|
+
async def _with_cleanup() -> T:
|
|
47
|
+
try:
|
|
48
|
+
return await coro
|
|
49
|
+
finally:
|
|
50
|
+
for storage in _active_storages:
|
|
51
|
+
if hasattr(storage, "close"):
|
|
52
|
+
try:
|
|
53
|
+
await storage.close()
|
|
54
|
+
except (OSError, RuntimeError):
|
|
55
|
+
logger.debug("Failed to close storage during cleanup", exc_info=True)
|
|
56
|
+
_active_storages.clear()
|
|
57
|
+
# Yield once so any pending callbacks from aiosqlite worker
|
|
58
|
+
# threads are drained before asyncio.run() tears down the loop.
|
|
59
|
+
# Prevents "Event loop is closed" on Python 3.12+.
|
|
60
|
+
await asyncio.sleep(0)
|
|
61
|
+
|
|
62
|
+
return asyncio.run(_with_cleanup())
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
async def get_storage(
|
|
66
|
+
config: CLIConfig,
|
|
67
|
+
*,
|
|
68
|
+
brain_name: str | None = None,
|
|
69
|
+
force_shared: bool = False,
|
|
70
|
+
force_local: bool = False,
|
|
71
|
+
force_sqlite: bool = False,
|
|
72
|
+
) -> PersistentStorage:
|
|
73
|
+
"""
|
|
74
|
+
Get storage for current brain.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
config: CLI configuration
|
|
78
|
+
brain_name: Brain name override (default: config.current_brain)
|
|
79
|
+
force_shared: Override config to use remote shared mode
|
|
80
|
+
force_local: Override config to use local JSON mode
|
|
81
|
+
force_sqlite: Override config to use local SQLite mode
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
Storage instance (local JSON, local SQLite, or remote shared)
|
|
85
|
+
"""
|
|
86
|
+
# Priority: explicit arg > env var > config file
|
|
87
|
+
if brain_name is None:
|
|
88
|
+
import os
|
|
89
|
+
|
|
90
|
+
env_brain = os.environ.get("SURREAL_MEMORY_BRAIN") or os.environ.get("SURREAL_MEMORY_BRAIN")
|
|
91
|
+
name = env_brain or config.current_brain
|
|
92
|
+
else:
|
|
93
|
+
name = brain_name
|
|
94
|
+
|
|
95
|
+
# Remote shared mode (via server)
|
|
96
|
+
use_shared = (config.is_shared_mode or force_shared) and not force_local and not force_sqlite
|
|
97
|
+
if use_shared:
|
|
98
|
+
from surreal_memory.storage.shared_store import SharedStorage
|
|
99
|
+
|
|
100
|
+
storage = SharedStorage(
|
|
101
|
+
server_url=config.shared.server_url,
|
|
102
|
+
brain_id=name,
|
|
103
|
+
timeout=config.shared.timeout,
|
|
104
|
+
api_key=config.shared.api_key,
|
|
105
|
+
)
|
|
106
|
+
await storage.connect()
|
|
107
|
+
_active_storages.append(storage)
|
|
108
|
+
return storage # type: ignore[return-value]
|
|
109
|
+
|
|
110
|
+
# SQLite mode (unified config - shared file-based storage)
|
|
111
|
+
if config.use_sqlite or force_sqlite:
|
|
112
|
+
from surreal_memory.unified_config import get_shared_storage
|
|
113
|
+
|
|
114
|
+
sqlite_storage = await get_shared_storage(name)
|
|
115
|
+
_active_storages.append(sqlite_storage)
|
|
116
|
+
return sqlite_storage # type: ignore[return-value]
|
|
117
|
+
|
|
118
|
+
# Legacy JSON mode
|
|
119
|
+
brain_path = config.get_brain_path(name)
|
|
120
|
+
return await PersistentStorage.load(brain_path)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def get_brain_path_auto(config: CLIConfig, brain_name: str | None = None) -> Path:
|
|
124
|
+
"""Get brain file path, choosing .db or .json based on storage mode."""
|
|
125
|
+
if config.use_sqlite:
|
|
126
|
+
return config.get_brain_db_path(brain_name)
|
|
127
|
+
return config.get_brain_path(brain_name)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def output_result(data: dict[str, Any], as_json: bool = False) -> None:
|
|
131
|
+
"""Output result in appropriate format."""
|
|
132
|
+
if as_json:
|
|
133
|
+
typer.echo(json.dumps(data, indent=2, default=str))
|
|
134
|
+
else:
|
|
135
|
+
# Human-readable format
|
|
136
|
+
if "error" in data:
|
|
137
|
+
typer.secho(f"Error: {data['error']}", fg=typer.colors.RED)
|
|
138
|
+
elif "answer" in data:
|
|
139
|
+
typer.echo(data["answer"])
|
|
140
|
+
|
|
141
|
+
# Show freshness warnings
|
|
142
|
+
if data.get("freshness_warnings"):
|
|
143
|
+
typer.echo("")
|
|
144
|
+
for warning in data["freshness_warnings"]:
|
|
145
|
+
typer.secho(warning, fg=typer.colors.YELLOW)
|
|
146
|
+
|
|
147
|
+
# Show metadata
|
|
148
|
+
meta_parts = []
|
|
149
|
+
if data.get("confidence") is not None:
|
|
150
|
+
meta_parts.append(f"confidence: {data['confidence']:.2f}")
|
|
151
|
+
if data.get("neurons_activated"):
|
|
152
|
+
meta_parts.append(f"neurons: {data['neurons_activated']}")
|
|
153
|
+
if data.get("oldest_memory_age"):
|
|
154
|
+
meta_parts.append(f"oldest: {data['oldest_memory_age']}")
|
|
155
|
+
|
|
156
|
+
if meta_parts:
|
|
157
|
+
typer.secho(f"\n[{', '.join(meta_parts)}]", fg=typer.colors.BRIGHT_BLACK)
|
|
158
|
+
|
|
159
|
+
# Show routing info if present
|
|
160
|
+
if data.get("routing"):
|
|
161
|
+
r = data["routing"]
|
|
162
|
+
typer.secho(
|
|
163
|
+
f"\n[routing: {r['query_type']}, depth: {r['suggested_depth']}, "
|
|
164
|
+
f"confidence: {r['confidence']}]",
|
|
165
|
+
fg=typer.colors.BRIGHT_BLACK,
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
elif "message" in data:
|
|
169
|
+
typer.secho(data["message"], fg=typer.colors.GREEN)
|
|
170
|
+
|
|
171
|
+
# Show memory type info
|
|
172
|
+
type_parts = []
|
|
173
|
+
if data.get("memory_type"):
|
|
174
|
+
type_parts.append(f"type: {data['memory_type']}")
|
|
175
|
+
if data.get("priority"):
|
|
176
|
+
type_parts.append(f"priority: {data['priority']}")
|
|
177
|
+
if data.get("expires_in_days") is not None:
|
|
178
|
+
type_parts.append(f"expires: {data['expires_in_days']}d")
|
|
179
|
+
if data.get("project"):
|
|
180
|
+
type_parts.append(f"project: {data['project']}")
|
|
181
|
+
if type_parts:
|
|
182
|
+
typer.secho(f" [{', '.join(type_parts)}]", fg=typer.colors.BRIGHT_BLACK)
|
|
183
|
+
|
|
184
|
+
# Show warnings if any
|
|
185
|
+
if data.get("warnings"):
|
|
186
|
+
for warning in data["warnings"]:
|
|
187
|
+
typer.secho(warning, fg=typer.colors.YELLOW)
|
|
188
|
+
|
|
189
|
+
elif "context" in data:
|
|
190
|
+
typer.echo(data["context"])
|
|
191
|
+
else:
|
|
192
|
+
typer.echo(str(data))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""CLI command modules."""
|