clavarium 0.2.97-beta.1 → 0.2.98-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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.97-beta.1",
3
+ "version": "0.2.98-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.97-beta.1",
9
+ "version": "0.2.98-beta.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.97-beta.1",
3
+ "version": "0.2.98-beta.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
package/server/api.mjs CHANGED
@@ -500,10 +500,12 @@ export async function handleApi(request, response, conversations, headers, resou
500
500
  return send(200, op[2] === 'password' ? await team.password(email) : { operators: await team[op[2]](email) }), true;
501
501
  }
502
502
  const renaming = /^\/api\/secrets\/([A-Z][A-Z0-9_]{0,39})\/rename$/.exec(pathname);
503
- if (renaming && secrets) return send(200, secrets.rename(renaming[1], String(body.name ?? '').trim())), true;
503
+ /* Its machines that run get the new name or value now, as a secret given to them does. */
504
+ const redeliver = async (name) => { for (const c of conversations.list()) if (c.phase === 'ready' && !c.asleep && secrets.of(c.name).includes(name)) await secrets.deliver(c.name).catch(() => {}); };
505
+ if (renaming && secrets) { const done = secrets.rename(renaming[1], String(body.name ?? '').trim()); await redeliver(String(body.name ?? '').trim()); return send(200, done), true; }
504
506
  /* A new value (never sent back) and/or a new expiry, in place. */
505
507
  const replacing = /^\/api\/secrets\/([A-Z][A-Z0-9_]{0,39})\/replace$/.exec(pathname);
506
- if (replacing && secrets) return send(200, secrets.replace(replacing[1], { value: body.value, expires: body.expires })), true;
508
+ if (replacing && secrets) { const done = secrets.replace(replacing[1], { value: body.value, expires: body.expires }); await redeliver(replacing[1]); return send(200, done), true; }
507
509
  const dropped = /^\/api\/secrets\/([A-Z][A-Z0-9_]{0,39})\/remove$/.exec(pathname);
508
510
  if (dropped && secrets) { secrets.remove(dropped[1]); return send(200, { ok: true }), true; }
509
511
  if (pathname === '/api/alerts' && alerts) return send(201, alerts.add(body.subscription, body.label)), true;
@@ -567,6 +569,10 @@ export async function handleApi(request, response, conversations, headers, resou
567
569
  const conversation = decodeURIComponent(handed[1]);
568
570
  if (!conversations.list().some((c) => c.name === conversation)) throw new Refusal(404, 'No such conversation.');
569
571
  secrets.attach(conversation, String(body.secret ?? ''), body.attached === true);
572
+ /* A machine that runs gets it (or loses it) now, in /run/secrets -- not only at the next
573
+ opening of a terminal; its tool's variables still wait for the tool's next start. */
574
+ const c = conversations.list().find((x) => x.name === conversation);
575
+ if (c?.phase === 'ready' && !c.asleep) await secrets.deliver(conversation).catch(() => {});
570
576
  retell(conversation);
571
577
  return send(200, { ok: true, secrets: secrets.of(conversation) }), true;
572
578
  }
package/server/main.mjs CHANGED
@@ -549,6 +549,14 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
549
549
  const history = new History({ file: `${dataDir}/history.json` });
550
550
  const historyLook = () => capacity.room().then((room) => history.sample(room, all.list().filter((c) => c.phase === 'ready').map((c) => ({ name: c.name, vm: `clv-${c.name}`, cores: c.cpus ?? 1, memoryMb: c.memoryMb, health: health.of(c.name) })))).catch(() => {});
551
551
  const historyTimer = setInterval(() => { void historyLook(); }, historyEveryMs); historyTimer.unref?.();
552
+ /* THE SECRETS' GUARD: each minute, every machine that runs is looked at -- the names in its
553
+ /run/secrets against those it should hold now, and what was last put there against what would
554
+ be now. A missing one is put back, one too many taken away, a new value given: whatever path
555
+ changed them (a page, an expiry, a machine restarted behind our back). */
556
+ const secretsGuard = async () => {
557
+ for (const name of all.awake()) { const now = await secrets.reconcile(name, delivered.get(name)).catch(() => null); if (now !== null) delivered.set(name, now); }
558
+ };
559
+ const secretsTimer = setInterval(() => { void secretsGuard().catch(() => {}); }, 60_000); secretsTimer.unref?.();
552
560
  /* The certificate the front serves, said in Settings (certificate.mjs). */
553
561
  const certificate = new Certificate({ origin: publicOrigin, alerts });
554
562
  /* All the machines to another disk, from Settings (machinesmove.mjs). */
@@ -565,7 +573,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
565
573
  const watching = setInterval(() => { void team.watch().catch(() => {}); }, 60_000); watching.unref?.();
566
574
  }
567
575
  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, bundles: new Bundles({ dir: `${dataDir}/imports`, folder: (name) => folders.folder(name) }), repair: (name) => repairTerminal(name) });
568
- server.on('close', () => { closing = true; stopBinders(); stopTethers(); clearInterval(historyTimer); history.save(); stopVmWatch(); stopShelf(); stopHealth(); stopUpdates(); stopWatch(); clearInterval(mailTimer); clearInterval(expiryTimer); clearInterval(answerTimer); clearInterval(wakeTimer); clearInterval(docketTimer); dockets.stop(); clearInterval(gitTimer); talk.stop(); });
576
+ server.on('close', () => { closing = true; stopBinders(); stopTethers(); clearInterval(historyTimer); clearInterval(secretsTimer); history.save(); stopVmWatch(); stopShelf(); stopHealth(); stopUpdates(); stopWatch(); clearInterval(mailTimer); clearInterval(expiryTimer); clearInterval(answerTimer); clearInterval(wakeTimer); clearInterval(docketTimer); dockets.stop(); clearInterval(gitTimer); talk.stop(); });
569
577
  let closing = false;
570
578
  bridge = attachBridge(server, {
571
579
  onRejoin: (name) => all.rejoin(name),
@@ -262,6 +262,20 @@ export class Secrets {
262
262
  return this.#given(conversation).map((s) => `${s.name}=${s.sealed}`).sort().join('|');
263
263
  }
264
264
 
265
+ /* THE GUARD (main.mjs, each minute, for each machine that runs): the names in its /run/secrets
266
+ against those it should hold, and `last` (the signature of what was last put there) against
267
+ what it would be now. Delivered again when either differs. Resolves with the signature now
268
+ there, or null when the machine could not be looked at. */
269
+ async reconcile(conversation, last) {
270
+ const seen = await this.#vms.exec(conversation, ['sh', '-c', `ls -1 ${SECRETS_DIR} 2>/dev/null; true`], { timeoutMs: 10_000 }).catch(() => null);
271
+ if (!seen || seen.code !== 0) return null;
272
+ const there = String(seen.stdout ?? '').split('\n').map((x) => x.trim()).filter(Boolean).sort().join('|');
273
+ const wanted = this.signature(conversation);
274
+ if (there === this.given(conversation).sort().join('|') && last === wanted) return wanted;
275
+ await this.deliver(conversation);
276
+ return wanted;
277
+ }
278
+
265
279
  /* Puts in the VM exactly the secrets attached NOW and not expired, and the
266
280
  runner. Called each time the conversation is opened: a detached or
267
281
  expired secret disappears from the VM, a new one appears, and a
package/web/links.js CHANGED
@@ -677,7 +677,7 @@
677
677
  const keep = h('button', { type: 'button', text: 'Cancel', onclick: () => openPop(l) });
678
678
  sure.addEventListener('click', async () => {
679
679
  sure.disabled = true;
680
- try { await takeAway(l); closePop(); await changed(); if (b.kind === 'secret') err(`${b.name} will no longer be handed to ${a.name}'s tool the next time it starts.`); } catch (e) { fail(e); }
680
+ try { await takeAway(l); closePop(); await changed(); if (b.kind === 'secret') err(`${b.name} is taken out of ${a.name}'s machine now; its tool keeps it as a variable until its next start.`); } catch (e) { fail(e); }
681
681
  });
682
682
  row.before(ask);
683
683
  row.replaceChildren(sure, keep);