clavarium 0.2.1-next.1 → 0.2.1-next.2

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.
@@ -89,7 +89,7 @@ UPDATER="$CODE/current/app/deploy/updater.mjs"
89
89
  UPDATE_STATE="/var/lib/clavarium/update"
90
90
 
91
91
  refuse() { echo "REFUSED: $*" >&2; exit 78; }
92
- usage() { echo "usage: clavarium-host [--say-only [--data DIR] [--mnt DIR]] <vm|shelf|folder|work|view|tools|net|git|server|update> <verb> [arguments]" >&2; exit 64; }
92
+ usage() { echo "usage: clavarium-host [--say-only [--data DIR] [--mnt DIR]] <vm|shelf|folder|work|view|tools|mounts|net|git|server|update> <verb> [arguments]" >&2; exit 64; }
93
93
 
94
94
  SAY="no"; DATA=""; MNT=""
95
95
  while [ $# -gt 0 ]; do
@@ -210,6 +210,22 @@ folder_of() {
210
210
  held "$MNT/resources/$1"
211
211
  }
212
212
 
213
+ # A VIEW WHOSE PROGRAM IS GONE (bindfs killed or crashed) stays mounted, but
214
+ # everything done there fails with "Transport endpoint is not connected": the
215
+ # view cannot be made again, and before 0.2.1 the server died at its start on
216
+ # it -- only a reboot cleared it (the update of 19-10). Such a mount is taken
217
+ # off (lazily: whatever still holds it gets an error, never a hang); one that
218
+ # answers is left alone. Only a FUSE mount exactly at that path, under $MNT.
219
+ unstale() {
220
+ [ "$SAY" = "yes" ] && return 0
221
+ local at="$1"
222
+ case "$at" in "$MNT"/views/*|"$MNT"/toolbox/view) : ;; *) refuse "not a view: $at" ;; esac
223
+ awk -v p="$at" '$2 == p && $3 ~ /^fuse/ { found = 1 } END { exit !found }' /proc/self/mounts || return 0
224
+ timeout 10 stat -- "$at" >/dev/null 2>&1 && return 0
225
+ umount -l -- "$at" || refuse "the broken view at $at could not be taken off"
226
+ echo "a broken view was taken off: $at" >&2
227
+ }
228
+
213
229
  # How a finished read unit is said to the server: from what systemd recorded,
214
230
  # never from what the code inside printed. See "git read".
215
231
  unit_code() {
@@ -541,6 +557,7 @@ case "$AREA $VERB" in
541
557
  [ $# -eq 1 ] || usage; is_name "$1" || refuse "not a folder name: $1"
542
558
  folder_of "$1"; kept views
543
559
  if [ "$SAY" != "yes" ]; then
560
+ unstale "$MNT/views/$1"
544
561
  mkdir -p "$MNT/views/$1"
545
562
  held "$MNT/views/$1"
546
563
  mountpoint -q "$MNT/views/$1" && exit 0
@@ -558,6 +575,7 @@ case "$AREA $VERB" in
558
575
  files="$MNT/toolbox/files"; view="$MNT/toolbox/view"
559
576
  if [ "$SAY" = "yes" ]; then printf '%s\n' "install -d -o OWNER -g GROUP -m 0755 $files" "bindfs -r -o allow_other $files $view"; exit 0; fi
560
577
  kept toolbox
578
+ unstale "$view"
561
579
  [ ! -L "$files" ] && [ ! -L "$view" ] || refuse "the tools folder is not what it should be"
562
580
  if [ ! -e "$files" ]; then owner="$(stat -c %u:%g "$DATA")"; install -d -o "${owner%:*}" -g "${owner#*:}" -m 0755 "$files"; fi
563
581
  held "$files"
@@ -569,11 +587,23 @@ case "$AREA $VERB" in
569
587
  [ $# -eq 1 ] || usage; is_name "$1" || refuse "not a folder name: $1"
570
588
  kept views
571
589
  if [ "$SAY" != "yes" ]; then
590
+ unstale "$MNT/views/$1"
572
591
  [ -e "$MNT/views/$1" ] || exit 0
573
592
  held "$MNT/views/$1"
574
593
  mountpoint -q "$MNT/views/$1" || exit 0
575
594
  fi
576
595
  run umount "$MNT/views/$1" ;;
596
+ "mounts repair")
597
+ # Every broken view taken off (see unstale): asked by the server as it
598
+ # starts, and by the updater (root) after each stop of the server, so
599
+ # that a view left broken never needs a reboot. Says what it did.
600
+ [ $# -eq 0 ] || usage
601
+ if [ "$SAY" = "yes" ]; then echo "umount -l <each FUSE view under $MNT that does not answer>"; exit 0; fi
602
+ kept views; kept toolbox
603
+ awk '$3 ~ /^fuse/ { print $2 }' /proc/self/mounts | while IFS= read -r at; do
604
+ case "$at" in "$MNT"/views/*|"$MNT"/toolbox/view) unstale "$at" ;; esac
605
+ done
606
+ exit 0 ;;
577
607
  "net taps")
578
608
  [ $# -eq 0 ] || usage
579
609
  run pgrep -a qemu-system ;;
package/deploy/install.sh CHANGED
@@ -551,7 +551,8 @@ fi
551
551
  # with Let's Encrypt's as soon as it can (sudo clavarium doctor --certificate).
552
552
  BIND=""; [ -z "$RELAY" ] || BIND=" bind 127.0.0.1"
553
553
  # The probe's token: kept on a rerun (see deploy/doctor.mjs, probeBlock).
554
- PROBE="$(sed -n 's/.*respond "\([0-9a-f]\{32\}\)" 200.*/\1/p' /etc/caddy/Caddyfile 2>/dev/null | head -1)"
554
+ # No Caddyfile yet (going online from local mode): no token, not a failure (pipefail).
555
+ PROBE="$( { sed -n 's/.*respond "\([0-9a-f]\{32\}\)" 200.*/\1/p' /etc/caddy/Caddyfile 2>/dev/null || true; } | head -1)"
555
556
  [ -n "$PROBE" ] || PROBE="$(openssl rand -hex 16)"
556
557
  cat > /etc/caddy/Caddyfile <<CADDY
557
558
  # The only thing on this machine that takes what comes from the outside.
@@ -69,6 +69,8 @@ const BUSY = ['building', 'moving', 'restarting'];
69
69
  const BUSY_STALE_MS = 30 * 60_000;
70
70
  /* THE WATCHDOG (each timer turn): down this many turns in a row, or its service failed: one action, at most one an hour. */
71
71
  const WATCH_MISSES = 3;
72
+ /* Restarts by systemd, the server not answering: it is looping (a port held, a view broken). */
73
+ const WATCH_LOOP = 3;
72
74
  const WATCH_EVERY_MS = 3600_000;
73
75
  /* An update this recent is the first suspect when the server will not stay up. */
74
76
  const WATCH_RECENT_MS = 24 * 3600_000;
@@ -155,7 +157,7 @@ const toHex = (integrity) => Buffer.from(String(integrity).replace(/^sha512-/, '
155
157
  export class Updater {
156
158
  #o; #run; #fetch;
157
159
  constructor({ code = PATHS.code, conf = PATHS.conf, stateDir = PATHS.stateDir, data = PATHS.data, hostTarget = PATHS.host, gitReadTarget = PATHS.gitRead, registry = REGISTRY, run = runCommand, fetcher = fetch, now = () => new Date(), log = (line) => console.log(line),
158
- verifySignatures, restart, health, backup, restoreData, installPrivileged, ensureNode, serviceState, answers, mainPid, pidCwd, diagnose, dropIn = DROP_IN,
160
+ verifySignatures, restart, health, backup, restoreData, installPrivileged, ensureNode, serviceState, answers, restarts, mainPid, pidCwd, diagnose, dropIn = DROP_IN,
159
161
  clock = () => Date.now(), sleep = (ms) => new Promise((r) => setTimeout(r, ms)), minFreeMb = 1024, healthMs = 60_000, watchMs = 120_000, settleMs = 10_000 } = {}) {
160
162
  this.#o = { code, conf, stateDir, data, hostTarget, gitReadTarget, registry: registry.replace(/\/$/, ''), now, log, minFreeMb, healthMs, watchMs, settleMs, clock, sleep, dropIn };
161
163
  this.#run = run; this.#fetch = fetcher;
@@ -172,6 +174,8 @@ export class Updater {
172
174
  this.serviceState = serviceState ?? (async () => (await this.#run(['systemctl', 'show', '-p', 'ActiveState', '--value', 'clavarium.service'], { timeoutMs: 10_000 })).stdout.trim() || 'unknown');
173
175
  /* Does the server answer, on its port, here? */
174
176
  this.answers = answers ?? (() => this.#fetch(`http://127.0.0.1:${readConf(this.#o.conf).PORT}/`, { signal: AbortSignal.timeout(5000), redirect: 'manual' }).then((r) => r.status < 500).catch(() => false));
177
+ /* How many times systemd started it again by itself since it was last started. */
178
+ this.restarts = restarts ?? (async () => Number((await this.#run(['systemctl', 'show', '-p', 'NRestarts', '--value', 'clavarium.service'], { timeoutMs: 10_000 })).stdout.trim()) || 0);
175
179
  this.mainPid = mainPid ?? (async () => (await this.#run(['systemctl', 'show', '-p', 'MainPID', '--value', 'clavarium.service'], { timeoutMs: 10_000 })).stdout.trim());
176
180
  this.pidCwd = pidCwd ?? ((pid) => { try { return realpathSync(`/proc/${pid}/cwd`); } catch { return ''; } });
177
181
  }
@@ -529,11 +533,15 @@ export class Updater {
529
533
  return last?.to === available && last.result !== 'done' ? `${available} did not work: back to ${last.from ?? 'nothing'} (${last.why ?? last.result})` : `updated to ${available}`;
530
534
  }
531
535
 
532
- /* THE WATCHDOG, at each timer turn: the server down (its service failed or stopped, or no answer
533
- WATCH_MISSES turns in a row) is acted on, once, and said in the history:
534
- - after an update of less than WATCH_RECENT_MS, with the release before it kept (and able to
535
- read the data): back to it, by itself ("did not stay up"), not tried again by itself;
536
- - otherwise: one restart.
536
+ /* THE WATCHDOG, at each timer turn: the server down (its service failed, stopped, or starting
537
+ again and again; or no answer WATCH_MISSES turns in a row) is acted on, once, and said in the
538
+ history:
539
+ - first, one restart of the release that runs: what blocked the old server (a process left
540
+ on its port, a view left broken) is cleared by the restart itself (#restart), and the new
541
+ version is seldom the cause (19-10: going back cured nothing);
542
+ - only if it does not come back, after an update of less than WATCH_RECENT_MS with the
543
+ release before it kept (and able to read the data): back to it, by itself, not tried
544
+ again by itself.
537
545
  Never more than one action in WATCH_EVERY_MS, so that it never loops. { acted, said } */
538
546
  async watchdog() {
539
547
  const state = await this.serviceState().catch(() => 'unknown');
@@ -542,7 +550,10 @@ export class Updater {
542
550
  if (up) { if (w.misses) this.#save({ watch: { ...w, misses: 0 } }); return { acted: false, said: 'up' }; }
543
551
  const misses = (w.misses ?? 0) + 1;
544
552
  this.#save({ watch: { ...w, misses, seen: state } });
545
- const down = state === 'failed' || state === 'inactive' || misses >= WATCH_MISSES;
553
+ /* Started again and again by systemd (seen "activating", or "active" for the second before it
554
+ dies again: many restarts by itself) is down at once, like failed or stopped. */
555
+ const looping = state === 'activating' || await this.restarts().catch(() => 0) >= WATCH_LOOP;
556
+ const down = state === 'failed' || state === 'inactive' || looping || misses >= WATCH_MISSES;
546
557
  this.#o.log(`watchdog: the server is ${state === 'active' ? 'active but does not answer' : state} (turn ${misses})`);
547
558
  if (!down) return { acted: false, said: `the server does not answer (turn ${misses} of ${WATCH_MISSES})` };
548
559
  const now = this.#o.now();
@@ -553,13 +564,17 @@ export class Updater {
553
564
  this.#save({ watch: { misses: 0, actedAt: now.toISOString(), seen: state } });
554
565
  const log = await this.#seen(`the server was down (${state})`);
555
566
  const current = this.current();
567
+ const v = current?.version ?? null;
568
+ const was = looping ? 'starting again and again' : state === 'active' ? 'no answer' : state;
569
+ this.#o.log(`watchdog: the server is ${state}: restarted once`);
570
+ const failed = current ? await this.#restartAndCheck(current) : await this.restart().then((r) => (r?.code ? lastLine(r) : '')).catch((e) => e.message);
556
571
  /* The last update or return (a restart by the watchdog is not one). */
557
572
  const last = (this.#state().history ?? []).find((h) => h.action !== 'restart');
558
- const recent = current && last && last.action === 'update' && last.result === 'done' && last.to === current.version && now - new Date(last.at) < WATCH_RECENT_MS;
573
+ const recent = failed && current && last && last.action === 'update' && last.result === 'done' && last.to === current.version && now - new Date(last.at) < WATCH_RECENT_MS;
559
574
  const previous = recent ? this.releases().find((r) => !r.current && r.version === last.from) : undefined;
560
575
  const format = this.#dataFormat();
561
576
  if (previous && (format === undefined || previous.dataFormat >= format)) {
562
- let why = `${current.version} did not stay up (its service ${state === 'active' ? 'did not answer' : `was ${state}`}): back to ${previous.version}`;
577
+ let why = `${current.version} did not stay up (its service ${state === 'active' ? 'did not answer' : `was ${state}`}) nor came back after a restart (${failed}): back to ${previous.version}`;
563
578
  this.#o.log(`watchdog: ${why}`);
564
579
  this.#step('update', current.version, 'Going back');
565
580
  let back;
@@ -570,10 +585,7 @@ export class Updater {
570
585
  this.prune();
571
586
  return { acted: true, said: why };
572
587
  }
573
- const v = current?.version ?? null;
574
- this.#o.log(`watchdog: the server is ${state}: restarted once`);
575
- const failed = current ? await this.#restartAndCheck(current) : await this.restart().then((r) => (r?.code ? lastLine(r) : '')).catch((e) => e.message);
576
- const why = `the server was down (${state === 'active' ? 'no answer' : state}): restarted by itself${failed ? `; it did not come back (${failed}): journalctl -u clavarium` : ''}`;
588
+ const why = `the server was down (${was}): restarted by itself${failed ? `; it did not come back (${failed}): journalctl -u clavarium` : ''}`;
577
589
  this.#history({ action: 'restart', from: v, to: v, result: failed ? 'failed' : 'done', by: 'watchdog', why, log: log.slice(-LOG_MAX) });
578
590
  return { acted: true, said: why };
579
591
  } finally { unlock(); }
@@ -646,6 +658,10 @@ export class Updater {
646
658
  const stuck = left.filter((x) => x.state === 'D' && x.port);
647
659
  if (stuck.length) return { code: 1, stderr: `a stuck process holds the port: ${stuck.map((p) => `pid ${p.pid}, state D`).join('; ')} (it waits on the kernel and cannot be killed): the server needs a reboot` };
648
660
  if (left.some((x) => x.state === 'D')) this.#o.log(`processes of the old server stuck in state D (not on the port): ${left.map((p) => p.pid).join(', ')}`);
661
+ /* The views the old server left broken (their program killed with it): taken off, or the
662
+ new server could not make them again before a reboot. Never a reason not to start. */
663
+ const repaired = await this.#run([this.#o.hostTarget, 'mounts', 'repair'], { timeoutMs: 60_000 });
664
+ if (repaired.code || String(repaired.stderr).trim()) this.#o.log(`mounts: ${String(repaired.stderr).trim() || `exit ${repaired.code}`}`);
649
665
  await this.#run(['systemctl', 'reset-failed', 'clavarium.service'], { timeoutMs: 30_000 });
650
666
  return this.#run(['systemctl', 'start', 'clavarium.service'], { timeoutMs: 120_000 });
651
667
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.1-next.1",
3
+ "version": "0.2.1-next.2",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.1-next.1",
9
+ "version": "0.2.1-next.2",
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.1-next.1",
3
+ "version": "0.2.1-next.2",
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/bridge.mjs CHANGED
@@ -29,6 +29,8 @@ export const PATH = '/terminal';
29
29
  export const DEVICE_PATH = '/c/terminal';
30
30
  export const CLOSE_ENDED = 1000;
31
31
  export const CLOSE_TAKEN = 4001;
32
+ /* A device whose right on this terminal was taken back (or its session ended): put out at once. */
33
+ export const CLOSE_REVOKED = 4003;
32
34
  /* A channel that dropped is reopened after a moment, a few times a minute at most. */
33
35
  export const REOPEN_AFTER_MS = 1000;
34
36
  export const REDRAW_AFTER_MS = 250;
@@ -82,15 +84,33 @@ export const sameOrigin = makeOriginCheck();
82
84
  export function attachBridge(server, { spawn, onLeft = () => {}, onEnded = () => {}, originOk = sameOrigin, gate = () => 'local', deviceName = () => undefined, onRejoin = () => {}, onTyped = () => {} }) {
83
85
  const sockets = new WebSocketServer({ noServer: true });
84
86
  const seats = new Seats();
87
+ /* THE DEVICES AT A TERMINAL, each with what lets it stay: asked again when the owner changes
88
+ what devices were given (recheck), and before anything it types is typed. A right taken
89
+ back used to end only at the next connection -- an open terminal went on (found 19-10). */
90
+ const deviceSeats = new Map(); /* viewer -> () => still allowed */
91
+ const revoked = new WeakSet();
92
+ const allowed = (viewer) => {
93
+ if (revoked.has(viewer)) return false;
94
+ const still = deviceSeats.get(viewer);
95
+ if (!still || still()) return true;
96
+ revoked.add(viewer); deviceSeats.delete(viewer);
97
+ viewer.close(CLOSE_REVOKED, 'not given any more');
98
+ /* A device that does not answer the close is not waited for. */
99
+ setTimeout(() => viewer.terminate(), 2000).unref?.();
100
+ return false;
101
+ };
85
102
 
86
103
  server.on('upgrade', (request, socket, head) => {
87
104
  const url = new URL(request.url ?? '/', 'http://local');
88
105
  let name;
106
+ let still;
89
107
  if (url.pathname === DEVICE_PATH) {
90
108
  /* A device: no operator identity is looked at, and none is needed. */
91
109
  /* `d`: which of its pairings this device speaks for. */
92
- name = deviceName(request.headers, url.searchParams.get('d') ?? '', url.searchParams.get('c') ?? undefined) ?? '';
110
+ const ask = () => deviceName(request.headers, url.searchParams.get('d') ?? '', url.searchParams.get('c') ?? undefined) ?? '';
111
+ name = ask();
93
112
  if (!isConversationName(name) || !originOk(request.headers)) { socket.destroy(); return; }
113
+ still = () => ask() === name;
94
114
  } else if (url.pathname === PATH) {
95
115
  name = url.searchParams.get('c') ?? '';
96
116
  if (!isConversationName(name) || !originOk(request.headers) || gate(request.headers) === undefined) { socket.destroy(); return; }
@@ -98,6 +118,7 @@ export function attachBridge(server, { spawn, onLeft = () => {}, onEnded = () =>
98
118
  const cols = Number(url.searchParams.get('cols'));
99
119
  const rows = Number(url.searchParams.get('rows'));
100
120
  sockets.handleUpgrade(request, socket, head, (viewer) => {
121
+ if (still) { deviceSeats.set(viewer, still); viewer.on('close', () => deviceSeats.delete(viewer)); }
101
122
  seat(viewer, name, within(cols, COLS) ? cols : 80, within(rows, ROWS) ? rows : 24);
102
123
  });
103
124
  });
@@ -236,7 +257,7 @@ export function attachBridge(server, { spawn, onLeft = () => {}, onEnded = () =>
236
257
  if (viewer.readyState === 1) viewer.send(JSON.stringify({ type: 'ready' }));
237
258
  const mine = kept;
238
259
  viewer.on('message', (data, binary) => {
239
- if (mine.sink !== viewer) return;
260
+ if (mine.sink !== viewer || !allowed(viewer)) return;
240
261
  /* `onTyped`: told THAT something came from a screen (the owner is there), which is not reading what the tool prints. */
241
262
  if (binary) {
242
263
  const typed = data.toString();
@@ -296,5 +317,7 @@ export function attachBridge(server, { spawn, onLeft = () => {}, onEnded = () =>
296
317
  since anything came out of it -- THAT something came, never what: a
297
318
  tool still drawing its first screen is not reading its keyboard yet. */
298
319
  const settled = (name) => { const kept = live.get(name); return kept ? { openFor: Date.now() - kept.openedAt, quietFor: Date.now() - kept.outputAt } : null; };
299
- return { seats, drop, warm, type, settled, open: (name) => live.has(name), droppedAt: (name) => dropped.get(name) };
320
+ /* What devices were given changed: each device at a terminal is asked again. */
321
+ const recheck = () => { for (const viewer of [...deviceSeats.keys()]) allowed(viewer); };
322
+ return { seats, drop, warm, type, settled, recheck, open: (name) => live.has(name), droppedAt: (name) => dropped.get(name) };
300
323
  }
@@ -60,6 +60,7 @@ export class Devices {
60
60
  conversation was shared in two parts (see below). */
61
61
  constructor(store, now = () => Date.now(), grants = new Grants(), { chatWas = () => false } = {}) {
62
62
  this.#store = store; this.#now = now; this.#grants = grants;
63
+ this.changed = () => {};
63
64
  /* Sessions outlive a restart of this server (a new version put in place): what is kept is
64
65
  only their sha256 and their end, on the device's record, never the session itself. */
65
66
  for (const d of store.all()) for (const k of Array.isArray(d.sessions) ? d.sessions : []) {
@@ -133,6 +134,7 @@ export class Devices {
133
134
  const clean = readRights(asset, rights);
134
135
  if (typeOf(asset) === 'secret') throw new Refusal(400, 'A secret is handed to a conversation, never shared with a device.');
135
136
  this.#grants.give(pairingSubject(id), asset, clean);
137
+ this.changed();
136
138
  }
137
139
  /* A name the owner will recognise. */
138
140
  rename(id, label) {
@@ -148,6 +150,7 @@ export class Devices {
148
150
  if (!this.#store.get(id)) throw new Refusal(404, 'No such device.');
149
151
  this.#grants.take(pairingSubject(id), String(asset));
150
152
  if (this.grantsOf(id).length === 0) this.revoke(id);
153
+ this.changed();
151
154
  }
152
155
 
153
156
  revoke(id) {
@@ -156,6 +159,7 @@ export class Devices {
156
159
  this.#grants.forgetSubject(pairingSubject(id));
157
160
  this.#challenges.delete(id);
158
161
  for (const [key, s] of this.#sessions) if (s.device === id) this.#sessions.delete(key);
162
+ this.changed();
159
163
  }
160
164
 
161
165
  /* Something is gone (a conversation archived, a folder removed): nobody
@@ -164,6 +168,7 @@ export class Devices {
164
168
  forgetAsset(asset) {
165
169
  this.#grants.forgetAsset(asset);
166
170
  for (const d of this.#store.all()) if (this.grantsOf(d.name).length === 0) this.revoke(d.name);
171
+ this.changed();
167
172
  }
168
173
 
169
174
  /* ---- device side ---- */
@@ -231,7 +236,10 @@ export class Devices {
231
236
  const id = this.pairingOf(session, pairing);
232
237
  if (id === undefined) return undefined;
233
238
  const mine = this.conversationsOf(id);
234
- return mine.includes(wanted) ? wanted : mine[0];
239
+ /* None named: its first. One named and not given: none -- never another one in its place
240
+ (a terminal asked for one conversation once opened on another). */
241
+ if (wanted === undefined || wanted === '') return mine[0];
242
+ return mine.includes(wanted) ? wanted : undefined;
235
243
  }
236
244
  }
237
245
 
package/server/door.mjs CHANGED
@@ -60,7 +60,7 @@ async function readJson(request) {
60
60
  }
61
61
 
62
62
  /* The conversation the pairing asking speaks for, or undefined: the one it
63
- names if it was given it, otherwise the first it was given. */
63
+ names, only if it was given it; naming none, the first it was given. */
64
64
  export function deviceConversation(devices, headers, pairing, wanted) {
65
65
  if (!isPairingId(pairing)) return undefined;
66
66
  return devices.conversationOf(readCookie(headers.cookie, cookieNameOf(pairing)), pairing, wanted);
@@ -70,6 +70,8 @@ export function deviceConversation(devices, headers, pairing, wanted) {
70
70
  A pairing given its chat alone gets no terminal channel at all -- no
71
71
  keys, no shortcuts, no dictation typed into it. */
72
72
  export function deviceTerminal(devices, headers, pairing, wanted) {
73
+ /* A terminal is always asked for by the name of its conversation: nothing is guessed. */
74
+ if (typeof wanted !== 'string' || wanted === '') return undefined;
73
75
  const name = deviceConversation(devices, headers, pairing, wanted);
74
76
  return name !== undefined && devices.rightsOn(pairing, name).includes('x') ? name : undefined;
75
77
  }
package/server/main.mjs CHANGED
@@ -226,6 +226,10 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
226
226
  and serves its pages even when the host program or the VM manager does not answer;
227
227
  a machine that starts waits for it (all.prepare). */
228
228
  const hostSteps = (async () => {
229
+ /* A view left broken (its program gone: killed, crashed) is taken off first, or none can
230
+ be made there again before a reboot: see clavarium-host, "mounts repair". */
231
+ const repaired = await asHost(['mounts', 'repair'], { timeoutMs: 60_000 });
232
+ if (repaired.code || repaired.stderr.trim()) console.error(`mounts: ${repaired.stderr.trim() || `exit ${repaired.code}`}`);
229
233
  /* Before anything can start a VM: see resources.mjs. */
230
234
  await folders.ensureViews().catch((error) => console.error(`views: ${error.message}`));
231
235
  /* Not in place is said, not fatal: no machine is then given /tools. */
@@ -406,6 +410,10 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
406
410
  deviceName: (headers, pairing, wanted) => deviceTerminal(devices, headers, pairing, wanted),
407
411
  });
408
412
  all.drop = (name) => bridge.drop(name);
413
+ /* What a device was given changes: a terminal it holds and lost goes at once. */
414
+ devices.changed = () => bridge.recheck();
415
+ /* And a session that ends by itself (its hours are up): seen within a minute. */
416
+ const rechecking = setInterval(() => bridge.recheck(), 60_000); rechecking.unref?.();
409
417
  /* A TERMINAL THAT DOES NOT COME, though its machine runs (asked by the
410
418
  page once it has waited): repaired (conversations.mjs), then opened
411
419
  again before the page comes back for it. */
package/web/app.js CHANGED
@@ -25,8 +25,9 @@
25
25
  let deviceShared = [];
26
26
  /* The parts of its conversation this device was given: its terminal, its
27
27
  chat ('write', 'read' or null). Only those are shown -- and the server
28
- refuses the others whatever this page does. */
29
- let deviceParts = { terminal: true, chat: null };
28
+ refuses the others whatever this page does. Nothing until the server said (/me): a
29
+ terminal button shown before that was a terminal the device had not been given. */
30
+ let deviceParts = { terminal: false, chat: null };
30
31
  /* What Parley mounted for the chat screen, and for which conversation. */
31
32
  let thread = null;
32
33
  let threadOf = '';