Skip to content

[Code Quality] Standardize output routing: Replace raw fmt.Println with explicit stderr routing #12531

@github-actions

Description

@github-actions

Description

The codebase contains 46 instances of raw fmt.Println() calls that should be replaced with explicit fmt.Fprintln(os.Stderr, ...) for consistent output routing. Following Unix conventions, diagnostic output should go to stderr, reserving stdout for structured data (JSON).

Current Issues

  1. Inconsistent output routing - Some diagnostic messages go to stdout, others to stderr
  2. Breaks Unix conventions - Data and diagnostics are mixed
  3. Complicates piping - Users can't easily separate data from diagnostics
  4. No linter enforcement - New instances can be introduced

Files Affected

The following files contain raw fmt.Println() calls that need conversion:

  • pkg/workflow/stop_after.go - 10 instances
  • pkg/workflow/mcp_config_custom.go - 1 instance
  • pkg/workflow/engine_firewall_support.go - 3 instances
  • pkg/campaign/command.go - 3 instances (JSON output exception)
  • pkg/cli/tool_graph.go - 1 instance
  • Additional files - ~28 instances

Suggested Changes

Pattern to Replace

// ❌ Current (wrong)
fmt.Println(console.FormatWarningMessage("Warning message"))
fmt.Printf("Status: %s\n", status)

// ✅ Correct
fmt.Fprintln(os.Stderr, console.FormatWarningMessage("Warning message"))
fmt.Fprintf(os.Stderr, "Status: %s\n", status)

Exception: JSON Output

// ✅ JSON output should go to stdout (not stderr)
fmt.Println(string(jsonBytes))  // Keep this for JSON output

Implementation Steps

  1. Identify all fmt.Println() and fmt.Printf() calls
  2. For each instance:
    • If JSON output → Keep as fmt.Println() to stdout
    • If diagnostic output → Change to fmt.Fprintln(os.Stderr, ...)
  3. Run full test suite to verify no breakage
  4. Update AGENTS.md with output routing guidelines

Success Criteria

  • All non-JSON fmt.Println() calls replaced with fmt.Fprintln(os.Stderr, ...)
  • All non-JSON fmt.Printf() calls replaced with fmt.Fprintf(os.Stderr, ...)
  • JSON output continues to go to stdout
  • All tests pass
  • AGENTS.md updated with output routing convention
  • Consider adding linter rule to prevent new instances

Priority

High - Affects consistency across entire CLI, impacts user experience when piping/redirecting output

Source

Extracted from Terminal Stylist Analysis discussion #12488

The analysis identified 46 instances of raw fmt.Print* calls that should be standardized for consistent output routing following Unix conventions.

AI generated by Discussion Task Miner - Code Quality Improvement Agent

  • expires on Feb 12, 2026, 1:27 PM UTC

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions