@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
@@ -13,7 +13,7 @@
13
13
  // The decode ↔ canonical import cycle (verify needs decode; decode's window
14
14
  // rule needs the number oracle) is a node-ESM circular import over hoisted
15
15
  // function declarations — resolved at call time, never at module init.
16
- import { maximum } from "./bounds.js";
16
+ import { coerce, maximum } from "./bounds.js";
17
17
  import { decode } from "./decode.js";
18
18
  import { err, ok, IJSON_MAX } from "./value.js";
19
19
  const SHORT_ESCAPES = {
@@ -24,10 +24,12 @@ const SHORT_ESCAPES = {
24
24
  0x0d: "r",
25
25
  };
26
26
  export function encode(value, bounds) {
27
- // The profile is read field-wise (bytes) whatever the caller passed.
28
- const profile = (bounds ?? maximum());
27
+ const normalized = coerce(bounds === undefined ? maximum() : bounds);
28
+ if (!normalized.ok)
29
+ return normalized;
30
+ const profile = normalized.v;
29
31
  const parts = [];
30
- const walked = walk(value, parts);
32
+ const walked = walk(value, parts, profile, 0, { nodes: 0 });
31
33
  if (!walked.ok)
32
34
  return walked;
33
35
  const out = parts.join("");
@@ -58,12 +60,27 @@ export function number(f) {
58
60
  return JSON.stringify(f);
59
61
  }
60
62
  // ---- encode walk ----------------------------------------------------------------
61
- function walk(value, out) {
63
+ function walk(value, out, bounds, depth, counter) {
64
+ if (value === null || typeof value !== "object")
65
+ return err("invalid_type");
66
+ if (++counter.nodes > bounds.nodes)
67
+ return err("ceiling:nodes");
68
+ if (value.t === "arr" || value.t === "obj") {
69
+ if (!Array.isArray(value.v))
70
+ return err("invalid_type");
71
+ if (depth >= bounds.depth)
72
+ return err("ceiling:depth");
73
+ const field = value.t === "arr" ? "items" : "members";
74
+ if (value.v.length > bounds[field])
75
+ return err(`ceiling:${field}`);
76
+ }
62
77
  switch (value.t) {
63
78
  case "null":
64
79
  out.push("null");
65
80
  return ok(undefined);
66
81
  case "bool":
82
+ if (typeof value.v !== "boolean")
83
+ return err("invalid_type");
67
84
  out.push(value.v ? "true" : "false");
68
85
  return ok(undefined);
69
86
  case "int":
@@ -73,9 +90,19 @@ function walk(value, out) {
73
90
  out.push(String(value.v));
74
91
  return ok(undefined);
75
92
  case "float":
93
+ if (typeof value.v !== "number")
94
+ return err("invalid_type");
95
+ if (!Number.isFinite(value.v))
96
+ return err("invalid_number");
76
97
  out.push(number(value.v));
77
98
  return ok(undefined);
78
99
  case "str": {
100
+ if (typeof value.v !== "string")
101
+ return err("invalid_type");
102
+ if (Buffer.byteLength(value.v) > bounds.bytes)
103
+ return err("ceiling:bytes");
104
+ if (Buffer.byteLength(value.v) > bounds.string)
105
+ return err("ceiling:string");
79
106
  const escaped = escapeString(value.v);
80
107
  if (!escaped.ok)
81
108
  return escaped;
@@ -87,7 +114,7 @@ function walk(value, out) {
87
114
  for (let i = 0; i < value.v.length; i++) {
88
115
  if (i > 0)
89
116
  out.push(",");
90
- const element = walk(value.v[i], out);
117
+ const element = walk(value.v[i], out, bounds, depth + 1, counter);
91
118
  if (!element.ok)
92
119
  return element;
93
120
  }
@@ -95,7 +122,12 @@ function walk(value, out) {
95
122
  return ok(undefined);
96
123
  }
97
124
  case "obj": {
98
- for (const [name] of value.v) {
125
+ for (const pair of value.v) {
126
+ if (!Array.isArray(pair) || pair.length !== 2 || typeof pair[0] !== "string")
127
+ return err("invalid_type");
128
+ const name = pair[0];
129
+ if (Buffer.byteLength(name) > bounds.key)
130
+ return err("ceiling:key");
99
131
  if (!validString(name))
100
132
  return err("invalid_encoding");
101
133
  }
@@ -112,13 +144,14 @@ function walk(value, out) {
112
144
  if (!key.ok)
113
145
  return key;
114
146
  out.push('"' + key.v + '":');
115
- const member = walk(sorted[i][1], out);
147
+ const member = walk(sorted[i][1], out, bounds, depth + 1, counter);
116
148
  if (!member.ok)
117
149
  return member;
118
150
  }
119
151
  out.push("}");
120
152
  return ok(undefined);
121
153
  }
154
+ default: return err("invalid_type");
122
155
  }
123
156
  }
124
157
  function escapeString(s) {
@@ -6,8 +6,11 @@
6
6
  // IO.binwrite parity). Exit 3 marks an internal invariant (outside the
7
7
  // 0/1/2 contract, exactly as an escript crash is — loud, never laundered
8
8
  // into "disagreement").
9
- import { readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
10
- import { join } from "node:path";
9
+ import { resultsDocument, canonical } from "./results.js";
10
+ import { serve } from "./execution.js";
11
+ import { runHarness } from "./harness.js";
12
+ import { readdirSync, readFileSync, lstatSync, openSync, closeSync, readSync, fstatSync } from "node:fs";
13
+ import { join, relative, sep } from "node:path";
11
14
  import { load, loadPriorCensus } from "./corpus.js";
12
15
  import { encode } from "./canonical.js";
13
16
  import { toBytes } from "./report.js";
@@ -16,9 +19,41 @@ import { decode as decodeBlueprint } from "./blueprint.js";
16
19
  import { decode as decodeDeployment } from "./deployment.js";
17
20
  import { decode as decodeEnvelope } from "./federation.js";
18
21
  import { obj, str } from "./value.js";
19
- const USAGE = "usage: node verifier/cli.ts --corpus <dir> | --prior-corpus <dir> | --artifact <file>";
22
+ const USAGE = `usage: agent-blueprint-protocol [--corpus <dir> | --prior-corpus <dir> | --artifact <file> | --results --corpus <dir> | --serve --corpus <dir> | conformance run <options> -- <command...> | --help | --version]
23
+ No arguments: verify the installed release's embedded corpus.
24
+ --corpus <dir>: verify a corpus and report agreement.
25
+ --prior-corpus <dir>: replay a released corpus under current verification.
26
+ --artifact <file>: verify a Blueprint, Deployment Manifest, or Federation TaskEnvelope.
27
+ --help: print this help. --version: print the package version.
28
+ Exit codes: 0 agreement or valid artifact (also help/version); 1 disagreement or invalid artifact;
29
+ 2 usage, unreadable input, or corpus integrity failure; 3 internal error.`;
20
30
  const BYTE_CAP = 5_000_000;
21
- function main(argv) {
31
+ function releaseMetadata() {
32
+ for (const path of ["../release-metadata.json", "../priv/release-metadata.json", "./release-metadata.json"]) {
33
+ try {
34
+ return JSON.parse(readFileSync(new URL(path, import.meta.url), "utf8"));
35
+ }
36
+ catch (error) {
37
+ if (error.code !== "ENOENT")
38
+ throw error;
39
+ }
40
+ }
41
+ throw new Error("release metadata missing");
42
+ }
43
+ async function main(argv) {
44
+ if (argv[0] === "conformance" && argv[1] === "run")
45
+ return runHarness(argv.slice(2), readCorpus, releaseMetadata());
46
+ const mode = argv[0] === "--results" ? "results" : argv[0] === "--serve" ? "serve" : "report";
47
+ if (mode !== "report")
48
+ argv = argv.slice(1);
49
+ if (argv.length === 1 && argv[0] === "--help") {
50
+ process.stdout.write(USAGE + "\n");
51
+ return 0;
52
+ }
53
+ if (argv.length === 1 && argv[0] === "--version") {
54
+ process.stdout.write(releaseMetadata().package_version + "\n");
55
+ return 0;
56
+ }
22
57
  if (argv.length === 2 && argv[0] === "--artifact" && argv[1] !== "" && typeof argv[1] === "string") {
23
58
  return verifyArtifact(argv[1]);
24
59
  }
@@ -38,7 +73,7 @@ function main(argv) {
38
73
  map = readCorpus(dir);
39
74
  }
40
75
  catch {
41
- process.stderr.write("corpus unreadable: a file is missing, unreadable, or over the byte ceiling\n");
76
+ process.stderr.write("corpus unreadable: missing, unreadable, not regular, or over the file or byte ceiling\n");
42
77
  return 2;
43
78
  }
44
79
  const corpus = prior ? loadPriorCensus(map) : load(map);
@@ -48,10 +83,14 @@ function main(argv) {
48
83
  process.stderr.write("corpus integrity failure: :" + corpus.e + "\n");
49
84
  return 2;
50
85
  }
86
+ const certified = corpus.v.identity === releaseMetadata().corpus_digest ? "matches" : "does not match";
87
+ process.stderr.write(`corpus digest ${certified} the release-certified corpus\n`);
88
+ if (mode === "serve")
89
+ return serve(corpus.v);
51
90
  const results = run(corpus.v);
52
91
  const bytes = toBytes(corpus.v.identity, results);
53
92
  // exitCode (not process.exit) so piped stdout drains before exit.
54
- process.stdout.write(bytes);
93
+ process.stdout.write(mode === "results" ? canonical(resultsDocument(corpus.v)) : bytes);
55
94
  const agreed = results.flat().filter((r) => r.agree).length;
56
95
  return agreed === results.flat().length && agreed > 0 ? 0 : 1;
57
96
  }
@@ -66,12 +105,12 @@ function main(argv) {
66
105
  function verifyArtifact(path) {
67
106
  let bytes;
68
107
  try {
69
- const info = statSync(path);
108
+ const info = lstatSync(path);
70
109
  if (!info.isFile())
71
110
  throw new Error("not a regular file");
72
111
  if (info.size > BYTE_CAP)
73
112
  throw new Error("over byte ceiling");
74
- bytes = readFileSync(path);
113
+ bytes = readRegular(path, BYTE_CAP);
75
114
  }
76
115
  catch {
77
116
  process.stderr.write("artifact unreadable: missing, not a regular file, or over the byte ceiling\n");
@@ -97,57 +136,70 @@ function verifyArtifact(path) {
97
136
  process.stdout.write(encoded.v);
98
137
  return kind === null ? 1 : 0;
99
138
  }
100
- // Reads EVERY file under the corpus directory — dotfiles included — so the
101
- // loader's file-set equality sees exactly what the directory carries.
102
- // Per-file size cap at the Bounds byte ceiling; a hostile corpus directory
103
- // cannot exhaust memory or crash past the exit-code contract. Directory
104
- // symlinks are followed (Path.wildcard parity).
139
+ // At most 1,000 entries and 5,000,000 bytes across the entire tree.
140
+ // Symlinks and special files deny before reading; reads are bounded even if a file grows.
141
+ function readRegular(path, cap) {
142
+ const fd = openSync(path, "r");
143
+ try {
144
+ const info = fstatSync(fd);
145
+ if (!info.isFile() || info.size > cap)
146
+ throw new Error("unreadable");
147
+ const chunks = [];
148
+ let size = 0;
149
+ for (;;) {
150
+ const chunk = Buffer.alloc(Math.min(64 * 1024, cap - size + 1));
151
+ const count = readSync(fd, chunk);
152
+ if (count === 0)
153
+ return Buffer.concat(chunks, size);
154
+ size += count;
155
+ if (size > cap)
156
+ throw new Error("over byte ceiling");
157
+ chunks.push(chunk.subarray(0, count));
158
+ }
159
+ }
160
+ finally {
161
+ closeSync(fd);
162
+ }
163
+ }
105
164
  function readCorpus(dir) {
106
165
  const map = new Map();
107
- const visited = new Set();
166
+ let count = 0;
167
+ let total = 0;
108
168
  const walk = (current) => {
109
- // Cycle bound: directory symlinks repeat their realpath; a repeat is
110
- // skipped so the walk terminates inside the corpus-error contract.
111
- const real = realpathSync(current);
112
- if (visited.has(real))
113
- return;
114
- visited.add(real);
115
169
  for (const entry of readdirSync(current, { withFileTypes: true })) {
170
+ if (entry.name === ".DS_Store" || entry.name.startsWith("._"))
171
+ continue;
172
+ if (++count > 1_000)
173
+ throw new Error("over file ceiling");
116
174
  const path = join(current, entry.name);
117
- if (entry.isDirectory() || (entry.isSymbolicLink() && statSync(path).isDirectory())) {
175
+ const info = lstatSync(path);
176
+ if (info.isDirectory())
118
177
  walk(path);
178
+ else if (info.isFile()) {
179
+ if (info.size > BYTE_CAP - total)
180
+ throw new Error("over byte ceiling");
181
+ const bytes = readRegular(path, BYTE_CAP - total);
182
+ total += bytes.length;
183
+ map.set(relative(dir, path).split(sep).join("/"), bytes);
119
184
  }
120
- else {
121
- const info = statSync(path);
122
- // Regular files only: a FIFO/socket/device planted in the corpus
123
- // directory would block readFileSync past the exit contract — skip
124
- // it and let the loader's file-set equality deny (loud, not a hang).
125
- if (info.isFile()) {
126
- if (info.size > BYTE_CAP)
127
- throw new Error("over byte ceiling");
128
- map.set(path.slice(dir.length + 1), readFileSync(path));
129
- }
130
- }
185
+ else
186
+ throw new Error("not a regular file");
131
187
  }
132
188
  };
133
- // A missing (or non-directory) corpus root yields an EMPTY map — the
134
- // loader then denies corpus_index_invalid, exactly as the escript's
135
- // empty-wildcard path does (integrity failure, not unreadable).
136
- if (!existsDirectory(dir))
137
- return map;
138
- walk(dir);
139
- return map;
140
- }
141
- function existsDirectory(dir) {
142
189
  try {
143
- return statSync(dir).isDirectory();
190
+ if (!lstatSync(dir).isDirectory())
191
+ throw new Error("not a directory");
144
192
  }
145
- catch {
146
- return false;
193
+ catch (error) {
194
+ if (error.code === "ENOENT")
195
+ return map;
196
+ throw error;
147
197
  }
198
+ walk(dir);
199
+ return map;
148
200
  }
149
201
  try {
150
- process.exitCode = main(process.argv.slice(2));
202
+ process.exitCode = await main(process.argv.slice(2));
151
203
  }
152
204
  catch (error) {
153
205
  process.stderr.write("verifier internal error: " + error.message + "\n");
@@ -1,15 +1,11 @@
1
- // The compatibility surface — the mirror of AgentBlueprintProtocol.Compatibility:
2
- // identity-exact or error. A manifest identity (one build_identities entry)
3
- // is matched only by an observed identity carrying the EXACT
4
- // (kind, name, version, digest) tuple; ranges deny
5
- // compatibility_identity_inexact on BOTH sides; a manifest identity with no
6
- // exact observed counterpart denies compatibility_entry_missing; duplicate
7
- // candidates deny compatibility_duplicate_entry.
1
+ import { isValue } from "./value.js";
8
2
  import * as digest from "./digest.js";
9
3
  import { keyfind } from "./registry_engine.js";
10
4
  const IDENTITY_KEYS = ["kind", "name", "version", "digest"];
11
5
  const EXACT_CHARSET = /^[A-Za-z0-9.+-]+$/;
12
6
  export function verify(deployment, observed) {
7
+ if (!deployment || !isValue(deployment.value) || !observed || !Array.isArray(observed.identities))
8
+ return { ok: false, e: "invalid_type" };
13
9
  const manifest = manifestIdentities(deployment);
14
10
  if (!manifest.ok)
15
11
  return manifest;
@@ -21,6 +17,8 @@ export function verify(deployment, observed) {
21
17
  // The exactness predicate (public on the twin): total over junk input — any
22
18
  // non-conforming shape answers false.
23
19
  export function exact(identity) {
20
+ if (!identity || typeof identity !== "object")
21
+ return false;
24
22
  const version = identity.version;
25
23
  if (typeof version !== "string")
26
24
  return false;
@@ -1,5 +1,5 @@
1
1
  import type { Value } from "./value.ts";
2
- export declare const SURFACES: readonly ["json.decode", "canonicalization.encode", "base64url.decode", "digest.tagged", "signature.verify", "schema.validate_instance", "blueprint.decode", "deployment.decode", "negotiation.negotiate", "extension.resolve", "bounds.new", "bounds_algebra.intersect", "portability.scan", "compatibility.verify", "federation.decode", "federation.verify_commitment"];
2
+ export declare const SURFACES: readonly ["reconcile", "predicate", "json.decode", "canonicalization.encode", "base64url.decode", "digest.tagged", "signature.verify", "schema.validate_instance", "blueprint.decode", "deployment.decode", "negotiation.negotiate", "extension.resolve", "bounds.new", "bounds_algebra.intersect", "portability.scan", "compatibility.verify", "federation.decode", "federation.verify_commitment"];
3
3
  export declare const CLASSES: readonly ["valid", "boundary_near", "exact_bound", "maximum_plus_one", "invalid_encoding", "invalid_duplicate", "invalid_type", "invalid_constraint", "invalid_cardinality", "unknown_member", "tamper_meaningful_byte", "digest_mismatch", "signature_invalid", "revision_above_max", "revision_below_min", "required_field_unsupported", "required_field_not_covered", "extension_unknown_critical", "extension_unknown_optional_roundtrip", "extension_criticality_conflict", "extension_schema_unavailable", "extension_deprecated_retained", "bound_widening_operational", "bound_widening_protected", "forbidden_portable_value", "compatibility_range_rejected", "binding_stale", "federation_state_unmappable", "federation_terminal_conflict", "audience_mismatch", "terminal_equivocation"];
4
4
  export interface LoadedCorpus {
5
5
  index: Value;
@@ -25,6 +25,8 @@ import { registryDigest } from "./registry.js";
25
25
  const INDEX_FORMAT = "agent-blueprint-protocol-conformance-corpus-index";
26
26
  const CASE_FILE_FORMAT = "agent-blueprint-protocol-conformance-cases";
27
27
  export const SURFACES = [
28
+ "reconcile",
29
+ "predicate",
28
30
  "json.decode",
29
31
  "canonicalization.encode",
30
32
  "base64url.decode",
@@ -75,9 +77,11 @@ export const CLASSES = [
75
77
  "audience_mismatch",
76
78
  "terminal_equivocation",
77
79
  ];
78
- // The pinned 16×29 floor: per surface, required classes + the falsifiable
80
+ // The pinned 18×31 floor: per surface, required classes + the falsifiable
79
81
  // n_a reason covering its complement.
80
82
  const FLOOR = {
83
+ reconcile: { required: ["valid", "invalid_type", "digest_mismatch", "revision_above_max", "unknown_member", "forbidden_portable_value", "signature_invalid", "binding_stale", "bound_widening_protected"], n_a: "byte codecs, schema and federation checks have their own surfaces" },
84
+ predicate: { required: ["valid", "invalid_type", "invalid_constraint", "invalid_cardinality", "maximum_plus_one", "exact_bound"], n_a: "artifact, signature, bounds and federation checks do not reach predicates" },
81
85
  "json.decode": {
82
86
  required: [
83
87
  "valid",
@@ -235,6 +239,8 @@ export function loadPriorCensus(map) {
235
239
  return loadWithMode(map, true);
236
240
  }
237
241
  function loadWithMode(map, priorCensus) {
242
+ if (!(map instanceof Map) || [...map].some(([key, bytes]) => typeof key !== "string" || !Buffer.isBuffer(bytes)))
243
+ return indexInvalid();
238
244
  const indexBytes = map.get("index.json");
239
245
  if (indexBytes === undefined)
240
246
  return indexInvalid();
@@ -709,7 +715,9 @@ function verifyRawBindings(cases, raws) {
709
715
  }
710
716
  // ---- tagged-object helpers ----------------------------------------------------------------------
711
717
  export function member(container, key) {
712
- if (container.t !== "obj")
718
+ if (!container || container.t !== "obj" || !Array.isArray(container.v))
719
+ return null;
720
+ if (Array.from(container.v).some((pair) => !Array.isArray(pair) || pair.length !== 2 || typeof pair[0] !== "string" || !pair[1] || typeof pair[1] !== "object"))
713
721
  return null;
714
722
  const found = container.v.find(([k]) => k === key);
715
723
  return found ? found[1] : null;
@@ -11,7 +11,7 @@
11
11
  // twin's classify_parse_error): invalid_encoding when any byte is bad, else
12
12
  // invalid_syntax. Ceiling/code failures carry their own reason verbatim —
13
13
  // the twin throws those from inside :json's hooks with the reason attached.
14
- import { maximum } from "./bounds.js";
14
+ import { coerce, maximum } from "./bounds.js";
15
15
  import { number } from "./canonical.js";
16
16
  import { err, ok } from "./value.js";
17
17
  // Thrown for ceiling/code denials — reason rides the exception.
@@ -28,11 +28,15 @@ export class SyntaxFail extends Error {
28
28
  export function decode(input, bounds) {
29
29
  if (typeof input !== "string" && !Buffer.isBuffer(input))
30
30
  return err("invalid_type");
31
+ const normalized = coerce(bounds === undefined ? maximum() : bounds);
32
+ if (!normalized.ok)
33
+ return normalized;
31
34
  const bytes = typeof input === "string" ? Buffer.from(input, "utf8") : input;
32
- // The profile is read field-wise (bytes/items/…) whatever the caller passed.
33
- const profile = (bounds ?? maximum());
35
+ const profile = normalized.v;
34
36
  if (bytes.length > profile.bytes)
35
37
  return err("ceiling:bytes");
38
+ if (typeof input === "string" && bytes.toString("utf8") !== input)
39
+ return err("invalid_encoding");
36
40
  const validUtf8 = isUtf8(bytes);
37
41
  const s = new Scanner(bytes, profile);
38
42
  try {
@@ -75,7 +79,7 @@ class Scanner {
75
79
  const value = this.parseValue();
76
80
  this.skipWs();
77
81
  if (!this.eof())
78
- throw new SyntaxFail(); // trailing bytes
82
+ throw new CodeFail("trailing_bytes");
79
83
  this.bumpNodes();
80
84
  return this.sink(value);
81
85
  }
@@ -109,8 +113,11 @@ class Scanner {
109
113
  }
110
114
  // Containers guard depth at ENTRY (live depth, root container = 1).
111
115
  parseArray() {
112
- this.enter();
113
116
  this.pos++; // '['
117
+ this.skipWs();
118
+ if (this.eof())
119
+ throw new SyntaxFail();
120
+ this.enter();
114
121
  const items = [];
115
122
  this.skipWs();
116
123
  if (!this.eof() && this.peek() === 0x5d) {
@@ -121,6 +128,9 @@ class Scanner {
121
128
  for (;;) {
122
129
  this.skipWs();
123
130
  const element = this.parseValue();
131
+ this.skipWs();
132
+ if (this.eof() || (this.peek() !== 0x2c && this.peek() !== 0x5d))
133
+ throw new SyntaxFail();
124
134
  this.guard(items.length + 1, this.bounds.items, "items");
125
135
  this.bumpNodes();
126
136
  items.push(this.sink(element));
@@ -140,8 +150,11 @@ class Scanner {
140
150
  }
141
151
  }
142
152
  parseObject() {
143
- this.enter();
144
153
  this.pos++; // '{'
154
+ this.skipWs();
155
+ if (this.eof())
156
+ throw new SyntaxFail();
157
+ this.enter();
145
158
  const members = [];
146
159
  this.skipWs();
147
160
  if (!this.eof() && this.peek() === 0x7d) {
@@ -160,6 +173,9 @@ class Scanner {
160
173
  this.pos++;
161
174
  this.skipWs();
162
175
  const value = this.parseValue();
176
+ this.skipWs();
177
+ if (this.eof() || (this.peek() !== 0x2c && this.peek() !== 0x7d))
178
+ throw new SyntaxFail();
163
179
  this.guard(members.length + 1, this.bounds.members, "members");
164
180
  if (Buffer.byteLength(key, "utf8") > this.bounds.key) {
165
181
  throw new CodeFail("ceiling:key");
@@ -425,6 +441,8 @@ function utf8Len(firstByte) {
425
441
  }
426
442
  // Strict UTF-8 validation: rejects overlong forms, surrogates, > U+10FFFF.
427
443
  export function isUtf8(bytes) {
444
+ if (!Buffer.isBuffer(bytes))
445
+ return false;
428
446
  let i = 0;
429
447
  while (i < bytes.length) {
430
448
  const c = bytes[i];
@@ -15,6 +15,7 @@ type VResult = {
15
15
  } | {
16
16
  ok: false;
17
17
  e: string;
18
+ subject?: (string | number)[];
18
19
  };
19
20
  export declare function table(): Spec[];
20
21
  export declare function decode(bytes: Buffer | string | symbol, bounds?: Bounds | Record<string, unknown>): {
@@ -23,6 +24,7 @@ export declare function decode(bytes: Buffer | string | symbol, bounds?: Bounds
23
24
  } | {
24
25
  ok: false;
25
26
  e: string;
27
+ subject?: (string | number)[];
26
28
  };
27
29
  export declare function fromValue(value: Value, opts?: {
28
30
  authoredExtensions?: string[];
@@ -32,18 +34,33 @@ export declare function fromValue(value: Value, opts?: {
32
34
  } | {
33
35
  ok: false;
34
36
  e: string;
37
+ subject?: (string | number)[];
38
+ };
39
+ export declare function toValue(deployment: Deployment): Value | {
40
+ ok: false;
41
+ e: string;
42
+ subject?: (string | number)[];
43
+ };
44
+ export declare function digestInput(deployment: Deployment): Value | {
45
+ ok: false;
46
+ e: string;
47
+ subject?: (string | number)[];
35
48
  };
36
- export declare function toValue(deployment: Deployment): Value;
37
- export declare function digestInput(deployment: Deployment): Value;
38
49
  export declare function canonicalBytes(deployment: Deployment): {
39
50
  ok: true;
40
51
  v: string;
41
52
  } | {
42
53
  ok: false;
43
54
  e: string;
55
+ subject?: (string | number)[];
56
+ };
57
+ export declare function contentDigest(deployment: Deployment): string | {
58
+ ok: false;
59
+ e: string;
60
+ subject?: (string | number)[];
44
61
  };
45
- export declare function contentDigest(deployment: Deployment): string;
46
62
  export declare function verifyContentDigest(deployment: Deployment): VResult;
47
63
  export declare function verifyBinding(deployment: Deployment, bound: blueprint.Blueprint, obs: Observations): VResult;
64
+ export declare function scan(value: Value, authoredNs: Set<string>): VResult;
48
65
  export declare function parseTimestamp(stamped: string): number | null;
49
66
  export {};