brain-memory 0.1.0-beta.12 → 0.1.0-beta.14
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/README.md +20 -12
- package/bin/install.js +19 -14
- package/bin/memorize.js +379 -0
- package/bin/recall.js +30 -4
- package/bin/reinforce.js +9 -1
- package/commands/brain/memorize.md +57 -187
- package/commands/brain/sync.md +16 -28
- package/package.json +4 -2
- package/prompts/claude.md +11 -20
- package/prompts/gemini.md +11 -20
- package/prompts/openai.md +12 -21
- package/prompts/opencode.md +176 -0
- package/src/installer.js +9 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Brain Memory System
|
|
2
|
+
|
|
3
|
+
This project uses the **Brain Memory** plugin — a hierarchical, file-system-based memory system that mimics human cognition with neuroscience-inspired mechanisms including associative networks, spreading activation, context-dependent recall, spaced reinforcement, and cognitive memory types.
|
|
4
|
+
|
|
5
|
+
## Memory Location
|
|
6
|
+
|
|
7
|
+
All memories are stored in a single global `~/.brain/` directory in the user's home folder, shared across all projects and all supported AI agents. The directory uses a deep nested structure organized by life domains (professional, personal, social, family) with on-demand subcategories.
|
|
8
|
+
|
|
9
|
+
## How It Works
|
|
10
|
+
|
|
11
|
+
### Memory Format
|
|
12
|
+
Each memory is a Markdown file with YAML frontmatter containing: `id`, `type`, `cognitive_type` (episodic/semantic/procedural), `created`, `last_accessed`, `access_count`, `recall_history`, `strength` (0.0-1.0), `decay_rate` (per day), `salience` (0.0-1.0), `confidence` (0.0-1.0), `tags`, `related` memory IDs, `source`, and `encoding_context`.
|
|
13
|
+
|
|
14
|
+
### Strength & Decay Model
|
|
15
|
+
- Memories have a base `strength` set at creation based on their impact/type/cognitive type
|
|
16
|
+
- Strength decays over time: `effective = strength * (decay_rate ^ days_since_access)`
|
|
17
|
+
- Recalled memories get **stronger** via spaced reinforcement — the longer since last recall, the bigger the boost
|
|
18
|
+
- Memories become progressively more forgetting-resistant with each recall (decay_rate improves)
|
|
19
|
+
- Weak memories can be consolidated into stronger combined memories
|
|
20
|
+
- During sleep, global synaptic homeostasis prevents strength inflation
|
|
21
|
+
|
|
22
|
+
### Cognitive Types
|
|
23
|
+
- **Episodic** — Event-specific memories. Higher initial strength, faster decay. The details fade but lessons persist.
|
|
24
|
+
- **Semantic** — Abstracted knowledge. Default decay. Stable long-term storage.
|
|
25
|
+
- **Procedural** — Skills and workflows. Lower initial strength but extremely slow decay once established.
|
|
26
|
+
|
|
27
|
+
### Memory Types & Default Strengths
|
|
28
|
+
| Type | Strength | Decay/day | Description |
|
|
29
|
+
|------|----------|-----------|-------------|
|
|
30
|
+
| decision | 0.85 | 0.995 | Choices made and rationale |
|
|
31
|
+
| insight | 0.90 | 0.997 | Deep realizations, patterns |
|
|
32
|
+
| goal | 0.80 | 0.993 | Objectives and aspirations |
|
|
33
|
+
| experience | 0.75 | 0.985 | Notable events or processes |
|
|
34
|
+
| learning | 0.70 | 0.990 | New knowledge acquired |
|
|
35
|
+
| relationship | 0.70 | 0.997 | Connections between entities |
|
|
36
|
+
| preference | 0.60 | 0.998 | User preferences and style |
|
|
37
|
+
| observation | 0.40 | 0.950 | Casual facts or notices |
|
|
38
|
+
|
|
39
|
+
### Associative Network
|
|
40
|
+
Memories are connected via weighted edges in `~/.brain/associations.json`. When you recall memory A, **spreading activation** automatically surfaces related memories B and C — just like how the brain activates linked neurons. Links are strengthened through **Hebbian learning**: memories recalled together become more tightly connected over time.
|
|
41
|
+
|
|
42
|
+
### Context-Dependent Recall
|
|
43
|
+
Memories store their encoding context (project, topics, task type). During recall, memories encoded in a similar context to the current session are scored higher — matching how human memory works better when recall context matches encoding context.
|
|
44
|
+
|
|
45
|
+
### Salience & Confidence
|
|
46
|
+
- **Salience** (0.0-1.0): Emotional/motivational significance. High-salience memories (>= 0.7) are never auto-pruned.
|
|
47
|
+
- **Confidence** (0.0-1.0): Epistemic certainty. Low-confidence memories are flagged during recall.
|
|
48
|
+
|
|
49
|
+
## Available Commands
|
|
50
|
+
|
|
51
|
+
- `/brain:init` — Initialize the brain structure
|
|
52
|
+
- `/brain:memorize [topic]` — Store memories from current context
|
|
53
|
+
- `/brain:remember [query]` — Recall relevant memories with spreading activation and context matching
|
|
54
|
+
- `/brain:review [scope]` — Spaced repetition review session for due memories
|
|
55
|
+
- `/brain:explore [category]` — Browse the brain hierarchy
|
|
56
|
+
- `/brain:consolidate [scope]` — Merge related weak memories into stronger ones
|
|
57
|
+
- `/brain:forget [target]` — Decay or archive memories
|
|
58
|
+
- `/brain:sunshine [target]` — Deep forensic erasure — trace and remove all references to a memory
|
|
59
|
+
- `/brain:sleep [scope]` — Full maintenance cycle: replay, synaptic homeostasis, knowledge propagation, semantic crystallization, reorganize, consolidate, prune, REM dreaming, and expertise detection
|
|
60
|
+
- `/brain:status` — Dashboard with brain health overview
|
|
61
|
+
- `/brain:sync [subcommand]` — Sync memories via Git remote or export/import for portability
|
|
62
|
+
|
|
63
|
+
## Session Start Behavior
|
|
64
|
+
|
|
65
|
+
**Perform these steps at session start — but keep it lightweight.**
|
|
66
|
+
|
|
67
|
+
If `~/.brain/index.json` exists:
|
|
68
|
+
|
|
69
|
+
1. **Read the index** to get memory count and categories
|
|
70
|
+
2. **Run the recall engine only if the current project has relevant memories:**
|
|
71
|
+
```bash
|
|
72
|
+
brain-recall --context --project "<current project>" --top 5
|
|
73
|
+
```
|
|
74
|
+
If the project is unrelated to any stored memories (e.g., a new project with no matching context), skip the recall and just show the count. Don't waste cycles searching when nothing will match.
|
|
75
|
+
3. **Silently internalize** results — do NOT dump memory contents
|
|
76
|
+
4. **Output a single status line:**
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
🧠 Brain active — <N> memories (<M> in project context)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Only add extra lines if actionable:
|
|
83
|
+
- `📋 <X> due for review` — if review queue has items
|
|
84
|
+
- `⚠️ <N> low-confidence memories used frequently` — if access_count ≥ 3 and confidence < 0.5
|
|
85
|
+
|
|
86
|
+
**The goal is ambient awareness** — know about past decisions, learnings, and preferences without reciting them. Reference them naturally when relevant.
|
|
87
|
+
|
|
88
|
+
## Ambient Session Tracking
|
|
89
|
+
|
|
90
|
+
**Throughout the session, maintain a running mental log of notable events.** This requires no file writes — just internal awareness.
|
|
91
|
+
|
|
92
|
+
Track these categories as they happen:
|
|
93
|
+
- **Decisions** — Architecture choices, technology selections, trade-off resolutions
|
|
94
|
+
- **Learnings** — New patterns, debugging insights, API discoveries
|
|
95
|
+
- **Insights** — Realizations about the codebase, project, or process
|
|
96
|
+
- **Experiences** — Significant events like incidents, deployments, milestones
|
|
97
|
+
- **Goals** — New objectives discussed or planned
|
|
98
|
+
|
|
99
|
+
**Why this matters:** Without active tracking, you can only evaluate what happened at session end — by which point early-session events may be forgotten or the user may have already left. By tracking as events occur, nothing is lost.
|
|
100
|
+
|
|
101
|
+
## Periodic Memory Checkpoint
|
|
102
|
+
|
|
103
|
+
**Every ~10 substantive interactions** (file edits, architecture decisions, debugging breakthroughs, significant discussions — not trivial reads or simple answers), silently evaluate whether your ambient tracking log contains memorizable content.
|
|
104
|
+
|
|
105
|
+
If notable items have accumulated, append a **brief one-liner** at the end of your next natural response:
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
🧠 Notable <type(s)> this session — /brain:memorize when ready
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Rules:**
|
|
112
|
+
- **Never interrupt flow** — only append to the end of a response the user is already receiving, never send as a standalone message
|
|
113
|
+
- **At most once per ~10 substantive interactions** — no spamming
|
|
114
|
+
- **Reset the counter** after the user runs `/brain:memorize`
|
|
115
|
+
- **Don't mention if nothing notable** has accumulated
|
|
116
|
+
- **Be specific about types** — say "decisions and learnings" not just "notable content"
|
|
117
|
+
|
|
118
|
+
## Session End Behavior
|
|
119
|
+
|
|
120
|
+
When a session is ending (user says bye/thanks/done, conversation wraps up, or you sense the interaction is concluding), perform these steps **in order**:
|
|
121
|
+
|
|
122
|
+
### Step 1: Save Session Context (ALWAYS — do this first)
|
|
123
|
+
|
|
124
|
+
**Immediately** append a session summary to `~/.brain/contexts.json`, even for trivial sessions. Context tracking is cheap and provides valuable recall signals for future sessions.
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"session_id": "<timestamp-based-id>",
|
|
129
|
+
"started": "<session start ISO timestamp>",
|
|
130
|
+
"ended": "<session end ISO timestamp>",
|
|
131
|
+
"project": "<current project name>",
|
|
132
|
+
"topics": ["<key topics discussed>"],
|
|
133
|
+
"task_type": "<primary task type>",
|
|
134
|
+
"memories_created": ["<IDs of memories stored this session>"],
|
|
135
|
+
"memories_recalled": ["<IDs of memories retrieved this session>"],
|
|
136
|
+
"notable_unsaved": ["<brief descriptions of notable items NOT yet memorized>"]
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Keep only the last 20 session entries. The `notable_unsaved` field preserves what happened even if the user didn't memorize — future sessions can reference it.
|
|
141
|
+
|
|
142
|
+
### Step 2: Suggest Memorization (if warranted)
|
|
143
|
+
|
|
144
|
+
If the session contained meaningful content based on your ambient tracking:
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
💡 This session contained notable <type(s)>. Would you like to store them as brain memories?
|
|
148
|
+
Run /brain:memorize to capture them before this context is lost.
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Rules:**
|
|
152
|
+
- Do NOT auto-memorize without user consent
|
|
153
|
+
- Do NOT prompt for trivial sessions (quick fixes, typo corrections, simple questions)
|
|
154
|
+
- Only suggest when there is genuinely valuable context worth preserving
|
|
155
|
+
- **Do not wait for explicit session-end signals** — if the conversation appears to be wrapping up, save context proactively
|
|
156
|
+
|
|
157
|
+
## When Recalling Memories
|
|
158
|
+
|
|
159
|
+
When the user asks you to "remember" something, or when context from past sessions would be helpful, use the **deterministic recall engine** instead of manually computing scores:
|
|
160
|
+
|
|
161
|
+
1. Run `brain-recall "<query>" --project <project> --task <task_type> --top 10` (or `node <install-path>/bin/recall.js`)
|
|
162
|
+
2. The engine computes TF-IDF relevance, decayed strength, spreading activation, context match, and salience — all deterministically
|
|
163
|
+
3. Read the top-scoring memory files and present results
|
|
164
|
+
4. Run `brain-reinforce <mem_id1> <mem_id2> ...` to apply spaced reinforcement and Hebbian co-retrieval strengthening
|
|
165
|
+
5. If no matches, search the archive (`~/.brain/_archived/`)
|
|
166
|
+
|
|
167
|
+
The recall engine ensures **identical scoring across all agents** — Claude, Gemini, Codex, and OpenCode all get the same rankings for the same query.
|
|
168
|
+
|
|
169
|
+
## Portable Sync
|
|
170
|
+
|
|
171
|
+
Brain memories can be synced across devices in two ways:
|
|
172
|
+
|
|
173
|
+
1. **Git remote** — Push/pull `~/.brain/` to any private Git repository (GitHub, GitLab, Codeberg, self-hosted). Run `/brain:sync setup <url>` to configure, then use `/brain:sync push` and `/brain:sync pull`.
|
|
174
|
+
2. **Export/Import** — Pack the entire `~/.brain/` into a single portable file for manual transfer. Run `/brain:sync export` and `/brain:sync import <path>`.
|
|
175
|
+
|
|
176
|
+
Both methods support optional AES-256-GCM encryption. Sync is always manual — never automatic.
|
package/src/installer.js
CHANGED
|
@@ -32,6 +32,15 @@ const RUNTIMES = {
|
|
|
32
32
|
promptSource: 'openai.md',
|
|
33
33
|
commandStyle: 'skills',
|
|
34
34
|
},
|
|
35
|
+
opencode: {
|
|
36
|
+
name: 'OpenCode',
|
|
37
|
+
globalDir: path.join(os.homedir(), '.config', 'opencode'),
|
|
38
|
+
localDir: '.opencode',
|
|
39
|
+
commandsSubdir: 'commands',
|
|
40
|
+
promptFile: 'AGENTS.md',
|
|
41
|
+
promptSource: 'opencode.md',
|
|
42
|
+
commandStyle: 'flat',
|
|
43
|
+
},
|
|
35
44
|
};
|
|
36
45
|
|
|
37
46
|
const BRAIN_MARKER_START = '<!-- BRAIN-MEMORY-START -->';
|