@fnndsc/calypso 0.29.14 → 0.30.0

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 (82) hide show
  1. package/dist/calypso.js +19 -8
  2. package/dist/calypso.js.map +1 -1
  3. package/dist/daemon/attachFile.d.ts +26 -19
  4. package/dist/daemon/attachFile.js +42 -51
  5. package/dist/daemon/attachFile.js.map +1 -1
  6. package/dist/daemon/attachOrigin.d.ts +69 -0
  7. package/dist/daemon/attachOrigin.js +125 -0
  8. package/dist/daemon/attachOrigin.js.map +1 -0
  9. package/dist/daemon/berth.d.ts +265 -26
  10. package/dist/daemon/berth.js +521 -158
  11. package/dist/daemon/berth.js.map +1 -1
  12. package/dist/daemon/claims.js +19 -9
  13. package/dist/daemon/claims.js.map +1 -1
  14. package/dist/daemon/commandLane.d.ts +317 -0
  15. package/dist/daemon/commandLane.js +409 -0
  16. package/dist/daemon/commandLane.js.map +1 -0
  17. package/dist/daemon/console.d.ts +0 -2
  18. package/dist/daemon/console.js +7 -10
  19. package/dist/daemon/console.js.map +1 -1
  20. package/dist/daemon/consoleSession.js +4 -1
  21. package/dist/daemon/consoleSession.js.map +1 -1
  22. package/dist/daemon/elevation.d.ts +0 -3
  23. package/dist/daemon/elevation.js +1 -3
  24. package/dist/daemon/elevation.js.map +1 -1
  25. package/dist/daemon/face.d.ts +18 -4
  26. package/dist/daemon/face.js +77 -32
  27. package/dist/daemon/face.js.map +1 -1
  28. package/dist/daemon/hostControl.d.ts +114 -1
  29. package/dist/daemon/hostControl.js +104 -4
  30. package/dist/daemon/hostControl.js.map +1 -1
  31. package/dist/daemon/hostPty.d.ts +14 -0
  32. package/dist/daemon/hostPty.js +19 -1
  33. package/dist/daemon/hostPty.js.map +1 -1
  34. package/dist/daemon/hostPtyRelay.d.ts +118 -0
  35. package/dist/daemon/hostPtyRelay.js +186 -0
  36. package/dist/daemon/hostPtyRelay.js.map +1 -0
  37. package/dist/daemon/httpRoutes.d.ts +257 -0
  38. package/dist/daemon/httpRoutes.js +537 -0
  39. package/dist/daemon/httpRoutes.js.map +1 -0
  40. package/dist/daemon/instance.d.ts +37 -0
  41. package/dist/daemon/instance.js +59 -0
  42. package/dist/daemon/instance.js.map +1 -0
  43. package/dist/daemon/launch.d.ts +17 -0
  44. package/dist/daemon/launch.js +198 -194
  45. package/dist/daemon/launch.js.map +1 -1
  46. package/dist/daemon/launchBanner.d.ts +76 -0
  47. package/dist/daemon/launchBanner.js +80 -0
  48. package/dist/daemon/launchBanner.js.map +1 -0
  49. package/dist/daemon/rival.d.ts +65 -0
  50. package/dist/daemon/rival.js +67 -0
  51. package/dist/daemon/rival.js.map +1 -0
  52. package/dist/daemon/server.d.ts +104 -190
  53. package/dist/daemon/server.js +358 -866
  54. package/dist/daemon/server.js.map +1 -1
  55. package/dist/daemon/settings.d.ts +42 -0
  56. package/dist/daemon/settings.js +43 -0
  57. package/dist/daemon/settings.js.map +1 -0
  58. package/dist/daemon/surface.d.ts +103 -0
  59. package/dist/daemon/surface.js +71 -0
  60. package/dist/daemon/surface.js.map +1 -0
  61. package/dist/daemon/surfaceReplies.d.ts +109 -0
  62. package/dist/daemon/surfaceReplies.js +108 -0
  63. package/dist/daemon/surfaceReplies.js.map +1 -0
  64. package/dist/daemon/terminals.js +5 -2
  65. package/dist/daemon/terminals.js.map +1 -1
  66. package/dist/daemon/token.d.ts +41 -5
  67. package/dist/daemon/token.js +43 -12
  68. package/dist/daemon/token.js.map +1 -1
  69. package/dist/daemon/uploadHold.d.ts +85 -0
  70. package/dist/daemon/uploadHold.js +205 -0
  71. package/dist/daemon/uploadHold.js.map +1 -0
  72. package/dist/daemon/vfsHeaders.d.ts +11 -0
  73. package/dist/daemon/vfsHeaders.js +60 -0
  74. package/dist/daemon/vfsHeaders.js.map +1 -0
  75. package/dist/index.d.ts +5 -5
  76. package/dist/index.js +3 -4
  77. package/dist/index.js.map +1 -1
  78. package/dist/notes.json +1 -1
  79. package/package.json +9 -4
  80. package/dist/daemon/discovery.d.ts +0 -23
  81. package/dist/daemon/discovery.js +0 -57
  82. package/dist/daemon/discovery.js.map +0 -1
@@ -1,4 +1,5 @@
1
1
  import { type ClosingCause } from '@fnndsc/menu';
2
+ export { trustedRoot_settle, type OwnFolder, type OwnRefusal } from '@fnndsc/fond';
2
3
  /**
3
4
  * The advertised location of one running daemon, keyed by CUBE identity.
4
5
  *
@@ -20,6 +21,8 @@ export interface Berth {
20
21
  versions?: Record<string, string>;
21
22
  /** When the daemon booted, ISO. */
22
23
  booted?: string;
24
+ /** This launch's key for proving which instance answers (`berthInstance_probe`); absent in an earlier release's record. */
25
+ probeKey?: string;
23
26
  }
24
27
  /**
25
28
  * Normalises a `<user>@<url>` identity lexically — no DNS, no network.
@@ -64,6 +67,20 @@ export declare function berthKey_compute(identity: string): string;
64
67
  * @returns The absolute berth directory path (not guaranteed to exist yet).
65
68
  */
66
69
  export declare function berthDir_path(): string;
70
+ /**
71
+ * Joins names onto a configured folder as spelled, never normalising it: a `..` the configuration holds reaches the
72
+ * owner-only check (`ownFolder_settle`), which refuses it, instead of being folded into another folder first.
73
+ *
74
+ * @param base - The folder as configured.
75
+ * @param names - Plain names to append.
76
+ * @returns The joined path.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * spelled_join('/run/user/1000/x/..', 'calypso'); // '/run/user/1000/x/../calypso'
81
+ * ```
82
+ */
83
+ export declare function spelled_join(base: string, ...names: string[]): string;
67
84
  /**
68
85
  * The absolute path of one identity's berth file.
69
86
  *
@@ -87,6 +104,7 @@ export declare function berth_pathIn(runtimeDir: string, identity: string): stri
87
104
  * Writes a berth to its identity-keyed file, readable only by the current user.
88
105
  *
89
106
  * @param berth - The berth to advertise; its `identity` must be normalised.
107
+ * @throws {Error} When the berth folder is not this account's own, or a record that is not stands at the name.
90
108
  */
91
109
  export declare function berth_write(berth: Berth): void;
92
110
  /**
@@ -106,6 +124,51 @@ export declare function berth_read(identity: string): Berth | null;
106
124
  * @returns The berth, or null.
107
125
  */
108
126
  export declare function berthOwn_read(identity: string): Berth | null;
127
+ /**
128
+ * Where a porter keeps its sessions' state, from the environment alone: `PORTER_STATE_DIR` when it is set,
129
+ * else `porter` under the XDG state folder (`xdgDir_resolve`). The one reading porter starts by and a client
130
+ * looks for sessions by.
131
+ *
132
+ * Spelled, not normalised: a `..` in either reaches the state root's check (`trustedRoot_settle`), never
133
+ * folded away first. An empty `PORTER_STATE_DIR` is unset, as an empty XDG variable is, and a trailing `/`
134
+ * is trimmed, so both sides name one root by one string.
135
+ *
136
+ * @param env - The environment; `process.env` in production.
137
+ * @param home - The account's home as spelled; `HOME`, else the account's.
138
+ * @returns The state root.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * porterStateRoot_resolve({ XDG_STATE_HOME: '/state' }); // '/state/porter'
143
+ * porterStateRoot_resolve({ PORTER_STATE_DIR: '/srv/porter/' }); // '/srv/porter'
144
+ * ```
145
+ */
146
+ export declare function porterStateRoot_resolve(env?: NodeJS.ProcessEnv, home?: string): string;
147
+ /**
148
+ * A porter session's runtime folder: `<root>/<session>/run`, where its calypso writes its berth.
149
+ *
150
+ * @param root - The porter state root.
151
+ * @param session - The session's folder under it: its identity's `berthKey_compute`.
152
+ * @returns The runtime folder.
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * porterSessionRuntime_path('/srv/porter', berthKey_compute(identity)); // '/srv/porter/<key>/run'
157
+ * ```
158
+ */
159
+ export declare function porterSessionRuntime_path(root: string, session: string): string;
160
+ /**
161
+ * The folder a daemon started with a runtime folder keeps its berth and closing files in.
162
+ *
163
+ * @param runtimeDir - The runtime folder.
164
+ * @returns `<runtimeDir>/calypso`.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * berthFolder_pathIn('/run/mise'); // '/run/mise/calypso'
169
+ * ```
170
+ */
171
+ export declare function berthFolder_pathIn(runtimeDir: string): string;
109
172
  /**
110
173
  * The state directories a porter on this machine keeps its sessions under,
111
174
  * in the order looked: the porter's own setting, the user's state directory
@@ -122,6 +185,20 @@ export declare function porterStateRoots_get(): string[];
122
185
  * @returns The candidate paths.
123
186
  */
124
187
  export declare function berthPaths_list(identity: string): string[];
188
+ /**
189
+ * Reads a berth record held to this account: its folder through a trusted path, owner-only, never made by a
190
+ * reader; the record a regular 0600 file of this account's, bounded. A missing folder or record is no berth; one
191
+ * refused is said once (its path and why) and is no berth either.
192
+ *
193
+ * @param path - The record.
194
+ * @returns The berth, or null.
195
+ *
196
+ * @example
197
+ * ```ts
198
+ * const berth: Berth | null = berthRecord_read(berth_path(identity));
199
+ * ```
200
+ */
201
+ export declare function berthRecord_read(path: string): Berth | null;
125
202
  /**
126
203
  * Reads every advertised berth in the berth directory.
127
204
  *
@@ -129,31 +206,174 @@ export declare function berthPaths_list(identity: string): string[];
129
206
  * or holds none.
130
207
  */
131
208
  export declare function berthAll_read(): Berth[];
209
+ /** A berth and the file it was read from. */
210
+ export interface LocatedBerth {
211
+ /** The berth. */
212
+ readonly berth: Berth;
213
+ /** The record that holds it: this runtime's, or a porter session's. */
214
+ readonly path: string;
215
+ }
132
216
  /**
133
- * Removes an identity's berth file if present (used to reap a berth whose
134
- * daemon a liveness probe found dead).
217
+ * Reads every advertised berth with the file each was read from.
135
218
  *
136
- * @param identity - A normalised identity from {@link identity_normalise}.
219
+ * A berth is found in this runtime's directory or in a porter session's,
220
+ * so the file is not something an identity alone gives back: a listing
221
+ * that must name where a berth's token is kept names this path.
222
+ *
223
+ * @returns All well-formed berths, one per identity, each with its record's path.
137
224
  */
138
- export declare function berth_remove(identity: string): void;
225
+ export declare function berthAllLocated_read(): LocatedBerth[];
139
226
  /**
140
- * Reports whether something is listening at a berth's WebSocket address, by a
141
- * plain TCP connect — no WebSocket handshake, so this stays within the daemon
142
- * package (which has no client). It is the liveness check `daemon_launch` uses
143
- * to refuse starting a rival for an identity that is already hosted; a surface's
144
- * resolver uses a stronger handshake probe for attach.
227
+ * Reads every well-formed berth in one folder, held to this account first (`ownFolder_settle`); a refused
228
+ * folder, a folder that cannot be listed, and a refused record are each said once and passed over.
229
+ *
230
+ * @param dir - The folder.
231
+ * @returns Its berths, each with its file (by the folder's resolved path).
232
+ *
233
+ * @example
234
+ * ```ts
235
+ * const found: LocatedBerth[] = berthFolder_read(join(runtime, 'calypso'));
236
+ * ```
237
+ */
238
+ export declare function berthFolder_read(dir: string): LocatedBerth[];
239
+ /**
240
+ * What a probe learnt of a berth's daemon.
241
+ *
242
+ * @example
243
+ * ```ts
244
+ * const liveness: BerthLiveness = await berthInstance_probe(berth);
245
+ * ```
246
+ */
247
+ export type BerthLiveness =
248
+ /** The recorded instance answered with its proof. */
249
+ 'live'
250
+ /** Nothing of it is there: a refused connection, or (for a keyed record) an answer that is not its proof. */
251
+ | 'dead'
252
+ /** A record of an earlier release, with no key to prove by, whose address did not refuse: it may be running. */
253
+ | 'unverified';
254
+ /**
255
+ * A fresh key for this launch's instance proof.
256
+ *
257
+ * @returns 32 random bytes, lowercase hex.
258
+ *
259
+ * @example
260
+ * ```ts
261
+ * const berth: Berth = { ...facts, probeKey: probeKey_generate() };
262
+ * ```
263
+ */
264
+ export declare function probeKey_generate(): string;
265
+ /**
266
+ * The facts of one running daemon a proof is made over.
267
+ *
268
+ * @example
269
+ * ```ts
270
+ * const facts: InstanceFacts = { probeKey, identity, pid: process.pid, booted };
271
+ * ```
272
+ */
273
+ export interface InstanceFacts {
274
+ /** The launch's probe key, hex. */
275
+ probeKey: string;
276
+ /** The identity it serves. */
277
+ identity: string;
278
+ /** Its process id. */
279
+ pid: number;
280
+ /** When it booted, ISO. */
281
+ booted: string;
282
+ }
283
+ /**
284
+ * The proof that a daemon is the instance a record names: HMAC-SHA256 under the launch's probe key over the label,
285
+ * the nonce, the identity, the pid and the boot time, one per line. Neither the key nor the token travels.
286
+ *
287
+ * @param facts - The instance's facts.
288
+ * @param nonce - The probe's nonce.
289
+ * @returns The proof, hex.
290
+ *
291
+ * @example
292
+ * ```ts
293
+ * const proof: string = instanceProof_compute(facts, nonce);
294
+ * ```
295
+ */
296
+ export declare function instanceProof_compute(facts: InstanceFacts, nonce: string): string;
297
+ /**
298
+ * A berth address: what a connection is made to, and the origin a probe is asked at.
299
+ *
300
+ * @example
301
+ * ```ts
302
+ * const target: BerthTarget | null = berthUrl_target(berth.url);
303
+ * ```
304
+ */
305
+ export interface BerthTarget {
306
+ /** The host as `net.connect` takes it (an IPv6 address without brackets). */
307
+ host: string;
308
+ /** The port, a scheme's default filled in. */
309
+ port: number;
310
+ /** `ws:` or `wss:`. */
311
+ secure: boolean;
312
+ /** The `http(s)://host[:port]` origin the instance route is asked at; nothing else of the URL goes. */
313
+ origin: string;
314
+ }
315
+ /** How a plain connection to an address went. */
316
+ export type ConnectOutcome = 'accepted' | 'refused' | 'inconclusive';
317
+ /**
318
+ * A berth URL's address: a `ws:` or `wss:` URL with a host and no credentials, its scheme's default port filled
319
+ * in. Anything else names no daemon a berth could record.
320
+ *
321
+ * @param url - The URL.
322
+ * @returns The address, or null.
323
+ *
324
+ * @example
325
+ * ```ts
326
+ * berthUrl_target('ws://[::1]:4000'); // { host: '::1', port: 4000, secure: false, origin: 'http://[::1]:4000' }
327
+ * ```
328
+ */
329
+ export declare function berthUrl_target(url: string): BerthTarget | null;
330
+ /**
331
+ * Connects to a berth's address and says how it went, no handshake, within one deadline. Only a refusal means
332
+ * nothing is there; a timeout, a name that does not resolve, an address that names no daemon, or any other failure
333
+ * is inconclusive.
145
334
  *
146
335
  * @param url - A `ws://host:port` berth URL.
147
- * @param timeoutMs - How long to wait for the TCP connect (default 500 ms).
148
- * @returns True when the port accepts a connection.
336
+ * @param timeoutMs - The deadline for the whole attempt.
337
+ * @returns How it went.
338
+ *
339
+ * @example
340
+ * ```ts
341
+ * if ((await berthUrl_connect(berth.url)) === 'refused') startHere();
342
+ * ```
149
343
  */
150
- export declare function berthUrl_isAlive(url: string, timeoutMs?: number): Promise<boolean>;
344
+ export declare function berthUrl_connect(url: string, timeoutMs?: number): Promise<ConnectOutcome>;
151
345
  /**
152
- * A probe that reports whether a berth's daemon is actually reachable. The
153
- * surface supplies one backed by its attach client; the local resolver uses it
154
- * to reap dead berths on read.
346
+ * Whether a berth's recorded daemon is running. A keyed record is live only when its address answers a fresh nonce
347
+ * with the proof the record's key gives for that instance (identity, pid, boot time); anything else is dead. An
348
+ * earlier release's record has no key: a refused connection means it is gone, anything else leaves it unverified
349
+ * (never grounds to start beside it or adopt it).
350
+ *
351
+ * @param berth - The record.
352
+ * @returns What was learnt.
353
+ *
354
+ * @example
355
+ * ```ts
356
+ * if ((await berthInstance_probe(berth)) === 'live') attach(berth);
357
+ * ```
155
358
  */
156
- export type BerthLivenessProbe = (berth: Berth) => Promise<boolean>;
359
+ export declare function berthInstance_probe(berth: Berth): Promise<BerthLiveness>;
360
+ /**
361
+ * A probe that says whether a berth's daemon is running. The local resolver uses one to pass over a record whose
362
+ * daemon has gone; a test supplies a double.
363
+ */
364
+ export type BerthLivenessProbe = (berth: Berth) => Promise<BerthLiveness>;
365
+ /**
366
+ * A berth, the record it was read from, and what a probe learnt of it.
367
+ *
368
+ * @example
369
+ * ```ts
370
+ * for (const { berth, liveness } of await resolver.probed_list()) say(berth.identity, liveness);
371
+ * ```
372
+ */
373
+ export interface ProbedBerth extends LocatedBerth {
374
+ /** What the probe learnt. */
375
+ readonly liveness: BerthLiveness;
376
+ }
157
377
  /**
158
378
  * The berth lookup seam. Tier 1 ships {@link LocalBerthResolver} over the local
159
379
  * files; a future tier-2 `PorterBerthResolver` will implement the same contract
@@ -170,27 +390,45 @@ export interface BerthResolver {
170
390
  /**
171
391
  * Lists every live berth (for a bare `--remote` with several daemons).
172
392
  *
173
- * @returns The live berths, dead ones reaped.
393
+ * @returns The live berths.
174
394
  */
175
395
  list(): Promise<Berth[]>;
176
396
  }
177
397
  /**
178
- * The tier-1 resolver: reads identity-keyed berth files and, when given a
179
- * liveness probe, reaps any berth whose daemon has gone (passive cleanup — the
180
- * next read of a stale berth removes it). Without a probe it returns berths as
181
- * recorded, trusting the caller's own attach to surface a dead one.
398
+ * The tier-1 resolver: reads identity-keyed berth records and, given a probe, walks every record of an identity in
399
+ * order (this runtime's, then each porter session's), probing each before one is chosen, so a dead record never
400
+ * hides a live one behind it. Nothing is removed: a dead record is passed over and the next daemon of its identity
401
+ * replaces it. Without a probe it returns records as written, trusting the caller's own attach to find a dead one.
182
402
  */
183
403
  export declare class LocalBerthResolver implements BerthResolver {
184
404
  private readonly liveness_probe?;
185
405
  /**
186
- * @param liveness_probe - Optional reachability probe; when present, dead
187
- * berths are reaped and never returned.
406
+ * @param liveness_probe - Optional probe; when present, only live berths are returned.
188
407
  */
189
408
  constructor(liveness_probe?: BerthLivenessProbe | undefined);
190
409
  /** @inheritdoc */
191
410
  resolve(identity: string): Promise<Berth | null>;
192
411
  /** @inheritdoc */
193
412
  list(): Promise<Berth[]>;
413
+ /**
414
+ * Every live berth with the record it was read from, one per identity.
415
+ *
416
+ * @returns The berths and their files.
417
+ */
418
+ listLocated(): Promise<LocatedBerth[]>;
419
+ /**
420
+ * Every record with what a probe learnt of it, one per identity: the first live record of each identity, else
421
+ * its first unverified one (an earlier release's daemon that may still run), else none. Without a probe, the
422
+ * first record of each identity, as written, counted live.
423
+ *
424
+ * @returns The probed berths.
425
+ *
426
+ * @example
427
+ * ```ts
428
+ * const rows: ProbedBerth[] = await new LocalBerthResolver(berthInstance_probe).probed_list();
429
+ * ```
430
+ */
431
+ probed_list(): Promise<ProbedBerth[]>;
194
432
  }
195
433
  /**
196
434
  * Where a host leaves the reason it is ending an identity's daemon: beside
@@ -208,13 +446,14 @@ export declare function closing_pathIn(runtimeDir: string, identity: string): st
208
446
  * @param runtimeDir - The daemon's runtime directory.
209
447
  * @param identity - The normalised identity.
210
448
  * @param cause - Why: `restart` or `end`.
449
+ * @throws {Error} When the folder is not this account's own, or a note that is not stands at the name.
211
450
  */
212
451
  export declare function closing_write(runtimeDir: string, identity: string, cause: ClosingCause): void;
213
452
  /**
214
- * Takes the reason a host left for this daemon's ending, removing it.
453
+ * Takes the reason a host left for this daemon's ending: renamed aside and read once, never put back.
215
454
  *
216
455
  * @param identity - The daemon's normalised identity.
217
- * @param runtimeDir - Its runtime directory; this process's by default.
218
- * @returns The cause, or null when none was left (or it is stale).
456
+ * @param runtimeDir - Its runtime directory; by default this process's berth folder's.
457
+ * @returns The cause, or null when none was left (or it is stale, or refused).
219
458
  */
220
459
  export declare function closing_take(identity: string, runtimeDir?: string): ClosingCause | null;