Repository navigation
fix(search): attach pattern and glob values so a leading dash is not read as a flag - #22
Merged
Merged
Conversation
An agent searching for a CLI flag name (pattern="--json") got COLGREP_FAILED: build_search_argv passes ["-e", pattern] and clap reads the value as the next flag. The observation hands the fix to a cold session with the measured argv forms. `--pattern=<p>` works, while `-e=<p>` returns [] with exit 0, so the obvious fix would be silently wrong. Tracked by the reminder candler-colgrep-mcp-dash-pattern. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…read as a flag
build_search_argv passed the pattern as two words, ["-e", pattern]. When
the value spells a colgrep flag (--json, -k), clap reads it as that flag,
colgrep exits 2 with "a value is required for '--pattern <PATTERN>'" and
the agent gets COLGREP_FAILED. Agents search for CLI flag names often.
--include, --exclude and --exclude-dir share the bug (`--include -k`
exits 2 the same way). All four now go out as --long=value.
Not -e=<p>: the short attached form keeps the "=" in the value and
silently returns no hits. Measured by hand on colgrep 1.8.5+cs.1
(--no-update, existing index):
-e --json exit 2
-e=--json exit 0, 0 hits (silently wrong)
--pattern=--json exit 0, hits
-F --pattern=--json exit 0, hits (-F is a separate boolean)
--pattern=binary=<literal> same hit as `-e binary=<literal>`; clap
splits on the first "=" only
--pattern=binary=<absent> 0 hits (negative control)
--include=-k, --exclude=-s,
--exclude-dir=-w exit 0 (two-word forms exit 2)
-e '' and --pattern= same result
The fixed adapter, run against the real binary, gives hits for
pattern="--json" (with and without fixed_string) and for a pattern that
contains "=". It gives 0 hits for the negative controls.
--alpha and -k stay as two words: the tool schema holds them to 0..1
and >=1, so they cannot start with a dash.
Tests: no new test. The existing argv guards used only plain values and
asserted the two-word [flag, value] adjacency. Their pattern and glob
rows now carry a value that spells a flag (--json, -k) and assert the
attached token. These rows were seen failing on the old code (6 red)
before the fix turned them green. The absence guard now compares the
flag name before "=", so emitting --pattern=None when unset turns it red;
that mutant was run and went red. The "=" case is clap's rule, not this
code's, so the real-binary probe above checks it, not a unit row.
Spec: __reports__/search_argv/00-observation_dash_leading_pattern_v0.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Record in the search_argv README that the fix landed on PR #22 and how it answered the report's hand-off questions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
The fix
searchfailed withCOLGREP_FAILEDwheneverpatternstarted with-(e.g.pattern="--json", a common search for agents looking up a CLI flag).build_search_argvpassed the pattern as two words,["-e", pattern]. clap reads a value that spells a colgrep flag as that flag, so colgrep exited 2 witha value is required for '--pattern <PATTERN>'.--include,--excludeand--exclude-dirhad the same bug.All four now go out in the attached long form:
--pattern=<p>,--include=<g>,--exclude=<g>,--exclude-dir=<d>. They do not use-e=<p>: that short attached form keeps the=in the value and returns no hits without any error.--alphaand-kare unchanged. The tool schema holds them to0..1and≥1, so they can never start with-.Evidence (colgrep
1.8.5+cs.1, by hand,--no-update)-e --json(old code)a value is required for '--pattern <PATTERN>'-e=--json--pattern=--json-F --pattern=--jsonfixed_stringneeds nothing more)--pattern=binary=<literal>-e binary=<literal>: a value containing=stays intact--pattern=binary=<absent>--include -k/--exclude -s/--exclude-dir -w--include=-k/--exclude=-s/--exclude-dir=-wThe fixed adapter, run against the real binary, returns hits for
pattern="--json"(with and withoutfixed_string) and for a pattern containing=, and 0 hits for the negative controls.Tests
No new test. The existing argv guards used only plain values and asserted the two-word
[flag, value]adjacency, which is exactly the shape that was wrong. Their pattern and glob rows now carry a value that spells a flag (--json,-k) and assert the attached token. Those rows failed on the old code (6 red) and pass after the fix. The absence guard now compares the flag name before=. Without that change it could no longer fail for the pattern row; an injected--pattern=Nonemutant turns it red. The=case comes from clap's parsing, not from this code, so the real-binary probe above checks it instead of a unit row.Gates:
pytest366 passed (1 opt-in skip),ruff check,ruff format --check,cz check --rev-range main..HEAD.Supporting evidence
__reports__/search_argv/00-observation_dash_leading_pattern_v0.md: the observation report filed when the bug was hit during a colgrep 1.8.5 review. Its README status now records the fix.Commits
docs(reports): record why a search pattern starting with a dash failsfix(search): attach pattern and glob values so a leading dash is not read as a flagdocs(reports): mark the dash-leading pattern fix as landedNo release in this PR (
cz bumpis separate).🤖 Generated with Claude Code