visualproof 0.11.1 → 0.12.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 +5 -1
- package/dist/server/app.js +18 -6
- package/dist/server/appaccess.js +7 -5
- package/dist/server/appcall.js +118 -0
- package/dist/server/appshare.js +27 -4
- package/dist/server/call.js +373 -0
- package/dist/server/children.js +6 -5
- package/dist/server/live.js +46 -2
- package/dist/server/livekit.js +193 -0
- package/dist/server/main.js +30 -0
- package/dist/server/options.js +45 -1
- package/dist/server/pipeline.js +4 -3
- package/dist/server/readonly.js +18 -4
- package/dist/server/readonlygate.js +5 -1
- package/dist/shared/call.js +5 -0
- package/dist/shared/notecard.js +60 -1
- package/dist/web/bundle/app.js +802 -51
- package/dist/web/bundle/call.js +33692 -0
- package/dist/web/index.html +27 -0
- package/dist/web/style.css +181 -9
- package/package.json +2 -1
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// LiveKit, by hand (CallSpec, "As built"): the calls run on a LiveKit server the operator names
|
|
2
|
+
// (--livekit-url, --livekit-keys; CallSpec decision 1), which the server speaks to in two ways
|
|
3
|
+
// alone — the access tokens it gives pages, JWTs signed with the key's secret, and LiveKit's room
|
|
4
|
+
// service, its Twirp API, for who is in a room, a participant removed and a room deleted. Both are
|
|
5
|
+
// small enough to write here: the server takes no LiveKit SDK, and nothing of it but these lines
|
|
6
|
+
// knows LiveKit's wire.
|
|
7
|
+
import { createHmac } from "node:crypto";
|
|
8
|
+
import { readFileSync, statSync } from "node:fs";
|
|
9
|
+
const KEY = /^[A-Za-z0-9_.-]{1,256}$/;
|
|
10
|
+
const SECRET = /^\S{1,1024}$/;
|
|
11
|
+
/** The keys --livekit-keys names: the file's (readable by its owner alone), one line
|
|
12
|
+
* `<key>: <secret>` as LiveKit's own keys file has it; or, `env`, the server's LIVEKIT_API_KEY and
|
|
13
|
+
* LIVEKIT_API_SECRET. Or why the server does not start. */
|
|
14
|
+
export function loadLiveKitKeys(spec, env = process.env) {
|
|
15
|
+
if (spec === "env") {
|
|
16
|
+
const key = (env.LIVEKIT_API_KEY ?? "").trim();
|
|
17
|
+
const secret = (env.LIVEKIT_API_SECRET ?? "").trim();
|
|
18
|
+
if (!key || !secret)
|
|
19
|
+
return { error: "env: LIVEKIT_API_KEY and LIVEKIT_API_SECRET are not both set in the server's environment" };
|
|
20
|
+
if (!KEY.test(key) || !SECRET.test(secret))
|
|
21
|
+
return { error: "env: LIVEKIT_API_KEY or LIVEKIT_API_SECRET is not one LiveKit gives (letters, digits and _ . - for the key; no spaces in the secret)" };
|
|
22
|
+
return { key, secret };
|
|
23
|
+
}
|
|
24
|
+
let mode;
|
|
25
|
+
try {
|
|
26
|
+
const st = statSync(spec);
|
|
27
|
+
if (!st.isFile())
|
|
28
|
+
return { error: `${spec} is not a file: give the file that holds the LiveKit key and its secret, one line "<key>: <secret>"` };
|
|
29
|
+
mode = st.mode;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return { error: `${spec}: there is no such file. Write there the LiveKit key and its secret, one line "<key>: <secret>", and make it readable by the server's user alone: chmod 600 ${spec}` };
|
|
33
|
+
}
|
|
34
|
+
// as an ssh key: a file others may read is refused, not used (POSIX modes; Windows has none)
|
|
35
|
+
if (process.platform !== "win32" && (mode & 0o077) !== 0)
|
|
36
|
+
return { error: `${spec} may be read or written by others than its owner (mode ${(mode & 0o777).toString(8)}): chmod 600 ${spec}` };
|
|
37
|
+
let text;
|
|
38
|
+
try {
|
|
39
|
+
text = readFileSync(spec, "utf8");
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
return { error: `${spec} cannot be read: ${e instanceof Error ? e.message : String(e)}` };
|
|
43
|
+
}
|
|
44
|
+
return parseKeys(text, spec);
|
|
45
|
+
}
|
|
46
|
+
/** A keys file's text: one line `<key>: <secret>`, beside blank lines and comments (#). */
|
|
47
|
+
export function parseKeys(text, where = "the file") {
|
|
48
|
+
const lines = text.split(/\r?\n/).map((l) => l.trim()).filter((l) => l && !l.startsWith("#"));
|
|
49
|
+
if (lines.length === 0)
|
|
50
|
+
return { error: `${where} is empty: write there the LiveKit key and its secret, one line "<key>: <secret>"` };
|
|
51
|
+
if (lines.length > 1)
|
|
52
|
+
return { error: `${where} holds ${lines.length} lines: VisualProof takes one key, one line "<key>: <secret>"` };
|
|
53
|
+
const m = /^([^:\s]+)\s*:\s*(\S+)$/.exec(lines[0]);
|
|
54
|
+
if (!m || !KEY.test(m[1]) || !SECRET.test(m[2]))
|
|
55
|
+
return { error: `${where} does not hold a key as LiveKit's keys file does: one line "<key>: <secret>"` };
|
|
56
|
+
return { key: m[1], secret: m[2] };
|
|
57
|
+
}
|
|
58
|
+
/** A JWT signed with HS256 by `secret`. */
|
|
59
|
+
export function signJwt(payload, secret) {
|
|
60
|
+
const part = (o) => Buffer.from(JSON.stringify(o)).toString("base64url");
|
|
61
|
+
const head = `${part({ alg: "HS256", typ: "JWT" })}.${part(payload)}`;
|
|
62
|
+
return `${head}.${createHmac("sha256", secret).update(head).digest("base64url")}`;
|
|
63
|
+
}
|
|
64
|
+
/** A LiveKit access token: the key's (`iss`), for `identity` (`sub`) where it joins a room, valid
|
|
65
|
+
* from now for `ttl` seconds, with the participant's `name` and what it may do. */
|
|
66
|
+
export function accessToken(keys, o, now = Date.now()) {
|
|
67
|
+
const t = Math.floor(now / 1000);
|
|
68
|
+
return signJwt({ iss: keys.key, ...(o.identity ? { sub: o.identity } : {}), nbf: t, exp: t + o.ttl, ...(o.name !== undefined ? { name: o.name } : {}), video: o.video }, keys.secret);
|
|
69
|
+
}
|
|
70
|
+
/** What LiveKit answered other than yes: its status and Twirp's code (`not_found`, …). */
|
|
71
|
+
export class LiveKitError extends Error {
|
|
72
|
+
status;
|
|
73
|
+
code;
|
|
74
|
+
constructor(status, code, message) {
|
|
75
|
+
super(message);
|
|
76
|
+
this.status = status;
|
|
77
|
+
this.code = code;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** The address the server asks LiveKit at: --livekit-api, else the pages' --livekit-url as HTTP. */
|
|
81
|
+
export function apiOf(url, api) {
|
|
82
|
+
return (api ?? url.replace(/^ws(s?):\/\//, "http$1://")).replace(/\/+$/, "");
|
|
83
|
+
}
|
|
84
|
+
/** LiveKit's room service (its Twirp API, JSON): each request with a token of its own, a minute
|
|
85
|
+
* long, that grants what the request needs and nothing more. */
|
|
86
|
+
export class RoomService {
|
|
87
|
+
api;
|
|
88
|
+
keys;
|
|
89
|
+
fetch;
|
|
90
|
+
/** how long a request may take before it counts as unanswered */
|
|
91
|
+
timeoutMs = 10_000;
|
|
92
|
+
constructor(api, keys, fetchImpl = fetch) {
|
|
93
|
+
this.api = api.replace(/\/+$/, "");
|
|
94
|
+
this.keys = keys;
|
|
95
|
+
this.fetch = fetchImpl;
|
|
96
|
+
}
|
|
97
|
+
async call(method, body, video) {
|
|
98
|
+
const token = accessToken(this.keys, { ttl: 60, video });
|
|
99
|
+
let r;
|
|
100
|
+
try {
|
|
101
|
+
r = await this.fetch(`${this.api}/twirp/livekit.RoomService/${method}`, {
|
|
102
|
+
method: "POST",
|
|
103
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${token}` },
|
|
104
|
+
body: JSON.stringify(body),
|
|
105
|
+
signal: AbortSignal.timeout(this.timeoutMs),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
throw new LiveKitError(0, "unavailable", `LiveKit (${this.api}) could not be reached: ${e instanceof Error ? e.message : String(e)}`);
|
|
110
|
+
}
|
|
111
|
+
const text = await r.text().catch(() => "");
|
|
112
|
+
if (!r.ok) {
|
|
113
|
+
let code = "";
|
|
114
|
+
let msg = text.slice(0, 200);
|
|
115
|
+
try {
|
|
116
|
+
const b = JSON.parse(text);
|
|
117
|
+
if (typeof b.code === "string")
|
|
118
|
+
code = b.code;
|
|
119
|
+
if (typeof b.msg === "string")
|
|
120
|
+
msg = b.msg;
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// not Twirp's JSON: a proxy's page
|
|
124
|
+
}
|
|
125
|
+
// not_found only where LiveKit says so: a 404 of a proxy's, or of a wrong --livekit-api, is no
|
|
126
|
+
// room gone, and nothing it asked was done
|
|
127
|
+
throw new LiveKitError(r.status, code || "unknown", `LiveKit answered ${method} with ${r.status}${msg ? `: ${msg}` : ""}`);
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
return text ? JSON.parse(text) : {};
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
throw new LiveKitError(r.status, "malformed", `LiveKit's answer to ${method} is not JSON`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/** The room's participants; none where LiveKit has no such room (nobody was in it lately). */
|
|
137
|
+
async participants(room) {
|
|
138
|
+
let b;
|
|
139
|
+
try {
|
|
140
|
+
b = await this.call("ListParticipants", { room }, { roomAdmin: true, room });
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
if (e instanceof LiveKitError && e.code === "not_found")
|
|
144
|
+
return [];
|
|
145
|
+
throw e;
|
|
146
|
+
}
|
|
147
|
+
const list = b?.participants;
|
|
148
|
+
return Array.isArray(list) ? list.map(participantOf).filter((p) => p !== null) : [];
|
|
149
|
+
}
|
|
150
|
+
/** Remove a participant from the room; one LiveKit does not know (gone already) is no error.
|
|
151
|
+
* Nothing of its tokens is revoked (`revokeTokenTs` 1: LiveKit's own default, a minute ahead,
|
|
152
|
+
* would keep the page out that long where it enforces it): the server keeps one removed on
|
|
153
|
+
* purpose out itself (server/call.ts). */
|
|
154
|
+
async remove(room, identity) {
|
|
155
|
+
try {
|
|
156
|
+
await this.call("RemoveParticipant", { room, identity, revokeTokenTs: 1 }, { roomAdmin: true, room });
|
|
157
|
+
}
|
|
158
|
+
catch (e) {
|
|
159
|
+
if (!(e instanceof LiveKitError && e.code === "not_found"))
|
|
160
|
+
throw e;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** Delete the room: every participant is disconnected at once. A room LiveKit does not know is
|
|
164
|
+
* no error. */
|
|
165
|
+
async deleteRoom(room) {
|
|
166
|
+
try {
|
|
167
|
+
await this.call("DeleteRoom", { room }, { roomCreate: true });
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
if (!(e instanceof LiveKitError && e.code === "not_found"))
|
|
171
|
+
throw e;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/** A participant of the room service's JSON, or null for one without an identity. Its numbers are
|
|
176
|
+
* int64s, which protobuf's JSON writes as strings. */
|
|
177
|
+
function participantOf(x) {
|
|
178
|
+
const p = x;
|
|
179
|
+
if (!p || typeof p !== "object" || typeof p.identity !== "string" || !p.identity)
|
|
180
|
+
return null;
|
|
181
|
+
// seconds since the epoch, within reason: anything else is none
|
|
182
|
+
const n = (v) => {
|
|
183
|
+
const x = typeof v === "number" ? v : typeof v === "string" && /^\d{1,12}$/.test(v) ? Number(v) : 0;
|
|
184
|
+
return Number.isFinite(x) && x > 0 && x < 1e11 ? x : 0;
|
|
185
|
+
};
|
|
186
|
+
return {
|
|
187
|
+
sid: typeof p.sid === "string" ? p.sid : "",
|
|
188
|
+
identity: p.identity,
|
|
189
|
+
state: typeof p.state === "string" ? p.state : "ACTIVE",
|
|
190
|
+
joinedAt: n(p.joinedAt ?? p.joined_at),
|
|
191
|
+
kind: typeof p.kind === "string" ? p.kind : "STANDARD",
|
|
192
|
+
};
|
|
193
|
+
}
|
package/dist/server/main.js
CHANGED
|
@@ -34,6 +34,8 @@ import { App } from "./app.js";
|
|
|
34
34
|
import { findClaude, Hosted } from "./hosted.js";
|
|
35
35
|
import { DEFAULT_SERVER_AGENT_NAME, loadClaudeToken, retire010, serverAgentToken } from "./serveragent.js";
|
|
36
36
|
import { mcpServerText } from "./agententry.js";
|
|
37
|
+
import { CallRoom } from "./call.js";
|
|
38
|
+
import { apiOf, loadLiveKitKeys } from "./livekit.js";
|
|
37
39
|
/** What a stop signal does to a server: end it at once, until it can stop gracefully (serve). */
|
|
38
40
|
let stopNow = () => process.exit(0);
|
|
39
41
|
async function main() {
|
|
@@ -69,6 +71,16 @@ async function main() {
|
|
|
69
71
|
}
|
|
70
72
|
claudeToken = c.token;
|
|
71
73
|
}
|
|
74
|
+
// the call's LiveKit keys (CallSpec decision 1): read once, now, as the Claude token is
|
|
75
|
+
let livekitKeys = null;
|
|
76
|
+
if (o.cmd === "serve" && o.livekitUrl && o.livekitKeys) {
|
|
77
|
+
const k = loadLiveKitKeys(o.livekitKeys);
|
|
78
|
+
if ("error" in k) {
|
|
79
|
+
console.error(`visualproof: --livekit-keys ${o.livekitKeys === "env" ? "" : "file "}${k.error}`);
|
|
80
|
+
return endNotTheCode(2);
|
|
81
|
+
}
|
|
82
|
+
livekitKeys = k;
|
|
83
|
+
}
|
|
72
84
|
// following a branch (DeploySpec): its clone in the cache, made at the first start, is the project
|
|
73
85
|
const deploy = o.remote ? await openDeployment(o) : null;
|
|
74
86
|
if (o.remote && !deploy)
|
|
@@ -146,6 +158,21 @@ async function main() {
|
|
|
146
158
|
}
|
|
147
159
|
const review = new ReviewStore(project.root, dirs.site);
|
|
148
160
|
const live = new Live(project, dirs, o.graph, review, o.editor, o.jobs);
|
|
161
|
+
// the call, on the LiveKit server the command line names (CallSpec)
|
|
162
|
+
if (o.livekitUrl && livekitKeys)
|
|
163
|
+
live.call = new CallRoom({
|
|
164
|
+
url: o.livekitUrl,
|
|
165
|
+
api: apiOf(o.livekitUrl, o.livekitApi),
|
|
166
|
+
keys: livekitKeys,
|
|
167
|
+
site: dirs.site,
|
|
168
|
+
hooks: {
|
|
169
|
+
page: (t) => live.callPage(t),
|
|
170
|
+
pageById: (id) => live.callPageById(id),
|
|
171
|
+
send: (e, d) => live.broadcast(e, d),
|
|
172
|
+
sendTo: (t, e, d) => live.sendTo(t, e, d),
|
|
173
|
+
log: (l) => console.log(l),
|
|
174
|
+
},
|
|
175
|
+
});
|
|
149
176
|
// 0.10's agents run per person, and the Claude tokens they ran on, go (AgentSpec decision 10);
|
|
150
177
|
// the server's own agent's token is kept from one start to the next, else made
|
|
151
178
|
const agentsRoot = join(dirs.cache, "agents");
|
|
@@ -286,6 +313,8 @@ async function main() {
|
|
|
286
313
|
`--jobs ${memory.fits} if memory runs short (it starts fewer while less than ${inGB(memoryFloor())} is available)`);
|
|
287
314
|
console.log(` access: ${key ? `by its link only, /k/<the key in ${o.accessKeyFile}>${key.made ? " (a new key was made there)" : ""}${o.publicRead ? "; anyone else read-only (--public)" : ""}` : `anyone who reaches the port, by its address, localhost${[...(o.publicUrl ? [urlHost(o.publicUrl)] : []), ...o.allowedHosts].map((n) => `, ${n}`).join("")} (other names are refused: --allowed-host)`}`);
|
|
288
315
|
console.log(` version: ${version}; updates ${updatesInWords(o.updates, version, supervised)}`);
|
|
316
|
+
if (live.call)
|
|
317
|
+
console.log(` call: on the LiveKit server at ${live.call.url} (asked at ${apiOf(o.livekitUrl, o.livekitApi)}), room ${live.call.room}`);
|
|
289
318
|
if (deployment) {
|
|
290
319
|
const d = deployment.status(true);
|
|
291
320
|
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)}`);
|
|
@@ -332,6 +361,7 @@ async function main() {
|
|
|
332
361
|
updates.start();
|
|
333
362
|
});
|
|
334
363
|
live.start();
|
|
364
|
+
live.call?.start();
|
|
335
365
|
deployment?.start();
|
|
336
366
|
}
|
|
337
367
|
/** The site a branch's server keeps, as the supervisor finds it (UpdateSpec decision 7): `--site`,
|
package/dist/server/options.js
CHANGED
|
@@ -23,6 +23,7 @@ function usage(code = 2) {
|
|
|
23
23
|
[--claude-oauth file|env] [--claude-oauth-name Claude]
|
|
24
24
|
[--public-url https://host] [--allowed-host name]... [--library-limit GB]
|
|
25
25
|
[--updates auto|notify|off]
|
|
26
|
+
[--livekit-url wss://host --livekit-keys file|env [--livekit-api http://host:7880]]
|
|
26
27
|
visualproof purge-file <lean-project> <sha256> [--site dir] [--cache dir]
|
|
27
28
|
visualproof export <lean-project> -o page.html [--label text] [--root Name]... [--graph saved.json]
|
|
28
29
|
[--jobs ${DEFAULT_JOBS}] [--site dir] [--cache dir]
|
|
@@ -169,6 +170,15 @@ function usage(code = 2) {
|
|
|
169
170
|
--library-limit the most the project's library of papers and images may take, in GB (default
|
|
170
171
|
${DEFAULT_LIBRARY_LIMIT / 1024 ** 3}); its files are kept in the site directory, by their hash.
|
|
171
172
|
|
|
173
|
+
--livekit-url turns the call on: a video call among the people here, in a window of the page,
|
|
174
|
+
on the LiveKit server at this address (wss://…; your own, or LiveKit Cloud). Pages
|
|
175
|
+
connect to it directly: camera, microphone and screen go through it, never through
|
|
176
|
+
VisualProof. Without it there is no call.
|
|
177
|
+
--livekit-keys the file that holds the LiveKit API key and its secret, one line "<key>: <secret>"
|
|
178
|
+
(readable by its owner alone), or env for LIVEKIT_API_KEY and LIVEKIT_API_SECRET.
|
|
179
|
+
--livekit-api where the server asks LiveKit who is in the call, when that is not --livekit-url
|
|
180
|
+
(a LiveKit on this machine: http://127.0.0.1:7880).
|
|
181
|
+
|
|
172
182
|
purge-file deletes a file's bytes from the library for good (a file added by mistake), and what
|
|
173
183
|
was read of it; its record and its links stay in the review, saying this server lacks it.
|
|
174
184
|
Nothing else deletes a file: removing one from the page archives it.
|
|
@@ -193,7 +203,7 @@ export function parseArgs(argv) {
|
|
|
193
203
|
console.error(`visualproof: VISUALPROOF_UPDATES=${fromEnv}: say auto, notify or off`);
|
|
194
204
|
process.exit(2);
|
|
195
205
|
}
|
|
196
|
-
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", claudeOAuth: null, claudeOAuthName: null, accessKeyFile: null, jobs: DEFAULT_JOBS, leanFiles: null, 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 };
|
|
206
|
+
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", claudeOAuth: null, claudeOAuthName: null, accessKeyFile: null, jobs: DEFAULT_JOBS, leanFiles: null, 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, livekitUrl: null, livekitApi: null, livekitKeys: null };
|
|
197
207
|
for (let i = 0; i < rest.length; i++) {
|
|
198
208
|
const a = rest[i];
|
|
199
209
|
const val = () => rest[++i] ?? usage();
|
|
@@ -331,6 +341,31 @@ export function parseArgs(argv) {
|
|
|
331
341
|
usage();
|
|
332
342
|
o.libraryLimit = Math.round(gb * 1024 ** 3);
|
|
333
343
|
}
|
|
344
|
+
// the call (CallSpec decision 1): each said in a line, as --public-url is
|
|
345
|
+
else if (a === "--livekit-url" && cmd === "serve") {
|
|
346
|
+
const u = val();
|
|
347
|
+
if (!/^wss?:\/\/[^\s/?#@]+(\/[^\s?#]*)?$/.test(u)) {
|
|
348
|
+
console.error(`visualproof: --livekit-url ${u.slice(0, 200)}: give the address pages reach the LiveKit server at, wss://host (or ws://host for one on this machine), with its path if it has one`);
|
|
349
|
+
process.exit(2);
|
|
350
|
+
}
|
|
351
|
+
o.livekitUrl = u.replace(/\/+$/, "");
|
|
352
|
+
}
|
|
353
|
+
else if (a === "--livekit-api" && cmd === "serve") {
|
|
354
|
+
const u = val();
|
|
355
|
+
if (!/^https?:\/\/[^\s/?#@]+(\/[^\s?#]*)?$/.test(u)) {
|
|
356
|
+
console.error(`visualproof: --livekit-api ${u.slice(0, 200)}: give the address the server asks LiveKit at, http(s)://host:port, e.g. http://127.0.0.1:7880`);
|
|
357
|
+
process.exit(2);
|
|
358
|
+
}
|
|
359
|
+
o.livekitApi = u.replace(/\/+$/, "");
|
|
360
|
+
}
|
|
361
|
+
else if (a === "--livekit-keys" && cmd === "serve") {
|
|
362
|
+
const v = rest[++i];
|
|
363
|
+
if (v === undefined || v.startsWith("-")) {
|
|
364
|
+
console.error('visualproof: --livekit-keys takes the file that holds the LiveKit API key and its secret, one line "<key>: <secret>", or env for LIVEKIT_API_KEY and LIVEKIT_API_SECRET');
|
|
365
|
+
process.exit(2);
|
|
366
|
+
}
|
|
367
|
+
o.livekitKeys = v === "env" ? "env" : resolve(v);
|
|
368
|
+
}
|
|
334
369
|
else if (a.startsWith("-"))
|
|
335
370
|
usage();
|
|
336
371
|
else if (!o.path)
|
|
@@ -392,6 +427,15 @@ export function parseArgs(argv) {
|
|
|
392
427
|
console.error("visualproof: --claude-oauth-name names the agent --claude-oauth runs: give --claude-oauth too");
|
|
393
428
|
process.exit(2);
|
|
394
429
|
}
|
|
430
|
+
// the call is on with its LiveKit server and the keys to it, or off (CallSpec decision 1)
|
|
431
|
+
if (o.livekitUrl !== null && o.livekitKeys === null) {
|
|
432
|
+
console.error("visualproof: --livekit-url needs --livekit-keys: the file that holds the LiveKit API key and its secret, or env");
|
|
433
|
+
process.exit(2);
|
|
434
|
+
}
|
|
435
|
+
if (o.livekitUrl === null && (o.livekitKeys !== null || o.livekitApi !== null)) {
|
|
436
|
+
console.error(`visualproof: ${o.livekitKeys !== null ? "--livekit-keys" : "--livekit-api"} goes with --livekit-url, which turns the call on`);
|
|
437
|
+
process.exit(2);
|
|
438
|
+
}
|
|
395
439
|
// a template that cannot make a link is said at the start, not found out by a reader's click
|
|
396
440
|
const why = o.editor === null ? null : invalidTemplate(o.editor);
|
|
397
441
|
if (why) {
|
package/dist/server/pipeline.js
CHANGED
|
@@ -129,7 +129,7 @@ export async function ensureBundle() {
|
|
|
129
129
|
// compares with its server's — a bundle of another version would have every new tab reload
|
|
130
130
|
for (const f of [...readdirRec(join(WEB, "src")), ...readdirRec(join(SRC, "shared")), join(REPO, "package.json")])
|
|
131
131
|
newest = Math.max(newest, statSync(f).mtimeMs);
|
|
132
|
-
const beside = ["layout.js", "edges.js", "pdfworker.js"].every((f) => existsSync(join(dist, f)));
|
|
132
|
+
const beside = ["layout.js", "edges.js", "pdfworker.js", "call.js"].every((f) => existsSync(join(dist, f)));
|
|
133
133
|
if (existsSync(out) && beside && statSync(out).mtimeMs >= newest)
|
|
134
134
|
return;
|
|
135
135
|
mkdirSync(dirname(dist), { recursive: true });
|
|
@@ -147,7 +147,8 @@ export async function ensureBundle() {
|
|
|
147
147
|
/** The page's bundle, from `web/src/` of a checkout, into `outdir`: by `ensureBundle` at start, and
|
|
148
148
|
* by scripts/build.mjs into the package. Beside the page, the workers that lay out the Time
|
|
149
149
|
* Machine's past graphs (web/src/layoutworker.ts) and choose the overview's edges
|
|
150
|
-
* (web/src/edgeworker.ts) off the page's thread.
|
|
150
|
+
* (web/src/edgeworker.ts) off the page's thread; and the call (web/src/call/main.ts, CallSpec),
|
|
151
|
+
* with LiveKit's client, which the page loads only when its window first opens. */
|
|
151
152
|
export async function bundlePage(outdir, sourcemap = true) {
|
|
152
153
|
const esbuild = await import("esbuild");
|
|
153
154
|
const srcDir = join(WEB, "src");
|
|
@@ -155,7 +156,7 @@ export async function bundlePage(outdir, sourcemap = true) {
|
|
|
155
156
|
// pdf.js's worker, which reads the library's PDFs for the reference window (AttachmentSpec
|
|
156
157
|
// decision 11), is bundled beside the page's own workers and served as they are: no outside
|
|
157
158
|
// service. Its legacy build, as the page's, for browsers that lack what the modern one uses
|
|
158
|
-
entryPoints: { app: join(srcDir, "main.ts"), layout: join(srcDir, "layoutworker.ts"), edges: join(srcDir, "edgeworker.ts"), pdfworker: fileURLToPath(import.meta.resolve("pdfjs-dist/legacy/build/pdf.worker.min.mjs")) },
|
|
159
|
+
entryPoints: { app: join(srcDir, "main.ts"), layout: join(srcDir, "layoutworker.ts"), edges: join(srcDir, "edgeworker.ts"), pdfworker: fileURLToPath(import.meta.resolve("pdfjs-dist/legacy/build/pdf.worker.min.mjs")), call: join(srcDir, "call", "main.ts") },
|
|
159
160
|
bundle: true,
|
|
160
161
|
format: "esm",
|
|
161
162
|
// the owner reads in Safari: what Safari 16 lacks of the syntax (pdf.js's class static blocks; a
|
package/dist/server/readonly.js
CHANGED
|
@@ -28,7 +28,7 @@ const SECRET = /^[A-Za-z0-9_-]{43}$/;
|
|
|
28
28
|
const sha = (s) => createHash("sha256").update(s).digest();
|
|
29
29
|
const cookieValue = (r) => `${r.id}.${sha(`visualproof read-only cookie\0${r.token}`).toString("base64url")}`;
|
|
30
30
|
const same = (a, b) => timingSafeEqual(sha(a), sha(b));
|
|
31
|
-
const info = (r) => ({ id: r.id, path: `${READONLY_PATH}${r.token}`, by: r.by, created: r.created, revoked: r.revoked, revokedBy: r.revokedBy, lastUsed: r.lastUsed });
|
|
31
|
+
const info = (r) => ({ id: r.id, path: `${READONLY_PATH}${r.token}`, by: r.by, created: r.created, revoked: r.revoked, revokedBy: r.revokedBy, lastUsed: r.lastUsed, ...(r.call ? { call: true } : {}) });
|
|
32
32
|
export class ReadOnlyLinks {
|
|
33
33
|
file;
|
|
34
34
|
records = [];
|
|
@@ -60,13 +60,14 @@ export class ReadOnlyLinks {
|
|
|
60
60
|
this.timer.unref?.();
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
/** Make a link, by `by` (null: someone who gave no name)
|
|
64
|
-
|
|
63
|
+
/** Make a link, by `by` (null: someone who gave no name); `call`: its holder may join the call
|
|
64
|
+
* (CallSpec decision 4). */
|
|
65
|
+
create(by, now = Date.now(), call = false) {
|
|
65
66
|
let id;
|
|
66
67
|
do
|
|
67
68
|
id = randomBytes(5).toString("hex");
|
|
68
69
|
while (this.records.some((r) => r.id === id));
|
|
69
|
-
const r = { id, token: `${READONLY_PREFIX}${id}_${randomBytes(32).toString("base64url")}`, by, created: new Date(now).toISOString(), revoked: null, revokedBy: null, lastUsed: null };
|
|
70
|
+
const r = { id, token: `${READONLY_PREFIX}${id}_${randomBytes(32).toString("base64url")}`, by, created: new Date(now).toISOString(), revoked: null, revokedBy: null, lastUsed: null, ...(call ? { call: true } : {}) };
|
|
70
71
|
this.records.push(r);
|
|
71
72
|
this.save();
|
|
72
73
|
return info(r);
|
|
@@ -116,6 +117,19 @@ export class ReadOnlyLinks {
|
|
|
116
117
|
const r = this.records.find((x) => x.id === id);
|
|
117
118
|
return r ? info(r) : undefined;
|
|
118
119
|
}
|
|
120
|
+
/** Whether a link in force joins the call, switched (CallSpec decision 4): the link as it is
|
|
121
|
+
* now, or null where there is no such link in force. */
|
|
122
|
+
setCall(id, call) {
|
|
123
|
+
const r = this.records.find((x) => x.id === id);
|
|
124
|
+
if (!r || r.revoked)
|
|
125
|
+
return null;
|
|
126
|
+
if (call)
|
|
127
|
+
r.call = true;
|
|
128
|
+
else
|
|
129
|
+
delete r.call;
|
|
130
|
+
this.save();
|
|
131
|
+
return info(r);
|
|
132
|
+
}
|
|
119
133
|
/** Revoke a link in force: it lets nobody in from now on, and its pages' streams end. */
|
|
120
134
|
revoke(id, by, now = Date.now()) {
|
|
121
135
|
const r = this.records.find((x) => x.id === id);
|
|
@@ -7,7 +7,7 @@ export function readOnlyAllows(method, path) {
|
|
|
7
7
|
const read = method === "GET" || method === "HEAD";
|
|
8
8
|
if (read) {
|
|
9
9
|
// the page and its files: its fonts, the tips' clips (GuideSpec decision 6)
|
|
10
|
-
if (path === "/" || path === "/index.html" || path === "/style.css" || /^\/(app|layout|edges|pdfworker)\.js(\.map)?$/.test(path) || path.startsWith("/pdfjs/") || path.startsWith("/fonts/") || path.startsWith("/tips/"))
|
|
10
|
+
if (path === "/" || path === "/index.html" || path === "/style.css" || /^\/(app|layout|edges|pdfworker|call)\.js(\.map)?$/.test(path) || path.startsWith("/pdfjs/") || path.startsWith("/fonts/") || path.startsWith("/tips/"))
|
|
11
11
|
return true;
|
|
12
12
|
// the graph, its sources and Lean's answers, the review, the build status, what happened, the
|
|
13
13
|
// views, the history, the library, the printed document's state and files, who the reader is
|
|
@@ -35,6 +35,10 @@ export function readOnlyAllows(method, path) {
|
|
|
35
35
|
// 2026-10-20): its own pointer is relayed to nobody, and it is counted nowhere
|
|
36
36
|
if (method === "POST" && path === "/api/pointer")
|
|
37
37
|
return true;
|
|
38
|
+
// the call, by a read-only link that joins it (CallSpec decision 4): a token, and leaving; the
|
|
39
|
+
// route asks the link, and lets them do nothing else there
|
|
40
|
+
if (method === "POST" && (path === "/api/call/token" || path === "/api/call/leave"))
|
|
41
|
+
return true;
|
|
38
42
|
return false;
|
|
39
43
|
}
|
|
40
44
|
/** Whether Lean's answer is what it says in the end, to be kept for the build: not a failure, nor
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// The call as the server tells the pages of it (CallSpec): who is in it, as the server knows them —
|
|
2
|
+
// never as LiveKit, or a participant, says it — and what one page is told alone.
|
|
3
|
+
/** What a tab of a page calls itself in the call (web/src/call/tab.ts): the server's identity of
|
|
4
|
+
* its participant is made of it, and nobody else is told it. */
|
|
5
|
+
export const CALL_TAB = /^[A-Za-z0-9_-]{16,64}$/;
|
package/dist/shared/notecard.js
CHANGED
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
// The notes layer stacks, bottom to top (NOTE_Z): the leaders, the icons and dots with the folded
|
|
25
25
|
// clusters' markers, the cards — the one pressed or opened last in front —, what would hold a dragged
|
|
26
26
|
// note, and the icon being dragged. An expanded note's card covers the icons under it; its own it
|
|
27
|
-
// never covers, since a card hangs clear of its icon.
|
|
27
|
+
// never covers, since a card hangs clear of its icon. Another card it covers only where no place
|
|
28
|
+
// near enough is free (the owner's decision of 2026-11-10, spreadCards).
|
|
28
29
|
import { AUTO_COLLAPSE_PX, CARD_REACH, DECL_AT, DECL_REACH, keptDecl, noteLook, ZONE_MAX_PX, ZONE_MIN_PX } from "./sticky.js";
|
|
29
30
|
/** the icon's diameter on the screen, in pixels: something to point at and click, small enough to
|
|
30
31
|
* sit in a cluster without covering what is around its place */
|
|
@@ -257,6 +258,64 @@ export function hangCard(icon, off, w, h, room, avoid = null) {
|
|
|
257
258
|
}
|
|
258
259
|
return { box: best.box, flip: best.flip };
|
|
259
260
|
}
|
|
261
|
+
/** the room kept between two cards set apart (spreadCards), in pixels of the screen */
|
|
262
|
+
export const CARD_APART = 6;
|
|
263
|
+
/** The cards' boxes set apart so that, as far as they can be, no card covers another (the owner's
|
|
264
|
+
* decision of 2026-11-10): one placed by hand, or dragged, stays where it is; every other, from the
|
|
265
|
+
* top of the screen down, keeps where it hangs by itself where nothing taken is there, and else
|
|
266
|
+
* moves the least it can to where nothing is — another way round its icon (FLIPS), or from one of
|
|
267
|
+
* them along an edge of a card in the way to just past it, CARD_APART clear —, clear of its own
|
|
268
|
+
* icon, within CARD_REACH of it, no further out of the room nor over the name it keeps off than it
|
|
269
|
+
* was. Where no such place is, it stays where it hangs, over the others. */
|
|
270
|
+
export function spreadCards(cards) {
|
|
271
|
+
const out = cards.map((c) => c.box);
|
|
272
|
+
const taken = cards.filter((c) => c.fixed).map((c) => c.box);
|
|
273
|
+
const free = cards
|
|
274
|
+
.map((c, i) => ({ c, i }))
|
|
275
|
+
.filter(({ c }) => !c.fixed)
|
|
276
|
+
.sort((a, b) => a.c.box.y0 - b.c.box.y0 || a.c.box.x0 - b.c.box.x0 || a.i - b.i);
|
|
277
|
+
for (const { c, i } of free) {
|
|
278
|
+
const b = c.box;
|
|
279
|
+
const meets = (x) => taken.some((t) => area(x, t) > 0);
|
|
280
|
+
if (!meets(b)) {
|
|
281
|
+
taken.push(b);
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
const w = b.x1 - b.x0, h = b.y1 - b.y0;
|
|
285
|
+
const outside = (x) => Math.max(0, w * h - area(x, c.room));
|
|
286
|
+
const was = { out: outside(b), covers: !!c.avoid && area(b, c.avoid) > 0 };
|
|
287
|
+
const [ix, iy] = c.icon;
|
|
288
|
+
const off = [(b.x0 + b.x1) / 2 - ix, (b.y0 + b.y1) / 2 - iy];
|
|
289
|
+
const fits = (x) => {
|
|
290
|
+
const dx = (x.x0 + x.x1) / 2 - ix, dy = (x.y0 + x.y1) / 2 - iy;
|
|
291
|
+
if (Math.abs(dx) > CARD_REACH || Math.abs(dy) > CARD_REACH)
|
|
292
|
+
return false;
|
|
293
|
+
if (Math.abs(dx) < w / 2 + ICON_CLEAR && Math.abs(dy) < h / 2 + ICON_CLEAR)
|
|
294
|
+
return false;
|
|
295
|
+
if (outside(x) > was.out + 0.5)
|
|
296
|
+
return false;
|
|
297
|
+
if (!was.covers && c.avoid && area(x, c.avoid) > 0)
|
|
298
|
+
return false;
|
|
299
|
+
return !meets(x);
|
|
300
|
+
};
|
|
301
|
+
const by = (x, dx, dy) => ({ x0: x.x0 + dx, y0: x.y0 + dy, x1: x.x1 + dx, y1: x.y1 + dy });
|
|
302
|
+
const ways = [];
|
|
303
|
+
for (const [fx, fy] of FLIPS) {
|
|
304
|
+
const f = cardBox(ix, iy, [off[0] * fx, off[1] * fy], w, h);
|
|
305
|
+
ways.push(f);
|
|
306
|
+
for (const t of taken)
|
|
307
|
+
ways.push(by(f, 0, t.y0 - CARD_APART - f.y1), by(f, 0, t.y1 + CARD_APART - f.y0), by(f, t.x0 - CARD_APART - f.x1, 0), by(f, t.x1 + CARD_APART - f.x0, 0));
|
|
308
|
+
}
|
|
309
|
+
// the nearest to where it hangs by itself, the first of those as near: tried nearest first
|
|
310
|
+
const cx = (b.x0 + b.x1) / 2, cy = (b.y0 + b.y1) / 2;
|
|
311
|
+
const far = ways.map((x, k) => ({ x, k, d: Math.hypot((x.x0 + x.x1) / 2 - cx, (x.y0 + x.y1) / 2 - cy) }));
|
|
312
|
+
far.sort((p, q) => p.d - q.d || p.k - q.k);
|
|
313
|
+
const best = far.find((p) => fits(p.x))?.x ?? b;
|
|
314
|
+
out[i] = best;
|
|
315
|
+
taken.push(best);
|
|
316
|
+
}
|
|
317
|
+
return out;
|
|
318
|
+
}
|
|
260
319
|
/** The leader between an icon at (x, y) and its card's box: from the icon's edge to the point of the
|
|
261
320
|
* card nearest the icon's centre; null where they touch. */
|
|
262
321
|
export function leaderLine(x, y, b) {
|