@agent-blueprint-protocol/verifier 0.8.2 → 0.8.4

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 (49) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +6 -6
  3. package/dist/corpus/cases/blueprint-decode.json +1 -1
  4. package/dist/corpus/cases/bounds-new.json +1 -1
  5. package/dist/corpus/cases/bounds_algebra-intersect.json +1 -1
  6. package/dist/corpus/cases/canonicalization-encode.json +1 -1
  7. package/dist/corpus/cases/deployment-decode.json +1 -1
  8. package/dist/corpus/cases/federation-decode.json +1 -1
  9. package/dist/corpus/cases/json-decode.json +1 -1
  10. package/dist/corpus/cases/portability-scan.json +1 -1
  11. package/dist/corpus/cases/schema-validate_instance.json +1 -1
  12. package/dist/corpus/index.json +1 -1
  13. package/dist/kit/cli.mjs +1 -4
  14. package/dist/release-metadata.json +1 -1
  15. package/dist/verifier/b64url.d.ts +6 -2
  16. package/dist/verifier/b64url.js +6 -0
  17. package/dist/verifier/blueprint.d.ts +12 -3
  18. package/dist/verifier/blueprint.js +21 -7
  19. package/dist/verifier/bounds.d.ts +1 -1
  20. package/dist/verifier/bounds.js +3 -3
  21. package/dist/verifier/bounds_algebra.js +7 -4
  22. package/dist/verifier/canonical.d.ts +1 -1
  23. package/dist/verifier/canonical.js +41 -8
  24. package/dist/verifier/cli.js +111 -42
  25. package/dist/verifier/compatibility.js +6 -8
  26. package/dist/verifier/corpus.js +5 -1
  27. package/dist/verifier/decode.js +9 -3
  28. package/dist/verifier/deployment.d.ts +12 -3
  29. package/dist/verifier/deployment.js +33 -10
  30. package/dist/verifier/digest.d.ts +12 -0
  31. package/dist/verifier/digest.js +16 -2
  32. package/dist/verifier/extension.js +4 -4
  33. package/dist/verifier/federation.js +18 -74
  34. package/dist/verifier/negotiation.js +8 -2
  35. package/dist/verifier/portability.d.ts +1 -1
  36. package/dist/verifier/portability.js +45 -8
  37. package/dist/verifier/predicate.js +4 -7
  38. package/dist/verifier/registry_engine.js +29 -12
  39. package/dist/verifier/report.d.ts +8 -0
  40. package/dist/verifier/report.js +9 -2
  41. package/dist/verifier/run_corpus.js +4 -80
  42. package/dist/verifier/runner.d.ts +4 -0
  43. package/dist/verifier/runner.js +13 -15
  44. package/dist/verifier/schema.js +14 -55
  45. package/dist/verifier/signature.d.ts +2 -2
  46. package/dist/verifier/signature.js +10 -4
  47. package/dist/verifier/value.d.ts +9 -2
  48. package/dist/verifier/value.js +81 -11
  49. package/package.json +1 -1
@@ -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
  }
@@ -1,11 +1,5 @@
1
- // The federation profile — the mirror of AgentBlueprintProtocol.Federation:
2
- // the 23-member TaskEnvelope decoded through the registry engine (carrier-key
3
- // placement laws, R1-R4 root hooks), the lossy-aware A2A/MCP state codecs
4
- // (federation_state_unmappable, never a silent degrade), the bounded
5
- // from_value reconstruction path, and verify_commitment's numbered steps
6
- // (terminal members → JWS verify → binding → commitment recompute → context
7
- // compare → prior-receipt conflict → signed freshness).
8
- import { MAXIMA as CEILINGS, coerce as coerceBounds, maximum as maxBounds } from "./bounds.js";
1
+ import { isValue } from "./value.js";
2
+ import { coerce as coerceBounds, maximum as maxBounds } from "./bounds.js";
9
3
  import * as blueprint from "./blueprint.js";
10
4
  import * as canonical from "./canonical.js";
11
5
  import * as digest from "./digest.js";
@@ -250,7 +244,7 @@ export function decode(bytes, bounds) {
250
244
  // already-decoded value, with the decoder's ceilings re-imposed (a hostile
251
245
  // carrier body cannot buy unbounded work the decode lane would have refused).
252
246
  export function fromValue(value) {
253
- if (value.t !== "obj")
247
+ if (!value || value.t !== "obj")
254
248
  return { ok: false, e: "invalid_type" };
255
249
  const bounded = boundedShape(value);
256
250
  if (!bounded.ok)
@@ -268,69 +262,15 @@ function normalizeBounds(bounds) {
268
262
  return { ok: true, v: maxBounds() };
269
263
  return coerceBounds(bounds);
270
264
  }
265
+ // ---- the bounded shape walk (from_value's decoder-parity gate) ----------------------
271
266
  function boundedShape(value) {
272
- return shapeWalk(value, { members: 0, items: 0, nodes: 0, string: 0, depth: 0 });
273
- }
274
- function shapeWalk(value, acc) {
275
- const entry = ceiling(acc);
276
- if (!entry.ok)
277
- return entry;
278
- switch (value.t) {
279
- case "obj": {
280
- const bumped = bump(acc, { members: value.v.length, nodes: 1, depth: 1 });
281
- return walkShapeMembers(value.v, bumped);
282
- }
283
- case "arr": {
284
- const bumped = bump(acc, { items: value.v.length, nodes: 1, depth: 1 });
285
- return walkShapeItems(value.v, bumped);
286
- }
287
- case "str": {
288
- const bumped = bump(acc, { nodes: 1, string: Buffer.byteLength(value.v, "utf8"), depth: 1 });
289
- return ceiling(bumped);
290
- }
291
- default:
292
- return ceiling(bump(acc, { nodes: 1 }));
293
- }
294
- }
295
- function walkShapeMembers(members, acc) {
296
- for (const [, value] of members) {
297
- const result = shapeWalk(value, acc);
298
- if (!result.ok)
299
- return result;
300
- }
301
- return { ok: true };
302
- }
303
- function walkShapeItems(items, acc) {
304
- for (const item of items) {
305
- const result = shapeWalk(item, acc);
306
- if (!result.ok)
307
- return result;
308
- }
309
- return { ok: true };
310
- }
311
- function bump(acc, adds) {
312
- const out = { ...acc };
313
- for (const [key, add] of Object.entries(adds)) {
314
- out[key] += add;
315
- }
316
- return out;
317
- }
318
- function ceiling(acc) {
319
- const checks = [
320
- ["members", CEILINGS.members, "members"],
321
- ["items", CEILINGS.items, "items"],
322
- ["nodes", CEILINGS.nodes, "nodes"],
323
- ["string", CEILINGS.string, "string"],
324
- ["depth", CEILINGS.depth, "depth"],
325
- ];
326
- for (const [key, max, name] of checks) {
327
- if (acc[key] > max)
328
- return { ok: false, e: `ceiling:${name}` };
329
- }
330
- return { ok: true };
267
+ const result = canonical.encode(value);
268
+ return result.ok ? { ok: true } : result;
331
269
  }
332
270
  // ---- canonical bytes ------------------------------------------------------------------
333
271
  export function canonicalBytes(envelope) {
272
+ if (!envelope || typeof envelope !== "object")
273
+ return { ok: false, e: "invalid_type" };
334
274
  return canonical.encode(envelope.value);
335
275
  }
336
276
  // ---- the federation portability pass (mode map + R4) ----------------------------------
@@ -427,7 +367,7 @@ function keyIdPositions(entry) {
427
367
  export function fromA2aState(spelling) {
428
368
  if (typeof spelling !== "string")
429
369
  return { ok: false, e: "invalid_type" };
430
- if (spelling in A2A_TO_LOGICAL)
370
+ if (Object.hasOwn(A2A_TO_LOGICAL, spelling))
431
371
  return { ok: true, v: A2A_TO_LOGICAL[spelling] };
432
372
  if (spelling === "TASK_STATE_UNSPECIFIED") {
433
373
  return { ok: false, e: "federation_state_unmappable" };
@@ -444,7 +384,7 @@ export function toA2aState(spelling) {
444
384
  export function fromMcpState(spelling) {
445
385
  if (typeof spelling !== "string")
446
386
  return { ok: false, e: "invalid_type" };
447
- if (spelling in MCP_TO_LOGICAL)
387
+ if (Object.hasOwn(MCP_TO_LOGICAL, spelling))
448
388
  return { ok: true, v: MCP_TO_LOGICAL[spelling] };
449
389
  return { ok: false, e: "invalid_constraint" };
450
390
  }
@@ -466,7 +406,7 @@ export function mcpCarrierKey() {
466
406
  return "com.example/federation";
467
407
  }
468
408
  export function fromA2aCarrier(carrier) {
469
- if (carrier.t !== "obj")
409
+ if (!isValue(carrier) || carrier.t !== "obj")
470
410
  return { ok: false, e: "invalid_type" };
471
411
  const id = carrierString(carrier.v, "id");
472
412
  if (!id.ok)
@@ -487,7 +427,7 @@ export function fromA2aCarrier(carrier) {
487
427
  return rebuilt.ok ? { ok: true, v: { decoded: true } } : rebuilt;
488
428
  }
489
429
  export function fromMcpCarrier(carrier) {
490
- if (carrier.t !== "obj")
430
+ if (!isValue(carrier) || carrier.t !== "obj")
491
431
  return { ok: false, e: "invalid_type" };
492
432
  const id = carrierString(carrier.v, "taskId");
493
433
  if (!id.ok)
@@ -558,7 +498,7 @@ function rebuild(id, logical, body) {
558
498
  // The Terminal Commitment: the domain-separated digest over exactly the
559
499
  // seven named components.
560
500
  export function terminalCommitment(envelope) {
561
- if (envelope.value.t !== "obj")
501
+ if (!envelope || !isValue(envelope.value) || envelope.value.t !== "obj")
562
502
  return { ok: false, e: "invalid_type" };
563
503
  const members = new Map(envelope.value.v);
564
504
  const taskOk = stringMember(members, "task_identity");
@@ -591,7 +531,7 @@ export function terminalCommitment(envelope) {
591
531
  return { ok: true, v: digest.hash("federation_envelope", Buffer.from(jcs.v, "utf8")) };
592
532
  }
593
533
  export function verifyCommitment(envelope, context) {
594
- if (envelope.value.t !== "obj")
534
+ if (!envelope || !isValue(envelope.value) || envelope.value.t !== "obj")
595
535
  return { ok: false, e: "invalid_type" };
596
536
  const members = new Map(envelope.value.v);
597
537
  const taskOk = stringMember(members, "task_identity");
@@ -606,6 +546,10 @@ export function verifyCommitment(envelope, context) {
606
546
  const signatureEntry = receiptFetch(receipt.v, "signature");
607
547
  if (!signatureEntry.ok)
608
548
  return signatureEntry;
549
+ if (!context || typeof context !== "object" || !Array.isArray(context.keys) ||
550
+ (context.issuerKeySets != null && (typeof context.issuerKeySets !== "object" || Array.isArray(context.issuerKeySets) || Object.values(context.issuerKeySets).some((keys) => !Array.isArray(keys)))) ||
551
+ (!Array.isArray(context.priorReceipts) || context.priorReceipts.some((receipt) => !receipt || typeof receipt !== "object")))
552
+ return { ok: false, e: "invalid_type" };
609
553
  const pool = resolvePool(members, context);
610
554
  if (!pool.ok)
611
555
  return pool;
@@ -1,3 +1,4 @@
1
+ import { isValue } from "./value.js";
1
2
  // Negotiation — the mirror of AgentBlueprintProtocol.Negotiation: the
2
3
  // evolution gate over protocol machinery only (protocol_revision →
3
4
  // required_core_fields → extensions, precedence pinned), the host-pinned
@@ -84,6 +85,11 @@ const RESERVED_NAMES = new Set([
84
85
  "maxtokens",
85
86
  ]);
86
87
  export function negotiate(artifact, support) {
88
+ if (!isValue(artifact) || !support || !(support.revisions instanceof Set) || !(support.coreFields instanceof Set) ||
89
+ !support.registry || typeof support.registry !== "object" || Array.isArray(support.registry) ||
90
+ Object.values(support.registry).some((entry) => !entry || typeof entry !== "object") ||
91
+ !support.schemas || typeof support.schemas !== "object" || Array.isArray(support.schemas))
92
+ return { ok: false, e: "invalid_type" };
87
93
  // Revision stays FIRST — a max+1 artifact reports its revision reason
88
94
  // before any other defect.
89
95
  const revision = revisionCheck(artifact, support);
@@ -205,7 +211,7 @@ function extensionsCheck(value, support) {
205
211
  // alone. Entries for namespaces the registry does not carry pass through as
206
212
  // given (the host-supplied registration surface).
207
213
  function resolveEntry(namespace, support) {
208
- const override = support.registry[namespace];
214
+ const override = Object.hasOwn(support.registry, namespace) ? support.registry[namespace] : undefined;
209
215
  if (override !== undefined) {
210
216
  const valid = (override.criticality === "critical" || override.criticality === "optional") &&
211
217
  ["reserved", "active", "deprecated", "retired"].includes(override.state);
@@ -258,7 +264,7 @@ function criticalJudgment(ns, regions, support) {
258
264
  function criticalBodyCheck(entry, body, support, namespace) {
259
265
  if (entry.schemaDigest === null)
260
266
  return { ok: false, e: "extension_schema_unavailable" };
261
- const schemaDocument = support.schemas[namespace];
267
+ const schemaDocument = Object.hasOwn(support.schemas, namespace) ? support.schemas[namespace] : undefined;
262
268
  if (schemaDocument === undefined)
263
269
  return { ok: false, e: "extension_schema_unavailable" };
264
270
  // The pin: JCS of the parsed document under the extension-schema domain.
@@ -3,7 +3,7 @@ type ScanResult = {
3
3
  ok: true;
4
4
  } | {
5
5
  ok: false;
6
- e: "forbidden_portable_value";
6
+ e: "forbidden_portable_value" | "invalid_type" | "ceiling:depth";
7
7
  };
8
8
  export declare function scan(value: Value): ScanResult;
9
9
  export declare function scanAuthored(value: Value): ScanResult;
@@ -1,7 +1,8 @@
1
1
  // The never-portable structural guard — the mirror of AgentBlueprintProtocol.Portability:
2
2
  // member-name and value-shape denylists over tagged values, four walks
3
3
  // (scan / scanAuthored / scanIdentifier / scanValue) with the position-scoped
4
- // identifier exemption. Deny reason everywhere: forbidden_portable_value.
4
+ // identifier exemption and bounded recursion. Malformed inputs deny by type.
5
+ import { MAXIMA } from "./bounds.js";
5
6
  // The 34-name member denylist, verbatim, stored NORMALIZED (snake +
6
7
  // case-folded, kebab folded in at compare time) so camel, kebab, and
7
8
  // SCREAMING forms of one denied name converge.
@@ -62,7 +63,6 @@ const UUID_SHAPE = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}
62
63
  const B64URL = /^[A-Za-z0-9_-]+$/;
63
64
  // RFC 3986 scheme + "://" + non-empty authority, or the scheme-less
64
65
  // network-path reference anchored at string start.
65
- const NETWORK_URI = /[A-Za-z][A-Za-z0-9+.-]*:\/\/[^/\s#?]+|^\/\/[^/\s#?]+/;
66
66
  const LOWER_IDENTIFIER = /^[a-z0-9_-]+$/;
67
67
  const UPPER_IDENTIFIER = /^[A-Z0-9_-]+$/;
68
68
  const forbidden = () => ({ ok: false, e: "forbidden_portable_value" });
@@ -86,25 +86,37 @@ function deniedName(name) {
86
86
  const normalized = name.toLowerCase().replaceAll("-", "_");
87
87
  return DENIED_NAMES.has(normalized);
88
88
  }
89
- function walk(value, names, exempt) {
89
+ function walk(value, names, exempt, depth = 0) {
90
+ if (value === null || typeof value !== "object")
91
+ return { ok: false, e: "invalid_type" };
92
+ if ((value.t === "obj" || value.t === "arr") && depth >= MAXIMA.depth)
93
+ return { ok: false, e: "ceiling:depth" };
90
94
  switch (value.t) {
91
95
  case "obj": {
96
+ if (!Array.isArray(value.v) || Array.from(value.v).some((pair) => !Array.isArray(pair) || pair.length !== 2 || typeof pair[0] !== "string"))
97
+ return { ok: false, e: "invalid_type" };
92
98
  if (names && value.v.some(([name]) => deniedName(name)))
93
99
  return forbidden();
94
100
  for (const [, member] of value.v) {
95
- if (!walk(member, names, exempt).ok)
96
- return forbidden();
101
+ const result = walk(member, names, exempt, depth + 1);
102
+ if (!result.ok)
103
+ return result;
97
104
  }
98
105
  return { ok: true };
99
106
  }
100
107
  case "arr": {
108
+ if (!Array.isArray(value.v))
109
+ return { ok: false, e: "invalid_type" };
101
110
  for (const item of value.v) {
102
- if (!walk(item, names, exempt).ok)
103
- return forbidden();
111
+ const result = walk(item, names, exempt, depth + 1);
112
+ if (!result.ok)
113
+ return result;
104
114
  }
105
115
  return { ok: true };
106
116
  }
107
117
  case "str":
118
+ if (typeof value.v !== "string")
119
+ return { ok: false, e: "invalid_type" };
108
120
  if (exempt && identifierStyle(value.v))
109
121
  return { ok: true };
110
122
  return forbiddenValue(value.v) ? forbidden() : { ok: true };
@@ -122,11 +134,36 @@ function uuidShaped(s) {
122
134
  function structuralSecret(s) {
123
135
  return (s.includes(PEM_MARKER) ||
124
136
  compactJws(s) ||
125
- NETWORK_URI.test(s) ||
137
+ networkUri(s) ||
126
138
  rawKeyMaterial(s) ||
127
139
  paddedStandardB64(s) ||
128
140
  colonHexFingerprint(s));
129
141
  }
142
+ // Delimiters partition the backward walks. An unanchored scheme can start
143
+ // at any letter in its run, so "1a://x" still has the suffix scheme "a".
144
+ function networkUri(s) {
145
+ if (s.startsWith("//") && authorityStart(s, 2))
146
+ return true;
147
+ let at = s.indexOf("://");
148
+ while (at !== -1) {
149
+ if (authorityStart(s, at + 3)) {
150
+ for (let i = at - 1; i >= 0; i--) {
151
+ const c = s.charCodeAt(i);
152
+ if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122))
153
+ return true;
154
+ if (!((c >= 48 && c <= 57) || c === 43 || c === 45 || c === 46))
155
+ break;
156
+ }
157
+ }
158
+ at = s.indexOf("://", at + 3);
159
+ }
160
+ return false;
161
+ }
162
+ // ASCII whitespace only: the reference scans bytes, so non-ASCII spaces
163
+ // (U+00A0, U+3000, ...) begin an authority like any other character.
164
+ function authorityStart(s, at) {
165
+ return at < s.length && /[^/\t\n\v\f\r #?]/.test(s[at]);
166
+ }
130
167
  // Pad-identified standard base64 (1-6 "=" at 32+ chars), or unpadded
131
168
  // standard-alphabet runs at the 43-char calibration.
132
169
  function paddedStandardB64(s) {
@@ -1,9 +1,4 @@
1
- // The closed, portable boolean predicate algebra — the mirror of
2
- // AgentBlueprintProtocol.Predicate's validate/2 (the shape walk the Blueprint
3
- // root hook consumes): closed operator world, per-operator operand members,
4
- // the 256-node ceiling, and the pinned per-node check order
5
- // (op presence → op value → unknown member → missing operand → operand
6
- // type/cardinality → path[0] → node ceiling, counted depth-first on entry).
1
+ import { isValue } from "./value.js";
7
2
  const NODE_CEILING = 256;
8
3
  const FOLD_OPS = ["and", "or"];
9
4
  const NOT_OPS = ["not"];
@@ -28,6 +23,8 @@ const OPERANDS = {
28
23
  absent: ["path"],
29
24
  };
30
25
  export function validate(predicate, portNames) {
26
+ if (!isValue(predicate) || !Array.isArray(portNames) || portNames.some((name) => typeof name !== "string"))
27
+ return { ok: false, e: "invalid_type" };
31
28
  const ports = new Set(portNames);
32
29
  const result = shape(predicate, ports, 0);
33
30
  return result.ok ? { ok: true } : { ok: false, e: result.e };
@@ -72,7 +69,7 @@ function opOf(members) {
72
69
  return { ok: true, v: found.v };
73
70
  }
74
71
  function closedMembers(members, op) {
75
- const operands = OPERANDS[op];
72
+ const operands = Object.hasOwn(OPERANDS, op) ? OPERANDS[op] : undefined;
76
73
  if (operands === undefined)
77
74
  return { ok: false, e: "predicate_op_unknown" };
78
75
  const allowed = new Set(["op", ...operands]);
@@ -1,19 +1,11 @@
1
- // The generic field-registry validate engine — the mirror of
2
- // AgentBlueprintProtocol.Registry: ONE table-driven walk parameterized by the
3
- // artifact layer's table. The engine knows tables, not domains. Failure
4
- // precedence is pinned: member well-formedness → unknown_member (document
5
- // order) → missing_required_field (table order) → invalid_type (table order)
6
- // → invalid_constraint (table order) → invalid_cardinality (table order) →
7
- // nested recursion (document order, child reasons propagate) → root hooks
8
- // (table order). `:integer` is TAG-STRICT (a float, zero-fraction included,
9
- // denies invalid_type).
1
+ import { isValue } from "./value.js";
10
2
  // The table-builder helper (the twin's field/2): name + kind, required by
11
3
  // default, keyword-style options.
12
4
  export function field(name, kind, opts = {}) {
13
5
  return { name, required: true, kind, ...opts };
14
6
  }
15
7
  export function validate(table, value) {
16
- if (value.t !== "obj")
8
+ if (!isValue(value) || !Array.isArray(table) || Array.from(table).some((spec) => !specShape(spec)) || value.t !== "obj")
17
9
  return { ok: false, e: "invalid_type" };
18
10
  const members = value.v;
19
11
  for (const [name] of members) {
@@ -74,6 +66,26 @@ export function validate(table, value) {
74
66
  }
75
67
  return { ok: true };
76
68
  }
69
+ function specShape(spec, depth = 0) {
70
+ if (!spec || typeof spec !== "object" || depth > 64)
71
+ return false;
72
+ if ((spec.check !== undefined && typeof spec.check !== "function") ||
73
+ (spec.rootHook !== undefined && typeof spec.rootHook !== "function"))
74
+ return false;
75
+ const kind = spec.kind;
76
+ if (typeof kind === "string")
77
+ return ["string", "integer", "float", "boolean", "number", "any", "custom"].includes(kind);
78
+ if (!kind || typeof kind !== "object")
79
+ return false;
80
+ if ("enum" in kind)
81
+ return kind.enum instanceof Set;
82
+ if ("array" in kind)
83
+ return specShape(kind.array, depth + 1);
84
+ if ("object" in kind)
85
+ return !!kind.object && Array.isArray(kind.object.members) &&
86
+ kind.object.members.every((member) => specShape(member, depth + 1));
87
+ return false;
88
+ }
77
89
  // ---- stages --------------------------------------------------------------------------
78
90
  function specConstraint(spec, value) {
79
91
  if (typeof spec.kind === "object" && "enum" in spec.kind) {
@@ -189,12 +201,17 @@ function wellFormed(value) {
189
201
  }
190
202
  // ---- helpers -------------------------------------------------------------------------
191
203
  export function keyfind(members, name) {
204
+ if (!Array.isArray(members) || Array.from(members).some((pair) => !Array.isArray(pair) || pair.length !== 2 || typeof pair[0] !== "string"))
205
+ return null;
192
206
  const found = members.find(([key]) => key === name);
193
207
  return found ? found[1] : null;
194
208
  }
195
209
  // Elixir `=:=` term equality over the tagged algebra: tags are strict
196
210
  // (int 5 and float 5.0 are distinct), object member ORDER is significant.
197
211
  export function termEqual(a, b) {
212
+ return isValue(a) && isValue(b) && termEqualAt(a, b);
213
+ }
214
+ function termEqualAt(a, b) {
198
215
  if (a.t !== b.t)
199
216
  return false;
200
217
  switch (a.t) {
@@ -208,13 +225,13 @@ export function termEqual(a, b) {
208
225
  case "arr":
209
226
  return (b.t === "arr" &&
210
227
  a.v.length === b.v.length &&
211
- a.v.every((x, i) => termEqual(x, b.v[i])));
228
+ a.v.every((x, i) => termEqualAt(x, b.v[i])));
212
229
  case "obj":
213
230
  return (b.t === "obj" &&
214
231
  a.v.length === b.v.length &&
215
232
  a.v.every((pair, i) => {
216
233
  const other = b.v[i];
217
- return pair[0] === other[0] && termEqual(pair[1], other[1]);
234
+ return pair[0] === other[0] && termEqualAt(pair[1], other[1]);
218
235
  }));
219
236
  }
220
237
  }
@@ -10,4 +10,12 @@ export interface Report {
10
10
  disagreed: number;
11
11
  }
12
12
  export declare function build(results: CaseResult[][]): Report;
13
+ export declare function build(results: unknown): Report | {
14
+ ok: false;
15
+ e: string;
16
+ };
13
17
  export declare function toBytes(corpusIdentity: string, results: CaseResult[][]): string;
18
+ export declare function toBytes(corpusIdentity: unknown, results: unknown): string | {
19
+ ok: false;
20
+ e: string;
21
+ };
@@ -4,7 +4,10 @@
4
4
  import { encode } from "./canonical.js";
5
5
  import { bool, int, obj, str } from "./value.js";
6
6
  const FORMAT = "agent-blueprint-protocol-conformance-report";
7
- export function build(results) {
7
+ export function build(input) {
8
+ const results = input;
9
+ if (!Array.isArray(results) || results.some((rows) => !Array.isArray(rows) || rows.some((row) => !row || typeof row.caseId !== "string" || typeof row.agree !== "boolean")))
10
+ return { ok: false, e: "invalid_type" };
8
11
  const all = results.flat();
9
12
  const total = all.length;
10
13
  const agreed = all.filter((r) => r.agree).length;
@@ -13,7 +16,11 @@ export function build(results) {
13
16
  return { agreement, exitStatus: agreement ? 0 : 1, total, agreed, disagreed };
14
17
  }
15
18
  export function toBytes(corpusIdentity, results) {
19
+ if (typeof corpusIdentity !== "string")
20
+ return { ok: false, e: "invalid_type" };
16
21
  const report = build(results);
22
+ if ("ok" in report)
23
+ return report;
17
24
  const encoded = encode(obj([
18
25
  ["format", str(FORMAT)],
19
26
  ["agreement", bool(report.agreement)],
@@ -24,6 +31,6 @@ export function toBytes(corpusIdentity, results) {
24
31
  ["corpus_digest", str(corpusIdentity)],
25
32
  ]));
26
33
  if (!encoded.ok)
27
- throw new Error("report must encode");
34
+ return encoded;
28
35
  return encoded.v;
29
36
  }
@@ -1,81 +1,5 @@
1
- // The corpus harness: loads ../priv/conformance from the filesystem into a
2
- // path→bytes map (recursive, dotfiles included), verifies it through
3
- // corpus.load, executes every case through runner.run, and prints per-case
4
- // results plus the agreement summary. Exit 0 iff 86/86 agree.
5
- import { readFileSync, readdirSync, statSync } from "node:fs";
6
- import { join } from "node:path";
7
- import * as corpus from "./corpus.js";
8
- import * as runner from "./runner.js";
9
- const CORPUS_ROOT = join(import.meta.dirname, "..", "..", "priv", "conformance");
10
- function loadCorpusFiles(root) {
11
- const map = new Map();
12
- const walk = (dir, prefix) => {
13
- for (const entry of readdirSync(dir)) {
14
- const absolute = join(dir, entry);
15
- const relative = prefix === "" ? entry : prefix + "/" + entry;
16
- if (statSync(absolute).isDirectory()) {
17
- walk(absolute, relative);
18
- continue;
19
- }
20
- map.set(relative, readFileSync(absolute));
21
- }
22
- };
23
- walk(root, "");
24
- return map;
25
- }
26
- const files = loadCorpusFiles(CORPUS_ROOT);
27
- const loaded = corpus.load(files);
28
- if (!loaded.ok) {
29
- process.stderr.write(`corpus load failed: ${loaded.e}\n`);
30
- process.exit(2);
31
- }
32
- const results = runner.run(loaded.v);
33
- let total = 0;
34
- let agreed = 0;
35
- const disagreements = [];
36
- for (const file of results) {
37
- for (const result of file) {
38
- total++;
39
- if (result.agree) {
40
- agreed++;
41
- process.stdout.write(`ok ${result.caseId}\n`);
42
- }
43
- else {
44
- // CaseResult[] carries no path (run() groups by file); explain ignores it.
45
- const detail = explain(result.caseId, file.path);
46
- disagreements.push({ id: result.caseId, detail });
47
- process.stdout.write(`DISAGREE ${result.caseId}\n`);
48
- }
49
- }
50
- }
51
- // Re-execute each disagreement to surface expected vs got.
52
- // loaded.ok was checked above (process.exit on failure) — the casts mirror it.
53
- function explain(caseId, _path) {
54
- const all = loaded.v.cases.flatMap((f) => f.cases);
55
- const caseObj = all.find((c) => c.id === caseId);
56
- if (caseObj === undefined)
57
- return "case not found";
58
- const expectedCode = corpus.memberString(caseObj.expected, "code");
59
- const executed = runner.execute(caseObj, loaded.v.data, loaded.v.raws);
60
- const got = executed.actual.ok
61
- ? "valid: " + JSON.stringify(executed.actual.v)
62
- : "invalid: " + executed.actual.e;
63
- const want = expectedCode !== null ? `invalid: ${expectedCode}` : "valid: " + JSON.stringify(projectExpectation(caseObj));
64
- return ` expected ${want}\n got ${got}`;
65
- }
66
- function projectExpectation(caseObj) {
67
- if (caseObj.expected.t !== "obj")
68
- return null;
69
- const out = {};
70
- for (const [key, value] of caseObj.expected.v) {
71
- out[key] = value.t === "str" ? value.v : value.t;
72
- }
73
- return out;
74
- }
75
- process.stdout.write(`\ntotal ${total} | agreed ${agreed} | disagreed ${total - agreed}\n`);
76
- for (const d of disagreements) {
77
- process.stdout.write(`${d.id}\n${d.detail}\n`);
78
- }
79
- if (agreed !== total || total === 0) {
80
- process.exit(1);
1
+ // Compatibility entry for the conformance CLI. Importing it performs no I/O.
2
+ import { pathToFileURL } from "node:url";
3
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
4
+ await import("./cli.js");
81
5
  }
@@ -6,6 +6,10 @@ export interface CaseResult {
6
6
  agree: boolean;
7
7
  }
8
8
  export declare function run(corpus: LoadedCorpus): CaseResult[][];
9
+ export declare function run(corpus: unknown): CaseResult[][] | {
10
+ ok: false;
11
+ e: string;
12
+ };
9
13
  export declare function execute(caseObj: CaseObj, data: Map<string, Value>, raws: Map<string, Buffer>): {
10
14
  actual: SurfaceResult;
11
15
  agree: boolean;
@@ -1,3 +1,4 @@
1
+ import { isValue } from "./value.js";
1
2
  // The case executor — the mirror of AgentBlueprintProtocol.Conformance.Runner:
2
3
  // dispatches each corpus case against the verifier's own surface twins and
3
4
  // compares to the case's code-level, shape-agnostic expectation (invalid →
@@ -18,13 +19,19 @@ import * as federation from "./federation.js";
18
19
  import * as portability from "./portability.js";
19
20
  import * as schema from "./schema.js";
20
21
  import * as signature from "./signature.js";
21
- export function run(corpus) {
22
+ export function run(input) {
23
+ const corpus = input;
24
+ if (!corpus || !Array.isArray(corpus.cases) || !(corpus.data instanceof Map) || !(corpus.raws instanceof Map) ||
25
+ corpus.cases.some((file) => !file || !Array.isArray(file.cases) || file.cases.some((row) => !row || typeof row.id !== "string" || !isValue(row.input) || !isValue(row.expected))))
26
+ return { ok: false, e: "invalid_type" };
22
27
  return corpus.cases.map((file) => file.cases.map((caseObj) => ({
23
28
  caseId: caseObj.id,
24
29
  agree: execute(caseObj, corpus.data, corpus.raws).agree,
25
30
  })));
26
31
  }
27
32
  export function execute(caseObj, data, raws) {
33
+ if (!caseObj || typeof caseObj !== "object" || !isValue(caseObj.input) || !isValue(caseObj.expected) || !(data instanceof Map) || !(raws instanceof Map))
34
+ return { actual: { ok: false, e: "invalid_type" }, agree: false };
28
35
  const input = caseObj.input;
29
36
  const strict = caseObj.expected.t === "obj" ? member(caseObj.expected, "strict_signature") : null;
30
37
  const expected = caseObj.expected.t === "obj"
@@ -74,6 +81,8 @@ function agrees(expected, actual) {
74
81
  if (!actual.ok)
75
82
  return false;
76
83
  return projections.every(([key, want]) => {
84
+ if (!Object.hasOwn(actual.v, key))
85
+ return false;
77
86
  const got = actual.v[key];
78
87
  if (got === undefined)
79
88
  return false;
@@ -117,21 +126,11 @@ function deepEqual(want, got) {
117
126
  const gotRecord = got;
118
127
  if (Object.keys(gotRecord).length !== want.v.length)
119
128
  return false;
120
- return want.v.every(([k, w]) => k in gotRecord && deepEqual(w, gotRecord[k]));
129
+ return want.v.every(([k, w]) => Object.hasOwn(gotRecord, k) && deepEqual(w, gotRecord[k]));
121
130
  }
122
131
  return false;
123
132
  }
124
133
  // --- dispatch ----------------------------------------------------------------------
125
- const BOUNDS_KEYS = {
126
- bytes: "bytes",
127
- depth: "depth",
128
- members: "members",
129
- items: "items",
130
- nodes: "nodes",
131
- string: "string",
132
- key: "key",
133
- number_lexeme: "number_lexeme",
134
- };
135
134
  const DIGEST_DOMAINS = [
136
135
  "blueprint_content",
137
136
  "deployment_content",
@@ -457,8 +456,7 @@ function boundsOverrides(input) {
457
456
  const out = Object.create(null);
458
457
  for (const [key, value] of overrides.v) {
459
458
  // Unknown keys pass through so coerce() denies them (unknown_bound).
460
- const mapped = BOUNDS_KEYS[key] ?? key;
461
- out[mapped] = value.t === "int" || value.t === "float" ? value.v : plainOf(value);
459
+ out[key] = value.t === "int" || value.t === "float" ? value.v : plainOf(value);
462
460
  }
463
461
  return { ok: true, v: out };
464
462
  }
@@ -552,7 +550,7 @@ function buildSupport(input) {
552
550
  }
553
551
  }
554
552
  const schemasRaw = member(source, "schemas");
555
- const schemas = {};
553
+ const schemas = Object.create(null);
556
554
  if (schemasRaw !== null && schemasRaw.t === "obj") {
557
555
  for (const [ns, schemaValue] of schemasRaw.v)
558
556
  schemas[ns] = schemaValue;