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
Conversation
… 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.
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.
socket <cmd> --jsonleaked non-JSON onto stdout, breaking| jqand scripted use. Closes the ASK-115 loop:--jsonimplies a clean stdout, no new--no-logflag.Root cause
The lib logger routes its
step/substepstatus helpers to stdout, while every other status helper (info/warn/success/fail) and the whole spinner go to stderr. Progress lines emitted viasubstep(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/substepare routed to stderr to match the spinner.logger.logis 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 bothmeowOrExitandmeowWithSubcommandsright aftersetMachineOutputMode.Receipts
socket whoami --json→ stdout is JSON only, stderr empty (payload path unchanged).step/substeproute to stderr under--json/--markdown/--quiet, stay on stdout with no machine flag, and restore afterward.test + check output
Scope
Commands with incomplete
--jsonsupport (somemanifestgenerators emit unguardedlogger.logchatter, 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’sstep/substephelpers, which otherwise write to stdout unlike other status helpers.Adds
applyMachineOutputStreamPolicyinmachine-output-streams.mts: at argv-parse time it temporarily shadowsstep/substepontologger.error(stderr) while machine-output mode is active, restores defaults when it is not, and leaveslogger.logon stdout for payloads. Wired immediately aftersetMachineOutputModeinmeowOrExitandmeowWithSubcommands, with unit tests for engage/restore behavior across machine flags.Reviewed by Cursor Bugbot for commit ed010bf. Configure here.