clavarium 0.2.22 → 0.2.23-next.2
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/README.md +4 -1
- package/deploy/clavarium-host +2 -0
- package/npm-shrinkwrap.json +6 -6
- package/package.json +2 -2
- package/server/capacity.mjs +11 -2
- package/server/conversations.mjs +2 -1
- package/server/gitkeeper.mjs +29 -3
- package/server/main.mjs +1 -1
- package/server/shelf.mjs +2 -0
- package/server/talk.mjs +17 -5
- package/web/app.js +371 -65
- package/web/index.html +51 -47
- package/web/style.css +172 -25
package/README.md
CHANGED
|
@@ -104,7 +104,10 @@ Built slice by slice; the plan is in `blueprint/architecture.html`, tab
|
|
|
104
104
|
under /work/.parley/files/, the tool given its path). What is wrong with its
|
|
105
105
|
machine, and its restarts, are grey lines in the thread, with what can be
|
|
106
106
|
done; after a restart the tool is told once to read the whole thread again
|
|
107
|
-
(`parley read --all`).
|
|
107
|
+
(`parley read --all`). The server keeps its own copy of the thread, out of
|
|
108
|
+
the machine: a line the tool rewrites or deletes in /work/.parley, the
|
|
109
|
+
owner's too, is shown as it was, and the thread says "History changed
|
|
110
|
+
here". Off by default, per conversation; what the tool
|
|
108
111
|
prints in its terminal is never read.
|
|
109
112
|
|
|
110
113
|
- **13 - the machine**: each conversation's machine is looked at after a
|
package/deploy/clavarium-host
CHANGED
|
@@ -87,6 +87,8 @@ SHELF_CACHE="$SHELF_STORE/cache"
|
|
|
87
87
|
# (No drop-in is the usual case: under pipefail a missing file must not stop this program.)
|
|
88
88
|
MOVED_TO="$( { sed -n 's/^Environment=MULTIPASS_STORAGE=\(\/[A-Za-z0-9/._-]*\)$/\1/p' /etc/systemd/system/snap.multipass.multipassd.service.d/override.conf 2>/dev/null || true; } | head -1)"
|
|
89
89
|
if [ -n "$MOVED_TO" ] && [ -d "$MOVED_TO/data" ]; then SHELF_STORE="$MOVED_TO"; SHELF_INSTANCES="$MOVED_TO/data/vault/instances"; SHELF_CACHE="$MOVED_TO/cache"; fi
|
|
90
|
+
# Also the floor under a grown disk (grow_room): the server keeps the same
|
|
91
|
+
# (MIN_FREE_MB in server/shelf.mjs, used by server/capacity.mjs).
|
|
90
92
|
SHELF_MIN_FREE_MB="6144"
|
|
91
93
|
CONF="/etc/clavarium/host.conf"
|
|
92
94
|
# THE GIT READER (verb "git read"): an empty root-owned directory used as the
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.23-next.2",
|
|
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.23-next.2",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
|
13
13
|
"@xterm/xterm": "^6.0.0",
|
|
14
14
|
"clavarium-docket": "0.1.0",
|
|
15
|
-
"clavarium-parley": "0.
|
|
15
|
+
"clavarium-parley": "0.14.0-next.1",
|
|
16
16
|
"mermaid": "11.17.2",
|
|
17
17
|
"node-pty": "^1.1.0",
|
|
18
18
|
"pdfjs-dist": "6.4.299",
|
|
@@ -700,9 +700,9 @@
|
|
|
700
700
|
}
|
|
701
701
|
},
|
|
702
702
|
"node_modules/clavarium-parley": {
|
|
703
|
-
"version": "0.
|
|
704
|
-
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.
|
|
705
|
-
"integrity": "sha512-
|
|
703
|
+
"version": "0.14.0-next.1",
|
|
704
|
+
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.14.0-next.1.tgz",
|
|
705
|
+
"integrity": "sha512-hPscRjPaoh9Jjucjt0C48DSiOOEwVj2ZUBBs0iGL7rIZlqC/GuxwFq6KvlSqWVyVFuyOwRsO7OdpGcuYVsWjZQ==",
|
|
706
706
|
"license": "MIT",
|
|
707
707
|
"bin": {
|
|
708
708
|
"parley": "bin/parley.mjs",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.23-next.2",
|
|
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.",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@xterm/addon-fit": "^0.11.0",
|
|
46
46
|
"@xterm/xterm": "^6.0.0",
|
|
47
47
|
"clavarium-docket": "0.1.0",
|
|
48
|
-
"clavarium-parley": "0.
|
|
48
|
+
"clavarium-parley": "0.14.0-next.1",
|
|
49
49
|
"mermaid": "11.17.2",
|
|
50
50
|
"node-pty": "^1.1.0",
|
|
51
51
|
"pdfjs-dist": "6.4.299",
|
package/server/capacity.mjs
CHANGED
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
* nothing is refused: the reserve is a guard, not a gate that jams.
|
|
37
37
|
*/
|
|
38
38
|
import { Refusal, DISK_GB } from './conversations.mjs';
|
|
39
|
+
import { MIN_FREE_MB } from './shelf.mjs';
|
|
39
40
|
|
|
40
41
|
export const RESERVE_DISK_MB = 5 * 1024;
|
|
41
42
|
export const RESERVE_MEMORY_MB = 1024;
|
|
@@ -244,8 +245,16 @@ export class Capacity {
|
|
|
244
245
|
throw new Refusal(409, `${verb}: this server cannot spare ${asks}. It has ${gb(f.memory.freeMb)} of memory free and keeps ${gb(r.memoryMb)} in reserve. ${what}, or lower the reserve in Settings, This server.`);
|
|
245
246
|
}
|
|
246
247
|
const takes = kind === 'create' ? (this.#shelf?.about?.().current?.sizeMb ?? NEW_MACHINE_MB) : diskMb;
|
|
247
|
-
|
|
248
|
-
|
|
248
|
+
/* A disk grown: the host program refuses it under its own floor
|
|
249
|
+
(grow_room in deploy/clavarium-host: what it grows by, plus
|
|
250
|
+
SHELF_MIN_FREE_MB), whatever reserve is set here. The same rule
|
|
251
|
+
here, so that it is refused before anything is stopped. */
|
|
252
|
+
if (f.disk && kind === 'grow' && takes > 0) {
|
|
253
|
+
const needMb = takes + Math.max(r.diskMb, MIN_FREE_MB);
|
|
254
|
+
if (f.disk.freeMb < needMb) throw new Refusal(409, `${verb}: ${gb(f.disk.freeMb)} of disk free, ${gb(needMb)} needed.`);
|
|
255
|
+
}
|
|
256
|
+
if (f.disk && kind === 'create' && takes > 0 && f.disk.freeMb - takes < r.diskMb) {
|
|
257
|
+
const asks = `the ${gb(takes)} of disk a new machine takes`;
|
|
249
258
|
throw new Refusal(409, `${verb}: this server cannot spare ${asks}. It has ${gb(f.disk.freeMb)} of disk free and keeps ${gb(r.diskMb)} in reserve. Archive conversations you no longer need, or lower the reserve in Settings, This server.`);
|
|
250
259
|
}
|
|
251
260
|
}
|
package/server/conversations.mjs
CHANGED
|
@@ -201,7 +201,8 @@ export class Conversations {
|
|
|
201
201
|
|
|
202
202
|
/* `resumes`: the tool can take up its last session when it starts (`resume` in config/tools.json). */
|
|
203
203
|
/* `rights`: it can be started with every right in its machine (`rights` in config/tools.json). */
|
|
204
|
-
|
|
204
|
+
/* `ai`: an agent that reads instructions (`instructions`), not a bare terminal. */
|
|
205
|
+
tools() { return this.#tools.map(({ id, label, memoryMb, resume, rights, instructions }) => ({ id, label, memoryMb, resumes: Boolean(resume), rights: Boolean(rights), ai: Boolean(instructions) })); }
|
|
205
206
|
|
|
206
207
|
/* The sign-in rules of a conversation's tool, or undefined. */
|
|
207
208
|
signinRules(name) { return this.#tools.find((t) => t.id === this.#store.get(name)?.tool)?.signin; }
|
package/server/gitkeeper.mjs
CHANGED
|
@@ -207,8 +207,13 @@ const upTo = (id) => (short(id) ? ` (up to ${short(id)})` : '');
|
|
|
207
207
|
/* "See the N commits": from the tip before to the tip now, as the review shows them; none for a new branch. */
|
|
208
208
|
const seeCommits = (name, head, base, n) => (short(head) && short(base) && Number.isInteger(n) && n > 0 ? [`commits:${name}.${head.slice(0, 12)}.${base.slice(0, 12)}.${Math.min(n, 9999)}`] : []);
|
|
209
209
|
|
|
210
|
+
/* How long one request waits for a check before it hears it still runs (a proxy cuts longer ones), and how
|
|
211
|
+
long a finished run is kept for the request that asks again just after. */
|
|
212
|
+
export const CHECK_WAIT_MS = 20_000;
|
|
213
|
+
export const CHECK_KEEP_MS = 60_000;
|
|
214
|
+
|
|
210
215
|
export class GitKeeper {
|
|
211
|
-
#store; #review; #resources; #checks; #alerts; #now; #tellAgent; #thread; #last; #held = new Map(); #results = new Map(); #running = new Set(); #telling = new Map();
|
|
216
|
+
#store; #review; #resources; #checks; #alerts; #now; #tellAgent; #thread; #last; #held = new Map(); #results = new Map(); #running = new Set(); #telling = new Map(); #inFlight = new Map();
|
|
212
217
|
|
|
213
218
|
/* `review`: GitReview (reads, the reference, Send). `checks`: GitChecks.
|
|
214
219
|
`alerts`: what tells the owner's phone. `tellAgent(repository, line,
|
|
@@ -480,7 +485,28 @@ export class GitKeeper {
|
|
|
480
485
|
const target = body?.target || undefined;
|
|
481
486
|
const seen = typeof body?.head === 'string' ? this.#review.reviewOf(r.name, body.head, target) : undefined;
|
|
482
487
|
if (!seen) throw new Refusal(409, 'The repository changed since you looked: look again at what would be sent.');
|
|
483
|
-
return this.#
|
|
488
|
+
return this.#joined(r.name, seen, body?.wait, body?.join === true);
|
|
489
|
+
}
|
|
490
|
+
/* A CHECK OUTLIVES THE REQUEST THAT ASKED FOR IT. It may take minutes (dependencies installed, then the
|
|
491
|
+
tests), longer than a proxy on the way lets one request wait: the page was cut off and said "could not
|
|
492
|
+
run" while the checks ran on. So the run is kept here by repository, commit and target; a request
|
|
493
|
+
waits for it at most CHECK_WAIT_MS, then hears { status: 'running' } and asks again, joining the same run. */
|
|
494
|
+
/* A run still going is always joined; one just ended only by `join` (the page asking again after
|
|
495
|
+
"running"): any other ask is a new run, as before. */
|
|
496
|
+
async #joined(name, seen, wait, join = false) {
|
|
497
|
+
const key = `${name}\n${seen.head}\n${seen.target ?? ''}`;
|
|
498
|
+
let entry = this.#inFlight.get(key);
|
|
499
|
+
if (!entry || (entry.done && !join)) {
|
|
500
|
+
const made = { done: false };
|
|
501
|
+
made.run = this.#check(name, seen).finally(() => { made.done = true; setTimeout(() => { if (this.#inFlight.get(key) === made) this.#inFlight.delete(key); }, CHECK_KEEP_MS).unref?.(); });
|
|
502
|
+
this.#inFlight.set(key, made);
|
|
503
|
+
entry = made;
|
|
504
|
+
}
|
|
505
|
+
const run = entry.run;
|
|
506
|
+
const ms = Number.isFinite(wait) ? Math.max(0, Math.min(wait, CHECK_WAIT_MS)) : CHECK_WAIT_MS;
|
|
507
|
+
let timer;
|
|
508
|
+
const pending = new Promise((ok) => { timer = setTimeout(() => ok({ status: 'running', head: seen.head, branch: seen.branch, target: seen.target }), ms); });
|
|
509
|
+
try { return await Promise.race([run, pending]); } finally { clearTimeout(timer); }
|
|
484
510
|
}
|
|
485
511
|
/* `machine`: the conversation whose machine runs them (automatic sending). */
|
|
486
512
|
async #check(name, seen, machine) {
|
|
@@ -520,7 +546,7 @@ export class GitKeeper {
|
|
|
520
546
|
const branch = typeof body?.branch === 'string' && body.branch ? body.branch : undefined;
|
|
521
547
|
const out = await this.#review.outgoing(r.name, { target, branch });
|
|
522
548
|
if (!out?.head || !out.target) throw new Refusal(409, out?.message || 'There is no commit to check on this branch.');
|
|
523
|
-
return this.#
|
|
549
|
+
return this.#joined(r.name, { head: out.head, branch: out.branch, target: out.target, remoteTip: out.remoteTip ?? null }, body?.wait);
|
|
524
550
|
}
|
|
525
551
|
|
|
526
552
|
/* Send, from the page: as GitReview.push, and refused when the owner
|
package/server/main.mjs
CHANGED
|
@@ -388,7 +388,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
388
388
|
checks: new GitChecks({ vms, conversations: all, resources: folders }) });
|
|
389
389
|
const gitTimer = gitKeeper.start(gitEveryMs);
|
|
390
390
|
/* A conversation with a tool on a screen that is not its terminal: see talk.mjs. */
|
|
391
|
-
const talk = new Talk({ store: talkStore, words: new Store(`${dataDir}/talk-words.json`), vms, conversations: all, resources: folders, toolbox, warm: (name) => bridge?.warm(name), ...(talkEveryMs ? { listenEveryMs: talkEveryMs } : {}),
|
|
391
|
+
const talk = new Talk({ store: talkStore, words: new Store(`${dataDir}/talk-words.json`), keptDir: `${dataDir}/talk-kept`, vms, conversations: all, resources: folders, toolbox, warm: (name) => bridge?.warm(name), ...(talkEveryMs ? { listenEveryMs: talkEveryMs } : {}),
|
|
392
392
|
...(rereadAfterMs === undefined ? {} : { rereadAfterMs }),
|
|
393
393
|
/* A line typed down the terminal already open when there is one, and
|
|
394
394
|
what is already known of a machine used instead of asking (talk.mjs). */
|
package/server/shelf.mjs
CHANGED
|
@@ -35,6 +35,8 @@ export const REFRESH_MS = 30 * DAY;
|
|
|
35
35
|
/* A little more than a month: a monthly rebuild that failed for a few days
|
|
36
36
|
does not send every new conversation the long way at once. */
|
|
37
37
|
export const MAX_AGE_MS = 40 * DAY;
|
|
38
|
+
/* SHELF_MIN_FREE_MB of deploy/clavarium-host, which refuses under it too:
|
|
39
|
+
a rebuild, and a disk grown (on top of what it grows by: capacity.mjs). */
|
|
38
40
|
export const MIN_FREE_MB = 6 * 1024;
|
|
39
41
|
/* After a failed or refused rebuild, the next automatic try waits this long. */
|
|
40
42
|
export const RETRY_MS = DAY;
|
package/server/talk.mjs
CHANGED
|
@@ -40,6 +40,13 @@
|
|
|
40
40
|
* AFTER A RESTART the tool starts again with no memory of the
|
|
41
41
|
* chat: once it had time to start, REREAD is typed
|
|
42
42
|
* in its terminal, once (it reads the whole thread).
|
|
43
|
+
* THE THREAD, KEPT HERE Parley's own copy (its `keep`): every line read
|
|
44
|
+
* or written is kept in this server's data, one
|
|
45
|
+
* folder per conversation, out of the machine's
|
|
46
|
+
* reach. That copy is what the page shows; a line
|
|
47
|
+
* the tool rewrote or deleted in /work/.parley --
|
|
48
|
+
* the person's too -- is said in the thread
|
|
49
|
+
* ("History changed here"), never taken.
|
|
43
50
|
* FILES OF THE PERSON attached to a message, put under
|
|
44
51
|
* /work/.parley/files/<id>/<name>, and the message
|
|
45
52
|
* gives the tool their paths.
|
|
@@ -51,7 +58,7 @@
|
|
|
51
58
|
*/
|
|
52
59
|
import { posix, join } from 'node:path';
|
|
53
60
|
import { randomUUID } from 'node:crypto';
|
|
54
|
-
import { mkdirSync, lstatSync } from 'node:fs';
|
|
61
|
+
import { mkdirSync, lstatSync, rmSync } from 'node:fs';
|
|
55
62
|
import { install, Parley, WAKE, REREAD, texts, fill, LANGUAGES, SHOWN_MAX, FILES_MAX } from 'clavarium-parley/host';
|
|
56
63
|
import { importFile } from './files.mjs';
|
|
57
64
|
import { KEYS } from 'clavarium-parley/ui';
|
|
@@ -152,15 +159,18 @@ const WORDS = Object.freeze([...KEYS, 'alert-asks', 'alert-waits']);
|
|
|
152
159
|
export class Talk {
|
|
153
160
|
#store; #words; #vms; #conversations; #resources; #toolbox; #warm; #alert; #listening = new Map(); #every; #now;
|
|
154
161
|
#typedAt = new Map(); #nextTry = new Map(); #trying = new Map(); #timer; #lastLang = 'en'; #rereadAfter;
|
|
155
|
-
#terminal; #health; #ranAt = new Map();
|
|
162
|
+
#terminal; #health; #ranAt = new Map(); #kept;
|
|
156
163
|
|
|
157
164
|
/* `alert({ title, body, url })`: told when the tool asks, or waits.
|
|
158
165
|
`words`: a store for the owner's choice of words (one record). */
|
|
159
166
|
/* `terminal`: the terminals the bridge keeps open (bridge.mjs): `open(name)`,
|
|
160
167
|
`type(name, line, enterAfterMs)`, `droppedAt(name)`. `health`: what was
|
|
161
168
|
last seen of each machine (health.mjs), `of(name)`. Both optional. */
|
|
162
|
-
|
|
163
|
-
|
|
169
|
+
/* `keptDir`: where each conversation's thread is kept (its own folder),
|
|
170
|
+
in this server's data -- never in the work folder, which its machine
|
|
171
|
+
writes. Without it, the bridge folder is all there is. */
|
|
172
|
+
constructor({ store, words, vms, conversations, resources, toolbox = null, warm = async () => {}, alert = () => {}, listenEveryMs = 2000, now = () => Date.now(), rereadAfterMs = REREAD_AFTER_MS, terminal = null, health = null, keptDir = null }) {
|
|
173
|
+
this.#terminal = terminal; this.#health = health; this.#kept = keptDir;
|
|
164
174
|
this.#store = store; this.#words = words; this.#vms = vms; this.#conversations = conversations; this.#resources = resources; this.#toolbox = toolbox; this.#warm = warm; this.#alert = alert; this.#every = listenEveryMs; this.#now = now; this.#rereadAfter = rereadAfterMs;
|
|
165
175
|
for (const s of store.all()) if (s.on === true) this.#listen(s.name);
|
|
166
176
|
this.#timer = setInterval(() => { void this.#tick(); }, Math.min(listenEveryMs, 1000));
|
|
@@ -173,6 +183,7 @@ export class Talk {
|
|
|
173
183
|
return c;
|
|
174
184
|
}
|
|
175
185
|
#dir(name) { return `${this.#resources.workFolder(name)}/${FOLDER}`; }
|
|
186
|
+
#keep(name) { return this.#kept && isConversationName(name) ? join(this.#kept, name) : undefined; }
|
|
176
187
|
|
|
177
188
|
/* ---- the words a person reads ---- */
|
|
178
189
|
settings() {
|
|
@@ -241,6 +252,7 @@ export class Talk {
|
|
|
241
252
|
|
|
242
253
|
#parley(name, reacted = () => {}) {
|
|
243
254
|
return new Parley(this.#dir(name), {
|
|
255
|
+
keep: this.#keep(name),
|
|
244
256
|
reach: (path) => this.#reach(name, path),
|
|
245
257
|
on: (event) => {
|
|
246
258
|
if (event.type === 'person-reacted') { reacted(event); return; }
|
|
@@ -572,6 +584,6 @@ export class Talk {
|
|
|
572
584
|
}
|
|
573
585
|
}
|
|
574
586
|
|
|
575
|
-
forget(name) { this.#deaf(name); this.#store.remove(name); this.#typedAt.delete(name); this.#ranAt.delete(name); this.#nextTry.delete(name); this.#nextTry.delete(`reread:${name}`); }
|
|
587
|
+
forget(name) { this.#deaf(name); if (this.#keep(name)) rmSync(this.#keep(name), { recursive: true, force: true }); this.#store.remove(name); this.#typedAt.delete(name); this.#ranAt.delete(name); this.#nextTry.delete(name); this.#nextTry.delete(`reread:${name}`); }
|
|
576
588
|
stop() { clearInterval(this.#timer); for (const name of [...this.#listening.keys()]) this.#deaf(name); }
|
|
577
589
|
}
|