claude-mem-opencode 0.0.1

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.
Files changed (59) hide show
  1. package/README.md +391 -0
  2. package/dist/bundle/claude-mem-opencode.js +542 -0
  3. package/dist/bundle/index.d.ts +13 -0
  4. package/dist/bundle/index.d.ts.map +1 -0
  5. package/dist/bundle/index.js.map +1 -0
  6. package/dist/bundle/package.json +10 -0
  7. package/dist/bundle/skill/SKILL.md +118 -0
  8. package/dist/bundle/skill/operations/search.md +178 -0
  9. package/dist/bundle/skill/operations/timeline.md +269 -0
  10. package/dist/bundle/skill/operations/workflow.md +375 -0
  11. package/dist/cli.d.ts +6 -0
  12. package/dist/cli.d.ts.map +1 -0
  13. package/dist/cli.js +164 -0
  14. package/dist/cli.js.map +1 -0
  15. package/dist/integration/context-injector.d.ts +19 -0
  16. package/dist/integration/context-injector.d.ts.map +1 -0
  17. package/dist/integration/context-injector.js +47 -0
  18. package/dist/integration/context-injector.js.map +1 -0
  19. package/dist/integration/event-listeners.d.ts +41 -0
  20. package/dist/integration/event-listeners.d.ts.map +1 -0
  21. package/dist/integration/event-listeners.js +156 -0
  22. package/dist/integration/event-listeners.js.map +1 -0
  23. package/dist/integration/index.d.ts +66 -0
  24. package/dist/integration/index.d.ts.map +1 -0
  25. package/dist/integration/index.js +127 -0
  26. package/dist/integration/index.js.map +1 -0
  27. package/dist/integration/session-mapper.d.ts +39 -0
  28. package/dist/integration/session-mapper.d.ts.map +1 -0
  29. package/dist/integration/session-mapper.js +63 -0
  30. package/dist/integration/session-mapper.js.map +1 -0
  31. package/dist/integration/test.d.ts +6 -0
  32. package/dist/integration/test.d.ts.map +1 -0
  33. package/dist/integration/test.js +73 -0
  34. package/dist/integration/test.js.map +1 -0
  35. package/dist/integration/utils/logger.d.ts +15 -0
  36. package/dist/integration/utils/logger.d.ts.map +1 -0
  37. package/dist/integration/utils/logger.js +26 -0
  38. package/dist/integration/utils/logger.js.map +1 -0
  39. package/dist/integration/utils/privacy.d.ts +32 -0
  40. package/dist/integration/utils/privacy.d.ts.map +1 -0
  41. package/dist/integration/utils/privacy.js +62 -0
  42. package/dist/integration/utils/privacy.js.map +1 -0
  43. package/dist/integration/utils/project-name.d.ts +16 -0
  44. package/dist/integration/utils/project-name.d.ts.map +1 -0
  45. package/dist/integration/utils/project-name.js +28 -0
  46. package/dist/integration/utils/project-name.js.map +1 -0
  47. package/dist/integration/version-checker.d.ts +52 -0
  48. package/dist/integration/version-checker.d.ts.map +1 -0
  49. package/dist/integration/version-checker.js +121 -0
  50. package/dist/integration/version-checker.js.map +1 -0
  51. package/dist/integration/worker-client.d.ts +94 -0
  52. package/dist/integration/worker-client.d.ts.map +1 -0
  53. package/dist/integration/worker-client.js +188 -0
  54. package/dist/integration/worker-client.js.map +1 -0
  55. package/dist/test.d.ts +6 -0
  56. package/dist/test.d.ts.map +1 -0
  57. package/dist/test.js +73 -0
  58. package/dist/test.js.map +1 -0
  59. package/package.json +69 -0
package/README.md ADDED
@@ -0,0 +1,391 @@
1
+ # claude-mem-opencode
2
+
3
+ OpenCode integration for [claude-mem](https://github.com/thedotmack/claude-mem) persistent memory.
4
+
5
+ ## Overview
6
+
7
+ `claude-mem-opencode` automatically captures your OpenCode coding sessions as compressed memories, making them searchable for future sessions. It provides persistent context across sessions with ~10x token efficiency compared to storing full tool outputs.
8
+
9
+ ## Requirements
10
+
11
+ - **Node.js** >= 18.0.0
12
+ - **Bun** >= 1.0.0
13
+ - **claude-mem** >= 8.5.4 (for full functionality)
14
+
15
+ ## Important Note
16
+
17
+ claude-mem v8.5.4 worker API is required for full functionality but is only available from [GitHub releases](https://github.com/thedotmack/claude-mem/releases), not npm.
18
+
19
+ See [Installation Guide](docs/INSTALLATION.md) for detailed instructions on installing claude-mem from GitHub.
20
+
21
+ ## Features
22
+
23
+ - **Automatic Memory Capture**: Captures tool usage automatically via OpenCode events
24
+ - **Intelligent Compression**: Uses AI to compress observations while preserving context
25
+ - **Natural Language Search**: Search your coding history using natural language
26
+ - **Privacy Protection**: Automatic privacy tag stripping for sensitive data
27
+ - **Session Mapping**: Maps OpenCode sessions to claude-mem sessions
28
+ - **Context Injection**: Automatically injects relevant memories into new sessions
29
+
30
+ ## Quick Start
31
+
32
+ ### 1. Install claude-mem v8.5.4 from GitHub
33
+
34
+ ```bash
35
+ # Clone claude-mem repository
36
+ git clone https://github.com/thedotmack/claude-mem.git
37
+ cd claude-mem
38
+
39
+ # Build and install
40
+ bun install
41
+ bun run build
42
+ bun link
43
+
44
+ # Verify installation
45
+ claude-mem --version
46
+ # Should output: 8.5.4
47
+ ```
48
+
49
+ ### 2. Start claude-mem worker
50
+
51
+ ```bash
52
+ claude-mem worker start
53
+
54
+ # Verify worker is running
55
+ curl http://localhost:37777/api/health
56
+ ```
57
+
58
+ ### 3. Use in your code
59
+
60
+ ```typescript
61
+ import { ClaudeMemIntegration } from 'claude-mem-opencode'
62
+
63
+ const integration = new ClaudeMemIntegration()
64
+ await integration.initialize()
65
+
66
+ // Memory is now being captured automatically!
67
+ ```
68
+
69
+ ### 3. Use in OpenCode
70
+
71
+ ```typescript
72
+ import { ClaudeMemIntegration } from 'claude-mem-opencode'
73
+
74
+ const integration = new ClaudeMemIntegration()
75
+ await integration.initialize()
76
+
77
+ // Memory is now being captured automatically!
78
+
79
+ // Search memories
80
+ const results = await integration.searchMemory("authentication")
81
+
82
+ // Get project context
83
+ const context = await integration.getProjectContext()
84
+
85
+ // Get status
86
+ const status = await integration.getStatus()
87
+ console.log(status)
88
+ ```
89
+
90
+ ## API Reference
91
+
92
+ ### ClaudeMemIntegration
93
+
94
+ Main integration class that manages all memory operations.
95
+
96
+ #### Constructor
97
+
98
+ ```typescript
99
+ new ClaudeMemIntegration(workerUrl?: string)
100
+ ```
101
+
102
+ - `workerUrl`: Optional URL of claude-mem worker (default: `http://localhost:37777`)
103
+
104
+ #### Methods
105
+
106
+ **initialize()**: Initialize the integration
107
+
108
+ ```typescript
109
+ await integration.initialize()
110
+ ```
111
+
112
+ **getStatus()**: Get integration status
113
+
114
+ ```typescript
115
+ const status = await integration.getStatus()
116
+ // Returns: { initialized, workerReady, workerUrl, currentProject }
117
+ ```
118
+
119
+ **getProjectContext(project?)**: Get memory context for a project
120
+
121
+ ```typescript
122
+ const context = await integration.getProjectContext('my-project')
123
+ ```
124
+
125
+ **searchMemory(query, options?)**: Search memories
126
+
127
+ ```typescript
128
+ const results = await integration.searchMemory('authentication', {
129
+ limit: 10,
130
+ type: 'code',
131
+ project: 'my-project'
132
+ })
133
+ ```
134
+
135
+ **isMemoryAvailable()**: Check if memory features are available
136
+
137
+ ```typescript
138
+ if (integration.isMemoryAvailable()) {
139
+ // Memory operations available
140
+ }
141
+ ```
142
+
143
+ **getWorkerClient()**: Get underlying WorkerClient (advanced usage)
144
+
145
+ ```typescript
146
+ const client = integration.getWorkerClient()
147
+ await client.initSession({ ... })
148
+ ```
149
+
150
+ **shutdown()**: Shutdown integration
151
+
152
+ ```typescript
153
+ await integration.shutdown()
154
+ ```
155
+
156
+ ### WorkerClient
157
+
158
+ Low-level HTTP client for claude-mem worker API.
159
+
160
+ ```typescript
161
+ import { WorkerClient } from 'claude-mem-opencode'
162
+
163
+ const client = new WorkerClient(37777)
164
+
165
+ // Check health
166
+ await client.healthCheck()
167
+
168
+ // Initialize session
169
+ await client.initSession({
170
+ contentSessionId: 'session-123',
171
+ project: 'my-project',
172
+ prompt: 'Initial prompt'
173
+ })
174
+
175
+ // Add observation
176
+ await client.addObservation({
177
+ sessionDbId: 1,
178
+ promptNumber: 1,
179
+ toolName: 'bash',
180
+ toolInput: { command: 'ls' },
181
+ toolOutput: 'file1.txt\nfile2.txt',
182
+ cwd: '/home/user/project',
183
+ timestamp: Date.now()
184
+ })
185
+
186
+ // Complete session
187
+ await client.completeSession(1)
188
+
189
+ // Search
190
+ const results = await client.search('query', { limit: 10 })
191
+ ```
192
+
193
+ ### EventListeners
194
+
195
+ Listens to OpenCode events and captures tool usage.
196
+
197
+ ```typescript
198
+ import { EventListeners } from 'claude-mem-opencode'
199
+
200
+ const listeners = new EventListeners(workerClient)
201
+ await listeners.initialize()
202
+ ```
203
+
204
+ ### ContextInjector
205
+
206
+ Injects memory context into OpenCode sessions.
207
+
208
+ ```typescript
209
+ import { ContextInjector } from 'claude-mem-opencode'
210
+
211
+ const injector = new ContextInjector(workerClient)
212
+ const context = await injector.injectContext('my-project')
213
+ ```
214
+
215
+ ### SessionMapper
216
+
217
+ Maps OpenCode session IDs to claude-mem session IDs.
218
+
219
+ ```typescript
220
+ import { SessionMapper } from 'claude-mem-opencode'
221
+
222
+ const mapper = new SessionMapper()
223
+
224
+ // Map sessions
225
+ mapper.mapOpenCodeToClaudeMem('opencode-session-123', 1)
226
+
227
+ // Get mapping
228
+ const claudeMemId = mapper.getClaudeMemSessionId('opencode-session-123')
229
+ ```
230
+
231
+ ### PrivacyTagStripper
232
+
233
+ Removes privacy tags from content before storage.
234
+
235
+ ```typescript
236
+ import { PrivacyTagStripper } from 'claude-mem-opencode'
237
+
238
+ const stripper = new PrivacyTagStripper()
239
+
240
+ const cleaned = stripper.strip('<private>secret</private> data')
241
+ // Returns: ' data'
242
+ ```
243
+
244
+ ### ProjectNameExtractor
245
+
246
+ Extracts project name from directory paths.
247
+
248
+ ```typescript
249
+ import { ProjectNameExtractor } from 'claude-mem-opencode'
250
+
251
+ const extractor = new ProjectNameExtractor()
252
+
253
+ const projectName = extractor.extract('/home/user/my-project')
254
+ // Returns: 'my-project'
255
+
256
+ const currentProject = extractor.getCurrentProject()
257
+ // Returns: name of current working directory
258
+ ```
259
+
260
+ ### Logger
261
+
262
+ Simple logging utility.
263
+
264
+ ```typescript
265
+ import { Logger, LogLevel } from 'claude-mem-opencode'
266
+
267
+ const logger = new Logger('MY_APP')
268
+
269
+ logger.debug('Debug message')
270
+ logger.info('Info message')
271
+ logger.warn('Warning message')
272
+ logger.error('Error message')
273
+ ```
274
+
275
+ ## Privacy Protection
276
+
277
+ Use privacy tags to prevent sensitive data from being stored:
278
+
279
+ ```typescript
280
+ // This will not be stored
281
+ <private>password = "secret123"</private>
282
+
283
+ // This will not be stored
284
+ <claude-mem-context>Previously injected context</claude-mem-context>
285
+ ```
286
+
287
+ The `PrivacyTagStripper` automatically removes these tags before storing data.
288
+
289
+ ## Architecture
290
+
291
+ ```
292
+ ┌─────────────────────────────────────────────────────────────┐
293
+ │ OpenCode │
294
+ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐│
295
+ │ │ Bus │ │ Session │ │ MessageV2 ││
296
+ │ │ (Events) │ │ (Info) │ │ (Part) ││
297
+ │ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘│
298
+ │ │ │ │ │
299
+ │ └─────────────────┴─────────────────┘ │
300
+ │ │ │
301
+ │ claude-mem-opencode │
302
+ │ │ │
303
+ └───────────────────────────┼─────────────────────────────┘
304
+ │ HTTP
305
+ ┌───────▼────────┐
306
+ │ claude-mem │
307
+ │ Worker API │
308
+ │ (localhost: │
309
+ │ 37777) │
310
+ └────────────────┘
311
+ ```
312
+
313
+ ## Development
314
+
315
+ ### Building
316
+
317
+ ```bash
318
+ npm run build
319
+ ```
320
+
321
+ ### Testing
322
+
323
+ ```bash
324
+ # Run all tests
325
+ npm test
326
+
327
+ # Run unit tests
328
+ npm run test:unit
329
+
330
+ # Run integration tests
331
+ npm run test:integration
332
+
333
+ # Run E2E tests
334
+ npm run test:e2e
335
+ ```
336
+
337
+ ### Creating Bundle
338
+
339
+ ```bash
340
+ npm run bundle
341
+ ```
342
+
343
+ ## Testing
344
+
345
+ Run unit tests (no claude-mem required):
346
+
347
+ ```bash
348
+ npm run test:unit
349
+ # Expected: 54 pass
350
+ ```
351
+
352
+ Run integration/E2E tests (requires claude-mem worker):
353
+
354
+ ```bash
355
+ # Start worker
356
+ claude-mem worker start
357
+
358
+ # Run tests
359
+ npm run test:integration
360
+ npm run test:e2e
361
+
362
+ # Stop worker
363
+ claude-mem worker stop
364
+ ```
365
+
366
+ See [Testing Guide](docs/TESTING.md) for comprehensive testing instructions.
367
+
368
+ ## Troubleshooting
369
+
370
+ ### Worker not starting
371
+
372
+ ```bash
373
+ # Verify claude-mem installation
374
+ claude-mem --version
375
+ # Must be 8.5.4 or higher
376
+
377
+ # Check worker logs
378
+ claude-mem worker logs
379
+
380
+ # Ensure port 37777 is available
381
+ lsof -i :37777 # macOS/Linux
382
+ ```
383
+
384
+ ## License
385
+
386
+ MIT
387
+
388
+ ## Acknowledgments
389
+
390
+ - [claude-mem](https://github.com/thedotmack/claude-mem) - Persistent memory for Claude Code
391
+ - [OpenCode](https://github.com/sst/opencode) - The AI CLI