mirror of
https://github.com/stablyai/orca.git
synced 2026-11-04 02:57:36 +00:00
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import {
|
|
toRuntimeExecutionHostId,
|
|
toSshExecutionHostId,
|
|
type ExecutionHostId
|
|
} from './execution-host'
|
|
import { parseRemoteRuntimePtyId, isRemoteRuntimePtyId } 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:') || isRemoteRuntimePtyId(ptyId)) {
|
|
return 'foreign'
|
|
}
|
|
return null
|
|
}
|