clavarium 0.2.423-next.1 → 0.2.426-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.423-next.1",
3
+ "version": "0.2.426-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.423-next.1",
9
+ "version": "0.2.426-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.423-next.1",
3
+ "version": "0.2.426-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.",
@@ -21,6 +21,8 @@ import { join } from 'node:path';
21
21
  export const SESSION = 'main';
22
22
  export const STOP_DELAY_MS = 60_000;
23
23
  const STEP_MS = 15 * 60_000;
24
+ /* A size in words: 840 KB, 12 MB, 1.4 GB. */
25
+ const sizeWords = (bytes) => (bytes >= 1024 ** 3 ? `${(bytes / 1024 ** 3).toFixed(1)} GB` : bytes >= 1024 ** 2 ? `${Math.round(bytes / 1024 ** 2)} MB` : `${Math.round(bytes / 1024)} KB`);
24
26
  /* The door of a conversation in a shared machine (#221), put in the machine by the server. */
25
27
  export const DOOR = new URL('../config/machine/clavarium-enter', import.meta.url);
26
28
  /* The most programs one conversation may run in a shared machine. */
@@ -102,7 +104,7 @@ const sizeSaid = (c, asked = {}) => {
102
104
  const firstLine = (text) => String(text ?? '').trim().split('\n').filter(Boolean).pop()?.slice(0, 200) ?? '';
103
105
 
104
106
  export class Conversations {
105
- #layout; #store; #vms; #tools; #stopDelayMs; #timers = new Map(); #watching = new Map(); #fresh = new Set(); #mountAgain = new Set(); #holding = new Set(); #uid; #gid;
107
+ #layout; #store; #vms; #tools; #stopDelayMs; #timers = new Map(); #watching = new Map(); #fresh = new Set(); #mountAgain = new Set(); #holding = new Set(); #borrowed = new Set(); #uid; #gid;
106
108
  /* THE ONE ACTION RUNNING ON EACH MACHINE (machineAction), by name: a start, a stop, a restart, a
107
109
  sleep, a resize, a force stop. A second one is refused while it runs; Force stop ends it and
108
110
  takes its place. */
@@ -1026,13 +1028,22 @@ export class Conversations {
1026
1028
  const built = this.#store.get(to);
1027
1029
  if (!built) return undefined; /* erased meanwhile */
1028
1030
  if (built.phase === 'failed') throw new Error(built.error ?? 'its machine could not be made.');
1031
+ /* Said as it goes, once a second at most: a long copy is seen moving (13-11, "on ne sait pas si ça marche"). */
1032
+ let said = 0;
1033
+ const say = (step) => { const now = Date.now(); if (now - said < 1000) return; said = now; if (this.#store.get(to)) this.#store.patch(to, { step }); };
1029
1034
  this.#store.patch(to, { step: 'Copying its work' });
1030
- await this.copyWork(from, to);
1035
+ const work = await this.copyWork(from, to, (p) => say(`Copying its work: ${p.files} files, ${sizeWords(p.bytes)}`));
1036
+ if (work?.files !== undefined) this.#store.patch(to, { step: `Copying its work: ${work.files} files, ${sizeWords(work.bytes)}, done` });
1031
1037
  if (tool.state) {
1032
1038
  this.#store.patch(to, { step: `Copying ${tool.label}'s memory` });
1033
1039
  const state = await this.#vms.state(from, { fresh: true }).catch(() => undefined);
1034
1040
  if (state !== 'Running') {
1041
+ this.#store.patch(to, { step: `Copying ${tool.label}'s memory: waking its original` });
1035
1042
  await this.room({ kind: 'start', name: from, memoryMb: Number(c.memoryMb) || tool.memoryMb });
1043
+ /* Woken outside a wake, it is still marked asleep: borrowed, so that the server's sweep of sleepers
1044
+ holding memory (capacity.mjs, reclaimSleepers) does not put it back to sleep while it is read --
1045
+ the reading would end cut (13-11: exit 255). */
1046
+ this.#borrowed.add(from);
1036
1047
  const started = await this.#vms.start(from);
1037
1048
  if (started.code !== 0) throw new Error(`its original's machine did not start: ${firstLine(started.stderr) || `exit ${started.code}`}.`);
1038
1049
  woke = true;
@@ -1043,8 +1054,11 @@ export class Conversations {
1043
1054
  let code; let child;
1044
1055
  for (let attempt = 0; attempt < 2 && code !== 0; attempt++) {
1045
1056
  if (attempt) await new Promise((ok) => setTimeout(ok, 10_000));
1057
+ this.#store.patch(to, { step: `Copying ${tool.label}'s memory` });
1046
1058
  const out = await this.exportState(from);
1047
1059
  child = out.child;
1060
+ let read = 0;
1061
+ out.stream.on('data', (d) => { read += d.length; say(`Copying ${tool.label}'s memory: ${sizeWords(read)} read`); });
1048
1062
  const failed = new Promise((ok) => child.on('error', () => ok(-1)));
1049
1063
  const file = createWriteStream(carried, { mode: 0o600 });
1050
1064
  out.stream.pipe(file);
@@ -1057,6 +1071,7 @@ export class Conversations {
1057
1071
  const started = await this.#vms.start(to);
1058
1072
  if (started.code !== 0) throw new Error(`its machine did not start: ${firstLine(started.stderr) || `exit ${started.code}`}.`);
1059
1073
  }
1074
+ this.#store.patch(to, { step: `Putting ${tool.label}'s memory in the copy` });
1060
1075
  await this.#unpack(to, c.tool, createReadStream(carried));
1061
1076
  }
1062
1077
  this.#store.patch(to, { step: 'Giving it the same accesses' });
@@ -1073,6 +1088,7 @@ export class Conversations {
1073
1088
  } finally {
1074
1089
  rmSync(dir, { recursive: true, force: true });
1075
1090
  if (woke) await this.sleep(from).catch(() => {});
1091
+ this.#borrowed.delete(from);
1076
1092
  }
1077
1093
  }
1078
1094
 
@@ -1634,7 +1650,8 @@ export class Conversations {
1634
1650
  awake() { return this.#store.all().filter((c) => c.phase === 'ready' && c.asleep !== true && c.stopped !== true).map((c) => c.name); }
1635
1651
  /* Put to sleep, and nothing else: not one being built (02-11: a reset machine was taken for a sleeper and
1636
1652
  suspended mid-build), not a failed one. */
1637
- asleep() { return this.#store.all().filter((c) => c.phase === 'ready' && c.asleep === true).map((c) => c.name); }
1653
+ /* (One woken the time a copy reads it -- #borrowed -- is not asleep then: its memory is never "reclaimed" under it.) */
1654
+ asleep() { return this.#store.all().filter((c) => c.phase === 'ready' && c.asleep === true && !this.#borrowed.has(c.name)).map((c) => c.name); }
1638
1655
 
1639
1656
  /* Whether the machine of a conversation runs right now. */
1640
1657
  async running(name) { return (await this.#vms.state(name)) === 'Running'; }
@@ -16,13 +16,18 @@ export function copied(path) {
16
16
  return !NOT_COPIED.some((x) => p === x || p.startsWith(`${x}/`));
17
17
  }
18
18
 
19
- export async function copyWorkFolder(from, to) {
19
+ /* `onProgress({ files, bytes })`: how far, as it goes (each file as it is taken) -- a long copy says so. */
20
+ export async function copyWorkFolder(from, to, onProgress) {
21
+ const done = { files: 0, bytes: 0 };
20
22
  await cp(from, to, {
21
23
  recursive: true, force: true, preserveTimestamps: true, verbatimSymlinks: true, errorOnExist: false,
22
24
  filter: async (source) => {
23
25
  if (!copied(relative(from, source))) return false;
24
26
  const s = await lstat(source).catch(() => null);
25
- return Boolean(s && (s.isFile() || s.isDirectory() || s.isSymbolicLink()));
27
+ const ok = Boolean(s && (s.isFile() || s.isDirectory() || s.isSymbolicLink()));
28
+ if (ok && s.isFile()) { done.files += 1; done.bytes += s.size; onProgress?.({ ...done }); }
29
+ return ok;
26
30
  },
27
31
  });
32
+ return done;
28
33
  }
package/server/main.mjs CHANGED
@@ -669,7 +669,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
669
669
  all.room = (ask) => capacity.check(ask);
670
670
  /* A COPY (conversations.copy): its work folder from its original's, host side -- what is its alone left out
671
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));
672
+ all.copyWork = (from, to, onProgress) => copyWorkFolder(folders.workFolder(from), folders.workFolder(to), onProgress);
673
673
  all.copyRights = async (from, to) => {
674
674
  for (const r of folders.of(from)) {
675
675
  if (r.access === 'write') gitKeeper?.beforeWriter(r.name, to, true);
package/web/app.js CHANGED
@@ -368,7 +368,9 @@
368
368
  const owner = conversations.find((x) => x.name === panel.of.split('/')[0]);
369
369
  paintMlive($('notice-mlive'), owner);
370
370
  const mline = mstepLine(owner?.machine);
371
- $('notice-text').textContent = mline || `${stepNow(p, tool)}${s >= 180 ? ` \u2014 ${usualFor(p.kind, s)}` : ''}`;
371
+ /* A copy or a move, past its machine's build: what it does now (its work, its tool's memory), said as the server says it. */
372
+ const carrying = owner?.phase === 'building' && /^(Copying|Taking|Putting|Giving)\b/.test(owner.step ?? '') ? owner.step : '';
373
+ $('notice-text').textContent = mline || (carrying ? `${carrying}\u2026` : `${stepNow(p, tool)}${s >= 180 ? ` \u2014 ${usualFor(p.kind, s)}` : ''}`);
372
374
  return true;
373
375
  };
374
376
  /* Shown, or brought up to date when it is shown already (its wheel keeps turning). */
@@ -1428,7 +1430,7 @@
1428
1430
  const agentWho = (c) => [c.chatName, c.toolLabel ?? c.tool].filter(Boolean).join(' \u00b7 ');
1429
1431
  function convModel(c, told = false) {
1430
1432
  /* Under way: the step the panel shows, in its words (the tool named once). */
1431
- const under = c.progress && ['building', 'restarting', 'ready'].includes(c.phase) ? stepNow(c.progress, c.toolLabel) : '';
1433
+ const under = c.phase === 'building' && /^(Copying|Taking|Putting|Giving)\b/.test(c.step ?? '') ? c.step : c.progress && ['building', 'restarting', 'ready'].includes(c.phase) ? stepNow(c.progress, c.toolLabel) : '';
1432
1434
  /* What it is doing, when it says something: its tool is not named on every row. */
1433
1435
  const now = under || (holds(c) && c.phase !== 'building' ? (c.progress.kind === 'build' ? uiSaid('set-list-starting', 'starting') : uiSaid('set-list-restarting', 'restarting')) : c.phase === 'ready' ? (c.asleep ? uiSaid('set-list-asleep', 'asleep') : '') : c.phase === 'building' ? (c.step ?? 'building') : c.phase === 'moving' ? uiSaid('set-list-moving', 'moving its work') : c.phase === 'restarting' ? uiSaid('set-list-restarting', 'restarting') : uiSaid('set-list-failed', 'failed'));
1434
1436
  /* The line of its tool only when it says something: under way, asleep, failed -- not "Claude Code" again and again. */
package/web/style.css CHANGED
@@ -3057,3 +3057,6 @@ button.kit-switch[aria-checked="true"]::after { left: 18px; background: var(--ok
3057
3057
  html:not([data-door="device"]) #room > header .views button { gap: 4px; padding-inline: 7px; }
3058
3058
  html:not([data-door="device"]) #room > header .views .count { min-width: 1.2em; padding: 1px 4px; }
3059
3059
  }
3060
+ /* At hand (13-11): a switch's name never under its buttons -- the name keeps its width, the buttons wrap. */
3061
+ .hand-switches .set-row > .set-what { flex: none; }
3062
+ .hand-switches .set-row > .set-control { flex: 0 1 auto; min-width: 0; flex-wrap: wrap; justify-content: flex-end; }