clavarium 0.2.523-next.1 → 0.2.525-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/multipass-refresh.mjs +25 -18
- package/deploy/updater.mjs +2 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/api.mjs +2 -0
- package/server/door.mjs +1 -1
- package/server/main.mjs +2 -2
- package/server/signinhelp.mjs +9 -0
- package/server/vmwatch.mjs +5 -3
|
@@ -15,6 +15,8 @@ const MACHINE_MS = 180_000;
|
|
|
15
15
|
const BACK_TRIES = 36;
|
|
16
16
|
const BACK_EVERY_MS = 5_000;
|
|
17
17
|
export const TRY_EVERY_MS = 20 * 3600_000;
|
|
18
|
+
/* In the data folder while it runs: the server's watch leaves Multipass alone (vmwatch.mjs, `paused`). */
|
|
19
|
+
export const MULTIPASS_UPDATING = 'multipass-updating';
|
|
18
20
|
|
|
19
21
|
const first = (r) => String(r?.stderr || r?.stdout || '').trim().split('\n').filter(Boolean).pop()?.slice(0, 200) || `exit ${r?.code}`;
|
|
20
22
|
|
|
@@ -38,7 +40,7 @@ export function runningMachines(text) {
|
|
|
38
40
|
return list.filter((m) => m?.state === 'Running' && /^clv-[a-z0-9-]+$/.test(m?.name ?? '')).map((m) => m.name);
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
export async function multipassTurn({ run, mode, inWindow, busy, state, save, log = () => {}, now = () => Date.now(), sleep = (ms) => new Promise((r) => { setTimeout(r, ms); }), multipass = '/snap/bin/multipass' }) {
|
|
43
|
+
export async function multipassTurn({ run, mode, inWindow, busy, state, save, log = () => {}, now = () => Date.now(), sleep = (ms) => new Promise((r) => { setTimeout(r, ms); }), multipass = '/snap/bin/multipass', mark = () => {} }) {
|
|
42
44
|
const sh = (argv, timeoutMs = SNAP_MS) => Promise.resolve(run(argv, { timeoutMs })).catch((e) => ({ code: 1, stderr: e.message }));
|
|
43
45
|
const list = await sh(['snap', 'list', 'multipass']);
|
|
44
46
|
if (list.code !== 0) return 'no multipass here';
|
|
@@ -83,22 +85,27 @@ export async function multipassTurn({ run, mode, inWindow, busy, state, save, lo
|
|
|
83
85
|
const running = seen.code === 0 ? runningMachines(seen.stdout) : null;
|
|
84
86
|
if (!running) { log(`multipass: its machines could not be read: not updated (${first(seen)})`); return 'not updated'; }
|
|
85
87
|
|
|
86
|
-
/*
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
/* Told to the server first (23-11, on a real server: machines going to sleep keep Multipass busy for minutes, the
|
|
89
|
+
server's watch took it for hung and restarted it in the middle). */
|
|
90
|
+
mark(true);
|
|
91
|
+
try {
|
|
92
|
+
/* Written down BEFORE anything stops: a turn cut here still brings them back. */
|
|
93
|
+
save({ multipassRefresh: { triedAt: new Date(now()).toISOString(), machines: running } });
|
|
94
|
+
log(`multipass: a new version: ${running.length} machine(s) put to sleep for its update`);
|
|
95
|
+
for (const name of running) {
|
|
96
|
+
const r = await sh([multipass, 'suspend', name], MACHINE_MS);
|
|
97
|
+
if (r.code !== 0) {
|
|
98
|
+
log(`multipass: ${name} could not be put to sleep (${first(r)}): not updated, its machines started again`);
|
|
99
|
+
save({ multipassRefresh: { ...state().multipassRefresh, machines: await back(running) } });
|
|
100
|
+
return 'not updated';
|
|
101
|
+
}
|
|
95
102
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
/* --ignore-running: a client of Multipass still open (a terminal, a command) would make snap refuse (seen on a real machine); its machine is asleep. */
|
|
104
|
+
const done = await sh(['snap', 'refresh', 'multipass', '--ignore-running'], REFRESH_MS);
|
|
105
|
+
log(done.code === 0 ? 'multipass: updated' : `multipass: its update failed: ${first(done)}`);
|
|
106
|
+
const left = await back(running);
|
|
107
|
+
save({ multipassRefresh: { ...state().multipassRefresh, machines: left } });
|
|
108
|
+
log(left.length ? `multipass: ${left.length} machine(s) to start again at the next turn` : 'multipass: its machines are running again');
|
|
109
|
+
return done.code === 0 ? 'updated' : 'update failed';
|
|
110
|
+
} finally { mark(false); }
|
|
104
111
|
}
|
package/deploy/updater.mjs
CHANGED
|
@@ -56,7 +56,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
56
56
|
import { fetchToolArchives, REGISTRY } from './parley-archive.mjs';
|
|
57
57
|
import { ensureTunnel, tunnelUnit, relayOfUnit, TUNNEL_UNIT, TUNNEL_PROGRAM } from './tunnel.mjs';
|
|
58
58
|
import { ensureGenericClientId } from './oidc.mjs';
|
|
59
|
-
import { multipassTurn } from './multipass-refresh.mjs';
|
|
59
|
+
import { multipassTurn, MULTIPASS_UPDATING } from './multipass-refresh.mjs';
|
|
60
60
|
/* The updater's run keeps the tunnel up to date: the same functions, from here too. */
|
|
61
61
|
export { ensureTunnel, tunnelUnit, relayOfUnit, TUNNEL_UNIT, TUNNEL_PROGRAM };
|
|
62
62
|
|
|
@@ -1128,7 +1128,7 @@ async function main(argv) {
|
|
|
1128
1128
|
const file = join(PATHS.stateDir, 'multipass-refresh.json');
|
|
1129
1129
|
const state = () => { try { return JSON.parse(readFileSync(file, 'utf8')); } catch { return {}; } };
|
|
1130
1130
|
const save = (change) => { writeFileSync(`${file}.new`, `${JSON.stringify({ ...state(), ...change })}\n`); renameSync(`${file}.new`, file); };
|
|
1131
|
-
await multipassTurn({ run: runCommand, mode: conf.MODE, inWindow: inWindow(conf.WINDOW, new Date()), busy: () => u.busy(), state, save, log: (line) => console.error(`updater: ${line}`) });
|
|
1131
|
+
await multipassTurn({ run: runCommand, mode: conf.MODE, inWindow: inWindow(conf.WINDOW, new Date()), busy: () => u.busy(), state, save, log: (line) => console.error(`updater: ${line}`), mark: (on) => { const f = join(PATHS.data, MULTIPASS_UPDATING); if (on) writeFileSync(f, `${new Date().toISOString()}\n`, { mode: 0o644 }); else rmSync(f, { force: true }); } });
|
|
1132
1132
|
} catch (error) { console.error(`updater: Multipass could not be looked at: ${error.message}`); }
|
|
1133
1133
|
const r = await u.runOnce(); console.log(typeof r === 'string' ? r : 'done'); return; }
|
|
1134
1134
|
case 'set': if (rest.length !== 2) throw new Refused('set <mode|channel|window|port> <value>'); return print(u.set(rest[0], rest[1]));
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.525-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.525-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/api.mjs
CHANGED
|
@@ -890,6 +890,8 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
890
890
|
if (talking[2] === '/pin') return send(200, await talk.pin(conversation, body.to, body.on !== false)), true;
|
|
891
891
|
if (talking[2] === '/split') return send(200, talk.setSplit(conversation, { messages: body.messages, days: body.days, off: body.off })), true;
|
|
892
892
|
if (typeof body.on === 'boolean') { const now = await talk.set(conversation, body.on); retell(conversation); return send(200, now), true; }
|
|
893
|
+
/* A sign-in code pasted in the chat while its sign-in waits: typed into its tool, never in the thread (#405). */
|
|
894
|
+
if (conversations.signinHelp?.codeInChat(conversation, body.text, body.files)) return send(201, { ...(await conversations.signinHelp.enterCode(conversation, body.text)), told: 'signin' }), true;
|
|
893
895
|
/* What the chat may add to an answer: the choices ticked, the answers of a group, the zone of a picture it is about (Parley checks each). */
|
|
894
896
|
return send(201, await talk.say(conversation, body.text, body.answers, body.files, body.via, { picked: body.picked, replies: body.replies, about: body.about, quick: body.quick === true })), true;
|
|
895
897
|
}
|
package/server/door.mjs
CHANGED
|
@@ -189,7 +189,7 @@ export async function handleDoor(request, response, { devices, conversations, re
|
|
|
189
189
|
if (request.headers['content-type'] !== 'application/octet-stream') return send(400, { error: 'An attachment is a file.' });
|
|
190
190
|
return send(201, await talk.attach(name, url.searchParams.get('name') ?? '', request));
|
|
191
191
|
}
|
|
192
|
-
if (request.method === 'POST' && talking[1] === undefined) { const body = await readJson(request); return send(201, await talk.say(name, body.text, body.answers, body.files, body.via, { quick: body.quick === true })); }
|
|
192
|
+
if (request.method === 'POST' && talking[1] === undefined) { const body = await readJson(request); if (part.terminal && signinCode && conversations.signinHelp?.codeInChat(name, body.text, body.files)) return send(201, { ...(await signinCode(name, body.text)), told: 'signin' }); return send(201, await talk.say(name, body.text, body.answers, body.files, body.via, { quick: body.quick === true })); }
|
|
193
193
|
}
|
|
194
194
|
/* A sign-in code (#405): a device given its terminal could type it there; no other. Named twice, never guessed. */
|
|
195
195
|
const codeFor = /^\/conversations\/([^/]+)\/signin-code$/.exec(route);
|
package/server/main.mjs
CHANGED
|
@@ -14,7 +14,7 @@ import { Catalogue } from './catalog.mjs';
|
|
|
14
14
|
* node server/main.mjs --command "your-tool" --cwd /path/to/work
|
|
15
15
|
* no VM: one tool on this machine, at /?c=<name>. For development.
|
|
16
16
|
*/
|
|
17
|
-
import { readFileSync, readdirSync } from 'node:fs';
|
|
17
|
+
import { readFileSync, readdirSync, statSync } from 'node:fs';
|
|
18
18
|
import { createHash } from 'node:crypto';
|
|
19
19
|
import { createServer } from 'node:http';
|
|
20
20
|
import { readFile } from 'node:fs/promises';
|
|
@@ -767,7 +767,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
767
767
|
may say otherwise: set by hand, or by an earlier version). Not waited for. */
|
|
768
768
|
void all.reconcileAll?.().catch(() => {});
|
|
769
769
|
/* The VM manager, watched: said to the pages when it does not answer, restarted once when stuck (vmwatch.mjs). */
|
|
770
|
-
const vmWatch = new VmWatch({ run: asHost, store: new Store(`${dataDir}/vm-manager.json`), alert: (payload) => { events.add({ kind: 'server', text: `${payload.title}: ${payload.body ?? ''}`.trim() }); void alerts.tell(payload)?.catch?.(() => {}); } });
|
|
770
|
+
const vmWatch = new VmWatch({ paused: () => { try { return Date.now() - statSync(`${dataDir}/multipass-updating`).mtimeMs < 45 * 60_000; } catch { return false; } }, run: asHost, store: new Store(`${dataDir}/vm-manager.json`), alert: (payload) => { events.add({ kind: 'server', text: `${payload.title}: ${payload.body ?? ''}`.trim() }); void alerts.tell(payload)?.catch?.(() => {}); } });
|
|
771
771
|
const stopVmWatch = vmWatch.start(vmWatchEveryMs);
|
|
772
772
|
const platform = { get machines() { return vmWatch.ok; }, answerer: answerer.about(), get operators() { return team ? team.allowed() : [...operators]; }, address: publicOrigin ?? null, version: JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version, get dictation() { return voice.current() ? (voice.model ?? 'set') : null; } };
|
|
773
773
|
/* Who gets what, and a whole setup in one file: see setup.mjs. */
|
package/server/signinhelp.mjs
CHANGED
|
@@ -185,6 +185,15 @@ export class SigninHelp {
|
|
|
185
185
|
const ask = this.#personsAsk(name);
|
|
186
186
|
return ask !== null && ask.field !== true;
|
|
187
187
|
}
|
|
188
|
+
/* PASTED IN THE CHAT ITSELF (23-11, its owner: « I just want to paste the code », no terminal, no other field): while
|
|
189
|
+
its sign-in waits, a message that is nothing but a code is that code. It goes to enterCode, never into the thread. */
|
|
190
|
+
codeInChat(name, text, files) {
|
|
191
|
+
if (Array.isArray(files) && files.length) return false;
|
|
192
|
+
const code = String(text ?? '').trim();
|
|
193
|
+
/* One long word is not a code: « Probablement » stays a message. Its two halves (#), or long with letters and digits. */
|
|
194
|
+
const shaped = code.includes('#') ? code.length >= 20 : code.length >= 32 && /[0-9]/.test(code) && /[A-Za-z]/.test(code);
|
|
195
|
+
return shaped && CODE.test(code) && this.#personsAsk(name) !== null;
|
|
196
|
+
}
|
|
188
197
|
/* THE CODE PASTED IN ITS FIELD (#405). Typed once, only while its tool shows its prompt; the value is in no answer,
|
|
189
198
|
no error, no log, no file. */
|
|
190
199
|
async enterCode(name, value) {
|
package/server/vmwatch.mjs
CHANGED
|
@@ -40,11 +40,11 @@ export function statesOf(csv) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export class VmWatch {
|
|
43
|
-
#run; #store; #now; #hour; #log; #alert; #stuckMs; #reviveEveryMs; #downSince = null; #reviving = null; #running = new Set(); #wait;
|
|
43
|
+
#run; #store; #now; #hour; #log; #alert; #stuckMs; #reviveEveryMs; #downSince = null; #reviving = null; #running = new Set(); #wait; #paused;
|
|
44
44
|
ok = true;
|
|
45
45
|
/* `hour()`: this server's local hour, 0-23 (injected for tests). */
|
|
46
|
-
constructor({ run, store, now = () => Date.now(), hour = () => new Date().getHours(), log = (line) => console.error(line), alert = () => {}, stuckMs = STUCK_MS, reviveEveryMs = REVIVE_EVERY_MS, wait = (ms) => new Promise((r) => { setTimeout(r, ms).unref?.(); }) }) {
|
|
47
|
-
this.#wait = wait;
|
|
46
|
+
constructor({ run, store, now = () => Date.now(), hour = () => new Date().getHours(), log = (line) => console.error(line), alert = () => {}, stuckMs = STUCK_MS, reviveEveryMs = REVIVE_EVERY_MS, wait = (ms) => new Promise((r) => { setTimeout(r, ms).unref?.(); }), paused = () => false }) {
|
|
47
|
+
this.#wait = wait; this.#paused = paused;
|
|
48
48
|
this.#run = run; this.#store = store; this.#now = now; this.#hour = hour; this.#log = log; this.#alert = alert; this.#stuckMs = stuckMs; this.#reviveEveryMs = reviveEveryMs;
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -70,6 +70,8 @@ export class VmWatch {
|
|
|
70
70
|
|
|
71
71
|
/* One look: 'ok', 'down', 'down; restarted already', 'asked', 'down; asked already', 'revived' or 'revive failed'. */
|
|
72
72
|
async look() {
|
|
73
|
+
/* Its update runs, in the update window (deploy/multipass-refresh.mjs): busy on purpose, it brings its machines back itself. */
|
|
74
|
+
if (this.#paused()) { this.#downSince = null; return 'paused'; }
|
|
73
75
|
const r = await this.#run(['vm', 'ping'], { timeoutMs: PING_MS }).catch((e) => ({ code: 1, stderr: e.message }));
|
|
74
76
|
if (r.code === 0) {
|
|
75
77
|
const was = !this.ok;
|