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/version-meta.ts?format=json
48 linesFirst import 100%Last change First import in version 0, 1 version changed it
1// Who made a version, how new it is, and whether that version exists. Reads
2// go through VersionMetaHost; today the host is Project.
3
4import { ProjectError } from "./project-error.ts";
5import { last, SHARED, type Space } from "./spaces.ts";
6
7/** What version metadata reads need from a project. */
8export interface VersionMetaHost {
9 needInit(): void;
10 spaceNamed(name: string | null): Space;
13/** There is no such version of this space. */
14export function checkVersion(space: Space, version: number): void {
15 if (!Number.isInteger(version) || version < 0 || version > last(space)) {
16 throw new ProjectError(
17 "bad-request",
18 `there is no version ${String(version)}${space.name === SHARED ? "" : ` of draft ${space.name}`}`,
19 );
20 }
23/** The newest version of shared, or of a named draft. */
24export function lastVersion(host: VersionMetaHost, draft: string | null = null): number {
25 host.needInit();
26 return last(host.spaceNamed(draft));
29/**
30 * Who made a version of shared or a named draft, why and when, and a draft's
31 * shared base (abso issue 80).
32 */
33export function versionMeta(
34 host: VersionMetaHost,
35 version: number,
36 draft: string | null = null,
37): { agent: string; message: string; time: number; sharedBase?: number } {
38 host.needInit();
39 const space = host.spaceNamed(draft);
40 checkVersion(space, version);
41 const p = space.versions[version]!;
42 return {
43 agent: p.agent,
44 message: p.message,
45 time: p.time,
46 ...(p.sharedBase !== undefined ? { sharedBase: p.sharedBase } : {}),
47 };