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

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