mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
* [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>
54 lines
2.1 KiB
TypeScript
54 lines
2.1 KiB
TypeScript
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
|
||
}
|