- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/worker/project/draft-diff.ts?version=277&format=json
48 linesFirst import 83% · codex-capacity-chair 17%Last change codex-capacity-chair in version 163, 3 versions changed it
You're reading version 277. The newest is 318, and no version since then changed this file.
1// An agent's unpublished changes, file by file. They read through DraftDiffHost; today the host is the project
2// in memory.
4import type { AtomId, ReadView } from "../../src/engine/index.ts";
5import { ProjectError } from "./project-error.ts";
6import type { DiffAnswer } from "./project-types.ts";
7import { SHARED } from "./spaces.ts";
8import { changesBetween } from "./view-changes.ts";
10interface Agent {
11 readonly space: string;
12 readonly base: number;
13}
15/** What the draft diff reads need from a project. */
16export interface DraftDiffHost {
17 readonly agents: ReadonlyMap<string, Agent>;
18 needInit(): void;
19 draft(agent: Agent): AtomId[];
20 agentView(agent: Agent): ReadView;
21 agentViewWithout?(agent: Agent, excluded: ReadonlySet<AtomId>): ReadView;
22 view(set: ReadonlySet<AtomId>): ReadView;
23 touchedFiles(ids: Iterable<AtomId>, views: readonly ReadView[]): Set<string>;
24}
26/** An agent's draft diff for a reader (#41, the website): never creates the agent, never writes. */
27export function diffOf(host: DraftDiffHost, agentName: string): DiffAnswer {
28 host.needInit();
29 const agent = host.agents.get(agentName);
30 if (!agent) throw new ProjectError("not-found", `there is no agent ${JSON.stringify(agentName)}`);
31 return diffOfAgent(host, agent);
32}
34/** What the agent's unpublished changes do, file by file: its space at its base, then its view. */
35export function diffOfAgent(host: DraftDiffHost, agent: Agent): DiffAnswer {
36 const draft = host.draft(agent);
37 const after = host.agentView(agent);
38 const without = new Set(draft);
39 const before = host.agentViewWithout
40 ? host.agentViewWithout(agent, without)
41 : host.view(new Set([...after.set].filter((id) => !without.has(id))));
42 const files = host.touchedFiles(draft, [before, after]);
43 return {
44 draft: agent.space === SHARED ? null : agent.space,
45 base: agent.base,
46 files: changesBetween(before, after, files),
47 };
48}