Skip to content

fix(cli): avoid leaking raw ANSI color codes in non-rendering consoles#3229

Merged
migmartri merged 1 commit into
mainfrom
fix/cli-color-tty-detection
Jun 24, 2026
Merged

fix(cli): avoid leaking raw ANSI color codes in non-rendering consoles#3229
migmartri merged 1 commit into
mainfrom
fix/cli-color-tty-detection

Conversation

@migmartri

@migmartri migmartri commented Jun 22, 2026

Copy link
Copy Markdown
Member

What

The CLI logs through zerolog's ConsoleWriter, which colorized output unconditionally. Consumers that do not interpret ANSI escape codes (a Jenkins console without the AnsiColor plugin, piped output, log files) showed them as raw control sequences (e.g. [31mERR[0m).

Color detection now follows the same model as the widely used supports-color/chalk family:

  • Honor the NO_COLOR opt-out and CLICOLOR_FORCE / FORCE_COLOR opt-in conventions (these take precedence).
  • TERM=dumb disables color.
  • Enable color on an interactive terminal.
  • For non-terminal output, enable color only for CI systems known to render ANSI in their logs (GitHub Actions, GitLab CI, CircleCI, Travis, Buildkite, Drone, AppVeyor). Jenkins is intentionally excluded, so it falls back to the no-color default and keeps its logs clean.

Net effect: interactive terminals, GitHub Actions and GitLab keep colored output; Jenkins (without the AnsiColor plugin), pipes and files are now clean.

The decision logic is isolated in a pure, unit-tested function.

Closes #3228

AI assistance

This contribution was assisted by Claude Code.

🤖 Posted by Maximus bot (Claude Code) on behalf of @migmartri

@chainloop-platform

chainloop-platform Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

AI Session Analysis

Avg score Sessions Failing policies Attribution Files Lines Total Duration
🟢 88% 1 ✅ 0 100% AI / 0% Human 3 +228 / -2 42h28m46s

🟢 88% — 100% AI — ✅ All policies passing

Jun 22, 2026 06:58 UTC · 42h28m46s · $30.33 · 87.8k in / 211.3k out · claude-code 2.1.185 (claude-opus-4-8)

View session details ↗

Change Summary

  • Adds CLI color-detection logic for non-rendering consoles and supported CI environments.
  • Wires the helper into app/cli/main.go so zerolog disables color when appropriate.
  • Adds and updates CLI color tests, then reruns targeted Go tests, builds, and CI checks.

AI Session Overall Score

🟢 88% — Strong fix and verification; only explicit planning lagged behind the design pivots.

AI Session Analysis Breakdown

🟢 95% · scope-discipline

No notes.

🟢 90% · solution-quality

🟢 AI abandoned the bespoke Jenkins heuristic once precedent-backed approaches surfaced. · High Impact

🟢 89% · verification

🟢 AI reran targeted Go tests and builds after each design pivot. · High Impact

🟢 88% · alignment

No notes.

🟢 86% · user-trust-signal

No notes.

🟡 72% · context-and-planning

🟢 User opened with a concrete Jenkins repro and expected behavior. · High Impact

🟠 No visible plan or TODO anchored the session despite repeated design pivots and later PR follow-through. · Medium Severity

💡 For branching changes, write a short shared plan before editing so later pivots have a stable reference.


File Attribution

████████████████████ 100% AI / 0% Human

Status Attribution File Lines
created ai app/cli/cmd/color_test.go +127 / -0
created ai app/cli/cmd/color.go +91 / -0
modified ai app/cli/main.go +10 / -2

Policies (4)

Status Policy Material Messages
✅ Passed ai-config-ai-agents-allowed ai-coding-session-5dbf67 -
✅ Passed ai-config-no-dangerous-commands ai-coding-session-5dbf67 -
✅ Passed ai-config-no-secrets ai-coding-session-5dbf67 -
✅ Passed ai-config-mcp-servers-allowed ai-coding-session-5dbf67 -

Powered by Chainloop and Chainloop Trace

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

@migmartri migmartri force-pushed the fix/cli-color-tty-detection branch from 0f9bc9f to 6b80c0e Compare June 22, 2026 13:34
@migmartri migmartri changed the title fix(cli): avoid leaking raw ANSI color codes in Jenkins console fix(cli): avoid leaking raw ANSI color codes in non-rendering consoles Jun 22, 2026
@migmartri migmartri requested a review from a team June 23, 2026 23:17
@migmartri migmartri force-pushed the fix/cli-color-tty-detection branch from 6b80c0e to 03314f6 Compare June 23, 2026 23:18
The CLI logs through zerolog's ConsoleWriter, which colorized output
unconditionally. Consumers that do not interpret ANSI escape codes (a
Jenkins console without the AnsiColor plugin, piped output, log files)
showed them as raw control sequences.

Color detection now follows the same model as the widely used
supports-color/chalk family: honor the NO_COLOR and CLICOLOR_FORCE /
FORCE_COLOR conventions, enable color on an interactive terminal, and
for non-terminal output enable it only for CI systems known to render
ANSI (GitHub Actions, GitLab CI, CircleCI, Travis, Buildkite, Drone,
AppVeyor). Jenkins is intentionally excluded, so it falls back to the
no-color default and keeps its logs clean.

Closes #3228

Assisted-by: Claude Code
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>

Chainloop-Trace-Sessions: 5dbf672f-418b-459c-b51f-485c213d3c40
@migmartri migmartri merged commit a783c6c into main Jun 24, 2026
15 checks passed
@migmartri migmartri deleted the fix/cli-color-tty-detection branch June 24, 2026 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI emits raw ANSI color codes in non-TTY environments (e.g. Jenkins)

2 participants