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/draft-diff.ts?version=78&format=json
45 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// An agent's unpublished changes, file by file. They read through DraftDiffHost; today the host is the project
2// in memory.
3
4import type { AtomId, View } 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";
9
10interface Agent {
11 readonly space: string;
12 readonly base: number;
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): View;
21 view(set: ReadonlySet<AtomId>): View;
22 touchedFiles(ids: Iterable<AtomId>, views: readonly View[]): Set<string>;
25/** An agent's draft diff for a reader (#41, the website): never creates the agent, never writes. */
26export function diffOf(host: DraftDiffHost, agentName: string): DiffAnswer {
27 host.needInit();
28 const agent = host.agents.get(agentName);
29 if (!agent) throw new ProjectError("not-found", `there is no agent ${JSON.stringify(agentName)}`);
30 return diffOfAgent(host, agent);
33/** What the agent's unpublished changes do, file by file: its space at its base, then its view. */
34export function diffOfAgent(host: DraftDiffHost, agent: Agent): DiffAnswer {
35 const draft = host.draft(agent);
36 const after = host.agentView(agent);
37 const without = new Set(draft);
38 const before = host.view(new Set([...after.set].filter((id) => !without.has(id))));
39 const files = host.touchedFiles(draft, [before, after]);
40 return {
41 draft: agent.space === SHARED ? null : agent.space,
42 base: agent.base,
43 files: changesBetween(before, after, files),
44 };