Versions 91 to 318
new file, 441 lines
1+// A first opinion on a held push (#19), shared by the open server and the platform: for each collision, which of abso's
3+// Off unless AUTOSETTLE is "on" (advice) or "act" (the client settles) and the Worker has an AI binding. The model
5+
7+
12+
29+
36+ * rule: code decided without the model. turned down: the model's pick would break the file. unsure: the model
44+
46+ * The heading a client puts over what it settled by itself, in the message of the push that follows (abso-core 19,
47+ * 23). One line per file under it: `- <file>: kept <side>, confidence 0.81. <reason>` or `…, by a check in code. …`.
50+
56+ { readonly pick: string; readonly by: string; readonly confidence: number; readonly reason: string },
66+
67+/** What a push's message says its abso settled by itself, by file; empty for a push that settled by hand. */
74+ const m = /^- (.+): kept (yours|theirs|both), (?:by a check in code|confidence ([01]\.\d\d))\. ?(.*)$/.exec(line);
85+
89+
90+const solid = (lines: readonly string[]) => lines.map((l) => l.trim()).filter((l) => /[A-Za-z0-9]/.test(l));
91+
96+ if (yours.join("\n") === theirs.join("\n")) return { pick: "theirs", reason: "both sides wrote the same lines" };
103+
110+ return `keeping both would repeat ${twice.length === 1 ? "a line" : `${twice.length} lines`}: ${twice[0]}`;
118+ // Two versions of one statement, such as an import from the same module with a different list of names:
120+ const names = (lines: readonly string[]) => new Set(lines.join(" ").match(/[A-Za-z_$][\w$]{2,}/g) ?? []);
129+
131+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.
133+- "yours": keep YOURS only. YOURS already does what THEIRS meant, or THEIRS is wrong or out of date.
134+- "theirs": keep THEIRS only. THEIRS already does what YOURS meant, or YOURS is wrong or out of date.
135+- "both": keep both unchanged, YOURS then THEIRS. They add separate things that work side by side, with nothing duplicated or contradictory.
136+- "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.
137+Give "confidence" from 0 to 1: how likely your pick is the correct settle. Give "reason" as one plain sentence. Do not write code.`;
138+
139+const block = (lines: readonly string[]) => (lines.length === 0 ? "(no lines)" : lines.join("\n"));
140+
164+
174+
175+/** The model's pick: several samples at once, the confidence being the share that agree with the most common pick. */
180+): Promise<{ pick: Pick; confidence: number; reason: string; selfReported: number[]; usage: unknown }> {
193+ const answer = (typeof out.response === "string" ? JSON.parse(out.response) : out.response) as {
198+ if (!(PICKS as readonly string[]).includes(answer?.pick)) throw new Error(`not a settle choice: ${answer?.pick}`);
202+ const votes = Object.fromEntries(PICKS.map((p) => [p, answers.filter((a) => a.pick === p).length])) as Record<
216+
217+const text = (lines: readonly string[]): string => (lines.length === 0 ? "(no lines)" : lines.join("\n"));
218+
224+ before_either_change: h.base.length === 0 && h.before.length === 0 ? "(not given)" : text(h.base),
229+ their_push: { agent: h.theirAgent ?? "the other agent", message: h.theirMessage ?? "(no message)" },
233+
236+ "`yours` is what the held agent wrote, for the reason in `your_push`; `theirs` was pushed first, for the reason in `their_push`. " +
239+
241+ yours: "Keep `yours` only: `yours` already does what `theirs` meant, or `theirs` is wrong or out of date.",
242+ theirs: "Keep `theirs` only: `theirs` already does what `yours` meant, or `yours` is wrong or out of date.",
243+ both: "Keep both unchanged, `yours` then `theirs`: they add separate things that work side by side, and nothing is duplicated or contradicts.",
245+ "Neither side alone and not both unchanged: 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.",
247+
253+
261+ "If `yours` were placed directly above `theirs`, unchanged, would the file still be correct code with nothing defined twice?",
263+
265+ * A System One request (TypeSafe's Jev and Cloudflare's Clef both take it): the choice in two option orders, since
275+ ...Object.fromEntries(Object.entries(SIGNS).map(([id, q]) => [id, { type: "noul", instructions: q }])),
279+
280+/** Choice confidence: how far the top probability sits above an even split, 0 to 1 (TypeSafe's formula). */
286+
292+): Promise<{ pick: Pick; confidence: number; reason: string; probabilities: Record<Pick, number> }> {
293+ const out = (await ai.run(model === "clef-flash" ? "@cf/cloudflare/clef-flash" : "@cf/cloudflare/clef", {
312+ reason: `Clef's probabilities: ${PICKS.map((k) => `${words[k]} ${probabilities[k].toFixed(2)}`).join(", ")}`,
315+
325+ // Clef unless a text model is named: on project abso's 33 past holds it settled nothing wrong at 0.5 or more,
352+ : { pick: m.pick, confidence: m.confidence, reason: m.reason, by: "model", model, ms: Date.now() - started };
354+
361+ readonly theirs: { readonly agent: string; readonly message: string; readonly text: string; readonly file?: string };
363+
365+ * Advice for each lines collision of a held push, in the order of `collisions`; null where it doesn't apply
366+ * (another kind, already in the agent's file) or the model failed. Collisions don't carry the lines both
375+ const lines = (text: string) => (text === "" ? [] : text.replace(/\r?\n$/, "").split(/\r?\n/));
403+
404+/** The switch as a Worker's env carries it: AUTOSETTLE "on" advises, "act" also has the client settle; else off. */
411+
413+ * The one hook for a server (#19): a publish answer with the first opinion added when the push was held and the
414+ * switch is on, or the answer as it was. Under "act" it also says `settle: true`, and the client settles the
- MCP
- compare on this site's /mcp
- CLI
- abso diff 91 318 worker/project/autosettle.ts --json
- JSON
- /christopher/abso-core/compare/91..318?file=worker%2Fproject%2Fautosettle.ts&format=json