@cortexkit/subc-client 0.16.1 → 0.18.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.
- package/README.md +35 -0
- package/dist/client.d.ts +36 -8
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +269 -46
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/launch-nonce.d.ts +173 -0
- package/dist/launch-nonce.d.ts.map +1 -0
- package/dist/launch-nonce.js +334 -0
- package/dist/launch-nonce.js.map +1 -0
- package/dist/provider.d.ts +41 -4
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +69 -4
- package/dist/provider.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +303 -52
- package/src/index.ts +13 -0
- package/src/launch-nonce.ts +447 -0
- package/src/provider.ts +109 -8
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The launch nonce: the secret the daemon gives each module it spawns, which
|
|
3
|
+
* the module presents to be admitted as itself.
|
|
4
|
+
*
|
|
5
|
+
* On macOS and Linux the daemon hands it over through a pipe rather than the
|
|
6
|
+
* environment, because any process of the same user can read another
|
|
7
|
+
* process's initial environment (`ps eww`). The pipe's read end is descriptor
|
|
8
|
+
* 3 in the module and `SUBC_LAUNCH_NONCE_FD` names it as `<fd>:<inode>`.
|
|
9
|
+
* {@link launchNonce} reads that descriptor once, closes it, and caches the
|
|
10
|
+
* value for the life of the process. While modules move over, the daemon also
|
|
11
|
+
* keeps setting the environment copy (`SUBC_LAUNCH_NONCE`), which
|
|
12
|
+
* {@link launchNonce} reads when no descriptor is named. Windows has no
|
|
13
|
+
* descriptor handoff, so there only the environment copy is read.
|
|
14
|
+
*
|
|
15
|
+
* This mirrors the Rust accessor in `subc-os` (`subc_os::launch_nonce`): the
|
|
16
|
+
* same checks in the same order, the same error names and messages.
|
|
17
|
+
*/
|
|
18
|
+
import { closeSync, fstatSync, readSync } from "node:fs";
|
|
19
|
+
/** The environment copy of the nonce, kept only while modules move to the descriptor. */
|
|
20
|
+
export const SUBC_LAUNCH_NONCE_ENV = "SUBC_LAUNCH_NONCE";
|
|
21
|
+
/**
|
|
22
|
+
* Names the descriptor holding the nonce, as `<fd>:<inode>`. The inode names
|
|
23
|
+
* the pipe itself, so the reader can tell it from an unrelated descriptor that
|
|
24
|
+
* happens to have the same number. A process a module spawns inherits this
|
|
25
|
+
* variable but not the pipe, and without the inode it would read and close
|
|
26
|
+
* whatever that process has at the number.
|
|
27
|
+
*/
|
|
28
|
+
export const SUBC_LAUNCH_NONCE_FD_ENV = "SUBC_LAUNCH_NONCE_FD";
|
|
29
|
+
/** The descriptor number the daemon gives the pipe's read end in the module. */
|
|
30
|
+
export const LAUNCH_NONCE_FD = 3;
|
|
31
|
+
// This file sticks to syntax Node can strip without transforming (no
|
|
32
|
+
// constructor parameter properties, no enums), so tests can run it directly
|
|
33
|
+
// under Node as well as Bun.
|
|
34
|
+
export class LaunchNonceError extends Error {
|
|
35
|
+
name = "LaunchNonceError";
|
|
36
|
+
kind;
|
|
37
|
+
fd;
|
|
38
|
+
errno;
|
|
39
|
+
value;
|
|
40
|
+
expectedInode;
|
|
41
|
+
foundInode;
|
|
42
|
+
constructor(kind, message, details = {}) {
|
|
43
|
+
super(message);
|
|
44
|
+
this.kind = kind;
|
|
45
|
+
this.fd = details.fd;
|
|
46
|
+
this.errno = details.errno;
|
|
47
|
+
this.value = details.value;
|
|
48
|
+
this.expectedInode = details.expectedInode;
|
|
49
|
+
this.foundInode = details.foundInode;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Whether `error` is a {@link LaunchNonceError}, including one thrown by another
|
|
54
|
+
* copy of this package sharing the process-wide cache, which `instanceof`
|
|
55
|
+
* would not recognise.
|
|
56
|
+
*/
|
|
57
|
+
export function isLaunchNonceError(error) {
|
|
58
|
+
return (error instanceof Error &&
|
|
59
|
+
error.name === "LaunchNonceError" &&
|
|
60
|
+
typeof error.kind === "string");
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* This process's launch nonce and where it came from, or `undefined` when
|
|
64
|
+
* neither variable is set (or the environment copy is empty): the process was
|
|
65
|
+
* not started by the daemon. Throws the cached {@link LaunchNonceError} when a
|
|
66
|
+
* named descriptor could not be taken.
|
|
67
|
+
*
|
|
68
|
+
* The first call decides, and every later call returns the same answer
|
|
69
|
+
* without touching the descriptor or the environment again. So every reader
|
|
70
|
+
* in a process must come through here: after the first read closes the
|
|
71
|
+
* descriptor, its number is the next one the process hands out, and a second
|
|
72
|
+
* independent reader would read and close some unrelated socket or file. The
|
|
73
|
+
* cache is shared with every other copy of this package loaded in the same
|
|
74
|
+
* JavaScript realm (see {@link PROCESS_CELL_KEY}); a worker thread is its own
|
|
75
|
+
* realm and has its own cache, so read it on the main thread.
|
|
76
|
+
*
|
|
77
|
+
* - When `SUBC_LAUNCH_NONCE_FD` is set (not on Windows), the descriptor it
|
|
78
|
+
* names is taken only if it is a pipe with the named inode and holds bytes;
|
|
79
|
+
* it is then read to end of file and closed. Anything else throws and leaves
|
|
80
|
+
* the descriptor as it was, and never falls back to the environment.
|
|
81
|
+
* - Otherwise the value of `SUBC_LAUNCH_NONCE` is used.
|
|
82
|
+
*
|
|
83
|
+
* It never changes `process.env`. Removing either variable would break any
|
|
84
|
+
* other reader in the process still on the environment copy.
|
|
85
|
+
*
|
|
86
|
+
* Call it before the process spawns anything. Until the first read the
|
|
87
|
+
* descriptor is inheritable (it has to be, to survive the daemon's exec), so a
|
|
88
|
+
* child spawned earlier would inherit the pipe.
|
|
89
|
+
*
|
|
90
|
+
* It assumes the write end of the pipe was closed before this process started,
|
|
91
|
+
* as the daemon's handoff does. Node and Bun cannot ask how many bytes a pipe
|
|
92
|
+
* holds without reading it (the Rust accessor uses the FIONREAD ioctl), so the
|
|
93
|
+
* emptiness check is a first read: at end of file it returns no bytes and
|
|
94
|
+
* consumes nothing. If some other process still held the write end open, an
|
|
95
|
+
* empty pipe would block that read instead of reporting `Empty`.
|
|
96
|
+
*/
|
|
97
|
+
export function launchNonce() {
|
|
98
|
+
return unwrap(processCell().result());
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* {@link launchNonce} without the throw: `undefined` for no nonce and for a
|
|
102
|
+
* refused descriptor alike. For readers that treat a refusal as "no
|
|
103
|
+
* identity", such as the consumer's route open.
|
|
104
|
+
*/
|
|
105
|
+
export function launchNonceOrUndefined() {
|
|
106
|
+
const result = processCell().result();
|
|
107
|
+
return result.ok ? result.nonce ?? undefined : undefined;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Where the process-wide cell lives. A registry symbol rather than a module
|
|
111
|
+
* variable, because a module's dependencies often install two copies of this
|
|
112
|
+
* package. With a cache per copy, the second copy would look at the
|
|
113
|
+
* descriptor after the first had closed it, refuse, and so fail to register
|
|
114
|
+
* the module with the daemon.
|
|
115
|
+
*/
|
|
116
|
+
const PROCESS_CELL_KEY = Symbol.for("@cortexkit/subc-client/launch-nonce/v1");
|
|
117
|
+
function processCell() {
|
|
118
|
+
const global = globalThis;
|
|
119
|
+
let cell = global[PROCESS_CELL_KEY];
|
|
120
|
+
if (cell === undefined) {
|
|
121
|
+
cell = new LaunchNonceCell((key) => process.env[key]);
|
|
122
|
+
global[PROCESS_CELL_KEY] = cell;
|
|
123
|
+
}
|
|
124
|
+
return cell;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Forgets the process-wide answer, so the next {@link launchNonce} reads again.
|
|
128
|
+
* For tests that change the environment between cases; never for modules,
|
|
129
|
+
* where a second read is exactly what the cache exists to prevent.
|
|
130
|
+
*/
|
|
131
|
+
export function resetLaunchNonceForTests() {
|
|
132
|
+
delete globalThis[PROCESS_CELL_KEY];
|
|
133
|
+
}
|
|
134
|
+
function unwrap(result) {
|
|
135
|
+
if (!result.ok)
|
|
136
|
+
throw result.error;
|
|
137
|
+
return result.nonce ?? undefined;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* A launch nonce read at most once. The process has one, behind
|
|
141
|
+
* {@link launchNonce}; tests make their own with a stand-in for the
|
|
142
|
+
* environment, the platform, and fstat.
|
|
143
|
+
*/
|
|
144
|
+
export class LaunchNonceCell {
|
|
145
|
+
cached;
|
|
146
|
+
/** How many times this cell has taken a descriptor. At most one. */
|
|
147
|
+
descriptorReads = 0;
|
|
148
|
+
lookup;
|
|
149
|
+
platform;
|
|
150
|
+
stat;
|
|
151
|
+
constructor(lookup, platform = process.platform, stat = (fd) => fstatSync(fd, { bigint: true })) {
|
|
152
|
+
this.lookup = lookup;
|
|
153
|
+
this.platform = platform;
|
|
154
|
+
this.stat = stat;
|
|
155
|
+
}
|
|
156
|
+
result() {
|
|
157
|
+
if (this.cached === undefined)
|
|
158
|
+
this.cached = this.read();
|
|
159
|
+
return this.cached;
|
|
160
|
+
}
|
|
161
|
+
/** The cached value, reading it first if no caller has yet; throws a refusal. */
|
|
162
|
+
get() {
|
|
163
|
+
return unwrap(this.result());
|
|
164
|
+
}
|
|
165
|
+
read() {
|
|
166
|
+
if (this.platform !== "win32") {
|
|
167
|
+
const named = this.lookup(SUBC_LAUNCH_NONCE_FD_ENV);
|
|
168
|
+
if (named !== undefined) {
|
|
169
|
+
try {
|
|
170
|
+
return { ok: true, nonce: this.readDescriptor(named) };
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
if (error instanceof LaunchNonceError)
|
|
174
|
+
return { ok: false, error };
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const value = this.lookup(SUBC_LAUNCH_NONCE_ENV);
|
|
180
|
+
return { ok: true, nonce: value ? makeLaunchNonce(value, "env") : null };
|
|
181
|
+
}
|
|
182
|
+
readDescriptor(text) {
|
|
183
|
+
const { fd, expectedInode } = parseFdValue(text);
|
|
184
|
+
// Check what the descriptor is before taking ownership of it. Reading and
|
|
185
|
+
// closing a descriptor that belongs to other code in this process would
|
|
186
|
+
// break that code, and a process that inherited the variable without the
|
|
187
|
+
// descriptor may well have something else at this number.
|
|
188
|
+
let stat;
|
|
189
|
+
try {
|
|
190
|
+
stat = this.stat(fd);
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
const errno = errnoOf(error) ?? 0;
|
|
194
|
+
throw new LaunchNonceError("NotOpen", `${SUBC_LAUNCH_NONCE_FD_ENV} names descriptor ${fd}, which is not open (errno ${errno}); ` +
|
|
195
|
+
"a process spawned by a module inherits the variable but not the descriptor", { fd, errno });
|
|
196
|
+
}
|
|
197
|
+
if (!stat.isFIFO()) {
|
|
198
|
+
throw new LaunchNonceError("NotAPipe", `${SUBC_LAUNCH_NONCE_FD_ENV} names descriptor ${fd}, which is not a pipe; left it untouched`, { fd });
|
|
199
|
+
}
|
|
200
|
+
// Node reports st_ino as a signed 64-bit value, and macOS pipe inodes use
|
|
201
|
+
// the top bit, so they come back negative. The variable carries the
|
|
202
|
+
// unsigned value (the Rust daemon writes `st_ino as u64`).
|
|
203
|
+
const foundInode = BigInt.asUintN(64, stat.ino);
|
|
204
|
+
if (foundInode !== expectedInode) {
|
|
205
|
+
throw new LaunchNonceError("WrongPipe", `${SUBC_LAUNCH_NONCE_FD_ENV} names descriptor ${fd} with inode ${expectedInode}, but it has ` +
|
|
206
|
+
`inode ${foundInode}; left it untouched`, { fd, expectedInode, foundInode });
|
|
207
|
+
}
|
|
208
|
+
// Node and Bun have no FIONREAD (the ioctl the Rust accessor uses to count
|
|
209
|
+
// the waiting bytes without reading them), so the first read is the
|
|
210
|
+
// emptiness check. With the write end closed, as the daemon leaves it, an
|
|
211
|
+
// empty pipe answers end of file: zero bytes, nothing consumed, and the
|
|
212
|
+
// descriptor stays open. A non-blocking descriptor with a writer still
|
|
213
|
+
// open answers EAGAIN, which likewise consumed nothing. Do not replace
|
|
214
|
+
// this with fstat's size: macOS reports the waiting byte count there for
|
|
215
|
+
// an anonymous pipe, but 0 for a mkfifo pipe, and Linux reports 0 for
|
|
216
|
+
// every pipe.
|
|
217
|
+
const chunk = Buffer.alloc(256);
|
|
218
|
+
let got;
|
|
219
|
+
try {
|
|
220
|
+
got = readSync(fd, chunk, 0, chunk.length, null);
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
if (isWouldBlock(error))
|
|
224
|
+
throw emptyError(fd);
|
|
225
|
+
throw unreadableError(fd, errnoOf(error));
|
|
226
|
+
}
|
|
227
|
+
if (got === 0)
|
|
228
|
+
throw emptyError(fd);
|
|
229
|
+
// From here the descriptor is this process's to consume: it is the pipe
|
|
230
|
+
// the daemon named by inode, and every reader goes through this one cell,
|
|
231
|
+
// which reaches this line at most once.
|
|
232
|
+
this.descriptorReads += 1;
|
|
233
|
+
const parts = [Buffer.from(chunk.subarray(0, got))];
|
|
234
|
+
try {
|
|
235
|
+
for (;;) {
|
|
236
|
+
const n = readSync(fd, chunk, 0, chunk.length, null);
|
|
237
|
+
if (n === 0)
|
|
238
|
+
break;
|
|
239
|
+
parts.push(Buffer.from(chunk.subarray(0, n)));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
throw unreadableError(fd, errnoOf(error));
|
|
244
|
+
}
|
|
245
|
+
finally {
|
|
246
|
+
closeQuietly(fd);
|
|
247
|
+
}
|
|
248
|
+
let value;
|
|
249
|
+
try {
|
|
250
|
+
value = new TextDecoder("utf-8", { fatal: true }).decode(Buffer.concat(parts));
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
throw new LaunchNonceError("NotUtf8", `the launch nonce pipe at descriptor ${fd} held bytes that are not UTF-8`, { fd });
|
|
254
|
+
}
|
|
255
|
+
return makeLaunchNonce(value, "fd");
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const U64_MAX = (1n << 64n) - 1n;
|
|
259
|
+
const I32_MAX = 2 ** 31 - 1;
|
|
260
|
+
/**
|
|
261
|
+
* Parse `<fd>:<inode>` exactly as the Rust accessor does: split at the first
|
|
262
|
+
* colon; the descriptor is decimal with an optional `+` or `-` sign and must
|
|
263
|
+
* fit a signed 32-bit integer and not be negative; the inode is decimal with
|
|
264
|
+
* an optional `+` and must fit an unsigned 64-bit integer.
|
|
265
|
+
*/
|
|
266
|
+
function parseFdValue(text) {
|
|
267
|
+
const malformed = () => new LaunchNonceError("Malformed", `${SUBC_LAUNCH_NONCE_FD_ENV}=${JSON.stringify(text)} is not <fd>:<inode>`, { value: text });
|
|
268
|
+
const colon = text.indexOf(":");
|
|
269
|
+
if (colon < 0)
|
|
270
|
+
throw malformed();
|
|
271
|
+
const fdText = text.slice(0, colon);
|
|
272
|
+
const inodeText = text.slice(colon + 1);
|
|
273
|
+
if (!/^[+-]?\d+$/.test(fdText) || !/^\+?\d+$/.test(inodeText))
|
|
274
|
+
throw malformed();
|
|
275
|
+
const fdBig = BigInt(fdText);
|
|
276
|
+
if (fdBig < 0n || fdBig > BigInt(I32_MAX))
|
|
277
|
+
throw malformed();
|
|
278
|
+
const expectedInode = BigInt(inodeText);
|
|
279
|
+
if (expectedInode > U64_MAX)
|
|
280
|
+
throw malformed();
|
|
281
|
+
return { fd: Number(fdBig), expectedInode };
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Holds the value in a private field behind a getter, so logging, inspecting
|
|
285
|
+
* or serialising the object does not print the secret; the Rust type's Debug
|
|
286
|
+
* output redacts it the same way.
|
|
287
|
+
*/
|
|
288
|
+
class RedactedLaunchNonce {
|
|
289
|
+
source;
|
|
290
|
+
#value;
|
|
291
|
+
constructor(value, source) {
|
|
292
|
+
this.#value = value;
|
|
293
|
+
this.source = source;
|
|
294
|
+
Object.freeze(this);
|
|
295
|
+
}
|
|
296
|
+
get value() {
|
|
297
|
+
return this.#value;
|
|
298
|
+
}
|
|
299
|
+
toJSON() {
|
|
300
|
+
return { source: this.source };
|
|
301
|
+
}
|
|
302
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
303
|
+
return `LaunchNonce { value: <${this.#value.length} bytes redacted>, source: "${this.source}" }`;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
function makeLaunchNonce(value, source) {
|
|
307
|
+
return new RedactedLaunchNonce(value, source);
|
|
308
|
+
}
|
|
309
|
+
function emptyError(fd) {
|
|
310
|
+
return new LaunchNonceError("Empty", `the launch nonce pipe at descriptor ${fd} is empty; left it untouched`, { fd });
|
|
311
|
+
}
|
|
312
|
+
function unreadableError(fd, errno) {
|
|
313
|
+
// `Some(n)` / `None` is how the Rust message prints an optional errno.
|
|
314
|
+
const shown = errno === undefined ? "None" : `Some(${errno})`;
|
|
315
|
+
return new LaunchNonceError("Unreadable", `could not read the launch nonce from descriptor ${fd} (errno ${shown})`, { fd, errno });
|
|
316
|
+
}
|
|
317
|
+
function isWouldBlock(error) {
|
|
318
|
+
const code = error?.code;
|
|
319
|
+
return code === "EAGAIN" || code === "EWOULDBLOCK";
|
|
320
|
+
}
|
|
321
|
+
/** Node and Bun report errno negated (libuv style); the Rust errors carry it positive. */
|
|
322
|
+
function errnoOf(error) {
|
|
323
|
+
const errno = error?.errno;
|
|
324
|
+
return typeof errno === "number" ? Math.abs(errno) : undefined;
|
|
325
|
+
}
|
|
326
|
+
function closeQuietly(fd) {
|
|
327
|
+
try {
|
|
328
|
+
closeSync(fd);
|
|
329
|
+
}
|
|
330
|
+
catch {
|
|
331
|
+
// Nothing useful can be done if closing the consumed pipe fails.
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
//# sourceMappingURL=launch-nonce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launch-nonce.js","sourceRoot":"","sources":["../src/launch-nonce.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAoB,MAAM,SAAS,CAAC;AAE3E,yFAA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,KAAK,GAAG,EACxE,EAAE,EAAE,EAAE,KAAK,EAAE,CACd,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,MAAM,IAAI,GAAI,KAAmC,EAAE,IAAI,CAAC;IACxD,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,aAAa,CAAC;AACrD,CAAC;AAED,0FAA0F;AAC1F,SAAS,OAAO,CAAC,KAAc;IAC7B,MAAM,KAAK,GAAI,KAAoC,EAAE,KAAK,CAAC;IAC3D,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACjE,CAAC;AAED,SAAS,YAAY,CAAC,EAAU;IAC9B,IAAI,CAAC;QACH,SAAS,CAAC,EAAE,CAAC,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACP,iEAAiE;IACnE,CAAC;AACH,CAAC"}
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type BindIdentity, type ReconnectBackoff, type RequestOptions, type RouteTarget, type SubcCallErrorKind } from "./client.js";
|
|
2
2
|
import { type ConnectionInfo } from "./connection-file.js";
|
|
3
3
|
import { AdmissionClass, Priority } from "./envelope.js";
|
|
4
|
+
import { type LaunchNonceSource } from "./launch-nonce.js";
|
|
4
5
|
import { RouteHandle } from "./route-handle.js";
|
|
5
6
|
export declare const HELLO_CORR = 1n;
|
|
6
7
|
export type TrustTier = "first_party" | "reviewed" | "untrusted";
|
|
@@ -27,6 +28,34 @@ export interface ManifestInput {
|
|
|
27
28
|
provides: ProviderRoleInput[];
|
|
28
29
|
consumes: ConsumerRoleInput[];
|
|
29
30
|
bindings: BindingsInput;
|
|
31
|
+
/**
|
|
32
|
+
* Facts about the running build, sent in HELLO only when declared. When it is
|
|
33
|
+
* declared without `launch_nonce_source`, the provider fills that field in
|
|
34
|
+
* from the launch nonce it sends.
|
|
35
|
+
*/
|
|
36
|
+
provenance?: ManifestProvenance;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Build provenance a module declares in its manifest; mirrors
|
|
40
|
+
* `ManifestProvenance` in subc-protocol. Every field is optional and is left
|
|
41
|
+
* off the wire when unset. Omit a field you cannot know rather than sending a
|
|
42
|
+
* placeholder such as "unknown".
|
|
43
|
+
*/
|
|
44
|
+
export interface ManifestProvenance {
|
|
45
|
+
build_git_sha?: string;
|
|
46
|
+
/** Why `build_git_sha` is unavailable; an open set of reasons. */
|
|
47
|
+
build_git_sha_absence_reason?: string;
|
|
48
|
+
build_lock_digest?: string;
|
|
49
|
+
/** The subc-protocol crate version this module's wire vocabulary matches. */
|
|
50
|
+
wire_crate_version?: string;
|
|
51
|
+
store_schema_version?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Where the running module read its launch nonce from: `fd` (the pipe the
|
|
54
|
+
* daemon hands over as descriptor 3) or `env` (the environment variable kept
|
|
55
|
+
* while modules move to the pipe). A fact about the running process, not
|
|
56
|
+
* the build. Filled in by the provider when left unset.
|
|
57
|
+
*/
|
|
58
|
+
launch_nonce_source?: LaunchNonceSource;
|
|
30
59
|
}
|
|
31
60
|
export type ProviderRoleInput = {
|
|
32
61
|
role: "tool_provider";
|
|
@@ -203,16 +232,19 @@ export interface SubcProviderConnectOptions {
|
|
|
203
232
|
onConnectionState?: (event: ProviderConnectionState) => void | Promise<void>;
|
|
204
233
|
/**
|
|
205
234
|
* The one-time launch nonce to echo in HELLO for a reserved module. Defaults to
|
|
206
|
-
* the
|
|
207
|
-
*
|
|
235
|
+
* the process's launch nonce (see `launchNonce`: the descriptor subc hands
|
|
236
|
+
* over, or the `SUBC_LAUNCH_NONCE` environment copy), and `connect()` rejects
|
|
237
|
+
* with code `launch_nonce_unavailable` when a named descriptor is refused.
|
|
238
|
+
* Pass explicitly to override. Omitted from the wire when empty
|
|
239
|
+
* (non-reserved modules).
|
|
208
240
|
*/
|
|
209
241
|
launchNonce?: string;
|
|
210
242
|
/**
|
|
211
243
|
* Whether an unexpected connection drop starts a reconnect-and-re-register
|
|
212
244
|
* cycle (`true`) or ends serving and resolves {@link SubcProvider.closed}
|
|
213
245
|
* (`false`). Defaults to `false` when the process runs under the daemon's
|
|
214
|
-
* supervision (
|
|
215
|
-
*
|
|
246
|
+
* supervision (`SUBC_MODULE_ID` is set and the process has a launch nonce,
|
|
247
|
+
* the pair the daemon injects at spawn), since
|
|
216
248
|
* the daemon owns a supervised module's restarts and waits for it to exit;
|
|
217
249
|
* `true` otherwise, so plugins and other self-connecting providers keep
|
|
218
250
|
* reconnecting. A daemon GOODBYE and `close()` end serving regardless.
|
|
@@ -362,4 +394,9 @@ export declare class SubcProvider {
|
|
|
362
394
|
private failFatal;
|
|
363
395
|
private finishClosed;
|
|
364
396
|
}
|
|
397
|
+
/**
|
|
398
|
+
* The manifest exactly as HELLO sends it. Exported for the conformance tests,
|
|
399
|
+
* not from the package entry.
|
|
400
|
+
*/
|
|
401
|
+
export declare function normalizeManifest(manifest: ManifestInput, sentNonce: string | undefined): ManifestInput;
|
|
365
402
|
//# sourceMappingURL=provider.d.ts.map
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAA2C,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACpG,OAAO,EACL,cAAc,EAMd,QAAQ,EAGT,MAAM,eAAe,CAAC;AACvB,OAAO,EAKL,KAAK,iBAAiB,EACvB,MAAM,mBAAmB,CAAC;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CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAWrC,8GAA8G;WACjG,OAAO,CAAC,IAAI,EAAE,0BAA0B,GAAG,OAAO,CAAC,YAAY,CAAC;IAavE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;mBAiBP,cAAc;YAoBrB,QAAQ;YAuBR,QAAQ;IAyEtB;;;;;;OAMG;IACH;;;;;;;OAOG;YACW,gBAAgB;YAShB,eAAe;IAS7B,OAAO,CAAC,WAAW;IAanB,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,gBAAgB;YAIV,oBAAoB;YA+GpB,iBAAiB;YAqGjB,mBAAmB;YA0CnB,SAAS;YA2BT,MAAM;IAKpB,OAAO,CAAC,oBAAoB;IAe5B,OAAO,CAAC,0BAA0B;YA6BpB,kBAAkB;IAgDhC,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,wBAAwB;IAIhC,OAAO,CAAC,qBAAqB;IAK7B,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,gBAAgB;IAuBxB,OAAO,CAAC,sBAAsB;IAI9B,OAAO,CAAC,sBAAsB;YAMhB,yBAAyB;IAmCvC,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,YAAY;IAYpB,OAAO,CAAC,SAAS;IASjB,OAAO,CAAC,YAAY;CAGrB;AAsMD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,aAAa,CA2BvG"}
|
package/dist/provider.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Buffer } from "node:buffer";
|
|
2
2
|
import { AuthError, authenticateClient } from "./auth.js";
|
|
3
|
-
import { DEFAULT_RECONNECT_BACKOFF, isEstablishedRouteDead,
|
|
3
|
+
import { DEFAULT_RECONNECT_BACKOFF, isEstablishedRouteDead, SUBC_MODULE_ID_ENV, } from "./client.js";
|
|
4
4
|
import { ConnectionFileError, readConnectionFile } from "./connection-file.js";
|
|
5
5
|
import { AdmissionClass, buildFlags, buildFrame, buildFrameWithVersion, encodeFrame, FrameType, Priority, PROTOCOL_VERSION, } from "./envelope.js";
|
|
6
|
+
import { isLaunchNonceError, launchNonce as processLaunchNonce, launchNonceOrUndefined, } from "./launch-nonce.js";
|
|
6
7
|
import { belongsToConnection, createRouteHandle, newConnectionToken, StaleRouteHandleError, } from "./route-handle.js";
|
|
7
8
|
import { SocketClosedError, SocketTimeoutError, SocketWriteNotQueuedError, SocketWriteQueuedError, SubcSocket, writeBorrowed, } from "./socket.js";
|
|
8
9
|
const DEFAULT_HANDSHAKE_TIMEOUT_MS = 10_000;
|
|
@@ -827,7 +828,25 @@ function normalizeProviderConnectOptions(opts) {
|
|
|
827
828
|
// spawns a module; together they mark the process as supervised, and the nonce
|
|
828
829
|
// is also what HELLO echoes for a reserved module_id.
|
|
829
830
|
const envModuleId = nonEmpty(process.env[SUBC_MODULE_ID_ENV]);
|
|
830
|
-
|
|
831
|
+
// The nonce comes from the process-wide accessor, which reads the daemon's
|
|
832
|
+
// descriptor at most once. A refused descriptor fails the connect, unless the
|
|
833
|
+
// caller supplied the nonce itself, in which case it only means "not
|
|
834
|
+
// supervised".
|
|
835
|
+
let processNonce;
|
|
836
|
+
if (opts.launchNonce === undefined) {
|
|
837
|
+
try {
|
|
838
|
+
processNonce = processLaunchNonce()?.value;
|
|
839
|
+
}
|
|
840
|
+
catch (error) {
|
|
841
|
+
if (isLaunchNonceError(error))
|
|
842
|
+
throw launchNonceUnavailable(error);
|
|
843
|
+
throw error;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
else {
|
|
847
|
+
processNonce = launchNonceOrUndefined()?.value;
|
|
848
|
+
}
|
|
849
|
+
const envLaunchNonce = nonEmpty(processNonce);
|
|
831
850
|
const supervised = envModuleId !== undefined && envLaunchNonce !== undefined;
|
|
832
851
|
return {
|
|
833
852
|
connectionFile: opts.connectionFile,
|
|
@@ -854,10 +873,20 @@ function normalizedControlOps(controlOps) {
|
|
|
854
873
|
merged.add(HEALTH_CHECK_OP);
|
|
855
874
|
return [...merged];
|
|
856
875
|
}
|
|
876
|
+
/**
|
|
877
|
+
* The typed HELLO failure for a refused launch-nonce descriptor. The message
|
|
878
|
+
* matches the Rust SDK's `SubcModuleError::LaunchNonce`; `detail.kind` and
|
|
879
|
+
* `cause` carry the accessor's error.
|
|
880
|
+
*/
|
|
881
|
+
function launchNonceUnavailable(error) {
|
|
882
|
+
const wrapped = new SubcProviderError(`launch nonce unavailable: ${error.message}`, "launch_nonce_unavailable", "terminal", { kind: error.kind });
|
|
883
|
+
wrapped.cause = error;
|
|
884
|
+
return wrapped;
|
|
885
|
+
}
|
|
857
886
|
function buildHelloFrame(opts) {
|
|
858
887
|
const nonce = opts.launchNonce;
|
|
859
888
|
return buildFrame(FrameType.Hello, controlFlags(), 0, 0, HELLO_CORR, encodeJson({
|
|
860
|
-
manifest: normalizeManifest(opts.manifest),
|
|
889
|
+
manifest: normalizeManifest(opts.manifest, nonce),
|
|
861
890
|
protocol_ver: PROTOCOL_VERSION,
|
|
862
891
|
control_ops: normalizedControlOps(opts.controlOps),
|
|
863
892
|
// Echo the one-time launch nonce subc injects for a reserved module
|
|
@@ -946,7 +975,11 @@ function bindRejection(decision) {
|
|
|
946
975
|
message: decision.message ?? "route.bind rejected by provider",
|
|
947
976
|
};
|
|
948
977
|
}
|
|
949
|
-
|
|
978
|
+
/**
|
|
979
|
+
* The manifest exactly as HELLO sends it. Exported for the conformance tests,
|
|
980
|
+
* not from the package entry.
|
|
981
|
+
*/
|
|
982
|
+
export function normalizeManifest(manifest, sentNonce) {
|
|
950
983
|
return {
|
|
951
984
|
module_id: manifest.module_id,
|
|
952
985
|
module_version: manifest.module_version,
|
|
@@ -969,8 +1002,40 @@ function normalizeManifest(manifest) {
|
|
|
969
1002
|
optional: [...manifest.bindings.identity.optional],
|
|
970
1003
|
},
|
|
971
1004
|
},
|
|
1005
|
+
...(manifest.provenance === undefined
|
|
1006
|
+
? {}
|
|
1007
|
+
: { provenance: normalizeProvenance(manifest.provenance, sentNonce) }),
|
|
972
1008
|
};
|
|
973
1009
|
}
|
|
1010
|
+
function normalizeProvenance(provenance, sentNonce) {
|
|
1011
|
+
const out = {};
|
|
1012
|
+
if (provenance.build_git_sha !== undefined)
|
|
1013
|
+
out.build_git_sha = provenance.build_git_sha;
|
|
1014
|
+
if (provenance.build_git_sha_absence_reason !== undefined) {
|
|
1015
|
+
out.build_git_sha_absence_reason = provenance.build_git_sha_absence_reason;
|
|
1016
|
+
}
|
|
1017
|
+
if (provenance.build_lock_digest !== undefined)
|
|
1018
|
+
out.build_lock_digest = provenance.build_lock_digest;
|
|
1019
|
+
if (provenance.wire_crate_version !== undefined)
|
|
1020
|
+
out.wire_crate_version = provenance.wire_crate_version;
|
|
1021
|
+
if (provenance.store_schema_version !== undefined)
|
|
1022
|
+
out.store_schema_version = provenance.store_schema_version;
|
|
1023
|
+
const source = provenance.launch_nonce_source ?? launchNonceSourceOf(sentNonce);
|
|
1024
|
+
if (source !== undefined)
|
|
1025
|
+
out.launch_nonce_source = source;
|
|
1026
|
+
return out;
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
* Where the nonce HELLO sends came from, as the Rust SDK reports it: the
|
|
1030
|
+
* accessor's source when the accessor holds that same nonce, and nothing when
|
|
1031
|
+
* HELLO sends none or the caller supplied a different one.
|
|
1032
|
+
*/
|
|
1033
|
+
function launchNonceSourceOf(sentNonce) {
|
|
1034
|
+
if (sentNonce === undefined)
|
|
1035
|
+
return undefined;
|
|
1036
|
+
const nonce = launchNonceOrUndefined();
|
|
1037
|
+
return nonce !== undefined && nonce.value === sentNonce ? nonce.source : undefined;
|
|
1038
|
+
}
|
|
974
1039
|
function normalizeProviderRole(role) {
|
|
975
1040
|
switch (role.role) {
|
|
976
1041
|
case "tool_provider":
|