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
show on this site's /mcp
CLI
abso show 204 --json
JSON
/christopher/abso-core/versions/204?format=json

Auto-settle switch (abso 19): on advises, act also has the client settle

of shared·autosettle··Not checked

AUTOSETTLE=on now only adds advice to a held push; AUTOSETTLE=act adds settle: true, and the client settles the collisions advised a side only then (ABSO_AUTOSETTLE=off still stops it). The whole server hook is one function, withAdvice(env, op, agent, request, answer), so a Worker calls it in one line: return json(a.status, await withAdvice(env, op, agent, body, a.body)). Tested: the switch test, held-push tests, and the local demo under on (held with advice) and act (settled and pushed).

Version 203 · Files at version 204

6 files, 74 lines added, 24 removed.

--- a/client/src/api-answers.ts
+++ b/client/src/api-answers.ts
@@ -88,7 +88,14 @@
8888 }
8989 /** With the merge queue on (#39): queued, not landed yet; `ahead` publishes wait in front of it. */
9090 | { ok: true; queued: number; position: number; ahead: number; changes: number; settled?: readonly Settled[] }
91− | { ok: false; collisions: readonly Collision[]; reason?: string; advice?: readonly (Advice | null)[] };
91+ | {
92+ ok: false;
93+ collisions: readonly Collision[];
94+ reason?: string;
95+ advice?: readonly (Advice | null)[];
96+ /** The server runs AUTOSETTLE=act: settle the collisions it advised a side of, and push again (#19). */
97+ settle?: boolean;
98+ };
9299/**
93100 * A server's first opinion on one collision of a held push (#19), when it runs AUTOSETTLE: which settle fits,
94101 * how sure, and why. `by`: rule (code decided), model (Workers AI), turned down (the model's pick would break
--- a/client/src/publish-commands.ts
+++ b/client/src/publish-commands.ts
@@ -461,8 +461,9 @@
461461 const newer = real.filter((c) => c.kind !== "duplicate");
462462 // The server's first opinion on each collision (#19), when it runs AUTOSETTLE.
463463 const advice = answer.advice ?? [];
464− // When it says to keep a side of every collision, settle them here and push again (ABSO_AUTOSETTLE=off stops it).
465− const plan = autoSettled ? null : autoPlan(collisions, advice, env);
464+ // When the server says to settle (its AUTOSETTLE=act) and to keep a side of every collision, settle them here and
465+ // push again (ABSO_AUTOSETTLE=off stops it).
466+ const plan = autoSettled || answer.settle !== true ? null : autoPlan(collisions, advice, env);
466467 if (plan) {
467468 const pulled = await runSync({ positionals: [], flags: new Map() }, env);
468469 const done: string[] = [];
--- a/server/src/env.ts
+++ b/server/src/env.ts
@@ -24,7 +24,7 @@
2424 /** Per-agent keys: "on" with KEY_HMAC_SECRET set. */
2525 AGENT_KEYS?: string;
2626 KEY_HMAC_SECRET?: string;
27− /** "on" gives a held push a first opinion on each collision from Workers AI (#19); needs the AI binding. */
27+ /** "on" gives a held push a first opinion on each collision from Workers AI (#19); "act" also has the client settle the ones advised a side. Needs the AI binding. */
2828 AUTOSETTLE?: string;
2929 /** Which model advises: clef (the default), clef-flash, or a Workers AI text model's id. */
3030 AUTOSETTLE_MODEL?: string;
--- a/server/src/router.ts
+++ b/server/src/router.ts
@@ -18,7 +18,7 @@
1818// ABSO_TOKEN set, the server refuses every call.
1919
2020import { type Answer, validName } from "../../worker/project/http.ts";
21−import { adviseHeld } from "./autosettle.ts";
21+import { withAdvice } from "./autosettle.ts";
2222import { artifactsOf, type Env, secret } from "./env.ts";
2323import type { IssuesAuth, issuesFetch } from "./issues-entry.ts";
2424import { isAgentKey, type KeyRole, keyAllows, keysEnabled, timingSame } from "./keys.ts";
@@ -270,23 +270,7 @@
270270 request.headers.get("Idempotency-Key") ?? undefined,
271271 )) as unknown as Answer;
272272 // A held push gets a first opinion on each collision (#19), when the server is set up for it.
273− if (op === "publish" && env.AUTOSETTLE === "on" && env.AI && agent) {
274− const held = a.body as { ok?: boolean; collisions?: Parameters<typeof adviseHeld>[1] };
275− if (held.ok === false && held.collisions && held.collisions.length > 0) {
276− const message = String((body as { message?: unknown } | undefined)?.message ?? "");
277− const advice = await adviseHeld(
278− env.AI,
279− held.collisions,
280− { agent, message },
281− {
282− ...(env.AUTOSETTLE_MODEL ? { model: env.AUTOSETTLE_MODEL } : {}),
283− ...(Number(env.AUTOSETTLE_AT) > 0 ? { at: Number(env.AUTOSETTLE_AT) } : {}),
284− },
285− );
286− if (advice.some((x) => x !== null)) return json(a.status, { ...held, advice });
287− }
288− }
289− return json(a.status, a.body);
273+ return json(a.status, await withAdvice(env, op, agent, body, a.body));
290274 } catch (e) {
291275 const error = `the project object failed: ${e instanceof Error ? e.message : String(e)}`;
292276 console.error(`${project} ${op ?? top}: ${error}`);
--- a/worker/project/autosettle.ts
+++ b/worker/project/autosettle.ts
@@ -1,6 +1,6 @@
11// A first opinion on a held push (#19), shared by the open server and the platform: for each collision, which of abso's
22// settle choices fits, from Workers AI, with checks in code before and after.
3−// Off unless AUTOSETTLE is "on" and the Worker has an AI binding. The model
3+// Off unless AUTOSETTLE is "on" (advice) or "act" (the client settles) and the Worker has an AI binding. The model
44// picks one of four words; it never writes code.
55
66/** abso's settle choices, plus a hand edit by an agent. */
@@ -357,3 +357,42 @@
357357 }),
358358 );
359359}
361+/** The switch as a Worker's env carries it: AUTOSETTLE "on" advises, "act" also has the client settle; else off. */
362+export interface AutosettleEnv {
363+ readonly AUTOSETTLE?: string;
364+ readonly AUTOSETTLE_MODEL?: string;
365+ readonly AUTOSETTLE_AT?: string | number;
366+ readonly AI?: Ai;
367+}
369+/**
370+ * The one hook for a server (#19): a publish answer with the first opinion added when the push was held and the
371+ * switch is on, or the answer as it was. Under "act" it also says `settle: true`, and the client settles the
372+ * collisions advised to a side and pushes again; under "on" the client only shows the advice.
373+ */
374+export async function withAdvice(
375+ env: AutosettleEnv,
376+ op: string | undefined,
377+ agent: string | undefined,
378+ request: unknown,
379+ answer: unknown,
380+): Promise<unknown> {
381+ const mode = env.AUTOSETTLE;
382+ if (op !== "publish" || (mode !== "on" && mode !== "act") || !env.AI || !agent) return answer;
383+ const held = answer as { ok?: boolean; collisions?: readonly HeldCollision[] } | null;
384+ if (held?.ok !== false || !held.collisions || held.collisions.length === 0) return answer;
385+ const message = String((request as { message?: unknown } | null | undefined)?.message ?? "");
386+ const at = Number(env.AUTOSETTLE_AT);
387+ const advice = await adviseHeld(
388+ env.AI,
389+ held.collisions,
390+ { agent, message },
391+ {
392+ ...(env.AUTOSETTLE_MODEL ? { model: env.AUTOSETTLE_MODEL } : {}),
393+ ...(at > 0 ? { at } : {}),
394+ },
395+ );
396+ if (!advice.some((x) => x !== null)) return answer;
397+ return { ...held, advice, ...(mode === "act" ? { settle: true } : {}) };
398+}
--- a/worker/project/test/autosettle.test.ts
+++ b/worker/project/test/autosettle.test.ts
@@ -1,6 +1,6 @@
11import assert from "node:assert/strict";
22import { test } from "node:test";
3−import { type Ai, adviseHeld, refused, ruled } from "../autosettle.ts";
3+import { type Ai, adviseHeld, refused, ruled, withAdvice } from "../autosettle.ts";
44
55/**
66 * A stand-in for Workers AI that always leans to `pick`: a System One answer for Clef (`top` on `pick`, the rest
@@ -93,3 +93,22 @@
9393 const [a] = await adviseHeld(ai, [held("a = 1", "b = 2")], me);
9494 assert.equal(a, null);
9595});
97+test("the switch: off leaves the answer alone, on adds advice, act also tells the client to settle", async () => {
98+ const answer = { ok: false, collisions: [routes] };
99+ const request = { message: "my reason" };
100+ assert.equal(await withAdvice({ AI: fakeAi("both") }, "publish", "me", request, answer), answer);
101+ assert.equal(await withAdvice({ AUTOSETTLE: "on", AI: fakeAi("both") }, "draft", "me", request, answer), answer);
102+ const on = (await withAdvice({ AUTOSETTLE: "on", AI: fakeAi("both") }, "publish", "me", request, answer)) as {
103+ advice?: unknown[];
104+ settle?: boolean;
105+ };
106+ assert.equal(on.advice?.length, 1);
107+ assert.equal(on.settle, undefined);
108+ const act = (await withAdvice({ AUTOSETTLE: "act", AI: fakeAi("both") }, "publish", "me", request, answer)) as {
109+ settle?: boolean;
110+ };
111+ assert.equal(act.settle, true);
112+ const ok = { ok: true, version: 4 };
113+ assert.equal(await withAdvice({ AUTOSETTLE: "act", AI: fakeAi("both") }, "publish", "me", request, ok), ok);
114+});