diff --git a/src/host/hostMain.ts b/src/host/hostMain.ts index 6b25fc4..ff56591 100644 --- a/src/host/hostMain.ts +++ b/src/host/hostMain.ts @@ -245,6 +245,7 @@ export async function runHost(sessionId: string): Promise { rows: manifest.rows, env: manifest.env ?? {}, term: manifest.term ?? 'xterm-256color', + sessionId, }); invariant( diff --git a/src/pty/createPty.ts b/src/pty/createPty.ts index fbf5005..97c5897 100644 --- a/src/pty/createPty.ts +++ b/src/pty/createPty.ts @@ -16,6 +16,7 @@ export interface PtyOptions { rows: number; env: Record; term: string; + sessionId?: string; } const EXECUTABLE_PERMISSION_MASK = 0o111; @@ -96,6 +97,7 @@ export function resolvePtyEnv( env: Record, term: string, baseEnv: Record = process.env, + sessionId?: string, ): Record { const resolved: Record = {}; for (const [key, value] of Object.entries(baseEnv)) { @@ -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; } @@ -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), }); } diff --git a/test/unit/pty/createPty.test.ts b/test/unit/pty/createPty.test.ts index 62c0e71..477069b 100644 --- a/test/unit/pty/createPty.test.ts +++ b/test/unit/pty/createPty.test.ts @@ -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(); + }); });