opencode-branch-memory-manager 0.1.0

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 ADDED
@@ -0,0 +1,500 @@
1
+ # 🧠 OpenCode Branch Memory Manager
2
+
3
+ Automatically manages branch-specific context for OpenCode so you never lose your development context when switching branches.
4
+
5
+ ## ✨ Features
6
+
7
+ - 🔄 **Automatic Context Loading**: Loads saved context when switching branches (configurable)
8
+ - 💾 **Automatic Saving**: Auto-saves context on tool execution, session updates, and branch changes
9
+ - 🎛️ **Manual Control**: Save/load context with fine-grained filters
10
+ - 💾 **Branch-Specific Storage**: Context saved per git branch
11
+ - 📊 **Status Dashboard**: See all your saved contexts at a glance
12
+ - 🛡️ **Error Resilient**: Automatic backups and recovery from corrupted data
13
+ - 🌐 **Cross-Platform**: Works seamlessly on macOS, Linux, and Windows
14
+ - 📋 **List & Delete**: Manage saved contexts easily
15
+ - 🎯 **Configurable**: Customize auto-save behavior, context loading mode, and storage options
16
+
17
+ ## 🚀 Quick Start
18
+
19
+ ### Installation
20
+
21
+ #### Option 1: npm Package (Recommended)
22
+
23
+ **macOS/Linux:**
24
+ ```bash
25
+ bunx install @davecodes/opencode-branch-memory-manager
26
+ ```
27
+
28
+ **Windows (PowerShell):**
29
+ ```powershell
30
+ bunx install @davecodes/opencode-branch-memory-manager
31
+ ```
32
+
33
+ The plugin and tools will be automatically loaded when you run `opencode`. Add to your `opencode.json`:
34
+
35
+ ```json
36
+ {
37
+ "plugin": ["@davecodes/opencode-branch-memory-manager"]
38
+ }
39
+ ```
40
+
41
+ **Note:** This will add the plugin without removing any existing plugins you have.
42
+
43
+ #### Option 2: Local Installation
44
+
45
+ **macOS/Linux:**
46
+ ```bash
47
+ curl -fsSL https://raw.githubusercontent.com/Davidcreador/opencode-branch-memory-manager/main/install.sh | bash
48
+ ```
49
+
50
+ **Windows (PowerShell):**
51
+ ```powershell
52
+ irm https://raw.githubusercontent.com/Davidcreador/opencode-branch-memory-manager/main/install.ps1 | iex
53
+ ```
54
+
55
+ The plugin and tools will be automatically loaded when you run `opencode`. No configuration needed.
56
+
57
+ ### Getting Started
58
+
59
+ ```bash
60
+ opencode
61
+
62
+ # Check status
63
+ @branch-memory_status
64
+
65
+ # Save current context with filters
66
+ @branch-memory_save --include-messages --include-todos --include-files "Working on user authentication"
67
+
68
+ # Load context for a specific branch
69
+ @branch-memory_load --branch feature/payment-api
70
+
71
+ # List all saved contexts
72
+ @branch-memory_list --verbose
73
+ ```
74
+
75
+ ## 📖 Commands
76
+
77
+ ### @branch-memory_save
78
+
79
+ Save current session context for current git branch.
80
+
81
+ **Arguments:**
82
+ - `--include-messages`: Include conversation messages (default: true)
83
+ - `--include-todos`: Include todo items (default: true)
84
+ - `--include-files`: Include modified files (default: true)
85
+ - `--description`: Description of what you're saving
86
+
87
+ **Examples:**
88
+ ```
89
+ # Save everything
90
+ @branch-memory_save "Adding Stripe integration"
91
+
92
+ # Save only messages and todos
93
+ @branch-memory_save --include-messages --include-todos "Quick checkpoint"
94
+
95
+ # Save only files
96
+ @branch-memory_save --include-files "API work"
97
+ ```
98
+
99
+ ### @branch-memory_load
100
+
101
+ Load branch-specific context into current session.
102
+
103
+ **Arguments:**
104
+ - `--branch`: Branch name (default: current branch)
105
+
106
+ **Examples:**
107
+ ```
108
+ # Load current branch context
109
+ @branch-memory_load
110
+
111
+ # Load specific branch context
112
+ @branch-memory_load --branch feature/authentication
113
+ ```
114
+
115
+ ### @branch-memory_status
116
+
117
+ Show branch memory status and available contexts.
118
+
119
+ **Examples:**
120
+ ```
121
+ @branch-memory_status
122
+ ```
123
+
124
+ **Output:**
125
+ ```
126
+ 📊 Branch Memory Status
127
+ ═════════════════
128
+
129
+ Current branch: feature/user-auth
130
+ Current context:
131
+ 📝 Messages: 23
132
+ ✅ Todos: 7
133
+ 📁 Files: 5
134
+ 💾 Size: 2.3KB
135
+ ⏰ Saved: 2025-01-01T14:30:00.000Z
136
+ 📄 Description: Adding user authentication with OAuth
137
+
138
+ Available contexts:
139
+ → feature/user-auth (2.3KB, 2025-01-01T14:30:00)
140
+ → feature/payment-api (4.1KB, 2025-01-01T15:45:00)
141
+ main (1.8KB, 2025-01-01T12:00:00.000Z)
142
+ ```
143
+
144
+ ### @branch-memory_deleteContext
145
+
146
+ Delete saved context for a branch.
147
+
148
+ **Arguments:**
149
+ - `--branch`: Branch name to delete context for
150
+
151
+ **Example:**
152
+ ```
153
+ @branch-memory_deleteContext --branch old-feature
154
+ ```
155
+
156
+ ### @branch-memory_list
157
+
158
+ List all branches with saved contexts.
159
+
160
+ **Arguments:**
161
+ - `--verbose`: Show detailed information including message, todo, and file counts
162
+
163
+ **Examples:**
164
+ ```
165
+ @branch-memory_list
166
+
167
+ # With verbose details
168
+ @branch-memory_list --verbose
169
+ ```
170
+
171
+ **Output (verbose):**
172
+ ```
173
+ 📋 Branches with saved contexts
174
+ ═════════════════
175
+
176
+ feature/user-auth
177
+ 💾 Size: 2.3KB
178
+ ⏰ Modified: 2025-01-01T14:30:00
179
+ 📝 Messages: 23
180
+ ✅ Todos: 7
181
+ 📁 Files: 5
182
+
183
+ feature/payment-api
184
+ 💾 Size: 4.1KB
185
+ ⏰ Modified: 2025-01-01T15:45:00
186
+ 📝 Messages: 31
187
+ ✅ Todos: 12
188
+ 📁 Files: 8
189
+
190
+ main
191
+ 💾 Size: 1.8KB
192
+ ⏰ Modified: 2025-01-01T12:00:00
193
+ 📝 Messages: 15
194
+ ✅ Todos: 3
195
+ 📁 Files: 2
196
+
197
+ ═════════════════
198
+ Total: 3 branch(es)
199
+ ```
200
+
201
+ ## ⚙️ Configuration
202
+
203
+ Configuration is stored in `.opencode/config/branch-memory.json`
204
+
205
+ ### Default Configuration
206
+
207
+ ```json
208
+ {
209
+ "autoSave": {
210
+ "enabled": true,
211
+ "onMessageChange": true,
212
+ "onBranchChange": true,
213
+ "onToolExecute": true
214
+ },
215
+ "contextLoading": "auto",
216
+ "context": {
217
+ "defaultInclude": ["messages", "todos", "files"],
218
+ "maxMessages": 50,
219
+ "maxTodos": 20,
220
+ "compression": false
221
+ },
222
+ "storage": {
223
+ "maxBackups": 5,
224
+ "retentionDays": 90
225
+ },
226
+ "monitoring": {
227
+ "method": "both",
228
+ "pollingInterval": 1000
229
+ }
230
+ }
231
+ ```
232
+
233
+ ### Configuration Options
234
+
235
+ #### autoSave
236
+ - `enabled`: Enable/disable automatic saving (default: `true`)
237
+ - `onMessageChange`: Auto-save when messages change (default: `true`)
238
+ - `onBranchChange`: Auto-save when switching branches (default: `true`)
239
+ - `onToolExecute`: Auto-save before running tools (default: `true`)
240
+
241
+ #### contextLoading
242
+ - `"auto"`: Automatically load context when switching branches
243
+ - `"ask"`: Prompt user before loading context
244
+ - `"manual"`: Don't auto-load; use `@branch-memory_load` manually
245
+
246
+ #### context
247
+ - `defaultInclude`: Array of data types to include by default
248
+ - `maxMessages`: Maximum number of messages to save (default: 50)
249
+ - `maxTodos`: Maximum number of todos to save (default: 20)
250
+ - `compression`: Enable compression (not yet implemented)
251
+
252
+ #### storage
253
+ - `maxBackups`: Number of backups to keep (default: 5)
254
+ - `retentionDays`: Days to keep old contexts (default: 90)
255
+
256
+ #### monitoring
257
+ - `"watcher"`: Use file watcher only (fast, uses chokidar)
258
+ - `"polling"`: Use polling only (reliable, slower)
259
+ - `"both"`: Use watcher with polling fallback (default)
260
+
261
+ ## 🔧 How It Works
262
+
263
+ 1. **Initialization**: Plugin loads configuration from `.opencode/config/branch-memory.json`
264
+ 2. **Automatic Features** (when plugin is loaded):
265
+ - Auto-loads context when a new session starts (configurable)
266
+ - Auto-saves before tool execution
267
+ - Auto-saves on session updates (throttled)
268
+ - Monitors for git branch changes and auto-loads/saves
269
+ 3. **Manual Saving**: Use `@branch-memory_save` to save context:
270
+ - Saves conversation messages
271
+ - Saves todo items
272
+ - Saves modified file references
273
+ 4. **Manual Loading**: Use `@branch-memory_load` to restore context:
274
+ - Loads messages and todos
275
+ - Shows what was saved
276
+ 5. **Status Checking**: Use `@branch-memory_status` to see:
277
+ - Current branch and context
278
+ - All saved contexts
279
+ - Metadata (size, dates, counts)
280
+ 6. **Error Recovery**: Automatic backups prevent data loss
281
+ 7. **Management**: Use `@branch-memory_list` and `@branch-memory_deleteContext` to manage saved contexts
282
+
283
+ ## 🐛 Troubleshooting
284
+
285
+ ### Tools not available
286
+
287
+ 1. Check if tools are in `opencode.json`:
288
+ ```json
289
+ {
290
+ "tools": ["@branch-memory_save", "@branch-memory_load", "@branch-memory_status", "@branch-memory_list", "@branch-memory_deleteContext"]
291
+ }
292
+ ```
293
+
294
+ 2. Verify dependencies are installed:
295
+ ```bash
296
+ cd .opencode
297
+ bun install
298
+ ```
299
+
300
+ ### Context not saving
301
+
302
+ 1. Check if in a git repository:
303
+ ```bash
304
+ git status
305
+ ```
306
+
307
+ 2. Check configuration:
308
+ ```bash
309
+ cat .opencode/config/branch-memory.json
310
+ ```
311
+
312
+ 3. Check logs for errors:
313
+ ```bash
314
+ # Look for emoji indicators:
315
+ # ✅ = success
316
+ # ⚠️ = warning
317
+ # ❌ = error
318
+ ```
319
+
320
+ ### Branch changes not detected
321
+
322
+ 1. Verify git repository:
323
+ ```bash
324
+ git rev-parse --git-dir
325
+ ```
326
+
327
+ 2. Check `.git/HEAD` file exists and is being updated
328
+
329
+ 3. Try both monitoring modes:
330
+ ```json
331
+ {
332
+ "monitoring": {
333
+ "method": "watcher" // or "polling"
334
+ }
335
+ }
336
+ ```
337
+
338
+ ### Corrupted context files
339
+
340
+ The system automatically restores from backups. If issues persist:
341
+
342
+ 1. Check backup files:
343
+ ```bash
344
+ ls -la .opencode/branch-memory/
345
+ ```
346
+
347
+ 2. Manual cleanup:
348
+ ```bash
349
+ @branch-memory_deleteContext --branch broken-branch
350
+ ```
351
+
352
+ ### Permission errors
353
+
354
+ 1. Check file permissions:
355
+ ```bash
356
+ ls -la .opencode/branch-memory/
357
+ ```
358
+
359
+ 2. Ensure write access:
360
+ ```bash
361
+ chmod -R u+w .opencode/branch-memory/
362
+ ```
363
+
364
+ ## 📁 File Structure
365
+
366
+ ```
367
+ .opencode/
368
+ ├── plugin/
369
+ │ └── branch-memory-plugin.ts # Event hooks for auto-save/load
370
+ ├── tool/
371
+ │ └── branch-memory.ts # User-facing tools
372
+ ├── branch-memory/
373
+ │ ├── index.ts # Exports
374
+ │ ├── storage.ts # Context persistence
375
+ │ ├── git.ts # Git operations
376
+ │ ├── monitor.ts # Branch monitoring
377
+ │ ├── collector.ts # Context collection
378
+ │ ├── injector.ts # Context injection
379
+ │ ├── types.ts # TypeScript types
380
+ │ └── config.ts # Configuration
381
+ ├── config/
382
+ │ └── branch-memory.json # Configuration file
383
+ └── package.json # Dependencies
384
+ ```
385
+
386
+ ## 🚀 Advanced Usage
387
+
388
+ ### Custom Configuration
389
+
390
+ Edit `.opencode/config/branch-memory.json` to customize behavior:
391
+
392
+ ```json
393
+ {
394
+ "autoSave": {
395
+ "enabled": true,
396
+ "onMessageChange": true,
397
+ "onBranchChange": true,
398
+ "onToolExecute": true
399
+ },
400
+ "contextLoading": "ask",
401
+ "context": {
402
+ "defaultInclude": ["messages", "todos", "files"],
403
+ "maxMessages": 100,
404
+ "maxTodos": 50
405
+ }
406
+ }
407
+ ```
408
+
409
+ ### Workflow Example
410
+
411
+ 1. **Start working on a feature:**
412
+ ```bash
413
+ git checkout -b feature/user-profile
414
+ opencode
415
+ ```
416
+
417
+ 2. **Context auto-loads on session start (if contextLoading is "auto"):**
418
+ ```
419
+ 🚀 Session created - checking for saved context...
420
+ 📥 Found context for branch 'feature/user-profile'
421
+ Use @branch-memory_load to restore it
422
+ ```
423
+
424
+ 3. **Work on feature - context auto-saves as you work:**
425
+ ```bash
426
+ # Plugin auto-saves before tool execution and periodically
427
+ @branch-memory_save "Adding user profile feature"
428
+ ```
429
+
430
+ 4. **Switch to main to work on bug fix:**
431
+ ```bash
432
+ git checkout main
433
+ # Plugin detects branch change
434
+ 🔄 Branch changed: feature/user-profile → main
435
+ 💾 Saved context for old branch 'feature/user-profile'
436
+ 📥 Found context for branch 'main'
437
+ ```
438
+
439
+ 5. **Switch back to feature - context auto-loads:**
440
+ ```bash
441
+ git checkout feature/user-profile
442
+ # Plugin detects branch change
443
+ 🔄 Branch changed: main → feature/user-profile
444
+ 📥 Found context for branch 'feature/user-profile'
445
+ Use @branch-memory_load to restore it
446
+ ```
447
+
448
+ 6. **Or manually load context:**
449
+ ```bash
450
+ @branch-memory_load
451
+
452
+ # Context is restored - messages and todos are back
453
+ ```
454
+
455
+ ## 🛠️ Development
456
+
457
+ ### Build
458
+
459
+ ```bash
460
+ bun install
461
+ bun run build
462
+ ```
463
+
464
+ This compiles TypeScript files from `src/` to `dist/`.
465
+
466
+ ### Type Check
467
+
468
+ ```bash
469
+ bun run typecheck
470
+ ```
471
+
472
+ ### Testing
473
+
474
+ ```bash
475
+ bun test
476
+ ```
477
+
478
+ ## 📦 Publishing to npm
479
+
480
+ 1. Update version in `package.json`
481
+ 2. Build: `bun run build`
482
+ 3. Publish: `npm publish`
483
+
484
+ Make sure you're logged in to npm: `npm whoami`
485
+
486
+ ## 📝 License
487
+
488
+ MIT License - see [LICENSE](LICENSE) file for details.
489
+
490
+ ## 🤝 Contributing
491
+
492
+ Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
493
+
494
+ ## 🐛 Issues
495
+
496
+ Found a bug? Have a feature request? Please open an issue on GitHub.
497
+
498
+ ---
499
+
500
+ Made with ❤️ for the OpenCode community
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "opencode-branch-memory-manager",
3
+ "version": "0.1.0",
4
+ "description": "Automatically manages branch-specific context for OpenCode with auto-save, auto-load, and git workflow integration",
5
+ "author": "Davidcreador",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/Davidcreador/opencode-branch-memory-manager.git"
13
+ },
14
+ "homepage": "https://github.com/Davidcreador/opencode-branch-memory-manager#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/Davidcreador/opencode-branch-memory-manager/issues"
17
+ },
18
+ "files": [
19
+ ".opencode"
20
+ ],
21
+ "scripts": {
22
+ "build": "npm run build:local",
23
+ "build:npm": "cd src && bun install --no-lockfile && bun build index.ts --outdir ../dist --target node",
24
+ "build:local": "bun build .opencode/tool/branch-memory.ts --outdir .opencode/dist --target node",
25
+ "typecheck": "tsc --noEmit --project tsconfig.typecheck.json --skipLibCheck",
26
+ "test": "bun test",
27
+ "test:coverage": "bun test --coverage",
28
+ "lint": "eslint src tests --ext .ts",
29
+ "lint:fix": "eslint src tests --ext .ts --fix",
30
+ "clean": "rm -rf dist node_modules src/node_modules",
31
+ "prepublishOnly": "npm run clean && npm run build"
32
+ },
33
+ "keywords": [
34
+ "opencode",
35
+ "opencode-plugin",
36
+ "branch-memory",
37
+ "context",
38
+ "git",
39
+ "auto-save",
40
+ "workspace"
41
+ ],
42
+ "dependencies": {
43
+ "chokidar": "^4.0.0",
44
+ "zod": "^3.22.0"
45
+ },
46
+ "devDependencies": {
47
+ "@opencode-ai/plugin": "^1.0.0",
48
+ "@types/node": "^20.0.0",
49
+ "typescript": "^5.0.0"
50
+ },
51
+ "peerDependencies": {
52
+ "@opencode-ai/plugin": ">=1.0.0"
53
+ },
54
+ "engines": {
55
+ "node": ">=18.0.0",
56
+ "bun": ">=1.0.0"
57
+ },
58
+ "directories": {
59
+ "test": "tests"
60
+ }
61
+ }