clavarium 0.2.160-next.1 → 0.2.161-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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.160-next.1",
3
+ "version": "0.2.161-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.160-next.1",
9
+ "version": "0.2.161-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.160-next.1",
3
+ "version": "0.2.161-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.",
@@ -21,6 +21,7 @@
21
21
  */
22
22
  import { mkdirSync, lstatSync } from 'node:fs';
23
23
  import { keeper } from 'clavarium-tether/host';
24
+ import { JsonFile } from './store.mjs';
24
25
 
25
26
  export const FOLDER = '.tether';
26
27
  /* The keeper takes what the agents asked, this often. */
@@ -29,7 +30,7 @@ const AGENT = 'conversation:';
29
30
  export const USB_DEVICE = 'usb-device';
30
31
 
31
32
  export class Tethers {
32
- #keeper; #resources; #conversations; #secrets; #timers = []; #changes = 0; #seen = new Map();
33
+ #keeper; #resources; #conversations; #secrets; #timers = []; #changes = 0; #seen = new Map(); #offered;
33
34
  /* Set by the server once the thread is ready (main.mjs): (name, event) => talk.event(...).
34
35
  A call waiting for the owner is said in its conversation's thread when there is one. */
35
36
  announce = null;
@@ -38,6 +39,7 @@ export class Tethers {
38
39
  `secrets`: the vault, read by name for a connector only (reveal). */
39
40
  constructor({ dataDir, resources, conversations, secrets, connectors, now = () => Date.now() }) {
40
41
  this.#resources = resources; this.#conversations = conversations; this.#secrets = secrets;
42
+ this.#offered = new JsonFile(`${dataDir}/tether-offered.json`, []);
41
43
  this.#keeper = keeper(`${dataDir}/tether`, { sides: () => this.#sides(), secrets: (name) => this.#reveal(name), now, ...(connectors ? { connectors } : {}) });
42
44
  /* Every change a page shows -- a new approval waiting, one decided, the targets,
43
45
  the journal -- bumps the counter the client watches, so the approvals screen
@@ -97,6 +99,17 @@ export class Tethers {
97
99
  return value;
98
100
  }
99
101
 
102
+ /* The USB device is offered to every conversation once, at "propose": each flash still asks the
103
+ owner. Offered once only (the target remembers it): taken back by the owner, it stays taken back. */
104
+ #offerDevice(agent) {
105
+ try {
106
+ const offered = this.#offered.get();
107
+ if (offered.includes(agent) || !this.#keeper.store.target(USB_DEVICE)) return;
108
+ if (!this.#keeper.store.target(USB_DEVICE).grants?.[agent]) this.#keeper.store.grant(USB_DEVICE, agent, 'propose');
109
+ this.#offered.set([...offered, agent]);
110
+ } catch { /* a Tether without devices */ }
111
+ }
112
+
100
113
  /* Each conversation's folder, made when missing; one that is anything but a folder of its own is left out. */
101
114
  #sides() {
102
115
  const out = [];
@@ -107,6 +120,7 @@ export class Tethers {
107
120
  if (info === undefined) { try { mkdirSync(dir); } catch { continue; } }
108
121
  else if (!info.isDirectory() || info.isSymbolicLink()) continue;
109
122
  out.push({ dir, who: { id: `${AGENT}${name}`, kind: 'agent', name } });
123
+ this.#offerDevice(`${AGENT}${name}`);
110
124
  }
111
125
  return out;
112
126
  }
@@ -141,6 +155,7 @@ export class Tethers {
141
155
  given() {
142
156
  const out = {};
143
157
  for (const t of this.#keeper.store.targets()) {
158
+ if (t.kind === 'device') continue; /* offered to every conversation: not an access worth counting */
144
159
  for (const id of Object.keys(t.grants ?? {})) if (id.startsWith(AGENT)) out[id.slice(AGENT.length)] = (out[id.slice(AGENT.length)] ?? 0) + 1;
145
160
  }
146
161
  return out;