visualproof 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/assets/tips/phone-fingers.light.mp4 +0 -0
  2. package/dist/assets/tips/phone-fingers.light.webp +0 -0
  3. package/dist/assets/tips/tour-agent.webp +0 -0
  4. package/dist/assets/tips/tour-arrange.webp +0 -0
  5. package/dist/assets/tips/tour-artwork.webp +0 -0
  6. package/dist/assets/tips/tour-checks.webp +0 -0
  7. package/dist/assets/tips/tour-keys.webp +0 -0
  8. package/dist/assets/tips/tour-library.webp +0 -0
  9. package/dist/assets/tips/tour-project.webp +0 -0
  10. package/dist/assets/tips/tour-review.webp +0 -0
  11. package/dist/assets/tips/tour-share.webp +0 -0
  12. package/dist/assets/tips/tour-source.webp +0 -0
  13. package/dist/assets/tips/tour-target.webp +0 -0
  14. package/dist/assets/tips/tour-view.webp +0 -0
  15. package/dist/assets/tips/tour.json +125 -115
  16. package/dist/assets/tips/tour.webp +0 -0
  17. package/dist/mcp/visualproof-mcp.mjs +20 -9
  18. package/dist/server/access.js +28 -0
  19. package/dist/server/agent.js +137 -49
  20. package/dist/server/askfollow.js +1 -1
  21. package/dist/server/deploy.js +204 -53
  22. package/dist/server/invites.js +113 -20
  23. package/dist/server/live.js +125 -28
  24. package/dist/server/main.js +216 -69
  25. package/dist/server/mcptools.js +33 -20
  26. package/dist/server/presence.js +3 -3
  27. package/dist/server/prompt.js +8 -3
  28. package/dist/server/readonlygate.js +4 -4
  29. package/dist/server/reviewapi.js +51 -17
  30. package/dist/server/talk.js +231 -115
  31. package/dist/server/tokens.js +10 -2
  32. package/dist/shared/build.js +35 -1
  33. package/dist/shared/collab.js +8 -0
  34. package/dist/shared/keys.js +66 -37
  35. package/dist/shared/lostfound.js +1 -0
  36. package/dist/shared/mentions.js +83 -0
  37. package/dist/shared/query.js +13 -4
  38. package/dist/shared/review.js +91 -21
  39. package/dist/shared/reviewqueue.js +6 -1
  40. package/dist/web/bundle/app.js +3068 -1928
  41. package/dist/web/index.html +45 -9
  42. package/dist/web/src/reviewqueue.js +52 -19
  43. package/dist/web/src/trust.js +271 -0
  44. package/dist/web/style.css +181 -70
  45. package/docs/agent-api/README.md +13 -11
  46. package/docs/agent-api/advice.md +8 -2
  47. package/docs/agent-api/export.md +1 -1
  48. package/docs/agent-api/following.md +11 -12
  49. package/docs/agent-api/history.md +3 -2
  50. package/docs/agent-api/mcp.md +15 -15
  51. package/docs/agent-api/notes.md +1 -1
  52. package/docs/agent-api/reading.md +2 -2
  53. package/docs/agent-api/requests.md +12 -15
  54. package/docs/agent-api/talking.md +60 -55
  55. package/docs/agent-api/tcb.md +21 -21
  56. package/docs/agent-api/views.md +3 -4
  57. package/docs/agent-api/words.md +8 -8
  58. package/package.json +2 -1
@@ -19,18 +19,19 @@ import { isDeclName, LeanHover } from "./hover.js";
19
19
  import { Identities, layoutAuthor } from "./identity.js";
20
20
  import { LAYOUT_VERSION } from "../shared/graph.js";
21
21
  import { MAX_MEMORY_BYTES, readProjectView, Views } from "./views.js";
22
- import { cleanView, defaultAgentName, nameKey, validSession, withoutArtwork } from "../shared/collab.js";
22
+ import { cleanView, defaultAgentName, madeBy, nameKey, validSession, withoutArtwork } from "../shared/collab.js";
23
23
  import { writeSnapshot } from "./snapshot.js";
24
24
  import { lakeTextHash } from "./status.js";
25
25
  import { invalidTemplate } from "../shared/editor.js";
26
26
  import { packEdges } from "../shared/edgecodec.js";
27
- import { Access, hostAllowed, KEY_PATH, loadKey, urlHost } from "./access.js";
27
+ import { Access, fromOwnPage, hostAllowed, KEY_PATH, loadKey, urlHost } from "./access.js";
28
28
  import { asksForPage, sendAccessPage } from "./accesspage.js";
29
29
  import { INVITE_PATH, invalidPersonName, Invites, taken } from "./invites.js";
30
30
  import { AGENT_LEVELS, AgentApi, lower, needOf, refusal } from "./agent.js";
31
31
  import { AgentTokens, bearerOf, DEFAULT_DAYS, invalidAgentName, looksLikeToken, TOKEN_DAYS } from "./tokens.js";
32
32
  import { agentPrompt } from "./prompt.js";
33
- import { MAX_PERSON } from "./talk.js";
33
+ import { forPages, MAX_PERSON, PUBLIC, THREAD } from "./talk.js";
34
+ import { mentioned } from "../shared/mentions.js";
34
35
  import { DEFAULT_JOBS, inGB, jobsAdvice, memoryFloor, onMathlib, UsagePass, mergeUsage, saveMerged, WORKER_PEAK } from "./usage.js";
35
36
  import { extract } from "./extract.js";
36
37
  import { Exporter } from "./export.js";
@@ -47,12 +48,13 @@ import { RESTART_STATUS, supervise } from "./supervise.js";
47
48
  import { stopChildren } from "./children.js";
48
49
  import { filmStatus, serveFilm, useFilm } from "./film.js";
49
50
  import { finalAnswer, readOnlyAllows, ReadOnlyBounds } from "./readonlygate.js";
50
- import { branchProblem, branchToFollow, DEFAULT_POLL_MINUTES, DeployBusy, deployFolder, Deployment, deploySite, ensureClone, isGitAddress, lockDeployment, MIN_POLL_MINUTES, parseRemote, recordedDefault } from "./deploy.js";
51
+ import { branchProblem, branchToFollow, DEFAULT_BUILD_HOURS, DEFAULT_POLL_MINUTES, DeployBusy, deployFolder, Deployment, deploySite, ensureClone, isGitAddress, limitInWords, lockDeployment, MATHLIB_CACHES, MAX_BUILD_HOURS, MIN_BUILD_HOURS, MIN_POLL_MINUTES, parseBuildHours, parseRemote, recordedDefault, sharedMathlibCache } from "./deploy.js";
51
52
  import { shortCommit, slimDeploy } from "../shared/deploy.js";
52
53
  /** The usage, to stderr with status 2 for a command line it cannot read; asked for (`--help`),
53
54
  * to stdout with status 0. */
54
55
  function usage(code = 2) {
55
- (code === 0 ? console.log : console.error)(`usage: visualproof serve <lean-project | git URL> [--branch name] [--poll ${DEFAULT_POLL_MINUTES}] [--root Name]... [--port 4173] [--host 127.0.0.1]
56
+ (code === 0 ? console.log : console.error)(`usage: visualproof serve <lean-project | git URL> [--branch name] [--poll ${DEFAULT_POLL_MINUTES}] [--build-timeout ${DEFAULT_BUILD_HOURS}]
57
+ [--mathlib-cache shared|own] [--root Name]... [--port 4173] [--host 127.0.0.1]
56
58
  [--site dir] [--cache dir] [--graph saved.json]
57
59
  [--identity-header X-Forwarded-User] [--editor URL-template]
58
60
  [--agents read|advise|full] [--access-key-file file] [--public] [--jobs ${DEFAULT_JOBS}]
@@ -80,6 +82,13 @@ function usage(code = 2) {
80
82
  --branch the branch followed (default: the remote's default branch); never a pull request's or
81
83
  a fork's
82
84
  --poll how often the remote is asked for the branch's head, in minutes (default ${DEFAULT_POLL_MINUTES})
85
+ --build-timeout the hours past which \`lake build\` is stopped and the build failed, its commit
86
+ not tried again (default ${DEFAULT_BUILD_HOURS}; ${MIN_BUILD_HOURS} to ${MAX_BUILD_HOURS}, fractions too: 1.5)
87
+ --mathlib-cache where \`lake exe cache get\` keeps Mathlib's files: shared (the default) — the
88
+ user's, as their own builds' (~/.cache/mathlib, or MATHLIB_CACHE_DIR), so that a build
89
+ fetches only what they have not; own — the deployment's, in its folder of the cache
90
+ (deploy/<repo>-<hash>/mathlib-cache/): about 0.45 GB, the version of Mathlib checked
91
+ out alone (\`lake exe cache clean\` after each fetch), removed with that folder
83
92
 
84
93
  --root what to read: a library of the lakefile (the modules Lake builds of it) or a module;
85
94
  repeatable. By default the lakefile's default targets.
@@ -154,7 +163,8 @@ function usage(code = 2) {
154
163
  may read (a showcase); never for a private one.
155
164
 
156
165
  --public-url the address people reach this server at, when it is not the one their browser
157
- sends (a proxy in front): the prompt Share makes for an agent tells it this address.
166
+ sends (a proxy in front): the links Share and Copy link make, and the prompt Share
167
+ makes for an agent, carry it.
158
168
 
159
169
  --allowed-host without --access-key-file, a name this server is reached by; repeatable. A
160
170
  server without a key answers only requests for an IP address, localhost (and the names
@@ -200,7 +210,7 @@ function parseArgs(argv) {
200
210
  console.error(`visualproof: VISUALPROOF_UPDATES=${fromEnv}: say auto, notify or off`);
201
211
  process.exit(2);
202
212
  }
203
- const o = { cmd, path: "", roots: [], port: 4173, host: "127.0.0.1", site: null, cache: null, graph: null, out: null, label: "VisualProof", identityHeader: null, editor: null, agents: "full", accessKeyFile: null, jobs: DEFAULT_JOBS, publicUrl: null, allowedHosts: [], libraryLimit: DEFAULT_LIBRARY_LIMIT, sha: null, publicRead: false, recipe: null, png: false, svg: false, screen: { w: 1920, h: 1200 }, updates: UPDATE_MODES.includes(fromEnv) ? fromEnv : "auto", remote: null, branch: null, poll: null };
213
+ const o = { cmd, path: "", roots: [], port: 4173, host: "127.0.0.1", site: null, cache: null, graph: null, out: null, label: "VisualProof", identityHeader: null, editor: null, agents: "full", accessKeyFile: null, jobs: DEFAULT_JOBS, publicUrl: null, allowedHosts: [], libraryLimit: DEFAULT_LIBRARY_LIMIT, sha: null, publicRead: false, recipe: null, png: false, svg: false, screen: { w: 1920, h: 1200 }, updates: UPDATE_MODES.includes(fromEnv) ? fromEnv : "auto", remote: null, branch: null, poll: null, buildHours: null, mathlibCache: null };
204
214
  for (let i = 0; i < rest.length; i++) {
205
215
  const a = rest[i];
206
216
  const val = () => rest[++i] ?? usage();
@@ -279,6 +289,22 @@ function parseArgs(argv) {
279
289
  }
280
290
  o.poll = m;
281
291
  }
292
+ else if (a === "--build-timeout" && cmd === "serve") {
293
+ const h = parseBuildHours(val());
294
+ if (typeof h !== "number") {
295
+ console.error(`visualproof: ${h.error}`);
296
+ process.exit(2);
297
+ }
298
+ o.buildHours = h;
299
+ }
300
+ else if (a === "--mathlib-cache" && cmd === "serve") {
301
+ const v = val();
302
+ if (!MATHLIB_CACHES.includes(v)) {
303
+ console.error(`visualproof: --mathlib-cache ${v.slice(0, 40)}: say shared (the user's Mathlib cache, as their builds': the default) or own (the deployment's, in its folder of the cache)`);
304
+ process.exit(2);
305
+ }
306
+ o.mathlibCache = v;
307
+ }
282
308
  else if (a === "--updates" && cmd === "serve") {
283
309
  const mode = val();
284
310
  if (!UPDATE_MODES.includes(mode))
@@ -331,9 +357,14 @@ function parseArgs(argv) {
331
357
  }
332
358
  o.remote = r;
333
359
  }
334
- else if (o.branch !== null || o.poll !== null) {
335
- console.error("visualproof: --branch and --poll go with a git address (serve https://github.com/owner/repo): a folder is read as its owner's builds leave it");
336
- process.exit(2);
360
+ else {
361
+ // what is about following a branch and building it: a folder is never built (DeploySpec
362
+ // decision 15)
363
+ const given = [["--branch", o.branch], ["--poll", o.poll], ["--build-timeout", o.buildHours], ["--mathlib-cache", o.mathlibCache]].filter(([, v]) => v !== null).map(([n]) => n);
364
+ if (given.length) {
365
+ console.error(`visualproof: ${given.length > 1 ? `${given.slice(0, -1).join(", ")} and ${given[given.length - 1]} go` : `${given[0]} goes`} with a git address (serve https://github.com/owner/repo): a folder is read as its owner's builds leave it, never built`);
366
+ process.exit(2);
367
+ }
337
368
  }
338
369
  // read-only for whoever comes, beside those the key or a link lets in: without a key, everyone is in
339
370
  // already; behind a sign-in, there is nobody else
@@ -514,42 +545,65 @@ export class App {
514
545
  return sendGz(req, res, a.gz.body, a.gz.type);
515
546
  sendJson(res, a.body, a.status, a.headers);
516
547
  }
517
- /** Talking with an agent (AgentSpec decision 8), for pages: an agent's conversation (GET), and a
518
- * message to it (POST) — from a person with a name, to an agent that is not offline (409
519
- * otherwise: one listening has it at once, one thinking or working at its next wait), at most so
520
- * many a minute. The agent is named as presence names it. */
548
+ /** The conversations (CollabSpec decision 13, AgentSpec decision 8), for pages: a channel read
549
+ * (GET ?channel=public|<agent id>&before=<id>, the newest 200 first) and a message written in it
550
+ * (POST {channel, text, place}). Everyone with a name reads and writes the public channel; an
551
+ * agent's private channel is its maker's alone (shared/collab.ts, madeBy: 403 to anyone else).
552
+ * A read-only reader neither sees nor writes any (403), whatever the page sends; agents talk
553
+ * through their API. A private channel cannot be written to while its agent is offline (409); a
554
+ * mention of it in the public channel can, and is handed to it when it comes back. At most so
555
+ * many messages a minute, a person's in every channel together. */
521
556
  async chat(req, res, url) {
522
557
  const live = this.live;
523
- if (req.method === "GET") {
524
- const id = url.searchParams.get("agent") ?? "";
525
- const tok = live.presence.tokenOf(id);
526
- if (!tok)
527
- return sendJson(res, { error: "There is no such agent: only an agent with a token of its own can be talked to." }, 404);
528
- return sendJson(res, { agent: { id, name: live.tokens.get(tok)?.name ?? null, talk: live.talk.talk(tok) }, messages: live.talk.thread(tok) });
529
- }
530
- if (req.method !== "POST")
558
+ if (req.method !== "GET" && req.method !== "POST")
531
559
  return sendJson(res, { error: "/api/chat answers GET and POST." }, 405);
560
+ if (this.readOnlyOf.has(req))
561
+ return sendJson(res, { error: "This page is read-only.", readOnly: true }, 403);
532
562
  if (this.ids.kind(req) === "agent")
533
- return sendJson(res, { error: "Agents answer through their API.", hint: "POST /api/agent/reply." }, 403);
563
+ return sendJson(res, { error: "Agents talk through their API.", hint: "GET /api/agent/channel, POST /api/agent/reply." }, 403);
534
564
  const me = this.ids.who(req);
535
565
  if (!me)
536
- return sendJson(res, { error: "Say who you are first: a message is sent under your name.", who: true }, 401);
566
+ return sendJson(res, { error: "Say who you are first: the conversations are for people with a name, and a message is sent under yours.", who: true }, 401);
567
+ const who = { name: me, person: this.ids.person(req)?.id ?? null };
568
+ /** the channel a request names: the public one, or an agent's private one that is this
569
+ * reader's — 404 where there is no such agent, 403 where it is someone else's */
570
+ const channelOf = (raw) => {
571
+ if (raw === "public" || raw === undefined || raw === null || raw === "")
572
+ return { key: PUBLIC, agent: null };
573
+ const tok = typeof raw === "string" ? live.presence.tokenOf(raw) : null;
574
+ const record = tok ? live.tokens.get(tok) : undefined;
575
+ if (!tok || !record)
576
+ return { status: 404, body: { error: "There is no such channel: public, or the id of an agent with a token of its own." } };
577
+ if (!madeBy(record, who))
578
+ return { status: 403, body: { error: `${record.name}'s private channel is ${record.by}'s, who made its token: nobody else reads or writes it.`, private: true } };
579
+ return { key: tok, agent: { id: raw, record } };
580
+ };
581
+ if (req.method === "GET") {
582
+ const c = channelOf(url.searchParams.get("channel") ?? url.searchParams.get("agent"));
583
+ if ("status" in c)
584
+ return sendJson(res, c.body, c.status);
585
+ const raw = url.searchParams.get("before");
586
+ const before = raw && /^\d{1,9}$/.test(raw) ? Number(raw) : null;
587
+ const messages = live.talk.thread(c.key, THREAD, before).map(forPages);
588
+ if (!c.agent)
589
+ return sendJson(res, { channel: PUBLIC, messages });
590
+ return sendJson(res, { channel: c.agent.id, agent: { id: c.agent.id, name: c.agent.record.name, talk: live.talk.talk(c.key) }, messages });
591
+ }
537
592
  const r = await this.json(req, 1 << 16);
538
593
  if (r.error !== undefined)
539
594
  return sendJson(res, { error: `The body is ${r.error}.` }, 400);
540
595
  const b = (r.body ?? {});
541
- const tok = typeof b.agent === "string" ? live.presence.tokenOf(b.agent) : null;
542
- if (!tok)
543
- return sendJson(res, { error: "There is no such agent: only an agent with a token of its own can be talked to." }, 404);
544
- const name = live.tokens.get(tok)?.name ?? "The agent";
545
- if (live.talk.state(tok) === "offline")
546
- return sendJson(res, { error: "offline", message: `${name} is offline: it can be written to once it listens again.` }, 409);
596
+ const c = channelOf(b.channel ?? b.agent);
597
+ if ("status" in c)
598
+ return sendJson(res, c.body, c.status);
599
+ if (c.agent && live.talk.state(c.key) === "offline")
600
+ return sendJson(res, { error: "offline", message: `${c.agent.record.name} is offline: it can be written to once it listens again.` }, 409);
547
601
  const text = typeof b.text === "string" ? b.text.trim() : "";
548
602
  if (!text)
549
603
  return sendJson(res, { error: "The message is empty." }, 400);
550
604
  if (text.length > MAX_PERSON)
551
605
  return sendJson(res, { error: `A message is at most ${MAX_PERSON.toLocaleString("en")} characters.` }, 400);
552
- const wait = live.talk.allow("person", me);
606
+ const wait = live.talk.allow("person", who.person ? `p:${who.person}` : `n:${nameKey(me)}`);
553
607
  if (wait)
554
608
  return sendJson(res, { error: `Too many messages at once: wait ${wait} s.`, retryAfter: wait }, 429, { "retry-after": String(wait) });
555
609
  // where the writer was, as the page says it, bounded: a selection can be a long query; a private
@@ -558,17 +612,23 @@ export class App {
558
612
  const at = view ? this.agents.placeOf(view) : null;
559
613
  const clip = (x, n) => (x !== null && x.length > n ? x.slice(0, n - 1) + "…" : x);
560
614
  const where = at ? { inWords: clip(at.inWords, 600), view: at.view, declaration: clip(at.declaration, 300), selection: clip(at.selection, 300) } : null;
561
- const message = live.talk.post(tok, { from: me, kind: "person", text, where });
562
- return sendJson(res, { ok: true, message });
563
- }
564
- /** A new conversation with an agent (AgentSpec decision 8, the owner's decision of 2026-10-11):
565
- * a divider, from anyone who may write to it — a person with a name — and held to the rate of
566
- * their messages; an offline agent's too, so that its next session starts clean. One right after
615
+ // the names it mentions; in the public channel, the agents among them are handed it
616
+ const can = live.mentionable();
617
+ const mentions = mentioned(text, can.names);
618
+ const to = c.agent ? [] : [...new Set(mentions.flatMap((n) => can.agents.get(nameKey(n)) ?? []))];
619
+ const message = live.talk.post(c.key, { from: me, kind: "person", text, ...(mentions.length ? { mentions } : {}), where, to });
620
+ return sendJson(res, { ok: true, channel: c.agent?.id ?? PUBLIC, message: forPages(message) });
621
+ }
622
+ /** A new conversation in an agent's private channel (AgentSpec decision 8, the owner's decisions
623
+ * of 2026-10-11 and 2026-10-19): a divider, from its maker alone, held to the rate of their
624
+ * messages; an offline agent's too, so that its next session starts clean. One right after
567
625
  * another divides nothing: it is answered `unchanged`, and neither written nor counted. */
568
626
  async chatNew(req, res) {
569
627
  const live = this.live;
570
628
  if (req.method !== "POST")
571
629
  return sendJson(res, { error: "/api/chat/new answers POST." }, 405);
630
+ if (this.readOnlyOf.has(req))
631
+ return sendJson(res, { error: "This page is read-only.", readOnly: true }, 403);
572
632
  if (this.ids.kind(req) === "agent")
573
633
  return sendJson(res, { error: "A new conversation is for people to start." }, 403);
574
634
  const me = this.ids.who(req);
@@ -579,14 +639,19 @@ export class App {
579
639
  return sendJson(res, { error: `The body is ${r.error}.` }, 400);
580
640
  const b = (r.body ?? {});
581
641
  const tok = typeof b.agent === "string" ? live.presence.tokenOf(b.agent) : null;
582
- if (!tok)
583
- return sendJson(res, { error: "There is no such agent: only an agent with a token of its own can be talked to." }, 404);
642
+ const record = tok ? live.tokens.get(tok) : undefined;
643
+ if (!tok || !record)
644
+ return sendJson(res, { error: "There is no such agent: only an agent with a token of its own has a private channel." }, 404);
645
+ const person = this.ids.person(req)?.id ?? null;
646
+ if (!madeBy(record, { name: me, person }))
647
+ return sendJson(res, { error: `Only ${record.by}, who made ${record.name}'s token, starts a new conversation with it.`, private: true }, 403);
584
648
  if (live.talk.fresh(tok))
585
649
  return sendJson(res, { ok: true, unchanged: true, divider: null, message: "Nothing was said since the conversation began: it is new already." });
586
- const wait = live.talk.allow("person", me);
650
+ const wait = live.talk.allow("person", person ? `p:${person}` : `n:${nameKey(me)}`);
587
651
  if (wait)
588
652
  return sendJson(res, { error: `Too many at once: wait ${wait} s.`, retryAfter: wait }, 429, { "retry-after": String(wait) });
589
- return sendJson(res, { ok: true, divider: live.talk.restart(tok, me) });
653
+ const divider = live.talk.restart(tok, me);
654
+ return sendJson(res, { ok: true, divider: divider && forPages(divider) });
590
655
  }
591
656
  /** Asking others to follow (CollabSpec decision 10, the owner's decision of 2026-10-12), for pages:
592
657
  * POST /api/ask {token, to?} — the page whose event stream holds `token` asks everyone on the
@@ -664,10 +729,13 @@ export class App {
664
729
  // the server as the prompt names it
665
730
  const address = this.publicUrl ?? reachedAt(req);
666
731
  if (path === "/api/share/agents/prompt") {
667
- // a token that ended has no prompt: it lets nothing in
732
+ // a token that ended has no prompt: it lets nothing in. Its maker alone is shown it again (the
733
+ // owner's decision of 2026-10-19): whoever holds the token reads its private channel
668
734
  const t = typeof b.id === "string" ? tokens.token(b.id) : null;
669
735
  if (!t)
670
736
  return sendJson(res, { error: "There is no such token in force." }, 404);
737
+ if (!madeBy(t.record, { name: me, person: this.ids.person(req)?.id ?? null }))
738
+ return sendJson(res, { error: `Only ${t.record.by}, who made it, is shown this token's prompt again: whoever holds a token reads its agent's private channel.`, maker: false }, 403);
671
739
  return sendJson(res, { token: AgentTokens.info(t.record), prompt: agentPrompt({ url: address, token: t.token, record: t.record }) });
672
740
  }
673
741
  if (path !== "/api/share/agents")
@@ -685,21 +753,23 @@ export class App {
685
753
  const days = b.days ?? DEFAULT_DAYS;
686
754
  if (!TOKEN_DAYS.includes(days))
687
755
  return sendJson(res, { error: `days is one of ${TOKEN_DAYS.join(", ")}.` }, 400);
688
- const made = tokens.create({ name: name.trim(), by: me, level, days: days });
756
+ const made = tokens.create({ name: name.trim(), by: me, person: this.ids.person(req)?.id ?? null, level, days: days });
689
757
  const prompt = agentPrompt({ url: address, token: made.token, record: made.record });
690
758
  return sendJson(res, { token: AgentTokens.info(made.record), prompt, tokens: tokens.inForce().map(AgentTokens.info) });
691
759
  }
692
760
  /** Inviting a person (CollabSpec decision 9), for people: the personal links in force (GET), a new
693
761
  * one for a person named in the body (POST), and revoking one (POST …/revoke). Making and
694
762
  * revoking need a name: who made a link, and who revoked it, is said in Share. The link itself
695
- * is answered once, to whoever made it: the server keeps only its digest (server/invites.ts). */
763
+ * is answered once to whoever made it, and again to its holder alone (`mine`). */
696
764
  async sharePeople(req, res, url) {
697
765
  if (this.ids.kind(req) === "agent")
698
- return sendJson(res, { error: "Personal links are for people: an agent cannot make, list or revoke them." }, 403);
766
+ return sendJson(res, { error: "Personal links are for people: an agent cannot make, list, show or revoke them." }, 403);
699
767
  if (this.ids.header)
700
768
  return sendJson(res, { error: "Names come from the sign-in in front of this server: it has no personal links." }, 404);
701
769
  const invites = this.live.invites;
702
770
  const path = url.pathname.replace(/\/+$/, "");
771
+ if (path === "/api/share/people/mine" || path === "/api/share/people/mine/renew")
772
+ return this.myLink(req, res, path);
703
773
  const list = () => invites.inForce().map(Invites.info);
704
774
  if (path === "/api/share/people" && req.method === "GET")
705
775
  return sendJson(res, { invites: list() });
@@ -729,6 +799,38 @@ export class App {
729
799
  const link = `${this.publicUrl ?? reachedAt(req)}${INVITE_PATH}${made.token}`;
730
800
  return sendJson(res, { invite: Invites.info(made.record), link, invites: list() });
731
801
  }
802
+ /** The personal link a page came by, for its holder alone (CollabSpec decision 9, the owner's
803
+ * decision of 2026-10-19): shown again (POST /api/share/people/mine; `link` null for a link made
804
+ * before 0.6.0, of which the server kept only the digest), or made anew (POST …/mine/renew,
805
+ * `{stream}` the event stream of the page asking, which stays open) — the same id under a new
806
+ * secret, the old link and the browsers it let in cut off, this browser given the new cookie.
807
+ * Whoever else asks is refused: its maker, a guest, an agent; a read-only reader's page posts
808
+ * nothing here (server/readonlygate.ts). Asked for by POST, as an agent's prompt is, so that the
809
+ * browser sends its Origin and the link names the server as the page reached it. */
810
+ async myLink(req, res, path) {
811
+ const p = this.ids.person(req);
812
+ if (!p)
813
+ return sendJson(res, { error: "A personal link is shown to its holder alone, in a browser it let in: this page came by none.", holder: false }, 403);
814
+ if (req.method !== "POST")
815
+ return sendJson(res, { error: `${path} answers POST.` }, 405);
816
+ const invites = this.live.invites;
817
+ const address = this.publicUrl ?? reachedAt(req);
818
+ if (path === "/api/share/people/mine") {
819
+ const token = invites.tokenOf(p.id);
820
+ return sendJson(res, { invite: Invites.info(p), link: token ? `${address}${INVITE_PATH}${token}` : null });
821
+ }
822
+ const r = await this.json(req, 4096);
823
+ if (r.error !== undefined)
824
+ return sendJson(res, { error: `The body is ${r.error}.` }, 400);
825
+ const keep = r.body?.stream;
826
+ const made = invites.renew(p.id, { keep: typeof keep === "string" ? keep : undefined });
827
+ if (!made)
828
+ return sendJson(res, { error: "There is no such personal link in force." }, 404);
829
+ // this browser stays in: the cookie of the new link, beside what the request was given already
830
+ const set = res.getHeader("set-cookie");
831
+ res.setHeader("set-cookie", [...(Array.isArray(set) ? set : set === undefined ? [] : [String(set)]), invites.cookie(made.record)]);
832
+ return sendJson(res, { invite: Invites.info(made.record), link: `${address}${INVITE_PATH}${made.token}` });
833
+ }
732
834
  /** Read-only links (CollabSpec decision 11), for people: every link (GET), a new one (POST), and
733
835
  * revoking one (POST …/revoke). Anyone let in may make one; revoking needs a name, which Share
734
836
  * says beside the link. A server open to all, or behind a sign-in, has none. */
@@ -777,7 +879,7 @@ export class App {
777
879
  if (this.access && asksForPage(req, path) && (!c || !this.letIn(req)))
778
880
  return sendAccessPage(res, "link", this.publicRead);
779
881
  if (c)
780
- return sendText(req, res, revokedWords(c.record, "personal") + "\n", "text/plain; charset=utf-8", 410);
882
+ return sendText(req, res, endedWords(c) + "\n", "text/plain; charset=utf-8", 410);
781
883
  sendJson(res, { error: "not found" }, 404);
782
884
  }
783
885
  /** A read-only link opened (CollabSpec decision 11): the browser is given the cookie that lets
@@ -940,6 +1042,10 @@ export class App {
940
1042
  // API, the MCP server's file
941
1043
  if (this.hostNames && !hostAllowed(req.headers.host, this.hostNames))
942
1044
  return this.refuseHost(req, res, path);
1045
+ // what may write, only from a page of this server's own (server/access.ts, fromOwnPage): a page
1046
+ // of another site, or of another port of this host, would send this server's cookies with it
1047
+ if (!fromOwnPage(req.method, req.headers, this.publicUrl))
1048
+ return sendJson(res, { error: "A page of another site cannot change anything here." }, 403);
943
1049
  // every route; whatever one throws, handle() answers
944
1050
  {
945
1051
  // an agent's own token (server/tokens.ts) lets it into its API alone: the page and the page's
@@ -968,7 +1074,13 @@ export class App {
968
1074
  if (path.startsWith(READONLY_PATH))
969
1075
  return this.enterReadOnly(req, res, path.slice(READONLY_PATH.length), path);
970
1076
  const link = this.ids.link(req);
971
- const cookies = link && "ended" in link ? [live.invites.forget()] : [];
1077
+ // a link that ended: its cookie is forgotten as a page loads, once the page has said so. Not
1078
+ // before: the page's requests meanwhile are told (a browser the key lets in too, as a guest,
1079
+ // by /api/identity: web/src/people.ts); and the browser that made a link anew has the new
1080
+ // cookie under the same name, which a request of its pages still on its way with the old one
1081
+ // would answer with the forgetting after it
1082
+ const forget = link && "ended" in link && (path === "/" || path === "/index.html" || asksForPage(req, path));
1083
+ const cookies = forget ? [live.invites.forget()] : [];
972
1084
  const ro = this.access && !this.ids.header ? live.readOnly.ofCookie(req.headers.cookie) : null;
973
1085
  if (ro && "ended" in ro)
974
1086
  cookies.push(live.readOnly.forget());
@@ -982,7 +1094,7 @@ export class App {
982
1094
  // page, reloaded, says the link no longer opens the site (decision 7: to a browser, the
983
1095
  // page of a link that does not, which names nobody); the cookie is forgotten there, once
984
1096
  // it has been said
985
- const revoked = reader === null && this.ids.kind(req) !== "agent" ? (link && "ended" in link ? revokedWords(link.record, "personal") : ro && "ended" in ro ? revokedWords(ro.link, "read-only") : null) : null;
1097
+ const revoked = reader === null && this.ids.kind(req) !== "agent" ? (link && "ended" in link ? endedWords(link) : ro && "ended" in ro ? revokedWords(ro.link, "read-only") : null) : null;
986
1098
  if (revoked) {
987
1099
  if (asksForPage(req, path)) {
988
1100
  res.setHeader("set-cookie", cookies);
@@ -1074,8 +1186,13 @@ export class App {
1074
1186
  return pdfjsAsset(res, path);
1075
1187
  // with Lean's language server as it is (server/hover.ts): what is open, what crashed
1076
1188
  // a read-only reader is told how the server is, not its log nor where its review is kept
1189
+ // `?brief`: the build status without its files, which the page reads by GET /api/build
1077
1190
  if (path === "/api/status") {
1078
- const st = { ...live.status(), lean: this.hover.state() };
1191
+ const st = { ...live.status(url.searchParams.has("brief")), lean: this.hover.state() };
1192
+ // the address people reach the server at (--public-url): links of it are this site's, and the
1193
+ // page makes its own with it (CollabSpec, "Copied links")
1194
+ if (this.publicUrl)
1195
+ st.publicUrl = this.publicUrl;
1079
1196
  if (this.readOnlyOf.get(req) !== undefined) {
1080
1197
  delete st.log;
1081
1198
  st.review = { ...st.review, folder: undefined };
@@ -1155,7 +1272,13 @@ export class App {
1155
1272
  // the review (ReviewSpec.md): the whole of it, as a page takes it on, with the lines of its
1156
1273
  // logs that cannot be read; tagged with its revision, compressed once a revision
1157
1274
  if (path === "/api/review" && req.method === "GET")
1158
- return sendReview(req, res, live.review);
1275
+ return sendRevision(req, res, live.review, live.review.tag(), () => live.review.wholeText());
1276
+ // the whole build status, tagged with its revision (the owner's decision of 2026-10-19): what
1277
+ // changes after comes by the event stream
1278
+ if (path === "/api/build" && req.method === "GET") {
1279
+ const b = live.buildWhole();
1280
+ return sendRevision(req, res, live, b.tag, () => b.text);
1281
+ }
1159
1282
  if (path === "/api/review" && req.method === "POST") {
1160
1283
  // an opinion, a target, a trusted prefix or a key declaration is recorded under the
1161
1284
  // reader's name (CollabSpec decision 3), not one in the body; what it is about is
@@ -1181,11 +1304,11 @@ export class App {
1181
1304
  return this.export(req, res, url, agent, reader !== undefined);
1182
1305
  // who the reader is (CollabSpec decisions 3 and 9): the name their page gives, the proxy's, or
1183
1306
  // their personal link's — with the link, and whether the page's own name is a link holder's
1184
- // and not theirs; a link revoked says by whom
1307
+ // and not theirs; a link revoked says by whom, one made anew since this browser had it, when
1185
1308
  if (path === "/api/identity" && req.method === "GET") {
1186
1309
  const person = this.ids.person(req);
1187
1310
  const holder = this.ids.taken(req);
1188
- const ended = link && "ended" in link ? link.record : null;
1311
+ const ended = link && "ended" in link ? link : null;
1189
1312
  if (reader !== undefined)
1190
1313
  return sendJson(res, { mode: this.ids.mode, name: null, readOnly: { by: reader === "public" ? "public" : "link" } });
1191
1314
  return sendJson(res, {
@@ -1193,7 +1316,8 @@ export class App {
1193
1316
  name: this.ids.who(req),
1194
1317
  ...(person ? { person: Invites.info(person) } : {}),
1195
1318
  ...(holder ? { taken: taken(holder) } : {}),
1196
- ...(ended ? { revoked: { by: ended.revokedBy, at: ended.revoked, name: ended.name } } : {}),
1319
+ ...(ended?.ended === "revoked" ? { revoked: { by: ended.record.revokedBy, at: ended.record.revoked, name: ended.record.name } } : {}),
1320
+ ...(ended?.ended === "replaced" ? { replaced: { at: ended.at, name: ended.record.name } } : {}),
1197
1321
  });
1198
1322
  }
1199
1323
  if (path === "/api/identity" && req.method === "POST")
@@ -1212,13 +1336,14 @@ export class App {
1212
1336
  // agents have no artwork (ExportSpec decision 19): the page draws it
1213
1337
  if (agent && name)
1214
1338
  live.presence.agentBeat(name, withoutArtwork(cleanView(b.view)));
1215
- else if (!live.beat(b.token, priv ? null : name, priv ? null : cleanView(b.view), !priv && b.idle === true, priv, !!this.ids.person(req)))
1339
+ else if (!live.beat(b.token, priv ? null : name, priv ? null : cleanView(b.view), !priv && b.idle === true, priv, !!this.ids.person(req), name))
1216
1340
  return sendJson(res, { error: "This heartbeat is not from an open event stream of this page's: it is sent with the token the stream says hello with.", stream: false }, 403);
1217
1341
  return sendJson(res, { ok: true });
1218
1342
  }
1219
1343
  if (path === "/api/events") {
1220
1344
  const session = url.searchParams.get("session");
1221
- return live.subscribe(res, validSession(session) ? session : null, this.ids.person(req)?.id ?? null, reader ?? null, this.toldAll(req));
1345
+ // `build=delta`: the page takes the build status as changes (a page of 0.6.0 or later)
1346
+ return live.subscribe(res, validSession(session) ? session : null, this.ids.person(req)?.id ?? null, reader ?? null, this.toldAll(req), url.searchParams.get("build") === "delta", this.ids.who(req));
1222
1347
  }
1223
1348
  // what happened (CollabSpec decision 5): what the server stored; the review's own history the
1224
1349
  // page reads from the review
@@ -1373,6 +1498,13 @@ export class App {
1373
1498
  function revokedWords(r, kind) {
1374
1499
  return `This ${kind} link was revoked by ${r.revokedBy} on ${(r.revoked ?? "").slice(0, 10)}. Ask whoever ${kind === "personal" ? "invited you" : "gave it to you"} for a new one.`;
1375
1500
  }
1501
+ /** What a personal link that lets nobody in any more is told (410): revoked, by whom and when, or
1502
+ * made anew by its holder, and when (CollabSpec decision 9). */
1503
+ function endedWords(c) {
1504
+ if (c.ended === "revoked")
1505
+ return revokedWords(c.record, "personal");
1506
+ return `This personal link was made anew on ${c.at.slice(0, 10)}: it lets nobody in any more. Open the new one instead (My personal link, in the menu under your name where it was made anew).`;
1507
+ }
1376
1508
  /** an artwork's font file (assets/webfonts/) */
1377
1509
  const FONT_PATH = /^\/fonts\/(source-sans-3|source-serif-4|jost)-[a-z-]+\.woff2$/;
1378
1510
  const TYPES = {
@@ -1504,32 +1636,35 @@ function sendJsonText(res, text, code = 200, headers = {}) {
1504
1636
  res.writeHead(code, { "content-type": "application/json", "cache-control": "no-store", ...headers });
1505
1637
  res.end(text);
1506
1638
  }
1507
- /** the whole review compressed, under the tag of the revision it is of, per review */
1508
- const reviewGz = new WeakMap();
1509
- /** The whole review (GET /api/review), tagged with its run and its revision (server/review.ts): a
1510
- * page that has it is answered 304, which a reload is, and one whose review fell behind is sent it
1511
- * compressed — once a revision, off the server's thread when it is large, the same bytes for every
1512
- * page (a review of 5,000 opinions on Sphere-Packing-Lean: 8.5 MB of JSON, 1.1 MB sent). */
1513
- function sendReview(req, res, review) {
1639
+ /** what is sent whole under the tag of its revision, compressed, per what it is of (the review, the
1640
+ * build status) */
1641
+ const revisionGz = new WeakMap();
1642
+ /** A whole sent under the tag of its revision: the review (GET /api/review), tagged with its run and
1643
+ * its revision (server/review.ts), and the build status (GET /api/build, server/live.ts). A page that
1644
+ * has it is answered 304, which a reload is, and one that fell behind is sent it compressed — once a
1645
+ * revision, off the server's thread when it is large, the same bytes for every page (a review of
1646
+ * 5,000 opinions on Sphere-Packing-Lean: 8.5 MB of JSON, 1.1 MB sent; the build status of
1647
+ * NavierStokesAndEuler's 2,657 files: 362 KB, 42 KB sent). `of` is what it is of; `whole` writes it,
1648
+ * asked only where it is sent. */
1649
+ function sendRevision(req, res, of, tag, whole) {
1514
1650
  if (res.headersSent || res.writableEnded || refused.has(res))
1515
1651
  return;
1516
- const tag = review.tag();
1517
1652
  const head = { "content-type": "application/json", "cache-control": "private, no-cache", etag: tag, vary: "accept-encoding" };
1518
1653
  if (fresh(req, tag)) {
1519
1654
  res.writeHead(304, head);
1520
1655
  return void res.end();
1521
1656
  }
1522
- const text = review.wholeText();
1657
+ const text = whole();
1523
1658
  if (text.length <= JSON_GZIP_FROM || !acceptsGzip(req)) {
1524
1659
  res.writeHead(200, head);
1525
1660
  return void res.end(text);
1526
1661
  }
1527
- let c = reviewGz.get(review);
1662
+ let c = revisionGz.get(of);
1528
1663
  if (c?.tag !== tag) {
1529
1664
  const gz = text.length < JSON_GZIP_AWAY_FROM ? Promise.resolve(gzipSync(text)) : new Promise((ok, fail) => gzip(text, (e, b) => (e ? fail(e) : ok(b))));
1530
- reviewGz.set(review, (c = { tag, gz }));
1665
+ revisionGz.set(of, (c = { tag, gz }));
1531
1666
  // a compression that failed is tried again by the next page that asks
1532
- gz.catch(() => reviewGz.get(review)?.gz === gz && reviewGz.delete(review));
1667
+ gz.catch(() => revisionGz.get(of)?.gz === gz && revisionGz.delete(of));
1533
1668
  }
1534
1669
  c.gz.then((gz) => {
1535
1670
  if (res.headersSent || res.destroyed)
@@ -1755,6 +1890,8 @@ async function main() {
1755
1890
  project,
1756
1891
  roots: o.roots,
1757
1892
  everyMs: (o.poll ?? DEFAULT_POLL_MINUTES) * 60_000,
1893
+ buildMs: (o.buildHours ?? DEFAULT_BUILD_HOURS) * 3600_000,
1894
+ mathlibCache: o.mathlibCache ?? "shared",
1758
1895
  head: deploy.head,
1759
1896
  hooks: {
1760
1897
  reading: () => live.reading,
@@ -1860,9 +1997,19 @@ async function main() {
1860
1997
  console.log(` version: ${version}; updates ${updatesInWords(o.updates, version, supervised)}`);
1861
1998
  if (deployment) {
1862
1999
  const d = deployment.status(true);
1863
- console.log(` following: ${d.branch} of ${d.source ?? deployment.remote.url}, asked every ${o.poll ?? DEFAULT_POLL_MINUTES} min`);
2000
+ console.log(` following: ${d.branch} of ${d.source ?? deployment.remote.url}, asked every ${o.poll ?? DEFAULT_POLL_MINUTES} min; a build stopped past ${limitInWords(deployment.buildMs)}`);
1864
2001
  console.log(` clone: ${deployment.folder.checkout}`);
1865
- console.log(` builds: ${d.built ? `the tree holds the build of ${shortCommit(d.built)}${deployment.holds() ? ", cut short: it is done again" : ""}` : `none yet: the first, of ${shortCommit(deploy.head)}, starts now, and the page says so until it is done`}; their logs in ${deployment.folder.logs}`);
2002
+ // a failed build that wrote nothing is not built (DeploySpec decision 6): before any that did,
2003
+ // none is, and the next is the next commit pushed
2004
+ const next = deployment.toBuild();
2005
+ const l = d.last;
2006
+ const why = l ? (l.error ?? (l.exit === null ? "lake build was stopped" : l.exit !== undefined ? `lake build exited with ${l.exit}` : null)) : null;
2007
+ const none = next
2008
+ ? `none yet: the first, of ${shortCommit(next)}, starts now, and the page says so until it is done`
2009
+ : `none yet: that of ${shortCommit(l?.commit ?? deploy.head)} failed${why ? ` (${why})` : ""}, and the next commit pushed is built`;
2010
+ console.log(` builds: ${d.built ? `the tree holds the build of ${shortCommit(d.built)}${deployment.holds() ? ", cut short: it is done again" : ""}` : none}; their logs in ${deployment.folder.logs}`);
2011
+ // where the project is on Mathlib, its cache: the user's, or the deployment's own (DeploySpec decision 2)
2012
+ console.log(` Mathlib's cache: ${o.mathlibCache === "own" ? `${deployment.folder.mathlib}, the deployment's own` : `${sharedMathlibCache()}, the user's, shared by their builds`}`);
1866
2013
  }
1867
2014
  recordVersion(live, version, supervised);
1868
2015
  process.send?.({ vp: "listening", version });