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
blame on this site's /mcp
CLI
abso blame scripts/autosettle/jev.ts --json
JSON
/christopher/abso-core/blame/scripts/autosettle/jev.ts?format=json
122 linesautosettle 100%Last change autosettle in version 203,

122 lines from 7 changes in 4 versions.

autosettle189Jev auto-settle prototype, step 1 (#19): scripts/autosettle asks Jev to pick keep yours, theirs, both, or needs an agent for each marker block, and scores it against past settles. Local scripts only; reads JEV_API_KEY, never prints it.Compare1// Ask Jev (TypeSafe's System One model) how a held push's collision should be
2// settled (#19). Jev answers a Choice with a probability per option, so it can
3// pick among abso's own settle choices but can't write code.
4//
5// API: POST https://api.typesafe.ai/v1/systemone, per https://docs.typesafe.ai/api.md.
6// The key comes from JEV_API_KEY (or TYPESAFE_API_KEY, the SDK's own name) and
7// is never printed or written anywhere.
8
9import { execFileSync } from "node:child_process";
autosettle203Auto-settle (#19): the advice code moves into the tool, worker/project/autosettle.ts with its test, so the platform's pin carries it. server/src/autosettle.ts re-exports it for the open server; the scripts import it from there. No change in behavior.Compare10import { confidenceOf, SIGNS, systemOneBody } from "../../worker/project/autosettle.ts";
autosettle189Jev auto-settle prototype, step 1 (#19): scripts/autosettle asks Jev to pick keep yours, theirs, both, or needs an agent for each marker block, and scores it against past settles. Local scripts only; reads JEV_API_KEY, never prints it.Compare11
autosettle203Auto-settle (#19): the advice code moves into the tool, worker/project/autosettle.ts with its test, so the platform's pin carries it. server/src/autosettle.ts re-exports it for the open server; the scripts import it from there. No change in behavior.Compare12// The questions are the tool's own (worker/project/autosettle.ts), so Jev and Clef are asked alike.
autosettle201Auto-settle (#19): the open server's advice now comes from Clef, Cloudflare's decision model, by default. On project abso's 33 replayed past holds, Clef settled none wrong at confidence 0.5 or more, where the Llama text model was wrong once at 1.00 (it kept only theirs and would have dropped a 403 guard). A lean to one side under AUTOSETTLE_AT (0.5 unless set) is advice for an agent, marked unsure; AUTOSETTLE_MODEL picks clef-flash or a text model instead. Clef answers in about 0.3 s. The System One questions live in server/src/autosettle.ts, and scripts/autosettle/jev.ts asks Jev the same ones.Compare13export { systemOneBody };
autosettle189Jev auto-settle prototype, step 1 (#19): scripts/autosettle asks Jev to pick keep yours, theirs, both, or needs an agent for each marker block, and scores it against past settles. Local scripts only; reads JEV_API_KEY, never prints it.Compare15export const ENDPOINT = "https://api.typesafe.ai/v1/systemone";
17/** abso's settle choices, plus a hand edit by an agent. */
18export type Pick = "yours" | "theirs" | "both" | "agent";
19export const PICKS: readonly Pick[] = ["yours", "theirs", "both", "agent"];
21/** One collision as the held agent sees it: a marker block and what's around it. */
22export interface Hold {
23 readonly file: string;
24 readonly base: readonly string[];
25 readonly yours: readonly string[];
26 readonly theirs: readonly string[];
27 readonly before: readonly string[];
28 readonly after: readonly string[];
29 /** The held push's message: the settler's reason. */
30 readonly yourMessage?: string;
31 readonly yourAgent?: string;
32 /** The push that got there first: its reason. */
33 readonly theirMessage?: string;
34 readonly theirAgent?: string;
35 readonly issue?: string;
38export interface Verdict {
39 readonly pick: Pick;
40 /** Averaged over both option orders. */
41 readonly probabilities: Record<Pick, number>;
42 /** Choice confidence on the averaged probabilities: 0 at an even split, 1 when certain. */
43 readonly confidence: number;
44 /** Each order's own answer, to see whether the order moved it. */
45 readonly orders: readonly { pick: Pick; probabilities: Record<Pick, number>; confidence: number }[];
46 /** Yes-probabilities of the side questions. */
47 readonly signs: Record<string, number>;
48 readonly model: string;
49 readonly ms: number;
50 readonly inputTokens: number;
53export function apiKey(): string {
54 const key = process.env.JEV_API_KEY ?? process.env.TYPESAFE_API_KEY ?? userVariable("JEV_API_KEY");
55 if (!key) throw new Error("No Jev key: set JEV_API_KEY in the environment.");
56 return key;
59/** On Windows, a user variable set after this shell started (setx, or the Environment Variables dialog). */
60function userVariable(name: string): string | undefined {
61 if (process.platform !== "win32") return undefined;
62 try {
63 const out = execFileSync(
64 "powershell.exe",
65 ["-NoProfile", "-Command", `[Environment]::GetEnvironmentVariable('${name}','User')`],
66 { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] },
67 ).trim();
68 return out || undefined;
69 } catch {
70 return undefined;
71 }
74function top(p: Record<Pick, number>): Pick {
75 return PICKS.reduce((a, b) => (p[b] > p[a] ? b : a));
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.Compare76}
78export interface SystemOneAnswer {
79 model: string;
80 answers: Record<string, { type: string; probabilities?: Record<string, number>; noul?: number; choice?: string }>;
81 usage?: { input_tokens?: number };
84/** Ask Jev once. */
autosettle189Jev auto-settle prototype, step 1 (#19): scripts/autosettle asks Jev to pick keep yours, theirs, both, or needs an agent for each marker block, and scores it against past settles. Local scripts only; reads JEV_API_KEY, never prints it.Compare85export async function ask(h: Hold, opts: { model?: string; key?: string } = {}): Promise<Verdict> {
86 const started = performance.now();
87 const res = await fetch(ENDPOINT, {
88 method: "POST",
89 headers: { authorization: `Bearer ${opts.key ?? apiKey()}`, "content-type": "application/json" },
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.Compare90 body: JSON.stringify(systemOneBody(h, opts.model ?? "jev-latest")),
autosettle189Jev auto-settle prototype, step 1 (#19): scripts/autosettle asks Jev to pick keep yours, theirs, both, or needs an agent for each marker block, and scores it against past settles. Local scripts only; reads JEV_API_KEY, never prints it.Compare91 });
92 const ms = performance.now() - started;
93 if (!res.ok) throw new Error(`Jev answered ${res.status}: ${(await res.text()).slice(0, 500)}`);
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.Compare94 return verdictOf((await res.json()) as SystemOneAnswer, ms);
97/** A System One answer to systemOneBody's questions, as a Verdict. */
98export function verdictOf(out: SystemOneAnswer, ms: number): Verdict {
autosettle189Jev auto-settle prototype, step 1 (#19): scripts/autosettle asks Jev to pick keep yours, theirs, both, or needs an agent for each marker block, and scores it against past settles. Local scripts only; reads JEV_API_KEY, never prints it.Compare99 const orders = ["settle", "settle_reversed"].map((id) => {
100 const probabilities = Object.fromEntries(PICKS.map((k) => [k, out.answers[id]!.probabilities![k] ?? 0])) as Record<
101 Pick,
102 number
103 >;
104 return { pick: top(probabilities), probabilities, confidence: confidenceOf(probabilities) };
105 });
106 const probabilities = Object.fromEntries(
107 PICKS.map((k) => [k, (orders[0]!.probabilities[k] + orders[1]!.probabilities[k]) / 2]),
108 ) as Record<Pick, number>;
109 return {
110 pick: top(probabilities),
111 probabilities,
112 confidence: confidenceOf(probabilities),
113 orders,
114 signs: Object.fromEntries(Object.keys(SIGNS).map((id) => [id, out.answers[id]?.noul ?? Number.NaN])),
115 model: out.model,
116 ms,
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.Compare117 inputTokens: out.usage?.input_tokens ?? 0,
autosettle189Jev auto-settle prototype, step 1 (#19): scripts/autosettle asks Jev to pick keep yours, theirs, both, or needs an agent for each marker block, and scores it against past settles. Local scripts only; reads JEV_API_KEY, never prints it.Compare118 };
121/** Dollars for one call: Jev charges $0.042 per million input tokens, output free (docs.typesafe.ai/models). */
122export const dollars = (inputTokens: number): number => (inputTokens * 0.042) / 1e6;