Repository navigation
fix(core): handle non-UTF-8 ripgrep matches in grep - #15056
Conversation
Ripgrep emits base64 `bytes` instead of `text` when matched data is not valid UTF-8, which happens for ISO-8859-1 / Windows-1252 encoded files. The grep parser only accepted `text`, so any such match failed the whole search with "Invalid ripgrep match output" and forced a slower fallback. Accept both shapes for the matched line, path, and submatches, decoding base64 bytes as Windows-1252 so byte offsets stay aligned with the text.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge The incremental change (commit Files Reviewed (1 file)
Previous Review Summaries (3 snapshots, latest commit 31906a5)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 31906a5)Status: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (2 files)
Fix these issues in Kilo Cloud Previous review (commit 7bf5378)Status: No Issues Found | Recommendation: Merge Files Reviewed (1 file)
Incremental review of Previous review (commit 0e6da31)Status: 1 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (4 files)
The fix is sound: the new Reviewed by deepseek-v4.1-flash · Input: 29.6K · Output: 3.5K · Cached: 210.9K Review guidance: REVIEW.md from base branch |
… matches Drop the Windows-1252 assumption. Decode non-UTF-8 ripgrep output with lossy UTF-8 so valid multi-byte sequences survive intact and only truly undecodable bytes become U+FFFD. This avoids guessing the source encoding and eliminates mixed-encoding mojibake.
|
Tracked for the opencode v2 rewrite in #15087 ( |
Issue
No existing issue. This was reported directly by a user of the IntelliJ plugin who hits "Invalid ripgrep match output" on projects that contain ISO-8859-1 / Latin-1 encoded files.
What Problem This Solves
When a repository contains files that are not valid UTF-8, such as ISO-8859-1 / Windows-1252 source, Kilo's grep frequently failed with
Invalid ripgrep match output. Any search that matched one of those lines failed entirely, and the agent had to fall back to slower shell-based searches. This affected the CLI, the VS Code extension and the IntelliJ plugin, since they all run ripgrep through the same core service.Why This Change Was Made
Ripgrep reports non-UTF-8 data differently in its
--jsonoutput. Instead of{"text": "..."}it emits{"bytes": "<base64>"}. A single Latin-1 byte (for example0xF6forö) is enough to trigger this. The grep parser only accepted thetextshape, soSchema.decodeUnknownEffect(RawMatch)failed and the whole record was rejected.Changes:
textandbytesshapes for the matched line, the file path, and each submatch, decoding the base64 bytes back to text.Implementation
A new
Dataschema inpackages/core/src/kilocode/ripgrep-grep.tsmodels ripgrep's "arbitrary data" type as either{ text }or{ bytes }and normalizes it to{ text }via a decoding transform.packages/core/src/ripgrep.tsreuses it fordata.lines,data.path, andsubmatches[].match. The change to the shared upstream file is limited to those three field types, each marked withkilocode_change.Readandeditstill do not decode non-UTF-8 files (read rejects them withMalformedUtf8Error; edit decodes lossily), so the agent can still fall back to shell for those operations. Fixing that needs encoding detection and round-tripping, and is deliberately out of scope for this PR.User Impact
Grep now works normally on projects that mix UTF-8 and Latin-1 / Windows-1252 files, and returns the correct characters instead of failing. UTF-8 files behave exactly as before.
Screenshots / Video
N/A - no visual changes.
How to Test
Manual/local verification
bun test ./test/kilocode/ripgrep-encoding.test.ts ./test/ripgrep.test.ts ./test/kilocode/grep-tool.test.ts ./test/kilocode/ripgrep-settlement.test.ts ./test/filesystem/search.test.tsinpackages/core/: 19 pass, 0 fail. The four new encoding tests all failed withInvalid ripgrep match outputbefore the fix.bun run typecheckinpackages/core/: passed.bun run script/check-opencode-annotations.ts: passed.Reviewer test steps
printf 'title = "Handl\xe4ggning"\n' > legacy.java.Handlin that directory.Handläggningin the text, instead ofInvalid ripgrep match output.Blocked checks and substitute verification
Dependency
None.
Checklist