@parmanasystems/execution 1.0.19

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.
@@ -0,0 +1,810 @@
1
+ interface ExecutionToken {
2
+ execution_id: string;
3
+ policy_id: string;
4
+ decision_payload: any;
5
+ schema_version: string;
6
+ runtime_version: string;
7
+ }
8
+
9
+ /**
10
+ * 🔐 Issue Execution Token (FINAL)
11
+ * Fully deterministic — caller provides execution_id
12
+ */
13
+ declare function issueToken(input: {
14
+ execution_id: string;
15
+ policy_id: string;
16
+ decision_payload: any;
17
+ schema_version: string;
18
+ runtime_version: string;
19
+ }): ExecutionToken;
20
+
21
+ /**
22
+ * Synchronous signing interface used by the deterministic governance runtime.
23
+ * Implementations must produce a base64-encoded Ed25519 signature over the
24
+ * UTF-8 `payload`. See {@link LocalSigner} for the in-process implementation.
25
+ */
26
+ interface Signer {
27
+ /**
28
+ * Signs the canonical UTF-8 `payload` and returns a base64-encoded signature.
29
+ * Must be deterministic: the same key and payload always produce the same bytes.
30
+ */
31
+ sign(payload: string): string;
32
+ }
33
+
34
+ /**
35
+ * Signs the canonical form of `token` with `signer` and returns a
36
+ * base64-encoded Ed25519 signature.
37
+ */
38
+ declare function signExecutionToken(token: ExecutionToken, signer: Signer): string;
39
+
40
+ /**
41
+ * Synchronous verification interface used by the deterministic governance runtime.
42
+ * See {@link LocalVerifier} for the in-process implementation.
43
+ */
44
+ interface Verifier {
45
+ /**
46
+ * Verifies that `signature` (base64 Ed25519) was produced over the canonical
47
+ * UTF-8 `payload` with the corresponding private key.
48
+ */
49
+ verify(payload: string, signature: string): boolean;
50
+ }
51
+
52
+ declare function verifyExecutionToken(token: ExecutionToken, signature: string, verifier: Verifier): boolean;
53
+
54
+ /**
55
+ * Validates that `policyId` passes full bundle and signature verification.
56
+ * Delegates to {@link validatePolicy} and throws if validation fails.
57
+ *
58
+ * @throws When the policy does not exist or any version fails verification.
59
+ */
60
+ declare function verifyRuntimePolicy(policyId: string): void;
61
+
62
+ interface ExecutionContext {
63
+ token: any;
64
+ token_signature: string;
65
+ signer: any;
66
+ verifier: any;
67
+ runtime_manifest: any;
68
+ runtime_requirements: any;
69
+ }
70
+
71
+ interface ReplayStore {
72
+ markExecuted(execution_id: string): void;
73
+ }
74
+
75
+ interface ExecutionAttestation {
76
+ execution_id: string;
77
+ decision: {
78
+ action: "approve" | "reject";
79
+ requires_override: boolean;
80
+ reason?: string;
81
+ };
82
+ execution_state: "completed" | "blocked" | "pending_override";
83
+ signature: string;
84
+ runtime_hash: string;
85
+ }
86
+
87
+ /**
88
+ * 🔴 CORE EXECUTION (FULLY DETERMINISTIC)
89
+ *
90
+ * Principles:
91
+ * - NO time dependency
92
+ * - replay is enforced
93
+ * - decision is precomputed (token-driven)
94
+ * - execution is enforcement only
95
+ */
96
+ declare function executeDecision(context: ExecutionContext, replayStore: ReplayStore): ExecutionAttestation;
97
+
98
+ /** A single audit log entry with arbitrary governance fields. */
99
+ interface AuditEntry {
100
+ [key: string]: unknown;
101
+ }
102
+ /**
103
+ * Verifies that `signature` (base64 Ed25519) was produced over the canonical
104
+ * form of `entry` by the authority whose key `verifier` holds.
105
+ */
106
+ declare function verifyAuditEntry(entry: AuditEntry, signature: string, verifier: Verifier): boolean;
107
+ /**
108
+ * Placeholder for full audit-chain integrity verification.
109
+ * A complete implementation would re-hash every JSONL record and validate
110
+ * the `previous_record_hash` linkage.
111
+ *
112
+ * @returns `true` — full chain verification is not yet implemented.
113
+ */
114
+ declare function verifyAuditChain(): boolean;
115
+
116
+ type DecisionSource = "rule_match";
117
+ interface DecisionResult {
118
+ status: "decided";
119
+ outcome: {
120
+ action: "approve" | "reject";
121
+ requires_override: boolean;
122
+ reason?: string;
123
+ };
124
+ source: DecisionSource;
125
+ rule_id: string;
126
+ }
127
+
128
+ /**
129
+ * The static portion of the runtime manifest (everything except `runtime_hash`).
130
+ * Used both as the canonical source of capability declarations and as the input
131
+ * to {@link hashRuntime}.
132
+ */
133
+ declare const runtimeManifestDefinition: {
134
+ readonly runtime_version: "1.0.0";
135
+ readonly supported_schema_versions: readonly ["1.0.0"];
136
+ readonly capabilities: readonly ["deterministic-evaluation", "attestation-signing", "replay-protection", "bundle-verification"];
137
+ };
138
+ /**
139
+ * Returns the SHA-256 hex digest of the canonicalized {@link runtimeManifestDefinition}.
140
+ * This hash is embedded in every {@link ExecutionResult} as `runtime_hash`,
141
+ * binding the result to a specific version of the runtime.
142
+ */
143
+ declare function hashRuntime(): string;
144
+
145
+ /**
146
+ * 🔒 In-memory replay protection
147
+ */
148
+ declare class MemoryReplayStore implements ReplayStore {
149
+ private store;
150
+ markExecuted(execution_id: string): void;
151
+ }
152
+
153
+ interface AsyncReplayStore {
154
+ hasExecuted(executionId: string): Promise<boolean>;
155
+ markExecuted(executionId: string): Promise<void>;
156
+ get?(key: string): Promise<string | null>;
157
+ set?(key: string, value: string): Promise<void>;
158
+ del?(key: string): Promise<void>;
159
+ close?(): Promise<void>;
160
+ }
161
+
162
+ /**
163
+ * Async variant of {@link Signer} for remote key providers (e.g. AWS KMS).
164
+ * The returned promise resolves to a base64-encoded signature.
165
+ * See {@link AwsKmsSigner} for the AWS KMS implementation.
166
+ */
167
+ interface AsyncSigner {
168
+ /** Signs the canonical UTF-8 `payload` and resolves to a base64-encoded signature. */
169
+ sign(payload: string): Promise<string>;
170
+ }
171
+
172
+ /**
173
+ * Static description of the governance runtime's identity, capabilities, and
174
+ * supported protocol versions.
175
+ *
176
+ * Included in every {@link ExecutionResult} so verifiers can confirm the
177
+ * runtime environment without trusting the operator. The `runtime_hash`
178
+ * field is a deterministic SHA-256 commitment over the manifest definition,
179
+ * binding the result to a specific runtime build.
180
+ */
181
+ interface RuntimeManifest {
182
+ /** Semantic version of the governance runtime (e.g. `"1.0.0"`). */
183
+ runtime_version: string;
184
+ /** SHA-256 hex hash of the canonical runtime manifest definition. */
185
+ runtime_hash: string;
186
+ /** Schema version strings that this runtime can process. */
187
+ supported_schema_versions: readonly string[];
188
+ /** Capability strings advertised by this runtime (e.g. `"replay-protection"`). */
189
+ capabilities: readonly string[];
190
+ }
191
+ /**
192
+ * Returns the active {@link RuntimeManifest} for the current process,
193
+ * combining the static manifest definition with a freshly computed `runtime_hash`.
194
+ */
195
+ declare function getRuntimeManifest(): RuntimeManifest;
196
+
197
+ /**
198
+ * Signs the canonical form of `manifest` with `signer` and returns a
199
+ * base64-encoded Ed25519 signature. Use this to produce a verifiable
200
+ * attestation that a specific runtime version was active at a given time.
201
+ */
202
+ declare function signRuntimeManifest(manifest: RuntimeManifest, signer: Signer): string;
203
+
204
+ /**
205
+ * Verifies that `signature` (base64 Ed25519) was produced over the canonical
206
+ * form of `manifest` by the authority whose key `verifier` holds.
207
+ */
208
+ declare function verifyRuntimeManifest(manifest: RuntimeManifest, signature: string, verifier: Verifier): boolean;
209
+
210
+ /**
211
+ * In-process Ed25519 {@link Signer} backed by Node.js `crypto`.
212
+ *
213
+ * Suitable for development and environments where the private key can be
214
+ * securely injected at process start. For hardware-backed or remote signing
215
+ * see {@link AwsKmsSigner}.
216
+ */
217
+ declare class LocalSigner implements Signer {
218
+ private readonly privateKey;
219
+ /**
220
+ * @param privateKey - PEM-encoded Ed25519 private key (PKCS8 format).
221
+ */
222
+ constructor(privateKey: string);
223
+ /**
224
+ * Signs `payload` (UTF-8) with the Ed25519 private key and returns a
225
+ * base64-encoded signature.
226
+ */
227
+ sign(payload: string): string;
228
+ }
229
+
230
+ /**
231
+ * In-process Ed25519 {@link Verifier} backed by Node.js `crypto`.
232
+ *
233
+ * Paired with {@link LocalSigner}; both must use the same Ed25519 key pair.
234
+ */
235
+ declare class LocalVerifier implements Verifier {
236
+ private readonly publicKey;
237
+ /**
238
+ * @param publicKey - PEM-encoded Ed25519 public key (SPKI format).
239
+ */
240
+ constructor(publicKey: string);
241
+ /**
242
+ * Verifies that `signature` (base64 Ed25519) was produced over the UTF-8
243
+ * `payload` by the holder of the corresponding private key.
244
+ */
245
+ verify(payload: string, signature: string): boolean;
246
+ }
247
+
248
+ interface DryRunResult {
249
+ policy_id: string;
250
+ policy_version: string;
251
+ schema_version: string;
252
+ decision: DecisionResult;
253
+ rule_trace: string[];
254
+ governed: false;
255
+ dry_run: true;
256
+ evaluated_at: string;
257
+ }
258
+ declare function evaluateDryRun(policyId: string, policyVersion: string, signals: Record<string, unknown>, governed_time?: string): DryRunResult;
259
+
260
+ type InvariantBoundary = "canonicalize" | "validate" | "verify" | "replay" | "execute" | "sign";
261
+ interface InvariantEntry {
262
+ readonly id: string;
263
+ readonly description: string;
264
+ readonly boundary: InvariantBoundary | readonly InvariantBoundary[];
265
+ }
266
+ /**
267
+ * Single source of truth for all governance invariants.
268
+ *
269
+ * Every invariant_id that appears in ViolationReport, source comments,
270
+ * or test coverage maps MUST have an entry here. The CI gate
271
+ * (scripts/ci-invariant-gate.ts) enforces this at build time.
272
+ */
273
+ declare const INVARIANT_REGISTRY: {
274
+ readonly "INV-001": {
275
+ readonly id: "INV-001";
276
+ readonly description: "Canonical serialization produces identical bytes for identical inputs";
277
+ readonly boundary: "canonicalize";
278
+ };
279
+ readonly "INV-002": {
280
+ readonly id: "INV-002";
281
+ readonly description: "Input payload must be structurally valid";
282
+ readonly boundary: "validate";
283
+ };
284
+ readonly "INV-003": {
285
+ readonly id: "INV-003";
286
+ readonly description: "Execution token signature must be cryptographically valid";
287
+ readonly boundary: "verify";
288
+ };
289
+ readonly "INV-004": {
290
+ readonly id: "INV-004";
291
+ readonly description: "Execution time is injected deterministically — no wall-clock reads inside the execution scope";
292
+ readonly boundary: readonly InvariantBoundary[];
293
+ };
294
+ readonly "INV-005": {
295
+ readonly id: "INV-005";
296
+ readonly description: "Runtime version must be in the set of supported runtime versions";
297
+ readonly boundary: "verify";
298
+ };
299
+ readonly "INV-006": {
300
+ readonly id: "INV-006";
301
+ readonly description: "Schema version 1.0.0 must be supported by both runtime manifest and requirements";
302
+ readonly boundary: "verify";
303
+ };
304
+ readonly "INV-007": {
305
+ readonly id: "INV-007";
306
+ readonly description: "Execution token must not be expired at governed_time";
307
+ readonly boundary: "verify";
308
+ };
309
+ readonly "INV-008": {
310
+ readonly id: "INV-008";
311
+ readonly description: "The governed field is always in signature scope and equals literal true";
312
+ readonly boundary: "sign";
313
+ };
314
+ readonly "INV-009": {
315
+ readonly id: "INV-009";
316
+ readonly description: "Signals hash must be a non-empty string binding execution to specific inputs";
317
+ readonly boundary: "validate";
318
+ };
319
+ readonly "INV-010": {
320
+ readonly id: "INV-010";
321
+ readonly description: "Policy ID and policy version must be non-empty strings";
322
+ readonly boundary: "validate";
323
+ };
324
+ readonly "INV-011": {
325
+ readonly id: "INV-011";
326
+ readonly description: "All required runtime capabilities must be present in the runtime manifest";
327
+ readonly boundary: "verify";
328
+ };
329
+ readonly "INV-013": {
330
+ readonly id: "INV-013";
331
+ readonly description: "Replay protection is always enforced — execution_id is single-use and non-configurable";
332
+ readonly boundary: "replay";
333
+ };
334
+ readonly "INV-014": {
335
+ readonly id: "INV-014";
336
+ readonly description: "governed literal true structurally distinguishes ExecutionResult from DryRunResult";
337
+ readonly boundary: "execute";
338
+ };
339
+ readonly "INV-015": {
340
+ readonly id: "INV-015";
341
+ readonly description: "Audit record must be written before attestation is issued";
342
+ readonly boundary: "execute";
343
+ };
344
+ readonly "INV-016": {
345
+ readonly id: "INV-016";
346
+ readonly description: "Audit records are linearizable via SHA-256 hash chain";
347
+ readonly boundary: "execute";
348
+ };
349
+ readonly "INV-017": {
350
+ readonly id: "INV-017";
351
+ readonly description: "Any verification failure causes fail-closed execution — no partial results";
352
+ readonly boundary: readonly InvariantBoundary[];
353
+ };
354
+ readonly "INV-020": {
355
+ readonly id: "INV-020";
356
+ readonly description: "Runtime capability declarations are truthful and non-negotiable";
357
+ readonly boundary: "verify";
358
+ };
359
+ readonly "INV-022": {
360
+ readonly id: "INV-022";
361
+ readonly description: "Every policy decision is derivable from the policy document and input signals";
362
+ readonly boundary: "execute";
363
+ };
364
+ readonly "INV-024": {
365
+ readonly id: "INV-024";
366
+ readonly description: "Decision values are semantically unambiguous strings";
367
+ readonly boundary: "execute";
368
+ };
369
+ readonly "INV-025": {
370
+ readonly id: "INV-025";
371
+ readonly description: "Schema version and runtime version are present in every ExecutionResult";
372
+ readonly boundary: "execute";
373
+ };
374
+ readonly "INV-030": {
375
+ readonly id: "INV-030";
376
+ readonly description: "Every attestation contains a runtime_hash binding it to a specific runtime version";
377
+ readonly boundary: "execute";
378
+ };
379
+ readonly "INV-031": {
380
+ readonly id: "INV-031";
381
+ readonly description: "Runtime manifest declares explicit supported_schema_versions and runtime_version";
382
+ readonly boundary: "verify";
383
+ };
384
+ readonly "INV-033": {
385
+ readonly id: "INV-033";
386
+ readonly description: "Governance properties (replay, audit, attestation) are structurally enforced — not configurable";
387
+ readonly boundary: "execute";
388
+ };
389
+ readonly "INV-034": {
390
+ readonly id: "INV-034";
391
+ readonly description: "Any verifier holding the correct public key can independently verify an attestation";
392
+ readonly boundary: "sign";
393
+ };
394
+ readonly "INV-035": {
395
+ readonly id: "INV-035";
396
+ readonly description: "Verification is reproducible: same attestation + key produces identical outcome";
397
+ readonly boundary: "sign";
398
+ };
399
+ readonly "INV-037": {
400
+ readonly id: "INV-037";
401
+ readonly description: "Signatures from different authority keys do not cross-verify — signing domains are isolated";
402
+ readonly boundary: "sign";
403
+ };
404
+ readonly "INV-038": {
405
+ readonly id: "INV-038";
406
+ readonly description: "Cross-key verification failures are consistent: wrong-key always returns false";
407
+ readonly boundary: "sign";
408
+ };
409
+ readonly "INV-040": {
410
+ readonly id: "INV-040";
411
+ readonly description: "AI output and governance enforcement are strictly separated — no AI field in execution scope";
412
+ readonly boundary: "validate";
413
+ };
414
+ readonly "INV-041": {
415
+ readonly id: "INV-041";
416
+ readonly description: "Governance boundary is explicit: runtime manifest must declare runtime_version";
417
+ readonly boundary: "verify";
418
+ };
419
+ readonly "INV-047": {
420
+ readonly id: "INV-047";
421
+ readonly description: "Canonical serialization uses explicit UTF-8 encoding";
422
+ readonly boundary: "canonicalize";
423
+ };
424
+ readonly "INV-048": {
425
+ readonly id: "INV-048";
426
+ readonly description: "Unicode normalization is stable across canonicalization calls";
427
+ readonly boundary: "canonicalize";
428
+ };
429
+ readonly "INV-049": {
430
+ readonly id: "INV-049";
431
+ readonly description: "Canonical JSON sorts object keys recursively and preserves array order";
432
+ readonly boundary: "canonicalize";
433
+ };
434
+ readonly "INV-050": {
435
+ readonly id: "INV-050";
436
+ readonly description: "Duplicate JSON keys must not appear in governance payloads (gap: documented)";
437
+ readonly boundary: "canonicalize";
438
+ };
439
+ readonly "INV-051": {
440
+ readonly id: "INV-051";
441
+ readonly description: "Numeric values canonicalize identically regardless of trailing zeros";
442
+ readonly boundary: "canonicalize";
443
+ };
444
+ readonly "INV-052": {
445
+ readonly id: "INV-052";
446
+ readonly description: "Object insertion order does not affect canonical form or content-address hash";
447
+ readonly boundary: "canonicalize";
448
+ };
449
+ readonly "INV-053": {
450
+ readonly id: "INV-053";
451
+ readonly description: "Array element order is preserved through canonicalization";
452
+ readonly boundary: "canonicalize";
453
+ };
454
+ readonly "INV-054": {
455
+ readonly id: "INV-054";
456
+ readonly description: "JSON type closure: NaN and Infinity serialize to null; undefined fields are omitted";
457
+ readonly boundary: "canonicalize";
458
+ };
459
+ readonly "INV-057": {
460
+ readonly id: "INV-057";
461
+ readonly description: "Content-address (SHA-256) is stable for identical content across calls";
462
+ readonly boundary: "canonicalize";
463
+ };
464
+ readonly "INV-059": {
465
+ readonly id: "INV-059";
466
+ readonly description: "Replay domain is explicit: every execution_id in the store was consumed by a real execution";
467
+ readonly boundary: "replay";
468
+ };
469
+ readonly "INV-060": {
470
+ readonly id: "INV-060";
471
+ readonly description: "Attestation verification is idempotent: same inputs always produce identical results";
472
+ readonly boundary: "sign";
473
+ };
474
+ readonly "INV-061": {
475
+ readonly id: "INV-061";
476
+ readonly description: "Runtime capability declarations are immutable after build";
477
+ readonly boundary: "verify";
478
+ };
479
+ readonly "INV-072": {
480
+ readonly id: "INV-072";
481
+ readonly description: "Dry-run path produces no side effects: no replay store write, no audit record, no signature";
482
+ readonly boundary: "execute";
483
+ };
484
+ readonly "INV-073": {
485
+ readonly id: "INV-073";
486
+ readonly description: "Canonical evaluation source files contain no network calls";
487
+ readonly boundary: "execute";
488
+ };
489
+ readonly "INV-074": {
490
+ readonly id: "INV-074";
491
+ readonly description: "Every governed executeDecision call produces exactly one audit record";
492
+ readonly boundary: "execute";
493
+ };
494
+ readonly "INV-075": {
495
+ readonly id: "INV-075";
496
+ readonly description: "Execution IDs (UUIDv4) are unique per issuance — governance identity is non-reusable";
497
+ readonly boundary: "execute";
498
+ };
499
+ readonly "INV-077": {
500
+ readonly id: "INV-077";
501
+ readonly description: "All failure modes are deterministic: same invalid input always produces the same error";
502
+ readonly boundary: readonly InvariantBoundary[];
503
+ };
504
+ readonly "INV-078": {
505
+ readonly id: "INV-078";
506
+ readonly description: "Operational metadata fields must not contaminate deterministic signing scope";
507
+ readonly boundary: "validate";
508
+ };
509
+ readonly "INV-080": {
510
+ readonly id: "INV-080";
511
+ readonly description: "Unsupported schema and runtime versions fail explicitly with a descriptive error";
512
+ readonly boundary: "verify";
513
+ };
514
+ readonly "META-001": {
515
+ readonly id: "META-001";
516
+ readonly description: "Every governed execution produces a signed, independently verifiable attestation";
517
+ readonly boundary: "sign";
518
+ };
519
+ readonly "META-004": {
520
+ readonly id: "META-004";
521
+ readonly description: "Invariant violations always fail closed — no partial results are emitted on violation";
522
+ readonly boundary: readonly InvariantBoundary[];
523
+ };
524
+ };
525
+ type InvariantId = keyof typeof INVARIANT_REGISTRY;
526
+
527
+ /**
528
+ * Structured report emitted when a governance invariant is violated.
529
+ *
530
+ * Fields:
531
+ * invariant_id — the invariant from INVARIANT_REGISTRY that was breached
532
+ * boundary — pipeline stage where the violation was detected
533
+ * reason — human-readable explanation of what failed
534
+ * input_hash — SHA-256 of the canonical form of the input that triggered the violation
535
+ * timestamp_seq — monotonically increasing sequence number within the process lifetime
536
+ */
537
+ interface ViolationReport {
538
+ readonly invariant_id: string;
539
+ readonly boundary: string;
540
+ readonly reason: string;
541
+ readonly input_hash: string;
542
+ readonly timestamp_seq: number;
543
+ }
544
+ /**
545
+ * Thrown by every pipeline stage boundary when a governance invariant is violated.
546
+ *
547
+ * Carries a structured ViolationReport so downstream consumers can distinguish
548
+ * invariant violations from unexpected runtime errors without string parsing.
549
+ */
550
+ declare class InvariantViolation extends Error {
551
+ readonly report: ViolationReport;
552
+ constructor(report: ViolationReport);
553
+ }
554
+ /**
555
+ * Computes the SHA-256 hex digest of `value` for use as `input_hash` in a ViolationReport.
556
+ * Accepts a string (used as-is) or any value (JSON-stringified before hashing).
557
+ */
558
+ declare function hashInput(value: unknown): string;
559
+ /**
560
+ * Constructs and throws an InvariantViolation.
561
+ * Never returns — the return type `never` enforces this at compile time.
562
+ *
563
+ * @param invariant_id - ID from INVARIANT_REGISTRY
564
+ * @param boundary - Pipeline stage name
565
+ * @param reason - Human-readable reason (must contain the legacy message substring for test compat)
566
+ * @param input - The input that triggered the violation (hashed automatically)
567
+ */
568
+ declare function violate(invariant_id: string, boundary: string, reason: string, input: unknown): never;
569
+
570
+ /**
571
+ * 🔒 Stage 1 — Verification
572
+ */
573
+ declare function stageVerify(token: ExecutionToken, token_signature: string, verifier: {
574
+ verify: (data: Uint8Array, sig: Uint8Array) => boolean;
575
+ }, runtime_manifest: any, runtime_requirements: any): void;
576
+ /**
577
+ * 🔒 Stage 2 — Execution (ENFORCEMENT ONLY)
578
+ */
579
+ declare function stageExecute(token: ExecutionToken): void;
580
+ /**
581
+ * 🔒 Stage 3 — Signing (NEW MODEL)
582
+ */
583
+ declare function stageSign(payload: {
584
+ execution_id: string;
585
+ decision: {
586
+ action: "approve" | "reject";
587
+ requires_override: boolean;
588
+ reason?: string;
589
+ };
590
+ execution_state: "completed" | "blocked" | "pending_override";
591
+ }, signer: {
592
+ sign: (data: Uint8Array) => Uint8Array;
593
+ }, runtime_hash: string): {
594
+ execution_id: string;
595
+ decision: {
596
+ action: "approve" | "reject";
597
+ requires_override: boolean;
598
+ reason?: string;
599
+ };
600
+ execution_state: "completed" | "blocked" | "pending_override";
601
+ signature: string;
602
+ runtime_hash: string;
603
+ };
604
+
605
+ /**
606
+ * Sealed Execution VM — determinism enforcement for the governance execution scope.
607
+ *
608
+ * The execution stage (execute.ts, pipeline.ts) is forbidden from accessing:
609
+ * - Date.now() — non-deterministic wall clock
610
+ * - Math.random() — non-deterministic PRNG
611
+ * - fs / network IO — external state that varies across environments
612
+ *
613
+ * Time is injected explicitly via governed_time in ExecutionContext.
614
+ * The CI gate (scripts/ci-invariant-gate.ts) enforces these constraints statically.
615
+ *
616
+ * This module provides:
617
+ * - governingTime() — derives execution time from injected governed_time or falls
618
+ * back to the system clock (only acceptable outside execute.ts)
619
+ * - FORBIDDEN_GLOBALS — the list of globals that must not appear in execution-scope files
620
+ */
621
+ /** Globals forbidden inside the sealed execution scope. */
622
+ declare const FORBIDDEN_GLOBALS: readonly ["Date.now", "Math.random"];
623
+ /**
624
+ * Files in the execution package whose source must not reference FORBIDDEN_GLOBALS.
625
+ * Enforced by the CI gate.
626
+ */
627
+ declare const SEALED_SCOPE_FILES: readonly ["packages/execution/src/execute.ts", "packages/execution/src/pipeline.ts", "packages/execution/src/canonical-signing.ts", "packages/bundle/src/canonicalize.ts", "packages/bundle/src/hash.ts"];
628
+ /**
629
+ * Returns the governing time for an execution.
630
+ *
631
+ * When `provided` is a non-empty ISO 8601 string it is returned as-is,
632
+ * preserving determinism. When `provided` is absent or empty the current
633
+ * system time is used — this fallback is intentionally limited to
634
+ * non-execution-scope callers (audit.ts, dry-run.ts, tests).
635
+ *
636
+ * MUST NOT be called from execute.ts or pipeline.ts — those files must
637
+ * receive governed_time from their caller and pass it through explicitly.
638
+ */
639
+ declare function governingTime(provided?: string): string;
640
+
641
+ declare function executeFromSignals(input: {
642
+ policyId: string;
643
+ policyVersion: string;
644
+ signals: Record<string, unknown>;
645
+ metadata?: Record<string, unknown>;
646
+ }, signer: Signer, verifier: Verifier, replayStore: AsyncReplayStore & {
647
+ get?: (key: string) => Promise<string | null>;
648
+ set?: (key: string, value: string) => Promise<void>;
649
+ del?: (key: string) => Promise<void>;
650
+ }): Promise<{
651
+ status: "pending_override";
652
+ execution_id: string;
653
+ decision: DecisionResult;
654
+ requires_override: boolean;
655
+ execution_state?: undefined;
656
+ replay?: undefined;
657
+ signature?: undefined;
658
+ error?: undefined;
659
+ } | {
660
+ status: "success";
661
+ execution_id: string;
662
+ decision: DecisionResult;
663
+ execution_state: "completed" | "blocked";
664
+ requires_override: boolean;
665
+ replay: boolean;
666
+ signature?: undefined;
667
+ error?: undefined;
668
+ } | {
669
+ status: "success";
670
+ execution_id: string;
671
+ decision: DecisionResult;
672
+ execution_state: "completed" | "blocked";
673
+ requires_override: boolean;
674
+ signature: string;
675
+ replay?: undefined;
676
+ error?: undefined;
677
+ } | {
678
+ status: "error";
679
+ error: string;
680
+ execution_id?: undefined;
681
+ decision?: undefined;
682
+ requires_override?: undefined;
683
+ execution_state?: undefined;
684
+ replay?: undefined;
685
+ signature?: undefined;
686
+ }>;
687
+
688
+ interface BaseCondition {
689
+ signal: string;
690
+ equals?: unknown;
691
+ greater_than?: number;
692
+ less_than?: number;
693
+ }
694
+ interface AllCondition {
695
+ all: RuleCondition[];
696
+ }
697
+ interface AnyCondition {
698
+ any: RuleCondition[];
699
+ }
700
+ type RuleCondition = BaseCondition | AllCondition | AnyCondition;
701
+ interface PolicyRule {
702
+ id: string;
703
+ condition: RuleCondition;
704
+ outcome: {
705
+ action: "approve" | "reject";
706
+ requires_override: boolean;
707
+ reason?: string;
708
+ };
709
+ }
710
+ interface PolicyDocument {
711
+ schemaVersion: string;
712
+ signalsSchema: Record<string, unknown>;
713
+ rules: PolicyRule[];
714
+ }
715
+ declare function evaluatePolicy(policy: PolicyDocument, signals: Record<string, unknown>): DecisionResult;
716
+
717
+ declare function canonicalize(value: any): string;
718
+
719
+ /**
720
+ * Executes multiple records sequentially.
721
+ *
722
+ * Each record is processed independently.
723
+ * Errors are captured per-record (fail-isolated).
724
+ */
725
+ declare function executeBatch(records: Array<{
726
+ policyId: string;
727
+ policyVersion: string;
728
+ signals: Record<string, unknown>;
729
+ governed_time: string;
730
+ }>, signer: Signer, verifier: Verifier, replayStore: AsyncReplayStore): Promise<({
731
+ input: {
732
+ policyId: string;
733
+ policyVersion: string;
734
+ signals: Record<string, unknown>;
735
+ governed_time: string;
736
+ };
737
+ output: {
738
+ status: "pending_override";
739
+ execution_id: string;
740
+ decision: DecisionResult;
741
+ requires_override: boolean;
742
+ execution_state?: undefined;
743
+ replay?: undefined;
744
+ signature?: undefined;
745
+ error?: undefined;
746
+ } | {
747
+ status: "success";
748
+ execution_id: string;
749
+ decision: DecisionResult;
750
+ execution_state: "completed" | "blocked";
751
+ requires_override: boolean;
752
+ replay: boolean;
753
+ signature?: undefined;
754
+ error?: undefined;
755
+ } | {
756
+ status: "success";
757
+ execution_id: string;
758
+ decision: DecisionResult;
759
+ execution_state: "completed" | "blocked";
760
+ requires_override: boolean;
761
+ signature: string;
762
+ replay?: undefined;
763
+ error?: undefined;
764
+ } | {
765
+ status: "error";
766
+ error: string;
767
+ execution_id?: undefined;
768
+ decision?: undefined;
769
+ requires_override?: undefined;
770
+ execution_state?: undefined;
771
+ replay?: undefined;
772
+ signature?: undefined;
773
+ };
774
+ } | {
775
+ input: {
776
+ policyId: string;
777
+ policyVersion: string;
778
+ signals: Record<string, unknown>;
779
+ governed_time: string;
780
+ };
781
+ output: {
782
+ status: string;
783
+ error: string;
784
+ };
785
+ })[]>;
786
+
787
+ declare function loadPolicy(policyId: string, policyVersion: string, basePath?: string): PolicyDocument;
788
+
789
+ declare class RedisReplayStore implements AsyncReplayStore {
790
+ private client;
791
+ constructor(url: string);
792
+ hasExecuted(executionId: string): Promise<boolean>;
793
+ markExecuted(executionId: string): Promise<void>;
794
+ get(key: string): Promise<string | null>;
795
+ set(key: string, value: string): Promise<void>;
796
+ del(key: string): Promise<void>;
797
+ close(): Promise<void>;
798
+ }
799
+
800
+ declare function resolveOverride(executionId: string, replayStore: AsyncReplayStore & {
801
+ get: (key: string) => Promise<string | null>;
802
+ del: (key: string) => Promise<void>;
803
+ }, signer: Signer, verifier: Verifier): Promise<{
804
+ status: "success";
805
+ execution_id: string;
806
+ signature: string;
807
+ resolved: boolean;
808
+ }>;
809
+
810
+ export { type AsyncReplayStore, type AsyncSigner, type AuditEntry, type DecisionResult, type DryRunResult, type ExecutionAttestation, type ExecutionContext, type ExecutionToken, FORBIDDEN_GLOBALS, INVARIANT_REGISTRY, type InvariantBoundary, type InvariantEntry, type InvariantId, InvariantViolation, LocalSigner, LocalVerifier, MemoryReplayStore, RedisReplayStore, type ReplayStore, type RuntimeManifest, SEALED_SCOPE_FILES, type Signer, type Verifier, type ViolationReport, canonicalize, evaluateDryRun, evaluatePolicy, executeBatch, executeDecision, executeFromSignals, getRuntimeManifest, governingTime, hashInput, hashRuntime, issueToken, loadPolicy, resolveOverride, runtimeManifestDefinition, signExecutionToken, signRuntimeManifest, stageExecute, stageSign, stageVerify, verifyAuditChain, verifyAuditEntry, verifyExecutionToken, verifyRuntimeManifest, verifyRuntimePolicy, violate };