Skip to content

[plan] Abstract manual ANSI escape sequences to console package #11622

@github-actions

Description

@github-actions

Objective

Move hardcoded ANSI escape sequence (\033[K) from logs_orchestrator.go into the console package as a proper helper function.

Context

From discussion #11611: The codebase has 1 instance of manual ANSI escape codes that should be abstracted through the console package for consistency and TTY detection.

Current Issue: logs_orchestrator.go:778 uses fmt.Fprint(os.Stderr, "\r\033[K") directly.

Approach

  1. Create console.ClearLine() helper function:

    • Add new function in pkg/console/ (suggest output.go or new terminal.go)
    • Implement TTY detection using tty.IsStderrTerminal()
    • Only output ANSI codes when in TTY mode
  2. Update logs_orchestrator.go:

    • Replace manual ANSI escape with console.ClearLine() call
    • Import console package if not already imported
  3. Add tests:

    • Test TTY mode outputs ANSI sequence
    • Test non-TTY mode outputs nothing
    • Add to existing console package tests

Files to Modify

  • Create/Update: pkg/console/terminal.go (or appropriate file)
  • Update: pkg/cli/logs_orchestrator.go (line ~778)
  • Update: pkg/console/*_test.go (add test coverage)

Implementation Example

// pkg/console/terminal.go
func ClearLine() {
    if tty.IsStderrTerminal() {
        fmt.Fprint(os.Stderr, "\r\033[K")
    }
}
// logs_orchestrator.go (replace line ~778)
// Before:
fmt.Fprint(os.Stderr, "\r\033[K")

// After:
console.ClearLine()

Acceptance Criteria

  • console.ClearLine() function created with TTY detection
  • Manual ANSI escape in logs_orchestrator.go replaced with console helper
  • Tests verify TTY and non-TTY behavior
  • Code passes make fmt and make lint
  • make agent-finish completes successfully

Priority

Phase 1: Critical Fix (1-2 hours estimated)

AI generated by Plan Command for discussion #11611

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions