clavarium 0.2.20-next.1 → 0.2.20-next.3

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/README.md CHANGED
@@ -70,10 +70,12 @@ Built slice by slice; the plan is in `blueprint/architecture.html`, tab
70
70
  Settings; the message is encrypted for that device alone.
71
71
 
72
72
  - **11 - the simple screen**: each conversation can be shown without its
73
- terminal, for whoever does not read one: a box to say what is wanted,
74
- what is ready to read, and what the tool says now as plain text, read by
75
- the page from its own screen. What is written is typed into the same
76
- terminal; the server reads nothing more.
73
+ terminal, for whoever does not read one: its chat (12). While its chat is
74
+ off, its Chat tab says so, with the one button that turns it on and asks
75
+ its tool to use it. A device given its terminal but not its chat keeps
76
+ the plain screen: a box to say what is wanted, what is ready to read, and
77
+ what the tool says now as plain text, read by the page from its own
78
+ screen; what is written is typed into the same terminal.
77
79
 
78
80
  - **12 - talk through the app**: a branching on Clavarium Parley, a project
79
81
  of its own (an npm dependency at an exact version, `clavarium-parley`). Every machine has a
@@ -113,6 +113,17 @@ WIFI_STEP="3"
113
113
  # Where NetworkManager keeps its connections as files (keyfiles): a new network is written
114
114
  # there by this program, root's and 0600 -- the one place its password is ever written.
115
115
  NM_KEYFILES="/etc/NetworkManager/system-connections"
116
+ # THE NETWORK HANDED OVER TO NETWORKMANAGER (verbs "wifi handover", "wifi hand"): a server set up
117
+ # by the Ubuntu installer has its network in netplan, rendered by systemd-networkd, and no
118
+ # NetworkManager: its Wi-Fi cannot be chosen from Clavarium, and a cable plugged in later is not
119
+ # taken. NetworkManager is installed, one file of netplan's makes it the renderer, and if the
120
+ # networks in use before are not working again within $HAND_WAIT seconds, netplan's files are put
121
+ # back as they were. Its record; netplan's folder; the file added; the unit it runs in.
122
+ HAND_STATE="/var/lib/clavarium/network"
123
+ NETPLAN_DIR="/etc/netplan"
124
+ HAND_FILE="90-clavarium-network.yaml"
125
+ HAND_UNIT="clavarium-network-handover"
126
+ HAND_WAIT="90"
116
127
 
117
128
  refuse() { echo "REFUSED: $*" >&2; exit 78; }
118
129
  usage() { echo "usage: clavarium-host [--say-only [--data DIR] [--mnt DIR]] <vm|shelf|folder|work|view|tools|mounts|operator|machines|disks|net|git|server|update|wifi> <verb> [arguments]" >&2; exit 64; }
@@ -125,7 +136,8 @@ while [ $# -gt 0 ]; do
125
136
  --mnt) [ "$SAY" = "yes" ] || refuse "--mnt is only for --say-only"; MNT="${2:-}"; shift 2 ;;
126
137
  --test) [ "$(id -u)" != "0" ] || refuse "--test is never for root"; [ "$SAY" = "no" ] || refuse "--test runs for real: not with --say-only"
127
138
  TEST="${2:-}"; case "$TEST" in /*) : ;; *) refuse "--test takes an absolute path" ;; esac
128
- DATA="$TEST"; MNT="$TEST"; WIFI_STATE="$TEST/wifi"; NM_KEYFILES="$TEST/system-connections"; WIFI_WAIT="3"; WIFI_UP_WAIT="3"; WIFI_STEP="0.2"; shift 2 ;;
139
+ DATA="$TEST"; MNT="$TEST"; WIFI_STATE="$TEST/wifi"; NM_KEYFILES="$TEST/system-connections"; WIFI_WAIT="3"; WIFI_UP_WAIT="3"; WIFI_STEP="0.2"
140
+ HAND_STATE="$TEST/network"; NETPLAN_DIR="$TEST/netplan"; HAND_WAIT="3"; shift 2 ;;
129
141
  *) break ;;
130
142
  esac
131
143
  done
@@ -458,6 +470,45 @@ wifi_keyfile() {
458
470
  [ -n "$TEST" ] || chown root:root -- "$tmp"
459
471
  mv -f -- "$tmp" "$file"
460
472
  }
473
+ # THE HANDOVER. Possible where netplan renders the network with systemd-networkd (its default)
474
+ # and this program has not handed it over already; apt-get to install NetworkManager.
475
+ hand_possible() {
476
+ local r
477
+ type -P netplan >/dev/null 2>&1 && type -P apt-get >/dev/null 2>&1 || return 1
478
+ [ ! -e "$NETPLAN_DIR/$HAND_FILE" ] || return 1
479
+ compgen -G "$NETPLAN_DIR/*.yaml" >/dev/null || return 1
480
+ r="$(netplan get renderer 2>/dev/null | head -1 || true)"
481
+ case "$r" in ""|null|networkd) return 0 ;; *) return 1 ;; esac
482
+ }
483
+ # Its record: "hand <state> <seconds since 1970>" and "handwhy <why>".
484
+ hand_record() {
485
+ install -d -m 0700 "$HAND_STATE"
486
+ { printf 'hand %s %s\n' "$1" "$(date +%s)"; [ -z "${2:-}" ] || printf 'handwhy %s\n' "$2"; } > "$HAND_STATE/last.new"
487
+ mv -f -- "$HAND_STATE/last.new" "$HAND_STATE/last"
488
+ }
489
+ hand_word() { sed -n 's/^hand \([a-z-]*\) [0-9]*$/\1/p' "$HAND_STATE/last" 2>/dev/null | head -1 || true; }
490
+ # Going on: recorded as such, and not for longer than an install and a wait could take.
491
+ hand_busy() {
492
+ local at
493
+ case "$(hand_word)" in installing|switching) : ;; *) return 1 ;; esac
494
+ at="$(sed -n 's/^hand [a-z]* \([0-9]*\)$/\1/p' "$HAND_STATE/last" | head -1)"
495
+ [ $(( $(date +%s) - ${at:-0} )) -lt 1800 ]
496
+ }
497
+ # The networks in use: "<device> <gateway>", one per default route.
498
+ hand_routes() { ip -4 route show default 2>/dev/null | sed -n 's/^default via \([0-9.]*\) dev \([A-Za-z0-9._-]*\).*$/\2 \1/p' | sort -u || true; }
499
+ # Each of them working again, through NetworkManager: connected, with its way out (a default
500
+ # route through it). Not its gateway answering a ping: many a box does not answer one.
501
+ hand_back_up() {
502
+ local dev gw st
503
+ while read -r dev gw; do
504
+ [ -n "$dev" ] || continue
505
+ st="$(nmcli -g GENERAL.STATE device show "$dev" 2>/dev/null | head -1 || true)"
506
+ case "$st" in 100*) : ;; *) return 1 ;; esac
507
+ [ -n "$(ip -4 route show default dev "$dev" 2>/dev/null || true)" ] || return 1
508
+ done < "$HAND_STATE/routes"
509
+ [ "$(nmcli -t -f RUNNING general 2>/dev/null || true)" = "running" ]
510
+ }
511
+
461
512
  # The outcome of a switch, recorded for "wifi status": <state> [<why>]. Uses $ssid and $back.
462
513
  wifi_record() {
463
514
  install -d -m 0700 "$WIFI_STATE"
@@ -1170,6 +1221,14 @@ case "$AREA $VERB" in
1170
1221
  [[ "$line" =~ ^(last\ (joining|joined|went-back|back-failed|interrupted)\ [0-9]{1,12}|lastwhy\ [a-z-]{1,20}|last(ssid|back)\ .{0,32})$ ]] && printf '%s\n' "$line"
1171
1222
  done < "$WIFI_STATE/last"
1172
1223
  fi
1224
+ # The handover: how the last one went; whether it can be asked.
1225
+ if [ -f "$HAND_STATE/last" ]; then
1226
+ while IFS= read -r line; do
1227
+ if ! hand_busy && [[ "$line" =~ ^hand\ (installing|switching)\ ([0-9]{1,12})$ ]]; then line="hand interrupted ${BASH_REMATCH[2]}"; fi
1228
+ [[ "$line" =~ ^(hand\ (installing|switching|handed|went-back|failed|interrupted)\ [0-9]{1,12}|handwhy\ [a-z-]{1,20})$ ]] && printf '%s\n' "$line"
1229
+ done < "$HAND_STATE/last"
1230
+ fi
1231
+ hand_busy || ! hand_possible || echo "handover possible"
1173
1232
  type -P nmcli >/dev/null 2>&1 || { printf '%s\n' "nmcli no" "wifiwhy no-nmcli"; exit 0; }
1174
1233
  echo "nmcli yes"
1175
1234
  [ "$(nmcli -t -f RUNNING general 2>/dev/null || true)" = "running" ] || { echo "wifiwhy not-running"; exit 0; }
@@ -1317,6 +1376,85 @@ case "$AREA $VERB" in
1317
1376
  done
1318
1377
  go_back no-internet
1319
1378
  exit 0 ;;
1379
+ "wifi handover")
1380
+ # THE NETWORK TO NETWORKMANAGER, asked from Settings: started in a unit of its own ("wifi
1381
+ # hand"), and this returns at once: "handing". Refused where it is not possible.
1382
+ [ $# -eq 0 ] || usage
1383
+ if [ "$SAY" = "yes" ]; then
1384
+ printf '%s\n' "systemd-run --unit=$HAND_UNIT --collect clavarium-host wifi hand:" \
1385
+ " apt-get install network-manager (when it is not installed)" \
1386
+ " copy $NETPLAN_DIR aside; write $NETPLAN_DIR/$HAND_FILE (root, 0600: renderer NetworkManager); netplan apply" \
1387
+ " ${HAND_WAIT} s at most for the networks in use before to work again: then systemctl disable systemd-networkd-wait-online;" \
1388
+ " else netplan's files put back, netplan apply"
1389
+ exit 0
1390
+ fi
1391
+ ! hand_busy || refuse "the network is being handed over already: wait for its end (a few minutes)"
1392
+ ! wifi_busy || refuse "a Wi-Fi switch is going on: wait for its end"
1393
+ hand_possible || refuse "this server's network is not one netplan renders with systemd-networkd: nothing to hand over"
1394
+ hand_record installing
1395
+ self=(/bin/bash "$(readlink -f -- "$0")"); [ -z "$TEST" ] || self+=(--test "$TEST")
1396
+ if ! systemd-run --quiet --unit="$HAND_UNIT" --collect --description="Clavarium - the network handed over to NetworkManager, back as it was if it does not work" \
1397
+ --property=TimeoutStopSec=180 "${self[@]}" wifi hand; then
1398
+ hand_record failed stopped
1399
+ refuse "the handover could not be started (another one still running?)"
1400
+ fi
1401
+ echo "handing"
1402
+ exit 0 ;;
1403
+ "wifi hand")
1404
+ # THE HANDOVER ITSELF, run by "wifi handover" in its unit, as root. NetworkManager
1405
+ # installed if it is not (nothing else changed yet: a failure there leaves all as it was);
1406
+ # netplan's folder copied aside, root's; one file of netplan's makes NetworkManager the
1407
+ # renderer (the Wi-Fi it knew comes with it, and a cable is taken when plugged in); then
1408
+ # up to $HAND_WAIT seconds for the networks in use before to work again. If they do not,
1409
+ # netplan's files are put back as they were and applied. The outcome is recorded for "wifi status".
1410
+ [ $# -eq 0 ] || usage
1411
+ if [ "$SAY" = "yes" ]; then echo "see: wifi handover"; exit 0; fi
1412
+ [ "$(hand_word)" = "installing" ] || refuse "no handover was asked"
1413
+ install -d -m 0700 "$HAND_STATE"
1414
+ hand_routes > "$HAND_STATE/routes"
1415
+ if ! type -P nmcli >/dev/null 2>&1; then
1416
+ if ! DEBIAN_FRONTEND=noninteractive apt-get install -y -q network-manager > "$HAND_STATE/install.log" 2>&1; then hand_record failed install; exit 0; fi
1417
+ fi
1418
+ hand_record switching
1419
+ aside="$HAND_STATE/netplan-before"
1420
+ rm -rf -- "$aside"; install -d -m 0700 "$aside"
1421
+ cp -a -- "$NETPLAN_DIR/." "$aside/" || { hand_record failed copy; exit 0; }
1422
+ # Back as it was: netplan's files exactly as copied (theirs only), applied.
1423
+ put_back() {
1424
+ rm -f -- "$NETPLAN_DIR/$HAND_FILE"
1425
+ find "$NETPLAN_DIR" -mindepth 1 -maxdepth 1 -name '*.yaml' -exec rm -f -- {} + 2>/dev/null || true
1426
+ cp -a -- "$aside/." "$NETPLAN_DIR/"
1427
+ netplan apply >/dev/null 2>&1 || true
1428
+ hand_record went-back "$1"
1429
+ }
1430
+ trap 'put_back stopped; exit 0' TERM INT HUP
1431
+ tmp="$(mktemp -p "$NETPLAN_DIR" .clavarium-network.XXXXXX)" || { hand_record failed write; exit 0; }
1432
+ chmod 0600 -- "$tmp"
1433
+ printf '# Written by Clavarium (Settings, Network): NetworkManager drives the network.\nnetwork:\n version: 2\n renderer: NetworkManager\n' > "$tmp"
1434
+ [ -n "$TEST" ] || chown root:root -- "$tmp"
1435
+ mv -f -- "$tmp" "$NETPLAN_DIR/$HAND_FILE"
1436
+ if ! netplan generate >/dev/null 2>&1; then rm -f -- "$NETPLAN_DIR/$HAND_FILE"; trap - TERM INT HUP; hand_record failed invalid; exit 0; fi
1437
+ netplan apply >/dev/null 2>&1 || true
1438
+ start="$SECONDS"
1439
+ looks=$(awk -v w="$HAND_WAIT" -v s="$WIFI_STEP" 'BEGIN { print int(w / s) }')
1440
+ for ((i = 0; i < looks && SECONDS - start < HAND_WAIT; i++)); do
1441
+ if hand_back_up; then
1442
+ trap - TERM INT HUP
1443
+ # Its copy held the Wi-Fi password: not kept once it is no longer needed.
1444
+ rm -rf -- "$aside"
1445
+ # systemd-networkd drives nothing now: its wait for a network would hold each start
1446
+ # two minutes, then fail. NetworkManager's own wait takes its place.
1447
+ if [ "$(systemctl is-enabled systemd-networkd-wait-online.service 2>/dev/null || true)" = "enabled" ]; then
1448
+ systemctl disable systemd-networkd-wait-online.service >/dev/null 2>&1 && echo "networkd-wait-online disabled" > "$HAND_STATE/undone"
1449
+ fi
1450
+ hand_record handed
1451
+ exit 0
1452
+ fi
1453
+ sleep "$WIFI_STEP"
1454
+ done
1455
+ trap - TERM INT HUP
1456
+ put_back no-network
1457
+ exit 0 ;;
1320
1458
  "wifi forget")
1321
1459
  # <ssid>: every network NetworkManager keeps under that name, deleted. Never the one
1322
1460
  # in use (the server would lose its network), never during a switch.
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.20-next.1",
3
+ "version": "0.2.20-next.3",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.20-next.1",
9
+ "version": "0.2.20-next.3",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
13
13
  "@xterm/xterm": "^6.0.0",
14
- "clavarium-parley": "0.13.0",
14
+ "clavarium-parley": "0.13.1-next.2",
15
15
  "mermaid": "11.17.2",
16
16
  "node-pty": "^1.1.0",
17
17
  "pdfjs-dist": "6.4.299",
@@ -686,9 +686,9 @@
686
686
  }
687
687
  },
688
688
  "node_modules/clavarium-parley": {
689
- "version": "0.13.0",
690
- "resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.13.0.tgz",
691
- "integrity": "sha512-ZBoPVCucWaaY59bodXznl29Fh7Ig2cTiMIyftUnLYq5F+tqulHzXdTaY53/5s45VBz+ylT6XbbdG55eVjBSbDA==",
689
+ "version": "0.13.1-next.2",
690
+ "resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.13.1-next.2.tgz",
691
+ "integrity": "sha512-xy+6BzlSg1aHPbVvW4WXRd5HLFb75tMyUwVXXgspow+QdlJ6Sk1K3nx2u2M8tncbNC+gh2+Pv0wiMbgcghY7Vg==",
692
692
  "license": "MIT",
693
693
  "bin": {
694
694
  "parley": "bin/parley.mjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.20-next.1",
3
+ "version": "0.2.20-next.3",
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-parley": "0.13.0",
47
+ "clavarium-parley": "0.13.1-next.2",
48
48
  "mermaid": "11.17.2",
49
49
  "node-pty": "^1.1.0",
50
50
  "pdfjs-dist": "6.4.299",
package/server/api.mjs CHANGED
@@ -77,6 +77,7 @@
77
77
  * GET /api/wifi: this server's Wi-Fi GET /api/wifi/scan: the networks it sees (looked for again)
78
78
  * POST /api/wifi/join {ssid, password}: the switch started, back by itself if it does not work
79
79
  * POST /api/wifi/forget {ssid}: a kept network deleted (never the one in use)
80
+ * POST /api/wifi/handover: the network handed over to NetworkManager (back as it was if it does not work)
80
81
  * GET /api/events?kind=&conversation=&q=&before=&limit= what happened, newest first
81
82
  * GET /api/history?of=server|<name>&span=1h|24h|7d the curves of memory, CPU and disk (and the reserve, for the server)
82
83
  * GET /api/server/logs?source=&span= what the server's programs said POST /api/server/restart
@@ -400,6 +401,7 @@ export async function handleApi(request, response, conversations, headers, resou
400
401
  /* The password goes on to the host program and nowhere else: not in an answer, not in What happened. */
401
402
  if (pathname === '/api/wifi/join' && wifi) return send(202, await wifi.join(body.ssid, body.password ?? '')), true;
402
403
  if (pathname === '/api/wifi/forget' && wifi) return send(200, await wifi.forget(body.ssid)), true;
404
+ if (pathname === '/api/wifi/handover' && wifi) return send(202, await wifi.handover()), true;
403
405
  if (pathname === '/api/operators' && team) return send(201, await team.add(body.email)), true;
404
406
  const op = /^\/api\/operators\/([^/]{3,200})\/(password|disable|enable|remove)$/.exec(pathname);
405
407
  if (op && team) {
package/server/events.mjs CHANGED
@@ -57,6 +57,7 @@ const SAID = [
57
57
  [/^\/api\/machines\/forget-old$/, 'server', () => 'The old copy of the machines removed'],
58
58
  /* Its name only: the password of a network is never said. */
59
59
  [/^\/api\/wifi\/join$/, 'server', (m, b) => `Wi-Fi: joining "${clip(b.ssid, 40)}" asked`],
60
+ [/^\/api\/wifi\/handover$/, 'server', () => 'Network: management by Clavarium asked'],
60
61
  [/^\/api\/wifi\/forget$/, 'server', (m, b) => `Wi-Fi: "${clip(b.ssid, 40)}" forgotten`],
61
62
  [/^\/api\/instance$/, 'server', (m, b) => (String(b.name ?? '').trim() ? `This Clavarium named "${clip(b.name, 40)}"` : 'This Clavarium given back the name drawn from its address')],
62
63
  [/^\/api\/operators$/, 'sign-in', (m, b) => `Administrator ${clip(b.email, 80)} added`],
package/server/wifi.mjs CHANGED
@@ -18,6 +18,15 @@
18
18
  * join(ssid, password) the switch started: { started, ssid, back } (back: the network it
19
19
  * goes back to, or null); the password goes to the host on standard input only
20
20
  * forget(ssid) a kept network deleted (never the one in use)
21
+ *
22
+ * THE NETWORK HANDED OVER TO NETWORKMANAGER: a server set up by the Ubuntu installer has
23
+ * its network in netplan with systemd-networkd and no NetworkManager -- its Wi-Fi is not
24
+ * chosen from here, a cable plugged in later is not taken. `status()` says when it can be
25
+ * handed over (`handover: true`) and how the last one went (`hand: {state, at, why}`):
26
+ * handover() started in a unit of the host's own: NetworkManager installed, netplan
27
+ * made to render through it; back as it was if the networks in use before do
28
+ * not work again within a minute and a half. { started: true }
29
+ * hand.state: installing, switching, handed, went-back, failed, interrupted
21
30
  */
22
31
  import { Refusal } from './conversations.mjs';
23
32
 
@@ -38,13 +47,16 @@ export function passwordWhy(password) {
38
47
  return '';
39
48
  }
40
49
  const STATES = ['joining', 'joined', 'went-back', 'back-failed', 'interrupted'];
50
+ const HAND_STATES = ['installing', 'switching', 'handed', 'went-back', 'failed', 'interrupted'];
51
+ /* A handover is looked at this long: an install, then a minute and a half. */
52
+ const HAND_WATCH_FOR_MS = 20 * 60_000;
41
53
  /* After a join, the outcome is looked for this often and this long, to be said in What happened. */
42
54
  const WATCH_EVERY_MS = 5000;
43
55
  const WATCH_FOR_MS = 6 * 60_000;
44
56
 
45
57
  /* "wifi status", line by line: only the lines of the expected shapes. */
46
58
  export function readStatus(text) {
47
- const out = { available: false, why: null, device: null, using: null, saved: [], last: null };
59
+ const out = { available: false, why: null, device: null, using: null, saved: [], last: null, handover: false, hand: null };
48
60
  let nmcli = false;
49
61
  for (const line of String(text ?? '').split('\n').slice(0, 300)) {
50
62
  const word = line.split(' ', 1)[0]; const rest = line.slice(word.length + 1);
@@ -54,11 +66,15 @@ export function readStatus(text) {
54
66
  else if (word === 'using') { const m = /^(\d{1,3}) (.+)$/.exec(rest); if (m) out.using = { signal: Math.min(100, Number(m[1])), ssid: m[2] }; }
55
67
  else if (word === 'saved' && rest) out.saved.push(rest);
56
68
  else if (word === 'last') { const m = /^([a-z-]+) (\d{1,12})$/.exec(rest); if (m && STATES.includes(m[1])) out.last = { ...(out.last ?? {}), state: m[1], at: new Date(Number(m[2]) * 1000).toISOString() }; }
69
+ else if (word === 'handover') out.handover = rest === 'possible';
70
+ else if (word === 'hand') { const m = /^([a-z-]+) (\d{1,12})$/.exec(rest); if (m && HAND_STATES.includes(m[1])) out.hand = { ...(out.hand ?? {}), state: m[1], at: new Date(Number(m[2]) * 1000).toISOString() }; }
71
+ else if (word === 'handwhy' && /^[a-z-]{1,20}$/.test(rest)) out.hand = { ...(out.hand ?? {}), why: rest };
57
72
  else if (['lastssid', 'lastback', 'lastwhy'].includes(word) && line.startsWith(`${word} `)) out.last = { ...(out.last ?? {}), [word.slice(4)]: rest || null };
58
73
  }
59
74
  out.available = nmcli && !out.why && Boolean(out.device);
60
75
  if (!nmcli && !out.why) out.why = 'unreadable';
61
76
  if (out.last && !out.last.state) out.last = null;
77
+ if (out.hand && !out.hand.state) out.hand = null;
62
78
  return out;
63
79
  }
64
80
  /* "wifi scan": network <signal> <security> <now|other> <ssid>. */
@@ -72,7 +88,7 @@ export function readScan(text) {
72
88
  }
73
89
 
74
90
  export class Wifi {
75
- #host; #said; #watching = null; #everyMs; #forMs;
91
+ #host; #said; #watching = null; #handing = null; #everyMs; #forMs;
76
92
  /* `said(text)`: an outcome, in What happened (events.mjs). */
77
93
  constructor({ host, said = () => {}, watchEveryMs = WATCH_EVERY_MS, watchForMs = WATCH_FOR_MS }) {
78
94
  this.#host = host; this.#said = said; this.#everyMs = watchEveryMs; this.#forMs = watchForMs;
@@ -98,6 +114,29 @@ export class Wifi {
98
114
  this.#watch(ssid);
99
115
  return { started: true, ssid, back };
100
116
  }
117
+ async handover() {
118
+ const r = await this.#host(['wifi', 'handover'], { timeoutMs: 30_000 });
119
+ if (r.code !== 0) throw new Refusal(r.code === 78 ? 409 : 502, firstLine(r.stderr) || `exit ${r.code}`);
120
+ this.#watchHand();
121
+ return { started: true };
122
+ }
123
+ /* Its outcome, said once in What happened, as a switch's is. */
124
+ #watchHand() {
125
+ clearTimeout(this.#handing);
126
+ const until = Date.now() + HAND_WATCH_FOR_MS;
127
+ const look = async () => {
128
+ const h = (await this.status().catch(() => null))?.hand;
129
+ if (h && !['installing', 'switching'].includes(h.state)) {
130
+ this.#handing = null;
131
+ const why = { install: 'could not install NetworkManager', invalid: 'netplan refused', 'no-network': 'no network', stopped: 'stopped', copy: 'could not copy', write: 'could not write' }[h.why] ?? h.why ?? 'no reason given';
132
+ const words = { handed: 'Network: now managed by Clavarium', 'went-back': `Network: did not work (${why}), back as before`, failed: `Network: did not work (${why}), nothing changed`, interrupted: 'Network: interrupted' };
133
+ try { this.#said(words[h.state] ?? `Network: ${h.state}`); } catch { /* never in the way */ }
134
+ return;
135
+ }
136
+ if (Date.now() < until) { this.#handing = setTimeout(look, this.#everyMs); this.#handing.unref?.(); }
137
+ };
138
+ this.#handing = setTimeout(look, this.#everyMs); this.#handing.unref?.();
139
+ }
101
140
  async forget(ssid) {
102
141
  if (!nameOk(ssid)) throw new Refusal(400, 'Not a network name.');
103
142
  const r = await this.#host(['wifi', 'forget', ssid], { timeoutMs: 30_000 });
package/web/app.js CHANGED
@@ -2262,15 +2262,23 @@
2262
2262
  const wanted = talk.on && talkOf === current;
2263
2263
  box.hidden = !wanted;
2264
2264
  /* Where the tool talks through the app, the chat is the whole screen: one box to write in. */
2265
- $('simple-plain').hidden = wanted;
2265
+ /* Its chat off, on this server's own page: said, with the button that turns it on (a device's page keeps the plain screen). */
2266
+ const offer = !DEVICE && !wanted && !noTerminal();
2267
+ $('simple-plain').hidden = wanted || offer;
2268
+ $('chat-turn').hidden = !offer;
2269
+ if (offer) {
2270
+ const possible = !(talkOf === current && talk.possible === false);
2271
+ $('chat-turn-on').hidden = !possible;
2272
+ $('chat-turn-why').textContent = possible ? 'Turned on, its tool talks with you here, as in a messaging app. Its terminal stays one click away.' : 'This conversation works on the disk of its machine: its chat needs its work folder kept here.';
2273
+ }
2266
2274
  $('simple').toggleAttribute('data-chat', wanted);
2267
2275
  /* The ready-made answers type into the terminal: not under a chat. */
2268
- $('room').toggleAttribute('data-chat', wanted && simple);
2276
+ $('room').toggleAttribute('data-chat', (wanted || offer) && simple);
2269
2277
  /* Its chat alone was given, and the owner has not turned it on: said, not left blank. */
2270
2278
  $('chat-off').hidden = !(noTerminal() && !wanted);
2271
2279
  if (noTerminal()) { $('room').setAttribute('data-chat', ''); keysForChat(); say(wanted ? 'chat' : 'chat off', wanted ? 'live' : 'waiting'); }
2272
2280
  /* The bar's dictation types into the terminal: not while the chat is in front, which has its own. */
2273
- if (wanted && simple && stopListening) stopVoice();
2281
+ if ((wanted || offer) && simple && stopListening) stopVoice();
2274
2282
  paintSimple();
2275
2283
  if (!wanted) { thread?.destroy(); thread = null; threadOf = ''; return; }
2276
2284
  if (thread && threadOf === current) { void thread.refresh(); return; }
@@ -2491,6 +2499,23 @@
2491
2499
  catch (error) { $('panel-error').textContent = error.message; $('panel-error').hidden = false; }
2492
2500
  });
2493
2501
  }
2502
+ /* From the Chat tab: on, then its tool is asked to use it -- the same two steps as in its settings. */
2503
+ $('chat-turn-on').addEventListener('click', async () => {
2504
+ const name = current; const button = $('chat-turn-on');
2505
+ if (button.dataset.open) { delete button.dataset.open; button.textContent = 'Turn the chat on'; $('chat-turn-said').textContent = ''; await readTalk(); await paintThread(); return; }
2506
+ button.disabled = true; $('chat-turn-said').textContent = '';
2507
+ try { await post(`${API}/conversations/${encodeURIComponent(name)}/talk`, { on: true }); }
2508
+ catch (error) { $('chat-turn-said').textContent = error.message; button.disabled = false; return; }
2509
+ let asked = '';
2510
+ try { await post(`${API}/conversations/${encodeURIComponent(name)}/talk/invite`, { lang: deviceLang() }); }
2511
+ catch (error) { asked = error.message; }
2512
+ button.disabled = false;
2513
+ if (name !== current) return;
2514
+ void paintGuide(conversations.find((x) => x.name === name));
2515
+ /* Its tool could not be asked: the chat is on all the same; said here, the chat one click away. */
2516
+ if (asked) { $('chat-turn-said').textContent = `The chat is on, but its tool could not be asked to use it: ${asked}`; button.textContent = 'Open the chat'; button.dataset.open = 'yes'; return; }
2517
+ await readTalk(); await paintThread();
2518
+ });
2494
2519
  $('talk-invite').addEventListener('click', async () => {
2495
2520
  try { await post(`${API}/conversations/${encodeURIComponent(current)}/talk/invite`, { lang: deviceLang() }); $('talk-invite').textContent = 'Asked'; setTimeout(() => { $('talk-invite').textContent = 'Ask the tool to use it'; }, 2500); }
2496
2521
  catch (error) { $('panel-error').textContent = error.message; $('panel-error').hidden = false; }
@@ -4183,6 +4208,35 @@
4183
4208
  const arch = document.createElementNS(ns, 'path'); arch.setAttribute('d', 'M8 11V7a4 4 0 0 1 8 0v4');
4184
4209
  svg.append(body, arch); return svg;
4185
4210
  };
4211
+ /* THE NETWORK HANDED OVER TO NETWORKMANAGER (the host program, "wifi handover"): offered where
4212
+ netplan drives it with systemd-networkd; its progress and outcome, as the host recorded them. */
4213
+ const HAND_WHY = { install: 'could not install', invalid: 'refused', 'no-network': 'no network', stopped: 'stopped', copy: 'could not copy', write: 'could not write' };
4214
+ const HAND_DAY_MS = 24 * 3600_000;
4215
+ function paintHand(s) {
4216
+ const h = s.hand; const busy = ['installing', 'switching'].includes(h?.state);
4217
+ const words = !h ? '' : {
4218
+ installing: 'Setting it up (a minute or two)...',
4219
+ switching: 'Switching (a few seconds)...',
4220
+ handed: 'Done: Clavarium manages the network.',
4221
+ 'went-back': `It did not work (${HAND_WHY[h.why] ?? h.why ?? 'no reason given'}): all is back as before.`,
4222
+ failed: `It did not work (${HAND_WHY[h.why] ?? h.why ?? 'no reason given'}): nothing changed.`,
4223
+ interrupted: 'Interrupted (the server restarted?).',
4224
+ }[h.state] ?? '';
4225
+ const old = h?.state === 'handed' && Date.now() - Date.parse(h.at) > HAND_DAY_MS;
4226
+ $('wifi-hand-said').textContent = words; $('wifi-hand-said').hidden = !words || old;
4227
+ $('wifi-hand-said').className = h && ['went-back', 'failed', 'interrupted'].includes(h.state) ? 'error' : 'hint';
4228
+ $('wifi-hand').hidden = !s.handover || busy;
4229
+ if (busy && $('settings-wifi-top').open && !$('settings').hidden) wifiTimer = setTimeout(() => { void paintWifi(); }, 3000);
4230
+ }
4231
+ const handReset = () => { const go = $('wifi-hand-go'); go.dataset.sure = ''; go.textContent = 'Manage the network'; go.disabled = false; $('wifi-hand-cancel').hidden = true; };
4232
+ $('wifi-hand-go').addEventListener('click', () => {
4233
+ const go = $('wifi-hand-go');
4234
+ /* Two clicks: the network may be cut for a few seconds. */
4235
+ if (go.dataset.sure !== 'yes') { go.dataset.sure = 'yes'; go.textContent = 'Confirm (undone by itself if it fails)'; $('wifi-hand-cancel').hidden = false; return; }
4236
+ go.disabled = true;
4237
+ void post(`${API}/wifi/handover`, {}).then(() => { handReset(); void paintWifi(); }).catch((error) => { handReset(); $('wifi-hand-said').textContent = error.message; $('wifi-hand-said').className = 'error'; $('wifi-hand-said').hidden = false; });
4238
+ });
4239
+ $('wifi-hand-cancel').addEventListener('click', handReset);
4186
4240
  async function paintWifi() {
4187
4241
  clearTimeout(wifiTimer);
4188
4242
  const s = await fetch(`${API}/wifi`, { cache: 'no-store' }).then((r) => (r.ok ? r.json() : null)).catch(() => null);
@@ -4193,8 +4247,9 @@
4193
4247
  return;
4194
4248
  }
4195
4249
  wifiNow = s;
4250
+ paintHand(s);
4196
4251
  $('wifi-controls').hidden = !s.available;
4197
- if (!s.available) { $('wifi-now').textContent = WIFI_OUTSIDE[s.why] ?? WIFI_OUTSIDE.unreadable; $('wifi-last').hidden = true; return; }
4252
+ if (!s.available) { $('wifi-now').textContent = s.handover ? 'Clavarium does not manage this server\'s network yet.' : WIFI_OUTSIDE[s.why] ?? WIFI_OUTSIDE.unreadable; $('wifi-last').hidden = true; return; }
4198
4253
  $('wifi-now').replaceChildren();
4199
4254
  if (s.using) $('wifi-now').append(el('span', '', 'On '), el('b', '', s.using.ssid), el('span', '', ` (Wi-Fi, ${s.device}) `), signalBars(s.using.signal));
4200
4255
  else $('wifi-now').textContent = `Not on a Wi-Fi network (${s.device}).`;
package/web/index.html CHANGED
@@ -97,6 +97,8 @@
97
97
  drawn by Parley, from what the tool posted, never from its screen. -->
98
98
  <div id="simple" hidden>
99
99
  <div id="simple-thread" hidden></div>
100
+ <!-- ITS CHAT TURNED OFF: said, with the one button that turns it on (and asks its tool to use it). -->
101
+ <div id="chat-turn" hidden><p><b>The chat is off for this conversation.</b></p><p id="chat-turn-why">Turned on, its tool talks with you here, as in a messaging app. Its terminal stays one click away.</p><button type="button" class="primary" id="chat-turn-on">Turn the chat on</button><p class="hint" id="chat-turn-said" role="status"></p></div>
100
102
  <div id="simple-plain">
101
103
  <p id="simple-state" role="status"></p>
102
104
  <form id="simple-say" autocomplete="off">
@@ -715,6 +717,12 @@
715
717
  <div id="wifi" tabindex="-1">
716
718
  <p id="wifi-now" role="status"></p>
717
719
  <p id="wifi-last" class="hint" role="status" hidden></p>
720
+ <!-- ITS NETWORK SET UP OUTSIDE CLAVARIUM (netplan and systemd-networkd, as the Ubuntu installer leaves it): handed over to NetworkManager, back as it was if it does not work. -->
721
+ <div id="wifi-hand" hidden>
722
+ <p id="wifi-hand-about">Let Clavarium manage it: Wi-Fi chosen here, a cable taken by itself. Your Wi-Fi stays as it is.</p>
723
+ <div class="row"><button type="button" class="primary" id="wifi-hand-go">Manage the network</button><button type="button" id="wifi-hand-cancel" hidden>Cancel</button></div>
724
+ </div>
725
+ <p id="wifi-hand-said" role="status" hidden></p>
718
726
  <div id="wifi-controls" hidden>
719
727
  <div class="row"><button type="button" id="wifi-scan">Look for networks</button><span class="hint" id="wifi-said" role="status"></span></div>
720
728
  <ul id="wifi-list" class="wifi-list" hidden></ul>
package/web/style.css CHANGED
@@ -385,6 +385,10 @@ footer button.careful { border-style: dashed; color: var(--ink2); }
385
385
  /* The chat takes the whole screen: its box stays at the bottom, the messages scroll above it. */
386
386
  /* On a light screen, brass text is too pale to read: the words in that colour are darker; the buttons keep it. */
387
387
  :root[data-theme="light"] #simple-thread { --parley-ask: #8a5d00; }
388
+ #chat-turn { margin: auto; max-width: 40ch; text-align: center; padding: 32px 8px; }
389
+ #chat-turn p { margin: 0 0 12px; font-size: 1rem; }
390
+ #chat-turn p + p { color: var(--ink2); }
391
+ #chat-turn .hint { margin-top: 10px; font-size: .875rem; }
388
392
  #chat-off { margin: auto; max-width: 36ch; text-align: center; padding: 24px 8px; }
389
393
  #chat-off p { margin: 0 0 10px; font-size: 1rem; }
390
394
  #chat-off p + p { color: var(--ink2); }
@@ -1363,6 +1367,8 @@ select.pill { appearance: auto; }
1363
1367
  @media (pointer: coarse) { #list-resize { width: 18px; margin-right: -9px; } }
1364
1368
  @media (max-width: 700px) { #list-resize { display: none; } }
1365
1369
  #app[data-list="folded"] #list-resize { display: none; }
1370
+ /* A picture open over the page (the chat's viewer, its drawing): nothing of the page under it is grabbed. */
1371
+ #app:has(.parley-zoom:not([hidden])) #list-resize { display: none; }
1366
1372
  /* "Seen" stands apart from what acts on the machine: in the colour of what is fine. */
1367
1373
  .parley-act[data-act="seen"], #health-dismiss { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 60%, transparent); }
1368
1374
  .parley-act[data-act="seen"]:hover, #health-dismiss:hover { background: color-mix(in srgb, var(--ok) 14%, transparent); }