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
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// People on the page with one another (the routes of server/app.ts): where each one is, which the
|
|
2
|
+
// others see (presence: CollabSpec decisions 4 and 8), asking others to follow (decision 10), and
|
|
3
|
+
// the conversations (decision 13, AgentSpec decision 8) — the public channel, each agent's private
|
|
4
|
+
// one with its maker, a new conversation there. Agents do all of it through their API.
|
|
5
|
+
import { cleanView, madeBy, nameKey, withoutArtwork } from "../shared/collab.js";
|
|
6
|
+
import { forPages, MAX_PERSON, PUBLIC, THREAD } from "./talk.js";
|
|
7
|
+
import { mentioned } from "../shared/mentions.js";
|
|
8
|
+
import { sendJson } from "./send.js";
|
|
9
|
+
import { placeOf } from "./agentfollow.js";
|
|
10
|
+
/** where a reader is: the others see it (CollabSpec decision 4); of a private reader, only that
|
|
11
|
+
* they are here (decision 8) */
|
|
12
|
+
export async function presence(app, req, res, agent) {
|
|
13
|
+
const live = app.live;
|
|
14
|
+
const r = await app.json(req, 16384);
|
|
15
|
+
if (r.error !== undefined)
|
|
16
|
+
return sendJson(res, { error: r.error }, 400);
|
|
17
|
+
const b = (r.body ?? {});
|
|
18
|
+
// an agent is one entry by its name (server/presence.ts), never private; a page speaks for
|
|
19
|
+
// its own event stream only, by the secret the stream was given (`hello`)
|
|
20
|
+
const name = app.ids.who(req);
|
|
21
|
+
const priv = !agent && b.private === true;
|
|
22
|
+
// agents have no artwork (ExportSpec decision 19): the page draws it
|
|
23
|
+
if (agent && name)
|
|
24
|
+
live.presence.agentBeat(name, withoutArtwork(cleanView(b.view)));
|
|
25
|
+
else if (!live.beat(b.token, priv ? null : name, priv ? null : cleanView(b.view), !priv && b.idle === true, priv, !!app.ids.person(req), name))
|
|
26
|
+
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);
|
|
27
|
+
return sendJson(res, { ok: true });
|
|
28
|
+
}
|
|
29
|
+
/** The conversations (CollabSpec decision 13, AgentSpec decision 8), for pages: a channel read
|
|
30
|
+
* (GET ?channel=public|<agent id>&before=<id>, the newest 200 first) and a message written in it
|
|
31
|
+
* (POST {channel, text, place}). Everyone with a name reads and writes the public channel; an
|
|
32
|
+
* agent's private channel is its maker's alone (shared/collab.ts, madeBy: 403 to anyone else).
|
|
33
|
+
* A read-only reader neither sees nor writes any (403), whatever the page sends; agents talk
|
|
34
|
+
* through their API. A private channel cannot be written to while its agent is offline (409); a
|
|
35
|
+
* mention of it in the public channel can, and is handed to it when it comes back. At most so
|
|
36
|
+
* many messages a minute, a person's in every channel together. */
|
|
37
|
+
export async function chat(app, req, res, url) {
|
|
38
|
+
const live = app.live;
|
|
39
|
+
if (req.method !== "GET" && req.method !== "POST")
|
|
40
|
+
return sendJson(res, { error: "/api/chat answers GET and POST." }, 405);
|
|
41
|
+
if (app.readOnlyOf.has(req))
|
|
42
|
+
return sendJson(res, { error: "This page is read-only.", readOnly: true }, 403);
|
|
43
|
+
if (app.ids.kind(req) === "agent")
|
|
44
|
+
return sendJson(res, { error: "Agents talk through their API.", hint: "GET /api/agent/channel, POST /api/agent/reply." }, 403);
|
|
45
|
+
const me = app.ids.who(req);
|
|
46
|
+
if (!me)
|
|
47
|
+
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);
|
|
48
|
+
const who = { name: me, person: app.ids.person(req)?.id ?? null };
|
|
49
|
+
/** the channel a request names: the public one, or an agent's private one that is this
|
|
50
|
+
* reader's — 404 where there is no such agent, 403 where it is someone else's */
|
|
51
|
+
const channelOf = (raw) => {
|
|
52
|
+
if (raw === "public" || raw === undefined || raw === null || raw === "")
|
|
53
|
+
return { key: PUBLIC, agent: null };
|
|
54
|
+
const tok = typeof raw === "string" ? live.presence.tokenOf(raw) : null;
|
|
55
|
+
const record = tok ? live.tokens.get(tok) : undefined;
|
|
56
|
+
if (!tok || !record)
|
|
57
|
+
return { status: 404, body: { error: "There is no such channel: public, or the id of an agent with a token of its own." } };
|
|
58
|
+
if (!madeBy(record, who))
|
|
59
|
+
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 } };
|
|
60
|
+
return { key: tok, agent: { id: raw, record } };
|
|
61
|
+
};
|
|
62
|
+
if (req.method === "GET") {
|
|
63
|
+
const c = channelOf(url.searchParams.get("channel") ?? url.searchParams.get("agent"));
|
|
64
|
+
if ("status" in c)
|
|
65
|
+
return sendJson(res, c.body, c.status);
|
|
66
|
+
const raw = url.searchParams.get("before");
|
|
67
|
+
const before = raw && /^\d{1,9}$/.test(raw) ? Number(raw) : null;
|
|
68
|
+
const messages = live.talk.thread(c.key, THREAD, before).map(forPages);
|
|
69
|
+
if (!c.agent)
|
|
70
|
+
return sendJson(res, { channel: PUBLIC, messages });
|
|
71
|
+
return sendJson(res, { channel: c.agent.id, agent: { id: c.agent.id, name: c.agent.record.name, talk: live.talk.talk(c.key) }, messages });
|
|
72
|
+
}
|
|
73
|
+
const r = await app.json(req, 1 << 16);
|
|
74
|
+
if (r.error !== undefined)
|
|
75
|
+
return sendJson(res, { error: `The body is ${r.error}.` }, 400);
|
|
76
|
+
const b = (r.body ?? {});
|
|
77
|
+
const c = channelOf(b.channel ?? b.agent);
|
|
78
|
+
if ("status" in c)
|
|
79
|
+
return sendJson(res, c.body, c.status);
|
|
80
|
+
if (c.agent && live.talk.state(c.key) === "offline")
|
|
81
|
+
return sendJson(res, { error: "offline", message: `${c.agent.record.name} is offline: it can be written to once it listens again.` }, 409);
|
|
82
|
+
const text = typeof b.text === "string" ? b.text.trim() : "";
|
|
83
|
+
if (!text)
|
|
84
|
+
return sendJson(res, { error: "The message is empty." }, 400);
|
|
85
|
+
if (text.length > MAX_PERSON)
|
|
86
|
+
return sendJson(res, { error: `A message is at most ${MAX_PERSON.toLocaleString("en")} characters.` }, 400);
|
|
87
|
+
const wait = live.talk.allow("person", who.person ? `p:${who.person}` : `n:${nameKey(me)}`);
|
|
88
|
+
if (wait)
|
|
89
|
+
return sendJson(res, { error: `Too many messages at once: wait ${wait} s.`, retryAfter: wait }, 429, { "retry-after": String(wait) });
|
|
90
|
+
// where the writer was, as the page says it, bounded: a selection can be a long query; a private
|
|
91
|
+
// reader's message says nothing of where they are (CollabSpec decision 8), only who wrote it
|
|
92
|
+
const view = app.ids.privateOf(req) === null ? cleanView(b.place) : null;
|
|
93
|
+
const at = view ? placeOf(app.agents, view) : null;
|
|
94
|
+
const clip = (x, n) => (x !== null && x.length > n ? x.slice(0, n - 1) + "…" : x);
|
|
95
|
+
const where = at ? { inWords: clip(at.inWords, 600), view: at.view, declaration: clip(at.declaration, 300), selection: clip(at.selection, 300) } : null;
|
|
96
|
+
// the names it mentions; in the public channel, the agents among them are handed it
|
|
97
|
+
const can = live.mentionable();
|
|
98
|
+
const mentions = mentioned(text, can.names);
|
|
99
|
+
const to = c.agent ? [] : [...new Set(mentions.flatMap((n) => can.agents.get(nameKey(n)) ?? []))];
|
|
100
|
+
const message = live.talk.post(c.key, { from: me, kind: "person", text, ...(mentions.length ? { mentions } : {}), where, to });
|
|
101
|
+
return sendJson(res, { ok: true, channel: c.agent?.id ?? PUBLIC, message: forPages(message) });
|
|
102
|
+
}
|
|
103
|
+
/** A new conversation in an agent's private channel (AgentSpec decision 8, the owner's decisions
|
|
104
|
+
* of 2026-10-11 and 2026-10-19): a divider, from its maker alone, held to the rate of their
|
|
105
|
+
* messages; an offline agent's too, so that its next session starts clean. One right after
|
|
106
|
+
* another divides nothing: it is answered `unchanged`, and neither written nor counted. */
|
|
107
|
+
export async function chatNew(app, req, res) {
|
|
108
|
+
const live = app.live;
|
|
109
|
+
if (req.method !== "POST")
|
|
110
|
+
return sendJson(res, { error: "/api/chat/new answers POST." }, 405);
|
|
111
|
+
if (app.readOnlyOf.has(req))
|
|
112
|
+
return sendJson(res, { error: "This page is read-only.", readOnly: true }, 403);
|
|
113
|
+
if (app.ids.kind(req) === "agent")
|
|
114
|
+
return sendJson(res, { error: "A new conversation is for people to start." }, 403);
|
|
115
|
+
const me = app.ids.who(req);
|
|
116
|
+
if (!me)
|
|
117
|
+
return sendJson(res, { error: "Say who you are first: a new conversation is started under your name.", who: true }, 401);
|
|
118
|
+
const r = await app.json(req, 1 << 12);
|
|
119
|
+
if (r.error !== undefined)
|
|
120
|
+
return sendJson(res, { error: `The body is ${r.error}.` }, 400);
|
|
121
|
+
const b = (r.body ?? {});
|
|
122
|
+
const tok = typeof b.agent === "string" ? live.presence.tokenOf(b.agent) : null;
|
|
123
|
+
const record = tok ? live.tokens.get(tok) : undefined;
|
|
124
|
+
if (!tok || !record)
|
|
125
|
+
return sendJson(res, { error: "There is no such agent: only an agent with a token of its own has a private channel." }, 404);
|
|
126
|
+
const person = app.ids.person(req)?.id ?? null;
|
|
127
|
+
if (!madeBy(record, { name: me, person }))
|
|
128
|
+
return sendJson(res, { error: `Only ${record.by}, who made ${record.name}'s token, starts a new conversation with it.`, private: true }, 403);
|
|
129
|
+
if (live.talk.fresh(tok))
|
|
130
|
+
return sendJson(res, { ok: true, unchanged: true, divider: null, message: "Nothing was said since the conversation began: it is new already." });
|
|
131
|
+
const wait = live.talk.allow("person", person ? `p:${person}` : `n:${nameKey(me)}`);
|
|
132
|
+
if (wait)
|
|
133
|
+
return sendJson(res, { error: `Too many at once: wait ${wait} s.`, retryAfter: wait }, 429, { "retry-after": String(wait) });
|
|
134
|
+
const divider = live.talk.restart(tok, me);
|
|
135
|
+
return sendJson(res, { ok: true, divider: divider && forPages(divider) });
|
|
136
|
+
}
|
|
137
|
+
/** Asking others to follow (CollabSpec decision 10, the owner's decision of 2026-10-12), for pages:
|
|
138
|
+
* POST /api/ask {token, to?} — the page whose event stream holds `token` asks everyone on the
|
|
139
|
+
* server, or the person whose page is listed as `to`, to follow its reader, who has a name and is
|
|
140
|
+
* visible: a private reader cannot be followed; POST /api/ask/answer {token, id, answer} — a page
|
|
141
|
+
* asked answers, whoever its reader is. The server relays both (server/askfollow.ts); agents ask
|
|
142
|
+
* through their API (POST /api/agent/ask-follow). */
|
|
143
|
+
export async function ask(app, req, res, url) {
|
|
144
|
+
const live = app.live;
|
|
145
|
+
if (req.method !== "POST")
|
|
146
|
+
return sendJson(res, { error: `${url.pathname} answers POST.` }, 405);
|
|
147
|
+
if (app.ids.kind(req) === "agent")
|
|
148
|
+
return sendJson(res, { error: "Agents ask through their API.", hint: "POST /api/agent/ask-follow." }, 403);
|
|
149
|
+
const r = await app.json(req, 4096);
|
|
150
|
+
if (r.error !== undefined)
|
|
151
|
+
return sendJson(res, { error: `The body is ${r.error}.` }, 400);
|
|
152
|
+
const b = (r.body ?? {});
|
|
153
|
+
const page = live.pageStream(b.token);
|
|
154
|
+
if (!page)
|
|
155
|
+
return sendJson(res, { error: "This request 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);
|
|
156
|
+
if (url.pathname === "/api/ask/answer") {
|
|
157
|
+
const a = live.asks.answer(b.token, b.id, b.answer);
|
|
158
|
+
return sendJson(res, a.body, a.status);
|
|
159
|
+
}
|
|
160
|
+
if (url.pathname !== "/api/ask")
|
|
161
|
+
return sendJson(res, { error: "not found" }, 404);
|
|
162
|
+
const me = app.ids.who(req);
|
|
163
|
+
if (!me)
|
|
164
|
+
return sendJson(res, app.nameless(req, "a request to follow you says who asks"), 401);
|
|
165
|
+
if (page.private || app.ids.privateOf(req) !== null)
|
|
166
|
+
return sendJson(res, { error: "You are private: nobody can follow you. Go visible (the menu under your name) to ask." }, 409);
|
|
167
|
+
if (b.to !== undefined && b.to !== null && typeof b.to !== "string")
|
|
168
|
+
return sendJson(res, { error: "to is a reader's id, as presence lists them; left out, everyone." }, 400);
|
|
169
|
+
const person = app.ids.person(req);
|
|
170
|
+
// one request every 30 s per person — their personal link, else their name — and per page
|
|
171
|
+
const key = person ? `p:${person.id}` : `n:${nameKey(me)}`;
|
|
172
|
+
const a = live.asks.ask({ name: me, verified: !!person, agent: false, from: page.id, stream: b.token, rate: [key, `s:${b.token}`] }, typeof b.to === "string" ? { page: b.to } : { everyone: true });
|
|
173
|
+
if ("ok" in a) {
|
|
174
|
+
const { report: _, ...sent } = a.ok;
|
|
175
|
+
return sendJson(res, { ok: true, ...sent });
|
|
176
|
+
}
|
|
177
|
+
return sendJson(res, { error: a.error, ...(a.retryAfter ? { retryAfter: a.retryAfter } : {}) }, a.status, a.retryAfter ? { "retry-after": String(a.retryAfter) } : undefined);
|
|
178
|
+
}
|
package/dist/server/artcmd.js
CHANGED
|
@@ -118,7 +118,7 @@ export function makeArtwork(prep, review, project, ask) {
|
|
|
118
118
|
if (problems.length)
|
|
119
119
|
return { problems };
|
|
120
120
|
const s = cleanSettings(res.look, { scheme: "kind", theme: "light" });
|
|
121
|
-
// the theme as the mode sets it (web/src/
|
|
121
|
+
// the theme as the mode sets it (web/src/pageart.ts, drawLook): the board's style in the artwork's,
|
|
122
122
|
// the cells and the starfield in the dark one
|
|
123
123
|
const css = readFileSync(join(WEB, "style.css"), "utf8");
|
|
124
124
|
const v = cssTheme(css, s.style === "board" ? s.theme === "dark" : true);
|
package/dist/server/askfollow.js
CHANGED
|
@@ -246,7 +246,7 @@ export function askEndpoints(world, refuse) {
|
|
|
246
246
|
method: "POST",
|
|
247
247
|
path: "/api/agent/ask-follow",
|
|
248
248
|
needs: "advise",
|
|
249
|
-
about: "Ask the people on the page to follow you (the owner's decision of 2026-10-12): everyone — private readers too, counted, never named — or one person (who). Each sees a banner for 30 s, \"<you> (agent) asks you to follow · Follow · Not now\", with your mark; following you
|
|
249
|
+
about: "Ask the people on the page to follow you (the owner's decision of 2026-10-12): everyone — private readers too, counted, never named — or one person (who). Each sees a banner for 30 s, \"<you> (agent) asks you to follow · Follow · Not now\", with your mark; following you shows what you look at. Those following you already are not asked. One request every 30 s. The answer waits for theirs, at most the 30 s the request lasts (wait: false answers at once): who follows you now, who declined, who did not answer. Agents cannot be asked to follow.",
|
|
250
250
|
params: { who: "optional: a person's name, as GET /api/agent/companion lists people; left out, everyone on the page", wait: "false: answer at once, with whom it asked, without their answers (default: wait for them, at most 30 s)" },
|
|
251
251
|
returns: "{ok, id, pages, people: [{name, verified?, answer: following|declined|no answer|already following|waiting}], private: {asked, following?, declined?, no answer?, already following?, waiting?}, summary, waited} — 429 with retryAfter within 30 s of your last request",
|
|
252
252
|
run: async (a) => {
|
package/dist/server/deploy.js
CHANGED
|
@@ -8,10 +8,11 @@
|
|
|
8
8
|
// changes the tree, nothing is read from it, and the board on show stays the last build's.
|
|
9
9
|
//
|
|
10
10
|
// What is kept, in the deployment's folder of the cache (`<cache>/deploy/<repo>-<hash>/`): the
|
|
11
|
-
// clone, `state.json` (the commit the tree's
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
// by the next server, Lake
|
|
11
|
+
// clone (`clone/<repo>/`, whatever the repository is called), `state.json` (the commit the tree's
|
|
12
|
+
// outputs are of, the one checked out, the build going on, the last one that ended, the newest head
|
|
13
|
+
// seen), each build's log (`logs/`), and `.lock`: one server follows a branch with a cache at a
|
|
14
|
+
// time. A build cut short (a restart into a patch, a stop) is done again by the next server, Lake
|
|
15
|
+
// keeping what it finished.
|
|
15
16
|
//
|
|
16
17
|
// Git and Lake are run with argument arrays, never a shell; the address is checked against the
|
|
17
18
|
// schemes followed, the branch by git (`check-ref-format --branch`); nothing that git or Lake starts
|
|
@@ -21,11 +22,11 @@ import { spawn, spawnSync } from "node:child_process";
|
|
|
21
22
|
import { createHash } from "node:crypto";
|
|
22
23
|
import { closeSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
|
|
23
24
|
import { homedir, tmpdir } from "node:os";
|
|
24
|
-
import { join } from "node:path";
|
|
25
|
+
import { basename, dirname, join, relative } from "node:path";
|
|
25
26
|
import { shortCommit, slimDeploy } from "../shared/deploy.js";
|
|
26
27
|
import { childEnv, DETACH, end, grouped } from "./children.js";
|
|
27
28
|
import { dataHome, lockSite, SiteBusy } from "./dirs.js";
|
|
28
|
-
import { sourceAddress } from "./history.js";
|
|
29
|
+
import { buildTime, sourceAddress } from "./history.js";
|
|
29
30
|
import { openProject, ProjectError } from "./project.js";
|
|
30
31
|
/** How often the remote is asked by default (DeploySpec decision 3). */
|
|
31
32
|
export const DEFAULT_POLL_MINUTES = 2;
|
|
@@ -37,8 +38,11 @@ const ASK_MS = 60_000;
|
|
|
37
38
|
const GIT_MS = 10 * 60_000;
|
|
38
39
|
/** Mathlib's cache (`lake exe cache get`): it compiles the cache program first */
|
|
39
40
|
const CACHE_MS = 30 * 60_000;
|
|
40
|
-
/** `lake build
|
|
41
|
-
|
|
41
|
+
/** `--build-timeout`: the hours of `lake build` past which the build is stopped and failed
|
|
42
|
+
* (DeploySpec decision 14), by default and the least and most it takes: fractions of an hour too */
|
|
43
|
+
export const DEFAULT_BUILD_HOURS = 6;
|
|
44
|
+
export const MIN_BUILD_HOURS = 0.05;
|
|
45
|
+
export const MAX_BUILD_HOURS = 168;
|
|
42
46
|
/** the most of a build's log kept for the pages, in lines and characters */
|
|
43
47
|
const TAIL_LINES = 60;
|
|
44
48
|
const TAIL_CHARS = 8000;
|
|
@@ -137,15 +141,42 @@ export function branchProblem(name) {
|
|
|
137
141
|
return `git could not be run (${r.error.message}): following a branch needs git`;
|
|
138
142
|
return r.status === 0 && r.stdout.trim() === name ? null : no;
|
|
139
143
|
}
|
|
144
|
+
// ---------------------------------------------------------------- how long a build may take
|
|
145
|
+
/** `--build-timeout <hours>` read (DeploySpec decision 14): the hours, or why they are refused. */
|
|
146
|
+
export function parseBuildHours(v) {
|
|
147
|
+
const h = Number(v);
|
|
148
|
+
if (/^\d+(\.\d+)?$/.test(v) && h >= MIN_BUILD_HOURS && h <= MAX_BUILD_HOURS)
|
|
149
|
+
return h;
|
|
150
|
+
return { error: `--build-timeout ${v.slice(0, 40)}: say after how many hours a build is stopped, from ${MIN_BUILD_HOURS} (3 min) to ${MAX_BUILD_HOURS} (a week); 1.5 is an hour and a half` };
|
|
151
|
+
}
|
|
152
|
+
/** A build's limit as it is said: `6 hours`, `1 hour`, `1 h 30 min`, `3 min`, `4 min 12 s`. */
|
|
153
|
+
export function limitInWords(ms) {
|
|
154
|
+
if (ms < 60_000)
|
|
155
|
+
return `${Number((ms / 1000).toFixed(1))} s`;
|
|
156
|
+
const s = Math.round(ms / 1000);
|
|
157
|
+
if (s % 3600 === 0)
|
|
158
|
+
return s === 3600 ? "1 hour" : `${s / 3600} hours`;
|
|
159
|
+
const h = Math.floor(s / 3600), m = Math.floor((s % 3600) / 60), r = s % 60;
|
|
160
|
+
return [h ? `${h} h` : "", m ? `${m} min` : "", r ? `${r} s` : ""].filter(Boolean).join(" ");
|
|
161
|
+
}
|
|
140
162
|
// ---------------------------------------------------------------- where it is kept
|
|
141
163
|
/** A deployment's name among the others: the repository's name and a hash of the address and the
|
|
142
164
|
* branch. */
|
|
143
165
|
export function deployKey(remote, branch) {
|
|
144
166
|
return `${remote.name}-${createHash("sha1").update(`${remote.url}\0${branch}`).digest("hex").slice(0, 8)}`;
|
|
145
167
|
}
|
|
168
|
+
/** What the deployment's folder keeps of its own beside the clone of 0.5.0, which was named after
|
|
169
|
+
* its repository there (DeploySpec decision 2): a repository named so is moved out of their way. */
|
|
170
|
+
const OWN = /^(?:logs|mathlib-cache|state\.json(?:\.tmp-\d+)?)$/;
|
|
171
|
+
/** The deployment's folder: the clone in `clone/<repo>/`, apart from what the folder keeps of its
|
|
172
|
+
* own, whatever the repository is called (DeploySpec decision 2); a clone made by 0.5.0, named
|
|
173
|
+
* after its repository beside them, is kept where it is — never cloned again — unless its name is
|
|
174
|
+
* one of theirs (ensureClone moves it). */
|
|
146
175
|
export function deployFolder(cacheRoot, remote, branch) {
|
|
147
176
|
const dir = join(cacheRoot, "deploy", deployKey(remote, branch));
|
|
148
|
-
|
|
177
|
+
const was = join(dir, remote.name);
|
|
178
|
+
const checkout = !OWN.test(remote.name) && existsSync(join(was, ".git")) ? was : join(dir, "clone", remote.name);
|
|
179
|
+
return { dir, checkout, state: join(dir, "state.json"), logs: join(dir, "logs"), mathlib: join(dir, "mathlib-cache") };
|
|
149
180
|
}
|
|
150
181
|
/** The site of a deployment, without `--site`: under the data home by the address and the branch,
|
|
151
182
|
* so that the review stays where it is whatever `--cache` says. */
|
|
@@ -227,10 +258,23 @@ export function noPrompts(env, ssh = configuredSsh()) {
|
|
|
227
258
|
export function gitEnv(remote) {
|
|
228
259
|
return { ...noPrompts(gitBase()), GIT_ALLOW_PROTOCOL: remote.kind };
|
|
229
260
|
}
|
|
261
|
+
export const MATHLIB_CACHES = ["shared", "own"];
|
|
262
|
+
/** Mathlib's cache as the user's builds find it, as Mathlib's cache program reads it
|
|
263
|
+
* (`Cache/IO.lean`, `CACHEDIR`): `MATHLIB_CACHE_DIR`, else `$XDG_CACHE_HOME/mathlib`, else
|
|
264
|
+
* `~/.cache/mathlib`. */
|
|
265
|
+
export function sharedMathlibCache(env = process.env, home = homedir()) {
|
|
266
|
+
return env.MATHLIB_CACHE_DIR || join(env.XDG_CACHE_HOME || join(home, ".cache"), "mathlib");
|
|
267
|
+
}
|
|
230
268
|
/** Lake's environment for a build: the server's without what is its own — no access key or token
|
|
231
|
-
* of VisualProof's is in it — and no prompts for the git it runs for the dependencies.
|
|
232
|
-
|
|
233
|
-
|
|
269
|
+
* of VisualProof's is in it — and no prompts for the git it runs for the dependencies. With
|
|
270
|
+
* `mathlib`, Mathlib's cache is that folder (`MATHLIB_CACHE_DIR`, which every Mathlib since
|
|
271
|
+
* February 2025, Lean v4.17, reads: every supported toolchain's); `XDG_CACHE_HOME`, which an older
|
|
272
|
+
* one read, is left as it is, since Lake's cache and git's credential cache are found by it too. */
|
|
273
|
+
export function buildEnv(mathlib = null) {
|
|
274
|
+
const env = noPrompts(gitBase());
|
|
275
|
+
if (mathlib)
|
|
276
|
+
env.MATHLIB_CACHE_DIR = mathlib;
|
|
277
|
+
return env;
|
|
234
278
|
}
|
|
235
279
|
/** Run `cmd` with `args` — an array, never through a shell — as a group of its own (what it starts
|
|
236
280
|
* ends with it: server/children.ts), stopped past `timeoutMs`; what it writes goes to `onText` as
|
|
@@ -320,6 +364,14 @@ export async function branchToFollow(remote, given, cacheRoot) {
|
|
|
320
364
|
* nothing half made. The commit checked out, or why there is none. */
|
|
321
365
|
export async function ensureClone(remote, branch, folder, log) {
|
|
322
366
|
const env = gitEnv(remote);
|
|
367
|
+
// a clone of 0.5.0 named as what its folder keeps of its own (a repository called logs): moved
|
|
368
|
+
// into the clone's place, what it built with it
|
|
369
|
+
const was = join(folder.dir, remote.name);
|
|
370
|
+
if (was !== folder.checkout && OWN.test(remote.name) && existsSync(join(was, ".git")) && !existsSync(folder.checkout)) {
|
|
371
|
+
mkdirSync(dirname(folder.checkout), { recursive: true });
|
|
372
|
+
renameSync(was, folder.checkout);
|
|
373
|
+
log(`the clone moved to ${folder.checkout}: its folder keeps a ${remote.name} of its own`);
|
|
374
|
+
}
|
|
323
375
|
if (existsSync(join(folder.checkout, ".git"))) {
|
|
324
376
|
const r = await git(["-C", folder.checkout, "rev-parse", "--verify", "HEAD^{commit}"], env);
|
|
325
377
|
const c = r.stdout.trim();
|
|
@@ -327,12 +379,13 @@ export async function ensureClone(remote, branch, folder, log) {
|
|
|
327
379
|
return { commit: c, made: false };
|
|
328
380
|
return { error: `the clone ${folder.checkout} cannot be read (${gitWhy(r)}): remove it, and it is made again` };
|
|
329
381
|
}
|
|
330
|
-
|
|
382
|
+
const place = dirname(folder.checkout);
|
|
383
|
+
mkdirSync(place, { recursive: true });
|
|
331
384
|
// what a start that died midway left
|
|
332
|
-
for (const f of readdirSync(
|
|
333
|
-
const m = new RegExp(`^${
|
|
385
|
+
for (const f of readdirSync(place)) {
|
|
386
|
+
const m = new RegExp(`^${basename(folder.checkout).replace(/[.]/g, "\\.")}\\.tmp-(\\d+)$`).exec(f);
|
|
334
387
|
if (m && !alive(Number(m[1])))
|
|
335
|
-
rmSync(join(
|
|
388
|
+
rmSync(join(place, f), { recursive: true, force: true });
|
|
336
389
|
}
|
|
337
390
|
const tmp = `${folder.checkout}.tmp-${process.pid}`;
|
|
338
391
|
rmSync(tmp, { recursive: true, force: true });
|
|
@@ -395,29 +448,91 @@ export function onMathlib(root) {
|
|
|
395
448
|
return false;
|
|
396
449
|
}
|
|
397
450
|
}
|
|
451
|
+
/** Whether the Mathlib checked out in the project reads `MATHLIB_CACHE_DIR` (since February 2025,
|
|
452
|
+
* #21480; every supported toolchain's does): its cache program's source says so (`Cache/IO.lean`,
|
|
453
|
+
* `CACHEDIR`). One before keeps its cache by `XDG_CACHE_HOME` alone: the user's. */
|
|
454
|
+
export function mathlibReadsCacheDir(root) {
|
|
455
|
+
let packages = join(".lake", "packages");
|
|
456
|
+
try {
|
|
457
|
+
const m = JSON.parse(readFileSync(join(root, "lake-manifest.json"), "utf8"));
|
|
458
|
+
if (typeof m.packagesDir === "string" && m.packagesDir)
|
|
459
|
+
packages = m.packagesDir;
|
|
460
|
+
}
|
|
461
|
+
catch {
|
|
462
|
+
// Lake's default
|
|
463
|
+
}
|
|
464
|
+
try {
|
|
465
|
+
return readFileSync(join(root, packages, "mathlib", "Cache", "IO.lean"), "utf8").includes('"MATHLIB_CACHE_DIR"');
|
|
466
|
+
}
|
|
467
|
+
catch {
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
398
471
|
// ---------------------------------------------------------------- a build's log
|
|
472
|
+
/** What a build's log names more briefly for the pages (DeploySpec decision 11, SECURITY.md), the
|
|
473
|
+
* longest path first: the clone's folder `.`, the deployment's folder that holds it (its logs, its
|
|
474
|
+
* own Mathlib cache) from it (`../..`), and the home `~` — each as given and as resolved, since Lean
|
|
475
|
+
* prints paths resolved (macOS's /var is /private/var), git and Lake the ones given. A home reached
|
|
476
|
+
* through a symlink, or a folder under it that is one, prints resolved too: the folders elan and
|
|
477
|
+
* Lake use under it — `~/.elan` (or `$ELAN_HOME`), `~/.cache` (or `$XDG_CACHE_HOME`; Lake's cache,
|
|
478
|
+
* Mathlib's), `$MATHLIB_CACHE_DIR` where it is set — read by the path given, under `~`, whatever
|
|
479
|
+
* they resolve to (here `~/.elan` → `/data/.elan`: `/data/.elan/toolchains/…/bin/lean` reads
|
|
480
|
+
* `~/.elan/toolchains/…/bin/lean`). A folder outside the home keeps the path given. */
|
|
481
|
+
export function logNames(root, o = {}) {
|
|
482
|
+
const home = o.home ?? homedir();
|
|
483
|
+
const env = o.env ?? process.env;
|
|
484
|
+
// a folder not there yet (the clone before the first build's) as its nearest folder resolves
|
|
485
|
+
const resolved = (p) => {
|
|
486
|
+
try {
|
|
487
|
+
return realpathSync(p);
|
|
488
|
+
}
|
|
489
|
+
catch {
|
|
490
|
+
const up = dirname(p);
|
|
491
|
+
return up === p ? p : join(resolved(up), basename(p));
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
const names = new Map();
|
|
495
|
+
const name = (path, as) => {
|
|
496
|
+
for (const from of [path, resolved(path)])
|
|
497
|
+
if (from.length > 1 && !names.has(from))
|
|
498
|
+
names.set(from, as);
|
|
499
|
+
};
|
|
500
|
+
name(root, ".");
|
|
501
|
+
if (o.folder)
|
|
502
|
+
name(o.folder, relative(root, o.folder) || ".");
|
|
503
|
+
if (home && home.length > 1) {
|
|
504
|
+
const brief = (p) => (p === home ? "~" : p.startsWith(`${home}/`) ? `~${p.slice(home.length)}` : p);
|
|
505
|
+
for (const d of [env.ELAN_HOME || join(home, ".elan"), env.XDG_CACHE_HOME || join(home, ".cache"), env.MATHLIB_CACHE_DIR])
|
|
506
|
+
if (d)
|
|
507
|
+
name(d, brief(d));
|
|
508
|
+
name(home, "~");
|
|
509
|
+
}
|
|
510
|
+
return [...names].sort((a, b) => b[0].length - a[0].length);
|
|
511
|
+
}
|
|
512
|
+
/** What names a text's paths as `names` (the longest first) says, each where it is a whole path or
|
|
513
|
+
* begins one (not `/home/ann` in `/home/anne`, nor in `/mnt/home/ann`), once: what is put in stays. */
|
|
514
|
+
export function pathNamer(names) {
|
|
515
|
+
if (!names.length)
|
|
516
|
+
return (text) => text;
|
|
517
|
+
const to = new Map(names);
|
|
518
|
+
const any = names.map(([from]) => from.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&")).join("|");
|
|
519
|
+
const re = new RegExp(`(?<![\\w.~+@-])(?:${any})(?![\\w.~+@-])`, "g");
|
|
520
|
+
return (text) => text.replace(re, (m) => to.get(m) ?? m);
|
|
521
|
+
}
|
|
399
522
|
/** A build's log: everything its programs wrote, in `logs/<commit>.log` of the deployment (a build
|
|
400
|
-
* done again writes it again), and its end for the pages,
|
|
401
|
-
* home
|
|
523
|
+
* done again writes it again), and its end for the pages, its paths named briefly (`logNames`: the
|
|
524
|
+
* clone's folder `.`, the home `~`), colours and redrawn lines taken out. */
|
|
402
525
|
export class BuildLog {
|
|
403
526
|
file;
|
|
404
527
|
fd = null;
|
|
405
528
|
lines = [];
|
|
406
529
|
partial = "";
|
|
407
|
-
/** the
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
constructor(dir, commit, root) {
|
|
530
|
+
/** the paths the pages are given by another name (logNames) */
|
|
531
|
+
named;
|
|
532
|
+
constructor(dir, commit, root, o = {}) {
|
|
411
533
|
mkdirSync(dir, { recursive: true });
|
|
412
534
|
this.file = join(dir, `${commit}.log`);
|
|
413
|
-
|
|
414
|
-
try {
|
|
415
|
-
real = realpathSync(root);
|
|
416
|
-
}
|
|
417
|
-
catch {
|
|
418
|
-
// not there yet: the path as given
|
|
419
|
-
}
|
|
420
|
-
this.roots = [...new Set([real, root])].sort((a, b) => b.length - a.length);
|
|
535
|
+
this.named = pathNamer(logNames(root, o));
|
|
421
536
|
try {
|
|
422
537
|
this.fd = openSync(this.file, "w", 0o600);
|
|
423
538
|
}
|
|
@@ -456,12 +571,7 @@ export class BuildLog {
|
|
|
456
571
|
/** its end, as the pages are given it: its last `n` lines, the one being written included */
|
|
457
572
|
tail(n = TAIL_LINES) {
|
|
458
573
|
const last = this.partial.replace(/\x1b\[[0-9;?]*[ -/]*[@-~]/g, "").split("\r").pop().trimEnd();
|
|
459
|
-
const
|
|
460
|
-
let t = [...this.lines, ...(last ? [last] : [])].slice(-n).join("\n");
|
|
461
|
-
for (const r of this.roots)
|
|
462
|
-
t = t.split(r).join(".");
|
|
463
|
-
if (home && home.length > 1)
|
|
464
|
-
t = t.split(home).join("~");
|
|
574
|
+
const t = this.named([...this.lines, ...(last ? [last] : [])].slice(-n).join("\n"));
|
|
465
575
|
return t.length > TAIL_CHARS ? `…${t.slice(-TAIL_CHARS)}` : t;
|
|
466
576
|
}
|
|
467
577
|
close() {
|
|
@@ -510,6 +620,8 @@ export class Deployment {
|
|
|
510
620
|
running = null;
|
|
511
621
|
env;
|
|
512
622
|
lakeEnv;
|
|
623
|
+
/** `lake build` past which a build is stopped (DeploySpec decision 14) */
|
|
624
|
+
buildMs;
|
|
513
625
|
/** every build tried since the start, in order: what the tests read */
|
|
514
626
|
tried = [];
|
|
515
627
|
/** the log of the build going on */
|
|
@@ -520,22 +632,24 @@ export class Deployment {
|
|
|
520
632
|
this.branch = o.branch;
|
|
521
633
|
this.folder = o.folder;
|
|
522
634
|
this.env = gitEnv(o.remote);
|
|
523
|
-
this.lakeEnv = buildEnv();
|
|
635
|
+
this.lakeEnv = buildEnv(o.mathlibCache === "own" ? o.folder.mathlib : null);
|
|
636
|
+
this.buildMs = o.buildMs ?? DEFAULT_BUILD_HOURS * 3600_000;
|
|
524
637
|
this.state = this.read();
|
|
525
638
|
const head = this.headNow();
|
|
526
|
-
// the tree is one build's only where the
|
|
527
|
-
// was going on
|
|
528
|
-
this.interrupted = this.state.building !== null || (this.state.
|
|
639
|
+
// the tree is one build's only where the commit checked out is the one whose build last ran in
|
|
640
|
+
// it and no build was going on
|
|
641
|
+
this.interrupted = this.state.building !== null || (this.state.ran !== null && head !== null && head !== this.state.ran);
|
|
529
642
|
this.want = this.state.head?.commit ?? this.state.building?.commit ?? o.head ?? head;
|
|
530
643
|
this.done = this.interrupted ? null : this.state.done;
|
|
531
644
|
if (this.state.building)
|
|
532
645
|
o.hooks.log(`build: the build of ${shortCommit(this.state.building.commit)} was cut short (a restart, a stop): it is done again`);
|
|
533
646
|
}
|
|
534
647
|
read() {
|
|
535
|
-
const fresh = { version: 1, url: this.remote.url, branch: this.branch, outputs: null, building: null, done: null, last: null, head: null };
|
|
648
|
+
const fresh = { version: 1, url: this.remote.url, branch: this.branch, outputs: null, ran: null, building: null, done: null, last: null, head: null };
|
|
536
649
|
try {
|
|
537
650
|
const s = JSON.parse(readFileSync(this.folder.state, "utf8"));
|
|
538
|
-
|
|
651
|
+
// 0.5.0's: the commit whose build last ran is the one its outputs were said to be of
|
|
652
|
+
return { ...fresh, ...s, ran: s.ran ?? s.outputs?.commit ?? null, version: 1, url: this.remote.url, branch: this.branch };
|
|
539
653
|
}
|
|
540
654
|
catch {
|
|
541
655
|
return fresh;
|
|
@@ -582,8 +696,9 @@ export class Deployment {
|
|
|
582
696
|
get busy() {
|
|
583
697
|
return this.running !== null;
|
|
584
698
|
}
|
|
585
|
-
/** The commit what the tree
|
|
586
|
-
* reads (HistorySpec decision 4)
|
|
699
|
+
/** The commit what the tree's outputs were built from, and the branch: the history's for each
|
|
700
|
+
* build it reads (HistorySpec decision 4) — the last whose build wrote outputs, not a failed one
|
|
701
|
+
* that wrote none (DeploySpec decision 6). */
|
|
587
702
|
commit() {
|
|
588
703
|
return this.state.outputs ? { hash: this.state.outputs.commit, branch: this.branch } : null;
|
|
589
704
|
}
|
|
@@ -663,6 +778,11 @@ export class Deployment {
|
|
|
663
778
|
this.kick();
|
|
664
779
|
});
|
|
665
780
|
}
|
|
781
|
+
/** The commit built next where none is going on: the newest head seen, where it was not tried
|
|
782
|
+
* (the server's first lines say it). */
|
|
783
|
+
toBuild() {
|
|
784
|
+
return this.want && this.want !== this.done && this.want !== this.later ? this.want : null;
|
|
785
|
+
}
|
|
666
786
|
/** Until the build going on and those waiting are done: what the tests wait for. */
|
|
667
787
|
async settled() {
|
|
668
788
|
while (this.running || this.asking || this.retry)
|
|
@@ -685,7 +805,7 @@ export class Deployment {
|
|
|
685
805
|
this.o.hooks.changed();
|
|
686
806
|
const short = shortCommit(commit);
|
|
687
807
|
const say = this.o.hooks.log;
|
|
688
|
-
const log = (this.log = new BuildLog(this.folder.logs, commit, this.folder.checkout));
|
|
808
|
+
const log = (this.log = new BuildLog(this.folder.logs, commit, this.folder.checkout, { folder: this.folder.dir }));
|
|
689
809
|
const g = (args, ms = GIT_MS) => {
|
|
690
810
|
log.say(`$ git ${args.join(" ")}`);
|
|
691
811
|
return git(["-C", this.folder.checkout, ...args], this.env, ms, (t) => log.text(t));
|
|
@@ -736,10 +856,13 @@ export class Deployment {
|
|
|
736
856
|
this.step("cache");
|
|
737
857
|
say(`build: ${short}: getting Mathlib's cache`);
|
|
738
858
|
for (let n = 1; n <= 2 && !this.stopped; n++) {
|
|
739
|
-
|
|
859
|
+
// the deployment's own cache, beside the clone in its folder (DeploySpec decision 2)
|
|
860
|
+
log.say(`$ ${this.o.mathlibCache === "own" ? `MATHLIB_CACHE_DIR=${relative(this.folder.checkout, this.folder.mathlib)} ` : ""}lake exe cache get`);
|
|
740
861
|
const c = await run(lake, ["exe", "cache", "get"], { cwd: this.folder.checkout, env: this.lakeEnv, timeoutMs: CACHE_MS, onText: (t) => log.text(t) });
|
|
741
|
-
if (c.code === 0)
|
|
862
|
+
if (c.code === 0) {
|
|
863
|
+
await this.cleanMathlibCache(lake, log);
|
|
742
864
|
break;
|
|
865
|
+
}
|
|
743
866
|
// Lake builds what the cache did not give
|
|
744
867
|
log.say(`Mathlib's cache could not be had (${c.error ?? (c.timedOut ? "it took too long" : `exit ${c.code}`)})${n === 1 ? ": trying again" : ": lake build builds what it lacks"}`);
|
|
745
868
|
}
|
|
@@ -749,7 +872,10 @@ export class Deployment {
|
|
|
749
872
|
this.step("build");
|
|
750
873
|
say(`build: ${short}: lake build${this.o.roots.length ? ` ${this.o.roots.join(" ")}` : ""}`);
|
|
751
874
|
log.say(`$ lake build${this.o.roots.length ? ` ${this.o.roots.join(" ")}` : ""}`);
|
|
752
|
-
|
|
875
|
+
// the project's newest `.olean` before the build: whether it wrote any (as the history tells a
|
|
876
|
+
// new build: HistorySpec decision 4)
|
|
877
|
+
const before = buildTime(this.o.project);
|
|
878
|
+
const b = await run(lake, ["build", ...this.o.roots], { cwd: this.folder.checkout, env: this.lakeEnv, timeoutMs: this.buildMs, onText: (t) => log.text(t) });
|
|
753
879
|
// cut short by the server's stop: done again at the next start
|
|
754
880
|
if (this.stopped)
|
|
755
881
|
return;
|
|
@@ -757,8 +883,14 @@ export class Deployment {
|
|
|
757
883
|
await this.restore(log);
|
|
758
884
|
return ended({ ok: false, retry: true, error: `lake could not be run: ${b.error}` });
|
|
759
885
|
}
|
|
760
|
-
|
|
761
|
-
this
|
|
886
|
+
const ok = b.code === 0 && !b.timedOut;
|
|
887
|
+
// the tree is this build's, whatever came of it: checked out at its commit, its failed files
|
|
888
|
+
// shown as such; its outputs are, where it built the commit or wrote any. A failed build that
|
|
889
|
+
// wrote none leaves the board on the last build that did, which is what is said built (the
|
|
890
|
+
// owner's decision of 2026-10-19)
|
|
891
|
+
this.state.ran = commit;
|
|
892
|
+
if (ok || buildTime(this.o.project) > before)
|
|
893
|
+
this.state.outputs = { commit, at: new Date().toISOString() };
|
|
762
894
|
this.state.building = null;
|
|
763
895
|
this.interrupted = false;
|
|
764
896
|
// the modules a library's globs give, now that they are built
|
|
@@ -768,8 +900,10 @@ export class Deployment {
|
|
|
768
900
|
catch {
|
|
769
901
|
// read as it was after the checkout
|
|
770
902
|
}
|
|
771
|
-
|
|
772
|
-
|
|
903
|
+
// stopped past the limit: failed, and not tried again (DeploySpec decision 14)
|
|
904
|
+
if (b.timedOut)
|
|
905
|
+
log.say(`lake build took longer than ${limitInWords(this.buildMs)} (--build-timeout): stopped`);
|
|
906
|
+
return ended({ ok, exit: b.code, ...(b.timedOut ? { error: `it took longer than ${limitInWords(this.buildMs)} (--build-timeout): stopped` } : {}) });
|
|
773
907
|
}
|
|
774
908
|
catch (e) {
|
|
775
909
|
if (this.stopped)
|
|
@@ -783,6 +917,23 @@ export class Deployment {
|
|
|
783
917
|
this.log = null;
|
|
784
918
|
}
|
|
785
919
|
}
|
|
920
|
+
/** The deployment's own Mathlib cache keeps the version checked out alone (DeploySpec decision 2,
|
|
921
|
+
* the owner's decision of 2026-10-19): after each `lake exe cache get` that succeeded, `lake exe
|
|
922
|
+
* cache clean` deletes the files (`<hash>.ltar`) the Mathlib checked out does not link, which
|
|
923
|
+
* are what `get` fetches. Never the user's cache: only where the deployment has its own, and the
|
|
924
|
+
* Mathlib checked out reads it (one before February 2025 would clean the user's). */
|
|
925
|
+
async cleanMathlibCache(lake, log) {
|
|
926
|
+
if (this.o.mathlibCache !== "own" || this.lakeEnv.MATHLIB_CACHE_DIR !== this.folder.mathlib)
|
|
927
|
+
return;
|
|
928
|
+
if (!mathlibReadsCacheDir(this.folder.checkout)) {
|
|
929
|
+
log.say("Mathlib's cache is not cleaned: this Mathlib does not read MATHLIB_CACHE_DIR (it is older than February 2025), and keeps its cache with the user's");
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
log.say(`$ MATHLIB_CACHE_DIR=${relative(this.folder.checkout, this.folder.mathlib)} lake exe cache clean`);
|
|
933
|
+
const k = await run(lake, ["exe", "cache", "clean"], { cwd: this.folder.checkout, env: this.lakeEnv, timeoutMs: CACHE_MS, onText: (t) => log.text(t) });
|
|
934
|
+
if (k.code !== 0)
|
|
935
|
+
log.say(`Mathlib's cache could not be cleaned (${k.error ?? (k.timedOut ? "it took too long" : `exit ${k.code}`)}): what it holds of other versions stays until the next build`);
|
|
936
|
+
}
|
|
786
937
|
/** Whether the clone has `commit`. */
|
|
787
938
|
async has(commit) {
|
|
788
939
|
const r = await git(["-C", this.folder.checkout, "cat-file", "-e", `${commit}^{commit}`], this.env, ASK_MS);
|
|
@@ -792,7 +943,7 @@ export class Deployment {
|
|
|
792
943
|
* out at that build's commit again, so that what is read of it, and a restart, are that build's.
|
|
793
944
|
* Where that cannot be done, the tree stays held until a build ends. */
|
|
794
945
|
async restore(log) {
|
|
795
|
-
const was = this.state.
|
|
946
|
+
const was = this.state.ran;
|
|
796
947
|
if (was) {
|
|
797
948
|
log.say(`back to ${shortCommit(was)}, the last build's commit`);
|
|
798
949
|
const co = await git(["-C", this.folder.checkout, "-c", "advice.detachedHead=false", "checkout", "--quiet", "--force", "--detach", was], this.env);
|
package/dist/server/events.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// target's TCB that changed (with the opinions that went stale by it) — and is told of re-layouts,
|
|
5
5
|
// of targets taken off and of prefixes trusted or no longer trusted (the review's state keeps the
|
|
6
6
|
// trusted list, not who changed it), and of what agents do beside their advice: notes, layout
|
|
7
|
-
// batches and their undoing (server/
|
|
7
|
+
// batches and their undoing (server/agentplaces.ts), and of views saved, renamed, deleted and laid out
|
|
8
8
|
// afresh (server/views.ts). Opinions, targets and key marks are in the review's logs
|
|
9
9
|
// (server/review.ts); the page reads them from there.
|
|
10
10
|
//
|