clavarium 0.2.47-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 +26 -4
- package/web/index.html +9 -1
- package/web/style.css +3 -0
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
|
@@ -835,6 +835,11 @@
|
|
|
835
835
|
if (noTerminal()) $('files-open').hidden = deviceShared.length === 0;
|
|
836
836
|
$('sleep').hidden = !usable || c.asleep === true;
|
|
837
837
|
$('restart').hidden = DEVICE || !usable;
|
|
838
|
+
/* The same gestures, surfaced at the top of the panel: wake when asleep, else restart and sleep. */
|
|
839
|
+
$('quick-sleep').hidden = !usable || c.asleep === true;
|
|
840
|
+
$('quick-restart').hidden = DEVICE || !usable;
|
|
841
|
+
$('quick-wake').hidden = !c || c.asleep !== true;
|
|
842
|
+
$('panel-actions').hidden = DEVICE || !c || !(usable || c.asleep === true);
|
|
838
843
|
/* Its own sheet is there as soon as it exists: archiving one that failed is done from it. */
|
|
839
844
|
$('folders').hidden = DEVICE || !c;
|
|
840
845
|
}
|
|
@@ -1127,7 +1132,9 @@
|
|
|
1127
1132
|
/* One in Needs you just above is not said twice. */
|
|
1128
1133
|
/* The last day only: what is older is found in its group. */
|
|
1129
1134
|
const dayAgo = Date.now() - 24 * 3600_000;
|
|
1130
|
-
|
|
1135
|
+
/* Asleep ones go to the bottom of Recent: they are frozen, not what you came back to. */
|
|
1136
|
+
const recent = conversations.filter((c) => (c.hidden !== true || c.name === current) && !needsYou(c) && activityOf(c) >= dayAgo)
|
|
1137
|
+
.sort((a, b) => (Number(a.asleep === true) - Number(b.asleep === true)) || (activityOf(b) - activityOf(a)));
|
|
1131
1138
|
const few = 4;
|
|
1132
1139
|
if (recent.length && groups.length && section(RECENT, 'Recent', recent)) {
|
|
1133
1140
|
top.append(...unfolding(RECENT, recent.slice(0, showAllRecent ? recent.length : few).map((c) => itemButton(c, true))));
|
|
@@ -1422,6 +1429,15 @@
|
|
|
1422
1429
|
select.replaceChildren(...mems.map((m) => { const o = document.createElement('option'); o.value = String(m); o.textContent = sizeWords(m); return o; }));
|
|
1423
1430
|
select.value = String(mems.includes(was) ? was : least);
|
|
1424
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);
|
|
1425
1441
|
}
|
|
1426
1442
|
function paintNewTools() {
|
|
1427
1443
|
const box = $('newconv-tools');
|
|
@@ -1492,10 +1508,11 @@
|
|
|
1492
1508
|
if (id && !ID_SHAPE.test(id)) { newError('id', 'Lower-case letters, digits, hyphens'); return; }
|
|
1493
1509
|
const least = newTools.find((t) => t.id === chosenTool)?.memoryMb;
|
|
1494
1510
|
const memoryMb = Number($('newconv-memory').value);
|
|
1511
|
+
const cpus = Number($('newconv-cpus').value); const diskGb = Number($('newconv-disk').value);
|
|
1495
1512
|
newError('', '');
|
|
1496
1513
|
creating = true; $('newconv-create').disabled = true;
|
|
1497
1514
|
try {
|
|
1498
|
-
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 } : {}) });
|
|
1499
1516
|
$('newconv-name').value = ''; $('newconv-id').value = ''; $('newconv-id').placeholder = 'website-redesign'; $('newconv-group').value = '';
|
|
1500
1517
|
$('newconv-work').querySelector('[data-work="kept"]').click(); $('newconv-more').open = false;
|
|
1501
1518
|
await refresh();
|
|
@@ -7712,7 +7729,7 @@
|
|
|
7712
7729
|
$('share-done').addEventListener('click', leaveCompose);
|
|
7713
7730
|
|
|
7714
7731
|
/* ---------- resting and archiving ---------- */
|
|
7715
|
-
|
|
7732
|
+
async function sleepMachine() {
|
|
7716
7733
|
const name = current;
|
|
7717
7734
|
leavePanel();
|
|
7718
7735
|
disconnect();
|
|
@@ -7720,7 +7737,12 @@
|
|
|
7720
7737
|
show('Going to sleep...');
|
|
7721
7738
|
try { await post(`${API}/conversations/${encodeURIComponent(name)}/sleep`); await refresh(); enter(); }
|
|
7722
7739
|
catch (error) { say('awake', 'ended'); show(error.message, 'Back to the terminal', connect); }
|
|
7723
|
-
}
|
|
7740
|
+
}
|
|
7741
|
+
$('sleep').addEventListener('click', () => void sleepMachine());
|
|
7742
|
+
/* The quick actions at the top of the panel do the same as the Machine chapter's. */
|
|
7743
|
+
$('quick-sleep').addEventListener('click', () => void sleepMachine());
|
|
7744
|
+
$('quick-restart').addEventListener('click', () => { leavePanel(); void restartMachine(false); });
|
|
7745
|
+
$('quick-wake').addEventListener('click', () => { leavePanel(); seeTerminal(); });
|
|
7724
7746
|
async function rebuild() {
|
|
7725
7747
|
const name = current;
|
|
7726
7748
|
disconnect();
|
package/web/index.html
CHANGED
|
@@ -111,6 +111,12 @@
|
|
|
111
111
|
<div id="clists" class="sheet as-room" hidden><div id="clists-binder" class="binder-holder"></div></div>
|
|
112
112
|
<div id="panel" class="sheet" hidden>
|
|
113
113
|
<div class="panel-top"><b id="panel-title">This conversation</b></div>
|
|
114
|
+
<!-- The gestures done often on the machine, without opening the Machine chapter (app.js, paintMachine). -->
|
|
115
|
+
<div class="row panel-actions" id="panel-actions" hidden>
|
|
116
|
+
<button type="button" id="quick-wake" class="primary" hidden>Wake it</button>
|
|
117
|
+
<button type="button" id="quick-restart" hidden>Restart…</button>
|
|
118
|
+
<button type="button" id="quick-sleep" hidden title="Freezes the tool as it is; it wakes when you open the conversation">Sleep</button>
|
|
119
|
+
</div>
|
|
114
120
|
<p id="panel-error" class="error" role="alert" hidden></p>
|
|
115
121
|
<details class="chapter" id="chapter-general" data-chapter="general">
|
|
116
122
|
<summary><span class="chapter-title">General</span><span class="chapter-about">Name, group, chat.</span></summary>
|
|
@@ -898,10 +904,12 @@
|
|
|
898
904
|
<details class="more"><summary>Which one?</summary>A code project that installs packages: its disk. Can be changed later.</details>
|
|
899
905
|
</div>
|
|
900
906
|
<details class="chapter" id="newconv-more">
|
|
901
|
-
<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>
|
|
902
908
|
<div class="chapter-body">
|
|
903
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>
|
|
904
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>
|
|
905
913
|
</div>
|
|
906
914
|
</details>
|
|
907
915
|
</div>
|
package/web/style.css
CHANGED
|
@@ -127,6 +127,7 @@ footer button.wide { flex: 1 0 auto; background: var(--brass); border-color: var
|
|
|
127
127
|
.chip[data-access="write"] { color: var(--ok); border-color: var(--ok); }
|
|
128
128
|
.sheet { position: absolute; inset: 0; z-index: 3; display: flex; flex-direction: column; gap: 10px; padding: 14px; background: var(--panel); overflow-y: auto; }
|
|
129
129
|
.panel-top { display: flex; align-items: center; justify-content: space-between; }
|
|
130
|
+
.panel-actions { margin: 2px 0 12px; }
|
|
130
131
|
#panel-rows { display: flex; flex-direction: column; }
|
|
131
132
|
.folder { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
|
|
132
133
|
.folder b { flex: 1; min-width: 100px; overflow: hidden; text-overflow: ellipsis; }
|
|
@@ -190,6 +191,8 @@ a.button { font: 600 .8125rem var(--sans); text-decoration: none; border-radius:
|
|
|
190
191
|
#mic { flex-basis: 55%; padding-block: 12px; }
|
|
191
192
|
}
|
|
192
193
|
.item[data-asleep="true"] .dot { background: var(--ink2); }
|
|
194
|
+
/* Asleep: faded in the list (and sorted to the bottom of Recent, app.js), so it is plainly not where you are. */
|
|
195
|
+
.item[data-asleep="true"]:not([aria-current="true"]) { opacity: .62; }
|
|
193
196
|
footer button.careful { border-style: dashed; color: var(--ink2); }
|
|
194
197
|
/* On a touch screen every control is at least a fingertip high. */
|
|
195
198
|
@media (max-width: 700px) {
|