clavarium 0.2.9-next.1 → 0.2.10-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/api.mjs +9 -1
- package/server/health.mjs +19 -5
- package/server/main.mjs +1 -1
- package/server/talk.mjs +1 -1
- package/web/app.js +26 -13
- package/web/index.html +1 -1
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10-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.10-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
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* POST /api/conversations/<name>/machine {memoryMb?, diskGb?}: stopped, set, started again
|
|
9
9
|
* GET /api/conversations/<name>/health what was last seen of its machine
|
|
10
10
|
* POST /api/conversations/<name>/health look now (never wakes a machine)
|
|
11
|
+
* POST /api/conversations/<name>/health/seen what it says now no longer calls its owner (Needs you)
|
|
11
12
|
* POST /api/conversations/<name>/archive
|
|
12
13
|
* 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
|
|
13
14
|
* POST /api/conversations/<name>/resume {on}: its tool takes up its last session when it starts (true), or starts fresh
|
|
@@ -522,12 +523,19 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
522
523
|
}
|
|
523
524
|
const moved = /^\/api\/conversations\/([^/]+)\/work$/.exec(pathname);
|
|
524
525
|
if (moved) return send(202, await conversations.moveWork(decodeURIComponent(moved[1]), body.to)), true;
|
|
526
|
+
/* "Seen": what its machine says now no longer calls its owner (health.mjs). */
|
|
527
|
+
const seenOf = /^\/api\/conversations\/([^/]+)\/health\/seen$/.exec(pathname);
|
|
528
|
+
if (seenOf && health) {
|
|
529
|
+
const conversation = decodeURIComponent(seenOf[1]);
|
|
530
|
+
if (!conversations.list().some((c) => c.name === conversation)) throw new Refusal(404, 'No such conversation.');
|
|
531
|
+
return send(200, health.markSeen(conversation)), true;
|
|
532
|
+
}
|
|
525
533
|
const machine = /^\/api\/conversations\/([^/]+)\/(restart|machine|health)$/.exec(pathname);
|
|
526
534
|
if (machine) {
|
|
527
535
|
const conversation = decodeURIComponent(machine[1]);
|
|
528
536
|
if (machine[2] === 'health') {
|
|
529
537
|
if (!health || !conversations.list().some((c) => c.name === conversation)) throw new Refusal(404, 'No such conversation.');
|
|
530
|
-
|
|
538
|
+
await health.check(conversation, { asked: true }); return send(200, health.of(conversation)), true;
|
|
531
539
|
}
|
|
532
540
|
if (machine[2] === 'restart') return send(202, await conversations.restart(conversation)), true;
|
|
533
541
|
return send(202, await conversations.resize(conversation, { memoryMb: body.memoryMb, diskGb: body.diskGb, cpus: body.cpus })), true;
|
package/server/health.mjs
CHANGED
|
@@ -95,7 +95,8 @@ export function judge(record) {
|
|
|
95
95
|
else if (s !== 'Running') add('bad', 'state', `state:${s}`, `The VM manager says its machine is "${s}".`);
|
|
96
96
|
if (s === 'Running') {
|
|
97
97
|
if (record.answering === false) add('bad', 'answer', 'silent', 'Its machine does not answer. Restarting it usually helps.');
|
|
98
|
-
|
|
98
|
+
/* Said once a day at most, with how many: a tool that runs out of memory again and again (on purpose, sometimes) is one line, not one a look. */
|
|
99
|
+
if (record.oomKills > 0) add('warn', 'memory', `oom:${String(record.at ?? new Date().toISOString()).slice(0, 10)}`, `It ran out of memory${record.oomKills === 1 ? '' : ` ${record.oomKills} times`} since it started: a program in it was stopped. Its files are safe.`);
|
|
99
100
|
if (record.memory && record.memory.totalMb > 0 && record.memory.availableMb < Math.max(MEMORY_LOW_MB, record.memory.totalMb * 0.05)) add('warn', 'memory', 'memory-low', `Its memory is almost full: ${record.memory.availableMb} MB free of ${record.memory.totalMb} MB.`);
|
|
100
101
|
for (const [path, d] of Object.entries(record.disks ?? {})) {
|
|
101
102
|
if (d.sizeMb > 0 && d.availableMb < Math.max(DISK_LOW_MB, d.sizeMb * 0.1)) add('warn', 'disk', `disk:${path}`, `${path === '/' ? 'Its disk' : `Its work folder (${path})`} is almost full: ${d.availableMb} MB left of ${d.sizeMb} MB.`);
|
|
@@ -110,20 +111,30 @@ export function judge(record) {
|
|
|
110
111
|
}
|
|
111
112
|
|
|
112
113
|
export class Health {
|
|
113
|
-
#vms; #conversations; #resources; #records = new Map(); #running = new Map(); #quiet = new Map(); #settleMs; #probeMs; #lookMs;
|
|
114
|
+
#vms; #conversations; #resources; #records = new Map(); #running = new Map(); #quiet = new Map(); #settleMs; #probeMs; #lookMs; #seen;
|
|
114
115
|
/* Set by the server: told each judgment (the chat of a conversation says what is wrong: talk.mjs). */
|
|
115
116
|
judged = () => {};
|
|
116
117
|
|
|
117
118
|
/* `settleMs`: how long a missing folder is given before it is mounted
|
|
118
119
|
again (a machine that has just started may still be mounting it).
|
|
119
120
|
`lookMs`: how long the clock waits for one conversation's look. */
|
|
120
|
-
|
|
121
|
+
/* `seen`: a store of the problems its owner marked seen ("Seen"), by conversation. */
|
|
122
|
+
constructor({ vms, conversations, resources, settleMs = 5000, probeMs = PROBE_MS, lookMs = LOOK_MS, seen = null }) {
|
|
123
|
+
this.#seen = seen;
|
|
121
124
|
this.#vms = vms; this.#conversations = conversations; this.#resources = resources; this.#settleMs = settleMs; this.#probeMs = probeMs; this.#lookMs = lookMs;
|
|
122
125
|
}
|
|
123
126
|
|
|
124
127
|
/* The last thing known, or null. Cheap: nothing is asked. */
|
|
125
|
-
of(name) {
|
|
126
|
-
|
|
128
|
+
of(name) { const r = this.#records.get(name); return r ? { ...r, seen: this.#seen?.get(name)?.keys ?? [] } : null; }
|
|
129
|
+
/* "Seen": what it says now no longer calls its owner (Needs you); a problem of another kind, or one
|
|
130
|
+
that comes back after it went away, does. */
|
|
131
|
+
markSeen(name) {
|
|
132
|
+
const r = this.#records.get(name);
|
|
133
|
+
const keys = (r?.problems ?? []).filter((p) => p.level === 'warn' || p.level === 'bad').map((p) => p.key);
|
|
134
|
+
this.#seen?.put({ name, keys });
|
|
135
|
+
return this.of(name);
|
|
136
|
+
}
|
|
137
|
+
forget(name) { this.#records.delete(name); this.#quiet.delete(name); this.#seen?.remove?.(name); }
|
|
127
138
|
|
|
128
139
|
/* The look under way (it may be mounting a folder again), or null. */
|
|
129
140
|
busy(name) { return this.#running.get(name) ?? null; }
|
|
@@ -194,6 +205,9 @@ export class Health {
|
|
|
194
205
|
|
|
195
206
|
#keep(name, record) {
|
|
196
207
|
const kept = { ...record, ...judge(record) };
|
|
208
|
+
/* What was marked seen and is gone is forgotten: back later, it calls its owner again. */
|
|
209
|
+
const seen = this.#seen?.get(name);
|
|
210
|
+
if (seen && record.state === 'Running' && record.answering === true) { const still = seen.keys.filter((k) => kept.problems.some((p) => p.key === k)); if (still.length !== seen.keys.length) this.#seen.put({ name, keys: still }); }
|
|
197
211
|
this.#records.set(name, kept);
|
|
198
212
|
try { this.judged(name, kept); } catch { /* told, nothing more */ }
|
|
199
213
|
return kept;
|
package/server/main.mjs
CHANGED
|
@@ -371,7 +371,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
371
371
|
/* A device given a conversation that talks through the app talks there too. */
|
|
372
372
|
door.talk = talk;
|
|
373
373
|
/* The health of each machine, and folders that came loose put back: see health.mjs. */
|
|
374
|
-
const health = new Health({ vms, conversations: all, resources: folders, ...(healthSettleMs === undefined ? {} : { settleMs: healthSettleMs }) });
|
|
374
|
+
const health = new Health({ vms, conversations: all, resources: folders, seen: new Store(`${dataDir}/health-seen.json`), ...(healthSettleMs === undefined ? {} : { settleMs: healthSettleMs }) });
|
|
375
375
|
const stopHealth = health.start(healthEveryMs);
|
|
376
376
|
/* What is wrong with its machine is said in its chat too, where it happened. */
|
|
377
377
|
/* And what its owner chose that it does on top (healthreact.mjs): its agent told, or a command run. */
|
package/server/talk.mjs
CHANGED
|
@@ -445,7 +445,7 @@ export class Talk {
|
|
|
445
445
|
topic: 'Machine',
|
|
446
446
|
/* What can be done: a disk short of room is looked at (what takes it) or made larger --
|
|
447
447
|
a restart frees nothing; otherwise more memory where memory is short, a restart, its terminal. */
|
|
448
|
-
actions: fresh.every((p) => p.kind === 'disk') ? ['room', 'disk'] : [...(fresh.some((p) => p.kind === 'memory') ? ['memory'] : []), 'restart', 'terminal'],
|
|
448
|
+
actions: [...(fresh.every((p) => p.kind === 'disk') ? ['room', 'disk'] : [...(fresh.some((p) => p.kind === 'memory') ? ['memory'] : []), 'restart', 'terminal']), 'seen'],
|
|
449
449
|
});
|
|
450
450
|
}
|
|
451
451
|
|
package/web/app.js
CHANGED
|
@@ -855,8 +855,10 @@
|
|
|
855
855
|
/* It needs its owner: it asks or waits, its answerer asks, it failed, its machine is unwell. Said even when it is hidden. */
|
|
856
856
|
/* Its tool asks or waits for its owner, and the owner has not written since (talk.mjs, brief). */
|
|
857
857
|
const talkNeeds = (c) => Boolean(c.talk && (c.talk.needs ?? (c.talk.waiting > 0 || c.talk.state === 'waiting')));
|
|
858
|
-
|
|
859
|
-
|
|
858
|
+
/* Its machine calls its owner for what needs a hand -- it does not serve, its memory or disk is almost
|
|
859
|
+
full -- not marked "Seen"; a program stopped for lack of memory (its files safe) is only said. */
|
|
860
|
+
const healthNeeds = (c) => c.phase === 'ready' && !c.asleep && (c.health?.problems ?? []).some((p) => (p.level === 'bad' || (p.level === 'warn' && ['memory', 'disk'].includes(p.kind) && !String(p.key).startsWith('oom:'))) && !(c.health.seen ?? []).includes(p.key));
|
|
861
|
+
const needsYou = (c) => Boolean(talkNeeds(c) || c.answerer?.needs || c.phase === 'failed' || healthNeeds(c));
|
|
860
862
|
/* Hidden conversations are shown on a click on "N hidden", for this page only. */
|
|
861
863
|
let showHidden = false;
|
|
862
864
|
/* Recent: a few, or all of them (for this page only). */
|
|
@@ -942,7 +944,8 @@
|
|
|
942
944
|
head.setAttribute('aria-expanded', String(open));
|
|
943
945
|
const caret = document.createElement('span'); caret.className = 'caret'; caret.setAttribute('aria-hidden', 'true'); caret.textContent = '›';
|
|
944
946
|
const name = document.createElement('span'); name.className = 'group-name'; name.textContent = label;
|
|
945
|
-
|
|
947
|
+
/* A number only: the name keeps the room (its words for a screen reader). */
|
|
948
|
+
const count = document.createElement('small'); count.className = 'count'; count.textContent = String(all.length);
|
|
946
949
|
count.setAttribute('aria-label', `${all.length} conversation${all.length > 1 ? 's' : ''}`);
|
|
947
950
|
/* A small dot for each (up to six); the one that needs you is said even folded. */
|
|
948
951
|
const dots = document.createElement('span'); dots.className = 'group-dots'; dots.setAttribute('aria-hidden', 'true');
|
|
@@ -990,7 +993,8 @@
|
|
|
990
993
|
if (needs.length && section(NEEDS, 'Needs you', needs.length)) top.append(...needs.map((c) => itemButton(c, true)));
|
|
991
994
|
/* RECENT: by when it was last used; the last four, then all. Never a hidden one. Only once there
|
|
992
995
|
are groups: before, the one list below says the same, in the order chosen by hand. */
|
|
993
|
-
|
|
996
|
+
/* One in Needs you just above is not said twice. */
|
|
997
|
+
const recent = conversations.filter((c) => (c.hidden !== true || c.name === current) && !needsYou(c)).sort((a, b) => activityOf(b) - activityOf(a));
|
|
994
998
|
const few = 4;
|
|
995
999
|
if (recent.length && groups.length && section(RECENT, 'Recent', recent.length)) {
|
|
996
1000
|
top.append(...recent.slice(0, showAllRecent ? recent.length : few).map((c) => itemButton(c, true)));
|
|
@@ -1734,14 +1738,16 @@
|
|
|
1734
1738
|
function paintHealth() {
|
|
1735
1739
|
const c = conversations.find((x) => x.name === current);
|
|
1736
1740
|
const h = c?.health;
|
|
1737
|
-
|
|
1738
|
-
const
|
|
1741
|
+
/* What it says that was not marked "Seen" (health.mjs): the strip is for those only. */
|
|
1742
|
+
const shown = (h?.problems ?? []).filter((p) => (p.level === 'warn' || p.level === 'bad') && !(h.seen ?? []).includes(p.key));
|
|
1743
|
+
const serious = shown.length > 0 && c.phase === 'ready' && !c.asleep;
|
|
1744
|
+
const level = shown.some((p) => p.level === 'bad') ? 'bad' : 'warn';
|
|
1745
|
+
const key = serious ? `${current}:${shown.map((p) => p.text).join('|')}` : '';
|
|
1739
1746
|
$('health-strip').hidden = !serious || key === healthDismissed;
|
|
1740
1747
|
/* Running, but not well: the dot beside "live" says so too. */
|
|
1741
|
-
state.dataset.health = serious ?
|
|
1748
|
+
state.dataset.health = serious ? level : '';
|
|
1742
1749
|
if (!serious) return;
|
|
1743
|
-
$('health-strip').dataset.level =
|
|
1744
|
-
const shown = h.problems.filter((p) => p.level === 'warn' || p.level === 'bad');
|
|
1750
|
+
$('health-strip').dataset.level = level;
|
|
1745
1751
|
$('health-text').textContent = shown.map((p) => p.text).join(' ');
|
|
1746
1752
|
/* What can be done, from here: more memory where memory is short, a restart, its terminal when the chat is in front.
|
|
1747
1753
|
A disk short of room: what takes it, in the terminal, and (on a wide screen) a larger disk -- a restart frees nothing. */
|
|
@@ -1751,7 +1757,8 @@
|
|
|
1751
1757
|
$('health-disk').hidden = DEVICE || !disk || narrow();
|
|
1752
1758
|
$('health-restart').hidden = DEVICE || diskOnly;
|
|
1753
1759
|
$('health-terminal').hidden = !simple || noTerminal() || disk;
|
|
1754
|
-
|
|
1760
|
+
/* "Seen", for every screen: it no longer calls its owner until something else comes (a device: only here). */
|
|
1761
|
+
$('health-dismiss').onclick = () => { healthDismissed = key; $('health-strip').hidden = true; if (!DEVICE) void markSeen(); };
|
|
1755
1762
|
}
|
|
1756
1763
|
/* "More memory...": its memory, ready to be chosen -- the next size up already picked, applied only once asked. */
|
|
1757
1764
|
async function openMemory() {
|
|
@@ -1778,6 +1785,12 @@
|
|
|
1778
1785
|
disk.focus({ preventScroll: true });
|
|
1779
1786
|
}
|
|
1780
1787
|
/* Its terminal, asked for: never shown by itself in place of its chat. */
|
|
1788
|
+
/* "Seen": what its machine says now no longer puts it in Needs you (health.mjs). */
|
|
1789
|
+
async function markSeen() {
|
|
1790
|
+
if (!current || DEVICE) return;
|
|
1791
|
+
try { const record = await post(`${API}/conversations/${encodeURIComponent(current)}/health/seen`, {}); const c = conversations.find((x) => x.name === current); if (c) c.health = record; paint(); paintHealth(); }
|
|
1792
|
+
catch (error) { show(error.message, 'Back', () => { notice.hidden = true; }); }
|
|
1793
|
+
}
|
|
1781
1794
|
function seeTerminal() { if (DEVICE) { simple = false; paintSimple(); focusTerminal(); } else goTab('terminal'); paintHealth(); }
|
|
1782
1795
|
$('health-memory').addEventListener('click', () => { void openMemory(); });
|
|
1783
1796
|
$('health-terminal').addEventListener('click', seeTerminal);
|
|
@@ -2154,7 +2167,7 @@
|
|
|
2154
2167
|
/* A reaction to one of its messages: wherever the chat may be written in. */
|
|
2155
2168
|
...(!DEVICE || deviceParts.chat === 'write' ? { react: (to, reaction) => post(talkPath(name, '/react'), { to, reaction }) } : {}),
|
|
2156
2169
|
/* The buttons of a line of the machine: what this screen may do. */
|
|
2157
|
-
act: (id) => { if (id === 'memory') void openMemory(); else if (id === 'disk') void openDisk(); else if (id === 'room') seeTerminal(); else if (id === 'restart') void restartMachine(false); else if (id === 'terminal') seeTerminal(); else if (id.startsWith('review:')) void openGit(id.slice('review:'.length)); else openCommits(id); },
|
|
2170
|
+
act: (id) => { if (id === 'seen') void markSeen(); else if (id === 'memory') void openMemory(); else if (id === 'disk') void openDisk(); else if (id === 'room') seeTerminal(); else if (id === 'restart') void restartMachine(false); else if (id === 'terminal') seeTerminal(); else if (id.startsWith('review:')) void openGit(id.slice('review:'.length)); else openCommits(id); },
|
|
2158
2171
|
/* What it opens over the thread (a picture, its media, a search...) is a step of this page's: one Back closes it. */
|
|
2159
2172
|
back: { open: (name, close) => nav.over(`chat-${name}`, () => close(), { stack: true }), closed: (step) => { if (step) nav.drop(step); } },
|
|
2160
2173
|
/* Files attached to a message: wherever the chat may be written in. */
|
|
@@ -2222,7 +2235,7 @@
|
|
|
2222
2235
|
/* "commits:<repository>.<to>.<from>.<n>": those commits, in the review ("See the 3 commits"). A commit a
|
|
2223
2236
|
line names (7 to 40 hexadecimal characters, a digit among them) is a link to its review, on a line about
|
|
2224
2237
|
a repository; the agent's own messages are never read for this. */
|
|
2225
|
-
const ACTIONS = { memory: 'More memory...', disk: 'Give it more disk...', room: 'See what takes room', restart: 'Restart...', terminal: 'See the terminal', review: 'Open the review' };
|
|
2238
|
+
const ACTIONS = { memory: 'More memory...', disk: 'Give it more disk...', room: 'See what takes room', restart: 'Restart...', terminal: 'See the terminal', review: 'Open the review', seen: 'Seen' };
|
|
2226
2239
|
const COMMITS = /^commits:([a-z0-9][a-z0-9-]*)\.([0-9a-f]{7,40})\.([0-9a-f]{7,40})\.(\d{1,4})$/;
|
|
2227
2240
|
const COMMIT = /^commit:([a-z0-9][a-z0-9-]*)\.([0-9a-f]{7,40})$/;
|
|
2228
2241
|
function openCommits(id) {
|
|
@@ -2234,7 +2247,7 @@
|
|
|
2234
2247
|
function machineLines(data) {
|
|
2235
2248
|
if (!Array.isArray(data?.messages)) return data;
|
|
2236
2249
|
const kindOf = (id) => String(id).split(':')[0];
|
|
2237
|
-
const may = (id) => (id === 'terminal' || id === 'room' ? !noTerminal() : id === 'disk' ? !DEVICE && !narrow() : (id === 'memory' || id === 'restart' || /^review:[a-z0-9][a-z0-9._-]*$/.test(id) || COMMITS.test(id)) && !DEVICE);
|
|
2250
|
+
const may = (id) => (id === 'terminal' || id === 'room' ? !noTerminal() : id === 'disk' ? !DEVICE && !narrow() : (id === 'memory' || id === 'restart' || id === 'seen' || /^review:[a-z0-9][a-z0-9._-]*$/.test(id) || COMMITS.test(id)) && !DEVICE);
|
|
2238
2251
|
const label = (id) => { const n = Number(COMMITS.exec(id)?.[4] ?? 0); return n ? (n === 1 ? 'See the commit' : `See the ${n} commits`) : ACTIONS[kindOf(id)]; };
|
|
2239
2252
|
const linksOf = (m) => {
|
|
2240
2253
|
const repo = DEVICE ? null : (m.actions ?? []).map((id) => /^review:([a-z0-9][a-z0-9-]*)$/.exec(id)?.[1]).find(Boolean);
|
package/web/index.html
CHANGED
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
<button type="button" id="health-disk" hidden>Give it more disk...</button>
|
|
77
77
|
<button type="button" id="health-restart">Restart...</button>
|
|
78
78
|
<button type="button" id="health-terminal" hidden>See the terminal</button>
|
|
79
|
-
<button type="button" id="health-dismiss" aria-label="
|
|
79
|
+
<button type="button" id="health-dismiss" aria-label="Seen: no longer in Needs you" title="Seen: no longer in Needs you, until something else comes">Seen</button>
|
|
80
80
|
</span>
|
|
81
81
|
</div>
|
|
82
82
|
<div id="signin-strip" hidden>
|