fix: enable color output when --tty flag is set#1714
Conversation
When --tty is set, use FORCE_COLOR=1, TERM=xterm-256color, and COLUMNS=120 instead of NO_COLOR=1 so tools get proper color detection and terminal dimensions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (1 files)
Coverage comparison generated by |
There was a problem hiding this comment.
Pull request overview
This PR updates agent container color/TTY behavior so that ANSI color output is enabled only when the existing --tty flag is used, while keeping default non-TTY runs free of escape codes that can break log/snapshot assertions.
Changes:
- Switches agent environment color controls to
FORCE_COLOR=1,TERM=xterm-256color,COLUMNS=120whenconfig.ttyis true; otherwise setsNO_COLOR=1. - Prevents host
TERMfrom overriding the explicitTERM=xterm-256colorwhen--ttyis active. - Adds unit tests covering both tty and non-tty environment variable behavior.
Show a summary per file
| File | Description |
|---|---|
| src/docker-manager.ts | Implements conditional color/TERM env handling based on config.tty and avoids inheriting host TERM in tty mode. |
| src/docker-manager.test.ts | Adds coverage verifying env var differences between tty and non-tty configurations. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
|
Smoke test results (run 24042861995) ✅ GitHub MCP — Last 2 merged PRs: "⚡ pelis-agent-factory-advisor: pre-fetch content..." (#1701), "chore: upgrade gh-aw to v0.67.0..." (#1686) Overall: PASS
|
🔥 Smoke Test Results
PR: fix: enable color output when --tty flag is set Overall: PASS ✅
|
Smoke Test StatusPR Titles: ⚡ pelis-agent-factory-advisor: pre-fetch content, restrict tools, reduce prompt tokens (~21% token savings); chore: upgrade gh-aw to v0.67.0 and recompile all workflows
|
🧪 Chroot Version Comparison Results
Result: ❌ Not all tests passed — Python and Node.js versions differ between host and chroot environment.
|
Smoke Test: GitHub Actions Services Connectivity
Root cause: No GitHub Actions service containers (Redis, PostgreSQL) are running in this environment. The All 3 checks failed —
|
There was a problem hiding this comment.
Pull request overview
This PR adjusts how the agent container’s ANSI color behavior is configured by tying it to the existing --tty flag, addressing #1427 where lack of TTY breaks color detection and interactive output.
Changes:
- When
--ttyis set, enable color-oriented env vars (FORCE_COLOR=1,TERM=xterm-256color,COLUMNS=120); otherwise default toNO_COLOR=1. - Prevent host
TERMfrom being inherited when--ttyis enabled (soTERM=xterm-256colorremains effective). - Add unit tests for tty vs non-tty color environment behavior.
Show a summary per file
| File | Description |
|---|---|
| src/docker-manager.ts | Updates agent container environment construction to toggle color-related env vars based on config.tty, and adjusts host TERM inheritance logic. |
| src/docker-manager.test.ts | Adds assertions for the new tty/non-tty env behavior. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 2
| ...(config.tty ? { | ||
| FORCE_COLOR: '1', | ||
| TERM: 'xterm-256color', | ||
| COLUMNS: '120', | ||
| } : { | ||
| NO_COLOR: '1', | ||
| }), |
There was a problem hiding this comment.
When config.envAll is enabled and config.tty is true, this block does not set NO_COLOR, so NO_COLOR from the host environment can be injected later by the --env-all passthrough and end up disabling colors even though --tty was requested. Consider explicitly excluding NO_COLOR (and possibly related variables) when config.tty is true, or deleting environment.NO_COLOR after the env-all merge to ensure tty reliably enables color output.
| expect(env.COLUMNS).toBe('120'); | ||
| expect(env.NO_COLOR).toBeUndefined(); | ||
| }); | ||
|
|
There was a problem hiding this comment.
Current tests validate the default (tty=false) and tty=true env values, but they don’t cover common override scenarios that this PR is meant to address: (1) host TERM being present should not override TERM=xterm-256color when tty=true, and (2) with envAll: true, host NO_COLOR should not leak into the agent env when tty=true. Adding targeted tests for these cases would prevent regressions.
| it('should not let host TERM override TERM=xterm-256color when tty is true', () => { | |
| const originalTerm = process.env.TERM; | |
| process.env.TERM = 'screen-256color'; | |
| try { | |
| const ttyConfig = { ...mockConfig, tty: true }; | |
| const result = generateDockerCompose(ttyConfig, mockNetworkConfig); | |
| const agent = result.services.agent; | |
| const env = agent.environment as Record<string, string>; | |
| expect(env.FORCE_COLOR).toBe('1'); | |
| expect(env.TERM).toBe('xterm-256color'); | |
| expect(env.COLUMNS).toBe('120'); | |
| expect(env.NO_COLOR).toBeUndefined(); | |
| } finally { | |
| if (originalTerm === undefined) { | |
| delete process.env.TERM; | |
| } else { | |
| process.env.TERM = originalTerm; | |
| } | |
| } | |
| }); | |
| it('should not leak host NO_COLOR into agent env when envAll is true and tty is true', () => { | |
| const originalNoColor = process.env.NO_COLOR; | |
| process.env.NO_COLOR = '1'; | |
| try { | |
| const ttyEnvAllConfig = { ...mockConfig, tty: true, envAll: true }; | |
| const result = generateDockerCompose(ttyEnvAllConfig, mockNetworkConfig); | |
| const agent = result.services.agent; | |
| const env = agent.environment as Record<string, string>; | |
| expect(env.FORCE_COLOR).toBe('1'); | |
| expect(env.TERM).toBe('xterm-256color'); | |
| expect(env.COLUMNS).toBe('120'); | |
| expect(env.NO_COLOR).toBeUndefined(); | |
| } finally { | |
| if (originalNoColor === undefined) { | |
| delete process.env.NO_COLOR; | |
| } else { | |
| process.env.NO_COLOR = originalNoColor; | |
| } | |
| } | |
| }); |
Summary
--ttyCLI flag: when set, usesFORCE_COLOR=1,TERM=xterm-256color,COLUMNS=120instead of unconditionalNO_COLOR=1TERMfrom overriding the explicitxterm-256colorwhen--ttyis activeCloses #1427
Test plan
awf --tty --allow-domains example.com 'env | grep -E "FORCE_COLOR|TERM|COLUMNS|NO_COLOR"'shows correct env vars🤖 Generated with Claude Code