clavarium 0.2.419-next.1 → 0.2.421-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.419-next.1",
3
+ "version": "0.2.421-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.419-next.1",
9
+ "version": "0.2.421-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.419-next.1",
3
+ "version": "0.2.421-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
@@ -26,6 +26,7 @@
26
26
  * POST /api/mailboxes/<name>/live {smtp, email?}: that mailbox connected live too (send, move...), its password reused
27
27
  * POST /api/conversations/<name>/erase {confirm: <its name>}: deleted for good -- its machine and its work files
28
28
  * POST /api/conversations/<name>/into-machine {machine, machineMb?}: moved into a shared machine (#221), its tool's state along (202)
29
+ * POST /api/conversations/<name>/copy {title?, machine?, machineMb?}: a copy -- its work, its tool's state, its accesses; it untouched (202)
29
30
  * POST /api/conversations/<name>/rebuild {reset?, confirm?}: built again; reset (confirm: its name) for a working one too
30
31
  * POST /api/conversations/<name>/ask-first {on}: its tool asks before acting (true), or acts without asking in its machine (false, the default), from its next start
31
32
  * POST /api/conversations/<name>/resume {on}: its tool takes up its last session when it starts (true), or starts fresh
@@ -1003,6 +1004,13 @@ export async function handleApi(request, response, conversations, headers, resou
1003
1004
  const machineMb = body?.machineMb === undefined ? undefined : Number(body.machineMb);
1004
1005
  return send(202, await conversations.moveToShared(decodeURIComponent(moving[1]), { machine: body?.machine, machineMb })), true;
1005
1006
  }
1007
+ /* A copy of it (#221): a new conversation with its work, its tool's memory and its accesses; it untouched. */
1008
+ const copying = /^\/api\/conversations\/([^/]+)\/copy$/.exec(pathname);
1009
+ if (copying) {
1010
+ const machineMb = body?.machineMb === undefined ? undefined : Number(body.machineMb);
1011
+ const machine = typeof body?.machine === 'string' && body.machine ? body.machine : undefined;
1012
+ return send(202, await conversations.copy(decodeURIComponent(copying[1]), { title: body?.title, machine, machineMb })), true;
1013
+ }
1006
1014
  const again = /^\/api\/conversations\/([^/]+)\/rebuild$/.exec(pathname);
1007
1015
  if (again) {
1008
1016
  const reset = body?.reset === true;
@@ -130,6 +130,15 @@ export class Binders {
130
130
  }
131
131
  return out;
132
132
  }
133
+ /* A COPY of a conversation (#221) is given the lists its original was given, with the same access. */
134
+ copyGrants(from, to) {
135
+ const keeper = { id: 'person:keeper', kind: 'person', name: 'keeper' };
136
+ for (const l of this.#keeper.store.lists(keeper)) {
137
+ const given = l.grants?.[`${AGENT}${from}`];
138
+ const level = typeof given === 'string' ? given : given?.access ?? given?.level;
139
+ if (level === 'read' || level === 'write') this.#keeper.store.grant(l.id, `${AGENT}${to}`, level, keeper);
140
+ }
141
+ }
133
142
  /* FOR API KEYS (apikeys.mjs): every list with who was given it, as a person sees them; a key given a list, or
134
143
  taken back, on the list's own access -- as a conversation is. `identity`: the person, as its history says. */
135
144
  lists() { return this.#keeper.store.lists({ id: 'person:keeper', kind: 'person', name: 'keeper' }).map((l) => ({ id: l.id, title: l.title, archived: Boolean(l.archived), grants: { ...(l.grants ?? {}) } })); }
@@ -102,7 +102,7 @@ const sizeSaid = (c, asked = {}) => {
102
102
  const firstLine = (text) => String(text ?? '').trim().split('\n').filter(Boolean).pop()?.slice(0, 200) ?? '';
103
103
 
104
104
  export class Conversations {
105
- #layout; #store; #vms; #tools; #stopDelayMs; #timers = new Map(); #watching = new Map(); #fresh = new Set(); #mountAgain = new Set(); #uid; #gid;
105
+ #layout; #store; #vms; #tools; #stopDelayMs; #timers = new Map(); #watching = new Map(); #fresh = new Set(); #mountAgain = new Set(); #holding = new Set(); #uid; #gid;
106
106
  /* THE ONE ACTION RUNNING ON EACH MACHINE (machineAction), by name: a start, a stop, a restart, a
107
107
  sleep, a resize, a force stop. A second one is refused while it runs; Force stop ends it and
108
108
  takes its place. */
@@ -147,6 +147,10 @@ export class Conversations {
147
147
  or growing a machine would leave this server less than its reserve
148
148
  (capacity.mjs). `{ kind: 'create'|'start'|'grow', name, memoryMb, diskMb }`. */
149
149
  room = async () => {};
150
+ /* Set by the server: a COPY's work folder made from its original's (host side, its own files only), and the
151
+ accesses of the original given to the copy (copy, below). */
152
+ copyWork = async () => {};
153
+ copyRights = async () => {};
150
154
 
151
155
  /* `uid`/`gid`: the account this server runs as; files the tool writes in
152
156
  its kept work folder belong to it on the host. */
@@ -428,6 +432,8 @@ export class Conversations {
428
432
  }
429
433
  /* A new disk holds no session of the tool: its first start is a plain
430
434
  one (`false`: known, as opposed to a record made before this was kept). */
435
+ /* A copy being made (copy): built, but not usable until its work and its state are in. */
436
+ if (this.#holding.has(name)) { this.#store.patch(name, { step: 'Copying', toolStarted: false }); this.#fresh.add(name); this.#mountAgain.add(name); return undefined; }
431
437
  this.#store.patch(name, { phase: 'ready', step: undefined, buildingSince: undefined, toolStarted: false });
432
438
  this.#reach(name, 'folders');
433
439
  /* A machine that has just been built holds nothing of what was put
@@ -486,6 +492,7 @@ export class Conversations {
486
492
  const r = await this.#vms.exec(name, step.argv, { input: step.input, timeoutMs: STEP_MS });
487
493
  if (r.code !== 0) return fail(`Installing ${tool.label} failed at step ${i + 1}`, r);
488
494
  }
495
+ if (this.#holding.has(name)) { this.#store.patch(name, { step: 'Copying', toolStarted: false }); this.#fresh.add(name); this.#mountAgain.add(name); return undefined; }
489
496
  this.#store.patch(name, { phase: 'ready', step: undefined, buildingSince: undefined, toolStarted: false });
490
497
  this.#reach(name, 'folders');
491
498
  this.#fresh.add(name);
@@ -972,6 +979,83 @@ export class Conversations {
972
979
  return from ? { name: from.name, at: from.at } : null;
973
980
  }
974
981
 
982
+ /* A COPY OF A CONVERSATION (#221, 13-11, its owner's ask: safer than a move -- nothing is destroyed). A new
983
+ conversation, in a machine of its own or a shared one, with what its original has: its work folder (its
984
+ chat with it), its tool's state (the AI's memory), its settings, and the accesses it was given. Its devices,
985
+ its reminders and its pending asks are NOT copied: one of the two answers them, the original. Its original is
986
+ not touched; asleep, its machine is woken the time to read its tool's state, then put to sleep again.
987
+ -> the copy's record, at once; `this.copied`: the end of it. */
988
+ async copy(name, { title, machine, machineMb } = {}) {
989
+ const c = this.#store.get(name);
990
+ if (!c) throw new Refusal(404, 'No such conversation.');
991
+ if (c.phase !== 'ready') throw new Refusal(409, 'It is busy: copy it once it is ready.');
992
+ if (c.work !== 'kept') throw new Refusal(409, 'Its work is on its own machine\'s disk: it cannot be copied from here. Keep it here first (Its files), then copy it.');
993
+ const tool = this.#tools.find((t) => t.id === c.tool);
994
+ if (!tool) throw new Refusal(400, 'The tool of this conversation is no longer offered.');
995
+ const shared = machine !== undefined && machine !== null && machine !== '';
996
+ const size = shared ? this.#machineMbOf(machine) ?? machineMb ?? SHARED_MB : undefined;
997
+ const memory = shared ? Math.max(tool.memoryMb, Math.min(Number(c.memoryMb) || tool.memoryMb, Number(size) || SHARED_MB)) : Number(c.memoryMb) || tool.memoryMb;
998
+ const label = typeof title === 'string' && title.trim() ? title.trim() : `${c.title ?? c.name} (copy)`;
999
+ await this.admit({ title: label, tool: c.tool, memoryMb: memory, ...(shared ? { machine, machineMb } : {}) });
1000
+ const made = this.create({ title: label, tool: c.tool, memoryMb: memory, ...(shared ? { machine, machineMb } : { cpus: c.cpus, diskGb: c.diskGb }), ...(c.group ? { group: c.group } : {}) });
1001
+ /* Before its build can end (it awaits first): held, never usable half made. */
1002
+ this.#holding.add(made.name);
1003
+ this.#store.patch(made.name, { copyOf: name });
1004
+ const building = this.built;
1005
+ this.copied = this.#copying(name, made.name, c, tool, building);
1006
+ return this.#store.get(made.name);
1007
+ }
1008
+
1009
+ async #copying(from, to, c, tool, building) {
1010
+ const dir = mkdtempSync(join(tmpdir(), 'clv-copy-'));
1011
+ const carried = join(dir, 'state.tar.gz');
1012
+ let woke = false;
1013
+ try {
1014
+ await building;
1015
+ const built = this.#store.get(to);
1016
+ if (!built) return undefined; /* erased meanwhile */
1017
+ if (built.phase === 'failed') throw new Error(built.error ?? 'its machine could not be made.');
1018
+ this.#store.patch(to, { step: 'Copying its work' });
1019
+ await this.copyWork(from, to);
1020
+ if (tool.state) {
1021
+ this.#store.patch(to, { step: `Copying ${tool.label}'s memory` });
1022
+ const state = await this.#vms.state(from, { fresh: true }).catch(() => undefined);
1023
+ if (state !== 'Running') {
1024
+ await this.room({ kind: 'start', name: from, memoryMb: Number(c.memoryMb) || tool.memoryMb });
1025
+ const started = await this.#vms.start(from);
1026
+ if (started.code !== 0) throw new Error(`its original's machine did not start: ${firstLine(started.stderr) || `exit ${started.code}`}.`);
1027
+ woke = true;
1028
+ }
1029
+ const { stream, child } = await this.exportState(from);
1030
+ const failed = new Promise((ok) => child.on('error', () => ok(-1)));
1031
+ const file = createWriteStream(carried, { mode: 0o600 });
1032
+ stream.pipe(file);
1033
+ const code = await Promise.race([new Promise((ok) => child.on('close', ok)), failed]);
1034
+ await new Promise((ok) => (file.writableFinished ? ok() : file.on('finish', ok)));
1035
+ if (code !== 0) throw new Error(`its tool's memory could not be read (exit ${code}).`);
1036
+ if ((await this.#vms.state(to, { fresh: true }).catch(() => undefined)) !== 'Running') {
1037
+ const started = await this.#vms.start(to);
1038
+ if (started.code !== 0) throw new Error(`its machine did not start: ${firstLine(started.stderr) || `exit ${started.code}`}.`);
1039
+ }
1040
+ await this.#unpack(to, c.tool, createReadStream(carried));
1041
+ }
1042
+ this.#store.patch(to, { step: 'Giving it the same accesses' });
1043
+ await this.copyRights(from, to);
1044
+ this.#holding.delete(to);
1045
+ if (!this.#store.get(to)) return undefined;
1046
+ this.#store.patch(to, { phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, error: undefined });
1047
+ this.ready(to);
1048
+ return undefined;
1049
+ } catch (error) {
1050
+ this.#holding.delete(to);
1051
+ if (this.#store.get(to)) this.#store.patch(to, { phase: 'failed', step: undefined, progress: undefined, buildingSince: undefined, error: `Not copied: ${String(error?.message ?? error).replace(/\.?$/, '.')} Its original is untouched; erase this copy.` });
1052
+ return undefined;
1053
+ } finally {
1054
+ rmSync(dir, { recursive: true, force: true });
1055
+ if (woke) await this.sleep(from).catch(() => {});
1056
+ }
1057
+ }
1058
+
975
1059
  /* MOVED INTO A SHARED MACHINE (#221, 12-11, its owner's ask: put existing conversations together). From a
976
1060
  machine of its own: its tool's state carried (state.keep, as an export), its machine stopped -- kept until the
977
1061
  end, to go back to -- its place made in the shared machine as for a new one, the state put back in its home,
@@ -0,0 +1,28 @@
1
+ /* A COPY'S WORK FOLDER (conversations.copy, #221): made from its original's, here, as the files are -- its
2
+ * chat with it (.parley's thread, its read marks, its attachments), the AI's files, all of /work -- but never
3
+ * what belongs to the original alone:
4
+ * .docket its reminders and what woke it: they would fire twice;
5
+ * .tether, .binder its asks to the keepers and their answers, being answered: the copy asks its own;
6
+ * .parley's live files its pulse, its voice boxes, its restart asked, its program (put again by the server).
7
+ * Only plain files, folders and links: anything else (a socket, a pipe) is no work. Its copy keeps their times. */
8
+ import { cp, lstat } from 'node:fs/promises';
9
+ import { relative, sep } from 'node:path';
10
+
11
+ export const NOT_COPIED = Object.freeze(['.docket', '.tether', '.binder', '.parley/pulse.json', '.parley/speakers.json', '.parley/restart-asked', '.parley/server.mjs']);
12
+
13
+ /* Whether a path of the work folder (relative, '' for the folder itself) is copied. */
14
+ export function copied(path) {
15
+ const p = path.split(sep).join('/');
16
+ return !NOT_COPIED.some((x) => p === x || p.startsWith(`${x}/`));
17
+ }
18
+
19
+ export async function copyWorkFolder(from, to) {
20
+ await cp(from, to, {
21
+ recursive: true, force: true, preserveTimestamps: true, verbatimSymlinks: true, errorOnExist: false,
22
+ filter: async (source) => {
23
+ if (!copied(relative(from, source))) return false;
24
+ const s = await lstat(source).catch(() => null);
25
+ return Boolean(s && (s.isFile() || s.isDirectory() || s.isSymbolicLink()));
26
+ },
27
+ });
28
+ }
package/server/events.mjs CHANGED
@@ -33,6 +33,7 @@ const SAID = [
33
33
  [/^\/api\/conversations\/([^/]+)\/machine\/cancel$/, 'machine', (m) => `Machine of ${m[1]}: the size kept for its wake given up`],
34
34
  [/^\/api\/conversations\/([^/]+)\/sleep$/, 'machine', (m) => `Machine of ${m[1]} put to sleep`],
35
35
  [/^\/api\/conversations\/([^/]+)\/rebuild$/, 'machine', (m) => `Machine of ${m[1]} built again`],
36
+ [/^\/api\/conversations\/([^/]+)\/copy$/, 'conversation', (m, b) => `${m[1]} copied${b?.machine ? ` into the shared machine ${clip(String(b.machine), 32)}` : ''}`],
36
37
  [/^\/api\/conversations\/([^/]+)\/into-machine$/, 'machine', (m, b) => `${m[1]} moved into the shared machine ${clip(String(b?.machine ?? '?'), 32)}`],
37
38
  [/^\/api\/conversations\/([^/]+)\/network$/, 'machine', (m, b) => `${m[1]} ${b.online ? 'put online' : 'put offline'}`],
38
39
  [/^\/api\/conversations\/([^/]+)\/share$/, 'access', (m) => `A pairing code made for ${m[1]}`],
package/server/main.mjs CHANGED
@@ -92,6 +92,7 @@ import { Features, handleFeatures, cached } from './features.mjs';
92
92
  import { ApiKeys, handleExternal, handleApiKeys, statusOf } from './apikeys.mjs';
93
93
  import { RelayJoin, handleRelayJoin, RELAY_JOIN_PATH } from './relayjoin.mjs';
94
94
  import { WebSocketServer } from 'ws';
95
+ import { copyWorkFolder } from './copywork.mjs';
95
96
 
96
97
  const ROOT = fileURLToPath(new URL('..', import.meta.url));
97
98
  const MAINTENANCE = 'deploy/maintenance.html';
@@ -666,6 +667,21 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
666
667
  reclaim: (name) => { events.add({ kind: 'machine', text: `Machine of ${name}: memory reclaimed (it was asleep but still held RAM)`, conversation: name }); return vms.reclaim(name).then((r) => (r.stdout || '').trim()); },
667
668
  say: (name, text) => { try { talk.event(name, { kind: 'machine-problem', text, tone: 'warn', topic: 'Machine' }); } catch { /* its chat may be off */ } } });
668
669
  all.room = (ask) => capacity.check(ask);
670
+ /* A COPY (conversations.copy): its work folder from its original's, host side -- what is its alone left out
671
+ (its reminders, its pending asks to the keepers, its devices, its chat's live files) -- then the same accesses. */
672
+ all.copyWork = (from, to) => copyWorkFolder(folders.workFolder(from), folders.workFolder(to));
673
+ all.copyRights = async (from, to) => {
674
+ for (const r of folders.of(from)) {
675
+ if (r.access === 'write') gitKeeper?.beforeWriter(r.name, to, true);
676
+ await folders.attach(to, r.name, r.access);
677
+ }
678
+ for (const s of secrets.of(from)) secrets.attach(to, s, true);
679
+ tethers?.copyGrants(from, to);
680
+ binders?.copyGrants(from, to);
681
+ if (talk.isOn(from)) await talk.set(to, true).catch(() => {});
682
+ const lines = guide.lines(from);
683
+ if (lines.length) await guide.setLines(to, lines).catch(() => {});
684
+ };
669
685
  /* A tool that ended cut for lack of memory: said in the events, to the owner, and in its chat. */
670
686
  all.onToolExit = (name, report) => {
671
687
  if (!report?.oom?.length) return;
@@ -309,6 +309,19 @@ export class Tethers {
309
309
  await conn.run(verb, target, {}, { agent: 'person:owner', secret: async () => password });
310
310
  }
311
311
 
312
+ /* A COPY of a conversation (#221) is given what its original was given: each target at the same level, with
313
+ the same allow rules. Not a device or a voice box: those are offered with the original itself. */
314
+ copyGrants(from, to) {
315
+ const store = this.#keeper.store;
316
+ for (const t of store.targets()) {
317
+ if (t.kind === 'device' || t.kind === 'voicebox') continue;
318
+ const g = t.grants?.[`${AGENT}${from}`];
319
+ if (!g?.level) continue;
320
+ store.grant(t.id, `${AGENT}${to}`, g.level);
321
+ for (const rule of g.rules ?? []) { try { store.allow(t.id, `${AGENT}${to}`, rule); } catch { /* a rule no longer valid: left out */ } }
322
+ }
323
+ }
324
+
312
325
  /* What each conversation was given: { name: count } -- the targets it may use. */
313
326
  given() {
314
327
  const out = {};
package/server/tools.mjs CHANGED
@@ -18,14 +18,16 @@ const ARCHIVE = `node-${NODE_VERSION}-linux-x64.tar.xz`;
18
18
  const TMP = `/tmp/${ARCHIVE}`;
19
19
  const APT = ['sudo', '-n', 'env', 'DEBIAN_FRONTEND=noninteractive', 'apt-get'];
20
20
 
21
- /* A step is { argv, input? }: `input` goes to standard input. */
21
+ /* A step is { argv, input? }: `input` goes to standard input. Every one as root (sudo): in a shared machine a
22
+ step without sudo runs as the conversation's own user, behind its door, with its own /tmp -- the archive
23
+ fetched there would not be the one root unpacks (#221, 13-11: "tar: Error is not recoverable"). */
22
24
  export const NODE_STEPS = [
23
25
  { argv: [...APT, 'update', '-q'] },
24
26
  { argv: [...APT, 'install', '-y', '-q', '--no-install-recommends', 'curl', 'xz-utils', 'ca-certificates'] },
25
- { argv: ['curl', '--proto', '=https', '--tlsv1.2', '-fsSL', '--max-time', '600', '-o', TMP, `https://nodejs.org/dist/${NODE_VERSION}/${ARCHIVE}`] },
26
- { argv: ['sha256sum', '-c', '-'], input: `${NODE_SHA256} ${TMP}\n` },
27
+ { argv: ['sudo', '-n', 'curl', '--proto', '=https', '--tlsv1.2', '-fsSL', '--max-time', '600', '-o', TMP, `https://nodejs.org/dist/${NODE_VERSION}/${ARCHIVE}`] },
28
+ { argv: ['sudo', '-n', 'sha256sum', '-c', '-'], input: `${NODE_SHA256} ${TMP}\n` },
27
29
  { argv: ['sudo', '-n', 'tar', '-xJf', TMP, '-C', '/usr/local', '--strip-components=1', '--no-same-owner'] },
28
- { argv: ['rm', '-f', TMP] },
30
+ { argv: ['sudo', '-n', 'rm', '-f', TMP] },
29
31
  ];
30
32
 
31
33
  /* "npm-writable": what npm installs globally becomes the machine user's, so
package/web/app.js CHANGED
@@ -2991,6 +2991,14 @@
2991
2991
  if (!$('into-shared-name').value && names.length) $('into-shared-name').value = names[0];
2992
2992
  paintIntoShared();
2993
2993
  }
2994
+ /* A copy of it (#221): offered to any that is ready. */
2995
+ $('copy-it').hidden = DEVICE || !here || here.phase !== 'ready';
2996
+ if (!$('copy-it').hidden && ![$('copy-title'), $('copy-machine')].includes(document.activeElement)) {
2997
+ if ($('copy-it').dataset.of !== here.name) { $('copy-it').dataset.of = here.name; $('copy-title').value = `${here.title ?? here.name} (copy)`; $('copy-where').value = ''; $('copy-machine').value = ''; }
2998
+ const names = [...new Set(conversations.map((x) => x.sharedMachine).filter(Boolean))].sort();
2999
+ $('machine-names').replaceChildren(...names.map((n) => Object.assign(document.createElement('option'), { value: n })));
3000
+ paintCopy();
3001
+ }
2994
3002
  if (sharedHere && document.activeElement !== $('shared-memory')) {
2995
3003
  const inIt = conversations.filter((x) => x.sharedMachine === here.sharedMachine);
2996
3004
  const floor = Math.max(1024, ...inIt.map((x) => x.memoryMb ?? 0)); const now = here.machineMb ?? floor;
@@ -3137,6 +3145,38 @@
3137
3145
  catch (error) { show(error.message, 'Back', enter); }
3138
3146
  }, resume);
3139
3147
  });
3148
+ /* A COPY: in its own machine, or a shared one (there already, or new: its memory chosen). Work on its own disk: kept here first. */
3149
+ function paintCopy() {
3150
+ const here = conversations.find((x) => x.name === current);
3151
+ const shared = $('copy-where').value === 'shared';
3152
+ const known = conversations.some((x) => x.sharedMachine && x.sharedMachine === $('copy-machine').value.trim());
3153
+ $('copy-machine').hidden = !shared; $('copy-mb').hidden = !shared || known;
3154
+ const onDisk = here?.work === 'disk';
3155
+ $('copy-hint').textContent = onDisk ? 'Keep its files here first (Where the tool works)' : 'Work, AI memory and accesses · the original untouched';
3156
+ $('copy-apply').disabled = onDisk;
3157
+ }
3158
+ $('copy-where').addEventListener('change', () => { if ($('copy-where').value === 'shared' && !$('copy-machine').value) $('copy-machine').value = [...new Set(conversations.map((x) => x.sharedMachine).filter(Boolean))].sort()[0] ?? ''; paintCopy(); });
3159
+ $('copy-machine').addEventListener('input', () => paintCopy());
3160
+ $('copy-it').addEventListener('submit', (event) => {
3161
+ event.preventDefault();
3162
+ const name = current;
3163
+ const here = conversations.find((x) => x.name === name);
3164
+ if (!here) return;
3165
+ const title = $('copy-title').value.trim() || `${here.title ?? here.name} (copy)`;
3166
+ const shared = $('copy-where').value === 'shared';
3167
+ const machine = shared ? $('copy-machine').value.trim() : '';
3168
+ if (shared && !machine) { $('panel-error').textContent = 'Name the shared machine first.'; $('panel-error').hidden = false; return; }
3169
+ const known = shared && conversations.some((x) => x.sharedMachine === machine);
3170
+ const machineMb = shared && !known ? Number($('copy-mb').value) : undefined;
3171
+ leavePanel();
3172
+ const resume = socket && state.dataset.state === 'live' ? () => { notice.hidden = true; focusTerminal(); } : enter;
3173
+ show(`Make « ${title} », a copy of ${here.title ?? here.name}${shared ? ` in the shared machine « ${machine} »${known ? '' : ` (new, ${sizeWords(machineMb)})`}` : ' in a machine of its own'}? Its work, its AI's memory and its accesses are copied; not its devices nor its reminders. The original is untouched.`,
3174
+ 'Copy it', async () => {
3175
+ show('Copying...'); $('notice-spin').hidden = false;
3176
+ try { await post(`${API}/conversations/${encodeURIComponent(name)}/copy`, { title, ...(machine ? { machine } : {}), ...(machineMb ? { machineMb } : {}) }); await refresh(); resume(); }
3177
+ catch (error) { show(error.message, 'Back', enter); }
3178
+ }, resume);
3179
+ });
3140
3180
  $('shared-size').addEventListener('submit', (event) => {
3141
3181
  event.preventDefault();
3142
3182
  const name = current;
package/web/index.html CHANGED
@@ -243,6 +243,17 @@
243
243
  <p class="hint" id="into-shared-hint">Trial · work and tool state come along</p>
244
244
  <div class="row"><button type="submit" id="into-shared-apply">Move...</button></div>
245
245
  </form>
246
+ <!-- A COPY OF IT (#221): its work, its AI's memory, its accesses; the original untouched. -->
247
+ <form id="copy-it" autocomplete="off" hidden>
248
+ <label for="copy-title">A copy of it</label>
249
+ <input id="copy-title" maxlength="60">
250
+ <label for="copy-where">Its machine</label>
251
+ <select id="copy-where"><option value="">Its own</option><option value="shared">A shared machine</option></select>
252
+ <input id="copy-machine" maxlength="32" list="machine-names" placeholder="assistants" spellcheck="false" autocapitalize="off" autocomplete="off" aria-label="Shared machine" hidden>
253
+ <select id="copy-mb" aria-label="Its memory" hidden><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>
254
+ <p class="hint" id="copy-hint">Work, AI memory and accesses · the original untouched</p>
255
+ <div class="row"><button type="submit" id="copy-apply">Copy...</button></div>
256
+ </form>
246
257
  <div id="work-box">
247
258
  <div class="panel-top"><b>Where the tool works</b></div>
248
259
  <p id="work-now" class="hint"><span><span id="work-now-text"></span></span><span id="work-now-why" class="tip" hidden></span></p>
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, #shared-size, #into-shared { display: flex; flex-direction: column; gap: 6px; max-width: 30rem; }
502
- #machine-size label, #shared-size label, #into-shared label { font-size: .8125rem; color: var(--ink2); }
503
- #machine-size select, #shared-size select, #into-shared :is(select, input) { 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, #into-shared, #copy-it { display: flex; flex-direction: column; gap: 6px; max-width: 30rem; }
502
+ #machine-size label, #shared-size label, #into-shared label, #copy-it label { font-size: .8125rem; color: var(--ink2); }
503
+ #machine-size select, #shared-size select, #into-shared :is(select, input), #copy-it :is(select, input) { 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,12 +1909,13 @@ 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 :is(#machine-size, #shared-size, #into-shared) { 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, #into-shared) > label { font-size: .875rem; font-weight: 600; color: var(--ink); }
1914
- #panel :is(#machine-size, #shared-size, #into-shared) > :is(p, .row) { grid-column: 1 / -1; }
1915
- #panel :is(#machine-size, #shared-size, #into-shared) > .row { justify-content: flex-end; }
1916
- #shared-size[hidden], #into-shared[hidden], #into-shared [hidden] { display: none; }
1917
- @media (max-width: 560px) { #panel :is(#machine-size, #into-shared) { grid-template-columns: minmax(0, 1fr); } }
1912
+ #panel :is(#machine-size, #shared-size, #into-shared, #copy-it) { 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, #into-shared, #copy-it) > label { font-size: .875rem; font-weight: 600; color: var(--ink); }
1914
+ #panel :is(#machine-size, #shared-size, #into-shared, #copy-it) > :is(p, .row) { grid-column: 1 / -1; }
1915
+ #panel :is(#machine-size, #shared-size, #into-shared, #copy-it) > .row { justify-content: flex-end; }
1916
+ #shared-size[hidden], #into-shared[hidden], #into-shared [hidden], #copy-it[hidden], #copy-it [hidden] { display: none; }
1917
+ #panel #copy-it > :is(#copy-machine, #copy-mb) { grid-column: 2; }
1918
+ @media (max-width: 560px) { #panel :is(#machine-size, #into-shared, #copy-it) > :is(#copy-machine, #copy-mb) { grid-column: 1; } #panel :is(#machine-size, #into-shared, #copy-it) { grid-template-columns: minmax(0, 1fr); } }
1918
1919
  /* A chapter whose body is one block (Updates, Network): its pieces are the rows, not the block. */
1919
1920
  :is(#settings, #panel) .chapter-body > :is(#updates, #wifi) { padding: 0; }
1920
1921
  :is(#updates, #wifi) > * { margin: 0; padding: 12px 16px; }