Skip to content

feat(jq): add input_filename / input_line_number / $ENV stubs - #1490

Merged
chaliy merged 1 commit into
mainfrom
fix/issue-1486-jq-input-builtins
Apr 30, 2026
Merged

chaliy merged 1 commit into
mainfrom
fix/issue-1486-jq-input-builtins

Conversation

@chaliy

@chaliy chaliy commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Real jq exposes three IO-introspection facilities that jaq does not — input_filename, input_line_number, and the $ENV variable. LLM agents trained on stedfan/jq routinely emit calls to these and hit bashkit's compile error against ~800 chars of prepended stdlib, which they fail to recognise as "function missing" and re-run on a loop.

Changes

  • input_filename: null; and input_line_number: 0; added to JQ_COMPAT_DEFS. Bashkit reads inputs as a single concatenated stream via shell redirection, so per-input file metadata is not tracked; null / 0 mirror jq's documented "no input" defaults.
  • $ENV registered as a public global variable bound to the same shell-env map that the existing env filter exposes. $ENV == env now holds true.
  • crates/bashkit/docs/jq.md — new rustdoc guide listing supported flags, variables, and notable shimmed/stubbed filters so downstream agents and humans have a documented surface to target. Wired in as jq_guide in lib.rs.

Tests

  • Unit tests in crates/bashkit/src/builtins/jq.rs:
    • test_jq_input_filename_compiles_and_returns_null
    • test_jq_input_filename_with_chained_filter_compiles — reproduces the LLM idiom from the bug report
    • test_jq_input_line_number_compiles_and_returns_zero
    • test_jq_dollar_env_returns_shell_env
    • test_jq_dollar_env_matches_env_function
  • Spec cases in crates/bashkit/tests/spec_cases/jq/jq.test.sh:
    • jq_input_filename_returns_null
    • jq_input_line_number_returns_zero
    • jq_dollar_env_returns_shell_env

Test plan

  • cargo fmt --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test -p bashkit --features "jq http_client" (lib + doctests, all 116 doctests + 2211 lib tests green)
  • cargo test -p bashkit --features jq --test spec_tests (jq_spec_tests includes new cases)
  • All 5 new unit tests pass

Closes #1486


Generated by Claude Code

Real jq exposes three IO-introspection facilities that jaq does not:
`input_filename`, `input_line_number`, and the `$ENV` variable. LLM
agents trained on stedfan/jq routinely emit calls to these and were
hitting bashkit's compile error against ~800 chars of prepended stdlib,
which they fail to recognise as "function missing" and re-run on a loop.

Resolution:

- Define `input_filename: null;` and `input_line_number: 0;` in the
  compatibility shim. Bashkit reads inputs as a single concatenated
  stream via shell redirection, so per-input file metadata is not
  tracked; null/0 mirror jq's documented "no input" defaults.
- Bind `$ENV` as a public global variable with the same shell-env map
  the existing `env` filter exposes. `$ENV == env` now holds true.
- Add a dedicated jq guide (`crates/bashkit/docs/jq.md`) listing the
  supported flags, variables, and notable shimmed/stubbed filters so
  downstream agents and humans have a documented surface to target.

Closes #1486
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit e3623b5 Commit Preview URL

Branch Preview URL
Apr 30 2026, 10:02 AM

@chaliy
chaliy merged commit b216ddf into main Apr 30, 2026
34 checks passed
@chaliy
chaliy deleted the fix/issue-1486-jq-input-builtins branch April 30, 2026 10:12
@codecov

codecov Bot commented Apr 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@chaliy chaliy mentioned this pull request Apr 30, 2026
3 of 9 tasks
chaliy added a commit that referenced this pull request May 30, 2026
## Summary

Real jq exposes three IO-introspection facilities that jaq does not —
`input_filename`, `input_line_number`, and the `$ENV` variable. LLM
agents trained on stedfan/jq routinely emit calls to these and hit
bashkit's compile error against ~800 chars of prepended stdlib, which
they fail to recognise as "function missing" and re-run on a loop.

## Changes

- **`input_filename: null;`** and **`input_line_number: 0;`** added to
`JQ_COMPAT_DEFS`. Bashkit reads inputs as a single concatenated stream
via shell redirection, so per-input file metadata is not tracked; `null`
/ `0` mirror jq's documented "no input" defaults.
- **`$ENV`** registered as a public global variable bound to the same
shell-env map that the existing `env` filter exposes. `$ENV == env` now
holds true.
- **`crates/bashkit/docs/jq.md`** — new rustdoc guide listing supported
flags, variables, and notable shimmed/stubbed filters so downstream
agents and humans have a documented surface to target. Wired in as
`jq_guide` in `lib.rs`.

## Tests

- Unit tests in `crates/bashkit/src/builtins/jq.rs`:
  - `test_jq_input_filename_compiles_and_returns_null`
- `test_jq_input_filename_with_chained_filter_compiles` — reproduces the
LLM idiom from the bug report
  - `test_jq_input_line_number_compiles_and_returns_zero`
  - `test_jq_dollar_env_returns_shell_env`
  - `test_jq_dollar_env_matches_env_function`
- Spec cases in `crates/bashkit/tests/spec_cases/jq/jq.test.sh`:
  - `jq_input_filename_returns_null`
  - `jq_input_line_number_returns_zero`
  - `jq_dollar_env_returns_shell_env`

## Test plan

- [x] `cargo fmt --check`
- [x] `cargo clippy --all-targets -- -D warnings`
- [x] `cargo test -p bashkit --features "jq http_client"` (lib +
doctests, all 116 doctests + 2211 lib tests green)
- [x] `cargo test -p bashkit --features jq --test spec_tests`
(`jq_spec_tests` includes new cases)
- [x] All 5 new unit tests pass

Closes #1486

---
_Generated by [Claude
Code](https://claude.ai/code/session_015E4TFL6EEnsG2GeLKbRYkJ)_
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.

feat(jq): missing builtins — input_filename / input_line_number / $ENV

1 participant