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 191 --json
JSON
/christopher/abso-core/versions/191?format=json

Auto-settle (#19): a Workers AI settler. scripts/autosettle/workers-ai is a Worker (wrangler dev --port 8845) that asks Llama 3.3 70B, in JSON mode, for one of keep yours, keep theirs, keep both or needs an agent, plus a confidence and a one-line reason. settle-one and score use it by default (--via jev for Jev). On the commonmark hold (nesting 64 vs 1000) it picks needs an agent, 0.90, in 2.5 s.

of shared·autosettle··Not checked

Version 190 · Files at version 191

6 files, 203 lines added, 17 removed.

--- a/scripts/autosettle/extract.ts
+++ b/scripts/autosettle/extract.ts
@@ -85,7 +85,7 @@
8585 return to < 0 ? null : r.slice(from, to);
8686}
8787
88−const cases = [];
88+const cases: { kept: string; yours: string[] | null }[] = [];
8989for (const c of review.changes) {
9090 for (const s of c.settled) {
9191 const before = fileAt(s.theirs.version - 1, s.file);
--- a/scripts/autosettle/score.ts
+++ b/scripts/autosettle/score.ts
@@ -1,14 +1,29 @@
1−// Score Jev against how agents really settled past holds (#19).
1+// Score a model against how agents really settled past holds (#19).
22//
3−// node scripts/autosettle/score.ts <cases.json> [--out <report.json>] [--model jev-latest]
3+// node scripts/autosettle/score.ts <cases.json> [--via workers-ai|jev] [--model <id>] [--out <report.json>]
44//
5+// --via workers-ai (the default) needs the Worker in workers-ai/ running under wrangler dev.
6+//
57// A case is one settled collision: base, yours, theirsLines, context, both
68// pushes' messages, and `kept` from the server's settled record (yours, theirs,
7−// both, or rewrote, which counts as "agent": a hand edit). Needs JEV_API_KEY.
9+// both, or rewrote, which counts as "agent": a hand edit). --via jev needs JEV_API_KEY.
911import { readFileSync, writeFileSync } from "node:fs";
10−import { ask, dollars, type Hold, PICKS, type Pick, type Verdict } from "./jev.ts";
12+import { ask, dollars, type Hold, PICKS, type Pick } from "./jev.ts";
13+import { askWorkersAi } from "./workers-ai.ts";
1114
15+/** What score needs from either model. */
16+interface Verdict {
17+ pick: Pick;
18+ confidence: number;
19+ model: string;
20+ ms: number;
21+ inputTokens: number;
22+ reason?: string;
23+ probabilities?: Record<Pick, number>;
24+ orders?: readonly { pick: Pick }[];
25+}
1227interface Case {
1328 id: string;
1429 file: string;
@@ -47,17 +62,19 @@
4762}
4863
4964const args = process.argv.slice(2);
65+const via = flag(args, "--via") ?? "workers-ai";
5066const cases = (JSON.parse(readFileSync(args[0]!, "utf8")) as Case[]).filter(
5167 (c) => c.yours !== null && c.theirsLines !== null,
5268);
5369const rows: { id: string; truth: Pick; verdict: Verdict; right: boolean }[] = [];
5470for (const c of cases) {
5571 try {
56− const verdict = await ask(holdOf(c), { ...(flag(args, "--model") ? { model: flag(args, "--model") } : {}) });
72+ const model = flag(args, "--model") ? { model: flag(args, "--model")! } : {};
73+ const verdict: Verdict = via === "jev" ? await ask(holdOf(c), model) : await askWorkersAi(holdOf(c), model);
5774 const t = truth(c.kept);
5875 rows.push({ id: c.id, truth: t, verdict, right: verdict.pick === t });
5976 console.log(
60− `${verdict.pick === t ? "agree" : "DIFFER"} ${c.id}: agent ${t}, Jev ${verdict.pick} ${verdict.confidence.toFixed(2)} (${verdict.ms.toFixed(0)} ms)`,
77+ `${verdict.pick === t ? "agree" : "DIFFER"} ${c.id}: agent ${t}, model ${verdict.pick} ${verdict.confidence.toFixed(2)} (${verdict.ms.toFixed(0)} ms)`,
6178 );
6279 } catch (e) {
6380 console.log(`error ${c.id}: ${(e as Error).message}`);
@@ -74,6 +91,7 @@
7491 return { threshold, settled: sure.length, agreed: sure.filter((r) => r.right).length };
7592};
7693const report = {
94+ via,
7795 model: rows[0]?.verdict.model,
7896 cases: rows.length,
7997 skipped: cases.length - rows.length,
@@ -87,18 +105,19 @@
87105 Object.fromEntries(PICKS.map((p) => [p, rows.filter((r) => r.truth === t && r.verdict.pick === p).length])),
88106 ]),
89107 ),
90− ordersDisagreed: rows.filter((r) => r.verdict.orders[0]!.pick !== r.verdict.orders[1]!.pick).length,
108+ ordersDisagreed: rows.filter((r) => r.verdict.orders && r.verdict.orders[0]!.pick !== r.verdict.orders[1]!.pick)
109+ .length,
91110 latencyMs: { median: ms[Math.floor(ms.length / 2)], max: ms[ms.length - 1], mean: mean(ms) },
92111 inputTokensMean: mean(tokens),
93− dollarsPerCall: dollars(mean(tokens)),
112+ ...(via === "jev" ? { dollarsPerCall: dollars(mean(tokens)) } : {}),
94113 rows: rows.map((r) => ({
95114 id: r.id,
96115 agent: r.truth,
97− jev: r.verdict.pick,
116+ model: r.verdict.pick,
98117 confidence: r.verdict.confidence,
99118 probabilities: r.verdict.probabilities,
100− orders: r.verdict.orders.map((o) => o.pick),
101− signs: r.verdict.signs,
119+ orders: r.verdict.orders?.map((o) => o.pick),
120+ reason: r.verdict.reason,
102121 ms: Math.round(r.verdict.ms),
103122 })),
104123};
--- a/scripts/autosettle/settle-one.ts
+++ b/scripts/autosettle/settle-one.ts
@@ -1,13 +1,14 @@
1−// Ask Jev how to settle each marker block in one file (#19), the way abso pull
2−// leaves a held push's file. Prints Jev's pick and its probabilities; changes nothing.
1+// Ask a model how to settle each marker block in one file (#19), the way abso
2+// pull leaves a held push's file. Prints its pick; changes nothing.
33//
4−// node scripts/autosettle/settle-one.ts <file> [--message "<your held push's message>"] [--issue "..."] [--name <path in the project>] [--json]
4+// node scripts/autosettle/settle-one.ts <file> [--via workers-ai|jev] [--model <id>] [--message "<your held push's message>"] [--issue "..."] [--name <path in the project>] [--json]
55//
6−// Needs JEV_API_KEY in the environment.
6+// --via workers-ai (the default) needs workers-ai/ running under wrangler dev; --via jev needs JEV_API_KEY.
77
88import { readFileSync } from "node:fs";
99import { findBlocks } from "../../client/src/settle.ts";
1010import { ask, dollars, type Hold, PICKS } from "./jev.ts";
11+import { askWorkersAi } from "./workers-ai.ts";
1112
1213const CONTEXT = 15;
1314const CLOSE = /^>>>>>>> theirs: (.*?), version (\d+) "(.*)"$/;
@@ -57,8 +58,18 @@
5758 process.exit(1);
5859 }
5960 const results = [];
61+ const model = flag(args, "--model") ? { model: flag(args, "--model")! } : {};
6062 for (const [i, h] of holds.entries()) {
61− const v = await ask(h);
63+ if (flag(args, "--via") !== "jev") {
64+ const w = await askWorkersAi(h, model);
65+ results.push({ block: i + 1, ...w });
66+ if (!args.includes("--json"))
67+ console.log(
68+ `Block ${i + 1} of ${holds.length} in ${h.file}: ${w.pick}, confidence ${w.confidence.toFixed(2)}\n ${w.reason}\n ${w.model}, ${w.ms.toFixed(0)} ms (model ${w.modelMs} ms), ${w.inputTokens} input tokens`,
69+ );
70+ continue;
71+ }
72+ const v = await ask(h, model);
6273 results.push({ block: i + 1, ...v });
6374 if (args.includes("--json")) continue;
6475 const pct = (x: number) => `${(x * 100).toFixed(0)}%`;
--- /dev/null
+++ b/scripts/autosettle/workers-ai.ts
@@ -0,0 +1,45 @@
1+// Ask the local auto-settle Worker (workers-ai/, run with wrangler dev) how a hold should be settled (#19).
2+
3+import type { Hold, Pick } from "./jev.ts";
4+
5+export const WORKER = process.env.AUTOSETTLE_WORKER ?? "http://127.0.0.1:8845";
6+
7+export interface ModelVerdict {
8+ readonly pick: Pick;
9+ readonly confidence: number;
10+ readonly reason: string;
11+ readonly model: string;
12+ /** Round trip from here, through wrangler dev, to Workers AI and back. */
13+ readonly ms: number;
14+ /** The model's own time, as the Worker measured it. */
15+ readonly modelMs: number;
16+ readonly inputTokens: number;
17+}
19+export async function askWorkersAi(h: Hold, opts: { model?: string; url?: string } = {}): Promise<ModelVerdict> {
20+ const started = performance.now();
21+ const res = await fetch(opts.url ?? WORKER, {
22+ method: "POST",
23+ headers: { "content-type": "application/json" },
24+ body: JSON.stringify({ hold: h, ...(opts.model ? { model: opts.model } : {}) }),
25+ });
26+ const out = (await res.json()) as {
27+ pick?: Pick;
28+ confidence?: number;
29+ reason?: string;
30+ model: string;
31+ ms: number;
32+ error?: string;
33+ usage?: { prompt_tokens?: number } | null;
34+ };
35+ if (!res.ok || out.error || !out.pick) throw new Error(`Workers AI: ${out.error ?? res.status}`);
36+ return {
37+ pick: out.pick,
38+ confidence: Math.min(1, Math.max(0, out.confidence ?? 0)),
39+ reason: out.reason ?? "",
40+ model: out.model,
41+ ms: performance.now() - started,
42+ modelMs: out.ms,
43+ inputTokens: out.usage?.prompt_tokens ?? 0,
44+ };
45+}
--- /dev/null
+++ b/scripts/autosettle/workers-ai/index.ts
@@ -0,0 +1,101 @@
1+// A Worker that asks a Workers AI text model how a held push's collision should
2+// be settled (#19). JSON mode limits the answer to abso's settle choices, a
3+// confidence and a one-line reason: the model picks, it never writes code.
4+//
5+// cd scripts/autosettle/workers-ai && npx wrangler dev --port 8845 (the AI binding always runs on Cloudflare)
6+// POST / with {"hold": <Hold>, "model"?: "<@cf/... model>"}
7+
8+interface Env {
9+ readonly AI: { run(model: string, input: unknown): Promise<unknown> };
10+}
12+interface Hold {
13+ readonly file: string;
14+ readonly base: readonly string[];
15+ readonly yours: readonly string[];
16+ readonly theirs: readonly string[];
17+ readonly before: readonly string[];
18+ readonly after: readonly string[];
19+ readonly yourMessage?: string;
20+ readonly yourAgent?: string;
21+ readonly theirMessage?: string;
22+ readonly theirAgent?: string;
23+ readonly issue?: string;
24+}
26+const PICKS = ["yours", "theirs", "both", "agent"] as const;
27+const DEFAULT_MODEL = "@cf/meta/llama-3.3-70b-instruct-fp8-fast";
29+const SYSTEM = `You settle merge collisions in a version control system for coding agents.
30+Two agents changed the same lines of one file. Both started from BEFORE. YOURS is what the held agent wrote, for the reason in its push message; THEIRS was pushed first, for the reason in its push message.
31+Pick exactly one:
32+- "yours": keep YOURS only. YOURS already does what THEIRS meant, or THEIRS is wrong or out of date.
33+- "theirs": keep THEIRS only. THEIRS already does what YOURS meant, or YOURS is wrong or out of date.
34+- "both": keep both unchanged, YOURS then THEIRS. They add separate things that work side by side, with nothing duplicated or contradictory.
35+- "agent": none of those is correct. 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.
36+Give "confidence" from 0 to 1: how likely your pick is the correct settle. Give "reason" as one plain sentence. Do not write code.`;
38+const block = (lines: readonly string[]) => (lines.length === 0 ? "(no lines)" : lines.join("\n"));
40+function prompt(h: Hold): string {
41+ return [
42+ `FILE: ${h.file}`,
43+ `YOUR PUSH (${h.yourAgent ?? "you"}): ${h.yourMessage ?? "(no message)"}`,
44+ `THEIR PUSH (${h.theirAgent ?? "the other agent"}): ${h.theirMessage ?? "(no message)"}`,
45+ ...(h.issue ? [`ISSUE: ${h.issue}`] : []),
46+ "",
47+ "LINES ABOVE:",
48+ block(h.before),
49+ "",
50+ "BEFORE (what both started from):",
51+ block(h.base),
52+ "",
53+ "YOURS:",
54+ block(h.yours),
55+ "",
56+ "THEIRS:",
57+ block(h.theirs),
58+ "",
59+ "LINES BELOW:",
60+ block(h.after),
61+ ].join("\n");
62+}
64+const SCHEMA = {
65+ type: "object",
66+ properties: {
67+ pick: { type: "string", enum: PICKS },
68+ confidence: { type: "number", minimum: 0, maximum: 1 },
69+ reason: { type: "string" },
70+ },
71+ required: ["pick", "confidence", "reason"],
72+};
74+export default {
75+ async fetch(request: Request, env: Env): Promise<Response> {
76+ if (request.method !== "POST") return new Response("POST a hold", { status: 405 });
77+ const { hold, model = DEFAULT_MODEL } = (await request.json()) as { hold: Hold; model?: string };
78+ const started = Date.now();
79+ try {
80+ const out = (await env.AI.run(model, {
81+ messages: [
82+ { role: "system", content: SYSTEM },
83+ { role: "user", content: prompt(hold) },
84+ ],
85+ response_format: { type: "json_schema", json_schema: SCHEMA },
86+ temperature: 0,
87+ max_tokens: 200,
88+ })) as { response: unknown; usage?: { prompt_tokens?: number; completion_tokens?: number } };
89+ const answer = (typeof out.response === "string" ? JSON.parse(out.response) : out.response) as {
90+ pick: string;
91+ confidence: number;
92+ reason: string;
93+ };
94+ if (!(PICKS as readonly string[]).includes(answer.pick))
95+ return Response.json({ error: `not a settle choice: ${answer.pick}` }, { status: 502 });
96+ return Response.json({ ...answer, model, ms: Date.now() - started, usage: out.usage ?? null });
97+ } catch (e) {
98+ return Response.json({ error: (e as Error).message, model, ms: Date.now() - started }, { status: 502 });
99+ }
100+ },
101+};
--- /dev/null
+++ b/scripts/autosettle/workers-ai/wrangler.jsonc
@@ -0,0 +1,10 @@
1+// The auto-settle prototype's Workers AI caller (#19). Local only: npx wrangler dev from this folder.
2+// The AI binding always runs on Cloudflare, under the account wrangler is signed in to.
3+{
4+ "$schema": "../../../server/node_modules/wrangler/config-schema.json",
5+ "name": "abso-autosettle",
6+ "main": "index.ts",
7+ "compatibility_date": "2026-10-01",
8+ "workers_dev": false,
9+ "ai": { "binding": "AI", "remote": true }
10+}