@agent-blueprint-protocol/verifier 0.8.3 → 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 (43) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +5 -5
  3. package/dist/corpus/cases/blueprint-decode.json +1 -1
  4. package/dist/corpus/cases/deployment-decode.json +1 -1
  5. package/dist/corpus/cases/schema-validate_instance.json +1 -1
  6. package/dist/corpus/index.json +1 -1
  7. package/dist/kit/cli.mjs +1 -4
  8. package/dist/release-metadata.json +1 -1
  9. package/dist/verifier/b64url.d.ts +6 -2
  10. package/dist/verifier/b64url.js +6 -0
  11. package/dist/verifier/blueprint.d.ts +12 -3
  12. package/dist/verifier/blueprint.js +21 -7
  13. package/dist/verifier/bounds.d.ts +1 -1
  14. package/dist/verifier/bounds.js +2 -2
  15. package/dist/verifier/bounds_algebra.js +4 -1
  16. package/dist/verifier/canonical.d.ts +1 -1
  17. package/dist/verifier/canonical.js +41 -8
  18. package/dist/verifier/cli.js +111 -42
  19. package/dist/verifier/compatibility.js +5 -7
  20. package/dist/verifier/corpus.js +5 -1
  21. package/dist/verifier/decode.js +9 -3
  22. package/dist/verifier/deployment.d.ts +12 -3
  23. package/dist/verifier/deployment.js +31 -8
  24. package/dist/verifier/digest.d.ts +12 -0
  25. package/dist/verifier/digest.js +16 -2
  26. package/dist/verifier/extension.js +4 -4
  27. package/dist/verifier/federation.js +16 -72
  28. package/dist/verifier/negotiation.js +6 -0
  29. package/dist/verifier/portability.d.ts +1 -1
  30. package/dist/verifier/portability.js +19 -6
  31. package/dist/verifier/predicate.js +3 -6
  32. package/dist/verifier/registry_engine.js +29 -12
  33. package/dist/verifier/report.d.ts +8 -0
  34. package/dist/verifier/report.js +9 -2
  35. package/dist/verifier/run_corpus.js +4 -80
  36. package/dist/verifier/runner.d.ts +4 -0
  37. package/dist/verifier/runner.js +8 -1
  38. package/dist/verifier/schema.js +14 -55
  39. package/dist/verifier/signature.d.ts +2 -2
  40. package/dist/verifier/signature.js +10 -4
  41. package/dist/verifier/value.d.ts +9 -2
  42. package/dist/verifier/value.js +81 -11
  43. package/package.json +1 -1
@@ -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";
@@ -265,7 +260,14 @@ export function decode(bytes, bounds) {
265
260
  return { ok: true, v: { value } };
266
261
  }
267
262
  export function fromValue(value, opts = {}) {
263
+ if (opts === null || typeof opts !== "object" || Array.isArray(opts))
264
+ return { ok: false, e: "invalid_type" };
268
265
  const validated = opts.authoredExtensions ?? [];
266
+ if (!Array.isArray(validated) || validated.some((ns) => typeof ns !== "string"))
267
+ return { ok: false, e: "invalid_type" };
268
+ const shaped = canonical.encode(value);
269
+ if (!shaped.ok)
270
+ return shaped;
269
271
  if (validated.length > 0) {
270
272
  if (value.t !== "obj")
271
273
  return { ok: false, e: "invalid_type" };
@@ -282,24 +284,30 @@ export function fromValue(value, opts = {}) {
282
284
  return { ok: true, v: { value } };
283
285
  }
284
286
  export function toValue(deployment) {
285
- return deployment.value;
287
+ return deployment && isValue(deployment.value) ? deployment.value : { ok: false, e: "invalid_type" };
286
288
  }
287
289
  // ---- digest surface --------------------------------------------------------------------
288
290
  export function digestInput(deployment) {
291
+ if (!deployment || !isValue(deployment.value))
292
+ return { ok: false, e: "invalid_type" };
289
293
  if (deployment.value.t !== "obj")
290
294
  return deployment.value;
291
295
  return { t: "obj", v: deployment.value.v.filter(([name]) => !EVIDENCE_MEMBERS.includes(name)) };
292
296
  }
293
297
  export function canonicalBytes(deployment) {
298
+ if (!deployment || typeof deployment !== "object")
299
+ return { ok: false, e: "invalid_type" };
294
300
  return canonical.encode(deployment.value);
295
301
  }
296
302
  export function contentDigest(deployment) {
297
303
  const jcs = canonical.encode(digestInput(deployment));
298
304
  if (!jcs.ok)
299
- throw new Error("deployment digest input must encode");
305
+ return jcs;
300
306
  return digest.toTagged(digest.hash("deployment_content", Buffer.from(jcs.v, "utf8")));
301
307
  }
302
308
  export function verifyContentDigest(deployment) {
309
+ if (!deployment || !isValue(deployment.value))
310
+ return { ok: false, e: "invalid_type" };
303
311
  const members = deployment.value.t === "obj" ? deployment.value.v : [];
304
312
  const declared = keyfind(members, "deployment_digest");
305
313
  if (declared === null || declared.t !== "str")
@@ -313,6 +321,8 @@ export function verifyContentDigest(deployment) {
313
321
  // a non-array member, a non-object entry, a non-string operand, or an
314
322
  // unparsable descriptor digest is a malformed deployment, never empty.
315
323
  function boundToolBindings(deployment) {
324
+ if (!deployment || !isValue(deployment.value))
325
+ return { ok: false, e: "invalid_type" };
316
326
  if (deployment.value.t !== "obj")
317
327
  return { ok: false, e: "invalid_type" };
318
328
  const members = deployment.value.v;
@@ -349,6 +359,8 @@ function boundRelease(deployment) {
349
359
  const bindings = boundToolBindings(deployment);
350
360
  if (!bindings.ok)
351
361
  return bindings;
362
+ if (!deployment || !isValue(deployment.value))
363
+ return { ok: false, e: "invalid_type" };
352
364
  if (deployment.value.t !== "obj")
353
365
  return { ok: false, e: "invalid_type" };
354
366
  const release = keyfind(deployment.value.v, "blueprint_release");
@@ -372,6 +384,9 @@ function boundRelease(deployment) {
372
384
  // tool-binding completeness → mutation/recovery → attestation staleness →
373
385
  // observed rug-pull. Stages 5-6 are observation-gated.
374
386
  export function verifyBinding(deployment, bound, obs) {
387
+ if (!deployment || !isValue(deployment.value) || !bound || !isValue(bound.value) || !obs || typeof obs !== "object" || !obs.observed || typeof obs.observed !== "object" ||
388
+ (Object.getPrototypeOf(obs.observed) !== Object.prototype && Object.getPrototypeOf(obs.observed) !== null))
389
+ return { ok: false, e: "invalid_type" };
375
390
  const bindings = boundToolBindings(deployment);
376
391
  if (!bindings.ok)
377
392
  return bindings;
@@ -478,6 +493,8 @@ function stageRugPull(bindings, obs) {
478
493
  for (const entry of bindings) {
479
494
  const operation = memberString(entry, "logical_operation");
480
495
  const tagged = memberString(entry, "descriptor_digest");
496
+ if (typeof tagged !== "string")
497
+ return { ok: false, e: "invalid_type" };
481
498
  const parsed = digest.fromTagged(tagged);
482
499
  if (parsed.ok)
483
500
  attested.set(operation, parsed.v);
@@ -496,6 +513,8 @@ function stageRugPull(bindings, obs) {
496
513
  return { ok: true };
497
514
  }
498
515
  function recoveryMode(deployment) {
516
+ if (!deployment || !isValue(deployment.value))
517
+ return { ok: false, e: "invalid_type" };
499
518
  if (deployment.value.t !== "obj")
500
519
  return { ok: false, e: "invalid_type" };
501
520
  const owner = keyfind(deployment.value.v, "effect_owner");
@@ -514,6 +533,8 @@ function recoveryMode(deployment) {
514
533
  function blueprintContentDigest(bound) {
515
534
  try {
516
535
  const tagged = blueprint.contentDigest(bound);
536
+ if (typeof tagged !== "string")
537
+ return null;
517
538
  const parsed = digest.fromTagged(tagged);
518
539
  return parsed.ok ? parsed.v : null;
519
540
  }
@@ -814,6 +835,8 @@ function normalizeBounds(bounds) {
814
835
  // (DateTime.from_iso8601 parity, restricted to the calendar-valid Z form the
815
836
  // tables already enforce).
816
837
  export function parseTimestamp(stamped) {
838
+ if (typeof stamped !== "string")
839
+ return null;
817
840
  const matched = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(Z|[+-]\d{2}:\d{2})$/.exec(stamped);
818
841
  if (matched === null)
819
842
  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;
@@ -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;
@@ -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) ----------------------------------
@@ -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);
@@ -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.
@@ -85,25 +86,37 @@ function deniedName(name) {
85
86
  const normalized = name.toLowerCase().replaceAll("-", "_");
86
87
  return DENIED_NAMES.has(normalized);
87
88
  }
88
- 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" };
89
94
  switch (value.t) {
90
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" };
91
98
  if (names && value.v.some(([name]) => deniedName(name)))
92
99
  return forbidden();
93
100
  for (const [, member] of value.v) {
94
- if (!walk(member, names, exempt).ok)
95
- return forbidden();
101
+ const result = walk(member, names, exempt, depth + 1);
102
+ if (!result.ok)
103
+ return result;
96
104
  }
97
105
  return { ok: true };
98
106
  }
99
107
  case "arr": {
108
+ if (!Array.isArray(value.v))
109
+ return { ok: false, e: "invalid_type" };
100
110
  for (const item of value.v) {
101
- if (!walk(item, names, exempt).ok)
102
- return forbidden();
111
+ const result = walk(item, names, exempt, depth + 1);
112
+ if (!result.ok)
113
+ return result;
103
114
  }
104
115
  return { ok: true };
105
116
  }
106
117
  case "str":
118
+ if (typeof value.v !== "string")
119
+ return { ok: false, e: "invalid_type" };
107
120
  if (exempt && identifierStyle(value.v))
108
121
  return { ok: true };
109
122
  return forbiddenValue(value.v) ? forbidden() : { ok: true };
@@ -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 };
@@ -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
  }