Resolve stored blob references when reading agent files

This commit is contained in:
2026-10-08 00:09:53 -04:00
parent 592e829fec
commit 6a897df716
2 changed files with 45 additions and 2 deletions
+7 -2
View File
@@ -3,6 +3,7 @@ import { join, posix, relative, resolve, sep } from 'node:path';
import { config } from '../config.js';
import { nativeInstance, nativeRequest } from './native.js';
import { getHost } from '../hosts/index.js';
import { getFileBlob } from '../db/file-blobs.js';
function remote(path: string) {
for (const root of [config.serversRoot, config.t6ServersRoot]) {
@@ -49,8 +50,12 @@ export async function nativeFileManifest(root: string, directories: string[], ig
export async function readFile(path: string): Promise<Buffer> {
const target = remote(path);
if (!target) return fs.readFile(path);
const result = await nativeRequest<{ contentBase64: string | null }>(target.instance, 'files.read', { path: target.path });
return result.contentBase64 === null ? missing(path) : Buffer.from(result.contentBase64, 'base64');
const result = await nativeRequest<{ contentSha256?: string; contentBase64?: string | null } | null>(target.instance, 'files.read', { path: target.path });
// Stored receipts reference shared bytes; read them directly without a base64 round trip.
if (typeof result?.contentSha256 === 'string') return getFileBlob(result.contentSha256);
if (result?.contentBase64 === null) return missing(path);
if (typeof result?.contentBase64 === 'string') return Buffer.from(result.contentBase64, 'base64');
throw new Error(`Agent returned an invalid response for files.read: ${target.path}`);
}
export async function exists(path: string): Promise<boolean> {