Files
orca/src/main/native-chat/ssh-transcript-path.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

54 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { AgentStatusIpcPayload } from '../../shared/agent-status-types'
import { isWslHookRelayConnectionId } from '../../shared/wsl-hook-relay-contract'
// Encode connection and file in the engine’s single path string so local files cannot answer remote reads.
const SSH_TRANSCRIPT_PATH_PREFIX = 'orca-ssh-transcript:'
export type SshTranscriptLocation = { connectionId: string; remotePath: string }
export function toSshTranscriptPath(connectionId: string, remotePath: string): string {
return `${SSH_TRANSCRIPT_PATH_PREFIX}${encodeURIComponent(connectionId)}:${remotePath}`
}
export function parseSshTranscriptPath(path: string): SshTranscriptLocation | null {
if (!path.startsWith(SSH_TRANSCRIPT_PATH_PREFIX)) {
return null
}
const rest = path.slice(SSH_TRANSCRIPT_PATH_PREFIX.length)
const separator = rest.indexOf(':')
if (separator <= 0) {
return null
}
return {
connectionId: decodeURIComponent(rest.slice(0, separator)),
remotePath: rest.slice(separator + 1)
}
}
type HookRow = Pick<AgentStatusIpcPayload, 'connectionId' | 'providerSession'>
export function nativeChatTranscriptPathOnExecutionHost(
statusRows: readonly HookRow[],
sessionId: string,
transcriptPath: string | undefined
): string | undefined {
// Only host hook evidence may mint remote paths; client-provided forms cannot attest files.
const requested =
transcriptPath && !parseSshTranscriptPath(transcriptPath) ? transcriptPath : undefined
const rows = statusRows.filter(
(row) => row.providerSession?.id === sessionId && row.providerSession.transcriptPath
)
// Exact path attestation chooses the host; stale paths fall back to SSH.
const row =
rows.find((candidate) => candidate.providerSession?.transcriptPath === requested) ??
rows.find(isSshRow)
const remotePath = row?.providerSession?.transcriptPath
return row && isSshRow(row) && remotePath
? toSshTranscriptPath(row.connectionId, remotePath)
: requested
}
function isSshRow(row: HookRow): row is HookRow & { connectionId: string } {
return row.connectionId ? !isWslHookRelayConnectionId(row.connectionId) : false
}