clavarium 0.2.197-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/config/tools.json +18 -10
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/conversations.mjs +40 -14
- package/server/tools.mjs +6 -4
- package/web/style.css +11 -0
package/config/tools.json
CHANGED
|
@@ -46,13 +46,17 @@
|
|
|
46
46
|
"@anthropic-ai/claude-code"
|
|
47
47
|
],
|
|
48
48
|
"npm-writable",
|
|
49
|
+
[
|
|
50
|
+
"install",
|
|
51
|
+
"-D",
|
|
52
|
+
"-m",
|
|
53
|
+
"0600",
|
|
54
|
+
"/dev/null",
|
|
55
|
+
".claude/settings.json"
|
|
56
|
+
],
|
|
49
57
|
{
|
|
50
58
|
"argv": [
|
|
51
|
-
"
|
|
52
|
-
"-D",
|
|
53
|
-
"-m",
|
|
54
|
-
"0600",
|
|
55
|
-
"/dev/stdin",
|
|
59
|
+
"tee",
|
|
56
60
|
".claude/settings.json"
|
|
57
61
|
],
|
|
58
62
|
"input": "{\n \"theme\": \"dark-ansi\",\n \"permissions\": {\n \"allow\": [\n \"Bash(parley:*)\"\n ]\n }\n}\n"
|
|
@@ -137,13 +141,17 @@
|
|
|
137
141
|
"@anthropic-ai/claude-code"
|
|
138
142
|
],
|
|
139
143
|
"npm-writable",
|
|
144
|
+
[
|
|
145
|
+
"install",
|
|
146
|
+
"-D",
|
|
147
|
+
"-m",
|
|
148
|
+
"0600",
|
|
149
|
+
"/dev/null",
|
|
150
|
+
".claude/settings.json"
|
|
151
|
+
],
|
|
140
152
|
{
|
|
141
153
|
"argv": [
|
|
142
|
-
"
|
|
143
|
-
"-D",
|
|
144
|
-
"-m",
|
|
145
|
-
"0600",
|
|
146
|
-
"/dev/stdin",
|
|
154
|
+
"tee",
|
|
147
155
|
".claude/settings.json"
|
|
148
156
|
],
|
|
149
157
|
"input": "{\n \"theme\": \"dark-ansi\",\n \"permissions\": {\n \"allow\": [\n \"Bash(parley:*)\"\n ]\n }\n}\n"
|
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' });
|
|
@@ -486,9 +490,13 @@ export class Conversations {
|
|
|
486
490
|
/* Its tool: there already (another conversation installed it), or installed -- a step as root for the
|
|
487
491
|
machine, any other as its own user (its settings, in its home). */
|
|
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. */
|
|
494
|
+
const steps = there ? tool.steps.filter((s) => s.argv[0] !== 'sudo') : tool.steps;
|
|
495
|
+
this.#reach(name, 'installing', there ? 'came' : undefined);
|
|
496
|
+
for (const [i, step] of steps.entries()) {
|
|
490
497
|
if (!this.#store.get(name)) return undefined;
|
|
491
|
-
this.#store.patch(name, { step: `Installing ${tool.label} (${i + 1}/${
|
|
498
|
+
this.#store.patch(name, { step: `Installing ${tool.label} (${i + 1}/${steps.length})` });
|
|
499
|
+
this.#reach(name, 'installing', `${i + 1}/${steps.length}`);
|
|
492
500
|
const r = await this.#vms.exec(name, step.argv, { input: step.input, timeoutMs: STEP_MS });
|
|
493
501
|
if (r.code !== 0) return fail(`Installing ${tool.label} failed at step ${i + 1}`, r);
|
|
494
502
|
}
|
|
@@ -939,7 +947,10 @@ export class Conversations {
|
|
|
939
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; '
|
|
940
948
|
+ 'tar -czf - -C "$m" clavarium-conversation.json -C "$HOME" $ex $ks; rm -rf "$m"';
|
|
941
949
|
const argv = this.#vms.execArgv(name, ['sh', '-c', script, 'export', manifest, tool.state.skip.join(' '), tool.state.keep.join(' ')]);
|
|
942
|
-
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); });
|
|
943
954
|
return { name: `${name}-${new Date().toISOString().slice(0, 10)}.clavarium.tar.gz`, stream: child.stdout, child };
|
|
944
955
|
}
|
|
945
956
|
|
|
@@ -1022,17 +1033,30 @@ export class Conversations {
|
|
|
1022
1033
|
const state = await this.#vms.state(from, { fresh: true }).catch(() => undefined);
|
|
1023
1034
|
if (state !== 'Running') {
|
|
1024
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);
|
|
1025
1040
|
const started = await this.#vms.start(from);
|
|
1026
1041
|
if (started.code !== 0) throw new Error(`its original's machine did not start: ${firstLine(started.stderr) || `exit ${started.code}`}.`);
|
|
1027
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));
|
|
1028
1045
|
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
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)}` : ''}).`);
|
|
1036
1060
|
if ((await this.#vms.state(to, { fresh: true }).catch(() => undefined)) !== 'Running') {
|
|
1037
1061
|
const started = await this.#vms.start(to);
|
|
1038
1062
|
if (started.code !== 0) throw new Error(`its machine did not start: ${firstLine(started.stderr) || `exit ${started.code}`}.`);
|
|
@@ -1053,6 +1077,7 @@ export class Conversations {
|
|
|
1053
1077
|
} finally {
|
|
1054
1078
|
rmSync(dir, { recursive: true, force: true });
|
|
1055
1079
|
if (woke) await this.sleep(from).catch(() => {});
|
|
1080
|
+
this.#borrowed.delete(from);
|
|
1056
1081
|
}
|
|
1057
1082
|
}
|
|
1058
1083
|
|
|
@@ -1108,7 +1133,7 @@ export class Conversations {
|
|
|
1108
1133
|
stream.pipe(file);
|
|
1109
1134
|
const code = await Promise.race([new Promise((ok) => child.on('close', ok)), failed]);
|
|
1110
1135
|
await new Promise((ok) => (file.writableFinished ? ok() : file.on('finish', ok)));
|
|
1111
|
-
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)}` : ''}).`);
|
|
1112
1137
|
}
|
|
1113
1138
|
if (state !== undefined) {
|
|
1114
1139
|
this.#store.patch(name, { step: 'Stopping its own machine' });
|
|
@@ -1614,7 +1639,8 @@ export class Conversations {
|
|
|
1614
1639
|
awake() { return this.#store.all().filter((c) => c.phase === 'ready' && c.asleep !== true && c.stopped !== true).map((c) => c.name); }
|
|
1615
1640
|
/* Put to sleep, and nothing else: not one being built (02-11: a reset machine was taken for a sleeper and
|
|
1616
1641
|
suspended mid-build), not a failed one. */
|
|
1617
|
-
|
|
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); }
|
|
1618
1644
|
|
|
1619
1645
|
/* Whether the machine of a conversation runs right now. */
|
|
1620
1646
|
async running(name) { return (await this.#vms.state(name)) === 'Running'; }
|
package/server/tools.mjs
CHANGED
|
@@ -18,14 +18,16 @@ const ARCHIVE = `node-${NODE_VERSION}-linux-x64.tar.xz`;
|
|
|
18
18
|
const TMP = `/tmp/${ARCHIVE}`;
|
|
19
19
|
const APT = ['sudo', '-n', 'env', 'DEBIAN_FRONTEND=noninteractive', 'apt-get'];
|
|
20
20
|
|
|
21
|
-
/* A step is { argv, input? }: `input` goes to standard input.
|
|
21
|
+
/* A step is { argv, input? }: `input` goes to standard input. Every one as root (sudo): in a shared machine a
|
|
22
|
+
step without sudo runs as the conversation's own user, behind its door, with its own /tmp -- the archive
|
|
23
|
+
fetched there would not be the one root unpacks (#221, 13-11: "tar: Error is not recoverable"). */
|
|
22
24
|
export const NODE_STEPS = [
|
|
23
25
|
{ argv: [...APT, 'update', '-q'] },
|
|
24
26
|
{ argv: [...APT, 'install', '-y', '-q', '--no-install-recommends', 'curl', 'xz-utils', 'ca-certificates'] },
|
|
25
|
-
{ argv: ['curl', '--proto', '=https', '--tlsv1.2', '-fsSL', '--max-time', '600', '-o', TMP, `https://nodejs.org/dist/${NODE_VERSION}/${ARCHIVE}`] },
|
|
26
|
-
{ argv: ['sha256sum', '-c', '-'], input: `${NODE_SHA256} ${TMP}\n` },
|
|
27
|
+
{ argv: ['sudo', '-n', 'curl', '--proto', '=https', '--tlsv1.2', '-fsSL', '--max-time', '600', '-o', TMP, `https://nodejs.org/dist/${NODE_VERSION}/${ARCHIVE}`] },
|
|
28
|
+
{ argv: ['sudo', '-n', 'sha256sum', '-c', '-'], input: `${NODE_SHA256} ${TMP}\n` },
|
|
27
29
|
{ argv: ['sudo', '-n', 'tar', '-xJf', TMP, '-C', '/usr/local', '--strip-components=1', '--no-same-owner'] },
|
|
28
|
-
{ argv: ['rm', '-f', TMP] },
|
|
30
|
+
{ argv: ['sudo', '-n', 'rm', '-f', TMP] },
|
|
29
31
|
];
|
|
30
32
|
|
|
31
33
|
/* "npm-writable": what npm installs globally becomes the machine user's, so
|
package/web/style.css
CHANGED
|
@@ -3049,3 +3049,14 @@ button.kit-switch[aria-checked="true"]::after { left: 18px; background: var(--ok
|
|
|
3049
3049
|
.list-item.machine-item > .set-what > small.status-line { font-size: .75rem; margin: 0; }
|
|
3050
3050
|
#manager-row .status-line { margin: 2px 0 0; font-size: .75rem; }
|
|
3051
3051
|
#machines-confirm { margin: 8px 16px; }
|
|
3052
|
+
/* A phone (13-11): the bar's five buttons tighter, so that all stay on the screen -- its name gives way, never the bar. */
|
|
3053
|
+
@media (max-width: 480px) {
|
|
3054
|
+
html:not([data-door="device"]) #room > header #name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
3055
|
+
html:not([data-door="device"]) #room > header :is(.bar-right, .views) { flex: none; }
|
|
3056
|
+
html:not([data-door="device"]) #room > header .views { gap: 0; padding: 2px; }
|
|
3057
|
+
html:not([data-door="device"]) #room > header .views button { gap: 4px; padding-inline: 7px; }
|
|
3058
|
+
html:not([data-door="device"]) #room > header .views .count { min-width: 1.2em; padding: 1px 4px; }
|
|
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; }
|