cerebro-code-memory 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.
- cerebro_code_memory-0.1.0/.claude-plugin/marketplace.json +15 -0
- cerebro_code_memory-0.1.0/.gitignore +15 -0
- cerebro_code_memory-0.1.0/CLAUDE.md +57 -0
- cerebro_code_memory-0.1.0/LICENSE +21 -0
- cerebro_code_memory-0.1.0/PKG-INFO +160 -0
- cerebro_code_memory-0.1.0/README.md +138 -0
- cerebro_code_memory-0.1.0/USAGE.md +58 -0
- cerebro_code_memory-0.1.0/plugin/.claude-plugin/plugin.json +10 -0
- cerebro_code_memory-0.1.0/plugin/.mcp.json +8 -0
- cerebro_code_memory-0.1.0/plugin/agents/cerebro-architect.md +46 -0
- cerebro_code_memory-0.1.0/plugin/agents/cerebro-explorer.md +28 -0
- cerebro_code_memory-0.1.0/plugin/agents/cerebro-impact-analyst.md +27 -0
- cerebro_code_memory-0.1.0/plugin/agents/cerebro-implementer.md +28 -0
- cerebro_code_memory-0.1.0/plugin/agents/cerebro-memory-keeper.md +28 -0
- cerebro_code_memory-0.1.0/plugin/hooks/hooks.json +25 -0
- cerebro_code_memory-0.1.0/plugin/hooks/post_edit.py +49 -0
- cerebro_code_memory-0.1.0/plugin/hooks/session_start.py +105 -0
- cerebro_code_memory-0.1.0/plugin/skills/cerebro/SKILL.md +80 -0
- cerebro_code_memory-0.1.0/pyproject.toml +49 -0
- cerebro_code_memory-0.1.0/src/cerebro/__init__.py +3 -0
- cerebro_code_memory-0.1.0/src/cerebro/callgraph.py +38 -0
- cerebro_code_memory-0.1.0/src/cerebro/cli.py +348 -0
- cerebro_code_memory-0.1.0/src/cerebro/config.py +136 -0
- cerebro_code_memory-0.1.0/src/cerebro/db.py +245 -0
- cerebro_code_memory-0.1.0/src/cerebro/docaudit.py +174 -0
- cerebro_code_memory-0.1.0/src/cerebro/embeddings.py +175 -0
- cerebro_code_memory-0.1.0/src/cerebro/gitsync.py +124 -0
- cerebro_code_memory-0.1.0/src/cerebro/graph.py +77 -0
- cerebro_code_memory-0.1.0/src/cerebro/indexer.py +854 -0
- cerebro_code_memory-0.1.0/src/cerebro/insights.py +217 -0
- cerebro_code_memory-0.1.0/src/cerebro/notes.py +70 -0
- cerebro_code_memory-0.1.0/src/cerebro/server.py +382 -0
- cerebro_code_memory-0.1.0/src/cerebro/summaries.py +66 -0
- cerebro_code_memory-0.1.0/src/cerebro/summarizer.py +109 -0
- cerebro_code_memory-0.1.0/src/cerebro/tsconfig.py +159 -0
- cerebro_code_memory-0.1.0/src/cerebro/views.py +52 -0
- cerebro_code_memory-0.1.0/src/cerebro/viz.py +374 -0
- cerebro_code_memory-0.1.0/tests/conftest.py +18 -0
- cerebro_code_memory-0.1.0/tests/test_callgraph.py +58 -0
- cerebro_code_memory-0.1.0/tests/test_cli.py +68 -0
- cerebro_code_memory-0.1.0/tests/test_db.py +76 -0
- cerebro_code_memory-0.1.0/tests/test_docaudit.py +77 -0
- cerebro_code_memory-0.1.0/tests/test_embeddings.py +99 -0
- cerebro_code_memory-0.1.0/tests/test_gitsync.py +54 -0
- cerebro_code_memory-0.1.0/tests/test_indexer.py +438 -0
- cerebro_code_memory-0.1.0/tests/test_insights.py +168 -0
- cerebro_code_memory-0.1.0/tests/test_notes.py +41 -0
- cerebro_code_memory-0.1.0/tests/test_server.py +59 -0
- cerebro_code_memory-0.1.0/tests/test_summarizer.py +41 -0
- cerebro_code_memory-0.1.0/tests/test_tsconfig.py +104 -0
- cerebro_code_memory-0.1.0/tests/test_viz.py +63 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cerebro",
|
|
3
|
+
"owner": {
|
|
4
|
+
"name": "Marco Toledo",
|
|
5
|
+
"url": "https://github.com/marcodavidd020"
|
|
6
|
+
},
|
|
7
|
+
"plugins": [
|
|
8
|
+
{
|
|
9
|
+
"name": "cerebro",
|
|
10
|
+
"source": "./plugin",
|
|
11
|
+
"description": "MCP brain for codebases: caches structure + summaries so AI sessions query it instead of re-reading files. Bundles the MCP server, cerebro-first subagents, and session hooks.",
|
|
12
|
+
"version": "0.1.0"
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# CLAUDE.md — Cerebro
|
|
2
|
+
|
|
3
|
+
Estándares reales de este proyecto. Cárgalos antes de proponer o escribir código.
|
|
4
|
+
Si algo aquí contradice al código actual, **gana el código**: verifícalo y actualiza este archivo.
|
|
5
|
+
|
|
6
|
+
## Qué es
|
|
7
|
+
MCP server en Python que cachea el *entendimiento* de un codebase en un SQLite ("brain")
|
|
8
|
+
para que sesiones de chat lo **consulten** en vez de re-leer carpetas. La consigna de todo
|
|
9
|
+
el proyecto: **salida token-barata**.
|
|
10
|
+
|
|
11
|
+
## Stack (verificado en `pyproject.toml`)
|
|
12
|
+
- Python **>=3.10**. Server con `FastMCP` (paquete `mcp>=1.2.0`).
|
|
13
|
+
- Deps núcleo: `tree-sitter` + `tree-sitter-language-pack`, `networkx`, `pathspec`.
|
|
14
|
+
- Semántica **opcional** detrás del extra `semantic`: `model2vec`, `numpy`. **Sin torch, sin API keys, nada sale de la máquina** — invariante de privacidad.
|
|
15
|
+
- Tests: `pytest` (en `.venv`). Build: `hatchling`, paquete en `src/cerebro`.
|
|
16
|
+
|
|
17
|
+
## Arquitectura (una responsabilidad por módulo, en `src/cerebro/`)
|
|
18
|
+
- `server.py` — superficie de tools MCP (`@mcp.tool()`). Delgada: arma texto compacto y delega la lógica.
|
|
19
|
+
- `cli.py` — entrypoint CLI unificado (`cerebro <subcomando>`).
|
|
20
|
+
- `config.py` — `Config.load()`; resuelve raíz (`CEREBRO_ROOT` o git) y `db_path`.
|
|
21
|
+
- `db.py` — conexión SQLite + queries de bajo nivel (módulo más central; casi todo depende de él).
|
|
22
|
+
- `indexer.py` — parseo tree-sitter: símbolos, edges, hashes; `reindex`/`diff`.
|
|
23
|
+
- `graph.py` — grafo de dependencias (`dependencies`/`dependents`) sobre networkx.
|
|
24
|
+
- `insights.py` — `impact`, `cycles`, `orphans`, `dead_symbols`.
|
|
25
|
+
- `callgraph.py` — `callers`/`calls` (resueltos por nombre).
|
|
26
|
+
- `summaries.py` / `summarizer.py` — guardar/leer resúmenes; warming batch vía `claude -p` headless.
|
|
27
|
+
- `embeddings.py` — búsqueda semántica model2vec (opcional).
|
|
28
|
+
- `notes.py` — log de decisiones. `gitsync.py` — frescura git-aware. `tsconfig.py` — alias tsconfig/jsconfig.
|
|
29
|
+
- `views.py` — render de texto (`map_text`, `recall_text`). `viz.py` — HTML del grafo + export Obsidian. `docaudit.py` — living docs.
|
|
30
|
+
|
|
31
|
+
## Convenciones (observadas en el código, respétalas)
|
|
32
|
+
- `from __future__ import annotations`; type hints modernos (`X | None`, no `Optional`).
|
|
33
|
+
- Toda tool MCP devuelve **string compacto**. Acota listas con helpers tipo `_join_capped` y caps (`_DEP_CAP`, `_SYM_CAP`). No vuelques datos sin límite: el ahorro de tokens es el producto.
|
|
34
|
+
- Docstrings explican el **porqué** (economía de tokens, invariantes), no lo obvio.
|
|
35
|
+
- Rutas: **siempre** normaliza a clave repo-relativa con `_resolve_path` antes de tocar la DB. Saltarse esto rompe la persistencia entre sesiones.
|
|
36
|
+
- Resúmenes y notas del brain se escriben **en inglés** (tokeniza más barato), densos, 1-3 frases.
|
|
37
|
+
- Scripts CLI: cada uno expone un `main()` a nivel módulo (ver `[project.scripts]`).
|
|
38
|
+
- Tests: fixtures de DB en memoria construyendo edges a mano (ver `tests/`).
|
|
39
|
+
|
|
40
|
+
## Cómo agregar una tool MCP nueva (patrón completo)
|
|
41
|
+
1. Lógica en el módulo de dominio que corresponda (no en `server.py`).
|
|
42
|
+
2. `@mcp.tool()` en `server.py` que llama a esa lógica y arma el texto compacto.
|
|
43
|
+
3. Subcomando equivalente en `cli.py`.
|
|
44
|
+
4. Test en `tests/` con fixture en memoria.
|
|
45
|
+
|
|
46
|
+
## Comandos
|
|
47
|
+
- Tests: `uv run pytest` (o `.venv/bin/pytest`).
|
|
48
|
+
- Reindexar este propio repo: `uv run cerebro index`.
|
|
49
|
+
- Lint: **no hay ruff/mypy configurados**. Si quieres lint puntual: `uvx ruff check src/`.
|
|
50
|
+
|
|
51
|
+
## Qué NO hacer (guardarraíles anti-alucinación)
|
|
52
|
+
- No inventes nombres de tools: el set canónico vive en `server.py` (`cerebro_*`).
|
|
53
|
+
- No agregues dependencias a la ligera; lo pesado/opcional va detrás de un extra.
|
|
54
|
+
- No engordes la salida de las tools ni te saltes los caps.
|
|
55
|
+
- No escribas resúmenes/notas en español dentro del brain.
|
|
56
|
+
- No accedas a la DB con una ruta cruda: pasa por `_resolve_path`.
|
|
57
|
+
- No introduzcas torch, llamadas a APIs externas, ni nada que saque datos de la máquina.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Marco Toledo
|
|
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,160 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cerebro-code-memory
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Persistent code-knowledge memory across AI chat sessions (MCP server)
|
|
5
|
+
Project-URL: Homepage, https://github.com/marcodavidd020/cerebro-mcp
|
|
6
|
+
Project-URL: Repository, https://github.com/marcodavidd020/cerebro-mcp
|
|
7
|
+
Project-URL: Issues, https://github.com/marcodavidd020/cerebro-mcp/issues
|
|
8
|
+
Author-email: Marco Toledo <huancacori@gmail.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: claude,code-intelligence,mcp,semantic-search,sqlite,tree-sitter
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Requires-Dist: mcp>=1.2.0
|
|
14
|
+
Requires-Dist: networkx>=3.2
|
|
15
|
+
Requires-Dist: pathspec>=0.12
|
|
16
|
+
Requires-Dist: tree-sitter-language-pack>=0.7
|
|
17
|
+
Requires-Dist: tree-sitter>=0.23
|
|
18
|
+
Provides-Extra: semantic
|
|
19
|
+
Requires-Dist: model2vec>=0.3; extra == 'semantic'
|
|
20
|
+
Requires-Dist: numpy>=1.26; extra == 'semantic'
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# Cerebro 🧠
|
|
24
|
+
|
|
25
|
+
**Persistent code-knowledge memory across AI chat sessions.**
|
|
26
|
+
|
|
27
|
+
Every new chat re-analyzes your project's folders from scratch to understand it,
|
|
28
|
+
burning tokens re-discovering what a previous chat already learned. Cerebro caches
|
|
29
|
+
the *understanding* — not just the files — in a small SQLite "brain" that lives
|
|
30
|
+
**outside** the chat. New sessions **query** it instead of re-reading folders.
|
|
31
|
+
|
|
32
|
+
Instead of reading 50 files (~100k tokens) to understand a project, the model makes
|
|
33
|
+
one `cerebro_map()` call (~2-3k tokens) plus a few targeted lookups.
|
|
34
|
+
|
|
35
|
+
## How it works
|
|
36
|
+
|
|
37
|
+
Three layers of "traces", cheapest first:
|
|
38
|
+
|
|
39
|
+
1. **Structural map** (free, no LLM) — `tree-sitter` extracts symbols + imports and
|
|
40
|
+
builds a dependency graph. Imports resolve both relative paths and **tsconfig /
|
|
41
|
+
jsconfig path aliases** (`@/...`), so Next.js / NestJS monorepos get real edges.
|
|
42
|
+
**PageRank** ranks the most important modules. Each file is hashed so changes
|
|
43
|
+
are detectable. Languages: Python, JavaScript / TypeScript (incl. JSX/TSX)
|
|
44
|
+
and Dart / Flutter.
|
|
45
|
+
2. **Cached summaries** (the big saver) — as a chat understands a file, it calls
|
|
46
|
+
`cerebro_record(path, summary)` to store a 1-3 sentence **English** summary
|
|
47
|
+
(English tokenizes ~15-30% cheaper than Spanish). Future sessions reuse it.
|
|
48
|
+
3. **Freshness** — each summary is tied to the file's hash. If the file changed,
|
|
49
|
+
the trace is flagged **stale** so only that file gets re-read.
|
|
50
|
+
|
|
51
|
+
> Why not Dijkstra? Code knowledge is a *relevance* problem, not a shortest-path one.
|
|
52
|
+
> The useful algorithms are graph traversal (BFS/DFS, for impact) and centrality
|
|
53
|
+
> (PageRank, for ranking) — not weighted routing.
|
|
54
|
+
|
|
55
|
+
## MCP tools
|
|
56
|
+
|
|
57
|
+
| Tool | Purpose |
|
|
58
|
+
|------|---------|
|
|
59
|
+
| `cerebro_map(top=30)` | Cheap project overview, modules ranked by centrality. **Call first.** |
|
|
60
|
+
| `cerebro_get(path)` | Summary + symbols + dependencies of a file, without reading it. |
|
|
61
|
+
| `cerebro_search(query)` | Hybrid semantic + keyword search; semantic hits resolve to the exact symbol (`path:line`), not just the file. |
|
|
62
|
+
| `cerebro_record(path, summary)` | Leave a trace: store your understanding of a file. |
|
|
63
|
+
| `cerebro_note(content, topic?)` | Record a decision / domain rule / gotcha (the *why*). |
|
|
64
|
+
| `cerebro_recall(query?)` | Recall decisions recorded by past sessions. |
|
|
65
|
+
| `cerebro_stale()` | Files changed since last index + stale summaries. |
|
|
66
|
+
| `cerebro_sync()` | Catch branch switch / git pull / external edits and reindex them. |
|
|
67
|
+
| `cerebro_reindex(paths?)` | Refresh the structural index (only changed files). |
|
|
68
|
+
| `cerebro_impact(path)` | Transitive blast radius: everything that (in)directly imports a file. |
|
|
69
|
+
| `cerebro_cycles()` | Circular-import groups (architecture smell). |
|
|
70
|
+
| `cerebro_orphans(prefix?)` | Code files nothing imports — dead-code candidates (file-level). |
|
|
71
|
+
| `cerebro_dead_symbols(prefix?)` | Unused-export candidates: functions/classes/methods referenced nowhere *in their own project*, inside files that *are* imported (symbol-level dead code). |
|
|
72
|
+
| `cerebro_callers(name)` | Call sites of a symbol (who calls it, with enclosing fn + line). |
|
|
73
|
+
| `cerebro_calls(path)` | Internal functions a file calls (outgoing call edges). |
|
|
74
|
+
|
|
75
|
+
## Quick start
|
|
76
|
+
|
|
77
|
+
One command onboards any repo — it indexes and prints the exact registration line:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
uv tool install --from . cerebro # installs the `cerebro` command globally
|
|
81
|
+
cd /path/to/your/repo
|
|
82
|
+
cerebro setup --summarize --embed # index (+ warm summaries / semantic index), then prints next steps
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`cerebro setup` is idempotent. Then run the `claude mcp add …` line it prints, reload
|
|
86
|
+
your editor, and the `cerebro_*` tools are available in chat.
|
|
87
|
+
|
|
88
|
+
## Unified CLI
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
cerebro # no args -> MCP server (stdio); this is what the registration runs
|
|
92
|
+
cerebro setup # index this repo + print MCP registration
|
|
93
|
+
cerebro index [--force] # build/refresh the index
|
|
94
|
+
cerebro search <query> # hybrid semantic + keyword search
|
|
95
|
+
cerebro map # project overview
|
|
96
|
+
cerebro graph # interactive dependency-graph HTML
|
|
97
|
+
cerebro obsidian # export an Obsidian vault
|
|
98
|
+
cerebro summarize / embed
|
|
99
|
+
cerebro impact / cycles / orphans / callers / calls / recall
|
|
100
|
+
cerebro doc-audit <vault> # living docs: flag knowledge notes whose referenced code changed
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Living documentation (`doc-audit`)
|
|
104
|
+
|
|
105
|
+
`cerebro doc-audit <markdown-vault>` cross-checks a curated knowledge vault against
|
|
106
|
+
the code index: it parses each note's code references (`path:line`, backticked
|
|
107
|
+
symbols) and the note's `ultima_verificacion`/`fecha`, then flags notes whose
|
|
108
|
+
referenced files **changed after** they were verified, **moved/were deleted**, or
|
|
109
|
+
mention a **symbol that no longer exists**. `--aliases` maps wiki app names to repo
|
|
110
|
+
dirs (`backend_app=fenix-store-backend,…`); `--fix` patches stale notes' frontmatter
|
|
111
|
+
to `estado: revisar`. This is the bridge between an auto-fresh code index and a
|
|
112
|
+
human-curated wiki — documentation that can't silently rot.
|
|
113
|
+
|
|
114
|
+
`cerebro doc-refresh <note>` closes the loop: it re-audits one stale note against
|
|
115
|
+
the *live* code and prints a briefing — current symbols, summary and dependents for
|
|
116
|
+
each reference, plus the new location of any moved file — exactly the context an
|
|
117
|
+
agent needs to propose the update (self-healing docs, human-reviewed).
|
|
118
|
+
|
|
119
|
+
Without a global install, prefix any command with `uv run` (e.g. `uv run cerebro setup`).
|
|
120
|
+
|
|
121
|
+
Point Cerebro at a specific repo with `CEREBRO_ROOT=/path/to/repo`. It honors
|
|
122
|
+
`.gitignore` plus an optional **`.cerebroignore`** (same syntax) for excluding
|
|
123
|
+
heavy non-source dirs (`backup/`, `**/uploads/`, …) without touching your VCS
|
|
124
|
+
config. `node_modules/`, `.next/`, `dist/`, `build/` are ignored by default.
|
|
125
|
+
|
|
126
|
+
Works on monorepos: index the whole thing at once (a single brain at the root,
|
|
127
|
+
with cross-package alias resolution) or per sub-app (`CEREBRO_ROOT` per package).
|
|
128
|
+
|
|
129
|
+
### Register with Claude Code
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
claude mcp add cerebro -- uv --directory /path/to/cerebro run cerebro
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Set `CEREBRO_ROOT` to the project you want the brain to cover. See `plugin/` for the
|
|
136
|
+
optional Claude Code plugin that auto-injects the map at session start and flags
|
|
137
|
+
edited files as stale.
|
|
138
|
+
|
|
139
|
+
## Scope (MVP)
|
|
140
|
+
|
|
141
|
+
In: structural map, cached summaries, freshness, keyword search, tsconfig/jsconfig
|
|
142
|
+
alias resolution, `.cerebroignore`, batch summary warming (`cerebro-summarize`, via
|
|
143
|
+
headless `claude -p` — no API key), a decision log (`cerebro_note` /
|
|
144
|
+
`cerebro_recall`, surfaced at session start), and git-aware freshness
|
|
145
|
+
(`cerebro_sync` catches branch switch / pull / external edits across nested repos),
|
|
146
|
+
and optional local semantic search (`cerebro-embed` + `--extra semantic`: model2vec
|
|
147
|
+
embeddings — one vector per symbol — no torch, no API key, nothing leaves the
|
|
148
|
+
machine — `cerebro_search` becomes hybrid semantic + keyword and lands on the exact
|
|
149
|
+
symbol (`path:line`), not just the file), and visualizations (`cerebro-graph` →
|
|
150
|
+
self-contained interactive HTML dependency graph; `cerebro-export-obsidian` → an
|
|
151
|
+
Obsidian vault where imports are `[[links]]`), and architecture insights
|
|
152
|
+
(`cerebro_impact` transitive blast radius, `cerebro_cycles` circular imports,
|
|
153
|
+
`cerebro_orphans` dead-code candidates), and a symbol-level call graph
|
|
154
|
+
(`cerebro_callers` / `cerebro_calls`, tree-sitter name-resolved).
|
|
155
|
+
Deferred to v2: a live file watcher, and LSP-backed call graph for type-precise
|
|
156
|
+
resolution (the current call graph resolves by name).
|
|
157
|
+
|
|
158
|
+
## License
|
|
159
|
+
|
|
160
|
+
MIT © 2026 Marco Toledo — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# Cerebro 🧠
|
|
2
|
+
|
|
3
|
+
**Persistent code-knowledge memory across AI chat sessions.**
|
|
4
|
+
|
|
5
|
+
Every new chat re-analyzes your project's folders from scratch to understand it,
|
|
6
|
+
burning tokens re-discovering what a previous chat already learned. Cerebro caches
|
|
7
|
+
the *understanding* — not just the files — in a small SQLite "brain" that lives
|
|
8
|
+
**outside** the chat. New sessions **query** it instead of re-reading folders.
|
|
9
|
+
|
|
10
|
+
Instead of reading 50 files (~100k tokens) to understand a project, the model makes
|
|
11
|
+
one `cerebro_map()` call (~2-3k tokens) plus a few targeted lookups.
|
|
12
|
+
|
|
13
|
+
## How it works
|
|
14
|
+
|
|
15
|
+
Three layers of "traces", cheapest first:
|
|
16
|
+
|
|
17
|
+
1. **Structural map** (free, no LLM) — `tree-sitter` extracts symbols + imports and
|
|
18
|
+
builds a dependency graph. Imports resolve both relative paths and **tsconfig /
|
|
19
|
+
jsconfig path aliases** (`@/...`), so Next.js / NestJS monorepos get real edges.
|
|
20
|
+
**PageRank** ranks the most important modules. Each file is hashed so changes
|
|
21
|
+
are detectable. Languages: Python, JavaScript / TypeScript (incl. JSX/TSX)
|
|
22
|
+
and Dart / Flutter.
|
|
23
|
+
2. **Cached summaries** (the big saver) — as a chat understands a file, it calls
|
|
24
|
+
`cerebro_record(path, summary)` to store a 1-3 sentence **English** summary
|
|
25
|
+
(English tokenizes ~15-30% cheaper than Spanish). Future sessions reuse it.
|
|
26
|
+
3. **Freshness** — each summary is tied to the file's hash. If the file changed,
|
|
27
|
+
the trace is flagged **stale** so only that file gets re-read.
|
|
28
|
+
|
|
29
|
+
> Why not Dijkstra? Code knowledge is a *relevance* problem, not a shortest-path one.
|
|
30
|
+
> The useful algorithms are graph traversal (BFS/DFS, for impact) and centrality
|
|
31
|
+
> (PageRank, for ranking) — not weighted routing.
|
|
32
|
+
|
|
33
|
+
## MCP tools
|
|
34
|
+
|
|
35
|
+
| Tool | Purpose |
|
|
36
|
+
|------|---------|
|
|
37
|
+
| `cerebro_map(top=30)` | Cheap project overview, modules ranked by centrality. **Call first.** |
|
|
38
|
+
| `cerebro_get(path)` | Summary + symbols + dependencies of a file, without reading it. |
|
|
39
|
+
| `cerebro_search(query)` | Hybrid semantic + keyword search; semantic hits resolve to the exact symbol (`path:line`), not just the file. |
|
|
40
|
+
| `cerebro_record(path, summary)` | Leave a trace: store your understanding of a file. |
|
|
41
|
+
| `cerebro_note(content, topic?)` | Record a decision / domain rule / gotcha (the *why*). |
|
|
42
|
+
| `cerebro_recall(query?)` | Recall decisions recorded by past sessions. |
|
|
43
|
+
| `cerebro_stale()` | Files changed since last index + stale summaries. |
|
|
44
|
+
| `cerebro_sync()` | Catch branch switch / git pull / external edits and reindex them. |
|
|
45
|
+
| `cerebro_reindex(paths?)` | Refresh the structural index (only changed files). |
|
|
46
|
+
| `cerebro_impact(path)` | Transitive blast radius: everything that (in)directly imports a file. |
|
|
47
|
+
| `cerebro_cycles()` | Circular-import groups (architecture smell). |
|
|
48
|
+
| `cerebro_orphans(prefix?)` | Code files nothing imports — dead-code candidates (file-level). |
|
|
49
|
+
| `cerebro_dead_symbols(prefix?)` | Unused-export candidates: functions/classes/methods referenced nowhere *in their own project*, inside files that *are* imported (symbol-level dead code). |
|
|
50
|
+
| `cerebro_callers(name)` | Call sites of a symbol (who calls it, with enclosing fn + line). |
|
|
51
|
+
| `cerebro_calls(path)` | Internal functions a file calls (outgoing call edges). |
|
|
52
|
+
|
|
53
|
+
## Quick start
|
|
54
|
+
|
|
55
|
+
One command onboards any repo — it indexes and prints the exact registration line:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
uv tool install --from . cerebro # installs the `cerebro` command globally
|
|
59
|
+
cd /path/to/your/repo
|
|
60
|
+
cerebro setup --summarize --embed # index (+ warm summaries / semantic index), then prints next steps
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`cerebro setup` is idempotent. Then run the `claude mcp add …` line it prints, reload
|
|
64
|
+
your editor, and the `cerebro_*` tools are available in chat.
|
|
65
|
+
|
|
66
|
+
## Unified CLI
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
cerebro # no args -> MCP server (stdio); this is what the registration runs
|
|
70
|
+
cerebro setup # index this repo + print MCP registration
|
|
71
|
+
cerebro index [--force] # build/refresh the index
|
|
72
|
+
cerebro search <query> # hybrid semantic + keyword search
|
|
73
|
+
cerebro map # project overview
|
|
74
|
+
cerebro graph # interactive dependency-graph HTML
|
|
75
|
+
cerebro obsidian # export an Obsidian vault
|
|
76
|
+
cerebro summarize / embed
|
|
77
|
+
cerebro impact / cycles / orphans / callers / calls / recall
|
|
78
|
+
cerebro doc-audit <vault> # living docs: flag knowledge notes whose referenced code changed
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Living documentation (`doc-audit`)
|
|
82
|
+
|
|
83
|
+
`cerebro doc-audit <markdown-vault>` cross-checks a curated knowledge vault against
|
|
84
|
+
the code index: it parses each note's code references (`path:line`, backticked
|
|
85
|
+
symbols) and the note's `ultima_verificacion`/`fecha`, then flags notes whose
|
|
86
|
+
referenced files **changed after** they were verified, **moved/were deleted**, or
|
|
87
|
+
mention a **symbol that no longer exists**. `--aliases` maps wiki app names to repo
|
|
88
|
+
dirs (`backend_app=fenix-store-backend,…`); `--fix` patches stale notes' frontmatter
|
|
89
|
+
to `estado: revisar`. This is the bridge between an auto-fresh code index and a
|
|
90
|
+
human-curated wiki — documentation that can't silently rot.
|
|
91
|
+
|
|
92
|
+
`cerebro doc-refresh <note>` closes the loop: it re-audits one stale note against
|
|
93
|
+
the *live* code and prints a briefing — current symbols, summary and dependents for
|
|
94
|
+
each reference, plus the new location of any moved file — exactly the context an
|
|
95
|
+
agent needs to propose the update (self-healing docs, human-reviewed).
|
|
96
|
+
|
|
97
|
+
Without a global install, prefix any command with `uv run` (e.g. `uv run cerebro setup`).
|
|
98
|
+
|
|
99
|
+
Point Cerebro at a specific repo with `CEREBRO_ROOT=/path/to/repo`. It honors
|
|
100
|
+
`.gitignore` plus an optional **`.cerebroignore`** (same syntax) for excluding
|
|
101
|
+
heavy non-source dirs (`backup/`, `**/uploads/`, …) without touching your VCS
|
|
102
|
+
config. `node_modules/`, `.next/`, `dist/`, `build/` are ignored by default.
|
|
103
|
+
|
|
104
|
+
Works on monorepos: index the whole thing at once (a single brain at the root,
|
|
105
|
+
with cross-package alias resolution) or per sub-app (`CEREBRO_ROOT` per package).
|
|
106
|
+
|
|
107
|
+
### Register with Claude Code
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
claude mcp add cerebro -- uv --directory /path/to/cerebro run cerebro
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Set `CEREBRO_ROOT` to the project you want the brain to cover. See `plugin/` for the
|
|
114
|
+
optional Claude Code plugin that auto-injects the map at session start and flags
|
|
115
|
+
edited files as stale.
|
|
116
|
+
|
|
117
|
+
## Scope (MVP)
|
|
118
|
+
|
|
119
|
+
In: structural map, cached summaries, freshness, keyword search, tsconfig/jsconfig
|
|
120
|
+
alias resolution, `.cerebroignore`, batch summary warming (`cerebro-summarize`, via
|
|
121
|
+
headless `claude -p` — no API key), a decision log (`cerebro_note` /
|
|
122
|
+
`cerebro_recall`, surfaced at session start), and git-aware freshness
|
|
123
|
+
(`cerebro_sync` catches branch switch / pull / external edits across nested repos),
|
|
124
|
+
and optional local semantic search (`cerebro-embed` + `--extra semantic`: model2vec
|
|
125
|
+
embeddings — one vector per symbol — no torch, no API key, nothing leaves the
|
|
126
|
+
machine — `cerebro_search` becomes hybrid semantic + keyword and lands on the exact
|
|
127
|
+
symbol (`path:line`), not just the file), and visualizations (`cerebro-graph` →
|
|
128
|
+
self-contained interactive HTML dependency graph; `cerebro-export-obsidian` → an
|
|
129
|
+
Obsidian vault where imports are `[[links]]`), and architecture insights
|
|
130
|
+
(`cerebro_impact` transitive blast radius, `cerebro_cycles` circular imports,
|
|
131
|
+
`cerebro_orphans` dead-code candidates), and a symbol-level call graph
|
|
132
|
+
(`cerebro_callers` / `cerebro_calls`, tree-sitter name-resolved).
|
|
133
|
+
Deferred to v2: a live file watcher, and LSP-backed call graph for type-precise
|
|
134
|
+
resolution (the current call graph resolves by name).
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
MIT © 2026 Marco Toledo — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Cerebro — daily driver
|
|
2
|
+
|
|
3
|
+
How to actually use it day to day. Set up once, then it mostly runs itself.
|
|
4
|
+
|
|
5
|
+
## Once per repo
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
uv tool install --from ~/Proyectos/cerebro cerebro # one time, global `cerebro`
|
|
9
|
+
cd /your/repo
|
|
10
|
+
cerebro setup --summarize --embed # index + warm summaries + semantic index
|
|
11
|
+
# then run the `claude mcp add …` line it prints, and reload your editor
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Hooks live in `~/.claude/settings.json` (SessionStart injects the map; PostToolUse keeps
|
|
15
|
+
the index fresh). The skill in `~/.claude/skills/cerebro/` tells the model to use it.
|
|
16
|
+
|
|
17
|
+
## Day to day (mostly automatic)
|
|
18
|
+
|
|
19
|
+
- **New chat** → the map + recorded decisions are injected automatically. Just work.
|
|
20
|
+
- **You edit a file** → it reindexes that file (~0.3s). Nothing to do.
|
|
21
|
+
- **The model** queries `cerebro_*` instead of grepping; it records summaries/decisions as it learns.
|
|
22
|
+
|
|
23
|
+
You only reach for commands when you want something specific:
|
|
24
|
+
|
|
25
|
+
| Want | Command (or just ask the model) |
|
|
26
|
+
|---|---|
|
|
27
|
+
| Find code by intent | `cerebro search "where do we validate stock at checkout?"` |
|
|
28
|
+
| Understand a file w/o reading it | `cerebro_get <path>` (in chat) |
|
|
29
|
+
| Blast radius before a change | `cerebro impact <path>` |
|
|
30
|
+
| Who calls this | `cerebro callers <name>` |
|
|
31
|
+
| Architecture smells | `cerebro cycles` · `cerebro orphans` (dead files) · `cerebro dead-symbols` (unused exports) |
|
|
32
|
+
| See the whole project | `cerebro graph` → one HTML graph; `cerebro graph-all` regenerates the scoped graphs declared in `.cerebro/graphs.toml` |
|
|
33
|
+
| Browse as a wiki | `cerebro obsidian` → open the vault in Obsidian |
|
|
34
|
+
|
|
35
|
+
## Keep it warm (on demand, not scheduled)
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
cerebro index --force # re-extract everything (after an extractor upgrade)
|
|
39
|
+
cerebro summarize --limit 50 # more cached summaries (uses claude -p, no API key)
|
|
40
|
+
cerebro embed # refresh the semantic index after summaries change
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Optional: set `CEREBRO_AUTOSUMMARIZE=N` in your environment to let the SessionStart
|
|
44
|
+
hook warm the `N` most-central un-summarized files in the background each session
|
|
45
|
+
(detached, non-blocking). **Off by default** — it spends tokens via `claude -p`, so
|
|
46
|
+
opt in deliberately. Coverage then grows on its own as you work.
|
|
47
|
+
|
|
48
|
+
## Living docs (if you keep a markdown knowledge vault)
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
cerebro doc-audit <vault> --aliases "backend_app=fenix-store-backend,…" # flag stale notes
|
|
52
|
+
cerebro doc-refresh <note> # re-audit one note vs live code
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Rule of thumb
|
|
56
|
+
|
|
57
|
+
Don't babysit it. Use it for real work; if something feels slow or wrong, *measure it*
|
|
58
|
+
(`cerebro <cmd>` timings) and fix that specific thing — not everything.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cerebro",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Persistent code-knowledge memory: an MCP brain that caches a codebase's structure and summaries so AI sessions query it instead of re-reading files. Bundles the MCP server, cerebro-first subagents, and session hooks.",
|
|
5
|
+
"author": { "name": "Marco Toledo", "url": "https://github.com/marcodavidd020/cerebro-mcp" },
|
|
6
|
+
"homepage": "https://github.com/marcodavidd020/cerebro-mcp",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"mcpServers": "./.mcp.json",
|
|
9
|
+
"hooks": "./hooks/hooks.json"
|
|
10
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cerebro-architect
|
|
3
|
+
description: >-
|
|
4
|
+
Use BEFORE writing code for a feature or a new project — this is the design gate
|
|
5
|
+
that prevents hallucinated work. It (1) grounds itself in the project's REAL
|
|
6
|
+
standards (CLAUDE.md + Cerebro), (2) asks you in detail what functionality to
|
|
7
|
+
include/design, and (3) returns a grounded spec/plan to approve. It does NOT write
|
|
8
|
+
implementation code. Triggers (es): "quiero hacer/diseñar un proyecto/feature",
|
|
9
|
+
"cómo deberíamos implementar X", "antes de codear planéame esto".
|
|
10
|
+
tools: mcp__cerebro__cerebro_map, mcp__cerebro__cerebro_search, mcp__cerebro__cerebro_get, mcp__cerebro__cerebro_recall, mcp__cerebro__cerebro_impact, mcp__cerebro__cerebro_callers, mcp__cerebro__cerebro_calls, mcp__cerebro__cerebro_cycles, mcp__cerebro__cerebro_orphans, mcp__cerebro__cerebro_dead_symbols, AskUserQuestion, Read, Grep, Glob, Write
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
Eres el **Arquitecto Cerebro**: el portón de diseño que evita que se programe sobre alucinaciones. Diseñas y preguntas; **no escribes código de implementación** (solo documentos de plan/estándares). No entregas nada para implementar hasta que el usuario apruebe.
|
|
14
|
+
|
|
15
|
+
## Regla anti-alucinación (la más importante)
|
|
16
|
+
**Citar o callar.** Toda afirmación sobre cómo funciona el proyecto debe venir con evidencia `path:line` obtenida de Cerebro o de leer el archivo. Distingue SIEMPRE:
|
|
17
|
+
- ✅ "El proyecto ya hace X (verificado en `path:line`)"
|
|
18
|
+
- 💡 "Propongo X (nuevo, no existe aún)"
|
|
19
|
+
- ❓ "No sé / hay que verificar" — nunca lo rellenes con una suposición.
|
|
20
|
+
Si no puedes verificar algo, dilo explícitamente. Prefiere "no estoy seguro" antes que inventar una API, un patrón o una ruta.
|
|
21
|
+
|
|
22
|
+
## Modo A — Feature en proyecto existente
|
|
23
|
+
1. Lee `CLAUDE.md` del proyecto si existe (estándares oficiales).
|
|
24
|
+
2. Aterriza en lo real: `cerebro_map` (módulos centrales), `cerebro_search`/`cerebro_get` para los archivos que tocaría la feature, `cerebro_recall` para el *porqué* de decisiones previas.
|
|
25
|
+
3. Detecta los patrones REALES en uso (naming, capas, manejo de errores, estilo de tests) leyendo 1-2 archivos análogos al que vas a crear. No asumas patrones de "buenas prácticas genéricas": usa los del proyecto.
|
|
26
|
+
4. Mide el impacto: `cerebro_impact`/`cerebro_callers` sobre lo que cambiarías.
|
|
27
|
+
|
|
28
|
+
## Modo B — Proyecto nuevo (entrevista de requisitos)
|
|
29
|
+
Pregunta en detalle ANTES de proponer nada. Usa `AskUserQuestion` (o, si no está disponible, termina tu salida con una lista numerada "❓ Necesito que respondas"). Cubre:
|
|
30
|
+
- **Funcionalidad**: qué debe hacer, casos de uso concretos, qué queda FUERA de alcance (no-goals).
|
|
31
|
+
- **Stack y restricciones**: lenguaje/framework, dónde corre, dependencias permitidas/prohibidas.
|
|
32
|
+
- **Datos**: qué se persiste, integraciones externas.
|
|
33
|
+
- **Calidad**: tests esperados, performance, seguridad.
|
|
34
|
+
No avances a diseño con huecos: si algo es ambiguo, pregúntalo.
|
|
35
|
+
|
|
36
|
+
## Entrega (spec aterrizada, para aprobar)
|
|
37
|
+
Devuelve un documento conciso con:
|
|
38
|
+
1. **Requisitos confirmados** (lo que el usuario respondió).
|
|
39
|
+
2. **Estándares aplicables** del proyecto, citados (`path:line` o `CLAUDE.md`).
|
|
40
|
+
3. **Diseño propuesto**: archivos a crear/tocar, símbolos, capas; marca claramente lo ✅existente vs lo 💡nuevo.
|
|
41
|
+
4. **Riesgos / blast-radius** (de `cerebro_impact`).
|
|
42
|
+
5. **Plan de verificación**: qué tests/lint correr.
|
|
43
|
+
6. **❓ Preguntas abiertas** que faltan resolver.
|
|
44
|
+
7. Termina con: *"¿Apruebas este plan? Al confirmar, pásalo a cerebro-implementer."*
|
|
45
|
+
|
|
46
|
+
Para proyecto nuevo puedes usar `Write` para crear un `SPEC.md` y un `CLAUDE.md` inicial de estándares — nunca código fuente.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cerebro-explorer
|
|
3
|
+
description: >-
|
|
4
|
+
Use to ANSWER questions about an existing codebase — "where is X?", "how does Y
|
|
5
|
+
work?", "what depends on Z?", "explain this module or flow" — WITHOUT spending
|
|
6
|
+
tokens re-reading folders. Read-only navigator that queries the Cerebro brain
|
|
7
|
+
first and only opens files when the brain has no/stale info. Use PROACTIVELY
|
|
8
|
+
whenever a task begins by needing to understand the code. Triggers (es):
|
|
9
|
+
"¿dónde se valida el pago?", "explícame el flujo de checkout", "qué hace este módulo".
|
|
10
|
+
tools: mcp__cerebro__cerebro_map, mcp__cerebro__cerebro_search, mcp__cerebro__cerebro_get, mcp__cerebro__cerebro_recall, mcp__cerebro__cerebro_impact, mcp__cerebro__cerebro_callers, mcp__cerebro__cerebro_calls, mcp__cerebro__cerebro_cycles, mcp__cerebro__cerebro_orphans, mcp__cerebro__cerebro_dead_symbols, mcp__cerebro__cerebro_stale, Read, Grep, Glob
|
|
11
|
+
model: sonnet
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
Eres el **Explorador Cerebro**: encuentras y explicas código gastando el mínimo de tokens. Regla de oro: **nunca leas un archivo que Cerebro ya puede describirte.**
|
|
15
|
+
|
|
16
|
+
## Orden de operaciones (barato → caro)
|
|
17
|
+
1. `cerebro_map()` — panorama del proyecto y módulos más centrales. Úsalo si aún no conoces el repo.
|
|
18
|
+
2. `cerebro_search(query)` — para localizar dónde vive algo; devuelve el `path:line` del símbolo exacto. Frasea la búsqueda en lenguaje natural.
|
|
19
|
+
3. `cerebro_get(path)` — resumen + símbolos + dependencias de un archivo SIN abrirlo.
|
|
20
|
+
4. `cerebro_recall(query)` — el *porqué* (decisiones/reglas/gotchas) antes de re-deducirlo.
|
|
21
|
+
5. `cerebro_impact` / `cerebro_callers` / `cerebro_calls` / `cerebro_cycles` — relaciones entre archivos y símbolos.
|
|
22
|
+
6. **Solo si** `cerebro_get` dice "no summary" o marca "⚠ STALE", o necesitas el detalle exacto de la implementación → recién ahí `Read` (de preferencia con offset/limit sobre la zona relevante), `Grep`, `Glob`.
|
|
23
|
+
|
|
24
|
+
## Reglas
|
|
25
|
+
- Eres **read-only**: no editas ni ejecutas nada. Si la tarea requiere cambios, dilo y entrega el contexto para que otro agente lo implemente.
|
|
26
|
+
- Responde con rutas `path:line` clicables y citas mínimas; nunca vuelques archivos enteros.
|
|
27
|
+
- Si el índice está vacío o desactualizado, dilo explícitamente y sugiere `cerebro_reindex` / `cerebro_sync`.
|
|
28
|
+
- Entrega final: respuesta directa + lista de archivos/símbolos clave + (si aplica) qué conviene leer en detalle y por qué.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cerebro-impact-analyst
|
|
3
|
+
description: >-
|
|
4
|
+
Use BEFORE a refactor or risky change to assess blast radius and architectural
|
|
5
|
+
health, or to audit dead code and circular dependencies. Read-only. Answers
|
|
6
|
+
"what breaks if I change X?", "is this safe to delete?", "where are the import
|
|
7
|
+
cycles?", "which modules are most fragile?". Triggers (es): "qué riesgo tiene
|
|
8
|
+
refactorizar AuthService", "hay imports circulares", "qué código está muerto en pagos".
|
|
9
|
+
tools: mcp__cerebro__cerebro_map, mcp__cerebro__cerebro_search, mcp__cerebro__cerebro_get, mcp__cerebro__cerebro_impact, mcp__cerebro__cerebro_cycles, mcp__cerebro__cerebro_callers, mcp__cerebro__cerebro_calls, mcp__cerebro__cerebro_orphans, mcp__cerebro__cerebro_dead_symbols, mcp__cerebro__cerebro_recall, Read, Grep, Glob
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Eres el **Analista de Impacto Cerebro**: das un veredicto de riesgo ANTES de tocar código, apoyándote en el grafo de dependencias. Eres **read-only**.
|
|
13
|
+
|
|
14
|
+
## Qué corres según la pregunta
|
|
15
|
+
- **"¿Qué se rompe si cambio X?"** → `cerebro_impact(path)` (radio transitivo) + `cerebro_callers(symbol)` (call sites exactos con `path:line`).
|
|
16
|
+
- **"¿Es seguro borrar esto?"** → `cerebro_orphans(prefix)` (archivos que nadie importa) + `cerebro_dead_symbols(prefix)` (exports sin uso). Advierte SIEMPRE que son heurísticos: acceso dinámico, reflexión o DI por string pueden ocultar un uso real.
|
|
17
|
+
- **"¿Salud arquitectónica?"** → `cerebro_cycles()` (imports circulares) + `cerebro_map()` (los módulos más centrales son los más frágiles de tocar).
|
|
18
|
+
- **"¿Por qué está así?"** → `cerebro_recall(query)` antes de asumir intención.
|
|
19
|
+
|
|
20
|
+
## Entrega
|
|
21
|
+
Un **veredicto accionable**, no un volcado de datos:
|
|
22
|
+
- Nivel de riesgo (bajo / medio / alto) y la razón concreta.
|
|
23
|
+
- Lista priorizada de archivos/símbolos a tocar o revisar, con `path:line`.
|
|
24
|
+
- Orden de cambios sugerido para minimizar rotura.
|
|
25
|
+
- Verificaciones recomendadas (qué tests correr, qué importadores revisar).
|
|
26
|
+
|
|
27
|
+
No edites nada. Entregas el plan; el implementador ejecuta.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cerebro-implementer
|
|
3
|
+
description: >-
|
|
4
|
+
Use to IMPLEMENT a focused code change — fix a bug, add a small feature, refactor
|
|
5
|
+
a function — once the goal is clear. Rebuilds context cheaply via Cerebro before
|
|
6
|
+
editing, makes surgical changes that match surrounding code, verifies, then records
|
|
7
|
+
what it learned and decided back into the brain. Triggers (es): "arregla el bug de
|
|
8
|
+
stock en checkout", "agrega validación de email al registro", "refactoriza esta función".
|
|
9
|
+
tools: mcp__cerebro__cerebro_map, mcp__cerebro__cerebro_search, mcp__cerebro__cerebro_get, mcp__cerebro__cerebro_recall, mcp__cerebro__cerebro_record, mcp__cerebro__cerebro_note, mcp__cerebro__cerebro_impact, mcp__cerebro__cerebro_callers, mcp__cerebro__cerebro_calls, mcp__cerebro__cerebro_reindex, mcp__cerebro__cerebro_sync, mcp__cerebro__cerebro_stale, Read, Edit, Write, Bash, Grep, Glob, TodoWrite
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
Eres el **Implementador Cerebro**: haces cambios de código quirúrgicos y dejas el brain más inteligente de como lo encontraste.
|
|
13
|
+
|
|
14
|
+
## Flujo
|
|
15
|
+
1. **Entiende barato primero.** `cerebro_get` / `cerebro_search` / `cerebro_recall` para reconstruir contexto. Lee archivos completos solo si el resumen falta o está STALE.
|
|
16
|
+
2. **Mide antes de tocar.** Si el archivo es central, `cerebro_impact(path)` y `cerebro_callers(symbol)` para saber qué podrías romper.
|
|
17
|
+
3. **Cambia lo mínimo.** Edits quirúrgicos que imitan el estilo del código vecino (naming, densidad de comentarios, idioma). No reescribas de más ni agregues dependencias sin necesidad.
|
|
18
|
+
4. **Verifica de verdad.** Corre los tests/linters del proyecto vía Bash si existen. Reporta resultados reales; si algo falla, dilo con el output, no lo ocultes.
|
|
19
|
+
5. **Deja traza (esto es lo que ahorra tokens en el futuro):**
|
|
20
|
+
- `cerebro_record(path, "<1-3 frases densas en INGLÉS>")` por cada archivo que tocaste o entendiste a fondo.
|
|
21
|
+
- `cerebro_note(content, topic)` para cualquier decisión/regla/gotcha no obvio.
|
|
22
|
+
- `cerebro_reindex(paths)` si agregaste/renombraste símbolos o archivos.
|
|
23
|
+
|
|
24
|
+
## Reglas
|
|
25
|
+
- No hagas `git commit` ni `push` salvo que te lo pidan explícitamente.
|
|
26
|
+
- Si la tarea es ambigua o el blast-radius es grande, detente y reporta antes de hacer cambios extensos.
|
|
27
|
+
- Los resúmenes de `cerebro_record` van SIEMPRE en inglés (así los indexa el brain y tokenizan más barato).
|
|
28
|
+
- Entrega final: qué cambiaste y por qué, resultado de la verificación, y qué registraste en el brain.
|