{"draft":null,"from":280,"to":318,"files":[{"path":"scripts/build-client.mjs","added":3,"removed":0,"diff":"--- a/scripts/build-client.mjs\n+++ b/scripts/build-client.mjs\n@@ -31,6 +31,9 @@\n \t\twrite: false,\n \t\toutfile: OUT,\n \t\tlogLevel: \"warning\",\n+\t\t// Local projects run the open server's code in the client (client/src/local-store.ts); its Durable Object\n+\t\t// base class comes from the Workers runtime, so the bundle gets the client's stand-in.\n+\t\talias: { \"cloudflare:workers\": \"./client/src/durable-object-stand-in.ts\" },\n \t\t// A bundled CommonJS package (yaml) calls require(\"process\") lazily, which an ES module bundle\n \t\t// can't do without a real require.\n \t\tbanner: {"},{"path":"scripts/local-measure.ts","added":123,"removed":0,"diff":"--- /dev/null\n+++ b/scripts/local-measure.ts\n@@ -0,0 +1,123 @@\n+// Time and memory of a local project's commands (abso init --local) on a small and a large history:\n+//\n+//   node scripts/local-measure.ts [versions ...]        (default: 20 1000)\n+//\n+// Each history is built in this process through the client's main(); then every command is run as its own\n+// `node client/abso.ts` process, the way a person or an agent runs it, five times. It prints the median and slowest\n+// wall time, and the largest peak memory (maxRSS) of those runs, with the store's size on disk.\n+\n+import { spawnSync } from \"node:child_process\";\n+import { mkdtempSync, readdirSync, rmSync, statSync, writeFileSync } from \"node:fs\";\n+import { tmpdir } from \"node:os\";\n+import { join, resolve } from \"node:path\";\n+import { fileURLToPath, pathToFileURL } from \"node:url\";\n+import { main } from \"../client/src/main.ts\";\n+\n+const ROOT = resolve(fileURLToPath(new URL(\"..\", import.meta.url)));\n+const ENTRY = join(ROOT, \"client\", \"abso.ts\");\n+const FILES = 40;\n+const RUNS = 5;\n+\n+const sizes = process.argv.slice(2).map(Number);\n+const histories = sizes.length > 0 ? sizes : [20, 1000];\n+\n+function sizeOf(dir: string): number {\n+\tlet total = 0;\n+\tfor (const name of readdirSync(dir)) {\n+\t\tconst path = join(dir, name);\n+\t\tconst s = statSync(path);\n+\t\ttotal += s.isDirectory() ? sizeOf(path) : s.size;\n+\t}\n+\treturn total;\n+}\n+\n+const lines = (file: number, version: number) =>\n+\tArray.from({ length: 30 }, (_, i) =>\n+\t\ti === version % 30 ? `line ${i} of file ${file}, version ${version}` : `line ${i} of file ${file}`,\n+\t)\n+\t\t.join(\"\\n\")\n+\t\t.concat(\"\\n\");\n+\n+async function build(versions: number): Promise<{ store: string; alice: string; bob: string }> {\n+\tconst store = mkdtempSync(join(tmpdir(), \"abso-measure-store-\"));\n+\tconst alice = mkdtempSync(join(tmpdir(), \"abso-measure-alice-\"));\n+\tconst bob = mkdtempSync(join(tmpdir(), \"abso-measure-bob-\"));\n+\tconst env = { ABSO_STORE: store, ABSO_SERVERS_FILE: \"no-servers.json\" };\n+\tconst run = async (cwd: string, ...argv: string[]) => {\n+\t\tconst r = await main(argv, { cwd, env, write: () => {} });\n+\t\tif (r.exit !== 0) throw new Error(`${argv.join(\" \")}: ${r.stdout}${r.stderr}`);\n+\t};\n+\tfor (let f = 0; f < FILES; f++) writeFileSync(join(alice, `f${f}.txt`), lines(f, 0));\n+\tawait run(alice, \"init\", \"--local\", \"--project\", \"measure\", \"--agent\", \"alice\", \"--as-is\");\n+\tfor (let v = 1; v < versions; v++) {\n+\t\t// Each version changes three files, as a small piece of work does.\n+\t\tfor (const f of [v % FILES, (v * 7) % FILES, (v * 13) % FILES])\n+\t\t\twriteFileSync(join(alice, `f${f}.txt`), lines(f, v));\n+\t\tawait run(alice, \"push\", \"-m\", `Version ${v}`);\n+\t}\n+\tawait run(bob, \"join\", \"measure\", \"--local\", \"--agent\", \"bob\", \"--dir\", bob);\n+\treturn { store, alice, bob };\n+}\n+\n+function measure(cwd: string, store: string, argv: string[]): { median: number; slowest: number; rss: number } {\n+\tconst times: number[] = [];\n+\tlet rss = 0;\n+\tconst preload = join(tmpdir(), `abso-measure-rss-${process.pid}.mjs`);\n+\tconst out = join(tmpdir(), `abso-measure-rss-${process.pid}.json`);\n+\twriteFileSync(\n+\t\tpreload,\n+\t\t`import { writeFileSync } from \"node:fs\";\\nprocess.on(\"exit\", () => writeFileSync(${JSON.stringify(out)}, String(process.resourceUsage().maxRSS)));\\n`,\n+\t);\n+\tfor (let i = 0; i < RUNS; i++) {\n+\t\tconst started = performance.now();\n+\t\tconst r = spawnSync(process.execPath, [\"--import\", pathToFileURL(preload).href, ENTRY, ...argv], {\n+\t\t\tcwd,\n+\t\t\tenv: { ...process.env, ABSO_STORE: store, ABSO_SERVERS_FILE: \"no-servers.json\" },\n+\t\t\tencoding: \"utf8\",\n+\t\t});\n+\t\ttimes.push(performance.now() - started);\n+\t\tif (r.status !== 0 && argv[0] !== \"push\") throw new Error(`${argv.join(\" \")}: ${r.stdout}${r.stderr}`);\n+\t\trss = Math.max(\n+\t\t\trss,\n+\t\t\tNumber(\n+\t\t\t\tspawnSync(\n+\t\t\t\t\tprocess.execPath,\n+\t\t\t\t\t[\"-e\", `process.stdout.write(require(\"fs\").readFileSync(${JSON.stringify(out)}, \"utf8\"))`],\n+\t\t\t\t\t{ encoding: \"utf8\" },\n+\t\t\t\t).stdout,\n+\t\t\t),\n+\t\t);\n+\t}\n+\ttimes.sort((a, b) => a - b);\n+\treturn { median: times[Math.floor(RUNS / 2)]!, slowest: times[RUNS - 1]!, rss };\n+}\n+\n+const kb = (n: number) => `${(n / 1024).toFixed(0)} MB`;\n+const ms = (n: number) => `${n.toFixed(0)} ms`;\n+console.log(\n+\t`Node ${process.versions.node}, ${FILES} files of 30 lines, three files changed per version, ${RUNS} runs each.`,\n+);\n+console.log(\"history   | command              | median   | slowest  | peak memory\");\n+for (const versions of histories) {\n+\tconst started = performance.now();\n+\tconst { store, alice, bob } = await build(versions);\n+\tconst built = performance.now() - started;\n+\tconst steps: [string, string, string[]][] = [\n+\t\t[\"status\", alice, [\"status\"]],\n+\t\t[\"log\", alice, [\"log\"]],\n+\t\t[\"blame\", alice, [\"blame\", \"f0.txt\"]],\n+\t\t[\"pull (no change)\", bob, [\"pull\"]],\n+\t\t[\"record + push\", alice, [\"push\", \"-m\", \"One more\"]],\n+\t];\n+\tfor (const [name, cwd, argv] of steps) {\n+\t\tif (argv[0] === \"push\") writeFileSync(join(cwd, \"f1.txt\"), lines(1, versions + Math.random()));\n+\t\tconst m = measure(cwd, store, argv);\n+\t\tconsole.log(\n+\t\t\t`${String(versions).padStart(5)} v   | ${name.padEnd(20)} | ${ms(m.median).padStart(8)} | ${ms(m.slowest).padStart(8)} | ${kb(m.rss)}`,\n+\t\t);\n+\t}\n+\tconsole.log(\n+\t\t`${String(versions).padStart(5)} v   | store on disk ${(sizeOf(store) / 1048576).toFixed(1)} MB, built in-process in ${(built / 1000).toFixed(1)} s`,\n+\t);\n+\tfor (const d of [store, alice, bob]) rmSync(d, { recursive: true, force: true, maxRetries: 5 });\n+}"},{"path":"scripts/local-writers.ts","added":87,"removed":0,"diff":"--- /dev/null\n+++ b/scripts/local-writers.ts\n@@ -0,0 +1,87 @@\n+// A local project's store lock under load: 1, 4 and 16 writers pushing to one local project at once.\n+//\n+//   node scripts/local-writers.ts [writers ...]        (default: 1 4 16; PUSHES=10 pushes per writer)\n+//\n+// Each writer is its own agent, in its own folder, changing its own file, so nothing collides: what's measured is the\n+// store's lock (one SQLite write transaction per call). Every push is its own `node client/abso.ts push` process, as\n+// an agent runs it. It prints each push's wall time (median, 95th percentile, slowest), the pushes per second across\n+// all writers, and any push that failed.\n+\n+import { spawn } from \"node:child_process\";\n+import { mkdtempSync, rmSync, writeFileSync } from \"node:fs\";\n+import { tmpdir } from \"node:os\";\n+import { join, resolve } from \"node:path\";\n+import { fileURLToPath } from \"node:url\";\n+import { main } from \"../client/src/main.ts\";\n+\n+const ROOT = resolve(fileURLToPath(new URL(\"..\", import.meta.url)));\n+const ENTRY = join(ROOT, \"client\", \"abso.ts\");\n+const PUSHES = Number(process.env.PUSHES ?? 10);\n+const counts = process.argv.slice(2).map(Number);\n+\n+function push(cwd: string, store: string, message: string): Promise<{ ms: number; ok: boolean; out: string }> {\n+\tconst started = performance.now();\n+\treturn new Promise((done) => {\n+\t\tconst child = spawn(process.execPath, [ENTRY, \"push\", \"-m\", message], {\n+\t\t\tcwd,\n+\t\t\tenv: { ...process.env, ABSO_STORE: store, ABSO_SERVERS_FILE: \"no-servers.json\" },\n+\t\t});\n+\t\tlet out = \"\";\n+\t\tchild.stdout.on(\"data\", (d) => {\n+\t\t\tout += d;\n+\t\t});\n+\t\tchild.stderr.on(\"data\", (d) => {\n+\t\t\tout += d;\n+\t\t});\n+\t\tchild.on(\"close\", (code) => done({ ms: performance.now() - started, ok: code === 0, out }));\n+\t});\n+}\n+\n+const pct = (sorted: number[], p: number) => sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * p))]!;\n+console.log(`Node ${process.versions.node}, ${PUSHES} pushes per writer, each writer its own agent and file.`);\n+console.log(\"writers | pushes | median   | p95      | slowest  | pushes/s | failed\");\n+for (const writers of counts.length > 0 ? counts : [1, 4, 16]) {\n+\tconst store = mkdtempSync(join(tmpdir(), \"abso-writers-store-\"));\n+\tconst folders: string[] = [];\n+\tconst env = { ABSO_STORE: store, ABSO_SERVERS_FILE: \"no-servers.json\" };\n+\tconst first = mkdtempSync(join(tmpdir(), \"abso-writers-w0-\"));\n+\twriteFileSync(join(first, \"readme.txt\"), \"writers\\n\");\n+\tconst init = await main([\"init\", \"--local\", \"--project\", \"writers\", \"--agent\", \"w0\", \"--as-is\"], {\n+\t\tcwd: first,\n+\t\tenv,\n+\t\twrite: () => {},\n+\t});\n+\tif (init.exit !== 0) throw new Error(init.stdout + init.stderr);\n+\tfolders.push(first);\n+\tfor (let w = 1; w < writers; w++) {\n+\t\tconst dir = mkdtempSync(join(tmpdir(), `abso-writers-w${w}-`));\n+\t\tconst joined = await main([\"join\", \"writers\", \"--local\", \"--agent\", `w${w}`, \"--dir\", dir], {\n+\t\t\tcwd: dir,\n+\t\t\tenv,\n+\t\t\twrite: () => {},\n+\t\t});\n+\t\tif (joined.exit !== 0) throw new Error(joined.stdout + joined.stderr);\n+\t\tfolders.push(dir);\n+\t}\n+\tconst times: number[] = [];\n+\tconst failures: string[] = [];\n+\tconst started = performance.now();\n+\tawait Promise.all(\n+\t\tfolders.map(async (dir, w) => {\n+\t\t\tfor (let i = 0; i < PUSHES; i++) {\n+\t\t\t\twriteFileSync(join(dir, `w${w}.txt`), `writer ${w}, push ${i}\\n`);\n+\t\t\t\tconst r = await push(dir, store, `w${w} push ${i}`);\n+\t\t\t\ttimes.push(r.ms);\n+\t\t\t\tif (!r.ok) failures.push(`w${w} push ${i}: ${r.out.trim().split(\"\\n\").slice(-2).join(\" / \")}`);\n+\t\t\t}\n+\t\t}),\n+\t);\n+\tconst total = (performance.now() - started) / 1000;\n+\ttimes.sort((a, b) => a - b);\n+\tconst ms = (n: number) => `${n.toFixed(0)} ms`.padStart(8);\n+\tconsole.log(\n+\t\t`${String(writers).padStart(7)} | ${String(times.length).padStart(6)} | ${ms(pct(times, 0.5))} | ${ms(pct(times, 0.95))} | ${ms(times.at(-1)!)} | ${(times.length / total).toFixed(1).padStart(8)} | ${failures.length}`,\n+\t);\n+\tfor (const f of failures.slice(0, 5)) console.log(`        ${f}`);\n+\tfor (const d of [store, ...folders]) rmSync(d, { recursive: true, force: true, maxRetries: 5 });\n+}"}],"unmatched":[]}