visualproof 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/assets/tips/phone-fingers.light.mp4 +0 -0
  2. package/dist/assets/tips/phone-fingers.light.webp +0 -0
  3. package/dist/assets/tips/tour-agent.webp +0 -0
  4. package/dist/assets/tips/tour-arrange.webp +0 -0
  5. package/dist/assets/tips/tour-artwork.webp +0 -0
  6. package/dist/assets/tips/tour-checks.webp +0 -0
  7. package/dist/assets/tips/tour-keys.webp +0 -0
  8. package/dist/assets/tips/tour-library.webp +0 -0
  9. package/dist/assets/tips/tour-project.webp +0 -0
  10. package/dist/assets/tips/tour-review.webp +0 -0
  11. package/dist/assets/tips/tour-share.webp +0 -0
  12. package/dist/assets/tips/tour-source.webp +0 -0
  13. package/dist/assets/tips/tour-target.webp +0 -0
  14. package/dist/assets/tips/tour-view.webp +0 -0
  15. package/dist/assets/tips/tour.json +125 -115
  16. package/dist/assets/tips/tour.webp +0 -0
  17. package/dist/mcp/visualproof-mcp.mjs +20 -9
  18. package/dist/server/access.js +28 -0
  19. package/dist/server/agent.js +137 -49
  20. package/dist/server/askfollow.js +1 -1
  21. package/dist/server/deploy.js +204 -53
  22. package/dist/server/invites.js +113 -20
  23. package/dist/server/live.js +125 -28
  24. package/dist/server/main.js +216 -69
  25. package/dist/server/mcptools.js +33 -20
  26. package/dist/server/presence.js +3 -3
  27. package/dist/server/prompt.js +8 -3
  28. package/dist/server/readonlygate.js +4 -4
  29. package/dist/server/reviewapi.js +51 -17
  30. package/dist/server/talk.js +231 -115
  31. package/dist/server/tokens.js +10 -2
  32. package/dist/shared/build.js +35 -1
  33. package/dist/shared/collab.js +8 -0
  34. package/dist/shared/keys.js +66 -37
  35. package/dist/shared/lostfound.js +1 -0
  36. package/dist/shared/mentions.js +83 -0
  37. package/dist/shared/query.js +13 -4
  38. package/dist/shared/review.js +91 -21
  39. package/dist/shared/reviewqueue.js +6 -1
  40. package/dist/web/bundle/app.js +3068 -1928
  41. package/dist/web/index.html +45 -9
  42. package/dist/web/src/reviewqueue.js +52 -19
  43. package/dist/web/src/trust.js +271 -0
  44. package/dist/web/style.css +181 -70
  45. package/docs/agent-api/README.md +13 -11
  46. package/docs/agent-api/advice.md +8 -2
  47. package/docs/agent-api/export.md +1 -1
  48. package/docs/agent-api/following.md +11 -12
  49. package/docs/agent-api/history.md +3 -2
  50. package/docs/agent-api/mcp.md +15 -15
  51. package/docs/agent-api/notes.md +1 -1
  52. package/docs/agent-api/reading.md +2 -2
  53. package/docs/agent-api/requests.md +12 -15
  54. package/docs/agent-api/talking.md +60 -55
  55. package/docs/agent-api/tcb.md +21 -21
  56. package/docs/agent-api/views.md +3 -4
  57. package/docs/agent-api/words.md +8 -8
  58. package/package.json +2 -1
@@ -171,6 +171,14 @@ export const SCHEMES = ["kind", "status"];
171
171
  /** Activity's filters: the kind of event, and whose (web/src/activity.ts). */
172
172
  export const ACTIVITY_KINDS = ["all", "review", "build", "change"];
173
173
  export const ACTIVITY_WHO = ["all", "agents", "people"];
174
+ /** Whether `who` made the token `t` (AgentSpec decision 7): the personal link that made it, where an
175
+ * invited person did; else the name it was made under, as names are compared. Its private channel
176
+ * and its prompt are theirs alone. */
177
+ export function madeBy(t, who) {
178
+ if (t.makerPerson)
179
+ return who.person === t.makerPerson;
180
+ return who.name !== null && sameName(who.name, t.by);
181
+ }
174
182
  /** A session id: what a page calls itself for as long as it is open, in its event stream's address
175
183
  * only (the server keeps a page's streams few by it); it is never told to the others. */
176
184
  export function validSession(s) {
@@ -1,21 +1,26 @@
1
- // Key declarations (ExportSpec decisions 1, 3 and 4): the members of a target's review that matter
2
- // for understanding it — the central definitions, the structures they are built on, the main theorem —
3
- // marked by people, or by agents at level full, per target; the target itself is always key. What each key declaration rests
4
- // on beyond itself (its support), and how the key declarations rest on one another (the key graph),
5
- // are pure functions of the graph, the review and the target's review set, over the same set and
6
- // edges the review queue walks (shared/reviewqueue.ts): the page, the agents' API and the exported
7
- // document (shared/doc/) all read them here.
1
+ // Key declarations (ExportSpec decisions 1, 3 and 4): the members of a target's TCB that matter for
2
+ // understanding it — the central definitions, the structures they are built on, the main theorem —
3
+ // marked by people, or by agents at level full, per target; the target itself is always key. A key
4
+ // declaration may be trusted (the owner's decision of 2026-10-19): trust says it needs no review, key
5
+ // that it is needed to read the target. It is read and printed as any key one is, and counted apart:
6
+ // key progress counts the key declarations that need review, "+N trusted" beside them (keyCounts).
7
+ // What each key declaration rests on beyond itself (its support), and how the key declarations rest
8
+ // on one another (the key graph), are pure functions of the graph, the review and the target's review
9
+ // set, over the same edges the review queue walks (shared/reviewqueue.ts): the page, the agents' API
10
+ // and the exported document (shared/doc/) all read them here.
8
11
  //
9
12
  // A member x that is not key is *supported by* a key declaration k when x is reachable from k
10
- // through members that are not key, along statement and body references. The key graph has an edge
11
- // from k₁ to k₂ when k₂ is reachable from k₁ that way. Two refinements keep "every member is
12
- // supported by some key declaration" true where the review set is more than what the target
13
- // reaches through its members:
13
+ // through members of the TCB that are not key, along statement and body references; k's support is
14
+ // the members of the review set it supports — a trusted member is passed through, never counted
15
+ // (TCBSpec decision 7). The key graph has an edge from k₁ to k₂ when k₂ is reachable from k₁ that
16
+ // way. Two refinements keep "every member is supported by some key declaration" true where the
17
+ // review set is more than what the target reaches through its members:
14
18
  //
15
- // - a declaration of the project in the target's TCB that is trusted, by module or by name (a layer
16
- // reviewed elsewhere), is not a member, but what it uses may be: the walk passes through it as
17
- // through a member that is not key (the outside world never uses the project, so nothing else
18
- // outside the set can lead back into it);
19
+ // - a declaration of the target's TCB that is trusted, by module or by name (a layer reviewed
20
+ // elsewhere, or the outside world), is not a member, but what it uses may be, and it may be key:
21
+ // the walk passes through it as through a member that is not key. Through the outside world only
22
+ // where something there is key or needs review: the outside world never uses the project, so
23
+ // nothing else there can lead back to a key declaration or a member;
19
24
  // - a non-standard axiom the target rests on only through a proof is a member that no statement or
20
25
  // body reaches: it is the target's support, as `viaProof` says.
21
26
  //
@@ -23,31 +28,47 @@
23
28
  // target's TCB, each walk reads the edges of the members and of what it passes through, never the
24
29
  // whole graph's (Sphere-Packing-Lean's `Dim24.MainTheorem`: its TCB of 226 in 72 ms, its keys in 1 ms).
25
30
  import { keyMarks, statusOf } from "./review.js";
26
- import { TCB_SITES } from "./reviewqueue.js";
27
- /** The key declarations of `root` among the members of its review (`order`, the queue's order —
28
- * shared/reviewqueue.ts), in that order: the target, and each member marked key. A mark on
29
- * a declaration that has left the review (now trusted, or no longer in the TCB) is kept in the
30
- * review but counts for nothing until it is back. */
31
- export function keySet(g, d, root, order) {
31
+ import { dependencyOrder, TCB_SITES } from "./reviewqueue.js";
32
+ /** The key declarations of `root`: the target, and each declaration marked key for it that its TCB
33
+ * (`tcb`, statement and body reach) or its review set (`order`, the members in the queue's order —
34
+ * shared/reviewqueue.ts) holds, trusted or not (ExportSpec decision 1). In order: the trusted ones
35
+ * first, in dependency order among themselves; then those of the review set in review order; the
36
+ * target last, whether it needs review or not. A mark on a declaration that has left the TCB is
37
+ * kept in the review but counts for nothing until it is back; one on a declaration trusted since
38
+ * stays, trusted. */
39
+ export function keySet(g, d, root, order, tcb = g.reach([root], TCB_SITES, "out")) {
32
40
  const marked = new Set(keyMarks(d, g.nodes[root].name));
33
- return order.filter((i) => i === root || marked.has(g.nodes[i].name));
41
+ const member = new Set(order);
42
+ const trusted = [];
43
+ for (const name of marked) {
44
+ const i = g.byName.get(name);
45
+ if (i !== undefined && i !== root && tcb[i] && !member.has(i))
46
+ trusted.push(i);
47
+ }
48
+ return [...dependencyOrder(g, trusted), ...order.filter((i) => i !== root && marked.has(g.nodes[i].name)), root];
49
+ }
50
+ /** `root`'s key declarations (keySet) and those of them that need no review, without walking the key
51
+ * graph: what counting them needs (keyCounts). */
52
+ export function keyParts(g, d, root, order, tcb) {
53
+ const keys = keySet(g, d, root, order, tcb);
54
+ const member = new Set(order);
55
+ return { keys, trusted: keys.filter((k) => !member.has(k)) };
34
56
  }
35
- /** `root`'s key graph over its review: `order` is the review's members in review order (the
36
- * queue's `order`). */
57
+ /** `root`'s key graph over its TCB: `order` is the review's members in review order (the queue's
58
+ * `order`). */
37
59
  export function keyGraph(g, d, root, order) {
38
- const keys = keySet(g, d, root, order);
39
- // the target is always key, also where the review does not hold it (a test, a graph read again)
40
- if (!keys.includes(root))
41
- keys.push(root);
60
+ const tcb = g.reach([root], TCB_SITES, "out");
61
+ const { keys, trusted } = keyParts(g, d, root, order, tcb);
42
62
  const keyAt = new Map();
43
63
  keys.forEach((k, j) => keyAt.set(k, j));
44
64
  const position = new Map();
45
65
  order.forEach((i, k) => position.set(i, k));
46
66
  const member = (v) => position.has(v);
47
- // what a walk may pass through besides members: the project's own declarations in the target's
48
- // TCB that are not members, which only a trusted prefix keeps out of the review
49
- const tcb = g.reach([root], TCB_SITES, "out");
50
- const passable = (v) => member(v) || (tcb[v] === 1 && !g.isExt(v));
67
+ // what a walk may pass through besides members: the declarations of the target's TCB that are not
68
+ // members, which only trust keeps out of the review — the outside world's only where something
69
+ // there is key or a member, since nothing outside leads back into the project
70
+ const outside = keys.some((k) => g.isExt(k)) || order.some((i) => g.isExt(i));
71
+ const passable = (v) => member(v) || (tcb[v] === 1 && (outside || !g.isExt(v)));
51
72
  const supporters = new Map();
52
73
  const support = keys.map(() => []);
53
74
  const edges = new Set();
@@ -101,12 +122,19 @@ export function keyGraph(g, d, root, order) {
101
122
  return {
102
123
  root,
103
124
  keys,
125
+ trusted,
104
126
  supporters,
105
127
  support,
106
128
  edges: [...edges].sort((a, b) => a - b).map((x) => [Math.floor(x / K), x % K]),
107
129
  viaProof,
108
130
  };
109
131
  }
132
+ /** How `kg`'s key declarations stand (ExportSpec decision 4): those that need review by people's
133
+ * status; the trusted ones counted apart. */
134
+ export function keyCounts(g, d, kg) {
135
+ const trusted = new Set(kg.trusted);
136
+ return { ...statusCounts(g, d, kg.keys.filter((k) => !trusted.has(k))), trusted: trusted.size };
137
+ }
110
138
  /** The key graph's edges to draw while the tool is the Keys step of Rests on and something is lit
111
139
  * (ViewSpec decision 20): of each key graph given — the focus's target's, or elsewhere every
112
140
  * target's, which makes the union over the targets whose key declarations are lit — the edges
@@ -140,11 +168,12 @@ export function statusCounts(g, d, xs) {
140
168
  }
141
169
  return c;
142
170
  }
143
- /** The review's order with its key declarations first (ExportSpec decision 4): the key ones in
144
- * review order, then the rest in review order — how the agents' API lists a review set with
145
- * `key=first`. */
146
- export function keyFirst(order, isKey) {
147
- return [...order.filter(isKey), ...order.filter((i) => !isKey(i))];
171
+ /** The review's order with its key declarations first (ExportSpec decision 4): the key ones, `keys`
172
+ * in their order (keySet: the trusted ones first, then the review's in review order), then the rest
173
+ * of the review in review order — how the agents' API lists a review set with `key=first`. */
174
+ export function keyFirst(order, keys) {
175
+ const isKey = new Set(keys);
176
+ return [...keys, ...order.filter((i) => !isKey.has(i))];
148
177
  }
149
178
  /** The key graph's layers, top-down (an index per key declaration, into `kg.keys`): the target at
150
179
  * 0, each other one a layer below every key declaration that rests on it — the longest path from
@@ -65,6 +65,7 @@ export function lostEntries(d, views, has, known = (n) => n.includes("."), pinWh
65
65
  name,
66
66
  ...who(o),
67
67
  ...(o.recordedBy ? { recordedBy: o.recordedBy } : {}),
68
+ ...(o.withdrawn ? { withdrawn: o.withdrawn } : {}),
68
69
  verdict: o.verdict,
69
70
  ...(o.comment ? { comment: o.comment } : {}),
70
71
  ...(was.length ? { aliases: was.map((n) => lostKey.opinion(name, n, o.at)) } : {}),
@@ -0,0 +1,83 @@
1
+ // Mentions (CollabSpec decision 13, the owner's decision of 2026-10-19): `@` and a name in a message,
2
+ // the name of a person or of an agent as it is listed. The server reads them as a message is written
3
+ // (server/talk.ts): a person's mention of an agent hands the message to that agent, an agent's is
4
+ // shown and never handed. The page completes one as it is typed, from the people online and the
5
+ // agents listed, and marks the reader's own.
6
+ //
7
+ // Names may hold spaces ("Alice's AI"), so a mention is not a word: it is read against the names it
8
+ // may be, the longest that fits first, compared as names are (shared/collab.ts, sameName), and only
9
+ // where nothing of a name goes on after it (`@Al` is not `@Alice`). An `@` inside a word (an address,
10
+ // alice@example.org) mentions nobody.
11
+ import { MAX_NAME, nameKey, sameName } from "./collab.js";
12
+ /** what a name goes on with: after a mention there is none of it, and before its `@` neither */
13
+ const WORDY = /[\p{L}\p{N}_]/u;
14
+ /** The mentions in `text` of the names `names`, in order: at each `@` that starts a word, the
15
+ * longest of the names written there. */
16
+ export function mentionsIn(text, names) {
17
+ const sorted = [...new Set(names)].filter((n) => n.trim() !== "").sort((a, b) => b.length - a.length);
18
+ const out = [];
19
+ if (!sorted.length)
20
+ return out;
21
+ for (let i = text.indexOf("@"); i >= 0; i = text.indexOf("@", i + 1)) {
22
+ if (i > 0 && WORDY.test(text[i - 1]))
23
+ continue;
24
+ const rest = text.slice(i + 1, i + 1 + MAX_NAME + 1);
25
+ if (!rest || /^\s/.test(rest))
26
+ continue;
27
+ for (const n of sorted) {
28
+ const piece = rest.slice(0, n.length);
29
+ if (piece.length === n.length && sameName(piece, n) && !WORDY.test(rest[n.length] ?? "")) {
30
+ out.push({ name: n, start: i, end: i + 1 + n.length });
31
+ i += n.length;
32
+ break;
33
+ }
34
+ }
35
+ }
36
+ return out;
37
+ }
38
+ /** The names `text` mentions, each once, in the order first mentioned. */
39
+ export function mentioned(text, names) {
40
+ const out = [];
41
+ for (const m of mentionsIn(text, names))
42
+ if (!out.some((x) => sameName(x, m.name)))
43
+ out.push(m.name);
44
+ return out;
45
+ }
46
+ /** The mention being typed just before `caret`: where its `@` is, and what follows it so far (one
47
+ * line, a name's length at most); null where none is being typed. */
48
+ export function typingMention(text, caret) {
49
+ const before = text.slice(Math.max(0, caret - MAX_NAME - 1), caret);
50
+ const at = before.lastIndexOf("@");
51
+ if (at < 0)
52
+ return null;
53
+ const start = caret - before.length + at;
54
+ if (start > 0 && WORDY.test(text[start - 1]))
55
+ return null;
56
+ const query = before.slice(at + 1);
57
+ if (/[\n@]/.test(query) || /^\s/.test(query))
58
+ return null;
59
+ return { start, query };
60
+ }
61
+ /** The names that complete `query`, at most `max`: those that start with it first, then those with a
62
+ * word that does; people before agents, each in the order given. */
63
+ export function completions(query, names, max = 8) {
64
+ const q = nameKey(query);
65
+ const seen = new Set();
66
+ const first = [], then = [];
67
+ for (const n of names) {
68
+ const k = nameKey(n.name);
69
+ if (!k || seen.has(k))
70
+ continue;
71
+ seen.add(k);
72
+ if (k.startsWith(q))
73
+ first.push(n);
74
+ else if (q && k.split(/[\s.'’-]+/).some((w) => w.startsWith(q)))
75
+ then.push(n);
76
+ }
77
+ const people = (xs) => [...xs.filter((x) => !x.agent), ...xs.filter((x) => x.agent)];
78
+ return [...people(first), ...people(then)].slice(0, max);
79
+ }
80
+ /** Whether `text` mentions `name` (the reader's, say): one of its mentions is of that name. */
81
+ export function mentions(text, name, names = [name]) {
82
+ return mentionsIn(text, [...names, name]).some((m) => sameName(m.name, name));
83
+ }
@@ -63,7 +63,7 @@ export const QUERY_LIMITS = {
63
63
  /** characters of one name or prefix */
64
64
  name: 2_000,
65
65
  /** closures (tcb, uses, usedBy, refs), each a walk of the graph; each target of a `key(…)` counts as
66
- * one too, since its review set is walked to keep only the marks still in it. `key(targets)`
66
+ * one too, since its TCB is walked to keep only the marks still in it (keyScope). `key(targets)`
67
67
  * counts as one: how many targets there are is the project's, not the query's, and every
68
68
  * `key(targets)` of a query shares the same walks (evaluateIn) */
69
69
  closures: 64,
@@ -590,6 +590,15 @@ export function reviewScope(target) {
590
590
  { op: "or", q: axioms },
591
591
  ]);
592
592
  }
593
+ /** What can be key for a target (ExportSpec decision 1, the owner's decision of 2026-10-19): a
594
+ * member of its TCB, trusted or not, in the project or outside it, or of its review set — a
595
+ * non-standard axiom it rests on through proofs alone: `tcb(T) or (uses(T) and kind(axiom) and
596
+ * nonstandard)`. It reads nothing of the review: no trust changes it, so that a key declaration
597
+ * trusted since it was marked stays key. */
598
+ export function keyScope(target) {
599
+ const axioms = { op: "and", a: { op: "and", a: { op: "uses", of: [target] }, b: { op: "kind", kinds: ["axiom"] } }, b: { op: "nonstandard" } };
600
+ return { op: "or", a: { op: "tcb", of: [target] }, b: axioms };
601
+ }
593
602
  /** What the Keys step of Rests on selects (ViewSpec decision 20): what was clicked — a declaration,
594
603
  * or the set a cluster holds — and the key declarations in its TCB, of the targets `keys` names
595
604
  * (`targets`: every target). That is `decl(X) or (tcb(X) and key(T…))`, written
@@ -748,8 +757,8 @@ function evaluateIn(q, ctx, walks) {
748
757
  out[i] = 1;
749
758
  return out;
750
759
  case "key":
751
- // each target, and what was marked key for it that its review still holds (its Review
752
- // view's set, shared/reviewqueue.ts): a mark on what has left the review counts for nothing
760
+ // each target, and what was marked key for it that its TCB or review set still holds, trusted
761
+ // or not (keyScope): a mark on what has left them counts for nothing
753
762
  for (const t of q.of === "targets" ? Object.keys(d.targets) : q.of) {
754
763
  const root = g.byName.get(t);
755
764
  if (root === undefined)
@@ -758,7 +767,7 @@ function evaluateIn(q, ctx, walks) {
758
767
  const marks = keyMarks(d, t).map((x) => g.byName.get(x)).filter((i) => i !== undefined);
759
768
  if (!marks.length)
760
769
  continue;
761
- const set = evaluateIn(reviewScope(t), ctx, walks);
770
+ const set = evaluateIn(keyScope(t), ctx, walks);
762
771
  for (const i of marks)
763
772
  if (set[i])
764
773
  out[i] = 1;
@@ -33,6 +33,13 @@
33
33
  // stands at a build. A log may still hold such a line: the replay skips it (`readEvent`) without
34
34
  // calling it a problem, so that its writer writes on.
35
35
  //
36
+ // Since 2026-10-19 a reviewer may withdraw their current opinion (ReviewSpec decision 9, the owner's
37
+ // decision of 2026-10-19): a `withdraw` line, appended like any, never an erasure. The replay marks
38
+ // the opinion it takes back (`withdrawn`), which stays in the declaration's history; `current` and
39
+ // `advice`, and so every status, count and queue, read its author as having no opinion there, their
40
+ // earlier ones not restored. An agent withdraws its own advice alone, and a person may withdraw the
41
+ // opinion of the person they speak for, as recording one (decision 8).
42
+ //
36
43
  // Since 2026-10-09 a move (HistorySpec.md) carries what was said of one declaration to another, and
37
44
  // says where one is another renamed: shared/moves.ts replays it. Since 2026-10-11 the library's
38
45
  // files and the links into them are events too (AttachmentSpec.md): shared/library.ts replays them.
@@ -103,10 +110,11 @@ export function invalid(r) {
103
110
  return "agent";
104
111
  if (o.person !== undefined && (!validPersonId(o.person) || o.agent))
105
112
  return "person";
106
- // an opinion recorded for someone else (ReviewSpec decision 8): a person's, for another person
113
+ // an opinion recorded for someone else (ReviewSpec decision 8), or withdrawn for them (decision
114
+ // 9): a person's, for another person
107
115
  if (o.for !== undefined || o.forPerson !== undefined) {
108
- if (o.op !== "opinion")
109
- return "only an opinion is recorded for someone else";
116
+ if (o.op !== "opinion" && o.op !== "withdraw")
117
+ return "only an opinion, or its withdrawal, is recorded for someone else";
110
118
  if (o.agent)
111
119
  return "an agent records for no one";
112
120
  if (typeof o.for !== "string" || !validName(o.for.trim()))
@@ -133,6 +141,8 @@ export function invalid(r) {
133
141
  if (o.text !== undefined && o.statement !== undefined)
134
142
  return "a text or a statement, not both";
135
143
  return null;
144
+ case "withdraw":
145
+ return null;
136
146
  case "target":
137
147
  return typeof o.on === "boolean" ? null : "on";
138
148
  case "trust":
@@ -189,6 +199,18 @@ export function eventOf(d, r, toolchain, now) {
189
199
  }
190
200
  return e;
191
201
  }
202
+ case "withdraw": {
203
+ const e = { op: "withdraw", at: now, by, ...person, name: r.name };
204
+ // withdrawn for someone else (ReviewSpec decision 9)
205
+ if (r.for?.trim()) {
206
+ e.for = r.for.trim();
207
+ if (r.forPerson)
208
+ e.forPerson = r.forPerson;
209
+ }
210
+ if (r.agent)
211
+ e.agent = true;
212
+ return e;
213
+ }
192
214
  case "target":
193
215
  return { op: "target", at: now, by, ...person, name: r.name, on: r.on, ...agent };
194
216
  case "trust":
@@ -236,6 +258,18 @@ export function applyEvent(d, e) {
236
258
  (Object.hasOwn(d.opinions, name) ? d.opinions[name] : (d.opinions[name] = [])).push(forName === undefined ? o : recordedFor(d, o, forName, forPerson));
237
259
  return;
238
260
  }
261
+ case "withdraw": {
262
+ // the latest opinion of theirs, as `current` reads it, unless withdrawn already: marked, kept
263
+ // where it is (ReviewSpec decision 9); a line with nothing to take back does nothing
264
+ const ops = Object.hasOwn(d.opinions, e.name) ? d.opinions[e.name] : null;
265
+ const whose = voice(e);
266
+ const k = ops ? ops.findLastIndex((o) => author(o) === whose) : -1;
267
+ if (!ops || k < 0 || ops[k].withdrawn)
268
+ return;
269
+ const by = e.for === undefined ? {} : { recordedBy: { by: e.by, ...person } };
270
+ ops[k] = { ...ops[k], withdrawn: { at: e.at, ...by } };
271
+ return;
272
+ }
239
273
  case "target":
240
274
  if (!e.on)
241
275
  delete d.targets[e.name];
@@ -296,6 +330,8 @@ function named(d, id, name) {
296
330
  o.by = name;
297
331
  if (o.recordedBy?.person === id)
298
332
  o.recordedBy.by = name;
333
+ if (o.withdrawn?.recordedBy?.person === id)
334
+ o.withdrawn.recordedBy.by = name;
299
335
  }
300
336
  for (const t of Object.values(d.targets))
301
337
  if (t.person === id)
@@ -320,7 +356,8 @@ export function record(d, r, toolchain, now) {
320
356
  return e;
321
357
  }
322
358
  /** Whether recording `r` would change nothing: a target marked that is one, a prefix trusted that
323
- * is, a key declaration marked that is. Such a request is answered, and nothing is appended. */
359
+ * is, a key declaration marked that is, a withdrawal with no opinion standing to take back. Such a
360
+ * request is answered, and nothing is appended. */
324
361
  export function noChange(d, r) {
325
362
  if (r.op === "target")
326
363
  return Object.hasOwn(d.targets, r.name) === r.on;
@@ -328,6 +365,9 @@ export function noChange(d, r) {
328
365
  return d.trusted.includes(r.prefix) === r.on;
329
366
  if (r.op === "key")
330
367
  return keyMarked(d, r.target, r.name) === r.on;
368
+ // nothing standing to take back (ReviewSpec decision 9)
369
+ if (r.op === "withdraw")
370
+ return !standing(d, r.name, r.for?.trim() ? { by: r.for.trim(), ...(r.forPerson ? { person: r.forPerson } : {}) } : { by: r.by.trim(), agent: r.agent, person: r.person });
331
371
  if (r.op === "move")
332
372
  return moveIsIdle(d, { ...r, rename: r.rename || undefined });
333
373
  if (isLibraryOp(r.op))
@@ -384,19 +424,23 @@ export function readEvent(raw, agentLog, personLog = null) {
384
424
  if (e.text !== undefined && e.statement !== undefined)
385
425
  return "a text and a statement";
386
426
  // recorded for someone else (ReviewSpec decision 8): a person's line, for another person
387
- if (o.for !== undefined || o.forPerson !== undefined) {
388
- if (agentLog)
389
- return "an agent's opinion recorded for someone else";
390
- if (typeof o.for !== "string" || !validName(o.for))
391
- return "for";
392
- if (o.forPerson !== undefined && !validPersonId(o.forPerson))
393
- return "forPerson";
394
- if (o.for === by || (o.forPerson !== undefined && o.forPerson === personLog))
395
- return "an opinion recorded for its own writer";
396
- e.for = o.for;
397
- if (o.forPerson !== undefined)
398
- e.forPerson = o.forPerson;
399
- }
427
+ const f = readFor(o, by, agentLog, personLog);
428
+ if (typeof f === "string")
429
+ return f;
430
+ Object.assign(e, f);
431
+ if (agentLog)
432
+ e.agent = true;
433
+ return e;
434
+ }
435
+ case "withdraw": {
436
+ if (!str(o.name, 2000))
437
+ return "name";
438
+ const e = { op: "withdraw", at, by, ...person, name: o.name };
439
+ // withdrawn for someone else (ReviewSpec decision 9), as an opinion is recorded for them
440
+ const f = readFor(o, by, agentLog, personLog);
441
+ if (typeof f === "string")
442
+ return f;
443
+ Object.assign(e, f);
400
444
  if (agentLog)
401
445
  e.agent = true;
402
446
  return e;
@@ -423,6 +467,22 @@ export function readEvent(raw, agentLog, personLog = null) {
423
467
  return isLibraryOp(o.op) ? readLibraryEvent(o, at, by, agentLog, personLog) : "op";
424
468
  }
425
469
  }
470
+ /** Whom a line of an opinion or of a withdrawal is for, where it is another person's (ReviewSpec
471
+ * decisions 8 and 9): `for` and `forPerson` as read, none, or why the line cannot be read — an
472
+ * agent's line for anyone, a line for its own writer. */
473
+ function readFor(o, by, agentLog, personLog) {
474
+ if (o.for === undefined && o.forPerson === undefined)
475
+ return {};
476
+ if (agentLog)
477
+ return o.op === "withdraw" ? "an agent's withdrawal for someone else" : "an agent's opinion recorded for someone else";
478
+ if (typeof o.for !== "string" || !validName(o.for))
479
+ return "for";
480
+ if (o.forPerson !== undefined && !validPersonId(o.forPerson))
481
+ return "forPerson";
482
+ if (o.for === by || (o.forPerson !== undefined && o.forPerson === personLog))
483
+ return o.op === "withdraw" ? "a withdrawal for its own writer" : "an opinion recorded for its own writer";
484
+ return { for: o.for, ...(o.forPerson !== undefined ? { forPerson: o.forPerson } : {}) };
485
+ }
426
486
  /** Every log merged into one sequence: one writer's events in the order of their file, different
427
487
  * writers' by time; at the same time, by file name (the same on every replica, so every server
428
488
  * replays the same). A writer's clock going backwards keeps their order and delays nobody else's
@@ -549,9 +609,18 @@ export function problemsText(ps) {
549
609
  function author(o) {
550
610
  return o.person ? `link ${o.person}` : (o.agent ? "agent " : "person ") + o.by;
551
611
  }
552
- /** Whose an opinion line is: theirs it was recorded for (ReviewSpec decision 8), else its writer's. */
612
+ /** Whose a line of an opinion or a withdrawal is: theirs it was recorded for (ReviewSpec decisions 8
613
+ * and 9), else its writer's. */
553
614
  function voice(e) {
554
- return e.for === undefined ? author(e) : author({ by: e.for, verdict: e.verdict, at: e.at, ...(e.forPerson ? { person: e.forPerson } : {}) });
615
+ return e.for === undefined ? author(e) : author({ by: e.for, ...(e.forPerson ? { person: e.forPerson } : {}) });
616
+ }
617
+ /** The opinion of `who` on `name` that a withdrawal would take back (ReviewSpec decision 9): their
618
+ * latest, people's or an agent's, stale or not, unless it is withdrawn already; null where they
619
+ * have none standing. */
620
+ export function standing(d, name, who) {
621
+ const whose = author(who);
622
+ const o = (Object.hasOwn(d.opinions, name) ? d.opinions[name] : []).findLast((p) => author(p) === whose);
623
+ return o && !o.withdrawn ? o : null;
555
624
  }
556
625
  /** An opinion recorded for someone else (ReviewSpec decision 8), as the review holds it: theirs —
557
626
  * under their latest name where they are invited — saying who recorded it. */
@@ -561,14 +630,15 @@ function recordedFor(d, o, forName, forPerson) {
561
630
  return { ...rest, by: name, ...(forPerson ? { person: forPerson } : {}), recordedBy: { by, ...(person ? { person } : {}) } };
562
631
  }
563
632
  /** Each author's latest opinion on a declaration, people's or agents': a new one replaces their
564
- * earlier one. */
633
+ * earlier one; one withdrawn leaves its author none, their earlier ones not restored (ReviewSpec
634
+ * decision 9). */
565
635
  function latest(d, name, agents) {
566
636
  const out = new Map();
567
637
  // own keys only: a declaration may be called `constructor` or `toString`
568
638
  for (const o of Object.hasOwn(d.opinions, name) ? d.opinions[name] : [])
569
639
  if (!!o.agent === agents)
570
640
  out.set(author(o), o);
571
- return [...out.values()];
641
+ return [...out.values()].filter((o) => !o.withdrawn);
572
642
  }
573
643
  /** Each reviewer's latest opinion on a declaration: a new one replaces their earlier one. People
574
644
  * only: an agent's opinion is advice, and nothing read off this counts it. */
@@ -16,7 +16,7 @@
16
16
  import { SITE_BODY, SITE_STMT } from "./graph.js";
17
17
  import { current, fresh, STANDARD_AXIOMS, statusOf, trusted } from "./review.js";
18
18
  import { ALL_SITES } from "./viewgraph.js";
19
- import { evaluate, reviewScope } from "./query.js";
19
+ import { evaluate, keyScope, reviewScope } from "./query.js";
20
20
  /** The references a TCB follows: in statements and bodies, never inside a proof. */
21
21
  export const TCB_SITES = SITE_STMT | SITE_BODY;
22
22
  /** In how many of the targets' TCBs each declaration is. */
@@ -58,6 +58,11 @@ export function trustSplit(g, d, s, skip = -1) {
58
58
  export function reviewSet(g, d, root) {
59
59
  return evaluate(reviewScope(g.nodes[root].name), { g, review: d });
60
60
  }
61
+ /** What can be key for `root` (`keyScope`, ExportSpec decision 1): its TCB, trusted members
62
+ * included, and its review set, in the graph's numbering. No trust changes it. */
63
+ export function keyableSet(g, d, root) {
64
+ return evaluate(keyScope(g.nodes[root].name), { g, review: d });
65
+ }
61
66
  const VIA = 8;
62
67
  /** The non-standard axioms `root` rests on, through statements, bodies or proofs: those the axiom
63
68
  * sets of what it reaches name (the extractor's, through everything), and those it reaches as