Commit 0bc4ab3
committed
fix(toolkit): JSON-escape-aware command extract + repo-agnostic verify (DOJ-4872)
Round-4 bot review at 3/5 confidence flagged 1 P2 + 3 P3. All four addressed.
P2 — hooks/pre-tool-use-claim-verification.sh JSON command extractor
- The jq-less fallback regex `"[^"]*"` stops at the first inner quote.
For a bash command like `grep -rn \"Symbol\" src/`, the JSON envelope
embeds it as `"command": "grep -rn \\\"Symbol\\\" src/"`, and the
naive regex truncates at the first `\"`. Subsequent detector / suggester
logic then sees a partial command and emits the wrong replacement.
- Switched to the escape-aware JSON-string body
`([^"\\]|\\.)*` which accepts any non-quote-non-backslash byte OR a
backslash followed by any byte. Verified with an envelope containing
`grep -rn \"Symbol\" src/` — the full command extracts cleanly and
the suggester emits the right line.
P3 — hooks/pre-tool-use-claim-verification.sh cross-platform quote handling
- The bot flagged that the explicit single-quoted-pattern grep extractor
(added in round 3) used embedded-quote shell escaping that can drift
between GNU and BSD grep. Simplified by removing the explicit single-
quoted branch entirely: the awk fallback already strips both `"` and
`'` from the extracted token, so it covers both quote styles without
embedded escapes. Net code reduction; same behavior across the four
smoke-tested variants (single/double quoted, single/multi flag).
P3 — commands/verify.md repo-agnostic grep path
- The behavior section hardcoded `-- src/` as the path filter, which
would fail with a `fatal: pathspec` error in toolkit consumers that
have a different layout (`lib/`, `app/`, `packages/`, flat). Added a
detect-or-fallback step: if `src/` exists on the resolved ref, use
it as the path filter; otherwise pass no path filter and grep the
whole tree.
P3 — commands/verify.md remote-only tag resolution
- The normalization step probed `git rev-parse --verify refs/tags/<tag>`
which only sees LOCAL tags. A remote-only tag (e.g. `v1.31.0` just
pushed by a teammate but not yet fetched locally) would fall through
to the bare-branch branch and resolve to a nonexistent
`origin/v1.31.0`. Added a `git ls-remote --tags --exit-code origin
refs/tags/<tag>` probe between the local-tag and SHA branches; on hit,
runs `git fetch origin tag <tag> --quiet` before resolving. Comment
documents the failure mode.
Verification:
- shellcheck → 0 issues
- JSON envelope with escaped quotes:
`{"tool_input":{"command":"grep -rn \\\"Symbol\\\" src/"}}` →
Command: `grep -rn "Symbol" src/` (was: `grep -rn `)
Suggested: `git grep "Symbol" origin/<branch> -- src/` (was: garbled)
- "grep -rn 'Symbol' src/" → Suggested: "Symbol" (regression)
- "grep -rn \"Symbol\" src/" → Suggested: "Symbol" (regression)
- "grep -i -r \"Symbol\" src/" → Suggested: "Symbol" (regression)
- "ls src/foo.tsx" → Suggested: src/foo.tsx (regression)
- "echo hello" → silent (regression)
Created by Claude Code on behalf of @lapc506.1 parent 012e9ca commit 0bc4ab3
2 files changed
Lines changed: 37 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
46 | 49 | | |
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
53 | | - | |
| 56 | + | |
54 | 57 | | |
55 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
56 | 64 | | |
57 | 65 | | |
58 | 66 | | |
| |||
100 | 108 | | |
101 | 109 | | |
102 | 110 | | |
103 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
104 | 115 | | |
105 | 116 | | |
106 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
107 | 123 | | |
108 | | - | |
| 124 | + | |
109 | 125 | | |
110 | 126 | | |
111 | 127 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
80 | 84 | | |
81 | | - | |
| 85 | + | |
82 | 86 | | |
83 | 87 | | |
84 | 88 | | |
| |||
165 | 169 | | |
166 | 170 | | |
167 | 171 | | |
168 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
169 | 180 | | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
| 181 | + | |
| 182 | + | |
189 | 183 | | |
190 | 184 | | |
191 | 185 | | |
| |||
0 commit comments