@gtrabanco/agentic-workflow-schema 3.1.0 → 3.3.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 CHANGED
@@ -28,6 +28,51 @@ de cada skill van dentro. Los esquemas se exportan en
28
28
  `./envelope.schema.json`, `./skill-outcome.schema.json` y
29
29
  `./workflow-snapshot.schema.json`.
30
30
 
31
+ ## Recibos de revisión con vínculo de contenido (v1)
32
+
33
+ Dos nuevos contratos versionados prueban exactamente qué diff evaluó una revisión:
34
+
35
+ - **CandidateSnapshot v1** — `baseCommit`, `candidateCommit`, `baseTree`,
36
+ `candidateTree`, manifiesto ordenado `changedPaths` y
37
+ `acceptanceFingerprint`. Los validadores estrictos rechazan claves no
38
+ declaradas, algoritmos de hash mezclados, inyección de rutas y estados
39
+ no soportados.
40
+ - **ReviewReceipt v1** — `id` opaco, `candidateSnapshotDigest`, vocabulario
41
+ cerrado de `kind` (10 valores), `verdict`, `findings` estructurados y
42
+ `policyVersion`.
43
+
44
+ ### Hash y fingerprint
45
+
46
+ ```ts
47
+ import {
48
+ digestCandidateSnapshot,
49
+ digestReviewReceipt,
50
+ computeAcceptanceFingerprint,
51
+ canonicalizeCandidateSnapshot,
52
+ canonicalizeReviewReceipt,
53
+ } from "@gtrabanco/agentic-workflow-schema";
54
+
55
+ const digest = await digestCandidateSnapshot(snapshot);
56
+ const fingerprint = await computeAcceptanceFingerprint([{ id: "AC-001", blobSha256: "..." }]);
57
+ ```
58
+
59
+ ### Predicado de frescura
60
+
61
+ ```ts
62
+ import { compareReceiptToCurrentSnapshot } from "@gtrabanco/agentic-workflow-schema";
63
+
64
+ const result = await compareReceiptToCurrentSnapshot(
65
+ receipt, currentSnapshot, currentAcceptanceInputs, policyVersion
66
+ );
67
+ // { fresh: true } | { fresh: false, reasonCode: "stale-base-tree" | "stale-candidate-tree" | "stale-manifest" | "stale-acceptance-fingerprint" | "stale-review-policy" }
68
+ ```
69
+
70
+ > ⚠️ **La validez del esquema ≠ corrección de la revisión.** Un esquema válido
71
+ > prueba que la estructura se preservó, no que la revisión fue precisa. El
72
+ vínculo de contenido es obligatorio: nunca confíes un recibo que no está
73
+ vinculado de contenido al snapshot candidato actual y a la frontera de
74
+ aceptación.
75
+
31
76
  ## Parsear un turno conducido
32
77
 
33
78
  Usa los perfiles para seleccionar el resultado requerido, añade la instrucción
@@ -155,3 +200,30 @@ publicado. Los campos aditivos son minor; arreglos de parser, documentación o
155
200
  implementación son patch. Consulta la
156
201
  [orquestación programática](../../docs/workflow/ORCHESTRATION.es.md) para el
157
202
  protocolo de driver.
203
+
204
+ ## Decisor de transición del workflow
205
+
206
+ Exporta `decideWorkflowAction(input)` — una función pura y determinista que
207
+ combina un `WorkflowSnapshot v1`, el último `SkillOutcome v1` validado y una
208
+ `WorkflowDecisionPolicy` provista por el driver para decidir si puede invocar
209
+ la siguiente habilidad, debe refrescar con `workflow-status` o debe detenerse.
210
+
211
+ ```ts
212
+ function decideWorkflowAction(input: WorkflowDecisionInput): WorkflowActionDecision
213
+ ```
214
+
215
+ - **Elisión segura:** cuando el snapshot está congelado y la habilidad →
216
+ siguiente intento está probada por la tabla congelada
217
+ `WORKFLOW_TRANSITION_TABLE`, el driver invoca directamente sin llamar a
218
+ `workflow-status`.
219
+ - **Respaldo obligatorio:** en evidencia ausente, revisión obsoleta, estado
220
+ bloqueado, contradicciones, efectos no autorizados o cualquier transición
221
+ no reconocida, la función retorna `sense` (llamar `workflow-status`) o
222
+ `stop` (terminar).
223
+
224
+ **Puntos obligatorios de sensor:** ejecución inicial (sin outcome), ejecución
225
+ recuperada (revisión obsoleta), snapshot desconocido o contradicho, siguiente
226
+ intento no reconocido, y cualquier transición no en la tabla cerrada.
227
+
228
+ Consulta el [SPEC](../features/24-workflow-transition-decider/SPEC.md) para el
229
+ diseño completo, tablas de transición y vocabulario de códigos de razón.
package/README.md CHANGED
@@ -27,6 +27,49 @@ on Envelope v2 (use `null` when empty); skill-specific extensions belong inside
27
27
  it. The schemas are exported at `./envelope.schema.json`,
28
28
  `./skill-outcome.schema.json`, and `./workflow-snapshot.schema.json`.
29
29
 
30
+ ## Content-bound review receipts (v1)
31
+
32
+ Two new versioned contracts prove exactly which diff a review evaluated:
33
+
34
+ - **CandidateSnapshot v1** — `baseCommit`, `candidateCommit`, `baseTree`,
35
+ `candidateTree`, ordered `changedPaths` manifest, and `acceptanceFingerprint`.
36
+ Strict validators reject undeclared fields, mixed hash algorithms, path
37
+ injection, and unsupported statuses.
38
+ - **ReviewReceipt v1** — opaque `id`, `candidateSnapshotDigest`, closed `kind`
39
+ vocabulary (10 values), `verdict`, structured `findings`, and
40
+ `policyVersion`.
41
+
42
+ ### Hashing and fingerprinting
43
+
44
+ ```ts
45
+ import {
46
+ digestCandidateSnapshot,
47
+ digestReviewReceipt,
48
+ computeAcceptanceFingerprint,
49
+ canonicalizeCandidateSnapshot,
50
+ canonicalizeReviewReceipt,
51
+ } from "@gtrabanco/agentic-workflow-schema";
52
+
53
+ const digest = await digestCandidateSnapshot(snapshot);
54
+ const fingerprint = await computeAcceptanceFingerprint([{ id: "AC-001", blobSha256: "..." }]);
55
+ ```
56
+
57
+ ### Freshness predicate
58
+
59
+ ```ts
60
+ import { compareReceiptToCurrentSnapshot } from "@gtrabanco/agentic-workflow-schema";
61
+
62
+ const result = await compareReceiptToCurrentSnapshot(
63
+ receipt, currentSnapshot, currentAcceptanceInputs, policyVersion
64
+ );
65
+ // { fresh: true } | { fresh: false, reasonCode: "stale-base-tree" | "stale-candidate-tree" | "stale-manifest" | "stale-acceptance-fingerprint" | "stale-review-policy" }
66
+ ```
67
+
68
+ > ⚠️ **Schema validity ≠ review correctness.** A valid schema proves the
69
+ > structure was preserved, not that the review was accurate. Content binding
70
+ > is mandatory — never trust a receipt that is not content-bound to the current
71
+ > candidate snapshot and acceptance boundary.
72
+
30
73
  ## Parse a driven turn
31
74
 
32
75
  Use the profile metadata to select the required result, append the generated
@@ -145,6 +188,31 @@ It refuses a nonzero issue count without identities, an unmatched unit id, and
145
188
  unstructured prose. The compatibility diagnostics make every repair visible to
146
189
  the driver.
147
190
 
191
+ ## Workflow transition decider
192
+
193
+ Export `decideWorkflowAction(input)` — a pure, deterministic function that
194
+ combines a `WorkflowSnapshot v1`, the last validated `SkillOutcome v1`, and a
195
+ caller-provided `WorkflowDecisionPolicy` to decide whether a headless driver
196
+ may invoke the next skill, must refresh with `workflow-status`, or must stop.
197
+
198
+ ```ts
199
+ function decideWorkflowAction(input: WorkflowDecisionInput): WorkflowActionDecision
200
+ ```
201
+
202
+ - **Safe elision:** when the snapshot is frozen and the last skill → next intent
203
+ is proven by the frozen `WORKFLOW_TRANSITION_TABLE`, the driver invokes
204
+ directly without calling `workflow-status`.
205
+ - **Mandatory fallback:** on missing evidence, stale revision, blocked status,
206
+ contradictions, unauthorized effects, or any unrecognized transition, the
207
+ function returns `sense` (call `workflow-status`) or `stop` (terminate).
208
+
209
+ **Mandatory sensor points:** initial run (no outcome), recovered run (stale
210
+ revision), snapshot state unknown or contradicted, unrecognized next intent,
211
+ and any transition not in the closed table.
212
+
213
+ See [SPEC](../features/24-workflow-transition-decider/SPEC.md) for the full
214
+ design, transition tables, and reason-code vocabulary.
215
+
148
216
  Package major versions signal a breaking change to any published contract.
149
217
  Additive contract fields are minor; parser, documentation, or implementation
150
218
  fixes are patch releases. See
@@ -0,0 +1,129 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://github.com/gtrabanco/agentic-workflow/packages/agentic-workflow-schema/candidate-snapshot.schema.json",
4
+ "title": "agentic-workflow candidate snapshot v1",
5
+ "description": "A content-bound candidate snapshot proving exactly which diff a review evaluated. Source of truth: @gtrabanco/agentic-workflow-schema.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": [
9
+ "contract",
10
+ "objectFormat",
11
+ "baseCommit",
12
+ "candidateCommit",
13
+ "baseTree",
14
+ "candidateTree",
15
+ "acceptanceFingerprint",
16
+ "changedPaths"
17
+ ],
18
+ "properties": {
19
+ "contract": {
20
+ "type": "string",
21
+ "const": "agentic-workflow/candidate-snapshot@1"
22
+ },
23
+ "objectFormat": {
24
+ "enum": ["sha1", "sha256"]
25
+ },
26
+ "baseCommit": {
27
+ "$ref": "#/$defs/gitObjectId"
28
+ },
29
+ "candidateCommit": {
30
+ "$ref": "#/$defs/gitObjectId"
31
+ },
32
+ "baseTree": {
33
+ "$ref": "#/$defs/gitObjectId"
34
+ },
35
+ "candidateTree": {
36
+ "$ref": "#/$defs/gitObjectId"
37
+ },
38
+ "acceptanceFingerprint": {
39
+ "type": "string",
40
+ "pattern": "^[a-f0-9]{64}$"
41
+ },
42
+ "changedPaths": {
43
+ "type": "array",
44
+ "items": {
45
+ "$ref": "#/$defs/manifestEntryV1"
46
+ }
47
+ }
48
+ },
49
+ "$defs": {
50
+ "gitObjectId": {
51
+ "type": "object",
52
+ "additionalProperties": false,
53
+ "required": ["algorithm", "hex"],
54
+ "properties": {
55
+ "algorithm": {
56
+ "enum": ["sha1", "sha256"]
57
+ },
58
+ "hex": {
59
+ "type": "string"
60
+ }
61
+ },
62
+ "anyOf": [
63
+ {
64
+ "if": { "properties": { "algorithm": { "const": "sha1" } }, "required": ["algorithm"] },
65
+ "then": { "properties": { "hex": { "type": "string", "pattern": "^[a-f0-9]{40}$" } } }
66
+ },
67
+ {
68
+ "if": { "properties": { "algorithm": { "const": "sha256" } }, "required": ["algorithm"] },
69
+ "then": { "properties": { "hex": { "type": "string", "pattern": "^[a-f0-9]{64}$" } } }
70
+ }
71
+ ]
72
+ },
73
+ "manifestEntryV1": {
74
+ "type": "object",
75
+ "additionalProperties": false,
76
+ "required": ["path", "status", "oldPath", "mode", "objectSha", "sizeBytes", "binary"],
77
+ "properties": {
78
+ "path": {
79
+ "type": "string",
80
+ "pattern": "^(?!\\0)(?!\\/)(?!.*(?:^|\\/)(?:\\.\\.|\\./))[^\\0]*$"
81
+ },
82
+ "status": {
83
+ "enum": ["added", "modified", "deleted", "renamed", "copied", "type-changed"]
84
+ },
85
+ "oldPath": {
86
+ "type": ["string", "null"]
87
+ },
88
+ "mode": {
89
+ "oneOf": [
90
+ { "enum": ["100644", "100755", "120000", "160000"] },
91
+ { "type": "null" }
92
+ ]
93
+ },
94
+ "objectSha": {
95
+ "oneOf": [
96
+ { "$ref": "#/$defs/gitObjectId" },
97
+ { "type": "null" }
98
+ ]
99
+ },
100
+ "sizeBytes": {
101
+ "oneOf": [
102
+ { "type": "integer", "minimum": 0 },
103
+ { "type": "null" }
104
+ ]
105
+ },
106
+ "binary": {
107
+ "oneOf": [
108
+ { "type": "boolean" },
109
+ { "type": "null" }
110
+ ]
111
+ }
112
+ },
113
+ "anyOf": [
114
+ {
115
+ "if": { "properties": { "status": { "const": "deleted" } }, "required": ["status"] },
116
+ "then": { "properties": { "oldPath": { "const": null } } }
117
+ },
118
+ {
119
+ "if": { "properties": { "status": { "enum": ["renamed", "copied"] } }, "required": ["status"] },
120
+ "then": { "properties": { "oldPath": { "not": { "const": null } } } }
121
+ },
122
+ {
123
+ "if": { "properties": { "status": { "enum": ["added", "modified", "type-changed"] } }, "required": ["status"] },
124
+ "then": { "properties": { "oldPath": { "const": null } } }
125
+ }
126
+ ]
127
+ }
128
+ }
129
+ }
package/dist/index.d.ts CHANGED
@@ -173,6 +173,96 @@ export type StrictEnvelopeParseResult = {
173
173
  export declare function parseEnvelopeV2Strict(text: string): StrictEnvelopeParseResult;
174
174
  export type WorkflowIntent = "init-workspace" | "status" | "discover-repository-state" | "resolve-repository-state" | "design-feature" | "plan-feature" | "plan-fix" | "triage-issue" | "execute-phase" | "review-change" | "loop-review-fold" | "audit-pr" | "merge" | "ask-human" | "stop" | "none";
175
175
  export declare const WORKFLOW_INTENTS: readonly WorkflowIntent[];
176
+ /** Sense reason codes: transition cannot proceed without more sensor input. */
177
+ export declare const WORKFLOW_DECISION_SENSE_CODES: readonly ["sense-initial", "sense-stale-revision", "sense-missing-evidence", "sense-unknown-state", "sense-unlisted-transition"];
178
+ export type WorkflowDecisionSenseReason = (typeof WORKFLOW_DECISION_SENSE_CODES)[number];
179
+ /** Stop reason codes: the transition is explicitly blocked or must terminate. */
180
+ export declare const WORKFLOW_DECISION_STOP_CODES: readonly ["stop-blocked", "stop-needs-input", "stop-failed", "stop-contradiction", "stop-policy-denied", "stop-forbidden-transition"];
181
+ export type WorkflowDecisionStopReason = (typeof WORKFLOW_DECISION_STOP_CODES)[number];
182
+ /** Invoke reason codes: transition is proven and allowed. */
183
+ export declare const WORKFLOW_DECISION_INVOKE_CODES: readonly ["invoke-proven-transition"];
184
+ export type WorkflowDecisionInvokeReason = (typeof WORKFLOW_DECISION_INVOKE_CODES)[number];
185
+ export type WorkflowDecisionReasonCode = WorkflowDecisionSenseReason | WorkflowDecisionStopReason | WorkflowDecisionInvokeReason;
186
+ /** Policy a caller provides to control the transition decision. */
187
+ export interface WorkflowDecisionPolicy {
188
+ /** Intents the caller is permitted to invoke. */
189
+ readonly allowedIntents: readonly WorkflowIntent[];
190
+ /** Whether the caller has forge-write authorization. */
191
+ readonly forgeWriteAuthorized: boolean;
192
+ }
193
+ /** Input to the transition decision function. */
194
+ export interface WorkflowDecisionInput {
195
+ /** A validated WorkflowSnapshot v1. */
196
+ readonly snapshot: WorkflowSnapshot;
197
+ /** The last validated SkillOutcome v1, or null. */
198
+ readonly lastOutcome: SkillOutcome | null;
199
+ /** The revision at which the last outcome was recorded. */
200
+ readonly lastOutcomeSourceRevision: string | null;
201
+ /** Closed caller policy governing what transitions are permitted. */
202
+ readonly policy: WorkflowDecisionPolicy;
203
+ }
204
+ /** Intent values that may be directly invoked (excludes non-invocation intents). */
205
+ export type WorkflowInvocableIntent = Exclude<WorkflowIntent, "status" | "ask-human" | "stop" | "none">;
206
+ export type WorkflowActionDecision = {
207
+ readonly kind: "invoke";
208
+ readonly intent: WorkflowInvocableIntent;
209
+ readonly targets: readonly string[];
210
+ readonly reasonCode: "invoke-proven-transition";
211
+ readonly evidenceRefs: readonly string[];
212
+ readonly detail: string;
213
+ } | {
214
+ readonly kind: "sense";
215
+ readonly intent: "status";
216
+ readonly targets: readonly [];
217
+ readonly reasonCode: WorkflowDecisionSenseReason;
218
+ readonly evidenceRefs: readonly string[];
219
+ readonly detail: string;
220
+ } | {
221
+ readonly kind: "stop";
222
+ readonly intent: "ask-human" | "stop";
223
+ readonly targets: readonly string[];
224
+ readonly reasonCode: WorkflowDecisionStopReason;
225
+ readonly evidenceRefs: readonly string[];
226
+ readonly detail: string;
227
+ };
228
+ /** One row of the direct-invocation transition table. */
229
+ export interface WorkflowTransitionTableRow {
230
+ /** The last validated skill / workflow intent. */
231
+ readonly key: WorkflowIntent;
232
+ /** Allowed next intents (may be empty, or contain a single literal "*" for wildcard). */
233
+ readonly allowed: readonly string[];
234
+ /** Description of the row conditions (arity, identity, state constraints). */
235
+ readonly condition: string;
236
+ }
237
+ /**
238
+ * Frozen, versioned direct-invocation transition table.
239
+ *
240
+ * Maps each last-validated skill to its allowed next intents. Rows whose
241
+ * `allowed` array contains a literal "frozen" permit transitions only when
242
+ * the snapshot repository state is "frozen"; rows with an empty array
243
+ * explicitly forbid any transition (return sense/stop rather than invoke).
244
+ *
245
+ * Derived condition semantics (from the Design):
246
+ * none → sense-initial
247
+ * init-workspace → exactly discover-repository-state
248
+ * workflow-status → broad set of planning/execution skills
249
+ * discover-repository-state → row allowed iff snapshot.state === "frozen"
250
+ * resolve-repository-state → row allowed iff snapshot.contradictions.length > 0
251
+ * design-feature, plan-feature → 0..n allowed, each must be a plan/execute skill
252
+ * plan-fix → exactly 1, must be triage-issue
253
+ * triage-issue → 1..n allowed, each must be an issue identity string
254
+ * init-workspace, discover-repository-state → 0 allowed → stop-forbidden-transition
255
+ * resolve-repository-state → each allowed must match a contradiction field
256
+ * merge → exactly 1, must be the PR identity from audit-pr
257
+ */
258
+ export declare const WORKFLOW_TRANSITION_TABLE: readonly WorkflowTransitionTableRow[];
259
+ /**
260
+ * Decide whether a headless consumer may invoke the next skill, must refresh
261
+ * with workflow-status, or must stop.
262
+ *
263
+ * Pure, deterministic, fail-closed — no I/O, no randomness, no locale.
264
+ */
265
+ export declare function decideWorkflowAction(input: WorkflowDecisionInput): WorkflowActionDecision;
176
266
  /** Role a built-in skill plays in the workflow pipeline. */
177
267
  export declare const SKILL_ROLES: readonly ["sensor", "planner", "executor", "reviewer", "auditor", "publisher"];
178
268
  export type SkillRole = (typeof SKILL_ROLES)[number];
@@ -381,3 +471,160 @@ export declare function validateWorkflowSnapshotV1(value: unknown): WorkflowSnap
381
471
  * locations for every value it derives.
382
472
  */
383
473
  export declare function compileWorkflowSnapshot(input: WorkflowSnapshotInput): WorkflowSnapshotResult;
474
+ /** Contract identifier for CandidateSnapshot v1. */
475
+ export declare const CANDIDATE_SNAPSHOT_CONTRACT_ID = "agentic-workflow/candidate-snapshot@1";
476
+ /** Git object hash algorithm. */
477
+ export type GitObjectFormat = "sha1" | "sha256";
478
+ /** A fully-qualified Git object identifier — algorithm + hex digest. */
479
+ export interface GitObjectId {
480
+ readonly algorithm: GitObjectFormat;
481
+ readonly hex: string;
482
+ }
483
+ /** Allowed change statuses in a manifest entry. */
484
+ export type ChangeStatus = "added" | "modified" | "deleted" | "renamed" | "copied" | "type-changed";
485
+ /** Git file mode — serialized as string; null when not applicable. */
486
+ export type GitMode = "100644" | "100755" | "120000" | "160000";
487
+ /** A single entry in the changed-paths manifest. */
488
+ export interface ManifestEntryV1 {
489
+ readonly path: string;
490
+ readonly status: ChangeStatus;
491
+ readonly oldPath: string | null;
492
+ readonly mode: GitMode | null;
493
+ readonly objectSha: GitObjectId | null;
494
+ readonly sizeBytes: number | null;
495
+ readonly binary: boolean | null;
496
+ }
497
+ /** A content-bound candidate snapshot — proves exactly what a review evaluated. */
498
+ export interface CandidateSnapshotV1 {
499
+ readonly contract: typeof CANDIDATE_SNAPSHOT_CONTRACT_ID;
500
+ readonly objectFormat: GitObjectFormat;
501
+ readonly baseCommit: GitObjectId;
502
+ readonly candidateCommit: GitObjectId;
503
+ readonly baseTree: GitObjectId;
504
+ readonly candidateTree: GitObjectId;
505
+ readonly acceptanceFingerprint: string;
506
+ readonly changedPaths: readonly ManifestEntryV1[];
507
+ }
508
+ export type CandidateSnapshotValidationResult = {
509
+ ok: true;
510
+ snapshot: CandidateSnapshotV1;
511
+ } | {
512
+ ok: false;
513
+ errors: string[];
514
+ };
515
+ /**
516
+ * Structural validation of a CandidateSnapshot v1.
517
+ * Rejects undeclared fields, enforces GitObjectId format, path-byte ordering,
518
+ * null-applicability matrix, and the empty-diff rule.
519
+ */
520
+ export declare function validateCandidateSnapshotV1(value: unknown): CandidateSnapshotValidationResult;
521
+ /** Contract identifier for ReviewReceipt v1. */
522
+ export declare const REVIEW_RECEIPT_CONTRACT_ID = "agentic-workflow/review-receipt@1";
523
+ /** All review kinds supported by the workflow. */
524
+ export declare const REVIEW_KINDS: readonly ["implementation", "security", "verification", "debt", "design", "accessibility", "brand", "performance", "seo", "audit"];
525
+ /** Finding severity levels. */
526
+ export declare const FINDING_SEVERITIES: readonly ["info", "low", "medium", "high", "critical"];
527
+ /** A line-level piece of evidence attached to a finding. */
528
+ export interface FindingEvidenceV1 {
529
+ readonly path: string;
530
+ readonly line?: number;
531
+ }
532
+ /** A single finding within a review receipt. */
533
+ export interface FindingV1 {
534
+ readonly id: string;
535
+ readonly severity: (typeof FINDING_SEVERITIES)[number];
536
+ readonly summary: string;
537
+ readonly evidence?: FindingEvidenceV1;
538
+ readonly refs: readonly string[];
539
+ }
540
+ /** A content-bound review receipt — proves exactly what was reviewed. */
541
+ export interface ReviewReceiptV1 {
542
+ readonly contract: typeof REVIEW_RECEIPT_CONTRACT_ID;
543
+ readonly id: string;
544
+ readonly candidateSnapshotDigest: string;
545
+ readonly kind: (typeof REVIEW_KINDS)[number];
546
+ readonly verdict: "pass" | "fail";
547
+ readonly findings: readonly FindingV1[];
548
+ readonly reviewer: string;
549
+ readonly sessionId: string;
550
+ readonly startedAt: string;
551
+ readonly finishedAt: string;
552
+ readonly diagnostics: readonly string[];
553
+ readonly policyVersion: string;
554
+ }
555
+ export type ReviewReceiptValidationResult = {
556
+ ok: true;
557
+ receipt: ReviewReceiptV1;
558
+ } | {
559
+ ok: false;
560
+ errors: string[];
561
+ };
562
+ /**
563
+ * Structural validation of a ReviewReceipt v1.
564
+ * Rejects undeclared fields, enforces closed vocabularies, format rules,
565
+ * and constraints on timestamps and finding structure.
566
+ */
567
+ export declare function validateReviewReceiptV1(value: unknown): ReviewReceiptValidationResult;
568
+ /** Staleness reason codes — one per detectable dimension. */
569
+ export declare const STALE_REASON_CODES: readonly ["stale-base-tree", "stale-candidate-tree", "stale-manifest", "stale-acceptance-fingerprint", "stale-review-policy"];
570
+ export type StaleReasonCode = (typeof STALE_REASON_CODES)[number];
571
+ export type FreshResult = {
572
+ fresh: true;
573
+ };
574
+ export type StaleResult = {
575
+ fresh: false;
576
+ reasonCode: StaleReasonCode;
577
+ };
578
+ export type FreshnessResult = FreshResult | StaleResult;
579
+ /**
580
+ * D4 — Canonicalize a CandidateSnapshotV1.
581
+ * Produces deterministic JSON with declaration-order keys and sorted changedPaths.
582
+ */
583
+ export declare function canonicalizeCandidateSnapshot(snapshot: CandidateSnapshotV1): string;
584
+ /**
585
+ * D4 — Canonicalize a ReviewReceiptV1.
586
+ * Findings are sorted by ascending byte order of their stable ids.
587
+ */
588
+ export declare function canonicalizeReviewReceipt(receipt: ReviewReceiptV1): string;
589
+ /** D4 — Digest a CandidateSnapshotV1 via canonical serialization. */
590
+ export declare function digestCandidateSnapshot(snapshot: CandidateSnapshotV1): Promise<string>;
591
+ /** D4 — Digest a ReviewReceiptV1 via canonical serialization. */
592
+ export declare function digestReviewReceipt(receipt: ReviewReceiptV1): Promise<string>;
593
+ /**
594
+ * D2 — Compute the acceptance fingerprint from an ordered array of
595
+ * {id, blobSha256} entries. Returns lowercase hex SHA-256 over their
596
+ * canonical serialization (sorted by byte-order of id).
597
+ */
598
+ export declare function computeAcceptanceFingerprint(inputs: ReadonlyArray<{
599
+ id: string;
600
+ blobSha256: string;
601
+ }>): Promise<string>;
602
+ /**
603
+ * D1 — Compare a receipt against the current candidate snapshot and
604
+ * acceptance fingerprint. Returns exactly one stable reason code per stale
605
+ * dimension, or `{fresh: true}` when everything matches.
606
+ *
607
+ * Comparison order (per spec): baseCommit → candidateCommit → changedPaths
608
+ * (canonical equality) → acceptanceFingerprint → policyVersion.
609
+ * Everything equal AND snapshot digest === receipt.candidateSnapshotDigest → fresh.
610
+ */
611
+ export declare function compareReceiptToCurrentSnapshot(receipt: ReviewReceiptV1, snapshot: CandidateSnapshotV1, acceptanceInputs: ReadonlyArray<{
612
+ id: string;
613
+ blobSha256: string;
614
+ }>, policyVersion: string): Promise<FreshnessResult>;
615
+ export interface CanonicalVectorV1 {
616
+ /** Contract name. */
617
+ contract: string;
618
+ /** Expected SHA-256 hex digest. */
619
+ digest: string;
620
+ /** Description of what this vector tests. */
621
+ description: string;
622
+ }
623
+ /**
624
+ * Published frozen canonical vectors. Each vector is a minimal valid value
625
+ * whose canonical digest is deterministic and reproducible.
626
+ *
627
+ * These vectors lock the canonicalization rules (D4) in place.
628
+ * Changing any vector's expected digest would be a reviewed contract change.
629
+ */
630
+ export declare const CANONICAL_VECTORS: ReadonlyArray<CanonicalVectorV1>;