visualproof 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/assets/tips/phone-fingers.light.mp4 +0 -0
- package/dist/assets/tips/phone-fingers.light.webp +0 -0
- package/dist/assets/tips/tour-agent.webp +0 -0
- package/dist/assets/tips/tour-arrange.webp +0 -0
- package/dist/assets/tips/tour-artwork.webp +0 -0
- package/dist/assets/tips/tour-checks.webp +0 -0
- package/dist/assets/tips/tour-keys.webp +0 -0
- package/dist/assets/tips/tour-library.webp +0 -0
- package/dist/assets/tips/tour-project.webp +0 -0
- package/dist/assets/tips/tour-review.webp +0 -0
- package/dist/assets/tips/tour-share.webp +0 -0
- package/dist/assets/tips/tour-source.webp +0 -0
- package/dist/assets/tips/tour-target.webp +0 -0
- package/dist/assets/tips/tour-view.webp +0 -0
- package/dist/assets/tips/tour.json +125 -115
- package/dist/assets/tips/tour.webp +0 -0
- package/dist/extractor/Extract.lean +13 -3
- package/dist/mcp/visualproof-mcp.mjs +20 -9
- package/dist/server/access.js +28 -0
- package/dist/server/agent.js +130 -2819
- package/dist/server/agentactivity.js +72 -0
- package/dist/server/agentadvice.js +115 -0
- package/dist/server/agentdocs.js +1 -1
- package/dist/server/agententry.js +180 -0
- package/dist/server/agentexport.js +469 -0
- package/dist/server/agentfollow.js +384 -0
- package/dist/server/agentgraph.js +128 -0
- package/dist/server/agentlean.js +144 -0
- package/dist/server/agentlibrary.js +1 -1
- package/dist/server/agentplaces.js +242 -0
- package/dist/server/agentread.js +569 -0
- package/dist/server/agenttalk.js +282 -0
- package/dist/server/agenttcb.js +378 -0
- package/dist/server/agentviews.js +2 -2
- package/dist/server/app.js +377 -0
- package/dist/server/appaccess.js +127 -0
- package/dist/server/appagent.js +110 -0
- package/dist/server/appgraph.js +176 -0
- package/dist/server/appshare.js +179 -0
- package/dist/server/appsite.js +120 -0
- package/dist/server/apptalk.js +178 -0
- package/dist/server/artcmd.js +1 -1
- package/dist/server/askfollow.js +1 -1
- package/dist/server/deploy.js +204 -53
- package/dist/server/events.js +1 -1
- package/dist/server/history.js +51 -3
- package/dist/server/historyapi.js +34 -2
- package/dist/server/hover.js +11 -7
- package/dist/server/identity.js +1 -1
- package/dist/server/invites.js +113 -20
- package/dist/server/libraryroute.js +3 -3
- package/dist/server/live.js +186 -30
- package/dist/server/main.js +31 -1613
- package/dist/server/mcptools.js +33 -20
- package/dist/server/options.js +350 -0
- package/dist/server/outside.js +311 -0
- package/dist/server/pastdoc.js +22 -3
- package/dist/server/presence.js +3 -3
- package/dist/server/project.js +28 -4
- package/dist/server/prompt.js +8 -3
- package/dist/server/readonlygate.js +4 -4
- package/dist/server/reviewapi.js +51 -17
- package/dist/server/send.js +259 -0
- package/dist/server/talk.js +238 -116
- package/dist/server/tokens.js +13 -5
- package/dist/server/view.js +3 -1
- package/dist/server/views.js +1 -1
- package/dist/shared/artrecipe.js +3 -3
- package/dist/shared/build.js +35 -1
- package/dist/shared/collab.js +9 -1
- package/dist/shared/comment.js +1 -1
- package/dist/shared/doc/build.js +30 -14
- package/dist/shared/doc/latex.js +7 -2
- package/dist/shared/doc/model.js +4 -2
- package/dist/shared/doc/sections.js +21 -4
- package/dist/shared/keys.js +66 -37
- package/dist/shared/lostfound.js +1 -0
- package/dist/shared/mentions.js +83 -0
- package/dist/shared/outside.js +16 -0
- package/dist/shared/pastgraph.js +11 -2
- package/dist/shared/query.js +13 -4
- package/dist/shared/review.js +91 -21
- package/dist/shared/reviewqueue.js +6 -1
- package/dist/shared/scope.js +1 -1
- package/dist/web/bundle/app.js +51289 -49853
- package/dist/web/index.html +45 -9
- package/dist/web/src/reviewqueue.js +52 -19
- package/dist/web/src/selection.js +1 -1
- package/dist/web/src/theme.js +1 -1
- package/dist/web/src/trust.js +271 -0
- package/dist/web/src/visitors.js +1 -1
- package/dist/web/style.css +181 -70
- package/docs/agent-api/README.md +13 -11
- package/docs/agent-api/advice.md +8 -2
- package/docs/agent-api/export.md +9 -6
- package/docs/agent-api/following.md +11 -12
- package/docs/agent-api/history.md +6 -3
- package/docs/agent-api/mcp.md +15 -15
- package/docs/agent-api/notes.md +1 -1
- package/docs/agent-api/reading.md +10 -4
- package/docs/agent-api/requests.md +12 -15
- package/docs/agent-api/talking.md +60 -55
- package/docs/agent-api/tcb.md +21 -21
- package/docs/agent-api/views.md +3 -4
- package/docs/agent-api/words.md +8 -8
- package/package.json +2 -1
package/dist/server/live.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// written in, the exact contexts — come as the next version of the graph. Where every module's
|
|
14
14
|
// result is cached, the merged graph is the first one served.
|
|
15
15
|
import { randomBytes } from "node:crypto";
|
|
16
|
-
import { sameName } from "../shared/collab.js";
|
|
16
|
+
import { madeBy, nameKey, sameName } from "../shared/collab.js";
|
|
17
17
|
import { prepare } from "./pipeline.js";
|
|
18
18
|
import { extract, loadSaved } from "./extract.js";
|
|
19
19
|
import { DEFAULT_JOBS, UsagePass, mergeUsage, saveMerged } from "./usage.js";
|
|
@@ -25,14 +25,15 @@ import { agentKey, Presence } from "./presence.js";
|
|
|
25
25
|
import { AgentTokens } from "./tokens.js";
|
|
26
26
|
import { Invites } from "./invites.js";
|
|
27
27
|
import { ReadOnlyLinks } from "./readonly.js";
|
|
28
|
-
import { Talk } from "./talk.js";
|
|
28
|
+
import { forPages, PUBLIC, Talk } from "./talk.js";
|
|
29
29
|
import { Asks } from "./askfollow.js";
|
|
30
30
|
import { BuildTracker, compiling, importable, outputsOf, probeAll, scanModules, stampOf } from "./status.js";
|
|
31
31
|
import { BuildWatch, moduleDirs, shouldLook } from "./buildwatch.js";
|
|
32
|
+
import { buildChanges } from "../shared/build.js";
|
|
32
33
|
import { Views } from "./views.js";
|
|
33
34
|
import { graphOf, memoryProblem, titleContext } from "./agentviews.js";
|
|
34
35
|
import { ownName, rebinder, versionBase, versions, withVersions } from "./versions.js";
|
|
35
|
-
import { buildTime, commitNow, History } from "./history.js";
|
|
36
|
+
import { backfillPackages, buildTime, commitNow, History } from "./history.js";
|
|
36
37
|
import { backfillSources, keepSources } from "./sourcestore.js";
|
|
37
38
|
import { findRenames, Renames } from "./renames.js";
|
|
38
39
|
import { carryClusterLinks, Library } from "./library.js";
|
|
@@ -45,6 +46,7 @@ import { boardSet } from "../shared/board.js";
|
|
|
45
46
|
import { derivesOn, existsIn } from "../shared/noteplace.js";
|
|
46
47
|
import { packageVersion } from "./version.js";
|
|
47
48
|
import { withoutReasons } from "../shared/timeline.js";
|
|
49
|
+
import { OutsideSources } from "./outside.js";
|
|
48
50
|
const TICK = 1000;
|
|
49
51
|
/** outputs quiet this long, and no compile running: the build is over */
|
|
50
52
|
const SETTLE = 2500;
|
|
@@ -65,8 +67,18 @@ export const MAX_STREAMS_PER_SESSION = 4;
|
|
|
65
67
|
export const MAX_BUFFERED = 4 << 20;
|
|
66
68
|
/** the list of who is here goes out at most this often: a burst of heartbeats is one event */
|
|
67
69
|
const PRESENCE_EVERY = 500;
|
|
70
|
+
/** A change of the build status larger than this, and than this part of the whole (about what the
|
|
71
|
+
* whole takes compressed: 42 KB of NavierStokesAndEuler's 362), goes out as its revision alone
|
|
72
|
+
* (`build-rev`), which every page reads compressed (GET /api/build) rather than take it uncompressed
|
|
73
|
+
* on its stream: the first look, an edit or a build that starts or fails under much of a large
|
|
74
|
+
* project. A smaller one is no saving worth a request. */
|
|
75
|
+
export const BUILD_DELTA_MAX = 64 << 10;
|
|
76
|
+
export const BUILD_DELTA_PART = 1 / 8;
|
|
68
77
|
/** The graph's modules and their files (meta.modules), per graph read (agentviews.ts, graphOf). */
|
|
69
78
|
const moduleFiles = new WeakMap();
|
|
79
|
+
/** The modules the graph's outside declarations are in, per graph read: the only outside modules
|
|
80
|
+
* whose source is served or handed to Lean (server/outside.ts). */
|
|
81
|
+
const outsideModules = new WeakMap();
|
|
70
82
|
export class Live {
|
|
71
83
|
project;
|
|
72
84
|
/** the site directory and the project's caches (server/dirs.ts) */
|
|
@@ -85,6 +97,12 @@ export class Live {
|
|
|
85
97
|
lastLook = 0;
|
|
86
98
|
lastRunning = "";
|
|
87
99
|
buildText = "";
|
|
100
|
+
/** the build status's revision (`build-rev`, `build-delta`), counted from 0, before the first look,
|
|
101
|
+
* in this server's process; each file's status as last sent, as JSON, by module; and the whole as
|
|
102
|
+
* GET /api/build answers it, made when first asked */
|
|
103
|
+
buildRev = 0;
|
|
104
|
+
buildFiles = new Map();
|
|
105
|
+
buildWholeText = null;
|
|
88
106
|
build = null;
|
|
89
107
|
graph = null;
|
|
90
108
|
extracting = false;
|
|
@@ -161,6 +179,10 @@ export class Live {
|
|
|
161
179
|
nodeIndex = new Map();
|
|
162
180
|
/** the declarations outside the project the graph on show refers to: in it too */
|
|
163
181
|
outside = new Set();
|
|
182
|
+
/** where the outside declarations' sources are (server/outside.ts), and the packages' revisions
|
|
183
|
+
* as the graph on show was read: a package at another one now is not the text it was read from */
|
|
184
|
+
outsideSources;
|
|
185
|
+
outsideRead = null;
|
|
164
186
|
constructor(project, dirs, saved, review, editor = null, jobs = DEFAULT_JOBS) {
|
|
165
187
|
this.project = project;
|
|
166
188
|
this.dirs = dirs;
|
|
@@ -168,17 +190,21 @@ export class Live {
|
|
|
168
190
|
this.review = review;
|
|
169
191
|
this.editor = editor;
|
|
170
192
|
this.usage = new UsagePass(project, dirs, saved ? 0 : jobs, (l) => this.say(l));
|
|
193
|
+
// the toolchain is the project's as it is now: a branch followed may change it (server/deploy.ts)
|
|
194
|
+
this.outsideSources = new OutsideSources(project.root, () => this.project.toolchain);
|
|
171
195
|
this.tracker = new BuildTracker(project);
|
|
172
196
|
this.timeline = new Timeline(dirs.site, (e) => this.sendActivity(e));
|
|
173
197
|
this.tokens = new AgentTokens(dirs.site);
|
|
174
198
|
this.invites = new Invites(dirs.site);
|
|
175
199
|
// every page knows the names the people invited by a link go by, so that what each did shows
|
|
176
200
|
// under the name they go by now; a link revoked cuts its pages off at once, as it does its
|
|
177
|
-
// requests: their streams end, and come back only if the key lets them in
|
|
201
|
+
// requests: their streams end, and come back only if the key lets them in. A link made anew
|
|
202
|
+
// does the same, but to the page that made it anew (`keep`): the other pages of its browser,
|
|
203
|
+
// given the new cookie, come back as they were
|
|
178
204
|
this.invites.onChanged = () => this.send("people", this.invites.people());
|
|
179
|
-
this.invites.onEnded = (r) => {
|
|
205
|
+
this.invites.onEnded = (r, keep) => {
|
|
180
206
|
for (const st of [...this.streams.values()])
|
|
181
|
-
if (st.person === r.id)
|
|
207
|
+
if (st.person === r.id && (keep === undefined || st.token !== keep))
|
|
182
208
|
this.close(st);
|
|
183
209
|
};
|
|
184
210
|
this.readOnly = new ReadOnlyLinks(dirs.site);
|
|
@@ -250,12 +276,8 @@ export class Live {
|
|
|
250
276
|
this.tokens.onEnded = (r) => this.talk.close(r.id, r.revoked ? "revoked" : "expired");
|
|
251
277
|
this.talk.inForce = (id) => this.tokens.inForce().some((r) => r.id === id);
|
|
252
278
|
this.talk.onState = (id, talk) => this.presence.setTalk(id, talk);
|
|
253
|
-
// a new message goes to
|
|
254
|
-
this.talk.onMessage = (
|
|
255
|
-
const r = this.tokens.get(id);
|
|
256
|
-
if (r)
|
|
257
|
-
this.send("chat", { agent: agentKey({ name: r.name, token: r.id }), message });
|
|
258
|
-
};
|
|
279
|
+
// a new message goes to the pages that may read its channel (CollabSpec decision 13)
|
|
280
|
+
this.talk.onMessage = (channel, message) => this.sendChat(channel, message);
|
|
259
281
|
this.views.pageOf = (token) => (typeof token === "string" ? this.byToken.get(token)?.id ?? null : null);
|
|
260
282
|
// the views a private page holds live while a page of its session is open
|
|
261
283
|
this.views.sessionOpen = (session) => [...this.streams.values()].some((st) => st.session === session);
|
|
@@ -306,10 +328,14 @@ export class Live {
|
|
|
306
328
|
* stream that closed, a guess), and nothing changes. A private page's (`priv`, CollabSpec
|
|
307
329
|
* decision 8) is counted and nothing more is kept of it: not its name, not where it is.
|
|
308
330
|
* `verified`: the page of someone invited by a personal link (decision 9). */
|
|
309
|
-
beat(token, name, view, idle, priv = false, verified = false) {
|
|
331
|
+
beat(token, name, view, idle, priv = false, verified = false, who = name) {
|
|
310
332
|
const s = typeof token === "string" ? this.byToken.get(token) : undefined;
|
|
311
333
|
if (!s)
|
|
312
334
|
return false;
|
|
335
|
+
// the name the page goes by, said by its heartbeat's request, a private page's too (`who`): what
|
|
336
|
+
// of the channels its stream is sent (CollabSpec decision 13)
|
|
337
|
+
if (s.readOnly === null)
|
|
338
|
+
s.name = who;
|
|
313
339
|
if (s.private !== priv)
|
|
314
340
|
this.rename(s, priv, name, view, idle, verified);
|
|
315
341
|
else if (priv)
|
|
@@ -356,6 +382,39 @@ export class Live {
|
|
|
356
382
|
moduleFiles.set(G.meta, (files = new Map(G.meta.modules.map((m) => [m.name, m.file]))));
|
|
357
383
|
return files.get(module);
|
|
358
384
|
}
|
|
385
|
+
/** The file of a module outside the project, where an outside declaration of the graph on show
|
|
386
|
+
* is in it (ReviewSpec, "The source window", the owner's decision of 2026-10-20): its package's or
|
|
387
|
+
* Lean's core's (server/outside.ts), and whether that package is at another revision now than
|
|
388
|
+
* when the graph was read (`changed`). Undefined where the graph has no outside declaration in
|
|
389
|
+
* that module (or there is no graph yet, or it is a saved graph's, whose project is not here),
|
|
390
|
+
* null where its file is not found. */
|
|
391
|
+
outsideFile(module) {
|
|
392
|
+
const G = graphOf(this);
|
|
393
|
+
if (!G || this.saved)
|
|
394
|
+
return undefined;
|
|
395
|
+
let mods = outsideModules.get(G.meta);
|
|
396
|
+
if (!mods)
|
|
397
|
+
outsideModules.set(G.meta, (mods = new Set(G.meta.nodes.slice(G.meta.projectCount).map((v) => v.module))));
|
|
398
|
+
if (!mods.has(module))
|
|
399
|
+
return undefined;
|
|
400
|
+
const file = this.outsideSources.find(module);
|
|
401
|
+
if (!file)
|
|
402
|
+
return null;
|
|
403
|
+
const read = this.outsideRead;
|
|
404
|
+
const p = file.package;
|
|
405
|
+
const changed = !!read && (p.core ? read.toolchain !== this.project.toolchain : (read.packages[p.name] ?? null) !== p.rev);
|
|
406
|
+
return { file, changed };
|
|
407
|
+
}
|
|
408
|
+
/** A module outside the project as it is now, whatever the graph on show holds (server/outside.ts),
|
|
409
|
+
* and the toolchain now: what a past build's outside source is compared with (HistorySpec
|
|
410
|
+
* decision 24; server/historyapi.ts, `pastOutside`). Null for a saved graph, whose project is not
|
|
411
|
+
* here. */
|
|
412
|
+
outsideNow(module) {
|
|
413
|
+
if (this.saved)
|
|
414
|
+
return null;
|
|
415
|
+
const file = this.outsideSources.find(module);
|
|
416
|
+
return file && { file, toolchain: this.project.toolchain };
|
|
417
|
+
}
|
|
359
418
|
/** The Project view's pins changed (the agents' API): every page gets the operations, and who
|
|
360
419
|
* made them. */
|
|
361
420
|
placesChanged(ops, from, by) {
|
|
@@ -397,6 +456,41 @@ export class Live {
|
|
|
397
456
|
this.reversion();
|
|
398
457
|
this.lostChanged();
|
|
399
458
|
}
|
|
459
|
+
/** The build status a look found (the live loop's tick): where it changed, every page is told the
|
|
460
|
+
* files whose status changed, with the new revision (`build-delta`), which it applies to the
|
|
461
|
+
* status it holds; a large change (BUILD_DELTA_MAX) goes out as the revision alone (`build-rev`),
|
|
462
|
+
* at which each page reads the whole (GET /api/build). A page from before 0.6.0 is sent the
|
|
463
|
+
* whole (`build`), as it was. */
|
|
464
|
+
buildFound(build) {
|
|
465
|
+
const text = JSON.stringify(build);
|
|
466
|
+
this.build = build;
|
|
467
|
+
if (text === this.buildText)
|
|
468
|
+
return;
|
|
469
|
+
this.buildText = text;
|
|
470
|
+
this.buildWholeText = null;
|
|
471
|
+
const base = this.buildRev++;
|
|
472
|
+
const { files, gone, texts } = buildChanges(this.buildFiles, build);
|
|
473
|
+
this.buildFiles = texts;
|
|
474
|
+
if (this.streams.size) {
|
|
475
|
+
const delta = { epoch: this.instance, base, rev: this.buildRev, active: build.active, progress: build.progress, counts: build.counts, files, gone };
|
|
476
|
+
const d = JSON.stringify(delta);
|
|
477
|
+
const news = d.length > Math.max(BUILD_DELTA_MAX, text.length * BUILD_DELTA_PART) ? `event: build-rev\ndata: ${JSON.stringify(this.buildRevNow())}\n\n` : `event: build-delta\ndata: ${d}\n\n`;
|
|
478
|
+
let whole = null;
|
|
479
|
+
for (const st of [...this.streams.values()])
|
|
480
|
+
this.push(st, st.buildDeltas ? news : (whole ??= `event: build\ndata: ${text}\n\n`));
|
|
481
|
+
}
|
|
482
|
+
this.timeline.buildStatus(build);
|
|
483
|
+
}
|
|
484
|
+
/** Which build status the server holds (`build-rev`): its process and its revision. */
|
|
485
|
+
buildRevNow() {
|
|
486
|
+
return { epoch: this.instance, rev: this.buildRev };
|
|
487
|
+
}
|
|
488
|
+
/** The whole build status as GET /api/build answers it, with its revision, and the tag of that
|
|
489
|
+
* revision: written once a revision, whoever asks. */
|
|
490
|
+
buildWhole() {
|
|
491
|
+
this.buildWholeText ??= `{"epoch":${JSON.stringify(this.instance)},"rev":${this.buildRev},"status":${this.buildText || "null"}}`;
|
|
492
|
+
return { tag: `"b${this.instance}.${this.buildRev}"`, text: this.buildWholeText };
|
|
493
|
+
}
|
|
400
494
|
say(line) {
|
|
401
495
|
this.log.push(line);
|
|
402
496
|
if (this.log.length > 200)
|
|
@@ -419,6 +513,18 @@ export class Live {
|
|
|
419
513
|
// background (HistorySpec decision 22): a snapshot backfilled is not looked at again
|
|
420
514
|
if (this.history)
|
|
421
515
|
void backfillSources(this.history, this.project, this.dirs.cache, (l) => this.say(l)).catch((e) => this.say(`history: the source texts could not be backfilled: ${e instanceof Error ? e.message : String(e)}`));
|
|
516
|
+
// the packages' revisions of the snapshots read before they were recorded, from their commits
|
|
517
|
+
// (HistorySpec decision 24)
|
|
518
|
+
if (this.history && !this.saved) {
|
|
519
|
+
try {
|
|
520
|
+
const n = backfillPackages(this.history, this.project.root);
|
|
521
|
+
if (n)
|
|
522
|
+
this.say(`history: ${n} snapshot(s) given their packages' revisions, from their commits' lake-manifest.json`);
|
|
523
|
+
}
|
|
524
|
+
catch (e) {
|
|
525
|
+
this.say(`history: the packages' revisions could not be backfilled: ${e instanceof Error ? e.message : String(e)}`);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
422
528
|
// the review's logs are watched whatever the graph comes from: they may change on disk any time
|
|
423
529
|
this.timers.push(setInterval(() => this.checkReview(), TICK));
|
|
424
530
|
this.timers.push(setInterval(() => {
|
|
@@ -516,13 +622,7 @@ export class Live {
|
|
|
516
622
|
const d = this.deploy;
|
|
517
623
|
if (d && d.busy && !build.active)
|
|
518
624
|
build = { ...build, active: true };
|
|
519
|
-
|
|
520
|
-
this.build = build;
|
|
521
|
-
if (text !== this.buildText) {
|
|
522
|
-
this.buildText = text;
|
|
523
|
-
this.send("build", build);
|
|
524
|
-
this.timeline.buildStatus(build);
|
|
525
|
-
}
|
|
625
|
+
this.buildFound(build);
|
|
526
626
|
// and its builds, beside the files: the one going on, the newest commit waiting, the last
|
|
527
627
|
if (d) {
|
|
528
628
|
const now = JSON.stringify(d.status(true));
|
|
@@ -620,6 +720,10 @@ export class Live {
|
|
|
620
720
|
this.base = versionBase(ex.graph);
|
|
621
721
|
this.nodeIndex = new Map(this.base.names.map((n, i) => [n, i]));
|
|
622
722
|
this.outside = new Set(ex.graph.externals.map((e) => e.name));
|
|
723
|
+
// the revisions its outside declarations were read at: those of the manifest it was extracted
|
|
724
|
+
// with (server/extract.ts, fingerprint), as it is now; the packages and the toolchain as they are
|
|
725
|
+
this.outsideSources.forget();
|
|
726
|
+
this.outsideRead = this.saved ? null : { packages: this.outsideSources.revisions(), toolchain: this.project.toolchain };
|
|
623
727
|
// the history first: the renames found against the build before are migrated, so that the
|
|
624
728
|
// versions served are made under them (HistorySpec.md)
|
|
625
729
|
const renamed = this.snapshot(ex, missing);
|
|
@@ -777,7 +881,7 @@ export class Live {
|
|
|
777
881
|
written = found.written;
|
|
778
882
|
return found;
|
|
779
883
|
};
|
|
780
|
-
const r = this.history.record(ex.graph, { at: buildTime(this.project), fingerprint: ex.fingerprint, commit, toolchain: this.project.toolchain, missing, sources, tool: this.toolVersion });
|
|
884
|
+
const r = this.history.record(ex.graph, { at: buildTime(this.project), fingerprint: ex.fingerprint, commit, toolchain: this.project.toolchain, missing, sources, tool: this.toolVersion, packages: this.outsideSources.revisions() });
|
|
781
885
|
if (!r.written)
|
|
782
886
|
return renamed;
|
|
783
887
|
const s = r.info;
|
|
@@ -1171,8 +1275,10 @@ export class Live {
|
|
|
1171
1275
|
st.res.end(text);
|
|
1172
1276
|
}
|
|
1173
1277
|
}
|
|
1174
|
-
/** What /api/status says: enough for the loader and for a page that just connected.
|
|
1175
|
-
|
|
1278
|
+
/** What /api/status says: enough for the loader and for a page that just connected. `brief`: the
|
|
1279
|
+
* build status without its files (the page's loader, which reads them by GET /api/build). */
|
|
1280
|
+
status(brief = false) {
|
|
1281
|
+
const b = this.build;
|
|
1176
1282
|
return {
|
|
1177
1283
|
state: this.graph ? "ready" : this.extractError ? "error" : "extracting",
|
|
1178
1284
|
error: this.graph ? undefined : this.extractError ?? undefined,
|
|
@@ -1182,7 +1288,7 @@ export class Live {
|
|
|
1182
1288
|
graph: this.graphInfo(),
|
|
1183
1289
|
// the usage pass: how far it is, and the modules it could not elaborate
|
|
1184
1290
|
usage: this.usage.status,
|
|
1185
|
-
build:
|
|
1291
|
+
build: brief && b ? { active: b.active, progress: b.progress, counts: b.counts } : b,
|
|
1186
1292
|
// the branch followed, where the server builds what it shows (DeploySpec)
|
|
1187
1293
|
...(this.deploy ? { deploy: this.deploy.status(true) } : {}),
|
|
1188
1294
|
live: !this.saved,
|
|
@@ -1193,10 +1299,11 @@ export class Live {
|
|
|
1193
1299
|
};
|
|
1194
1300
|
}
|
|
1195
1301
|
/** A page's event stream; `session` is what the page calls itself (its streams are kept few by
|
|
1196
|
-
* it), `person` the personal link it came by
|
|
1197
|
-
*
|
|
1198
|
-
*
|
|
1199
|
-
|
|
1302
|
+
* it), `person` the personal link it came by, `buildDeltas` whether it takes the build status as
|
|
1303
|
+
* changes (a page of 0.6.0 or later), `name` the name it gives (the conversations it is sent).
|
|
1304
|
+
* The stream is named by the server: the page is told its id, which everyone sees, and a secret
|
|
1305
|
+
* for its heartbeats (`hello`); it is gone from presence when its stream closes. */
|
|
1306
|
+
subscribe(res, session = null, person = null, readOnly = null, toldAll = readOnly === null, buildDeltas = false, name = null) {
|
|
1200
1307
|
if (session) {
|
|
1201
1308
|
// a page that opens one more than a page needs (a reload whose old stream lingers) loses
|
|
1202
1309
|
// its oldest
|
|
@@ -1216,7 +1323,7 @@ export class Live {
|
|
|
1216
1323
|
connection: "keep-alive",
|
|
1217
1324
|
});
|
|
1218
1325
|
res.write("retry: 2000\n\n");
|
|
1219
|
-
const st = { res, id: randomBytes(9).toString("base64url"), token: randomBytes(24).toString("base64url"), session, private: false, person, readOnly, toldAll, room: Infinity, after: 0 };
|
|
1326
|
+
const st = { res, id: randomBytes(9).toString("base64url"), token: randomBytes(24).toString("base64url"), session, private: false, person, readOnly, name: readOnly === null ? name : null, toldAll, room: Infinity, after: 0, buildDeltas };
|
|
1220
1327
|
this.streams.set(res, st);
|
|
1221
1328
|
this.byToken.set(st.token, st);
|
|
1222
1329
|
this.presence.open(st.id);
|
|
@@ -1230,7 +1337,11 @@ export class Live {
|
|
|
1230
1337
|
// the views as they are: a page that was away (a restart, a lost connection) catches up, and
|
|
1231
1338
|
// reads again the boards it has open
|
|
1232
1339
|
this.write(res, "views", { views: this.views.list(), changes: [], all: true });
|
|
1233
|
-
|
|
1340
|
+
// the build status's revision: a page that holds another reads the whole (GET /api/build); what
|
|
1341
|
+
// changes after comes as deltas. A page from before 0.6.0 is sent it whole.
|
|
1342
|
+
if (buildDeltas)
|
|
1343
|
+
this.write(res, "build-rev", this.buildRevNow());
|
|
1344
|
+
else if (this.build)
|
|
1234
1345
|
this.write(res, "build", this.build);
|
|
1235
1346
|
if (this.deploy)
|
|
1236
1347
|
this.write(res, "deploy", this.deploy.status(readOnly === null));
|
|
@@ -1269,6 +1380,41 @@ export class Live {
|
|
|
1269
1380
|
for (const st of [...this.streams.values()])
|
|
1270
1381
|
this.push(st, text);
|
|
1271
1382
|
}
|
|
1383
|
+
/** A message of a channel, sent to the pages that read it (CollabSpec decision 13): a public one to
|
|
1384
|
+
* every page with a name, private readers' too; a private one only to the pages of the person
|
|
1385
|
+
* who made its agent's token (shared/collab.ts, madeBy), named by the agent's entry in presence;
|
|
1386
|
+
* nothing to a read-only reader's page, nor to a page without a name. */
|
|
1387
|
+
sendChat(channel, message) {
|
|
1388
|
+
if (!this.streams.size)
|
|
1389
|
+
return;
|
|
1390
|
+
const t = channel === PUBLIC ? null : (this.tokens.get(channel) ?? null);
|
|
1391
|
+
if (channel !== PUBLIC && !t)
|
|
1392
|
+
return;
|
|
1393
|
+
const text = `event: chat\ndata: ${JSON.stringify({ channel: t ? agentKey({ name: t.name, token: t.id }) : PUBLIC, message: forPages(message) })}\n\n`;
|
|
1394
|
+
for (const st of [...this.streams.values()])
|
|
1395
|
+
if (mayRead(st, t))
|
|
1396
|
+
this.push(st, text);
|
|
1397
|
+
}
|
|
1398
|
+
/** Who a message may mention (CollabSpec decision 13): the agents listed with a token in force, by
|
|
1399
|
+
* their tokens, and the people — with a page open, invited by a link, or who wrote in the public
|
|
1400
|
+
* channel lately — by the names they go by. */
|
|
1401
|
+
mentionable() {
|
|
1402
|
+
const agents = new Map();
|
|
1403
|
+
const names = [];
|
|
1404
|
+
for (const r of this.tokens.inForce()) {
|
|
1405
|
+
agents.set(nameKey(r.name), r.id);
|
|
1406
|
+
names.push(r.name);
|
|
1407
|
+
}
|
|
1408
|
+
for (const p of this.presence.list())
|
|
1409
|
+
if (!p.agent && p.name)
|
|
1410
|
+
names.push(p.name);
|
|
1411
|
+
for (const r of this.invites.inForce())
|
|
1412
|
+
names.push(r.name);
|
|
1413
|
+
for (const m of this.talk.thread(PUBLIC))
|
|
1414
|
+
if (m.kind === "person")
|
|
1415
|
+
names.push(m.from);
|
|
1416
|
+
return { names, agents };
|
|
1417
|
+
}
|
|
1272
1418
|
/** Write to a stream, unless what it has not read yet passed MAX_BUFFERED beyond its hello (`room`):
|
|
1273
1419
|
* then it is closed instead, and its page reconnects to the present state. A hello counted against
|
|
1274
1420
|
* MAX_BUFFERED (in 0.4.3 it carried the whole review, 7 MB for 5,000 opinions on
|
|
@@ -1340,3 +1486,13 @@ function viewsCarried(views) {
|
|
|
1340
1486
|
}
|
|
1341
1487
|
return { notes, pins, scopes, reviewViews: 0 };
|
|
1342
1488
|
}
|
|
1489
|
+
/** Whether a page's stream is sent a channel's messages (CollabSpec decision 13): the public channel
|
|
1490
|
+
* (`t` null) where it has a name, a private one where its reader made the agent's token; never a
|
|
1491
|
+
* read-only reader's. */
|
|
1492
|
+
function mayRead(st, t) {
|
|
1493
|
+
if (st.readOnly !== null)
|
|
1494
|
+
return false;
|
|
1495
|
+
if (!t)
|
|
1496
|
+
return st.name !== null || st.person !== null;
|
|
1497
|
+
return madeBy(t, { name: st.name, person: st.person });
|
|
1498
|
+
}
|