Commit 067c74b
committed
fix(toolkit): robust ls/grep argument extraction in claim-verification hook (DOJ-4872)
Round-2 bot review at 4/5 confidence flagged 2 P3 polish items on the
suggester's argument extraction. Both addressed; suggestions applied
verbatim with explanatory comments.
P3 — hooks/pre-tool-use-claim-verification.sh:145 (ls path extraction)
- Old: sed prefix-strip + awk first-token, which fails on commands
like `ls -la` (no path arg, trailing flags) — sed regex `-flags`
requires a trailing space, so the flags leak through and `-la` ends
up as the "path arg" in the suggested replacement.
- New: awk-only nested loop that locates the literal `ls` token,
then walks forward skipping any token starting with `-`, and
emits the first non-flag token. Empty when only flags are present
(correct), so the suggester falls through to the `<path>` placeholder.
P3 — hooks/pre-tool-use-claim-verification.sh:158 (grep pattern extraction)
- Old: awk fallback matched the first `-FLAGS` token and emitted the
immediately following token, which on `grep -i -r "Symbol" src/`
is `-r` — wrong.
- New: nested awk loop that, after finding the flag token, walks
forward skipping additional flag tokens before emitting the first
non-flag one. Correctly isolates `Symbol` for `grep -i -r "Symbol"`,
still correct for the single-flag-block form `grep -rn "Symbol"`.
Verification:
- shellcheck → 0 issues
- "ls -la" → suggester emits <path> placeholder (was: `-la`)
- "ls src/foo.tsx" → suggester emits `src/foo.tsx` (regression)
- "grep -i -r \"Symbol\" src/" → emits "Symbol" (was: `-r`)
- "grep -rn \"Symbol\" src/" → emits "Symbol" (regression)
- "echo hello" → silent (regression)
Created by Claude Code on behalf of @lapc506.1 parent 31f10c9 commit 067c74b
1 file changed
Lines changed: 7 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
158 | 160 | | |
159 | | - | |
160 | | - | |
| 161 | + | |
161 | 162 | | |
162 | 163 | | |
163 | 164 | | |
| |||
169 | 170 | | |
170 | 171 | | |
171 | 172 | | |
| 173 | + | |
| 174 | + | |
172 | 175 | | |
173 | | - | |
| 176 | + | |
174 | 177 | | |
175 | 178 | | |
176 | 179 | | |
| |||
0 commit comments