Clean up JSON output: logging helpers, stderr routing, and lifecycle signals#249
Merged
umair-ably merged 9 commits intomainfrom Apr 1, 2026
Merged
Clean up JSON output: logging helpers, stderr routing, and lifecycle signals#249umair-ably merged 9 commits intomainfrom
umair-ably merged 9 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThis PR standardises JSON output across the entire CLI by introducing five logging helpers on Changes
Review Notes
|
3 tasks
Contributor
|
Found few inconsistencies
|
Contributor
|
377327e to
9687ee6
Compare
Introduce five logging helpers on AblyBaseCommand that route status messages to stderr (human) or structured JSON (agents/scripts): - logProgress/logSuccessMessage: silent in JSON mode - logListening/logHolding/logWarning: emit structured JSON status events Also adds: - JSON completed signal in finally() so agents know when a command ends - Connection and channel state change events emitted in JSON mode - Cleanup timeout/error messages moved to stderr unconditionally - chat-base-command and stats-base-command updated to use new helpers
Add parseJsonOutput() and parseAllJsonRecords() to test/helpers/ndjson.ts. These handle stdout that now contains multiple JSON records (e.g. result + completed signal) in both compact NDJSON and pretty-printed formats.
Flag description now reads "(required with --json)" since JSON mode cannot show interactive confirmation prompts.
Mechanical migration across all ~99 command files: - Replace this.log(formatProgress/Success/Listening/Warning(...)) with this.logProgress/logSuccessMessage/logListening/logWarning(msg, flags) - Remove manual shouldOutputJson guards around status messages - Status text now routes to stderr (human) or structured JSON (agents) - stdout reserved for data output only
Mechanical test updates across ~104 test files: - Switch stdout assertions to stderr for status/progress/success messages - Use parseJsonOutput() for JSON tests that now receive multiple records (result + completed signal) - Adjust JSON output parsing to handle NDJSON format
E2E tests updated to check stderr instead of stdout for status/progress messages, matching the new output routing where status goes to stderr and only data goes to stdout.
- AGENTS.md: document logging helpers, completed signal, JSON hold status - Skills: update patterns, review checks, and code examples to reflect new logProgress/logSuccessMessage/logListening/logHolding/logWarning helpers instead of old manual formatX + shouldOutputJson pattern - README.md: regenerated from command metadata
…rr, enforce --force
- Respect --json with --token-only in auth token commands
- Auto-remove invalid/revoked keys in JSON mode instead of hanging on prompts
- Enforce --force flag for push publish commands in JSON mode
- Route formatLimitWarning output to stderr (19 commands)
- Migrate this.warn() to this.logWarning() for structured JSON warnings
- Fix premature logListening emission before subscription is ready
- Fix shouldOutputJson({}) dead code in bench commands
- Check stderr (not stdout) for status messages like "Entered presence", "Location set in space:", and "Waiting for" - Parse NDJSON correctly: find type "result" line for history, first line for list (completed status signal is appended as last line)
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.
Targets #248
Intent
This PR makes JSON output reliable and predictable for agent/script consumers, while cleaning up inconsistencies that accumulated across the codebase. The specific problems addressed:
JSON mode omitted useful status information. Connection state changes, progress messages, and warnings were silently swallowed in
--jsonmode. Agents had no way to observe connection lifecycle or know why a command was stalling.Mixed and inconsistent output routing. Some commands used
this.log(), othersthis.logToStderr(), othersconsole.log()for status messages. JSON guards (shouldOutputJson) were applied inconsistently — some commands guarded progress messages, others didn't, leading to human-readable text leaking into JSON stdout.No command completion signal. JSON consumers had no way to know when a command finished — they had to rely on process exit, which doesn't distinguish clean exit from crash. Agents need a definitive "done" signal.
Status text polluted stdout. Success messages, progress indicators, and warnings were written to stdout alongside data, making it impossible for JSON consumers to get clean machine-parseable output without filtering.
--forceflag was silently required in JSON mode. Commands with confirmation prompts would hang in JSON mode (no TTY to prompt). The flag description didn't communicate this.Commits
Add logging helpers and JSON lifecycle events to base commandlogProgress,logSuccessMessage,logListening,logHolding,logWarninghelpers onAblyBaseCommand. JSON completed signal infinally(). Connection/channel state events in JSON mode. Updateschat-base-commandandstats-base-command.Add NDJSON test helpers for multi-record JSON outputparseJsonOutput()andparseAllJsonRecords()intest/helpers/ndjson.tsfor tests that now receive multiple JSON records on stdout.Update --force flag description to indicate JSON mode requirementsrc/flags.ts.Migrate commands to use logging helpers and stderr for status outputthis.log(formatProgress/Success/Listening/Warning(...))withthis.logProgress/logSuccessMessage/logListening/logWarning(msg, flags), removeshouldOutputJsonguards around status messages.Update unit tests for stderr status messages and NDJSON outputstdout→stderrassertions for status messages, useparseJsonOutputfor multi-record JSON.Update E2E tests for stderr status messagesUpdate documentation, skills, and AGENTS.mdTest plan
pnpm preparesucceedspnpm exec eslint .— 0 errorspnpm test:unit— all passpnpm test:e2e— verify stderr routing in real subprocess execution🤖 Generated with Claude Code