- MCP
- blame on this site's /mcp
- CLI
- abso blame scripts/autosettle/workers-ai.ts --json
- JSON
- /christopher/abso-core/blame/scripts/autosettle/workers-ai.ts?format=json
67 linesautosettle 100%Last change autosettle in version 192,
67 lines from 3 changes in 2 versions.
autosettle191Auto-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.Compare1// Ask the local auto-settle Worker (workers-ai/, run with wrangler dev) how a hold should be settled (#19).
3import type { Hold, Pick } from "./jev.ts";
autosettle192Auto-settle (#19): code checks around the Workers AI pick. rules.ts settles in code when one side's lines are all in the other's, and turns down a keep-both that would repeat a line or set the same key twice (needs an agent instead). The Worker can take several samples and use their agreement as the confidence, since the model's own confidence swung 0.00 to 0.90 between identical runs.Compare4import { refused, ruled } from "./rules.ts";
autosettle191Auto-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.Compare5
6export const WORKER = process.env.AUTOSETTLE_WORKER ?? "http://127.0.0.1:8845";
8export interface ModelVerdict {
9 readonly pick: Pick;
10 readonly confidence: number;
11 readonly reason: string;
12 readonly model: string;
13 /** Round trip from here, through wrangler dev, to Workers AI and back. */
14 readonly ms: number;
15 /** The model's own time, as the Worker measured it. */
16 readonly modelMs: number;
17 readonly inputTokens: number;
autosettle192Auto-settle (#19): code checks around the Workers AI pick. rules.ts settles in code when one side's lines are all in the other's, and turns down a keep-both that would repeat a line or set the same key twice (needs an agent instead). The Worker can take several samples and use their agreement as the confidence, since the model's own confidence swung 0.00 to 0.90 between identical runs.Compare18 /** rule: code decided without the model. turned down: the model's pick would break the file, so an agent settles. */
19 readonly by: "rule" | "model" | "turned down";
20 /** The model's own pick, when it was turned down. */
21 readonly modelPick?: Pick;
autosettle191Auto-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.Compare22}
autosettle192Auto-settle (#19): code checks around the Workers AI pick. rules.ts settles in code when one side's lines are all in the other's, and turns down a keep-both that would repeat a line or set the same key twice (needs an agent instead). The Worker can take several samples and use their agreement as the confidence, since the model's own confidence swung 0.00 to 0.90 between identical runs.Compare24/** Code's rules first, then the model, then code's check on what the model picked. */
25export async function askWorkersAi(
26 h: Hold,
27 opts: { model?: string; url?: string; samples?: number } = {},
28): Promise<ModelVerdict> {
29 const rule = ruled(h);
30 if (rule) return { ...rule, confidence: 1, model: "rule", ms: 0, modelMs: 0, inputTokens: 0, by: "rule" };
31 const v = await askModel(h, opts);
32 const no = refused(h, v.pick);
33 return no ? { ...v, pick: "agent", reason: no, by: "turned down", modelPick: v.pick } : v;
34}
36async function askModel(h: Hold, opts: { model?: string; url?: string; samples?: number }): Promise<ModelVerdict> {
autosettle191Auto-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.Compare37 const started = performance.now();
38 const res = await fetch(opts.url ?? WORKER, {
39 method: "POST",
40 headers: { "content-type": "application/json" },
autosettle192Auto-settle (#19): code checks around the Workers AI pick. rules.ts settles in code when one side's lines are all in the other's, and turns down a keep-both that would repeat a line or set the same key twice (needs an agent instead). The Worker can take several samples and use their agreement as the confidence, since the model's own confidence swung 0.00 to 0.90 between identical runs.Compare41 body: JSON.stringify({
42 hold: h,
43 ...(opts.model ? { model: opts.model } : {}),
44 samples: opts.samples ?? Number(process.env.AUTOSETTLE_SAMPLES ?? 1),
45 }),
autosettle191Auto-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.Compare46 });
47 const out = (await res.json()) as {
48 pick?: Pick;
49 confidence?: number;
50 reason?: string;
51 model: string;
52 ms: number;
53 error?: string;
54 usage?: { prompt_tokens?: number } | null;
55 };
56 if (!res.ok || out.error || !out.pick) throw new Error(`Workers AI: ${out.error ?? res.status}`);
57 return {
58 pick: out.pick,
59 confidence: Math.min(1, Math.max(0, out.confidence ?? 0)),
60 reason: out.reason ?? "",
61 model: out.model,
62 ms: performance.now() - started,
63 modelMs: out.ms,
64 inputTokens: out.usage?.prompt_tokens ?? 0,
autosettle192Auto-settle (#19): code checks around the Workers AI pick. rules.ts settles in code when one side's lines are all in the other's, and turns down a keep-both that would repeat a line or set the same key twice (needs an agent instead). The Worker can take several samples and use their agreement as the confidence, since the model's own confidence swung 0.00 to 0.90 between identical runs.Compare65 by: "model",
autosettle191Auto-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.Compare66 };
67}