- MCP
- blame on this site's /mcp
- CLI
- abso blame scripts/autosettle/clef.ts --json
- JSON
- /christopher/abso-core/blame/scripts/autosettle/clef.ts?format=json
45 linesautosettle 100%Last change autosettle in version 198,
45 lines from 2 changes in 1 version.
autosettle198Auto-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.Compare1// 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.
5import { type Hold, type SystemOneAnswer, systemOneBody, type Verdict, verdictOf } from "./jev.ts";
6import { refused, ruled } from "./rules.ts";
7import { WORKER } from "./workers-ai.ts";
9export 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. */
16export 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}