Skip to content

fix(search): attach pattern and glob values so a leading dash is not read as a flag - #22

Merged
LittleCoinCoin merged 3 commits into
mainfrom
docs/search-argv-observation
Dec 3, 2026
Merged

LittleCoinCoin merged 3 commits into
mainfrom
docs/search-argv-observation

Conversation

@LittleCoinCoin

@LittleCoinCoin LittleCoinCoin commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

The fix

search failed with COLGREP_FAILED whenever pattern started with - (e.g. pattern="--json", a common search for agents looking up a CLI flag). build_search_argv passed the pattern as two words, ["-e", pattern]. clap reads a value that spells a colgrep flag as that flag, so colgrep exited 2 with a value is required for '--pattern <PATTERN>'. --include, --exclude and --exclude-dir had 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.

--alpha and -k are unchanged. The tool schema holds them to 0..1 and ≥1, so they can never start with -.

Evidence (colgrep 1.8.5+cs.1, by hand, --no-update)

Form Exit Result
-e --json (old code) 2 a value is required for '--pattern <PATTERN>'
-e=--json 0 0 hits: wrong, with no error
--pattern=--json 0 hits
-F --pattern=--json 0 hits (fixed_string needs nothing more)
--pattern=binary=<literal> 0 same hit as -e binary=<literal>: a value containing = stays intact
--pattern=binary=<absent> 0 0 hits (negative control)
--include -k / --exclude -s / --exclude-dir -w 2 same failure for globs
--include=-k / --exclude=-s / --exclude-dir=-w 0 parsed

The fixed adapter, run against the real binary, returns hits for pattern="--json" (with and without fixed_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=None mutant 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: pytest 366 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 fails
  • fix(search): attach pattern and glob values so a leading dash is not read as a flag
  • docs(reports): mark the dash-leading pattern fix as landed

No release in this PR (cz bump is separate).

🤖 Generated with Claude Code

LittleCoinCoin and others added 3 commits December 2, 2026 19:53
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>
@LittleCoinCoin LittleCoinCoin changed the title docs(reports): record why a search pattern starting with a dash fails fix(search): attach pattern and glob values so a leading dash is not read as a flag Dec 3, 2026
@LittleCoinCoin
LittleCoinCoin merged commit 212fe9f into main Dec 3, 2026
5 checks passed
@LittleCoinCoin
LittleCoinCoin deleted the docs/search-argv-observation branch December 3, 2026 02:03
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