clavarium 0.2.24-next.3 → 0.2.24-next.5
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 +6 -6
- package/package.json +2 -2
- package/server/dockets.mjs +4 -1
- package/server/gitkeeper.mjs +2 -2
- package/server/health.mjs +3 -1
- package/server/healthdocket.mjs +106 -0
- package/server/main.mjs +6 -0
- package/server/talk.mjs +2 -1
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.24-next.
|
|
3
|
+
"version": "0.2.24-next.5",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.24-next.
|
|
9
|
+
"version": "0.2.24-next.5",
|
|
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-binder": "0.1.0-next.1",
|
|
15
|
-
"clavarium-docket": "0.1.
|
|
15
|
+
"clavarium-docket": "0.1.1-next.1",
|
|
16
16
|
"clavarium-parley": "0.15.0-next.3",
|
|
17
17
|
"mermaid": "11.17.2",
|
|
18
18
|
"node-pty": "^1.1.0",
|
|
@@ -701,9 +701,9 @@
|
|
|
701
701
|
}
|
|
702
702
|
},
|
|
703
703
|
"node_modules/clavarium-docket": {
|
|
704
|
-
"version": "0.1.
|
|
705
|
-
"resolved": "https://registry.npmjs.org/clavarium-docket/-/clavarium-docket-0.1.
|
|
706
|
-
"integrity": "sha512-
|
|
704
|
+
"version": "0.1.1-next.1",
|
|
705
|
+
"resolved": "https://registry.npmjs.org/clavarium-docket/-/clavarium-docket-0.1.1-next.1.tgz",
|
|
706
|
+
"integrity": "sha512-GYt2o/J4RH3n9eEuE8BHU3bTUUleABe+1iPypxqpbllWfaiz8LDXmrhCm8YdcMaYySYq1NLt/ZJLahHp2dJ8Qw==",
|
|
707
707
|
"license": "MIT",
|
|
708
708
|
"bin": {
|
|
709
709
|
"docket": "bin/docket.mjs",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.24-next.
|
|
3
|
+
"version": "0.2.24-next.5",
|
|
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-binder": "0.1.0-next.1",
|
|
48
|
-
"clavarium-docket": "0.1.
|
|
48
|
+
"clavarium-docket": "0.1.1-next.1",
|
|
49
49
|
"clavarium-parley": "0.15.0-next.3",
|
|
50
50
|
"mermaid": "11.17.2",
|
|
51
51
|
"node-pty": "^1.1.0",
|
package/server/dockets.mjs
CHANGED
|
@@ -32,6 +32,9 @@ export const AGAIN_MS = 30 * 60_000;
|
|
|
32
32
|
/* ...this many times at most (the first included); then its chat says so. */
|
|
33
33
|
export const TOLD_MAX = 3;
|
|
34
34
|
|
|
35
|
+
/* One line in the chat: what was handled, cut short; the docket keeps it whole. */
|
|
36
|
+
const cut = (text, max) => { const s = String(text ?? '').replace(/\s+/g, ' ').trim(); return s.length > max ? `${s.slice(0, max - 1)}…` : s; };
|
|
37
|
+
|
|
35
38
|
export class Dockets {
|
|
36
39
|
#resources; #store; #say; #event; #alert; #idle; #awake; #chatOn; #now; #every; #zone;
|
|
37
40
|
#listening = new Map(); #zoned = new Set(); #busy = false;
|
|
@@ -97,7 +100,7 @@ export class Dockets {
|
|
|
97
100
|
|
|
98
101
|
/* What the tool did: said in its chat; a failure alerts its owner. */
|
|
99
102
|
#heard(name, e) {
|
|
100
|
-
if (e.type === 'acked' && e.ack.kind === 'done') this.#line(name, { kind: 'docket-done', text: `Handled: ${e.event.text}${e.ack.note ? ` -- ${e.ack.note}` : ''}`, topic: 'Handled', brief: e.event.text.slice(0, 60) });
|
|
103
|
+
if (e.type === 'acked' && e.ack.kind === 'done') this.#line(name, { kind: 'docket-done', text: `Handled: ${cut(e.event.text, 80)}${e.ack.note ? ` -- ${cut(e.ack.note, 120)}` : ''}`, topic: 'Handled', brief: e.event.text.slice(0, 60) });
|
|
101
104
|
if (e.type === 'acked' && e.ack.kind === 'failed') {
|
|
102
105
|
this.#line(name, { kind: 'docket-failed', text: `Could not be handled: ${e.event.text} -- ${e.ack.note}`, tone: 'warn', topic: 'Not handled' });
|
|
103
106
|
try { this.#alert({ title: `${name}: could not be handled`, body: `${e.event.text}: ${e.ack.note}`, url: `/?c=${name}` }); } catch { /* as said */ }
|
package/server/gitkeeper.mjs
CHANGED
|
@@ -568,7 +568,7 @@ export class GitKeeper {
|
|
|
568
568
|
}
|
|
569
569
|
try {
|
|
570
570
|
const sent = await this.#review.push(r.name, body);
|
|
571
|
-
if (!sent.already) this.#say(r.name, this.#attached(r.name), { kind: 'sent-by-hand', text: `Sent by hand
|
|
571
|
+
if (!sent.already) this.#say(r.name, this.#attached(r.name), { kind: 'sent-by-hand', text: `Sent by hand: ${r.name} → ${sent.branch}, ${commitsOf(sent.commits)}${sent.made ? ', a new branch' : ''}.`, topic: 'Sent', brief: sent.branch, actions: seeCommits(r.name, sent.head, sent.base, sent.commits) });
|
|
572
572
|
return sent;
|
|
573
573
|
} catch (error) {
|
|
574
574
|
if (error instanceof GitFailure) this.#sendFailed(r.name, error, { branch: body?.target, head: body?.head });
|
|
@@ -682,7 +682,7 @@ export class GitKeeper {
|
|
|
682
682
|
if (sent.already) { this.#log(name, { branch: b, head: tip.id, conversation, ok: true, what: `Already on the remote: ${b}.` }, { sent: true, by: conversation }); return true; }
|
|
683
683
|
this.#log(name, { branch: b, head: tip.id, conversation, ok: true, what: `Sent automatically for ${conversation}: ${sent.commits} commit(s) to ${sent.branch}${sent.made ? ' (a new branch)' : ''}, ${checked}.${sent.note ? ` ${sent.note}` : ''}` }, { sent: true, by: conversation });
|
|
684
684
|
if (alert) this.#tell(`${name}: sent to ${sent.branch}`, `${sent.commits} commit(s), automatically for ${conversation}, ${checked}.`);
|
|
685
|
-
this.#say(name, [conversation], { kind: 'sent', text: `Sent
|
|
685
|
+
this.#say(name, [conversation], { kind: 'sent', text: `Sent: ${name} → ${sent.branch}, ${commitsOf(sent.commits)}${sent.made ? ', a new branch' : ''}${s.checks ? '' : ', no checks'}.`, topic: 'Sent', brief: sent.branch, actions: seeCommits(name, sent.head, sent.base, sent.commits) });
|
|
686
686
|
return true;
|
|
687
687
|
} catch (error) {
|
|
688
688
|
const kind = error instanceof GitFailure ? error.kind : 'error';
|
package/server/health.mjs
CHANGED
|
@@ -128,6 +128,8 @@ export class Health {
|
|
|
128
128
|
#vms; #conversations; #resources; #records = new Map(); #running = new Map(); #quiet = new Map(); #settleMs; #probeMs; #lookMs; #seen;
|
|
129
129
|
/* Set by the server: told each judgment (the chat of a conversation says what is wrong: talk.mjs). */
|
|
130
130
|
judged = () => {};
|
|
131
|
+
/* Set by the server: told a conversation is forgotten (what else is kept of its machine goes too). */
|
|
132
|
+
forgotten = () => {};
|
|
131
133
|
|
|
132
134
|
/* `settleMs`: how long a missing folder is given before it is mounted
|
|
133
135
|
again (a machine that has just started may still be mounting it).
|
|
@@ -148,7 +150,7 @@ export class Health {
|
|
|
148
150
|
this.#seen?.put({ name, keys, at: new Date().toISOString() });
|
|
149
151
|
return this.of(name);
|
|
150
152
|
}
|
|
151
|
-
forget(name) { this.#records.delete(name); this.#quiet.delete(name); this.#seen?.remove?.(name); }
|
|
153
|
+
forget(name) { this.#records.delete(name); this.#quiet.delete(name); this.#seen?.remove?.(name); try { this.forgotten(name); } catch { /* told */ } }
|
|
152
154
|
|
|
153
155
|
/* The look under way (it may be mounting a folder again), or null. */
|
|
154
156
|
busy(name) { return this.#running.get(name) ?? null; }
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/* A MACHINE SHORT OF ROOM, TOLD TO ITS AGENT THROUGH ITS DOCKET (dockets.mjs),
|
|
2
|
+
* where its chat is on -- nowhere else. Its owner is told as before (talk.mjs,
|
|
3
|
+
* healthreact.mjs); this is on top: one event per threshold crossed, which the
|
|
4
|
+
* agent handles and acknowledges (docket done / failed: said in its chat).
|
|
5
|
+
*
|
|
6
|
+
* disk (/ and /work, each) at DISK_LEVELS of its size used
|
|
7
|
+
* memory at MEMORY_LEVELS used, at SUSTAINED looks in a row
|
|
8
|
+
* (health.mjs looks every two minutes: a peak is not news)
|
|
9
|
+
* out of memory the whole machine (not a program at its own limit),
|
|
10
|
+
* each time it happens again, OOM_QUIET_MS apart at least
|
|
11
|
+
*
|
|
12
|
+
* NO REPEAT: a level is posted once; again only when it got worse (the next
|
|
13
|
+
* level) or after it went below its REARM (a few points under it) and came
|
|
14
|
+
* back. What was posted is kept in a store, so a restart of the server does
|
|
15
|
+
* not post it again.
|
|
16
|
+
*
|
|
17
|
+
* Not where its owner chose its own reaction (healthreact.mjs): its agent is told
|
|
18
|
+
* one way, not two.
|
|
19
|
+
*
|
|
20
|
+
* Only a machine that runs and answered is judged: one that does not answer
|
|
21
|
+
* cannot read its docket, and what it has is not known (nothing changes).
|
|
22
|
+
*
|
|
23
|
+
* judged(name, record) told each judgment by health.mjs
|
|
24
|
+
* forget(name)
|
|
25
|
+
*/
|
|
26
|
+
export const DISK_LEVELS = [85, 95];
|
|
27
|
+
export const MEMORY_LEVELS = [90, 97];
|
|
28
|
+
/* Below this many points under a level, it may be posted again. */
|
|
29
|
+
export const REARM = 5;
|
|
30
|
+
export const SUSTAINED = 2;
|
|
31
|
+
export const OOM_QUIET_MS = 60 * 60_000;
|
|
32
|
+
export const KIND = 'machine-health';
|
|
33
|
+
|
|
34
|
+
const ACK = 'then say what you did (docket done ID "what")';
|
|
35
|
+
|
|
36
|
+
/* The highest level reached by `percent`, 0 when none. */
|
|
37
|
+
const reached = (percent, levels) => levels.reduce((n, l, i) => (percent >= l ? i + 1 : n), 0);
|
|
38
|
+
/* What is kept of `before` once at `percent`: a level stays posted until it is REARM under it. */
|
|
39
|
+
const kept = (before, percent, levels) => { let n = before; while (n > 0 && percent < levels[n - 1] - REARM) n -= 1; return n; };
|
|
40
|
+
|
|
41
|
+
export function diskText(path, percent) {
|
|
42
|
+
return path === '/'
|
|
43
|
+
? `Disk of your machine at ${percent}% (/): free space -- caches, temporary files, build outputs -- ${ACK}.`
|
|
44
|
+
: `Work folder of your machine at ${percent}% (${path}): free space without losing work -- caches, build outputs -- ${ACK}.`;
|
|
45
|
+
}
|
|
46
|
+
export function memoryText(percent) {
|
|
47
|
+
return `Memory of your machine at ${percent}% for several minutes: stop what is no longer needed -- servers, watchers, builds left running -- ${ACK}.`;
|
|
48
|
+
}
|
|
49
|
+
export function oomText(times) {
|
|
50
|
+
return `Your machine ran out of memory${times > 1 ? ` (${times} times since it started)` : ''}: a program was stopped. Run less at once, ${ACK}.`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export class HealthDocket {
|
|
54
|
+
#store; #dockets; #now;
|
|
55
|
+
#reacting;
|
|
56
|
+
/* `dockets`: { on(name), post(name, {kind, text, data}) } (dockets.mjs). `reacting(name)`: its owner
|
|
57
|
+
turned on its own reaction to a machine short of room (healthreact.mjs). */
|
|
58
|
+
constructor({ store, dockets, reacting = () => false, now = () => Date.now() }) { this.#store = store; this.#dockets = dockets; this.#reacting = reacting; this.#now = now; }
|
|
59
|
+
|
|
60
|
+
forget(name) { this.#store.remove?.(name); }
|
|
61
|
+
|
|
62
|
+
judged(name, record) {
|
|
63
|
+
if (!record || record.state !== 'Running' || record.answering !== true) return [];
|
|
64
|
+
if (!this.#dockets.on(name) || this.#reacting(name)) return [];
|
|
65
|
+
const before = this.#store.get(name) ?? {};
|
|
66
|
+
const r = { name, disks: { ...(before.disks ?? {}) }, memory: { ...(before.memory ?? {}) }, ...(before.oom ? { oom: { ...before.oom } } : {}) };
|
|
67
|
+
const posted = [];
|
|
68
|
+
/* Posted, or not (its folder cannot be written): then tried again at the next look. */
|
|
69
|
+
const post = (text, data) => {
|
|
70
|
+
try { posted.push(this.#dockets.post(name, { kind: KIND, text, data })); return true; } catch { return false; }
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
for (const [path, d] of Object.entries(record.disks ?? {})) {
|
|
74
|
+
if (!(d.sizeMb > 0)) continue;
|
|
75
|
+
const percent = Math.round(100 * (d.sizeMb - d.availableMb) / d.sizeMb);
|
|
76
|
+
const was = kept(r.disks[path] ?? 0, percent, DISK_LEVELS);
|
|
77
|
+
const now = reached(percent, DISK_LEVELS);
|
|
78
|
+
r.disks[path] = now > was && post(diskText(path, percent), { health: 'disk', path, percent, level: DISK_LEVELS[now - 1] }) ? now : was;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const m = record.memory;
|
|
82
|
+
if (m && m.totalMb > 0) {
|
|
83
|
+
const percent = Math.round(100 * (m.totalMb - m.availableMb) / m.totalMb);
|
|
84
|
+
const now = reached(percent, MEMORY_LEVELS);
|
|
85
|
+
/* Looks in a row at a level or above. */
|
|
86
|
+
const high = now > 0 ? (r.memory.high ?? 0) + 1 : 0;
|
|
87
|
+
const was = kept(r.memory.level ?? 0, percent, MEMORY_LEVELS);
|
|
88
|
+
const sent = now > was && high >= SUSTAINED && post(memoryText(percent), { health: 'memory', percent, level: MEMORY_LEVELS[now - 1] });
|
|
89
|
+
r.memory = { level: sent ? now : was, high };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/* The whole machine out of memory (the kernel's own words: health.mjs). Within the quiet time,
|
|
93
|
+
the count kept is not raised: told once it is over. A count lower than the one kept: the
|
|
94
|
+
machine started again, the count with it. */
|
|
95
|
+
const times = record.oomKinds?.machine;
|
|
96
|
+
if (Number.isInteger(times)) {
|
|
97
|
+
const last = r.oom ?? { count: 0, at: 0 };
|
|
98
|
+
const sent = times > last.count && this.#now() - last.at >= OOM_QUIET_MS && post(oomText(times), { health: 'oom', times });
|
|
99
|
+
r.oom = sent ? { count: times, at: this.#now() } : { count: Math.min(times, last.count), at: last.at };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const state = (x) => JSON.stringify([x.disks ?? {}, x.memory ?? {}, x.oom ?? null]);
|
|
103
|
+
if (state(r) !== state(before)) this.#store.put(r);
|
|
104
|
+
return posted;
|
|
105
|
+
}
|
|
106
|
+
}
|
package/server/main.mjs
CHANGED
|
@@ -61,6 +61,7 @@ import { Updates } from './updates.mjs';
|
|
|
61
61
|
import { Certificate } from './certificate.mjs';
|
|
62
62
|
import { Operators } from './operators.mjs';
|
|
63
63
|
import { HealthReact } from './healthreact.mjs';
|
|
64
|
+
import { HealthDocket } from './healthdocket.mjs';
|
|
64
65
|
import { MachinesMove } from './machinesmove.mjs';
|
|
65
66
|
import { Wifi } from './wifi.mjs';
|
|
66
67
|
import { Binders } from './binders.mjs';
|
|
@@ -438,10 +439,15 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
438
439
|
/* And what its owner chose that it does on top (healthreact.mjs): its agent told, or a command run. */
|
|
439
440
|
const reacting = new HealthReact({ store: new Store(`${dataDir}/health-react.json`), say: (name, line) => wakeups.say(name, line), exec: (name, argv, options) => vms.exec(name, argv, options),
|
|
440
441
|
isAgent: (name) => all.list().find((c) => c.name === name)?.ai === true, event: (name, line) => talk.event(name, line) });
|
|
442
|
+
/* Where its chat is on, its agent is given an event when its disk or memory crosses a level (healthdocket.mjs);
|
|
443
|
+
not where its owner turned on its own reaction (above): one way of telling it, not two. */
|
|
444
|
+
const healthDocket = new HealthDocket({ store: new Store(`${dataDir}/health-docket.json`), dockets, reacting: (name) => reacting.settings(name).on });
|
|
445
|
+
health.forgotten = (name) => healthDocket.forget(name);
|
|
441
446
|
/* A machine's problems worth keeping in What happened: said once, until they went away. */
|
|
442
447
|
const problemsSaid = new Map();
|
|
443
448
|
health.judged = (name, record) => {
|
|
444
449
|
talk.machine(name, record); void reacting.judged(name, record).catch(() => {});
|
|
450
|
+
try { healthDocket.judged(name, record); } catch { /* its docket: nothing more */ }
|
|
445
451
|
const now = (record?.problems ?? []).filter((x) => x.level === 'bad' || (x.level === 'warn' && ['memory', 'disk'].includes(x.kind)));
|
|
446
452
|
const before = problemsSaid.get(name) ?? new Set();
|
|
447
453
|
for (const x of now) if (!before.has(x.key)) events.add({ kind: 'machine', text: `${name}: ${x.text}`, conversation: name });
|
package/server/talk.mjs
CHANGED
|
@@ -148,7 +148,8 @@ export const EVENT_LEVELS = Object.freeze({
|
|
|
148
148
|
/* New tools in its machine that its tool reads only when it starts: a restart recommended (main.mjs). */
|
|
149
149
|
'tools-updated': 'news',
|
|
150
150
|
/* Its docket (dockets.mjs): what it handled, what it could not, what it never did; a reminder it set itself. */
|
|
151
|
-
|
|
151
|
+
/* What it handled is a trace by default: one line, in the detailed view; what failed or was never handled calls. */
|
|
152
|
+
'docket-done': 'trace',
|
|
152
153
|
'docket-failed': 'needs-you',
|
|
153
154
|
'docket-unhandled': 'needs-you',
|
|
154
155
|
'docket-reminder': 'trace',
|