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/changes-since.ts?format=json
60 linesFirst import 87% · codex-capacity-chair 13%Last change codex-capacity-chair in version 158, 3 versions changed it
1// The files whose text in the agent's view differs from before, and its open
2// collisions. Reads go through ChangesSinceHost; today the host is Project.
3
4import type { AtomId, ReadView } from "../../src/engine/index.ts";
5import type { Pair } from "./collisions.ts";
6import { sortKeys } from "./project-helpers.ts";
7import type { AgentState, Blobs, Collision, Files, Modes, SyncAnswer } from "./project-types.ts";
8import { modeChange } from "./view-changes.ts";
9
10/** What a changes-since read needs from a project. */
11export interface ChangesSinceHost {
12 agentView(agent: AgentState): ReadView;
13 touchedFiles(ids: Iterable<AtomId>, views: readonly ReadView[]): Set<string>;
14 openPairs(agent: AgentState): Pair[];
15 collision(agent: AgentState, pair: Pair): Collision;
16 duplicates(agent: AgentState): Collision[];
17 markedCollisions(agent: AgentState): Collision[];
20/** The files whose text in the agent's view differs from `before`, and its open collisions. */
21export function changesSince(host: ChangesSinceHost, agent: AgentState, before: ReadView): SyncAnswer {
22 const after = host.agentView(agent);
23 // Only files that an atom in one view but not the other touches can differ.
24 const touched = new Set<string>();
25 for (const [a, b] of [
26 [before.set, after.set],
27 [after.set, before.set],
28 ] as const) {
29 const changed = function* () {
30 for (const id of a) if (!b.has(id)) yield id;
31 };
32 for (const file of host.touchedFiles(changed(), [before, after])) touched.add(file);
33 }
34 const files: Files = {};
35 const modes: Modes = {};
36 const blobs: Blobs = {};
37 for (const path of touched) {
38 const text = after.hasFile(path) ? after.text(path) : null;
39 const blobBefore = before.attrs(path).blob;
40 const blobAfter = after.attrs(path).blob;
41 if (blobAfter !== blobBefore) blobs[path] = blobAfter;
42 // A binary file's bytes come by blob; a file that stops being binary always comes by text (or null).
43 if (blobAfter === null && (blobBefore !== null || text !== (before.hasFile(path) ? before.text(path) : null)))
44 files[path] = text;
45 const m = modeChange(before, after, path);
46 if (m) modes[path] = m.after;
47 }
48 const collisions = [
49 ...host.openPairs(agent).map((p) => host.collision(agent, p)),
50 ...host.duplicates(agent),
51 ...host.markedCollisions(agent),
52 ];
53 return {
54 version: agent.base,
55 files: sortKeys(files),
56 collisions,
57 ...(Object.keys(modes).length > 0 ? { modes: sortKeys(modes) } : {}),
58 ...(Object.keys(blobs).length > 0 ? { blobs: sortKeys(blobs) } : {}),
59 };