Skip to content

fix(grep): don't force -C 3 context on every content search#35

Open
T0mSIlver wants to merge 1 commit into
microsoft:mainfrom
T0mSIlver:fix/grep-context-default
Open

fix(grep): don't force -C 3 context on every content search#35
T0mSIlver wants to merge 1 commit into
microsoft:mainfrom
T0mSIlver:fix/grep-context-default

Conversation

@T0mSIlver

Copy link
Copy Markdown

Problem

context = params.get("-C", 3) gave -C a hidden default of 3. Since run_rg appends -C whenever context is not None, every content-mode search carried 3 lines of surrounding context — including before-context — even when the model passed no context flags or only -A/-B. This is undocumented; the schema describes -C as optional and "ignored otherwise".

Fix

Default -C to None so context is applied only when the model explicitly requests it. Adds tests/test_grep_context.py asserting no context appears by default and that -C=1 includes neighbors.

Paper reference

Confirmed by the paper: -B/-A/-C are "Lines of context before, after, or around each match when output_mode is content" — optional context flags with no default — so forcing -C 3 contradicted the spec. — FastContext paper (arXiv:2606.14066), Appendix E "FastContext Explorer: Tool Schemas", p. 19

context defaulted to 3 (params.get('-C', 3)), so run_rg always appended
'-C 3' in content mode — injecting surrounding context even when the
model requested none or only -A/-B. The schema says -C is 'ignored
otherwise' and documents no default. Only apply context when the model
actually provides -C, and add a test covering both cases.
@T0mSIlver T0mSIlver closed this Jun 27, 2026
@T0mSIlver T0mSIlver deleted the fix/grep-context-default branch June 27, 2026 11:31
@T0mSIlver T0mSIlver restored the fix/grep-context-default branch June 27, 2026 11:56
@T0mSIlver T0mSIlver reopened this Jun 27, 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