You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(shared): ripgrep matches open the right file when a heading looks like a note - #44627
When ripgrep --heading output includes a file whose name looks like a parenthesized note (such as (draft)) or a decoration (such as ---), parseGrepOutput consumes the heading as a note/decoration while keeping the previous file active and attributes that file's numbered matches to the preceding file.
Deterministic repro on origin/main (241d46c562fa9a0e1bfc58de181a704dd43ac8f7):
In a temporary directory, write hit\n to normal.ts and (draft). Running rg --color never -j1 -nH --heading hit -- normal.ts '(draft)' emits "normal.ts\n1:hit\n\n(draft)\n1:hit\n".
Pass that output through parseGrepOutput(output, ".") or openCodeToolTurnItem from packages/provider-opencode:
Observed on origin/main: Both parseGrepOutput and openCodeToolTurnItem return two normal.ts:1 results plus a root note { fileName: ".", preview: "(draft)" }, with no result for (draft):1.
Expected: One result each for normal.ts:1 and (draft):1 (preview: "hit"), with no note; a genuine trailing parenthesized warning (e.g. (Results are truncated.)) remains a root note.
Change
In packages/shared/src/grepOutput.ts, recognize a non-inline ripgrep heading at a file-block boundary ((lines[index - 1] ?? "").trim() === "") when the next line is a ripgrep numbered match (^\d+:), before interpreting the line as a decoration or parenthesized note. Genuine trailing provider notes have no following numbered match and continue to parse as root notes. Both packages/provider-opencode and packages/provider-acp consume parseGrepOutput, so server, web, desktop, and mobile surfaces receive the corrected file/line attributions automatically without contract or UI changes. Extended packages/shared/src/grepOutput.test.ts with regression assertions covering (draft), a trailing truncation note control, and a --- heading.
Scope
Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.
Verification
Base failure (origin/main241d46c562fa9a0e1bfc58de181a704dd43ac8f7):vp test run packages/shared/src/grepOutput.test.ts -t "heading looks like a note" failed with 2 normal.ts:1 matches and a root (draft) note instead of normal.ts:1 and (draft):1.
Head verification:vp test run packages/shared/src/grepOutput.test.ts passed 2/2 consecutive runs (13/13 tests each).
Changed-files gate:vp run check:changed exited 0 (format, lint, knip 1/2 & 2/2, typecheck across 38 packages, and 2 affected test files / 15 tests).
Not shown: End-to-end UI rendering in web/desktop/mobile clients (no UI code modified; only the shared grep output parser changed) and live rg binary invocation in this container (exact rg --color never -j1 -nH --heading stdout was fed directly into parseGrepOutput and openCodeToolTurnItem).
Authored by Gemini 4 Neon (Antigravity); reviewed by Kimi K3.1 Pro (Model Hub).
No actionable comments were generated in the recent review.
Walkthrough
parseGrepOutput now checks for file headings after blank lines before processing notes or separators. Tests cover (draft) and --- headings, and a truncation note associated with ".".
Changes: Grep heading recognition
Layer / File(s)
Summary
Recognize file headings at block boundaries packages/shared/src/grepOutput.ts, packages/shared/src/grepOutput.test.ts
The parser recognizes a heading when a blank line precedes it and a numbered match follows, with an exception for ambiguous inline matches while the format is undetermined. Tests cover (draft) and --- headings, and a truncation note associated with ".".
This fixes grep results being attributed to the wrong file when a filename looks like a note or decoration, such as (draft) or ---. The change is small and covered by regression tests, and no actionable merge risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: ripgrep matches are attributed to the correct file when a heading looks like a parenthesized note. It follows the conventional commit form and is specific. It is 81 ch…
Description check
The description follows the template sections: Problem, Change, Scope, and Verification. It gives a deterministic repro, expected and observed results, the specific change, why no issue is needed for …
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: ripgrep matches are attributed to the correct file when a heading looks like a parenthesized note. It follows the conventional commit form and is specific. It is 81 characters, which is slightly long but readable.
Full details: Description check
Explanation
The description follows the template sections: Problem, Change, Scope, and Verification. It gives a deterministic repro, expected and observed results, the specific change, why no issue is needed for a small obvious bug, and focused test results with an explicit list of what was not checked. The template's optional agent attribution line is present. The Problem section is longer than the template's one-or-two-sentence guidance, but the content is relevant and complete.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Reviewing files that changed from the base of the PR and between e371d9f and 916049d.
Files selected for processing: 2
packages/shared/src/grepOutput.test.ts
packages/shared/src/grepOutput.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
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
size:S10-29 changed lines (additions + deletions).vouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.
1 participant
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.
Problem
When ripgrep
--headingoutput includes a file whose name looks like a parenthesized note (such as(draft)) or a decoration (such as---),parseGrepOutputconsumes the heading as a note/decoration while keeping the previous file active and attributes that file's numbered matches to the preceding file.Deterministic repro on
origin/main(241d46c562fa9a0e1bfc58de181a704dd43ac8f7):hit\ntonormal.tsand(draft). Runningrg --color never -j1 -nH --heading hit -- normal.ts '(draft)'emits"normal.ts\n1:hit\n\n(draft)\n1:hit\n".parseGrepOutput(output, ".")oropenCodeToolTurnItemfrompackages/provider-opencode:origin/main: BothparseGrepOutputandopenCodeToolTurnItemreturn twonormal.ts:1results plus a root note{ fileName: ".", preview: "(draft)" }, with no result for(draft):1.normal.ts:1and(draft):1(preview: "hit"), with no note; a genuine trailing parenthesized warning (e.g.(Results are truncated.)) remains a root note.Change
In
packages/shared/src/grepOutput.ts, recognize a non-inline ripgrep heading at a file-block boundary ((lines[index - 1] ?? "").trim() === "") when the next line is a ripgrep numbered match (^\d+:), before interpreting the line as a decoration or parenthesized note. Genuine trailing provider notes have no following numbered match and continue to parse as root notes. Bothpackages/provider-opencodeandpackages/provider-acpconsumeparseGrepOutput, so server, web, desktop, and mobile surfaces receive the corrected file/line attributions automatically without contract or UI changes. Extendedpackages/shared/src/grepOutput.test.tswith regression assertions covering(draft), a trailing truncation note control, and a---heading.Scope
Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.
Verification
origin/main241d46c562fa9a0e1bfc58de181a704dd43ac8f7):vp test run packages/shared/src/grepOutput.test.ts -t "heading looks like a note"failed with 2normal.ts:1matches and a root(draft)note instead ofnormal.ts:1and(draft):1.vp test run packages/shared/src/grepOutput.test.tspassed 2/2 consecutive runs (13/13 tests each).vp run check:changedexited0(format,lint,knip1/2 & 2/2,typecheckacross 38 packages, and 2 affected test files / 15 tests).rgbinary invocation in this container (exactrg --color never -j1 -nH --headingstdout was fed directly intoparseGrepOutputandopenCodeToolTurnItem).Authored by Gemini 4 Neon (Antigravity); reviewed by Kimi K3.1 Pro (Model Hub).