{"version":287,"agent":"pinch","message":"Local projects: abso init --local keeps a project's history on this machine, with no server, sign-in or network\n\nA local folder's calls never leave the process. The client runs the open server's own router and project object (server/src) in-process, over Node's built-in SQLite. It's the same engine with the same answers, so what the commands print matches a server.\n\n- abso init --local [--project <name>] [--agent <name>] [--store <folder>] makes the project, and abso join <project> --local adds a folder. After that, record, push, pull, log, blame and the held collisions work as usual. The folder's config says \"server\": \"local\".\n- Where the store lives: --store (kept in the folder's config; a store inside the folder is left out of its files through .absoignore), else ABSO_STORE, else this user's data folder: %LOCALAPPDATA%\\abso\\store, ~/Library/Application Support/abso/store, or $XDG_DATA_HOME/abso/store. Nothing needs a writable home folder when ABSO_STORE or --store is set.\n- Each project is <store>/<project>/project.sqlite. Every call runs in one SQLite write transaction, which is the store's lock: other processes wait for it, and a process that dies mid-call keeps nothing half-written. A process reloads the project only when SQLite's data_version shows another process wrote.\n- No credential goes with a local folder's calls. The edit mod leaves local folders alone, so abso record sends their edits. Issues, asks and news aren't in local projects yet.\n- Needs Node 22.13 or later (node:sqlite); its experimental warning is kept out of the output. Run as .ts, a module hook supplies the Durable Object base class (client/src/durable-object-stand-in.ts); the build aliases cloudflare:workers to the same file. client/src/local-server.mjs, with its .d.mts, keeps the client's typecheck out of server/src, which has its own.\n- Each command closes the store files it opened.\n\nTests: local (8, with fetch replaced by one that throws: init, record, push, join, pull, log, blame, a held collision, --store inside the folder, refusals), plus failed-start, install, caller, doctor, lost-pull, help, body-files: 60 pass; tsc clean. The bundle built with the alias runs init, push and log locally.","time":1792119778236,"timeIso":"2026-10-16T03:02:58.236Z","changes":14,"change":4532,"files":["client/hooks/register.ts","client/src/api.ts","client/src/config.ts","client/src/durable-object-stand-in.ts","client/src/join-commands.ts","client/src/local-server.d.mts","client/src/local-server.mjs","client/src/local-store.ts","client/src/main.ts","client/test/local.test.ts","scripts/build-client.mjs"],"draft":null,"diff":[{"path":"client/hooks/register.ts","added":7,"removed":0,"diff":"--- a/client/hooks/register.ts\n+++ b/client/hooks/register.ts\n@@ -182,6 +182,9 @@\n \tfor (let job = jobs.shift(); job !== undefined; job = jobs.shift()) await run($, job);\n }\n \n+/** A local project's folder (abso init --local): its config names no server. */\n+const LOCAL_FOLDER = /\"server\"\\s*:\\s*\"local\"/;\n+\n async function run($: Engine, job: Job): Promise<void> {\n \tconst started = await $.clock.now().catch(() => job.queuedAt);\n \tlet outcome: string;\n@@ -191,6 +194,9 @@\n \t\t\toutcome = \"skipped: recording is paused (abso resume)\";\n \t\t} else if (/\"reader\"\\s*:\\s*true/.test((await readOr($, `${await stateOf($, job.root)}/config.json`)) ?? \"\")) {\n \t\t\toutcome = \"skipped: this folder is a reader\";\n+\t\t} else if (LOCAL_FOLDER.test((await readOr($, `${await stateOf($, job.root)}/config.json`)) ?? \"\")) {\n+\t\t\t// A local project's history is in a store on this machine, which only the abso command opens.\n+\t\t\toutcome = \"skipped: a local project; abso record sends its edits\";\n \t\t} else if (await ignored($, job.root, job.rel)) {\n \t\t\toutcome = \"skipped: ignored path\";\n \t\t} else if (await isLink($, job.root, job.rel)) {\n@@ -242,6 +248,7 @@\n \t\t\tproject: string;\n \t\t\tagent: string;\n \t\t};\n+\t\tif (config.server === \"local\") return;\n \t\tconst bearer = await token($, config.server);\n \t\tconst r = await $.http.fetch(\n \t\t\t`${config.server.replace(/\\/+$/, \"\")}/p/${encodeURIComponent(config.project)}/a/${encodeURIComponent(config.agent)}/news`,"},{"path":"client/src/api.ts","added":15,"removed":1,"diff":"--- a/client/src/api.ts\n+++ b/client/src/api.ts\n@@ -20,6 +20,7 @@\n \tSyncAnswer,\n } from \"./api-answers.ts\";\n import { ApiError, errorSentence, neverSent } from \"./api-error.ts\";\n+import { UsageError } from \"./args.ts\";\n import type { AutosettleAnswer, AutosettleMode } from \"./autosettle-commands.ts\";\n import {\n \tboxQuery,\n@@ -68,6 +69,7 @@\n \tIssueRow,\n \tIssueSearchHit,\n } from \"./issues-wire.ts\";\n+import { isLocal, LOCAL_BASE, localFetch, NO_STORE } from \"./local-store.ts\";\n import type { Modes } from \"./modes.ts\";\n \n export * from \"./api-answers.ts\";\n@@ -191,9 +193,13 @@\n \tcaller: string | undefined;\n \n \turl(path: string, server = this.config.server): string {\n-\t\treturn `${server.replace(/\\/+$/, \"\")}/p/${encodeURIComponent(this.config.project)}${path}`;\n+\t\tconst base = isLocal(server) ? LOCAL_BASE : server;\n+\t\treturn `${base.replace(/\\/+$/, \"\")}/p/${encodeURIComponent(this.config.project)}${path}`;\n \t}\n \n+\t/** A local project's calls: answered in this process (local-store.ts). */\n+\tprivate local: ((input: string, init?: RequestInit) => Promise<Response>) | undefined;\n+\n \tagentPath(action: string): string {\n \t\treturn `/a/${encodeURIComponent(this.config.agent)}/${action}`;\n \t}\n@@ -214,6 +220,12 @@\n \t * and follows no redirect, so nothing it sends goes anywhere it didn't name (headers() adds no sign-in).\n \t */\n \tsend(url: string, init: RequestInit = {}): Promise<Response> {\n+\t\tif (isLocal(this.config.server)) {\n+\t\t\tconst dir = this.config.localStore;\n+\t\t\tif (dir === undefined) return Promise.reject(new UsageError(NO_STORE));\n+\t\t\tthis.local ??= localFetch(dir);\n+\t\t\treturn this.local(url, init);\n+\t\t}\n \t\tif (!this.config.visitor) return fetch(url, init);\n \t\tif ((init.method ?? \"GET\") !== \"GET\")\n \t\t\treturn Promise.reject(new ApiError(\"a folder that reads signed out sends only reads\"));\n@@ -248,6 +260,8 @@\n \t\t\t\t\tsignal: AbortSignal.timeout(timeoutMs),\n \t\t\t\t});\n \t\t\t} catch (err) {\n+\t\t\t\t// A local project's refusal (no store, a Node without SQLite) says itself.\n+\t\t\t\tif (err instanceof UsageError) throw err;\n \t\t\t\tconst e = err as Error;\n \t\t\t\tconst why =\n \t\t\t\t\te.name === \"TimeoutError\""},{"path":"client/src/config.ts","added":19,"removed":3,"diff":"--- a/client/src/config.ts\n+++ b/client/src/config.ts\n@@ -11,6 +11,7 @@\n import { UsageError } from \"./args.ts\";\n import { type MachineServers, machineServers, TOKEN_SERVERS, tokenGoesTo, trustedList } from \"./core.ts\";\n import { fromEnv } from \"./env-names.ts\";\n+import { isLocal, storeDir } from \"./local-store.ts\";\n import { homeFile, stateDir } from \"./state-dir.ts\";\n \n /** What .avcs/config.json holds. */\n@@ -27,10 +28,14 @@\n \t * routes anyone can read and sends no credential. It has no agent; its config holds server, project and this.\n \t */\n \treadonly visitor?: boolean;\n+\t/** A local project's store (abso init --local --store), when it isn't the machine's own: ABSO_STORE or the OS data folder. */\n+\treadonly store?: string;\n }\n \n export interface Config extends Settings {\n \treadonly token?: string;\n+\t/** For a local project (server \"local\"): the store folder its history is in, or undefined when there's none to use. */\n+\treadonly localStore?: string;\n }\n \n export function configPath(root: string): string {\n@@ -64,11 +69,15 @@\n \tfor (const key of [\"server\", \"project\", \"agent\"] as const) {\n \t\tif (typeof raw[key] !== \"string\" || raw[key] === \"\") throw new Error(`${configPath(root)} has no \"${key}\"`);\n \t}\n-\tconst token = tokenFor(raw.server!, env, root, tokenFileOk);\n+\t// A local project's calls never leave this process, so no credential goes with them.\n+\tconst local = isLocal(raw.server);\n+\tconst token = local ? undefined : tokenFor(raw.server!, env, root, tokenFileOk);\n \treturn {\n \t\tserver: raw.server!,\n \t\tproject: raw.project!,\n \t\tagent: raw.agent!,\n+\t\t...(typeof raw.store === \"string\" && raw.store !== \"\" ? { store: raw.store } : {}),\n+\t\t...(local ? { localStore: storeDir(env, raw.store, root) } : {}),\n \t\t...(typeof raw.follow === \"string\" && raw.follow !== \"\" ? { follow: raw.follow } : {}),\n \t\t...(raw.reader === true ? { reader: true } : {}),\n \t\t...(token ? { token } : {}),\n@@ -275,10 +284,17 @@\n \n export function writeConfig(root: string, settings: Settings): void {\n \tmkdirSync(stateDir(root), { recursive: true });\n-\tconst { server, project, agent, follow, reader, visitor } = settings;\n+\tconst { server, project, agent, follow, reader, visitor, store } = settings;\n \tconst written = visitor\n \t\t? { server, project, visitor: true }\n-\t\t: { server, project, agent, ...(follow ? { follow } : {}), ...(reader ? { reader: true } : {}) };\n+\t\t: {\n+\t\t\t\tserver,\n+\t\t\t\tproject,\n+\t\t\t\tagent,\n+\t\t\t\t...(follow ? { follow } : {}),\n+\t\t\t\t...(reader ? { reader: true } : {}),\n+\t\t\t\t...(store ? { store } : {}),\n+\t\t\t};\n \twriteFileSync(configPath(root), `${JSON.stringify(written, null, 2)}\\n`);\n \texcludeFromGit(root);\n }"},{"path":"client/src/durable-object-stand-in.ts","added":13,"removed":0,"diff":"--- /dev/null\n+++ b/client/src/durable-object-stand-in.ts\n@@ -0,0 +1,13 @@\n+// What `import { DurableObject } from \"cloudflare:workers\"` gives the open server's code when it runs inside the client\n+// for a local project (local-store.ts): a base class that keeps the object's state and settings, which is all the\n+// project object takes from it. The build points that import here (scripts/build-client.mjs); run as .ts files, a\n+// module hook does (local-store.ts).\n+\n+export class DurableObject<Env = unknown> {\n+\tctx: unknown;\n+\tenv: Env;\n+\tconstructor(ctx: unknown, env: Env) {\n+\t\tthis.ctx = ctx;\n+\t\tthis.env = env;\n+\t}\n+}"},{"path":"client/src/join-commands.ts","added":80,"removed":21,"diff":"--- a/client/src/join-commands.ts\n+++ b/client/src/join-commands.ts\n@@ -2,7 +2,7 @@\n \n import { randomUUID } from \"node:crypto\";\n import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from \"node:fs\";\n-import { join, relative, resolve } from \"node:path\";\n+import { isAbsolute, join, relative, resolve, sep } from \"node:path\";\n import { Api, ApiError, type SyncAnswer } from \"./api.ts\";\n import { bool, type Parsed, str, UsageError } from \"./args.ts\";\n import { writeKnownBlobs } from \"./blobs.ts\";\n@@ -33,6 +33,7 @@\n import { fromEnv } from \"./env-names.ts\";\n import { clearKnown, loadIgnore, readFolder, writeKnown } from \"./folder.ts\";\n import { installerCommand, modInstalled } from \"./install.ts\";\n+import { LOCAL, NO_STORE, storeDir } from \"./local-store.ts\";\n import { type FullMode, foldModes, writeKnownModes } from \"./modes.ts\";\n import { initInOrg, siteOf } from \"./orgs.ts\";\n import { projectFileName, readProjectFile, startingProjectFileText, writeStartingProjectFile } from \"./project-file.ts\";\n@@ -101,6 +102,48 @@\n \treturn undefined;\n }\n \n+/**\n+ * --local (abso init, abso join): the project's history is in a store on this machine, not on a server. The store is\n+ * --store, else ABSO_STORE, else the OS's data folder; one given with --store is kept in the folder's config.\n+ */\n+function localFrom(args: Parsed, env: Env, command: string): { dir: string; settings: { store?: string } } | undefined {\n+\tconst store = str(args, \"store\");\n+\tif (!bool(args, \"local\")) {\n+\t\tif (store !== undefined)\n+\t\t\tthrow new UsageError(\"--store goes with --local: it says where a local project's history is\");\n+\t\treturn undefined;\n+\t}\n+\tif (str(args, \"server\") !== undefined)\n+\t\tthrow new UsageError(\"--local or --server, not both: a local project has no server\");\n+\tif (str(args, \"org\") !== undefined || bool(args, \"public\") || bool(args, \"private\") || bool(args, \"reader\"))\n+\t\tthrow new UsageError(\n+\t\t\t`abso ${command} --local takes --project, --agent, --store and --as-is; a local project has no server to share it`,\n+\t\t);\n+\tconst dir = storeDir(env.env, store, env.cwd);\n+\tif (dir === undefined) throw new UsageError(NO_STORE);\n+\treturn { dir, settings: store === undefined ? {} : { store: dir } };\n+}\n+\n+/** A store inside the project folder is left out of its files: a line in .absoignore. Its relative path, if so. */\n+function ignoreStoreInside(root: string, dir: string): string | undefined {\n+\tconst rel = relative(root, dir);\n+\tif (rel === \"\" || rel.startsWith(\"..\") || isAbsolute(rel)) return undefined;\n+\tconst line = `/${rel.split(sep).join(\"/\")}/`;\n+\tconst file = join(root, \".absoignore\");\n+\tconst had = existsSync(file) ? readFileSync(file, \"utf8\") : \"\";\n+\tconst lines = had.split(/\\r?\\n/);\n+\tif (!lines.includes(line)) {\n+\t\tconst gap = had === \"\" || had.endsWith(\"\\n\") ? \"\" : \"\\n\";\n+\t\twriteFileSync(file, `${had}${gap}${line}\\n`);\n+\t}\n+\treturn rel;\n+}\n+\n+/** What init and join say about a local project's store. */\n+function localText(dir: string, project: string, ignored?: string): string {\n+\treturn `It's a local project: its history is in ${join(dir, project)}, on this machine, and no server is needed.${ignored === undefined ? \"\" : ` .absoignore leaves the store, ${ignored}, out of the project's files.`}`;\n+}\n+\n /** Why a token file is no fallback: said when one is here and nothing else signs in. */\n const TOKEN_FILE_ASKED = \"~/.abso/token is used only with --token-file.\";\n \n@@ -112,35 +155,41 @@\n \tconst project = str(args, \"project\");\n \tif (!project) throw new UsageError(\"give the project a name with --project <name>\");\n \tif (bool(args, \"public\") && bool(args, \"private\")) throw new UsageError(\"--public or --private, not both\");\n+\tconst local = localFrom(args, env, \"init\");\n \t// A box signed in here, and no other credential asked for: the project is made as the person who approved the box,\n \t// the way the website makes one (abso 663). The token file only with --token-file, never by itself.\n-\tconst server = serverFrom(args, env);\n-\tconst box = readBox(server);\n-\tconst credential = tokenCredential(args, env.env, server, root);\n+\tconst server = local ? LOCAL : serverFrom(args, env);\n+\tconst box = local ? undefined : readBox(server);\n+\tconst credential = local ? undefined : tokenCredential(args, env.env, server, root);\n \tconst say = env.writeErr ?? env.write;\n \tif (box && credential === undefined) {\n \t\tsay(`Signing in with this box's sign-in, ${box.id}.\n `);\n \t\treturn initFromBox(args, env, root, project, server, box);\n \t}\n-\tif (credential === undefined && tokenFile() !== undefined)\n+\tif (!local && credential === undefined && tokenFile() !== undefined)\n \t\tthrow new UsageError(\n \t\t\t`abso init signs in with this box's sign-in, and this box isn't signed in to ${server}: abso login signs it in. ${TOKEN_FILE_ASKED}`,\n \t\t);\n \tconst org = str(args, \"org\");\n \tif (org !== undefined) return initInOrg(org, server);\n-\tconst config = makeSettings(args, env, project);\n+\tconst config: Settings = local\n+\t\t? { server: LOCAL, project, agent: agentFrom(args, str(args, \"agent\") ?? defaultAgentName()), ...local.settings }\n+\t\t: makeSettings(args, env, project);\n \tconst asIs = bool(args, \"as-is\");\n \tconst absoignore = join(root, \".absoignore\");\n \tconst wroteIgnore = !asIs && !existsSync(absoignore) && !existsSync(join(root, \".avcsignore\"));\n \tif (wroteIgnore) writeFileSync(absoignore, STARTING_ABSOIGNORE);\n+\t// A store kept inside the project folder, like a virtual environment, isn't the project's files.\n+\tconst ignoredStore = local ? ignoreStoreInside(root, local.dir) : undefined;\n \t// What the server runs on each new version (#39), guessed from package.json; recorded with the rest.\n \tconst wroteProject = asIs ? \"exists\" : writeStartingProjectFile(root);\n \tconst { files, blobs, modes, leftOut } = readFolder(root, loadIgnore(root));\n \tconst token = credential?.token;\n-\tsay(`Signing in with ${credential?.words ?? `no credential: nothing here signs in to ${server}`}.\n+\tif (!local)\n+\t\tsay(`Signing in with ${credential?.words ?? `no credential: nothing here signs in to ${server}`}.\n `);\n-\tconst api = new Api({ ...config, ...(token ? { token } : {}) });\n+\tconst api = new Api({ ...config, ...(token ? { token } : {}), ...(local ? { localStore: local.dir } : {}) });\n \tlet answer: Awaited<ReturnType<Api[\"init\"]>>;\n \ttry {\n \t\tawait uploadBlobs(api, blobs);\n@@ -170,12 +219,14 @@\n \t\t\t...(wroteIgnore\n \t\t\t\t? [\"Wrote a starting .absoignore (Claude Code state and operating system files); edit it like .gitignore.\"]\n \t\t\t\t: []),\n-\t\t\t...startingProjectFileText(wroteProject),\n+\t\t\t// A local project has no CI to run abso.json, so no word about one that isn't there.\n+\t\t\t...(local && wroteProject === \"nothing\" ? [] : startingProjectFileText(wroteProject)),\n \t\t\t...(answer.skipped && answer.skipped.length > 0 ? [`The server skipped: ${answer.skipped.join(\", \")}.`] : []),\n+\t\t\t...(local ? [localText(local.dir, project, ignoredStore)] : []),\n \t\t\t`This folder is agent ${config.agent}. Settings are in .abso/config.json.`,\n \t\t\t...refusedText(synced.refused),\n \t\t\t...(synced.kept.length > 0 ? [`Kept your copy of ${synced.kept.join(\", \")}.`] : []),\n-\t\t\thookHint(env.env),\n+\t\t\thookHint(env.env, local !== undefined),\n \t\t].join(\"\\n\"),\n \t\tjson: {\n \t\t\tproject,\n@@ -186,6 +237,7 @@\n \t\t\twroteAbsoignore: wroteIgnore,\n \t\t\twroteProjectFile: typeof wroteProject === \"string\" ? null : wroteProject,\n \t\t\tleftOut,\n+\t\t\t...(local ? { store: local.dir } : {}),\n \t\t},\n \t};\n }\n@@ -380,14 +432,17 @@\n \tmkdirSync(root, { recursive: true });\n \tif (findRoot(root) === root) throw new UsageError(`${root} already has .abso/config.json`);\n \tconst reader = bool(args, \"reader\");\n-\tconst server = serverFrom(args, env);\n-\tconst box = readBox(server);\n-\tconst hasKey = existsSync(join(stateDir(root), \"key\"));\n-\tconst credential = tokenCredential(args, env.env, server, root);\n+\t// A local project: no box, key or credential, and the agent is --agent or this computer's name.\n+\tconst local = localFrom(args, env, \"join\");\n+\tconst server = local ? LOCAL : serverFrom(args, env);\n+\tconst box = local ? undefined : readBox(server);\n+\tconst hasKey = !local && existsSync(join(stateDir(root), \"key\"));\n+\tconst credential = local ? undefined : tokenCredential(args, env.env, server, root);\n \tconst tokenFileAsked = bool(args, \"token-file\");\n \tlet agent: string;\n \tlet minted: { key: string; id: string } | undefined;\n-\tif (str(args, \"agent\") !== undefined) {\n+\tif (local) agent = agentFrom(args, str(args, \"agent\") ?? defaultAgentName());\n+\telse if (str(args, \"agent\") !== undefined) {\n \t\tagent = agentFrom(args);\n \t\tminted =\n \t\t\tbox && !hasKey && !fromEnv(env.env, \"KEY_FILE\") && !tokenFileAsked\n@@ -412,7 +467,7 @@\n \t\tagent = free.agent;\n \t\tminted = { key: free.key, id: free.id };\n \t}\n-\tconst config = { server, project, agent, ...(reader ? { reader: true } : {}) };\n+\tconst config = { server, project, agent, ...(reader ? { reader: true } : {}), ...local?.settings };\n \twriteConfig(root, config);\n \tclearKnown(root);\n \tif (minted) installKey(root, JSON.stringify(minted));\n@@ -425,10 +480,11 @@\n \t\tthrow error;\n \t}\n \tconst settings = tokenFileAsked ? { ...read, token: credential?.token } : read;\n-\t(env.writeErr ?? env.write)(\n-\t\t`Signing in with ${minted && box ? `a new key from this box's sign-in, ${box.id}` : hasKey ? \"this folder's key\" : (credential?.words ?? `no credential: nothing here signs in to ${server}`)}.\n+\tif (!local)\n+\t\t(env.writeErr ?? env.write)(\n+\t\t\t`Signing in with ${minted && box ? `a new key from this box's sign-in, ${box.id}` : hasKey ? \"this folder's key\" : (credential?.words ?? `no credential: nothing here signs in to ${server}`)}.\n `,\n-\t);\n+\t\t);\n \tconst api = new Api(settings);\n \tlet answer: SyncAnswer;\n \ttry {\n@@ -454,9 +510,10 @@\n \t\t\t\t\t\t`These files were already here and differ from shared, so they were left alone: ${synced.kept.join(\", \")}. abso record sends them as your changes.`,\n \t\t\t\t\t]\n \t\t\t\t: []),\n+\t\t\t...(local ? [localText(local.dir, project)] : []),\n \t\t\t...emptyHint(synced.version, synced.written.length, synced.kept.length, reader),\n \t\t\t...setupHint(root),\n-\t\t\thookHint(env.env),\n+\t\t\thookHint(env.env, local !== undefined),\n \t\t\t...(root === resolve(env.cwd) ? [] : [`cd ${relative(env.cwd, root) || root}`]),\n \t\t].join(\"\\n\"),\n \t\tjson: {\n@@ -480,7 +537,9 @@\n \t\t: [`Nothing is installed yet. Before building or testing here, run ${projectFileName(root)}'s setup: ${setup}`];\n }\n \n-function hookHint(env: Readonly<Record<string, string | undefined>>): string {\n+function hookHint(env: Readonly<Record<string, string | undefined>>, local = false): string {\n+\t// The mod sends each edit to the folder's server itself, and a local project has none.\n+\tif (local) return \"abso record sends the edits made here: the abso mod doesn't record local projects yet.\";\n \tif (modInstalled(env))\n \t\treturn \"Edits made by Claude Code here are recorded by the abso mod on this machine, signed in as this folder. Anything else: abso record.\";\n \t// A built copy (the npm package) has no installer to point at (abso-core 18)."},{"path":"client/src/local-server.d.mts","added":3,"removed":0,"diff":"--- /dev/null\n+++ b/client/src/local-server.d.mts\n@@ -0,0 +1,3 @@\n+// The types of local-server.mjs: as much of the open server as the client calls.\n+export declare function handle(request: Request, env: unknown, ctx: unknown, issues: unknown): Promise<Response>;\n+export declare const ProjectObject: new (ctx: unknown, env: unknown) => object;"},{"path":"client/src/local-server.mjs","added":6,"removed":0,"diff":"--- /dev/null\n+++ b/client/src/local-server.mjs\n@@ -0,0 +1,6 @@\n+// The open server's router and project object, for local projects (local-store.ts). Plain JS, with its types in\n+// local-server.d.mts, so the client's typecheck stops here: server/src is typechecked with the Workers' types\n+// (server/tsconfig.json). The build and Node follow these imports as usual.\n+\n+export { ProjectObject } from \"../../server/src/project-object.ts\";\n+export { handle } from \"../../server/src/router.ts\";"},{"path":"client/src/local-store.ts","added":360,"removed":0,"diff":"--- /dev/null\n+++ b/client/src/local-store.ts\n@@ -0,0 +1,360 @@\n+// Local projects (abso init --local): the open server's own router and project object (server/src) run in this\n+// process, over Node's SQLite, so a project needs no server, account or network. Each project is one SQLite file in a\n+// store folder. Every call runs in one SQLite write transaction, which is the store's lock: another process's call\n+// waits for it, and a process that dies mid-call leaves nothing half-written.\n+\n+import { existsSync, mkdirSync } from \"node:fs\";\n+import { homedir } from \"node:os\";\n+import { join, resolve } from \"node:path\";\n+import { deserialize, serialize } from \"node:v8\";\n+import { UsageError } from \"./args.ts\";\n+import { fromEnv } from \"./env-names.ts\";\n+\n+/** The server a local folder's config names. */\n+export const LOCAL = \"local\";\n+/** The address the client's calls use for a local project; they never leave this process. */\n+export const LOCAL_BASE = \"http://local.abso.invalid\";\n+/** The shared token the in-process server is given, and that its calls carry. Not a secret: nothing listens. */\n+const LOCAL_TOKEN = \"local-store\";\n+\n+export const isLocal = (server: string | undefined): boolean => server === LOCAL;\n+\n+type EnvMap = Readonly<Record<string, string | undefined>>;\n+\n+/**\n+ * Where local projects live: the folder's own store (--store, kept in its config), else ABSO_STORE, else the OS's\n+ * per-user data folder. Undefined when there is none to use (no data folder and nothing named), so nothing assumes a\n+ * writable home folder.\n+ */\n+export function storeDir(env: EnvMap, configured?: string, cwd = process.cwd()): string | undefined {\n+\tif (configured) return resolve(cwd, configured);\n+\tconst named = fromEnv(env, \"STORE\");\n+\tif (named) return resolve(cwd, named);\n+\tconst data =\n+\t\tprocess.platform === \"win32\"\n+\t\t\t? env.LOCALAPPDATA\n+\t\t\t: process.platform === \"darwin\"\n+\t\t\t\t? env.HOME && join(env.HOME, \"Library\", \"Application Support\")\n+\t\t\t\t: env.XDG_DATA_HOME || (env.HOME ? join(env.HOME, \".local\", \"share\") : undefined);\n+\tif (data) return join(data, \"abso\", \"store\");\n+\ttry {\n+\t\tconst home = homedir();\n+\t\treturn home ? join(home, \".local\", \"share\", \"abso\", \"store\") : undefined;\n+\t} catch {\n+\t\treturn undefined;\n+\t}\n+}\n+\n+export const NO_STORE =\n+\t\"there's no folder for local projects here: set ABSO_STORE to one, or give abso init --local a --store <folder>\";\n+\n+// --- The Workers runtime's parts the server uses, over node:sqlite -----------------------------------------------\n+\n+interface Db {\n+\texec(sql: string): void;\n+\tprepare(sql: string): {\n+\t\tall(...args: unknown[]): unknown[];\n+\t\trun(...args: unknown[]): unknown;\n+\t\tget(...args: unknown[]): unknown;\n+\t\tcolumns(): unknown[];\n+\t};\n+\tclose(): void;\n+}\n+\n+/** A Durable Object's storage: SQL, synchronous transactions, the key-value calls and the alarm, on one database. */\n+function storageOver(db: Db) {\n+\tdb.exec(\n+\t\t\"CREATE TABLE IF NOT EXISTS _local_kv (key TEXT PRIMARY KEY, value BLOB NOT NULL); CREATE TABLE IF NOT EXISTS _local_alarm (id INTEGER PRIMARY KEY CHECK (id = 0), at INTEGER)\",\n+\t);\n+\tconst statements = new Map<string, ReturnType<Db[\"prepare\"]>>();\n+\tconst prepared = (query: string) => {\n+\t\tlet s = statements.get(query);\n+\t\tif (!s) {\n+\t\t\ts = db.prepare(query);\n+\t\t\tstatements.set(query, s);\n+\t\t}\n+\t\treturn s;\n+\t};\n+\t// Workers takes and gives BLOB columns as ArrayBuffers; node:sqlite as Uint8Arrays.\n+\tconst bind = (v: unknown) => (v instanceof ArrayBuffer ? new Uint8Array(v) : v);\n+\tconst out = (v: unknown) => (v instanceof Uint8Array ? v.buffer.slice(v.byteOffset, v.byteOffset + v.byteLength) : v);\n+\tlet depth = 0;\n+\tconst kvGet = (key: string) => {\n+\t\tconst row = prepared(\"SELECT value FROM _local_kv WHERE key = ?\").get(key) as { value: Uint8Array } | undefined;\n+\t\treturn row ? deserialize(row.value) : undefined;\n+\t};\n+\tconst kvPut = (key: string, value: unknown) =>\n+\t\tprepared(\n+\t\t\t\"INSERT INTO _local_kv (key, value) VALUES (?, ?) ON CONFLICT (key) DO UPDATE SET value = excluded.value\",\n+\t\t).run(key, serialize(value));\n+\tconst kvDelete = (key: string) =>\n+\t\t(prepared(\"DELETE FROM _local_kv WHERE key = ?\").run(key) as { changes: number | bigint }).changes > 0;\n+\tconst storage = {\n+\t\tsql: {\n+\t\t\texec(query: string, ...bindings: unknown[]) {\n+\t\t\t\tconst statement = prepared(query);\n+\t\t\t\tconst args = bindings.map(bind);\n+\t\t\t\tconst rows = statement.columns().length > 0 ? statement.all(...args) : (statement.run(...args), []);\n+\t\t\t\treturn {\n+\t\t\t\t\ttoArray: () =>\n+\t\t\t\t\t\t(rows as Record<string, unknown>[]).map((r) =>\n+\t\t\t\t\t\t\tObject.fromEntries(Object.entries(r).map(([k, v]) => [k, out(v)])),\n+\t\t\t\t\t\t),\n+\t\t\t\t};\n+\t\t\t},\n+\t\t},\n+\t\ttransactionSync<T>(fn: () => T): T {\n+\t\t\tconst name = `local_t${depth++}`;\n+\t\t\tdb.exec(`SAVEPOINT ${name}`);\n+\t\t\ttry {\n+\t\t\t\tconst value = fn();\n+\t\t\t\tdb.exec(`RELEASE ${name}`);\n+\t\t\t\treturn value;\n+\t\t\t} catch (e) {\n+\t\t\t\tdb.exec(`ROLLBACK TO ${name}; RELEASE ${name}`);\n+\t\t\t\tthrow e;\n+\t\t\t} finally {\n+\t\t\t\tdepth--;\n+\t\t\t}\n+\t\t},\n+\t\tasync transaction<T>(fn: (txn: unknown) => Promise<T>): Promise<T> {\n+\t\t\treturn fn(storage);\n+\t\t},\n+\t\tasync get(key: string | string[]) {\n+\t\t\tif (typeof key === \"string\") return kvGet(key);\n+\t\t\treturn new Map(key.flatMap((k) => (kvGet(k) === undefined ? [] : [[k, kvGet(k)] as const])));\n+\t\t},\n+\t\tasync put(key: string | Record<string, unknown>, value?: unknown) {\n+\t\t\tif (typeof key === \"string\") kvPut(key, value);\n+\t\t\telse for (const [k, v] of Object.entries(key)) kvPut(k, v);\n+\t\t},\n+\t\tasync delete(key: string | string[]) {\n+\t\t\tif (typeof key === \"string\") return kvDelete(key);\n+\t\t\treturn key.filter(kvDelete).length;\n+\t\t},\n+\t\tasync list(options: { prefix?: string } = {}) {\n+\t\t\tconst rows = prepared(\"SELECT key, value FROM _local_kv WHERE key >= ? ORDER BY key\").all(\n+\t\t\t\toptions.prefix ?? \"\",\n+\t\t\t) as { key: string; value: Uint8Array }[];\n+\t\t\treturn new Map(\n+\t\t\t\trows.filter((r) => r.key.startsWith(options.prefix ?? \"\")).map((r) => [r.key, deserialize(r.value)]),\n+\t\t\t);\n+\t\t},\n+\t\t// The alarm is kept, but nothing in a local project needs it: it pushes out to Artifacts, which is off here.\n+\t\tasync getAlarm() {\n+\t\t\tconst row = prepared(\"SELECT at FROM _local_alarm WHERE id = 0\").get() as { at: number | null } | undefined;\n+\t\t\treturn row?.at ?? null;\n+\t\t},\n+\t\tasync setAlarm(at: number | Date) {\n+\t\t\tprepared(\"INSERT INTO _local_alarm (id, at) VALUES (0, ?) ON CONFLICT (id) DO UPDATE SET at = excluded.at\").run(\n+\t\t\t\tNumber(at),\n+\t\t\t);\n+\t\t},\n+\t\tasync deleteAlarm() {\n+\t\t\tprepared(\"DELETE FROM _local_alarm WHERE id = 0\").run();\n+\t\t},\n+\t};\n+\treturn storage;\n+}\n+\n+/** Workers' crypto.DigestStream, which the blob store hashes uploads with. */\n+async function installDigestStream(): Promise<void> {\n+\tconst c = globalThis.crypto as unknown as { DigestStream?: unknown };\n+\tif (c.DigestStream) return;\n+\tconst { createHash } = await import(\"node:crypto\");\n+\tclass DigestStream extends WritableStream<Uint8Array> {\n+\t\treadonly digest: Promise<ArrayBuffer>;\n+\t\tconstructor(algorithm: string) {\n+\t\t\tconst hash = createHash(algorithm.replace(\"-\", \"\").toLowerCase());\n+\t\t\tlet done!: (b: ArrayBuffer) => void;\n+\t\t\tconst digest = new Promise<ArrayBuffer>((ok) => {\n+\t\t\t\tdone = ok;\n+\t\t\t});\n+\t\t\tsuper({\n+\t\t\t\twrite: (chunk) => void hash.update(chunk),\n+\t\t\t\tclose: () => {\n+\t\t\t\t\tconst b = hash.digest();\n+\t\t\t\t\tdone(b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength) as ArrayBuffer);\n+\t\t\t\t},\n+\t\t\t});\n+\t\t\tthis.digest = digest;\n+\t\t}\n+\t}\n+\tc.DigestStream = DigestStream;\n+}\n+\n+// --- Loading the server's code ------------------------------------------------------------------------------------\n+\n+type Server = {\n+\tDatabaseSync: new (path: string) => Db;\n+\thandle: (request: Request, env: unknown, ctx: unknown, issues: unknown) => Promise<Response>;\n+\tProjectObject: new (ctx: unknown, env: unknown) => object;\n+};\n+let server: Promise<Server> | undefined;\n+\n+/** Node's SQLite says it's experimental on every start; that line would land in every local command's output. */\n+function quietSqliteWarning(): void {\n+\tconst emit = process.emitWarning;\n+\tif ((emit as { quiet?: boolean }).quiet) return;\n+\tconst quiet = ((warning: string | Error, ...rest: unknown[]) => {\n+\t\tconst text = typeof warning === \"string\" ? warning : warning.message;\n+\t\tif (text.startsWith(\"SQLite is an experimental feature\")) return;\n+\t\treturn (emit as (...a: unknown[]) => void).call(process, warning, ...rest);\n+\t}) as typeof process.emitWarning;\n+\t(quiet as unknown as { quiet: boolean }).quiet = true;\n+\tprocess.emitWarning = quiet;\n+}\n+\n+export const NODE_TOO_OLD = `local projects need Node 22.13 or later, for its built-in SQLite; this is Node ${process.versions.node}`;\n+\n+function loadServer(): Promise<Server> {\n+\tserver ??= (async () => {\n+\t\tquietSqliteWarning();\n+\t\tlet sqlite: { DatabaseSync: Server[\"DatabaseSync\"] };\n+\t\ttry {\n+\t\t\tsqlite = (await import(\"node:sqlite\")) as unknown as typeof sqlite;\n+\t\t} catch {\n+\t\t\tthrow new LocalError(NODE_TOO_OLD);\n+\t\t}\n+\t\tawait installDigestStream();\n+\t\t// Run as .ts files, the server's `import { DurableObject } from \"cloudflare:workers\"` needs a stand-in. A built\n+\t\t// copy has it already: the build points the import at the same file (scripts/build-client.mjs).\n+\t\tconst standIn = new URL(\"./durable-object-stand-in.ts\", import.meta.url).href;\n+\t\tconst mod = (await import(\"node:module\")) as unknown as {\n+\t\t\tregisterHooks?: (hooks: unknown) => { deregister(): void };\n+\t\t};\n+\t\tconst hooks = mod.registerHooks?.({\n+\t\t\tresolve(specifier: string, context: unknown, next: (s: string, c: unknown) => unknown) {\n+\t\t\t\tif (specifier === \"cloudflare:workers\") return { url: standIn, shortCircuit: true };\n+\t\t\t\treturn next(specifier, context);\n+\t\t\t},\n+\t\t});\n+\t\ttry {\n+\t\t\tconst { handle, ProjectObject } = await import(\"./local-server.mjs\");\n+\t\t\treturn {\n+\t\t\t\tDatabaseSync: sqlite.DatabaseSync,\n+\t\t\t\thandle,\n+\t\t\t\tProjectObject,\n+\t\t\t};\n+\t\t} finally {\n+\t\t\thooks?.deregister();\n+\t\t}\n+\t})();\n+\treturn server;\n+}\n+\n+/** What stops a local project from opening at all: said plainly, like a usage error. */\n+export class LocalError extends UsageError {}\n+\n+// --- One store, as a fetch -----------------------------------------------------------------------------------------\n+\n+interface Open {\n+\tdb: Db;\n+\tstorage: ReturnType<typeof storageOver>;\n+\tobject: object | undefined;\n+\t/** PRAGMA data_version when this process last used the project: it changes when another process writes. */\n+\tseen: number | undefined;\n+}\n+\n+/** Every store file this process has open: closed when its command ends (closeLocalStores). */\n+const opened = new Set<Db>();\n+\n+/** Closes every local project this process opened. Its next call opens them again. */\n+export function closeLocalStores(): void {\n+\tfor (const db of opened) {\n+\t\ttry {\n+\t\t\tdb.close();\n+\t\t} catch {}\n+\t}\n+\topened.clear();\n+}\n+\n+const PROJECT_PATH = /^\\/p\\/([^/]+)\\//;\n+const NAME = /^[A-Za-z0-9._-]{1,100}$/;\n+const json = (status: number, body: unknown) => Response.json(body, { status });\n+\n+/**\n+ * The fetch a local folder's calls go through: each call is answered by the open server's router, in this process,\n+ * against the project's SQLite file in `dir`. Only init makes a project's file.\n+ */\n+export function localFetch(dir: string): (input: string, init?: RequestInit) => Promise<Response> {\n+\tconst open = new Map<string, Open>();\n+\tlet opening: Server | undefined;\n+\tconst openProject = (name: string, create: boolean): Open | undefined => {\n+\t\tconst existing = open.get(name);\n+\t\tif (existing && opened.has(existing.db)) return existing;\n+\t\tconst folder = join(dir, name);\n+\t\tconst file = join(folder, \"project.sqlite\");\n+\t\tif (create) mkdirSync(folder, { recursive: true });\n+\t\telse if (!existsSync(file)) return undefined;\n+\t\tconst db = new opening!.DatabaseSync(file);\n+\t\topened.add(db);\n+\t\tdb.exec(\"PRAGMA journal_mode = WAL; PRAGMA busy_timeout = 120000; PRAGMA synchronous = NORMAL\");\n+\t\tconst project = { db, storage: storageOver(db), object: undefined, seen: undefined };\n+\t\topen.set(name, project);\n+\t\treturn project;\n+\t};\n+\tconst env = (name: string) => ({\n+\t\tABSO_TOKEN: LOCAL_TOKEN,\n+\t\tABSO_ARTIFACTS: \"off\",\n+\t\tABSO_DISK_FIRST: \"off\",\n+\t\tPROJECT: {\n+\t\t\tidFromName: (n: string) => n,\n+\t\t\tget: (n: string) => {\n+\t\t\t\tconst p = open.get(n);\n+\t\t\t\tif (!p || n !== name) throw new LocalError(`no local project ${n}`);\n+\t\t\t\tp.object ??= new opening!.ProjectObject(\n+\t\t\t\t\t{ id: { toString: () => n, name: n }, storage: p.storage, waitUntil: () => {} },\n+\t\t\t\t\tenv(name),\n+\t\t\t\t);\n+\t\t\t\treturn p.object;\n+\t\t\t},\n+\t\t},\n+\t\t// Issues, asks and news aren't in local projects yet: a start note's issue hooks find nothing to call.\n+\t\tISSUES_DO: { idFromName: (n: string) => n, get: () => ({}) },\n+\t});\n+\treturn async (input, init = {}) => {\n+\t\tconst s = await loadServer();\n+\t\topening = s;\n+\t\tconst url = new URL(input);\n+\t\tconst match = PROJECT_PATH.exec(url.pathname);\n+\t\tif (!match) return json(404, { error: \"a local store answers only project calls\" });\n+\t\tconst name = decodeURIComponent(match[1]!);\n+\t\tif (!NAME.test(name)) return json(400, { error: \"project names use letters, digits, '.', '_' and '-'\" });\n+\t\tconst p = openProject(name, url.pathname === `/p/${match[1]}/init`);\n+\t\tif (!p) return json(404, { error: `no local project ${name} in ${dir}` });\n+\t\tconst headers = new Headers(init.headers);\n+\t\theaders.set(\"authorization\", `Bearer ${LOCAL_TOKEN}`);\n+\t\tconst request = new Request(url, { ...init, headers });\n+\t\tconst waits: Promise<unknown>[] = [];\n+\t\tp.db.exec(\"BEGIN IMMEDIATE\");\n+\t\ttry {\n+\t\t\tconst version = (p.db.prepare(\"PRAGMA data_version\").get() as { data_version: number }).data_version;\n+\t\t\tif (p.seen !== undefined && version !== p.seen) p.object = undefined;\n+\t\t\tconst response = await s.handle(\n+\t\t\t\trequest,\n+\t\t\t\tenv(name),\n+\t\t\t\t{ waitUntil: (w: Promise<unknown>) => waits.push(w) },\n+\t\t\t\tissuesNone,\n+\t\t\t);\n+\t\t\tawait Promise.allSettled(waits);\n+\t\t\t// The answer is read whole before the write is kept, so a body that fails to arrive keeps nothing either.\n+\t\t\tconst body = await response.arrayBuffer();\n+\t\t\tp.db.exec(\"COMMIT\");\n+\t\t\tp.seen = (p.db.prepare(\"PRAGMA data_version\").get() as { data_version: number }).data_version;\n+\t\t\treturn new Response(body, { status: response.status, headers: response.headers });\n+\t\t} catch (e) {\n+\t\t\ttry {\n+\t\t\t\tp.db.exec(\"ROLLBACK\");\n+\t\t\t} catch {}\n+\t\t\t// What the object held in memory may be from the rolled-back call.\n+\t\t\tp.object = undefined;\n+\t\t\tp.seen = undefined;\n+\t\t\tif (e instanceof LocalError) throw e;\n+\t\t\t// Where the Workers runtime answers a throw with a 500, so does this.\n+\t\t\treturn json(500, { error: e instanceof Error ? e.message : String(e) });\n+\t\t}\n+\t};\n+}\n+\n+const issuesNone = async () => json(404, { error: \"issues, asks and news aren't in local projects yet\" });"},{"path":"client/src/main.ts","added":26,"removed":5,"diff":"--- a/client/src/main.ts\n+++ b/client/src/main.ts\n@@ -59,6 +59,7 @@\n \trunWaiting,\n } from \"./issues.ts\";\n import { adminToken, adminTokenWords, issuedPublic, keyList, keyListText, keyNew, keyRevoke } from \"./key-admin.ts\";\n+import { closeLocalStores } from \"./local-store.ts\";\n import { browserSkip, openInBrowser } from \"./open-browser.ts\";\n import { runOrg, runOrgs } from \"./orgs.ts\";\n import { runUnqueue } from \"./queue.ts\";\n@@ -121,11 +122,13 @@\n \t\t\tpublic: \"boolean\",\n \t\t\tprivate: \"boolean\",\n \t\t\t\"token-file\": \"boolean\",\n+\t\t\tlocal: \"boolean\",\n+\t\t\tstore: \"string\",\n \t\t},\n \t\tusage:\n-\t\t\t\"abso init [folder] --project <name> [--agent <name>] [--as-is] [--org <org>] [--public|--private] [--token-file]\",\n+\t\t\t\"abso init [folder] --project <name> [--agent <name>] [--as-is] [--org <org>] [--public|--private] [--token-file] | abso init [folder] --local --project <name> [--agent <name>] [--store <folder>] [--as-is]\",\n \t\tabout:\n-\t\t\t\"Create a project on the server from a folder's text files. The folder becomes that agent's folder. It writes a starting .absoignore, and, when the folder has no abso.json and package.json gives a check or a build to guess, an abso.json (setup, check, build and out): what the server's CI runs on each new version of shared. Without one, CI runs what it can guess itself, or nothing. --as-is writes neither: the folder goes up exactly as it is (an import). On a server this box is signed in to (abso login, approving all your projects), the project is made as you, the way the website's New project makes it: you own it, it's private unless you say --public, and the folder joins it at once with its own key (--agent names it; else the box's name). --org <org> makes it that organization's project. Elsewhere it needs --agent and a token: ABSO_TOKEN, or with --token-file this machine's ~/.abso/token, which is never used unasked. Before it makes anything, it says what it signs in with.\",\n+\t\t\t\"Create a project on the server from a folder's text files. The folder becomes that agent's folder. It writes a starting .absoignore, and, when the folder has no abso.json and package.json gives a check or a build to guess, an abso.json (setup, check, build and out): what the server's CI runs on each new version of shared. Without one, CI runs what it can guess itself, or nothing. --as-is writes neither: the folder goes up exactly as it is (an import). On a server this box is signed in to (abso login, approving all your projects), the project is made as you, the way the website's New project makes it: you own it, it's private unless you say --public, and the folder joins it at once with its own key (--agent names it; else the box's name). --org <org> makes it that organization's project. Elsewhere it needs --agent and a token: ABSO_TOKEN, or with --token-file this machine's ~/.abso/token, which is never used unasked. Before it makes anything, it says what it signs in with. --local makes a local project instead: its history is kept on this machine, in a store folder, and no server, sign-in or network is needed (Node 22.13 or later). The store is --store <folder> (kept in the folder's settings; inside the folder, .absoignore leaves it out), else ABSO_STORE, else this user's data folder (%LOCALAPPDATA%\\\\abso\\\\store, ~/Library/Application Support/abso/store, or $XDG_DATA_HOME/abso/store). The agent is --agent, else this computer's name.\",\n \t\trun: (args, env) => runInit(args, env),\n \t},\n \tkey: {\n@@ -327,10 +330,19 @@\n \t\t},\n \t},\n \tjoin: {\n-\t\tflags: { server: \"string\", agent: \"string\", dir: \"string\", reader: \"boolean\", \"token-file\": \"boolean\" },\n-\t\tusage: \"abso join <project> [--agent <name>] [--dir <folder>] [--reader] [--token-file]\",\n+\t\tflags: {\n+\t\t\tserver: \"string\",\n+\t\t\tagent: \"string\",\n+\t\t\tdir: \"string\",\n+\t\t\treader: \"boolean\",\n+\t\t\t\"token-file\": \"boolean\",\n+\t\t\tlocal: \"boolean\",\n+\t\t\tstore: \"string\",\n+\t\t},\n+\t\tusage:\n+\t\t\t\"abso join <project> [--agent <name>] [--dir <folder>] [--reader] [--token-file] | abso join <project> --local [--agent <name>] [--store <folder>] [--dir <folder>]\",\n \t\tabout:\n-\t\t\t\"Join a project as a new agent and write its shared files into a folder: --dir, else here when this folder is empty, else ./<project> (which has to be new or empty). Without --agent the agent is named after this box (the name abso login gave it, lower-cased), or the next free <name>-2, <name>-3; that needs the box signed in with abso login. --reader joins as a reader: it reads everything and records nothing, and the server refuses its edits, records and pushes. With --reader and no sign-in, a public project is joined to read signed out: the folder holds only its settings, sends no sign-in, and runs status, log, show, files, blame, why, where, issues, issue and search; every other command is refused. It says what it signs in with: a new key from this box's sign-in, the folder's key, or ABSO_TOKEN; this machine's ~/.abso/token only with --token-file, never unasked.\",\n+\t\t\t\"Join a project as a new agent and write its shared files into a folder: --dir, else here when this folder is empty, else ./<project> (which has to be new or empty). Without --agent the agent is named after this box (the name abso login gave it, lower-cased), or the next free <name>-2, <name>-3; that needs the box signed in with abso login. --reader joins as a reader: it reads everything and records nothing, and the server refuses its edits, records and pushes. With --reader and no sign-in, a public project is joined to read signed out: the folder holds only its settings, sends no sign-in, and runs status, log, show, files, blame, why, where, issues, issue and search; every other command is refused. It says what it signs in with: a new key from this box's sign-in, the folder's key, or ABSO_TOKEN; this machine's ~/.abso/token only with --token-file, never unasked. --local joins a local project (abso init --local) from the same store: --store, else ABSO_STORE, else this user's data folder; the agent is --agent, else this computer's name.\",\n \t\trun: runJoin,\n \t},\n \trecord: {\n@@ -989,6 +1001,15 @@\n }\n \n export async function main(argv: readonly string[], env: Env): Promise<MainResult> {\n+\ttry {\n+\t\treturn await runMain(argv, env);\n+\t} finally {\n+\t\t// A local project's store stays open only while its command runs.\n+\t\tcloseLocalStores();\n+\t}\n+}\n+\n+async function runMain(argv: readonly string[], env: Env): Promise<MainResult> {\n \tconst command = argv[0];\n \tconst json = argv.includes(\"--json\") && command !== \"run\" && command !== \"logs\";\n \tconst asked = argv.includes(\"--token-file\");"},{"path":"client/test/local.test.ts","added":140,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/local.test.ts\n@@ -0,0 +1,140 @@\n+// Local projects (abso init --local): a project whose history is in a store on this machine, answered by the open\n+// server's own code in the client's process. Every test here runs with fetch replaced by one that throws, so any\n+// call that would leave the machine fails the test.\n+\n+import assert from \"node:assert/strict\";\n+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\n+import { tmpdir } from \"node:os\";\n+import { join } from \"node:path\";\n+import { after, before, describe, it } from \"node:test\";\n+import { main } from \"../src/main.ts\";\n+import { stateDir } from \"../src/state-dir.ts\";\n+\n+const dirs: string[] = [];\n+const temp = (label: string) => {\n+\tconst d = mkdtempSync(join(tmpdir(), `abso-local-${label}-`));\n+\tdirs.push(d);\n+\treturn d;\n+};\n+\n+const outside: string[] = [];\n+const realFetch = globalThis.fetch;\n+before(() => {\n+\tglobalThis.fetch = (async (input: unknown) => {\n+\t\toutside.push(String(input instanceof Request ? input.url : input));\n+\t\tthrow new TypeError(\"network is off in this test\");\n+\t}) as typeof fetch;\n+});\n+after(() => {\n+\tglobalThis.fetch = realFetch;\n+\tfor (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 });\n+\tassert.deepEqual(outside, [], \"nothing reached for the network\");\n+});\n+\n+let store: string;\n+const env = () => ({ ABSO_STORE: store, ABSO_SERVERS_FILE: \"no-servers.json\", ABSO_HOOK_FORCE: \"1\" });\n+async function run(cwd: string, ...argv: string[]): Promise<{ exit: number; out: string; err: string }> {\n+\tconst r = await main(argv, { cwd, env: env(), write: () => {} });\n+\treturn { exit: r.exit, out: r.stdout, err: r.stderr };\n+}\n+const text = (dir: string, rel: string) => readFileSync(join(dir, rel), \"utf8\");\n+\n+describe(\"a local project, with the network off\", () => {\n+\tlet alice: string;\n+\tlet bob: string;\n+\tbefore(() => {\n+\t\tstore = temp(\"store\");\n+\t});\n+\n+\tit(\"init --local makes the project in the store, with no sign-in\", async () => {\n+\t\talice = temp(\"alice\");\n+\t\twriteFileSync(join(alice, \"a.txt\"), \"one\\ntwo\\nthree\\n\");\n+\t\tconst r = await run(alice, \"init\", \"--local\", \"--project\", \"demo\", \"--agent\", \"alice\");\n+\t\tassert.equal(r.exit, 0, r.out + r.err);\n+\t\tassert.match(r.out, /Created project demo at version 0 from 2 text files/, \"a.txt and the starting .absoignore\");\n+\t\tassert.doesNotMatch(r.out, /CI has nothing to run/);\n+\t\tassert.match(r.out, /It's a local project: its history is in .*demo, on this machine/);\n+\t\tassert.doesNotMatch(r.out + r.err, /Signing in/);\n+\t\tassert.ok(existsSync(join(store, \"demo\", \"project.sqlite\")));\n+\t\tconst config = JSON.parse(readFileSync(join(stateDir(alice), \"config.json\"), \"utf8\"));\n+\t\tassert.equal(config.server, \"local\");\n+\t\tassert.equal(config.store, undefined, \"the store came from ABSO_STORE, so the folder doesn't name it\");\n+\t});\n+\n+\tit(\"record and push make version 1, and log says so\", async () => {\n+\t\twriteFileSync(join(alice, \"a.txt\"), \"one\\nTWO\\nthree\\n\");\n+\t\twriteFileSync(join(alice, \"b.txt\"), \"new\\n\");\n+\t\tassert.equal((await run(alice, \"record\")).exit, 0);\n+\t\tconst pushed = await run(alice, \"push\", \"-m\", \"Change two, add b\");\n+\t\tassert.equal(pushed.exit, 0, pushed.out + pushed.err);\n+\t\tassert.match(pushed.out, /Pushed version 1/);\n+\t\tconst log = await run(alice, \"log\");\n+\t\tassert.equal(log.exit, 0, log.err);\n+\t\tassert.match(log.out, /Change two, add b/);\n+\t});\n+\n+\tit(\"a second folder joins, and pulls what the first pushes\", async () => {\n+\t\tbob = temp(\"bob\");\n+\t\tconst joined = await run(bob, \"join\", \"demo\", \"--local\", \"--agent\", \"bob\", \"--dir\", bob);\n+\t\tassert.equal(joined.exit, 0, joined.out + joined.err);\n+\t\tassert.equal(text(bob, \"a.txt\"), \"one\\nTWO\\nthree\\n\");\n+\t\tassert.equal(text(bob, \"b.txt\"), \"new\\n\");\n+\t\twriteFileSync(join(alice, \"b.txt\"), \"new\\nmore\\n\");\n+\t\tassert.equal((await run(alice, \"push\", \"-m\", \"More in b\")).exit, 0);\n+\t\tconst pulled = await run(bob, \"pull\");\n+\t\tassert.equal(pulled.exit, 0, pulled.out + pulled.err);\n+\t\tassert.equal(text(bob, \"b.txt\"), \"new\\nmore\\n\");\n+\t});\n+\n+\tit(\"blame names who wrote each line\", async () => {\n+\t\tconst r = await run(bob, \"blame\", \"a.txt\");\n+\t\tassert.equal(r.exit, 0, r.err);\n+\t\tassert.match(r.out, /alice/);\n+\t\tassert.match(r.out, /TWO/);\n+\t});\n+\n+\tit(\"a push that collides with work pushed since is held\", async () => {\n+\t\tassert.equal((await run(bob, \"pull\")).exit, 0);\n+\t\twriteFileSync(join(alice, \"a.txt\"), \"one\\nalice's\\nthree\\n\");\n+\t\tassert.equal((await run(alice, \"push\", \"-m\", \"Alice's two\")).exit, 0);\n+\t\twriteFileSync(join(bob, \"a.txt\"), \"one\\nbob's\\nthree\\n\");\n+\t\tconst held = await run(bob, \"push\", \"-m\", \"Bob's two\");\n+\t\tassert.notEqual(held.exit, 0);\n+\t\tassert.match(held.out + held.err, /collision/);\n+\t});\n+});\n+\n+describe(\"where a local project's store is\", () => {\n+\tit(\"--store inside the folder is kept in its settings and left out of its files\", async () => {\n+\t\tstore = temp(\"unused\");\n+\t\tconst dir = temp(\"venv\");\n+\t\twriteFileSync(join(dir, \"a.txt\"), \"x\\n\");\n+\t\tconst r = await run(dir, \"init\", \"--local\", \"--project\", \"beside\", \"--agent\", \"a\", \"--store\", \".abso-store\");\n+\t\tassert.equal(r.exit, 0, r.out + r.err);\n+\t\tassert.ok(existsSync(join(dir, \".abso-store\", \"beside\", \"project.sqlite\")));\n+\t\tassert.equal(JSON.parse(readFileSync(join(stateDir(dir), \"config.json\"), \"utf8\")).store, join(dir, \".abso-store\"));\n+\t\tassert.match(text(dir, \".absoignore\"), /^\\/\\.abso-store\\/$/m);\n+\t\tassert.match(r.out, /from 2 text files/, \"a.txt and .absoignore, not the store\");\n+\t\t// Every later command finds the store from the folder's settings, whatever ABSO_STORE says.\n+\t\twriteFileSync(join(dir, \"a.txt\"), \"y\\n\");\n+\t\tassert.equal((await run(dir, \"push\", \"-m\", \"y\")).exit, 0);\n+\t});\n+\n+\tit(\"--local refuses --server, and --store needs --local\", async () => {\n+\t\tconst dir = temp(\"refuse\");\n+\t\tmkdirSync(join(dir, \"x\"));\n+\t\tconst both = await run(dir, \"init\", \"--local\", \"--server\", \"https://abso.test\", \"--project\", \"p\");\n+\t\tassert.match(both.out + both.err, /--local or --server, not both/);\n+\t\tconst alone = await run(dir, \"init\", \"--store\", \"s\", \"--project\", \"p\");\n+\t\tassert.match(alone.out + alone.err, /--store goes with --local/);\n+\t});\n+\n+\tit(\"joining a project the store doesn't have leaves nothing behind\", async () => {\n+\t\tstore = temp(\"empty\");\n+\t\tconst dir = temp(\"nojoin\");\n+\t\tconst r = await run(dir, \"join\", \"nothing\", \"--local\", \"--agent\", \"a\", \"--dir\", dir);\n+\t\tassert.notEqual(r.exit, 0);\n+\t\tassert.match(r.out + r.err, /no local project nothing/);\n+\t\tassert.equal(existsSync(join(dir, \".abso\")) || existsSync(join(dir, \".avcs\")), false);\n+\t});\n+});"},{"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: {"}],"ci":null}