Files
orca/src/main/native-chat/transcript-file-version.ts
T
Jinwoo Hong b1e09a4c8e fix(native-chat): show an SSH session's chat history on the phone and desktop (#26334)
Fixes #26057. The hook reports the SSH host's transcript path, but native chat read it on the desktop's own disk, so SSH sessions showed an empty chat. The desktop now reads the transcript on the SSH host through its existing SSH filesystem provider, routed by the path layer that already handles WSL. A local row attesting the requested path keeps the session local; a transcript not yet written keeps the chat waiting. Desktop-only, no wire change.
2026-10-07 19:33:35 -04:00

58 lines
1.7 KiB
TypeScript

import { readTranscriptSlice, transcriptFileStat } from './wsl-transcript-fs-access'
const BOUNDARY_FINGERPRINT_BYTES = 64
export function extendTranscriptBoundary(previous: Buffer, chunk: Buffer): Buffer {
const chunkBytes = Math.min(chunk.length, BOUNDARY_FINGERPRINT_BYTES)
const previousBytes = Math.min(previous.length, BOUNDARY_FINGERPRINT_BYTES - chunkBytes)
const boundary = Buffer.allocUnsafeSlow(previousBytes + chunkBytes)
previous.copy(boundary, 0, previous.length - previousBytes)
chunk.copy(boundary, previousBytes, chunk.length - chunkBytes)
return boundary
}
export type TranscriptFileVersion = {
identity: string
size: number
mtimeMs: number
ctimeMs: number
}
export async function readTranscriptFileVersion(
filePath: string,
signal?: AbortSignal
): Promise<TranscriptFileVersion> {
const value = await transcriptFileStat(filePath, 'exact', signal)
return {
identity: `${value.dev}:${value.ino}`,
size: value.size,
mtimeMs: value.mtimeMs,
ctimeMs: value.ctimeMs
}
}
export async function boundaryFingerprint(
filePath: string,
offset: number,
signal?: AbortSignal
): Promise<string> {
if (offset <= 0) {
return ''
}
const start = Math.max(0, offset - BOUNDARY_FINGERPRINT_BYTES)
const slice = await readTranscriptSlice(filePath, start, offset - start, 'exact', signal)
return slice.toString('base64')
}
export function transcriptFileVersionChanged(
current: TranscriptFileVersion,
previous: TranscriptFileVersion
): boolean {
return (
current.identity !== previous.identity ||
current.size !== previous.size ||
current.mtimeMs !== previous.mtimeMs ||
current.ctimeMs !== previous.ctimeMs
)
}