clavarium 0.2.436-next.1 → 0.2.437-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.436-next.1",
3
+ "version": "0.2.437-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.436-next.1",
9
+ "version": "0.2.437-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.436-next.1",
3
+ "version": "0.2.437-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,7 +14,7 @@ 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, createReadStream, createWriteStream, mkdtempSync, rmSync } from 'node:fs';
17
+ import { readFileSync, createReadStream, createWriteStream, mkdtempSync, rmSync, statSync, copyFileSync } from 'node:fs';
18
18
  import { tmpdir } from 'node:os';
19
19
  import { join } from 'node:path';
20
20
 
@@ -938,7 +938,10 @@ export class Conversations {
938
938
  from its machine, a manifest first (clavarium-conversation.json: its tool, its name, its size). Nothing
939
939
  of the tool is known here: any tool that says where its state is can be exported, imported, moved.
940
940
  The machine must run (its home is in it). -> { name: the file's name, stream } */
941
- async exportState(name) {
941
+ /* `toWork` (14-11): the archive written into its own work folder (/work/.clavarium-carry/<toWork>.tgz), that
942
+ the server reads on its side, rather than sent out through the VM manager's output -- which stalled for good
943
+ past ~36 KB on the owner's server. Its output is then empty. */
944
+ async exportState(name, { toWork } = {}) {
942
945
  const c = this.#store.get(name);
943
946
  if (!c) throw new Refusal(404, 'No such conversation.');
944
947
  const tool = this.#tools.find((t) => t.id === c.tool);
@@ -949,13 +952,15 @@ export class Conversations {
949
952
  (a path it has not made yet left out), the cache left out. */
950
953
  /* (Its paths are plain -- letters, digits, . _ / - -- checked by tools.mjs: given as words.) */
951
954
  /* A reading of an earlier try that never ended (14-11: three left, each holding its pipe): ended first. */
952
- const script = 'for p in $(pgrep -f "^tar -czf - --warning=no-file-changed -C /tmp/"); do kill $p 2>/dev/null; done; m=$(mktemp -d) || exit 2; printf "%s" "$1" > "$m/clavarium-conversation.json"; '
955
+ const script = 'for p in $(pgrep -f "^tar -czf .* clavarium-conversation.json"); do kill $p 2>/dev/null; done; m=$(mktemp -d) || exit 2; printf "%s" "$1" > "$m/clavarium-conversation.json"; '
953
956
  + '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; '
954
- + 'rc=0; tar -czf - --warning=no-file-changed -C "$m" clavarium-conversation.json -C "$HOME" $ex $ks || rc=$?; rm -rf "$m"; '
957
+ + 'out=-; if [ -n "$4" ]; then mkdir -p /work/.clavarium-carry && out="/work/.clavarium-carry/$4.tgz"; fi; '
958
+ + 'rc=0; tar -czf "$out" --warning=no-file-changed -C "$m" clavarium-conversation.json -C "$HOME" $ex $ks || rc=$?; rm -rf "$m"; '
955
959
  /* 1: a file changed while read (its tool writing its log as it is read, 14-11: a live Claude Code): the
956
960
  archive is whole all the same -- what was there, read; only a real error (2) fails. */
957
961
  + '[ "$rc" -le 1 ]';
958
- const argv = this.#vms.execArgv(name, ['sh', '-c', script, 'export', manifest, tool.state.skip.join(' '), tool.state.keep.join(' ')]);
962
+ const id = typeof toWork === 'string' && /^[a-z0-9-]{1,64}$/.test(toWork) ? toWork : '';
963
+ const argv = this.#vms.execArgv(name, ['sh', '-c', script, 'export', manifest, tool.state.skip.join(' '), tool.state.keep.join(' '), id]);
959
964
  const child = spawn(argv[0], argv.slice(1), { stdio: ['ignore', 'pipe', 'pipe'] });
960
965
  /* What it said when it failed: kept short, for the message that says why (a copy, a move). */
961
966
  child.said = '';
@@ -1065,10 +1070,19 @@ export class Conversations {
1065
1070
  for (let attempt = 0; attempt < 2 && code !== 0; attempt++) {
1066
1071
  if (attempt) await new Promise((ok) => setTimeout(ok, 10_000));
1067
1072
  this.#store.patch(to, { step: `Copying ${tool.label}'s memory` });
1068
- const out = await this.exportState(from);
1073
+ /* Through its work folder when there is one here (14-11): its folders put back first -- a machine
1074
+ started outside an opening may have them loose -- then its archive written there, its size read
1075
+ on this side as it grows. Else, as before, through the VM manager's output. */
1076
+ const workDir = c.work === 'kept' && typeof this.workFolder === 'function' ? this.workFolder(from) : '';
1077
+ const carryId = workDir ? `copy-${to}-${Date.now()}` : '';
1078
+ const inWork = carryId ? join(workDir, '.clavarium-carry', `${carryId}.tgz`) : '';
1079
+ if (inWork) await Promise.race([Promise.resolve().then(() => this.mounted(from, true)).catch(() => {}), new Promise((r) => { setTimeout(r, MOUNTED_MS).unref?.(); })]);
1080
+ const out = await this.exportState(from, inWork ? { toWork: carryId } : {});
1069
1081
  child = out.child;
1070
1082
  let read = 0; let lastAt = Date.now(); let stalled = false;
1071
- out.stream.on('data', (d) => { read += d.length; lastAt = Date.now(); say(`Copying ${tool.label}'s memory: ${sizeWords(read)} read`); });
1083
+ const grew = (n) => { if (n <= read) return; read = n; lastAt = Date.now(); say(`Copying ${tool.label}'s memory: ${sizeWords(read)} read`); };
1084
+ if (inWork) out.stream.resume(); else out.stream.on('data', (d) => grew(read + d.length));
1085
+ const sizing = inWork ? setInterval(() => { try { grew(statSync(inWork).size); } catch { /* not there yet */ } }, 1000) : null;
1072
1086
  /* Nothing comes for a while: said, with how long; for too long, the reading is ended and why said --
1073
1087
  never an endless wait nobody can read (14-11: stuck at "36 KB read"). */
1074
1088
  /* Quiet for 30 s: its machine asked, once, what its reading does -- the file it is on and its state
@@ -1090,14 +1104,18 @@ export class Conversations {
1090
1104
  if (quiet >= 15) say(`Copying ${tool.label}'s memory: ${sizeWords(read)} read, nothing more for ${quiet} s`);
1091
1105
  }, 5000);
1092
1106
  const failed = new Promise((ok) => child.on('error', () => ok(-1)));
1093
- const file = createWriteStream(carried, { mode: 0o600 });
1094
- out.stream.pipe(file);
1095
- code = await Promise.race([new Promise((ok) => child.on('close', ok)), failed]).finally(() => clearInterval(watch));
1107
+ const file = inWork ? null : createWriteStream(carried, { mode: 0o600 });
1108
+ if (file) out.stream.pipe(file);
1109
+ code = await Promise.race([new Promise((ok) => child.on('close', ok)), failed]).finally(() => { clearInterval(watch); if (sizing) clearInterval(sizing); });
1110
+ /* Written in its work folder: taken from there, and the folder left as it was. */
1111
+ if (inWork) {
1112
+ try { if (code === 0 && !stalled) { copyFileSync(inWork, carried); grew(statSync(carried).size); } } finally { rmSync(inWork, { force: true }); }
1113
+ }
1096
1114
  if (stalled) {
1097
1115
  const now = await this.#vms.state(from, { fresh: true }).catch(() => undefined);
1098
1116
  throw new Error(`its original stopped sending its tool's memory: ${sizeWords(read)} read, then nothing for ${COPY_QUIET_MS / 60_000} min, its machine ${now ?? 'unreadable'} (see its job's log in Settings)`);
1099
1117
  }
1100
- await new Promise((ok) => (file.writableFinished ? ok() : file.on('finish', ok)));
1118
+ if (file) await new Promise((ok) => (file.writableFinished ? ok() : file.on('finish', ok)));
1101
1119
  if (code !== 255) break;
1102
1120
  }
1103
1121
  if (code !== 0) throw new Error(`its tool's memory could not be read (exit ${code}${firstLine(child.said) ? `: ${firstLine(child.said)}` : ''}).`);
@@ -8,7 +8,7 @@
8
8
  import { cp, lstat } from 'node:fs/promises';
9
9
  import { relative, sep } from 'node:path';
10
10
 
11
- export const NOT_COPIED = Object.freeze(['.docket', '.tether', '.binder', '.parley/pulse.json', '.parley/speakers.json', '.parley/restart-asked', '.parley/server.mjs']);
11
+ export const NOT_COPIED = Object.freeze(['.docket', '.tether', '.binder', '.clavarium-carry', '.parley/pulse.json', '.parley/speakers.json', '.parley/restart-asked', '.parley/server.mjs']);
12
12
 
13
13
  /* Whether a path of the work folder (relative, '' for the folder itself) is copied. */
14
14
  export function copied(path) {
package/server/main.mjs CHANGED
@@ -674,6 +674,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
674
674
  /* A COPY (conversations.copy): its work folder from its original's, host side -- what is its alone left out
675
675
  (its reminders, its pending asks to the keepers, its devices, its chat's live files) -- then the same accesses. */
676
676
  all.copyWork = (from, to, onProgress) => copyWorkFolder(folders.workFolder(from), folders.workFolder(to), onProgress);
677
+ /* Where a conversation's work folder is on this side: a copy reads its tool's memory through it (14-11). */
678
+ all.workFolder = (name) => folders.workFolder(name);
677
679
  all.copyRights = async (from, to) => {
678
680
  for (const r of folders.of(from)) {
679
681
  if (r.access === 'write') gitKeeper?.beforeWriter(r.name, to, true);