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/src/engine/sets.ts?version=86&format=json
89 linesFirst import 100%Last change First import in version 0, 1 version changed it

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

1// Sets of atoms: closure, closedness, history order, and drop.
2
3import type { Graph } from "./graph.ts";
4import { type Atom, type AtomId, type AtomSet, EngineError } from "./types.ts";
5
6/** The atoms plus everything they depend on, transitively. */
7export function closure(graph: Graph, ids: Iterable<AtomId>): Set<AtomId> {
8 return graph.closureOf(ids);
9}
11/** Atoms of the set whose deps are not all in the set, with what is missing. */
12export function missingDeps(graph: Graph, set: AtomSet): { atom: AtomId; missing: AtomId[] }[] {
13 const out: { atom: AtomId; missing: AtomId[] }[] = [];
14 for (const id of sortBySeq(graph, set)) {
15 const missing = graph.atom(id).deps.filter((d) => !set.has(d));
16 if (missing.length > 0) out.push({ atom: id, missing });
17 }
18 return out;
21/** Every atom's dependencies are in the set. */
22export function isClosed(graph: Graph, set: AtomSet): boolean {
23 for (const id of set) for (const d of graph.atom(id).deps) if (!set.has(d)) return false;
24 return true;
27/**
28 * History: the set in ascending priority (lamport, then seq). This is a
29 * topological order (deps always have lower lamport). Atoms with no path
30 * between them have no real order; their `deps` show which pairs are ordered.
31 */
32export function history(graph: Graph, set: Iterable<AtomId>): Atom[] {
33 return [...set].sort((a, b) => graph.comparePriority(a, b)).map((id) => graph.atom(id));
36/** Atoms in the set that depend on `id`, transitively (not including `id`). */
37export function dependentsIn(graph: Graph, set: AtomSet, id: AtomId): Set<AtomId> {
38 const out = new Set<AtomId>();
39 const stack = [id];
40 while (stack.length > 0) {
41 const cur = stack.pop()!;
42 for (const d of graph.dependentsOf(cur)) {
43 if (set.has(d) && !out.has(d)) {
44 out.add(d);
45 stack.push(d);
46 }
47 }
48 }
49 return out;
52/** Remove an atom and everything in the set that depends on it. Returns the new set and what left. */
53export function drop(graph: Graph, set: AtomSet, id: AtomId): { set: Set<AtomId>; removed: AtomId[] } {
54 if (!set.has(id)) throw new EngineError("not-in-set", `${id} is not in the set`);
55 const gone = dependentsIn(graph, set, id);
56 gone.add(id);
57 const kept = new Set<AtomId>();
58 for (const x of set) if (!gone.has(x)) kept.add(x);
59 return { set: kept, removed: sortBySeq(graph, gone) };
62/**
63 * What a pluck takes: the closure of `ids`, widened so that every group is
64 * all in or all out. `groupOf(id)` lists the atoms that travel with `id` (a
65 * git commit's hunks and its tie; just `id` when it belongs to no group).
66 * Whenever any atom of a group is in, the whole group and the closure of each
67 * of its atoms come too, repeated until nothing changes. The result is closed.
68 */
69export function pluckClosure(
70 graph: Graph,
71 ids: Iterable<AtomId>,
72 groupOf: (id: AtomId) => readonly AtomId[],
73): Set<AtomId> {
74 const out = new Set<AtomId>();
75 const stack = [...ids];
76 for (const id of stack) graph.atom(id);
77 while (stack.length > 0) {
78 const id = stack.pop()!;
79 if (out.has(id)) continue;
80 out.add(id);
81 for (const d of graph.atom(id).deps) if (!out.has(d)) stack.push(d);
82 for (const g of groupOf(id)) if (!out.has(g)) stack.push(g);
83 }
84 return out;
87export function sortBySeq(graph: Graph, ids: Iterable<AtomId>): AtomId[] {
88 return [...ids].sort((a, b) => graph.atom(a).seq - graph.atom(b).seq);