clavarium 0.2.434-next.1 → 0.2.435-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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.434-next.1",
3
+ "version": "0.2.435-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.434-next.1",
9
+ "version": "0.2.435-next.1",
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.434-next.1",
3
+ "version": "0.2.435-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.",
package/server/api.mjs CHANGED
@@ -127,6 +127,7 @@
127
127
  * GET /api/meshcentral: the remote screen (MeshCentral); POST /api/meshcentral/enable (turned on, in the background) /disable
128
128
  * GET /api/events?kind=&conversation=&q=&before=&limit= what happened, newest first
129
129
  * GET /api/jobs what it is doing: { running, done } (jobs.mjs), its updates of the day among the done
130
+ * GET /api/jobs/log?id= that job, under way or done today, with its log [{at, text}] (404: unknown)
130
131
  * GET /api/history?of=server|<name>&span=1h|24h|7d the curves of memory, CPU and disk (and the reserve, for the server)
131
132
  * GET /api/history/all?span=1h|24h|7d Settings, Usage: the server and every machine (asleep too) on one time axis,
132
133
  * in GB and cores: {t, capacity, server, itself, machines: [{name, alloc, asleep, ...}]}
@@ -415,6 +416,12 @@ export async function handleApi(request, response, conversations, headers, resou
415
416
  const done = [...said.done, ...updated].sort((a, b) => String(b.endedAt).localeCompare(String(a.endedAt)));
416
417
  return send(200, { running: said.running, done }), true;
417
418
  }
419
+ /* A job's log (jobs.mjs): read when its line is opened, never with the list, which stays light. */
420
+ if (pathname === '/api/jobs/log' && conversations.jobs) {
421
+ const job = conversations.jobs.log(query.get('id') ?? '');
422
+ if (!job) throw new Refusal(404, 'No such job.');
423
+ return send(200, job), true;
424
+ }
418
425
  if (pathname === '/api/events' && events) {
419
426
  const ask = { kind: query.get('kind') ?? '', conversation: query.get('conversation') ?? '', q: query.get('q') ?? '', before: query.get('before') ?? '', limit: Math.min(1000, Number(query.get('limit')) || 200) };
420
427
  const said = events.list(ask);
@@ -1072,20 +1072,22 @@ export class Conversations {
1072
1072
  /* Nothing comes for a while: said, with how long; for too long, the reading is ended and why said --
1073
1073
  never an endless wait nobody can read (14-11: stuck at "36 KB read"). */
1074
1074
  /* Quiet for 30 s: its machine asked, once, what its reading does -- the file it is on and its state
1075
- (D: waiting on the disk), its load, its free memory -- or said not to answer at all. Said with the
1076
- wait, and in the end's why (14-11: stuck at 36 KB on the owner's server, never here). */
1075
+ (D: waiting on the disk), its load, its free memory -- or said not to answer at all. Written to the
1076
+ copy's job log; the screen and the end's why stay short (14-11: stuck at 36 KB on the owner's server, never here). */
1077
1077
  let seen = '';
1078
1078
  /* Each tar and gzip: its state, what the kernel has it wait on (wchan), the file it holds and that
1079
1079
  file's filesystem -- enough to tell a disk, a network mount or a pipe nobody empties. */
1080
1080
  const probe = 'for p in $(pgrep -x tar) $(pgrep -x gzip); do f=$(ls -l /proc/$p/fd 2>/dev/null | grep -o "/home/[^ ]*" | tail -1); '
1081
1081
  + 'echo "$(cat /proc/$p/comm) $p $(cut -d" " -f3 /proc/$p/stat) $(cat /proc/$p/wchan 2>/dev/null) ${f#$HOME/}${f:+ [$(stat -f -c %T "$f" 2>/dev/null)]}"; done; '
1082
1082
  + 'echo "load $(cut -d" " -f1 /proc/loadavg)"; awk \'/MemAvailable/{print "free " int($2/1024) " MB"}\' /proc/meminfo';
1083
- const ask = () => { seen = '…'; this.#vms.exec(from, ['sh', '-c', probe], { timeoutMs: 20_000 }).then((r) => { seen = r.code === 0 ? (r.stdout || '').trim().split('\n').join(', ').slice(0, 200) : 'its machine did not answer'; }, () => { seen = 'its machine did not answer'; }); };
1083
+ /* What it said goes to the copy's job log (jobs.mjs), read in Settings and by its AI -- not on screen. */
1084
+ const heard = (said) => { seen = said; this.jobs?.note(to, `Its original's reading: ${said}`); };
1085
+ const ask = () => { seen = '…'; this.#vms.exec(from, ['sh', '-c', probe], { timeoutMs: 20_000 }).then((r) => { heard(r.code === 0 ? (r.stdout || '').trim().split('\n').join(', ').slice(0, 200) : 'its machine did not answer'); }, () => { heard('its machine did not answer'); }); };
1084
1086
  const watch = setInterval(() => {
1085
1087
  const quiet = Math.round((Date.now() - lastAt) / 1000);
1086
1088
  if (quiet >= COPY_QUIET_MS / 1000) { stalled = true; child.kill('SIGKILL'); return; }
1087
1089
  if (quiet >= 30 && !seen) ask();
1088
- if (quiet >= 15) say(`Copying ${tool.label}'s memory: ${sizeWords(read)} read, nothing more for ${quiet} s${seen && seen !== '…' ? ` (${seen})` : ''}`);
1090
+ if (quiet >= 15) say(`Copying ${tool.label}'s memory: ${sizeWords(read)} read, nothing more for ${quiet} s`);
1089
1091
  }, 5000);
1090
1092
  const failed = new Promise((ok) => child.on('error', () => ok(-1)));
1091
1093
  const file = createWriteStream(carried, { mode: 0o600 });
@@ -1093,7 +1095,7 @@ export class Conversations {
1093
1095
  code = await Promise.race([new Promise((ok) => child.on('close', ok)), failed]).finally(() => clearInterval(watch));
1094
1096
  if (stalled) {
1095
1097
  const now = await this.#vms.state(from, { fresh: true }).catch(() => undefined);
1096
- throw new Error(`its original stopped sending its tool's memory (${sizeWords(read)} read, then nothing for ${COPY_QUIET_MS / 60_000} min; its machine is ${now ?? 'in a state that could not be read'}${seen && seen !== '…' ? `; it said: ${seen}` : ''})`);
1098
+ throw new Error(`its original stopped sending its tool's memory: ${sizeWords(read)} read, then nothing for ${COPY_QUIET_MS / 60_000} min, its machine ${now ?? 'unreadable'} (see its job's log in Settings)`);
1097
1099
  }
1098
1100
  await new Promise((ok) => (file.writableFinished ? ok() : file.on('finish', ok)));
1099
1101
  if (code !== 255) break;
package/server/jobs.mjs CHANGED
@@ -4,15 +4,29 @@
4
4
  * record as it changes (Store's onChange), so it adds no wait.
5
5
  *
6
6
  * seen(before, after) a conversation's record changed (before or after undefined: made or removed)
7
- * list(now?) { running: [...], done: [...] } newest first, done within KEEP_MS
7
+ * note(name, text) a line added to the log of that conversation's job under way (none: nothing)
8
+ * list(now?) { running: [...], done: [...] } newest first, done within KEEP_MS; without their logs
9
+ * log(id) that job, under way or done, with its log; undefined if unknown
10
+ *
11
+ * Each job keeps a LOG (14-11), for the owner in Settings and for the conversation's AI, rather than diagnostics
12
+ * on screen: each new step, the lines noted, its end. A step that only counts on ("… 12 MB read") is kept once
13
+ * every PROGRESS_MS, and its last. Kept with the done jobs on disk, LOG_MAX lines of LINE_MAX characters at most.
8
14
  */
9
15
  import { JsonFile } from './store.mjs';
10
16
 
11
17
  export const BUSY = ['building', 'moving', 'restarting'];
12
18
  const KEEP_MS = 24 * 3600_000;
13
19
  const DONE_MAX = 50;
20
+ const LOG_MAX = 300;
21
+ const LINE_MAX = 300;
22
+ const PROGRESS_MS = 10_000;
14
23
 
15
24
  const titleOf = (c) => c?.title ?? c?.name ?? '?';
25
+ /* Its id: its conversation and when it started, in letters an address carries as they are. */
26
+ const idOf = (j) => `${j.conversation}-${j.startedAt}`.replace(/[^A-Za-z0-9_-]/g, '-');
27
+ /* A line that says the same as another but for its numbers: a count going on. */
28
+ const shapeOf = (text) => text.replace(/\d+(?:[.,]\d+)?/g, '#');
29
+ const bare = ({ log, ...job }) => job;
16
30
 
17
31
  /* Its words: what it is, from the phase and the record (a copy names its original, a move its machine). */
18
32
  export function jobWords(c) {
@@ -24,6 +38,8 @@ export function jobWords(c) {
24
38
 
25
39
  export class Jobs {
26
40
  #open = new Map();
41
+ /* A job under way's log, and the count line held back, said only if no other comes after it. */
42
+ #logs = new Map();
27
43
  #file;
28
44
  #done;
29
45
  #now;
@@ -32,20 +48,46 @@ export class Jobs {
32
48
  this.#now = now;
33
49
  this.#file = path ? new JsonFile(path, []) : undefined;
34
50
  const kept = this.#file?.get();
35
- this.#done = Array.isArray(kept) ? kept : [];
51
+ this.#done = Array.isArray(kept) ? kept.map((j) => ({ ...j, id: j.id ?? idOf(j) })) : [];
52
+ }
53
+
54
+ /* A line to a job's log: a step that only counts on is held back if the last one kept is less than
55
+ PROGRESS_MS old -- said when the next different line comes, or at the end, so its last is never lost. */
56
+ #add(name, text, { thin = false } = {}) {
57
+ const kept = this.#logs.get(name);
58
+ if (!kept) return;
59
+ const line = { at: new Date(this.#now()).toISOString(), text: String(text).slice(0, LINE_MAX) };
60
+ const last = kept.log.at(-1);
61
+ if (last?.text === line.text || kept.held?.text === line.text) return;
62
+ if (thin && last && shapeOf(last.text) === shapeOf(line.text) && Date.parse(line.at) - Date.parse(last.at) < PROGRESS_MS) { kept.held = line; return; }
63
+ if (kept.held && !(thin && last && shapeOf(kept.held.text) === shapeOf(line.text))) kept.log.push(kept.held);
64
+ kept.held = undefined;
65
+ kept.log.push(line);
66
+ /* Too long: its oldest lines go, its end is what tells what happened. */
67
+ if (kept.log.length > LOG_MAX) kept.log.splice(0, kept.log.length - LOG_MAX);
36
68
  }
37
69
 
70
+ note(name, text) { if (this.#open.has(name)) this.#add(name, text); }
71
+
38
72
  seen(before, after) {
39
73
  const name = after?.name ?? before?.name;
40
74
  if (!name) return;
41
75
  const busy = after && BUSY.includes(after.phase);
42
- if (busy && !this.#open.has(name)) this.#open.set(name, { conversation: name, what: jobWords(after), startedAt: new Date(this.#now()).toISOString() });
43
- else if (busy) this.#open.get(name).what = jobWords(after);
76
+ if (busy && !this.#open.has(name)) {
77
+ const job = { conversation: name, what: jobWords(after), startedAt: new Date(this.#now()).toISOString() };
78
+ this.#open.set(name, { id: idOf(job), ...job });
79
+ this.#logs.set(name, { log: [] });
80
+ } else if (busy) this.#open.get(name).what = jobWords(after);
81
+ if (busy && after.step) this.#add(name, after.step, { thin: true });
44
82
  if (busy || !this.#open.has(name)) return;
45
83
  const job = this.#open.get(name);
46
84
  this.#open.delete(name);
47
85
  const ok = after?.phase === 'ready';
48
- this.#end({ ...job, endedAt: new Date(this.#now()).toISOString(), result: after ? (ok ? 'done' : 'failed') : 'removed', ...(after && !ok && after.error ? { why: String(after.error).slice(0, 300) } : {}) });
86
+ const why = after && !ok && after.error ? String(after.error).slice(0, 300) : '';
87
+ this.#add(name, after ? (ok ? 'Done' : `Failed${why ? `: ${why}` : ''}`) : 'Removed');
88
+ const { log } = this.#logs.get(name);
89
+ this.#logs.delete(name);
90
+ this.#end({ ...job, endedAt: new Date(this.#now()).toISOString(), result: after ? (ok ? 'done' : 'failed') : 'removed', ...(why ? { why } : {}), log });
49
91
  }
50
92
 
51
93
  #end(job) {
@@ -64,6 +106,17 @@ export class Jobs {
64
106
  const c = byName.get(j.conversation);
65
107
  return { ...j, ...(c ? { what: jobWords(c), step: c.step ?? '', progress: c.progress } : {}) };
66
108
  });
67
- return { running, done: this.#done.filter((j) => Date.parse(j.endedAt) >= since) };
109
+ return { running, done: this.#done.filter((j) => Date.parse(j.endedAt) >= since).map(bare) };
110
+ }
111
+
112
+ log(id) {
113
+ for (const [name, job] of this.#open) {
114
+ if (job.id !== id) continue;
115
+ const { log, held } = this.#logs.get(name);
116
+ return { ...job, log: held ? [...log, held] : [...log] };
117
+ }
118
+ const since = this.#now() - KEEP_MS;
119
+ const done = this.#done.find((j) => j.id === id && Date.parse(j.endedAt) >= since);
120
+ return done && { ...done, log: done.log ?? [] };
68
121
  }
69
122
  }
@@ -9,10 +9,13 @@ export const SETTINGS_WORDS_FR = {
9
9
  'set-ch-s-general': 'Général', 'set-ch-s-about': 'À propos', 'set-ch-s-screen': 'Écran', 'set-ch-s-alerts': 'Alertes',
10
10
  'set-ch-s-resources': 'Ressources', 'set-ch-s-operators': 'Administrateurs', 'set-ch-s-network': 'Réseau', 'set-ch-s-remote-screen': 'Écran à distance',
11
11
  'set-ch-s-words': 'Écran du chat', 'set-ch-s-dictation': 'Dictée', 'set-ch-s-shortcuts': 'Raccourcis', 'set-ch-s-thread': 'Événements du chat',
12
- 'set-ch-s-updates': 'Mises à jour', 'set-ch-s-binders': 'Classeurs', 'set-ch-s-events': 'Activité', 'set-ch-s-logs': 'Journaux',
12
+ 'set-ch-s-updates': 'Mises à jour', 'set-ch-s-binders': 'Classeurs', 'set-ch-s-events': 'Activité', 'set-ch-s-jobs': 'Tâches', 'set-ch-s-logs': 'Journaux',
13
13
  'set-ch-s-usage': 'Usage', 'set-ch-s-backup': 'Sauvegarde', 'set-ch-s-advanced': 'Avancé',
14
14
  'set-check-updates': 'Chercher une mise à jour', 'set-activity': 'Activité', 'set-restart-dots': 'Redémarrer…', 'set-terminal': 'Terminal',
15
15
  'set-search': 'Chercher', 'set-why': 'Pourquoi',
16
+ /* Diagnostics › Tâches (jobs.mjs): celles du jour, chacune avec son journal. */
17
+ 'set-jobs-running': 'En cours', 'set-jobs-today': 'Aujourd\'hui', 'set-jobs-none': 'Rien aujourd\'hui',
18
+ 'set-jobs-starting': 'Démarrage', 'set-jobs-nolog': 'Rien de noté', 'set-jobs-unread': 'Illisible pour le moment',
16
19
  /* Diagnostics › « Vérifier les dossiers partagés » (health.mjs, linkguard.mjs). */
17
20
  'set-check-folders': 'Vérifier les dossiers partagés', 'set-looking': 'Vérification…',
18
21
  'set-fold-ok': '{path} : monté, lisible', 'set-fold-remounted': '{path} : détaché, remonté', 'set-fold-missing': '{path} : inaccessible',
package/web/app.js CHANGED
@@ -8340,6 +8340,43 @@
8340
8340
  $('events-more').hidden = got.length < 100;
8341
8341
  }
8342
8342
  $('settings-events-top').addEventListener('toggle', () => { if ($('settings-events-top').open) void paintEvents(); });
8343
+ /* JOBS (jobs.mjs): the day's, under way first, as in the badge's list; a line opened reads its log
8344
+ (GET /api/jobs/log), kept open when the list is read again -- every 5 s while one is under way. */
8345
+ let jobsTimer; const jobsOpen = new Set();
8346
+ const jobClock = (at) => new Date(at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
8347
+ async function paintJobLog(box, id) {
8348
+ const got = await fetch(`${API}/jobs/log?id=${encodeURIComponent(id)}`).then((r) => (r.ok ? r.json() : null)).catch(() => null);
8349
+ const list = el('ol', 'job-log');
8350
+ for (const line of got?.log ?? []) { const li = el('li'); const when = el('time', '', jobClock(line.at)); when.dateTime = line.at; li.append(when, el('span', '', line.text)); list.append(li); }
8351
+ if (!list.children.length) list.append(el('li', 'hint', got ? uiSaid('set-jobs-nolog', 'Nothing logged') : uiSaid('set-jobs-unread', 'Cannot be read just now')));
8352
+ box.querySelector('.job-log')?.remove(); box.append(list);
8353
+ }
8354
+ async function paintJobsChapter() {
8355
+ clearTimeout(jobsTimer);
8356
+ if (!$('settings-jobs-top').open) return;
8357
+ const got = await fetch(`${API}/jobs`).then((r) => (r.ok ? r.json() : null)).catch(() => null);
8358
+ if (!got) { $('jobs-said').textContent = uiSaid('set-jobs-unread', 'Cannot be read just now'); return; }
8359
+ const line = (j, result) => {
8360
+ const box = el('details', 'job-line'); box.dataset.result = result;
8361
+ const sum = el('summary');
8362
+ sum.append(el('span', '', result === 'running' ? '⟳' : result === 'done' ? '✓' : '✗'), el('span', '', j.what),
8363
+ el('small', '', result === 'running' ? (j.step || uiSaid('set-jobs-starting', 'Starting')) : [j.why, j.endedAt ? jobClock(j.endedAt) : ''].filter(Boolean).join(' · ')));
8364
+ box.append(sum);
8365
+ /* Clavarium's own updates have no log here: their story is in Updates. */
8366
+ if (!j.id) { sum.addEventListener('click', (event) => event.preventDefault()); return box; }
8367
+ box.dataset.job = j.id;
8368
+ box.addEventListener('toggle', () => { if (box.open) { jobsOpen.add(j.id); void paintJobLog(box, j.id); } else jobsOpen.delete(j.id); });
8369
+ if (jobsOpen.has(j.id)) box.open = true;
8370
+ return box;
8371
+ };
8372
+ const parts = [];
8373
+ if (got.running.length) parts.push(el('h3', '', uiSaid('set-jobs-running', 'Under way')), ...got.running.map((j) => line(j, 'running')));
8374
+ if (got.done.length) parts.push(el('h3', '', uiSaid('set-jobs-today', 'Today')), ...got.done.map((j) => line(j, j.result === 'done' ? 'done' : 'failed')));
8375
+ $('jobs-list').replaceChildren(...parts);
8376
+ $('jobs-said').textContent = parts.length ? '' : uiSaid('set-jobs-none', 'Nothing today');
8377
+ if (got.running.length) jobsTimer = setTimeout(() => { void paintJobsChapter(); }, 5000);
8378
+ }
8379
+ $('settings-jobs-top').addEventListener('toggle', () => { void paintJobsChapter(); });
8343
8380
  $('events-kind').addEventListener('change', () => { void paintEvents(); });
8344
8381
  let eventsTyping;
8345
8382
  $('events-q').addEventListener('input', () => { clearTimeout(eventsTyping); eventsTyping = setTimeout(() => { void paintEvents(); }, 250); });
package/web/index.html CHANGED
@@ -1345,6 +1345,14 @@
1345
1345
  <button type="button" id="events-more" hidden>Show older</button>
1346
1346
  </div>
1347
1347
  </details>
1348
+ <!-- WHAT IT DID TODAY: the day's jobs (server/jobs.mjs), under way first; each opens to its log. -->
1349
+ <details class="chapter" id="settings-jobs-top" data-chapter="s-jobs">
1350
+ <summary><span class="chapter-title" data-said="set-ch-s-jobs">Jobs</span><span class="chapter-about">Builds, copies, moves, step by step.</span></summary>
1351
+ <div class="chapter-body">
1352
+ <div id="jobs-list" class="jobs-list" aria-live="polite"></div>
1353
+ <p class="hint" id="jobs-said" role="status"></p>
1354
+ </div>
1355
+ </details>
1348
1356
  <!-- WHAT THE SERVER'S PROGRAMS SAID, to read, copy whole or keep (server/serverlogs.mjs);
1349
1357
  and this server started again. -->
1350
1358
  <details class="chapter" id="settings-logs-top" data-chapter="s-logs">
package/web/style.css CHANGED
@@ -1673,6 +1673,19 @@ svg.u-spark .u-oom { fill: var(--danger); stroke: var(--panel); stroke-width: 1.
1673
1673
  .event-conv { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
1674
1674
  .event-conv button { font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
1675
1675
  @media (max-width: 600px) { .event { grid-template-columns: 1fr auto auto; } .event-text, .event-who { grid-column: 1 / -1; } }
1676
+ /* Settings, Jobs: one line each, as in the badge's list; opened, its log, one line a step. */
1677
+ .jobs-list { display: flex; flex-direction: column; margin: 8px 0; font-size: .875rem; }
1678
+ .jobs-list h3 { margin: 10px 0 2px; font-size: .8125rem; color: var(--ink2); }
1679
+ .job-line { border-bottom: 1px solid var(--line); }
1680
+ .job-line > summary { display: grid; grid-template-columns: 16px 1fr; gap: 2px 8px; padding: 4px 0; cursor: pointer; list-style: none; }
1681
+ .job-line > summary::-webkit-details-marker { display: none; }
1682
+ .job-line > summary small { grid-column: 2; color: var(--ink2); overflow-wrap: anywhere; }
1683
+ .job-line[data-result="done"] > summary > span:first-child { color: var(--ok); }
1684
+ .job-line[data-result="failed"] > summary { color: var(--danger); }
1685
+ .job-log { list-style: none; margin: 0 0 6px 24px; padding: 0; font-size: .8125rem; }
1686
+ .job-log li { display: grid; grid-template-columns: 5.5rem 1fr; gap: 8px; padding: 1px 0; }
1687
+ .job-log time { color: var(--ink2); font-variant-numeric: tabular-nums; }
1688
+ .job-log span { min-width: 0; overflow-wrap: anywhere; }
1676
1689
  /* The choices of Logs and What happened: as wide as their words, in the colours of the page. */
1677
1690
  .events-pick select, .logs-pick select { width: auto; max-width: 100%; background-color: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }
1678
1691
  /* Needs you and Recent: a heading that folds its rows, with how many it holds. */