16 files, 187 lines added, 29 removed.
--- a/client/src/api-answers.ts
+++ b/client/src/api-answers.ts
@@ -65,6 +65,8 @@
6565 readonly theirs: { readonly agent: string; readonly version: number }; 6666 /** Lines both sides still had that the settled file no longer has (#37). */ 6767 readonly lost?: readonly string[]; 68+ /** The message of the settler's push that was held for this collision. */ 69+ readonly held?: string; 6971export interface RecordAnswer { 7072 readonly ok: boolean; @@ -124,6 +126,8 @@
124126 readonly time: number; 125127 readonly kinds: readonly string[]; 126128 readonly files: readonly string[]; 129+ /** A held push's message. */ 130+ readonly message?: string; 128132 readonly notes?: readonly NoteAnswer[]; 129133 readonly reviewers?: readonly { readonly agent: string; readonly files: readonly string[]; readonly read: boolean }[]; --- a/client/src/history-answers.ts
+++ b/client/src/history-answers.ts
@@ -161,6 +161,10 @@
161161 readonly message: string; 162162 readonly publish: Publish | null; 164+ /** When the line's own change settled nothing: the settle that kept it from a marker block. */ 165+ readonly settledBy?: { readonly atom: string; readonly author: string; readonly publish: Publish | null }; 166+ /** The settler's push that was held for the collision, with its message: that side's reason. */ 167+ readonly held?: { readonly agent: string; readonly message: string; readonly time: number }; 165169export interface WhereAnswer { 166170 readonly version: number; --- a/client/src/history.ts
+++ b/client/src/history.ts
@@ -119,10 +119,13 @@
119119 ...(w.change.message ? [`The change says: "${w.change.message}"`] : []), 120120 ...(w.settled.length > 0 122− "It settled a collision between:",
123+ ? `It was kept when ${w.settledBy.author} settled a collision between:` 124+ : "It settled a collision between:", 124126 (s) => ` ${s.author}, ${published(s.publish)}${s.message ? ` (the change: "${s.message}")` : ""}`, 128+ ...(w.held ? [` ${w.held.agent}, a held push: "${w.held.message}"`] : []), 128131 ...(w.reasons.length > 0 --- a/client/src/review.ts
+++ b/client/src/review.ts
@@ -111,7 +111,7 @@
112112 ...(c.refusals.length > 0 114− `Refused ${plural(c.refusals.length, "time")} on the way: ${c.refusals.map((r) => `${r.kinds.join(", ")} (${r.files.join(", ")})`).join("; ")}.`,
114+ `Refused ${plural(c.refusals.length, "time")} on the way: ${c.refusals.map((r) => `${r.kinds.join(", ")} (${r.files.join(", ")})${r.message ? `: ${JSON.stringify(r.message)}` : ""}`).join("; ")}.`, 117117 ...((c.reviewers ?? []).length > 0 --- a/client/test/held-push.test.ts
+++ b/client/test/held-push.test.ts
@@ -1,6 +1,6 @@
11// A held push from end to end, as two agents meet it: alice and bob change 22// the same line, bob's push is held, he pulls, settles and pushes again. 3−// What each step prints has to be true.
3+// What each step prints has to be true, and the record has to keep his reason. 55import assert from "node:assert/strict"; 66import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; @@ -68,6 +68,41 @@
6868 assert.match(policy(bob), /^<<<<<<< yours \(unpublished\)$/m, "the pull wrote a marker block"); 71+ for (const how of ["yours", "theirs", "both"] as const) { 72+ it(`why names the collision a line was kept from, settled --${how}`, async () => { 73+ const { alice, bob } = await held(); 74+ assert.equal((await run(bob, "pull")).exit, 0); 75+ const settled = await run(bob, "settle", "store-policy.md", `--${how}`); 76+ assert.equal(settled.exit, 0, settled.out); 77+ const pushed = await run(bob, "push", "-m", `Settle: keep ${how}`); 78+ assert.equal(pushed.exit, 0, pushed.out); 79+ assert.equal((await run(alice, "pull")).exit, 0); 80+ const why = await run(alice, "why", "store-policy.md:3"); 81+ assert.equal(why.exit, 0, why.out); 82+ assert.match(why.out, /It was kept when bob settled a collision between:\n {2}alice, version 1 by alice/); 83+ assert.match(why.out, new RegExp(`\\n {2}bob, a held push: "${HELD.replace(/\$/g, "\\$")}"`)); 87+ it("keeps its message: why on the settling line shows it, and so do the change page and the news", async () => { 88+ const { alice, bob } = await held(); 89+ assert.equal((await run(bob, "pull")).exit, 0); 90+ writeFileSync(join(bob, "store-policy.md"), POLICY.replace("$50", "$60")); 91+ const pushed = await run(bob, "push", "-m", "Settle with alice: meet at $60"); 92+ assert.equal(pushed.exit, 0, pushed.out); 93+ const why = await run(bob, "why", "store-policy.md:3"); 96+ /It settled a collision between:\n {2}alice, version 1 by alice[^\n]*\n {2}bob, a held push: "/, 98+ assert.ok(why.out.includes(HELD), why.out); 99+ const review = await run(alice, "review", "bob"); 100+ assert.match(review.out, /Settled: store-policy\.md \(rewrote both sides, against alice's version 1\)\./); 101+ assert.ok(review.out.includes(`Refused 1 time on the way: lines (store-policy.md): "${HELD}"`), review.out); 102+ const news = await run(alice, "news"); 103+ assert.ok(news.out.includes(`Its held push said: "${HELD}"`), news.out); 71106 it("the change page says what a settle kept in words that read for each choice", async () => { 72107 for (const [how, said] of [ 73108 ["yours", "kept bob's"], --- a/worker/project/apply-entry.ts
+++ b/worker/project/apply-entry.ts
@@ -112,6 +112,7 @@
113113 host.joinChange(agent, entry, at, space.name === SHARED ? null : space.name); 114114 agent.marked = agent.marked.filter((r) => r.space !== (entry.space ?? SHARED)); 115116 if (entry.queued !== undefined) host.setQueued(host.queued().filter((q) => q.id !== entry.queued)); @@ -243,23 +244,29 @@
245246 collisions: entry.collisions.map((c) => ({ ...c })), 247+ ...(entry.message ? { message: entry.message } : {}), 248250 // On the change the agent was working on, when there is one (#44). 249251 const agent = host.agentOf(entry.agent); 250252 host.active(agent, entry.time); 251253 const id = host.currentChange(agent, entry.time); 257+ kinds: [...new Set(entry.collisions.map((c) => c.kind))].sort(), 258+ files: [...new Set(entry.collisions.map((c) => c.file))].sort(), 259+ ...(entry.message ? { message: entry.message } : {}), 252261 if (id !== undefined) { 253262 const rec = host.changeRecord(id, agent, entry.time); 254− rec.refusals.push({
255− at,
256− time: entry.time,
257− kinds: [...new Set(entry.collisions.map((c) => c.kind))].sort(),
258− files: [...new Set(entry.collisions.map((c) => c.file))].sort(),
259− });
263+ rec.refusals.push({ ...refusal, files: [...refusal.files], kinds: [...refusal.kinds] }); 261265 host.changes.set(id, rec); 267+ // Kept until it pushes: the settle tells the held push's reason, and its change lists the refusal. 268+ if (entry.via === "publish") 269+ agent.held = [...(agent.held ?? []), { ...refusal, ...(id !== undefined ? { change: id } : {}) }]; --- a/worker/project/blame.ts
+++ b/worker/project/blame.ts
@@ -3,7 +3,8 @@
33// that change's author and message, and the publish that brought it into 44// shared, with its message. Why adds the change's reasons, what it settled, 55// and the reasons other changes give that point at it. 6−import type { AtomId } from "../../src/engine/index.ts";
6+import { type Atom, type AtomId, type LineId, type ReadView, View } from "../../src/engine/index.ts"; 7+import { blocksIn, isMarkerLine } from "./markers.ts"; 78import { pathKey } from "./pathkey.ts"; 89import type { Project } from "./project.ts"; @@ -66,7 +67,7 @@
6667 const { view, name } = viewOf(project, where); 6768 const file = project.spellingIn(view, asked); 6869 if (!view.hasFile(file)) throw badRequest(`${asked} isn't in ${name}`); 69− return { file, all: view.lines(file) };
70+ return { file, all: view.lines(file), view }; @@ -113,9 +114,59 @@
118+ * The settle a line was kept through, when its own change settled nothing: 119+ * an edit that took out the markers of a block the line sat in (as yours or 120+ * theirs), as abso settle --yours, --theirs or --both makes. The earliest, 123+function keptThrough(project: Project, view: ReadView, file: string, line: LineId, author: Atom): Atom | undefined { 124+ const graph = project.graph; 125+ const set = view.set; 126+ for (const s of graph.atoms()) { 127+ if (s.seq <= author.seq || s.resolves.length === 0 || !set.has(s.id)) continue; 128+ const marks = s.deletes.filter((id) => { 129+ const info = graph.line(id); 130+ return info !== undefined && info.file === file && isMarkerLine(info.text); 132+ if (marks.length === 0) continue; 133+ // The file just before the settle, markers and all. 134+ const before = new View( 139+ .filter((a) => set.has(a.id)) 142+ if (!before.hasFile(file)) continue; 143+ const lines = before.lines(file); 144+ const at = lines.findIndex((l) => l.id === line); 145+ if (at < 0) continue; 146+ const block = blocksIn(lines.map((l) => l.text)).find((b) => at > b.start && at < b.end); 147+ if (block && marks.includes(lines[block.start]!.id)) return s; 152+/** The settler's push that was held for this collision, newest first: its message is that side's reason. */ 153+function heldPush(project: Project, settle: Atom, file: string, after: number) { 154+ const held = project 155+ .refusals({ agent: settle.author, limit: 1000 }) 158+ r.via === "publish" && 159+ r.message !== undefined && 160+ r.time <= settle.time && 162+ r.collisions.some((c) => c.file === file), 164+ return held ? { agent: held.agent, message: held.message!, time: held.time } : undefined; 116167/** One line: the change that wrote it, the publish behind it, its reasons, and what it settled. */ 117168export function why(project: Project, asked: string, n: number, where: BlameWhere = {}) { 118− const { file, all } = lines(project, asked, where);
169+ const { file, all, view } = lines(project, asked, where); 119170 const line = all[n - 1]; 121172 throw Object.assign(new Error(`${file} has ${all.length} lines; ask for one in 1-${all.length}`), { @@ -163,10 +214,17 @@
163214 builtOn.sort((a, b) => 164215 (a.draft === undefined) !== (b.draft === undefined) ? (a.draft === undefined ? -1 : 1) : b.version - a.version, 166− const settled = atom.resolves.map((id) => {
217+ // What it settled: its own change, or the settle that kept it (both sides of a block it sat in). 218+ const kept = atom.resolves.length === 0 ? keptThrough(project, view, file, line.id, atom) : undefined; 219+ const settle = kept ?? atom; 220+ const settled = settle.resolves.map((id) => { 167221 const a = graph.atom(id); 168222 return { atom: id, author: a.author, message: a.message, publish: publishOf(project, id) }; 226+ ? heldPush(project, settle, file, Math.max(0, ...settled.map((s) => s.publish?.time ?? 0))) @@ -184,6 +242,8 @@
245+ ...(kept ? { settledBy: { atom: kept.id, author: kept.author, publish: publishOf(project, kept.id) } } : {}), 246+ ...(held ? { held } : {}), --- a/worker/project/change-records.ts
+++ b/worker/project/change-records.ts
@@ -101,6 +101,11 @@
101101 rec.versions.push({ version: entry.version, draft, message: entry.message, time: entry.time, at }); 102102 host.versionChange.set(`${draft ?? ""} ${entry.version}`, id); 103103 if (entry.type === "publish") for (const s of entry.settled ?? []) rec.settled.push({ ...s, version: entry.version }); 104+ // Pushes held on the way, when no change was going to put them on: they belong to the push that follows. 105+ if (entry.type === "publish") 106+ for (const { change: on, ...h } of agent.held ?? []) 107+ if (on === undefined && !rec.refusals.some((r) => r.at === h.at)) 108+ rec.refusals.push({ ...h, kinds: [...h.kinds], files: [...h.files] }); 105110 host.changes.set(id, rec); @@ -138,7 +143,12 @@
139144 files: [...new Set(versions.flatMap((v) => v.files))].toSorted(), 140145 settled: rec.settled.map((s) => ({ ...s })), 141− refusals: rec.refusals.map(({ time, kinds, files }) => ({ time, kinds: [...kinds], files: [...files] })),
146+ refusals: rec.refusals.map(({ time, kinds, files, message }) => ({ 150+ ...(message ? { message } : {}), 142152 notes: [...host.notes.values()].filter((n) => n.change === rec.id).map((n) => host.noteAnswer(n)), 143153 reviewers: host.reviewersOf( 144154 versions.flatMap((v) => v.files), --- a/worker/project/markers.ts
+++ b/worker/project/markers.ts
@@ -264,6 +264,11 @@
264264 return y === "nothing" && t === "nothing" ? "both" : "rewrote"; 267+/** The message of the agent's newest held push that named `file`: its side's reason, for the settle to tell. */ 268+export function heldMessage(agent: AgentState, file: string): string | undefined { 269+ return agent.held?.findLast((h) => h.message && h.files.includes(file))?.message; 267272/** What the marker reads need from a project. */ 268273export interface MarkerHost { 269274 readonly graph: Graph; --- a/worker/project/news.ts
+++ b/worker/project/news.ts
@@ -129,7 +129,7 @@
129129 rewrote: "it kept part of each side or rewrote them", 132−/** The other author of a marked collision a publish settled (#11): what was kept, and any lines lost. */
132+/** The other author of a marked collision a publish settled (#11): what was kept, any lines lost, and the settler's held reason. */ 133133export function settledItem(by: string, version: number, s: Settled): NewsItem { 135135 key: `settled ${by} ${version} ${s.file} ${s.theirs.version}`, @@ -138,6 +138,7 @@
139139 ? ` It also lost ${s.lost.length === 1 ? "a line" : `${s.lost.length} lines`} you both still had: ${s.lost.map((l) => `"${clip(l)}"`).join(", ")}.` 141+ (s.held ? ` Its held push said: "${clip(s.held)}".` : "") + 141142 ` abso show ${version}:${s.file} shows the file.`, --- a/worker/project/project-types.ts
+++ b/worker/project/project-types.ts
@@ -166,6 +166,8 @@
166166 readonly space?: string; 167167 readonly via: "publish" | "land"; 168168 readonly time: number; 169+ /** The held push's message: its reason, which the settle that follows tells. */ 170+ readonly message?: string; 169171 readonly collisions: readonly { 170172 readonly kind: Collision["kind"]; 171173 readonly file: string; @@ -343,7 +345,7 @@
343345 readonly time: number; 344346 readonly versions: { version: number; draft: string | null; message: string; time: number; at: number }[]; 345347 readonly settled: (Settled & { version: number })[]; 346− readonly refusals: { at: number; time: number; kinds: string[]; files: string[] }[];
348+ readonly refusals: { at: number; time: number; kinds: string[]; files: string[]; message?: string }[]; 347349 /** The log position of its newest entry. */ @@ -417,7 +419,7 @@
417419 versions: { version: number; draft: string | null; message: string; time: number; files: string[] }[]; 419421 settled: (Settled & { version: number })[]; 420− refusals: { time: number; kinds: string[]; files: string[] }[];
422+ refusals: { time: number; kinds: string[]; files: string[]; message?: string }[]; 421423 /** Its notes, replies included, oldest first. */ 422424 notes: NoteAnswer[]; 423425 /** The reviewers whose areas (avcs.json's "review") its files fall in, and whether each has left a note on it. */ @@ -448,6 +450,8 @@
448450 theirs: { agent: string; version: number }; 449451 /** Lines both sides still had that the settled file lost (#37): check them. */ 453+ /** The message of the settler's push that was held for this collision: its side's reason. */ 452456/** A line both sides changed that a sync merged word by word (#37): check it. */ 453457export interface MergedLine { @@ -550,6 +554,8 @@
550554 via: "publish" | "land"; 552556 collisions: { kind: Collision["kind"]; file: string; name?: string }[]; 557+ /** The held push's message. */ 554560/** One file before and after: text, or null where it doesn't exist. */ 555561export interface FileChange { @@ -727,6 +733,12 @@
727733 starting?: Starting; 728734 /** Collisions a sync wrote markers for (#11), until it publishes in that space. */ 729735 marked: (MarkedRegion & { space: string })[]; 737+ * Its pushes refused since it last pushed, with their messages, so the 738+ * settle that follows can tell its reason; `change` is the change a 739+ * refusal was put on, if one was going. 741+ held?: { at: number; time: number; kinds: string[]; files: string[]; message?: string; change?: number }[]; 732744/** Another agent with work on a file: unpublished changes, a starting note, or both. */ --- a/worker/project/project.ts
+++ b/worker/project/project.ts
@@ -1928,8 +1928,8 @@
19281928 collision: (agent, pair) => this.#collision(agent, pair), 19291929 definitionCollisions: (agent, newer) => this.#definitionCollisions(agent, newer), 19301930 duplicates: (agent) => this.#duplicates(agent), 1931− refuse: (agent, space, via, time, collisions, entries) =>
1932− this.#refuse(agent, space, via, time, collisions, entries),
1931+ refuse: (agent, space, via, time, collisions, entries, message) => 1932+ this.#refuse(agent, space, via, time, collisions, entries, message), 19331933 markerCollisions: (agent) => this.#markerCollisions(agent), 19341934 enqueue: (agent, message, time, draft, resolves, entries) => 19351935 this.#enqueue(agent, message, time, draft, resolves, entries), @@ -1975,8 +1975,8 @@
19751975 pairs: (draft, against, settled) => this.#pairs(draft, against, settled), 19761976 describe: (pair, yoursView, theirsView, spaceName) => this.#describe(pair, yoursView, theirsView, spaceName), 19771977 touchedFiles: (ids, views) => this.#touchedFiles(ids, views), 1978− refuse: (agent, space, via, time, collisions, entries) =>
1979− this.#refuse(agent, space, via, time, collisions, entries),
1978+ refuse: (agent, space, via, time, collisions, entries, message) => 1979+ this.#refuse(agent, space, via, time, collisions, entries, message), 19801980 currentChange: (agent, time) => this.#currentChange(agent, time), 19811981 nextAt: () => this.#nextAt, 19821982 apply: (entry) => this.#apply(entry), --- a/worker/project/publish.ts
+++ b/worker/project/publish.ts
@@ -5,7 +5,7 @@
55import { differenceSet, unionOverlay } from "../../src/engine/state-source.ts"; 66import type { Pair } from "./collisions.ts"; 77import type { DefinitionCollision } from "./definition-rule.ts"; 8−import { keptOf, lostLines, settleLines } from "./markers.ts";
8+import { heldMessage, keptOf, lostLines, settleLines } from "./markers.ts"; 99import { ProjectError } from "./project-error.ts"; 1010import type { AgentState, Collision, Entry, Meta, Mode, PublishAnswer, Settled } from "./project-types.ts"; 1111import { last, SHARED, type Space } from "./spaces.ts"; @@ -48,6 +48,7 @@
4949 collisions: Collision[], 5152 ): { ok: false; collisions: Collision[] }; 5253 markerCollisions(agent: AgentState): Collision[]; @@ -135,7 +136,7 @@
135136 ...host.definitionCollisions(agent, newer).map((d) => d.collision), 136137 ...host.duplicates(agent), 138− if (collisions.length > 0) return host.refuse(agent, space, "publish", time, collisions, entries);
139+ if (collisions.length > 0) return host.refuse(agent, space, "publish", time, collisions, entries, message); 139140 // Settled means the markers are gone (#11): refused while the draft adds any. 140141 const marked = host.markerCollisions(agent); 141142 if (marked.length > 0) return host.refuse(agent, space, "publish", time, marked, entries); @@ -173,11 +174,13 @@
174175 const lines = view.hasFile(r.file) ? view.lines(r.file).map((l) => l.text) : []; 175176 const lost = lostLines(lines, r); 177+ const held = heldMessage(agent, r.file); 178180 kept: keptOf(lines, r), 179181 theirs: { agent: r.agent, version: r.version }, 180182 ...(lost.length > 0 ? { lost } : {}), 183+ ...(held ? { held } : {}), --- a/worker/project/queue.ts
+++ b/worker/project/queue.ts
@@ -4,7 +4,7 @@
44import { type AtomId, buildAtom, type Graph, type ReadView } from "../../src/engine/index.ts"; 55import type { Pair } from "./collisions.ts"; 66import { definedTwice } from "./definitions.ts"; 7−import { keptOf, lostLines } from "./markers.ts";
7+import { heldMessage, keptOf, lostLines } from "./markers.ts"; 88import { clip } from "./news.ts"; 99import { ProjectError } from "./project-error.ts"; 1010import { projectFileIn } from "./project-helpers.ts"; @@ -49,6 +49,7 @@
5050 collisions: Collision[], 5253 ): { ok: false; collisions: Collision[] }; 5354 currentChange(agent: AgentState, time: number): number | undefined; @@ -149,7 +150,7 @@
152− if (collisions.length > 0) return host.refuse(agent, space, "publish", time, collisions, entries);
153+ if (collisions.length > 0) return host.refuse(agent, space, "publish", time, collisions, entries, message); 154155 const view = host.agentView(agent); 155156 const settled: Settled[] = agent.marked @@ -157,11 +158,13 @@
158159 const lines = view.hasFile(r.file) ? view.lines(r.file).map((l) => l.text) : []; 159160 const lost = lostLines(lines, r); 161+ const held = heldMessage(agent, r.file); 162164 kept: keptOf(lines, r), 163165 theirs: { agent: r.agent, version: r.version }, 164166 ...(lost.length > 0 ? { lost } : {}), 167+ ...(held ? { held } : {}), 167170 const id = host.queuedId() + 1; --- a/worker/project/refuse.ts
+++ b/worker/project/refuse.ts
@@ -11,7 +11,7 @@
1111 readonly refusals: readonly Refusal[]; 14−/** Answer a refusal, and log it (an entry that changes nothing but the counts). */
14+/** Answer a refusal, and log it (an entry that changes nothing but the counts, and keeps a push's message). */ 1515export function refuse( @@ -20,6 +20,7 @@
2121 collisions: Collision[], 2324): { ok: false; collisions: Collision[] } { 2425 const entry: Entry = { @@ -32,6 +33,8 @@
3334 ...(c.name !== undefined ? { name: c.name } : {}), 36+ // A held push keeps its message: the settle that follows tells it as this side's reason. 37+ ...(message ? { message } : {}), 3639 entries.push(entry); --- a/worker/project/test/project.test.ts
+++ b/worker/project/test/project.test.ts
@@ -204,12 +204,13 @@
204204 assert.equal(folderB["notes.md"], `one\ntwo\n${block}four\nfive\n`); 205205 assert.deepEqual(Object.keys(synced.files), ["notes.md"]); // b's own engine.ts edit was already in its folder 207− // b settles it with an edit that takes the markers out, and publish goes through, saying what b kept.
207+ // b settles it with an edit that takes the markers out, and publish goes through, saying what b kept 208+ // and what its held push said. 208209 project.edit("b", { file: "notes.md", old: block, new: "three (a and b)\n" }, 7); 209210 const settled = project.publish("b", "Settle three", 8); 210211 assert.deepEqual(settled.ok && "version" in settled && [settled.version, settled.settled], [ 212− [{ file: "notes.md", kept: "rewrote", theirs: { agent: "a", version: 1 } }],
213+ [{ file: "notes.md", kept: "rewrote", theirs: { agent: "a", version: 1 }, held: "Mark three for b" }], 214215 assert.equal(project.files()["notes.md"], "one\ntwo\nthree (a and b)\nfour\nfive\n"); 215216 assert.equal(project.files()["engine.ts"], "export function match(p, s) {\n return void 0;\n}\n"); @@ -357,7 +358,14 @@
357358 assert.equal(project.publish("bob", "c", 3).ok, false); 358359 assert.deepEqual(project.status().refusals, { total: 1, lines: 1, definition: 0, attribute: 0, duplicate: 0 }); 359360 assert.deepEqual(project.refusals().refusals, [ 360− { agent: "bob", draft: null, via: "publish", time: 3, collisions: [{ kind: "lines", file: "a.txt" }] },
366+ collisions: [{ kind: "lines", file: "a.txt" }], 362370 assert.deepEqual(Project.load(store.entries, new MemoryStore()).refusals(), project.refusals());