@byollm/protocol 0.1.0-alpha.6 → 0.1.0-alpha.61

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/dist/index.js CHANGED
@@ -2,8 +2,10 @@
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"]);
8
+ var BACKEND_CLASSES = Object.freeze(BackendClass.options);
7
9
  var BackendCost = z.enum(["free", "metered", "subscription"]);
8
10
  var backend = (b) => Object.freeze(b);
9
11
  var BACKENDS = Object.freeze({
@@ -162,6 +164,24 @@ var BACKENDS = Object.freeze({
162
164
  class: "process",
163
165
  cost: "subscription",
164
166
  adversarialCorpus: "process"
167
+ }),
168
+ /**
169
+ * OpenAI's Codex CLI, on a ChatGPT plan — byollm_016 stage 3.
170
+ *
171
+ * `subscription`, so `SUBSCRIPTION_SELF_LOCK` pins it to its owner's own
172
+ * work whatever the config says. That is load-bearing here in a way it is
173
+ * not for `claude-cli`: Codex is an *agent*, and its default feature set
174
+ * includes a shell tool, browser control and computer use. The daemon
175
+ * disables every one of them, verified against the shipped binary rather
176
+ * than assumed — see `codex-cli.ts` — but the self-lock is the floor under
177
+ * that verification rather than a duplicate of it.
178
+ */
179
+ "codex-cli": backend({
180
+ id: "codex-cli",
181
+ label: "Codex CLI (your ChatGPT plan)",
182
+ class: "process",
183
+ cost: "subscription",
184
+ adversarialCorpus: "process"
165
185
  })
166
186
  });
167
187
  var BACKEND_IDS = Object.freeze(Object.keys(BACKENDS));
@@ -177,42 +197,87 @@ function backendDescriptor(id) {
177
197
  function isLocalHost(hostname) {
178
198
  const host = hostname.toLowerCase().replace(/^\[|\]$/g, "");
179
199
  if (host === "localhost" || host.endsWith(".localhost")) return true;
180
- if (host === "::1") return true;
200
+ const version = isIP(host);
201
+ if (version === 0) return false;
202
+ if (version === 6) {
203
+ if (host === "::1") return true;
204
+ return /^f[cd]/.test(host);
205
+ }
181
206
  if (host.startsWith("127.")) return true;
182
207
  if (host.startsWith("10.")) return true;
183
208
  if (host.startsWith("192.168.")) return true;
184
- if (/^172\.(1[6-9]|2\d|3[01])\./.test(host)) return true;
185
- if (/^f[cd]/.test(host)) return true;
186
- return false;
209
+ return /^172\.(1[6-9]|2\d|3[01])\./.test(host);
187
210
  }
188
- function resolveCost(id, baseUrl) {
211
+ function isCloudTaggedModel(model) {
212
+ return /:[^:]*cloud$/.test(model);
213
+ }
214
+ function resolveCost(id, baseUrl, model) {
215
+ return classifyCost(id, baseUrl, model).cost;
216
+ }
217
+ function backendName(id) {
218
+ return BACKENDS[id].label.replace(/\s*\([^)]*\)$/, "");
219
+ }
220
+ function classifyCost(id, baseUrl, model) {
189
221
  const declared = BACKENDS[id].cost;
190
- if (declared !== null) return declared;
191
- if (baseUrl === void 0) return "metered";
222
+ if (declared !== null) {
223
+ const label = BACKENDS[id].label;
224
+ return {
225
+ cost: declared,
226
+ because: {
227
+ subscription: `${label} runs on an account you subscribe to`,
228
+ metered: `${label} bills per token`,
229
+ free: `${label} runs on this machine`
230
+ }[declared]
231
+ };
232
+ }
233
+ if (model !== void 0 && isCloudTaggedModel(model)) {
234
+ return {
235
+ cost: "metered",
236
+ because: `its model tag ends in \`:cloud\`, so the work runs on your provider's cloud account rather than on this machine`
237
+ };
238
+ }
239
+ if (baseUrl === void 0) {
240
+ return {
241
+ cost: "metered",
242
+ because: "it has no address, so where the work runs cannot be checked"
243
+ };
244
+ }
192
245
  try {
193
- return isLocalHost(new URL(baseUrl).hostname) ? "free" : "metered";
246
+ return isLocalHost(new URL(baseUrl).hostname) ? { cost: "free", because: "it runs on this machine" } : {
247
+ cost: "metered",
248
+ because: "its address is not on this machine, so the work leaves it"
249
+ };
194
250
  } catch {
195
- return "metered";
251
+ return {
252
+ cost: "metered",
253
+ because: "its address cannot be read, so where the work runs is unknown"
254
+ };
196
255
  }
197
256
  }
198
257
 
199
258
  // src/audience.ts
200
- var Audience = z2.enum(["self", "named", "public"]);
201
- var OfferScope = z2.enum(["self", "named", "public"]);
259
+ var Audience = z2.enum(["private", "team"]);
260
+ var OfferScope = z2.enum(["private", "team"]);
202
261
  var AUDIENCES = Object.freeze(Audience.options);
203
262
  var OFFER_SCOPES = Object.freeze(OfferScope.options);
204
263
  var MatchRefusal = z2.enum([
205
264
  /** The daemon advertises no capability for this kind. */
206
265
  "no-capability",
207
- /** Job is `self` but this daemon belongs to a different user. */
266
+ /** Job is `private` but this daemon belongs to a different user. */
208
267
  "audience-self-other-owner",
209
- /** Job is `named` but this daemon's local allowlist does not admit the owner. */
268
+ /**
269
+ * Job is `team` and nothing this device verified admits the job's owner.
270
+ *
271
+ * The id predates the grant and is kept, because ids are public and cited
272
+ * by conformance output. What it means has not moved: this device was not
273
+ * shown anything it could check.
274
+ */
210
275
  "not-locally-allowed",
211
- /** Job is `named`/`public` but the server's own allowlist excludes this runner. */
276
+ /** Job is `team` but the server's own allowlist excludes this runner. */
212
277
  "not-in-server-allowlist",
213
- /** The backend offers only `self` and the job belongs to someone else. */
278
+ /** The service offers only `private` and the job belongs to someone else. */
214
279
  "offer-scope-too-narrow",
215
- /** The matched backend is subscription-class, which is locked to `self`. */
280
+ /** The matched backend is subscription-class, which is locked to `private`. */
216
281
  "subscription-self-lock",
217
282
  /** The backend spends the owner's money and they have not agreed to share it. */
218
283
  "metered-no-spend-consent",
@@ -222,16 +287,16 @@ var MatchRefusal = z2.enum([
222
287
  var ALLOWED = Object.freeze({ ok: true });
223
288
  var refuse = (refusal) => Object.freeze({ ok: false, refusal });
224
289
  function effectiveOfferScope(configured, cost, spend) {
225
- if (cost === "subscription") return "self";
226
- if (cost === "metered" && spend?.acknowledged !== true) return "self";
290
+ if (cost === "subscription") return "private";
291
+ if (cost === "metered" && spend?.acknowledged !== true) return "private";
227
292
  return configured;
228
293
  }
229
294
  function matchAudience(job, daemon) {
230
295
  const sameOwner = job.owner === daemon.owner;
231
- if (job.audience === "self" && !sameOwner) {
296
+ if (job.audience === "private" && !sameOwner) {
232
297
  return refuse("audience-self-other-owner");
233
298
  }
234
- if (job.audience === "named" && !sameOwner && job.audienceAllow !== void 0 && !job.audienceAllow.includes(daemon.owner)) {
299
+ if (job.audience === "team" && !sameOwner && job.audienceAllow !== void 0 && !job.audienceAllow.includes(daemon.owner)) {
235
300
  return refuse("not-in-server-allowlist");
236
301
  }
237
302
  const scope = effectiveOfferScope(
@@ -254,20 +319,18 @@ function matchAudience(job, daemon) {
254
319
  }
255
320
  }
256
321
  switch (scope) {
257
- case "self":
322
+ case "private":
258
323
  return refuse("offer-scope-too-narrow");
259
- case "named":
260
- return daemon.locallyAllows(job.owner) ? ALLOWED : refuse("not-locally-allowed");
261
- case "public":
262
- return ALLOWED;
324
+ case "team":
325
+ return daemon.admits(job.owner) ? ALLOWED : refuse("not-locally-allowed");
263
326
  }
264
327
  }
265
328
  var REFUSAL_MESSAGES = Object.freeze({
266
- "no-capability": "no backend on this machine is configured and healthy for that job kind",
267
- "audience-self-other-owner": "the job is private to its owner and this machine is paired to someone else",
268
- "not-locally-allowed": "the job's owner is not on this machine's allowlist (byollm allow <server> <user>)",
269
- "not-in-server-allowlist": "the app restricted this job to named runners and this machine is not one of them",
270
- "offer-scope-too-narrow": "this backend is offered to its owner only (byollm offer <backend> named|public to widen)",
329
+ "no-capability": "no backend on this device is configured and healthy for that job kind",
330
+ "audience-self-other-owner": "the job is private to its owner and this device is paired to someone else",
331
+ "not-locally-allowed": "nothing this device can verify says the job's owner may use it",
332
+ "not-in-server-allowlist": "the app restricted this job to named runners and this device is not one of them",
333
+ "offer-scope-too-narrow": "this service is offered to its owner only (`byollm offer <service> team` to widen)",
271
334
  "subscription-self-lock": "subscription-backed models run their owner's work only \u2014 this is a protocol rule, not a setting",
272
335
  "metered-no-spend-consent": "this backend bills its owner per token, and they have not agreed to spend it on other people's work",
273
336
  "metered-ceiling-reached": "this backend is shared but has reached the spend ceiling its owner set"
@@ -286,20 +349,33 @@ var PAYLOAD_LIMITS = Object.freeze({
286
349
  var ChatMessage = z3.object({
287
350
  role: z3.enum(["system", "user", "assistant"]),
288
351
  content: z3.string().max(PAYLOAD_LIMITS.maxTextChars)
289
- });
352
+ }).strict();
290
353
  var GeneratePayload = z3.object({
291
354
  prompt: z3.string().min(1).max(PAYLOAD_LIMITS.maxTextChars),
292
355
  system: z3.string().max(PAYLOAD_LIMITS.maxTextChars).optional()
293
- }).strict();
356
+ }).strict().refine(
357
+ (payload) => payload.prompt.length + (payload.system?.length ?? 0) <= PAYLOAD_LIMITS.maxTotalChars,
358
+ {
359
+ message: `payload exceeds ${String(PAYLOAD_LIMITS.maxTotalChars)} characters`
360
+ }
361
+ );
294
362
  var ChatPayload = z3.object({
295
363
  messages: z3.array(ChatMessage).min(1).max(PAYLOAD_LIMITS.maxMessages),
296
364
  system: z3.string().max(PAYLOAD_LIMITS.maxTextChars).optional()
297
- }).strict();
365
+ }).strict().refine(
366
+ (payload) => payload.messages.reduce((sum, m) => sum + m.content.length, 0) + (payload.system?.length ?? 0) <= PAYLOAD_LIMITS.maxTotalChars,
367
+ {
368
+ message: `payload exceeds ${String(PAYLOAD_LIMITS.maxTotalChars)} characters`
369
+ }
370
+ );
298
371
  var JobKind = z3.enum(["llm.generate", "llm.chat"]);
299
372
  var JOB_KINDS = Object.freeze(JobKind.options);
300
373
  var KindedPayload = z3.discriminatedUnion("kind", [
301
- z3.object({ kind: z3.literal("llm.generate"), payload: GeneratePayload }),
302
- z3.object({ kind: z3.literal("llm.chat"), payload: ChatPayload })
374
+ // Strict on the wrappers too. A union member that strips is a door beside
375
+ // the one that is locked: the payloads inside are strict, and an extra key
376
+ // on the envelope vanished just as quietly.
377
+ z3.object({ kind: z3.literal("llm.generate"), payload: GeneratePayload }).strict(),
378
+ z3.object({ kind: z3.literal("llm.chat"), payload: ChatPayload }).strict()
303
379
  ]);
304
380
  function isJobKind(value) {
305
381
  return JOB_KINDS.includes(value);
@@ -316,161 +392,12 @@ function payloadTextLength(kinded) {
316
392
  }
317
393
 
318
394
  // src/job.ts
319
- import { z as z4 } from "zod";
320
- var JobState = z4.enum([
321
- "queued",
322
- "claimed",
323
- "running",
324
- "ok",
325
- "error",
326
- "canceled",
327
- "expired"
328
- ]);
329
- var TERMINAL_STATES = Object.freeze([
330
- "ok",
331
- "error",
332
- "canceled",
333
- "expired"
334
- ]);
335
- function isTerminal(state) {
336
- return TERMINAL_STATES.includes(state);
337
- }
338
- var TRANSITIONS = Object.freeze({
339
- queued: ["claimed", "expired", "canceled"],
340
- // A claimed job returns to `queued` when its lease expires un-renewed
341
- // ({@link MUSTS.LEASE_RECLAIMABLE}).
342
- claimed: ["running", "queued", "canceled", "error"],
343
- running: ["ok", "error", "canceled", "queued"],
344
- ok: [],
345
- error: [],
346
- canceled: [],
347
- expired: []
348
- });
349
- function canTransition(from, to) {
350
- return TRANSITIONS[from].includes(to);
351
- }
352
- var Lease = z4.object({
353
- /**
354
- * Identifies *this* grant, not just its holder.
355
- *
356
- * A runner can hold a job, release it, and claim it again — three leases,
357
- * one runner id. Without an id for the grant itself, a lease-scoped request
358
- * names a mutable target ambiguously, and a replayed release from the first
359
- * grant lands on the third: the job returns to the queue while the daemon
360
- * is mid-execution, and the work runs twice on the owner's hardware.
361
- *
362
- * That was a live hole, found in review after signed requests shipped. The
363
- * signature scheme's replay argument rests on endpoints being idempotent —
364
- * and release *is*, per lease, but not across leases, because nothing in
365
- * the request said which one.
366
- */
367
- id: z4.string().min(1),
368
- /** The runner holding the lease. */
369
- runnerId: z4.string().min(1),
370
- /** Epoch milliseconds after which the claim is void. */
371
- expiresAt: z4.number().int().positive()
372
- });
373
- var JobPayload = z4.union([GeneratePayload, ChatPayload]);
374
- var ClaimedJob = z4.object({
375
- id: z4.string().min(1),
376
- kind: JobKind,
377
- payload: JobPayload,
378
- audience: Audience,
379
- /** The app's id for the user who enqueued it. */
380
- owner: z4.string().min(1),
381
- /** Runner owners the app restricted a `named` job to, if any. */
382
- audienceAllow: z4.array(z4.string().min(1)).optional(),
383
- lease: Lease
384
- }).strict();
385
- var ResultProvenance = z4.object({
386
- /** The audience the job ran under. */
387
- audience: Audience,
388
- /** The runner that produced it. */
389
- runnerId: z4.string().min(1),
390
- /** The runner owner's id in this app's namespace. */
391
- runnerOwner: z4.string().min(1),
392
- /** Which backend class produced it — an HTTP call or a sandboxed spawn. */
393
- backendClass: BackendClass,
394
- /** The model the runner reports having used. */
395
- model: z4.string().min(1),
396
- /**
397
- * False only for `self` jobs. When true the app MUST treat `text` as
398
- * untrusted third-party content.
399
- */
400
- untrusted: z4.boolean()
401
- }).strict();
402
- function provenanceFor(input) {
403
- return {
404
- audience: input.audience,
405
- runnerId: input.runnerId,
406
- runnerOwner: input.runnerOwner,
407
- backendClass: input.backendClass,
408
- model: input.model,
409
- untrusted: input.audience !== "self"
410
- };
411
- }
412
- var JobResultOk = z4.object({
413
- outcome: z4.literal("ok"),
414
- text: z4.string(),
415
- /** Optional reference to a stored artifact; never a local path. */
416
- artifactUrl: z4.url().optional()
417
- }).strict();
418
- var JobResultError = z4.object({
419
- outcome: z4.literal("error"),
420
- code: z4.string().min(1),
421
- message: z4.string().min(1),
422
- /** Whether the app may reasonably re-enqueue. */
423
- retryable: z4.boolean()
424
- }).strict();
425
- var JobResultCanceled = z4.object({
426
- outcome: z4.literal("canceled")
427
- }).strict();
428
- var JobOutcome = z4.discriminatedUnion("outcome", [
429
- JobResultOk,
430
- JobResultError,
431
- JobResultCanceled
432
- ]);
433
- var DeliveredResult = z4.object({
434
- jobId: z4.string().min(1),
435
- state: JobState,
436
- outcome: JobOutcome.optional(),
437
- provenance: ResultProvenance.optional()
438
- }).strict();
439
- var SizeClass = z4.enum(["small", "medium", "large", "unbounded"]);
440
- var SIZE_CLASS_LIMITS = Object.freeze({
441
- small: 4e3,
442
- medium: 64e3,
443
- large: Number.POSITIVE_INFINITY
444
- });
445
- function sizeClassCeiling(sizeClass) {
446
- if (sizeClass === "unbounded") return Number.POSITIVE_INFINITY;
447
- return SIZE_CLASS_LIMITS[sizeClass];
448
- }
449
- function sizeClassOf(textChars) {
450
- if (textChars <= SIZE_CLASS_LIMITS.small) return "small";
451
- if (textChars <= SIZE_CLASS_LIMITS.medium) return "medium";
452
- return "large";
453
- }
454
- var JobStub = z4.object({
455
- id: z4.string().min(1),
456
- kind: JobKind,
457
- /** The app's id for the user who enqueued it. */
458
- owner: z4.string().min(1),
459
- audience: Audience,
460
- audienceAllow: z4.array(z4.string().min(1)).optional(),
461
- sizeClass: SizeClass,
462
- /** Reserved for byollm_006. False until streaming exists. */
463
- streaming: z4.boolean(),
464
- /** Epoch ms after which the work is pointless; bounds ciphertext retention. */
465
- deadlineAt: z4.number().int().positive()
466
- }).strict();
467
- var ClaimedStub = JobStub.extend({ lease: Lease }).strict();
468
-
469
- // src/envelope.ts
470
- import { createPrivateKey as createPrivateKey2, createPublicKey as createPublicKey2 } from "crypto";
471
- import sodium from "libsodium-wrappers";
472
395
  import { z as z6 } from "zod";
473
396
 
397
+ // src/grant.ts
398
+ import { Buffer as Buffer2 } from "buffer";
399
+ import { z as z5 } from "zod";
400
+
474
401
  // src/keys.ts
475
402
  import {
476
403
  createHash,
@@ -480,12 +407,12 @@ import {
480
407
  sign,
481
408
  verify
482
409
  } from "crypto";
483
- import { z as z5 } from "zod";
484
- var PublicIdentity = z5.object({
410
+ import { z as z4 } from "zod";
411
+ var PublicIdentity = z4.object({
485
412
  /** Raw Ed25519 public key. The pinned one. */
486
- identity: z5.string().min(1),
413
+ identity: z4.string().min(1),
487
414
  /** Raw X25519 public key, for sealing to this party. */
488
- encryption: z5.string().min(1),
415
+ encryption: z4.string().min(1),
489
416
  /**
490
417
  * Ed25519 signature over the encryption key, by the identity key.
491
418
  *
@@ -493,16 +420,16 @@ var PublicIdentity = z5.object({
493
420
  * own while relaying a genuine identity: the receiver pins the identity
494
421
  * and refuses any encryption key not signed by it.
495
422
  */
496
- encryptionSig: z5.string().min(1)
423
+ encryptionSig: z4.string().min(1)
497
424
  }).strict();
498
- var StoredKeys = z5.object({
499
- version: z5.literal(1),
500
- identityPublic: z5.string().min(1),
501
- identityPrivate: z5.string().min(1),
502
- encryptionPublic: z5.string().min(1),
503
- encryptionPrivate: z5.string().min(1),
504
- encryptionSig: z5.string().min(1),
505
- createdAt: z5.number().int().positive()
425
+ var StoredKeys = z4.object({
426
+ version: z4.literal(1),
427
+ identityPublic: z4.string().min(1),
428
+ identityPrivate: z4.string().min(1),
429
+ encryptionPublic: z4.string().min(1),
430
+ encryptionPrivate: z4.string().min(1),
431
+ encryptionSig: z4.string().min(1),
432
+ createdAt: z4.number().int().positive()
506
433
  }).strict();
507
434
  var ENCRYPTION_KEY_CONTEXT = "byollm/v1/encryption-key";
508
435
  function rawPublic(key) {
@@ -595,21 +522,451 @@ function fingerprint(identityPublic) {
595
522
  }
596
523
  var keyId = (identityPublic) => fingerprint(identityPublic);
597
524
 
525
+ // src/grant.ts
526
+ var GRANT_MAX_AGE_MS = 12e4;
527
+ var CLOCK_SKEW_WARN_MS = 3e4;
528
+ var CLOCK_ATTRIBUTION_MS = 5e3;
529
+ var GRANT_CONTEXT = "byollm/v1/grant";
530
+ var SignedGrant = z5.object({
531
+ /**
532
+ * This grant's own id — what makes it single-use.
533
+ *
534
+ * **Not the job id, and the difference is load-bearing.** Binding
535
+ * single-use to `jobId` would refuse a legitimate retry: a claim that
536
+ * times out is re-claimed, the control plane authors a second grant for
537
+ * the same job, and a device that recorded the job id as spent would
538
+ * reject its own recovery. A fresh id per authorship replays nothing and
539
+ * retries fine.
540
+ */
541
+ grantId: z5.string().min(1),
542
+ /**
543
+ * The job this grant admits, and only this one.
544
+ *
545
+ * A grant lifted from one job and presented for another is the obvious
546
+ * attack, and this field is why it fails.
547
+ */
548
+ jobId: z5.string().min(1),
549
+ /**
550
+ * The site the work came from, **as a key id** — byollm-review 2026-08-27.
551
+ *
552
+ * This was `siteId`, holding the site's id in the control plane's
553
+ * namespace, and it was signed by the engine and read by nobody. A signed
554
+ * field nobody checks is not a weak guarantee, it is the appearance of
555
+ * one: the design says "the grant carries the site", and nothing anywhere
556
+ * compared it to anything.
557
+ *
558
+ * It could not be compared. Job ids are chosen per site, so a grant
559
+ * authored for (site A, `job_1`) satisfied every device check against a
560
+ * stub naming (site B, `job_1`) — but the device holds sites only by the
561
+ * key ids it pinned, and had no way to relate a control-plane uuid to
562
+ * one. Checking the field would have meant a lookup through the party the
563
+ * grant exists to distrust.
564
+ *
565
+ * So the namespace changes to the one the device already has, and the
566
+ * name changes with it: this is the same value as {@link JobStub.site},
567
+ * compared directly, no lookup and nothing to believe. The control-plane
568
+ * id is not carried alongside — it had no reader, and keeping an
569
+ * unchecked field beside a checked one is how this hole was dug.
570
+ */
571
+ site: z5.string().min(1),
572
+ /** Whose job it is — the person the site enqueued for. */
573
+ user: z5.string().min(1),
574
+ /**
575
+ * Whose device it is for.
576
+ *
577
+ * Passed to {@link verifyGrant} rather than read out of the document, for
578
+ * the reason every verifier here takes its subject as an argument: a
579
+ * verifier that recovered the owner from the signed bytes would accept a
580
+ * genuine grant belonging to somebody else and pass every check.
581
+ */
582
+ owner: z5.string().min(1),
583
+ /** The site purpose this job serves — byollm_016 Amendment L. */
584
+ purpose: z5.string().min(1),
585
+ /** The kind of work. */
586
+ kind: z5.string().min(1),
587
+ /**
588
+ * The service the control plane resolved this (purpose, kind) to, from
589
+ * the user's own mapping.
590
+ *
591
+ * Selection is the control plane's; **offer-consistency is the
592
+ * device's**. A device verifies it actually offers this service, at a
593
+ * scope that includes {@link user}, before running anything.
594
+ */
595
+ service: z5.string().min(1),
596
+ /** When the control plane signed it — epoch ms, the only anchor for age. */
597
+ issuedAt: z5.number().int().positive(),
598
+ /** Base64url Ed25519 over {@link grantStatement}. */
599
+ signature: z5.string().min(1)
600
+ }).strict();
601
+ var GRANT_SIGNED_FIELDS = Object.freeze(
602
+ Object.keys(SignedGrant.shape).filter((key) => key !== "signature").sort()
603
+ );
604
+ function grantStatement(claims) {
605
+ return Buffer2.from(
606
+ JSON.stringify([
607
+ GRANT_CONTEXT,
608
+ ...GRANT_SIGNED_FIELDS.map((field) => claims[field])
609
+ ]),
610
+ "utf8"
611
+ );
612
+ }
613
+ function signGrant(keys, claims) {
614
+ return { ...claims, signature: signWith(keys, grantStatement(claims)) };
615
+ }
616
+ function verifyGrant(input) {
617
+ const { grant, now } = input;
618
+ if (grant.owner !== input.owner) return "wrong-owner";
619
+ if (grant.jobId !== input.jobId) return "wrong-job";
620
+ const age = now - grant.issuedAt;
621
+ if (age < -CLOCK_SKEW_WARN_MS) return "from-the-future";
622
+ if (age > (input.maxAgeMs ?? GRANT_MAX_AGE_MS)) return "expired";
623
+ return verifyWith(
624
+ input.controlPlanePublic,
625
+ grantStatement(grant),
626
+ grant.signature
627
+ ) ? null : "bad-signature";
628
+ }
629
+
630
+ // src/job.ts
631
+ var JobState = z6.enum([
632
+ "queued",
633
+ "claimed",
634
+ "running",
635
+ "ok",
636
+ "error",
637
+ "canceled",
638
+ "expired"
639
+ ]);
640
+ var TERMINAL_STATES = Object.freeze([
641
+ "ok",
642
+ "error",
643
+ "canceled",
644
+ "expired"
645
+ ]);
646
+ function isTerminal(state) {
647
+ return TERMINAL_STATES.includes(state);
648
+ }
649
+ var TRANSITIONS = Object.freeze({
650
+ queued: ["claimed", "expired", "canceled"],
651
+ // A claimed job returns to `queued` when its lease expires un-renewed
652
+ // ({@link MUSTS.LEASE_RECLAIMABLE}).
653
+ claimed: ["running", "queued", "canceled", "error"],
654
+ running: ["ok", "error", "canceled", "queued"],
655
+ ok: [],
656
+ error: [],
657
+ canceled: [],
658
+ expired: []
659
+ });
660
+ function canTransition(from, to) {
661
+ return TRANSITIONS[from].includes(to);
662
+ }
663
+ var Lease = z6.object({
664
+ /**
665
+ * Identifies *this* grant, not just its holder.
666
+ *
667
+ * A runner can hold a job, release it, and claim it again — three leases,
668
+ * one runner id. Without an id for the grant itself, a lease-scoped request
669
+ * names a mutable target ambiguously, and a replayed release from the first
670
+ * grant lands on the third: the job returns to the queue while the daemon
671
+ * is mid-execution, and the work runs twice on the owner's hardware.
672
+ *
673
+ * That was a live hole, found in review after signed requests shipped. The
674
+ * signature scheme's replay argument rests on endpoints being idempotent —
675
+ * and release *is*, per lease, but not across leases, because nothing in
676
+ * the request said which one.
677
+ */
678
+ id: z6.string().min(1),
679
+ /** The runner holding the lease. */
680
+ runnerId: z6.string().min(1),
681
+ /** Epoch milliseconds after which the claim is void. */
682
+ expiresAt: z6.number().int().positive()
683
+ }).strict();
684
+ var JobPayload = z6.union([GeneratePayload, ChatPayload]);
685
+ var ClaimedJob = z6.object({
686
+ id: z6.string().min(1),
687
+ kind: JobKind,
688
+ payload: JobPayload,
689
+ audience: Audience,
690
+ /** The app's id for the user who enqueued it. */
691
+ owner: z6.string().min(1),
692
+ /**
693
+ * Which site's job — V1-3.
694
+ *
695
+ * The stub has always carried it; the opened job did not, so everything
696
+ * downstream of the payload — the ingress line above all — recorded a job
697
+ * id that belongs to a site without saying which. Two sites can choose
698
+ * the same id, and the meter is the product.
699
+ *
700
+ * Optional so a caller assembling a job by hand is not forced to invent
701
+ * one, and so this reads as what it is: a fact about where the work came
702
+ * from, not a second copy of the routing key.
703
+ */
704
+ site: z6.string().min(1).optional(),
705
+ /**
706
+ * Which of the owner's services runs this — resolved, not requested.
707
+ *
708
+ * The daemon picks the backend from this, so it has to be the answer
709
+ * rather than a wish. On a relayed route it is copied off the **grant**,
710
+ * where a control plane put the person's own mapping and signed it; a
711
+ * site never named it and could not.
712
+ *
713
+ * It used to be what the site asked for, which made a job that selected a
714
+ * non-default service liable to be served by the default instead — the
715
+ * substitution `NO_PAYLOAD_ROUTING` forbids. Amendment L removed the
716
+ * asking; what is left is the answering.
717
+ *
718
+ * Optional, because direct mode has no control plane to resolve anything
719
+ * and the owner's own defaults answer under the ambiguity law.
720
+ */
721
+ service: z6.string().min(1).optional(),
722
+ lease: Lease
723
+ }).strict();
724
+ var ResultProvenance = z6.object({
725
+ /** The audience the job ran under. */
726
+ audience: Audience,
727
+ /** The runner that produced it. */
728
+ runnerId: z6.string().min(1),
729
+ /** The runner owner's id in this app's namespace. */
730
+ runnerOwner: z6.string().min(1),
731
+ /** Which backend class produced it — an HTTP call or a sandboxed spawn. */
732
+ backendClass: BackendClass,
733
+ /** The model the runner reports having used. */
734
+ model: z6.string().min(1),
735
+ /**
736
+ * False only for `self` jobs. When true the app MUST treat `text` as
737
+ * untrusted third-party content.
738
+ */
739
+ untrusted: z6.boolean()
740
+ }).strict();
741
+ function provenanceFor(input) {
742
+ return {
743
+ audience: input.audience,
744
+ runnerId: input.runnerId,
745
+ runnerOwner: input.runnerOwner,
746
+ backendClass: input.backendClass,
747
+ model: input.model,
748
+ untrusted: input.audience !== "private"
749
+ };
750
+ }
751
+ var RunMetadata = z6.object({
752
+ /** Which model actually served it. */
753
+ model: z6.string().min(1),
754
+ backendClass: BackendClass,
755
+ /** Wall-clock milliseconds the backend call took. */
756
+ durationMs: z6.number().int().nonnegative()
757
+ }).strict();
758
+ var JobResultOk = z6.object({
759
+ outcome: z6.literal("ok"),
760
+ text: z6.string(),
761
+ /** Optional reference to a stored artifact; never a local path. */
762
+ artifactUrl: z6.url().optional()
763
+ }).strict();
764
+ var JobResultError = z6.object({
765
+ outcome: z6.literal("error"),
766
+ code: z6.string().min(1),
767
+ message: z6.string().min(1),
768
+ /** Whether the app may reasonably re-enqueue. */
769
+ retryable: z6.boolean()
770
+ }).strict();
771
+ var JobResultCanceled = z6.object({
772
+ outcome: z6.literal("canceled")
773
+ }).strict();
774
+ var JobOutcome = z6.discriminatedUnion("outcome", [
775
+ JobResultOk,
776
+ JobResultError,
777
+ JobResultCanceled
778
+ ]);
779
+ var RefusalReason = z6.enum([
780
+ /**
781
+ * Two or more services answer this kind and the owner has named no default,
782
+ * so the kind is withheld. Nobody may pick on the owner's behalf — the wrong
783
+ * guess is the metered one.
784
+ *
785
+ * Told apart from its neighbour deliberately, and the line is whether a
786
+ * requester can walk a namespace. There are two kinds; asking about one
787
+ * enumerates nothing they could not learn from what the device advertises,
788
+ * and the difference is actionable — "the owner has not chosen" is fixable
789
+ * by the owner, "the default cannot serve you" is not. It is also already
790
+ * what a team member sees on the devices page: `awaitingDefault` carries
791
+ * exactly this, by kind, for exactly this reason.
792
+ */
793
+ "default-ambiguity",
794
+ /**
795
+ * A default exists and this requester can never use it — byollm_016's
796
+ * defaults-meet-audiences corner.
797
+ *
798
+ * The specimen: an owner's default for `llm.chat` is their Claude
799
+ * subscription, self-locked by `SUBSCRIPTION_SELF_LOCK`. A team member's
800
+ * job resolves to it and can never be served by it. That must be a refusal
801
+ * on the spot, not a wait that expires an hour later looking like nobody
802
+ * was online.
803
+ *
804
+ * Bounded like the value above, and unprobeable for the same reason: the
805
+ * requester named nothing, so there is no name space to walk.
806
+ */
807
+ "default-unusable"
808
+ ]);
809
+ var JobRefused = z6.object({
810
+ outcome: z6.literal("refused"),
811
+ reason: RefusalReason,
812
+ /** Plain words for a human reading a log, never parsed. */
813
+ message: z6.string().min(1)
814
+ }).strict();
815
+ var REFUSAL_TEXT = Object.freeze({
816
+ "default-ambiguity": "this device serves that kind from more than one service and its owner has not chosen which",
817
+ "default-unusable": "this device's default for that kind cannot run work for you"
818
+ });
819
+ var SealedOutcome = z6.object({ outcome: JobOutcome, ran: RunMetadata }).strict();
820
+ var DeliveredResult = z6.object({
821
+ jobId: z6.string().min(1),
822
+ state: JobState,
823
+ outcome: JobOutcome.optional(),
824
+ provenance: ResultProvenance.optional(),
825
+ /**
826
+ * Present, and always `true`, when this did not come from a runner —
827
+ * {@link MUSTS.FALLBACK_LABELED}.
828
+ *
829
+ * The app's own `onNoRunner` value produced it: a hosted model, a cached
830
+ * answer, an apology. It never travels on the wire, because nothing on
831
+ * the wire produced it; it exists so that a result which did not come
832
+ * from the user's own compute cannot be reported as though it did.
833
+ *
834
+ * A literal rather than a boolean, so `fallback: false` is not a
835
+ * spelling anybody can reach for. The absence of this field means a
836
+ * runner ran the job, and the *server* stamps it — an app cannot supply
837
+ * a substitute that hides what it is.
838
+ */
839
+ fallback: z6.literal(true).optional()
840
+ }).strict();
841
+ var SizeClass = z6.enum(["small", "medium", "large", "unbounded"]);
842
+ var SIZE_CLASSES = Object.freeze(SizeClass.options);
843
+ var SIZE_CLASS_LIMITS = Object.freeze({
844
+ small: 4e3,
845
+ medium: 64e3,
846
+ large: Number.POSITIVE_INFINITY
847
+ });
848
+ function sizeClassCeiling(sizeClass) {
849
+ if (sizeClass === "unbounded") return Number.POSITIVE_INFINITY;
850
+ return SIZE_CLASS_LIMITS[sizeClass];
851
+ }
852
+ function sizeClassOf(textChars) {
853
+ if (textChars <= SIZE_CLASS_LIMITS.small) return "small";
854
+ if (textChars <= SIZE_CLASS_LIMITS.medium) return "medium";
855
+ return "large";
856
+ }
857
+ var JobStub = z6.object({
858
+ id: z6.string().min(1),
859
+ kind: JobKind,
860
+ /** The app's id for the user who enqueued it. */
861
+ owner: z6.string().min(1),
862
+ /**
863
+ * Which site this job belongs to — byollm_009 Amendment A §A.3.
864
+ *
865
+ * **The site's identity key id**, not an id somebody assigned it. §6 has
866
+ * listed `site` since this spec was frozen; the schema never carried it,
867
+ * which is the drift the amendment closes.
868
+ *
869
+ * A key id rather than an opaque handle for one reason above the others:
870
+ * it makes the stub *self-describing* instead of a pointer into somebody
871
+ * else's table. A daemon holds this key id already, from pinning, so it
872
+ * can check `stub.site` against the payload envelope's `senderKeyId`
873
+ * without a lookup and without trusting the party that routed it. An
874
+ * opaque id can only be believed.
875
+ *
876
+ * It also avoids inventing a second namespace for a thing that has a
877
+ * canonical one — the shape of finding 41 (two owner namespaces compared
878
+ * for equality) and of finding fourteen before it.
879
+ *
880
+ * Rotation is a designed transition rather than a cost: a site publishes a
881
+ * new identity signed by the outgoing one, both are valid through an
882
+ * overlap window, and a daemon re-keys its own map by verifying that
883
+ * signature against the key it already pinned (§A.3.1).
884
+ */
885
+ site: z6.string().min(1),
886
+ audience: Audience,
887
+ // `audienceAllow` is **not** here, and its absence is the enforcement —
888
+ // cloud_008 §0.2.
889
+ //
890
+ // It was a list of the people who may run a job, travelling to every
891
+ // routing party on every shared job. byollm_001 Rev 1 §B settled who
892
+ // decides that long before this schema existed: *the daemon's own list
893
+ // decides, not the server's*, and `allowlist.predicateFor(origin)` is the
894
+ // enforcement in both lanes. So this was a second answer to a question the
895
+ // daemon already owned — able only to agree, in which case it was
896
+ // redundant, or to disagree, in which case nothing said which wins.
897
+ //
898
+ // The rule it leaves behind, which decides the next field too: **a class
899
+ // the router acts on may travel; membership never does.** `audience` stays
900
+ // for exactly that reason — the relay narrows on it. A roster does not
901
+ // travel, so `ROSTER_NOT_DISCLOSED` holds here by absence, which is the
902
+ // strongest way for a MUST to hold.
903
+ //
904
+ // The site keeps its own copy on `JobRecord` and still filters candidates
905
+ // with it before offering. That is server-internal, where the party
906
+ // holding the list authored it.
907
+ /**
908
+ * Which of the site's declared purposes this job serves — Amendment L.
909
+ *
910
+ * **A need, never a name.** The site's vocabulary is its own purposes;
911
+ * the person's is their services; and the two never meet. This field says
912
+ * "writing-assistant", and a control plane joins it to whatever that
913
+ * person mapped it to. The site learns only whether the slot was
914
+ * satisfiable.
915
+ *
916
+ * It replaced `service`, which let a site name one of the owner's
917
+ * services directly. That field is gone from both routes (Amendment L
918
+ * rider) and its refusal machinery with it — including the collapsed
919
+ * `select-unavailable`, which existed so that "no such service" and "not
920
+ * offered to you" could not be told apart. There is nothing left to
921
+ * probe: **a vocabulary that never crosses the boundary cannot be
922
+ * enumerated across it**, which is a stronger guarantee than the one the
923
+ * collapse gave.
924
+ *
925
+ * It travels for the reason the absent `audienceAllow` establishes: *a
926
+ * class the router acts on may travel; membership never does.* A purpose
927
+ * is a class, and the control plane acts on it.
928
+ *
929
+ * Optional because direct mode has no control plane to hold a mapping and
930
+ * is kind-only: the owner's own config and defaults answer, under the
931
+ * ambiguity law as shipped. Absent on a relayed route resolves against
932
+ * the site's reserved purpose, which a site that declared its own
933
+ * purposes will not have mapped — so the slot reads as unmapped and the
934
+ * site falls back, loudly enough and without a special case.
935
+ *
936
+ * A **stub** field and never a payload field, which is the line
937
+ * `NO_PAYLOAD_ROUTING` draws: the prompt cannot reach it, so no amount of
938
+ * user text can influence what runs.
939
+ */
940
+ purpose: z6.string().min(1).optional(),
941
+ sizeClass: SizeClass,
942
+ /** Reserved for byollm_006. False until streaming exists. */
943
+ streaming: z6.boolean(),
944
+ /** Epoch ms after which the work is pointless; bounds ciphertext retention. */
945
+ deadlineAt: z6.number().int().positive()
946
+ }).strict();
947
+ var ClaimedStub = JobStub.extend({
948
+ lease: Lease,
949
+ grant: SignedGrant.optional()
950
+ }).strict();
951
+
598
952
  // src/envelope.ts
953
+ import { createPrivateKey as createPrivateKey2, createPublicKey as createPublicKey2 } from "crypto";
954
+ import sodium from "libsodium-wrappers";
955
+ import { z as z7 } from "zod";
599
956
  var readied;
600
957
  async function cryptoReady() {
601
958
  readied ??= sodium.ready;
602
959
  await readied;
603
960
  }
604
961
  var ENVELOPE_MAX_AGE_MS = 24 * 60 * 6e4;
605
- var EnvelopeDirection = z6.enum(["payload", "result"]);
606
- var SealedEnvelope = z6.object({
962
+ var EnvelopeDirection = z7.enum(["payload", "result"]);
963
+ var SealedEnvelope = z7.object({
607
964
  /** Base64url `crypto_box_seal` output over the signed plaintext. */
608
- ciphertext: z6.string().min(1),
965
+ ciphertext: z7.string().min(1),
609
966
  /** Who this was sealed to — the recipient checks it is them. */
610
- recipientKeyId: z6.string().min(1),
967
+ recipientKeyId: z7.string().min(1),
611
968
  /** Who signed it — the recipient checks this against its pin. */
612
- senderKeyId: z6.string().min(1),
969
+ senderKeyId: z7.string().min(1),
613
970
  direction: EnvelopeDirection,
614
971
  /**
615
972
  * When this ciphertext stops being worth keeping.
@@ -623,7 +980,7 @@ var SealedEnvelope = z6.object({
623
980
  * Not trusted as written: it is also inside the signature, so a changed
624
981
  * deadline fails to verify.
625
982
  */
626
- deadlineAt: z6.number().int().positive()
983
+ deadlineAt: z7.number().int().positive()
627
984
  }).strict();
628
985
  function signedBody(context, plaintext) {
629
986
  return Buffer.from(
@@ -718,15 +1075,15 @@ async function open(input) {
718
1075
 
719
1076
  // src/signing.ts
720
1077
  import { createHash as createHash2 } from "crypto";
721
- import { z as z7 } from "zod";
1078
+ import { z as z8 } from "zod";
722
1079
  var MAX_CLOCK_SKEW_MS = 12e4;
723
- var RequestSignature = z7.object({
1080
+ var RequestSignature = z8.object({
724
1081
  /** Which runner is calling. The server looks up its pinned identity. */
725
- runnerId: z7.string().min(1),
1082
+ runnerId: z8.string().min(1),
726
1083
  /** Epoch ms, bounded by {@link MAX_CLOCK_SKEW_MS}. */
727
- issuedAt: z7.number().int().positive(),
1084
+ issuedAt: z8.number().int().positive(),
728
1085
  /** Base64url Ed25519 signature over {@link canonicalRequest}. */
729
- signature: z7.string().min(1)
1086
+ signature: z8.string().min(1)
730
1087
  }).strict();
731
1088
  function canonicalRequest(input) {
732
1089
  const digest = createHash2("sha256").update(input.body, "utf8").digest("hex");
@@ -748,6 +1105,21 @@ function signRequest(keys, input) {
748
1105
  signature: signWith(keys, canonicalRequest(input))
749
1106
  };
750
1107
  }
1108
+ function signSiteRequest(keys, input) {
1109
+ return signRequest(keys, {
1110
+ endpoint: siteEndpoint(input.endpoint),
1111
+ runnerId: input.siteId,
1112
+ issuedAt: input.issuedAt,
1113
+ body: input.body
1114
+ });
1115
+ }
1116
+ function verifySiteRequest(input) {
1117
+ return verifyRequest({
1118
+ ...input,
1119
+ endpoint: siteEndpoint(input.endpoint)
1120
+ });
1121
+ }
1122
+ var siteEndpoint = (endpoint) => `site/${endpoint}`;
751
1123
  function verifyRequest(input) {
752
1124
  const skew = input.maxSkewMs ?? MAX_CLOCK_SKEW_MS;
753
1125
  if (Math.abs(input.now - input.signature.issuedAt) > skew) return "stale";
@@ -764,7 +1136,119 @@ function verifyRequest(input) {
764
1136
  return ok ? null : "bad-signature";
765
1137
  }
766
1138
 
1139
+ // src/manifest.ts
1140
+ import { z as z9 } from "zod";
1141
+ var RESERVED_PURPOSE = "default";
1142
+ var RENDERABLE = /^[^\p{Cc}\p{Cf}\p{Cs}\p{Co}]+$/u;
1143
+ var renderable = (max, what) => z9.string().min(1).max(max).regex(
1144
+ RENDERABLE,
1145
+ `a ${what} is text a person reads \u2014 no control characters, direction overrides or zero-width padding`
1146
+ ).refine((value) => value.trim() !== "", {
1147
+ message: `a ${what} cannot be blank`
1148
+ });
1149
+ var PurposeKey = z9.string().regex(
1150
+ /^[a-z0-9][a-z0-9-]*$/,
1151
+ "a purpose key is a lowercase slug \u2014 letters, digits and hyphens"
1152
+ ).max(64);
1153
+ var Purpose = z9.object({
1154
+ /**
1155
+ * What a person reads on the consent screen. The only rendered field.
1156
+ *
1157
+ * Declared rather than derived from the key, because a key is a
1158
+ * compromise between machines and this is not. "Writing Assistant" is
1159
+ * what somebody understands; `writing-assistant` is what travels.
1160
+ */
1161
+ label: renderable(80, "label"),
1162
+ /** One line of context for the consent screen. Optional. */
1163
+ description: renderable(280, "description").optional(),
1164
+ /**
1165
+ * The kinds this purpose uses.
1166
+ *
1167
+ * A purpose may span kinds, and a mapping is per (purpose, kind) — so a
1168
+ * person can send this purpose's chat to one service and its generation
1169
+ * to another. Listing a kind here is what makes that slot appear.
1170
+ */
1171
+ kinds: z9.array(JobKind).min(1).max(JOB_KINDS.length).refine((kinds) => new Set(kinds).size === kinds.length, {
1172
+ message: "a purpose lists each kind once"
1173
+ })
1174
+ }).strict();
1175
+ var MAX_PURPOSES = 32;
1176
+ var Manifest = z9.record(PurposeKey, Purpose).refine((manifest) => Object.keys(manifest).length > 0, {
1177
+ message: "a manifest declares at least one purpose"
1178
+ }).refine((manifest) => Object.keys(manifest).length <= MAX_PURPOSES, {
1179
+ message: `a manifest declares at most ${String(MAX_PURPOSES)} purposes \u2014 a consent screen is a set of questions somebody answers one at a time`
1180
+ }).refine((manifest) => !(RESERVED_PURPOSE in manifest), {
1181
+ message: `"${RESERVED_PURPOSE}" is reserved for a site that declares no purposes of its own \u2014 give this one a name from your own vocabulary`
1182
+ });
1183
+ function singlePurposeManifest(input) {
1184
+ return {
1185
+ [RESERVED_PURPOSE]: { label: input.label, kinds: [...input.kinds] }
1186
+ };
1187
+ }
1188
+
1189
+ // src/succession.ts
1190
+ import { z as z10 } from "zod";
1191
+ var SUCCESSION_CONTEXT = "byollm/v1/site-succession";
1192
+ var RETIREMENT_WINDOW_MS = 7 * 24 * 60 * 60 * 1e3;
1193
+ var MAX_SUCCESSION_CHAIN = 64;
1194
+ var Succession = z10.object({
1195
+ /**
1196
+ * The predecessor's public identity — K1, in full.
1197
+ *
1198
+ * The whole identity rather than the key id, because a daemon meeting a
1199
+ * chain it has not seen before has to *verify* each link, and a key id is
1200
+ * a fingerprint: enough to compare, never enough to check a signature.
1201
+ */
1202
+ identity: PublicIdentity,
1203
+ /** K1's signature over the statement naming K1 and its successor. */
1204
+ signature: z10.string().min(1)
1205
+ }).strict();
1206
+ function successionStatement(fromKeyId, toKeyId) {
1207
+ return Buffer.from(`${SUCCESSION_CONTEXT}:${fromKeyId}:${toKeyId}`);
1208
+ }
1209
+ function signSuccession(previous, next) {
1210
+ return {
1211
+ identity: {
1212
+ identity: previous.identityPublic,
1213
+ encryption: previous.encryptionPublic,
1214
+ encryptionSig: previous.encryptionSig
1215
+ },
1216
+ signature: signWith(
1217
+ previous,
1218
+ successionStatement(keyId(previous.identityPublic), keyId(next.identity))
1219
+ )
1220
+ };
1221
+ }
1222
+ function verifyLink(link, toKeyId) {
1223
+ if (!verifyPublicIdentity(link.identity)) return false;
1224
+ return verifyWith(
1225
+ link.identity.identity,
1226
+ successionStatement(keyId(link.identity.identity), toKeyId),
1227
+ link.signature
1228
+ );
1229
+ }
1230
+ function walkSuccession(input) {
1231
+ const { current, chain, approved } = input;
1232
+ if (chain.length === 0) return { path: [current], failure: "no-chain" };
1233
+ if (chain.length > MAX_SUCCESSION_CHAIN)
1234
+ return { path: [current], failure: "too-long" };
1235
+ const steps = [...chain].reverse();
1236
+ const path = [current];
1237
+ let succeeding = current;
1238
+ for (const link of steps) {
1239
+ if (!verifyLink(link, succeeding)) return { path, failure: "broken-link" };
1240
+ const previous = keyId(link.identity.identity);
1241
+ path.unshift(previous);
1242
+ if (approved(previous)) return { path, from: previous };
1243
+ succeeding = previous;
1244
+ }
1245
+ return { path, failure: "unknown-origin" };
1246
+ }
1247
+
767
1248
  // src/musts.ts
1249
+ function kindsOf(must2) {
1250
+ return typeof must2.verifiedBy === "string" ? [must2.verifiedBy] : must2.verifiedBy;
1251
+ }
768
1252
  var must = (m) => Object.freeze(m);
769
1253
  var MUSTS = Object.freeze({
770
1254
  // ---- Pairing and identity -------------------------------------------
@@ -797,6 +1281,50 @@ var MUSTS = Object.freeze({
797
1281
  verifiedBy: "conformance",
798
1282
  source: "byollm_009 \xA74"
799
1283
  }),
1284
+ SITE_KEY_BY_STUB: must({
1285
+ id: "SITE_KEY_BY_STUB",
1286
+ 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.",
1287
+ enforcedBy: "daemon",
1288
+ // Adversarial, and the reason is the finding that produced it: the
1289
+ // honest paths pass with every site check deleted, because `open`
1290
+ // refuses a signature from the wrong key anyway. What distinguishes an
1291
+ // enforced rule from a coincidence here is a hostile pairing of stub and
1292
+ // envelope, which no conformance client would ever send.
1293
+ verifiedBy: "adversarial",
1294
+ source: "byollm_009 \xA7A.3"
1295
+ }),
1296
+ SITES_LOCALLY_APPROVED: must({
1297
+ id: "SITES_LOCALLY_APPROVED",
1298
+ statement: "A daemon MUST NOT run work for a site on an upstream's word alone. An upstream may propose a site set; work for any site in it MUST additionally carry a grant signed by the control-plane key this daemon pinned at pairing. A key that has changed for an id this daemon already pinned 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 pinned, over a statement naming both key ids MUST be accepted \u2014 provided the control plane projects the same successor \u2014 and MUST be announced rather than applied silently. The first job from a site this daemon has never served MUST be announced at the machine.",
1299
+ enforcedBy: "daemon",
1300
+ // Two kinds, and the second is the one that matters — V1-1.
1301
+ //
1302
+ // `construction`: the daemon cannot serve a site that is not in its
1303
+ // pinned map, and admission refuses before a payload is fetched — and
1304
+ // since byollm_016 Amendment K, being in the map is no longer sufficient
1305
+ // either: a signed grant is, and the relay proposing the set cannot
1306
+ // produce one.
1307
+ //
1308
+ // `adversarial`: the property that survives is about a *sequence* —
1309
+ // remove the id, re-offer it under a different key — which no honest
1310
+ // upstream sends and which the fence above does not see. That was the
1311
+ // bypass: the pin was deleted with the id, so the comparison had nothing
1312
+ // to compare against and the substitution arrived as a stranger.
1313
+ // **Not `conformance`, and that is a live gap rather than a judgement.**
1314
+ // Amendment C's succession clause is a rule about two implementations
1315
+ // agreeing, which is what a conformance check is for — but rotating a
1316
+ // site's key is not something `ConformanceTarget` can express, and adding
1317
+ // an optional hook that most targets omit would produce a check reporting
1318
+ // success for a reason unrelated to the property it claims. That is this
1319
+ // project's most-repeated bug, and it is not worth reintroducing for a
1320
+ // stronger-sounding word in a table. The rotation path is verified by
1321
+ // `site-rotation.test.ts` (both directions, against the shipped runner)
1322
+ // and `relay/test/rotation.test.ts` (both planes, against the reference
1323
+ // relay); the missing piece is a second *independent* implementation to
1324
+ // check them against, and there is not one yet.
1325
+ verifiedBy: ["construction", "adversarial"],
1326
+ source: "byollm_009 \xA7B.2, Amendment C"
1327
+ }),
800
1328
  KEYS_EXCHANGED_AT_CONSENT: must({
801
1329
  id: "KEYS_EXCHANGED_AT_CONSENT",
802
1330
  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.",
@@ -928,7 +1456,7 @@ var MUSTS = Object.freeze({
928
1456
  }),
929
1457
  NAMED_LOCAL_ALLOWLIST: must({
930
1458
  id: "NAMED_LOCAL_ALLOWLIST",
931
- statement: "A 'named' job MUST be admitted only by the daemon's own local (server origin, user id) allowlist \u2014 never on the server's assertion alone.",
1459
+ statement: "A 'team' job MUST be admitted only by something the device itself verified, keyed by (server origin, user id) \u2014 never on the routing party's assertion alone.",
932
1460
  enforcedBy: "daemon",
933
1461
  verifiedBy: "conformance",
934
1462
  source: "byollm_001 Rev 1 \xA7B"
@@ -984,12 +1512,12 @@ var MUSTS = Object.freeze({
984
1512
  verifiedBy: "conformance",
985
1513
  source: "byollm_001 \xA7Endpoints.4"
986
1514
  }),
987
- RESULT_PROVENANCE: must({
988
- id: "RESULT_PROVENANCE",
989
- statement: "A result from a non-'self' job MUST carry its provenance (audience and runner) to the delivery seam so an app never treats volunteer output as first-party.",
1515
+ PROVENANCE_NAMES_DEVICE: must({
1516
+ id: "PROVENANCE_NAMES_DEVICE",
1517
+ 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
1518
  enforcedBy: "server",
991
1519
  verifiedBy: "conformance",
992
- source: "byollm_003 Rev 1 \xA7Return-trip"
1520
+ source: "byollm_009 \xA711"
993
1521
  }),
994
1522
  // ---- The trust surface -------------------------------------------------
995
1523
  INGRESS_LOGGED_BEFORE_EXECUTION: must({
@@ -1007,12 +1535,33 @@ var MUSTS = Object.freeze({
1007
1535
  verifiedBy: "adversarial",
1008
1536
  source: "byollm_004 \xA72"
1009
1537
  }),
1538
+ /**
1539
+ * Amended for byollm_016 Phase B, and the amendment is deliberately narrow.
1540
+ *
1541
+ * A site may now name a **service** on the stub. The temptation is to read
1542
+ * that as a crack in this law, so the statement below says exactly where the
1543
+ * line is: a name selects from a menu the owner published, and resolves to a
1544
+ * model, backend, base URL and flags **only** through that owner's own
1545
+ * config. The site supplies a key; the owner supplies every value it maps
1546
+ * to. A name the owner does not advertise is refused rather than
1547
+ * substituted, because substitution is how "you may pick from my list" turns
1548
+ * into "you may ask for anything and get something".
1549
+ *
1550
+ * Two properties keep it from drifting into "sites demand models":
1551
+ *
1552
+ * 1. **Nothing the site sends is ever a value.** No model string, no URL,
1553
+ * no flag crosses the wire — only a key that means nothing off this
1554
+ * owner's machine.
1555
+ * 2. **It is a stub field, never a payload field.** The prompt cannot
1556
+ * reach it. That is unchanged and is the sentence the second clause
1557
+ * below still enforces verbatim.
1558
+ */
1010
1559
  NO_PAYLOAD_ROUTING: must({
1011
1560
  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.",
1561
+ 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
1562
  enforcedBy: "daemon",
1014
1563
  verifiedBy: "adversarial",
1015
- source: "byollm_004 \xA72"
1564
+ source: "byollm_004 \xA72, amended byollm_016 \xA7Phase B"
1016
1565
  }),
1017
1566
  STRIPPED_CHILD_ENV: must({
1018
1567
  id: "STRIPPED_CHILD_ENV",
@@ -1041,26 +1590,117 @@ var MUSTS = Object.freeze({
1041
1590
  enforcedBy: "daemon",
1042
1591
  verifiedBy: "adversarial",
1043
1592
  source: "byollm_004 \xA74"
1593
+ }),
1594
+ REVOCATION_IMMEDIATE: must({
1595
+ id: "REVOCATION_IMMEDIATE",
1596
+ 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.",
1597
+ // Both, and stated as one sentence with two obligations rather than
1598
+ // folded into REVOCATION_HONORED. That one binds the *daemon*: a revoked
1599
+ // daemon stops claiming and abandons in-flight work. This binds the
1600
+ // *upstream*. byollm_009 §5 is explicit that the pair is the point — "a
1601
+ // revocation enforced at one end survives a compromise of that end" — and
1602
+ // one entry covering both would make a compromised daemon look compliant.
1603
+ enforcedBy: "both",
1604
+ verifiedBy: "conformance",
1605
+ source: "byollm_009 \xA711"
1606
+ }),
1607
+ CONSENT_BEFORE_ROUTE: must({
1608
+ id: "CONSENT_BEFORE_ROUTE",
1609
+ 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.",
1610
+ enforcedBy: "server",
1611
+ verifiedBy: "conformance",
1612
+ source: "byollm_009 \xA711"
1613
+ }),
1614
+ ROSTER_NOT_DISCLOSED: must({
1615
+ id: "ROSTER_NOT_DISCLOSED",
1616
+ 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.",
1617
+ // Checkable since cloud_008 §0.2 took `audienceAllow` off the stub: the
1618
+ // property now holds by *absence*, and absence is exactly what a strict
1619
+ // schema and a serialised stub can be asked about. Before that it was a
1620
+ // sentence — and one this project cited in code comments, tests and two
1621
+ // specs as though it were enforced data, which is why it is worth
1622
+ // stating precisely rather than generously.
1623
+ enforcedBy: "both",
1624
+ verifiedBy: "conformance",
1625
+ source: "byollm_009 \xA711"
1626
+ }),
1627
+ EFFECTIVE_OFFER_ONLY: must({
1628
+ id: "EFFECTIVE_OFFER_ONLY",
1629
+ 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.",
1630
+ enforcedBy: "both",
1631
+ verifiedBy: "conformance",
1632
+ source: "byollm_009 \xA711"
1633
+ }),
1634
+ FALLBACK_LABELED: must({
1635
+ id: "FALLBACK_LABELED",
1636
+ 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.",
1637
+ // `construction` today, and deliberately not `conformance`. Nothing on
1638
+ // the wire yet distinguishes a fallback from any other community job —
1639
+ // the ledger that would give it a surface is unbuilt — so a check would
1640
+ // have to assert something it cannot observe. Promoted the day that
1641
+ // surface exists. Marking it `conformance` now would put "verified"
1642
+ // beside a property no third party can see, which is the one thing the
1643
+ // kinds exist to prevent.
1644
+ enforcedBy: "both",
1645
+ verifiedBy: "construction",
1646
+ source: "byollm_009 \xA711"
1647
+ }),
1648
+ RELAY_BLIND: must({
1649
+ id: "RELAY_BLIND",
1650
+ statement: "A relay MUST NOT hold any key capable of decrypting a payload, a result, or a delta frame.",
1651
+ // Operator: a third party can read the relay's types and see there is
1652
+ // nowhere to put such a key, but the kit certifies a *server* and cannot
1653
+ // reach inside somebody's deployment to prove what it holds.
1654
+ enforcedBy: "server",
1655
+ verifiedBy: "operator",
1656
+ source: "byollm_009 \xA711"
1657
+ }),
1658
+ SHARED_COMPUTE_DISCLOSED: must({
1659
+ id: "SHARED_COMPUTE_DISCLOSED",
1660
+ 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.",
1661
+ // Operator, and cloud_008 §0.3 is why the classification now comes with a
1662
+ // standing answer rather than a standing question. The screen is not
1663
+ // wire-observable, but the *string the server composes* is, and it is
1664
+ // now unit-tested with the two false sentences forbidden by name. The
1665
+ // kind stays `operator` because a third-party site can still render
1666
+ // whatever it likes; what changed is that the part inside our own
1667
+ // boundary stopped depending on somebody remembering to audit it.
1668
+ enforcedBy: "server",
1669
+ verifiedBy: "operator",
1670
+ source: "byollm_009 \xA711"
1044
1671
  })
1045
1672
  });
1673
+ var RETIRED_MUSTS = Object.freeze({
1674
+ RESULT_PROVENANCE: {
1675
+ supersededBy: "PROVENANCE_NAMES_DEVICE",
1676
+ 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."
1677
+ }
1678
+ });
1046
1679
  var MUST_IDS = Object.freeze(Object.keys(MUSTS));
1047
1680
  function mustsVerifiedBy(kind) {
1048
- return MUST_IDS.filter((id) => MUSTS[id].verifiedBy === kind);
1681
+ return MUST_IDS.filter((id) => kindsOf(MUSTS[id]).includes(kind));
1049
1682
  }
1050
1683
 
1051
1684
  // src/wire.ts
1052
- import { z as z8 } from "zod";
1053
- var PROTOCOL_VERSION = "0";
1685
+ import { z as z11 } from "zod";
1686
+ var PROTOCOL_VERSION = "1";
1054
1687
  var SUPPORTED_PROTOCOL_VERSIONS = Object.freeze([
1055
1688
  PROTOCOL_VERSION
1056
1689
  ]);
1057
1690
  var MIN_PROTOCOL_VERSION = SUPPORTED_PROTOCOL_VERSIONS[0] ?? PROTOCOL_VERSION;
1691
+ function declaredVersion(input) {
1692
+ const { body, query } = input;
1693
+ if (typeof body === "object" && body !== null && Object.hasOwn(body, "protocolVersion")) {
1694
+ return body.protocolVersion;
1695
+ }
1696
+ return query?.get("protocolVersion") ?? void 0;
1697
+ }
1058
1698
  function checkProtocolVersion(body) {
1059
1699
  const declared = typeof body === "object" && body !== null && Object.hasOwn(body, "protocolVersion") ? body.protocolVersion : void 0;
1060
1700
  if (typeof declared !== "string" || declared.length === 0) {
1061
1701
  return {
1062
1702
  error: "unsupported-protocol-version",
1063
- message: "this request declared no protocol version. Upgrade the daemon: `npm i -g byollm@alpha`.",
1703
+ message: `this request declared no protocol version. Upgrade the daemon: \`${UPGRADE_COMMAND}\`.`,
1064
1704
  supported: SUPPORTED_PROTOCOL_VERSIONS,
1065
1705
  minimum: MIN_PROTOCOL_VERSION
1066
1706
  };
@@ -1068,13 +1708,14 @@ function checkProtocolVersion(body) {
1068
1708
  if (!SUPPORTED_PROTOCOL_VERSIONS.includes(declared)) {
1069
1709
  return {
1070
1710
  error: "unsupported-protocol-version",
1071
- message: `this server speaks protocol ${SUPPORTED_PROTOCOL_VERSIONS.join(", ")} and the daemon asked for ${declared}. ` + (declared < MIN_PROTOCOL_VERSION ? "Upgrade the daemon: `npm i -g byollm@alpha`." : "This daemon is newer than the server; the server needs upgrading."),
1711
+ 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
1712
  supported: SUPPORTED_PROTOCOL_VERSIONS,
1073
1713
  minimum: MIN_PROTOCOL_VERSION
1074
1714
  };
1075
1715
  }
1076
1716
  return null;
1077
1717
  }
1718
+ var UPGRADE_COMMAND = "npm i -g byollm@latest";
1078
1719
  var PROTOCOL_PREFIX = "/byollm";
1079
1720
  var ENDPOINTS = Object.freeze([
1080
1721
  "pair",
@@ -1084,23 +1725,45 @@ var ENDPOINTS = Object.freeze([
1084
1725
  "result",
1085
1726
  "release"
1086
1727
  ]);
1087
- var Capability = z8.object({
1728
+ var Capability = z11.object({
1088
1729
  kind: JobKind,
1730
+ /**
1731
+ * The owner's name for the service answering this kind — byollm_016.
1732
+ *
1733
+ * A device advertises *which* of its services serves a kind, not merely
1734
+ * that something does. **A site never sees this**, and never did after
1735
+ * Amendment L: it is what a control plane resolves a person's mapping
1736
+ * against, so that the service a grant names is one this device actually
1737
+ * offers rather than one somebody invented.
1738
+ *
1739
+ * `isDefault` used to sit beside it, saying which row an unselected job
1740
+ * took. Nothing selects any more — a job names a purpose and a person's
1741
+ * mapping names a service — so there is no unselected job for a default
1742
+ * to catch, and the field went with the machinery it served.
1743
+ */
1744
+ service: z11.string().min(1),
1089
1745
  backendId: BackendIdSchema,
1090
1746
  backendClass: BackendClass,
1091
- model: z8.string().min(1),
1747
+ model: z11.string().min(1),
1092
1748
  offerScope: OfferScope
1093
1749
  }).strict();
1094
- var CapabilityMatrix = z8.array(Capability);
1095
- var PairStartRequest = z8.object({
1096
- protocolVersion: z8.literal(PROTOCOL_VERSION),
1097
- action: z8.literal("start"),
1098
- daemon: z8.object({
1099
- version: z8.string().min(1),
1750
+ var CapabilityMatrix = z11.array(Capability);
1751
+ var WithheldKind = z11.object({
1752
+ kind: JobKind,
1753
+ claimants: z11.array(
1754
+ z11.object({ service: z11.string().min(1), offer: OfferScope }).strict()
1755
+ ).min(2)
1756
+ }).strict();
1757
+ var GrantRef = z11.object({ jobId: z11.string().min(1), leaseId: z11.string().min(1) }).strict();
1758
+ var PairStartRequest = z11.object({
1759
+ protocolVersion: z11.literal(PROTOCOL_VERSION),
1760
+ action: z11.literal("start"),
1761
+ daemon: z11.object({
1762
+ version: z11.string().min(1),
1100
1763
  /** Shown in the app's runner list so a user can tell their machines apart. */
1101
- label: z8.string().min(1).max(120),
1102
- platform: z8.enum(["darwin", "linux", "win32"])
1103
- }),
1764
+ label: z11.string().min(1).max(120),
1765
+ platform: z11.enum(["darwin", "linux", "win32"])
1766
+ }).strict(),
1104
1767
  /**
1105
1768
  * This machine's public keys (byollm_009 §5).
1106
1769
  *
@@ -1111,111 +1774,278 @@ var PairStartRequest = z8.object({
1111
1774
  device: PublicIdentity,
1112
1775
  capabilities: CapabilityMatrix
1113
1776
  }).strict();
1114
- var PairStartResponse = z8.object({
1777
+ var PairStartResponse = z11.object({
1115
1778
  /** Secret the daemon polls with. Never shown to the user. */
1116
- deviceCode: z8.string().min(20),
1779
+ deviceCode: z11.string().min(20),
1117
1780
  /** Short code the user reads and confirms in the browser. */
1118
- userCode: z8.string().min(4).max(16),
1781
+ userCode: z11.string().min(4).max(16),
1119
1782
  /** Where the user approves. Must be on the server's own origin. */
1120
- verificationUrl: z8.url(),
1783
+ verificationUrl: z11.url(),
1121
1784
  /** Epoch ms after which the code is dead ({@link MUSTS.PAIR_CODE_EXPIRES}). */
1122
- expiresAt: z8.number().int().positive(),
1785
+ expiresAt: z11.number().int().positive(),
1123
1786
  /** How often the daemon may poll. */
1124
- pollIntervalMs: z8.number().int().min(500).max(6e4)
1787
+ pollIntervalMs: z11.number().int().min(500).max(6e4)
1125
1788
  }).strict();
1126
- var PairPollRequest = z8.object({
1127
- protocolVersion: z8.literal(PROTOCOL_VERSION),
1128
- action: z8.literal("poll"),
1129
- deviceCode: z8.string().min(20)
1789
+ var PairPollRequest = z11.object({
1790
+ protocolVersion: z11.literal(PROTOCOL_VERSION),
1791
+ action: z11.literal("poll"),
1792
+ deviceCode: z11.string().min(20)
1130
1793
  }).strict();
1131
- var PairPollResponse = z8.discriminatedUnion("status", [
1132
- z8.object({ status: z8.literal("pending") }).strict(),
1133
- z8.object({ status: z8.literal("denied") }).strict(),
1134
- z8.object({ status: z8.literal("expired") }).strict(),
1135
- z8.object({
1136
- status: z8.literal("approved"),
1137
- /** Bearer token for every later call. Scoped to exactly one user. */
1138
- runnerToken: z8.string().min(20),
1139
- runnerId: z8.string().min(1),
1794
+ var PairPollResponse = z11.discriminatedUnion("status", [
1795
+ z11.object({ status: z11.literal("pending") }).strict(),
1796
+ z11.object({ status: z11.literal("denied") }).strict(),
1797
+ z11.object({ status: z11.literal("expired") }).strict(),
1798
+ z11.object({
1799
+ status: z11.literal("approved"),
1800
+ // `runnerToken` is gone cloud_008 §2.4, finding 37.
1801
+ //
1802
+ // It was minted here, hashed into `RunnerRecord.tokenHash`, written to
1803
+ // the daemon's pairings file, and then **never sent, never looked up
1804
+ // and never compared**. `getRunnerByTokenHash` existed on both stores
1805
+ // and was called by nothing but a test asserting it returns null.
1806
+ //
1807
+ // Not merely dead wire, which is what `audienceAllow` and
1808
+ // `HeartbeatResponse.leases` were. This was a *secret*: minted,
1809
+ // transmitted, and written to two disks at rest, for nothing. A
1810
+ // credential with no purpose is a liability rather than clutter,
1811
+ // because the only thing it can ever do is leak.
1812
+ //
1813
+ // `REQUESTS_SIGNED_NOT_BEARER` was already the rule and was already
1814
+ // enforced — every authenticated call is signed by the device's pinned
1815
+ // identity key. This removes the thing the MUST is named after.
1816
+ runnerId: z11.string().min(1),
1140
1817
  /** The app's id for the approving user — this daemon's owner forever. */
1141
- owner: z8.string().min(1),
1818
+ owner: z11.string().min(1),
1142
1819
  /** Display name for the trust UI, if the app offers one. */
1143
- ownerLabel: z8.string().optional(),
1820
+ ownerLabel: z11.string().optional(),
1144
1821
  /**
1145
- * The site's public keys, for the daemon to pin (byollm_009 §5).
1822
+ * The sites this pairing covers, for the daemon to pin (byollm_009 §5),
1823
+ * keyed by each site's identity key id — cloud_009 §5.
1146
1824
  *
1147
- * Returned only on approval a pending or denied poll learns nothing,
1825
+ * Returned only on approval: a pending or denied poll learns nothing,
1148
1826
  * so an unapproved code cannot be used to enumerate a site's keys.
1827
+ *
1828
+ * **One pairing per upstream, not one per site.** A user who connects a
1829
+ * site on a web dashboard has no reason to go back to a laptop and run
1830
+ * a command, so which sites a pairing covers is a projection of consent
1831
+ * — refreshed on the heartbeat — rather than something frozen at
1832
+ * pairing. A direct site answers with exactly one entry, which is the
1833
+ * same shape and not a special case.
1834
+ *
1835
+ * Keyed by the id `stub.site` carries (Amendment A §A.3), so the
1836
+ * runner's lookup is a map read rather than a join across two
1837
+ * namespaces.
1149
1838
  */
1150
- site: PublicIdentity
1839
+ sites: z11.record(z11.string().min(1), PublicIdentity),
1840
+ /**
1841
+ * The control plane's grant-signing key, pinned here — Amendment J.
1842
+ *
1843
+ * **Pairing is when, and that is the whole question.** Pairing is
1844
+ * already the ceremony where an owner proves out of band that this
1845
+ * device is theirs, so a key learned here rides trust that has already
1846
+ * happened. The rejected alternative is trust-on-first-grant, and it is
1847
+ * rejected because it hands the decision back to the relay: a daemon
1848
+ * that learns whose signature to trust from the first grant to arrive
1849
+ * has its admission authority chosen by whoever controls delivery.
1850
+ *
1851
+ * Optional on the wire, and only on the wire: a direct-mode server has
1852
+ * no control plane and signs nothing, and a daemon that receives no key
1853
+ * serves its owner alone. It is not optional for a relay with a control
1854
+ * plane — one that omitted it would be asking devices to accept grants
1855
+ * from nobody in particular, and would find every job refused.
1856
+ *
1857
+ * Rotation is Amendment C's, with no path where a grant teaches a
1858
+ * daemon a new key.
1859
+ */
1860
+ controlPlanePublic: z11.string().min(1).optional()
1151
1861
  }).strict()
1152
1862
  ]);
1153
- var PairRequest = z8.discriminatedUnion("action", [
1863
+ var PairRequest = z11.discriminatedUnion("action", [
1154
1864
  PairStartRequest,
1155
1865
  PairPollRequest
1156
1866
  ]);
1157
- var ClaimRequest = z8.object({
1158
- protocolVersion: z8.literal(PROTOCOL_VERSION),
1159
- runnerId: z8.string().min(1),
1867
+ var ClaimRequest = z11.object({
1868
+ protocolVersion: z11.literal(PROTOCOL_VERSION),
1869
+ runnerId: z11.string().min(1),
1160
1870
  /** Re-sent on every claim so a server never matches against a stale matrix. */
1161
1871
  capabilities: CapabilityMatrix,
1162
1872
  /** Upper bound on jobs to return; the server may return fewer. */
1163
- max: z8.number().int().min(1).max(64)
1873
+ max: z11.number().int().min(1).max(64)
1164
1874
  }).strict();
1165
- var ClaimResponse = z8.object({
1875
+ var ClaimResponse = z11.object({
1166
1876
  /**
1167
1877
  * Stubs, not jobs. The payload arrives from `fetch`, sealed to whichever
1168
1878
  * device claimed — see {@link JobStub} for the exhaustive metadata list.
1169
1879
  */
1170
- jobs: z8.array(ClaimedStub),
1880
+ jobs: z11.array(ClaimedStub),
1171
1881
  /** Lease duration granted, so the daemon knows its renewal deadline. */
1172
- leaseMs: z8.number().int().positive()
1882
+ leaseMs: z11.number().int().positive()
1173
1883
  }).strict();
1174
- var HeartbeatRequest = z8.object({
1175
- protocolVersion: z8.literal(PROTOCOL_VERSION),
1176
- runnerId: z8.string().min(1),
1177
- daemonVersion: z8.string().min(1),
1884
+ var HeartbeatRequest = z11.object({
1885
+ protocolVersion: z11.literal(PROTOCOL_VERSION),
1886
+ runnerId: z11.string().min(1),
1887
+ daemonVersion: z11.string().min(1),
1178
1888
  capabilities: CapabilityMatrix,
1889
+ /**
1890
+ * Kinds this device is withholding, and why it can be said.
1891
+ *
1892
+ * Optional so a daemon that has nothing withheld sends nothing, and so an
1893
+ * older daemon against a newer hub is simply a device with no withheld
1894
+ * kinds rather than a parse failure.
1895
+ */
1896
+ withheld: z11.array(WithheldKind).default([]),
1179
1897
  /**
1180
1898
  * Leases this daemon believes it holds; the server renews exactly these.
1181
1899
  *
1182
1900
  * Lease ids rather than job ids, so a replayed heartbeat cannot renew a
1183
1901
  * grant the runner no longer holds — see {@link Lease.id}.
1184
1902
  */
1185
- activeLeases: z8.array(
1186
- z8.object({ jobId: z8.string().min(1), leaseId: z8.string().min(1) })
1187
- ),
1903
+ activeLeases: z11.array(GrantRef),
1188
1904
  /** True while the owner has the daemon paused; the server stops offering work. */
1189
- paused: z8.boolean()
1905
+ paused: z11.boolean()
1190
1906
  }).strict();
1191
- var HeartbeatResponse = z8.object({
1192
- /** Once true, the daemon stops claiming and abandons in-flight work. */
1193
- revoked: z8.boolean(),
1907
+ var HeartbeatResponse = z11.object({
1908
+ /**
1909
+ * The sites this daemon may serve, right now — cloud_008 finding 59.
1910
+ *
1911
+ * Revocation used to be a boolean, and it was device-wide: the daemon
1912
+ * plane refused every call when the (owner, hub-site) consent was gone,
1913
+ * heartbeat answered `revoked: true` with `lost: all`, and the daemon
1914
+ * dropped its whole pairing by origin. Under a hub that is one site's
1915
+ * revocation ending a machine's relationship with every other site it
1916
+ * served — the amplification finding 48 warned about, arriving through
1917
+ * the one field nobody thought of as tenancy.
1918
+ *
1919
+ * So the answer is the set. A site that leaves it is revoked *for that
1920
+ * site*: the daemon drops that pin and keeps the rest. An empty set is
1921
+ * what "revoked" used to mean, and the daemon can see that for itself
1922
+ * rather than being told a second time — two fields for one fact is how
1923
+ * they drift.
1924
+ */
1925
+ sites: z11.record(z11.string().min(1), PublicIdentity),
1926
+ /**
1927
+ * How a site's current key traces back to one this daemon already holds —
1928
+ * byollm_009 Amendment C.
1929
+ *
1930
+ * Keyed by the same id as `sites`, and **additive on purpose**: `sites`
1931
+ * remains the one statement of which key is current, and this says only
1932
+ * how that key got there. Two fields for one fact is how they drift; this
1933
+ * is two facts, and the second is evidence about the first.
1934
+ *
1935
+ * Optional because a site that has never rotated has no chain, which is
1936
+ * every site today. A daemon that receives one for an id it already holds
1937
+ * ignores it: the pin it has is the pin it approved.
1938
+ *
1939
+ * §12 carries what this adds to the metadata surface — a site's rotation
1940
+ * history is public by construction, because a daemon that cannot read it
1941
+ * cannot verify it.
1942
+ */
1943
+ successions: z11.record(
1944
+ z11.string().min(1),
1945
+ z11.object({
1946
+ /** Oldest last, as the projection carries it. */
1947
+ succeeds: z11.array(Succession).max(MAX_SUCCESSION_CHAIN),
1948
+ /**
1949
+ * Until when the superseded key may still sign work — epoch ms.
1950
+ *
1951
+ * The daemon holds its own clock against this, for the reason it
1952
+ * holds its own allowlist: a projection that could extend the
1953
+ * window indefinitely would be a two-key site forever, decided by
1954
+ * the party this design does not trust.
1955
+ */
1956
+ retiringUntil: z11.number().int().positive().optional()
1957
+ }).strict()
1958
+ ).optional(),
1194
1959
  /**
1195
1960
  * Per-job cancel (byollm_001 Rev 1 §C). The daemon aborts these jobs'
1196
1961
  * in-flight backend calls and reports them `canceled`.
1962
+ *
1963
+ * **The grant, not the id** — V1-3. Job ids are chosen per site, so two
1964
+ * sites may pick the same one, and a bare id told a daemon holding both
1965
+ * to abort whichever it happened to have filed under that name. The lease
1966
+ * is the unique grant and the daemon already keys its work by it; this is
1967
+ * the same shape `activeLeases` sends in the other direction.
1197
1968
  */
1198
- cancel: z8.array(z8.string().min(1)),
1199
- /** Jobs whose leases were renewed, with their new expiry. */
1200
- leases: z8.array(
1201
- z8.object({
1202
- jobId: z8.string().min(1),
1203
- expiresAt: z8.number().int().positive()
1204
- }).strict()
1969
+ cancel: z11.array(
1970
+ z11.object({ jobId: z11.string().min(1), leaseId: z11.string().min(1) }).strict()
1205
1971
  ),
1972
+ // `leases` is deliberately absent — cloud_008 §1.4b, finding 16.
1973
+ //
1974
+ // It carried "these leases were renewed, and here is the new expiry", and
1975
+ // **no daemon ever read it.** A mutation returning an empty list while
1976
+ // renewing correctly survived every test, which is what made it visible.
1977
+ //
1978
+ // It is neither a class nor membership, so Amendment A's rule does not
1979
+ // decide it — the older test does: nothing reads it, so it is dead wire.
1980
+ // §6's exhaustiveness is a commitment about what an upstream can see, and
1981
+ // it applies to every message rather than only to the stub.
1982
+ //
1983
+ // `lost` is the actionable signal and always was: a daemon stops work on
1984
+ // a lease it no longer holds. "Renewed" was the same question answered a
1985
+ // second time, and a second answer can only agree or contradict.
1986
+ //
1987
+ // Renewal itself is untouched — the upstream still extends the grants a
1988
+ // heartbeat names, which is what §0.6 fixed. What ended is telling the
1989
+ // daemon about it in a field it ignored. If an upstream ever needs to
1990
+ // push lease decisions, that is a new field with a reader, added on
1991
+ // purpose.
1206
1992
  /**
1207
1993
  * Jobs the daemon thinks it holds but the server has reassigned or
1208
1994
  * expired. The daemon must stop work on these and not report results.
1995
+ *
1996
+ * Named by grant rather than by id, for V1-3's reason: a bare id is
1997
+ * ambiguous across sites, and "the lease you no longer hold" is exactly
1998
+ * what this field means anyway.
1209
1999
  */
1210
- lost: z8.array(z8.string().min(1)),
2000
+ lost: z11.array(
2001
+ z11.object({ jobId: z11.string().min(1), leaseId: z11.string().min(1) }).strict()
2002
+ ),
1211
2003
  /** Server clock, so a daemon with a skewed clock still honors leases. */
1212
- serverTime: z8.number().int().positive()
2004
+ serverTime: z11.number().int().positive(),
2005
+ /**
2006
+ * Sites whose disclosure the user must read again before work moves —
2007
+ * cloud_008 finding 48, named rather than counted.
2008
+ *
2009
+ * A **subset of `sites`**, deliberately: a paused site keeps its pin, so
2010
+ * re-consenting never costs a re-pair. The daemon can say which site is
2011
+ * waiting and the user can go and read it, which is the difference
2012
+ * between a machine that is quietly idle and one that says why.
2013
+ *
2014
+ * Not `revoked`, which is a human ending a relationship, and not
2015
+ * `paused`, which on the request side already means "this daemon's
2016
+ * operator stopped it" — one word with two subjects on two halves of one
2017
+ * exchange is a confusion nobody untangles from a log.
2018
+ */
2019
+ awaitingConsent: z11.array(z11.string().min(1))
1213
2020
  }).strict();
1214
- var ResultDisposition = z8.enum(["ok", "error", "canceled"]);
1215
- var ResultRequest = z8.object({
1216
- protocolVersion: z8.literal(PROTOCOL_VERSION),
1217
- runnerId: z8.string().min(1),
1218
- jobId: z8.string().min(1),
2021
+ var ResultDisposition = z11.enum(["ok", "error", "canceled"]);
2022
+ var ResultRequest = z11.object({
2023
+ protocolVersion: z11.literal(PROTOCOL_VERSION),
2024
+ runnerId: z11.string().min(1),
2025
+ jobId: z11.string().min(1),
2026
+ /**
2027
+ * The grant this result was produced under — cloud_008 §1.4a.
2028
+ *
2029
+ * `fetch` has always named its lease, with the reasoning written beside
2030
+ * it: a request that names only the job would be answerable for whatever
2031
+ * lease exists when it arrives. **The operation that writes the result did
2032
+ * not**, on either plane, and checked only the runner id — which survives
2033
+ * a claim-release-reclaim cycle, so a device whose grant had been swept
2034
+ * and reissued could still land a result for a job it no longer held.
2035
+ *
2036
+ * Found by tracing a mutation that survived in §0.6: the lease lapsed, the
2037
+ * sweep requeued, the daemon re-claimed under a new grant, and the
2038
+ * original run finished and posted anyway. The relay marked the job done
2039
+ * with a result the site cannot open — it verifies the envelope against
2040
+ * the *current* holder's device, so the crypto contains the substitution —
2041
+ * and then refused the real holder's result as a replay. A lost job, in
2042
+ * silence.
2043
+ *
2044
+ * `LEASE_HONORED` is a statement about a lease *instance*. That was
2045
+ * learned once already, when a replayed release yanked a later grant, and
2046
+ * it applies here for the same reason.
2047
+ */
2048
+ leaseId: z11.string().min(1),
1219
2049
  /**
1220
2050
  * The outcome, sealed to the site and signed by the device.
1221
2051
  *
@@ -1231,26 +2061,48 @@ var ResultRequest = z8.object({
1231
2061
  * fact: believing it unverified would let a daemon mark a job `ok` while
1232
2062
  * sealing an error, and only the app would ever find out.
1233
2063
  */
1234
- disposition: ResultDisposition,
1235
- /** Which model actually served it, for the result's provenance. */
1236
- model: z8.string().min(1),
1237
- backendClass: BackendClass,
1238
- /** Wall-clock milliseconds the backend call took. */
1239
- durationMs: z8.number().int().nonnegative()
2064
+ disposition: ResultDisposition
2065
+ // `model`, `backendClass` and `durationMs` are **inside the envelope**
2066
+ // cloud_008 §2.5. See {@link RunMetadata}.
2067
+ //
2068
+ // They were here, in the clear, and that was two problems wearing one
2069
+ // coat. On the direct plane the site recorded unauthenticated fields
2070
+ // beside an authenticated answer: a daemon could seal one result and
2071
+ // declare a different model, and only the unsigned half would reach the
2072
+ // app. Through a relay they reached a third party that acts on none of
2073
+ // them — `model` in particular being the sort of detail Amendment A's
2074
+ // rule keeps off the wire.
2075
+ //
2076
+ // `disposition` stays, and the difference is the test: a relay *routes*
2077
+ // on it, so it is a class a routing party consumes. Nobody between the
2078
+ // two ends consumes these.
1240
2079
  }).strict();
1241
- var ResultResponse = z8.object({
2080
+ var ResultResponse = z11.object({
1242
2081
  /**
1243
- * False when the submission lost an idempotency race or the lease was
1244
- * already gone the daemon should discard, not retry
1245
- * ({@link MUSTS.RESULT_IDEMPOTENT}).
2082
+ * False when this submission wrote nothing the daemon should discard,
2083
+ * not retry ({@link MUSTS.RESULT_IDEMPOTENT}).
1246
2084
  */
1247
- accepted: z8.boolean(),
2085
+ accepted: z11.boolean(),
2086
+ /**
2087
+ * True when this device had already recorded this job's result.
2088
+ *
2089
+ * The difference between "already recorded" and "you no longer hold this"
2090
+ * — cloud_008 §3.6. A daemon whose acknowledgment was lost is in the first
2091
+ * case and needs to hear it: its answer is safely on disk. Reporting a
2092
+ * stale lease instead invents a worry about a result that is already
2093
+ * stored, and sends its owner looking for a routing problem.
2094
+ *
2095
+ * Set only for the device that finished the job. A different device gets
2096
+ * the same refusal it would get for a job that is *not* terminal, so a job
2097
+ * id cannot be used as a terminality probe.
2098
+ */
2099
+ duplicate: z11.boolean().optional(),
1248
2100
  /** The job's state after this submission. */
1249
- state: z8.string().min(1)
2101
+ state: z11.string().min(1)
1250
2102
  }).strict();
1251
- var ReleaseRequest = z8.object({
1252
- protocolVersion: z8.literal(PROTOCOL_VERSION),
1253
- runnerId: z8.string().min(1),
2103
+ var ReleaseRequest = z11.object({
2104
+ protocolVersion: z11.literal(PROTOCOL_VERSION),
2105
+ runnerId: z11.string().min(1),
1254
2106
  /**
1255
2107
  * Which leases to release — the grant, not just the job.
1256
2108
  *
@@ -1258,51 +2110,162 @@ var ReleaseRequest = z8.object({
1258
2110
  * moment it arrives, which for a replayed request is not the lease the
1259
2111
  * daemon meant. See {@link Lease.id}.
1260
2112
  */
1261
- leases: z8.array(
1262
- z8.object({ jobId: z8.string().min(1), leaseId: z8.string().min(1) })
1263
- ),
2113
+ leases: z11.array(GrantRef),
1264
2114
  /**
1265
2115
  * Why, so the app's runner list can say something true.
1266
2116
  *
1267
- * `refused` is load-bearing, not cosmetic: the server cannot evaluate a
1268
- * daemon's *local* `named` allowlist (§4.2), so it may legitimately offer
2117
+ * `refused` is load-bearing, not cosmetic: the server cannot evaluate
2118
+ * what a device will admit (§4.2), so it may legitimately offer
1269
2119
  * a job this daemon then declines. The server MUST record the refusal and
1270
2120
  * stop offering that job to that runner, or the pair would spin between
1271
2121
  * claim and release forever.
1272
2122
  */
1273
- reason: z8.enum(["shutdown", "pause", "revoked", "backend-down", "refused"])
2123
+ reason: z11.enum(["shutdown", "pause", "revoked", "backend-down", "refused"])
1274
2124
  }).strict();
1275
- var ReleaseResponse = z8.object({
1276
- released: z8.array(z8.string().min(1))
2125
+ var ReleaseResponse = z11.object({
2126
+ released: z11.array(z11.string().min(1))
1277
2127
  }).strict();
1278
- var WireErrorCode = z8.enum([
2128
+ var WireErrorCode = z11.enum([
1279
2129
  "bad-request",
1280
2130
  "unsupported-protocol-version",
2131
+ // "We do not know who you are." Exactly 401, and only that — cloud_008
2132
+ // §1.4d.
1281
2133
  "unauthorized",
2134
+ /**
2135
+ * "We know exactly who you are, and the answer is no." Exactly 403.
2136
+ *
2137
+ * Five refusals across both planes served 403 with `unauthorized`, whose
2138
+ * table entry is 401: a revoked device, a site claiming another site's
2139
+ * stub, a job you do not hold, a device belonging to another owner, a
2140
+ * relay that does not route for you. Every one of them is an *identified*
2141
+ * caller being refused.
2142
+ *
2143
+ * Collapsing the two loses a distinction that matters everywhere it is
2144
+ * read: a revoked daemon would look like an unsigned one in every log and
2145
+ * every client branch, and "check your keys" is the wrong advice for both
2146
+ * of them in opposite directions.
2147
+ */
2148
+ "forbidden",
1282
2149
  "revoked",
1283
2150
  "not-found",
2151
+ // Claimed, but the site has not sealed the payload yet — cloud_008 §1.4.
2152
+ //
2153
+ // A daemon must retry rather than abandon: the job is legitimately still
2154
+ // its own until the lease or the awaiting-payload clock says otherwise.
2155
+ // That is why it cannot be `not-found` or `server-error`, and why it was
2156
+ // the protocol gap that produced a bare 409 in the first place.
2157
+ "not-ready",
2158
+ /**
2159
+ * The job is over, and this call is about a job — V1-6, and the code the
2160
+ * site plane has been serving without one (V1-13).
2161
+ *
2162
+ * Distinct from `not-found`, which says "no such job", and from
2163
+ * `not-ready`, which says "not yet, keep asking". This one says "yes, and
2164
+ * it finished" — so a daemon must stop rather than retry, and a replayed
2165
+ * request must not be able to reopen it.
2166
+ */
2167
+ "too-late",
2168
+ // The caller's clock is too far from ours to judge a signature's freshness.
2169
+ //
2170
+ // Split out from `unauthorized` because the remedy is completely different
2171
+ // and only the server can tell them apart: a bad signature means the key is
2172
+ // wrong, this means the machine's time is wrong. A daemon reporting it as a
2173
+ // generic rejection sends its owner looking at their network.
2174
+ "clock-skew",
1284
2175
  "rate-limited",
1285
2176
  "server-error"
1286
2177
  ]);
1287
- var WireError = z8.object({
2178
+ var WireError = z11.object({
1288
2179
  error: WireErrorCode,
1289
- message: z8.string().min(1),
2180
+ message: z11.string().min(1),
2181
+ /**
2182
+ * What this server speaks, on `unsupported-protocol-version` — §B.4.
2183
+ *
2184
+ * The refusal has carried these since the version handshake existed and
2185
+ * the enumeration did not model them, so the one error that exists to be
2186
+ * *acted on* was the one that failed to parse as a wire error. Found by
2187
+ * the relay's own suite the day the relay started sending it: a refusal
2188
+ * outside the enumerated shape is a refusal a client cannot branch on,
2189
+ * which is the whole reason §1.4 enumerates them.
2190
+ *
2191
+ * Modelled the way `clock-skew`'s two fields already are — code-specific
2192
+ * extras, refused on any other code by the refinement below.
2193
+ */
2194
+ supported: z11.array(z11.string().min(1)).optional(),
2195
+ minimum: z11.string().min(1).optional(),
1290
2196
  /** Seconds; mirrors Retry-After for `rate-limited` and `server-error`. */
1291
- retryAfter: z8.number().int().nonnegative().optional()
1292
- }).strict();
2197
+ retryAfter: z11.number().int().nonnegative().optional(),
2198
+ /**
2199
+ * The server's clock, and the window it allows. `clock-skew` only.
2200
+ *
2201
+ * So the far side can say *how far off* rather than *that something is
2202
+ * wrong* — the difference between "adjust your clock by four minutes" and
2203
+ * "something is wrong with your connection". Not a disclosure: the
2204
+ * heartbeat response returns the same value, and so does every `Date`
2205
+ * header.
2206
+ */
2207
+ serverTime: z11.number().int().positive().optional(),
2208
+ maxSkewMs: z11.number().int().positive().optional()
2209
+ }).strict().superRefine((error, ctx) => {
2210
+ const skew = error.error === "clock-skew";
2211
+ const carried = error.serverTime !== void 0 || error.maxSkewMs !== void 0;
2212
+ if (skew && !carried) {
2213
+ ctx.addIssue({
2214
+ code: "custom",
2215
+ message: "clock-skew must carry serverTime and maxSkewMs"
2216
+ });
2217
+ }
2218
+ if (!skew && carried) {
2219
+ ctx.addIssue({
2220
+ code: "custom",
2221
+ message: `${error.error} must not carry serverTime or maxSkewMs`
2222
+ });
2223
+ }
2224
+ const version = error.error === "unsupported-protocol-version";
2225
+ const versionFields = error.supported !== void 0 || error.minimum !== void 0;
2226
+ if (version && !versionFields) {
2227
+ ctx.addIssue({
2228
+ code: "custom",
2229
+ message: "unsupported-protocol-version must carry supported and minimum"
2230
+ });
2231
+ }
2232
+ if (!version && versionFields) {
2233
+ ctx.addIssue({
2234
+ code: "custom",
2235
+ message: `${error.error} must not carry supported or minimum`
2236
+ });
2237
+ }
2238
+ });
1293
2239
  var ERROR_STATUS = Object.freeze({
1294
2240
  "bad-request": 400,
1295
2241
  "unsupported-protocol-version": 400,
1296
2242
  unauthorized: 401,
2243
+ forbidden: 403,
1297
2244
  revoked: 403,
1298
2245
  "not-found": 404,
2246
+ // 409, not 404: the job exists and is yours, it is simply not ready.
2247
+ "not-ready": 409,
2248
+ // The same 409 as `not-ready` and the opposite instruction: that one says
2249
+ // keep asking, this one says stop. The status is the class of the
2250
+ // problem — a request that does not fit the resource's state — and the
2251
+ // code is what a caller acts on.
2252
+ "too-late": 409,
2253
+ // 401 alongside `unauthorized`, because that is what it is — the
2254
+ // signature could not be judged. The code is what carries the remedy.
2255
+ "clock-skew": 401,
1299
2256
  "rate-limited": 429,
1300
2257
  "server-error": 500
1301
2258
  });
1302
- var FetchRequest = z8.object({
1303
- protocolVersion: z8.string().min(1),
1304
- runnerId: z8.string().min(1),
1305
- jobId: z8.string().min(1),
2259
+ var FetchRequest = z11.object({
2260
+ // `literal`, like every other request — V1-17. This one said
2261
+ // `string().min(1)`, so a daemon speaking a version this server does not
2262
+ // know got past the handshake on the one endpoint that hands over a
2263
+ // sealed payload. The version check exists so that a mismatch is a named
2264
+ // refusal rather than a schema failure three fields later; here it was
2265
+ // neither.
2266
+ protocolVersion: z11.literal(PROTOCOL_VERSION),
2267
+ runnerId: z11.string().min(1),
2268
+ jobId: z11.string().min(1),
1306
2269
  /**
1307
2270
  * The grant this daemon holds.
1308
2271
  *
@@ -1310,9 +2273,9 @@ var FetchRequest = z8.object({
1310
2273
  * only the job would be answerable for whatever lease exists when it
1311
2274
  * arrives ({@link Lease.id}).
1312
2275
  */
1313
- leaseId: z8.string().min(1)
2276
+ leaseId: z11.string().min(1)
1314
2277
  }).strict();
1315
- var FetchResponse = z8.object({
2278
+ var FetchResponse = z11.object({
1316
2279
  /**
1317
2280
  * The work, sealed to the device that claimed it — byollm_009 §6.
1318
2281
  *
@@ -1327,10 +2290,13 @@ export {
1327
2290
  AUDIENCES,
1328
2291
  Audience,
1329
2292
  BACKENDS,
2293
+ BACKEND_CLASSES,
1330
2294
  BACKEND_IDS,
1331
2295
  BackendClass,
1332
2296
  BackendCost,
1333
2297
  BackendIdSchema,
2298
+ CLOCK_ATTRIBUTION_MS,
2299
+ CLOCK_SKEW_WARN_MS,
1334
2300
  Capability,
1335
2301
  CapabilityMatrix,
1336
2302
  ChatMessage,
@@ -1340,19 +2306,25 @@ export {
1340
2306
  ClaimedJob,
1341
2307
  ClaimedStub,
1342
2308
  DeliveredResult,
2309
+ ENCRYPTION_KEY_CONTEXT,
1343
2310
  ENDPOINTS,
1344
2311
  ENVELOPE_MAX_AGE_MS,
1345
2312
  ERROR_STATUS,
1346
2313
  EnvelopeDirection,
1347
2314
  FetchRequest,
1348
2315
  FetchResponse,
2316
+ GRANT_CONTEXT,
2317
+ GRANT_MAX_AGE_MS,
2318
+ GRANT_SIGNED_FIELDS,
1349
2319
  GeneratePayload,
2320
+ GrantRef,
1350
2321
  HeartbeatRequest,
1351
2322
  HeartbeatResponse,
1352
2323
  JOB_KINDS,
1353
2324
  JobKind,
1354
2325
  JobOutcome,
1355
2326
  JobPayload,
2327
+ JobRefused,
1356
2328
  JobResultCanceled,
1357
2329
  JobResultError,
1358
2330
  JobResultOk,
@@ -1361,9 +2333,12 @@ export {
1361
2333
  KindedPayload,
1362
2334
  Lease,
1363
2335
  MAX_CLOCK_SKEW_MS,
2336
+ MAX_PURPOSES,
2337
+ MAX_SUCCESSION_CHAIN,
1364
2338
  MIN_PROTOCOL_VERSION,
1365
2339
  MUSTS,
1366
2340
  MUST_IDS,
2341
+ Manifest,
1367
2342
  MatchRefusal,
1368
2343
  OFFER_SCOPES,
1369
2344
  OfferScope,
@@ -1376,7 +2351,11 @@ export {
1376
2351
  PairStartRequest,
1377
2352
  PairStartResponse,
1378
2353
  PublicIdentity,
2354
+ Purpose,
1379
2355
  REFUSAL_MESSAGES,
2356
+ RESERVED_PURPOSE,
2357
+ RETIREMENT_WINDOW_MS,
2358
+ RefusalReason,
1380
2359
  ReleaseRequest,
1381
2360
  ReleaseResponse,
1382
2361
  RequestSignature,
@@ -1384,27 +2363,40 @@ export {
1384
2363
  ResultProvenance,
1385
2364
  ResultRequest,
1386
2365
  ResultResponse,
2366
+ RunMetadata,
2367
+ SIZE_CLASSES,
1387
2368
  SIZE_CLASS_LIMITS,
2369
+ SUCCESSION_CONTEXT,
1388
2370
  SUPPORTED_PROTOCOL_VERSIONS,
1389
2371
  SealedEnvelope,
2372
+ SealedOutcome,
2373
+ SignedGrant,
1390
2374
  SizeClass,
1391
2375
  StoredKeys,
2376
+ Succession,
1392
2377
  TERMINAL_STATES,
1393
2378
  WireError,
1394
2379
  WireErrorCode,
2380
+ WithheldKind,
1395
2381
  backendDescriptor,
2382
+ backendName,
1396
2383
  canTransition,
1397
2384
  canonicalRequest,
1398
2385
  checkProtocolVersion,
2386
+ classifyCost,
1399
2387
  cryptoReady,
2388
+ declaredVersion,
1400
2389
  effectiveOfferScope,
1401
2390
  fingerprint,
1402
2391
  generateKeys,
2392
+ grantStatement,
1403
2393
  isBackendId,
2394
+ isCloudTaggedModel,
1404
2395
  isJobKind,
1405
2396
  isLocalHost,
1406
2397
  isTerminal,
1407
2398
  keyId,
2399
+ kindsOf,
1408
2400
  matchAudience,
1409
2401
  mustsVerifiedBy,
1410
2402
  open,
@@ -1413,12 +2405,21 @@ export {
1413
2405
  publicIdentityOf,
1414
2406
  resolveCost,
1415
2407
  seal,
2408
+ signGrant,
1416
2409
  signRequest,
2410
+ signSiteRequest,
2411
+ signSuccession,
1417
2412
  signWith,
2413
+ singlePurposeManifest,
1418
2414
  sizeClassCeiling,
1419
2415
  sizeClassOf,
2416
+ successionStatement,
2417
+ verifyGrant,
2418
+ verifyLink,
1420
2419
  verifyPublicIdentity,
1421
2420
  verifyRequest,
1422
- verifyWith
2421
+ verifySiteRequest,
2422
+ verifyWith,
2423
+ walkSuccession
1423
2424
  };
1424
2425
  //# sourceMappingURL=index.js.map