- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/server/src/push-snapshot.ts?format=json
35 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 177, 1 version changed it
1import type { FileModes } from "../../worker/project/project-api.ts";
3export interface PushSnapshotMetadata {
4 version: number;
5 paths: string[];
6 modes: FileModes;
7 blobs: Record<string, string>;
8 last?: { agent: string; message: string };
9}
11/** Construct outside the read scope so detaching metadata never evaluates file text. */
12export function pushSnapshot(
13 metadata: PushSnapshotMetadata,
14 readText: (version: number, path: string) => string,
15 readBatch?: (version: number, paths: readonly string[]) => Record<string, string>,
16) {
17 const { paths, ...shared } = metadata;
18 const files: Record<string, string> = Object.create(null);
19 let cache: Record<string, string> = Object.create(null);
20 for (let index = 0; index < paths.length; index++) {
21 const path = paths[index]!;
22 Object.defineProperty(files, path, {
23 enumerable: true,
24 get: () => {
25 if (!readBatch) return readText(shared.version, path);
26 if (!Object.hasOwn(cache, path)) cache = readBatch(shared.version, paths.slice(index, index + 64));
27 if (!Object.hasOwn(cache, path)) throw Error("push batch omitted requested file");
28 const text = cache[path]!;
29 delete cache[path];
30 return text;
31 },
32 });
33 }
34 return { ...shared, files };
35}