- MCP
- show on this site's /mcp
- CLI
- abso show 201 --json
- JSON
- /christopher/abso-core/versions/201?format=json
Auto-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.
of shared·autosettle··Not checked
Version 200 · Files at version 201
7 files, 207 lines added, 106 removed.
--- a/client/src/api-answers.ts
+++ b/client/src/api-answers.ts
@@ -91,14 +91,14 @@
9191 | { ok: false; collisions: readonly Collision[]; reason?: string; advice?: readonly (Advice | null)[] };
9393 * A server's first opinion on one collision of a held push (#19), when it runs AUTOSETTLE: which settle fits,
94− * how sure, and why. `by`: rule (code decided), model (Workers AI), or turned down (the model's pick would break
95− * the file, so an agent settles).
94+ * how sure, and why. `by`: rule (code decided), model (Workers AI), turned down (the model's pick would break
95+ * the file, so an agent settles), or unsure (the model leaned to a side under the server's threshold).
101− readonly by: "rule" | "model" | "turned down";
--- a/client/src/publish-commands.ts
+++ b/client/src/publish-commands.ts
@@ -505,7 +505,9 @@
508− : `${a.confidence.toFixed(2)} of samples agree`;
511513
--- a/scripts/autosettle/jev.ts
+++ b/scripts/autosettle/jev.ts
@@ -7,7 +7,11 @@
88
1011
12+// The questions are the open server's own (server/src/autosettle.ts), so Jev and Clef are asked alike.
14+
1216
@@ -67,79 +71,10 @@
6973
70−const text = (lines: readonly string[]): string => (lines.length === 0 ? "(no lines)" : lines.join("\n"));
71−
72−function stateOf(h: Hold): Record<string, unknown> {
73− return {
74− file: h.file,
75− lines_above: text(h.before),
76− before_either_change: text(h.base),
77− yours: text(h.yours),
78− theirs: text(h.theirs),
79− lines_below: text(h.after),
80− your_push: { agent: h.yourAgent ?? "you", message: h.yourMessage ?? "(no message)" },
81− their_push: { agent: h.theirAgent ?? "the other agent", message: h.theirMessage ?? "(no message)" },
82− ...(h.issue ? { issue: h.issue } : {}),
83− };
84−}
85−
86−const INSTRUCTIONS =
87− "Two agents changed the same lines of `file`. Both started from `before_either_change`. " +
88− "`yours` is what the held agent wrote, for the reason in `your_push`; `theirs` was pushed first, for the reason in `their_push`. " +
89− "The region sits between `lines_above` and `lines_below`. " +
90− "Which result is correct code that does what both pushes meant?";
91−
92−const CRITERIA: Record<Pick, string> = {
93− yours: "Keep `yours` only: `yours` already does what `theirs` meant, or `theirs` is wrong or out of date.",
94− theirs: "Keep `theirs` only: `theirs` already does what `yours` meant, or `yours` is wrong or out of date.",
95− both: "Keep both unchanged, `yours` then `theirs`: they add separate things that work side by side, and nothing is duplicated or contradicts.",
96− agent:
97− "Neither side alone and not both unchanged: the sides change the same thing in different ways (such as two different values for one setting), or keeping both would duplicate or contradict, so a correct result needs a hand edit.",
98−};
99−
100−function choice(order: readonly Pick[]) {
101− return {
102− type: "choice",
103− instructions: INSTRUCTIONS,
104− criteria: Object.fromEntries(order.map((p) => [p, CRITERIA[p]])),
105− };
106−}
107−
108−const SIGNS: Record<string, string> = {
109− same_setting_different_values:
110− "Do `yours` and `theirs` set the same setting, constant or value to two different values?",
111− theirs_covers_yours: "Does `theirs` already do everything `yours` was changed to do?",
112− yours_covers_theirs: "Does `yours` already do everything `theirs` was changed to do?",
113− both_unchanged_compiles:
114− "If `yours` were placed directly above `theirs`, unchanged, would the file still be correct code with nothing defined twice?",
115−};
116−
117−function confidenceOf(p: Record<Pick, number>): number {
118− const max = Math.max(...PICKS.map((k) => p[k]));
119− const even = 1 / PICKS.length;
120− return Math.max(0, (max - even) / (1 - even));
121−}
122−
12677
127−/**
128− * One System One request (TypeSafe's API, which Cloudflare's Clef also takes): the choice in two option orders
129− * (Jev's docs warn order can sway a Choice) and the side questions.
130− */
131−export function systemOneBody(h: Hold, model: string) {
132− return {
133− model,
134− state: stateOf(h),
135− questions: {
136− settle: choice(PICKS),
137− settle_reversed: choice([...PICKS].reverse()),
138− ...Object.fromEntries(Object.entries(SIGNS).map(([id, q]) => [id, { type: "noul", instructions: q }])),
139− },
140− };
141−}
142−
14580 answers: Record<string, { type: string; probabilities?: Record<string, number>; noul?: number; choice?: string }>;
--- a/server/src/autosettle.ts
+++ b/server/src/autosettle.ts
@@ -30,8 +30,11 @@
33− /** rule: code decided without the model. turned down: the model's pick would break the file. */
34− readonly by: "rule" | "model" | "turned down";
34+ * rule: code decided without the model. turned down: the model's pick would break the file. unsure: the model
@@ -168,13 +171,130 @@
170173
174+const text = (lines: readonly string[]): string => (lines.length === 0 ? "(no lines)" : lines.join("\n"));
175+
181+ before_either_change: h.base.length === 0 && h.before.length === 0 ? "(not given)" : text(h.base),
186+ their_push: { agent: h.theirAgent ?? "the other agent", message: h.theirMessage ?? "(no message)" },
190+
193+ "`yours` is what the held agent wrote, for the reason in `your_push`; `theirs` was pushed first, for the reason in `their_push`. " +
196+
198+ yours: "Keep `yours` only: `yours` already does what `theirs` meant, or `theirs` is wrong or out of date.",
199+ theirs: "Keep `theirs` only: `theirs` already does what `yours` meant, or `yours` is wrong or out of date.",
200+ both: "Keep both unchanged, `yours` then `theirs`: they add separate things that work side by side, and nothing is duplicated or contradicts.",
202+ "Neither side alone and not both unchanged: the sides change the same thing in different ways (such as two different values for one setting), or keeping both would duplicate or contradict, so a correct result needs a hand edit.",
204+
210+
218+ "If `yours` were placed directly above `theirs`, unchanged, would the file still be correct code with nothing defined twice?",
220+
222+ * A System One request (TypeSafe's Jev and Cloudflare's Clef both take it): the choice in two option orders, since
232+ ...Object.fromEntries(Object.entries(SIGNS).map(([id, q]) => [id, { type: "noul", instructions: q }])),
236+
237+/** Choice confidence: how far the top probability sits above an even split, 0 to 1 (TypeSafe's formula). */
243+
249+): Promise<{ pick: Pick; confidence: number; reason: string; probabilities: Record<Pick, number> }> {
250+ const out = (await ai.run(model === "clef-flash" ? "@cf/cloudflare/clef-flash" : "@cf/cloudflare/clef", {
269+ reason: `Clef's probabilities: ${PICKS.map((k) => `${words[k]} ${probabilities[k].toFixed(2)}`).join(", ")}`,
272+
172−export async function advise(ai: Ai, h: Hold, opts: { model?: string; samples?: number } = {}): Promise<Advice> {
176− const m = await modelPick(ai, h, opts);
177− const model = opts.model ?? MODEL;
282+ // Clef unless a text model is named: on project abso's 33 past holds it settled nothing wrong at 0.5 or more,
@@ -207,24 +327,29 @@
211332 const lines = (text: string) => (text === "" ? [] : text.replace(/\r?\n$/, "").split(/\r?\n/));
216− return await advise(ai, {
217− file: c.file,
218− base: [],
219− yours: lines(c.yours.text),
220− theirs: lines(c.theirs.text),
221− before: [],
222− after: [],
223− yourAgent: held.agent,
224− yourMessage: held.message,
225− theirAgent: c.theirs.agent,
226− theirMessage: c.theirs.message,
227− });
--- a/server/src/env.ts
+++ b/server/src/env.ts
@@ -26,6 +26,10 @@
2727 /** "on" gives a held push a first opinion on each collision from Workers AI (#19); needs the AI binding. */
--- a/server/src/router.ts
+++ b/server/src/router.ts
@@ -274,7 +274,15 @@
277− const advice = await adviseHeld(env.AI, held.collisions, { agent, message });
--- a/server/test/autosettle.test.ts
+++ b/server/test/autosettle.test.ts
@@ -2,12 +2,26 @@
44
5−/** A stand-in for Workers AI that always answers `pick`, and counts its calls. */
6−function fakeAi(pick: string): Ai & { calls: number } {
6+ * A stand-in for Workers AI that always leans to `pick`: a System One answer for Clef (`top` on `pick`, the rest
9− async run() {
1125 return { response: { pick, confidence: 0.9, reason: "a fixed answer" }, usage: { prompt_tokens: 10 } };
@@ -20,13 +34,12 @@
2339
2440test("code settles when one side's lines are all in the other's, without asking the model", async () => {
26− const [a] = await adviseHeld(ai, [held("\ttimeoutMs: 30000,\n", "\ttimeoutMs: 30000,\n\tretries: 2,\n")], {
27− agent: "me",
28− message: "my reason",
29− });
42+ const [a] = await adviseHeld(ai, [held("\ttimeoutMs: 30000,\n", "\ttimeoutMs: 30000,\n\tretries: 2,\n")], me);
@@ -43,17 +56,31 @@
4558
46−test("the model's pick comes back with how many samples agree, and other kinds get no advice", async () => {
59+test("Clef advises by default: one call, its confidence from the probabilities, and other kinds get no advice", async () => {
48− const advice = await adviseHeld(
49− ai,
50− [held('\t"/blame": blame,\n', '\t"/search": search,\n'), held("x", "y", "definition")],
51− { agent: "me", message: "my reason" },
52− );
55− assert.equal(advice[0]?.confidence, 1);
69+
70+test("a lean to one side under the threshold goes to an agent, saying which side it leaned to", async () => {
78+
79+test("a text model named instead takes 5 samples, its confidence the share that agree", async () => {
81+ const [a] = await adviseHeld(ai, [routes], me, { model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast" });
5986
@@ -63,6 +90,6 @@
66− const [a] = await adviseHeld(ai, [held("a = 1", "b = 2")], { agent: "me", message: "m" });