fix: display CLI help text on stdout instead of stderr#80
Conversation
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
|
How other CLI tools handle these cases? Is display of help is error or success? |
|
🤖 AI Work Session Started Starting automated work session at 2025-12-21T20:07:35.618Z The PR has been converted to draft mode while work is in progress. This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback. |
Answer: Help display should go to STDOUT (success case)I researched how popular CLI tools handle this scenario. Here are the findings: Popular CLI Tools BehaviorWhen called without a subcommand, these tools display help on stdout: git → stdout: 2126 bytes, stderr: 0 bytes ✅ STDOUT
gh → stdout: 2442 bytes, stderr: 0 bytes ✅ STDOUT
npm → stdout: 1268 bytes, stderr: 0 bytes ✅ STDOUT
agent auth → stdout: 2242 bytes, stderr: 0 bytes ✅ STDOUT (after our fix)Invalid Subcommand vs No SubcommandCLI tools distinguish between these two cases: Case 1: No subcommand (user needs help)
Case 2: Invalid subcommand (actual error)
Why STDOUT is Correct
ConclusionHelp display is a success case - the tool is successfully showing the user what they need. Our fix aligns with how leading CLI tools (git, GitHub CLI, npm) handle this scenario. Full research findings are documented in |
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
|
Resolve merge conflicts, and ensure we don't ever show informational messages as stderr, use in all places stdout unless it is critical error, regular error or warning. Ensure all changes are correct, consistent, validated, tested and fully meet all discussed requirements (check issue description and all comments in issue and in pull request). Ensure all CI/CD checks pass. |
|
🤖 AI Work Session Started Starting automated work session at 2026-02-13T12:01:18.352Z The PR has been converted to draft mode while work is in progress. This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback. |
When running `agent auth` or `agent mcp` without a subcommand, the help text was sent to stderr via outputError(), causing it to appear in red in many terminals. Changed to use a new outputHelp() function that writes to stdout with type 'status', and strip ANSI color codes from yargs help output. Exit code changed from 1 to 0 since displaying help is not an error condition. This follows industry standards (git, gh, npm all use stdout for help). Fixes #77 Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
5058c14 to
7ffcf71
Compare
🤖 Solution Draft LogChanges Made
Working session completed. |
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
Summary
Fixed the color issue with help text when calling
agent authwithout a subcommand.Problem
When running
agent authwithout specifying a subcommand (likelogin,logout, etc.), the help text was appearing in red color in terminals. This happened because:outputError(), and many terminals display stderr output in redSolution
outputHelp()function injs/src/cli/output.tsthat writes to stdout with type'status'(informational, not error).fail()handler injs/src/index.jsto useoutputHelp()instead ofoutputError()for validation messages (no-subcommand case)yargs.help()output usingstripAnsi()1to0since displaying help is not an errorAudit Results
All
outputError()/writeStderr/process.stderrusages in the codebase were audited:index.js.fail()handler (msg case)index.js.fail()handler (err case)index.jsuncaughtException/unhandledRejectionindex.jsAuthenticationError, FileNotFoundindex.jsValidationError (--disable-stdin, etc.)continuous-mode.jsSessionNotFoundsession/agent.jsToolExecutionErrorjson-standard/index.tsevent outputcmd/export.ts@clack/promptsConclusion: Only the
.fail()handler's help text case was incorrectly using stderr. All other stderr usages are for genuine errors and are correct.Industry Standard Comparison
Changes
js/src/cli/output.ts: AddedoutputHelp()function that writes to stdoutjs/src/index.js: Changed.fail()handler to useoutputHelp()+stripAnsi()for validation messagesjs/.changeset/fix-auth-help-stdout.md: Changeset for patch releaseexperiments/test-help-stdout.sh: Test script verifying stdout outputexperiments/test-help-vs-error.sh: Test script verifying help vs error distinctionTesting
agent authhelp text goes to stdout (609 bytes), stderr empty (0 bytes)agent mcphelp text goes to stdout (427 bytes), stderr empty (0 bytes)agent --helpcontinues to work correctlyFixes #77