Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 7 to 318

Compare

+215 −69 in 25 places
Lines 2–9 at 318 (were 2–8 at 7)
22
33import { existsSync, readFileSync } from "node:fs";
44import { join } from "node:path";
5−import { type Api, ApiError, type Collision, type Settled } from "./api.ts";
5+import { autoTrailer } from "../../worker/project/autosettle.ts";
6+import { type Advice, type Api, ApiError, type Collision, type Settled } from "./api.ts";
67import { bool, type Parsed, str, UsageError } from "./args.ts";
78import { boxOf, knownPrep, runRun, shellWord } from "./box-commands.ts";
89import { collisionsHeading, collisionText, mergedLinesText, mergedText } from "./collision-text.ts";
Lines 13–36 at 318 (were 12–31 at 7)
1213 FOLDER_LOG_LIMIT,
1314 LISTED,
1415 meantBinary,
16+ pullUnfinished,
1517 READER_REFUSES,
1618 recordedFirst,
1719 recordFolder,
1820 syncFolder,
1921 turnedBinaryText,
2022 unwrittenText,
23+ withLeftOut,
2124} from "./commands.ts";
2225import { type Config, isReader } from "./config.ts";
26+import { fromEnv } from "./env-names.ts";
2327import { ignoredHere } from "./fetch.ts";
24−import { absolute, forgetKnown, isLocalOnly, loadIgnore, readText, writeFileAtomic } from "./folder.ts";
25−import { PROJECT_FILE, readProjectFile } from "./project-file.ts";
28+import { absolute, forgetKnown, isLocalOnly, type LeftOut, loadIgnore, readText, writeFileAtomic } from "./folder.ts";
29+import { projectFileName, readProjectFile } from "./project-file.ts";
2630import { pulledText, STILL_QUEUED, standing, WAIT_SECONDS, waitForQueued } from "./queue.ts";
2731import { type Refused, refusedText, unsafePath } from "./safety.ts";
2832import { blocksIn, settleText } from "./settle.ts";
33+import { stateDir } from "./state-dir.ts";
2934
3035/**
3136 * Files new in the draft that this folder's ignore rules leave out. An edit
Lines 66–85 at 318 (were 61–66 at 7)
6166 ];
6267}
6368
69+/**
70+ * After "Pushed version N.": whether CI will check it, where the server says (its `ciWhere`). Nothing for the server's own
71+ * compute, where pushes have always been checked, or for a server that doesn't say.
72+ */
73+export function ciWhereText(where: string | undefined, version: number): string[] {
74+ if (where === "off")
75+ return [
76+ `CI is off for this project, so version ${version} isn't checked. Connect a Cloudflare account in the project's settings on the website to run it there.`,
77+ ];
78+ if (where === "account")
79+ return [`CI checks it in the project's Cloudflare account: abso ci ${version} shows the result.`];
80+ return [];
81+}
6483export async function runPublish(args: Parsed, env: Env): Promise<Output> {
6584 const message = str(args, "message");
6685 if (!message) throw new UsageError('say why with -m "<message>"');
Lines 89–95 at 318 (were 70–76 at 7)
7089 const rawWait = str(args, "wait");
7190 if (rawWait !== undefined && !/^\d{1,4}$/.test(rawWait))
7291 throw new UsageError(
73− `--wait is how many seconds to wait for a queued publish to land, like 100 (got ${JSON.stringify(rawWait)})`,
92+ `--wait is how many seconds to wait for a queued push to land, like 100 (got ${JSON.stringify(rawWait)})`,
7493 );
7594 const waitSeconds = bool(args, "no-wait") ? 0 : rawWait === undefined ? WAIT_SECONDS : Number(rawWait);
7695 let skippedCheck = false;
Lines 105–111 at 318 (were 86–91 at 7)
86105 // --check alone: the build and check in the draft's own avcs.json, as the server's job runs them on
87106 // each version, so a draft that changes them runs the new ones (#39).
88107 const pf = readProjectFile(root);
108+ const PROJECT_FILE = projectFileName(root);
89109 if (pf === null || "error" in pf || pf.file.check === "") {
90110 const why =
91111 pf === null ? `there is no ${PROJECT_FILE}` : "error" in pf ? pf.error : `${PROJECT_FILE} has no "check"`;
Lines 116–175 at 318 (were 96–155 at 7)
96116 check = pf.file.build === "" ? pf.file.check : `${pf.file.build} && ${pf.file.check}`;
97117 }
98118 if (check !== undefined) {
99− // Your draft on newest shared, as it would land, must pass the check (#37, Builder 1):
119+ // Your draft on newest shared, as it would land, must pass the check (#37):
100120 // two changes that each passed alone turned shared red twice. Sync first, then run it in the box.
101121 const say = env.writeErr ?? env.write;
102− // Known to have no prep: refuse before syncing and running (#37, Artist 1). Unknown: the run below tells.
122+ // Known to have no prep: refuse before syncing and running (#37). Unknown: the run below tells.
103123 const noPrep =
104− "your box has no prep, so a check would run without node_modules and its result couldn't be trusted. Run abso prep 'npm ci --ignore-scripts' once (every fresh box then starts from it), then publish --check again.";
124+ "your box has no prep, so a check would run without node_modules and its result couldn't be trusted. Run abso prep 'npm ci --ignore-scripts' once (every fresh box then starts from it), then push --check again.";
105125 if (knownPrep(root, boxOf(args, env)) === null && existsSync(join(root, "package-lock.json"))) {
106126 return {
107127 exit: EXIT.refused,
108− text: `Not published: ${noPrep} (Nothing was run: this folder's last run in that box said it had no prep.)`,
128+ text: `Not pushed: ${noPrep} (Nothing was run: this folder's last run in that box said it had no prep.)`,
109129 json: { check: { command: check, ran: false, prep: null } },
110130 };
111131 }
112132 const synced = await unreached(
113133 runSync({ positionals: [], flags: new Map() }, env),
114− "Nothing was published, and the check didn't run.",
134+ "Nothing was pushed, and the check didn't run.",
115135 );
116136 const sj = synced.json as { collisions?: readonly unknown[]; refused?: readonly Refused[] };
117137 if ((sj.collisions?.length ?? 0) > 0) {
118138 return {
119139 exit: EXIT.refused,
120− text: `${synced.text}\nNot published: the sync before the check left collisions. Settle them, then publish --check again.`,
140+ text: `${synced.text}\nNot pushed: the pull before the check left collisions. Settle them, then push --check again.`,
121141 json: { check: null, sync: synced.json },
122142 };
123143 }
124144 if (synced.text) say(`${synced.text}\n`);
125− // Paths the sync wouldn't write (safety.ts) don't block: the check just ran without them (Cloud).
145+ // Paths the sync wouldn't write (safety.ts) don't block: the check just ran without them.
126146 if ((sj.refused?.length ?? 0) > 0)
127147 say(
128− `avcs: the sync didn't write these: ${sj.refused!.map((r) => r.path).join(", ")}; the check runs without them.\n`,
148+ `abso: the pull didn't write these: ${sj.refused!.map((r) => r.path).join(", ")}; the check runs without them.\n`,
129149 );
130− say(`avcs: checking your draft on newest shared in the box: ${check}\n`);
150+ say(`abso: checking your draft on newest shared in the box: ${check}\n`);
131151 const flags = new Map<string, string | boolean>();
132152 const box = str(args, "box");
133153 if (box !== undefined) flags.set("box", box);
134154 const ran = await runRun({ positionals: [check], flags }, { ...env, runKind: "publish-check" });
135155 // No prep and a package-lock: the box had no node_modules, so the check can't be trusted either way
136− // (#37, Builder 1: npx tsc fetched an unrelated, deprecated tsc package).
156+ // (#37: npx tsc fetched an unrelated, deprecated tsc package).
137157 if ((ran.json as { prep?: string | null }).prep === null && existsSync(join(root, "package-lock.json"))) {
138158 return {
139159 exit: EXIT.refused,
140− text: "Not published: your box has no prep, so the check ran without node_modules and its result can't be trusted. Run abso prep 'npm ci --ignore-scripts' once (every fresh box then starts from it), then publish --check again.",
160+ text: "Not pushed: your box has no prep, so the check ran without node_modules and its result can't be trusted. Run abso prep 'npm ci --ignore-scripts' once (every fresh box then starts from it), then push --check again.",
141161 json: { check: { command: check, exit: ran.exit ?? 0, prep: null } },
142162 };
143163 }
144164 if ((ran.exit ?? 0) !== 0) {
145− // Whose is it? Run the check once more on shared alone, at the version just synced to (#36, Builder 6:
165+ // Whose is it? Run the check once more on shared alone, at the version just synced to (#36:
146166 // stopped by someone else's red test, nothing said whose). One extra run, only when the check fails.
147167 const recent = (await api.log({ agent: config.agent }, 5)).versions;
148168 const newest = recent[0]?.version;
149169 let verdict: string[] = [];
150170 let sharedExit: number | undefined;
151171 if (newest !== undefined) {
152− say(`avcs: the check failed; running it on shared alone (version ${newest}) to see whose it is.\n`);
172+ say(`abso: the check failed; running it on shared alone (version ${newest}) to see whose it is.\n`);
153173 const atFlags = new Map(flags);
154174 atFlags.set("at", String(newest));
155175 sharedExit =
Lines 191–197 at 318 (were 171–177 at 7)
171191 return {
172192 exit: EXIT.refused,
173193 text: [
174− `Not published: the check failed (exit ${ran.exit}) on your draft with newest shared. Its output is above.`,
194+ `Not pushed: the check failed (exit ${ran.exit}) on your draft with newest shared. Its output is above.`,
175195 ...verdict,
176196 ].join("\n"),
177197 json: {
Lines 203–231 at 318 (were 183–205 at 7)
183203 },
184204 };
185205 }
186− say("avcs: the check passed; publishing.\n");
206+ say("abso: the check passed; pushing.\n");
187207 }
188208 const checked = check !== undefined;
189− const steps = publishSteps(args, env, root, config, api, message, checked, waitSeconds, skippedCheck);
209+ const leftOut: LeftOut[] = [];
210+ const steps = publishSteps(args, env, root, config, api, message, checked, waitSeconds, skippedCheck, leftOut);
190211 // Say how far it got when the server can't be reached (#37, GAME - UI/UX: did the check run? did the draft go up?).
191− const out = await unreached(
212+ const reached = await unreached(
192213 steps,
193− checked
194− ? "The check passed, but the publish never reached the server: nothing was published."
195− : "Nothing was published.",
196− `${checked ? "The check passed; " : ""}the publish may have reached the server before its answer was lost: abso status shows whether your draft was published.`,
214+ checked ? "The check passed, but the push never reached the server: nothing was pushed." : "Nothing was pushed.",
215+ `${checked ? "The check passed; " : ""}the push may have reached the server before its answer was lost: abso status shows whether your draft was pushed.`,
197216 );
198− // --done: this publish finishes the work the start note named (#44): take the note back once it's published or queued.
199− const went =
200− (out.json as { version?: unknown; queued?: unknown }).version !== undefined ||
201− (out.json as { queued?: unknown }).queued !== undefined;
202− if (!bool(args, "done") || !went) return out;
217+ const out = withLeftOut(reached, leftOut);
218+ // --done: this publish finishes the work the start note named (#44): take the note back once it's published.
219+ // A publish still in the merge queue may yet be pulled, so its note and issue stay as they are until it lands.
220+ if (!bool(args, "done")) return out;
221+ const { version, queued, outcome } = out.json as { version?: unknown; queued?: unknown; outcome?: unknown };
222+ if (version === undefined) {
223+ if (queued === undefined || outcome === "pulled") return out;
224+ return {
225+ ...out,
226+ text: `${out.text}\nYour start note stays (--done): push ${queued} hasn't landed yet. Once it has, abso start --done takes the note back and abso issue <N> --done closes the issue it names.`,
227+ };
228+ }
203229 // done (#54): the work is finished, so an issue the note named is closed with this change.
204230 await api.starting(null, undefined, { done: true });
205231 return {
Lines 258–264 at 318 (were 232–238 at 7)
232258 );
233259 if (landed) {
234260 return {
235− text: `Published version ${landed.version}. The server's answer was lost (${why}), but shared's log shows your publish landed.`,
261+ text: `Pushed version ${landed.version}. The server's answer was lost (${why}), but shared's log shows your push landed.`,
236262 json: { version: landed.version, lostAnswer: why },
237263 };
238264 }
Lines 268–280 at 318 (were 242–254 at 7)
242268 if (queued) {
243269 return {
244270 exit: STILL_QUEUED,
245− text: `Queued as publish ${queued.id}. The server's answer was lost (${why}), but the merge queue holds your publish; the outcome comes as news on your next edit, and abso status shows the queue.`,
271+ text: `Queued as push ${queued.id}. The server's answer was lost (${why}), but the merge queue holds your push; the outcome comes as news on your next edit, and abso status shows the queue.`,
246272 json: { queued: queued.id, outcome: "queued", lostAnswer: why },
247273 };
248274 }
249275 return {
250276 exit: EXIT.error,
251− text: `Not published: ${why}. Shared's newest versions and the merge queue don't have it, so it's safe to publish again.`,
277+ text: `Not pushed: ${why}. Shared's newest versions and the merge queue don't have it, so it's safe to push again.`,
252278 json: { published: false, lostAnswer: why },
253279 };
254280 } catch {
Lines 308–324 at 318 (were 282–295 at 7)
282308 checked: boolean,
283309 waitSeconds: number,
284310 skippedCheck: boolean,
311+ leftOut: LeftOut[],
312+ autoSettled = false,
285313): Promise<Output> {
286314 const recorded = await recordFolder(root, api, false, meantBinary(args));
315+ leftOut.push(...recorded.leftOut);
287316 const pre = [...recordedFirst(recorded), ...droppedIgnoredText(await dropIgnoredFromDraft(root, api))];
288317 if (recorded.turnedBinary.length > 0) {
289318 // Publishing now would leave the others on the file's old text without anyone noticing (#25).
290319 return {
291320 exit: EXIT.refused,
292− text: [...pre, ...turnedBinaryText(recorded.turnedBinary), "Not published."].join("\n"),
321+ text: [...pre, ...turnedBinaryText(recorded.turnedBinary), "Not pushed."].join("\n"),
293322 json: { turnedBinary: recorded.turnedBinary, recorded: recorded.sent },
294323 };
295324 }
Lines 337–343 at 318 (were 308–314 at 7)
308337 try {
309338 answer = await api.publish(message, asIs);
310339 } catch (err) {
311− // The answer can be lost after the publish committed (Cloud: a storage reset killed the reply to
340+ // The answer can be lost after the publish committed (a storage reset killed the reply to
312341 // two publishes that had landed). Look before saying it failed; never publish again by itself.
313342 const found = await afterLostPublish(api, config.agent, message, started, err);
314343 if (found) return { ...found, text: [...pre, found.text].join("\n") };
Lines 346–352 at 318 (were 317–323 at 7)
317346 if (answer.ok && "queued" in answer) {
318347 // The merge queue (#39): it lands once a batch with it passes the project's check.
319348 const say = env.writeErr ?? env.write;
320− const head = `Queued as publish ${answer.queued}${answer.ahead === 0 ? "" : `, ${answer.ahead} ${answer.ahead === 1 ? "publish" : "publishes"} ahead of it`}: it lands once the project's check passes on it in the merge queue.`;
349+ const head = `Queued as push ${answer.queued}${answer.ahead === 0 ? "" : `, ${answer.ahead} ${answer.ahead === 1 ? "push" : "pushes"} ahead of it`}: it lands once the project's check passes on it in the merge queue.`;
321350 const notes = [
322351 ...pre,
323352 ...(skippedCheck
Lines 369–386 at 318 (were 340–359 at 7)
340369 text: [...notes, head, `Not waiting (--no-wait). ${later}`].join("\n"),
341370 json: { ...json, outcome: "queued" },
342371 };
343− say(`avcs: ${head} Waiting up to ${waitSeconds} s for it (--no-wait returns at once).\n`);
372+ say(`abso: ${head} Waiting up to ${waitSeconds} s for it (--no-wait returns at once).\n`);
344373 const out = await waitForQueued(
345374 api,
346375 answer.queued,
347376 waitSeconds * 1000,
348377 say,
349− Number(env.env.AVCS_QUEUE_POLL_MS) || 3000,
378+ Number(fromEnv(env.env, "QUEUE_POLL_MS")) || 3000,
350379 );
351380 if (out.kind !== "waiting") heard(root, out.news);
352381 if (out.kind === "landed")
353382 return {
354− text: [...notes, `Published version ${out.version}: it passed the project's check in the merge queue.`].join(
355− "\n",
356− ),
383+ text: [...notes, `Pushed version ${out.version}: it passed the project's check in the merge queue.`].join("\n"),
357384 json: { ...json, version: out.version, outcome: "landed" },
358385 };
359386 if (out.kind === "pulled")
Lines 394–400 at 318 (were 367–373 at 7)
367394 exit: STILL_QUEUED,
368395 text: [
369396 ...notes,
370− `Publish ${answer.queued} left the merge queue, but nothing said whether it landed: abso log -n 3 shows it if it did.`,
397+ `Push ${answer.queued} left the merge queue, but nothing said whether it landed: abso log -n 3 shows it if it did.`,
371398 ].join("\n"),
372399 json: { ...json, outcome: "unknown" },
373400 };
Lines 404–410 at 318 (were 377–385 at 7)
377404 : "still in the queue (the queue could not be read)";
378405 return {
379406 exit: STILL_QUEUED,
380− text: [...notes, `Still queued after ${waitSeconds} s: publish ${answer.queued} is ${where}. ${later}`].join(
381− "\n",
382− ),
407+ text: [...notes, `Still queued after ${waitSeconds} s: push ${answer.queued} is ${where}. ${later}`].join("\n"),
383408 json: { ...json, outcome: "queued" },
384409 };
385410 }
Lines 413–420 at 318 (were 388–395 at 7)
388413 const what =
389414 answer.changes === 0
390415 ? await alreadyInShared(root, api, config.agent, recorded.paths, answer.version)
391− : `Published version ${answer.version}.${merged.length > 0 ? ` ${mergedText(merged)}` : ""}`;
392− // The check ran on shared as it was; what landed since went in unchecked (Cloud).
416+ : `Pushed version ${answer.version}.${merged.length > 0 ? ` ${mergedText(merged)}` : ""}`;
417+ // The check ran on shared as it was; what landed since went in unchecked.
393418 const moved =
394419 checked && merged.length > 0
395420 ? [
Lines 426–443 at 318 (were 401–416 at 7)
401426 ...pre,
402427 what,
403428 ...moved,
404− // --check alone was skipped for a queue that turned out not to be on: the answer, not the draft's avcs.json, says (Cloud).
429+ // --check alone was skipped for a queue that turned out not to be on: the answer, not the draft's avcs.json, says.
405430 ...(skippedCheck
406431 ? [
407432 `It landed directly, with no check: your avcs.json says "queue": true, but shared's doesn't yet, so the merge queue isn't on and --check alone was skipped. abso ci ${answer.version} shows CI's result once it has run.`,
408433 ]
409434 : []),
410435 ...settledText(answer.settled ?? [], answer.version),
436+ ...(answer.changes === 0 ? [] : ciWhereText(answer.ciWhere, answer.version)),
411437 ].join("\n"),
412438 json: {
413439 version: answer.version,
440+ ...(answer.ciWhere === undefined ? {} : { ciWhere: answer.ciWhere }),
414441 changes: answer.changes ?? null,
415442 mergedWith: answer.mergedWith ?? [],
416443 settled: answer.settled ?? [],
Lines 453–474 at 318 (were 426–447 at 7)
426453 exit: EXIT.refused,
427454 text: [
428455 ...pre,
429− `Not published: ${files.join(", ")} still ${files.length === 1 ? "has" : "have"} collision markers (${plural(collisions.length, "block")}).`,
456+ `Not pushed: ${files.join(", ")} still ${files.length === 1 ? "has" : "have"} collision markers (${plural(collisions.length, "block")}).`,
430457 ...collisions.map(collisionText),
431− `Settle each: keep yours, theirs or a mix and delete the marker lines, or abso settle <file> --yours|--theirs|--both. Then publish again. abso publish --as-is keeps both sides everywhere; the other authors hear it.`,
458+ `Settle each: keep yours, theirs or a mix and delete the marker lines, or abso settle <file> --yours|--theirs|--both. Then push again. abso push --as-is keeps both sides everywhere; the other authors hear it.`,
432459 ].join("\n"),
433460 json: { collisions, recorded: recorded.sent },
434461 };
435462 }
436− // Lines both sides changed, still as the sync left them (#37, Builder 1): publishing would put both in shared.
463+ // Lines both sides changed, still as the sync left them (#37): publishing would put both in shared.
437464 if (collisions.length > 0 && collisions.every((c) => c.untouched)) {
438465 return {
439466 exit: EXIT.refused,
440467 text: [
441468 ...pre,
442− `Not published: ${plural(collisions.length, "collision")} you synced into and haven't edited since. Both sides' lines are still in the file, so publishing now would put them in shared twice.`,
469+ `Not pushed: ${plural(collisions.length, "collision")} you pulled into and haven't edited since. Both sides' lines are still in the file, so pushing now would put them in shared twice.`,
443470 ...collisions.map(collisionText),
444− "Edit each to what it should be (keep yours, theirs, or a mix), then publish again. If both really belong, abso publish --as-is keeps both.",
471+ "Edit each to what it should be (keep yours, theirs, or a mix), then push again. If both really belong, abso push --as-is keeps both.",
445472 ].join("\n"),
446473 json: { collisions, recorded: recorded.sent },
447474 };
Lines 477–629 at 318 (were 450–486 at 7)
450477 const real = collisions.filter((c) => !isLocalOnly(c.file));
451478 const twice = real.filter((c) => c.kind === "duplicate");
452479 const newer = real.filter((c) => c.kind !== "duplicate");
480+ // The server's first opinion on each collision (#19), when it runs AUTOSETTLE.
481+ const advice = answer.advice ?? [];
482+ // When the server says to settle (its AUTOSETTLE=act) and to keep a side of every collision, settle them here and
483+ // push again (ABSO_AUTOSETTLE=off stops it).
484+ const plan = autoSettled || answer.settle !== true ? null : autoPlan(collisions, advice, env);
485+ if (plan) {
486+ const pulled = await runSync({ positionals: [], flags: new Map() }, env);
487+ const done: string[] = [];
488+ for (const [file, a] of plan) {
489+ const path = absolute(root, file);
490+ const text = readText(path);
491+ const settled =
492+ text === null || text === undefined ? null : settleText(text, a.pick as "yours" | "theirs" | "both");
493+ if (!settled) continue;
494+ if (settled.blocks > 0) {
495+ writeFileAtomic(path, settled.text);
496+ done.push(file);
497+ continue;
498+ }
499+ // No marker block: the pull merged the lines itself. That counts when the file already holds the
500+ // advised side's lines (keep both: both sides').
501+ const lines = new Set(text!.split(/\r?\n/).map((l) => l.trim()));
502+ const sides = collisions
503+ .filter((c) => c.file === file)
504+ .flatMap((c) => [
505+ ...(a.pick !== "theirs" ? [c.yours.text] : []),
506+ ...(a.pick !== "yours" ? [c.theirs.text] : []),
507+ ]);
508+ const wanted = sides.flatMap((t) => t.split(/\r?\n/).map((l) => l.trim())).filter((l) => l !== "");
509+ if (wanted.length > 0 && wanted.every((l) => lines.has(l))) done.push(file);
510+ }
511+ const left = [...plan.keys()].filter((f) => !done.includes(f));
512+ if (left.length > 0)
513+ return {
514+ exit: EXIT.refused,
515+ text: [
516+ ...pre,
517+ pulled.text,
518+ `Not pushed: the server advised settling ${left.join(", ")}, but the pull left no marker block there. Settle as the pull says, then push again.`,
519+ ].join("\n"),
520+ json: { collisions, advice, autosettle: { pulled: true, settled: done, left } },
521+ };
522+ const again = await publishSteps(
523+ args,
524+ env,
525+ root,
526+ config,
527+ api,
528+ `${message}\n\n${autoTrailer(plan)}`,
529+ checked,
530+ waitSeconds,
531+ skippedCheck,
532+ leftOut,
533+ true,
534+ );
535+ return {
536+ ...again,
537+ text: [
538+ ...pre,
539+ `Held: ${plural(collisions.length, "collision")} with work pushed since your last pull. Settled automatically, as the server advised:`,
540+ ...[...plan].map(([file, a]) => ` ${file}: ${adviceWords(a)}`),
541+ again.text,
542+ "Check what was kept with abso show <version>:<file>; to change it, edit the file and push. ABSO_AUTOSETTLE=off settles nothing by itself.",
543+ ].join("\n"),
544+ json: { ...(again.json as object), autosettled: Object.fromEntries(plan) },
545+ };
546+ }
453547 return {
454548 exit: EXIT.refused,
455549 text: [
456550 ...pre,
457551 // A name defined twice is already in your folder (sync listed it); the rest is newer work.
458− `Not published: ${plural(collisions.length, "collision")}${newer.length > 0 ? " with work published since your last sync" : ""}.${answer.reason ? ` (${answer.reason})` : ""}`,
552+ `Not pushed: ${plural(collisions.length, "collision")}${newer.length > 0 ? " with work pushed since your last pull" : ""}.${answer.reason ? ` (${answer.reason})` : ""}`,
459553 ...real.map(collisionText),
554+ ...(advice.some((a) => a)
555+ ? [
556+ "First opinion (a model on the server, with checks in code; you still settle):",
557+ ...collisions.flatMap((c, i) => (advice[i] ? [` ${c.file}: ${adviceWords(advice[i]!)}`] : [])),
558+ ]
559+ : []),
460560 ...(local.length > 0
461561 ? [
462− ` ${local.map((c) => c.file).join(", ")}: local files that should never have been shared. abso sync drops them from your draft and leaves your copy on disk.`,
562+ ` ${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.`,
463563 ]
464564 : []),
465565 ...(real.some((c) => c.theirs.queued !== undefined)
466566 ? [
467− "Some of theirs are still in the merge queue, not in shared: once they land (abso status shows the queue), abso sync brings them in to settle; if they're pulled, publish again as you are.",
567+ "Some of theirs are still in the merge queue, not in shared: once they land (abso status shows the queue), abso pull brings them in to settle; if they're turned back, push again as you are.",
468568 ]
469569 : []),
470570 newer.length > 0
471− ? `Run abso sync: each of those files comes back holding both sides' lines, with no markers. Edit it to what it should be${twice.length > 0 ? ", keep one definition of each name defined twice" : ""}, then publish again.`
571+ ? `Run abso pull: each of those files comes back holding both sides' lines, in a marker block where you both changed the same lines. Settle each as the pull says${twice.length > 0 ? ", keep one definition of each name defined twice" : ""}, then push again.`
472572 : twice.length > 0
473− ? "Keep one definition of each name defined twice (delete yours, or theirs), then publish again."
474− : "Run abso sync, then publish again.",
573+ ? "Keep one definition of each name defined twice (delete yours, or theirs), then push again."
574+ : "Run abso pull, then push again.",
475575 ].join("\n"),
476− json: { collisions, recorded: recorded.sent, ...(answer.reason ? { reason: answer.reason } : {}) },
576+ json: {
577+ collisions,
578+ recorded: recorded.sent,
579+ ...(answer.reason ? { reason: answer.reason } : {}),
580+ ...(advice.length > 0 ? { advice } : {}),
581+ },
477582 };
478583}
479584
585+function adviceWords(a: Advice): string {
586+ const what = a.pick === "agent" ? "needs an agent" : `keep ${a.pick}`;
587+ const how =
588+ a.by === "rule"
589+ ? "by a check in code"
590+ : a.by === "turned down"
591+ ? `the model said keep ${a.modelPick}, turned down`
592+ : a.by === "unsure"
593+ ? `the model leaned to keep ${a.modelPick} at ${a.confidence.toFixed(2)}`
594+ : `confidence ${a.confidence.toFixed(2)}`;
595+ return `${what} (${how}): ${a.reason}`;
596+}
598+/**
599+ * What to settle by itself (#19), file by file, or null to leave it to the agent: every collision a lines collision
600+ * the server advised keeping a side of (it advises a side only at or above its threshold), each file's advice the
601+ * same, nothing still queued or local-only, and ABSO_AUTOSETTLE not "off".
602+ */
603+function autoPlan(
604+ collisions: readonly Collision[],
605+ advice: readonly (Advice | null)[],
606+ env: Env,
607+): Map<string, Advice> | null {
608+ if (fromEnv(env.env, "AUTOSETTLE") === "off" || collisions.length === 0) return null;
609+ const plan = new Map<string, Advice>();
610+ for (const [i, c] of collisions.entries()) {
611+ const a = advice[i];
612+ if ((c.kind ?? "lines") !== "lines" || c.untouched || c.marked || c.theirs.queued !== undefined) return null;
613+ if (isLocalOnly(c.file) || !a || a.pick === "agent") return null;
614+ const before = plan.get(c.file);
615+ if (before && before.pick !== a.pick) return null;
616+ if (!before || a.confidence < before.confidence) plan.set(c.file, a);
617+ }
618+ return plan;
619+}
480621export async function runSync(args: Parsed, env: Env): Promise<Output> {
481622 const { root, api } = open(env);
482623 const recorded = await recordFolder(root, api);
483624 const ignoredDropped = await dropIgnoredFromDraft(root, api);
625+ // A pull here that never wrote its answer (abso-core 26): this one asks for every file to catch up.
626+ const catchingUp = pullUnfinished(root) && !bool(args, "full");
484627 const s = await syncFolder(root, api, bool(args, "full"));
485628 const changes = s.written.length + s.deleted.length;
486629 // A renamed file is one line, not an update and a delete.
Lines 633–649 at 318 (were 490–503 at 7)
490633 ...turnedBinaryText(recorded.turnedBinary),
491634 ...recordedFirst(recorded),
492635 ...droppedIgnoredText(ignoredDropped),
493− `Synced to version ${s.version}: ${changes === 0 ? "no files changed" : `${plural(updated.length, "file")} updated, ${removed.length} deleted${s.renamed.length > 0 ? `, ${s.renamed.length} renamed` : ""}`}.`,
494− ...changedFilesText("sync", updated, removed, s.renamed, bool(args, "verbose")),
636+ `Pulled to version ${s.version}: ${changes === 0 ? "no files changed" : `${plural(updated.length, "file")} updated, ${removed.length} deleted${s.renamed.length > 0 ? `, ${s.renamed.length} renamed` : ""}`}.`,
637+ ...changedFilesText("pull", updated, removed, s.renamed, bool(args, "verbose")),
638+ ...(catchingUp
639+ ? ["The last pull here didn't finish, so this one asked for every file and wrote the ones that differed."]
640+ : []),
495641 ...refusedText(s.refused),
496642 // Ones an earlier sync couldn't write; this sync's are named just above.
497643 ...unwrittenText(s.unwritten, new Set(s.refused.map((r) => r.path))),
498644 ...mergedLinesText(s.merged),
499645 ...(s.kept.length > 0
500− ? [`Left alone because they changed while syncing (run abso sync again): ${s.kept.join(", ")}`]
646+ ? [`Left alone because they changed while pulling (run abso pull again): ${s.kept.join(", ")}`]
501647 : []),
502648 ...(s.dropped.length > 0
503649 ? [`Dropped from your draft, kept on disk (these stay local): ${s.dropped.join(", ")}`]
Lines 674–680 at 318 (were 528–534 at 7)
528674function settledText(settled: readonly Settled[], version: number | undefined): string[] {
529675 if (settled.length === 0) return [];
530676 const said = { yours: "kept yours", theirs: "kept theirs", both: "kept both", rewrote: "rewrote them" } as const;
531− // Lines both sides still had that the settled file no longer has (#37, Playtester 1): the settler should look.
677+ // Lines both sides still had that the settled file no longer has (#37): the settler should look.
532678 const quote = (l: string) => `"${l.trim().length > 60 ? `${l.trim().slice(0, 57)}...` : l.trim()}"`;
533679 return [
534680 `Settled ${plural(settled.length, "collision")}: ${settled.map((s) => `${s.file} (${said[s.kept]}, against ${s.theirs.agent}'s version ${s.theirs.version})`).join("; ")}. ${[...new Set(settled.map((s) => s.theirs.agent))].join(", ")} will hear what you kept.`,
Lines 688–694 at 318 (were 542–548 at 7)
542688}
543689
544690/**
545− * What an empty publish says (#37, Artist 1: "Nothing to publish: your draft
691+ * What an empty publish says (#37: "Nothing to publish: your draft
546692 * is empty" read as lost work). The files this folder edited since its last
547693 * publish (this record's, and the edit hook's sends in .avcs/hook.log) that
548694 * someone else changed in shared since then: shared already has them as you
Lines 701–712 at 318 (were 555–566 at 7)
555701 recordedPaths: readonly string[],
556702 version: number,
557703): Promise<string> {
558− const empty = `Nothing to publish: your draft is empty. Shared is at version ${version}.`;
704+ const empty = `Nothing to push: your draft is empty. Shared is at version ${version}.`;
559705 const log = await api.log({ agent }, FOLDER_LOG_LIMIT);
560706 const since = log.versions.find((v) => v.agent === agent)?.time ?? 0;
561707 const edited = new Set(recordedPaths);
562708 try {
563− for (const line of readFileSync(join(root, ".avcs", "hook.log"), "utf8").split("\n")) {
709+ for (const line of readFileSync(join(stateDir(root), "hook.log"), "utf8").split("\n")) {
564710 const [at, , rel, outcome] = line.split("\t");
565711 if (rel && outcome?.startsWith("sent") && Date.parse(at ?? "") >= since) edited.add(rel);
566712 }
Lines 720–730 at 318 (were 574–584 at 7)
574720 found.push(`${rel} (version ${last.version}, ${last.agent}: "${last.message}")`);
575721 }
576722 if (found.length === 0) return empty;
577− return `Nothing published: shared already has ${found.length === 1 ? "the file you changed" : "the files you changed"} as you have ${found.length === 1 ? "it" : "them"}, so nothing of yours is lost. Last changed in ${found.join("; ")}. Shared is at version ${version}.`;
723+ return `Nothing pushed: shared already has ${found.length === 1 ? "the file you changed" : "the files you changed"} as you have ${found.length === 1 ? "it" : "them"}, so nothing of yours is lost. Last changed in ${found.join("; ")}. Shared is at version ${version}.`;
578724}
579725
580726/**
581− * Several files marked against one version (#37, Builder 6: twenty tool
727+ * Several files marked against one version (#37: twenty tool
582728 * scripts muted twice at once): if that version already does what yours do,
583729 * one settle takes theirs in all of them.
584730 */
MCP
compare on this site's /mcp
CLI
abso diff 7 318 client/src/publish-commands.ts --json
JSON
/christopher/abso-core/compare/7..318?file=client%2Fsrc%2Fpublish-commands.ts&format=json