fix(gh): passthrough output when --jq flag is present#319
Closed
jackfreem wants to merge 1 commit intortk-ai:masterfrom
Closed
fix(gh): passthrough output when --jq flag is present#319jackfreem wants to merge 1 commit intortk-ai:masterfrom
jackfreem wants to merge 1 commit intortk-ai:masterfrom
Conversation
When `gh api` is called with `--jq`, gh applies the filter and returns
already-user-filtered output (e.g. a scalar "104" or a compact object).
RTK was then passing this through `filter_json_string()`, which replaces
all JSON values with type placeholders — turning "104" into "int" and
{"tag_name":"v0.23.0"} into {tag_name: string}.
Fix: detect `--jq`/`--jq=<expr>` in args and print the output as-is.
The user has already expressed exactly what data they want; schema
extraction on top of that is wrong.
Adds `has_jq_flag()` helper (testable, follows existing repo pattern)
and five unit tests covering the flag detection and the breakage case.
Fixes rtk-ai#311
Collaborator
|
Hi @jackfreem, @rursache! We have several PRs tackling gh flag passthrough (#196, #217, #319, #325, #328) — they all touch |
This was referenced Mar 5, 2026
Collaborator
|
Fixed in v0.27.0 — gh with --jq now skips rewrite. |
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.
Summary
Fixes #311.
rtk gh apiwith--jqwas returning type placeholders (int,string,{ tag_name: string }) instead of real values.Root cause
run_api()unconditionally passed allgh apioutput throughjson_cmd::filter_json_string(), which is a schema extractor — it replaces every JSON value with its type descriptor. When--jqis present,ghhas already applied the user's filter and returned targeted output (e.g. a scalar104or a small object). Running that through the schema extractor destroys the data the user asked for.Fix
Detect
--jq/--jq=<expr>in args and print the output as-is. Adds ahas_jq_flag()helper following the existingshould_passthrough_run_view()pattern.Before / After
Tests
5 new unit tests added to
gh_cmd::tests:test_has_jq_flag_long_form—--jq .filterstyletest_has_jq_flag_equals_form—--jq=.filterstyletest_has_jq_flag_absent— no flag presenttest_has_jq_flag_empty— empty argstest_api_jq_output_not_schema_filtered— demonstratesfilter_json_string("104")returns"int", confirming why the passthrough is necessarytest_api_jq_object_would_be_schema_mangled— demonstrates object projections lose real values without the fixAll 28
gh_cmdtests pass.