Files
orca/src/main/ipc/shell-editor-ssh-host.ts
T
OrcaWinandOrcaWin 3286f3b259 [comment audit] Clean up IPC, host lifecycle and native-chat comments (#32966)
* [comment audit] Tighten watcher lifetime and file-write constraints [skip ci]

* [comment audit] Clarify IPC routing and notification comments [skip ci]

* [comment audit] Shorten watcher, preflight and PTY comments [skip ci]

* [comment audit] Clarify PTY delivery and restore ownership [skip ci]

* [comment audit] Tighten PTY environment and flow-control rationale [skip ci]

* [comment audit] Clarify IPC spawn and stable-pane guarantees [skip ci]

* [comment audit] Tighten PTY provider and filesystem ownership rationale [skip ci]

* [comment audit] Clarify clone ownership and remote runtime recovery [skip ci]

* [comment audit] Condense upload, settings and SSH lifecycle comments [skip ci]

* [comment audit] Shorten shutdown, preview and worktree watcher rationale [skip ci]

* [comment audit] Clarify worktree identity, remote ownership and copy limits [skip ci]

* [comment audit] Shorten worktree catalog, removal and WSL routing rationale [skip ci]

* [comment audit] Tighten Linear credential, pagination and export comments [skip ci]

* [comment audit] Condense managed-server activation, snapshot and launch rationale [skip ci]

* [comment audit] Trim runtime installation and managed-server lifecycle comments [skip ci]

* [comment audit] Simplify managed tunnel, memory and menu comments [skip ci]

* [comment audit] Condense integration, model catalog and attachment rationale [skip ci]

* [comment audit] Shorten journal persistence, replay and queue rationale [skip ci]

* [comment audit] Condense journal ordering and timeline lifecycle comments [skip ci]

* [comment audit] Trim timeline and subscriber delivery explanations [skip ci]

* [comment audit] Shorten Stop, child-exit and recovery contracts [skip ci]

* [comment audit] Simplify handover and host recovery comments [skip ci]

* [comment audit] Trim queue delivery and provider startup commentary [skip ci]

* [comment audit] Clarify restart and rewind safety comments [skip ci]

* [comment audit] Trim status, Stop and completion commentary [skip ci]

* [comment audit] Simplify transcript lookup and visual containment comments [skip ci]

* [comment audit] Trim transcript reader, watcher and WSL transport commentary [skip ci]

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-10-23 19:07:32 -07:00

59 lines
2.3 KiB
TypeScript

import { getAppEnvironment } from '../../shared/app-environment'
import { parseExecutionHostId, toSshExecutionHostId } from '../../shared/execution-host'
import { getManagedOrcadFenceEnvironmentId } from '../../shared/managed-orcad-ssh-owner'
import { listEnvironments } from '../../shared/runtime-environment-store'
import {
getOrcadSshDeployment,
getRuntimeSshAccess,
type KnownRuntimeEnvironment
} from '../../shared/runtime-environments'
import type { SshTarget } from '../../shared/ssh-types'
import { fingerprintRuntimeSshTarget } from '../ssh/runtime-ssh-target-fingerprint'
export type ListRuntimeEnvironments = () => readonly Pick<
KnownRuntimeEnvironment,
'id' | 'orcadDeployment' | 'sshAccess'
>[]
export const listAppRuntimeEnvironments: ListRuntimeEnvironments = () =>
listEnvironments(getAppEnvironment().getPath('userData'))
/** Whether `target` is the SSH host that owns the path: that host, or the one its server runs on. */
export function isEditorSshHostForOwner(
target: SshTarget,
ownerHostId: unknown,
listRuntimeEnvironments: ListRuntimeEnvironments
): boolean {
if (ownerHostId === toSshExecutionHostId(target.id)) {
return true
}
const owner = typeof ownerHostId === 'string' ? parseExecutionHostId(ownerHostId) : null
if (owner?.kind !== 'runtime') {
return false
}
let environments: ReturnType<ListRuntimeEnvironments>
try {
environments = listRuntimeEnvironments()
} catch {
return false
}
// Re-derive ownership in main so renderer claims cannot redirect editing to another host.
const environment = environments.find((entry) => entry.id === owner.environmentId)
const link = environment ? getRuntimeSshAccess(environment) : undefined
if (!environment || link?.sshTargetId !== target.id) {
return false
}
// A stale link can name a different host that reused the registration ID.
if (target.generation !== link.sshTargetGeneration) {
return false
}
if (getOrcadSshDeployment(environment)) {
return getManagedOrcadFenceEnvironmentId(target) === environment.id
}
// Edits retain generation, so also pin the settings used to verify SSH access.
const access = environment.sshAccess
return (
!!access?.targetFingerprint && fingerprintRuntimeSshTarget(target) === access.targetFingerprint
)
}