Skip to content

fix(memory): normalize Windows path separators in parsePath/parseCcPath#1655

Open
lxcxjxhx wants to merge 1 commit into
XiaomiMiMo:mainfrom
lxcxjxhx:fix/memory-fts-windows-path-separator
Open

fix(memory): normalize Windows path separators in parsePath/parseCcPath#1655
lxcxjxhx wants to merge 1 commit into
XiaomiMiMo:mainfrom
lxcxjxhx:fix/memory-fts-windows-path-separator

Conversation

@lxcxjxhx

Copy link
Copy Markdown

Summary

Fix memory_fts staying empty on Windows. parsePath and parseCcPath in
packages/opencode/src/memory/paths.ts were written against POSIX paths
with hard-coded forward slashes in their regexes. On Windows, path.join
produces backslash-separated paths, so the regexes never matched, every
.md file failed to be indexed, and Memory.search returned zero hits.

Root cause

packages/opencode/src/memory/paths.ts:46:

const m = absPath.match(/\/memory\/(global|projects|sessions)(?:\/([^/]+))?\/(.+)\.md$/)

absPath is whatever path.join(...) produced, which on Windows is
C:\Users\user\.local\share\mimocode\memory\global\MEMORY.md. The regex
looks for /memory/... only, so it returns null and the file is silently
skipped.

parseCcPath (same file, line ~60) had the same bug for .claude/projects/.../memory/*.md
files.

Fix

Add a small normalizePathSeparators helper that converts backslashes to
forward slashes before matching. POSIX paths are unaffected because they
contain no backslashes.

function normalizePathSeparators(absPath: string): string {
  return absPath.replace(/\\/g, "/")
}

export function parsePath(absPath: string): MemoryLocator | null {
  const normalized = normalizePathSeparators(absPath)
  const m = normalized.match(/\/memory\/(global|projects|sessions)(?:\/([^/]+))?\/(.+)\.md$/)
  // ...
}

parseCcPath gets the same treatment.

Tests

Added regression tests covering the exact scenarios from #1571 plus the
CC variant:

  • paths.test.ts (6 new tests):
    • Windows path with backslashes: global MEMORY.md
    • Windows path with backslashes: project memory.md
    • Windows path with backslashes: session checkpoint.md
    • Windows path with backslashes: project free file (D: drive)
    • mixed separators normalize to forward slashes
    • Windows path that is not under /memory still returns null
  • cc-paths.test.ts (3 new tests):
    • Windows path with backslashes: standard slug
    • Windows path with backslashes: MEMORY.md (the index file)
    • Windows path with mixed separators normalizes to forward slashes

All 4 existing POSIX-path tests in each file continue to pass unchanged
(verified locally with a node-based reproduction script: 16/16 passed).

Files changed

  • packages/opencode/src/memory/paths.ts (+13 / -2)
  • packages/opencode/test/memory/paths.test.ts (+52)
  • packages/opencode/test/memory/cc-paths.test.ts (+32)

Local test evidence

This environment doesn't have bun installed, so I couldn't run
bun test directly. I verified the regex behavior with a node script
that imports the same regex pattern and exercises every test case (16/16
passed). The CI on main and dev will run the full bun test suite.

Checklist

Notes for reviewer

This is a Draft PR pending the maintainers' review. Happy to:

  • rename normalizePathSeparators to match project conventions
  • move the helper into a shared path-utils module if preferred
  • add more CC or memory sub-path test cases

This PR was drafted with AI assistance. Core fix and tests were
manually written and locally verified.

On Windows, `path.join` produces backslash-separated paths (e.g.
`C:\Users\me\memory\global\MEMORY.md`). The regexes in
`packages/opencode/src/memory/paths.ts` are written against POSIX
paths with hard-coded forward slashes, so they never matched on
Windows. As a result, `memory_fts` stayed empty (0 indexed rows
for 15 .md files), and `Memory.search` returned zero hits.

Fix by normalizing path separators before matching in both
`parsePath` and `parseCcPath`. POSIX paths are unaffected because
they contain no backslashes.

Closes XiaomiMiMo#1571.
@lxcxjxhx lxcxjxhx marked this pull request as ready for review July 10, 2026 11:31
@lxcxjxhx lxcxjxhx changed the title [WIP/AI-assisted] fix(memory): normalize Windows path separators in parsePath/parseCcPath fix(memory): normalize Windows path separators in parsePath/parseCcPath Jul 11, 2026
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.

1 participant