feat(tools): ast-grep structural search/rewrite and gh CLI operations - #19
Conversation
`ast_grep` matches a pattern against the syntax tree — metavariables and all — and renders `file:line` results on the workspace's 1-based convention. `ast_edit` rewrites those matches, previewing the diff by default and writing only on `apply: true`, so the model reviews before anything lands on disk; the catalog's preview-then-resolve, folded into one tool. The binary is discovered at call time (`ast-grep`, then `sg`, accepted only if `--version` identifies ast-grep — plain `sg` is the shell-group utility), and absence is a clear error with an install hint, never a silent fallback to text search. Applies under a sandbox run through the same shell wrapper as `bash`, Seatbelt-confined where the OS enforces it. The apply summary is read from stderr, where ast-grep actually reports it. Stub-binary tests cover flag construction, rendering, and the preview/apply split everywhere (with an ETXTBSY warm-up so parallel test runs can't race a fresh script's exec); a real-binary roundtrip runs when ast-grep is installed and skips where it isn't, like CI. Inspect-mode pen children get `ast_grep`; work children get both. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KoSjfcJPjXpkVLTS2Vxwwr
|
Warning Review limit reached
Next review available in: 43 minutes Limit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits within each organization. For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
One tool, raw `gh` arguments as an array — no shell in between, so nothing needs quoting and nothing can be injected. The tool adds what gh cannot know: the runtime derives parallel safety from the verb (views, lists, diffs, checks, and searches ride alongside anything; mutations and the open-ended `api` stay serial, defaults closed), a network-denying sandbox refuses the call outright, and a missing binary errors with the install + `gh auth login` hint. Prompts are disabled so a headless run can never wedge on an interactive question. gh acts with the user's own login on remote state, which the workspace sandbox's write confinement deliberately does not govern — it fences the filesystem, not GitHub. Accordingly the tool registers on top-level runs only; pen children keep to the workspace. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KoSjfcJPjXpkVLTS2Vxwwr
The external-surface tranche from
docs/TOOLS.md: three tools wrapping two proven binaries, each degrading explicitly — never silently — when its binary is absent.ast_grep/ast_edit— structural code search and rewrite (ast-grep)ast_grepmatches a pattern against the syntax tree (metavariables like$A,$$$ARGS), rendered asfile:lineresults on the workspace's 1-based convention, capped at 200 matches. Parallel- and replay-safe.ast_editrewrites those matches, previewing the diff by default and writing only onapply: true— the catalog's preview-then-resolve folded into one tool. Previews are parallel-safe; applies are serial and run through the sandbox's shell wrapper likebash(Seatbelt-confined on macOS).ast-grep, thensg— accepted only when--versionidentifies ast-grep, since plainsgis the Unix shell-group utility. Absence is a clear error with an install hint.Registry::standard(); inspect-mode pen children get read-onlyast_grep.github— gh CLI operationsgharguments as an array, no shell in between: nothing needs quoting, nothing can be injected.apistay serial, defaults closed.gh auth loginhint; prompts are disabled so headless runs can't wedge.Validation
cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspace(repeated runs) — all green, 188 tests.🤖 Generated with Claude Code
https://claude.ai/code/session_01KoSjfcJPjXpkVLTS2Vxwwr