ocerebro 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +288 -0
- package/bin/ocerebro.js +98 -0
- package/cerebro/__init__.py +7 -0
- package/cerebro/__main__.py +19 -0
- package/cerebro/cerebro_setup.py +459 -0
- package/hooks/__init__.py +1 -0
- package/hooks/cost_hook.py +45 -0
- package/hooks/coverage_hook.py +39 -0
- package/hooks/error_hook.py +48 -0
- package/hooks/expensive_hook.py +41 -0
- package/hooks/global_logger.py +32 -0
- package/package.json +49 -0
- package/pyproject.toml +77 -0
- package/src/__init__.py +2 -0
- package/src/cli/__init__.py +2 -0
- package/src/cli/dream.py +91 -0
- package/src/cli/gc.py +93 -0
- package/src/cli/main.py +583 -0
- package/src/cli/remember.py +74 -0
- package/src/consolidation/__init__.py +8 -0
- package/src/consolidation/checkpoints.py +96 -0
- package/src/consolidation/dream.py +465 -0
- package/src/consolidation/extractor.py +313 -0
- package/src/consolidation/promoter.py +435 -0
- package/src/consolidation/remember.py +544 -0
- package/src/consolidation/scorer.py +191 -0
- package/src/core/__init__.py +6 -0
- package/src/core/event_schema.py +55 -0
- package/src/core/jsonl_storage.py +238 -0
- package/src/core/paths.py +254 -0
- package/src/core/session_manager.py +76 -0
- package/src/diff/__init__.py +5 -0
- package/src/diff/memory_diff.py +571 -0
- package/src/forgetting/__init__.py +6 -0
- package/src/forgetting/decay.py +86 -0
- package/src/forgetting/gc.py +296 -0
- package/src/forgetting/guard_rails.py +126 -0
- package/src/hooks/__init__.py +11 -0
- package/src/hooks/core_captures.py +170 -0
- package/src/hooks/custom_loader.py +389 -0
- package/src/index/__init__.py +7 -0
- package/src/index/embeddings_db.py +419 -0
- package/src/index/metadata_db.py +230 -0
- package/src/index/queries.py +357 -0
- package/src/mcp/__init__.py +2 -0
- package/src/mcp/server.py +640 -0
- package/src/memdir/__init__.py +19 -0
- package/src/memdir/scanner.py +260 -0
- package/src/official/__init__.py +5 -0
- package/src/official/markdown_storage.py +173 -0
- package/src/official/templates.py +128 -0
- package/src/working/__init__.py +5 -0
- package/src/working/memory_view.py +150 -0
- package/src/working/yaml_storage.py +234 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OARANHA
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
# OCerebro 🧠
|
|
2
|
+
|
|
3
|
+
**Sistema de Memória para Agentes (Claude Code/MCP)**
|
|
4
|
+
|
|
5
|
+
OCerebro dá memória persistente e capacidade de aprendizado para o Claude Code. Ele captura automaticamente todo o contexto das sessões, consolida em memória estruturada e permite busca semântica com sqlite-vec.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## ✨ Funcionalidades
|
|
10
|
+
|
|
11
|
+
- 📦 **Memória Automática 3 Camadas**: Raw → Working → Official
|
|
12
|
+
- 🔍 **Busca Híbrida**: Texto (FTS5) + Semântica (sqlite-vec ANN)
|
|
13
|
+
- 🤖 **MCP Server**: 6 ferramentas para Claude Code
|
|
14
|
+
- 🎣 **Hooks Customizáveis**: Extensível via YAML
|
|
15
|
+
- 📊 **RFM Scoring**: Relevância temporal e importância
|
|
16
|
+
- 🛡️ **Guard Rails**: Proteções para não deletar importante
|
|
17
|
+
- 💾 **SQLite Nativo**: Zero dependências externas, zero infra
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 🚀 Instalação Rápida
|
|
22
|
+
|
|
23
|
+
### Pré-requisitos
|
|
24
|
+
|
|
25
|
+
- Python 3.10+
|
|
26
|
+
- Claude Desktop (opcional, para integração MCP)
|
|
27
|
+
|
|
28
|
+
### Passo 1: Instalar
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install ocerebro
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Ou instale localmente:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
git clone https://github.com/OARANHA/ocerebro.git
|
|
38
|
+
cd ocerebro
|
|
39
|
+
pip install .
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Passo 2: Setup Automático
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Em seu projeto
|
|
46
|
+
ocerebro init
|
|
47
|
+
|
|
48
|
+
# Configura Claude Desktop automaticamente
|
|
49
|
+
ocerebro setup claude
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Pronto!** Reinicie o Claude Desktop e as ferramentas estarão disponíveis.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 📖 Uso
|
|
57
|
+
|
|
58
|
+
### No Terminal
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Ver status do sistema
|
|
62
|
+
ocerebro status
|
|
63
|
+
|
|
64
|
+
# Ver memória de um projeto
|
|
65
|
+
ocerebro memory meu-projeto
|
|
66
|
+
|
|
67
|
+
# Buscar por texto
|
|
68
|
+
ocerebro search "autenticação JWT"
|
|
69
|
+
|
|
70
|
+
# Criar checkpoint manual
|
|
71
|
+
ocerebro checkpoint meu-projeto --reason "antes de refatorar"
|
|
72
|
+
|
|
73
|
+
# Promover decisão para official
|
|
74
|
+
ocerebro promote meu-projeto sess_abc123
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### No Claude Code (MCP)
|
|
78
|
+
|
|
79
|
+
Com o MCP Server configurado, você tem acesso a:
|
|
80
|
+
|
|
81
|
+
| Ferramenta | Descrição |
|
|
82
|
+
|------------|-----------|
|
|
83
|
+
| `cerebro_memory` | Gera MEMORY.md do projeto |
|
|
84
|
+
| `cerebro_search` | Busca memórias por texto/embedding |
|
|
85
|
+
| `cerebro_checkpoint` | Cria checkpoint da sessão atual |
|
|
86
|
+
| `cerebro_promote` | Promove draft para decisão official |
|
|
87
|
+
| `cerebro_status` | Status do sistema |
|
|
88
|
+
| `cerebro_hooks` | Gerencia hooks customizados |
|
|
89
|
+
| `cerebro_diff` | Análise diferencial de memória entre períodos |
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 🏗️ Arquitetura
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
┌─────────────────────────────────────────────────────────┐
|
|
97
|
+
│ Claude Code │
|
|
98
|
+
│ ↓ │
|
|
99
|
+
│ MCP Server │
|
|
100
|
+
└─────────────────────────────────────────────────────────┘
|
|
101
|
+
↓
|
|
102
|
+
┌─────────────────────────────────────────────────────────┐
|
|
103
|
+
│ OCerebro │
|
|
104
|
+
│ │
|
|
105
|
+
│ Raw (JSONL) → Working (YAML) → Official (Markdown) │
|
|
106
|
+
│ ↓ ↓ ↓ │
|
|
107
|
+
│ Eventos → Extração → Rascunhos → Memória │
|
|
108
|
+
│ ↓ ↓ │
|
|
109
|
+
│ sqlite-vec ← Busca Híbrida │
|
|
110
|
+
└─────────────────────────────────────────────────────────┘
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## 📁 Estrutura do Projeto
|
|
116
|
+
|
|
117
|
+
No seu projeto, o OCerebro cria:
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
meu-projeto/
|
|
121
|
+
.ocerebro/
|
|
122
|
+
raw/ ← Eventos brutos (JSONL)
|
|
123
|
+
working/ ← Rascunhos YAML
|
|
124
|
+
official/ ← Memória permanente (Markdown)
|
|
125
|
+
index/ ← Banco de dados (metadata + embeddings)
|
|
126
|
+
config/ ← Configurações
|
|
127
|
+
MEMORY.md ← Memória ativa (gerado automaticamente)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## 🎣 Hooks Customizados
|
|
133
|
+
|
|
134
|
+
Crie automações com hooks:
|
|
135
|
+
|
|
136
|
+
### Exemplo: `hooks.yaml`
|
|
137
|
+
|
|
138
|
+
```yaml
|
|
139
|
+
hooks:
|
|
140
|
+
- name: notificar_erro
|
|
141
|
+
event_type: error
|
|
142
|
+
module_path: hooks/error_hook.py
|
|
143
|
+
function: on_error
|
|
144
|
+
config:
|
|
145
|
+
notify_severity: ["critical", "high"]
|
|
146
|
+
|
|
147
|
+
- name: track_custo_llm
|
|
148
|
+
event_type: tool_call
|
|
149
|
+
event_subtype: llm
|
|
150
|
+
module_path: hooks/cost_hook.py
|
|
151
|
+
function: on_llm_call
|
|
152
|
+
config:
|
|
153
|
+
monthly_budget: 100.0
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**Documentação completa:** [docs/HOOKS_GUIDE.md](docs/HOOKS_GUIDE.md)
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## 🔧 Configuração Manual (MCP)
|
|
161
|
+
|
|
162
|
+
Se o setup automático não funcionar, edite `claude_desktop.json`:
|
|
163
|
+
|
|
164
|
+
### Windows
|
|
165
|
+
```
|
|
166
|
+
%APPDATA%\Claude\claude_desktop.json
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### macOS
|
|
170
|
+
```
|
|
171
|
+
~/Library/Application Support/Claude/claude_desktop.json
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Linux
|
|
175
|
+
```
|
|
176
|
+
~/.config/Claude/claude_desktop.json
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**Conteúdo:**
|
|
180
|
+
|
|
181
|
+
```json
|
|
182
|
+
{
|
|
183
|
+
"mcpServers": {
|
|
184
|
+
"ocerebro": {
|
|
185
|
+
"command": "python",
|
|
186
|
+
"args": ["/caminho/para/ocerebro/src/mcp/server.py"],
|
|
187
|
+
"cwd": "/caminho/para/ocerebro"
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## 🧪 Testes
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
# Instalar dependências de teste
|
|
199
|
+
pip install -e ".[test]"
|
|
200
|
+
|
|
201
|
+
# Rodar testes
|
|
202
|
+
pytest
|
|
203
|
+
|
|
204
|
+
# Com coverage
|
|
205
|
+
pytest --cov=src
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
**Status:** 133 testes passando ✅
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## 📊 Estatísticas
|
|
213
|
+
|
|
214
|
+
| Métrica | Valor |
|
|
215
|
+
|---------|-------|
|
|
216
|
+
| Testes | 133 passing |
|
|
217
|
+
| Linhas de código | ~7.700 |
|
|
218
|
+
| Commits | 25+ |
|
|
219
|
+
| Ferramentas MCP | 6 |
|
|
220
|
+
| Tipos de evento | 8+ |
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## 🤝 Contribuindo
|
|
225
|
+
|
|
226
|
+
1. Fork o repositório
|
|
227
|
+
2. Crie uma branch (`git checkout -b feature/minha-feature`)
|
|
228
|
+
3. Commit (`git commit -m 'feat: adiciona nova feature'`)
|
|
229
|
+
4. Push (`git push origin feature/minha-feature`)
|
|
230
|
+
5. Abra um Pull Request
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## 📝 Changelog
|
|
235
|
+
|
|
236
|
+
### v0.1.0 (2026-04-01)
|
|
237
|
+
|
|
238
|
+
- ✅ Arquitetura 3 camadas (Raw → Working → Official)
|
|
239
|
+
- ✅ Extractor e Promoter
|
|
240
|
+
- ✅ EmbeddingsDB + QueryEngine (busca híbrida com sqlite-vec)
|
|
241
|
+
- ✅ CLI completa
|
|
242
|
+
- ✅ MCP Server (6 ferramentas)
|
|
243
|
+
- ✅ Hooks customizados via YAML
|
|
244
|
+
- ✅ 133 testes passing
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## 📚 Documentação
|
|
249
|
+
|
|
250
|
+
- [Guia de Hooks](docs/HOOKS_GUIDE.md)
|
|
251
|
+
- [Spec de Design](docs/superpowers/specs/2026-03-31-cerebro-design.md)
|
|
252
|
+
- [Plano de Implementação](docs/superpowers/plans/2026-03-31-cerebro-implementacao.md)
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## 🙋 FAQ
|
|
257
|
+
|
|
258
|
+
**O OCerebro funciona sem o Claude Desktop?**
|
|
259
|
+
Sim! A CLI funciona independentemente. O MCP Server é opcional.
|
|
260
|
+
|
|
261
|
+
**Posso sincronizar memória entre computadores?**
|
|
262
|
+
Sim! Use Git para sincronizar `official/` e `config/`.
|
|
263
|
+
|
|
264
|
+
**O que acontece se deletar `.ocerebro/`?**
|
|
265
|
+
Você perde a memória local. Se tiver `official/` em backup, pode recuperar.
|
|
266
|
+
|
|
267
|
+
**Funciona em Linux/Mac/Windows?**
|
|
268
|
+
Sim! Testado em todas as plataformas.
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## 📄 Licença
|
|
273
|
+
|
|
274
|
+
MIT License - veja [LICENSE](LICENSE) para detalhes.
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## 🌟 Créditos
|
|
279
|
+
|
|
280
|
+
Criado por [@OARANHA](https://github.com/OARANHA)
|
|
281
|
+
|
|
282
|
+
Feito com ❤️ para a comunidade Claude Code.
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
**Stars:** ⭐ 0 | **Forks:** 🍴 0
|
|
287
|
+
|
|
288
|
+
[Reportar bug](https://github.com/OARANHA/ocerebro/issues) • [Pedir feature](https://github.com/OARANHA/ocerebro/issues)
|
package/bin/ocerebro.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* OCerebro CLI - Node.js wrapper
|
|
4
|
+
*
|
|
5
|
+
* Este script chama a CLI Python do OCerebro.
|
|
6
|
+
* Usa CommonJS para compatibilidade máxima.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const { execSync, spawn } = require('child_process');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
|
|
12
|
+
// Determina o comando Python e valida versão
|
|
13
|
+
function getPythonCmd() {
|
|
14
|
+
const candidates = [];
|
|
15
|
+
|
|
16
|
+
// Tenta python primeiro
|
|
17
|
+
try {
|
|
18
|
+
execSync('python --version', { stdio: 'ignore' });
|
|
19
|
+
candidates.push('python');
|
|
20
|
+
} catch {
|
|
21
|
+
// Tenta python3
|
|
22
|
+
try {
|
|
23
|
+
execSync('python3 --version', { stdio: 'ignore' });
|
|
24
|
+
candidates.push('python3');
|
|
25
|
+
} catch {
|
|
26
|
+
console.error('Erro: Python não encontrado. Por favor instale Python 3.10+');
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Valida versão do Python
|
|
32
|
+
for (const cmd of candidates) {
|
|
33
|
+
try {
|
|
34
|
+
const versionOutput = execSync(`${cmd} --version`, {
|
|
35
|
+
encoding: 'utf-8',
|
|
36
|
+
stdio: ['ignore', 'pipe', 'pipe']
|
|
37
|
+
});
|
|
38
|
+
const match = versionOutput.match(/Python (\d+)\.(\d+)/);
|
|
39
|
+
if (match) {
|
|
40
|
+
const major = parseInt(match[1]);
|
|
41
|
+
const minor = parseInt(match[2]);
|
|
42
|
+
if (major < 3 || (major === 3 && minor < 10)) {
|
|
43
|
+
console.error(`❌ Python ${major}.${minor} detectado.`);
|
|
44
|
+
console.error(' OCerebro requer Python 3.10+');
|
|
45
|
+
console.error(' Baixe em: https://python.org');
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
return cmd;
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Fallback para o primeiro candidato
|
|
56
|
+
return candidates[0];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Encontra o caminho do pacote ocerebro
|
|
60
|
+
function getOcerebroPath(pythonCmd) {
|
|
61
|
+
try {
|
|
62
|
+
// Tenta encontrar via pip show
|
|
63
|
+
const output = execSync(`${pythonCmd} -m pip show ocerebro`, { encoding: 'utf-8' });
|
|
64
|
+
const match = output.match(/Location: (.+)/);
|
|
65
|
+
if (match) {
|
|
66
|
+
return path.join(match[1].trim(), 'ocerebro');
|
|
67
|
+
}
|
|
68
|
+
} catch {
|
|
69
|
+
// Se não estiver instalado via pip, usa path relativo
|
|
70
|
+
return path.join(__dirname, '..');
|
|
71
|
+
}
|
|
72
|
+
return path.join(__dirname, '..');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Argumentos da linha de comando
|
|
76
|
+
const args = process.argv.slice(2);
|
|
77
|
+
|
|
78
|
+
// Comando principal (chamado UMA única vez)
|
|
79
|
+
const pythonCmd = getPythonCmd();
|
|
80
|
+
const ocerebroPath = getOcerebroPath(pythonCmd);
|
|
81
|
+
const cliScript = path.join(ocerebroPath, 'src', 'cli', 'main.py');
|
|
82
|
+
|
|
83
|
+
// Executa a CLI Python
|
|
84
|
+
const pythonArgs = [cliScript, ...args];
|
|
85
|
+
|
|
86
|
+
const proc = spawn(pythonCmd, pythonArgs, {
|
|
87
|
+
stdio: 'inherit',
|
|
88
|
+
cwd: process.cwd()
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
proc.on('close', (code) => {
|
|
92
|
+
process.exit(code);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
proc.on('error', (err) => {
|
|
96
|
+
console.error('Erro ao executar OCerebro:', err.message);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Permite executar como: python -m cerebro setup
|
|
2
|
+
|
|
3
|
+
Comandos:
|
|
4
|
+
python -m cerebro setup - Setup completo
|
|
5
|
+
python -m cerebro setup claude - Configura Claude Desktop
|
|
6
|
+
python -m cerebro setup init - Cria .ocerebro/ e hooks.yaml
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import sys
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
# Adiciona parent ao path para imports
|
|
13
|
+
parent_path = Path(__file__).parent.parent
|
|
14
|
+
sys.path.insert(0, str(parent_path))
|
|
15
|
+
|
|
16
|
+
from cerebro.cerebro_setup import main
|
|
17
|
+
|
|
18
|
+
if __name__ == "__main__":
|
|
19
|
+
main()
|