zikkaron 0.1.0__tar.gz

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.
Files changed (71) hide show
  1. zikkaron-0.1.0/.gitignore +30 -0
  2. zikkaron-0.1.0/LICENSE +21 -0
  3. zikkaron-0.1.0/PKG-INFO +236 -0
  4. zikkaron-0.1.0/README.md +202 -0
  5. zikkaron-0.1.0/pyproject.toml +62 -0
  6. zikkaron-0.1.0/requirements.txt +10 -0
  7. zikkaron-0.1.0/zikkaron/__init__.py +1 -0
  8. zikkaron-0.1.0/zikkaron/__main__.py +71 -0
  9. zikkaron-0.1.0/zikkaron/astrocyte_pool.py +355 -0
  10. zikkaron-0.1.0/zikkaron/causal_discovery.py +574 -0
  11. zikkaron-0.1.0/zikkaron/cls_store.py +563 -0
  12. zikkaron-0.1.0/zikkaron/cognitive_map.py +316 -0
  13. zikkaron-0.1.0/zikkaron/compression.py +425 -0
  14. zikkaron-0.1.0/zikkaron/config.py +64 -0
  15. zikkaron-0.1.0/zikkaron/consolidation.py +478 -0
  16. zikkaron-0.1.0/zikkaron/crdt_sync.py +343 -0
  17. zikkaron-0.1.0/zikkaron/curation.py +483 -0
  18. zikkaron-0.1.0/zikkaron/embeddings.py +152 -0
  19. zikkaron-0.1.0/zikkaron/engram.py +157 -0
  20. zikkaron-0.1.0/zikkaron/fractal.py +544 -0
  21. zikkaron-0.1.0/zikkaron/hdc_encoder.py +211 -0
  22. zikkaron-0.1.0/zikkaron/hopfield.py +283 -0
  23. zikkaron-0.1.0/zikkaron/knowledge_graph.py +474 -0
  24. zikkaron-0.1.0/zikkaron/metacognition.py +597 -0
  25. zikkaron-0.1.0/zikkaron/models.py +208 -0
  26. zikkaron-0.1.0/zikkaron/narrative.py +217 -0
  27. zikkaron-0.1.0/zikkaron/predictive_coding.py +448 -0
  28. zikkaron-0.1.0/zikkaron/prospective.py +180 -0
  29. zikkaron-0.1.0/zikkaron/reconsolidation.py +352 -0
  30. zikkaron-0.1.0/zikkaron/retrieval.py +617 -0
  31. zikkaron-0.1.0/zikkaron/rules_engine.py +354 -0
  32. zikkaron-0.1.0/zikkaron/sensory_buffer.py +77 -0
  33. zikkaron-0.1.0/zikkaron/server.py +991 -0
  34. zikkaron-0.1.0/zikkaron/sleep_compute.py +476 -0
  35. zikkaron-0.1.0/zikkaron/staleness.py +192 -0
  36. zikkaron-0.1.0/zikkaron/storage.py +1292 -0
  37. zikkaron-0.1.0/zikkaron/tests/__init__.py +0 -0
  38. zikkaron-0.1.0/zikkaron/tests/test_astrocyte_pool.py +314 -0
  39. zikkaron-0.1.0/zikkaron/tests/test_buffer.py +161 -0
  40. zikkaron-0.1.0/zikkaron/tests/test_causal_discovery.py +535 -0
  41. zikkaron-0.1.0/zikkaron/tests/test_cls_store.py +492 -0
  42. zikkaron-0.1.0/zikkaron/tests/test_cognitive_map.py +592 -0
  43. zikkaron-0.1.0/zikkaron/tests/test_compression.py +490 -0
  44. zikkaron-0.1.0/zikkaron/tests/test_consolidation.py +356 -0
  45. zikkaron-0.1.0/zikkaron/tests/test_crdt.py +610 -0
  46. zikkaron-0.1.0/zikkaron/tests/test_curation.py +445 -0
  47. zikkaron-0.1.0/zikkaron/tests/test_embedding_upgrade.py +287 -0
  48. zikkaron-0.1.0/zikkaron/tests/test_embeddings.py +111 -0
  49. zikkaron-0.1.0/zikkaron/tests/test_engram.py +447 -0
  50. zikkaron-0.1.0/zikkaron/tests/test_fractal.py +347 -0
  51. zikkaron-0.1.0/zikkaron/tests/test_frontier_integration.py +534 -0
  52. zikkaron-0.1.0/zikkaron/tests/test_frontier_schema.py +620 -0
  53. zikkaron-0.1.0/zikkaron/tests/test_hdc.py +593 -0
  54. zikkaron-0.1.0/zikkaron/tests/test_hopfield.py +478 -0
  55. zikkaron-0.1.0/zikkaron/tests/test_integration.py +1127 -0
  56. zikkaron-0.1.0/zikkaron/tests/test_knowledge_graph.py +297 -0
  57. zikkaron-0.1.0/zikkaron/tests/test_metacognition.py +579 -0
  58. zikkaron-0.1.0/zikkaron/tests/test_narrative.py +227 -0
  59. zikkaron-0.1.0/zikkaron/tests/test_predictive_coding.py +598 -0
  60. zikkaron-0.1.0/zikkaron/tests/test_prospective.py +271 -0
  61. zikkaron-0.1.0/zikkaron/tests/test_reconsolidation.py +402 -0
  62. zikkaron-0.1.0/zikkaron/tests/test_retrieval.py +376 -0
  63. zikkaron-0.1.0/zikkaron/tests/test_rules_engine.py +694 -0
  64. zikkaron-0.1.0/zikkaron/tests/test_server.py +317 -0
  65. zikkaron-0.1.0/zikkaron/tests/test_sleep_compute.py +401 -0
  66. zikkaron-0.1.0/zikkaron/tests/test_sqlite_vec.py +295 -0
  67. zikkaron-0.1.0/zikkaron/tests/test_staleness.py +245 -0
  68. zikkaron-0.1.0/zikkaron/tests/test_storage.py +526 -0
  69. zikkaron-0.1.0/zikkaron/tests/test_thermodynamics.py +400 -0
  70. zikkaron-0.1.0/zikkaron/tests/test_transport.py +183 -0
  71. zikkaron-0.1.0/zikkaron/thermodynamics.py +236 -0
@@ -0,0 +1,30 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.so
5
+ *.egg-info/
6
+ dist/
7
+ build/
8
+ .eggs/
9
+ *.egg
10
+
11
+ .venv/
12
+ venv/
13
+ env/
14
+
15
+ .pytest_cache/
16
+ .coverage
17
+ htmlcov/
18
+
19
+ *.db
20
+ *.db-wal
21
+ *.db-shm
22
+
23
+ .lockstep/
24
+ *.lockstep.yml
25
+ .lockstep.yml
26
+
27
+ .claude/
28
+
29
+ .env
30
+ *.log
zikkaron-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 amanhij
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,236 @@
1
+ Metadata-Version: 2.4
2
+ Name: zikkaron
3
+ Version: 0.1.0
4
+ Summary: Biologically-inspired persistent memory engine for Claude Code
5
+ Project-URL: Homepage, https://github.com/amanhij/Zikkaron
6
+ Project-URL: Repository, https://github.com/amanhij/Zikkaron
7
+ Project-URL: Issues, https://github.com/amanhij/Zikkaron/issues
8
+ Author: amanhij
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: claude,cognitive-architecture,hopfield-networks,knowledge-graph,mcp,memory,neuroscience,persistent-memory
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Classifier: Topic :: Software Development :: Libraries
21
+ Requires-Python: >=3.11
22
+ Requires-Dist: fastapi>=0.104.0
23
+ Requires-Dist: mcp>=1.0.0
24
+ Requires-Dist: networkx>=3.0
25
+ Requires-Dist: numpy>=1.24.0
26
+ Requires-Dist: pydantic-settings>=2.0.0
27
+ Requires-Dist: pydantic>=2.5.0
28
+ Requires-Dist: sentence-transformers>=2.2.0
29
+ Requires-Dist: sqlite-vec>=0.1.6
30
+ Requires-Dist: sse-starlette>=1.6.0
31
+ Requires-Dist: uvicorn>=0.24.0
32
+ Requires-Dist: watchdog>=3.0.0
33
+ Description-Content-Type: text/markdown
34
+
35
+ # Zikkaron
36
+
37
+ Persistent memory engine for Claude Code, implemented as an MCP server.
38
+
39
+ Large language model agents lose all accumulated knowledge when a session ends. Context windows function as volatile working memory — once cleared, every architectural decision, debugging insight, and project-specific convention must be re-established from scratch. Zikkaron provides a durable memory substrate that persists across sessions, using mechanisms drawn from computational neuroscience to organize, consolidate, and retrieve knowledge over time.
40
+
41
+ ## Architecture
42
+
43
+ Zikkaron runs as a local MCP (Model Context Protocol) server over SSE. All data stays on your machine in a single SQLite database with WAL mode, FTS5 full-text search, and `sqlite-vec` for vector similarity.
44
+
45
+ The system is composed of 26 subsystems organized into three tiers:
46
+
47
+ ### Core Storage and Retrieval
48
+
49
+ | Module | Role |
50
+ |---|---|
51
+ | `storage.py` | SQLite WAL engine with 15 tables, FTS5 indexing, `sqlite-vec` ANN search |
52
+ | `embeddings.py` | Sentence-transformer encoding (`all-MiniLM-L6-v2`) with batched operations |
53
+ | `retrieval.py` | Multi-signal fusion retriever combining vector similarity, FTS5 BM25, knowledge graph PPR, spreading activation, and fractal hierarchy traversal |
54
+ | `models.py` | Pydantic data models for memories, entities, relationships, clusters, rules, and causal edges |
55
+ | `config.py` | Environment-based configuration with `ZIKKARON_` prefix |
56
+
57
+ ### Memory Dynamics
58
+
59
+ | Module | Role |
60
+ |---|---|
61
+ | `thermodynamics.py` | Heat-based memory salience. Surprise scoring, importance heuristics, emotional valence, and temporal decay govern which memories stay accessible |
62
+ | `reconsolidation.py` | Memories become labile on retrieval and are rewritten based on context mismatch magnitude. Implements the Nader et al. (2000) reconsolidation model with three outcomes: reinforcement, modification, or archival |
63
+ | `predictive_coding.py` | Write gate that only stores prediction errors. Maintains a generative model per directory context and computes surprisal against existing knowledge — redundant information is filtered at ingest |
64
+ | `engram.py` | Competitive memory slot allocation based on CREB-like excitability (Josselyn & Frankland, 2007). High-excitability slots win allocation; temporally proximate memories share engram slots |
65
+ | `compression.py` | Rate-distortion optimal forgetting (Toth et al., 2020). Memories degrade progressively: full fidelity at 0-7 days, gist compression at 7-30 days, semantic tag extraction beyond 30 days |
66
+ | `staleness.py` | File-change watchdog using SHA-256 hashing to detect when source code has diverged from stored memories |
67
+
68
+ ### Consolidation and Organization
69
+
70
+ | Module | Role |
71
+ |---|---|
72
+ | `consolidation.py` | Background astrocyte daemon running periodic consolidation cycles: decay application, staleness checks, prospective trigger evaluation |
73
+ | `astrocyte_pool.py` | Domain-specialized consolidation processes (code structure, architectural decisions, error patterns, dependency tracking) running as a worker pool |
74
+ | `sleep_compute.py` | Offline "dream replay" that replays memory pairs to discover cross-project connections, runs Louvain community detection for clustering, and performs temporal compression |
75
+ | `fractal.py` | Hierarchical multi-scale memory tree. Memories cluster at leaf level; clusters merge into intermediate summaries; summaries merge into root abstractions. Supports drill-down navigation |
76
+ | `cls_store.py` | Complementary Learning Systems (McClelland et al., 1995). Dual-store architecture: fast episodic capture in a hippocampal buffer, slow semantic abstraction in a neocortical store with periodic interleaved replay |
77
+
78
+ ### Knowledge Structure
79
+
80
+ | Module | Role |
81
+ |---|---|
82
+ | `knowledge_graph.py` | Typed entity-relationship graph with co-occurrence, causal, and temporal edges. Supports Personalized PageRank for contextual retrieval |
83
+ | `causal_discovery.py` | PC algorithm (Spirtes, Glymour, Scheines, 2000) for discovering causal DAGs from coding session event logs. Conditional independence testing via partial correlation |
84
+ | `cognitive_map.py` | Successor Representation (Stachenfeld et al., 2017) for navigation-based retrieval. Memories that co-occur in similar contexts cluster in SR space, enabling associative traversal even when content differs |
85
+ | `narrative.py` | Autobiographical project stories synthesized from memory timelines, key decisions, and significant events |
86
+ | `curation.py` | Automated memory maintenance: duplicate merging, contradiction detection, cross-reference linking |
87
+
88
+ ### Frontier Capabilities
89
+
90
+ | Module | Role |
91
+ |---|---|
92
+ | `hopfield.py` | Modern continuous Hopfield networks (Ramsauer et al., 2021). Energy-based associative retrieval equivalent to transformer attention: `softmax(beta * X^T * query)` |
93
+ | `hdc_encoder.py` | Hyperdimensional Computing / Vector Symbolic Architecture (Kanerva, 1988). Encodes memories as role-filler bindings in 10,000-dimensional bipolar space for structured queries |
94
+ | `metacognition.py` | Self-assessment of knowledge coverage. Gap detection across five dimensions: isolated entities, stale regions, low-confidence zones, missing connections, one-sided knowledge |
95
+ | `rules_engine.py` | Neuro-symbolic constraints. Hard rules (must satisfy) and soft rules (preference boosts/penalties) scoped to global, directory, or file level |
96
+ | `crdt_sync.py` | Multi-agent memory sharing via CRDTs (OR-Set for collections, LWW-Register for content, G-Counter for access counts). Automatic conflict resolution across agent instances |
97
+ | `prospective.py` | Future-oriented triggers that fire when matching context is detected — directory, keyword, entity, or time-based conditions |
98
+ | `sensory_buffer.py` | Episodic capture buffer for raw session content with configurable token windows and overlap |
99
+
100
+ ## MCP Tools
101
+
102
+ Zikkaron exposes 18 tools over MCP:
103
+
104
+ | Tool | Description |
105
+ |---|---|
106
+ | `remember` | Store a new memory. Passes through the predictive coding write gate and engram allocation |
107
+ | `recall` | Semantic + keyword search with heat-weighted ranking. Automatically boosts accessed memories |
108
+ | `forget` | Mark a memory for deletion by zeroing heat, then remove |
109
+ | `validate_memory` | Check memory validity against current file state via SHA-256 |
110
+ | `get_project_context` | Return all active memories for a directory, sorted by heat |
111
+ | `consolidate_now` | Trigger an immediate consolidation cycle |
112
+ | `memory_stats` | System statistics: counts, averages, subsystem status |
113
+ | `rate_memory` | Provide usefulness feedback for metamemory tracking |
114
+ | `recall_hierarchical` | Retrieve from the fractal hierarchy at a specific level or adaptively |
115
+ | `drill_down` | Navigate into a cluster to see its constituent memories |
116
+ | `create_trigger` | Create a prospective memory trigger for future context matching |
117
+ | `get_project_story` | Get the autobiographical narrative for a project directory |
118
+ | `add_rule` | Define a neuro-symbolic rule for filtering or re-ranking retrieval |
119
+ | `get_rules` | List active rules, optionally filtered by directory |
120
+ | `navigate_memory` | Traverse concept space using successor representation cognitive maps |
121
+ | `get_causal_chain` | Get causal ancestors and descendants for an entity from the PC algorithm DAG |
122
+ | `assess_coverage` | Evaluate knowledge coverage for a topic with gap identification |
123
+ | `detect_gaps` | Find knowledge gaps in a project: isolated entities, stale regions, missing connections |
124
+
125
+ ## Quick Start
126
+
127
+ Requires Python 3.11+.
128
+
129
+ ```bash
130
+ pip install zikkaron
131
+ ```
132
+
133
+ Add one line to your Claude Code MCP configuration (`~/.claude/settings.json`):
134
+
135
+ ```json
136
+ {
137
+ "mcpServers": {
138
+ "zikkaron": {
139
+ "command": "zikkaron"
140
+ }
141
+ }
142
+ }
143
+ ```
144
+
145
+ That's it. Claude Code will launch Zikkaron automatically via stdio transport. No manual server management.
146
+
147
+ ### From source
148
+
149
+ ```bash
150
+ git clone https://github.com/amanhij/Zikkaron.git
151
+ cd Zikkaron
152
+ pip install -e .
153
+ ```
154
+
155
+ ### SSE transport (advanced)
156
+
157
+ For running as a persistent background server instead of stdio:
158
+
159
+ ```bash
160
+ zikkaron --transport sse
161
+ ```
162
+
163
+ Then configure Claude Code to connect via URL:
164
+
165
+ ```json
166
+ {
167
+ "mcpServers": {
168
+ "zikkaron": {
169
+ "type": "sse",
170
+ "url": "http://127.0.0.1:8742/sse"
171
+ }
172
+ }
173
+ }
174
+ ```
175
+
176
+ Default port: `8742`. Override with `--port`. Database defaults to `~/.zikkaron/memory.db`, override with `--db-path`.
177
+
178
+ ## Configuration
179
+
180
+ All settings are configurable via environment variables with the `ZIKKARON_` prefix:
181
+
182
+ | Variable | Default | Description |
183
+ |---|---|---|
184
+ | `ZIKKARON_PORT` | `8742` | Server port |
185
+ | `ZIKKARON_DB_PATH` | `~/.zikkaron/memory.db` | Database location |
186
+ | `ZIKKARON_EMBEDDING_MODEL` | `all-MiniLM-L6-v2` | Sentence-transformer model |
187
+ | `ZIKKARON_DECAY_FACTOR` | `0.95` | Base heat decay per consolidation cycle |
188
+ | `ZIKKARON_COLD_THRESHOLD` | `0.05` | Heat below which memories are candidates for archival |
189
+ | `ZIKKARON_WRITE_GATE_THRESHOLD` | `0.4` | Minimum surprisal to pass the predictive coding write gate |
190
+ | `ZIKKARON_HOPFIELD_BETA` | `8.0` | Hopfield network sharpness parameter |
191
+ | `ZIKKARON_SR_DISCOUNT` | `0.9` | Successor representation discount factor |
192
+ | `ZIKKARON_COGNITIVE_LOAD_LIMIT` | `4` | Maximum chunks in active context (Cowan's 4 +/- 1) |
193
+
194
+ See `zikkaron/config.py` for the full list.
195
+
196
+ ## Testing
197
+
198
+ ```bash
199
+ python -m pytest zikkaron/tests/ -x -q
200
+ ```
201
+
202
+ 891 tests across 33 test files covering all subsystems.
203
+
204
+ ## Dependencies
205
+
206
+ - **mcp** — Model Context Protocol SDK
207
+ - **sentence-transformers** — Local embedding generation
208
+ - **sqlite-vec** — Vector similarity search extension for SQLite
209
+ - **networkx** — Graph algorithms for knowledge graph and causal discovery
210
+ - **numpy** — Numerical operations for Hopfield networks, HDC, and SR
211
+ - **fastapi / uvicorn / sse-starlette** — HTTP server and SSE transport
212
+ - **pydantic** — Data validation and settings management
213
+ - **watchdog** — File system change detection
214
+
215
+ ## References
216
+
217
+ The implementation draws on ideas from the following work:
218
+
219
+ - Ramsauer et al. "Hopfield Networks is All You Need" (ICLR 2021, arXiv:2008.02217)
220
+ - Nader, Schafe, LeDoux. "Fear memories require protein synthesis in the amygdala for reconsolidation after retrieval" (Nature 406, 2000)
221
+ - Osan, Tort, Bhatt, Bhatt, Bhatt, Amaral. "Three outcomes of reconsolidation" (PLoS ONE, 2011)
222
+ - McClelland, McNaughton, O'Reilly. "Why there are complementary learning systems in the hippocampus and neocortex" (Psych. Review 102, 1995)
223
+ - Sun et al. "Organizing memories for generalization in complementary learning systems" (Nature Neuroscience 26, 2023)
224
+ - Stachenfeld, Botvinick, Gershman. "The hippocampus as a predictive map" (Nature Neuroscience 20, 2017)
225
+ - Whittington et al. "The Tolman-Eichenbaum Machine" (Cell 183, 2020)
226
+ - Spirtes, Glymour, Scheines. *Causation, Prediction, and Search* (MIT Press, 2000)
227
+ - Kanerva. *Sparse Distributed Memory* (MIT Press, 1988)
228
+ - Frady, Kleyko, Sommer. "Variable Binding for Sparse Distributed Representations" (IEEE TNNLS, 2022)
229
+ - Toth et al. "Optimal forgetting via rate-distortion theory" (PLoS Computational Biology, 2020)
230
+ - Josselyn, Frankland. "Memory allocation: mechanisms and function" (Annual Review Neuroscience 41, 2018)
231
+ - Rashid et al. "Competition between engrams influences fear memory formation and recall" (Science 353, 2016)
232
+ - Zhou et al. "MetaRAG: Metacognitive Retrieval-Augmented Generation" (ACM Web, 2024)
233
+
234
+ ## License
235
+
236
+ MIT
@@ -0,0 +1,202 @@
1
+ # Zikkaron
2
+
3
+ Persistent memory engine for Claude Code, implemented as an MCP server.
4
+
5
+ Large language model agents lose all accumulated knowledge when a session ends. Context windows function as volatile working memory — once cleared, every architectural decision, debugging insight, and project-specific convention must be re-established from scratch. Zikkaron provides a durable memory substrate that persists across sessions, using mechanisms drawn from computational neuroscience to organize, consolidate, and retrieve knowledge over time.
6
+
7
+ ## Architecture
8
+
9
+ Zikkaron runs as a local MCP (Model Context Protocol) server over SSE. All data stays on your machine in a single SQLite database with WAL mode, FTS5 full-text search, and `sqlite-vec` for vector similarity.
10
+
11
+ The system is composed of 26 subsystems organized into three tiers:
12
+
13
+ ### Core Storage and Retrieval
14
+
15
+ | Module | Role |
16
+ |---|---|
17
+ | `storage.py` | SQLite WAL engine with 15 tables, FTS5 indexing, `sqlite-vec` ANN search |
18
+ | `embeddings.py` | Sentence-transformer encoding (`all-MiniLM-L6-v2`) with batched operations |
19
+ | `retrieval.py` | Multi-signal fusion retriever combining vector similarity, FTS5 BM25, knowledge graph PPR, spreading activation, and fractal hierarchy traversal |
20
+ | `models.py` | Pydantic data models for memories, entities, relationships, clusters, rules, and causal edges |
21
+ | `config.py` | Environment-based configuration with `ZIKKARON_` prefix |
22
+
23
+ ### Memory Dynamics
24
+
25
+ | Module | Role |
26
+ |---|---|
27
+ | `thermodynamics.py` | Heat-based memory salience. Surprise scoring, importance heuristics, emotional valence, and temporal decay govern which memories stay accessible |
28
+ | `reconsolidation.py` | Memories become labile on retrieval and are rewritten based on context mismatch magnitude. Implements the Nader et al. (2000) reconsolidation model with three outcomes: reinforcement, modification, or archival |
29
+ | `predictive_coding.py` | Write gate that only stores prediction errors. Maintains a generative model per directory context and computes surprisal against existing knowledge — redundant information is filtered at ingest |
30
+ | `engram.py` | Competitive memory slot allocation based on CREB-like excitability (Josselyn & Frankland, 2007). High-excitability slots win allocation; temporally proximate memories share engram slots |
31
+ | `compression.py` | Rate-distortion optimal forgetting (Toth et al., 2020). Memories degrade progressively: full fidelity at 0-7 days, gist compression at 7-30 days, semantic tag extraction beyond 30 days |
32
+ | `staleness.py` | File-change watchdog using SHA-256 hashing to detect when source code has diverged from stored memories |
33
+
34
+ ### Consolidation and Organization
35
+
36
+ | Module | Role |
37
+ |---|---|
38
+ | `consolidation.py` | Background astrocyte daemon running periodic consolidation cycles: decay application, staleness checks, prospective trigger evaluation |
39
+ | `astrocyte_pool.py` | Domain-specialized consolidation processes (code structure, architectural decisions, error patterns, dependency tracking) running as a worker pool |
40
+ | `sleep_compute.py` | Offline "dream replay" that replays memory pairs to discover cross-project connections, runs Louvain community detection for clustering, and performs temporal compression |
41
+ | `fractal.py` | Hierarchical multi-scale memory tree. Memories cluster at leaf level; clusters merge into intermediate summaries; summaries merge into root abstractions. Supports drill-down navigation |
42
+ | `cls_store.py` | Complementary Learning Systems (McClelland et al., 1995). Dual-store architecture: fast episodic capture in a hippocampal buffer, slow semantic abstraction in a neocortical store with periodic interleaved replay |
43
+
44
+ ### Knowledge Structure
45
+
46
+ | Module | Role |
47
+ |---|---|
48
+ | `knowledge_graph.py` | Typed entity-relationship graph with co-occurrence, causal, and temporal edges. Supports Personalized PageRank for contextual retrieval |
49
+ | `causal_discovery.py` | PC algorithm (Spirtes, Glymour, Scheines, 2000) for discovering causal DAGs from coding session event logs. Conditional independence testing via partial correlation |
50
+ | `cognitive_map.py` | Successor Representation (Stachenfeld et al., 2017) for navigation-based retrieval. Memories that co-occur in similar contexts cluster in SR space, enabling associative traversal even when content differs |
51
+ | `narrative.py` | Autobiographical project stories synthesized from memory timelines, key decisions, and significant events |
52
+ | `curation.py` | Automated memory maintenance: duplicate merging, contradiction detection, cross-reference linking |
53
+
54
+ ### Frontier Capabilities
55
+
56
+ | Module | Role |
57
+ |---|---|
58
+ | `hopfield.py` | Modern continuous Hopfield networks (Ramsauer et al., 2021). Energy-based associative retrieval equivalent to transformer attention: `softmax(beta * X^T * query)` |
59
+ | `hdc_encoder.py` | Hyperdimensional Computing / Vector Symbolic Architecture (Kanerva, 1988). Encodes memories as role-filler bindings in 10,000-dimensional bipolar space for structured queries |
60
+ | `metacognition.py` | Self-assessment of knowledge coverage. Gap detection across five dimensions: isolated entities, stale regions, low-confidence zones, missing connections, one-sided knowledge |
61
+ | `rules_engine.py` | Neuro-symbolic constraints. Hard rules (must satisfy) and soft rules (preference boosts/penalties) scoped to global, directory, or file level |
62
+ | `crdt_sync.py` | Multi-agent memory sharing via CRDTs (OR-Set for collections, LWW-Register for content, G-Counter for access counts). Automatic conflict resolution across agent instances |
63
+ | `prospective.py` | Future-oriented triggers that fire when matching context is detected — directory, keyword, entity, or time-based conditions |
64
+ | `sensory_buffer.py` | Episodic capture buffer for raw session content with configurable token windows and overlap |
65
+
66
+ ## MCP Tools
67
+
68
+ Zikkaron exposes 18 tools over MCP:
69
+
70
+ | Tool | Description |
71
+ |---|---|
72
+ | `remember` | Store a new memory. Passes through the predictive coding write gate and engram allocation |
73
+ | `recall` | Semantic + keyword search with heat-weighted ranking. Automatically boosts accessed memories |
74
+ | `forget` | Mark a memory for deletion by zeroing heat, then remove |
75
+ | `validate_memory` | Check memory validity against current file state via SHA-256 |
76
+ | `get_project_context` | Return all active memories for a directory, sorted by heat |
77
+ | `consolidate_now` | Trigger an immediate consolidation cycle |
78
+ | `memory_stats` | System statistics: counts, averages, subsystem status |
79
+ | `rate_memory` | Provide usefulness feedback for metamemory tracking |
80
+ | `recall_hierarchical` | Retrieve from the fractal hierarchy at a specific level or adaptively |
81
+ | `drill_down` | Navigate into a cluster to see its constituent memories |
82
+ | `create_trigger` | Create a prospective memory trigger for future context matching |
83
+ | `get_project_story` | Get the autobiographical narrative for a project directory |
84
+ | `add_rule` | Define a neuro-symbolic rule for filtering or re-ranking retrieval |
85
+ | `get_rules` | List active rules, optionally filtered by directory |
86
+ | `navigate_memory` | Traverse concept space using successor representation cognitive maps |
87
+ | `get_causal_chain` | Get causal ancestors and descendants for an entity from the PC algorithm DAG |
88
+ | `assess_coverage` | Evaluate knowledge coverage for a topic with gap identification |
89
+ | `detect_gaps` | Find knowledge gaps in a project: isolated entities, stale regions, missing connections |
90
+
91
+ ## Quick Start
92
+
93
+ Requires Python 3.11+.
94
+
95
+ ```bash
96
+ pip install zikkaron
97
+ ```
98
+
99
+ Add one line to your Claude Code MCP configuration (`~/.claude/settings.json`):
100
+
101
+ ```json
102
+ {
103
+ "mcpServers": {
104
+ "zikkaron": {
105
+ "command": "zikkaron"
106
+ }
107
+ }
108
+ }
109
+ ```
110
+
111
+ That's it. Claude Code will launch Zikkaron automatically via stdio transport. No manual server management.
112
+
113
+ ### From source
114
+
115
+ ```bash
116
+ git clone https://github.com/amanhij/Zikkaron.git
117
+ cd Zikkaron
118
+ pip install -e .
119
+ ```
120
+
121
+ ### SSE transport (advanced)
122
+
123
+ For running as a persistent background server instead of stdio:
124
+
125
+ ```bash
126
+ zikkaron --transport sse
127
+ ```
128
+
129
+ Then configure Claude Code to connect via URL:
130
+
131
+ ```json
132
+ {
133
+ "mcpServers": {
134
+ "zikkaron": {
135
+ "type": "sse",
136
+ "url": "http://127.0.0.1:8742/sse"
137
+ }
138
+ }
139
+ }
140
+ ```
141
+
142
+ Default port: `8742`. Override with `--port`. Database defaults to `~/.zikkaron/memory.db`, override with `--db-path`.
143
+
144
+ ## Configuration
145
+
146
+ All settings are configurable via environment variables with the `ZIKKARON_` prefix:
147
+
148
+ | Variable | Default | Description |
149
+ |---|---|---|
150
+ | `ZIKKARON_PORT` | `8742` | Server port |
151
+ | `ZIKKARON_DB_PATH` | `~/.zikkaron/memory.db` | Database location |
152
+ | `ZIKKARON_EMBEDDING_MODEL` | `all-MiniLM-L6-v2` | Sentence-transformer model |
153
+ | `ZIKKARON_DECAY_FACTOR` | `0.95` | Base heat decay per consolidation cycle |
154
+ | `ZIKKARON_COLD_THRESHOLD` | `0.05` | Heat below which memories are candidates for archival |
155
+ | `ZIKKARON_WRITE_GATE_THRESHOLD` | `0.4` | Minimum surprisal to pass the predictive coding write gate |
156
+ | `ZIKKARON_HOPFIELD_BETA` | `8.0` | Hopfield network sharpness parameter |
157
+ | `ZIKKARON_SR_DISCOUNT` | `0.9` | Successor representation discount factor |
158
+ | `ZIKKARON_COGNITIVE_LOAD_LIMIT` | `4` | Maximum chunks in active context (Cowan's 4 +/- 1) |
159
+
160
+ See `zikkaron/config.py` for the full list.
161
+
162
+ ## Testing
163
+
164
+ ```bash
165
+ python -m pytest zikkaron/tests/ -x -q
166
+ ```
167
+
168
+ 891 tests across 33 test files covering all subsystems.
169
+
170
+ ## Dependencies
171
+
172
+ - **mcp** — Model Context Protocol SDK
173
+ - **sentence-transformers** — Local embedding generation
174
+ - **sqlite-vec** — Vector similarity search extension for SQLite
175
+ - **networkx** — Graph algorithms for knowledge graph and causal discovery
176
+ - **numpy** — Numerical operations for Hopfield networks, HDC, and SR
177
+ - **fastapi / uvicorn / sse-starlette** — HTTP server and SSE transport
178
+ - **pydantic** — Data validation and settings management
179
+ - **watchdog** — File system change detection
180
+
181
+ ## References
182
+
183
+ The implementation draws on ideas from the following work:
184
+
185
+ - Ramsauer et al. "Hopfield Networks is All You Need" (ICLR 2021, arXiv:2008.02217)
186
+ - Nader, Schafe, LeDoux. "Fear memories require protein synthesis in the amygdala for reconsolidation after retrieval" (Nature 406, 2000)
187
+ - Osan, Tort, Bhatt, Bhatt, Bhatt, Amaral. "Three outcomes of reconsolidation" (PLoS ONE, 2011)
188
+ - McClelland, McNaughton, O'Reilly. "Why there are complementary learning systems in the hippocampus and neocortex" (Psych. Review 102, 1995)
189
+ - Sun et al. "Organizing memories for generalization in complementary learning systems" (Nature Neuroscience 26, 2023)
190
+ - Stachenfeld, Botvinick, Gershman. "The hippocampus as a predictive map" (Nature Neuroscience 20, 2017)
191
+ - Whittington et al. "The Tolman-Eichenbaum Machine" (Cell 183, 2020)
192
+ - Spirtes, Glymour, Scheines. *Causation, Prediction, and Search* (MIT Press, 2000)
193
+ - Kanerva. *Sparse Distributed Memory* (MIT Press, 1988)
194
+ - Frady, Kleyko, Sommer. "Variable Binding for Sparse Distributed Representations" (IEEE TNNLS, 2022)
195
+ - Toth et al. "Optimal forgetting via rate-distortion theory" (PLoS Computational Biology, 2020)
196
+ - Josselyn, Frankland. "Memory allocation: mechanisms and function" (Annual Review Neuroscience 41, 2018)
197
+ - Rashid et al. "Competition between engrams influences fear memory formation and recall" (Science 353, 2016)
198
+ - Zhou et al. "MetaRAG: Metacognitive Retrieval-Augmented Generation" (ACM Web, 2024)
199
+
200
+ ## License
201
+
202
+ MIT
@@ -0,0 +1,62 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "zikkaron"
7
+ version = "0.1.0"
8
+ description = "Biologically-inspired persistent memory engine for Claude Code"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.11"
12
+ authors = [
13
+ { name = "amanhij" },
14
+ ]
15
+ keywords = [
16
+ "mcp",
17
+ "claude",
18
+ "memory",
19
+ "persistent-memory",
20
+ "cognitive-architecture",
21
+ "hopfield-networks",
22
+ "knowledge-graph",
23
+ "neuroscience",
24
+ ]
25
+ classifiers = [
26
+ "Development Status :: 4 - Beta",
27
+ "Intended Audience :: Developers",
28
+ "License :: OSI Approved :: MIT License",
29
+ "Programming Language :: Python :: 3",
30
+ "Programming Language :: Python :: 3.11",
31
+ "Programming Language :: Python :: 3.12",
32
+ "Programming Language :: Python :: 3.13",
33
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
34
+ "Topic :: Software Development :: Libraries",
35
+ ]
36
+ dependencies = [
37
+ "fastapi>=0.104.0",
38
+ "sse-starlette>=1.6.0",
39
+ "uvicorn>=0.24.0",
40
+ "mcp>=1.0.0",
41
+ "sentence-transformers>=2.2.0",
42
+ "watchdog>=3.0.0",
43
+ "pydantic>=2.5.0",
44
+ "pydantic-settings>=2.0.0",
45
+ "numpy>=1.24.0",
46
+ "sqlite-vec>=0.1.6",
47
+ "networkx>=3.0",
48
+ ]
49
+
50
+ [project.scripts]
51
+ zikkaron = "zikkaron.__main__:cli"
52
+
53
+ [project.urls]
54
+ Homepage = "https://github.com/amanhij/Zikkaron"
55
+ Repository = "https://github.com/amanhij/Zikkaron"
56
+ Issues = "https://github.com/amanhij/Zikkaron/issues"
57
+
58
+ [tool.hatch.build.targets.wheel]
59
+ packages = ["zikkaron"]
60
+
61
+ [tool.pytest.ini_options]
62
+ testpaths = ["zikkaron/tests"]
@@ -0,0 +1,10 @@
1
+ fastapi>=0.104.0
2
+ sse-starlette>=1.6.0
3
+ uvicorn>=0.24.0
4
+ mcp>=1.0.0
5
+ sentence-transformers>=2.2.0
6
+ watchdog>=3.0.0
7
+ pydantic>=2.5.0
8
+ numpy>=1.24.0
9
+ sqlite-vec>=0.1.6
10
+ networkx>=3.0
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,71 @@
1
+ """Entry point for python -m zikkaron."""
2
+
3
+ import argparse
4
+
5
+ from zikkaron import __version__
6
+ from zikkaron.server import main
7
+
8
+ VALID_TRANSPORTS = ("stdio", "sse", "streamable-http")
9
+
10
+ STARTUP_BANNER = f"""\
11
+ === Zikkaron v{__version__} ===
12
+ Biologically-inspired persistent memory engine for Claude Code
13
+
14
+ Active modules:
15
+ * StorageEngine (SQLite WAL + FTS5 + sqlite-vec)
16
+ * EmbeddingEngine (sentence-transformers)
17
+ * SensoryBuffer (episode capture)
18
+ * MemoryThermodynamics (surprise, importance, valence, decay)
19
+ * KnowledgeGraph (typed relationships, causal detection)
20
+ * HippoRetriever (PPR + vector + FTS5 + spreading activation + fractal)
21
+ * MemoryCurator (merge/link/create, contradiction, memify)
22
+ * AstrocyteEngine (background consolidation daemon)
23
+ * AstrocytePool (domain-aware processes: code/decisions/errors/deps)
24
+ * SleepComputeEngine (dream replay, compression, community detection)
25
+ * FractalMemoryTree (hierarchical multi-scale retrieval)
26
+ * ProspectiveMemory (future-oriented triggers)
27
+ * NarrativeEngine (autobiographical project stories)
28
+ * StalenessDetector (file-change watchdog)
29
+
30
+ MCP Tools: remember, recall, forget, validate_memory, get_project_context,
31
+ consolidate_now, memory_stats, rate_memory, recall_hierarchical,
32
+ drill_down, create_trigger, get_project_story
33
+
34
+ MCP Resources: memory://stats, memory://hot, memory://stale,
35
+ memory://processes, memory://narrative/{{directory}}
36
+ """
37
+
38
+
39
+ def cli():
40
+ parser = argparse.ArgumentParser(description="Zikkaron memory engine MCP server")
41
+ parser.add_argument("--port", type=int, default=None, help="Server port (default: 8742)")
42
+ parser.add_argument("--db-path", type=str, default=None, help="SQLite database path")
43
+ parser.add_argument(
44
+ "--transport",
45
+ type=str,
46
+ default="stdio",
47
+ choices=VALID_TRANSPORTS,
48
+ help="MCP transport protocol (default: stdio)",
49
+ )
50
+ parser.add_argument(
51
+ "--quiet",
52
+ action="store_true",
53
+ help="Suppress startup banner",
54
+ )
55
+ args = parser.parse_args()
56
+
57
+ if not args.quiet and args.transport != "stdio":
58
+ import sys as _sys
59
+ print(STARTUP_BANNER, file=_sys.stderr)
60
+ print(f"Transport: {args.transport}", file=_sys.stderr)
61
+ if args.port:
62
+ print(f"Port: {args.port}", file=_sys.stderr)
63
+ if args.db_path:
64
+ print(f"Database: {args.db_path}", file=_sys.stderr)
65
+ print(file=_sys.stderr)
66
+
67
+ main(port=args.port, db_path=args.db_path, transport=args.transport)
68
+
69
+
70
+ if __name__ == "__main__":
71
+ cli()