@openprose/reactor-cradle 0.1.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +270 -0
  3. package/dist/assert/index.d.ts +35 -0
  4. package/dist/assert/index.d.ts.map +1 -0
  5. package/dist/assert/index.js +398 -0
  6. package/dist/baselines/cost-thesis/index.d.ts +103 -0
  7. package/dist/baselines/cost-thesis/index.d.ts.map +1 -0
  8. package/dist/baselines/cost-thesis/index.js +337 -0
  9. package/dist/baselines/naive-loop/index.d.ts +46 -0
  10. package/dist/baselines/naive-loop/index.d.ts.map +1 -0
  11. package/dist/baselines/naive-loop/index.js +188 -0
  12. package/dist/baselines/no-memo/index.d.ts +84 -0
  13. package/dist/baselines/no-memo/index.d.ts.map +1 -0
  14. package/dist/baselines/no-memo/index.js +226 -0
  15. package/dist/doubles/clock.d.ts +9 -0
  16. package/dist/doubles/clock.d.ts.map +1 -0
  17. package/dist/doubles/clock.js +42 -0
  18. package/dist/doubles/storage.d.ts +24 -0
  19. package/dist/doubles/storage.d.ts.map +1 -0
  20. package/dist/doubles/storage.js +191 -0
  21. package/dist/eval/index.d.ts +204 -0
  22. package/dist/eval/index.d.ts.map +1 -0
  23. package/dist/eval/index.js +596 -0
  24. package/dist/index.d.ts +24 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +39 -0
  27. package/dist/policy-author/index.d.ts +103 -0
  28. package/dist/policy-author/index.d.ts.map +1 -0
  29. package/dist/policy-author/index.js +358 -0
  30. package/dist/policy-drift/index.d.ts +64 -0
  31. package/dist/policy-drift/index.d.ts.map +1 -0
  32. package/dist/policy-drift/index.js +495 -0
  33. package/dist/policy-replay/index.d.ts +106 -0
  34. package/dist/policy-replay/index.d.ts.map +1 -0
  35. package/dist/policy-replay/index.js +361 -0
  36. package/dist/provider-parity/index.d.ts +91 -0
  37. package/dist/provider-parity/index.d.ts.map +1 -0
  38. package/dist/provider-parity/index.js +439 -0
  39. package/dist/recompile/index.d.ts +161 -0
  40. package/dist/recompile/index.d.ts.map +1 -0
  41. package/dist/recompile/index.js +690 -0
  42. package/dist/release-candidate/index.d.ts +139 -0
  43. package/dist/release-candidate/index.d.ts.map +1 -0
  44. package/dist/release-candidate/index.js +553 -0
  45. package/dist/release-parity/index.d.ts +80 -0
  46. package/dist/release-parity/index.d.ts.map +1 -0
  47. package/dist/release-parity/index.js +1035 -0
  48. package/dist/replay/model-gateway.d.ts +25 -0
  49. package/dist/replay/model-gateway.d.ts.map +1 -0
  50. package/dist/replay/model-gateway.js +166 -0
  51. package/dist/replay/parity.d.ts +110 -0
  52. package/dist/replay/parity.d.ts.map +1 -0
  53. package/dist/replay/parity.js +232 -0
  54. package/dist/rollback/index.d.ts +106 -0
  55. package/dist/rollback/index.d.ts.map +1 -0
  56. package/dist/rollback/index.js +694 -0
  57. package/dist/scenario/parser.d.ts +11 -0
  58. package/dist/scenario/parser.d.ts.map +1 -0
  59. package/dist/scenario/parser.js +490 -0
  60. package/dist/scenario/runner.d.ts +12 -0
  61. package/dist/scenario/runner.d.ts.map +1 -0
  62. package/dist/scenario/runner.js +345 -0
  63. package/dist/scenario/synthetic-world-adapter.d.ts +4 -0
  64. package/dist/scenario/synthetic-world-adapter.d.ts.map +1 -0
  65. package/dist/scenario/synthetic-world-adapter.js +82 -0
  66. package/dist/scenario/time.d.ts +4 -0
  67. package/dist/scenario/time.d.ts.map +1 -0
  68. package/dist/scenario/time.js +45 -0
  69. package/dist/scenario/types.d.ts +149 -0
  70. package/dist/scenario/types.d.ts.map +1 -0
  71. package/dist/scenario/types.js +5 -0
  72. package/dist/spikes/index.d.ts +10 -0
  73. package/dist/spikes/index.d.ts.map +1 -0
  74. package/dist/spikes/index.js +29 -0
  75. package/dist/spikes/k1-ensemble-spread.d.ts +88 -0
  76. package/dist/spikes/k1-ensemble-spread.d.ts.map +1 -0
  77. package/dist/spikes/k1-ensemble-spread.js +396 -0
  78. package/dist/spikes/k2-policy-author.d.ts +25 -0
  79. package/dist/spikes/k2-policy-author.d.ts.map +1 -0
  80. package/dist/spikes/k2-policy-author.js +503 -0
  81. package/dist/spikes/live-refresh.d.ts +150 -0
  82. package/dist/spikes/live-refresh.d.ts.map +1 -0
  83. package/dist/spikes/live-refresh.js +511 -0
  84. package/dist/world/index.d.ts +2 -0
  85. package/dist/world/index.d.ts.map +1 -0
  86. package/dist/world/index.js +17 -0
  87. package/dist/world/synthetic-world.d.ts +104 -0
  88. package/dist/world/synthetic-world.d.ts.map +1 -0
  89. package/dist/world/synthetic-world.js +449 -0
  90. package/package.json +139 -0
@@ -0,0 +1,495 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.POLICY_DRIFT_P2_BACKSTOP_FACT = exports.POLICY_DRIFT_P2_OFF_LOG_FACT = exports.POLICY_DRIFT_P2_COST_FACT = exports.POLICY_DRIFT_P2_RESPONSIBILITY_ID = exports.POLICY_DRIFT_P2_SCENARIO_VERSION_V0 = exports.POLICY_DRIFT_P2_SCENARIO_SCHEMA_V0 = void 0;
4
+ exports.createPolicyDriftGatewayProbeV0 = createPolicyDriftGatewayProbeV0;
5
+ exports.makeRecordedPolicyDriftP2ScenarioV0 = makeRecordedPolicyDriftP2ScenarioV0;
6
+ exports.runRecordedPolicyDriftP2ProofV0 = runRecordedPolicyDriftP2ProofV0;
7
+ exports.assertRecordedPolicyDriftP2ScenarioV0 = assertRecordedPolicyDriftP2ScenarioV0;
8
+ exports.normalizePolicyDriftResultV0 = normalizePolicyDriftResultV0;
9
+ const node_crypto_1 = require("node:crypto");
10
+ const { canonicalizeForReceiptV0, createReceiptV0, hashCanonicalReceiptV0, } = loadReactorReceipt();
11
+ const { POLICY_ARTIFACT_SCHEMA, POLICY_ARTIFACT_VERSION, POLICY_AUTHOR_HISTORY_QUERY_SCHEMA, canonicalizePolicyArtifactV0, validatePolicyArtifactV0, } = loadReactorPolicy();
12
+ exports.POLICY_DRIFT_P2_SCENARIO_SCHEMA_V0 = "openprose.reactor-cradle.policy-drift-p2-scenario";
13
+ exports.POLICY_DRIFT_P2_SCENARIO_VERSION_V0 = 0;
14
+ exports.POLICY_DRIFT_P2_RESPONSIBILITY_ID = "incident-channel-current-briefing";
15
+ exports.POLICY_DRIFT_P2_COST_FACT = "cost.fresh_tokens_per_maintained_day";
16
+ exports.POLICY_DRIFT_P2_OFF_LOG_FACT = "source.incident_channel.unrecorded_sentiment_score";
17
+ exports.POLICY_DRIFT_P2_BACKSTOP_FACT = "kernel.deep_shallow_contradiction_count_7d";
18
+ function createPolicyDriftGatewayProbeV0() {
19
+ let agentLaunchCount = 0;
20
+ let modelGatewayInvocationCount = 0;
21
+ return {
22
+ get agent_launch_count() {
23
+ return agentLaunchCount;
24
+ },
25
+ get model_gateway_invocation_count() {
26
+ return modelGatewayInvocationCount;
27
+ },
28
+ assertNoInvocations() {
29
+ if (agentLaunchCount !== 0 || modelGatewayInvocationCount !== 0) {
30
+ throw new Error(`policy drift path invoked forbidden inference gateways: agent=${agentLaunchCount}, model=${modelGatewayInvocationCount}`);
31
+ }
32
+ },
33
+ // Kept as non-enumerable implementation detail would hide the tripwire
34
+ // from fixture snapshots, so tests use the public counters above instead.
35
+ launch() {
36
+ agentLaunchCount += 1;
37
+ throw new Error("policy drift must not launch an agent SDK activation");
38
+ },
39
+ complete() {
40
+ modelGatewayInvocationCount += 1;
41
+ throw new Error("policy drift must not call the model gateway");
42
+ },
43
+ };
44
+ }
45
+ function makeRecordedPolicyDriftP2ScenarioV0() {
46
+ const contractRevision = hashText([
47
+ "kind: responsibility",
48
+ "Goal: The incident channel has a current, accurate briefing.",
49
+ "Criteria: impact, timeline, owner, next action, and customer-facing status are current.",
50
+ ].join("\n"));
51
+ const asOf = "2026-05-19T00:00:00.000Z";
52
+ const receiptHistory = makeReceiptHistory(contractRevision);
53
+ const exploredReceiptHashes = receiptHistory
54
+ .map((receipt) => receipt.content_hash)
55
+ .sort((left, right) => left.localeCompare(right));
56
+ const receiptHistorySummaryHash = hashReceiptHistorySummary(receiptHistory);
57
+ const costDriftArtifact = makePolicyArtifact({
58
+ contract_revision: contractRevision,
59
+ explored_receipt_hashes: exploredReceiptHashes,
60
+ receipt_history_summary_hash: receiptHistorySummaryHash,
61
+ falsification_fact: exports.POLICY_DRIFT_P2_COST_FACT,
62
+ falsification_value: 500,
63
+ policy_revision: "policy.p2.cost-drift.recorded",
64
+ });
65
+ const offLogArtifact = makePolicyArtifact({
66
+ contract_revision: contractRevision,
67
+ explored_receipt_hashes: exploredReceiptHashes,
68
+ receipt_history_summary_hash: receiptHistorySummaryHash,
69
+ falsification_fact: exports.POLICY_DRIFT_P2_OFF_LOG_FACT,
70
+ falsification_value: 0.75,
71
+ policy_revision: "policy.p2.off-log.recorded",
72
+ });
73
+ const costDriftArtifactBytes = canonicalizePolicyArtifactV0(costDriftArtifact);
74
+ const offLogArtifactBytes = canonicalizePolicyArtifactV0(offLogArtifact);
75
+ return {
76
+ schema: exports.POLICY_DRIFT_P2_SCENARIO_SCHEMA_V0,
77
+ v: exports.POLICY_DRIFT_P2_SCENARIO_VERSION_V0,
78
+ responsibility_id: exports.POLICY_DRIFT_P2_RESPONSIBILITY_ID,
79
+ contract_revision: contractRevision,
80
+ as_of: asOf,
81
+ receipt_history: receiptHistory,
82
+ cost_drift_artifact: costDriftArtifact,
83
+ off_log_artifact: offLogArtifact,
84
+ cost_drift_artifact_bytes: costDriftArtifactBytes,
85
+ cost_drift_artifact_content_hash: hashCanonicalReceiptV0(costDriftArtifactBytes),
86
+ off_log_artifact_bytes: offLogArtifactBytes,
87
+ off_log_artifact_content_hash: hashCanonicalReceiptV0(offLogArtifactBytes),
88
+ };
89
+ }
90
+ function runRecordedPolicyDriftP2ProofV0(input) {
91
+ const scenario = input.scenario ?? makeRecordedPolicyDriftP2ScenarioV0();
92
+ assertRecordedPolicyDriftP2ScenarioV0(scenario);
93
+ const gatewayProbe = createPolicyDriftGatewayProbeV0();
94
+ const costDrift = normalizePolicyDriftResultV0(input.evaluatePolicyDriftV0({
95
+ artifact: scenario.cost_drift_artifact,
96
+ receipts: scenario.receipt_history,
97
+ as_of: scenario.as_of,
98
+ }));
99
+ assertTrippedCostDrift(costDrift, scenario);
100
+ gatewayProbe.assertNoInvocations();
101
+ const offLog = normalizePolicyDriftResultV0(input.evaluatePolicyDriftV0({
102
+ artifact: scenario.off_log_artifact,
103
+ receipts: scenario.receipt_history,
104
+ as_of: scenario.as_of,
105
+ }));
106
+ assertIndeterminateOffLogDrift(offLog);
107
+ gatewayProbe.assertNoInvocations();
108
+ return {
109
+ scenario,
110
+ cost_drift: costDrift,
111
+ off_log: offLog,
112
+ gateway_invocations: {
113
+ agent_launch_count: 0,
114
+ model_gateway_invocation_count: 0,
115
+ },
116
+ };
117
+ }
118
+ function assertRecordedPolicyDriftP2ScenarioV0(scenario) {
119
+ if (scenario.schema !== exports.POLICY_DRIFT_P2_SCENARIO_SCHEMA_V0) {
120
+ throw new Error("policy drift P2 scenario schema is malformed");
121
+ }
122
+ if (scenario.v !== exports.POLICY_DRIFT_P2_SCENARIO_VERSION_V0) {
123
+ throw new Error("policy drift P2 scenario version must be 0");
124
+ }
125
+ if (scenario.receipt_history.length === 0) {
126
+ throw new Error("policy drift P2 scenario must include receipt history");
127
+ }
128
+ assertValidArtifact(scenario.cost_drift_artifact, scenario.cost_drift_artifact_bytes, scenario.cost_drift_artifact_content_hash);
129
+ assertValidArtifact(scenario.off_log_artifact, scenario.off_log_artifact_bytes, scenario.off_log_artifact_content_hash);
130
+ }
131
+ function normalizePolicyDriftResultV0(result) {
132
+ if (!isRecord(result)) {
133
+ throw new Error("policy drift result must be an object");
134
+ }
135
+ const outcome = readOutcome(result);
136
+ const facts = readFacts(result);
137
+ const evidenceReceiptHashes = readContentHashArrayFromUnknown(result["evidence_receipt_hashes"] ??
138
+ result["evidence_receipts"] ??
139
+ result["evidence_hashes"], "policy drift evidence receipt hashes");
140
+ const predicate = readPredicateEvaluation(result["predicate_evaluation"] ??
141
+ result["predicate"] ??
142
+ result["falsification_predicate_evaluation"]);
143
+ const missingFactIds = readStringArrayFromUnknown(result["missing_fact_ids"] ?? result["missing_facts"] ?? [], "policy drift missing fact ids");
144
+ const unsupportedFactIds = readStringArrayFromUnknown(result["unsupported_fact_ids"] ?? result["unsupported_facts"] ?? [], "policy drift unsupported fact ids");
145
+ return {
146
+ outcome,
147
+ facts,
148
+ evidence_receipt_hashes: evidenceReceiptHashes,
149
+ predicate,
150
+ missing_fact_ids: missingFactIds,
151
+ unsupported_fact_ids: unsupportedFactIds,
152
+ raw: result,
153
+ };
154
+ }
155
+ function makePolicyArtifact(input) {
156
+ return {
157
+ schema: POLICY_ARTIFACT_SCHEMA,
158
+ v: POLICY_ARTIFACT_VERSION,
159
+ responsibility_id: exports.POLICY_DRIFT_P2_RESPONSIBILITY_ID,
160
+ registry_id: "registry.incident-channel-current-briefing.p2",
161
+ policy_revision: input.policy_revision,
162
+ no_anchor: true,
163
+ live_observables: LIVE_OBSERVABLES,
164
+ cadence: {
165
+ shallow_recheck_ms: 15 * 60 * 1000,
166
+ plan_audit_ms: 6 * 60 * 60 * 1000,
167
+ deep_revalidation_ms: 7 * 24 * 60 * 60 * 1000,
168
+ },
169
+ hysteresis: {
170
+ min_recompile_interval_ms: 60 * 60 * 1000,
171
+ enter_degraded_threshold: 0.34,
172
+ exit_degraded_threshold: 0.18,
173
+ warmup_judged_activations: 5,
174
+ },
175
+ thresholds: {
176
+ max_calibration_divergence_multiplier: 1.6,
177
+ escalation_precision_floor: 0.7,
178
+ backstop_deep_contradiction_count: 99,
179
+ stale_brief_minutes: 30,
180
+ fresh_tokens_per_day_ceiling: 500,
181
+ },
182
+ transitive_freshness_function: { kind: "kernel-default" },
183
+ falsification_predicate: {
184
+ kind: "greater-than-or-equal",
185
+ fact: input.falsification_fact,
186
+ value: input.falsification_value,
187
+ },
188
+ backstop_divergence_predicate: {
189
+ kind: "greater-than-or-equal",
190
+ fact: exports.POLICY_DRIFT_P2_BACKSTOP_FACT,
191
+ value: 99,
192
+ },
193
+ provenance: {
194
+ contract_revision: input.contract_revision,
195
+ receipt_history_summary_hash: input.receipt_history_summary_hash,
196
+ explored_receipt_hashes: input.explored_receipt_hashes,
197
+ history_query: {
198
+ schema: POLICY_AUTHOR_HISTORY_QUERY_SCHEMA,
199
+ v: POLICY_ARTIFACT_VERSION,
200
+ selected_receipt_hashes: input.explored_receipt_hashes,
201
+ rationale: "recorded P2 proof pins the receipt-log slice used to evaluate policy drift",
202
+ },
203
+ },
204
+ };
205
+ }
206
+ const LIVE_OBSERVABLES = [
207
+ {
208
+ id: exports.POLICY_DRIFT_P2_COST_FACT,
209
+ source: "cost-ledger",
210
+ description: "fresh maintenance tokens per maintained day from receipt cost facts",
211
+ },
212
+ {
213
+ id: exports.POLICY_DRIFT_P2_BACKSTOP_FACT,
214
+ source: "kernel-backstop",
215
+ description: "B2 deep-vs-shallow contradiction count over the trailing seven days",
216
+ },
217
+ {
218
+ id: "receipt.escalation_precision_7d",
219
+ source: "receipt-log",
220
+ description: "precision of escalation receipts over the trailing seven days",
221
+ },
222
+ {
223
+ id: exports.POLICY_DRIFT_P2_OFF_LOG_FACT,
224
+ source: "connector",
225
+ description: "live incident-channel signal deliberately absent from the receipt log",
226
+ },
227
+ ];
228
+ function makeReceiptHistory(contractRevision) {
229
+ return [
230
+ makeReceipt({
231
+ contract_revision: contractRevision,
232
+ memo_key: "memo:bootstrap",
233
+ as_of: "2026-05-18T00:00:00.000Z",
234
+ next_forecast_recheck: "2026-05-18T06:00:00.000Z",
235
+ event_cause: "real-input",
236
+ role: "judge",
237
+ evidence_input_ids: [hashText("incident-bootstrap-evidence")],
238
+ status: "up",
239
+ fresh: 900,
240
+ reused: 0,
241
+ tags: ["policy-drift-p2", "bootstrap"],
242
+ }),
243
+ makeReceipt({
244
+ contract_revision: contractRevision,
245
+ memo_key: "memo:forecast-recheck",
246
+ as_of: "2026-05-18T12:00:00.000Z",
247
+ next_forecast_recheck: "2026-05-19T00:00:00.000Z",
248
+ event_cause: "forecast-recheck",
249
+ role: "judge",
250
+ evidence_input_ids: [hashText("incident-plan-age-evidence")],
251
+ status: "up",
252
+ fresh: 450,
253
+ reused: 320,
254
+ tags: ["policy-drift-p2", "plan-age"],
255
+ }),
256
+ makeReceipt({
257
+ contract_revision: contractRevision,
258
+ memo_key: "memo:escalation-review",
259
+ as_of: "2026-05-18T18:00:00.000Z",
260
+ next_forecast_recheck: "2026-05-19T00:00:00.000Z",
261
+ event_cause: "escalation",
262
+ role: "judge",
263
+ evidence_input_ids: [hashText("incident-escalation-evidence")],
264
+ status: "blocked",
265
+ fresh: 375,
266
+ reused: 0,
267
+ tags: ["policy-drift-p2", "escalation"],
268
+ }),
269
+ ];
270
+ }
271
+ function makeReceipt(input) {
272
+ return createReceiptV0({
273
+ core: {
274
+ responsibility_id: exports.POLICY_DRIFT_P2_RESPONSIBILITY_ID,
275
+ contract_revision: input.contract_revision,
276
+ event_cause: input.event_cause,
277
+ ...(input.event_cause === "forecast-recheck"
278
+ ? { recheck_kind: "plan-age" }
279
+ : {}),
280
+ memo_key: input.memo_key,
281
+ evidence_input_ids: input.evidence_input_ids,
282
+ as_of: input.as_of,
283
+ role: input.role,
284
+ },
285
+ sig: {
286
+ scheme: "none",
287
+ null_reason: "cradle recorded P2 policy-drift proof",
288
+ },
289
+ verdict: {
290
+ status: input.status,
291
+ confidence: {
292
+ value: input.status === "blocked" ? 0 : 0.82,
293
+ derivation_method: "recorded-cradle-policy-drift-fixture",
294
+ calibration_grade: "none",
295
+ label_source: "none",
296
+ },
297
+ ...(input.status === "blocked"
298
+ ? {
299
+ blocked: {
300
+ reason: "recorded escalation review exceeded cost budget",
301
+ fix_target: "policy-artifact",
302
+ interrupt_cause: "needs-judgment",
303
+ },
304
+ }
305
+ : {}),
306
+ },
307
+ freshness: {
308
+ as_of: input.as_of,
309
+ next_forecast_recheck: input.next_forecast_recheck,
310
+ },
311
+ composition: {
312
+ consumed_receipts: [],
313
+ cycle_checked: true,
314
+ },
315
+ cost: {
316
+ provider: "cradle",
317
+ model: "recorded-policy-drift-fixture",
318
+ role: input.role,
319
+ tags: input.tags,
320
+ responsibility_id: exports.POLICY_DRIFT_P2_RESPONSIBILITY_ID,
321
+ run_id: "policy-drift-p2-recorded",
322
+ as_of: input.as_of,
323
+ tokens: {
324
+ fresh: input.fresh,
325
+ reused: input.reused,
326
+ },
327
+ surprise_cause: input.event_cause,
328
+ },
329
+ });
330
+ }
331
+ function assertValidArtifact(artifact, expectedBytes, expectedContentHash) {
332
+ const validation = validatePolicyArtifactV0(artifact);
333
+ if (!validation.ok) {
334
+ throw new Error(`recorded policy drift artifact is invalid: ${validation.errors.join("; ")}`);
335
+ }
336
+ if (validation.bytes !== expectedBytes) {
337
+ throw new Error("recorded policy drift artifact bytes are not canonical");
338
+ }
339
+ if (validation.content_hash !== expectedContentHash) {
340
+ throw new Error("recorded policy drift artifact content hash is stale");
341
+ }
342
+ }
343
+ function assertTrippedCostDrift(result, scenario) {
344
+ if (result.outcome !== "tripped") {
345
+ throw new Error(`expected cost drift predicate to trip, received ${result.outcome}`);
346
+ }
347
+ if (result.predicate.outcome !== "tripped") {
348
+ throw new Error(`expected cost drift predicate evaluation to trip, received ${result.predicate.outcome}`);
349
+ }
350
+ const costFact = result.facts[exports.POLICY_DRIFT_P2_COST_FACT];
351
+ if (typeof costFact !== "number" || costFact < 500) {
352
+ throw new Error("cost drift proof must expose the tripping receipt-log cost fact");
353
+ }
354
+ assertEvidenceSubset(result.evidence_receipt_hashes, scenario.receipt_history);
355
+ }
356
+ function assertIndeterminateOffLogDrift(result) {
357
+ if (result.outcome !== "indeterminate") {
358
+ throw new Error(`expected off-log live observable to be indeterminate, received ${result.outcome}`);
359
+ }
360
+ if (result.predicate.outcome !== "indeterminate") {
361
+ throw new Error(`expected off-log predicate evaluation to be indeterminate, received ${result.predicate.outcome}`);
362
+ }
363
+ const missingOrUnsupported = new Set([
364
+ ...result.missing_fact_ids,
365
+ ...result.unsupported_fact_ids,
366
+ ]);
367
+ if (!missingOrUnsupported.has(exports.POLICY_DRIFT_P2_OFF_LOG_FACT)) {
368
+ throw new Error("off-log drift proof must name the missing live observable fact");
369
+ }
370
+ }
371
+ function assertEvidenceSubset(evidenceReceiptHashes, receiptHistory) {
372
+ if (evidenceReceiptHashes.length === 0) {
373
+ throw new Error("policy drift proof must expose evidence receipt hashes");
374
+ }
375
+ const knownHashes = new Set(receiptHistory.map((receipt) => receipt.content_hash));
376
+ const unknown = evidenceReceiptHashes.filter((hash) => !knownHashes.has(hash));
377
+ if (unknown.length > 0) {
378
+ throw new Error(`policy drift proof referenced receipts outside the recorded log: ${unknown.join(", ")}`);
379
+ }
380
+ }
381
+ function readOutcome(result) {
382
+ const value = result["outcome"] ?? result["status"];
383
+ if (value === "not-tripped" ||
384
+ value === "tripped" ||
385
+ value === "indeterminate") {
386
+ return value;
387
+ }
388
+ throw new Error("policy drift result outcome must be not-tripped, tripped, or indeterminate");
389
+ }
390
+ function readFacts(result) {
391
+ const value = result["facts"] ?? result["evaluated_facts"] ?? result["derived_facts"];
392
+ if (!isRecord(value)) {
393
+ throw new Error("policy drift result must expose evaluated facts");
394
+ }
395
+ const facts = {};
396
+ for (const [key, factValue] of Object.entries(value)) {
397
+ if (!isKernelFactValue(factValue)) {
398
+ throw new Error(`policy drift fact ${key} has unsupported value type`);
399
+ }
400
+ facts[key] = factValue;
401
+ }
402
+ return facts;
403
+ }
404
+ function readPredicateEvaluation(value) {
405
+ if (!isRecord(value)) {
406
+ throw new Error("policy drift result must expose predicate evaluation");
407
+ }
408
+ const outcome = value["outcome"];
409
+ if (outcome !== "not-tripped" &&
410
+ outcome !== "tripped" &&
411
+ outcome !== "indeterminate") {
412
+ throw new Error("policy drift predicate evaluation outcome is malformed");
413
+ }
414
+ const reason = value["reason"];
415
+ if (reason !== undefined && typeof reason !== "string") {
416
+ throw new Error("policy drift predicate evaluation reason must be a string");
417
+ }
418
+ return {
419
+ outcome,
420
+ ...(reason === undefined ? {} : { reason }),
421
+ };
422
+ }
423
+ function readContentHashArrayFromUnknown(value, label) {
424
+ const values = readStringArrayFromUnknown(value, label);
425
+ const malformed = values.find((item) => !isContentHash(item));
426
+ if (malformed !== undefined) {
427
+ throw new Error(`${label} contains non-content-hash value ${malformed}`);
428
+ }
429
+ return values;
430
+ }
431
+ function readStringArrayFromUnknown(value, label) {
432
+ if (!Array.isArray(value)) {
433
+ throw new Error(`${label} must be an array`);
434
+ }
435
+ if (!value.every((item) => typeof item === "string" && item.length > 0)) {
436
+ throw new Error(`${label} must contain non-empty strings`);
437
+ }
438
+ return Object.freeze([...value]);
439
+ }
440
+ function hashReceiptHistorySummary(receiptHistory) {
441
+ return hashCanonicalReceiptV0(canonicalizeForReceiptV0(receiptHistory.map((receipt) => ({
442
+ content_hash: receipt.content_hash,
443
+ contract_revision: receipt.core.contract_revision,
444
+ as_of: receipt.core.as_of,
445
+ role: receipt.core.role,
446
+ event_cause: receipt.core.event_cause,
447
+ verdict_status: receipt.verdict.status,
448
+ next_forecast_recheck: receipt.freshness.next_forecast_recheck,
449
+ surprise_cause: receipt.cost.surprise_cause,
450
+ fresh_tokens: receipt.cost.tokens.fresh,
451
+ }))));
452
+ }
453
+ function isKernelFactValue(value) {
454
+ return (value === null ||
455
+ typeof value === "string" ||
456
+ typeof value === "number" ||
457
+ typeof value === "boolean");
458
+ }
459
+ function isContentHash(value) {
460
+ return /^sha256:[a-f0-9]{64}$/.test(value);
461
+ }
462
+ function hashText(value) {
463
+ return `sha256:${(0, node_crypto_1.createHash)("sha256").update(value).digest("hex")}`;
464
+ }
465
+ function isRecord(value) {
466
+ return typeof value === "object" && value !== null && !Array.isArray(value);
467
+ }
468
+ function loadReactorReceipt() {
469
+ try {
470
+ return require("@openprose/reactor/receipt");
471
+ }
472
+ catch (error) {
473
+ if (isMissingReactorSubpath(error, "@openprose/reactor/receipt")) {
474
+ return require("../../../reactor/dist/receipt");
475
+ }
476
+ throw error;
477
+ }
478
+ }
479
+ function loadReactorPolicy() {
480
+ try {
481
+ return require("@openprose/reactor/policy");
482
+ }
483
+ catch (error) {
484
+ if (isMissingReactorSubpath(error, "@openprose/reactor/policy")) {
485
+ return require("../../../reactor/dist/policy");
486
+ }
487
+ throw error;
488
+ }
489
+ }
490
+ function isMissingReactorSubpath(error, subpath) {
491
+ return (isRecord(error) &&
492
+ error["code"] === "MODULE_NOT_FOUND" &&
493
+ typeof error["message"] === "string" &&
494
+ error["message"].includes(subpath));
495
+ }
@@ -0,0 +1,106 @@
1
+ import type { AuthoredPolicyArtifactV0 } from "@openprose/reactor/policy";
2
+ import type { ContentHashV0, ReceiptV0 } from "@openprose/reactor/receipt";
3
+ import type { ReactorAgentSdkAdapterV0, ReactorModelGatewayAdapterV0, ReactorRegistrySnapshotV0 } from "@openprose/reactor/sdk";
4
+ import { type NormalizedPolicyRecompileDecisionV0, type PlanPolicyRecompileV0 } from "../recompile";
5
+ export declare const POLICY_REPLAY_P5_SCENARIO_SCHEMA_V0: "openprose.reactor-cradle.policy-replay-p5-scenario";
6
+ export declare const POLICY_REPLAY_P5_SCENARIO_VERSION_V0: 0;
7
+ export type PolicyReplayArtifactSourceV0 = "recorded-registry-snapshot-bytes";
8
+ export interface RecordedPolicyReplayP5ScenarioV0 {
9
+ readonly schema: typeof POLICY_REPLAY_P5_SCENARIO_SCHEMA_V0;
10
+ readonly v: typeof POLICY_REPLAY_P5_SCENARIO_VERSION_V0;
11
+ readonly responsibility_id: string;
12
+ readonly contract_revision: ContentHashV0;
13
+ readonly as_of: string;
14
+ readonly last_recompile_at: string;
15
+ readonly last_policy_revalidated_at: string;
16
+ readonly last_unforced_deep_at: string;
17
+ readonly source_policy_loop: "p3-recorded-recompile";
18
+ readonly receipt_history: readonly ReceiptV0[];
19
+ readonly recorded_registry_snapshot: ReactorRegistrySnapshotV0;
20
+ readonly recorded_policy_artifact_bytes: string;
21
+ readonly recorded_policy_artifact_content_hash: ContentHashV0;
22
+ }
23
+ export interface RecordedPolicyArtifactReplayAuthorityV0 {
24
+ readonly source: PolicyReplayArtifactSourceV0;
25
+ readonly artifact: AuthoredPolicyArtifactV0;
26
+ readonly bytes: string;
27
+ readonly content_hash: ContentHashV0;
28
+ readonly byte_length: number;
29
+ readonly namespace: string;
30
+ readonly registry_id: string;
31
+ readonly revision: string;
32
+ readonly validation_state: "validated";
33
+ readonly artifact_bytes_canonical: true;
34
+ readonly content_hash_verified: true;
35
+ }
36
+ export type PolicyReplayForbiddenAuthorV0 = (input: unknown) => Promise<ReactorRegistrySnapshotV0> | ReactorRegistrySnapshotV0;
37
+ export interface PolicyReplayWithheldGatewayProbeV0 {
38
+ readonly agentSdk: Pick<ReactorAgentSdkAdapterV0, "launch">;
39
+ readonly agent_sdk: Pick<ReactorAgentSdkAdapterV0, "launch">;
40
+ readonly modelGateway: Pick<ReactorModelGatewayAdapterV0, "invoke">;
41
+ readonly model_gateway: Pick<ReactorModelGatewayAdapterV0, "invoke">;
42
+ readonly authorPolicyArtifactV0: PolicyReplayForbiddenAuthorV0;
43
+ readonly author_policy_artifact_v0: PolicyReplayForbiddenAuthorV0;
44
+ readonly agent_launch_count: number;
45
+ readonly model_gateway_invocation_count: number;
46
+ readonly policy_author_invocation_count: number;
47
+ readonly assertNoInvocations: () => void;
48
+ }
49
+ export interface RecordedPolicyReplayRunInputV0 {
50
+ readonly artifact: AuthoredPolicyArtifactV0;
51
+ readonly policy_artifact: AuthoredPolicyArtifactV0;
52
+ readonly recorded_registry_snapshot: ReactorRegistrySnapshotV0;
53
+ readonly recorded_artifact_bytes: string;
54
+ readonly recorded_policy_artifact_bytes: string;
55
+ readonly recorded_artifact_content_hash: ContentHashV0;
56
+ readonly recorded_policy_artifact_content_hash: ContentHashV0;
57
+ readonly receipt_history: readonly ReceiptV0[];
58
+ readonly receipts: readonly ReceiptV0[];
59
+ readonly as_of: string;
60
+ readonly last_recompile_at: string;
61
+ readonly last_policy_recompile_at: string;
62
+ readonly last_policy_revalidated_at: string;
63
+ readonly last_unforced_deep_at: string;
64
+ readonly responsibility_id: string;
65
+ readonly contract_revision: ContentHashV0;
66
+ readonly policy_artifact_namespace: string;
67
+ readonly policy_artifact_revision: string;
68
+ readonly author_input: {
69
+ readonly responsibility_id: string;
70
+ readonly contract_revision: ContentHashV0;
71
+ readonly receipt_history: readonly ReceiptV0[];
72
+ readonly receipts: readonly ReceiptV0[];
73
+ readonly as_of: string;
74
+ readonly policy_artifact_namespace: string;
75
+ readonly agentSdk: Pick<ReactorAgentSdkAdapterV0, "launch">;
76
+ };
77
+ readonly agentSdk: Pick<ReactorAgentSdkAdapterV0, "launch">;
78
+ readonly agent_sdk: Pick<ReactorAgentSdkAdapterV0, "launch">;
79
+ readonly modelGateway: Pick<ReactorModelGatewayAdapterV0, "invoke">;
80
+ readonly model_gateway: Pick<ReactorModelGatewayAdapterV0, "invoke">;
81
+ readonly authorPolicyArtifactV0: PolicyReplayForbiddenAuthorV0;
82
+ readonly author_policy_artifact_v0: PolicyReplayForbiddenAuthorV0;
83
+ }
84
+ export type ReplayRecordedPolicyArtifactV0 = (input: RecordedPolicyReplayRunInputV0) => Promise<unknown> | unknown;
85
+ export interface RecordedPolicyReplayP5ProofV0 {
86
+ readonly scenario: RecordedPolicyReplayP5ScenarioV0;
87
+ readonly replay_authority: RecordedPolicyArtifactReplayAuthorityV0;
88
+ readonly replay_decision: NormalizedPolicyRecompileDecisionV0;
89
+ readonly raw_replay_result: unknown;
90
+ readonly gateway_invocations: {
91
+ readonly agent_launch_count: 0;
92
+ readonly model_gateway_invocation_count: 0;
93
+ };
94
+ readonly policy_author_invocation_count: 0;
95
+ }
96
+ export interface RunRecordedPolicyReplayP5ProofInputV0 {
97
+ readonly replayRecordedPolicyV0: ReplayRecordedPolicyArtifactV0;
98
+ readonly scenario?: RecordedPolicyReplayP5ScenarioV0;
99
+ }
100
+ export declare function makeRecordedPolicyReplayP5ScenarioV0(): RecordedPolicyReplayP5ScenarioV0;
101
+ export declare function assertRecordedPolicyReplayP5ScenarioV0(scenario: RecordedPolicyReplayP5ScenarioV0): void;
102
+ export declare function readRecordedPolicyArtifactFromRegistryV0(snapshot: ReactorRegistrySnapshotV0): RecordedPolicyArtifactReplayAuthorityV0;
103
+ export declare function createPolicyReplayP5WithheldGatewayProbeV0(): PolicyReplayWithheldGatewayProbeV0;
104
+ export declare function createRecordedArtifactPolicyRecompileReplayV0(planPolicyRecompileV0: PlanPolicyRecompileV0): ReplayRecordedPolicyArtifactV0;
105
+ export declare function runRecordedPolicyReplayP5ProofV0(input: RunRecordedPolicyReplayP5ProofInputV0): Promise<RecordedPolicyReplayP5ProofV0>;
106
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/policy-replay/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,KAAK,EAGV,wBAAwB,EACxB,4BAA4B,EAG5B,yBAAyB,EAC1B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,KAAK,mCAAmC,EACxC,KAAK,qBAAqB,EAG3B,MAAM,cAAc,CAAC;AAMtB,eAAO,MAAM,mCAAmC,EAC9C,oDAA6D,CAAC;AAChE,eAAO,MAAM,oCAAoC,EAAG,CAAU,CAAC;AAE/D,MAAM,MAAM,4BAA4B,GACtC,kCAAkC,CAAC;AAErC,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,MAAM,EAAE,OAAO,mCAAmC,CAAC;IAC5D,QAAQ,CAAC,CAAC,EAAE,OAAO,oCAAoC,CAAC;IACxD,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,iBAAiB,EAAE,aAAa,CAAC;IAC1C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,C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