Files
orca/src/shared/terminal-execution-host.ts
T
Brennan Benson 8ca4ed945e feat(terminal): report execution host and listing scope in terminal list (#14973)
* feat(terminal): report execution host and listing scope in terminal list

`orca terminal list` returned rows with no host identity and no statement
of what the listing covered, so a scoped listing that saw nothing read as
"nothing exists anywhere" — an agent reported a live remote worker dead.

Each row now carries an optional `executionHostId` derived from the PTY id
(SSH and paired-runtime ids embed their owner), and the result carries an
optional `hostScope` naming the hosts covered and the known hosts skipped.
Both are surfaced in `--json` and in the human-readable CLI output, where
an absent field renders as `unknown` rather than `local`.

Both row builders route through one resolver, so the rule lives in one place.

* fix(terminal): preserve unverifiable host scope

* fix(terminal): fail closed on unverifiable hosts

* test(terminal): name unverifiable scope explicitly

* perf(terminal): keep graph hydration host scans narrow

* fix(terminal): reject blank foreign host owners

* fix(terminal): validate inferred inventory hosts

* fix(terminal): preserve paired folder host scope

* fix(terminal): keep inventory host inference typed

* fix(terminal): disclose paired folder hosts
2026-08-16 22:13:03 -07:00

38 lines
1.3 KiB
TypeScript

import {
toRuntimeExecutionHostId,
toSshExecutionHostId,
type ExecutionHostId
} from './execution-host'
import { parseRemoteRuntimePtyId } from './remote-runtime-pty-id'
import { parseAppSshPtyId } from './ssh-pty-id'
/** 'foreign' = the id proves the PTY runs off this host but cannot name where. */
export type PtyExecutionHost = ExecutionHostId | 'foreign' | null
// Why: a PTY id, not a path, is the authority on where a terminal runs — SSH and
// paired-runtime ids embed their owner. `null` means the id carries no host at
// all, so the caller may fall back to the worktree's host.
export function getPtyExecutionHost(ptyId: string | null | undefined): PtyExecutionHost {
if (!ptyId) {
return null
}
const ssh = parseAppSshPtyId(ptyId)
if (ssh) {
const connectionId = ssh.connectionId.trim()
return connectionId && connectionId === ssh.connectionId
? toSshExecutionHostId(connectionId)
: 'foreign'
}
const remote = parseRemoteRuntimePtyId(ptyId)
if (remote) {
const environmentId = remote.environmentId?.trim()
return environmentId && environmentId === remote.environmentId
? toRuntimeExecutionHostId(environmentId)
: 'foreign'
}
if (ptyId.startsWith('ssh:') || ptyId.startsWith('remote:')) {
return 'foreign'
}
return null
}