@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.
- package/CHANGELOG.md +137 -0
- package/LICENSE +1 -1
- package/NOTICE +2 -2
- package/README.md +164 -255
- package/dist/corpus/cases/blueprint-decode.json +1 -1
- package/dist/corpus/cases/bounds-new.json +1 -1
- package/dist/corpus/cases/bounds_algebra-intersect.json +1 -1
- package/dist/corpus/cases/canonicalization-encode.json +1 -1
- package/dist/corpus/cases/deployment-decode.json +1 -1
- package/dist/corpus/cases/extension-resolve.json +1 -1
- package/dist/corpus/cases/federation-decode.json +1 -1
- package/dist/corpus/cases/federation-verify_commitment.json +1 -1
- package/dist/corpus/cases/json-decode.json +1 -1
- package/dist/corpus/cases/negotiation-negotiate.json +1 -1
- package/dist/corpus/cases/predicate.json +1 -0
- package/dist/corpus/cases/reconcile.json +1 -0
- package/dist/corpus/cases/schema-validate_instance.json +1 -1
- package/dist/corpus/cases/signature-verify.json +1 -1
- package/dist/corpus/index.json +1 -1
- package/dist/kit/cli.mjs +1 -4
- package/dist/release-history.json +1 -0
- package/dist/release-metadata.json +1 -1
- package/dist/spec/FOUNDATION-TRANSITION.md +67 -0
- package/dist/spec/IPR.md +27 -0
- package/dist/spec/LICENSE +190 -0
- package/dist/spec/NOTICE +4 -0
- package/dist/spec/README.md +47 -0
- package/dist/spec/conformance/base64url-decode.schema.json +176 -0
- package/dist/spec/conformance/blueprint-decode.schema.json +280 -0
- package/dist/spec/conformance/bounds-new.schema.json +302 -0
- package/dist/spec/conformance/bounds_algebra-intersect.schema.json +457 -0
- package/dist/spec/conformance/canonicalization-encode.schema.json +280 -0
- package/dist/spec/conformance/case-file.schema.json +122 -0
- package/dist/spec/conformance/certified-results.json +1 -0
- package/dist/spec/conformance/claim.schema.json +52 -0
- package/dist/spec/conformance/compatibility-verify.schema.json +262 -0
- package/dist/spec/conformance/deployment-decode.schema.json +322 -0
- package/dist/spec/conformance/digest-tagged.schema.json +200 -0
- package/dist/spec/conformance/evidence.schema.json +249 -0
- package/dist/spec/conformance/execution.md +80 -0
- package/dist/spec/conformance/extension-resolve.schema.json +264 -0
- package/dist/spec/conformance/federation-decode.schema.json +318 -0
- package/dist/spec/conformance/federation-verify_commitment.schema.json +342 -0
- package/dist/spec/conformance/index.schema.json +102 -0
- package/dist/spec/conformance/json-decode.schema.json +287 -0
- package/dist/spec/conformance/negotiation-negotiate.schema.json +264 -0
- package/dist/spec/conformance/portability-scan.schema.json +188 -0
- package/dist/spec/conformance/predicate.schema.json +201 -0
- package/dist/spec/conformance/reconcile.schema.json +287 -0
- package/dist/spec/conformance/runner.md +182 -0
- package/dist/spec/conformance/schema-validate_instance.schema.json +206 -0
- package/dist/spec/conformance/signature-verify.schema.json +224 -0
- package/dist/spec/conformance/support.schema.json +72 -0
- package/dist/spec/errata.md +13 -0
- package/dist/spec/grammar/blueprint.cddl +92 -0
- package/dist/spec/grammar/deployment.cddl +125 -0
- package/dist/spec/grammar/derived/blueprint.schema.json +340 -0
- package/dist/spec/grammar/derived/deployment.schema.json +496 -0
- package/dist/spec/grammar/derived/taskenvelope.schema.json +244 -0
- package/dist/spec/grammar/taskenvelope.cddl +77 -0
- package/dist/spec/protocol.md +1238 -0
- package/dist/spec/registry/OPERATIONS.md +69 -0
- package/dist/spec/registry/registry.json +68 -0
- package/dist/verifier/b64url.d.ts +6 -2
- package/dist/verifier/b64url.js +7 -1
- package/dist/verifier/blueprint.d.ts +12 -16
- package/dist/verifier/blueprint.js +40 -112
- package/dist/verifier/bounds.d.ts +1 -1
- package/dist/verifier/bounds.js +2 -2
- package/dist/verifier/bounds_algebra.d.ts +9 -0
- package/dist/verifier/bounds_algebra.js +10 -7
- package/dist/verifier/canonical.d.ts +1 -1
- package/dist/verifier/canonical.js +41 -8
- package/dist/verifier/cli.js +97 -45
- package/dist/verifier/compatibility.js +5 -7
- package/dist/verifier/corpus.d.ts +1 -1
- package/dist/verifier/corpus.js +10 -2
- package/dist/verifier/decode.js +24 -6
- package/dist/verifier/deployment.d.ts +20 -3
- package/dist/verifier/deployment.js +48 -10
- package/dist/verifier/digest.d.ts +12 -0
- package/dist/verifier/digest.js +17 -3
- package/dist/verifier/errors.d.ts +2 -0
- package/dist/verifier/errors.js +1 -0
- package/dist/verifier/execution.d.ts +13 -0
- package/dist/verifier/execution.js +82 -0
- package/dist/verifier/extension.js +4 -4
- package/dist/verifier/facade.d.ts +325 -0
- package/dist/verifier/facade.js +78 -0
- package/dist/verifier/federation.d.ts +2 -2
- package/dist/verifier/federation.js +26 -79
- package/dist/verifier/harness.d.ts +16 -0
- package/dist/verifier/harness.js +201 -0
- package/dist/verifier/index.d.ts +3 -0
- package/dist/verifier/index.js +2 -0
- package/dist/verifier/mapping.d.ts +139 -0
- package/dist/verifier/mapping.js +1 -0
- package/dist/verifier/negotiation.d.ts +2 -1
- package/dist/verifier/negotiation.js +12 -3
- package/dist/verifier/plain.d.ts +4 -0
- package/dist/verifier/plain.js +38 -0
- package/dist/verifier/portability.d.ts +1 -1
- package/dist/verifier/portability.js +19 -6
- package/dist/verifier/predicate.d.ts +7 -0
- package/dist/verifier/predicate.js +63 -7
- package/dist/verifier/reconcile.d.ts +37 -0
- package/dist/verifier/reconcile.js +115 -0
- package/dist/verifier/registry.js +10 -1
- package/dist/verifier/registry_engine.d.ts +3 -0
- package/dist/verifier/registry_engine.js +37 -20
- package/dist/verifier/report.d.ts +8 -0
- package/dist/verifier/report.js +9 -2
- package/dist/verifier/results.d.ts +3 -0
- package/dist/verifier/results.js +13 -0
- package/dist/verifier/run_corpus.js +4 -80
- package/dist/verifier/runner.d.ts +6 -0
- package/dist/verifier/runner.js +123 -17
- package/dist/verifier/schema.js +14 -55
- package/dist/verifier/signature.d.ts +19 -8
- package/dist/verifier/signature.js +51 -29
- package/dist/verifier/value.d.ts +9 -2
- package/dist/verifier/value.js +81 -11
- package/package.json +17 -12
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as blueprint from './blueprint.ts';
|
|
2
|
+
import * as deployment from './deployment.ts';
|
|
3
|
+
import * as negotiation from './negotiation.ts';
|
|
4
|
+
import * as signature from './signature.ts';
|
|
5
|
+
type Failure = {
|
|
6
|
+
ok: false;
|
|
7
|
+
e: string;
|
|
8
|
+
subject?: (string | number)[];
|
|
9
|
+
};
|
|
10
|
+
export interface Inputs {
|
|
11
|
+
hostBounds: Record<string, unknown>;
|
|
12
|
+
support: negotiation.Support;
|
|
13
|
+
keys: signature.PublicKey[];
|
|
14
|
+
protectedClamp: 'deny' | 'acknowledge';
|
|
15
|
+
observations: deployment.Observations;
|
|
16
|
+
}
|
|
17
|
+
export interface Check {
|
|
18
|
+
surface: string;
|
|
19
|
+
subject: (string | number)[];
|
|
20
|
+
verified: boolean;
|
|
21
|
+
detail: unknown;
|
|
22
|
+
}
|
|
23
|
+
export interface Evidence {
|
|
24
|
+
protocol_revision: number;
|
|
25
|
+
blueprint_digest: string;
|
|
26
|
+
deployment_digest: string;
|
|
27
|
+
checks: Check[];
|
|
28
|
+
effective_bounds: Record<string, unknown>;
|
|
29
|
+
clamps: unknown[];
|
|
30
|
+
optional_extensions_retained: string[];
|
|
31
|
+
not_verified: string[];
|
|
32
|
+
}
|
|
33
|
+
export declare function reconcile(bp: blueprint.Blueprint, dep: deployment.Deployment, inputs: Inputs): {
|
|
34
|
+
ok: true;
|
|
35
|
+
v: Evidence;
|
|
36
|
+
} | Failure;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import * as blueprint from './blueprint.js';
|
|
2
|
+
import * as deployment from './deployment.js';
|
|
3
|
+
import * as negotiation from './negotiation.js';
|
|
4
|
+
import * as algebra from './bounds_algebra.js';
|
|
5
|
+
import * as signature from './signature.js';
|
|
6
|
+
import * as digest from './digest.js';
|
|
7
|
+
import { validate } from './registry_engine.js';
|
|
8
|
+
import { member, memberString } from './corpus.js';
|
|
9
|
+
import { plain, jsonValue } from './plain.js';
|
|
10
|
+
import { isValue } from './value.js';
|
|
11
|
+
const HOST_OWNED = ['tenancy', 'live_policy', 'authority', 'effect_ownership', 'execution', 'billing', 'evaluation_truth'];
|
|
12
|
+
const CLASSIFICATION = ['public', 'internal', 'confidential', 'restricted'];
|
|
13
|
+
function failure(e, subject = []) { return { ok: false, e, subject }; }
|
|
14
|
+
function lift(bp) {
|
|
15
|
+
const b = plain(bp.value);
|
|
16
|
+
const sites = [b.classification_ceiling, b.output_contract.classification_ceiling, ...b.input_ports.map((p) => p.classification_ceiling), ...b.output_ports.map((p) => p.classification_ceiling), ...b.capability_requirements.map((p) => p.classification_ceiling)];
|
|
17
|
+
const strongest = (values, order) => order[Math.max(0, ...values.map(x => order.indexOf(x)))];
|
|
18
|
+
return { ...b.ceilings, classification_ceiling: { ordinal: strongest(sites, CLASSIFICATION), markers: [] }, disclosure_ceiling: 'full', approval_trait: strongest(b.capability_requirements.map((x) => x.approval_trait), ['none', 'human_required', 'separated_human_required']), authority_trait: strongest(b.capability_requirements.map((x) => x.authority_trait), ['none', 'local_policy', 'external_authority_required']), effect_impact_ceiling: strongest([...b.capability_requirements, ...b.effect_intents].map((x) => x.impact_class), ['ordinary', 'money', 'authority', 'secret']) };
|
|
19
|
+
}
|
|
20
|
+
export function reconcile(bp, dep, inputs) {
|
|
21
|
+
if (!bp || !isValue(bp.value))
|
|
22
|
+
return failure('invalid_type', ['blueprint']);
|
|
23
|
+
if (!dep || !isValue(dep.value))
|
|
24
|
+
return failure('invalid_type', ['deployment']);
|
|
25
|
+
if (!inputs || typeof inputs !== 'object')
|
|
26
|
+
return failure('invalid_type', ['inputs']);
|
|
27
|
+
for (const key of ['support', 'observations', 'hostBounds'])
|
|
28
|
+
if (!inputs[key] || typeof inputs[key] !== 'object')
|
|
29
|
+
return failure('invalid_type', ['inputs', key === 'hostBounds' ? 'host_bounds' : key]);
|
|
30
|
+
if (!Array.isArray(inputs.keys))
|
|
31
|
+
return failure('invalid_type', ['inputs', 'keys']);
|
|
32
|
+
for (let i = 0; i < inputs.keys.length; i++)
|
|
33
|
+
if (!inputs.keys[i] || typeof inputs.keys[i] !== 'object')
|
|
34
|
+
return failure('invalid_type', ['inputs', 'keys', i]);
|
|
35
|
+
if (!['deny', 'acknowledge'].includes(inputs.protectedClamp))
|
|
36
|
+
return failure('invalid_type', ['inputs', 'protected_clamp']);
|
|
37
|
+
const checks = [];
|
|
38
|
+
const checked = (surface, subject, verified = true, detail = null) => checks.push({ surface, subject: [subject], verified, detail });
|
|
39
|
+
const artifacts = [['blueprint', bp, blueprint], ['deployment', dep, deployment]];
|
|
40
|
+
// Stage order is part of the verification contract.
|
|
41
|
+
for (const [name, artifact, mod] of artifacts) {
|
|
42
|
+
if (artifact.value.t !== 'obj')
|
|
43
|
+
return failure('invalid_type', [name]);
|
|
44
|
+
const result = mod.canonicalBytes(artifact); // stage: canonical
|
|
45
|
+
if (!result.ok)
|
|
46
|
+
return failure(result.e, [name]);
|
|
47
|
+
checked('canonical', name);
|
|
48
|
+
}
|
|
49
|
+
for (const [name, artifact, mod] of artifacts) {
|
|
50
|
+
const result = mod.verifyContentDigest(artifact); // stage: digest
|
|
51
|
+
if (!result.ok)
|
|
52
|
+
return failure(result.e, [name]);
|
|
53
|
+
checked('digest', name, true, mod.contentDigest(artifact));
|
|
54
|
+
}
|
|
55
|
+
const outcomes = [];
|
|
56
|
+
for (const [name, artifact] of artifacts) {
|
|
57
|
+
const result = negotiation.negotiate(artifact.value, inputs.support); // stage: negotiation
|
|
58
|
+
if (!result.ok)
|
|
59
|
+
return failure(result.e, [name, ...(result.e === 'protocol_revision_unsupported' ? ['protocol_revision'] : result.e === 'required_core_field_unsupported' || result.e === 'required_core_field_not_digest_covered' ? ['required_core_fields'] : [])]);
|
|
60
|
+
outcomes.push(result.v);
|
|
61
|
+
checked('negotiation', name);
|
|
62
|
+
}
|
|
63
|
+
for (const outcome of outcomes) {
|
|
64
|
+
for (const ns of outcome.quarantinedExtensions)
|
|
65
|
+
checked('extensions', ns, false, 'quarantined');
|
|
66
|
+
for (const ns of outcome.optionalRetained)
|
|
67
|
+
checked('extensions', ns, false, 'retained');
|
|
68
|
+
}
|
|
69
|
+
for (const [name, artifact, mod] of artifacts) {
|
|
70
|
+
const result = validate(mod.table(), artifact.value); // stage: structure
|
|
71
|
+
if (!result.ok)
|
|
72
|
+
return failure(result.e, [name, ...(result.subject ?? [])]);
|
|
73
|
+
checked('structure', name);
|
|
74
|
+
}
|
|
75
|
+
for (let i = 0; i < artifacts.length; i++) {
|
|
76
|
+
const [name, artifact, mod] = artifacts[i];
|
|
77
|
+
const result = mod.scan(artifact.value, new Set(outcomes[i].criticalExtensions)); // stage: portability
|
|
78
|
+
if (!result.ok)
|
|
79
|
+
return failure(result.e, [name]);
|
|
80
|
+
checked('portability', name);
|
|
81
|
+
}
|
|
82
|
+
for (const [name, artifact, mod] of artifacts) {
|
|
83
|
+
const entries = member(artifact.value, 'signatures');
|
|
84
|
+
const signatures = entries?.t === 'arr' ? entries.v : [];
|
|
85
|
+
for (let i = 0; i < signatures.length; i++) {
|
|
86
|
+
const result = signature.verify(signatures[i], inputs.keys); // stage: signatures
|
|
87
|
+
if (!result.ok)
|
|
88
|
+
return failure(result.e, [name, 'signatures', i, ...(result.subject ?? [])]);
|
|
89
|
+
if (digest.toTagged(result.v.contentDigest) !== mod.contentDigest(artifact))
|
|
90
|
+
return failure('digest_mismatch', [name, 'signatures', i]);
|
|
91
|
+
}
|
|
92
|
+
checked('signatures', name, signatures.length > 0, signatures.length ? { key_ids: [...new Set(signatures.map(x => { const a = signature.attributes(x); if (!a.ok)
|
|
93
|
+
throw Error('signature invariant'); return a.v.keyId; }))] } : 'no_signatures_present');
|
|
94
|
+
}
|
|
95
|
+
const binding = deployment.verifyBinding(dep, bp, inputs.observations); // stage: bind
|
|
96
|
+
if (!binding.ok)
|
|
97
|
+
return failure(binding.e, ['deployment', ...(binding.subject ?? [])]);
|
|
98
|
+
const bindings = member(dep.value, 'tool_bindings');
|
|
99
|
+
const names = bindings.v.map(x => memberString(x, 'logical_operation'));
|
|
100
|
+
const staleness = names.length > 0 && inputs.observations.now !== null && inputs.observations.maxAttestationAgeMs !== null;
|
|
101
|
+
const descriptors = names.length > 0 && names.every(x => Object.hasOwn(inputs.observations.observed, x));
|
|
102
|
+
const extra = [['binding_staleness', staleness], ['binding_descriptors', descriptors]];
|
|
103
|
+
const skipped = extra.filter(x => !x[1]).map(x => x[0]);
|
|
104
|
+
checked('bind', 'deployment', skipped.length === 0, { checked: ['release_binding', 'binding_completeness', 'effect_recovery', ...extra.filter(x => x[1]).map(x => x[0])], not_verified: skipped });
|
|
105
|
+
const depBounds = plain(member(dep.value, 'host_bounds'));
|
|
106
|
+
depBounds.classification_ceiling = { ordinal: depBounds.classification_ceiling, markers: [] };
|
|
107
|
+
const bounds = algebra.intersect(lift(bp), depBounds, inputs.hostBounds, inputs.protectedClamp); // stage: bounds
|
|
108
|
+
if (!bounds.ok)
|
|
109
|
+
return failure(bounds.e, bounds.subject ?? []);
|
|
110
|
+
checked('bounds', 'bounds');
|
|
111
|
+
const clamps = jsonValue(bounds.v.clamps.map(c => ({ field: c.field, class: c.cls, unit: c.cls === 'protected' ? 'ordinal' : c.field === 'max_cost' ? 'money' : c.field === 'max_elapsed_ms' ? 'millisecond' : c.field === 'max_tokens' ? 'token' : 'count', requested: c.requested, effective: c.effective, source: c.source, acknowledged: c.acknowledged }))).map((c) => { delete c.cls; return c; });
|
|
112
|
+
for (const clamp of clamps)
|
|
113
|
+
checked('bounds', clamp.field, true, clamp);
|
|
114
|
+
return { ok: true, v: { protocol_revision: plain(member(bp.value, 'protocol_revision')), blueprint_digest: blueprint.contentDigest(bp), deployment_digest: deployment.contentDigest(dep), checks, effective_bounds: bounds.v.effective, clamps, optional_extensions_retained: [...new Set(outcomes.flatMap(o => o.optionalRetained))], not_verified: [...new Set([...HOST_OWNED, 'signature_created_at', 'lifecycle_state', ...checks.flatMap(c => c.verified ? [] : [c.surface]), ...skipped])] } };
|
|
115
|
+
}
|
|
@@ -83,11 +83,20 @@ function entries() {
|
|
|
83
83
|
namespace: "com.example/federation",
|
|
84
84
|
owner: "Agent Blueprint Protocol",
|
|
85
85
|
criticality: "critical",
|
|
86
|
-
state: "
|
|
86
|
+
state: "deprecated",
|
|
87
87
|
schema_digest: taggedFederationDigest(),
|
|
88
88
|
a2a_uri: "https://example.com/extensions/federation",
|
|
89
89
|
promoted_at_revision: null,
|
|
90
90
|
},
|
|
91
|
+
{
|
|
92
|
+
namespace: "io.github.baselabs/federation",
|
|
93
|
+
owner: "Agent Blueprint Protocol",
|
|
94
|
+
criticality: "critical",
|
|
95
|
+
state: "active",
|
|
96
|
+
schema_digest: taggedFederationDigest(),
|
|
97
|
+
a2a_uri: "https://baselabs.github.io/agent_blueprint_protocol/extensions/federation",
|
|
98
|
+
promoted_at_revision: null,
|
|
99
|
+
},
|
|
91
100
|
];
|
|
92
101
|
}
|
|
93
102
|
export function registeredExtensions() {
|
|
@@ -13,12 +13,14 @@ export type Check = (value: Value) => {
|
|
|
13
13
|
} | {
|
|
14
14
|
ok: false;
|
|
15
15
|
e: string;
|
|
16
|
+
subject?: (string | number)[];
|
|
16
17
|
};
|
|
17
18
|
export type RootHook = (members: Map<string, Value>) => {
|
|
18
19
|
ok: true;
|
|
19
20
|
} | {
|
|
20
21
|
ok: false;
|
|
21
22
|
e: string;
|
|
23
|
+
subject?: (string | number)[];
|
|
22
24
|
};
|
|
23
25
|
export interface Spec {
|
|
24
26
|
name?: string;
|
|
@@ -35,6 +37,7 @@ export type VResult = {
|
|
|
35
37
|
} | {
|
|
36
38
|
ok: false;
|
|
37
39
|
e: string;
|
|
40
|
+
subject?: (string | number)[];
|
|
38
41
|
};
|
|
39
42
|
export declare function field(name: string, kind: Kind, opts?: Partial<Spec>): Spec;
|
|
40
43
|
export declare function validate(table: Spec[], value: Value): VResult;
|
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
|
|
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) {
|
|
@@ -29,13 +21,13 @@ export function validate(table, value) {
|
|
|
29
21
|
const tableNames = new Set(table.map((spec) => spec.name));
|
|
30
22
|
for (const [name] of members) {
|
|
31
23
|
if (!tableNames.has(name))
|
|
32
|
-
return { ok: false, e: "unknown_member" };
|
|
24
|
+
return { ok: false, e: "unknown_member", subject: [] };
|
|
33
25
|
}
|
|
34
26
|
const present = new Set(members.map(([name]) => name));
|
|
35
27
|
for (const spec of table) {
|
|
36
28
|
// Table specs always come from field() (named); the ! mirrors that invariant.
|
|
37
29
|
if (spec.required && !present.has(spec.name))
|
|
38
|
-
return { ok: false, e: "missing_required_field" };
|
|
30
|
+
return { ok: false, e: "missing_required_field", subject: [spec.name] };
|
|
39
31
|
}
|
|
40
32
|
// Every table stage shares one walk: find the first spec (in table order)
|
|
41
33
|
// whose present value fails.
|
|
@@ -46,7 +38,7 @@ export function validate(table, value) {
|
|
|
46
38
|
continue;
|
|
47
39
|
const failure = judge(spec, found);
|
|
48
40
|
if (failure !== null)
|
|
49
|
-
return { ok: false, e: failure.e };
|
|
41
|
+
return { ok: false, e: failure.e, subject: [spec.name, ...(failure.subject ?? [])] };
|
|
50
42
|
}
|
|
51
43
|
return { ok: true };
|
|
52
44
|
};
|
|
@@ -70,10 +62,30 @@ export function validate(table, value) {
|
|
|
70
62
|
continue;
|
|
71
63
|
const result = spec.rootHook(memberMap);
|
|
72
64
|
if (!result.ok)
|
|
73
|
-
return result;
|
|
65
|
+
return { ...result, subject: [spec.name, ...(result.subject ?? [])] };
|
|
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) {
|
|
@@ -82,7 +94,7 @@ function specConstraint(spec, value) {
|
|
|
82
94
|
}
|
|
83
95
|
if (spec.check !== undefined) {
|
|
84
96
|
const result = spec.check(value);
|
|
85
|
-
return result.ok ? null :
|
|
97
|
+
return result.ok ? null : result;
|
|
86
98
|
}
|
|
87
99
|
return null;
|
|
88
100
|
}
|
|
@@ -125,10 +137,10 @@ function recurse(kind, value) {
|
|
|
125
137
|
if (typeof kind === "object" && "array" in kind) {
|
|
126
138
|
if (value.t !== "arr")
|
|
127
139
|
return { ok: true };
|
|
128
|
-
for (const item of value.v) {
|
|
140
|
+
for (const [index, item] of value.v.entries()) {
|
|
129
141
|
const result = elementOk(kind.array, item);
|
|
130
142
|
if (!result.ok)
|
|
131
|
-
return result;
|
|
143
|
+
return { ...result, subject: [index, ...(result.subject ?? [])] };
|
|
132
144
|
}
|
|
133
145
|
return { ok: true };
|
|
134
146
|
}
|
|
@@ -144,7 +156,7 @@ function elementOk(spec, value) {
|
|
|
144
156
|
return { ok: false, e: "invalid_type" };
|
|
145
157
|
const constraint = specConstraint(spec, value);
|
|
146
158
|
if (constraint !== null)
|
|
147
|
-
return
|
|
159
|
+
return constraint;
|
|
148
160
|
return recurse(spec.kind, value);
|
|
149
161
|
}
|
|
150
162
|
// ---- kinds --------------------------------------------------------------------------
|
|
@@ -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) =>
|
|
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] &&
|
|
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
|
+
};
|
package/dist/verifier/report.js
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
34
|
+
return encoded;
|
|
28
35
|
return encoded.v;
|
|
29
36
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { encode } from './canonical.js';
|
|
2
|
+
import { tagged } from './plain.js';
|
|
3
|
+
import { project } from './runner.js';
|
|
4
|
+
import { memberString } from './corpus.js';
|
|
5
|
+
export function canonical(value) {
|
|
6
|
+
const result = encode(tagged(value));
|
|
7
|
+
if (!result.ok)
|
|
8
|
+
throw new TypeError(result.e);
|
|
9
|
+
return result.v;
|
|
10
|
+
}
|
|
11
|
+
export function resultsDocument(corpus) {
|
|
12
|
+
return { format: 'agent-blueprint-protocol-conformance-results', corpus_digest: corpus.identity, registry_digest: memberString(corpus.index, 'registry_digest'), results: corpus.cases.flatMap(f => f.cases).sort((a, b) => Buffer.compare(Buffer.from(a.id), Buffer.from(b.id))).map(c => ({ id: c.id, surface: c.surface, result: project(c, corpus.data, corpus.raws) })) };
|
|
13
|
+
}
|
|
@@ -1,81 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 = Object.create(null);
|
|
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;
|
|
@@ -16,5 +20,7 @@ export type SurfaceResult = {
|
|
|
16
20
|
} | {
|
|
17
21
|
ok: false;
|
|
18
22
|
e: string;
|
|
23
|
+
subject?: (string | number)[];
|
|
19
24
|
};
|
|
20
25
|
export { str, int, float, nil };
|
|
26
|
+
export declare function project(caseObj: CaseObj, data: Map<string, Value>, raws: Map<string, Buffer>): Record<string, unknown>;
|