fix(cli): keep stdout parseable in JSON mode - #257
Merged
Conversation
`--json` is documented as machine-readable output, but some commands wrote
human-facing progress text to stdout ahead of the JSON document, so piping
the output into a parser failed:
$ kudu --cli programs list --json
Loading installed programs...
{ "programs": [ ...
$ kudu --cli network scan --json
Scanning network...
{ "items": [ ...
The behaviour was inconsistent — `perf info` and `startup list` emitted clean
JSON while `programs list` and `network scan` did not.
Route `cliLog()` and `cliVerbose()` to stderr when `ctx.json` is set. Progress
is preserved (visible on stderr, or redirectable with `2>/dev/null`) while
stdout becomes a single parseable JSON document. Both helpers are fixed at the
source rather than at their ~116 call sites, so every command benefits.
`showProgress()` already suppressed carriage-return progress in JSON mode, so
that path was unaffected.
Adds tests covering both streams in JSON and human modes, and documents the
stdout/stderr split in CLI.md.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
evolv3ai
added a commit
to evolv3ai/kudu
that referenced
this pull request
Jul 26, 2026
CLI.md documented three commands (scan, clean, metrics) while the CLI dispatcher exposes twenty command groups. `kudu --cli --help` was already accurate; only the Markdown had gone stale. Rewrites CLI.md against the actual command surface, verified empirically on Windows 11: - All twenty command groups with subcommands, grouped by purpose (inventory/diagnostics, maintenance, security, config). - Per-command annotations for what works without elevation, and which commands are long-running filesystem walks. - The graceful-degradation contract: privileged operations return `needsAdmin: true` with exit code 0, so scripts must check the flag rather than infer from exit status. - Elevation behaviour, including that packaged Windows builds force UAC via `requestedExecutionLevel: requireAdministrator` while running from source does not — the code path for unelevated operation is fully supported. - That `network scan` reports entry counts rather than entries, and the platform layer's `getEstablishedConnections()` is not CLI-reachable. - That `metrics-server` binds 0.0.0.0 and needs no cloud API key, unlike `--daemon`. Fork-specific: the unelevated verification tables and source-route invocation notes reflect this fork's use as a system-data source for local agent tooling. Upstream received only the narrow stdout/stderr fix (AdventDevInc#257); this broader rewrite is deliberately kept here. Claims that could not be verified are marked as such rather than asserted: `malware scan` was not run to completion, and `disk analyze`/`disk file-types` exceeded a 180s timeout on a 2TB volume. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 37b7db819c
ℹ️ 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".
The --json stdout-purity guarantee didn't hold for `malware scan --json`: _initYaraEngine() and the engine's platform-skip line logged `[yara] ...` via console.log (stdout) before the JSON result, breaking `| jq`. Route both to stderr (console.error), matching the other [yara] diagnostics.
Contributor
|
Thank you @evolv3ai ! |
dbfx
approved these changes
Jul 27, 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.
What does this PR do?
Routes CLI progress output to stderr when
--jsonis passed, so stdout contains nothing but the JSON document.Why?
--jsonis documented as "Output results as JSON instead of human-readable text", but several commands print a progress line to stdout ahead of the JSON, which breaks any consumer that pipes stdout into a parser:The behaviour was inconsistent, which is what suggested an oversight rather than a deliberate choice —
perf infoandstartup listalready emitted clean JSON, whileprograms listandnetwork scandid not.cliLog()andcliVerbose()are fixed at the source instead of at their ~116 call sites, so every command benefits and no future call site can reintroduce it. Progress isn't lost — it moves to stderr, so it still shows in a terminal and can be captured (2>progress.log) or dropped (2>/dev/null).showProgress()already suppressed carriage-return progress in JSON mode, so that path was unaffected.How to test
Unit tests cover both streams across JSON/human/quiet modes in
src/main/cli.test.ts.Checklist
npm testpasses — 2167 tests, 93 filesnpm run buildsucceeds🤖 Generated with Claude Code