clavarium 0.2.422-next.1 → 0.2.423-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.422-next.1",
3
+ "version": "0.2.423-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.422-next.1",
9
+ "version": "0.2.423-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.422-next.1",
3
+ "version": "0.2.423-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.",
@@ -462,10 +462,14 @@ export class Conversations {
462
462
  const sharing = await this.#vms.execMachine(name, [...SHARING_STEP], { timeoutMs: STEP_MS });
463
463
  if (sharing.code !== 0) return fail('The shared machine could not be prepared for shared folders', sharing);
464
464
  } else if (state !== 'Running') {
465
+ this.#store.patch(name, { step: `Starting the shared machine ${c.sharedMachine}` });
465
466
  const started = await this.#vms.start(name);
466
467
  if (started.code !== 0) return fail('The shared machine did not start', started);
467
468
  }
468
- /* Its door, always the one of this version (put again: an older one is replaced). */
469
+ /* Its door, always the one of this version (put again: an older one is replaced). The page's steps follow
470
+ (preparing, installing): a new shared machine takes minutes, never one frozen "Starting". */
471
+ this.#reach(name, 'preparing');
472
+ this.#store.patch(name, { step: `Opening its door in the shared machine ${c.sharedMachine}` });
469
473
  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 });
470
474
  if (door.code !== 0) return fail('The door of the shared machine could not be put in place', door);
471
475
  this.#store.patch(name, { step: 'Making its place in the shared machine' });
@@ -488,9 +492,11 @@ export class Conversations {
488
492
  const there = tool.steps.length === 0 || (await this.#vms.exec(name, ['sh', '-c', `command -v ${tool.command[0]}`])).code === 0;
489
493
  /* There already: its own steps still (its settings, in its own home), the machine's not. */
490
494
  const steps = there ? tool.steps.filter((s) => s.argv[0] !== 'sudo') : tool.steps;
495
+ this.#reach(name, 'installing', there ? 'came' : undefined);
491
496
  for (const [i, step] of steps.entries()) {
492
497
  if (!this.#store.get(name)) return undefined;
493
498
  this.#store.patch(name, { step: `Installing ${tool.label} (${i + 1}/${steps.length})` });
499
+ this.#reach(name, 'installing', `${i + 1}/${steps.length}`);
494
500
  const r = await this.#vms.exec(name, step.argv, { input: step.input, timeoutMs: STEP_MS });
495
501
  if (r.code !== 0) return fail(`Installing ${tool.label} failed at step ${i + 1}`, r);
496
502
  }
@@ -941,7 +947,10 @@ export class Conversations {
941
947
  + 'ex=""; for a in $2; do ex="$ex --exclude=./$a"; done; ks=""; for a in $3; do if [ -e "$HOME/$a" ]; then ks="$ks ./$a"; fi; done; '
942
948
  + 'tar -czf - -C "$m" clavarium-conversation.json -C "$HOME" $ex $ks; rm -rf "$m"';
943
949
  const argv = this.#vms.execArgv(name, ['sh', '-c', script, 'export', manifest, tool.state.skip.join(' '), tool.state.keep.join(' ')]);
944
- const child = spawn(argv[0], argv.slice(1), { stdio: ['ignore', 'pipe', 'ignore'] });
950
+ const child = spawn(argv[0], argv.slice(1), { stdio: ['ignore', 'pipe', 'pipe'] });
951
+ /* What it said when it failed: kept short, for the message that says why (a copy, a move). */
952
+ child.said = '';
953
+ child.stderr.on('data', (d) => { child.said = (child.said + d).slice(-2000); });
945
954
  return { name: `${name}-${new Date().toISOString().slice(0, 10)}.clavarium.tar.gz`, stream: child.stdout, child };
946
955
  }
947
956
 
@@ -1027,14 +1036,23 @@ export class Conversations {
1027
1036
  const started = await this.#vms.start(from);
1028
1037
  if (started.code !== 0) throw new Error(`its original's machine did not start: ${firstLine(started.stderr) || `exit ${started.code}`}.`);
1029
1038
  woke = true;
1039
+ /* Started is not yet reachable: its commands wait for it, two minutes at most. */
1040
+ for (let i = 0; i < 24 && (await this.#vms.exec(from, ['true'], { timeoutMs: 20_000 }).catch(() => ({ code: 1 }))).code !== 0; i++) await new Promise((ok) => setTimeout(ok, 5000));
1030
1041
  }
1031
- const { stream, child } = await this.exportState(from);
1032
- const failed = new Promise((ok) => child.on('error', () => ok(-1)));
1033
- const file = createWriteStream(carried, { mode: 0o600 });
1034
- stream.pipe(file);
1035
- const code = await Promise.race([new Promise((ok) => child.on('close', ok)), failed]);
1036
- await new Promise((ok) => (file.writableFinished ? ok() : file.on('finish', ok)));
1037
- if (code !== 0) throw new Error(`its tool's memory could not be read (exit ${code}).`);
1042
+ /* Read once more if the VM manager could not reach it (255): a machine just woken may still be settling. */
1043
+ let code; let child;
1044
+ for (let attempt = 0; attempt < 2 && code !== 0; attempt++) {
1045
+ if (attempt) await new Promise((ok) => setTimeout(ok, 10_000));
1046
+ const out = await this.exportState(from);
1047
+ child = out.child;
1048
+ const failed = new Promise((ok) => child.on('error', () => ok(-1)));
1049
+ const file = createWriteStream(carried, { mode: 0o600 });
1050
+ out.stream.pipe(file);
1051
+ code = await Promise.race([new Promise((ok) => child.on('close', ok)), failed]);
1052
+ await new Promise((ok) => (file.writableFinished ? ok() : file.on('finish', ok)));
1053
+ if (code !== 255) break;
1054
+ }
1055
+ if (code !== 0) throw new Error(`its tool's memory could not be read (exit ${code}${firstLine(child.said) ? `: ${firstLine(child.said)}` : ''}).`);
1038
1056
  if ((await this.#vms.state(to, { fresh: true }).catch(() => undefined)) !== 'Running') {
1039
1057
  const started = await this.#vms.start(to);
1040
1058
  if (started.code !== 0) throw new Error(`its machine did not start: ${firstLine(started.stderr) || `exit ${started.code}`}.`);
@@ -1110,7 +1128,7 @@ export class Conversations {
1110
1128
  stream.pipe(file);
1111
1129
  const code = await Promise.race([new Promise((ok) => child.on('close', ok)), failed]);
1112
1130
  await new Promise((ok) => (file.writableFinished ? ok() : file.on('finish', ok)));
1113
- if (code !== 0) return back(`its tool's state could not be taken (exit ${code}).`);
1131
+ if (code !== 0) return back(`its tool's state could not be taken (exit ${code}${firstLine(child.said) ? `: ${firstLine(child.said)}` : ''}).`);
1114
1132
  }
1115
1133
  if (state !== undefined) {
1116
1134
  this.#store.patch(name, { step: 'Stopping its own machine' });