Skip to content

bug(browser): grep wrapper builds ambiguous "grep -r <pattern>" when pattern starts with "-" #329

Description

@apireno

Deferred from PR #308 R2 review (source comment, Codex P2).

`grep`'s wrapper in `browser/agent-harness/cli_anything/browser/utils/domshell_backend.py` builds the command string as `f"grep -r {_q(pattern)}"`. If the user supplies a pattern that starts with `-` (e.g. `fs grep -disabled`), DOMShell's shell-style argument parser will try to interpret the pattern as another flag rather than as the search term. Result: cryptic error or worse, wrong-pattern match.

Reproducer (conceptual — needs live DOMShell to confirm error message):
```python
backend.grep("-disabled", session=session)

Builds: grep -r -disabled

DOMShell parses -disabled as flags, not as pattern.

```

Suggested fix: terminate flag parsing with `--` before the pattern:
```python
op = asyncio.run(_call_execute(
f"grep -r -- {_q(pattern)}", use_daemon, session=session,
))
```
If DOMShell's parser doesn't honor `--` as flag terminator, fall back to `-e ` (GNU grep convention):
```python
op = asyncio.run(_call_execute(
f"grep -r -e {_q(pattern)}", use_daemon, session=session,
))
```
Smoke against `@apireno/domshell` to determine which DOMShell accepts.

Tests needed:

  • `test_grep_unrooted_uses_flag_terminator_before_pattern` — assert the `--` (or `-e`) is present before `_q(pattern)` in the command string.
  • `test_grep_rooted_uses_flag_terminator_before_pattern` — same, for the middle position of the 3-call rooted sequence.
  • Optional: end-to-end with a hyphen-prefixed pattern to confirm correct match semantics.

Why deferred: pre-existing bug — the `grep` wrapper had the same shape before the 2.0.2 migration. Best landed as a focused fix once #308 merges.

Scope: both branches of `grep` in `domshell_backend.py` (unrooted + rooted middle call) + 2-3 regression tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    existing-cli-fixFixes or improves an existing CLI harness

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions