{"file":"server/src/router.ts","version":318,"total":311,"from":1,"to":311,"lines":[{"n":1,"text":"// The open server's router (index.ts is the Worker's entry). abso's open server: one Worker that anyone deploys to their own Cloudflare account (`cd server && npx wrangler","atom":"a1488","author":"speed","version":150},{"n":2,"text":"// deploy`). Every project is a Durable Object named by the project's name; its shared is pushed out to an Artifacts","atom":"a1488","author":"speed","version":150},{"n":3,"text":"// repo abso-<project>. The routes are the platform's core routes, so the stock client works against it:","atom":"a1488","author":"speed","version":150},{"n":4,"text":"//","atom":"a1488","author":"speed","version":150},{"n":5,"text":"//   GET  /version                          the deployed version's tag; no token needed","atom":"a1488","author":"speed","version":150},{"n":6,"text":"//   /p/<project>/<read or init>            init, status, log, show, file, blame, feed and the other reads (http.ts)","atom":"a1488","author":"speed","version":150},{"n":7,"text":"//   /p/<project>/a/<agent>/<op>            an agent's calls: record, publish, sync, draft, land, announce, ...","atom":"a1488","author":"speed","version":150},{"n":8,"text":"//   GET  /p/<project>/head                 shared's newest version, read from storage without loading the project","atom":"a1488","author":"speed","version":150},{"n":9,"text":"//   PUT|GET /p/<project>/blobs/<sha256>    a binary file's bytes; a PUT whose bytes don't hash to the name is refused","atom":"a1488","author":"speed","version":150},{"n":10,"text":"//   GET  /p/<project>/out                  the push out to Artifacts: repo, last version pushed, plain-git intake","atom":"a1488","author":"speed","version":150},{"n":11,"text":"//   POST /p/<project>/git-remote           the repo's remote and a write token good for an hour, for plain git","atom":"a1488","author":"speed","version":150},{"n":12,"text":"//   POST /p/<project>/git-sync             takes in commits pushed with plain git now (the alarm also does)","atom":"a1488","author":"speed","version":150},{"n":13,"text":"//   GET  /p/<project>/export?from=&limit=  the log as JSON lines, for backups","atom":"a1488","author":"speed","version":150},{"n":14,"text":"//   /issues/p/<project>/...                issues, asks and news (issues-entry.ts)","atom":"a1488","author":"speed","version":150},{"n":15,"text":"//   GET|POST /admin/agent-keys?project=    per-agent keys: list, or issue (?agent=&role=&expires=); POST .../revoke?id=","atom":"a1488","author":"speed","version":150},{"n":16,"text":"//","atom":"a1488","author":"speed","version":150},{"n":17,"text":"// Every route but /version needs Authorization: Bearer <ABSO_TOKEN>, or an agent's key when AGENT_KEYS is on. With no","atom":"a1488","author":"speed","version":150},{"n":18,"text":"// ABSO_TOKEN set, the server refuses every call.","atom":"a1488","author":"speed","version":150},{"n":19,"text":"","atom":"a1488","author":"speed","version":150},{"n":20,"text":"import { type Answer, validName } from \"../../worker/project/http.ts\";","atom":"a1488","author":"speed","version":150},{"n":21,"text":"import { withAdvice } from \"./autosettle.ts\";","atom":"a2292","author":"autosettle","version":204},{"n":22,"text":"import { artifactsOf, type Env, secret } from \"./env.ts\";","atom":"a1488","author":"speed","version":150},{"n":23,"text":"import type { IssuesAuth, issuesFetch } from \"./issues-entry.ts\";","atom":"a1488","author":"speed","version":150},{"n":24,"text":"import { isAgentKey, type KeyRole, keyAllows, keysEnabled, timingSame } from \"./keys.ts\";","atom":"a1488","author":"speed","version":150},{"n":25,"text":"import type { KeyForCall } from \"./project-object.ts\";","atom":"a1488","author":"speed","version":150},{"n":26,"text":"import { repoName, writeAccess } from \"./push.ts\";","atom":"a1488","author":"speed","version":150},{"n":27,"text":"","atom":"a1488","author":"speed","version":150},{"n":28,"text":"const AGENT_OPS =","atom":"a1488","author":"speed","version":150},{"n":29,"text":"\t\"edit|record|publish|sync|draft|draft-sync|land|pluck|amend|diff|restore|drop|label|announce|news|note|note-close|move|starting|reader|files|status|unqueue\";","atom":"a1488","author":"speed","version":150},{"n":30,"text":"const TOP_ROUTES =","atom":"a1488","author":"speed","version":150},{"n":31,"text":"\t\"init|status|head|out|export|blobs/[^/]+|git-sync|git-remote|blame|why|tree|path|follow|collisions|draft-state|where|feed|drafts|diff|ribbon|position|changes|notes|change/[0-9]{1,12}|refusals|labels|files|announce|log|show|file|compare|visibility|ci|queue\";","atom":"a1488","author":"speed","version":150},{"n":32,"text":"","atom":"a1488","author":"speed","version":150},{"n":33,"text":"/** A project's routes: the project, the top-level route, and an agent's name and op under /a/. */","atom":"a1488","author":"speed","version":150},{"n":34,"text":"export const PROJECT_ROUTE = new RegExp(`^/p/([^/]+)/(${TOP_ROUTES}|a/([^/]+)/(${AGENT_OPS}))$`);","atom":"a1488","author":"speed","version":150},{"n":35,"text":"/** Issues, asks and news: the project and the rest of the path, handed to the issues code. */","atom":"a1488","author":"speed","version":150},{"n":36,"text":"export const ISSUES_ROUTE = /^\\/issues\\/p\\/([^/]+)(\\/.*)?$/;","atom":"a1488","author":"speed","version":150},{"n":37,"text":"","atom":"a1488","author":"speed","version":150},{"n":38,"text":"/** Routes answered here or by a direct object method, not through the project call. */","atom":"a1488","author":"speed","version":150},{"n":39,"text":"const DIRECT = new Set([\"head\", \"out\", \"export\", \"git-remote\", \"git-sync\", \"ci\", \"queue\", \"visibility\"]);","atom":"a1488","author":"speed","version":150},{"n":40,"text":"/** Reads whose query string is the call's body. */","atom":"a1488","author":"speed","version":150},{"n":41,"text":"const QUERY_READS = new Set([","atom":"a1488","author":"speed","version":150},{"n":42,"text":"\t\"status\",","atom":"a1488","author":"speed","version":150},{"n":43,"text":"\t\"blame\",","atom":"a1488","author":"speed","version":150},{"n":44,"text":"\t\"why\",","atom":"a1488","author":"speed","version":150},{"n":45,"text":"\t\"tree\",","atom":"a1488","author":"speed","version":150},{"n":46,"text":"\t\"path\",","atom":"a1488","author":"speed","version":150},{"n":47,"text":"\t\"follow\",","atom":"a1488","author":"speed","version":150},{"n":48,"text":"\t\"collisions\",","atom":"a1488","author":"speed","version":150},{"n":49,"text":"\t\"draft-state\",","atom":"a1488","author":"speed","version":150},{"n":50,"text":"\t\"refusals\",","atom":"a1488","author":"speed","version":150},{"n":51,"text":"\t\"labels\",","atom":"a1488","author":"speed","version":150},{"n":52,"text":"\t\"log\",","atom":"a1488","author":"speed","version":150},{"n":53,"text":"\t\"show\",","atom":"a1488","author":"speed","version":150},{"n":54,"text":"\t\"file\",","atom":"a1488","author":"speed","version":150},{"n":55,"text":"\t\"files\",","atom":"a1488","author":"speed","version":150},{"n":56,"text":"\t\"compare\",","atom":"a1488","author":"speed","version":150},{"n":57,"text":"\t\"without\",","atom":"a2083","author":"candidates","version":186},{"n":58,"text":"\t\"where\",","atom":"a1488","author":"speed","version":150},{"n":59,"text":"\t\"feed\",","atom":"a1488","author":"speed","version":150},{"n":60,"text":"\t\"drafts\",","atom":"a1488","author":"speed","version":150},{"n":61,"text":"\t\"diff\",","atom":"a1488","author":"speed","version":150},{"n":62,"text":"\t\"ribbon\",","atom":"a1488","author":"speed","version":150},{"n":63,"text":"\t\"position\",","atom":"a1488","author":"speed","version":150},{"n":64,"text":"\t\"changes\",","atom":"a1488","author":"speed","version":150},{"n":65,"text":"\t\"notes\",","atom":"a1488","author":"speed","version":150},{"n":66,"text":"]);","atom":"a1488","author":"speed","version":150},{"n":67,"text":"const SHA = /^[0-9a-f]{64}$/;","atom":"a1488","author":"speed","version":150},{"n":68,"text":"","atom":"a1488","author":"speed","version":150},{"n":69,"text":"const json = (status: number, body: unknown) =>","atom":"a1488","author":"speed","version":150},{"n":70,"text":"\tResponse.json(body, { status, headers: { \"cache-control\": \"no-store\" } });","atom":"a1488","author":"speed","version":150},{"n":71,"text":"","atom":"a1488","author":"speed","version":150},{"n":72,"text":"/** Whether two secrets match, in constant time whatever their lengths: their SHA-256 digests are compared. */","atom":"a1488","author":"speed","version":150},{"n":73,"text":"export async function sameSecret(a: string, b: string): Promise<boolean> {","atom":"a1488","author":"speed","version":150},{"n":74,"text":"\tconst digest = async (s: string) =>","atom":"a1488","author":"speed","version":150},{"n":75,"text":"\t\t[...new Uint8Array(await crypto.subtle.digest(\"SHA-256\", new TextEncoder().encode(s)))]","atom":"a1488","author":"speed","version":150},{"n":76,"text":"\t\t\t.map((n) => n.toString(16).padStart(2, \"0\"))","atom":"a1488","author":"speed","version":150},{"n":77,"text":"\t\t\t.join(\"\");","atom":"a1488","author":"speed","version":150},{"n":78,"text":"\treturn timingSame(await digest(a), await digest(b));","atom":"a1488","author":"speed","version":150},{"n":79,"text":"}","atom":"a1488","author":"speed","version":150},{"n":80,"text":"","atom":"a1488","author":"speed","version":150},{"n":81,"text":"export type Caller = { kind: \"token\" } | { kind: \"key\"; presented: string };","atom":"a1488","author":"speed","version":150},{"n":82,"text":"","atom":"a1488","author":"speed","version":150},{"n":83,"text":"/**","atom":"a1488","author":"speed","version":150},{"n":84,"text":" * Who is calling: the shared token, or an agent key to be checked by its project. A Response is a refusal. With no","atom":"a1488","author":"speed","version":150},{"n":85,"text":" * shared token set, everything is refused.","atom":"a1488","author":"speed","version":150},{"n":86,"text":" */","atom":"a1488","author":"speed","version":150},{"n":87,"text":"export async function authorize(request: Request, env: Env): Promise<Caller | Response> {","atom":"a1488","author":"speed","version":150},{"n":88,"text":"\tconst shared = secret(env, \"TOKEN\");","atom":"a1488","author":"speed","version":150},{"n":89,"text":"\tif (!shared)","atom":"a1488","author":"speed","version":150},{"n":90,"text":"\t\treturn json(503, {","atom":"a1488","author":"speed","version":150},{"n":91,"text":"\t\t\terror:","atom":"a1488","author":"speed","version":150},{"n":92,"text":"\t\t\t\t\"this server has no ABSO_TOKEN set, so it refuses every call; set one with npx wrangler secret put ABSO_TOKEN\",","atom":"a1488","author":"speed","version":150},{"n":93,"text":"\t\t});","atom":"a1488","author":"speed","version":150},{"n":94,"text":"\tconst presented = (request.headers.get(\"authorization\") ?? \"\").replace(/^Bearer /, \"\");","atom":"a1488","author":"speed","version":150},{"n":95,"text":"\tif (presented && isAgentKey(presented) && keysEnabled(env)) return { kind: \"key\", presented };","atom":"a1488","author":"speed","version":150},{"n":96,"text":"\tif (presented && (await sameSecret(presented, shared))) return { kind: \"token\" };","atom":"a1488","author":"speed","version":150},{"n":97,"text":"\treturn json(401, { error: \"missing or wrong token\" });","atom":"a1488","author":"speed","version":150},{"n":98,"text":"}","atom":"a1488","author":"speed","version":150},{"n":99,"text":"","atom":"a1488","author":"speed","version":150},{"n":100,"text":"/** The x-abso-admin header against ABSO_ADMIN_TOKEN, in constant time. */","atom":"a1488","author":"speed","version":150},{"n":101,"text":"async function isAdmin(request: Request, env: Env): Promise<boolean> {","atom":"a1488","author":"speed","version":150},{"n":102,"text":"\tconst token = secret(env, \"ADMIN_TOKEN\");","atom":"a1488","author":"speed","version":150},{"n":103,"text":"\tconst sent = request.headers.get(\"x-abso-admin\") ?? request.headers.get(\"x-avcs-admin\");","atom":"a1488","author":"speed","version":150},{"n":104,"text":"\treturn !!token && !!sent && (await sameSecret(sent, token));","atom":"a1488","author":"speed","version":150},{"n":105,"text":"}","atom":"a1488","author":"speed","version":150},{"n":106,"text":"","atom":"a1488","author":"speed","version":150},{"n":107,"text":"const addressOf = (request: Request) => request.headers.get(\"cf-connecting-ip\") ?? \"unknown\";","atom":"a1488","author":"speed","version":150},{"n":108,"text":"const projectObject = (env: Env, project: string) => env.PROJECT.get(env.PROJECT.idFromName(project));","atom":"a1488","author":"speed","version":150},{"n":109,"text":"","atom":"a1488","author":"speed","version":150},{"n":110,"text":"/** Per-agent keys for one project: list (GET), issue (POST ?agent=&role=&expires=), revoke (POST .../revoke?id=). */","atom":"a1488","author":"speed","version":150},{"n":111,"text":"async function agentKeys(request: Request, env: Env, url: URL, caller: Caller): Promise<Response> {","atom":"a1488","author":"speed","version":150},{"n":112,"text":"\tif (!keysEnabled(env))","atom":"a1488","author":"speed","version":150},{"n":113,"text":"\t\treturn json(404, { error: \"agent keys are off here: AGENT_KEYS=on and KEY_HMAC_SECRET turn them on\" });","atom":"a1488","author":"speed","version":150},{"n":114,"text":"\tif (caller.kind !== \"token\") return json(401, { error: \"missing or wrong token\" });","atom":"a1488","author":"speed","version":150},{"n":115,"text":"\tif (!(await isAdmin(request, env))) return json(403, { error: \"agent keys need x-abso-admin: <the admin token>\" });","atom":"a1488","author":"speed","version":150},{"n":116,"text":"\tconst project = url.searchParams.get(\"project\") ?? \"\";","atom":"a1488","author":"speed","version":150},{"n":117,"text":"\tif (!validName(project)) return json(400, { error: \"agent keys need ?project=<name>\" });","atom":"a1488","author":"speed","version":150},{"n":118,"text":"\tconst obj = projectObject(env, project);","atom":"a1488","author":"speed","version":150},{"n":119,"text":"\tif (url.pathname === \"/admin/agent-keys/revoke\") {","atom":"a1488","author":"speed","version":150},{"n":120,"text":"\t\tif (request.method !== \"POST\") return json(405, { error: \"revoking a key is a POST\" });","atom":"a1488","author":"speed","version":150},{"n":121,"text":"\t\treturn json(200, await obj.revokeAgentKey(url.searchParams.get(\"id\") ?? \"\", addressOf(request)));","atom":"a1488","author":"speed","version":150},{"n":122,"text":"\t}","atom":"a1488","author":"speed","version":150},{"n":123,"text":"\tif (request.method === \"GET\")","atom":"a1488","author":"speed","version":150},{"n":124,"text":"\t\treturn json(200, { keys: await obj.listAgentKeys(url.searchParams.get(\"agent\") ?? undefined) });","atom":"a1488","author":"speed","version":150},{"n":125,"text":"\tif (request.method !== \"POST\") return json(405, { error: \"agent keys take GET or POST\" });","atom":"a1488","author":"speed","version":150},{"n":126,"text":"\tconst agent = url.searchParams.get(\"agent\") ?? \"\";","atom":"a1488","author":"speed","version":150},{"n":127,"text":"\tif (!validName(agent)) return json(400, { error: \"issuing a key needs ?agent=<name>\" });","atom":"a1488","author":"speed","version":150},{"n":128,"text":"\tconst role = url.searchParams.get(\"role\") ?? \"writer\";","atom":"a1488","author":"speed","version":150},{"n":129,"text":"\tif (role !== \"owner\" && role !== \"writer\" && role !== \"reader\")","atom":"a1488","author":"speed","version":150},{"n":130,"text":"\t\treturn json(400, { error: \"role is owner, writer or reader\" });","atom":"a1488","author":"speed","version":150},{"n":131,"text":"\tconst issued = await obj.issueAgentKey(agent, addressOf(request), url.searchParams.get(\"expires\"), role);","atom":"a1488","author":"speed","version":150},{"n":132,"text":"\treturn \"error\" in issued ? json(400, issued) : json(200, issued);","atom":"a1488","author":"speed","version":150},{"n":133,"text":"}","atom":"a1488","author":"speed","version":150},{"n":134,"text":"","atom":"a1488","author":"speed","version":150},{"n":135,"text":"/** The engine's ci and queue reads, for a server with neither: empty, so status and log say nothing about them. */","atom":"a1488","author":"speed","version":150},{"n":136,"text":"const NO_CI = { latest: null, checked: null, running: null, red: null, behind: null };","atom":"a1488","author":"speed","version":150},{"n":137,"text":"const NO_QUEUE = { items: [], paused: null };","atom":"a1488","author":"speed","version":150},{"n":138,"text":"","atom":"a1488","author":"speed","version":150},{"n":139,"text":"async function projectRoute(","atom":"a1488","author":"speed","version":150},{"n":140,"text":"\trequest: Request,","atom":"a1488","author":"speed","version":150},{"n":141,"text":"\tenv: Env,","atom":"a1488","author":"speed","version":150},{"n":142,"text":"\turl: URL,","atom":"a1488","author":"speed","version":150},{"n":143,"text":"\tcaller: Caller,","atom":"a1488","author":"speed","version":150},{"n":144,"text":"\tmatch: RegExpExecArray,","atom":"a1488","author":"speed","version":150},{"n":145,"text":"): Promise<Response> {","atom":"a1488","author":"speed","version":150},{"n":146,"text":"\tconst [, project, top, agent, op] = match as unknown as [","atom":"a1488","author":"speed","version":150},{"n":147,"text":"\t\tstring,","atom":"a1488","author":"speed","version":150},{"n":148,"text":"\t\tstring,","atom":"a1488","author":"speed","version":150},{"n":149,"text":"\t\tstring,","atom":"a1488","author":"speed","version":150},{"n":150,"text":"\t\tstring | undefined,","atom":"a1488","author":"speed","version":150},{"n":151,"text":"\t\tstring | undefined,","atom":"a1488","author":"speed","version":150},{"n":152,"text":"\t];","atom":"a1488","author":"speed","version":150},{"n":153,"text":"\tif (!validName(project)) return json(400, { error: \"project names use letters, digits, '.', '_' and '-'\" });","atom":"a1488","author":"speed","version":150},{"n":154,"text":"\tconst obj = projectObject(env, project);","atom":"a1488","author":"speed","version":150},{"n":155,"text":"\tconst route = agent === undefined ? top : op;","atom":"a1488","author":"speed","version":150},{"n":156,"text":"\tconst write = request.method !== \"GET\" && request.method !== \"HEAD\";","atom":"a1488","author":"speed","version":150},{"n":157,"text":"\tconst blob = top.startsWith(\"blobs/\");","atom":"a1488","author":"speed","version":150},{"n":158,"text":"\tlet keyForCall: KeyForCall | undefined;","atom":"a1488","author":"speed","version":150},{"n":159,"text":"\tlet how: string | undefined;","atom":"a1488","author":"speed","version":150},{"n":160,"text":"\tif (caller.kind === \"key\") {","atom":"a1488","author":"speed","version":150},{"n":161,"text":"\t\tif (DIRECT.has(top) || blob) {","atom":"a1488","author":"speed","version":150},{"n":162,"text":"\t\t\tconst decided = await obj.checkAgentKey(caller.presented, agent, addressOf(request));","atom":"a1488","author":"speed","version":150},{"n":163,"text":"\t\t\tif (!decided.ok) return json(decided.status, { error: decided.error });","atom":"a1488","author":"speed","version":150},{"n":164,"text":"\t\t\tconst allowed = keyAllows(decided.role, { write, agent, route, method: request.method });","atom":"a1488","author":"speed","version":150},{"n":165,"text":"\t\t\tif (!allowed.ok) return json(allowed.status, { error: allowed.error });","atom":"a1488","author":"speed","version":150},{"n":166,"text":"\t\t\thow = decided.as;","atom":"a1488","author":"speed","version":150},{"n":167,"text":"\t\t} else keyForCall = { presented: caller.presented, address: addressOf(request), write, route };","atom":"a1488","author":"speed","version":150},{"n":168,"text":"\t}","atom":"a1488","author":"speed","version":150},{"n":169,"text":"","atom":"a1488","author":"speed","version":150},{"n":170,"text":"\tif (top === \"head\") {","atom":"a1488","author":"speed","version":150},{"n":171,"text":"\t\tif (request.method !== \"GET\") return json(405, { error: \"head is a GET\" });","atom":"a1488","author":"speed","version":150},{"n":172,"text":"\t\tconst head = await obj.head();","atom":"a1488","author":"speed","version":150},{"n":173,"text":"\t\treturn head ? json(200, head) : json(404, { error: \"no such project; run init first\" });","atom":"a1488","author":"speed","version":150},{"n":174,"text":"\t}","atom":"a1488","author":"speed","version":150},{"n":175,"text":"\tif (top === \"out\") return json(200, await obj.out());","atom":"a1488","author":"speed","version":150},{"n":176,"text":"\tif (top === \"ci\") return json(200, NO_CI);","atom":"a1488","author":"speed","version":150},{"n":177,"text":"\tif (top === \"queue\") return json(200, NO_QUEUE);","atom":"a1488","author":"speed","version":150},{"n":178,"text":"\tif (top === \"visibility\") {","atom":"a1488","author":"speed","version":150},{"n":179,"text":"\t\tif (request.method !== \"GET\")","atom":"a1488","author":"speed","version":150},{"n":180,"text":"\t\t\treturn json(400, { error: \"every project on this server is private: it answers only its token and keys\" });","atom":"a1488","author":"speed","version":150},{"n":181,"text":"\t\treturn json(200, { project, visibility: \"private\" });","atom":"a1488","author":"speed","version":150},{"n":182,"text":"\t}","atom":"a1488","author":"speed","version":150},{"n":183,"text":"\tif (blob) {","atom":"a1488","author":"speed","version":150},{"n":184,"text":"\t\tconst sha = top.slice(\"blobs/\".length);","atom":"a1488","author":"speed","version":150},{"n":185,"text":"\t\tif (!SHA.test(sha)) return json(400, { error: \"a blob's name is its SHA-256 in lowercase hex\" });","atom":"a1488","author":"speed","version":150},{"n":186,"text":"\t\tif (request.method === \"PUT\") {","atom":"a1488","author":"speed","version":150},{"n":187,"text":"\t\t\tif (!request.body) return json(400, { error: \"PUT the blob's bytes as the body\" });","atom":"a1488","author":"speed","version":150},{"n":188,"text":"\t\t\tconst a = (await obj.putBlob(sha, request.body)) as unknown as Answer;","atom":"a1488","author":"speed","version":150},{"n":189,"text":"\t\t\treturn json(a.status, a.body);","atom":"a1488","author":"speed","version":150},{"n":190,"text":"\t\t}","atom":"a1488","author":"speed","version":150},{"n":191,"text":"\t\tif (request.method !== \"GET\") return json(405, { error: \"blobs take GET or PUT\" });","atom":"a1488","author":"speed","version":150},{"n":192,"text":"\t\tconst bytes = await obj.getBlob(sha);","atom":"a1488","author":"speed","version":150},{"n":193,"text":"\t\tif (!bytes) return json(404, { error: `no blob ${sha} in this project` });","atom":"a1488","author":"speed","version":150},{"n":194,"text":"\t\treturn new Response(bytes, {","atom":"a1488","author":"speed","version":150},{"n":195,"text":"\t\t\theaders: { \"content-type\": \"application/octet-stream\", \"cache-control\": \"private, max-age=31536000, immutable\" },","atom":"a1488","author":"speed","version":150},{"n":196,"text":"\t\t});","atom":"a1488","author":"speed","version":150},{"n":197,"text":"\t}","atom":"a1488","author":"speed","version":150},{"n":198,"text":"\tif (top === \"export\") {","atom":"a1488","author":"speed","version":150},{"n":199,"text":"\t\tconst from = Number(url.searchParams.get(\"from\") ?? \"0\");","atom":"a1488","author":"speed","version":150},{"n":200,"text":"\t\tconst limit = Number(url.searchParams.get(\"limit\") ?? \"500\");","atom":"a1488","author":"speed","version":150},{"n":201,"text":"\t\tif (!Number.isInteger(from) || from < 0 || !Number.isInteger(limit) || limit < 1 || limit > 5000)","atom":"a1488","author":"speed","version":150},{"n":202,"text":"\t\t\treturn json(400, { error: \"export takes ?from=<seq>&limit=<1-5000>\" });","atom":"a1488","author":"speed","version":150},{"n":203,"text":"\t\tconst page = await obj.exportLog(from, limit);","atom":"a1488","author":"speed","version":150},{"n":204,"text":"\t\tif (page === null) return json(404, { error: \"no such project; run init first\" });","atom":"a1488","author":"speed","version":150},{"n":205,"text":"\t\treturn new Response(page.lines, {","atom":"a1488","author":"speed","version":150},{"n":206,"text":"\t\t\theaders: {","atom":"a1488","author":"speed","version":150},{"n":207,"text":"\t\t\t\t\"content-type\": \"application/x-ndjson\",","atom":"a1488","author":"speed","version":150},{"n":208,"text":"\t\t\t\t\"x-abso-next\": page.next === null ? \"\" : String(page.next),","atom":"a1488","author":"speed","version":150},{"n":209,"text":"\t\t\t\t\"cache-control\": \"no-store\",","atom":"a1488","author":"speed","version":150},{"n":210,"text":"\t\t\t},","atom":"a1488","author":"speed","version":150},{"n":211,"text":"\t\t});","atom":"a1488","author":"speed","version":150},{"n":212,"text":"\t}","atom":"a1488","author":"speed","version":150},{"n":213,"text":"\tif (top === \"git-remote\") {","atom":"a1488","author":"speed","version":150},{"n":214,"text":"\t\t// For a person who works with plain git: clone, commit, push; the project takes the commits in.","atom":"a1488","author":"speed","version":150},{"n":215,"text":"\t\tif (request.method !== \"POST\") return json(405, { error: \"git-remote is a POST\" });","atom":"a1488","author":"speed","version":150},{"n":216,"text":"\t\tconst artifacts = artifactsOf(env);","atom":"a1488","author":"speed","version":150},{"n":217,"text":"\t\tif (!artifacts) return json(501, { error: \"this server has no Artifacts binding, so no git remote\" });","atom":"a1488","author":"speed","version":150},{"n":218,"text":"\t\tif ((await obj.head()) === null) return json(404, { error: \"no such project; run init first\" });","atom":"a1488","author":"speed","version":150},{"n":219,"text":"\t\tconst { remote, secret: token } = await writeAccess(artifacts, repoName(project), 3600);","atom":"a1488","author":"speed","version":150},{"n":220,"text":"\t\t// The token goes in a header for each git call, never in the remote URL or a credential store.","atom":"a1488","author":"speed","version":150},{"n":221,"text":"\t\tconst header = `Authorization: Basic ${btoa(`x:${token}`)}`;","atom":"a1488","author":"speed","version":150},{"n":222,"text":"\t\tconst git = `git -c credential.helper= -c http.extraHeader=\"${header}\"`;","atom":"a1488","author":"speed","version":150},{"n":223,"text":"\t\treturn json(200, {","atom":"a1488","author":"speed","version":150},{"n":224,"text":"\t\t\tremote,","atom":"a1488","author":"speed","version":150},{"n":225,"text":"\t\t\ttoken,","atom":"a1488","author":"speed","version":150},{"n":226,"text":"\t\t\texpiresIn: 3600,","atom":"a1488","author":"speed","version":150},{"n":227,"text":"\t\t\theader,","atom":"a1488","author":"speed","version":150},{"n":228,"text":"\t\t\tclone: `${git} clone ${remote}`,","atom":"a1488","author":"speed","version":150},{"n":229,"text":"\t\t\tfetch: `${git} fetch`,","atom":"a1488","author":"speed","version":150},{"n":230,"text":"\t\t\tpush: `${git} push`,","atom":"a1488","author":"speed","version":150},{"n":231,"text":"\t\t});","atom":"a1488","author":"speed","version":150},{"n":232,"text":"\t}","atom":"a1488","author":"speed","version":150},{"n":233,"text":"\tif (top === \"git-sync\") {","atom":"a1488","author":"speed","version":150},{"n":234,"text":"\t\tif (request.method !== \"POST\") return json(405, { error: \"git-sync is a POST\" });","atom":"a1488","author":"speed","version":150},{"n":235,"text":"\t\ttry {","atom":"a1488","author":"speed","version":150},{"n":236,"text":"\t\t\treturn json(200, { taken: await obj.gitSync() });","atom":"a1488","author":"speed","version":150},{"n":237,"text":"\t\t} catch (e) {","atom":"a1488","author":"speed","version":150},{"n":238,"text":"\t\t\treturn json(502, { error: `could not read the project's repo: ${e instanceof Error ? e.message : String(e)}` });","atom":"a1488","author":"speed","version":150},{"n":239,"text":"\t\t}","atom":"a1488","author":"speed","version":150},{"n":240,"text":"\t}","atom":"a1488","author":"speed","version":150},{"n":241,"text":"","atom":"a1488","author":"speed","version":150},{"n":242,"text":"\tlet body: unknown;","atom":"a1488","author":"speed","version":150},{"n":243,"text":"\tif (request.method === \"POST\") {","atom":"a1488","author":"speed","version":150},{"n":244,"text":"\t\tconst text = await request.text();","atom":"a1488","author":"speed","version":150},{"n":245,"text":"\t\tif (text) {","atom":"a1488","author":"speed","version":150},{"n":246,"text":"\t\t\ttry {","atom":"a1488","author":"speed","version":150},{"n":247,"text":"\t\t\t\tbody = JSON.parse(text);","atom":"a1488","author":"speed","version":150},{"n":248,"text":"\t\t\t} catch {","atom":"a1488","author":"speed","version":150},{"n":249,"text":"\t\t\t\treturn json(400, { error: \"the body must be JSON\" });","atom":"a1488","author":"speed","version":150},{"n":250,"text":"\t\t\t}","atom":"a1488","author":"speed","version":150},{"n":251,"text":"\t\t}","atom":"a1488","author":"speed","version":150},{"n":252,"text":"\t} else if (request.method === \"GET\" && (QUERY_READS.has(route ?? \"\") || top.startsWith(\"change/\"))) {","atom":"a1488","author":"speed","version":150},{"n":253,"text":"\t\tbody = Object.fromEntries(url.searchParams);","atom":"a1488","author":"speed","version":150},{"n":254,"text":"\t} else return json(405, { error: `${route} is a POST` });","atom":"a1488","author":"speed","version":150},{"n":255,"text":"\t// Which client sent a recording goes in the log with it.","atom":"a1488","author":"speed","version":150},{"n":256,"text":"\tif ((op === \"edit\" || op === \"record\") && body && typeof body === \"object\") {","atom":"a1488","author":"speed","version":150},{"n":257,"text":"\t\tconst client = request.headers.get(\"x-abso-client\") ?? request.headers.get(\"x-avcs-client\") ?? \"\";","atom":"a1488","author":"speed","version":150},{"n":258,"text":"\t\tconst { client: _, ...rest } = body as Record<string, unknown>;","atom":"a1488","author":"speed","version":150},{"n":259,"text":"\t\tbody = { ...rest, ...(/^[\\w.+-]{1,20}\\/[\\w.+-]{1,40}$/.test(client) ? { client } : {}) };","atom":"a1488","author":"speed","version":150},{"n":260,"text":"\t}","atom":"a1488","author":"speed","version":150},{"n":261,"text":"\ttry {","atom":"a1488","author":"speed","version":150},{"n":262,"text":"\t\tconst a = (await obj.call(","atom":"a1668","author":"codex-capacity-chair","version":162},{"n":263,"text":"\t\t\tproject,","atom":"a1668","author":"codex-capacity-chair","version":162},{"n":264,"text":"\t\t\t(op ?? top)!,","atom":"a1668","author":"codex-capacity-chair","version":162},{"n":265,"text":"\t\t\tagent,","atom":"a1668","author":"codex-capacity-chair","version":162},{"n":266,"text":"\t\t\tbody,","atom":"a1668","author":"codex-capacity-chair","version":162},{"n":267,"text":"\t\t\tfalse,","atom":"a1668","author":"codex-capacity-chair","version":162},{"n":268,"text":"\t\t\thow,","atom":"a1668","author":"codex-capacity-chair","version":162},{"n":269,"text":"\t\t\tkeyForCall,","atom":"a1668","author":"codex-capacity-chair","version":162},{"n":270,"text":"\t\t\trequest.headers.get(\"Idempotency-Key\") ?? undefined,","atom":"a1668","author":"codex-capacity-chair","version":162},{"n":271,"text":"\t\t)) as unknown as Answer;","atom":"a1668","author":"codex-capacity-chair","version":162},{"n":272,"text":"\t\t// A held push gets a first opinion on each collision (#19), when the server is set up for it.","atom":"a2196","author":"autosettle","version":196},{"n":273,"text":"\t\treturn json(a.status, await withAdvice(env, op, agent, body, a.body));","atom":"a2292","author":"autosettle","version":204},{"n":274,"text":"\t} catch (e) {","atom":"a1488","author":"speed","version":150},{"n":275,"text":"\t\tconst error = `the project object failed: ${e instanceof Error ? e.message : String(e)}`;","atom":"a1488","author":"speed","version":150},{"n":276,"text":"\t\tconsole.error(`${project} ${op ?? top}: ${error}`);","atom":"a1488","author":"speed","version":150},{"n":277,"text":"\t\treturn json(500, { error });","atom":"a1488","author":"speed","version":150},{"n":278,"text":"\t}","atom":"a1488","author":"speed","version":150},{"n":279,"text":"}","atom":"a1488","author":"speed","version":150},{"n":280,"text":"","atom":"a1488","author":"speed","version":150},{"n":281,"text":"/** One request. The issues code comes in as an argument, so this file loads without the Workers runtime (tests). */","atom":"a1488","author":"speed","version":150},{"n":282,"text":"export async function handle(","atom":"a1488","author":"speed","version":150},{"n":283,"text":"\trequest: Request,","atom":"a1488","author":"speed","version":150},{"n":284,"text":"\tenv: Env,","atom":"a1488","author":"speed","version":150},{"n":285,"text":"\tctx: ExecutionContext,","atom":"a1488","author":"speed","version":150},{"n":286,"text":"\tissues: typeof issuesFetch,","atom":"a1488","author":"speed","version":150},{"n":287,"text":"): Promise<Response> {","atom":"a1488","author":"speed","version":150},{"n":288,"text":"\tconst url = new URL(request.url);","atom":"a1488","author":"speed","version":150},{"n":289,"text":"\tif (url.pathname === \"/version\") return json(200, { commit: env.CF_VERSION_METADATA?.tag || null });","atom":"a1488","author":"speed","version":150},{"n":290,"text":"\tconst caller = await authorize(request, env);","atom":"a1488","author":"speed","version":150},{"n":291,"text":"\tif (caller instanceof Response) return caller;","atom":"a1488","author":"speed","version":150},{"n":292,"text":"\tif (url.pathname === \"/\")","atom":"a1488","author":"speed","version":150},{"n":293,"text":"\t\treturn new Response(\"abso: agent-first version control. The API lives under /p/<project>.\\n\");","atom":"a1488","author":"speed","version":150},{"n":294,"text":"\tif (url.pathname === \"/admin/agent-keys\" || url.pathname === \"/admin/agent-keys/revoke\")","atom":"a1488","author":"speed","version":150},{"n":295,"text":"\t\treturn agentKeys(request, env, url, caller);","atom":"a1488","author":"speed","version":150},{"n":296,"text":"\tconst onIssues = ISSUES_ROUTE.exec(url.pathname);","atom":"a1488","author":"speed","version":150},{"n":297,"text":"\tif (onIssues) {","atom":"a1488","author":"speed","version":150},{"n":298,"text":"\t\tconst project = decodeURIComponent(onIssues[1]!);","atom":"a1488","author":"speed","version":150},{"n":299,"text":"\t\tif (!validName(project)) return json(400, { error: \"project names use letters, digits, '.', '_' and '-'\" });","atom":"a1488","author":"speed","version":150},{"n":300,"text":"\t\tlet auth: IssuesAuth = { kind: \"token\" };","atom":"a1488","author":"speed","version":150},{"n":301,"text":"\t\tif (caller.kind === \"key\") {","atom":"a1488","author":"speed","version":150},{"n":302,"text":"\t\t\tconst decided = await projectObject(env, project).checkAgentKey(caller.presented, undefined, addressOf(request));","atom":"a1488","author":"speed","version":150},{"n":303,"text":"\t\t\tif (!decided.ok) return json(decided.status, { error: decided.error });","atom":"a1488","author":"speed","version":150},{"n":304,"text":"\t\t\tauth = { kind: \"key\", agent: decided.agent, role: decided.role as KeyRole };","atom":"a1488","author":"speed","version":150},{"n":305,"text":"\t\t}","atom":"a1488","author":"speed","version":150},{"n":306,"text":"\t\treturn issues(request, env, ctx, { project, rest: onIssues[2] ?? \"\", auth });","atom":"a1488","author":"speed","version":150},{"n":307,"text":"\t}","atom":"a1488","author":"speed","version":150},{"n":308,"text":"\tconst m = PROJECT_ROUTE.exec(url.pathname);","atom":"a1488","author":"speed","version":150},{"n":309,"text":"\tif (!m) return json(404, { error: \"no such route\" });","atom":"a1488","author":"speed","version":150},{"n":310,"text":"\treturn projectRoute(request, env, url, caller, m);","atom":"a1488","author":"speed","version":150},{"n":311,"text":"}","atom":"a1488","author":"speed","version":150}],"atoms":[{"atom":"a1488","author":"speed","message":"","time":1791907425388,"timeIso":"2026-10-13T16:03:45.388Z","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":"a1668","author":"codex-capacity-chair","message":"","time":1791944420248,"timeIso":"2026-10-14T02:20:20.248Z","publish":{"draft":null,"version":162,"agent":"codex-capacity-chair","message":"Add reviewed disk-first history and indexed graph storage for core issue 16; retain runtime activation gate","time":1791945013341,"timeIso":"2026-10-14T02:30:13.341Z"}},{"atom":"a2083","author":"candidates","message":"","time":1792003409924,"timeIso":"2026-10-14T18:43:29.924Z","publish":{"draft":null,"version":186,"agent":"candidates","message":"Read a version of shared without some earlier versions: abso show <N> --without A,B shows what differs and abso export <dir> --version N --without A,B writes the files. The server's GET without?version=&versions= checks the set left exactly as asked: when a version it keeps builds on one left out, it refuses with that chain, the files and the wider set that works, and never widens it. Atoms keep their ids and authors; shared and its log don't change; the same ask gives the same tree hash.","time":1792004002371,"timeIso":"2026-10-14T18:53:22.371Z"}},{"atom":"a2196","author":"autosettle","message":"","time":1792021614959,"timeIso":"2026-10-14T23:46:54.959Z","publish":{"draft":null,"version":196,"agent":"autosettle","message":"Auto-settle (#19), step 3 behind a switch: the open server gives a held push a first opinion. With AUTOSETTLE=on and an AI binding (both off unless set), a held push's answer carries advice for each lines collision: keep yours, theirs or both, or needs an agent, with how many of 5 Workers AI samples agree and one line why. Checks in code run first and after (server/src/autosettle.ts), and the scripts now use the same ones. The client prints the advice under the collisions; the agent still settles. A model that fails leaves no advice and never fails the push's answer. server/test/autosettle.test.ts covers it with a stand-in for Workers AI.","time":1792021901137,"timeIso":"2026-10-14T23:51:41.137Z"}},{"atom":"a2292","author":"autosettle","message":"","time":1792028480762,"timeIso":"2026-10-15T01:41:20.762Z","publish":{"draft":null,"version":204,"agent":"autosettle","message":"Auto-settle switch (abso 19): on advises, act also has the client settle\n\nAUTOSETTLE=on now only adds advice to a held push; AUTOSETTLE=act adds settle: true, and the client settles the collisions advised a side only then (ABSO_AUTOSETTLE=off still stops it). The whole server hook is one function, withAdvice(env, op, agent, request, answer), so a Worker calls it in one line: return json(a.status, await withAdvice(env, op, agent, body, a.body)). Tested: the switch test, held-push tests, and the local demo under on (held with advice) and act (settled and pushed).","time":1792028481422,"timeIso":"2026-10-15T01:41:21.422Z"}}]}