fix(memory): normalize Windows path separators in parsePath/parseCcPath#1655
Open
lxcxjxhx wants to merge 1 commit into
Open
fix(memory): normalize Windows path separators in parsePath/parseCcPath#1655lxcxjxhx wants to merge 1 commit into
lxcxjxhx wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
memory_ftsstaying empty on Windows.parsePathandparseCcPathinpackages/opencode/src/memory/paths.tswere written against POSIX pathswith hard-coded forward slashes in their regexes. On Windows,
path.joinproduces backslash-separated paths, so the regexes never matched, every
.mdfile failed to be indexed, andMemory.searchreturned zero hits.Root cause
packages/opencode/src/memory/paths.ts:46:absPathis whateverpath.join(...)produced, which on Windows isC:\Users\user\.local\share\mimocode\memory\global\MEMORY.md. The regexlooks for
/memory/...only, so it returnsnulland the file is silentlyskipped.
parseCcPath(same file, line ~60) had the same bug for.claude/projects/.../memory/*.mdfiles.
Fix
Add a small
normalizePathSeparatorshelper that converts backslashes toforward slashes before matching. POSIX paths are unaffected because they
contain no backslashes.
parseCcPathgets 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.mdWindows path with backslashes: project memory.mdWindows path with backslashes: session checkpoint.mdWindows path with backslashes: project free file(D: drive)mixed separators normalize to forward slashesWindows path that is not under /memory still returns nullcc-paths.test.ts(3 new tests):Windows path with backslashes: standard slugWindows path with backslashes: MEMORY.md (the index file)Windows path with mixed separators normalizes to forward slashesAll 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
buninstalled, so I couldn't runbun testdirectly. I verified the regex behavior with a node scriptthat imports the same regex pattern and exercises every test case (16/16
passed). The CI on
mainanddevwill run the full bun test suite.Checklist
Notes for reviewer
This is a Draft PR pending the maintainers' review. Happy to:
normalizePathSeparatorsto match project conventionspath-utilsmodule if preferredThis PR was drafted with AI assistance. Core fix and tests were
manually written and locally verified.