clavarium 0.2.236-next.1 → 0.2.237-beta.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.
Files changed (104) hide show
  1. package/config/launch/claude-code.sh +40 -19
  2. package/config/launch/codex.sh +37 -0
  3. package/config/launch/json-set.mjs +5 -2
  4. package/config/launch/mcp-relay.mjs +98 -0
  5. package/config/launch/mcp-sock.sh +31 -0
  6. package/config/launch/screen-watch.mjs +173 -0
  7. package/config/launch/toml-block.mjs +26 -0
  8. package/config/launch/tools-host.mjs +93 -0
  9. package/config/launch/vibe.sh +40 -0
  10. package/config/machine/clavarium-beat +44 -0
  11. package/config/machine/clavarium-beat-one +40 -0
  12. package/config/machine/clavarium-enter +60 -0
  13. package/config/tools.json +170 -12
  14. package/deploy/clavarium-host +385 -31
  15. package/deploy/clavarium-tunnel +14 -3
  16. package/deploy/clavarium.mjs +4 -0
  17. package/deploy/git-read +57 -5
  18. package/deploy/install.sh +11 -5
  19. package/deploy/maintenance.html +5 -2
  20. package/deploy/online.mjs +251 -8
  21. package/deploy/relay.sh +53 -27
  22. package/deploy/tunnel.mjs +7 -5
  23. package/deploy/updater.mjs +168 -25
  24. package/npm-shrinkwrap.json +245 -19
  25. package/package.json +9 -6
  26. package/server/agenda.mjs +140 -0
  27. package/server/api.mjs +392 -28
  28. package/server/apikeys.mjs +1372 -0
  29. package/server/beat.mjs +189 -0
  30. package/server/binders.mjs +42 -0
  31. package/server/boxcollect.mjs +276 -0
  32. package/server/boxes.mjs +348 -29
  33. package/server/bridge.mjs +13 -4
  34. package/server/browsers.mjs +364 -0
  35. package/server/capacity.mjs +37 -10
  36. package/server/carry.mjs +143 -0
  37. package/server/catalog.mjs +48 -0
  38. package/server/contactview.mjs +122 -0
  39. package/server/conversations.mjs +1122 -46
  40. package/server/copywork.mjs +34 -0
  41. package/server/demandes.mjs +251 -0
  42. package/server/desktop.mjs +102 -0
  43. package/server/devices.mjs +1 -0
  44. package/server/dictation-engines.mjs +91 -0
  45. package/server/dockets.mjs +49 -6
  46. package/server/door.mjs +19 -5
  47. package/server/events.mjs +3 -0
  48. package/server/features.mjs +366 -0
  49. package/server/files.mjs +43 -1
  50. package/server/gitaccess.mjs +12 -3
  51. package/server/gitchecks.mjs +17 -3
  52. package/server/gitkeeper.mjs +45 -10
  53. package/server/gitpush.mjs +286 -71
  54. package/server/gitrunner.mjs +144 -10
  55. package/server/grants.mjs +47 -11
  56. package/server/guide.mjs +31 -10
  57. package/server/health.mjs +138 -12
  58. package/server/jobs.mjs +138 -0
  59. package/server/linkguard.mjs +191 -0
  60. package/server/machinelist.mjs +58 -0
  61. package/server/mailref.mjs +90 -0
  62. package/server/mailview.mjs +204 -0
  63. package/server/main.mjs +425 -47
  64. package/server/mcpoauth.mjs +338 -0
  65. package/server/mcpx.mjs +175 -0
  66. package/server/network.mjs +125 -13
  67. package/server/profile.mjs +129 -0
  68. package/server/relayjoin.mjs +67 -0
  69. package/server/resources.mjs +6 -0
  70. package/server/revive.mjs +70 -0
  71. package/server/rooms.mjs +462 -0
  72. package/server/secrets.mjs +25 -12
  73. package/server/serverlogs.mjs +30 -4
  74. package/server/settingswords.mjs +375 -0
  75. package/server/signinhelp.mjs +239 -0
  76. package/server/speech.mjs +40 -4
  77. package/server/spoken.mjs +60 -0
  78. package/server/sshconsole.mjs +99 -0
  79. package/server/sshmachine.mjs +76 -0
  80. package/server/store.mjs +15 -1
  81. package/server/suggest.mjs +66 -0
  82. package/server/talk.mjs +228 -55
  83. package/server/tethers.mjs +223 -13
  84. package/server/toolbox.mjs +30 -7
  85. package/server/tools.mjs +38 -6
  86. package/server/updates.mjs +7 -2
  87. package/server/vm.mjs +215 -46
  88. package/server/vmwatch.mjs +82 -23
  89. package/server/voice.mjs +183 -51
  90. package/server/wakelearn.mjs +214 -0
  91. package/server/wakeups.mjs +42 -2
  92. package/server/watchdog.mjs +102 -0
  93. package/web/app.js +5590 -1237
  94. package/web/desk.js +531 -0
  95. package/web/device.html +15 -2
  96. package/web/features.js +480 -0
  97. package/web/index.html +874 -490
  98. package/web/kit.js +1142 -0
  99. package/web/links.js +2 -2
  100. package/web/mail-view.js +386 -0
  101. package/web/manifest.webmanifest +4 -0
  102. package/web/style.css +1592 -268
  103. package/web/voice-core.js +48 -0
  104. package/web/voice.js +13 -5
package/deploy/relay.sh CHANGED
@@ -1,45 +1,64 @@
1
1
  #!/bin/bash
2
2
  # ---------------------------------------------------------------------------
3
- # TURNS THIS MACHINE INTO THE RELAY OF ONE CLAVARIUM. One command, parameters
4
- # only. Run it on a small machine that has a public address; the machine at
5
- # home dials out to it, so home needs no open port and no fixed address.
3
+ # TURNS THIS MACHINE INTO THE RELAY OF A CLAVARIUM -- and, later, of other
4
+ # Clavarium homes too. One command, parameters only. Run it on a small machine
5
+ # that has a public address; the machine at home dials out to it, so home
6
+ # needs no open port and no fixed address.
6
7
  #
7
- # sudo deploy/relay.sh --key "ssh-ed25519 AAAA... clavarium-tunnel"
8
+ # sudo deploy/relay.sh --key "ssh-ed25519 AAAA... clavarium-tunnel" --name clav.example.com
8
9
  #
9
10
  # --key LINE the PUBLIC tunnel key of the home machine (`sudo clavarium key`)
10
11
  # --keeper-key LINE the PUBLIC maintenance key of the home machine (optional)
12
+ # --name NAME the home's name (its domain); with it, the relay routes by
13
+ # name from the start, and other homes can be added later
11
14
  # --dry-run check the parameters, say what would be done, do nothing
12
15
  #
13
16
  # `sudo clavarium online --relay HOST` at home runs this script here by itself,
14
- # over SSH, with both keys.
17
+ # over SSH, with both keys and the name. That home is the PRINCIPAL: the only
18
+ # one that holds the maintenance key. Run again on a relay that serves homes
19
+ # already, this script sets up the principal again (its key, its name) and
20
+ # leaves the other homes as they are.
15
21
  #
16
22
  # THE RELAY IS BLIND. It carries bytes: TLS starts in the browser and ends at
17
23
  # home, so this machine never sees a page, a keystroke or a password. It holds
18
24
  # no certificate and no secret of yours.
19
25
  #
20
26
  # WHAT IT SETS UP:
21
- # - an account, "clavarium-tunnel", that can do ONE thing: hold two
22
- # listening ports (8443, 8080) forwarded to home. No shell, no terminal,
23
- # no command, no other forwarding;
24
- # - a rule that sends what arrives on 443 and 80 to those two ports;
27
+ # - an account, "clavarium-tunnel", that can do ONE thing: hold listening
28
+ # ports forwarded to home. Each home has its own key there, and each key
29
+ # may hold its own two ports only (the principal: 8443 and 8080). No
30
+ # shell, no terminal, no command, no other forwarding;
31
+ # - what takes 443 and 80: the router, which reads the name the visitor
32
+ # asks for and passes the bytes, untouched, to that home's ports (a name
33
+ # it does not know goes nowhere); or, for a relay of one home whose name
34
+ # it does not know (set up before names were given), a rule that sends
35
+ # 443 and 80 to 8443 and 8080;
25
36
  # - the maintenance program, clavarium-relay, fetched by THIS machine from
26
37
  # npm at the version written below and checked against the registry's
27
38
  # sha512; with --keeper-key, an account "clavarium-keeper" that may run
28
- # that program, and nothing else (status, repair, updates);
39
+ # that program, and nothing else (status, repair, updates, the homes);
29
40
  # - Ubuntu's security updates, by themselves (unattended-upgrades).
30
41
  #
42
+ # ANOTHER HOME is added from the principal, never from here and never with
43
+ # an account of this machine: `sudo clavarium relay invite NAME` there gives
44
+ # a one-time code, typed on the new home (`sudo clavarium online --relay
45
+ # PRINCIPAL --domain NAME --join CODE`). The principal adds the new home's
46
+ # PUBLIC tunnel key here (clavarium-relay add-home) and tells it its ports.
47
+ # A second owner is thus let in by the principal's owner, and by nobody else.
48
+ #
31
49
  # WHAT A BLIND RELAY CAN STILL DO, and how to close it: whoever controls this
32
- # machine receives port 80 for your name, so it could answer a certificate
33
- # authority's challenge itself and obtain a valid certificate for your name.
34
- # One DNS record closes that: a CAA record that names YOUR certificate
35
- # account ("accounturi="). The end of this script says it again.
50
+ # machine receives port 80 for every name it serves, so it could answer a
51
+ # certificate authority's challenge itself and obtain a valid certificate for
52
+ # such a name. One DNS record per name closes that: a CAA record that names
53
+ # THAT home's certificate account ("accounturi="). The end of this script says
54
+ # it again, and so does each home as it goes online.
36
55
  #
37
56
  # Exit codes: 0 done; 64 bad parameters; 78 this machine is refused.
38
57
  # ---------------------------------------------------------------------------
39
58
  set -euo pipefail
40
59
 
41
60
  # The version of the maintenance program this Clavarium works with.
42
- RELAY_VERSION="0.1.1"
61
+ RELAY_VERSION="0.2.0-beta.1"
43
62
  ACCOUNT="clavarium-tunnel"
44
63
  TLS_PORT="8443"
45
64
  HTTP_PORT="8080"
@@ -49,15 +68,16 @@ ROOT="${CLAVARIUM_RELAY_ROOT:-}"
49
68
  REGISTRY="https://registry.npmjs.org"
50
69
  [ -z "$ROOT" ] || REGISTRY="${CLAVARIUM_RELAY_REGISTRY:-$REGISTRY}"
51
70
 
52
- bad() { echo "relay: $*" >&2; echo "usage: relay.sh --key \"ssh-ed25519 AAAA... name\" [--keeper-key \"ssh-ed25519 AAAA... name\"] [--dry-run]" >&2; exit 64; }
71
+ bad() { echo "relay: $*" >&2; echo "usage: relay.sh --key \"ssh-ed25519 AAAA... name\" [--keeper-key \"ssh-ed25519 AAAA... name\"] [--name NAME] [--dry-run]" >&2; exit 64; }
53
72
  refuse() { echo "relay: REFUSED: $*" >&2; exit 78; }
54
73
  step() { echo "== $*"; }
55
74
 
56
- KEY=""; KEEPER_KEY=""; DRY="no"
75
+ KEY=""; KEEPER_KEY=""; NAME=""; DRY="no"
57
76
  while [ $# -gt 0 ]; do
58
77
  case "$1" in
59
78
  --key) KEY="${2:-}"; shift 2 || bad "--key needs a value" ;;
60
79
  --keeper-key) KEEPER_KEY="${2:-}"; [ -n "$KEEPER_KEY" ] || bad "--keeper-key needs a value"; shift 2 ;;
80
+ --name) NAME="${2:-}"; [ -n "$NAME" ] || bad "--name needs a value"; shift 2 ;;
61
81
  --dry-run) DRY="yes"; shift ;;
62
82
  *) bad "unknown parameter: $1" ;;
63
83
  esac
@@ -70,12 +90,13 @@ done
70
90
  [[ "$KEY" =~ ^ssh-ed25519\ [A-Za-z0-9+/]{68}(\ [A-Za-z0-9@._-]{1,64})?$ ]] || bad "--key is one line: ssh-ed25519, the key, and optionally a name"
71
91
  [ -z "$KEEPER_KEY" ] || [[ "$KEEPER_KEY" =~ ^ssh-ed25519\ [A-Za-z0-9+/]{68}(\ [A-Za-z0-9@._-]{1,64})?$ ]] || bad "--keeper-key is one line: ssh-ed25519, the key, and optionally a name"
72
92
  [ "$KEY" != "$KEEPER_KEY" ] || bad "the tunnel and the maintenance keys are two different keys"
93
+ [ -z "$NAME" ] || [[ "$NAME" =~ ^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,24}$ ]] || bad "--name is a host name, lower case, like clav.example.com"
73
94
 
74
95
  if [ "$DRY" = "yes" ]; then
75
96
  cat <<PLAN
76
97
  would make this machine a relay:
77
98
  account $ACCOUNT: may hold ports $TLS_PORT and $HTTP_PORT forwarded to home, and nothing else
78
- ports 443 -> $TLS_PORT, 80 -> $HTTP_PORT
99
+ ports 443 -> $TLS_PORT, 80 -> $HTTP_PORT, for $([ -n "$NAME" ] && echo "the name $NAME, through the router (other names: refused)" || echo "any name (no --name: one home only)")
79
100
  sees nothing: TLS ends at home
80
101
  program clavarium-relay@$RELAY_VERSION from npm, checked (sha512 of the registry)
81
102
  maintenance $([ -n "$KEEPER_KEY" ] && echo "clavarium-keeper: may run clavarium-relay, and nothing else" || echo "none (no --keeper-key)")
@@ -97,10 +118,12 @@ for k in "$KEY" "$KEEPER_KEY"; do
97
118
  ssh-keygen -l -f "$check" >/dev/null 2>&1 || { rm -f -- "$check"; refuse "this is not a key the SSH tools recognise"; }
98
119
  done
99
120
  rm -f -- "$check"
100
- for port in 443 80 "$TLS_PORT" "$HTTP_PORT"; do
101
- # (On a second run, the tunnel itself holds two of them: that is the SSH server.)
102
- if ss -ltnpH "sport = :$port" 2>/dev/null | grep -v '"sshd' | grep -q .; then refuse "something already listens on port $port here: a relay needs 443 and 80 for itself"; fi
103
- done
121
+ # On a relay already (a second run), its own router holds 443 and 80, and the tunnels hold theirs.
122
+ if [ ! -s "$ROOT/etc/clavarium-relay/homes" ] && [ ! -s "$ROOT/etc/ssh/clavarium-relay/$ACCOUNT" ]; then
123
+ for port in 443 80 "$TLS_PORT" "$HTTP_PORT"; do
124
+ if ss -ltnpH "sport = :$port" 2>/dev/null | grep -v '"sshd' | grep -q .; then refuse "something already listens on port $port here: a relay needs 443 and 80 for itself"; fi
125
+ done
126
+ fi
104
127
 
105
128
  step "the maintenance program, from npm"
106
129
  for tool in curl openssl tar; do command -v "$tool" >/dev/null 2>&1 || { export DEBIAN_FRONTEND=noninteractive; apt-get update -qq; apt-get install -y -qq curl openssl tar ca-certificates >/dev/null; break; }; done
@@ -129,8 +152,10 @@ install -m 0755 "$work/package/clavarium-relay" "$ROOT$PROGRAM"
129
152
  rm -rf -- "$work"
130
153
 
131
154
  step "accounts, rules, ports, updates"
132
- if [ -n "$KEEPER_KEY" ]; then "$ROOT$PROGRAM" setup --key "$KEY" --keeper-key "$KEEPER_KEY"
133
- else "$ROOT$PROGRAM" setup --key "$KEY"; fi
155
+ setup=(setup --key "$KEY")
156
+ [ -z "$KEEPER_KEY" ] || setup+=(--keeper-key "$KEEPER_KEY")
157
+ [ -z "$NAME" ] || setup+=(--name "$NAME")
158
+ "$ROOT$PROGRAM" "${setup[@]}"
134
159
 
135
160
  echo
136
161
  echo "This machine is a relay. It waits for the home machine to dial in."
@@ -138,7 +163,8 @@ echo "Compare with what the home machine printed (it must be the same):"
138
163
  echo " $(ssh-keygen -l -f "$ROOT/etc/ssh/ssh_host_ed25519_key.pub" | cut -d' ' -f2)"
139
164
  echo "Point your name at this machine's public address (ports 443 and 80 must reach it)."
140
165
  echo
141
- echo "TO KEEP THIS RELAY BLIND, add a CAA record to your DNS that names your certificate"
142
- echo "account (accounturi=...). Without it, whoever controls this machine could obtain a"
143
- echo "certificate for your name. The account address is at home, after the first certificate:"
166
+ echo "TO KEEP THIS RELAY BLIND, add a CAA record to your DNS FOR EACH NAME it serves, that"
167
+ echo "names that home's certificate account (accounturi=...). Without it, whoever controls"
168
+ echo "this machine could obtain a certificate for that name. The account address is at"
169
+ echo "each home, after its first certificate:"
144
170
  echo " sudo grep -rho '\"location\": *\"[^\"]*\"' /var/lib/caddy/caddy/acme"
package/deploy/tunnel.mjs CHANGED
@@ -10,7 +10,9 @@ import { fileURLToPath } from 'node:url';
10
10
  its port are read from the unit there, written as before or as now. Restarted only when it changed. */
11
11
  export const TUNNEL_UNIT = '/etc/systemd/system/clavarium-tunnel.service';
12
12
  export const TUNNEL_PROGRAM = '/usr/local/sbin/clavarium-tunnel';
13
- export function tunnelUnit(relay, port, program = TUNNEL_PROGRAM) {
13
+ /* `ports`: { tls, http } for a home the relay's principal added (its own ports on the relay); none for
14
+ the principal itself (8443 and 8080, as ever). */
15
+ export function tunnelUnit(relay, port, program = TUNNEL_PROGRAM, ports = null) {
14
16
  return `[Unit]
15
17
  Description=Clavarium - the outgoing tunnel to the relay
16
18
  After=network-online.target caddy.service
@@ -21,7 +23,7 @@ StartLimitIntervalSec=0
21
23
  User=clavarium-tunnel
22
24
  Group=clavarium-tunnel
23
25
  # Only TLS (443) and the certificate challenge (80) are carried: see ${program}.
24
- ExecStart=${program} ${relay} ${port}
26
+ ExecStart=${program} ${relay} ${port}${ports ? ` ${ports.tls} ${ports.http}` : ''}
25
27
  Restart=always
26
28
  RestartSec=5
27
29
  # What it counts of the relay's refusals, kept across its restarts.
@@ -37,8 +39,8 @@ WantedBy=multi-user.target
37
39
  `;
38
40
  }
39
41
  export function relayOfUnit(text) {
40
- const now = new RegExp(`^ExecStart=\\S+clavarium-tunnel ([A-Za-z0-9.-]{1,253}) (\\d{1,5})$`, 'm').exec(text);
41
- if (now) return { relay: now[1], port: now[2] };
42
+ const now = new RegExp(`^ExecStart=\\S+clavarium-tunnel ([A-Za-z0-9.-]{1,253}) (\\d{1,5})(?: (\\d{4,5}) (\\d{4,5}))?$`, 'm').exec(text);
43
+ if (now) return { relay: now[1], port: now[2], ...(now[3] ? { ports: { tls: now[3], http: now[4] } } : {}) };
42
44
  const before = /-p (\d{1,5}) clavarium-tunnel@([A-Za-z0-9.-]{1,253})\s*$/m.exec(text);
43
45
  return before ? { relay: before[2], port: before[1] } : null;
44
46
  }
@@ -56,7 +58,7 @@ export async function ensureTunnel({ file = TUNNEL_UNIT, program = TUNNEL_PROGRA
56
58
  if (!existsSync(program)) return false;
57
59
  const at = relayOfUnit(text);
58
60
  if (!at) return false;
59
- const wanted = tunnelUnit(at.relay, at.port, program);
61
+ const wanted = tunnelUnit(at.relay, at.port, program, at.ports ?? null);
60
62
  if (text === wanted) {
61
63
  /* The same unit, a new program: what runs now is the old one until it is started again. */
62
64
  if (installed && process.getuid?.() === 0) await run(['systemctl', 'try-restart', 'clavarium-tunnel.service'], { timeoutMs: 60_000 });
@@ -85,6 +85,15 @@ const WATCH_EVERY_MS = 3600_000;
85
85
  const WATCH_RECENT_MS = 24 * 3600_000;
86
86
  const HISTORY_MAX = 30;
87
87
  const ASK_EVERY_MS = 6 * 3600_000;
88
+ /* A VERSION THAT COULD NOT EVEN BE FETCHED (16-11: npm asked one minute after it came out, before every mirror
89
+ had it): nothing of it ran here, so it is tried again by itself, this long after, this many times at most. */
90
+ export const FETCH_AGAIN_MS = 30 * 60_000;
91
+ export const FETCH_TRIES = 3;
92
+ /* NOT RACING THE REGISTRY (17-11: 0.2.228-beta.1 asked of npm the minute it was tagged, refused; the same
93
+ install worked 20 minutes later): a version is installed by itself only once it has been out this long --
94
+ since its time in the registry (`time`), or since this updater first saw it when the registry says none.
95
+ Asked by the owner (Update, Try again): at once. */
96
+ export const RELEASE_SETTLE_MS = 10 * 60_000;
88
97
  /* Between "Switching" said in state.json and the server stopped: the pages ask the server every
89
98
  10 seconds at most (app.js), and the server says it in each answer (updates.mjs, notice): each
90
99
  gives way to the maintenance page before the server goes. */
@@ -92,6 +101,8 @@ export const NOTICE_MS = 15_000;
92
101
  const PROVENANCE = 'https://slsa.dev/provenance/v1';
93
102
  /* What the log of a failure keeps, at most (history entry `log`, shown behind "See the log"). */
94
103
  const LOG_MAX = 12_000;
104
+ /* Of npm's own debug log (in its cache, which goes with the attempt): the last lines kept in the history. */
105
+ const NPM_LOG_LINES = 40;
95
106
  /* Set beside the server's unit by the updater (root): a crash loop never locks the service out, so a
96
107
  restart asked later (an update, the watchdog) still starts it. */
97
108
  export const DROP_IN = '/etc/systemd/system/clavarium.service.d/restart.conf';
@@ -101,14 +112,33 @@ export const DROP_IN_TEXT = '# Written by the Clavarium updater: a crash loop ne
101
112
  during it, the installed app and the browser) shared one CSRF cookie, and the first to come back
102
113
  was refused ("Unable to find a valid CSRF token", found 20-10). One cookie per sign-in, and time
103
114
  to type a password. Added to a file that lacks them, the proxy restarted; nothing else touched. */
115
+ /* THE DOOR FOR PROGRAMS (server/apikeys.mjs, API keys): /api/ext/ goes through without sign-on, as the
116
+ devices' /c/ does -- the key in each call is the right, and the server never looks at an identity
117
+ there (the proxy strips those headers on these routes). Added to the one-line list of routes the
118
+ proxy skips, beside "^/c/"; a file with no such line, or a list over several lines, is left as it is. */
119
+ export const EXT_ROUTE = '^/api/ext/';
120
+ const EXT_COMMENT = '# /api/ext/: programs with an API key; the server checks the key (added by the Clavarium updater).';
121
+ export function withExtRoute(text) {
122
+ const lines = text.split('\n');
123
+ const i = lines.findIndex((l) => /^\s*skip_auth_routes\s*=/.test(l));
124
+ if (i < 0 || lines[i].includes(`"${EXT_ROUTE}"`)) return text;
125
+ const m = /^(\s*skip_auth_routes\s*=\s*\[)([^\]]*)\](\s*(#.*)?)$/.exec(lines[i]);
126
+ if (!m) return text;
127
+ const inner = m[2].trim().replace(/,\s*$/, '');
128
+ lines[i] = `${m[1]}${inner ? `${inner}, ` : ''}"${EXT_ROUTE}"]${m[3]}`;
129
+ if (lines[i - 1] !== EXT_COMMENT) lines.splice(i, 0, EXT_COMMENT);
130
+ return lines.join('\n');
131
+ }
104
132
  export const PROXY_CFG = '/etc/oauth2-proxy/oauth2-proxy.cfg';
105
133
  export const PROXY_LINES = ['cookie_csrf_per_request = true', 'cookie_csrf_expire = "30m"'];
106
134
  export async function ensureProxySettings({ file = PROXY_CFG, run = runCommand } = {}) {
107
135
  let text;
108
136
  try { text = readFileSync(file, 'utf8'); } catch { return false; }
109
137
  const missing = PROXY_LINES.filter((l) => !text.split('\n').some((x) => x.trim().startsWith(l.split(' =')[0])));
110
- if (!missing.length) return false;
111
- writeFileSync(`${file}.new`, `${text.replace(/\n*$/, '\n')}# Added by the Clavarium updater: one CSRF cookie per sign-in.\n${missing.join('\n')}\n`, { mode: 0o600 });
138
+ let next = withExtRoute(text);
139
+ if (missing.length) next = `${next.replace(/\n*$/, '\n')}# Added by the Clavarium updater: one CSRF cookie per sign-in.\n${missing.join('\n')}\n`;
140
+ if (next === text) return false;
141
+ writeFileSync(`${file}.new`, next, { mode: 0o600 });
112
142
  renameSync(`${file}.new`, file);
113
143
  if (process.getuid?.() === 0) await run(['systemctl', 'try-restart', 'oauth2-proxy.service'], { timeoutMs: 60_000 });
114
144
  return true;
@@ -122,34 +152,56 @@ export const SUDOERS = '/etc/sudoers.d/clavarium';
122
152
  /* What sudo is told, tried in this order: the first its version takes without a word wins. Some sudo builds do
123
153
  not know « syslog » (found 01-11 on a real server: « unknown setting: 'syslog' » on every call); they keep
124
154
  the session lines quiet at least. A line of ours their sudo does not take is replaced. */
125
- export const QUIET_SETTINGS = ['!syslog, !pam_session', '!pam_session'];
155
+ export const QUIET_SETTINGS = ['!syslog, !pam_session', '!pam_session', '!syslog']; /* sudo-rs (Ubuntu 25.10+) refuses pam_session: !syslog alone tried after */
126
156
  export const quietLine = (account, setting = QUIET_SETTINGS[0]) => `Defaults:${account} ${setting}`;
127
157
  const QUIET_COMMENT = '# Added by the Clavarium updater: its probes every few seconds are not written to the system log.';
128
- export async function ensureQuietSudo({ file = SUDOERS, run = runCommand } = {}) {
158
+ /* `told(outcome)`: what is in place after this turn, for Settings (sudo-quiet.json beside the state, server/updates.mjs):
159
+ { on: true, setting } or { on: false, why } -- the file missing, no account in it, visudo refusing (its words). */
160
+ export async function ensureQuietSudo({ file = SUDOERS, run = runCommand, told = () => {} } = {}) {
129
161
  let text;
130
- try { text = readFileSync(file, 'utf8'); } catch { return false; }
162
+ try { text = readFileSync(file, 'utf8'); } catch (error) { told({ on: false, why: `${file} not readable (${error.code ?? error.message})` }); return false; }
131
163
  const account = text.match(/^([a-z_][a-z0-9_-]*)\s+ALL=\(root\)\s+NOPASSWD:/m)?.[1];
132
- if (!account) return false;
164
+ if (!account) { told({ on: false, why: `no "<account> ALL=(root) NOPASSWD:" line in ${file}` }); return false; }
165
+ let refusal = '';
133
166
  const accepted = async (candidate) => {
134
167
  rmSync(`${file}.new`, { force: true });
135
168
  writeFileSync(`${file}.new`, candidate, { mode: 0o440 });
136
169
  const r = await run(['visudo', '-cf', `${file}.new`], { timeoutMs: 30_000 });
137
- return r.code === 0 && !/unknown setting|syntax error|parse error/i.test(`${r.stdout}\n${r.stderr}`);
170
+ const said = `${r.stdout ?? ''}\n${r.stderr ?? ''}`;
171
+ const ok = r.code === 0 && !/unknown setting|syntax error|parse error/i.test(said);
172
+ if (!ok) refusal = said.split('\n').map((l) => l.trim()).filter(Boolean).pop()?.slice(0, 200) || `visudo exit ${r.code}`;
173
+ return ok;
138
174
  };
139
175
  /* The rule as it is, without any line of ours. */
140
176
  const base = text.split('\n').filter((l) => l !== QUIET_COMMENT && !l.startsWith(`Defaults:${account} `)).join('\n').replace(/\n*$/, '\n');
141
- const current = QUIET_SETTINGS.map((q) => quietLine(account, q)).find((l) => text.includes(l));
177
+ const current = QUIET_SETTINGS.find((q) => text.includes(quietLine(account, q)));
142
178
  try {
143
- if (current && await accepted(text)) return false; /* ours, and taken as it is */
179
+ if (current && await accepted(text)) { told({ on: true, setting: current, account }); return false; } /* ours, and taken as it is */
180
+ const refused = [];
144
181
  for (const setting of QUIET_SETTINGS) {
145
182
  const next = `${base}${QUIET_COMMENT}\n${quietLine(account, setting)}\n`;
146
- if (await accepted(next)) { renameSync(`${file}.new`, file); return true; }
183
+ if (await accepted(next)) {
184
+ try { renameSync(`${file}.new`, file); } catch (error) { told({ on: false, why: `${file} not replaced (${error.code ?? error.message})` }); throw error; }
185
+ told({ on: true, setting, account }); return true;
186
+ }
187
+ refused.push(`${setting}: ${refusal}`);
147
188
  }
148
189
  /* None taken: the rule alone, as install.sh wrote it -- never a file sudo complains about. */
190
+ told({ on: false, why: `visudo refused ${refused.join('; ')}`.slice(0, 300) });
149
191
  if (current && await accepted(base)) { renameSync(`${file}.new`, file); return true; }
150
192
  return false;
151
193
  } finally { rmSync(`${file}.new`, { force: true }); }
152
194
  }
195
+ /* WHETHER IT WORKS, for Settings (17-11: the owner's journal still had a sudo line a second, the rule said to be
196
+ written): which sudo this is (`sudo --version`, its first line), and how many sudo lines the journal got over
197
+ the last ten minutes -- read by its own field, which the journal indexes: no long read. */
198
+ export async function sudoSeen({ run = runCommand } = {}) {
199
+ const v = await run(['sudo', '--version'], { timeoutMs: 10_000 }).catch(() => ({ code: 1, stdout: '' }));
200
+ const sudo = String(v.stdout ?? '').split('\n')[0].trim().slice(0, 80) || null;
201
+ const j = await run(['journalctl', 'SYSLOG_IDENTIFIER=sudo', '--since', '-10min', '-o', 'cat', '--no-pager', '-q'], { timeoutMs: 20_000 }).catch(() => ({ code: 1, stdout: '' }));
202
+ const lines10m = j.code === 0 ? String(j.stdout ?? '').split('\n').filter((l) => l.trim()).length : null;
203
+ return { sudo, lines10m };
204
+ }
153
205
 
154
206
  /* FFMPEG, kept by the updater: the voice boxes play a radio, a podcast, a music file through it
155
207
  (server/boxes.mjs, listen). Installed by install.sh; added once to a machine installed before. */
@@ -240,6 +292,37 @@ export async function ensureMaintenance({ caddyfile = CADDYFILE, caddy = CADDY,
240
292
  }
241
293
 
242
294
  export class Refused extends Error {}
295
+ /* NOTHING OF THE VERSION RAN: npm could not install it, or the registry did not answer about it (not there
296
+ yet, a mirror behind, the network). Said in the history as `fetch: true`, tried again by itself later.
297
+ `log`: what npm said, for "See the log". */
298
+ export class FetchFailed extends Error {
299
+ constructor(message, { log } = {}) { super(message); this.log = log; }
300
+ }
301
+
302
+ /* WHAT A LOG MUST NEVER SHOW: npm's debug log can carry the registry's credentials (an .npmrc token, an
303
+ Authorization header, a URL with a password). Each is put as ***. */
304
+ export function redact(text) {
305
+ return String(text ?? '')
306
+ .replace(/\b(proxy-authorization|authorization)(["']?\s*[:=]\s*["']?)(?:(bearer|basic|token)\s+)?[^\s"',;}]+/gi, (_, k, sep, scheme) => `${k}${sep}${scheme ? `${scheme} ` : ''}***`)
307
+ .replace(/\b(bearer|basic)\s+[A-Za-z0-9._~+/=-]{6,}/gi, '$1 ***')
308
+ .replace(/((?:_authToken|_auth|_password|authToken|token|password|passwd|secret|otp)["']?\s*[=:]\s*["']?)[^\s"',;}]+/gi, '$1***')
309
+ .replace(/\bnpm_[A-Za-z0-9]{16,}\b/g, 'npm_***')
310
+ .replace(/\bgh[opsur]_[A-Za-z0-9]{16,}\b/g, 'gh*_***')
311
+ .replace(/(\/\/)[^\s/@:]+:[^\s/@]+@/g, '$1***@');
312
+ }
313
+
314
+ /* The end of npm's own debug log, from the cache it was given: the last lines that say something (its
315
+ `silly` lines, its call stack and its pointer to itself left out), each bounded, credentials taken out. '' when there is none. */
316
+ export function npmLogTail(cache, lines = NPM_LOG_LINES) {
317
+ const dir = join(cache, '_logs');
318
+ let name;
319
+ try { name = readdirSync(dir).filter((f) => f.endsWith('.log')).sort().pop(); } catch { return ''; }
320
+ if (!name) return '';
321
+ let text = '';
322
+ try { text = readFileSync(join(dir, name), 'utf8'); } catch { return ''; }
323
+ const kept = text.split('\n').filter((l) => l.trim() && !/^\d+\s+silly\b|^\d+\s+verbose stack\s+at |A complete log of this run can be found in/.test(l)).slice(-lines).map((l) => (l.length > 500 ? `${l.slice(0, 500)}...` : l));
324
+ return redact(kept.join('\n'));
325
+ }
243
326
 
244
327
  /* SEMANTIC VERSIONS, compared as npm does: a pre-release comes before its release. */
245
328
  export function compareVersions(a, b) {
@@ -305,7 +388,19 @@ export function runCommand(argv, { cwd, env = process.env, timeoutMs = 900_000 }
305
388
  });
306
389
  }
307
390
 
308
- const lastLine = (r) => String(r.stderr || r.stdout || '').trim().split('\n').filter((l) => l.trim() && !/^npm (notice|warn)/.test(l)).pop()?.slice(0, 300) ?? `exit ${r.code}`;
391
+ /* npm's lines that say nothing of why: its notices, its warnings, its pointer to a log that is gone with
392
+ its cache, its empty error lines. */
393
+ const NPM_NOISE = /^npm (notice|warn)|A complete log of this run can be found in|^npm (error|ERR!)\s*$/;
394
+ const lastLine = (r) => redact(String(r.stderr || r.stdout || '').trim().split('\n').filter((l) => l.trim() && !NPM_NOISE.test(l)).pop()?.slice(0, 300) ?? `exit ${r.code}`);
395
+ /* Why npm failed, in one line: its error code and its first words of explanation ("code ETARGET: notarget
396
+ No matching version found for ..."), else its last line that says something. */
397
+ function npmWhy(r) {
398
+ const errors = String(r.stderr || r.stdout || '').split('\n').map((l) => /^npm (?:error|ERR!) (.+)$/.exec(l.trim())?.[1]?.trim()).filter((l) => l && !NPM_NOISE.test(`npm error ${l}`));
399
+ const code = errors.find((l) => /^code \S+$/.test(l));
400
+ const said = errors.find((l) => !/^(code|errno|syscall|path|dest|signal|command|cwd) /.test(l));
401
+ if (!code && !said) return lastLine(r);
402
+ return redact([code, said].filter(Boolean).join(': ').slice(0, 300));
403
+ }
309
404
  const stamp = (d) => d.toISOString().replace(/[-:]/g, '').replace('T', '-').slice(0, 15);
310
405
  const toHex = (integrity) => Buffer.from(String(integrity).replace(/^sha512-/, ''), 'base64').toString('hex');
311
406
 
@@ -313,8 +408,8 @@ export class Updater {
313
408
  #o; #run; #fetch;
314
409
  constructor({ code = PATHS.code, conf = PATHS.conf, stateDir = PATHS.stateDir, data = PATHS.data, hostTarget = PATHS.host, gitReadTarget = PATHS.gitRead, tunnelTarget = PATHS.tunnel, registry = REGISTRY, run = runCommand, fetcher = fetch, now = () => new Date(), log = (line) => console.log(line),
315
410
  verifySignatures, restart, health, backup, restoreData, installPrivileged, ensureNode, serviceState, answers, restarts, mainPid, pidCwd, diagnose, dropIn = DROP_IN,
316
- clock = () => Date.now(), sleep = (ms) => new Promise((r) => setTimeout(r, ms)), minFreeMb = 1024, healthMs = 60_000, watchMs = 120_000, settleMs = 10_000, noticeMs = NOTICE_MS } = {}) {
317
- this.#o = { code, conf, stateDir, data, hostTarget, gitReadTarget, tunnelTarget, registry: registry.replace(/\/$/, ''), now, log, minFreeMb, healthMs, watchMs, settleMs, noticeMs, clock, sleep, dropIn };
411
+ clock = () => Date.now(), sleep = (ms) => new Promise((r) => setTimeout(r, ms)), minFreeMb = 1024, healthMs = 60_000, watchMs = 120_000, settleMs = 10_000, noticeMs = NOTICE_MS, releaseSettleMs = RELEASE_SETTLE_MS } = {}) {
412
+ this.#o = { code, conf, stateDir, data, hostTarget, gitReadTarget, tunnelTarget, registry: registry.replace(/\/$/, ''), now, log, minFreeMb, healthMs, watchMs, settleMs, noticeMs, releaseSettleMs, clock, sleep, dropIn };
318
413
  this.#run = run; this.#fetch = fetcher;
319
414
  this.verifySignatures = verifySignatures ?? ((dir) => this.#npm(['audit', 'signatures'], { cwd: dir, timeoutMs: 300_000 }));
320
415
  this.restart = restart ?? (() => this.#restart());
@@ -380,10 +475,12 @@ export class Updater {
380
475
 
381
476
  set(key, value) { writeConf(this.#o.conf, key, value); return this.about(); }
382
477
 
478
+ /* The registry not answering, or not with what was asked: a fetch failure (FetchFailed), not the release's fault. */
383
479
  async #json(url) {
384
- const answer = await this.#fetch(url, { headers: { accept: 'application/json' }, signal: AbortSignal.timeout(60_000) });
385
- if (!answer.ok) throw new Error(`the registry answered ${answer.status} for ${url}`);
386
- return answer.json();
480
+ let answer;
481
+ try { answer = await this.#fetch(url, { headers: { accept: 'application/json' }, signal: AbortSignal.timeout(60_000) }); } catch (error) { throw new FetchFailed(`the registry could not be reached for ${url}: ${error.cause?.code ?? error.message}`); }
482
+ if (!answer.ok) throw new FetchFailed(`the registry answered ${answer.status} for ${url}`);
483
+ try { return await answer.json(); } catch (error) { throw new FetchFailed(`the registry's answer for ${url} was cut: ${error.message}`); }
387
484
  }
388
485
  #packument(name) { return this.#json(`${this.#o.registry}/${name}`); }
389
486
 
@@ -401,7 +498,11 @@ export class Updater {
401
498
  if (conf.CHANNEL === 'beta' && tags.beta && (!candidate || compareVersions(tags.beta, candidate) > 0)) candidate = tags.beta;
402
499
  if (candidate && (!VERSION.test(candidate) || !p.versions?.[candidate])) candidate = undefined;
403
500
  const available = candidate && (!current || compareVersions(candidate, current.version) > 0) ? candidate : null;
404
- this.#save({ checkedAt: this.#o.now().toISOString(), available, checkError: null });
501
+ /* Since when it is out (RELEASE_SETTLE_MS): the registry's time for it, and when it was first seen here. */
502
+ const was = this.#state().outSince;
503
+ const published = Date.parse(p.time?.[available] ?? '');
504
+ const outSince = available ? { version: available, seenAt: was?.version === available && was.seenAt ? was.seenAt : this.#o.now().toISOString(), publishedAt: Number.isFinite(published) ? new Date(published).toISOString() : null } : null;
505
+ this.#save({ checkedAt: this.#o.now().toISOString(), available, checkError: null, outSince });
405
506
  return available;
406
507
  } catch (error) {
407
508
  this.#save({ checkedAt: this.#o.now().toISOString(), checkError: `The registry could not be asked: ${error.message}` });
@@ -419,6 +520,12 @@ export class Updater {
419
520
  }
420
521
 
421
522
  #npmEnv(nodeDir) { return { ...process.env, PATH: `${nodeDir ? `${nodeDir}/bin:` : ''}${dirname(process.execPath)}:${process.env.PATH ?? '/usr/bin:/bin'}`, npm_config_update_notifier: 'false', npm_config_fund: 'false', npm_config_audit: 'false' }; }
523
+ /* What npm said when it failed, for "See the log": its own words, then the end of its debug log. */
524
+ #npmFailure(r, what) {
525
+ const said = redact(String(r.stderr || r.stdout || '').trim().split('\n').filter((l) => !/A complete log of this run can be found in/.test(l)).slice(-20).join('\n'));
526
+ const tail = npmLogTail(join(this.#o.stateDir, 'npm-cache'));
527
+ return [`== ${this.#o.now().toISOString()} ${what} failed (exit ${r.code})`, `-- what npm said\n${said || '(nothing)'}`, ...(tail ? [`-- the end of npm's debug log\n${tail}`] : [])].join('\n').slice(-LOG_MAX);
528
+ }
422
529
  #npm(args, { cwd, nodeDir, timeoutMs = 900_000 } = {}) {
423
530
  const npm = nodeDir ? join(nodeDir, 'bin', 'npm') : join(dirname(process.execPath), 'npm');
424
531
  return this.#run([npm, ...args, '--registry', `${this.#o.registry}/`, '--cache', join(this.#o.stateDir, 'npm-cache'), '--loglevel=error'], { cwd, env: this.#npmEnv(nodeDir), timeoutMs });
@@ -442,9 +549,12 @@ export class Updater {
442
549
  this.#step(action, id, 'Fetching');
443
550
  writeFileSync(join(tmp, 'package.json'), `${JSON.stringify({ name: 'clavarium-release', private: true, dependencies: { [NAME]: version } }, null, 2)}\n`);
444
551
  const got = await this.#npm(['install', '--ignore-scripts', '--no-audit', '--no-fund', '--save-exact'], { cwd: tmp });
445
- if (got.code !== 0) throw new Error(`npm could not install ${NAME}@${version}: ${lastLine(got)}`);
552
+ /* Whatever made it fail (not there yet, a mirror behind, the network, a cut archive), nothing of it ran:
553
+ a fetch failure, with what npm said kept (its debug log goes with its cache, below). */
554
+ if (got.code !== 0) throw new FetchFailed(`npm could not install ${NAME}@${version}: ${npmWhy(got)}`, { log: this.#npmFailure(got, `npm install ${NAME}@${version}`) });
446
555
  app = join(tmp, 'node_modules', NAME);
447
- const manifest = JSON.parse(readFileSync(join(app, 'package.json'), 'utf8'));
556
+ let manifest;
557
+ try { manifest = JSON.parse(readFileSync(join(app, 'package.json'), 'utf8')); } catch (error) { throw new FetchFailed(`npm could not install ${NAME}@${version}: it left no package (${error.code ?? error.message})`, { log: this.#npmFailure(got, `npm install ${NAME}@${version}`) }); }
448
558
  if (manifest.name !== NAME || manifest.version !== version) throw new Error(`npm installed ${manifest.name}@${manifest.version}, not ${NAME}@${version}`);
449
559
  this.#step(action, id, 'Checking');
450
560
  await this.verify(tmp, version);
@@ -491,6 +601,8 @@ export class Updater {
491
601
  const own = entry(NAME);
492
602
  const p = await this.#packument(NAME);
493
603
  const dist = p.versions?.[version]?.dist;
604
+ /* Installed, but not listed by the registry that was asked next (a mirror behind): fetched again later. */
605
+ if (own && !dist) throw new FetchFailed(`the registry does not list ${NAME}@${version} yet`);
494
606
  if (!own || !dist || own.version !== version || own.integrity !== dist.integrity) throw new Error(`${NAME}@${version} as installed is not the archive the registry lists`);
495
607
  for (const name of Object.keys(REPOS)) {
496
608
  const e = name === NAME ? own : entry(name);
@@ -583,7 +695,11 @@ export class Updater {
583
695
  const unlock = this.#lock();
584
696
  try {
585
697
  let release;
586
- try { release = await this.prepare({ version }); } catch (error) { this.#history({ action: 'update', from: from?.version ?? null, to: version, result: 'failed', why: error.message }); throw error; }
698
+ try { release = await this.prepare({ version }); } catch (error) {
699
+ const fetched = error instanceof FetchFailed || /^npm could not install /.test(error.message);
700
+ this.#history({ action: 'update', from: from?.version ?? null, to: version, result: 'failed', why: error.message, ...(fetched ? { fetch: true } : {}), ...(typeof error.log === 'string' && error.log ? { log: error.log.slice(-LOG_MAX) } : {}) });
701
+ throw error;
702
+ }
587
703
  const before = this.#dataFormat();
588
704
  let archive;
589
705
  try {
@@ -695,8 +811,17 @@ export class Updater {
695
811
  const available = await this.check();
696
812
  if (!available) return 'up to date';
697
813
  if (conf.MODE === 'ask') return `${available} is out: waiting for the owner`;
698
- /* A version that failed here is not tried again by itself: the owner can, from Settings. */
699
- if ((state.history ?? []).some((h) => h.to === available && h.action === 'update' && h.result !== 'done')) return `${available} failed here before: not tried again by itself`;
814
+ /* A version that failed here is not tried again by itself: the owner can, from Settings. One that only
815
+ could not be fetched (nothing of it ran) is, later, a few times. */
816
+ const failed = (state.history ?? []).filter((h) => h.to === available && h.action === 'update' && h.result !== 'done');
817
+ if (failed.some((h) => h.fetch !== true)) return `${available} failed here before: not tried again by itself`;
818
+ if (failed.length >= FETCH_TRIES) return `${available} could not be fetched ${failed.length} times: not tried again by itself`;
819
+ const lastAt = Math.max(...failed.map((h) => new Date(h.at ?? 0).getTime()), -Infinity);
820
+ if (failed.length && now - lastAt < FETCH_AGAIN_MS) return `${available} could not be fetched: tried again later`;
821
+ /* Just out: every mirror given time to have it (RELEASE_SETTLE_MS). */
822
+ const out = this.#state().outSince;
823
+ const outAt = Math.min(...[out?.version === available ? out.seenAt : null, out?.version === available ? out.publishedAt : null].map((t) => Date.parse(t ?? '')).filter(Number.isFinite), now.getTime());
824
+ if (now - outAt < this.#o.releaseSettleMs) return `${available} is just out: installed by itself from ${new Date(outAt + this.#o.releaseSettleMs).toISOString()}`;
700
825
  const why = await this.busy(); if (why) return why;
701
826
  await this.apply(available);
702
827
  /* What the history says, not what was hoped: a version that did not start was undone. */
@@ -841,11 +966,19 @@ export class Updater {
841
966
  const port = readConf(this.#o.conf).PORT;
842
967
  const part = async (title, argv) => { const r = await this.#run(argv, { timeoutMs: 20_000 }); return `-- ${title}\n${String(r.stdout || r.stderr || `exit ${r.code}`).trim()}`; };
843
968
  const left = await this.#leftovers().catch(() => []);
969
+ /* WHAT THE SERVER ITSELF SAID (17-11): the unit's journal is mostly the sudo lines of the host program it
970
+ runs (a hundred a minute), its own words lost among them -- the owner saw only those, and no reason.
971
+ Read further back, the sudo and PAM lines left out, the last of the rest kept. */
972
+ const serverSaid = async () => {
973
+ const r = await this.#run(['journalctl', '-u', 'clavarium.service', '-n', '4000', '--no-pager', '-o', 'short-iso'], { timeoutMs: 20_000 });
974
+ const lines = String(r.stdout || '').split('\n').filter((l) => l.trim() && !/ (sudo|pkexec)\[\d+\]: | pam_unix\(/.test(l));
975
+ return `-- what the server said (journalctl -u clavarium, sudo lines left out)\n${lines.slice(-80).join('\n').trim() || String(r.stderr || `exit ${r.code}`).trim()}`;
976
+ };
844
977
  return [
845
978
  await part('systemctl status clavarium', ['systemctl', 'status', 'clavarium.service', '--no-pager', '-n', '0']),
846
979
  await part(`who listens on ${port}`, ['ss', '-Hltnp', `sport = :${port}`]),
847
980
  `-- processes of the server's unit or on its port\n${left.map((p) => `pid ${p.pid} state ${p.state}${p.port ? ' (holds the port)' : ''}`).join('\n') || 'none'}`,
848
- await part('journalctl -u clavarium -n 80', ['journalctl', '-u', 'clavarium.service', '-n', '80', '--no-pager', '-o', 'short-iso']),
981
+ await serverSaid(),
849
982
  ].join('\n');
850
983
  }
851
984
 
@@ -960,8 +1093,18 @@ async function main(argv) {
960
1093
  try { const [{ installWatch }, { realSys }] = await Promise.all([import('./doctor.mjs'), import('./online.mjs')]); if (await installWatch(realSys())) console.error('updater: the certificate timer set up'); } catch (error) { console.error(`updater: the certificate timer could not be set up: ${error.message}`); }
961
1094
  try { if (await u.ensureDropIn()) console.error('updater: the drop-in of the server\'s unit written'); } catch (error) { console.error(`updater: the drop-in could not be written: ${error.message}`); }
962
1095
  try { if (await ensureFfmpeg()) console.error('updater: ffmpeg installed, for the sounds the voice boxes play'); } catch (error) { console.error(`updater: ffmpeg could not be installed: ${error.message}`); }
963
- try { if (await ensureQuietSudo()) console.error('updater: sudo no longer logs the host program\'s probes'); } catch (error) { console.error(`updater: sudo could not be made quiet: ${error.message}`); }
964
- try { if (await ensureProxySettings()) console.error('updater: the sign-in proxy takes one CSRF cookie per sign-in'); } catch (error) { console.error(`updater: the sign-in proxy could not be set: ${error.message}`); }
1096
+ /* What became of it is kept beside the state, for Settings (server/updates.mjs: sudoQuiet). */
1097
+ {
1098
+ let outcome = { on: false, why: 'not looked at' };
1099
+ try { if (await ensureQuietSudo({ told: (o) => { outcome = o; } })) console.error('updater: sudo no longer logs the host program\'s probes'); } catch (error) { console.error(`updater: sudo could not be made quiet: ${error.message}`); if (outcome.on) outcome = { on: false, why: error.message.slice(0, 200) }; }
1100
+ if (!outcome.on) console.error(`updater: sudo quiet: not applied: ${outcome.why}`);
1101
+ try {
1102
+ const seen = await sudoSeen();
1103
+ writeFileSync(join(PATHS.stateDir, 'sudo-quiet.json.new'), `${JSON.stringify({ ...outcome, ...seen, at: new Date().toISOString() })}\n`, { mode: 0o644 });
1104
+ renameSync(join(PATHS.stateDir, 'sudo-quiet.json.new'), join(PATHS.stateDir, 'sudo-quiet.json'));
1105
+ } catch (error) { console.error(`updater: the sudo quiet state could not be kept: ${error.message}`); }
1106
+ }
1107
+ try { if (await ensureProxySettings()) console.error('updater: the sign-in proxy set (one CSRF cookie per sign-in; /api/ext/ for API keys)'); } catch (error) { console.error(`updater: the sign-in proxy could not be set: ${error.message}`); }
965
1108
  try { const c = await ensureGenericClientId({ run: runCommand }); if (c.changed.length) console.error('updater: the sign-in client id was made generic (nothing names the product in the open)'); } catch (error) { console.error(`updater: the sign-in client id could not be made generic: ${error.message}`); }
966
1109
  try { if (await ensureTunnel({ run: runCommand })) console.error('updater: the tunnel to the relay notices a cut sooner'); } catch (error) { console.error(`updater: the tunnel could not be set: ${error.message}`); }
967
1110
  /* What became of the relay is kept beside the state, for Settings (server/updates.mjs: relay). */