Description
Both V1 and V2 edit tools do not normalize Unicode before comparing file content with oldString. On macOS where files are often stored in NFD (decomposed) form, while AI-generated text is NFC (precomposed), Unicode canonically-equivalent characters like é (U+00E9) vs e + combining accent (U+0065 U+0301) will not match, causing edit failures.
Affected Files
packages/core/src/tool/edit.ts:164 - countOccurrences uses indexOf without normalization
packages/core/src/tool/edit.ts:187 - replace uses string comparison without normalization
packages/opencode/src/tool/edit.ts:132 - replace() function uses indexOf without normalization
Inconsistency
packages/opencode/src/patch/index.ts:486 already has NFC normalization for apply_patch:
return tryMatch(lines, pattern, startIndex, (a, b) => a.normalize("NFC") === b.normalize("NFC"), eof)
The edit tools should have the same normalization for consistency.
Steps to reproduce
- On macOS, create a file with decomposed Unicode (e.g.,
touch $(echo '\u00e9' | iconv -f UTF-8 -t UTF-8-MAC))
- Ask the AI to edit text containing accented characters
- The AI's NFC-formatted oldString won't match the file's NFD content
- Edit fails with "oldString not found"
OpenCode version
1.17.3
Description
Both V1 and V2 edit tools do not normalize Unicode before comparing file content with oldString. On macOS where files are often stored in NFD (decomposed) form, while AI-generated text is NFC (precomposed), Unicode canonically-equivalent characters like
é(U+00E9) vse+ combining accent (U+0065 U+0301) will not match, causing edit failures.Affected Files
packages/core/src/tool/edit.ts:164-countOccurrencesusesindexOfwithout normalizationpackages/core/src/tool/edit.ts:187-replaceuses string comparison without normalizationpackages/opencode/src/tool/edit.ts:132-replace()function usesindexOfwithout normalizationInconsistency
packages/opencode/src/patch/index.ts:486already has NFC normalization for apply_patch:The edit tools should have the same normalization for consistency.
Steps to reproduce
touch $(echo '\u00e9' | iconv -f UTF-8 -t UTF-8-MAC))OpenCode version
1.17.3