All jobs

Add JSON Output to a Rust CLI

An agent adds a --json flag to zoxide query that prints each match's path and frecency score, with four integration tests; cargo test and clippy pass.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads src/cmd/query.rs, the Query struct in src/cmd/cmd.rs, man/man1/zoxide-query.1, the existing tests and CHANGELOG.md before writing. query already chose between interactive, list and single-result output from one Stream of matches. serde was a dependency; serde_json was only in the lockfile through another crate.

It adds a json field with conflicts_with_all = ["interactive", "list", "score"] and a query_json method that collects every match, skips the --exclude path, and writes one array of {path, score} with serde_json::to_writer. The tests in tests/query_json.rs run the binary against a real temporary database, and a manual run printed [{"path":"/tmp/tmp.YckGnxl5nm/x","score":4.0}].

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "A Linear issue labeled agent says: \"Add JSON Output to a Rust CLI. Add a --json flag to zoxide query so it prints each result with its path and score as a JSON array, documented in the man page.\" Do the work in this repository, add tests for it, run cargo test and cargo clippy, and open a pull request that links back to the issue.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

Tried on ajeetdsouza/zoxide at f0b3163: 14 files changed, 126 insertions(+), 3 deletions(-), seven of them shell completions under contrib/completions/ that the crate's build.rs regenerated for the new flag. cargo test and plain cargo clippy passed on the untouched clone; the baseline clippy ran without --all-targets. After the change the new suite ended test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.03s, and cargo clippy --all-targets exited 0.

For the reviewer: --json always lists every match, even without --list, and score is the raw frecency float, not clamped or rounded like the --score text. serde_json becomes a direct dependency. The nix-dev-gated tests/completions.rs did not run.

Run it on every Linear issue labeled agent

An automation with a linear trigger on linear.issue.labeled and the label agent runs the linear-label-to-pr recipe's prompt when someone in your Rush org labels a request for machine-readable output. An issue that says whether --json without -l should print only the top match settles the one choice this run made on its own.

The use case this job follows, with its automation and trigger: Turn a Linear label into a PR.

Why run it on Rush?

A new flag on a clap CLI touches more than the command: zoxide's build.rs regenerated seven completion scripts, and the run kept them in the diff and named them for the reviewer. It made --json conflict with -i, -l and -s rather than print two formats, and json_conflicts_with_list tests that refusal.

Frequently asked questions

Why does --json list every match?

The run read "each result" in the request as a list. It says printing only the top match unless -l is given is a small change if you prefer that.

Did the build need anything the repository does not provide?

The sandbox had no Rust toolchain or C linker, and the first cargo test failed with error: linker 'cc' not found. The agent installed Rust with rustup and build-essential with apt, then ran the baseline. None of that is in the diff.

More Rust CLI jobs

The same job on other stacks

More jobs like this: Turn a Linear label into a PR

Keep reading