@gtrabanco/agentic-workflow-schema 3.3.0 → 3.5.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/README.es.md +549 -3
- package/README.md +539 -3
- package/dist/canonical-json.d.ts +60 -0
- package/dist/canonical-json.js +119 -0
- package/dist/index.d.ts +263 -2
- package/dist/index.js +587 -52
- package/dist/pre-execution-contract.d.ts +175 -0
- package/dist/pre-execution-contract.js +676 -0
- package/dist/pre-execution-vectors.d.ts +19 -0
- package/dist/pre-execution-vectors.js +35 -0
- package/dist/pre-execution.d.ts +363 -0
- package/dist/pre-execution.js +838 -0
- package/dist/sha256.d.ts +43 -0
- package/dist/sha256.js +189 -0
- package/dist/verification-contract.d.ts +294 -0
- package/dist/verification-contract.js +1229 -0
- package/package.json +21 -3
- package/pre-execution-artifact-snapshot.schema.json +383 -0
- package/pre-execution-review-receipt.schema.json +457 -0
- package/verification-plan.schema.json +197 -0
- package/verification-receipt.schema.json +309 -0
package/dist/sha256.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHA-256 for the package's digest surface.
|
|
3
|
+
*
|
|
4
|
+
* Two entry points over one implementation contract:
|
|
5
|
+
* - `sha256Hex` (async, Web Crypto) — the historical path the published candidate
|
|
6
|
+
* and verification digests use;
|
|
7
|
+
* - `sha256HexSync` — the same function over the same bytes, needed because
|
|
8
|
+
* `buildPreExecutionArtifactSnapshot` derives digests from caller-supplied
|
|
9
|
+
* document text in ONE synchronous pass (feature 28 AC2): a builder that had
|
|
10
|
+
* to await per artifact row would either force the whole pre-execution API
|
|
11
|
+
* async or hash the wrong bytes when a caller mutated content mid-flight.
|
|
12
|
+
* Since the fold of F67 the pre-execution family uses the SYNC path end to end —
|
|
13
|
+
* builder, canonicalizers, digests, blessing and freshness comparator answer in
|
|
14
|
+
* one calling style, because a half-async family forces `await` ceremony on every
|
|
15
|
+
* caller of a contract whose bytes are already in hand.
|
|
16
|
+
*
|
|
17
|
+
* Both return one identical lowercase 64-hex digest for identical bytes:
|
|
18
|
+
* `test/pre-execution-canonical.test.mjs` pins that agreement over an
|
|
19
|
+
* ASCII/multibyte/oversized corpus — the async path against `node:crypto` and,
|
|
20
|
+
* since feature 28 P17, the host-native sync path, the pure-JS sync path and the
|
|
21
|
+
* WebCrypto async path against each other — so no path can silently drift.
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* FIPS 180-4 SHA-256 over raw bytes. The message-schedule buffer is reused across
|
|
25
|
+
* every 64-byte block of ONE call, and the padded tail is written into a scratch
|
|
26
|
+
* block instead of copying the whole message. The buffers themselves are allocated
|
|
27
|
+
* per call (`h`, `w`, the padding block, the digest): what this function keeps
|
|
28
|
+
* allocation-free is the per-block work, not the repeated hashing across calls
|
|
29
|
+
* (C9, P16 fold — the sentence used to claim the latter, which is the kind of
|
|
30
|
+
* comment↔code drift this unit's own AC15 exists to refuse).
|
|
31
|
+
*/
|
|
32
|
+
export declare function sha256Bytes(message: Uint8Array): Uint8Array;
|
|
33
|
+
/**
|
|
34
|
+
* Lowercase 64-hex SHA-256 of UTF-8 bytes, computed without awaiting.
|
|
35
|
+
*
|
|
36
|
+
* Routed: the host's native SHA-256 where the host exposes one, this package's
|
|
37
|
+
* pure-JS FIPS 180-4 core otherwise. Both branches hash the same UTF-8 bytes
|
|
38
|
+
* and emit the same lowercase 64-hex string — the guarantee AC21 states and the
|
|
39
|
+
* three-path case in `test/pre-execution-canonical.test.mjs` pins.
|
|
40
|
+
*/
|
|
41
|
+
export declare function sha256HexSync(data: string): string;
|
|
42
|
+
/** D4 — SHA-256 hex digest (async via Web Crypto). Same bytes as the sync path. */
|
|
43
|
+
export declare function sha256Hex(data: string): Promise<string>;
|
package/dist/sha256.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHA-256 for the package's digest surface.
|
|
3
|
+
*
|
|
4
|
+
* Two entry points over one implementation contract:
|
|
5
|
+
* - `sha256Hex` (async, Web Crypto) — the historical path the published candidate
|
|
6
|
+
* and verification digests use;
|
|
7
|
+
* - `sha256HexSync` — the same function over the same bytes, needed because
|
|
8
|
+
* `buildPreExecutionArtifactSnapshot` derives digests from caller-supplied
|
|
9
|
+
* document text in ONE synchronous pass (feature 28 AC2): a builder that had
|
|
10
|
+
* to await per artifact row would either force the whole pre-execution API
|
|
11
|
+
* async or hash the wrong bytes when a caller mutated content mid-flight.
|
|
12
|
+
* Since the fold of F67 the pre-execution family uses the SYNC path end to end —
|
|
13
|
+
* builder, canonicalizers, digests, blessing and freshness comparator answer in
|
|
14
|
+
* one calling style, because a half-async family forces `await` ceremony on every
|
|
15
|
+
* caller of a contract whose bytes are already in hand.
|
|
16
|
+
*
|
|
17
|
+
* Both return one identical lowercase 64-hex digest for identical bytes:
|
|
18
|
+
* `test/pre-execution-canonical.test.mjs` pins that agreement over an
|
|
19
|
+
* ASCII/multibyte/oversized corpus — the async path against `node:crypto` and,
|
|
20
|
+
* since feature 28 P17, the host-native sync path, the pure-JS sync path and the
|
|
21
|
+
* WebCrypto async path against each other — so no path can silently drift.
|
|
22
|
+
*/
|
|
23
|
+
const K = [
|
|
24
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
25
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
26
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
27
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
28
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
29
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
30
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
31
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
32
|
+
];
|
|
33
|
+
const HEX = "0123456789abcdef";
|
|
34
|
+
const _encoder = new TextEncoder();
|
|
35
|
+
function rotr(x, n) {
|
|
36
|
+
return (x >>> n) | (x << (32 - n));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* FIPS 180-4 SHA-256 over raw bytes. The message-schedule buffer is reused across
|
|
40
|
+
* every 64-byte block of ONE call, and the padded tail is written into a scratch
|
|
41
|
+
* block instead of copying the whole message. The buffers themselves are allocated
|
|
42
|
+
* per call (`h`, `w`, the padding block, the digest): what this function keeps
|
|
43
|
+
* allocation-free is the per-block work, not the repeated hashing across calls
|
|
44
|
+
* (C9, P16 fold — the sentence used to claim the latter, which is the kind of
|
|
45
|
+
* comment↔code drift this unit's own AC15 exists to refuse).
|
|
46
|
+
*/
|
|
47
|
+
export function sha256Bytes(message) {
|
|
48
|
+
const h = new Uint32Array([
|
|
49
|
+
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
|
|
50
|
+
]);
|
|
51
|
+
const w = new Uint32Array(64);
|
|
52
|
+
// The contract's own ceilings (4 MiB per artifact, 64 KiB per payload) keep the
|
|
53
|
+
// length in the low 32 bits, so the high word is always 0 here; it is computed
|
|
54
|
+
// rather than assumed so a future budget raise cannot truncate the padding.
|
|
55
|
+
const bitLengthHigh = Math.floor(message.length / 0x20000000);
|
|
56
|
+
const bitLengthLow = (message.length % 0x20000000) * 8;
|
|
57
|
+
const compress = (block, offset) => {
|
|
58
|
+
for (let i = 0; i < 16; i++) {
|
|
59
|
+
const p = offset + i * 4;
|
|
60
|
+
w[i] = ((block[p] << 24) | (block[p + 1] << 16) | (block[p + 2] << 8) | block[p + 3]) >>> 0;
|
|
61
|
+
}
|
|
62
|
+
for (let i = 16; i < 64; i++) {
|
|
63
|
+
const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >>> 3);
|
|
64
|
+
const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >>> 10);
|
|
65
|
+
w[i] = (w[i - 16] + (s0 >>> 0) + w[i - 7] + (s1 >>> 0)) >>> 0;
|
|
66
|
+
}
|
|
67
|
+
let [a, b, c, d, e, f, g, hh] = h;
|
|
68
|
+
for (let i = 0; i < 64; i++) {
|
|
69
|
+
const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
70
|
+
const ch = ((e & f) ^ (~e & g)) >>> 0;
|
|
71
|
+
const temp1 = (hh + (S1 >>> 0) + ch + K[i] + w[i]) >>> 0;
|
|
72
|
+
const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
73
|
+
const maj = ((a & b) ^ (a & c) ^ (b & c)) >>> 0;
|
|
74
|
+
const temp2 = ((S0 >>> 0) + maj) >>> 0;
|
|
75
|
+
hh = g;
|
|
76
|
+
g = f;
|
|
77
|
+
f = e;
|
|
78
|
+
e = (d + temp1) >>> 0;
|
|
79
|
+
d = c;
|
|
80
|
+
c = b;
|
|
81
|
+
b = a;
|
|
82
|
+
a = (temp1 + temp2) >>> 0;
|
|
83
|
+
}
|
|
84
|
+
h[0] = (h[0] + a) >>> 0;
|
|
85
|
+
h[1] = (h[1] + b) >>> 0;
|
|
86
|
+
h[2] = (h[2] + c) >>> 0;
|
|
87
|
+
h[3] = (h[3] + d) >>> 0;
|
|
88
|
+
h[4] = (h[4] + e) >>> 0;
|
|
89
|
+
h[5] = (h[5] + f) >>> 0;
|
|
90
|
+
h[6] = (h[6] + g) >>> 0;
|
|
91
|
+
h[7] = (h[7] + hh) >>> 0;
|
|
92
|
+
};
|
|
93
|
+
const fullBlocks = Math.floor(message.length / 64);
|
|
94
|
+
for (let i = 0; i < fullBlocks; i++)
|
|
95
|
+
compress(message, i * 64);
|
|
96
|
+
const tail = message.length % 64;
|
|
97
|
+
// One or two padding blocks: 0x80, zeros, then the 64-bit big-endian length.
|
|
98
|
+
const padLength = tail < 56 ? 64 : 128;
|
|
99
|
+
const pad = new Uint8Array(padLength);
|
|
100
|
+
pad.set(message.subarray(fullBlocks * 64), 0);
|
|
101
|
+
pad[tail] = 0x80;
|
|
102
|
+
pad[padLength - 8] = (bitLengthHigh >>> 24) & 0xff;
|
|
103
|
+
pad[padLength - 7] = (bitLengthHigh >>> 16) & 0xff;
|
|
104
|
+
pad[padLength - 6] = (bitLengthHigh >>> 8) & 0xff;
|
|
105
|
+
pad[padLength - 5] = bitLengthHigh & 0xff;
|
|
106
|
+
pad[padLength - 4] = (bitLengthLow >>> 24) & 0xff;
|
|
107
|
+
pad[padLength - 3] = (bitLengthLow >>> 16) & 0xff;
|
|
108
|
+
pad[padLength - 2] = (bitLengthLow >>> 8) & 0xff;
|
|
109
|
+
pad[padLength - 1] = bitLengthLow & 0xff;
|
|
110
|
+
for (let i = 0; i < padLength; i += 64)
|
|
111
|
+
compress(pad, i);
|
|
112
|
+
const out = new Uint8Array(32);
|
|
113
|
+
for (let i = 0; i < 8; i++) {
|
|
114
|
+
out[i * 4] = (h[i] >>> 24) & 0xff;
|
|
115
|
+
out[i * 4 + 1] = (h[i] >>> 16) & 0xff;
|
|
116
|
+
out[i * 4 + 2] = (h[i] >>> 8) & 0xff;
|
|
117
|
+
out[i * 4 + 3] = h[i] & 0xff;
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The native path, or `null` when this host exposes none.
|
|
123
|
+
*
|
|
124
|
+
* Sourced through `globalThis.process?.getBuiltinModule?.("crypto")` — the
|
|
125
|
+
* presence-check AC21 names — because the package targets browsers too and may
|
|
126
|
+
* be bundled by a toolchain that leaves `crypto` un-resolvable. The duck-typed
|
|
127
|
+
* `NativeCrypto` interface above is what keeps that lookup type-checked without
|
|
128
|
+
* a static `node:` specifier and without `@types/node` (AC21).
|
|
129
|
+
*
|
|
130
|
+
* Deliberately NOT cached in a module-level variable: a host that answers once
|
|
131
|
+
* can stop answering later (bundle moved between runtimes, the builtin
|
|
132
|
+
* unregistered), and a cached verdict — either way — is a wrong-host assumption
|
|
133
|
+
* that would either strand Node on the JS path or throw in a browser. The
|
|
134
|
+
* lookup is three `typeof` checks and one guarded call; measured against the
|
|
135
|
+
* digest it costs, caching is not worth the risk (unit 28 D36).
|
|
136
|
+
*/
|
|
137
|
+
function nativeSha256() {
|
|
138
|
+
const host = globalThis;
|
|
139
|
+
const getBuiltinModule = host.process?.getBuiltinModule;
|
|
140
|
+
if (typeof getBuiltinModule !== "function")
|
|
141
|
+
return null;
|
|
142
|
+
let builtin;
|
|
143
|
+
try {
|
|
144
|
+
builtin = getBuiltinModule.call(host.process, "crypto");
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
if (typeof builtin !== "object" || builtin === null)
|
|
150
|
+
return null;
|
|
151
|
+
const createHash = builtin.createHash;
|
|
152
|
+
if (typeof createHash !== "function")
|
|
153
|
+
return null;
|
|
154
|
+
return (bytes) => builtin.createHash("sha256").update(bytes).digest();
|
|
155
|
+
}
|
|
156
|
+
function toHex(bytes) {
|
|
157
|
+
let out = "";
|
|
158
|
+
for (const byte of bytes)
|
|
159
|
+
out += HEX[byte >> 4] + HEX[byte & 0x0f];
|
|
160
|
+
return out;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Lowercase 64-hex SHA-256 of UTF-8 bytes, computed without awaiting.
|
|
164
|
+
*
|
|
165
|
+
* Routed: the host's native SHA-256 where the host exposes one, this package's
|
|
166
|
+
* pure-JS FIPS 180-4 core otherwise. Both branches hash the same UTF-8 bytes
|
|
167
|
+
* and emit the same lowercase 64-hex string — the guarantee AC21 states and the
|
|
168
|
+
* three-path case in `test/pre-execution-canonical.test.mjs` pins.
|
|
169
|
+
*/
|
|
170
|
+
export function sha256HexSync(data) {
|
|
171
|
+
const bytes = _encoder.encode(data);
|
|
172
|
+
const native = nativeSha256();
|
|
173
|
+
if (native !== null) {
|
|
174
|
+
try {
|
|
175
|
+
return toHex(native(bytes));
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
// The binding was there a moment ago and failed now: answer from the
|
|
179
|
+
// JS core rather than propagating a host error out of a digest.
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return toHex(sha256Bytes(bytes));
|
|
183
|
+
}
|
|
184
|
+
/** D4 — SHA-256 hex digest (async via Web Crypto). Same bytes as the sync path. */
|
|
185
|
+
export async function sha256Hex(data) {
|
|
186
|
+
const buf = _encoder.encode(data);
|
|
187
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", buf);
|
|
188
|
+
return toHex(new Uint8Array(hashBuffer));
|
|
189
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical internal definition of the two staged-verification contracts.
|
|
3
|
+
*
|
|
4
|
+
* This module is the SINGLE source of the VerificationPlan v1 /
|
|
5
|
+
* VerificationReceipt v1 structural contract: the closed field lists,
|
|
6
|
+
* vocabularies, bounds, patterns and cross-field rules declared here are
|
|
7
|
+
* consumed by
|
|
8
|
+
* - runtime validation (`validateStructure` below, used by the two public
|
|
9
|
+
* authoritative entries in `index.ts`), and
|
|
10
|
+
* - the deterministic Draft-07 structural projection generator
|
|
11
|
+
* (`scripts/generate-verification-schemas.mjs`).
|
|
12
|
+
*
|
|
13
|
+
* It is package-internal: it is not re-exported from the package root and the
|
|
14
|
+
* published `exports` map does not expose it. The generated JSON Schemas are
|
|
15
|
+
* structural projections of this definition, never a second semantic authority.
|
|
16
|
+
*/
|
|
17
|
+
/** Field-level pattern rule shared by runtime validation and the projection. */
|
|
18
|
+
export interface VerificationPatternRule {
|
|
19
|
+
/** ECMA-262 source a valid value must match (negative lookaheads express prohibitions). */
|
|
20
|
+
readonly regex: string;
|
|
21
|
+
/** Runtime message tail; the field is always named through its path. */
|
|
22
|
+
readonly message: string;
|
|
23
|
+
}
|
|
24
|
+
export type VerificationFieldType = "const" | "enum" | "string" | "integer" | "boolean" | "stringArray" | "array" | "nullable";
|
|
25
|
+
/** One declared property of a contract object. */
|
|
26
|
+
export interface VerificationFieldSpec {
|
|
27
|
+
readonly key: string;
|
|
28
|
+
readonly type: VerificationFieldType;
|
|
29
|
+
readonly description: string;
|
|
30
|
+
/** `const` — the only permitted value. */
|
|
31
|
+
readonly value?: string;
|
|
32
|
+
/** `enum` — the closed vocabulary (also drives `notIn` cross rules). */
|
|
33
|
+
readonly enum?: readonly string[];
|
|
34
|
+
readonly minLength?: number;
|
|
35
|
+
readonly maxLength?: number;
|
|
36
|
+
/** Reject values containing NUL. */
|
|
37
|
+
readonly nulFree?: boolean;
|
|
38
|
+
/** Single pattern a valid string must match (digest/timestamp shapes). */
|
|
39
|
+
readonly pattern?: string;
|
|
40
|
+
readonly minimum?: number;
|
|
41
|
+
/** Ceiling for an integer field (D14 per-command timeout). */
|
|
42
|
+
readonly maximum?: number;
|
|
43
|
+
readonly exclusiveMinimum?: number;
|
|
44
|
+
/** `stringArray` — per-item bounds. */
|
|
45
|
+
readonly itemMaxLength?: number;
|
|
46
|
+
readonly itemNulFree?: boolean;
|
|
47
|
+
readonly maxItems?: number;
|
|
48
|
+
readonly minItems?: number;
|
|
49
|
+
/** `array`/`object`-typed members: name of the nested object spec. */
|
|
50
|
+
readonly specName?: string;
|
|
51
|
+
/** `nullable` — the non-null member type. */
|
|
52
|
+
readonly nullableOf?: "string" | "integer" | "object";
|
|
53
|
+
/**
|
|
54
|
+
* Specific code reported instead of the generic `invalid-value` when this
|
|
55
|
+
* field's *content* rule (pattern, NUL-free, const/enum vocabulary) fails.
|
|
56
|
+
* Capacity ceilings keep `limit-exceeded` and type errors keep `invalid-type`,
|
|
57
|
+
* so this only specializes "well-formed value" rules (D5 evidence references).
|
|
58
|
+
*/
|
|
59
|
+
readonly violationCode?: VerificationDiagnosticCodeV1;
|
|
60
|
+
/** Field-level pattern rules (path shapes). */
|
|
61
|
+
readonly rules?: readonly VerificationPatternRule[];
|
|
62
|
+
}
|
|
63
|
+
export type VerificationRuleKind = "exactly-one-non-null" | "null-when" | "non-null-when" | "unique" | "timestamp-order" | "calendar-roundtrip"
|
|
64
|
+
/** `fields` must stay ≤ `maximum` while `when` holds (a numeric field's value or an array field's length). */
|
|
65
|
+
| "maximum-when"
|
|
66
|
+
/** Sum of `fields` over `collection` items matching `when` stays ≤ `maximum`. */
|
|
67
|
+
| "stage-aggregate-budget"
|
|
68
|
+
/** `collection` must be `uniqueItems` as a Draft-07 floor (a family may enforce a stronger key offline). */
|
|
69
|
+
| "unique-items"
|
|
70
|
+
/**
|
|
71
|
+
* While `when` holds, each field in `fields` must be one of `values`. This is the
|
|
72
|
+
* one form of "a sibling field narrows my vocabulary" Draft 07 can state, so a
|
|
73
|
+
* consumer's editor refuses e.g. a SPEC-stage receipt carrying a Plan verdict
|
|
74
|
+
* instead of letting it pass a structural validation it cannot survive.
|
|
75
|
+
*/
|
|
76
|
+
| "enum-when";
|
|
77
|
+
/** One predicate over a sibling field's value. */
|
|
78
|
+
export interface VerificationWhenCondition {
|
|
79
|
+
readonly field: string;
|
|
80
|
+
readonly equals?: string;
|
|
81
|
+
readonly in?: readonly string[];
|
|
82
|
+
readonly notIn?: readonly string[];
|
|
83
|
+
/** Predicate holds while the sibling array carries at least this many rows. */
|
|
84
|
+
readonly minItems?: number;
|
|
85
|
+
}
|
|
86
|
+
/** Cross-field rule declared once; projected whenever Draft-07 can express it. */
|
|
87
|
+
export interface VerificationCrossRule {
|
|
88
|
+
readonly id: string;
|
|
89
|
+
readonly description: string;
|
|
90
|
+
/**
|
|
91
|
+
* D16 code to report instead of this kind's default (see `CROSS_RULE_DEFAULT_CODE`).
|
|
92
|
+
* A contract family may pin one of its OWN codes here (the pre-execution family
|
|
93
|
+
* pins `invalid-topology`), so the declared type accepts any string while the
|
|
94
|
+
* shared engine keeps its closed vocabulary for the codes it emits itself.
|
|
95
|
+
*/
|
|
96
|
+
readonly code?: VerificationDiagnosticCodeV1 | (string & {});
|
|
97
|
+
/** false → enforced by the authoritative validator only, disclosed in the projection. */
|
|
98
|
+
readonly projectable: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Where the runtime enforces the rule. Default `"walk"`: every structural pass
|
|
101
|
+
* (so a well-formedness validator refuses it too). `"binding"` marks a rule a
|
|
102
|
+
* well-formed document may violate — the projection still renders it, but only
|
|
103
|
+
* the family's binding authority (which blesses a verdict) applies it, so a
|
|
104
|
+
* recorded topology a plain review carried is refused exactly where it would
|
|
105
|
+
* be acted on.
|
|
106
|
+
*/
|
|
107
|
+
readonly enforcement?: "walk" | "binding";
|
|
108
|
+
readonly kind: VerificationRuleKind;
|
|
109
|
+
/**
|
|
110
|
+
* Predicate over a sibling field's value, or the conjunction of several under
|
|
111
|
+
* `allOf`. The conjunction exists because one real rule is discriminated by TWO
|
|
112
|
+
* siblings at once (`parentSpecSnapshotDigest` is required when `stage == plan`
|
|
113
|
+
* AND `unitKind == feature` — finding RS14); a family that needs to name the
|
|
114
|
+
* discriminator it fired on — `exactly-one-non-null` and `stage-aggregate-budget`
|
|
115
|
+
* report a row at `<when.field>` — stays on the single-condition form, because no
|
|
116
|
+
* single field names a conjunction.
|
|
117
|
+
*/
|
|
118
|
+
readonly when?: VerificationWhenCondition | {
|
|
119
|
+
readonly allOf: readonly VerificationWhenCondition[];
|
|
120
|
+
};
|
|
121
|
+
/** Constrained fields (`exactly-one-non-null`, `null-when`, `non-null-when`, timestamp/ calendar rules). */
|
|
122
|
+
readonly fields?: readonly string[];
|
|
123
|
+
/** `unique` — the array field the rule scans. */
|
|
124
|
+
readonly collection?: string;
|
|
125
|
+
/** `maximum-when` / `stage-aggregate-budget` — the declared ceiling. */
|
|
126
|
+
readonly maximum?: number;
|
|
127
|
+
/** `enum-when` — the only values each `fields` entry may take while `when` holds. */
|
|
128
|
+
readonly values?: readonly string[];
|
|
129
|
+
}
|
|
130
|
+
/** One contract object: its fields and its cross-field rules. */
|
|
131
|
+
export interface VerificationObjectSpec {
|
|
132
|
+
readonly description: string;
|
|
133
|
+
readonly fields: readonly VerificationFieldSpec[];
|
|
134
|
+
readonly rules: readonly VerificationCrossRule[];
|
|
135
|
+
}
|
|
136
|
+
/** A whole contract: root object spec, nested `$defs` specs, projection metadata. */
|
|
137
|
+
export interface VerificationContractSpec {
|
|
138
|
+
readonly contractId: string;
|
|
139
|
+
readonly fileName: string;
|
|
140
|
+
readonly title: string;
|
|
141
|
+
readonly description: string;
|
|
142
|
+
/** The authoritative public runtime entry point for this contract. */
|
|
143
|
+
readonly authority: string;
|
|
144
|
+
/** Label used by undeclared-key diagnostics (`plan` / `receipt`). */
|
|
145
|
+
readonly rootLabel: string;
|
|
146
|
+
readonly root: VerificationObjectSpec;
|
|
147
|
+
readonly objects: Readonly<Record<string, VerificationObjectSpec>>;
|
|
148
|
+
}
|
|
149
|
+
/** Contract ids, declared once; the package root re-exports them publicly. */
|
|
150
|
+
export declare const VERIFICATION_PLAN_CONTRACT_ID: "agentic-workflow/verification-plan@1";
|
|
151
|
+
export declare const VERIFICATION_RECEIPT_CONTRACT_ID: "agentic-workflow/verification-receipt@1";
|
|
152
|
+
/** Closed vocabularies, declared once; the root re-exports them publicly. */
|
|
153
|
+
export declare const VERIFICATION_STAGES: readonly ["fast", "full"];
|
|
154
|
+
export declare const VERIFICATION_COST_CLASSES: readonly ["cheap", "moderate", "expensive"];
|
|
155
|
+
export declare const VERIFICATION_COMMAND_STATUSES: readonly ["passed", "failed", "timed-out", "skipped", "infrastructure-error"];
|
|
156
|
+
export declare const VERIFICATION_VERDICTS: readonly ["pass", "fail", "incomplete"];
|
|
157
|
+
export declare const WORKING_DIRECTORY_POLICIES: readonly ["candidate-root", "relative-path"];
|
|
158
|
+
/**
|
|
159
|
+
* D14 — bounded usability: the SHAPE ceilings (cardinality + string length).
|
|
160
|
+
*
|
|
161
|
+
* Every number the validator enforces is read from this object, and the same
|
|
162
|
+
* object is published publicly so a consumer can size fixtures without
|
|
163
|
+
* restating a literal. `VERIFICATION_LIMITS` is extended with the payload
|
|
164
|
+
* budgets by P11 and the timeout budgets by P12; the canonical plan/receipt
|
|
165
|
+
* byte budgets and the aggregate stage sums are enforced at runtime and are
|
|
166
|
+
* listed here once those phases land.
|
|
167
|
+
*/
|
|
168
|
+
export declare const VERIFICATION_LIMITS: Readonly<{
|
|
169
|
+
readonly commands: 128;
|
|
170
|
+
readonly results: 128;
|
|
171
|
+
readonly argsPerCommand: 64;
|
|
172
|
+
readonly idChars: 128;
|
|
173
|
+
readonly pathChars: 1024;
|
|
174
|
+
readonly argChars: 4096;
|
|
175
|
+
readonly skipReasonChars: 1024;
|
|
176
|
+
readonly evidenceRefChars: 1024;
|
|
177
|
+
readonly planBytes: number;
|
|
178
|
+
readonly receiptBytes: number;
|
|
179
|
+
readonly fastCommandTimeoutMs: number;
|
|
180
|
+
readonly fastStageTimeoutMs: number;
|
|
181
|
+
readonly fullCommandTimeoutMs: number;
|
|
182
|
+
readonly fullStageTimeoutMs: number;
|
|
183
|
+
readonly diagnostics: 50;
|
|
184
|
+
}>;
|
|
185
|
+
/**
|
|
186
|
+
* D16 — the closed diagnostic vocabulary. Every validation failure row carries
|
|
187
|
+
* exactly one of these codes plus an RFC 6901 path; adding a code is a reviewed,
|
|
188
|
+
* versioned contract change, and no code ever names the submitted value.
|
|
189
|
+
*/
|
|
190
|
+
export declare const VERIFICATION_DIAGNOSTIC_CODES: readonly ["invalid-type", "missing-field", "unknown-field", "invalid-value", "limit-exceeded", "duplicate-id", "unknown-command", "invalid-order", "invalid-stage", "invalid-exit-state", "invalid-evidence", "invalid-skip", "invalid-fail-fast", "digest-mismatch", "verdict-mismatch", "budget-exceeded"];
|
|
191
|
+
export type VerificationDiagnosticCodeV1 = (typeof VERIFICATION_DIAGNOSTIC_CODES)[number];
|
|
192
|
+
/** One D16 failure row: a frozen code and the pointer to the offending location. */
|
|
193
|
+
export interface VerificationDiagnosticV1 {
|
|
194
|
+
readonly code: VerificationDiagnosticCodeV1;
|
|
195
|
+
/** RFC 6901 pointer over declared property names and decimal indices; `""` is the document root. */
|
|
196
|
+
readonly path: string;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Bounded diagnostic collector (D14/D16).
|
|
200
|
+
*
|
|
201
|
+
* Allocation is capped at `VERIFICATION_LIMITS.diagnostics`: past the ceiling the
|
|
202
|
+
* sink counts rows instead of building them, so an oversized payload can never
|
|
203
|
+
* make the validator allocate one diagnostic per byte it disliked. `count()` is
|
|
204
|
+
* the total number of failures seen (held + dropped) and is what the structural
|
|
205
|
+
* walk uses to decide whether anything failed — never the capped length.
|
|
206
|
+
*/
|
|
207
|
+
export interface VerificationDiagnosticSink {
|
|
208
|
+
push(code: VerificationDiagnosticCodeV1, path: string): void;
|
|
209
|
+
/** Failures seen so far, including the ones the ceiling dropped. */
|
|
210
|
+
count(): number;
|
|
211
|
+
/** Freeze the held rows and report whether the ceiling truncated them. */
|
|
212
|
+
finish(): {
|
|
213
|
+
readonly diagnostics: readonly VerificationDiagnosticV1[];
|
|
214
|
+
readonly truncated: boolean;
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
export declare function createVerificationDiagnosticSink(limit?: number): VerificationDiagnosticSink;
|
|
218
|
+
export declare const VERIFICATION_CONTRACT: Readonly<{
|
|
219
|
+
plan: VerificationContractSpec;
|
|
220
|
+
receipt: VerificationContractSpec;
|
|
221
|
+
}>;
|
|
222
|
+
/**
|
|
223
|
+
* Non-validating own-property projection of a contract value.
|
|
224
|
+
*
|
|
225
|
+
* `canonicalize*`/`digest*` run this first so a digest always describes the
|
|
226
|
+
* normalized DTO — never an accidental prototype value or an undeclared field.
|
|
227
|
+
* It performs no checks (callers validate first) and copies only declared own
|
|
228
|
+
* properties, so the walk is one pass with no regex and no error buffers.
|
|
229
|
+
*/
|
|
230
|
+
export declare function projectStructure(contract: VerificationContractSpec, spec: VerificationObjectSpec, value: unknown): unknown;
|
|
231
|
+
/**
|
|
232
|
+
* Capture the submitted document once, optionally bounded by `budgetBytes` of
|
|
233
|
+
* canonical form (F99): the capture aborts as soon as the running UTF-16 size
|
|
234
|
+
* passes the budget, so an illegal payload costs about the budget's worth of
|
|
235
|
+
* work instead of its own size. The abort reports the ROOT pointer — the byte
|
|
236
|
+
* budget outranks every shape ceiling and answers one root-path row (D16/F77).
|
|
237
|
+
*
|
|
238
|
+
* `measureExact` says whether the running size IS the canonical byte size: the
|
|
239
|
+
* document is pure ASCII (escapes are ASCII) and every leaf was measurable. A
|
|
240
|
+
* caller may then skip its own byte measure; anything else falls back to it.
|
|
241
|
+
*/
|
|
242
|
+
export type VerificationInputCapture = {
|
|
243
|
+
readonly ok: true;
|
|
244
|
+
readonly value: unknown;
|
|
245
|
+
readonly measureExact: boolean;
|
|
246
|
+
} | {
|
|
247
|
+
readonly ok: false;
|
|
248
|
+
readonly code: VerificationDiagnosticCodeV1;
|
|
249
|
+
readonly pointer: string;
|
|
250
|
+
};
|
|
251
|
+
export declare function captureVerificationInput(value: unknown, budgetBytes?: number): VerificationInputCapture;
|
|
252
|
+
/**
|
|
253
|
+
* The `when` predicates of one rule as a list: the single-condition form is the
|
|
254
|
+
* one-element case, so every reader handles exactly one shape.
|
|
255
|
+
*
|
|
256
|
+
* A rule with no `when` applies unconditionally; `stage-aggregate-budget` and
|
|
257
|
+
* `exactly-one-non-null` report the discriminator they fired on, which only the
|
|
258
|
+
* single-condition form can name (see `VerificationCrossRule.when`).
|
|
259
|
+
*/
|
|
260
|
+
export declare function whenConditions(when?: VerificationCrossRule["when"]): readonly VerificationWhenCondition[];
|
|
261
|
+
/**
|
|
262
|
+
* Validate one contract object against its spec, recording D16 diagnostics in
|
|
263
|
+
* `sink`, and return its normalized own-property DTO — or `undefined` when
|
|
264
|
+
* anything in this object (or below it) failed.
|
|
265
|
+
*
|
|
266
|
+
* Only own properties of declared keys are read, so inherited or prototype
|
|
267
|
+
* values can never be mistaken for contract data; the returned object is a
|
|
268
|
+
* fresh plain literal, so mutating the input afterwards cannot change it.
|
|
269
|
+
*
|
|
270
|
+
* Every path is an RFC 6901 JSON Pointer built from declared contract property
|
|
271
|
+
* names and decimal array indices (`/commands/3/id`; `""` is the document root),
|
|
272
|
+
* so a diagnostic identifies the offending location without naming — let alone
|
|
273
|
+
* echoing — the submitted value.
|
|
274
|
+
*/
|
|
275
|
+
export declare function validateStructure(contract: VerificationContractSpec, spec: VerificationObjectSpec, value: unknown, path: string, sink: VerificationDiagnosticSink): Record<string, unknown> | undefined;
|
|
276
|
+
/**
|
|
277
|
+
* Apply one cross-field rule to a captured, normalized document. Exported for a
|
|
278
|
+
* family's binding authority, which re-applies the `binding`-enforcement rules
|
|
279
|
+
* the shared walk deliberately skipped.
|
|
280
|
+
*/
|
|
281
|
+
export declare function applyCrossRule(spec: VerificationObjectSpec, rule: VerificationCrossRule, value: Record<string, unknown>, path: string, sink: VerificationDiagnosticSink): void;
|
|
282
|
+
/**
|
|
283
|
+
* Every cross rule that pins a diagnostic must pin a code the family publishes.
|
|
284
|
+
*
|
|
285
|
+
* `VerificationCrossRule.code` is widened to `string` on purpose — a contract family
|
|
286
|
+
* reports one of its OWN codes there — and `applyCrossRule` casts the value back to
|
|
287
|
+
* the closed code type without checking it, so the type said "closed vocabulary"
|
|
288
|
+
* while the runtime said nothing: a mistyped code, or one borrowed from another
|
|
289
|
+
* family, would reach a caller as a diagnostic no consumer can match (F71). This is
|
|
290
|
+
* the checked half of that cast, run against the declarations at load time, where
|
|
291
|
+
* the failure is a broken import rather than a wrong verdict. It answers the codes it
|
|
292
|
+
* verified so a caller can prove the scan was not vacuous.
|
|
293
|
+
*/
|
|
294
|
+
export declare function assertCrossRuleVocabulary(contracts: Record<string, VerificationContractSpec>, vocabulary: readonly string[], owner: string): readonly string[];
|