Commit Graph
8 Commits
Author SHA1 Message Date
Claude 68ab3309bc Memory › Usage: which memories the agents actually use
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
2026-11-28 20:01:49 +00:00
Louis RailleandClaude Sonnet 4.6 9fdf5ece58 brain: claude-export — ingest Claude Desktop conversations
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>
2026-11-27 20:09:03 +01:00
Louis RailleandClaude Sonnet 4.6 5145557bee brain: dedupResults — seuil 0.40 pour ❌ même projet (fix 404 double injection)
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>
2026-11-27 19:12:51 +01:00
Louis RailleandClaude Sonnet 4.6 15100202ad brain: dedup fix + dual query ❌/pref + git tracking + no-remote guard
- elements.ts: dedupElements bug fix (discard breaks inner loop), constraints
  (same kind, same project, ❌ ≠ active), DedupJournalEntry, threshold 0.7
- hooks/brain-prompt.js: dual SQL query (priority ❌/pref bypass LIMIT 30),
  uniform minMatches (removed effectiveMinMatches reduction), sort bonus ❌/pref,
  dedupResults Jaccard 0.5
- cli.ts: assertNoRemote guard on ingest/enrich/dedup/reset; dedup journal;
  pre-op gitCommit before enrich + dedup (replaces tar backup)
- write.ts: dedupElements call after mergeElements in updateProjectFromSession;
  selective .gitignore (track .state/proj/*.json, ignore binaries/logs)
- tests: 144 passing (dedupElements constraints, Jaccard, hooks false positives)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-11-27 18:57:21 +01:00
Louis RailleandClaude Sonnet 4.6 ccb09310c9 brain: keywords field, FTS mesures fix, collect filters, enrich command, regression tests
- elements.ts: add `keywords` field (6-10 FR+EN search terms) to schema + StoredElement
- fts.ts: index keywords_text as FTS5 column; remove hardcoded mesure exclusion (now opt-in via excludeMesures flag)
- digest.ts: prompt brain to generate keywords with domain/synonym coverage; fix notch annotation wording
- collect.ts: filter <task-notification>, <system-reminder>, <parameter> and toolu_… tool-id lines
- cli.ts: add `brain enrich` command to backfill keywords on existing state files
- brain-prompt.js: remove AND kind != 'mesure' (mesures now injectable)
- tests: add newsletter mesure element, 4 regression tests (design/migration/newsletter/math), fix 50→80ms threshold

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-11-27 04:09:44 +01:00
Louis RailleandClaude Sonnet 4.6 75fe235fc0 brain: anti-contamination — 3 gardes + isolation tests + intégration
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>
2026-11-27 02:56:44 +01:00
Louis RailleandClaude Sonnet 4.6 051fab0e13 brain: hooks — stopwords FR étendu, seuils same-project -0.5 / cross-project -6.0
- brain-prompt.js : même projet requiert score <= -0.5 (pas de ghost match BM25)
- brain-prompt.js : cross-project tightened -3.5 → -6.0 (bloque intégrale*/intégralement)
- brain-prompt.js + fts.ts : stopwords FR étendus (comment, pourquoi, toujours, faut…)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-11-27 02:45:20 +01:00
Louis RailleandClaude Sonnet 4.6 a8d0e713c8 brain: step 2 — MCP server + hooks (FTS5, corrections, pause)
- brain/src/fts.ts : index FTS5 SQLite (BM25 OR-query, diacritics, stopwords FR+EN,
  prefix queries, cross-project threshold -6.0, mesures exclues, session dedup)
- brain/src/mcp/server.ts : serveur MCP stdio 6 outils (brain_index, brain_search,
  brain_project, brain_rules, brain_get, brain_correct)
- brain/hooks/brain-session-start.js : hook SessionStart (~1500 tokens, corrections
  global+projet, décisions actives, tâches ouvertes, guard COUCOU_BRAIN_INTERNAL)
- brain/hooks/brain-prompt.js : hook UserPromptSubmit (FTS < 280 ms, 5 résultats
  ~1000 tokens, dedup session, guard interne)
- brain/hooks/package.json : force CJS pour les hooks dans le paquet ESM
- brain/launchd/fr.louisraille.brain-ingest.plist : agent launchd horaire
- brain/src/cli.ts : commandes mcp, fts (debug), pause, resume, doctor + correct
  --scope + rebuild FTS après ingest/rebuild
- brain/tests/fts.test.ts + hooks.test.ts : 114 tests, 5 suites

Validé sur 4 scénarios : portfo/bento ✅, sbe-hub/migration ✅,
reels/corrections ✅, math sans rapport → rien ✅

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-11-27 02:41:25 +01:00