second-brain-graph 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.
- second_brain_graph-0.1.0/LICENSE +21 -0
- second_brain_graph-0.1.0/MANIFEST.in +7 -0
- second_brain_graph-0.1.0/PKG-INFO +258 -0
- second_brain_graph-0.1.0/README.it.md +229 -0
- second_brain_graph-0.1.0/README.md +225 -0
- second_brain_graph-0.1.0/pyproject.toml +62 -0
- second_brain_graph-0.1.0/second_brain/__init__.py +21 -0
- second_brain_graph-0.1.0/second_brain/__main__.py +8 -0
- second_brain_graph-0.1.0/second_brain/assess.py +211 -0
- second_brain_graph-0.1.0/second_brain/classify.py +87 -0
- second_brain_graph-0.1.0/second_brain/cli.py +185 -0
- second_brain_graph-0.1.0/second_brain/freshness.py +121 -0
- second_brain_graph-0.1.0/second_brain/gate.py +79 -0
- second_brain_graph-0.1.0/second_brain/ignore.py +76 -0
- second_brain_graph-0.1.0/second_brain/indexer.py +295 -0
- second_brain_graph-0.1.0/second_brain/mcp_server.py +91 -0
- second_brain_graph-0.1.0/second_brain/model.py +213 -0
- second_brain_graph-0.1.0/second_brain/operational.py +103 -0
- second_brain_graph-0.1.0/second_brain/py.typed +0 -0
- second_brain_graph-0.1.0/second_brain/pycode.py +61 -0
- second_brain_graph-0.1.0/second_brain/query.py +177 -0
- second_brain_graph-0.1.0/second_brain/references.py +80 -0
- second_brain_graph-0.1.0/second_brain/store.py +66 -0
- second_brain_graph-0.1.0/second_brain/ui/3d-force-graph.min.js +5 -0
- second_brain_graph-0.1.0/second_brain/ui/template.html +341 -0
- second_brain_graph-0.1.0/second_brain/viewer.py +57 -0
- second_brain_graph-0.1.0/second_brain_graph.egg-info/PKG-INFO +258 -0
- second_brain_graph-0.1.0/second_brain_graph.egg-info/SOURCES.txt +45 -0
- second_brain_graph-0.1.0/second_brain_graph.egg-info/dependency_links.txt +1 -0
- second_brain_graph-0.1.0/second_brain_graph.egg-info/entry_points.txt +3 -0
- second_brain_graph-0.1.0/second_brain_graph.egg-info/requires.txt +7 -0
- second_brain_graph-0.1.0/second_brain_graph.egg-info/top_level.txt +1 -0
- second_brain_graph-0.1.0/setup.cfg +4 -0
- second_brain_graph-0.1.0/tests/test_assess.py +81 -0
- second_brain_graph-0.1.0/tests/test_classify.py +20 -0
- second_brain_graph-0.1.0/tests/test_cli.py +67 -0
- second_brain_graph-0.1.0/tests/test_gate.py +115 -0
- second_brain_graph-0.1.0/tests/test_gate_baseline.py +15 -0
- second_brain_graph-0.1.0/tests/test_ignore.py +39 -0
- second_brain_graph-0.1.0/tests/test_indexer.py +134 -0
- second_brain_graph-0.1.0/tests/test_mcp.py +19 -0
- second_brain_graph-0.1.0/tests/test_model.py +101 -0
- second_brain_graph-0.1.0/tests/test_operational.py +59 -0
- second_brain_graph-0.1.0/tests/test_pycode.py +39 -0
- second_brain_graph-0.1.0/tests/test_query.py +71 -0
- second_brain_graph-0.1.0/tests/test_references.py +37 -0
- second_brain_graph-0.1.0/tests/test_viewer.py +55 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lopax
|
|
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,7 @@
|
|
|
1
|
+
# Ship the vendored 3D viewer assets in the source distribution (wheels already include them
|
|
2
|
+
# via [tool.setuptools.package-data]). Without this, the sdist would omit ui/*.js and ui/*.html.
|
|
3
|
+
include LICENSE
|
|
4
|
+
include README.md
|
|
5
|
+
include README.it.md
|
|
6
|
+
include second_brain/py.typed
|
|
7
|
+
recursive-include second_brain/ui *.html *.js
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: second-brain-graph
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A living, always-fresh, low-token map of every project: files, links, areas and mechanics, with a navigable 3D view.
|
|
5
|
+
Author-email: Lopax <lopax76@users.noreply.github.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/lopax76/second-brain
|
|
8
|
+
Project-URL: Repository, https://github.com/lopax76/second-brain
|
|
9
|
+
Project-URL: Issues, https://github.com/lopax76/second-brain/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/lopax76/second-brain#readme
|
|
11
|
+
Keywords: knowledge-graph,memory,ai-agents,documentation,code-graph,mcp
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
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 :: Documentation
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
29
|
+
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
30
|
+
Provides-Extra: mcp
|
|
31
|
+
Requires-Dist: mcp>=1.2; extra == "mcp"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# Second Brain (SB)
|
|
35
|
+
|
|
36
|
+
[](https://github.com/lopax76/second-brain/actions/workflows/ci.yml)
|
|
37
|
+
[](LICENSE)
|
|
38
|
+
[](pyproject.toml)
|
|
39
|
+
[](pyproject.toml)
|
|
40
|
+
|
|
41
|
+
**A living, always-fresh, low-token map of every project** — files, links, areas and
|
|
42
|
+
mechanics — that an AI assistant can **query** instead of re-reading everything, and that a
|
|
43
|
+
human can explore in a navigable **3D graph**.
|
|
44
|
+
|
|
45
|
+
🇮🇹 [Leggi in italiano →](README.it.md)
|
|
46
|
+
|
|
47
|
+
> Not "another place to store stuff". It's the canonical, per-project picture that stays in
|
|
48
|
+
> sync with your files so you never lose track: no forgotten pieces, no "we discussed that
|
|
49
|
+
> three chats ago", no stale docs.
|
|
50
|
+
|
|
51
|
+

|
|
52
|
+
|
|
53
|
+
<sub>The offline 3D viewer on a real, multi-project workspace (names anonymized): nodes colored
|
|
54
|
+
by type, grouped here by type, with a click-through detail panel.</sub>
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Why this exists
|
|
59
|
+
|
|
60
|
+
A project gets more complex over time. Files drift, some go orphaned or quietly broken, the
|
|
61
|
+
mental model of "what's where and how it connects" gets fuzzier, and an AI assistant **loses
|
|
62
|
+
the thread between one chat and the next** — so every session starts by re-reading and
|
|
63
|
+
re-searching files. That is slow, incomplete, and **burns tokens repeatedly** — and it only
|
|
64
|
+
gets worse as the project grows.
|
|
65
|
+
|
|
66
|
+
Second Brain builds the project's graph **once** and keeps it fresh incrementally (outside the
|
|
67
|
+
model, at near-zero token cost). The assistant **queries** it and gets compact answers; a human
|
|
68
|
+
opens the **3D view** and sees the whole project at a glance.
|
|
69
|
+
|
|
70
|
+
It is **not a RAG system**: no embeddings, no vector store, no LLM needed to build the graph.
|
|
71
|
+
It maps the *structural* relationships between files, which makes it complementary to RAG and
|
|
72
|
+
purpose-built for one thing: **situational awareness at a very low token cost.**
|
|
73
|
+
|
|
74
|
+
## What makes it different
|
|
75
|
+
|
|
76
|
+
- **Read-only on your sources** — it indexes, it never modifies your files. Run it on anything
|
|
77
|
+
without risk.
|
|
78
|
+
- **Files are the truth** — the graph is derived (in `.secondbrain/`) and always regenerable;
|
|
79
|
+
contents are never duplicated into it.
|
|
80
|
+
- **Zero runtime dependencies** — the core runs on the Python standard library alone. No
|
|
81
|
+
conflicts, instant install, works in CI / containers / air-gapped boxes.
|
|
82
|
+
- **Low token cost by design** — queries return ids, types, sizes and connections, never file
|
|
83
|
+
contents, so orienting an assistant costs a few hundred tokens, not tens of thousands.
|
|
84
|
+
- **Anti-drift gate** — refuses to call the graph "fine" while something is stale, orphaned, or
|
|
85
|
+
broken.
|
|
86
|
+
- **Offline 3D viewer** — the data is inlined and the 3D library is vendored next to the page;
|
|
87
|
+
the viewer works fully offline, no CDN, nothing for a script blocker to break.
|
|
88
|
+
- **Optional MCP server** — exposes the same low-token queries to MCP-aware assistants, behind
|
|
89
|
+
an optional extra so the core stays dependency-free.
|
|
90
|
+
|
|
91
|
+
## See it on a real project (anonymized)
|
|
92
|
+
|
|
93
|
+
A **read-only** measurement on a mature, multi-repo project (identity withheld): ~1,684
|
|
94
|
+
knowledge files across 17 top-level areas, indexed in **~1.3 s** (index `graph.json` = 0.91 MB).
|
|
95
|
+
|
|
96
|
+
Three ways to answer the same four questions about the project — *what's here, list every
|
|
97
|
+
recorded decision, which files are truncated/empty, the most-connected files* — in three
|
|
98
|
+
separate clean chats:
|
|
99
|
+
|
|
100
|
+
| Metric | NOTHING (manual) | TODAY (manual) | WITH Second Brain |
|
|
101
|
+
|---|---|---|---|
|
|
102
|
+
| Time | ~8.5 min | ~9 min | **~3–4 min** |
|
|
103
|
+
| Working tokens | opaque | opaque | **~3–4k, self-measured** |
|
|
104
|
+
| **Decisions found** | 112 (wrong) | 131 (wrong) | **117 (exact)** |
|
|
105
|
+
| **Truncated files** | 3 | 0 (missed) | **2 (exact)** |
|
|
106
|
+
| Files counted | 2,174 | 2,174 | **1,684 (exact)** |
|
|
107
|
+
| Reproducible / verifiable | no | no | **yes** |
|
|
108
|
+
|
|
109
|
+
Two things stand out. (1) The two manual runs **disagree with each other** — 112 vs 131
|
|
110
|
+
decisions, 3 vs 0 truncated files (the second missed them entirely): the by-hand method is
|
|
111
|
+
non-deterministic and unverifiable. (2) Second Brain returns the **exact, identical answer
|
|
112
|
+
every run**, with far fewer tokens and in less than half the time.
|
|
113
|
+
|
|
114
|
+
Just to *orient* an assistant on the whole project — something you pay for **every session** —
|
|
115
|
+
reading the curated source-of-truth docs costs **~229,000 tokens**; the `second-brain map`
|
|
116
|
+
digest costs **~270 tokens**: **~800× less**, and roughly constant as the project grows (the
|
|
117
|
+
full index is queried, never loaded into context).
|
|
118
|
+
|
|
119
|
+
<p align="center">
|
|
120
|
+
<img src="docs/assets/chart-tokens.png" width="90%" alt="Tokens to orient (log scale): ~26.7M to read everything, ~4.09M all docs, ~229,000 today's curated docs, ~270 the Second Brain digest">
|
|
121
|
+
</p>
|
|
122
|
+
|
|
123
|
+
<p align="center">
|
|
124
|
+
<img src="docs/assets/chart-accuracy.png" width="48%" alt="Accuracy: manual runs disagree (112 / 131), Second Brain is exact (117)">
|
|
125
|
+
<img src="docs/assets/chart-time.png" width="48%" alt="Time to answer: ~8.5 / ~9 min manual vs ~3–4 min with Second Brain; index build ~1.3 s once">
|
|
126
|
+
</p>
|
|
127
|
+
|
|
128
|
+
And it surfaces what even curated docs miss: genuinely **truncated/corrupted files** (with
|
|
129
|
+
UTF-16/encoding false positives excluded), **~45 empty files**, **~1,390 orphan files (~80%)**,
|
|
130
|
+
**117 decisions** and **~626 cross-references** now explicit and queryable, plus **13 files
|
|
131
|
+
already stale within seconds** of indexing (a live system constantly writing) — which is
|
|
132
|
+
exactly why the map has to update itself.
|
|
133
|
+
|
|
134
|
+
<p align="center">
|
|
135
|
+
<img src="docs/assets/chart-memory.png" width="72%" alt="Illustrative: across many chats a hand-kept project map drifts while a queryable graph stays current">
|
|
136
|
+
</p>
|
|
137
|
+
|
|
138
|
+
<sub>Illustrative — the continuity problem SB removes: over many sessions a hand-kept map
|
|
139
|
+
drifts as orphans and stale files pile up, while a queryable graph stays current.</sub>
|
|
140
|
+
|
|
141
|
+
### The same structure, the code layer
|
|
142
|
+
|
|
143
|
+
Second Brain's code-import layer renders the whole workspace as a graph you can actually read:
|
|
144
|
+
|
|
145
|
+

|
|
146
|
+
|
|
147
|
+
## Install
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
pip install -e . # from a clone
|
|
151
|
+
# once published:
|
|
152
|
+
# pip install second-brain-graph
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Requires Python 3.10+. Runtime dependencies: **none** (standard library only).
|
|
156
|
+
|
|
157
|
+
## Quickstart
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
second-brain build . # index a project -> .secondbrain/graph.json
|
|
161
|
+
second-brain gate . # anti-drift check: broken refs, stale files, orphans
|
|
162
|
+
second-brain view . # write the offline 3D viewer -> .secondbrain/view.html
|
|
163
|
+
second-brain stats . # quick counts by node/edge type
|
|
164
|
+
second-brain map . # compact digest: areas, sizes, most-connected files
|
|
165
|
+
second-brain find util . # find nodes by name or path
|
|
166
|
+
second-brain neighbors second_brain/model.py . # a node and its connections
|
|
167
|
+
second-brain assess . # one-shot before/after report: problems + token savings
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**Drill down** by pointing the tool at a subfolder — `second-brain view ./src/api` renders just
|
|
171
|
+
that area in full detail, while the top-level view stays light via *backbone* mode (areas +
|
|
172
|
+
the knowledge-connected core; isolated data files are summarized on their area node).
|
|
173
|
+
|
|
174
|
+
Open `.secondbrain/view.html` in a browser (double-click — no server needed): the data is
|
|
175
|
+
inlined and the 3D library is vendored next to the page, so **it works fully offline**.
|
|
176
|
+
|
|
177
|
+
## Query layer (for AI assistants)
|
|
178
|
+
|
|
179
|
+
`second-brain map`, `find`, and `neighbors` return compact, budgeted answers (ids, types, sizes,
|
|
180
|
+
connections — never file contents). An optional **MCP server** exposes the same queries to
|
|
181
|
+
MCP-aware assistants:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
pip install "second-brain-graph[mcp]"
|
|
185
|
+
second-brain-mcp . # serves map / find / neighbors / subgraph / health over stdio
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
See [`docs/mcp.md`](docs/mcp.md) for the tools and their shapes.
|
|
189
|
+
|
|
190
|
+
## How it works
|
|
191
|
+
|
|
192
|
+
1. **Index** — walk the project, classify each file into a typed node, and extract edges:
|
|
193
|
+
Python imports (via `ast`), JS/TS imports, documentation references (markdown links,
|
|
194
|
+
`[[wikilinks]]`, and **plain path mentions in prose** — the part standard tools miss), and
|
|
195
|
+
area membership. Operational nodes (decisions found in the docs, sessions from git commits)
|
|
196
|
+
are added too.
|
|
197
|
+
2. **Stay fresh** — content-hash diffing rebuilds only what changed (outside the model).
|
|
198
|
+
3. **Query / view** — a human gets the 3D view; an assistant queries the low-token layer.
|
|
199
|
+
|
|
200
|
+
**On false positives:** plain path mentions in prose are inherently noisy. Second Brain handles
|
|
201
|
+
this asymmetrically — markdown links and wikilinks are intentional (an unresolved one is
|
|
202
|
+
reported as *broken*), but a plain prose mention is used **only if it resolves** to a real file;
|
|
203
|
+
otherwise it is dropped as noise and never creates a broken reference. Deep import parsing is
|
|
204
|
+
Python and JS/TS today; other languages contribute via documentation links.
|
|
205
|
+
|
|
206
|
+
The full node/edge taxonomy, the `graph.json` schema, and the classification rules are
|
|
207
|
+
documented in [`docs/graph-format.md`](docs/graph-format.md).
|
|
208
|
+
|
|
209
|
+
## Try the before/after yourself
|
|
210
|
+
|
|
211
|
+
Run these in **separate clean chats** (read-only), then compare the answers and the token/time
|
|
212
|
+
cost. Replace `/path/to/project` with a real project.
|
|
213
|
+
|
|
214
|
+
**TODAY (your current method):**
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
READ-ONLY: do not modify, create, delete or move any file. On the project at
|
|
218
|
+
/path/to/project, work with your NORMAL method (reference docs, memory, the tools you
|
|
219
|
+
usually use). Give me a COMPLETE, ACCURATE picture answering these 4 questions:
|
|
220
|
+
1) how many files (excluding images, venvs, caches, .git) and the breakdown by type;
|
|
221
|
+
2) list ALL decisions recorded in the docs (D-XXX, ADR-N, RFC-N);
|
|
222
|
+
3) which files are truncated/corrupted (null-byte) or empty (zero-byte);
|
|
223
|
+
4) the 10 most-connected files. When done, tell me the time and tokens you used.
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
**WITH Second Brain** (index already built — query it, don't re-read files):
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
READ-ONLY. Second Brain's index is already built — only query it. Use ONLY:
|
|
230
|
+
python -m second_brain map "/path/to/project"
|
|
231
|
+
python -m second_brain stats "/path/to/project"
|
|
232
|
+
python -m second_brain find <text> "/path/to/project"
|
|
233
|
+
and read /path/to/project/.secondbrain/assessment.md. Answer the same 4 questions, then
|
|
234
|
+
tell me the time and tokens you used.
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Status & roadmap
|
|
238
|
+
|
|
239
|
+
Alpha (v0.1). Working today: the typed graph, the anti-drift gate, the offline 3D viewer, the
|
|
240
|
+
low-token query layer (`map`/`find`/`neighbors`/`subgraph`), operational nodes
|
|
241
|
+
(decisions/sessions), and the optional MCP server. Next: richer reference resolution and a PyPI
|
|
242
|
+
release.
|
|
243
|
+
|
|
244
|
+
## Development
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
pip install -e ".[dev,mcp]"
|
|
248
|
+
ruff check second-brain tests
|
|
249
|
+
pytest -q
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Contributions are welcome — see [CONTRIBUTING.md](CONTRIBUTING.md) and the
|
|
253
|
+
[design principles](CONTRIBUTING.md#design-principles-please-keep-these-intact) (read-only,
|
|
254
|
+
zero-deps, low-token, deterministic). Security reports: [SECURITY.md](SECURITY.md).
|
|
255
|
+
|
|
256
|
+
## License
|
|
257
|
+
|
|
258
|
+
[MIT](LICENSE).
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# Second Brain (SB)
|
|
2
|
+
|
|
3
|
+
[](https://github.com/lopax76/second-brain/actions/workflows/ci.yml)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](pyproject.toml)
|
|
6
|
+
[](pyproject.toml)
|
|
7
|
+
|
|
8
|
+
**Una mappa viva, sempre fresca e a basso costo di token di ogni progetto** — file, collegamenti,
|
|
9
|
+
aree e meccaniche — che un assistente AI può **interrogare** invece di rileggere tutto, e che una
|
|
10
|
+
persona può esplorare in un **grafo 3D** navigabile.
|
|
11
|
+
|
|
12
|
+
🇬🇧 [Read in English →](README.md)
|
|
13
|
+
|
|
14
|
+
> Non "un altro posto dove mettere roba". È il quadro canonico, per-progetto, che resta in sync
|
|
15
|
+
> con i tuoi file così non perdi mai il filo: niente pezzi dimenticati, niente "ne avevamo parlato
|
|
16
|
+
> tre chat fa", niente documenti stantii.
|
|
17
|
+
|
|
18
|
+

|
|
19
|
+
|
|
20
|
+
<sub>Il viewer 3D offline su un workspace multi-progetto reale (nomi anonimizzati): nodi colorati
|
|
21
|
+
per tipo, qui raggruppati per tipo, con pannello di dettaglio cliccabile.</sub>
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Perché nasce
|
|
26
|
+
|
|
27
|
+
Un progetto diventa più complesso col tempo. I file derivano, alcuni restano orfani o si rompono
|
|
28
|
+
in silenzio, lo schema mentale di "cosa c'è e come si collega" si fa sempre più sfocato, e un
|
|
29
|
+
assistente AI **perde il filo tra una chat e l'altra** — così ogni sessione riparte rileggendo e
|
|
30
|
+
ri-cercando i file. È lento, incompleto e **brucia token ripetutamente** — e peggiora man mano che
|
|
31
|
+
il progetto cresce.
|
|
32
|
+
|
|
33
|
+
Second Brain costruisce il grafo del progetto **una volta sola** e lo mantiene fresco in modo
|
|
34
|
+
incrementale (fuori dal modello, a costo di token quasi nullo). L'assistente lo **interroga** e
|
|
35
|
+
ottiene risposte compatte; una persona apre la **vista 3D** e vede l'intero progetto a colpo
|
|
36
|
+
d'occhio.
|
|
37
|
+
|
|
38
|
+
**Non è un sistema RAG**: niente embedding, niente vector store, nessun LLM per costruire il grafo.
|
|
39
|
+
Mappa le relazioni *strutturali* tra i file, il che lo rende complementare al RAG e mirato a una
|
|
40
|
+
cosa sola: **consapevolezza del contesto a costo di token bassissimo.**
|
|
41
|
+
|
|
42
|
+
## Cosa lo rende diverso
|
|
43
|
+
|
|
44
|
+
- **Read-only sui sorgenti** — indicizza, non modifica mai i tuoi file. Lo esegui su qualsiasi cosa
|
|
45
|
+
senza rischio.
|
|
46
|
+
- **I file sono la verità** — il grafo è derivato (in `.secondbrain/`) e sempre rigenerabile; i
|
|
47
|
+
contenuti non vengono mai duplicati dentro.
|
|
48
|
+
- **Zero dipendenze runtime** — il core gira con la sola libreria standard di Python. Nessun
|
|
49
|
+
conflitto, installazione istantanea, funziona in CI / container / macchine air-gapped.
|
|
50
|
+
- **Basso costo di token per design** — le query restituiscono id, tipi, dimensioni e collegamenti,
|
|
51
|
+
mai il contenuto dei file: orientare un assistente costa qualche centinaio di token, non decine di
|
|
52
|
+
migliaia.
|
|
53
|
+
- **Gate anti-deriva** — rifiuta di dichiarare il grafo "a posto" finché c'è qualcosa di stantio,
|
|
54
|
+
orfano o rotto.
|
|
55
|
+
- **Viewer 3D offline** — i dati sono inline e la libreria 3D è bundlata accanto alla pagina; il
|
|
56
|
+
viewer funziona completamente offline, niente CDN, niente che un blocco-script possa rompere.
|
|
57
|
+
- **Server MCP opzionale** — espone le stesse query a basso costo agli assistenti MCP, dietro un
|
|
58
|
+
extra opzionale così il core resta senza dipendenze.
|
|
59
|
+
|
|
60
|
+
## Visto su un progetto reale (anonimizzato)
|
|
61
|
+
|
|
62
|
+
Misura **read-only** su un progetto maturo multi-repo (identità non rivelata): ~1.684 file di
|
|
63
|
+
conoscenza in 17 aree di primo livello, indicizzato in **~1,3 s** (indice `graph.json` = 0,91 MB).
|
|
64
|
+
|
|
65
|
+
Tre modi di rispondere alle stesse quattro domande sul progetto — *cosa c'è, elenca ogni decisione
|
|
66
|
+
registrata, quali file sono troncati/vuoti, i file più collegati* — in tre chat pulite separate:
|
|
67
|
+
|
|
68
|
+
| Metrica | NIENTE (manuale) | ADESSO (manuale) | CON Second Brain |
|
|
69
|
+
|---|---|---|---|
|
|
70
|
+
| Tempo | ~8,5 min | ~9 min | **~3–4 min** |
|
|
71
|
+
| Token di lavoro | opachi | opachi | **~3–4k, auto-misurabili** |
|
|
72
|
+
| **Decisioni trovate** | 112 (errato) | 131 (errato) | **117 (esatto)** |
|
|
73
|
+
| **File troncati** | 3 | 0 (mancati) | **2 (esatto)** |
|
|
74
|
+
| File contati | 2.174 | 2.174 | **1.684 (esatto)** |
|
|
75
|
+
| Riproducibile / verificabile | no | no | **sì** |
|
|
76
|
+
|
|
77
|
+
Due cose saltano all'occhio. (1) I due run manuali **non concordano tra loro** — 112 vs 131
|
|
78
|
+
decisioni, 3 vs 0 troncati (il secondo li ha mancati del tutto): il metodo a mano è
|
|
79
|
+
non-deterministico e non verificabile. (2) Second Brain dà la **risposta esatta e identica a ogni
|
|
80
|
+
run**, con molti meno token e in meno della metà del tempo.
|
|
81
|
+
|
|
82
|
+
Solo per *orientare* un assistente sull'intero progetto — cosa che paghi **ogni sessione** —
|
|
83
|
+
rileggere i documenti curati sorgente-di-verità costa **~229.000 token**; il digest
|
|
84
|
+
`second-brain map` costa **~270 token**: **~800× in meno**, e ~costante mentre il progetto cresce
|
|
85
|
+
(l'indice completo si interroga, non entra mai nel contesto).
|
|
86
|
+
|
|
87
|
+
<p align="center">
|
|
88
|
+
<img src="docs/assets/chart-tokens.png" width="90%" alt="Token per orientarsi (scala log): ~26,7M per leggere tutto, ~4,09M tutti i documenti, ~229.000 i documenti curati di oggi, ~270 il digest di Second Brain">
|
|
89
|
+
</p>
|
|
90
|
+
|
|
91
|
+
<p align="center">
|
|
92
|
+
<img src="docs/assets/chart-accuracy.png" width="48%" alt="Accuratezza: i run manuali non concordano (112 / 131), Second Brain è esatto (117)">
|
|
93
|
+
<img src="docs/assets/chart-time.png" width="48%" alt="Tempo per rispondere: ~8,5 / ~9 min manuale vs ~3–4 min con Second Brain; build indice ~1,3 s una-tantum">
|
|
94
|
+
</p>
|
|
95
|
+
|
|
96
|
+
E fa emergere ciò che persino i documenti curati non vedono: file **realmente
|
|
97
|
+
troncati/corrotti** (esclusi i falsi positivi UTF-16/encoding), **~45 file vuoti**, **~1.390 file
|
|
98
|
+
orfani (~80%)**, **117 decisioni** e **~626 riferimenti incrociati** ora espliciti e interrogabili,
|
|
99
|
+
più **13 file già stantii a pochi secondi** dall'indicizzazione (un sistema vivo che riscrive di
|
|
100
|
+
continuo) — ed è proprio per questo che la mappa deve aggiornarsi da sola.
|
|
101
|
+
|
|
102
|
+
<p align="center">
|
|
103
|
+
<img src="docs/assets/chart-memory.png" width="72%" alt="Illustrativo: nel corso di molte chat una mappa tenuta a mano deriva, mentre un grafo interrogabile resta aggiornato">
|
|
104
|
+
</p>
|
|
105
|
+
|
|
106
|
+
<sub>Illustrativo — il problema di continuità che SB elimina: nel corso di molte sessioni una
|
|
107
|
+
mappa tenuta a mano deriva (orfani e file stantii si accumulano), mentre un grafo interrogabile
|
|
108
|
+
resta sempre aggiornato.</sub>
|
|
109
|
+
|
|
110
|
+
### La stessa struttura, il layer di codice
|
|
111
|
+
|
|
112
|
+
Il layer di import-codice di Second Brain rende l'intero workspace come un grafo davvero leggibile:
|
|
113
|
+
|
|
114
|
+

|
|
115
|
+
|
|
116
|
+
## Installazione
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
pip install -e . # da un clone
|
|
120
|
+
# una volta pubblicato:
|
|
121
|
+
# pip install second-brain-graph
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Richiede Python 3.10+. Dipendenze runtime: **nessuna** (solo libreria standard).
|
|
125
|
+
|
|
126
|
+
## Avvio rapido
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
second-brain build . # indicizza un progetto -> .secondbrain/graph.json
|
|
130
|
+
second-brain gate . # check anti-deriva: ref rotte, file stantii, orfani
|
|
131
|
+
second-brain view . # scrive il viewer 3D offline -> .secondbrain/view.html
|
|
132
|
+
second-brain stats . # conteggi rapidi per tipo nodo/arco
|
|
133
|
+
second-brain map . # digest compatto: aree, dimensioni, file più connessi
|
|
134
|
+
second-brain find util . # trova nodi per nome o path
|
|
135
|
+
second-brain neighbors second_brain/model.py . # un nodo e le sue connessioni
|
|
136
|
+
second-brain assess . # report prima/dopo: problemi + risparmio token
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**Drill-down** puntando lo strumento su una sottocartella — `second-brain view ./src/api`
|
|
140
|
+
renderizza solo quell'area in pieno dettaglio, mentre la vista d'insieme resta leggera grazie alla
|
|
141
|
+
modalità *backbone* (aree + nucleo connesso per conoscenza; i file-dati isolati sono riassunti sul
|
|
142
|
+
nodo-area).
|
|
143
|
+
|
|
144
|
+
Apri `.secondbrain/view.html` in un browser (doppio clic — niente server): i dati sono inline e la
|
|
145
|
+
libreria 3D è bundlata accanto alla pagina, quindi **funziona completamente offline**.
|
|
146
|
+
|
|
147
|
+
## Layer di query (per gli assistenti AI)
|
|
148
|
+
|
|
149
|
+
`second-brain map`, `find` e `neighbors` restituiscono risposte compatte e budgettate (id, tipi,
|
|
150
|
+
dimensioni, connessioni — mai il contenuto dei file). Un **server MCP** opzionale espone le stesse
|
|
151
|
+
query agli assistenti compatibili MCP:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
pip install "second-brain-graph[mcp]"
|
|
155
|
+
second-brain-mcp . # serve map / find / neighbors / subgraph / health su stdio
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Vedi [`docs/mcp.md`](docs/mcp.md) per i tool e le forme dei dati.
|
|
159
|
+
|
|
160
|
+
## Come funziona
|
|
161
|
+
|
|
162
|
+
1. **Index** — percorre il progetto, classifica ogni file in un nodo tipizzato ed estrae gli archi:
|
|
163
|
+
import Python (via `ast`), import JS/TS, riferimenti di documentazione (link markdown,
|
|
164
|
+
`[[wikilink]]` e **menzioni di path in prosa** — il pezzo che gli strumenti standard mancano) e
|
|
165
|
+
appartenenza ad area. Vengono aggiunti anche i nodi operativi (decisioni trovate nei documenti,
|
|
166
|
+
sessioni dai commit git).
|
|
167
|
+
2. **Stay fresh** — il diffing per content-hash ricostruisce solo ciò che è cambiato (fuori dal
|
|
168
|
+
modello).
|
|
169
|
+
3. **Query / view** — una persona ottiene la vista 3D; un assistente interroga il layer a basso
|
|
170
|
+
costo di token.
|
|
171
|
+
|
|
172
|
+
**Sui falsi positivi:** le menzioni di path in prosa sono intrinsecamente rumorose. Second Brain
|
|
173
|
+
le gestisce in modo asimmetrico — link markdown e wikilink sono intenzionali (uno non risolto è
|
|
174
|
+
segnalato come *rotto*), ma una menzione in prosa è usata **solo se risolve** a un file reale;
|
|
175
|
+
altrimenti viene scartata come rumore e non crea mai un riferimento rotto. Il parsing profondo degli
|
|
176
|
+
import oggi è Python e JS/TS; gli altri linguaggi contribuiscono via link di documentazione.
|
|
177
|
+
|
|
178
|
+
La tassonomia completa nodi/archi, lo schema di `graph.json` e le regole di classificazione sono
|
|
179
|
+
documentati in [`docs/graph-format.md`](docs/graph-format.md).
|
|
180
|
+
|
|
181
|
+
## Prova tu il prima/dopo
|
|
182
|
+
|
|
183
|
+
Esegui questi in **chat pulite separate** (read-only), poi confronta le risposte e il costo
|
|
184
|
+
token/tempo. Sostituisci `/path/al/progetto` con un progetto reale.
|
|
185
|
+
|
|
186
|
+
**ADESSO (il tuo metodo attuale):**
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
SOLO LETTURA: non modificare, creare, cancellare o spostare alcun file. Sul progetto in
|
|
190
|
+
/path/al/progetto, lavora col tuo METODO NORMALE (documenti di riferimento, memoria, gli
|
|
191
|
+
strumenti che usi di solito). Dammi un quadro COMPLETO e ACCURATO rispondendo a 4 domande:
|
|
192
|
+
1) quanti file (esclusi immagini, venv, cache, .git) e ripartizione per tipo;
|
|
193
|
+
2) elenca TUTTE le decisioni registrate nei documenti (D-XXX, ADR-N, RFC-N);
|
|
194
|
+
3) quali file sono troncati/corrotti (null-byte) o vuoti (zero-byte);
|
|
195
|
+
4) i 10 file più collegati. Quando hai finito, dimmi tempo e token consumati.
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**CON Second Brain** (indice già costruito — interrogalo, non rileggere i file):
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
SOLO LETTURA. L'indice di Second Brain è già costruito — va solo interrogato. Usa SOLO:
|
|
202
|
+
python -m second_brain map "/path/al/progetto"
|
|
203
|
+
python -m second_brain stats "/path/al/progetto"
|
|
204
|
+
python -m second_brain find <testo> "/path/al/progetto"
|
|
205
|
+
e leggi /path/al/progetto/.secondbrain/assessment.md. Rispondi alle stesse 4 domande, poi
|
|
206
|
+
dimmi tempo e token consumati.
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Stato & roadmap
|
|
210
|
+
|
|
211
|
+
Alpha (v0.1). Funzionante oggi: grafo tipizzato, gate anti-deriva, viewer 3D offline, layer di
|
|
212
|
+
query a basso costo (`map`/`find`/`neighbors`/`subgraph`), nodi operativi (decisioni/sessioni) e
|
|
213
|
+
server MCP opzionale. Prossimi passi: risoluzione dei riferimenti più ricca e una release su PyPI.
|
|
214
|
+
|
|
215
|
+
## Sviluppo
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
pip install -e ".[dev,mcp]"
|
|
219
|
+
ruff check second-brain tests
|
|
220
|
+
pytest -q
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
I contributi sono benvenuti — vedi [CONTRIBUTING.md](CONTRIBUTING.md) e i
|
|
224
|
+
[principi di design](CONTRIBUTING.md#design-principles-please-keep-these-intact) (read-only,
|
|
225
|
+
zero-deps, basso costo di token, deterministico). Segnalazioni di sicurezza: [SECURITY.md](SECURITY.md).
|
|
226
|
+
|
|
227
|
+
## Licenza
|
|
228
|
+
|
|
229
|
+
[MIT](LICENSE).
|