Skip to content

fix(cli): keep --json stdout payload-only by routing logger status to stderr#1422

Open
John-David Dalton (jdalton) wants to merge 1 commit into
mainfrom
jdalton/ask-115-add-no-log-option-to-suppress-npm-cli-output-in-scripts
Open

fix(cli): keep --json stdout payload-only by routing logger status to stderr#1422
John-David Dalton (jdalton) wants to merge 1 commit into
mainfrom
jdalton/ask-115-add-no-log-option-to-suppress-npm-cli-output-in-scripts

Conversation

@jdalton

@jdalton John-David Dalton (jdalton) commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

socket <cmd> --json leaked non-JSON onto stdout, breaking | jq and scripted use. Closes the ASK-115 loop: --json implies a clean stdout, no new --no-log flag.

Root cause

The lib logger routes its step / substep status helpers to stdout, while every other status helper (info / warn / success / fail) and the whole spinner go to stderr. Progress lines emitted via substep (e.g. the fix PR-cleanup step, the SDK unreadable-file notice) therefore landed on the payload stream under --json.

Fix

At the argv-parse boundary — not per command — when machine-output mode (--json / --markdown / --quiet) is engaged, step / substep are routed to stderr to match the spinner. logger.log is left untouched: it's the payload / primary-data channel (JSON, Markdown, and output-kind-gated human text all flow through it), so it stays on stdout.

New module util/output/machine-output-streams.mts, wired into both meowOrExit and meowWithSubcommands right after setMachineOutputMode.

Receipts

  • socket whoami --json → stdout is JSON only, stderr empty (payload path unchanged).
  • New unit test: step / substep route to stderr under --json / --markdown / --quiet, stay on stdout with no machine flag, and restore afterward.
test + check output
✓ test/unit/util/output/machine-output-streams.test.mts (5 tests)
✓ test/unit/util/output/ (all suites, 199 tests incl. ambient-mode, emit-payload, mode)
✓ test/unit/util/cli/ (with-subcommands, 56 tests)
✓ cmd-organization-quota (12) + cmd-scan-view (19)
[check] 132 check(s) passed

Scope

Commands with incomplete --json support (some manifest generators emit unguarded logger.log chatter, acknowledged in-code) are out of scope — this fixes the structural status-helper leak that affects every properly---json-capable command.


Note

Low Risk
Localized CLI output routing at parse time with restore semantics; no auth, data, or API behavior changes.

Overview
Fixes socket <cmd> --json (and --markdown / --quiet) leaking progress text onto stdout when commands use the shared logger’s step / substep helpers, which otherwise write to stdout unlike other status helpers.

Adds applyMachineOutputStreamPolicy in machine-output-streams.mts: at argv-parse time it temporarily shadows step / substep onto logger.error (stderr) while machine-output mode is active, restores defaults when it is not, and leaves logger.log on stdout for payloads. Wired immediately after setMachineOutputMode in meowOrExit and meowWithSubcommands, with unit tests for engage/restore behavior across machine flags.

Reviewed by Cursor Bugbot for commit ed010bf. Configure here.

… stderr

Under machine-output mode (--json/--markdown/--quiet) stdout must carry only the command payload, but the lib logger routes its step/substep status helpers to stdout while every other status helper and the spinner go to stderr. Progress messages therefore leaked onto the payload stream (the original ASK-115 report: 'socket fix --json' emitted stray output on stdout).

Route step/substep to stderr at the argv-parse boundary when machine-output mode is engaged; logger.log is left untouched as the payload/primary-data channel.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant