fix: use absolute default path for mdMirror fallback directory#628
Conversation
When mdMirror.dir is not configured, the fallback resolved to a CWD-relative "memory-md" path, polluting whichever directory the gateway or CLI happened to start from. Use ~/.openclaw/memory/md-mirror as the default, following the same pattern as getDefaultDbPath(). Closes CortexReach#627 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes mdMirror’s fallback directory to be a stable absolute path (under the user’s OpenClaw data dir) instead of resolving relative to the current working directory.
Changes:
- Added
getDefaultMdMirrorDir()to compute~/.openclaw/memory/md-mirror. - Updated
createMdMirrorWriter()to use the new default whenmdMirror.diris not configured. - Added a new test file covering the default path and config override behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
index.ts |
Introduces the new default mdMirror dir helper, uses it in createMdMirrorWriter, and exports it for tests. |
test/mdmirror-fallback-dir.test.mjs |
Adds unit tests validating the default mdMirror dir and config parsing behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** | ||
| * Resets the registration state — primarily intended for use in tests that need | ||
| * to unload/reload the plugin without restarting the process. | ||
| * @public | ||
| */ | ||
| export { getDefaultMdMirrorDir }; | ||
|
|
||
| export function resetRegistration() { |
There was a problem hiding this comment.
The JSDoc block that describes resetRegistration() now precedes export { getDefaultMdMirrorDir };, so the comment will attach to the export statement instead of the resetRegistration function (and resetRegistration() loses its @public docs). Move the named export either above this JSDoc block, or move the JSDoc immediately above resetRegistration() (or add a separate doc comment for getDefaultMdMirrorDir if intended public).
| const fallbackDir = config.mdMirror.dir | ||
| ? api.resolvePath(config.mdMirror.dir) | ||
| : getDefaultMdMirrorDir(); |
There was a problem hiding this comment.
fallbackDir uses getDefaultMdMirrorDir() directly when mdMirror.dir is unset, while other default paths (e.g. dbPath) are still passed through api.resolvePath(...). For consistency (and to ensure any normalization/sandboxing logic in resolvePath is applied uniformly), consider always wrapping the chosen path with api.resolvePath, even when using the default absolute path.
| const fallbackDir = config.mdMirror.dir | |
| ? api.resolvePath(config.mdMirror.dir) | |
| : getDefaultMdMirrorDir(); | |
| const fallbackDir = api.resolvePath( | |
| config.mdMirror.dir ?? getDefaultMdMirrorDir(), | |
| ); |
- Move export statement above the resetRegistration() JSDoc so the doc comment stays attached to the correct function - Wrap the default path through api.resolvePath() for consistency with other default paths (normalization/sandboxing) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
{CWD}/memory-mdinstead of a stable absolute path whenmdMirror.diris not configuredgetDefaultMdMirrorDir()following the same pattern as the existinggetDefaultDbPath()— resolves to~/.openclaw/memory/md-mirrorCloses #627
Changes
index.ts:getDefaultMdMirrorDir()helper (returns~/.openclaw/memory/md-mirror)createMdMirrorWriter()to use the new helper whenmdMirror.diris not set, instead of the CWD-relative"memory-md"getDefaultMdMirrorDirfor testabilitytest/mdmirror-fallback-dir.test.mjs(new):Testing
node --test test/mdmirror-fallback-dir.test.mjs)test:core-regressionpassestest:storage-and-schemapassestest:llm-clients-and-authpassestest:packaging-and-workflowpassestest:cli-smokehas a pre-existing failure on master (unrelated to this change)This PR was created with the assistance of Claude Code (AI).