feat: honor --json-compact and signal pagination in --query output - #1672
Merged
Merged
Conversation
The --query encoder rendered every value through fmt.Sprintf("%v", val)
and url.Values.Set, so an array became the literal "[a b]", a repeated
value overwrote instead of accumulating, and large numbers could turn into
scientific notation. Any structured filter silently built the wrong request.
Decode with UseNumber and encode per JSON type: scalars become a single
value, arrays of scalars become repeated params (?k=a&k=b), numbers keep
their literal, and a nested object or array-of-objects is rejected with a
clear error naming the key.
Emit compact single-line JSON from --query list commands when --json-compact is set (default stays pretty-printed), and print a stderr diagnostic when the response is one page of a larger result set. The truncation hint covers checkpoint (next token), offset with totals, and offset with only a total, so callers don't mistake a page for the full set. The records fetched are unchanged.
Base the --query pagination hint on the Management API's standard list envelope (start/limit/length/total/next) and mirror management.List.HasNext rather than guessing the records array by length: - Offset: signal more pages when total > start + limit, and report the count from the envelope's length field instead of the longest top-level array. A bare total without limit is no longer treated as a pagination signal, so an unrelated total field cannot trigger a spurious hint. - Checkpoint: keep firing on a non-empty next token, but suppress it on an empty page (length == 0) so we never claim more results for a page that returned nothing. Also colorize --json-compact --query output to match the other compact commands (ColorizeJSON is already TTY-guarded, so piped output stays plain).
…, single-parse) Reject --csv when combined with --query instead of silently ignoring it, soften the checkpoint hint wording so a trailing next token no longer claims results definitively exist, report only the total when the envelope omits length, decode just the scalar pagination fields to avoid allocating the result array, and document the include_totals requirement on the --query flag.
# Conflicts: # CHANGELOG.md
Wrap the --query decode and encode failures in validationError so a malformed or nested filter classifies as "validation" instead of "unknown", matching the --data path. A JSON null now omits the parameter instead of sending an empty value, and queryScalarString gained a float64 fallback so the encoder stays correct if a caller decodes without UseNumber.
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md # internal/cli/query_json_test.go
Keeps the literals compilable once validationError gains additional fields, independent of merge order with the error-envelope change.
…ix/agent-query-encoding
…ix/agent-query-output
# Conflicts: # internal/cli/query_json.go # internal/cli/query_json_test.go
ramya18101
approved these changes
Sep 18, 2026
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.
🔧 Changes
Improves the
--querylist output path (auth0 actions list,auth0 roles list, and any future list command wired throughrunJSONQuery) in two ways:--json-compact. When--json-compactis set, the response is emitted as a single dense JSON line viajson.Compact. The default output stays pretty-printed. Both paths run throughansi.ColorizeJSON, which is TTY-guarded, so interactive output is colorized while piped or agent output stays plain.--csvis intentionally not supported here, because the response is raw API JSON with no fixed column shape to flatten.--querycall fetches one page. When the response indicates more records exist than were returned, a diagnostic is now printed to stderr so the returned records aren't mistaken for the full result set. The output on stdout and the number of records fetched are unchanged.The truncation signal reads the Management API's standard list envelope, whose fields go-auth0 models as
management.List(start/limit/length/total/next), and mirrors that type's ownHasNext()contract so the hint agrees with how the SDK defines "more pages":include_totals): more pages exist whentotal > start + limit. The "Showing X of Y" count comes from the envelope'slengthfield (the number actually returned on this page), falling back tolimitwhenlengthis absent. Atotalwithoutlimitis not treated as a pagination signal, so an unrelated scalar field cannot trigger a spurious hint.from/take): fires on a non-emptynexttoken and points the caller to pass it asfrom, but is suppressed on an empty page (length == 0) so it never claims more results for a page that returned nothing.📚 References
Part of the agent-compatibility work. Stacked on #1671.
🔬 Testing
Covered by unit tests in
internal/cli/query_json_test.go:TestRunJSONQuery_CompactOutputasserts compact mode emits a single dense line.TestPaginationHintcovers offset and checkpoint pagination plus the negative cases (complete set, last page, emptynexttoken, empty checkpoint page,totalwithoutlimit, no metadata, bare array).TestRunJSONQuery_TruncationWarningasserts the diagnostic reaches stderr on a truncated page.Run with
make test-unitorgo test ./internal/cli/ -run 'TestRunJSONQuery|TestPaginationHint'.Backward compatibility note: this changes observable behavior on two commands that already shipped,
auth0 actions list --queryandauth0 roles list --query. They now emit an additional diagnostic line to stderr on a truncated page, and they now honor--json-compact(previously the flag was silently ignored on this path). Scripts that read results from stdout are unaffected; only stderr gains a line, and only when the result set is truncated. Flagging for a maintainer decision, since it touches existing command output.📝 Checklist