clavarium 0.2.226-next.1 → 0.2.228-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/deploy/clavarium-host +11 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/api.mjs +10 -2
- package/server/conversations.mjs +24 -5
- package/server/vm.mjs +2 -0
- package/web/app.js +31 -0
- package/web/index.html +4 -3
- package/web/style.css +5 -0
package/deploy/clavarium-host
CHANGED
|
@@ -1137,6 +1137,17 @@ case "$AREA $VERB" in
|
|
|
1137
1137
|
if [ -d "$at" ] && [ ! -L "$at" ]; then rmdir "$at" 2>/dev/null || true; fi
|
|
1138
1138
|
if [ -f "$img" ] && [ ! -L "$img" ]; then mv -n "$img" "$MNT/removed/$1-work-$(date -u +%Y%m%dT%H%M%SZ)-$$.img"; fi
|
|
1139
1139
|
exit 0 ;;
|
|
1140
|
+
"work erase")
|
|
1141
|
+
# Deleted for good, or its machine reset, BY ITS OWNER, after a confirmation that names the conversation
|
|
1142
|
+
# (01-11): its work disk is ERASED, not put aside. Only that one file and its mount point.
|
|
1143
|
+
[ $# -eq 1 ] || usage; is_name "$1" || refuse "not a conversation name: $1"
|
|
1144
|
+
img="$MNT/work-disks/$1.img"; at="$MNT/work/$1"
|
|
1145
|
+
if [ "$SAY" = "yes" ]; then printf 'disk %s erased\n' "$img"; exit 0; fi
|
|
1146
|
+
kept work; kept work-disks
|
|
1147
|
+
if mountpoint -q "$at"; then umount "$at" || refuse "the work disk of $1 is in use"; fi
|
|
1148
|
+
if [ -d "$at" ] && [ ! -L "$at" ]; then rmdir "$at" 2>/dev/null || true; fi
|
|
1149
|
+
if [ -f "$img" ] && [ ! -L "$img" ]; then rm -f -- "$img"; fi
|
|
1150
|
+
exit 0 ;;
|
|
1140
1151
|
"view make")
|
|
1141
1152
|
[ $# -eq 1 ] || usage; is_name "$1" || refuse "not a folder name: $1"
|
|
1142
1153
|
folder_of "$1"; kept views
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.228-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.228-next.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
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
* POST /api/conversations/<name>/health/seen what it says now no longer calls its owner (Needs you)
|
|
15
15
|
* POST /api/conversations/<name>/exit-report why its tool ended: { now (read in its machine, if it runs), last (kept at its end) }
|
|
16
16
|
* POST /api/conversations/<name>/archive
|
|
17
|
+
* POST /api/conversations/<name>/erase {confirm: <its name>}: deleted for good -- its machine and its work files
|
|
18
|
+
* POST /api/conversations/<name>/rebuild {reset?, confirm?}: built again; reset (confirm: its name) for a working one too
|
|
17
19
|
* 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
|
|
18
20
|
* POST /api/conversations/<name>/resume {on}: its tool takes up its last session when it starts (true), or starts fresh
|
|
19
21
|
* POST /api/conversations/<name>/terminal/repair its terminal does not come though its machine runs: repaired
|
|
@@ -710,10 +712,16 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
710
712
|
return send(200, await repair(conversation)), true;
|
|
711
713
|
}
|
|
712
714
|
const again = /^\/api\/conversations\/([^/]+)\/rebuild$/.exec(pathname);
|
|
713
|
-
if (again)
|
|
714
|
-
|
|
715
|
+
if (again) {
|
|
716
|
+
const reset = body?.reset === true;
|
|
717
|
+
if (reset && String(body?.confirm ?? '') !== decodeURIComponent(again[1])) throw new Refusal(400, 'Type the name of the conversation to reset it.');
|
|
718
|
+
return send(202, await conversations.rebuild(decodeURIComponent(again[1]), { reset })), true;
|
|
719
|
+
}
|
|
720
|
+
const action = /^\/api\/conversations\/([^/]+)\/(sleep|archive|erase)$/.exec(pathname);
|
|
721
|
+
if (action?.[2] === 'erase' && String(body?.confirm ?? '') !== decodeURIComponent(action[1])) throw new Refusal(400, 'Type the name of the conversation to delete it for good.');
|
|
715
722
|
if (!action) return send(404, { error: 'Not found.' }), true;
|
|
716
723
|
await conversations[action[2]](decodeURIComponent(action[1]));
|
|
724
|
+
if (action[2] === 'erase') action[2] = 'archive'; /* what it leaves behind is forgotten as for an archive */
|
|
717
725
|
if (action[2] === 'archive') resources?.forget(decodeURIComponent(action[1]));
|
|
718
726
|
if (action[2] === 'archive') gitKeeper?.forgetConversation(decodeURIComponent(action[1]));
|
|
719
727
|
if (action[2] === 'archive') sharing?.devices.forget(decodeURIComponent(action[1]));
|
package/server/conversations.mjs
CHANGED
|
@@ -383,23 +383,27 @@ export class Conversations {
|
|
|
383
383
|
on the old machine's disk is not brought back: nothing here can.
|
|
384
384
|
A conversation that has a working machine is refused -- this is not a
|
|
385
385
|
reset button. */
|
|
386
|
-
|
|
386
|
+
/* `reset` (01-11, its owner's ask, confirmed by typing its name): a working machine too -- deleted with
|
|
387
|
+
everything on it and its work files, and built anew; its settings and what is attached to it stay. */
|
|
388
|
+
async rebuild(name, { reset = false } = {}) {
|
|
387
389
|
const c = this.#store.get(name);
|
|
388
390
|
if (!c) throw new Refusal(404, 'No such conversation.');
|
|
389
|
-
if (c.phase === 'building') throw new Refusal(409, 'This conversation is still being built.');
|
|
391
|
+
if (c.phase === 'building' && !reset) throw new Refusal(409, 'This conversation is still being built.');
|
|
390
392
|
const tool = this.#tools.find((t) => t.id === c.tool);
|
|
391
393
|
if (!tool) throw new Refusal(400, 'The tool of this conversation is no longer offered.');
|
|
392
394
|
const state = await this.#vms.state(name, { fresh: true });
|
|
393
|
-
if (state !== undefined && c.phase !== 'failed') throw new Refusal(409, 'This conversation has its machine: there is nothing to build again.');
|
|
394
|
-
|
|
395
|
+
if (state !== undefined && c.phase !== 'failed' && !reset) throw new Refusal(409, 'This conversation has its machine: there is nothing to build again.');
|
|
396
|
+
/* A reset replaces its own machine: the room it takes is given back first. */
|
|
397
|
+
if (!(reset && state !== undefined)) await this.room({ kind: 'create', name, memoryMb: c.memoryMb });
|
|
395
398
|
this.#cancelStop(name);
|
|
396
399
|
this.drop(name);
|
|
397
400
|
/* Marked first: two requests cannot both start a build. */
|
|
398
401
|
const now = new Date().toISOString();
|
|
399
402
|
this.#store.patch(name, { phase: 'building', step: 'Starting the machine', error: undefined, asleep: false, buildingSince: now, progress: buildProgress(now) });
|
|
400
403
|
this.built = (async () => {
|
|
401
|
-
/* What a failed build left behind is cleared away first. */
|
|
404
|
+
/* What a failed build left behind is cleared away first; a reset, its files too. */
|
|
402
405
|
if (state !== undefined) await this.#vms.remove(name);
|
|
406
|
+
if (reset && c.work === 'kept') await this.#vms.workErase(name);
|
|
403
407
|
return this.#build(name, tool, c.memoryMb, true);
|
|
404
408
|
})();
|
|
405
409
|
return this.#store.get(name);
|
|
@@ -1257,6 +1261,21 @@ export class Conversations {
|
|
|
1257
1261
|
if (kept) await this.#vms.workAside(name);
|
|
1258
1262
|
}
|
|
1259
1263
|
|
|
1264
|
+
/* DELETED FOR GOOD (01-11, its owner's ask, confirmed by typing its name): as archived, but its work is
|
|
1265
|
+
erased, not put aside. Whatever state its machine is in -- one that never started too. */
|
|
1266
|
+
async erase(name) {
|
|
1267
|
+
if (!this.#store.get(name)) throw new Refusal(404, 'No such conversation.');
|
|
1268
|
+
this.#cancelStop(name);
|
|
1269
|
+
this.drop(name);
|
|
1270
|
+
const kept = this.#store.get(name).work === 'kept';
|
|
1271
|
+
this.#store.remove(name);
|
|
1272
|
+
if (await this.#vms.state(name, { fresh: true }) !== undefined) await this.#vms.remove(name);
|
|
1273
|
+
if (kept) {
|
|
1274
|
+
const r = await this.#vms.workErase(name);
|
|
1275
|
+
if (r?.code) throw new Refusal(500, `Its machine is deleted, but its files could not be erased: ${firstLine(r.stderr) || `exit ${r.code}`}`);
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1260
1279
|
#cancelStop(name) {
|
|
1261
1280
|
const timer = this.#timers.get(name);
|
|
1262
1281
|
if (timer) { clearTimeout(timer); this.#timers.delete(name); }
|
package/server/vm.mjs
CHANGED
|
@@ -151,6 +151,8 @@ export class Vms {
|
|
|
151
151
|
return r.code === 0 && m ? { disk: Number(m[1]), host: Number(m[2]) } : undefined;
|
|
152
152
|
}
|
|
153
153
|
workAside(conversation) { vmName(conversation); return this.run(['work', 'aside', conversation]); }
|
|
154
|
+
/* Deleted for good, or reset, by its owner: its work disk erased, not put aside. */
|
|
155
|
+
workErase(conversation) { vmName(conversation); return this.run(['work', 'erase', conversation]); }
|
|
154
156
|
|
|
155
157
|
/* The tools folder (see toolbox.mjs), shown read-only at /tools. */
|
|
156
158
|
mountTools(conversation, uid, gid) {
|
package/web/app.js
CHANGED
|
@@ -849,6 +849,7 @@
|
|
|
849
849
|
const c = conversations.find((x) => x.name === current);
|
|
850
850
|
const usable = Boolean(c) && c.phase === 'ready' && !holds(c);
|
|
851
851
|
$('archive').hidden = !c;
|
|
852
|
+
$('reset-machine').hidden = $('erase-conversation').hidden = !c || DEVICE;
|
|
852
853
|
$('files-open').hidden = $('share').hidden = !usable;
|
|
853
854
|
/* Given its chat alone: the files of the chat open from the chat; Files holds only what was given to the device itself. */
|
|
854
855
|
if (noTerminal()) $('files-open').hidden = deviceShared.length === 0;
|
|
@@ -9181,6 +9182,36 @@
|
|
|
9181
9182
|
catch (error) { show(error.message, 'Close', enter); }
|
|
9182
9183
|
}
|
|
9183
9184
|
$('archive').addEventListener('click', () => { void archive(false); });
|
|
9185
|
+
/* RESET or DELETE FOR GOOD (01-11): whatever state its machine is in -- one that never started too. Both
|
|
9186
|
+
erase, so its name is typed first; nothing is done until it matches. */
|
|
9187
|
+
let sureAction = null;
|
|
9188
|
+
function askSure(what, button, action) {
|
|
9189
|
+
const c = conversations.find((x) => x.name === current); if (!c) return;
|
|
9190
|
+
sureAction = { name: c.name, shown: shownName(c), action };
|
|
9191
|
+
$('sure-what').textContent = `${what} Type « ${shownName(c)} » to confirm.`;
|
|
9192
|
+
$('sure-go').textContent = button; $('sure-go').disabled = true; $('sure-name').value = '';
|
|
9193
|
+
$('sure-form').hidden = false; focusField($('sure-name'));
|
|
9194
|
+
}
|
|
9195
|
+
const sureClose = () => { sureAction = null; $('sure-form').hidden = true; };
|
|
9196
|
+
$('sure-name').addEventListener('input', () => { $('sure-go').disabled = !sureAction || $('sure-name').value.trim() !== sureAction.shown; });
|
|
9197
|
+
$('sure-cancel').addEventListener('click', sureClose);
|
|
9198
|
+
$('sure-form').addEventListener('submit', (event) => {
|
|
9199
|
+
event.preventDefault();
|
|
9200
|
+
if (!sureAction || $('sure-name').value.trim() !== sureAction.shown) return;
|
|
9201
|
+
const { name, action } = sureAction; sureClose(); void action(name);
|
|
9202
|
+
});
|
|
9203
|
+
$('reset-machine').addEventListener('click', () => askSure('Reset: its machine and its files are erased, and a new empty machine is built. Its settings and attached assets stay.', 'Reset', async (name) => {
|
|
9204
|
+
leavePanel(); disconnect();
|
|
9205
|
+
say('building', 'connecting'); show('Resetting: a new machine is being built...');
|
|
9206
|
+
try { await post(`${API}/conversations/${encodeURIComponent(name)}/rebuild`, { reset: true, confirm: name }); await refresh(); enter(); }
|
|
9207
|
+
catch (error) { show(error.message, 'Close', enter); }
|
|
9208
|
+
}));
|
|
9209
|
+
$('erase-conversation').addEventListener('click', () => askSure('Delete for good: its machine and its files are erased; nothing is put aside. Attached assets stay where they are.', 'Delete for good', async (name) => {
|
|
9210
|
+
leavePanel(); disconnect();
|
|
9211
|
+
say('archiving', 'connecting'); show('Deleting for good...');
|
|
9212
|
+
try { await post(`${API}/conversations/${encodeURIComponent(name)}/erase`, { confirm: name }); await refresh(); select(''); }
|
|
9213
|
+
catch (error) { show(error.message, 'Close', enter); }
|
|
9214
|
+
}));
|
|
9184
9215
|
/* "<" of a conversation (a phone): the list, as Back does. */
|
|
9185
9216
|
$('back').addEventListener('click', () => { if (!nav.close('room')) select(''); });
|
|
9186
9217
|
|
package/web/index.html
CHANGED
|
@@ -351,10 +351,11 @@
|
|
|
351
351
|
</div>
|
|
352
352
|
</details>
|
|
353
353
|
<details class="chapter" id="chapter-advanced" data-chapter="advanced">
|
|
354
|
-
<summary><span class="chapter-title">Advanced</span><span class="chapter-about">Archive it.</span></summary>
|
|
354
|
+
<summary><span class="chapter-title">Advanced</span><span class="chapter-about">Archive, reset or delete it.</span></summary>
|
|
355
355
|
<div class="chapter-body">
|
|
356
|
-
<p class="hint">
|
|
357
|
-
<div class="row" id="conversation-actions"><button type="button" id="archive" hidden>Archive...</button></div>
|
|
356
|
+
<p class="hint">Archive: its machine is deleted; its files are put aside on the server. Reset: a new machine, empty; settings and attached assets stay. Delete for good: nothing is kept.</p>
|
|
357
|
+
<div class="row" id="conversation-actions"><button type="button" id="archive" hidden>Archive...</button><button type="button" id="reset-machine" class="danger" hidden>Reset...</button><button type="button" id="erase-conversation" class="danger" hidden>Delete for good...</button></div>
|
|
358
|
+
<form id="sure-form" class="row sure" autocomplete="off" hidden><label for="sure-name" id="sure-what"></label><input id="sure-name" spellcheck="false" autocomplete="off"><button type="submit" id="sure-go" class="danger" disabled></button><button type="button" id="sure-cancel">Cancel</button></form>
|
|
358
359
|
</div>
|
|
359
360
|
</details>
|
|
360
361
|
</div>
|
package/web/style.css
CHANGED
|
@@ -2098,3 +2098,8 @@ body.as-dragging #assets-rows .as-row { touch-action: none; }
|
|
|
2098
2098
|
.chooser-option:hover, .chooser-option:focus-visible { background: var(--bar); }
|
|
2099
2099
|
.chooser-option[aria-selected="true"] { font-weight: 600; }
|
|
2100
2100
|
.chooser-none { padding: 8px 10px; color: var(--ink2); }
|
|
2101
|
+
|
|
2102
|
+
/* Typing the conversation's name before an erasing action. */
|
|
2103
|
+
.sure { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
|
|
2104
|
+
.sure label { flex: 1 1 100%; color: var(--ink2); }
|
|
2105
|
+
.sure input { flex: 1 1 12em; min-width: 0; }
|