Skip to content

fix: use absolute default path for mdMirror fallback directory#628

Merged
rwmjhb merged 2 commits intoCortexReach:masterfrom
ScientificProgrammer:fix/mdmirror-fallback-dir
Apr 15, 2026
Merged

fix: use absolute default path for mdMirror fallback directory#628
rwmjhb merged 2 commits intoCortexReach:masterfrom
ScientificProgrammer:fix/mdmirror-fallback-dir

Conversation

@ScientificProgrammer
Copy link
Copy Markdown
Contributor

Summary

  • Fixes the mdMirror fallback directory resolving to {CWD}/memory-md instead of a stable absolute path when mdMirror.dir is not configured
  • Adds getDefaultMdMirrorDir() following the same pattern as the existing getDefaultDbPath() — resolves to ~/.openclaw/memory/md-mirror
  • Adds tests for the new default and config-override behavior

Closes #627

Changes

index.ts:

  • Added getDefaultMdMirrorDir() helper (returns ~/.openclaw/memory/md-mirror)
  • Updated createMdMirrorWriter() to use the new helper when mdMirror.dir is not set, instead of the CWD-relative "memory-md"
  • Exported getDefaultMdMirrorDir for testability

test/mdmirror-fallback-dir.test.mjs (new):

  • 5 test cases covering absolute path, correct default location, no legacy relative path, explicit dir override, and undefined-when-unset behavior

Testing

  • All 5 new tests pass (node --test test/mdmirror-fallback-dir.test.mjs)
  • test:core-regression passes
  • test:storage-and-schema passes
  • test:llm-clients-and-auth passes
  • test:packaging-and-workflow passes
  • test:cli-smoke has a pre-existing failure on master (unrelated to this change)

This PR was created with the assistance of Claude Code (AI).

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>
Copilot AI review requested due to automatic review settings April 15, 2026 03:20
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 when mdMirror.dir is 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.

Comment thread index.ts
Comment on lines 4058 to 4065
/**
* 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() {
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment thread index.ts Outdated
Comment on lines +1534 to +1536
const fallbackDir = config.mdMirror.dir
? api.resolvePath(config.mdMirror.dir)
: getDefaultMdMirrorDir();
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
const fallbackDir = config.mdMirror.dir
? api.resolvePath(config.mdMirror.dir)
: getDefaultMdMirrorDir();
const fallbackDir = api.resolvePath(
config.mdMirror.dir ?? getDefaultMdMirrorDir(),
);

Copilot uses AI. Check for mistakes.
- 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>
@rwmjhb rwmjhb merged commit 18c7676 into CortexReach:master Apr 15, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mdMirror fallback directory resolves to CWD instead of ~/.openclaw/memory/md-mirror

3 participants