@rlabs-inc/memory 0.5.2 → 0.5.8

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.
@@ -243,7 +243,8 @@ export async function createServer(config: ServerConfig = {}) {
243
243
  logger.debug('Using Gemini CLI for curation', 'server')
244
244
  result = await curator.curateWithGeminiCLI(
245
245
  body.claude_session_id,
246
- body.trigger
246
+ body.trigger,
247
+ body.cwd // Run from original project directory
247
248
  )
248
249
  } else {
249
250
  // Default: Use Claude Code (session resume or transcript parsing)
@@ -0,0 +1,191 @@
1
+ // ============================================================================
2
+ // PATH UTILITIES - Centralized path resolution for memory system
3
+ // ============================================================================
4
+
5
+ import { join } from 'path'
6
+ import { homedir, tmpdir } from 'os'
7
+ import { existsSync } from 'fs'
8
+
9
+ // ============================================================================
10
+ // TEMP PATHS - For Gemini CLI system prompt injection
11
+ // ============================================================================
12
+
13
+ /**
14
+ * Get temp file path for curator system prompt
15
+ * Used by Gemini CLI via GEMINI_SYSTEM_MD env var
16
+ */
17
+ export function getCuratorPromptPath(): string {
18
+ return join(tmpdir(), '.gemini-curator-prompt.md')
19
+ }
20
+
21
+ /**
22
+ * Get temp file path for manager system prompt
23
+ * Used by Gemini CLI via GEMINI_SYSTEM_MD env var
24
+ */
25
+ export function getManagerPromptPath(): string {
26
+ return join(tmpdir(), '.gemini-manager-prompt.md')
27
+ }
28
+
29
+ // ============================================================================
30
+ // STORAGE PATHS - Where memories are stored
31
+ // ============================================================================
32
+
33
+ /**
34
+ * Get central storage path (default location for all memory data)
35
+ * ~/.local/share/memory
36
+ */
37
+ export function getCentralStoragePath(): string {
38
+ return join(homedir(), '.local', 'share', 'memory')
39
+ }
40
+
41
+ /**
42
+ * Get global storage path (shared across all projects)
43
+ * ~/.local/share/memory/global
44
+ */
45
+ export function getGlobalStoragePath(): string {
46
+ return join(getCentralStoragePath(), 'global')
47
+ }
48
+
49
+ /**
50
+ * Get global memories path
51
+ * ~/.local/share/memory/global/memories
52
+ */
53
+ export function getGlobalMemoriesPath(): string {
54
+ return join(getGlobalStoragePath(), 'memories')
55
+ }
56
+
57
+ /**
58
+ * Get personal primer path
59
+ * ~/.local/share/memory/global/primer/personal-primer.md
60
+ */
61
+ export function getPersonalPrimerPath(): string {
62
+ return join(getGlobalStoragePath(), 'primer', 'personal-primer.md')
63
+ }
64
+
65
+ /**
66
+ * Get project storage path based on storage mode
67
+ *
68
+ * Central mode: ~/.local/share/memory/{projectId}
69
+ * Local mode: {projectPath}/.memory/{projectId}
70
+ */
71
+ export function getProjectStoragePath(
72
+ projectId: string,
73
+ storageMode: 'central' | 'local' = 'central',
74
+ projectPath?: string,
75
+ localFolder: string = '.memory'
76
+ ): string {
77
+ if (storageMode === 'local' && projectPath) {
78
+ return join(projectPath, localFolder, projectId)
79
+ }
80
+ return join(getCentralStoragePath(), projectId)
81
+ }
82
+
83
+ /**
84
+ * Get project memories path
85
+ */
86
+ export function getProjectMemoriesPath(
87
+ projectId: string,
88
+ storageMode: 'central' | 'local' = 'central',
89
+ projectPath?: string,
90
+ localFolder: string = '.memory'
91
+ ): string {
92
+ return join(getProjectStoragePath(projectId, storageMode, projectPath, localFolder), 'memories')
93
+ }
94
+
95
+ // ============================================================================
96
+ // MANAGER CWD - Working directory for manager agent
97
+ // ============================================================================
98
+
99
+ export interface StoragePaths {
100
+ projectPath: string
101
+ globalPath: string
102
+ projectMemoriesPath: string
103
+ globalMemoriesPath: string
104
+ personalPrimerPath: string
105
+ storageMode: 'central' | 'local'
106
+ }
107
+
108
+ /**
109
+ * Get the storage mode from StoragePaths (defaults to 'central')
110
+ */
111
+ export function getStorageMode(storagePaths?: StoragePaths): 'central' | 'local' {
112
+ return storagePaths?.storageMode ?? 'central'
113
+ }
114
+
115
+ /**
116
+ * Get the working directory for the manager agent
117
+ *
118
+ * Central mode: ~/.local/share/memory (parent of both project and global)
119
+ * Local mode: project storage path (write access to project only)
120
+ */
121
+ export function getManagerCwd(storagePaths?: StoragePaths): string {
122
+ const storageMode = getStorageMode(storagePaths)
123
+
124
+ if (storageMode === 'central') {
125
+ // Central: run from parent directory to access both project and global
126
+ return getCentralStoragePath()
127
+ }
128
+
129
+ // Local: run from project storage path
130
+ return storagePaths?.projectPath ?? getCentralStoragePath()
131
+ }
132
+
133
+ /**
134
+ * Resolve full storage paths from config
135
+ * This mirrors engine.getStoragePaths() logic
136
+ */
137
+ export function resolveStoragePaths(
138
+ projectId: string,
139
+ storageMode: 'central' | 'local' = 'central',
140
+ projectPath?: string,
141
+ localFolder: string = '.memory'
142
+ ): StoragePaths {
143
+ const globalPath = getGlobalStoragePath()
144
+ const globalMemoriesPath = getGlobalMemoriesPath()
145
+ const personalPrimerPath = getPersonalPrimerPath()
146
+
147
+ const projectStoragePath = getProjectStoragePath(projectId, storageMode, projectPath, localFolder)
148
+ const projectMemoriesPath = join(projectStoragePath, 'memories')
149
+
150
+ return {
151
+ projectPath: projectStoragePath,
152
+ globalPath,
153
+ projectMemoriesPath,
154
+ globalMemoriesPath,
155
+ personalPrimerPath,
156
+ storageMode,
157
+ }
158
+ }
159
+
160
+ // ============================================================================
161
+ // CLI DISCOVERY - Find Claude CLI command
162
+ // ============================================================================
163
+
164
+ /**
165
+ * Get the Claude CLI command path
166
+ * Uses `which` for universal discovery across installation methods
167
+ *
168
+ * Priority:
169
+ * 1. CURATOR_COMMAND env var (explicit override)
170
+ * 2. `which claude` (universal - works with native, homebrew, npm)
171
+ * 3. ~/.claude/local/claude (legacy native install)
172
+ * 4. 'claude' (last resort - assume in PATH)
173
+ */
174
+ export function getClaudeCommand(): string {
175
+ // 1. Check for explicit override
176
+ const envCommand = process.env.CURATOR_COMMAND
177
+ if (envCommand) return envCommand
178
+
179
+ // 2. Use `which` to find claude in PATH
180
+ const result = Bun.spawnSync(['which', 'claude'])
181
+ if (result.exitCode === 0) {
182
+ return result.stdout.toString().trim()
183
+ }
184
+
185
+ // 3. Legacy fallback - hardcoded native install path
186
+ const claudeLocal = join(homedir(), '.claude', 'local', 'claude')
187
+ if (existsSync(claudeLocal)) return claudeLocal
188
+
189
+ // 4. Last resort
190
+ return 'claude'
191
+ }