@agent-blueprint-protocol/verifier 0.8.3 → 1.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/CHANGELOG.md +137 -0
  2. package/LICENSE +1 -1
  3. package/NOTICE +2 -2
  4. package/README.md +164 -255
  5. package/dist/corpus/cases/blueprint-decode.json +1 -1
  6. package/dist/corpus/cases/bounds-new.json +1 -1
  7. package/dist/corpus/cases/bounds_algebra-intersect.json +1 -1
  8. package/dist/corpus/cases/canonicalization-encode.json +1 -1
  9. package/dist/corpus/cases/deployment-decode.json +1 -1
  10. package/dist/corpus/cases/extension-resolve.json +1 -1
  11. package/dist/corpus/cases/federation-decode.json +1 -1
  12. package/dist/corpus/cases/federation-verify_commitment.json +1 -1
  13. package/dist/corpus/cases/json-decode.json +1 -1
  14. package/dist/corpus/cases/negotiation-negotiate.json +1 -1
  15. package/dist/corpus/cases/predicate.json +1 -0
  16. package/dist/corpus/cases/reconcile.json +1 -0
  17. package/dist/corpus/cases/schema-validate_instance.json +1 -1
  18. package/dist/corpus/cases/signature-verify.json +1 -1
  19. package/dist/corpus/index.json +1 -1
  20. package/dist/kit/cli.mjs +1 -4
  21. package/dist/release-history.json +1 -0
  22. package/dist/release-metadata.json +1 -1
  23. package/dist/spec/FOUNDATION-TRANSITION.md +67 -0
  24. package/dist/spec/IPR.md +27 -0
  25. package/dist/spec/LICENSE +190 -0
  26. package/dist/spec/NOTICE +4 -0
  27. package/dist/spec/README.md +47 -0
  28. package/dist/spec/conformance/base64url-decode.schema.json +176 -0
  29. package/dist/spec/conformance/blueprint-decode.schema.json +280 -0
  30. package/dist/spec/conformance/bounds-new.schema.json +302 -0
  31. package/dist/spec/conformance/bounds_algebra-intersect.schema.json +457 -0
  32. package/dist/spec/conformance/canonicalization-encode.schema.json +280 -0
  33. package/dist/spec/conformance/case-file.schema.json +122 -0
  34. package/dist/spec/conformance/certified-results.json +1 -0
  35. package/dist/spec/conformance/claim.schema.json +52 -0
  36. package/dist/spec/conformance/compatibility-verify.schema.json +262 -0
  37. package/dist/spec/conformance/deployment-decode.schema.json +322 -0
  38. package/dist/spec/conformance/digest-tagged.schema.json +200 -0
  39. package/dist/spec/conformance/evidence.schema.json +249 -0
  40. package/dist/spec/conformance/execution.md +80 -0
  41. package/dist/spec/conformance/extension-resolve.schema.json +264 -0
  42. package/dist/spec/conformance/federation-decode.schema.json +318 -0
  43. package/dist/spec/conformance/federation-verify_commitment.schema.json +342 -0
  44. package/dist/spec/conformance/index.schema.json +102 -0
  45. package/dist/spec/conformance/json-decode.schema.json +287 -0
  46. package/dist/spec/conformance/negotiation-negotiate.schema.json +264 -0
  47. package/dist/spec/conformance/portability-scan.schema.json +188 -0
  48. package/dist/spec/conformance/predicate.schema.json +201 -0
  49. package/dist/spec/conformance/reconcile.schema.json +287 -0
  50. package/dist/spec/conformance/runner.md +182 -0
  51. package/dist/spec/conformance/schema-validate_instance.schema.json +206 -0
  52. package/dist/spec/conformance/signature-verify.schema.json +224 -0
  53. package/dist/spec/conformance/support.schema.json +72 -0
  54. package/dist/spec/errata.md +13 -0
  55. package/dist/spec/grammar/blueprint.cddl +92 -0
  56. package/dist/spec/grammar/deployment.cddl +125 -0
  57. package/dist/spec/grammar/derived/blueprint.schema.json +340 -0
  58. package/dist/spec/grammar/derived/deployment.schema.json +496 -0
  59. package/dist/spec/grammar/derived/taskenvelope.schema.json +244 -0
  60. package/dist/spec/grammar/taskenvelope.cddl +77 -0
  61. package/dist/spec/protocol.md +1238 -0
  62. package/dist/spec/registry/OPERATIONS.md +69 -0
  63. package/dist/spec/registry/registry.json +68 -0
  64. package/dist/verifier/b64url.d.ts +6 -2
  65. package/dist/verifier/b64url.js +7 -1
  66. package/dist/verifier/blueprint.d.ts +12 -16
  67. package/dist/verifier/blueprint.js +40 -112
  68. package/dist/verifier/bounds.d.ts +1 -1
  69. package/dist/verifier/bounds.js +2 -2
  70. package/dist/verifier/bounds_algebra.d.ts +9 -0
  71. package/dist/verifier/bounds_algebra.js +10 -7
  72. package/dist/verifier/canonical.d.ts +1 -1
  73. package/dist/verifier/canonical.js +41 -8
  74. package/dist/verifier/cli.js +97 -45
  75. package/dist/verifier/compatibility.js +5 -7
  76. package/dist/verifier/corpus.d.ts +1 -1
  77. package/dist/verifier/corpus.js +10 -2
  78. package/dist/verifier/decode.js +24 -6
  79. package/dist/verifier/deployment.d.ts +20 -3
  80. package/dist/verifier/deployment.js +48 -10
  81. package/dist/verifier/digest.d.ts +12 -0
  82. package/dist/verifier/digest.js +17 -3
  83. package/dist/verifier/errors.d.ts +2 -0
  84. package/dist/verifier/errors.js +1 -0
  85. package/dist/verifier/execution.d.ts +13 -0
  86. package/dist/verifier/execution.js +82 -0
  87. package/dist/verifier/extension.js +4 -4
  88. package/dist/verifier/facade.d.ts +325 -0
  89. package/dist/verifier/facade.js +78 -0
  90. package/dist/verifier/federation.d.ts +2 -2
  91. package/dist/verifier/federation.js +26 -79
  92. package/dist/verifier/harness.d.ts +16 -0
  93. package/dist/verifier/harness.js +201 -0
  94. package/dist/verifier/index.d.ts +3 -0
  95. package/dist/verifier/index.js +2 -0
  96. package/dist/verifier/mapping.d.ts +139 -0
  97. package/dist/verifier/mapping.js +1 -0
  98. package/dist/verifier/negotiation.d.ts +2 -1
  99. package/dist/verifier/negotiation.js +12 -3
  100. package/dist/verifier/plain.d.ts +4 -0
  101. package/dist/verifier/plain.js +38 -0
  102. package/dist/verifier/portability.d.ts +1 -1
  103. package/dist/verifier/portability.js +19 -6
  104. package/dist/verifier/predicate.d.ts +7 -0
  105. package/dist/verifier/predicate.js +63 -7
  106. package/dist/verifier/reconcile.d.ts +37 -0
  107. package/dist/verifier/reconcile.js +115 -0
  108. package/dist/verifier/registry.js +10 -1
  109. package/dist/verifier/registry_engine.d.ts +3 -0
  110. package/dist/verifier/registry_engine.js +37 -20
  111. package/dist/verifier/report.d.ts +8 -0
  112. package/dist/verifier/report.js +9 -2
  113. package/dist/verifier/results.d.ts +3 -0
  114. package/dist/verifier/results.js +13 -0
  115. package/dist/verifier/run_corpus.js +4 -80
  116. package/dist/verifier/runner.d.ts +6 -0
  117. package/dist/verifier/runner.js +123 -17
  118. package/dist/verifier/schema.js +14 -55
  119. package/dist/verifier/signature.d.ts +19 -8
  120. package/dist/verifier/signature.js +51 -29
  121. package/dist/verifier/value.d.ts +9 -2
  122. package/dist/verifier/value.js +81 -11
  123. package/package.json +17 -12
@@ -1,9 +1,4 @@
1
- // The Deployment Manifest artifact — the mirror of AgentBlueprintProtocol.Deployment:
2
- // canonical verify → the 19-member registry table (exact-only build-identity
3
- // versions, lifecycle temporal rules, the as_of total rule) → the portability
4
- // scan (eligibility expressions as the open region) → the content-digest
5
- // comparison under the deployment_content domain; plus the six-stage
6
- // verify_binding deny set with its pinned order.
1
+ import { isValue } from "./value.js";
7
2
  import { coerce as coerceBounds, maximum as maxBounds } from "./bounds.js";
8
3
  import * as blueprint from "./blueprint.js";
9
4
  import * as canonical from "./canonical.js";
@@ -233,6 +228,7 @@ export function table() {
233
228
  field("signatures", { array: { kind: "custom", check: checkSignatureEntry } }, {
234
229
  required: false,
235
230
  maxItems: CEILING_SIGNATURES,
231
+ check: checkSignatureIds,
236
232
  }),
237
233
  field("attestations", { array: { kind: "any" } }, {
238
234
  required: false,
@@ -265,7 +261,14 @@ export function decode(bytes, bounds) {
265
261
  return { ok: true, v: { value } };
266
262
  }
267
263
  export function fromValue(value, opts = {}) {
264
+ if (opts === null || typeof opts !== "object" || Array.isArray(opts))
265
+ return { ok: false, e: "invalid_type" };
268
266
  const validated = opts.authoredExtensions ?? [];
267
+ if (!Array.isArray(validated) || validated.some((ns) => typeof ns !== "string"))
268
+ return { ok: false, e: "invalid_type" };
269
+ const shaped = canonical.encode(value);
270
+ if (!shaped.ok)
271
+ return shaped;
269
272
  if (validated.length > 0) {
270
273
  if (value.t !== "obj")
271
274
  return { ok: false, e: "invalid_type" };
@@ -282,24 +285,30 @@ export function fromValue(value, opts = {}) {
282
285
  return { ok: true, v: { value } };
283
286
  }
284
287
  export function toValue(deployment) {
285
- return deployment.value;
288
+ return deployment && isValue(deployment.value) ? deployment.value : { ok: false, e: "invalid_type" };
286
289
  }
287
290
  // ---- digest surface --------------------------------------------------------------------
288
291
  export function digestInput(deployment) {
292
+ if (!deployment || !isValue(deployment.value))
293
+ return { ok: false, e: "invalid_type" };
289
294
  if (deployment.value.t !== "obj")
290
295
  return deployment.value;
291
296
  return { t: "obj", v: deployment.value.v.filter(([name]) => !EVIDENCE_MEMBERS.includes(name)) };
292
297
  }
293
298
  export function canonicalBytes(deployment) {
299
+ if (!deployment || typeof deployment !== "object")
300
+ return { ok: false, e: "invalid_type" };
294
301
  return canonical.encode(deployment.value);
295
302
  }
296
303
  export function contentDigest(deployment) {
297
304
  const jcs = canonical.encode(digestInput(deployment));
298
305
  if (!jcs.ok)
299
- throw new Error("deployment digest input must encode");
306
+ return jcs;
300
307
  return digest.toTagged(digest.hash("deployment_content", Buffer.from(jcs.v, "utf8")));
301
308
  }
302
309
  export function verifyContentDigest(deployment) {
310
+ if (!deployment || !isValue(deployment.value))
311
+ return { ok: false, e: "invalid_type" };
303
312
  const members = deployment.value.t === "obj" ? deployment.value.v : [];
304
313
  const declared = keyfind(members, "deployment_digest");
305
314
  if (declared === null || declared.t !== "str")
@@ -313,6 +322,8 @@ export function verifyContentDigest(deployment) {
313
322
  // a non-array member, a non-object entry, a non-string operand, or an
314
323
  // unparsable descriptor digest is a malformed deployment, never empty.
315
324
  function boundToolBindings(deployment) {
325
+ if (!deployment || !isValue(deployment.value))
326
+ return { ok: false, e: "invalid_type" };
316
327
  if (deployment.value.t !== "obj")
317
328
  return { ok: false, e: "invalid_type" };
318
329
  const members = deployment.value.v;
@@ -349,6 +360,8 @@ function boundRelease(deployment) {
349
360
  const bindings = boundToolBindings(deployment);
350
361
  if (!bindings.ok)
351
362
  return bindings;
363
+ if (!deployment || !isValue(deployment.value))
364
+ return { ok: false, e: "invalid_type" };
352
365
  if (deployment.value.t !== "obj")
353
366
  return { ok: false, e: "invalid_type" };
354
367
  const release = keyfind(deployment.value.v, "blueprint_release");
@@ -372,6 +385,9 @@ function boundRelease(deployment) {
372
385
  // tool-binding completeness → mutation/recovery → attestation staleness →
373
386
  // observed rug-pull. Stages 5-6 are observation-gated.
374
387
  export function verifyBinding(deployment, bound, obs) {
388
+ if (!deployment || !isValue(deployment.value) || !bound || !isValue(bound.value) || !obs || typeof obs !== "object" || !obs.observed || typeof obs.observed !== "object" ||
389
+ (Object.getPrototypeOf(obs.observed) !== Object.prototype && Object.getPrototypeOf(obs.observed) !== null))
390
+ return { ok: false, e: "invalid_type" };
375
391
  const bindings = boundToolBindings(deployment);
376
392
  if (!bindings.ok)
377
393
  return bindings;
@@ -450,6 +466,8 @@ function stageRecovery(deployment, bindings, bound) {
450
466
  function stageStaleness(bindings, obs) {
451
467
  if (obs.now === null)
452
468
  return { ok: true };
469
+ if (typeof obs.now !== "string")
470
+ return { ok: false, e: "invalid_type" };
453
471
  const now = parseTimestamp(obs.now);
454
472
  if (now === null)
455
473
  return { ok: true }; // parse_time parity: undecodable now skips
@@ -478,6 +496,8 @@ function stageRugPull(bindings, obs) {
478
496
  for (const entry of bindings) {
479
497
  const operation = memberString(entry, "logical_operation");
480
498
  const tagged = memberString(entry, "descriptor_digest");
499
+ if (typeof tagged !== "string")
500
+ return { ok: false, e: "invalid_type" };
481
501
  const parsed = digest.fromTagged(tagged);
482
502
  if (parsed.ok)
483
503
  attested.set(operation, parsed.v);
@@ -496,6 +516,8 @@ function stageRugPull(bindings, obs) {
496
516
  return { ok: true };
497
517
  }
498
518
  function recoveryMode(deployment) {
519
+ if (!deployment || !isValue(deployment.value))
520
+ return { ok: false, e: "invalid_type" };
499
521
  if (deployment.value.t !== "obj")
500
522
  return { ok: false, e: "invalid_type" };
501
523
  const owner = keyfind(deployment.value.v, "effect_owner");
@@ -514,6 +536,8 @@ function recoveryMode(deployment) {
514
536
  function blueprintContentDigest(bound) {
515
537
  try {
516
538
  const tagged = blueprint.contentDigest(bound);
539
+ if (typeof tagged !== "string")
540
+ return null;
517
541
  const parsed = digest.fromTagged(tagged);
518
542
  return parsed.ok ? parsed.v : null;
519
543
  }
@@ -642,10 +666,20 @@ function checkRequiredCoreFields(value) {
642
666
  }
643
667
  // The purpose is this artifact's fact: the envelope parses AND must be
644
668
  // "deployment" here.
669
+ function checkSignatureIds(value) {
670
+ if (value.t !== "arr")
671
+ return { ok: false, e: "invalid_type" };
672
+ const ids = value.v.flatMap((entry) => {
673
+ const attrs = entry?.t === "obj" ? keyfind(entry.v, "signed_attributes") : null;
674
+ const id = attrs?.t === "obj" ? keyfind(attrs.v, "key_id") : null;
675
+ return id?.t === "str" ? [id.v] : [];
676
+ });
677
+ return new Set(ids).size === ids.length ? { ok: true } : { ok: false, e: "invalid_constraint" };
678
+ }
645
679
  function checkSignatureEntry(entry) {
646
680
  const attrs = blueprint.signatureAttributes(entry);
647
681
  if (!attrs.ok)
648
- return { ok: false, e: attrs.e };
682
+ return attrs;
649
683
  return attrs.v.purpose === "deployment" ? { ok: true } : { ok: false, e: "invalid_constraint" };
650
684
  }
651
685
  // An eligibility expression: any non-empty JSON object — the host's policy
@@ -740,7 +774,9 @@ function checkExactVersion(value) {
740
774
  return { ok: true };
741
775
  }
742
776
  // ---- the portability scan ---------------------------------------------------------------
743
- function scan(value, authoredNs) {
777
+ export function scan(value, authoredNs) {
778
+ if (!isValue(value) || value.t !== "obj" || !(authoredNs instanceof Set) || [...authoredNs].some(ns => typeof ns !== "string"))
779
+ return { ok: false, e: "invalid_type" };
744
780
  if (value.t !== "obj")
745
781
  return { ok: false, e: "invalid_type" };
746
782
  const members = value.v;
@@ -814,6 +850,8 @@ function normalizeBounds(bounds) {
814
850
  // (DateTime.from_iso8601 parity, restricted to the calendar-valid Z form the
815
851
  // tables already enforce).
816
852
  export function parseTimestamp(stamped) {
853
+ if (typeof stamped !== "string")
854
+ return null;
817
855
  const matched = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(Z|[+-]\d{2}:\d{2})$/.exec(stamped);
818
856
  if (matched === null)
819
857
  return null;
@@ -5,8 +5,20 @@ export interface Digest {
5
5
  bytes: Buffer;
6
6
  }
7
7
  export declare function of(data: Buffer): Digest;
8
+ export declare function of(data: unknown): Digest | {
9
+ ok: false;
10
+ e: string;
11
+ };
8
12
  export declare function hash(domain: Domain, data: Buffer): Digest;
13
+ export declare function hash(domain: unknown, data: unknown): Digest | {
14
+ ok: false;
15
+ e: string;
16
+ };
9
17
  export declare function toTagged(digest: Digest): string;
18
+ export declare function toTagged(digest: unknown): string | {
19
+ ok: false;
20
+ e: string;
21
+ };
10
22
  export declare function fromTagged(input: string): {
11
23
  ok: true;
12
24
  v: Digest;
@@ -1,6 +1,6 @@
1
1
  // Domain-separated SHA-256 digests — the mirror of AgentBlueprintProtocol.Digest:
2
2
  // preimage `separator || 0x00 || jcs_bytes` under the registered separator
3
- // (base §8.2), tagged wire form "sha-256:<43-char unpadded base64url>".
3
+ // (protocol §5), tagged wire form "sha-256:<43-char unpadded base64url>".
4
4
  import { createHash } from "node:crypto";
5
5
  import * as b64 from "./b64url.js";
6
6
  export const SEPARATORS = {
@@ -16,15 +16,25 @@ export const SEPARATORS = {
16
16
  const SIZES = { "sha-256": 32 };
17
17
  const TAGS = Object.keys(SIZES);
18
18
  export function of(data) {
19
+ if (!Buffer.isBuffer(data))
20
+ return { ok: false, e: "invalid_type" };
19
21
  return { algorithm: "sha-256", bytes: createHash("sha256").update(data).digest() };
20
22
  }
21
- export function hash(domain, data) {
23
+ export function hash(domainInput, data) {
24
+ const domain = domainInput;
25
+ if (typeof domain !== "string" || !Object.hasOwn(SEPARATORS, domain) || !Buffer.isBuffer(data))
26
+ return { ok: false, e: "invalid_type" };
22
27
  return of(Buffer.concat([Buffer.from(SEPARATORS[domain], "utf8"), Buffer.from([0]), data]));
23
28
  }
24
- export function toTagged(digest) {
29
+ export function toTagged(input) {
30
+ const digest = input;
31
+ if (!digest || digest.algorithm !== "sha-256" || !Buffer.isBuffer(digest.bytes) || digest.bytes.length !== 32)
32
+ return { ok: false, e: "invalid_type" };
25
33
  return "sha-256:" + b64.encode(digest.bytes);
26
34
  }
27
35
  export function fromTagged(input) {
36
+ if (typeof input !== "string")
37
+ return { ok: false, e: "invalid_type" };
28
38
  const colon = input.indexOf(":");
29
39
  if (colon === -1)
30
40
  return { ok: false, e: "digest_encoding_invalid" };
@@ -41,6 +51,8 @@ export function fromTagged(input) {
41
51
  }
42
52
  // Constant-time equality over the digest bytes (the twin's xor-accumulate).
43
53
  export function equal(a, b) {
54
+ if (!a || !b || !Buffer.isBuffer(a.bytes) || !Buffer.isBuffer(b.bytes))
55
+ return false;
44
56
  if (a.bytes.length !== b.bytes.length || a.algorithm !== b.algorithm)
45
57
  return false;
46
58
  let diff = 0;
@@ -49,6 +61,8 @@ export function equal(a, b) {
49
61
  return diff === 0;
50
62
  }
51
63
  export function verifyContent(domain, jcsBytes, tagged) {
64
+ if (typeof domain !== "string" || !Object.hasOwn(SEPARATORS, domain) || !Buffer.isBuffer(jcsBytes))
65
+ return { ok: false, e: "invalid_type" };
52
66
  const declared = fromTagged(tagged);
53
67
  if (!declared.ok)
54
68
  return declared;
@@ -0,0 +1,2 @@
1
+ /** Closed denial vocabulary, including the decoder ceiling family. */
2
+ export type ErrorCode = "attestation_malformed" | "audience_mismatch" | "base64url_invalid" | "base64url_padded" | "binding_attestation_stale" | "binding_descriptor_mismatch" | "binding_incomplete" | "bound_source_missing" | "bound_unit_mismatch" | "bound_unknown" | "bound_value_invalid" | "ceiling:bytes" | "ceiling:depth" | "ceiling:items" | "ceiling:key" | "ceiling:members" | "ceiling:nodes" | "ceiling:number_lexeme" | "ceiling:string" | "compatibility_duplicate_entry" | "compatibility_entry_missing" | "compatibility_identity_inexact" | "corpus_applicability_incomplete" | "corpus_case_id_duplicate" | "corpus_case_invalid" | "corpus_count_mismatch" | "corpus_empty" | "corpus_file_set_mismatch" | "corpus_hash_mismatch" | "corpus_index_invalid" | "deployment_digest_mismatch" | "digest_algorithm_unsupported" | "digest_encoding_invalid" | "digest_mismatch" | "duplicate_member" | "extension_criticality_conflict" | "extension_duplicate" | "extension_namespace_invalid" | "extension_payload_forbidden" | "extension_retired" | "extension_schema_digest_mismatch" | "extension_schema_unavailable" | "extension_unknown_critical" | "federation_mapping_conflict" | "federation_state_unmappable" | "federation_terminal_conflict" | "forbidden_portable_value" | "integer_magnitude" | "invalid_cardinality" | "invalid_constraint" | "invalid_encoding" | "invalid_number" | "invalid_syntax" | "invalid_type" | "lifecycle_state_invalid" | "missing_ceiling" | "missing_required_field" | "no_authoritative_recovery" | "non_canonical_bytes" | "nonportable_content" | "number_not_double_expressible" | "predicate_nodes_exceeded" | "predicate_op_unknown" | "predicate_path_unresolved" | "protected_bound_clamp_denied" | "protocol_revision_unsupported" | "required_core_field_not_digest_covered" | "required_core_field_unsupported" | "schema_complexity_exceeded" | "schema_dialect_unknown" | "schema_invalid_shape" | "schema_keyword_not_allowed" | "schema_keyword_value_invalid" | "schema_ref_cycle" | "schema_ref_unresolvable" | "signature_algorithm_unsupported" | "signature_key_unsupported" | "signature_malformed" | "signature_not_verified" | "trailing_bytes" | "unknown_bound" | "unknown_member";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import type { Readable } from 'node:stream';
2
+ import { type LoadedCorpus } from './corpus.ts';
3
+ export declare const LINE_LIMIT = 5000000;
4
+ export declare class ExecutionFailure extends Error {
5
+ outcome: string;
6
+ constructor(outcome: string);
7
+ }
8
+ export declare function lines(stream: Readable): {
9
+ next: (timeout: number) => Promise<unknown>;
10
+ end: () => void;
11
+ };
12
+ export declare function handshake(corpus: LoadedCorpus): Record<string, unknown>;
13
+ export declare function serve(corpus: LoadedCorpus): Promise<number>;
@@ -0,0 +1,82 @@
1
+ import { decode } from './decode.js';
2
+ import { plain } from './plain.js';
3
+ import { canonical } from './results.js';
4
+ import { memberString } from './corpus.js';
5
+ import { project } from './runner.js';
6
+ export const LINE_LIMIT = 5_000_000;
7
+ export class ExecutionFailure extends Error {
8
+ outcome;
9
+ constructor(outcome) { super(outcome); this.outcome = outcome; }
10
+ }
11
+ export function lines(stream) {
12
+ const queue = [];
13
+ let pending = null, buffer = Buffer.alloc(0), ended = false;
14
+ const push = (x) => { if (pending) {
15
+ const resolve = pending;
16
+ pending = null;
17
+ resolve(x);
18
+ }
19
+ else
20
+ queue.push(x); };
21
+ stream.on('data', (chunk) => {
22
+ buffer = Buffer.concat([buffer, chunk]);
23
+ for (;;) {
24
+ const index = buffer.indexOf(10);
25
+ if (index < 0)
26
+ break;
27
+ const row = buffer.subarray(0, index);
28
+ buffer = buffer.subarray(index + 1);
29
+ if (row.length + 1 > LINE_LIMIT) {
30
+ push(new ExecutionFailure('oversized_line'));
31
+ stream.pause();
32
+ return;
33
+ }
34
+ const value = decode(row);
35
+ push(value.ok ? plain(value.v) : new ExecutionFailure('malformed_line'));
36
+ }
37
+ if (buffer.length >= LINE_LIMIT) {
38
+ push(new ExecutionFailure('oversized_line'));
39
+ stream.pause();
40
+ }
41
+ });
42
+ const end = () => { if (ended)
43
+ return; ended = true; if (buffer.length)
44
+ push(new ExecutionFailure('malformed_line')); push(null); };
45
+ stream.on('end', end);
46
+ stream.on('error', () => push(new ExecutionFailure('early_exit')));
47
+ return { end, next: async (timeout) => {
48
+ let timer;
49
+ const item = queue.length ? queue.shift() : ended ? null : await new Promise(resolve => { pending = resolve; timer = setTimeout(() => { pending = null; resolve(new ExecutionFailure('response_timeout')); }, timeout); });
50
+ if (timer)
51
+ clearTimeout(timer);
52
+ if (item instanceof Error)
53
+ throw item;
54
+ return item;
55
+ } };
56
+ }
57
+ export function handshake(corpus) {
58
+ return { protocol: 'agent-blueprint-protocol-conformance-execution', version: 1, corpus_digest: corpus.identity, registry_digest: memberString(corpus.index, 'registry_digest') };
59
+ }
60
+ export async function serve(corpus) {
61
+ const reader = lines(process.stdin), hello = handshake(corpus);
62
+ try {
63
+ if (canonical(await reader.next(30_000)) !== canonical(hello))
64
+ return 2;
65
+ process.stdout.write(canonical(hello) + '\n');
66
+ for (;;) {
67
+ const request = await reader.next(30_000);
68
+ if (request === null)
69
+ return 0;
70
+ if (!request || Object.keys(request).sort().join(',') !== 'id,input,surface' || typeof request.id !== 'string' || typeof request.surface !== 'string' || !request.input || typeof request.input !== 'object' || Array.isArray(request.input))
71
+ return 2;
72
+ const input = decode(canonical(request.input));
73
+ if (!input.ok)
74
+ return 2;
75
+ const row = { id: request.id, surface: request.surface, input: input.v, expected: { t: 'obj', v: [] } };
76
+ process.stdout.write(canonical({ id: request.id, result: project(row, corpus.data, corpus.raws) }) + '\n');
77
+ }
78
+ }
79
+ catch {
80
+ return 2;
81
+ }
82
+ }
@@ -1,13 +1,11 @@
1
- // The positional extension envelope — the mirror of AgentBlueprintProtocol.Extension:
2
- // {"critical": {ns → body}, "optional": {ns → body}}, shared by both artifact
3
- // tables as a table check and by the scans as the open-region walk.
1
+ import { isValue } from "./value.js";
4
2
  const IDENTIFIER_BYTES = 512;
5
3
  const CEILING_EXTENSIONS = 32;
6
4
  const NAMESPACE = /^[a-z0-9][a-z0-9.-]*\/[a-z0-9][a-z0-9.-]*$/;
7
5
  // The envelope shape check a table carries: exactly critical + optional
8
6
  // regions, namespace form, total cardinality, no namespace in both.
9
7
  export function envelopeOk(value) {
10
- if (value.t !== "obj")
8
+ if (!isValue(value) || value.t !== "obj")
11
9
  return { ok: false, e: "invalid_type" };
12
10
  const members = value.v;
13
11
  const names = members.map(([name]) => name).sort();
@@ -70,6 +68,8 @@ function namespaceForm(ns) {
70
68
  return Buffer.byteLength(ns, "utf8") <= IDENTIFIER_BYTES && NAMESPACE.test(ns);
71
69
  }
72
70
  function memberValue(members, name) {
71
+ if (!isValue({ t: "obj", v: members }))
72
+ return null;
73
73
  const found = members.find(([key]) => key === name);
74
74
  return found ? found[1] : null;
75
75
  }