clavarium 0.2.400-next.1 → 0.2.402-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.400-next.1",
3
+ "version": "0.2.402-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.400-next.1",
9
+ "version": "0.2.402-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.400-next.1",
3
+ "version": "0.2.402-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.",
@@ -14,10 +14,13 @@ import { resumeOrFresh } from './tools.mjs';
14
14
  import { TOOLS_PATH, LAUNCH } from './toolbox.mjs';
15
15
  import { availableParallelism } from 'node:os';
16
16
  import { spawn } from 'node:child_process';
17
+ import { readFileSync } from 'node:fs';
17
18
 
18
19
  export const SESSION = 'main';
19
20
  export const STOP_DELAY_MS = 60_000;
20
21
  const STEP_MS = 15 * 60_000;
22
+ /* The door of a conversation in a shared machine (#221), put in the machine by the server. */
23
+ export const DOOR = new URL('../config/machine/clavarium-enter', import.meta.url);
21
24
  /* Moving a work folder: what must stay free after it, and how long a copy may take. */
22
25
  export const ROOM_MB = 1024;
23
26
  /* A file shown straight from a machine's disk: where, and how large at most. */
@@ -268,8 +271,10 @@ export class Conversations {
268
271
 
269
272
  /* Whether a new machine may be made for this request: what `create`
270
273
  checks, and the server's room (capacity.mjs). Asked before `create`. */
271
- async admit({ name, title, tool, memoryMb } = {}) {
274
+ async admit({ name, title, tool, memoryMb, machine } = {}) {
272
275
  if (!name && typeof title === 'string' && !titleProblem(title)) ({ name } = this.#naming({ title }));
276
+ /* Into a shared machine that is there already: no new machine, no room asked for it. */
277
+ if (typeof machine === 'string' && this.#store.all().some((x) => x.sharedMachine === machine && x.machineUser)) return;
273
278
  const chosen = this.#tools.find((t) => t.id === tool);
274
279
  /* What `create` refuses anyway is said by `create`. */
275
280
  if (!chosen || !isConversationName(name) || this.#store.get(name)) return;
@@ -290,8 +295,11 @@ export class Conversations {
290
295
  return { name: id, title: title !== undefined && title !== id ? title : undefined };
291
296
  }
292
297
 
293
- create({ name: given, title: read, tool, memoryMb, cpus, diskGb, workOnDisk, group }) {
298
+ create({ name: given, title: read, tool, memoryMb, cpus, diskGb, workOnDisk, group, machine }) {
294
299
  const { name, title } = this.#naming({ name: given, title: read });
300
+ /* IN A SHARED MACHINE (#221), named: its work is always kept here (mounted into its place there). */
301
+ 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.');
302
+ if (machine !== undefined && machine === given) throw new Refusal(400, 'A shared machine has a name of its own, not a conversation\'s.');
295
303
  if (group !== undefined) { const problem = groupProblem(group); if (problem) throw new Refusal(400, problem); }
296
304
  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.');
297
305
  const chosen = this.#tools.find((t) => t.id === tool);
@@ -307,7 +315,7 @@ export class Conversations {
307
315
  if (!Number.isInteger(disk) || disk < DISK_GB || disk > DISK_MAX_GB) throw new Refusal(400, `Disk is ${DISK_GB} to ${DISK_MAX_GB} GB.`);
308
316
  if (this.#store.get(name)) throw new Refusal(409, 'A conversation already has this name.');
309
317
  const now = new Date().toISOString();
310
- 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) };
318
+ 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) };
311
319
  /* A new one comes first in its folder (or first of those in none). */
312
320
  const { order, groups } = this.#order();
313
321
  this.#store.put(conversation);
@@ -318,6 +326,7 @@ export class Conversations {
318
326
 
319
327
  /* `again`: a machine built anew for a conversation that had one. */
320
328
  async #build(name, tool, memoryMb, again = false) {
329
+ if (this.#store.get(name)?.sharedMachine) return this.#buildShared(name, tool, memoryMb);
321
330
  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}`}` }); };
322
331
  /* The size chosen at creation (stored by create, kept on a rebuild): launched with it, or, for a
323
332
  copy of a ready-made machine, brought to it while the copy is still stopped. */
@@ -407,6 +416,54 @@ export class Conversations {
407
416
  return undefined;
408
417
  }
409
418
 
419
+ /* A CONVERSATION IN A SHARED MACHINE (#221): the machine made by the first one that lives in it (its door
420
+ installed), started if it sleeps; then this one's place in it -- told to the host, its own user made by its
421
+ door, its work mounted there for that user, its tool installed (what runs as root for the machine, the rest
422
+ as its user). The same end as a machine of its own: ready, its tool started by the next opening. */
423
+ async #buildShared(name, tool, memoryMb) {
424
+ const c = this.#store.get(name);
425
+ 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}`}`, buildingSince: undefined }); return undefined; };
426
+ let state = await this.#vms.state(name, { fresh: true }).catch(() => undefined);
427
+ if (state === undefined) {
428
+ this.#store.patch(name, { step: `Making the shared machine ${c.sharedMachine}` });
429
+ const launched = await this.#vms.launch(name, memoryMb);
430
+ if (launched.code !== 0) return fail('The shared machine did not start', launched);
431
+ const sharing = await this.#vms.execMachine(name, [...SHARING_STEP], { timeoutMs: STEP_MS });
432
+ if (sharing.code !== 0) return fail('The shared machine could not be prepared for shared folders', sharing);
433
+ } else if (state !== 'Running') {
434
+ const started = await this.#vms.start(name);
435
+ if (started.code !== 0) return fail('The shared machine did not start', started);
436
+ }
437
+ /* Its door, always the one of this version (put again: an older one is replaced). */
438
+ 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 });
439
+ if (door.code !== 0) return fail('The door of the shared machine could not be put in place', door);
440
+ this.#store.patch(name, { step: 'Making its place in the shared machine' });
441
+ const told = await this.#vms.share(name);
442
+ if (told.code !== 0) return fail('The host did not take it into the shared machine', told);
443
+ const me = await this.#vms.execMachine(name, ['sudo', '-n', 'clavarium-enter', name, '--', 'sh', '-c', 'id -u; id -g'], { timeoutMs: STEP_MS });
444
+ const [uid, gid] = String(me.stdout ?? '').trim().split('\n').map(Number);
445
+ if (me.code !== 0 || !Number.isInteger(uid) || !Number.isInteger(gid)) return fail('Its own user could not be made', me);
446
+ this.#store.patch(name, { machineUser: { uid, gid } });
447
+ const kept = await this.#vms.workMake(name);
448
+ const shown = kept.code === 0 ? await this.#vms.workMount(name, uid, gid) : kept;
449
+ if (shown.code !== 0) return fail('The work folder could not be shown in the shared machine', shown);
450
+ /* Its tool: there already (another conversation installed it), or installed -- a step as root for the
451
+ machine, any other as its own user (its settings, in its home). */
452
+ const there = tool.steps.length === 0 || (await this.#vms.exec(name, ['sh', '-c', `command -v ${tool.command[0]}`])).code === 0;
453
+ for (const [i, step] of (there ? [] : tool.steps).entries()) {
454
+ if (!this.#store.get(name)) return undefined;
455
+ this.#store.patch(name, { step: `Installing ${tool.label} (${i + 1}/${tool.steps.length})` });
456
+ const r = await this.#vms.exec(name, step.argv, { input: step.input, timeoutMs: STEP_MS });
457
+ if (r.code !== 0) return fail(`Installing ${tool.label} failed at step ${i + 1}`, r);
458
+ }
459
+ this.#store.patch(name, { phase: 'ready', step: undefined, buildingSince: undefined, toolStarted: false });
460
+ this.#reach(name, 'folders');
461
+ this.#fresh.add(name);
462
+ this.#mountAgain.add(name);
463
+ this.ready(name);
464
+ return undefined;
465
+ }
466
+
410
467
  /* Builds the machine of a conversation AGAIN: after a build that failed,
411
468
  or when the machine is gone (a backup put back on a new computer brings
412
469
  the conversation's name, tool and folders, not its machine). What was
@@ -1618,12 +1675,35 @@ export class Conversations {
1618
1675
  this.#cancelStop(name);
1619
1676
  this.drop(name);
1620
1677
  const kept = this.#store.get(name).work === 'kept';
1621
- this.#store.remove(name);
1622
- if (await this.#vms.state(name, { fresh: true }) !== undefined) await this.#vms.remove(name);
1678
+ if (this.#store.get(name).sharedMachine) await this.#leaveShared(name, { erase: false });
1679
+ else {
1680
+ this.#store.remove(name);
1681
+ if (await this.#vms.state(name, { fresh: true }) !== undefined) await this.#vms.remove(name);
1682
+ }
1623
1683
  /* Its work is moved aside on the server, not erased. */
1624
1684
  if (kept) await this.#vms.workAside(name);
1625
1685
  }
1626
1686
 
1687
+ /* OUT OF A SHARED MACHINE (#221): its programs ended, its work taken out of its place there, the host told;
1688
+ its user and home removed when it is erased (kept when archived). The machine itself goes only with the last
1689
+ conversation that lived in it. The record is removed here, before the machine is looked at. */
1690
+ async #leaveShared(name, { erase }) {
1691
+ const shared = this.#store.get(name).sharedMachine;
1692
+ const others = this.#store.all().filter((x) => x.name !== name && x.sharedMachine === shared);
1693
+ const running = (await this.#vms.state(name, { fresh: true }).catch(() => undefined)) === 'Running';
1694
+ if (running) {
1695
+ await this.#vms.execMachine(name, ['sudo', '-n', 'pkill', '-KILL', '-u', `c-${name}`], { timeoutMs: 30_000 }).catch(() => {});
1696
+ await this.#vms.workUnmount(name).catch(() => {});
1697
+ if (erase) await this.#vms.execMachine(name, ['sudo', '-n', 'userdel', '--remove', `c-${name}`], { timeoutMs: 60_000 }).catch(() => {});
1698
+ }
1699
+ await this.#vms.unshare(name).catch(() => {});
1700
+ const last = others.length === 0;
1701
+ const state = last ? await this.#vms.state(name, { fresh: true }).catch(() => undefined) : undefined;
1702
+ this.#store.remove(name);
1703
+ /* (Its name gone from the store, the VM manager is still reached through the machine's own name.) */
1704
+ if (last && state !== undefined) await this.#vms.removeVm(`clv-${shared}`);
1705
+ }
1706
+
1627
1707
  /* DELETED FOR GOOD (01-11, its owner's ask, confirmed by typing its name): as archived, but its work is
1628
1708
  erased, not put aside. Whatever state its machine is in -- one that never started too. */
1629
1709
  async erase(name) {
@@ -1631,8 +1711,11 @@ export class Conversations {
1631
1711
  this.#cancelStop(name);
1632
1712
  this.drop(name);
1633
1713
  const kept = this.#store.get(name).work === 'kept';
1634
- this.#store.remove(name);
1635
- if (await this.#vms.state(name, { fresh: true }) !== undefined) await this.#vms.remove(name);
1714
+ if (this.#store.get(name).sharedMachine) await this.#leaveShared(name, { erase: true });
1715
+ else {
1716
+ this.#store.remove(name);
1717
+ if (await this.#vms.state(name, { fresh: true }) !== undefined) await this.#vms.remove(name);
1718
+ }
1636
1719
  if (kept) {
1637
1720
  const r = await this.#vms.workErase(name);
1638
1721
  if (r?.code) throw new Refusal(500, `Its machine is deleted, but its files could not be erased: ${firstLine(r.stderr) || `exit ${r.code}`}`);
package/server/main.mjs CHANGED
@@ -312,7 +312,10 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
312
312
  const asHost = runner(host);
313
313
  /* A conversation in a shared machine (#221) says which: the machine its VM operations reach. */
314
314
  const conversationStore = new Store(`${dataDir}/conversations.json`);
315
- const vms = new Vms(asHost, host, { machineOf: (name) => { const m = conversationStore.get(name)?.machine; return typeof m === 'string' && m ? m : undefined; } });
315
+ const vms = new Vms(asHost, host, {
316
+ machineOf: (name) => { const m = conversationStore.get(name)?.sharedMachine; return typeof m === 'string' && m ? m : undefined; },
317
+ userOf: (name) => { const u = conversationStore.get(name)?.machineUser; return u && Number.isInteger(u.uid) && Number.isInteger(u.gid) ? u : undefined; },
318
+ });
316
319
  const all = conversations ?? new Conversations({ store: conversationStore, layout: new JsonFile(`${dataDir}/layout.json`, {}), vms, tools, ...(stopDelayMs === undefined ? {} : { stopDelayMs }) });
317
320
  /* Who may do what with what: ONE table, shared by everything below. */
318
321
  const grants = new Grants(new Store(`${dataDir}/grants.json`));
@@ -159,6 +159,7 @@ export const SETTINGS_WORDS_FR = {
159
159
  'set-na-k-mcp': 'Serveur MCP', 'set-cx-mcp': 'serveur MCP',
160
160
  'set-mcp-head': 'Ajouter un serveur MCP', 'set-mcp-hint': 'Ses outils pour vos IA ; la clé reste ici.',
161
161
  'set-mcp-name': 'Nom', 'set-mcp-url': 'Adresse', 'set-mcp-key': 'Clé', 'set-mcp-add': 'Ajouter',
162
+ 'set-mshared-with': 'Partagée « {m} », avec {others}.', 'set-mshared-alone': 'Machine partagée « {m} », seule pour l\'instant.',
162
163
  'set-carry': 'La mémoire de son outil', 'set-carry-hint': 'Mémoire, sessions, réglages : à emporter.',
163
164
  'set-carry-export': 'Exporter', 'set-carry-import': 'Importer…', 'set-carry-go': 'Importer',
164
165
  'set-carry-ask': '« {file} » dans « {name} » ? Mémoire remplacée.', 'set-carry-done': 'Importé depuis « {from} ».',
package/server/vm.mjs CHANGED
@@ -84,11 +84,12 @@ export class VmUnknown extends Error {
84
84
  export class Vms {
85
85
  /* `run(argv, options)` reaches the host program; `prefix` is the same
86
86
  route as an argument vector, for the one caller that needs a terminal. */
87
- #ask; #snapshot = null; #asking = null; #now; #freshMs; #machineOf;
87
+ #ask; #snapshot = null; #asking = null; #now; #freshMs; #machineOf; #userOf;
88
88
  /* `freshMs`: how long one answer serves every caller (0: only those asking meanwhile). */
89
89
  /* `machineOf(conversation)`: the shared machine it lives in (#221), or nothing -- its own, `clv-<conversation>`. */
90
- constructor(run, prefix, { now = () => Date.now(), freshMs = STATES_FRESH_MS, machineOf = () => undefined } = {}) {
91
- this.#ask = run; this.prefix = prefix; this.#now = now; this.#freshMs = freshMs; this.#machineOf = machineOf;
90
+ constructor(run, prefix, { now = () => Date.now(), freshMs = STATES_FRESH_MS, machineOf = () => undefined, userOf = () => undefined } = {}) {
91
+ /* `userOf(conversation)`: its own user in a shared machine, { uid, gid } -- what its mounts are owned by there. */
92
+ this.#ask = run; this.prefix = prefix; this.#now = now; this.#freshMs = freshMs; this.#machineOf = machineOf; this.#userOf = userOf;
92
93
  /* What changes a machine makes the states asked again (not taken from before it). */
93
94
  this.run = async (argv, options) => {
94
95
  const changes = argv[0] === 'vm' && CHANGES.has(argv[1]);
@@ -116,6 +117,8 @@ export class Vms {
116
117
  return this.#asking;
117
118
  }
118
119
 
120
+ /* Whether it lives in a shared machine (#221). */
121
+ shared(conversation) { return this.#machineOf(conversation) !== undefined; }
119
122
  /* ITS MACHINE (#221): a conversation's own (`clv-<name>`, as always), or the shared one it lives in. */
120
123
  vmOf(conversation) {
121
124
  const shared = this.#machineOf(conversation);
@@ -126,8 +129,16 @@ export class Vms {
126
129
  /* In a shared machine, everything run for a conversation goes through its door (clavarium-enter, as root):
127
130
  its own /work, its own home and user, its limits -- each tool sees what it sees in a machine of its own. */
128
131
  #door(conversation, argv) {
129
- return this.#machineOf(conversation) === undefined ? argv : ['sudo', '-n', 'clavarium-enter', conversation, '--', ...argv];
132
+ /* A command run as root (sudo) is the server's own work on the machine (an install, a mount): not
133
+ through the door. Everything else -- a terminal, a tool, a probe -- is the conversation's. */
134
+ if (this.#machineOf(conversation) === undefined || argv[0] === 'sudo') return argv;
135
+ return ['sudo', '-n', 'clavarium-enter', conversation, '--', ...argv];
130
136
  }
137
+ /* In a shared machine: its machine-wide work, as its admin user, never through a door (the door itself installed). */
138
+ execMachine(conversation, argv, options) { return this.run(['vm', 'exec', this.vmOf(conversation), '--', ...argv], options); }
139
+ /* The host's list of who lives in a shared machine (vm share / unshare). */
140
+ share(conversation) { return this.run(['vm', 'share', this.vmOf(conversation), conversation]); }
141
+ unshare(conversation) { return this.run(['vm', 'unshare', this.vmOf(conversation), conversation]); }
131
142
 
132
143
  launch(conversation, memoryMb, diskGb, cpus) {
133
144
  /* The disk and cores go with the memory only when they are the chosen size, not the defaults. */
@@ -176,6 +187,8 @@ export class Vms {
176
187
  is on the host is decided by the host program, not here. `uid`/`gid`:
177
188
  files written in the VM belong, on the host, to this account. */
178
189
  mount(conversation, kind, name, uid, gid) {
190
+ /* In a shared machine (#221): into its own place there, where its door finds it. */
191
+ if (this.shared(conversation)) { const u = this.#userOf(conversation) ?? { uid, gid }; return this.run(['vm', 'smount', this.vmOf(conversation), conversation, kind, name, String(u.uid), String(u.gid)], { timeoutMs: 600_000 }); }
179
192
  return this.run(['vm', 'mount', this.vmOf(conversation), kind, name, String(uid), String(gid)], { timeoutMs: 600_000 });
180
193
  }
181
194
 
@@ -183,9 +196,13 @@ export class Vms {
183
196
  machine at /work. Made (or found again) before it is mounted. */
184
197
  workMake(conversation) { this.vmOf(conversation); return this.run(['work', 'make', conversation]); }
185
198
  workMount(conversation, uid, gid) {
199
+ if (this.shared(conversation)) { const u = this.#userOf(conversation) ?? { uid, gid }; return this.run(['vm', 'smount', this.vmOf(conversation), conversation, 'work', conversation, String(u.uid), String(u.gid)], { timeoutMs: 600_000 }); }
186
200
  return this.run(['vm', 'mount', this.vmOf(conversation), 'work', conversation, String(uid), String(gid)], { timeoutMs: 600_000 });
187
201
  }
188
- workUnmount(conversation) { return this.run(['vm', 'unwork', this.vmOf(conversation)], { timeoutMs: 120_000 }); }
202
+ workUnmount(conversation) {
203
+ if (this.shared(conversation)) return this.run(['vm', 'sumount', this.vmOf(conversation), conversation, 'work'], { timeoutMs: 120_000 });
204
+ return this.run(['vm', 'unwork', this.vmOf(conversation)], { timeoutMs: 120_000 });
205
+ }
189
206
  /* Megabytes left: { disk, host }, or undefined if it cannot be told. */
190
207
  async workRoom(conversation) {
191
208
  this.vmOf(conversation);
@@ -204,6 +221,7 @@ export class Vms {
204
221
  unmountTools(conversation) { return this.run(['vm', 'untools', this.vmOf(conversation)], { timeoutMs: 120_000 }); }
205
222
 
206
223
  umount(conversation, name) {
224
+ if (this.shared(conversation)) return this.run(['vm', 'sumount', this.vmOf(conversation), conversation, name], { timeoutMs: 120_000 });
207
225
  return this.run(['vm', 'umount', this.vmOf(conversation), name], { timeoutMs: 120_000 });
208
226
  }
209
227
 
@@ -240,4 +258,6 @@ export class Vms {
240
258
  suspend that did not end the process): wake+resleep, then a clean stop. */
241
259
  reclaim(conversation) { return this.run(['vm', 'reclaim', this.vmOf(conversation)], { timeoutMs: 300_000 }); }
242
260
  remove(conversation) { return this.run(['vm', 'delete', this.vmOf(conversation)], { timeoutMs: 300_000 }); }
261
+ /* A shared machine deleted by its own name (its last conversation gone: no conversation leads to it any more). */
262
+ removeVm(vm) { if (!/^clv-[a-z]([a-z0-9-]{0,30}[a-z0-9])?$/.test(vm)) throw new Error('not one of our machines'); return this.run(['vm', 'delete', vm], { timeoutMs: 300_000 }); }
243
263
  }
package/web/app.js CHANGED
@@ -1987,7 +1987,7 @@
1987
1987
  let chosenTool = '';
1988
1988
  let newTools = [];
1989
1989
  const ID_SHAPE = /^[a-z]([a-z0-9-]{0,30}[a-z0-9])?$/;
1990
- const NEW_FIELDS = ['name', 'group', 'id', 'memory'];
1990
+ const NEW_FIELDS = ['name', 'group', 'id', 'memory', 'machine'];
1991
1991
  function newError(field, text) {
1992
1992
  const at = field && NEW_FIELDS.includes(field) ? field : '';
1993
1993
  for (const f of NEW_FIELDS) {
@@ -2101,6 +2101,20 @@
2101
2101
  b.addEventListener('click', () => { for (const other of $('newconv-work').querySelectorAll('[data-work]')) other.setAttribute('aria-checked', String(other === b)); });
2102
2102
  }
2103
2103
  const newOnDisk = () => $('newconv-work').querySelector('[data-work="disk"]').getAttribute('aria-checked') === 'true';
2104
+ /* WHERE IT LIVES (#221): its own machine, or a shared one -- an existing one offered, or a new name. In a shared
2105
+ machine its files are always kept here: that choice is hidden. */
2106
+ const newShared = () => $('newconv-where').querySelector('[data-where="shared"]').getAttribute('aria-checked') === 'true';
2107
+ const paintWhere = () => {
2108
+ const shared = newShared();
2109
+ $('newconv-machine-row').hidden = !shared;
2110
+ $('newconv-files-card').hidden = shared;
2111
+ const names = [...new Set(conversations.map((c) => c.sharedMachine).filter(Boolean))].sort();
2112
+ $('machine-names').replaceChildren(...names.map((n) => Object.assign(document.createElement('option'), { value: n })));
2113
+ if (shared && !$('newconv-machine').value && names.length) $('newconv-machine').value = names[0];
2114
+ };
2115
+ for (const b of $('newconv-where').querySelectorAll('[data-where]')) {
2116
+ b.addEventListener('click', () => { for (const other of $('newconv-where').querySelectorAll('[data-where]')) other.setAttribute('aria-checked', String(other === b)); paintWhere(); });
2117
+ }
2104
2118
  async function openNew({ push = true, group = null } = {}) {
2105
2119
  if (DEVICE) return;
2106
2120
  newError('', '');
@@ -2149,6 +2163,7 @@
2149
2163
  const group = $('newconv-group').value.trim();
2150
2164
  if (!title) { newError('name', 'Give a name.'); return; }
2151
2165
  if (id && !ID_SHAPE.test(id)) { newError('id', 'Lower-case letters, digits, hyphens'); return; }
2166
+ if (newShared() && !ID_SHAPE.test($('newconv-machine').value.trim())) { newError('machine', 'A name: lower-case letters, digits, hyphens'); return; }
2152
2167
  const least = newTools.find((t) => t.id === chosenTool)?.memoryMb;
2153
2168
  const memoryMb = Number($('newconv-memory').value);
2154
2169
  const cpus = Number($('newconv-cpus').value); const diskGb = Number($('newconv-disk').value);
@@ -2156,9 +2171,9 @@
2156
2171
  creating = true; $('newconv-create').disabled = true;
2157
2172
  try {
2158
2173
  const opencode = await openCodeChoice();
2159
- const made = await post(`${API}/conversations`, { ...(opencode ? { opencode } : {}), title, ...(id ? { name: id } : {}), ...(group ? { group } : {}), tool: chosenTool, workOnDisk: newOnDisk(), ...(document.getElementById('newconv-chat')?.checked === false ? { chat: false } : {}), ...(memoryMb && memoryMb !== least ? { memoryMb } : {}), ...(cpus && cpus !== 1 ? { cpus } : {}), ...(diskGb && diskGb !== 8 ? { diskGb } : {}) });
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 } : {}) });
2160
2175
  $('newconv-name').value = ''; $('newconv-id').value = ''; $('newconv-id').placeholder = 'website-redesign'; $('newconv-group').value = '';
2161
- $('newconv-work').querySelector('[data-work="kept"]').click(); $('newconv-more').open = false; { const ch = document.getElementById('newconv-chat'); if (ch) ch.checked = true; }
2176
+ $('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; }
2162
2177
  await refresh();
2163
2178
  /* The new one is selected: the page gives way to it, with no step of it left behind. */
2164
2179
  select(made.name);
@@ -2574,6 +2589,15 @@
2574
2589
  catch (error) { show(error.message, 'Back to the terminal', enter); }
2575
2590
  }, () => { notice.hidden = true; focusTerminal(); });
2576
2591
  };
2592
+ /* In a shared machine (#221): its name and the others in it, said once -- stopping it stops them too. */
2593
+ const sharedIn = here?.sharedMachine;
2594
+ $('machine-shared').hidden = DEVICE || !sharedIn;
2595
+ if (sharedIn) {
2596
+ const others = conversations.filter((c) => c.sharedMachine === sharedIn && c.name !== current).map((c) => c.title ?? c.name);
2597
+ $('machine-shared').textContent = others.length
2598
+ ? uiSaid('set-mshared-with', 'Shared machine « {m} », with {others}. Stopping it stops them too.', { m: sharedIn, others: others.join(', ') })
2599
+ : uiSaid('set-mshared-alone', 'Shared machine « {m} », alone in it for now.', { m: sharedIn });
2600
+ }
2577
2601
  /* Its tool's memory, exported as one file, or put back from one (#351): the person's own act, from here. */
2578
2602
  $('carry-box').hidden = DEVICE || !here;
2579
2603
  $('carry-export').href = `${API}/conversations/${encodeURIComponent(current)}/export`;
package/web/index.html CHANGED
@@ -203,6 +203,8 @@
203
203
  <div class="curves-head"><b>Over time</b><div class="levels curves-span" role="group" aria-label="Over"><button type="button" data-span="1h" aria-pressed="true">1 h</button><button type="button" data-span="24h" aria-pressed="false">24 h</button><button type="button" data-span="7d" aria-pressed="false">7 days</button></div></div>
204
204
  <div class="curves-row"></div>
205
205
  </div>
206
+ <!-- IN A SHARED MACHINE (#221): which, and who else lives in it -- its stop or restart stops them too. -->
207
+ <p id="machine-shared" class="hint machine-shared" hidden></p>
206
208
  <p id="machine-restarted" class="hint" role="status" hidden></p>
207
209
  <div id="resume-box" hidden>
208
210
  <div class="set-row"><div class="set-what"><b>When its tool starts</b><small id="resume-hint">After a wake or restart</small></div><div class="set-control"><div class="levels" id="resume-on" role="group" aria-label="When its tool starts"><button type="button" data-on="true">Resume its last session</button><button type="button" data-on="false">Start fresh</button></div></div></div>
@@ -1432,7 +1434,16 @@
1432
1434
  </div>
1433
1435
  <small id="newconv-oc-raw" class="hint" hidden>Set it up yourself in its terminal.</small>
1434
1436
  </div>
1435
- <div class="nc-card">
1437
+ <!-- WHERE IT LIVES (#221): a machine of its own, or a shared one (lighter, for assistants). -->
1438
+ <div class="nc-card" id="newconv-where-card">
1439
+ <span class="sub-head">Where it lives</span>
1440
+ <div id="newconv-where" class="pick two" role="radiogroup" aria-label="Where it lives">
1441
+ <button type="button" role="radio" data-where="own" aria-checked="true"><b>Its own machine</b><small>All to itself</small></button>
1442
+ <button type="button" role="radio" data-where="shared" aria-checked="false"><b>A shared machine</b><small>Lighter. For assistants</small></button>
1443
+ </div>
1444
+ <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>
1445
+ </div>
1446
+ <div class="nc-card" id="newconv-files-card">
1436
1447
  <span class="sub-head">Its files</span>
1437
1448
  <div id="newconv-work" class="pick two" role="radiogroup" aria-label="Its files">
1438
1449
  <button type="button" role="radio" data-work="kept" aria-checked="true"><b>Kept here</b><small>Seen in Files. Outlives the machine</small></button>