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