Skip to content

add jq CLI surface parity for output, streaming, seq, and modules - #768

Merged
ewhauser merged 2 commits into
mainfrom
ewhauser/jq-cli-surface-parity
Mar 28, 2026
Merged

ewhauser merged 2 commits into
mainfrom
ewhauser/jq-cli-surface-parity

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

What changed

  • add jq CLI support for -V, --ascii-output, -C/--color-output, -M/--monochrome-output, --unbuffered, --stream, --stream-errors, --seq, -L/--library-path, and --build-configuration
  • replace the old jq output path with a local formatter that handles ASCII escaping, ANSI color decisions, JSON-seq framing, and raw-output precedence
  • add jq input iterators for normal JSON input, raw input, stream tuples, stream error tuples, JSON text sequences, inputs, and input_filename
  • add a sandbox-backed jq module loader for -L and module-relative search metadata
  • extend jq unit coverage and clear the corresponding jq conformance xfails

Why

The gbash jq wrapper only covered a narrow subset of jq's CLI surface, so the compatibility suite stayed green while several standard jq flags and input modes were still missing.

Impact

contrib/jq now matches jq 1.8.1 behavior across the planned CLI flags and input modes, while still keeping the legacy gbash aliases -v, --ascii, --color, and --monochrome available.

Root cause

The previous implementation compiled gojq with variables and environment only, formatted output through gojq.Marshal, and did not provide a sandbox-aware module loader or jq-style input iterator plumbing.

Validation

  • make lint
  • go test ./contrib/jq
  • GBASH_RUN_JQ_CONFORMANCE=1 GBASH_CONFORMANCE_JQ="$(./scripts/ensure-jq.sh)" GBASH_CONFORMANCE_BASH="$(./scripts/ensure-bash.sh)" go test ./contrib/jq -run '^TestJQConformance$' -count=1

Remaining known gap

  • default object output key order still differs from jq and remains tracked as the only jq conformance xfail

@ewhauser ewhauser changed the title [codex] Add jq CLI surface parity for output, streaming, seq, and modules add jq CLI surface parity for output, streaming, seq, and modules Mar 28, 2026
@ewhauser
ewhauser marked this pull request as ready for review March 28, 2026 21:17
@ewhauser
ewhauser merged commit b9290b8 into main Mar 28, 2026
16 checks passed
@ewhauser
ewhauser deleted the ewhauser/jq-cli-surface-parity branch March 28, 2026 21:20

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3b8b9e37d8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread contrib/jq/jq_input.go
}

func newJQInputIter(ctx context.Context, inv *commands.Invocation, opts *jqOptions, inputs []string) (*jqSliceIter, error) {
sources, err := readJQInputSources(ctx, inv, inputs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Stop eagerly reading stdin when building the iterator

newJQInputIter unconditionally calls readJQInputSources, and readJQInputSources immediately reads all stdin when no file args are provided. This makes commands like jq -n '1' consume/block on stdin even though the filter does not require input, and it also prevents early-terminating input/inputs filters from short-circuiting on long-lived streams. Input consumption needs to be lazy so stdin is only read when the jq program actually requests it.

Useful? React with 👍 / 👎.

Comment thread contrib/jq/jq.go
Comment on lines +116 to +117
if name != "" && (len(inputs) > 0 || !opts.nullInput) {
return name

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Return stdin filename for input_filename under -n

The input_filename callback returns nil whenever -n is set and there are no explicit file operands because of the len(inputs) > 0 || !opts.nullInput guard. In jq, jq -n 'inputs | input_filename' should yield "<stdin>" for stdin-fed values, so this condition causes incorrect results for null-input workflows that still consume data via inputs/input.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant