@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.
- package/LICENSE +21 -0
- package/README.md +270 -0
- package/dist/assert/index.d.ts +35 -0
- package/dist/assert/index.d.ts.map +1 -0
- package/dist/assert/index.js +398 -0
- package/dist/baselines/cost-thesis/index.d.ts +103 -0
- package/dist/baselines/cost-thesis/index.d.ts.map +1 -0
- package/dist/baselines/cost-thesis/index.js +337 -0
- package/dist/baselines/naive-loop/index.d.ts +46 -0
- package/dist/baselines/naive-loop/index.d.ts.map +1 -0
- package/dist/baselines/naive-loop/index.js +188 -0
- package/dist/baselines/no-memo/index.d.ts +84 -0
- package/dist/baselines/no-memo/index.d.ts.map +1 -0
- package/dist/baselines/no-memo/index.js +226 -0
- package/dist/doubles/clock.d.ts +9 -0
- package/dist/doubles/clock.d.ts.map +1 -0
- package/dist/doubles/clock.js +42 -0
- package/dist/doubles/storage.d.ts +24 -0
- package/dist/doubles/storage.d.ts.map +1 -0
- package/dist/doubles/storage.js +191 -0
- package/dist/eval/index.d.ts +204 -0
- package/dist/eval/index.d.ts.map +1 -0
- package/dist/eval/index.js +596 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/policy-author/index.d.ts +103 -0
- package/dist/policy-author/index.d.ts.map +1 -0
- package/dist/policy-author/index.js +358 -0
- package/dist/policy-drift/index.d.ts +64 -0
- package/dist/policy-drift/index.d.ts.map +1 -0
- package/dist/policy-drift/index.js +495 -0
- package/dist/policy-replay/index.d.ts +106 -0
- package/dist/policy-replay/index.d.ts.map +1 -0
- package/dist/policy-replay/index.js +361 -0
- package/dist/provider-parity/index.d.ts +91 -0
- package/dist/provider-parity/index.d.ts.map +1 -0
- package/dist/provider-parity/index.js +439 -0
- package/dist/recompile/index.d.ts +161 -0
- package/dist/recompile/index.d.ts.map +1 -0
- package/dist/recompile/index.js +690 -0
- package/dist/release-candidate/index.d.ts +139 -0
- package/dist/release-candidate/index.d.ts.map +1 -0
- package/dist/release-candidate/index.js +553 -0
- package/dist/release-parity/index.d.ts +80 -0
- package/dist/release-parity/index.d.ts.map +1 -0
- package/dist/release-parity/index.js +1035 -0
- package/dist/replay/model-gateway.d.ts +25 -0
- package/dist/replay/model-gateway.d.ts.map +1 -0
- package/dist/replay/model-gateway.js +166 -0
- package/dist/replay/parity.d.ts +110 -0
- package/dist/replay/parity.d.ts.map +1 -0
- package/dist/replay/parity.js +232 -0
- package/dist/rollback/index.d.ts +106 -0
- package/dist/rollback/index.d.ts.map +1 -0
- package/dist/rollback/index.js +694 -0
- package/dist/scenario/parser.d.ts +11 -0
- package/dist/scenario/parser.d.ts.map +1 -0
- package/dist/scenario/parser.js +490 -0
- package/dist/scenario/runner.d.ts +12 -0
- package/dist/scenario/runner.d.ts.map +1 -0
- package/dist/scenario/runner.js +345 -0
- package/dist/scenario/synthetic-world-adapter.d.ts +4 -0
- package/dist/scenario/synthetic-world-adapter.d.ts.map +1 -0
- package/dist/scenario/synthetic-world-adapter.js +82 -0
- package/dist/scenario/time.d.ts +4 -0
- package/dist/scenario/time.d.ts.map +1 -0
- package/dist/scenario/time.js +45 -0
- package/dist/scenario/types.d.ts +149 -0
- package/dist/scenario/types.d.ts.map +1 -0
- package/dist/scenario/types.js +5 -0
- package/dist/spikes/index.d.ts +10 -0
- package/dist/spikes/index.d.ts.map +1 -0
- package/dist/spikes/index.js +29 -0
- package/dist/spikes/k1-ensemble-spread.d.ts +88 -0
- package/dist/spikes/k1-ensemble-spread.d.ts.map +1 -0
- package/dist/spikes/k1-ensemble-spread.js +396 -0
- package/dist/spikes/k2-policy-author.d.ts +25 -0
- package/dist/spikes/k2-policy-author.d.ts.map +1 -0
- package/dist/spikes/k2-policy-author.js +503 -0
- package/dist/spikes/live-refresh.d.ts +150 -0
- package/dist/spikes/live-refresh.d.ts.map +1 -0
- package/dist/spikes/live-refresh.js +511 -0
- package/dist/world/index.d.ts +2 -0
- package/dist/world/index.d.ts.map +1 -0
- package/dist/world/index.js +17 -0
- package/dist/world/synthetic-world.d.ts +104 -0
- package/dist/world/synthetic-world.d.ts.map +1 -0
- package/dist/world/synthetic-world.js +449 -0
- package/package.json +139 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertStaticSurpriseZeroV0 = assertStaticSurpriseZeroV0;
|
|
4
|
+
exports.assertSurpriseAttributionCompleteV0 = assertSurpriseAttributionCompleteV0;
|
|
5
|
+
exports.assertFlatSpendUnderStaticV0 = assertFlatSpendUnderStaticV0;
|
|
6
|
+
exports.assertNoFixedIntervalWorkV0 = assertNoFixedIntervalWorkV0;
|
|
7
|
+
exports.evaluateCradleAssertionV0 = evaluateCradleAssertionV0;
|
|
8
|
+
exports.evaluateCradleAssertionsV0 = evaluateCradleAssertionsV0;
|
|
9
|
+
exports.evaluateExpectedCradleRelationshipsV0 = evaluateExpectedCradleRelationshipsV0;
|
|
10
|
+
const ALLOWED_SURPRISE_CAUSES = new Set([
|
|
11
|
+
"real-input",
|
|
12
|
+
"forecast-recheck",
|
|
13
|
+
"escalation",
|
|
14
|
+
]);
|
|
15
|
+
function assertStaticSurpriseZeroV0(run) {
|
|
16
|
+
const failures = [];
|
|
17
|
+
const observations = collectSurpriseObservations(run);
|
|
18
|
+
if (run.world_profile !== "static") {
|
|
19
|
+
failures.push({
|
|
20
|
+
path: "world_profile",
|
|
21
|
+
message: "static-surprise-zero only applies to static world runs",
|
|
22
|
+
observed: run.world_profile,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (observations.length === 0) {
|
|
26
|
+
failures.push({
|
|
27
|
+
path: "trace",
|
|
28
|
+
message: "static world run has no surprise observations to prove zero",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
for (const observation of observations) {
|
|
32
|
+
const surprise = observation.surprise;
|
|
33
|
+
if (surprise.profile !== "static") {
|
|
34
|
+
failures.push({
|
|
35
|
+
path: `${observation.path}.profile`,
|
|
36
|
+
message: "static run reported a non-static surprise profile",
|
|
37
|
+
observed: surprise.profile,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (surprise.count !== 0) {
|
|
41
|
+
failures.push({
|
|
42
|
+
path: `${observation.path}.count`,
|
|
43
|
+
message: "static run reported material surprise",
|
|
44
|
+
observed: surprise.count,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (surprise.causes.length !== 0) {
|
|
48
|
+
failures.push({
|
|
49
|
+
path: `${observation.path}.causes`,
|
|
50
|
+
message: "static run reported surprise causes",
|
|
51
|
+
observed: surprise.causes,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (failures.length > 0) {
|
|
56
|
+
return result("static-surprise-zero", "fail", "static-world surprise observations must all remain zero", failures);
|
|
57
|
+
}
|
|
58
|
+
return result("static-surprise-zero", "pass", "static-world surprise stayed at zero across the run trace", [
|
|
59
|
+
{
|
|
60
|
+
path: "trace",
|
|
61
|
+
message: "checked static surprise observations",
|
|
62
|
+
observed: { observations: observations.length },
|
|
63
|
+
},
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
function assertSurpriseAttributionCompleteV0(run) {
|
|
67
|
+
const observations = collectTokenObservations(run);
|
|
68
|
+
const tokenBearing = observations.filter(isTokenBearing);
|
|
69
|
+
const failures = [];
|
|
70
|
+
for (const observation of tokenBearing) {
|
|
71
|
+
if (observation.surprise_cause === undefined ||
|
|
72
|
+
!ALLOWED_SURPRISE_CAUSES.has(observation.surprise_cause)) {
|
|
73
|
+
failures.push({
|
|
74
|
+
path: `${observation.path}.surprise_cause`,
|
|
75
|
+
message: "token-bearing payload is missing a valid surprise cause",
|
|
76
|
+
observed: {
|
|
77
|
+
kind: observation.kind,
|
|
78
|
+
fresh: observation.fresh,
|
|
79
|
+
reused: observation.reused,
|
|
80
|
+
surprise_cause: observation.surprise_cause ?? null,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (failures.length > 0) {
|
|
86
|
+
return result("surprise-attribution-complete", "fail", "every token-bearing receipt/model payload must name its surprise cause", failures);
|
|
87
|
+
}
|
|
88
|
+
return result("surprise-attribution-complete", "pass", "all token-bearing receipt/model payloads name a valid surprise cause", [
|
|
89
|
+
{
|
|
90
|
+
path: "receipt_log.entries",
|
|
91
|
+
message: "checked token-bearing payloads",
|
|
92
|
+
observed: {
|
|
93
|
+
token_bearing_payloads: tokenBearing.length,
|
|
94
|
+
token_payloads_seen: observations.length,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
function assertFlatSpendUnderStaticV0(run, options = {}) {
|
|
100
|
+
const failures = [];
|
|
101
|
+
const tokenBearing = collectTokenObservations(run).filter(isTokenBearing);
|
|
102
|
+
const bootstrapReceiptCount = options.bootstrap_receipt_count ?? 1;
|
|
103
|
+
const postBootstrap = tokenBearing.slice(bootstrapReceiptCount);
|
|
104
|
+
if (run.world_profile !== "static") {
|
|
105
|
+
failures.push({
|
|
106
|
+
path: "world_profile",
|
|
107
|
+
message: "flat-spend-under-static only applies to static world runs",
|
|
108
|
+
observed: run.world_profile,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if (tokenBearing.length === 0) {
|
|
112
|
+
failures.push({
|
|
113
|
+
path: "receipt_log.entries",
|
|
114
|
+
message: "static spend relationship needs token-bearing payload evidence",
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
for (const observation of postBootstrap) {
|
|
118
|
+
if (observation.fresh === 0) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (isPlanAuditObservation(observation)) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
failures.push({
|
|
125
|
+
path: `${observation.path}.tokens.fresh`,
|
|
126
|
+
message: "post-bootstrap static-world fresh spend must stay flat except plan-audit floor receipts",
|
|
127
|
+
observed: {
|
|
128
|
+
kind: observation.kind,
|
|
129
|
+
fresh: observation.fresh,
|
|
130
|
+
reused: observation.reused,
|
|
131
|
+
surprise_cause: observation.surprise_cause ?? null,
|
|
132
|
+
recheck_kind: observation.recheck_kind ?? null,
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
if (failures.length > 0) {
|
|
137
|
+
return result("flat-spend-under-static", "fail", "static-world fresh spend increased after bootstrap outside the plan-audit floor", failures);
|
|
138
|
+
}
|
|
139
|
+
return result("flat-spend-under-static", "pass", "static-world post-bootstrap fresh spend stayed flat apart from allowed plan-audit floor receipts", [
|
|
140
|
+
{
|
|
141
|
+
path: "receipt_log.entries",
|
|
142
|
+
message: "checked token-bearing receipts by relationship after bootstrap",
|
|
143
|
+
observed: {
|
|
144
|
+
token_bearing_payloads: tokenBearing.length,
|
|
145
|
+
bootstrap_receipt_count: bootstrapReceiptCount,
|
|
146
|
+
post_bootstrap_payloads: postBootstrap.length,
|
|
147
|
+
plan_audit_floor_payloads: postBootstrap.filter(isPlanAuditObservation).length,
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
]);
|
|
151
|
+
}
|
|
152
|
+
function assertNoFixedIntervalWorkV0(run) {
|
|
153
|
+
const failures = [];
|
|
154
|
+
const schedules = collectReceiptSchedules(run);
|
|
155
|
+
const forecastTokenWork = collectTokenObservations(run).filter((observation) => isTokenBearing(observation) &&
|
|
156
|
+
observation.surprise_cause === "forecast-recheck");
|
|
157
|
+
for (const work of forecastTokenWork) {
|
|
158
|
+
const activeSchedule = findActiveSchedule(schedules, work.as_of);
|
|
159
|
+
if (activeSchedule === undefined) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (compareIsoInstants(work.as_of, activeSchedule.next_forecast_recheck) < 0) {
|
|
163
|
+
failures.push({
|
|
164
|
+
path: work.path,
|
|
165
|
+
message: "forecast-recheck token work occurred before the prior scheduled check",
|
|
166
|
+
observed: {
|
|
167
|
+
as_of: work.as_of,
|
|
168
|
+
previous_receipt_path: activeSchedule.path,
|
|
169
|
+
next_forecast_recheck: activeSchedule.next_forecast_recheck,
|
|
170
|
+
fresh: work.fresh,
|
|
171
|
+
reused: work.reused,
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const traceGaps = collectTraceGaps(run);
|
|
177
|
+
if (failures.length > 0) {
|
|
178
|
+
return result("no-fixed-interval-work", "fail", "forecast-paced runs must not spend tokens in virtual-clock gaps before the next scheduled check", failures);
|
|
179
|
+
}
|
|
180
|
+
return result("no-fixed-interval-work", "pass", "no forecast-recheck token work appeared before the next scheduled check", [
|
|
181
|
+
{
|
|
182
|
+
path: "trace",
|
|
183
|
+
message: "checked virtual-clock trace gaps against receipt schedules",
|
|
184
|
+
observed: {
|
|
185
|
+
trace_gaps: traceGaps,
|
|
186
|
+
scheduled_receipts: schedules.length,
|
|
187
|
+
forecast_token_work: forecastTokenWork.length,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
]);
|
|
191
|
+
}
|
|
192
|
+
function evaluateCradleAssertionV0(run, family, options = {}) {
|
|
193
|
+
switch (family) {
|
|
194
|
+
case "static-surprise-zero":
|
|
195
|
+
return assertStaticSurpriseZeroV0(run);
|
|
196
|
+
case "surprise-attribution-complete":
|
|
197
|
+
return assertSurpriseAttributionCompleteV0(run);
|
|
198
|
+
case "flat-spend-under-static":
|
|
199
|
+
return assertFlatSpendUnderStaticV0(run, options.flat_spend);
|
|
200
|
+
case "no-fixed-interval-work":
|
|
201
|
+
return assertNoFixedIntervalWorkV0(run);
|
|
202
|
+
case "release-parity-fixture":
|
|
203
|
+
throw new Error("release-parity-fixture assertions are emitted by the recorded release-parity module");
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function evaluateCradleAssertionsV0(run, families, options = {}) {
|
|
207
|
+
return suiteResult(families.map((family) => evaluateCradleAssertionV0(run, family, options)));
|
|
208
|
+
}
|
|
209
|
+
function evaluateExpectedCradleRelationshipsV0(run, options = {}) {
|
|
210
|
+
const families = run.expected_relationships.flatMap((relationship) => familyFromExpectedRelationship(relationship));
|
|
211
|
+
return evaluateCradleAssertionsV0(run, uniqueFamilies(families), options);
|
|
212
|
+
}
|
|
213
|
+
function familyFromExpectedRelationship(relationship) {
|
|
214
|
+
switch (relationship.relationship) {
|
|
215
|
+
case "static-surprise-zero":
|
|
216
|
+
return ["static-surprise-zero"];
|
|
217
|
+
case "surprise-attribution-complete":
|
|
218
|
+
case "every-token-has-surprise-cause":
|
|
219
|
+
return ["surprise-attribution-complete"];
|
|
220
|
+
case "flat-spend-under-static":
|
|
221
|
+
case "tokens-flat-after-bootstrap":
|
|
222
|
+
return ["flat-spend-under-static"];
|
|
223
|
+
case "no-fixed-interval-work":
|
|
224
|
+
return ["no-fixed-interval-work"];
|
|
225
|
+
default:
|
|
226
|
+
return [];
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
function uniqueFamilies(families) {
|
|
230
|
+
return Array.from(new Set(families));
|
|
231
|
+
}
|
|
232
|
+
function suiteResult(results) {
|
|
233
|
+
return {
|
|
234
|
+
status: results.some((item) => item.status === "fail") ? "fail" : "pass",
|
|
235
|
+
results: Object.freeze([...results]),
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function result(family, status, summary, evidence) {
|
|
239
|
+
return {
|
|
240
|
+
ok: status === "pass",
|
|
241
|
+
relationship: family,
|
|
242
|
+
family,
|
|
243
|
+
status,
|
|
244
|
+
summary,
|
|
245
|
+
evidence: Object.freeze([...evidence]),
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function collectSurpriseObservations(run) {
|
|
249
|
+
const observations = [];
|
|
250
|
+
for (const [traceIndex, entry] of run.trace.entries()) {
|
|
251
|
+
if (entry.world_advance?.surprise !== undefined) {
|
|
252
|
+
observations.push({
|
|
253
|
+
path: `trace[${traceIndex}].world_advance.surprise`,
|
|
254
|
+
surprise: entry.world_advance.surprise,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
if (entry.world_event?.surprise !== undefined) {
|
|
258
|
+
observations.push({
|
|
259
|
+
path: `trace[${traceIndex}].world_event.surprise`,
|
|
260
|
+
surprise: entry.world_event.surprise,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
for (const [readIndex, read] of entry.world_reads.entries()) {
|
|
264
|
+
if (read.surprise !== undefined) {
|
|
265
|
+
observations.push({
|
|
266
|
+
path: `trace[${traceIndex}].world_reads[${readIndex}].surprise`,
|
|
267
|
+
surprise: read.surprise,
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return observations;
|
|
273
|
+
}
|
|
274
|
+
function collectTokenObservations(input) {
|
|
275
|
+
const receipts = readReceipts(input);
|
|
276
|
+
const observations = receipts.map((receipt, index) => ({
|
|
277
|
+
kind: "receipt",
|
|
278
|
+
path: `receipt_log.entries[${index}].cost`,
|
|
279
|
+
as_of: receipt.cost.as_of,
|
|
280
|
+
fresh: receipt.cost.tokens.fresh,
|
|
281
|
+
reused: receipt.cost.tokens.reused,
|
|
282
|
+
surprise_cause: receipt.cost.surprise_cause,
|
|
283
|
+
...(receipt.core.recheck_kind === undefined
|
|
284
|
+
? {}
|
|
285
|
+
: { recheck_kind: receipt.core.recheck_kind }),
|
|
286
|
+
}));
|
|
287
|
+
if (isScenarioRun(input)) {
|
|
288
|
+
observations.push(...collectModelResponseTokenObservations(input));
|
|
289
|
+
}
|
|
290
|
+
return observations;
|
|
291
|
+
}
|
|
292
|
+
function collectModelResponseTokenObservations(run) {
|
|
293
|
+
const observations = [];
|
|
294
|
+
for (const [traceIndex, entry] of run.trace.entries()) {
|
|
295
|
+
const payload = entry.model_response?.payload;
|
|
296
|
+
if (!isRecord(payload)) {
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
const tokens = readTokens(payload["tokens"]);
|
|
300
|
+
if (tokens === undefined) {
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
observations.push({
|
|
304
|
+
kind: "model-response",
|
|
305
|
+
path: `trace[${traceIndex}].model_response.payload`,
|
|
306
|
+
as_of: entry.as_of,
|
|
307
|
+
fresh: tokens.fresh,
|
|
308
|
+
reused: tokens.reused,
|
|
309
|
+
...(typeof payload["surprise_cause"] === "string"
|
|
310
|
+
? { surprise_cause: payload["surprise_cause"] }
|
|
311
|
+
: {}),
|
|
312
|
+
...(typeof payload["recheck_kind"] === "string"
|
|
313
|
+
? { recheck_kind: payload["recheck_kind"] }
|
|
314
|
+
: {}),
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
return observations;
|
|
318
|
+
}
|
|
319
|
+
function readReceipts(input) {
|
|
320
|
+
if (isReceiptArray(input)) {
|
|
321
|
+
return input;
|
|
322
|
+
}
|
|
323
|
+
if (isScenarioRun(input)) {
|
|
324
|
+
return input.receipt_log.entries;
|
|
325
|
+
}
|
|
326
|
+
if (isScenarioReceiptLog(input)) {
|
|
327
|
+
return input.entries;
|
|
328
|
+
}
|
|
329
|
+
return [];
|
|
330
|
+
}
|
|
331
|
+
function isScenarioRun(value) {
|
|
332
|
+
return isRecord(value) && Array.isArray(value["trace"]);
|
|
333
|
+
}
|
|
334
|
+
function isScenarioReceiptLog(value) {
|
|
335
|
+
return isRecord(value) && Array.isArray(value["entries"]);
|
|
336
|
+
}
|
|
337
|
+
function isReceiptArray(value) {
|
|
338
|
+
return Array.isArray(value);
|
|
339
|
+
}
|
|
340
|
+
function isTokenBearing(observation) {
|
|
341
|
+
return observation.fresh + observation.reused > 0;
|
|
342
|
+
}
|
|
343
|
+
function isPlanAuditObservation(observation) {
|
|
344
|
+
return (observation.surprise_cause === "forecast-recheck" &&
|
|
345
|
+
observation.recheck_kind === "plan-age");
|
|
346
|
+
}
|
|
347
|
+
function collectReceiptSchedules(run) {
|
|
348
|
+
return run.receipt_log.entries
|
|
349
|
+
.map((receipt, index) => ({
|
|
350
|
+
path: `receipt_log.entries[${index}].freshness.next_forecast_recheck`,
|
|
351
|
+
as_of: receipt.freshness.as_of,
|
|
352
|
+
next_forecast_recheck: receipt.freshness.next_forecast_recheck,
|
|
353
|
+
}))
|
|
354
|
+
.sort((left, right) => compareIsoInstants(left.as_of, right.as_of));
|
|
355
|
+
}
|
|
356
|
+
function findActiveSchedule(schedules, asOf) {
|
|
357
|
+
let active;
|
|
358
|
+
for (const schedule of schedules) {
|
|
359
|
+
if (compareIsoInstants(schedule.as_of, asOf) < 0) {
|
|
360
|
+
active = schedule;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return active;
|
|
364
|
+
}
|
|
365
|
+
function collectTraceGaps(run) {
|
|
366
|
+
const gaps = [];
|
|
367
|
+
for (let index = 1; index < run.trace.length; index += 1) {
|
|
368
|
+
const previous = run.trace[index - 1];
|
|
369
|
+
const current = run.trace[index];
|
|
370
|
+
if (previous === undefined || current === undefined) {
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (previous.as_of !== current.as_of) {
|
|
374
|
+
gaps.push(`${previous.as_of}..${current.as_of}`);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return gaps;
|
|
378
|
+
}
|
|
379
|
+
function compareIsoInstants(left, right) {
|
|
380
|
+
return Date.parse(left) - Date.parse(right);
|
|
381
|
+
}
|
|
382
|
+
function readTokens(value) {
|
|
383
|
+
if (!isRecord(value)) {
|
|
384
|
+
return undefined;
|
|
385
|
+
}
|
|
386
|
+
const fresh = value["fresh"];
|
|
387
|
+
const reused = value["reused"];
|
|
388
|
+
if (typeof fresh !== "number" ||
|
|
389
|
+
typeof reused !== "number" ||
|
|
390
|
+
!Number.isFinite(fresh) ||
|
|
391
|
+
!Number.isFinite(reused)) {
|
|
392
|
+
return undefined;
|
|
393
|
+
}
|
|
394
|
+
return { fresh, reused };
|
|
395
|
+
}
|
|
396
|
+
function isRecord(value) {
|
|
397
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
398
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { ContentHashV0, ReceiptEventCauseV0, ReceiptRecheckKindV0, ReceiptRoleV0 } from "@openprose/reactor/receipt";
|
|
2
|
+
import type { NoMemoBaselineSummaryV0 } from "../no-memo";
|
|
3
|
+
import type { NaiveLoopBaselineSummaryV0 } from "../naive-loop";
|
|
4
|
+
import type { ScenarioRunReceiptV0, ScenarioWorldProfileV0 } from "../../scenario/types";
|
|
5
|
+
export declare const COST_THESIS_SUMMARY_SCHEMA_V0: "openprose.reactor-cradle.baseline.cost-thesis.summary";
|
|
6
|
+
export declare const COST_THESIS_SUMMARY_VERSION_V0: 0;
|
|
7
|
+
export declare const COST_THESIS_GENERATED_AT_V0: "2026-05-20T00:00:00.000Z";
|
|
8
|
+
export type CostThesisRowVariantV0 = "reactor" | "reactor-no-memo" | "naive-loop";
|
|
9
|
+
export type CostThesisRowProvenanceV0 = "runtime-produced" | "simulated" | "control";
|
|
10
|
+
export type CostThesisTurnSourceV0 = "receipt.cost" | "no-memo-simulation" | "naive-loop-control";
|
|
11
|
+
export type CostThesisTurnOutcomeV0 = "model-invocation" | "runtime-receipt" | "memo-hit" | "fresh-judge" | "control-review";
|
|
12
|
+
export interface CostThesisTokensV0 {
|
|
13
|
+
readonly fresh: number;
|
|
14
|
+
readonly reused: number;
|
|
15
|
+
readonly total: number;
|
|
16
|
+
}
|
|
17
|
+
export interface CostThesisRatioV0 {
|
|
18
|
+
readonly fresh: number;
|
|
19
|
+
readonly reused: number;
|
|
20
|
+
readonly label: string;
|
|
21
|
+
readonly reused_is_zero: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface CostThesisScenarioRefV0 {
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly profile: ScenarioWorldProfileV0;
|
|
26
|
+
readonly initial_instant: string;
|
|
27
|
+
readonly final_instant: string;
|
|
28
|
+
}
|
|
29
|
+
export interface CostThesisTurnDetailV0 {
|
|
30
|
+
readonly index: number;
|
|
31
|
+
readonly as_of: string;
|
|
32
|
+
readonly source: CostThesisTurnSourceV0;
|
|
33
|
+
readonly outcome: CostThesisTurnOutcomeV0;
|
|
34
|
+
readonly tokens: CostThesisTokensV0;
|
|
35
|
+
readonly model_invocation_count: number;
|
|
36
|
+
readonly event_cause?: ReceiptEventCauseV0;
|
|
37
|
+
readonly recheck_kind?: ReceiptRecheckKindV0;
|
|
38
|
+
readonly receipt_hash?: ContentHashV0;
|
|
39
|
+
readonly provider?: string;
|
|
40
|
+
readonly model?: string;
|
|
41
|
+
readonly role?: ReceiptRoleV0;
|
|
42
|
+
readonly review_kind?: string;
|
|
43
|
+
readonly source_ids?: readonly string[];
|
|
44
|
+
readonly note: string;
|
|
45
|
+
}
|
|
46
|
+
export interface CostThesisReportRowV0 {
|
|
47
|
+
readonly variant: CostThesisRowVariantV0;
|
|
48
|
+
readonly label: string;
|
|
49
|
+
readonly scenario: CostThesisScenarioRefV0;
|
|
50
|
+
readonly provenance: CostThesisRowProvenanceV0;
|
|
51
|
+
readonly receipt_count: number;
|
|
52
|
+
readonly turn_count: number;
|
|
53
|
+
readonly model_invocation_count: number;
|
|
54
|
+
readonly tokens: CostThesisTokensV0;
|
|
55
|
+
readonly ratio: CostThesisRatioV0;
|
|
56
|
+
readonly notes: readonly string[];
|
|
57
|
+
readonly turns: readonly CostThesisTurnDetailV0[];
|
|
58
|
+
readonly source_summary_hash?: ContentHashV0;
|
|
59
|
+
}
|
|
60
|
+
export type CostThesisEventChangingStatusV0 = {
|
|
61
|
+
readonly status: "absent";
|
|
62
|
+
readonly reason: string;
|
|
63
|
+
readonly notes: readonly string[];
|
|
64
|
+
} | {
|
|
65
|
+
readonly status: "measured";
|
|
66
|
+
readonly scenario_id: string;
|
|
67
|
+
readonly profile: Exclude<ScenarioWorldProfileV0, "static">;
|
|
68
|
+
readonly rows: readonly CostThesisReportRowV0[];
|
|
69
|
+
readonly notes: readonly string[];
|
|
70
|
+
};
|
|
71
|
+
export interface CostThesisStaticScenarioSummaryV0 {
|
|
72
|
+
readonly scenario: CostThesisScenarioRefV0;
|
|
73
|
+
readonly status: "measured";
|
|
74
|
+
readonly rows: readonly CostThesisReportRowV0[];
|
|
75
|
+
readonly notes: readonly string[];
|
|
76
|
+
}
|
|
77
|
+
export interface CostThesisSummaryV0 {
|
|
78
|
+
readonly schema: typeof COST_THESIS_SUMMARY_SCHEMA_V0;
|
|
79
|
+
readonly v: typeof COST_THESIS_SUMMARY_VERSION_V0;
|
|
80
|
+
readonly generated_at: typeof COST_THESIS_GENERATED_AT_V0;
|
|
81
|
+
readonly static_scenario: CostThesisStaticScenarioSummaryV0;
|
|
82
|
+
readonly event_changing_scenario?: CostThesisEventChangingStatusV0;
|
|
83
|
+
readonly notes: readonly string[];
|
|
84
|
+
readonly content_hash: ContentHashV0;
|
|
85
|
+
}
|
|
86
|
+
export interface CreateStaticCostThesisSummaryInputV0 {
|
|
87
|
+
readonly reactor_run: ScenarioRunReceiptV0;
|
|
88
|
+
readonly no_memo: NoMemoBaselineSummaryV0;
|
|
89
|
+
readonly naive_loop: NaiveLoopBaselineSummaryV0;
|
|
90
|
+
readonly event_changing_scenario?: CostThesisEventChangingStatusV0;
|
|
91
|
+
}
|
|
92
|
+
export declare function createC5StaticCostThesisSummaryV0(input: CreateStaticCostThesisSummaryInputV0): CostThesisSummaryV0;
|
|
93
|
+
export declare function measureReactorStaticCostRowV0(run: ScenarioRunReceiptV0): CostThesisReportRowV0;
|
|
94
|
+
export declare function measureReactorRuntimeCostRowV0(run: ScenarioRunReceiptV0): CostThesisReportRowV0;
|
|
95
|
+
export declare function createC5EventChangingCostThesisScenarioV0(input: {
|
|
96
|
+
readonly reactor_run: ScenarioRunReceiptV0;
|
|
97
|
+
}): Extract<CostThesisEventChangingStatusV0, {
|
|
98
|
+
readonly status: "measured";
|
|
99
|
+
}>;
|
|
100
|
+
export declare function normalizeNoMemoCostRowV0(summary: NoMemoBaselineSummaryV0, expectedScenario?: CostThesisScenarioRefV0): CostThesisReportRowV0;
|
|
101
|
+
export declare function normalizeNaiveLoopCostRowV0(summary: NaiveLoopBaselineSummaryV0, expectedScenario?: CostThesisScenarioRefV0): CostThesisReportRowV0;
|
|
102
|
+
export declare function missingEventChangingScenarioV0(): CostThesisEventChangingStatusV0;
|
|
103
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/baselines/cost-thesis/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EAEd,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EACV,uBAAuB,EAExB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,0BAA0B,EAE3B,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEzF,eAAO,MAAM,6BAA6B,EACxC,uDAAgE,CAAC;AACnE,eAAO,MAAM,8BAA8B,EAAG,CAAU,CAAC;AACzD,eAAO,MAAM,2BAA2B,EACtC,0BAAmC,CAAC;AAEtC,MAAM,MAAM,sBAAsB,GAC9B,SAAS,GACT,iBAAiB,GACjB,YAAY,CAAC;AACjB,MAAM,MAAM,yBAAyB,GACjC,kBAAkB,GAClB,WAAW,GACX,SAAS,CAAC;AACd,MAAM,MAAM,sBAAsB,GAC9B,cAAc,GACd,oBAAoB,GACpB,oBAAoB,CAAC;AACzB,MAAM,MAAM,uBAAuB,GAC/B,kBAAkB,GAClB,iBAAiB,GACjB,UAAU,GACV,aAAa,GACb,gBAAgB,CAAC;AAErB,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KA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