@agent-blueprint-protocol/verifier 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +891 -0
- package/LICENSE +190 -0
- package/NOTICE +4 -0
- package/README.md +199 -0
- package/dist/corpus/cases/base64url-decode.json +1 -0
- package/dist/corpus/cases/blueprint-decode.json +1 -0
- package/dist/corpus/cases/bounds-new.json +1 -0
- package/dist/corpus/cases/bounds_algebra-intersect.json +1 -0
- package/dist/corpus/cases/canonicalization-encode.json +1 -0
- package/dist/corpus/cases/compatibility-verify.json +1 -0
- package/dist/corpus/cases/deployment-decode.json +1 -0
- package/dist/corpus/cases/digest-tagged.json +1 -0
- package/dist/corpus/cases/extension-resolve.json +1 -0
- package/dist/corpus/cases/federation-decode.json +1 -0
- package/dist/corpus/cases/federation-verify_commitment.json +1 -0
- package/dist/corpus/cases/json-decode.json +1 -0
- package/dist/corpus/cases/negotiation-negotiate.json +1 -0
- package/dist/corpus/cases/portability-scan.json +1 -0
- package/dist/corpus/cases/schema-validate_instance.json +1 -0
- package/dist/corpus/cases/signature-verify.json +1 -0
- package/dist/corpus/index.json +1 -0
- package/dist/corpus/schemas/estate-contract.schema.json +1 -0
- package/dist/corpus/schemas/object.schema.json +1 -0
- package/dist/corpus/vectors/blueprint-golden.json +1 -0
- package/dist/corpus/vectors/deployment-golden.json +1 -0
- package/dist/corpus/vectors/rfc8785-numbers.json +1 -0
- package/dist/kit/cli.mjs +24 -0
- package/dist/verifier/b64url.d.ts +16 -0
- package/dist/verifier/b64url.js +36 -0
- package/dist/verifier/blueprint.d.ts +56 -0
- package/dist/verifier/blueprint.js +795 -0
- package/dist/verifier/bounds.d.ts +19 -0
- package/dist/verifier/bounds.js +45 -0
- package/dist/verifier/bounds_algebra.d.ts +27 -0
- package/dist/verifier/bounds_algebra.js +282 -0
- package/dist/verifier/canonical.d.ts +17 -0
- package/dist/verifier/canonical.js +160 -0
- package/dist/verifier/cli.d.ts +1 -0
- package/dist/verifier/cli.js +149 -0
- package/dist/verifier/compatibility.d.ts +22 -0
- package/dist/verifier/compatibility.js +112 -0
- package/dist/verifier/corpus.d.ts +42 -0
- package/dist/verifier/corpus.js +672 -0
- package/dist/verifier/decode.d.ts +16 -0
- package/dist/verifier/decode.js +457 -0
- package/dist/verifier/deployment.d.ts +49 -0
- package/dist/verifier/deployment.js +830 -0
- package/dist/verifier/digest.d.ts +23 -0
- package/dist/verifier/digest.js +58 -0
- package/dist/verifier/extension.d.ts +11 -0
- package/dist/verifier/extension.js +75 -0
- package/dist/verifier/federation.d.ts +76 -0
- package/dist/verifier/federation.js +817 -0
- package/dist/verifier/negotiation.d.ts +29 -0
- package/dist/verifier/negotiation.js +324 -0
- package/dist/verifier/portability.d.ts +12 -0
- package/dist/verifier/portability.js +184 -0
- package/dist/verifier/predicate.d.ts +10 -0
- package/dist/verifier/predicate.js +172 -0
- package/dist/verifier/registry.d.ts +16 -0
- package/dist/verifier/registry.js +120 -0
- package/dist/verifier/registry_engine.d.ts +42 -0
- package/dist/verifier/registry_engine.js +220 -0
- package/dist/verifier/report.d.ts +13 -0
- package/dist/verifier/report.js +29 -0
- package/dist/verifier/run_corpus.d.ts +1 -0
- package/dist/verifier/run_corpus.js +81 -0
- package/dist/verifier/runner.d.ts +20 -0
- package/dist/verifier/runner.js +778 -0
- package/dist/verifier/schema.d.ts +20 -0
- package/dist/verifier/schema.js +623 -0
- package/dist/verifier/self_checks.d.ts +1 -0
- package/dist/verifier/self_checks.js +316 -0
- package/dist/verifier/signature.d.ts +23 -0
- package/dist/verifier/signature.js +226 -0
- package/dist/verifier/value.d.ts +44 -0
- package/dist/verifier/value.js +77 -0
- package/package.json +42 -0
|
@@ -0,0 +1,172 @@
|
|
|
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).
|
|
7
|
+
const NODE_CEILING = 256;
|
|
8
|
+
const FOLD_OPS = ["and", "or"];
|
|
9
|
+
const NOT_OPS = ["not"];
|
|
10
|
+
const COMPARE_OPS = ["eq", "ne", "lt", "lte", "gt", "gte"];
|
|
11
|
+
const MEMBER_OPS = ["in"];
|
|
12
|
+
const PRESENCE_OPS = ["present", "absent"];
|
|
13
|
+
const ARG_OPS = [...FOLD_OPS, ...NOT_OPS];
|
|
14
|
+
const PATH_OPS = [...COMPARE_OPS, ...MEMBER_OPS, ...PRESENCE_OPS];
|
|
15
|
+
// operand name lists per operator
|
|
16
|
+
const OPERANDS = {
|
|
17
|
+
and: ["args"],
|
|
18
|
+
or: ["args"],
|
|
19
|
+
not: ["args"],
|
|
20
|
+
eq: ["path", "value"],
|
|
21
|
+
ne: ["path", "value"],
|
|
22
|
+
lt: ["path", "value"],
|
|
23
|
+
lte: ["path", "value"],
|
|
24
|
+
gt: ["path", "value"],
|
|
25
|
+
gte: ["path", "value"],
|
|
26
|
+
in: ["path", "values"],
|
|
27
|
+
present: ["path"],
|
|
28
|
+
absent: ["path"],
|
|
29
|
+
};
|
|
30
|
+
export function validate(predicate, portNames) {
|
|
31
|
+
const ports = new Set(portNames);
|
|
32
|
+
const result = shape(predicate, ports, 0);
|
|
33
|
+
return result.ok ? { ok: true } : { ok: false, e: result.e };
|
|
34
|
+
}
|
|
35
|
+
// ---- shape walk -----------------------------------------------------------------------
|
|
36
|
+
function shape(predicate, ports, count) {
|
|
37
|
+
if (predicate.t !== "obj")
|
|
38
|
+
return { ok: false, e: "invalid_type" };
|
|
39
|
+
const members = predicate.v;
|
|
40
|
+
if (count + 1 > NODE_CEILING)
|
|
41
|
+
return { ok: false, e: "predicate_nodes_exceeded" };
|
|
42
|
+
if (!noDuplicateMembers(members))
|
|
43
|
+
return { ok: false, e: "invalid_type" };
|
|
44
|
+
const op = opOf(members);
|
|
45
|
+
if (!op.ok)
|
|
46
|
+
return op;
|
|
47
|
+
const closed = closedMembers(members, op.v);
|
|
48
|
+
if (!closed.ok)
|
|
49
|
+
return closed;
|
|
50
|
+
const present = operandsPresent(members, op.v);
|
|
51
|
+
if (!present.ok)
|
|
52
|
+
return present;
|
|
53
|
+
return operandShapes(members, op.v, ports, count + 1);
|
|
54
|
+
}
|
|
55
|
+
function noDuplicateMembers(members) {
|
|
56
|
+
const names = new Set();
|
|
57
|
+
for (const [name] of members) {
|
|
58
|
+
if (typeof name !== "string")
|
|
59
|
+
return false;
|
|
60
|
+
if (names.has(name))
|
|
61
|
+
return false;
|
|
62
|
+
names.add(name);
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
function opOf(members) {
|
|
67
|
+
const found = keyfind(members, "op");
|
|
68
|
+
if (found === null)
|
|
69
|
+
return { ok: false, e: "missing_required_field" };
|
|
70
|
+
if (found.t !== "str")
|
|
71
|
+
return { ok: false, e: "invalid_type" };
|
|
72
|
+
return { ok: true, v: found.v };
|
|
73
|
+
}
|
|
74
|
+
function closedMembers(members, op) {
|
|
75
|
+
const operands = OPERANDS[op];
|
|
76
|
+
if (operands === undefined)
|
|
77
|
+
return { ok: false, e: "predicate_op_unknown" };
|
|
78
|
+
const allowed = new Set(["op", ...operands]);
|
|
79
|
+
for (const [name] of members) {
|
|
80
|
+
if (!allowed.has(name))
|
|
81
|
+
return { ok: false, e: "unknown_member" };
|
|
82
|
+
}
|
|
83
|
+
return { ok: true };
|
|
84
|
+
}
|
|
85
|
+
function operandsPresent(members, op) {
|
|
86
|
+
for (const name of OPERANDS[op]) {
|
|
87
|
+
if (keyfind(members, name) === null)
|
|
88
|
+
return { ok: false, e: "missing_required_field" };
|
|
89
|
+
}
|
|
90
|
+
return { ok: true };
|
|
91
|
+
}
|
|
92
|
+
function operandShapes(members, op, ports, count) {
|
|
93
|
+
if (ARG_OPS.includes(op)) {
|
|
94
|
+
const args = arrayMember(members, "args");
|
|
95
|
+
if (!args.ok)
|
|
96
|
+
return args;
|
|
97
|
+
if (!arityOk(op, args.v.length))
|
|
98
|
+
return { ok: false, e: "invalid_cardinality" };
|
|
99
|
+
return argShapes(args.v, ports, count);
|
|
100
|
+
}
|
|
101
|
+
// path ops
|
|
102
|
+
const path = pathMember(members, ports);
|
|
103
|
+
if (!path.ok)
|
|
104
|
+
return path;
|
|
105
|
+
if (op === "in") {
|
|
106
|
+
const values = valuesMember(members);
|
|
107
|
+
if (!values.ok)
|
|
108
|
+
return values;
|
|
109
|
+
}
|
|
110
|
+
return { ok: true, v: count };
|
|
111
|
+
}
|
|
112
|
+
function arityOk(op, n) {
|
|
113
|
+
if (FOLD_OPS.includes(op))
|
|
114
|
+
return n >= 1;
|
|
115
|
+
return n === 1; // not
|
|
116
|
+
}
|
|
117
|
+
function argShapes(items, ports, count) {
|
|
118
|
+
let acc = count;
|
|
119
|
+
for (const item of items) {
|
|
120
|
+
const result = shape(item, ports, acc);
|
|
121
|
+
if (!result.ok)
|
|
122
|
+
return result;
|
|
123
|
+
acc = result.v;
|
|
124
|
+
}
|
|
125
|
+
return { ok: true, v: acc };
|
|
126
|
+
}
|
|
127
|
+
function arrayMember(members, name) {
|
|
128
|
+
const found = keyfind(members, name);
|
|
129
|
+
if (found !== null && found.t === "arr")
|
|
130
|
+
return { ok: true, v: found.v };
|
|
131
|
+
return { ok: false, e: "invalid_type" };
|
|
132
|
+
}
|
|
133
|
+
function pathMember(members, ports) {
|
|
134
|
+
const found = keyfind(members, "path");
|
|
135
|
+
if (found === null || found.t !== "arr")
|
|
136
|
+
return { ok: false, e: "invalid_type" };
|
|
137
|
+
const segments = found.v;
|
|
138
|
+
if (segments.length === 0)
|
|
139
|
+
return { ok: false, e: "invalid_type" };
|
|
140
|
+
if (!segments.every((s) => s.t === "str"))
|
|
141
|
+
return { ok: false, e: "invalid_type" };
|
|
142
|
+
const root = segments[0].v;
|
|
143
|
+
return ports.has(root) ? { ok: true } : { ok: false, e: "predicate_path_unresolved" };
|
|
144
|
+
}
|
|
145
|
+
function valuesMember(members) {
|
|
146
|
+
const found = keyfind(members, "values");
|
|
147
|
+
if (found === null || found.t !== "arr")
|
|
148
|
+
return { ok: false, e: "invalid_type" };
|
|
149
|
+
if (!found.v.every(wellFormed))
|
|
150
|
+
return { ok: false, e: "invalid_type" };
|
|
151
|
+
return { ok: true };
|
|
152
|
+
}
|
|
153
|
+
// `value`/`values` operands carry arbitrary tagged JSON; they must still be
|
|
154
|
+
// well-formed tagged values or evaluate-time equality would crash.
|
|
155
|
+
function wellFormed(value) {
|
|
156
|
+
switch (value.t) {
|
|
157
|
+
case "null":
|
|
158
|
+
case "bool":
|
|
159
|
+
case "int":
|
|
160
|
+
case "float":
|
|
161
|
+
case "str":
|
|
162
|
+
return true;
|
|
163
|
+
case "arr":
|
|
164
|
+
return value.v.every(wellFormed);
|
|
165
|
+
case "obj":
|
|
166
|
+
return value.v.every(([name, member]) => typeof name === "string" && wellFormed(member));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function keyfind(members, name) {
|
|
170
|
+
const found = members.find(([key]) => key === name);
|
|
171
|
+
return found ? found[1] : null;
|
|
172
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Value } from "./value.ts";
|
|
2
|
+
export type Criticality = "critical" | "optional";
|
|
3
|
+
export type RegState = "reserved" | "active" | "deprecated" | "retired";
|
|
4
|
+
export interface RegistryEntry {
|
|
5
|
+
namespace: string;
|
|
6
|
+
owner: string;
|
|
7
|
+
criticality: Criticality;
|
|
8
|
+
state: RegState;
|
|
9
|
+
schema_digest: string | null;
|
|
10
|
+
a2a_uri: string;
|
|
11
|
+
promoted_at_revision: number | null;
|
|
12
|
+
}
|
|
13
|
+
export declare function federationSchema(): Value;
|
|
14
|
+
export declare function registeredExtensions(): RegistryEntry[];
|
|
15
|
+
export declare function entry(namespace: string): RegistryEntry | null;
|
|
16
|
+
export declare function registryDigest(): string;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// The compiled-in extension registry twin: the six entries (five
|
|
2
|
+
// first-release rows plus the estate-contract product registration) and
|
|
3
|
+
// the federation schema, with the registry content digest the corpus binds
|
|
4
|
+
// to. Agreement with the Elixir twin is proven by the corpus's own
|
|
5
|
+
// registry_digest check at load — neither side reads the other's source.
|
|
6
|
+
import * as digest from "./digest.js";
|
|
7
|
+
import { encode } from "./canonical.js";
|
|
8
|
+
import { bool, int, nil, obj, str } from "./value.js";
|
|
9
|
+
// The federation envelope's minimal schema — owned by this package, inside
|
|
10
|
+
// the bounded dialect (closed object, no reserved-semantics names).
|
|
11
|
+
export function federationSchema() {
|
|
12
|
+
return obj([
|
|
13
|
+
["additionalProperties", bool(false)],
|
|
14
|
+
[
|
|
15
|
+
"properties",
|
|
16
|
+
obj([
|
|
17
|
+
["issuer", obj([["type", str("string")]])],
|
|
18
|
+
["subject", obj([["type", str("string")]])],
|
|
19
|
+
["audience", obj([["type", str("string")]])],
|
|
20
|
+
]),
|
|
21
|
+
],
|
|
22
|
+
["type", str("object")],
|
|
23
|
+
]);
|
|
24
|
+
}
|
|
25
|
+
function taggedFederationDigest() {
|
|
26
|
+
const jcs = encode(federationSchema());
|
|
27
|
+
if (!jcs.ok)
|
|
28
|
+
throw new Error("federation schema must encode");
|
|
29
|
+
return digest.toTagged(digest.hash("extension_schema", Buffer.from(jcs.v, "utf8")));
|
|
30
|
+
}
|
|
31
|
+
function entries() {
|
|
32
|
+
return [
|
|
33
|
+
{
|
|
34
|
+
namespace: "com.example.commerce/graph",
|
|
35
|
+
owner: "ExampleCommerce",
|
|
36
|
+
criticality: "critical",
|
|
37
|
+
state: "active",
|
|
38
|
+
schema_digest: null,
|
|
39
|
+
a2a_uri: "https://example.com/extensions/commerce-graph",
|
|
40
|
+
promoted_at_revision: null,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
namespace: "com.example.commerce/classification-labels",
|
|
44
|
+
owner: "ExampleCommerce",
|
|
45
|
+
criticality: "optional",
|
|
46
|
+
state: "active",
|
|
47
|
+
schema_digest: null,
|
|
48
|
+
a2a_uri: "https://example.com/extensions/commerce-classification-labels",
|
|
49
|
+
promoted_at_revision: null,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
namespace: "com.example.commerce/rubric-assertion",
|
|
53
|
+
owner: "ExampleCommerce",
|
|
54
|
+
criticality: "optional",
|
|
55
|
+
state: "active",
|
|
56
|
+
schema_digest: null,
|
|
57
|
+
a2a_uri: "https://example.com/extensions/commerce-rubric-assertion",
|
|
58
|
+
promoted_at_revision: null,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
namespace: "com.example.platform/estate",
|
|
62
|
+
owner: "ExamplePlatform",
|
|
63
|
+
criticality: "optional",
|
|
64
|
+
state: "deprecated",
|
|
65
|
+
schema_digest: null,
|
|
66
|
+
a2a_uri: "https://example.com/extensions/platform-estate",
|
|
67
|
+
promoted_at_revision: null,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
// The product-extension registration: the first product-owned critical
|
|
71
|
+
// pin. The document is corpus data (schemas/estate-contract.schema.json);
|
|
72
|
+
// this digest is JCS-of-parsed-document under the extension-schema
|
|
73
|
+
// domain, bound to the shipped file by the Elixir pin test.
|
|
74
|
+
namespace: "com.example.platform/estate-contract",
|
|
75
|
+
owner: "ExamplePlatform",
|
|
76
|
+
criticality: "critical",
|
|
77
|
+
state: "active",
|
|
78
|
+
schema_digest: "sha-256:s_ToZWwxrhhd4vVxAyUh2Q6Gddston4tBSLHTLvCQAw",
|
|
79
|
+
a2a_uri: "https://example.com/extensions/platform-estate-contract",
|
|
80
|
+
promoted_at_revision: null,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
namespace: "com.example/federation",
|
|
84
|
+
owner: "Agent Blueprint Protocol",
|
|
85
|
+
criticality: "critical",
|
|
86
|
+
state: "active",
|
|
87
|
+
schema_digest: taggedFederationDigest(),
|
|
88
|
+
a2a_uri: "https://example.com/extensions/federation",
|
|
89
|
+
promoted_at_revision: null,
|
|
90
|
+
},
|
|
91
|
+
];
|
|
92
|
+
}
|
|
93
|
+
export function registeredExtensions() {
|
|
94
|
+
return entries();
|
|
95
|
+
}
|
|
96
|
+
export function entry(namespace) {
|
|
97
|
+
return entries().find((candidate) => candidate.namespace === namespace) ?? null;
|
|
98
|
+
}
|
|
99
|
+
// The registry content digest (the corpus-registry binding): hash over the
|
|
100
|
+
// JCS of entries projected to their declared field set, keyed by namespace.
|
|
101
|
+
export function registryDigest() {
|
|
102
|
+
const projected = obj(entries().map((entry) => [
|
|
103
|
+
entry.namespace,
|
|
104
|
+
obj([
|
|
105
|
+
["a2a_uri", str(entry.a2a_uri)],
|
|
106
|
+
["criticality", str(entry.criticality)],
|
|
107
|
+
["owner", str(entry.owner)],
|
|
108
|
+
[
|
|
109
|
+
"promoted_at_revision",
|
|
110
|
+
entry.promoted_at_revision === null ? nil : int(entry.promoted_at_revision),
|
|
111
|
+
],
|
|
112
|
+
["schema_digest", entry.schema_digest === null ? nil : str(entry.schema_digest)],
|
|
113
|
+
["state", str(entry.state)],
|
|
114
|
+
]),
|
|
115
|
+
]));
|
|
116
|
+
const jcs = encode(projected);
|
|
117
|
+
if (!jcs.ok)
|
|
118
|
+
throw new Error("registry projection must encode");
|
|
119
|
+
return digest.toTagged(digest.hash("extension_registry", Buffer.from(jcs.v, "utf8")));
|
|
120
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Value } from "./value.ts";
|
|
2
|
+
export type Kind = "string" | "integer" | "float" | "boolean" | "number" | "any" | "custom" | {
|
|
3
|
+
enum: Set<string>;
|
|
4
|
+
} | {
|
|
5
|
+
array: Spec;
|
|
6
|
+
} | {
|
|
7
|
+
object: {
|
|
8
|
+
members: Spec[];
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export type Check = (value: Value) => {
|
|
12
|
+
ok: true;
|
|
13
|
+
} | {
|
|
14
|
+
ok: false;
|
|
15
|
+
e: string;
|
|
16
|
+
};
|
|
17
|
+
export type RootHook = (members: Map<string, Value>) => {
|
|
18
|
+
ok: true;
|
|
19
|
+
} | {
|
|
20
|
+
ok: false;
|
|
21
|
+
e: string;
|
|
22
|
+
};
|
|
23
|
+
export interface Spec {
|
|
24
|
+
name?: string;
|
|
25
|
+
required?: boolean;
|
|
26
|
+
kind: Kind;
|
|
27
|
+
check?: Check;
|
|
28
|
+
rootHook?: RootHook;
|
|
29
|
+
minItems?: number;
|
|
30
|
+
maxItems?: number;
|
|
31
|
+
uniqueBy?: string | ":value";
|
|
32
|
+
}
|
|
33
|
+
export type VResult = {
|
|
34
|
+
ok: true;
|
|
35
|
+
} | {
|
|
36
|
+
ok: false;
|
|
37
|
+
e: string;
|
|
38
|
+
};
|
|
39
|
+
export declare function field(name: string, kind: Kind, opts?: Partial<Spec>): Spec;
|
|
40
|
+
export declare function validate(table: Spec[], value: Value): VResult;
|
|
41
|
+
export declare function keyfind(members: [string, Value][], name: string): Value | null;
|
|
42
|
+
export declare function termEqual(a: Value, b: Value): boolean;
|
|
@@ -0,0 +1,220 @@
|
|
|
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).
|
|
10
|
+
// The table-builder helper (the twin's field/2): name + kind, required by
|
|
11
|
+
// default, keyword-style options.
|
|
12
|
+
export function field(name, kind, opts = {}) {
|
|
13
|
+
return { name, required: true, kind, ...opts };
|
|
14
|
+
}
|
|
15
|
+
export function validate(table, value) {
|
|
16
|
+
if (value.t !== "obj")
|
|
17
|
+
return { ok: false, e: "invalid_type" };
|
|
18
|
+
const members = value.v;
|
|
19
|
+
for (const [name] of members) {
|
|
20
|
+
if (typeof name !== "string")
|
|
21
|
+
return { ok: false, e: "invalid_type" };
|
|
22
|
+
}
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
for (const [name] of members) {
|
|
25
|
+
if (seen.has(name))
|
|
26
|
+
return { ok: false, e: "invalid_type" };
|
|
27
|
+
seen.add(name);
|
|
28
|
+
}
|
|
29
|
+
const tableNames = new Set(table.map((spec) => spec.name));
|
|
30
|
+
for (const [name] of members) {
|
|
31
|
+
if (!tableNames.has(name))
|
|
32
|
+
return { ok: false, e: "unknown_member" };
|
|
33
|
+
}
|
|
34
|
+
const present = new Set(members.map(([name]) => name));
|
|
35
|
+
for (const spec of table) {
|
|
36
|
+
// Table specs always come from field() (named); the ! mirrors that invariant.
|
|
37
|
+
if (spec.required && !present.has(spec.name))
|
|
38
|
+
return { ok: false, e: "missing_required_field" };
|
|
39
|
+
}
|
|
40
|
+
// Every table stage shares one walk: find the first spec (in table order)
|
|
41
|
+
// whose present value fails.
|
|
42
|
+
const stageFailure = (judge) => {
|
|
43
|
+
for (const spec of table) {
|
|
44
|
+
const found = keyfind(members, spec.name);
|
|
45
|
+
if (found === null)
|
|
46
|
+
continue;
|
|
47
|
+
const failure = judge(spec, found);
|
|
48
|
+
if (failure !== null)
|
|
49
|
+
return { ok: false, e: failure.e };
|
|
50
|
+
}
|
|
51
|
+
return { ok: true };
|
|
52
|
+
};
|
|
53
|
+
const typeStage = stageFailure((spec, value) => (kindOk(spec.kind, value) ? null : { ok: false, e: "invalid_type" }));
|
|
54
|
+
if (!typeStage.ok)
|
|
55
|
+
return typeStage;
|
|
56
|
+
const constraintStage = stageFailure((spec, value) => specConstraint(spec, value));
|
|
57
|
+
if (!constraintStage.ok)
|
|
58
|
+
return constraintStage;
|
|
59
|
+
const cardinalityStage = stageFailure((spec, value) => arrayCardinality(spec, value));
|
|
60
|
+
if (!cardinalityStage.ok)
|
|
61
|
+
return cardinalityStage;
|
|
62
|
+
const recursionStage = stageFailure((spec, value) => passNil(recurse(spec.kind, value)));
|
|
63
|
+
if (!recursionStage.ok)
|
|
64
|
+
return recursionStage;
|
|
65
|
+
const memberMap = new Map(members);
|
|
66
|
+
for (const spec of table) {
|
|
67
|
+
if (spec.rootHook === undefined)
|
|
68
|
+
continue;
|
|
69
|
+
if (!memberMap.has(spec.name))
|
|
70
|
+
continue;
|
|
71
|
+
const result = spec.rootHook(memberMap);
|
|
72
|
+
if (!result.ok)
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
return { ok: true };
|
|
76
|
+
}
|
|
77
|
+
// ---- stages --------------------------------------------------------------------------
|
|
78
|
+
function specConstraint(spec, value) {
|
|
79
|
+
if (typeof spec.kind === "object" && "enum" in spec.kind) {
|
|
80
|
+
if (value.t === "str")
|
|
81
|
+
return spec.kind.enum.has(value.v) ? null : { ok: false, e: "invalid_constraint" };
|
|
82
|
+
}
|
|
83
|
+
if (spec.check !== undefined) {
|
|
84
|
+
const result = spec.check(value);
|
|
85
|
+
return result.ok ? null : { ok: false, e: result.e };
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
function arrayCardinality(spec, value) {
|
|
90
|
+
if (value.t !== "arr")
|
|
91
|
+
return null;
|
|
92
|
+
if (spec.minItems !== undefined && value.v.length < spec.minItems) {
|
|
93
|
+
return { ok: false, e: "invalid_cardinality" };
|
|
94
|
+
}
|
|
95
|
+
if (spec.maxItems !== undefined && value.v.length > spec.maxItems) {
|
|
96
|
+
return { ok: false, e: "invalid_cardinality" };
|
|
97
|
+
}
|
|
98
|
+
if (duplicateKeys(spec.uniqueBy, value.v))
|
|
99
|
+
return { ok: false, e: "invalid_cardinality" };
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
// Uniqueness over raw values: object elements participate through the named
|
|
103
|
+
// member; scalar elements participate whole (uniqueBy: ":value").
|
|
104
|
+
function duplicateKeys(uniqueBy, items) {
|
|
105
|
+
if (uniqueBy === undefined)
|
|
106
|
+
return false;
|
|
107
|
+
if (uniqueBy === ":value") {
|
|
108
|
+
return items.some((item, i) => items.slice(0, i).some((other) => termEqual(item, other)));
|
|
109
|
+
}
|
|
110
|
+
const keys = [];
|
|
111
|
+
for (const item of items) {
|
|
112
|
+
if (item.t !== "obj")
|
|
113
|
+
continue;
|
|
114
|
+
const found = keyfind(item.v, uniqueBy);
|
|
115
|
+
if (found !== null)
|
|
116
|
+
keys.push(found);
|
|
117
|
+
}
|
|
118
|
+
return keys.some((key, i) => keys.slice(0, i).some((other) => termEqual(key, other)));
|
|
119
|
+
}
|
|
120
|
+
function passNil(result) {
|
|
121
|
+
return result.ok ? null : result;
|
|
122
|
+
}
|
|
123
|
+
// ---- recursion ----------------------------------------------------------------------
|
|
124
|
+
function recurse(kind, value) {
|
|
125
|
+
if (typeof kind === "object" && "array" in kind) {
|
|
126
|
+
if (value.t !== "arr")
|
|
127
|
+
return { ok: true };
|
|
128
|
+
for (const item of value.v) {
|
|
129
|
+
const result = elementOk(kind.array, item);
|
|
130
|
+
if (!result.ok)
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
return { ok: true };
|
|
134
|
+
}
|
|
135
|
+
if (typeof kind === "object" && "object" in kind) {
|
|
136
|
+
if (value.t !== "obj")
|
|
137
|
+
return { ok: true };
|
|
138
|
+
return validate(kind.object.members, value);
|
|
139
|
+
}
|
|
140
|
+
return { ok: true };
|
|
141
|
+
}
|
|
142
|
+
function elementOk(spec, value) {
|
|
143
|
+
if (!kindOk(spec.kind, value))
|
|
144
|
+
return { ok: false, e: "invalid_type" };
|
|
145
|
+
const constraint = specConstraint(spec, value);
|
|
146
|
+
if (constraint !== null)
|
|
147
|
+
return { ok: false, e: constraint.e };
|
|
148
|
+
return recurse(spec.kind, value);
|
|
149
|
+
}
|
|
150
|
+
// ---- kinds --------------------------------------------------------------------------
|
|
151
|
+
function kindOk(kind, value) {
|
|
152
|
+
switch (kind) {
|
|
153
|
+
case "string":
|
|
154
|
+
return value.t === "str";
|
|
155
|
+
case "integer":
|
|
156
|
+
return value.t === "int";
|
|
157
|
+
case "float":
|
|
158
|
+
return value.t === "float";
|
|
159
|
+
case "boolean":
|
|
160
|
+
return value.t === "bool";
|
|
161
|
+
case "number":
|
|
162
|
+
return value.t === "int" || value.t === "float";
|
|
163
|
+
case "any":
|
|
164
|
+
return wellFormed(value);
|
|
165
|
+
case "custom":
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
if (typeof kind === "object" && "enum" in kind)
|
|
169
|
+
return value.t === "str";
|
|
170
|
+
if (typeof kind === "object" && "array" in kind)
|
|
171
|
+
return value.t === "arr";
|
|
172
|
+
if (typeof kind === "object" && "object" in kind)
|
|
173
|
+
return value.t === "obj";
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
function wellFormed(value) {
|
|
177
|
+
switch (value.t) {
|
|
178
|
+
case "null":
|
|
179
|
+
case "bool":
|
|
180
|
+
case "int":
|
|
181
|
+
case "float":
|
|
182
|
+
case "str":
|
|
183
|
+
return true;
|
|
184
|
+
case "arr":
|
|
185
|
+
return value.v.every(wellFormed);
|
|
186
|
+
case "obj":
|
|
187
|
+
return value.v.every(([name, member]) => typeof name === "string" && wellFormed(member));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// ---- helpers -------------------------------------------------------------------------
|
|
191
|
+
export function keyfind(members, name) {
|
|
192
|
+
const found = members.find(([key]) => key === name);
|
|
193
|
+
return found ? found[1] : null;
|
|
194
|
+
}
|
|
195
|
+
// Elixir `=:=` term equality over the tagged algebra: tags are strict
|
|
196
|
+
// (int 5 and float 5.0 are distinct), object member ORDER is significant.
|
|
197
|
+
export function termEqual(a, b) {
|
|
198
|
+
if (a.t !== b.t)
|
|
199
|
+
return false;
|
|
200
|
+
switch (a.t) {
|
|
201
|
+
case "null":
|
|
202
|
+
return true;
|
|
203
|
+
case "bool":
|
|
204
|
+
case "int":
|
|
205
|
+
case "float":
|
|
206
|
+
case "str":
|
|
207
|
+
return a.v === b.v;
|
|
208
|
+
case "arr":
|
|
209
|
+
return (b.t === "arr" &&
|
|
210
|
+
a.v.length === b.v.length &&
|
|
211
|
+
a.v.every((x, i) => termEqual(x, b.v[i])));
|
|
212
|
+
case "obj":
|
|
213
|
+
return (b.t === "obj" &&
|
|
214
|
+
a.v.length === b.v.length &&
|
|
215
|
+
a.v.every((pair, i) => {
|
|
216
|
+
const other = b.v[i];
|
|
217
|
+
return pair[0] === other[0] && termEqual(pair[1], other[1]);
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface CaseResult {
|
|
2
|
+
caseId: string;
|
|
3
|
+
agree: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface Report {
|
|
6
|
+
agreement: boolean;
|
|
7
|
+
exitStatus: 0 | 1;
|
|
8
|
+
total: number;
|
|
9
|
+
agreed: number;
|
|
10
|
+
disagreed: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function build(results: CaseResult[][]): Report;
|
|
13
|
+
export declare function toBytes(corpusIdentity: string, results: CaseResult[][]): string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// The report builder — the mirror of AgentBlueprintProtocol.Conformance.Report:
|
|
2
|
+
// refuses vacuous green (agreement requires total > 0 AND zero disagreements)
|
|
3
|
+
// and emits deterministic JCS report bytes identity-bound to the corpus.
|
|
4
|
+
import { encode } from "./canonical.js";
|
|
5
|
+
import { bool, int, obj, str } from "./value.js";
|
|
6
|
+
const FORMAT = "agent-blueprint-protocol-conformance-report";
|
|
7
|
+
export function build(results) {
|
|
8
|
+
const all = results.flat();
|
|
9
|
+
const total = all.length;
|
|
10
|
+
const agreed = all.filter((r) => r.agree).length;
|
|
11
|
+
const disagreed = total - agreed;
|
|
12
|
+
const agreement = total > 0 && disagreed === 0;
|
|
13
|
+
return { agreement, exitStatus: agreement ? 0 : 1, total, agreed, disagreed };
|
|
14
|
+
}
|
|
15
|
+
export function toBytes(corpusIdentity, results) {
|
|
16
|
+
const report = build(results);
|
|
17
|
+
const encoded = encode(obj([
|
|
18
|
+
["format", str(FORMAT)],
|
|
19
|
+
["agreement", bool(report.agreement)],
|
|
20
|
+
["exit_status", int(report.exitStatus)],
|
|
21
|
+
["total", int(report.total)],
|
|
22
|
+
["agreed", int(report.agreed)],
|
|
23
|
+
["disagreed", int(report.disagreed)],
|
|
24
|
+
["corpus_digest", str(corpusIdentity)],
|
|
25
|
+
]));
|
|
26
|
+
if (!encoded.ok)
|
|
27
|
+
throw new Error("report must encode");
|
|
28
|
+
return encoded.v;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|