clavarium 0.2.130-next.1 → 0.2.133-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/config/tools.json +1 -0
- package/npm-shrinkwrap.json +6 -6
- package/package.json +2 -2
- package/server/api.mjs +10 -0
- package/server/conversations.mjs +27 -0
- package/server/main.mjs +9 -0
- package/server/tools.mjs +3 -1
- package/web/app.js +33 -0
- package/web/index.html +5 -0
- package/web/style.css +8 -1
package/config/tools.json
CHANGED
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.133-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.133-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
|
13
13
|
"@xterm/xterm": "^6.0.0",
|
|
14
|
-
"clavarium-binder": "0.1.
|
|
14
|
+
"clavarium-binder": "0.1.38-next.1",
|
|
15
15
|
"clavarium-docket": "0.1.1",
|
|
16
16
|
"clavarium-parley": "0.17.20-next.1",
|
|
17
17
|
"clavarium-tether": "0.1.0-next.32",
|
|
@@ -716,9 +716,9 @@
|
|
|
716
716
|
}
|
|
717
717
|
},
|
|
718
718
|
"node_modules/clavarium-binder": {
|
|
719
|
-
"version": "0.1.
|
|
720
|
-
"resolved": "https://registry.npmjs.org/clavarium-binder/-/clavarium-binder-0.1.
|
|
721
|
-
"integrity": "sha512-
|
|
719
|
+
"version": "0.1.38-next.1",
|
|
720
|
+
"resolved": "https://registry.npmjs.org/clavarium-binder/-/clavarium-binder-0.1.38-next.1.tgz",
|
|
721
|
+
"integrity": "sha512-9nhZM/vb1hsXr60vJ354XNWVCojyB9RrrAtl9BWFtaIPO55Dde9D5fgxOylmqTprjmMVq8r6Za2YqvWe+W05ig==",
|
|
722
722
|
"license": "MIT",
|
|
723
723
|
"bin": {
|
|
724
724
|
"binder": "bin/binder.mjs",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.133-next.1",
|
|
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.",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@xterm/addon-fit": "^0.11.0",
|
|
46
46
|
"@xterm/xterm": "^6.0.0",
|
|
47
|
-
"clavarium-binder": "0.1.
|
|
47
|
+
"clavarium-binder": "0.1.38-next.1",
|
|
48
48
|
"clavarium-docket": "0.1.1",
|
|
49
49
|
"clavarium-parley": "0.17.20-next.1",
|
|
50
50
|
"clavarium-tether": "0.1.0-next.32",
|
package/server/api.mjs
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* GET /api/conversations/<name>/health what was last seen of its machine
|
|
13
13
|
* POST /api/conversations/<name>/health look now (never wakes a machine)
|
|
14
14
|
* POST /api/conversations/<name>/health/seen what it says now no longer calls its owner (Needs you)
|
|
15
|
+
* POST /api/conversations/<name>/exit-report why its tool ended: { now (read in its machine, if it runs), last (kept at its end) }
|
|
15
16
|
* POST /api/conversations/<name>/archive
|
|
16
17
|
* 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
|
|
17
18
|
* POST /api/conversations/<name>/resume {on}: its tool takes up its last session when it starts (true), or starts fresh
|
|
@@ -619,6 +620,15 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
619
620
|
}
|
|
620
621
|
const moved = /^\/api\/conversations\/([^/]+)\/work$/.exec(pathname);
|
|
621
622
|
if (moved) return send(202, await conversations.moveWork(decodeURIComponent(moved[1]), body.to)), true;
|
|
623
|
+
/* Why its tool ended: read now in its machine when it runs, else the last kept at its end. */
|
|
624
|
+
const exitOf = /^\/api\/conversations\/([^/]+)\/exit-report$/.exec(pathname);
|
|
625
|
+
if (exitOf) {
|
|
626
|
+
const conversation = decodeURIComponent(exitOf[1]);
|
|
627
|
+
const c = conversations.list().find((x) => x.name === conversation);
|
|
628
|
+
if (!c) throw new Refusal(404, 'No such conversation.');
|
|
629
|
+
const now = await conversations.exitReport(conversation).catch(() => null);
|
|
630
|
+
return send(200, { now, last: c.lastExit ?? null }), true;
|
|
631
|
+
}
|
|
622
632
|
/* "Seen": what its machine says now no longer calls its owner (health.mjs). */
|
|
623
633
|
const seenOf = /^\/api\/conversations\/([^/]+)\/health\/seen$/.exec(pathname);
|
|
624
634
|
if (seenOf && health) {
|
package/server/conversations.mjs
CHANGED
|
@@ -1036,6 +1036,11 @@ export class Conversations {
|
|
|
1036
1036
|
const alive = await this.#vms.exec(name, ['tmux', '-L', SOCKET, 'has-session', '-t', `=${SESSION}`]);
|
|
1037
1037
|
/* true: the tool is still there, only the channel to it dropped. */
|
|
1038
1038
|
if (alive.code === 0) return true;
|
|
1039
|
+
/* Before its machine stops (and its kernel's memory of the night with it): why the tool
|
|
1040
|
+
ended, kept on the conversation and said -- a person without access to the server
|
|
1041
|
+
sees it in Machine, and is told at once when it was cut for lack of memory. */
|
|
1042
|
+
const report = await this.exitReport(name).catch(() => null);
|
|
1043
|
+
if (report) { this.#store.patch(name, { lastExit: report }); try { this.onToolExit?.(name, report); } catch { /* telling is best effort */ } }
|
|
1039
1044
|
this.#cancelStop(name);
|
|
1040
1045
|
const timer = setTimeout(() => {
|
|
1041
1046
|
this.#timers.delete(name);
|
|
@@ -1046,6 +1051,28 @@ export class Conversations {
|
|
|
1046
1051
|
return false;
|
|
1047
1052
|
}
|
|
1048
1053
|
|
|
1054
|
+
/* WHY ITS TOOL ENDED, read inside the machine while it still runs: the kernel's kills for
|
|
1055
|
+
lack of memory since it started (with the program's name), its memory, and the last
|
|
1056
|
+
lines of the tool's own log (`logs` in config/tools.json). Read as the machine's
|
|
1057
|
+
ordinary user; dmesg through sudo when it may. Nothing is changed. */
|
|
1058
|
+
async exitReport(name) {
|
|
1059
|
+
const c = this.#store.get(name);
|
|
1060
|
+
if (!c) throw new Refusal(404, 'No such conversation.');
|
|
1061
|
+
if (await this.#vms.state(name) !== 'Running') throw new Refusal(409, 'Its machine is not running.');
|
|
1062
|
+
const tool = this.#tools.find((t) => t.id === c.tool);
|
|
1063
|
+
const logs = Array.isArray(tool?.logs) ? tool.logs.filter((d) => /^[A-Za-z0-9._/-]+$/.test(d)) : [];
|
|
1064
|
+
const script = [
|
|
1065
|
+
'( sudo -n dmesg -T 2>/dev/null || dmesg -T 2>/dev/null ) | grep -E "Killed process|Out of memory|Memory cgroup out of memory" | tail -n 4 | sed "s/^/oom /"',
|
|
1066
|
+
'awk \'/^MemTotal:/{print "memory", int($2/1024)}\' /proc/meminfo',
|
|
1067
|
+
'for d in "$@"; do f=$(ls -t "$HOME/$d"/*.log 2>/dev/null | head -1); [ -n "$f" ] && { echo "logfile $f"; tail -n 25 "$f" | cut -c1-300 | sed "s/^/log /"; }; done; true',
|
|
1068
|
+
].join('\n');
|
|
1069
|
+
const r = await this.#vms.exec(name, ['bash', '-c', script, 'report', ...logs], { timeoutMs: 20_000 });
|
|
1070
|
+
const lines = String(r.stdout ?? '').split('\n');
|
|
1071
|
+
const pick = (p) => lines.filter((l) => l.startsWith(`${p} `)).map((l) => l.slice(p.length + 1));
|
|
1072
|
+
const memoryMb = Number(pick('memory')[0]) || null;
|
|
1073
|
+
return { at: new Date().toISOString(), oom: pick('oom'), memoryMb, logFile: pick('logfile')[0] ?? null, log: pick('log') };
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1049
1076
|
/* ONE FILE OF THE MACHINE'S OWN DISK, read for the person who asked to
|
|
1050
1077
|
see it (a path on their screen, clicked). Only under /work, only a
|
|
1051
1078
|
plain path, only a regular file of a modest size; read as the
|
package/server/main.mjs
CHANGED
|
@@ -530,6 +530,15 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
530
530
|
reclaim: (name) => { events.add({ kind: 'machine', text: `Machine of ${name}: memory reclaimed (it was asleep but still held RAM)`, conversation: name }); return vms.reclaim(name).then((r) => (r.stdout || '').trim()); },
|
|
531
531
|
say: (name, text) => { try { talk.event(name, { kind: 'machine-problem', text, tone: 'warn', topic: 'Machine' }); } catch { /* its chat may be off */ } } });
|
|
532
532
|
all.room = (ask) => capacity.check(ask);
|
|
533
|
+
/* A tool that ended cut for lack of memory: said in the events, to the owner, and in its chat. */
|
|
534
|
+
all.onToolExit = (name, report) => {
|
|
535
|
+
if (!report?.oom?.length) return;
|
|
536
|
+
const size = report.memoryMb ? ` (${Math.round(report.memoryMb / 1024 * 10) / 10} GB)` : '';
|
|
537
|
+
const text = `Its tool was stopped: the machine ran out of memory${size}. Give it more in Settings → Machine → Memory, or start it fresh.`;
|
|
538
|
+
events.add({ kind: 'machine', text: `Machine of ${name}: its tool was stopped for lack of memory${size}`, conversation: name });
|
|
539
|
+
void alerts.tell({ title: `${name}: its tool ran out of memory`, body: text, url: `/?c=${encodeURIComponent(name)}&open=settings` });
|
|
540
|
+
try { talk.event(name, { kind: 'machine-problem', text, tone: 'warn', topic: 'Machine' }); } catch { /* its chat may be off */ }
|
|
541
|
+
};
|
|
533
542
|
const stopWatch = capacity.start();
|
|
534
543
|
/* The curves of the resources (history.mjs): one look a minute, from what the server knows already. */
|
|
535
544
|
const history = new History({ file: `${dataDir}/history.json` });
|
package/server/tools.mjs
CHANGED
|
@@ -98,13 +98,15 @@ export function readTools(text) {
|
|
|
98
98
|
machine's user (".claude/CLAUDE.md"): a marked block in it points
|
|
99
99
|
the tool to its guide (see guide.mjs). A plain relative path. */
|
|
100
100
|
if (t.instructions !== undefined && !INSTRUCTIONS.test(t.instructions)) throw new Error(`${t.id}: instructions is a relative path in the home, without ".."`);
|
|
101
|
+
/* Where the tool keeps its own log, read when it ends (why it stopped): folders relative to the home. */
|
|
102
|
+
if (t.logs !== undefined && (!Array.isArray(t.logs) || t.logs.some((d) => typeof d !== 'string' || !/^[A-Za-z0-9._/-]+$/.test(d) || d.startsWith('/') || d.split('/').includes('..')))) throw new Error(`${t.id}: logs is a list of folders relative to the home, without ".."`);
|
|
101
103
|
/* Optional: ITS LAUNCHER, a script of config/launch shown at /tools/launch: run at each start,
|
|
102
104
|
given the rights chosen (full, ask) then the command; it sets what the tool needs,
|
|
103
105
|
then runs it. Clavarium knows nothing more of the tool. */
|
|
104
106
|
if (t.launch !== undefined && !/^[a-z][a-z0-9-]{0,40}\.sh$/.test(t.launch)) throw new Error(`${t.id}: launch is the name of a script of config/launch, such as "${t.id}.sh"`);
|
|
105
107
|
/* Repairs an existing machine is given once (see FIXES in conversations.mjs). */
|
|
106
108
|
const fixups = t.install.includes('npm-writable') ? NPM_WRITABLE : [];
|
|
107
|
-
return Object.freeze({ id: t.id, label: t.label, ...(t.instructions ? { instructions: t.instructions } : {}), command: Object.freeze([...t.command]), ...(t.launch ? { launch: t.launch } : {}), ...(t.resume ? { resume: Object.freeze([...t.resume]) } : {}), memoryMb: t.memoryMb, ...(rights ? { rights } : {}), steps: Object.freeze(steps), fixups: Object.freeze(fixups), signin });
|
|
109
|
+
return Object.freeze({ id: t.id, label: t.label, ...(t.instructions ? { instructions: t.instructions } : {}), ...(t.logs ? { logs: Object.freeze([...t.logs]) } : {}), command: Object.freeze([...t.command]), ...(t.launch ? { launch: t.launch } : {}), ...(t.resume ? { resume: Object.freeze([...t.resume]) } : {}), memoryMb: t.memoryMb, ...(rights ? { rights } : {}), steps: Object.freeze(steps), fixups: Object.freeze(fixups), signin });
|
|
108
110
|
});
|
|
109
111
|
}
|
|
110
112
|
|
package/web/app.js
CHANGED
|
@@ -2222,6 +2222,36 @@
|
|
|
2222
2222
|
try { await post(`${API}/conversations/${encodeURIComponent(current)}/health-react`, { on: $('react-on').checked, message: $('react-message').value, command: $('react-command').value }); $('react-said').textContent = 'Saved.'; }
|
|
2223
2223
|
catch (error) { $('react-said').textContent = error.message; }
|
|
2224
2224
|
});
|
|
2225
|
+
/* WHY ITS TOOL STOPPED, said plainly: cut for lack of memory (and what to do), else its log's
|
|
2226
|
+
last lines. `last` was kept when it ended; `now` is read in the machine when it runs. */
|
|
2227
|
+
function paintToolExit(r) {
|
|
2228
|
+
const body = $('tool-exit-body'); body.replaceChildren();
|
|
2229
|
+
const rep = r?.last ?? null; const now = r?.now ?? null;
|
|
2230
|
+
if (!rep && !now) { body.hidden = !r; if (r) body.append(el('p', 'hint', 'Nothing kept yet: its tool has not ended since this was added, and its machine is not running.')); return; }
|
|
2231
|
+
body.hidden = false;
|
|
2232
|
+
const show = (title, x) => {
|
|
2233
|
+
if (!x) return;
|
|
2234
|
+
const box = el('div', 'tool-exit-one');
|
|
2235
|
+
box.append(el('p', '', [title, x.at ? new Date(x.at).toLocaleString() : ''].filter(Boolean).join(' · ')));
|
|
2236
|
+
if (x.oom?.length) {
|
|
2237
|
+
box.append(el('p', 'error', `Stopped for lack of memory: the machine${x.memoryMb ? ` (${sizeWords(x.memoryMb)})` : ''} ran out. Give it more memory below, or start its tool fresh.`));
|
|
2238
|
+
const pre = el('pre', 'tool-exit-lines'); pre.textContent = x.oom.join('\n'); box.append(pre);
|
|
2239
|
+
} else box.append(el('p', 'hint', 'No program was stopped for lack of memory.'));
|
|
2240
|
+
if (x.log?.length) {
|
|
2241
|
+
const d = document.createElement('details'); const sm = document.createElement('summary'); sm.textContent = `Last lines of its own log${x.logFile ? ` (${x.logFile.split('/').pop()})` : ''}`;
|
|
2242
|
+
const pre = el('pre', 'tool-exit-lines'); pre.textContent = x.log.join('\n'); d.append(sm, pre); box.append(d);
|
|
2243
|
+
}
|
|
2244
|
+
body.append(box);
|
|
2245
|
+
};
|
|
2246
|
+
show('Now, in its machine', now);
|
|
2247
|
+
show('When its tool last ended', rep);
|
|
2248
|
+
}
|
|
2249
|
+
$('tool-exit-look').addEventListener('click', async () => {
|
|
2250
|
+
const b = $('tool-exit-look'); b.disabled = true; b.textContent = 'Looking…';
|
|
2251
|
+
try { paintToolExit(await post(`${API}/conversations/${encodeURIComponent(current)}/exit-report`, {})); }
|
|
2252
|
+
catch (error) { $('tool-exit-body').replaceChildren(el('p', 'error', error.message)); $('tool-exit-body').hidden = false; }
|
|
2253
|
+
b.disabled = false; b.textContent = 'Why did its tool stop?';
|
|
2254
|
+
});
|
|
2225
2255
|
function paintMachine(here) {
|
|
2226
2256
|
void paintReact(here);
|
|
2227
2257
|
/* Its curves: asked again when it changes, or once in a while (paintCurves). */
|
|
@@ -2239,6 +2269,7 @@
|
|
|
2239
2269
|
fact('Works in', here.work === 'kept' ? 'a folder kept here (/work)' : 'the disk of its machine (/work)');
|
|
2240
2270
|
}
|
|
2241
2271
|
healthLines($('machine-health'), here?.health ?? null);
|
|
2272
|
+
if ($('tool-exit').dataset.of !== (here?.name ?? '')) { $('tool-exit').dataset.of = here?.name ?? ''; paintToolExit(here?.lastExit ? { last: here.lastExit } : null); }
|
|
2242
2273
|
$('machine-restarted').textContent = here?.restarted ?? ''; $('machine-restarted').hidden = !here?.restarted;
|
|
2243
2274
|
/* The choices are not painted over while somebody is choosing. */
|
|
2244
2275
|
const memory = $('machine-memory'); const disk = $('machine-disk'); const cores = $('machine-cpus');
|
|
@@ -5842,6 +5873,8 @@
|
|
|
5842
5873
|
const foot = el('div', 'curve-foot'); foot.append(el('span', '', curveTime(r.from, r.span)), el('span', '', 'now'));
|
|
5843
5874
|
box.append(head, plot, foot);
|
|
5844
5875
|
if (Number.isFinite(level)) box.append(el('small', 'hint curve-legend', '..... the reserve: what must stay free'));
|
|
5876
|
+
/* Said, not only on hover (a tablet has none): what a red dot is, and how many. */
|
|
5877
|
+
if (r.marks?.length) box.append(el('small', 'hint curve-legend curve-legend-oom', `● ${r.marks.length === 1 ? 'a program was' : `${r.marks.length} times a program was`} stopped for lack of memory`));
|
|
5845
5878
|
return box;
|
|
5846
5879
|
}
|
|
5847
5880
|
const curvesAt = new WeakMap();
|
package/web/index.html
CHANGED
|
@@ -165,6 +165,11 @@
|
|
|
165
165
|
<div class="chapter-body">
|
|
166
166
|
<div class="panel-top"><b>Health</b><button type="button" id="health-check">Look now</button></div>
|
|
167
167
|
<ul id="machine-health" class="health-lines" aria-live="polite"></ul>
|
|
168
|
+
<!-- WHY ITS TOOL STOPPED: kept when the tool ends, read again on demand (no server access needed). -->
|
|
169
|
+
<div id="tool-exit" class="tool-exit">
|
|
170
|
+
<div class="row"><button type="button" id="tool-exit-look">Why did its tool stop?</button></div>
|
|
171
|
+
<div id="tool-exit-body" hidden></div>
|
|
172
|
+
</div>
|
|
168
173
|
<!-- ITS CURVES: memory, CPU and disk over time (server/history.mjs). -->
|
|
169
174
|
<div class="curves" id="machine-curves" data-of="" hidden>
|
|
170
175
|
<div class="curves-head"><b>Over time</b><div class="levels curves-span" role="group" aria-label="Over"><button type="button" data-span="1h" aria-pressed="true">1 h</button><button type="button" data-span="24h" aria-pressed="false">24 h</button><button type="button" data-span="7d" aria-pressed="false">7 days</button></div></div>
|
package/web/style.css
CHANGED
|
@@ -1222,7 +1222,7 @@ header .ic, #folders .ic { width: 18px; height: 18px; fill: none; stroke: curren
|
|
|
1222
1222
|
.as-foot { margin-top: 10px; }
|
|
1223
1223
|
.as-form { display: flex; flex-direction: column; gap: 8px; }
|
|
1224
1224
|
.as-form h3 { margin: 0; font-size: 1.125rem; }
|
|
1225
|
-
.as-form form { display: flex; flex-direction: column; gap: 6px; }
|
|
1225
|
+
.as-form form, #connexion-classic:not([hidden]) { display: flex; flex-direction: column; gap: 6px; }
|
|
1226
1226
|
#gitview-remote-box > summary { display: none; }
|
|
1227
1227
|
#gitview-remote { display: flex; flex-direction: column; gap: 6px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
|
|
1228
1228
|
.as-none { margin: auto; text-align: center; }
|
|
@@ -1903,3 +1903,10 @@ details.commit > pre { margin: 6px 0 0 1.6em; white-space: pre-wrap; overflow-wr
|
|
|
1903
1903
|
#preview-body:has(> img:only-child) { display: flex; align-items: center; justify-content: center; }
|
|
1904
1904
|
#preview-body > img:only-child { max-height: 100%; width: auto; object-fit: contain; margin: 0; }
|
|
1905
1905
|
#viewer #preview-download.ico svg { width: 20px; height: 20px; }
|
|
1906
|
+
|
|
1907
|
+
/* Why its tool stopped (Machine). */
|
|
1908
|
+
.tool-exit { margin: .4rem 0 .8rem; }
|
|
1909
|
+
.tool-exit-one { margin-top: .5rem; }
|
|
1910
|
+
.tool-exit-one p { margin: .2rem 0; }
|
|
1911
|
+
.tool-exit-lines { max-height: 14rem; overflow: auto; font-size: .78rem; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--panel-2, rgba(127,127,127,.08)); padding: .5rem .6rem; border-radius: 8px; margin: .3rem 0; }
|
|
1912
|
+
.curve-legend-oom { color: var(--danger); }
|