spine-memory 0.2.0__tar.gz → 0.2.2__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 (27) hide show
  1. {spine_memory-0.2.0/spine_memory.egg-info → spine_memory-0.2.2}/PKG-INFO +332 -319
  2. {spine_memory-0.2.0 → spine_memory-0.2.2}/README.md +4 -3
  3. {spine_memory-0.2.0 → spine_memory-0.2.2}/pyproject.toml +15 -1
  4. {spine_memory-0.2.0 → spine_memory-0.2.2}/setup.cfg +4 -4
  5. {spine_memory-0.2.0 → spine_memory-0.2.2/spine_memory.egg-info}/PKG-INFO +332 -319
  6. {spine_memory-0.2.0 → spine_memory-0.2.2}/spine_memory.egg-info/SOURCES.txt +1 -0
  7. spine_memory-0.2.2/tests/test_smoke.py +200 -0
  8. spine_memory-0.2.2/tools/_critic_check.py +183 -0
  9. {spine_memory-0.2.0 → spine_memory-0.2.2}/tools/_node_io.py +69 -2
  10. {spine_memory-0.2.0 → spine_memory-0.2.2}/tools/_quality_audit.py +7 -7
  11. {spine_memory-0.2.0 → spine_memory-0.2.2}/tools/_wander.py +3 -2
  12. {spine_memory-0.2.0 → spine_memory-0.2.2}/tools/cli.py +4 -2
  13. {spine_memory-0.2.0 → spine_memory-0.2.2}/tools/mcp_server.py +8 -7
  14. {spine_memory-0.2.0 → spine_memory-0.2.2}/tools/night_daemon.py +25 -31
  15. {spine_memory-0.2.0 → spine_memory-0.2.2}/tools/spine_preflight.py +3 -3
  16. spine_memory-0.2.0/tests/test_smoke.py +0 -96
  17. {spine_memory-0.2.0 → spine_memory-0.2.2}/LICENSE +0 -0
  18. {spine_memory-0.2.0 → spine_memory-0.2.2}/spine_memory.egg-info/dependency_links.txt +0 -0
  19. {spine_memory-0.2.0 → spine_memory-0.2.2}/spine_memory.egg-info/entry_points.txt +0 -0
  20. {spine_memory-0.2.0 → spine_memory-0.2.2}/spine_memory.egg-info/requires.txt +0 -0
  21. {spine_memory-0.2.0 → spine_memory-0.2.2}/spine_memory.egg-info/top_level.txt +0 -0
  22. {spine_memory-0.2.0 → spine_memory-0.2.2}/tools/_build_index.py +0 -0
  23. {spine_memory-0.2.0 → spine_memory-0.2.2}/tools/_check_anchors.py +0 -0
  24. {spine_memory-0.2.0 → spine_memory-0.2.2}/tools/_crosslink.py +0 -0
  25. {spine_memory-0.2.0 → spine_memory-0.2.2}/tools/_embed_links.py +0 -0
  26. {spine_memory-0.2.0 → spine_memory-0.2.2}/tools/_git_hook.py +0 -0
  27. {spine_memory-0.2.0 → spine_memory-0.2.2}/tools/benchmark_tokens.py +0 -0
@@ -1,319 +1,332 @@
1
- Metadata-Version: 2.4
2
- Name: spine-memory
3
- Version: 0.2.0
4
- Summary: Hierarchical Markdown/YAML graph memory for long-horizon AI agents — git-native, zero-token CI guardrails, no vector DB.
5
- License-Expression: MIT
6
- Keywords: memory,llm,ai-agent,markdown,knowledge-graph,mcp,provenance
7
- Classifier: Development Status :: 4 - Beta
8
- Classifier: Intended Audience :: Developers
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: Topic :: Software Development :: Libraries
11
- Requires-Python: >=3.9
12
- Description-Content-Type: text/markdown
13
- License-File: LICENSE
14
- Provides-Extra: mcp
15
- Requires-Dist: fastmcp>=2.0.0; extra == "mcp"
16
- Provides-Extra: tokens
17
- Requires-Dist: tiktoken>=0.7.0; extra == "tokens"
18
- Provides-Extra: dev
19
- Requires-Dist: fastmcp>=2.0.0; extra == "dev"
20
- Requires-Dist: tiktoken>=0.7.0; extra == "dev"
21
- Dynamic: license-file
22
-
23
- # SPINE: Hierarchical Graph Memory for Long-Horizon AI Agents
24
-
25
- > Read this in: [English](README.md) · [Русский](README_RU.md)
26
-
27
- ![CI](https://github.com/Scrimal/SPINE-Memory/actions/workflows/ci.yml/badge.svg)
28
-
29
- **SPINE** is a lightweight Markdown- and YAML-based cognitive memory framework
30
- that gives LLM agents persistent, scalable, low-latency long-term memory without
31
- heavy vector-database overhead.
32
-
33
- Battle-tested on a real-world personal knowledge graph of **532 structured memory
34
- nodes (~2.6M+ chars indexed)** and **460+ typed semantic links**, with schema
35
- integrity enforced by deterministic, zero-token CI checks.
36
-
37
- > Your IDE remembers **WHAT** is in the file. SPINE remembers **WHY** it's there — with receipts.
38
-
39
- ---
40
-
41
- ## SPINE in 60 seconds
42
-
43
- **Dev / IDE.** Your coding agent spots a `sleep(200)` in a retry loop and reaches
44
- to "clean it up". It runs `git blame`, finds the commit, then asks SPINE. SPINE
45
- returns a post-mortem node: *"2026-03 rate-limit incident — the API returns 429
46
- if we retry faster than 200 ms."* The agent leaves the line alone. No 3 AM page.
47
-
48
- **Long-horizon agent.** An agent running 500+ sessions across months, with 2.6M+
49
- chars of accumulated context, needs a decision from three months ago. It walks
50
- the funnel — `impulse` (2 lines) → `summary` (5 sentences) → `cleaned_data` →
51
- `source_base` — spending ~60 tokens on the first hop instead of loading the whole
52
- corpus. Marginal cost: **~$0.01/node**.
53
-
54
- ---
55
-
56
- ## The Problem
57
-
58
- Standard flat RAG degrades as a knowledge base grows past a few hundred documents:
59
-
60
- - **Context bloat & token cost** — full raw chunks exhaust context windows with
61
- logs, formatting noise, and boilerplate.
62
- - **Loss of causality & chronology** — vector similarity misses temporal order
63
- (`roots -> after`) and high-level thematic grouping.
64
- - **Destructive compression** — summarization discards original data, blocking
65
- forensic lookups and future fine-tuning.
66
- - **Memory rot & hallucination** — without periodic consolidation and schema
67
- validation, agent memory accumulates noise.
68
-
69
- ---
70
-
71
- ## Core Architecture
72
-
73
- SPINE organizes memory into a **3-tier cognitive topology** modeled after
74
- biological neural organization:
75
-
76
- ```
77
- [ Tier 1: Domains — macro-areas ]
78
- │
79
- ▼
80
- [ Tier 2: Constellations — thematic clusters, 5–20 nodes ]
81
- │
82
- ▼
83
- [ Tier 3: SPINE Nodes — atomic memory units, ~5k chars each ]
84
- ```
85
-
86
- ### Key mechanisms
87
-
88
- 1. **Deterministic ingestion & chunking.** Raw logs are pre-processed by
89
- deterministic Python scripts into ~5,000-char Markdown chunks *before* touching
90
- an LLM — cutting ingestion token cost and semantic load.
91
- 2. **Multi-layer progressive disclosure** (`Constellation` → `Impulse` →
92
- `Summary` → `Cleaned` → `Raw`). The agent walks a relevance funnel instead of
93
- loading raw chunks upfront:
94
- - **Routing & scent** — filter by domain/constellation, scan 1–2-line
95
- **impulses** and **anchors** inside candidate clusters.
96
- - **Synthesis** — read the 3–5-sentence **summary** to confirm relevance.
97
- - **Precision context** — load artifact-free **cleaned data**.
98
- - **Lossless basement** — preserve the untouched original in **source_base**
99
- (≥70% byte ratio) for forensic drill-down and future LoRA/QLoRA fine-tuning.
100
- 3. **Multi-dimensional navigation & Hebbian salience.**
101
- - Chronological chains: `roots` → `after` with typed relations
102
- (`:continuation`, `:genesis`, `:contrast`, …).
103
- - Typed `semantic_links` + a compiled `reverse_index.json` for bidirectional
104
- traversal without mutating existing YAML.
105
- - `strategic_weight` (0.0–1.0), `access_count`, `last_accessed` keep active
106
- memories hot while dormant ones cool without dead links.
107
- 4. **Zero-token deterministic guardrails.** `_critic_check.sh` and
108
- `_quality_audit.py` enforce structure, length caps (`IMPULSE <= 2 lines`,
109
- `SUMMARY <= 5 sentences`), anchor canon compliance, and `SOURCE_BASE >= 70%`
110
- byte retention via instant bash/Python checks — no LLM-vs-LLM critic loops.
111
- 5. **Hybrid compute routing.** Designed for constrained edge hardware: local
112
- embeddings on a Linux GPU, lightweight API models for routine extraction,
113
- frontier models reserved strictly for deep synthesis.
114
-
115
- ---
116
-
117
- ## Dev Overlay: memory *around* code
118
-
119
- SPINE is not a symbol index — LSP, Tree-sitter and `ripgrep` already own that.
120
- SPINE stores **intent**: why a decision was made, what broke, what traps exist.
121
- One node type, four kinds, bound to code with a pointer to Git (not a copy of
122
- the source):
123
-
124
- ```yaml
125
- kind: adr | postmortem | gotcha | contract
126
- repo_ref: {path, commit, lines}
127
- code_refs: ["src/auth/jwt.py::verify_token@a1b2c3d"]
128
- status: active | superseded | historical # facts don't decay, they get superseded
129
- ```
130
-
131
- Dev tools:
132
-
133
- - `spine_for_file(filepath)` — ADR / post-mortem / gotcha for a code file
134
- - `spine_preflight --files ...` — what you might break *before* you change it
135
- - `_git_hook.py --kind ...` — scaffold a memory node from a merged PR
136
- (memory fills itself as a byproduct of normal work)
137
-
138
- ---
139
-
140
- ## Graph scale & metrics
141
-
142
- | Metric | Value |
143
- | :--- | :--- |
144
- | Production graph scale | 532 nodes (~2.6M+ chars indexed) |
145
- | Typed semantic links | 460+ edges |
146
- | Embedding links | 1496 (top-5, threshold 0.88) |
147
- | YAML validity — production | 100% (532/532), enforced by `critic_check` |
148
- | YAML validity — demo corpus | 100% (3/3 PASS) |
149
- | Chunk granularity | ~5,000 chars |
150
- | Retrieval strategy | progressive disclosure |
151
-
152
- ---
153
-
154
- ## Human-Readable & Obsidian-Ready
155
-
156
- Memory is plain Markdown in Git — open it in Obsidian, `grep` it, `diff` it,
157
- read it with your own eyes. No black box, no "trust me, the vector said so".
158
-
159
- ![SPINE graph rendered in Obsidian](assets/graph_dark.png)
160
-
161
- ---
162
-
163
- ## Batch Ingestion & Staging Workflow
164
-
165
- ```mermaid
166
- flowchart LR
167
- A[Raw Chunk] --> B[Temp Staging]
168
- B --> C{Zero-Token Critic}
169
- C -- PASS --> D[Atomic Commit]
170
- C -- FAIL --> B
171
- D --> E[Context Compaction<br/>every 5 nodes]
172
- E --> F[Next Chunk]
173
- ```
174
-
175
- The agent writes each node draft into a temporary buffer (`TEMP`), runs
176
- `_critic_check.sh` on it, resolves boundary cases on its own with bounded
177
- discretion (e.g. a short source chunk, or a decimal point miscounted as a
178
- sentence terminator) without looping in self-criticism, and only then atomically
179
- commits the valid node into the production graph. Every 5 nodes the heavy
180
- context is compacted into lightweight snapshots.
181
-
182
- This staging discipline enables ingesting **40+ raw nodes in a row (500k+
183
- tokens)** in a single session without degradation, at a marginal cost of
184
- **~$0.01/node** (deterministic validation is token-free; only the final write
185
- consumes model tokens).
186
-
187
- ---
188
-
189
- ## Repository structure
190
-
191
- ```
192
- .
193
- ├── pyproject.toml # pip package (zero required deps)
194
- ├── README.md
195
- ├── README_RU.md
196
- ├── SKILL.md # agent skill (Pi, Claude Code, Cursor)
197
- ├── requirements.txt # optional deps (fastmcp, tiktoken)
198
- ├── assets/
199
- │ └── graph_dark.png # Obsidian graph screenshot
200
- ├── methodology/
201
- │ ├── SPINE_METHODOLOGY.md # format spec (RU)
202
- │ └── SPINE_METHODOLOGY_EN.md # format spec (EN)
203
- ├── raw/
204
- │ ├── U001.md # raw chunk #1
205
- │ ├── U002.md # raw chunk #2
206
- │ └── U003.md # raw chunk #3
207
- ├── nodes/
208
- │ ├── KEDR_001.md # processed node (domain «Связь»)
209
- │ ├── KEDR_002.md # processed node (domain «Карта»)
210
- │ └── KEDR_003.md # processed node (domain «Тайны_Груза»)
211
- ├── anchors/
212
- │ └── anchor_dump.json # anchor canon for the demo graph
213
- └── tools/ # validation & traversal utilities
214
- ├── cli.py # spine CLI entry point
215
- ├── _node_io.py # canonical node reader/writer
216
- ├── _critic_check.sh
217
- ├── _check_anchors.py
218
- ├── _crosslink.py
219
- ├── _wander.py
220
- ├── _quality_audit.py
221
- ├── _build_index.py # rebuild reverse_index + anchor canon
222
- ├── _embed_links.py # import precomputed embedding links
223
- ├── spine_preflight.py # context radar for changed files
224
- ├── _git_hook.py # PR -> node scaffold
225
- ├── night_daemon.py # nightly consolidation + self-audit
226
- ├── mcp_server.py # MCP server (FastMCP)
227
- └── benchmark_tokens.py # token savings benchmark
228
- ```
229
-
230
- The demo corpus (`KEDR_001..003`) is written in **Russian** to verify Cyrillic
231
- tokenization and semantic anchors. All tools and the schema are
232
- language-agnostic.
233
-
234
- Raw chunks are named `U<number>.md` and paired with `nodes/<ID>.md` by the
235
- trailing number (`U001` ↔ `KEDR_001`).
236
-
237
- ---
238
-
239
- ## Quickstart
240
-
241
- Install and try it in 60 seconds:
242
-
243
- ```bash
244
- pip install spine-memory # core (zero required deps)
245
- pip install spine-memory[mcp] # + MCP server (fastmcp)
246
-
247
- spine init --preset dev # scaffold .spine/ inside your repo
248
- spine index # rebuild reverse_index.json
249
- spine wander --from ADR_001 # walk the graph
250
- spine mcp # start the MCP server
251
- ```
252
-
253
- Or run directly from a checkout (no install):
254
-
255
- ```bash
256
- # 1. Auto-audit nodes (clean PASS expected)
257
- bash tools/_critic_check.sh nodes raw anchors/anchor_dump.json
258
-
259
- # 2. Validate anchors against the canon
260
- python tools/_check_anchors.py nodes/KEDR_001.md --dump anchors/anchor_dump.json --quiet
261
-
262
- # 3. Walk the graph (forward and backlinks)
263
- python tools/_wander.py --from KEDR_001 --hops 2 --folder nodes
264
-
265
- # 4. Global quality audit
266
- python tools/_quality_audit.py --nodes nodes --raw raw
267
-
268
- # 5. Crosslink generation (dry run / apply)
269
- python tools/_crosslink.py --folder nodes
270
- python tools/_crosslink.py --folder nodes --apply
271
-
272
- # 6. MCP server (stdio, for Claude Desktop / Cursor / Windsurf)
273
- pip install -r requirements.txt
274
- python tools/mcp_server.py
275
-
276
- # 7. Token savings benchmark
277
- python tools/benchmark_tokens.py
278
-
279
- # 8. Rebuild reverse index + refresh anchor canon
280
- python tools/_build_index.py
281
-
282
- # 9. Nightly consolidation + self-audit
283
- python tools/night_daemon.py --folder nodes
284
-
285
- # 10. Import precomputed embedding links (from an external GPU worker)
286
- python tools/_embed_links.py --input embed_links.json --folder nodes
287
- ```
288
-
289
- ---
290
-
291
- ## Node format (v2.1)
292
-
293
- ```
294
- --- # YAML frontmatter
295
- id: KEDR_001
296
- type: spine_node
297
- domain: Связь
298
- hub: "[[Кедр_Связь]]"
299
- constellation: Кедр-9 Expedition
300
- vectors:
301
- - "связь::трёхслойный_архив" # comment required
302
- search_anchors:
303
- - трёхслойный_архив
304
- chronology:
305
- roots: "[[U001]]"
306
- after: "[[KEDR_002]]:continuation"
307
- semantic_links:
308
- - "[[KEDR_002]]::продолжение"
309
- ---
310
-
311
- # IMPULSE — 1–2 lines
312
- # SUMMARY — 3–5 sentences
313
- # CLEANED_DATA — ~25 lines of facts
314
- # IMPACT — strategic_weight + key_insight
315
- # SOURCE_BASE — ≥70% of the raw source
316
- ---
317
- ```
318
-
319
- Full specification: `methodology/SPINE_METHODOLOGY_EN.md` (RU: `methodology/SPINE_METHODOLOGY.md`).
1
+ Metadata-Version: 2.4
2
+ Name: spine-memory
3
+ Version: 0.2.2
4
+ Summary: Hierarchical Markdown/YAML graph memory for long-horizon AI agents — git-native, zero-token CI guardrails, no vector DB.
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://github.com/Scrimal/SPINE-Memory
7
+ Project-URL: Repository, https://github.com/Scrimal/SPINE-Memory
8
+ Project-URL: Documentation, https://github.com/Scrimal/SPINE-Memory/blob/main/methodology/SPINE_METHODOLOGY_EN.md
9
+ Project-URL: Issues, https://github.com/Scrimal/SPINE-Memory/issues
10
+ Project-URL: Changelog, https://github.com/Scrimal/SPINE-Memory/blob/main/CHANGELOG.md
11
+ Keywords: memory,llm,ai-agent,markdown,knowledge-graph,mcp,provenance
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Libraries
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.9
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Provides-Extra: mcp
27
+ Requires-Dist: fastmcp>=2.0.0; extra == "mcp"
28
+ Provides-Extra: tokens
29
+ Requires-Dist: tiktoken>=0.7.0; extra == "tokens"
30
+ Provides-Extra: dev
31
+ Requires-Dist: fastmcp>=2.0.0; extra == "dev"
32
+ Requires-Dist: tiktoken>=0.7.0; extra == "dev"
33
+ Dynamic: license-file
34
+
35
+ # SPINE: Hierarchical Graph Memory for Long-Horizon AI Agents
36
+
37
+ > Read this in: [English](README.md) · [Русский](README_RU.md)
38
+
39
+ ![CI](https://github.com/Scrimal/SPINE-Memory/actions/workflows/ci.yml/badge.svg)
40
+
41
+ **SPINE** is a lightweight Markdown- and YAML-based cognitive memory framework
42
+ that gives LLM agents persistent, scalable, low-latency long-term memory without
43
+ heavy vector-database overhead.
44
+
45
+ Battle-tested on a real-world personal knowledge graph of **532 structured memory
46
+ nodes (~2.6M+ chars indexed)** and **460+ typed semantic links**, with schema
47
+ integrity enforced by deterministic, zero-token CI checks.
48
+
49
+ > Your IDE remembers **WHAT** is in the file. SPINE remembers **WHY** it's there — with receipts.
50
+
51
+ ---
52
+
53
+ ## SPINE in 60 seconds
54
+
55
+ **Dev / IDE.** Your coding agent spots a `sleep(200)` in a retry loop and reaches
56
+ to "clean it up". It runs `git blame`, finds the commit, then asks SPINE. SPINE
57
+ returns a post-mortem node: *"2026-03 rate-limit incident — the API returns 429
58
+ if we retry faster than 200 ms."* The agent leaves the line alone. No 3 AM page.
59
+
60
+ **Long-horizon agent.** An agent running 500+ sessions across months, with 2.6M+
61
+ chars of accumulated context, needs a decision from three months ago. It walks
62
+ the funnel — `impulse` (2 lines) → `summary` (5 sentences) → `cleaned_data` →
63
+ `source_base` — spending ~60 tokens on the first hop instead of loading the whole
64
+ corpus. Marginal cost: **~$0.01/node**.
65
+
66
+ ---
67
+
68
+ ## The Problem
69
+
70
+ Standard flat RAG degrades as a knowledge base grows past a few hundred documents:
71
+
72
+ - **Context bloat & token cost** — full raw chunks exhaust context windows with
73
+ logs, formatting noise, and boilerplate.
74
+ - **Loss of causality & chronology** — vector similarity misses temporal order
75
+ (`roots -> after`) and high-level thematic grouping.
76
+ - **Destructive compression** — summarization discards original data, blocking
77
+ forensic lookups and future fine-tuning.
78
+ - **Memory rot & hallucination** — without periodic consolidation and schema
79
+ validation, agent memory accumulates noise.
80
+
81
+ ---
82
+
83
+ ## Core Architecture
84
+
85
+ SPINE organizes memory into a **3-tier cognitive topology** modeled after
86
+ biological neural organization:
87
+
88
+ ```
89
+ [ Tier 1: Domains — macro-areas ]
90
+ │
91
+ ▼
92
+ [ Tier 2: Constellations — thematic clusters, 5–20 nodes ]
93
+ │
94
+ ▼
95
+ [ Tier 3: SPINE Nodes — atomic memory units, ~5k chars each ]
96
+ ```
97
+
98
+ ### Key mechanisms
99
+
100
+ 1. **Deterministic ingestion & chunking.** Raw logs are pre-processed by
101
+ deterministic Python scripts into ~5,000-char Markdown chunks *before* touching
102
+ an LLM — cutting ingestion token cost and semantic load.
103
+ 2. **Multi-layer progressive disclosure** (`Constellation` → `Impulse` →
104
+ `Summary` → `Cleaned` → `Raw`). The agent walks a relevance funnel instead of
105
+ loading raw chunks upfront:
106
+ - **Routing & scent** — filter by domain/constellation, scan 1–2-line
107
+ **impulses** and **anchors** inside candidate clusters.
108
+ - **Synthesis** — read the 3–5-sentence **summary** to confirm relevance.
109
+ - **Precision context** — load artifact-free **cleaned data**.
110
+ - **Lossless basement** — preserve the untouched original in **source_base**
111
+ (≥70% byte ratio) for forensic drill-down and future LoRA/QLoRA fine-tuning.
112
+ 3. **Multi-dimensional navigation & Hebbian salience.**
113
+ - Chronological chains: `roots` → `after` with typed relations
114
+ (`:continuation`, `:genesis`, `:contrast`, …).
115
+ - Typed `semantic_links` + a compiled `reverse_index.json` for bidirectional
116
+ traversal without mutating existing YAML.
117
+ - `strategic_weight` (0.0–1.0), `access_count`, `last_accessed` keep active
118
+ memories hot while dormant ones cool without dead links.
119
+ 4. **Zero-token deterministic guardrails.** `_critic_check.sh` and
120
+ `_quality_audit.py` enforce structure, length caps (`IMPULSE <= 2 lines`,
121
+ `SUMMARY <= 5 sentences`), anchor canon compliance, and `SOURCE_BASE >= 70%`
122
+ byte retention via instant bash/Python checks — no LLM-vs-LLM critic loops.
123
+ 5. **Hybrid compute routing.** Designed for constrained edge hardware: local
124
+ embeddings on a Linux GPU, lightweight API models for routine extraction,
125
+ frontier models reserved strictly for deep synthesis.
126
+
127
+ ---
128
+
129
+ ## Dev Overlay: memory *around* code
130
+
131
+ SPINE is not a symbol index — LSP, Tree-sitter and `ripgrep` already own that.
132
+ SPINE stores **intent**: why a decision was made, what broke, what traps exist.
133
+ One node type, four kinds, bound to code with a pointer to Git (not a copy of
134
+ the source):
135
+
136
+ ```yaml
137
+ kind: adr | postmortem | gotcha | contract
138
+ repo_ref: {path, commit, lines}
139
+ code_refs: ["src/auth/jwt.py::verify_token@a1b2c3d"]
140
+ status: active | superseded | historical # facts don't decay, they get superseded
141
+ ```
142
+
143
+ Dev tools:
144
+
145
+ - `spine_for_file(filepath)` — ADR / post-mortem / gotcha for a code file
146
+ - `spine_preflight --files ...` — what you might break *before* you change it
147
+ - `_git_hook.py --kind ...` — scaffold a memory node from a merged PR
148
+ (memory fills itself as a byproduct of normal work)
149
+
150
+ ---
151
+
152
+ ## Graph scale & metrics
153
+
154
+ | Metric | Value |
155
+ | :--- | :--- |
156
+ | Production graph scale | 532 nodes (~2.6M+ chars indexed) |
157
+ | Typed semantic links | 460+ edges |
158
+ | Embedding links | 1496 (top-5, threshold 0.88) |
159
+ | YAML validity — production | 100% (532/532), enforced by `critic_check` |
160
+ | YAML validity — demo corpus | 100% (6/6 PASS) |
161
+ | Chunk granularity | ~5,000 chars |
162
+ | Retrieval strategy | progressive disclosure |
163
+
164
+ ---
165
+
166
+ ## Human-Readable & Obsidian-Ready
167
+
168
+ Memory is plain Markdown in Git — open it in Obsidian, `grep` it, `diff` it,
169
+ read it with your own eyes. No black box, no "trust me, the vector said so".
170
+
171
+ ![SPINE graph rendered in Obsidian](assets/graph_dark.png)
172
+
173
+ ---
174
+
175
+ ## Batch Ingestion & Staging Workflow
176
+
177
+ ```mermaid
178
+ flowchart LR
179
+ A[Raw Chunk] --> B[Temp Staging]
180
+ B --> C{Zero-Token Critic}
181
+ C -- PASS --> D[Atomic Commit]
182
+ C -- FAIL --> B
183
+ D --> E[Context Compaction<br/>every 5 nodes]
184
+ E --> F[Next Chunk]
185
+ ```
186
+
187
+ The agent writes each node draft into a temporary buffer (`TEMP`), runs
188
+ `_critic_check.sh` on it, resolves boundary cases on its own with bounded
189
+ discretion (e.g. a short source chunk, or a decimal point miscounted as a
190
+ sentence terminator) without looping in self-criticism, and only then atomically
191
+ commits the valid node into the production graph. Every 5 nodes the heavy
192
+ context is compacted into lightweight snapshots.
193
+
194
+ This staging discipline enables ingesting **40+ raw nodes in a row (500k+
195
+ tokens)** in a single session without degradation, at a marginal cost of
196
+ **~$0.01/node** (deterministic validation is token-free; only the final write
197
+ consumes model tokens).
198
+
199
+ ---
200
+
201
+ ## Repository structure
202
+
203
+ ```
204
+ .
205
+ ├── pyproject.toml # pip package (zero required deps)
206
+ ├── README.md
207
+ ├── README_RU.md
208
+ ├── SKILL.md # agent skill (Pi, Claude Code, Cursor)
209
+ ├── requirements.txt # optional deps (fastmcp, tiktoken)
210
+ ├── assets/
211
+ │ └── graph_dark.png # Obsidian graph screenshot
212
+ ├── methodology/
213
+ │ ├── SPINE_METHODOLOGY.md # format spec (RU)
214
+ │ └── SPINE_METHODOLOGY_EN.md # format spec (EN)
215
+ ├── raw/
216
+ │ ├── U001.md # raw chunk #1
217
+ │ ├── U002.md # raw chunk #2
218
+ │ └── U003.md # raw chunk #3
219
+ ├── nodes/
220
+ │ ├── KEDR_001.md # processed node (domain «Связь»)
221
+ │ ├── KEDR_002.md # processed node (domain «Карта»)
222
+ │ └── KEDR_003.md # processed node (domain «Тайны_Груза»)
223
+ ├── anchors/
224
+ │ └── anchor_dump.json # anchor canon for the demo graph
225
+ └── tools/ # validation & traversal utilities
226
+ ├── cli.py # spine CLI entry point
227
+ ├── _node_io.py # canonical node reader/writer
228
+ ├── _critic_check.sh
229
+ ├── _check_anchors.py
230
+ ├── _crosslink.py
231
+ ├── _wander.py
232
+ ├── _quality_audit.py
233
+ ├── _build_index.py # rebuild reverse_index + anchor canon
234
+ ├── _embed_links.py # import precomputed embedding links
235
+ ├── spine_preflight.py # context radar for changed files
236
+ ├── _git_hook.py # PR -> node scaffold
237
+ ├── night_daemon.py # nightly consolidation + self-audit
238
+ ├── mcp_server.py # MCP server (FastMCP)
239
+ └── benchmark_tokens.py # token savings benchmark
240
+ ```
241
+
242
+ The demo corpus (`KEDR_001..006`) is written in **Russian** to verify Cyrillic
243
+ tokenization and semantic anchors. All tools and the schema are
244
+ language-agnostic. The full story is told as a longread in
245
+ [`docs/longread.md`](docs/longread.md) — each chapter maps to one SPINE mechanic.
246
+
247
+ Raw chunks are named `U<number>.md` and paired with `nodes/<ID>.md` by the
248
+ trailing number (`U001` ↔ `KEDR_001`).
249
+
250
+ ---
251
+
252
+ ## Quickstart
253
+
254
+ Install and try it in 60 seconds:
255
+
256
+ ```bash
257
+ pip install spine-memory # core (zero required deps)
258
+ pip install spine-memory[mcp] # + MCP server (fastmcp)
259
+
260
+ spine init --preset dev # scaffold .spine/ inside your repo
261
+ spine index # rebuild reverse_index.json
262
+ spine wander --from ADR_001 # walk the graph
263
+ spine mcp # start the MCP server
264
+ ```
265
+
266
+ Or run directly from a checkout (no install):
267
+
268
+ ```bash
269
+ # 1. Auto-audit nodes (clean PASS expected)
270
+ bash tools/_critic_check.sh nodes raw anchors/anchor_dump.json
271
+
272
+ # 2. Validate anchors against the canon
273
+ python tools/_check_anchors.py nodes/KEDR_001.md --dump anchors/anchor_dump.json --quiet
274
+
275
+ # 3. Walk the graph (forward and backlinks)
276
+ python tools/_wander.py --from KEDR_001 --hops 2 --folder nodes
277
+
278
+ # 4. Global quality audit
279
+ python tools/_quality_audit.py --nodes nodes --raw raw
280
+
281
+ # 5. Crosslink generation (dry run / apply)
282
+ python tools/_crosslink.py --folder nodes
283
+ python tools/_crosslink.py --folder nodes --apply
284
+
285
+ # 6. MCP server (stdio, for Claude Desktop / Cursor / Windsurf)
286
+ pip install -r requirements.txt
287
+ python tools/mcp_server.py
288
+
289
+ # 7. Token savings benchmark
290
+ python tools/benchmark_tokens.py
291
+
292
+ # 8. Rebuild reverse index + refresh anchor canon
293
+ python tools/_build_index.py
294
+
295
+ # 9. Nightly consolidation + self-audit
296
+ python tools/night_daemon.py --folder nodes
297
+
298
+ # 10. Import precomputed embedding links (from an external GPU worker)
299
+ python tools/_embed_links.py --input embed_links.json --folder nodes
300
+ ```
301
+
302
+ ---
303
+
304
+ ## Node format (v2.1)
305
+
306
+ ```
307
+ --- # YAML frontmatter
308
+ id: KEDR_001
309
+ type: spine_node
310
+ domain: Связь
311
+ hub: "[[Кедр_Связь]]"
312
+ constellation: Кедр-9 Expedition
313
+ vectors:
314
+ - "связь::трёхслойный_архив" # comment required
315
+ search_anchors:
316
+ - трёхслойный_архив
317
+ chronology:
318
+ roots: "[[U001]]"
319
+ after: "[[KEDR_002]]:continuation"
320
+ semantic_links:
321
+ - "[[KEDR_002]]::продолжение"
322
+ ---
323
+
324
+ # IMPULSE — 1–2 lines
325
+ # SUMMARY — 3–5 sentences
326
+ # CLEANED_DATA — ~25 lines of facts
327
+ # IMPACT — strategic_weight + key_insight
328
+ # SOURCE_BASE — ≥70% of the raw source
329
+ ---
330
+ ```
331
+
332
+ Full specification: `methodology/SPINE_METHODOLOGY_EN.md` (RU: `methodology/SPINE_METHODOLOGY.md`).