{"file":"client/src/settle.ts","version":318,"total":121,"from":1,"to":121,"lines":[{"n":1,"text":"// abso settle <file...> --yours | --theirs | --both: settle a file's","atom":"a0","author":"init","version":0},{"n":2,"text":"// collisions by rewriting the marker blocks a sync wrote into it (#11, round","atom":"a0","author":"init","version":0},{"n":3,"text":"// 1). A block is exactly four marker lines, in this order, as the engine","atom":"a0","author":"init","version":0},{"n":4,"text":"// writes them:","atom":"a0","author":"init","version":0},{"n":5,"text":"//","atom":"a0","author":"init","version":0},{"n":6,"text":"//   <<<<<<< yours (unpublished)","atom":"a0","author":"init","version":0},{"n":7,"text":"//   ...yours","atom":"a0","author":"init","version":0},{"n":8,"text":"//   ||||||| before (version N)","atom":"a0","author":"init","version":0},{"n":9,"text":"//   ...the lines both started from","atom":"a0","author":"init","version":0},{"n":10,"text":"//   =======","atom":"a0","author":"init","version":0},{"n":11,"text":"//   ...theirs","atom":"a0","author":"init","version":0},{"n":12,"text":"//   >>>>>>> theirs: <agent>, version N \"<message>\"","atom":"a0","author":"init","version":0},{"n":13,"text":"//","atom":"a0","author":"init","version":0},{"n":14,"text":"// Anything else that merely starts with <<<<<<< (a doc about git, a test","atom":"a0","author":"init","version":0},{"n":15,"text":"// fixture) is not a block and is left alone. The server works out at publish","atom":"a0","author":"init","version":0},{"n":16,"text":"// which side survived, and tells the other author.","atom":"a0","author":"init","version":0},{"n":17,"text":"","atom":"a0","author":"init","version":0},{"n":18,"text":"import { readFileSync } from \"node:fs\";","atom":"a0","author":"init","version":0},{"n":19,"text":"import { UsageError } from \"./args.ts\";","atom":"a0","author":"init","version":0},{"n":20,"text":"","atom":"a0","author":"init","version":0},{"n":21,"text":"export type Keep = \"yours\" | \"theirs\" | \"both\";","atom":"a0","author":"init","version":0},{"n":22,"text":"","atom":"a0","author":"init","version":0},{"n":23,"text":"const OPEN = \"<<<<<<< yours (unpublished)\";","atom":"a0","author":"init","version":0},{"n":24,"text":"const BASE = /^\\|\\|\\|\\|\\|\\|\\| before \\(version \\d+\\)$/;","atom":"a0","author":"init","version":0},{"n":25,"text":"const MID = \"=======\";","atom":"a0","author":"init","version":0},{"n":26,"text":"const CLOSE = /^>>>>>>> theirs: /;","atom":"a0","author":"init","version":0},{"n":27,"text":"","atom":"a0","author":"init","version":0},{"n":28,"text":"export interface Block {","atom":"a0","author":"init","version":0},{"n":29,"text":"\t/** 0-based index of the opening marker line. */","atom":"a0","author":"init","version":0},{"n":30,"text":"\treadonly start: number;","atom":"a0","author":"init","version":0},{"n":31,"text":"\t/** 0-based index of the closing marker line. */","atom":"a0","author":"init","version":0},{"n":32,"text":"\treadonly end: number;","atom":"a0","author":"init","version":0},{"n":33,"text":"\treadonly yours: readonly string[];","atom":"a0","author":"init","version":0},{"n":34,"text":"\treadonly base: readonly string[];","atom":"a0","author":"init","version":0},{"n":35,"text":"\treadonly theirs: readonly string[];","atom":"a0","author":"init","version":0},{"n":36,"text":"}","atom":"a0","author":"init","version":0},{"n":37,"text":"","atom":"a0","author":"init","version":0},{"n":38,"text":"/** The marker blocks in a file's lines. A run of lines that doesn't follow the four markers in order is not a block. */","atom":"a0","author":"init","version":0},{"n":39,"text":"export function findBlocks(lines: readonly string[]): Block[] {","atom":"a0","author":"init","version":0},{"n":40,"text":"\tconst out: Block[] = [];","atom":"a0","author":"init","version":0},{"n":41,"text":"\tfor (let i = 0; i < lines.length; i++) {","atom":"a0","author":"init","version":0},{"n":42,"text":"\t\tif (lines[i] !== OPEN) continue;","atom":"a0","author":"init","version":0},{"n":43,"text":"\t\tlet base = -1;","atom":"a0","author":"init","version":0},{"n":44,"text":"\t\tlet mid = -1;","atom":"a0","author":"init","version":0},{"n":45,"text":"\t\tlet end = -1;","atom":"a0","author":"init","version":0},{"n":46,"text":"\t\tfor (let j = i + 1; j < lines.length; j++) {","atom":"a0","author":"init","version":0},{"n":47,"text":"\t\t\tconst l = lines[j]!;","atom":"a0","author":"init","version":0},{"n":48,"text":"\t\t\tif (l === OPEN) break;","atom":"a0","author":"init","version":0},{"n":49,"text":"\t\t\tif (base === -1 && BASE.test(l)) base = j;","atom":"a0","author":"init","version":0},{"n":50,"text":"\t\t\telse if (base !== -1 && mid === -1 && l === MID) mid = j;","atom":"a0","author":"init","version":0},{"n":51,"text":"\t\t\telse if (mid !== -1 && CLOSE.test(l)) {","atom":"a0","author":"init","version":0},{"n":52,"text":"\t\t\t\tend = j;","atom":"a0","author":"init","version":0},{"n":53,"text":"\t\t\t\tbreak;","atom":"a0","author":"init","version":0},{"n":54,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":55,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":56,"text":"\t\tif (end === -1) continue;","atom":"a0","author":"init","version":0},{"n":57,"text":"\t\tout.push({","atom":"a0","author":"init","version":0},{"n":58,"text":"\t\t\tstart: i,","atom":"a0","author":"init","version":0},{"n":59,"text":"\t\t\tend,","atom":"a0","author":"init","version":0},{"n":60,"text":"\t\t\tyours: lines.slice(i + 1, base),","atom":"a0","author":"init","version":0},{"n":61,"text":"\t\t\tbase: lines.slice(base + 1, mid),","atom":"a0","author":"init","version":0},{"n":62,"text":"\t\t\ttheirs: lines.slice(mid + 1, end),","atom":"a0","author":"init","version":0},{"n":63,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":64,"text":"\t\ti = end;","atom":"a0","author":"init","version":0},{"n":65,"text":"\t}","atom":"a0","author":"init","version":0},{"n":66,"text":"\treturn out;","atom":"a0","author":"init","version":0},{"n":67,"text":"}","atom":"a0","author":"init","version":0},{"n":68,"text":"","atom":"a0","author":"init","version":0},{"n":69,"text":"/** The text with each block replaced by the side kept (both: yours, then theirs), keeping the file's line endings. */","atom":"a0","author":"init","version":0},{"n":70,"text":"export function settleText(text: string, keep: Keep): { text: string; blocks: number } {","atom":"a0","author":"init","version":0},{"n":71,"text":"\tconst eol = text.includes(\"\\r\\n\") ? \"\\r\\n\" : \"\\n\";","atom":"a0","author":"init","version":0},{"n":72,"text":"\tconst lines = text.split(/\\r?\\n/);","atom":"a0","author":"init","version":0},{"n":73,"text":"\tconst blocks = findBlocks(lines);","atom":"a0","author":"init","version":0},{"n":74,"text":"\tif (blocks.length === 0) return { text, blocks: 0 };","atom":"a0","author":"init","version":0},{"n":75,"text":"\tconst out: string[] = [];","atom":"a0","author":"init","version":0},{"n":76,"text":"\tlet at = 0;","atom":"a0","author":"init","version":0},{"n":77,"text":"\tfor (const b of blocks) {","atom":"a0","author":"init","version":0},{"n":78,"text":"\t\tout.push(...lines.slice(at, b.start));","atom":"a0","author":"init","version":0},{"n":79,"text":"\t\tif (keep !== \"theirs\") out.push(...b.yours);","atom":"a0","author":"init","version":0},{"n":80,"text":"\t\tif (keep !== \"yours\") out.push(...b.theirs);","atom":"a0","author":"init","version":0},{"n":81,"text":"\t\tat = b.end + 1;","atom":"a0","author":"init","version":0},{"n":82,"text":"\t}","atom":"a0","author":"init","version":0},{"n":83,"text":"\tout.push(...lines.slice(at));","atom":"a0","author":"init","version":0},{"n":84,"text":"\treturn { text: out.join(eol), blocks: blocks.length };","atom":"a0","author":"init","version":0},{"n":85,"text":"}","atom":"a0","author":"init","version":0},{"n":86,"text":"","atom":"a0","author":"init","version":0},{"n":87,"text":"/** Which side the flags name: exactly one of --yours, --theirs, --both. */","atom":"a0","author":"init","version":0},{"n":88,"text":"export function keepFrom(flags: { yours: boolean; theirs: boolean; both: boolean }): Keep {","atom":"a0","author":"init","version":0},{"n":89,"text":"\tconst picked = ([\"yours\", \"theirs\", \"both\"] as const).filter((k) => flags[k]);","atom":"a0","author":"init","version":0},{"n":90,"text":"\tif (picked.length !== 1)","atom":"a0","author":"init","version":0},{"n":91,"text":"\t\tthrow new UsageError(\"say which side to keep, once: abso settle <file...> --yours, --theirs or --both\");","atom":"a0","author":"init","version":0},{"n":92,"text":"\treturn picked[0]!;","atom":"a0","author":"init","version":0},{"n":93,"text":"}","atom":"a0","author":"init","version":0},{"n":94,"text":"","atom":"a0","author":"init","version":0},{"n":95,"text":"/** How many blocks a file on disk holds (0 when it can't be read as text). */","atom":"a0","author":"init","version":0},{"n":96,"text":"export function blocksIn(path: string): number {","atom":"a0","author":"init","version":0},{"n":97,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":98,"text":"\t\treturn findBlocks(readFileSync(path, \"utf8\").split(/\\r?\\n/)).length;","atom":"a0","author":"init","version":0},{"n":99,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":100,"text":"\t\treturn 0;","atom":"a0","author":"init","version":0},{"n":101,"text":"\t}","atom":"a0","author":"init","version":0},{"n":102,"text":"}","atom":"a0","author":"init","version":0},{"n":103,"text":"","atom":"a53","author":"review","version":12},{"n":104,"text":"/**","atom":"a53","author":"review","version":12},{"n":105,"text":" * The first line (1-based) of what looks like a git conflict left in a text: a \"<<<<<<< \" line, then a \"=======\" line,","atom":"a53","author":"review","version":12},{"n":106,"text":" * then a \">>>>>>> \" line. abso's own blocks are not these (their opening line is exact, and `abso settle` finds them);","atom":"a53","author":"review","version":12},{"n":107,"text":" * a merge done by git, or markers typed or pasted by hand, are plain text to abso, which would publish them as they are.","atom":"a53","author":"review","version":12},{"n":108,"text":" */","atom":"a53","author":"review","version":12},{"n":109,"text":"export function gitMarkerLine(text: string): number | undefined {","atom":"a53","author":"review","version":12},{"n":110,"text":"\tconst lines = text.split(/\\r?\\n/);","atom":"a53","author":"review","version":12},{"n":111,"text":"\tfor (let i = 0; i < lines.length; i++) {","atom":"a53","author":"review","version":12},{"n":112,"text":"\t\tif (!lines[i]!.startsWith(\"<<<<<<< \") || lines[i] === OPEN) continue;","atom":"a53","author":"review","version":12},{"n":113,"text":"\t\tlet mid = false;","atom":"a53","author":"review","version":12},{"n":114,"text":"\t\tfor (let j = i + 1; j < lines.length; j++) {","atom":"a53","author":"review","version":12},{"n":115,"text":"\t\t\tif (lines[j]!.startsWith(\"<<<<<<< \")) break;","atom":"a53","author":"review","version":12},{"n":116,"text":"\t\t\tif (lines[j] === MID) mid = true;","atom":"a53","author":"review","version":12},{"n":117,"text":"\t\t\telse if (mid && lines[j]!.startsWith(\">>>>>>> \")) return i + 1;","atom":"a53","author":"review","version":12},{"n":118,"text":"\t\t}","atom":"a53","author":"review","version":12},{"n":119,"text":"\t}","atom":"a53","author":"review","version":12},{"n":120,"text":"\treturn undefined;","atom":"a53","author":"review","version":12},{"n":121,"text":"}","atom":"a53","author":"review","version":12}],"atoms":[{"atom":"a0","author":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z","publish":{"draft":null,"version":0,"agent":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z"}},{"atom":"a53","author":"review","message":"","time":1791514003159,"timeIso":"2026-10-09T02:46:43.159Z","publish":{"draft":null,"version":12,"agent":"review","message":"record and publish note two things git users know the hard way, without blocking. (1) A file that holds what looks like a git conflict (a '<<<<<<< ' line, a '=======' line, then a '>>>>>>> ' line, other than abso's own blocks) gets: 'Note: <file> has lines that look like a git conflict (from line N)...'. (2) A sent path of 160+ characters inside the folder, or 240+ with the folder's location, gets a note that Windows stops at 260. Both are one line per file, only when the file is sent, and the JSON carries gitMarkers and longPaths. gitMarkerLine is in settle.ts, longPathsOf in commands.ts. Tests: three new ones; the whole suite passes (702) and biome ci is clean.","time":1791514010730,"timeIso":"2026-10-09T02:46:50.730Z"}}]}