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 CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <h1 align="center">🧠 cc-brain</h1>
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="#commands">Commands</a> β€’
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 β€” gone.
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 │────▢│ Brain Loaded │────▢│ You Work... β”‚
89
+ β”‚ Session Start │────>β”‚ Brain Loaded │────>β”‚ You Work... β”‚
89
90
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
90
91
  β”‚
91
92
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
92
- β”‚ Next Session │◀────│ Brain Saved β”‚β—€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
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 # Show statistics
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 '{"t2": {"focus": "testing"}}'
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 Β© [tripzcodes](https://github.com/tripzcodes)
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",
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": "./bin/cc-brain.js"
7
+ "cc-brain": "bin/cc-brain.js"
8
8
  },
9
9
  "files": [
10
10
  "bin",
@@ -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
 
@@ -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)) {