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?format=json
192 linesFirst import 72% · pinch 11% · capacity 9% · engine 7% · codex-capacity-chair 2%Last change capacity in version 303, 6 versions changed it
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, ReadView } from "../../src/engine/index.ts";
5import { ProjectError } from "./project-error.ts";
6import { countRefusals, type projectFileIn } from "./project-helpers.ts";
7import type {
8 AgentState,
9 AgentStatus,
10 EditsVia,
11 Refusal,
12 Starting,
13 StatusAnswer,
14 TellRecord,
15 TellStatus,
16} from "./project-types.ts";
17import { last, SHARED, type Space, sharedBaseOf } from "./spaces.ts";
19/** What the snapshot reads need from a project. */
20export interface SnapshotHost {
21 readonly agents: ReadonlyMap<string, AgentState>;
22 readonly spaces: ReadonlyMap<string, Space>;
23 queue(): readonly { readonly agent: string; readonly id: number }[];
24 readonly refusals: readonly Refusal[];
25 readonly labels: ReadonlyMap<string, readonly number[]>;
26 readonly tells: ReadonlyMap<number, TellRecord>;
27 needInit(): void;
28 shared(): Space;
29 draft(agent: AgentState): AtomId[];
30 draftFiles(agent: AgentState): Set<string>;
31 liveNote(agent: AgentState): Starting | undefined;
32 openCollisions(agent: AgentState): { collisions?: AgentStatus["collisions"] };
33 editsOf(agent: AgentState): {
34 edits: EditsVia;
35 modCurrent: boolean | null;
36 lastEdit: number | null;
37 joined: number | null;
38 };
39 setOf(space: Space): ReadonlySet<AtomId>;
40 spaceNamed(name: string | null): Space;
41 checkVersion(space: Space, version: number): void;
42 viewAt(space: Space, version: number): ReadView;
43 /** A version's file list from kept version shapes, when every version up to it has one (pathindex.ts). */
44 keptPaths?(space: Space, version: number): string[] | undefined;
45 agentView(agent: AgentState): ReadView;
46 version(): number;
47 /** Shared's project file (224), or undefined before init or without one. */
48 projectFile(): ReturnType<typeof projectFileIn>;
51/**
52 * An agent with nothing of its own sees exactly its base version, so its paths are that version's kept file list
53 * (pathindex.ts), when there is one: no layout of every known file (abso - Performance, abso 711).
54 */
55function viewPaths(host: SnapshotHost, agent: AgentState): string[] {
56 const kept =
57 agent.mine.length === 0
58 ? host.keptPaths?.(host.spaceNamed(agent.space === SHARED ? null : agent.space), agent.base)
59 : undefined;
60 return kept ?? host.agentView(agent).paths();
63/**
64 * The paths in an agent's view now (#37): what its folder should hold.
65 * Reading it changes nothing. Binary files are included.
66 */
67export function agentPaths(
68 host: SnapshotHost,
69 agentName: string,
70): { version: number; draft: string | null; files: string[] } {
71 host.needInit();
72 const agent = host.agents.get(agentName);
73 if (!agent) throw new ProjectError("bad-request", `there is no agent ${JSON.stringify(agentName)}; join first`);
74 return {
75 version: agent.base,
76 draft: agent.space === SHARED ? null : agent.space,
77 files: viewPaths(host, agent),
78 };
81/** The paths in shared, or a named draft, at a version (the newest by default). */
82export function pathsAt(
83 host: SnapshotHost,
84 version?: number,
85 draft: string | null = null,
86): { version: number; draft: string | null; files: string[] } {
87 host.needInit();
88 const space = host.spaceNamed(draft);
89 const v = version ?? last(space);
90 host.checkVersion(space, v);
91 return { version: v, draft, files: host.keptPaths?.(space, v) ?? host.viewAt(space, v).paths() };
94/**
95 * The paths in an agent's view now, for a reader (#41, F25): like
96 * agentPaths, but an unknown agent is not found, and nothing is made.
97 */
98export function pathsOf(
99 host: SnapshotHost,
100 agentName: string,
101): { agent: string; version: number; draft: string | null; files: string[] } {
102 host.needInit();
103 const agent = host.agents.get(agentName);
104 if (!agent) throw new ProjectError("not-found", `there is no agent ${JSON.stringify(agentName)}`);
105 return {
106 agent: agent.name,
107 version: agent.base,
108 draft: agent.space === SHARED ? null : agent.space,
109 files: viewPaths(host, agent),
110 };
113/** Every label, with the versions it marks, newest first. */
114export function labels(host: SnapshotHost): { labels: Record<string, number[]> } {
115 const out: Record<string, number[]> = {};
116 for (const name of [...host.labels.keys()].toSorted()) out[name] = [...host.labels.get(name)!].toReversed();
117 return { labels: out };
120export function status(host: SnapshotHost): StatusAnswer {
121 const agents = [...host.agents.values()]
122 .toSorted((a, b) => (a.name < b.name ? -1 : 1))
123 .map((agent) => {
124 const draft = host.draft(agent);
125 const files = host.draftFiles(agent);
126 const queued = host.queue();
127 const parked = [...agent.parked]
128 .map(([space, p]) => {
129 const set = host.setOf(host.spaces.get(space)!);
130 return { draft: space === SHARED ? null : space, draftChanges: p.mine.filter((id) => !set.has(id)).length };
131 })
132 .filter((p) => p.draftChanges > 0)
133 .toSorted((a, b) => ((a.draft ?? "") < (b.draft ?? "") ? -1 : 1));
134 return {
135 agent: agent.name,
136 draft: agent.space === SHARED ? null : agent.space,
137 base: agent.base,
138 draftChanges: draft.length,
139 files: [...files].toSorted(),
140 parked,
141 ...(host.liveNote(agent)
142 ? { starting: { ...host.liveNote(agent)!, files: [...host.liveNote(agent)!.files] } }
143 : {}),
144 ...host.openCollisions(agent),
145 ...(queued.some((q) => q.agent === agent.name)
146 ? { queued: queued.filter((q) => q.agent === agent.name).map((q) => q.id) }
147 : {}),
148 ...host.editsOf(agent),
149 };
150 });
151 const drafts = [...host.spaces.values()]
152 .filter((s) => s.name !== SHARED)
153 .toSorted((a, b) => (a.name < b.name ? -1 : 1))
154 .map((s) => ({
155 name: s.name,
156 version: last(s),
157 sharedBase: sharedBaseOf(s),
158 changes: [...s.own].filter((id) => !host.shared().own.has(id)).length,
159 agents: agents.filter((a) => a.draft === s.name).map((a) => a.agent),
160 }));
161 // Waiting announcements: the sentences still in agents' undelivered news.
162 const waiting = new Map<string, string[]>();
163 for (const agent of [...host.agents.values()].toSorted((a, b) => (a.name < b.name ? -1 : 1))) {
164 for (const text of agent.news) {
165 if (!text.startsWith("Announcement from ")) continue;
166 const list = waiting.get(text);
167 if (list) list.push(agent.name);
168 else waiting.set(text, [agent.name]);
169 }
170 }
171 const announcements = [...waiting].map(([text, names]) => ({ text, waiting: names }));
172 // Who has heard each of the newest tells, and when (277): the news and heard entries' times.
173 const tells: TellStatus[] = [...host.tells.values()].toReversed().map((t) => ({
174 id: t.id,
175 text: t.text,
176 at: t.at ?? null,
177 to: [...t.heard]
178 .toSorted(([a], [b]) => (a < b ? -1 : 1))
179 .map(([agent, h]) => ({ agent, heard: h !== null, at: h?.at ?? null })),
180 }));
181 // Both project files in shared (224): say which one counts, never quietly.
182 const file = host.projectFile();
183 return {
184 version: host.version(),
185 agents,
186 drafts,
187 refusals: countRefusals(host.refusals),
188 announcements,
189 tells,
190 ...(file?.ignored ? { projectFile: { used: "abso.json" as const, ignored: file.ignored } } : {}),
191 };