visualproof 0.4.3 → 0.5.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 +16 -7
- package/dist/assets/latex/visualproof.sty +19 -9
- 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 +117 -112
- package/dist/assets/tips/tour.webp +0 -0
- package/dist/mcp/visualproof-mcp.mjs +7 -3
- package/dist/server/access.js +37 -1
- package/dist/server/accesspage.js +130 -0
- package/dist/server/agent.js +11 -5
- package/dist/server/agentlibrary.js +1 -1
- package/dist/server/agentviews.js +1 -1
- package/dist/server/artcmd.js +1 -1
- package/dist/server/askfollow.js +1 -4
- package/dist/server/buildwatch.js +133 -0
- package/dist/server/deploy.js +844 -0
- package/dist/server/doctor.js +15 -3
- package/dist/server/events.js +20 -5
- package/dist/server/export.js +17 -4
- package/dist/server/fetchurl.js +30 -13
- package/dist/server/film.js +1 -1
- package/dist/server/history.js +3 -1
- package/dist/server/historyapi.js +100 -50
- package/dist/server/historythread.js +206 -0
- package/dist/server/hover.js +8 -0
- package/dist/server/identity.js +25 -1
- package/dist/server/library.js +10 -3
- package/dist/server/live.js +206 -28
- package/dist/server/lostfound.js +3 -2
- package/dist/server/main.js +361 -50
- package/dist/server/poppler.js +48 -10
- package/dist/server/renames.js +10 -5
- package/dist/server/review.js +32 -2
- package/dist/server/reviewapi.js +1 -1
- package/dist/server/status.js +144 -50
- package/dist/server/talk.js +7 -2
- package/dist/server/usage.js +51 -0
- package/dist/server/views.js +21 -7
- package/dist/shared/board.js +2 -1
- package/dist/shared/collab.js +14 -8
- package/dist/shared/deploy.js +35 -0
- package/dist/shared/doc/latex.js +5 -3
- package/dist/shared/doc/outline.js +6 -3
- package/dist/shared/layout.js +297 -70
- package/dist/shared/libm.js +366 -0
- package/dist/shared/library.js +11 -6
- package/dist/shared/palette.js +1 -1
- package/dist/shared/review.js +7 -5
- package/dist/shared/search.js +7 -3
- package/dist/shared/separate.js +556 -32
- package/dist/shared/views.js +8 -1
- package/dist/web/bundle/app.js +3595 -1520
- package/dist/web/bundle/edges.js +44 -16
- package/dist/web/bundle/layout.js +1026 -80
- package/dist/web/index.html +2 -2
- package/dist/web/src/artwork.js +25 -4
- package/dist/web/src/axiomring.js +42 -0
- package/dist/web/src/bundles.js +52 -16
- package/dist/web/src/canvas.js +109 -54
- package/dist/web/src/overview.js +4 -1
- package/dist/web/src/past.js +28 -0
- package/dist/web/src/scene.js +13 -12
- package/dist/web/src/selection.js +47 -4
- package/dist/web/src/status.js +32 -2
- package/dist/web/src/theme.js +108 -0
- package/dist/web/style.css +181 -45
- package/docs/agent-api/following.md +1 -1
- package/docs/agent-api/history.md +3 -0
- package/docs/agent-api/library.md +1 -1
- package/docs/agent-api/requests.md +4 -1
- package/docs/agent-api/views.md +1 -1
- package/package.json +1 -1
package/dist/server/live.js
CHANGED
|
@@ -4,13 +4,16 @@
|
|
|
4
4
|
// Two speeds, on purpose. Build status is cheap (a few stats and hashes) and goes out every
|
|
5
5
|
// second it changes, so a page shows "building 12 / 40" while Lean works. The graph is expensive
|
|
6
6
|
// and only meaningful between builds, so it is re-extracted once the outputs stop moving; until
|
|
7
|
-
// then the page keeps the last good graph and says how old it is.
|
|
7
|
+
// then the page keeps the last good graph and says how old it is. With nothing happening, the
|
|
8
|
+
// loop asks which compiles run, and looks at the files only when a watch says something moved
|
|
9
|
+
// (server/buildwatch.ts): a server at rest costs next to nothing.
|
|
8
10
|
//
|
|
9
11
|
// The extractor's graph is served as soon as it is ready; the usage pass (server/usage.ts) then
|
|
10
12
|
// elaborates the modules whose result is not cached, and its findings — the notation each unit is
|
|
11
13
|
// written in, the exact contexts — come as the next version of the graph. Where every module's
|
|
12
14
|
// result is cached, the merged graph is the first one served.
|
|
13
15
|
import { randomBytes } from "node:crypto";
|
|
16
|
+
import { sameName } from "../shared/collab.js";
|
|
14
17
|
import { prepare } from "./pipeline.js";
|
|
15
18
|
import { extract, loadSaved } from "./extract.js";
|
|
16
19
|
import { DEFAULT_JOBS, UsagePass, mergeUsage, saveMerged } from "./usage.js";
|
|
@@ -24,7 +27,8 @@ import { Invites } from "./invites.js";
|
|
|
24
27
|
import { ReadOnlyLinks } from "./readonly.js";
|
|
25
28
|
import { Talk } from "./talk.js";
|
|
26
29
|
import { Asks } from "./askfollow.js";
|
|
27
|
-
import { BuildTracker, importable,
|
|
30
|
+
import { BuildTracker, compiling, importable, outputsOf, probeAll, scanModules, stampOf } from "./status.js";
|
|
31
|
+
import { BuildWatch, moduleDirs, shouldLook } from "./buildwatch.js";
|
|
28
32
|
import { Views } from "./views.js";
|
|
29
33
|
import { graphOf, memoryProblem, titleContext } from "./agentviews.js";
|
|
30
34
|
import { ownName, rebinder, versionBase, versions, withVersions } from "./versions.js";
|
|
@@ -44,6 +48,9 @@ import { withoutReasons } from "../shared/timeline.js";
|
|
|
44
48
|
const TICK = 1000;
|
|
45
49
|
/** outputs quiet this long, and no compile running: the build is over */
|
|
46
50
|
const SETTLE = 2500;
|
|
51
|
+
/** how long a watch's news of a change a look found may take before the look counts as one it
|
|
52
|
+
* missed (server/buildwatch.ts) */
|
|
53
|
+
const MISS_GRACE_MS = 500;
|
|
47
54
|
const PING = 15000;
|
|
48
55
|
/** Event streams, which every change goes to: at most this many open at once, and this many per
|
|
49
56
|
* page (`session`: a reload, a lost connection coming back), its oldest closed for a new one. */
|
|
@@ -69,7 +76,15 @@ export class Live {
|
|
|
69
76
|
mods = new Map();
|
|
70
77
|
lastStamp = "";
|
|
71
78
|
extractedStamp = "";
|
|
79
|
+
/** what the last look would read: the stamp, or a followed branch's outputs alone */
|
|
80
|
+
lastRead = "";
|
|
72
81
|
quietSince = 0;
|
|
82
|
+
/** what tells the loop to look at the files (server/buildwatch.ts) */
|
|
83
|
+
buildWatch = new BuildWatch((l) => this.say(l));
|
|
84
|
+
/** when the files were last looked at, the compiles that ran then, and the status as last sent */
|
|
85
|
+
lastLook = 0;
|
|
86
|
+
lastRunning = "";
|
|
87
|
+
buildText = "";
|
|
73
88
|
build = null;
|
|
74
89
|
graph = null;
|
|
75
90
|
extracting = false;
|
|
@@ -85,6 +100,11 @@ export class Live {
|
|
|
85
100
|
/** review changes not yet sent: those made in one turn of the event loop go out as one */
|
|
86
101
|
reviewPending = [];
|
|
87
102
|
version = 0;
|
|
103
|
+
/** the branch followed (DeploySpec), where the server builds what it shows; null for a workspace,
|
|
104
|
+
* whose builds are its owner's */
|
|
105
|
+
deploy = null;
|
|
106
|
+
/** graphs being made ready to serve (install): the tree is read meanwhile */
|
|
107
|
+
installing = 0;
|
|
88
108
|
/** this server's process, as its pages know it (UpdateSpec decision 8): the graph's versions are
|
|
89
109
|
* counted again by another */
|
|
90
110
|
instance = randomBytes(6).toString("base64url");
|
|
@@ -343,7 +363,11 @@ export class Live {
|
|
|
343
363
|
}
|
|
344
364
|
/** The review changed (server/review.ts tells it): every open page gets what changed — the new
|
|
345
365
|
* events, which it applies to the review it holds (`review-delta`), or, where events came in
|
|
346
|
-
* between, the
|
|
366
|
+
* between, the revision alone (`review-rev`), at which the page reads the whole review (GET
|
|
367
|
+
* /api/review, compressed and tagged). The stream never carries the whole review: with thousands
|
|
368
|
+
* of opinions it is megabytes, and it went uncompressed to every page, which read it again from
|
|
369
|
+
* GET /api/review besides (5.4 MB to each page of a review of 5,000 opinions on
|
|
370
|
+
* NavierStokesAndEuler, 0.7 MB compressed). Changes made in one turn (an agent's batch of advice)
|
|
347
371
|
* go out as one. A new target's TCB is where its timeline starts; it has no view until a click
|
|
348
372
|
* gives it one (ViewSpec decision 29). */
|
|
349
373
|
reviewChanged(c) {
|
|
@@ -361,7 +385,7 @@ export class Live {
|
|
|
361
385
|
if (deltas)
|
|
362
386
|
this.send("review-delta", { epoch: last.epoch, base: cs[0].base, rev: last.rev, events: cs.flatMap((c) => c.events), problems: last.problems, error: this.review.error });
|
|
363
387
|
else
|
|
364
|
-
this.send("review", this.
|
|
388
|
+
this.send("review-rev", this.reviewRev());
|
|
365
389
|
this.timeline.reviewChanged(this.review.data);
|
|
366
390
|
// a target a move brought from another name takes that name's view over; a target unmarked is
|
|
367
391
|
// unlinked from its view
|
|
@@ -396,27 +420,43 @@ export class Live {
|
|
|
396
420
|
if (this.history)
|
|
397
421
|
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)}`));
|
|
398
422
|
// the review's logs are watched whatever the graph comes from: they may change on disk any time
|
|
399
|
-
setInterval(() => this.checkReview(), TICK);
|
|
400
|
-
setInterval(() => {
|
|
423
|
+
this.timers.push(setInterval(() => this.checkReview(), TICK));
|
|
424
|
+
this.timers.push(setInterval(() => {
|
|
401
425
|
for (const st of [...this.streams.values()])
|
|
402
426
|
this.push(st, ": ping\n\n");
|
|
403
|
-
}, PING);
|
|
427
|
+
}, PING));
|
|
404
428
|
if (this.saved) {
|
|
405
429
|
// a saved extraction does not change: no watching of the build
|
|
406
430
|
void this.extract(null);
|
|
407
431
|
return;
|
|
408
432
|
}
|
|
409
433
|
const loop = async () => {
|
|
434
|
+
if (this.stopped)
|
|
435
|
+
return;
|
|
410
436
|
try {
|
|
411
437
|
await this.tick();
|
|
412
438
|
}
|
|
413
439
|
catch (e) {
|
|
414
440
|
this.say(`watch: ${e instanceof Error ? e.message : String(e)}`);
|
|
415
441
|
}
|
|
416
|
-
|
|
442
|
+
if (!this.stopped)
|
|
443
|
+
this.next = setTimeout(loop, TICK);
|
|
417
444
|
};
|
|
418
445
|
void loop();
|
|
419
446
|
}
|
|
447
|
+
/** the loop's timers, which `stop` clears */
|
|
448
|
+
timers = [];
|
|
449
|
+
next = null;
|
|
450
|
+
stopped = false;
|
|
451
|
+
/** Nothing more is watched (a test that ran the loop, at its end). */
|
|
452
|
+
stop() {
|
|
453
|
+
this.stopped = true;
|
|
454
|
+
for (const t of this.timers)
|
|
455
|
+
clearInterval(t);
|
|
456
|
+
if (this.next)
|
|
457
|
+
clearTimeout(this.next);
|
|
458
|
+
this.timers = [];
|
|
459
|
+
}
|
|
420
460
|
/** The review's logs changed on disk (by hand, a backup restored): what changed is read, and the
|
|
421
461
|
* store tells the pages. */
|
|
422
462
|
checkReview() {
|
|
@@ -428,30 +468,76 @@ export class Live {
|
|
|
428
468
|
}
|
|
429
469
|
}
|
|
430
470
|
async tick() {
|
|
471
|
+
const running = await compiling(this.project);
|
|
431
472
|
const now = Date.now();
|
|
432
|
-
const
|
|
433
|
-
|
|
473
|
+
const runs = [...running].sort().join(" ");
|
|
474
|
+
// the files are looked at only when something says to (server/buildwatch.ts)
|
|
475
|
+
const heard = this.buildWatch.dirty;
|
|
476
|
+
const look = shouldLook({
|
|
477
|
+
heard,
|
|
478
|
+
polling: this.buildWatch.polling !== null,
|
|
479
|
+
running: running.size,
|
|
480
|
+
runsChanged: runs !== this.lastRunning,
|
|
481
|
+
active: !!this.build?.active,
|
|
482
|
+
sinceMove: now - this.quietSince,
|
|
483
|
+
sinceLook: now - this.lastLook,
|
|
484
|
+
unread: this.lastRead !== this.extractedStamp,
|
|
485
|
+
settle: SETTLE,
|
|
486
|
+
tick: TICK,
|
|
487
|
+
});
|
|
488
|
+
if (!look)
|
|
489
|
+
return;
|
|
490
|
+
this.buildWatch.dirty = false;
|
|
491
|
+
this.lastLook = now;
|
|
492
|
+
this.lastRunning = runs;
|
|
493
|
+
let probes = probeAll(this.project, this.mods);
|
|
494
|
+
let st = stampOf(probes);
|
|
495
|
+
// the first look is not a change: a project at rest is read at once
|
|
496
|
+
const moved = st !== this.lastStamp && this.lastStamp !== "";
|
|
497
|
+
// a change no watch told of, unless its news is on its way still (through the event loop; after
|
|
498
|
+
// a moment, on macOS): one more and the watches are given up
|
|
499
|
+
if (moved && !heard && this.buildWatch.polling === null)
|
|
500
|
+
setTimeout(() => this.buildWatch.dirty || this.buildWatch.missed(), MISS_GRACE_MS).unref();
|
|
434
501
|
if (st !== this.lastStamp || this.mods.size === 0) {
|
|
435
502
|
// sources or outputs moved: files may have appeared, and the import graph changed
|
|
436
503
|
this.project.files = indexSources(this.project.root);
|
|
437
504
|
this.mods = scanModules(this.project);
|
|
438
|
-
|
|
505
|
+
probes = probeAll(this.project, this.mods);
|
|
506
|
+
st = stampOf(probes);
|
|
439
507
|
}
|
|
440
|
-
|
|
441
|
-
const moved = st !== this.lastStamp && this.lastStamp !== "";
|
|
508
|
+
this.buildWatch.watch(moduleDirs(this.project, this.mods), this.project.root);
|
|
442
509
|
this.lastStamp = st;
|
|
443
510
|
if (moved)
|
|
444
511
|
this.quietSince = now;
|
|
445
|
-
|
|
446
|
-
|
|
512
|
+
// the status as JSON once a look, compared with what went out last
|
|
513
|
+
let build = await this.tracker.status(this.mods, probes, running);
|
|
514
|
+
// following a branch, the build going on is the server's own: active from its fetch to its end
|
|
515
|
+
// (DeploySpec decision 6)
|
|
516
|
+
const d = this.deploy;
|
|
517
|
+
if (d && d.busy && !build.active)
|
|
518
|
+
build = { ...build, active: true };
|
|
519
|
+
const text = JSON.stringify(build);
|
|
447
520
|
this.build = build;
|
|
448
|
-
if (
|
|
521
|
+
if (text !== this.buildText) {
|
|
522
|
+
this.buildText = text;
|
|
449
523
|
this.send("build", build);
|
|
450
524
|
this.timeline.buildStatus(build);
|
|
451
525
|
}
|
|
526
|
+
// and its builds, beside the files: the one going on, the newest commit waiting, the last
|
|
527
|
+
if (d) {
|
|
528
|
+
const now = JSON.stringify(d.status(true));
|
|
529
|
+
if (now !== this.deploySent) {
|
|
530
|
+
this.deploySent = now;
|
|
531
|
+
this.sendDeploy();
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
// a branch's tree is read only between its builds, and only where a build wrote something:
|
|
535
|
+
// its sources change only with a checkout, which a build follows (DeploySpec decision 5)
|
|
536
|
+
const read = d ? outputsOf(probes) : st;
|
|
537
|
+
this.lastRead = read;
|
|
452
538
|
const settled = !build.active && now - this.quietSince >= SETTLE;
|
|
453
|
-
if (settled && !this.extracting &&
|
|
454
|
-
this.extractedStamp =
|
|
539
|
+
if (settled && !this.extracting && read !== this.extractedStamp && !d?.holds()) {
|
|
540
|
+
this.extractedStamp = read;
|
|
455
541
|
const ok = importable(this.project, this.mods);
|
|
456
542
|
const okSet = new Set(ok);
|
|
457
543
|
const missing = [...this.mods.keys()].filter((m) => !okSet.has(m)).sort();
|
|
@@ -516,6 +602,17 @@ export class Live {
|
|
|
516
602
|
* provisional: the usage pass's graph, which `completes` that build's extraction, is laid out as
|
|
517
603
|
* the build's own (server/pipeline.ts, prepare). */
|
|
518
604
|
async install(ex, missing, usage, completes) {
|
|
605
|
+
// the tree is read until it is served (the source texts the snapshot keeps): a branch's build
|
|
606
|
+
// waits (DeploySpec decision 5)
|
|
607
|
+
this.installing++;
|
|
608
|
+
try {
|
|
609
|
+
await this.installNow(ex, missing, usage, completes);
|
|
610
|
+
}
|
|
611
|
+
finally {
|
|
612
|
+
this.installing--;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
async installNow(ex, missing, usage, completes) {
|
|
519
616
|
const laid = await prepare(this.project, this.dirs, null, (l) => this.say(l), { extraction: ex, provisional: usage === "pending", completes });
|
|
520
617
|
if (this.graph && this.graph.fingerprint === laid.fingerprint)
|
|
521
618
|
return;
|
|
@@ -527,7 +624,8 @@ export class Live {
|
|
|
527
624
|
// versions served are made under them (HistorySpec.md)
|
|
528
625
|
const renamed = this.snapshot(ex, missing);
|
|
529
626
|
const prep = this.versioned(laid);
|
|
530
|
-
|
|
627
|
+
const commit = this.deploy?.commit()?.hash;
|
|
628
|
+
this.graph = { version: ++this.version, fingerprint: prep.fingerprint, at: new Date().toISOString(), missing, usage: { state: usage, failed }, ...(commit ? { commit } : {}), prep };
|
|
531
629
|
this.send("graph", this.graphInfo());
|
|
532
630
|
this.lostChanged();
|
|
533
631
|
// opinions recorded under the kernel's hash are bound to the versions of this graph
|
|
@@ -614,7 +712,8 @@ export class Live {
|
|
|
614
712
|
// a re-layout going on is let finish; a newer build supersedes the pass
|
|
615
713
|
while (this.extracting && this.passFor === ex.fingerprint)
|
|
616
714
|
await new Promise((ok) => setTimeout(ok, 200));
|
|
617
|
-
|
|
715
|
+
// a branch's build that started meanwhile changes the tree: its graph is read once it ends
|
|
716
|
+
if (!merged || this.passFor !== ex.fingerprint || this.deploy?.holds())
|
|
618
717
|
return;
|
|
619
718
|
this.passFor = null;
|
|
620
719
|
await this.install(merged, missing, "done", ex.fingerprint);
|
|
@@ -650,6 +749,12 @@ export class Live {
|
|
|
650
749
|
const renamed = this.review.data.renamed;
|
|
651
750
|
return renamed ? (u) => identityIn(renamed, u) : ownName;
|
|
652
751
|
}
|
|
752
|
+
/** The renames in force (to → from), which `identity` follows: what the history's worker makes it
|
|
753
|
+
* again from (server/historythread.ts). */
|
|
754
|
+
renamed() {
|
|
755
|
+
const renamed = this.review.data.renamed;
|
|
756
|
+
return renamed ? Object.entries(renamed) : null;
|
|
757
|
+
}
|
|
653
758
|
/** Keep a snapshot of the graph just read (server/history.ts): a new build's, or its own again;
|
|
654
759
|
* then pair what vanished since the build before with what appeared (server/renames.ts), and
|
|
655
760
|
* migrate the renames of high confidence. The pages are told of a snapshot made or changed
|
|
@@ -660,7 +765,10 @@ export class Live {
|
|
|
660
765
|
return renamed;
|
|
661
766
|
try {
|
|
662
767
|
const t0 = Date.now();
|
|
663
|
-
|
|
768
|
+
// a branch's build is of the commit its build checked out, on the branch followed; a
|
|
769
|
+
// workspace's, of the commit checked out as it is read
|
|
770
|
+
const d = this.deploy?.commit();
|
|
771
|
+
const commit = this.deploy ? (d ? { hash: d.hash, branch: d.branch } : null) : commitNow(this.project.root);
|
|
664
772
|
// the texts the build was compiled from, while its files are most likely still those
|
|
665
773
|
// (HistorySpec decision 21): only the files that changed since any build are written
|
|
666
774
|
let written = 0;
|
|
@@ -928,6 +1036,12 @@ export class Live {
|
|
|
928
1036
|
const r = this.invites.holder(name);
|
|
929
1037
|
return r ? { id: r.id, name: r.name } : undefined;
|
|
930
1038
|
}
|
|
1039
|
+
/** Whether `name` is an agent's now (sameName): a token in force has it, or an agent on the page
|
|
1040
|
+
* gives it — nobody's opinion is recorded for an agent, even one that has written nothing yet
|
|
1041
|
+
* (ReviewSpec decision 8, AgentSpec decision 2). */
|
|
1042
|
+
agentNamed(name) {
|
|
1043
|
+
return this.tokens.inForce().some((r) => sameName(r.name, name)) || this.presence.list().some((p) => p.agent && p.name !== null && sameName(p.name, name));
|
|
1044
|
+
}
|
|
931
1045
|
/** The usage pass's contexts of a module (shared/context.ts), when the graph on show has them. */
|
|
932
1046
|
contextsOf(module) {
|
|
933
1047
|
return this.graph?.prep.usage?.contexts[module] ?? null;
|
|
@@ -979,7 +1093,51 @@ export class Live {
|
|
|
979
1093
|
/** Whether the server is working on the build (an extraction, a re-layout, the usage pass):
|
|
980
1094
|
* no moment to restart in (UpdateSpec decision 6). */
|
|
981
1095
|
get busy() {
|
|
982
|
-
return this.extracting || this.usage.status.state === "running";
|
|
1096
|
+
return this.extracting || this.usage.status.state === "running" || !!this.deploy?.busy;
|
|
1097
|
+
}
|
|
1098
|
+
/** Whether the tree is being read: an extraction, a re-layout, a graph made ready to serve. A
|
|
1099
|
+
* branch's build changes the tree only after (DeploySpec decision 5). */
|
|
1100
|
+
get reading() {
|
|
1101
|
+
return this.extracting || this.installing > 0;
|
|
1102
|
+
}
|
|
1103
|
+
/** Following a branch, the commit of the graph on show and the branch (an exported document's
|
|
1104
|
+
* build, GET /api/git): null before a build was read; undefined for a workspace, whose commit git
|
|
1105
|
+
* says as it is now. */
|
|
1106
|
+
shownCommit() {
|
|
1107
|
+
const d = this.deploy;
|
|
1108
|
+
if (!d)
|
|
1109
|
+
return undefined;
|
|
1110
|
+
const c = this.graph?.commit ?? d.commit()?.hash;
|
|
1111
|
+
return c ? { hash: c, branch: d.status(false).branch } : null;
|
|
1112
|
+
}
|
|
1113
|
+
/** The branch followed and its builds, as agents are told them (GET /api/agent/history); null
|
|
1114
|
+
* for a workspace. */
|
|
1115
|
+
following() {
|
|
1116
|
+
return this.deploy?.status(true) ?? null;
|
|
1117
|
+
}
|
|
1118
|
+
/** A branch's build ended (DeploySpec decision 5): the tree is read again once it settles,
|
|
1119
|
+
* whatever the build wrote — a usage pass it cut short is done then, from what it finished. */
|
|
1120
|
+
reread() {
|
|
1121
|
+
this.extractedStamp = "";
|
|
1122
|
+
}
|
|
1123
|
+
/** A branch's builds changed (one started, a step, a newer commit waiting): the loop looks at its
|
|
1124
|
+
* next turn, as it does when a watch tells of a change (server/buildwatch.ts), and the pages are
|
|
1125
|
+
* told then. */
|
|
1126
|
+
lookSoon() {
|
|
1127
|
+
this.buildWatch.dirty = true;
|
|
1128
|
+
}
|
|
1129
|
+
/** The branch's builds as the pages were last told them (`deploy`). */
|
|
1130
|
+
deploySent = "";
|
|
1131
|
+
/** The branch's builds, to every page (`deploy`): a read-only reader's without the build's log
|
|
1132
|
+
* (DeploySpec decision 11). */
|
|
1133
|
+
sendDeploy() {
|
|
1134
|
+
const d = this.deploy;
|
|
1135
|
+
if (!d || !this.streams.size)
|
|
1136
|
+
return;
|
|
1137
|
+
const full = `event: deploy\ndata: ${JSON.stringify(d.status(true))}\n\n`;
|
|
1138
|
+
const slim = `event: deploy\ndata: ${JSON.stringify(d.status(false))}\n\n`;
|
|
1139
|
+
for (const st of [...this.streams.values()])
|
|
1140
|
+
this.push(st, st.readOnly === null ? full : slim);
|
|
983
1141
|
}
|
|
984
1142
|
/** What happened, to every page: a version set aside, without why, to those not told all
|
|
985
1143
|
* (UpdateSpec decision 11). */
|
|
@@ -1025,6 +1183,8 @@ export class Live {
|
|
|
1025
1183
|
// the usage pass: how far it is, and the modules it could not elaborate
|
|
1026
1184
|
usage: this.usage.status,
|
|
1027
1185
|
build: this.build,
|
|
1186
|
+
// the branch followed, where the server builds what it shows (DeploySpec)
|
|
1187
|
+
...(this.deploy ? { deploy: this.deploy.status(true) } : {}),
|
|
1028
1188
|
live: !this.saved,
|
|
1029
1189
|
editor: this.editor,
|
|
1030
1190
|
streams: { open: this.streams.size, max: MAX_STREAMS, readOnly: this.readOnlyStreams(), maxReadOnly: MAX_READONLY_STREAMS, closedForNotReading: this.dropped, agentsListening: this.talk.count },
|
|
@@ -1056,7 +1216,7 @@ export class Live {
|
|
|
1056
1216
|
connection: "keep-alive",
|
|
1057
1217
|
});
|
|
1058
1218
|
res.write("retry: 2000\n\n");
|
|
1059
|
-
const st = { res, id: randomBytes(9).toString("base64url"), token: randomBytes(24).toString("base64url"), session, private: false, person, readOnly, toldAll };
|
|
1219
|
+
const st = { res, id: randomBytes(9).toString("base64url"), token: randomBytes(24).toString("base64url"), session, private: false, person, readOnly, toldAll, room: Infinity, after: 0 };
|
|
1060
1220
|
this.streams.set(res, st);
|
|
1061
1221
|
this.byToken.set(st.token, st);
|
|
1062
1222
|
this.presence.open(st.id);
|
|
@@ -1072,8 +1232,11 @@ export class Live {
|
|
|
1072
1232
|
this.write(res, "views", { views: this.views.list(), changes: [], all: true });
|
|
1073
1233
|
if (this.build)
|
|
1074
1234
|
this.write(res, "build", this.build);
|
|
1075
|
-
|
|
1076
|
-
|
|
1235
|
+
if (this.deploy)
|
|
1236
|
+
this.write(res, "deploy", this.deploy.status(readOnly === null));
|
|
1237
|
+
// the review's revision: a page that holds another reads the whole review (GET /api/review);
|
|
1238
|
+
// what changes after comes as deltas
|
|
1239
|
+
this.write(res, "review-rev", this.reviewRev());
|
|
1077
1240
|
const g = this.graphInfo();
|
|
1078
1241
|
if (g)
|
|
1079
1242
|
this.write(res, "graph", g);
|
|
@@ -1085,6 +1248,12 @@ export class Live {
|
|
|
1085
1248
|
this.write(res, "lost", lostNews(this.lostSent));
|
|
1086
1249
|
else
|
|
1087
1250
|
this.lostChanged();
|
|
1251
|
+
st.room = MAX_BUFFERED + res.writableLength;
|
|
1252
|
+
st.after = 0;
|
|
1253
|
+
}
|
|
1254
|
+
/** Which review the server holds (`review-rev`): its run and its revision. */
|
|
1255
|
+
reviewRev() {
|
|
1256
|
+
return { epoch: this.review.epoch, rev: this.review.rev };
|
|
1088
1257
|
}
|
|
1089
1258
|
write(res, event, data) {
|
|
1090
1259
|
const st = this.streams.get(res);
|
|
@@ -1100,15 +1269,24 @@ export class Live {
|
|
|
1100
1269
|
for (const st of [...this.streams.values()])
|
|
1101
1270
|
this.push(st, text);
|
|
1102
1271
|
}
|
|
1103
|
-
/** Write to a stream, unless what it has not read yet passed MAX_BUFFERED
|
|
1104
|
-
* instead, and its page reconnects to the present state.
|
|
1272
|
+
/** Write to a stream, unless what it has not read yet passed MAX_BUFFERED beyond its hello (`room`):
|
|
1273
|
+
* then it is closed instead, and its page reconnects to the present state. A hello counted against
|
|
1274
|
+
* MAX_BUFFERED (in 0.4.3 it carried the whole review, 7 MB for 5,000 opinions on
|
|
1275
|
+
* Sphere-Packing-Lean) closed every page's stream as it opened, and the pages reconnected every two
|
|
1276
|
+
* seconds, never live. */
|
|
1105
1277
|
push(st, text) {
|
|
1106
|
-
|
|
1278
|
+
const waiting = st.res.writableLength;
|
|
1279
|
+
// all that waits was written since the hello: the hello is read
|
|
1280
|
+
if (st.room > MAX_BUFFERED && st.room !== Infinity && waiting <= st.after)
|
|
1281
|
+
st.room = MAX_BUFFERED;
|
|
1282
|
+
if (waiting > st.room) {
|
|
1107
1283
|
this.dropped++;
|
|
1108
1284
|
this.close(st);
|
|
1109
1285
|
return;
|
|
1110
1286
|
}
|
|
1111
1287
|
st.res.write(text);
|
|
1288
|
+
if (st.room > MAX_BUFFERED)
|
|
1289
|
+
st.after += text.length;
|
|
1112
1290
|
}
|
|
1113
1291
|
/** A stream is over: its page leaves the list, its secret means nothing any more. */
|
|
1114
1292
|
/** How many read-only readers' streams are open. */
|
package/dist/server/lostfound.js
CHANGED
|
@@ -72,8 +72,9 @@ export class Archive {
|
|
|
72
72
|
return lines;
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
/** Whether a file is empty, missing, or ends with a line break
|
|
76
|
-
|
|
75
|
+
/** Whether a file is empty, missing, or ends with a line break: what is appended to one that does not
|
|
76
|
+
* (a line cut short as the server stopped) starts a line of its own (server/renames.ts too). */
|
|
77
|
+
export function endsLine(file) {
|
|
77
78
|
let fd;
|
|
78
79
|
try {
|
|
79
80
|
fd = openSync(file, "r");
|