{"version":196,"agent":"autosettle","message":"Auto-settle (#19), step 3 behind a switch: the open server gives a held push a first opinion. With AUTOSETTLE=on and an AI binding (both off unless set), a held push's answer carries advice for each lines collision: keep yours, theirs or both, or needs an agent, with how many of 5 Workers AI samples agree and one line why. Checks in code run first and after (server/src/autosettle.ts), and the scripts now use the same ones. The client prints the advice under the collisions; the agent still settles. A model that fails leaves no advice and never fails the push's answer. server/test/autosettle.test.ts covers it with a stand-in for Workers AI.","time":1792021901137,"timeIso":"2026-10-14T23:51:41.137Z","changes":11,"change":3315,"files":["client/src/api-answers.ts","client/src/publish-commands.ts","scripts/autosettle/rules.ts","server/src/autosettle.ts","server/src/env.ts","server/src/router.ts","server/test/autosettle.test.ts"],"draft":null,"diff":[{"path":"client/src/api-answers.ts","added":15,"removed":1,"diff":"--- a/client/src/api-answers.ts\n+++ b/client/src/api-answers.ts\n@@ -88,7 +88,21 @@\n \t  }\n \t/** With the merge queue on (#39): queued, not landed yet; `ahead` publishes wait in front of it. */\n \t| { ok: true; queued: number; position: number; ahead: number; changes: number; settled?: readonly Settled[] }\n-\t| { ok: false; collisions: readonly Collision[]; reason?: string };\n+\t| { ok: false; collisions: readonly Collision[]; reason?: string; advice?: readonly (Advice | null)[] };\n+/**\n+ * A server's first opinion on one collision of a held push (#19), when it runs AUTOSETTLE: which settle fits,\n+ * how sure, and why. `by`: rule (code decided), model (Workers AI), or turned down (the model's pick would break\n+ * the file, so an agent settles).\n+ */\n+export interface Advice {\n+\treadonly pick: \"yours\" | \"theirs\" | \"both\" | \"agent\";\n+\treadonly confidence: number;\n+\treadonly reason: string;\n+\treadonly by: \"rule\" | \"model\" | \"turned down\";\n+\treadonly modelPick?: string;\n+\treadonly model?: string;\n+\treadonly ms: number;\n+}\n /** A note on lines (#44): where its lines are now, or null when they're all gone. */\n export interface NoteAnswer {\n \treadonly id: number;"},{"path":"client/src/publish-commands.ts","added":26,"removed":2,"diff":"--- a/client/src/publish-commands.ts\n+++ b/client/src/publish-commands.ts\n@@ -2,7 +2,7 @@\n \n import { existsSync, readFileSync } from \"node:fs\";\n import { join } from \"node:path\";\n-import { type Api, ApiError, type Collision, type Settled } from \"./api.ts\";\n+import { type Advice, type Api, ApiError, type Collision, type Settled } from \"./api.ts\";\n import { bool, type Parsed, str, UsageError } from \"./args.ts\";\n import { boxOf, knownPrep, runRun, shellWord } from \"./box-commands.ts\";\n import { collisionsHeading, collisionText, mergedLinesText, mergedText } from \"./collision-text.ts\";\n@@ -458,6 +458,8 @@\n \tconst real = collisions.filter((c) => !isLocalOnly(c.file));\n \tconst twice = real.filter((c) => c.kind === \"duplicate\");\n \tconst newer = real.filter((c) => c.kind !== \"duplicate\");\n+\t// The server's first opinion on each collision (#19), when it runs AUTOSETTLE. Advice only: the agent settles.\n+\tconst advice = answer.advice ?? [];\n \treturn {\n \t\texit: EXIT.refused,\n \t\ttext: [\n@@ -465,6 +467,12 @@\n \t\t\t// A name defined twice is already in your folder (sync listed it); the rest is newer work.\n \t\t\t`Not pushed: ${plural(collisions.length, \"collision\")}${newer.length > 0 ? \" with work pushed since your last pull\" : \"\"}.${answer.reason ? ` (${answer.reason})` : \"\"}`,\n \t\t\t...real.map(collisionText),\n+\t\t\t...(advice.some((a) => a)\n+\t\t\t\t? [\n+\t\t\t\t\t\t\"First opinion (a model on the server, with checks in code; you still settle):\",\n+\t\t\t\t\t\t...collisions.flatMap((c, i) => (advice[i] ? [`  ${c.file}: ${adviceWords(advice[i]!)}`] : [])),\n+\t\t\t\t\t]\n+\t\t\t\t: []),\n \t\t\t...(local.length > 0\n \t\t\t\t? [\n \t\t\t\t\t\t`  ${local.map((c) => c.file).join(\", \")}: local files that should never have been shared. abso pull drops them from your draft and leaves your copy on disk.`,\n@@ -481,10 +489,26 @@\n \t\t\t\t\t? \"Keep one definition of each name defined twice (delete yours, or theirs), then push again.\"\n \t\t\t\t\t: \"Run abso pull, then push again.\",\n \t\t].join(\"\\n\"),\n-\t\tjson: { collisions, recorded: recorded.sent, ...(answer.reason ? { reason: answer.reason } : {}) },\n+\t\tjson: {\n+\t\t\tcollisions,\n+\t\t\trecorded: recorded.sent,\n+\t\t\t...(answer.reason ? { reason: answer.reason } : {}),\n+\t\t\t...(advice.length > 0 ? { advice } : {}),\n+\t\t},\n \t};\n }\n \n+function adviceWords(a: Advice): string {\n+\tconst what = a.pick === \"agent\" ? \"needs an agent\" : `keep ${a.pick}`;\n+\tconst how =\n+\t\ta.by === \"rule\"\n+\t\t\t? \"by a check in code\"\n+\t\t\t: a.by === \"turned down\"\n+\t\t\t\t? `the model said keep ${a.modelPick}, turned down`\n+\t\t\t\t: `${a.confidence.toFixed(2)} of samples agree`;\n+\treturn `${what} (${how}): ${a.reason}`;\n+}\n+\n export async function runSync(args: Parsed, env: Env): Promise<Output> {\n \tconst { root, api } = open(env);\n \tconst recorded = await recordFolder(root, api);"},{"path":"scripts/autosettle/rules.ts","added":2,"removed":44,"diff":"--- a/scripts/autosettle/rules.ts\n+++ b/scripts/autosettle/rules.ts\n@@ -1,45 +1,3 @@\n-// Checks in code around the model's pick (#19). What code can decide, code\n-// decides; what the model picks is turned down when it would plainly break\n-// the file. Both run before anything is settled automatically.\n+// Checks in code around the model's pick (#19): the open server's own, so the scripts score what it runs.\n \n-import type { Hold, Pick } from \"./jev.ts\";\n-\n-const solid = (lines: readonly string[]) => lines.map((l) => l.trim()).filter((l) => /[A-Za-z0-9]/.test(l));\n-\n-/** A pick code can make without the model, with why; undefined when it takes judgment. */\n-export function ruled(h: Hold): { pick: Pick; reason: string } | undefined {\n-\tconst yours = solid(h.yours);\n-\tconst theirs = solid(h.theirs);\n-\tif (yours.join(\"\\n\") === theirs.join(\"\\n\")) return { pick: \"theirs\", reason: \"both sides wrote the same lines\" };\n-\tif (yours.length > 0 && yours.every((l) => theirs.includes(l)))\n-\t\treturn { pick: \"theirs\", reason: \"every line of yours is already in theirs\" };\n-\tif (theirs.length > 0 && theirs.every((l) => yours.includes(l)))\n-\t\treturn { pick: \"yours\", reason: \"every line of theirs is already in yours\" };\n-\treturn undefined;\n-}\n-\n-/** Why a model's pick can't be applied as it is, or undefined when it can. */\n-export function refused(h: Hold, pick: Pick): string | undefined {\n-\tif (pick !== \"both\") return undefined;\n-\tconst theirs = new Set(solid(h.theirs));\n-\tconst twice = solid(h.yours).filter((l) => theirs.has(l));\n-\tif (twice.length > 0)\n-\t\treturn `keeping both would repeat ${twice.length === 1 ? \"a line\" : `${twice.length} lines`}: ${twice[0]}`;\n-\t// The same key or name set on both sides: `timeoutMs:`, `limit =`.\n-\tconst key = (l: string) => /^([A-Za-z_$\"'][\\w$\"'-]*)\\s*[:=]/.exec(l)?.[1];\n-\tconst theirKeys = new Set(solid(h.theirs).map(key).filter(Boolean));\n-\tconst clash = solid(h.yours)\n-\t\t.map(key)\n-\t\t.find((k) => k && theirKeys.has(k));\n-\tif (clash) return `keeping both would set ${clash} twice`;\n-\t// Two versions of one statement, such as an import from the same module with a different list of names:\n-\t// most of the names on one side are on the other too.\n-\tconst names = (lines: readonly string[]) => new Set(lines.join(\" \").match(/[A-Za-z_$][\\w$]{2,}/g) ?? []);\n-\tconst a = names(h.yours);\n-\tconst b = names(h.theirs);\n-\tconst shared = [...a].filter((n) => b.has(n)).length;\n-\tconst share = shared / Math.max(1, Math.min(a.size, b.size));\n-\treturn share >= 0.5\n-\t\t? `keeping both would repeat one statement in two versions (${shared} names on both sides)`\n-\t\t: undefined;\n-}\n+export { refused, ruled } from \"../../server/src/autosettle.ts\";"},{"path":"server/src/autosettle.ts","added":234,"removed":0,"diff":"--- /dev/null\n+++ b/server/src/autosettle.ts\n@@ -0,0 +1,234 @@\n+// A first opinion on a held push (#19): for each collision, which of abso's\n+// settle choices fits, from Workers AI, with checks in code before and after.\n+// Off unless AUTOSETTLE is \"on\" and the Worker has an AI binding. The model\n+// picks one of four words; it never writes code.\n+\n+/** abso's settle choices, plus a hand edit by an agent. */\n+export type Pick = \"yours\" | \"theirs\" | \"both\" | \"agent\";\n+export const PICKS: readonly Pick[] = [\"yours\", \"theirs\", \"both\", \"agent\"];\n+export const MODEL = \"@cf/meta/llama-3.3-70b-instruct-fp8-fast\";\n+\n+/** One collision as the held agent sees it. */\n+export interface Hold {\n+\treadonly file: string;\n+\treadonly base: readonly string[];\n+\treadonly yours: readonly string[];\n+\treadonly theirs: readonly string[];\n+\treadonly before: readonly string[];\n+\treadonly after: readonly string[];\n+\t/** The held push's message: the settler's reason. */\n+\treadonly yourMessage?: string;\n+\treadonly yourAgent?: string;\n+\t/** The push that got there first: its reason. */\n+\treadonly theirMessage?: string;\n+\treadonly theirAgent?: string;\n+\treadonly issue?: string;\n+}\n+\n+export interface Advice {\n+\treadonly pick: Pick;\n+\t/** The share of samples that agree, or 1 for a pick code made. */\n+\treadonly confidence: number;\n+\treadonly reason: string;\n+\t/** rule: code decided without the model. turned down: the model's pick would break the file. */\n+\treadonly by: \"rule\" | \"model\" | \"turned down\";\n+\treadonly modelPick?: Pick;\n+\treadonly model?: string;\n+\treadonly ms: number;\n+}\n+\n+export interface Ai {\n+\trun(model: string, input: unknown): Promise<unknown>;\n+}\n+\n+const solid = (lines: readonly string[]) => lines.map((l) => l.trim()).filter((l) => /[A-Za-z0-9]/.test(l));\n+\n+/** A pick code can make without the model, with why; undefined when it takes judgment. */\n+export function ruled(h: Hold): { pick: Pick; reason: string } | undefined {\n+\tconst yours = solid(h.yours);\n+\tconst theirs = solid(h.theirs);\n+\tif (yours.join(\"\\n\") === theirs.join(\"\\n\")) return { pick: \"theirs\", reason: \"both sides wrote the same lines\" };\n+\tif (yours.length > 0 && yours.every((l) => theirs.includes(l)))\n+\t\treturn { pick: \"theirs\", reason: \"every line of yours is already in theirs\" };\n+\tif (theirs.length > 0 && theirs.every((l) => yours.includes(l)))\n+\t\treturn { pick: \"yours\", reason: \"every line of theirs is already in yours\" };\n+\treturn undefined;\n+}\n+\n+/** Why a model's pick can't be applied as it is, or undefined when it can. */\n+export function refused(h: Hold, pick: Pick): string | undefined {\n+\tif (pick !== \"both\") return undefined;\n+\tconst theirs = new Set(solid(h.theirs));\n+\tconst twice = solid(h.yours).filter((l) => theirs.has(l));\n+\tif (twice.length > 0)\n+\t\treturn `keeping both would repeat ${twice.length === 1 ? \"a line\" : `${twice.length} lines`}: ${twice[0]}`;\n+\t// The same key or name set on both sides: `timeoutMs:`, `limit =`.\n+\tconst key = (l: string) => /^([A-Za-z_$\"'][\\w$\"'-]*)\\s*[:=]/.exec(l)?.[1];\n+\tconst theirKeys = new Set(solid(h.theirs).map(key).filter(Boolean));\n+\tconst clash = solid(h.yours)\n+\t\t.map(key)\n+\t\t.find((k) => k && theirKeys.has(k));\n+\tif (clash) return `keeping both would set ${clash} twice`;\n+\t// Two versions of one statement, such as an import from the same module with a different list of names:\n+\t// most of the names on one side are on the other too.\n+\tconst names = (lines: readonly string[]) => new Set(lines.join(\" \").match(/[A-Za-z_$][\\w$]{2,}/g) ?? []);\n+\tconst a = names(h.yours);\n+\tconst b = names(h.theirs);\n+\tconst shared = [...a].filter((n) => b.has(n)).length;\n+\tconst share = shared / Math.max(1, Math.min(a.size, b.size));\n+\treturn share >= 0.5\n+\t\t? `keeping both would repeat one statement in two versions (${shared} names on both sides)`\n+\t\t: undefined;\n+}\n+\n+const SYSTEM = `You settle merge collisions in a version control system for coding agents.\n+Two agents changed the same lines of one file. Both started from BEFORE. YOURS is what the held agent wrote, for the reason in its push message; THEIRS was pushed first, for the reason in its push message.\n+Pick exactly one:\n+- \"yours\": keep YOURS only. YOURS already does what THEIRS meant, or THEIRS is wrong or out of date.\n+- \"theirs\": keep THEIRS only. THEIRS already does what YOURS meant, or YOURS is wrong or out of date.\n+- \"both\": keep both unchanged, YOURS then THEIRS. They add separate things that work side by side, with nothing duplicated or contradictory.\n+- \"agent\": none of those is correct. The sides change the same thing in different ways (such as two different values for one setting), or keeping both would duplicate or contradict, so a correct result needs a hand edit.\n+Give \"confidence\" from 0 to 1: how likely your pick is the correct settle. Give \"reason\" as one plain sentence. Do not write code.`;\n+\n+const block = (lines: readonly string[]) => (lines.length === 0 ? \"(no lines)\" : lines.join(\"\\n\"));\n+\n+function prompt(h: Hold): string {\n+\treturn [\n+\t\t`FILE: ${h.file}`,\n+\t\t`YOUR PUSH (${h.yourAgent ?? \"you\"}): ${h.yourMessage ?? \"(no message)\"}`,\n+\t\t`THEIR PUSH (${h.theirAgent ?? \"the other agent\"}): ${h.theirMessage ?? \"(no message)\"}`,\n+\t\t...(h.issue ? [`ISSUE: ${h.issue}`] : []),\n+\t\t\"\",\n+\t\t\"LINES ABOVE:\",\n+\t\tblock(h.before),\n+\t\t\"\",\n+\t\t\"BEFORE (what both started from):\",\n+\t\th.base.length === 0 && h.before.length === 0 ? \"(not given)\" : block(h.base),\n+\t\t\"\",\n+\t\t\"YOURS:\",\n+\t\tblock(h.yours),\n+\t\t\"\",\n+\t\t\"THEIRS:\",\n+\t\tblock(h.theirs),\n+\t\t\"\",\n+\t\t\"LINES BELOW:\",\n+\t\tblock(h.after),\n+\t].join(\"\\n\");\n+}\n+\n+const SCHEMA = {\n+\ttype: \"object\",\n+\tproperties: {\n+\t\tpick: { type: \"string\", enum: PICKS },\n+\t\tconfidence: { type: \"number\", minimum: 0, maximum: 1 },\n+\t\treason: { type: \"string\" },\n+\t},\n+\trequired: [\"pick\", \"confidence\", \"reason\"],\n+};\n+\n+/** The model's pick: several samples at once, the confidence being the share that agree with the most common pick. */\n+export async function modelPick(\n+\tai: Ai,\n+\th: Hold,\n+\topts: { model?: string; samples?: number } = {},\n+): Promise<{ pick: Pick; confidence: number; reason: string; selfReported: number[]; usage: unknown }> {\n+\tconst model = opts.model ?? MODEL;\n+\tconst samples = Math.min(9, Math.max(1, opts.samples ?? 5));\n+\tconst one = async () => {\n+\t\tconst out = (await ai.run(model, {\n+\t\t\tmessages: [\n+\t\t\t\t{ role: \"system\", content: SYSTEM },\n+\t\t\t\t{ role: \"user\", content: prompt(h) },\n+\t\t\t],\n+\t\t\tresponse_format: { type: \"json_schema\", json_schema: SCHEMA },\n+\t\t\ttemperature: samples > 1 ? 0.7 : 0,\n+\t\t\tmax_tokens: 200,\n+\t\t})) as { response: unknown; usage?: unknown };\n+\t\tconst answer = (typeof out.response === \"string\" ? JSON.parse(out.response) : out.response) as {\n+\t\t\tpick: string;\n+\t\t\tconfidence: number;\n+\t\t\treason: string;\n+\t\t};\n+\t\tif (!(PICKS as readonly string[]).includes(answer?.pick)) throw new Error(`not a settle choice: ${answer?.pick}`);\n+\t\treturn { ...answer, pick: answer.pick as Pick, usage: out.usage ?? null };\n+\t};\n+\tconst answers = await Promise.all(Array.from({ length: samples }, one));\n+\tconst votes = Object.fromEntries(PICKS.map((p) => [p, answers.filter((a) => a.pick === p).length])) as Record<\n+\t\tPick,\n+\t\tnumber\n+\t>;\n+\tconst pick = PICKS.reduce((a, b) => (votes[b] > votes[a] ? b : a));\n+\tconst first = answers.find((a) => a.pick === pick)!;\n+\treturn {\n+\t\tpick,\n+\t\tconfidence: samples > 1 ? votes[pick] / samples : first.confidence,\n+\t\treason: first.reason,\n+\t\tselfReported: answers.map((a) => a.confidence),\n+\t\tusage: first.usage,\n+\t};\n+}\n+\n+/** Code's rules first, then the model, then code's check on what the model picked. */\n+export async function advise(ai: Ai, h: Hold, opts: { model?: string; samples?: number } = {}): Promise<Advice> {\n+\tconst started = Date.now();\n+\tconst rule = ruled(h);\n+\tif (rule) return { ...rule, confidence: 1, by: \"rule\", ms: 0 };\n+\tconst m = await modelPick(ai, h, opts);\n+\tconst model = opts.model ?? MODEL;\n+\tconst no = refused(h, m.pick);\n+\treturn no\n+\t\t? {\n+\t\t\t\tpick: \"agent\",\n+\t\t\t\tconfidence: m.confidence,\n+\t\t\t\treason: no,\n+\t\t\t\tby: \"turned down\",\n+\t\t\t\tmodelPick: m.pick,\n+\t\t\t\tmodel,\n+\t\t\t\tms: Date.now() - started,\n+\t\t\t}\n+\t\t: { pick: m.pick, confidence: m.confidence, reason: m.reason, by: \"model\", model, ms: Date.now() - started };\n+}\n+\n+interface HeldCollision {\n+\treadonly kind: string;\n+\treadonly file: string;\n+\treadonly untouched?: true;\n+\treadonly marked?: true;\n+\treadonly yours: { readonly lines: [number, number]; readonly text: string };\n+\treadonly theirs: { readonly agent: string; readonly message: string; readonly text: string; readonly file?: string };\n+}\n+\n+/**\n+ * Advice for each lines collision of a held push, in the order of `collisions`; null where it doesn't apply\n+ * (another kind, already in the agent's file) or the model failed. Collisions don't carry the lines both\n+ * started from, so the model goes without them.\n+ */\n+export async function adviseHeld(\n+\tai: Ai,\n+\tcollisions: readonly HeldCollision[],\n+\theld: { agent: string; message: string },\n+): Promise<(Advice | null)[]> {\n+\tconst lines = (text: string) => (text === \"\" ? [] : text.replace(/\\r?\\n$/, \"\").split(/\\r?\\n/));\n+\treturn Promise.all(\n+\t\tcollisions.map(async (c) => {\n+\t\t\tif (c.kind !== \"lines\" || c.untouched || c.marked) return null;\n+\t\t\ttry {\n+\t\t\t\treturn await advise(ai, {\n+\t\t\t\t\tfile: c.file,\n+\t\t\t\t\tbase: [],\n+\t\t\t\t\tyours: lines(c.yours.text),\n+\t\t\t\t\ttheirs: lines(c.theirs.text),\n+\t\t\t\t\tbefore: [],\n+\t\t\t\t\tafter: [],\n+\t\t\t\t\tyourAgent: held.agent,\n+\t\t\t\t\tyourMessage: held.message,\n+\t\t\t\t\ttheirAgent: c.theirs.agent,\n+\t\t\t\t\ttheirMessage: c.theirs.message,\n+\t\t\t\t});\n+\t\t\t} catch (e) {\n+\t\t\t\tconsole.error(`autosettle: ${c.file}: ${e instanceof Error ? e.message : String(e)}`);\n+\t\t\t\treturn null;\n+\t\t\t}\n+\t\t}),\n+\t);\n+}"},{"path":"server/src/env.ts","added":4,"removed":0,"diff":"--- a/server/src/env.ts\n+++ b/server/src/env.ts\n@@ -24,6 +24,10 @@\n \t/** Per-agent keys: \"on\" with KEY_HMAC_SECRET set. */\n \tAGENT_KEYS?: string;\n \tKEY_HMAC_SECRET?: string;\n+\t/** \"on\" gives a held push a first opinion on each collision from Workers AI (#19); needs the AI binding. */\n+\tAUTOSETTLE?: string;\n+\t/** Workers AI, for AUTOSETTLE. Unbound unless wrangler.jsonc names it. */\n+\tAI?: { run(model: string, input: unknown): Promise<unknown> };\n }\n \n /** A secret by its abso name, or its avcs name from before the rename. Empty counts as unset. */"},{"path":"server/src/router.ts","added":10,"removed":0,"diff":"--- a/server/src/router.ts\n+++ b/server/src/router.ts\n@@ -18,6 +18,7 @@\n // ABSO_TOKEN set, the server refuses every call.\n \n import { type Answer, validName } from \"../../worker/project/http.ts\";\n+import { adviseHeld } from \"./autosettle.ts\";\n import { artifactsOf, type Env, secret } from \"./env.ts\";\n import type { IssuesAuth, issuesFetch } from \"./issues-entry.ts\";\n import { isAgentKey, type KeyRole, keyAllows, keysEnabled, timingSame } from \"./keys.ts\";\n@@ -268,6 +269,15 @@\n \t\t\tkeyForCall,\n \t\t\trequest.headers.get(\"Idempotency-Key\") ?? undefined,\n \t\t)) as unknown as Answer;\n+\t\t// A held push gets a first opinion on each collision (#19), when the server is set up for it.\n+\t\tif (op === \"publish\" && env.AUTOSETTLE === \"on\" && env.AI && agent) {\n+\t\t\tconst held = a.body as { ok?: boolean; collisions?: Parameters<typeof adviseHeld>[1] };\n+\t\t\tif (held.ok === false && held.collisions && held.collisions.length > 0) {\n+\t\t\t\tconst message = String((body as { message?: unknown } | undefined)?.message ?? \"\");\n+\t\t\t\tconst advice = await adviseHeld(env.AI, held.collisions, { agent, message });\n+\t\t\t\tif (advice.some((x) => x !== null)) return json(a.status, { ...held, advice });\n+\t\t\t}\n+\t\t}\n \t\treturn json(a.status, a.body);\n \t} catch (e) {\n \t\tconst error = `the project object failed: ${e instanceof Error ? e.message : String(e)}`;"},{"path":"server/test/autosettle.test.ts","added":68,"removed":0,"diff":"--- /dev/null\n+++ b/server/test/autosettle.test.ts\n@@ -0,0 +1,68 @@\n+import assert from \"node:assert/strict\";\n+import { test } from \"node:test\";\n+import { type Ai, adviseHeld, refused, ruled } from \"../src/autosettle.ts\";\n+\n+/** A stand-in for Workers AI that always answers `pick`, and counts its calls. */\n+function fakeAi(pick: string): Ai & { calls: number } {\n+\tconst ai = {\n+\t\tcalls: 0,\n+\t\tasync run() {\n+\t\t\tai.calls++;\n+\t\t\treturn { response: { pick, confidence: 0.9, reason: \"a fixed answer\" }, usage: { prompt_tokens: 10 } };\n+\t\t},\n+\t};\n+\treturn ai;\n+}\n+\n+const held = (yours: string, theirs: string, kind = \"lines\") => ({\n+\tkind,\n+\tfile: \"src/a.ts\",\n+\tyours: { lines: [3, 3] as [number, number], text: yours },\n+\ttheirs: { agent: \"other\", message: \"their reason\", text: theirs },\n+});\n+\n+test(\"code settles when one side's lines are all in the other's, without asking the model\", async () => {\n+\tconst ai = fakeAi(\"both\");\n+\tconst [a] = await adviseHeld(ai, [held(\"\\ttimeoutMs: 30000,\\n\", \"\\ttimeoutMs: 30000,\\n\\tretries: 2,\\n\")], {\n+\t\tagent: \"me\",\n+\t\tmessage: \"my reason\",\n+\t});\n+\tassert.equal(a?.pick, \"theirs\");\n+\tassert.equal(a?.by, \"rule\");\n+\tassert.equal(ai.calls, 0);\n+});\n+\n+test(\"a keep-both that sets one key twice, or holds one import in two versions, goes to an agent\", () => {\n+\tconst hold = (yours: string[], theirs: string[]) => ({ file: \"a\", base: [], yours, theirs, before: [], after: [] });\n+\tassert.match(refused(hold([\"\\tmaxNesting: 64,\"], [\"\\tmaxNesting: 1000,\"]), \"both\") ?? \"\", /maxNesting twice/);\n+\tassert.match(\n+\t\trefused(hold(['import { a, b, c } from \"./x.ts\";'], ['import { a, b, d } from \"./x.ts\";']), \"both\") ?? \"\",\n+\t\t/one statement in two versions/,\n+\t);\n+\tassert.equal(refused(hold(['\\t\"/blame\": blame,'], ['\\t\"/search\": search,']), \"both\"), undefined);\n+\tassert.equal(ruled(hold(['\\t\"/blame\": blame,'], ['\\t\"/search\": search,'])), undefined);\n+});\n+\n+test(\"the model's pick comes back with how many samples agree, and other kinds get no advice\", async () => {\n+\tconst ai = fakeAi(\"both\");\n+\tconst advice = await adviseHeld(\n+\t\tai,\n+\t\t[held('\\t\"/blame\": blame,\\n', '\\t\"/search\": search,\\n'), held(\"x\", \"y\", \"definition\")],\n+\t\t{ agent: \"me\", message: \"my reason\" },\n+\t);\n+\tassert.equal(advice[0]?.pick, \"both\");\n+\tassert.equal(advice[0]?.by, \"model\");\n+\tassert.equal(advice[0]?.confidence, 1);\n+\tassert.equal(advice[1], null);\n+\tassert.equal(ai.calls, 5);\n+});\n+\n+test(\"a model that fails leaves no advice instead of failing the push's answer\", async () => {\n+\tconst ai: Ai = {\n+\t\tasync run() {\n+\t\t\tthrow new Error(\"Workers AI is down\");\n+\t\t},\n+\t};\n+\tconst [a] = await adviseHeld(ai, [held(\"a = 1\", \"b = 2\")], { agent: \"me\", message: \"m\" });\n+\tassert.equal(a, null);\n+});"}],"ci":null}