{"draft":null,"from":188,"to":189,"files":[{"path":"scripts/autosettle/settle-one.ts","added":81,"removed":0,"diff":"--- /dev/null\n+++ b/scripts/autosettle/settle-one.ts\n@@ -0,0 +1,81 @@\n+// Ask Jev how to settle each marker block in one file (#19), the way abso pull\n+// leaves a held push's file. Prints Jev's pick and its probabilities; changes nothing.\n+//\n+//   node scripts/autosettle/settle-one.ts <file> [--message \"<your held push's message>\"] [--issue \"...\"] [--name <path in the project>] [--json]\n+//\n+// Needs JEV_API_KEY in the environment.\n+\n+import { readFileSync } from \"node:fs\";\n+import { findBlocks } from \"../../client/src/settle.ts\";\n+import { ask, dollars, type Hold, PICKS } from \"./jev.ts\";\n+\n+const CONTEXT = 15;\n+const CLOSE = /^>>>>>>> theirs: (.*?), version (\\d+) \"(.*)\"$/;\n+\n+/** Each marker block in a file's text as a Hold. */\n+export function holdsIn(\n+\ttext: string,\n+\tfile: string,\n+\textra: { yourMessage?: string; yourAgent?: string; issue?: string } = {},\n+): Hold[] {\n+\tconst lines = text.split(/\\r?\\n/);\n+\treturn findBlocks(lines).map((b) => {\n+\t\tconst close = CLOSE.exec(lines[b.end]!);\n+\t\treturn {\n+\t\t\tfile,\n+\t\t\tbase: b.base,\n+\t\t\tyours: b.yours,\n+\t\t\ttheirs: b.theirs,\n+\t\t\tbefore: lines.slice(Math.max(0, b.start - CONTEXT), b.start),\n+\t\t\tafter: lines.slice(b.end + 1, b.end + 1 + CONTEXT),\n+\t\t\t...(close ? { theirAgent: close[1], theirMessage: close[3] } : {}),\n+\t\t\t...extra,\n+\t\t};\n+\t});\n+}\n+\n+function flag(args: string[], name: string): string | undefined {\n+\tconst i = args.indexOf(name);\n+\treturn i === -1 ? undefined : args[i + 1];\n+}\n+\n+async function main(): Promise<void> {\n+\tconst args = process.argv.slice(2);\n+\tconst path = args[0];\n+\tif (!path || path.startsWith(\"--\")) {\n+\t\tconsole.error(\n+\t\t\t'usage: node scripts/autosettle/settle-one.ts <file> [--message \"...\"] [--issue \"...\"] [--name <path>] [--json]',\n+\t\t);\n+\t\tprocess.exit(2);\n+\t}\n+\tconst holds = holdsIn(readFileSync(path, \"utf8\"), flag(args, \"--name\") ?? path, {\n+\t\t...(flag(args, \"--message\") ? { yourMessage: flag(args, \"--message\") } : {}),\n+\t\t...(flag(args, \"--issue\") ? { issue: flag(args, \"--issue\") } : {}),\n+\t});\n+\tif (holds.length === 0) {\n+\t\tconsole.error(`${path} has no marker blocks.`);\n+\t\tprocess.exit(1);\n+\t}\n+\tconst results = [];\n+\tfor (const [i, h] of holds.entries()) {\n+\t\tconst v = await ask(h);\n+\t\tresults.push({ block: i + 1, ...v });\n+\t\tif (args.includes(\"--json\")) continue;\n+\t\tconst pct = (x: number) => `${(x * 100).toFixed(0)}%`;\n+\t\tconsole.log(`Block ${i + 1} of ${holds.length} in ${h.file}: ${v.pick}, confidence ${v.confidence.toFixed(2)}`);\n+\t\tconsole.log(`  probabilities: ${PICKS.map((k) => `${k} ${pct(v.probabilities[k])}`).join(\", \")}`);\n+\t\tconsole.log(\n+\t\t\t`  each order: ${v.orders.map((o) => `${o.pick} ${o.confidence.toFixed(2)}`).join(\" / \")}; side questions: ${Object.entries(\n+\t\t\t\tv.signs,\n+\t\t\t)\n+\t\t\t\t.map(([k, p]) => `${k} ${pct(p)}`)\n+\t\t\t\t.join(\", \")}`,\n+\t\t);\n+\t\tconsole.log(\n+\t\t\t`  ${v.model}, ${v.ms.toFixed(0)} ms, ${v.inputTokens} input tokens ($${dollars(v.inputTokens).toFixed(6)})`,\n+\t\t);\n+\t}\n+\tif (args.includes(\"--json\")) console.log(JSON.stringify(results, null, \"\\t\"));\n+}\n+\n+if (process.argv[1]?.endsWith(\"settle-one.ts\")) await main();"}],"unmatched":[]}