--- a/scripts/autosettle/rules.ts
+++ b/scripts/autosettle/rules.ts
@@ -1,45 +1,3 @@
1−// Checks in code around the model's pick (#19). What code can decide, code
2−// decides; what the model picks is turned down when it would plainly break
3−// the file. Both run before anything is settled automatically.
1+// Checks in code around the model's pick (#19): the open server's own, so the scripts score what it runs. 5−import type { Hold, Pick } from "./jev.ts";
6−
7−const solid = (lines: readonly string[]) => lines.map((l) => l.trim()).filter((l) => /[A-Za-z0-9]/.test(l));
8−
9−/** A pick code can make without the model, with why; undefined when it takes judgment. */
10−export function ruled(h: Hold): { pick: Pick; reason: string } | undefined {
11− const yours = solid(h.yours);
12− const theirs = solid(h.theirs);
13− if (yours.join("\n") === theirs.join("\n")) return { pick: "theirs", reason: "both sides wrote the same lines" };
14− if (yours.length > 0 && yours.every((l) => theirs.includes(l)))
15− return { pick: "theirs", reason: "every line of yours is already in theirs" };
16− if (theirs.length > 0 && theirs.every((l) => yours.includes(l)))
17− return { pick: "yours", reason: "every line of theirs is already in yours" };
18− return undefined;
19−}
20−
21−/** Why a model's pick can't be applied as it is, or undefined when it can. */
22−export function refused(h: Hold, pick: Pick): string | undefined {
23− if (pick !== "both") return undefined;
24− const theirs = new Set(solid(h.theirs));
25− const twice = solid(h.yours).filter((l) => theirs.has(l));
26− if (twice.length > 0)
27− return `keeping both would repeat ${twice.length === 1 ? "a line" : `${twice.length} lines`}: ${twice[0]}`;
28− // The same key or name set on both sides: `timeoutMs:`, `limit =`.
29− const key = (l: string) => /^([A-Za-z_$"'][\w$"'-]*)\s*[:=]/.exec(l)?.[1];
30− const theirKeys = new Set(solid(h.theirs).map(key).filter(Boolean));
31− const clash = solid(h.yours)
32− .map(key)
33− .find((k) => k && theirKeys.has(k));
34− if (clash) return `keeping both would set ${clash} twice`;
35− // Two versions of one statement, such as an import from the same module with a different list of names:
36− // most of the names on one side are on the other too.
37− const names = (lines: readonly string[]) => new Set(lines.join(" ").match(/[A-Za-z_$][\w$]{2,}/g) ?? []);
38− const a = names(h.yours);
39− const b = names(h.theirs);
40− const shared = [...a].filter((n) => b.has(n)).length;
41− const share = shared / Math.max(1, Math.min(a.size, b.size));
42− return share >= 0.5
43− ? `keeping both would repeat one statement in two versions (${shared} names on both sides)`
44− : undefined;
45−}
3+export { refused, ruled } from "../../server/src/autosettle.ts";