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

Auto-settle (#19): Clef, Cloudflare's decision model on Workers AI, as a settler. Clef takes Jev's System One request, so clef.ts sends jev.ts's own questions through the local Worker's new /system-one route, with the same code checks before and after. score.ts and settle-one.ts take --via clef (--model clef or clef-flash). Six local holds: 6 of 6 right, 0.4 to 0.6 s each.

of shared·autosettle··Not checked

Version 197 · Files at version 198

5 files, 102 lines added, 18 removed.

--- /dev/null
+++ b/scripts/autosettle/clef.ts
@@ -0,0 +1,45 @@
1+// Ask Clef, Cloudflare's decision model on Workers AI, how a hold should be settled (#19). Clef takes Jev's
2+// System One request (state and typed questions) and answers with a probability per option, so the questions are
3+// jev.ts's own; it goes through the local Worker (workers-ai/, wrangler dev), which has the AI binding.
4+
5+import { type Hold, type SystemOneAnswer, systemOneBody, type Verdict, verdictOf } from "./jev.ts";
6+import { refused, ruled } from "./rules.ts";
7+import { WORKER } from "./workers-ai.ts";
8+
9+export interface ClefVerdict extends Verdict {
10+ readonly reason?: string;
11+ readonly by: "rule" | "model" | "turned down";
12+ readonly modelPick?: Verdict["pick"];
13+}
15+/** Code's rules first, then Clef, then code's check on its pick, as for the Workers AI text model. */
16+export async function askClef(
17+ h: Hold,
18+ opts: { model?: "clef" | "clef-flash"; url?: string } = {},
19+): Promise<ClefVerdict> {
20+ const rule = ruled(h);
21+ if (rule)
22+ return {
23+ pick: rule.pick,
24+ reason: rule.reason,
25+ confidence: 1,
26+ probabilities: { yours: 0, theirs: 0, both: 0, agent: 0, [rule.pick]: 1 },
27+ orders: [],
28+ signs: {},
29+ model: "rule",
30+ ms: 0,
31+ inputTokens: 0,
32+ by: "rule",
33+ };
34+ const started = performance.now();
35+ const res = await fetch(`${opts.url ?? WORKER}/system-one`, {
36+ method: "POST",
37+ headers: { "content-type": "application/json" },
38+ body: JSON.stringify(systemOneBody(h, opts.model ?? "clef")),
39+ });
40+ const out = (await res.json()) as SystemOneAnswer & { error?: string };
41+ if (!res.ok || out.error || !out.answers) throw new Error(`Clef: ${out.error ?? res.status}`);
42+ const v = verdictOf({ ...out, model: out.model ?? opts.model ?? "clef" }, performance.now() - started);
43+ const no = refused(h, v.pick);
44+ return no ? { ...v, pick: "agent", reason: no, by: "turned down", modelPick: v.pick } : { ...v, by: "model" };
45+}
--- a/scripts/autosettle/jev.ts
+++ b/scripts/autosettle/jev.ts
@@ -124,32 +124,43 @@
124124 return PICKS.reduce((a, b) => (p[b] > p[a] ? b : a));
125125}
126126
127−/** Ask Jev once, with the choice in two option orders (Jev's docs warn order can sway a Choice) and the side questions. */
128−export async function ask(h: Hold, opts: { model?: string; key?: string } = {}): Promise<Verdict> {
129− const forward = PICKS;
130− const backward = [...PICKS].reverse();
131− const body = {
132− model: opts.model ?? "jev-latest",
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,
133134 state: stateOf(h),
134135 questions: {
135− settle: choice(forward),
136− settle_reversed: choice(backward),
136+ settle: choice(PICKS),
137+ settle_reversed: choice([...PICKS].reverse()),
137138 ...Object.fromEntries(Object.entries(SIGNS).map(([id, q]) => [id, { type: "noul", instructions: q }])),
138139 },
139140 };
141+}
143+export interface SystemOneAnswer {
144+ model: string;
145+ answers: Record<string, { type: string; probabilities?: Record<string, number>; noul?: number; choice?: string }>;
146+ usage?: { input_tokens?: number };
147+}
149+/** Ask Jev once. */
150+export async function ask(h: Hold, opts: { model?: string; key?: string } = {}): Promise<Verdict> {
140151 const started = performance.now();
141152 const res = await fetch(ENDPOINT, {
142153 method: "POST",
143154 headers: { authorization: `Bearer ${opts.key ?? apiKey()}`, "content-type": "application/json" },
144− body: JSON.stringify(body),
155+ body: JSON.stringify(systemOneBody(h, opts.model ?? "jev-latest")),
145156 });
146157 const ms = performance.now() - started;
147158 if (!res.ok) throw new Error(`Jev answered ${res.status}: ${(await res.text()).slice(0, 500)}`);
148− const out = (await res.json()) as {
149− model: string;
150− answers: Record<string, { type: string; probabilities?: Record<string, number>; noul?: number; choice?: string }>;
151− usage: { input_tokens: number };
152− };
159+ return verdictOf((await res.json()) as SystemOneAnswer, ms);
160+}
162+/** A System One answer to systemOneBody's questions, as a Verdict. */
163+export function verdictOf(out: SystemOneAnswer, ms: number): Verdict {
153164 const orders = ["settle", "settle_reversed"].map((id) => {
154165 const probabilities = Object.fromEntries(PICKS.map((k) => [k, out.answers[id]!.probabilities![k] ?? 0])) as Record<
155166 Pick,
@@ -168,7 +179,7 @@
168179 signs: Object.fromEntries(Object.keys(SIGNS).map((id) => [id, out.answers[id]?.noul ?? Number.NaN])),
169180 model: out.model,
170181 ms,
171− inputTokens: out.usage.input_tokens,
182+ inputTokens: out.usage?.input_tokens ?? 0,
172183 };
173184}
174185
--- a/scripts/autosettle/score.ts
+++ b/scripts/autosettle/score.ts
@@ -1,6 +1,6 @@
11// Score a model against how agents really settled past holds (#19).
22//
3−// node scripts/autosettle/score.ts <cases.json> [--via workers-ai|jev] [--model <id>] [--out <report.json>]
3+// node scripts/autosettle/score.ts <cases.json> [--via workers-ai|clef|jev] [--model <id>] [--out <report.json>]
44//
55// --via workers-ai (the default) needs the Worker in workers-ai/ running under wrangler dev.
66//
@@ -9,6 +9,7 @@
99// both, or rewrote, which counts as "agent": a hand edit). --via jev needs JEV_API_KEY.
1010
1111import { readFileSync, writeFileSync } from "node:fs";
12+import { askClef } from "./clef.ts";
1213import { ask, dollars, type Hold, PICKS, type Pick } from "./jev.ts";
1314import { askWorkersAi } from "./workers-ai.ts";
1415
@@ -70,7 +71,12 @@
7071for (const c of cases) {
7172 try {
7273 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);
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);
7480 const t = truth(c.kept);
7581 rows.push({ id: c.id, truth: t, verdict, right: verdict.pick === t });
7682 console.log(
--- a/scripts/autosettle/settle-one.ts
+++ b/scripts/autosettle/settle-one.ts
@@ -1,12 +1,13 @@
11// Ask a model how to settle each marker block in one file (#19), the way abso
22// pull leaves a held push's file. Prints its pick; changes nothing.
33//
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]
4+// node scripts/autosettle/settle-one.ts <file> [--via workers-ai|clef|jev] [--model <id>] [--message "<your held push's message>"] [--issue "..."] [--name <path in the project>] [--json]
55//
66// --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";
10+import { askClef } from "./clef.ts";
1011import { ask, dollars, type Hold, PICKS } from "./jev.ts";
1112import { askWorkersAi } from "./workers-ai.ts";
1213
@@ -60,6 +61,15 @@
6061 const results = [];
6162 const model = flag(args, "--model") ? { model: flag(args, "--model")! } : {};
6263 for (const [i, h] of holds.entries()) {
64+ if (flag(args, "--via") === "clef") {
65+ const c = await askClef(h, { model: (flag(args, "--model") as "clef" | "clef-flash" | undefined) ?? "clef" });
66+ results.push({ block: i + 1, ...c });
67+ if (!args.includes("--json"))
68+ console.log(
69+ `Block ${i + 1} of ${holds.length} in ${h.file}: ${c.pick}, confidence ${c.confidence.toFixed(2)} (${c.by}${c.modelPick ? `, Clef said ${c.modelPick}` : ""})\n probabilities: ${PICKS.map((k) => `${k} ${(c.probabilities[k] * 100).toFixed(0)}%`).join(", ")}\n ${c.model}, ${c.ms.toFixed(0)} ms`,
70+ );
71+ continue;
72+ }
6373 if (flag(args, "--via") !== "jev") {
6474 const w = await askWorkersAi(h, model);
6575 results.push({ block: i + 1, ...w });
--- a/scripts/autosettle/workers-ai/index.ts
+++ b/scripts/autosettle/workers-ai/index.ts
@@ -74,6 +74,18 @@
7474export default {
7575 async fetch(request: Request, env: Env): Promise<Response> {
7676 if (request.method !== "POST") return new Response("POST a hold", { status: 405 });
77+ // POST /system-one: a System One request (state and typed questions) for a Clef decision model, passed through.
78+ if (new URL(request.url).pathname === "/system-one") {
79+ const body = (await request.json()) as { model?: string };
80+ const id = body.model === "clef-flash" ? "@cf/cloudflare/clef-flash" : "@cf/cloudflare/clef";
81+ const started = Date.now();
82+ try {
83+ const out = await env.AI.run(id, { ...body, model: body.model ?? "clef" });
84+ return Response.json({ ...(out as object), ms: Date.now() - started });
85+ } catch (e) {
86+ return Response.json({ error: (e as Error).message, model: id }, { status: 502 });
87+ }
88+ }
7789 const {
7890 hold,
7991 model = DEFAULT_MODEL,