Conversation
`rtk rewrite 'gh pr view 123 --json reviews'` exited 1 with no output, so the hook passed the command through unrewritten — `gh pr view --json` is how gh is used in practice, so those calls were never tracked. The rtk-ai#196 guard assumed `rtk gh` would reshape structured output, but `gh_cmd::run` has passed `--json` straight to gh since then, the same stance `gh api` takes. Rewriting is therefore byte-for-byte safe and the guard only cost coverage. - drop the registry special-case for `rtk gh` + --json/--jq/--template - harden the passthrough gate it was masking: `has_json_flag` matched only a bare `--json`, so `gh pr view 42 --json=number` fell into the filter and returned rtk's summary instead of the requested field. `wants_raw_output` now covers --json/--jq/-q/--template/-t in both spellings - flip the rtk-ai#196 registry tests to assert the rewrite, add unit tests for the flag spellings Verified against a real PR: `gh pr view N --json number,title,state,reviews` and the --jq/--template forms are byte-identical through `rtk gh`. Fixes rtk-ai#4067 Signed-off-by: dopaemon <polarisdp@gmail.com>
dopaemon
force-pushed
the
fix/gh-json-rewrite
branch
from
September 14, 2026 20:34
9156895 to
5f90d75
Compare
📊 Automated PR Analysis
SummaryRemoves a stale registry guard that skipped rewriting Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4067
Problem
Exit 1 / empty output is the "no rewrite" verdict, so the hook passes the command through untouched. Since almost every real
gh pr viewcall carries--json, that whole family was invisible to rtk — the issue reports it as the single largest missed-savings command inrtk discover.Why the guard is stale
registry.rsskipped the rewrite forrtk ghwhenever the args contained--json/--jq/--template(#196), on the grounds thatrtk ghwould corrupt structured output. That hasn't been true for a while:gh_cmd::runchecks the same flags first and hands the call torun_passthrough, which streams gh's own bytes and propagates its exit code — the same stancegh apidocuments ("Passthrough preserves the full response and tracks metrics at 0% savings").So the guard bought nothing and cost coverage.
Changes
src/discover/registry.rs: drop thertk gh+--json/--jq/--templatespecial-case.gh pr view 123 --json reviewsnow rewrites tortk gh pr view 123 --json reviews.src/cmds/git/gh_cmd.rs: harden the passthrough gate the registry guard was masking.has_json_flagmatched only a bare--json, so the=spelling slipped into the filter path. On currentdevelop:wants_raw_outputreplaces it and covers--json/--jq/-q/--template/-tin both--flag valueand--flag=valueforms. Without this, lifting the registry guard would have made that wrong-output path reachable from the hook.Tests: the four fix: passthrough --json/--jq/--template flags in all gh subcommands #196 registry tests now assert the rewrite instead of
None(plus one for the issue's exactgh pr view 123 --json reviews), and three unit tests cover the flag spellings.Verification
Byte-comparison against a real PR,
ghvsrtk gh:cargo fmt --all+cargo clippy --all-targetsclean;cargo test --bin rtk→ 3615 passed, plus the hook/gh integration binaries (hook_decision_protocol_test,gh_pr_checks_failure_test,copilot_selfheal_test,hook_warning_scope_test) green.Not included
The issue's secondary note (
git log -1 | grep -n fooleaves the post-pipe stage unrewritten) is a separate, deliberate mechanism —PipelineSafetyonly rewrites stages a filter can safely occupy. Worth its own issue rather than folding into this fix.