clavarium 0.2.251-beta.1 → 0.2.252-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.
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.251-beta.1",
3
+ "version": "0.2.252-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.251-beta.1",
9
+ "version": "0.2.252-beta.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
13
13
  "@xterm/xterm": "^6.0.0",
14
14
  "clavarium-binder": "0.1.66-next.1",
15
15
  "clavarium-docket": "0.1.2-next.3",
16
- "clavarium-parley": "0.17.101-next.1",
16
+ "clavarium-parley": "0.17.102-next.1",
17
17
  "clavarium-tether": "0.1.0-next.79",
18
18
  "mammoth": "1.13.0",
19
19
  "mermaid": "11.17.2",
@@ -787,9 +787,9 @@
787
787
  }
788
788
  },
789
789
  "node_modules/clavarium-parley": {
790
- "version": "0.17.101-next.1",
791
- "resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.101-next.1.tgz",
792
- "integrity": "sha512-OwQhmMDa8TvYXaDVIHKKBG3x2sKdkdIJUm9A/NTArSSTnAG/liD5iIt+rilcMZM7820ogmywoF8cU+3RUoJZbg==",
790
+ "version": "0.17.102-next.1",
791
+ "resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.102-next.1.tgz",
792
+ "integrity": "sha512-RUGpMBGs1ibNjVZnz0ghMP9YJPRlIYQtqlaI94WP354gzcwoUiQ/0G/m8HiWNxXGLVvcWU0hy7pM+3lFvvvosw==",
793
793
  "license": "MIT",
794
794
  "bin": {
795
795
  "parley": "bin/parley.mjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.251-beta.1",
3
+ "version": "0.2.252-beta.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
@@ -47,7 +47,7 @@
47
47
  "@xterm/xterm": "^6.0.0",
48
48
  "clavarium-binder": "0.1.66-next.1",
49
49
  "clavarium-docket": "0.1.2-next.3",
50
- "clavarium-parley": "0.17.101-next.1",
50
+ "clavarium-parley": "0.17.102-next.1",
51
51
  "clavarium-tether": "0.1.0-next.79",
52
52
  "mammoth": "1.13.0",
53
53
  "mermaid": "11.17.2",
package/server/api.mjs CHANGED
@@ -1076,8 +1076,8 @@ export async function handleApi(request, response, conversations, headers, resou
1076
1076
  if (typeof body?.escalate === 'boolean') return send(200, conversations.setStopEscalate(conversation, body.escalate)), true;
1077
1077
  /* Its watchdog (watchdog.mjs): on or off, and how long it waits. */
1078
1078
  if (body?.watchdog && typeof body.watchdog === 'object') return send(200, conversations.setWatchdog(conversation, { on: typeof body.watchdog.on === 'boolean' ? body.watchdog.on : undefined, delayMin: body.watchdog.delayMin })), true;
1079
- /* Its shared machine's own memory (#221): the whole machine restarted, every conversation in it. */
1080
- if (body?.machineMb !== undefined) return send(200, await conversations.resizeShared(conversation, { machineMb: body.machineMb })), true;
1079
+ /* Its shared machine's own memory, cores and disk (#221; 28-11): the whole machine restarted, every conversation in it. */
1080
+ if (body?.machineMb !== undefined || body?.machineDiskGb !== undefined || body?.machineCpus !== undefined) return send(200, await conversations.resizeShared(conversation, { machineMb: body.machineMb, diskGb: body.machineDiskGb, cpus: body.machineCpus })), true;
1081
1081
  const resized = await conversations.resize(conversation, { memoryMb: body.memoryMb, diskGb: body.diskGb, cpus: body.cpus });
1082
1082
  /* Asleep, nothing was started: the choice is only kept, for its wake. */
1083
1083
  return send(resized.phase === 'restarting' ? 202 : 200, resized), true;
@@ -188,7 +188,7 @@ export class Conversations {
188
188
  if (c.phase === 'moving') store.patch(c.name, { phase: 'ready', step: undefined, moved: 'The server restarted while the work folder was being moved. The files are safe, in the machine: look at /work, /work.before-move and /work.moving.' });
189
189
  /* A move into a shared machine cut short (14-11): back in its own machine, as it was -- never « build it
190
190
  again », which would make its own machine anew and lose its tool's memory. */
191
- 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.` });
191
+ if (c.phase === 'building' && c.movingTo) store.patch(c.name, { phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, sharedMachine: undefined, machineMb: undefined, machineDiskGb: undefined, machineCpus: 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.` });
192
192
  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.` });
193
193
  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.' });
194
194
  /* A change of AI cut short before its switch: it kept its AI (the record changes in one write). */
@@ -338,6 +338,11 @@ export class Conversations {
338
338
 
339
339
  /* The size of a shared machine: what its first conversation made it with (each of its conversations carries
340
340
  it); undefined while none lives in it. */
341
+ /* Its disk and cores as the others in that machine know them (28-11), or nothing: the defaults it was made with. */
342
+ #machineSizesOf(machine) {
343
+ const peer = this.#store.all().find((x) => x.sharedMachine === machine && (Number.isInteger(x.machineDiskGb) || Number.isInteger(x.machineCpus)));
344
+ return peer ? { machineDiskGb: peer.machineDiskGb, machineCpus: peer.machineCpus } : {};
345
+ }
341
346
  #machineMbOf(machine) {
342
347
  const there = this.#store.all().filter((x) => x.sharedMachine === machine);
343
348
  if (!there.length) return undefined;
@@ -374,7 +379,7 @@ export class Conversations {
374
379
  }
375
380
  if (this.#store.get(name)) throw new Refusal(409, 'A conversation already has this name.');
376
381
  const now = new Date().toISOString();
377
- const conversation = { name, ...(title ? { title } : {}), ...(group ? { group } : {}), tool, memoryMb: memory, cpus: cores, diskGb: disk, fixed: FIXES, ...(machine ? { sharedMachine: machine, machineMb: size } : {}), work: workOnDisk === true && !machine ? 'disk' : 'kept', phase: 'building', step: 'Starting the machine', createdAt: now, buildingSince: now, progress: buildProgress(now) };
382
+ const conversation = { name, ...(title ? { title } : {}), ...(group ? { group } : {}), tool, memoryMb: memory, cpus: cores, diskGb: disk, fixed: FIXES, ...(machine ? { sharedMachine: machine, machineMb: size, ...this.#machineSizesOf(machine) } : {}), work: workOnDisk === true && !machine ? 'disk' : 'kept', phase: 'building', step: 'Starting the machine', createdAt: now, buildingSince: now, progress: buildProgress(now) };
378
383
  /* A new one comes first in its folder (or first of those in none). */
379
384
  const { order, groups } = this.#order();
380
385
  this.#store.put(conversation);
@@ -1496,7 +1501,7 @@ export class Conversations {
1496
1501
  const carried = join(dir, 'state.tar.gz');
1497
1502
  const back = (why) => {
1498
1503
  /* Back to its own machine, as it was (stopped: the next opening wakes it). */
1499
- this.#store.patch(name, { toolsStarted: c.toolsStarted, 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}` });
1504
+ this.#store.patch(name, { toolsStarted: c.toolsStarted, sharedMachine: undefined, machineMb: undefined, machineDiskGb: undefined, machineCpus: undefined, machineUser: undefined, memoryMb: c.memoryMb, phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, error: undefined, movingTo: undefined, movingFromMb: undefined, moveFailed: `Not moved: ${why}` });
1500
1505
  this.#fresh.add(name); this.#mountAgain.add(name);
1501
1506
  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 */ }
1502
1507
  };
@@ -1512,7 +1517,8 @@ export class Conversations {
1512
1517
  const stopped = await this.#vms.stop(name);
1513
1518
  if (stopped.code !== 0) return back(`its machine did not stop: ${firstLine(stopped.stderr) || `exit ${stopped.code}`}.`);
1514
1519
  }
1515
- this.#store.patch(name, { sharedMachine: machine, machineMb: size, memoryMb: memory });
1520
+ /* Its disk and cores are the machine's: those the others there know of (28-11). */
1521
+ this.#store.patch(name, { sharedMachine: machine, machineMb: size, memoryMb: memory, ...this.#machineSizesOf(machine) });
1516
1522
  await this.#buildShared(name, tool, memory);
1517
1523
  const now = this.#store.get(name);
1518
1524
  if (!now) return undefined; /* archived meanwhile */
@@ -1602,7 +1608,7 @@ export class Conversations {
1602
1608
  left = true;
1603
1609
  }
1604
1610
  /* Its own machine, as a new conversation's: built with its name, held before its tool starts. */
1605
- this.#store.patch(name, { sharedMachine: undefined, machineMb: undefined, machineUser: undefined, memoryMb: memory, step: 'Starting the machine' });
1611
+ this.#store.patch(name, { sharedMachine: undefined, machineMb: undefined, machineDiskGb: undefined, machineCpus: undefined, machineUser: undefined, memoryMb: memory, step: 'Starting the machine' });
1606
1612
  /* One left behind by an attempt cut short: not this conversation's any more. */
1607
1613
  if ((await this.#vms.state(name, { fresh: true }).catch(() => undefined)) !== undefined) await this.#vms.removeVm(vmName(name)).catch(() => {});
1608
1614
  this.#holding.add(name);
@@ -2472,30 +2478,48 @@ export class Conversations {
2472
2478
  return this.#store.get(name);
2473
2479
  }
2474
2480
 
2475
- /* A SHARED MACHINE GIVEN MORE OR LESS MEMORY (#221), from the settings of any conversation in it: never less than
2476
- the largest limit of those in it; stopped cleanly, set, started again -- every conversation in it is
2477
- interrupted, the page says so before. Each then finds its place again (its work mounted) at its next opening. */
2478
- async resizeShared(name, { machineMb } = {}) {
2481
+ /* A SHARED MACHINE RESIZED (#221; disk and cores 28-11), from the settings of any conversation in it: its memory
2482
+ never less than the largest limit of those in it, its disk only grows, its cores up to the server's; stopped
2483
+ cleanly, set, started again -- every conversation in it is interrupted, the page says so before. Each then finds
2484
+ its place again (its work mounted) at its next opening. What is not given stays as it is. */
2485
+ async resizeShared(name, { machineMb, diskGb, cpus } = {}) {
2479
2486
  const c = this.#busyCheck(name);
2480
2487
  if (!c.sharedMachine) throw new Refusal(400, 'Not in a shared machine.');
2481
2488
  const all = this.#store.all().filter((x) => x.sharedMachine === c.sharedMachine);
2489
+ const given = (v) => v !== undefined && v !== null && v !== '';
2482
2490
  const now = this.#machineMbOf(c.sharedMachine);
2483
- const size = Number(machineMb);
2491
+ const real = await this.#vms.size(name).catch(() => ({}));
2492
+ const diskNow = real?.diskGb ?? all.map((x) => x.machineDiskGb).find(Number.isInteger) ?? DISK_GB;
2493
+ const cpusNow = real?.cpus ?? all.map((x) => x.machineCpus).find(Number.isInteger) ?? 1;
2494
+ const size = given(machineMb) ? Number(machineMb) : now;
2495
+ const disk = given(diskGb) ? Number(diskGb) : diskNow;
2496
+ const cores = given(cpus) ? Number(cpus) : cpusNow;
2484
2497
  const largest = Math.max(...all.map((x) => Number(x.memoryMb) || 0));
2485
- if (!Number.isInteger(size) || size < Math.max(1024, largest) || size > 16384) throw new Refusal(400, `The machine ${c.sharedMachine} has ${Math.max(1024, largest)} to 16384 MB (no less than the largest of its conversations).`);
2486
- if (size === now) throw new Refusal(409, 'Nothing to change: it already has this.');
2498
+ if (size !== now && (!Number.isInteger(size) || size < Math.max(1024, largest) || size > 16384)) throw new Refusal(400, `The machine ${c.sharedMachine} has ${Math.max(1024, largest)} to 16384 MB (no less than the largest limit of the conversations in it).`);
2499
+ if (!Number.isInteger(disk) || disk > DISK_MAX_GB) throw new Refusal(400, `A disk is at most ${DISK_MAX_GB} GB.`);
2500
+ if (disk < diskNow) throw new Refusal(400, `A disk can only grow: it has ${diskNow} GB.`);
2501
+ const hostCpus = availableParallelism();
2502
+ if (cores !== cpusNow && (!Number.isInteger(cores) || cores < 1 || cores > hostCpus)) throw new Refusal(400, `Cores: 1 to ${hostCpus}, those of this server, which its machines share.`);
2503
+ if (size === now && disk === diskNow && cores === cpusNow) throw new Refusal(409, 'Nothing to change: it already has this.');
2487
2504
  for (const x of all) if (this.#acts.has(x.name)) throw this.#busy(x.name);
2488
2505
  const state = await this.#vms.state(name, { fresh: true }).catch(() => undefined);
2489
2506
  if (state === undefined) throw new Refusal(410, 'The shared machine no longer exists.');
2490
- await this.room({ kind: 'grow', name, memoryMb: state === 'Running' ? Math.max(0, size - now) : 0, diskMb: 0 });
2507
+ await this.room({ kind: 'grow', name, memoryMb: state === 'Running' ? Math.max(0, size - now) : 0, diskMb: Math.max(0, disk - diskNow) * 1024 });
2491
2508
  for (const x of all) { this.#cancelStop(x.name); this.drop(x.name); }
2492
2509
  const fail = (what, r) => new Refusal(502, `${what}: ${firstLine(r.stderr) || firstLine(r.stdout) || `exit ${r.code}`}`);
2493
2510
  if (state !== 'Stopped') { const r = await this.#vms.stop(name); if (r.code !== 0) throw fail('The shared machine did not stop', r); }
2494
- const set = await this.#vms.setMemory(name, size);
2495
- if (set.code !== 0) { await this.#vms.start(name).catch(() => undefined); throw fail('Its memory could not be set', set); }
2511
+ const steps = [[size !== now, () => this.#vms.setMemory(name, size), 'Its memory could not be set'],
2512
+ [cores !== cpusNow, () => this.#vms.setCpus(name, cores), 'Its cores could not be set'],
2513
+ [disk !== diskNow, () => this.#vms.setDisk(name, disk), 'Its disk could not be grown']];
2514
+ for (const [wanted, run, what] of steps) {
2515
+ if (!wanted) continue;
2516
+ const r = await run();
2517
+ if (r.code !== 0) { await this.#vms.start(name).catch(() => undefined); throw fail(what, r); }
2518
+ }
2496
2519
  const started = await this.#vms.start(name);
2520
+ const said = [size !== now ? `${size} MB` : '', cores !== cpusNow ? `${cores} core${cores > 1 ? 's' : ''}` : '', disk !== diskNow ? `a ${disk} GB disk` : ''].filter(Boolean).join(', ');
2497
2521
  for (const x of all) {
2498
- this.#store.patch(x.name, { machineMb: size, toolStarted: false, restarted: `Its shared machine was restarted with ${size} MB.` });
2522
+ this.#store.patch(x.name, { machineMb: size, machineDiskGb: disk, machineCpus: cores, toolStarted: false, restarted: `Its shared machine was restarted with ${said}.` });
2499
2523
  this.#mountAgain.add(x.name); this.#fresh.add(x.name);
2500
2524
  }
2501
2525
  if (started.code !== 0) throw fail('The shared machine did not start again', started);
package/web/app.js CHANGED
@@ -3149,12 +3149,20 @@
3149
3149
  if (sharers) $('where-now').append(' · ', uiSaid('set-where-stops', 'Stopping it stops them too'));
3150
3150
  for (const id of ['where-copy', 'where-move']) $(id).disabled = here.phase !== 'ready';
3151
3151
  }
3152
- if (sharedHere && document.activeElement !== $('shared-memory')) {
3152
+ if (sharedHere && !['shared-memory', 'shared-cpus', 'shared-disk'].includes(document.activeElement?.id)) {
3153
3153
  const inIt = conversations.filter((x) => x.sharedMachine === here.sharedMachine);
3154
3154
  const floor = Math.max(1024, ...inIt.map((x) => x.memoryMb ?? 0)); const now = here.machineMb ?? floor;
3155
3155
  const sizes = [...new Set([now, ...MEMORY_CHOICES.filter((m) => m >= floor)])].sort((a, b) => a - b);
3156
3156
  $('shared-memory').replaceChildren(...sizes.map((m) => Object.assign(document.createElement('option'), { value: String(m), textContent: `${sizeWords(m)}${m === now ? ' (now)' : ''}` })));
3157
3157
  $('shared-memory').value = String(now);
3158
+ /* Its cores and disk (28-11): the machine's, as last set (else the defaults it was made with); a disk only grows. */
3159
+ const coresNow = here.machineCpus ?? 1; const most = Math.max(here.hostCpus ?? 1, coresNow);
3160
+ $('shared-cpus').replaceChildren(...Array.from({ length: most }, (_, i) => i + 1).map((n) => Object.assign(document.createElement('option'), { value: String(n), textContent: `${n}${n === coresNow ? ' (now)' : ''}` })));
3161
+ $('shared-cpus').value = String(coresNow);
3162
+ const diskNow = here.machineDiskGb ?? 8;
3163
+ const disks = [...new Set([diskNow, ...DISK_CHOICES.filter((d) => d > diskNow)])].sort((a, b) => a - b);
3164
+ $('shared-disk').replaceChildren(...disks.map((d) => Object.assign(document.createElement('option'), { value: String(d), textContent: `${d} GB${d === diskNow ? ' (now)' : ''}` })));
3165
+ $('shared-disk').value = String(diskNow);
3158
3166
  }
3159
3167
  /* When its tool starts: its last session, or a new one -- for a tool that can take one up. */
3160
3168
  $('resume-box').hidden = DEVICE || !here?.resumes;
@@ -3510,14 +3518,17 @@
3510
3518
  const here = conversations.find((x) => x.name === name);
3511
3519
  if (!here?.sharedMachine) return;
3512
3520
  const machineMb = Number($('shared-memory').value);
3513
- if (machineMb === here.machineMb) { $('panel-error').textContent = 'Nothing to change: choose another memory first.'; $('panel-error').hidden = false; return; }
3521
+ const machineCpus = Number($('shared-cpus').value); const machineDiskGb = Number($('shared-disk').value);
3522
+ const coresNow = here.machineCpus ?? 1; const diskNow = here.machineDiskGb ?? 8;
3523
+ if (machineMb === here.machineMb && machineCpus === coresNow && machineDiskGb === diskNow) { $('panel-error').textContent = 'Nothing to change: choose another size first.'; $('panel-error').hidden = false; return; }
3524
+ const asked = [machineMb !== here.machineMb ? `${sizeWords(machineMb)} of memory (now ${sizeWords(here.machineMb ?? 0)})` : '', machineCpus !== coresNow ? `${machineCpus} core${machineCpus > 1 ? 's' : ''} (now ${coresNow})` : '', machineDiskGb !== diskNow ? `a ${machineDiskGb} GB disk (now ${diskNow} GB; a disk cannot shrink again)` : ''].filter(Boolean).join(', ');
3514
3525
  const inIt = conversations.filter((x) => x.sharedMachine === here.sharedMachine).map((x) => x.title ?? x.name);
3515
3526
  leavePanel();
3516
3527
  const resume = socket && state.dataset.state === 'live' ? () => { notice.hidden = true; focusTerminal(); } : enter;
3517
- show(`Give the shared machine « ${here.sharedMachine} » ${sizeWords(machineMb)} of memory (now ${sizeWords(here.machineMb ?? 0)})? IT IS STOPPED AND STARTED AGAIN: ${inIt.join(', ')} ${inIt.length > 1 ? 'are' : 'is'} interrupted.`,
3528
+ show(`Give the shared machine « ${here.sharedMachine} » ${asked}? IT IS STOPPED AND STARTED AGAIN: ${inIt.join(', ')} ${inIt.length > 1 ? 'are' : 'is'} interrupted.`,
3518
3529
  'Change it', async () => {
3519
3530
  disconnect(); say('restarting', 'connecting'); show('Changing the shared machine...'); $('notice-spin').hidden = false;
3520
- try { await post(`${API}/conversations/${encodeURIComponent(name)}/machine`, { machineMb }); await refresh(); enter(); }
3531
+ try { await post(`${API}/conversations/${encodeURIComponent(name)}/machine`, { ...(machineMb !== here.machineMb ? { machineMb } : {}), ...(machineCpus !== coresNow ? { machineCpus } : {}), ...(machineDiskGb !== diskNow ? { machineDiskGb } : {}) }); await refresh(); enter(); }
3521
3532
  catch (error) { show(error.message, 'Back', enter); }
3522
3533
  }, resume);
3523
3534
  });
package/web/index.html CHANGED
@@ -240,7 +240,11 @@
240
240
  <form id="shared-size" autocomplete="off" hidden>
241
241
  <label for="shared-memory">Shared machine memory</label>
242
242
  <select id="shared-memory"></select>
243
- <p class="hint" id="shared-size-hint">Restarts every conversation in it</p>
243
+ <label for="shared-cpus">Its cores</label>
244
+ <select id="shared-cpus"></select>
245
+ <label for="shared-disk">Its disk</label>
246
+ <select id="shared-disk"></select>
247
+ <p class="hint" id="shared-size-hint">Restarts every conversation in it · a disk only grows</p>
244
248
  <div class="row"><button type="submit" id="shared-size-apply">Change...</button></div>
245
249
  </form>
246
250
  <div id="work-box">