@byollm/protocol 0.1.0-alpha.5 → 0.1.0-alpha.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/README.md +106 -4
- package/dist/index.d.ts +606 -70
- package/dist/index.js +888 -132
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { z as z2 } from "zod";
|
|
3
3
|
|
|
4
4
|
// src/backends.ts
|
|
5
|
+
import { isIP } from "net";
|
|
5
6
|
import { z } from "zod";
|
|
6
7
|
var BackendClass = z.enum(["http", "process"]);
|
|
7
8
|
var BackendCost = z.enum(["free", "metered", "subscription"]);
|
|
@@ -162,6 +163,24 @@ var BACKENDS = Object.freeze({
|
|
|
162
163
|
class: "process",
|
|
163
164
|
cost: "subscription",
|
|
164
165
|
adversarialCorpus: "process"
|
|
166
|
+
}),
|
|
167
|
+
/**
|
|
168
|
+
* OpenAI's Codex CLI, on a ChatGPT plan — byollm_016 stage 3.
|
|
169
|
+
*
|
|
170
|
+
* `subscription`, so `SUBSCRIPTION_SELF_LOCK` pins it to its owner's own
|
|
171
|
+
* work whatever the config says. That is load-bearing here in a way it is
|
|
172
|
+
* not for `claude-cli`: Codex is an *agent*, and its default feature set
|
|
173
|
+
* includes a shell tool, browser control and computer use. The daemon
|
|
174
|
+
* disables every one of them, verified against the shipped binary rather
|
|
175
|
+
* than assumed — see `codex-cli.ts` — but the self-lock is the floor under
|
|
176
|
+
* that verification rather than a duplicate of it.
|
|
177
|
+
*/
|
|
178
|
+
"codex-cli": backend({
|
|
179
|
+
id: "codex-cli",
|
|
180
|
+
label: "Codex CLI (your ChatGPT plan)",
|
|
181
|
+
class: "process",
|
|
182
|
+
cost: "subscription",
|
|
183
|
+
adversarialCorpus: "process"
|
|
165
184
|
})
|
|
166
185
|
});
|
|
167
186
|
var BACKEND_IDS = Object.freeze(Object.keys(BACKENDS));
|
|
@@ -177,17 +196,24 @@ function backendDescriptor(id) {
|
|
|
177
196
|
function isLocalHost(hostname) {
|
|
178
197
|
const host = hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
179
198
|
if (host === "localhost" || host.endsWith(".localhost")) return true;
|
|
180
|
-
|
|
199
|
+
const version = isIP(host);
|
|
200
|
+
if (version === 0) return false;
|
|
201
|
+
if (version === 6) {
|
|
202
|
+
if (host === "::1") return true;
|
|
203
|
+
return /^f[cd]/.test(host);
|
|
204
|
+
}
|
|
181
205
|
if (host.startsWith("127.")) return true;
|
|
182
206
|
if (host.startsWith("10.")) return true;
|
|
183
207
|
if (host.startsWith("192.168.")) return true;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
208
|
+
return /^172\.(1[6-9]|2\d|3[01])\./.test(host);
|
|
209
|
+
}
|
|
210
|
+
function isCloudTaggedModel(model) {
|
|
211
|
+
return /:[^:]*cloud$/.test(model);
|
|
187
212
|
}
|
|
188
|
-
function resolveCost(id, baseUrl) {
|
|
213
|
+
function resolveCost(id, baseUrl, model) {
|
|
189
214
|
const declared = BACKENDS[id].cost;
|
|
190
215
|
if (declared !== null) return declared;
|
|
216
|
+
if (model !== void 0 && isCloudTaggedModel(model)) return "metered";
|
|
191
217
|
if (baseUrl === void 0) return "metered";
|
|
192
218
|
try {
|
|
193
219
|
return isLocalHost(new URL(baseUrl).hostname) ? "free" : "metered";
|
|
@@ -197,8 +223,8 @@ function resolveCost(id, baseUrl) {
|
|
|
197
223
|
}
|
|
198
224
|
|
|
199
225
|
// src/audience.ts
|
|
200
|
-
var Audience = z2.enum(["
|
|
201
|
-
var OfferScope = z2.enum(["
|
|
226
|
+
var Audience = z2.enum(["private", "team", "public"]);
|
|
227
|
+
var OfferScope = z2.enum(["private", "team", "public"]);
|
|
202
228
|
var AUDIENCES = Object.freeze(Audience.options);
|
|
203
229
|
var OFFER_SCOPES = Object.freeze(OfferScope.options);
|
|
204
230
|
var MatchRefusal = z2.enum([
|
|
@@ -222,16 +248,16 @@ var MatchRefusal = z2.enum([
|
|
|
222
248
|
var ALLOWED = Object.freeze({ ok: true });
|
|
223
249
|
var refuse = (refusal) => Object.freeze({ ok: false, refusal });
|
|
224
250
|
function effectiveOfferScope(configured, cost, spend) {
|
|
225
|
-
if (cost === "subscription") return "
|
|
226
|
-
if (cost === "metered" && spend?.acknowledged !== true) return "
|
|
251
|
+
if (cost === "subscription") return "private";
|
|
252
|
+
if (cost === "metered" && spend?.acknowledged !== true) return "private";
|
|
227
253
|
return configured;
|
|
228
254
|
}
|
|
229
255
|
function matchAudience(job, daemon) {
|
|
230
256
|
const sameOwner = job.owner === daemon.owner;
|
|
231
|
-
if (job.audience === "
|
|
257
|
+
if (job.audience === "private" && !sameOwner) {
|
|
232
258
|
return refuse("audience-self-other-owner");
|
|
233
259
|
}
|
|
234
|
-
if (job.audience === "
|
|
260
|
+
if (job.audience === "team" && !sameOwner && job.audienceAllow !== void 0 && !job.audienceAllow.includes(daemon.owner)) {
|
|
235
261
|
return refuse("not-in-server-allowlist");
|
|
236
262
|
}
|
|
237
263
|
const scope = effectiveOfferScope(
|
|
@@ -254,19 +280,19 @@ function matchAudience(job, daemon) {
|
|
|
254
280
|
}
|
|
255
281
|
}
|
|
256
282
|
switch (scope) {
|
|
257
|
-
case "
|
|
283
|
+
case "private":
|
|
258
284
|
return refuse("offer-scope-too-narrow");
|
|
259
|
-
case "
|
|
285
|
+
case "team":
|
|
260
286
|
return daemon.locallyAllows(job.owner) ? ALLOWED : refuse("not-locally-allowed");
|
|
261
287
|
case "public":
|
|
262
288
|
return ALLOWED;
|
|
263
289
|
}
|
|
264
290
|
}
|
|
265
291
|
var REFUSAL_MESSAGES = Object.freeze({
|
|
266
|
-
"no-capability": "no backend on this
|
|
267
|
-
"audience-self-other-owner": "the job is private to its owner and this
|
|
268
|
-
"not-locally-allowed": "the job's owner is not on this
|
|
269
|
-
"not-in-server-allowlist": "the app restricted this job to named runners and this
|
|
292
|
+
"no-capability": "no backend on this device is configured and healthy for that job kind",
|
|
293
|
+
"audience-self-other-owner": "the job is private to its owner and this device is paired to someone else",
|
|
294
|
+
"not-locally-allowed": "the job's owner is not on this device's allowlist (byollm allow <server> <user>)",
|
|
295
|
+
"not-in-server-allowlist": "the app restricted this job to named runners and this device is not one of them",
|
|
270
296
|
"offer-scope-too-narrow": "this backend is offered to its owner only (byollm offer <backend> named|public to widen)",
|
|
271
297
|
"subscription-self-lock": "subscription-backed models run their owner's work only \u2014 this is a protocol rule, not a setting",
|
|
272
298
|
"metered-no-spend-consent": "this backend bills its owner per token, and they have not agreed to spend it on other people's work",
|
|
@@ -290,11 +316,21 @@ var ChatMessage = z3.object({
|
|
|
290
316
|
var GeneratePayload = z3.object({
|
|
291
317
|
prompt: z3.string().min(1).max(PAYLOAD_LIMITS.maxTextChars),
|
|
292
318
|
system: z3.string().max(PAYLOAD_LIMITS.maxTextChars).optional()
|
|
293
|
-
}).strict()
|
|
319
|
+
}).strict().refine(
|
|
320
|
+
(payload) => payload.prompt.length + (payload.system?.length ?? 0) <= PAYLOAD_LIMITS.maxTotalChars,
|
|
321
|
+
{
|
|
322
|
+
message: `payload exceeds ${String(PAYLOAD_LIMITS.maxTotalChars)} characters`
|
|
323
|
+
}
|
|
324
|
+
);
|
|
294
325
|
var ChatPayload = z3.object({
|
|
295
326
|
messages: z3.array(ChatMessage).min(1).max(PAYLOAD_LIMITS.maxMessages),
|
|
296
327
|
system: z3.string().max(PAYLOAD_LIMITS.maxTextChars).optional()
|
|
297
|
-
}).strict()
|
|
328
|
+
}).strict().refine(
|
|
329
|
+
(payload) => payload.messages.reduce((sum, m) => sum + m.content.length, 0) + (payload.system?.length ?? 0) <= PAYLOAD_LIMITS.maxTotalChars,
|
|
330
|
+
{
|
|
331
|
+
message: `payload exceeds ${String(PAYLOAD_LIMITS.maxTotalChars)} characters`
|
|
332
|
+
}
|
|
333
|
+
);
|
|
298
334
|
var JobKind = z3.enum(["llm.generate", "llm.chat"]);
|
|
299
335
|
var JOB_KINDS = Object.freeze(JobKind.options);
|
|
300
336
|
var KindedPayload = z3.discriminatedUnion("kind", [
|
|
@@ -378,8 +414,19 @@ var ClaimedJob = z4.object({
|
|
|
378
414
|
audience: Audience,
|
|
379
415
|
/** The app's id for the user who enqueued it. */
|
|
380
416
|
owner: z4.string().min(1),
|
|
381
|
-
/**
|
|
382
|
-
|
|
417
|
+
/**
|
|
418
|
+
* Which site's job — V1-3.
|
|
419
|
+
*
|
|
420
|
+
* The stub has always carried it; the opened job did not, so everything
|
|
421
|
+
* downstream of the payload — the ingress line above all — recorded a job
|
|
422
|
+
* id that belongs to a site without saying which. Two sites can choose
|
|
423
|
+
* the same id, and the meter is the product.
|
|
424
|
+
*
|
|
425
|
+
* Optional so a caller assembling a job by hand is not forced to invent
|
|
426
|
+
* one, and so this reads as what it is: a fact about where the work came
|
|
427
|
+
* from, not a second copy of the routing key.
|
|
428
|
+
*/
|
|
429
|
+
site: z4.string().min(1).optional(),
|
|
383
430
|
lease: Lease
|
|
384
431
|
}).strict();
|
|
385
432
|
var ResultProvenance = z4.object({
|
|
@@ -406,9 +453,16 @@ function provenanceFor(input) {
|
|
|
406
453
|
runnerOwner: input.runnerOwner,
|
|
407
454
|
backendClass: input.backendClass,
|
|
408
455
|
model: input.model,
|
|
409
|
-
untrusted: input.audience !== "
|
|
456
|
+
untrusted: input.audience !== "private"
|
|
410
457
|
};
|
|
411
458
|
}
|
|
459
|
+
var RunMetadata = z4.object({
|
|
460
|
+
/** Which model actually served it. */
|
|
461
|
+
model: z4.string().min(1),
|
|
462
|
+
backendClass: BackendClass,
|
|
463
|
+
/** Wall-clock milliseconds the backend call took. */
|
|
464
|
+
durationMs: z4.number().int().nonnegative()
|
|
465
|
+
}).strict();
|
|
412
466
|
var JobResultOk = z4.object({
|
|
413
467
|
outcome: z4.literal("ok"),
|
|
414
468
|
text: z4.string(),
|
|
@@ -430,11 +484,88 @@ var JobOutcome = z4.discriminatedUnion("outcome", [
|
|
|
430
484
|
JobResultError,
|
|
431
485
|
JobResultCanceled
|
|
432
486
|
]);
|
|
487
|
+
var RefusalReason = z4.enum([
|
|
488
|
+
/**
|
|
489
|
+
* A selection this requester cannot be served — byollm_016 Phase B.
|
|
490
|
+
*
|
|
491
|
+
* **One value for two causes, and the collapse is the security property.**
|
|
492
|
+
* A named service may be unknown to this owner, or known and not offered to
|
|
493
|
+
* this requester. Those are different facts and the requester may learn
|
|
494
|
+
* neither, because telling them apart turns refusal wording into an
|
|
495
|
+
* inventory oracle: probe names, sort the answers, and enumerate a device
|
|
496
|
+
* you were never offered. The finer cause lives owner-side, where the person
|
|
497
|
+
* reading it already owns the machine — see {@link SelectionFailure}.
|
|
498
|
+
*
|
|
499
|
+
* The first draft of this enum had both causes on the wire with a comment
|
|
500
|
+
* claiming they disclosed identically. They did not; the comment described a
|
|
501
|
+
* property the code lacked, which is the more dangerous half of that mistake.
|
|
502
|
+
*/
|
|
503
|
+
"select-unavailable",
|
|
504
|
+
/**
|
|
505
|
+
* Two or more services answer this kind and the owner has named no default,
|
|
506
|
+
* so the kind is withheld. Nobody may pick on the owner's behalf — the wrong
|
|
507
|
+
* guess is the metered one.
|
|
508
|
+
*
|
|
509
|
+
* Not collapsed into the value above, and the reason is that a kind is not
|
|
510
|
+
* probeable. There are two kinds; a requester asking about one is not
|
|
511
|
+
* enumerating a namespace, and learns nothing they could not learn by
|
|
512
|
+
* looking at what the device advertises. It is also already what a roster
|
|
513
|
+
* member sees on the devices page — `awaitingDefault` carries exactly this,
|
|
514
|
+
* by kind, for exactly this reason.
|
|
515
|
+
*/
|
|
516
|
+
"default-ambiguity",
|
|
517
|
+
/**
|
|
518
|
+
* A default exists and this requester can never use it — byollm_016's
|
|
519
|
+
* defaults-meet-audiences corner.
|
|
520
|
+
*
|
|
521
|
+
* The specimen: an owner's default for `llm.chat` is their Claude
|
|
522
|
+
* subscription, self-locked by `SUBSCRIPTION_SELF_LOCK`. A team member's
|
|
523
|
+
* unselected job resolves to it and can never be served by it. That must be
|
|
524
|
+
* a refusal on the spot, not a wait that expires an hour later looking like
|
|
525
|
+
* nobody was online.
|
|
526
|
+
*
|
|
527
|
+
* Bounded like the value above and probeable for the same reason it is not:
|
|
528
|
+
* the requester named nothing, so there is no name space to walk.
|
|
529
|
+
*/
|
|
530
|
+
"default-unusable"
|
|
531
|
+
]);
|
|
532
|
+
var JobRefused = z4.object({
|
|
533
|
+
outcome: z4.literal("refused"),
|
|
534
|
+
reason: RefusalReason,
|
|
535
|
+
/** Plain words for a human reading a log, never parsed. */
|
|
536
|
+
message: z4.string().min(1)
|
|
537
|
+
}).strict();
|
|
538
|
+
var REFUSAL_TEXT = Object.freeze({
|
|
539
|
+
"select-unavailable": "that service is not available to you on this device",
|
|
540
|
+
"default-ambiguity": "this device serves that kind from more than one service and its owner has not chosen which",
|
|
541
|
+
"default-unusable": "this device's default for that kind cannot run work for you"
|
|
542
|
+
});
|
|
543
|
+
var REFUSED_SELECTION = Object.freeze({
|
|
544
|
+
outcome: "refused",
|
|
545
|
+
reason: "select-unavailable",
|
|
546
|
+
message: REFUSAL_TEXT["select-unavailable"]
|
|
547
|
+
});
|
|
548
|
+
var SealedOutcome = z4.object({ outcome: JobOutcome, ran: RunMetadata }).strict();
|
|
433
549
|
var DeliveredResult = z4.object({
|
|
434
550
|
jobId: z4.string().min(1),
|
|
435
551
|
state: JobState,
|
|
436
552
|
outcome: JobOutcome.optional(),
|
|
437
|
-
provenance: ResultProvenance.optional()
|
|
553
|
+
provenance: ResultProvenance.optional(),
|
|
554
|
+
/**
|
|
555
|
+
* Present, and always `true`, when this did not come from a runner —
|
|
556
|
+
* {@link MUSTS.FALLBACK_LABELED}.
|
|
557
|
+
*
|
|
558
|
+
* The app's own `onNoRunner` value produced it: a hosted model, a cached
|
|
559
|
+
* answer, an apology. It never travels on the wire, because nothing on
|
|
560
|
+
* the wire produced it; it exists so that a result which did not come
|
|
561
|
+
* from the user's own compute cannot be reported as though it did.
|
|
562
|
+
*
|
|
563
|
+
* A literal rather than a boolean, so `fallback: false` is not a
|
|
564
|
+
* spelling anybody can reach for. The absence of this field means a
|
|
565
|
+
* runner ran the job, and the *server* stamps it — an app cannot supply
|
|
566
|
+
* a substitute that hides what it is.
|
|
567
|
+
*/
|
|
568
|
+
fallback: z4.literal(true).optional()
|
|
438
569
|
}).strict();
|
|
439
570
|
var SizeClass = z4.enum(["small", "medium", "large", "unbounded"]);
|
|
440
571
|
var SIZE_CLASS_LIMITS = Object.freeze({
|
|
@@ -456,8 +587,75 @@ var JobStub = z4.object({
|
|
|
456
587
|
kind: JobKind,
|
|
457
588
|
/** The app's id for the user who enqueued it. */
|
|
458
589
|
owner: z4.string().min(1),
|
|
590
|
+
/**
|
|
591
|
+
* Which site this job belongs to — byollm_009 Amendment A §A.3.
|
|
592
|
+
*
|
|
593
|
+
* **The site's identity key id**, not an id somebody assigned it. §6 has
|
|
594
|
+
* listed `site` since this spec was frozen; the schema never carried it,
|
|
595
|
+
* which is the drift the amendment closes.
|
|
596
|
+
*
|
|
597
|
+
* A key id rather than an opaque handle for one reason above the others:
|
|
598
|
+
* it makes the stub *self-describing* instead of a pointer into somebody
|
|
599
|
+
* else's table. A daemon holds this key id already, from pinning, so it
|
|
600
|
+
* can check `stub.site` against the payload envelope's `senderKeyId`
|
|
601
|
+
* without a lookup and without trusting the party that routed it. An
|
|
602
|
+
* opaque id can only be believed.
|
|
603
|
+
*
|
|
604
|
+
* It also avoids inventing a second namespace for a thing that has a
|
|
605
|
+
* canonical one — the shape of finding 41 (two owner namespaces compared
|
|
606
|
+
* for equality) and of finding fourteen before it.
|
|
607
|
+
*
|
|
608
|
+
* Rotation is a designed transition rather than a cost: a site publishes a
|
|
609
|
+
* new identity signed by the outgoing one, both are valid through an
|
|
610
|
+
* overlap window, and a daemon re-keys its own map by verifying that
|
|
611
|
+
* signature against the key it already pinned (§A.3.1).
|
|
612
|
+
*/
|
|
613
|
+
site: z4.string().min(1),
|
|
459
614
|
audience: Audience,
|
|
460
|
-
audienceAllow
|
|
615
|
+
// `audienceAllow` is **not** here, and its absence is the enforcement —
|
|
616
|
+
// cloud_008 §0.2.
|
|
617
|
+
//
|
|
618
|
+
// It was a list of the people who may run a job, travelling to every
|
|
619
|
+
// routing party on every `named` job. byollm_001 Rev 1 §B settled who
|
|
620
|
+
// decides that long before this schema existed: *the daemon's own list
|
|
621
|
+
// decides, not the server's*, and `allowlist.predicateFor(origin)` is the
|
|
622
|
+
// enforcement in both lanes. So this was a second answer to a question the
|
|
623
|
+
// daemon already owned — able only to agree, in which case it was
|
|
624
|
+
// redundant, or to disagree, in which case nothing said which wins.
|
|
625
|
+
//
|
|
626
|
+
// The rule it leaves behind, which decides the next field too: **a class
|
|
627
|
+
// the router acts on may travel; membership never does.** `audience` stays
|
|
628
|
+
// for exactly that reason — the relay narrows on it. A roster does not
|
|
629
|
+
// travel, so `ROSTER_NOT_DISCLOSED` holds here by absence, which is the
|
|
630
|
+
// strongest way for a MUST to hold.
|
|
631
|
+
//
|
|
632
|
+
// The site keeps its own copy on `JobRecord` and still filters candidates
|
|
633
|
+
// with it before offering. That is server-internal, where the party
|
|
634
|
+
// holding the list authored it.
|
|
635
|
+
/**
|
|
636
|
+
* Which of the owner's services should answer — byollm_016 Phase B.
|
|
637
|
+
*
|
|
638
|
+
* **A selection from a menu, never a demand.** The owner advertises named
|
|
639
|
+
* services; a site may name one of them, and that is the entire power the
|
|
640
|
+
* field grants. It carries no model, no base URL, no flags — the daemon
|
|
641
|
+
* resolves the name against its own config and nothing else, so what
|
|
642
|
+
* actually runs is still decided exclusively by the person who owns the
|
|
643
|
+
* hardware. A name that is not on that owner's menu is refused
|
|
644
|
+
* (`select-unadvertised`), never silently substituted, because a
|
|
645
|
+
* substitution is how "select" would quietly become "whatever we had".
|
|
646
|
+
*
|
|
647
|
+
* Absent means "the owner's default for this kind", which is the only
|
|
648
|
+
* behaviour Phase A had.
|
|
649
|
+
*
|
|
650
|
+
* It travels because the router matches on it, under the rule the absent
|
|
651
|
+
* `audienceAllow` above establishes: *a class the router acts on may
|
|
652
|
+
* travel; membership never does.* This is a class.
|
|
653
|
+
*
|
|
654
|
+
* It is a **stub** field and never a payload field, which is the line
|
|
655
|
+
* `NO_PAYLOAD_ROUTING` draws: the prompt cannot reach it, so no amount of
|
|
656
|
+
* user text can influence what runs.
|
|
657
|
+
*/
|
|
658
|
+
service: z4.string().min(1).optional(),
|
|
461
659
|
sizeClass: SizeClass,
|
|
462
660
|
/** Reserved for byollm_006. False until streaming exists. */
|
|
463
661
|
streaming: z4.boolean(),
|
|
@@ -748,6 +946,21 @@ function signRequest(keys, input) {
|
|
|
748
946
|
signature: signWith(keys, canonicalRequest(input))
|
|
749
947
|
};
|
|
750
948
|
}
|
|
949
|
+
function signSiteRequest(keys, input) {
|
|
950
|
+
return signRequest(keys, {
|
|
951
|
+
endpoint: siteEndpoint(input.endpoint),
|
|
952
|
+
runnerId: input.siteId,
|
|
953
|
+
issuedAt: input.issuedAt,
|
|
954
|
+
body: input.body
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
function verifySiteRequest(input) {
|
|
958
|
+
return verifyRequest({
|
|
959
|
+
...input,
|
|
960
|
+
endpoint: siteEndpoint(input.endpoint)
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
var siteEndpoint = (endpoint) => `site/${endpoint}`;
|
|
751
964
|
function verifyRequest(input) {
|
|
752
965
|
const skew = input.maxSkewMs ?? MAX_CLOCK_SKEW_MS;
|
|
753
966
|
if (Math.abs(input.now - input.signature.issuedAt) > skew) return "stale";
|
|
@@ -764,7 +977,69 @@ function verifyRequest(input) {
|
|
|
764
977
|
return ok ? null : "bad-signature";
|
|
765
978
|
}
|
|
766
979
|
|
|
980
|
+
// src/succession.ts
|
|
981
|
+
import { z as z8 } from "zod";
|
|
982
|
+
var SUCCESSION_CONTEXT = "byollm/v1/site-succession";
|
|
983
|
+
var RETIREMENT_WINDOW_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
984
|
+
var MAX_SUCCESSION_CHAIN = 64;
|
|
985
|
+
var Succession = z8.object({
|
|
986
|
+
/**
|
|
987
|
+
* The predecessor's public identity — K1, in full.
|
|
988
|
+
*
|
|
989
|
+
* The whole identity rather than the key id, because a daemon meeting a
|
|
990
|
+
* chain it has not seen before has to *verify* each link, and a key id is
|
|
991
|
+
* a fingerprint: enough to compare, never enough to check a signature.
|
|
992
|
+
*/
|
|
993
|
+
identity: PublicIdentity,
|
|
994
|
+
/** K1's signature over the statement naming K1 and its successor. */
|
|
995
|
+
signature: z8.string().min(1)
|
|
996
|
+
}).strict();
|
|
997
|
+
function successionStatement(fromKeyId, toKeyId) {
|
|
998
|
+
return Buffer.from(`${SUCCESSION_CONTEXT}:${fromKeyId}:${toKeyId}`);
|
|
999
|
+
}
|
|
1000
|
+
function signSuccession(previous, next) {
|
|
1001
|
+
return {
|
|
1002
|
+
identity: {
|
|
1003
|
+
identity: previous.identityPublic,
|
|
1004
|
+
encryption: previous.encryptionPublic,
|
|
1005
|
+
encryptionSig: previous.encryptionSig
|
|
1006
|
+
},
|
|
1007
|
+
signature: signWith(
|
|
1008
|
+
previous,
|
|
1009
|
+
successionStatement(keyId(previous.identityPublic), keyId(next.identity))
|
|
1010
|
+
)
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
function verifyLink(link, toKeyId) {
|
|
1014
|
+
if (!verifyPublicIdentity(link.identity)) return false;
|
|
1015
|
+
return verifyWith(
|
|
1016
|
+
link.identity.identity,
|
|
1017
|
+
successionStatement(keyId(link.identity.identity), toKeyId),
|
|
1018
|
+
link.signature
|
|
1019
|
+
);
|
|
1020
|
+
}
|
|
1021
|
+
function walkSuccession(input) {
|
|
1022
|
+
const { current, chain, approved } = input;
|
|
1023
|
+
if (chain.length === 0) return { path: [current], failure: "no-chain" };
|
|
1024
|
+
if (chain.length > MAX_SUCCESSION_CHAIN)
|
|
1025
|
+
return { path: [current], failure: "too-long" };
|
|
1026
|
+
const steps = [...chain].reverse();
|
|
1027
|
+
const path = [current];
|
|
1028
|
+
let succeeding = current;
|
|
1029
|
+
for (const link of steps) {
|
|
1030
|
+
if (!verifyLink(link, succeeding)) return { path, failure: "broken-link" };
|
|
1031
|
+
const previous = keyId(link.identity.identity);
|
|
1032
|
+
path.unshift(previous);
|
|
1033
|
+
if (approved(previous)) return { path, from: previous };
|
|
1034
|
+
succeeding = previous;
|
|
1035
|
+
}
|
|
1036
|
+
return { path, failure: "unknown-origin" };
|
|
1037
|
+
}
|
|
1038
|
+
|
|
767
1039
|
// src/musts.ts
|
|
1040
|
+
function kindsOf(must2) {
|
|
1041
|
+
return typeof must2.verifiedBy === "string" ? [must2.verifiedBy] : must2.verifiedBy;
|
|
1042
|
+
}
|
|
768
1043
|
var must = (m) => Object.freeze(m);
|
|
769
1044
|
var MUSTS = Object.freeze({
|
|
770
1045
|
// ---- Pairing and identity -------------------------------------------
|
|
@@ -797,6 +1072,48 @@ var MUSTS = Object.freeze({
|
|
|
797
1072
|
verifiedBy: "conformance",
|
|
798
1073
|
source: "byollm_009 \xA74"
|
|
799
1074
|
}),
|
|
1075
|
+
SITE_KEY_BY_STUB: must({
|
|
1076
|
+
id: "SITE_KEY_BY_STUB",
|
|
1077
|
+
statement: "A daemon MUST verify a job's payload against the pinned key of the site the stub names, and MUST refuse a job naming a site it has not pinned. It MUST NOT fall back to another pinned key, and MUST refuse an envelope whose declared sender disagrees with the stub's site.",
|
|
1078
|
+
enforcedBy: "daemon",
|
|
1079
|
+
// Adversarial, and the reason is the finding that produced it: the
|
|
1080
|
+
// honest paths pass with every site check deleted, because `open`
|
|
1081
|
+
// refuses a signature from the wrong key anyway. What distinguishes an
|
|
1082
|
+
// enforced rule from a coincidence here is a hostile pairing of stub and
|
|
1083
|
+
// envelope, which no conformance client would ever send.
|
|
1084
|
+
verifiedBy: "adversarial",
|
|
1085
|
+
source: "byollm_009 \xA7A.3"
|
|
1086
|
+
}),
|
|
1087
|
+
SITES_LOCALLY_APPROVED: must({
|
|
1088
|
+
id: "SITES_LOCALLY_APPROVED",
|
|
1089
|
+
statement: "A daemon MUST NOT run work for a site it has not approved on the machine itself. An upstream may propose a site set; a site the daemon has never approved MUST be offered to its owner and served nothing until they approve it. A key that has changed for an already-approved id MUST be refused for the life of the pairing, including after that id has left the set and returned. A **verified succession** is not a changed key: a new key id carrying a signature, by a key this daemon has already approved, over a statement naming both key ids MUST be accepted without a new local approval \u2014 provided the control plane projects the same successor \u2014 and MUST be announced rather than applied silently.",
|
|
1090
|
+
enforcedBy: "daemon",
|
|
1091
|
+
// Two kinds, and the second is the one that matters — V1-1.
|
|
1092
|
+
//
|
|
1093
|
+
// `construction`: the daemon cannot serve a site that is not in its
|
|
1094
|
+
// pinned map, and admission refuses before a payload is fetched, so the
|
|
1095
|
+
// ordinary path cannot reach a site nobody approved.
|
|
1096
|
+
//
|
|
1097
|
+
// `adversarial`: the property that survives is about a *sequence* —
|
|
1098
|
+
// remove the id, re-offer it under a different key — which no honest
|
|
1099
|
+
// upstream sends and which the fence above does not see. That was the
|
|
1100
|
+
// bypass: the pin was deleted with the id, so the comparison had nothing
|
|
1101
|
+
// to compare against and the substitution arrived as a stranger.
|
|
1102
|
+
// **Not `conformance`, and that is a live gap rather than a judgement.**
|
|
1103
|
+
// Amendment C's succession clause is a rule about two implementations
|
|
1104
|
+
// agreeing, which is what a conformance check is for — but rotating a
|
|
1105
|
+
// site's key is not something `ConformanceTarget` can express, and adding
|
|
1106
|
+
// an optional hook that most targets omit would produce a check reporting
|
|
1107
|
+
// success for a reason unrelated to the property it claims. That is this
|
|
1108
|
+
// project's most-repeated bug, and it is not worth reintroducing for a
|
|
1109
|
+
// stronger-sounding word in a table. The rotation path is verified by
|
|
1110
|
+
// `site-rotation.test.ts` (both directions, against the shipped runner)
|
|
1111
|
+
// and `relay/test/rotation.test.ts` (both planes, against the reference
|
|
1112
|
+
// relay); the missing piece is a second *independent* implementation to
|
|
1113
|
+
// check them against, and there is not one yet.
|
|
1114
|
+
verifiedBy: ["construction", "adversarial"],
|
|
1115
|
+
source: "byollm_009 \xA7B.2, Amendment C"
|
|
1116
|
+
}),
|
|
800
1117
|
KEYS_EXCHANGED_AT_CONSENT: must({
|
|
801
1118
|
id: "KEYS_EXCHANGED_AT_CONSENT",
|
|
802
1119
|
statement: "Pairing MUST exchange both parties' public identities; each side MUST verify that the encryption key is signed by the identity presenting it, and MUST pin the identity. Keys MUST NOT be delivered before approval.",
|
|
@@ -984,12 +1301,12 @@ var MUSTS = Object.freeze({
|
|
|
984
1301
|
verifiedBy: "conformance",
|
|
985
1302
|
source: "byollm_001 \xA7Endpoints.4"
|
|
986
1303
|
}),
|
|
987
|
-
|
|
988
|
-
id: "
|
|
989
|
-
statement: "A result
|
|
1304
|
+
PROVENANCE_NAMES_DEVICE: must({
|
|
1305
|
+
id: "PROVENANCE_NAMES_DEVICE",
|
|
1306
|
+
statement: "A result MUST carry the claiming device's key id and its relationship to the requester, to the delivery seam, so an app never treats volunteer output as first-party. The key id MUST be the device the upstream granted the lease to, and a result whose signature does not verify against that device MUST be refused rather than recorded.",
|
|
990
1307
|
enforcedBy: "server",
|
|
991
1308
|
verifiedBy: "conformance",
|
|
992
|
-
source: "
|
|
1309
|
+
source: "byollm_009 \xA711"
|
|
993
1310
|
}),
|
|
994
1311
|
// ---- The trust surface -------------------------------------------------
|
|
995
1312
|
INGRESS_LOGGED_BEFORE_EXECUTION: must({
|
|
@@ -1007,12 +1324,33 @@ var MUSTS = Object.freeze({
|
|
|
1007
1324
|
verifiedBy: "adversarial",
|
|
1008
1325
|
source: "byollm_004 \xA72"
|
|
1009
1326
|
}),
|
|
1327
|
+
/**
|
|
1328
|
+
* Amended for byollm_016 Phase B, and the amendment is deliberately narrow.
|
|
1329
|
+
*
|
|
1330
|
+
* A site may now name a **service** on the stub. The temptation is to read
|
|
1331
|
+
* that as a crack in this law, so the statement below says exactly where the
|
|
1332
|
+
* line is: a name selects from a menu the owner published, and resolves to a
|
|
1333
|
+
* model, backend, base URL and flags **only** through that owner's own
|
|
1334
|
+
* config. The site supplies a key; the owner supplies every value it maps
|
|
1335
|
+
* to. A name the owner does not advertise is refused rather than
|
|
1336
|
+
* substituted, because substitution is how "you may pick from my list" turns
|
|
1337
|
+
* into "you may ask for anything and get something".
|
|
1338
|
+
*
|
|
1339
|
+
* Two properties keep it from drifting into "sites demand models":
|
|
1340
|
+
*
|
|
1341
|
+
* 1. **Nothing the site sends is ever a value.** No model string, no URL,
|
|
1342
|
+
* no flag crosses the wire — only a key that means nothing off this
|
|
1343
|
+
* owner's machine.
|
|
1344
|
+
* 2. **It is a stub field, never a payload field.** The prompt cannot
|
|
1345
|
+
* reach it. That is unchanged and is the sentence the second clause
|
|
1346
|
+
* below still enforces verbatim.
|
|
1347
|
+
*/
|
|
1010
1348
|
NO_PAYLOAD_ROUTING: must({
|
|
1011
1349
|
id: "NO_PAYLOAD_ROUTING",
|
|
1012
|
-
statement: "Model, backend, base URL, and flags MUST come from owner config only; a payload MUST NOT influence any of them.",
|
|
1350
|
+
statement: "Model, backend, base URL, and flags MUST come from owner config only; a payload MUST NOT influence any of them. A stub MAY name a service the owner advertises, which selects among that owner's own config entries and MUST NOT introduce any value the owner did not write; an unadvertised name MUST be refused, never substituted.",
|
|
1013
1351
|
enforcedBy: "daemon",
|
|
1014
1352
|
verifiedBy: "adversarial",
|
|
1015
|
-
source: "byollm_004 \xA72"
|
|
1353
|
+
source: "byollm_004 \xA72, amended byollm_016 \xA7Phase B"
|
|
1016
1354
|
}),
|
|
1017
1355
|
STRIPPED_CHILD_ENV: must({
|
|
1018
1356
|
id: "STRIPPED_CHILD_ENV",
|
|
@@ -1041,26 +1379,117 @@ var MUSTS = Object.freeze({
|
|
|
1041
1379
|
enforcedBy: "daemon",
|
|
1042
1380
|
verifiedBy: "adversarial",
|
|
1043
1381
|
source: "byollm_004 \xA74"
|
|
1382
|
+
}),
|
|
1383
|
+
REVOCATION_IMMEDIATE: must({
|
|
1384
|
+
id: "REVOCATION_IMMEDIATE",
|
|
1385
|
+
statement: "Revocation MUST take effect at the upstream at once \u2014 a revoked runner MUST NOT be granted further work from the moment the record changes \u2014 and MUST reach the daemon by its next heartbeat.",
|
|
1386
|
+
// Both, and stated as one sentence with two obligations rather than
|
|
1387
|
+
// folded into REVOCATION_HONORED. That one binds the *daemon*: a revoked
|
|
1388
|
+
// daemon stops claiming and abandons in-flight work. This binds the
|
|
1389
|
+
// *upstream*. byollm_009 §5 is explicit that the pair is the point — "a
|
|
1390
|
+
// revocation enforced at one end survives a compromise of that end" — and
|
|
1391
|
+
// one entry covering both would make a compromised daemon look compliant.
|
|
1392
|
+
enforcedBy: "both",
|
|
1393
|
+
verifiedBy: "conformance",
|
|
1394
|
+
source: "byollm_009 \xA711"
|
|
1395
|
+
}),
|
|
1396
|
+
CONSENT_BEFORE_ROUTE: must({
|
|
1397
|
+
id: "CONSENT_BEFORE_ROUTE",
|
|
1398
|
+
statement: "An upstream MUST NOT route a job to a device without a record binding that user, that site and that scope. There MUST be no discovery path by which a device receives work it was never granted.",
|
|
1399
|
+
enforcedBy: "server",
|
|
1400
|
+
verifiedBy: "conformance",
|
|
1401
|
+
source: "byollm_009 \xA711"
|
|
1402
|
+
}),
|
|
1403
|
+
ROSTER_NOT_DISCLOSED: must({
|
|
1404
|
+
id: "ROSTER_NOT_DISCLOSED",
|
|
1405
|
+
statement: "A site MUST NOT learn the membership of a group whose compute it uses, and MUST NOT publish membership to a routing party. No wire message may carry a list of who may run a job.",
|
|
1406
|
+
// Checkable since cloud_008 §0.2 took `audienceAllow` off the stub: the
|
|
1407
|
+
// property now holds by *absence*, and absence is exactly what a strict
|
|
1408
|
+
// schema and a serialised stub can be asked about. Before that it was a
|
|
1409
|
+
// sentence — and one this project cited in code comments, tests and two
|
|
1410
|
+
// specs as though it were enforced data, which is why it is worth
|
|
1411
|
+
// stating precisely rather than generously.
|
|
1412
|
+
enforcedBy: "both",
|
|
1413
|
+
verifiedBy: "conformance",
|
|
1414
|
+
source: "byollm_009 \xA711"
|
|
1415
|
+
}),
|
|
1416
|
+
EFFECTIVE_OFFER_ONLY: must({
|
|
1417
|
+
id: "EFFECTIVE_OFFER_ONLY",
|
|
1418
|
+
statement: "A daemon MUST declare effective offers only. An upstream MUST NOT receive raw config, allowlists, or capacity the owner has not shared, and MUST act on the declared offer rather than on what was asked for.",
|
|
1419
|
+
enforcedBy: "both",
|
|
1420
|
+
verifiedBy: "conformance",
|
|
1421
|
+
source: "byollm_009 \xA711"
|
|
1422
|
+
}),
|
|
1423
|
+
FALLBACK_LABELED: must({
|
|
1424
|
+
id: "FALLBACK_LABELED",
|
|
1425
|
+
statement: "Work served by anything other than the user's own compute MUST be labelled as such wherever it is reported, and MUST NOT be silently substituted.",
|
|
1426
|
+
// `construction` today, and deliberately not `conformance`. Nothing on
|
|
1427
|
+
// the wire yet distinguishes a fallback from any other community job —
|
|
1428
|
+
// the ledger that would give it a surface is unbuilt — so a check would
|
|
1429
|
+
// have to assert something it cannot observe. Promoted the day that
|
|
1430
|
+
// surface exists. Marking it `conformance` now would put "verified"
|
|
1431
|
+
// beside a property no third party can see, which is the one thing the
|
|
1432
|
+
// kinds exist to prevent.
|
|
1433
|
+
enforcedBy: "both",
|
|
1434
|
+
verifiedBy: "construction",
|
|
1435
|
+
source: "byollm_009 \xA711"
|
|
1436
|
+
}),
|
|
1437
|
+
RELAY_BLIND: must({
|
|
1438
|
+
id: "RELAY_BLIND",
|
|
1439
|
+
statement: "A relay MUST NOT hold any key capable of decrypting a payload, a result, or a delta frame.",
|
|
1440
|
+
// Operator: a third party can read the relay's types and see there is
|
|
1441
|
+
// nowhere to put such a key, but the kit certifies a *server* and cannot
|
|
1442
|
+
// reach inside somebody's deployment to prove what it holds.
|
|
1443
|
+
enforcedBy: "server",
|
|
1444
|
+
verifiedBy: "operator",
|
|
1445
|
+
source: "byollm_009 \xA711"
|
|
1446
|
+
}),
|
|
1447
|
+
SHARED_COMPUTE_DISCLOSED: must({
|
|
1448
|
+
id: "SHARED_COMPUTE_DISCLOSED",
|
|
1449
|
+
statement: "Before a user's work first runs on compute they do not own, they MUST be told in plain language that the machine's owner can see it.",
|
|
1450
|
+
// Operator, and cloud_008 §0.3 is why the classification now comes with a
|
|
1451
|
+
// standing answer rather than a standing question. The screen is not
|
|
1452
|
+
// wire-observable, but the *string the server composes* is, and it is
|
|
1453
|
+
// now unit-tested with the two false sentences forbidden by name. The
|
|
1454
|
+
// kind stays `operator` because a third-party site can still render
|
|
1455
|
+
// whatever it likes; what changed is that the part inside our own
|
|
1456
|
+
// boundary stopped depending on somebody remembering to audit it.
|
|
1457
|
+
enforcedBy: "server",
|
|
1458
|
+
verifiedBy: "operator",
|
|
1459
|
+
source: "byollm_009 \xA711"
|
|
1044
1460
|
})
|
|
1045
1461
|
});
|
|
1462
|
+
var RETIRED_MUSTS = Object.freeze({
|
|
1463
|
+
RESULT_PROVENANCE: {
|
|
1464
|
+
supersededBy: "PROVENANCE_NAMES_DEVICE",
|
|
1465
|
+
note: "Strengthened, not renamed: attribution is now by proof of possession \u2014 the result's signature must verify against the device the upstream granted the lease to \u2014 rather than by a provenance label travelling beside it. byollm_009 \xA711 states the stronger form."
|
|
1466
|
+
}
|
|
1467
|
+
});
|
|
1046
1468
|
var MUST_IDS = Object.freeze(Object.keys(MUSTS));
|
|
1047
1469
|
function mustsVerifiedBy(kind) {
|
|
1048
|
-
return MUST_IDS.filter((id) => MUSTS[id].
|
|
1470
|
+
return MUST_IDS.filter((id) => kindsOf(MUSTS[id]).includes(kind));
|
|
1049
1471
|
}
|
|
1050
1472
|
|
|
1051
1473
|
// src/wire.ts
|
|
1052
|
-
import { z as
|
|
1474
|
+
import { z as z9 } from "zod";
|
|
1053
1475
|
var PROTOCOL_VERSION = "0";
|
|
1054
1476
|
var SUPPORTED_PROTOCOL_VERSIONS = Object.freeze([
|
|
1055
1477
|
PROTOCOL_VERSION
|
|
1056
1478
|
]);
|
|
1057
1479
|
var MIN_PROTOCOL_VERSION = SUPPORTED_PROTOCOL_VERSIONS[0] ?? PROTOCOL_VERSION;
|
|
1480
|
+
function declaredVersion(input) {
|
|
1481
|
+
const { body, query } = input;
|
|
1482
|
+
if (typeof body === "object" && body !== null && Object.hasOwn(body, "protocolVersion")) {
|
|
1483
|
+
return body.protocolVersion;
|
|
1484
|
+
}
|
|
1485
|
+
return query?.get("protocolVersion") ?? void 0;
|
|
1486
|
+
}
|
|
1058
1487
|
function checkProtocolVersion(body) {
|
|
1059
1488
|
const declared = typeof body === "object" && body !== null && Object.hasOwn(body, "protocolVersion") ? body.protocolVersion : void 0;
|
|
1060
1489
|
if (typeof declared !== "string" || declared.length === 0) {
|
|
1061
1490
|
return {
|
|
1062
1491
|
error: "unsupported-protocol-version",
|
|
1063
|
-
message:
|
|
1492
|
+
message: `this request declared no protocol version. Upgrade the daemon: \`${UPGRADE_COMMAND}\`.`,
|
|
1064
1493
|
supported: SUPPORTED_PROTOCOL_VERSIONS,
|
|
1065
1494
|
minimum: MIN_PROTOCOL_VERSION
|
|
1066
1495
|
};
|
|
@@ -1068,13 +1497,14 @@ function checkProtocolVersion(body) {
|
|
|
1068
1497
|
if (!SUPPORTED_PROTOCOL_VERSIONS.includes(declared)) {
|
|
1069
1498
|
return {
|
|
1070
1499
|
error: "unsupported-protocol-version",
|
|
1071
|
-
message: `this server speaks protocol ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")} and the daemon asked for ${declared}. ` + (declared < MIN_PROTOCOL_VERSION ?
|
|
1500
|
+
message: `this server speaks protocol ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")} and the daemon asked for ${declared}. ` + (declared < MIN_PROTOCOL_VERSION ? `Upgrade the daemon: \`${UPGRADE_COMMAND}\`.` : "This daemon is newer than the server; the server needs upgrading."),
|
|
1072
1501
|
supported: SUPPORTED_PROTOCOL_VERSIONS,
|
|
1073
1502
|
minimum: MIN_PROTOCOL_VERSION
|
|
1074
1503
|
};
|
|
1075
1504
|
}
|
|
1076
1505
|
return null;
|
|
1077
1506
|
}
|
|
1507
|
+
var UPGRADE_COMMAND = "npm i -g byollm@latest";
|
|
1078
1508
|
var PROTOCOL_PREFIX = "/byollm";
|
|
1079
1509
|
var ENDPOINTS = Object.freeze([
|
|
1080
1510
|
"pair",
|
|
@@ -1084,22 +1514,46 @@ var ENDPOINTS = Object.freeze([
|
|
|
1084
1514
|
"result",
|
|
1085
1515
|
"release"
|
|
1086
1516
|
]);
|
|
1087
|
-
var Capability =
|
|
1517
|
+
var Capability = z9.object({
|
|
1088
1518
|
kind: JobKind,
|
|
1519
|
+
/**
|
|
1520
|
+
* The owner's name for the service answering this kind — byollm_016.
|
|
1521
|
+
*
|
|
1522
|
+
* A device advertises *which* of its services serves a kind, not merely
|
|
1523
|
+
* that something does. Phase B lets a job select by this name; until then
|
|
1524
|
+
* it is what a device page shows and what a default is chosen between.
|
|
1525
|
+
*/
|
|
1526
|
+
service: z9.string().min(1),
|
|
1527
|
+
/**
|
|
1528
|
+
* Whether this row is the default for its kind.
|
|
1529
|
+
*
|
|
1530
|
+
* Stated rather than inferred from being the only row, which is true in
|
|
1531
|
+
* Phase A and stops being true the moment Phase B advertises every
|
|
1532
|
+
* selectable service per kind. A consumer that learned "default means
|
|
1533
|
+
* alone" would have to unlearn it, and the ones that did not would be
|
|
1534
|
+
* quietly wrong. One field now, no second shape later.
|
|
1535
|
+
*/
|
|
1536
|
+
isDefault: z9.boolean(),
|
|
1089
1537
|
backendId: BackendIdSchema,
|
|
1090
1538
|
backendClass: BackendClass,
|
|
1091
|
-
model:
|
|
1539
|
+
model: z9.string().min(1),
|
|
1092
1540
|
offerScope: OfferScope
|
|
1093
1541
|
}).strict();
|
|
1094
|
-
var CapabilityMatrix =
|
|
1095
|
-
var
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1542
|
+
var CapabilityMatrix = z9.array(Capability);
|
|
1543
|
+
var WithheldKind = z9.object({
|
|
1544
|
+
kind: JobKind,
|
|
1545
|
+
claimants: z9.array(
|
|
1546
|
+
z9.object({ service: z9.string().min(1), offer: OfferScope }).strict()
|
|
1547
|
+
).min(2)
|
|
1548
|
+
}).strict();
|
|
1549
|
+
var PairStartRequest = z9.object({
|
|
1550
|
+
protocolVersion: z9.literal(PROTOCOL_VERSION),
|
|
1551
|
+
action: z9.literal("start"),
|
|
1552
|
+
daemon: z9.object({
|
|
1553
|
+
version: z9.string().min(1),
|
|
1100
1554
|
/** Shown in the app's runner list so a user can tell their machines apart. */
|
|
1101
|
-
label:
|
|
1102
|
-
platform:
|
|
1555
|
+
label: z9.string().min(1).max(120),
|
|
1556
|
+
platform: z9.enum(["darwin", "linux", "win32"])
|
|
1103
1557
|
}),
|
|
1104
1558
|
/**
|
|
1105
1559
|
* This machine's public keys (byollm_009 §5).
|
|
@@ -1111,111 +1565,259 @@ var PairStartRequest = z8.object({
|
|
|
1111
1565
|
device: PublicIdentity,
|
|
1112
1566
|
capabilities: CapabilityMatrix
|
|
1113
1567
|
}).strict();
|
|
1114
|
-
var PairStartResponse =
|
|
1568
|
+
var PairStartResponse = z9.object({
|
|
1115
1569
|
/** Secret the daemon polls with. Never shown to the user. */
|
|
1116
|
-
deviceCode:
|
|
1570
|
+
deviceCode: z9.string().min(20),
|
|
1117
1571
|
/** Short code the user reads and confirms in the browser. */
|
|
1118
|
-
userCode:
|
|
1572
|
+
userCode: z9.string().min(4).max(16),
|
|
1119
1573
|
/** Where the user approves. Must be on the server's own origin. */
|
|
1120
|
-
verificationUrl:
|
|
1574
|
+
verificationUrl: z9.url(),
|
|
1121
1575
|
/** Epoch ms after which the code is dead ({@link MUSTS.PAIR_CODE_EXPIRES}). */
|
|
1122
|
-
expiresAt:
|
|
1576
|
+
expiresAt: z9.number().int().positive(),
|
|
1123
1577
|
/** How often the daemon may poll. */
|
|
1124
|
-
pollIntervalMs:
|
|
1578
|
+
pollIntervalMs: z9.number().int().min(500).max(6e4)
|
|
1125
1579
|
}).strict();
|
|
1126
|
-
var PairPollRequest =
|
|
1127
|
-
protocolVersion:
|
|
1128
|
-
action:
|
|
1129
|
-
deviceCode:
|
|
1580
|
+
var PairPollRequest = z9.object({
|
|
1581
|
+
protocolVersion: z9.literal(PROTOCOL_VERSION),
|
|
1582
|
+
action: z9.literal("poll"),
|
|
1583
|
+
deviceCode: z9.string().min(20)
|
|
1130
1584
|
}).strict();
|
|
1131
|
-
var PairPollResponse =
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
status:
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1585
|
+
var PairPollResponse = z9.discriminatedUnion("status", [
|
|
1586
|
+
z9.object({ status: z9.literal("pending") }).strict(),
|
|
1587
|
+
z9.object({ status: z9.literal("denied") }).strict(),
|
|
1588
|
+
z9.object({ status: z9.literal("expired") }).strict(),
|
|
1589
|
+
z9.object({
|
|
1590
|
+
status: z9.literal("approved"),
|
|
1591
|
+
// `runnerToken` is gone — cloud_008 §2.4, finding 37.
|
|
1592
|
+
//
|
|
1593
|
+
// It was minted here, hashed into `RunnerRecord.tokenHash`, written to
|
|
1594
|
+
// the daemon's pairings file, and then **never sent, never looked up
|
|
1595
|
+
// and never compared**. `getRunnerByTokenHash` existed on both stores
|
|
1596
|
+
// and was called by nothing but a test asserting it returns null.
|
|
1597
|
+
//
|
|
1598
|
+
// Not merely dead wire, which is what `audienceAllow` and
|
|
1599
|
+
// `HeartbeatResponse.leases` were. This was a *secret*: minted,
|
|
1600
|
+
// transmitted, and written to two disks at rest, for nothing. A
|
|
1601
|
+
// credential with no purpose is a liability rather than clutter,
|
|
1602
|
+
// because the only thing it can ever do is leak.
|
|
1603
|
+
//
|
|
1604
|
+
// `REQUESTS_SIGNED_NOT_BEARER` was already the rule and was already
|
|
1605
|
+
// enforced — every authenticated call is signed by the device's pinned
|
|
1606
|
+
// identity key. This removes the thing the MUST is named after.
|
|
1607
|
+
runnerId: z9.string().min(1),
|
|
1140
1608
|
/** The app's id for the approving user — this daemon's owner forever. */
|
|
1141
|
-
owner:
|
|
1609
|
+
owner: z9.string().min(1),
|
|
1142
1610
|
/** Display name for the trust UI, if the app offers one. */
|
|
1143
|
-
ownerLabel:
|
|
1611
|
+
ownerLabel: z9.string().optional(),
|
|
1144
1612
|
/**
|
|
1145
|
-
* The
|
|
1613
|
+
* The sites this pairing covers, for the daemon to pin (byollm_009 §5),
|
|
1614
|
+
* keyed by each site's identity key id — cloud_009 §5.
|
|
1146
1615
|
*
|
|
1147
|
-
* Returned only on approval
|
|
1616
|
+
* Returned only on approval: a pending or denied poll learns nothing,
|
|
1148
1617
|
* so an unapproved code cannot be used to enumerate a site's keys.
|
|
1618
|
+
*
|
|
1619
|
+
* **One pairing per upstream, not one per site.** A user who connects a
|
|
1620
|
+
* site on a web dashboard has no reason to go back to a laptop and run
|
|
1621
|
+
* a command, so which sites a pairing covers is a projection of consent
|
|
1622
|
+
* — refreshed on the heartbeat — rather than something frozen at
|
|
1623
|
+
* pairing. A direct site answers with exactly one entry, which is the
|
|
1624
|
+
* same shape and not a special case.
|
|
1625
|
+
*
|
|
1626
|
+
* Keyed by the id `stub.site` carries (Amendment A §A.3), so the
|
|
1627
|
+
* runner's lookup is a map read rather than a join across two
|
|
1628
|
+
* namespaces.
|
|
1149
1629
|
*/
|
|
1150
|
-
|
|
1630
|
+
sites: z9.record(z9.string().min(1), PublicIdentity)
|
|
1151
1631
|
}).strict()
|
|
1152
1632
|
]);
|
|
1153
|
-
var PairRequest =
|
|
1633
|
+
var PairRequest = z9.discriminatedUnion("action", [
|
|
1154
1634
|
PairStartRequest,
|
|
1155
1635
|
PairPollRequest
|
|
1156
1636
|
]);
|
|
1157
|
-
var ClaimRequest =
|
|
1158
|
-
protocolVersion:
|
|
1159
|
-
runnerId:
|
|
1637
|
+
var ClaimRequest = z9.object({
|
|
1638
|
+
protocolVersion: z9.literal(PROTOCOL_VERSION),
|
|
1639
|
+
runnerId: z9.string().min(1),
|
|
1160
1640
|
/** Re-sent on every claim so a server never matches against a stale matrix. */
|
|
1161
1641
|
capabilities: CapabilityMatrix,
|
|
1162
1642
|
/** Upper bound on jobs to return; the server may return fewer. */
|
|
1163
|
-
max:
|
|
1643
|
+
max: z9.number().int().min(1).max(64)
|
|
1164
1644
|
}).strict();
|
|
1165
|
-
var ClaimResponse =
|
|
1645
|
+
var ClaimResponse = z9.object({
|
|
1166
1646
|
/**
|
|
1167
1647
|
* Stubs, not jobs. The payload arrives from `fetch`, sealed to whichever
|
|
1168
1648
|
* device claimed — see {@link JobStub} for the exhaustive metadata list.
|
|
1169
1649
|
*/
|
|
1170
|
-
jobs:
|
|
1650
|
+
jobs: z9.array(ClaimedStub),
|
|
1171
1651
|
/** Lease duration granted, so the daemon knows its renewal deadline. */
|
|
1172
|
-
leaseMs:
|
|
1652
|
+
leaseMs: z9.number().int().positive()
|
|
1173
1653
|
}).strict();
|
|
1174
|
-
var HeartbeatRequest =
|
|
1175
|
-
protocolVersion:
|
|
1176
|
-
runnerId:
|
|
1177
|
-
daemonVersion:
|
|
1654
|
+
var HeartbeatRequest = z9.object({
|
|
1655
|
+
protocolVersion: z9.literal(PROTOCOL_VERSION),
|
|
1656
|
+
runnerId: z9.string().min(1),
|
|
1657
|
+
daemonVersion: z9.string().min(1),
|
|
1178
1658
|
capabilities: CapabilityMatrix,
|
|
1659
|
+
/**
|
|
1660
|
+
* Kinds this device is withholding, and why it can be said.
|
|
1661
|
+
*
|
|
1662
|
+
* Optional so a daemon that has nothing withheld sends nothing, and so an
|
|
1663
|
+
* older daemon against a newer hub is simply a device with no withheld
|
|
1664
|
+
* kinds rather than a parse failure.
|
|
1665
|
+
*/
|
|
1666
|
+
withheld: z9.array(WithheldKind).default([]),
|
|
1179
1667
|
/**
|
|
1180
1668
|
* Leases this daemon believes it holds; the server renews exactly these.
|
|
1181
1669
|
*
|
|
1182
1670
|
* Lease ids rather than job ids, so a replayed heartbeat cannot renew a
|
|
1183
1671
|
* grant the runner no longer holds — see {@link Lease.id}.
|
|
1184
1672
|
*/
|
|
1185
|
-
activeLeases:
|
|
1186
|
-
|
|
1673
|
+
activeLeases: z9.array(
|
|
1674
|
+
z9.object({ jobId: z9.string().min(1), leaseId: z9.string().min(1) })
|
|
1187
1675
|
),
|
|
1188
1676
|
/** True while the owner has the daemon paused; the server stops offering work. */
|
|
1189
|
-
paused:
|
|
1677
|
+
paused: z9.boolean()
|
|
1190
1678
|
}).strict();
|
|
1191
|
-
var HeartbeatResponse =
|
|
1192
|
-
/**
|
|
1193
|
-
|
|
1679
|
+
var HeartbeatResponse = z9.object({
|
|
1680
|
+
/**
|
|
1681
|
+
* The sites this daemon may serve, right now — cloud_008 finding 59.
|
|
1682
|
+
*
|
|
1683
|
+
* Revocation used to be a boolean, and it was device-wide: the daemon
|
|
1684
|
+
* plane refused every call when the (owner, hub-site) consent was gone,
|
|
1685
|
+
* heartbeat answered `revoked: true` with `lost: all`, and the daemon
|
|
1686
|
+
* dropped its whole pairing by origin. Under a hub that is one site's
|
|
1687
|
+
* revocation ending a machine's relationship with every other site it
|
|
1688
|
+
* served — the amplification finding 48 warned about, arriving through
|
|
1689
|
+
* the one field nobody thought of as tenancy.
|
|
1690
|
+
*
|
|
1691
|
+
* So the answer is the set. A site that leaves it is revoked *for that
|
|
1692
|
+
* site*: the daemon drops that pin and keeps the rest. An empty set is
|
|
1693
|
+
* what "revoked" used to mean, and the daemon can see that for itself
|
|
1694
|
+
* rather than being told a second time — two fields for one fact is how
|
|
1695
|
+
* they drift.
|
|
1696
|
+
*/
|
|
1697
|
+
sites: z9.record(z9.string().min(1), PublicIdentity),
|
|
1698
|
+
/**
|
|
1699
|
+
* How a site's current key traces back to one this daemon already holds —
|
|
1700
|
+
* byollm_009 Amendment C.
|
|
1701
|
+
*
|
|
1702
|
+
* Keyed by the same id as `sites`, and **additive on purpose**: `sites`
|
|
1703
|
+
* remains the one statement of which key is current, and this says only
|
|
1704
|
+
* how that key got there. Two fields for one fact is how they drift; this
|
|
1705
|
+
* is two facts, and the second is evidence about the first.
|
|
1706
|
+
*
|
|
1707
|
+
* Optional because a site that has never rotated has no chain, which is
|
|
1708
|
+
* every site today. A daemon that receives one for an id it already holds
|
|
1709
|
+
* ignores it: the pin it has is the pin it approved.
|
|
1710
|
+
*
|
|
1711
|
+
* §12 carries what this adds to the metadata surface — a site's rotation
|
|
1712
|
+
* history is public by construction, because a daemon that cannot read it
|
|
1713
|
+
* cannot verify it.
|
|
1714
|
+
*/
|
|
1715
|
+
successions: z9.record(
|
|
1716
|
+
z9.string().min(1),
|
|
1717
|
+
z9.object({
|
|
1718
|
+
/** Oldest last, as the projection carries it. */
|
|
1719
|
+
succeeds: z9.array(Succession).max(MAX_SUCCESSION_CHAIN),
|
|
1720
|
+
/**
|
|
1721
|
+
* Until when the superseded key may still sign work — epoch ms.
|
|
1722
|
+
*
|
|
1723
|
+
* The daemon holds its own clock against this, for the reason it
|
|
1724
|
+
* holds its own allowlist: a projection that could extend the
|
|
1725
|
+
* window indefinitely would be a two-key site forever, decided by
|
|
1726
|
+
* the party this design does not trust.
|
|
1727
|
+
*/
|
|
1728
|
+
retiringUntil: z9.number().int().positive().optional()
|
|
1729
|
+
}).strict()
|
|
1730
|
+
).optional(),
|
|
1194
1731
|
/**
|
|
1195
1732
|
* Per-job cancel (byollm_001 Rev 1 §C). The daemon aborts these jobs'
|
|
1196
1733
|
* in-flight backend calls and reports them `canceled`.
|
|
1734
|
+
*
|
|
1735
|
+
* **The grant, not the id** — V1-3. Job ids are chosen per site, so two
|
|
1736
|
+
* sites may pick the same one, and a bare id told a daemon holding both
|
|
1737
|
+
* to abort whichever it happened to have filed under that name. The lease
|
|
1738
|
+
* is the unique grant and the daemon already keys its work by it; this is
|
|
1739
|
+
* the same shape `activeLeases` sends in the other direction.
|
|
1197
1740
|
*/
|
|
1198
|
-
cancel:
|
|
1199
|
-
|
|
1200
|
-
leases: z8.array(
|
|
1201
|
-
z8.object({
|
|
1202
|
-
jobId: z8.string().min(1),
|
|
1203
|
-
expiresAt: z8.number().int().positive()
|
|
1204
|
-
}).strict()
|
|
1741
|
+
cancel: z9.array(
|
|
1742
|
+
z9.object({ jobId: z9.string().min(1), leaseId: z9.string().min(1) }).strict()
|
|
1205
1743
|
),
|
|
1744
|
+
// `leases` is deliberately absent — cloud_008 §1.4b, finding 16.
|
|
1745
|
+
//
|
|
1746
|
+
// It carried "these leases were renewed, and here is the new expiry", and
|
|
1747
|
+
// **no daemon ever read it.** A mutation returning an empty list while
|
|
1748
|
+
// renewing correctly survived every test, which is what made it visible.
|
|
1749
|
+
//
|
|
1750
|
+
// It is neither a class nor membership, so Amendment A's rule does not
|
|
1751
|
+
// decide it — the older test does: nothing reads it, so it is dead wire.
|
|
1752
|
+
// §6's exhaustiveness is a commitment about what an upstream can see, and
|
|
1753
|
+
// it applies to every message rather than only to the stub.
|
|
1754
|
+
//
|
|
1755
|
+
// `lost` is the actionable signal and always was: a daemon stops work on
|
|
1756
|
+
// a lease it no longer holds. "Renewed" was the same question answered a
|
|
1757
|
+
// second time, and a second answer can only agree or contradict.
|
|
1758
|
+
//
|
|
1759
|
+
// Renewal itself is untouched — the upstream still extends the grants a
|
|
1760
|
+
// heartbeat names, which is what §0.6 fixed. What ended is telling the
|
|
1761
|
+
// daemon about it in a field it ignored. If an upstream ever needs to
|
|
1762
|
+
// push lease decisions, that is a new field with a reader, added on
|
|
1763
|
+
// purpose.
|
|
1206
1764
|
/**
|
|
1207
1765
|
* Jobs the daemon thinks it holds but the server has reassigned or
|
|
1208
1766
|
* expired. The daemon must stop work on these and not report results.
|
|
1767
|
+
*
|
|
1768
|
+
* Named by grant rather than by id, for V1-3's reason: a bare id is
|
|
1769
|
+
* ambiguous across sites, and "the lease you no longer hold" is exactly
|
|
1770
|
+
* what this field means anyway.
|
|
1209
1771
|
*/
|
|
1210
|
-
lost:
|
|
1772
|
+
lost: z9.array(
|
|
1773
|
+
z9.object({ jobId: z9.string().min(1), leaseId: z9.string().min(1) }).strict()
|
|
1774
|
+
),
|
|
1211
1775
|
/** Server clock, so a daemon with a skewed clock still honors leases. */
|
|
1212
|
-
serverTime:
|
|
1776
|
+
serverTime: z9.number().int().positive(),
|
|
1777
|
+
/**
|
|
1778
|
+
* Sites whose disclosure the user must read again before work moves —
|
|
1779
|
+
* cloud_008 finding 48, named rather than counted.
|
|
1780
|
+
*
|
|
1781
|
+
* A **subset of `sites`**, deliberately: a paused site keeps its pin, so
|
|
1782
|
+
* re-consenting never costs a re-pair. The daemon can say which site is
|
|
1783
|
+
* waiting and the user can go and read it, which is the difference
|
|
1784
|
+
* between a machine that is quietly idle and one that says why.
|
|
1785
|
+
*
|
|
1786
|
+
* Not `revoked`, which is a human ending a relationship, and not
|
|
1787
|
+
* `paused`, which on the request side already means "this daemon's
|
|
1788
|
+
* operator stopped it" — one word with two subjects on two halves of one
|
|
1789
|
+
* exchange is a confusion nobody untangles from a log.
|
|
1790
|
+
*/
|
|
1791
|
+
awaitingConsent: z9.array(z9.string().min(1))
|
|
1213
1792
|
}).strict();
|
|
1214
|
-
var ResultDisposition =
|
|
1215
|
-
var ResultRequest =
|
|
1216
|
-
protocolVersion:
|
|
1217
|
-
runnerId:
|
|
1218
|
-
jobId:
|
|
1793
|
+
var ResultDisposition = z9.enum(["ok", "error", "canceled"]);
|
|
1794
|
+
var ResultRequest = z9.object({
|
|
1795
|
+
protocolVersion: z9.literal(PROTOCOL_VERSION),
|
|
1796
|
+
runnerId: z9.string().min(1),
|
|
1797
|
+
jobId: z9.string().min(1),
|
|
1798
|
+
/**
|
|
1799
|
+
* The grant this result was produced under — cloud_008 §1.4a.
|
|
1800
|
+
*
|
|
1801
|
+
* `fetch` has always named its lease, with the reasoning written beside
|
|
1802
|
+
* it: a request that names only the job would be answerable for whatever
|
|
1803
|
+
* lease exists when it arrives. **The operation that writes the result did
|
|
1804
|
+
* not**, on either plane, and checked only the runner id — which survives
|
|
1805
|
+
* a claim-release-reclaim cycle, so a device whose grant had been swept
|
|
1806
|
+
* and reissued could still land a result for a job it no longer held.
|
|
1807
|
+
*
|
|
1808
|
+
* Found by tracing a mutation that survived in §0.6: the lease lapsed, the
|
|
1809
|
+
* sweep requeued, the daemon re-claimed under a new grant, and the
|
|
1810
|
+
* original run finished and posted anyway. The relay marked the job done
|
|
1811
|
+
* with a result the site cannot open — it verifies the envelope against
|
|
1812
|
+
* the *current* holder's device, so the crypto contains the substitution —
|
|
1813
|
+
* and then refused the real holder's result as a replay. A lost job, in
|
|
1814
|
+
* silence.
|
|
1815
|
+
*
|
|
1816
|
+
* `LEASE_HONORED` is a statement about a lease *instance*. That was
|
|
1817
|
+
* learned once already, when a replayed release yanked a later grant, and
|
|
1818
|
+
* it applies here for the same reason.
|
|
1819
|
+
*/
|
|
1820
|
+
leaseId: z9.string().min(1),
|
|
1219
1821
|
/**
|
|
1220
1822
|
* The outcome, sealed to the site and signed by the device.
|
|
1221
1823
|
*
|
|
@@ -1231,26 +1833,48 @@ var ResultRequest = z8.object({
|
|
|
1231
1833
|
* fact: believing it unverified would let a daemon mark a job `ok` while
|
|
1232
1834
|
* sealing an error, and only the app would ever find out.
|
|
1233
1835
|
*/
|
|
1234
|
-
disposition: ResultDisposition
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1836
|
+
disposition: ResultDisposition
|
|
1837
|
+
// `model`, `backendClass` and `durationMs` are **inside the envelope** —
|
|
1838
|
+
// cloud_008 §2.5. See {@link RunMetadata}.
|
|
1839
|
+
//
|
|
1840
|
+
// They were here, in the clear, and that was two problems wearing one
|
|
1841
|
+
// coat. On the direct plane the site recorded unauthenticated fields
|
|
1842
|
+
// beside an authenticated answer: a daemon could seal one result and
|
|
1843
|
+
// declare a different model, and only the unsigned half would reach the
|
|
1844
|
+
// app. Through a relay they reached a third party that acts on none of
|
|
1845
|
+
// them — `model` in particular being the sort of detail Amendment A's
|
|
1846
|
+
// rule keeps off the wire.
|
|
1847
|
+
//
|
|
1848
|
+
// `disposition` stays, and the difference is the test: a relay *routes*
|
|
1849
|
+
// on it, so it is a class a routing party consumes. Nobody between the
|
|
1850
|
+
// two ends consumes these.
|
|
1240
1851
|
}).strict();
|
|
1241
|
-
var ResultResponse =
|
|
1852
|
+
var ResultResponse = z9.object({
|
|
1242
1853
|
/**
|
|
1243
|
-
* False when
|
|
1244
|
-
*
|
|
1245
|
-
* ({@link MUSTS.RESULT_IDEMPOTENT}).
|
|
1854
|
+
* False when this submission wrote nothing — the daemon should discard,
|
|
1855
|
+
* not retry ({@link MUSTS.RESULT_IDEMPOTENT}).
|
|
1246
1856
|
*/
|
|
1247
|
-
accepted:
|
|
1857
|
+
accepted: z9.boolean(),
|
|
1858
|
+
/**
|
|
1859
|
+
* True when this device had already recorded this job's result.
|
|
1860
|
+
*
|
|
1861
|
+
* The difference between "already recorded" and "you no longer hold this"
|
|
1862
|
+
* — cloud_008 §3.6. A daemon whose acknowledgment was lost is in the first
|
|
1863
|
+
* case and needs to hear it: its answer is safely on disk. Reporting a
|
|
1864
|
+
* stale lease instead invents a worry about a result that is already
|
|
1865
|
+
* stored, and sends its owner looking for a routing problem.
|
|
1866
|
+
*
|
|
1867
|
+
* Set only for the device that finished the job. A different device gets
|
|
1868
|
+
* the same refusal it would get for a job that is *not* terminal, so a job
|
|
1869
|
+
* id cannot be used as a terminality probe.
|
|
1870
|
+
*/
|
|
1871
|
+
duplicate: z9.boolean().optional(),
|
|
1248
1872
|
/** The job's state after this submission. */
|
|
1249
|
-
state:
|
|
1873
|
+
state: z9.string().min(1)
|
|
1250
1874
|
}).strict();
|
|
1251
|
-
var ReleaseRequest =
|
|
1252
|
-
protocolVersion:
|
|
1253
|
-
runnerId:
|
|
1875
|
+
var ReleaseRequest = z9.object({
|
|
1876
|
+
protocolVersion: z9.literal(PROTOCOL_VERSION),
|
|
1877
|
+
runnerId: z9.string().min(1),
|
|
1254
1878
|
/**
|
|
1255
1879
|
* Which leases to release — the grant, not just the job.
|
|
1256
1880
|
*
|
|
@@ -1258,8 +1882,8 @@ var ReleaseRequest = z8.object({
|
|
|
1258
1882
|
* moment it arrives, which for a replayed request is not the lease the
|
|
1259
1883
|
* daemon meant. See {@link Lease.id}.
|
|
1260
1884
|
*/
|
|
1261
|
-
leases:
|
|
1262
|
-
|
|
1885
|
+
leases: z9.array(
|
|
1886
|
+
z9.object({ jobId: z9.string().min(1), leaseId: z9.string().min(1) })
|
|
1263
1887
|
),
|
|
1264
1888
|
/**
|
|
1265
1889
|
* Why, so the app's runner list can say something true.
|
|
@@ -1270,39 +1894,152 @@ var ReleaseRequest = z8.object({
|
|
|
1270
1894
|
* stop offering that job to that runner, or the pair would spin between
|
|
1271
1895
|
* claim and release forever.
|
|
1272
1896
|
*/
|
|
1273
|
-
reason:
|
|
1897
|
+
reason: z9.enum(["shutdown", "pause", "revoked", "backend-down", "refused"])
|
|
1274
1898
|
}).strict();
|
|
1275
|
-
var ReleaseResponse =
|
|
1276
|
-
released:
|
|
1899
|
+
var ReleaseResponse = z9.object({
|
|
1900
|
+
released: z9.array(z9.string().min(1))
|
|
1277
1901
|
}).strict();
|
|
1278
|
-
var WireErrorCode =
|
|
1902
|
+
var WireErrorCode = z9.enum([
|
|
1279
1903
|
"bad-request",
|
|
1280
1904
|
"unsupported-protocol-version",
|
|
1905
|
+
// "We do not know who you are." Exactly 401, and only that — cloud_008
|
|
1906
|
+
// §1.4d.
|
|
1281
1907
|
"unauthorized",
|
|
1908
|
+
/**
|
|
1909
|
+
* "We know exactly who you are, and the answer is no." Exactly 403.
|
|
1910
|
+
*
|
|
1911
|
+
* Five refusals across both planes served 403 with `unauthorized`, whose
|
|
1912
|
+
* table entry is 401: a revoked device, a site claiming another site's
|
|
1913
|
+
* stub, a job you do not hold, a device belonging to another owner, a
|
|
1914
|
+
* relay that does not route for you. Every one of them is an *identified*
|
|
1915
|
+
* caller being refused.
|
|
1916
|
+
*
|
|
1917
|
+
* Collapsing the two loses a distinction that matters everywhere it is
|
|
1918
|
+
* read: a revoked daemon would look like an unsigned one in every log and
|
|
1919
|
+
* every client branch, and "check your keys" is the wrong advice for both
|
|
1920
|
+
* of them in opposite directions.
|
|
1921
|
+
*/
|
|
1922
|
+
"forbidden",
|
|
1282
1923
|
"revoked",
|
|
1283
1924
|
"not-found",
|
|
1925
|
+
// Claimed, but the site has not sealed the payload yet — cloud_008 §1.4.
|
|
1926
|
+
//
|
|
1927
|
+
// A daemon must retry rather than abandon: the job is legitimately still
|
|
1928
|
+
// its own until the lease or the awaiting-payload clock says otherwise.
|
|
1929
|
+
// That is why it cannot be `not-found` or `server-error`, and why it was
|
|
1930
|
+
// the protocol gap that produced a bare 409 in the first place.
|
|
1931
|
+
"not-ready",
|
|
1932
|
+
/**
|
|
1933
|
+
* The job is over, and this call is about a job — V1-6, and the code the
|
|
1934
|
+
* site plane has been serving without one (V1-13).
|
|
1935
|
+
*
|
|
1936
|
+
* Distinct from `not-found`, which says "no such job", and from
|
|
1937
|
+
* `not-ready`, which says "not yet, keep asking". This one says "yes, and
|
|
1938
|
+
* it finished" — so a daemon must stop rather than retry, and a replayed
|
|
1939
|
+
* request must not be able to reopen it.
|
|
1940
|
+
*/
|
|
1941
|
+
"too-late",
|
|
1942
|
+
// The caller's clock is too far from ours to judge a signature's freshness.
|
|
1943
|
+
//
|
|
1944
|
+
// Split out from `unauthorized` because the remedy is completely different
|
|
1945
|
+
// and only the server can tell them apart: a bad signature means the key is
|
|
1946
|
+
// wrong, this means the machine's time is wrong. A daemon reporting it as a
|
|
1947
|
+
// generic rejection sends its owner looking at their network.
|
|
1948
|
+
"clock-skew",
|
|
1284
1949
|
"rate-limited",
|
|
1285
1950
|
"server-error"
|
|
1286
1951
|
]);
|
|
1287
|
-
var WireError =
|
|
1952
|
+
var WireError = z9.object({
|
|
1288
1953
|
error: WireErrorCode,
|
|
1289
|
-
message:
|
|
1954
|
+
message: z9.string().min(1),
|
|
1955
|
+
/**
|
|
1956
|
+
* What this server speaks, on `unsupported-protocol-version` — §B.4.
|
|
1957
|
+
*
|
|
1958
|
+
* The refusal has carried these since the version handshake existed and
|
|
1959
|
+
* the enumeration did not model them, so the one error that exists to be
|
|
1960
|
+
* *acted on* was the one that failed to parse as a wire error. Found by
|
|
1961
|
+
* the relay's own suite the day the relay started sending it: a refusal
|
|
1962
|
+
* outside the enumerated shape is a refusal a client cannot branch on,
|
|
1963
|
+
* which is the whole reason §1.4 enumerates them.
|
|
1964
|
+
*
|
|
1965
|
+
* Modelled the way `clock-skew`'s two fields already are — code-specific
|
|
1966
|
+
* extras, refused on any other code by the refinement below.
|
|
1967
|
+
*/
|
|
1968
|
+
supported: z9.array(z9.string().min(1)).optional(),
|
|
1969
|
+
minimum: z9.string().min(1).optional(),
|
|
1290
1970
|
/** Seconds; mirrors Retry-After for `rate-limited` and `server-error`. */
|
|
1291
|
-
retryAfter:
|
|
1292
|
-
|
|
1971
|
+
retryAfter: z9.number().int().nonnegative().optional(),
|
|
1972
|
+
/**
|
|
1973
|
+
* The server's clock, and the window it allows. `clock-skew` only.
|
|
1974
|
+
*
|
|
1975
|
+
* So the far side can say *how far off* rather than *that something is
|
|
1976
|
+
* wrong* — the difference between "adjust your clock by four minutes" and
|
|
1977
|
+
* "something is wrong with your connection". Not a disclosure: the
|
|
1978
|
+
* heartbeat response returns the same value, and so does every `Date`
|
|
1979
|
+
* header.
|
|
1980
|
+
*/
|
|
1981
|
+
serverTime: z9.number().int().positive().optional(),
|
|
1982
|
+
maxSkewMs: z9.number().int().positive().optional()
|
|
1983
|
+
}).strict().superRefine((error, ctx) => {
|
|
1984
|
+
const skew = error.error === "clock-skew";
|
|
1985
|
+
const carried = error.serverTime !== void 0 || error.maxSkewMs !== void 0;
|
|
1986
|
+
if (skew && !carried) {
|
|
1987
|
+
ctx.addIssue({
|
|
1988
|
+
code: "custom",
|
|
1989
|
+
message: "clock-skew must carry serverTime and maxSkewMs"
|
|
1990
|
+
});
|
|
1991
|
+
}
|
|
1992
|
+
if (!skew && carried) {
|
|
1993
|
+
ctx.addIssue({
|
|
1994
|
+
code: "custom",
|
|
1995
|
+
message: `${error.error} must not carry serverTime or maxSkewMs`
|
|
1996
|
+
});
|
|
1997
|
+
}
|
|
1998
|
+
const version = error.error === "unsupported-protocol-version";
|
|
1999
|
+
const versionFields = error.supported !== void 0 || error.minimum !== void 0;
|
|
2000
|
+
if (version && !versionFields) {
|
|
2001
|
+
ctx.addIssue({
|
|
2002
|
+
code: "custom",
|
|
2003
|
+
message: "unsupported-protocol-version must carry supported and minimum"
|
|
2004
|
+
});
|
|
2005
|
+
}
|
|
2006
|
+
if (!version && versionFields) {
|
|
2007
|
+
ctx.addIssue({
|
|
2008
|
+
code: "custom",
|
|
2009
|
+
message: `${error.error} must not carry supported or minimum`
|
|
2010
|
+
});
|
|
2011
|
+
}
|
|
2012
|
+
});
|
|
1293
2013
|
var ERROR_STATUS = Object.freeze({
|
|
1294
2014
|
"bad-request": 400,
|
|
1295
2015
|
"unsupported-protocol-version": 400,
|
|
1296
2016
|
unauthorized: 401,
|
|
2017
|
+
forbidden: 403,
|
|
1297
2018
|
revoked: 403,
|
|
1298
2019
|
"not-found": 404,
|
|
2020
|
+
// 409, not 404: the job exists and is yours, it is simply not ready.
|
|
2021
|
+
"not-ready": 409,
|
|
2022
|
+
// The same 409 as `not-ready` and the opposite instruction: that one says
|
|
2023
|
+
// keep asking, this one says stop. The status is the class of the
|
|
2024
|
+
// problem — a request that does not fit the resource's state — and the
|
|
2025
|
+
// code is what a caller acts on.
|
|
2026
|
+
"too-late": 409,
|
|
2027
|
+
// 401 alongside `unauthorized`, because that is what it is — the
|
|
2028
|
+
// signature could not be judged. The code is what carries the remedy.
|
|
2029
|
+
"clock-skew": 401,
|
|
1299
2030
|
"rate-limited": 429,
|
|
1300
2031
|
"server-error": 500
|
|
1301
2032
|
});
|
|
1302
|
-
var FetchRequest =
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
2033
|
+
var FetchRequest = z9.object({
|
|
2034
|
+
// `literal`, like every other request — V1-17. This one said
|
|
2035
|
+
// `string().min(1)`, so a daemon speaking a version this server does not
|
|
2036
|
+
// know got past the handshake on the one endpoint that hands over a
|
|
2037
|
+
// sealed payload. The version check exists so that a mismatch is a named
|
|
2038
|
+
// refusal rather than a schema failure three fields later; here it was
|
|
2039
|
+
// neither.
|
|
2040
|
+
protocolVersion: z9.literal(PROTOCOL_VERSION),
|
|
2041
|
+
runnerId: z9.string().min(1),
|
|
2042
|
+
jobId: z9.string().min(1),
|
|
1306
2043
|
/**
|
|
1307
2044
|
* The grant this daemon holds.
|
|
1308
2045
|
*
|
|
@@ -1310,9 +2047,9 @@ var FetchRequest = z8.object({
|
|
|
1310
2047
|
* only the job would be answerable for whatever lease exists when it
|
|
1311
2048
|
* arrives ({@link Lease.id}).
|
|
1312
2049
|
*/
|
|
1313
|
-
leaseId:
|
|
2050
|
+
leaseId: z9.string().min(1)
|
|
1314
2051
|
}).strict();
|
|
1315
|
-
var FetchResponse =
|
|
2052
|
+
var FetchResponse = z9.object({
|
|
1316
2053
|
/**
|
|
1317
2054
|
* The work, sealed to the device that claimed it — byollm_009 §6.
|
|
1318
2055
|
*
|
|
@@ -1340,6 +2077,7 @@ export {
|
|
|
1340
2077
|
ClaimedJob,
|
|
1341
2078
|
ClaimedStub,
|
|
1342
2079
|
DeliveredResult,
|
|
2080
|
+
ENCRYPTION_KEY_CONTEXT,
|
|
1343
2081
|
ENDPOINTS,
|
|
1344
2082
|
ENVELOPE_MAX_AGE_MS,
|
|
1345
2083
|
ERROR_STATUS,
|
|
@@ -1353,6 +2091,7 @@ export {
|
|
|
1353
2091
|
JobKind,
|
|
1354
2092
|
JobOutcome,
|
|
1355
2093
|
JobPayload,
|
|
2094
|
+
JobRefused,
|
|
1356
2095
|
JobResultCanceled,
|
|
1357
2096
|
JobResultError,
|
|
1358
2097
|
JobResultOk,
|
|
@@ -1361,6 +2100,7 @@ export {
|
|
|
1361
2100
|
KindedPayload,
|
|
1362
2101
|
Lease,
|
|
1363
2102
|
MAX_CLOCK_SKEW_MS,
|
|
2103
|
+
MAX_SUCCESSION_CHAIN,
|
|
1364
2104
|
MIN_PROTOCOL_VERSION,
|
|
1365
2105
|
MUSTS,
|
|
1366
2106
|
MUST_IDS,
|
|
@@ -1377,6 +2117,8 @@ export {
|
|
|
1377
2117
|
PairStartResponse,
|
|
1378
2118
|
PublicIdentity,
|
|
1379
2119
|
REFUSAL_MESSAGES,
|
|
2120
|
+
RETIREMENT_WINDOW_MS,
|
|
2121
|
+
RefusalReason,
|
|
1380
2122
|
ReleaseRequest,
|
|
1381
2123
|
ReleaseResponse,
|
|
1382
2124
|
RequestSignature,
|
|
@@ -1384,27 +2126,35 @@ export {
|
|
|
1384
2126
|
ResultProvenance,
|
|
1385
2127
|
ResultRequest,
|
|
1386
2128
|
ResultResponse,
|
|
2129
|
+
RunMetadata,
|
|
1387
2130
|
SIZE_CLASS_LIMITS,
|
|
2131
|
+
SUCCESSION_CONTEXT,
|
|
1388
2132
|
SUPPORTED_PROTOCOL_VERSIONS,
|
|
1389
2133
|
SealedEnvelope,
|
|
2134
|
+
SealedOutcome,
|
|
1390
2135
|
SizeClass,
|
|
1391
2136
|
StoredKeys,
|
|
2137
|
+
Succession,
|
|
1392
2138
|
TERMINAL_STATES,
|
|
1393
2139
|
WireError,
|
|
1394
2140
|
WireErrorCode,
|
|
2141
|
+
WithheldKind,
|
|
1395
2142
|
backendDescriptor,
|
|
1396
2143
|
canTransition,
|
|
1397
2144
|
canonicalRequest,
|
|
1398
2145
|
checkProtocolVersion,
|
|
1399
2146
|
cryptoReady,
|
|
2147
|
+
declaredVersion,
|
|
1400
2148
|
effectiveOfferScope,
|
|
1401
2149
|
fingerprint,
|
|
1402
2150
|
generateKeys,
|
|
1403
2151
|
isBackendId,
|
|
2152
|
+
isCloudTaggedModel,
|
|
1404
2153
|
isJobKind,
|
|
1405
2154
|
isLocalHost,
|
|
1406
2155
|
isTerminal,
|
|
1407
2156
|
keyId,
|
|
2157
|
+
kindsOf,
|
|
1408
2158
|
matchAudience,
|
|
1409
2159
|
mustsVerifiedBy,
|
|
1410
2160
|
open,
|
|
@@ -1414,11 +2164,17 @@ export {
|
|
|
1414
2164
|
resolveCost,
|
|
1415
2165
|
seal,
|
|
1416
2166
|
signRequest,
|
|
2167
|
+
signSiteRequest,
|
|
2168
|
+
signSuccession,
|
|
1417
2169
|
signWith,
|
|
1418
2170
|
sizeClassCeiling,
|
|
1419
2171
|
sizeClassOf,
|
|
2172
|
+
successionStatement,
|
|
2173
|
+
verifyLink,
|
|
1420
2174
|
verifyPublicIdentity,
|
|
1421
2175
|
verifyRequest,
|
|
1422
|
-
|
|
2176
|
+
verifySiteRequest,
|
|
2177
|
+
verifyWith,
|
|
2178
|
+
walkSuccession
|
|
1423
2179
|
};
|
|
1424
2180
|
//# sourceMappingURL=index.js.map
|