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/project-status.ts?version=0&format=json
147 linesFirst import 100%Last change First import in version 0, 1 version changed it

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

1// What the project looks like now: status, the paths in a folder, and the labels. They read through
2// SnapshotHost; today the host is the project in memory.
3
4import type { AtomId, View } from "../../src/engine/index.ts";
5import { ProjectError } from "./project-error.ts";
6import { countRefusals } from "./project-helpers.ts";
7import type { AgentState, AgentStatus, EditsVia, Refusal, Starting, StatusAnswer } from "./project-types.ts";
8import { last, SHARED, type Space, sharedBaseOf } from "./spaces.ts";
9
10/** What the snapshot reads need from a project. */
11export interface SnapshotHost {
12 readonly agents: ReadonlyMap<string, AgentState>;
13 readonly spaces: ReadonlyMap<string, Space>;
14 queue(): readonly { readonly agent: string; readonly id: number }[];
15 readonly refusals: readonly Refusal[];
16 readonly labels: ReadonlyMap<string, readonly number[]>;
17 needInit(): void;
18 shared(): Space;
19 draft(agent: AgentState): AtomId[];
20 draftFiles(agent: AgentState): Set<string>;
21 liveNote(agent: AgentState): Starting | undefined;
22 openCollisions(agent: AgentState): { collisions?: AgentStatus["collisions"] };
23 editsOf(agent: AgentState): {
24 edits: EditsVia;
25 modCurrent: boolean | null;
26 lastEdit: number | null;
27 joined: number | null;
28 };
29 setOf(space: Space): ReadonlySet<AtomId>;
30 spaceNamed(name: string | null): Space;
31 checkVersion(space: Space, version: number): void;
32 viewAt(space: Space, version: number): View;
33 agentView(agent: AgentState): View;
34 version(): number;
37/**
38 * The paths in an agent's view now (#37): what its folder should hold.
39 * Reading it changes nothing. Binary files are included.
40 */
41export function agentPaths(
42 host: SnapshotHost,
43 agentName: string,
44): { version: number; draft: string | null; files: string[] } {
45 host.needInit();
46 const agent = host.agents.get(agentName);
47 if (!agent) throw new ProjectError("bad-request", `there is no agent ${JSON.stringify(agentName)}; join first`);
48 return {
49 version: agent.base,
50 draft: agent.space === SHARED ? null : agent.space,
51 files: host.agentView(agent).paths(),
52 };
55/** The paths in shared, or a named draft, at a version (the newest by default). */
56export function pathsAt(
57 host: SnapshotHost,
58 version?: number,
59 draft: string | null = null,
60): { version: number; draft: string | null; files: string[] } {
61 host.needInit();
62 const space = host.spaceNamed(draft);
63 const v = version ?? last(space);
64 host.checkVersion(space, v);
65 return { version: v, draft, files: host.viewAt(space, v).paths() };
68/**
69 * The paths in an agent's view now, for a reader (#41, F25): like
70 * agentPaths, but an unknown agent is not found, and nothing is made.
71 */
72export function pathsOf(
73 host: SnapshotHost,
74 agentName: string,
75): { agent: string; version: number; draft: string | null; files: string[] } {
76 host.needInit();
77 const agent = host.agents.get(agentName);
78 if (!agent) throw new ProjectError("not-found", `there is no agent ${JSON.stringify(agentName)}`);
79 return {
80 agent: agent.name,
81 version: agent.base,
82 draft: agent.space === SHARED ? null : agent.space,
83 files: host.agentView(agent).paths(),
84 };
87/** Every label, with the versions it marks, newest first. */
88export function labels(host: SnapshotHost): { labels: Record<string, number[]> } {
89 const out: Record<string, number[]> = {};
90 for (const name of [...host.labels.keys()].toSorted()) out[name] = [...host.labels.get(name)!].toReversed();
91 return { labels: out };
94export function status(host: SnapshotHost): StatusAnswer {
95 const agents = [...host.agents.values()]
96 .toSorted((a, b) => (a.name < b.name ? -1 : 1))
97 .map((agent) => {
98 const draft = host.draft(agent);
99 const files = host.draftFiles(agent);
100 const queued = host.queue();
101 const parked = [...agent.parked]
102 .map(([space, p]) => {
103 const set = host.setOf(host.spaces.get(space)!);
104 return { draft: space === SHARED ? null : space, draftChanges: p.mine.filter((id) => !set.has(id)).length };
105 })
106 .filter((p) => p.draftChanges > 0)
107 .toSorted((a, b) => ((a.draft ?? "") < (b.draft ?? "") ? -1 : 1));
108 return {
109 agent: agent.name,
110 draft: agent.space === SHARED ? null : agent.space,
111 base: agent.base,
112 draftChanges: draft.length,
113 files: [...files].toSorted(),
114 parked,
115 ...(host.liveNote(agent)
116 ? { starting: { ...host.liveNote(agent)!, files: [...host.liveNote(agent)!.files] } }
117 : {}),
118 ...host.openCollisions(agent),
119 ...(queued.some((q) => q.agent === agent.name)
120 ? { queued: queued.filter((q) => q.agent === agent.name).map((q) => q.id) }
121 : {}),
122 ...host.editsOf(agent),
123 };
124 });
125 const drafts = [...host.spaces.values()]
126 .filter((s) => s.name !== SHARED)
127 .toSorted((a, b) => (a.name < b.name ? -1 : 1))
128 .map((s) => ({
129 name: s.name,
130 version: last(s),
131 sharedBase: sharedBaseOf(s),
132 changes: [...s.own].filter((id) => !host.shared().own.has(id)).length,
133 agents: agents.filter((a) => a.draft === s.name).map((a) => a.agent),
134 }));
135 // Waiting announcements: the sentences still in agents' undelivered news.
136 const waiting = new Map<string, string[]>();
137 for (const agent of [...host.agents.values()].toSorted((a, b) => (a.name < b.name ? -1 : 1))) {
138 for (const text of agent.news) {
139 if (!text.startsWith("Announcement from ")) continue;
140 const list = waiting.get(text);
141 if (list) list.push(agent.name);
142 else waiting.set(text, [agent.name]);
143 }
144 }
145 const announcements = [...waiting].map(([text, names]) => ({ text, waiting: names }));
146 return { version: host.version(), agents, drafts, refusals: countRefusals(host.refusals), announcements };