clavarium 0.2.437-next.1 → 0.2.438-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.
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/conversations.mjs +23 -7
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.438-next.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.438-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/conversations.mjs
CHANGED
|
@@ -14,9 +14,9 @@ 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, statSync, copyFileSync } from 'node:fs';
|
|
17
|
+
import { readFileSync, createReadStream, createWriteStream, mkdtempSync, rmSync, statSync, copyFileSync, mkdirSync } from 'node:fs';
|
|
18
18
|
import { tmpdir } from 'node:os';
|
|
19
|
-
import { join } from 'node:path';
|
|
19
|
+
import { join, dirname } from 'node:path';
|
|
20
20
|
|
|
21
21
|
export const SESSION = 'main';
|
|
22
22
|
export const STOP_DELAY_MS = 60_000;
|
|
@@ -982,19 +982,35 @@ export class Conversations {
|
|
|
982
982
|
|
|
983
983
|
/* An exported state unpacked into its home (its tool stopped by the caller): its manifest checked, then each
|
|
984
984
|
part put in place of the old. -> the manifest's { name, at }, or null. */
|
|
985
|
+
/* `input`: a stream, sent through the VM manager's input; or the path of a file here -- then, when it has a work
|
|
986
|
+
folder here, put there and read from it in its machine (14-11: the VM manager's channel failed past a few tens
|
|
987
|
+
of KB on the owner's server, both ways). */
|
|
985
988
|
async #unpack(name, toolId, input) {
|
|
989
|
+
let viaWork = '';
|
|
990
|
+
let source = input;
|
|
991
|
+
const workDir = typeof input === 'string' && this.#store.get(name)?.work === 'kept' && typeof this.workFolder === 'function' ? this.workFolder(name) : '';
|
|
992
|
+
if (workDir) {
|
|
993
|
+
const id = `in-${Date.now()}`;
|
|
994
|
+
viaWork = join(workDir, '.clavarium-carry', `${id}.tgz`);
|
|
995
|
+
mkdirSync(dirname(viaWork), { recursive: true });
|
|
996
|
+
copyFileSync(input, viaWork);
|
|
997
|
+
source = id;
|
|
998
|
+
} else if (typeof input === 'string') source = createReadStream(input);
|
|
999
|
+
try { return await this.#unpackFrom(name, toolId, source, Boolean(viaWork)); } finally { if (viaWork) rmSync(viaWork, { force: true }); }
|
|
1000
|
+
}
|
|
1001
|
+
async #unpackFrom(name, toolId, input, fromWork) {
|
|
986
1002
|
/* Unpacked aside first: its manifest read, its tool checked; then moved into the home. */
|
|
987
1003
|
/* Aside in the home itself (never /tmp, which may be memory): then each part moved in place of the old. */
|
|
988
|
-
const script = 'set -e; m=$(mktemp -d "$HOME/.clavarium-import.XXXXXX"); trap \'rm -rf "$m"\' EXIT; tar -xzf - -C "$m"; '
|
|
1004
|
+
const script = 'set -e; m=$(mktemp -d "$HOME/.clavarium-import.XXXXXX"); trap \'rm -rf "$m"\' EXIT; if [ -n "$2" ]; then tar -xzf "/work/.clavarium-carry/$2.tgz" -C "$m"; else tar -xzf - -C "$m"; fi; '
|
|
989
1005
|
+ 'grep -q "\\"kind\\":\\"clavarium-conversation\\"" "$m/clavarium-conversation.json" || { echo "not an exported conversation" >&2; exit 3; }; '
|
|
990
1006
|
+ 'grep -q "\\"tool\\":\\"$1\\"" "$m/clavarium-conversation.json" || { echo "another tool" >&2; exit 4; }; '
|
|
991
1007
|
+ 'cat "$m/clavarium-conversation.json"; rm -f "$m/clavarium-conversation.json"; '
|
|
992
1008
|
+ 'for e in "$m"/.[!.]* "$m"/*; do if [ ! -e "$e" ]; then continue; fi; b=$(basename "$e"); rm -rf "$HOME/$b"; mv "$e" "$HOME/$b"; done';
|
|
993
|
-
const argv = this.#vms.execArgv(name, ['sh', '-c', script, 'import', toolId]);
|
|
1009
|
+
const argv = this.#vms.execArgv(name, ['sh', '-c', script, 'import', toolId, fromWork ? input : '']);
|
|
994
1010
|
const child = spawn(argv[0], argv.slice(1), { stdio: ['pipe', 'pipe', 'pipe'] });
|
|
995
1011
|
const out = []; const err = [];
|
|
996
1012
|
child.stdout.on('data', (d) => out.push(d)); child.stderr.on('data', (d) => err.push(d));
|
|
997
|
-
input.pipe(child.stdin);
|
|
1013
|
+
if (fromWork) child.stdin.end(); else input.pipe(child.stdin);
|
|
998
1014
|
child.stdin.on('error', () => { /* it stopped reading: said below */ });
|
|
999
1015
|
const code = await new Promise((ok) => child.on('close', ok));
|
|
1000
1016
|
if (code === 3) throw new Refusal(400, 'This is not an exported conversation.');
|
|
@@ -1138,7 +1154,7 @@ export class Conversations {
|
|
|
1138
1154
|
if (started.code !== 0) throw new Error(`its machine did not start: ${firstLine(started.stderr) || `exit ${started.code}`}.`);
|
|
1139
1155
|
}
|
|
1140
1156
|
this.#store.patch(to, { step: `Putting ${tool.label}'s memory in the copy` });
|
|
1141
|
-
await this.#unpack(to, c.tool,
|
|
1157
|
+
await this.#unpack(to, c.tool, carried);
|
|
1142
1158
|
}
|
|
1143
1159
|
this.#store.patch(to, { step: 'Giving it the same accesses' });
|
|
1144
1160
|
await this.copyRights(from, to);
|
|
@@ -1232,7 +1248,7 @@ export class Conversations {
|
|
|
1232
1248
|
/* Not opened while its state is put back: building still, to the end. */
|
|
1233
1249
|
this.#store.patch(name, { phase: 'building', step: `Putting ${tool.label}'s state back` });
|
|
1234
1250
|
this.drop(name);
|
|
1235
|
-
try { await this.#unpack(name, c.tool,
|
|
1251
|
+
try { await this.#unpack(name, c.tool, carried); } catch (error) {
|
|
1236
1252
|
this.#store.patch(name, { phase: 'ready', step: undefined });
|
|
1237
1253
|
this.ready(name);
|
|
1238
1254
|
this.renewed(name, `Moved to the shared machine ${machine}, but ${tool.label}'s state did not come along (${error.message}): it starts afresh. Its old machine is kept, stopped.`, true);
|