visualproof 0.5.0 → 0.7.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 (107) hide show
  1. package/README.md +2 -2
  2. package/dist/assets/tips/phone-fingers.light.mp4 +0 -0
  3. package/dist/assets/tips/phone-fingers.light.webp +0 -0
  4. package/dist/assets/tips/tour-agent.webp +0 -0
  5. package/dist/assets/tips/tour-arrange.webp +0 -0
  6. package/dist/assets/tips/tour-artwork.webp +0 -0
  7. package/dist/assets/tips/tour-checks.webp +0 -0
  8. package/dist/assets/tips/tour-keys.webp +0 -0
  9. package/dist/assets/tips/tour-library.webp +0 -0
  10. package/dist/assets/tips/tour-project.webp +0 -0
  11. package/dist/assets/tips/tour-review.webp +0 -0
  12. package/dist/assets/tips/tour-share.webp +0 -0
  13. package/dist/assets/tips/tour-source.webp +0 -0
  14. package/dist/assets/tips/tour-target.webp +0 -0
  15. package/dist/assets/tips/tour-view.webp +0 -0
  16. package/dist/assets/tips/tour.json +125 -115
  17. package/dist/assets/tips/tour.webp +0 -0
  18. package/dist/extractor/Extract.lean +13 -3
  19. package/dist/mcp/visualproof-mcp.mjs +20 -9
  20. package/dist/server/access.js +28 -0
  21. package/dist/server/agent.js +130 -2819
  22. package/dist/server/agentactivity.js +72 -0
  23. package/dist/server/agentadvice.js +115 -0
  24. package/dist/server/agentdocs.js +1 -1
  25. package/dist/server/agententry.js +180 -0
  26. package/dist/server/agentexport.js +469 -0
  27. package/dist/server/agentfollow.js +384 -0
  28. package/dist/server/agentgraph.js +128 -0
  29. package/dist/server/agentlean.js +144 -0
  30. package/dist/server/agentlibrary.js +1 -1
  31. package/dist/server/agentplaces.js +242 -0
  32. package/dist/server/agentread.js +569 -0
  33. package/dist/server/agenttalk.js +282 -0
  34. package/dist/server/agenttcb.js +378 -0
  35. package/dist/server/agentviews.js +2 -2
  36. package/dist/server/app.js +377 -0
  37. package/dist/server/appaccess.js +127 -0
  38. package/dist/server/appagent.js +110 -0
  39. package/dist/server/appgraph.js +176 -0
  40. package/dist/server/appshare.js +179 -0
  41. package/dist/server/appsite.js +120 -0
  42. package/dist/server/apptalk.js +178 -0
  43. package/dist/server/artcmd.js +1 -1
  44. package/dist/server/askfollow.js +1 -1
  45. package/dist/server/deploy.js +204 -53
  46. package/dist/server/events.js +1 -1
  47. package/dist/server/history.js +51 -3
  48. package/dist/server/historyapi.js +34 -2
  49. package/dist/server/hover.js +11 -7
  50. package/dist/server/identity.js +1 -1
  51. package/dist/server/invites.js +113 -20
  52. package/dist/server/libraryroute.js +3 -3
  53. package/dist/server/live.js +186 -30
  54. package/dist/server/main.js +31 -1613
  55. package/dist/server/mcptools.js +33 -20
  56. package/dist/server/options.js +350 -0
  57. package/dist/server/outside.js +311 -0
  58. package/dist/server/pastdoc.js +22 -3
  59. package/dist/server/presence.js +3 -3
  60. package/dist/server/project.js +28 -4
  61. package/dist/server/prompt.js +8 -3
  62. package/dist/server/readonlygate.js +4 -4
  63. package/dist/server/reviewapi.js +51 -17
  64. package/dist/server/send.js +259 -0
  65. package/dist/server/talk.js +238 -116
  66. package/dist/server/tokens.js +13 -5
  67. package/dist/server/view.js +3 -1
  68. package/dist/server/views.js +1 -1
  69. package/dist/shared/artrecipe.js +3 -3
  70. package/dist/shared/build.js +35 -1
  71. package/dist/shared/collab.js +9 -1
  72. package/dist/shared/comment.js +1 -1
  73. package/dist/shared/doc/build.js +30 -14
  74. package/dist/shared/doc/latex.js +7 -2
  75. package/dist/shared/doc/model.js +4 -2
  76. package/dist/shared/doc/sections.js +21 -4
  77. package/dist/shared/keys.js +66 -37
  78. package/dist/shared/lostfound.js +1 -0
  79. package/dist/shared/mentions.js +83 -0
  80. package/dist/shared/outside.js +16 -0
  81. package/dist/shared/pastgraph.js +11 -2
  82. package/dist/shared/query.js +13 -4
  83. package/dist/shared/review.js +91 -21
  84. package/dist/shared/reviewqueue.js +6 -1
  85. package/dist/shared/scope.js +1 -1
  86. package/dist/web/bundle/app.js +51289 -49853
  87. package/dist/web/index.html +45 -9
  88. package/dist/web/src/reviewqueue.js +52 -19
  89. package/dist/web/src/selection.js +1 -1
  90. package/dist/web/src/theme.js +1 -1
  91. package/dist/web/src/trust.js +271 -0
  92. package/dist/web/src/visitors.js +1 -1
  93. package/dist/web/style.css +181 -70
  94. package/docs/agent-api/README.md +13 -11
  95. package/docs/agent-api/advice.md +8 -2
  96. package/docs/agent-api/export.md +9 -6
  97. package/docs/agent-api/following.md +11 -12
  98. package/docs/agent-api/history.md +6 -3
  99. package/docs/agent-api/mcp.md +15 -15
  100. package/docs/agent-api/notes.md +1 -1
  101. package/docs/agent-api/reading.md +10 -4
  102. package/docs/agent-api/requests.md +12 -15
  103. package/docs/agent-api/talking.md +60 -55
  104. package/docs/agent-api/tcb.md +21 -21
  105. package/docs/agent-api/views.md +3 -4
  106. package/docs/agent-api/words.md +8 -8
  107. package/package.json +2 -1
@@ -64,6 +64,17 @@
64
64
  <svg viewBox="0 0 16 16" width="15" height="15" aria-hidden="true"><path d="M2 8h2.5l1.5-4 3 8 1.5-4H14"/></svg>
65
65
  <span id="activity-badge" class="act-badge" hidden></span>
66
66
  </button>
67
+ <!-- the conversations (CollabSpec decision 13, web/src/talk.ts): opens and closes the reader's
68
+ own conversation window; counts what they have not seen of Everyone, marked where they are
69
+ mentioned or one of their agents answered; a mention's notice under it -->
70
+ <div class="talk-wrap">
71
+ <button id="talk-btn" class="act-btn act-icon" title="Conversations: everyone on this page, and your agents" aria-label="Conversations" aria-pressed="false" hidden>
72
+ <svg viewBox="0 0 16 16" width="15" height="15" aria-hidden="true"><path d="M3.2 3h9.6c.7 0 1.2.5 1.2 1.2v5.6c0 .7-.5 1.2-1.2 1.2H7.6L4.6 13.4V11H3.2C2.5 11 2 10.5 2 9.8V4.2C2 3.5 2.5 3 3.2 3z"/></svg>
73
+ <span id="talk-badge" class="act-badge" hidden></span>
74
+ <span id="talk-at" class="talk-at" aria-hidden="true" hidden>@</span>
75
+ </button>
76
+ <button id="talk-notice" class="glass" type="button" hidden></button>
77
+ </div>
67
78
  <!-- the others' initials: a person's opens their menu, to follow them or ask them to follow
68
79
  you; under them, what your request to follow came to (web/src/peermenu.ts,
69
80
  web/src/askfollow.ts) -->
@@ -83,9 +94,10 @@
83
94
  <button id="help-btn" class="help-btn" title="Help: tips, keys, the tour (?)" aria-label="Help" aria-haspopup="menu" aria-expanded="false">?</button>
84
95
  <div id="help-menu" class="glass" role="menu" aria-label="Help" hidden></div>
85
96
  </div>
86
- <!-- on a phone the bar's buttons are in one menu (web/src/phone.ts) -->
97
+ <!-- on a phone the bar's buttons are in one menu, what is new under it on it: Activity's count
98
+ and the conversations', their mark (web/src/phone.ts) -->
87
99
  <div class="more-wrap">
88
- <button id="more-btn" class="act-btn act-icon" aria-label="More" aria-haspopup="menu" aria-expanded="false" title="Share, the library, export, activity, your name, help"><svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><circle cx="3.5" cy="8" r="1.3"/><circle cx="8" cy="8" r="1.3"/><circle cx="12.5" cy="8" r="1.3"/></svg><span id="more-badge" class="act-badge" hidden></span></button>
100
+ <button id="more-btn" class="act-btn act-icon" aria-label="More" aria-haspopup="menu" aria-expanded="false" title="Share, the library, export, activity, the conversations, your name, help"><svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><circle cx="3.5" cy="8" r="1.3"/><circle cx="8" cy="8" r="1.3"/><circle cx="12.5" cy="8" r="1.3"/></svg><span id="more-badge" class="act-badge" hidden></span><span id="more-at" class="talk-at" aria-hidden="true" hidden>@</span></button>
89
101
  <div id="more-pop" class="glass" role="menu" aria-label="More" hidden></div>
90
102
  </div>
91
103
  </div>
@@ -216,14 +228,36 @@
216
228
  <!-- the canvas's menu: a right click, the ContextMenu key or Shift+F10 (web/src/ctxmenu.ts) -->
217
229
  <div id="ctxmenu" role="menu" aria-label="Actions" tabindex="-1" hidden></div>
218
230
  <!-- the floating windows, the one pressed or focused last in front (web/src/floatwin.ts): the
219
- source windows (web/src/sourcewin.ts adds each) and the following strip -->
231
+ source windows (web/src/sourcewin.ts adds each); the conversation window in front of them all,
232
+ always (ReviewSpec, "In front"); the following strip -->
220
233
  <div id="windows">
221
- <!-- following someone: the strip; following an agent that can be talked to, a window with the
222
- strip as its title bar, the conversation, and the pill it collapses to (web/src/people.ts,
223
- web/src/talk.ts, web/src/chatwin.ts, which adds the edges that resize it) -->
224
- <div id="following" class="glass" hidden>
225
- <div class="fl-strip"></div><div id="talk" hidden></div>
226
- <div class="fl-pill"><button class="fl-pill-open" type="button"><span class="fl-pill-text"></span><span class="fl-new" title="A new reply"></span></button><button data-unfollow type="button" title="Stop following" aria-label="Stop following">✕</button></div>
234
+ <!-- following someone: the strip, whom and its ✕ (web/src/people.ts) -->
235
+ <div id="following" class="glass" hidden><div class="fl-strip"></div></div>
236
+ <!-- the conversation window, the reader's own (CollabSpec decision 13): its channels at its head,
237
+ the thread, the agent's state, the box, and the pill it collapses to (web/src/chatwin.ts,
238
+ which adds the edges that resize it; web/src/talk.ts; web/src/chatinput.ts) -->
239
+ <div id="convo" class="glass" role="region" aria-label="Conversations" hidden>
240
+ <div class="cv-head">
241
+ <div class="cv-tabs" role="tablist" aria-label="Channels"></div>
242
+ <button data-cv-new type="button" aria-label="New conversation" hidden><svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="M3.2 2.8h9.6c.7 0 1.2.5 1.2 1.2v6.2c0 .7-.5 1.2-1.2 1.2H7.4L4.5 13.8v-2.4H3.2c-.7 0-1.2-.5-1.2-1.2V4c0-.7.5-1.2 1.2-1.2z" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linejoin="round"/><path d="M8 4.9v4.2M5.9 7h4.2" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/></svg></button>
243
+ <button data-collapse type="button" title="Collapse to one line (or double-click the title bar)" aria-label="Collapse"><svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="M4 8.5h8" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/></svg></button>
244
+ <button data-cv-close type="button" title="Close the conversations (the button at the top opens them again)" aria-label="Close">✕</button>
245
+ </div>
246
+ <div class="cv-body">
247
+ <div class="cv-thread tk-thread" aria-live="polite"></div>
248
+ <div class="cv-state" hidden></div>
249
+ <form class="cv-form" autocomplete="off">
250
+ <div class="cv-mentions glass" role="listbox" aria-label="Mention" hidden></div>
251
+ <div class="cv-input" role="textbox" aria-multiline="true" aria-label="Your message" contenteditable="true" spellcheck="true"></div>
252
+ <div class="cv-tools">
253
+ <button type="button" class="cv-tool" data-cv-link title="Insert a link to what you see: it shows as what it leads to, and carries no key"><svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true"><path d="M6.5 9.5l3-3M7 4.5l1.2-1.2a2.6 2.6 0 0 1 3.7 3.7L10.7 8.2M9 11.5l-1.2 1.2a2.6 2.6 0 0 1-3.7-3.7L5.3 7.8" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg><span>What I see</span></button>
254
+ <span class="cv-hint muted">Enter sends · Shift+Enter, a new line · @ mentions</span>
255
+ <button type="submit" class="rv-btn primary">Send</button>
256
+ </div>
257
+ <div class="cv-err" hidden></div>
258
+ </form>
259
+ </div>
260
+ <div class="fl-pill"><button class="fl-pill-open" type="button"><span class="fl-pill-text"></span><span class="fl-new" title="Something new"></span></button><button data-cv-close type="button" title="Close the conversations" aria-label="Close">✕</button></div>
227
261
  </div>
228
262
  </div>
229
263
  <!-- someone asks you to follow them (CollabSpec decision 10, web/src/askfollow.ts): at the top
@@ -252,6 +286,8 @@
252
286
  <button type="submit" id="who-ok" class="rv-btn primary">Continue</button>
253
287
  </div>
254
288
  </form>
289
+ <!-- the personal link the reader came by, shown to them alone, in the form's place (web/src/mylink.ts) -->
290
+ <div id="mylink" class="modal-box glass" role="dialog" aria-modal="true" aria-labelledby="mylink-title" hidden></div>
255
291
  </div>
256
292
  <div id="export-modal" hidden></div>
257
293
  <div id="tip" class="tip" hidden></div>
@@ -15,15 +15,18 @@
15
15
  // them. Their advice is never counted here: the progress and what the reader reviewed are people's.
16
16
  //
17
17
  // Key declarations come first in reading (ExportSpec decision 4): progress has two levels, key
18
- // (approved of the key declarations, the target among them) and all (approved of the review). They
19
- // are marked ◆ in the review list, which can show them alone; what each supports is shared/keys.ts.
18
+ // (approved of the key declarations that need review, the target among them, those trusted told
19
+ // apart as "+N trusted") and all (approved of the review). They are marked ◆ in the review list,
20
+ // which can show them alone, the trusted ones among them (the owner's decision of 2026-10-19: a key
21
+ // declaration is a member of the TCB, trusted or not); what each supports is shared/keys.ts.
20
22
  import { SITE_STMT } from "../../shared/graph.js";
21
23
  import { advice, adviceOf, fresh, statusOf } from "../../shared/review.js";
22
- import { keyGraph, statusCounts } from "../../shared/keys.js";
23
- import { keyMarks } from "../../shared/review.js";
24
- import { inTargets, nonStandardAxiom, offBoard, queueProgress, reviewQueue, settled, whyChain } from "../../shared/reviewqueue.js";
24
+ import { keyCounts, keyGraph } from "../../shared/keys.js";
25
+ import { keyMarks, trustedBy } from "../../shared/review.js";
26
+ import { inTargets, nonStandardAxiom, offBoard, queueProgress, reviewQueue, settled, TCB_SITES, whyChain } from "../../shared/reviewqueue.js";
25
27
  import { BOT } from "./agentmark.js";
26
28
  import { escapeHtml } from "./highlight.js";
29
+ import { SHIELD } from "./trust.js";
27
30
  /** How a declaration reads in a chain: with its namespace's last part, which tells `Module.env`
28
31
  * from `ModExpr.env`. */
29
32
  function chainName(g, i) {
@@ -66,7 +69,7 @@ export class ReviewFlow {
66
69
  const k = this.states.findIndex((s) => s.g === g);
67
70
  let st = k >= 0 ? this.states.splice(k, 1)[0] : null;
68
71
  if (!st || st.review !== review)
69
- st = { g, review, orders: new Map(), shared: null, keyGraphs: new Map() };
72
+ st = { g, review, orders: new Map(), tcbs: new Map(), shared: null, keyGraphs: new Map() };
70
73
  this.states.push(st);
71
74
  if (this.states.length > KEEP_FLOWS)
72
75
  this.states.shift();
@@ -93,14 +96,32 @@ export class ReviewFlow {
93
96
  isKey(root, i) {
94
97
  return i === root || this.keys(root).keys.includes(i);
95
98
  }
96
- /** Whether `i` is in what `root`'s review holds: what can be marked key for it. */
99
+ /** Whether `i` is a key declaration of `root` that needs no review: trusted. */
100
+ isTrustedKey(root, i) {
101
+ return this.keys(root).trusted.includes(i);
102
+ }
103
+ /** Whether `i` is in what `root`'s review holds. */
97
104
  inReview(root, i) {
98
105
  return this.queue(root).order.includes(i);
99
106
  }
100
- /** How far the review of `root`'s key declarations has come: approved of K, the target among
101
- * them. */
107
+ /** `root`'s TCB: statement and body reach. */
108
+ tcb(root) {
109
+ const st = this.state();
110
+ let t = st.tcbs.get(root);
111
+ if (!t)
112
+ st.tcbs.set(root, (t = st.g.reach([root], TCB_SITES, "out")));
113
+ return t;
114
+ }
115
+ /** Whether `i` can be marked key for `root` (ExportSpec decision 1, the owner's decision of
116
+ * 2026-10-19): a member of its TCB, trusted or not, in the project or outside it, or of its review
117
+ * set (a non-standard axiom reached through proofs alone) — never the target itself. */
118
+ keyable(root, i) {
119
+ return i !== root && (this.tcb(root)[i] === 1 || this.inReview(root, i));
120
+ }
121
+ /** How far the review of `root`'s key declarations has come: approved of those that need review
122
+ * (K, the target among them), the trusted ones counted apart. */
102
123
  keyProgress(root) {
103
- return statusCounts(this.hooks.graph(), this.hooks.review(), this.keys(root).keys);
124
+ return keyCounts(this.hooks.graph(), this.hooks.review(), this.keys(root));
104
125
  }
105
126
  /** How far `root`'s review has come: its review set, and the axioms beside it. */
106
127
  progress(root) {
@@ -122,9 +143,10 @@ export class ReviewFlow {
122
143
  const q = this.queue(root);
123
144
  return q.order.filter((i) => !this.done(i)).length + offBoard(q).filter((a) => !this.axiomDone(a)).length;
124
145
  }
125
- /** What is left of `root`'s key declarations for this reader. */
146
+ /** What is left of `root`'s key declarations for this reader: those that need review. */
126
147
  keysLeft(root) {
127
- return this.keys(root).keys.filter((i) => !this.done(i)).length;
148
+ const kg = this.keys(root);
149
+ return kg.keys.filter((i) => !kg.trusted.includes(i) && !this.done(i)).length;
128
150
  }
129
151
  /** The declarations of `root`'s TCB that an agent comments on (advice on the present version), in
130
152
  * review order. */
@@ -161,7 +183,7 @@ export class ReviewFlow {
161
183
  ? ` · <span class="lens-adv" title="${escapeHtml(`${who.join(", ")} (agent${who.length === 1 ? "" : "s"}) ${who.length === 1 ? "comments" : "comment"} on ${commented.length} declaration${commented.length === 1 ? "" : "s"} here — advice, not counted; the target's review list marks them`)}">${BOT}${escapeHtml(who.length === 1 ? `${who[0]} comments on` : "Agents comment on")} ${commented.length}</span>`
162
184
  : "";
163
185
  meta.innerHTML =
164
- `· <span class="lens-key" title="${escapeHtml(`Key declarations: ${k.approved} of ${k.total} approved (the target among them) · ${keysLeft} not yet reviewed by you`)}"><span class="key-mark">◆</span>${k.approved} / ${k.total}</span>` +
186
+ `· <span class="lens-key" title="${escapeHtml(`Key declarations: ${k.approved} of the ${k.total} that need review approved (the target among them) · ${keysLeft} not yet reviewed by you${k.trusted ? ` · ${k.trusted} more trusted, needing no review` : ""}`)}"><span class="key-mark">◆</span>${k.approved} / ${k.total}${k.trusted ? ` <span class="muted">+${k.trusted} trusted</span>` : ""}</span>` +
165
187
  ` · ${p.approved} / ${p.total} approved` + (p.commented ? ` · ${p.commented} commented` : "") + (p.stale ? ` · ${p.stale} stale` : "") + adv +
166
188
  // the reader's own part done: an opinion on every one, every non-standard axiom approved
167
189
  (left ? "" : ` · <span class="lens-done">All reviewed ✓</span>`);
@@ -173,15 +195,18 @@ export class ReviewFlow {
173
195
  /** The panel's list of a target's review in review order: numbered, the review status of each,
174
196
  * the ones the reader reviewed faded. A non-standard axiom says so, and
175
197
  * where it is used; one the graph has no declaration for on the board is listed first, and goes
176
- * to the target, whose panel approves it. */
198
+ * to the target, whose panel approves it. `keyOnly` (◆ Key): the key declarations alone, in their
199
+ * order (shared/keys.ts, keySet) — the trusted ones first, marked trusted and unnumbered, since
200
+ * they are not in the review order; then the rest, numbered as in the review order. */
177
201
  listHtml(root, keyOnly = false) {
178
202
  const g = this.hooks.graph();
179
203
  const d = this.hooks.review();
180
204
  const q = this.queue(root);
181
- const keys = new Set(this.keys(root).keys);
205
+ const kg = this.keys(root);
206
+ const keys = new Set(kg.keys);
182
207
  const off = keyOnly ? [] : offBoard(q);
183
208
  // the positions are the review order's, also where only the key declarations are listed
184
- const order = keyOnly ? q.order.filter((i) => keys.has(i)) : q.order;
209
+ const order = keyOnly ? kg.keys : q.order;
185
210
  const position = new Map(q.order.map((i, k) => [i, k]));
186
211
  const offN = offBoard(q).length;
187
212
  const where = (a) => (a.via.length ? ` · used in ${a.via.map((j) => chainName(g, j)).join(", ")}` : "");
@@ -190,15 +215,23 @@ export class ReviewFlow {
190
215
  `<span class="q-n">${k + 1}</span>axiom ${escapeHtml(a.name)}<span class="muted">${escapeHtml(where(a))}</span></button>`);
191
216
  const kp = this.keyProgress(root);
192
217
  const note = keyOnly
193
- ? `The key declarations, ◆, in review order: ${kp.approved} of ${kp.total} approved, ${this.keysLeft(root)} not yet reviewed by you.`
218
+ ? `The key declarations, ◆, ${kp.trusted ? `${kp.trusted} trusted first, needing no review, then the rest ` : ""}in review order: ${kp.approved} of ${kp.total} approved, ${this.keysLeft(root)} not yet reviewed by you.`
194
219
  : `Non-standard axioms first, then bottom-up: what a declaration uses comes before it; ` +
195
220
  `${this.left(root)} of ${q.order.length + offN} not yet reviewed by you.`;
196
221
  return (`<div class="q-note muted">${note}</div>` +
197
222
  `<div class="q-list">` +
198
223
  offRows.join("") +
199
224
  order
200
- .map((i, k) => {
225
+ .map((i) => {
201
226
  const v = g.nodes[i];
227
+ const at = position.get(i);
228
+ // a trusted key declaration: read with the others, in need of no review, so no status and
229
+ // no place in the review order (ExportSpec decision 1)
230
+ if (at === undefined) {
231
+ const by = trustedBy(d, v.name, v.module, g.isExt(i));
232
+ return (`<button class="row q-row q-key rv-trusted" data-walk="${i}" title="${escapeHtml(`Go to ${v.name} — a key declaration, trusted without review${by.length ? `, under ${by.join(" and ")}` : ""}: it is read with the others and needs no opinion`)}">` +
233
+ `<span class="q-n q-trusted" aria-label="trusted">${SHIELD}</span>${i === root ? `<span class="star">★</span>` : `<span class="key-mark">◆</span>`}${escapeHtml(v.name)}<span class="muted"> · trusted</span></button>`);
234
+ }
202
235
  const mine = this.done(i);
203
236
  const cls = `row q-row rv-${statusOf(d, v.name, v.hash)}${mine ? " q-mine" : ""}`;
204
237
  const what = mine ? " — you reviewed it" : "";
@@ -208,7 +241,7 @@ export class ReviewFlow {
208
241
  const ax = axiomOf.get(i);
209
242
  const key = i !== root && keys.has(i);
210
243
  return (`<button class="${cls}${key ? " q-key" : ""}" data-walk="${i}" title="Go to ${escapeHtml(v.name)}${what}${key ? " — a key declaration" : ""}${ax ? escapeHtml(` — a non-standard axiom${where(ax)}`) : ""}">` +
211
- `<span class="q-n">${offN + position.get(i) + 1}</span>${i === root ? `<span class="star">★</span>` : key ? `<span class="key-mark">◆</span>` : ""}${ax ? "axiom " : ""}${escapeHtml(v.name)}${ax ? `<span class="muted">${escapeHtml(where(ax))}</span>` : ""}${mark}</button>`);
244
+ `<span class="q-n">${offN + at + 1}</span>${i === root ? `<span class="star">★</span>` : key ? `<span class="key-mark">◆</span>` : ""}${ax ? "axiom " : ""}${escapeHtml(v.name)}${ax ? `<span class="muted">${escapeHtml(where(ax))}</span>` : ""}${mark}</button>`);
212
245
  })
213
246
  .join("") +
214
247
  `</div>`);
@@ -15,7 +15,7 @@
15
15
  //
16
16
  // Everything here is without the page, so that it can be tested: what a pick's query is and what
17
17
  // it says in words, reading picks back from a query (an address, a reader followed, an agent), what
18
- // a click or a shift-click does to the list, and how key 2 steps through Rests on. main.ts keeps the
18
+ // a click or a shift-click does to the list, and how key 2 steps through Rests on. pageselection.ts keeps the
19
19
  // list and the thing the panel tells of; web/src/selbar.ts shows the list.
20
20
  import { renameInQuery } from "../../shared/moves.js";
21
21
  import { describe, keysQuery, parseQuery, printQuery, readKeys } from "../../shared/query.js";
@@ -38,7 +38,7 @@ export function applyTheme(choice = themeChoice()) {
38
38
  document.documentElement.dataset.theme = t;
39
39
  }
40
40
  /** Show `t` whatever the reader chose, until it is let go (null): the artwork mode's theme (web/src/
41
- * main.ts, drawLook), which a change of the system's, followed by "As the system", must not undo
41
+ * pageart.ts, drawLook), which a change of the system's, followed by "As the system", must not undo
42
42
  * while the mode is on. Let go, the reader's choice is in force again. */
43
43
  export function holdTheme(t) {
44
44
  held = t;
@@ -0,0 +1,271 @@
1
+ // What is trusted without review (ReviewSpec decision 3), chosen from the page: the trusted
2
+ // prefixes listed in a popover from the side panel's Trusted button, each with a way to stop
3
+ // trusting it, and a way to trust a cluster from its row in the outline. Each asks first, and says
4
+ // what it means and what it changes: how many declarations the prefix covers, and how many each
5
+ // target then counts for review.
6
+ import { SITE_BODY, SITE_STMT } from "../../shared/graph.js";
7
+ import { covers, DEFAULT_TRUSTED, OUTSIDE, prefixLabel, under, validPrefix } from "../../shared/review.js";
8
+ import { escapeHtml } from "./highlight.js";
9
+ /** The declarations of a set of the graph, as the review reads them. */
10
+ export function membersOf(g, set) {
11
+ const out = [];
12
+ for (let j = 0; j < set.length; j++)
13
+ if (set[j])
14
+ out.push({ name: g.nodes[j].name, module: g.nodes[j].module, ext: g.isExt(j), hash: g.nodes[j].hash });
15
+ return out;
16
+ }
17
+ /** A target's TCB, the target included, as the panel and the Targets list read it:
18
+ * statement and body edges. */
19
+ export function tcbMembers(g, roots) {
20
+ return membersOf(g, g.reach(roots, SITE_STMT | SITE_BODY, "out"));
21
+ }
22
+ const EXT = "⟨external⟩";
23
+ /** The prefix a cluster of the outline stands for, or null where trust cannot name it. A cluster of
24
+ * the project is a namespace or a folder of files, and its key is the prefix either way; one
25
+ * outside the project only when clustered by file, since the outside world is trusted by module
26
+ * (clustered by namespace, its clusters are names, which say nothing of where they come from). */
27
+ export function clusterPrefix(c, mode) {
28
+ if (!c.ext)
29
+ return validPrefix(c.key) ? c.key : null;
30
+ // the outside world as a whole, in either clustering
31
+ if (c.key === EXT)
32
+ return OUTSIDE;
33
+ if (mode !== "module" || !c.key.startsWith(EXT + "."))
34
+ return null;
35
+ const p = c.key.slice(EXT.length + 1);
36
+ return validPrefix(p) ? p : null;
37
+ }
38
+ /** What trusting a prefix (or no longer trusting it) changes: how many of the graph's declarations
39
+ * it covers, in the project and outside it, and each target's count for review before and after. */
40
+ export function effectOf(g, d, prefix, on, targets) {
41
+ let own = 0, outside = 0;
42
+ for (let j = 0; j < g.n; j++) {
43
+ const v = g.nodes[j];
44
+ if (covers(prefix, v.name, v.module, g.isExt(j)))
45
+ g.isExt(j) ? outside++ : own++;
46
+ }
47
+ // the same review with the list changed (its opinions and targets shared, not copied)
48
+ const next = { ...d, trusted: on ? [...d.trusted, prefix].sort() : d.trusted.filter((p) => p !== prefix) };
49
+ const counts = targets.map((t) => ({ name: t.name, before: t.count(d), after: t.count(next) })).filter((t) => t.before !== t.after);
50
+ return { own, outside, targets: counts };
51
+ }
52
+ /** Where trusting `prefix` (`on`), or no longer trusting it, is undone, as the question says it:
53
+ * Trusted lists every trusted prefix, and of those taken off only the defaults (ReviewSpec decision
54
+ * 3) and the outside world, which has its own button there; any other leaves the list, and is
55
+ * trusted again from the shield on its row — a module outside the project only where the cluster
56
+ * tree is by file (`clusterPrefix`). `outside`: the prefix covers only declarations outside the
57
+ * project. */
58
+ export function undoNote(prefix, on, outside) {
59
+ if (on)
60
+ return "Undo it from Trusted in the side panel.";
61
+ if (DEFAULT_TRUSTED.includes(prefix))
62
+ return "It stays listed under Trusted, to be trusted again.";
63
+ if (prefix === OUTSIDE)
64
+ return "It can be trusted again from Trusted in the side panel.";
65
+ return `It leaves the Trusted list: the shield on its row in the side panel${outside ? ", clustered by file," : ""} trusts it again.`;
66
+ }
67
+ export const SHIELD = `<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M8 1.8 3 3.6v3.9c0 3.1 2.1 5.5 5 6.7 2.9-1.2 5-3.6 5-6.7V3.6z"/></svg>`;
68
+ export class Trust {
69
+ list;
70
+ pop;
71
+ hooks;
72
+ /** what the open question is about */
73
+ asking = null;
74
+ constructor(list, pop, hooks) {
75
+ this.list = list;
76
+ this.pop = pop;
77
+ this.hooks = hooks;
78
+ list.addEventListener("click", (e) => {
79
+ const t = e.target;
80
+ const off = t.closest("[data-untrust]");
81
+ if (off)
82
+ return this.ask(off.dataset.untrust, false, off);
83
+ const on = t.closest("[data-retrust]");
84
+ if (on)
85
+ return this.ask(on.dataset.retrust, true, on);
86
+ const show = t.closest("[data-show]");
87
+ if (show)
88
+ this.hooks.show(show.dataset.show);
89
+ });
90
+ pop.addEventListener("click", (e) => {
91
+ const t = e.target;
92
+ if (t.closest("[data-tp-cancel]"))
93
+ this.close();
94
+ else if (t.closest("[data-tp-ok]"))
95
+ void this.confirm();
96
+ });
97
+ // a click anywhere else is a no; one on another trust action asks about that instead
98
+ document.addEventListener("pointerdown", (e) => {
99
+ const t = e.target;
100
+ if (this.asking && !pop.contains(t) && !t.closest("[data-trust], [data-untrust], [data-retrust]") && !t.closest("#modal"))
101
+ this.close();
102
+ });
103
+ }
104
+ get open() {
105
+ return this.asking !== null;
106
+ }
107
+ writable() {
108
+ const R = this.hooks.review();
109
+ return !R.readOnly && !R.blocked;
110
+ }
111
+ /** The list in its popover: every trusted prefix, and the defaults no longer trusted, which
112
+ * can be trusted again from here (the outline names only what the graph holds). */
113
+ render() {
114
+ const d = this.hooks.review().data;
115
+ const g = this.hooks.graph();
116
+ const can = this.writable();
117
+ const esc = escapeHtml;
118
+ const count = (p) => {
119
+ let n = 0;
120
+ for (let j = 0; j < g.n; j++)
121
+ if (covers(p, g.nodes[j].name, g.nodes[j].module, g.isExt(j)))
122
+ n++;
123
+ return n;
124
+ };
125
+ const chip = (p) => {
126
+ const n = count(p);
127
+ const own = !DEFAULT_TRUSTED.includes(p);
128
+ return (`<span class="tl-chip${own ? " own" : ""}${p === OUTSIDE ? " world" : ""}">` +
129
+ `<button class="tl-name" data-show="${esc(p)}" title="${esc(prefixLabel(p))}: ${n.toLocaleString()} declaration${n === 1 ? "" : "s"} here trusted without review — click to show ${own ? "them" : "it"}">${esc(prefixLabel(p))}</button>` +
130
+ (can ? `<button class="tl-x" data-untrust="${esc(p)}" title="Stop trusting ${esc(prefixLabel(p))}…" aria-label="Stop trusting ${esc(prefixLabel(p))}">✕</button>` : "") +
131
+ `</span>`);
132
+ };
133
+ // a default taken off stays in sight, so that it can be put back
134
+ const gone = DEFAULT_TRUSTED.filter((p) => !d.trusted.includes(p));
135
+ const off = (p) => `<span class="tl-chip off"><button class="tl-name" data-show="${esc(p)}" title="${esc(p)}: one of the defaults, not trusted now — its declarations count for review">${esc(p)}</button>` +
136
+ (can ? `<button class="tl-x" data-retrust="${esc(p)}" title="Trust ${esc(p)} again…" aria-label="Trust ${esc(p)} again">+</button>` : "") +
137
+ `</span>`;
138
+ this.list.innerHTML =
139
+ `<div class="tl-h"><span class="tl-t">Trusted</span><span class="muted">not reviewed, not counted · the same on every board</span></div>` +
140
+ `<div class="tl-chips">${d.trusted.map(chip).join("")}${gone.map(off).join("")}</div>` +
141
+ (can && !d.trusted.includes(OUTSIDE)
142
+ ? `<button class="tl-all" data-retrust="${OUTSIDE}" title="Trust every declaration outside the project, whatever its module…">Trust the whole outside world</button>`
143
+ : "") +
144
+ (can ? `<div class="tl-hint muted">To trust a namespace or a folder, use <span class="tl-shield">${SHIELD}</span> on its row in the side panel.</div>` : "") +
145
+ (this.hooks.review().note ? `<div class="tl-hint muted">${esc(this.hooks.review().note)}</div>` : "");
146
+ }
147
+ /** A cluster row's trust mark and action in the outline, as HTML: a shield where a trusted prefix
148
+ * covers the cluster, and on the row under the pointer a shield to trust it. */
149
+ cell(c, mode) {
150
+ const p = clusterPrefix(c, mode);
151
+ if (!p)
152
+ return "";
153
+ const d = this.hooks.review().data;
154
+ const esc = escapeHtml;
155
+ const by = d.trusted.filter((t) => under(p, t) || (t === OUTSIDE && c.ext));
156
+ const can = this.writable();
157
+ // a trusted one's shield is its mark and its action
158
+ if (by.includes(p))
159
+ return can
160
+ ? `<button class="o-trust on" data-trust title="${esc(prefixLabel(p))} is trusted without review — click to stop trusting it">${SHIELD}</button>`
161
+ : `<span class="o-trust on" title="${esc(prefixLabel(p))} is trusted without review">${SHIELD}</span>`;
162
+ // a broader prefix covers it: taking that one off is done where it is
163
+ if (by.length)
164
+ return `<span class="o-trust on under" title="Trusted without review, under ${esc(prefixLabel(by[0]))}">${SHIELD}</span>`;
165
+ return can ? `<button class="o-trust" data-trust title="Trust ${esc(prefixLabel(p))}: its declarations are not counted in reviews and need no opinion…" aria-label="Trust ${esc(prefixLabel(p))}">${SHIELD}</button>` : "";
166
+ }
167
+ /** Whether a cluster is trusted without review, as its panel says it (web/src/clusterpanel.ts):
168
+ * the prefix it stands for (null where trust cannot name it), whether that prefix is trusted
169
+ * itself, the broader trusted prefix that covers it otherwise, whether this page may change it,
170
+ * and why not where the review is read-only here. */
171
+ state(c, mode) {
172
+ const p = clusterPrefix(c, mode);
173
+ const can = this.writable();
174
+ const note = this.hooks.review().note;
175
+ if (!p)
176
+ return { prefix: null, on: false, by: null, can };
177
+ const by = this.hooks.review().data.trusted.filter((t) => under(p, t) || (t === OUTSIDE && c.ext));
178
+ return { prefix: p, on: by.includes(p), by: by.includes(p) ? null : by[0] ?? null, can, ...(note ? { note } : {}) };
179
+ }
180
+ /** A click on a cluster row's action: trust it, or stop trusting it. */
181
+ clicked(c, mode, anchor) {
182
+ const p = clusterPrefix(c, mode);
183
+ if (p && this.writable())
184
+ this.ask(p, !this.hooks.review().data.trusted.includes(p), anchor);
185
+ }
186
+ /** Ask before trusting a prefix or no longer trusting it: what it means, and what it changes.
187
+ * Beside `anchor`, or (the canvas's menu) at a point of the window, kept inside it. */
188
+ ask(prefix, on, anchor) {
189
+ if (!this.writable())
190
+ return;
191
+ this.asking = { prefix, on };
192
+ const g = this.hooks.graph();
193
+ const d = this.hooks.review().data;
194
+ const esc = escapeHtml;
195
+ const code = prefix === OUTSIDE ? "everything outside the project" : `<code>${esc(prefix)}</code>`;
196
+ const e = effectOf(g, d, prefix, on, this.hooks.targets());
197
+ const n = (x) => x.toLocaleString();
198
+ const one = e.own + e.outside === 1;
199
+ const which = prefix === OUTSIDE
200
+ ? `${n(e.outside)} declaration${one ? "" : "s"} outside the project`
201
+ : e.own && e.outside
202
+ ? `${n(e.own)} declarations of the project whose name or module starts with ${code}, and the ${n(e.outside)} outside it whose module does,`
203
+ : e.outside
204
+ ? `${n(e.outside)} declaration${one ? "" : "s"} outside the project whose module starts with ${code}`
205
+ : `${n(e.own)} declaration${one ? "" : "s"} whose name or module starts with ${code}`;
206
+ const text = on
207
+ ? `The ${which} ${one ? "is" : "are"} then trusted without review: not counted in any target's progress, and in need of no opinion. Opinions given on ${one ? "it" : "them"} are kept.`
208
+ : `The ${which} then need${one ? "s" : ""} review again, unless another trusted prefix covers ${one ? "it" : "them"}: counted in each target's progress.`;
209
+ const effect = e.targets.length
210
+ ? `<div class="tp-effect"><div class="muted">Counted for review</div>` +
211
+ e.targets.map((t) => `<div><span class="star">★</span>${esc(t.name.split(".").pop())} <b>${n(t.before)} → ${n(t.after)}</b></div>`).join("") +
212
+ `</div>`
213
+ : `<div class="tp-effect muted">No target's count changes.</div>`;
214
+ const deflt = DEFAULT_TRUSTED.includes(prefix) && !on ? `<div class="tp-text">${code} is one of the defaults: what a review of a Lean project usually takes on trust.</div>` : "";
215
+ this.pop.innerHTML =
216
+ `<div class="tp-title">${on ? "Trust" : "Stop trusting"} ${code}?</div>` +
217
+ `<div class="tp-text">${text}</div>${deflt}${effect}` +
218
+ `<div class="tp-note muted">For everyone on this server, recorded under your name in the review; Activity says who did it. ${undoNote(prefix, on, !e.own && e.outside > 0)}</div>` +
219
+ `<div class="rv-err" hidden></div>` +
220
+ `<div class="modal-actions"><button class="rv-btn" data-tp-cancel>Cancel</button>` +
221
+ `<button class="rv-btn primary" data-tp-ok>${on ? "Trust" : "Stop trusting"}</button></div>`;
222
+ this.pop.hidden = false;
223
+ if (!(anchor instanceof HTMLElement)) {
224
+ const w = this.pop.offsetWidth, hh = this.pop.offsetHeight;
225
+ this.pop.style.left = `${Math.round(Math.max(12, Math.min(anchor.x, innerWidth - w - 12)))}px`;
226
+ this.pop.style.top = `${Math.round(Math.max(70, Math.min(anchor.y, innerHeight - hh - 12)))}px`;
227
+ return;
228
+ }
229
+ // beside the panel it was asked from — the side panel's right (or the Trusted popover's), the
230
+ // cluster panel's left — level with what was clicked, inside the window
231
+ const right = anchor.closest("#panel");
232
+ const side = (anchor.closest("#trust-list:not([hidden])") ?? anchor.closest("#side") ?? right ?? anchor).getBoundingClientRect();
233
+ const at = anchor.getBoundingClientRect();
234
+ const h = this.pop.offsetHeight;
235
+ this.pop.style.left = `${Math.round(right ? Math.max(12, side.left - 10 - this.pop.offsetWidth) : side.right + 10)}px`;
236
+ this.pop.style.top = `${Math.round(Math.max(70, Math.min(innerHeight - h - 12, at.top - 12)))}px`;
237
+ }
238
+ /** The review changed: the list follows, and a question someone else has answered meanwhile
239
+ * goes away. */
240
+ reviewChanged() {
241
+ this.render();
242
+ if (this.asking && this.hooks.review().data.trusted.includes(this.asking.prefix) === this.asking.on)
243
+ this.close();
244
+ }
245
+ close() {
246
+ this.asking = null;
247
+ this.pop.hidden = true;
248
+ }
249
+ async confirm() {
250
+ const q = this.asking;
251
+ if (!q)
252
+ return;
253
+ const me = await this.hooks.ensureReviewer();
254
+ if (!me || this.asking !== q)
255
+ return;
256
+ // one answer per question: a second click while the first is on its way does nothing
257
+ const ok = this.pop.querySelector("[data-tp-ok]");
258
+ if (ok)
259
+ ok.disabled = true;
260
+ const why = await this.hooks.submit({ op: "trust", prefix: q.prefix, on: q.on });
261
+ if (ok)
262
+ ok.disabled = false;
263
+ if (!why)
264
+ return this.close();
265
+ const err = this.pop.querySelector(".rv-err");
266
+ if (err) {
267
+ err.textContent = why;
268
+ err.hidden = false;
269
+ }
270
+ }
271
+ }
@@ -18,7 +18,7 @@
18
18
  //
19
19
  // This file holds the trail, the temporary clusters a set of visitors needs and how they are packed,
20
20
  // where the outermost of them is put in a cluster of the board, and the references a visitor's edges
21
- // draw, all as pure functions; web/src/visits.ts lays them on the board's scene, web/src/main.ts
21
+ // draw, all as pure functions; web/src/visits.ts lays them on the board's scene, web/src/pageselection.ts
22
22
  // keeps the trail of the board on show and web/src/canvas.ts draws it.
23
23
  import { packEnclose, packSiblings } from "d3-hierarchy";
24
24
  import { SITE_BODY, SITE_STMT } from "../../shared/graph.js";