clavarium 0.2.49-next.1 → 0.2.50-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/clavarium-host +10 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/conversations.mjs +18 -3
- package/server/vm.mjs +4 -2
- package/web/app.js +11 -1
- package/web/index.html +3 -1
package/deploy/clavarium-host
CHANGED
|
@@ -724,8 +724,16 @@ AREA="$1"; VERB="$2"; shift 2
|
|
|
724
724
|
|
|
725
725
|
case "$AREA $VERB" in
|
|
726
726
|
"vm launch")
|
|
727
|
-
|
|
728
|
-
|
|
727
|
+
# <vm> <memory> [<disk-gigabytes> <cores>]: the size chosen at creation;
|
|
728
|
+
# without the last two, the defaults (DISK, one core).
|
|
729
|
+
[ $# -eq 2 ] || [ $# -eq 4 ] || usage; vm_of "$1"; memory_ok "$2"
|
|
730
|
+
disk="$DISK"; cores=1
|
|
731
|
+
if [ $# -eq 4 ]; then
|
|
732
|
+
[[ "$3" =~ ^[0-9]{1,4}$ ]] && [ "$3" -ge 5 ] && [ "$3" -le "$DISK_MAX_GB" ] || refuse "disk out of bounds: $3"
|
|
733
|
+
[[ "$4" =~ ^[0-9]{1,3}$ ]] && [ "$4" -ge 1 ] && [ "$4" -le "$(nproc)" ] || refuse "cores out of bounds: $4 (the host has $(nproc))"
|
|
734
|
+
disk="${3}G"; cores="$4"
|
|
735
|
+
fi
|
|
736
|
+
run "$MULTIPASS" launch "$IMAGE" --name "$1" --memory "${2}M" --disk "$disk" --cpus "$cores" --timeout "$LAUNCH_SECONDS" ;;
|
|
729
737
|
"vm clone")
|
|
730
738
|
# <shelf> <vm> <memory>: a conversation's machine, copied from the
|
|
731
739
|
# ready-made one (which must be stopped: Multipass refuses otherwise).
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.50-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.50-next.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
|
@@ -260,7 +260,7 @@ export class Conversations {
|
|
|
260
260
|
return { name: id, title: title !== undefined && title !== id ? title : undefined };
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
-
create({ name: given, title: read, tool, memoryMb, workOnDisk, group }) {
|
|
263
|
+
create({ name: given, title: read, tool, memoryMb, cpus, diskGb, workOnDisk, group }) {
|
|
264
264
|
const { name, title } = this.#naming({ name: given, title: read });
|
|
265
265
|
if (group !== undefined) { const problem = groupProblem(group); if (problem) throw new Refusal(400, problem); }
|
|
266
266
|
if (!isConversationName(name)) throw new Refusal(400, 'A name is 1 to 32 lower-case letters, digits or hyphens; it starts with a letter and does not end with a hyphen.');
|
|
@@ -270,9 +270,14 @@ export class Conversations {
|
|
|
270
270
|
if (!Number.isInteger(memory) || memory < chosen.memoryMb || memory > 16384) {
|
|
271
271
|
throw new Refusal(400, `This tool needs at least ${chosen.memoryMb} MB of memory.`);
|
|
272
272
|
}
|
|
273
|
+
/* Cores and disk, chosen at creation like the memory; their defaults when not given. */
|
|
274
|
+
const cores = cpus ?? 1;
|
|
275
|
+
if (!Number.isInteger(cores) || cores < 1 || cores > availableParallelism()) throw new Refusal(400, `Cores are 1 to ${availableParallelism()} (what this server has).`);
|
|
276
|
+
const disk = diskGb ?? DISK_GB;
|
|
277
|
+
if (!Number.isInteger(disk) || disk < DISK_GB || disk > DISK_MAX_GB) throw new Refusal(400, `Disk is ${DISK_GB} to ${DISK_MAX_GB} GB.`);
|
|
273
278
|
if (this.#store.get(name)) throw new Refusal(409, 'A conversation already has this name.');
|
|
274
279
|
const now = new Date().toISOString();
|
|
275
|
-
const conversation = { name, ...(title ? { title } : {}), ...(group ? { group } : {}), tool, memoryMb: memory, diskGb:
|
|
280
|
+
const conversation = { name, ...(title ? { title } : {}), ...(group ? { group } : {}), tool, memoryMb: memory, cpus: cores, diskGb: disk, fixed: FIXES, work: workOnDisk === true ? 'disk' : 'kept', phase: 'building', step: 'Starting the machine', createdAt: now, buildingSince: now, progress: buildProgress(now) };
|
|
276
281
|
/* A new one comes first in its folder (or first of those in none). */
|
|
277
282
|
const { order, groups } = this.#order();
|
|
278
283
|
this.#store.put(conversation);
|
|
@@ -284,6 +289,11 @@ export class Conversations {
|
|
|
284
289
|
/* `again`: a machine built anew for a conversation that had one. */
|
|
285
290
|
async #build(name, tool, memoryMb, again = false) {
|
|
286
291
|
const fail = (what, r) => { this.#store.patch(name, { phase: 'failed', step: undefined, progress: undefined, error: `${what}: ${firstLine(r.stderr) || firstLine(r.stdout) || `exit ${r.code}`}` }); };
|
|
292
|
+
/* The size chosen at creation (stored by create, kept on a rebuild): launched with it, or, for a
|
|
293
|
+
copy of a ready-made machine, brought to it while the copy is still stopped. */
|
|
294
|
+
const made = this.#store.get(name);
|
|
295
|
+
const diskGb = made?.diskGb ?? DISK_GB; const cpus = made?.cpus ?? 1;
|
|
296
|
+
const custom = diskGb !== DISK_GB || cpus !== 1;
|
|
287
297
|
/* A COPY OF THE READY-MADE MACHINE when there is one that holds this
|
|
288
298
|
tool (see shelf.mjs): it only has to boot. Anything wrong with the
|
|
289
299
|
copy -- an older VM manager without "clone", a copy that does not
|
|
@@ -293,13 +303,18 @@ export class Conversations {
|
|
|
293
303
|
let readyMade = false;
|
|
294
304
|
if (from) {
|
|
295
305
|
const cloned = await this.#vms.clone(name, from, memoryMb);
|
|
306
|
+
if (cloned.code === 0 && custom) {
|
|
307
|
+
/* Still stopped, like the memory the clone set: its cores, and its disk grown to the chosen size. */
|
|
308
|
+
if (cpus !== 1) await this.#vms.setCpus(name, cpus).catch(() => {});
|
|
309
|
+
if (diskGb !== DISK_GB) await this.#vms.setDisk(name, diskGb).catch(() => {});
|
|
310
|
+
}
|
|
296
311
|
const started = cloned.code === 0 ? await this.#vms.start(name) : cloned;
|
|
297
312
|
readyMade = started.code === 0;
|
|
298
313
|
if (!readyMade && await this.#vms.state(name, { fresh: true }) !== undefined) await this.#vms.remove(name);
|
|
299
314
|
if (!this.#store.get(name)) return undefined; /* archived meanwhile */
|
|
300
315
|
}
|
|
301
316
|
if (!readyMade) {
|
|
302
|
-
const launched = await this.#vms.launch(name, memoryMb);
|
|
317
|
+
const launched = await this.#vms.launch(name, memoryMb, custom ? diskGb : undefined, custom ? cpus : undefined);
|
|
303
318
|
if (launched.code !== 0) return fail('The machine did not start', launched);
|
|
304
319
|
}
|
|
305
320
|
this.#store.patch(name, { step: 'Preparing the machine', readyMade: readyMade || undefined });
|
package/server/vm.mjs
CHANGED
|
@@ -93,8 +93,10 @@ export class Vms {
|
|
|
93
93
|
return this.#asking;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
launch(conversation, memoryMb) {
|
|
97
|
-
|
|
96
|
+
launch(conversation, memoryMb, diskGb, cpus) {
|
|
97
|
+
/* The disk and cores go with the memory only when they are the chosen size, not the defaults. */
|
|
98
|
+
const size = diskGb && cpus ? [String(diskGb), String(cpus)] : [];
|
|
99
|
+
return this.run(['vm', 'launch', vmName(conversation), String(memoryMb), ...size], { timeoutMs: (LAUNCH_SECONDS + 60) * 1000 });
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
/* The machine of a conversation as a COPY of the ready-made one (see
|
package/web/app.js
CHANGED
|
@@ -1429,6 +1429,15 @@
|
|
|
1429
1429
|
select.replaceChildren(...mems.map((m) => { const o = document.createElement('option'); o.value = String(m); o.textContent = sizeWords(m); return o; }));
|
|
1430
1430
|
select.value = String(mems.includes(was) ? was : least);
|
|
1431
1431
|
$('newconv-memory-least').textContent = tool ? `${tool.label} needs ${sizeWords(least)} at least` : '';
|
|
1432
|
+
/* Cores: 1 to what this server has (learnt from any machine we know), default 1. */
|
|
1433
|
+
const hostCpus = Math.max(1, ...conversations.map((c) => c.hostCpus ?? 1));
|
|
1434
|
+
const cpus = $('newconv-cpus'); const wasCpus = Number(cpus.value) || 1;
|
|
1435
|
+
cpus.replaceChildren(...Array.from({ length: hostCpus }, (_, i) => i + 1).map((n) => { const o = document.createElement('option'); o.value = String(n); o.textContent = `${n}${n === 1 ? ' (default)' : ''}${n === hostCpus && n > 1 ? ' (all of this server)' : ''}`; return o; }));
|
|
1436
|
+
cpus.value = String(wasCpus <= hostCpus ? wasCpus : 1);
|
|
1437
|
+
/* Disk: from the default up; it only grows afterwards. */
|
|
1438
|
+
const disk = $('newconv-disk'); const wasDisk = Number(disk.value) || 8;
|
|
1439
|
+
disk.replaceChildren(...DISK_CHOICES.map((d) => { const o = document.createElement('option'); o.value = String(d); o.textContent = `${d} GB${d === 8 ? ' (default)' : ''}`; return o; }));
|
|
1440
|
+
disk.value = String(DISK_CHOICES.includes(wasDisk) ? wasDisk : 8);
|
|
1432
1441
|
}
|
|
1433
1442
|
function paintNewTools() {
|
|
1434
1443
|
const box = $('newconv-tools');
|
|
@@ -1499,10 +1508,11 @@
|
|
|
1499
1508
|
if (id && !ID_SHAPE.test(id)) { newError('id', 'Lower-case letters, digits, hyphens'); return; }
|
|
1500
1509
|
const least = newTools.find((t) => t.id === chosenTool)?.memoryMb;
|
|
1501
1510
|
const memoryMb = Number($('newconv-memory').value);
|
|
1511
|
+
const cpus = Number($('newconv-cpus').value); const diskGb = Number($('newconv-disk').value);
|
|
1502
1512
|
newError('', '');
|
|
1503
1513
|
creating = true; $('newconv-create').disabled = true;
|
|
1504
1514
|
try {
|
|
1505
|
-
const made = await post(`${API}/conversations`, { title, ...(id ? { name: id } : {}), ...(group ? { group } : {}), tool: chosenTool, workOnDisk: newOnDisk(), ...(memoryMb && memoryMb !== least ? { memoryMb } : {}) });
|
|
1515
|
+
const made = await post(`${API}/conversations`, { title, ...(id ? { name: id } : {}), ...(group ? { group } : {}), tool: chosenTool, workOnDisk: newOnDisk(), ...(memoryMb && memoryMb !== least ? { memoryMb } : {}), ...(cpus && cpus !== 1 ? { cpus } : {}), ...(diskGb && diskGb !== 8 ? { diskGb } : {}) });
|
|
1506
1516
|
$('newconv-name').value = ''; $('newconv-id').value = ''; $('newconv-id').placeholder = 'website-redesign'; $('newconv-group').value = '';
|
|
1507
1517
|
$('newconv-work').querySelector('[data-work="kept"]').click(); $('newconv-more').open = false;
|
|
1508
1518
|
await refresh();
|
package/web/index.html
CHANGED
|
@@ -904,10 +904,12 @@
|
|
|
904
904
|
<details class="more"><summary>Which one?</summary>A code project that installs packages: its disk. Can be changed later.</details>
|
|
905
905
|
</div>
|
|
906
906
|
<details class="chapter" id="newconv-more">
|
|
907
|
-
<summary><span class="chapter-title">More</span><span class="chapter-about">Identifier, memory.</span></summary>
|
|
907
|
+
<summary><span class="chapter-title">More</span><span class="chapter-about">Identifier, memory, cores, disk.</span></summary>
|
|
908
908
|
<div class="chapter-body">
|
|
909
909
|
<div class="set-row"><div class="set-what"><label for="newconv-id">Identifier</label><small>Its machine and address. Never changes</small><span id="newconv-id-error" class="err" role="alert" hidden></span></div><div class="set-control"><input id="newconv-id" maxlength="32" pattern="[a-z]([a-z0-9\-]{0,30}[a-z0-9])?" placeholder="website-redesign" spellcheck="false" autocapitalize="none"></div></div>
|
|
910
910
|
<div class="set-row"><div class="set-what"><label for="newconv-memory">Memory</label><small id="newconv-memory-least"></small><span id="newconv-memory-error" class="err" role="alert" hidden></span></div><div class="set-control"><select id="newconv-memory"></select></div></div>
|
|
911
|
+
<div class="set-row"><div class="set-what"><label for="newconv-cpus">Cores</label><small>Shared with the server's machines</small></div><div class="set-control"><select id="newconv-cpus"></select></div></div>
|
|
912
|
+
<div class="set-row"><div class="set-what"><label for="newconv-disk">Disk</label><small>For code kept on the machine; a disk only grows</small></div><div class="set-control"><select id="newconv-disk"></select></div></div>
|
|
911
913
|
</div>
|
|
912
914
|
</details>
|
|
913
915
|
</div>
|