clavarium 0.2.300-next.1 → 0.2.302-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1390,8 +1390,20 @@ OOMScoreAdjust=-900'
1390
1390
  [ $# -eq 0 ] || usage
1391
1391
  run pgrep -a qemu-system ;;
1392
1392
  "net bridge")
1393
+ # The bridge the machines' taps are on: multipass 1.17 names it per zone
1394
+ # (mpqemubrzone1, ...), older ones mpqemubr0 (04-11: the offline rules
1395
+ # were never written, their bridge not found). The first tap's says.
1393
1396
  [ $# -eq 0 ] || usage
1394
- run ip -4 -o addr show "$BRIDGE" ;;
1397
+ if [ "$SAY" = "yes" ]; then echo "ip -4 -o addr show <the bridge of the taps, else $BRIDGE>"; exit 0; fi
1398
+ bridge="$BRIDGE"
1399
+ for t in /sys/class/net/tap-*; do
1400
+ [ -e "$t/master" ] || continue
1401
+ m=$(basename "$(readlink "$t/master")"); [[ "$m" =~ ^mpqemubr[a-z0-9]{1,12}$ ]] && { bridge="$m"; break; }
1402
+ done
1403
+ if [ "$bridge" = "$BRIDGE" ] && ! [ -e "/sys/class/net/$BRIDGE" ]; then
1404
+ for b in /sys/class/net/mpqemubr*; do [ -e "$b" ] && { bridge=$(basename "$b"); break; }; done
1405
+ fi
1406
+ run ip -4 -o addr show "$bridge" ;;
1395
1407
  "net apply")
1396
1408
  # <ruleset>: the whole table, as text. Each line must be one of the
1397
1409
  # shapes the server writes; one unknown line refuses the whole.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.300-next.1",
3
+ "version": "0.2.302-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.300-next.1",
9
+ "version": "0.2.302-next.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.300-next.1",
3
+ "version": "0.2.302-next.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
@@ -71,6 +71,8 @@ export function escaped(text) {
71
71
 
72
72
  export class GitReview {
73
73
  #store; #vault; #resources; #local; #access; #runner; #now; #listeners = []; #waivers = () => ({});
74
+ /* The refresh of each repository on its way: { run, waitMs }, by name. */
75
+ #refreshing = new Map();
74
76
 
75
77
  /* `localRemotes`: lets a remote be a directory of this machine. For tests only.
76
78
  `runner`: the git runner (gitrunner.mjs); its reads go through the host program. */
@@ -204,8 +206,22 @@ export class GitReview {
204
206
  The only writer of the reference. */
205
207
  async refresh(name, { waitMs = SEND_WAIT_MS } = {}) {
206
208
  const r = this.#repository(name);
207
- const release = await this.#runner.lock(this.#reference(r.name), waitMs);
208
- try { return await this.#refreshLocked(r); } finally { release(); }
209
+ /* One on its way already, that waits at least as long as this one
210
+ would: its fetch is shared, not made again behind it. A page that
211
+ reviews several branches of a repository at once (To send) would
212
+ otherwise line up one fetch per branch behind the reference's lock,
213
+ and the last ones be refused as busy -- and drop out of the list. */
214
+ const going = this.#refreshing.get(r.name);
215
+ if (going && going.waitMs >= waitMs) return going.run;
216
+ const run = (async () => {
217
+ const release = await this.#runner.lock(this.#reference(r.name), waitMs);
218
+ try { return await this.#refreshLocked(r); } finally { release(); }
219
+ })();
220
+ const entry = { run, waitMs };
221
+ this.#refreshing.set(r.name, entry);
222
+ const done = () => { if (this.#refreshing.get(r.name) === entry) this.#refreshing.delete(r.name); };
223
+ run.then(done, done);
224
+ return run;
209
225
  }
210
226
  /* `ours`: { branch, head } just pushed from here: what it brings back is not news from the remote. */
211
227
  async #refreshLocked(r, ours = null) {
package/server/main.mjs CHANGED
@@ -361,6 +361,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
361
361
  /* Each opening: the runner and the attached secrets are put in the VM,
362
362
  and the tool is started through the runner. */
363
363
  const network = new Network({ host: asHost, offline: () => all.offline() });
364
+ /* A machine the VM manager started by itself (after a reboot) is put in its silo too (04-11). */
365
+ const stopNetworkWatch = network.watch();
364
366
  /* The rules follow what runs: applied now, and again each time a
365
367
  conversation is opened, since a VM that just started has a new tap. */
366
368
  const hostReady = (async () => { await hostSteps; await network.apply().catch((error) => console.error(`network rules: ${error.message}`)); })();
@@ -656,7 +658,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
656
658
  rooms.boxesBound(boxes.all());
657
659
  rooms.refresh();
658
660
  const { server, listening } = serve(port, all, folders, { gate, originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, wifi, binders, meshcentral, tethers, accounts, groups, boxes, catalogue, rooms, bundles: new Bundles({ dir: `${dataDir}/imports`, folder: (name) => folders.folder(name) }), repair: (name) => repairTerminal(name) });
659
- server.on('close', () => { closing = true; stopBinders(); stopTethers(); clearInterval(historyTimer); clearInterval(secretsTimer); history.save(); stopVmWatch(); stopShelf(); stopHealth(); stopUpdates(); stopWatch(); clearInterval(mailTimer); clearInterval(restartTimer); clearInterval(expiryTimer); clearInterval(answerTimer); clearInterval(wakeTimer); clearInterval(docketTimer); dockets.stop(); clearInterval(gitTimer); talk.stop(); });
661
+ server.on('close', () => { closing = true; stopBinders(); stopTethers(); clearInterval(historyTimer); clearInterval(secretsTimer); history.save(); stopVmWatch(); stopShelf(); stopHealth(); stopNetworkWatch(); stopUpdates(); stopWatch(); clearInterval(mailTimer); clearInterval(restartTimer); clearInterval(expiryTimer); clearInterval(answerTimer); clearInterval(wakeTimer); clearInterval(docketTimer); dockets.stop(); clearInterval(gitTimer); talk.stop(); });
660
662
  let closing = false;
661
663
  boxes.attach(server, WebSocketServer);
662
664
  for (const c of all.list()) talk.speakers(c.name, boxes.speakersOf(c.name));
@@ -26,6 +26,10 @@ const TAP = /^tap-[0-9a-f]{1,12}$/;
26
26
  /* The taps of the running conversation VMs, read from the process list:
27
27
  { conversation: tap }. Anything that does not look exactly as expected is
28
28
  left out: a rule is never built from a string that was not checked. */
29
+ /* How often what runs is looked at, for the rules (see watch). */
30
+ export const WATCH_MS = 20_000;
31
+ export const RELOAD_MS = 10 * 60_000;
32
+
29
33
  export function readTaps(processList) {
30
34
  const taps = {};
31
35
  for (const line of String(processList ?? '').split('\n')) {
@@ -62,6 +66,8 @@ export function ruleset(taps, offline, bridgeAddress) {
62
66
 
63
67
  export class Network {
64
68
  #host; #offline;
69
+ /* The table last loaded, and whether it was: the same table is not loaded again. */
70
+ #last = null;
65
71
 
66
72
  /* `host(argv)` reaches the host program;
67
73
  `offline()` returns the names of the conversations switched offline. */
@@ -79,7 +85,21 @@ export class Network {
79
85
  a pipe as its input file (measured), and nothing in the rules is
80
86
  secret. Every name in them was checked by readTaps, and the host
81
87
  program checks every line again before loading it. */
82
- const r = await this.#host(['net', 'apply', ruleset(taps, bridge ? wanted : [], bridge ?? '0.0.0.0')]);
83
- return r.code === 0 && (bridge !== undefined || wanted.length === 0);
88
+ const text = ruleset(taps, bridge ? wanted : [], bridge ?? '0.0.0.0');
89
+ const ok = bridge !== undefined || wanted.length === 0;
90
+ /* Loaded again anyway now and then: a table taken off by someone else comes back. */
91
+ if (this.#last?.text === text && this.#last.loaded && Date.now() - this.#last.at < RELOAD_MS) return ok;
92
+ const r = await this.#host(['net', 'apply', text]);
93
+ this.#last = { text, loaded: r.code === 0, at: Date.now() };
94
+ return r.code === 0 && ok;
95
+ }
96
+
97
+ /* KEPT UP TO DATE (04-11): a machine started by the VM manager itself -- after the server
98
+ restarted -- has a new tap that no opening told: looked at every `everyMs`, the table loaded
99
+ again only when what runs changed. Returns the stop. */
100
+ watch(everyMs = WATCH_MS) {
101
+ const timer = setInterval(() => { void this.apply().catch(() => {}); }, everyMs);
102
+ timer.unref?.();
103
+ return () => clearInterval(timer);
84
104
  }
85
105
  }
package/web/app.js CHANGED
@@ -3554,7 +3554,8 @@
3554
3554
  const r = await fetch(`${API}${path}`);
3555
3555
  const j = await r.json().catch(() => ({}));
3556
3556
  if (r.ok) return j;
3557
- if (!(r.status === 503 && j.down === true)) return { state: 'error', message: j.error || 'It could not be read.' };
3557
+ /* Down for a moment, or its repository busy (another read holds it): asked again. */
3558
+ if (!(r.status === 503 && (j.down === true || j.kind === 'busy'))) return { state: 'error', message: j.error || 'It could not be read.' };
3558
3559
  } catch { return { state: 'error', message: 'It could not be read.' }; }
3559
3560
  await new Promise((ok) => setTimeout(ok, 1500 * (i + 1)));
3560
3561
  }
@@ -3974,6 +3975,8 @@
3974
3975
  const BRANCHES_MORE = 7;
3975
3976
  /* What a row is, for the filter: a branch the remote has and that is ahead of it, a branch it does not have, nothing to send. */
3976
3977
  const kindOfRow = (out) => (out?.state !== 'ahead' ? 'none' : out.targetExists === false ? 'new' : 'update');
3978
+ /* A branch that could not be read is not "nothing to send": it stays listed, under every filter, with why. */
3979
+ const unread = (out) => out?.state === 'error' || out?.state === 'unreachable';
3977
3980
  const TS_FILTERS = [['update', 'To update'], ['new', 'New branches'], ['all', 'All']];
3978
3981
  /* Three steps: every branch read (said as it goes, nothing checked yet); filtered and ticked; the checks of what is
3979
3982
  ticked, on a click; then Send. */
@@ -3995,7 +3998,7 @@
3995
3998
  let sending = false; let checking = false;
3996
3999
  let sure = '';
3997
4000
  let reposDone = 0; let reading = true;
3998
- const shownRow = (r) => filter === 'all' || kindOfRow(r.out) === filter;
4001
+ const shownRow = (r) => filter === 'all' || kindOfRow(r.out) === filter || unread(r.out);
3999
4002
  const picked = () => rows.filter((r) => r.picked && r.out?.state === 'ahead' && shownRow(r));
4000
4003
  const label = (r) => (rows.filter((x) => x.name === r.name).length > 1 ? `${r.name} (${r.branch})` : r.name);
4001
4004
  async function look(r) {
@@ -4040,7 +4043,12 @@
4040
4043
  meter.hidden = !reading; meterFill.style.width = `${names.length ? Math.round((reposDone / names.length) * 100) : 100}%`;
4041
4044
  progress.toggleAttribute('data-busy', reading);
4042
4045
  if (reading) { progress.dataset.tone = 'warn'; progress.textContent = `Reading the repositories: ${reposDone} of ${names.length}${rows.length ? ` · ${rows.length} branch${rows.length === 1 ? '' : 'es'} found` : ''}`; }
4043
- else { progress.dataset.tone = count('update') + count('new') ? 'ok' : ''; progress.textContent = count('update') + count('new') ? `${count('update')} to update · ${count('new')} new · all read` : 'Nothing to send · all read'; }
4046
+ else {
4047
+ const failed = rows.filter((r) => unread(r.out)).length;
4048
+ const tail = failed ? ` · ${failed} not read` : ' · all read';
4049
+ progress.dataset.tone = failed ? 'warn' : count('update') + count('new') ? 'ok' : '';
4050
+ progress.textContent = count('update') + count('new') ? `${count('update')} to update · ${count('new')} new${tail}` : `Nothing to send${tail}`;
4051
+ }
4044
4052
  filters.replaceChildren(...TS_FILTERS.map(([key, word]) => {
4045
4053
  const n = key === 'all' ? rows.length : count(key);
4046
4054
  const b = el('button', '', `${word} ${n}`); b.type = 'button'; b.dataset.filter = key; b.setAttribute('aria-pressed', String(filter === key));
@@ -4083,8 +4091,10 @@
4083
4091
  tick.addEventListener('change', () => { r.picked = tick.checked; sure = ''; paint(); if (!review.hidden) paintReview(); });
4084
4092
  const who = el('div', 'ts-who'); who.append(el('b', '', r.name), el('small', 'hint', out?.remote ? hostOf(out.remote) : out ? 'no remote' : ''));
4085
4093
  const way = el('div', 'ts-way');
4086
- if (out?.branch) {
4087
- const code = el('code', 'ts-branch', out.branch); code.title = out.branch; way.append(code);
4094
+ /* Its own name even when it could not be read: which branch is missing is said. */
4095
+ const named = out?.branch ?? (unread(out) ? r.branch : '');
4096
+ if (named) {
4097
+ const code = el('code', 'ts-branch', named); code.title = named; way.append(code);
4088
4098
  if (['ahead', 'up-to-date', 'diverged'].includes(out.state) && out.target) {
4089
4099
  way.append(el('span', 'ts-arrow', '→'));
4090
4100
  const to = el('select'); to.setAttribute('aria-label', `Where ${label(r)} goes`); to.disabled = sending || checking;
@@ -4300,7 +4310,7 @@
4300
4310
  const r = { name, out: null, keep: first.keep, branch: b.name, target: '', picked: false, check: null, sent: null, movedAt: b.movedAt };
4301
4311
  await look(r);
4302
4312
  /* Ticked by one rule for every row: a branch of the remote to update is ticked; a new one is not. */
4303
- if (r.out?.state === 'ahead') { r.picked = kindOfRow(r.out) === 'update'; rows.splice(rows.findLastIndex((x) => x.name === name) + 1, 0, r); }
4313
+ if (r.out?.state === 'ahead' || unread(r.out)) { r.picked = kindOfRow(r.out) === 'update'; rows.splice(rows.findLastIndex((x) => x.name === name) + 1, 0, r); }
4304
4314
  paint();
4305
4315
  }));
4306
4316
  reposDone++; paint();