{"file":"server/src/push.ts","version":318,"total":305,"from":1,"to":305,"lines":[{"n":1,"text":"// Out to Artifacts (#8): shared's files as one git commit on main of the","atom":"a1447","author":"speed","version":150},{"n":2,"text":"// project's repo, with the publish message and the agent as author. The repo","atom":"a1447","author":"speed","version":150},{"n":3,"text":"// is created on first use. isomorphic-git works in an in-memory filesystem:","atom":"a1447","author":"speed","version":150},{"n":4,"text":"// a depth-1 clone of main with nothing checked out, then a new tree from","atom":"a1447","author":"speed","version":150},{"n":5,"text":"// shared's files that compresses and writes only what changed (abso issue 293).","atom":"a1447","author":"speed","version":150},{"n":6,"text":"import { createHash } from \"node:crypto\";","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":7,"text":"import git from \"isomorphic-git\";","atom":"a1447","author":"speed","version":150},{"n":8,"text":"import http from \"isomorphic-git/http/web\";","atom":"a1447","author":"speed","version":150},{"n":9,"text":"import type { FileModes } from \"../../worker/project/project-api.ts\";","atom":"a1447","author":"speed","version":150},{"n":10,"text":"import type { SqliteStorage } from \"./engine-project.ts\";","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":11,"text":"import { GitDiskIntake } from \"./git-disk-intake.ts\";","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":12,"text":"import { GitFileContents } from \"./git-file-contents.ts\";","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":13,"text":"import { gitHttp } from \"./git-http.ts\";","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":14,"text":"import { MemoryFS } from \"./memory-fs.ts\";","atom":"a1447","author":"speed","version":150},{"n":15,"text":"","atom":"a1447","author":"speed","version":150},{"n":16,"text":"export interface PushResult {","atom":"a1447","author":"speed","version":150},{"n":17,"text":"\trepo: string;","atom":"a1447","author":"speed","version":150},{"n":18,"text":"\tremote: string;","atom":"a1447","author":"speed","version":150},{"n":19,"text":"\tcommit: string;","atom":"a1447","author":"speed","version":150},{"n":20,"text":"\tversion: number;","atom":"a1447","author":"speed","version":150},{"n":21,"text":"\tms: number;","atom":"a1447","author":"speed","version":150},{"n":22,"text":"}","atom":"a1447","author":"speed","version":150},{"n":23,"text":"","atom":"a1447","author":"speed","version":150},{"n":24,"text":"/** New blob bytes per push before the push out splits into parts: Artifacts refuses a push much over 20 MB. */","atom":"a1447","author":"speed","version":150},{"n":25,"text":"const PUSH_BATCH = 16 * 1024 * 1024;","atom":"a1447","author":"speed","version":150},{"n":26,"text":"","atom":"a1447","author":"speed","version":150},{"n":27,"text":"/** A file as a tree entry holds it: its blob and its mode (\"100644\", \"100755\", \"120000\"). */","atom":"a1447","author":"speed","version":150},{"n":28,"text":"export interface TreeFile {","atom":"a1447","author":"speed","version":150},{"n":29,"text":"\toid: string;","atom":"a1447","author":"speed","version":150},{"n":30,"text":"\tmode: string;","atom":"a1447","author":"speed","version":150},{"n":31,"text":"}","atom":"a1447","author":"speed","version":150},{"n":32,"text":"","atom":"a1447","author":"speed","version":150},{"n":33,"text":"/** Every file in a tree, and every folder's tree oid (\"\" is the root), read from tree objects only. */","atom":"a1447","author":"speed","version":150},{"n":34,"text":"export async function readTreeFiles(","atom":"a1447","author":"speed","version":150},{"n":35,"text":"\tfs: MemoryFS,","atom":"a1447","author":"speed","version":150},{"n":36,"text":"\tdir: string,","atom":"a1447","author":"speed","version":150},{"n":37,"text":"\toid: string,","atom":"a1447","author":"speed","version":150},{"n":38,"text":"\tprefix = \"\",","atom":"a1447","author":"speed","version":150},{"n":39,"text":"\tfiles = new Map<string, TreeFile>(),","atom":"a1447","author":"speed","version":150},{"n":40,"text":"\ttrees = new Map<string, string>(),","atom":"a1447","author":"speed","version":150},{"n":41,"text":"\tcache?: object,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":42,"text":"): Promise<{ files: Map<string, TreeFile>; trees: Map<string, string> }> {","atom":"a1447","author":"speed","version":150},{"n":43,"text":"\ttrees.set(prefix, oid);","atom":"a1447","author":"speed","version":150},{"n":44,"text":"\tconst { tree } = await git.readTree({ fs, dir, oid, cache });","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":45,"text":"\tfor (const e of tree) {","atom":"a1447","author":"speed","version":150},{"n":46,"text":"\t\tconst path = prefix === \"\" ? e.path : `${prefix}/${e.path}`;","atom":"a1447","author":"speed","version":150},{"n":47,"text":"\t\tif (e.type === \"tree\") await readTreeFiles(fs, dir, e.oid, path, files, trees, cache);","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":48,"text":"\t\telse if (e.type === \"blob\") files.set(path, { oid: e.oid, mode: e.mode });","atom":"a1447","author":"speed","version":150},{"n":49,"text":"\t}","atom":"a1447","author":"speed","version":150},{"n":50,"text":"\treturn { files, trees };","atom":"a1447","author":"speed","version":150},{"n":51,"text":"}","atom":"a1447","author":"speed","version":150},{"n":52,"text":"","atom":"a1447","author":"speed","version":150},{"n":53,"text":"/**","atom":"a1447","author":"speed","version":150},{"n":54,"text":" * Hash the Git header and content separately so export does not allocate a second whole-file buffer.","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":55,"text":" */","atom":"a1447","author":"speed","version":150},{"n":56,"text":"export async function blobOid(bytes: Uint8Array): Promise<string> {","atom":"a1447","author":"speed","version":150},{"n":57,"text":"\treturn createHash(\"sha1\").update(`blob ${bytes.byteLength}\\0`).update(bytes).digest(\"hex\");","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":58,"text":"}","atom":"a1447","author":"speed","version":150},{"n":59,"text":"","atom":"a1447","author":"speed","version":150},{"n":60,"text":"const parentOf = (path: string) => {","atom":"a1447","author":"speed","version":150},{"n":61,"text":"\tconst cut = path.lastIndexOf(\"/\");","atom":"a1447","author":"speed","version":150},{"n":62,"text":"\treturn cut < 0 ? \"\" : path.slice(0, cut);","atom":"a1447","author":"speed","version":150},{"n":63,"text":"};","atom":"a1447","author":"speed","version":150},{"n":64,"text":"","atom":"a1447","author":"speed","version":150},{"n":65,"text":"/**","atom":"a1447","author":"speed","version":150},{"n":66,"text":" * The tree for `files`, written bottom up. A folder with nothing changed under it keeps its old tree oid (`before`),","atom":"a1447","author":"speed","version":150},{"n":67,"text":" * so only the folders on a changed path are written again.","atom":"a1447","author":"speed","version":150},{"n":68,"text":" */","atom":"a1447","author":"speed","version":150},{"n":69,"text":"export async function writeTrees(","atom":"a1447","author":"speed","version":150},{"n":70,"text":"\tfs: MemoryFS,","atom":"a1447","author":"speed","version":150},{"n":71,"text":"\tdir: string,","atom":"a1447","author":"speed","version":150},{"n":72,"text":"\tfiles: Map<string, TreeFile>,","atom":"a1447","author":"speed","version":150},{"n":73,"text":"\tbefore: Map<string, string>,","atom":"a1447","author":"speed","version":150},{"n":74,"text":"\tchanged: Set<string>,","atom":"a1447","author":"speed","version":150},{"n":75,"text":"): Promise<string> {","atom":"a1447","author":"speed","version":150},{"n":76,"text":"\tconst dirty = new Set<string>([\"\"]);","atom":"a1447","author":"speed","version":150},{"n":77,"text":"\tfor (const path of changed) for (let d = parentOf(path); d !== \"\"; d = parentOf(d)) dirty.add(d);","atom":"a1447","author":"speed","version":150},{"n":78,"text":"\ttype Entry = { mode: string; oid: string; type: \"blob\" | \"tree\" };","atom":"a1447","author":"speed","version":150},{"n":79,"text":"\tconst kids = new Map<string, Map<string, Entry>>([[\"\", new Map()]]);","atom":"a1447","author":"speed","version":150},{"n":80,"text":"\tconst folder = (d: string) => {","atom":"a1447","author":"speed","version":150},{"n":81,"text":"\t\tlet k = kids.get(d);","atom":"a1447","author":"speed","version":150},{"n":82,"text":"\t\tif (!k) {","atom":"a1447","author":"speed","version":150},{"n":83,"text":"\t\t\tkids.set(d, (k = new Map()));","atom":"a1447","author":"speed","version":150},{"n":84,"text":"\t\t\tif (d !== \"\") folder(parentOf(d));","atom":"a1447","author":"speed","version":150},{"n":85,"text":"\t\t}","atom":"a1447","author":"speed","version":150},{"n":86,"text":"\t\treturn k;","atom":"a1447","author":"speed","version":150},{"n":87,"text":"\t};","atom":"a1447","author":"speed","version":150},{"n":88,"text":"\tfor (const [path, f] of files)","atom":"a1447","author":"speed","version":150},{"n":89,"text":"\t\tfolder(parentOf(path)).set(path.slice(path.lastIndexOf(\"/\") + 1), { ...f, type: \"blob\" });","atom":"a1447","author":"speed","version":150},{"n":90,"text":"\t// Deepest first, so a folder's subfolders have their oids before it is written.","atom":"a1447","author":"speed","version":150},{"n":91,"text":"\tconst depth = (d: string) => (d === \"\" ? 0 : d.split(\"/\").length);","atom":"a1447","author":"speed","version":150},{"n":92,"text":"\tconst order = [...kids.keys()].sort((a, b) => depth(b) - depth(a));","atom":"a1447","author":"speed","version":150},{"n":93,"text":"\tlet root = \"\";","atom":"a1447","author":"speed","version":150},{"n":94,"text":"\tfor (const d of order) {","atom":"a1447","author":"speed","version":150},{"n":95,"text":"\t\tconst old = before.get(d);","atom":"a1447","author":"speed","version":150},{"n":96,"text":"\t\tconst oid =","atom":"a1447","author":"speed","version":150},{"n":97,"text":"\t\t\told !== undefined && !dirty.has(d)","atom":"a1447","author":"speed","version":150},{"n":98,"text":"\t\t\t\t? old","atom":"a1447","author":"speed","version":150},{"n":99,"text":"\t\t\t\t: await git.writeTree({ fs, dir, tree: [...kids.get(d)!].map(([path, e]) => ({ path, ...e })) });","atom":"a1447","author":"speed","version":150},{"n":100,"text":"\t\tif (d === \"\") root = oid;","atom":"a1447","author":"speed","version":150},{"n":101,"text":"\t\telse folder(parentOf(d)).set(d.slice(d.lastIndexOf(\"/\") + 1), { mode: \"040000\", oid, type: \"tree\" });","atom":"a1447","author":"speed","version":150},{"n":102,"text":"\t}","atom":"a1447","author":"speed","version":150},{"n":103,"text":"\treturn root;","atom":"a1447","author":"speed","version":150},{"n":104,"text":"}","atom":"a1447","author":"speed","version":150},{"n":105,"text":"","atom":"a1447","author":"speed","version":150},{"n":106,"text":"/**","atom":"a1447","author":"speed","version":150},{"n":107,"text":" * A project's Artifacts repo: abso-<project>. Project names are letters, digits, \".\", \"_\" and \"-\" (validName), which","atom":"a1447","author":"speed","version":150},{"n":108,"text":" * repo names take as they are.","atom":"a1447","author":"speed","version":150},{"n":109,"text":" */","atom":"a1447","author":"speed","version":150},{"n":110,"text":"export function repoName(project: string): string {","atom":"a1447","author":"speed","version":150},{"n":111,"text":"\treturn `abso-${project}`;","atom":"a1447","author":"speed","version":150},{"n":112,"text":"}","atom":"a1447","author":"speed","version":150},{"n":113,"text":"","atom":"a1447","author":"speed","version":150},{"n":114,"text":"/** The project one of our repos holds, or null for a repo that isn't ours. */","atom":"a1447","author":"speed","version":150},{"n":115,"text":"export function projectOfRepo(repo: string): string | null {","atom":"a1447","author":"speed","version":150},{"n":116,"text":"\treturn repo.startsWith(\"abso-\") && repo.length > \"abso-\".length ? repo.slice(\"abso-\".length) : null;","atom":"a1447","author":"speed","version":150},{"n":117,"text":"}","atom":"a1447","author":"speed","version":150},{"n":118,"text":"","atom":"a1447","author":"speed","version":150},{"n":119,"text":"/** The repo's remote and a write token good for `seconds`, creating the repo if it's new. */","atom":"a1447","author":"speed","version":150},{"n":120,"text":"export async function writeAccess(","atom":"a1447","author":"speed","version":150},{"n":121,"text":"\tartifacts: Artifacts,","atom":"a1447","author":"speed","version":150},{"n":122,"text":"\tname: string,","atom":"a1447","author":"speed","version":150},{"n":123,"text":"\tseconds = 600,","atom":"a1447","author":"speed","version":150},{"n":124,"text":"): Promise<{ remote: string; secret: string }> {","atom":"a1447","author":"speed","version":150},{"n":125,"text":"\ttry {","atom":"a1447","author":"speed","version":150},{"n":126,"text":"\t\tusing repo = await artifacts.get(name);","atom":"a1447","author":"speed","version":150},{"n":127,"text":"\t\tconst [info, token] = await Promise.all([repo.info(), repo.createToken(\"write\", seconds)]);","atom":"a1447","author":"speed","version":150},{"n":128,"text":"\t\treturn { remote: info!.remote, secret: token.plaintext.split(\"?expires=\")[0]! };","atom":"a1447","author":"speed","version":150},{"n":129,"text":"\t} catch {","atom":"a1447","author":"speed","version":150},{"n":130,"text":"\t\tconst created = await artifacts.create(name, { description: `abso project ${name}`, setDefaultBranch: \"main\" });","atom":"a1447","author":"speed","version":150},{"n":131,"text":"\t\treturn { remote: created.remote, secret: created.token.split(\"?expires=\")[0]! };","atom":"a1447","author":"speed","version":150},{"n":132,"text":"\t}","atom":"a1447","author":"speed","version":150},{"n":133,"text":"}","atom":"a1447","author":"speed","version":150},{"n":134,"text":"","atom":"a1447","author":"speed","version":150},{"n":135,"text":"export interface SharedFiles {","atom":"a1447","author":"speed","version":150},{"n":136,"text":"\tversion: number;","atom":"a1447","author":"speed","version":150},{"n":137,"text":"\tfiles: Record<string, string>;","atom":"a1447","author":"speed","version":150},{"n":138,"text":"\tmodes?: FileModes;","atom":"a1447","author":"speed","version":150},{"n":139,"text":"\tblobs?: Record<string, string>;","atom":"a1447","author":"speed","version":150},{"n":140,"text":"\tlast?: { agent: string; message: string };","atom":"a1447","author":"speed","version":150},{"n":141,"text":"}","atom":"a1447","author":"speed","version":150},{"n":142,"text":"","atom":"a1447","author":"speed","version":150},{"n":143,"text":"/**","atom":"a1447","author":"speed","version":150},{"n":144,"text":" * Shared's files as commits on top of `head` (null: a repo with no main yet), in the repo at `dir`. `part` is called","atom":"a1447","author":"speed","version":150},{"n":145,"text":" * with each earlier part's commit when the new blobs are too big for one push. Answers the last commit and how many","atom":"a1447","author":"speed","version":150},{"n":146,"text":" * paths changed.","atom":"a1447","author":"speed","version":150},{"n":147,"text":" */","atom":"a1447","author":"speed","version":150},{"n":148,"text":"export async function commitShared(","atom":"a1447","author":"speed","version":150},{"n":149,"text":"\tfs: MemoryFS,","atom":"a1447","author":"speed","version":150},{"n":150,"text":"\tdir: string,","atom":"a1447","author":"speed","version":150},{"n":151,"text":"\thead: string | null,","atom":"a1447","author":"speed","version":150},{"n":152,"text":"\tshared: SharedFiles,","atom":"a1447","author":"speed","version":150},{"n":153,"text":"\treadBlob: (sha256: string) => Uint8Array | null,","atom":"a1447","author":"speed","version":150},{"n":154,"text":"\tpart: (commit: string) => Promise<void> = async () => {},","atom":"a1447","author":"speed","version":150},{"n":155,"text":"\tcache?: object,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":156,"text":"): Promise<{ commit: string; changed: number }> {","atom":"a1447","author":"speed","version":150},{"n":157,"text":"\tconst old = head","atom":"a1447","author":"speed","version":150},{"n":158,"text":"\t\t? await readTreeFiles(","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":159,"text":"\t\t\t\tfs,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":160,"text":"\t\t\t\tdir,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":161,"text":"\t\t\t\t(await git.readCommit({ fs, dir, oid: head, cache })).commit.tree,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":162,"text":"\t\t\t\t\"\",","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":163,"text":"\t\t\t\tnew Map(),","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":164,"text":"\t\t\t\tnew Map(),","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":165,"text":"\t\t\t\tcache,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":166,"text":"\t\t\t)","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":167,"text":"\t\t: { files: new Map<string, TreeFile>(), trees: new Map<string, string>() };","atom":"a1447","author":"speed","version":150},{"n":168,"text":"\tconst blobs = shared.blobs ?? {};","atom":"a1447","author":"speed","version":150},{"n":169,"text":"\tconst now = new Map<string, TreeFile>();","atom":"a1447","author":"speed","version":150},{"n":170,"text":"\tconst changed = new Set<string>();","atom":"a1447","author":"speed","version":150},{"n":171,"text":"\tfor (const path of old.files.keys()) if (!(path in shared.files) && !(path in blobs)) changed.add(path);","atom":"a1447","author":"speed","version":150},{"n":172,"text":"\t// A file whose blob and mode match the last push keeps its entry; only a new blob is compressed and written.","atom":"a1447","author":"speed","version":150},{"n":173,"text":"\tconst put = async (path: string, bytes: Uint8Array, mode: string, oid: string) => {","atom":"a1447","author":"speed","version":150},{"n":174,"text":"\t\tconst was = old.files.get(path);","atom":"a1447","author":"speed","version":150},{"n":175,"text":"\t\tif (was?.oid !== oid) await git.writeBlob({ fs, dir, blob: bytes });","atom":"a1447","author":"speed","version":150},{"n":176,"text":"\t\tif (was?.oid !== oid || was.mode !== mode) changed.add(path);","atom":"a1447","author":"speed","version":150},{"n":177,"text":"\t\tnow.set(path, { oid, mode });","atom":"a1447","author":"speed","version":150},{"n":178,"text":"\t};","atom":"a1447","author":"speed","version":150},{"n":179,"text":"\t// Each file goes into the tree as a blob with its mode (#27): 100755 for exec, 120000 for a link, whose blob is","atom":"a1447","author":"speed","version":150},{"n":180,"text":"\t// its target.","atom":"a1447","author":"speed","version":150},{"n":181,"text":"\tconst enc = new TextEncoder();","atom":"a1447","author":"speed","version":150},{"n":182,"text":"\tconst agent = shared.last?.agent ?? \"abso\";","atom":"a1447","author":"speed","version":150},{"n":183,"text":"\tconst author = { name: agent, email: `${agent}@abso.invalid` };","atom":"a1447","author":"speed","version":150},{"n":184,"text":"\tconst committer = { name: \"abso\", email: \"abso@abso.invalid\" };","atom":"a1447","author":"speed","version":150},{"n":185,"text":"\tconst say = (p: string) => `${shared.last?.message ?? \"Start the project\"}${p}\\n\\nabso-version: ${shared.version}\\n`;","atom":"a1447","author":"speed","version":150},{"n":186,"text":"\tlet parent = head;","atom":"a1447","author":"speed","version":150},{"n":187,"text":"\t// A part holds what's written so far and preserves old entries for files not reached yet.","atom":"a2027","author":"codex-capacity-chair","version":181},{"n":188,"text":"\tconst commitNow = async (message: string) => {","atom":"a1447","author":"speed","version":150},{"n":189,"text":"\t\tconst files = new Map(now);","atom":"a1447","author":"speed","version":150},{"n":190,"text":"\t\tfor (const [path, f] of old.files)","atom":"a2027","author":"codex-capacity-chair","version":181},{"n":191,"text":"\t\t\tif (!files.has(path) && (path in blobs || path in shared.files)) files.set(path, f);","atom":"a2027","author":"codex-capacity-chair","version":181},{"n":192,"text":"\t\tconst tree = await writeTrees(fs, dir, files, old.trees, changed);","atom":"a1447","author":"speed","version":150},{"n":193,"text":"\t\tparent = await git.commit({","atom":"a1447","author":"speed","version":150},{"n":194,"text":"\t\t\tcache,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":195,"text":"\t\t\tfs,","atom":"a1447","author":"speed","version":150},{"n":196,"text":"\t\t\tdir,","atom":"a1447","author":"speed","version":150},{"n":197,"text":"\t\t\tmessage,","atom":"a1447","author":"speed","version":150},{"n":198,"text":"\t\t\tauthor,","atom":"a1447","author":"speed","version":150},{"n":199,"text":"\t\t\tcommitter,","atom":"a1447","author":"speed","version":150},{"n":200,"text":"\t\t\ttree,","atom":"a1447","author":"speed","version":150},{"n":201,"text":"\t\t\tparent: parent ? [parent] : [],","atom":"a1447","author":"speed","version":150},{"n":202,"text":"\t\t\tref: \"main\",","atom":"a1447","author":"speed","version":150},{"n":203,"text":"\t\t});","atom":"a1447","author":"speed","version":150},{"n":204,"text":"\t\treturn parent;","atom":"a1447","author":"speed","version":150},{"n":205,"text":"\t};","atom":"a1447","author":"speed","version":150},{"n":206,"text":"\t// Artifacts refuses a push much over 20 MB, so when new text or binary blobs add up","atom":"a2027","author":"codex-capacity-chair","version":181},{"n":207,"text":"\t// to more than PUSH_BATCH, the earlier ones go in commits of their own","atom":"a1447","author":"speed","version":150},{"n":208,"text":"\t// first. Every part carries abso-version, so intake never takes them in.","atom":"a1447","author":"speed","version":150},{"n":209,"text":"\tlet pending = 0;","atom":"a1447","author":"speed","version":150},{"n":210,"text":"\tlet parts = 0;","atom":"a1447","author":"speed","version":150},{"n":211,"text":"\tfor (const path of Object.keys(shared.files)) {","atom":"a1810","author":"codex-capacity-chair","version":166},{"n":212,"text":"\t\tconst mode = shared.modes?.[path];","atom":"a1447","author":"speed","version":150},{"n":213,"text":"\t\tconst link = typeof mode?.link === \"string\" ? mode.link : null;","atom":"a1447","author":"speed","version":150},{"n":214,"text":"\t\tconst bytes = enc.encode(link ?? shared.files[path]!);","atom":"a1810","author":"codex-capacity-chair","version":166},{"n":215,"text":"\t\tconst oid = await blobOid(bytes);","atom":"a2027","author":"codex-capacity-chair","version":181},{"n":216,"text":"\t\tconst fresh = old.files.get(path)?.oid !== oid;","atom":"a2027","author":"codex-capacity-chair","version":181},{"n":217,"text":"\t\tif (fresh && pending > 0 && pending + bytes.byteLength > PUSH_BATCH) {","atom":"a2027","author":"codex-capacity-chair","version":181},{"n":218,"text":"\t\t\tawait part(await commitNow(say(` (part ${++parts})`)));","atom":"a2027","author":"codex-capacity-chair","version":181},{"n":219,"text":"\t\t\tpending = 0;","atom":"a2027","author":"codex-capacity-chair","version":181},{"n":220,"text":"\t\t}","atom":"a2027","author":"codex-capacity-chair","version":181},{"n":221,"text":"\t\tif (fresh) pending += bytes.byteLength;","atom":"a2027","author":"codex-capacity-chair","version":181},{"n":222,"text":"\t\tawait put(path, bytes, link !== null ? \"120000\" : mode?.exec ? \"100755\" : \"100644\", oid);","atom":"a2027","author":"codex-capacity-chair","version":181},{"n":223,"text":"\t}","atom":"a2027","author":"codex-capacity-chair","version":181},{"n":224,"text":"\tfor (const [path, sha] of Object.entries(blobs)) {","atom":"a1447","author":"speed","version":150},{"n":225,"text":"\t\tconst bytes = readBlob(sha);","atom":"a1447","author":"speed","version":150},{"n":226,"text":"\t\tif (!bytes) throw new Error(`${path}: blob ${sha} is missing from the project's store`);","atom":"a1447","author":"speed","version":150},{"n":227,"text":"\t\tconst oid = await blobOid(bytes);","atom":"a1447","author":"speed","version":150},{"n":228,"text":"\t\tconst fresh = old.files.get(path)?.oid !== oid;","atom":"a1447","author":"speed","version":150},{"n":229,"text":"\t\tif (fresh && pending > 0 && pending + bytes.byteLength > PUSH_BATCH) {","atom":"a1447","author":"speed","version":150},{"n":230,"text":"\t\t\tawait part(await commitNow(say(` (part ${++parts})`)));","atom":"a1447","author":"speed","version":150},{"n":231,"text":"\t\t\tpending = 0;","atom":"a1447","author":"speed","version":150},{"n":232,"text":"\t\t}","atom":"a1447","author":"speed","version":150},{"n":233,"text":"\t\tif (fresh) pending += bytes.byteLength;","atom":"a1447","author":"speed","version":150},{"n":234,"text":"\t\tawait put(path, bytes, shared.modes?.[path]?.exec ? \"100755\" : \"100644\", oid);","atom":"a1447","author":"speed","version":150},{"n":235,"text":"\t}","atom":"a1447","author":"speed","version":150},{"n":236,"text":"\tconst commit = await commitNow(say(parts > 0 ? ` (part ${parts + 1}, last)` : \"\"));","atom":"a1447","author":"speed","version":150},{"n":237,"text":"\treturn { commit, changed: changed.size };","atom":"a1447","author":"speed","version":150},{"n":238,"text":"}","atom":"a1447","author":"speed","version":150},{"n":239,"text":"","atom":"a1447","author":"speed","version":150},{"n":240,"text":"export async function pushShared(","atom":"a1447","author":"speed","version":150},{"n":241,"text":"\tartifacts: Artifacts,","atom":"a1447","author":"speed","version":150},{"n":242,"text":"\tproject: string,","atom":"a1447","author":"speed","version":150},{"n":243,"text":"\tshared: SharedFiles,","atom":"a1447","author":"speed","version":150},{"n":244,"text":"\t/** A binary file's bytes by SHA-256 (#27), from the project's blob store. */","atom":"a1447","author":"speed","version":150},{"n":245,"text":"\treadBlob: (sha256: string) => Uint8Array | null = () => null,","atom":"a1447","author":"speed","version":150},{"n":246,"text":"\tdisk?: { storage: SqliteStorage; maxPackBytes: number; maxObjectBytes: number; maxDecodedBytes: number },","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":247,"text":"): Promise<PushResult> {","atom":"a1447","author":"speed","version":150},{"n":248,"text":"\tconst t0 = Date.now();","atom":"a1447","author":"speed","version":150},{"n":249,"text":"\tconst name = repoName(project);","atom":"a1447","author":"speed","version":150},{"n":250,"text":"\tconst { remote, secret } = await writeAccess(artifacts, name);","atom":"a1447","author":"speed","version":150},{"n":251,"text":"\tconst onAuth = () => ({ username: \"x\", password: secret });","atom":"a1447","author":"speed","version":150},{"n":252,"text":"\tusing contents = disk ? new GitFileContents(disk.storage, disk.maxObjectBytes, disk.maxDecodedBytes) : undefined;","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":253,"text":"\tusing intake = disk","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":254,"text":"\t\t? new GitDiskIntake(disk.storage, disk.maxPackBytes, disk.maxObjectBytes, disk.maxDecodedBytes)","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":255,"text":"\t\t: undefined;","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":256,"text":"\tconst cache = disk ? {} : undefined;","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":257,"text":"\tif (intake && cache) intake.attach(cache);","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":258,"text":"\tconst transport = disk ? gitHttp() : http;","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":259,"text":"\tlet fs = new MemoryFS(contents);","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":260,"text":"\tconst dir = \"/repo\";","atom":"a1447","author":"speed","version":150},{"n":261,"text":"\t// A new repo has no main yet. isomorphic-git \"clones\" an empty repo without","atom":"a1447","author":"speed","version":150},{"n":262,"text":"\t// an error but leaves HEAD on master, so check for main and start clean.","atom":"a1447","author":"speed","version":150},{"n":263,"text":"\t// Nothing is checked out: the new tree is built from tree objects (293).","atom":"a1447","author":"speed","version":150},{"n":264,"text":"\t// Only an explicitly absent main is an empty repository. Transport, decode,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":265,"text":"\t// and size failures must never become permission to replace remote history.","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":266,"text":"\tconst refs = await git.listServerRefs({ http: transport, url: remote, onAuth, prefix: \"refs/heads/main\" });","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":267,"text":"\tlet head: string | null = null;","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":268,"text":"\tif (refs.some((ref) => ref.ref === \"refs/heads/main\")) {","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":269,"text":"\t\tawait git.clone({","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":270,"text":"\t\t\tfs,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":271,"text":"\t\t\thttp: transport,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":272,"text":"\t\t\tcache,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":273,"text":"\t\t\tdir,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":274,"text":"\t\t\turl: remote,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":275,"text":"\t\t\tref: \"main\",","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":276,"text":"\t\t\tsingleBranch: true,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":277,"text":"\t\t\tdepth: 1,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":278,"text":"\t\t\tnoCheckout: true,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":279,"text":"\t\t\tonAuth,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":280,"text":"\t\t});","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":281,"text":"\t\tintake?.assertReady();","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":282,"text":"\t\thead = await git.resolveRef({ fs, dir, ref: \"main\" });","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":283,"text":"\t}","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":284,"text":"\tif (head === null) {","atom":"a1447","author":"speed","version":150},{"n":285,"text":"\t\tfs = new MemoryFS(contents);","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":286,"text":"\t\tawait git.init({ fs, dir, defaultBranch: \"main\" });","atom":"a1447","author":"speed","version":150},{"n":287,"text":"\t}","atom":"a1447","author":"speed","version":150},{"n":288,"text":"\tconst t1 = Date.now();","atom":"a1447","author":"speed","version":150},{"n":289,"text":"\tconst push = () => git.push({ fs, http: transport, cache, dir, url: remote, ref: \"main\", remoteRef: \"main\", onAuth });","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":290,"text":"\tconst { commit, changed } = await commitShared(","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":291,"text":"\t\tfs,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":292,"text":"\t\tdir,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":293,"text":"\t\thead,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":294,"text":"\t\tshared,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":295,"text":"\t\treadBlob,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":296,"text":"\t\tasync () => void (await push()),","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":297,"text":"\t\tcache,","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":298,"text":"\t);","atom":"a2012","author":"codex-capacity-chair","version":180},{"n":299,"text":"\tconst t2 = Date.now();","atom":"a1447","author":"speed","version":150},{"n":300,"text":"\tawait push();","atom":"a1447","author":"speed","version":150},{"n":301,"text":"\tconsole.log(","atom":"a1447","author":"speed","version":150},{"n":302,"text":"\t\t`push ${project} v${shared.version}: clone ${t1 - t0} ms, files ${t2 - t1} ms (${changed} changed), push ${Date.now() - t2} ms`,","atom":"a1447","author":"speed","version":150},{"n":303,"text":"\t);","atom":"a1447","author":"speed","version":150},{"n":304,"text":"\treturn { repo: name, remote, commit, version: shared.version, ms: Date.now() - t0 };","atom":"a1447","author":"speed","version":150},{"n":305,"text":"}","atom":"a1447","author":"speed","version":150}],"atoms":[{"atom":"a1447","author":"speed","message":"","time":1791906675188,"timeIso":"2026-10-13T15:51:15.188Z","publish":{"draft":null,"version":150,"agent":"speed","message":"Open server: the project Worker, Durable Object and Artifacts (issue 17)","time":1791907522179,"timeIso":"2026-10-13T16:05:22.179Z"}},{"atom":"a1810","author":"codex-capacity-chair","message":"","time":1791953747113,"timeIso":"2026-10-14T04:55:47.113Z","publish":{"draft":null,"version":166,"agent":"codex-capacity-chair","message":"Read long insertion text lazily and stream files through Git commit construction","time":1791954093327,"timeIso":"2026-10-14T05:01:33.327Z"}},{"atom":"a2012","author":"codex-capacity-chair","message":"","time":1791975298240,"timeIso":"2026-10-14T10:54:58.240Z","publish":{"draft":null,"version":180,"agent":"codex-capacity-chair","message":"Keep Git export files and intake history on disk behind the disk-first switch; remember bounded intake refusals. In both modes, stop export after failed intake and retry in 1, 5, then 15 minutes; list refs before export cloning and propagate clone errors instead of treating failures as an empty repository. Preserve legacy cache lifetime, avoid a whole-file hash copy, and verify real Git uploads plus cold retry behavior. Review 56 cleared; activation remains off.","time":1791975298240,"timeIso":"2026-10-14T10:54:58.240Z"}},{"atom":"a2027","author":"codex-capacity-chair","message":"","time":1791976047265,"timeIso":"2026-10-14T11:07:27.265Z","publish":{"draft":null,"version":181,"agent":"codex-capacity-chair","message":"Batch changed text toward the 16 MiB push limit. Preserve pending old text and binary files in intermediate commits, retain intended deletions and parent ancestry, and leave single oversized files unsplit. Review 56 cleared the two-file change; disk-first activation remains off.","time":1791976047265,"timeIso":"2026-10-14T11:07:27.265Z"}}]}