Files
archived-orca/src/shared/files-runtime-capabilities.ts
T
Neil 6077bbaf7a Download a granted host file in pages instead of whole (#38693)
* fix(files): download a granted host file in pages instead of whole

A paired host serves a file outside every workspace only through its
terminal grant, whose read is whole-file, text-only and size-capped, so
Shift-click and "Download & open with default app" on such a file opened
it in Orca with "too large" or "binary" errors instead of downloading.
Hosts now page a granted file through files.readTerminalArtifactChunk,
behind a capability, and downloads stream through it like workspace files.

Refs #35968

* fix(files): pin a granted file's ctime so a large download can't mix versions

Files above the digest cap are pinned by stat alone, and utimes can put a
rewritten file's mtime back. ctime moves on every write and can't be reset,
so a same-size in-place rewrite now makes the grant stale.

Refs #35968

* fix(terminal): let a newer link click win over a granted download's host check

Refs #35968

* fix(terminal): drop a superseded granted download whatever the host answers

Refs #35968

* test(files): wait out a coarse ctime tick before rewriting a granted file

On filesystems that stamp ctime in coarse ticks, a rewrite right after the
grant could keep the granted ctime and make the stale-page test flaky. The
test now rewrites until the ctime moves. Also corrects a comment that said a
grant can't be downloaded.

Refs #35968

* style(files): format the granted chunk capability constant

Refs #35968
2026-11-05 16:35:12 -08:00

36 lines
1.6 KiB
TypeScript

import {
FILE_WRITE_DISK_PRECONDITION_RUNTIME_CAPABILITY,
FILE_WRITE_IDENTICAL_RUNTIME_CAPABILITY
} from './file-write-disk-precondition'
import { STAGED_FILE_SAVE_RUNTIME_CAPABILITY } from './staged-file-save'
import { FILE_REPLACE_WITH_UPLOAD_RUNTIME_CAPABILITY } from './file-bytes-write'
// Why: older runtimes strip mutation owner fields, so clients must fence writes before RPC.
export const FILE_MUTATION_OWNERSHIP_RUNTIME_CAPABILITY = 'files.mutation-ownership.v1' as const
export const FILE_MUTATION_OWNERSHIP_UPDATE_REQUIRED_MESSAGE =
'Remote file changes require a newer Orca server. Update the HUB and try again.'
// Why: older hosts drop `offset`/`limit` and answer with the whole folder.
export const FILE_READ_DIR_PAGED_RUNTIME_CAPABILITY = 'files.readDir.paged.v1' as const
export const FILE_DOC_PREVIEW_RUNTIME_CAPABILITY = 'files.readDocPreview' as const
// Why: older hosts read a granted file only whole and as text, so a download needs this method.
export const TERMINAL_ARTIFACT_CHUNK_RUNTIME_CAPABILITY =
'files.readTerminalArtifactChunk.v1' as const
export const FILES_RUNTIME_CAPABILITIES = [
'files.pathsExist',
'files.resolve-terminal-path.cross-workspace.v1',
'files.resolve-terminal-path.absolute-files.v1',
'files.resolve-terminal-path.in-place-files.v1',
FILE_DOC_PREVIEW_RUNTIME_CAPABILITY,
FILE_READ_DIR_PAGED_RUNTIME_CAPABILITY,
FILE_WRITE_DISK_PRECONDITION_RUNTIME_CAPABILITY,
FILE_WRITE_IDENTICAL_RUNTIME_CAPABILITY,
FILE_MUTATION_OWNERSHIP_RUNTIME_CAPABILITY,
STAGED_FILE_SAVE_RUNTIME_CAPABILITY,
FILE_REPLACE_WITH_UPLOAD_RUNTIME_CAPABILITY,
TERMINAL_ARTIFACT_CHUNK_RUNTIME_CAPABILITY
] as const