Skip to content

Commit 2c81abd

Browse files
Mossakaclaude
andauthored
fix: enable color output when --tty flag is set (#1427) (#1714)
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 b8f9f7a commit 2c81abd

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
@@ -555,10 +555,17 @@ export function generateDockerCompose(
555555
SQUID_PROXY_PORT: SQUID_PORT.toString(),
556556
HOME: homeDir,
557557
PATH: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
558-
// Disable ANSI color output from CLI tools (Rich, Chalk, etc.) inside the container.
559-
// Tools like Rich inject ANSI escape codes that break test assertions expecting plain text.
558+
// Color output control: when --tty is set, enable color output for tools that support it.
559+
// When tty is off (default), disable colors to avoid ANSI escape codes in log output.
560560
// NO_COLOR is a standard convention (https://no-color.org/) supported by many libraries.
561-
NO_COLOR: '1',
561+
// FORCE_COLOR is used by Chalk, Rich, and other tools to enable color output.
562+
...(config.tty ? {
563+
FORCE_COLOR: '1',
564+
TERM: 'xterm-256color',
565+
COLUMNS: '120',
566+
} : {
567+
NO_COLOR: '1',
568+
}),
562569
// Configure one-shot-token library with sensitive tokens to protect
563570
// These tokens are cached on first access and unset from /proc/self/environ
564571
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',
@@ -668,7 +675,8 @@ export function generateDockerCompose(
668675
// it gets a placeholder value set earlier (line ~362) for credential isolation
669676
if (process.env.COPILOT_GITHUB_TOKEN && !config.enableApiProxy) environment.COPILOT_GITHUB_TOKEN = process.env.COPILOT_GITHUB_TOKEN;
670677
if (process.env.USER) environment.USER = process.env.USER;
671-
if (process.env.TERM) environment.TERM = process.env.TERM;
678+
// When --tty is set, we use TERM=xterm-256color (set above); otherwise inherit host TERM
679+
if (process.env.TERM && !config.tty) environment.TERM = process.env.TERM;
672680
if (process.env.XDG_CONFIG_HOME) environment.XDG_CONFIG_HOME = process.env.XDG_CONFIG_HOME;
673681
// Enterprise environment variables — needed for GHEC/GHES Copilot authentication
674682
if (process.env.GITHUB_SERVER_URL) environment.GITHUB_SERVER_URL = process.env.GITHUB_SERVER_URL;

0 commit comments

Comments
 (0)