clavarium 0.2.405-next.1 → 0.2.407-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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.405-next.1",
3
+ "version": "0.2.407-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.405-next.1",
9
+ "version": "0.2.407-next.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.405-next.1",
3
+ "version": "0.2.407-next.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.",
package/server/api.mjs CHANGED
@@ -20,6 +20,7 @@
20
20
  * POST /api/conversations/<name>/health look now (never wakes a machine)
21
21
  * POST /api/conversations/<name>/health/seen what it says now no longer calls its owner (Needs you)
22
22
  * POST /api/conversations/<name>/exit-report why its tool ended: { now (read in its machine, if it runs), last (kept at its end) }
23
+ * POST /api/conversations/<name>/machine {machineMb} in a shared machine: that machine's memory, all in it restarted
23
24
  * POST /api/conversations/<name>/archive
24
25
  * POST /api/binder/suggest {id}: at most three quick actions for that card -> {actions: [{key, label, why, on, ask?}]}
25
26
  * POST /api/mailboxes/<name>/live {smtp, email?}: that mailbox connected live too (send, move...), its password reused
@@ -958,6 +959,8 @@ export async function handleApi(request, response, conversations, headers, resou
958
959
  if (typeof body?.escalate === 'boolean') return send(200, conversations.setStopEscalate(conversation, body.escalate)), true;
959
960
  /* Its watchdog (watchdog.mjs): on or off, and how long it waits. */
960
961
  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;
962
+ /* Its shared machine's own memory (#221): the whole machine restarted, every conversation in it. */
963
+ if (body?.machineMb !== undefined) return send(200, await conversations.resizeShared(conversation, { machineMb: body.machineMb })), true;
961
964
  const resized = await conversations.resize(conversation, { memoryMb: body.memoryMb, diskGb: body.diskGb, cpus: body.cpus });
962
965
  /* Asleep, nothing was started: the choice is only kept, for its wake. */
963
966
  return send(resized.phase === 'restarting' ? 202 : 200, resized), true;
@@ -23,6 +23,9 @@ const STEP_MS = 15 * 60_000;
23
23
  export const DOOR = new URL('../config/machine/clavarium-enter', import.meta.url);
24
24
  /* The most programs one conversation may run in a shared machine. */
25
25
  export const SHARED_PROCS = 1024;
26
+ /* A NEW SHARED MACHINE's memory (12-11, operator): chosen when it is made, 4 GB unless said; the conversations
27
+ that live in it share it, each within its own limit. */
28
+ export const SHARED_MB = 4096;
26
29
  /* Moving a work folder: what must stay free after it, and how long a copy may take. */
27
30
  export const ROOM_MB = 1024;
28
31
  /* A file shown straight from a machine's disk: where, and how large at most. */
@@ -273,14 +276,15 @@ export class Conversations {
273
276
 
274
277
  /* Whether a new machine may be made for this request: what `create`
275
278
  checks, and the server's room (capacity.mjs). Asked before `create`. */
276
- async admit({ name, title, tool, memoryMb, machine } = {}) {
279
+ async admit({ name, title, tool, memoryMb, machine, machineMb } = {}) {
277
280
  if (!name && typeof title === 'string' && !titleProblem(title)) ({ name } = this.#naming({ title }));
278
281
  /* Into a shared machine that is there already: no new machine, no room asked for it. */
279
- if (typeof machine === 'string' && this.#store.all().some((x) => x.sharedMachine === machine && x.machineUser)) return;
282
+ if (typeof machine === 'string' && this.#machineMbOf(machine) !== undefined) return;
280
283
  const chosen = this.#tools.find((t) => t.id === tool);
281
284
  /* What `create` refuses anyway is said by `create`. */
282
285
  if (!chosen || !isConversationName(name) || this.#store.get(name)) return;
283
- const memory = memoryMb ?? chosen.memoryMb;
286
+ /* A new shared machine: the room it takes is its own size, not the conversation's. */
287
+ const memory = typeof machine === 'string' ? (machineMb ?? SHARED_MB) : (memoryMb ?? chosen.memoryMb);
284
288
  if (!Number.isInteger(memory)) return;
285
289
  await this.room({ kind: 'create', memoryMb: memory });
286
290
  }
@@ -297,7 +301,15 @@ export class Conversations {
297
301
  return { name: id, title: title !== undefined && title !== id ? title : undefined };
298
302
  }
299
303
 
300
- create({ name: given, title: read, tool, memoryMb, cpus, diskGb, workOnDisk, group, machine }) {
304
+ /* The size of a shared machine: what its first conversation made it with (each of its conversations carries
305
+ it); undefined while none lives in it. */
306
+ #machineMbOf(machine) {
307
+ const there = this.#store.all().filter((x) => x.sharedMachine === machine);
308
+ if (!there.length) return undefined;
309
+ return there.map((x) => x.machineMb).find(Number.isInteger) ?? Math.max(...there.map((x) => Number(x.memoryMb) || 0));
310
+ }
311
+
312
+ create({ name: given, title: read, tool, memoryMb, cpus, diskGb, workOnDisk, group, machine, machineMb }) {
301
313
  const { name, title } = this.#naming({ name: given, title: read });
302
314
  /* IN A SHARED MACHINE (#221), named: its work is always kept here (mounted into its place there). */
303
315
  if (machine !== undefined && (typeof machine !== 'string' || !isConversationName(machine))) throw new Refusal(400, 'A machine name is 1 to 32 lower-case letters, digits or hyphens; it starts with a letter.');
@@ -315,9 +327,18 @@ export class Conversations {
315
327
  if (!Number.isInteger(cores) || cores < 1 || cores > availableParallelism()) throw new Refusal(400, `Cores are 1 to ${availableParallelism()} (what this server has).`);
316
328
  const disk = diskGb ?? DISK_GB;
317
329
  if (!Number.isInteger(disk) || disk < DISK_GB || disk > DISK_MAX_GB) throw new Refusal(400, `Disk is ${DISK_GB} to ${DISK_MAX_GB} GB.`);
330
+ /* Its shared machine's size: chosen when it is made (4 GB unless said), then the same for all in it; a
331
+ conversation never asks more than its machine has. */
332
+ let size;
333
+ if (machine !== undefined) {
334
+ const there = this.#machineMbOf(machine);
335
+ size = there ?? machineMb ?? SHARED_MB;
336
+ if (there === undefined && (!Number.isInteger(size) || size < 1024 || size > 16384)) throw new Refusal(400, 'A shared machine has 1024 to 16384 MB of memory.');
337
+ if (memory > size) throw new Refusal(400, `The machine ${machine} has ${size} MB of memory: this conversation cannot have more (${memory} MB).`);
338
+ }
318
339
  if (this.#store.get(name)) throw new Refusal(409, 'A conversation already has this name.');
319
340
  const now = new Date().toISOString();
320
- const conversation = { name, ...(title ? { title } : {}), ...(group ? { group } : {}), tool, memoryMb: memory, cpus: cores, diskGb: disk, fixed: FIXES, ...(machine ? { sharedMachine: machine } : {}), work: workOnDisk === true && !machine ? 'disk' : 'kept', phase: 'building', step: 'Starting the machine', createdAt: now, buildingSince: now, progress: buildProgress(now) };
341
+ 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) };
321
342
  /* A new one comes first in its folder (or first of those in none). */
322
343
  const { order, groups } = this.#order();
323
344
  this.#store.put(conversation);
@@ -428,7 +449,7 @@ export class Conversations {
428
449
  let state = await this.#vms.state(name, { fresh: true }).catch(() => undefined);
429
450
  if (state === undefined) {
430
451
  this.#store.patch(name, { step: `Making the shared machine ${c.sharedMachine}` });
431
- const launched = await this.#vms.launch(name, memoryMb);
452
+ const launched = await this.#vms.launch(name, Number.isInteger(c.machineMb) ? c.machineMb : memoryMb);
432
453
  if (launched.code !== 0) return fail('The shared machine did not start', launched);
433
454
  const sharing = await this.#vms.execMachine(name, [...SHARING_STEP], { timeoutMs: STEP_MS });
434
455
  if (sharing.code !== 0) return fail('The shared machine could not be prepared for shared folders', sharing);
@@ -998,6 +1019,7 @@ export class Conversations {
998
1019
  async resize(name, asked = {}) {
999
1020
  const c = this.#busyCheck(name);
1000
1021
  const tool = this.#tools.find((t) => t.id === c.tool);
1022
+ if (c.sharedMachine) return this.#limitShared(name, c, tool, asked);
1001
1023
  const { memory, disk, cpus } = this.#sizeAsked(c, tool, asked);
1002
1024
  if (c.asleep === true) return this.#later(name, c, { memoryMb: memory, cpus, diskGb: disk });
1003
1025
  const act = this.#take(name, 'resize');
@@ -1231,7 +1253,7 @@ export class Conversations {
1231
1253
  const timer = setTimeout(() => {
1232
1254
  this.#timers.delete(name);
1233
1255
  /* Not under an action of its owner's (a restart, a sleep): that one decides. */
1234
- if (!this.#watching.has(name) && !this.#acts.has(name)) { this.drop(name); void this.#vms.stop(name); }
1256
+ if (!this.#watching.has(name) && !this.#acts.has(name)) { this.drop(name); void this.#stopUnlessShared(name); }
1235
1257
  }, this.#stopDelayMs);
1236
1258
  timer.unref?.();
1237
1259
  this.#timers.set(name, timer);
@@ -1730,6 +1752,65 @@ export class Conversations {
1730
1752
  }
1731
1753
  }
1732
1754
 
1755
+ /* ITS TOOL ENDED, ITS MACHINE STOPPED -- unless it is a shared machine (#221) where another conversation still
1756
+ has its tool, a screen or an action: then only this one's programs end, the others go on. */
1757
+ async #stopUnlessShared(name) {
1758
+ const shared = this.#store.get(name)?.sharedMachine;
1759
+ if (!shared) return this.#vms.stop(name);
1760
+ for (const other of this.#store.all().filter((x) => x.name !== name && x.sharedMachine === shared)) {
1761
+ if (this.#watching.has(other.name) || this.#acts.has(other.name) || this.#timers.has(other.name)) return this.#endShared(name);
1762
+ const alive = await this.#vms.exec(other.name, ['tmux', '-L', SOCKET, 'has-session', '-t', `=${SESSION}`]).catch(() => ({ code: 1 }));
1763
+ if (alive.code === 0) return this.#endShared(name);
1764
+ }
1765
+ return this.#vms.stop(name);
1766
+ }
1767
+ #endShared(name) { return this.#vms.execMachine(name, ['sudo', '-n', 'pkill', '-KILL', '-u', `c-${name}`], { timeoutMs: STEP_MS }).catch(() => undefined); }
1768
+
1769
+ /* ITS SHARE OF A SHARED MACHINE (#221): its memory there is its limit, at most the machine's; set without
1770
+ stopping anything, read by its door when its tool starts again. Cores and disk are the machine's. */
1771
+ async #limitShared(name, c, tool, { memoryMb, diskGb, cpus } = {}) {
1772
+ if ((diskGb !== undefined && diskGb !== null && diskGb !== '' && Number(diskGb) !== (c.diskGb ?? DISK_GB)) || (cpus !== undefined && cpus !== null && cpus !== '' && Number(cpus) !== (c.cpus ?? 1))) throw new Refusal(400, `Cores and disk are those of the shared machine ${c.sharedMachine}.`);
1773
+ const memory = Number(memoryMb);
1774
+ const size = this.#machineMbOf(c.sharedMachine);
1775
+ const least = tool?.memoryMb ?? 512;
1776
+ if (!Number.isInteger(memory) || memory < least || memory > size) throw new Refusal(400, `Its memory is between ${least} MB (what ${tool?.label ?? 'its tool'} needs) and ${size} MB (its shared machine's).`);
1777
+ if (memory === c.memoryMb) throw new Refusal(409, 'Nothing to change: it already has this.');
1778
+ const r = await this.#vms.execMachine(name, ['sudo', '-n', 'install', '-D', '-m', '0644', '-o', 'root', '-g', 'root', '/dev/stdin', `/etc/clavarium/limits/${name}`], { input: `mem=${memory}\nprocs=${SHARED_PROCS}\n`, timeoutMs: STEP_MS });
1779
+ if (r.code !== 0) throw new Refusal(502, `Its limit could not be set: ${firstLine(r.stderr) || `exit ${r.code}`}`);
1780
+ this.#store.patch(name, { memoryMb: memory, restarted: `Its limit is now ${memory} MB, from its tool's next start.` });
1781
+ return this.#store.get(name);
1782
+ }
1783
+
1784
+ /* A SHARED MACHINE GIVEN MORE OR LESS MEMORY (#221), from the settings of any conversation in it: never less than
1785
+ the largest limit of those in it; stopped cleanly, set, started again -- every conversation in it is
1786
+ interrupted, the page says so before. Each then finds its place again (its work mounted) at its next opening. */
1787
+ async resizeShared(name, { machineMb } = {}) {
1788
+ const c = this.#busyCheck(name);
1789
+ if (!c.sharedMachine) throw new Refusal(400, 'Not in a shared machine.');
1790
+ const all = this.#store.all().filter((x) => x.sharedMachine === c.sharedMachine);
1791
+ const now = this.#machineMbOf(c.sharedMachine);
1792
+ const size = Number(machineMb);
1793
+ const largest = Math.max(...all.map((x) => Number(x.memoryMb) || 0));
1794
+ 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).`);
1795
+ if (size === now) throw new Refusal(409, 'Nothing to change: it already has this.');
1796
+ for (const x of all) if (this.#acts.has(x.name)) throw this.#busy(x.name);
1797
+ const state = await this.#vms.state(name, { fresh: true }).catch(() => undefined);
1798
+ if (state === undefined) throw new Refusal(410, 'The shared machine no longer exists.');
1799
+ await this.room({ kind: 'grow', name, memoryMb: state === 'Running' ? Math.max(0, size - now) : 0, diskMb: 0 });
1800
+ for (const x of all) { this.#cancelStop(x.name); this.drop(x.name); }
1801
+ const fail = (what, r) => new Refusal(502, `${what}: ${firstLine(r.stderr) || firstLine(r.stdout) || `exit ${r.code}`}`);
1802
+ if (state !== 'Stopped') { const r = await this.#vms.stop(name); if (r.code !== 0) throw fail('The shared machine did not stop', r); }
1803
+ const set = await this.#vms.setMemory(name, size);
1804
+ if (set.code !== 0) { await this.#vms.start(name).catch(() => undefined); throw fail('Its memory could not be set', set); }
1805
+ const started = await this.#vms.start(name);
1806
+ for (const x of all) {
1807
+ this.#store.patch(x.name, { machineMb: size, toolStarted: false, restarted: `Its shared machine was restarted with ${size} MB.` });
1808
+ this.#mountAgain.add(x.name); this.#fresh.add(x.name);
1809
+ }
1810
+ if (started.code !== 0) throw fail('The shared machine did not start again', started);
1811
+ return this.#store.get(name);
1812
+ }
1813
+
1733
1814
  #cancelStop(name) {
1734
1815
  const timer = this.#timers.get(name);
1735
1816
  if (timer) { clearTimeout(timer); this.#timers.delete(name); }
package/web/app.js CHANGED
@@ -2111,7 +2111,10 @@
2111
2111
  const names = [...new Set(conversations.map((c) => c.sharedMachine).filter(Boolean))].sort();
2112
2112
  $('machine-names').replaceChildren(...names.map((n) => Object.assign(document.createElement('option'), { value: n })));
2113
2113
  if (shared && !$('newconv-machine').value && names.length) $('newconv-machine').value = names[0];
2114
+ /* A new shared machine: its memory chosen here (12-11); one that is there keeps its own. */
2115
+ $('newconv-machine-mb-row').hidden = !shared || names.includes($('newconv-machine').value.trim());
2114
2116
  };
2117
+ $('newconv-machine').addEventListener('input', () => paintWhere());
2115
2118
  for (const b of $('newconv-where').querySelectorAll('[data-where]')) {
2116
2119
  b.addEventListener('click', () => { for (const other of $('newconv-where').querySelectorAll('[data-where]')) other.setAttribute('aria-checked', String(other === b)); paintWhere(); });
2117
2120
  }
@@ -2171,7 +2174,7 @@
2171
2174
  creating = true; $('newconv-create').disabled = true;
2172
2175
  try {
2173
2176
  const opencode = await openCodeChoice();
2174
- const made = await post(`${API}/conversations`, { ...(opencode ? { opencode } : {}), title, ...(id ? { name: id } : {}), ...(group ? { group } : {}), tool: chosenTool, workOnDisk: newShared() ? false : newOnDisk(), ...(newShared() ? { machine: $('newconv-machine').value.trim() } : {}), ...(document.getElementById('newconv-chat')?.checked === false ? { chat: false } : {}), ...(memoryMb && memoryMb !== least ? { memoryMb } : {}), ...(cpus && cpus !== 1 ? { cpus } : {}), ...(diskGb && diskGb !== 8 ? { diskGb } : {}) });
2177
+ const made = await post(`${API}/conversations`, { ...(opencode ? { opencode } : {}), title, ...(id ? { name: id } : {}), ...(group ? { group } : {}), tool: chosenTool, workOnDisk: newShared() ? false : newOnDisk(), ...(newShared() ? { machine: $('newconv-machine').value.trim(), ...($('newconv-machine-mb-row').hidden ? {} : { machineMb: Number($('newconv-machine-mb').value) }) } : {}), ...(document.getElementById('newconv-chat')?.checked === false ? { chat: false } : {}), ...(memoryMb && memoryMb !== least ? { memoryMb } : {}), ...(cpus && cpus !== 1 ? { cpus } : {}), ...(diskGb && diskGb !== 8 ? { diskGb } : {}) });
2175
2178
  $('newconv-name').value = ''; $('newconv-id').value = ''; $('newconv-id').placeholder = 'website-redesign'; $('newconv-group').value = '';
2176
2179
  $('newconv-work').querySelector('[data-work="kept"]').click(); $('newconv-where').querySelector('[data-where="own"]').click(); $('newconv-machine').value = ''; $('newconv-more').open = false; { const ch = document.getElementById('newconv-chat'); if (ch) ch.checked = true; }
2177
2180
  await refresh();
@@ -2949,7 +2952,8 @@
2949
2952
  cores.replaceChildren(...Array.from({ length: most }, (_, i) => i + 1).map((n) => { const o = document.createElement('option'); o.value = String(n); o.textContent = `${n}${n === (here.cpus ?? 1) ? ' (now)' : ''}${n === most && n > 1 ? ' (all of this server)' : ''}`; return o; }));
2950
2953
  cores.value = String(here.cpus ?? 1);
2951
2954
  const least = here.memoryMinMb ?? 512;
2952
- const mems = [...new Set([...MEMORY_CHOICES.filter((m) => m >= least), here.memoryMb])].sort((a, b) => a - b);
2955
+ /* In a shared machine (#221): its limit there, up to the machine's own memory. */
2956
+ const mems = [...new Set([...MEMORY_CHOICES.filter((m) => m >= least && (!here.sharedMachine || m <= (here.machineMb ?? m))), here.memoryMb])].sort((a, b) => a - b);
2953
2957
  memory.replaceChildren(...mems.map((m) => { const o = document.createElement('option'); o.value = String(m); o.textContent = `${sizeWords(m)}${m === here.memoryMb ? ' (now)' : ''}${m === least ? ' (least for its tool)' : ''}`; return o; }));
2954
2958
  memory.value = String(here.memoryMb);
2955
2959
  const now = here.diskGb ?? 8;
@@ -2971,6 +2975,21 @@
2971
2975
  $('machine-later-text').textContent = here?.sizeAtWake ? `Will be applied when it wakes: ${laterWords(here.sizeAtWake)}` : '';
2972
2976
  $('machine-later').hidden = !here?.sizeAtWake;
2973
2977
  $('machine-size-apply').textContent = here?.asleep === true ? 'Keep for its wake' : 'Apply...';
2978
+ /* In a shared machine (#221): its memory is its limit there (no restart), cores and disk the machine's; the
2979
+ machine's own memory below, which restarts all in it. */
2980
+ const sharedHere = Boolean(here?.sharedMachine) && !DEVICE;
2981
+ for (const id of ['machine-cpus', 'machine-disk']) { $(id).hidden = sharedHere; $(id).previousElementSibling.hidden = sharedHere; }
2982
+ $('machine-memory').previousElementSibling.textContent = sharedHere ? 'Its limit' : 'Memory';
2983
+ $('machine-size-title').textContent = sharedHere ? 'Memory' : 'Memory, cores and disk';
2984
+ if (sharedHere) { $('machine-size-hint').textContent = 'Its limit in the shared machine · from its next start'; $('machine-size-apply').textContent = 'Apply'; }
2985
+ $('shared-size').hidden = !sharedHere || here.phase !== 'ready';
2986
+ if (sharedHere && document.activeElement !== $('shared-memory')) {
2987
+ const inIt = conversations.filter((x) => x.sharedMachine === here.sharedMachine);
2988
+ const floor = Math.max(1024, ...inIt.map((x) => x.memoryMb ?? 0)); const now = here.machineMb ?? floor;
2989
+ const sizes = [...new Set([now, ...MEMORY_CHOICES.filter((m) => m >= floor)])].sort((a, b) => a - b);
2990
+ $('shared-memory').replaceChildren(...sizes.map((m) => Object.assign(document.createElement('option'), { value: String(m), textContent: `${sizeWords(m)}${m === now ? ' (now)' : ''}` })));
2991
+ $('shared-memory').value = String(now);
2992
+ }
2974
2993
  /* When its tool starts: its last session, or a new one -- for a tool that can take one up. */
2975
2994
  $('resume-box').hidden = DEVICE || !here?.resumes;
2976
2995
  for (const b of $('resume-on').children) b.setAttribute('aria-pressed', String((b.dataset.on === 'true') === (here?.resume !== false)));
@@ -3051,6 +3070,15 @@
3051
3070
  if (!here) return;
3052
3071
  const memoryMb = Number($('machine-memory').value); const diskGb = Number($('machine-disk').value); const cpus = Number($('machine-cpus').value) || (here.cpus ?? 1);
3053
3072
  if (memoryMb === here.memoryMb && diskGb === (here.diskGb ?? 8) && cpus === (here.cpus ?? 1)) { $('panel-error').textContent = 'Nothing to change: choose another memory, cores or disk first.'; $('panel-error').hidden = false; return; }
3073
+ /* In a shared machine: its limit, set at once -- nothing stopped. */
3074
+ if (here.sharedMachine) {
3075
+ $('panel-error').hidden = true;
3076
+ void (async () => {
3077
+ try { await post(`${API}/conversations/${encodeURIComponent(name)}/machine`, { memoryMb }); await refresh(); paintMachine(conversations.find((x) => x.name === name)); }
3078
+ catch (error) { $('panel-error').textContent = error.message; $('panel-error').hidden = false; }
3079
+ })();
3080
+ return;
3081
+ }
3054
3082
  const changes = [memoryMb !== here.memoryMb ? `${sizeWords(memoryMb)} of memory (now ${sizeWords(here.memoryMb)})` : '', cpus !== (here.cpus ?? 1) ? `${cpus} core${cpus > 1 ? 's' : ''} (now ${here.cpus ?? 1})` : '', diskGb !== (here.diskGb ?? 8) ? `a disk of ${diskGb} GB (now ${here.diskGb ?? 8} GB; it can never shrink again)` : ''].filter(Boolean).join(' and ');
3055
3083
  /* Asleep: kept for its wake, from Settings, where it is then said; nothing is stopped or woken now. */
3056
3084
  if (here.asleep === true) {
@@ -3071,6 +3099,25 @@
3071
3099
  }, resume);
3072
3100
  });
3073
3101
 
3102
+ /* ITS SHARED MACHINE'S MEMORY (#221): asked first, naming every conversation it interrupts. */
3103
+ $('shared-size').addEventListener('submit', (event) => {
3104
+ event.preventDefault();
3105
+ const name = current;
3106
+ const here = conversations.find((x) => x.name === name);
3107
+ if (!here?.sharedMachine) return;
3108
+ const machineMb = Number($('shared-memory').value);
3109
+ if (machineMb === here.machineMb) { $('panel-error').textContent = 'Nothing to change: choose another memory first.'; $('panel-error').hidden = false; return; }
3110
+ const inIt = conversations.filter((x) => x.sharedMachine === here.sharedMachine).map((x) => x.title ?? x.name);
3111
+ leavePanel();
3112
+ const resume = socket && state.dataset.state === 'live' ? () => { notice.hidden = true; focusTerminal(); } : enter;
3113
+ 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.`,
3114
+ 'Change it', async () => {
3115
+ disconnect(); say('restarting', 'connecting'); show('Changing the shared machine...'); $('notice-spin').hidden = false;
3116
+ try { await post(`${API}/conversations/${encodeURIComponent(name)}/machine`, { machineMb }); await refresh(); enter(); }
3117
+ catch (error) { show(error.message, 'Back', enter); }
3118
+ }, resume);
3119
+ });
3120
+
3074
3121
  /* ---------- what its tool is told about where it is (server/guide.mjs) ---------- */
3075
3122
  /* One quiet line; behind "see", the exact text its tool reads, made by
3076
3123
  the server from these settings, the owner's own lines, and "Tell it
package/web/index.html CHANGED
@@ -213,7 +213,7 @@
213
213
  <div class="set-row"><div class="set-what"><b data-said="set-mesc">If a stop hangs</b></div><div class="set-control"><div class="levels" id="m-escalate" role="group" aria-label="If a stop hangs"><button type="button" data-on="true" data-said="set-mesc-auto">Force it</button><button type="button" data-on="false" data-said="set-mesc-ask">Ask me</button></div></div></div>
214
214
  <!-- ITS WATCHDOG (server/watchdog.mjs): mute or full that long, forced off then started, once. -->
215
215
  <div class="set-row" id="m-dog-row"><div class="set-what"><b data-said="set-mdog">Watchdog</b><small data-said="set-mdog-what">Restarts it if stuck</small></div><div class="set-control"><div class="levels" id="m-dog" role="group" aria-label="Watchdog"><button type="button" data-min="0" data-said="set-mdog-off">Off</button><button type="button" data-min="30">30 min</button><button type="button" data-min="60">1 h</button><button type="button" data-min="120">2 h</button><button type="button" data-min="custom" data-said="set-mdog-custom">Custom</button></div><label class="m-dog-min" id="m-dog-custom" hidden><input type="number" id="m-dog-min" min="10" max="1440" step="5" inputmode="numeric" aria-label="Minutes"> min</label></div></div>
216
- <div class="panel-top"><b>Memory, cores and disk</b></div>
216
+ <div class="panel-top"><b id="machine-size-title">Memory, cores and disk</b></div>
217
217
  <form id="machine-size" autocomplete="off">
218
218
  <label for="machine-memory">Memory</label>
219
219
  <select id="machine-memory"></select>
@@ -227,6 +227,13 @@
227
227
  <p class="hint" id="machine-later" role="status" hidden><span id="machine-later-text"></span> · <button type="button" id="machine-later-cancel" class="inline">cancel</button></p>
228
228
  <div class="row"><button type="submit" id="machine-size-apply">Apply...</button></div>
229
229
  </form>
230
+ <!-- ITS SHARED MACHINE'S OWN MEMORY (#221): the whole machine restarted, every conversation in it. -->
231
+ <form id="shared-size" autocomplete="off" hidden>
232
+ <label for="shared-memory">Shared machine memory</label>
233
+ <select id="shared-memory"></select>
234
+ <p class="hint" id="shared-size-hint">Restarts every conversation in it</p>
235
+ <div class="row"><button type="submit" id="shared-size-apply">Change...</button></div>
236
+ </form>
230
237
  <div id="work-box">
231
238
  <div class="panel-top"><b>Where the tool works</b></div>
232
239
  <p id="work-now" class="hint"><span><span id="work-now-text"></span></span><span id="work-now-why" class="tip" hidden></span></p>
@@ -1442,6 +1449,7 @@
1442
1449
  <button type="button" role="radio" data-where="shared" aria-checked="false"><b>A shared machine</b><small>Lighter. For assistants</small></button>
1443
1450
  </div>
1444
1451
  <div class="set-row" id="newconv-machine-row" hidden><div class="set-what"><label for="newconv-machine">Machine</label><small>An existing one, or a new name</small><span id="newconv-machine-error" class="err" role="alert" hidden></span></div><div class="set-control"><input id="newconv-machine" maxlength="32" list="machine-names" placeholder="assistants" spellcheck="false" autocapitalize="off" autocomplete="off"><datalist id="machine-names"></datalist></div></div>
1452
+ <div class="set-row" id="newconv-machine-mb-row" hidden><div class="set-what"><label for="newconv-machine-mb">Its memory</label><small>Shared by the conversations in it</small></div><div class="set-control"><select id="newconv-machine-mb"><option value="2048">2 GB</option><option value="4096" selected>4 GB</option><option value="6144">6 GB</option><option value="8192">8 GB</option><option value="12288">12 GB</option><option value="16384">16 GB</option></select></div></div>
1445
1453
  </div>
1446
1454
  <div class="nc-card" id="newconv-files-card">
1447
1455
  <span class="sub-head">Its files</span>
package/web/style.css CHANGED
@@ -498,9 +498,9 @@ details.chapter.reached { outline: 2px solid var(--brass); outline-offset: 2px;
498
498
  .facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
499
499
  .facts dt { color: var(--ink2); }
500
500
  .facts dd { margin: 0; overflow-wrap: anywhere; }
501
- #machine-size { display: flex; flex-direction: column; gap: 6px; max-width: 30rem; }
502
- #machine-size label { font-size: .8125rem; color: var(--ink2); }
503
- #machine-size select { width: 100%; min-height: 40px; font: .875rem var(--sans); color: var(--ink); background-color: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; }
501
+ #machine-size, #shared-size { display: flex; flex-direction: column; gap: 6px; max-width: 30rem; }
502
+ #machine-size label, #shared-size label { font-size: .8125rem; color: var(--ink2); }
503
+ #machine-size select, #shared-size select { width: 100%; min-height: 40px; font: .875rem var(--sans); color: var(--ink); background-color: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; }
504
504
  .health-lines { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
505
505
  .health-lines li { padding-left: 1.3em; position: relative; }
506
506
  .health-lines li::before { content: ""; position: absolute; left: .2em; top: .45em; width: .55em; height: .55em; border-radius: 50%; background: var(--ok); }
@@ -1909,10 +1909,11 @@ button.tip-btn:hover, button.tip-btn[aria-expanded="true"] { color: var(--brass-
1909
1909
  :is(#settings, #panel) .chapter-body .panel-top { border: 0; }
1910
1910
  :is(#settings, #panel) .chapter-body .panel-top > b { font-size: .6875rem; letter-spacing: .06em; text-transform: uppercase; color: var(--ink2); }
1911
1911
  /* The machine's size: each a row, its name on the left, its choice on the right. */
1912
- #panel #machine-size { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 16rem); gap: 10px 16px; align-items: center; max-width: none; }
1913
- #panel #machine-size > label { font-size: .875rem; font-weight: 600; color: var(--ink); }
1914
- #panel #machine-size > :is(p, .row) { grid-column: 1 / -1; }
1915
- #panel #machine-size > .row { justify-content: flex-end; }
1912
+ #panel :is(#machine-size, #shared-size) { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 16rem); gap: 10px 16px; align-items: center; max-width: none; }
1913
+ #panel :is(#machine-size, #shared-size) > label { font-size: .875rem; font-weight: 600; color: var(--ink); }
1914
+ #panel :is(#machine-size, #shared-size) > :is(p, .row) { grid-column: 1 / -1; }
1915
+ #panel :is(#machine-size, #shared-size) > .row { justify-content: flex-end; }
1916
+ #shared-size[hidden] { display: none; }
1916
1917
  @media (max-width: 560px) { #panel #machine-size { grid-template-columns: minmax(0, 1fr); } }
1917
1918
  /* A chapter whose body is one block (Updates, Network): its pieces are the rows, not the block. */
1918
1919
  :is(#settings, #panel) .chapter-body > :is(#updates, #wifi) { padding: 0; }