@dsh-ray/assistant-evaluation 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +310 -2
  3. package/bin/dsh-benchmark.js +46 -0
  4. package/cordis.patch.yml +17 -0
  5. package/lib/attention-owner-questions.d.ts +104 -0
  6. package/lib/attention-owner-questions.d.ts.map +1 -0
  7. package/lib/attention-owner-questions.js +185 -0
  8. package/lib/attention-owner-questions.js.map +1 -0
  9. package/lib/attention-tuning.d.ts +513 -0
  10. package/lib/attention-tuning.d.ts.map +1 -0
  11. package/lib/attention-tuning.js +1242 -0
  12. package/lib/attention-tuning.js.map +1 -0
  13. package/lib/benchmark/cli.d.ts +6 -0
  14. package/lib/benchmark/cli.d.ts.map +1 -0
  15. package/lib/benchmark/cli.js +370 -0
  16. package/lib/benchmark/cli.js.map +1 -0
  17. package/lib/benchmark/corpus.d.ts +39 -0
  18. package/lib/benchmark/corpus.d.ts.map +1 -0
  19. package/lib/benchmark/corpus.js +183 -0
  20. package/lib/benchmark/corpus.js.map +1 -0
  21. package/lib/benchmark/deepseek.d.ts +15 -0
  22. package/lib/benchmark/deepseek.d.ts.map +1 -0
  23. package/lib/benchmark/deepseek.js +143 -0
  24. package/lib/benchmark/deepseek.js.map +1 -0
  25. package/lib/benchmark/families-corpus.d.ts +109 -0
  26. package/lib/benchmark/families-corpus.d.ts.map +1 -0
  27. package/lib/benchmark/families-corpus.js +587 -0
  28. package/lib/benchmark/families-corpus.js.map +1 -0
  29. package/lib/benchmark/families-runtime.d.ts +191 -0
  30. package/lib/benchmark/families-runtime.d.ts.map +1 -0
  31. package/lib/benchmark/families-runtime.js +1171 -0
  32. package/lib/benchmark/families-runtime.js.map +1 -0
  33. package/lib/benchmark/growth-runtime.d.ts +97 -0
  34. package/lib/benchmark/growth-runtime.d.ts.map +1 -0
  35. package/lib/benchmark/growth-runtime.js +437 -0
  36. package/lib/benchmark/growth-runtime.js.map +1 -0
  37. package/lib/benchmark/holdout-evidence.d.ts +126 -0
  38. package/lib/benchmark/holdout-evidence.d.ts.map +1 -0
  39. package/lib/benchmark/holdout-evidence.js +466 -0
  40. package/lib/benchmark/holdout-evidence.js.map +1 -0
  41. package/lib/benchmark/holdout-isolation.d.ts +27 -0
  42. package/lib/benchmark/holdout-isolation.d.ts.map +1 -0
  43. package/lib/benchmark/holdout-isolation.js +66 -0
  44. package/lib/benchmark/holdout-isolation.js.map +1 -0
  45. package/lib/benchmark/holdout-protocol.d.ts +68 -0
  46. package/lib/benchmark/holdout-protocol.d.ts.map +1 -0
  47. package/lib/benchmark/holdout-protocol.js +271 -0
  48. package/lib/benchmark/holdout-protocol.js.map +1 -0
  49. package/lib/benchmark/holdout-provider.d.ts +26 -0
  50. package/lib/benchmark/holdout-provider.d.ts.map +1 -0
  51. package/lib/benchmark/holdout-provider.js +382 -0
  52. package/lib/benchmark/holdout-provider.js.map +1 -0
  53. package/lib/benchmark/holdout.d.ts +83 -0
  54. package/lib/benchmark/holdout.d.ts.map +1 -0
  55. package/lib/benchmark/holdout.js +394 -0
  56. package/lib/benchmark/holdout.js.map +1 -0
  57. package/lib/benchmark/index.d.ts +12 -0
  58. package/lib/benchmark/index.d.ts.map +1 -0
  59. package/lib/benchmark/index.js +9 -0
  60. package/lib/benchmark/index.js.map +1 -0
  61. package/lib/benchmark/memory-corpus.d.ts +55 -0
  62. package/lib/benchmark/memory-corpus.d.ts.map +1 -0
  63. package/lib/benchmark/memory-corpus.js +153 -0
  64. package/lib/benchmark/memory-corpus.js.map +1 -0
  65. package/lib/benchmark/memory-runtime.d.ts +63 -0
  66. package/lib/benchmark/memory-runtime.d.ts.map +1 -0
  67. package/lib/benchmark/memory-runtime.js +75 -0
  68. package/lib/benchmark/memory-runtime.js.map +1 -0
  69. package/lib/benchmark/native-goal-services.d.ts +66 -0
  70. package/lib/benchmark/native-goal-services.d.ts.map +1 -0
  71. package/lib/benchmark/native-goal-services.js +52 -0
  72. package/lib/benchmark/native-goal-services.js.map +1 -0
  73. package/lib/benchmark/native-skills-runtime.d.ts +157 -0
  74. package/lib/benchmark/native-skills-runtime.d.ts.map +1 -0
  75. package/lib/benchmark/native-skills-runtime.js +337 -0
  76. package/lib/benchmark/native-skills-runtime.js.map +1 -0
  77. package/lib/benchmark/native-skills.d.ts +142 -0
  78. package/lib/benchmark/native-skills.d.ts.map +1 -0
  79. package/lib/benchmark/native-skills.js +259 -0
  80. package/lib/benchmark/native-skills.js.map +1 -0
  81. package/lib/benchmark/native.d.ts +77 -0
  82. package/lib/benchmark/native.d.ts.map +1 -0
  83. package/lib/benchmark/native.js +711 -0
  84. package/lib/benchmark/native.js.map +1 -0
  85. package/lib/benchmark/planning-runtime.d.ts +80 -0
  86. package/lib/benchmark/planning-runtime.d.ts.map +1 -0
  87. package/lib/benchmark/planning-runtime.js +313 -0
  88. package/lib/benchmark/planning-runtime.js.map +1 -0
  89. package/lib/benchmark/report.d.ts +4 -0
  90. package/lib/benchmark/report.d.ts.map +1 -0
  91. package/lib/benchmark/report.js +243 -0
  92. package/lib/benchmark/report.js.map +1 -0
  93. package/lib/benchmark/runner.d.ts +25 -0
  94. package/lib/benchmark/runner.d.ts.map +1 -0
  95. package/lib/benchmark/runner.js +124 -0
  96. package/lib/benchmark/runner.js.map +1 -0
  97. package/lib/benchmark/schema.d.ts +20 -0
  98. package/lib/benchmark/schema.d.ts.map +1 -0
  99. package/lib/benchmark/schema.js +183 -0
  100. package/lib/benchmark/schema.js.map +1 -0
  101. package/lib/benchmark/store.d.ts +18 -0
  102. package/lib/benchmark/store.d.ts.map +1 -0
  103. package/lib/benchmark/store.js +321 -0
  104. package/lib/benchmark/store.js.map +1 -0
  105. package/lib/benchmark/strategy-capabilities.d.ts +154 -0
  106. package/lib/benchmark/strategy-capabilities.d.ts.map +1 -0
  107. package/lib/benchmark/strategy-capabilities.js +304 -0
  108. package/lib/benchmark/strategy-capabilities.js.map +1 -0
  109. package/lib/benchmark/strategy-config.d.ts +29 -0
  110. package/lib/benchmark/strategy-config.d.ts.map +1 -0
  111. package/lib/benchmark/strategy-config.js +98 -0
  112. package/lib/benchmark/strategy-config.js.map +1 -0
  113. package/lib/benchmark/strategy-corpus-v2.d.ts +18 -0
  114. package/lib/benchmark/strategy-corpus-v2.d.ts.map +1 -0
  115. package/lib/benchmark/strategy-corpus-v2.js +143 -0
  116. package/lib/benchmark/strategy-corpus-v2.js.map +1 -0
  117. package/lib/benchmark/strategy-corpus.d.ts +30 -0
  118. package/lib/benchmark/strategy-corpus.d.ts.map +1 -0
  119. package/lib/benchmark/strategy-corpus.js +95 -0
  120. package/lib/benchmark/strategy-corpus.js.map +1 -0
  121. package/lib/benchmark/strategy-evidence.d.ts +161 -0
  122. package/lib/benchmark/strategy-evidence.d.ts.map +1 -0
  123. package/lib/benchmark/strategy-evidence.js +561 -0
  124. package/lib/benchmark/strategy-evidence.js.map +1 -0
  125. package/lib/benchmark/strategy-executor.d.ts +29 -0
  126. package/lib/benchmark/strategy-executor.d.ts.map +1 -0
  127. package/lib/benchmark/strategy-executor.js +180 -0
  128. package/lib/benchmark/strategy-executor.js.map +1 -0
  129. package/lib/benchmark/strategy-goal-runtime.d.ts +80 -0
  130. package/lib/benchmark/strategy-goal-runtime.d.ts.map +1 -0
  131. package/lib/benchmark/strategy-goal-runtime.js +283 -0
  132. package/lib/benchmark/strategy-goal-runtime.js.map +1 -0
  133. package/lib/benchmark/strategy-meter.d.ts +62 -0
  134. package/lib/benchmark/strategy-meter.d.ts.map +1 -0
  135. package/lib/benchmark/strategy-meter.js +330 -0
  136. package/lib/benchmark/strategy-meter.js.map +1 -0
  137. package/lib/benchmark/strategy-owner.d.ts +71 -0
  138. package/lib/benchmark/strategy-owner.d.ts.map +1 -0
  139. package/lib/benchmark/strategy-owner.js +282 -0
  140. package/lib/benchmark/strategy-owner.js.map +1 -0
  141. package/lib/benchmark/strategy-plan.d.ts +58 -0
  142. package/lib/benchmark/strategy-plan.d.ts.map +1 -0
  143. package/lib/benchmark/strategy-plan.js +81 -0
  144. package/lib/benchmark/strategy-plan.js.map +1 -0
  145. package/lib/benchmark/strategy-policy.d.ts +16 -0
  146. package/lib/benchmark/strategy-policy.d.ts.map +1 -0
  147. package/lib/benchmark/strategy-policy.js +77 -0
  148. package/lib/benchmark/strategy-policy.js.map +1 -0
  149. package/lib/benchmark/strategy-projection.d.ts +157 -0
  150. package/lib/benchmark/strategy-projection.d.ts.map +1 -0
  151. package/lib/benchmark/strategy-projection.js +171 -0
  152. package/lib/benchmark/strategy-projection.js.map +1 -0
  153. package/lib/benchmark/strategy.d.ts +17 -0
  154. package/lib/benchmark/strategy.d.ts.map +1 -0
  155. package/lib/benchmark/strategy.js +21 -0
  156. package/lib/benchmark/strategy.js.map +1 -0
  157. package/lib/benchmark/traex.d.ts +17 -0
  158. package/lib/benchmark/traex.d.ts.map +1 -0
  159. package/lib/benchmark/traex.js +139 -0
  160. package/lib/benchmark/traex.js.map +1 -0
  161. package/lib/benchmark/types.d.ts +190 -0
  162. package/lib/benchmark/types.d.ts.map +1 -0
  163. package/lib/benchmark/types.js +3 -0
  164. package/lib/benchmark/types.js.map +1 -0
  165. package/lib/benchmark/usage.d.ts +36 -0
  166. package/lib/benchmark/usage.d.ts.map +1 -0
  167. package/lib/benchmark/usage.js +84 -0
  168. package/lib/benchmark/usage.js.map +1 -0
  169. package/lib/index.d.ts +26 -0
  170. package/lib/index.d.ts.map +1 -0
  171. package/lib/index.js +19 -0
  172. package/lib/index.js.map +1 -0
  173. package/lib/intake-attention-agreement-store.d.ts +33 -0
  174. package/lib/intake-attention-agreement-store.d.ts.map +1 -0
  175. package/lib/intake-attention-agreement-store.js +162 -0
  176. package/lib/intake-attention-agreement-store.js.map +1 -0
  177. package/lib/intake-attention-agreement.d.ts +126 -0
  178. package/lib/intake-attention-agreement.d.ts.map +1 -0
  179. package/lib/intake-attention-agreement.js +209 -0
  180. package/lib/intake-attention-agreement.js.map +1 -0
  181. package/lib/intake-evaluation-agreement.d.ts +204 -0
  182. package/lib/intake-evaluation-agreement.d.ts.map +1 -0
  183. package/lib/intake-evaluation-agreement.js +740 -0
  184. package/lib/intake-evaluation-agreement.js.map +1 -0
  185. package/lib/notification-outcomes.d.ts +63 -0
  186. package/lib/notification-outcomes.d.ts.map +1 -0
  187. package/lib/notification-outcomes.js +399 -0
  188. package/lib/notification-outcomes.js.map +1 -0
  189. package/lib/service.d.ts +694 -0
  190. package/lib/service.d.ts.map +1 -0
  191. package/lib/service.js +2992 -0
  192. package/lib/service.js.map +1 -0
  193. package/lib/sqlite.d.ts +15 -0
  194. package/lib/sqlite.d.ts.map +1 -0
  195. package/lib/sqlite.js +1247 -0
  196. package/lib/sqlite.js.map +1 -0
  197. package/lib/store.d.ts +175 -0
  198. package/lib/store.d.ts.map +1 -0
  199. package/lib/store.js +1722 -0
  200. package/lib/store.js.map +1 -0
  201. package/lib/tools.d.ts +4 -0
  202. package/lib/tools.d.ts.map +1 -0
  203. package/lib/tools.js +212 -0
  204. package/lib/tools.js.map +1 -0
  205. package/lib/types.d.ts +787 -0
  206. package/lib/types.d.ts.map +1 -0
  207. package/lib/types.js +28 -0
  208. package/lib/types.js.map +1 -0
  209. package/lib/version.d.ts +2 -0
  210. package/lib/version.d.ts.map +1 -0
  211. package/lib/version.js +2 -0
  212. package/lib/version.js.map +1 -0
  213. package/lib/work-item-owner-proof.d.ts +4 -0
  214. package/lib/work-item-owner-proof.d.ts.map +1 -0
  215. package/lib/work-item-owner-proof.js +53 -0
  216. package/lib/work-item-owner-proof.js.map +1 -0
  217. package/package.json +242 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategy-evidence.d.ts","sourceRoot":"","sources":["../../src/benchmark/strategy-evidence.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAA;AAGxG,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,qBA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AI,EAAE,MAAM,CAAA;KAAE,CAAC;IAMrF,WAAW,CAAC,SAAS,EAAE,qBAAqB,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC,qBAAqB,CAAC;IAGnH,SAAS,CAAC,KAAK,EAAE,iBAAiB,GAAG,QAAQ,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAM/E,QAAQ,CAAC,SAAS,EAAE,qBAAqB,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC,kBAAkB,CAAC;CA6C9G"}
@@ -0,0 +1,561 @@
1
+ import { closeSync, constants, fstatSync, fsyncSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, unlinkSync, writeFileSync } from 'node:fs';
2
+ import { isAbsolute, relative, resolve } from 'node:path';
3
+ import { createHash, randomUUID } from 'node:crypto';
4
+ import { acceptanceCanonicalJson, validateTaskAcceptanceContract, validateTaskVerificationReceipt } from '@dsh-ray/task-acceptance-contract';
5
+ import { benchmarkHash, benchmarkObject, benchmarkSchedule } from './schema.js';
6
+ import { parseStrategyBenchmarkPlan, strategyBenchmarkJournalPlan, strategyBenchmarkPlanDigest } from './strategy-plan.js';
7
+ import { assertStrategyPolicyConfiguration } from './strategy-policy.js';
8
+ export const strategyEvidenceProtocol = 'dsh-native-goal-strategy-evidence/v1';
9
+ export const strategyFailureProtocol = 'dsh-native-goal-strategy-failure/v1';
10
+ export const strategyCellProtocol = 'dsh-native-goal-strategy-cell/v1';
11
+ // A cell aggregates many individually bounded contracts and model traces.
12
+ // Keep their canonical encoding while using an independent aggregate bound.
13
+ const MAX_EVIDENCE_BYTES = 32 * 1024 * 1024;
14
+ function evidenceJson(value) {
15
+ const active = new Set();
16
+ let nodes = 0;
17
+ let bytes = 0;
18
+ const encode = (item, depth) => {
19
+ if (++nodes > 500000 || depth > 32)
20
+ fail('evidence is too complex');
21
+ if (item === null || typeof item === 'boolean' || typeof item === 'string' || typeof item === 'number') {
22
+ if (typeof item === 'number' && (!Number.isFinite(item) || Number.isInteger(item) && !Number.isSafeInteger(item)))
23
+ fail('invalid evidence number');
24
+ if (typeof item === 'string' && Buffer.byteLength(item) > MAX_EVIDENCE_BYTES)
25
+ fail('evidence too large');
26
+ const text = JSON.stringify(item);
27
+ bytes += Buffer.byteLength(text);
28
+ if (bytes > MAX_EVIDENCE_BYTES)
29
+ fail('evidence too large');
30
+ return text;
31
+ }
32
+ if (typeof item !== 'object' || active.has(item))
33
+ fail('invalid evidence value');
34
+ const array = Array.isArray(item);
35
+ if (!array && Object.getPrototypeOf(item) !== Object.prototype && Object.getPrototypeOf(item) !== null)
36
+ fail('non-plain evidence');
37
+ const names = Reflect.ownKeys(item).filter(key => !(array && key === 'length'));
38
+ for (const key of names) {
39
+ const descriptor = Object.getOwnPropertyDescriptor(item, key);
40
+ if (typeof key === 'string') {
41
+ bytes += Buffer.byteLength(key) + 3;
42
+ if (bytes > MAX_EVIDENCE_BYTES)
43
+ fail('evidence too large');
44
+ }
45
+ if (typeof key !== 'string' || ['__proto__', 'prototype', 'constructor'].includes(key) || !descriptor.enumerable || !('value' in descriptor))
46
+ fail('non-plain evidence');
47
+ }
48
+ if (array && (names.length !== item.length || item.length > 10001 || names.some((key, index) => key !== String(index))))
49
+ fail('invalid evidence array');
50
+ active.add(item);
51
+ try {
52
+ return array ? `[${item.map(child => encode(child, depth + 1)).join(',')}]`
53
+ : `{${names.sort().map(key => `${JSON.stringify(key)}:${encode(item[key], depth + 1)}`).join(',')}}`;
54
+ }
55
+ finally {
56
+ active.delete(item);
57
+ }
58
+ };
59
+ const text = encode(value, 0);
60
+ if (Buffer.byteLength(text) > MAX_EVIDENCE_BYTES)
61
+ fail('evidence too large');
62
+ return text;
63
+ }
64
+ function evidenceSnapshot(value) {
65
+ const copy = JSON.parse(evidenceJson(value));
66
+ const freeze = (item) => { if (item && typeof item === 'object') {
67
+ Object.values(item).forEach(freeze);
68
+ Object.freeze(item);
69
+ } };
70
+ freeze(copy);
71
+ return copy;
72
+ }
73
+ const evidenceDigest = (value) => createHash('sha256').update(evidenceJson(value)).digest('hex');
74
+ function fail(message) { throw new Error(`strategy evidence: ${message}`); }
75
+ const identical = (a, b) => acceptanceCanonicalJson(a) === acceptanceCanonicalJson(b);
76
+ const id = (value, label, max = 512) => {
77
+ if (typeof value !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._:/-]*$/u.test(value) || value.length > max)
78
+ fail(`invalid ${label}`);
79
+ return value;
80
+ };
81
+ const verdict = (value) => {
82
+ if (value !== 'achieved' && value !== 'not-achieved' && value !== 'unknown')
83
+ fail('invalid verdict');
84
+ return value;
85
+ };
86
+ const privateDirectory = (path, label, create) => {
87
+ if (!isAbsolute(path))
88
+ fail(`${label} must be absolute`);
89
+ if (create)
90
+ mkdirSync(path, { recursive: true, mode: 0o700 });
91
+ const original = lstatSync(path);
92
+ if (original.isSymbolicLink())
93
+ fail(`${label} is not private`);
94
+ const resolved = realpathSync(path);
95
+ if (resolved !== path)
96
+ fail(`${label} must be canonical`);
97
+ const stat = lstatSync(resolved);
98
+ const uid = process.getuid?.();
99
+ if (!stat.isDirectory() || stat.isSymbolicLink() || (stat.mode & 0o077) !== 0 || uid !== undefined && stat.uid !== uid)
100
+ fail(`${label} is not private`);
101
+ return resolved;
102
+ };
103
+ const nested = (parent, child) => { const path = relative(parent, child); return path === '' || (!path.startsWith('..') && !isAbsolute(path)); };
104
+ function privateFile(path) {
105
+ const stat = lstatSync(path);
106
+ if (stat.size > MAX_EVIDENCE_BYTES)
107
+ fail('evidence too large');
108
+ const uid = process.getuid?.();
109
+ if (!stat.isFile() || stat.isSymbolicLink() || stat.nlink !== 1 || (stat.mode & 0o077) !== 0 || uid !== undefined && stat.uid !== uid)
110
+ fail('evidence object is not private');
111
+ }
112
+ function privateOpenedFile(fd, path) {
113
+ const stat = fstatSync(fd);
114
+ if (stat.size > MAX_EVIDENCE_BYTES)
115
+ fail('evidence too large');
116
+ const entry = lstatSync(path);
117
+ const uid = process.getuid?.();
118
+ if (!stat.isFile() || stat.nlink !== 1 || (stat.mode & 0o077) !== 0 || uid !== undefined && stat.uid !== uid
119
+ || entry.isSymbolicLink() || entry.dev !== stat.dev || entry.ino !== stat.ino || entry.nlink !== 1
120
+ || (entry.mode & 0o077) !== 0 || uid !== undefined && entry.uid !== uid)
121
+ fail('evidence object is not private');
122
+ }
123
+ function syncDirectory(path) { const fd = openSync(path, constants.O_RDONLY | constants.O_DIRECTORY); try {
124
+ fsyncSync(fd);
125
+ }
126
+ finally {
127
+ closeSync(fd);
128
+ } }
129
+ function keys(value, expected) { return benchmarkObject(value, expected); }
130
+ function requestFor(plan, cell) {
131
+ const journal = strategyBenchmarkJournalPlan(plan);
132
+ const exact = benchmarkSchedule(journal).find(item => identical(item, cell));
133
+ if (!exact)
134
+ fail('cell is not in strategy plan');
135
+ const task = journal.cases.find(item => item.id === exact.caseId);
136
+ const variant = journal.variants.find(item => item.id === exact.variantId);
137
+ if (!task || !variant)
138
+ fail('cell has no bound request');
139
+ return { planId: journal.id, dataset: journal.dataset, cell: exact, task, variant, budget: journal.budget };
140
+ }
141
+ function parseMeter(value, expectedMode) {
142
+ const raw = keys(evidenceSnapshot(value), ['observationMode', 'budget', 'modelCalls', 'toolCalls', 'activeToolCalls', 'inputTokens', 'outputTokens', 'costUsdMicros', 'heldModelCalls', 'heldInputTokens', 'heldOutputTokens', 'heldCostUsdMicros', 'traces']);
143
+ if ((raw.observationMode !== 'enforced-upper-bound-provider-output' && raw.observationMode !== 'observed-call-count') || !Array.isArray(raw.traces) || raw.traces.length > 10_001)
144
+ fail('invalid meter snapshot');
145
+ // Cross-check the meter's self-reported mode against the plaintext mode frozen in the plan.
146
+ if (raw.observationMode !== expectedMode)
147
+ fail('meter observation mode differs from frozen plan');
148
+ const callsMode = raw.observationMode === 'observed-call-count';
149
+ const budget = keys(raw.budget, ['durationMs', 'inputTokens', 'outputTokens', 'costUsdMicros', 'toolCalls']);
150
+ for (const name of ['durationMs', 'inputTokens', 'outputTokens', 'toolCalls'])
151
+ if (!Number.isSafeInteger(budget[name]) || budget[name] < 0)
152
+ fail('invalid meter budget');
153
+ if (budget.costUsdMicros !== null && (!Number.isSafeInteger(budget.costUsdMicros) || budget.costUsdMicros < 0))
154
+ fail('invalid meter budget');
155
+ if (callsMode && (budget.costUsdMicros !== null || budget.inputTokens !== 0))
156
+ fail('invalid call-count meter budget');
157
+ for (const name of ['modelCalls', 'toolCalls', 'activeToolCalls', 'inputTokens', 'outputTokens', 'heldModelCalls', 'heldInputTokens', 'heldOutputTokens'])
158
+ if (!Number.isSafeInteger(raw[name]) || raw[name] < 0)
159
+ fail('invalid meter counters');
160
+ if (raw.costUsdMicros !== null && (!Number.isSafeInteger(raw.costUsdMicros) || raw.costUsdMicros < 0) || raw.heldCostUsdMicros !== null && (!Number.isSafeInteger(raw.heldCostUsdMicros) || raw.heldCostUsdMicros < 0))
161
+ fail('invalid meter cost');
162
+ let calls = 0;
163
+ let input = 0;
164
+ let output = 0;
165
+ let heldCalls = 0;
166
+ let heldInput = 0;
167
+ let heldOutput = 0;
168
+ let heldCost = raw.heldCostUsdMicros === null ? null : 0;
169
+ const ids = new Set();
170
+ raw.traces.forEach(trace => {
171
+ const item = keys(trace, ['id', 'sessionId', 'agentId', 'startedAt', 'completedAt', 'phase', 'dispatched', 'reservedInputTokens', 'reservedOutputTokens', 'reservedCostUsdMicros', 'usage', 'reason']);
172
+ if (!Number.isSafeInteger(item.id) || item.id < 1 || ids.has(item.id) || !Number.isSafeInteger(item.startedAt) || item.startedAt < 0 || item.completedAt !== null && (!Number.isSafeInteger(item.completedAt) || item.completedAt < item.startedAt) || !(item.sessionId === null || typeof item.sessionId === 'string') || !(item.agentId === null || typeof item.agentId === 'string') || typeof item.dispatched !== 'boolean' || !['preflight', 'reserved', 'streaming', 'settled', 'retained', 'rejected'].includes(item.phase) || !Number.isSafeInteger(item.reservedInputTokens) || !Number.isSafeInteger(item.reservedOutputTokens) || item.reservedInputTokens < 0 || item.reservedOutputTokens < 0 || !(item.reservedCostUsdMicros === null || Number.isSafeInteger(item.reservedCostUsdMicros) && item.reservedCostUsdMicros >= 0) || !(item.reason === null || ['cancelled', 'disposed', 'request-contract', 'input-bound', 'shared-budget', 'stream', 'usage', 'cost', 'tool-budget'].includes(item.reason)))
173
+ fail('invalid meter trace');
174
+ ids.add(item.id);
175
+ if (callsMode) {
176
+ // Call-count mode never measures tokens or money: every reservation is zero,
177
+ // cost is null, and a settled trace carries usage=null while still counting one call.
178
+ if (item.reservedInputTokens !== 0 || item.reservedOutputTokens !== 0 || item.reservedCostUsdMicros !== null || item.usage !== null)
179
+ fail('invalid call-count meter trace');
180
+ if (item.phase === 'settled') {
181
+ if (!item.dispatched || item.completedAt === null || item.reason !== null)
182
+ fail('invalid settled trace');
183
+ calls++;
184
+ }
185
+ else {
186
+ if (item.phase === 'rejected' && item.dispatched)
187
+ fail('invalid rejected reservation');
188
+ if (item.phase === 'preflight' && (item.dispatched || item.completedAt !== null || item.reason !== null)
189
+ || (item.phase === 'reserved' || item.phase === 'streaming') && (item.completedAt !== null || item.reason !== null)
190
+ || item.phase === 'streaming' && !item.dispatched
191
+ || (item.phase === 'retained' || item.phase === 'rejected') && (item.completedAt === null || item.reason === null))
192
+ fail('invalid meter phase');
193
+ if (item.phase === 'reserved' || item.phase === 'streaming' || item.phase === 'retained')
194
+ heldCalls++;
195
+ }
196
+ return;
197
+ }
198
+ const reserved = item.reservedInputTokens > 0 || item.reservedOutputTokens > 0;
199
+ if (item.phase === 'settled') {
200
+ if (!item.dispatched || item.completedAt === null || item.reason !== null || !reserved)
201
+ fail('invalid settled trace');
202
+ const usage = keys(item.usage, ['inputTokens', 'uncachedInputTokens', 'outputTokens', 'cacheReadTokens', 'cacheWriteTokens', 'reasoningTokens', 'totalTokens']);
203
+ for (const field of Object.values(usage))
204
+ if (!Number.isSafeInteger(field) || field < 0)
205
+ fail('invalid settled usage');
206
+ if (usage.inputTokens > item.reservedInputTokens || usage.outputTokens > item.reservedOutputTokens)
207
+ fail('usage exceeds reservation');
208
+ if (usage.inputTokens !== usage.uncachedInputTokens + usage.cacheReadTokens + usage.cacheWriteTokens || usage.totalTokens !== usage.inputTokens + usage.outputTokens || usage.reasoningTokens > usage.outputTokens)
209
+ fail('invalid settled usage');
210
+ calls++;
211
+ input += usage.inputTokens;
212
+ output += usage.outputTokens;
213
+ }
214
+ else {
215
+ if (item.phase === 'retained' && !reserved || item.phase === 'rejected' && (reserved || item.dispatched))
216
+ fail('invalid rejected reservation');
217
+ if (item.usage !== null || item.phase === 'preflight' && (item.dispatched || item.completedAt !== null || item.reason !== null || reserved) || (item.phase === 'reserved' || item.phase === 'streaming') && (item.completedAt !== null || item.reason !== null || !reserved) || item.phase === 'streaming' && !item.dispatched || (item.phase === 'retained' || item.phase === 'rejected') && (item.completedAt === null || item.reason === null))
218
+ fail('invalid meter phase');
219
+ if (item.phase === 'reserved' || item.phase === 'streaming' || item.phase === 'retained') {
220
+ heldCalls++;
221
+ heldInput += item.reservedInputTokens;
222
+ heldOutput += item.reservedOutputTokens;
223
+ if (heldCost !== null) {
224
+ if (item.reservedCostUsdMicros === null)
225
+ fail('meter aggregate mismatch');
226
+ heldCost += item.reservedCostUsdMicros;
227
+ }
228
+ }
229
+ }
230
+ });
231
+ if (callsMode) {
232
+ if (calls !== raw.modelCalls || heldCalls !== raw.heldModelCalls || raw.activeToolCalls > raw.toolCalls
233
+ || input !== 0 || output !== 0 || heldInput !== 0 || heldOutput !== 0 || heldCost !== null
234
+ || raw.inputTokens !== 0 || raw.outputTokens !== 0 || raw.costUsdMicros !== null
235
+ || raw.heldInputTokens !== 0 || raw.heldOutputTokens !== 0 || raw.heldCostUsdMicros !== null)
236
+ fail('meter aggregate mismatch');
237
+ }
238
+ else if (calls !== raw.modelCalls || input !== raw.inputTokens || output !== raw.outputTokens || heldCalls !== raw.heldModelCalls || heldInput !== raw.heldInputTokens || heldOutput !== raw.heldOutputTokens || heldCost !== raw.heldCostUsdMicros || raw.activeToolCalls > raw.toolCalls)
239
+ fail('meter aggregate mismatch');
240
+ return raw;
241
+ }
242
+ function validateMeterBounds(meter, plan, budget) {
243
+ if (meter.modelCalls > plan.execution.modelCalls || meter.heldModelCalls > plan.execution.modelCalls || meter.modelCalls + meter.heldModelCalls > plan.execution.modelCalls
244
+ || meter.toolCalls > budget.toolCalls || meter.activeToolCalls > meter.toolCalls)
245
+ fail('meter exceeds bound plan');
246
+ // Call-count mode has no token or monetary budget; only call/tool bounds are enforceable.
247
+ if (meter.observationMode === 'observed-call-count')
248
+ return;
249
+ if (meter.inputTokens > budget.inputTokens || meter.heldInputTokens > budget.inputTokens || meter.inputTokens + meter.heldInputTokens > budget.inputTokens
250
+ || meter.outputTokens > budget.outputTokens || meter.heldOutputTokens > budget.outputTokens || meter.outputTokens + meter.heldOutputTokens > budget.outputTokens
251
+ || meter.traces.some(trace => trace.reservedInputTokens > budget.inputTokens || trace.reservedOutputTokens > plan.execution.maxOutputTokensPerCall)
252
+ || budget.costUsdMicros !== null && (meter.costUsdMicros === null || meter.heldCostUsdMicros === null || meter.costUsdMicros > budget.costUsdMicros || meter.heldCostUsdMicros > budget.costUsdMicros || meter.costUsdMicros + meter.heldCostUsdMicros > budget.costUsdMicros))
253
+ fail('meter exceeds bound plan');
254
+ }
255
+ function parseNative(value) {
256
+ const raw = keys(value, ['parent', 'runs', 'strategies', 'outcomeAssessments', 'selectedOutcomeContractId', 'receipts']);
257
+ const parent = keys(raw.parent, ['sessionId', 'goalId', 'nativeGoalId', 'definitionVersion', 'definitionDigest', 'lifecycle', 'quiescent']);
258
+ id(parent.sessionId, 'parent session');
259
+ id(parent.goalId, 'parent goal');
260
+ id(parent.nativeGoalId, 'native parent goal');
261
+ if (!Number.isSafeInteger(parent.definitionVersion) || parent.definitionVersion < 1 || !/^[a-f0-9]{64}$/u.test(parent.definitionDigest) || !['completed', 'failed', 'cancelled', 'unknown'].includes(parent.lifecycle) || typeof parent.quiescent !== 'boolean' || !Array.isArray(raw.runs) || !Array.isArray(raw.strategies) || !Array.isArray(raw.outcomeAssessments) || !Array.isArray(raw.receipts))
262
+ fail('invalid native evidence');
263
+ const runs = new Map();
264
+ raw.runs.forEach(run => { const item = keys(run, ['runId', 'executionStatus', 'quiescent']); const runId = id(item.runId, 'run id'); if (!['succeeded', 'unknown'].includes(item.executionStatus) || typeof item.quiescent !== 'boolean' || runs.has(runId))
265
+ fail('invalid native run'); runs.set(runId, { executionStatus: item.executionStatus, quiescent: item.quiescent }); });
266
+ const strategyIds = new Set();
267
+ const childSessions = new Set();
268
+ raw.strategies.forEach(strategy => { const item = keys(strategy, ['strategyId', 'parentRunId', 'kind', 'outcome', 'children']); const strategyId = id(item.strategyId, 'strategy id'); if (strategyIds.has(strategyId) || !runs.has(id(item.parentRunId, 'strategy parent run')) || !['investigate', 'review', 'compare'].includes(item.kind) || !['advice', 'execution-failed', 'cancelled', 'unknown'].includes(item.outcome) || !Array.isArray(item.children))
269
+ fail('invalid strategy evidence'); strategyIds.add(strategyId); item.children.forEach(child => { const row = keys(child, ['sessionId', 'stopReason', 'quiescent']); const sessionId = id(row.sessionId, 'child session'); id(row.stopReason, 'child stop reason'); if (childSessions.has(sessionId) || typeof row.quiescent !== 'boolean')
270
+ fail('invalid child lifecycle'); childSessions.add(sessionId); }); });
271
+ const assessments = new Map();
272
+ raw.outcomeAssessments.forEach(assessment => { const item = keys(assessment, ['contract', 'triggerRunId', 'dispatchedAt', 'execution']); let contract; try {
273
+ contract = validateTaskAcceptanceContract(item.contract);
274
+ }
275
+ catch {
276
+ fail('invalid outcome assessment');
277
+ } ; if (contract.task.kind !== 'goal-outcome' || assessments.has(contract.id) || !(item.triggerRunId === null || typeof item.triggerRunId === 'string') || item.triggerRunId !== null && !runs.has(id(item.triggerRunId, 'assessment trigger run')) || !(item.dispatchedAt === null || Number.isSafeInteger(item.dispatchedAt) && item.dispatchedAt >= 0))
278
+ fail('invalid outcome assessment'); const goal = contract.task.goal; if (goal.id !== parent.goalId || goal.sessionId !== parent.sessionId || goal.nativeGoalId !== parent.nativeGoalId || goal.definitionVersion !== parent.definitionVersion || goal.definitionDigest !== parent.definitionDigest)
279
+ fail('outcome assessment binding differs'); let execution = null; if (item.execution !== null) {
280
+ const status = keys(item.execution, ['status', 'quiescent', 'completedAt']);
281
+ if ((status.status !== 'succeeded' && status.status !== 'unknown') || typeof status.quiescent !== 'boolean' || !Number.isSafeInteger(status.completedAt) || status.completedAt < 0 || item.dispatchedAt === null || status.completedAt < item.dispatchedAt)
282
+ fail('invalid outcome assessment');
283
+ execution = status;
284
+ } ; assessments.set(contract.id, { contract, triggerRunId: item.triggerRunId, dispatchedAt: item.dispatchedAt, execution }); });
285
+ if (raw.selectedOutcomeContractId !== null && typeof raw.selectedOutcomeContractId !== 'string')
286
+ fail('invalid selected outcome');
287
+ const selected = raw.selectedOutcomeContractId === null ? undefined : assessments.get(id(raw.selectedOutcomeContractId, 'selected outcome'));
288
+ const selectedAt = selected?.dispatchedAt;
289
+ if (raw.selectedOutcomeContractId !== null && (selected === undefined || selectedAt === null || selectedAt === undefined || selected.execution === null || [...assessments.values()].some(item => item !== selected && item.dispatchedAt !== null && item.dispatchedAt >= selectedAt)))
290
+ fail('invalid selected outcome');
291
+ const contractIds = new Set();
292
+ const receiptIds = new Set();
293
+ raw.receipts.forEach(receipt => { const item = keys(receipt, ['runId', 'taskKind', 'contract', 'receipt', 'quiescent']); const runId = id(item.runId, 'receipt run'); const run = runs.get(runId); if (!run || (item.taskKind !== 'goal-step' && item.taskKind !== 'goal-outcome') || typeof item.quiescent !== 'boolean')
294
+ fail('invalid receipt lifecycle'); let contract; let proof; try {
295
+ contract = validateTaskAcceptanceContract(item.contract);
296
+ proof = validateTaskVerificationReceipt(contract, item.receipt);
297
+ }
298
+ catch {
299
+ fail('invalid acceptance receipt');
300
+ } ; if (contract.task.kind !== 'goal-step' && contract.task.kind !== 'goal-outcome')
301
+ fail('receipt binding differs'); const assessment = contract.task.kind === 'goal-outcome' ? assessments.get(contract.id) : undefined; if (contractIds.has(contract.id) || receiptIds.has(proof.id) || contract.task.kind !== item.taskKind || contract.task.kind === 'goal-outcome' && (assessment === undefined || !identical(assessment.contract, contract) || assessment.triggerRunId !== runId))
302
+ fail('receipt binding differs'); const goal = contract.task.goal; if (goal.id !== parent.goalId || goal.sessionId !== parent.sessionId || goal.nativeGoalId !== parent.nativeGoalId || goal.definitionVersion !== parent.definitionVersion || goal.definitionDigest !== parent.definitionDigest || contract.task.kind === 'goal-step' && contract.task.goal.runId !== runId)
303
+ fail('receipt binding differs'); contractIds.add(contract.id); receiptIds.add(proof.id); });
304
+ return raw;
305
+ }
306
+ function parse(input, expectedMode) {
307
+ const raw = keys(evidenceSnapshot(input), ['protocol', 'version', 'planDigest', 'request', 'input', 'acceptance', 'versions', 'meter', 'native', 'outcome']);
308
+ if (raw.protocol !== strategyEvidenceProtocol || raw.version !== 1)
309
+ fail('unsupported protocol');
310
+ benchmarkHash(raw.planDigest);
311
+ const request = keys(raw.request, ['planId', 'dataset', 'cell', 'task', 'variant', 'budget']);
312
+ id(request.planId, 'plan id');
313
+ const inputDigest = keys(raw.input, ['digest']);
314
+ const acceptance = keys(raw.acceptance, ['digest', 'verdict']);
315
+ benchmarkHash(inputDigest.digest);
316
+ benchmarkHash(acceptance.digest);
317
+ const accepted = verdict(acceptance.verdict);
318
+ const outcome = keys(raw.outcome, ['status', 'verdict', 'quiescent']);
319
+ if ((outcome.status !== 'completed' && outcome.status !== 'unknown') || typeof outcome.quiescent !== 'boolean')
320
+ fail('invalid outcome');
321
+ const result = verdict(outcome.verdict);
322
+ const native = parseNative(raw.native);
323
+ const meter = parseMeter(raw.meter, expectedMode);
324
+ const attributedSessions = new Set([native.parent.sessionId, ...native.strategies.flatMap(strategy => strategy.children.map(child => child.sessionId))]);
325
+ const knownNativeStop = native.runs.length > 0 && native.runs.every(run => run.executionStatus === 'succeeded' && run.quiescent)
326
+ && native.strategies.every(strategy => strategy.outcome !== 'unknown' && strategy.children.every(child => child.quiescent))
327
+ && native.outcomeAssessments.every(assessment => assessment.execution?.status === 'succeeded' && assessment.execution.quiescent)
328
+ && meter.traces.every(trace => trace.sessionId !== null && attributedSessions.has(trace.sessionId));
329
+ if ((native.parent.quiescent || outcome.quiescent) && !knownNativeStop)
330
+ fail('native quiescence is not established');
331
+ const versions = keys(raw.versions, ['model', 'prompt', 'skills', 'tools', 'policy', 'runtime']);
332
+ Object.values(versions).forEach(benchmarkHash);
333
+ const trustedOutcome = native.selectedOutcomeContractId !== null && native.receipts.some(item => {
334
+ if (item.taskKind !== 'goal-outcome' || item.contract.id !== native.selectedOutcomeContractId || item.receipt.objectiveStatus !== result || !item.quiescent)
335
+ return false;
336
+ const run = native.runs.find(row => row.runId === item.runId);
337
+ const assessment = native.outcomeAssessments.find(row => identical(row.contract, item.contract));
338
+ return run?.executionStatus === 'succeeded' && run.quiescent && assessment?.triggerRunId === item.runId && assessment.execution?.status === 'succeeded' && assessment.execution.quiescent;
339
+ });
340
+ if (accepted !== result || native.selectedOutcomeContractId === null && result !== 'unknown' || result !== 'unknown' && native.selectedOutcomeContractId !== null && !trustedOutcome || result === 'achieved' && (!knownNativeStop || outcome.status !== 'completed' || !outcome.quiescent || !native.parent.quiescent || native.parent.lifecycle !== 'completed' || meter.modelCalls < 1 || meter.heldModelCalls !== 0 || meter.activeToolCalls !== 0 || meter.traces.length < 1 || meter.traces.some(trace => trace.phase !== 'settled') || !trustedOutcome))
341
+ fail('achieved evidence is incomplete');
342
+ if (outcome.status === 'unknown' && result !== 'unknown')
343
+ fail('unknown outcome cannot assert a verdict');
344
+ return raw;
345
+ }
346
+ export class StrategyEvidenceStore {
347
+ #directory;
348
+ constructor(input) {
349
+ if (!isAbsolute(input.candidateWorkspace) || !isAbsolute(input.stateDirectory))
350
+ fail('workspace and state directory must be absolute');
351
+ const workspace = privateDirectory(input.candidateWorkspace, 'candidate workspace', false);
352
+ const state = privateDirectory(input.stateDirectory, 'evidence state directory', input.createDirectories !== false);
353
+ if (nested(workspace, state) || nested(state, workspace))
354
+ fail('evidence state must be outside candidate workspace');
355
+ this.#directory = privateDirectory(resolve(state, 'strategy-evidence-v1'), 'evidence object directory', input.createDirectories !== false);
356
+ }
357
+ #path(digest) { benchmarkHash(digest); return resolve(this.#directory, `${digest}.json`); }
358
+ write(input) {
359
+ input = evidenceSnapshot(input);
360
+ const plan = parseStrategyBenchmarkPlan(input.plan);
361
+ const expected = requestFor(plan, input.request.cell);
362
+ const { plan: _plan, ...unbound } = input;
363
+ const object = parse({ ...unbound, planDigest: strategyBenchmarkPlanDigest(plan) }, plan.execution.observationMode);
364
+ if (!identical(object.request, expected) || !identical(object.meter.budget, expected.budget) || object.input.digest !== expected.task.inputDigest || object.acceptance.digest !== expected.task.acceptanceDigest || !identical(object.versions, expected.variant.versions))
365
+ fail('request identity drift');
366
+ validateMeterBounds(object.meter, plan, expected.budget);
367
+ return this.#publish(strategyEvidenceProtocol, object);
368
+ }
369
+ #publish(protocol, object) {
370
+ const digest = evidenceDigest(object);
371
+ const content = evidenceJson({ protocol, version: 1, digest, evidence: object });
372
+ const path = this.#path(digest);
373
+ try {
374
+ privateFile(path);
375
+ if (readFileSync(path, 'utf8') !== content)
376
+ fail('digest collision or conflicting evidence');
377
+ return Object.freeze({ digest, path });
378
+ }
379
+ catch (error) {
380
+ if (error.code !== 'ENOENT')
381
+ throw error;
382
+ }
383
+ const temporary = resolve(this.#directory, `.${digest}.${randomUUID()}.tmp`);
384
+ let fd;
385
+ try {
386
+ fd = openSync(temporary, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | constants.O_NOFOLLOW, 0o600);
387
+ writeFileSync(fd, content, 'utf8');
388
+ fsyncSync(fd);
389
+ closeSync(fd);
390
+ fd = undefined;
391
+ try {
392
+ linkSync(temporary, path);
393
+ }
394
+ catch (error) {
395
+ if (error.code !== 'EEXIST')
396
+ throw error;
397
+ privateFile(path);
398
+ if (readFileSync(path, 'utf8') !== content)
399
+ fail('digest collision or conflicting evidence');
400
+ }
401
+ unlinkSync(temporary);
402
+ syncDirectory(this.#directory);
403
+ return Object.freeze({ digest, path });
404
+ }
405
+ finally {
406
+ if (fd !== undefined)
407
+ closeSync(fd);
408
+ try {
409
+ unlinkSync(temporary);
410
+ }
411
+ catch { }
412
+ }
413
+ }
414
+ read(planInput, cell, digest) {
415
+ const plan = parseStrategyBenchmarkPlan(planInput);
416
+ const expected = requestFor(plan, cell);
417
+ const evidence = parse(this.#readEnvelope(strategyEvidenceProtocol, digest), plan.execution.observationMode);
418
+ if (evidenceDigest(evidence) !== digest || evidence.planDigest !== strategyBenchmarkPlanDigest(plan) || !identical(evidence.request, expected) || !identical(evidence.meter.budget, expected.budget)
419
+ || evidence.input.digest !== expected.task.inputDigest || evidence.acceptance.digest !== expected.task.acceptanceDigest || !identical(evidence.versions, expected.variant.versions))
420
+ fail('evidence binding differs');
421
+ validateMeterBounds(evidence.meter, plan, expected.budget);
422
+ return evidence;
423
+ }
424
+ #readEnvelope(protocol, digest) {
425
+ const path = this.#path(digest);
426
+ privateFile(path);
427
+ let serialized;
428
+ let fd;
429
+ try {
430
+ fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW);
431
+ privateOpenedFile(fd, path);
432
+ serialized = readFileSync(fd, 'utf8');
433
+ privateOpenedFile(fd, path);
434
+ }
435
+ catch (error) {
436
+ if (error.message?.startsWith('strategy evidence:'))
437
+ throw error;
438
+ fail('invalid evidence object');
439
+ }
440
+ finally {
441
+ if (fd !== undefined)
442
+ closeSync(fd);
443
+ }
444
+ let value;
445
+ try {
446
+ value = JSON.parse(serialized);
447
+ }
448
+ catch {
449
+ fail('invalid evidence JSON');
450
+ }
451
+ const envelope = keys(value, ['protocol', 'version', 'digest', 'evidence']);
452
+ if (envelope.protocol !== protocol || envelope.version !== 1 || envelope.digest !== digest || evidenceDigest(envelope.evidence) !== digest)
453
+ fail('invalid evidence envelope');
454
+ return envelope.evidence;
455
+ }
456
+ /** A failure observation is terminal evidence of uncertainty, never an acceptance receipt. */
457
+ writeFailure(input) {
458
+ const copy = evidenceSnapshot(input);
459
+ const plan = parseStrategyBenchmarkPlan(copy.plan);
460
+ const { plan: _plan, ...body } = copy;
461
+ const evidence = parseFailure({ ...body, planDigest: strategyBenchmarkPlanDigest(plan) }, plan, copy.request.cell);
462
+ return this.#publish(strategyFailureProtocol, evidence);
463
+ }
464
+ readFailure(planInput, cell, digest) {
465
+ return parseFailure(this.#readEnvelope(strategyFailureProtocol, digest), parseStrategyBenchmarkPlan(planInput), cell);
466
+ }
467
+ writeCell(input) {
468
+ const copy = evidenceSnapshot(input);
469
+ const plan = parseStrategyBenchmarkPlan(copy.plan);
470
+ const { plan: _plan, ...body } = copy;
471
+ const evidence = this.#parseCell({ ...body, planDigest: strategyBenchmarkPlanDigest(plan) }, plan, copy.request.cell);
472
+ return this.#publish(strategyCellProtocol, evidence);
473
+ }
474
+ readCell(planInput, cell, digest) {
475
+ return this.#parseCell(this.#readEnvelope(strategyCellProtocol, digest), parseStrategyBenchmarkPlan(planInput), cell);
476
+ }
477
+ #parseCell(value, plan, cell) {
478
+ const raw = keys(evidenceSnapshot(value), ['protocol', 'version', 'planDigest', 'request', 'nativeEvidenceDigest', 'capabilities']);
479
+ if (raw.protocol !== strategyCellProtocol || raw.version !== 1 || raw.planDigest !== strategyBenchmarkPlanDigest(plan)
480
+ || !identical(raw.request, requestFor(plan, cell)))
481
+ fail('invalid cell binding');
482
+ benchmarkHash(raw.nativeEvidenceDigest);
483
+ const native = this.read(plan, cell, raw.nativeEvidenceDigest);
484
+ if (native.outcome.status !== 'completed' || native.outcome.verdict === 'unknown' || !native.outcome.quiescent)
485
+ fail('cell outcome remains unknown');
486
+ const capability = keys(raw.capabilities, ['sourceIdentity', 'runtimeCommitment', 'requests']);
487
+ const commitment = keys(capability.runtimeCommitment, ['source', 'sourceIdentityDigest', 'runtimeDigest', 'cgroupRootsDigest', 'stepMaxDurationMs', 'stopTimeoutMs']);
488
+ const sourceDigest = evidenceDigest(capability.sourceIdentity);
489
+ if (commitment.sourceIdentityDigest !== sourceDigest || evidenceDigest(commitment) !== plan.capabilities.common.runtime)
490
+ fail('runtime source commitment drift');
491
+ if (!Array.isArray(capability.requests) || capability.requests.length !== native.meter.traces.length || capability.requests.length === 0)
492
+ fail('incomplete capability observations');
493
+ const expectedCounts = new Map();
494
+ for (const trace of native.meter.traces) {
495
+ if (trace.sessionId === null || trace.phase !== 'settled')
496
+ fail('cell meter remains unknown');
497
+ expectedCounts.set(trace.sessionId, (expectedCounts.get(trace.sessionId) ?? 0) + 1);
498
+ }
499
+ const children = new Set(native.native.strategies.flatMap(strategy => strategy.children.map(child => child.sessionId)));
500
+ const enabled = cell.variantId === 'adaptive-strategy';
501
+ const toolNames = ['goal_create', 'goal_context', 'goal_checkpoint', 'isolation_run', ...(enabled ? ['goal_strategy'] : [])].sort();
502
+ for (const input of capability.requests) {
503
+ const request = keys(input, ['sessionId', 'kind', 'observation']);
504
+ const sessionId = id(request.sessionId, 'capability Session');
505
+ const count = expectedCounts.get(sessionId) ?? 0;
506
+ if (count === 0)
507
+ fail('capability request is not metered');
508
+ expectedCounts.set(sessionId, count - 1);
509
+ if (request.kind === 'child') {
510
+ if (!children.has(sessionId) || request.observation !== null)
511
+ fail('unattributed capability child');
512
+ }
513
+ else {
514
+ if (request.kind !== 'parent' || sessionId !== native.native.parent.sessionId)
515
+ fail('unattributed capability parent');
516
+ const observation = keys(request.observation, ['sourceDigest', 'services', 'parentTools', 'policy', 'personaDigest', 'dynamicGoalContext']);
517
+ if (observation.sourceDigest !== sourceDigest || observation.personaDigest !== plan.capabilities.common.persona
518
+ || !identical(observation.services, { goals: true, assistantPolicy: true, tools: true }) || observation.dynamicGoalContext !== 'not-attested')
519
+ fail('capability probe differs');
520
+ const policy = keys(observation.policy, ['common', 'strategy', 'configuration', 'configDigest']);
521
+ if (policy.common !== 'allow' || policy.strategy !== (enabled ? 'allow' : 'deny') || policy.configDigest !== evidenceDigest(policy.configuration))
522
+ fail('capability policy drift');
523
+ assertStrategyPolicyConfiguration(policy.configuration, enabled);
524
+ if (!Array.isArray(observation.parentTools) || !identical(observation.parentTools.map(tool => keys(tool, ['name', 'description', 'parameters', 'output']).name).sort(), toolNames))
525
+ fail('capability tool set differs');
526
+ }
527
+ }
528
+ if ([...expectedCounts.values()].some(count => count !== 0))
529
+ fail('incomplete metered request observations');
530
+ return raw;
531
+ }
532
+ }
533
+ function parseFailure(value, plan, cell) {
534
+ const raw = keys(evidenceSnapshot(value), ['protocol', 'version', 'planDigest', 'request', 'reason', 'observedAt', 'snapshot']);
535
+ const expected = requestFor(plan, cell);
536
+ if (raw.protocol !== strategyFailureProtocol || raw.version !== 1 || raw.planDigest !== strategyBenchmarkPlanDigest(plan)
537
+ || !identical(raw.request, expected) || !['adapter-error', 'interrupted', 'timeout', 'invalid-observation', 'budget-exceeded', 'not-quiescent'].includes(raw.reason)
538
+ || !Number.isSafeInteger(raw.observedAt) || raw.observedAt < 0)
539
+ fail('invalid failure binding');
540
+ const snapshot = keys(raw.snapshot, ['runtimeRoot', 'stage', 'cleanup', 'meter', 'goalSnapshot', 'lastGoalObservation', 'failureStage']);
541
+ if (!(snapshot.runtimeRoot === null || typeof snapshot.runtimeRoot === 'string' && isAbsolute(snapshot.runtimeRoot))
542
+ || !['setup', 'executing', 'cleanup', 'evidence', 'closed'].includes(snapshot.stage)
543
+ || !['pending', 'succeeded', 'unknown'].includes(snapshot.cleanup)
544
+ || !(snapshot.goalSnapshot === null || typeof snapshot.goalSnapshot === 'object' && !Array.isArray(snapshot.goalSnapshot))
545
+ || !(snapshot.failureStage === null || ['setup', 'executing', 'cleanup', 'evidence'].includes(snapshot.failureStage)))
546
+ fail('invalid failure snapshot');
547
+ if (snapshot.lastGoalObservation !== null) {
548
+ const history = keys(snapshot.lastGoalObservation, ['observedAt', 'value']);
549
+ if (!Number.isSafeInteger(history.observedAt) || history.observedAt < 0 || history.observedAt > raw.observedAt
550
+ || history.value === null || typeof history.value !== 'object' || Array.isArray(history.value))
551
+ fail('invalid historical goal observation');
552
+ }
553
+ if (snapshot.meter !== null) {
554
+ const meter = parseMeter(snapshot.meter, plan.execution.observationMode);
555
+ if (!identical(meter.budget, expected.budget))
556
+ fail('failure meter budget drift');
557
+ validateMeterBounds(meter, plan, expected.budget);
558
+ }
559
+ return raw;
560
+ }
561
+ //# sourceMappingURL=strategy-evidence.js.map