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/refuse.ts?format=json
52 linesFirst import 92% · speed 8%Last change speed in version 160, 2 versions changed it
1// Answer a refused publish or land, and list those refusals. Writes go
2// through RefuseHost; today the host is Project.
3
4import { countRefusals } from "./project-helpers.ts";
5import type { AgentState, Collision, Entry, Refusal, RefusalCounts } from "./project-types.ts";
6import { SHARED, type Space } from "./spaces.ts";
7
8/** What recording a refusal and listing them needs from a project. */
9export interface RefuseHost {
10 apply(entry: Entry): void;
11 readonly refusals: readonly Refusal[];
14/** Answer a refusal, and log it (an entry that changes nothing but the counts, and keeps a push's message). */
15export function refuse(
16 host: RefuseHost,
17 agent: AgentState,
18 space: Space,
19 via: "publish" | "land",
20 time: number,
21 collisions: Collision[],
22 entries: Entry[],
23 message?: string,
24): { ok: false; collisions: Collision[] } {
25 const entry: Entry = {
26 type: "refused",
27 agent: agent.name,
28 ...(space.name !== SHARED ? { space: space.name } : {}),
29 via,
30 time,
31 collisions: collisions.map((c) => ({
32 kind: c.kind,
33 file: c.file,
34 ...(c.name !== undefined ? { name: c.name } : {}),
35 })),
36 // A held push keeps its message: the settle that follows tells it as this side's reason.
37 ...(message ? { message } : {}),
38 };
39 entries.push(entry);
40 host.apply(entry);
41 return { ok: false, collisions };
44/** Refused publishes and lands, newest first (`limit` defaults to 50), with counts over all of them. */
45export function refusals(
46 host: RefuseHost,
47 options: { agent?: string; limit?: number } = {},
48): { counts: RefusalCounts; refusals: Refusal[] } {
49 const all = options.agent === undefined ? host.refusals : host.refusals.filter((r) => r.agent === options.agent);
50 const limit = Number.isInteger(options.limit) && options.limit! > 0 ? options.limit! : 50;
51 return { counts: countRefusals(all), refusals: all.slice(-limit).toReversed() };