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/settle-one.ts?version=192&format=json
92 linesautosettle 100%Last change autosettle in version 191, 2 versions changed it

You're reading version 192. The newest is 318, and 1 version since then changed this file. Go to the newestCompare with 318

1// Ask a model how to settle each marker block in one file (#19), the way abso
2// pull leaves a held push's file. Prints its pick; changes nothing.
3//
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]
5//
6// --via workers-ai (the default) needs workers-ai/ running under wrangler dev; --via jev needs JEV_API_KEY.
7
8import { readFileSync } from "node:fs";
9import { findBlocks } from "../../client/src/settle.ts";
10import { ask, dollars, type Hold, PICKS } from "./jev.ts";
11import { askWorkersAi } from "./workers-ai.ts";
13const CONTEXT = 15;
14const CLOSE = /^>>>>>>> theirs: (.*?), version (\d+) "(.*)"$/;
16/** Each marker block in a file's text as a Hold. */
17export function holdsIn(
18 text: string,
19 file: string,
20 extra: { yourMessage?: string; yourAgent?: string; issue?: string } = {},
21): Hold[] {
22 const lines = text.split(/\r?\n/);
23 return findBlocks(lines).map((b) => {
24 const close = CLOSE.exec(lines[b.end]!);
25 return {
26 file,
27 base: b.base,
28 yours: b.yours,
29 theirs: b.theirs,
30 before: lines.slice(Math.max(0, b.start - CONTEXT), b.start),
31 after: lines.slice(b.end + 1, b.end + 1 + CONTEXT),
32 ...(close ? { theirAgent: close[1], theirMessage: close[3] } : {}),
33 ...extra,
34 };
35 });
38function flag(args: string[], name: string): string | undefined {
39 const i = args.indexOf(name);
40 return i === -1 ? undefined : args[i + 1];
43async function main(): Promise<void> {
44 const args = process.argv.slice(2);
45 const path = args[0];
46 if (!path || path.startsWith("--")) {
47 console.error(
48 'usage: node scripts/autosettle/settle-one.ts <file> [--message "..."] [--issue "..."] [--name <path>] [--json]',
49 );
50 process.exit(2);
51 }
52 const holds = holdsIn(readFileSync(path, "utf8"), flag(args, "--name") ?? path, {
53 ...(flag(args, "--message") ? { yourMessage: flag(args, "--message") } : {}),
54 ...(flag(args, "--issue") ? { issue: flag(args, "--issue") } : {}),
55 });
56 if (holds.length === 0) {
57 console.error(`${path} has no marker blocks.`);
58 process.exit(1);
59 }
60 const results = [];
61 const model = flag(args, "--model") ? { model: flag(args, "--model")! } : {};
62 for (const [i, h] of holds.entries()) {
63 if (flag(args, "--via") !== "jev") {
64 const w = await askWorkersAi(h, model);
65 results.push({ block: i + 1, ...w });
66 if (!args.includes("--json"))
67 console.log(
68 `Block ${i + 1} of ${holds.length} in ${h.file}: ${w.pick}, confidence ${w.confidence.toFixed(2)}\n ${w.reason}\n ${w.model}, ${w.ms.toFixed(0)} ms (model ${w.modelMs} ms), ${w.inputTokens} input tokens`,
69 );
70 continue;
71 }
72 const v = await ask(h, model);
73 results.push({ block: i + 1, ...v });
74 if (args.includes("--json")) continue;
75 const pct = (x: number) => `${(x * 100).toFixed(0)}%`;
76 console.log(`Block ${i + 1} of ${holds.length} in ${h.file}: ${v.pick}, confidence ${v.confidence.toFixed(2)}`);
77 console.log(` probabilities: ${PICKS.map((k) => `${k} ${pct(v.probabilities[k])}`).join(", ")}`);
78 console.log(
79 ` each order: ${v.orders.map((o) => `${o.pick} ${o.confidence.toFixed(2)}`).join(" / ")}; side questions: ${Object.entries(
80 v.signs,
81 )
82 .map(([k, p]) => `${k} ${pct(p)}`)
83 .join(", ")}`,
84 );
85 console.log(
86 ` ${v.model}, ${v.ms.toFixed(0)} ms, ${v.inputTokens} input tokens ($${dollars(v.inputTokens).toFixed(6)})`,
87 );
88 }
89 if (args.includes("--json")) console.log(JSON.stringify(results, null, "\t"));
92if (process.argv[1]?.endsWith("settle-one.ts")) await main();