@seriousgaming/sdk-tools 1.11.0 → 1.12.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 (192) hide show
  1. package/dist/agent/guidance.md +4 -0
  2. package/dist/{cli-F2D4GGUA.js → cli-2BKEIIA3.js} +66 -0
  3. package/dist/{cli-ZGCG6C22.js → cli-2QGTDHRX.js} +21 -21
  4. package/dist/{cli-SRXDLMXY.js → cli-2SDG3SZ7.js} +21 -21
  5. package/dist/{cli-DH35TZ2Q.js → cli-2VXP34R5.js} +2 -2
  6. package/dist/{cli-P3NUTOPK.js → cli-2W4B6PD5.js} +1 -1
  7. package/dist/{cli-WJVPSVF2.js → cli-2X7DKSXN.js} +24 -24
  8. package/dist/{cli-ATAJSIXH.js → cli-2ZP4N7HK.js} +19 -19
  9. package/dist/{cli-5O7XENQY.js → cli-3GJYZH4C.js} +5 -5
  10. package/dist/{cli-H6PP2MZT.js → cli-3GO3M2MX.js} +17 -13
  11. package/dist/{cli-HMDYG6PS.js → cli-3LDLUNME.js} +17 -17
  12. package/dist/{cli-BZOKZ7LP.js → cli-3WY6L2WP.js} +27 -27
  13. package/dist/{cli-REAM7LSC.js → cli-44MBABRD.js} +25 -25
  14. package/dist/{cli-5TTJWM2R.js → cli-4IO7MKLR.js} +20 -20
  15. package/dist/{cli-HNDFANQG.js → cli-4U2PY7W3.js} +1 -1
  16. package/dist/{cli-WQ7JBZNW.js → cli-4WI4LTBI.js} +2 -2
  17. package/dist/{cli-OTBCA54D.js → cli-55EIGGZK.js} +1 -1
  18. package/dist/{cli-FYPW25VD.js → cli-5AQV6FTL.js} +18 -18
  19. package/dist/{cli-RKPQLB7J.js → cli-5CW7BEU7.js} +3 -3
  20. package/dist/{cli-27TQVLVF.js → cli-5JUVHNZF.js} +12 -12
  21. package/dist/{cli-F3YJKP6D.js → cli-5KERL6HV.js} +9 -4
  22. package/dist/{cli-MSNSXVGF.js → cli-5KSA24NQ.js} +24 -24
  23. package/dist/{cli-5VZBFMCK.js → cli-5PIFO3EN.js} +8 -0
  24. package/dist/{cli-FT3X3D4P.js → cli-5QN2Z43X.js} +20 -20
  25. package/dist/cli-5XSPAA5X.js +69 -0
  26. package/dist/{cli-B2QAJ5RQ.js → cli-62KAYGXO.js} +20 -20
  27. package/dist/{cli-QPV3TYOM.js → cli-6IMV5ZZU.js} +26 -26
  28. package/dist/{cli-UULZSQBV.js → cli-6KWCIAN2.js} +764 -66
  29. package/dist/{cli-DQE7ITIR.js → cli-6NWETIX5.js} +20 -20
  30. package/dist/{cli-L7F4XKCB.js → cli-774W3MN5.js} +26 -26
  31. package/dist/cli-7BUD3VAD.js +16 -0
  32. package/dist/{cli-XNOAO6DY.js → cli-7KEP57S7.js} +12 -12
  33. package/dist/{cli-5UKWX3IU.js → cli-7OYFJMA6.js} +18 -18
  34. package/dist/{cli-WNHMJM3Z.js → cli-7ZNEDQ3G.js} +20 -20
  35. package/dist/{cli-5RRPUL6V.js → cli-AFK6OUID.js} +12 -12
  36. package/dist/{cli-6P6V2EHY.js → cli-AIYQFWXN.js} +25 -25
  37. package/dist/{cli-ERJNDBDH.js → cli-ARAAEWIQ.js} +2 -2
  38. package/dist/cli-AVQYV3N4.js +36 -0
  39. package/dist/{cli-TI2FOFPA.js → cli-B54Z6CXH.js} +16 -16
  40. package/dist/{cli-EEO5ZPAZ.js → cli-B5TC4MEL.js} +5 -5
  41. package/dist/{cli-5Z4D3F6Y.js → cli-BCXGOLU3.js} +3 -3
  42. package/dist/{cli-G2GLW5Z4.js → cli-BHAODVTZ.js} +1 -1
  43. package/dist/{cli-4F24FUW6.js → cli-BPS2JG74.js} +20 -20
  44. package/dist/{cli-W3RG2MRI.js → cli-BVO55SR2.js} +2 -2
  45. package/dist/{cli-R5SNTPND.js → cli-CFH3JZP5.js} +21 -21
  46. package/dist/{cli-Q7QSWNY2.js → cli-CTK2OIK6.js} +20 -20
  47. package/dist/{cli-ATWJCB2G.js → cli-CW5MV4VX.js} +4 -4
  48. package/dist/{cli-TCQJL2GY.js → cli-D5VOSJZ7.js} +1 -1
  49. package/dist/{cli-KIZTASLL.js → cli-DAEPMK7A.js} +5 -5
  50. package/dist/{cli-44CM2AH2.js → cli-DAHR7PKB.js} +1 -1
  51. package/dist/{cli-XW3JLRSA.js → cli-DWDSBTYL.js} +1 -1
  52. package/dist/cli-DYSDPGXW.js +95 -0
  53. package/dist/{cli-QEFYDXMH.js → cli-DZCLRZXJ.js} +1 -1
  54. package/dist/{cli-77T4LJQF.js → cli-EJ47IE45.js} +24 -24
  55. package/dist/{cli-QDBYFITU.js → cli-EK4OSJHA.js} +2 -2
  56. package/dist/{cli-GO64NABP.js → cli-FCJHNXDA.js} +1 -1
  57. package/dist/{cli-ZNQBF4Z3.js → cli-FNESSE3L.js} +1 -1
  58. package/dist/{cli-D3S7NJZ3.js → cli-FTLH4WCE.js} +17 -17
  59. package/dist/{cli-JHLWBRXB.js → cli-FYV77YS2.js} +18 -18
  60. package/dist/cli-GMJX6Q4Q.js +36 -0
  61. package/dist/{cli-7JUNA74L.js → cli-GRBVNGDW.js} +1 -1
  62. package/dist/{cli-XKAIDYIE.js → cli-HAFCFY77.js} +33 -19
  63. package/dist/{cli-OXLOGXT3.js → cli-HCJLYI24.js} +3 -3
  64. package/dist/{cli-XOYUTNER.js → cli-HCXS5EXU.js} +25 -25
  65. package/dist/cli-HEUNNHDH.js +36 -0
  66. package/dist/{cli-G3TU6CP6.js → cli-HNUTIWDZ.js} +19 -19
  67. package/dist/{cli-JXQLHJO2.js → cli-HXT25ETJ.js} +244 -243
  68. package/dist/{cli-5EH4WTH4.js → cli-IGEL7UJQ.js} +5 -5
  69. package/dist/{cli-TLSTSZAC.js → cli-IO32YA5N.js} +26 -26
  70. package/dist/cli-IPTGZDBB.js +36 -0
  71. package/dist/{cli-OBLEROSC.js → cli-J25TYFKB.js} +19 -19
  72. package/dist/{cli-5ATO27Z4.js → cli-J7XYMEMX.js} +20 -20
  73. package/dist/{cli-X3TSTTYI.js → cli-JC5OJRID.js} +2 -2
  74. package/dist/{cli-25SJZI7N.js → cli-JD563OF4.js} +126 -27
  75. package/dist/{cli-VXLHOZSO.js → cli-JRJF2WHU.js} +20 -20
  76. package/dist/{cli-UQC46YSV.js → cli-JTFLIMIG.js} +3 -3
  77. package/dist/{cli-K4HSQWXC.js → cli-K2BSJ2PK.js} +2 -2
  78. package/dist/{cli-OM32UURE.js → cli-K4QTYMN2.js} +25 -25
  79. package/dist/{cli-BJFYGVJV.js → cli-KFJDD4C4.js} +20 -20
  80. package/dist/{cli-WW54THXN.js → cli-KVQ2JPVD.js} +1 -1
  81. package/dist/{cli-LHMRUJVN.js → cli-L6AHMW2Z.js} +1 -1
  82. package/dist/{cli-IKSLPAZN.js → cli-LCYUBCVY.js} +4 -4
  83. package/dist/{cli-HGCOEL5T.js → cli-LEWSCDH5.js} +4 -4
  84. package/dist/{cli-XJ7JESC2.js → cli-LI6G7GND.js} +27 -27
  85. package/dist/{cli-OMTHTWYJ.js → cli-LU2GCWIU.js} +21 -21
  86. package/dist/{cli-UEQMK4WX.js → cli-M3Z2KOEB.js} +1 -1
  87. package/dist/{cli-226ZJ72R.js → cli-M6E3E3I2.js} +170 -3
  88. package/dist/{cli-NKKCDO6K.js → cli-MCRPA4Z6.js} +20 -20
  89. package/dist/{cli-BQ36DV5C.js → cli-MI2DEDMA.js} +3 -3
  90. package/dist/{cli-6O7YCK2M.js → cli-MITZ6SE7.js} +3 -3
  91. package/dist/{cli-LPFSJ625.js → cli-MTIYD3BX.js} +26 -26
  92. package/dist/{cli-5M6KDNVX.js → cli-MTZUJGBK.js} +2 -2
  93. package/dist/{cli-GSOV26O5.js → cli-NCLMUXLC.js} +14 -14
  94. package/dist/{cli-X52TXCNF.js → cli-NLS3DKWH.js} +26 -26
  95. package/dist/{cli-AH6AMAIB.js → cli-NMDGS7IE.js} +1 -1
  96. package/dist/cli-O3DJO2CS.js +30 -0
  97. package/dist/{cli-BC67QHD5.js → cli-O47D5BFN.js} +2 -2
  98. package/dist/{cli-MDVC5ZNM.js → cli-OBRZ36VP.js} +14 -14
  99. package/dist/{cli-UVIURDZC.js → cli-OMG4E53H.js} +20 -20
  100. package/dist/{cli-C32Q5E5I.js → cli-P6V3NSU4.js} +1 -1
  101. package/dist/{cli-RMD5WSUQ.js → cli-PAMQMTHK.js} +21 -21
  102. package/dist/{cli-WNBP3LOD.js → cli-PKTHOCT3.js} +26 -26
  103. package/dist/{cli-S3NHXAJM.js → cli-QK7QAP5H.js} +18 -18
  104. package/dist/cli-QQ432JEN.js +36 -0
  105. package/dist/{cli-YYXAGJQR.js → cli-QVNDPTBU.js} +20 -20
  106. package/dist/{cli-KJA6GLZI.js → cli-R2DFD6ZZ.js} +15 -15
  107. package/dist/{cli-6BLVI2JM.js → cli-RMVJMOWU.js} +111 -7
  108. package/dist/{cli-TEBV2OIW.js → cli-RQISHMJF.js} +83 -21
  109. package/dist/{cli-X64BNBQH.js → cli-RVZH462G.js} +585 -8
  110. package/dist/{cli-6AMK3DYS.js → cli-SEEOQVUL.js} +12 -12
  111. package/dist/{cli-QTCTWYCM.js → cli-SO354HPI.js} +3 -3
  112. package/dist/{cli-RHL4B4H7.js → cli-T76HDH7F.js} +88 -4
  113. package/dist/{cli-ZJW6HQ6N.js → cli-TIS7DWRR.js} +7 -7
  114. package/dist/{cli-6JWDFCUV.js → cli-TY3B6XS7.js} +21 -21
  115. package/dist/{cli-4FJL3KQZ.js → cli-UKEZJFIT.js} +2 -2
  116. package/dist/cli-VQAMW4RF.js +95 -0
  117. package/dist/{cli-ATHATKI5.js → cli-W4LMRVZT.js} +78 -47
  118. package/dist/cli-W7I5KGIB.js +84 -0
  119. package/dist/{cli-B3EFE7ZF.js → cli-WXGJFA4F.js} +1 -1
  120. package/dist/{cli-PNS4KWWC.js → cli-XCG33I77.js} +24 -24
  121. package/dist/{cli-DBMEH4Y5.js → cli-YHLSG5HB.js} +26 -26
  122. package/dist/cli-YNH5DTHY.js +36 -0
  123. package/dist/cli-YPMJWPDA.js +69 -0
  124. package/dist/{cli-PXQYY6KM.js → cli-YSXIR7EM.js} +0 -0
  125. package/dist/cli-ZPFWO4VW.js +85 -0
  126. package/dist/cli.js +53 -53
  127. package/dist/client.js +1918 -283
  128. package/dist/core/assessment-moves.d.ts +32 -0
  129. package/dist/core/assessment-reports.d.ts +38 -0
  130. package/dist/core/assessment-settings.d.ts +15 -0
  131. package/dist/core/benchmark-samples.d.ts +28 -0
  132. package/dist/core/session-host.d.ts +4 -0
  133. package/dist/core/session-roster.d.ts +6 -0
  134. package/dist/core/session-timers.d.ts +40 -0
  135. package/dist/core/session.d.ts +14 -1
  136. package/dist/core/tick-timer.d.ts +18 -0
  137. package/dist/dev/console/assets/{index-Ch6HHb2T.js → index-zd--5H1f.js} +26 -26
  138. package/dist/dev/console/index.html +1 -1
  139. package/dist/dev/shell.d.ts +8 -0
  140. package/dist/dev/view/commands.d.ts +3 -1
  141. package/dist/docs/api/index.md +1 -1
  142. package/dist/docs/api/sdk-commands.md +29 -0
  143. package/dist/docs/api/sdk-e2e.md +30 -0
  144. package/dist/docs/api/sdk-projection.md +5 -0
  145. package/dist/docs/api/sdk-tools-client.md +30 -0
  146. package/dist/docs/api/sdk-ui.md +7 -0
  147. package/dist/docs/api/sdk.md +834 -19
  148. package/dist/docs/changelog.md +28 -0
  149. package/dist/docs/cli-error-codes.md +5 -1
  150. package/dist/docs/cli-reference.md +76 -2
  151. package/dist/docs/concepts/index.md +2 -0
  152. package/dist/docs/concepts/terminology.md +12 -0
  153. package/dist/docs/guides/assessments.md +248 -0
  154. package/dist/docs/guides/benchmarks.md +241 -0
  155. package/dist/docs/guides/engine.md +8 -0
  156. package/dist/docs/guides/index.md +2 -0
  157. package/dist/docs/guides/presentation.md +11 -9
  158. package/dist/docs/guides/session-hooks.md +24 -22
  159. package/dist/docs/guides/tick-controller.md +22 -1
  160. package/dist/docs/guides/ui.md +24 -0
  161. package/dist/docs/guides/upgrading.md +21 -0
  162. package/dist/docs/page-index.md +16 -12
  163. package/dist/docs/recipes/create-assessment.md +124 -0
  164. package/dist/docs/recipes/create-benchmark.md +115 -0
  165. package/dist/docs/recipes/index.md +2 -0
  166. package/dist/execution/context-composition.d.ts +39 -4
  167. package/dist/execution/engine-state.d.ts +13 -0
  168. package/dist/execution/executor.d.ts +16 -0
  169. package/dist/execution/logic-result.d.ts +13 -2
  170. package/dist/help-examples.d.ts +12 -0
  171. package/dist/host/adapter.d.ts +24 -1
  172. package/dist/host/protocol.d.ts +115 -1
  173. package/dist/host.js +29 -1
  174. package/dist/playwright.js +1912 -277
  175. package/dist/runtime/index.d.ts +3 -1
  176. package/dist/runtime/manifest-version.d.ts +1 -1
  177. package/dist/runtime.js +298 -16
  178. package/dist/schema.json +189 -0
  179. package/dist/templating/resource-metadata.d.ts +1 -1
  180. package/dist/utils/error-codes.d.ts +9 -1
  181. package/dist/validation/assessment-validation.d.ts +34 -0
  182. package/dist/validation/benchmark-validation.d.ts +20 -0
  183. package/dist/validation/schema-validation.d.ts +4 -0
  184. package/package.json +3 -3
  185. package/dist/cli-27Z5T52R.js +0 -30
  186. package/dist/cli-3VLBFWHN.js +0 -36
  187. package/dist/cli-BINVO5R7.js +0 -36
  188. package/dist/cli-HLI5UEKX.js +0 -36
  189. package/dist/cli-OF36EA62.js +0 -36
  190. package/dist/cli-OVIJRBFI.js +0 -36
  191. package/dist/cli-UIYKPSIY.js +0 -36
  192. package/dist/cli-WZNIW6ZO.js +0 -16
@@ -46,7 +46,7 @@ var require_extend = __commonJS({
46
46
  }
47
47
  return toStr.call(arr) === "[object Array]";
48
48
  };
49
- var isPlainObject3 = function isPlainObject4(obj) {
49
+ var isPlainObject4 = function isPlainObject5(obj) {
50
50
  if (!obj || toStr.call(obj) !== "[object Object]") {
51
51
  return false;
52
52
  }
@@ -103,12 +103,12 @@ var require_extend = __commonJS({
103
103
  src = getProperty(target, name);
104
104
  copy = getProperty(options, name);
105
105
  if (target !== copy) {
106
- if (deep && copy && (isPlainObject3(copy) || (copyIsArray = isArray(copy)))) {
106
+ if (deep && copy && (isPlainObject4(copy) || (copyIsArray = isArray(copy)))) {
107
107
  if (copyIsArray) {
108
108
  copyIsArray = false;
109
109
  clone = src && isArray(src) ? src : [];
110
110
  } else {
111
- clone = src && isPlainObject3(src) ? src : {};
111
+ clone = src && isPlainObject4(src) ? src : {};
112
112
  }
113
113
  setProperty(target, { name, newValue: extend2(deep, clone, copy) });
114
114
  } else if (typeof copy !== "undefined") {
@@ -155,6 +155,39 @@ var BASES = [
155
155
  mergeDefinition: true,
156
156
  referencedByReadsWrites: true
157
157
  },
158
+ {
159
+ type: "benchmark",
160
+ pluralDir: "benchmarks",
161
+ bundleFile: "benchmark.sdk.json",
162
+ manifestKey: "benchmarks",
163
+ kind: "composition",
164
+ label: "Benchmark",
165
+ // Only the engine writes benchmarks, so it is the one referrer: a
166
+ // benchmark anywhere else would let a participant or a facilitator
167
+ // move the figures every other session is compared with.
168
+ sites: [
169
+ {
170
+ referrerKeys: ["engine"],
171
+ shape: { kind: "stringArray", path: "benchmarks", labelSuffix: "benchmarks" }
172
+ }
173
+ ]
174
+ },
175
+ {
176
+ type: "assessment",
177
+ pluralDir: "assessments",
178
+ bundleFile: "assessment.sdk.json",
179
+ manifestKey: "assessments",
180
+ kind: "composition",
181
+ label: "Assessment",
182
+ // Only the engine scores, so it is the one referrer: a score written
183
+ // anywhere else could be a participant marking their own work.
184
+ sites: [
185
+ {
186
+ referrerKeys: ["engine"],
187
+ shape: { kind: "stringArray", path: "assessments", labelSuffix: "assessments" }
188
+ }
189
+ ]
190
+ },
158
191
  {
159
192
  type: "engine",
160
193
  slot: "engine",
@@ -545,6 +578,14 @@ var ERROR_CODES = {
545
578
  category: "package",
546
579
  description: "The package uses an optional feature its manifest's `requires` does not list, so a runtime without the feature would run it with part of it missing."
547
580
  },
581
+ BENCHMARK_UNWRITTEN: {
582
+ category: "package",
583
+ description: "A benchmark is not in the engine's `benchmarks`, so nothing writes it and it never holds a value. A warning."
584
+ },
585
+ ASSESSMENT_UNWRITTEN: {
586
+ category: "package",
587
+ description: "An assessment is not in the engine's `assessments`, so nothing scores it and it never holds a result. A warning."
588
+ },
548
589
  REFERENCE_UNKNOWN: {
549
590
  category: "package",
550
591
  description: "A `reads`, `writes`, `settings`, `configures` or `endpoints` entry names something the package does not declare."
@@ -960,6 +1001,352 @@ import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
960
1001
  import { readFile, readdir } from "fs/promises";
961
1002
  import { basename, dirname, join as join3, relative as relative2, sep as sep2 } from "path";
962
1003
 
1004
+ // ../sdk/lib/build/callbacks.js
1005
+ var UndeclaredApiUseError = class extends Error {
1006
+ resourceIdentifier;
1007
+ api;
1008
+ constructor(resourceIdentifier, api) {
1009
+ super(`Resource "${resourceIdentifier}" attempted to call callback "${api}" but did not declare it in its bundle's "uses" array. Add "${api}" to the bundle's uses to allow this call.`);
1010
+ this.name = "UndeclaredApiUseError";
1011
+ this.resourceIdentifier = resourceIdentifier;
1012
+ this.api = api;
1013
+ }
1014
+ };
1015
+
1016
+ // ../sdk/lib/build/tick-validation.js
1017
+ var MAX_EFFECTIVE_TICK_INTERVAL_MS = 7 * 24 * 60 * 60 * 1e3;
1018
+
1019
+ // ../sdk/lib/build/setting-path.js
1020
+ var NOT_PLAIN = /[.[\]"\s]/u;
1021
+ function isPlainKey(key) {
1022
+ return key !== "" && !NOT_PLAIN.test(key);
1023
+ }
1024
+ function settingPath(identifier, ...keys) {
1025
+ let path3 = isPlainKey(identifier) ? identifier : `[${JSON.stringify(identifier)}]`;
1026
+ for (const key of keys) {
1027
+ const step = String(key);
1028
+ path3 += isPlainKey(step) ? `.${step}` : `[${JSON.stringify(step)}]`;
1029
+ }
1030
+ return path3;
1031
+ }
1032
+ function parseSettingPath(path3) {
1033
+ const steps = [];
1034
+ let at = 0;
1035
+ while (at < path3.length) {
1036
+ if (path3[at] === "[") {
1037
+ const end2 = closingQuote(path3, at + 1);
1038
+ if (end2 === void 0 || path3[end2 + 1] !== "]")
1039
+ return void 0;
1040
+ let key2;
1041
+ try {
1042
+ key2 = JSON.parse(path3.slice(at + 1, end2 + 1));
1043
+ } catch {
1044
+ return void 0;
1045
+ }
1046
+ if (typeof key2 !== "string")
1047
+ return void 0;
1048
+ steps.push(key2);
1049
+ at = end2 + 2;
1050
+ continue;
1051
+ }
1052
+ if (steps.length > 0) {
1053
+ if (path3[at] !== ".")
1054
+ return void 0;
1055
+ at += 1;
1056
+ }
1057
+ let end = at;
1058
+ while (end < path3.length && path3[end] !== "." && path3[end] !== "[")
1059
+ end += 1;
1060
+ const key = path3.slice(at, end);
1061
+ if (!isPlainKey(key))
1062
+ return void 0;
1063
+ steps.push(key);
1064
+ at = end;
1065
+ }
1066
+ const [identifier, ...keys] = steps;
1067
+ return identifier === void 0 ? void 0 : { identifier, keys };
1068
+ }
1069
+ function closingQuote(path3, start) {
1070
+ if (path3[start] !== '"')
1071
+ return void 0;
1072
+ for (let at = start + 1; at < path3.length; at += 1) {
1073
+ if (path3[at] === "\\")
1074
+ at += 1;
1075
+ else if (path3[at] === '"')
1076
+ return at;
1077
+ }
1078
+ return void 0;
1079
+ }
1080
+
1081
+ // ../sdk/lib/build/validators.js
1082
+ var SCENARIO_GATE_READ_LIMIT_BYTES = 10 * 1024 * 1024;
1083
+ var ScenarioAssetTooLargeError = class _ScenarioAssetTooLargeError extends Error {
1084
+ /** The reference the gate asked to read. */
1085
+ reference;
1086
+ /** The file's size in bytes. */
1087
+ size;
1088
+ /** The cap it exceeds: {@link SCENARIO_GATE_READ_LIMIT_BYTES}. */
1089
+ limit;
1090
+ constructor(reference, size) {
1091
+ super(`Cannot read "${reference}" in a Scenario gate: it is ${size} bytes, over the ${SCENARIO_GATE_READ_LIMIT_BYTES}-byte (10 MB) limit on a gate's reads. Call describeAsset to check that it is there or how large it is.`);
1092
+ this.name = "ScenarioAssetTooLargeError";
1093
+ this.reference = reference;
1094
+ this.size = size;
1095
+ this.limit = SCENARIO_GATE_READ_LIMIT_BYTES;
1096
+ Object.setPrototypeOf(this, _ScenarioAssetTooLargeError.prototype);
1097
+ }
1098
+ };
1099
+
1100
+ // ../sdk/lib/build/benchmarks.js
1101
+ var BENCHMARKS_FEATURE = "benchmarks";
1102
+ var BENCHMARK_TAG_VALUE_PATTERN = /^[A-Za-z0-9:._-]{1,64}$/;
1103
+ var MAX_BENCHMARKS_PER_GAME = 20;
1104
+ function resolveBenchmarkLevel(definition3) {
1105
+ return definition3.level ?? "team";
1106
+ }
1107
+ function isRecord(value) {
1108
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1109
+ }
1110
+ function benchmarkWriteProblem(definition3, write) {
1111
+ if (write === null)
1112
+ return null;
1113
+ if (!isRecord(write))
1114
+ return "must be an object, or null to remove the record";
1115
+ for (const [name, value] of Object.entries(write)) {
1116
+ if (value === void 0 || value === null)
1117
+ continue;
1118
+ if (name === "tags") {
1119
+ if (!isRecord(value))
1120
+ return `"tags" must be an object of tag values`;
1121
+ const declared = definition3.tags ?? [];
1122
+ for (const [tag, tagValue] of Object.entries(value)) {
1123
+ if (!declared.includes(tag)) {
1124
+ return declared.length === 0 ? `tag "${tag}" is not declared: the benchmark declares no tags` : `tag "${tag}" is not declared; declared tags are ${declared.map((t) => `"${t}"`).join(", ")}`;
1125
+ }
1126
+ if (tagValue === void 0 || tagValue === null)
1127
+ continue;
1128
+ if (typeof tagValue !== "string" || !BENCHMARK_TAG_VALUE_PATTERN.test(tagValue)) {
1129
+ return `tag "${tag}" must be 1 to 64 characters of letters, digits, ':', '.', '_' or '-', got ${JSON.stringify(tagValue)}`;
1130
+ }
1131
+ }
1132
+ continue;
1133
+ }
1134
+ if (name === "excluded") {
1135
+ if (typeof value !== "boolean") {
1136
+ return `"excluded" must be a boolean, got ${JSON.stringify(value)}`;
1137
+ }
1138
+ continue;
1139
+ }
1140
+ const field = definition3.fields[name];
1141
+ if (!field)
1142
+ return `field "${name}" is not declared`;
1143
+ if ("type" in field) {
1144
+ if (typeof value !== "number" || !Number.isFinite(value)) {
1145
+ return `field "${name}" must be a finite number, got ${JSON.stringify(value)}`;
1146
+ }
1147
+ } else if (typeof value !== "string" || !field.enum.includes(value)) {
1148
+ return `field "${name}" must be one of ${field.enum.map((o) => JSON.stringify(o)).join(", ")}, got ${JSON.stringify(value)}`;
1149
+ }
1150
+ }
1151
+ return null;
1152
+ }
1153
+ function applyBenchmarkWrite(current, write) {
1154
+ if (write === null)
1155
+ return void 0;
1156
+ const next = { ...current };
1157
+ for (const [name, value] of Object.entries(write)) {
1158
+ if (value === void 0)
1159
+ continue;
1160
+ if (value === null) {
1161
+ delete next[name];
1162
+ } else if (name === "tags" && isRecord(value)) {
1163
+ const tags = Object.fromEntries(Object.entries(value).filter(([, tagValue]) => typeof tagValue === "string"));
1164
+ if (Object.keys(tags).length === 0)
1165
+ delete next.tags;
1166
+ else
1167
+ next.tags = tags;
1168
+ } else {
1169
+ next[name] = value;
1170
+ }
1171
+ }
1172
+ return Object.keys(next).length === 0 ? void 0 : next;
1173
+ }
1174
+ function benchmarkFilters(query) {
1175
+ const where3 = query?.where;
1176
+ const filters = where3 === void 0 ? [{}] : Array.isArray(where3) ? where3 : [where3];
1177
+ if (filters.length === 0) {
1178
+ throw new Error('getBenchmark: "where" must hold at least one filter');
1179
+ }
1180
+ for (const filter of filters) {
1181
+ if (!isRecord(filter) || Object.values(filter).some((v) => typeof v !== "string")) {
1182
+ throw new Error("getBenchmark: each filter must be an object of tag names to strings");
1183
+ }
1184
+ }
1185
+ return filters.map((filter) => ({ ...filter }));
1186
+ }
1187
+
1188
+ // ../sdk/lib/build/assessments.js
1189
+ var ASSESSMENTS_FEATURE = "assessments";
1190
+ var ASSESSMENTS_SETTINGS = "assessments";
1191
+ var MAX_ASSESSMENTS_PER_GAME = 20;
1192
+ var ASSESSMENT_FEEDBACK_MAX_LENGTH = 500;
1193
+ function isRecord2(value) {
1194
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1195
+ }
1196
+ function foldRecord(definition3, current, write) {
1197
+ if (write === null)
1198
+ return { next: void 0 };
1199
+ if (!isRecord2(write))
1200
+ return { problem: "must be an object, or null to remove the result" };
1201
+ const next = isRecord2(current) ? { ...current } : {};
1202
+ for (const [name, value] of Object.entries(write)) {
1203
+ if (value === void 0)
1204
+ continue;
1205
+ if (name === "score") {
1206
+ if (value === null)
1207
+ return { problem: '"score" cannot be removed; remove the result' };
1208
+ if (typeof value !== "number" || !Number.isFinite(value)) {
1209
+ return { problem: `"score" must be a finite number, got ${JSON.stringify(value)}` };
1210
+ }
1211
+ if (value < definition3.min || value > definition3.max) {
1212
+ return {
1213
+ problem: `"score" must be between ${definition3.min} and ${definition3.max}, got ${value}`
1214
+ };
1215
+ }
1216
+ next.score = value;
1217
+ } else if (name === "feedback") {
1218
+ if (value === null) {
1219
+ delete next.feedback;
1220
+ } else if (typeof value !== "string") {
1221
+ return { problem: `"feedback" must be a string, got ${JSON.stringify(value)}` };
1222
+ } else if (value.length > ASSESSMENT_FEEDBACK_MAX_LENGTH) {
1223
+ return {
1224
+ problem: `"feedback" must be at most ${ASSESSMENT_FEEDBACK_MAX_LENGTH} characters, got ${value.length}`
1225
+ };
1226
+ } else {
1227
+ next.feedback = value;
1228
+ }
1229
+ } else if (name === "final") {
1230
+ if (value === null) {
1231
+ delete next.final;
1232
+ } else if (typeof value !== "boolean") {
1233
+ return { problem: `"final" must be a boolean, got ${JSON.stringify(value)}` };
1234
+ } else if (value) {
1235
+ next.final = true;
1236
+ } else {
1237
+ delete next.final;
1238
+ }
1239
+ } else {
1240
+ return {
1241
+ problem: `"${name}" is not a field of a result; use score, feedback or final`
1242
+ };
1243
+ }
1244
+ }
1245
+ if (next.score === void 0) {
1246
+ return { problem: 'a result needs a "score", and this write leaves it without one' };
1247
+ }
1248
+ return { next };
1249
+ }
1250
+ function foldAssessmentWrite(definition3, current, write, participantIds) {
1251
+ if (definition3.level === "team")
1252
+ return foldRecord(definition3, current, write);
1253
+ if (write === null)
1254
+ return { next: void 0 };
1255
+ if (!isRecord2(write)) {
1256
+ return {
1257
+ problem: "must be an object of results by participant id, or null to remove every result"
1258
+ };
1259
+ }
1260
+ const records = isRecord2(current) ? { ...current } : {};
1261
+ for (const [participantId, recordWrite] of Object.entries(write)) {
1262
+ if (recordWrite === void 0)
1263
+ continue;
1264
+ if (recordWrite !== null && !participantIds.has(participantId)) {
1265
+ return {
1266
+ problem: `participant "${participantId}" is not on this team, so it cannot be scored here`
1267
+ };
1268
+ }
1269
+ const folded = foldRecord(definition3, records[participantId], recordWrite);
1270
+ if ("problem" in folded) {
1271
+ return { problem: `participant "${participantId}": ${folded.problem}` };
1272
+ }
1273
+ if (folded.next === void 0)
1274
+ delete records[participantId];
1275
+ else
1276
+ records[participantId] = folded.next;
1277
+ }
1278
+ return { next: Object.keys(records).length === 0 ? void 0 : records };
1279
+ }
1280
+ function resolveAssessmentBands(definition3, settings) {
1281
+ return (definition3.bands ?? []).map((band) => {
1282
+ const override = settings?.[band.id];
1283
+ return {
1284
+ id: band.id,
1285
+ from: typeof override?.from === "number" ? override.from : band.from,
1286
+ passing: typeof override?.passing === "boolean" ? override.passing : band.passing === true
1287
+ };
1288
+ });
1289
+ }
1290
+ function assessmentBandOf(score, bands) {
1291
+ let found = null;
1292
+ for (const band of bands)
1293
+ if (band.from <= score)
1294
+ found = band;
1295
+ return found;
1296
+ }
1297
+ function buildAssessmentReport(input) {
1298
+ const { definition: definition3, bands, teams, participants, audience } = input;
1299
+ const result = (record2, teamId, complete, participantId) => {
1300
+ if (!isRecord2(record2) || typeof record2.score !== "number")
1301
+ return null;
1302
+ const band = assessmentBandOf(record2.score, bands);
1303
+ const span = definition3.max - definition3.min;
1304
+ return {
1305
+ teamId,
1306
+ ...participantId === void 0 ? {} : { participantId },
1307
+ score: record2.score,
1308
+ scaled: span > 0 ? (record2.score - definition3.min) / span : 0,
1309
+ band: band?.id ?? null,
1310
+ passed: band === null ? null : band.passing,
1311
+ ...typeof record2.feedback === "string" ? { feedback: record2.feedback } : {},
1312
+ final: record2.final === true || complete
1313
+ };
1314
+ };
1315
+ const results = [];
1316
+ if (definition3.level === "team") {
1317
+ for (const team of teams) {
1318
+ if (audience.kind !== "all" && audience.teamId !== team.teamId)
1319
+ continue;
1320
+ const row = result(team.records, team.teamId, team.complete);
1321
+ if (row)
1322
+ results.push(row);
1323
+ }
1324
+ } else {
1325
+ const byTeam = new Map(teams.map((team) => [team.teamId, team]));
1326
+ for (const participant of participants) {
1327
+ if (audience.kind === "team" && audience.teamId !== participant.teamId)
1328
+ continue;
1329
+ if (audience.kind === "participant" && audience.participantId !== participant.id) {
1330
+ continue;
1331
+ }
1332
+ const team = byTeam.get(participant.teamId);
1333
+ if (!team || !isRecord2(team.records))
1334
+ continue;
1335
+ const row = result(team.records[participant.id], team.teamId, team.complete, participant.id);
1336
+ if (row)
1337
+ results.push(row);
1338
+ }
1339
+ }
1340
+ return {
1341
+ identifier: definition3.identifier,
1342
+ level: definition3.level,
1343
+ min: definition3.min,
1344
+ max: definition3.max,
1345
+ bands: bands.map((band) => ({ ...band })),
1346
+ results
1347
+ };
1348
+ }
1349
+
963
1350
  // cli/bundling/logic-exports.ts
964
1351
  import { existsSync } from "fs";
965
1352
 
@@ -1160,6 +1547,56 @@ async function readLogicExports(filePath, names, packageRoot) {
1160
1547
  }
1161
1548
  }
1162
1549
 
1550
+ // cli/core/assessment-settings.ts
1551
+ function assessmentSettingsResource(assessments) {
1552
+ const properties = {};
1553
+ for (const { definition: definition3 } of assessments) {
1554
+ const bands = definition3.bands ?? [];
1555
+ if (bands.length === 0) continue;
1556
+ const bandProperties = {};
1557
+ const defaults = {};
1558
+ for (const band of bands) {
1559
+ const value = { from: band.from, passing: band.passing === true };
1560
+ defaults[band.id] = value;
1561
+ bandProperties[band.id] = {
1562
+ type: "object",
1563
+ title: band.id,
1564
+ properties: {
1565
+ from: {
1566
+ type: "number",
1567
+ title: "Lowest score",
1568
+ minimum: definition3.min,
1569
+ maximum: definition3.max,
1570
+ default: value.from
1571
+ },
1572
+ passing: { type: "boolean", title: "Counts as a pass", default: value.passing }
1573
+ },
1574
+ additionalProperties: false,
1575
+ default: value
1576
+ };
1577
+ }
1578
+ properties[definition3.identifier] = {
1579
+ type: "object",
1580
+ title: definition3.identifier,
1581
+ ...definition3.description ? { description: definition3.description } : {},
1582
+ properties: bandProperties,
1583
+ additionalProperties: false,
1584
+ default: defaults
1585
+ };
1586
+ }
1587
+ if (Object.keys(properties).length === 0) return null;
1588
+ return {
1589
+ definition: {
1590
+ identifier: ASSESSMENTS_SETTINGS,
1591
+ settingsSchema: {
1592
+ type: "object",
1593
+ properties,
1594
+ additionalProperties: false
1595
+ }
1596
+ }
1597
+ };
1598
+ }
1599
+
1163
1600
  // ../schema.json
1164
1601
  var schema_default = {
1165
1602
  $schema: "https://json-schema.org/draft/2020-12/schema",
@@ -1316,6 +1753,24 @@ var schema_default = {
1316
1753
  },
1317
1754
  uniqueItems: true
1318
1755
  },
1756
+ benchmarks: {
1757
+ type: "array",
1758
+ description: "Identifiers of the benchmarks this engine writes. The engine alone writes benchmarks: it receives its current records as `benchmarks`, beside `context`, and returns writes under `benchmarks`, beside `capabilities`. A game that declares any lists the `benchmarks` feature in `requires`",
1759
+ items: {
1760
+ type: "string",
1761
+ pattern: "^[a-z][a-z0-9_]*$"
1762
+ },
1763
+ uniqueItems: true
1764
+ },
1765
+ assessments: {
1766
+ type: "array",
1767
+ description: "Identifiers of the assessments this engine scores. The engine alone writes assessments: it receives its team's current results as `assessments`, beside `context`, and returns writes under `assessments`, beside `capabilities`. A game that declares any lists the `assessments` feature in `requires`",
1768
+ items: {
1769
+ type: "string",
1770
+ pattern: "^[a-z][a-z0-9_]*$"
1771
+ },
1772
+ uniqueItems: true
1773
+ },
1319
1774
  aggregate: {
1320
1775
  type: "boolean",
1321
1776
  description: "Generated, not authored. True when the engine's logic exports InitAggregate and RunAggregate, in which case it runs once across all teams rather than per-team via Run, and may write to shared capabilities. The build derives this from the exports and writes it into the bundled manifest; authoring it in engine.sdk.json is an error.",
@@ -1325,6 +1780,163 @@ var schema_default = {
1325
1780
  required: ["identifier"],
1326
1781
  additionalProperties: false
1327
1782
  },
1783
+ BenchmarkField: {
1784
+ description: "One field of a benchmark: a number, pooled as a distribution, or one of a short declared list of options, pooled as a count per option",
1785
+ oneOf: [
1786
+ {
1787
+ type: "object",
1788
+ properties: {
1789
+ type: { const: "number" },
1790
+ description: { type: "string" }
1791
+ },
1792
+ required: ["type"],
1793
+ additionalProperties: false
1794
+ },
1795
+ {
1796
+ type: "object",
1797
+ properties: {
1798
+ enum: {
1799
+ type: "array",
1800
+ description: "The options a record may hold. Closed and short, so nothing free-form leaves the session",
1801
+ items: {
1802
+ type: "string",
1803
+ pattern: "^[A-Za-z0-9_-]{1,64}$"
1804
+ },
1805
+ minItems: 1,
1806
+ maxItems: 20,
1807
+ uniqueItems: true
1808
+ },
1809
+ description: { type: "string" }
1810
+ },
1811
+ required: ["enum"],
1812
+ additionalProperties: false
1813
+ }
1814
+ ]
1815
+ },
1816
+ BenchmarkDefinition: {
1817
+ type: "object",
1818
+ description: "Definition of a benchmark: outcomes and decisions the engine records for each team (or the session), which a runtime pools anonymously across sessions so a user interface can compare a team with everyone who has played",
1819
+ properties: {
1820
+ identifier: {
1821
+ type: "string",
1822
+ description: "Identifier for the benchmark: its directory name",
1823
+ pattern: "^[a-z][a-z0-9_]*$"
1824
+ },
1825
+ revision: {
1826
+ type: "integer",
1827
+ minimum: 1,
1828
+ description: "Results are pooled per revision. Bump it when a change makes earlier results no longer comparable; leave it alone across ordinary releases so the pool carries on"
1829
+ },
1830
+ level: {
1831
+ type: "string",
1832
+ enum: ["team", "session"],
1833
+ default: "team",
1834
+ description: "'team' (default): one record per team, written by Run or under an aggregate result's teams. 'session': one record for the whole session, written only under an aggregate result's shared"
1835
+ },
1836
+ tags: {
1837
+ type: "array",
1838
+ description: "The names a record can be grouped by. The engine sets each one's value, a short string, and a user interface filters on any combination of them",
1839
+ items: {
1840
+ type: "string",
1841
+ pattern: "^[A-Za-z][A-Za-z0-9_]*$"
1842
+ },
1843
+ maxItems: 5,
1844
+ uniqueItems: true
1845
+ },
1846
+ fields: {
1847
+ type: "object",
1848
+ description: "The benchmark's fields, flat. 'tags' and 'excluded' are reserved",
1849
+ additionalProperties: { $ref: "#/$defs/BenchmarkField" },
1850
+ propertyNames: {
1851
+ pattern: "^[A-Za-z][A-Za-z0-9_]*$",
1852
+ not: { enum: ["tags", "excluded"] }
1853
+ },
1854
+ minProperties: 1,
1855
+ maxProperties: 20
1856
+ }
1857
+ },
1858
+ required: ["identifier", "revision", "fields"],
1859
+ additionalProperties: false
1860
+ },
1861
+ SDKBenchmark: {
1862
+ type: "object",
1863
+ description: "Bundle containing a benchmark definition",
1864
+ properties: {
1865
+ definition: { $ref: "#/$defs/BenchmarkDefinition" }
1866
+ },
1867
+ required: ["definition"],
1868
+ additionalProperties: false
1869
+ },
1870
+ AssessmentBand: {
1871
+ type: "object",
1872
+ description: "One band of an assessment's scores, such as 'developing' or 'expert': every score from `from` up to the next band's `from`",
1873
+ properties: {
1874
+ id: {
1875
+ type: "string",
1876
+ description: "The band's identifier, reported with each result in it. A user interface shows its own label for it",
1877
+ pattern: "^[a-z][a-z0-9_]*$"
1878
+ },
1879
+ from: {
1880
+ type: "number",
1881
+ description: "The lowest score in the band. Bands are listed in ascending order of `from`, and the first starts at the assessment's `min`. A default: the built-in `assessments` settings let a scenario or a session move it"
1882
+ },
1883
+ passing: {
1884
+ type: "boolean",
1885
+ description: "Whether a score in this band is a pass. A default, which the built-in `assessments` settings let a scenario or a session change",
1886
+ default: false
1887
+ },
1888
+ description: {
1889
+ type: "string",
1890
+ description: "What the band means, for whoever reads the game's results"
1891
+ }
1892
+ },
1893
+ required: ["id", "from"],
1894
+ additionalProperties: false
1895
+ },
1896
+ AssessmentDefinition: {
1897
+ type: "object",
1898
+ description: "Definition of an assessment: one measure the engine scores for each participant, or for each team, which a runtime may report to a learning management system. The score is the game's; the runtime places it in a band and decides pass or fail from the band",
1899
+ properties: {
1900
+ identifier: {
1901
+ type: "string",
1902
+ description: "Identifier for the assessment: its directory name",
1903
+ pattern: "^[a-z][a-z0-9_]*$"
1904
+ },
1905
+ description: {
1906
+ type: "string",
1907
+ description: "What the assessment measures, for whoever reads the game's results"
1908
+ },
1909
+ level: {
1910
+ type: "string",
1911
+ enum: ["participant", "team"],
1912
+ description: "'participant': one score per participant, written for each by participant id. 'team': one score per team, which every participant on the team receives"
1913
+ },
1914
+ min: {
1915
+ type: "number",
1916
+ description: "The lowest score the engine may write"
1917
+ },
1918
+ max: {
1919
+ type: "number",
1920
+ description: "The highest score the engine may write. Greater than `min`"
1921
+ },
1922
+ bands: {
1923
+ type: "array",
1924
+ description: "The ranges a score falls into, ascending, the first starting at `min`: at most 10. Without bands, a result has no band and no pass or fail",
1925
+ items: { $ref: "#/$defs/AssessmentBand" }
1926
+ }
1927
+ },
1928
+ required: ["identifier", "level", "min", "max"],
1929
+ additionalProperties: false
1930
+ },
1931
+ SDKAssessment: {
1932
+ type: "object",
1933
+ description: "Bundle containing an assessment definition",
1934
+ properties: {
1935
+ definition: { $ref: "#/$defs/AssessmentDefinition" }
1936
+ },
1937
+ required: ["definition"],
1938
+ additionalProperties: false
1939
+ },
1328
1940
  CapabilityDefinition: {
1329
1941
  type: "object",
1330
1942
  description: "Definition of a capability",
@@ -2353,6 +2965,14 @@ var schema_default = {
2353
2965
  type: "array",
2354
2966
  items: { $ref: "#/$defs/SDKCapability" }
2355
2967
  },
2968
+ benchmarks: {
2969
+ type: "array",
2970
+ items: { $ref: "#/$defs/SDKBenchmark" }
2971
+ },
2972
+ assessments: {
2973
+ type: "array",
2974
+ items: { $ref: "#/$defs/SDKAssessment" }
2975
+ },
2356
2976
  settings: {
2357
2977
  type: "array",
2358
2978
  items: { $ref: "#/$defs/SDKSettings" }
@@ -2739,6 +3359,12 @@ var schema_default = {
2739
3359
  SDKPackage: { $ref: "#/$defs/SDKPackage" },
2740
3360
  SDKEngine: { $ref: "#/$defs/SDKEngine" },
2741
3361
  SDKCapability: { $ref: "#/$defs/SDKCapability" },
3362
+ BenchmarkField: { $ref: "#/$defs/BenchmarkField" },
3363
+ BenchmarkDefinition: { $ref: "#/$defs/BenchmarkDefinition" },
3364
+ SDKBenchmark: { $ref: "#/$defs/SDKBenchmark" },
3365
+ AssessmentBand: { $ref: "#/$defs/AssessmentBand" },
3366
+ AssessmentDefinition: { $ref: "#/$defs/AssessmentDefinition" },
3367
+ SDKAssessment: { $ref: "#/$defs/SDKAssessment" },
2742
3368
  SDKScenario: { $ref: "#/$defs/SDKScenario" },
2743
3369
  SDKUserInterface: { $ref: "#/$defs/SDKUserInterface" },
2744
3370
  SDKSetup: {
@@ -2910,7 +3536,11 @@ var SUPPORTED_FEATURES = [
2910
3536
  // File reads in a validator's `Scenario` gate (§15.8).
2911
3537
  "scenario-files",
2912
3538
  // The `Scenario` gate judging a session as it starts, and refusing it (§15.8).
2913
- "session-validation"
3539
+ "session-validation",
3540
+ // Benchmarks: engine-written records pooled across sessions (§6.16).
3541
+ "benchmarks",
3542
+ // Assessments: engine-written scores per participant or team, in bands (§6.17).
3543
+ "assessments"
2914
3544
  ];
2915
3545
  function unsupportedFeatures(manifest) {
2916
3546
  return (manifest.requires ?? []).filter((feature) => !SUPPORTED_FEATURES.includes(feature));
@@ -2940,102 +3570,6 @@ function unsupportedServices(resources, supported = SUPPORTED_SERVICES) {
2940
3570
  import { existsSync as existsSync2, readdirSync, readFileSync } from "fs";
2941
3571
  import { join as join2 } from "path";
2942
3572
 
2943
- // ../sdk/lib/build/callbacks.js
2944
- var UndeclaredApiUseError = class extends Error {
2945
- resourceIdentifier;
2946
- api;
2947
- constructor(resourceIdentifier, api) {
2948
- super(`Resource "${resourceIdentifier}" attempted to call callback "${api}" but did not declare it in its bundle's "uses" array. Add "${api}" to the bundle's uses to allow this call.`);
2949
- this.name = "UndeclaredApiUseError";
2950
- this.resourceIdentifier = resourceIdentifier;
2951
- this.api = api;
2952
- }
2953
- };
2954
-
2955
- // ../sdk/lib/build/tick-validation.js
2956
- var MAX_EFFECTIVE_TICK_INTERVAL_MS = 7 * 24 * 60 * 60 * 1e3;
2957
-
2958
- // ../sdk/lib/build/setting-path.js
2959
- var NOT_PLAIN = /[.[\]"\s]/u;
2960
- function isPlainKey(key) {
2961
- return key !== "" && !NOT_PLAIN.test(key);
2962
- }
2963
- function settingPath(identifier, ...keys) {
2964
- let path3 = isPlainKey(identifier) ? identifier : `[${JSON.stringify(identifier)}]`;
2965
- for (const key of keys) {
2966
- const step = String(key);
2967
- path3 += isPlainKey(step) ? `.${step}` : `[${JSON.stringify(step)}]`;
2968
- }
2969
- return path3;
2970
- }
2971
- function parseSettingPath(path3) {
2972
- const steps = [];
2973
- let at = 0;
2974
- while (at < path3.length) {
2975
- if (path3[at] === "[") {
2976
- const end2 = closingQuote(path3, at + 1);
2977
- if (end2 === void 0 || path3[end2 + 1] !== "]")
2978
- return void 0;
2979
- let key2;
2980
- try {
2981
- key2 = JSON.parse(path3.slice(at + 1, end2 + 1));
2982
- } catch {
2983
- return void 0;
2984
- }
2985
- if (typeof key2 !== "string")
2986
- return void 0;
2987
- steps.push(key2);
2988
- at = end2 + 2;
2989
- continue;
2990
- }
2991
- if (steps.length > 0) {
2992
- if (path3[at] !== ".")
2993
- return void 0;
2994
- at += 1;
2995
- }
2996
- let end = at;
2997
- while (end < path3.length && path3[end] !== "." && path3[end] !== "[")
2998
- end += 1;
2999
- const key = path3.slice(at, end);
3000
- if (!isPlainKey(key))
3001
- return void 0;
3002
- steps.push(key);
3003
- at = end;
3004
- }
3005
- const [identifier, ...keys] = steps;
3006
- return identifier === void 0 ? void 0 : { identifier, keys };
3007
- }
3008
- function closingQuote(path3, start) {
3009
- if (path3[start] !== '"')
3010
- return void 0;
3011
- for (let at = start + 1; at < path3.length; at += 1) {
3012
- if (path3[at] === "\\")
3013
- at += 1;
3014
- else if (path3[at] === '"')
3015
- return at;
3016
- }
3017
- return void 0;
3018
- }
3019
-
3020
- // ../sdk/lib/build/validators.js
3021
- var SCENARIO_GATE_READ_LIMIT_BYTES = 10 * 1024 * 1024;
3022
- var ScenarioAssetTooLargeError = class _ScenarioAssetTooLargeError extends Error {
3023
- /** The reference the gate asked to read. */
3024
- reference;
3025
- /** The file's size in bytes. */
3026
- size;
3027
- /** The cap it exceeds: {@link SCENARIO_GATE_READ_LIMIT_BYTES}. */
3028
- limit;
3029
- constructor(reference, size) {
3030
- super(`Cannot read "${reference}" in a Scenario gate: it is ${size} bytes, over the ${SCENARIO_GATE_READ_LIMIT_BYTES}-byte (10 MB) limit on a gate's reads. Call describeAsset to check that it is there or how large it is.`);
3031
- this.name = "ScenarioAssetTooLargeError";
3032
- this.reference = reference;
3033
- this.size = size;
3034
- this.limit = SCENARIO_GATE_READ_LIMIT_BYTES;
3035
- Object.setPrototypeOf(this, _ScenarioAssetTooLargeError.prototype);
3036
- }
3037
- };
3038
-
3039
3573
  // ../node_modules/.pnpm/ccount@2.0.1/node_modules/ccount/index.js
3040
3574
  function ccount(value, character) {
3041
3575
  const source = String(value);
@@ -15707,6 +16241,70 @@ var capabilityExample = JSON.stringify(
15707
16241
  null,
15708
16242
  4
15709
16243
  );
16244
+ var benchmarkExample = JSON.stringify(
16245
+ {
16246
+ definition: {
16247
+ identifier: "outcome",
16248
+ revision: 1,
16249
+ tags: ["difficulty"],
16250
+ fields: {
16251
+ NetProfit: { type: "number", description: "Profit over the whole game" },
16252
+ Round1Pricing: { enum: ["premium", "match", "discount"] }
16253
+ }
16254
+ }
16255
+ },
16256
+ null,
16257
+ 4
16258
+ );
16259
+ var benchmarkUpdateExample = JSON.stringify(
16260
+ {
16261
+ definition: {
16262
+ identifier: "outcome",
16263
+ revision: 2,
16264
+ tags: ["difficulty", "teams"],
16265
+ fields: {
16266
+ NetProfit: { type: "number", description: "Profit over the whole game" }
16267
+ }
16268
+ }
16269
+ },
16270
+ null,
16271
+ 4
16272
+ );
16273
+ var assessmentExample = JSON.stringify(
16274
+ {
16275
+ definition: {
16276
+ identifier: "teamwork",
16277
+ description: "How well each participant worked with their team",
16278
+ level: "participant",
16279
+ min: 0,
16280
+ max: 100,
16281
+ bands: [
16282
+ { id: "developing", from: 0 },
16283
+ { id: "competent", from: 50, passing: true },
16284
+ { id: "expert", from: 80, passing: true }
16285
+ ]
16286
+ }
16287
+ },
16288
+ null,
16289
+ 4
16290
+ );
16291
+ var assessmentUpdateExample = JSON.stringify(
16292
+ {
16293
+ definition: {
16294
+ identifier: "teamwork",
16295
+ level: "participant",
16296
+ min: 0,
16297
+ max: 100,
16298
+ bands: [
16299
+ { id: "developing", from: 0 },
16300
+ { id: "competent", from: 60, passing: true },
16301
+ { id: "expert", from: 85, passing: true }
16302
+ ]
16303
+ }
16304
+ },
16305
+ null,
16306
+ 4
16307
+ );
15710
16308
  var settingsExample = JSON.stringify(
15711
16309
  {
15712
16310
  definition: {
@@ -16186,6 +16784,8 @@ var facilitatorGuideUpdateExample = JSON.stringify(
16186
16784
  var RESOURCE_EXAMPLES = {
16187
16785
  package: { new: packageExample, update: packageUpdateExample },
16188
16786
  capability: { new: capabilityExample, update: capabilityUpdateExample },
16787
+ benchmark: { new: benchmarkExample, update: benchmarkUpdateExample },
16788
+ assessment: { new: assessmentExample, update: assessmentUpdateExample },
16189
16789
  settings: { new: settingsExample, update: settingsUpdateExample },
16190
16790
  engine: { new: engineExample, update: engineUpdateExample },
16191
16791
  ui: { new: userInterfaceExample, update: userInterfaceUpdateExample },
@@ -16219,6 +16819,8 @@ var settingsAjv = createAjv("reference");
16219
16819
  ajv2.addSchema(schema, "schema.json");
16220
16820
  var validators = {
16221
16821
  sdkCapability: ajv2.compile({ $ref: "schema.json#/$defs/SDKCapability" }),
16822
+ sdkBenchmark: ajv2.compile({ $ref: "schema.json#/$defs/SDKBenchmark" }),
16823
+ sdkAssessment: ajv2.compile({ $ref: "schema.json#/$defs/SDKAssessment" }),
16222
16824
  sdkSettings: ajv2.compile({ $ref: "schema.json#/$defs/SDKSettings" }),
16223
16825
  sdkEngine: ajv2.compile({ $ref: "schema.json#/$defs/SDKEngine" }),
16224
16826
  sdkUserInterface: ajv2.compile({
@@ -16370,6 +16972,16 @@ var validateSDKCapability = makeValidator(
16370
16972
  "capability.sdk.json",
16371
16973
  resourceExample("capability", "new")
16372
16974
  );
16975
+ var validateSDKBenchmark = makeValidator(
16976
+ validators.sdkBenchmark,
16977
+ "benchmark.sdk.json",
16978
+ resourceExample("benchmark", "new")
16979
+ );
16980
+ var validateSDKAssessment = makeValidator(
16981
+ validators.sdkAssessment,
16982
+ "assessment.sdk.json",
16983
+ resourceExample("assessment", "new")
16984
+ );
16373
16985
  var validateSDKSettings = makeValidator(
16374
16986
  validators.sdkSettings,
16375
16987
  "settings.sdk.json",
@@ -16978,8 +17590,16 @@ async function loadConfig(configPath) {
16978
17590
  problems.throwIfAny();
16979
17591
  assertRequiredFeaturesSupported(jsonConfig, configPath);
16980
17592
  const capabilities = await discover(configDir, KINDS.capability, problems);
17593
+ const benchmarks = await discover(configDir, KINDS.benchmark, problems);
17594
+ const assessments = await discover(configDir, KINDS.assessment, problems);
16981
17595
  const authoredSettings = await discover(configDir, KINDS.settings, problems);
16982
17596
  refuseReservedSettings(problems, authoredSettings);
17597
+ if (assessments.length > 0) refuseAssessmentSettings(problems, authoredSettings);
17598
+ const assessmentSettings = assessmentSettingsResource(assessments);
17599
+ const builtInSettings = () => [
17600
+ gameSettingsResource(jsonConfig),
17601
+ ...assessmentSettings ? [assessmentSettings] : []
17602
+ ];
16983
17603
  const scenarios = await discover(configDir, KINDS.scenario, problems);
16984
17604
  const hooks = await discover(configDir, KINDS.hook, problems);
16985
17605
  const discoveredValidators = await discover(configDir, KINDS.validator, problems);
@@ -17017,7 +17637,7 @@ async function loadConfig(configPath) {
17017
17637
  refuseUnknownSettingsInSetupNotes(
17018
17638
  setup,
17019
17639
  configDir,
17020
- [gameSettingsResource(jsonConfig), ...authoredSettings],
17640
+ [...builtInSettings(), ...authoredSettings],
17021
17641
  problems
17022
17642
  );
17023
17643
  problems.throwIfAny();
@@ -17049,8 +17669,10 @@ async function loadConfig(configPath) {
17049
17669
  ...tick_controller ? { tick_controller } : {},
17050
17670
  ...guide ? { guide } : {},
17051
17671
  capabilities,
17052
- // The built-in `game` settings come first, then the package's own.
17053
- settings: [gameSettingsResource(jsonConfig), ...authoredSettings],
17672
+ ...benchmarks.length > 0 ? { benchmarks } : {},
17673
+ ...assessments.length > 0 ? { assessments } : {},
17674
+ // The built-in settings come first, then the package's own.
17675
+ settings: [...builtInSettings(), ...authoredSettings],
17054
17676
  scenarios,
17055
17677
  hooks,
17056
17678
  validators: validators2,
@@ -17199,6 +17821,19 @@ function refuseReservedSettings(problems, settings) {
17199
17821
  }
17200
17822
  ]);
17201
17823
  }
17824
+ function refuseAssessmentSettings(problems, settings) {
17825
+ if (!settings.some((entry) => entry.definition.identifier === ASSESSMENTS_SETTINGS)) return;
17826
+ const message = `\`settings/${ASSESSMENTS_SETTINGS}/\` is reserved for the built-in assessment band settings`;
17827
+ const hint = "Set an assessment's bands in its assessment.sdk.json, and rename this settings resource.";
17828
+ problems.add("SETTINGS_RESERVED", `Invalid package: ${message}. ${hint}`, [
17829
+ {
17830
+ code: "SETTINGS_RESERVED",
17831
+ message,
17832
+ hint,
17833
+ file: `settings/${ASSESSMENTS_SETTINGS}/settings.sdk.json`
17834
+ }
17835
+ ]);
17836
+ }
17202
17837
  function refuseUnknownSettingsInSetupNotes(setup, configDir, settings, problems) {
17203
17838
  if (!setup) return;
17204
17839
  const schemas = settingsSchemas({ settings: [...settings] });
@@ -17378,6 +18013,8 @@ function kind(type, validate2, hasRootDirectory = true) {
17378
18013
  }
17379
18014
  var KINDS = {
17380
18015
  capability: kind("capability", validateSDKCapability, false),
18016
+ benchmark: kind("benchmark", validateSDKBenchmark, false),
18017
+ assessment: kind("assessment", validateSDKAssessment, false),
17381
18018
  settings: kind("settings", validateSDKSettings, false),
17382
18019
  engine: kind("engine", validateSDKEngine),
17383
18020
  ui: kind("ui", validateSDKUserInterface),
@@ -17508,7 +18145,7 @@ import { statSync as statSync3 } from "fs";
17508
18145
  import { mkdtemp as mkdtemp3, rm as rm6 } from "fs/promises";
17509
18146
  import { createServer } from "http";
17510
18147
  import { tmpdir as tmpdir3 } from "os";
17511
- import { dirname as dirname11, join as join20 } from "path";
18148
+ import { dirname as dirname11, join as join21 } from "path";
17512
18149
  import { fileURLToPath as fileURLToPath4 } from "url";
17513
18150
  import react2 from "@vitejs/plugin-react";
17514
18151
  import express2 from "express";
@@ -17694,6 +18331,8 @@ var QUERY_TYPES = /* @__PURE__ */ new Set([
17694
18331
  "callEndpoint",
17695
18332
  "getPastState",
17696
18333
  "getAllTeamsParticipants",
18334
+ "getBenchmark",
18335
+ "getAssessment",
17697
18336
  "getEndpointAudit",
17698
18337
  "listEndpoints"
17699
18338
  ]);
@@ -17765,6 +18404,7 @@ var COMMAND_FIELDS = {
17765
18404
  resumeTimer: { "teamIndex?": "number" },
17766
18405
  extendTick: { byMs: "number", "teamIndex?": "number" },
17767
18406
  advanceClock: { byMs: "number" },
18407
+ makeDormant: {},
17768
18408
  armFault: { fault: "fault", "times?": "number", "reason?": "string" },
17769
18409
  disarmFault: { fault: "fault" },
17770
18410
  // Queries
@@ -17792,6 +18432,14 @@ var COMMAND_FIELDS = {
17792
18432
  "participantId?": "string",
17793
18433
  "teamId?": "string"
17794
18434
  },
18435
+ getBenchmark: { identifier: "string", where: "array" },
18436
+ getAssessment: {
18437
+ identifier: "string",
18438
+ "audience?": "string",
18439
+ "participantId?": "string",
18440
+ "teamId?": "string",
18441
+ "viewerRole?": "viewerRole"
18442
+ },
17795
18443
  getEndpointAudit: {},
17796
18444
  listEndpoints: { "external?": "boolean" }
17797
18445
  };
@@ -17863,12 +18511,21 @@ var PROJECTION_VERSION = 4;
17863
18511
  // cli/execution/engine-state.ts
17864
18512
  var ENGINE_STATE_KEY = "$engineState";
17865
18513
  var SHARED_ENGINE_STATE_KEY = "$sharedEngineState";
17866
- var RESERVED_KEYS = /* @__PURE__ */ new Set([ENGINE_STATE_KEY, SHARED_ENGINE_STATE_KEY]);
18514
+ var BENCHMARKS_KEY = "$benchmarks";
18515
+ var SHARED_BENCHMARKS_KEY = "$sharedBenchmarks";
18516
+ var ASSESSMENTS_KEY = "$assessments";
18517
+ var RESERVED_KEYS = /* @__PURE__ */ new Set([
18518
+ ENGINE_STATE_KEY,
18519
+ SHARED_ENGINE_STATE_KEY,
18520
+ BENCHMARKS_KEY,
18521
+ SHARED_BENCHMARKS_KEY,
18522
+ ASSESSMENTS_KEY
18523
+ ]);
17867
18524
  function isReservedKey(key) {
17868
18525
  return RESERVED_KEYS.has(key);
17869
18526
  }
17870
18527
  function withoutEngineState(context) {
17871
- if (!(ENGINE_STATE_KEY in context) && !(SHARED_ENGINE_STATE_KEY in context)) return context;
18528
+ if (!Object.keys(context).some(isReservedKey)) return context;
17872
18529
  const rest = {};
17873
18530
  for (const [key, value] of Object.entries(context)) {
17874
18531
  if (!isReservedKey(key)) rest[key] = value;
@@ -18861,11 +19518,11 @@ function normalizeVariablesSchema(schema2) {
18861
19518
  }
18862
19519
 
18863
19520
  // cli/execution/logic-result.ts
18864
- function isRecord(value) {
19521
+ function isRecord3(value) {
18865
19522
  return typeof value === "object" && value !== null && !Array.isArray(value);
18866
19523
  }
18867
19524
  function readCapabilities(label4, result, allowed = ["capabilities", "deletes"]) {
18868
- if (!isRecord(result)) {
19525
+ if (!isRecord3(result)) {
18869
19526
  throw new Error(`${label4} must return an object of the form { capabilities: { ... } }`);
18870
19527
  }
18871
19528
  const unknownKeys = Object.keys(result).filter((key) => !allowed.includes(key));
@@ -18879,7 +19536,7 @@ function readCapabilities(label4, result, allowed = ["capabilities", "deletes"])
18879
19536
  if (capabilities === void 0 || capabilities === null) {
18880
19537
  return {};
18881
19538
  }
18882
- if (!isRecord(capabilities)) {
19539
+ if (!isRecord3(capabilities)) {
18883
19540
  throw new Error(`${label4} returned "capabilities" that is not an object`);
18884
19541
  }
18885
19542
  const reserved = Object.keys(capabilities).find(isReservedKey);
@@ -18891,7 +19548,7 @@ function readCapabilities(label4, result, allowed = ["capabilities", "deletes"])
18891
19548
  return capabilities;
18892
19549
  }
18893
19550
  function readDeletes(label4, result) {
18894
- if (!isRecord(result)) return [];
19551
+ if (!isRecord3(result)) return [];
18895
19552
  const deletes = result.deletes;
18896
19553
  if (deletes === void 0 || deletes === null) return [];
18897
19554
  if (!Array.isArray(deletes)) {
@@ -18936,18 +19593,32 @@ function assertDeletesDeclared(label4, deletes, declaration, shared, target) {
18936
19593
  }
18937
19594
  }
18938
19595
  }
18939
- function readEngineResult(label4, result, phase = "init") {
18940
- const allowed = phase === "tick" ? ["capabilities", "deletes", "state", "complete"] : ["capabilities", "deletes", "state"];
19596
+ function readEngineResult(label4, result, phase = "init", writesBenchmarks = false, writesAssessments = false) {
19597
+ const allowed = [
19598
+ "capabilities",
19599
+ "deletes",
19600
+ "state",
19601
+ ...phase === "tick" ? ["complete"] : [],
19602
+ ...writesBenchmarks ? ["benchmarks"] : [],
19603
+ ...writesAssessments ? ["assessments"] : []
19604
+ ];
18941
19605
  const capabilities = readCapabilities(label4, result, allowed);
18942
19606
  const deletes = readDeletes(label4, result);
18943
- const { state: state2, complete } = result;
19607
+ const { state: state2, complete, benchmarks, assessments } = result;
18944
19608
  if (complete !== void 0 && typeof complete !== "boolean") {
18945
19609
  throw new Error(`${label4} returned "complete" that is not a boolean`);
18946
19610
  }
18947
- return { capabilities, deletes, state: state2, complete: complete === true };
19611
+ return {
19612
+ capabilities,
19613
+ deletes,
19614
+ state: state2,
19615
+ complete: complete === true,
19616
+ ...benchmarks === void 0 ? {} : { benchmarks },
19617
+ ...assessments === void 0 ? {} : { assessments }
19618
+ };
18948
19619
  }
18949
- function readAggregateResult(label4, result, teamCount, phase = "init") {
18950
- if (!isRecord(result)) {
19620
+ function readAggregateResult(label4, result, teamCount, phase = "init", writesBenchmarks = false, writesAssessments = false) {
19621
+ if (!isRecord3(result)) {
18951
19622
  throw new Error(
18952
19623
  `${label4} must return { shared: { capabilities }, teams: [{ capabilities }] }`
18953
19624
  );
@@ -18964,15 +19635,27 @@ function readAggregateResult(label4, result, teamCount, phase = "init") {
18964
19635
  );
18965
19636
  }
18966
19637
  return {
18967
- shared: result.shared === void 0 ? { capabilities: {}, deletes: [], state: void 0, complete: false } : readEngineResult(`${label4} "shared"`, result.shared, phase),
19638
+ shared: result.shared === void 0 ? { capabilities: {}, deletes: [], state: void 0, complete: false } : readEngineResult(
19639
+ `${label4} "shared"`,
19640
+ result.shared,
19641
+ phase,
19642
+ writesBenchmarks,
19643
+ writesAssessments
19644
+ ),
18968
19645
  teams: result.teams.map(
18969
- (team, i) => readEngineResult(`${label4} "teams[${i}]"`, team, phase)
19646
+ (team, i) => readEngineResult(
19647
+ `${label4} "teams[${i}]"`,
19648
+ team,
19649
+ phase,
19650
+ writesBenchmarks,
19651
+ writesAssessments
19652
+ )
18970
19653
  )
18971
19654
  };
18972
19655
  }
18973
19656
  var TICK_CONTROLLER_KEYS = ["enabled", "intervalMs", "nextTickAt", "complete"];
18974
19657
  function readTickControllerResult(label4, result) {
18975
- if (!isRecord(result)) {
19658
+ if (!isRecord3(result)) {
18976
19659
  throw new Error(`${label4} must return an object of the form { enabled, intervalMs? }`);
18977
19660
  }
18978
19661
  const unknownKeys = Object.keys(result).filter((key) => !TICK_CONTROLLER_KEYS.includes(key));
@@ -18991,6 +19674,87 @@ function readTickControllerResult(label4, result) {
18991
19674
  }
18992
19675
 
18993
19676
  // cli/execution/context-composition.ts
19677
+ function foldAssessmentWrites(label4, raw, current, participantIds, scope) {
19678
+ if (raw === void 0) return void 0;
19679
+ if (!isPlainObject3(raw)) {
19680
+ scope.warn(
19681
+ `${label4} returned "assessments" that is not an object of writes by assessment. Every assessment write in it was dropped, and the round carried on.`
19682
+ );
19683
+ return void 0;
19684
+ }
19685
+ const writes = structuredClone(raw);
19686
+ const results = structuredClone(isPlainObject3(current) ? current : {});
19687
+ for (const [identifier, write] of Object.entries(writes)) {
19688
+ if (write === void 0) continue;
19689
+ const named3 = `${label4} wrote assessment "${identifier}"`;
19690
+ const definition3 = scope.assessments?.get(identifier);
19691
+ if (!definition3) {
19692
+ scope.warn(
19693
+ `${named3}, which the engine does not declare in "assessments". The write was dropped.`
19694
+ );
19695
+ continue;
19696
+ }
19697
+ const folded = foldAssessmentWrite(definition3, results[identifier], write, participantIds);
19698
+ if ("problem" in folded) {
19699
+ scope.warn(
19700
+ `${named3}: ${folded.problem}. The write was dropped, and the round carried on.`
19701
+ );
19702
+ continue;
19703
+ }
19704
+ if (folded.next === void 0) delete results[identifier];
19705
+ else results[identifier] = folded.next;
19706
+ }
19707
+ return results;
19708
+ }
19709
+ function isPlainObject3(value) {
19710
+ return typeof value === "object" && value !== null && !Array.isArray(value);
19711
+ }
19712
+ function foldBenchmarkWrites(label4, raw, current, level, scope) {
19713
+ if (raw === void 0) return void 0;
19714
+ if (!isPlainObject3(raw)) {
19715
+ scope.warn(
19716
+ `${label4} returned "benchmarks" that is not an object of writes by benchmark. Every benchmark write in it was dropped, and the round carried on.`
19717
+ );
19718
+ return void 0;
19719
+ }
19720
+ const writes = structuredClone(raw);
19721
+ const records = structuredClone(isPlainObject3(current) ? current : {});
19722
+ for (const [identifier, write] of Object.entries(writes)) {
19723
+ if (write === void 0) continue;
19724
+ const named3 = `${label4} wrote benchmark "${identifier}"`;
19725
+ const definition3 = scope.benchmarks.get(identifier);
19726
+ if (!definition3) {
19727
+ scope.warn(
19728
+ `${named3}, which the engine does not declare in "benchmarks". The write was dropped.`
19729
+ );
19730
+ continue;
19731
+ }
19732
+ const declaredLevel = resolveBenchmarkLevel(definition3);
19733
+ if (declaredLevel !== level) {
19734
+ scope.warn(
19735
+ declaredLevel === "session" ? `${named3}, which is session-level, so it is written under an aggregate result's "shared". The write was dropped.` : `${named3}, which is per team, so it is written for each team rather than under "shared". The write was dropped.`
19736
+ );
19737
+ continue;
19738
+ }
19739
+ const problem = benchmarkWriteProblem(definition3, write);
19740
+ if (problem !== null) {
19741
+ scope.warn(`${named3}: ${problem}. The write was dropped, and the round carried on.`);
19742
+ continue;
19743
+ }
19744
+ const next = applyBenchmarkWrite(
19745
+ records[identifier],
19746
+ write
19747
+ );
19748
+ if (next === void 0) delete records[identifier];
19749
+ else records[identifier] = next;
19750
+ }
19751
+ return records;
19752
+ }
19753
+ function storeRecords(target, key, records) {
19754
+ if (records === void 0) return;
19755
+ if (Object.keys(records).length === 0) delete target[key];
19756
+ else target[key] = records;
19757
+ }
18994
19758
  function mutationAffects(reads, previous4, next) {
18995
19759
  if (!reads || reads.length === 0) return true;
18996
19760
  return reads.some((capId) => JSON.stringify(previous4[capId]) !== JSON.stringify(next[capId]));
@@ -19046,12 +19810,17 @@ function foldLogicResult(capabilities, deletes, contextBefore, defaults) {
19046
19810
  const merged = mergeCapabilityFields(capabilities, contextBefore, defaults);
19047
19811
  return deletes.length === 0 ? merged : applyContextUpdate(merged, {}, deletes);
19048
19812
  }
19049
- function aggregateArgs(contexts, identities, declaration, store, sharedIds, participants) {
19813
+ function aggregateArgs(contexts, identities, declaration, store, sharedIds, participants, writesBenchmarks = false, writesAssessments = false) {
19050
19814
  const shared = projectForLogic(store, declaration);
19051
19815
  return {
19052
19816
  shared: {
19053
19817
  context: structuredClone(shared),
19054
- state: structuredClone(store[SHARED_ENGINE_STATE_KEY])
19818
+ state: structuredClone(store[SHARED_ENGINE_STATE_KEY]),
19819
+ ...writesBenchmarks ? {
19820
+ benchmarks: structuredClone(
19821
+ store[SHARED_BENCHMARKS_KEY] ?? {}
19822
+ )
19823
+ } : {}
19055
19824
  },
19056
19825
  teams: contexts.map((context, i) => ({
19057
19826
  teamId: identities[i].teamId,
@@ -19061,12 +19830,22 @@ function aggregateArgs(contexts, identities, declaration, store, sharedIds, part
19061
19830
  ([capId]) => !sharedIds.has(capId)
19062
19831
  )
19063
19832
  ),
19064
- state: structuredClone(context[ENGINE_STATE_KEY])
19833
+ state: structuredClone(context[ENGINE_STATE_KEY]),
19834
+ ...writesBenchmarks ? {
19835
+ benchmarks: structuredClone(
19836
+ context[BENCHMARKS_KEY] ?? {}
19837
+ )
19838
+ } : {},
19839
+ ...writesAssessments ? {
19840
+ assessments: structuredClone(
19841
+ context[ASSESSMENTS_KEY] ?? {}
19842
+ )
19843
+ } : {}
19065
19844
  })),
19066
19845
  participants
19067
19846
  };
19068
19847
  }
19069
- function applyEngineResult(label4, result, contextBefore, scope) {
19848
+ function applyEngineResult(label4, result, contextBefore, scope, teamId) {
19070
19849
  assertDeletesDeclared(label4, result.deletes, scope.engine, new Set(scope.sharedIds), "team");
19071
19850
  const merged = foldLogicResult(
19072
19851
  result.capabilities,
@@ -19078,9 +19857,25 @@ function applyEngineResult(label4, result, contextBefore, scope) {
19078
19857
  assertJsonSerialisable(label4, result.state);
19079
19858
  merged[ENGINE_STATE_KEY] = structuredClone(result.state);
19080
19859
  }
19860
+ storeRecords(
19861
+ merged,
19862
+ BENCHMARKS_KEY,
19863
+ foldBenchmarkWrites(label4, result.benchmarks, contextBefore[BENCHMARKS_KEY], "team", scope)
19864
+ );
19865
+ storeRecords(
19866
+ merged,
19867
+ ASSESSMENTS_KEY,
19868
+ foldAssessmentWrites(
19869
+ label4,
19870
+ result.assessments,
19871
+ contextBefore[ASSESSMENTS_KEY],
19872
+ teamId === void 0 ? /* @__PURE__ */ new Set() : scope.participantIdsOf?.(teamId) ?? /* @__PURE__ */ new Set(),
19873
+ scope
19874
+ )
19875
+ );
19081
19876
  return merged;
19082
19877
  }
19083
- function applyAggregateResult(read, contextsBefore, engineIdentifier, phase, scope, store) {
19878
+ function applyAggregateResult(read, contextsBefore, engineIdentifier, phase, scope, store, teamIds = []) {
19084
19879
  const label4 = `Engine "${engineIdentifier}" ${phase}`;
19085
19880
  const result = {
19086
19881
  shared: read.shared.capabilities,
@@ -19110,7 +19905,13 @@ function applyAggregateResult(read, contextsBefore, engineIdentifier, phase, sco
19110
19905
  "shared"
19111
19906
  );
19112
19907
  const contexts = read.teams.map((team, i) => {
19113
- const context = applyEngineResult(`${label4} "teams[${i}]"`, team, contextsBefore[i], scope);
19908
+ const context = applyEngineResult(
19909
+ `${label4} "teams[${i}]"`,
19910
+ team,
19911
+ contextsBefore[i],
19912
+ scope,
19913
+ teamIds[i]
19914
+ );
19114
19915
  enforceDeclaredWrites(
19115
19916
  engineIdentifier,
19116
19917
  scope.engine,
@@ -19120,11 +19921,27 @@ function applyAggregateResult(read, contextsBefore, engineIdentifier, phase, sco
19120
19921
  );
19121
19922
  return context;
19122
19923
  });
19924
+ if (read.shared.assessments !== void 0) {
19925
+ scope.warn(
19926
+ `${label4} "shared" returned "assessments", but every assessment belongs to a team or a participant, so it is written under each team's entry in "teams". The writes were dropped, and the round carried on.`
19927
+ );
19928
+ }
19123
19929
  let next = { ...store };
19124
19930
  if (read.shared.state !== void 0) {
19125
19931
  assertJsonSerialisable(`${label4} "shared"`, read.shared.state);
19126
19932
  next[SHARED_ENGINE_STATE_KEY] = structuredClone(read.shared.state);
19127
19933
  }
19934
+ storeRecords(
19935
+ next,
19936
+ SHARED_BENCHMARKS_KEY,
19937
+ foldBenchmarkWrites(
19938
+ `${label4} "shared"`,
19939
+ read.shared.benchmarks,
19940
+ store[SHARED_BENCHMARKS_KEY],
19941
+ "session",
19942
+ scope
19943
+ )
19944
+ );
19128
19945
  for (const [capId, sliceValue] of Object.entries(result.shared)) {
19129
19946
  const base2 = next[capId];
19130
19947
  const value = sliceValue && typeof sliceValue === "object" && !Array.isArray(sliceValue) && base2 && typeof base2 === "object" && !Array.isArray(base2) ? {
@@ -19148,6 +19965,11 @@ function applyAggregateResult(read, contextsBefore, engineIdentifier, phase, sco
19148
19965
  context[capId] = structuredClone(store[capId]);
19149
19966
  }
19150
19967
  }
19968
+ if (SHARED_BENCHMARKS_KEY in store) {
19969
+ context[SHARED_BENCHMARKS_KEY] = structuredClone(store[SHARED_BENCHMARKS_KEY]);
19970
+ } else {
19971
+ delete context[SHARED_BENCHMARKS_KEY];
19972
+ }
19151
19973
  }
19152
19974
  return { contexts, store };
19153
19975
  }
@@ -20807,6 +21629,7 @@ var GameExecutor = class {
20807
21629
  * contexts it was handed (§11). Read by the session straight after a tick.
20808
21630
  */
20809
21631
  lastTickCompletion = [];
21632
+ warnings = [];
20810
21633
  waitingRoomOpen = false;
20811
21634
  deps;
20812
21635
  /** `meta`, the roster, callbacks and bounds: what every logic call shares. */
@@ -20969,24 +21792,74 @@ var GameExecutor = class {
20969
21792
  }
20970
21793
  /** How a result folds into a board, for the game as it is loaded now. */
20971
21794
  composition() {
21795
+ const declared = new Set(this.engine?.definition.benchmarks ?? []);
21796
+ const assessed = new Set(this.engine?.definition.assessments ?? []);
20972
21797
  return {
20973
21798
  defaults: this.capabilityDefaults,
20974
21799
  sharedIds: new Set(this.getSharedCapabilityIds()),
20975
- engine: this.engine?.definition ?? {}
21800
+ engine: this.engine?.definition ?? {},
21801
+ benchmarks: new Map(
21802
+ (this.config?.benchmarks ?? []).filter((benchmark) => declared.has(benchmark.definition.identifier)).map((benchmark) => [benchmark.definition.identifier, benchmark.definition])
21803
+ ),
21804
+ warn: (message) => {
21805
+ logger.warn(message);
21806
+ this.warnings.push(message);
21807
+ },
21808
+ assessments: new Map(
21809
+ (this.config?.assessments ?? []).filter((assessment) => assessed.has(assessment.definition.identifier)).map((assessment) => [assessment.definition.identifier, assessment.definition])
21810
+ ),
21811
+ participantIdsOf: (teamId) => new Set(this.calls.participantsOn([teamId]).map((participant) => participant.id))
21812
+ };
21813
+ }
21814
+ /** Whether the engine declares assessments, and so is handed and may return them (§6.17). */
21815
+ writesAssessments() {
21816
+ return (this.engine?.definition.assessments?.length ?? 0) > 0;
21817
+ }
21818
+ /** Whether the engine declares benchmarks, and so is handed and may return them (§6.16). */
21819
+ writesBenchmarks() {
21820
+ return (this.engine?.definition.benchmarks?.length ?? 0) > 0;
21821
+ }
21822
+ /**
21823
+ * The `benchmarks` and `assessments` arguments of an `Init` or `Run` on
21824
+ * `context`: its team's records and results, each passed only to an engine
21825
+ * that declares some.
21826
+ */
21827
+ recordArgs(context) {
21828
+ return {
21829
+ ...this.writesBenchmarks() ? {
21830
+ benchmarks: structuredClone(
21831
+ context[BENCHMARKS_KEY] ?? {}
21832
+ )
21833
+ } : {},
21834
+ ...this.writesAssessments() ? {
21835
+ assessments: structuredClone(
21836
+ context[ASSESSMENTS_KEY] ?? {}
21837
+ )
21838
+ } : {}
20976
21839
  };
20977
21840
  }
21841
+ /**
21842
+ * What went wrong without failing anything since the last call, such as a
21843
+ * benchmark write that was dropped (§6.16), for the operation to report.
21844
+ */
21845
+ takeWarnings() {
21846
+ const warnings = this.warnings;
21847
+ this.warnings = [];
21848
+ return warnings;
21849
+ }
20978
21850
  /**
20979
21851
  * Fold an aggregate result into the team contexts and the canonical store.
20980
21852
  * See {@link applyAggregateResult}.
20981
21853
  */
20982
- applyAggregateResult(read, contextsBefore, engineIdentifier, phase) {
21854
+ applyAggregateResult(read, contextsBefore, engineIdentifier, phase, teamIds) {
20983
21855
  const { contexts, store } = applyAggregateResult(
20984
21856
  read,
20985
21857
  contextsBefore,
20986
21858
  engineIdentifier,
20987
21859
  phase,
20988
21860
  this.composition(),
20989
- this.sharedContext
21861
+ this.sharedContext,
21862
+ teamIds
20990
21863
  );
20991
21864
  this.sharedContext = store;
20992
21865
  return contexts;
@@ -20999,7 +21872,9 @@ var GameExecutor = class {
20999
21872
  declaration,
21000
21873
  this.sharedContext,
21001
21874
  new Set(this.getSharedCapabilityIds()),
21002
- this.calls.participantsOn(identities.map((identity) => identity.teamId))
21875
+ this.calls.participantsOn(identities.map((identity) => identity.teamId)),
21876
+ this.writesBenchmarks(),
21877
+ this.writesAssessments()
21003
21878
  );
21004
21879
  }
21005
21880
  /**
@@ -21182,6 +22057,7 @@ var GameExecutor = class {
21182
22057
  () => run({
21183
22058
  context: projectForLogic(contexts[i], engine.definition),
21184
22059
  state: contexts[i][ENGINE_STATE_KEY],
22060
+ ...this.recordArgs(contexts[i]),
21185
22061
  settings: engineSettings,
21186
22062
  meta: teamMeta[i],
21187
22063
  participants: this.calls.participantsOn([
@@ -21196,10 +22072,18 @@ var GameExecutor = class {
21196
22072
  team: identities[i]
21197
22073
  }
21198
22074
  ),
21199
- "tick"
22075
+ "tick",
22076
+ this.writesBenchmarks(),
22077
+ this.writesAssessments()
21200
22078
  );
21201
22079
  if (read.complete) completed[i] = true;
21202
- contexts[i] = applyEngineResult(label4, read, contextBefore, this.composition());
22080
+ contexts[i] = applyEngineResult(
22081
+ label4,
22082
+ read,
22083
+ contextBefore,
22084
+ this.composition(),
22085
+ identities[i].teamId
22086
+ );
21203
22087
  enforceDeclaredWrites(
21204
22088
  engineIdentifier,
21205
22089
  engine.definition,
@@ -21239,7 +22123,9 @@ var GameExecutor = class {
21239
22123
  { resource: { type: "engine", identifier: engineIdentifier }, tick: tick2 }
21240
22124
  ),
21241
22125
  args.teams.length,
21242
- "tick"
22126
+ "tick",
22127
+ this.writesBenchmarks(),
22128
+ this.writesAssessments()
21243
22129
  );
21244
22130
  result.teams.forEach((team, i) => {
21245
22131
  if (team.complete || result.shared.complete) completed[i] = true;
@@ -21248,7 +22134,8 @@ var GameExecutor = class {
21248
22134
  result,
21249
22135
  contextsBefore,
21250
22136
  engineIdentifier,
21251
- "RunAggregate"
22137
+ "RunAggregate",
22138
+ identities.map((identity) => identity.teamId)
21252
22139
  );
21253
22140
  }
21254
22141
  }
@@ -21327,13 +22214,17 @@ var GameExecutor = class {
21327
22214
  }),
21328
22215
  { resource: { type: "engine", identifier: engineIdentifier } }
21329
22216
  ),
21330
- args.teams.length
22217
+ args.teams.length,
22218
+ "init",
22219
+ this.writesBenchmarks(),
22220
+ this.writesAssessments()
21331
22221
  );
21332
22222
  contexts = this.applyAggregateResult(
21333
22223
  result,
21334
22224
  contextsBefore,
21335
22225
  engineIdentifier,
21336
- "InitAggregate"
22226
+ "InitAggregate",
22227
+ identities.map((identity) => identity.teamId)
21337
22228
  );
21338
22229
  }
21339
22230
  this.context = { ...contexts[0] };
@@ -21369,6 +22260,7 @@ var GameExecutor = class {
21369
22260
  () => initFn({
21370
22261
  context: projectForLogic(before, engine.definition),
21371
22262
  state: void 0,
22263
+ ...this.recordArgs(before),
21372
22264
  settings,
21373
22265
  meta: { ...sessionMeta, ...identity },
21374
22266
  participants: this.calls.participantsOn([identity.teamId]),
@@ -21378,9 +22270,18 @@ var GameExecutor = class {
21378
22270
  resource: { type: "engine", identifier: engine.definition.identifier },
21379
22271
  team: identity
21380
22272
  }
21381
- )
22273
+ ),
22274
+ "init",
22275
+ this.writesBenchmarks(),
22276
+ this.writesAssessments()
22277
+ );
22278
+ const context = applyEngineResult(
22279
+ label4,
22280
+ after,
22281
+ before,
22282
+ this.composition(),
22283
+ identity.teamId
21382
22284
  );
21383
- const context = applyEngineResult(label4, after, before, this.composition());
21384
22285
  enforceDeclaredWrites(
21385
22286
  engine.definition.identifier,
21386
22287
  engine.definition,
@@ -21419,7 +22320,11 @@ var GameExecutor = class {
21419
22320
  */
21420
22321
  setContext(context) {
21421
22322
  this.context = { ...context };
21422
- for (const capId of [...this.getSharedCapabilityIds(), SHARED_ENGINE_STATE_KEY]) {
22323
+ for (const capId of [
22324
+ ...this.getSharedCapabilityIds(),
22325
+ SHARED_ENGINE_STATE_KEY,
22326
+ SHARED_BENCHMARKS_KEY
22327
+ ]) {
21423
22328
  if (capId in context) {
21424
22329
  this.sharedContext[capId] = structuredClone(context[capId]);
21425
22330
  }
@@ -21625,6 +22530,7 @@ var GameExecutor = class {
21625
22530
  () => initFn({
21626
22531
  context: projectForLogic(this.context, engine.definition),
21627
22532
  state: void 0,
22533
+ ...this.recordArgs(this.context),
21628
22534
  settings: engineSettings,
21629
22535
  meta: teamMeta,
21630
22536
  participants: this.calls.participantsOn([teamMeta.teamId]),
@@ -21634,13 +22540,17 @@ var GameExecutor = class {
21634
22540
  resource: { type: "engine", identifier: engineIdentifier },
21635
22541
  team: { teamId: teamMeta.teamId, index: teamMeta.index }
21636
22542
  }
21637
- )
22543
+ ),
22544
+ "init",
22545
+ this.writesBenchmarks(),
22546
+ this.writesAssessments()
21638
22547
  );
21639
22548
  this.context = applyEngineResult(
21640
22549
  initLabel,
21641
22550
  initResult,
21642
22551
  contextBefore,
21643
- this.composition()
22552
+ this.composition(),
22553
+ teamMeta.teamId
21644
22554
  );
21645
22555
  enforceDeclaredWrites(
21646
22556
  engineIdentifier,
@@ -21683,13 +22593,17 @@ var GameExecutor = class {
21683
22593
  }),
21684
22594
  { resource: { type: "engine", identifier: engineIdentifier } }
21685
22595
  ),
21686
- 1
22596
+ 1,
22597
+ "init",
22598
+ this.writesBenchmarks(),
22599
+ this.writesAssessments()
21687
22600
  );
21688
22601
  [this.context] = this.applyAggregateResult(
21689
22602
  result,
21690
22603
  [aggregateContextBefore],
21691
22604
  engineIdentifier,
21692
- "InitAggregate"
22605
+ "InitAggregate",
22606
+ ["team-1"]
21693
22607
  );
21694
22608
  }
21695
22609
  }
@@ -23497,8 +24411,8 @@ function remarkGuideSettings(options) {
23497
24411
  if (!parent || typeof index3 !== "number") return;
23498
24412
  const directive2 = node2;
23499
24413
  if (directive2.type === "containerDirective" && directive2.name === "when") {
23500
- const outcome = evaluateWhen(options.settings, directive2.attributes ?? {});
23501
- const replacement = "error" in outcome ? [errorBlock(outcome.error)] : outcome.show ? directive2.children : [];
24414
+ const outcome3 = evaluateWhen(options.settings, directive2.attributes ?? {});
24415
+ const replacement = "error" in outcome3 ? [errorBlock(outcome3.error)] : outcome3.show ? directive2.children : [];
23502
24416
  parent.children.splice(index3, 1, ...replacement);
23503
24417
  return [SKIP, index3];
23504
24418
  }
@@ -23611,6 +24525,137 @@ function readEffectiveGuide(guide, root2, resolved) {
23611
24525
  return { identifier: guide.definition.identifier, locales, chapters, settings };
23612
24526
  }
23613
24527
 
24528
+ // cli/core/assessment-reports.ts
24529
+ function assessmentAudience(query) {
24530
+ if (query.audience !== "own") return { kind: "all" };
24531
+ if (query.participantId !== void 0 && query.teamId !== void 0) {
24532
+ return { kind: "participant", teamId: query.teamId, participantId: query.participantId };
24533
+ }
24534
+ if (query.viewerRole === "observer" && query.teamId !== void 0) {
24535
+ return { kind: "team", teamId: query.teamId };
24536
+ }
24537
+ return null;
24538
+ }
24539
+ function answerAssessment(input) {
24540
+ const { query } = input;
24541
+ const assessment = input.assessments.find(
24542
+ (entry) => entry.definition.identifier === query.identifier
24543
+ );
24544
+ if (!assessment) {
24545
+ return {
24546
+ type: "assessmentFailure",
24547
+ error: `The package declares no assessment "${query.identifier}"`
24548
+ };
24549
+ }
24550
+ const audience = assessmentAudience(query);
24551
+ if (audience === null) {
24552
+ return {
24553
+ type: "assessmentFailure",
24554
+ error: "getAssessment from a player surface needs the participant or observer behind it"
24555
+ };
24556
+ }
24557
+ const settings = input.settings[ASSESSMENTS_SETTINGS];
24558
+ const report = buildAssessmentReport({
24559
+ definition: assessment.definition,
24560
+ bands: resolveAssessmentBands(assessment.definition, settings?.[query.identifier]),
24561
+ teams: input.teams.map((team) => ({
24562
+ teamId: team.teamId,
24563
+ records: team.context?.[ASSESSMENTS_KEY]?.[query.identifier],
24564
+ complete: team.complete
24565
+ })),
24566
+ participants: input.participants,
24567
+ audience
24568
+ });
24569
+ return { type: "assessment", report };
24570
+ }
24571
+
24572
+ // cli/core/benchmark-samples.ts
24573
+ import { readFile as readFile5, stat as stat3 } from "node:fs/promises";
24574
+ import { join as join10 } from "node:path";
24575
+ function benchmarkSamplePath(identifier) {
24576
+ return join10("benchmarks", identifier, "sample.json");
24577
+ }
24578
+ var NUMERIC_FIGURES = ["mean", "min", "max", "p10", "p25", "p50", "p75", "p90"];
24579
+ function isRecord4(value) {
24580
+ return typeof value === "object" && value !== null && !Array.isArray(value);
24581
+ }
24582
+ function isCount(value) {
24583
+ return typeof value === "number" && Number.isInteger(value) && value >= 0;
24584
+ }
24585
+ function fieldProblem(name, value) {
24586
+ if (!isRecord4(value)) return `fields.${name} must be an object`;
24587
+ if (!isCount(value.count)) return `fields.${name}.count must be a whole number of at least 0`;
24588
+ if (value.kind === "number") {
24589
+ for (const figure of NUMERIC_FIGURES) {
24590
+ const v = value[figure];
24591
+ if (v !== void 0 && (typeof v !== "number" || !Number.isFinite(v))) {
24592
+ return `fields.${name}.${figure} must be a number`;
24593
+ }
24594
+ }
24595
+ return null;
24596
+ }
24597
+ if (value.kind === "choice") {
24598
+ if (!isRecord4(value.options)) return `fields.${name}.options must be an object`;
24599
+ for (const [option, count] of Object.entries(value.options)) {
24600
+ if (!isCount(count)) {
24601
+ return `fields.${name}.options.${option} must be a whole number of at least 0`;
24602
+ }
24603
+ }
24604
+ return null;
24605
+ }
24606
+ return `fields.${name}.kind must be "number" or "choice"`;
24607
+ }
24608
+ function benchmarkSampleProblem(sample) {
24609
+ if (!isRecord4(sample)) return "it must be an object";
24610
+ if (sample.scope !== "organisation" && sample.scope !== "global") {
24611
+ return 'scope must be "organisation" or "global"';
24612
+ }
24613
+ if (!isRecord4(sample.fields)) return "fields must be an object of field statistics";
24614
+ for (const [name, value] of Object.entries(sample.fields)) {
24615
+ const problem = fieldProblem(name, value);
24616
+ if (problem) return problem;
24617
+ }
24618
+ return null;
24619
+ }
24620
+ async function isDirectory(path3) {
24621
+ try {
24622
+ return (await stat3(path3)).isDirectory();
24623
+ } catch {
24624
+ return false;
24625
+ }
24626
+ }
24627
+ async function isDeclared(packagePath, identifier, declared) {
24628
+ if (!/^[A-Za-z0-9_-]+$/.test(identifier)) return false;
24629
+ if (declared && declared.length > 0) return declared.includes(identifier);
24630
+ return isDirectory(join10(packagePath, "benchmarks", identifier));
24631
+ }
24632
+ async function answerBenchmarkFromSample(options) {
24633
+ const { packagePath, identifier, where: where3, declared } = options;
24634
+ if (!await isDeclared(packagePath, identifier, declared)) {
24635
+ throw new Error(`No benchmark "${identifier}" is declared`);
24636
+ }
24637
+ const relative8 = benchmarkSamplePath(identifier);
24638
+ let text5;
24639
+ try {
24640
+ text5 = await readFile5(join10(packagePath, relative8), "utf-8");
24641
+ } catch (error) {
24642
+ if (error.code === "ENOENT") return null;
24643
+ throw error;
24644
+ }
24645
+ let sample;
24646
+ try {
24647
+ sample = JSON.parse(text5);
24648
+ } catch (error) {
24649
+ throw new Error(
24650
+ `${relative8} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`
24651
+ );
24652
+ }
24653
+ const problem = benchmarkSampleProblem(sample);
24654
+ if (problem) throw new Error(`${relative8} is not a benchmark sample: ${problem}`);
24655
+ const { scope, fields } = sample;
24656
+ return { scope, matched: { ...where3[0] }, fields };
24657
+ }
24658
+
23614
24659
  // cli/core/clock.ts
23615
24660
  var systemClock = {
23616
24661
  now: () => Date.now(),
@@ -24063,9 +25108,9 @@ function withLogicError(result, logicError) {
24063
25108
  return logicError ? { ...result, logicError } : result;
24064
25109
  }
24065
25110
  var RefusedError = class extends Error {
24066
- constructor(message, outcome) {
25111
+ constructor(message, outcome3) {
24067
25112
  super(message);
24068
- this.outcome = outcome;
25113
+ this.outcome = outcome3;
24069
25114
  }
24070
25115
  outcome;
24071
25116
  };
@@ -24083,12 +25128,12 @@ function withStale(result, error) {
24083
25128
  function markIfLogic(error, failure) {
24084
25129
  return failure ? markLogicFailure(error, failure) : error;
24085
25130
  }
24086
- function refuseIfArmed(faults, fault, outcome) {
25131
+ function refuseIfArmed(faults, fault, outcome3) {
24087
25132
  const fired = faults.fire(fault);
24088
25133
  if (!fired) return;
24089
25134
  throw new RefusedError(
24090
25135
  `Injected ${fault}`,
24091
- fired.reason === void 0 ? outcome : { ...outcome, message: fired.reason }
25136
+ fired.reason === void 0 ? outcome3 : { ...outcome3, message: fired.reason }
24092
25137
  );
24093
25138
  }
24094
25139
 
@@ -24806,6 +25851,49 @@ function undoOneTeam(host, position2) {
24806
25851
  return true;
24807
25852
  }
24808
25853
 
25854
+ // cli/core/assessment-moves.ts
25855
+ function participantLevelAssessments(assessments) {
25856
+ return assessments.filter((entry) => entry.definition.level === "participant").map((entry) => entry.definition.identifier);
25857
+ }
25858
+ function recordsOf(context) {
25859
+ return context?.[ASSESSMENTS_KEY] ?? {};
25860
+ }
25861
+ function withRecords(context, records) {
25862
+ const next = { ...context };
25863
+ const kept = Object.fromEntries(
25864
+ Object.entries(records).filter(([, byId]) => Object.keys(byId ?? {}).length > 0)
25865
+ );
25866
+ if (Object.keys(kept).length > 0) next[ASSESSMENTS_KEY] = kept;
25867
+ else delete next[ASSESSMENTS_KEY];
25868
+ return next;
25869
+ }
25870
+ function settleAssessmentRecords(input) {
25871
+ const { teamIds, teamOf: teamOf2, identifiers, prefer } = input;
25872
+ const contexts = [...input.contexts];
25873
+ if (identifiers.length === 0) return contexts;
25874
+ const records = contexts.map((context) => structuredClone(recordsOf(context)));
25875
+ const positionOf = new Map(teamIds.map((teamId, position2) => [teamId, position2]));
25876
+ let moved = false;
25877
+ records.forEach((teamRecords, position2) => {
25878
+ for (const identifier of identifiers) {
25879
+ const byId = teamRecords[identifier];
25880
+ if (!byId) continue;
25881
+ for (const [participantId, record2] of Object.entries(byId)) {
25882
+ const destination = positionOf.get(teamOf2(participantId) ?? "");
25883
+ if (destination === void 0 || destination === position2) continue;
25884
+ delete byId[participantId];
25885
+ const target = records[destination][identifier] ??= {};
25886
+ if (participantId === prefer || !(participantId in target)) {
25887
+ target[participantId] = record2;
25888
+ }
25889
+ moved = true;
25890
+ }
25891
+ }
25892
+ });
25893
+ if (!moved) return input.contexts;
25894
+ return contexts.map((context, position2) => withRecords(context, records[position2]));
25895
+ }
25896
+
24809
25897
  // cli/core/team-names.ts
24810
25898
  function pickLocalised(entry, locale) {
24811
25899
  if (!entry) return void 0;
@@ -25141,6 +26229,7 @@ var SessionRoster = class {
25141
26229
  if (fromTeamId === toTeamId) return void 0;
25142
26230
  const moved = this.host.participants.move(fromTeamId, participantId, toTeamId);
25143
26231
  if (!moved) throw new DeniedError("The participant could not be moved");
26232
+ this.settleAssessments(participantId);
25144
26233
  const move = { fromTeamId, toTeamId };
25145
26234
  await this.fireHook("participantMove", moved, {
25146
26235
  teamId: fromTeamId,
@@ -25149,6 +26238,25 @@ var SessionRoster = class {
25149
26238
  await this.fireHook("participantMove", moved, { payload: { ...move, phase: "arrival" } });
25150
26239
  return void 0;
25151
26240
  }
26241
+ /**
26242
+ * Move participant-level assessment results to the team each participant
26243
+ * is on now (§6.17.2): after a move, with `prefer` the one who moved, and
26244
+ * after an undo, which restores results to the teams that held them then.
26245
+ */
26246
+ settleAssessments(prefer) {
26247
+ const { executor, state: state2 } = this.host;
26248
+ const identifiers = participantLevelAssessments(executor.getConfig()?.assessments ?? []);
26249
+ if (identifiers.length === 0) return;
26250
+ const contexts = state2.getTeamContexts();
26251
+ const settled = settleAssessmentRecords({
26252
+ contexts,
26253
+ teamIds: state2.getTeamIndexes().map((index3) => `team-${index3 + 1}`),
26254
+ teamOf: (id) => this.findParticipantTeam(id),
26255
+ identifiers,
26256
+ prefer
26257
+ });
26258
+ if (settled !== contexts) state2.setTeamContexts(settled);
26259
+ }
25152
26260
  findParticipantTeam(participantId) {
25153
26261
  for (const index3 of this.host.state.getTeamIndexes()) {
25154
26262
  const teamId = `team-${index3 + 1}`;
@@ -25210,7 +26318,7 @@ function insertAt(values, position2, value) {
25210
26318
 
25211
26319
  // cli/execution/scenario-gates.ts
25212
26320
  import { existsSync as existsSync8 } from "fs";
25213
- import { readFile as readFile5 } from "fs/promises";
26321
+ import { readFile as readFile6 } from "fs/promises";
25214
26322
  var SCENARIO_VALIDATION = "scenario-validation";
25215
26323
  var SCENARIO_FILES = "scenario-files";
25216
26324
  var SESSION_VALIDATION = "session-validation";
@@ -25243,7 +26351,7 @@ async function runScenarioGates(options) {
25243
26351
  if (!hasScenarioGate(config)) return [];
25244
26352
  const loader = options.loader ?? new LogicLoader(options.packagePath, {
25245
26353
  transpile: Transpile,
25246
- fs: { existsSync: existsSync8, readFile: readFile5 }
26354
+ fs: { existsSync: existsSync8, readFile: readFile6 }
25247
26355
  });
25248
26356
  const resolved = resolveSettingsLayers(
25249
26357
  config,
@@ -25605,7 +26713,9 @@ var IDLE_TIMER = {
25605
26713
  pausedAt: null,
25606
26714
  pausedMs: 0,
25607
26715
  extendedMs: 0,
25608
- scheduleStartedAt: null
26716
+ scheduleStartedAt: null,
26717
+ dormant: false,
26718
+ dormantAt: null
25609
26719
  };
25610
26720
  function scheduleFor(result, now) {
25611
26721
  const problem = validateTickControllerResult2(result, { now });
@@ -25651,6 +26761,8 @@ var TickTimer = class {
25651
26761
  pausedMs = 0;
25652
26762
  scheduleStartedAt = null;
25653
26763
  extendedMs = 0;
26764
+ /** When the session went dormant (§11.4a), or null while it is not. */
26765
+ dormantAt = null;
25654
26766
  /** The answer the current schedule was built from, to tell a re-evaluation that changed nothing. */
25655
26767
  answer = null;
25656
26768
  /**
@@ -25690,7 +26802,7 @@ var TickTimer = class {
25690
26802
  this.intervalMs = schedule.intervalMs;
25691
26803
  this.usedNextTickAt = schedule.usedNextTickAt;
25692
26804
  this.scheduleStartedAt ??= now;
25693
- if (this.paused) {
26805
+ if (this.paused || this.dormantAt !== null) {
25694
26806
  this.remainingMs = schedule.delayMs;
25695
26807
  return schedule.clamped;
25696
26808
  }
@@ -25702,8 +26814,32 @@ var TickTimer = class {
25702
26814
  const now = this.clock.now();
25703
26815
  this.paused = true;
25704
26816
  this.pausedAt = now;
25705
- this.remainingMs = this.dueAt === null ? null : Math.max(0, this.dueAt - now);
25706
- this.cancelPending();
26817
+ if (this.dormantAt === null) this.hold(now);
26818
+ }
26819
+ /**
26820
+ * Suspend automatic ticking because the session was left unattended
26821
+ * (§11.4a). Held like a pause, but separate from one: waking never ends a
26822
+ * facilitator's pause.
26823
+ */
26824
+ suspend() {
26825
+ if (this.dormantAt !== null) return;
26826
+ const now = this.clock.now();
26827
+ this.dormantAt = now;
26828
+ if (!this.paused) this.hold(now);
26829
+ }
26830
+ /**
26831
+ * Wake from dormancy (§11.4a), resuming as from a pause (§11.4). The
26832
+ * dormant time joins `pausedMs`, except where a facilitator's pause
26833
+ * already covers it. A timer the facilitator paused stays paused.
26834
+ */
26835
+ wake() {
26836
+ if (this.dormantAt === null) return "idle";
26837
+ const now = this.clock.now();
26838
+ const dormantAt = this.dormantAt;
26839
+ this.dormantAt = null;
26840
+ if (this.paused) return "idle";
26841
+ this.pausedMs += now - dormantAt;
26842
+ return this.continue(now);
25707
26843
  }
25708
26844
  /**
25709
26845
  * Resume (§11.4). Interval mode continues from the time that was left;
@@ -25716,6 +26852,11 @@ var TickTimer = class {
25716
26852
  this.paused = false;
25717
26853
  if (this.pausedAt !== null) this.pausedMs += now - this.pausedAt;
25718
26854
  this.pausedAt = null;
26855
+ if (this.dormantAt !== null) return "idle";
26856
+ return this.continue(now);
26857
+ }
26858
+ /** Pick a held schedule back up, after a pause or dormancy. */
26859
+ continue(now) {
25719
26860
  if (!this.enabled) return "idle";
25720
26861
  if (this.usedNextTickAt) {
25721
26862
  this.remainingMs = null;
@@ -25735,6 +26876,9 @@ var TickTimer = class {
25735
26876
  if (this.paused) {
25736
26877
  return "The timer is paused, so there is no scheduled tick to move. Resume it first";
25737
26878
  }
26879
+ if (this.dormantAt !== null) {
26880
+ return "The session is dormant, so there is no scheduled tick to move";
26881
+ }
25738
26882
  if (this.dueAt === null) return "No tick is scheduled, so there is no deadline to move";
25739
26883
  const now = this.clock.now();
25740
26884
  const target = Math.max(now, this.dueAt + ms);
@@ -25753,17 +26897,25 @@ var TickTimer = class {
25753
26897
  this.intervalMs = null;
25754
26898
  }
25755
26899
  state() {
26900
+ const held = this.paused || this.dormantAt !== null;
25756
26901
  return {
25757
26902
  enabled: this.enabled,
25758
26903
  paused: this.paused,
25759
- nextTickAt: this.paused ? null : this.dueAt,
25760
- intervalMs: this.enabled && !this.paused ? this.intervalMs : null,
26904
+ nextTickAt: held ? null : this.dueAt,
26905
+ intervalMs: this.enabled && !held ? this.intervalMs : null,
25761
26906
  pausedAt: this.pausedAt,
25762
26907
  pausedMs: this.pausedMs,
25763
26908
  extendedMs: this.extendedMs,
25764
- scheduleStartedAt: this.scheduleStartedAt
26909
+ scheduleStartedAt: this.scheduleStartedAt,
26910
+ dormant: this.dormantAt !== null,
26911
+ dormantAt: this.dormantAt
25765
26912
  };
25766
26913
  }
26914
+ /** Keep what is left of this window, and stop the pending tick. */
26915
+ hold(now) {
26916
+ this.remainingMs = this.dueAt === null ? null : Math.max(0, this.dueAt - now);
26917
+ this.cancelPending();
26918
+ }
25767
26919
  arm(at) {
25768
26920
  this.cancelPending();
25769
26921
  this.dueAt = at;
@@ -25782,15 +26934,70 @@ var TickTimer = class {
25782
26934
 
25783
26935
  // cli/core/session-timers.ts
25784
26936
  var COHORT = -1;
26937
+ var DORMANT_AFTER_MS = 24 * 60 * 60 * 1e3;
26938
+ var DORMANT_AFTER_TICKS = 100;
25785
26939
  var SessionTimers = class {
25786
26940
  constructor(host) {
25787
26941
  this.host = host;
26942
+ this.lastActivityAt = host.clock.now();
25788
26943
  }
25789
26944
  host;
25790
26945
  /** True while a tick runs, so a timer firing then is dropped (§11.1). */
25791
26946
  ticking = false;
25792
26947
  /** Automatic tick timers, keyed by team index, or {@link COHORT} (§11). */
25793
26948
  timers = /* @__PURE__ */ new Map();
26949
+ /** When the session went dormant (§11.4a), or null while it is not. */
26950
+ dormantAt = null;
26951
+ /** When anything outside the host last used the session (§11.4a). */
26952
+ lastActivityAt;
26953
+ /** Automatic ticks since then, every team's together (§11.4a). */
26954
+ unattendedTicks = 0;
26955
+ /** Surfaces and console pages open on the session, which keep it awake. */
26956
+ openSurfaces = 0;
26957
+ /** Whether automatic ticking is suspended because the session was unattended. */
26958
+ get dormant() {
26959
+ return this.dormantAt !== null;
26960
+ }
26961
+ /**
26962
+ * Something outside the host used the session (§11.4a): restart the
26963
+ * clock, and wake the session if it is dormant. Interval-mode timers pick
26964
+ * up at once; what is returned re-asks the controller for scheduled-mode
26965
+ * ones, for the caller to queue ahead of the activity itself. Null when
26966
+ * nothing woke.
26967
+ */
26968
+ noteActivity() {
26969
+ this.lastActivityAt = this.host.clock.now();
26970
+ this.unattendedTicks = 0;
26971
+ if (this.dormantAt === null) return null;
26972
+ this.dormantAt = null;
26973
+ const reevaluate = this.groups().filter(
26974
+ (group) => this.timers.get(group.key)?.wake() === "re-evaluate"
26975
+ );
26976
+ return async () => {
26977
+ for (const group of reevaluate) await this.evaluate(group);
26978
+ };
26979
+ }
26980
+ /**
26981
+ * How many surfaces are open on the session. Opening one is activity, and
26982
+ * while any is open the session stays awake: the dev server counts an
26983
+ * idle open surface as use, which the specification leaves to the host.
26984
+ */
26985
+ surfacesOpen(count) {
26986
+ const opened = count > this.openSurfaces;
26987
+ const lastClosed = count === 0 && this.openSurfaces > 0;
26988
+ this.openSurfaces = count;
26989
+ return opened || lastClosed ? this.noteActivity() : null;
26990
+ }
26991
+ /**
26992
+ * Suspend automatic ticking now (§11.4a), whether or not the minimums
26993
+ * have passed: the dev server's way to show an author a dormant session
26994
+ * without waiting a day.
26995
+ */
26996
+ suspend() {
26997
+ if (this.dormantAt !== null) return;
26998
+ this.dormantAt = this.host.clock.now();
26999
+ for (const timer of this.timers.values()) timer.suspend();
27000
+ }
25794
27001
  /** Cancel every timer, for a session that is stopping. */
25795
27002
  stop() {
25796
27003
  for (const timer of this.timers.values()) timer.cancel();
@@ -25915,6 +27122,7 @@ var SessionTimers = class {
25915
27122
  let timer = this.timers.get(key);
25916
27123
  if (!timer) {
25917
27124
  timer = new TickTimer(this.host.clock, () => void this.onFired(key));
27125
+ if (this.dormantAt !== null) timer.suspend();
25918
27126
  this.timers.set(key, timer);
25919
27127
  }
25920
27128
  return timer;
@@ -26015,18 +27223,191 @@ var SessionTimers = class {
26015
27223
  type: "tick",
26016
27224
  ...key === COHORT ? {} : { teamIndex: key }
26017
27225
  });
26018
- if (result.ok) return;
27226
+ if (result.ok) {
27227
+ this.unattendedTicks += 1;
27228
+ this.suspendIfUnattended();
27229
+ return;
27230
+ }
26019
27231
  await this.host.enqueue(async () => {
26020
27232
  const group = this.groups().find((candidate) => candidate.key === key);
26021
27233
  if (group) await this.evaluate(group);
26022
27234
  this.host.emitState("timer");
26023
27235
  });
26024
27236
  }
27237
+ /**
27238
+ * Go dormant once nothing has used the session for both minimums, and no
27239
+ * surface is open (§11.4a). Judged after an automatic tick, since nothing
27240
+ * else happens to a session nobody is using.
27241
+ */
27242
+ suspendIfUnattended() {
27243
+ if (this.dormantAt !== null || this.openSurfaces > 0) return;
27244
+ if (this.unattendedTicks < DORMANT_AFTER_TICKS) return;
27245
+ if (this.host.clock.now() - this.lastActivityAt < DORMANT_AFTER_MS) return;
27246
+ this.suspend();
27247
+ this.host.emitState("dormant");
27248
+ }
26025
27249
  };
26026
27250
 
26027
27251
  // cli/core/session-writes.ts
26028
27252
  import { isDeepStrictEqual as isDeepStrictEqual3 } from "util";
26029
27253
 
27254
+ // cli/validation/assessment-validation.ts
27255
+ var MAX_BANDS = 10;
27256
+ function outcome() {
27257
+ return { errors: [], warnings: [], findings: [] };
27258
+ }
27259
+ function addError(result, finding) {
27260
+ result.errors.push(finding.hint ? `${finding.message}. ${finding.hint}` : finding.message);
27261
+ result.findings.push({ severity: "error", ...finding });
27262
+ }
27263
+ function bandsProblem(definition3, bands) {
27264
+ if (bands.length === 0) return null;
27265
+ if (bands[0].from !== definition3.min) {
27266
+ return `the first band, "${bands[0].id}", starts at ${bands[0].from} rather than at the minimum score, ${definition3.min}`;
27267
+ }
27268
+ for (let i = 1; i < bands.length; i++) {
27269
+ if (bands[i].from <= bands[i - 1].from) {
27270
+ return `band "${bands[i].id}" starts at ${bands[i].from}, not above "${bands[i - 1].id}" at ${bands[i - 1].from}; bands ascend in the order they are listed`;
27271
+ }
27272
+ }
27273
+ const last = bands[bands.length - 1];
27274
+ if (last.from > definition3.max) {
27275
+ return `band "${last.id}" starts at ${last.from}, above the maximum score, ${definition3.max}`;
27276
+ }
27277
+ return null;
27278
+ }
27279
+ function resolvedBandProblems(assessments, resolved) {
27280
+ const settings = resolved[ASSESSMENTS_SETTINGS];
27281
+ const problems = [];
27282
+ for (const { definition: definition3 } of assessments) {
27283
+ const problem = bandsProblem(
27284
+ definition3,
27285
+ resolveAssessmentBands(definition3, settings?.[definition3.identifier])
27286
+ );
27287
+ if (problem !== null) {
27288
+ problems.push(
27289
+ `The bands of assessment "${definition3.identifier}" would be out of order: ${problem}`
27290
+ );
27291
+ }
27292
+ }
27293
+ return problems;
27294
+ }
27295
+ function validateAssessment(assessment, config) {
27296
+ const result = outcome();
27297
+ const { definition: definition3 } = assessment;
27298
+ const { identifier } = definition3;
27299
+ const file = bundleFileOf("assessment", identifier);
27300
+ const resource = { type: "assessment", identifier };
27301
+ if (!(config.requires ?? []).includes(ASSESSMENTS_FEATURE)) {
27302
+ addError(result, {
27303
+ code: "FEATURE_UNDECLARED",
27304
+ message: `Assessment "${identifier}" needs the \`${ASSESSMENTS_FEATURE}\` feature, but \`requires\` does not list it`,
27305
+ hint: `Add "${ASSESSMENTS_FEATURE}" to \`requires\` in seriousgaming.sdk.json, so a runtime that cannot hold results refuses the package rather than failing the first round that scores one`,
27306
+ file: MANIFEST_FILE,
27307
+ pointer: pointerOf("requires"),
27308
+ resource
27309
+ });
27310
+ }
27311
+ if (!(definition3.max > definition3.min)) {
27312
+ addError(result, {
27313
+ code: "PACKAGE_INVALID",
27314
+ message: `Assessment "${identifier}" has a maximum score of ${definition3.max}, which is not above its minimum, ${definition3.min}`,
27315
+ hint: 'Set "max" above "min"',
27316
+ file,
27317
+ pointer: pointerOf("definition", "max"),
27318
+ resource
27319
+ });
27320
+ return result;
27321
+ }
27322
+ if ((definition3.bands?.length ?? 0) > MAX_BANDS) {
27323
+ addError(result, {
27324
+ code: "PACKAGE_INVALID",
27325
+ message: `Assessment "${identifier}" declares ${definition3.bands?.length} bands, more than the ${MAX_BANDS} an assessment may have`,
27326
+ hint: "Merge neighbouring bands",
27327
+ file,
27328
+ pointer: pointerOf("definition", "bands"),
27329
+ resource
27330
+ });
27331
+ }
27332
+ const ids = (definition3.bands ?? []).map((band) => band.id);
27333
+ const duplicate = ids.find((id, index3) => ids.indexOf(id) !== index3);
27334
+ if (duplicate !== void 0) {
27335
+ addError(result, {
27336
+ code: "PACKAGE_INVALID",
27337
+ message: `Assessment "${identifier}" declares band "${duplicate}" more than once`,
27338
+ hint: "Give each band its own id",
27339
+ file,
27340
+ pointer: pointerOf("definition", "bands"),
27341
+ resource
27342
+ });
27343
+ }
27344
+ const declaredProblem = bandsProblem(definition3, resolveAssessmentBands(definition3));
27345
+ if (declaredProblem !== null) {
27346
+ addError(result, {
27347
+ code: "PACKAGE_INVALID",
27348
+ message: `Assessment "${identifier}": ${declaredProblem}`,
27349
+ hint: 'List the bands lowest first, the first starting at "min", each "from" above the last and no higher than "max"',
27350
+ file,
27351
+ pointer: pointerOf("definition", "bands"),
27352
+ resource
27353
+ });
27354
+ }
27355
+ if (!(config.engine?.definition.assessments?.includes(identifier) ?? false)) {
27356
+ const message = `Assessment "${identifier}" is not in the engine's "assessments", so nothing can score it and it will never hold a result`;
27357
+ result.warnings.push(message);
27358
+ result.findings.push({
27359
+ severity: "warning",
27360
+ code: "ASSESSMENT_UNWRITTEN",
27361
+ message,
27362
+ hint: `Add "${identifier}" to "assessments" in engine/engine.sdk.json, or delete the assessment`,
27363
+ file,
27364
+ resource
27365
+ });
27366
+ }
27367
+ for (const scenario of config.scenarios ?? []) {
27368
+ const settings = scenario.definition.settings?.[ASSESSMENTS_SETTINGS];
27369
+ const override = settings?.[identifier];
27370
+ if (override === void 0) continue;
27371
+ const problem = bandsProblem(definition3, resolveAssessmentBands(definition3, override));
27372
+ if (problem === null) continue;
27373
+ addError(result, {
27374
+ code: "PACKAGE_INVALID",
27375
+ message: `Scenario "${scenario.definition.identifier}" moves the bands of assessment "${identifier}" out of order: ${problem}`,
27376
+ hint: "Keep each band starting above the one before it, the first at the minimum score",
27377
+ file: bundleFileOf("scenario", scenario.definition.identifier),
27378
+ pointer: pointerOf("definition", "settings", ASSESSMENTS_SETTINGS, identifier),
27379
+ resource: { type: "scenario", identifier: scenario.definition.identifier }
27380
+ });
27381
+ }
27382
+ return result;
27383
+ }
27384
+ function validateEngineAssessments(config) {
27385
+ const result = outcome();
27386
+ const declared = new Set((config.assessments ?? []).map((a) => a.definition.identifier));
27387
+ const engine = config.engine;
27388
+ if (engine) {
27389
+ (engine.definition.assessments ?? []).forEach((identifier, index3) => {
27390
+ if (declared.has(identifier)) return;
27391
+ addError(result, {
27392
+ code: "REFERENCE_UNKNOWN",
27393
+ message: `Engine declares assessment "${identifier}", which the package does not have`,
27394
+ hint: `Create it with "new assessment", or remove it from the engine's "assessments"`,
27395
+ file: bundleFileOf("engine", "engine"),
27396
+ pointer: pointerOf("definition", "assessments", index3),
27397
+ resource: { type: "engine", identifier: engine.definition.identifier }
27398
+ });
27399
+ });
27400
+ }
27401
+ if (declared.size > MAX_ASSESSMENTS_PER_GAME) {
27402
+ addError(result, {
27403
+ code: "PACKAGE_INVALID",
27404
+ message: `The game declares ${declared.size} assessments, more than the ${MAX_ASSESSMENTS_PER_GAME} a game may have`,
27405
+ hint: "Fold related measures into one assessment, or remove the ones nobody reports"
27406
+ });
27407
+ }
27408
+ return result;
27409
+ }
27410
+
26030
27411
  // cli/validation/file-settings.ts
26031
27412
  function fileSettingValues(declared, value, path3 = [], root2 = declared) {
26032
27413
  if (!declared || typeof declared !== "object" || !root2) return [];
@@ -26249,11 +27630,16 @@ async function updateSettings(host, command) {
26249
27630
  refuseUnconfiguredSettings(host, command.uiIdentifier, command.payload);
26250
27631
  const existing = executor.getSessionOverrides() ?? {};
26251
27632
  const changed = changedFrom(command.payload, executor.resolveConfiguration());
26252
- const layer = deepMergeContext(existing, isRecord2(changed) ? changed : {});
27633
+ const layer = deepMergeContext(existing, isRecord5(changed) ? changed : {});
26253
27634
  const config = executor.getConfig();
26254
27635
  const result = config ? validateSessionOverrides(layer, settingsSchemas(config)) : { valid: true };
26255
27636
  if (!result.valid) throw new DeniedError(result.errors ?? "Invalid settings");
26256
- await refuseUnfitFiles(host, isRecord2(changed) ? changed : {});
27637
+ const bands = resolvedBandProblems(
27638
+ config?.assessments ?? [],
27639
+ deepMergeContext(executor.buildResetConfiguration(), layer)
27640
+ );
27641
+ if (bands.length > 0) throw new DeniedError(bands.join("\n"));
27642
+ await refuseUnfitFiles(host, isRecord5(changed) ? changed : {});
26257
27643
  executor.setConfiguration(layer);
26258
27644
  return void 0;
26259
27645
  }
@@ -26271,13 +27657,17 @@ async function updateScenarioDraft(host, drafts, command) {
26271
27657
  host.executor.resolveScenarioDraft(scenarioId, edits)
26272
27658
  );
26273
27659
  const config = host.executor.getConfig();
26274
- const errors = config ? collectSettingsOverrideErrors(
26275
- deepMergeContext(edits, isRecord2(changed) ? changed : {}),
26276
- settingsSchemas(config)
26277
- ) : [];
27660
+ const merged = deepMergeContext(edits, isRecord5(changed) ? changed : {});
27661
+ const errors = config ? [
27662
+ ...collectSettingsOverrideErrors(merged, settingsSchemas(config)),
27663
+ ...resolvedBandProblems(
27664
+ config.assessments ?? [],
27665
+ host.executor.resolveScenarioDraft(scenarioId, merged)
27666
+ )
27667
+ ] : [];
26278
27668
  if (errors.length > 0) throw new DeniedError(errors.join("\n"));
26279
- await refuseUnfitFiles(host, isRecord2(changed) ? changed : {}, { draft: true });
26280
- drafts.record(scenarioId, isRecord2(changed) ? changed : {});
27669
+ await refuseUnfitFiles(host, isRecord5(changed) ? changed : {}, { draft: true });
27670
+ drafts.record(scenarioId, isRecord5(changed) ? changed : {});
26281
27671
  return void 0;
26282
27672
  }
26283
27673
  async function refuseUnfitFiles(host, changed, options = {}) {
@@ -26395,11 +27785,11 @@ function resolveSharedWrites(host, board) {
26395
27785
  executor.setSharedContext(deepMergeContext(store, changed));
26396
27786
  return { ...board, ...executor.getSharedContext() };
26397
27787
  }
26398
- function isRecord2(value) {
27788
+ function isRecord5(value) {
26399
27789
  return typeof value === "object" && value !== null && !Array.isArray(value);
26400
27790
  }
26401
27791
  function changedFrom(update, current) {
26402
- if (isRecord2(update) && isRecord2(current)) {
27792
+ if (isRecord5(update) && isRecord5(current)) {
26403
27793
  const changed = {};
26404
27794
  for (const [key, value] of Object.entries(update)) {
26405
27795
  const difference = changedFrom(value, current[key]);
@@ -26775,8 +28165,10 @@ var PLAY_STAGE = /* @__PURE__ */ new Set([
26775
28165
  "moveParticipant",
26776
28166
  "renameOwnTeam",
26777
28167
  "renameSelf",
26778
- "extendTick"
28168
+ "extendTick",
28169
+ "makeDormant"
26779
28170
  ]);
28171
+ var HOST_CONTROLS = /* @__PURE__ */ new Set(["armFault", "disarmFault", "makeDormant"]);
26780
28172
  var STALE_BLOCKED = /* @__PURE__ */ new Set([
26781
28173
  "tick",
26782
28174
  "undo",
@@ -26915,7 +28307,7 @@ var Session = class {
26915
28307
  },
26916
28308
  enqueue: (work) => this.enqueue(work),
26917
28309
  apply: (command) => this.apply(command),
26918
- submit: (command) => this.submit(command),
28310
+ submit: (command) => this.enqueue(() => this.apply(command)),
26919
28311
  report: (message, source, teamId) => this.report(message, source, teamId),
26920
28312
  emit: (event) => this.emit(event),
26921
28313
  emitState: (cause) => this.emitState(cause)
@@ -26965,8 +28357,24 @@ var Session = class {
26965
28357
  /** Submit a state-changing command. Queued, in order, one at a time. */
26966
28358
  submit(command) {
26967
28359
  if (command.type === "advanceClock") return this.advanceClock(command.byMs);
28360
+ if (!HOST_CONTROLS.has(command.type)) this.noteActivity();
26968
28361
  return this.enqueue(() => this.apply(command));
26969
28362
  }
28363
+ /**
28364
+ * Something outside the host used the session (§11.4a). A dormant session
28365
+ * wakes before the activity is handled: the re-evaluation waking needs is
28366
+ * queued ahead of it.
28367
+ */
28368
+ noteActivity() {
28369
+ this.finishWaking(this.timers.noteActivity());
28370
+ }
28371
+ finishWaking(reevaluate) {
28372
+ if (!reevaluate) return;
28373
+ void this.enqueue(async () => {
28374
+ await reevaluate();
28375
+ this.emitState("woke");
28376
+ });
28377
+ }
26970
28378
  /**
26971
28379
  * Queue `work` as one operation: every logic call it makes reads the same
26972
28380
  * `meta.now`, taken as it starts rather than as it was submitted (§10.2).
@@ -27036,6 +28444,7 @@ var Session = class {
27036
28444
  case "getState":
27037
28445
  return { type: "state", state: this.project() };
27038
28446
  case "callEndpoint":
28447
+ this.noteActivity();
27039
28448
  return this.endpoints.answer(command);
27040
28449
  case "getEndpointAudit":
27041
28450
  return { type: "endpointAudit", entries: [...this.endpoints.auditLog()] };
@@ -27087,6 +28496,41 @@ var Session = class {
27087
28496
  }
27088
28497
  return { type: "participants", participants: this.roster.records() };
27089
28498
  }
28499
+ case "getAssessment": {
28500
+ const indexes = this.state.getTeamIndexes();
28501
+ const contexts = this.state.getTeamContexts();
28502
+ const complete = this.state.teamsFinished(this.tickLimit());
28503
+ const teams = indexes.map((index3, position2) => ({
28504
+ teamId: `team-${index3 + 1}`,
28505
+ context: contexts[position2],
28506
+ complete: complete[position2] ?? false
28507
+ }));
28508
+ return answerAssessment({
28509
+ query: command,
28510
+ assessments: this.executor.getConfig()?.assessments ?? [],
28511
+ teams,
28512
+ participants: teams.flatMap(
28513
+ (team) => this.participants.list(team.teamId).map((record2) => ({ id: record2.id, teamId: team.teamId }))
28514
+ ),
28515
+ settings: this.executor.resolveConfiguration()
28516
+ });
28517
+ }
28518
+ case "getBenchmark": {
28519
+ try {
28520
+ const statistics = await answerBenchmarkFromSample({
28521
+ packagePath: this.options.packagePath,
28522
+ identifier: command.identifier,
28523
+ where: benchmarkFilters({ where: command.where }),
28524
+ declared: this.executor.getConfig()?.benchmarks?.map((benchmark) => benchmark.definition.identifier)
28525
+ });
28526
+ return { type: "benchmark", statistics };
28527
+ } catch (error) {
28528
+ return {
28529
+ type: "benchmarkFailure",
28530
+ error: errorMessage(error, "The benchmark could not be read")
28531
+ };
28532
+ }
28533
+ }
27090
28534
  }
27091
28535
  }
27092
28536
  /** Convenience for a caller that does not care which kind it is holding. */
@@ -27116,6 +28560,16 @@ var Session = class {
27116
28560
  canUndo: canUndo[position2] ?? false,
27117
28561
  context: withoutEngineState(contexts[position2] ?? {}),
27118
28562
  ...contexts[position2]?.[ENGINE_STATE_KEY] !== void 0 ? { state: structuredClone(contexts[position2][ENGINE_STATE_KEY]) } : {},
28563
+ ...contexts[position2]?.[BENCHMARKS_KEY] !== void 0 ? {
28564
+ benchmarks: structuredClone(
28565
+ contexts[position2][BENCHMARKS_KEY]
28566
+ )
28567
+ } : {},
28568
+ ...contexts[position2]?.[ASSESSMENTS_KEY] !== void 0 ? {
28569
+ assessments: structuredClone(
28570
+ contexts[position2][ASSESSMENTS_KEY]
28571
+ )
28572
+ } : {},
27119
28573
  participants: this.participants.list(teamId).map((record2) => ({
27120
28574
  id: record2.id,
27121
28575
  name: record2.name,
@@ -27216,6 +28670,14 @@ var Session = class {
27216
28670
  syncPresence(connected) {
27217
28671
  if (this.roster.syncPresence(connected)) this.emitState("presence");
27218
28672
  }
28673
+ /**
28674
+ * How many surfaces and console pages are open on this session, which the
28675
+ * host observes as it does presence. Opening one is activity, and while
28676
+ * any is open the session does not go dormant (§11.4a).
28677
+ */
28678
+ syncOpenSurfaces(count) {
28679
+ this.finishWaking(this.timers.surfacesOpen(count));
28680
+ }
27219
28681
  /** Edits on disk this session has not applied, each list empty when none is. */
27220
28682
  pendingChanges() {
27221
28683
  return {
@@ -27389,10 +28851,11 @@ var Session = class {
27389
28851
  try {
27390
28852
  const readsBefore = this.timers.readsBefore(command);
27391
28853
  this.startWarnings = [];
28854
+ this.executor.takeWarnings();
27392
28855
  const committedAtTick = await this.dispatch(command);
27393
28856
  await this.timers.retime(command, readsBefore);
27394
28857
  this.emitState(command.type);
27395
- const warnings = this.startWarnings;
28858
+ const warnings = [...this.startWarnings, ...this.executor.takeWarnings()];
27396
28859
  this.startWarnings = [];
27397
28860
  return {
27398
28861
  ok: true,
@@ -27432,7 +28895,11 @@ var Session = class {
27432
28895
  case "tick":
27433
28896
  return tick(this.host, command);
27434
28897
  case "undo":
27435
- return keepingSessionLifetime(this.host, () => undo(this.host, command));
28898
+ return keepingSessionLifetime(this.host, async () => {
28899
+ const tick2 = await undo(this.host, command);
28900
+ this.roster.settleAssessments();
28901
+ return tick2;
28902
+ });
27436
28903
  case "reset":
27437
28904
  return keepingSessionLifetime(this.host, () => reset(this.host, command));
27438
28905
  case "updateContext":
@@ -27477,6 +28944,14 @@ var Session = class {
27477
28944
  return void 0;
27478
28945
  case "extendTick":
27479
28946
  return this.timers.extend(command);
28947
+ case "makeDormant":
28948
+ if (!this.executor.getConfig()?.tick_controller) {
28949
+ throw new DeniedError(
28950
+ "This game has no tick controller, so nothing ticks on its own"
28951
+ );
28952
+ }
28953
+ this.timers.suspend();
28954
+ return void 0;
27480
28955
  case "armFault":
27481
28956
  this.faults.arm(command.fault, {
27482
28957
  ...command.times === void 0 ? {} : { times: command.times },
@@ -27747,8 +29222,13 @@ var Session = class {
27747
29222
  return resolveTeamDisplayName(index3, this.settings().teams.defaultNames, this.locale);
27748
29223
  }
27749
29224
  sharedEngineState() {
27750
- const state2 = this.executor.getSharedContext()[SHARED_ENGINE_STATE_KEY];
27751
- return state2 === void 0 ? {} : { sharedState: state2 };
29225
+ const shared = this.executor.getSharedContext();
29226
+ const state2 = shared[SHARED_ENGINE_STATE_KEY];
29227
+ const benchmarks = shared[SHARED_BENCHMARKS_KEY];
29228
+ return {
29229
+ ...state2 === void 0 ? {} : { sharedState: state2 },
29230
+ ...benchmarks === void 0 ? {} : { sharedBenchmarks: structuredClone(benchmarks) }
29231
+ };
27752
29232
  }
27753
29233
  sharedStore() {
27754
29234
  const shared = this.executor.getSharedContext();
@@ -27831,8 +29311,8 @@ var Session = class {
27831
29311
  };
27832
29312
 
27833
29313
  // cli/server/vite-plugin.ts
27834
- import { readFile as readFile6 } from "fs/promises";
27835
- import { isAbsolute as isAbsolute6, join as join10, relative as relative4 } from "path";
29314
+ import { readFile as readFile7 } from "fs/promises";
29315
+ import { isAbsolute as isAbsolute6, join as join11, relative as relative4 } from "path";
27836
29316
  function toRootRelative(html2, documentDirectory) {
27837
29317
  return html2.replace(
27838
29318
  /(\s(?:src|href)=")(?!https?:|\/\/|\/|data:|#)(\.\/)?([^"]+)(")/g,
@@ -27870,7 +29350,7 @@ if (import.meta.hot) {
27870
29350
  `;
27871
29351
  async function serveHtmlWithVite(server, res, next, htmlFilePath, documentUrl) {
27872
29352
  try {
27873
- const html2 = await readFile6(htmlFilePath, "utf-8");
29353
+ const html2 = await readFile7(htmlFilePath, "utf-8");
27874
29354
  const directory = documentUrl.slice(0, documentUrl.lastIndexOf("/"));
27875
29355
  const transformed = await server.transformIndexHtml(
27876
29356
  documentUrl,
@@ -27884,7 +29364,7 @@ async function serveHtmlWithVite(server, res, next, htmlFilePath, documentUrl) {
27884
29364
  }
27885
29365
  async function serveStatic(res, next, absolutePath) {
27886
29366
  try {
27887
- const data = await readFile6(absolutePath);
29367
+ const data = await readFile7(absolutePath);
27888
29368
  res.setHeader("Content-Type", contentTypeFor(absolutePath));
27889
29369
  res.end(data);
27890
29370
  } catch {
@@ -27945,8 +29425,8 @@ function buildRoutes(options) {
27945
29425
  ];
27946
29426
  }
27947
29427
  function resolveAbsolute(workingDir, rootDirectory, urlPath) {
27948
- const baseDir = isAbsolute6(rootDirectory) ? rootDirectory : join10(workingDir, rootDirectory);
27949
- return join10(baseDir, urlPath);
29428
+ const baseDir = isAbsolute6(rootDirectory) ? rootDirectory : join11(workingDir, rootDirectory);
29429
+ return join11(baseDir, urlPath);
27950
29430
  }
27951
29431
  function seriousgamingUiPlugin(options) {
27952
29432
  const { workingDir } = options;
@@ -28018,16 +29498,16 @@ function seriousgamingUiPlugin(options) {
28018
29498
 
28019
29499
  // cli/validation/package-validation.ts
28020
29500
  import { existsSync as existsSync12, readFileSync as readFileSync7 } from "fs";
28021
- import { readFile as readFile7 } from "fs/promises";
29501
+ import { readFile as readFile8 } from "fs/promises";
28022
29502
  import { dirname as dirname5, resolve as resolve8 } from "path";
28023
29503
 
28024
29504
  // cli/generation/ts-type.ts
28025
29505
  import { existsSync as existsSync9, readFileSync as readFileSync5, statSync } from "fs";
28026
- import { dirname as dirname3, isAbsolute as isAbsolute7, join as join11, relative as relative5, resolve as resolve5, sep as sep5 } from "path";
29506
+ import { dirname as dirname3, isAbsolute as isAbsolute7, join as join12, relative as relative5, resolve as resolve5, sep as sep5 } from "path";
28027
29507
  var NAMED_IMPORT = /import\((['"])([^'"]+)\1\)\.([A-Za-z_$][\w$]*)/g;
28028
29508
  var MODULE_EXTENSIONS = [".ts", ".tsx", ".d.ts", "/index.ts", "/index.tsx"];
28029
29509
  function capabilityDirectory(workingDir, identifier) {
28030
- return join11(workingDir, getPluralResourceMeta("capability").pluralDir, identifier);
29510
+ return join12(workingDir, getPluralResourceMeta("capability").pluralDir, identifier);
28031
29511
  }
28032
29512
  function collectTsTypes(schema2, into = []) {
28033
29513
  if (Array.isArray(schema2)) {
@@ -28078,9 +29558,85 @@ function exportsName(source, name) {
28078
29558
  return declared.test(source) || listed.test(source) || /export\s+\*\s+from/.test(source);
28079
29559
  }
28080
29560
 
29561
+ // cli/validation/benchmark-validation.ts
29562
+ function outcome2() {
29563
+ return { errors: [], warnings: [], findings: [] };
29564
+ }
29565
+ function addError2(result, finding) {
29566
+ result.errors.push(finding.hint ? `${finding.message}. ${finding.hint}` : finding.message);
29567
+ result.findings.push({ severity: "error", ...finding });
29568
+ }
29569
+ function validateBenchmark(benchmark, config) {
29570
+ const result = outcome2();
29571
+ const { identifier } = benchmark.definition;
29572
+ const file = bundleFileOf("benchmark", identifier);
29573
+ const resource = { type: "benchmark", identifier };
29574
+ if (!(config.requires ?? []).includes(BENCHMARKS_FEATURE)) {
29575
+ addError2(result, {
29576
+ code: "FEATURE_UNDECLARED",
29577
+ message: `Benchmark "${identifier}" needs the \`${BENCHMARKS_FEATURE}\` feature, but \`requires\` does not list it`,
29578
+ hint: `Add "${BENCHMARKS_FEATURE}" to \`requires\` in seriousgaming.sdk.json, so a runtime that cannot record benchmarks refuses the package rather than failing the first round that writes one`,
29579
+ file: MANIFEST_FILE,
29580
+ pointer: pointerOf("requires"),
29581
+ resource
29582
+ });
29583
+ }
29584
+ const engine = config.engine;
29585
+ const written = engine?.definition.benchmarks?.includes(identifier) ?? false;
29586
+ if (!written) {
29587
+ const message = `Benchmark "${identifier}" is not in the engine's "benchmarks", so nothing can write it and it will never hold a value`;
29588
+ result.warnings.push(message);
29589
+ result.findings.push({
29590
+ severity: "warning",
29591
+ code: "BENCHMARK_UNWRITTEN",
29592
+ message,
29593
+ hint: `Add "${identifier}" to "benchmarks" in engine/engine.sdk.json, or delete the benchmark`,
29594
+ file,
29595
+ resource
29596
+ });
29597
+ }
29598
+ if (written && resolveBenchmarkLevel(benchmark.definition) === "session" && engine?.definition.aggregate !== true) {
29599
+ addError2(result, {
29600
+ code: "PACKAGE_INVALID",
29601
+ message: `Benchmark "${identifier}" is session-level, but the engine is not aggregate, so it has no session result to write it under`,
29602
+ hint: 'Export InitAggregate and RunAggregate from the engine, or make the benchmark per team by removing "level"',
29603
+ file,
29604
+ pointer: pointerOf("definition", "level"),
29605
+ resource
29606
+ });
29607
+ }
29608
+ return result;
29609
+ }
29610
+ function validateEngineBenchmarks(config) {
29611
+ const result = outcome2();
29612
+ const declared = new Set((config.benchmarks ?? []).map((b) => b.definition.identifier));
29613
+ const engine = config.engine;
29614
+ if (engine) {
29615
+ (engine.definition.benchmarks ?? []).forEach((identifier, index3) => {
29616
+ if (declared.has(identifier)) return;
29617
+ addError2(result, {
29618
+ code: "REFERENCE_UNKNOWN",
29619
+ message: `Engine declares benchmark "${identifier}", which the package does not have`,
29620
+ hint: `Create it with "new benchmark", or remove it from the engine's "benchmarks"`,
29621
+ file: bundleFileOf("engine", "engine"),
29622
+ pointer: pointerOf("definition", "benchmarks", index3),
29623
+ resource: { type: "engine", identifier: engine.definition.identifier }
29624
+ });
29625
+ });
29626
+ }
29627
+ if (declared.size > MAX_BENCHMARKS_PER_GAME) {
29628
+ addError2(result, {
29629
+ code: "PACKAGE_INVALID",
29630
+ message: `The game declares ${declared.size} benchmarks, more than the ${MAX_BENCHMARKS_PER_GAME} a game may have`,
29631
+ hint: "Combine related fields into one benchmark, or remove the ones no debrief shows"
29632
+ });
29633
+ }
29634
+ return result;
29635
+ }
29636
+
28081
29637
  // cli/validation/facilitator-guide-validator.ts
28082
29638
  import { existsSync as existsSync10, readdirSync as readdirSync3, readFileSync as readFileSync6, statSync as statSync2 } from "fs";
28083
- import { dirname as dirname4, join as join12, resolve as resolve6, sep as sep6 } from "path";
29639
+ import { dirname as dirname4, join as join13, resolve as resolve6, sep as sep6 } from "path";
28084
29640
 
28085
29641
  // cli/guide/video-registry.ts
28086
29642
  var VIDEO_PROVIDERS = {
@@ -28354,20 +29910,20 @@ var LARGE_VIDEO_FILE_BYTES = 25 * 1024 * 1024;
28354
29910
  var VIDEO_BLOCK_PATTERN = /^[ \t]*```video[ \t]*\r?\n([\s\S]*?)^[ \t]*```[ \t]*$/gm;
28355
29911
  var IMAGE_PATTERN = /!\[[^\]]*\]\(([^()\s]+)(?:\s+"[^"]*")?\)/g;
28356
29912
  function listChapters(localeDir) {
28357
- return readdirSync3(localeDir).filter((name) => name.endsWith(".md") && statSync2(join12(localeDir, name)).isFile()).sort();
29913
+ return readdirSync3(localeDir).filter((name) => name.endsWith(".md") && statSync2(join13(localeDir, name)).isFile()).sort();
28358
29914
  }
28359
29915
  function validateFacilitatorGuideContent(options) {
28360
29916
  const errors = [];
28361
29917
  const warnings = [];
28362
29918
  const { definition: definition3, rootDirectory } = options;
28363
- const contentDir = join12(rootDirectory, "content");
29919
+ const contentDir = join13(rootDirectory, "content");
28364
29920
  const declaredLocales = Object.keys(definition3.locales);
28365
29921
  if (!existsSync10(contentDir)) {
28366
29922
  warnings.push("Guide has no content/ directory");
28367
29923
  return { errors, warnings };
28368
29924
  }
28369
29925
  for (const entry of readdirSync3(contentDir)) {
28370
- if (!statSync2(join12(contentDir, entry)).isDirectory()) continue;
29926
+ if (!statSync2(join13(contentDir, entry)).isDirectory()) continue;
28371
29927
  if (!declaredLocales.includes(entry)) {
28372
29928
  warnings.push(
28373
29929
  `Content directory "content/${entry}/" has no matching locale in the guide definition`
@@ -28375,14 +29931,14 @@ function validateFacilitatorGuideContent(options) {
28375
29931
  }
28376
29932
  }
28377
29933
  const reference = referenceLocale(definition3.locales);
28378
- const referenceDir = join12(contentDir, reference);
29934
+ const referenceDir = join13(contentDir, reference);
28379
29935
  const referenceChapters = existsSync10(referenceDir) ? listChapters(referenceDir) : [];
28380
29936
  if (referenceChapters.length === 0) {
28381
29937
  warnings.push(`Guide has no chapters for its reference locale "${reference}"`);
28382
29938
  }
28383
29939
  const read = [];
28384
29940
  for (const locale of declaredLocales) {
28385
- const localeDir = join12(contentDir, locale);
29941
+ const localeDir = join13(contentDir, locale);
28386
29942
  if (!existsSync10(localeDir)) {
28387
29943
  warnings.push(`Declared locale "${locale}" has no content/${locale}/ directory`);
28388
29944
  continue;
@@ -28401,7 +29957,7 @@ function validateFacilitatorGuideContent(options) {
28401
29957
  }
28402
29958
  }
28403
29959
  for (const chapter of chapters) {
28404
- const chapterPath = join12(localeDir, chapter);
29960
+ const chapterPath = join13(localeDir, chapter);
28405
29961
  const content3 = readFileSync6(chapterPath, "utf-8");
28406
29962
  const label4 = `content/${locale}/${chapter}`;
28407
29963
  read.push({ label: label4, markdown: content3, reference: locale === reference });
@@ -28412,14 +29968,14 @@ function validateFacilitatorGuideContent(options) {
28412
29968
  continue;
28413
29969
  }
28414
29970
  if (parsed.kind !== "file") continue;
28415
- const assetsDir = join12(rootDirectory, "assets");
29971
+ const assetsDir = join13(rootDirectory, "assets");
28416
29972
  for (const [key, path3] of [
28417
29973
  ["src", parsed.src],
28418
29974
  ["poster", parsed.poster],
28419
29975
  ["captions", parsed.captions]
28420
29976
  ]) {
28421
29977
  if (path3 === void 0) continue;
28422
- const file = join12(assetsDir, path3);
29978
+ const file = join13(assetsDir, path3);
28423
29979
  if (!existsSync10(file) || !statSync2(file).isFile()) {
28424
29980
  errors.push(
28425
29981
  `${label4}: video ${key} "assets/${path3}" does not resolve to a file`
@@ -29598,7 +31154,7 @@ function readsWritten(type) {
29598
31154
  const label4 = getResourceMeta(type).label;
29599
31155
  return (resource, context) => {
29600
31156
  const definition3 = resource.definition;
29601
- const outcome = {
31157
+ const outcome3 = {
29602
31158
  errors: [],
29603
31159
  warnings: [],
29604
31160
  findings: []
@@ -29607,15 +31163,15 @@ function readsWritten(type) {
29607
31163
  if (!context.capabilityIds.has(capId)) return;
29608
31164
  if (context.writtenInPackage.has(capId)) return;
29609
31165
  const message = `${label4} "${definition3.identifier}" declares a read of capability "${capId}", but no engine, user interface, or hook in this package writes it, so it can only ever hold its schema defaults. Remove the read if it is unused, or move the values to a settings resource if they are meant to be constants.`;
29610
- outcome.warnings.push(message);
29611
- outcome.findings.push({
31166
+ outcome3.warnings.push(message);
31167
+ outcome3.findings.push({
29612
31168
  severity: "warning",
29613
31169
  code: "READ_NEVER_WRITTEN",
29614
31170
  message,
29615
31171
  pointer: pointerOf("definition", "reads", index3)
29616
31172
  });
29617
31173
  });
29618
- return outcome;
31174
+ return outcome3;
29619
31175
  };
29620
31176
  }
29621
31177
  var uiFiles = (ui, context) => validateUIFiles(ui, context.workingDir);
@@ -29653,12 +31209,25 @@ var VALIDATION_DESCRIPTORS = [
29653
31209
  localRefs("capability")
29654
31210
  ]
29655
31211
  }),
31212
+ descriptor({
31213
+ type: "benchmark",
31214
+ resources: (config) => config.benchmarks ?? [],
31215
+ identify: named2,
31216
+ checks: [(benchmark, context) => validateBenchmark(benchmark, context.config)]
31217
+ }),
31218
+ descriptor({
31219
+ type: "assessment",
31220
+ resources: (config) => config.assessments ?? [],
31221
+ identify: named2,
31222
+ checks: [(assessment, context) => validateAssessment(assessment, context.config)]
31223
+ }),
29656
31224
  // The built-in `game` resource's defaults are the manifest's own values,
29657
- // which the game's checks already hold to their schema.
31225
+ // which the game's checks already hold to their schema, and the built-in
31226
+ // `assessments` resource's are the bundles' bands, which theirs do.
29658
31227
  descriptor({
29659
31228
  type: "settings",
29660
31229
  resources: (config) => (config.settings ?? []).filter(
29661
- (settings) => settings.definition.identifier !== GAME_SETTINGS
31230
+ (settings) => settings.definition.identifier !== GAME_SETTINGS && !(settings.definition.identifier === ASSESSMENTS_SETTINGS && (config.assessments?.length ?? 0) > 0)
29662
31231
  ),
29663
31232
  identify: named2,
29664
31233
  checks: [
@@ -29704,6 +31273,8 @@ var VALIDATION_DESCRIPTORS = [
29704
31273
  writer: writesOf,
29705
31274
  checks: [
29706
31275
  (engine, context) => validateEngine(engine, context.config),
31276
+ (_engine, context) => validateEngineBenchmarks(context.config),
31277
+ (_engine, context) => validateEngineAssessments(context.config),
29707
31278
  (engine, context) => validateEngineFiles(engine, context.workingDir),
29708
31279
  schemaDefaults2("engine"),
29709
31280
  readsWritten("engine")
@@ -29983,7 +31554,7 @@ async function validateLoadedPackage(config, options) {
29983
31554
  capabilityIds: new Set((config.capabilities ?? []).map(named2)),
29984
31555
  logicLoader: new LogicLoader(dirname5(options.configPath), {
29985
31556
  transpile: Transpile,
29986
- fs: { existsSync: existsSync12, readFile: readFile7 }
31557
+ fs: { existsSync: existsSync12, readFile: readFile8 }
29987
31558
  })
29988
31559
  };
29989
31560
  const results = [];
@@ -30042,7 +31613,7 @@ function setupNotesChecks(setup, context) {
30042
31613
  const configures = new Set(setup.definition.configures ?? []);
30043
31614
  const reads = new Set(setup.definition.settings ?? []);
30044
31615
  const resource = { type: "setup", identifier: "setup" };
30045
- const outcome = {
31616
+ const outcome3 = {
30046
31617
  errors: [],
30047
31618
  warnings: [],
30048
31619
  findings: []
@@ -30058,8 +31629,8 @@ function setupNotesChecks(setup, context) {
30058
31629
  const identifier = parseSettingPath(path3)?.identifier ?? "";
30059
31630
  if (!configures.has(identifier) && !reads.has(identifier)) {
30060
31631
  const message = `Setup notes ${file}, line ${line}, name \`${path3}\`, but the setup UI neither configures nor reads "${identifier}", so a host refuses a change to it. Add "${identifier}" to its \`configures\` if setup may change it, or to its \`settings\` if the notes name it only as where the menu's offer is read from.`;
30061
- outcome.warnings.push(message);
30062
- outcome.findings.push({
31632
+ outcome3.warnings.push(message);
31633
+ outcome3.findings.push({
30063
31634
  severity: "warning",
30064
31635
  code: "SETUP_NOTES_UNCONFIGURED",
30065
31636
  message,
@@ -30070,7 +31641,7 @@ function setupNotesChecks(setup, context) {
30070
31641
  }
30071
31642
  }
30072
31643
  }
30073
- return outcome;
31644
+ return outcome3;
30074
31645
  }
30075
31646
  function ungatedSettingsChecks(gameIdentifier, config) {
30076
31647
  const resource = { type: "game", identifier: gameIdentifier };
@@ -30082,7 +31653,9 @@ function ungatedSettingsChecks(gameIdentifier, config) {
30082
31653
  (config.validators ?? []).filter((v) => v.definition.gates?.includes("scenario")).flatMap((v) => v.definition.settings ?? [])
30083
31654
  );
30084
31655
  for (const identifier of configures) {
30085
- if (identifier === GAME_SETTINGS || gated.has(identifier)) continue;
31656
+ if (identifier === GAME_SETTINGS || identifier === ASSESSMENTS_SETTINGS || gated.has(identifier)) {
31657
+ continue;
31658
+ }
30086
31659
  const message = `The setup UI changes the "${identifier}" settings, but no \`Scenario\` gate declares them, so nothing checks a facilitator's changes to them before the session starts. Add "${identifier}" to the \`settings\` of the validator that exports \`Scenario\` if a change there can break play.`;
30087
31660
  warnings.push(message);
30088
31661
  findings.push({
@@ -30097,8 +31670,8 @@ function ungatedSettingsChecks(gameIdentifier, config) {
30097
31670
  }
30098
31671
  return { errors: [], warnings, findings };
30099
31672
  }
30100
- function record(result, outcome) {
30101
- const byMessage = new Map((outcome.findings ?? []).map((f) => [f.message, f]));
31673
+ function record(result, outcome3) {
31674
+ const byMessage = new Map((outcome3.findings ?? []).map((f) => [f.message, f]));
30102
31675
  const add = (severity, message) => {
30103
31676
  const finding = byMessage.get(message) ?? {
30104
31677
  code: message.includes(LOGIC_NODE_BUILTIN) ? LOGIC_NODE_BUILTIN : "PACKAGE_INVALID",
@@ -30106,18 +31679,18 @@ function record(result, outcome) {
30106
31679
  };
30107
31680
  result.diagnostics.push(located(severity, finding, result));
30108
31681
  };
30109
- if (outcome.errorFindings) {
30110
- result.errors.push(...outcome.errors);
31682
+ if (outcome3.errorFindings) {
31683
+ result.errors.push(...outcome3.errors);
30111
31684
  result.diagnostics.push(
30112
- ...outcome.errorFindings.map((finding) => located("error", finding, result))
31685
+ ...outcome3.errorFindings.map((finding) => located("error", finding, result))
30113
31686
  );
30114
31687
  } else {
30115
- for (const message of outcome.errors) {
31688
+ for (const message of outcome3.errors) {
30116
31689
  result.errors.push(message);
30117
31690
  add("error", message);
30118
31691
  }
30119
31692
  }
30120
- for (const message of outcome.warnings ?? []) {
31693
+ for (const message of outcome3.warnings ?? []) {
30121
31694
  result.warnings.push(message);
30122
31695
  add("warning", message);
30123
31696
  }
@@ -30159,7 +31732,7 @@ function scenarioRefusals(problems, subject, resource, file, pointerFor) {
30159
31732
 
30160
31733
  // cli/dev/brands.ts
30161
31734
  import { existsSync as existsSync13, readFileSync as readFileSync8 } from "fs";
30162
- import { dirname as dirname6, isAbsolute as isAbsolute8, join as join13, normalize as normalize2, resolve as resolve9, sep as sep8 } from "path";
31735
+ import { dirname as dirname6, isAbsolute as isAbsolute8, join as join14, normalize as normalize2, resolve as resolve9, sep as sep8 } from "path";
30163
31736
  import { fileURLToPath as fileURLToPath2 } from "url";
30164
31737
  var ROLES = ["primary", "secondary", "success", "error", "warning", "info"];
30165
31738
  var NEUTRALS = ["background", "surface", "text"];
@@ -30248,7 +31821,7 @@ var PLAIN_DARK = {
30248
31821
  info: "#29b6f6"
30249
31822
  };
30250
31823
  function builtInBrandsDirectory() {
30251
- return join13(dirname6(fileURLToPath2(import.meta.url)), "brands");
31824
+ return join14(dirname6(fileURLToPath2(import.meta.url)), "brands");
30252
31825
  }
30253
31826
  function invalid(path3, problem) {
30254
31827
  return new CliError("INPUT_INVALID", `The brand file ${path3} is not valid: ${problem}`, {
@@ -30361,12 +31934,12 @@ function loadBrands(brandFiles = []) {
30361
31934
  brand: { name: "Plain brand" }
30362
31935
  };
30363
31936
  const seriousGaming = readBrandFile(
30364
- join13(directory, "serious-gaming", "brand.json"),
31937
+ join14(directory, "serious-gaming", "brand.json"),
30365
31938
  SERIOUS_GAMING,
30366
31939
  plain
30367
31940
  );
30368
31941
  const awkward = readBrandFile(
30369
- join13(directory, "awkward", "brand.json"),
31942
+ join14(directory, "awkward", "brand.json"),
30370
31943
  "awkward",
30371
31944
  seriousGaming
30372
31945
  );
@@ -30437,23 +32010,23 @@ function summarise(brand, assetOrigin) {
30437
32010
 
30438
32011
  // cli/dev/console-path.ts
30439
32012
  import { existsSync as existsSync14 } from "fs";
30440
- import { join as join14, sep as sep9 } from "path";
32013
+ import { join as join15, sep as sep9 } from "path";
30441
32014
  function resolveConsolePath(dirname14, filename, fileExists = existsSync14) {
30442
32015
  const fromSource = filename.includes(`${sep9}cli${sep9}dev${sep9}`) || filename.includes("/cli/dev/");
30443
- const path3 = fromSource ? join14(dirname14, "..", "..", "dist", "dev", "console") : join14(dirname14, "dev", "console");
30444
- return { path: path3, built: fileExists(join14(path3, "index.html")) };
32016
+ const path3 = fromSource ? join15(dirname14, "..", "..", "dist", "dev", "console") : join15(dirname14, "dev", "console");
32017
+ return { path: path3, built: fileExists(join15(path3, "index.html")) };
30445
32018
  }
30446
32019
  var MISSING_CONSOLE_MESSAGE = "The dev console has not been built yet. Run `pnpm build` in sdk-tools, or `pnpm exec vite build cli/dev/console` to build just the console.";
30447
32020
 
30448
32021
  // cli/dev/lockfile.ts
30449
32022
  import { createHash as createHash3, randomUUID as randomUUID3 } from "crypto";
30450
- import { mkdir as mkdir3, readFile as readFile8, rm as rm3, writeFile as writeFile3 } from "fs/promises";
32023
+ import { mkdir as mkdir3, readFile as readFile9, rm as rm3, writeFile as writeFile3 } from "fs/promises";
30451
32024
  import { hostname } from "os";
30452
- import { basename as basename3, dirname as dirname8, join as join16, resolve as resolve11 } from "path";
32025
+ import { basename as basename3, dirname as dirname8, join as join17, resolve as resolve11 } from "path";
30453
32026
 
30454
32027
  // cli/dev/tools-identity.ts
30455
32028
  import { existsSync as existsSync15, readFileSync as readFileSync9, realpathSync as realpathSync3 } from "fs";
30456
- import { dirname as dirname7, join as join15, resolve as resolve10, sep as sep10 } from "path";
32029
+ import { dirname as dirname7, join as join16, resolve as resolve10, sep as sep10 } from "path";
30457
32030
  import { fileURLToPath as fileURLToPath3 } from "url";
30458
32031
  var cached = null;
30459
32032
  function toolsIdentity() {
@@ -30464,10 +32037,10 @@ function readIdentity(filename) {
30464
32037
  const here = dirname7(filename);
30465
32038
  const fromSource = filename.includes(`${sep10}cli${sep10}dev${sep10}`);
30466
32039
  const root2 = fromSource ? resolve10(here, "..", "..") : resolve10(here, "..");
30467
- const entry = fromSource ? join15(root2, "cli", "cli.ts") : join15(here, "cli.js");
32040
+ const entry = fromSource ? join16(root2, "cli", "cli.ts") : join16(here, "cli.js");
30468
32041
  let version = "0.0.0";
30469
32042
  try {
30470
- const manifest = JSON.parse(readFileSync9(join15(root2, "package.json"), "utf-8"));
32043
+ const manifest = JSON.parse(readFileSync9(join16(root2, "package.json"), "utf-8"));
30471
32044
  version = manifest.version ?? version;
30472
32045
  } catch {
30473
32046
  }
@@ -30479,10 +32052,10 @@ var DEV_STATE_DIR_ENV_VAR = "SERIOUSGAMING_DEV_STATE_DIR";
30479
32052
  var ownInstances = /* @__PURE__ */ new Set();
30480
32053
  function lockFilePath(packagePath, env = process.env) {
30481
32054
  const stateDir = env[DEV_STATE_DIR_ENV_VAR]?.trim();
30482
- if (!stateDir) return join16(packagePath, ".seriousgaming-sdk", "session.json");
32055
+ if (!stateDir) return join17(packagePath, ".seriousgaming-sdk", "session.json");
30483
32056
  const absolute = resolve11(packagePath);
30484
32057
  const key = createHash3("sha256").update(absolute).digest("hex").slice(0, 12);
30485
- return join16(resolve11(stateDir), `${basename3(absolute)}-${key}`, "session.json");
32058
+ return join17(resolve11(stateDir), `${basename3(absolute)}-${key}`, "session.json");
30486
32059
  }
30487
32060
  async function writeLockFile(packagePath, details) {
30488
32061
  const path3 = lockFilePath(packagePath);
@@ -30514,7 +32087,7 @@ function newInstanceId() {
30514
32087
  import { rmSync, watch as watchDirectory } from "fs";
30515
32088
  import { mkdtemp as mkdtemp2, rm as rm4, writeFile as writeFile4 } from "fs/promises";
30516
32089
  import { tmpdir as tmpdir2 } from "os";
30517
- import { basename as basename4, join as join17, relative as relative7, sep as sep11 } from "path";
32090
+ import { basename as basename4, join as join18, relative as relative7, sep as sep11 } from "path";
30518
32091
  import { watch } from "chokidar";
30519
32092
  var IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
30520
32093
  "node_modules",
@@ -30545,7 +32118,7 @@ function classifyDirectory(packagePath, path3) {
30545
32118
  return !segments.some((segment) => IGNORED_DIRECTORIES.has(segment));
30546
32119
  }
30547
32120
  async function untilWatchesDeliver(timeoutMs = 2e3) {
30548
- const directory = await mkdtemp2(join17(tmpdir2(), "sg-watch-"));
32121
+ const directory = await mkdtemp2(join18(tmpdir2(), "sg-watch-"));
30549
32122
  const removeOnExit = () => rmSync(directory, { recursive: true, force: true });
30550
32123
  process.once("exit", removeOnExit);
30551
32124
  const remove = () => {
@@ -30567,7 +32140,7 @@ async function untilWatchesDeliver(timeoutMs = 2e3) {
30567
32140
  });
30568
32141
  const deadline = Date.now() + timeoutMs;
30569
32142
  for (let attempt = 0; !delivered && Date.now() < deadline; attempt++) {
30570
- await writeFile4(join17(directory, "probe"), String(attempt));
32143
+ await writeFile4(join18(directory, "probe"), String(attempt));
30571
32144
  await new Promise((resolve14) => setTimeout(resolve14, 25));
30572
32145
  }
30573
32146
  return async () => {
@@ -30640,19 +32213,19 @@ function publicHostnames(origins) {
30640
32213
 
30641
32214
  // cli/dev/routes.ts
30642
32215
  import { existsSync as existsSync18 } from "fs";
30643
- import { readFile as readFile10 } from "fs/promises";
32216
+ import { readFile as readFile11 } from "fs/promises";
30644
32217
  import { isAbsolute as isAbsolute10, normalize as normalize3, resolve as resolve12, sep as sep12 } from "path";
30645
32218
  import express from "express";
30646
32219
 
30647
32220
  // cli/core/package-scenario.ts
30648
32221
  import { existsSync as existsSync17, readdirSync as readdirSync4 } from "fs";
30649
- import { mkdir as mkdir5, readFile as readFile9, rm as rm5 } from "fs/promises";
30650
- import { dirname as dirname10, isAbsolute as isAbsolute9, join as join19, resolve as resolvePath3 } from "path";
32222
+ import { mkdir as mkdir5, readFile as readFile10, rm as rm5 } from "fs/promises";
32223
+ import { dirname as dirname10, isAbsolute as isAbsolute9, join as join20, resolve as resolvePath3 } from "path";
30651
32224
 
30652
32225
  // cli/core/asset-reference-translator.ts
30653
32226
  import { existsSync as existsSync16 } from "fs";
30654
32227
  import { mkdir as mkdir4, writeFile as writeFile5 } from "fs/promises";
30655
- import { basename as basename5, dirname as dirname9, extname, join as join18, posix as posix2 } from "path";
32228
+ import { basename as basename5, dirname as dirname9, extname, join as join19, posix as posix2 } from "path";
30656
32229
  var ASSET_PREFIX2 = "asset:";
30657
32230
  var BLOB_PREFIX2 = "blob:";
30658
32231
  function createBlobToAssetTranslator(opts) {
@@ -30670,14 +32243,14 @@ function createBlobToAssetTranslator(opts) {
30670
32243
  opts.sourceScenarioRootDirectory,
30671
32244
  reference
30672
32245
  );
30673
- const targetSubdir = join18(opts.targetAssetsDirectory, subdirectory);
32246
+ const targetSubdir = join19(opts.targetAssetsDirectory, subdirectory);
30674
32247
  await mkdir4(targetSubdir, { recursive: true });
30675
32248
  const safeName = sanitizeAssetName(asset.name);
30676
32249
  const relativePath = posix2.join(
30677
32250
  subdirectory,
30678
32251
  uniqueAssetName(targetSubdir, safeName, reservedNames)
30679
32252
  );
30680
- const absolutePath = join18(opts.targetAssetsDirectory, relativePath);
32253
+ const absolutePath = join19(opts.targetAssetsDirectory, relativePath);
30681
32254
  await mkdir4(dirname9(absolutePath), { recursive: true });
30682
32255
  await writeFile5(absolutePath, asset.data);
30683
32256
  reservedNames.add(basename5(absolutePath));
@@ -30689,12 +32262,12 @@ function sanitizeAssetName(name) {
30689
32262
  return stripped.length > 0 ? stripped : "asset";
30690
32263
  }
30691
32264
  function uniqueAssetName(directory, name, reserved) {
30692
- if (!existsSync16(join18(directory, name)) && !reserved.has(name)) return name;
32265
+ if (!existsSync16(join19(directory, name)) && !reserved.has(name)) return name;
30693
32266
  const ext = extname(name);
30694
32267
  const stem = ext ? name.slice(0, -ext.length) : name;
30695
32268
  for (let i = 1; i < 1e3; i++) {
30696
32269
  const candidate = `${stem}-${i}${ext}`;
30697
- if (!existsSync16(join18(directory, candidate)) && !reserved.has(candidate)) {
32270
+ if (!existsSync16(join19(directory, candidate)) && !reserved.has(candidate)) {
30698
32271
  return candidate;
30699
32272
  }
30700
32273
  }
@@ -30755,15 +32328,15 @@ async function createPackageScenario(opts) {
30755
32328
  if (existing) {
30756
32329
  scenarioFilePath = existing.scenarioFilePath;
30757
32330
  const scenarioRoot = isAbsolute9(existing.bundle.rootDirectory) ? existing.bundle.rootDirectory : resolvePath3(dirname10(existing.scenarioFilePath), existing.bundle.rootDirectory);
30758
- targetAssetsDirectory = join19(scenarioRoot, "assets");
32331
+ targetAssetsDirectory = join20(scenarioRoot, "assets");
30759
32332
  bundleRootDirectory = existing.bundle.rootDirectory;
30760
32333
  sourceScenarioRootDirectory = scenarioRoot;
30761
- await mkdir5(join19(targetAssetsDirectory, "shared"), { recursive: true });
32334
+ await mkdir5(join20(targetAssetsDirectory, "shared"), { recursive: true });
30762
32335
  } else {
30763
- const scenarioDir = join19(opts.packagePath, "scenarios", opts.identifier);
30764
- scenarioFilePath = join19(scenarioDir, "scenario.sdk.json");
30765
- targetAssetsDirectory = join19(scenarioDir, "assets");
30766
- await mkdir5(join19(scenarioDir, "assets", "shared"), { recursive: true });
32336
+ const scenarioDir = join20(opts.packagePath, "scenarios", opts.identifier);
32337
+ scenarioFilePath = join20(scenarioDir, "scenario.sdk.json");
32338
+ targetAssetsDirectory = join20(scenarioDir, "assets");
32339
+ await mkdir5(join20(scenarioDir, "assets", "shared"), { recursive: true });
30767
32340
  }
30768
32341
  const translated = await translateSettings({
30769
32342
  settings: opts.settings,
@@ -30838,11 +32411,11 @@ async function deletePackageScenario(packagePath, identifier) {
30838
32411
  }
30839
32412
  async function findScenarioBundle(packagePath, identifier) {
30840
32413
  for (const relativePath of scenarioBundlePaths(packagePath)) {
30841
- const filePath = join19(packagePath, relativePath);
32414
+ const filePath = join20(packagePath, relativePath);
30842
32415
  if (!existsSync17(filePath)) continue;
30843
32416
  try {
30844
32417
  if (relativePath.split("/")[1] !== identifier) continue;
30845
- const bundle = JSON.parse(await readFile9(filePath, "utf-8"));
32418
+ const bundle = JSON.parse(await readFile10(filePath, "utf-8"));
30846
32419
  return { scenarioFilePath: filePath, relativePath, bundle };
30847
32420
  } catch {
30848
32421
  continue;
@@ -30851,29 +32424,29 @@ async function findScenarioBundle(packagePath, identifier) {
30851
32424
  return null;
30852
32425
  }
30853
32426
  function scenarioBundlePaths(packagePath) {
30854
- const scenariosDir = join19(packagePath, "scenarios");
32427
+ const scenariosDir = join20(packagePath, "scenarios");
30855
32428
  if (!existsSync17(scenariosDir)) return [];
30856
32429
  return readdirSync4(scenariosDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort().map((name) => `scenarios/${name}/scenario.sdk.json`);
30857
32430
  }
30858
32431
  async function readPackageManifest(packagePath) {
30859
- const manifestPath = join19(packagePath, "seriousgaming.sdk.json");
32432
+ const manifestPath = join20(packagePath, "seriousgaming.sdk.json");
30860
32433
  if (!existsSync17(manifestPath)) {
30861
32434
  throw new PackageScenarioError(
30862
32435
  "package-manifest-missing",
30863
32436
  `Cannot find seriousgaming.sdk.json at ${packagePath}`
30864
32437
  );
30865
32438
  }
30866
- return JSON.parse(await readFile9(manifestPath, "utf-8"));
32439
+ return JSON.parse(await readFile10(manifestPath, "utf-8"));
30867
32440
  }
30868
32441
  async function makeScenarioDefault(packagePath, identifier) {
30869
32442
  await readPackageManifest(packagePath);
30870
32443
  let found = false;
30871
32444
  for (const entry of scenarioBundlePaths(packagePath)) {
30872
- const filePath = join19(packagePath, entry);
32445
+ const filePath = join20(packagePath, entry);
30873
32446
  if (!existsSync17(filePath)) continue;
30874
32447
  let bundle;
30875
32448
  try {
30876
- bundle = JSON.parse(await readFile9(filePath, "utf-8"));
32449
+ bundle = JSON.parse(await readFile10(filePath, "utf-8"));
30877
32450
  } catch {
30878
32451
  continue;
30879
32452
  }
@@ -31652,7 +33225,7 @@ function registerRoutes(app, deps) {
31652
33225
  res.status(404).json({ error: "Chapter not found" });
31653
33226
  return;
31654
33227
  }
31655
- res.type("text/markdown").send(await readFile10(file, "utf-8"));
33228
+ res.type("text/markdown").send(await readFile11(file, "utf-8"));
31656
33229
  });
31657
33230
  app.get("/api/guide/assets/*path", (req, res) => {
31658
33231
  const guide = session.guide();
@@ -31822,13 +33395,26 @@ var NO_TEAM_ID = {
31822
33395
  renameSelf: "renameSelf renames the caller, whom the host resolves; it takes no teamId"
31823
33396
  };
31824
33397
  var FRAME_QUERIES = {
31825
- game: /* @__PURE__ */ new Set(["callEndpoint", "getPastState", "getAllTeamsParticipants"]),
31826
- "waiting-room": /* @__PURE__ */ new Set(["callEndpoint", "getPastState", "getAllTeamsParticipants"]),
31827
- session: /* @__PURE__ */ new Set(["callEndpoint", "getPastState"]),
33398
+ game: /* @__PURE__ */ new Set([
33399
+ "callEndpoint",
33400
+ "getPastState",
33401
+ "getAllTeamsParticipants",
33402
+ "getBenchmark",
33403
+ "getAssessment"
33404
+ ]),
33405
+ "waiting-room": /* @__PURE__ */ new Set([
33406
+ "callEndpoint",
33407
+ "getPastState",
33408
+ "getAllTeamsParticipants",
33409
+ "getBenchmark",
33410
+ "getAssessment"
33411
+ ]),
33412
+ session: /* @__PURE__ */ new Set(["callEndpoint", "getPastState", "getBenchmark", "getAssessment"]),
31828
33413
  setup: /* @__PURE__ */ new Set(["callEndpoint"]),
31829
33414
  "scenario-editor": /* @__PURE__ */ new Set(["callEndpoint"]),
31830
- presentation: /* @__PURE__ */ new Set(["getPastState"])
33415
+ presentation: /* @__PURE__ */ new Set(["getPastState", "getBenchmark", "getAssessment"])
31831
33416
  };
33417
+ var PLAYER_SURFACES = /* @__PURE__ */ new Set(["game", "waiting-room"]);
31832
33418
  function teamScope(viewer) {
31833
33419
  return viewer.teamIndex === void 0 ? {} : { teamIndex: viewer.teamIndex };
31834
33420
  }
@@ -31977,7 +33563,7 @@ function commandFor(message, surface, viewer) {
31977
33563
  return null;
31978
33564
  }
31979
33565
  }
31980
- function queryFor(message, surface, viewer) {
33566
+ function queryFor(message, surface, viewer, { sessionless = false } = {}) {
31981
33567
  if (!FRAME_QUERIES[surface.kind].has(message.type)) return null;
31982
33568
  switch (message.type) {
31983
33569
  case "callEndpoint":
@@ -32004,6 +33590,28 @@ function queryFor(message, surface, viewer) {
32004
33590
  };
32005
33591
  case "getAllTeamsParticipants":
32006
33592
  return { type: "getAllTeamsParticipants", uiIdentifier: surface.identifier };
33593
+ case "getBenchmark":
33594
+ return {
33595
+ type: "getBenchmark",
33596
+ identifier: String(message.identifier),
33597
+ where: Array.isArray(message.where) ? message.where : []
33598
+ };
33599
+ // The audience is the host's to decide, from the surface and the viewer
33600
+ // it holds the render as, never from anything the page sends.
33601
+ case "getAssessment":
33602
+ if (sessionless) {
33603
+ return { refused: "A presentation shown without a session has no results to read" };
33604
+ }
33605
+ return {
33606
+ type: "getAssessment",
33607
+ identifier: String(message.identifier),
33608
+ ...PLAYER_SURFACES.has(surface.kind) ? {
33609
+ audience: "own",
33610
+ ...actorOf(viewer),
33611
+ ...roleOf(viewer),
33612
+ ...viewer.teamIndex === void 0 ? {} : { teamId: `team-${viewer.teamIndex + 1}` }
33613
+ } : { audience: "all" }
33614
+ };
32007
33615
  default:
32008
33616
  return null;
32009
33617
  }
@@ -32185,6 +33793,8 @@ var DevShell = class {
32185
33793
  socketRuns = /* @__PURE__ */ new WeakMap();
32186
33794
  /** The participant an operator page says it is showing, where it shows one. */
32187
33795
  socketPresence = /* @__PURE__ */ new Map();
33796
+ /** Console pages open, each of which keeps its run awake (§11.4a). */
33797
+ consoleSockets = /* @__PURE__ */ new Set();
32188
33798
  options;
32189
33799
  brands;
32190
33800
  server = null;
@@ -32246,7 +33856,7 @@ var DevShell = class {
32246
33856
  throw new Error(`No built surfaces at ${built}: build them first`);
32247
33857
  }
32248
33858
  if (this.options.isolated) {
32249
- const dir = await mkdtemp3(join20(tmpdir3(), "seriousgaming-dev-blobs-"));
33859
+ const dir = await mkdtemp3(join21(tmpdir3(), "seriousgaming-dev-blobs-"));
32250
33860
  this.isolatedBlobs = { dir, restore: redirectBlobs(this.options.packagePath, dir) };
32251
33861
  }
32252
33862
  try {
@@ -32335,9 +33945,9 @@ var DevShell = class {
32335
33945
  return;
32336
33946
  }
32337
33947
  void this.walkthrough?.reloadBundles();
32338
- void this.session.reloadBundles().then((outcome) => {
32339
- this.record(outcome);
32340
- reportReload(outcome);
33948
+ void this.session.reloadBundles().then((outcome3) => {
33949
+ this.record(outcome3);
33950
+ reportReload(outcome3);
32341
33951
  });
32342
33952
  }
32343
33953
  /**
@@ -32378,10 +33988,10 @@ var DevShell = class {
32378
33988
  }
32379
33989
  }
32380
33990
  /** Keep what a reload could not apply, for the next command to be told. */
32381
- record(outcome) {
32382
- if (outcome.kind !== "failed") this.reloadFailure = null;
32383
- if (outcome.kind === "reinitialised") this.seeded.clear();
32384
- else for (const capability of outcome.added) this.seeded.add(capability);
33991
+ record(outcome3) {
33992
+ if (outcome3.kind !== "failed") this.reloadFailure = null;
33993
+ if (outcome3.kind === "reinitialised") this.seeded.clear();
33994
+ else for (const capability of outcome3.added) this.seeded.add(capability);
32385
33995
  }
32386
33996
  /**
32387
33997
  * Everything this server could not apply live to `run`, as it stands now:
@@ -32634,7 +34244,7 @@ Install the package's dependencies and restart.`
32634
34244
  const slot2 = SURFACE_SLOT[kind2];
32635
34245
  this.assetApp.use(
32636
34246
  `${SURFACE_PREFIX[kind2]}/${slot2}`,
32637
- express2.static(join20(directory, slot2), { index: false })
34247
+ express2.static(join21(directory, slot2), { index: false })
32638
34248
  );
32639
34249
  }
32640
34250
  this.assetApp.use((req, res) => {
@@ -32786,22 +34396,30 @@ Install the package's dependencies to serve its surfaces.
32786
34396
  host: request.headers.host,
32787
34397
  localOrigins: wantsLocalOrigins(location.search)
32788
34398
  });
32789
- void this.sendView(socket).then(() => this.syncPresence(route.run));
34399
+ void this.sendView(socket).then(() => {
34400
+ this.syncPresence(route.run);
34401
+ this.syncOpenSurfaces(route.run);
34402
+ });
32790
34403
  socket.on("message", (raw) => void this.receiveView(socket, raw));
32791
34404
  socket.on("close", () => {
32792
34405
  this.views.delete(socket);
32793
34406
  this.syncPresence(route.run);
34407
+ this.syncOpenSurfaces(route.run);
32794
34408
  });
32795
34409
  });
32796
34410
  this.sockets.on("connection", (socket, request) => {
32797
34411
  const run = runFromUrl(request.url);
32798
34412
  this.socketRuns.set(socket, run);
34413
+ this.consoleSockets.add(socket);
32799
34414
  void this.runFor(run).then((session) => {
32800
34415
  send(socket, { type: "state", state: session.project(), cause: "connected" });
34416
+ this.syncOpenSurfaces(run);
32801
34417
  });
32802
34418
  socket.on("message", (raw) => void this.receive(socket, raw));
32803
34419
  socket.on("close", () => {
34420
+ this.consoleSockets.delete(socket);
32804
34421
  if (this.socketPresence.delete(socket)) this.syncPresence(run);
34422
+ this.syncOpenSurfaces(run);
32805
34423
  });
32806
34424
  });
32807
34425
  }
@@ -32931,6 +34549,23 @@ Install the package's dependencies to serve its surfaces.
32931
34549
  }
32932
34550
  session.syncPresence(present);
32933
34551
  }
34552
+ /**
34553
+ * Tell a run how many pages are open on it, console and viewer alike.
34554
+ * Opening one is activity, and the dev server keeps a run with any open
34555
+ * awake (§11.4a), which the specification leaves to the host.
34556
+ */
34557
+ syncOpenSurfaces(run) {
34558
+ const session = run === "walkthrough" ? this.walkthrough : this.session;
34559
+ if (!session) return;
34560
+ let count = 0;
34561
+ for (const socket of this.consoleSockets) {
34562
+ if ((this.socketRuns.get(socket) ?? "session") === run) count += 1;
34563
+ }
34564
+ for (const view of this.views.values()) {
34565
+ if (view.route.run === run) count += 1;
34566
+ }
34567
+ session.syncOpenSurfaces(count);
34568
+ }
32934
34569
  updateViews(event, run) {
32935
34570
  if (event.type === "round-processing") {
32936
34571
  const teams = this.processing.get(run) ?? /* @__PURE__ */ new Set();
@@ -33061,28 +34696,28 @@ Install the package's dependencies to serve its surfaces.
33061
34696
  );
33062
34697
  }
33063
34698
  };
33064
- function reportReload(outcome) {
33065
- switch (outcome.kind) {
34699
+ function reportReload(outcome3) {
34700
+ switch (outcome3.kind) {
33066
34701
  case "failed":
33067
34702
  return;
33068
34703
  case "reinitialised":
33069
- if (hasPendingChanges(outcome.pending)) {
34704
+ if (hasPendingChanges(outcome3.pending)) {
33070
34705
  logger.success(
33071
- `${describePendingChanges(outcome.pending)}. Re-initialised the session at tick 0 to apply it.`
34706
+ `${describePendingChanges(outcome3.pending)}. Re-initialised the session at tick 0 to apply it.`
33072
34707
  );
33073
34708
  }
33074
- for (const capability of outcome.added) {
34709
+ for (const capability of outcome3.added) {
33075
34710
  logger.success(
33076
34711
  `Capability "${capability}" added. Re-initialised the session at tick 0 so Init runs for it.`
33077
34712
  );
33078
34713
  }
33079
- if (!hasPendingChanges(outcome.pending) && outcome.added.length === 0) {
34714
+ if (!hasPendingChanges(outcome3.pending) && outcome3.added.length === 0) {
33080
34715
  logger.success("Package changed; re-initialised the session at tick 0.");
33081
34716
  }
33082
34717
  return;
33083
34718
  case "pending":
33084
34719
  logger.warn(
33085
- `${pendingHeadline(outcome.pending)}. ${describePendingChanges(outcome.pending)}.
34720
+ `${pendingHeadline(outcome3.pending)}. ${describePendingChanges(outcome3.pending)}.
33086
34721
  ` + PENDING_CHANGES_HINT
33087
34722
  );
33088
34723
  break;
@@ -33090,7 +34725,7 @@ function reportReload(outcome) {
33090
34725
  logger.success("Package changed; the session uses it from here.");
33091
34726
  break;
33092
34727
  }
33093
- for (const capability of outcome.added) logger.warn(seededMessage(capability));
34728
+ for (const capability of outcome3.added) logger.warn(seededMessage(capability));
33094
34729
  }
33095
34730
  function buildErrorLine(error) {
33096
34731
  const at = diagnosticLocation(error);
@@ -33133,7 +34768,7 @@ function hmrConnectSources(host, vitePort) {
33133
34768
 
33134
34769
  // cli/utils/env-loader.ts
33135
34770
  import { readFileSync as readFileSync11, existsSync as existsSync20 } from "fs";
33136
- import { join as join22 } from "path";
34771
+ import { join as join23 } from "path";
33137
34772
 
33138
34773
  // cli/utils/global-settings.ts
33139
34774
  import {
@@ -33146,7 +34781,7 @@ import {
33146
34781
  writeFileSync
33147
34782
  } from "fs";
33148
34783
  import { homedir } from "os";
33149
- import { dirname as dirname12, isAbsolute as isAbsolute11, join as join21 } from "path";
34784
+ import { dirname as dirname12, isAbsolute as isAbsolute11, join as join22 } from "path";
33150
34785
  var GLOBAL_SETTINGS_ENV_VAR = "SERIOUSGAMING_SDK_CONFIG";
33151
34786
  function resolveGlobalSettingsPath() {
33152
34787
  const override = process.env[GLOBAL_SETTINGS_ENV_VAR];
@@ -33159,7 +34794,7 @@ function resolveGlobalSettingsPath() {
33159
34794
  }
33160
34795
  return override;
33161
34796
  }
33162
- return join21(homedir(), ".seriousgaming-sdk", "config.json");
34797
+ return join22(homedir(), ".seriousgaming-sdk", "config.json");
33163
34798
  }
33164
34799
  function loadGlobalSettings(path3 = resolveGlobalSettingsPath()) {
33165
34800
  if (!existsSync19(path3)) {
@@ -33207,7 +34842,7 @@ function loadEnvironmentConfig(workingDir, flags) {
33207
34842
  const config = {};
33208
34843
  const ttsVoicePresets = {};
33209
34844
  applyGlobalSettings(config);
33210
- const envPath = join22(workingDir, ".env");
34845
+ const envPath = join23(workingDir, ".env");
33211
34846
  if (existsSync20(envPath)) {
33212
34847
  try {
33213
34848
  const content3 = readFileSync11(envPath, "utf-8");