@volter/teams 0.2.49 → 0.2.50

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/home.mjs CHANGED
@@ -5,6 +5,7 @@
5
5
  // machine.key / machine.pub the host key; it signs `describe`, nothing else
6
6
  // machine.sock the local door: owner-only, the OS user is the caller
7
7
  // machine.json the running daemon: pid, key id, socket, linked server
8
+ // machine-link.json that daemon's link to its server as it is now: up, down or replaced, and since when
8
9
  // launches.jsonl launch key → pane contextKey
9
10
  // log.jsonl hash-chained accountability, no bodies
10
11
  // log.<ts>.jsonl its rotations, oldest pruned past `logKeep`
@@ -66,6 +67,7 @@ export function ensureSocketDirectory(socketPath) {
66
67
  export const paths = (home) => ({
67
68
  machineKey: join(home, 'machine'),
68
69
  machine: join(home, 'machine.json'),
70
+ link: join(home, 'machine-link.json'),
69
71
  socket: machineSocketPath(home),
70
72
  launches: join(home, 'launches.jsonl'),
71
73
  log: join(home, 'log.jsonl'),
package/machine-core.mjs CHANGED
@@ -98,6 +98,7 @@ export class MachineCore extends EventEmitter {
98
98
  }
99
99
  await this.afterListen();
100
100
  if (this.link) {
101
+ this.#publishLink('down', null);
101
102
  await this.refreshLinkConfiguration().catch((error) => this.emit('link', { event: 'configuration-failed', error: error.message }));
102
103
  this.#connectLink();
103
104
  }
@@ -157,6 +158,7 @@ export class MachineCore extends EventEmitter {
157
158
  try { if (statSync(this.socketPath).ino === this.socketInode) rmSync(this.socketPath, { force: true }); } catch { /* already gone */ }
158
159
  }
159
160
  try { if (JSON.parse(readFileSync(this.p.machine, 'utf8')).pid === process.pid) rmSync(this.p.machine); } catch { /* absent or unreadable */ }
161
+ try { if (JSON.parse(readFileSync(this.p.link, 'utf8')).pid === process.pid) rmSync(this.p.link); } catch { /* absent or unreadable */ }
160
162
  }
161
163
 
162
164
  /** Before the connections close: a product finishes or abandons what is in flight. */
@@ -164,6 +166,18 @@ export class MachineCore extends EventEmitter {
164
166
 
165
167
  // ---- the server link ----------------------------------------------------
166
168
 
169
+ /**
170
+ * The link as it is now, in a file beside the machine record (machine-link.json): `state` up, down or replaced, and
171
+ * since when. The record's `server` says only which server this daemon was started for; whether it reaches that
172
+ * server is read here, by what runs outside this process (an upgrade's activation watch, the service's next start),
173
+ * because a daemon that answers its socket with no link is unreachable to everything remote.
174
+ */
175
+ #publishLink(state, error) {
176
+ if (this.linkPublished?.state === state) return;
177
+ this.linkPublished = { pid: process.pid, server: this.link?.server ?? null, state, since_ms: Date.now(), error: error ?? null };
178
+ try { writeJson(this.p.link, this.linkPublished); } catch { /* a reading for others; the link itself is unaffected */ }
179
+ }
180
+
167
181
  /** Re-read the machine's custodian and grants from the server. */
168
182
  async refreshLinkConfiguration() {
169
183
  const configuration = await this.link.configuration();
@@ -187,6 +201,7 @@ export class MachineCore extends EventEmitter {
187
201
  if (settled) return;
188
202
  settled = true;
189
203
  if (this.linkSocket === socket) { this.linkSocket = null; this.linkChannel = null; }
204
+ if (!this.linkReplaced) this.#publishLink('down', error?.message ?? null);
190
205
  this.emit('link', { event: 'dropped', error: error?.message ?? null });
191
206
  this.#retryLink();
192
207
  };
@@ -198,6 +213,7 @@ export class MachineCore extends EventEmitter {
198
213
  channel.on('stream', (stream, accept, refuse) => { void this.#onLinkStream(channel, stream, accept, refuse); });
199
214
  channel.on('close', () => dropped(null));
200
215
  channel.on('error', () => {});
216
+ this.#publishLink('up', null);
201
217
  this.emit('link', { event: 'up', server });
202
218
  } catch (error) { socket.terminate(); dropped(error); }
203
219
  });
@@ -218,6 +234,7 @@ export class MachineCore extends EventEmitter {
218
234
  // this one stops and says so.
219
235
  if (String(reason ?? '') === 'replaced') {
220
236
  this.linkReplaced = true;
237
+ this.#publishLink('replaced', 'another connector for this machine took over its link');
221
238
  this.emit('link', { event: 'replaced', error: 'another connector for this machine took over its link; this one stopped linking' });
222
239
  }
223
240
  dropped(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/teams",
3
- "version": "0.2.49",
3
+ "version": "0.2.50",
4
4
  "type": "module",
5
5
  "description": "Volter Teams, the neutral team plane: machine identity and daemon core, the local door and server link, admission from machine grants, product doors, and the Teams server's neutral routes (company RFC 0008).",
6
6
  "license": "MIT",