@gtrabanco/agentic-workflow-schema 3.2.0 → 3.4.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 +300 -3
- package/README.md +292 -3
- package/candidate-snapshot.schema.json +129 -0
- package/dist/index.d.ts +410 -0
- package/dist/index.js +1116 -1
- package/dist/verification-contract.d.ts +227 -0
- package/dist/verification-contract.js +1111 -0
- package/package.json +17 -3
- package/review-receipt.schema.json +130 -0
- package/verification-plan.schema.json +197 -0
- package/verification-receipt.schema.json +309 -0
|
@@ -0,0 +1,227 @@
|
|
|
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 (stage-scoped ceiling). */
|
|
65
|
+
| "maximum-when"
|
|
66
|
+
/** Sum of `fields` over `collection` items matching `when` stays ≤ `maximum`. */
|
|
67
|
+
| "stage-aggregate-budget";
|
|
68
|
+
/** Cross-field rule declared once; projected whenever Draft-07 can express it. */
|
|
69
|
+
export interface VerificationCrossRule {
|
|
70
|
+
readonly id: string;
|
|
71
|
+
readonly description: string;
|
|
72
|
+
/** D16 code to report instead of this kind's default (see `CROSS_RULE_DEFAULT_CODE`). */
|
|
73
|
+
readonly code?: VerificationDiagnosticCodeV1;
|
|
74
|
+
/** false → enforced by the authoritative validator only, disclosed in the projection. */
|
|
75
|
+
readonly projectable: boolean;
|
|
76
|
+
readonly kind: VerificationRuleKind;
|
|
77
|
+
/** Predicate over a sibling field's value. */
|
|
78
|
+
readonly when?: {
|
|
79
|
+
readonly field: string;
|
|
80
|
+
readonly equals?: string;
|
|
81
|
+
readonly in?: readonly string[];
|
|
82
|
+
readonly notIn?: readonly string[];
|
|
83
|
+
};
|
|
84
|
+
/** Constrained fields (`exactly-one-non-null`, `null-when`, `non-null-when`, timestamp/ calendar rules). */
|
|
85
|
+
readonly fields?: readonly string[];
|
|
86
|
+
/** `unique` — the array field the rule scans. */
|
|
87
|
+
readonly collection?: string;
|
|
88
|
+
/** `maximum-when` / `stage-aggregate-budget` — the declared ceiling. */
|
|
89
|
+
readonly maximum?: number;
|
|
90
|
+
}
|
|
91
|
+
/** One contract object: its fields and its cross-field rules. */
|
|
92
|
+
export interface VerificationObjectSpec {
|
|
93
|
+
readonly description: string;
|
|
94
|
+
readonly fields: readonly VerificationFieldSpec[];
|
|
95
|
+
readonly rules: readonly VerificationCrossRule[];
|
|
96
|
+
}
|
|
97
|
+
/** A whole contract: root object spec, nested `$defs` specs, projection metadata. */
|
|
98
|
+
export interface VerificationContractSpec {
|
|
99
|
+
readonly contractId: string;
|
|
100
|
+
readonly fileName: string;
|
|
101
|
+
readonly title: string;
|
|
102
|
+
readonly description: string;
|
|
103
|
+
/** The authoritative public runtime entry point for this contract. */
|
|
104
|
+
readonly authority: string;
|
|
105
|
+
/** Label used by undeclared-key diagnostics (`plan` / `receipt`). */
|
|
106
|
+
readonly rootLabel: string;
|
|
107
|
+
readonly root: VerificationObjectSpec;
|
|
108
|
+
readonly objects: Readonly<Record<string, VerificationObjectSpec>>;
|
|
109
|
+
}
|
|
110
|
+
/** Contract ids, declared once; the package root re-exports them publicly. */
|
|
111
|
+
export declare const VERIFICATION_PLAN_CONTRACT_ID: "agentic-workflow/verification-plan@1";
|
|
112
|
+
export declare const VERIFICATION_RECEIPT_CONTRACT_ID: "agentic-workflow/verification-receipt@1";
|
|
113
|
+
/** Closed vocabularies, declared once; the root re-exports them publicly. */
|
|
114
|
+
export declare const VERIFICATION_STAGES: readonly ["fast", "full"];
|
|
115
|
+
export declare const VERIFICATION_COST_CLASSES: readonly ["cheap", "moderate", "expensive"];
|
|
116
|
+
export declare const VERIFICATION_COMMAND_STATUSES: readonly ["passed", "failed", "timed-out", "skipped", "infrastructure-error"];
|
|
117
|
+
export declare const VERIFICATION_VERDICTS: readonly ["pass", "fail", "incomplete"];
|
|
118
|
+
export declare const WORKING_DIRECTORY_POLICIES: readonly ["candidate-root", "relative-path"];
|
|
119
|
+
/**
|
|
120
|
+
* D14 — bounded usability: the SHAPE ceilings (cardinality + string length).
|
|
121
|
+
*
|
|
122
|
+
* Every number the validator enforces is read from this object, and the same
|
|
123
|
+
* object is published publicly so a consumer can size fixtures without
|
|
124
|
+
* restating a literal. `VERIFICATION_LIMITS` is extended with the payload
|
|
125
|
+
* budgets by P11 and the timeout budgets by P12; the canonical plan/receipt
|
|
126
|
+
* byte budgets and the aggregate stage sums are enforced at runtime and are
|
|
127
|
+
* listed here once those phases land.
|
|
128
|
+
*/
|
|
129
|
+
export declare const VERIFICATION_LIMITS: Readonly<{
|
|
130
|
+
readonly commands: 128;
|
|
131
|
+
readonly results: 128;
|
|
132
|
+
readonly argsPerCommand: 64;
|
|
133
|
+
readonly idChars: 128;
|
|
134
|
+
readonly pathChars: 1024;
|
|
135
|
+
readonly argChars: 4096;
|
|
136
|
+
readonly skipReasonChars: 1024;
|
|
137
|
+
readonly evidenceRefChars: 1024;
|
|
138
|
+
readonly planBytes: number;
|
|
139
|
+
readonly receiptBytes: number;
|
|
140
|
+
readonly fastCommandTimeoutMs: number;
|
|
141
|
+
readonly fastStageTimeoutMs: number;
|
|
142
|
+
readonly fullCommandTimeoutMs: number;
|
|
143
|
+
readonly fullStageTimeoutMs: number;
|
|
144
|
+
readonly diagnostics: 50;
|
|
145
|
+
}>;
|
|
146
|
+
/**
|
|
147
|
+
* D16 — the closed diagnostic vocabulary. Every validation failure row carries
|
|
148
|
+
* exactly one of these codes plus an RFC 6901 path; adding a code is a reviewed,
|
|
149
|
+
* versioned contract change, and no code ever names the submitted value.
|
|
150
|
+
*/
|
|
151
|
+
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"];
|
|
152
|
+
export type VerificationDiagnosticCodeV1 = (typeof VERIFICATION_DIAGNOSTIC_CODES)[number];
|
|
153
|
+
/** One D16 failure row: a frozen code and the pointer to the offending location. */
|
|
154
|
+
export interface VerificationDiagnosticV1 {
|
|
155
|
+
readonly code: VerificationDiagnosticCodeV1;
|
|
156
|
+
/** RFC 6901 pointer over declared property names and decimal indices; `""` is the document root. */
|
|
157
|
+
readonly path: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Bounded diagnostic collector (D14/D16).
|
|
161
|
+
*
|
|
162
|
+
* Allocation is capped at `VERIFICATION_LIMITS.diagnostics`: past the ceiling the
|
|
163
|
+
* sink counts rows instead of building them, so an oversized payload can never
|
|
164
|
+
* make the validator allocate one diagnostic per byte it disliked. `count()` is
|
|
165
|
+
* the total number of failures seen (held + dropped) and is what the structural
|
|
166
|
+
* walk uses to decide whether anything failed — never the capped length.
|
|
167
|
+
*/
|
|
168
|
+
export interface VerificationDiagnosticSink {
|
|
169
|
+
push(code: VerificationDiagnosticCodeV1, path: string): void;
|
|
170
|
+
/** Failures seen so far, including the ones the ceiling dropped. */
|
|
171
|
+
count(): number;
|
|
172
|
+
/** Freeze the held rows and report whether the ceiling truncated them. */
|
|
173
|
+
finish(): {
|
|
174
|
+
readonly diagnostics: readonly VerificationDiagnosticV1[];
|
|
175
|
+
readonly truncated: boolean;
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
export declare function createVerificationDiagnosticSink(limit?: number): VerificationDiagnosticSink;
|
|
179
|
+
export declare const VERIFICATION_CONTRACT: Readonly<{
|
|
180
|
+
plan: VerificationContractSpec;
|
|
181
|
+
receipt: VerificationContractSpec;
|
|
182
|
+
}>;
|
|
183
|
+
/**
|
|
184
|
+
* Non-validating own-property projection of a contract value.
|
|
185
|
+
*
|
|
186
|
+
* `canonicalize*`/`digest*` run this first so a digest always describes the
|
|
187
|
+
* normalized DTO — never an accidental prototype value or an undeclared field.
|
|
188
|
+
* It performs no checks (callers validate first) and copies only declared own
|
|
189
|
+
* properties, so the walk is one pass with no regex and no error buffers.
|
|
190
|
+
*/
|
|
191
|
+
export declare function projectStructure(contract: VerificationContractSpec, spec: VerificationObjectSpec, value: unknown): unknown;
|
|
192
|
+
/**
|
|
193
|
+
* Capture the submitted document once, optionally bounded by `budgetBytes` of
|
|
194
|
+
* canonical form (F99): the capture aborts as soon as the running UTF-16 size
|
|
195
|
+
* passes the budget, so an illegal payload costs about the budget's worth of
|
|
196
|
+
* work instead of its own size. The abort reports the ROOT pointer — the byte
|
|
197
|
+
* budget outranks every shape ceiling and answers one root-path row (D16/F77).
|
|
198
|
+
*
|
|
199
|
+
* `measureExact` says whether the running size IS the canonical byte size: the
|
|
200
|
+
* document is pure ASCII (escapes are ASCII) and every leaf was measurable. A
|
|
201
|
+
* caller may then skip its own byte measure; anything else falls back to it.
|
|
202
|
+
*/
|
|
203
|
+
export type VerificationInputCapture = {
|
|
204
|
+
readonly ok: true;
|
|
205
|
+
readonly value: unknown;
|
|
206
|
+
readonly measureExact: boolean;
|
|
207
|
+
} | {
|
|
208
|
+
readonly ok: false;
|
|
209
|
+
readonly code: VerificationDiagnosticCodeV1;
|
|
210
|
+
readonly pointer: string;
|
|
211
|
+
};
|
|
212
|
+
export declare function captureVerificationInput(value: unknown, budgetBytes?: number): VerificationInputCapture;
|
|
213
|
+
/**
|
|
214
|
+
* Validate one contract object against its spec, recording D16 diagnostics in
|
|
215
|
+
* `sink`, and return its normalized own-property DTO — or `undefined` when
|
|
216
|
+
* anything in this object (or below it) failed.
|
|
217
|
+
*
|
|
218
|
+
* Only own properties of declared keys are read, so inherited or prototype
|
|
219
|
+
* values can never be mistaken for contract data; the returned object is a
|
|
220
|
+
* fresh plain literal, so mutating the input afterwards cannot change it.
|
|
221
|
+
*
|
|
222
|
+
* Every path is an RFC 6901 JSON Pointer built from declared contract property
|
|
223
|
+
* names and decimal array indices (`/commands/3/id`; `""` is the document root),
|
|
224
|
+
* so a diagnostic identifies the offending location without naming — let alone
|
|
225
|
+
* echoing — the submitted value.
|
|
226
|
+
*/
|
|
227
|
+
export declare function validateStructure(contract: VerificationContractSpec, spec: VerificationObjectSpec, value: unknown, path: string, sink: VerificationDiagnosticSink): Record<string, unknown> | undefined;
|