clavarium 0.2.198-beta.1 → 0.2.199-beta.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/conversations.mjs +36 -12
- package/web/style.css +3 -0
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.199-beta.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.199-beta.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/conversations.mjs
CHANGED
|
@@ -102,7 +102,7 @@ const sizeSaid = (c, asked = {}) => {
|
|
|
102
102
|
const firstLine = (text) => String(text ?? '').trim().split('\n').filter(Boolean).pop()?.slice(0, 200) ?? '';
|
|
103
103
|
|
|
104
104
|
export class Conversations {
|
|
105
|
-
#layout; #store; #vms; #tools; #stopDelayMs; #timers = new Map(); #watching = new Map(); #fresh = new Set(); #mountAgain = new Set(); #holding = new Set(); #uid; #gid;
|
|
105
|
+
#layout; #store; #vms; #tools; #stopDelayMs; #timers = new Map(); #watching = new Map(); #fresh = new Set(); #mountAgain = new Set(); #holding = new Set(); #borrowed = new Set(); #uid; #gid;
|
|
106
106
|
/* THE ONE ACTION RUNNING ON EACH MACHINE (machineAction), by name: a start, a stop, a restart, a
|
|
107
107
|
sleep, a resize, a force stop. A second one is refused while it runs; Force stop ends it and
|
|
108
108
|
takes its place. */
|
|
@@ -462,10 +462,14 @@ export class Conversations {
|
|
|
462
462
|
const sharing = await this.#vms.execMachine(name, [...SHARING_STEP], { timeoutMs: STEP_MS });
|
|
463
463
|
if (sharing.code !== 0) return fail('The shared machine could not be prepared for shared folders', sharing);
|
|
464
464
|
} else if (state !== 'Running') {
|
|
465
|
+
this.#store.patch(name, { step: `Starting the shared machine ${c.sharedMachine}` });
|
|
465
466
|
const started = await this.#vms.start(name);
|
|
466
467
|
if (started.code !== 0) return fail('The shared machine did not start', started);
|
|
467
468
|
}
|
|
468
|
-
/* Its door, always the one of this version (put again: an older one is replaced).
|
|
469
|
+
/* Its door, always the one of this version (put again: an older one is replaced). The page's steps follow
|
|
470
|
+
(preparing, installing): a new shared machine takes minutes, never one frozen "Starting". */
|
|
471
|
+
this.#reach(name, 'preparing');
|
|
472
|
+
this.#store.patch(name, { step: `Opening its door in the shared machine ${c.sharedMachine}` });
|
|
469
473
|
const door = await this.#vms.execMachine(name, ['sudo', '-n', 'install', '-m', '0755', '-o', 'root', '-g', 'root', '/dev/stdin', '/usr/local/sbin/clavarium-enter'], { input: readFileSync(DOOR, 'utf8'), timeoutMs: STEP_MS });
|
|
470
474
|
if (door.code !== 0) return fail('The door of the shared machine could not be put in place', door);
|
|
471
475
|
this.#store.patch(name, { step: 'Making its place in the shared machine' });
|
|
@@ -488,9 +492,11 @@ export class Conversations {
|
|
|
488
492
|
const there = tool.steps.length === 0 || (await this.#vms.exec(name, ['sh', '-c', `command -v ${tool.command[0]}`])).code === 0;
|
|
489
493
|
/* There already: its own steps still (its settings, in its own home), the machine's not. */
|
|
490
494
|
const steps = there ? tool.steps.filter((s) => s.argv[0] !== 'sudo') : tool.steps;
|
|
495
|
+
this.#reach(name, 'installing', there ? 'came' : undefined);
|
|
491
496
|
for (const [i, step] of steps.entries()) {
|
|
492
497
|
if (!this.#store.get(name)) return undefined;
|
|
493
498
|
this.#store.patch(name, { step: `Installing ${tool.label} (${i + 1}/${steps.length})` });
|
|
499
|
+
this.#reach(name, 'installing', `${i + 1}/${steps.length}`);
|
|
494
500
|
const r = await this.#vms.exec(name, step.argv, { input: step.input, timeoutMs: STEP_MS });
|
|
495
501
|
if (r.code !== 0) return fail(`Installing ${tool.label} failed at step ${i + 1}`, r);
|
|
496
502
|
}
|
|
@@ -941,7 +947,10 @@ export class Conversations {
|
|
|
941
947
|
+ 'ex=""; for a in $2; do ex="$ex --exclude=./$a"; done; ks=""; for a in $3; do if [ -e "$HOME/$a" ]; then ks="$ks ./$a"; fi; done; '
|
|
942
948
|
+ 'tar -czf - -C "$m" clavarium-conversation.json -C "$HOME" $ex $ks; rm -rf "$m"';
|
|
943
949
|
const argv = this.#vms.execArgv(name, ['sh', '-c', script, 'export', manifest, tool.state.skip.join(' '), tool.state.keep.join(' ')]);
|
|
944
|
-
const child = spawn(argv[0], argv.slice(1), { stdio: ['ignore', 'pipe', '
|
|
950
|
+
const child = spawn(argv[0], argv.slice(1), { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
951
|
+
/* What it said when it failed: kept short, for the message that says why (a copy, a move). */
|
|
952
|
+
child.said = '';
|
|
953
|
+
child.stderr.on('data', (d) => { child.said = (child.said + d).slice(-2000); });
|
|
945
954
|
return { name: `${name}-${new Date().toISOString().slice(0, 10)}.clavarium.tar.gz`, stream: child.stdout, child };
|
|
946
955
|
}
|
|
947
956
|
|
|
@@ -1024,17 +1033,30 @@ export class Conversations {
|
|
|
1024
1033
|
const state = await this.#vms.state(from, { fresh: true }).catch(() => undefined);
|
|
1025
1034
|
if (state !== 'Running') {
|
|
1026
1035
|
await this.room({ kind: 'start', name: from, memoryMb: Number(c.memoryMb) || tool.memoryMb });
|
|
1036
|
+
/* Woken outside a wake, it is still marked asleep: borrowed, so that the server's sweep of sleepers
|
|
1037
|
+
holding memory (capacity.mjs, reclaimSleepers) does not put it back to sleep while it is read --
|
|
1038
|
+
the reading would end cut (13-11: exit 255). */
|
|
1039
|
+
this.#borrowed.add(from);
|
|
1027
1040
|
const started = await this.#vms.start(from);
|
|
1028
1041
|
if (started.code !== 0) throw new Error(`its original's machine did not start: ${firstLine(started.stderr) || `exit ${started.code}`}.`);
|
|
1029
1042
|
woke = true;
|
|
1043
|
+
/* Started is not yet reachable: its commands wait for it, two minutes at most. */
|
|
1044
|
+
for (let i = 0; i < 24 && (await this.#vms.exec(from, ['true'], { timeoutMs: 20_000 }).catch(() => ({ code: 1 }))).code !== 0; i++) await new Promise((ok) => setTimeout(ok, 5000));
|
|
1030
1045
|
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1046
|
+
/* Read once more if the VM manager could not reach it (255): a machine just woken may still be settling. */
|
|
1047
|
+
let code; let child;
|
|
1048
|
+
for (let attempt = 0; attempt < 2 && code !== 0; attempt++) {
|
|
1049
|
+
if (attempt) await new Promise((ok) => setTimeout(ok, 10_000));
|
|
1050
|
+
const out = await this.exportState(from);
|
|
1051
|
+
child = out.child;
|
|
1052
|
+
const failed = new Promise((ok) => child.on('error', () => ok(-1)));
|
|
1053
|
+
const file = createWriteStream(carried, { mode: 0o600 });
|
|
1054
|
+
out.stream.pipe(file);
|
|
1055
|
+
code = await Promise.race([new Promise((ok) => child.on('close', ok)), failed]);
|
|
1056
|
+
await new Promise((ok) => (file.writableFinished ? ok() : file.on('finish', ok)));
|
|
1057
|
+
if (code !== 255) break;
|
|
1058
|
+
}
|
|
1059
|
+
if (code !== 0) throw new Error(`its tool's memory could not be read (exit ${code}${firstLine(child.said) ? `: ${firstLine(child.said)}` : ''}).`);
|
|
1038
1060
|
if ((await this.#vms.state(to, { fresh: true }).catch(() => undefined)) !== 'Running') {
|
|
1039
1061
|
const started = await this.#vms.start(to);
|
|
1040
1062
|
if (started.code !== 0) throw new Error(`its machine did not start: ${firstLine(started.stderr) || `exit ${started.code}`}.`);
|
|
@@ -1055,6 +1077,7 @@ export class Conversations {
|
|
|
1055
1077
|
} finally {
|
|
1056
1078
|
rmSync(dir, { recursive: true, force: true });
|
|
1057
1079
|
if (woke) await this.sleep(from).catch(() => {});
|
|
1080
|
+
this.#borrowed.delete(from);
|
|
1058
1081
|
}
|
|
1059
1082
|
}
|
|
1060
1083
|
|
|
@@ -1110,7 +1133,7 @@ export class Conversations {
|
|
|
1110
1133
|
stream.pipe(file);
|
|
1111
1134
|
const code = await Promise.race([new Promise((ok) => child.on('close', ok)), failed]);
|
|
1112
1135
|
await new Promise((ok) => (file.writableFinished ? ok() : file.on('finish', ok)));
|
|
1113
|
-
if (code !== 0) return back(`its tool's state could not be taken (exit ${code}).`);
|
|
1136
|
+
if (code !== 0) return back(`its tool's state could not be taken (exit ${code}${firstLine(child.said) ? `: ${firstLine(child.said)}` : ''}).`);
|
|
1114
1137
|
}
|
|
1115
1138
|
if (state !== undefined) {
|
|
1116
1139
|
this.#store.patch(name, { step: 'Stopping its own machine' });
|
|
@@ -1616,7 +1639,8 @@ export class Conversations {
|
|
|
1616
1639
|
awake() { return this.#store.all().filter((c) => c.phase === 'ready' && c.asleep !== true && c.stopped !== true).map((c) => c.name); }
|
|
1617
1640
|
/* Put to sleep, and nothing else: not one being built (02-11: a reset machine was taken for a sleeper and
|
|
1618
1641
|
suspended mid-build), not a failed one. */
|
|
1619
|
-
|
|
1642
|
+
/* (One woken the time a copy reads it -- #borrowed -- is not asleep then: its memory is never "reclaimed" under it.) */
|
|
1643
|
+
asleep() { return this.#store.all().filter((c) => c.phase === 'ready' && c.asleep === true && !this.#borrowed.has(c.name)).map((c) => c.name); }
|
|
1620
1644
|
|
|
1621
1645
|
/* Whether the machine of a conversation runs right now. */
|
|
1622
1646
|
async running(name) { return (await this.#vms.state(name)) === 'Running'; }
|
package/web/style.css
CHANGED
|
@@ -3057,3 +3057,6 @@ button.kit-switch[aria-checked="true"]::after { left: 18px; background: var(--ok
|
|
|
3057
3057
|
html:not([data-door="device"]) #room > header .views button { gap: 4px; padding-inline: 7px; }
|
|
3058
3058
|
html:not([data-door="device"]) #room > header .views .count { min-width: 1.2em; padding: 1px 4px; }
|
|
3059
3059
|
}
|
|
3060
|
+
/* At hand (13-11): a switch's name never under its buttons -- the name keeps its width, the buttons wrap. */
|
|
3061
|
+
.hand-switches .set-row > .set-what { flex: none; }
|
|
3062
|
+
.hand-switches .set-row > .set-control { flex: 0 1 auto; min-width: 0; flex-wrap: wrap; justify-content: flex-end; }
|