feat(terminal): set TERM_PROGRAM_VERSION on PTY env (#951)

TUIs feature-gate on TERM_PROGRAM_VERSION (Neovim's terminal
autodetection, bat/delta styling hints, etc). We already set
TERM_PROGRAM=Orca but left the version unset, so tools can't distinguish
Orca builds or tell when version-gated features are safe to enable.

Seed process.env.ORCA_APP_VERSION from app.getVersion() at main startup
and read it from both PTY spawn sites (main-side local-pty-provider and
the daemon-side pty-subprocess, which inherits env via fork). Keeps
providers/local-pty-provider.ts free of electron imports.
This commit is contained in:
Neil 2026-04-22 14:42:19 -07:00 committed by GitHub
parent 89b85b828b
commit d56fcff469
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 1 deletions

View File

@ -35,7 +35,11 @@ export function createPtySubprocess(opts: PtySubprocessOptions): SubprocessHandl
...opts.env,
TERM: 'xterm-256color',
COLORTERM: 'truecolor',
TERM_PROGRAM: 'Orca'
TERM_PROGRAM: 'Orca',
// Why: TUIs feature-gate on TERM_PROGRAM_VERSION. The daemon is forked
// by main (daemon-init.ts:93) with the parent's env, so ORCA_APP_VERSION
// — set in src/main/index.ts from app.getVersion() — is inherited here.
TERM_PROGRAM_VERSION: process.env.ORCA_APP_VERSION ?? '0.0.0-dev'
} as Record<string, string>
env.LANG ??= 'en_US.UTF-8'

View File

@ -55,6 +55,11 @@ let runtimeRpc: OrcaRuntimeRpcServer | null = null
let starNag: StarNagService | null = null
installUncaughtPipeErrorGuard()
// Why: propagate the Orca app version into `process.env` so PTY-env
// construction in both main (local-pty-provider) and the forked daemon
// (pty-subprocess) can set `TERM_PROGRAM_VERSION` without re-importing
// electron. The daemon inherits `process.env` via fork (daemon-init.ts:93).
process.env.ORCA_APP_VERSION = app.getVersion()
patchPackagedProcessPath()
// Why: patchPackagedProcessPath seeds a minimal list of well-known system
// dirs synchronously so early IPC (e.g. preflight before the shell spawn

View File

@ -261,6 +261,16 @@ describe('registerPtyHandlers', () => {
expect(env.TERM_PROGRAM).toBe('Orca')
})
it('surfaces ORCA_APP_VERSION as TERM_PROGRAM_VERSION for TUI feature gating', async () => {
const env = await spawnAndGetEnv(undefined, { ORCA_APP_VERSION: '1.2.3-test' })
expect(env.TERM_PROGRAM_VERSION).toBe('1.2.3-test')
})
it('falls back to a placeholder version when ORCA_APP_VERSION is unset', async () => {
const env = await spawnAndGetEnv(undefined, { ORCA_APP_VERSION: undefined })
expect(env.TERM_PROGRAM_VERSION).toBe('0.0.0-dev')
})
it('injects the selected Codex home into Orca terminal PTYs', async () => {
const env = await spawnAndGetEnv(undefined, undefined, () => '/tmp/orca-codex-home')
expect(env.CODEX_HOME).toBe('/tmp/orca-codex-home')

View File

@ -173,6 +173,11 @@ export class LocalPtyProvider implements IPtyProvider {
TERM: 'xterm-256color',
COLORTERM: 'truecolor',
TERM_PROGRAM: 'Orca',
// Why: TUIs feature-gate on TERM_PROGRAM_VERSION (Neovim's termcap
// autodetection, bat/delta paging hints). Sourced from ORCA_APP_VERSION
// which main/index.ts seeds from app.getVersion() at startup; the
// fallback keeps tests and non-Electron runs working.
TERM_PROGRAM_VERSION: process.env.ORCA_APP_VERSION ?? '0.0.0-dev',
FORCE_HYPERLINK: '1'
} as Record<string, string>