@openprose/reactor 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 (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +231 -0
  3. package/dist/adapters/agent-sdk-passthrough/index.d.ts +8 -0
  4. package/dist/adapters/agent-sdk-passthrough/index.d.ts.map +1 -0
  5. package/dist/adapters/agent-sdk-passthrough/index.js +25 -0
  6. package/dist/adapters/clock-system/index.d.ts +9 -0
  7. package/dist/adapters/clock-system/index.d.ts.map +1 -0
  8. package/dist/adapters/clock-system/index.js +39 -0
  9. package/dist/adapters/connector-static/index.d.ts +11 -0
  10. package/dist/adapters/connector-static/index.d.ts.map +1 -0
  11. package/dist/adapters/connector-static/index.js +35 -0
  12. package/dist/adapters/event-sink-memory/index.d.ts +10 -0
  13. package/dist/adapters/event-sink-memory/index.d.ts.map +1 -0
  14. package/dist/adapters/event-sink-memory/index.js +20 -0
  15. package/dist/adapters/index.d.ts +10 -0
  16. package/dist/adapters/index.d.ts.map +1 -0
  17. package/dist/adapters/index.js +25 -0
  18. package/dist/adapters/json.d.ts +3 -0
  19. package/dist/adapters/json.d.ts.map +1 -0
  20. package/dist/adapters/json.js +61 -0
  21. package/dist/adapters/model-gateway-record-replay/index.d.ts +24 -0
  22. package/dist/adapters/model-gateway-record-replay/index.d.ts.map +1 -0
  23. package/dist/adapters/model-gateway-record-replay/index.js +55 -0
  24. package/dist/adapters/sandbox-null/index.d.ts +3 -0
  25. package/dist/adapters/sandbox-null/index.d.ts.map +1 -0
  26. package/dist/adapters/sandbox-null/index.js +8 -0
  27. package/dist/adapters/storage-fs/index.d.ts +14 -0
  28. package/dist/adapters/storage-fs/index.d.ts.map +1 -0
  29. package/dist/adapters/storage-fs/index.js +65 -0
  30. package/dist/adapters/storage-memory/index.d.ts +11 -0
  31. package/dist/adapters/storage-memory/index.d.ts.map +1 -0
  32. package/dist/adapters/storage-memory/index.js +34 -0
  33. package/dist/adapters/types.d.ts +22 -0
  34. package/dist/adapters/types.d.ts.map +1 -0
  35. package/dist/adapters/types.js +97 -0
  36. package/dist/composition/index.d.ts +79 -0
  37. package/dist/composition/index.d.ts.map +1 -0
  38. package/dist/composition/index.js +280 -0
  39. package/dist/cost/index.d.ts +49 -0
  40. package/dist/cost/index.d.ts.map +1 -0
  41. package/dist/cost/index.js +206 -0
  42. package/dist/evidence-plan/index.d.ts +57 -0
  43. package/dist/evidence-plan/index.d.ts.map +1 -0
  44. package/dist/evidence-plan/index.js +164 -0
  45. package/dist/forecast/index.d.ts +39 -0
  46. package/dist/forecast/index.d.ts.map +1 -0
  47. package/dist/forecast/index.js +119 -0
  48. package/dist/index.d.ts +14 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +29 -0
  51. package/dist/judge/index.d.ts +29 -0
  52. package/dist/judge/index.d.ts.map +1 -0
  53. package/dist/judge/index.js +138 -0
  54. package/dist/kernel/index.d.ts +170 -0
  55. package/dist/kernel/index.d.ts.map +1 -0
  56. package/dist/kernel/index.js +637 -0
  57. package/dist/memo/index.d.ts +59 -0
  58. package/dist/memo/index.d.ts.map +1 -0
  59. package/dist/memo/index.js +189 -0
  60. package/dist/policy/index.d.ts +249 -0
  61. package/dist/policy/index.d.ts.map +1 -0
  62. package/dist/policy/index.js +1463 -0
  63. package/dist/projection/index.d.ts +119 -0
  64. package/dist/projection/index.d.ts.map +1 -0
  65. package/dist/projection/index.js +506 -0
  66. package/dist/reactor/index.d.ts +54 -0
  67. package/dist/reactor/index.d.ts.map +1 -0
  68. package/dist/reactor/index.js +1861 -0
  69. package/dist/receipt/index.d.ts +190 -0
  70. package/dist/receipt/index.d.ts.map +1 -0
  71. package/dist/receipt/index.js +646 -0
  72. package/dist/sdk/exit-bundle.d.ts +144 -0
  73. package/dist/sdk/exit-bundle.d.ts.map +1 -0
  74. package/dist/sdk/exit-bundle.js +1034 -0
  75. package/dist/sdk/index.d.ts +201 -0
  76. package/dist/sdk/index.d.ts.map +1 -0
  77. package/dist/sdk/index.js +418 -0
  78. package/package.json +89 -0
@@ -0,0 +1,49 @@
1
+ import type { ReceiptEventCauseV0, ReceiptRecheckKindV0, ReceiptV0 } from "../receipt";
2
+ export declare const ALLOWED_SURPRISE_CAUSES_V0: readonly ["real-input", "forecast-recheck", "escalation"];
3
+ export type CostRelationshipV0 = "surprise-attribution-complete" | "flat-spend-under-static";
4
+ export type CostEvaluationIssueCodeV0 = "receipt-not-object" | "core-not-object" | "core-event-cause-invalid" | "cost-not-object" | "tokens-not-object" | "tokens-invalid" | "surprise-cause-missing" | "surprise-cause-invalid" | "surprise-cause-multiple" | "surprise-cause-mismatch" | "bootstrap-receipt-count-invalid" | "world-profile-not-static" | "token-bearing-evidence-missing" | "post-bootstrap-fresh-spend";
5
+ export interface CostEvaluationIssueV0 {
6
+ readonly path: string;
7
+ readonly code: CostEvaluationIssueCodeV0;
8
+ readonly message: string;
9
+ readonly observed: unknown;
10
+ }
11
+ export interface ReceiptCostObservationV0 {
12
+ readonly path: string;
13
+ readonly token_bearing: boolean;
14
+ readonly fresh: number;
15
+ readonly reused: number;
16
+ readonly surprise_cause: ReceiptEventCauseV0;
17
+ readonly recheck_kind: ReceiptRecheckKindV0 | null;
18
+ readonly content_hash: string | null;
19
+ }
20
+ export interface ReceiptSurpriseAttributionCheckV0 {
21
+ readonly ok: boolean;
22
+ readonly issues: readonly CostEvaluationIssueV0[];
23
+ readonly observation: ReceiptCostObservationV0 | null;
24
+ }
25
+ export interface CostRelationshipEvaluationV0 {
26
+ readonly ok: boolean;
27
+ readonly relationship: CostRelationshipV0;
28
+ readonly summary: string;
29
+ readonly issues: readonly CostEvaluationIssueV0[];
30
+ readonly checked: {
31
+ readonly receipts: number;
32
+ readonly token_bearing_receipts: number;
33
+ readonly post_bootstrap_token_bearing_receipts: number;
34
+ readonly plan_age_audit_floor_receipts: number;
35
+ };
36
+ }
37
+ export interface FlatSpendUnderStaticInputV0 {
38
+ readonly receipts: readonly unknown[];
39
+ readonly bootstrap_receipt_count?: number;
40
+ readonly world_profile?: string;
41
+ }
42
+ export declare function isAllowedSurpriseCauseV0(value: unknown): value is ReceiptEventCauseV0;
43
+ export declare function isTokenBearingReceiptV0(receipt: Pick<ReceiptV0, "cost">): boolean;
44
+ export declare function validateReceiptSurpriseAttributionV0(receipt: unknown, path?: string): ReceiptSurpriseAttributionCheckV0;
45
+ export declare const validateReceiptSurpriseCauseV0: typeof validateReceiptSurpriseAttributionV0;
46
+ export declare function evaluateSurpriseAttributionCompleteV0(receipts: readonly unknown[]): CostRelationshipEvaluationV0;
47
+ export declare function evaluateFlatSpendUnderStaticV0(input: FlatSpendUnderStaticInputV0): CostRelationshipEvaluationV0;
48
+ export declare function isPlanAgeAuditObservationV0(observation: Pick<ReceiptCostObservationV0, "surprise_cause" | "recheck_kind">): boolean;
49
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cost/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,SAAS,EACV,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,0BAA0B,2DAIa,CAAC;AAErD,MAAM,MAAM,kBAAkB,GAC1B,+BAA+B,GAC/B,yBAAyB,CAAC;AAE9B,MAAM,MAAM,yBAAyB,GACjC,oBAAoB,GACpB,iBAAiB,GACjB,0BAA0B,GAC1B,iBAAiB,GACjB,mBAAmB,GACnB,gBAAgB,GAChB,wBAAwB,GACxB,wBAAwB,GACxB,yBAAyB,GACzB,yBAAyB,GACzB,iCAAiC,GACjC,0BAA0B,GAC1B,gCAAgC,GAChC,4BAA4B,CAAC;AAEjC,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,yBAAyB,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QA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CACjC;AAUD,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,mBAAmB,CAK9B;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,GAC/B,OAAO,CAET;AAED,wBAAgB,oCAAoC,CAClD,OAAO,EAAE,OAAO,EAChB,IAAI,SAAY,GACf,iCAAiC,CAqEnC;AAED,eAAO,MAAM,8BAA8B,6CACL,CAAC;AAEvC,wBAAgB,qCAAqC,CACnD,QAAQ,EAAE,SAAS,OAAO,EAAE,GAC3B,4BAA4B,CAkC9B;AAED,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,2BAA2B,GACjC,4BAA4B,CA4F9B;AAED,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,IAAI,CACf,wBAAwB,EACxB,gBAAgB,GAAG,cAAc,CAClC,GACA,OAAO,CAKT"}
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateReceiptSurpriseCauseV0 = exports.ALLOWED_SURPRISE_CAUSES_V0 = void 0;
4
+ exports.isAllowedSurpriseCauseV0 = isAllowedSurpriseCauseV0;
5
+ exports.isTokenBearingReceiptV0 = isTokenBearingReceiptV0;
6
+ exports.validateReceiptSurpriseAttributionV0 = validateReceiptSurpriseAttributionV0;
7
+ exports.evaluateSurpriseAttributionCompleteV0 = evaluateSurpriseAttributionCompleteV0;
8
+ exports.evaluateFlatSpendUnderStaticV0 = evaluateFlatSpendUnderStaticV0;
9
+ exports.isPlanAgeAuditObservationV0 = isPlanAgeAuditObservationV0;
10
+ exports.ALLOWED_SURPRISE_CAUSES_V0 = Object.freeze([
11
+ "real-input",
12
+ "forecast-recheck",
13
+ "escalation",
14
+ ]);
15
+ const ALLOWED_SURPRISE_CAUSE_SET = new Set(exports.ALLOWED_SURPRISE_CAUSES_V0);
16
+ const ALLOWED_RECHECK_KIND_SET = new Set([
17
+ "evidence-age",
18
+ "plan-age",
19
+ ]);
20
+ function isAllowedSurpriseCauseV0(value) {
21
+ return (typeof value === "string" &&
22
+ ALLOWED_SURPRISE_CAUSE_SET.has(value));
23
+ }
24
+ function isTokenBearingReceiptV0(receipt) {
25
+ return receipt.cost.tokens.fresh + receipt.cost.tokens.reused > 0;
26
+ }
27
+ function validateReceiptSurpriseAttributionV0(receipt, path = "receipt") {
28
+ const issues = [];
29
+ if (!isRecord(receipt)) {
30
+ return {
31
+ ok: false,
32
+ issues: [
33
+ issue(path, "receipt-not-object", "receipt must be an object before cost attribution can be evaluated", receipt),
34
+ ],
35
+ observation: null,
36
+ };
37
+ }
38
+ const cost = readRecord(receipt, "cost", path, "cost-not-object", issues);
39
+ const core = readRecord(receipt, "core", path, "core-not-object", issues);
40
+ if (cost === undefined || core === undefined) {
41
+ return { ok: false, issues: Object.freeze([...issues]), observation: null };
42
+ }
43
+ const tokenSpend = readTokenSpend(cost, `${path}.cost`, issues);
44
+ const coreEventCause = readCoreEventCause(core, `${path}.core`, issues);
45
+ const surpriseCause = readExactlyOneSurpriseCause(cost, `${path}.cost`, issues);
46
+ if (surpriseCause !== undefined &&
47
+ coreEventCause !== undefined &&
48
+ surpriseCause !== coreEventCause) {
49
+ issues.push(issue(`${path}.cost.surprise_cause`, "surprise-cause-mismatch", "cost.surprise_cause must match receipt core.event_cause", { surprise_cause: surpriseCause, event_cause: coreEventCause }));
50
+ }
51
+ const recheckKind = readRecheckKind(core, `${path}.core`);
52
+ if (tokenSpend === undefined ||
53
+ surpriseCause === undefined ||
54
+ coreEventCause === undefined) {
55
+ return { ok: false, issues: Object.freeze([...issues]), observation: null };
56
+ }
57
+ const observation = {
58
+ path: `${path}.cost`,
59
+ token_bearing: tokenSpend.fresh + tokenSpend.reused > 0,
60
+ fresh: tokenSpend.fresh,
61
+ reused: tokenSpend.reused,
62
+ surprise_cause: surpriseCause,
63
+ recheck_kind: recheckKind,
64
+ content_hash: typeof receipt["content_hash"] === "string" ? receipt["content_hash"] : null,
65
+ };
66
+ return {
67
+ ok: issues.length === 0,
68
+ issues: Object.freeze([...issues]),
69
+ observation,
70
+ };
71
+ }
72
+ exports.validateReceiptSurpriseCauseV0 = validateReceiptSurpriseAttributionV0;
73
+ function evaluateSurpriseAttributionCompleteV0(receipts) {
74
+ const checks = receipts.map((receipt, index) => validateReceiptSurpriseAttributionV0(receipt, `receipts[${index}]`));
75
+ const observations = checks.flatMap((check) => check.observation === null ? [] : [check.observation]);
76
+ const tokenBearing = observations.filter((observation) => observation.token_bearing);
77
+ const issues = checks.flatMap((check) => check.issues);
78
+ if (tokenBearing.length === 0) {
79
+ issues.push(issue("receipts", "token-bearing-evidence-missing", "surprise attribution needs at least one token-bearing receipt", { receipts: receipts.length }));
80
+ }
81
+ return relationshipResult("surprise-attribution-complete", issues.length === 0
82
+ ? "all token-bearing receipts name exactly one allowed surprise cause"
83
+ : "one or more token-bearing receipts failed surprise attribution", receipts.length, tokenBearing.length, 0, 0, issues);
84
+ }
85
+ function evaluateFlatSpendUnderStaticV0(input) {
86
+ const issues = [];
87
+ const bootstrapReceiptCount = input.bootstrap_receipt_count ?? 1;
88
+ if (!Number.isSafeInteger(bootstrapReceiptCount) ||
89
+ bootstrapReceiptCount < 0) {
90
+ issues.push(issue("bootstrap_receipt_count", "bootstrap-receipt-count-invalid", "bootstrap_receipt_count must be a non-negative safe integer", bootstrapReceiptCount));
91
+ }
92
+ if (input.world_profile !== undefined &&
93
+ input.world_profile !== "static") {
94
+ issues.push(issue("world_profile", "world-profile-not-static", "flat-spend-under-static only applies to static world runs", input.world_profile));
95
+ }
96
+ const checks = input.receipts.map((receipt, index) => validateReceiptSurpriseAttributionV0(receipt, `receipts[${index}]`));
97
+ issues.push(...checks.flatMap((check) => check.issues));
98
+ const observations = checks.flatMap((check) => check.observation === null ? [] : [check.observation]);
99
+ const tokenBearing = observations.filter((observation) => observation.token_bearing);
100
+ const safeBootstrapReceiptCount = Number.isSafeInteger(bootstrapReceiptCount) && bootstrapReceiptCount >= 0
101
+ ? bootstrapReceiptCount
102
+ : 0;
103
+ const postBootstrap = tokenBearing.slice(safeBootstrapReceiptCount);
104
+ if (tokenBearing.length === 0) {
105
+ issues.push(issue("receipts", "token-bearing-evidence-missing", "flat-spend-under-static needs token-bearing receipt evidence", { receipts: input.receipts.length }));
106
+ }
107
+ for (const observation of postBootstrap) {
108
+ if (observation.fresh === 0 || isPlanAgeAuditObservationV0(observation)) {
109
+ continue;
110
+ }
111
+ issues.push(issue(`${observation.path}.tokens.fresh`, "post-bootstrap-fresh-spend", "post-bootstrap static-world fresh spend must stay flat except plan-age audit receipts", {
112
+ fresh: observation.fresh,
113
+ reused: observation.reused,
114
+ surprise_cause: observation.surprise_cause,
115
+ recheck_kind: observation.recheck_kind,
116
+ content_hash: observation.content_hash,
117
+ }));
118
+ }
119
+ return relationshipResult("flat-spend-under-static", issues.length === 0
120
+ ? "static-world post-bootstrap fresh spend stayed flat apart from the plan-age audit floor"
121
+ : "static-world post-bootstrap fresh spend increased outside the plan-age audit floor", input.receipts.length, tokenBearing.length, postBootstrap.length, postBootstrap.filter(isPlanAgeAuditObservationV0).length, issues);
122
+ }
123
+ function isPlanAgeAuditObservationV0(observation) {
124
+ return (observation.surprise_cause === "forecast-recheck" &&
125
+ observation.recheck_kind === "plan-age");
126
+ }
127
+ function relationshipResult(relationship, summary, receiptCount, tokenBearingReceiptCount, postBootstrapTokenBearingReceiptCount, planAgeAuditFloorReceiptCount, issues) {
128
+ return {
129
+ ok: issues.length === 0,
130
+ relationship,
131
+ summary,
132
+ issues: Object.freeze([...issues]),
133
+ checked: {
134
+ receipts: receiptCount,
135
+ token_bearing_receipts: tokenBearingReceiptCount,
136
+ post_bootstrap_token_bearing_receipts: postBootstrapTokenBearingReceiptCount,
137
+ plan_age_audit_floor_receipts: planAgeAuditFloorReceiptCount,
138
+ },
139
+ };
140
+ }
141
+ function readRecord(record, key, path, code, issues) {
142
+ const value = record[key];
143
+ if (!isRecord(value)) {
144
+ issues.push(issue(`${path}.${key}`, code, `${path}.${key} must be an object`, value));
145
+ return undefined;
146
+ }
147
+ return value;
148
+ }
149
+ function readTokenSpend(cost, path, issues) {
150
+ const tokens = cost["tokens"];
151
+ if (!isRecord(tokens)) {
152
+ issues.push(issue(`${path}.tokens`, "tokens-not-object", "cost.tokens must carry fresh and reused token counts", tokens));
153
+ return undefined;
154
+ }
155
+ const fresh = tokens["fresh"];
156
+ const reused = tokens["reused"];
157
+ if (!isNonNegativeSafeInteger(fresh) || !isNonNegativeSafeInteger(reused)) {
158
+ issues.push(issue(`${path}.tokens`, "tokens-invalid", "cost.tokens.fresh and cost.tokens.reused must be non-negative safe integers", { fresh, reused }));
159
+ return undefined;
160
+ }
161
+ return { fresh, reused };
162
+ }
163
+ function readCoreEventCause(core, path, issues) {
164
+ const eventCause = core["event_cause"];
165
+ if (!isAllowedSurpriseCauseV0(eventCause)) {
166
+ issues.push(issue(`${path}.event_cause`, "core-event-cause-invalid", "core.event_cause must be one of the allowed surprise causes", eventCause));
167
+ return undefined;
168
+ }
169
+ return eventCause;
170
+ }
171
+ function readExactlyOneSurpriseCause(cost, path, issues) {
172
+ if (!Object.hasOwn(cost, "surprise_cause")) {
173
+ issues.push(issue(`${path}.surprise_cause`, "surprise-cause-missing", "cost.surprise_cause is required for receipt v0 cost attribution", null));
174
+ return undefined;
175
+ }
176
+ const surpriseCause = cost["surprise_cause"];
177
+ if (Array.isArray(surpriseCause) || Object.hasOwn(cost, "surprise_causes")) {
178
+ issues.push(issue(`${path}.surprise_cause`, "surprise-cause-multiple", "receipt v0 cost attribution must name exactly one surprise cause", {
179
+ surprise_cause: surpriseCause,
180
+ surprise_causes: cost["surprise_causes"] ?? null,
181
+ }));
182
+ return undefined;
183
+ }
184
+ if (!isAllowedSurpriseCauseV0(surpriseCause)) {
185
+ issues.push(issue(`${path}.surprise_cause`, "surprise-cause-invalid", "cost.surprise_cause must be one of real-input, forecast-recheck, escalation", surpriseCause));
186
+ return undefined;
187
+ }
188
+ return surpriseCause;
189
+ }
190
+ function readRecheckKind(core, path) {
191
+ const recheckKind = core["recheck_kind"];
192
+ if (typeof recheckKind === "string" &&
193
+ ALLOWED_RECHECK_KIND_SET.has(recheckKind)) {
194
+ return recheckKind;
195
+ }
196
+ return null;
197
+ }
198
+ function issue(path, code, message, observed) {
199
+ return { path, code, message, observed };
200
+ }
201
+ function isRecord(value) {
202
+ return typeof value === "object" && value !== null && !Array.isArray(value);
203
+ }
204
+ function isNonNegativeSafeInteger(value) {
205
+ return Number.isSafeInteger(value) && value >= 0;
206
+ }
@@ -0,0 +1,57 @@
1
+ import { type ContentHashV0, type ReceiptV0 } from "../receipt";
2
+ export type EvidenceSourceKind = "adapter" | "forecast" | "dependency";
3
+ export type EvidenceReceiptOrder = "unordered" | "declared";
4
+ export type DeepRoamTrigger = "confidence-escalation" | "stakes-escalation" | "forecast-evidence-age" | "forecast-plan-age" | "no-anchor-forced-deep" | "degraded-calibration";
5
+ export interface CompiledEvidenceSource {
6
+ readonly id: string;
7
+ readonly kind: EvidenceSourceKind;
8
+ readonly required: boolean;
9
+ readonly receipt_order?: EvidenceReceiptOrder;
10
+ }
11
+ export interface CompiledEvidencePlan {
12
+ readonly responsibility_id: string;
13
+ readonly contract_revision: ContentHashV0;
14
+ readonly policy_artifact_namespace: string;
15
+ readonly policy_artifact_revision: string;
16
+ readonly plan_revision: string;
17
+ readonly as_of: string;
18
+ readonly evidence_order: EvidenceReceiptOrder;
19
+ readonly sources: readonly CompiledEvidenceSource[];
20
+ }
21
+ export interface EvidenceReceiptRef {
22
+ readonly source_id: string;
23
+ readonly receipt_hash: ContentHashV0;
24
+ }
25
+ export type EvidenceSourceCollector = (source: CompiledEvidenceSource) => ReceiptV0 | undefined;
26
+ export type ShallowEvidencePlanResult = {
27
+ readonly outcome: "ready";
28
+ readonly consulted_source_ids: readonly string[];
29
+ readonly evidence_receipts: readonly EvidenceReceiptRef[];
30
+ readonly canonical_evidence_receipts: readonly EvidenceReceiptRef[];
31
+ } | {
32
+ readonly outcome: "fail-safe";
33
+ readonly consulted_source_ids: readonly string[];
34
+ readonly reason: string;
35
+ readonly receipt: ReceiptV0;
36
+ };
37
+ export interface DeepRoamDiscovery {
38
+ readonly source_id: string;
39
+ readonly kind: EvidenceSourceKind;
40
+ readonly receipt_hash?: ContentHashV0;
41
+ }
42
+ export type DeepRoamReconciliation = {
43
+ readonly outcome: "plan-confirmed";
44
+ readonly trigger: DeepRoamTrigger;
45
+ readonly confirmed_source_ids: readonly string[];
46
+ } | {
47
+ readonly outcome: "force-recompile";
48
+ readonly trigger: DeepRoamTrigger;
49
+ readonly discovered_source_ids: readonly string[];
50
+ readonly discovered_receipt_hashes: readonly ContentHashV0[];
51
+ readonly reason: string;
52
+ };
53
+ export declare function executeShallowEvidencePlan(plan: CompiledEvidencePlan, collectors: Readonly<Record<string, EvidenceSourceCollector>>): ShallowEvidencePlanResult;
54
+ export declare function reconcileDeepRoam(plan: CompiledEvidencePlan, trigger: DeepRoamTrigger, discoveries: readonly DeepRoamDiscovery[]): DeepRoamReconciliation;
55
+ export declare function canonicalizeEvidenceReceiptRefsForPlan(plan: Pick<CompiledEvidencePlan, "evidence_order">, refs: readonly EvidenceReceiptRef[]): readonly EvidenceReceiptRef[];
56
+ export declare function validateCompiledEvidencePlan(plan: CompiledEvidencePlan): readonly string[];
57
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/evidence-plan/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,SAAS,EAIf,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,UAAU,GAAG,YAAY,CAAC;AACvE,MAAM,MAAM,oBAAoB,GAAG,WAAW,GAAG,UAAU,CAAC;AAC5D,MAAM,MAAM,eAAe,GACvB,uBAAuB,GACvB,mBAAmB,GACnB,uBAAuB,GACvB,mBAAmB,GACnB,u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EAAE,CAsDnB"}
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeShallowEvidencePlan = executeShallowEvidencePlan;
4
+ exports.reconcileDeepRoam = reconcileDeepRoam;
5
+ exports.canonicalizeEvidenceReceiptRefsForPlan = canonicalizeEvidenceReceiptRefsForPlan;
6
+ exports.validateCompiledEvidencePlan = validateCompiledEvidencePlan;
7
+ const kernel_1 = require("../kernel");
8
+ const receipt_1 = require("../receipt");
9
+ function executeShallowEvidencePlan(plan, collectors) {
10
+ const validation = validateCompiledEvidencePlan(plan);
11
+ if (validation.length > 0) {
12
+ return failSafe(plan, [], validation.join("; "));
13
+ }
14
+ const consultedSourceIds = [];
15
+ const evidenceReceipts = [];
16
+ for (const source of plan.sources) {
17
+ consultedSourceIds.push(source.id);
18
+ const collector = collectors[source.id];
19
+ if (collector === undefined) {
20
+ if (!source.required) {
21
+ continue;
22
+ }
23
+ return failSafe(plan, consultedSourceIds, `planned source ${source.id} has no collector`);
24
+ }
25
+ const receipt = collector(source);
26
+ if (receipt === undefined) {
27
+ if (!source.required) {
28
+ continue;
29
+ }
30
+ return failSafe(plan, consultedSourceIds, `planned source ${source.id} produced no receipt`);
31
+ }
32
+ const verification = (0, receipt_1.verifyReceiptV0)(receipt);
33
+ if (!verification.ok) {
34
+ return failSafe(plan, consultedSourceIds, `planned source ${source.id} produced an unverifiable receipt`);
35
+ }
36
+ evidenceReceipts.push({
37
+ source_id: source.id,
38
+ receipt_hash: verification.content_hash,
39
+ });
40
+ }
41
+ const canonicalEvidenceReceipts = canonicalizeEvidenceReceiptRefsForPlan(plan, evidenceReceipts);
42
+ return {
43
+ outcome: "ready",
44
+ consulted_source_ids: consultedSourceIds,
45
+ evidence_receipts: evidenceReceipts,
46
+ canonical_evidence_receipts: canonicalEvidenceReceipts,
47
+ };
48
+ }
49
+ function reconcileDeepRoam(plan, trigger, discoveries) {
50
+ const plannedSourceIds = new Set(plan.sources.map((source) => source.id));
51
+ const discovered = discoveries.filter((discovery) => !plannedSourceIds.has(discovery.source_id));
52
+ if (discovered.length === 0) {
53
+ return {
54
+ outcome: "plan-confirmed",
55
+ trigger,
56
+ confirmed_source_ids: plan.sources.map((source) => source.id),
57
+ };
58
+ }
59
+ return {
60
+ outcome: "force-recompile",
61
+ trigger,
62
+ discovered_source_ids: discovered.map((discovery) => discovery.source_id),
63
+ discovered_receipt_hashes: discovered.flatMap((discovery) => discovery.receipt_hash === undefined ? [] : [discovery.receipt_hash]),
64
+ reason: "deep roaming discovered evidence outside the compiled plan",
65
+ };
66
+ }
67
+ function canonicalizeEvidenceReceiptRefsForPlan(plan, refs) {
68
+ const seen = new Set();
69
+ for (const ref of refs) {
70
+ if (seen.has(ref.receipt_hash)) {
71
+ throw new Error(`duplicate evidence receipt ref ${ref.receipt_hash}`);
72
+ }
73
+ seen.add(ref.receipt_hash);
74
+ }
75
+ if (plan.evidence_order === "declared") {
76
+ return [...refs];
77
+ }
78
+ return [...refs].sort((left, right) => left.receipt_hash.localeCompare(right.receipt_hash));
79
+ }
80
+ function validateCompiledEvidencePlan(plan) {
81
+ const errors = [];
82
+ if (plan.responsibility_id.length === 0) {
83
+ errors.push("plan.responsibility_id must be non-empty");
84
+ }
85
+ if (!isContentHash(plan.contract_revision)) {
86
+ errors.push("plan.contract_revision must be a sha256 content address");
87
+ }
88
+ if (plan.policy_artifact_namespace.length === 0) {
89
+ errors.push("plan.policy_artifact_namespace must be non-empty");
90
+ }
91
+ if (plan.policy_artifact_revision.length === 0) {
92
+ errors.push("plan.policy_artifact_revision must be non-empty");
93
+ }
94
+ if (plan.plan_revision.length === 0) {
95
+ errors.push("plan.plan_revision must be non-empty");
96
+ }
97
+ if (!isReplayableInstant(plan.as_of)) {
98
+ errors.push("plan.as_of must be a replayable ISO instant");
99
+ }
100
+ if (plan.evidence_order !== "unordered" && plan.evidence_order !== "declared") {
101
+ errors.push("plan.evidence_order is malformed");
102
+ }
103
+ const seenSourceIds = new Set();
104
+ for (const source of plan.sources) {
105
+ if (source.id.length === 0) {
106
+ errors.push("source.id must be non-empty");
107
+ }
108
+ if (seenSourceIds.has(source.id)) {
109
+ errors.push(`source ${source.id} is duplicated`);
110
+ }
111
+ seenSourceIds.add(source.id);
112
+ if (source.kind !== "adapter" &&
113
+ source.kind !== "forecast" &&
114
+ source.kind !== "dependency") {
115
+ errors.push(`source ${source.id} has malformed kind`);
116
+ }
117
+ if (typeof source.required !== "boolean") {
118
+ errors.push(`source ${source.id} required flag is malformed`);
119
+ }
120
+ if (source.receipt_order !== undefined &&
121
+ source.receipt_order !== "unordered" &&
122
+ source.receipt_order !== "declared") {
123
+ errors.push(`source ${source.id} receipt_order is malformed`);
124
+ }
125
+ }
126
+ return errors;
127
+ }
128
+ function failSafe(plan, consultedSourceIds, reason) {
129
+ return {
130
+ outcome: "fail-safe",
131
+ consulted_source_ids: consultedSourceIds,
132
+ reason,
133
+ receipt: (0, kernel_1.createKernelSafetyReceipt)({
134
+ responsibility_id: plan.responsibility_id,
135
+ contract_revision: plan.contract_revision,
136
+ memo_key: `evidence-plan-fail-safe:${plan.policy_artifact_namespace}:${plan.plan_revision}`,
137
+ evidence_input_ids: [failSafeEvidenceInputId(plan, consultedSourceIds, reason)],
138
+ as_of: plan.as_of,
139
+ reason,
140
+ fix_target: "policy-artifact",
141
+ interrupt_cause: "needs-judgment",
142
+ event_cause: "escalation",
143
+ }),
144
+ };
145
+ }
146
+ function failSafeEvidenceInputId(plan, consultedSourceIds, reason) {
147
+ return (0, receipt_1.hashCanonicalReceiptV0)((0, receipt_1.canonicalizeForReceiptV0)({
148
+ schema: "openprose.evidence-plan.fail-safe-input",
149
+ v: 0,
150
+ contract_revision: plan.contract_revision,
151
+ policy_artifact_namespace: plan.policy_artifact_namespace,
152
+ policy_artifact_revision: plan.policy_artifact_revision,
153
+ plan_revision: plan.plan_revision,
154
+ consulted_source_ids: consultedSourceIds,
155
+ reason,
156
+ as_of: plan.as_of,
157
+ }));
158
+ }
159
+ function isContentHash(value) {
160
+ return /^sha256:[a-f0-9]{64}$/.test(value);
161
+ }
162
+ function isReplayableInstant(value) {
163
+ return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/.test(value);
164
+ }
@@ -0,0 +1,39 @@
1
+ import { type ContentHashV0, type ReceiptRecheckKindV0, type ReceiptV0 } from "../receipt";
2
+ export interface ForecastScheduleStateV0 {
3
+ readonly responsibility_id: string;
4
+ readonly contract_revision: ContentHashV0;
5
+ readonly memo_key: string;
6
+ readonly evidence_input_ids: readonly ContentHashV0[];
7
+ readonly next_evidence_recheck: string;
8
+ readonly next_plan_recheck: string;
9
+ }
10
+ export interface ForecastScheduleInputV0 {
11
+ readonly as_of: string;
12
+ readonly schedule: ForecastScheduleStateV0;
13
+ readonly real_input_observed: boolean;
14
+ }
15
+ export type ForecastScheduleResultV0 = {
16
+ readonly outcome: "sleep";
17
+ readonly next_due_at: string;
18
+ readonly token_bearing_receipts: readonly ReceiptV0[];
19
+ readonly due_rechecks: readonly ReceiptRecheckKindV0[];
20
+ } | {
21
+ readonly outcome: "manufacture-recheck";
22
+ readonly next_due_at?: string;
23
+ readonly receipts: readonly ReceiptV0[];
24
+ readonly token_bearing_receipts: readonly ReceiptV0[];
25
+ readonly due_rechecks: readonly ReceiptRecheckKindV0[];
26
+ readonly reason: "forecast-clock-crossed" | "adversarial-silent";
27
+ };
28
+ export declare function evaluateForecastScheduleV0(input: ForecastScheduleInputV0): ForecastScheduleResultV0;
29
+ export interface ForecastRecheckReceiptInputV0 {
30
+ readonly responsibility_id: string;
31
+ readonly contract_revision: ContentHashV0;
32
+ readonly memo_key: string;
33
+ readonly evidence_input_ids: readonly ContentHashV0[];
34
+ readonly as_of: string;
35
+ readonly recheck_kind: ReceiptRecheckKindV0;
36
+ }
37
+ export declare function createForecastRecheckReceiptV0(input: ForecastRecheckReceiptInputV0): ReceiptV0;
38
+ export declare function tokenBearingReceipts(receipts: readonly ReceiptV0[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D,QAAQ,CAAC,MAAM,EAAE,wBAAwB,GAAG,oBAAoB,CAAC;CAClE,CAAC;AAEN,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,uBAAuB,GAC7B,wBAAwB,CAqC1B;AAED,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,iBAAiB,EAAE,aAAa,CAAC;IAC1C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,kBAAkB,EAAE,SAAS,aAAa,EAAE,CAAC;IACtD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAAC;CAC7C;AAED,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,6BAA6B,GACnC,SAAS,CA+CX;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,SAAS,SAAS,EAAE,GAC7B,SAAS,SAAS,EAAE,CAItB"}
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.evaluateForecastScheduleV0 = evaluateForecastScheduleV0;
4
+ exports.createForecastRecheckReceiptV0 = createForecastRecheckReceiptV0;
5
+ exports.tokenBearingReceipts = tokenBearingReceipts;
6
+ const receipt_1 = require("../receipt");
7
+ function evaluateForecastScheduleV0(input) {
8
+ const asOfMs = parseInstantMs(input.as_of, "as_of");
9
+ const dueRechecks = dueRecheckKinds(input.schedule, asOfMs);
10
+ if (dueRechecks.length === 0) {
11
+ return {
12
+ outcome: "sleep",
13
+ next_due_at: earliestInstant([
14
+ input.schedule.next_evidence_recheck,
15
+ input.schedule.next_plan_recheck,
16
+ ]),
17
+ token_bearing_receipts: [],
18
+ due_rechecks: [],
19
+ };
20
+ }
21
+ const receipts = dueRechecks.map((recheckKind) => createForecastRecheckReceiptV0({
22
+ responsibility_id: input.schedule.responsibility_id,
23
+ contract_revision: input.schedule.contract_revision,
24
+ memo_key: input.schedule.memo_key,
25
+ evidence_input_ids: input.schedule.evidence_input_ids,
26
+ as_of: input.as_of,
27
+ recheck_kind: recheckKind,
28
+ }));
29
+ const nextDueAt = nextDueAfter(input.schedule, dueRechecks);
30
+ return {
31
+ outcome: "manufacture-recheck",
32
+ ...(nextDueAt === undefined ? {} : { next_due_at: nextDueAt }),
33
+ receipts,
34
+ token_bearing_receipts: tokenBearingReceipts(receipts),
35
+ due_rechecks: dueRechecks,
36
+ reason: input.real_input_observed ? "forecast-clock-crossed" : "adversarial-silent",
37
+ };
38
+ }
39
+ function createForecastRecheckReceiptV0(input) {
40
+ return (0, receipt_1.createReceiptV0)({
41
+ core: {
42
+ responsibility_id: input.responsibility_id,
43
+ contract_revision: input.contract_revision,
44
+ event_cause: "forecast-recheck",
45
+ recheck_kind: input.recheck_kind,
46
+ memo_key: input.memo_key,
47
+ evidence_input_ids: input.evidence_input_ids,
48
+ as_of: input.as_of,
49
+ role: "judge",
50
+ },
51
+ sig: (0, receipt_1.createNullSignerReceiptSignatureV0)(),
52
+ verdict: {
53
+ status: "blocked",
54
+ confidence: {
55
+ value: 0,
56
+ derivation_method: "forecast-gated-synthetic-input",
57
+ calibration_grade: "none",
58
+ label_source: "forecast-clock",
59
+ },
60
+ blocked: {
61
+ reason: `forecast-${input.recheck_kind}-recheck-required`,
62
+ fix_target: "judge",
63
+ interrupt_cause: "needs-judgment",
64
+ },
65
+ },
66
+ freshness: {
67
+ as_of: input.as_of,
68
+ next_forecast_recheck: input.as_of,
69
+ },
70
+ composition: {
71
+ consumed_receipts: [],
72
+ cycle_checked: true,
73
+ },
74
+ cost: {
75
+ provider: "forecast",
76
+ model: "deterministic-scheduler",
77
+ role: "judge",
78
+ tags: ["forecast-recheck", input.recheck_kind],
79
+ responsibility_id: input.responsibility_id,
80
+ run_id: `forecast-${input.recheck_kind}-${input.as_of}`,
81
+ as_of: input.as_of,
82
+ tokens: { fresh: 0, reused: 0 },
83
+ surprise_cause: "forecast-recheck",
84
+ },
85
+ });
86
+ }
87
+ function tokenBearingReceipts(receipts) {
88
+ return receipts.filter((receipt) => receipt.cost.tokens.fresh + receipt.cost.tokens.reused > 0);
89
+ }
90
+ function dueRecheckKinds(schedule, asOfMs) {
91
+ const due = [];
92
+ if (parseInstantMs(schedule.next_evidence_recheck, "next_evidence_recheck") <= asOfMs) {
93
+ due.push("evidence-age");
94
+ }
95
+ if (parseInstantMs(schedule.next_plan_recheck, "next_plan_recheck") <= asOfMs) {
96
+ due.push("plan-age");
97
+ }
98
+ return due;
99
+ }
100
+ function earliestInstant(values) {
101
+ return [...values].sort((left, right) => parseInstantMs(left, left) - parseInstantMs(right, right))[0] ?? "";
102
+ }
103
+ function nextDueAfter(schedule, dueRechecks) {
104
+ const candidates = [];
105
+ if (!dueRechecks.includes("evidence-age")) {
106
+ candidates.push(schedule.next_evidence_recheck);
107
+ }
108
+ if (!dueRechecks.includes("plan-age")) {
109
+ candidates.push(schedule.next_plan_recheck);
110
+ }
111
+ return candidates.length === 0 ? undefined : earliestInstant(candidates);
112
+ }
113
+ function parseInstantMs(value, name) {
114
+ const parsed = Date.parse(value);
115
+ if (!Number.isFinite(parsed)) {
116
+ throw new Error(`${name} must be a replayable instant`);
117
+ }
118
+ return parsed;
119
+ }
@@ -0,0 +1,14 @@
1
+ export * from "./receipt";
2
+ export * from "./cost";
3
+ export * from "./kernel";
4
+ export * from "./evidence-plan";
5
+ export * from "./memo";
6
+ export * from "./forecast";
7
+ export * from "./sdk";
8
+ export * from "./reactor";
9
+ export * from "./judge";
10
+ export * from "./adapters";
11
+ export * from "./policy";
12
+ export * from "./composition";
13
+ export * from "./projection";
14
+ //# sourceMappingURL=index.d.ts.map