feat(filter): add --jq global flag for jq-style output filtering#590
Merged
Conversation
Add a global `--jq <EXPR>` flag that applies a jq expression to any command's JSON response before output formatting, making it composable with every `-o` format (json, yaml, table, csv, tsv). - src/filter.rs (new): encapsulates jaq engine (jaq-core + jaq-std + jaq-json). Single apply_jq(value, expr) function; collapses output stream: 0 → Null, 1 → unwrapped, ≥2 → Array. 8 unit tests. - Cargo.toml: add jaq-core 3.1.0, jaq-std 3.0.1, jaq-json 2.0.1 (features = ["serde"]) - src/config.rs: add pub jq: Option<String> field - src/formatter.rs: serialize-once refactor — all 5 renderers + build_agent_envelope now take &serde_json::Value; filter applied in format_and_print before envelope/sort/rendering - src/main.rs: #[arg(long, global = true)] jq: Option<String> on Cli - src/extensions/mod.rs: PreParsedGlobals parses --jq / --jq= - src/extensions/exec.rs: injects PUP_FILTER env var for extensions - All direct format_and_print call sites updated (cfg.jq.as_deref()) - docs/COMMANDS.md: document --jq, cardinality behavior, bypass caveat Environment: Datadog workspace Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
Author
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b76072f1b3
ℹ️ 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".
…n agent mode When --jq rewrites the payload before the agent envelope is built, the caller's count/truncated fields (computed pre-filter) no longer describe .data. This misleads agents relying on the envelope's count field. - strip_counts_after_filter: drops count/truncated when --jq active; keeps command/next_action. Metadata.skip_serializing_if makes the omitted fields disappear from JSON. - append_jq_note: extends metadata.note with JQ_FILTER_NOTE when --jq ran, so agents know --jq targets the raw payload (write .[], not .data[]). - format_and_print agent-mode JSON branch: threads metadata through strip_counts_after_filter then calls append_jq_note on the envelope. The jq == None path is byte-for-byte identical to before. - 5 new unit tests: strip_counts (None→None, populated→stripped), append_jq_note (both notes present), integration (count omitted + both notes), regression (no --jq keeps count and note unchanged). - docs/COMMANDS.md: documents that --jq targets the payload (write .[], not .data[]) and that count/truncated are omitted in agent mode. Environment: Datadog workspace Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Three test-only Config struct initializers were missing the newly-added `jq: Option<String>` field, causing `error[E0063]` when CI built with `--all-targets`. Local `cargo clippy` without that flag skipped test binaries, so the breakage only surfaced in CI. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
amaskara-dd
approved these changes
Jun 18, 2026
jack-edmonds-dd
added a commit
that referenced
this pull request
Jun 18, 2026
Config gained a jq field in PR #590 but one test initializer in config.rs was missed, causing clippy --all-targets to fail. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
Adds a global
--jq <EXPR>flag that applies a jq expression to any command's JSON response before output formatting. Works with every-oformat (json, yaml, table, csv, tsv). Built on jaq — a pure-Rust, security-audited jq implementation with no C dependencies (cross-compiles to all 4 release targets and thebrowserWASM feature).Changes
src/filter.rs(new) —apply_jq(value, expr)encapsulates the jaq v3 API (Loader,Arena,Compiler,Ctx); collapses output stream: 0 →null, 1 → unwrapped, ≥2 → array. 8 unit tests covering happy paths, edge cases, and invalid-expression error handling.Cargo.toml— addsjaq-core 3.1.0,jaq-std 3.0.1,jaq-json 2.0.1(withfeatures = ["serde"])src/formatter.rs— serialize-once refactor:serde_json::to_value(data)called once informat_and_print, then&serde_json::Valuepassed to all 5 renderers andbuild_agent_envelope;--jqfilter applied before envelope/sort/renderingsrc/config.rs— addspub jq: Option<String>fieldsrc/main.rs— adds#[arg(long, global = true)] jq: Option<String>toClisrc/extensions/mod.rs—PreParsedGlobalsparses--jq/--jq=forms;apply_tosetscfg.jqsrc/extensions/exec.rs— injectsPUP_FILTERenv var so extensions can self-apply the filterformat_and_printcall sites updated to passcfg.jq.as_deref()docs/COMMANDS.md— documents--jq, cardinality-collapse behavior, and the bypass caveat for commands that print directlyTesting
cargo build✅cargo test✅ — 1284 passed; 7 pre-existing DNS/platform failures unrelated to this changecargo clippy -- -D warnings✅cargo fmt --check✅Related Issues
Closes #N/A — new feature per internal request
🤖 Generated with Claude Code