{"file":"worker/project/notes.ts","version":318,"total":326,"from":1,"to":326,"lines":[{"n":1,"text":"// Notes on lines and review areas (#44): where a note's lines are now and what that makes it, who","atom":"a0","author":"init","version":0},{"n":2,"text":"// reviews which files by avcs.json, the notes list, every agent's start note, and writing or closing","atom":"a0","author":"init","version":0},{"n":3,"text":"// a note. Reads go through NoteHost, writes through NoteWriteHost; today the host is Project.","atom":"a0","author":"init","version":0},{"n":4,"text":"","atom":"a0","author":"init","version":0},{"n":5,"text":"import type { AtomId, Graph, LineId, ReadView } from \"../../src/engine/index.ts\";","atom":"a1346","author":"codex-capacity-chair","version":143},{"n":6,"text":"import { matchesPattern } from \"./globs.ts\";","atom":"a0","author":"init","version":0},{"n":7,"text":"import { type NewsItem, noteClosedItem, noteSaid } from \"./news.ts\";","atom":"a0","author":"init","version":0},{"n":8,"text":"import { checkReadPath } from \"./path-rules.ts\";","atom":"a0","author":"init","version":0},{"n":9,"text":"import { ProjectError } from \"./project-error.ts\";","atom":"a0","author":"init","version":0},{"n":10,"text":"import type {","atom":"a0","author":"init","version":0},{"n":11,"text":"\tAgentState,","atom":"a0","author":"init","version":0},{"n":12,"text":"\tChangeRecord,","atom":"a0","author":"init","version":0},{"n":13,"text":"\tEntry,","atom":"a0","author":"init","version":0},{"n":14,"text":"\tNoteAnswer,","atom":"a0","author":"init","version":0},{"n":15,"text":"\tNoteBody,","atom":"a0","author":"init","version":0},{"n":16,"text":"\tNoteRecord,","atom":"a0","author":"init","version":0},{"n":17,"text":"\tPersonSender,","atom":"a0","author":"init","version":0},{"n":18,"text":"\tStarting,","atom":"a0","author":"init","version":0},{"n":19,"text":"} from \"./project-types.ts\";","atom":"a0","author":"init","version":0},{"n":20,"text":"import { last, SHARED, type Space } from \"./spaces.ts\";","atom":"a0","author":"init","version":0},{"n":21,"text":"","atom":"a0","author":"init","version":0},{"n":22,"text":"/** What the note reads need from a project. */","atom":"a0","author":"init","version":0},{"n":23,"text":"export interface NoteHost {","atom":"a0","author":"init","version":0},{"n":24,"text":"\treadonly graph: Graph;","atom":"a0","author":"init","version":0},{"n":25,"text":"\treadonly agents: ReadonlyMap<string, AgentState>;","atom":"a0","author":"init","version":0},{"n":26,"text":"\treadonly spaces: ReadonlyMap<string, Space>;","atom":"a0","author":"init","version":0},{"n":27,"text":"\treadonly notes: ReadonlyMap<number, NoteRecord>;","atom":"a0","author":"init","version":0},{"n":28,"text":"\tinitialized(): boolean;","atom":"a0","author":"init","version":0},{"n":29,"text":"\tshared(): Space;","atom":"a0","author":"init","version":0},{"n":30,"text":"\tsharedView(): ReadView;","atom":"a1346","author":"codex-capacity-chair","version":143},{"n":31,"text":"\tspellingIn(view: ReadView, path: string): string;","atom":"a1346","author":"codex-capacity-chair","version":143},{"n":32,"text":"\tviewAt(space: Space, version: number): ReadView;","atom":"a1346","author":"codex-capacity-chair","version":143},{"n":33,"text":"\tagentView(agent: AgentState): ReadView;","atom":"a1346","author":"codex-capacity-chair","version":143},{"n":34,"text":"\tview(set: ReadonlySet<AtomId>): ReadView;","atom":"a1346","author":"codex-capacity-chair","version":143},{"n":35,"text":"\tat(space: Space, version: number): ReadonlySet<AtomId>;","atom":"a0","author":"init","version":0},{"n":36,"text":"\tliveNote(agent: AgentState): Starting | undefined;","atom":"a0","author":"init","version":0},{"n":37,"text":"}","atom":"a0","author":"init","version":0},{"n":38,"text":"","atom":"a0","author":"init","version":0},{"n":39,"text":"/** What writing or closing a note needs from a project. */","atom":"a0","author":"init","version":0},{"n":40,"text":"export interface NoteWriteHost {","atom":"a0","author":"init","version":0},{"n":41,"text":"\treadonly notes: Map<number, NoteRecord>;","atom":"a0","author":"init","version":0},{"n":42,"text":"\treadonly agents: ReadonlyMap<string, AgentState>;","atom":"a0","author":"init","version":0},{"n":43,"text":"\treadonly changes: ReadonlyMap<number, ChangeRecord>;","atom":"a0","author":"init","version":0},{"n":44,"text":"\treadonly graph: Graph;","atom":"a0","author":"init","version":0},{"n":45,"text":"\tlastNote(): number;","atom":"a0","author":"init","version":0},{"n":46,"text":"\tagentView(agent: AgentState): ReadView;","atom":"a1346","author":"codex-capacity-chair","version":143},{"n":47,"text":"\tviewAtVersion(version: number): ReadView;","atom":"a1346","author":"codex-capacity-chair","version":143},{"n":48,"text":"\tsharedView(): ReadView;","atom":"a1346","author":"codex-capacity-chair","version":143},{"n":49,"text":"\tchangeOfLines(lines: readonly LineId[]): number | undefined;","atom":"a0","author":"init","version":0},{"n":50,"text":"\tapply(entry: Entry): void;","atom":"a0","author":"init","version":0},{"n":51,"text":"\tflush(entries: Entry[]): void;","atom":"a0","author":"init","version":0},{"n":52,"text":"\tqueueNews(agent: AgentState, items: NewsItem[], entries: Entry[]): void;","atom":"a0","author":"init","version":0},{"n":53,"text":"\tnoteAnswer(n: NoteRecord): NoteAnswer;","atom":"a0","author":"init","version":0},{"n":54,"text":"}","atom":"a0","author":"init","version":0},{"n":55,"text":"","atom":"a0","author":"init","version":0},{"n":56,"text":"export interface ReviewRule {","atom":"a0","author":"init","version":0},{"n":57,"text":"\treadonly paths: string[];","atom":"a0","author":"init","version":0},{"n":58,"text":"\treadonly reviewer: string;","atom":"a0","author":"init","version":0},{"n":59,"text":"}","atom":"a0","author":"init","version":0},{"n":60,"text":"","atom":"a0","author":"init","version":0},{"n":61,"text":"/** The project's reviewers per area: avcs.json's `\"review\": [{\"paths\": [...], \"reviewer\": \"...\"}]`. */","atom":"a0","author":"init","version":0},{"n":62,"text":"export function reviewRulesIn(avcsJson: string | undefined): ReviewRule[] {","atom":"a0","author":"init","version":0},{"n":63,"text":"\tif (avcsJson === undefined) return [];","atom":"a0","author":"init","version":0},{"n":64,"text":"\tlet review: unknown;","atom":"a0","author":"init","version":0},{"n":65,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":66,"text":"\t\treview = (JSON.parse(avcsJson) as { review?: unknown }).review;","atom":"a0","author":"init","version":0},{"n":67,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":68,"text":"\t\treturn [];","atom":"a0","author":"init","version":0},{"n":69,"text":"\t}","atom":"a0","author":"init","version":0},{"n":70,"text":"\tif (!Array.isArray(review)) return [];","atom":"a0","author":"init","version":0},{"n":71,"text":"\treturn review.flatMap((r) => {","atom":"a0","author":"init","version":0},{"n":72,"text":"\t\tconst { paths, reviewer } = (r ?? {}) as { paths?: unknown; reviewer?: unknown };","atom":"a0","author":"init","version":0},{"n":73,"text":"\t\treturn Array.isArray(paths) &&","atom":"a0","author":"init","version":0},{"n":74,"text":"\t\t\tpaths.every((p) => typeof p === \"string\") &&","atom":"a0","author":"init","version":0},{"n":75,"text":"\t\t\ttypeof reviewer === \"string\" &&","atom":"a0","author":"init","version":0},{"n":76,"text":"\t\t\treviewer !== \"\"","atom":"a0","author":"init","version":0},{"n":77,"text":"\t\t\t? [{ paths: paths as string[], reviewer }]","atom":"a0","author":"init","version":0},{"n":78,"text":"\t\t\t: [];","atom":"a0","author":"init","version":0},{"n":79,"text":"\t});","atom":"a0","author":"init","version":0},{"n":80,"text":"}","atom":"a0","author":"init","version":0},{"n":81,"text":"","atom":"a0","author":"init","version":0},{"n":82,"text":"/** Each reviewer whose area these files fall in, the files that do, and whether it has noted the change. */","atom":"a0","author":"init","version":0},{"n":83,"text":"export function reviewersOf(","atom":"a0","author":"init","version":0},{"n":84,"text":"\trules: readonly ReviewRule[],","atom":"a0","author":"init","version":0},{"n":85,"text":"\tfiles: readonly string[],","atom":"a0","author":"init","version":0},{"n":86,"text":"\thasNoted: (agent: string) => boolean,","atom":"a0","author":"init","version":0},{"n":87,"text":"): { agent: string; files: string[]; read: boolean }[] {","atom":"a0","author":"init","version":0},{"n":88,"text":"\tconst out = new Map<string, Set<string>>();","atom":"a0","author":"init","version":0},{"n":89,"text":"\tfor (const rule of rules) {","atom":"a0","author":"init","version":0},{"n":90,"text":"\t\tconst matched = files.filter((f) => rule.paths.some((p) => matchesPattern(p, f)));","atom":"a0","author":"init","version":0},{"n":91,"text":"\t\tif (matched.length === 0) continue;","atom":"a0","author":"init","version":0},{"n":92,"text":"\t\tconst set = out.get(rule.reviewer) ?? new Set<string>();","atom":"a0","author":"init","version":0},{"n":93,"text":"\t\tfor (const f of matched) set.add(f);","atom":"a0","author":"init","version":0},{"n":94,"text":"\t\tout.set(rule.reviewer, set);","atom":"a0","author":"init","version":0},{"n":95,"text":"\t}","atom":"a0","author":"init","version":0},{"n":96,"text":"\treturn [...out]","atom":"a0","author":"init","version":0},{"n":97,"text":"\t\t.sort(([a], [b]) => (a < b ? -1 : 1))","atom":"a0","author":"init","version":0},{"n":98,"text":"\t\t.map(([agent, set]) => ({ agent, files: [...set].sort(), read: hasNoted(agent) }));","atom":"a0","author":"init","version":0},{"n":99,"text":"}","atom":"a0","author":"init","version":0},{"n":100,"text":"","atom":"a0","author":"init","version":0},{"n":101,"text":"/** A note as reads show it, from the view its lines live in (undefined when no space holds them any more). */","atom":"a0","author":"init","version":0},{"n":102,"text":"export function noteAnswerIn(n: NoteRecord, view: ReadView | undefined): NoteAnswer {","atom":"a1346","author":"codex-capacity-chair","version":143},{"n":103,"text":"\t// Where the lines are now, found by their ids: a move (#49) can have taken them to another file.","atom":"a0","author":"init","version":0},{"n":104,"text":"\tlet lines: [number, number] | null = null;","atom":"a0","author":"init","version":0},{"n":105,"text":"\tlet file = n.file;","atom":"a0","author":"init","version":0},{"n":106,"text":"\tif (view) {","atom":"a0","author":"init","version":0},{"n":107,"text":"\t\tconst found: { file: string; at: number }[] = [];","atom":"a0","author":"init","version":0},{"n":108,"text":"\t\tfor (const id of n.lines) {","atom":"a0","author":"init","version":0},{"n":109,"text":"\t\t\tconst f = view.fileOf(id);","atom":"a0","author":"init","version":0},{"n":110,"text":"\t\t\tconst at = view.lineNumber(f, id);","atom":"a0","author":"init","version":0},{"n":111,"text":"\t\t\tif (at >= 0) found.push({ file: f, at: at + 1 });","atom":"a0","author":"init","version":0},{"n":112,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":113,"text":"\t\tif (found.length > 0) {","atom":"a0","author":"init","version":0},{"n":114,"text":"\t\t\tfile = found[0]!.file;","atom":"a0","author":"init","version":0},{"n":115,"text":"\t\t\tconst at = found.filter((x) => x.file === file).map((x) => x.at);","atom":"a0","author":"init","version":0},{"n":116,"text":"\t\t\tlines = [Math.min(...at), Math.max(...at)];","atom":"a0","author":"init","version":0},{"n":117,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":118,"text":"\t}","atom":"a0","author":"init","version":0},{"n":119,"text":"\tconst state = n.closed ? n.closed.how : lines !== null ? \"open\" : n.kind === \"objection\" ? \"addressed\" : \"outdated\";","atom":"a0","author":"init","version":0},{"n":120,"text":"\treturn {","atom":"a0","author":"init","version":0},{"n":121,"text":"\t\tid: n.id,","atom":"a0","author":"init","version":0},{"n":122,"text":"\t\tagent: n.agent,","atom":"a0","author":"init","version":0},{"n":123,"text":"\t\tkind: n.kind,","atom":"a0","author":"init","version":0},{"n":124,"text":"\t\tfile,","atom":"a0","author":"init","version":0},{"n":125,"text":"\t\tlines,","atom":"a0","author":"init","version":0},{"n":126,"text":"\t\ttext: n.text,","atom":"a0","author":"init","version":0},{"n":127,"text":"\t\tchange: n.change ?? null,","atom":"a0","author":"init","version":0},{"n":128,"text":"\t\treply: n.reply ?? null,","atom":"a0","author":"init","version":0},{"n":129,"text":"\t\ttime: n.time,","atom":"a0","author":"init","version":0},{"n":130,"text":"\t\tstate,","atom":"a0","author":"init","version":0},{"n":131,"text":"\t\t...(n.person ? { person: { ...n.person.person } } : {}),","atom":"a0","author":"init","version":0},{"n":132,"text":"\t};","atom":"a0","author":"init","version":0},{"n":133,"text":"}","atom":"a0","author":"init","version":0},{"n":134,"text":"","atom":"a0","author":"init","version":0},{"n":135,"text":"/**","atom":"a0","author":"init","version":0},{"n":136,"text":" * The view a note's lines live in (#44):","atom":"a328","author":"infra-split","version":37},{"n":137,"text":" * shared once any were published there; else the named draft they were","atom":"a0","author":"init","version":0},{"n":138,"text":" * published into; else their author's draft, where it works now or where it","atom":"a0","author":"init","version":0},{"n":139,"text":" * parked it. Undefined when no space holds them any more (a discarded draft).","atom":"a0","author":"init","version":0},{"n":140,"text":" */","atom":"a0","author":"init","version":0},{"n":141,"text":"export function noteView(host: NoteHost, n: NoteRecord): ReadView | undefined {","atom":"a1346","author":"codex-capacity-chair","version":143},{"n":142,"text":"\tconst writers = new Set(n.lines.map((l) => host.graph.lineAtom(l)).filter((a): a is AtomId => a !== undefined));","atom":"a0","author":"init","version":0},{"n":143,"text":"\tconst holds = (set: ReadonlySet<AtomId> | readonly AtomId[]) =>","atom":"a0","author":"init","version":0},{"n":144,"text":"\t\t[...writers].some((a) => (set instanceof Set ? set.has(a) : (set as readonly AtomId[]).includes(a)));","atom":"a0","author":"init","version":0},{"n":145,"text":"\tif (holds(host.shared().own)) return host.sharedView();","atom":"a0","author":"init","version":0},{"n":146,"text":"\tfor (const space of host.spaces.values())","atom":"a0","author":"init","version":0},{"n":147,"text":"\t\tif (space !== host.shared() && holds(space.own)) return host.viewAt(space, last(space));","atom":"a0","author":"init","version":0},{"n":148,"text":"\tconst first = [...writers][0];","atom":"a0","author":"init","version":0},{"n":149,"text":"\tconst author = first === undefined ? undefined : host.agents.get(host.graph.atom(first).author);","atom":"a0","author":"init","version":0},{"n":150,"text":"\tif (!author) return undefined;","atom":"a0","author":"init","version":0},{"n":151,"text":"\tif (holds(author.mine)) return host.agentView(author);","atom":"a0","author":"init","version":0},{"n":152,"text":"\tfor (const [name, parked] of author.parked) {","atom":"a0","author":"init","version":0},{"n":153,"text":"\t\tconst space = host.spaces.get(name);","atom":"a0","author":"init","version":0},{"n":154,"text":"\t\tif (space && holds(parked.mine)) return host.view(new Set([...host.at(space, parked.base), ...parked.mine]));","atom":"a0","author":"init","version":0},{"n":155,"text":"\t}","atom":"a0","author":"init","version":0},{"n":156,"text":"\treturn undefined;","atom":"a0","author":"init","version":0},{"n":157,"text":"}","atom":"a0","author":"init","version":0},{"n":158,"text":"","atom":"a0","author":"init","version":0},{"n":159,"text":"export function noteAnswer(host: NoteHost, n: NoteRecord): NoteAnswer {","atom":"a0","author":"init","version":0},{"n":160,"text":"\treturn noteAnswerIn(n, noteView(host, n));","atom":"a0","author":"init","version":0},{"n":161,"text":"}","atom":"a0","author":"init","version":0},{"n":162,"text":"","atom":"a0","author":"init","version":0},{"n":163,"text":"/** Notes, oldest first: on a file, on a change, or only the ones still open. */","atom":"a0","author":"init","version":0},{"n":164,"text":"export function notes(","atom":"a0","author":"init","version":0},{"n":165,"text":"\thost: NoteHost,","atom":"a0","author":"init","version":0},{"n":166,"text":"\toptions: { file?: string; change?: number; open?: boolean } = {},","atom":"a0","author":"init","version":0},{"n":167,"text":"): { notes: NoteAnswer[] } {","atom":"a0","author":"init","version":0},{"n":168,"text":"\t// Any spelling reads the stored one (#41, F7).","atom":"a0","author":"init","version":0},{"n":169,"text":"\tconst file =","atom":"a0","author":"init","version":0},{"n":170,"text":"\t\toptions.file === undefined || !host.initialized() ? options.file : host.spellingIn(host.sharedView(), options.file);","atom":"a0","author":"init","version":0},{"n":171,"text":"\tconst out = [...host.notes.values()]","atom":"a0","author":"init","version":0},{"n":172,"text":"\t\t.filter((n) => options.change === undefined || n.change === options.change)","atom":"a0","author":"init","version":0},{"n":173,"text":"\t\t.map((n) => ({ n, a: noteAnswer(host, n) }))","atom":"a0","author":"init","version":0},{"n":174,"text":"\t\t.filter(({ n, a }) => file === undefined || a.file === file || n.file === file)","atom":"a0","author":"init","version":0},{"n":175,"text":"\t\t.map(({ a }) => a)","atom":"a0","author":"init","version":0},{"n":176,"text":"\t\t.filter((n) => !options.open || n.state === \"open\");","atom":"a0","author":"init","version":0},{"n":177,"text":"\treturn { notes: out };","atom":"a0","author":"init","version":0},{"n":178,"text":"}","atom":"a0","author":"init","version":0},{"n":179,"text":"","atom":"a0","author":"init","version":0},{"n":180,"text":"/** Every agent's starting note, by agent name. */","atom":"a0","author":"init","version":0},{"n":181,"text":"export function startingNotes(","atom":"a0","author":"init","version":0},{"n":182,"text":"\thost: NoteHost,","atom":"a0","author":"init","version":0},{"n":183,"text":"): { agent: string; draft: string | null; text: string; files: string[]; time: number }[] {","atom":"a0","author":"init","version":0},{"n":184,"text":"\treturn [...host.agents.values()]","atom":"a0","author":"init","version":0},{"n":185,"text":"\t\t.filter((a) => host.liveNote(a))","atom":"a0","author":"init","version":0},{"n":186,"text":"\t\t.toSorted((a, b) => (a.name < b.name ? -1 : 1))","atom":"a0","author":"init","version":0},{"n":187,"text":"\t\t.map((a) => {","atom":"a0","author":"init","version":0},{"n":188,"text":"\t\t\tconst note = host.liveNote(a)!;","atom":"a0","author":"init","version":0},{"n":189,"text":"\t\t\treturn { agent: a.name, draft: a.space === SHARED ? null : a.space, ...note, files: [...note.files] };","atom":"a0","author":"init","version":0},{"n":190,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":191,"text":"}","atom":"a0","author":"init","version":0},{"n":192,"text":"","atom":"a0","author":"init","version":0},{"n":193,"text":"export function writeNote(","atom":"a0","author":"init","version":0},{"n":194,"text":"\thost: NoteWriteHost,","atom":"a0","author":"init","version":0},{"n":195,"text":"\tentries: Entry[],","atom":"a0","author":"init","version":0},{"n":196,"text":"\twriterOf: () => { name: string; person?: PersonSender },","atom":"a0","author":"init","version":0},{"n":197,"text":"\tbody: NoteBody,","atom":"a0","author":"init","version":0},{"n":198,"text":"\ttime: number,","atom":"a0","author":"init","version":0},{"n":199,"text":"): { id: number; change: number | null; lines: [number, number] } {","atom":"a0","author":"init","version":0},{"n":200,"text":"\tconst text = body.text;","atom":"a0","author":"init","version":0},{"n":201,"text":"\tif (typeof text !== \"string\" || text.trim() === \"\") throw new ProjectError(\"bad-request\", \"a note needs {text}\");","atom":"a0","author":"init","version":0},{"n":202,"text":"\tif (text.length > 4000) throw new ProjectError(\"bad-request\", \"a note is at most 4000 characters\");","atom":"a0","author":"init","version":0},{"n":203,"text":"\tconst kind = body.kind ?? \"comment\";","atom":"a0","author":"init","version":0},{"n":204,"text":"\tif (kind !== \"comment\" && kind !== \"objection\" && kind !== \"read\")","atom":"a0","author":"init","version":0},{"n":205,"text":"\t\tthrow new ProjectError(\"bad-request\", \"kind is comment, objection or read\");","atom":"a0","author":"init","version":0},{"n":206,"text":"\tlet file: string;","atom":"a0","author":"init","version":0},{"n":207,"text":"\tlet lines: LineId[];","atom":"a0","author":"init","version":0},{"n":208,"text":"\tlet change: number | undefined;","atom":"a0","author":"init","version":0},{"n":209,"text":"\tlet reply: number | undefined;","atom":"a0","author":"init","version":0},{"n":210,"text":"\tif (body.reply !== undefined) {","atom":"a0","author":"init","version":0},{"n":211,"text":"\t\tconst parent = Number.isInteger(body.reply) ? host.notes.get(body.reply as number) : undefined;","atom":"a0","author":"init","version":0},{"n":212,"text":"\t\tif (!parent) throw new ProjectError(\"not-found\", `there is no note ${String(body.reply)}`);","atom":"a0","author":"init","version":0},{"n":213,"text":"\t\treply = parent.reply ?? parent.id;","atom":"a0","author":"init","version":0},{"n":214,"text":"\t\t({ file, change } = parent);","atom":"a0","author":"init","version":0},{"n":215,"text":"\t\tlines = [...parent.lines];","atom":"a0","author":"init","version":0},{"n":216,"text":"\t} else {","atom":"a0","author":"init","version":0},{"n":217,"text":"\t\tif (typeof body.file !== \"string\")","atom":"a0","author":"init","version":0},{"n":218,"text":"\t\t\tthrow new ProjectError(\"bad-request\", \"a note needs {file, from, to}, or {reply}\");","atom":"a0","author":"init","version":0},{"n":219,"text":"\t\tfile = body.file;","atom":"a0","author":"init","version":0},{"n":220,"text":"\t\tcheckReadPath(file);","atom":"a0","author":"init","version":0},{"n":221,"text":"\t\tlet view: ReadView;","atom":"a1346","author":"codex-capacity-chair","version":143},{"n":222,"text":"\t\tif (typeof body.of === \"string\") {","atom":"a0","author":"init","version":0},{"n":223,"text":"\t\t\tconst of = host.agents.get(body.of);","atom":"a0","author":"init","version":0},{"n":224,"text":"\t\t\tif (!of) throw new ProjectError(\"not-found\", `there is no agent ${JSON.stringify(body.of)}`);","atom":"a0","author":"init","version":0},{"n":225,"text":"\t\t\tview = host.agentView(of);","atom":"a0","author":"init","version":0},{"n":226,"text":"\t\t} else if (body.version !== undefined) {","atom":"a0","author":"init","version":0},{"n":227,"text":"\t\t\tview = host.viewAtVersion(body.version as number);","atom":"a0","author":"init","version":0},{"n":228,"text":"\t\t} else {","atom":"a0","author":"init","version":0},{"n":229,"text":"\t\t\tview = host.sharedView();","atom":"a0","author":"init","version":0},{"n":230,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":231,"text":"\t\tif (!view.hasFile(file)) throw new ProjectError(\"not-found\", `there is no ${file} there`);","atom":"a0","author":"init","version":0},{"n":232,"text":"\t\tconst shown = view.lines(file);","atom":"a0","author":"init","version":0},{"n":233,"text":"\t\tconst from = body.from ?? 1;","atom":"a0","author":"init","version":0},{"n":234,"text":"\t\tconst to = body.to ?? from;","atom":"a0","author":"init","version":0},{"n":235,"text":"\t\tif (","atom":"a0","author":"init","version":0},{"n":236,"text":"\t\t\t!Number.isInteger(from) ||","atom":"a0","author":"init","version":0},{"n":237,"text":"\t\t\t!Number.isInteger(to) ||","atom":"a0","author":"init","version":0},{"n":238,"text":"\t\t\t(from as number) < 1 ||","atom":"a0","author":"init","version":0},{"n":239,"text":"\t\t\t(to as number) < (from as number) ||","atom":"a0","author":"init","version":0},{"n":240,"text":"\t\t\t(to as number) > shown.length","atom":"a0","author":"init","version":0},{"n":241,"text":"\t\t) {","atom":"a0","author":"init","version":0},{"n":242,"text":"\t\t\tthrow new ProjectError(\"bad-request\", `from and to are line numbers in ${file}, 1 to ${shown.length}`);","atom":"a0","author":"init","version":0},{"n":243,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":244,"text":"\t\tif ((to as number) - (from as number) >= 500)","atom":"a0","author":"init","version":0},{"n":245,"text":"\t\t\tthrow new ProjectError(\"bad-request\", \"a note covers at most 500 lines\");","atom":"a0","author":"init","version":0},{"n":246,"text":"\t\tlines = shown.slice((from as number) - 1, to as number).map((l) => l.id);","atom":"a0","author":"init","version":0},{"n":247,"text":"\t\tchange = host.changeOfLines(lines);","atom":"a0","author":"init","version":0},{"n":248,"text":"\t}","atom":"a0","author":"init","version":0},{"n":249,"text":"\tconst writer = writerOf();","atom":"a0","author":"init","version":0},{"n":250,"text":"\tconst id = host.lastNote() + 1;","atom":"a0","author":"init","version":0},{"n":251,"text":"\tconst entry: Entry = {","atom":"a0","author":"init","version":0},{"n":252,"text":"\t\ttype: \"note\",","atom":"a0","author":"init","version":0},{"n":253,"text":"\t\tid,","atom":"a0","author":"init","version":0},{"n":254,"text":"\t\tagent: writer.name,","atom":"a0","author":"init","version":0},{"n":255,"text":"\t\tkind,","atom":"a0","author":"init","version":0},{"n":256,"text":"\t\tfile,","atom":"a0","author":"init","version":0},{"n":257,"text":"\t\tlines,","atom":"a0","author":"init","version":0},{"n":258,"text":"\t\ttext: text.trim(),","atom":"a0","author":"init","version":0},{"n":259,"text":"\t\t...(change !== undefined ? { change } : {}),","atom":"a0","author":"init","version":0},{"n":260,"text":"\t\t...(reply !== undefined ? { reply } : {}),","atom":"a0","author":"init","version":0},{"n":261,"text":"\t\ttime,","atom":"a0","author":"init","version":0},{"n":262,"text":"\t\t...(writer.person ? { person: writer.person } : {}),","atom":"a0","author":"init","version":0},{"n":263,"text":"\t};","atom":"a0","author":"init","version":0},{"n":264,"text":"\tentries.push(entry);","atom":"a0","author":"init","version":0},{"n":265,"text":"\thost.apply(entry);","atom":"a0","author":"init","version":0},{"n":266,"text":"\tconst note = host.notes.get(id)!;","atom":"a0","author":"init","version":0},{"n":267,"text":"\tconst where = host.noteAnswer(note).lines;","atom":"a0","author":"init","version":0},{"n":268,"text":"\tif (kind !== \"read\") {","atom":"a0","author":"init","version":0},{"n":269,"text":"\t\tconst rec = change !== undefined ? host.changes.get(change) : undefined;","atom":"a0","author":"init","version":0},{"n":270,"text":"\t\tconst hearers = new Set<string>();","atom":"a0","author":"init","version":0},{"n":271,"text":"\t\tfor (const l of lines) {","atom":"a0","author":"init","version":0},{"n":272,"text":"\t\t\tconst info = host.graph.line(l);","atom":"a0","author":"init","version":0},{"n":273,"text":"\t\t\tif (info) hearers.add(host.graph.atom(info.atom).author);","atom":"a0","author":"init","version":0},{"n":274,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":275,"text":"\t\tif (rec) hearers.add(rec.agent);","atom":"a0","author":"init","version":0},{"n":276,"text":"\t\tif (reply !== undefined)","atom":"a0","author":"init","version":0},{"n":277,"text":"\t\t\tfor (const n of host.notes.values()) if (n.id === reply || n.reply === reply) hearers.add(n.agent);","atom":"a0","author":"init","version":0},{"n":278,"text":"\t\thearers.delete(writer.name);","atom":"a0","author":"init","version":0},{"n":279,"text":"\t\tconst said = noteSaid({","atom":"a0","author":"init","version":0},{"n":280,"text":"\t\t\tid,","atom":"a0","author":"init","version":0},{"n":281,"text":"\t\t\twriter: writer.name,","atom":"a0","author":"init","version":0},{"n":282,"text":"\t\t\t...(writer.person ? { person: writer.person } : {}),","atom":"a0","author":"init","version":0},{"n":283,"text":"\t\t\tkind,","atom":"a0","author":"init","version":0},{"n":284,"text":"\t\t\treply: reply !== undefined,","atom":"a0","author":"init","version":0},{"n":285,"text":"\t\t\tfile,","atom":"a0","author":"init","version":0},{"n":286,"text":"\t\t\twhere,","atom":"a0","author":"init","version":0},{"n":287,"text":"\t\t\t...(rec ? { change: rec.note?.text ?? rec.versions[0]?.message ?? \"\" } : {}),","atom":"a0","author":"init","version":0},{"n":288,"text":"\t\t\ttext: text.trim(),","atom":"a0","author":"init","version":0},{"n":289,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":290,"text":"\t\tfor (const name of [...hearers].toSorted()) {","atom":"a0","author":"init","version":0},{"n":291,"text":"\t\t\tconst a = host.agents.get(name);","atom":"a0","author":"init","version":0},{"n":292,"text":"\t\t\tif (a) host.queueNews(a, [{ key: `note ${id}`, text: said }], entries);","atom":"a0","author":"init","version":0},{"n":293,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":294,"text":"\t}","atom":"a0","author":"init","version":0},{"n":295,"text":"\thost.flush(entries);","atom":"a0","author":"init","version":0},{"n":296,"text":"\treturn { id, change: change ?? null, lines: where ?? [0, 0] };","atom":"a0","author":"init","version":0},{"n":297,"text":"}","atom":"a0","author":"init","version":0},{"n":298,"text":"","atom":"a0","author":"init","version":0},{"n":299,"text":"/** Close a note: only its writer can (#44). */","atom":"a0","author":"init","version":0},{"n":300,"text":"export function closeNote(","atom":"a0","author":"init","version":0},{"n":301,"text":"\thost: NoteWriteHost,","atom":"a0","author":"init","version":0},{"n":302,"text":"\tagentName: string,","atom":"a0","author":"init","version":0},{"n":303,"text":"\tid: number,","atom":"a0","author":"init","version":0},{"n":304,"text":"\thow: unknown,","atom":"a0","author":"init","version":0},{"n":305,"text":"\ttime: number,","atom":"a0","author":"init","version":0},{"n":306,"text":"\tperson?: PersonSender,","atom":"a0","author":"init","version":0},{"n":307,"text":"): NoteAnswer {","atom":"a0","author":"init","version":0},{"n":308,"text":"\tconst note = Number.isInteger(id) ? host.notes.get(id) : undefined;","atom":"a0","author":"init","version":0},{"n":309,"text":"\tif (!note) throw new ProjectError(\"not-found\", `there is no note ${String(id)}`);","atom":"a0","author":"init","version":0},{"n":310,"text":"\tif (how !== \"resolved\" && how !== \"withdrawn\") throw new ProjectError(\"bad-request\", \"how is resolved or withdrawn\");","atom":"a0","author":"init","version":0},{"n":311,"text":"\tif (note.agent !== agentName)","atom":"a0","author":"init","version":0},{"n":312,"text":"\t\tthrow new ProjectError(\"conflict\", `only ${note.agent}, who wrote note ${id}, can close it`);","atom":"a0","author":"init","version":0},{"n":313,"text":"\tif (note.closed) return host.noteAnswer(note);","atom":"a0","author":"init","version":0},{"n":314,"text":"\tconst entries: Entry[] = [];","atom":"a0","author":"init","version":0},{"n":315,"text":"\tconst entry: Entry = { type: \"note-closed\", id, agent: agentName, how, time, ...(person ? { person } : {}) };","atom":"a0","author":"init","version":0},{"n":316,"text":"\tentries.push(entry);","atom":"a0","author":"init","version":0},{"n":317,"text":"\thost.apply(entry);","atom":"a0","author":"init","version":0},{"n":318,"text":"\tconst rec = note.change !== undefined ? host.changes.get(note.change) : undefined;","atom":"a0","author":"init","version":0},{"n":319,"text":"\tif (rec && rec.agent !== agentName && note.kind === \"objection\") {","atom":"a0","author":"init","version":0},{"n":320,"text":"\t\tconst a = host.agents.get(rec.agent);","atom":"a0","author":"init","version":0},{"n":321,"text":"\t\tif (a) host.queueNews(a, [noteClosedItem(agentName, how, id, note)], entries);","atom":"a0","author":"init","version":0},{"n":322,"text":"\t}","atom":"a0","author":"init","version":0},{"n":323,"text":"\thost.flush(entries);","atom":"a0","author":"init","version":0},{"n":324,"text":"\t// Storage-backed maps return snapshots; apply may replace the stored row.","atom":"a987","author":"codex-capacity-chair","version":109},{"n":325,"text":"\treturn host.noteAnswer(host.notes.get(id)!);","atom":"a987","author":"codex-capacity-chair","version":109},{"n":326,"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":"a328","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":"a987","author":"codex-capacity-chair","message":"","time":1791824699039,"timeIso":"2026-10-12T17:04:59.039Z","publish":{"draft":null,"version":109,"agent":"codex-capacity-chair","message":"Add opt-in persistent writer state, checked reopen and bounded adoption","time":1791825459416,"timeIso":"2026-10-12T17:17:39.416Z"}},{"atom":"a1346","author":"codex-capacity-chair","message":"","time":1791854964720,"timeIso":"2026-10-13T01:29:24.720Z","publish":{"draft":null,"version":143,"agent":"codex-capacity-chair","message":"Add inactive disk projection provider and verified transactional readers (#16)","time":1791855032023,"timeIso":"2026-10-13T01:30:32.023Z"}}]}