Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/worker/project/add-draft.ts?format=json
77 linesFirst import 95% · codex-capacity-chair 5%Last change codex-capacity-chair in version 175, 3 versions changed it
1// Build a draft change against the agent's view. Writes go through
2// AddDraftHost; today the host is Project.
3
4import {
5 type Atom,
6 type AtomId,
7 type AttrSet,
8 buildAtom,
9 claimsOf,
10 type EditInput,
11 type Graph,
12 type MoveInput,
13 parseKey,
14 type ReadView,
15} from "../../src/engine/index.ts";
16import type { Pair } from "./collisions.ts";
17import type { AgentState, Entry, Meta } from "./project-types.ts";
19/** What building a draft change needs from a project. */
20export interface AddDraftHost {
21 readonly graph: Graph;
22 openPairs(agent: AgentState): Pair[];
23 markersSettled(agent: AgentState, view: ReadView, atom: Atom): AtomId[];
24 apply(entry: Entry): void;
27/**
28 * Build a draft change against the agent's view. If it touches lines on
29 * either side of a collision the agent has already seen, it settles that
30 * collision (the engine's `resolves`).
31 */
32export function addDraft(
33 host: AddDraftHost,
34 agent: AgentState,
35 view: ReadView,
36 input: { edits: readonly EditInput[]; attrs?: readonly AttrSet[]; move?: MoveInput },
37 time: number,
38 meta: Meta,
39 entries: Entry[],
40): void {
41 const base = {
42 author: agent.name,
43 message: "",
44 time,
45 edits: input.edits,
46 ...(input.attrs?.length ? { attrs: input.attrs } : {}),
47 ...(input.move ? { move: input.move } : {}),
48 };
49 let atom = buildAtom(view, base);
50 const touched = new Set<AtomId>();
51 for (const key of claimsOf(atom)) {
52 const { kind, node } = parseKey(key);
53 if (kind === "line") touched.add(host.graph.idOfSeq(host.graph.writerSeqOf(host.graph.lineN(node))));
54 // Setting an attribute again settles a collision over it.
55 if (kind === "attr") for (const w of host.graph.writersOf(key)) touched.add(w);
56 }
57 const resolves = new Set<AtomId>();
58 for (const p of host.openPairs(agent)) {
59 if (touched.has(p.yours) || touched.has(p.theirs)) {
60 resolves.add(p.yours);
61 resolves.add(p.theirs);
62 }
63 }
64 // Taking out a block's markers settles the changes that collided there (#11).
65 for (const id of host.markersSettled(agent, view, atom)) resolves.add(id);
66 if (resolves.size > 0) atom = buildAtom(view, { ...base, resolves: [...resolves] });
67 const entry: Entry = {
68 type: "draft",
69 agent: agent.name,
70 atom,
71 ...(typeof meta.session === "string" ? { session: meta.session } : {}),
72 ...(typeof meta.subagent === "string" ? { subagent: meta.subagent } : {}),
73 ...(typeof meta.client === "string" ? { client: meta.client } : {}),
74 };
75 entries.push(entry);
76 host.apply(entry);