clavarium 0.2.465-next.1 → 0.2.467-next.1
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/deploy/updater.mjs +12 -3
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/bridge.mjs +3 -1
- package/server/conversations.mjs +5 -1
- package/server/health.mjs +6 -0
- package/server/main.mjs +10 -5
- package/server/revive.mjs +14 -10
- package/web/app.js +2 -1
package/deploy/updater.mjs
CHANGED
|
@@ -85,6 +85,10 @@ const WATCH_EVERY_MS = 3600_000;
|
|
|
85
85
|
const WATCH_RECENT_MS = 24 * 3600_000;
|
|
86
86
|
const HISTORY_MAX = 30;
|
|
87
87
|
const ASK_EVERY_MS = 6 * 3600_000;
|
|
88
|
+
/* A VERSION THAT COULD NOT EVEN BE FETCHED (16-11: npm asked one minute after it came out, before every mirror
|
|
89
|
+
had it): nothing of it ran here, so it is tried again by itself, this long after, this many times at most. */
|
|
90
|
+
export const FETCH_AGAIN_MS = 30 * 60_000;
|
|
91
|
+
export const FETCH_TRIES = 3;
|
|
88
92
|
/* Between "Switching" said in state.json and the server stopped: the pages ask the server every
|
|
89
93
|
10 seconds at most (app.js), and the server says it in each answer (updates.mjs, notice): each
|
|
90
94
|
gives way to the maintenance page before the server goes. */
|
|
@@ -602,7 +606,7 @@ export class Updater {
|
|
|
602
606
|
const unlock = this.#lock();
|
|
603
607
|
try {
|
|
604
608
|
let release;
|
|
605
|
-
try { release = await this.prepare({ version }); } catch (error) { this.#history({ action: 'update', from: from?.version ?? null, to: version, result: 'failed', why: error.message }); throw error; }
|
|
609
|
+
try { release = await this.prepare({ version }); } catch (error) { this.#history({ action: 'update', from: from?.version ?? null, to: version, result: 'failed', why: error.message, ...(/^npm could not install /.test(error.message) ? { fetch: true } : {}) }); throw error; }
|
|
606
610
|
const before = this.#dataFormat();
|
|
607
611
|
let archive;
|
|
608
612
|
try {
|
|
@@ -714,8 +718,13 @@ export class Updater {
|
|
|
714
718
|
const available = await this.check();
|
|
715
719
|
if (!available) return 'up to date';
|
|
716
720
|
if (conf.MODE === 'ask') return `${available} is out: waiting for the owner`;
|
|
717
|
-
/* A version that failed here is not tried again by itself: the owner can, from Settings.
|
|
718
|
-
|
|
721
|
+
/* A version that failed here is not tried again by itself: the owner can, from Settings. One that only
|
|
722
|
+
could not be fetched (nothing of it ran) is, later, a few times. */
|
|
723
|
+
const failed = (state.history ?? []).filter((h) => h.to === available && h.action === 'update' && h.result !== 'done');
|
|
724
|
+
if (failed.some((h) => h.fetch !== true)) return `${available} failed here before: not tried again by itself`;
|
|
725
|
+
if (failed.length >= FETCH_TRIES) return `${available} could not be fetched ${failed.length} times: not tried again by itself`;
|
|
726
|
+
const lastAt = Math.max(...failed.map((h) => new Date(h.at ?? 0).getTime()), -Infinity);
|
|
727
|
+
if (failed.length && now - lastAt < FETCH_AGAIN_MS) return `${available} could not be fetched: tried again later`;
|
|
719
728
|
const why = await this.busy(); if (why) return why;
|
|
720
729
|
await this.apply(available);
|
|
721
730
|
/* What the history says, not what was hoped: a version that did not start was undone. */
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.467-next.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.467-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/bridge.mjs
CHANGED
|
@@ -185,7 +185,9 @@ export function attachBridge(server, { spawn, onLeft = () => {}, onEnded = () =>
|
|
|
185
185
|
return run;
|
|
186
186
|
}
|
|
187
187
|
async function openNow(name, cols, rows, sink, say) {
|
|
188
|
-
|
|
188
|
+
/* Who opens it, for What happened when it wakes a sleeper: a screen, or this server (warm). */
|
|
189
|
+
const who = sink ? (deviceSeats.has(sink) ? 'a paired device' : 'a page') : undefined;
|
|
190
|
+
const terminal = await spawn(name, cols, rows, say, who);
|
|
189
191
|
/* While it was being opened another one may have been: the newest wins. */
|
|
190
192
|
if (live.has(name)) close(name);
|
|
191
193
|
const kept = { terminal, sink, cols, rows, openedAt: Date.now(), outputAt: Date.now() };
|
package/server/conversations.mjs
CHANGED
|
@@ -163,6 +163,9 @@ export class Conversations {
|
|
|
163
163
|
/* Set by the server: its wake-ups, for a whole export; and on its import, when asked, its reminders (from the
|
|
164
164
|
export's work folder) and those wake-ups given again (15-11, as a copy does). */
|
|
165
165
|
wakeupsOf = () => undefined;
|
|
166
|
+
/* Set by the server: a machine put to sleep or stopped, woken by an opening -- `by` who (16-11: a sleeper found
|
|
167
|
+
awake in the morning, and nothing said who woke it). Said in What happened. */
|
|
168
|
+
woken = () => {};
|
|
166
169
|
importReminders = async () => {};
|
|
167
170
|
|
|
168
171
|
/* `uid`/`gid`: the account this server runs as; files the tool writes in
|
|
@@ -560,7 +563,7 @@ export class Conversations {
|
|
|
560
563
|
}
|
|
561
564
|
|
|
562
565
|
/* What a terminal must run to reach this conversation. Wakes the VM first. */
|
|
563
|
-
async open(name, say = () => {}) {
|
|
566
|
+
async open(name, say = () => {}, by = 'the server') {
|
|
564
567
|
const c = this.#store.get(name);
|
|
565
568
|
if (!c) throw new Refusal(404, 'No such conversation.');
|
|
566
569
|
if (c.phase !== 'ready') throw new Refusal(409, c.phase === 'building' ? 'This conversation is still being built.' : c.phase === 'moving' ? 'This conversation is moving its work folder.' : 'This conversation could not be built.');
|
|
@@ -571,6 +574,7 @@ export class Conversations {
|
|
|
571
574
|
/* Opening is the explicit gesture that ends a sleep, or a stop its owner asked for. */
|
|
572
575
|
if (c.asleep) this.#store.patch(name, { asleep: false });
|
|
573
576
|
if (c.stopped) this.#store.patch(name, { stopped: undefined });
|
|
577
|
+
if (c.asleep || c.stopped) { try { this.woken(name, by, c.asleep ? 'asleep' : 'stopped'); } catch { /* said, nothing more */ } }
|
|
574
578
|
this.#watching.set(name, (this.#watching.get(name) ?? 0) + 1);
|
|
575
579
|
/* Another screen is applying the size kept for its wake: this one opens once it is over. */
|
|
576
580
|
await this.#resizing.get(name)?.catch(() => {});
|
package/server/health.mjs
CHANGED
|
@@ -33,6 +33,10 @@ import { SESSION } from './conversations.mjs';
|
|
|
33
33
|
export const RESTART_OUTSIDE = '/var/tmp/clavarium-restart-asked';
|
|
34
34
|
/* What a folder that came loose looks like on a terminal (the kernel's words for ENOTCONN). */
|
|
35
35
|
const LOOSE_WORDS = 'transport endpoint is not connected|socket is not connected|ENOTCONN';
|
|
36
|
+
/* A WORK FOLDER THE VM MANAGER CANNOT TAKE BACK (16-11, tried on a test server): its mount program died, multipass
|
|
37
|
+
cannot unmount it ("Failed to terminate SSHFS mount process") and then refuses to mount it again ("already
|
|
38
|
+
mounted"). Only a restart of its machine mounts it again. */
|
|
39
|
+
export const STUCK_MOUNT = /already mounted|terminate SSHFS mount process/i;
|
|
36
40
|
|
|
37
41
|
/* How long installing the shared-folder helper in a machine may take (it comes from the snap store). */
|
|
38
42
|
export const SHARING_MS = 180_000;
|
|
@@ -143,6 +147,7 @@ export function judge(record) {
|
|
|
143
147
|
for (const path of record.remounted ?? []) add('info', 'mount', `remounted:${path}`, `${path} had come loose in the machine: it was mounted again.`);
|
|
144
148
|
for (const { path, why } of record.failed ?? []) add('bad', 'mount', `failed:${path}`, `${path} is not reachable in the machine and could not be mounted again${why ? `: ${why}` : ''}.`);
|
|
145
149
|
for (const path of record.missing ?? []) if (!(record.failed ?? []).some((f) => f.path === path)) add('warn', 'mount', `missing:${path}`, `${path} is not reachable in the machine.`);
|
|
150
|
+
if (record.stuckWork) add('bad', 'mount', 'stuck-work', 'Its work folder cannot be mounted again in its machine: its machine is restarted, its work picks up where it was.');
|
|
146
151
|
if (record.stale) add('bad', 'mount', 'stale-tool', 'Its tool is still in a folder that came loose: it is restarted, its work picks up where it was.');
|
|
147
152
|
/* Its terminal says so while its folders look well: said, nothing done (its tool may only be quoting it). */
|
|
148
153
|
else if (record.screenLoose > 0 && !(record.missing ?? []).length) add('warn', 'mount', 'screen-loose', 'Its terminal says a folder is not connected, though its folders look well.');
|
|
@@ -249,6 +254,7 @@ export class Health {
|
|
|
249
254
|
return this.#keep(name, {
|
|
250
255
|
at, state, answering: true, memory: facts.memory, oomKills: facts.oomKills ?? 0, ...(facts.oomKinds ? { oomKinds: facts.oomKinds } : {}), disks: facts.disks,
|
|
251
256
|
paths, missing: loose(), ...(remounted.length ? { remounted } : {}), ...(failed.length ? { failed } : {}), ...(links ? { links } : {}),
|
|
257
|
+
...(failed.some((f) => f.path === '/work' && STUCK_MOUNT.test(f.why ?? '')) ? { stuckWork: true } : {}),
|
|
252
258
|
...(facts.stale ? { stale: true } : {}), ...(facts.screenLoose ? { screenLoose: facts.screenLoose } : {}), ...(facts.restartAsked ? { restartAsked: true } : {}),
|
|
253
259
|
/* What was put back stays said until a later look finds nothing to put back. */
|
|
254
260
|
});
|
package/server/main.mjs
CHANGED
|
@@ -483,7 +483,10 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
483
483
|
/* A sign-in a companion did for another conversation (signinhelp.mjs, made below): its answer typed there. */
|
|
484
484
|
acked: (name, e) => signinHelp?.acked(name, e) });
|
|
485
485
|
const typingWatch = new TypingWatch();
|
|
486
|
-
|
|
486
|
+
/* WHO WOKE IT (16-11): this server opens a terminal for others (a wake-up, a key); said once it wakes one. */
|
|
487
|
+
const wakeWhy = { why: new Map(), set(name, by) { this.why.set(name, by); }, take(name) { const by = this.why.get(name); this.why.delete(name); return by ?? 'the server'; } };
|
|
488
|
+
all.woken = (name, by, was) => events.add({ kind: 'machine', text: `Machine of ${name}: woken by ${by} (it was ${was})`, conversation: name });
|
|
489
|
+
const wakeups = new Wakeups({ store: new Store(`${dataDir}/wakeups.json`), vms, conversations: all, resources: folders, warm: (name) => { if (!all.awake().includes(name)) wakeWhy.set(name, 'its wake-up'); return bridge?.warm(name); }, docket: dockets, typing: (name) => typingWatch.busy(name),
|
|
487
490
|
fired: (name, { text }) => talk.event(name, { kind: 'wakeup', text, topic: 'Wake-up' }) });
|
|
488
491
|
const wakeTimer = wakeups.start(wakeEveryMs);
|
|
489
492
|
const docketTimer = dockets.start(wakeEveryMs);
|
|
@@ -618,16 +621,17 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
618
621
|
by the server, its tool only; told through its docket first (read as it starts), its chat after. */
|
|
619
622
|
const revive = new Revive({
|
|
620
623
|
restart: (name) => all.restartTool(name),
|
|
624
|
+
restartMachine: async (name) => { const r = await all.machineAction(name, 'restart', { wait: true }); return r?.ok !== false; },
|
|
621
625
|
busy: (name) => talk.pulse(name)?.busy === true,
|
|
622
626
|
taken: (name) => vms.exec(name, ['rm', '-f', RESTART_OUTSIDE], { timeoutMs: 10_000 }),
|
|
623
627
|
tell: (name, why, step) => {
|
|
624
|
-
const loose = why === 'stale';
|
|
628
|
+
const loose = why === 'stale' || why === 'stuck';
|
|
625
629
|
if (step === 'before') {
|
|
626
630
|
if (loose) try { if (dockets.on(name)) dockets.post(name, { kind: 'restarted', text: 'Your work folder came loose in your machine and was put back: your tool was restarted to see it again (what was in the old one could not be reached). Your work picks up where it was; what ran in the background stopped.' }); } catch { /* its docket may be off */ }
|
|
627
631
|
return;
|
|
628
632
|
}
|
|
629
633
|
const text = step === 'done'
|
|
630
|
-
? (loose ? 'Its work folder had come loose: its tool was restarted to see it again. Its work picks up where it was.' : 'Its tool was restarted as it asked: its work picks up where it was.')
|
|
634
|
+
? (why === 'stuck' ? 'Its work folder could not be mounted again: its machine was restarted, the folder is back. Its work picks up where it was.' : loose ? 'Its work folder had come loose: its tool was restarted to see it again. Its work picks up where it was.' : 'Its tool was restarted as it asked: its work picks up where it was.')
|
|
631
635
|
: 'Its tool could not be restarted: open its terminal and type exit, it starts again.';
|
|
632
636
|
try { talk.event(name, { kind: step === 'done' ? 'restarted' : 'machine-problem', text, topic: step === 'done' ? 'Restarted' : 'Machine', ...(step === 'done' ? {} : { tone: 'warn' }) }); } catch { /* its chat is off */ }
|
|
633
637
|
if (step === 'failed') events.add({ kind: 'machine', text: `${name}: ${text}`, conversation: name });
|
|
@@ -865,6 +869,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
865
869
|
wake: (name) => {
|
|
866
870
|
const c = all.get(name);
|
|
867
871
|
if (c?.phase !== 'ready') throw new Refusal(409, 'This conversation is not ready.');
|
|
872
|
+
if (c.asleep === true || c.stopped === true) wakeWhy.set(name, 'a key (API)');
|
|
868
873
|
void bridge?.warm(name);
|
|
869
874
|
return { state: c.asleep === true ? 'waking' : 'awake' };
|
|
870
875
|
},
|
|
@@ -920,8 +925,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
920
925
|
/* Put to sleep or stopped: a page that comes back by itself does not wake it (bridge.mjs, CLOSE_ASLEEP). */
|
|
921
926
|
asleep: (name) => { const c = all.get(name); return c?.asleep === true || c?.stopped === true; },
|
|
922
927
|
onTyped: (name, data) => { answerer.typed(name, data); talk.typed(name); all.touch(name); typingWatch.typed(name, data); },
|
|
923
|
-
spawn: async (name, cols, rows, say) => {
|
|
924
|
-
const [program, ...argv] = await all.open(name, say);
|
|
928
|
+
spawn: async (name, cols, rows, say, who) => {
|
|
929
|
+
const [program, ...argv] = await all.open(name, say, who ?? wakeWhy.take(name));
|
|
925
930
|
const started = pty.spawn(program, argv, { name: 'xterm-256color', env: withoutTmux(env), cols, rows });
|
|
926
931
|
/* Its start is over once something is drawn (nothing of it is
|
|
927
932
|
read), once it ends, or after a while whatever happens. Not
|
package/server/revive.mjs
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Told by health.mjs, each look (`judged`):
|
|
9
9
|
* - `stale`: a program of its tool's session is in a folder that cannot be entered;
|
|
10
|
-
* - `restartAsked`: its tool asked from outside /work (health.mjs, RESTART_OUTSIDE)
|
|
10
|
+
* - `restartAsked`: its tool asked from outside /work (health.mjs, RESTART_OUTSIDE);
|
|
11
|
+
* - `stuckWork`: its work folder cannot be mounted again (health.mjs, STUCK_MOUNT): its MACHINE is restarted
|
|
12
|
+
* (`restartMachine`), the one thing that mounts it again; it outranks the others.
|
|
11
13
|
* Then, at the next tick: its tool only is restarted (conversations.mjs restartTool, never its
|
|
12
14
|
* machine), once its turn has ended -- or after WAIT_MS anyway when stale: a tool stuck in a dead
|
|
13
15
|
* folder cannot say its turn ended (its pulse is in /work). Never a loop: not again within AGAIN_MS.
|
|
@@ -17,27 +19,29 @@ export const WAIT_MS = 5 * 60_000;
|
|
|
17
19
|
export const AGAIN_MS = 30 * 60_000;
|
|
18
20
|
|
|
19
21
|
export class Revive {
|
|
20
|
-
#restart; #busy; #tell; #taken; #now; #wanted = new Map(); #lastAt = new Map(); #going = new Set();
|
|
22
|
+
#restart; #restartMachine; #busy; #tell; #taken; #now; #wanted = new Map(); #lastAt = new Map(); #going = new Set();
|
|
21
23
|
|
|
22
24
|
/* `restart(name)`: its tool restarted, resolves with whether it was. `busy(name)`: its turn goes on.
|
|
23
25
|
`tell(name, why, step)`: said where it should be, step 'before' (its docket), then 'done' or 'failed' (main.mjs).
|
|
24
26
|
`taken(name)`: the request outside /work removed (in its machine). */
|
|
25
|
-
constructor({ restart, busy = () => false, tell = () => {}, taken = async () => {}, now = Date.now }) {
|
|
26
|
-
this.#restart = restart; this.#busy = busy; this.#tell = tell; this.#taken = taken; this.#now = now;
|
|
27
|
+
constructor({ restart, restartMachine = async () => false, busy = () => false, tell = () => {}, taken = async () => {}, now = Date.now }) {
|
|
28
|
+
this.#restart = restart; this.#restartMachine = restartMachine; this.#busy = busy; this.#tell = tell; this.#taken = taken; this.#now = now;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
/* What one look found. A look that finds it well forgets a stale one not yet acted on. */
|
|
30
32
|
judged(name, record) {
|
|
31
33
|
if (!record || record.state !== 'Running' || record.answering !== true) return;
|
|
32
34
|
if (record.restartAsked) { void Promise.resolve().then(() => this.#taken(name)).catch(() => {}); this.#want(name, 'asked'); }
|
|
33
|
-
if (record.
|
|
34
|
-
else if (this.#
|
|
35
|
+
if (record.stuckWork) this.#want(name, 'stuck');
|
|
36
|
+
else if (record.stale) this.#want(name, 'stale');
|
|
37
|
+
else if (['stale', 'stuck'].includes(this.#wanted.get(name)?.why)) this.#wanted.delete(name);
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
#want(name, why) {
|
|
38
41
|
const had = this.#wanted.get(name);
|
|
39
|
-
/*
|
|
40
|
-
|
|
42
|
+
/* stuck over stale over a plain request: the stronger is acted on, even while it looks busy. */
|
|
43
|
+
const rank = { asked: 0, stale: 1, stuck: 2 };
|
|
44
|
+
if (!had || rank[why] > rank[had.why]) this.#wanted.set(name, { why, since: had?.since ?? this.#now() });
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
wanted(name) { return this.#wanted.get(name)?.why ?? null; }
|
|
@@ -49,14 +53,14 @@ export class Revive {
|
|
|
49
53
|
for (const [name, { why, since }] of [...this.#wanted]) {
|
|
50
54
|
if (this.#going.has(name)) continue;
|
|
51
55
|
const busy = (() => { try { return this.#busy(name); } catch { return false; } })();
|
|
52
|
-
if (busy && !(why
|
|
56
|
+
if (busy && !(why !== 'asked' && this.#now() - since >= WAIT_MS)) continue;
|
|
53
57
|
this.#wanted.delete(name);
|
|
54
58
|
if (this.#now() - (this.#lastAt.get(name) ?? -Infinity) < AGAIN_MS) continue;
|
|
55
59
|
this.#lastAt.set(name, this.#now());
|
|
56
60
|
this.#going.add(name);
|
|
57
61
|
try {
|
|
58
62
|
try { this.#tell(name, why, 'before'); } catch { /* told, nothing more */ }
|
|
59
|
-
const ok = await this.#restart(name).catch(() => false);
|
|
63
|
+
const ok = await (why === 'stuck' ? this.#restartMachine(name) : this.#restart(name)).catch(() => false);
|
|
60
64
|
if (ok) done.push(name);
|
|
61
65
|
try { this.#tell(name, why, ok ? 'done' : 'failed'); } catch { /* told, nothing more */ }
|
|
62
66
|
} finally { this.#going.delete(name); }
|
package/web/app.js
CHANGED
|
@@ -8187,7 +8187,8 @@
|
|
|
8187
8187
|
apply.dataset.retry = String(failedHere);
|
|
8188
8188
|
apply.className = failedHere ? '' : 'primary';
|
|
8189
8189
|
apply.textContent = failedHere ? `Try ${u.available} again\u2026` : `Update to ${u.available ?? ''}`;
|
|
8190
|
-
|
|
8190
|
+
const onlyFetch = failedHere && u.history.filter((h) => h.action === 'update' && h.to === u.available && h.result !== 'done').every((h) => h.fetch === true);
|
|
8191
|
+
$('updates-retry-note').textContent = !failedHere ? '' : onlyFetch ? 'It could not be downloaded before; it is tried again by itself.' : `It did not start here before. If it fails again, ${u.version} is put back.`;
|
|
8191
8192
|
$('updates-retry-note').hidden = !failedHere;
|
|
8192
8193
|
$('updates-retry-yes').hidden = true; $('updates-retry-no').hidden = true; apply.hidden = false;
|
|
8193
8194
|
/* The last thing that went wrong, said once at the top, in words: a version put
|