visualproof 0.4.4 → 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 (82) hide show
  1. package/README.md +16 -7
  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 +132 -117
  17. package/dist/assets/tips/tour.webp +0 -0
  18. package/dist/mcp/visualproof-mcp.mjs +20 -9
  19. package/dist/server/access.js +31 -1
  20. package/dist/server/accesspage.js +130 -0
  21. package/dist/server/agent.js +143 -50
  22. package/dist/server/askfollow.js +1 -1
  23. package/dist/server/buildwatch.js +133 -0
  24. package/dist/server/deploy.js +995 -0
  25. package/dist/server/doctor.js +15 -3
  26. package/dist/server/film.js +1 -1
  27. package/dist/server/historyapi.js +100 -50
  28. package/dist/server/historythread.js +206 -0
  29. package/dist/server/hover.js +8 -0
  30. package/dist/server/invites.js +113 -20
  31. package/dist/server/live.js +308 -60
  32. package/dist/server/main.js +450 -77
  33. package/dist/server/mcptools.js +33 -20
  34. package/dist/server/presence.js +3 -3
  35. package/dist/server/prompt.js +8 -3
  36. package/dist/server/readonlygate.js +4 -4
  37. package/dist/server/review.js +27 -7
  38. package/dist/server/reviewapi.js +51 -17
  39. package/dist/server/status.js +119 -46
  40. package/dist/server/talk.js +231 -115
  41. package/dist/server/tokens.js +10 -2
  42. package/dist/server/usage.js +51 -0
  43. package/dist/shared/board.js +2 -1
  44. package/dist/shared/build.js +35 -1
  45. package/dist/shared/collab.js +8 -0
  46. package/dist/shared/deploy.js +35 -0
  47. package/dist/shared/keys.js +66 -37
  48. package/dist/shared/layout.js +297 -70
  49. package/dist/shared/libm.js +366 -0
  50. package/dist/shared/lostfound.js +1 -0
  51. package/dist/shared/mentions.js +83 -0
  52. package/dist/shared/palette.js +1 -1
  53. package/dist/shared/query.js +13 -4
  54. package/dist/shared/review.js +91 -21
  55. package/dist/shared/reviewqueue.js +6 -1
  56. package/dist/shared/separate.js +556 -32
  57. package/dist/web/bundle/app.js +5022 -2736
  58. package/dist/web/bundle/edges.js +2 -1
  59. package/dist/web/bundle/layout.js +1026 -80
  60. package/dist/web/index.html +45 -9
  61. package/dist/web/src/canvas.js +47 -34
  62. package/dist/web/src/overview.js +4 -1
  63. package/dist/web/src/reviewqueue.js +52 -19
  64. package/dist/web/src/scene.js +13 -12
  65. package/dist/web/src/status.js +28 -0
  66. package/dist/web/src/theme.js +108 -0
  67. package/dist/web/src/trust.js +271 -0
  68. package/dist/web/style.css +283 -105
  69. package/docs/agent-api/README.md +13 -11
  70. package/docs/agent-api/advice.md +8 -2
  71. package/docs/agent-api/export.md +1 -1
  72. package/docs/agent-api/following.md +11 -12
  73. package/docs/agent-api/history.md +6 -2
  74. package/docs/agent-api/mcp.md +15 -15
  75. package/docs/agent-api/notes.md +1 -1
  76. package/docs/agent-api/reading.md +2 -2
  77. package/docs/agent-api/requests.md +16 -18
  78. package/docs/agent-api/talking.md +60 -55
  79. package/docs/agent-api/tcb.md +21 -21
  80. package/docs/agent-api/views.md +3 -4
  81. package/docs/agent-api/words.md +8 -8
  82. package/package.json +2 -1
@@ -0,0 +1,366 @@
1
+ // The transcendental functions the layout uses, the same on every engine (CanvasSpec, "Dependency
2
+ // order", the same picture everywhere).
3
+ //
4
+ // ECMAScript fixes + − × ÷ and √ to the last bit, but leaves Math.sin, cos, acos, log1p, hypot and
5
+ // the like to each engine: Chrome and Node, two builds of V8, already differ in the last digit of
6
+ // some, and the layout amplifies a last digit into a different picture (a board laid out on the
7
+ // page beside the same board laid out on the server moved 91 of its 184 declarations). So the
8
+ // layout computes them here, from the operations every engine computes alike: ports of the fdlibm
9
+ // routines (Sun's freely distributable libm, as FreeBSD's msun keeps it) that V8 itself runs, and
10
+ // V8's own Math.hypot. On Node they give what Math gives to the last bit, so that no layout the
11
+ // server made before moves (test/libm.test.ts checks them against Node's Math on the inputs the
12
+ // layout has); on any other engine they give the same.
13
+ //
14
+ // Only what the layout needs: arguments past the reach of the medium-sized argument reduction (a
15
+ // quarter of a million radians) are not reduced exactly, and are never asked for.
16
+ // a double's two 32-bit words, read and written through one buffer
17
+ const f64 = new Float64Array(1);
18
+ const u32 = new Uint32Array(f64.buffer);
19
+ /** the index of the high word: the layout runs on little-endian machines, but this does not assume it */
20
+ const HI = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1 ? 1 : 0;
21
+ const LO = 1 - HI;
22
+ function hiWord(x) {
23
+ f64[0] = x;
24
+ return u32[HI] | 0;
25
+ }
26
+ function loWord(x) {
27
+ f64[0] = x;
28
+ return u32[LO] >>> 0;
29
+ }
30
+ function withHi(x, hi) {
31
+ f64[0] = x;
32
+ u32[HI] = hi >>> 0;
33
+ return f64[0];
34
+ }
35
+ function withLo(x, lo) {
36
+ f64[0] = x;
37
+ u32[LO] = lo >>> 0;
38
+ return f64[0];
39
+ }
40
+ function fromWords(hi, lo) {
41
+ u32[HI] = hi >>> 0;
42
+ u32[LO] = lo >>> 0;
43
+ return f64[0];
44
+ }
45
+ /** √(x² + y²), as V8 computes Math.hypot of two numbers: each divided by the larger magnitude,
46
+ * squared and summed (Kahan's compensation, which two terms leave at zero), the square root
47
+ * scaled back. */
48
+ export function hypot(x, y) {
49
+ const ax = Math.abs(x), ay = Math.abs(y);
50
+ if (ax === Infinity || ay === Infinity)
51
+ return Infinity;
52
+ if (ax !== ax || ay !== ay)
53
+ return NaN;
54
+ const max = ax > ay ? ax : ay;
55
+ if (max === 0)
56
+ return 0;
57
+ const a = ax / max, b = ay / max;
58
+ return Math.sqrt(a * a + b * b) * max;
59
+ }
60
+ // fdlibm e_acos.c
61
+ const PI = 3.14159265358979311600e+00;
62
+ const PIO2_HI = 1.57079632679489655800e+00;
63
+ const PIO2_LO = 6.12323399573676603587e-17;
64
+ const pS0 = 1.66666666666666657415e-01;
65
+ const pS1 = -3.25565818622400915405e-01;
66
+ const pS2 = 2.01212532134862925881e-01;
67
+ const pS3 = -4.00555345006794114027e-02;
68
+ const pS4 = 7.91534994289814532176e-04;
69
+ const pS5 = 3.47933107596021167570e-05;
70
+ const qS1 = -2.40339491173441421878e+00;
71
+ const qS2 = 2.02094576023350569471e+00;
72
+ const qS3 = -6.88283971605453293030e-01;
73
+ const qS4 = 7.70381505559019352791e-02;
74
+ /** arccos x, in [0, π]. */
75
+ export function acos(x) {
76
+ const hx = hiWord(x);
77
+ const ix = hx & 0x7fffffff;
78
+ if (ix >= 0x3ff00000) {
79
+ // |x| >= 1
80
+ if (((ix - 0x3ff00000) | loWord(x)) === 0)
81
+ return hx > 0 ? 0.0 : PI + 2.0 * PIO2_LO;
82
+ return NaN;
83
+ }
84
+ if (ix < 0x3fe00000) {
85
+ // |x| < 0.5
86
+ if (ix <= 0x3c600000)
87
+ return PIO2_HI + PIO2_LO;
88
+ const z = x * x;
89
+ const p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));
90
+ const q = 1.0 + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));
91
+ const r = p / q;
92
+ return PIO2_HI - (x - (PIO2_LO - x * r));
93
+ }
94
+ else if (hx < 0) {
95
+ // x < -0.5
96
+ const z = (1.0 + x) * 0.5;
97
+ const p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));
98
+ const q = 1.0 + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));
99
+ const s = Math.sqrt(z);
100
+ const r = p / q;
101
+ const w = r * s - PIO2_LO;
102
+ return PI - 2.0 * (s + w);
103
+ }
104
+ else {
105
+ // x > 0.5
106
+ const z = (1.0 - x) * 0.5;
107
+ const s = Math.sqrt(z);
108
+ const df = withLo(s, 0);
109
+ const c = (z - df * df) / (s + df);
110
+ const p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));
111
+ const q = 1.0 + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));
112
+ const r = p / q;
113
+ const w = r * s + c;
114
+ return 2.0 * (df + w);
115
+ }
116
+ }
117
+ // fdlibm s_log1p.c
118
+ const LN2_HI = 6.93147180369123816490e-01;
119
+ const LN2_LO = 1.90821492927058770002e-10;
120
+ const Lp1 = 6.666666666666735130e-01;
121
+ const Lp2 = 3.999999999940941908e-01;
122
+ const Lp3 = 2.857142874366239149e-01;
123
+ const Lp4 = 2.222219843214978396e-01;
124
+ const Lp5 = 1.818357216161805012e-01;
125
+ const Lp6 = 1.531383769920937332e-01;
126
+ const Lp7 = 1.479819860511658591e-01;
127
+ /** log(1 + x), exact for small x. */
128
+ export function log1p(x) {
129
+ const hx = hiWord(x);
130
+ const ax = hx & 0x7fffffff;
131
+ let k = 1;
132
+ let f = 0, c = 0, hu = 0;
133
+ if (hx < 0x3fda827a) {
134
+ // 1 + x < √2
135
+ if (ax >= 0x3ff00000)
136
+ return x === -1.0 ? -Infinity : NaN;
137
+ if (ax < 0x3e200000) {
138
+ // |x| < 2^-29
139
+ if (ax < 0x3c900000)
140
+ return x;
141
+ return x - x * x * 0.5;
142
+ }
143
+ if (hx > 0 || hx <= (0xbfd2bec4 | 0)) {
144
+ // √2/2 - 1 <= x < √2 - 1
145
+ k = 0;
146
+ f = x;
147
+ hu = 1;
148
+ }
149
+ }
150
+ if (hx >= 0x7ff00000)
151
+ return x + x;
152
+ if (k !== 0) {
153
+ let u;
154
+ if (hx < 0x43400000) {
155
+ u = 1.0 + x;
156
+ hu = hiWord(u);
157
+ k = (hu >> 20) - 1023;
158
+ // the correction term
159
+ c = k > 0 ? 1.0 - (u - x) : x - (u - 1.0);
160
+ c /= u;
161
+ }
162
+ else {
163
+ u = x;
164
+ hu = hiWord(u);
165
+ k = (hu >> 20) - 1023;
166
+ c = 0;
167
+ }
168
+ hu &= 0x000fffff;
169
+ // u, or u/2, normalised into [√2/2, √2]
170
+ if (hu < 0x6a09e) {
171
+ u = withHi(u, hu | 0x3ff00000);
172
+ }
173
+ else {
174
+ k += 1;
175
+ u = withHi(u, hu | 0x3fe00000);
176
+ hu = (0x00100000 - hu) >> 2;
177
+ }
178
+ f = u - 1.0;
179
+ }
180
+ const hfsq = 0.5 * f * f;
181
+ if (hu === 0) {
182
+ // |f| < 2^-20
183
+ if (f === 0) {
184
+ if (k === 0)
185
+ return 0;
186
+ c += k * LN2_LO;
187
+ return k * LN2_HI + c;
188
+ }
189
+ const R = hfsq * (1.0 - 0.66666666666666666 * f);
190
+ if (k === 0)
191
+ return f - R;
192
+ return k * LN2_HI - ((R - (k * LN2_LO + c)) - f);
193
+ }
194
+ const s = f / (2.0 + f);
195
+ const z = s * s;
196
+ const R = z * (Lp1 + z * (Lp2 + z * (Lp3 + z * (Lp4 + z * (Lp5 + z * (Lp6 + z * Lp7))))));
197
+ if (k === 0)
198
+ return f - (hfsq - s * (hfsq + R));
199
+ return k * LN2_HI - ((hfsq - (s * (hfsq + R) + (k * LN2_LO + c))) - f);
200
+ }
201
+ // fdlibm k_sin.c, k_cos.c
202
+ const S1 = -1.66666666666666324348e-01;
203
+ const S2 = 8.33333333332248946124e-03;
204
+ const S3 = -1.98412698298579493134e-04;
205
+ const S4 = 2.75573137070700676789e-06;
206
+ const S5 = -2.50507602534068634195e-08;
207
+ const S6 = 1.58969099521155010221e-10;
208
+ function kernelSin(x, y, iy) {
209
+ const ix = hiWord(x) & 0x7fffffff;
210
+ if (ix < 0x3e400000 && Math.trunc(x) === 0)
211
+ return x;
212
+ const z = x * x;
213
+ const v = z * x;
214
+ const r = S2 + z * (S3 + z * (S4 + z * (S5 + z * S6)));
215
+ if (iy === 0)
216
+ return x + v * (S1 + z * r);
217
+ return x - ((z * (0.5 * y - v * r) - y) - v * S1);
218
+ }
219
+ const C1 = 4.16666666666666019037e-02;
220
+ const C2 = -1.38888888888741095749e-03;
221
+ const C3 = 2.48015872894767294178e-05;
222
+ const C4 = -2.75573143513906633035e-07;
223
+ const C5 = 2.08757232129817482790e-09;
224
+ const C6 = -1.13596475577881948265e-11;
225
+ function kernelCos(x, y) {
226
+ const ix = hiWord(x) & 0x7fffffff;
227
+ if (ix < 0x3e400000 && Math.trunc(x) === 0)
228
+ return 1.0;
229
+ const z = x * x;
230
+ const r = z * (C1 + z * (C2 + z * (C3 + z * (C4 + z * (C5 + z * C6)))));
231
+ if (ix < 0x3fd33333)
232
+ return 1.0 - (0.5 * z - (z * r - x * y));
233
+ const qx = ix > 0x3fe90000 ? 0.28125 : fromWords(ix - 0x00200000, 0);
234
+ const iz = 0.5 * z - qx;
235
+ const a = 1.0 - qx;
236
+ return a - (iz - (z * r - x * y));
237
+ }
238
+ // fdlibm e_rem_pio2.c, without the large arguments' reduction
239
+ const INVPIO2 = 6.36619772367581382433e-01;
240
+ const PIO2_1 = 1.57079632673412561417e+00;
241
+ const PIO2_1T = 6.07710050650619224932e-11;
242
+ const PIO2_2 = 6.07710050630396597660e-11;
243
+ const PIO2_2T = 2.02226624879595063154e-21;
244
+ const PIO2_3 = 2.02226624871116645580e-21;
245
+ const PIO2_3T = 8.47842766036889956997e-32;
246
+ const NPIO2_HW = [
247
+ 0x3ff921fb, 0x400921fb, 0x4012d97c, 0x401921fb, 0x401f6a7a, 0x4022d97c, 0x4025fdbb, 0x402921fb, 0x402c463a, 0x402f6a7a, 0x4031475c,
248
+ 0x4032d97c, 0x40346b9c, 0x4035fdbb, 0x40378fdb, 0x403921fb, 0x403ab41b, 0x403c463a, 0x403dd85a, 0x403f6a7a, 0x40407e4c, 0x4041475c,
249
+ 0x4042106c, 0x4042d97c, 0x4043a28c, 0x40446b9c, 0x404534ac, 0x4045fdbb, 0x4046c6cb, 0x40478fdb, 0x404858eb, 0x404921fb,
250
+ ];
251
+ /** x reduced by a multiple n of π/2 into [-π/4, π/4], as y0 + y1; returns n. */
252
+ const red = new Float64Array(2);
253
+ function remPio2(x) {
254
+ const hx = hiWord(x);
255
+ const ix = hx & 0x7fffffff;
256
+ if (ix <= 0x3fe921fb) {
257
+ red[0] = x;
258
+ red[1] = 0;
259
+ return 0;
260
+ }
261
+ if (ix < 0x4002d97c) {
262
+ // |x| < 3π/4: n = ±1
263
+ if (hx > 0) {
264
+ let z = x - PIO2_1;
265
+ if (ix !== 0x3ff921fb) {
266
+ red[0] = z - PIO2_1T;
267
+ red[1] = (z - red[0]) - PIO2_1T;
268
+ }
269
+ else {
270
+ z -= PIO2_2;
271
+ red[0] = z - PIO2_2T;
272
+ red[1] = (z - red[0]) - PIO2_2T;
273
+ }
274
+ return 1;
275
+ }
276
+ let z = x + PIO2_1;
277
+ if (ix !== 0x3ff921fb) {
278
+ red[0] = z + PIO2_1T;
279
+ red[1] = (z - red[0]) + PIO2_1T;
280
+ }
281
+ else {
282
+ z += PIO2_2;
283
+ red[0] = z + PIO2_2T;
284
+ red[1] = (z - red[0]) + PIO2_2T;
285
+ }
286
+ return -1;
287
+ }
288
+ if (ix > 0x413921fb)
289
+ throw new RangeError("libm: argument out of range");
290
+ // medium size: |x| <= 2^19 π/2
291
+ let t = Math.abs(x);
292
+ const n = Math.trunc(t * INVPIO2 + 0.5);
293
+ const fn = n;
294
+ let r = t - fn * PIO2_1;
295
+ let w = fn * PIO2_1T;
296
+ if (n < 32 && ix !== NPIO2_HW[n - 1]) {
297
+ red[0] = r - w;
298
+ }
299
+ else {
300
+ const j = ix >> 20;
301
+ red[0] = r - w;
302
+ let i = j - ((hiWord(red[0]) >> 20) & 0x7ff);
303
+ if (i > 16) {
304
+ // a second iteration, good to 118 bits
305
+ t = r;
306
+ w = fn * PIO2_2;
307
+ r = t - w;
308
+ w = fn * PIO2_2T - ((t - r) - w);
309
+ red[0] = r - w;
310
+ i = j - ((hiWord(red[0]) >> 20) & 0x7ff);
311
+ if (i > 49) {
312
+ // a third, 151 bits
313
+ t = r;
314
+ w = fn * PIO2_3;
315
+ r = t - w;
316
+ w = fn * PIO2_3T - ((t - r) - w);
317
+ red[0] = r - w;
318
+ }
319
+ }
320
+ }
321
+ red[1] = (r - red[0]) - w;
322
+ if (hx < 0) {
323
+ red[0] = -red[0];
324
+ red[1] = -red[1];
325
+ return -n;
326
+ }
327
+ return n;
328
+ }
329
+ /** sin x, for |x| up to 2^19 π/2. */
330
+ export function sin(x) {
331
+ const ix = hiWord(x) & 0x7fffffff;
332
+ if (ix <= 0x3fe921fb)
333
+ return kernelSin(x, 0, 0);
334
+ if (ix >= 0x7ff00000)
335
+ return NaN;
336
+ const n = remPio2(x);
337
+ switch (n & 3) {
338
+ case 0:
339
+ return kernelSin(red[0], red[1], 1);
340
+ case 1:
341
+ return kernelCos(red[0], red[1]);
342
+ case 2:
343
+ return -kernelSin(red[0], red[1], 1);
344
+ default:
345
+ return -kernelCos(red[0], red[1]);
346
+ }
347
+ }
348
+ /** cos x, for |x| up to 2^19 π/2. */
349
+ export function cos(x) {
350
+ const ix = hiWord(x) & 0x7fffffff;
351
+ if (ix <= 0x3fe921fb)
352
+ return kernelCos(x, 0);
353
+ if (ix >= 0x7ff00000)
354
+ return NaN;
355
+ const n = remPio2(x);
356
+ switch (n & 3) {
357
+ case 0:
358
+ return kernelCos(red[0], red[1]);
359
+ case 1:
360
+ return -kernelSin(red[0], red[1], 1);
361
+ case 2:
362
+ return -kernelCos(red[0], red[1]);
363
+ default:
364
+ return kernelSin(red[0], red[1], 1);
365
+ }
366
+ }
@@ -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
+ }
@@ -26,7 +26,7 @@ export const STATUS_COLORS = {
26
26
  commented: "#2a62c0",
27
27
  stale: "#e69f00",
28
28
  approved: "#009e73",
29
- unreviewed: "#c7c7cc",
29
+ unreviewed: "#a6a29c",
30
30
  trusted: "#b3e2c2",
31
31
  };
32
32
  /** The code's token colours (web/src/highlight.ts). `sorry` is drawn white on its colour. */
@@ -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;