{"file":"worker/project/http.ts","version":318,"total":633,"from":1,"to":633,"lines":[{"n":1,"text":"// The JSON routes of the contract (docs/v2-slice1.md), as a pure function of","atom":"a0","author":"init","version":0},{"n":2,"text":"// the project calls, so they can be tested in Node without a Worker.","atom":"a0","author":"init","version":0},{"n":3,"text":"","atom":"a665","author":"engine","version":73},{"n":4,"text":"import type { EditBody, ProjectCalls, ProjectHistory } from \"./project-api.ts\";","atom":"a0","author":"init","version":0},{"n":5,"text":"import { unseenError } from \"./unseen.ts\";","atom":"a665","author":"engine","version":73},{"n":6,"text":"","atom":"a0","author":"init","version":0},{"n":7,"text":"export interface Answer {","atom":"a0","author":"init","version":0},{"n":8,"text":"\tstatus: number;","atom":"a0","author":"init","version":0},{"n":9,"text":"\tbody: unknown;","atom":"a0","author":"init","version":0},{"n":10,"text":"}","atom":"a0","author":"init","version":0},{"n":11,"text":"","atom":"a0","author":"init","version":0},{"n":12,"text":"const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,62}$/;","atom":"a0","author":"init","version":0},{"n":13,"text":"","atom":"a0","author":"init","version":0},{"n":14,"text":"export function validName(name: string | undefined): name is string {","atom":"a0","author":"init","version":0},{"n":15,"text":"\treturn name !== undefined && NAME.test(name);","atom":"a0","author":"init","version":0},{"n":16,"text":"}","atom":"a0","author":"init","version":0},{"n":17,"text":"","atom":"a0","author":"init","version":0},{"n":18,"text":"/**","atom":"a0","author":"init","version":0},{"n":19,"text":" * The call's answer, or undefined when `ms` passes or the call fails.","atom":"a0","author":"init","version":0},{"n":20,"text":" * The call keeps running either way: this only bounds how long the caller waits.","atom":"a0","author":"init","version":0},{"n":21,"text":" */","atom":"a0","author":"init","version":0},{"n":22,"text":"export function within<T>(work: Promise<T>, ms: number): Promise<T | undefined> {","atom":"a0","author":"init","version":0},{"n":23,"text":"\treturn new Promise((resolve) => {","atom":"a0","author":"init","version":0},{"n":24,"text":"\t\tconst timer = setTimeout(() => resolve(undefined), ms);","atom":"a0","author":"init","version":0},{"n":25,"text":"\t\twork.then(","atom":"a0","author":"init","version":0},{"n":26,"text":"\t\t\t(value) => {","atom":"a0","author":"init","version":0},{"n":27,"text":"\t\t\t\tclearTimeout(timer);","atom":"a0","author":"init","version":0},{"n":28,"text":"\t\t\t\tresolve(value);","atom":"a0","author":"init","version":0},{"n":29,"text":"\t\t\t},","atom":"a0","author":"init","version":0},{"n":30,"text":"\t\t\t() => {","atom":"a0","author":"init","version":0},{"n":31,"text":"\t\t\t\tclearTimeout(timer);","atom":"a0","author":"init","version":0},{"n":32,"text":"\t\t\t\tresolve(undefined);","atom":"a0","author":"init","version":0},{"n":33,"text":"\t\t\t},","atom":"a0","author":"init","version":0},{"n":34,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":35,"text":"\t});","atom":"a0","author":"init","version":0},{"n":36,"text":"}","atom":"a0","author":"init","version":0},{"n":37,"text":"","atom":"a0","author":"init","version":0},{"n":38,"text":"const fail = (status: number, error: string): Answer => ({ status, body: { error } });","atom":"a0","author":"init","version":0},{"n":39,"text":"","atom":"a0","author":"init","version":0},{"n":40,"text":"/**","atom":"a0","author":"init","version":0},{"n":41,"text":" * Agents that read everything and record nothing (#37, Reporter). Kept by the","atom":"a0","author":"init","version":0},{"n":42,"text":" * caller outside the log: a refused call writes nothing, so replay never","atom":"a0","author":"init","version":0},{"n":43,"text":" * needs it, and an older Worker can still load the log.","atom":"a0","author":"init","version":0},{"n":44,"text":" */","atom":"a0","author":"init","version":0},{"n":45,"text":"export interface Readers {","atom":"a0","author":"init","version":0},{"n":46,"text":"\thas(agent: string): boolean;","atom":"a0","author":"init","version":0},{"n":47,"text":"\tset(agent: string, reader: boolean): void;","atom":"a0","author":"init","version":0},{"n":48,"text":"\tlist(): string[];","atom":"a0","author":"init","version":0},{"n":49,"text":"}","atom":"a0","author":"init","version":0},{"n":50,"text":"","atom":"a0","author":"init","version":0},{"n":51,"text":"/**","atom":"a0","author":"init","version":0},{"n":52,"text":" * What a reader may not do: change code. Edits and records (which old edit","atom":"a2548","author":"approvals-page","version":250},{"n":53,"text":" * mods send on their own) and publishes answer 200 {ok: false, reason}, so a","atom":"a2548","author":"approvals-page","version":250},{"n":54,"text":" * mod only logs it; the rest are refused outright. Talking stays open (abso","atom":"a2548","author":"approvals-page","version":250},{"n":55,"text":" * 682, Christopher: \"readers need to be able to do asks and news and stuff\"):","atom":"a2548","author":"approvals-page","version":250},{"n":56,"text":" * announcements, notes on lines, asks and issues all work for a reader.","atom":"a2548","author":"approvals-page","version":250},{"n":57,"text":" */","atom":"a0","author":"init","version":0},{"n":58,"text":"const NOT_FOR_READERS: Record<string, \"answer\" | \"refuse\"> = {","atom":"a0","author":"init","version":0},{"n":59,"text":"\tedit: \"answer\",","atom":"a0","author":"init","version":0},{"n":60,"text":"\trecord: \"answer\",","atom":"a0","author":"init","version":0},{"n":61,"text":"\tpublish: \"answer\",","atom":"a0","author":"init","version":0},{"n":62,"text":"\tland: \"answer\",","atom":"a0","author":"init","version":0},{"n":63,"text":"\tpluck: \"answer\",","atom":"a0","author":"init","version":0},{"n":64,"text":"\t\"draft-sync\": \"refuse\",","atom":"a0","author":"init","version":0},{"n":65,"text":"\tdrop: \"refuse\",","atom":"a0","author":"init","version":0},{"n":66,"text":"\tamend: \"refuse\",","atom":"a0","author":"init","version":0},{"n":67,"text":"\tlabel: \"refuse\",","atom":"a0","author":"init","version":0},{"n":68,"text":"\tstarting: \"refuse\",","atom":"a0","author":"init","version":0},{"n":69,"text":"\tmove: \"refuse\",","atom":"a0","author":"init","version":0},{"n":70,"text":"};","atom":"a0","author":"init","version":0},{"n":71,"text":"","atom":"a0","author":"init","version":0},{"n":72,"text":"/** A path the project won't hold: .avcs/ is each folder's own settings. */","atom":"a0","author":"init","version":0},{"n":73,"text":"/** A path under a folder's state folder (.abso/, or .avcs/ from before the rename), which never leaves it. */","atom":"a132","author":"pinch","version":18},{"n":74,"text":"function localPath(paths: string[]): string | undefined {","atom":"a0","author":"init","version":0},{"n":75,"text":"\treturn paths.find((p) => [\".abso\", \".avcs\"].some((d) => p === d || p.startsWith(`${d}/`) || p.startsWith(`./${d}/`)));","atom":"a132","author":"pinch","version":18},{"n":76,"text":"}","atom":"a0","author":"init","version":0},{"n":77,"text":"const LOCAL = (p: string) =>","atom":"a132","author":"pinch","version":18},{"n":78,"text":"\tfail(400, `${p} is under ${p.replace(/^\\.\\//, \"\").split(\"/\")[0]}/, which stays in the agent's folder`);","atom":"a132","author":"pinch","version":18},{"n":79,"text":"","atom":"a0","author":"init","version":0},{"n":80,"text":"/**","atom":"a0","author":"init","version":0},{"n":81,"text":" * The reader rules (#37, Reporter), for one agent call: the answer to","atom":"a0","author":"init","version":0},{"n":82,"text":" * `reader {reader}`, or the refusal of something a reader may not do, or","atom":"a0","author":"init","version":0},{"n":83,"text":" * undefined when the call goes ahead. An agent holding unpublished work","atom":"a0","author":"init","version":0},{"n":84,"text":" * can't become a reader.","atom":"a0","author":"init","version":0},{"n":85,"text":" */","atom":"a0","author":"init","version":0},{"n":86,"text":"export function readerAnswer(","atom":"a0","author":"init","version":0},{"n":87,"text":"\tproject: { status(): unknown },","atom":"a0","author":"init","version":0},{"n":88,"text":"\top: string,","atom":"a0","author":"init","version":0},{"n":89,"text":"\tagent: string,","atom":"a0","author":"init","version":0},{"n":90,"text":"\tbody: unknown,","atom":"a0","author":"init","version":0},{"n":91,"text":"\treaders: Readers,","atom":"a0","author":"init","version":0},{"n":92,"text":"): Answer | undefined {","atom":"a0","author":"init","version":0},{"n":93,"text":"\tif (op === \"reader\") {","atom":"a0","author":"init","version":0},{"n":94,"text":"\t\tconst on = (body as { reader?: unknown } | undefined)?.reader;","atom":"a0","author":"init","version":0},{"n":95,"text":"\t\tif (typeof on !== \"boolean\") return fail(400, \"reader needs {reader: true} or {reader: false}\");","atom":"a0","author":"init","version":0},{"n":96,"text":"\t\tif (on) {","atom":"a0","author":"init","version":0},{"n":97,"text":"\t\t\tconst me = (","atom":"a0","author":"init","version":0},{"n":98,"text":"\t\t\t\tproject.status() as { agents?: { agent: string; draftChanges: number; parked?: unknown[] }[] }","atom":"a0","author":"init","version":0},{"n":99,"text":"\t\t\t).agents?.find((a) => a.agent === agent);","atom":"a0","author":"init","version":0},{"n":100,"text":"\t\t\tif (me && (me.draftChanges > 0 || (me.parked?.length ?? 0) > 0)) {","atom":"a0","author":"init","version":0},{"n":101,"text":"\t\t\t\treturn fail(","atom":"a0","author":"init","version":0},{"n":102,"text":"\t\t\t\t\t409,","atom":"a0","author":"init","version":0},{"n":103,"text":"\t\t\t\t\t`${agent} has unpushed changes; push or restore them (abso restore --all) before it becomes a reader`,","atom":"a872","author":"rename","version":100},{"n":104,"text":"\t\t\t\t);","atom":"a0","author":"init","version":0},{"n":105,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":106,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":107,"text":"\t\treaders.set(agent, on);","atom":"a0","author":"init","version":0},{"n":108,"text":"\t\treturn { status: 200, body: { agent, reader: on } };","atom":"a0","author":"init","version":0},{"n":109,"text":"\t}","atom":"a0","author":"init","version":0},{"n":110,"text":"\tconst barred = readers.has(agent) ? NOT_FOR_READERS[op] : undefined;","atom":"a0","author":"init","version":0},{"n":111,"text":"\tif (!barred) return undefined;","atom":"a0","author":"init","version":0},{"n":112,"text":"\tconst reason = `agent ${agent} is a reader: it records nothing (abso join --reader)`;","atom":"a0","author":"init","version":0},{"n":113,"text":"\tif (barred === \"refuse\") return fail(403, reason);","atom":"a0","author":"init","version":0},{"n":114,"text":"\treturn { status: 200, body: { ok: false, reason, ...(op === \"edit\" || op === \"record\" ? {} : { collisions: [] }) } };","atom":"a0","author":"init","version":0},{"n":115,"text":"}","atom":"a0","author":"init","version":0},{"n":116,"text":"","atom":"a0","author":"init","version":0},{"n":117,"text":"/** The status answer with readers marked on their agent entries and listed (#37). */","atom":"a0","author":"init","version":0},{"n":118,"text":"export function statusWithReaders(status: unknown, readers: Readers | undefined): unknown {","atom":"a0","author":"init","version":0},{"n":119,"text":"\tconst s = status as { agents?: { agent: string }[] };","atom":"a0","author":"init","version":0},{"n":120,"text":"\tif (!readers || readers.list().length === 0) return s;","atom":"a0","author":"init","version":0},{"n":121,"text":"\treturn {","atom":"a0","author":"init","version":0},{"n":122,"text":"\t\t...s,","atom":"a0","author":"init","version":0},{"n":123,"text":"\t\tagents: (s.agents ?? []).map((a) => (readers.has(a.agent) ? { ...a, reader: true } : a)),","atom":"a0","author":"init","version":0},{"n":124,"text":"\t\treaders: readers.list(),","atom":"a0","author":"init","version":0},{"n":125,"text":"\t};","atom":"a0","author":"init","version":0},{"n":126,"text":"}","atom":"a0","author":"init","version":0},{"n":127,"text":"","atom":"a0","author":"init","version":0},{"n":128,"text":"/** op is \"init\", \"status\", or an agent op (\"edit\", \"record\", \"publish\", \"sync\"). */","atom":"a0","author":"init","version":0},{"n":129,"text":"export function answer(","atom":"a0","author":"init","version":0},{"n":130,"text":"\tproject: ProjectCalls,","atom":"a0","author":"init","version":0},{"n":131,"text":"\top: string,","atom":"a0","author":"init","version":0},{"n":132,"text":"\tagent: string | undefined,","atom":"a0","author":"init","version":0},{"n":133,"text":"\tbody: unknown,","atom":"a0","author":"init","version":0},{"n":134,"text":"\treaders?: Readers,","atom":"a0","author":"init","version":0},{"n":135,"text":"\thow?: string,","atom":"a0","author":"init","version":0},{"n":136,"text":"): Answer {","atom":"a0","author":"init","version":0},{"n":137,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":138,"text":"\t\tif (op === \"init\") {","atom":"a0","author":"init","version":0},{"n":139,"text":"\t\t\tconst files = (body as { files?: Record<string, string> })?.files;","atom":"a0","author":"init","version":0},{"n":140,"text":"\t\t\tif (!files || typeof files !== \"object\") return fail(400, \"init needs {files: {path: text}}\");","atom":"a0","author":"init","version":0},{"n":141,"text":"\t\t\tif (project.exists()) return fail(409, \"the project already exists\");","atom":"a0","author":"init","version":0},{"n":142,"text":"\t\t\tconst bad = localPath(Object.keys(files));","atom":"a0","author":"init","version":0},{"n":143,"text":"\t\t\tif (bad) return LOCAL(bad);","atom":"a0","author":"init","version":0},{"n":144,"text":"\t\t\tconst modes = (body as { modes?: unknown })?.modes;","atom":"a0","author":"init","version":0},{"n":145,"text":"\t\t\tif (modes !== undefined && (typeof modes !== \"object\" || modes === null))","atom":"a0","author":"init","version":0},{"n":146,"text":"\t\t\t\treturn fail(400, \"modes must be {path: {exec, link}}\");","atom":"a0","author":"init","version":0},{"n":147,"text":"\t\t\tconst blobs = (body as { blobs?: unknown })?.blobs;","atom":"a0","author":"init","version":0},{"n":148,"text":"\t\t\tif (blobs !== undefined && (typeof blobs !== \"object\" || blobs === null))","atom":"a0","author":"init","version":0},{"n":149,"text":"\t\t\t\treturn fail(400, \"blobs must be {path: sha256}\");","atom":"a0","author":"init","version":0},{"n":150,"text":"\t\t\tif (blobs && localPath(Object.keys(blobs))) return LOCAL(localPath(Object.keys(blobs))!);","atom":"a0","author":"init","version":0},{"n":151,"text":"\t\t\treturn {","atom":"a0","author":"init","version":0},{"n":152,"text":"\t\t\t\tstatus: 200,","atom":"a0","author":"init","version":0},{"n":153,"text":"\t\t\t\tbody: project.init(","atom":"a0","author":"init","version":0},{"n":154,"text":"\t\t\t\t\tfiles,","atom":"a0","author":"init","version":0},{"n":155,"text":"\t\t\t\t\tmodes as Record<string, { exec?: boolean; link?: string | null }> | undefined,","atom":"a0","author":"init","version":0},{"n":156,"text":"\t\t\t\t\tblobs as Record<string, string> | undefined,","atom":"a0","author":"init","version":0},{"n":157,"text":"\t\t\t\t),","atom":"a0","author":"init","version":0},{"n":158,"text":"\t\t\t};","atom":"a0","author":"init","version":0},{"n":159,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":160,"text":"\t\tif (!project.exists()) return fail(404, \"no such project; run init first\");","atom":"a0","author":"init","version":0},{"n":161,"text":"\t\t// Readers (#37): marked on their agent entries, and listed even before their first sync.","atom":"a0","author":"init","version":0},{"n":162,"text":"\t\t// Reads for the website (#41): ?at=<log position> replays status and where as they stood then.","atom":"a0","author":"init","version":0},{"n":163,"text":"\t\tconst atOf = (): number | undefined => {","atom":"a0","author":"init","version":0},{"n":164,"text":"\t\t\tconst at = (body as { at?: string } | undefined)?.at;","atom":"a0","author":"init","version":0},{"n":165,"text":"\t\t\treturn at !== undefined && at !== \"\" && Number.isInteger(Number(at)) && Number(at) >= 0 ? Number(at) : undefined;","atom":"a0","author":"init","version":0},{"n":166,"text":"\t\t};","atom":"a0","author":"init","version":0},{"n":167,"text":"\t\tif (op === \"status\" && agent === undefined) {","atom":"a0","author":"init","version":0},{"n":168,"text":"\t\t\tconst at = atOf();","atom":"a0","author":"init","version":0},{"n":169,"text":"\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":170,"text":"\t\t\tif (at !== undefined)","atom":"a0","author":"init","version":0},{"n":171,"text":"\t\t\t\treturn history.statusAt","atom":"a0","author":"init","version":0},{"n":172,"text":"\t\t\t\t\t? { status: 200, body: history.statusAt(at) }","atom":"a0","author":"init","version":0},{"n":173,"text":"\t\t\t\t\t: fail(501, \"status at a log position needs the engine\");","atom":"a0","author":"init","version":0},{"n":174,"text":"\t\t\treturn { status: 200, body: statusWithReaders(project.status(), readers) };","atom":"a0","author":"init","version":0},{"n":175,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":176,"text":"\t\tif (op === \"where\") {","atom":"a0","author":"init","version":0},{"n":177,"text":"\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":178,"text":"\t\t\tif (!history.where) return fail(501, \"where needs the engine\");","atom":"a0","author":"init","version":0},{"n":179,"text":"\t\t\tconst at = atOf();","atom":"a0","author":"init","version":0},{"n":180,"text":"\t\t\tif (at !== undefined)","atom":"a0","author":"init","version":0},{"n":181,"text":"\t\t\t\treturn history.whereAt","atom":"a0","author":"init","version":0},{"n":182,"text":"\t\t\t\t\t? { status: 200, body: history.whereAt(at) }","atom":"a0","author":"init","version":0},{"n":183,"text":"\t\t\t\t\t: fail(501, \"where at a log position needs the engine\");","atom":"a0","author":"init","version":0},{"n":184,"text":"\t\t\treturn { status: 200, body: history.where() };","atom":"a0","author":"init","version":0},{"n":185,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":186,"text":"\t\tif (op === \"changes\" || op.startsWith(\"change/\")) {","atom":"a0","author":"init","version":0},{"n":187,"text":"\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":188,"text":"\t\t\tif (!history.change || !history.changes) return fail(501, `${op} needs the engine`);","atom":"a0","author":"init","version":0},{"n":189,"text":"\t\t\tconst q = (body ?? {}) as Record<string, string | undefined>;","atom":"a0","author":"init","version":0},{"n":190,"text":"\t\t\tif (op !== \"changes\") return { status: 200, body: history.change(Number(op.slice(\"change/\".length))) };","atom":"a0","author":"init","version":0},{"n":191,"text":"\t\t\tconst since = q.since === undefined || q.since === \"\" ? 0 : Number(q.since);","atom":"a0","author":"init","version":0},{"n":192,"text":"\t\t\tconst limit = q.limit === undefined || q.limit === \"\" ? 50 : Number(q.limit);","atom":"a0","author":"init","version":0},{"n":193,"text":"\t\t\tif (!Number.isInteger(since) || since < 0) return fail(400, \"changes needs ?since=<log position>\");","atom":"a0","author":"init","version":0},{"n":194,"text":"\t\t\tif (!Number.isInteger(limit) || limit < 1 || limit > 200) return fail(400, \"limit is 1-200\");","atom":"a0","author":"init","version":0},{"n":195,"text":"\t\t\tconst before = q.before === undefined || q.before === \"\" ? undefined : Number(q.before);","atom":"a0","author":"init","version":0},{"n":196,"text":"\t\t\tif (before !== undefined && (!Number.isInteger(before) || before < 0))","atom":"a0","author":"init","version":0},{"n":197,"text":"\t\t\t\treturn fail(400, \"before must be a log position\");","atom":"a0","author":"init","version":0},{"n":198,"text":"\t\t\t// ?issue= (#54): the changes whose start note named that issue.","atom":"a0","author":"init","version":0},{"n":199,"text":"\t\t\tif (q.issue !== undefined && q.issue !== \"\" && !/^[1-9]\\d{0,9}$/.test(q.issue))","atom":"a0","author":"init","version":0},{"n":200,"text":"\t\t\t\treturn fail(400, \"issue must be an issue number\");","atom":"a0","author":"init","version":0},{"n":201,"text":"\t\t\treturn { status: 200, body: history.changes(since, limit, before, q.issue ? Number(q.issue) : undefined) };","atom":"a0","author":"init","version":0},{"n":202,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":203,"text":"\t\tif (op === \"notes\") {","atom":"a0","author":"init","version":0},{"n":204,"text":"\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":205,"text":"\t\t\tif (!history.notes) return fail(501, \"notes needs the engine\");","atom":"a0","author":"init","version":0},{"n":206,"text":"\t\t\tconst q = (body ?? {}) as Record<string, string | undefined>;","atom":"a0","author":"init","version":0},{"n":207,"text":"\t\t\tif (q.change !== undefined && !/^\\d+$/.test(q.change)) return fail(400, \"change must be a change id\");","atom":"a0","author":"init","version":0},{"n":208,"text":"\t\t\treturn {","atom":"a0","author":"init","version":0},{"n":209,"text":"\t\t\t\tstatus: 200,","atom":"a0","author":"init","version":0},{"n":210,"text":"\t\t\t\tbody: history.notes({","atom":"a0","author":"init","version":0},{"n":211,"text":"\t\t\t\t\t...(q.file ? { file: q.file } : {}),","atom":"a0","author":"init","version":0},{"n":212,"text":"\t\t\t\t\t...(q.change ? { change: Number(q.change) } : {}),","atom":"a0","author":"init","version":0},{"n":213,"text":"\t\t\t\t\t...(q.open === \"1\" || q.open === \"true\" ? { open: true } : {}),","atom":"a0","author":"init","version":0},{"n":214,"text":"\t\t\t\t}),","atom":"a0","author":"init","version":0},{"n":215,"text":"\t\t\t};","atom":"a0","author":"init","version":0},{"n":216,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":217,"text":"\t\tif (op === \"position\") {","atom":"a0","author":"init","version":0},{"n":218,"text":"\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":219,"text":"\t\t\tif (!history.position) return fail(501, \"position needs the engine\");","atom":"a0","author":"init","version":0},{"n":220,"text":"\t\t\tconst q = (body ?? {}) as Record<string, string | undefined>;","atom":"a0","author":"init","version":0},{"n":221,"text":"\t\t\tif (q.version !== undefined && q.version !== \"\") {","atom":"a0","author":"init","version":0},{"n":222,"text":"\t\t\t\tif (!/^\\d+$/.test(q.version)) return fail(400, \"version must be a version number\");","atom":"a0","author":"init","version":0},{"n":223,"text":"\t\t\t\treturn { status: 200, body: history.position({ version: Number(q.version) }) };","atom":"a0","author":"init","version":0},{"n":224,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":225,"text":"\t\t\tif (q.time === undefined || q.time === \"\")","atom":"a0","author":"init","version":0},{"n":226,"text":"\t\t\t\treturn fail(400, \"position needs ?time=<ISO time or ms since 1970> or ?version=<n>\");","atom":"a0","author":"init","version":0},{"n":227,"text":"\t\t\tconst time = /^\\d+$/.test(q.time) ? Number(q.time) : Date.parse(q.time);","atom":"a0","author":"init","version":0},{"n":228,"text":"\t\t\tif (!Number.isFinite(time)) return fail(400, \"time is an ISO time or ms since 1970\");","atom":"a0","author":"init","version":0},{"n":229,"text":"\t\t\treturn { status: 200, body: history.position({ time }) };","atom":"a0","author":"init","version":0},{"n":230,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":231,"text":"\t\tif (op === \"ribbon\") {","atom":"a0","author":"init","version":0},{"n":232,"text":"\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":233,"text":"\t\t\tif (!history.ribbon) return fail(501, \"ribbon needs the engine\");","atom":"a0","author":"init","version":0},{"n":234,"text":"\t\t\treturn { status: 200, body: history.ribbon() };","atom":"a0","author":"init","version":0},{"n":235,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":236,"text":"\t\tif (op === \"feed\" || op === \"drafts\" || (op === \"diff\" && agent === undefined)) {","atom":"a0","author":"init","version":0},{"n":237,"text":"\t\t\tconst q = (body ?? {}) as Record<string, string | undefined>;","atom":"a0","author":"init","version":0},{"n":238,"text":"\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":239,"text":"\t\t\tif (!history.feed || !history.drafts || !history.diffOf) return fail(501, `${op} needs the engine`);","atom":"a0","author":"init","version":0},{"n":240,"text":"\t\t\tif (op === \"drafts\") return { status: 200, body: history.drafts() };","atom":"a0","author":"init","version":0},{"n":241,"text":"\t\t\tif (op === \"diff\") {","atom":"a0","author":"init","version":0},{"n":242,"text":"\t\t\t\tif (!q.agent) return fail(400, \"diff needs ?agent=<name>\");","atom":"a0","author":"init","version":0},{"n":243,"text":"\t\t\t\treturn { status: 200, body: history.diffOf(q.agent) };","atom":"a0","author":"init","version":0},{"n":244,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":245,"text":"\t\t\tconst from = q.from === undefined || q.from === \"\" ? 0 : Number(q.from);","atom":"a0","author":"init","version":0},{"n":246,"text":"\t\t\tconst limit = q.limit === undefined || q.limit === \"\" ? 500 : Number(q.limit);","atom":"a0","author":"init","version":0},{"n":247,"text":"\t\t\tif (!Number.isInteger(from) || from < 0) return fail(400, \"feed needs ?from=<log position>\");","atom":"a0","author":"init","version":0},{"n":248,"text":"\t\t\tif (!Number.isInteger(limit) || limit < 1 || limit > 2000) return fail(400, \"limit is 1-2000\");","atom":"a0","author":"init","version":0},{"n":249,"text":"\t\t\treturn { status: 200, body: history.feed(from, limit) };","atom":"a0","author":"init","version":0},{"n":250,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":251,"text":"\t\tif (op === \"draft-state\") {","atom":"a0","author":"init","version":0},{"n":252,"text":"\t\t\t// A named draft's state in one read (#41, the Drafts page): base, behind, versions, first edit, collisions.","atom":"a0","author":"init","version":0},{"n":253,"text":"\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":254,"text":"\t\t\tif (!history.draftState) return fail(501, \"draft-state needs the engine\");","atom":"a0","author":"init","version":0},{"n":255,"text":"\t\t\tconst q = (body ?? {}) as Record<string, string | undefined>;","atom":"a0","author":"init","version":0},{"n":256,"text":"\t\t\tif (!q.name) return fail(400, \"draft-state needs ?name=<draft>\");","atom":"a0","author":"init","version":0},{"n":257,"text":"\t\t\treturn { status: 200, body: history.draftState(q.name) };","atom":"a0","author":"init","version":0},{"n":258,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":259,"text":"\t\tif (","atom":"a0","author":"init","version":0},{"n":260,"text":"\t\t\top === \"tree\" ||","atom":"a0","author":"init","version":0},{"n":261,"text":"\t\t\top === \"path\" ||","atom":"a0","author":"init","version":0},{"n":262,"text":"\t\t\top === \"follow\" ||","atom":"a0","author":"init","version":0},{"n":263,"text":"\t\t\top === \"collisions\" ||","atom":"a0","author":"init","version":0},{"n":264,"text":"\t\t\t(op === \"blame\" && (body as { folder?: unknown } | undefined)?.folder !== undefined)","atom":"a0","author":"init","version":0},{"n":265,"text":"\t\t) {","atom":"a0","author":"init","version":0},{"n":266,"text":"\t\t\t// Reads for the Files pages (#41): GETs, the body is the query string.","atom":"a0","author":"init","version":0},{"n":267,"text":"\t\t\tconst q = (body ?? {}) as Record<string, string | undefined>;","atom":"a0","author":"init","version":0},{"n":268,"text":"\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":269,"text":"\t\t\tif (!history.tree || !history.pathLife || !history.follow || !history.collisions || !history.folderBlame)","atom":"a0","author":"init","version":0},{"n":270,"text":"\t\t\t\treturn fail(501, `${op} needs the engine`);","atom":"a0","author":"init","version":0},{"n":271,"text":"\t\t\tconst int = (s: string | undefined): number | undefined | null =>","atom":"a0","author":"init","version":0},{"n":272,"text":"\t\t\t\ts === undefined || s === \"\" ? undefined : /^\\d+$/.test(s) ? Number(s) : null;","atom":"a0","author":"init","version":0},{"n":273,"text":"\t\t\tconst version = int(q.version);","atom":"a0","author":"init","version":0},{"n":274,"text":"\t\t\tif (version === null) return fail(400, \"version must be a version number\");","atom":"a0","author":"init","version":0},{"n":275,"text":"\t\t\tconst draft = q.draft || null;","atom":"a0","author":"init","version":0},{"n":276,"text":"\t\t\tif (op === \"blame\")","atom":"a0","author":"init","version":0},{"n":277,"text":"\t\t\t\treturn {","atom":"a0","author":"init","version":0},{"n":278,"text":"\t\t\t\t\tstatus: 200,","atom":"a0","author":"init","version":0},{"n":279,"text":"\t\t\t\t\tbody: history.folderBlame(q.folder ?? \"\", version, q.draft || undefined, q.agent || undefined),","atom":"a0","author":"init","version":0},{"n":280,"text":"\t\t\t\t};","atom":"a0","author":"init","version":0},{"n":281,"text":"\t\t\t// agent= (#41, F25): the folder as that agent has it; authors=1 (F33): each entry's authors in the same read.","atom":"a0","author":"init","version":0},{"n":282,"text":"\t\t\tif (op === \"tree\") {","atom":"a0","author":"init","version":0},{"n":283,"text":"\t\t\t\tif (q.authors !== undefined && q.authors !== \"\" && q.authors !== \"1\")","atom":"a0","author":"init","version":0},{"n":284,"text":"\t\t\t\t\treturn fail(400, \"authors is 1 or left out\");","atom":"a0","author":"init","version":0},{"n":285,"text":"\t\t\t\treturn {","atom":"a0","author":"init","version":0},{"n":286,"text":"\t\t\t\t\tstatus: 200,","atom":"a0","author":"init","version":0},{"n":287,"text":"\t\t\t\t\tbody: history.tree(q.folder ?? \"\", version, draft, q.agent || undefined, q.authors === \"1\"),","atom":"a0","author":"init","version":0},{"n":288,"text":"\t\t\t\t};","atom":"a0","author":"init","version":0},{"n":289,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":290,"text":"\t\t\tif (op === \"collisions\")","atom":"a0","author":"init","version":0},{"n":291,"text":"\t\t\t\treturn { status: 200, body: history.collisions(q.file || undefined, q.folder || undefined) };","atom":"a0","author":"init","version":0},{"n":292,"text":"\t\t\tif (!q.path) return fail(400, `${op} needs ?path=<path>`);","atom":"a0","author":"init","version":0},{"n":293,"text":"\t\t\tif (op === \"path\") return { status: 200, body: history.pathLife(q.path, version, draft) };","atom":"a0","author":"init","version":0},{"n":294,"text":"\t\t\tconst from = int(q.from);","atom":"a0","author":"init","version":0},{"n":295,"text":"\t\t\tconst to = int(q.to) ?? from;","atom":"a0","author":"init","version":0},{"n":296,"text":"\t\t\tconst at = int(q.at);","atom":"a0","author":"init","version":0},{"n":297,"text":"\t\t\tif (","atom":"a0","author":"init","version":0},{"n":298,"text":"\t\t\t\tversion === undefined ||","atom":"a0","author":"init","version":0},{"n":299,"text":"\t\t\t\tfrom === undefined ||","atom":"a0","author":"init","version":0},{"n":300,"text":"\t\t\t\tfrom === null ||","atom":"a0","author":"init","version":0},{"n":301,"text":"\t\t\t\tto === null ||","atom":"a0","author":"init","version":0},{"n":302,"text":"\t\t\t\tto === undefined ||","atom":"a0","author":"init","version":0},{"n":303,"text":"\t\t\t\tat === null","atom":"a0","author":"init","version":0},{"n":304,"text":"\t\t\t)","atom":"a0","author":"init","version":0},{"n":305,"text":"\t\t\t\treturn fail(400, \"follow needs ?path=&version=&from=, and ?to= and ?at= if wanted\");","atom":"a0","author":"init","version":0},{"n":306,"text":"\t\t\treturn { status: 200, body: history.follow(q.path, version, from, to, at, draft) };","atom":"a0","author":"init","version":0},{"n":307,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":308,"text":"\t\tif (op === \"blame\" || op === \"why\") {","atom":"a0","author":"init","version":0},{"n":309,"text":"\t\t\t// GETs: the body is the query string as {file, from, to, line}.","atom":"a0","author":"init","version":0},{"n":310,"text":"\t\t\tconst q = (body ?? {}) as Record<string, string | undefined>;","atom":"a0","author":"init","version":0},{"n":311,"text":"\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":312,"text":"\t\t\tif (!q.file) return fail(400, `${op} needs ?file=<path>, or blame ?folder=<path> (\"\" for the whole project)`);","atom":"a0","author":"init","version":0},{"n":313,"text":"\t\t\tif (!history.blame || !history.why) return fail(501, `${op} needs the engine`);","atom":"a0","author":"init","version":0},{"n":314,"text":"\t\t\tconst num = (s: string | undefined) => (s === undefined || s === \"\" ? undefined : Number(s));","atom":"a0","author":"init","version":0},{"n":315,"text":"\t\t\tconst draft = q.draft || undefined;","atom":"a0","author":"init","version":0},{"n":316,"text":"\t\t\tconst who = q.agent || undefined;","atom":"a0","author":"init","version":0},{"n":317,"text":"\t\t\tif (op === \"blame\")","atom":"a0","author":"init","version":0},{"n":318,"text":"\t\t\t\treturn { status: 200, body: history.blame(q.file, num(q.from), num(q.to), num(q.version), draft, who) };","atom":"a0","author":"init","version":0},{"n":319,"text":"\t\t\tconst line = num(q.line);","atom":"a0","author":"init","version":0},{"n":320,"text":"\t\t\tif (!line || !Number.isInteger(line)) return fail(400, \"why needs ?line=<number>\");","atom":"a0","author":"init","version":0},{"n":321,"text":"\t\t\treturn { status: 200, body: history.why(q.file, line, draft, who, num(q.version)) };","atom":"a2175","author":"whytrail","version":193},{"n":322,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":323,"text":"\t\tif (op === \"announce\" && agent === undefined) {","atom":"a0","author":"init","version":0},{"n":324,"text":"\t\t\t// The sender comes from the route, like every other agent op, not from","atom":"a0","author":"init","version":0},{"n":325,"text":"\t\t\t// a body field anyone can fill in (#31).","atom":"a327","author":"infra-split","version":37},{"n":326,"text":"\t\t\treturn fail(400, \"announce from your own agent: POST /p/:project/a/<you>/announce {text, to?}\");","atom":"a0","author":"init","version":0},{"n":327,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":328,"text":"\t\tif (op === \"files\" && agent === undefined) {","atom":"a0","author":"init","version":0},{"n":329,"text":"\t\t\t// GET ?version=&draft=: the paths in shared (or a named draft) at a version.","atom":"a0","author":"init","version":0},{"n":330,"text":"\t\t\tconst q = (body ?? {}) as Record<string, string | undefined>;","atom":"a0","author":"init","version":0},{"n":331,"text":"\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":332,"text":"\t\t\t// ?agent=: the files as an agent has them (#41, F25), read only, so an unknown agent is 404.","atom":"a0","author":"init","version":0},{"n":333,"text":"\t\t\tif (q.agent !== undefined) {","atom":"a0","author":"init","version":0},{"n":334,"text":"\t\t\t\tif (!history.pathsOf) return fail(501, \"files?agent= needs the engine\");","atom":"a0","author":"init","version":0},{"n":335,"text":"\t\t\t\treturn { status: 200, body: history.pathsOf(q.agent) };","atom":"a0","author":"init","version":0},{"n":336,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":337,"text":"\t\t\tif (!history.pathsAt) return fail(501, \"files needs the engine\");","atom":"a0","author":"init","version":0},{"n":338,"text":"\t\t\tconst version = q.version !== undefined && q.version !== \"\" ? Number(q.version) : undefined;","atom":"a0","author":"init","version":0},{"n":339,"text":"\t\t\tif (version !== undefined && !Number.isInteger(version)) return fail(400, \"version must be a number\");","atom":"a0","author":"init","version":0},{"n":340,"text":"\t\t\treturn { status: 200, body: history.pathsAt(version, q.draft || null) };","atom":"a0","author":"init","version":0},{"n":341,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":342,"text":"\t\tif (op === \"labels\") {","atom":"a0","author":"init","version":0},{"n":343,"text":"\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":344,"text":"\t\t\tif (!history.labels) return fail(501, \"labels needs the engine\");","atom":"a0","author":"init","version":0},{"n":345,"text":"\t\t\treturn { status: 200, body: history.labels() };","atom":"a0","author":"init","version":0},{"n":346,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":347,"text":"\t\tif (op === \"refusals\") {","atom":"a0","author":"init","version":0},{"n":348,"text":"\t\t\t// GET ?agent=<name>&limit=<n>: refused publishes and lands, newest first, and counts.","atom":"a0","author":"init","version":0},{"n":349,"text":"\t\t\tconst q = (body ?? {}) as Record<string, string | undefined>;","atom":"a0","author":"init","version":0},{"n":350,"text":"\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":351,"text":"\t\t\tif (!history.refusals) return fail(501, \"refusals needs the engine\");","atom":"a0","author":"init","version":0},{"n":352,"text":"\t\t\tconst limit = q.limit !== undefined && Number.isInteger(Number(q.limit)) ? Number(q.limit) : undefined;","atom":"a0","author":"init","version":0},{"n":353,"text":"\t\t\treturn { status: 200, body: history.refusals(q.agent || undefined, limit) };","atom":"a0","author":"init","version":0},{"n":354,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":355,"text":"\t\tif (op === \"without\") {","atom":"a2084","author":"candidates","version":186},{"n":356,"text":"\t\t\t// GET ?version=<n>&versions=<n,n>: version n of shared with those versions left out (without.ts).","atom":"a2084","author":"candidates","version":186},{"n":357,"text":"\t\t\tconst q = (body ?? {}) as Record<string, string | undefined>;","atom":"a2084","author":"candidates","version":186},{"n":358,"text":"\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a2084","author":"candidates","version":186},{"n":359,"text":"\t\t\tif (!history.without) return fail(501, \"without needs the engine\");","atom":"a2084","author":"candidates","version":186},{"n":360,"text":"\t\t\tconst version = q.version !== undefined && /^\\d+$/.test(q.version) ? Number(q.version) : undefined;","atom":"a2084","author":"candidates","version":186},{"n":361,"text":"\t\t\tconst versions = (q.versions ?? \"\").split(\",\").filter((s) => s.trim() !== \"\");","atom":"a2084","author":"candidates","version":186},{"n":362,"text":"\t\t\tif (version === undefined || versions.length === 0 || versions.some((s) => !/^\\s*\\d+\\s*$/.test(s)))","atom":"a2084","author":"candidates","version":186},{"n":363,"text":"\t\t\t\treturn fail(400, \"without needs ?version=<number>&versions=<number,number>\");","atom":"a2084","author":"candidates","version":186},{"n":364,"text":"\t\t\treturn { status: 200, body: history.without(version, versions.map(Number)) };","atom":"a2084","author":"candidates","version":186},{"n":365,"text":"\t\t}","atom":"a2084","author":"candidates","version":186},{"n":366,"text":"\t\tif (op === \"log\" || op === \"show\" || op === \"file\" || op === \"compare\") {","atom":"a0","author":"init","version":0},{"n":367,"text":"\t\t\t// GETs: ?draft=<name> (shared when absent); log ?limit, ?path; show ?version; file ?path, ?version; compare ?from, ?to.","atom":"a0","author":"init","version":0},{"n":368,"text":"\t\t\tconst q = (body ?? {}) as Record<string, string | undefined>;","atom":"a0","author":"init","version":0},{"n":369,"text":"\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":370,"text":"\t\t\tif (!history.log || !history.show || !history.fileAt || !history.compare)","atom":"a0","author":"init","version":0},{"n":371,"text":"\t\t\t\treturn fail(501, `${op} needs the engine`);","atom":"a0","author":"init","version":0},{"n":372,"text":"\t\t\tconst draft = q.draft ? q.draft : null;","atom":"a0","author":"init","version":0},{"n":373,"text":"\t\t\tconst int = (s: string | undefined): number | undefined =>","atom":"a0","author":"init","version":0},{"n":374,"text":"\t\t\t\ts !== undefined && s !== \"\" && Number.isInteger(Number(s)) ? Number(s) : undefined;","atom":"a0","author":"init","version":0},{"n":375,"text":"\t\t\tconst who = q.agent || undefined;","atom":"a0","author":"init","version":0},{"n":376,"text":"\t\t\tif (op === \"log\")","atom":"a0","author":"init","version":0},{"n":377,"text":"\t\t\t\treturn {","atom":"a0","author":"init","version":0},{"n":378,"text":"\t\t\t\t\tstatus: 200,","atom":"a0","author":"init","version":0},{"n":379,"text":"\t\t\t\t\tbody: history.log(","atom":"a0","author":"init","version":0},{"n":380,"text":"\t\t\t\t\t\tdraft,","atom":"a0","author":"init","version":0},{"n":381,"text":"\t\t\t\t\t\tint(q.limit),","atom":"a0","author":"init","version":0},{"n":382,"text":"\t\t\t\t\t\tq.path || undefined,","atom":"a0","author":"init","version":0},{"n":383,"text":"\t\t\t\t\t\twho,","atom":"a0","author":"init","version":0},{"n":384,"text":"\t\t\t\t\t\tint(q.before),","atom":"a0","author":"init","version":0},{"n":385,"text":"\t\t\t\t\t\tq.follow === \"1\" || q.follow === \"true\",","atom":"a0","author":"init","version":0},{"n":386,"text":"\t\t\t\t\t),","atom":"a0","author":"init","version":0},{"n":387,"text":"\t\t\t\t};","atom":"a0","author":"init","version":0},{"n":388,"text":"\t\t\tif (op === \"file\") {","atom":"a0","author":"init","version":0},{"n":389,"text":"\t\t\t\tconst version = int(q.version);","atom":"a0","author":"init","version":0},{"n":390,"text":"\t\t\t\tif (!q.path || version === undefined) return fail(400, \"file needs ?path=<path>&version=<number>\");","atom":"a0","author":"init","version":0},{"n":391,"text":"\t\t\t\treturn { status: 200, body: history.fileAt(q.path, version, draft, who) };","atom":"a0","author":"init","version":0},{"n":392,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":393,"text":"\t\t\tif (op === \"compare\") {","atom":"a0","author":"init","version":0},{"n":394,"text":"\t\t\t\tconst from = int(q.from);","atom":"a0","author":"init","version":0},{"n":395,"text":"\t\t\t\tconst to = int(q.to);","atom":"a0","author":"init","version":0},{"n":396,"text":"\t\t\t\tif (from === undefined || to === undefined) return fail(400, \"compare needs ?from=<number>&to=<number>\");","atom":"a0","author":"init","version":0},{"n":397,"text":"\t\t\t\t// summary=1: each file's size and SHA-256, not its texts (abso issue 680).","atom":"a2485","author":"capacity","version":243},{"n":398,"text":"\t\t\t\treturn { status: 200, body: history.compare(from, to, draft, who, q.summary === \"1\") };","atom":"a2485","author":"capacity","version":243},{"n":399,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":400,"text":"\t\t\tconst version = Number(q.version);","atom":"a0","author":"init","version":0},{"n":401,"text":"\t\t\tif (q.version === undefined || !Number.isInteger(version)) return fail(400, \"show needs ?version=<number>\");","atom":"a0","author":"init","version":0},{"n":402,"text":"\t\t\treturn { status: 200, body: history.show(version, draft, who) };","atom":"a0","author":"init","version":0},{"n":403,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":404,"text":"\t\tif (!validName(agent)) return fail(400, \"agent names use letters, digits, '.', '_' and '-'\");","atom":"a0","author":"init","version":0},{"n":405,"text":"\t\tif (op === \"reader\" && !readers) return fail(501, \"reader needs the Worker\");","atom":"a0","author":"init","version":0},{"n":406,"text":"\t\tconst gated = readers ? readerAnswer(project, op, agent, body, readers) : undefined;","atom":"a0","author":"init","version":0},{"n":407,"text":"\t\tif (gated) return gated;","atom":"a0","author":"init","version":0},{"n":408,"text":"\t\tswitch (op) {","atom":"a0","author":"init","version":0},{"n":409,"text":"\t\t\tcase \"edit\": {","atom":"a0","author":"init","version":0},{"n":410,"text":"\t\t\t\tconst b = body as EditBody;","atom":"a0","author":"init","version":0},{"n":411,"text":"\t\t\t\tif (!b || typeof b.file !== \"string\")","atom":"a0","author":"init","version":0},{"n":412,"text":"\t\t\t\t\treturn fail(400, \"edit needs {file, old, new}, {file, content} or {file, edits}\");","atom":"a0","author":"init","version":0},{"n":413,"text":"\t\t\t\tif (localPath([b.file])) return LOCAL(b.file);","atom":"a0","author":"init","version":0},{"n":414,"text":"\t\t\t\treturn { status: 200, body: project.edit(agent, b) };","atom":"a0","author":"init","version":0},{"n":415,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":416,"text":"\t\t\tcase \"record\": {","atom":"a0","author":"init","version":0},{"n":417,"text":"\t\t\t\tconst files = (body as { files?: Record<string, string | null> })?.files;","atom":"a0","author":"init","version":0},{"n":418,"text":"\t\t\t\tif (!files || typeof files !== \"object\") return fail(400, \"record needs {files: {path: text or null}}\");","atom":"a0","author":"init","version":0},{"n":419,"text":"\t\t\t\tconst bad = localPath(Object.keys(files));","atom":"a0","author":"init","version":0},{"n":420,"text":"\t\t\t\tif (bad) return LOCAL(bad);","atom":"a0","author":"init","version":0},{"n":421,"text":"\t\t\t\tconst modes = (body as { modes?: unknown })?.modes;","atom":"a0","author":"init","version":0},{"n":422,"text":"\t\t\t\tif (modes !== undefined && (typeof modes !== \"object\" || modes === null))","atom":"a0","author":"init","version":0},{"n":423,"text":"\t\t\t\t\treturn fail(400, \"modes must be {path: {exec, link}}\");","atom":"a0","author":"init","version":0},{"n":424,"text":"\t\t\t\tconst blobs = (body as { blobs?: unknown })?.blobs;","atom":"a0","author":"init","version":0},{"n":425,"text":"\t\t\t\tif (blobs !== undefined && (typeof blobs !== \"object\" || blobs === null))","atom":"a0","author":"init","version":0},{"n":426,"text":"\t\t\t\t\treturn fail(400, \"blobs must be {path: sha256}\");","atom":"a0","author":"init","version":0},{"n":427,"text":"\t\t\t\tif (blobs && localPath(Object.keys(blobs))) return LOCAL(localPath(Object.keys(blobs))!);","atom":"a0","author":"init","version":0},{"n":428,"text":"\t\t\t\tconst who = body as { session?: unknown; subagent?: unknown; client?: unknown };","atom":"a0","author":"init","version":0},{"n":429,"text":"\t\t\t\tconst meta = {","atom":"a0","author":"init","version":0},{"n":430,"text":"\t\t\t\t\t...(typeof who.session === \"string\" ? { session: who.session } : {}),","atom":"a0","author":"init","version":0},{"n":431,"text":"\t\t\t\t\t...(typeof who.subagent === \"string\" ? { subagent: who.subagent } : {}),","atom":"a0","author":"init","version":0},{"n":432,"text":"\t\t\t\t\t...(typeof who.client === \"string\" ? { client: who.client } : {}),","atom":"a0","author":"init","version":0},{"n":433,"text":"\t\t\t\t};","atom":"a0","author":"init","version":0},{"n":434,"text":"\t\t\t\treturn {","atom":"a0","author":"init","version":0},{"n":435,"text":"\t\t\t\t\tstatus: 200,","atom":"a0","author":"init","version":0},{"n":436,"text":"\t\t\t\t\tbody: project.record(","atom":"a0","author":"init","version":0},{"n":437,"text":"\t\t\t\t\t\tagent,","atom":"a0","author":"init","version":0},{"n":438,"text":"\t\t\t\t\t\tfiles,","atom":"a0","author":"init","version":0},{"n":439,"text":"\t\t\t\t\t\tmodes as Record<string, { exec?: boolean; link?: string | null }> | undefined,","atom":"a0","author":"init","version":0},{"n":440,"text":"\t\t\t\t\t\tblobs as Record<string, string> | undefined,","atom":"a0","author":"init","version":0},{"n":441,"text":"\t\t\t\t\t\tmeta,","atom":"a0","author":"init","version":0},{"n":442,"text":"\t\t\t\t\t),","atom":"a0","author":"init","version":0},{"n":443,"text":"\t\t\t\t};","atom":"a0","author":"init","version":0},{"n":444,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":445,"text":"\t\t\tcase \"publish\": {","atom":"a0","author":"init","version":0},{"n":446,"text":"\t\t\t\tconst message = (body as { message?: string })?.message;","atom":"a0","author":"init","version":0},{"n":447,"text":"\t\t\t\tif (typeof message !== \"string\" || !message.trim()) return fail(400, \"push needs {message} saying why\");","atom":"a872","author":"rename","version":100},{"n":448,"text":"\t\t\t\tconst unseen = unseenError(\"the message\", message);","atom":"a665","author":"engine","version":73},{"n":449,"text":"\t\t\t\tif (unseen) return fail(400, unseen);","atom":"a665","author":"engine","version":73},{"n":450,"text":"\t\t\t\t// asIs (#37): publish even with collided lines untouched since the sync, both sides kept.","atom":"a0","author":"init","version":0},{"n":451,"text":"\t\t\t\treturn { status: 200, body: project.publish(agent, message, (body as { asIs?: unknown }).asIs === true) };","atom":"a0","author":"init","version":0},{"n":452,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":453,"text":"\t\t\tcase \"sync\": {","atom":"a0","author":"init","version":0},{"n":454,"text":"\t\t\t\t// {label}: follow a label (#10), syncing to the newest version of shared that carries it.","atom":"a0","author":"init","version":0},{"n":455,"text":"\t\t\t\tconst label = (body as { label?: unknown } | undefined)?.label;","atom":"a0","author":"init","version":0},{"n":456,"text":"\t\t\t\tif ((body as { full?: unknown } | undefined)?.full === true) {","atom":"a0","author":"init","version":0},{"n":457,"text":"\t\t\t\t\t// {full: true}: every file in the agent's view, as a first sync answers (#37).","atom":"a0","author":"init","version":0},{"n":458,"text":"\t\t\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":459,"text":"\t\t\t\t\tif (!history.syncFull) return fail(501, \"a full pull needs the engine\");","atom":"a872","author":"rename","version":100},{"n":460,"text":"\t\t\t\t\tif (label !== undefined && typeof label !== \"string\") return fail(400, \"label must be a label name\");","atom":"a0","author":"init","version":0},{"n":461,"text":"\t\t\t\t\treturn { status: 200, body: history.syncFull(agent, label as string | undefined) };","atom":"a0","author":"init","version":0},{"n":462,"text":"\t\t\t\t}","atom":"a0","author":"init","version":0},{"n":463,"text":"\t\t\t\tif (label === undefined) return { status: 200, body: project.sync(agent) };","atom":"a0","author":"init","version":0},{"n":464,"text":"\t\t\t\tif (typeof label !== \"string\") return fail(400, \"label must be a label name\");","atom":"a0","author":"init","version":0},{"n":465,"text":"\t\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":466,"text":"\t\t\t\tif (!history.syncTo) return fail(501, \"following a label needs the engine\");","atom":"a0","author":"init","version":0},{"n":467,"text":"\t\t\t\treturn { status: 200, body: history.syncTo(agent, label) };","atom":"a0","author":"init","version":0},{"n":468,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":469,"text":"\t\t\tcase \"label\": {","atom":"a0","author":"init","version":0},{"n":470,"text":"\t\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":471,"text":"\t\t\t\tif (!history.label) return fail(501, \"label needs the engine\");","atom":"a0","author":"init","version":0},{"n":472,"text":"\t\t\t\tconst b = (body ?? {}) as { name?: unknown; version?: unknown; remove?: unknown };","atom":"a0","author":"init","version":0},{"n":473,"text":"\t\t\t\tif (typeof b.name !== \"string\") return fail(400, \"label needs {name}, and {version} unless it's the newest\");","atom":"a0","author":"init","version":0},{"n":474,"text":"\t\t\t\tif (b.version !== undefined && !Number.isInteger(b.version)) return fail(400, \"version must be a number\");","atom":"a0","author":"init","version":0},{"n":475,"text":"\t\t\t\treturn { status: 200, body: history.label(agent, b.name, b.version as number | undefined, b.remove === true) };","atom":"a0","author":"init","version":0},{"n":476,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":477,"text":"\t\t\t// Named drafts (#10).","atom":"a0","author":"init","version":0},{"n":478,"text":"\t\t\tcase \"draft\": {","atom":"a0","author":"init","version":0},{"n":479,"text":"\t\t\t\tconst name = (body as { name?: unknown })?.name;","atom":"a0","author":"init","version":0},{"n":480,"text":"\t\t\t\tif (name !== null && typeof name !== \"string\")","atom":"a0","author":"init","version":0},{"n":481,"text":"\t\t\t\t\treturn fail(400, \"draft needs {name}, or {name: null} for shared\");","atom":"a0","author":"init","version":0},{"n":482,"text":"\t\t\t\treturn { status: 200, body: project.switchTo(agent, name, (body as { carry?: unknown }).carry === true) };","atom":"a0","author":"init","version":0},{"n":483,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":484,"text":"\t\t\tcase \"land\": {","atom":"a0","author":"init","version":0},{"n":485,"text":"\t\t\t\tconst message = (body as { message?: string })?.message;","atom":"a0","author":"init","version":0},{"n":486,"text":"\t\t\t\tif (typeof message !== \"string\" || !message.trim()) return fail(400, \"land needs {message} saying why\");","atom":"a0","author":"init","version":0},{"n":487,"text":"\t\t\t\tconst unseen = unseenError(\"the message\", message);","atom":"a665","author":"engine","version":73},{"n":488,"text":"\t\t\t\tif (unseen) return fail(400, unseen);","atom":"a665","author":"engine","version":73},{"n":489,"text":"\t\t\t\treturn { status: 200, body: project.land(agent, message) };","atom":"a0","author":"init","version":0},{"n":490,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":491,"text":"\t\t\tcase \"draft-sync\":","atom":"a0","author":"init","version":0},{"n":492,"text":"\t\t\t\treturn { status: 200, body: project.syncDraft(agent) };","atom":"a0","author":"init","version":0},{"n":493,"text":"\t\t\t// The paths in the agent's view (#37): what its folder should hold. A GET; changes nothing.","atom":"a0","author":"init","version":0},{"n":494,"text":"\t\t\tcase \"files\": {","atom":"a0","author":"init","version":0},{"n":495,"text":"\t\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":496,"text":"\t\t\t\tif (!history.agentPaths) return fail(501, \"files needs the engine\");","atom":"a0","author":"init","version":0},{"n":497,"text":"\t\t\t\treturn { status: 200, body: history.agentPaths(agent) };","atom":"a0","author":"init","version":0},{"n":498,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":499,"text":"\t\t\t// abso status in one trip (abso issue 80): the project's status and the agent's paths.","atom":"a0","author":"init","version":0},{"n":500,"text":"\t\t\tcase \"status\": {","atom":"a0","author":"init","version":0},{"n":501,"text":"\t\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":502,"text":"\t\t\t\tif (!history.agentPaths) return fail(501, \"status needs the engine\");","atom":"a0","author":"init","version":0},{"n":503,"text":"\t\t\t\treturn {","atom":"a0","author":"init","version":0},{"n":504,"text":"\t\t\t\t\tstatus: 200,","atom":"a0","author":"init","version":0},{"n":505,"text":"\t\t\t\t\tbody: { ...(statusWithReaders(project.status(), readers) as object), files: history.agentPaths(agent) },","atom":"a0","author":"init","version":0},{"n":506,"text":"\t\t\t\t};","atom":"a0","author":"init","version":0},{"n":507,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":508,"text":"\t\t\t// Amend (#27): correct the message of the agent's newest publish.","atom":"a0","author":"init","version":0},{"n":509,"text":"\t\t\tcase \"amend\": {","atom":"a0","author":"init","version":0},{"n":510,"text":"\t\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":511,"text":"\t\t\t\tif (!history.amend) return fail(501, \"amend needs the engine\");","atom":"a0","author":"init","version":0},{"n":512,"text":"\t\t\t\tconst message = (body as { message?: unknown } | undefined)?.message;","atom":"a0","author":"init","version":0},{"n":513,"text":"\t\t\t\tif (typeof message !== \"string\" || !message.trim()) return fail(400, \"amend needs {message}\");","atom":"a0","author":"init","version":0},{"n":514,"text":"\t\t\t\tconst unseen = unseenError(\"the message\", message);","atom":"a665","author":"engine","version":73},{"n":515,"text":"\t\t\t\tif (unseen) return fail(400, unseen);","atom":"a665","author":"engine","version":73},{"n":516,"text":"\t\t\t\treturn { status: 200, body: history.amend(agent, message) };","atom":"a0","author":"init","version":0},{"n":517,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":518,"text":"\t\t\t// Pluck (#27): take some versions of a named draft into shared.","atom":"a0","author":"init","version":0},{"n":519,"text":"\t\t\tcase \"pluck\": {","atom":"a0","author":"init","version":0},{"n":520,"text":"\t\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":521,"text":"\t\t\t\tif (!history.pluck) return fail(501, \"pluck needs the engine\");","atom":"a0","author":"init","version":0},{"n":522,"text":"\t\t\t\tconst b = (body ?? {}) as {","atom":"a0","author":"init","version":0},{"n":523,"text":"\t\t\t\t\tdraft?: unknown;","atom":"a0","author":"init","version":0},{"n":524,"text":"\t\t\t\t\tversions?: unknown;","atom":"a0","author":"init","version":0},{"n":525,"text":"\t\t\t\t\tmessage?: unknown;","atom":"a0","author":"init","version":0},{"n":526,"text":"\t\t\t\t\twithDependencies?: unknown;","atom":"a0","author":"init","version":0},{"n":527,"text":"\t\t\t\t};","atom":"a0","author":"init","version":0},{"n":528,"text":"\t\t\t\tif (typeof b.draft !== \"string\") return fail(400, \"pluck needs {draft, versions: [number], message}\");","atom":"a0","author":"init","version":0},{"n":529,"text":"\t\t\t\tif (!Array.isArray(b.versions) || b.versions.length === 0 || !b.versions.every((v) => Number.isInteger(v)))","atom":"a0","author":"init","version":0},{"n":530,"text":"\t\t\t\t\treturn fail(400, \"pluck needs {versions: [number]}\");","atom":"a0","author":"init","version":0},{"n":531,"text":"\t\t\t\tif (typeof b.message !== \"string\" || !b.message.trim()) return fail(400, \"pluck needs {message} saying why\");","atom":"a0","author":"init","version":0},{"n":532,"text":"\t\t\t\tconst unseen = unseenError(\"the message\", b.message);","atom":"a665","author":"engine","version":73},{"n":533,"text":"\t\t\t\tif (unseen) return fail(400, unseen);","atom":"a665","author":"engine","version":73},{"n":534,"text":"\t\t\t\treturn {","atom":"a0","author":"init","version":0},{"n":535,"text":"\t\t\t\t\tstatus: 200,","atom":"a0","author":"init","version":0},{"n":536,"text":"\t\t\t\t\tbody: history.pluck(agent, b.draft, b.versions as number[], b.message, b.withDependencies === true),","atom":"a0","author":"init","version":0},{"n":537,"text":"\t\t\t\t};","atom":"a0","author":"init","version":0},{"n":538,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":539,"text":"\t\t\t// Drop (#10): take published versions out of shared.","atom":"a0","author":"init","version":0},{"n":540,"text":"\t\t\tcase \"drop\": {","atom":"a0","author":"init","version":0},{"n":541,"text":"\t\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":542,"text":"\t\t\t\tif (!history.drop) return fail(501, \"drop needs the engine\");","atom":"a0","author":"init","version":0},{"n":543,"text":"\t\t\t\tconst b = (body ?? {}) as { versions?: unknown; message?: unknown; withDependents?: unknown };","atom":"a0","author":"init","version":0},{"n":544,"text":"\t\t\t\tif (!Array.isArray(b.versions) || b.versions.length === 0 || !b.versions.every((v) => Number.isInteger(v)))","atom":"a0","author":"init","version":0},{"n":545,"text":"\t\t\t\t\treturn fail(400, \"drop needs {versions: [number], message}\");","atom":"a0","author":"init","version":0},{"n":546,"text":"\t\t\t\tif (typeof b.message !== \"string\" || !b.message.trim()) return fail(400, \"drop needs {message} saying why\");","atom":"a0","author":"init","version":0},{"n":547,"text":"\t\t\t\tconst unseen = unseenError(\"the message\", b.message);","atom":"a665","author":"engine","version":73},{"n":548,"text":"\t\t\t\tif (unseen) return fail(400, unseen);","atom":"a665","author":"engine","version":73},{"n":549,"text":"\t\t\t\treturn { status: 200, body: history.drop(agent, b.versions as number[], b.message, b.withDependents === true) };","atom":"a0","author":"init","version":0},{"n":550,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":551,"text":"\t\t\t// Announcements, and news without an edit.","atom":"a0","author":"init","version":0},{"n":552,"text":"\t\t\tcase \"move\": {","atom":"a0","author":"init","version":0},{"n":553,"text":"\t\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":554,"text":"\t\t\t\tif (!history.move) return fail(501, \"move needs the engine\");","atom":"a0","author":"init","version":0},{"n":555,"text":"\t\t\t\tconst b = (body ?? {}) as { from?: unknown; to?: unknown };","atom":"a0","author":"init","version":0},{"n":556,"text":"\t\t\t\tif (typeof b.from !== \"string\" || typeof b.to !== \"string\") return fail(400, \"move needs {from, to}\");","atom":"a0","author":"init","version":0},{"n":557,"text":"\t\t\t\tif (localPath([b.from, b.to])) return LOCAL(localPath([b.from, b.to])!);","atom":"a0","author":"init","version":0},{"n":558,"text":"\t\t\t\treturn { status: 200, body: history.move(agent, b.from, b.to) };","atom":"a0","author":"init","version":0},{"n":559,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":560,"text":"\t\t\tcase \"note\":","atom":"a0","author":"init","version":0},{"n":561,"text":"\t\t\tcase \"note-close\": {","atom":"a0","author":"init","version":0},{"n":562,"text":"\t\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":563,"text":"\t\t\t\tif (!history.note || !history.closeNote) return fail(501, `${op} needs the engine`);","atom":"a0","author":"init","version":0},{"n":564,"text":"\t\t\t\tconst b = (body ?? {}) as Record<string, unknown>;","atom":"a0","author":"init","version":0},{"n":565,"text":"\t\t\t\tif (op === \"note-close\") return { status: 200, body: history.closeNote(agent, b.id as number, b.how) };","atom":"a0","author":"init","version":0},{"n":566,"text":"\t\t\t\tconst unseen = unseenError(\"the note\", b.text);","atom":"a665","author":"engine","version":73},{"n":567,"text":"\t\t\t\tif (unseen) return fail(400, unseen);","atom":"a665","author":"engine","version":73},{"n":568,"text":"\t\t\t\treturn { status: 200, body: history.note(agent, b) };","atom":"a0","author":"init","version":0},{"n":569,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":570,"text":"\t\t\tcase \"announce\":","atom":"a0","author":"init","version":0},{"n":571,"text":"\t\t\tcase \"news\": {","atom":"a0","author":"init","version":0},{"n":572,"text":"\t\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":573,"text":"\t\t\t\tif (!history.announce || !history.news) return fail(501, `${op} needs the engine`);","atom":"a0","author":"init","version":0},{"n":574,"text":"\t\t\t\tif (op === \"news\") return { status: 200, body: history.news(agent) };","atom":"a0","author":"init","version":0},{"n":575,"text":"\t\t\t\tconst b = (body ?? {}) as { text?: unknown; to?: unknown };","atom":"a0","author":"init","version":0},{"n":576,"text":"\t\t\t\tif (typeof b.text !== \"string\" || !b.text.trim()) return fail(400, \"announce needs {text}\");","atom":"a0","author":"init","version":0},{"n":577,"text":"\t\t\t\tconst unseen = unseenError(\"the text\", b.text);","atom":"a665","author":"engine","version":73},{"n":578,"text":"\t\t\t\tif (unseen) return fail(400, unseen);","atom":"a665","author":"engine","version":73},{"n":579,"text":"\t\t\t\tif (b.to !== undefined && (!Array.isArray(b.to) || !b.to.every((a) => typeof a === \"string\")))","atom":"a0","author":"init","version":0},{"n":580,"text":"\t\t\t\t\treturn fail(400, \"to must be a list of agent names\");","atom":"a0","author":"init","version":0},{"n":581,"text":"\t\t\t\treturn { status: 200, body: history.announce(agent, b.text, b.to as string[] | undefined, how) };","atom":"a0","author":"init","version":0},{"n":582,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":583,"text":"\t\t\t// What the agent is starting on (#37, #13): {text, files?}, or {text: null} to take it back.","atom":"a0","author":"init","version":0},{"n":584,"text":"\t\t\tcase \"starting\": {","atom":"a0","author":"init","version":0},{"n":585,"text":"\t\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":586,"text":"\t\t\t\tif (!history.starting) return fail(501, \"starting needs the engine\");","atom":"a0","author":"init","version":0},{"n":587,"text":"\t\t\t\tconst b = (body ?? {}) as { text?: unknown; files?: unknown; issue?: unknown; done?: unknown };","atom":"a0","author":"init","version":0},{"n":588,"text":"\t\t\t\tif (b.text !== null && (typeof b.text !== \"string\" || !b.text.trim()))","atom":"a0","author":"init","version":0},{"n":589,"text":"\t\t\t\t\treturn fail(400, \"starting needs {text}, or {text: null} to take it back\");","atom":"a0","author":"init","version":0},{"n":590,"text":"\t\t\t\tconst unseen = unseenError(\"the note\", b.text);","atom":"a665","author":"engine","version":73},{"n":591,"text":"\t\t\t\tif (unseen) return fail(400, unseen);","atom":"a665","author":"engine","version":73},{"n":592,"text":"\t\t\t\tif (b.files !== undefined && (!Array.isArray(b.files) || !b.files.every((f) => typeof f === \"string\")))","atom":"a0","author":"init","version":0},{"n":593,"text":"\t\t\t\t\treturn fail(400, \"files must be a list of paths\");","atom":"a0","author":"init","version":0},{"n":594,"text":"\t\t\t\t// issue (#54): the issue the note works on; done: a take-back because the work is finished, closing it.","atom":"a0","author":"init","version":0},{"n":595,"text":"\t\t\t\treturn {","atom":"a0","author":"init","version":0},{"n":596,"text":"\t\t\t\t\tstatus: 200,","atom":"a0","author":"init","version":0},{"n":597,"text":"\t\t\t\t\tbody: history.starting(agent, b.text as string | null, b.files as string[] | undefined, {","atom":"a0","author":"init","version":0},{"n":598,"text":"\t\t\t\t\t\t...(b.issue !== undefined ? { issue: b.issue } : {}),","atom":"a0","author":"init","version":0},{"n":599,"text":"\t\t\t\t\t\t...(b.done !== undefined ? { done: b.done } : {}),","atom":"a0","author":"init","version":0},{"n":600,"text":"\t\t\t\t\t}),","atom":"a0","author":"init","version":0},{"n":601,"text":"\t\t\t\t};","atom":"a0","author":"init","version":0},{"n":602,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":603,"text":"\t\t\t// Everyday commands (#27).","atom":"a0","author":"init","version":0},{"n":604,"text":"\t\t\tcase \"diff\":","atom":"a0","author":"init","version":0},{"n":605,"text":"\t\t\tcase \"restore\": {","atom":"a0","author":"init","version":0},{"n":606,"text":"\t\t\t\tconst history = project as ProjectCalls & Partial<ProjectHistory>;","atom":"a0","author":"init","version":0},{"n":607,"text":"\t\t\t\tif (!history.diff || !history.restore) return fail(501, `${op} needs the engine`);","atom":"a0","author":"init","version":0},{"n":608,"text":"\t\t\t\tif (op === \"diff\") return { status: 200, body: history.diff(agent) };","atom":"a0","author":"init","version":0},{"n":609,"text":"\t\t\t\tconst b = (body ?? {}) as { files?: unknown; all?: unknown };","atom":"a0","author":"init","version":0},{"n":610,"text":"\t\t\t\tif (b.all === true) return { status: 200, body: history.restore(agent, null) };","atom":"a0","author":"init","version":0},{"n":611,"text":"\t\t\t\tif (!Array.isArray(b.files) || !b.files.every((f) => typeof f === \"string\")) {","atom":"a0","author":"init","version":0},{"n":612,"text":"\t\t\t\t\treturn fail(400, \"restore needs {files: [path]} or {all: true}\");","atom":"a0","author":"init","version":0},{"n":613,"text":"\t\t\t\t}","atom":"a0","author":"init","version":0},{"n":614,"text":"\t\t\t\treturn { status: 200, body: history.restore(agent, b.files as string[]) };","atom":"a0","author":"init","version":0},{"n":615,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":616,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":617,"text":"\t\treturn fail(404, `no such operation: ${op}`);","atom":"a0","author":"init","version":0},{"n":618,"text":"\t} catch (e) {","atom":"a0","author":"init","version":0},{"n":619,"text":"\t\t// The engine throws ProjectError with a code; anything else is ours.","atom":"a0","author":"init","version":0},{"n":620,"text":"\t\tconst code = (e as { code?: string }).code;","atom":"a0","author":"init","version":0},{"n":621,"text":"\t\tconst status =","atom":"a0","author":"init","version":0},{"n":622,"text":"\t\t\tcode === \"not-implemented\"","atom":"a0","author":"init","version":0},{"n":623,"text":"\t\t\t\t? 501","atom":"a0","author":"init","version":0},{"n":624,"text":"\t\t\t\t: code === \"not-initialized\" || code === \"not-found\"","atom":"a0","author":"init","version":0},{"n":625,"text":"\t\t\t\t\t? 404","atom":"a0","author":"init","version":0},{"n":626,"text":"\t\t\t\t\t: code === \"already-initialized\" || code === \"conflict\"","atom":"a0","author":"init","version":0},{"n":627,"text":"\t\t\t\t\t\t? 409","atom":"a0","author":"init","version":0},{"n":628,"text":"\t\t\t\t\t\t: code === \"bad-request\" || code === \"bad-agent\"","atom":"a0","author":"init","version":0},{"n":629,"text":"\t\t\t\t\t\t\t? 400","atom":"a0","author":"init","version":0},{"n":630,"text":"\t\t\t\t\t\t\t: 500;","atom":"a0","author":"init","version":0},{"n":631,"text":"\t\treturn fail(status, e instanceof Error ? e.message : String(e));","atom":"a0","author":"init","version":0},{"n":632,"text":"\t}","atom":"a0","author":"init","version":0},{"n":633,"text":"}","atom":"a0","author":"init","version":0}],"atoms":[{"atom":"a0","author":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z","publish":{"draft":null,"version":0,"agent":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z"}},{"atom":"a132","author":"pinch","message":"","time":1791523142973,"timeIso":"2026-10-09T05:19:02.973Z","publish":{"draft":null,"version":18,"agent":"pinch","message":"New folders keep .avcs/ for now; the server keeps both state folders out of a project\n\nVersion 17 made new folders with .abso/. An edit mod or Cursor hook installed before the rename looks only for .avcs/config.json, so in a .abso/ folder it would stop recording edits, and nothing would say so. Until installs can say which mods know .abso/, a new folder is made with .avcs/ again (NEW_FOLDER_DIR in client/src/state-dir.ts). Reading is unchanged: a folder with .abso/ works exactly as one with .avcs/, and neither is ever half-moved. The user's files still go to ~/.abso/, since an older client that can't find them says so.\n\nThe server refused only paths under .avcs/, and the test server only .abso/. Both now refuse both, so a folder's state never becomes part of a project, whichever name it has.\n\nTests: new folders get .avcs/; a folder moved to .abso/ records and isn't moved back; the tests that assumed .abso/ for a new folder now use .avcs/.","time":1791523143960,"timeIso":"2026-10-09T05:19:03.960Z"}},{"atom":"a327","author":"infra-split","message":"","time":1791546813593,"timeIso":"2026-10-09T11:53:33.593Z","publish":{"draft":null,"version":37,"agent":"infra-split","message":"Comments and test names give each reason in plain words, without naming who raised it\n\nNotes like \"(#37, Builder 5)\" or \"(AVCS - Security)\" become \"(#37)\" or go, and a private commit hash after a name goes with it. Issue numbers and references such as git's CVE-2019-1353 stay. Only comments and test names change; no behavior changes.","time":1791547035956,"timeIso":"2026-10-09T11:57:15.956Z"}},{"atom":"a665","author":"engine","message":"","time":1791610870534,"timeIso":"2026-10-10T05:41:10.534Z","publish":{"draft":null,"version":73,"agent":"engine","message":"Messages and notes can't hold characters a reader can't see: publish, land, amend, pluck and drop messages, starting notes, line notes and announcements are refused when they hold control characters other than tab and newline (CRLF passes), or zero-width, bidirectional or tag characters. It's the same list the website's announcements and Issues use.","time":1791610877933,"timeIso":"2026-10-10T05:41:17.933Z"}},{"atom":"a872","author":"rename","message":"","time":1791659799126,"timeIso":"2026-10-10T19:16:39.126Z","publish":{"draft":null,"version":100,"agent":"rename","message":"abso publish is now abso push, abso sync is now abso pull (abso 427)\n\nCommands, help, flags, messages, MCP tool names and descriptions, hook text, README, SKILL.md and tests say push and pull; \"shared\" stays the noun (\"Pushed version N\"). No aliases, no notices. A queued push that was \"pulled\" is now \"turned back\", so pull means one thing.\n\npush -f/--force/-u/--all/--tags and pull --rebase/--ff-only/--squash refuse with one plain line naming the abso way; push and pull take no remote or branch.\n\nKept as stored: log entry kinds (publish, sync, pulled), HTTP route paths, the pipeline trigger on: publish, the yours (unpublished) marker, npm-publish.","time":1791659833853,"timeIso":"2026-10-10T19:17:13.853Z"}},{"atom":"a2084","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":"a2175","author":"whytrail","message":"","time":1792019576836,"timeIso":"2026-10-14T23:12:56.836Z","publish":{"draft":null,"version":193,"agent":"whytrail","message":"abso why follows a line back past formatting to its reason, and names git commits\n\nwhy now lists a line's earlier changes, newest first, with what the line read before each. A change that rewrote a line left the line it replaced in the file's history; why pairs the two (same code formatted differently, the same code rewrapped, or the most similar line) and follows the pairs back. A change that only touched formatting (whitespace, line wrapping, quotes, trailing commas, line-end semicolons, parentheses around a lone arrow parameter) is skipped by default, and why names it: 'Skipped 1 formatting change since: version 366'. --all shows those too. --at <version> reads the line as it was at that version.\n\nA push imported from git (client/scripts/import-git.ts, or a plain git push) names its commit and author in why and blame. import-git.ts now also records where the repository's issues are, from origin on GitHub or GitLab or --issues, and why says which issue #N in an imported message or line means. A project imported before this can say it once in abso.json: \"gitIssues\": \"https://github.com/owner/repo/issues\".\n\nCloses issues 20 and 21's tool side.","time":1792019638939,"timeIso":"2026-10-14T23:13:58.939Z"}},{"atom":"a2485","author":"capacity","message":"","time":1792072853745,"timeIso":"2026-10-15T14:00:53.745Z","publish":{"draft":null,"version":243,"agent":"capacity","message":"compare's summary: each changed file's size and SHA-256 instead of its texts (abso issue 680; disk-first 2; abso Capacity).\n\ncompare 612 to 1224 on abso answers 13.2 MB: the full before and after text of about 3,000 changed files. Read Speed's shape lets the site ask for a summary and fetch a file's texts when it opens it.\n\n- view-changes.ts summariesBetween: the files changesBetween would list, each side as {size, sha256} for text (UTF-8 bytes, SHA-256 of the text), {blob} for a binary file (its hash; the Worker adds its size from the blob store), or null when absent; mode and blob as in the full answer. Each text is read, summed up and let go.\n- version-log compare takes summary and answers {from, to, summary: true, files}. ProjectHistory.compare and both engine-project.ts implementations take a fifth argument, summary; http.ts passes ?summary=1. The full answer is unchanged.\n\nOn abso adopted fresh: the summary for 612 to 1224 is 174 KB instead of 13.2 MB, with heap after at 38 MB. The time is the same (about 20 s cold): it still lays the files out to hash them. Stored per-version sizes and hashes would remove that; they're proposed with the author totals table.\n\nNew test compare-summary: on an in-memory and a writer-backed project, the summary lists the files the full compare does, with sizes and SHA-256s of its texts, blob hashes for a binary file, and no text. Every engine test (292 of 292), every worker/project test (342 of 342); tsc (worker and server) and biome clean.","time":1792072854373,"timeIso":"2026-10-15T14:00:54.373Z"}},{"atom":"a2548","author":"approvals-page","message":"","time":1792083665112,"timeIso":"2026-10-15T17:01:05.112Z","publish":{"draft":null,"version":250,"agent":"approvals-page","message":"Readers talk (abso 682, Christopher: 'readers need to be able to do asks and news and stuff', 'and make issues etc'): a reader agent may announce, note lines and close notes again. Being a reader limits code only: edit, record, publish, land, pluck, draft-sync, drop, amend, label, starting and move stay refused. Undoes the communication refusals of 248. Test: client/test/client.test.ts 'a reader talks: it announces, notes lines and closes notes, but still can't start or push (abso 682)', which fails with the refusal back.","time":1792083930921,"timeIso":"2026-10-15T17:05:30.921Z"}}]}