Lines 1–8 at 318 (were 1–6 at 59)
11// The JSON routes of the contract (docs/v2-slice1.md), as a pure function of 22// the project calls, so they can be tested in Node without a Worker. 34import type { EditBody, ProjectCalls, ProjectHistory } from "./project-api.ts"; 5+import { unseenError } from "./unseen.ts"; 57export interface Answer { Lines 49–59 at 318 (were 47–55 at 59)
50− * What a reader may not do. Edits and records (which old edit mods send on
51− * their own) and publishes answer 200 {ok: false, reason}, so a mod only logs
52− * it; the rest are refused outright.
52+ * What a reader may not do: change code. Edits and records (which old edit 53+ * mods send on their own) and publishes answer 200 {ok: false, reason}, so a 54+ * mod only logs it; the rest are refused outright. Talking stays open (abso 55+ * 682, Christopher: "readers need to be able to do asks and news and stuff"): 56+ * announcements, notes on lines, asks and issues all work for a reader. 5458const NOT_FOR_READERS: Record<string, "answer" | "refuse"> = { Lines 100–106 at 318 (were 96–102 at 59)
96100 if (me && (me.draftChanges > 0 || (me.parked?.length ?? 0) > 0)) { 99− `${agent} has unpublished changes; publish or restore them (abso restore --all) before it becomes a reader`,
103+ `${agent} has unpushed changes; push or restore them (abso restore --all) before it becomes a reader`, Lines 318–324 at 318 (were 314–320 at 59)
314318 return { status: 200, body: history.blame(q.file, num(q.from), num(q.to), num(q.version), draft, who) }; 315319 const line = num(q.line); 316320 if (!line || !Number.isInteger(line)) return fail(400, "why needs ?line=<number>"); 317− return { status: 200, body: history.why(q.file, line, draft, who) };
321+ return { status: 200, body: history.why(q.file, line, draft, who, num(q.version)) }; 319323 if (op === "announce" && agent === undefined) { 320324 // The sender comes from the route, like every other agent op, not from Lines 352–368 at 318 (were 348–353 at 59)
348352 const limit = q.limit !== undefined && Number.isInteger(Number(q.limit)) ? Number(q.limit) : undefined; 349353 return { status: 200, body: history.refusals(q.agent || undefined, limit) }; 355+ if (op === "without") { 356+ // GET ?version=<n>&versions=<n,n>: version n of shared with those versions left out (without.ts). 357+ const q = (body ?? {}) as Record<string, string | undefined>; 358+ const history = project as ProjectCalls & Partial<ProjectHistory>; 359+ if (!history.without) return fail(501, "without needs the engine"); 360+ const version = q.version !== undefined && /^\d+$/.test(q.version) ? Number(q.version) : undefined; 361+ const versions = (q.versions ?? "").split(",").filter((s) => s.trim() !== ""); 362+ if (version === undefined || versions.length === 0 || versions.some((s) => !/^\s*\d+\s*$/.test(s))) 363+ return fail(400, "without needs ?version=<number>&versions=<number,number>"); 364+ return { status: 200, body: history.without(version, versions.map(Number)) }; 351366 if (op === "log" || op === "show" || op === "file" || op === "compare") { 352367 // GETs: ?draft=<name> (shared when absent); log ?limit, ?path; show ?version; file ?path, ?version; compare ?from, ?to. 353368 const q = (body ?? {}) as Record<string, string | undefined>; Lines 394–401 at 318 (were 379–385 at 59)
379394 const from = int(q.from); 380395 const to = int(q.to); 381396 if (from === undefined || to === undefined) return fail(400, "compare needs ?from=<number>&to=<number>"); 382− return { status: 200, body: history.compare(from, to, draft, who) };
397+ // summary=1: each file's size and SHA-256, not its texts (abso issue 680). 398+ return { status: 200, body: history.compare(from, to, draft, who, q.summary === "1") }; 384400 const version = Number(q.version); 385401 if (q.version === undefined || !Number.isInteger(version)) return fail(400, "show needs ?version=<number>"); Lines 444–452 at 318 (were 428–434 at 59)
430446 const message = (body as { message?: string })?.message; 431− if (typeof message !== "string" || !message.trim()) return fail(400, "publish needs {message} saying why");
447+ if (typeof message !== "string" || !message.trim()) return fail(400, "push needs {message} saying why"); 448+ const unseen = unseenError("the message", message); 449+ if (unseen) return fail(400, unseen); 432450 // asIs (#37): publish even with collided lines untouched since the sync, both sides kept. 433451 return { status: 200, body: project.publish(agent, message, (body as { asIs?: unknown }).asIs === true) }; Lines 456–462 at 318 (were 438–444 at 59)
438456 if ((body as { full?: unknown } | undefined)?.full === true) { 439457 // {full: true}: every file in the agent's view, as a first sync answers (#37). 440458 const history = project as ProjectCalls & Partial<ProjectHistory>; 441− if (!history.syncFull) return fail(501, "a full sync needs the engine");
459+ if (!history.syncFull) return fail(501, "a full pull needs the engine"); 442460 if (label !== undefined && typeof label !== "string") return fail(400, "label must be a label name"); 443461 return { status: 200, body: history.syncFull(agent, label as string | undefined) }; Lines 484–491 at 318 (were 466–471 at 59)
467485 const message = (body as { message?: string })?.message; 468486 if (typeof message !== "string" || !message.trim()) return fail(400, "land needs {message} saying why"); 487+ const unseen = unseenError("the message", message); 488+ if (unseen) return fail(400, unseen); 469489 return { status: 200, body: project.land(agent, message) }; 471491 case "draft-sync": Lines 511–518 at 318 (were 491–496 at 59)
491511 if (!history.amend) return fail(501, "amend needs the engine"); 492512 const message = (body as { message?: unknown } | undefined)?.message; 493513 if (typeof message !== "string" || !message.trim()) return fail(400, "amend needs {message}"); 514+ const unseen = unseenError("the message", message); 515+ if (unseen) return fail(400, unseen); 494516 return { status: 200, body: history.amend(agent, message) }; 496518 // Pluck (#27): take some versions of a named draft into shared. Lines 529–536 at 318 (were 507–512 at 59)
507529 if (!Array.isArray(b.versions) || b.versions.length === 0 || !b.versions.every((v) => Number.isInteger(v))) 508530 return fail(400, "pluck needs {versions: [number]}"); 509531 if (typeof b.message !== "string" || !b.message.trim()) return fail(400, "pluck needs {message} saying why"); 532+ const unseen = unseenError("the message", b.message); 533+ if (unseen) return fail(400, unseen); 512536 body: history.pluck(agent, b.draft, b.versions as number[], b.message, b.withDependencies === true), Lines 544–551 at 318 (were 520–525 at 59)
520544 if (!Array.isArray(b.versions) || b.versions.length === 0 || !b.versions.every((v) => Number.isInteger(v))) 521545 return fail(400, "drop needs {versions: [number], message}"); 522546 if (typeof b.message !== "string" || !b.message.trim()) return fail(400, "drop needs {message} saying why"); 547+ const unseen = unseenError("the message", b.message); 548+ if (unseen) return fail(400, unseen); 523549 return { status: 200, body: history.drop(agent, b.versions as number[], b.message, b.withDependents === true) }; 525551 // Announcements, and news without an edit. Lines 563–570 at 318 (were 537–542 at 59)
537563 if (!history.note || !history.closeNote) return fail(501, `${op} needs the engine`); 538564 const b = (body ?? {}) as Record<string, unknown>; 539565 if (op === "note-close") return { status: 200, body: history.closeNote(agent, b.id as number, b.how) }; 566+ const unseen = unseenError("the note", b.text); 567+ if (unseen) return fail(400, unseen); 540568 return { status: 200, body: history.note(agent, b) }; Lines 574–581 at 318 (were 546–551 at 59)
546574 if (op === "news") return { status: 200, body: history.news(agent) }; 547575 const b = (body ?? {}) as { text?: unknown; to?: unknown }; 548576 if (typeof b.text !== "string" || !b.text.trim()) return fail(400, "announce needs {text}"); 577+ const unseen = unseenError("the text", b.text); 578+ if (unseen) return fail(400, unseen); 549579 if (b.to !== undefined && (!Array.isArray(b.to) || !b.to.every((a) => typeof a === "string"))) 550580 return fail(400, "to must be a list of agent names"); 551581 return { status: 200, body: history.announce(agent, b.text, b.to as string[] | undefined, how) }; Lines 587–594 at 318 (were 557–562 at 59)
557587 const b = (body ?? {}) as { text?: unknown; files?: unknown; issue?: unknown; done?: unknown }; 558588 if (b.text !== null && (typeof b.text !== "string" || !b.text.trim())) 559589 return fail(400, "starting needs {text}, or {text: null} to take it back"); 590+ const unseen = unseenError("the note", b.text); 591+ if (unseen) return fail(400, unseen); 560592 if (b.files !== undefined && (!Array.isArray(b.files) || !b.files.every((f) => typeof f === "string"))) 561593 return fail(400, "files must be a list of paths"); 562594 // issue (#54): the issue the note works on; done: a take-back because the work is finished, closing it.