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?version=78&format=json
61 linesFirst import 100%Last change First import in version 0, 1 version changed it

You're reading version 78. The newest is 318, and 2 versions since then changed this file. Go to the newestCompare with 318

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, View } 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): View;
13 touchedFiles(ids: Iterable<AtomId>, views: readonly View[]): 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: View): 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 for (const file of host.touchedFiles(
30 [...a].filter((id) => !b.has(id)),
31 [before, after],
32 ))
33 touched.add(file);
34 }
35 const files: Files = {};
36 const modes: Modes = {};
37 const blobs: Blobs = {};
38 for (const path of touched) {
39 const text = after.hasFile(path) ? after.text(path) : null;
40 const blobBefore = before.attrs(path).blob;
41 const blobAfter = after.attrs(path).blob;
42 if (blobAfter !== blobBefore) blobs[path] = blobAfter;
43 // A binary file's bytes come by blob; a file that stops being binary always comes by text (or null).
44 if (blobAfter === null && (blobBefore !== null || text !== (before.hasFile(path) ? before.text(path) : null)))
45 files[path] = text;
46 const m = modeChange(before, after, path);
47 if (m) modes[path] = m.after;
48 }
49 const collisions = [
50 ...host.openPairs(agent).map((p) => host.collision(agent, p)),
51 ...host.duplicates(agent),
52 ...host.markedCollisions(agent),
53 ];
54 return {
55 version: agent.base,
56 files: sortKeys(files),
57 collisions,
58 ...(Object.keys(modes).length > 0 ? { modes: sortKeys(modes) } : {}),
59 ...(Object.keys(blobs).length > 0 ? { blobs: sortKeys(blobs) } : {}),
60 };