{"file":"worker/project/draft-diff.ts","version":318,"total":48,"from":1,"to":48,"lines":[{"n":1,"text":"// An agent's unpublished changes, file by file. They read through DraftDiffHost; today the host is the project","atom":"a0","author":"init","version":0},{"n":2,"text":"// in memory.","atom":"a0","author":"init","version":0},{"n":3,"text":"","atom":"a0","author":"init","version":0},{"n":4,"text":"import type { AtomId, ReadView } from \"../../src/engine/index.ts\";","atom":"a1335","author":"codex-capacity-chair","version":143},{"n":5,"text":"import { ProjectError } from \"./project-error.ts\";","atom":"a0","author":"init","version":0},{"n":6,"text":"import type { DiffAnswer } from \"./project-types.ts\";","atom":"a0","author":"init","version":0},{"n":7,"text":"import { SHARED } from \"./spaces.ts\";","atom":"a0","author":"init","version":0},{"n":8,"text":"import { changesBetween } from \"./view-changes.ts\";","atom":"a0","author":"init","version":0},{"n":9,"text":"","atom":"a0","author":"init","version":0},{"n":10,"text":"interface Agent {","atom":"a0","author":"init","version":0},{"n":11,"text":"\treadonly space: string;","atom":"a0","author":"init","version":0},{"n":12,"text":"\treadonly base: number;","atom":"a0","author":"init","version":0},{"n":13,"text":"}","atom":"a0","author":"init","version":0},{"n":14,"text":"","atom":"a0","author":"init","version":0},{"n":15,"text":"/** What the draft diff reads need from a project. */","atom":"a0","author":"init","version":0},{"n":16,"text":"export interface DraftDiffHost {","atom":"a0","author":"init","version":0},{"n":17,"text":"\treadonly agents: ReadonlyMap<string, Agent>;","atom":"a0","author":"init","version":0},{"n":18,"text":"\tneedInit(): void;","atom":"a0","author":"init","version":0},{"n":19,"text":"\tdraft(agent: Agent): AtomId[];","atom":"a0","author":"init","version":0},{"n":20,"text":"\tagentView(agent: Agent): ReadView;","atom":"a1335","author":"codex-capacity-chair","version":143},{"n":21,"text":"\tagentViewWithout?(agent: Agent, excluded: ReadonlySet<AtomId>): ReadView;","atom":"a1778","author":"codex-capacity-chair","version":163},{"n":22,"text":"\tview(set: ReadonlySet<AtomId>): ReadView;","atom":"a1335","author":"codex-capacity-chair","version":143},{"n":23,"text":"\ttouchedFiles(ids: Iterable<AtomId>, views: readonly ReadView[]): Set<string>;","atom":"a1335","author":"codex-capacity-chair","version":143},{"n":24,"text":"}","atom":"a0","author":"init","version":0},{"n":25,"text":"","atom":"a0","author":"init","version":0},{"n":26,"text":"/** An agent's draft diff for a reader (#41, the website): never creates the agent, never writes. */","atom":"a0","author":"init","version":0},{"n":27,"text":"export function diffOf(host: DraftDiffHost, agentName: string): DiffAnswer {","atom":"a0","author":"init","version":0},{"n":28,"text":"\thost.needInit();","atom":"a0","author":"init","version":0},{"n":29,"text":"\tconst agent = host.agents.get(agentName);","atom":"a0","author":"init","version":0},{"n":30,"text":"\tif (!agent) throw new ProjectError(\"not-found\", `there is no agent ${JSON.stringify(agentName)}`);","atom":"a0","author":"init","version":0},{"n":31,"text":"\treturn diffOfAgent(host, agent);","atom":"a0","author":"init","version":0},{"n":32,"text":"}","atom":"a0","author":"init","version":0},{"n":33,"text":"","atom":"a0","author":"init","version":0},{"n":34,"text":"/** What the agent's unpublished changes do, file by file: its space at its base, then its view. */","atom":"a0","author":"init","version":0},{"n":35,"text":"export function diffOfAgent(host: DraftDiffHost, agent: Agent): DiffAnswer {","atom":"a0","author":"init","version":0},{"n":36,"text":"\tconst draft = host.draft(agent);","atom":"a0","author":"init","version":0},{"n":37,"text":"\tconst after = host.agentView(agent);","atom":"a0","author":"init","version":0},{"n":38,"text":"\tconst without = new Set(draft);","atom":"a0","author":"init","version":0},{"n":39,"text":"\tconst before = host.agentViewWithout","atom":"a1778","author":"codex-capacity-chair","version":163},{"n":40,"text":"\t\t? host.agentViewWithout(agent, without)","atom":"a1778","author":"codex-capacity-chair","version":163},{"n":41,"text":"\t\t: host.view(new Set([...after.set].filter((id) => !without.has(id))));","atom":"a1778","author":"codex-capacity-chair","version":163},{"n":42,"text":"\tconst files = host.touchedFiles(draft, [before, after]);","atom":"a0","author":"init","version":0},{"n":43,"text":"\treturn {","atom":"a0","author":"init","version":0},{"n":44,"text":"\t\tdraft: agent.space === SHARED ? null : agent.space,","atom":"a0","author":"init","version":0},{"n":45,"text":"\t\tbase: agent.base,","atom":"a0","author":"init","version":0},{"n":46,"text":"\t\tfiles: changesBetween(before, after, files),","atom":"a0","author":"init","version":0},{"n":47,"text":"\t};","atom":"a0","author":"init","version":0},{"n":48,"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":"a1335","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"}},{"atom":"a1778","author":"codex-capacity-chair","message":"","time":1791948048631,"timeIso":"2026-10-14T03:20:48.631Z","publish":{"draft":null,"version":163,"agent":"codex-capacity-chair","message":"Integrate reviewed disk-backed operations, queue and bounded read caches","time":1791949753900,"timeIso":"2026-10-14T03:49:13.900Z"}}]}