fix(linux): stop Orca terminals from launching the GNOME Orca screen reader via bare orca (#8347)

On Linux the CLI installs as orca-ide so it never shadows /usr/bin/orca
(GNOME's screen reader), but agent-facing surfaces (orca-cli skill,
dispatch preambles, CLI hints) all invoke bare `orca` — so on stock
Ubuntu an agent inside an Orca terminal launched the screen reader,
which started speaking (#7904).

Fix: prepend a userData-scoped shim dir (bare `orca` -> bundled
orca-ide launcher, or the stable AppImage) to the PATH of every
packaged-Linux managed PTY, mirroring the existing dev-mode cli/bin
prepend. The user's own shells — and their real screen reader command —
stay untouched. Also flip the orca-cli skill probe to prefer orca-ide
so agents outside Orca terminals never execute the screen reader.

Fixes #7904

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Neil
2026-07-12 00:38:35 -07:00
committed by GitHub
co-authored by Orca
parent 6ee81dcfb1
commit 42cf64cdc9
6 changed files with 250 additions and 7 deletions
+16 -5
View File
@@ -60,30 +60,41 @@ export async function installLinuxBareOrcaDispatcher(
return { state: 'installed', dispatcherPath, target: resolved.target }
}
function resolveDispatcherScript(
/** Bare-`orca` script that execs the Orca CLI: the stable AppImage when running
* from one, otherwise the bundled `orca-ide` launcher. Shared by the serve
* dispatcher and the managed-terminal PATH shim. */
export function buildBareOrcaCliScript(
resourcesPath: string,
appImagePath: string | null
): { script: string; target: string } | null {
if (appImagePath) {
// Why: an AppImage mounts resources under an ephemeral FUSE path per launch,
// so the dispatcher must exec the stable outer AppImage — reuse the same
// so the script must exec the stable outer AppImage — reuse the same
// wrapper CliInstaller installs for the AppImage command.
return { script: withMarker(buildAppImageCliWrapper(appImagePath)), target: appImagePath }
return { script: buildAppImageCliWrapper(appImagePath), target: appImagePath }
}
const launcher = getBundledLauncherPath('linux', resourcesPath)
// Why: getBundledLauncherPath only joins the path; guard existence so we never
// write a dispatcher pointing at a missing launcher (which would fail at exec
// write a script pointing at a missing launcher (which would fail at exec
// time with a confusing error instead of the command-not-found we fix).
if (!launcher || !existsSync(launcher)) {
return null
}
return {
script: `#!/usr/bin/env bash\n${DISPATCHER_MARKER}\nexec ${quoteShell(launcher)} "$@"\n`,
script: `#!/usr/bin/env bash\nexec ${quoteShell(launcher)} "$@"\n`,
target: launcher
}
}
function resolveDispatcherScript(
resourcesPath: string,
appImagePath: string | null
): { script: string; target: string } | null {
const resolved = buildBareOrcaCliScript(resourcesPath, appImagePath)
return resolved && { script: withMarker(resolved.script), target: resolved.target }
}
function withMarker(script: string): string {
const firstNewline = script.indexOf('\n')
if (firstNewline === -1) {
@@ -0,0 +1,118 @@
import { chmodSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
import { mkdtemp, rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it, vi } from 'vitest'
vi.mock('electron', () => ({
app: { isPackaged: true }
}))
import { ensureLinuxTerminalOrcaCliShimDir } from './linux-terminal-orca-cli-shim'
const created: string[] = []
async function makeFixture(): Promise<{ userDataPath: string; resourcesPath: string }> {
const root = await mkdtemp(join(tmpdir(), 'orca-terminal-cli-shim-'))
created.push(root)
const resourcesPath = join(root, 'resources')
// The bundled orca-ide launcher must exist for the shim to be written.
mkdirSync(join(resourcesPath, 'bin'), { recursive: true })
writeFileSync(join(resourcesPath, 'bin', 'orca-ide'), '#!/usr/bin/env bash\n', 'utf8')
return { userDataPath: join(root, 'user-data'), resourcesPath }
}
afterEach(async () => {
await Promise.all(created.splice(0).map((dir) => rm(dir, { recursive: true, force: true })))
})
describe('ensureLinuxTerminalOrcaCliShimDir', () => {
it('writes an executable bare-orca shim that execs the bundled orca-ide launcher', async () => {
const { userDataPath, resourcesPath } = await makeFixture()
const shimDir = ensureLinuxTerminalOrcaCliShimDir({
userDataPath,
resourcesPath,
appImagePath: null
})
expect(shimDir).toBe(join(userDataPath, 'linux-orca-cli-shim'))
const content = readFileSync(join(shimDir!, 'orca'), 'utf8')
// Single-quoted so a resources path with shell metacharacters can't break out.
expect(content).toContain(`exec '${join(resourcesPath, 'bin', 'orca-ide')}' "$@"`)
const mode = statSync(join(shimDir!, 'orca')).mode & 0o777
expect(mode & 0o111).not.toBe(0)
})
it('memoizes per userDataPath and re-asserts the exec bit for a stale shim', async () => {
const { userDataPath, resourcesPath } = await makeFixture()
const options = { userDataPath, resourcesPath, appImagePath: null }
const first = ensureLinuxTerminalOrcaCliShimDir(options)
expect(first).not.toBeNull()
const shimPath = join(first!, 'orca')
chmodSync(shimPath, 0o644)
// A distinct userData path is not memoized, so ensure runs again and heals
// the exec bit lost above only when it actually processes that path.
const second = ensureLinuxTerminalOrcaCliShimDir(options)
expect(second).toBe(first)
const root = await mkdtemp(join(tmpdir(), 'orca-terminal-cli-shim-2-'))
created.push(root)
const otherUserData = join(root, 'user-data')
mkdirSync(join(otherUserData, 'linux-orca-cli-shim'), { recursive: true })
writeFileSync(join(otherUserData, 'linux-orca-cli-shim', 'orca'), 'stale contents', 'utf8')
chmodSync(join(otherUserData, 'linux-orca-cli-shim', 'orca'), 0o644)
const healed = ensureLinuxTerminalOrcaCliShimDir({
userDataPath: otherUserData,
resourcesPath,
appImagePath: null
})
expect(healed).not.toBeNull()
const healedPath = join(healed!, 'orca')
expect(readFileSync(healedPath, 'utf8')).toContain('orca-ide')
expect(statSync(healedPath).mode & 0o111).not.toBe(0)
})
it('execs the stable AppImage (not the ephemeral mount) when running from an AppImage', async () => {
const { userDataPath, resourcesPath } = await makeFixture()
const appImagePath = join(userDataPath, 'Applications', 'Orca.AppImage')
const shimDir = ensureLinuxTerminalOrcaCliShimDir({
userDataPath,
resourcesPath,
appImagePath
})
const content = readFileSync(join(shimDir!, 'orca'), 'utf8')
expect(content).toContain(appImagePath)
expect(content).not.toContain(resourcesPath)
})
it('returns null (and does not memoize) when the bundled launcher is missing', async () => {
const root = await mkdtemp(join(tmpdir(), 'orca-terminal-cli-shim-missing-'))
created.push(root)
const userDataPath = join(root, 'user-data')
const missing = ensureLinuxTerminalOrcaCliShimDir({
userDataPath,
resourcesPath: join(root, 'resources'),
appImagePath: null
})
expect(missing).toBeNull()
// Once the launcher exists (e.g. later probe with real resources), the same
// userData path succeeds — proving failures are not cached.
const resourcesPath = join(root, 'resources')
mkdirSync(join(resourcesPath, 'bin'), { recursive: true })
writeFileSync(join(resourcesPath, 'bin', 'orca-ide'), '#!/usr/bin/env bash\n', 'utf8')
const recovered = ensureLinuxTerminalOrcaCliShimDir({
userDataPath,
resourcesPath,
appImagePath: null
})
expect(recovered).toBe(join(userDataPath, 'linux-orca-cli-shim'))
})
})
@@ -0,0 +1,70 @@
import { chmodSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'
import { buildBareOrcaCliScript } from './linux-bare-orca-dispatcher'
const SHIM_DIR_NAME = 'linux-orca-cli-shim'
// Why: rewriting the shim on every PTY spawn is wasted fs work; the target only
// changes with the install itself, so one successful write per process is enough.
// Failures are NOT cached so a transient fs error retries on the next spawn.
const ensuredShimDirs = new Map<string, string>()
export type LinuxTerminalOrcaCliShimOptions = {
userDataPath: string
/** Test seam — defaults to the packaged resources root. */
resourcesPath?: string | null
/** Test seam — defaults to $APPIMAGE (set only when running from an AppImage). */
appImagePath?: string | null
}
// Why: on Linux the CLI installs as `orca-ide` so it never shadows the GNOME
// Orca screen reader at /usr/bin/orca — but agent-facing surfaces (skills,
// dispatch preambles, CLI hints) all invoke bare `orca`, so on stock Ubuntu an
// agent inside an Orca terminal would launch the screen reader instead
// (stablyai/orca#7904). Prepending this userData-scoped shim dir to managed-PTY
// PATH makes bare `orca` resolve to the Orca CLI inside Orca terminals only,
// leaving the user's own shells (and their screen reader) untouched.
export function ensureLinuxTerminalOrcaCliShimDir(
options: LinuxTerminalOrcaCliShimOptions
): string | null {
const cached = ensuredShimDirs.get(options.userDataPath)
if (cached !== undefined) {
return cached
}
const resourcesPath = options.resourcesPath ?? process.resourcesPath
if (!resourcesPath) {
return null
}
const resolved = buildBareOrcaCliScript(
resourcesPath,
options.appImagePath ?? process.env.APPIMAGE ?? null
)
if (!resolved) {
return null
}
const shimDir = join(options.userDataPath, SHIM_DIR_NAME)
const shimPath = join(shimDir, 'orca')
try {
if (readShim(shimPath) !== resolved.script) {
mkdirSync(shimDir, { recursive: true })
writeFileSync(shimPath, resolved.script, 'utf8')
}
// Why: always re-assert the exec bit — a shim written by an older run (or
// restored from backup) with mode stripped would fail every agent CLI call.
chmodSync(shimPath, 0o755)
} catch {
return null
}
ensuredShimDirs.set(options.userDataPath, shimDir)
return shimDir
}
function readShim(shimPath: string): string | null {
try {
return readFileSync(shimPath, 'utf8')
} catch {
return null
}
}