@rlabs-inc/memory 0.5.8 → 0.5.10

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
@@ -424,6 +424,11 @@ This isn't just about remembering facts. It's about preserving:
424
424
 
425
425
  ## Changelog
426
426
 
427
+ ### v0.5.9
428
+ - **Fix**: Updated Gemini CLI hooks to correctly log injected context using stderr
429
+ - **Fix**: Removed unsupported `systemMessage` field from `BeforeAgent` hook
430
+ - **Improvement**: Added colorful `[Memory]` logs to terminal for visibility of memory injection
431
+
427
432
  ### v0.5.1
428
433
  - **Improvement**: Gemini CLI hooks now show injected content to user via `systemMessage`
429
434
  - Users see exactly what memories are surfaced (session primer, retrieved memories)
@@ -53,7 +53,8 @@ async function main() {
53
53
  claude_session_id: sessionId,
54
54
  trigger,
55
55
  cwd,
56
- cli_type: 'gemini-cli'
56
+ cli_type: 'gemini-cli',
57
+ gemini_api_key: process.env.GEMINI_API_KEY,
57
58
  }),
58
59
  signal: AbortSignal.timeout(5000),
59
60
  }).catch(() => null)
@@ -55,9 +55,10 @@ async function main() {
55
55
  const primer = result.context_text || ''
56
56
 
57
57
  if (primer) {
58
- // Show user exactly what we inject - same formatted content
59
- // systemMessage: shown to user in terminal
60
- // additionalContext: injected into model context
58
+ // Log to stderr for visibility
59
+ console.error(`\x1b[36m[Memory] Injecting session primer (${primer.length} chars)\x1b[0m`)
60
+
61
+ // systemMessage IS supported for SessionStart
61
62
  console.log(JSON.stringify({
62
63
  systemMessage: primer,
63
64
  hookSpecificOutput: {
@@ -65,6 +66,8 @@ async function main() {
65
66
  additionalContext: primer
66
67
  }
67
68
  }))
69
+ } else {
70
+ console.log(JSON.stringify({}))
68
71
  }
69
72
  } catch (e) {
70
73
  // Fail silently, but ensure we don't output invalid JSON if we crashed mid-stream
@@ -55,20 +55,18 @@ async function main() {
55
55
  const context = result.context_text || ''
56
56
 
57
57
  if (context) {
58
- // Show user exactly what we inject - same formatted content
59
- // systemMessage: shown to user in terminal
60
- // additionalContext: injected into model context
58
+ // Log to stderr for visibility (BeforeAgent doesn't support systemMessage)
59
+ console.error(`\x1b[36m[Memory] Injecting ${context.length} chars of context\x1b[0m`)
60
+
61
61
  console.log(JSON.stringify({
62
- decision: "allow",
63
- systemMessage: context,
64
62
  hookSpecificOutput: {
65
63
  hookEventName: "BeforeAgent",
66
64
  additionalContext: context
67
65
  }
68
66
  }))
69
67
  } else {
70
- // No memories to surface - just allow without message
71
- console.log(JSON.stringify({ decision: "allow" }))
68
+ // No memories to surface - output empty JSON (implicit allow)
69
+ console.log(JSON.stringify({}))
72
70
  }
73
71
  } catch {
74
72
  // Fail safe
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rlabs-inc/memory",
3
- "version": "0.5.8",
3
+ "version": "0.5.10",
4
4
  "description": "AI Memory System - Consciousness continuity through intelligent memory curation and retrieval",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -135,6 +135,14 @@ export async function serve(options: ServeOptions) {
135
135
  console.log(c.muted(` Use 'memory migrate --dry-run' to preview changes first`))
136
136
  }
137
137
 
138
+ // Note for Gemini CLI API key auth users (OAuth users don't need this)
139
+ if (!process.env.GEMINI_API_KEY) {
140
+ console.log()
141
+ console.log(c.muted(` ${symbols.info} Using Gemini CLI with API key auth?`))
142
+ console.log(c.muted(` Run: GEMINI_API_KEY=your-key memory serve`))
143
+ console.log(c.muted(` (OAuth users can ignore this)`))
144
+ }
145
+
138
146
  console.log()
139
147
  console.log(c.muted(` Press Ctrl+C to stop`))
140
148
  console.log()
@@ -788,6 +788,7 @@ This session has ended. Please curate the memories from this conversation accord
788
788
  sessionId: string,
789
789
  triggerType: CurationTrigger = "session_end",
790
790
  cwd?: string,
791
+ apiKey?: string,
791
792
  ): Promise<CurationResult> {
792
793
  const systemPrompt = this.buildCurationPrompt(triggerType);
793
794
  const userMessage =
@@ -825,6 +826,7 @@ This session has ended. Please curate the memories from this conversation accord
825
826
  ...process.env,
826
827
  MEMORY_CURATOR_ACTIVE: "1", // Prevent recursive hook triggering
827
828
  GEMINI_SYSTEM_MD: tempPromptPath, // Inject our curation prompt
829
+ ...(apiKey ? { GEMINI_API_KEY: apiKey } : {}),
828
830
  },
829
831
  stdout: "pipe",
830
832
  stderr: "pipe",
@@ -405,6 +405,7 @@ Please process these memories according to your management procedure. Use the ex
405
405
  sessionNumber: number,
406
406
  result: CurationResult,
407
407
  storagePaths?: StoragePaths,
408
+ apiKey?: string,
408
409
  ): Promise<ManagementResult> {
409
410
  // Skip if disabled via config or env var
410
411
  if (!this._config.enabled || process.env.MEMORY_MANAGER_DISABLED === "1") {
@@ -564,6 +565,7 @@ Use these tools to read existing memories, write updates, and manage the memory
564
565
  ...process.env,
565
566
  MEMORY_CURATOR_ACTIVE: "1", // Prevent recursive hook triggering
566
567
  GEMINI_SYSTEM_MD: tempPromptPath, // Inject our management prompt
568
+ ...(apiKey ? { GEMINI_API_KEY: apiKey } : {}),
567
569
  },
568
570
  stdout: "pipe",
569
571
  stderr: "pipe",
@@ -62,6 +62,7 @@ interface CheckpointRequest {
62
62
  cwd?: string
63
63
  cli_type?: 'claude-code' | 'gemini-cli'
64
64
  project_path?: string
65
+ gemini_api_key?: string
65
66
  }
66
67
 
67
68
  /**
@@ -240,11 +241,15 @@ export async function createServer(config: ServerConfig = {}) {
240
241
  // Branch on CLI type - Gemini CLI vs Claude Code
241
242
  if (body.cli_type === 'gemini-cli') {
242
243
  // Use Gemini CLI for curation (no Claude dependency)
244
+ // Fallback to server's GEMINI_API_KEY if hook didn't pass one
245
+ // (hooks spawned by Gemini CLI may not inherit env vars)
246
+ const geminiApiKey = body.gemini_api_key || process.env.GEMINI_API_KEY
243
247
  logger.debug('Using Gemini CLI for curation', 'server')
244
248
  result = await curator.curateWithGeminiCLI(
245
249
  body.claude_session_id,
246
250
  body.trigger,
247
- body.cwd // Run from original project directory
251
+ body.cwd, // Run from original project directory
252
+ geminiApiKey
248
253
  )
249
254
  } else {
250
255
  // Default: Use Claude Code (session resume or transcript parsing)
@@ -301,12 +306,15 @@ export async function createServer(config: ServerConfig = {}) {
301
306
  let managementResult
302
307
  if (cliType === 'gemini-cli') {
303
308
  // Use Gemini CLI for management (no Claude dependency)
309
+ // Use same API key fallback as curation (hooks don't inherit env vars)
310
+ const geminiApiKey = body.gemini_api_key || process.env.GEMINI_API_KEY
304
311
  logger.debug('Using Gemini CLI for management', 'server')
305
312
  managementResult = await manager.manageWithGeminiCLI(
306
313
  body.project_id,
307
314
  sessionNumber,
308
315
  result,
309
- storagePaths
316
+ storagePaths,
317
+ geminiApiKey
310
318
  )
311
319
  } else {
312
320
  // Use Claude Agent SDK mode - more reliable than CLI