visualproof 0.0.0-stage → 0.2.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 (146) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +99 -2
  3. package/dist/assets/fonts/JuliaMono-Regular.ttf +0 -0
  4. package/dist/assets/fonts/JuliaMono-RegularItalic.ttf +0 -0
  5. package/dist/assets/fonts/JuliaMono-SemiBold.ttf +0 -0
  6. package/dist/assets/fonts/LICENSE-JuliaMono.txt +93 -0
  7. package/dist/assets/latex/visualproof.sty +308 -0
  8. package/dist/assets/webfonts/LICENSE-Jost.txt +93 -0
  9. package/dist/assets/webfonts/LICENSE-SourceSans3.txt +93 -0
  10. package/dist/assets/webfonts/LICENSE-SourceSerif4.txt +93 -0
  11. package/dist/assets/webfonts/jost-latin-ext-wght-normal.woff2 +0 -0
  12. package/dist/assets/webfonts/jost-latin-wght-normal.woff2 +0 -0
  13. package/dist/assets/webfonts/source-sans-3-greek-wght-italic.woff2 +0 -0
  14. package/dist/assets/webfonts/source-sans-3-greek-wght-normal.woff2 +0 -0
  15. package/dist/assets/webfonts/source-sans-3-latin-ext-wght-italic.woff2 +0 -0
  16. package/dist/assets/webfonts/source-sans-3-latin-ext-wght-normal.woff2 +0 -0
  17. package/dist/assets/webfonts/source-sans-3-latin-wght-italic.woff2 +0 -0
  18. package/dist/assets/webfonts/source-sans-3-latin-wght-normal.woff2 +0 -0
  19. package/dist/assets/webfonts/source-serif-4-greek-wght-italic.woff2 +0 -0
  20. package/dist/assets/webfonts/source-serif-4-greek-wght-normal.woff2 +0 -0
  21. package/dist/assets/webfonts/source-serif-4-latin-ext-wght-italic.woff2 +0 -0
  22. package/dist/assets/webfonts/source-serif-4-latin-ext-wght-normal.woff2 +0 -0
  23. package/dist/assets/webfonts/source-serif-4-latin-wght-italic.woff2 +0 -0
  24. package/dist/assets/webfonts/source-serif-4-latin-wght-normal.woff2 +0 -0
  25. package/dist/extractor/Extract.lean +1180 -0
  26. package/dist/extractor/Usage.lean +900 -0
  27. package/dist/mcp/visualproof-mcp.mjs +476 -0
  28. package/dist/server/access.js +95 -0
  29. package/dist/server/agent.js +3270 -0
  30. package/dist/server/agentdocs.js +35 -0
  31. package/dist/server/agentlibrary.js +202 -0
  32. package/dist/server/agentnotes.js +701 -0
  33. package/dist/server/agentviews.js +703 -0
  34. package/dist/server/askfollow.js +286 -0
  35. package/dist/server/boardspots.js +159 -0
  36. package/dist/server/dirs.js +175 -0
  37. package/dist/server/doctor.js +186 -0
  38. package/dist/server/events.js +198 -0
  39. package/dist/server/export.js +420 -0
  40. package/dist/server/extract.js +204 -0
  41. package/dist/server/fetchurl.js +321 -0
  42. package/dist/server/figures.js +158 -0
  43. package/dist/server/history.js +780 -0
  44. package/dist/server/historyapi.js +304 -0
  45. package/dist/server/hover.js +595 -0
  46. package/dist/server/identity.js +114 -0
  47. package/dist/server/invites.js +241 -0
  48. package/dist/server/layoutthread.js +51 -0
  49. package/dist/server/library.js +600 -0
  50. package/dist/server/libraryroute.js +211 -0
  51. package/dist/server/live.js +1101 -0
  52. package/dist/server/lostfound.js +199 -0
  53. package/dist/server/main.js +1406 -0
  54. package/dist/server/mcptools.js +496 -0
  55. package/dist/server/pastdoc.js +73 -0
  56. package/dist/server/pipeline.js +159 -0
  57. package/dist/server/poppler.js +251 -0
  58. package/dist/server/presence.js +252 -0
  59. package/dist/server/project.js +222 -0
  60. package/dist/server/prompt.js +53 -0
  61. package/dist/server/readonly.js +152 -0
  62. package/dist/server/readonlygate.js +123 -0
  63. package/dist/server/renames.js +268 -0
  64. package/dist/server/review.js +334 -0
  65. package/dist/server/reviewapi.js +188 -0
  66. package/dist/server/snapshot.js +50 -0
  67. package/dist/server/sourcestore.js +473 -0
  68. package/dist/server/status.js +360 -0
  69. package/dist/server/talk.js +476 -0
  70. package/dist/server/tokens.js +221 -0
  71. package/dist/server/usage.js +501 -0
  72. package/dist/server/versions.js +82 -0
  73. package/dist/server/view.js +164 -0
  74. package/dist/server/views.js +1167 -0
  75. package/dist/shared/askfollow.js +46 -0
  76. package/dist/shared/board.js +332 -0
  77. package/dist/shared/build.js +2 -0
  78. package/dist/shared/collab.js +241 -0
  79. package/dist/shared/comment.js +285 -0
  80. package/dist/shared/context.js +157 -0
  81. package/dist/shared/doc/authors.js +98 -0
  82. package/dist/shared/doc/build.js +358 -0
  83. package/dist/shared/doc/latex.js +455 -0
  84. package/dist/shared/doc/markdown.js +159 -0
  85. package/dist/shared/doc/model.js +37 -0
  86. package/dist/shared/doc/order.js +124 -0
  87. package/dist/shared/doc/outline.js +45 -0
  88. package/dist/shared/doc/proof.js +272 -0
  89. package/dist/shared/doc/sections.js +93 -0
  90. package/dist/shared/doc/settings.js +75 -0
  91. package/dist/shared/edgecodec.js +102 -0
  92. package/dist/shared/editor.js +64 -0
  93. package/dist/shared/excerpt.js +87 -0
  94. package/dist/shared/graph.js +16 -0
  95. package/dist/shared/items.js +92 -0
  96. package/dist/shared/keys.js +203 -0
  97. package/dist/shared/layout.js +926 -0
  98. package/dist/shared/lexer.js +130 -0
  99. package/dist/shared/library.js +711 -0
  100. package/dist/shared/lostfound.js +150 -0
  101. package/dist/shared/moves.js +244 -0
  102. package/dist/shared/notecard.js +295 -0
  103. package/dist/shared/noteplace.js +505 -0
  104. package/dist/shared/palette.js +46 -0
  105. package/dist/shared/pastgraph.js +103 -0
  106. package/dist/shared/places.js +80 -0
  107. package/dist/shared/projectnotes.js +244 -0
  108. package/dist/shared/query.js +818 -0
  109. package/dist/shared/review.js +642 -0
  110. package/dist/shared/reviewqueue.js +333 -0
  111. package/dist/shared/ring.js +366 -0
  112. package/dist/shared/scope.js +255 -0
  113. package/dist/shared/scopeedit.js +81 -0
  114. package/dist/shared/search.js +191 -0
  115. package/dist/shared/separate.js +178 -0
  116. package/dist/shared/sharesnap.js +281 -0
  117. package/dist/shared/sticky.js +501 -0
  118. package/dist/shared/timeline.js +73 -0
  119. package/dist/shared/titles.js +300 -0
  120. package/dist/shared/viewgraph.js +157 -0
  121. package/dist/shared/views.js +859 -0
  122. package/dist/web/bundle/app.js +52671 -0
  123. package/dist/web/bundle/edges.js +407 -0
  124. package/dist/web/bundle/layout.js +1010 -0
  125. package/dist/web/bundle/pdfworker.js +48322 -0
  126. package/dist/web/index.html +257 -0
  127. package/dist/web/src/motion.js +430 -0
  128. package/dist/web/src/past.js +224 -0
  129. package/dist/web/src/scene.js +804 -0
  130. package/dist/web/style.css +2548 -0
  131. package/docs/agent-api/README.md +91 -0
  132. package/docs/agent-api/advice.md +108 -0
  133. package/docs/agent-api/export.md +120 -0
  134. package/docs/agent-api/following.md +140 -0
  135. package/docs/agent-api/history.md +142 -0
  136. package/docs/agent-api/library.md +65 -0
  137. package/docs/agent-api/mcp.md +104 -0
  138. package/docs/agent-api/notes.md +93 -0
  139. package/docs/agent-api/reading.md +166 -0
  140. package/docs/agent-api/requests.md +94 -0
  141. package/docs/agent-api/talking.md +100 -0
  142. package/docs/agent-api/tcb.md +135 -0
  143. package/docs/agent-api/views.md +125 -0
  144. package/docs/agent-api/words.md +56 -0
  145. package/package.json +39 -4
  146. package/test/toolchains.json +5 -0
@@ -0,0 +1,164 @@
1
+ // The extractor's graph, turned into what the page loads: card data, both layouts, and the
2
+ // edges as a flat binary array.
3
+ import { readFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { LAYOUT_VERSION } from "../shared/graph.js";
6
+ import { gitSource } from "./history.js";
7
+ import { layOutHere, layOutOffThread } from "./layoutthread.js";
8
+ import { compiledTextHash } from "./status.js";
9
+ import { versionBase, versions } from "./versions.js";
10
+ const MODES = ["namespace", "module"];
11
+ /** The view of an extraction, laid out here (a test, a command run once). */
12
+ export function buildView(p, ex, log, memory = null) {
13
+ const { nodes, edges } = viewParts(p, ex);
14
+ const layouts = {};
15
+ for (const mode of MODES) {
16
+ const t0 = performance.now();
17
+ layouts[mode] = layOutHere(mode, nodes, edges, memory?.[mode] ?? null);
18
+ log(`layout by ${mode}: ${layouts[mode].clusters.length} clusters, ${Math.round(performance.now() - t0)} ms`);
19
+ }
20
+ return assemble(p, ex, nodes, edges, layouts);
21
+ }
22
+ /** The same, both clusterings laid out at once off the server's thread (server/layoutthread.ts),
23
+ * which meanwhile goes on answering. */
24
+ export async function buildViewOffThread(p, ex, log, memory = null) {
25
+ const { nodes, edges } = viewParts(p, ex);
26
+ const laid = await Promise.all(MODES.map(async (mode) => {
27
+ const t0 = performance.now();
28
+ const layout = await layOutOffThread(mode, nodes, edges, memory?.[mode] ?? null);
29
+ log(`layout by ${mode}: ${layout.clusters.length} clusters, ${Math.round(performance.now() - t0)} ms, off the server's thread`);
30
+ return layout;
31
+ }));
32
+ return assemble(p, ex, nodes, edges, { namespace: laid[0], module: laid[1] });
33
+ }
34
+ /** The declarations as the page reads them, the outside ones after the project's, and the edges
35
+ * packed. */
36
+ function viewParts(p, ex) {
37
+ const g = ex.graph;
38
+ // what an opinion is bound to: the version, which a pure rename leaves as it is, made here as if
39
+ // nothing were renamed (the server makes it again under the renames in force: server/versions.ts)
40
+ const vs = versions(versionBase(g));
41
+ const nodes = g.nodes.map((n, i) => {
42
+ const v = { name: n.name, kind: n.kind, module: n.module, ax: n.ax, type: n.type, hash: vs[i] };
43
+ if (vs[i] !== n.hash)
44
+ v.kernel = n.hash;
45
+ if (n.doc)
46
+ v.doc = n.doc;
47
+ if (n.range)
48
+ v.range = n.range;
49
+ if (n.gen !== undefined)
50
+ v.gen = n.gen;
51
+ if (n.also?.length)
52
+ v.also = n.also;
53
+ if (n.flags?.length)
54
+ v.flags = n.flags;
55
+ if (n.leanName)
56
+ v.leanName = n.leanName;
57
+ if (n.display)
58
+ v.display = n.display;
59
+ if (n.interprets?.length)
60
+ v.interprets = n.interprets;
61
+ if (n.rules?.length)
62
+ v.rules = n.rules;
63
+ if (n.proofs?.length)
64
+ v.proofs = n.proofs;
65
+ return v;
66
+ });
67
+ for (const e of g.externals)
68
+ nodes.push({ name: e.name, kind: e.kind, module: e.module, ax: e.ax, ext: true });
69
+ notationStatements(p, nodes);
70
+ const edges = new Int32Array(g.edges.length * 3);
71
+ g.edges.forEach(([s, d, m], i) => {
72
+ edges[3 * i] = s;
73
+ edges[3 * i + 1] = d;
74
+ edges[3 * i + 2] = m;
75
+ });
76
+ return { nodes, edges };
77
+ }
78
+ /** The project's git source and commit as it is read, where it is a git repository. */
79
+ function gitOf(root) {
80
+ const git = gitSource(root);
81
+ return git ? { git } : {};
82
+ }
83
+ function assemble(p, ex, nodes, edges, layouts) {
84
+ const g = ex.graph;
85
+ const meta = {
86
+ schema: 1,
87
+ layoutVersion: LAYOUT_VERSION,
88
+ project: {
89
+ name: p.name,
90
+ root: p.root,
91
+ roots: p.roots,
92
+ ...(p.targets ? { targets: p.targets } : {}),
93
+ toolchain: p.toolchain,
94
+ extractedAt: ex.at,
95
+ extractMs: g.stats.ms,
96
+ ...gitOf(p.root),
97
+ },
98
+ modules: g.modules.map((m) => {
99
+ const file = p.files.get(m.name) ?? null;
100
+ return { name: m.name, file, imports: m.imports, compiled: file ? compiledTextHash(p, m.name, file) : null };
101
+ }),
102
+ nodes,
103
+ projectCount: g.nodes.length,
104
+ axioms: g.axioms,
105
+ axiomSets: g.axiomSets,
106
+ layouts,
107
+ edgeCount: g.edges.length,
108
+ };
109
+ return { meta, edges };
110
+ }
111
+ /** At most this many lines of a notation command make its statement. */
112
+ const NOTATION_LINES = 6;
113
+ /** A notation unit's statement is its command, as written (TCBSpec.md, decision 2): what Lean
114
+ * elaborated it into (a `ParserDescr`, a `Macro`) says nothing a reader can check. Its first
115
+ * lines, its doc comment left out. */
116
+ export function notationStatements(p, nodes) {
117
+ const files = new Map();
118
+ for (const v of nodes) {
119
+ if (v.kind !== "notation" || v.ext || !v.range)
120
+ continue;
121
+ let lines = files.get(v.module);
122
+ if (lines === undefined) {
123
+ const rel = p.files.get(v.module);
124
+ try {
125
+ lines = rel ? readFileSync(join(p.root, rel), "utf8").split("\n") : null;
126
+ }
127
+ catch {
128
+ lines = null;
129
+ }
130
+ files.set(v.module, lines);
131
+ }
132
+ if (!lines)
133
+ continue;
134
+ const text = commandLines(lines, v.range);
135
+ if (!text)
136
+ continue;
137
+ v.type = text;
138
+ // the command as written says what it is where its constants cannot (`infixl`, a `notation`
139
+ // without an unexpander)
140
+ const kw = COMMAND.exec(text)?.[1];
141
+ if (kw && v.display && /^(?:notation|macro|elab) ·/.test(v.display))
142
+ v.display = v.display.replace(/^\S+/, kw);
143
+ }
144
+ }
145
+ /** The keyword of a syntax extension command, past its attributes and modifiers. */
146
+ const COMMAND = /^\s*(?:@\[[^\]]*\]\s*)?(?:(?:local|scoped|private|protected)\s+)*(notation|infixl|infixr|infix|prefix|postfix|macro|elab)\b/;
147
+ /** The lines of a command at `range` ([line, col, endLine, endCol], 1-based lines), its doc comment
148
+ * left out, at most NOTATION_LINES of them. */
149
+ export function commandLines(lines, range) {
150
+ let first = range[0] - 1;
151
+ const last = Math.min(lines.length - 1, range[2] - 1);
152
+ // a doc comment opens the range: what follows its `-/` is the command
153
+ if (/^\s*\/--/.test(lines[first] ?? "")) {
154
+ while (first <= last && !/-\/\s*$/.test(lines[first]))
155
+ first++;
156
+ first++;
157
+ }
158
+ const body = lines.slice(first, last + 1);
159
+ while (body.length && !body[body.length - 1].trim())
160
+ body.pop();
161
+ if (!body.length)
162
+ return null;
163
+ return body.length > NOTATION_LINES ? body.slice(0, NOTATION_LINES).join("\n") + "\n …" : body.join("\n");
164
+ }