brain now counts every memory that reaches an agent, in .state/usage.jsonl on the Mac:
the SessionStart and prompt hooks write the ids they inject, the MCP tools the ids they
return (a search or a get counts as the agent picking it; brain_rules doesn't). The
prompt hook's old lines in hooks.log are read too, so the page isn't empty on day one.
`brain usage --json` gives the uses of the last 30 days, the share of memory that ever
served, the most used, the most useful (come back in the most sessions, an agent's own
search counts double) and the ones that never served.
New page Memory › Usage shows it, with the Statistics page's cards and bars.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LJm3SRL9k3gBPaVtfPhwcT
Adds `brain ingest --claude-export <path>` to process the official
claude.ai data export (zip or folder with conversations.json).
- Same mask → digest → elements → FTS pipeline as code sessions
- Incremental by uuid + updated_at (re-ingests if conversation updated)
- Elements tagged sourceType="desktop" in StoredElement + FTS source_type
- Hook never injects desktop elements outside their current project
- 20 new tests (164 total)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Deux décisions ❌ du même projet avec Jaccard ≥ 0.40 → une seule injectée.
Cross-project ou non-❌ : seuil reste à 0.50.
Jaccard réel des deux 404 CRT : 0.413 (< 0.45, > 0.40).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Racine : COUCOU_BRAIN_INTERNAL n'est pas relayé par Claude Code aux hooks.
3 gardes en défense en profondeur :
1. Env flag COUCOU_BRAIN_INTERNAL (best-effort, inchangé)
2. CWD guard : cwd dans brainPath → exit 0 (bloque .state/digestion)
3. Slug blacklist : digestion|brain-security|state|tmp → exit 0
4. Marker guard brain-prompt : <!-- coucou-brain-internal --> → exit 0
digest.ts : passe explicitement COUCOU_BRAIN_INTERNAL=1 dans l'env
du subprocess claude (belt-and-suspenders si Claude Code le transmet).
Tests (hooks.test.ts) :
- BRAIN_LOG_FILE=/dev/null dans runHook() → les invocations de test
n'écrivent plus dans hooks.log
- 5 nouveaux tests CWD guard (digestion cwd, marker, slug blacklist)
- Test intégration anti-contamination : simule un appel de digestion
sans BRAIN_LOG_FILE=/dev/null et vérifie 0 nouvelles lignes dans hooks.log
Contamination passée : 3 sessions (f811f8a8, a1132e9e, 7623086b) étaient
des security-trap tests, pas des digestions réelles — aucune fiche contaminée.
119/119 tests.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>