cc-brain 0.1.3 β 0.1.4
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 +105 -14
- package/package.json +2 -2
- package/scripts/install.js +16 -0
- package/scripts/uninstall.js +12 -0
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<h1 align="center"
|
|
2
|
+
<h1 align="center">cc-brain</h1>
|
|
3
3
|
<p align="center">
|
|
4
4
|
<strong>Persistent memory for Claude Code</strong><br>
|
|
5
5
|
<em>Remember context across sessions</em>
|
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
</p>
|
|
15
15
|
|
|
16
16
|
<p align="center">
|
|
17
|
-
<a href="#installation">Installation</a>
|
|
18
|
-
<a href="#how-it-works">How It Works</a>
|
|
19
|
-
<a href="#
|
|
17
|
+
<a href="#installation">Installation</a> -
|
|
18
|
+
<a href="#how-it-works">How It Works</a> -
|
|
19
|
+
<a href="#architecture">Architecture</a> -
|
|
20
|
+
<a href="#commands">Commands</a> -
|
|
20
21
|
<a href="#cli">CLI</a>
|
|
21
22
|
</p>
|
|
22
23
|
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
|
|
25
26
|
## The Problem
|
|
26
27
|
|
|
27
|
-
Claude Code sessions are **ephemeral**. When context fills up or you start a new session, everything is forgotten. Your preferences, project decisions, debugging history
|
|
28
|
+
Claude Code sessions are **ephemeral**. When context fills up or you start a new session, everything is forgotten. Your preferences, project decisions, debugging history -- gone.
|
|
28
29
|
|
|
29
30
|
## The Solution
|
|
30
31
|
|
|
@@ -70,7 +71,7 @@ claude plugins add cc-brain
|
|
|
70
71
|
βββ projects/{id}/
|
|
71
72
|
βββ context.md # Current project state
|
|
72
73
|
βββ archive/ # Session history
|
|
73
|
-
βββ 2025-01-31.md
|
|
74
|
+
βββ 2025-01-31-143052.md
|
|
74
75
|
```
|
|
75
76
|
|
|
76
77
|
### Memory Tiers
|
|
@@ -85,17 +86,65 @@ claude plugins add cc-brain
|
|
|
85
86
|
|
|
86
87
|
```
|
|
87
88
|
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
|
|
88
|
-
β Session Start
|
|
89
|
+
β Session Start βββββ>β Brain Loaded βββββ>β You Work... β
|
|
89
90
|
βββββββββββββββββββ βββββββββββββββββββ ββββββββββ¬βββββββββ
|
|
90
91
|
β
|
|
91
92
|
βββββββββββββββββββ βββββββββββββββββββ β
|
|
92
|
-
β Next Session
|
|
93
|
+
β Next Session β<βββββ Brain Saved β<ββββββββββββββ
|
|
93
94
|
βββββββββββββββββββ βββββββββββββββββββ
|
|
94
95
|
(before compaction)
|
|
95
96
|
```
|
|
96
97
|
|
|
97
98
|
---
|
|
98
99
|
|
|
100
|
+
## Architecture
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
104
|
+
β Claude Code β
|
|
105
|
+
β β
|
|
106
|
+
β SessionStart hook ββ> loader.js ββ> XML output β
|
|
107
|
+
β β β
|
|
108
|
+
β βββ T1: <user-profile> β
|
|
109
|
+
β βββ T1: <preferences> β
|
|
110
|
+
β βββ T2: <project id="..."> β
|
|
111
|
+
β βββ T3: <archive hint /> β
|
|
112
|
+
β β
|
|
113
|
+
β PreCompact hook ββ> saver.js ββ> atomic writes β
|
|
114
|
+
β β β
|
|
115
|
+
β βββ validates input shape β
|
|
116
|
+
β βββ enforces line limits β
|
|
117
|
+
β βββ warns at 80% capacity β
|
|
118
|
+
β βββ safeWriteFileSync() β
|
|
119
|
+
β β
|
|
120
|
+
β /recall skill ββ> recall.js ββ> scored results β
|
|
121
|
+
β β β
|
|
122
|
+
β βββ regex with safe fallback β
|
|
123
|
+
β βββ header match scoring β
|
|
124
|
+
β βββ TTY-aware color output β
|
|
125
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
126
|
+
β
|
|
127
|
+
v
|
|
128
|
+
~/.claude/brain/ (persistent)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Data Flow
|
|
132
|
+
|
|
133
|
+
1. **SessionStart** - `loader.js` loads T1 + T2 into XML-tagged sections, auto-prunes archives older than 90 days
|
|
134
|
+
2. **PreCompact** - Agent analyzes session, calls `saver.js` with structured JSON payload
|
|
135
|
+
3. **Manual** - `/save` skill triggers the saver, `/recall` searches the archive
|
|
136
|
+
4. **Archive** - Each save creates `YYYY-MM-DD-HHMMSS.md` (one file per session, no collisions)
|
|
137
|
+
|
|
138
|
+
### Design Decisions
|
|
139
|
+
|
|
140
|
+
- **Atomic writes** - All file writes use temp file + rename to prevent corruption
|
|
141
|
+
- **Cross-runtime** - Works in both Node (>=18) and Bun via `isMainModule()` helper
|
|
142
|
+
- **Hook preservation** - Install/uninstall detect cc-brain hooks by content matching, never overwrite user's other hooks
|
|
143
|
+
- **XML output** - Loader wraps content in semantic tags (`<user-profile>`, `<preferences>`, `<project>`) for reliable Claude parsing
|
|
144
|
+
- **Input validation** - Saver checks shape, key names, and types before writing
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
99
148
|
## Commands
|
|
100
149
|
|
|
101
150
|
Use these skills in Claude Code:
|
|
@@ -112,14 +161,15 @@ Use these skills in Claude Code:
|
|
|
112
161
|
|
|
113
162
|
```bash
|
|
114
163
|
# Setup
|
|
115
|
-
cc-brain install # Install hooks
|
|
116
|
-
cc-brain uninstall # Remove hooks
|
|
164
|
+
cc-brain install # Install hooks (merges with existing)
|
|
165
|
+
cc-brain uninstall # Remove hooks (preserves user hooks)
|
|
117
166
|
cc-brain uninstall --purge # Remove everything
|
|
118
167
|
|
|
119
168
|
# Search & Archive
|
|
120
|
-
cc-brain recall "query" # Search archive
|
|
169
|
+
cc-brain recall "query" # Search archive (scored results)
|
|
170
|
+
cc-brain recall "query" --context # Show surrounding lines
|
|
121
171
|
cc-brain archive list # List entries
|
|
122
|
-
cc-brain archive stats #
|
|
172
|
+
cc-brain archive stats # Statistics (avg size, time span)
|
|
123
173
|
cc-brain archive prune --keep 20
|
|
124
174
|
|
|
125
175
|
# Project Identity
|
|
@@ -127,11 +177,52 @@ cc-brain project-id --init # Create stable .brain-id
|
|
|
127
177
|
|
|
128
178
|
# Manual Save
|
|
129
179
|
cc-brain save --dry-run --json '{"t2": {"focus": "testing"}}'
|
|
130
|
-
cc-brain save --json '{"
|
|
180
|
+
cc-brain save --json '{"t3": "Added search functionality"}'
|
|
131
181
|
```
|
|
132
182
|
|
|
133
183
|
---
|
|
134
184
|
|
|
185
|
+
## Project Structure
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
src/
|
|
189
|
+
utils.js Shared utilities (safeWriteFileSync, isMainModule)
|
|
190
|
+
loader.js Loads T1+T2 into XML context, auto-prunes archive
|
|
191
|
+
saver.js Structured saver with validation, limits, atomic writes
|
|
192
|
+
recall.js Scored archive search with safe regex and color detection
|
|
193
|
+
archive.js Archive management (list, prune, stats)
|
|
194
|
+
project-id.js Stable project identity (.brain-id)
|
|
195
|
+
bin/
|
|
196
|
+
cc-brain.js CLI entry point with fast runtime detection
|
|
197
|
+
hooks/
|
|
198
|
+
hooks.json Hook configuration (SessionStart, PreCompact)
|
|
199
|
+
skills/
|
|
200
|
+
save.md /save skill
|
|
201
|
+
recall.md /recall skill
|
|
202
|
+
brain.md /brain skill
|
|
203
|
+
scripts/
|
|
204
|
+
install.js Install hooks (merges, preserves existing)
|
|
205
|
+
uninstall.js Remove hooks (filters cc-brain only)
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Features
|
|
211
|
+
|
|
212
|
+
- **Persistent memory** across sessions and compactions
|
|
213
|
+
- **Structured saving** with JSON validation and dry-run preview
|
|
214
|
+
- **Input validation** with shape checking, key allowlist, type enforcement
|
|
215
|
+
- **Capacity warnings** at 80% of line limits before rejecting
|
|
216
|
+
- **Atomic file writes** via temp + rename to prevent corruption
|
|
217
|
+
- **Scored search** with regex safe fallback and header-weighted ranking
|
|
218
|
+
- **Smart color output** that detects TTY and respects NO_COLOR
|
|
219
|
+
- **Auto-prune** removes archive entries older than 90 days
|
|
220
|
+
- **Hook-safe install** that merges without clobbering user config
|
|
221
|
+
- **Cross-runtime** support for Node (>=18) and Bun
|
|
222
|
+
- **Stable project identity** via `.brain-id` that survives renames
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
135
226
|
## Project Identity
|
|
136
227
|
|
|
137
228
|
By default, projects are identified by directory name. For stable identity that survives renames:
|
|
@@ -162,4 +253,4 @@ cc-brain uninstall --purge # Remove everything
|
|
|
162
253
|
|
|
163
254
|
## License
|
|
164
255
|
|
|
165
|
-
MIT
|
|
256
|
+
MIT - [tripzcodes](https://github.com/tripzcodes)
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cc-brain",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Persistent memory system for Claude Code - remembers context across sessions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"cc-brain": "
|
|
7
|
+
"cc-brain": "bin/cc-brain.js"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"bin",
|
package/scripts/install.js
CHANGED
|
@@ -93,6 +93,22 @@ settings.hooks.PreCompact = mergeHookArray(settings.hooks.PreCompact, hooks.PreC
|
|
|
93
93
|
writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
|
|
94
94
|
console.log(`\nUpdated: ${settingsPath}`);
|
|
95
95
|
|
|
96
|
+
// --- Install Skills to ~/.claude/skills/ ---
|
|
97
|
+
const SKILLS_DIR = join(CLAUDE_DIR, 'skills');
|
|
98
|
+
const skillNames = ['save', 'recall', 'brain'];
|
|
99
|
+
|
|
100
|
+
for (const name of skillNames) {
|
|
101
|
+
const skillDir = join(SKILLS_DIR, name);
|
|
102
|
+
mkdirSync(skillDir, { recursive: true });
|
|
103
|
+
copyFileSync(
|
|
104
|
+
join(PROJECT_ROOT, 'skills', `${name}.md`),
|
|
105
|
+
join(skillDir, 'SKILL.md')
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
console.log(`\nInstalled skills to: ${SKILLS_DIR}`);
|
|
110
|
+
console.log(' /save, /recall, /brain');
|
|
111
|
+
|
|
96
112
|
console.log(`
|
|
97
113
|
cc-brain installed!
|
|
98
114
|
|
package/scripts/uninstall.js
CHANGED
|
@@ -69,6 +69,18 @@ if (existsSync(SETTINGS_PATH)) {
|
|
|
69
69
|
console.log('No settings.json found');
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
// --- Remove Skills from ~/.claude/skills/ ---
|
|
73
|
+
const SKILLS_DIR = join(CLAUDE_DIR, 'skills');
|
|
74
|
+
const skillNames = ['save', 'recall', 'brain'];
|
|
75
|
+
|
|
76
|
+
for (const name of skillNames) {
|
|
77
|
+
const skillDir = join(SKILLS_DIR, name);
|
|
78
|
+
if (existsSync(skillDir)) {
|
|
79
|
+
rmSync(skillDir, { recursive: true, force: true });
|
|
80
|
+
console.log(`Removed: ${skillDir}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
72
84
|
// Optionally remove brain data
|
|
73
85
|
if (purge) {
|
|
74
86
|
if (existsSync(BRAIN_DIR)) {
|