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/label.ts?format=json
57 linesFirst import 100%Last change First import in version 0, 1 version changed it
1// Put a label on a version of shared, or take it off. Writes go through
2// LabelHost; today the host is Project.
3
4import { ProjectError } from "./project-error.ts";
5import { NAME } from "./project-helpers.ts";
6import type { AgentState, Entry } from "./project-types.ts";
7
8/** What labeling a version of shared needs from a project. */
9export interface LabelHost {
10 agent(name: string, entries: Entry[]): AgentState;
11 version(): number;
12 readonly labels: ReadonlyMap<string, readonly number[]>;
13 apply(entry: Entry): void;
14 flush(entries: Entry[]): void;
17/**
18 * Put a label on a version of shared (the newest by default), or take it
19 * off with `remove`. A label can mark many versions ("passed-ci"); a folder
20 * follows the newest with `sync {label}`.
21 */
22export function label(
23 host: LabelHost,
24 agentName: string,
25 name: string,
26 version: number | undefined,
27 time: number,
28 options: { remove?: boolean } = {},
29): { name: string; version: number; versions: number[] } {
30 if (typeof name !== "string" || !NAME.test(name))
31 throw new ProjectError(
32 "bad-request",
33 `bad label ${JSON.stringify(name)}: letters, digits, '.', '_' and '-', up to 64`,
34 );
35 const entries: Entry[] = [];
36 const agent = host.agent(agentName, entries);
37 const v = version ?? host.version();
38 if (!Number.isInteger(v) || v < 0 || v > host.version())
39 throw new ProjectError("bad-request", `there is no version ${String(v)} of shared`);
40 const has = host.labels.get(name)?.includes(v) ?? false;
41 if (has !== (options.remove === true)) {
42 host.flush(entries);
43 return { name, version: v, versions: [...(host.labels.get(name) ?? [])].toReversed() };
44 }
45 const entry: Entry = {
46 type: "label",
47 agent: agent.name,
48 name,
49 version: v,
50 time,
51 ...(options.remove ? { remove: true } : {}),
52 };
53 entries.push(entry);
54 host.apply(entry);
55 host.flush(entries);
56 return { name, version: v, versions: [...(host.labels.get(name) ?? [])].toReversed() };