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
blame on this site's /mcp
CLI
abso blame worker/project/test/autosettle.test.ts --json
JSON
/christopher/abso-core/blame/worker/project/test/autosettle.test.ts?format=json
162 linesautosettle 100%Last change autosettle in version 211,

162 lines from 5 changes in 5 versions.

autosettle203Auto-settle (#19): the advice code moves into the tool, worker/project/autosettle.ts with its test, so the platform's pin carries it. server/src/autosettle.ts re-exports it for the open server; the scripts import it from there. No change in behavior.Compare1import assert from "node:assert/strict";
2import { test } from "node:test";
autosettle211Settled automatically, on the record and in the other agent's news (abso-core 23) The client's re-push after settling by itself now ends its message with a fixed trailer, one line per file: 'Settled automatically (abso 19):' then '- <file>: kept <side>, confidence 0.81. <reason>' (or 'by a check in code'). autoTrailer writes it and autoSettledOf reads it back, both in worker/project/autosettle.ts. Publish and the merge queue put it on each settle record as settled[].auto {pick, by, confidence, reason}, so the website can mark the version. The other agent's news says 'X settled its collision with your version N in <file> automatically, as abso's model advised (confidence 0.81), pushing version V: ...' and still outlasts a sync. Tests: autosettle.test.ts 9 (trailer round trip, news words), the client's settle/held tests 21, held-push, markers, project, same-line. Typecheck and server typecheck clean. Local open server under act: the trailer is written as above.Compare3import { type Ai, adviseHeld, autoSettledOf, autoTrailer, refused, ruled, withAdvice } from "../autosettle.ts";
4import { outlastsSync, settledItem } from "../news.ts";
autosettle196Auto-settle (#19), step 3 behind a switch: the open server gives a held push a first opinion. With AUTOSETTLE=on and an AI binding (both off unless set), a held push's answer carries advice for each lines collision: keep yours, theirs or both, or needs an agent, with how many of 5 Workers AI samples agree and one line why. Checks in code run first and after (server/src/autosettle.ts), and the scripts now use the same ones. The client prints the advice under the collisions; the agent still settles. A model that fails leaves no advice and never fails the push's answer. server/test/autosettle.test.ts covers it with a stand-in for Workers AI.Compare5
autosettle201Auto-settle (#19): the open server's advice now comes from Clef, Cloudflare's decision model, by default. On project abso's 33 replayed past holds, Clef settled none wrong at confidence 0.5 or more, where the Llama text model was wrong once at 1.00 (it kept only theirs and would have dropped a 403 guard). A lean to one side under AUTOSETTLE_AT (0.5 unless set) is advice for an agent, marked unsure; AUTOSETTLE_MODEL picks clef-flash or a text model instead. Clef answers in about 0.3 s. The System One questions live in server/src/autosettle.ts, and scripts/autosettle/jev.ts asks Jev the same ones.Compare6/**
7 * A stand-in for Workers AI that always leans to `pick`: a System One answer for Clef (`top` on `pick`, the rest
8 * spread evenly) or a JSON-mode answer for a text model. It counts its calls.
9 */
10function fakeAi(pick: string, top = 0.85): Ai & { calls: number } {
autosettle196Auto-settle (#19), step 3 behind a switch: the open server gives a held push a first opinion. With AUTOSETTLE=on and an AI binding (both off unless set), a held push's answer carries advice for each lines collision: keep yours, theirs or both, or needs an agent, with how many of 5 Workers AI samples agree and one line why. Checks in code run first and after (server/src/autosettle.ts), and the scripts now use the same ones. The client prints the advice under the collisions; the agent still settles. A model that fails leaves no advice and never fails the push's answer. server/test/autosettle.test.ts covers it with a stand-in for Workers AI.Compare11 const ai = {
12 calls: 0,
autosettle201Auto-settle (#19): the open server's advice now comes from Clef, Cloudflare's decision model, by default. On project abso's 33 replayed past holds, Clef settled none wrong at confidence 0.5 or more, where the Llama text model was wrong once at 1.00 (it kept only theirs and would have dropped a 403 guard). A lean to one side under AUTOSETTLE_AT (0.5 unless set) is advice for an agent, marked unsure; AUTOSETTLE_MODEL picks clef-flash or a text model instead. Clef answers in about 0.3 s. The System One questions live in server/src/autosettle.ts, and scripts/autosettle/jev.ts asks Jev the same ones.Compare13 async run(_model: string, input: unknown) {
autosettle196Auto-settle (#19), step 3 behind a switch: the open server gives a held push a first opinion. With AUTOSETTLE=on and an AI binding (both off unless set), a held push's answer carries advice for each lines collision: keep yours, theirs or both, or needs an agent, with how many of 5 Workers AI samples agree and one line why. Checks in code run first and after (server/src/autosettle.ts), and the scripts now use the same ones. The client prints the advice under the collisions; the agent still settles. A model that fails leaves no advice and never fails the push's answer. server/test/autosettle.test.ts covers it with a stand-in for Workers AI.Compare14 ai.calls++;
autosettle201Auto-settle (#19): the open server's advice now comes from Clef, Cloudflare's decision model, by default. On project abso's 33 replayed past holds, Clef settled none wrong at confidence 0.5 or more, where the Llama text model was wrong once at 1.00 (it kept only theirs and would have dropped a 403 guard). A lean to one side under AUTOSETTLE_AT (0.5 unless set) is advice for an agent, marked unsure; AUTOSETTLE_MODEL picks clef-flash or a text model instead. Clef answers in about 0.3 s. The System One questions live in server/src/autosettle.ts, and scripts/autosettle/jev.ts asks Jev the same ones.Compare15 if ((input as { questions?: unknown }).questions) {
16 const probabilities = Object.fromEntries(
17 ["yours", "theirs", "both", "agent"].map((k) => [k, k === pick ? top : (1 - top) / 3]),
18 );
19 return {
20 answers: {
21 settle: { type: "choice", probabilities },
22 settle_reversed: { type: "choice", probabilities },
23 },
24 };
25 }
autosettle196Auto-settle (#19), step 3 behind a switch: the open server gives a held push a first opinion. With AUTOSETTLE=on and an AI binding (both off unless set), a held push's answer carries advice for each lines collision: keep yours, theirs or both, or needs an agent, with how many of 5 Workers AI samples agree and one line why. Checks in code run first and after (server/src/autosettle.ts), and the scripts now use the same ones. The client prints the advice under the collisions; the agent still settles. A model that fails leaves no advice and never fails the push's answer. server/test/autosettle.test.ts covers it with a stand-in for Workers AI.Compare26 return { response: { pick, confidence: 0.9, reason: "a fixed answer" }, usage: { prompt_tokens: 10 } };
27 },
28 };
29 return ai;
32const held = (yours: string, theirs: string, kind = "lines") => ({
33 kind,
34 file: "src/a.ts",
35 yours: { lines: [3, 3] as [number, number], text: yours },
36 theirs: { agent: "other", message: "their reason", text: theirs },
37});
autosettle201Auto-settle (#19): the open server's advice now comes from Clef, Cloudflare's decision model, by default. On project abso's 33 replayed past holds, Clef settled none wrong at confidence 0.5 or more, where the Llama text model was wrong once at 1.00 (it kept only theirs and would have dropped a 403 guard). A lean to one side under AUTOSETTLE_AT (0.5 unless set) is advice for an agent, marked unsure; AUTOSETTLE_MODEL picks clef-flash or a text model instead. Clef answers in about 0.3 s. The System One questions live in server/src/autosettle.ts, and scripts/autosettle/jev.ts asks Jev the same ones.Compare38const routes = held('\t"/blame": blame,\n', '\t"/search": search,\n');
39const me = { agent: "me", message: "my reason" };
autosettle196Auto-settle (#19), step 3 behind a switch: the open server gives a held push a first opinion. With AUTOSETTLE=on and an AI binding (both off unless set), a held push's answer carries advice for each lines collision: keep yours, theirs or both, or needs an agent, with how many of 5 Workers AI samples agree and one line why. Checks in code run first and after (server/src/autosettle.ts), and the scripts now use the same ones. The client prints the advice under the collisions; the agent still settles. A model that fails leaves no advice and never fails the push's answer. server/test/autosettle.test.ts covers it with a stand-in for Workers AI.Compare40
41test("code settles when one side's lines are all in the other's, without asking the model", async () => {
42 const ai = fakeAi("both");
autosettle201Auto-settle (#19): the open server's advice now comes from Clef, Cloudflare's decision model, by default. On project abso's 33 replayed past holds, Clef settled none wrong at confidence 0.5 or more, where the Llama text model was wrong once at 1.00 (it kept only theirs and would have dropped a 403 guard). A lean to one side under AUTOSETTLE_AT (0.5 unless set) is advice for an agent, marked unsure; AUTOSETTLE_MODEL picks clef-flash or a text model instead. Clef answers in about 0.3 s. The System One questions live in server/src/autosettle.ts, and scripts/autosettle/jev.ts asks Jev the same ones.Compare43 const [a] = await adviseHeld(ai, [held("\ttimeoutMs: 30000,\n", "\ttimeoutMs: 30000,\n\tretries: 2,\n")], me);
autosettle196Auto-settle (#19), step 3 behind a switch: the open server gives a held push a first opinion. With AUTOSETTLE=on and an AI binding (both off unless set), a held push's answer carries advice for each lines collision: keep yours, theirs or both, or needs an agent, with how many of 5 Workers AI samples agree and one line why. Checks in code run first and after (server/src/autosettle.ts), and the scripts now use the same ones. The client prints the advice under the collisions; the agent still settles. A model that fails leaves no advice and never fails the push's answer. server/test/autosettle.test.ts covers it with a stand-in for Workers AI.Compare44 assert.equal(a?.pick, "theirs");
45 assert.equal(a?.by, "rule");
46 assert.equal(ai.calls, 0);
47});
49test("a keep-both that sets one key twice, or holds one import in two versions, goes to an agent", () => {
50 const hold = (yours: string[], theirs: string[]) => ({ file: "a", base: [], yours, theirs, before: [], after: [] });
51 assert.match(refused(hold(["\tmaxNesting: 64,"], ["\tmaxNesting: 1000,"]), "both") ?? "", /maxNesting twice/);
52 assert.match(
53 refused(hold(['import { a, b, c } from "./x.ts";'], ['import { a, b, d } from "./x.ts";']), "both") ?? "",
54 /one statement in two versions/,
55 );
56 assert.equal(refused(hold(['\t"/blame": blame,'], ['\t"/search": search,']), "both"), undefined);
57 assert.equal(ruled(hold(['\t"/blame": blame,'], ['\t"/search": search,'])), undefined);
58});
autosettle201Auto-settle (#19): the open server's advice now comes from Clef, Cloudflare's decision model, by default. On project abso's 33 replayed past holds, Clef settled none wrong at confidence 0.5 or more, where the Llama text model was wrong once at 1.00 (it kept only theirs and would have dropped a 403 guard). A lean to one side under AUTOSETTLE_AT (0.5 unless set) is advice for an agent, marked unsure; AUTOSETTLE_MODEL picks clef-flash or a text model instead. Clef answers in about 0.3 s. The System One questions live in server/src/autosettle.ts, and scripts/autosettle/jev.ts asks Jev the same ones.Compare60test("Clef advises by default: one call, its confidence from the probabilities, and other kinds get no advice", async () => {
autosettle196Auto-settle (#19), step 3 behind a switch: the open server gives a held push a first opinion. With AUTOSETTLE=on and an AI binding (both off unless set), a held push's answer carries advice for each lines collision: keep yours, theirs or both, or needs an agent, with how many of 5 Workers AI samples agree and one line why. Checks in code run first and after (server/src/autosettle.ts), and the scripts now use the same ones. The client prints the advice under the collisions; the agent still settles. A model that fails leaves no advice and never fails the push's answer. server/test/autosettle.test.ts covers it with a stand-in for Workers AI.Compare61 const ai = fakeAi("both");
autosettle201Auto-settle (#19): the open server's advice now comes from Clef, Cloudflare's decision model, by default. On project abso's 33 replayed past holds, Clef settled none wrong at confidence 0.5 or more, where the Llama text model was wrong once at 1.00 (it kept only theirs and would have dropped a 403 guard). A lean to one side under AUTOSETTLE_AT (0.5 unless set) is advice for an agent, marked unsure; AUTOSETTLE_MODEL picks clef-flash or a text model instead. Clef answers in about 0.3 s. The System One questions live in server/src/autosettle.ts, and scripts/autosettle/jev.ts asks Jev the same ones.Compare62 const advice = await adviseHeld(ai, [routes, held("x", "y", "definition")], me);
autosettle196Auto-settle (#19), step 3 behind a switch: the open server gives a held push a first opinion. With AUTOSETTLE=on and an AI binding (both off unless set), a held push's answer carries advice for each lines collision: keep yours, theirs or both, or needs an agent, with how many of 5 Workers AI samples agree and one line why. Checks in code run first and after (server/src/autosettle.ts), and the scripts now use the same ones. The client prints the advice under the collisions; the agent still settles. A model that fails leaves no advice and never fails the push's answer. server/test/autosettle.test.ts covers it with a stand-in for Workers AI.Compare63 assert.equal(advice[0]?.pick, "both");
64 assert.equal(advice[0]?.by, "model");
autosettle201Auto-settle (#19): the open server's advice now comes from Clef, Cloudflare's decision model, by default. On project abso's 33 replayed past holds, Clef settled none wrong at confidence 0.5 or more, where the Llama text model was wrong once at 1.00 (it kept only theirs and would have dropped a 403 guard). A lean to one side under AUTOSETTLE_AT (0.5 unless set) is advice for an agent, marked unsure; AUTOSETTLE_MODEL picks clef-flash or a text model instead. Clef answers in about 0.3 s. The System One questions live in server/src/autosettle.ts, and scripts/autosettle/jev.ts asks Jev the same ones.Compare65 assert.equal(advice[0]?.model, "@cf/cloudflare/clef");
66 assert.equal(advice[0]?.confidence.toFixed(2), "0.80");
autosettle196Auto-settle (#19), step 3 behind a switch: the open server gives a held push a first opinion. With AUTOSETTLE=on and an AI binding (both off unless set), a held push's answer carries advice for each lines collision: keep yours, theirs or both, or needs an agent, with how many of 5 Workers AI samples agree and one line why. Checks in code run first and after (server/src/autosettle.ts), and the scripts now use the same ones. The client prints the advice under the collisions; the agent still settles. A model that fails leaves no advice and never fails the push's answer. server/test/autosettle.test.ts covers it with a stand-in for Workers AI.Compare67 assert.equal(advice[1], null);
autosettle201Auto-settle (#19): the open server's advice now comes from Clef, Cloudflare's decision model, by default. On project abso's 33 replayed past holds, Clef settled none wrong at confidence 0.5 or more, where the Llama text model was wrong once at 1.00 (it kept only theirs and would have dropped a 403 guard). A lean to one side under AUTOSETTLE_AT (0.5 unless set) is advice for an agent, marked unsure; AUTOSETTLE_MODEL picks clef-flash or a text model instead. Clef answers in about 0.3 s. The System One questions live in server/src/autosettle.ts, and scripts/autosettle/jev.ts asks Jev the same ones.Compare68 assert.equal(ai.calls, 1);
69});
71test("a lean to one side under the threshold goes to an agent, saying which side it leaned to", async () => {
72 const [a] = await adviseHeld(fakeAi("both", 0.55), [routes], me);
73 assert.equal(a?.pick, "agent");
74 assert.equal(a?.by, "unsure");
75 assert.equal(a?.modelPick, "both");
76 const [b] = await adviseHeld(fakeAi("both", 0.55), [routes], me, { at: 0.3 });
77 assert.equal(b?.pick, "both");
78});
80test("a text model named instead takes 5 samples, its confidence the share that agree", async () => {
81 const ai = fakeAi("both");
82 const [a] = await adviseHeld(ai, [routes], me, { model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast" });
83 assert.equal(a?.pick, "both");
84 assert.equal(a?.confidence, 1);
autosettle196Auto-settle (#19), step 3 behind a switch: the open server gives a held push a first opinion. With AUTOSETTLE=on and an AI binding (both off unless set), a held push's answer carries advice for each lines collision: keep yours, theirs or both, or needs an agent, with how many of 5 Workers AI samples agree and one line why. Checks in code run first and after (server/src/autosettle.ts), and the scripts now use the same ones. The client prints the advice under the collisions; the agent still settles. A model that fails leaves no advice and never fails the push's answer. server/test/autosettle.test.ts covers it with a stand-in for Workers AI.Compare85 assert.equal(ai.calls, 5);
86});
88test("a model that fails leaves no advice instead of failing the push's answer", async () => {
89 const ai: Ai = {
90 async run() {
91 throw new Error("Workers AI is down");
92 },
93 };
autosettle201Auto-settle (#19): the open server's advice now comes from Clef, Cloudflare's decision model, by default. On project abso's 33 replayed past holds, Clef settled none wrong at confidence 0.5 or more, where the Llama text model was wrong once at 1.00 (it kept only theirs and would have dropped a 403 guard). A lean to one side under AUTOSETTLE_AT (0.5 unless set) is advice for an agent, marked unsure; AUTOSETTLE_MODEL picks clef-flash or a text model instead. Clef answers in about 0.3 s. The System One questions live in server/src/autosettle.ts, and scripts/autosettle/jev.ts asks Jev the same ones.Compare94 const [a] = await adviseHeld(ai, [held("a = 1", "b = 2")], me);
autosettle196Auto-settle (#19), step 3 behind a switch: the open server gives a held push a first opinion. With AUTOSETTLE=on and an AI binding (both off unless set), a held push's answer carries advice for each lines collision: keep yours, theirs or both, or needs an agent, with how many of 5 Workers AI samples agree and one line why. Checks in code run first and after (server/src/autosettle.ts), and the scripts now use the same ones. The client prints the advice under the collisions; the agent still settles. A model that fails leaves no advice and never fails the push's answer. server/test/autosettle.test.ts covers it with a stand-in for Workers AI.Compare95 assert.equal(a, null);
autosettle204Auto-settle switch (abso 19): on advises, act also has the client settle 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).Compare96});
98test("the switch: off leaves the answer alone, on adds advice, act also tells the client to settle", async () => {
99 const answer = { ok: false, collisions: [routes] };
100 const request = { message: "my reason" };
101 assert.equal(await withAdvice({ AI: fakeAi("both") }, "publish", "me", request, answer), answer);
102 assert.equal(await withAdvice({ AUTOSETTLE: "on", AI: fakeAi("both") }, "draft", "me", request, answer), answer);
103 const on = (await withAdvice({ AUTOSETTLE: "on", AI: fakeAi("both") }, "publish", "me", request, answer)) as {
104 advice?: unknown[];
105 settle?: boolean;
106 };
107 assert.equal(on.advice?.length, 1);
108 assert.equal(on.settle, undefined);
109 const act = (await withAdvice({ AUTOSETTLE: "act", AI: fakeAi("both") }, "publish", "me", request, answer)) as {
110 settle?: boolean;
111 };
112 assert.equal(act.settle, true);
113 const ok = { ok: true, version: 4 };
114 assert.equal(await withAdvice({ AUTOSETTLE: "act", AI: fakeAi("both") }, "publish", "me", request, ok), ok);
autosettle211Settled automatically, on the record and in the other agent's news (abso-core 23) The client's re-push after settling by itself now ends its message with a fixed trailer, one line per file: 'Settled automatically (abso 19):' then '- <file>: kept <side>, confidence 0.81. <reason>' (or 'by a check in code'). autoTrailer writes it and autoSettledOf reads it back, both in worker/project/autosettle.ts. Publish and the merge queue put it on each settle record as settled[].auto {pick, by, confidence, reason}, so the website can mark the version. The other agent's news says 'X settled its collision with your version N in <file> automatically, as abso's model advised (confidence 0.81), pushing version V: ...' and still outlasts a sync. Tests: autosettle.test.ts 9 (trailer round trip, news words), the client's settle/held tests 21, held-push, markers, project, same-line. Typecheck and server typecheck clean. Local open server under act: the trailer is written as above.Compare115});
117test("the message trailer: the client writes what it settled by itself, and the server reads it back by file", () => {
118 const trailer = autoTrailer([
119 [
120 "docs/start.md",
121 { pick: "yours", by: "model", confidence: 0.8125, reason: "Both fixed the typo;\nyours adds a line." },
122 ],
123 [
124 "src/network.ts",
125 { pick: "theirs", by: "rule", confidence: 1, reason: "every line of yours is already in theirs" },
126 ],
127 ]);
128 assert.equal(
129 trailer,
130 [
131 "Settled automatically (abso 19):",
132 "- docs/start.md: kept yours, confidence 0.81. Both fixed the typo; yours adds a line.",
133 "- src/network.ts: kept theirs, by a check in code. every line of yours is already in theirs",
134 ].join("\n"),
135 );
136 const read = autoSettledOf(`Fix the jion typo\n\n${trailer}`);
137 assert.deepEqual(read.get("docs/start.md"), {
138 pick: "yours",
139 by: "model",
140 confidence: 0.81,
141 reason: "Both fixed the typo; yours adds a line.",
142 });
143 assert.equal(read.get("src/network.ts")?.by, "rule");
144 assert.equal(autoSettledOf("Settled the typo by hand").size, 0);
145});
147test("the other agent's news says the settle was automatic, and still outlasts a sync", () => {
148 const s = {
149 file: "docs/start.md",
150 kept: "yours" as const,
151 theirs: { agent: "client", version: 2 },
152 auto: { pick: "yours" as const, by: "model" as const, confidence: 0.81, reason: "r" },
153 };
154 const item = settledItem("docs", 3, s);
155 assert.equal(outlastsSync(item.text), true);
156 assert.match(
157 item.text,
158 /^docs settled its collision with your version 2 in docs\/start\.md automatically, as abso's model advised \(confidence 0\.81\), pushing version 3:/,
159 );
160 const byHand = settledItem("docs", 3, { ...s, auto: undefined });
161 assert.match(byHand.text, /in docs\/start\.md, pushing version 3:/);
autosettle196Auto-settle (#19), step 3 behind a switch: the open server gives a held push a first opinion. With AUTOSETTLE=on and an AI binding (both off unless set), a held push's answer carries advice for each lines collision: keep yours, theirs or both, or needs an agent, with how many of 5 Workers AI samples agree and one line why. Checks in code run first and after (server/src/autosettle.ts), and the scripts now use the same ones. The client prints the advice under the collisions; the agent still settles. A model that fails leaves no advice and never fails the push's answer. server/test/autosettle.test.ts covers it with a stand-in for Workers AI.Compare162});