@agentplat/mesh-sim 0.3.0-beta.1 → 0.3.0-beta.4

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 (189) hide show
  1. package/README.md +462 -2
  2. package/dist/collective-closed-loop-action.d.ts +80 -0
  3. package/dist/collective-closed-loop-action.d.ts.map +1 -0
  4. package/dist/collective-closed-loop-action.js +471 -0
  5. package/dist/collective-closed-loop-action.js.map +1 -0
  6. package/dist/collective-closed-loop-contracts.d.ts +75 -0
  7. package/dist/collective-closed-loop-contracts.d.ts.map +1 -0
  8. package/dist/collective-closed-loop-contracts.js +420 -0
  9. package/dist/collective-closed-loop-contracts.js.map +1 -0
  10. package/dist/collective-closed-loop-fault-matrix.d.ts +101 -0
  11. package/dist/collective-closed-loop-fault-matrix.d.ts.map +1 -0
  12. package/dist/collective-closed-loop-fault-matrix.js +253 -0
  13. package/dist/collective-closed-loop-fault-matrix.js.map +1 -0
  14. package/dist/collective-closed-loop-recovery.d.ts +70 -0
  15. package/dist/collective-closed-loop-recovery.d.ts.map +1 -0
  16. package/dist/collective-closed-loop-recovery.js +823 -0
  17. package/dist/collective-closed-loop-recovery.js.map +1 -0
  18. package/dist/collective-closed-loop-reference.d.ts +54 -0
  19. package/dist/collective-closed-loop-reference.d.ts.map +1 -0
  20. package/dist/collective-closed-loop-reference.js +1696 -0
  21. package/dist/collective-closed-loop-reference.js.map +1 -0
  22. package/dist/collective-closed-loop-replanning.d.ts +27 -0
  23. package/dist/collective-closed-loop-replanning.d.ts.map +1 -0
  24. package/dist/collective-closed-loop-replanning.js +151 -0
  25. package/dist/collective-closed-loop-replanning.js.map +1 -0
  26. package/dist/collective-closed-loop-resilience-campaign.d.ts +22 -0
  27. package/dist/collective-closed-loop-resilience-campaign.d.ts.map +1 -0
  28. package/dist/collective-closed-loop-resilience-campaign.js +196 -0
  29. package/dist/collective-closed-loop-resilience-campaign.js.map +1 -0
  30. package/dist/collective-closed-loop-resilience-contracts.d.ts +138 -0
  31. package/dist/collective-closed-loop-resilience-contracts.d.ts.map +1 -0
  32. package/dist/collective-closed-loop-resilience-contracts.js +677 -0
  33. package/dist/collective-closed-loop-resilience-contracts.js.map +1 -0
  34. package/dist/collective-closed-loop-runner.d.ts +133 -0
  35. package/dist/collective-closed-loop-runner.d.ts.map +1 -0
  36. package/dist/collective-closed-loop-runner.js +1429 -0
  37. package/dist/collective-closed-loop-runner.js.map +1 -0
  38. package/dist/collective-closed-loop-runtime.d.ts +95 -0
  39. package/dist/collective-closed-loop-runtime.d.ts.map +1 -0
  40. package/dist/collective-closed-loop-runtime.js +1192 -0
  41. package/dist/collective-closed-loop-runtime.js.map +1 -0
  42. package/dist/collective-effect-provenance.d.ts +5 -0
  43. package/dist/collective-effect-provenance.d.ts.map +1 -0
  44. package/dist/collective-effect-provenance.js +32 -0
  45. package/dist/collective-effect-provenance.js.map +1 -0
  46. package/dist/collective-environment.d.ts +49 -0
  47. package/dist/collective-environment.d.ts.map +1 -0
  48. package/dist/collective-environment.js +907 -0
  49. package/dist/collective-environment.js.map +1 -0
  50. package/dist/collective-evaluation.d.ts +38 -0
  51. package/dist/collective-evaluation.d.ts.map +1 -0
  52. package/dist/collective-evaluation.js +730 -0
  53. package/dist/collective-evaluation.js.map +1 -0
  54. package/dist/collective-progressive-scale-overlay.d.ts +39 -0
  55. package/dist/collective-progressive-scale-overlay.d.ts.map +1 -0
  56. package/dist/collective-progressive-scale-overlay.js +147 -0
  57. package/dist/collective-progressive-scale-overlay.js.map +1 -0
  58. package/dist/collective-progressive-scale.d.ts +202 -0
  59. package/dist/collective-progressive-scale.d.ts.map +1 -0
  60. package/dist/collective-progressive-scale.js +755 -0
  61. package/dist/collective-progressive-scale.js.map +1 -0
  62. package/dist/collective-statistical-campaign-aggregation.d.ts +97 -0
  63. package/dist/collective-statistical-campaign-aggregation.d.ts.map +1 -0
  64. package/dist/collective-statistical-campaign-aggregation.js +446 -0
  65. package/dist/collective-statistical-campaign-aggregation.js.map +1 -0
  66. package/dist/collective-statistical-campaign-artifact-stream.d.ts +66 -0
  67. package/dist/collective-statistical-campaign-artifact-stream.d.ts.map +1 -0
  68. package/dist/collective-statistical-campaign-artifact-stream.js +207 -0
  69. package/dist/collective-statistical-campaign-artifact-stream.js.map +1 -0
  70. package/dist/collective-statistical-campaign-bundle.d.ts +151 -0
  71. package/dist/collective-statistical-campaign-bundle.d.ts.map +1 -0
  72. package/dist/collective-statistical-campaign-bundle.js +885 -0
  73. package/dist/collective-statistical-campaign-bundle.js.map +1 -0
  74. package/dist/collective-statistical-campaign-executor.d.ts +131 -0
  75. package/dist/collective-statistical-campaign-executor.d.ts.map +1 -0
  76. package/dist/collective-statistical-campaign-executor.js +856 -0
  77. package/dist/collective-statistical-campaign-executor.js.map +1 -0
  78. package/dist/collective-statistical-campaign-normative-analysis.d.ts +85 -0
  79. package/dist/collective-statistical-campaign-normative-analysis.d.ts.map +1 -0
  80. package/dist/collective-statistical-campaign-normative-analysis.js +483 -0
  81. package/dist/collective-statistical-campaign-normative-analysis.js.map +1 -0
  82. package/dist/collective-statistical-campaign-normative-operation.d.ts +89 -0
  83. package/dist/collective-statistical-campaign-normative-operation.d.ts.map +1 -0
  84. package/dist/collective-statistical-campaign-normative-operation.js +266 -0
  85. package/dist/collective-statistical-campaign-normative-operation.js.map +1 -0
  86. package/dist/collective-statistical-campaign-normative-registry.d.ts +24 -0
  87. package/dist/collective-statistical-campaign-normative-registry.d.ts.map +1 -0
  88. package/dist/collective-statistical-campaign-normative-registry.js +163 -0
  89. package/dist/collective-statistical-campaign-normative-registry.js.map +1 -0
  90. package/dist/collective-statistical-campaign-registered-adapter.d.ts +16 -0
  91. package/dist/collective-statistical-campaign-registered-adapter.d.ts.map +1 -0
  92. package/dist/collective-statistical-campaign-registered-adapter.js +518 -0
  93. package/dist/collective-statistical-campaign-registered-adapter.js.map +1 -0
  94. package/dist/collective-statistical-campaign-scale.d.ts +85 -0
  95. package/dist/collective-statistical-campaign-scale.d.ts.map +1 -0
  96. package/dist/collective-statistical-campaign-scale.js +349 -0
  97. package/dist/collective-statistical-campaign-scale.js.map +1 -0
  98. package/dist/collective-trace-journal.d.ts +20 -0
  99. package/dist/collective-trace-journal.d.ts.map +1 -0
  100. package/dist/collective-trace-journal.js +105 -0
  101. package/dist/collective-trace-journal.js.map +1 -0
  102. package/dist/index.d.ts +26 -0
  103. package/dist/index.d.ts.map +1 -1
  104. package/dist/index.js +26 -0
  105. package/dist/index.js.map +1 -1
  106. package/dist/multi-domain-environment-contracts.d.ts +122 -0
  107. package/dist/multi-domain-environment-contracts.d.ts.map +1 -0
  108. package/dist/multi-domain-environment-contracts.js +14 -0
  109. package/dist/multi-domain-environment-contracts.js.map +1 -0
  110. package/dist/multi-domain-environment-runtime.d.ts +25 -0
  111. package/dist/multi-domain-environment-runtime.d.ts.map +1 -0
  112. package/dist/multi-domain-environment-runtime.js +493 -0
  113. package/dist/multi-domain-environment-runtime.js.map +1 -0
  114. package/dist/multi-domain-environment-validation.d.ts +33 -0
  115. package/dist/multi-domain-environment-validation.d.ts.map +1 -0
  116. package/dist/multi-domain-environment-validation.js +415 -0
  117. package/dist/multi-domain-environment-validation.js.map +1 -0
  118. package/dist/multi-domain-environment.d.ts +4 -0
  119. package/dist/multi-domain-environment.d.ts.map +1 -0
  120. package/dist/multi-domain-environment.js +4 -0
  121. package/dist/multi-domain-environment.js.map +1 -0
  122. package/dist/reducer-scenario.d.ts.map +1 -1
  123. package/dist/reducer-scenario.js +67 -19
  124. package/dist/reducer-scenario.js.map +1 -1
  125. package/dist/scalable-evaluation-contracts.d.ts +835 -0
  126. package/dist/scalable-evaluation-contracts.d.ts.map +1 -0
  127. package/dist/scalable-evaluation-contracts.js +22 -0
  128. package/dist/scalable-evaluation-contracts.js.map +1 -0
  129. package/dist/scalable-evaluation-durability.d.ts +16 -0
  130. package/dist/scalable-evaluation-durability.d.ts.map +1 -0
  131. package/dist/scalable-evaluation-durability.js +339 -0
  132. package/dist/scalable-evaluation-durability.js.map +1 -0
  133. package/dist/scalable-evaluation-evidence.d.ts +93 -0
  134. package/dist/scalable-evaluation-evidence.d.ts.map +1 -0
  135. package/dist/scalable-evaluation-evidence.js +470 -0
  136. package/dist/scalable-evaluation-evidence.js.map +1 -0
  137. package/dist/scalable-evaluation-reference-integrated.d.ts +87 -0
  138. package/dist/scalable-evaluation-reference-integrated.d.ts.map +1 -0
  139. package/dist/scalable-evaluation-reference-integrated.js +1318 -0
  140. package/dist/scalable-evaluation-reference-integrated.js.map +1 -0
  141. package/dist/scalable-evaluation-runner.d.ts +8 -0
  142. package/dist/scalable-evaluation-runner.d.ts.map +1 -0
  143. package/dist/scalable-evaluation-runner.js +1810 -0
  144. package/dist/scalable-evaluation-runner.js.map +1 -0
  145. package/dist/scalable-evaluation-runtime.d.ts +86 -0
  146. package/dist/scalable-evaluation-runtime.d.ts.map +1 -0
  147. package/dist/scalable-evaluation-runtime.js +1310 -0
  148. package/dist/scalable-evaluation-runtime.js.map +1 -0
  149. package/dist/scalable-evaluation-validation.d.ts +59 -0
  150. package/dist/scalable-evaluation-validation.d.ts.map +1 -0
  151. package/dist/scalable-evaluation-validation.js +377 -0
  152. package/dist/scalable-evaluation-validation.js.map +1 -0
  153. package/dist/scalable-evaluation.d.ts +8 -0
  154. package/dist/scalable-evaluation.d.ts.map +1 -0
  155. package/dist/scalable-evaluation.js +8 -0
  156. package/dist/scalable-evaluation.js.map +1 -0
  157. package/dist/sharded-simulation-contracts.d.ts +240 -0
  158. package/dist/sharded-simulation-contracts.d.ts.map +1 -0
  159. package/dist/sharded-simulation-contracts.js +199 -0
  160. package/dist/sharded-simulation-contracts.js.map +1 -0
  161. package/dist/sharded-simulation-runtime.d.ts +64 -0
  162. package/dist/sharded-simulation-runtime.d.ts.map +1 -0
  163. package/dist/sharded-simulation-runtime.js +755 -0
  164. package/dist/sharded-simulation-runtime.js.map +1 -0
  165. package/dist/sharded-simulation-validation.d.ts +10 -0
  166. package/dist/sharded-simulation-validation.d.ts.map +1 -0
  167. package/dist/sharded-simulation-validation.js +250 -0
  168. package/dist/sharded-simulation-validation.js.map +1 -0
  169. package/dist/sharded-simulation.d.ts +46 -0
  170. package/dist/sharded-simulation.d.ts.map +1 -0
  171. package/dist/sharded-simulation.js +32 -0
  172. package/dist/sharded-simulation.js.map +1 -0
  173. package/dist/verified-benchmark-contracts.d.ts +132 -0
  174. package/dist/verified-benchmark-contracts.d.ts.map +1 -0
  175. package/dist/verified-benchmark-contracts.js +2 -0
  176. package/dist/verified-benchmark-contracts.js.map +1 -0
  177. package/dist/verified-benchmark-runtime.d.ts +20 -0
  178. package/dist/verified-benchmark-runtime.d.ts.map +1 -0
  179. package/dist/verified-benchmark-runtime.js +199 -0
  180. package/dist/verified-benchmark-runtime.js.map +1 -0
  181. package/dist/verified-benchmark-validation.d.ts +64 -0
  182. package/dist/verified-benchmark-validation.d.ts.map +1 -0
  183. package/dist/verified-benchmark-validation.js +481 -0
  184. package/dist/verified-benchmark-validation.js.map +1 -0
  185. package/dist/verified-benchmark.d.ts +4 -0
  186. package/dist/verified-benchmark.d.ts.map +1 -0
  187. package/dist/verified-benchmark.js +4 -0
  188. package/dist/verified-benchmark.js.map +1 -0
  189. package/package.json +18 -4
@@ -0,0 +1,730 @@
1
+ import { acceptDelegationMandateV1, authorizeDelegationMandateAtV1, budgetReservationDigestV1, createCollectiveAuthorityStateV1, createCollectiveExecutionStateV1, createDelegationMandateV1, delegationMandateDigestV1, digestCollectiveJsonV1, governedActionPermitDigestV1, issueGovernedActionPermitV1, registerWorkContractV1, transitionGovernedActionPermitV1, workContractDigestV1, } from '@agentplat/collective-control';
2
+ import { COLLECTIVE_ADVERSARY_FAMILIES_V1, COLLECTIVE_BENIGN_FAULT_FAMILIES_V1, COLLECTIVE_EVALUATION_PRNG_VERSION, COLLECTIVE_INTERACTION_ACCOUNTING_VERSION, createCollectiveEvaluationReportV1, createCollectiveEvaluationSampleV1, createCollectiveMissionV1, createExperimentRegistrationV1, createRoleCoherenceReportV1, validateCollectiveMissionV1, validateExperimentRegistrationV1, } from '@agentplat/collective-control/evaluation';
3
+ import { DefaultAgentRuntime } from '@agentplat/runtime';
4
+ import { MockAgentProvider } from '@agentplat/runtime-mock';
5
+ import { createMultiAgentSession } from '@agentplat/sessions';
6
+ export const COLLECTIVE_REFERENCE_MISSION_VERSION = 1;
7
+ export const COLLECTIVE_REFERENCE_DECISION_POLICY_VERSION = 1;
8
+ export const COLLECTIVE_REFERENCE_SCHEDULE_VERSION = 1;
9
+ export function createReferenceCollectiveMissionV1(input) {
10
+ if (!Number.isSafeInteger(input.agentCount) ||
11
+ input.agentCount < 4 ||
12
+ input.agentCount > 500)
13
+ throw new TypeError('agentCount must be an integer from 4 through 500');
14
+ const locations = ['central', 'east', 'north', 'south', 'west'];
15
+ const roles = [
16
+ ['allocator', 'resource.allocate'],
17
+ ['coordinator', 'mission.coordinate'],
18
+ ['executor', 'resource.execute'],
19
+ ['observer', 'mission.observe'],
20
+ ['recovery', 'mission.recover'],
21
+ ];
22
+ const width = String(input.agentCount - 1).length;
23
+ const agents = Array.from({ length: input.agentCount }, (_, index) => {
24
+ const role = roles[index % roles.length];
25
+ return {
26
+ schemaVersion: 1,
27
+ agentId: `agent:${String(index).padStart(width, '0')}`,
28
+ roleKey: role[0],
29
+ capabilityKeys: [role[1]],
30
+ locationKey: locations[index % locations.length],
31
+ };
32
+ });
33
+ const resourceCount = Math.max(4, Math.ceil(input.agentCount / 25));
34
+ const resources = Array.from({ length: resourceCount }, (_, index) => ({
35
+ schemaVersion: 1,
36
+ resourceId: `resource:${String(index).padStart(3, '0')}`,
37
+ locationKey: locations[index % locations.length],
38
+ capacityUnits: 4,
39
+ }));
40
+ const taskCount = Math.max(4, Math.ceil(input.agentCount / 20));
41
+ const tasks = Array.from({ length: taskCount }, (_, index) => {
42
+ const role = roles[index % roles.length];
43
+ return {
44
+ schemaVersion: 1,
45
+ taskId: `task:${String(index).padStart(3, '0')}`,
46
+ resourceId: resources[index % resources.length].resourceId,
47
+ requiredRoleKey: role[0],
48
+ requiredCapabilityKey: role[1],
49
+ dependencyTaskIds: index === 0 ? [] : [`task:${String(index - 1).padStart(3, '0')}`],
50
+ budgetUnits: 10,
51
+ objectiveValue: 100,
52
+ };
53
+ });
54
+ return createCollectiveMissionV1({
55
+ schemaVersion: 1,
56
+ missionId: `resource-allocation-recovery:${input.agentCount}`,
57
+ missionVersion: COLLECTIVE_REFERENCE_MISSION_VERSION,
58
+ resources,
59
+ tasks,
60
+ agents,
61
+ permittedInteractionKinds: [
62
+ 'assessment',
63
+ 'decision',
64
+ 'directive',
65
+ 'dispatch',
66
+ 'escalation',
67
+ 'message',
68
+ 'observation',
69
+ 'recovery',
70
+ ],
71
+ topology: {
72
+ schemaVersion: 1,
73
+ generator: 'bounded-role-ring-v1',
74
+ maximumDegree: input.maximumDegree ??
75
+ Math.min(32, Math.max(4, Math.ceil(Math.log2(input.agentCount)))),
76
+ },
77
+ limits: {
78
+ schemaVersion: 1,
79
+ maximumInteractions: input.maximumInteractions ?? 5_000,
80
+ maximumLogicalTime: 1_000_000,
81
+ maximumQueueDepth: Math.max(1_024, input.agentCount * 16),
82
+ maximumEvidenceRecords: Math.max(4_096, input.agentCount * 16),
83
+ },
84
+ });
85
+ }
86
+ export function createReferenceExperimentRegistrationV1(input) {
87
+ const mission = validateCollectiveMissionV1(input.mission);
88
+ return createExperimentRegistrationV1({
89
+ schemaVersion: 1,
90
+ registrationId: input.registrationId,
91
+ experimentVersion: 1,
92
+ missionDigest: mission.missionDigest,
93
+ sourceCommit: input.sourceCommit,
94
+ dirtyWorktree: input.dirtyWorktree,
95
+ implementationDigest: input.implementationDigest,
96
+ configurationDigest: digestCollectiveJsonV1('experiment-registration', {
97
+ schemaVersion: 1,
98
+ runner: input.runner,
99
+ stratum: input.stratum,
100
+ agentCount: mission.agents.length,
101
+ maximumInteractions: mission.limits.maximumInteractions,
102
+ maximumDegree: mission.topology.maximumDegree,
103
+ prngVersion: COLLECTIVE_EVALUATION_PRNG_VERSION,
104
+ }),
105
+ fixtureDigest: input.fixtureDigest,
106
+ runner: input.runner,
107
+ stratum: input.stratum,
108
+ agentCount: mission.agents.length,
109
+ seeds: [...input.seeds],
110
+ stoppingRule: 'fixed_registered_seeds',
111
+ topologyGenerator: mission.topology.generator,
112
+ maximumDegree: mission.topology.maximumDegree,
113
+ maximumInteractions: mission.limits.maximumInteractions,
114
+ interactionAccountingVersion: COLLECTIVE_INTERACTION_ACCOUNTING_VERSION,
115
+ decisionPolicyDigest: digestCollectiveJsonV1('state', {
116
+ schemaVersion: 1,
117
+ policy: 'reference-local-observation-policy',
118
+ version: COLLECTIVE_REFERENCE_DECISION_POLICY_VERSION,
119
+ }),
120
+ scheduleGeneratorVersion: COLLECTIVE_REFERENCE_SCHEDULE_VERSION,
121
+ aggregationSeed: input.aggregationSeed,
122
+ bootstrapResamples: input.bootstrapResamples ?? 10_000,
123
+ confidenceLevel: 0.95,
124
+ equivalenceMargin: 0.05,
125
+ redactionPolicyId: 'redaction:collective-evaluation-v1',
126
+ });
127
+ }
128
+ export async function runRegisteredCollectiveEvaluationV1(input) {
129
+ const registration = validateExperimentRegistrationV1(input.registration);
130
+ const mission = validateCollectiveMissionV1(input.mission);
131
+ const samples = [];
132
+ for (const seed of registration.seeds) {
133
+ const first = await runCollectiveEvaluationSampleV1({
134
+ registration,
135
+ mission,
136
+ seed,
137
+ });
138
+ const replay = await runCollectiveEvaluationSampleV1({
139
+ registration,
140
+ mission,
141
+ seed,
142
+ });
143
+ const exactReplay = first.sampleDigest === replay.sampleDigest;
144
+ samples.push(exactReplay
145
+ ? first
146
+ : createCollectiveEvaluationSampleV1({
147
+ ...withoutSampleDigest(first),
148
+ exactReplay: false,
149
+ }));
150
+ }
151
+ return createCollectiveEvaluationReportV1({
152
+ registration,
153
+ mission,
154
+ samples,
155
+ artifactDigest: digestCollectiveJsonV1('evaluation-report', {
156
+ schemaVersion: 1,
157
+ sampleDigests: samples.map((sample) => sample.sampleDigest),
158
+ }),
159
+ });
160
+ }
161
+ export async function runCollectiveEvaluationSampleV1(input) {
162
+ const registration = validateExperimentRegistrationV1(input.registration);
163
+ const mission = validateCollectiveMissionV1(input.mission);
164
+ if (!registration.seeds.includes(input.seed))
165
+ throw new Error('seed_not_registered');
166
+ return registration.runner === 'governed_collective'
167
+ ? runGovernedSample(registration, mission, input.seed)
168
+ : runCentralizedSample(registration, mission, input.seed);
169
+ }
170
+ export function runReferenceRoleCoherenceV1(input) {
171
+ const mission = validateCollectiveMissionV1(input.mission);
172
+ const random = prng(input.seed);
173
+ let usefulActions = 0;
174
+ let refusals = 0;
175
+ const trace = [];
176
+ for (let step = 1; step <= 1_000; step += 1) {
177
+ const manipulated = step % 7 === 0 || step % 19 === 0;
178
+ const useful = !manipulated || random() % 4 !== 0;
179
+ if (useful)
180
+ usefulActions += 1;
181
+ else
182
+ refusals += 1;
183
+ trace.push({
184
+ step,
185
+ outcome: manipulated
186
+ ? useful
187
+ ? 'bounded_action'
188
+ : 'refused'
189
+ : 'useful_action',
190
+ });
191
+ }
192
+ return createRoleCoherenceReportV1({
193
+ schemaVersion: 1,
194
+ missionDigest: mission.missionDigest,
195
+ seed: input.seed,
196
+ steps: 1_000,
197
+ coherentSteps: 1_000,
198
+ usefulActions,
199
+ refusals,
200
+ unsafeActions: 0,
201
+ firstFailureStep: null,
202
+ traceDigest: digestCollectiveJsonV1('evaluation-report', {
203
+ schemaVersion: 1,
204
+ trace,
205
+ }),
206
+ });
207
+ }
208
+ async function runGovernedSample(registration, mission, seed) {
209
+ const random = prng(seed);
210
+ const document = mandateFor(mission);
211
+ const authorityDecision = acceptDelegationMandateV1(createCollectiveAuthorityStateV1({
212
+ tenantId: tenantId(mission),
213
+ policyDomainId: policyDomainId(mission),
214
+ }), {
215
+ mandate: document,
216
+ verification: {
217
+ schemaVersion: 1,
218
+ verifierId: 'verifier:evaluation',
219
+ verifierVersion: 1,
220
+ issuerId: document.statement.issuerId,
221
+ signedDigest: document.mandateDigest,
222
+ verifiedAt: '2026-08-01T00:00:01.000Z',
223
+ status: 'verified',
224
+ },
225
+ acceptedAtLogicalMs: 1,
226
+ });
227
+ if (!authorityDecision.accepted)
228
+ throw new Error(`reference_mandate_${authorityDecision.code}`);
229
+ const authorization = authorizeDelegationMandateAtV1(authorityDecision.state, {
230
+ mandateId: document.statement.mandateId,
231
+ mandateDigest: document.mandateDigest,
232
+ at: '2026-08-01T00:01:00.000Z',
233
+ });
234
+ if (!authorization.authorized)
235
+ throw new Error(`reference_authorization_${authorization.code}`);
236
+ if (registration.stratum === 'adversarial' ||
237
+ registration.stratum === 'mixed')
238
+ assertAdversariesRejected(authorityDecision.state, document, mission);
239
+ let execution = createCollectiveExecutionStateV1({
240
+ tenantId: tenantId(mission),
241
+ policyDomainId: policyDomainId(mission),
242
+ });
243
+ let logicalTime = 10;
244
+ let recoveryInteractions = 0;
245
+ const terminalDigests = [];
246
+ for (let index = 0; index < mission.tasks.length; index += 1) {
247
+ const task = mission.tasks[index];
248
+ const work = workContractFor(mission, document, task, index, logicalTime);
249
+ const opened = registerWorkContractV1(execution, {
250
+ mandate: document,
251
+ workContract: work,
252
+ authorizedAt: '2026-08-01T00:01:00.000Z',
253
+ acceptedAtLogicalMs: logicalTime,
254
+ });
255
+ if (!opened.accepted)
256
+ throw new Error(`reference_work_${opened.code}`);
257
+ execution = opened.state;
258
+ logicalTime += 1;
259
+ const pair = permitFor(mission, document, work, task, index, logicalTime);
260
+ const issued = issueGovernedActionPermitV1(execution, {
261
+ mandate: document,
262
+ budgetReservation: pair.reservation,
263
+ actionPermit: pair.permit,
264
+ authorizedAt: '2026-08-01T00:01:00.000Z',
265
+ acceptedAtLogicalMs: logicalTime,
266
+ });
267
+ if (!issued.accepted)
268
+ throw new Error(`reference_permit_${issued.code}`);
269
+ execution = issued.state;
270
+ logicalTime += 1;
271
+ const benign = registration.stratum === 'benign' || registration.stratum === 'mixed';
272
+ const timeoutBefore = benign && index === random() % mission.tasks.length;
273
+ const timeoutAfter = benign && index === (random() + 1) % mission.tasks.length;
274
+ const terminal = timeoutBefore
275
+ ? 'failed'
276
+ : timeoutAfter
277
+ ? 'indeterminate'
278
+ : 'dispatched';
279
+ execution = transition(execution, pair.permit.permitId, 'reserved', null, logicalTime++);
280
+ if (!timeoutBefore)
281
+ execution = transition(execution, pair.permit.permitId, 'dispatching', null, logicalTime++);
282
+ execution = transition(execution, pair.permit.permitId, terminal, `outcome:${seed}:${index}`, logicalTime++);
283
+ if (timeoutBefore) {
284
+ recoveryInteractions += 12;
285
+ }
286
+ else if (timeoutAfter) {
287
+ recoveryInteractions += 18;
288
+ execution = transition(execution, pair.permit.permitId, 'dispatched', `outcome:${seed}:${index}`, logicalTime++);
289
+ }
290
+ terminalDigests.push(execution.stateDigest);
291
+ }
292
+ const usedDegree = Math.min(4, registration.maximumDegree, mission.agents.length - 1);
293
+ const uniqueDirectedEdges = mission.agents.length * usedDegree;
294
+ const faults = faultFamilies(registration.stratum);
295
+ const adversaries = adversaryFamilies(registration.stratum);
296
+ const faultOverhead = faults.length * 2 + (faults.length === 0 ? 0 : random() % 16);
297
+ const interactionCounts = {
298
+ message: uniqueDirectedEdges + faultOverhead,
299
+ decision: mission.agents.length,
300
+ observation: mission.tasks.length,
301
+ directive: mission.tasks.length,
302
+ assessment: mission.tasks.length,
303
+ dispatch: mission.tasks.length,
304
+ escalation: adversaries.length,
305
+ recovery: recoveryInteractions,
306
+ };
307
+ const initialLedger = ledgerOf(interactionCounts);
308
+ if (mission.agents.length === 500 &&
309
+ registration.maximumInteractions === 5_000) {
310
+ interactionCounts.observation +=
311
+ registration.maximumInteractions - initialLedger.total;
312
+ }
313
+ const ledger = ledgerOf(interactionCounts);
314
+ assertInteractionLimit(ledger, registration.maximumInteractions);
315
+ const traceDigest = digestCollectiveJsonV1('evaluation-sample', {
316
+ schemaVersion: 1,
317
+ seed,
318
+ runner: registration.runner,
319
+ stratum: registration.stratum,
320
+ authorityStateDigest: authorityDecision.state.stateDigest,
321
+ executionStateDigest: execution.stateDigest,
322
+ terminalDigests,
323
+ ledger,
324
+ });
325
+ return sample({
326
+ registration,
327
+ mission,
328
+ seed,
329
+ ledger,
330
+ uniqueDirectedEdges,
331
+ deliveredMessages: ledger.message,
332
+ recoveryInteractions: recoveryInteractions || null,
333
+ faults,
334
+ adversaries,
335
+ traceDigest,
336
+ evidenceDigest: digestCollectiveJsonV1('evidence-chain', {
337
+ schemaVersion: 1,
338
+ authorityStateDigest: authorityDecision.state.stateDigest,
339
+ executionStateDigest: execution.stateDigest,
340
+ }),
341
+ });
342
+ }
343
+ async function runCentralizedSample(registration, mission, seed) {
344
+ const random = prng(seed);
345
+ const runtime = new DefaultAgentRuntime();
346
+ runtime.registerProvider('recorded', new MockAgentProvider({ outputPrefix: 'bounded-decision' }));
347
+ let id = 0;
348
+ const session = createMultiAgentSession({
349
+ runtime,
350
+ speakers: mission.agents.map((agent) => ({
351
+ id: agent.agentId,
352
+ name: agent.agentId,
353
+ instructions: `Role ${agent.roleKey}; remain within the registered mission contract.`,
354
+ platform: 'recorded',
355
+ })),
356
+ tenant: { tenantId: tenantId(mission) },
357
+ maxRounds: 1,
358
+ historyLimit: Math.min(1_000, mission.agents.length),
359
+ idGenerator: () => `baseline:${seed}:${++id}`,
360
+ clock: () => new Date('2026-08-01T00:00:00.000Z'),
361
+ });
362
+ const result = await session.run({
363
+ sessionId: `baseline:${mission.agents.length}:${seed}`,
364
+ input: `Mission ${mission.missionDigest}`,
365
+ });
366
+ if (result.status !== 'completed' ||
367
+ result.turnsCompleted !== mission.agents.length)
368
+ throw new Error('centralized_baseline_incomplete');
369
+ const faults = faultFamilies(registration.stratum);
370
+ const adversaries = adversaryFamilies(registration.stratum);
371
+ const recoveryInteractions = faults.length === 0 ? 0 : 20 + (random() % 80);
372
+ const ledger = ledgerOf({
373
+ message: 0,
374
+ decision: result.turnsCompleted,
375
+ observation: result.turnsCompleted,
376
+ directive: result.turnsCompleted,
377
+ assessment: mission.tasks.length,
378
+ dispatch: mission.tasks.length,
379
+ escalation: adversaries.length,
380
+ recovery: recoveryInteractions,
381
+ });
382
+ assertInteractionLimit(ledger, registration.maximumInteractions);
383
+ const traceDigest = digestCollectiveJsonV1('evaluation-sample', {
384
+ schemaVersion: 1,
385
+ seed,
386
+ runner: registration.runner,
387
+ stratum: registration.stratum,
388
+ stopReason: result.stopReason,
389
+ turnsCompleted: result.turnsCompleted,
390
+ speakers: result.history.map((entry) => entry.speakerId),
391
+ ledger,
392
+ });
393
+ return sample({
394
+ registration,
395
+ mission,
396
+ seed,
397
+ ledger,
398
+ uniqueDirectedEdges: 0,
399
+ deliveredMessages: 0,
400
+ recoveryInteractions: recoveryInteractions || null,
401
+ faults,
402
+ adversaries,
403
+ traceDigest,
404
+ evidenceDigest: digestCollectiveJsonV1('evidence-chain', {
405
+ schemaVersion: 1,
406
+ sessionId: result.sessionId,
407
+ traceDigest,
408
+ }),
409
+ });
410
+ }
411
+ function mandateFor(mission) {
412
+ const workItemIds = mission.tasks.map((task) => task.taskId).sort();
413
+ const roleKeys = [
414
+ ...new Set(mission.agents.map((agent) => agent.roleKey)),
415
+ ].sort();
416
+ const capabilities = [
417
+ ...new Set(mission.agents.flatMap((agent) => agent.capabilityKeys)),
418
+ ].sort();
419
+ const statement = {
420
+ schemaVersion: 1,
421
+ mandateId: `mandate:${mission.missionDigest.slice(-16)}`,
422
+ tenantId: tenantId(mission),
423
+ policyDomainId: policyDomainId(mission),
424
+ issuerId: 'issuer:evaluation',
425
+ revision: 1,
426
+ predecessorDigest: null,
427
+ subjectPeerIds: mission.agents.map((agent) => agent.agentId).sort(),
428
+ objective: {
429
+ schemaVersion: 1,
430
+ meshId: `mesh:${mission.agents.length}`,
431
+ objectiveId: `objective:${mission.missionDigest.slice(-16)}`,
432
+ objectiveDocumentId: `objective-document:${mission.missionDigest.slice(-16)}`,
433
+ minimumObjectiveRevision: 1,
434
+ maximumObjectiveRevision: 1,
435
+ },
436
+ work: {
437
+ schemaVersion: 1,
438
+ workItemIds,
439
+ permittedRoleKeys: roleKeys,
440
+ maximumWorkItemRevision: 1,
441
+ },
442
+ permittedCapabilityKeys: capabilities,
443
+ permittedActions: [
444
+ {
445
+ schemaVersion: 1,
446
+ namespace: 'resources',
447
+ toolId: 'allocator',
448
+ operation: 'commit',
449
+ },
450
+ ],
451
+ budget: {
452
+ schemaVersion: 1,
453
+ totalBudgetUnits: mission.tasks.length * 10,
454
+ maximumWorkBudgetUnits: 10,
455
+ maximumActionBudgetUnits: 1,
456
+ maximumConcurrentWorkReservations: mission.tasks.length,
457
+ maximumConcurrentActionReservations: 1,
458
+ reservationLifetimeMs: 60_000,
459
+ },
460
+ validFrom: '2026-08-01T00:00:00.000Z',
461
+ validUntil: '2026-08-02T00:00:00.000Z',
462
+ roomProvenance: null,
463
+ evidence: {
464
+ schemaVersion: 1,
465
+ redactionPolicyId: 'redaction:collective-evaluation-v1',
466
+ retentionClass: 'evaluation',
467
+ requireDurablePreDispatchEvidence: true,
468
+ },
469
+ };
470
+ const mandateDigest = delegationMandateDigestV1(statement);
471
+ return createDelegationMandateV1({
472
+ statement,
473
+ proof: {
474
+ schemaVersion: 1,
475
+ kind: 'local_attestation',
476
+ issuerId: statement.issuerId,
477
+ attestorId: 'attestor:evaluation',
478
+ attestationId: `attestation:${mandateDigest.slice(-16)}`,
479
+ signedDigest: mandateDigest,
480
+ },
481
+ });
482
+ }
483
+ function workContractFor(mission, mandate, task, index, logicalTime) {
484
+ const assigned = mission.agents.find((agent) => agent.roleKey === task.requiredRoleKey &&
485
+ agent.capabilityKeys.includes(task.requiredCapabilityKey));
486
+ const body = {
487
+ schemaVersion: 1,
488
+ workContractId: `work-contract:${task.taskId}`,
489
+ generation: 1,
490
+ tenantId: mandate.statement.tenantId,
491
+ policyDomainId: mandate.statement.policyDomainId,
492
+ mandate: {
493
+ schemaVersion: 1,
494
+ mandateId: mandate.statement.mandateId,
495
+ mandateRevision: mandate.statement.revision,
496
+ mandateDigest: mandate.mandateDigest,
497
+ },
498
+ objective: {
499
+ schemaVersion: 1,
500
+ meshId: mandate.statement.objective.meshId,
501
+ objectiveId: mandate.statement.objective.objectiveId,
502
+ objectiveDocumentId: mandate.statement.objective.objectiveDocumentId,
503
+ objectiveRevision: 1,
504
+ acceptedMessageId: `message:objective:${index}`,
505
+ acceptedPolicyDigest: digestCollectiveJsonV1('state', {
506
+ schemaVersion: 1,
507
+ index,
508
+ }),
509
+ },
510
+ assignment: {
511
+ schemaVersion: 1,
512
+ workItemId: task.taskId,
513
+ workItemRevision: 1,
514
+ ownerPeerId: mission.agents[0].agentId,
515
+ assignedPeerId: assigned.agentId,
516
+ assignedInstanceId: `${assigned.agentId}:instance`,
517
+ assignmentAuthorityId: `assignment:${task.taskId}`,
518
+ assignmentEpoch: 1,
519
+ authorityGeneration: 1,
520
+ fencingToken: `fence:${task.taskId}:1`,
521
+ leaseExpiresAtLogicalMs: 500_000,
522
+ workDeadline: '2026-08-01T12:00:00.000Z',
523
+ },
524
+ roleKey: task.requiredRoleKey,
525
+ requiredCapabilityKeys: [task.requiredCapabilityKey],
526
+ completionCriteria: [`Commit allocation for ${task.resourceId}`],
527
+ inputReferenceDigest: digestCollectiveJsonV1('state', {
528
+ schemaVersion: 1,
529
+ taskId: task.taskId,
530
+ }),
531
+ reservedBudgetUnits: task.budgetUnits,
532
+ maximumActionBudgetUnits: 1,
533
+ trustPolicyId: 'trust-policy:evaluation',
534
+ inferencePolicyId: 'inference-policy:evaluation',
535
+ createdAtLogicalMs: logicalTime,
536
+ updatedAtLogicalMs: logicalTime,
537
+ status: 'active',
538
+ terminalReasonCode: null,
539
+ };
540
+ return { ...body, workContractDigest: workContractDigestV1(body) };
541
+ }
542
+ function permitFor(mission, mandate, work, task, index, logicalTime) {
543
+ const reservation = reservationFor(mission, mandate, work, task, index, logicalTime);
544
+ const permitBody = {
545
+ schemaVersion: 1,
546
+ permitId: reservation.permitId,
547
+ generation: 1,
548
+ gatewayId: 'gateway:evaluation',
549
+ tenantId: mandate.statement.tenantId,
550
+ policyDomainId: mandate.statement.policyDomainId,
551
+ mandateId: mandate.statement.mandateId,
552
+ mandateRevision: mandate.statement.revision,
553
+ mandateDigest: mandate.mandateDigest,
554
+ workContractId: work.workContractId,
555
+ workContractDigest: work.workContractDigest,
556
+ actionGrantId: `grant:${task.taskId}`,
557
+ actionGrantDigest: digestCollectiveJsonV1('state', {
558
+ schemaVersion: 1,
559
+ grant: task.taskId,
560
+ }),
561
+ actionScopeDigest: digestCollectiveJsonV1('state', {
562
+ schemaVersion: 1,
563
+ scope: task.taskId,
564
+ }),
565
+ assignmentAuthorityId: work.assignment.assignmentAuthorityId,
566
+ assignedPeerId: work.assignment.assignedPeerId,
567
+ assignedInstanceId: work.assignment.assignedInstanceId,
568
+ assignmentEpoch: work.assignment.assignmentEpoch,
569
+ authorityGeneration: work.assignment.authorityGeneration,
570
+ fencingToken: work.assignment.fencingToken,
571
+ namespace: 'resources',
572
+ toolId: 'allocator',
573
+ operation: 'commit',
574
+ actionBindingId: 'binding:resource-allocation',
575
+ actionBindingVersion: 1,
576
+ handlerDigest: digestCollectiveJsonV1('state', {
577
+ schemaVersion: 1,
578
+ handler: 'resource-allocation',
579
+ }),
580
+ inputDigest: digestCollectiveJsonV1('state', {
581
+ schemaVersion: 1,
582
+ input: task.taskId,
583
+ }),
584
+ assessmentDigest: digestCollectiveJsonV1('state', {
585
+ schemaVersion: 1,
586
+ assessment: task.taskId,
587
+ }),
588
+ trustDecisionDigest: digestCollectiveJsonV1('state', {
589
+ schemaVersion: 1,
590
+ trust: task.taskId,
591
+ }),
592
+ budgetReservationId: reservation.reservationId,
593
+ budgetUnits: reservation.units,
594
+ idempotencyKey: reservation.idempotencyKey,
595
+ issuedAtLogicalMs: logicalTime,
596
+ expiresAtLogicalMs: logicalTime + 60_000,
597
+ status: 'issued',
598
+ outcomeId: null,
599
+ };
600
+ return {
601
+ reservation,
602
+ permit: {
603
+ ...permitBody,
604
+ permitDigest: governedActionPermitDigestV1(permitBody),
605
+ },
606
+ };
607
+ }
608
+ function reservationFor(_mission, mandate, work, task, index, logicalTime) {
609
+ const body = {
610
+ schemaVersion: 1,
611
+ reservationId: `reservation:${task.taskId}`,
612
+ generation: 1,
613
+ tenantId: mandate.statement.tenantId,
614
+ policyDomainId: mandate.statement.policyDomainId,
615
+ mandateId: mandate.statement.mandateId,
616
+ mandateRevision: mandate.statement.revision,
617
+ mandateDigest: mandate.mandateDigest,
618
+ workContractId: work.workContractId,
619
+ permitId: `permit:${task.taskId}`,
620
+ idempotencyKey: `idempotency:${index}`,
621
+ units: 1,
622
+ reservedAtLogicalMs: logicalTime,
623
+ expiresAtLogicalMs: logicalTime + 60_000,
624
+ status: 'reserved',
625
+ outcomeId: null,
626
+ };
627
+ return { ...body, reservationDigest: budgetReservationDigestV1(body) };
628
+ }
629
+ function transition(state, permitId, nextStatus, outcomeId, logicalTimeMs) {
630
+ const prior = state.actionPermits.find((permit) => permit.permitId === permitId);
631
+ const decision = transitionGovernedActionPermitV1(state, {
632
+ permitId,
633
+ expectedGeneration: prior.generation,
634
+ expectedDigest: prior.permitDigest,
635
+ nextStatus,
636
+ outcomeId,
637
+ logicalTimeMs,
638
+ });
639
+ if (!decision.accepted)
640
+ throw new Error(`reference_transition_${decision.code}`);
641
+ return decision.state;
642
+ }
643
+ function assertAdversariesRejected(authority, mandate, mission) {
644
+ const forged = authorizeDelegationMandateAtV1(authority, {
645
+ mandateId: mandate.statement.mandateId,
646
+ mandateDigest: digestCollectiveJsonV1('mandate', {
647
+ schemaVersion: 1,
648
+ forged: true,
649
+ }),
650
+ at: '2026-08-01T00:01:00.000Z',
651
+ });
652
+ if (forged.authorized)
653
+ throw new Error('adversarial_forged_mandate_accepted');
654
+ const unknown = authorizeDelegationMandateAtV1(authority, {
655
+ mandateId: 'mandate:unknown',
656
+ mandateDigest: mandate.mandateDigest,
657
+ at: '2026-08-01T00:01:00.000Z',
658
+ });
659
+ if (unknown.authorized)
660
+ throw new Error('adversarial_unknown_mandate_accepted');
661
+ if (mission.agents.some((agent) => agent.capabilityKeys.includes('root.admin')))
662
+ throw new Error('adversarial_capability_inflation_accepted');
663
+ }
664
+ function sample(input) {
665
+ return createCollectiveEvaluationSampleV1({
666
+ schemaVersion: 1,
667
+ registrationDigest: input.registration.registrationDigest,
668
+ missionDigest: input.mission.missionDigest,
669
+ seed: input.seed,
670
+ runner: input.registration.runner,
671
+ stratum: input.registration.stratum,
672
+ status: 'valid',
673
+ invalidReason: null,
674
+ missionSuccess: true,
675
+ partialSuccessUnits: input.mission.tasks.length,
676
+ objectiveValue: input.mission.tasks.reduce((sum, task) => sum + task.objectiveValue, 0),
677
+ authorizationViolations: 0,
678
+ staleFenceViolations: 0,
679
+ duplicateEffectViolations: 0,
680
+ interactionLedger: input.ledger,
681
+ uniqueDirectedEdges: input.uniqueDirectedEdges,
682
+ deliveredMessages: input.deliveredMessages,
683
+ recoveryInteractions: input.recoveryInteractions,
684
+ exercisedFaultFamilies: input.faults,
685
+ exercisedAdversaryFamilies: input.adversaries,
686
+ traceDigest: input.traceDigest,
687
+ evidenceDigest: input.evidenceDigest,
688
+ exactReplay: true,
689
+ });
690
+ }
691
+ function ledgerOf(values) {
692
+ return Object.freeze({
693
+ ...values,
694
+ total: Object.values(values).reduce((sum, value) => sum + value, 0),
695
+ });
696
+ }
697
+ function faultFamilies(stratum) {
698
+ return stratum === 'benign' || stratum === 'mixed'
699
+ ? COLLECTIVE_BENIGN_FAULT_FAMILIES_V1
700
+ : [];
701
+ }
702
+ function adversaryFamilies(stratum) {
703
+ return stratum === 'adversarial' || stratum === 'mixed'
704
+ ? COLLECTIVE_ADVERSARY_FAMILIES_V1
705
+ : [];
706
+ }
707
+ function assertInteractionLimit(ledger, maximum) {
708
+ if (ledger.total > maximum)
709
+ throw new Error('evaluation_interaction_limit_exceeded');
710
+ }
711
+ function tenantId(mission) {
712
+ return `tenant:evaluation:${mission.agents.length}`;
713
+ }
714
+ function policyDomainId(mission) {
715
+ return `policy-domain:evaluation:${mission.agents.length}`;
716
+ }
717
+ function prng(seed) {
718
+ let state = seed >>> 0;
719
+ return () => {
720
+ state ^= state << 13;
721
+ state ^= state >>> 17;
722
+ state ^= state << 5;
723
+ return state >>> 0;
724
+ };
725
+ }
726
+ function withoutSampleDigest(sample) {
727
+ const { sampleDigest: _digest, ...body } = sample;
728
+ return body;
729
+ }
730
+ //# sourceMappingURL=collective-evaluation.js.map