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
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/scripts/autosettle/score.ts?format=json
133 linesautosettle 100%Last change autosettle in version 198, 3 versions changed it
1// Score a model against how agents really settled past holds (#19).
2//
3// node scripts/autosettle/score.ts <cases.json> [--via workers-ai|clef|jev] [--model <id>] [--out <report.json>]
4//
5// --via workers-ai (the default) needs the Worker in workers-ai/ running under wrangler dev.
6//
7// A case is one settled collision: base, yours, theirsLines, context, both
8// pushes' messages, and `kept` from the server's settled record (yours, theirs,
9// both, or rewrote, which counts as "agent": a hand edit). --via jev needs JEV_API_KEY.
11import { readFileSync, writeFileSync } from "node:fs";
12import { askClef } from "./clef.ts";
13import { ask, dollars, type Hold, PICKS, type Pick } from "./jev.ts";
14import { askWorkersAi } from "./workers-ai.ts";
16/** What score needs from either model. */
17interface Verdict {
18 pick: Pick;
19 confidence: number;
20 model: string;
21 ms: number;
22 inputTokens: number;
23 reason?: string;
24 probabilities?: Record<Pick, number>;
25 orders?: readonly { pick: Pick }[];
28interface Case {
29 id: string;
30 file: string;
31 kind?: string;
32 settler: { agent: string; heldMessage?: string; settleMessage?: string };
33 theirs: { agent: string; version: number; message?: string };
34 base: string[] | null;
35 yours: string[] | null;
36 theirsLines: string[] | null;
37 context?: { before?: string[]; after?: string[] };
38 kept: "yours" | "theirs" | "both" | "rewrote";
39 issue?: string | null;
42const truth = (kept: Case["kept"]): Pick => (kept === "rewrote" ? "agent" : kept);
44function holdOf(c: Case): Hold {
45 return {
46 file: c.file,
47 base: c.base ?? [],
48 yours: c.yours ?? [],
49 theirs: c.theirsLines ?? [],
50 before: c.context?.before ?? [],
51 after: c.context?.after ?? [],
52 yourAgent: c.settler.agent,
53 ...(c.settler.heldMessage ? { yourMessage: c.settler.heldMessage } : {}),
54 theirAgent: c.theirs.agent,
55 ...(c.theirs.message ? { theirMessage: c.theirs.message } : {}),
56 ...(c.issue ? { issue: c.issue } : {}),
57 };
60function flag(args: string[], name: string): string | undefined {
61 const i = args.indexOf(name);
62 return i === -1 ? undefined : args[i + 1];
65const args = process.argv.slice(2);
66const via = flag(args, "--via") ?? "workers-ai";
67const cases = (JSON.parse(readFileSync(args[0]!, "utf8")) as Case[]).filter(
68 (c) => c.yours !== null && c.theirsLines !== null,
69);
70const rows: { id: string; truth: Pick; verdict: Verdict; right: boolean }[] = [];
71for (const c of cases) {
72 try {
73 const model = flag(args, "--model") ? { model: flag(args, "--model")! } : {};
74 const verdict: Verdict =
75 via === "jev"
76 ? await ask(holdOf(c), model)
77 : via === "clef"
78 ? await askClef(holdOf(c), { model: (model.model as "clef" | "clef-flash") ?? "clef" })
79 : await askWorkersAi(holdOf(c), model);
80 const t = truth(c.kept);
81 rows.push({ id: c.id, truth: t, verdict, right: verdict.pick === t });
82 console.log(
83 `${verdict.pick === t ? "agree" : "DIFFER"} ${c.id}: agent ${t}, model ${verdict.pick} ${verdict.confidence.toFixed(2)} (${verdict.ms.toFixed(0)} ms)`,
84 );
85 } catch (e) {
86 console.log(`error ${c.id}: ${(e as Error).message}`);
87 }
90const mean = (xs: number[]) => (xs.length === 0 ? Number.NaN : xs.reduce((a, b) => a + b, 0) / xs.length);
91const right = rows.filter((r) => r.right);
92const wrong = rows.filter((r) => !r.right);
93const ms = rows.map((r) => r.verdict.ms).sort((a, b) => a - b);
94const tokens = rows.map((r) => r.verdict.inputTokens);
95const at = (threshold: number) => {
96 const sure = rows.filter((r) => r.verdict.confidence >= threshold);
97 return { threshold, settled: sure.length, agreed: sure.filter((r) => r.right).length };
98};
99const report = {
100 via,
101 model: rows[0]?.verdict.model,
102 cases: rows.length,
103 skipped: cases.length - rows.length,
104 agreed: right.length,
105 confidenceWhenRight: mean(right.map((r) => r.verdict.confidence)),
106 confidenceWhenWrong: mean(wrong.map((r) => r.verdict.confidence)),
107 thresholds: [0.3, 0.5, 0.6, 0.7, 0.8, 0.9].map(at),
108 confusion: Object.fromEntries(
109 PICKS.map((t) => [
110 t,
111 Object.fromEntries(PICKS.map((p) => [p, rows.filter((r) => r.truth === t && r.verdict.pick === p).length])),
112 ]),
113 ),
114 ordersDisagreed: rows.filter((r) => r.verdict.orders && r.verdict.orders[0]!.pick !== r.verdict.orders[1]!.pick)
115 .length,
116 latencyMs: { median: ms[Math.floor(ms.length / 2)], max: ms[ms.length - 1], mean: mean(ms) },
117 inputTokensMean: mean(tokens),
118 ...(via === "jev" ? { dollarsPerCall: dollars(mean(tokens)) } : {}),
119 rows: rows.map((r) => ({
120 id: r.id,
121 agent: r.truth,
122 model: r.verdict.pick,
123 confidence: r.verdict.confidence,
124 probabilities: r.verdict.probabilities,
125 orders: r.verdict.orders?.map((o) => o.pick),
126 reason: r.verdict.reason,
127 ms: Math.round(r.verdict.ms),
128 })),
129};
130const out = flag(args, "--out");
131if (out) writeFileSync(out, JSON.stringify(report, null, "\t"));
132const { rows: _, ...summary } = report;
133console.log(JSON.stringify(summary, null, "\t"));