Skip to content

Commit e361b86

Browse files
Mossakaclaude
andcommitted
fix: enable color output when --tty flag is set (#1427)
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>
1 parent 8b903e7 commit e361b86

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

src/docker-manager.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,26 @@ describe('docker-manager', () => {
610610
expect(env.AWF_SSL_BUMP_ENABLED).toBeUndefined();
611611
});
612612

613-
it('should set NO_COLOR=1 to disable ANSI color output from CLI tools', () => {
613+
it('should set NO_COLOR=1 when tty is false (default)', () => {
614614
const result = generateDockerCompose(mockConfig, mockNetworkConfig);
615615
const agent = result.services.agent;
616616
const env = agent.environment as Record<string, string>;
617617

618618
expect(env.NO_COLOR).toBe('1');
619+
expect(env.FORCE_COLOR).toBeUndefined();
620+
expect(env.COLUMNS).toBeUndefined();
621+
});
622+
623+
it('should set FORCE_COLOR, TERM, and COLUMNS when tty is true', () => {
624+
const ttyConfig = { ...mockConfig, tty: true };
625+
const result = generateDockerCompose(ttyConfig, mockNetworkConfig);
626+
const agent = result.services.agent;
627+
const env = agent.environment as Record<string, string>;
628+
629+
expect(env.FORCE_COLOR).toBe('1');
630+
expect(env.TERM).toBe('xterm-256color');
631+
expect(env.COLUMNS).toBe('120');
632+
expect(env.NO_COLOR).toBeUndefined();
619633
});
620634

621635
it('should mount required volumes in agent container (default behavior)', () => {

src/docker-manager.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,17 @@ export function generateDockerCompose(
536536
SQUID_PROXY_PORT: SQUID_PORT.toString(),
537537
HOME: homeDir,
538538
PATH: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
539-
// Disable ANSI color output from CLI tools (Rich, Chalk, etc.) inside the container.
540-
// Tools like Rich inject ANSI escape codes that break test assertions expecting plain text.
539+
// Color output control: when --tty is set, enable color output for tools that support it.
540+
// When tty is off (default), disable colors to avoid ANSI escape codes in log output.
541541
// NO_COLOR is a standard convention (https://no-color.org/) supported by many libraries.
542-
NO_COLOR: '1',
542+
// FORCE_COLOR is used by Chalk, Rich, and other tools to enable color output.
543+
...(config.tty ? {
544+
FORCE_COLOR: '1',
545+
TERM: 'xterm-256color',
546+
COLUMNS: '120',
547+
} : {
548+
NO_COLOR: '1',
549+
}),
543550
// Configure one-shot-token library with sensitive tokens to protect
544551
// These tokens are cached on first access and unset from /proc/self/environ
545552
AWF_ONE_SHOT_TOKENS: 'COPILOT_GITHUB_TOKEN,GITHUB_TOKEN,GH_TOKEN,GITHUB_API_TOKEN,GITHUB_PAT,GH_ACCESS_TOKEN,OPENAI_API_KEY,OPENAI_KEY,ANTHROPIC_API_KEY,CLAUDE_API_KEY,CODEX_API_KEY',
@@ -649,7 +656,8 @@ export function generateDockerCompose(
649656
// it gets a placeholder value set earlier (line ~362) for credential isolation
650657
if (process.env.COPILOT_GITHUB_TOKEN && !config.enableApiProxy) environment.COPILOT_GITHUB_TOKEN = process.env.COPILOT_GITHUB_TOKEN;
651658
if (process.env.USER) environment.USER = process.env.USER;
652-
if (process.env.TERM) environment.TERM = process.env.TERM;
659+
// When --tty is set, we use TERM=xterm-256color (set above); otherwise inherit host TERM
660+
if (process.env.TERM && !config.tty) environment.TERM = process.env.TERM;
653661
if (process.env.XDG_CONFIG_HOME) environment.XDG_CONFIG_HOME = process.env.XDG_CONFIG_HOME;
654662
// Enterprise environment variables — needed for GHEC/GHES Copilot authentication
655663
if (process.env.GITHUB_SERVER_URL) environment.GITHUB_SERVER_URL = process.env.GITHUB_SERVER_URL;

0 commit comments

Comments
 (0)