visualproof 0.4.3 → 0.4.4

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 (47) hide show
  1. package/dist/assets/latex/visualproof.sty +19 -9
  2. package/dist/mcp/visualproof-mcp.mjs +7 -3
  3. package/dist/server/access.js +34 -0
  4. package/dist/server/agent.js +5 -4
  5. package/dist/server/agentlibrary.js +1 -1
  6. package/dist/server/agentviews.js +1 -1
  7. package/dist/server/artcmd.js +1 -1
  8. package/dist/server/askfollow.js +1 -4
  9. package/dist/server/events.js +20 -5
  10. package/dist/server/export.js +17 -4
  11. package/dist/server/fetchurl.js +30 -13
  12. package/dist/server/history.js +3 -1
  13. package/dist/server/identity.js +25 -1
  14. package/dist/server/library.js +10 -3
  15. package/dist/server/live.js +32 -5
  16. package/dist/server/lostfound.js +3 -2
  17. package/dist/server/main.js +113 -28
  18. package/dist/server/poppler.js +48 -10
  19. package/dist/server/renames.js +10 -5
  20. package/dist/server/review.js +10 -0
  21. package/dist/server/reviewapi.js +1 -1
  22. package/dist/server/status.js +29 -8
  23. package/dist/server/talk.js +7 -2
  24. package/dist/server/views.js +21 -7
  25. package/dist/shared/collab.js +14 -8
  26. package/dist/shared/doc/latex.js +5 -3
  27. package/dist/shared/doc/outline.js +6 -3
  28. package/dist/shared/library.js +11 -6
  29. package/dist/shared/review.js +7 -5
  30. package/dist/shared/search.js +7 -3
  31. package/dist/shared/views.js +8 -1
  32. package/dist/web/bundle/app.js +1646 -717
  33. package/dist/web/bundle/edges.js +42 -15
  34. package/dist/web/index.html +2 -2
  35. package/dist/web/src/artwork.js +25 -4
  36. package/dist/web/src/axiomring.js +42 -0
  37. package/dist/web/src/bundles.js +52 -16
  38. package/dist/web/src/canvas.js +62 -20
  39. package/dist/web/src/past.js +28 -0
  40. package/dist/web/src/selection.js +47 -4
  41. package/dist/web/src/status.js +4 -2
  42. package/dist/web/style.css +79 -10
  43. package/docs/agent-api/following.md +1 -1
  44. package/docs/agent-api/library.md +1 -1
  45. package/docs/agent-api/requests.md +3 -1
  46. package/docs/agent-api/views.md +1 -1
  47. package/package.json +1 -1
@@ -75,7 +75,10 @@ export function readView(raw) {
75
75
  const r = raw;
76
76
  if (typeof r.id !== "string" || !r.id)
77
77
  return "it has no id";
78
- const bad = invalidQuery(r.scope);
78
+ // the Project holds everything (ViewSpec decision 5): a scope an earlier version let it take (the
79
+ // outside world toggled, a condition added) is read as `all`
80
+ const project = r.id === PROJECT;
81
+ const bad = project ? null : invalidQuery(r.scope);
79
82
  if (bad)
80
83
  return `its scope cannot be read: ${bad}`;
81
84
  const clustering = r.clustering ?? "namespace";
@@ -95,11 +98,11 @@ export function readView(raw) {
95
98
  // a note that cannot be read is left out; the others are the view's
96
99
  const notes = cleanNotes(r.notes);
97
100
  // the notes of the project added to it and taken out of it; the Project keeps none, holding all
98
- const items = r.id === PROJECT ? {} : cleanItems(r.items);
101
+ const items = project ? {} : cleanItems(r.items);
99
102
  return {
100
103
  id: r.id,
101
104
  name: r.name ?? null,
102
- scope: cleanQuery(r.scope),
105
+ scope: project ? { op: "all" } : cleanQuery(r.scope),
103
106
  clustering: clustering,
104
107
  pins: pins,
105
108
  folds: folds,
@@ -168,21 +171,23 @@ function cleanMemory(x) {
168
171
  export function readProjectView(siteDir, layoutVersion) {
169
172
  const file = join(siteDir, "views.json");
170
173
  if (!existsSync(file))
171
- return { view: null };
174
+ return { view: null, notes: 0 };
172
175
  try {
173
176
  const raw = JSON.parse(readFileSync(file, "utf8"));
177
+ // the project's notes, every one of which the Project's board shows (AttachmentSpec decision 17)
178
+ const notes = cleanProjectNotes(raw.notes).length;
174
179
  for (const r of Array.isArray(raw.views) ? raw.views : []) {
175
180
  const v = readView(r);
176
181
  if (typeof v === "string" || v.id !== PROJECT)
177
182
  continue;
178
183
  if (raw.layoutVersion !== layoutVersion)
179
184
  v.pins = emptyLayouts();
180
- return { view: v };
185
+ return { view: v, notes };
181
186
  }
182
- return { view: null };
187
+ return { view: null, notes };
183
188
  }
184
189
  catch (e) {
185
- return { view: null, why: e instanceof Error ? e.message : String(e) };
190
+ return { view: null, notes: 0, why: e instanceof Error ? e.message : String(e) };
186
191
  }
187
192
  }
188
193
  export class Views {
@@ -235,6 +240,15 @@ export class Views {
235
240
  const has = (n) => !!n.carries?.some((c) => c.file === sha);
236
241
  return this.book.notes.some(has) || this.book.list().some((v) => (v.notes ?? []).some(has));
237
242
  }
243
+ /** Whether a note, the project's or a view's, shows page `page` of PDF `sha` — a clip of
244
+ * `region` of it (rounded as the library rounds a region), or, with none, the page a whole PDF
245
+ * carried shows (its own, else the first): what a read-only page draws of the library
246
+ * (CollabSpec decision 11). */
247
+ shows(sha, page, region) {
248
+ const same = (c) => c.file === sha && (region ? !!c.region && (c.page ?? 1) === page && c.region.every((x, k) => Math.round(x * 1e4) === Math.round(region[k] * 1e4)) : !c.region && (c.page ?? 1) === page);
249
+ const has = (n) => !!n.carries?.some(same);
250
+ return this.book.notes.some(has) || this.book.list().some((v) => (v.notes ?? []).some(has));
251
+ }
238
252
  /** A file came into the library (its first record, by upload or by URL, from a person or an agent):
239
253
  * every item shows on the Project (the owner's decision of 2026-10-11), so a note of the project
240
254
  * carries it — collapsed, its text the file's title, written by whoever added the file, at the
@@ -25,23 +25,29 @@ export function cutShort(s, room) {
25
25
  export function defaultAgentName(by) {
26
26
  return `${cutShort(by.trim(), MAX_NAME - "'s AI".length)}'s AI`;
27
27
  }
28
- /** An agent's name told apart from the names `taken` (the tokens in force), whatever the case: the
28
+ /** An agent's name told apart from the names `taken` (the tokens in force), as sameName tells them: the
29
29
  * name itself, else numbered — "Alice's AI 2", "Alice's AI 3" — within the characters a name may
30
30
  * have, the name cut short to make room for the number. */
31
31
  export function uniqueName(name, taken) {
32
- const seen = new Set([...taken].map((t) => t.toLowerCase()));
32
+ const seen = new Set([...taken].map(nameKey));
33
33
  for (let n = 1;; n++) {
34
34
  const s = n === 1 ? name : `${cutShort(name, MAX_NAME - ` ${n}`.length)} ${n}`;
35
- if (!seen.has(s.toLowerCase()))
35
+ if (!seen.has(nameKey(s)))
36
36
  return s;
37
37
  }
38
38
  }
39
- /** Whether two names are the same name to a reader: whatever the case, and however Unicode writes
40
- * the same letters. A guest cannot take a name someone invited by a personal link holds in this
41
- * sense (CollabSpec decision 9), so that "alice" does not pass for "Alice". */
39
+ /** A name as a reader tells it from others: whatever the case, however Unicode writes the same
40
+ * letters, and without the characters nobody sees (zero-width spaces and joiners, soft hyphens,
41
+ * direction marks: Unicode's default-ignorable code points), which would make one name look like
42
+ * another. */
43
+ export function nameKey(s) {
44
+ return s.normalize("NFKC").replace(/\p{Default_Ignorable_Code_Point}/gu, "").trim().toLowerCase();
45
+ }
46
+ /** Whether two names are the same name to a reader (nameKey). A guest cannot take a name someone
47
+ * invited by a personal link holds in this sense (CollabSpec decision 9), so that neither "alice"
48
+ * nor "Alice" with a zero-width space passes for "Alice". */
42
49
  export function sameName(a, b) {
43
- const key = (s) => s.trim().normalize("NFKC").toLowerCase();
44
- return key(a) === key(b);
50
+ return nameKey(a) === nameKey(b);
45
51
  }
46
52
  /** Up to two letters for a name's round badge: the first letters of its first two words. */
47
53
  export function initials(name) {
@@ -375,11 +375,13 @@ function contents(doc, n) {
375
375
  * project (Mathlib 203, Init 97)`, the six largest libraries named. */
376
376
  function outsideLine(o) {
377
377
  const n = int(o.count);
378
- const named = o.by.slice(0, 6).map((b) => `${escapeLatex(b.name)} ${int(b.count)}`);
378
+ // in thousands as the Export window counts them ("2,640"), the same in every locale
379
+ const k = (x) => x.toLocaleString("en");
380
+ const named = o.by.slice(0, 6).map((b) => `${escapeLatex(b.name)} ${k(int(b.count))}`);
379
381
  const rest = o.by.slice(6).reduce((a, b) => a + int(b.count), 0);
380
382
  if (rest)
381
- named.push(`others ${rest}`);
382
- return `${n} declaration${n === 1 ? "" : "s"} from outside the project${named.length ? ` (${named.join(", ")})` : ""}, not printed`;
383
+ named.push(`others ${k(rest)}`);
384
+ return `${k(n)} declaration${n === 1 ? "" : "s"} from outside the project${named.length ? ` (${named.join(", ")})` : ""}, not printed`;
383
385
  }
384
386
  /** `n` declarations, in words. */
385
387
  const decls = (n) => `${int(n)} declaration${int(n) === 1 ? "" : "s"}`;
@@ -3,11 +3,14 @@
3
3
  // declarations and the notes in each, and the notes attached to a declaration after it. The page
4
4
  // draws the board as this outline (web/src/linear.ts); it is made from the same plan and the same
5
5
  // order the document is (shared/doc/sections.ts, shared/doc/order.ts), so that the two agree.
6
+ import { inlines } from "./markdown.js";
6
7
  import { orderDoc } from "./order.js";
7
- /** A note's first words: its first line, Markdown marks taken out, at most 60 characters. */
8
+ /** A note's first words: its first line of text (a code fence's mark is none), its Markdown marks
9
+ * taken out as its card reads them — code spans' backquotes, emphasis and strong — so that a
10
+ * name's underscores stay (`flt_regular`); at most 60 characters. */
8
11
  export function firstWords(text) {
9
- const line = text.split("\n").find((l) => l.trim()) ?? "";
10
- const plain = line.replace(/[*_`#>]+/g, "").replace(/\s+/g, " ").trim();
12
+ const line = text.split("\n").find((l) => l.trim() && !/^\s*(?:```+|~~~+)/.test(l)) ?? "";
13
+ const plain = inlines(line).map((x) => x.s).join("").replace(/\s+/g, " ").trim();
11
14
  return plain.length > 60 ? `${plain.slice(0, 59).trimEnd()}…` : plain;
12
15
  }
13
16
  /** The outline of the document of `plan` (of graph `g`) in the order of the board `spots` gives. */
@@ -562,21 +562,26 @@ export function quoteAt(text, start, end, context = QUOTE_CONTEXT) {
562
562
  const after = squeeze(text.slice(end, end + context * 3)).s.slice(0, context);
563
563
  return { text: q, ...(before ? { before } : {}), ...(after ? { after } : {}) };
564
564
  }
565
+ /** Typography read as typed: curly quotes as straight ones, dashes and the minus sign as a hyphen —
566
+ * each one character for one, so that offsets into the text stay where they were. A quote typed
567
+ * by hand or by an agent ("Kummer's lemma.") is found in a page typeset with ’ and –. */
568
+ export const plainPunctuation = (s) => s.replace(/[\u2018\u2019\u201a\u201b\u2032]/g, "'").replace(/[\u201c\u201d\u201e\u201f\u2033]/g, '"').replace(/[\u2010-\u2015\u2212]/g, "-");
565
569
  /** Where a quote is in a page's text: the offsets of the best match into `text` — the one whose
566
570
  * surroundings agree most with what was kept around it — or null when it is not there. Spaces are
567
- * read loosely, and so is case where no exact match is. */
571
+ * read loosely; so is case where no exact match is, and then typographic quotes and dashes. */
568
572
  export function findQuote(text, q) {
569
573
  const page = squeeze(text);
570
574
  const want = squeeze(q.text).s;
571
575
  if (!want)
572
576
  return null;
573
- const tries = [page.s, page.s.toLowerCase()];
574
- for (const [k, hay] of tries.entries()) {
575
- const needle = k ? want.toLowerCase() : want;
577
+ const tries = [(s) => s, (s) => s.toLowerCase(), (s) => plainPunctuation(s.toLowerCase())];
578
+ for (const read of tries) {
579
+ const hay = read(page.s);
580
+ const needle = read(want);
576
581
  let best = null;
577
582
  for (let at = hay.indexOf(needle); at >= 0; at = hay.indexOf(needle, at + 1)) {
578
- const before = q.before ? squeeze(q.before).s : "";
579
- const after = q.after ? squeeze(q.after).s : "";
583
+ const before = q.before ? read(squeeze(q.before).s) : "";
584
+ const after = q.after ? read(squeeze(q.after).s) : "";
580
585
  const score = common(hay.slice(Math.max(0, at - before.length - 1), at).trimEnd(), before, true) + common(hay.slice(at + needle.length).trimStart(), after, false);
581
586
  if (!best || score > best.score)
582
587
  best = { at, score };
@@ -654,18 +654,20 @@ export function trusted(d, name, module, external) {
654
654
  }
655
655
  /** What the canvas and the lists mark a declaration with: what reviewers said about it, and when
656
656
  * nobody has, whether a trusted prefix covers it — for the project's own declarations only:
657
- * the outside world trusted by default is the rule there, not news. */
658
- export function markOf(d, name, module, external, hash) {
657
+ * the outside world trusted by default is the rule there, not news; and never for a non-standard
658
+ * axiom (`axiom`), which needs review whatever trusts it (decision 3). */
659
+ export function markOf(d, name, module, external, hash, axiom = false) {
659
660
  const s = statusOf(d, name, hash);
660
- if (s !== "none" || external)
661
+ if (s !== "none" || external || axiom)
661
662
  return s;
662
663
  return trustedBy(d, name, module, false).length ? "trusted" : "none";
663
664
  }
664
- /** How far the review of a set (a target's TCB) has come. */
665
+ /** How far the review of a set (a target's TCB, a cluster) has come: what needs review in it, a
666
+ * non-standard axiom (`axiom`) whatever trusts it (decision 3). */
665
667
  export function progressOf(d, members) {
666
668
  const p = { total: 0, approved: 0, commented: 0, stale: 0 };
667
669
  for (const m of members) {
668
- if (trusted(d, m.name, m.module, m.ext))
670
+ if (!m.axiom && trusted(d, m.name, m.module, m.ext))
669
671
  continue;
670
672
  p.total++;
671
673
  const s = statusOf(d, m.name, m.hash);
@@ -11,7 +11,8 @@
11
11
  // scan, and a query that only adds to the last one looks through what the last one found.
12
12
  //
13
13
  // A unit is found by the names it folds too (ViewNode.also): `QOR.Name`, which Lean generated from
14
- // the command that writes `QOR`, finds `QOR`, as a name does, and the hit says which (`via`).
14
+ // the command that writes `QOR`, finds `QOR`, as a name does, after the declarations found by their
15
+ // own names, and the hit says which (`via`).
15
16
  //
16
17
  // The page's search box (web/src/search.ts) and the agent API (server/agent.ts) both search so.
17
18
  export const PLACES = ["name", "statement", "doc"];
@@ -95,7 +96,10 @@ export function search(ix, query, within) {
95
96
  if (tier === 0) {
96
97
  // as the search always ranked a name: the words in its last component, exactly, at its start,
97
98
  // inside it; then the project before the outside world; then the shorter name. A word found
98
- // in a name it folds counts as found in that name.
99
+ // in a name it folds counts as found in that name, and ranks after every declaration found by
100
+ // its own name: a generated name (`_aux_FltRegular_CaseI_…_termR_1`) has no dots, so all of it
101
+ // reads as a last component, and would rank its notation before `FltRegular.caseI` for
102
+ // "caseI flt".
99
103
  let name = names[i];
100
104
  for (const w of order) {
101
105
  const a = folded(w);
@@ -109,7 +113,7 @@ export function search(ix, query, within) {
109
113
  let fit = 0;
110
114
  for (const w of order)
111
115
  fit = Math.max(fit, last === w ? 0 : last.startsWith(w) ? 1 : last.includes(w) ? 2 : 3);
112
- score = fit * 1000 + (ext ? 500 : 0) + Math.min(400, name.length);
116
+ score = (via !== undefined ? 4000 : 0) + fit * 1000 + (ext ? 500 : 0) + Math.min(400, name.length);
113
117
  }
114
118
  else {
115
119
  // fewer words that needed this place first (the rest are in the name), then a word found
@@ -178,6 +178,9 @@ export function linkRefused(v, target) {
178
178
  * Remove from this view makes a copy without it instead. Every other view's scope can change, a
179
179
  * target's view's too (decision 28). */
180
180
  export const fixedScope = (v) => v.id === PROJECT;
181
+ /** Why the Project's scope is not changed (ViewSpec decision 5: never rescoped, the outside world
182
+ * included). */
183
+ export const PROJECT_SCOPE = "The Project always holds everything: Duplicate it for a board that holds less.";
181
184
  /** Why a view cannot be kept at a past build, or null. The Project and a target's view always show
182
185
  * the latest: the one is everyone's way in, and on the other the review is given, which a past
183
186
  * graph cannot take; Save as new view keeps a build in a view of its own. */
@@ -597,11 +600,15 @@ export class ViewBook {
597
600
  /** A view's scope changed by `by`. A scope changed is work done on the board, as a pin dropped is:
598
601
  * a view not kept yet is kept by it (ViewSpec decision 6), so that what was added to it or taken
599
602
  * out of it from the canvas's menu outlives the pages that had it open. A rename carried into the
600
- * scope (`keep` false: server/views.ts, moveDeclaration) is no one's work and keeps nothing. */
603
+ * scope (`keep` false: server/views.ts, moveDeclaration) is no one's work and keeps nothing. The
604
+ * Project's scope stays `all` (ViewSpec decision 5), whoever asks: the page, an agent, a
605
+ * snapshot. */
601
606
  setScope(id, scope, by, keep = true) {
602
607
  const v = this.find(id);
603
608
  if (typeof v === "string")
604
609
  return v;
610
+ if (fixedScope(v))
611
+ return sameQuery(v.scope, scope) ? null : PROJECT_SCOPE;
605
612
  if (sameQuery(v.scope, scope))
606
613
  return null;
607
614
  v.scope = scope;