mr-memory 1.0.1 → 1.0.3

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 (3) hide show
  1. package/index.ts +16 -2
  2. package/package.json +1 -1
  3. package/upload.ts +20 -3
package/index.ts CHANGED
@@ -188,9 +188,23 @@ const memoryRouterPlugin = {
188
188
  const os = await import("node:os");
189
189
  const path = await import("node:path");
190
190
  const stateDir = opts.brain ? path.resolve(opts.brain) : path.join(os.homedir(), ".openclaw");
191
- const workspacePath = opts.workspace ? path.resolve(opts.workspace) : process.cwd();
191
+ // Use OpenClaw's configured workspace, not cwd
192
+ const configWorkspace = api.config.workspace || api.config.agents?.defaults?.workspace;
193
+ const workspacePath = opts.workspace
194
+ ? path.resolve(opts.workspace)
195
+ : configWorkspace
196
+ ? path.resolve(configWorkspace.replace(/^~/, os.homedir()))
197
+ : path.join(os.homedir(), ".openclaw", "workspace");
192
198
  const { runUpload } = await import("./upload.js");
193
- await runUpload({ memoryKey, endpoint, targetPath, stateDir, workspacePath });
199
+ await runUpload({
200
+ memoryKey,
201
+ endpoint,
202
+ targetPath,
203
+ stateDir,
204
+ workspacePath,
205
+ hasWorkspaceFlag: !!opts.workspace,
206
+ hasBrainFlag: !!opts.brain,
207
+ });
194
208
  });
195
209
 
196
210
  mr.command("delete")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mr-memory",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "MemoryRouter persistent memory plugin for OpenClaw — your AI remembers every conversation",
5
5
  "type": "module",
6
6
  "keywords": [
package/upload.ts CHANGED
@@ -118,7 +118,7 @@ async function exists(p: string): Promise<boolean> {
118
118
  }
119
119
  }
120
120
 
121
- async function discoverFiles(workspacePath: string, stateDir: string): Promise<string[]> {
121
+ async function discoverWorkspaceFiles(workspacePath: string): Promise<string[]> {
122
122
  const files: string[] = [];
123
123
 
124
124
  const memoryMd = path.join(workspacePath, "MEMORY.md");
@@ -136,6 +136,12 @@ async function discoverFiles(workspacePath: string, stateDir: string): Promise<s
136
136
  if (await exists(p)) files.push(p);
137
137
  }
138
138
 
139
+ return files;
140
+ }
141
+
142
+ async function discoverBrainFiles(stateDir: string): Promise<string[]> {
143
+ const files: string[] = [];
144
+
139
145
  const sessionsDir = path.join(stateDir, "agents", "main", "sessions");
140
146
  if (await exists(sessionsDir)) {
141
147
  const allSessionFiles = await fs.readdir(sessionsDir);
@@ -171,6 +177,8 @@ export async function runUpload(params: {
171
177
  targetPath?: string;
172
178
  stateDir: string;
173
179
  workspacePath?: string;
180
+ hasWorkspaceFlag?: boolean;
181
+ hasBrainFlag?: boolean;
174
182
  }): Promise<void> {
175
183
  const { memoryKey, endpoint, targetPath, stateDir } = params;
176
184
  const uploadUrl = `${endpoint}/v1/memory/upload`;
@@ -198,8 +206,17 @@ export async function runUpload(params: {
198
206
  } else {
199
207
  files = [resolved];
200
208
  }
209
+ } else if (params.hasBrainFlag && !params.hasWorkspaceFlag) {
210
+ // --brain only: upload sessions from brain path
211
+ files = await discoverBrainFiles(stateDir);
212
+ } else if (params.hasWorkspaceFlag && !params.hasBrainFlag) {
213
+ // --workspace only: upload workspace files only
214
+ files = await discoverWorkspaceFiles(workspacePath);
201
215
  } else {
202
- files = await discoverFiles(workspacePath, stateDir);
216
+ // No flags or both flags: upload both workspace + sessions
217
+ const wsFiles = await discoverWorkspaceFiles(workspacePath);
218
+ const brainFiles = await discoverBrainFiles(stateDir);
219
+ files = [...wsFiles, ...brainFiles];
203
220
  }
204
221
 
205
222
  if (files.length === 0) {
@@ -302,7 +319,7 @@ export async function runUpload(params: {
302
319
  }
303
320
  }
304
321
 
305
- console.log(`\n✅ ${totalProcessed} vectors stored in vault`);
322
+ console.log(`\n✅ ${totalProcessed} memories stored in vault`);
306
323
  if (totalFailed > 0) {
307
324
  console.log(`⚠️ ${totalFailed} failed (${((totalFailed / (totalProcessed + totalFailed)) * 100).toFixed(0)}%)`);
308
325
  }