clavarium 0.2.10 → 0.2.11

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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.10",
9
+ "version": "0.2.11",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
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.",
package/server/health.mjs CHANGED
@@ -26,6 +26,9 @@
26
26
  export const PROBE = [
27
27
  'awk \'/^MemTotal:/{t=$2} /^MemAvailable:/{a=$2} END{print "memory", t+0, a+0}\' /proc/meminfo',
28
28
  'awk \'$1=="oom_kill"{n=$2} END{print "oom", n+0}\' /proc/vmstat',
29
+ /* Which kind, from the kernel's own words: the whole machine short ("Out of memory"), or a program
30
+ at the limit it was given ("Memory cgroup out of memory"). Read with sudo when it may; else not said. */
31
+ '( sudo -n dmesg 2>/dev/null || dmesg 2>/dev/null ) | awk \'/Memory cgroup out of memory: Killed process/{l++; next} /Out of memory: Killed process/{g++} END{if (NR) print "oomkinds", g+0, l+0}\'',
29
32
  'df -Pm / | awk \'NR==2{print "disk /", $4, $2}\'',
30
33
  'for p in "$@"; do',
31
34
  ' if awk -v p="$p" \'$2==p{f=1} END{exit !f}\' /proc/mounts; then',
@@ -65,6 +68,7 @@ export function readProbe(text, paths = []) {
65
68
  const [a, b, c] = parts.slice(1).map(whole);
66
69
  if (parts[0] === 'memory' && parts.length === 3 && a !== undefined && b !== undefined) facts.memory = { totalMb: Math.round(a / 1024), availableMb: Math.round(b / 1024) };
67
70
  if (parts[0] === 'oom' && parts.length === 2 && a !== undefined) facts.oomKills = a;
71
+ if (parts[0] === 'oomkinds' && parts.length === 3 && a !== undefined && b !== undefined) facts.oomKinds = { machine: a, limit: b };
68
72
  if (parts[0] === 'disk' && parts.length === 4 && disks.has(parts[1]) && b !== undefined && c !== undefined) facts.disks[parts[1]] = { availableMb: b, sizeMb: c };
69
73
  if (parts[0] === 'mount' && parts.length === 3 && expected.has(parts[2]) && MOUNT_STATES.has(parts[1])) facts.mounts[parts[2]] = parts[1];
70
74
  }
@@ -96,7 +100,13 @@ export function judge(record) {
96
100
  if (s === 'Running') {
97
101
  if (record.answering === false) add('bad', 'answer', 'silent', 'Its machine does not answer. Restarting it usually helps.');
98
102
  /* 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.`);
103
+ /* THE WHOLE MACHINE short of memory is said, each time it happens again; a program stopped at the
104
+ limit it was given (on purpose, often) is only noted, quietly. When the kind cannot be told, noted. */
105
+ const kinds = record.oomKinds;
106
+ if (kinds && kinds.machine > 0) add('warn', 'memory', `oom-machine:${kinds.machine}`, `The whole machine ran out of memory${kinds.machine === 1 ? '' : ` ${kinds.machine} times`} since it started: a program in it was stopped. Its files are safe.`);
107
+ const limited = kinds ? kinds.limit : 0;
108
+ if (limited > 0) add('info', 'memory', 'oom-limit', `${limited} program${limited === 1 ? ' was' : 's were'} stopped at the memory limit given to ${limited === 1 ? 'it' : 'them'}, since it started. The machine itself had room.`);
109
+ if (!kinds && record.oomKills > 0) add('info', 'memory', 'oom', `${record.oomKills} program${record.oomKills === 1 ? ' was' : 's were'} stopped for lack of memory since it started (whether the machine or a limit of their own, it could not be told). Its files are safe.`);
100
110
  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.`);
101
111
  for (const [path, d] of Object.entries(record.disks ?? {})) {
102
112
  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.`);
@@ -189,7 +199,7 @@ export class Health {
189
199
  }
190
200
  }
191
201
  return this.#keep(name, {
192
- at, state, answering: true, memory: facts.memory, oomKills: facts.oomKills ?? 0, disks: facts.disks,
202
+ at, state, answering: true, memory: facts.memory, oomKills: facts.oomKills ?? 0, ...(facts.oomKinds ? { oomKinds: facts.oomKinds } : {}), disks: facts.disks,
193
203
  missing: loose(), ...(remounted.length ? { remounted } : {}), ...(failed.length ? { failed } : {}),
194
204
  /* What was put back stays said until a later look finds nothing to put back. */
195
205
  });
@@ -68,9 +68,11 @@ export class History {
68
68
  const running = rss !== undefined;
69
69
  const key = this.#keys.get(m.name);
70
70
  /* A program stopped for lack of memory since the last look: a mark on the curve. */
71
- const oom = Number.isInteger(h?.oomKills) && key?.oom !== null && key?.oom !== undefined && h.oomKills > key.oom;
71
+ /* The whole machine short of memory, when the kind is known; a program at its own limit is no mark. */
72
+ const kills = h?.oomKinds ? h.oomKinds.machine : h?.oomKills;
73
+ const oom = Number.isInteger(kills) && key?.oom !== null && key?.oom !== undefined && kills > key.oom;
72
74
  this.#push(m.name, t, running ? { memory, cpu, disk: d ? pct(d.sizeMb - d.availableMb, d.sizeMb) : null } : { memory: null, cpu: null, disk: null }, oom);
73
- if (Number.isInteger(h?.oomKills)) this.#keys.get(m.name).oom = h.oomKills;
75
+ if (Number.isInteger(kills)) this.#keys.get(m.name).oom = kills;
74
76
  }
75
77
  if (this.#file && t - this.#savedAt >= SAVE_MS) this.save();
76
78
  }
package/web/app.js CHANGED
@@ -34,6 +34,37 @@
34
34
  const noTerminal = () => DEVICE && !deviceParts.terminal;
35
35
  /* A phone: what needs a wide screen (the Machine chapter's sizes) is not offered there. */
36
36
  const narrow = () => matchMedia('(max-width: 700px)').matches;
37
+ /* THE LIST'S WIDTH, on this device: between LIST_MIN and LIST_MAX (never more than half the window). */
38
+ const LIST_WIDTH = 'clavarium-list-width'; const LIST_MIN = 200; const LIST_MAX = 560; const LIST_USUAL = 260;
39
+ const listWidth = (px) => {
40
+ const w = Math.round(Math.max(LIST_MIN, Math.min(LIST_MAX, innerWidth / 2, px)));
41
+ document.getElementById('app')?.style.setProperty('--list-width', `${w}px`);
42
+ const handle = document.getElementById('list-resize');
43
+ if (!handle) return w;
44
+ handle.setAttribute('aria-valuenow', String(w)); handle.setAttribute('aria-valuemin', String(LIST_MIN)); handle.setAttribute('aria-valuemax', String(LIST_MAX));
45
+ return w;
46
+ };
47
+ const keepWidth = (w) => { try { if (w === LIST_USUAL) localStorage.removeItem(LIST_WIDTH); else localStorage.setItem(LIST_WIDTH, String(w)); } catch { /* this page only */ } };
48
+ (() => {
49
+ /* A page with no list of its own (a device's) has nothing to widen. */
50
+ const handle = document.getElementById('list-resize');
51
+ if (!handle) return;
52
+ let kept = LIST_USUAL; try { kept = Number(localStorage.getItem(LIST_WIDTH)) || LIST_USUAL; } catch { /* none */ }
53
+ listWidth(kept);
54
+ let drag = null;
55
+ handle.addEventListener('pointerdown', (e) => { if (e.button !== 0) return; drag = { id: e.pointerId }; handle.setPointerCapture(e.pointerId); handle.dataset.dragging = 'true'; e.preventDefault(); });
56
+ handle.addEventListener('pointermove', (e) => { if (!drag || e.pointerId !== drag.id) return; listWidth(e.clientX - document.getElementById('app').getBoundingClientRect().left); });
57
+ const end = (e) => { if (!drag || e.pointerId !== drag.id) return; drag = null; delete handle.dataset.dragging; keepWidth(Number(handle.getAttribute('aria-valuenow'))); };
58
+ handle.addEventListener('pointerup', end); handle.addEventListener('pointercancel', end);
59
+ handle.addEventListener('dblclick', () => keepWidth(listWidth(LIST_USUAL)));
60
+ handle.addEventListener('keydown', (e) => {
61
+ const now = Number(handle.getAttribute('aria-valuenow')) || LIST_USUAL;
62
+ const to = e.key === 'ArrowLeft' ? now - 16 : e.key === 'ArrowRight' ? now + 16 : e.key === 'Home' ? LIST_MIN : e.key === 'End' ? LIST_MAX : e.key === 'Enter' ? LIST_USUAL : null;
63
+ if (to === null) return;
64
+ e.preventDefault(); keepWidth(listWidth(to));
65
+ });
66
+ addEventListener('resize', () => listWidth(Number(handle.getAttribute('aria-valuenow')) || LIST_USUAL));
67
+ })();
37
68
  /* On the device page some controls do not exist; what would have been
38
69
  done to them is done to a detached element instead, and is lost. */
39
70
  const $ = (id) => document.getElementById(id) ?? document.createElement('div');
@@ -936,7 +967,7 @@
936
967
  /* `label`: the name shown; the conversations in no group are one of their own ("Not filed", key NONE). */
937
968
  const NONE = '\u0000none';
938
969
  /* The two sections above the groups, folded or not like a group (never a group's name: those are plain words). */
939
- const NEEDS = '\u0001needs'; const RECENT = '\u0001recent';
970
+ const NEEDS = '\u0001needs'; const RECENT = '\u0001recent'; const GROUPS = '\u0001groups';
940
971
  function groupBox(g, inside, all, open, label = g) {
941
972
  const box = document.createElement('div'); box.className = 'group'; box.dataset.group = g === NONE ? '' : g;
942
973
  const head = document.createElement('button'); head.type = 'button'; head.className = 'group-head'; head.dataset.group = g === NONE ? '' : g;
@@ -963,6 +994,8 @@
963
994
  }
964
995
  function paint() {
965
996
  if (listHeld) { paintLater = true; return; }
997
+ /* The groups, folded as a whole or not (a search shows them all). */
998
+ let groupsOpen = true;
966
999
  const items = $('items');
967
1000
  items.replaceChildren();
968
1001
  const top = $('recent'); top.replaceChildren();
@@ -978,7 +1011,7 @@
978
1011
  /* A section that folds: open at first, folded or not on this device as its owner leaves it. */
979
1012
  const section = (key, label, count) => {
980
1013
  const open = !folded.has(key);
981
- const b = document.createElement('button'); b.type = 'button'; b.className = 'list-head list-fold'; b.dataset.section = key === NEEDS ? 'needs' : 'recent';
1014
+ const b = document.createElement('button'); b.type = 'button'; b.className = 'list-head list-fold'; b.dataset.section = key === NEEDS ? 'needs' : key === RECENT ? 'recent' : 'groups';
982
1015
  b.setAttribute('aria-expanded', String(open));
983
1016
  const chevron = document.createElement('span'); chevron.className = 'list-chevron'; chevron.setAttribute('aria-hidden', 'true'); chevron.textContent = open ? '\u25BE' : '\u25B8';
984
1017
  /* How many, only when folded: open, its rows (and "Show more") say it. */
@@ -1000,19 +1033,24 @@
1000
1033
  top.append(...recent.slice(0, showAllRecent ? recent.length : few).map((c) => itemButton(c, true)));
1001
1034
  if (recent.length > few) {
1002
1035
  const more = document.createElement('button'); more.type = 'button'; more.className = 'inline more-recent';
1003
- more.textContent = showAllRecent ? 'Show fewer' : `Show more (${recent.length - few})`;
1036
+ /* A chevron, centred: the words for the pointer and for a screen reader. */
1037
+ const words = showAllRecent ? 'Show fewer' : `Show ${recent.length - few} more`;
1038
+ more.replaceChildren(Object.assign(document.createElement('span'), { className: 'more-chevron', textContent: showAllRecent ? '\u2303' : '\u2304' }));
1039
+ more.title = words; more.setAttribute('aria-label', words); more.setAttribute('aria-expanded', String(showAllRecent));
1004
1040
  more.addEventListener('click', () => { showAllRecent = !showAllRecent; paint(); });
1005
1041
  top.append(more);
1006
1042
  }
1007
1043
  }
1008
1044
  /* GROUPS: the order chosen by hand, and those in no group as one of their own. */
1009
1045
  if (groups.length) {
1010
- top.append(heading('Groups'));
1011
1046
  const loose = shown.filter((c) => !c.group);
1012
- if (loose.length) items.append(groupBox(NONE, loose, conversations.filter((c) => !c.group).sort(byRank), !folded.has(NONE), 'Not filed'));
1047
+ groupsOpen = section(GROUPS, 'Groups', groups.length + (loose.length ? 1 : 0));
1048
+ if (loose.length && groupsOpen) items.append(groupBox(NONE, loose, conversations.filter((c) => !c.group).sort(byRank), !folded.has(NONE), 'Not filed'));
1013
1049
  } else {
1014
- /* No group yet: one list, each with what was said last and when. */
1015
- items.append(...shown.map((c) => itemButton(c, false, true)));
1050
+ /* No group yet: one list, each with what was said last and when -- without those in Needs you
1051
+ just above (said once), under a heading of its own when Needs you is there. */
1052
+ if (needs.length) top.append(heading('Conversations'));
1053
+ items.append(...shown.filter((c) => !needsYou(c)).map((c) => itemButton(c, false, true)));
1016
1054
  if (conversations.length > 1) {
1017
1055
  const tip = document.createElement('p'); tip.className = 'hint list-tip'; tip.textContent = 'Put conversations in groups to find them by subject: open one, then Settings, Group.';
1018
1056
  items.append(tip);
@@ -1020,6 +1058,7 @@
1020
1058
  }
1021
1059
  }
1022
1060
  for (const g of groups) {
1061
+ if (!groupsOpen) break;
1023
1062
  const inside = shown.filter((c) => c.group === g);
1024
1063
  /* Nothing of it in sight (all hidden, or nothing found): not shown. */
1025
1064
  if (inside.length === 0) continue;
@@ -1220,7 +1259,7 @@
1220
1259
  if (!r.ok) throw new Error('no api');
1221
1260
  conversations = await r.json();
1222
1261
  await readDevices();
1223
- $('list').hidden = false; $('back').hidden = false; $('nav').hidden = false;
1262
+ $('list').hidden = false; $('back').hidden = false; $('nav').hidden = false; $('list-resize').hidden = false;
1224
1263
  }
1225
1264
  home = true;
1226
1265
  if (conversations.find((x) => x.name === current)?.answerer?.needs) $('room').setAttribute('data-asking', '');
@@ -2235,7 +2274,7 @@
2235
2274
  /* "commits:<repository>.<to>.<from>.<n>": those commits, in the review ("See the 3 commits"). A commit a
2236
2275
  line names (7 to 40 hexadecimal characters, a digit among them) is a link to its review, on a line about
2237
2276
  a repository; the agent's own messages are never read for this. */
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' };
2277
+ 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: '\u2713 Seen' };
2239
2278
  const COMMITS = /^commits:([a-z0-9][a-z0-9-]*)\.([0-9a-f]{7,40})\.([0-9a-f]{7,40})\.(\d{1,4})$/;
2240
2279
  const COMMIT = /^commit:([a-z0-9][a-z0-9-]*)\.([0-9a-f]{7,40})$/;
2241
2280
  function openCommits(id) {
package/web/index.html CHANGED
@@ -48,6 +48,8 @@
48
48
  <!-- THE THREE PLACES of the owner's page: its conversations, who gets what
49
49
  (Access), and its settings. Bottom left on a wide screen; a bar along
50
50
  the bottom on a phone. -->
51
+ <!-- THE LIST'S WIDTH: dragged on its edge (or arrows), kept on this device; a double click gives it back. -->
52
+ <div id="list-resize" role="separator" aria-orientation="vertical" aria-label="Width of the list" title="Drag to widen or narrow the list; double click for its usual width" tabindex="0" hidden></div>
51
53
  <nav id="nav" aria-label="Places" hidden>
52
54
  <button type="button" id="nav-conversations" data-place="conversations" aria-current="page"><svg class="nav-ic" viewBox="0 0 24 24" aria-hidden="true" data-icon="message-square"><path d="M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414 .586l-2.202 2.202A.71 .71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z"/></svg><span>Conversations</span></button>
53
55
  <button type="button" id="nav-assets" data-place="assets"><svg class="nav-ic" viewBox="0 0 24 24" aria-hidden="true" data-icon="layers"><path d="M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z"/><path d="M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12"/><path d="M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17"/></svg><span>Assets</span></button>
@@ -76,7 +78,7 @@
76
78
  <button type="button" id="health-disk" hidden>Give it more disk...</button>
77
79
  <button type="button" id="health-restart">Restart...</button>
78
80
  <button type="button" id="health-terminal" hidden>See the terminal</button>
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>
81
+ <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">&#x2713; Seen</button>
80
82
  </span>
81
83
  </div>
82
84
  <div id="signin-strip" hidden>
package/web/style.css CHANGED
@@ -23,7 +23,7 @@ button { font: 600 .8125rem var(--sans); color: var(--ink); background: var(--bu
23
23
  button.primary { background: var(--brass); border-color: var(--brass); color: var(--on-brass); }
24
24
  button:focus-visible, input:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
25
25
  /* The list on the left, the three places under it, the conversation beside them. */
26
- #app { display: grid; grid-template-columns: 260px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; height: 100%; }
26
+ #app { display: grid; grid-template-columns: var(--list-width, 260px) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; height: 100%; }
27
27
  #app:has(> #list[hidden]) #room { grid-column: 1 / -1; }
28
28
  #list { grid-column: 1; grid-row: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; padding: 10px; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
29
29
  #list .top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
@@ -1286,7 +1286,9 @@ select.pill { appearance: auto; }
1286
1286
  .item[data-when] > b { padding-right: 5.5em; }
1287
1287
  .item .when { position: absolute; top: 9px; right: 10px; max-width: 5em; overflow: hidden; white-space: nowrap; font-weight: 400; color: var(--ink2); }
1288
1288
  .item .last { display: block; color: var(--ink); opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1289
- .more-recent { align-self: flex-start; }
1289
+ .more-recent { align-self: center; display: inline-flex; align-items: center; gap: 4px; padding: 2px 14px; border-radius: 999px; text-decoration: none; color: var(--ink2); }
1290
+ .more-recent:hover { color: var(--ink); background: var(--bar); }
1291
+ .more-chevron { font-size: 1.1rem; line-height: 1; }
1290
1292
  .list-tip { margin: 8px 2px; }
1291
1293
  /* Needs you and Recent above the groups, in the list's own scroll: never a box scrolled inside it
1292
1294
  (a row cut in half at its bottom). A few rows, then "Show all". */
@@ -1345,3 +1347,14 @@ select.pill { appearance: auto; }
1345
1347
  .list-fold:hover { color: var(--ink); }
1346
1348
  .list-chevron { width: 1em; text-align: center; }
1347
1349
  .list-count { margin-left: auto; font-weight: 400; letter-spacing: 0; font-variant-numeric: tabular-nums; }
1350
+
1351
+ /* The list's width, dragged on its edge: a strip of a few pixels over the border, wider to the touch. */
1352
+ #list-resize { grid-column: 1; grid-row: 1 / span 2; justify-self: end; width: 9px; margin-right: -5px; z-index: 5; cursor: col-resize; touch-action: none; background: transparent; }
1353
+ #list-resize:hover, #list-resize:focus-visible, #list-resize[data-dragging] { background: color-mix(in srgb, var(--brass) 45%, transparent); outline: none; }
1354
+ @media (pointer: coarse) { #list-resize { width: 18px; margin-right: -9px; } }
1355
+ @media (max-width: 700px) { #list-resize { display: none; } }
1356
+ #app[data-list="folded"] #list-resize { display: none; }
1357
+ /* "Seen" stands apart from what acts on the machine: in the colour of what is fine. */
1358
+ .parley-act[data-act="seen"], #health-dismiss { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 60%, transparent); }
1359
+ .parley-act[data-act="seen"]:hover, #health-dismiss:hover { background: color-mix(in srgb, var(--ok) 14%, transparent); }
1360
+ button.inline.more-recent { text-decoration: none; }