clavarium 0.2.211-beta.1 → 0.2.212-beta.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/config/launch/claude-code.sh +2 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/api.mjs +5 -3
- package/server/carry.mjs +2 -0
- package/server/conversations.mjs +147 -30
- package/server/dockets.mjs +17 -1
- package/server/jobs.mjs +6 -2
- package/server/main.mjs +3 -1
- package/server/settingswords.mjs +2 -2
- package/server/wakeups.mjs +12 -0
- package/web/app.js +81 -8
- package/web/index.html +4 -3
- package/web/style.css +3 -1
|
@@ -54,11 +54,11 @@ if [ -f "$chat/server.mjs" ]; then
|
|
|
54
54
|
|| echo "launch: the chat will not say when Claude Code works without a word" >&2
|
|
55
55
|
fi
|
|
56
56
|
# WHAT ITS SCREEN ASKS (02-11), read by the generic screen-watch -- Claude Code's own words, here and only
|
|
57
|
-
# here: not signed in, its sign-in started by itself, its link sent to the person's chat, the code they paste
|
|
57
|
+
# here: not signed in (at its start, or signed out on the way: « Login expired », 15-11), its sign-in started by itself, its link sent to the person's chat, the code they paste
|
|
58
58
|
# there typed back (02-11, tried on a real Claude Code); an update installed told to the agent, which restarts
|
|
59
59
|
# when it suits it (never in the middle of its work). A tool that changes its words: only these lines change.
|
|
60
60
|
node "$(dirname "$0")/screen-watch.mjs" \
|
|
61
|
-
'type:Not logged in
|
|
61
|
+
'type:(Not logged in|Login expired|OAuth token (has )?expired|Invalid API key)[^\n]{0,24}/login=/login' \
|
|
62
62
|
'keys:Select login method:=Enter' \
|
|
63
63
|
'link:https://(claude\.ai|claude\.com|console\.anthropic\.com)/\S*oauth\S*' \
|
|
64
64
|
'code:Paste code here' \
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.212-beta.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.212-beta.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/api.mjs
CHANGED
|
@@ -25,8 +25,9 @@
|
|
|
25
25
|
* POST /api/binder/suggest {id}: at most three quick actions for that card -> {actions: [{key, label, why, on, ask?}]}
|
|
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
|
-
* POST /api/conversations/<name>/into-machine {machine, machineMb?}: moved into a shared machine (#221), its tool's state along (202)
|
|
29
|
-
*
|
|
28
|
+
* POST /api/conversations/<name>/into-machine {machine, machineMb?}: moved into a shared machine (#221), its tool's state along (202);
|
|
29
|
+
* {} (no machine): out of its shared machine, into one of its own (15-11)
|
|
30
|
+
* POST /api/conversations/<name>/copy {title?, machine?, machineMb?, reminders?}: a copy -- its work, its tool's state, its accesses (its reminders and wake-ups when asked); it untouched (202)
|
|
30
31
|
* POST /api/conversations/<name>/rebuild {reset?, confirm?}: built again; reset (confirm: its name) for a working one too
|
|
31
32
|
* 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
|
|
32
33
|
* POST /api/conversations/<name>/resume {on}: its tool takes up its last session when it starts (true), or starts fresh
|
|
@@ -1031,6 +1032,7 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
1031
1032
|
/* Moved into a shared machine (#221): one there already, or a new one of the size given. */
|
|
1032
1033
|
const moving = /^\/api\/conversations\/([^/]+)\/into-machine$/.exec(pathname);
|
|
1033
1034
|
if (moving) {
|
|
1035
|
+
if (body?.machine === undefined) return send(202, await conversations.moveToOwn(decodeURIComponent(moving[1]))), true;
|
|
1034
1036
|
const machineMb = body?.machineMb === undefined ? undefined : Number(body.machineMb);
|
|
1035
1037
|
return send(202, await conversations.moveToShared(decodeURIComponent(moving[1]), { machine: body?.machine, machineMb })), true;
|
|
1036
1038
|
}
|
|
@@ -1039,7 +1041,7 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
1039
1041
|
if (copying) {
|
|
1040
1042
|
const machineMb = body?.machineMb === undefined ? undefined : Number(body.machineMb);
|
|
1041
1043
|
const machine = typeof body?.machine === 'string' && body.machine ? body.machine : undefined;
|
|
1042
|
-
return send(202, await conversations.copy(decodeURIComponent(copying[1]), { title: body?.title, machine, machineMb })), true;
|
|
1044
|
+
return send(202, await conversations.copy(decodeURIComponent(copying[1]), { title: body?.title, machine, machineMb, reminders: body?.reminders === true })), true;
|
|
1043
1045
|
}
|
|
1044
1046
|
const again = /^\/api\/conversations\/([^/]+)\/rebuild$/.exec(pathname);
|
|
1045
1047
|
if (again) {
|
package/server/carry.mjs
CHANGED
|
@@ -42,6 +42,8 @@ export function wholeStream(homeTar, workDir, done = () => {}) {
|
|
|
42
42
|
const home = createReadStream(homeTar, { start: 0, end: size - END - 1 });
|
|
43
43
|
home.on('error', end);
|
|
44
44
|
home.on('end', () => {
|
|
45
|
+
/* Its home read whole: its part taken away now, before the file ends (15-11, a test saw it still there). */
|
|
46
|
+
done();
|
|
45
47
|
/* Its work: every file, its carried parts left out; named work/... (a link's target left as it is). */
|
|
46
48
|
child = spawn('tar', ['-cf', '-', '-b', '1', '-C', workDir, `--exclude=./${CARRY}`, '--transform', 's,^\\.,work,S', '.'], { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
47
49
|
child.stdout.pipe(gzip);
|
package/server/conversations.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import { TOOLS_PATH, LAUNCH } from './toolbox.mjs';
|
|
|
15
15
|
import { homeExcludes, wholeStream, readManifest, workEmpty, unpackHere, restoreWork, CARRY } from './carry.mjs';
|
|
16
16
|
import { availableParallelism } from 'node:os';
|
|
17
17
|
import { spawn } from 'node:child_process';
|
|
18
|
-
import { readFileSync, createReadStream, createWriteStream, mkdtempSync, rmSync, statSync, copyFileSync, mkdirSync } from 'node:fs';
|
|
18
|
+
import { readFileSync, createReadStream, createWriteStream, mkdtempSync, rmSync, statSync, copyFileSync, mkdirSync, existsSync } from 'node:fs';
|
|
19
19
|
import { tmpdir } from 'node:os';
|
|
20
20
|
import { join, dirname } from 'node:path';
|
|
21
21
|
|
|
@@ -176,6 +176,7 @@ export class Conversations {
|
|
|
176
176
|
/* A move into a shared machine cut short (14-11): back in its own machine, as it was -- never « build it
|
|
177
177
|
again », which would make its own machine anew and lose its tool's memory. */
|
|
178
178
|
if (c.phase === 'building' && c.movingTo) store.patch(c.name, { phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, sharedMachine: undefined, machineMb: undefined, machineUser: undefined, ...(c.movingFromMb ? { memoryMb: c.movingFromMb } : {}), movingTo: undefined, movingFromMb: undefined, stopped: true, moved: `The server restarted while it was moving to the shared machine ${c.movingTo}: it stays in its own machine, as it was. Move it again when you like.` });
|
|
179
|
+
else if (c.phase === 'building' && c.movingOutOf) store.patch(c.name, { phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, ...c.movingOutOf, movingOutOf: undefined, stopped: true, moved: `The server restarted while it was moving out of the shared machine ${c.movingOutOf.sharedMachine}: it stays there. Move it again when you like.` });
|
|
179
180
|
else if (c.phase === 'building') store.patch(c.name, { phase: 'failed', error: 'The server restarted while this conversation was being built. Build it again, or archive it.' });
|
|
180
181
|
if (c.phase === 'restarting') store.patch(c.name, { phase: 'ready', step: undefined, restartingSince: undefined, restarted: 'The server restarted while this machine was being restarted: look at its state, and restart it again if needed.' });
|
|
181
182
|
/* An action cut short: said as such, never left running on the page. */
|
|
@@ -1102,11 +1103,11 @@ export class Conversations {
|
|
|
1102
1103
|
|
|
1103
1104
|
/* A COPY OF A CONVERSATION (#221, 13-11, its owner's ask: safer than a move -- nothing is destroyed). A new
|
|
1104
1105
|
conversation, in a machine of its own or a shared one, with what its original has: its work folder (its
|
|
1105
|
-
chat with it), its tool's state (the AI's memory), its settings, and the accesses it was given
|
|
1106
|
-
|
|
1106
|
+
chat with it), its tool's state (the AI's memory), its settings, and the accesses it was given; its reminders
|
|
1107
|
+
and wake-ups only when asked (`reminders`, 15-11). Its devices and its pending asks are NOT copied: one of the two answers them, the original. Its original is
|
|
1107
1108
|
not touched; asleep, its machine is woken the time to read its tool's state, then put to sleep again.
|
|
1108
1109
|
-> the copy's record, at once; `this.copied`: the end of it. */
|
|
1109
|
-
async copy(name, { title, machine, machineMb } = {}) {
|
|
1110
|
+
async copy(name, { title, machine, machineMb, reminders = false } = {}) {
|
|
1110
1111
|
const c = this.#store.get(name);
|
|
1111
1112
|
if (!c) throw new Refusal(404, 'No such conversation.');
|
|
1112
1113
|
if (c.phase !== 'ready') throw new Refusal(409, 'It is busy: copy it once it is ready.');
|
|
@@ -1126,11 +1127,11 @@ export class Conversations {
|
|
|
1126
1127
|
this.#holding.add(made.name);
|
|
1127
1128
|
this.#store.patch(made.name, { copyOf: name });
|
|
1128
1129
|
const building = this.built;
|
|
1129
|
-
this.copied = this.#copying(name, made.name, c, tool, building, open);
|
|
1130
|
+
this.copied = this.#copying(name, made.name, c, tool, building, open, reminders === true);
|
|
1130
1131
|
return this.#store.get(made.name);
|
|
1131
1132
|
}
|
|
1132
1133
|
|
|
1133
|
-
async #copying(from, to, c, tool, building, open = () => {}) {
|
|
1134
|
+
async #copying(from, to, c, tool, building, open = () => {}, reminders = false) {
|
|
1134
1135
|
const dir = mkdtempSync(join(tmpdir(), 'clv-copy-'));
|
|
1135
1136
|
const carried = join(dir, 'state.tar.gz');
|
|
1136
1137
|
let woke = false; let putBack = 'sleep';
|
|
@@ -1173,6 +1174,7 @@ export class Conversations {
|
|
|
1173
1174
|
const carryId = workDir ? `copy-${to}-${Date.now()}` : '';
|
|
1174
1175
|
const inWork = carryId ? join(workDir, '.clavarium-carry', `${carryId}.tgz`) : '';
|
|
1175
1176
|
if (inWork) await Promise.race([Promise.resolve().then(() => this.mounted(from, true)).catch(() => {}), new Promise((r) => { setTimeout(r, MOUNTED_MS).unref?.(); })]);
|
|
1177
|
+
if (inWork && !(await this.#workShown(from, workDir))) throw new Error('its original\'s work folder is not shown in its machine: open the original once, then copy it again');
|
|
1176
1178
|
const out = await this.exportState(from, inWork ? { toWork: carryId } : {});
|
|
1177
1179
|
child = out.child;
|
|
1178
1180
|
let read = 0; let lastAt = Date.now(); let stalled = false;
|
|
@@ -1238,6 +1240,8 @@ export class Conversations {
|
|
|
1238
1240
|
}
|
|
1239
1241
|
this.#store.patch(to, { step: 'Giving it the same accesses' });
|
|
1240
1242
|
await this.copyRights(from, to);
|
|
1243
|
+
/* Its reminders and wake-ups too, when asked (15-11): an unticked box on the copy's last screen. */
|
|
1244
|
+
if (reminders && typeof this.copyReminders === 'function') await Promise.resolve().then(() => this.copyReminders(from, to)).catch(() => {});
|
|
1241
1245
|
this.#holding.delete(to);
|
|
1242
1246
|
if (!this.#store.get(to)) return undefined;
|
|
1243
1247
|
this.#store.patch(to, { phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, error: undefined });
|
|
@@ -1283,18 +1287,62 @@ export class Conversations {
|
|
|
1283
1287
|
this.#cancelStop(name);
|
|
1284
1288
|
const now = new Date().toISOString();
|
|
1285
1289
|
/* `movingTo`: what a restart of this server finds, to put it back in its own machine, as it was (14-11). */
|
|
1286
|
-
this.#store.patch(name, { phase: 'building', step: `Moving to the shared machine ${machine}`, buildingSince: now, progress: buildProgress(now), movingTo: machine, movingFromMb: c.memoryMb });
|
|
1290
|
+
this.#store.patch(name, { phase: 'building', step: `Moving to the shared machine ${machine}`, buildingSince: now, progress: buildProgress(now), movingTo: machine, movingFromMb: c.memoryMb, moveFailed: undefined });
|
|
1287
1291
|
this.built = this.#moving(name, c, tool, machine, size, memory, state).finally(() => this.#give(name, act));
|
|
1288
1292
|
return this.#store.get(name);
|
|
1289
1293
|
}
|
|
1290
1294
|
|
|
1295
|
+
/* ITS WORK FOLDER SEEN FROM ITS MACHINE (15-11): a file made there is found here -- else what is written for the
|
|
1296
|
+
server to read stays inside the machine (a work folder unmounted by a move cut short). Shown again once if not. */
|
|
1297
|
+
async #workShown(name, workDir) {
|
|
1298
|
+
const seen = async () => {
|
|
1299
|
+
const id = `probe-${Date.now()}`;
|
|
1300
|
+
await this.#vms.exec(name, ['sh', '-c', `mkdir -p /work/.clavarium-carry && : > /work/.clavarium-carry/${id}`], { timeoutMs: 30_000 }).catch(() => {});
|
|
1301
|
+
const there = existsSync(join(workDir, '.clavarium-carry', id));
|
|
1302
|
+
rmSync(join(workDir, '.clavarium-carry', id), { force: true });
|
|
1303
|
+
return there;
|
|
1304
|
+
};
|
|
1305
|
+
if (await seen()) return true;
|
|
1306
|
+
await this.#vms.workMount(name, this.#uid, this.#gid).catch(() => {});
|
|
1307
|
+
return seen();
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
/* ITS TOOL'S STATE, TAKEN ALONG for a move (12-11, 15-11): through its work folder, as a copy reads it (14-11),
|
|
1311
|
+
written to `carried`. -> undefined, or why it could not be. */
|
|
1312
|
+
async #takeState(name, c, tool, carried) {
|
|
1313
|
+
this.#store.patch(name, { step: `Taking ${tool.label}'s state along` });
|
|
1314
|
+
/* Through its work folder, as a copy reads it (14-11): the VM manager's output stalls past ~36 KB on
|
|
1315
|
+
the owner's server -- a move then waited for ever. Its size read as it grows, said; quiet too long: ended. */
|
|
1316
|
+
const workDir = c.work === 'kept' && typeof this.workFolder === 'function' ? this.workFolder(name) : '';
|
|
1317
|
+
const carryId = workDir ? `move-${name}-${Date.now()}` : '';
|
|
1318
|
+
const inWork = carryId ? join(workDir, '.clavarium-carry', `${carryId}.tgz`) : '';
|
|
1319
|
+
if (inWork) await Promise.race([Promise.resolve().then(() => this.mounted(name, true)).catch(() => {}), new Promise((r) => { setTimeout(r, MOUNTED_MS).unref?.(); })]);
|
|
1320
|
+
if (inWork && !(await this.#workShown(name, workDir))) return 'its work folder is not shown in its machine: open the conversation once, then move it again.';
|
|
1321
|
+
const { stream, child } = await this.exportState(name, inWork ? { toWork: carryId } : {});
|
|
1322
|
+
let read = 0; let lastAt = Date.now(); let stalled = false;
|
|
1323
|
+
const grew = (n) => { if (n <= read) return; read = n; lastAt = Date.now(); this.#store.patch(name, { step: `Taking ${tool.label}'s state along: ${sizeWords(read)}` }); };
|
|
1324
|
+
const sizing = setInterval(() => {
|
|
1325
|
+
if (inWork) { try { grew(statSync(inWork).size); } catch { /* not there yet */ } }
|
|
1326
|
+
if (Date.now() - lastAt >= COPY_QUIET_MS) { stalled = true; child.kill('SIGKILL'); }
|
|
1327
|
+
}, 1000);
|
|
1328
|
+
const failed = new Promise((ok) => child.on('error', () => ok(-1)));
|
|
1329
|
+
const file = inWork ? null : createWriteStream(carried, { mode: 0o600 });
|
|
1330
|
+
if (file) { stream.on('data', (d) => grew(read + d.length)); stream.pipe(file); } else stream.resume();
|
|
1331
|
+
const code = await Promise.race([new Promise((ok) => child.on('close', ok)), failed]).finally(() => clearInterval(sizing));
|
|
1332
|
+
if (file) await new Promise((ok) => (file.writableFinished ? ok() : file.on('finish', ok)));
|
|
1333
|
+
if (inWork) { try { if (code === 0 && !stalled) copyFileSync(inWork, carried); } finally { rmSync(inWork, { force: true }); } }
|
|
1334
|
+
if (stalled) return `its tool's state stopped coming (${sizeWords(read)} read, then nothing for ${COPY_QUIET_MS / 60_000} min).`;
|
|
1335
|
+
if (code !== 0) return `its tool's state could not be taken (exit ${code}${firstLine(child.said) ? `: ${firstLine(child.said)}` : ''}).`;
|
|
1336
|
+
return undefined;
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1291
1339
|
async #moving(name, c, tool, machine, size, memory, state) {
|
|
1292
1340
|
const old = vmName(name);
|
|
1293
1341
|
const dir = mkdtempSync(join(tmpdir(), 'clv-move-'));
|
|
1294
1342
|
const carried = join(dir, 'state.tar.gz');
|
|
1295
1343
|
const back = (why) => {
|
|
1296
1344
|
/* Back to its own machine, as it was (stopped: the next opening wakes it). */
|
|
1297
|
-
this.#store.patch(name, { sharedMachine: undefined, machineMb: undefined, machineUser: undefined, memoryMb: c.memoryMb, phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, error: undefined, movingTo: undefined, movingFromMb: undefined });
|
|
1345
|
+
this.#store.patch(name, { sharedMachine: undefined, machineMb: undefined, machineUser: undefined, memoryMb: c.memoryMb, phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, error: undefined, movingTo: undefined, movingFromMb: undefined, moveFailed: `Not moved: ${why}` });
|
|
1298
1346
|
this.#fresh.add(name); this.#mountAgain.add(name);
|
|
1299
1347
|
try { this.renewed(name, `Not moved to the shared machine ${machine}: ${why} It stays in its own machine, as it was.`, false); } catch { /* told, nothing more */ }
|
|
1300
1348
|
};
|
|
@@ -1302,28 +1350,8 @@ export class Conversations {
|
|
|
1302
1350
|
this.drop(name);
|
|
1303
1351
|
if (state === 'Running') await this.#vms.exec(name, ['tmux', '-L', SOCKET, 'kill-server'], { timeoutMs: 10_000 }).catch(() => {});
|
|
1304
1352
|
if (tool.state) {
|
|
1305
|
-
this.#
|
|
1306
|
-
|
|
1307
|
-
the owner's server -- a move then waited for ever. Its size read as it grows, said; quiet too long: ended. */
|
|
1308
|
-
const workDir = c.work === 'kept' && typeof this.workFolder === 'function' ? this.workFolder(name) : '';
|
|
1309
|
-
const carryId = workDir ? `move-${name}-${Date.now()}` : '';
|
|
1310
|
-
const inWork = carryId ? join(workDir, '.clavarium-carry', `${carryId}.tgz`) : '';
|
|
1311
|
-
if (inWork) await Promise.race([Promise.resolve().then(() => this.mounted(name, true)).catch(() => {}), new Promise((r) => { setTimeout(r, MOUNTED_MS).unref?.(); })]);
|
|
1312
|
-
const { stream, child } = await this.exportState(name, inWork ? { toWork: carryId } : {});
|
|
1313
|
-
let read = 0; let lastAt = Date.now(); let stalled = false;
|
|
1314
|
-
const grew = (n) => { if (n <= read) return; read = n; lastAt = Date.now(); this.#store.patch(name, { step: `Taking ${tool.label}'s state along: ${sizeWords(read)}` }); };
|
|
1315
|
-
const sizing = setInterval(() => {
|
|
1316
|
-
if (inWork) { try { grew(statSync(inWork).size); } catch { /* not there yet */ } }
|
|
1317
|
-
if (Date.now() - lastAt >= COPY_QUIET_MS) { stalled = true; child.kill('SIGKILL'); }
|
|
1318
|
-
}, 1000);
|
|
1319
|
-
const failed = new Promise((ok) => child.on('error', () => ok(-1)));
|
|
1320
|
-
const file = inWork ? null : createWriteStream(carried, { mode: 0o600 });
|
|
1321
|
-
if (file) { stream.on('data', (d) => grew(read + d.length)); stream.pipe(file); } else stream.resume();
|
|
1322
|
-
const code = await Promise.race([new Promise((ok) => child.on('close', ok)), failed]).finally(() => clearInterval(sizing));
|
|
1323
|
-
if (file) await new Promise((ok) => (file.writableFinished ? ok() : file.on('finish', ok)));
|
|
1324
|
-
if (inWork) { try { if (code === 0 && !stalled) copyFileSync(inWork, carried); } finally { rmSync(inWork, { force: true }); } }
|
|
1325
|
-
if (stalled) return back(`its tool's state stopped coming (${sizeWords(read)} read, then nothing for ${COPY_QUIET_MS / 60_000} min).`);
|
|
1326
|
-
if (code !== 0) return back(`its tool's state could not be taken (exit ${code}${firstLine(child.said) ? `: ${firstLine(child.said)}` : ''}).`);
|
|
1353
|
+
const why = await this.#takeState(name, c, tool, carried);
|
|
1354
|
+
if (why) return back(why);
|
|
1327
1355
|
}
|
|
1328
1356
|
if (state !== undefined) {
|
|
1329
1357
|
this.#store.patch(name, { step: 'Stopping its own machine' });
|
|
@@ -1361,6 +1389,95 @@ export class Conversations {
|
|
|
1361
1389
|
} finally { rmSync(dir, { recursive: true, force: true }); }
|
|
1362
1390
|
}
|
|
1363
1391
|
|
|
1392
|
+
/* OUT OF ITS SHARED MACHINE, INTO ONE OF ITS OWN (#221, 15-11): the move the other way. Its tool's state carried
|
|
1393
|
+
(as into a shared machine), its programs there ended and its work taken out of its place, its own machine built
|
|
1394
|
+
as a new one's, the state put back, then its place in the shared machine removed -- its user and home there, or
|
|
1395
|
+
the whole machine when it was the last in it. Anything wrong before its own machine is ready: back in the shared
|
|
1396
|
+
machine, as it was (its place there kept until the end). -> the record, at once; `this.built`: the end of it. */
|
|
1397
|
+
async moveToOwn(name) {
|
|
1398
|
+
const c = this.#busyCheck(name);
|
|
1399
|
+
if (!c.sharedMachine) throw new Refusal(409, 'It has a machine of its own already.');
|
|
1400
|
+
const tool = this.#tools.find((t) => t.id === c.tool);
|
|
1401
|
+
if (!tool) throw new Refusal(400, 'The tool of this conversation is no longer offered.');
|
|
1402
|
+
const state = await this.#vms.state(name, { fresh: true }).catch(() => undefined);
|
|
1403
|
+
if (tool.state && state !== 'Running') throw new Refusal(409, 'Its shared machine is not running: open the conversation first, so that its tool\'s state can come along.', { retry: false });
|
|
1404
|
+
const memory = Math.max(tool.memoryMb, Number(c.memoryMb) || tool.memoryMb);
|
|
1405
|
+
await this.room({ kind: 'create', memoryMb: memory });
|
|
1406
|
+
const act = this.#take(name, 'move');
|
|
1407
|
+
this.#cancelStop(name);
|
|
1408
|
+
const now = new Date().toISOString();
|
|
1409
|
+
/* `movingOutOf`: what a restart of this server finds, to put it back in its shared machine (constructor). */
|
|
1410
|
+
this.#store.patch(name, { phase: 'building', step: `Moving out of the shared machine ${c.sharedMachine}`, buildingSince: now, progress: buildProgress(now), movingOutOf: { sharedMachine: c.sharedMachine, machineMb: c.machineMb, machineUser: c.machineUser, memoryMb: c.memoryMb }, moveFailed: undefined });
|
|
1411
|
+
this.built = this.#movingOut(name, c, tool, memory, state).finally(() => this.#give(name, act));
|
|
1412
|
+
return this.#store.get(name);
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
async #movingOut(name, c, tool, memory, state) {
|
|
1416
|
+
const shared = c.sharedMachine;
|
|
1417
|
+
const was = { sharedMachine: shared, machineMb: c.machineMb, machineUser: c.machineUser, memoryMb: c.memoryMb };
|
|
1418
|
+
const dir = mkdtempSync(join(tmpdir(), 'clv-move-'));
|
|
1419
|
+
const carried = join(dir, 'state.tar.gz');
|
|
1420
|
+
let left = false;
|
|
1421
|
+
const back = async (why) => {
|
|
1422
|
+
/* Back in its shared machine, as it was: its own machine, if begun, removed; its work shown there again. */
|
|
1423
|
+
if (!this.#store.get(name)) return undefined;
|
|
1424
|
+
this.#store.patch(name, { sharedMachine: undefined });
|
|
1425
|
+
if ((await this.#vms.state(name, { fresh: true }).catch(() => undefined)) !== undefined) await this.#vms.removeVm(vmName(name)).catch(() => {});
|
|
1426
|
+
this.#store.patch(name, { ...was, phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, error: undefined, movingOutOf: undefined, moveFailed: `Not moved: ${why}` });
|
|
1427
|
+
if (left) await this.#vms.workMount(name, this.#uid, this.#gid).catch(() => {});
|
|
1428
|
+
this.#fresh.add(name); this.#mountAgain.add(name);
|
|
1429
|
+
try { this.renewed(name, `Not moved out of the shared machine ${shared}: ${why} It stays there, as it was.`, false); } catch { /* told, nothing more */ }
|
|
1430
|
+
return undefined;
|
|
1431
|
+
};
|
|
1432
|
+
try {
|
|
1433
|
+
this.drop(name);
|
|
1434
|
+
if (state === 'Running') await this.#vms.exec(name, ['tmux', '-L', SOCKET, 'kill-server'], { timeoutMs: 10_000 }).catch(() => {});
|
|
1435
|
+
if (tool.state) {
|
|
1436
|
+
const why = await this.#takeState(name, c, tool, carried);
|
|
1437
|
+
if (why) return back(why);
|
|
1438
|
+
}
|
|
1439
|
+
if (state === 'Running') {
|
|
1440
|
+
/* Its programs there ended, its work taken out of its place: nothing of it runs there any more. */
|
|
1441
|
+
this.#store.patch(name, { step: `Leaving the shared machine ${shared}` });
|
|
1442
|
+
await this.#vms.execMachine(name, ['sudo', '-n', 'pkill', '-KILL', '-u', `c-${name}`], { timeoutMs: 30_000 }).catch(() => {});
|
|
1443
|
+
await this.#vms.workUnmount(name).catch(() => {});
|
|
1444
|
+
left = true;
|
|
1445
|
+
}
|
|
1446
|
+
/* Its own machine, as a new conversation's: built with its name, held before its tool starts. */
|
|
1447
|
+
this.#store.patch(name, { sharedMachine: undefined, machineMb: undefined, machineUser: undefined, memoryMb: memory, step: 'Starting the machine' });
|
|
1448
|
+
/* One left behind by an attempt cut short: not this conversation's any more. */
|
|
1449
|
+
if ((await this.#vms.state(name, { fresh: true }).catch(() => undefined)) !== undefined) await this.#vms.removeVm(vmName(name)).catch(() => {});
|
|
1450
|
+
this.#holding.add(name);
|
|
1451
|
+
try { await this.#build(name, tool, memory); } finally { this.#holding.delete(name); }
|
|
1452
|
+
const now = this.#store.get(name);
|
|
1453
|
+
if (!now) return undefined; /* archived meanwhile */
|
|
1454
|
+
if (now.phase === 'failed') return back(`${String(now.error ?? 'its own machine could not be made.').replace(/\.?$/, '.')}`);
|
|
1455
|
+
let lost = '';
|
|
1456
|
+
if (tool.state) {
|
|
1457
|
+
this.#store.patch(name, { step: `Putting ${tool.label}'s state back` });
|
|
1458
|
+
try { await this.#unpack(name, c.tool, carried); } catch (error) { lost = error.message; }
|
|
1459
|
+
}
|
|
1460
|
+
this.#store.patch(name, { phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, toolStarted: false, movingOutOf: undefined });
|
|
1461
|
+
this.ready(name);
|
|
1462
|
+
/* There for good: its place in the shared machine goes -- the whole machine with the last one in it. */
|
|
1463
|
+
const others = this.#store.all().filter((x) => x.name !== name && x.sharedMachine === shared);
|
|
1464
|
+
if (others.length) {
|
|
1465
|
+
const there = this.#vms.run;
|
|
1466
|
+
await there(['vm', 'unshare', vmName(shared), name]).catch(() => {});
|
|
1467
|
+
if (left) {
|
|
1468
|
+
await there(['vm', 'exec', vmName(shared), '--', 'sudo', '-n', 'userdel', '--remove', `c-${name}`], { timeoutMs: 60_000 }).catch(() => {});
|
|
1469
|
+
await there(['vm', 'exec', vmName(shared), '--', 'sudo', '-n', 'rm', '-f', `/etc/clavarium/limits/${name}`], { timeoutMs: 30_000 }).catch(() => {});
|
|
1470
|
+
}
|
|
1471
|
+
} else await this.#vms.removeVm(vmName(shared)).catch(() => {});
|
|
1472
|
+
this.renewed(name, lost
|
|
1473
|
+
? `Moved out of the shared machine ${shared} into a machine of its own, but ${tool.label}'s state did not come along (${lost}): it starts afresh.`
|
|
1474
|
+
: `Moved out of the shared machine ${shared} into a machine of its own: its work folder${tool.state ? `, ${tool.label}'s state` : ''} and this chat came along.`, true);
|
|
1475
|
+
return undefined;
|
|
1476
|
+
} catch (error) {
|
|
1477
|
+
return back(`${String(error?.message ?? error).replace(/\.?$/, '.')}`);
|
|
1478
|
+
} finally { rmSync(dir, { recursive: true, force: true }); }
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1364
1481
|
async #fixup(name, tool) {
|
|
1365
1482
|
for (const step of tool.fixups) {
|
|
1366
1483
|
const r = await this.#vms.exec(name, step.argv, { timeoutMs: 120_000 }).catch(() => ({ code: 1 }));
|
package/server/dockets.mjs
CHANGED
|
@@ -24,12 +24,28 @@
|
|
|
24
24
|
* The folder is the work folder's .docket, beside .parley: the tool writes
|
|
25
25
|
* there, so nothing in it is trusted (the library bounds and cleans it).
|
|
26
26
|
*/
|
|
27
|
-
import { mkdirSync, lstatSync } from 'node:fs';
|
|
27
|
+
import { mkdirSync, lstatSync, readFileSync, writeFileSync } from 'node:fs';
|
|
28
|
+
import { join } from 'node:path';
|
|
28
29
|
import { Docket, WAKE } from 'clavarium-docket/host';
|
|
29
30
|
import { verbs } from 'clavarium-docket/server';
|
|
30
31
|
|
|
31
32
|
export { WAKE };
|
|
32
33
|
export const FOLDER = '.docket';
|
|
34
|
+
|
|
35
|
+
/* A COPY'S REMINDERS (15-11, asked when it is copied): the reminders its original's tool set (plans.jsonl in its
|
|
36
|
+
docket folder), those still to come -- a repeating one, or one due later -- written in the copy's; one taken
|
|
37
|
+
back, or past, is not. Its events and their answers stay the original's. -> how many. */
|
|
38
|
+
export function copyPlans(fromWork, toWork, now = Date.now()) {
|
|
39
|
+
const lines = (file) => { try { return readFileSync(join(fromWork, FOLDER, file), 'utf8').split('\n').filter(Boolean).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter(Boolean); } catch { return []; } };
|
|
40
|
+
const off = new Set(lines('plans-off.jsonl').map((o) => o.plan));
|
|
41
|
+
const kept = lines('plans.jsonl').filter((p) => p.kind === 'plan' && !off.has(p.id) && (p.cron || (p.due && Date.parse(p.due) > now)));
|
|
42
|
+
if (!kept.length) return 0;
|
|
43
|
+
mkdirSync(join(toWork, FOLDER), { recursive: true });
|
|
44
|
+
let zone = null; try { zone = readFileSync(join(fromWork, FOLDER, 'zone'), 'utf8'); } catch { /* none */ }
|
|
45
|
+
if (zone !== null) writeFileSync(join(toWork, FOLDER, 'zone'), zone);
|
|
46
|
+
writeFileSync(join(toWork, FOLDER, 'plans.jsonl'), kept.map((p) => JSON.stringify(p)).join('\n') + '\n', { flag: 'a' });
|
|
47
|
+
return kept.length;
|
|
48
|
+
}
|
|
33
49
|
export const TICK_MS = 5000;
|
|
34
50
|
/* An event not acknowledged is told again after this long, the tool idle... */
|
|
35
51
|
export const AGAIN_MS = 30 * 60_000;
|
package/server/jobs.mjs
CHANGED
|
@@ -33,6 +33,8 @@ const bare = ({ log, ...job }) => job;
|
|
|
33
33
|
export function jobWords(c) {
|
|
34
34
|
if (c.phase === 'moving') return `Moving ${titleOf(c)}${c.sharedMachine ? ` into « ${c.sharedMachine} »` : ''}`;
|
|
35
35
|
if (c.phase === 'restarting') return `Restarting ${titleOf(c)}`;
|
|
36
|
+
if (c.movingTo) return `Moving ${titleOf(c)} into « ${c.movingTo} »`;
|
|
37
|
+
if (c.movingOutOf) return `Moving ${titleOf(c)} out of « ${c.movingOutOf.sharedMachine} »`;
|
|
36
38
|
if (c.copyOf) return `Copy ${titleOf(c)}${c.sharedMachine ? ` in « ${c.sharedMachine} »` : ''}`;
|
|
37
39
|
return `Building ${titleOf(c)}${c.sharedMachine ? ` in « ${c.sharedMachine} »` : ''}`;
|
|
38
40
|
}
|
|
@@ -94,8 +96,10 @@ export class Jobs {
|
|
|
94
96
|
if (busy || !this.#open.has(name)) return;
|
|
95
97
|
const job = this.#open.get(name);
|
|
96
98
|
this.#open.delete(name);
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
+
/* A move that went back (15-11): ready where it was, but not done -- `moveFailed` says why. */
|
|
100
|
+
const ok = after?.phase === 'ready' && !after.moveFailed;
|
|
101
|
+
const said = after?.error ?? after?.moveFailed;
|
|
102
|
+
const why = after && !ok && said ? String(said).slice(0, 300) : '';
|
|
99
103
|
this.#add(name, after ? (ok ? 'Done' : `Failed${why ? `: ${why}` : ''}`) : 'Removed');
|
|
100
104
|
const { log } = this.#logs.get(name);
|
|
101
105
|
this.#logs.delete(name);
|
package/server/main.mjs
CHANGED
|
@@ -41,7 +41,7 @@ import { Secrets, RUNNER } from './secrets.mjs';
|
|
|
41
41
|
import { scan, secretRef } from './secret-scan.mjs';
|
|
42
42
|
import { Network } from './network.mjs';
|
|
43
43
|
import { Answerer, answererConfig } from './answerer.mjs';
|
|
44
|
-
import { Dockets } from './dockets.mjs';
|
|
44
|
+
import { Dockets, copyPlans } from './dockets.mjs';
|
|
45
45
|
import { PULSE_MS } from 'clavarium-parley/ui';
|
|
46
46
|
import { Wakeups, TypingWatch, CALL_PATH } from './wakeups.mjs';
|
|
47
47
|
import { Alerts } from './alerts.mjs';
|
|
@@ -680,6 +680,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
680
680
|
all.copyWork = (from, to, onProgress) => copyWorkFolder(folders.workFolder(from), folders.workFolder(to), onProgress);
|
|
681
681
|
/* Where a conversation's work folder is on this side: a copy reads its tool's memory through it (14-11). */
|
|
682
682
|
all.workFolder = (name) => folders.workFolder(name);
|
|
683
|
+
/* Its reminders and wake-ups, when the copy asked for them (15-11). */
|
|
684
|
+
all.copyReminders = (from, to) => { copyPlans(folders.workFolder(from), folders.workFolder(to)); wakeups.copyTo(from, to); };
|
|
683
685
|
all.copyRights = async (from, to) => {
|
|
684
686
|
for (const r of folders.of(from)) {
|
|
685
687
|
if (r.access === 'write') gitKeeper?.beforeWriter(r.name, to, true);
|
package/server/settingswords.mjs
CHANGED
|
@@ -179,9 +179,9 @@ export const SETTINGS_WORDS_FR = {
|
|
|
179
179
|
'set-cm-own-to': 'sa propre machine', 'set-cm-copy-to': 'Copier {t} vers {where}', 'set-cm-move-to': 'Déplacer {t} dans {where}',
|
|
180
180
|
'set-cm-new-line': 'Nouvelle machine partagée · {size}', 'set-cm-copy-name': 'Nom de la copie',
|
|
181
181
|
'set-cm-goes-work': 'Son dossier de travail', 'set-cm-goes-memory': 'La mémoire de son IA', 'set-cm-goes-access': 'Ses accès',
|
|
182
|
-
'set-cm-
|
|
182
|
+
'set-cm-reminders': 'Ses rappels et réveils aussi', 'set-cm-not-devices': 'Pas ses appareils', 'set-cm-untouched': 'Celle-ci intacte : lue, puis remise en l\'état',
|
|
183
183
|
'set-cm-stay': 'Vous restez ici · « Ouvrir » une fois prête', 'set-cm-stops': 'Son outil s\'arrête environ une minute',
|
|
184
|
-
'set-cm-deleted': 'Sa propre machine est supprimée', 'set-cm-back': 'Retour', 'set-cm-copy-go': 'La copier', 'set-cm-move-go': 'La déplacer',
|
|
184
|
+
'set-cm-deleted': 'Sa propre machine est supprimée', 'set-cm-stops-out': 'Son outil s\'arrête quelques minutes', 'set-cm-shared-deleted': 'La machine partagée « {m} » est supprimée', 'set-cm-place-deleted': 'Sa place dans « {m} » est supprimée', 'set-cm-back': 'Retour', 'set-cm-copy-go': 'La copier', 'set-cm-move-go': 'La déplacer',
|
|
185
185
|
'set-cm-ready': 'Copie prête', 'set-cm-open': 'Ouvrir', 'set-cm-failed': 'Pas copiée', 'set-cm-see-why': 'Voir pourquoi',
|
|
186
186
|
'set-carry': 'Exporter / Importer', 'set-carry-hint': 'Mémoire de son IA, ou tout : à emporter.',
|
|
187
187
|
'set-carry-export': 'Mémoire de son IA', 'set-carry-all': 'Tout (dossier perso, travail, accès)', 'set-carry-all-off': 'Son travail doit être gardé ici.',
|
package/server/wakeups.mjs
CHANGED
|
@@ -234,6 +234,18 @@ export class Wakeups {
|
|
|
234
234
|
return once ? { ...this.of(name), address: `${CALL_PATH}${once}` } : this.of(name);
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
+
/* A COPY'S WAKE-UPS (15-11, asked when it is copied): its original's, each its own again (a new id, its clock
|
|
238
|
+
counted from now); a call from outside is not -- its address is the original's, said once and never again. */
|
|
239
|
+
copyTo(from, to) {
|
|
240
|
+
this.#known(from); this.#known(to);
|
|
241
|
+
const was = this.#record(from);
|
|
242
|
+
const now = this.#now().toISOString();
|
|
243
|
+
const items = was.items.filter((i) => i.kind !== 'call').map(({ last, ...i }) => ({ ...i, id: randomUUID(), made: now, last: null, ...(i.fired !== undefined ? { fired: now } : {}) }));
|
|
244
|
+
const r = this.#record(to);
|
|
245
|
+
this.#store.put({ ...r, perHour: was.perHour, items: [...r.items, ...items].slice(0, ITEMS_MAX) });
|
|
246
|
+
return this.of(to);
|
|
247
|
+
}
|
|
248
|
+
|
|
237
249
|
#change(name, id, change) {
|
|
238
250
|
this.#known(name);
|
|
239
251
|
const r = this.#record(name);
|
package/web/app.js
CHANGED
|
@@ -1993,6 +1993,8 @@
|
|
|
1993
1993
|
paintChips();
|
|
1994
1994
|
paintHealth();
|
|
1995
1995
|
if (!DEVICE) void paintGauge();
|
|
1996
|
+
/* The chats of the others, kept for a switch at once (15-11): what moved, fetched in the background. */
|
|
1997
|
+
if (!DEVICE) void keepChats();
|
|
1996
1998
|
const now = mark(conversations.find((x) => x.name === current));
|
|
1997
1999
|
paintActions();
|
|
1998
2000
|
if (before !== now || now.startsWith('building') || now.startsWith('restarting') || now.startsWith('moving')) enter(true);
|
|
@@ -3267,11 +3269,13 @@
|
|
|
3267
3269
|
/* The places it may go, for a copy or a move of this one; the one chosen kept if it still is one. */
|
|
3268
3270
|
function cmPlaces(here) {
|
|
3269
3271
|
const machines = sharedMachines().filter((m) => !(cm.kind === 'move' && m.name === here.sharedMachine));
|
|
3270
|
-
|
|
3271
|
-
const
|
|
3272
|
+
/* Out of a shared machine (15-11): into one of its own, first; or into another shared one. */
|
|
3273
|
+
const own = cm.kind === 'copy' || Boolean(here.sharedMachine);
|
|
3274
|
+
const open = [...(own ? [''] : []), ...(cm.kind === 'move' && here.sharedMachine ? [] : [...machines.map((m) => m.name), 'new'])];
|
|
3272
3275
|
if (!open.includes(cm.place)) cm.place = open[0];
|
|
3273
3276
|
const cards = [];
|
|
3274
|
-
if (
|
|
3277
|
+
if (own) cards.push(cmCard('', uiSaid('set-where-own', 'Its own machine')));
|
|
3278
|
+
if (cm.kind === 'move' && here.sharedMachine) return { cards, open };
|
|
3275
3279
|
for (const m of machines) {
|
|
3276
3280
|
const small = [m.who.length ? uiSaid('set-cm-with', 'With {who}', { who: m.who.join(', ') }) : '', m.mb ? sizeWords(m.mb) : ''].filter(Boolean).join(' · ');
|
|
3277
3281
|
cards.push(cmCard(m.name, uiSaid('set-cm-shared', 'Shared machine « {m} »', { m: m.name }), small));
|
|
@@ -3316,9 +3320,10 @@
|
|
|
3316
3320
|
const here = conversations.find((x) => x.name === current);
|
|
3317
3321
|
if (DEVICE || !here || here.phase !== 'ready') return;
|
|
3318
3322
|
if (cm.of !== here.name) { $('cm-new-name').value = ''; $('cm-copy-title').value = ''; }
|
|
3319
|
-
Object.assign(cm, { of: here.name, kind, place: kind === 'copy' ? '' : (sharedMachines().find((m) => m.name !== here.sharedMachine)?.name ?? 'new') });
|
|
3323
|
+
Object.assign(cm, { of: here.name, kind, place: kind === 'copy' || here.sharedMachine ? '' : (sharedMachines().find((m) => m.name !== here.sharedMachine)?.name ?? 'new') });
|
|
3320
3324
|
$('machine-names').replaceChildren(...sharedMachines().map((m) => Object.assign(document.createElement('option'), { value: m.name })));
|
|
3321
3325
|
$('cm-copy-title').value = `${here.title ?? here.name} (copy)`;
|
|
3326
|
+
$('cm-reminders').checked = false;
|
|
3322
3327
|
/* Its sheep: two for a copy (the second slides out of the first), one walking for a move. */
|
|
3323
3328
|
if (!$('cm-sheep').childElementCount) $('cm-sheep').innerHTML = `<div class="mascot cm-one">${MASCOTS[MASCOT]()}</div><div class="mascot cm-one">${MASCOTS[MASCOT]()}</div>`;
|
|
3324
3329
|
$('cm-choose').hidden = false; $('cm-check').hidden = true;
|
|
@@ -3346,6 +3351,11 @@
|
|
|
3346
3351
|
$('cm-new-line')?.remove();
|
|
3347
3352
|
if (goes.machine && !goes.known) $('cm-check').prepend(Object.assign(document.createElement('p'), { id: 'cm-new-line', className: 'cm-not', textContent: uiSaid('set-cm-new-line', 'A new shared machine · {size}', { size: sizeWords(goes.machineMb) }) }));
|
|
3348
3353
|
$('cm-copy-part').hidden = cm.kind !== 'copy'; $('cm-move-part').hidden = cm.kind !== 'move';
|
|
3354
|
+
/* Out of a shared machine (15-11): its own machine is built, its place there removed -- the machine itself with the last one in it. */
|
|
3355
|
+
const out = cm.kind === 'move' && here.sharedMachine;
|
|
3356
|
+
const alone = out && !conversations.some((x) => x.name !== here.name && x.sharedMachine === here.sharedMachine);
|
|
3357
|
+
$('cm-stops').textContent = out ? uiSaid('set-cm-stops-out', 'Its tool stops for a few minutes') : uiSaid('set-cm-stops', 'Its tool stops for about a minute');
|
|
3358
|
+
$('cm-deleted').textContent = !out ? uiSaid('set-cm-deleted', 'Its own machine is deleted') : alone ? uiSaid('set-cm-shared-deleted', 'The shared machine « {m} » is deleted', { m: here.sharedMachine }) : uiSaid('set-cm-place-deleted', 'Its place in « {m} » is deleted', { m: here.sharedMachine });
|
|
3349
3359
|
$('cm-go').textContent = cm.kind === 'copy' ? uiSaid('set-cm-copy-go', 'Copy it') : uiSaid('set-cm-move-go', 'Move it');
|
|
3350
3360
|
$('cm-go').className = 'primary';
|
|
3351
3361
|
$('cm-choose').hidden = true; $('cm-check').hidden = false;
|
|
@@ -3369,7 +3379,7 @@
|
|
|
3369
3379
|
}
|
|
3370
3380
|
const title = $('cm-copy-title').value.trim() || `${here.title ?? here.name} (copy)`;
|
|
3371
3381
|
try {
|
|
3372
|
-
const made = await post(`${API}/conversations/${encodeURIComponent(name)}/copy`, { title, ...goes.body });
|
|
3382
|
+
const made = await post(`${API}/conversations/${encodeURIComponent(name)}/copy`, { title, ...goes.body, ...($('cm-reminders').checked ? { reminders: true } : {}) });
|
|
3373
3383
|
if (made?.name) copiesWatched.add(made.name);
|
|
3374
3384
|
await refresh();
|
|
3375
3385
|
} catch (error) { cmToast(`✗ ${error.message}`, 'bad'); }
|
|
@@ -3556,6 +3566,40 @@
|
|
|
3556
3566
|
send, the words of this device's language, and how a file is opened. */
|
|
3557
3567
|
let talk = { on: false, messages: [] };
|
|
3558
3568
|
let talkOf = '';
|
|
3569
|
+
/* KEPT CHATS (15-11): another conversation opened shows its chat at once, never a blank one while it
|
|
3570
|
+
comes. This page keeps, in memory only, each one's chat state and the end of its thread: fetched in
|
|
3571
|
+
the background, one at a time, for those of the list whose chat is on; again only when the list says
|
|
3572
|
+
it moved, and then only what changed (the server's cursor). The chat open keeps its own copy as it
|
|
3573
|
+
looks again. Opened, the copy is drawn at once, then the whole window is fetched and put in its place. */
|
|
3574
|
+
const KEPT_LAST = 50;
|
|
3575
|
+
const kept = new Map();
|
|
3576
|
+
/* Kept once loaded: an import() asked again resolves only after the next frame, a blank one. */
|
|
3577
|
+
let parleyLoaded = null;
|
|
3578
|
+
const parleyUi = () => (parleyLoaded ? Promise.resolve(parleyLoaded) : import(new URL('vendor/parley-ui.js', new URL(DEVICE ? '/c/' : '/', location.href)).href).then((m) => { parleyLoaded = m; return m; }));
|
|
3579
|
+
const keptOf = (name) => { if (!kept.has(name)) kept.set(name, { state: null, thread: null, mark: '' }); return kept.get(name); };
|
|
3580
|
+
let keeping = false;
|
|
3581
|
+
async function keepChats() {
|
|
3582
|
+
if (DEVICE || keeping || document.hidden) return;
|
|
3583
|
+
keeping = true;
|
|
3584
|
+
try {
|
|
3585
|
+
for (const n of [...kept.keys()]) if (!conversations.some((x) => x.name === n && x.talk)) kept.delete(n);
|
|
3586
|
+
const { since } = await parleyUi();
|
|
3587
|
+
for (const c of [...conversations]) {
|
|
3588
|
+
if (!c.talk || c.phase !== 'ready' || c.name === threadOf) continue;
|
|
3589
|
+
const mark = JSON.stringify(c.talk);
|
|
3590
|
+
const was = kept.get(c.name);
|
|
3591
|
+
if (was?.mark === mark && was.thread) continue;
|
|
3592
|
+
const cursor = typeof was?.thread?.cursor === 'string' && was.thread.cursor ? was.thread.cursor : null;
|
|
3593
|
+
const ask = (params) => fetch(talkPath(c.name, '', params)).then((r) => (r.ok ? r.json() : null)).catch(() => null);
|
|
3594
|
+
const [state, got] = await Promise.all([ask({ state: 1 }), ask({ last: KEPT_LAST, ...(cursor ? { since: cursor } : {}) })]);
|
|
3595
|
+
/* Opened meanwhile: its chat keeps its own copy. */
|
|
3596
|
+
if (c.name === threadOf) continue;
|
|
3597
|
+
if (state && state.on !== true) { kept.delete(c.name); continue; }
|
|
3598
|
+
if (!state || !Array.isArray(got?.messages)) continue;
|
|
3599
|
+
kept.set(c.name, { state, thread: cursor ? since(was.thread, got) : got, mark });
|
|
3600
|
+
}
|
|
3601
|
+
} finally { keeping = false; }
|
|
3602
|
+
}
|
|
3559
3603
|
let chatView = 'simple';
|
|
3560
3604
|
try { chatView = localStorage.getItem('clavarium-chat-view') === 'detailed' ? 'detailed' : 'simple'; } catch { /* a private window */ }
|
|
3561
3605
|
/* "Send when I stop", for dictation in the chat: kept by this device. */
|
|
@@ -3597,6 +3641,7 @@
|
|
|
3597
3641
|
/* Asked for the one before, answered once another was open: not taken for this one's. */
|
|
3598
3642
|
if (name !== current) return talk;
|
|
3599
3643
|
talk = got; talkOf = name;
|
|
3644
|
+
if (talk.on) keptOf(name).state = talk; else kept.delete(name);
|
|
3600
3645
|
return talk;
|
|
3601
3646
|
}
|
|
3602
3647
|
async function paintThread() {
|
|
@@ -3631,7 +3676,7 @@
|
|
|
3631
3676
|
thread?.destroy(); thread = null; threadOf = '';
|
|
3632
3677
|
const name = current;
|
|
3633
3678
|
/* From where this page is: a device's page lives under /c/, and nothing else is open to it. */
|
|
3634
|
-
const [{ mount }, words] = await Promise.all([
|
|
3679
|
+
const [{ mount, since }, words] = await Promise.all([parleyUi(), readWords()]);
|
|
3635
3680
|
if (name !== current || (thread && threadOf === current)) return;
|
|
3636
3681
|
threadOf = name;
|
|
3637
3682
|
/* The short-lived secrets live in this conversation now (secret-scan.mjs): the chat shows each as
|
|
@@ -3648,12 +3693,34 @@
|
|
|
3648
3693
|
return data.since === true ? { ...data, messages: [...data.messages.filter((m) => m.from !== 'system'), ...lines.values()] } : data;
|
|
3649
3694
|
};
|
|
3650
3695
|
let first = true;
|
|
3696
|
+
const shaped = (data, asked) => Promise.resolve(withLines(data, asked)).then(machineLines).then((d) => withMachine(d, name)).then((d) => { refreshSecrets(); if (first) { first = false; fadeIn(box); } return d; });
|
|
3697
|
+
/* Kept (15-11): its first look is the copy this page kept, drawn at once; the next one asks the whole
|
|
3698
|
+
window again (the copy may be a shorter one, or old), and it takes its place. Then as before. */
|
|
3699
|
+
let keptFirst = kept.get(name)?.thread ?? null;
|
|
3700
|
+
let whole = false;
|
|
3701
|
+
const keepThread = (data, asked) => {
|
|
3702
|
+
if (!Array.isArray(data?.messages) || asked.before || threadOf !== name) return data;
|
|
3703
|
+
const k = keptOf(name);
|
|
3704
|
+
k.thread = data.since === true ? (k.thread ? since(k.thread, data) : null) : data;
|
|
3705
|
+
k.mark = '';
|
|
3706
|
+
return data;
|
|
3707
|
+
};
|
|
3651
3708
|
thread = mount(box, {
|
|
3652
3709
|
words, view: chatView,
|
|
3653
3710
|
onView: (v) => { chatView = v; try { localStorage.setItem('clavarium-chat-view', v); } catch { /* as above */ } },
|
|
3654
3711
|
/* A part of the thread: its end at first, then what changed, the page before on demand (Parley's window). */
|
|
3655
3712
|
window: windowFor(chatWindow),
|
|
3656
|
-
load: (asked = {}) =>
|
|
3713
|
+
load: (asked = {}) => {
|
|
3714
|
+
if (keptFirst && !asked.since && !asked.before) {
|
|
3715
|
+
const data = keptFirst; keptFirst = null; whole = true;
|
|
3716
|
+
setTimeout(() => { if (thread && threadOf === name) void thread.refresh(); }, 0);
|
|
3717
|
+
return shaped(data, asked);
|
|
3718
|
+
}
|
|
3719
|
+
const { since: _since, ...all } = asked;
|
|
3720
|
+
const ask = whole && asked.since ? all : asked;
|
|
3721
|
+
whole = false;
|
|
3722
|
+
return fetch(talkPath(name, '', ask)).then((r) => r.json()).then((data) => keepThread(data, ask)).then((data) => shaped(data, ask));
|
|
3723
|
+
},
|
|
3657
3724
|
/* The whole thread searched, however little of it is shown. */
|
|
3658
3725
|
search: (q) => fetch(talkPath(name, '/search', { q })).then((r) => (r.ok ? r.json() : { matches: [], count: 0 })),
|
|
3659
3726
|
/* `via: 'voice'`: part of it was dictated, said to the tool. */
|
|
@@ -3884,7 +3951,13 @@
|
|
|
3884
3951
|
if (!current) return;
|
|
3885
3952
|
const name = current;
|
|
3886
3953
|
const mine = ++opening;
|
|
3887
|
-
|
|
3954
|
+
/* Kept (15-11): its chat drawn at once from the copy this page has; its state asked meanwhile, and
|
|
3955
|
+
the chat taken down only if it is off now. */
|
|
3956
|
+
const k = kept.get(name);
|
|
3957
|
+
if (k?.state?.on && k.thread) {
|
|
3958
|
+
talk = k.state; talkOf = name;
|
|
3959
|
+
void readTalk().then(() => { if (mine === opening && name === current && !talk.on) void paintThread(); });
|
|
3960
|
+
} else await readTalk();
|
|
3888
3961
|
if (mine !== opening || name !== current) return;
|
|
3889
3962
|
const want = talk.on || noTerminal() ? true : simplePref;
|
|
3890
3963
|
if (want !== simple) { simple = want; simpleFilesAt = 0; }
|
package/web/index.html
CHANGED
|
@@ -1515,13 +1515,14 @@
|
|
|
1515
1515
|
<label class="cm-label" for="cm-copy-title" data-said="set-cm-copy-name">Name of the copy</label>
|
|
1516
1516
|
<input id="cm-copy-title" maxlength="60">
|
|
1517
1517
|
<ul class="cm-goes"><li data-said="set-cm-goes-work">Its work folder</li><li data-said="set-cm-goes-memory">Its AI's memory</li><li data-said="set-cm-goes-access">Its accesses</li></ul>
|
|
1518
|
-
<
|
|
1518
|
+
<label class="cm-tick"><input type="checkbox" id="cm-reminders"> <span data-said="set-cm-reminders">Its reminders and wake-ups too</span></label>
|
|
1519
|
+
<p class="cm-not" data-said="set-cm-not-devices">Not its devices</p>
|
|
1519
1520
|
<p class="cm-box" data-said="set-cm-untouched">This one: untouched (woken or started to read it, then put back as it was)</p>
|
|
1520
1521
|
<p class="cm-box" data-said="set-cm-stay">You stay here · « Open it » when it is ready</p>
|
|
1521
1522
|
</div>
|
|
1522
1523
|
<div id="cm-move-part">
|
|
1523
|
-
<p class="cm-box" data-said="set-cm-stops">Its tool stops for about a minute</p>
|
|
1524
|
-
<p class="cm-box cm-danger" data-said="set-cm-deleted">Its own machine is deleted</p>
|
|
1524
|
+
<p class="cm-box" id="cm-stops" data-said="set-cm-stops">Its tool stops for about a minute</p>
|
|
1525
|
+
<p class="cm-box cm-danger" id="cm-deleted" data-said="set-cm-deleted">Its own machine is deleted</p>
|
|
1525
1526
|
</div>
|
|
1526
1527
|
<div class="cm-acts"><button type="button" id="cm-back" data-said="set-cm-back">Back</button><button type="button" class="primary" id="cm-go"></button></div>
|
|
1527
1528
|
</div>
|
package/web/style.css
CHANGED
|
@@ -500,7 +500,7 @@ details.chapter.reached { outline: 2px solid var(--brass); outline-offset: 2px;
|
|
|
500
500
|
.facts dd { margin: 0; overflow-wrap: anywhere; }
|
|
501
501
|
#machine-size, #shared-size { display: flex; flex-direction: column; gap: 6px; max-width: 30rem; }
|
|
502
502
|
#machine-size label, #shared-size label { font-size: .8125rem; color: var(--ink2); }
|
|
503
|
-
#machine-size select, #shared-size select, #cm :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; }
|
|
503
|
+
#machine-size select, #shared-size select, #cm :is(select, input:not([type=checkbox])) { 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); }
|
|
@@ -3122,6 +3122,8 @@ a.button[aria-disabled] { opacity: .5; pointer-events: none; }
|
|
|
3122
3122
|
.cm-goes { list-style: none; margin: 2px 0 0; padding: 0; font-size: .875rem; color: var(--ok); }
|
|
3123
3123
|
.cm-goes li::before { content: "\2713\00a0"; }
|
|
3124
3124
|
.cm-not { margin: 0; font-size: .75rem; color: var(--ink2); }
|
|
3125
|
+
.cm-tick { display: flex; align-items: center; justify-content: flex-start; gap: .5rem; font-size: .85rem; cursor: pointer; }
|
|
3126
|
+
#cm .cm-tick input { width: 18px; height: 18px; flex: none; margin: 0; accent-color: var(--brass); }
|
|
3125
3127
|
.cm-box { margin: 0; padding: 8px 11px; font-size: .875rem; border: 1px solid var(--line); border-radius: 8px; }
|
|
3126
3128
|
.cm-box.cm-danger { color: var(--danger); border-color: var(--danger); font-weight: 600; }
|
|
3127
3129
|
.cm-acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
|