Problem statement
User-visible output is scattered across fmt.Print*, Cobra, the interactive login path, and MCP. Stdio MCP requires a strict contract: stdout = JSON-RPC only; everything else should go to stderr or an injected writer. Violations regress MCP hosts (e.g. "not valid JSON" in the client). Phase 1 fixes the known gateway mcp + Execute() paths; a broader design reduces repeat risk.
Direction to explore
- A small presentation / output boundary, e.g.
UserOutput with Out, Err io.Writer on config or cmd, defaulting to os.Stdout / os.Stderr.
- Modes:
TTY vs MCPStdio (or NonInteractive) chosen once per invocation (command leaf, env, or context).
Execute() and other high-touch paths use Err (or mode-aware writers) instead of hardcoded stdout for messages when in MCP stdio mode.
- Longer term: inventory and migrate direct
fmt.Print where protocol safety matters.
Questions for the spike
- How much of the codebase writes non-protocol text to stdout? (grep / inventory)
- Should MCP mode be env-only, command-derived, or both?
- logrus / verbose logging: ensure debug does not hit stdout in MCP.
- Tests: subprocess
gateway mcp + fake stdin; assert no non-JSON lines on stdout until JSON-RPC (may overlap Phase 1d acceptance tests).
Exit criteria
Close with a short design note + follow-up epic, or won't do with rationale (cost vs. rare footguns).
Problem statement
User-visible output is scattered across
fmt.Print*, Cobra, the interactive login path, and MCP. Stdio MCP requires a strict contract: stdout = JSON-RPC only; everything else should go to stderr or an injected writer. Violations regress MCP hosts (e.g. "not valid JSON" in the client). Phase 1 fixes the knowngateway mcp+Execute()paths; a broader design reduces repeat risk.Direction to explore
UserOutputwithOut,Err io.Writeronconfigorcmd, defaulting toos.Stdout/os.Stderr.TTYvsMCPStdio(orNonInteractive) chosen once per invocation (command leaf, env, or context).Execute()and other high-touch paths useErr(or mode-aware writers) instead of hardcoded stdout for messages when in MCP stdio mode.fmt.Printwhere protocol safety matters.Questions for the spike
gateway mcp+ fake stdin; assert no non-JSON lines on stdout until JSON-RPC (may overlap Phase 1d acceptance tests).Exit criteria
Close with a short design note + follow-up epic, or won't do with rationale (cost vs. rare footguns).