- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/client/src/autosettle-commands.ts?format=json
126 linesautosettle 100%Last change autosettle in version 223, 2 versions changed it
1// abso autosettle (abso-core 23): see or change what the project's server does with a held push: Off, Advise or Settle.
2// The model only picks a side; under Settle, the held agent's own abso settles and pushes again.
3import { ApiError } from "./api-error.ts";
4import { type Parsed, str, UsageError } from "./args.ts";
5import { type Env, type Output, open } from "./commands.ts";
7export type AutosettleMode = "off" | "advise" | "settle";
8const MODES: readonly AutosettleMode[] = ["off", "advise", "settle"];
10/** The project's choice, as the server answers it. */
11export interface AutosettleAnswer {
12 readonly project: string;
13 readonly mode: AutosettleMode;
14 readonly at: number;
15 readonly changedBy?: string;
16 readonly changedAt?: string;
17 readonly gate?: "open" | "stopped";
18}
20/** A server with no choice per project (the open server): its operator's AUTOSETTLE decides. */
21const NO_CHOICE_HERE =
22 "This server keeps no auto-settle choice per project: whoever runs it sets AUTOSETTLE (off, on for advice, act to settle).";
24export function autosettleWords(a: AutosettleAnswer): string {
25 const what =
26 a.mode === "off"
27 ? "Off: held pushes come back as they always have."
28 : a.mode === "advise"
29 ? "Advise: each collision in a held push comes back with the model's pick, how sure it is, and why. The agent still settles."
30 : `Settle at ${a.at.toFixed(2)}: when the model is at least that sure about every collision in a held push, the agent's abso settles it and pushes again. Anything less sure is left to the agent, with the advice.`;
31 return [
32 `${a.project} is on ${what}`,
33 ...(a.gate === "stopped" ? ["Stopped by abso for now: no held push gets advice until it starts again."] : []),
34 ...(a.changedBy ? [`Last changed by ${a.changedBy}${a.changedAt ? `, ${a.changedAt}` : ""}.`] : []),
35 ].join("\n");
36}
38/** One held push in the history, as the server answers it. */
39interface HistoryHold {
40 readonly id: number;
41 readonly time: string;
42 readonly agent: string;
43 readonly message: string;
44 readonly mode: AutosettleMode;
45 readonly at: number;
46 readonly collisions: readonly {
47 readonly file: string;
48 readonly theirs: { readonly agent: string; readonly version?: number };
49 readonly advice: {
50 readonly pick: string;
51 readonly confidence: number;
52 readonly by: string;
53 readonly reason: string;
54 };
55 readonly settled: boolean;
56 readonly outcome: { readonly kept: string; readonly auto: boolean; readonly version?: number } | null;
57 readonly calls?: readonly { readonly model: string; readonly input: unknown; readonly output: unknown }[];
58 }[];
59}
61/** A held push in a few lines: what the model said, and what was then kept. */
62export function holdWords(h: HistoryHold): string {
63 return [
64 `${h.id}: ${h.agent}, ${h.time}, under ${h.mode}${h.mode === "settle" ? ` at ${h.at.toFixed(2)}` : ""}: "${h.message.split(/\r?\n/)[0]}"`,
65 ...h.collisions.map((c) => {
66 const said = `${c.advice.pick === "agent" ? "leave it to an agent" : `keep ${c.advice.pick}`} (${c.advice.by === "rule" ? "a check in code" : `${c.advice.by}, ${c.advice.confidence.toFixed(2)}`})`;
67 const then = c.outcome
68 ? `kept ${c.outcome.kept}${c.outcome.auto ? " automatically" : " by hand"}${c.outcome.version !== undefined ? ` in version ${c.outcome.version}` : ""}`
69 : "not settled yet";
70 return ` ${c.file}, against ${c.theirs.agent}${c.theirs.version !== undefined ? `'s version ${c.theirs.version}` : ""}: advised ${said}${c.settled ? ", told to settle" : ""}; ${then}.`;
71 }),
72 ].join("\n");
73}
75/** abso autosettle history [<id>]: the held pushes the model advised on, newest first, or one with its calls. */
76async function runHistory(args: Parsed, env: Env): Promise<Output> {
77 const { api } = open(env);
78 const id = args.positionals[1];
79 if (id !== undefined) {
80 if (!/^[0-9]{1,9}$/.test(id)) throw new UsageError("abso autosettle history <id> takes a hold's number");
81 const hold = (await api.autosettleHold(Number(id))) as HistoryHold;
82 const calls = hold.collisions.flatMap((c) => (c.calls ?? []).map((k) => ` ${c.file}: ${k.model}`));
83 return {
84 text: [holdWords(hold), "Calls to the model (--json has each request and answer):", ...calls].join("\n"),
85 json: { ...hold },
86 };
87 }
88 const page = (await api.autosettleHistory()) as { holds: HistoryHold[]; next?: number };
89 return {
90 text:
91 page.holds.length === 0
92 ? "No held push has had advice in this project yet."
93 : page.holds.map(holdWords).join("\n"),
94 json: { ...page },
95 };
96}
98export async function runAutosettle(args: Parsed, env: Env): Promise<Output> {
99 if (args.positionals[0] === "history") {
100 if (args.positionals.length > 2) throw new UsageError("abso autosettle history takes at most a hold's number");
101 return runHistory(args, env);
102 }
103 if (args.positionals.length > 1) throw new UsageError("autosettle takes at most one word: off, advise or settle");
104 const want = args.positionals[0];
105 const atRaw = str(args, "at");
106 const { api } = open(env);
107 try {
108 if (want === undefined) {
109 if (atRaw !== undefined)
110 throw new UsageError("--at goes with a choice, for example: abso autosettle settle --at 0.6");
111 const now = await api.autosettle();
112 return { text: autosettleWords(now), json: { ...now } };
113 }
114 if (!MODES.includes(want as AutosettleMode))
115 throw new UsageError("autosettle is off, advise or settle, for example: abso autosettle settle --at 0.6");
116 const at = atRaw === undefined ? undefined : Number(atRaw);
117 if (at !== undefined && !(at >= 0.3 && at <= 0.95))
118 throw new UsageError("--at is how sure the model must be before abso settles: a number from 0.3 to 0.95");
119 const set = await api.setAutosettle(want as AutosettleMode, at);
120 return { text: autosettleWords(set), json: { ...set } };
121 } catch (e) {
122 if (e instanceof ApiError && e.status === 404 && /no such route/.test(e.message))
123 return { text: NO_CHOICE_HERE, json: { error: NO_CHOICE_HERE } };
124 throw e;
125 }
126}