Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/host/hostMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export async function runHost(sessionId: string): Promise<void> {
rows: manifest.rows,
env: manifest.env ?? {},
term: manifest.term ?? 'xterm-256color',
sessionId,
});

invariant(
Expand Down
10 changes: 9 additions & 1 deletion src/pty/createPty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface PtyOptions {
rows: number;
env: Record<string, string>;
term: string;
sessionId?: string;
}

const EXECUTABLE_PERMISSION_MASK = 0o111;
Expand Down Expand Up @@ -96,6 +97,7 @@ export function resolvePtyEnv(
env: Record<string, string>,
term: string,
baseEnv: Record<string, string | undefined> = process.env,
sessionId?: string,
): Record<string, string> {
const resolved: Record<string, string> = {};
for (const [key, value] of Object.entries(baseEnv)) {
Expand All @@ -113,6 +115,12 @@ export function resolvePtyEnv(

Object.assign(resolved, env);
resolved.TERM = term;

resolved.AGENT_TTY_ACTIVE = 'true';
if (sessionId) {
resolved.AGENT_TTY_SESSION_ID = sessionId;
}

return resolved;
}

Expand Down Expand Up @@ -144,6 +152,6 @@ export function createPty(options: PtyOptions): IPty {
cwd,
cols,
rows,
env: resolvePtyEnv(env, term),
env: resolvePtyEnv(env, term, process.env, options.sessionId),
});
}
20 changes: 20 additions & 0 deletions test/unit/pty/createPty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,24 @@ describe('resolvePtyEnv', () => {
expect(resolved.BAZ).toBe('qux');
expect(Object.prototype.hasOwnProperty.call(resolved, 'EMPTY')).toBe(false);
});

it('unconditionally sets AGENT_TTY_ACTIVE to true', () => {
const resolved = resolvePtyEnv({}, 'xterm-256color', {});
expect(resolved.AGENT_TTY_ACTIVE).toBe('true');
});

it('sets AGENT_TTY_SESSION_ID when sessionId is provided', () => {
const resolved = resolvePtyEnv(
{},
'xterm-256color',
{},
'test-session-123',
);
expect(resolved.AGENT_TTY_SESSION_ID).toBe('test-session-123');
});

it('does not set AGENT_TTY_SESSION_ID when sessionId is not provided', () => {
const resolved = resolvePtyEnv({}, 'xterm-256color', {});
expect(resolved.AGENT_TTY_SESSION_ID).toBeUndefined();
});
});