Whether a Bash command actually RUNS a search tool (#3121). The old test was a plain substring scan over the whole command string, including quoted arguments and heredoc bodies - so `git commit -m "add flag support"` fired ("flag " contains "ag "), prose containing "find " fired, an
(cmd_str: str)
| 1425 | |
| 1426 | |
| 1427 | def _bash_invokes_search(cmd_str: str) -> bool: |
| 1428 | """Whether a Bash command actually RUNS a search tool (#3121). |
| 1429 | |
| 1430 | The old test was a plain substring scan over the whole command string, |
| 1431 | including quoted arguments and heredoc bodies - so `git commit -m "add |
| 1432 | flag support"` fired ("flag " contains "ag "), prose containing "find " |
| 1433 | fired, and a design doc written via heredoc fired if its body mentioned |
| 1434 | grep. Every false positive injects a nudge where graphify has nothing to |
| 1435 | contribute and trains the agent to skim the line. |
| 1436 | |
| 1437 | Decide on the command's executed tokens instead: drop heredoc bodies and |
| 1438 | quoted spans, split on shell operators, and match the executable at each |
| 1439 | command position (wrappers like sudo/xargs/env skipped; `git grep` and |
| 1440 | `VAR=x grep ...` still count; a search-tool name inside prose does not). |
| 1441 | `sed` and `awk` count too when they open a file themselves: run on files, they |
| 1442 | are a grep or a read of the codebase by another name. Reading a pipe, editing |
| 1443 | in place, or naming no file (a program alone reads stdin) does not count. |
| 1444 | """ |
| 1445 | for name, args, piped in _bash_commands(cmd_str): |
| 1446 | if name in _SEARCH_COMMANDS: |
| 1447 | return True |
| 1448 | if name == "git" and any( |
| 1449 | t2 == "grep" for t2 in args[:3] if not t2.startswith("-") |
| 1450 | ): |
| 1451 | return True |
| 1452 | if name in ("sed", "awk") and not piped: |
| 1453 | # The program and at least one file; `x=1` is an awk assignment. |
| 1454 | operands = [t2 for t2 in args if not t2.startswith("-") and "=" not in t2] |
| 1455 | if not _sed_awk_in_place(name, args) and len(operands) >= 2: |
| 1456 | return True |
| 1457 | return False |
| 1458 | |
| 1459 | |
| 1460 | def _sed_awk_in_place(name: str, args: "list[str]") -> bool: |