clavarium 0.2.463-next.1 → 0.2.464-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.463-next.1",
3
+ "version": "0.2.464-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.463-next.1",
9
+ "version": "0.2.464-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.463-next.1",
3
+ "version": "0.2.464-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/guide.mjs CHANGED
@@ -129,7 +129,7 @@ export function ownText({ name, tool, shared, workKept, resources = [], chat, on
129
129
  /* The thread is kept whole: after a restart, its end is read, and further back on demand. */
130
130
  if (chat && reread) out.push(`- After a restart: ${plain(reread, 60)}, the end of the chat; it says how to read further back.`);
131
131
  /* 02-11: the one command a tool may ask of the server. */
132
- if (chat) out.push('- To be restarted (new tools to take up, or anything stuck): finish what runs, then `touch /work/.parley/restart-asked`; the server restarts you once your turn ends, and your work picks up where it was.');
132
+ if (chat) out.push('- To be restarted (new tools to take up, or anything stuck): finish what runs, then `touch /work/.parley/restart-asked`; the server restarts you once your turn ends, and your work picks up where it was. /work itself fails ("not connected"): `cd / && touch /var/tmp/clavarium-restart-asked` instead.');
133
133
  /* Its docket (dockets.mjs): what wakes it waits there until it says done or failed. */
134
134
  if (chat) out.push('- What wakes you (a file arrived, the clock, a call) waits in your docket: when told "run docket", run it, do each, then docket done ID or docket failed ID "why". To be reminded later: docket remind --at "2026-10-23 09:00" (or --in 2h, --cron "0 9 * * 1") "what for". docket --help says all.');
135
135
  /* Its lists (binders.mjs): kept on the server, asked for through .binder; a person approves. */
package/server/health.mjs CHANGED
@@ -25,6 +25,14 @@
25
25
  shell. It prints one fact per line; the server reads only these lines. */
26
26
  import { SHARING_STEP } from './vm.mjs';
27
27
  import { WHY } from './linkguard.mjs';
28
+ import { SOCKET } from './tmux.mjs';
29
+ import { SESSION } from './conversations.mjs';
30
+
31
+ /* A FILE OUTSIDE /work where its tool may ask to be restarted when /work itself is dead (16-11): the
32
+ one in its chat's folder (talk.mjs, RESTART_ASKED) cannot be written then. Read by the probe. */
33
+ export const RESTART_OUTSIDE = '/var/tmp/clavarium-restart-asked';
34
+ /* What a folder that came loose looks like on a terminal (the kernel's words for ENOTCONN). */
35
+ const LOOSE_WORDS = 'transport endpoint is not connected|socket is not connected|ENOTCONN';
28
36
 
29
37
  /* How long installing the shared-folder helper in a machine may take (it comes from the snap store). */
30
38
  export const SHARING_MS = 180_000;
@@ -41,6 +49,15 @@ export const PROBE = [
41
49
  ' else echo "mount missing $p"; fi',
42
50
  'done',
43
51
  'if [ -d /work ] && awk \'$2=="/work"{f=1} END{exit !f}\' /proc/mounts; then timeout 5 df -Pm /work 2>/dev/null | awk \'NR==2{print "disk /work", $4, $2}\'; fi',
52
+ /* ITS TOOL STILL IN A FOLDER THAT WENT (16-11). A folder put back is a NEW mount: a program that was
53
+ in the old one stays in it, dead ("Transport endpoint is not connected"), until it is started
54
+ again -- the folder looks well, its tool does not. So each program of its tool's session whose
55
+ folder is ours to read (readlink) and cannot be entered is said; the first one is enough. */
56
+ `t=$(tmux -L ${SOCKET} list-panes -t '=${SESSION}:' -F '#{pane_pid}' 2>/dev/null | head -n 1)`,
57
+ 'case "$t" in ""|*[!0-9]*) ;; *) timeout 5 sh -c \'for p in $(ps -o pid= -s "$1" 2>/dev/null); do l=$(readlink "/proc/$p/cwd" 2>/dev/null) || continue; [ -n "$l" ] || continue; [ -d "/proc/$p/cwd/." ] || { echo "stale $p"; exit 0; }; done\' stale "$t";; esac',
58
+ /* What its terminal shows now: a folder that is not connected, said by its tool (a symptom, not a proof). */
59
+ `tmux -L ${SOCKET} capture-pane -p -t '=${SESSION}:' 2>/dev/null | grep -c -i -E '${LOOSE_WORDS}' | awk '{print "screen", $1+0}'`,
60
+ `if [ -f ${RESTART_OUTSIDE} ]; then echo "restart asked"; fi`,
44
61
  ].join('\n');
45
62
  export const PROBE_NAME = 'clavarium-health';
46
63
 
@@ -76,6 +93,9 @@ export function readProbe(text, paths = []) {
76
93
  if (parts[0] === 'oomkinds' && parts.length === 3 && a !== undefined && b !== undefined) facts.oomKinds = { machine: a, limit: b };
77
94
  if (parts[0] === 'disk' && parts.length === 4 && disks.has(parts[1]) && b !== undefined && c !== undefined) facts.disks[parts[1]] = { availableMb: b, sizeMb: c };
78
95
  if (parts[0] === 'mount' && parts.length === 3 && expected.has(parts[2]) && MOUNT_STATES.has(parts[1])) facts.mounts[parts[2]] = parts[1];
96
+ if (parts[0] === 'stale' && parts.length === 2 && a !== undefined) facts.stale = true;
97
+ if (parts[0] === 'screen' && parts.length === 2 && a !== undefined) facts.screenLoose = a;
98
+ if (line.trim() === 'restart asked') facts.restartAsked = true;
79
99
  }
80
100
  return facts;
81
101
  }
@@ -123,6 +143,9 @@ export function judge(record) {
123
143
  for (const path of record.remounted ?? []) add('info', 'mount', `remounted:${path}`, `${path} had come loose in the machine: it was mounted again.`);
124
144
  for (const { path, why } of record.failed ?? []) add('bad', 'mount', `failed:${path}`, `${path} is not reachable in the machine and could not be mounted again${why ? `: ${why}` : ''}.`);
125
145
  for (const path of record.missing ?? []) if (!(record.failed ?? []).some((f) => f.path === path)) add('warn', 'mount', `missing:${path}`, `${path} is not reachable in the machine.`);
146
+ if (record.stale) add('bad', 'mount', 'stale-tool', 'Its tool is still in a folder that came loose: it is restarted, its work picks up where it was.');
147
+ /* Its terminal says so while its folders look well: said, nothing done (its tool may only be quoting it). */
148
+ else if (record.screenLoose > 0 && !(record.missing ?? []).length) add('warn', 'mount', 'screen-loose', 'Its terminal says a folder is not connected, though its folders look well.');
126
149
  }
127
150
  /* Links its folders hold that the share cannot serve (linkguard.mjs): looked at on this server, whatever its machine does. */
128
151
  for (const l of record.links?.removed ?? []) add('info', 'link', `link-removed:${l.folder}/${l.path}`, `/resources/${l.folder}/${l.path} was a broken link (${WHY[l.kind] ?? l.kind}): it was removed on the server, what it pointed to left as it was.`);
@@ -226,6 +249,7 @@ export class Health {
226
249
  return this.#keep(name, {
227
250
  at, state, answering: true, memory: facts.memory, oomKills: facts.oomKills ?? 0, ...(facts.oomKinds ? { oomKinds: facts.oomKinds } : {}), disks: facts.disks,
228
251
  paths, missing: loose(), ...(remounted.length ? { remounted } : {}), ...(failed.length ? { failed } : {}), ...(links ? { links } : {}),
252
+ ...(facts.stale ? { stale: true } : {}), ...(facts.screenLoose ? { screenLoose: facts.screenLoose } : {}), ...(facts.restartAsked ? { restartAsked: true } : {}),
229
253
  /* What was put back stays said until a later look finds nothing to put back. */
230
254
  });
231
255
  }
package/server/main.mjs CHANGED
@@ -59,7 +59,8 @@ import { GitChecks } from './gitchecks.mjs';
59
59
  import { GitKeeper } from './gitkeeper.mjs';
60
60
  import { GitRunner } from './gitrunner.mjs';
61
61
  import { Shelf } from './shelf.mjs';
62
- import { Health } from './health.mjs';
62
+ import { Health, RESTART_OUTSIDE } from './health.mjs';
63
+ import { Revive } from './revive.mjs';
63
64
  import { LinkGuard, removedLine, toolLine } from './linkguard.mjs';
64
65
  import { Setup } from './setup.mjs';
65
66
  import { Capacity } from './capacity.mjs';
@@ -613,7 +614,27 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
613
614
  /* A TOOL THAT ASKS TO BE RESTARTED (02-11: to take up its tools, after an update): its tool restarted by this server
614
615
  once its turn has ended (its pulse no longer busy), said in its chat; once per ten minutes at most. */
615
616
  const restartedAt = new Map();
617
+ /* ITS TOOL STILL IN A FOLDER THAT CAME LOOSE, or asking from outside /work (16-11, revive.mjs): restarted
618
+ by the server, its tool only; told through its docket first (read as it starts), its chat after. */
619
+ const revive = new Revive({
620
+ restart: (name) => all.restartTool(name),
621
+ busy: (name) => talk.pulse(name)?.busy === true,
622
+ taken: (name) => vms.exec(name, ['rm', '-f', RESTART_OUTSIDE], { timeoutMs: 10_000 }),
623
+ tell: (name, why, step) => {
624
+ const loose = why === 'stale';
625
+ if (step === 'before') {
626
+ if (loose) try { if (dockets.on(name)) dockets.post(name, { kind: 'restarted', text: 'Your work folder came loose in your machine and was put back: your tool was restarted to see it again (what was in the old one could not be reached). Your work picks up where it was; what ran in the background stopped.' }); } catch { /* its docket may be off */ }
627
+ return;
628
+ }
629
+ const text = step === 'done'
630
+ ? (loose ? 'Its work folder had come loose: its tool was restarted to see it again. Its work picks up where it was.' : 'Its tool was restarted as it asked: its work picks up where it was.')
631
+ : 'Its tool could not be restarted: open its terminal and type exit, it starts again.';
632
+ try { talk.event(name, { kind: step === 'done' ? 'restarted' : 'machine-problem', text, topic: step === 'done' ? 'Restarted' : 'Machine', ...(step === 'done' ? {} : { tone: 'warn' }) }); } catch { /* its chat is off */ }
633
+ if (step === 'failed') events.add({ kind: 'machine', text: `${name}: ${text}`, conversation: name });
634
+ },
635
+ });
616
636
  const restartTimer = setInterval(() => {
637
+ void revive.tick().catch(() => {});
617
638
  for (const name of all.awake()) {
618
639
  if (!talk.restartAsked(name)) continue;
619
640
  if (talk.pulse(name)?.busy) continue;
@@ -646,7 +667,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
646
667
  /* Where its chat is on, its agent is given an event when its disk or memory crosses a level (healthdocket.mjs);
647
668
  not where its owner turned on its own reaction (above): one way of telling it, not two. */
648
669
  const healthDocket = new HealthDocket({ store: new Store(`${dataDir}/health-docket.json`), dockets, reacting: (name) => reacting.settings(name).on });
649
- health.forgotten = (name) => { healthDocket.forget(name); watchdog.forget(name); };
670
+ health.forgotten = (name) => { healthDocket.forget(name); watchdog.forget(name); revive.forget(name); };
650
671
  /* A machine's problems worth keeping in What happened: said once, until they went away. */
651
672
  const problemsSaid = new Map();
652
673
  /* ITS WATCHDOG (watchdog.mjs): mute or full for as long as its owner set, forced off then started, once;
@@ -662,6 +683,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
662
683
  alert: (payload) => { events.add({ kind: 'machine', text: `${payload.title}: ${payload.body ?? ''}`.trim() }); void alerts.tell(payload)?.catch?.(() => {}); } });
663
684
  health.judged = (name, record) => {
664
685
  void watchdog.judged(name, record).catch(() => {});
686
+ try { revive.judged(name, record); } catch { /* its tool: nothing more */ }
665
687
  talk.machine(name, record); void reacting.judged(name, record).catch(() => {});
666
688
  /* A folder that came loose and was put back: said once, in its chat (the look that put it back). */
667
689
  for (const path of record?.remounted ?? []) { try { talk.event(name, { kind: 'machine-ok', text: `Le dossier ${path} s'était détaché de la machine : il a été remonté.`, topic: 'Machine', brief: 'Shared folder' }); } catch { /* its chat is off */ } }
@@ -0,0 +1,66 @@
1
+ /* ITS TOOL STARTED AGAIN WHEN A FOLDER IT WAS IN CAME LOOSE (16-11).
2
+ *
3
+ * Seen in production: /work of a conversation came loose ("socket is not connected"). Putting the
4
+ * folder back (health.mjs, resources.mjs repair) makes a NEW mount; its tool, and every program it
5
+ * started (its shell, Parley, Docket), stays in the old one, dead, until it is started again. It cannot
6
+ * even ask to be restarted: that request is a file in /work. Its owner typed exit by hand; this does it.
7
+ *
8
+ * Told by health.mjs, each look (`judged`):
9
+ * - `stale`: a program of its tool's session is in a folder that cannot be entered;
10
+ * - `restartAsked`: its tool asked from outside /work (health.mjs, RESTART_OUTSIDE).
11
+ * Then, at the next tick: its tool only is restarted (conversations.mjs restartTool, never its
12
+ * machine), once its turn has ended -- or after WAIT_MS anyway when stale: a tool stuck in a dead
13
+ * folder cannot say its turn ended (its pulse is in /work). Never a loop: not again within AGAIN_MS.
14
+ * Its tool told through its docket before it starts again, its owner through What happened.
15
+ */
16
+ export const WAIT_MS = 5 * 60_000;
17
+ export const AGAIN_MS = 30 * 60_000;
18
+
19
+ export class Revive {
20
+ #restart; #busy; #tell; #taken; #now; #wanted = new Map(); #lastAt = new Map(); #going = new Set();
21
+
22
+ /* `restart(name)`: its tool restarted, resolves with whether it was. `busy(name)`: its turn goes on.
23
+ `tell(name, why, step)`: said where it should be, step 'before' (its docket), then 'done' or 'failed' (main.mjs).
24
+ `taken(name)`: the request outside /work removed (in its machine). */
25
+ constructor({ restart, busy = () => false, tell = () => {}, taken = async () => {}, now = Date.now }) {
26
+ this.#restart = restart; this.#busy = busy; this.#tell = tell; this.#taken = taken; this.#now = now;
27
+ }
28
+
29
+ /* What one look found. A look that finds it well forgets a stale one not yet acted on. */
30
+ judged(name, record) {
31
+ if (!record || record.state !== 'Running' || record.answering !== true) return;
32
+ if (record.restartAsked) { void Promise.resolve().then(() => this.#taken(name)).catch(() => {}); this.#want(name, 'asked'); }
33
+ if (record.stale) this.#want(name, 'stale');
34
+ else if (this.#wanted.get(name)?.why === 'stale') this.#wanted.delete(name);
35
+ }
36
+
37
+ #want(name, why) {
38
+ const had = this.#wanted.get(name);
39
+ /* A stale tool outranks a plain request: it is acted on even while it looks busy. */
40
+ if (!had || (why === 'stale' && had.why !== 'stale')) this.#wanted.set(name, { why, since: had?.since ?? this.#now() });
41
+ }
42
+
43
+ wanted(name) { return this.#wanted.get(name)?.why ?? null; }
44
+ forget(name) { this.#wanted.delete(name); this.#lastAt.delete(name); }
45
+
46
+ /* One pass: each one wanted, restarted when it may be. Resolves with the names restarted. */
47
+ async tick() {
48
+ const done = [];
49
+ for (const [name, { why, since }] of [...this.#wanted]) {
50
+ if (this.#going.has(name)) continue;
51
+ const busy = (() => { try { return this.#busy(name); } catch { return false; } })();
52
+ if (busy && !(why === 'stale' && this.#now() - since >= WAIT_MS)) continue;
53
+ this.#wanted.delete(name);
54
+ if (this.#now() - (this.#lastAt.get(name) ?? -Infinity) < AGAIN_MS) continue;
55
+ this.#lastAt.set(name, this.#now());
56
+ this.#going.add(name);
57
+ try {
58
+ try { this.#tell(name, why, 'before'); } catch { /* told, nothing more */ }
59
+ const ok = await this.#restart(name).catch(() => false);
60
+ if (ok) done.push(name);
61
+ try { this.#tell(name, why, ok ? 'done' : 'failed'); } catch { /* told, nothing more */ }
62
+ } finally { this.#going.delete(name); }
63
+ }
64
+ return done;
65
+ }
66
+ }