- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/worker/project/refuse.ts?draft=login-timeout&format=json
49 linesFirst import 100%0 versions changed it
1// Answer a refused publish or land, and list those refusals. Writes go
2// through RefuseHost; today the host is Project.
4import { countRefusals } from "./project-helpers.ts";
5import type { AgentState, Collision, Entry, Refusal, RefusalCounts } from "./project-types.ts";
6import { SHARED, type Space } from "./spaces.ts";
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[];
12}
14/** Answer a refusal, and log it (an entry that changes nothing but the counts). */
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): { ok: false; collisions: Collision[] } {
24 const entry: Entry = {
25 type: "refused",
26 agent: agent.name,
27 ...(space.name !== SHARED ? { space: space.name } : {}),
28 via,
29 time,
30 collisions: collisions.map((c) => ({
31 kind: c.kind,
32 file: c.file,
33 ...(c.name !== undefined ? { name: c.name } : {}),
34 })),
35 };
36 entries.push(entry);
37 host.apply(entry);
38 return { ok: false, collisions };
39}
41/** Refused publishes and lands, newest first (`limit` defaults to 50), with counts over all of them. */
42export function refusals(
43 host: RefuseHost,
44 options: { agent?: string; limit?: number } = {},
45): { counts: RefusalCounts; refusals: Refusal[] } {
46 const all = options.agent === undefined ? host.refusals : host.refusals.filter((r) => r.agent === options.agent);
47 const limit = Number.isInteger(options.limit) && options.limit! > 0 ? options.limit! : 50;
48 return { counts: countRefusals(all), refusals: all.slice(-limit).toReversed() };
49}