clavarium 0.2.448-next.1 → 0.2.450-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/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/api.mjs +3 -1
- package/server/carry.mjs +2 -0
- package/server/conversations.mjs +140 -25
- package/server/jobs.mjs +6 -2
- package/server/settingswords.mjs +1 -1
- package/web/app.js +11 -4
- package/web/index.html +2 -2
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.450-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.450-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
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
* POST /api/binder/suggest {id}: at most three quick actions for that card -> {actions: [{key, label, why, on, ask?}]}
|
|
26
26
|
* POST /api/mailboxes/<name>/live {smtp, email?}: that mailbox connected live too (send, move...), its password reused
|
|
27
27
|
* POST /api/conversations/<name>/erase {confirm: <its name>}: deleted for good -- its machine and its work files
|
|
28
|
-
* POST /api/conversations/<name>/into-machine {machine, machineMb?}: moved into a shared machine (#221), its tool's state along (202)
|
|
28
|
+
* POST /api/conversations/<name>/into-machine {machine, machineMb?}: moved into a shared machine (#221), its tool's state along (202);
|
|
29
|
+
* {} (no machine): out of its shared machine, into one of its own (15-11)
|
|
29
30
|
* POST /api/conversations/<name>/copy {title?, machine?, machineMb?}: a copy -- its work, its tool's state, its accesses; it untouched (202)
|
|
30
31
|
* POST /api/conversations/<name>/rebuild {reset?, confirm?}: built again; reset (confirm: its name) for a working one too
|
|
31
32
|
* POST /api/conversations/<name>/ask-first {on}: its tool asks before acting (true), or acts without asking in its machine (false, the default), from its next start
|
|
@@ -1031,6 +1032,7 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
1031
1032
|
/* Moved into a shared machine (#221): one there already, or a new one of the size given. */
|
|
1032
1033
|
const moving = /^\/api\/conversations\/([^/]+)\/into-machine$/.exec(pathname);
|
|
1033
1034
|
if (moving) {
|
|
1035
|
+
if (body?.machine === undefined) return send(202, await conversations.moveToOwn(decodeURIComponent(moving[1]))), true;
|
|
1034
1036
|
const machineMb = body?.machineMb === undefined ? undefined : Number(body.machineMb);
|
|
1035
1037
|
return send(202, await conversations.moveToShared(decodeURIComponent(moving[1]), { machine: body?.machine, machineMb })), true;
|
|
1036
1038
|
}
|
package/server/carry.mjs
CHANGED
|
@@ -42,6 +42,8 @@ export function wholeStream(homeTar, workDir, done = () => {}) {
|
|
|
42
42
|
const home = createReadStream(homeTar, { start: 0, end: size - END - 1 });
|
|
43
43
|
home.on('error', end);
|
|
44
44
|
home.on('end', () => {
|
|
45
|
+
/* Its home read whole: its part taken away now, before the file ends (15-11, a test saw it still there). */
|
|
46
|
+
done();
|
|
45
47
|
/* Its work: every file, its carried parts left out; named work/... (a link's target left as it is). */
|
|
46
48
|
child = spawn('tar', ['-cf', '-', '-b', '1', '-C', workDir, `--exclude=./${CARRY}`, '--transform', 's,^\\.,work,S', '.'], { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
47
49
|
child.stdout.pipe(gzip);
|
package/server/conversations.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import { TOOLS_PATH, LAUNCH } from './toolbox.mjs';
|
|
|
15
15
|
import { homeExcludes, wholeStream, readManifest, workEmpty, unpackHere, restoreWork, CARRY } from './carry.mjs';
|
|
16
16
|
import { availableParallelism } from 'node:os';
|
|
17
17
|
import { spawn } from 'node:child_process';
|
|
18
|
-
import { readFileSync, createReadStream, createWriteStream, mkdtempSync, rmSync, statSync, copyFileSync, mkdirSync } from 'node:fs';
|
|
18
|
+
import { readFileSync, createReadStream, createWriteStream, mkdtempSync, rmSync, statSync, copyFileSync, mkdirSync, existsSync } from 'node:fs';
|
|
19
19
|
import { tmpdir } from 'node:os';
|
|
20
20
|
import { join, dirname } from 'node:path';
|
|
21
21
|
|
|
@@ -176,6 +176,7 @@ export class Conversations {
|
|
|
176
176
|
/* A move into a shared machine cut short (14-11): back in its own machine, as it was -- never « build it
|
|
177
177
|
again », which would make its own machine anew and lose its tool's memory. */
|
|
178
178
|
if (c.phase === 'building' && c.movingTo) store.patch(c.name, { phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, sharedMachine: undefined, machineMb: undefined, machineUser: undefined, ...(c.movingFromMb ? { memoryMb: c.movingFromMb } : {}), movingTo: undefined, movingFromMb: undefined, stopped: true, moved: `The server restarted while it was moving to the shared machine ${c.movingTo}: it stays in its own machine, as it was. Move it again when you like.` });
|
|
179
|
+
else if (c.phase === 'building' && c.movingOutOf) store.patch(c.name, { phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, ...c.movingOutOf, movingOutOf: undefined, stopped: true, moved: `The server restarted while it was moving out of the shared machine ${c.movingOutOf.sharedMachine}: it stays there. Move it again when you like.` });
|
|
179
180
|
else if (c.phase === 'building') store.patch(c.name, { phase: 'failed', error: 'The server restarted while this conversation was being built. Build it again, or archive it.' });
|
|
180
181
|
if (c.phase === 'restarting') store.patch(c.name, { phase: 'ready', step: undefined, restartingSince: undefined, restarted: 'The server restarted while this machine was being restarted: look at its state, and restart it again if needed.' });
|
|
181
182
|
/* An action cut short: said as such, never left running on the page. */
|
|
@@ -1173,6 +1174,7 @@ export class Conversations {
|
|
|
1173
1174
|
const carryId = workDir ? `copy-${to}-${Date.now()}` : '';
|
|
1174
1175
|
const inWork = carryId ? join(workDir, '.clavarium-carry', `${carryId}.tgz`) : '';
|
|
1175
1176
|
if (inWork) await Promise.race([Promise.resolve().then(() => this.mounted(from, true)).catch(() => {}), new Promise((r) => { setTimeout(r, MOUNTED_MS).unref?.(); })]);
|
|
1177
|
+
if (inWork && !(await this.#workShown(from, workDir))) throw new Error('its original\'s work folder is not shown in its machine: open the original once, then copy it again');
|
|
1176
1178
|
const out = await this.exportState(from, inWork ? { toWork: carryId } : {});
|
|
1177
1179
|
child = out.child;
|
|
1178
1180
|
let read = 0; let lastAt = Date.now(); let stalled = false;
|
|
@@ -1283,18 +1285,62 @@ export class Conversations {
|
|
|
1283
1285
|
this.#cancelStop(name);
|
|
1284
1286
|
const now = new Date().toISOString();
|
|
1285
1287
|
/* `movingTo`: what a restart of this server finds, to put it back in its own machine, as it was (14-11). */
|
|
1286
|
-
this.#store.patch(name, { phase: 'building', step: `Moving to the shared machine ${machine}`, buildingSince: now, progress: buildProgress(now), movingTo: machine, movingFromMb: c.memoryMb });
|
|
1288
|
+
this.#store.patch(name, { phase: 'building', step: `Moving to the shared machine ${machine}`, buildingSince: now, progress: buildProgress(now), movingTo: machine, movingFromMb: c.memoryMb, moveFailed: undefined });
|
|
1287
1289
|
this.built = this.#moving(name, c, tool, machine, size, memory, state).finally(() => this.#give(name, act));
|
|
1288
1290
|
return this.#store.get(name);
|
|
1289
1291
|
}
|
|
1290
1292
|
|
|
1293
|
+
/* ITS WORK FOLDER SEEN FROM ITS MACHINE (15-11): a file made there is found here -- else what is written for the
|
|
1294
|
+
server to read stays inside the machine (a work folder unmounted by a move cut short). Shown again once if not. */
|
|
1295
|
+
async #workShown(name, workDir) {
|
|
1296
|
+
const seen = async () => {
|
|
1297
|
+
const id = `probe-${Date.now()}`;
|
|
1298
|
+
await this.#vms.exec(name, ['sh', '-c', `mkdir -p /work/.clavarium-carry && : > /work/.clavarium-carry/${id}`], { timeoutMs: 30_000 }).catch(() => {});
|
|
1299
|
+
const there = existsSync(join(workDir, '.clavarium-carry', id));
|
|
1300
|
+
rmSync(join(workDir, '.clavarium-carry', id), { force: true });
|
|
1301
|
+
return there;
|
|
1302
|
+
};
|
|
1303
|
+
if (await seen()) return true;
|
|
1304
|
+
await this.#vms.workMount(name, this.#uid, this.#gid).catch(() => {});
|
|
1305
|
+
return seen();
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
/* ITS TOOL'S STATE, TAKEN ALONG for a move (12-11, 15-11): through its work folder, as a copy reads it (14-11),
|
|
1309
|
+
written to `carried`. -> undefined, or why it could not be. */
|
|
1310
|
+
async #takeState(name, c, tool, carried) {
|
|
1311
|
+
this.#store.patch(name, { step: `Taking ${tool.label}'s state along` });
|
|
1312
|
+
/* Through its work folder, as a copy reads it (14-11): the VM manager's output stalls past ~36 KB on
|
|
1313
|
+
the owner's server -- a move then waited for ever. Its size read as it grows, said; quiet too long: ended. */
|
|
1314
|
+
const workDir = c.work === 'kept' && typeof this.workFolder === 'function' ? this.workFolder(name) : '';
|
|
1315
|
+
const carryId = workDir ? `move-${name}-${Date.now()}` : '';
|
|
1316
|
+
const inWork = carryId ? join(workDir, '.clavarium-carry', `${carryId}.tgz`) : '';
|
|
1317
|
+
if (inWork) await Promise.race([Promise.resolve().then(() => this.mounted(name, true)).catch(() => {}), new Promise((r) => { setTimeout(r, MOUNTED_MS).unref?.(); })]);
|
|
1318
|
+
if (inWork && !(await this.#workShown(name, workDir))) return 'its work folder is not shown in its machine: open the conversation once, then move it again.';
|
|
1319
|
+
const { stream, child } = await this.exportState(name, inWork ? { toWork: carryId } : {});
|
|
1320
|
+
let read = 0; let lastAt = Date.now(); let stalled = false;
|
|
1321
|
+
const grew = (n) => { if (n <= read) return; read = n; lastAt = Date.now(); this.#store.patch(name, { step: `Taking ${tool.label}'s state along: ${sizeWords(read)}` }); };
|
|
1322
|
+
const sizing = setInterval(() => {
|
|
1323
|
+
if (inWork) { try { grew(statSync(inWork).size); } catch { /* not there yet */ } }
|
|
1324
|
+
if (Date.now() - lastAt >= COPY_QUIET_MS) { stalled = true; child.kill('SIGKILL'); }
|
|
1325
|
+
}, 1000);
|
|
1326
|
+
const failed = new Promise((ok) => child.on('error', () => ok(-1)));
|
|
1327
|
+
const file = inWork ? null : createWriteStream(carried, { mode: 0o600 });
|
|
1328
|
+
if (file) { stream.on('data', (d) => grew(read + d.length)); stream.pipe(file); } else stream.resume();
|
|
1329
|
+
const code = await Promise.race([new Promise((ok) => child.on('close', ok)), failed]).finally(() => clearInterval(sizing));
|
|
1330
|
+
if (file) await new Promise((ok) => (file.writableFinished ? ok() : file.on('finish', ok)));
|
|
1331
|
+
if (inWork) { try { if (code === 0 && !stalled) copyFileSync(inWork, carried); } finally { rmSync(inWork, { force: true }); } }
|
|
1332
|
+
if (stalled) return `its tool's state stopped coming (${sizeWords(read)} read, then nothing for ${COPY_QUIET_MS / 60_000} min).`;
|
|
1333
|
+
if (code !== 0) return `its tool's state could not be taken (exit ${code}${firstLine(child.said) ? `: ${firstLine(child.said)}` : ''}).`;
|
|
1334
|
+
return undefined;
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1291
1337
|
async #moving(name, c, tool, machine, size, memory, state) {
|
|
1292
1338
|
const old = vmName(name);
|
|
1293
1339
|
const dir = mkdtempSync(join(tmpdir(), 'clv-move-'));
|
|
1294
1340
|
const carried = join(dir, 'state.tar.gz');
|
|
1295
1341
|
const back = (why) => {
|
|
1296
1342
|
/* Back to its own machine, as it was (stopped: the next opening wakes it). */
|
|
1297
|
-
this.#store.patch(name, { sharedMachine: undefined, machineMb: undefined, machineUser: undefined, memoryMb: c.memoryMb, phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, error: undefined, movingTo: undefined, movingFromMb: undefined });
|
|
1343
|
+
this.#store.patch(name, { sharedMachine: undefined, machineMb: undefined, machineUser: undefined, memoryMb: c.memoryMb, phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, error: undefined, movingTo: undefined, movingFromMb: undefined, moveFailed: `Not moved: ${why}` });
|
|
1298
1344
|
this.#fresh.add(name); this.#mountAgain.add(name);
|
|
1299
1345
|
try { this.renewed(name, `Not moved to the shared machine ${machine}: ${why} It stays in its own machine, as it was.`, false); } catch { /* told, nothing more */ }
|
|
1300
1346
|
};
|
|
@@ -1302,28 +1348,8 @@ export class Conversations {
|
|
|
1302
1348
|
this.drop(name);
|
|
1303
1349
|
if (state === 'Running') await this.#vms.exec(name, ['tmux', '-L', SOCKET, 'kill-server'], { timeoutMs: 10_000 }).catch(() => {});
|
|
1304
1350
|
if (tool.state) {
|
|
1305
|
-
this.#
|
|
1306
|
-
|
|
1307
|
-
the owner's server -- a move then waited for ever. Its size read as it grows, said; quiet too long: ended. */
|
|
1308
|
-
const workDir = c.work === 'kept' && typeof this.workFolder === 'function' ? this.workFolder(name) : '';
|
|
1309
|
-
const carryId = workDir ? `move-${name}-${Date.now()}` : '';
|
|
1310
|
-
const inWork = carryId ? join(workDir, '.clavarium-carry', `${carryId}.tgz`) : '';
|
|
1311
|
-
if (inWork) await Promise.race([Promise.resolve().then(() => this.mounted(name, true)).catch(() => {}), new Promise((r) => { setTimeout(r, MOUNTED_MS).unref?.(); })]);
|
|
1312
|
-
const { stream, child } = await this.exportState(name, inWork ? { toWork: carryId } : {});
|
|
1313
|
-
let read = 0; let lastAt = Date.now(); let stalled = false;
|
|
1314
|
-
const grew = (n) => { if (n <= read) return; read = n; lastAt = Date.now(); this.#store.patch(name, { step: `Taking ${tool.label}'s state along: ${sizeWords(read)}` }); };
|
|
1315
|
-
const sizing = setInterval(() => {
|
|
1316
|
-
if (inWork) { try { grew(statSync(inWork).size); } catch { /* not there yet */ } }
|
|
1317
|
-
if (Date.now() - lastAt >= COPY_QUIET_MS) { stalled = true; child.kill('SIGKILL'); }
|
|
1318
|
-
}, 1000);
|
|
1319
|
-
const failed = new Promise((ok) => child.on('error', () => ok(-1)));
|
|
1320
|
-
const file = inWork ? null : createWriteStream(carried, { mode: 0o600 });
|
|
1321
|
-
if (file) { stream.on('data', (d) => grew(read + d.length)); stream.pipe(file); } else stream.resume();
|
|
1322
|
-
const code = await Promise.race([new Promise((ok) => child.on('close', ok)), failed]).finally(() => clearInterval(sizing));
|
|
1323
|
-
if (file) await new Promise((ok) => (file.writableFinished ? ok() : file.on('finish', ok)));
|
|
1324
|
-
if (inWork) { try { if (code === 0 && !stalled) copyFileSync(inWork, carried); } finally { rmSync(inWork, { force: true }); } }
|
|
1325
|
-
if (stalled) return back(`its tool's state stopped coming (${sizeWords(read)} read, then nothing for ${COPY_QUIET_MS / 60_000} min).`);
|
|
1326
|
-
if (code !== 0) return back(`its tool's state could not be taken (exit ${code}${firstLine(child.said) ? `: ${firstLine(child.said)}` : ''}).`);
|
|
1351
|
+
const why = await this.#takeState(name, c, tool, carried);
|
|
1352
|
+
if (why) return back(why);
|
|
1327
1353
|
}
|
|
1328
1354
|
if (state !== undefined) {
|
|
1329
1355
|
this.#store.patch(name, { step: 'Stopping its own machine' });
|
|
@@ -1361,6 +1387,95 @@ export class Conversations {
|
|
|
1361
1387
|
} finally { rmSync(dir, { recursive: true, force: true }); }
|
|
1362
1388
|
}
|
|
1363
1389
|
|
|
1390
|
+
/* OUT OF ITS SHARED MACHINE, INTO ONE OF ITS OWN (#221, 15-11): the move the other way. Its tool's state carried
|
|
1391
|
+
(as into a shared machine), its programs there ended and its work taken out of its place, its own machine built
|
|
1392
|
+
as a new one's, the state put back, then its place in the shared machine removed -- its user and home there, or
|
|
1393
|
+
the whole machine when it was the last in it. Anything wrong before its own machine is ready: back in the shared
|
|
1394
|
+
machine, as it was (its place there kept until the end). -> the record, at once; `this.built`: the end of it. */
|
|
1395
|
+
async moveToOwn(name) {
|
|
1396
|
+
const c = this.#busyCheck(name);
|
|
1397
|
+
if (!c.sharedMachine) throw new Refusal(409, 'It has a machine of its own already.');
|
|
1398
|
+
const tool = this.#tools.find((t) => t.id === c.tool);
|
|
1399
|
+
if (!tool) throw new Refusal(400, 'The tool of this conversation is no longer offered.');
|
|
1400
|
+
const state = await this.#vms.state(name, { fresh: true }).catch(() => undefined);
|
|
1401
|
+
if (tool.state && state !== 'Running') throw new Refusal(409, 'Its shared machine is not running: open the conversation first, so that its tool\'s state can come along.', { retry: false });
|
|
1402
|
+
const memory = Math.max(tool.memoryMb, Number(c.memoryMb) || tool.memoryMb);
|
|
1403
|
+
await this.room({ kind: 'create', memoryMb: memory });
|
|
1404
|
+
const act = this.#take(name, 'move');
|
|
1405
|
+
this.#cancelStop(name);
|
|
1406
|
+
const now = new Date().toISOString();
|
|
1407
|
+
/* `movingOutOf`: what a restart of this server finds, to put it back in its shared machine (constructor). */
|
|
1408
|
+
this.#store.patch(name, { phase: 'building', step: `Moving out of the shared machine ${c.sharedMachine}`, buildingSince: now, progress: buildProgress(now), movingOutOf: { sharedMachine: c.sharedMachine, machineMb: c.machineMb, machineUser: c.machineUser, memoryMb: c.memoryMb }, moveFailed: undefined });
|
|
1409
|
+
this.built = this.#movingOut(name, c, tool, memory, state).finally(() => this.#give(name, act));
|
|
1410
|
+
return this.#store.get(name);
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
async #movingOut(name, c, tool, memory, state) {
|
|
1414
|
+
const shared = c.sharedMachine;
|
|
1415
|
+
const was = { sharedMachine: shared, machineMb: c.machineMb, machineUser: c.machineUser, memoryMb: c.memoryMb };
|
|
1416
|
+
const dir = mkdtempSync(join(tmpdir(), 'clv-move-'));
|
|
1417
|
+
const carried = join(dir, 'state.tar.gz');
|
|
1418
|
+
let left = false;
|
|
1419
|
+
const back = async (why) => {
|
|
1420
|
+
/* Back in its shared machine, as it was: its own machine, if begun, removed; its work shown there again. */
|
|
1421
|
+
if (!this.#store.get(name)) return undefined;
|
|
1422
|
+
this.#store.patch(name, { sharedMachine: undefined });
|
|
1423
|
+
if ((await this.#vms.state(name, { fresh: true }).catch(() => undefined)) !== undefined) await this.#vms.removeVm(vmName(name)).catch(() => {});
|
|
1424
|
+
this.#store.patch(name, { ...was, phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, error: undefined, movingOutOf: undefined, moveFailed: `Not moved: ${why}` });
|
|
1425
|
+
if (left) await this.#vms.workMount(name, this.#uid, this.#gid).catch(() => {});
|
|
1426
|
+
this.#fresh.add(name); this.#mountAgain.add(name);
|
|
1427
|
+
try { this.renewed(name, `Not moved out of the shared machine ${shared}: ${why} It stays there, as it was.`, false); } catch { /* told, nothing more */ }
|
|
1428
|
+
return undefined;
|
|
1429
|
+
};
|
|
1430
|
+
try {
|
|
1431
|
+
this.drop(name);
|
|
1432
|
+
if (state === 'Running') await this.#vms.exec(name, ['tmux', '-L', SOCKET, 'kill-server'], { timeoutMs: 10_000 }).catch(() => {});
|
|
1433
|
+
if (tool.state) {
|
|
1434
|
+
const why = await this.#takeState(name, c, tool, carried);
|
|
1435
|
+
if (why) return back(why);
|
|
1436
|
+
}
|
|
1437
|
+
if (state === 'Running') {
|
|
1438
|
+
/* Its programs there ended, its work taken out of its place: nothing of it runs there any more. */
|
|
1439
|
+
this.#store.patch(name, { step: `Leaving the shared machine ${shared}` });
|
|
1440
|
+
await this.#vms.execMachine(name, ['sudo', '-n', 'pkill', '-KILL', '-u', `c-${name}`], { timeoutMs: 30_000 }).catch(() => {});
|
|
1441
|
+
await this.#vms.workUnmount(name).catch(() => {});
|
|
1442
|
+
left = true;
|
|
1443
|
+
}
|
|
1444
|
+
/* Its own machine, as a new conversation's: built with its name, held before its tool starts. */
|
|
1445
|
+
this.#store.patch(name, { sharedMachine: undefined, machineMb: undefined, machineUser: undefined, memoryMb: memory, step: 'Starting the machine' });
|
|
1446
|
+
/* One left behind by an attempt cut short: not this conversation's any more. */
|
|
1447
|
+
if ((await this.#vms.state(name, { fresh: true }).catch(() => undefined)) !== undefined) await this.#vms.removeVm(vmName(name)).catch(() => {});
|
|
1448
|
+
this.#holding.add(name);
|
|
1449
|
+
try { await this.#build(name, tool, memory); } finally { this.#holding.delete(name); }
|
|
1450
|
+
const now = this.#store.get(name);
|
|
1451
|
+
if (!now) return undefined; /* archived meanwhile */
|
|
1452
|
+
if (now.phase === 'failed') return back(`${String(now.error ?? 'its own machine could not be made.').replace(/\.?$/, '.')}`);
|
|
1453
|
+
let lost = '';
|
|
1454
|
+
if (tool.state) {
|
|
1455
|
+
this.#store.patch(name, { step: `Putting ${tool.label}'s state back` });
|
|
1456
|
+
try { await this.#unpack(name, c.tool, carried); } catch (error) { lost = error.message; }
|
|
1457
|
+
}
|
|
1458
|
+
this.#store.patch(name, { phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, toolStarted: false, movingOutOf: undefined });
|
|
1459
|
+
this.ready(name);
|
|
1460
|
+
/* There for good: its place in the shared machine goes -- the whole machine with the last one in it. */
|
|
1461
|
+
const others = this.#store.all().filter((x) => x.name !== name && x.sharedMachine === shared);
|
|
1462
|
+
if (others.length) {
|
|
1463
|
+
const there = this.#vms.run;
|
|
1464
|
+
await there(['vm', 'unshare', vmName(shared), name]).catch(() => {});
|
|
1465
|
+
if (left) {
|
|
1466
|
+
await there(['vm', 'exec', vmName(shared), '--', 'sudo', '-n', 'userdel', '--remove', `c-${name}`], { timeoutMs: 60_000 }).catch(() => {});
|
|
1467
|
+
await there(['vm', 'exec', vmName(shared), '--', 'sudo', '-n', 'rm', '-f', `/etc/clavarium/limits/${name}`], { timeoutMs: 30_000 }).catch(() => {});
|
|
1468
|
+
}
|
|
1469
|
+
} else await this.#vms.removeVm(vmName(shared)).catch(() => {});
|
|
1470
|
+
this.renewed(name, lost
|
|
1471
|
+
? `Moved out of the shared machine ${shared} into a machine of its own, but ${tool.label}'s state did not come along (${lost}): it starts afresh.`
|
|
1472
|
+
: `Moved out of the shared machine ${shared} into a machine of its own: its work folder${tool.state ? `, ${tool.label}'s state` : ''} and this chat came along.`, true);
|
|
1473
|
+
return undefined;
|
|
1474
|
+
} catch (error) {
|
|
1475
|
+
return back(`${String(error?.message ?? error).replace(/\.?$/, '.')}`);
|
|
1476
|
+
} finally { rmSync(dir, { recursive: true, force: true }); }
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1364
1479
|
async #fixup(name, tool) {
|
|
1365
1480
|
for (const step of tool.fixups) {
|
|
1366
1481
|
const r = await this.#vms.exec(name, step.argv, { timeoutMs: 120_000 }).catch(() => ({ code: 1 }));
|
package/server/jobs.mjs
CHANGED
|
@@ -33,6 +33,8 @@ const bare = ({ log, ...job }) => job;
|
|
|
33
33
|
export function jobWords(c) {
|
|
34
34
|
if (c.phase === 'moving') return `Moving ${titleOf(c)}${c.sharedMachine ? ` into « ${c.sharedMachine} »` : ''}`;
|
|
35
35
|
if (c.phase === 'restarting') return `Restarting ${titleOf(c)}`;
|
|
36
|
+
if (c.movingTo) return `Moving ${titleOf(c)} into « ${c.movingTo} »`;
|
|
37
|
+
if (c.movingOutOf) return `Moving ${titleOf(c)} out of « ${c.movingOutOf.sharedMachine} »`;
|
|
36
38
|
if (c.copyOf) return `Copy ${titleOf(c)}${c.sharedMachine ? ` in « ${c.sharedMachine} »` : ''}`;
|
|
37
39
|
return `Building ${titleOf(c)}${c.sharedMachine ? ` in « ${c.sharedMachine} »` : ''}`;
|
|
38
40
|
}
|
|
@@ -94,8 +96,10 @@ export class Jobs {
|
|
|
94
96
|
if (busy || !this.#open.has(name)) return;
|
|
95
97
|
const job = this.#open.get(name);
|
|
96
98
|
this.#open.delete(name);
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
+
/* A move that went back (15-11): ready where it was, but not done -- `moveFailed` says why. */
|
|
100
|
+
const ok = after?.phase === 'ready' && !after.moveFailed;
|
|
101
|
+
const said = after?.error ?? after?.moveFailed;
|
|
102
|
+
const why = after && !ok && said ? String(said).slice(0, 300) : '';
|
|
99
103
|
this.#add(name, after ? (ok ? 'Done' : `Failed${why ? `: ${why}` : ''}`) : 'Removed');
|
|
100
104
|
const { log } = this.#logs.get(name);
|
|
101
105
|
this.#logs.delete(name);
|
package/server/settingswords.mjs
CHANGED
|
@@ -181,7 +181,7 @@ export const SETTINGS_WORDS_FR = {
|
|
|
181
181
|
'set-cm-goes-work': 'Son dossier de travail', 'set-cm-goes-memory': 'La mémoire de son IA', 'set-cm-goes-access': 'Ses accès',
|
|
182
182
|
'set-cm-not': 'Ni ses appareils, ni ses rappels', 'set-cm-untouched': 'Celle-ci intacte : lue, puis remise en l\'état',
|
|
183
183
|
'set-cm-stay': 'Vous restez ici · « Ouvrir » une fois prête', 'set-cm-stops': 'Son outil s\'arrête environ une minute',
|
|
184
|
-
'set-cm-deleted': 'Sa propre machine est supprimée', 'set-cm-back': 'Retour', 'set-cm-copy-go': 'La copier', 'set-cm-move-go': 'La déplacer',
|
|
184
|
+
'set-cm-deleted': 'Sa propre machine est supprimée', 'set-cm-stops-out': 'Son outil s\'arrête quelques minutes', 'set-cm-shared-deleted': 'La machine partagée « {m} » est supprimée', 'set-cm-place-deleted': 'Sa place dans « {m} » est supprimée', 'set-cm-back': 'Retour', 'set-cm-copy-go': 'La copier', 'set-cm-move-go': 'La déplacer',
|
|
185
185
|
'set-cm-ready': 'Copie prête', 'set-cm-open': 'Ouvrir', 'set-cm-failed': 'Pas copiée', 'set-cm-see-why': 'Voir pourquoi',
|
|
186
186
|
'set-carry': 'Exporter / Importer', 'set-carry-hint': 'Mémoire de son IA, ou tout : à emporter.',
|
|
187
187
|
'set-carry-export': 'Mémoire de son IA', 'set-carry-all': 'Tout (dossier perso, travail, accès)', 'set-carry-all-off': 'Son travail doit être gardé ici.',
|
package/web/app.js
CHANGED
|
@@ -3267,11 +3267,13 @@
|
|
|
3267
3267
|
/* The places it may go, for a copy or a move of this one; the one chosen kept if it still is one. */
|
|
3268
3268
|
function cmPlaces(here) {
|
|
3269
3269
|
const machines = sharedMachines().filter((m) => !(cm.kind === 'move' && m.name === here.sharedMachine));
|
|
3270
|
-
|
|
3271
|
-
const
|
|
3270
|
+
/* Out of a shared machine (15-11): into one of its own, first; or into another shared one. */
|
|
3271
|
+
const own = cm.kind === 'copy' || Boolean(here.sharedMachine);
|
|
3272
|
+
const open = [...(own ? [''] : []), ...(cm.kind === 'move' && here.sharedMachine ? [] : [...machines.map((m) => m.name), 'new'])];
|
|
3272
3273
|
if (!open.includes(cm.place)) cm.place = open[0];
|
|
3273
3274
|
const cards = [];
|
|
3274
|
-
if (
|
|
3275
|
+
if (own) cards.push(cmCard('', uiSaid('set-where-own', 'Its own machine')));
|
|
3276
|
+
if (cm.kind === 'move' && here.sharedMachine) return { cards, open };
|
|
3275
3277
|
for (const m of machines) {
|
|
3276
3278
|
const small = [m.who.length ? uiSaid('set-cm-with', 'With {who}', { who: m.who.join(', ') }) : '', m.mb ? sizeWords(m.mb) : ''].filter(Boolean).join(' · ');
|
|
3277
3279
|
cards.push(cmCard(m.name, uiSaid('set-cm-shared', 'Shared machine « {m} »', { m: m.name }), small));
|
|
@@ -3316,7 +3318,7 @@
|
|
|
3316
3318
|
const here = conversations.find((x) => x.name === current);
|
|
3317
3319
|
if (DEVICE || !here || here.phase !== 'ready') return;
|
|
3318
3320
|
if (cm.of !== here.name) { $('cm-new-name').value = ''; $('cm-copy-title').value = ''; }
|
|
3319
|
-
Object.assign(cm, { of: here.name, kind, place: kind === 'copy' ? '' : (sharedMachines().find((m) => m.name !== here.sharedMachine)?.name ?? 'new') });
|
|
3321
|
+
Object.assign(cm, { of: here.name, kind, place: kind === 'copy' || here.sharedMachine ? '' : (sharedMachines().find((m) => m.name !== here.sharedMachine)?.name ?? 'new') });
|
|
3320
3322
|
$('machine-names').replaceChildren(...sharedMachines().map((m) => Object.assign(document.createElement('option'), { value: m.name })));
|
|
3321
3323
|
$('cm-copy-title').value = `${here.title ?? here.name} (copy)`;
|
|
3322
3324
|
/* Its sheep: two for a copy (the second slides out of the first), one walking for a move. */
|
|
@@ -3346,6 +3348,11 @@
|
|
|
3346
3348
|
$('cm-new-line')?.remove();
|
|
3347
3349
|
if (goes.machine && !goes.known) $('cm-check').prepend(Object.assign(document.createElement('p'), { id: 'cm-new-line', className: 'cm-not', textContent: uiSaid('set-cm-new-line', 'A new shared machine · {size}', { size: sizeWords(goes.machineMb) }) }));
|
|
3348
3350
|
$('cm-copy-part').hidden = cm.kind !== 'copy'; $('cm-move-part').hidden = cm.kind !== 'move';
|
|
3351
|
+
/* Out of a shared machine (15-11): its own machine is built, its place there removed -- the machine itself with the last one in it. */
|
|
3352
|
+
const out = cm.kind === 'move' && here.sharedMachine;
|
|
3353
|
+
const alone = out && !conversations.some((x) => x.name !== here.name && x.sharedMachine === here.sharedMachine);
|
|
3354
|
+
$('cm-stops').textContent = out ? uiSaid('set-cm-stops-out', 'Its tool stops for a few minutes') : uiSaid('set-cm-stops', 'Its tool stops for about a minute');
|
|
3355
|
+
$('cm-deleted').textContent = !out ? uiSaid('set-cm-deleted', 'Its own machine is deleted') : alone ? uiSaid('set-cm-shared-deleted', 'The shared machine « {m} » is deleted', { m: here.sharedMachine }) : uiSaid('set-cm-place-deleted', 'Its place in « {m} » is deleted', { m: here.sharedMachine });
|
|
3349
3356
|
$('cm-go').textContent = cm.kind === 'copy' ? uiSaid('set-cm-copy-go', 'Copy it') : uiSaid('set-cm-move-go', 'Move it');
|
|
3350
3357
|
$('cm-go').className = 'primary';
|
|
3351
3358
|
$('cm-choose').hidden = true; $('cm-check').hidden = false;
|
package/web/index.html
CHANGED
|
@@ -1520,8 +1520,8 @@
|
|
|
1520
1520
|
<p class="cm-box" data-said="set-cm-stay">You stay here · « Open it » when it is ready</p>
|
|
1521
1521
|
</div>
|
|
1522
1522
|
<div id="cm-move-part">
|
|
1523
|
-
<p class="cm-box" data-said="set-cm-stops">Its tool stops for about a minute</p>
|
|
1524
|
-
<p class="cm-box cm-danger" data-said="set-cm-deleted">Its own machine is deleted</p>
|
|
1523
|
+
<p class="cm-box" id="cm-stops" data-said="set-cm-stops">Its tool stops for about a minute</p>
|
|
1524
|
+
<p class="cm-box cm-danger" id="cm-deleted" data-said="set-cm-deleted">Its own machine is deleted</p>
|
|
1525
1525
|
</div>
|
|
1526
1526
|
<div class="cm-acts"><button type="button" id="cm-back" data-said="set-cm-back">Back</button><button type="button" class="primary" id="cm-go"></button></div>
|
|
1527
1527
|
</div>
|