@seriousgaming/sdk-tools 1.10.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.
- package/dist/agent/guidance.md +35 -23
- package/dist/{cli-F2D4GGUA.js → cli-2BKEIIA3.js} +66 -0
- package/dist/{cli-NQSL2CIH.js → cli-2QGTDHRX.js} +21 -21
- package/dist/{cli-33MZSPPK.js → cli-2SDG3SZ7.js} +21 -21
- package/dist/{cli-CLO7HKEQ.js → cli-2VXP34R5.js} +5 -3
- package/dist/{cli-P3NUTOPK.js → cli-2W4B6PD5.js} +1 -1
- package/dist/{cli-SOO6SEIS.js → cli-2X7DKSXN.js} +28 -25
- package/dist/{cli-LNEZ6KDW.js → cli-2ZP4N7HK.js} +19 -19
- package/dist/{cli-5O7XENQY.js → cli-3GJYZH4C.js} +5 -5
- package/dist/{cli-NAZTYKZT.js → cli-3GO3M2MX.js} +30 -14
- package/dist/{cli-YZJBFKRI.js → cli-3LDLUNME.js} +17 -17
- package/dist/{cli-J42N4PJG.js → cli-3WY6L2WP.js} +31 -29
- package/dist/{cli-WG7MAOCS.js → cli-44MBABRD.js} +25 -25
- package/dist/{cli-MGZYQDCH.js → cli-4IO7MKLR.js} +20 -20
- package/dist/{cli-HNDFANQG.js → cli-4U2PY7W3.js} +1 -1
- package/dist/{cli-4JNF3O5N.js → cli-4WI4LTBI.js} +2 -2
- package/dist/{cli-OTBCA54D.js → cli-55EIGGZK.js} +1 -1
- package/dist/{cli-5TKPT3CY.js → cli-5AQV6FTL.js} +18 -18
- package/dist/{cli-KNXY43YV.js → cli-5CW7BEU7.js} +3 -3
- package/dist/{cli-5V4N4BR4.js → cli-5JUVHNZF.js} +12 -12
- package/dist/{cli-F3YJKP6D.js → cli-5KERL6HV.js} +9 -4
- package/dist/{cli-HN442ZVK.js → cli-5KSA24NQ.js} +24 -24
- package/dist/{cli-5VZBFMCK.js → cli-5PIFO3EN.js} +8 -0
- package/dist/{cli-IQBY7Z7Q.js → cli-5QN2Z43X.js} +20 -20
- package/dist/cli-5XSPAA5X.js +69 -0
- package/dist/{cli-QW7VXL2V.js → cli-62KAYGXO.js} +20 -20
- package/dist/{cli-TDLIPYKT.js → cli-6IMV5ZZU.js} +26 -26
- package/dist/{cli-UULZSQBV.js → cli-6KWCIAN2.js} +764 -66
- package/dist/{cli-2ANX6E3A.js → cli-6NWETIX5.js} +20 -20
- package/dist/{cli-EXUPHPDJ.js → cli-774W3MN5.js} +26 -26
- package/dist/cli-7BUD3VAD.js +16 -0
- package/dist/{cli-7NUFHMGE.js → cli-7KEP57S7.js} +12 -12
- package/dist/{cli-6CYAOUYT.js → cli-7OYFJMA6.js} +18 -18
- package/dist/{cli-ILHHJR2S.js → cli-7ZNEDQ3G.js} +20 -20
- package/dist/{cli-5RRPUL6V.js → cli-AFK6OUID.js} +12 -12
- package/dist/{cli-A3AJQZEN.js → cli-AIYQFWXN.js} +25 -25
- package/dist/{cli-B5DWKRZ4.js → cli-ARAAEWIQ.js} +2 -2
- package/dist/cli-AVQYV3N4.js +36 -0
- package/dist/{cli-35GV2F6R.js → cli-B54Z6CXH.js} +16 -16
- package/dist/{cli-467VRXGP.js → cli-B5TC4MEL.js} +5 -5
- package/dist/{cli-5Z4D3F6Y.js → cli-BCXGOLU3.js} +3 -3
- package/dist/{cli-G2GLW5Z4.js → cli-BHAODVTZ.js} +1 -1
- package/dist/{cli-XR3O2YTV.js → cli-BPS2JG74.js} +20 -20
- package/dist/{cli-W3RG2MRI.js → cli-BVO55SR2.js} +2 -2
- package/dist/{cli-PYAST3G5.js → cli-CFH3JZP5.js} +21 -21
- package/dist/{cli-VZVHS5AP.js → cli-CTK2OIK6.js} +20 -20
- package/dist/{cli-ATWJCB2G.js → cli-CW5MV4VX.js} +4 -4
- package/dist/{cli-TCQJL2GY.js → cli-D5VOSJZ7.js} +1 -1
- package/dist/{cli-KIZTASLL.js → cli-DAEPMK7A.js} +5 -5
- package/dist/{cli-44CM2AH2.js → cli-DAHR7PKB.js} +1 -1
- package/dist/{cli-XW3JLRSA.js → cli-DWDSBTYL.js} +1 -1
- package/dist/cli-DYSDPGXW.js +95 -0
- package/dist/{cli-GRSQRFRG.js → cli-DZCLRZXJ.js} +9 -2
- package/dist/{cli-RSF5R3HC.js → cli-EJ47IE45.js} +28 -25
- package/dist/{cli-QDBYFITU.js → cli-EK4OSJHA.js} +2 -2
- package/dist/{cli-GO64NABP.js → cli-FCJHNXDA.js} +1 -1
- package/dist/{cli-ZNQBF4Z3.js → cli-FNESSE3L.js} +1 -1
- package/dist/{cli-MUOLHQNL.js → cli-FTLH4WCE.js} +17 -17
- package/dist/{cli-JHLWBRXB.js → cli-FYV77YS2.js} +18 -18
- package/dist/cli-GMJX6Q4Q.js +36 -0
- package/dist/{cli-7JUNA74L.js → cli-GRBVNGDW.js} +1 -1
- package/dist/{cli-XKAIDYIE.js → cli-HAFCFY77.js} +33 -19
- package/dist/{cli-OXLOGXT3.js → cli-HCJLYI24.js} +3 -3
- package/dist/{cli-HHRP6FP6.js → cli-HCXS5EXU.js} +25 -25
- package/dist/cli-HEUNNHDH.js +36 -0
- package/dist/{cli-36GABN2A.js → cli-HNUTIWDZ.js} +19 -19
- package/dist/{cli-JXQLHJO2.js → cli-HXT25ETJ.js} +244 -243
- package/dist/{cli-5EH4WTH4.js → cli-IGEL7UJQ.js} +5 -5
- package/dist/{cli-JMNPMDXH.js → cli-IO32YA5N.js} +26 -26
- package/dist/cli-IPTGZDBB.js +36 -0
- package/dist/{cli-L54SXUK6.js → cli-J25TYFKB.js} +19 -19
- package/dist/{cli-CQ4ZR3ZQ.js → cli-J7XYMEMX.js} +20 -20
- package/dist/{cli-5DWR7RPQ.js → cli-JC5OJRID.js} +2 -2
- package/dist/{cli-25SJZI7N.js → cli-JD563OF4.js} +126 -27
- package/dist/{cli-JAVMRERQ.js → cli-JRJF2WHU.js} +20 -20
- package/dist/{cli-UQC46YSV.js → cli-JTFLIMIG.js} +3 -3
- package/dist/{cli-2AH6D32V.js → cli-K2BSJ2PK.js} +2 -2
- package/dist/{cli-XB5PI2XT.js → cli-K4QTYMN2.js} +25 -25
- package/dist/{cli-5SHG2M7E.js → cli-KFJDD4C4.js} +20 -20
- package/dist/{cli-WW54THXN.js → cli-KVQ2JPVD.js} +1 -1
- package/dist/{cli-O5WYATAI.js → cli-L6AHMW2Z.js} +4 -2
- package/dist/{cli-IKSLPAZN.js → cli-LCYUBCVY.js} +4 -4
- package/dist/{cli-HGCOEL5T.js → cli-LEWSCDH5.js} +4 -4
- package/dist/{cli-HNG6PZW2.js → cli-LI6G7GND.js} +27 -27
- package/dist/{cli-2AVPNSAX.js → cli-LU2GCWIU.js} +21 -21
- package/dist/{cli-UEQMK4WX.js → cli-M3Z2KOEB.js} +1 -1
- package/dist/{cli-226ZJ72R.js → cli-M6E3E3I2.js} +170 -3
- package/dist/{cli-OXU6TTEN.js → cli-MCRPA4Z6.js} +20 -20
- package/dist/{cli-BQ36DV5C.js → cli-MI2DEDMA.js} +3 -3
- package/dist/{cli-6O7YCK2M.js → cli-MITZ6SE7.js} +3 -3
- package/dist/{cli-VALLLE6Y.js → cli-MTIYD3BX.js} +26 -26
- package/dist/{cli-5M6KDNVX.js → cli-MTZUJGBK.js} +2 -2
- package/dist/{cli-GSOV26O5.js → cli-NCLMUXLC.js} +14 -14
- package/dist/{cli-Z3DITVBE.js → cli-NLS3DKWH.js} +26 -26
- package/dist/{cli-AH6AMAIB.js → cli-NMDGS7IE.js} +1 -1
- package/dist/cli-O3DJO2CS.js +30 -0
- package/dist/{cli-BC67QHD5.js → cli-O47D5BFN.js} +2 -2
- package/dist/{cli-MDVC5ZNM.js → cli-OBRZ36VP.js} +14 -14
- package/dist/{cli-267QJ2DS.js → cli-OMG4E53H.js} +20 -20
- package/dist/{cli-C32Q5E5I.js → cli-P6V3NSU4.js} +1 -1
- package/dist/{cli-PBSLPO6G.js → cli-PAMQMTHK.js} +21 -21
- package/dist/{cli-RUEPTOWG.js → cli-PKTHOCT3.js} +26 -26
- package/dist/{cli-PTXOKO2Y.js → cli-QK7QAP5H.js} +18 -18
- package/dist/cli-QQ432JEN.js +36 -0
- package/dist/{cli-YFLQ7XOO.js → cli-QVNDPTBU.js} +20 -20
- package/dist/{cli-KJA6GLZI.js → cli-R2DFD6ZZ.js} +15 -15
- package/dist/{cli-6BLVI2JM.js → cli-RMVJMOWU.js} +111 -7
- package/dist/{cli-M6AZFIMV.js → cli-RQISHMJF.js} +88 -23
- package/dist/{cli-X64BNBQH.js → cli-RVZH462G.js} +585 -8
- package/dist/{cli-LLJQI2QP.js → cli-SEEOQVUL.js} +12 -12
- package/dist/{cli-QTCTWYCM.js → cli-SO354HPI.js} +3 -3
- package/dist/{cli-URCHZDTS.js → cli-T76HDH7F.js} +90 -5
- package/dist/{cli-ZJW6HQ6N.js → cli-TIS7DWRR.js} +7 -7
- package/dist/{cli-WOFYI7HZ.js → cli-TY3B6XS7.js} +21 -21
- package/dist/{cli-4FJL3KQZ.js → cli-UKEZJFIT.js} +2 -2
- package/dist/cli-VQAMW4RF.js +95 -0
- package/dist/{cli-4A7RWFNO.js → cli-W4LMRVZT.js} +78 -47
- package/dist/cli-W7I5KGIB.js +84 -0
- package/dist/{cli-B3EFE7ZF.js → cli-WXGJFA4F.js} +1 -1
- package/dist/{cli-IPTHJT3J.js → cli-XCG33I77.js} +28 -25
- package/dist/{cli-WLSACMYA.js → cli-YHLSG5HB.js} +30 -28
- package/dist/cli-YNH5DTHY.js +36 -0
- package/dist/cli-YPMJWPDA.js +69 -0
- package/dist/{cli-PXQYY6KM.js → cli-YSXIR7EM.js} +0 -0
- package/dist/cli-ZPFWO4VW.js +85 -0
- package/dist/cli.js +53 -53
- package/dist/client/index.d.ts +1 -1
- package/dist/client/test-session.d.ts +44 -6
- package/dist/client.js +1934 -286
- package/dist/core/assessment-moves.d.ts +32 -0
- package/dist/core/assessment-reports.d.ts +38 -0
- package/dist/core/assessment-settings.d.ts +15 -0
- package/dist/core/benchmark-samples.d.ts +28 -0
- package/dist/core/session-host.d.ts +4 -0
- package/dist/core/session-roster.d.ts +6 -0
- package/dist/core/session-timers.d.ts +40 -0
- package/dist/core/session.d.ts +14 -1
- package/dist/core/tick-timer.d.ts +18 -0
- package/dist/dev/console/assets/{index-Ch6HHb2T.js → index-zd--5H1f.js} +26 -26
- package/dist/dev/console/index.html +1 -1
- package/dist/dev/shell.d.ts +8 -0
- package/dist/dev/view/commands.d.ts +3 -1
- package/dist/docs/api/index.md +4 -2
- package/dist/docs/api/sdk-commands.md +29 -0
- package/dist/docs/api/sdk-e2e.md +30 -0
- package/dist/docs/api/sdk-projection.md +5 -0
- package/dist/docs/api/sdk-tools-client.md +68 -6
- package/dist/docs/api/sdk-tools-vite.md +21 -0
- package/dist/docs/api/sdk-ui.md +7 -0
- package/dist/docs/api/sdk.md +834 -19
- package/dist/docs/changelog.md +67 -0
- package/dist/docs/cli-error-codes.md +5 -1
- package/dist/docs/cli-reference.md +76 -2
- package/dist/docs/concepts/index.md +2 -0
- package/dist/docs/concepts/terminology.md +12 -0
- package/dist/docs/guides/assessments.md +248 -0
- package/dist/docs/guides/benchmarks.md +241 -0
- package/dist/docs/guides/endpoints.md +1 -1
- package/dist/docs/guides/engine-testing.md +49 -14
- package/dist/docs/guides/engine.md +10 -2
- package/dist/docs/guides/index.md +2 -0
- package/dist/docs/guides/presentation.md +11 -9
- package/dist/docs/guides/session-hooks.md +24 -22
- package/dist/docs/guides/testing.md +3 -8
- package/dist/docs/guides/tick-controller.md +22 -1
- package/dist/docs/guides/ui.md +24 -0
- package/dist/docs/guides/upgrading.md +36 -0
- package/dist/docs/page-index.md +18 -13
- package/dist/docs/recipes/create-assessment.md +124 -0
- package/dist/docs/recipes/create-benchmark.md +115 -0
- package/dist/docs/recipes/create-game.md +1 -1
- package/dist/docs/recipes/fix-duplicate-packages.md +8 -19
- package/dist/docs/recipes/index.md +2 -0
- package/dist/execution/context-composition.d.ts +39 -4
- package/dist/execution/engine-state.d.ts +13 -0
- package/dist/execution/executor.d.ts +16 -0
- package/dist/execution/logic-result.d.ts +13 -2
- package/dist/help-examples.d.ts +12 -0
- package/dist/host/adapter.d.ts +24 -1
- package/dist/host/protocol.d.ts +115 -1
- package/dist/host.js +29 -1
- package/dist/oxlint/logic.json +184 -0
- package/dist/playwright.js +1928 -280
- package/dist/runtime/index.d.ts +3 -1
- package/dist/runtime/manifest-version.d.ts +1 -1
- package/dist/runtime.js +298 -16
- package/dist/schema.json +189 -0
- package/dist/templates/package/README.md.liquid +1 -0
- package/dist/templates/package/claude/rules/workflow-create-engine.md +1 -1
- package/dist/templates/package/claude/rules/workflow-create-user-interface.md +1 -1
- package/dist/templates/package/claude/rules/workflow-test-engine-or-ui.md +1 -1
- package/dist/templates/package/claude/rules/workflow-update-sdk-version.md +2 -2
- package/dist/templates/package/claude/settings.json.template +1 -0
- package/dist/templates/package/oxfmtrc.json.template +8 -1
- package/dist/templates/package/oxlintrc.json.template +1 -180
- package/dist/templates/package/package.json.liquid +1 -0
- package/dist/templates/package/vite.config.ts.liquid +2 -8
- package/dist/templates/package/vitest.config.ts.liquid +2 -8
- package/dist/templates/starter-game/package.json +2 -1
- package/dist/templates/starter-game/testing/engine/game.engine.test.ts +62 -37
- package/dist/templates/starter-game/vite.config.ts +2 -8
- package/dist/templates/starter-game/vitest.config.ts +4 -3
- package/dist/templating/resource-metadata.d.ts +1 -1
- package/dist/utils/error-codes.d.ts +9 -1
- package/dist/utils/resource-scan.d.ts +5 -0
- package/dist/validation/assessment-validation.d.ts +34 -0
- package/dist/validation/benchmark-validation.d.ts +20 -0
- package/dist/validation/schema-validation.d.ts +4 -0
- package/dist/vite/index.d.ts +30 -0
- package/dist/vite.js +12 -0
- package/package.json +12 -4
- package/dist/cli-27Z5T52R.js +0 -30
- package/dist/cli-5XE4OMFL.js +0 -36
- package/dist/cli-BB6CU4ZC.js +0 -36
- package/dist/cli-FGP6YYM7.js +0 -36
- package/dist/cli-I3ZAZYWP.js +0 -36
- package/dist/cli-RFAPPYXK.js +0 -36
- package/dist/cli-WZNIW6ZO.js +0 -16
- package/dist/cli-XEEOJGBL.js +0 -36
|
@@ -3,8 +3,9 @@ import {
|
|
|
3
3
|
fileSettingWriteErrors,
|
|
4
4
|
isChapterEmpty,
|
|
5
5
|
referenceLocale,
|
|
6
|
-
resolveBlobInputs
|
|
7
|
-
|
|
6
|
+
resolveBlobInputs,
|
|
7
|
+
resolvedBandProblems
|
|
8
|
+
} from "./cli-M6E3E3I2.js";
|
|
8
9
|
import {
|
|
9
10
|
validateTickControllerResult
|
|
10
11
|
} from "./cli-4LKXZQ2B.js";
|
|
@@ -32,26 +33,37 @@ import {
|
|
|
32
33
|
resolveCapabilityScope,
|
|
33
34
|
runScenarioGates,
|
|
34
35
|
withOverrunRetry
|
|
35
|
-
} from "./cli-
|
|
36
|
-
import {
|
|
37
|
-
deleteBlobs,
|
|
38
|
-
describeBlob,
|
|
39
|
-
readBlob,
|
|
40
|
-
storeBlob
|
|
41
|
-
} from "./cli-QWQMPCL6.js";
|
|
36
|
+
} from "./cli-HXT25ETJ.js";
|
|
42
37
|
import {
|
|
38
|
+
ASSESSMENTS_SETTINGS,
|
|
43
39
|
DeniedError,
|
|
44
40
|
GAME_SETTINGS,
|
|
45
41
|
RESOURCE_METADATA,
|
|
46
42
|
Transpile,
|
|
43
|
+
applyBenchmarkWrite,
|
|
44
|
+
benchmarkFilters,
|
|
45
|
+
benchmarkWriteProblem,
|
|
46
|
+
buildAssessmentReport,
|
|
47
47
|
collectSettingsOverrideErrors,
|
|
48
48
|
createAjv,
|
|
49
49
|
errorMessage,
|
|
50
|
+
foldAssessmentWrite,
|
|
50
51
|
gameSettingsOf,
|
|
51
52
|
loadConfig,
|
|
53
|
+
resolveAssessmentBands,
|
|
54
|
+
resolveBenchmarkLevel,
|
|
52
55
|
settingsSchemas,
|
|
53
56
|
validateSessionOverrides
|
|
54
|
-
} from "./cli-
|
|
57
|
+
} from "./cli-RVZH462G.js";
|
|
58
|
+
import {
|
|
59
|
+
deleteBlobs,
|
|
60
|
+
describeBlob,
|
|
61
|
+
readBlob,
|
|
62
|
+
storeBlob
|
|
63
|
+
} from "./cli-QWQMPCL6.js";
|
|
64
|
+
import {
|
|
65
|
+
logger
|
|
66
|
+
} from "./cli-D5VOSJZ7.js";
|
|
55
67
|
|
|
56
68
|
// cli/execution/configuration-builder.ts
|
|
57
69
|
import { existsSync, readFileSync } from "fs";
|
|
@@ -248,7 +260,9 @@ var IDLE_TIMER = {
|
|
|
248
260
|
pausedAt: null,
|
|
249
261
|
pausedMs: 0,
|
|
250
262
|
extendedMs: 0,
|
|
251
|
-
scheduleStartedAt: null
|
|
263
|
+
scheduleStartedAt: null,
|
|
264
|
+
dormant: false,
|
|
265
|
+
dormantAt: null
|
|
252
266
|
};
|
|
253
267
|
function scheduleFor(result, now) {
|
|
254
268
|
const problem = validateTickControllerResult(result, { now });
|
|
@@ -294,6 +308,8 @@ var TickTimer = class {
|
|
|
294
308
|
pausedMs = 0;
|
|
295
309
|
scheduleStartedAt = null;
|
|
296
310
|
extendedMs = 0;
|
|
311
|
+
/** When the session went dormant (§11.4a), or null while it is not. */
|
|
312
|
+
dormantAt = null;
|
|
297
313
|
/** The answer the current schedule was built from, to tell a re-evaluation that changed nothing. */
|
|
298
314
|
answer = null;
|
|
299
315
|
/**
|
|
@@ -333,7 +349,7 @@ var TickTimer = class {
|
|
|
333
349
|
this.intervalMs = schedule.intervalMs;
|
|
334
350
|
this.usedNextTickAt = schedule.usedNextTickAt;
|
|
335
351
|
this.scheduleStartedAt ??= now;
|
|
336
|
-
if (this.paused) {
|
|
352
|
+
if (this.paused || this.dormantAt !== null) {
|
|
337
353
|
this.remainingMs = schedule.delayMs;
|
|
338
354
|
return schedule.clamped;
|
|
339
355
|
}
|
|
@@ -345,8 +361,32 @@ var TickTimer = class {
|
|
|
345
361
|
const now = this.clock.now();
|
|
346
362
|
this.paused = true;
|
|
347
363
|
this.pausedAt = now;
|
|
348
|
-
|
|
349
|
-
|
|
364
|
+
if (this.dormantAt === null) this.hold(now);
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Suspend automatic ticking because the session was left unattended
|
|
368
|
+
* (§11.4a). Held like a pause, but separate from one: waking never ends a
|
|
369
|
+
* facilitator's pause.
|
|
370
|
+
*/
|
|
371
|
+
suspend() {
|
|
372
|
+
if (this.dormantAt !== null) return;
|
|
373
|
+
const now = this.clock.now();
|
|
374
|
+
this.dormantAt = now;
|
|
375
|
+
if (!this.paused) this.hold(now);
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Wake from dormancy (§11.4a), resuming as from a pause (§11.4). The
|
|
379
|
+
* dormant time joins `pausedMs`, except where a facilitator's pause
|
|
380
|
+
* already covers it. A timer the facilitator paused stays paused.
|
|
381
|
+
*/
|
|
382
|
+
wake() {
|
|
383
|
+
if (this.dormantAt === null) return "idle";
|
|
384
|
+
const now = this.clock.now();
|
|
385
|
+
const dormantAt = this.dormantAt;
|
|
386
|
+
this.dormantAt = null;
|
|
387
|
+
if (this.paused) return "idle";
|
|
388
|
+
this.pausedMs += now - dormantAt;
|
|
389
|
+
return this.continue(now);
|
|
350
390
|
}
|
|
351
391
|
/**
|
|
352
392
|
* Resume (§11.4). Interval mode continues from the time that was left;
|
|
@@ -359,6 +399,11 @@ var TickTimer = class {
|
|
|
359
399
|
this.paused = false;
|
|
360
400
|
if (this.pausedAt !== null) this.pausedMs += now - this.pausedAt;
|
|
361
401
|
this.pausedAt = null;
|
|
402
|
+
if (this.dormantAt !== null) return "idle";
|
|
403
|
+
return this.continue(now);
|
|
404
|
+
}
|
|
405
|
+
/** Pick a held schedule back up, after a pause or dormancy. */
|
|
406
|
+
continue(now) {
|
|
362
407
|
if (!this.enabled) return "idle";
|
|
363
408
|
if (this.usedNextTickAt) {
|
|
364
409
|
this.remainingMs = null;
|
|
@@ -378,6 +423,9 @@ var TickTimer = class {
|
|
|
378
423
|
if (this.paused) {
|
|
379
424
|
return "The timer is paused, so there is no scheduled tick to move. Resume it first";
|
|
380
425
|
}
|
|
426
|
+
if (this.dormantAt !== null) {
|
|
427
|
+
return "The session is dormant, so there is no scheduled tick to move";
|
|
428
|
+
}
|
|
381
429
|
if (this.dueAt === null) return "No tick is scheduled, so there is no deadline to move";
|
|
382
430
|
const now = this.clock.now();
|
|
383
431
|
const target = Math.max(now, this.dueAt + ms);
|
|
@@ -396,17 +444,25 @@ var TickTimer = class {
|
|
|
396
444
|
this.intervalMs = null;
|
|
397
445
|
}
|
|
398
446
|
state() {
|
|
447
|
+
const held = this.paused || this.dormantAt !== null;
|
|
399
448
|
return {
|
|
400
449
|
enabled: this.enabled,
|
|
401
450
|
paused: this.paused,
|
|
402
|
-
nextTickAt:
|
|
403
|
-
intervalMs: this.enabled && !
|
|
451
|
+
nextTickAt: held ? null : this.dueAt,
|
|
452
|
+
intervalMs: this.enabled && !held ? this.intervalMs : null,
|
|
404
453
|
pausedAt: this.pausedAt,
|
|
405
454
|
pausedMs: this.pausedMs,
|
|
406
455
|
extendedMs: this.extendedMs,
|
|
407
|
-
scheduleStartedAt: this.scheduleStartedAt
|
|
456
|
+
scheduleStartedAt: this.scheduleStartedAt,
|
|
457
|
+
dormant: this.dormantAt !== null,
|
|
458
|
+
dormantAt: this.dormantAt
|
|
408
459
|
};
|
|
409
460
|
}
|
|
461
|
+
/** Keep what is left of this window, and stop the pending tick. */
|
|
462
|
+
hold(now) {
|
|
463
|
+
this.remainingMs = this.dueAt === null ? null : Math.max(0, this.dueAt - now);
|
|
464
|
+
this.cancelPending();
|
|
465
|
+
}
|
|
410
466
|
arm(at) {
|
|
411
467
|
this.cancelPending();
|
|
412
468
|
this.dueAt = at;
|
|
@@ -524,6 +580,8 @@ var QUERY_TYPES = /* @__PURE__ */ new Set([
|
|
|
524
580
|
"callEndpoint",
|
|
525
581
|
"getPastState",
|
|
526
582
|
"getAllTeamsParticipants",
|
|
583
|
+
"getBenchmark",
|
|
584
|
+
"getAssessment",
|
|
527
585
|
"getEndpointAudit",
|
|
528
586
|
"listEndpoints"
|
|
529
587
|
]);
|
|
@@ -595,6 +653,7 @@ var COMMAND_FIELDS = {
|
|
|
595
653
|
resumeTimer: { "teamIndex?": "number" },
|
|
596
654
|
extendTick: { byMs: "number", "teamIndex?": "number" },
|
|
597
655
|
advanceClock: { byMs: "number" },
|
|
656
|
+
makeDormant: {},
|
|
598
657
|
armFault: { fault: "fault", "times?": "number", "reason?": "string" },
|
|
599
658
|
disarmFault: { fault: "fault" },
|
|
600
659
|
// Queries
|
|
@@ -622,6 +681,14 @@ var COMMAND_FIELDS = {
|
|
|
622
681
|
"participantId?": "string",
|
|
623
682
|
"teamId?": "string"
|
|
624
683
|
},
|
|
684
|
+
getBenchmark: { identifier: "string", where: "array" },
|
|
685
|
+
getAssessment: {
|
|
686
|
+
identifier: "string",
|
|
687
|
+
"audience?": "string",
|
|
688
|
+
"participantId?": "string",
|
|
689
|
+
"teamId?": "string",
|
|
690
|
+
"viewerRole?": "viewerRole"
|
|
691
|
+
},
|
|
625
692
|
getEndpointAudit: {},
|
|
626
693
|
listEndpoints: { "external?": "boolean" }
|
|
627
694
|
};
|
|
@@ -693,12 +760,21 @@ var PROJECTION_VERSION = 4;
|
|
|
693
760
|
// cli/execution/engine-state.ts
|
|
694
761
|
var ENGINE_STATE_KEY = "$engineState";
|
|
695
762
|
var SHARED_ENGINE_STATE_KEY = "$sharedEngineState";
|
|
696
|
-
var
|
|
763
|
+
var BENCHMARKS_KEY = "$benchmarks";
|
|
764
|
+
var SHARED_BENCHMARKS_KEY = "$sharedBenchmarks";
|
|
765
|
+
var ASSESSMENTS_KEY = "$assessments";
|
|
766
|
+
var RESERVED_KEYS = /* @__PURE__ */ new Set([
|
|
767
|
+
ENGINE_STATE_KEY,
|
|
768
|
+
SHARED_ENGINE_STATE_KEY,
|
|
769
|
+
BENCHMARKS_KEY,
|
|
770
|
+
SHARED_BENCHMARKS_KEY,
|
|
771
|
+
ASSESSMENTS_KEY
|
|
772
|
+
]);
|
|
697
773
|
function isReservedKey(key) {
|
|
698
774
|
return RESERVED_KEYS.has(key);
|
|
699
775
|
}
|
|
700
776
|
function withoutEngineState(context) {
|
|
701
|
-
if (!(
|
|
777
|
+
if (!Object.keys(context).some(isReservedKey)) return context;
|
|
702
778
|
const rest = {};
|
|
703
779
|
for (const [key, value] of Object.entries(context)) {
|
|
704
780
|
if (!isReservedKey(key)) rest[key] = value;
|
|
@@ -918,17 +994,31 @@ function assertDeletesDeclared(label, deletes, declaration, shared, target) {
|
|
|
918
994
|
}
|
|
919
995
|
}
|
|
920
996
|
}
|
|
921
|
-
function readEngineResult(label, result, phase = "init") {
|
|
922
|
-
const allowed =
|
|
997
|
+
function readEngineResult(label, result, phase = "init", writesBenchmarks = false, writesAssessments = false) {
|
|
998
|
+
const allowed = [
|
|
999
|
+
"capabilities",
|
|
1000
|
+
"deletes",
|
|
1001
|
+
"state",
|
|
1002
|
+
...phase === "tick" ? ["complete"] : [],
|
|
1003
|
+
...writesBenchmarks ? ["benchmarks"] : [],
|
|
1004
|
+
...writesAssessments ? ["assessments"] : []
|
|
1005
|
+
];
|
|
923
1006
|
const capabilities = readCapabilities(label, result, allowed);
|
|
924
1007
|
const deletes = readDeletes(label, result);
|
|
925
|
-
const { state, complete } = result;
|
|
1008
|
+
const { state, complete, benchmarks, assessments } = result;
|
|
926
1009
|
if (complete !== void 0 && typeof complete !== "boolean") {
|
|
927
1010
|
throw new Error(`${label} returned "complete" that is not a boolean`);
|
|
928
1011
|
}
|
|
929
|
-
return {
|
|
1012
|
+
return {
|
|
1013
|
+
capabilities,
|
|
1014
|
+
deletes,
|
|
1015
|
+
state,
|
|
1016
|
+
complete: complete === true,
|
|
1017
|
+
...benchmarks === void 0 ? {} : { benchmarks },
|
|
1018
|
+
...assessments === void 0 ? {} : { assessments }
|
|
1019
|
+
};
|
|
930
1020
|
}
|
|
931
|
-
function readAggregateResult(label, result, teamCount, phase = "init") {
|
|
1021
|
+
function readAggregateResult(label, result, teamCount, phase = "init", writesBenchmarks = false, writesAssessments = false) {
|
|
932
1022
|
if (!isRecord(result)) {
|
|
933
1023
|
throw new Error(
|
|
934
1024
|
`${label} must return { shared: { capabilities }, teams: [{ capabilities }] }`
|
|
@@ -946,9 +1036,21 @@ function readAggregateResult(label, result, teamCount, phase = "init") {
|
|
|
946
1036
|
);
|
|
947
1037
|
}
|
|
948
1038
|
return {
|
|
949
|
-
shared: result.shared === void 0 ? { capabilities: {}, deletes: [], state: void 0, complete: false } : readEngineResult(
|
|
1039
|
+
shared: result.shared === void 0 ? { capabilities: {}, deletes: [], state: void 0, complete: false } : readEngineResult(
|
|
1040
|
+
`${label} "shared"`,
|
|
1041
|
+
result.shared,
|
|
1042
|
+
phase,
|
|
1043
|
+
writesBenchmarks,
|
|
1044
|
+
writesAssessments
|
|
1045
|
+
),
|
|
950
1046
|
teams: result.teams.map(
|
|
951
|
-
(team, i) => readEngineResult(
|
|
1047
|
+
(team, i) => readEngineResult(
|
|
1048
|
+
`${label} "teams[${i}]"`,
|
|
1049
|
+
team,
|
|
1050
|
+
phase,
|
|
1051
|
+
writesBenchmarks,
|
|
1052
|
+
writesAssessments
|
|
1053
|
+
)
|
|
952
1054
|
)
|
|
953
1055
|
};
|
|
954
1056
|
}
|
|
@@ -973,6 +1075,87 @@ function readTickControllerResult(label, result) {
|
|
|
973
1075
|
}
|
|
974
1076
|
|
|
975
1077
|
// cli/execution/context-composition.ts
|
|
1078
|
+
function foldAssessmentWrites(label, raw, current, participantIds, scope) {
|
|
1079
|
+
if (raw === void 0) return void 0;
|
|
1080
|
+
if (!isPlainObject(raw)) {
|
|
1081
|
+
scope.warn(
|
|
1082
|
+
`${label} returned "assessments" that is not an object of writes by assessment. Every assessment write in it was dropped, and the round carried on.`
|
|
1083
|
+
);
|
|
1084
|
+
return void 0;
|
|
1085
|
+
}
|
|
1086
|
+
const writes = structuredClone(raw);
|
|
1087
|
+
const results = structuredClone(isPlainObject(current) ? current : {});
|
|
1088
|
+
for (const [identifier, write] of Object.entries(writes)) {
|
|
1089
|
+
if (write === void 0) continue;
|
|
1090
|
+
const named = `${label} wrote assessment "${identifier}"`;
|
|
1091
|
+
const definition = scope.assessments?.get(identifier);
|
|
1092
|
+
if (!definition) {
|
|
1093
|
+
scope.warn(
|
|
1094
|
+
`${named}, which the engine does not declare in "assessments". The write was dropped.`
|
|
1095
|
+
);
|
|
1096
|
+
continue;
|
|
1097
|
+
}
|
|
1098
|
+
const folded = foldAssessmentWrite(definition, results[identifier], write, participantIds);
|
|
1099
|
+
if ("problem" in folded) {
|
|
1100
|
+
scope.warn(
|
|
1101
|
+
`${named}: ${folded.problem}. The write was dropped, and the round carried on.`
|
|
1102
|
+
);
|
|
1103
|
+
continue;
|
|
1104
|
+
}
|
|
1105
|
+
if (folded.next === void 0) delete results[identifier];
|
|
1106
|
+
else results[identifier] = folded.next;
|
|
1107
|
+
}
|
|
1108
|
+
return results;
|
|
1109
|
+
}
|
|
1110
|
+
function isPlainObject(value) {
|
|
1111
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1112
|
+
}
|
|
1113
|
+
function foldBenchmarkWrites(label, raw, current, level, scope) {
|
|
1114
|
+
if (raw === void 0) return void 0;
|
|
1115
|
+
if (!isPlainObject(raw)) {
|
|
1116
|
+
scope.warn(
|
|
1117
|
+
`${label} returned "benchmarks" that is not an object of writes by benchmark. Every benchmark write in it was dropped, and the round carried on.`
|
|
1118
|
+
);
|
|
1119
|
+
return void 0;
|
|
1120
|
+
}
|
|
1121
|
+
const writes = structuredClone(raw);
|
|
1122
|
+
const records = structuredClone(isPlainObject(current) ? current : {});
|
|
1123
|
+
for (const [identifier, write] of Object.entries(writes)) {
|
|
1124
|
+
if (write === void 0) continue;
|
|
1125
|
+
const named = `${label} wrote benchmark "${identifier}"`;
|
|
1126
|
+
const definition = scope.benchmarks.get(identifier);
|
|
1127
|
+
if (!definition) {
|
|
1128
|
+
scope.warn(
|
|
1129
|
+
`${named}, which the engine does not declare in "benchmarks". The write was dropped.`
|
|
1130
|
+
);
|
|
1131
|
+
continue;
|
|
1132
|
+
}
|
|
1133
|
+
const declaredLevel = resolveBenchmarkLevel(definition);
|
|
1134
|
+
if (declaredLevel !== level) {
|
|
1135
|
+
scope.warn(
|
|
1136
|
+
declaredLevel === "session" ? `${named}, which is session-level, so it is written under an aggregate result's "shared". The write was dropped.` : `${named}, which is per team, so it is written for each team rather than under "shared". The write was dropped.`
|
|
1137
|
+
);
|
|
1138
|
+
continue;
|
|
1139
|
+
}
|
|
1140
|
+
const problem = benchmarkWriteProblem(definition, write);
|
|
1141
|
+
if (problem !== null) {
|
|
1142
|
+
scope.warn(`${named}: ${problem}. The write was dropped, and the round carried on.`);
|
|
1143
|
+
continue;
|
|
1144
|
+
}
|
|
1145
|
+
const next = applyBenchmarkWrite(
|
|
1146
|
+
records[identifier],
|
|
1147
|
+
write
|
|
1148
|
+
);
|
|
1149
|
+
if (next === void 0) delete records[identifier];
|
|
1150
|
+
else records[identifier] = next;
|
|
1151
|
+
}
|
|
1152
|
+
return records;
|
|
1153
|
+
}
|
|
1154
|
+
function storeRecords(target, key, records) {
|
|
1155
|
+
if (records === void 0) return;
|
|
1156
|
+
if (Object.keys(records).length === 0) delete target[key];
|
|
1157
|
+
else target[key] = records;
|
|
1158
|
+
}
|
|
976
1159
|
function mutationAffects(reads, previous, next) {
|
|
977
1160
|
if (!reads || reads.length === 0) return true;
|
|
978
1161
|
return reads.some((capId) => JSON.stringify(previous[capId]) !== JSON.stringify(next[capId]));
|
|
@@ -1028,12 +1211,17 @@ function foldLogicResult(capabilities, deletes, contextBefore, defaults) {
|
|
|
1028
1211
|
const merged = mergeCapabilityFields(capabilities, contextBefore, defaults);
|
|
1029
1212
|
return deletes.length === 0 ? merged : applyContextUpdate(merged, {}, deletes);
|
|
1030
1213
|
}
|
|
1031
|
-
function aggregateArgs(contexts, identities, declaration, store, sharedIds, participants) {
|
|
1214
|
+
function aggregateArgs(contexts, identities, declaration, store, sharedIds, participants, writesBenchmarks = false, writesAssessments = false) {
|
|
1032
1215
|
const shared = projectForLogic(store, declaration);
|
|
1033
1216
|
return {
|
|
1034
1217
|
shared: {
|
|
1035
1218
|
context: structuredClone(shared),
|
|
1036
|
-
state: structuredClone(store[SHARED_ENGINE_STATE_KEY])
|
|
1219
|
+
state: structuredClone(store[SHARED_ENGINE_STATE_KEY]),
|
|
1220
|
+
...writesBenchmarks ? {
|
|
1221
|
+
benchmarks: structuredClone(
|
|
1222
|
+
store[SHARED_BENCHMARKS_KEY] ?? {}
|
|
1223
|
+
)
|
|
1224
|
+
} : {}
|
|
1037
1225
|
},
|
|
1038
1226
|
teams: contexts.map((context, i) => ({
|
|
1039
1227
|
teamId: identities[i].teamId,
|
|
@@ -1043,12 +1231,22 @@ function aggregateArgs(contexts, identities, declaration, store, sharedIds, part
|
|
|
1043
1231
|
([capId]) => !sharedIds.has(capId)
|
|
1044
1232
|
)
|
|
1045
1233
|
),
|
|
1046
|
-
state: structuredClone(context[ENGINE_STATE_KEY])
|
|
1234
|
+
state: structuredClone(context[ENGINE_STATE_KEY]),
|
|
1235
|
+
...writesBenchmarks ? {
|
|
1236
|
+
benchmarks: structuredClone(
|
|
1237
|
+
context[BENCHMARKS_KEY] ?? {}
|
|
1238
|
+
)
|
|
1239
|
+
} : {},
|
|
1240
|
+
...writesAssessments ? {
|
|
1241
|
+
assessments: structuredClone(
|
|
1242
|
+
context[ASSESSMENTS_KEY] ?? {}
|
|
1243
|
+
)
|
|
1244
|
+
} : {}
|
|
1047
1245
|
})),
|
|
1048
1246
|
participants
|
|
1049
1247
|
};
|
|
1050
1248
|
}
|
|
1051
|
-
function applyEngineResult(label, result, contextBefore, scope) {
|
|
1249
|
+
function applyEngineResult(label, result, contextBefore, scope, teamId) {
|
|
1052
1250
|
assertDeletesDeclared(label, result.deletes, scope.engine, new Set(scope.sharedIds), "team");
|
|
1053
1251
|
const merged = foldLogicResult(
|
|
1054
1252
|
result.capabilities,
|
|
@@ -1060,9 +1258,25 @@ function applyEngineResult(label, result, contextBefore, scope) {
|
|
|
1060
1258
|
assertJsonSerialisable(label, result.state);
|
|
1061
1259
|
merged[ENGINE_STATE_KEY] = structuredClone(result.state);
|
|
1062
1260
|
}
|
|
1261
|
+
storeRecords(
|
|
1262
|
+
merged,
|
|
1263
|
+
BENCHMARKS_KEY,
|
|
1264
|
+
foldBenchmarkWrites(label, result.benchmarks, contextBefore[BENCHMARKS_KEY], "team", scope)
|
|
1265
|
+
);
|
|
1266
|
+
storeRecords(
|
|
1267
|
+
merged,
|
|
1268
|
+
ASSESSMENTS_KEY,
|
|
1269
|
+
foldAssessmentWrites(
|
|
1270
|
+
label,
|
|
1271
|
+
result.assessments,
|
|
1272
|
+
contextBefore[ASSESSMENTS_KEY],
|
|
1273
|
+
teamId === void 0 ? /* @__PURE__ */ new Set() : scope.participantIdsOf?.(teamId) ?? /* @__PURE__ */ new Set(),
|
|
1274
|
+
scope
|
|
1275
|
+
)
|
|
1276
|
+
);
|
|
1063
1277
|
return merged;
|
|
1064
1278
|
}
|
|
1065
|
-
function applyAggregateResult(read, contextsBefore, engineIdentifier, phase, scope, store) {
|
|
1279
|
+
function applyAggregateResult(read, contextsBefore, engineIdentifier, phase, scope, store, teamIds = []) {
|
|
1066
1280
|
const label = `Engine "${engineIdentifier}" ${phase}`;
|
|
1067
1281
|
const result = {
|
|
1068
1282
|
shared: read.shared.capabilities,
|
|
@@ -1092,7 +1306,13 @@ function applyAggregateResult(read, contextsBefore, engineIdentifier, phase, sco
|
|
|
1092
1306
|
"shared"
|
|
1093
1307
|
);
|
|
1094
1308
|
const contexts = read.teams.map((team, i) => {
|
|
1095
|
-
const context = applyEngineResult(
|
|
1309
|
+
const context = applyEngineResult(
|
|
1310
|
+
`${label} "teams[${i}]"`,
|
|
1311
|
+
team,
|
|
1312
|
+
contextsBefore[i],
|
|
1313
|
+
scope,
|
|
1314
|
+
teamIds[i]
|
|
1315
|
+
);
|
|
1096
1316
|
enforceDeclaredWrites(
|
|
1097
1317
|
engineIdentifier,
|
|
1098
1318
|
scope.engine,
|
|
@@ -1102,11 +1322,27 @@ function applyAggregateResult(read, contextsBefore, engineIdentifier, phase, sco
|
|
|
1102
1322
|
);
|
|
1103
1323
|
return context;
|
|
1104
1324
|
});
|
|
1325
|
+
if (read.shared.assessments !== void 0) {
|
|
1326
|
+
scope.warn(
|
|
1327
|
+
`${label} "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.`
|
|
1328
|
+
);
|
|
1329
|
+
}
|
|
1105
1330
|
let next = { ...store };
|
|
1106
1331
|
if (read.shared.state !== void 0) {
|
|
1107
1332
|
assertJsonSerialisable(`${label} "shared"`, read.shared.state);
|
|
1108
1333
|
next[SHARED_ENGINE_STATE_KEY] = structuredClone(read.shared.state);
|
|
1109
1334
|
}
|
|
1335
|
+
storeRecords(
|
|
1336
|
+
next,
|
|
1337
|
+
SHARED_BENCHMARKS_KEY,
|
|
1338
|
+
foldBenchmarkWrites(
|
|
1339
|
+
`${label} "shared"`,
|
|
1340
|
+
read.shared.benchmarks,
|
|
1341
|
+
store[SHARED_BENCHMARKS_KEY],
|
|
1342
|
+
"session",
|
|
1343
|
+
scope
|
|
1344
|
+
)
|
|
1345
|
+
);
|
|
1110
1346
|
for (const [capId, sliceValue] of Object.entries(result.shared)) {
|
|
1111
1347
|
const base = next[capId];
|
|
1112
1348
|
const value = sliceValue && typeof sliceValue === "object" && !Array.isArray(sliceValue) && base && typeof base === "object" && !Array.isArray(base) ? {
|
|
@@ -1130,6 +1366,11 @@ function applyAggregateResult(read, contextsBefore, engineIdentifier, phase, sco
|
|
|
1130
1366
|
context[capId] = structuredClone(store[capId]);
|
|
1131
1367
|
}
|
|
1132
1368
|
}
|
|
1369
|
+
if (SHARED_BENCHMARKS_KEY in store) {
|
|
1370
|
+
context[SHARED_BENCHMARKS_KEY] = structuredClone(store[SHARED_BENCHMARKS_KEY]);
|
|
1371
|
+
} else {
|
|
1372
|
+
delete context[SHARED_BENCHMARKS_KEY];
|
|
1373
|
+
}
|
|
1133
1374
|
}
|
|
1134
1375
|
return { contexts, store };
|
|
1135
1376
|
}
|
|
@@ -1805,6 +2046,7 @@ var GameExecutor = class {
|
|
|
1805
2046
|
* contexts it was handed (§11). Read by the session straight after a tick.
|
|
1806
2047
|
*/
|
|
1807
2048
|
lastTickCompletion = [];
|
|
2049
|
+
warnings = [];
|
|
1808
2050
|
waitingRoomOpen = false;
|
|
1809
2051
|
deps;
|
|
1810
2052
|
/** `meta`, the roster, callbacks and bounds: what every logic call shares. */
|
|
@@ -1967,24 +2209,74 @@ var GameExecutor = class {
|
|
|
1967
2209
|
}
|
|
1968
2210
|
/** How a result folds into a board, for the game as it is loaded now. */
|
|
1969
2211
|
composition() {
|
|
2212
|
+
const declared = new Set(this.engine?.definition.benchmarks ?? []);
|
|
2213
|
+
const assessed = new Set(this.engine?.definition.assessments ?? []);
|
|
1970
2214
|
return {
|
|
1971
2215
|
defaults: this.capabilityDefaults,
|
|
1972
2216
|
sharedIds: new Set(this.getSharedCapabilityIds()),
|
|
1973
|
-
engine: this.engine?.definition ?? {}
|
|
2217
|
+
engine: this.engine?.definition ?? {},
|
|
2218
|
+
benchmarks: new Map(
|
|
2219
|
+
(this.config?.benchmarks ?? []).filter((benchmark) => declared.has(benchmark.definition.identifier)).map((benchmark) => [benchmark.definition.identifier, benchmark.definition])
|
|
2220
|
+
),
|
|
2221
|
+
warn: (message) => {
|
|
2222
|
+
logger.warn(message);
|
|
2223
|
+
this.warnings.push(message);
|
|
2224
|
+
},
|
|
2225
|
+
assessments: new Map(
|
|
2226
|
+
(this.config?.assessments ?? []).filter((assessment) => assessed.has(assessment.definition.identifier)).map((assessment) => [assessment.definition.identifier, assessment.definition])
|
|
2227
|
+
),
|
|
2228
|
+
participantIdsOf: (teamId) => new Set(this.calls.participantsOn([teamId]).map((participant) => participant.id))
|
|
2229
|
+
};
|
|
2230
|
+
}
|
|
2231
|
+
/** Whether the engine declares assessments, and so is handed and may return them (§6.17). */
|
|
2232
|
+
writesAssessments() {
|
|
2233
|
+
return (this.engine?.definition.assessments?.length ?? 0) > 0;
|
|
2234
|
+
}
|
|
2235
|
+
/** Whether the engine declares benchmarks, and so is handed and may return them (§6.16). */
|
|
2236
|
+
writesBenchmarks() {
|
|
2237
|
+
return (this.engine?.definition.benchmarks?.length ?? 0) > 0;
|
|
2238
|
+
}
|
|
2239
|
+
/**
|
|
2240
|
+
* The `benchmarks` and `assessments` arguments of an `Init` or `Run` on
|
|
2241
|
+
* `context`: its team's records and results, each passed only to an engine
|
|
2242
|
+
* that declares some.
|
|
2243
|
+
*/
|
|
2244
|
+
recordArgs(context) {
|
|
2245
|
+
return {
|
|
2246
|
+
...this.writesBenchmarks() ? {
|
|
2247
|
+
benchmarks: structuredClone(
|
|
2248
|
+
context[BENCHMARKS_KEY] ?? {}
|
|
2249
|
+
)
|
|
2250
|
+
} : {},
|
|
2251
|
+
...this.writesAssessments() ? {
|
|
2252
|
+
assessments: structuredClone(
|
|
2253
|
+
context[ASSESSMENTS_KEY] ?? {}
|
|
2254
|
+
)
|
|
2255
|
+
} : {}
|
|
1974
2256
|
};
|
|
1975
2257
|
}
|
|
2258
|
+
/**
|
|
2259
|
+
* What went wrong without failing anything since the last call, such as a
|
|
2260
|
+
* benchmark write that was dropped (§6.16), for the operation to report.
|
|
2261
|
+
*/
|
|
2262
|
+
takeWarnings() {
|
|
2263
|
+
const warnings = this.warnings;
|
|
2264
|
+
this.warnings = [];
|
|
2265
|
+
return warnings;
|
|
2266
|
+
}
|
|
1976
2267
|
/**
|
|
1977
2268
|
* Fold an aggregate result into the team contexts and the canonical store.
|
|
1978
2269
|
* See {@link applyAggregateResult}.
|
|
1979
2270
|
*/
|
|
1980
|
-
applyAggregateResult(read, contextsBefore, engineIdentifier, phase) {
|
|
2271
|
+
applyAggregateResult(read, contextsBefore, engineIdentifier, phase, teamIds) {
|
|
1981
2272
|
const { contexts, store } = applyAggregateResult(
|
|
1982
2273
|
read,
|
|
1983
2274
|
contextsBefore,
|
|
1984
2275
|
engineIdentifier,
|
|
1985
2276
|
phase,
|
|
1986
2277
|
this.composition(),
|
|
1987
|
-
this.sharedContext
|
|
2278
|
+
this.sharedContext,
|
|
2279
|
+
teamIds
|
|
1988
2280
|
);
|
|
1989
2281
|
this.sharedContext = store;
|
|
1990
2282
|
return contexts;
|
|
@@ -1997,7 +2289,9 @@ var GameExecutor = class {
|
|
|
1997
2289
|
declaration,
|
|
1998
2290
|
this.sharedContext,
|
|
1999
2291
|
new Set(this.getSharedCapabilityIds()),
|
|
2000
|
-
this.calls.participantsOn(identities.map((identity) => identity.teamId))
|
|
2292
|
+
this.calls.participantsOn(identities.map((identity) => identity.teamId)),
|
|
2293
|
+
this.writesBenchmarks(),
|
|
2294
|
+
this.writesAssessments()
|
|
2001
2295
|
);
|
|
2002
2296
|
}
|
|
2003
2297
|
/**
|
|
@@ -2180,6 +2474,7 @@ var GameExecutor = class {
|
|
|
2180
2474
|
() => run({
|
|
2181
2475
|
context: projectForLogic(contexts[i], engine.definition),
|
|
2182
2476
|
state: contexts[i][ENGINE_STATE_KEY],
|
|
2477
|
+
...this.recordArgs(contexts[i]),
|
|
2183
2478
|
settings: engineSettings,
|
|
2184
2479
|
meta: teamMeta[i],
|
|
2185
2480
|
participants: this.calls.participantsOn([
|
|
@@ -2194,10 +2489,18 @@ var GameExecutor = class {
|
|
|
2194
2489
|
team: identities[i]
|
|
2195
2490
|
}
|
|
2196
2491
|
),
|
|
2197
|
-
"tick"
|
|
2492
|
+
"tick",
|
|
2493
|
+
this.writesBenchmarks(),
|
|
2494
|
+
this.writesAssessments()
|
|
2198
2495
|
);
|
|
2199
2496
|
if (read.complete) completed[i] = true;
|
|
2200
|
-
contexts[i] = applyEngineResult(
|
|
2497
|
+
contexts[i] = applyEngineResult(
|
|
2498
|
+
label,
|
|
2499
|
+
read,
|
|
2500
|
+
contextBefore,
|
|
2501
|
+
this.composition(),
|
|
2502
|
+
identities[i].teamId
|
|
2503
|
+
);
|
|
2201
2504
|
enforceDeclaredWrites(
|
|
2202
2505
|
engineIdentifier,
|
|
2203
2506
|
engine.definition,
|
|
@@ -2237,7 +2540,9 @@ var GameExecutor = class {
|
|
|
2237
2540
|
{ resource: { type: "engine", identifier: engineIdentifier }, tick: tick2 }
|
|
2238
2541
|
),
|
|
2239
2542
|
args.teams.length,
|
|
2240
|
-
"tick"
|
|
2543
|
+
"tick",
|
|
2544
|
+
this.writesBenchmarks(),
|
|
2545
|
+
this.writesAssessments()
|
|
2241
2546
|
);
|
|
2242
2547
|
result.teams.forEach((team, i) => {
|
|
2243
2548
|
if (team.complete || result.shared.complete) completed[i] = true;
|
|
@@ -2246,7 +2551,8 @@ var GameExecutor = class {
|
|
|
2246
2551
|
result,
|
|
2247
2552
|
contextsBefore,
|
|
2248
2553
|
engineIdentifier,
|
|
2249
|
-
"RunAggregate"
|
|
2554
|
+
"RunAggregate",
|
|
2555
|
+
identities.map((identity) => identity.teamId)
|
|
2250
2556
|
);
|
|
2251
2557
|
}
|
|
2252
2558
|
}
|
|
@@ -2325,13 +2631,17 @@ var GameExecutor = class {
|
|
|
2325
2631
|
}),
|
|
2326
2632
|
{ resource: { type: "engine", identifier: engineIdentifier } }
|
|
2327
2633
|
),
|
|
2328
|
-
args.teams.length
|
|
2634
|
+
args.teams.length,
|
|
2635
|
+
"init",
|
|
2636
|
+
this.writesBenchmarks(),
|
|
2637
|
+
this.writesAssessments()
|
|
2329
2638
|
);
|
|
2330
2639
|
contexts = this.applyAggregateResult(
|
|
2331
2640
|
result,
|
|
2332
2641
|
contextsBefore,
|
|
2333
2642
|
engineIdentifier,
|
|
2334
|
-
"InitAggregate"
|
|
2643
|
+
"InitAggregate",
|
|
2644
|
+
identities.map((identity) => identity.teamId)
|
|
2335
2645
|
);
|
|
2336
2646
|
}
|
|
2337
2647
|
this.context = { ...contexts[0] };
|
|
@@ -2367,6 +2677,7 @@ var GameExecutor = class {
|
|
|
2367
2677
|
() => initFn({
|
|
2368
2678
|
context: projectForLogic(before, engine.definition),
|
|
2369
2679
|
state: void 0,
|
|
2680
|
+
...this.recordArgs(before),
|
|
2370
2681
|
settings,
|
|
2371
2682
|
meta: { ...sessionMeta, ...identity },
|
|
2372
2683
|
participants: this.calls.participantsOn([identity.teamId]),
|
|
@@ -2376,9 +2687,18 @@ var GameExecutor = class {
|
|
|
2376
2687
|
resource: { type: "engine", identifier: engine.definition.identifier },
|
|
2377
2688
|
team: identity
|
|
2378
2689
|
}
|
|
2379
|
-
)
|
|
2690
|
+
),
|
|
2691
|
+
"init",
|
|
2692
|
+
this.writesBenchmarks(),
|
|
2693
|
+
this.writesAssessments()
|
|
2694
|
+
);
|
|
2695
|
+
const context = applyEngineResult(
|
|
2696
|
+
label,
|
|
2697
|
+
after,
|
|
2698
|
+
before,
|
|
2699
|
+
this.composition(),
|
|
2700
|
+
identity.teamId
|
|
2380
2701
|
);
|
|
2381
|
-
const context = applyEngineResult(label, after, before, this.composition());
|
|
2382
2702
|
enforceDeclaredWrites(
|
|
2383
2703
|
engine.definition.identifier,
|
|
2384
2704
|
engine.definition,
|
|
@@ -2417,7 +2737,11 @@ var GameExecutor = class {
|
|
|
2417
2737
|
*/
|
|
2418
2738
|
setContext(context) {
|
|
2419
2739
|
this.context = { ...context };
|
|
2420
|
-
for (const capId of [
|
|
2740
|
+
for (const capId of [
|
|
2741
|
+
...this.getSharedCapabilityIds(),
|
|
2742
|
+
SHARED_ENGINE_STATE_KEY,
|
|
2743
|
+
SHARED_BENCHMARKS_KEY
|
|
2744
|
+
]) {
|
|
2421
2745
|
if (capId in context) {
|
|
2422
2746
|
this.sharedContext[capId] = structuredClone(context[capId]);
|
|
2423
2747
|
}
|
|
@@ -2623,6 +2947,7 @@ var GameExecutor = class {
|
|
|
2623
2947
|
() => initFn({
|
|
2624
2948
|
context: projectForLogic(this.context, engine.definition),
|
|
2625
2949
|
state: void 0,
|
|
2950
|
+
...this.recordArgs(this.context),
|
|
2626
2951
|
settings: engineSettings,
|
|
2627
2952
|
meta: teamMeta,
|
|
2628
2953
|
participants: this.calls.participantsOn([teamMeta.teamId]),
|
|
@@ -2632,13 +2957,17 @@ var GameExecutor = class {
|
|
|
2632
2957
|
resource: { type: "engine", identifier: engineIdentifier },
|
|
2633
2958
|
team: { teamId: teamMeta.teamId, index: teamMeta.index }
|
|
2634
2959
|
}
|
|
2635
|
-
)
|
|
2960
|
+
),
|
|
2961
|
+
"init",
|
|
2962
|
+
this.writesBenchmarks(),
|
|
2963
|
+
this.writesAssessments()
|
|
2636
2964
|
);
|
|
2637
2965
|
this.context = applyEngineResult(
|
|
2638
2966
|
initLabel,
|
|
2639
2967
|
initResult,
|
|
2640
2968
|
contextBefore,
|
|
2641
|
-
this.composition()
|
|
2969
|
+
this.composition(),
|
|
2970
|
+
teamMeta.teamId
|
|
2642
2971
|
);
|
|
2643
2972
|
enforceDeclaredWrites(
|
|
2644
2973
|
engineIdentifier,
|
|
@@ -2681,13 +3010,17 @@ var GameExecutor = class {
|
|
|
2681
3010
|
}),
|
|
2682
3011
|
{ resource: { type: "engine", identifier: engineIdentifier } }
|
|
2683
3012
|
),
|
|
2684
|
-
1
|
|
3013
|
+
1,
|
|
3014
|
+
"init",
|
|
3015
|
+
this.writesBenchmarks(),
|
|
3016
|
+
this.writesAssessments()
|
|
2685
3017
|
);
|
|
2686
3018
|
[this.context] = this.applyAggregateResult(
|
|
2687
3019
|
result,
|
|
2688
3020
|
[aggregateContextBefore],
|
|
2689
3021
|
engineIdentifier,
|
|
2690
|
-
"InitAggregate"
|
|
3022
|
+
"InitAggregate",
|
|
3023
|
+
["team-1"]
|
|
2691
3024
|
);
|
|
2692
3025
|
}
|
|
2693
3026
|
}
|
|
@@ -2968,6 +3301,137 @@ function readEffectiveGuide(guide, root, resolved) {
|
|
|
2968
3301
|
return { identifier: guide.definition.identifier, locales, chapters, settings };
|
|
2969
3302
|
}
|
|
2970
3303
|
|
|
3304
|
+
// cli/core/assessment-reports.ts
|
|
3305
|
+
function assessmentAudience(query) {
|
|
3306
|
+
if (query.audience !== "own") return { kind: "all" };
|
|
3307
|
+
if (query.participantId !== void 0 && query.teamId !== void 0) {
|
|
3308
|
+
return { kind: "participant", teamId: query.teamId, participantId: query.participantId };
|
|
3309
|
+
}
|
|
3310
|
+
if (query.viewerRole === "observer" && query.teamId !== void 0) {
|
|
3311
|
+
return { kind: "team", teamId: query.teamId };
|
|
3312
|
+
}
|
|
3313
|
+
return null;
|
|
3314
|
+
}
|
|
3315
|
+
function answerAssessment(input) {
|
|
3316
|
+
const { query } = input;
|
|
3317
|
+
const assessment = input.assessments.find(
|
|
3318
|
+
(entry) => entry.definition.identifier === query.identifier
|
|
3319
|
+
);
|
|
3320
|
+
if (!assessment) {
|
|
3321
|
+
return {
|
|
3322
|
+
type: "assessmentFailure",
|
|
3323
|
+
error: `The package declares no assessment "${query.identifier}"`
|
|
3324
|
+
};
|
|
3325
|
+
}
|
|
3326
|
+
const audience = assessmentAudience(query);
|
|
3327
|
+
if (audience === null) {
|
|
3328
|
+
return {
|
|
3329
|
+
type: "assessmentFailure",
|
|
3330
|
+
error: "getAssessment from a player surface needs the participant or observer behind it"
|
|
3331
|
+
};
|
|
3332
|
+
}
|
|
3333
|
+
const settings = input.settings[ASSESSMENTS_SETTINGS];
|
|
3334
|
+
const report = buildAssessmentReport({
|
|
3335
|
+
definition: assessment.definition,
|
|
3336
|
+
bands: resolveAssessmentBands(assessment.definition, settings?.[query.identifier]),
|
|
3337
|
+
teams: input.teams.map((team) => ({
|
|
3338
|
+
teamId: team.teamId,
|
|
3339
|
+
records: team.context?.[ASSESSMENTS_KEY]?.[query.identifier],
|
|
3340
|
+
complete: team.complete
|
|
3341
|
+
})),
|
|
3342
|
+
participants: input.participants,
|
|
3343
|
+
audience
|
|
3344
|
+
});
|
|
3345
|
+
return { type: "assessment", report };
|
|
3346
|
+
}
|
|
3347
|
+
|
|
3348
|
+
// cli/core/benchmark-samples.ts
|
|
3349
|
+
import { readFile as readFile2, stat } from "node:fs/promises";
|
|
3350
|
+
import { join as join4 } from "node:path";
|
|
3351
|
+
function benchmarkSamplePath(identifier) {
|
|
3352
|
+
return join4("benchmarks", identifier, "sample.json");
|
|
3353
|
+
}
|
|
3354
|
+
var NUMERIC_FIGURES = ["mean", "min", "max", "p10", "p25", "p50", "p75", "p90"];
|
|
3355
|
+
function isRecord2(value) {
|
|
3356
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3357
|
+
}
|
|
3358
|
+
function isCount(value) {
|
|
3359
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0;
|
|
3360
|
+
}
|
|
3361
|
+
function fieldProblem(name, value) {
|
|
3362
|
+
if (!isRecord2(value)) return `fields.${name} must be an object`;
|
|
3363
|
+
if (!isCount(value.count)) return `fields.${name}.count must be a whole number of at least 0`;
|
|
3364
|
+
if (value.kind === "number") {
|
|
3365
|
+
for (const figure of NUMERIC_FIGURES) {
|
|
3366
|
+
const v = value[figure];
|
|
3367
|
+
if (v !== void 0 && (typeof v !== "number" || !Number.isFinite(v))) {
|
|
3368
|
+
return `fields.${name}.${figure} must be a number`;
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
return null;
|
|
3372
|
+
}
|
|
3373
|
+
if (value.kind === "choice") {
|
|
3374
|
+
if (!isRecord2(value.options)) return `fields.${name}.options must be an object`;
|
|
3375
|
+
for (const [option, count] of Object.entries(value.options)) {
|
|
3376
|
+
if (!isCount(count)) {
|
|
3377
|
+
return `fields.${name}.options.${option} must be a whole number of at least 0`;
|
|
3378
|
+
}
|
|
3379
|
+
}
|
|
3380
|
+
return null;
|
|
3381
|
+
}
|
|
3382
|
+
return `fields.${name}.kind must be "number" or "choice"`;
|
|
3383
|
+
}
|
|
3384
|
+
function benchmarkSampleProblem(sample) {
|
|
3385
|
+
if (!isRecord2(sample)) return "it must be an object";
|
|
3386
|
+
if (sample.scope !== "organisation" && sample.scope !== "global") {
|
|
3387
|
+
return 'scope must be "organisation" or "global"';
|
|
3388
|
+
}
|
|
3389
|
+
if (!isRecord2(sample.fields)) return "fields must be an object of field statistics";
|
|
3390
|
+
for (const [name, value] of Object.entries(sample.fields)) {
|
|
3391
|
+
const problem = fieldProblem(name, value);
|
|
3392
|
+
if (problem) return problem;
|
|
3393
|
+
}
|
|
3394
|
+
return null;
|
|
3395
|
+
}
|
|
3396
|
+
async function isDirectory(path2) {
|
|
3397
|
+
try {
|
|
3398
|
+
return (await stat(path2)).isDirectory();
|
|
3399
|
+
} catch {
|
|
3400
|
+
return false;
|
|
3401
|
+
}
|
|
3402
|
+
}
|
|
3403
|
+
async function isDeclared(packagePath, identifier, declared) {
|
|
3404
|
+
if (!/^[A-Za-z0-9_-]+$/.test(identifier)) return false;
|
|
3405
|
+
if (declared && declared.length > 0) return declared.includes(identifier);
|
|
3406
|
+
return isDirectory(join4(packagePath, "benchmarks", identifier));
|
|
3407
|
+
}
|
|
3408
|
+
async function answerBenchmarkFromSample(options) {
|
|
3409
|
+
const { packagePath, identifier, where, declared } = options;
|
|
3410
|
+
if (!await isDeclared(packagePath, identifier, declared)) {
|
|
3411
|
+
throw new Error(`No benchmark "${identifier}" is declared`);
|
|
3412
|
+
}
|
|
3413
|
+
const relative = benchmarkSamplePath(identifier);
|
|
3414
|
+
let text;
|
|
3415
|
+
try {
|
|
3416
|
+
text = await readFile2(join4(packagePath, relative), "utf-8");
|
|
3417
|
+
} catch (error) {
|
|
3418
|
+
if (error.code === "ENOENT") return null;
|
|
3419
|
+
throw error;
|
|
3420
|
+
}
|
|
3421
|
+
let sample;
|
|
3422
|
+
try {
|
|
3423
|
+
sample = JSON.parse(text);
|
|
3424
|
+
} catch (error) {
|
|
3425
|
+
throw new Error(
|
|
3426
|
+
`${relative} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`
|
|
3427
|
+
);
|
|
3428
|
+
}
|
|
3429
|
+
const problem = benchmarkSampleProblem(sample);
|
|
3430
|
+
if (problem) throw new Error(`${relative} is not a benchmark sample: ${problem}`);
|
|
3431
|
+
const { scope, fields } = sample;
|
|
3432
|
+
return { scope, matched: { ...where[0] }, fields };
|
|
3433
|
+
}
|
|
3434
|
+
|
|
2971
3435
|
// cli/core/history.ts
|
|
2972
3436
|
var HistoryManager = class {
|
|
2973
3437
|
snapshots = [];
|
|
@@ -4096,6 +4560,49 @@ function undoOneTeam(host, position) {
|
|
|
4096
4560
|
return true;
|
|
4097
4561
|
}
|
|
4098
4562
|
|
|
4563
|
+
// cli/core/assessment-moves.ts
|
|
4564
|
+
function participantLevelAssessments(assessments) {
|
|
4565
|
+
return assessments.filter((entry) => entry.definition.level === "participant").map((entry) => entry.definition.identifier);
|
|
4566
|
+
}
|
|
4567
|
+
function recordsOf(context) {
|
|
4568
|
+
return context?.[ASSESSMENTS_KEY] ?? {};
|
|
4569
|
+
}
|
|
4570
|
+
function withRecords(context, records) {
|
|
4571
|
+
const next = { ...context };
|
|
4572
|
+
const kept = Object.fromEntries(
|
|
4573
|
+
Object.entries(records).filter(([, byId]) => Object.keys(byId ?? {}).length > 0)
|
|
4574
|
+
);
|
|
4575
|
+
if (Object.keys(kept).length > 0) next[ASSESSMENTS_KEY] = kept;
|
|
4576
|
+
else delete next[ASSESSMENTS_KEY];
|
|
4577
|
+
return next;
|
|
4578
|
+
}
|
|
4579
|
+
function settleAssessmentRecords(input) {
|
|
4580
|
+
const { teamIds, teamOf, identifiers, prefer } = input;
|
|
4581
|
+
const contexts = [...input.contexts];
|
|
4582
|
+
if (identifiers.length === 0) return contexts;
|
|
4583
|
+
const records = contexts.map((context) => structuredClone(recordsOf(context)));
|
|
4584
|
+
const positionOf = new Map(teamIds.map((teamId, position) => [teamId, position]));
|
|
4585
|
+
let moved = false;
|
|
4586
|
+
records.forEach((teamRecords, position) => {
|
|
4587
|
+
for (const identifier of identifiers) {
|
|
4588
|
+
const byId = teamRecords[identifier];
|
|
4589
|
+
if (!byId) continue;
|
|
4590
|
+
for (const [participantId, record] of Object.entries(byId)) {
|
|
4591
|
+
const destination = positionOf.get(teamOf(participantId) ?? "");
|
|
4592
|
+
if (destination === void 0 || destination === position) continue;
|
|
4593
|
+
delete byId[participantId];
|
|
4594
|
+
const target = records[destination][identifier] ??= {};
|
|
4595
|
+
if (participantId === prefer || !(participantId in target)) {
|
|
4596
|
+
target[participantId] = record;
|
|
4597
|
+
}
|
|
4598
|
+
moved = true;
|
|
4599
|
+
}
|
|
4600
|
+
}
|
|
4601
|
+
});
|
|
4602
|
+
if (!moved) return input.contexts;
|
|
4603
|
+
return contexts.map((context, position) => withRecords(context, records[position]));
|
|
4604
|
+
}
|
|
4605
|
+
|
|
4099
4606
|
// cli/core/team-names.ts
|
|
4100
4607
|
function pickLocalised(entry, locale) {
|
|
4101
4608
|
if (!entry) return void 0;
|
|
@@ -4431,6 +4938,7 @@ var SessionRoster = class {
|
|
|
4431
4938
|
if (fromTeamId === toTeamId) return void 0;
|
|
4432
4939
|
const moved = this.host.participants.move(fromTeamId, participantId, toTeamId);
|
|
4433
4940
|
if (!moved) throw new DeniedError("The participant could not be moved");
|
|
4941
|
+
this.settleAssessments(participantId);
|
|
4434
4942
|
const move = { fromTeamId, toTeamId };
|
|
4435
4943
|
await this.fireHook("participantMove", moved, {
|
|
4436
4944
|
teamId: fromTeamId,
|
|
@@ -4439,6 +4947,25 @@ var SessionRoster = class {
|
|
|
4439
4947
|
await this.fireHook("participantMove", moved, { payload: { ...move, phase: "arrival" } });
|
|
4440
4948
|
return void 0;
|
|
4441
4949
|
}
|
|
4950
|
+
/**
|
|
4951
|
+
* Move participant-level assessment results to the team each participant
|
|
4952
|
+
* is on now (§6.17.2): after a move, with `prefer` the one who moved, and
|
|
4953
|
+
* after an undo, which restores results to the teams that held them then.
|
|
4954
|
+
*/
|
|
4955
|
+
settleAssessments(prefer) {
|
|
4956
|
+
const { executor, state } = this.host;
|
|
4957
|
+
const identifiers = participantLevelAssessments(executor.getConfig()?.assessments ?? []);
|
|
4958
|
+
if (identifiers.length === 0) return;
|
|
4959
|
+
const contexts = state.getTeamContexts();
|
|
4960
|
+
const settled = settleAssessmentRecords({
|
|
4961
|
+
contexts,
|
|
4962
|
+
teamIds: state.getTeamIndexes().map((index) => `team-${index + 1}`),
|
|
4963
|
+
teamOf: (id) => this.findParticipantTeam(id),
|
|
4964
|
+
identifiers,
|
|
4965
|
+
prefer
|
|
4966
|
+
});
|
|
4967
|
+
if (settled !== contexts) state.setTeamContexts(settled);
|
|
4968
|
+
}
|
|
4442
4969
|
findParticipantTeam(participantId) {
|
|
4443
4970
|
for (const index of this.host.state.getTeamIndexes()) {
|
|
4444
4971
|
const teamId = `team-${index + 1}`;
|
|
@@ -4631,15 +5158,70 @@ async function tickEveryTeam(host, next) {
|
|
|
4631
5158
|
|
|
4632
5159
|
// cli/core/session-timers.ts
|
|
4633
5160
|
var COHORT = -1;
|
|
5161
|
+
var DORMANT_AFTER_MS = 24 * 60 * 60 * 1e3;
|
|
5162
|
+
var DORMANT_AFTER_TICKS = 100;
|
|
4634
5163
|
var SessionTimers = class {
|
|
4635
5164
|
constructor(host) {
|
|
4636
5165
|
this.host = host;
|
|
5166
|
+
this.lastActivityAt = host.clock.now();
|
|
4637
5167
|
}
|
|
4638
5168
|
host;
|
|
4639
5169
|
/** True while a tick runs, so a timer firing then is dropped (§11.1). */
|
|
4640
5170
|
ticking = false;
|
|
4641
5171
|
/** Automatic tick timers, keyed by team index, or {@link COHORT} (§11). */
|
|
4642
5172
|
timers = /* @__PURE__ */ new Map();
|
|
5173
|
+
/** When the session went dormant (§11.4a), or null while it is not. */
|
|
5174
|
+
dormantAt = null;
|
|
5175
|
+
/** When anything outside the host last used the session (§11.4a). */
|
|
5176
|
+
lastActivityAt;
|
|
5177
|
+
/** Automatic ticks since then, every team's together (§11.4a). */
|
|
5178
|
+
unattendedTicks = 0;
|
|
5179
|
+
/** Surfaces and console pages open on the session, which keep it awake. */
|
|
5180
|
+
openSurfaces = 0;
|
|
5181
|
+
/** Whether automatic ticking is suspended because the session was unattended. */
|
|
5182
|
+
get dormant() {
|
|
5183
|
+
return this.dormantAt !== null;
|
|
5184
|
+
}
|
|
5185
|
+
/**
|
|
5186
|
+
* Something outside the host used the session (§11.4a): restart the
|
|
5187
|
+
* clock, and wake the session if it is dormant. Interval-mode timers pick
|
|
5188
|
+
* up at once; what is returned re-asks the controller for scheduled-mode
|
|
5189
|
+
* ones, for the caller to queue ahead of the activity itself. Null when
|
|
5190
|
+
* nothing woke.
|
|
5191
|
+
*/
|
|
5192
|
+
noteActivity() {
|
|
5193
|
+
this.lastActivityAt = this.host.clock.now();
|
|
5194
|
+
this.unattendedTicks = 0;
|
|
5195
|
+
if (this.dormantAt === null) return null;
|
|
5196
|
+
this.dormantAt = null;
|
|
5197
|
+
const reevaluate = this.groups().filter(
|
|
5198
|
+
(group) => this.timers.get(group.key)?.wake() === "re-evaluate"
|
|
5199
|
+
);
|
|
5200
|
+
return async () => {
|
|
5201
|
+
for (const group of reevaluate) await this.evaluate(group);
|
|
5202
|
+
};
|
|
5203
|
+
}
|
|
5204
|
+
/**
|
|
5205
|
+
* How many surfaces are open on the session. Opening one is activity, and
|
|
5206
|
+
* while any is open the session stays awake: the dev server counts an
|
|
5207
|
+
* idle open surface as use, which the specification leaves to the host.
|
|
5208
|
+
*/
|
|
5209
|
+
surfacesOpen(count) {
|
|
5210
|
+
const opened = count > this.openSurfaces;
|
|
5211
|
+
const lastClosed = count === 0 && this.openSurfaces > 0;
|
|
5212
|
+
this.openSurfaces = count;
|
|
5213
|
+
return opened || lastClosed ? this.noteActivity() : null;
|
|
5214
|
+
}
|
|
5215
|
+
/**
|
|
5216
|
+
* Suspend automatic ticking now (§11.4a), whether or not the minimums
|
|
5217
|
+
* have passed: the dev server's way to show an author a dormant session
|
|
5218
|
+
* without waiting a day.
|
|
5219
|
+
*/
|
|
5220
|
+
suspend() {
|
|
5221
|
+
if (this.dormantAt !== null) return;
|
|
5222
|
+
this.dormantAt = this.host.clock.now();
|
|
5223
|
+
for (const timer of this.timers.values()) timer.suspend();
|
|
5224
|
+
}
|
|
4643
5225
|
/** Cancel every timer, for a session that is stopping. */
|
|
4644
5226
|
stop() {
|
|
4645
5227
|
for (const timer of this.timers.values()) timer.cancel();
|
|
@@ -4764,6 +5346,7 @@ var SessionTimers = class {
|
|
|
4764
5346
|
let timer = this.timers.get(key);
|
|
4765
5347
|
if (!timer) {
|
|
4766
5348
|
timer = new TickTimer(this.host.clock, () => void this.onFired(key));
|
|
5349
|
+
if (this.dormantAt !== null) timer.suspend();
|
|
4767
5350
|
this.timers.set(key, timer);
|
|
4768
5351
|
}
|
|
4769
5352
|
return timer;
|
|
@@ -4864,13 +5447,29 @@ var SessionTimers = class {
|
|
|
4864
5447
|
type: "tick",
|
|
4865
5448
|
...key === COHORT ? {} : { teamIndex: key }
|
|
4866
5449
|
});
|
|
4867
|
-
if (result.ok)
|
|
5450
|
+
if (result.ok) {
|
|
5451
|
+
this.unattendedTicks += 1;
|
|
5452
|
+
this.suspendIfUnattended();
|
|
5453
|
+
return;
|
|
5454
|
+
}
|
|
4868
5455
|
await this.host.enqueue(async () => {
|
|
4869
5456
|
const group = this.groups().find((candidate) => candidate.key === key);
|
|
4870
5457
|
if (group) await this.evaluate(group);
|
|
4871
5458
|
this.host.emitState("timer");
|
|
4872
5459
|
});
|
|
4873
5460
|
}
|
|
5461
|
+
/**
|
|
5462
|
+
* Go dormant once nothing has used the session for both minimums, and no
|
|
5463
|
+
* surface is open (§11.4a). Judged after an automatic tick, since nothing
|
|
5464
|
+
* else happens to a session nobody is using.
|
|
5465
|
+
*/
|
|
5466
|
+
suspendIfUnattended() {
|
|
5467
|
+
if (this.dormantAt !== null || this.openSurfaces > 0) return;
|
|
5468
|
+
if (this.unattendedTicks < DORMANT_AFTER_TICKS) return;
|
|
5469
|
+
if (this.host.clock.now() - this.lastActivityAt < DORMANT_AFTER_MS) return;
|
|
5470
|
+
this.suspend();
|
|
5471
|
+
this.host.emitState("dormant");
|
|
5472
|
+
}
|
|
4874
5473
|
};
|
|
4875
5474
|
|
|
4876
5475
|
// cli/core/session-writes.ts
|
|
@@ -4953,11 +5552,16 @@ async function updateSettings(host, command) {
|
|
|
4953
5552
|
refuseUnconfiguredSettings(host, command.uiIdentifier, command.payload);
|
|
4954
5553
|
const existing = executor.getSessionOverrides() ?? {};
|
|
4955
5554
|
const changed = changedFrom(command.payload, executor.resolveConfiguration());
|
|
4956
|
-
const layer = deepMergeContext(existing,
|
|
5555
|
+
const layer = deepMergeContext(existing, isRecord3(changed) ? changed : {});
|
|
4957
5556
|
const config = executor.getConfig();
|
|
4958
5557
|
const result = config ? validateSessionOverrides(layer, settingsSchemas(config)) : { valid: true };
|
|
4959
5558
|
if (!result.valid) throw new DeniedError(result.errors ?? "Invalid settings");
|
|
4960
|
-
|
|
5559
|
+
const bands = resolvedBandProblems(
|
|
5560
|
+
config?.assessments ?? [],
|
|
5561
|
+
deepMergeContext(executor.buildResetConfiguration(), layer)
|
|
5562
|
+
);
|
|
5563
|
+
if (bands.length > 0) throw new DeniedError(bands.join("\n"));
|
|
5564
|
+
await refuseUnfitFiles(host, isRecord3(changed) ? changed : {});
|
|
4961
5565
|
executor.setConfiguration(layer);
|
|
4962
5566
|
return void 0;
|
|
4963
5567
|
}
|
|
@@ -4975,13 +5579,17 @@ async function updateScenarioDraft(host, drafts, command) {
|
|
|
4975
5579
|
host.executor.resolveScenarioDraft(scenarioId, edits)
|
|
4976
5580
|
);
|
|
4977
5581
|
const config = host.executor.getConfig();
|
|
4978
|
-
const
|
|
4979
|
-
|
|
4980
|
-
settingsSchemas(config)
|
|
4981
|
-
|
|
5582
|
+
const merged = deepMergeContext(edits, isRecord3(changed) ? changed : {});
|
|
5583
|
+
const errors = config ? [
|
|
5584
|
+
...collectSettingsOverrideErrors(merged, settingsSchemas(config)),
|
|
5585
|
+
...resolvedBandProblems(
|
|
5586
|
+
config.assessments ?? [],
|
|
5587
|
+
host.executor.resolveScenarioDraft(scenarioId, merged)
|
|
5588
|
+
)
|
|
5589
|
+
] : [];
|
|
4982
5590
|
if (errors.length > 0) throw new DeniedError(errors.join("\n"));
|
|
4983
|
-
await refuseUnfitFiles(host,
|
|
4984
|
-
drafts.record(scenarioId,
|
|
5591
|
+
await refuseUnfitFiles(host, isRecord3(changed) ? changed : {}, { draft: true });
|
|
5592
|
+
drafts.record(scenarioId, isRecord3(changed) ? changed : {});
|
|
4985
5593
|
return void 0;
|
|
4986
5594
|
}
|
|
4987
5595
|
async function refuseUnfitFiles(host, changed, options = {}) {
|
|
@@ -5099,11 +5707,11 @@ function resolveSharedWrites(host, board) {
|
|
|
5099
5707
|
executor.setSharedContext(deepMergeContext(store, changed));
|
|
5100
5708
|
return { ...board, ...executor.getSharedContext() };
|
|
5101
5709
|
}
|
|
5102
|
-
function
|
|
5710
|
+
function isRecord3(value) {
|
|
5103
5711
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
5104
5712
|
}
|
|
5105
5713
|
function changedFrom(update, current) {
|
|
5106
|
-
if (
|
|
5714
|
+
if (isRecord3(update) && isRecord3(current)) {
|
|
5107
5715
|
const changed = {};
|
|
5108
5716
|
for (const [key, value] of Object.entries(update)) {
|
|
5109
5717
|
const difference = changedFrom(value, current[key]);
|
|
@@ -5479,8 +6087,10 @@ var PLAY_STAGE = /* @__PURE__ */ new Set([
|
|
|
5479
6087
|
"moveParticipant",
|
|
5480
6088
|
"renameOwnTeam",
|
|
5481
6089
|
"renameSelf",
|
|
5482
|
-
"extendTick"
|
|
6090
|
+
"extendTick",
|
|
6091
|
+
"makeDormant"
|
|
5483
6092
|
]);
|
|
6093
|
+
var HOST_CONTROLS = /* @__PURE__ */ new Set(["armFault", "disarmFault", "makeDormant"]);
|
|
5484
6094
|
var STALE_BLOCKED = /* @__PURE__ */ new Set([
|
|
5485
6095
|
"tick",
|
|
5486
6096
|
"undo",
|
|
@@ -5619,7 +6229,7 @@ var Session = class {
|
|
|
5619
6229
|
},
|
|
5620
6230
|
enqueue: (work) => this.enqueue(work),
|
|
5621
6231
|
apply: (command) => this.apply(command),
|
|
5622
|
-
submit: (command) => this.
|
|
6232
|
+
submit: (command) => this.enqueue(() => this.apply(command)),
|
|
5623
6233
|
report: (message, source, teamId) => this.report(message, source, teamId),
|
|
5624
6234
|
emit: (event) => this.emit(event),
|
|
5625
6235
|
emitState: (cause) => this.emitState(cause)
|
|
@@ -5669,8 +6279,24 @@ var Session = class {
|
|
|
5669
6279
|
/** Submit a state-changing command. Queued, in order, one at a time. */
|
|
5670
6280
|
submit(command) {
|
|
5671
6281
|
if (command.type === "advanceClock") return this.advanceClock(command.byMs);
|
|
6282
|
+
if (!HOST_CONTROLS.has(command.type)) this.noteActivity();
|
|
5672
6283
|
return this.enqueue(() => this.apply(command));
|
|
5673
6284
|
}
|
|
6285
|
+
/**
|
|
6286
|
+
* Something outside the host used the session (§11.4a). A dormant session
|
|
6287
|
+
* wakes before the activity is handled: the re-evaluation waking needs is
|
|
6288
|
+
* queued ahead of it.
|
|
6289
|
+
*/
|
|
6290
|
+
noteActivity() {
|
|
6291
|
+
this.finishWaking(this.timers.noteActivity());
|
|
6292
|
+
}
|
|
6293
|
+
finishWaking(reevaluate) {
|
|
6294
|
+
if (!reevaluate) return;
|
|
6295
|
+
void this.enqueue(async () => {
|
|
6296
|
+
await reevaluate();
|
|
6297
|
+
this.emitState("woke");
|
|
6298
|
+
});
|
|
6299
|
+
}
|
|
5674
6300
|
/**
|
|
5675
6301
|
* Queue `work` as one operation: every logic call it makes reads the same
|
|
5676
6302
|
* `meta.now`, taken as it starts rather than as it was submitted (§10.2).
|
|
@@ -5740,6 +6366,7 @@ var Session = class {
|
|
|
5740
6366
|
case "getState":
|
|
5741
6367
|
return { type: "state", state: this.project() };
|
|
5742
6368
|
case "callEndpoint":
|
|
6369
|
+
this.noteActivity();
|
|
5743
6370
|
return this.endpoints.answer(command);
|
|
5744
6371
|
case "getEndpointAudit":
|
|
5745
6372
|
return { type: "endpointAudit", entries: [...this.endpoints.auditLog()] };
|
|
@@ -5791,6 +6418,41 @@ var Session = class {
|
|
|
5791
6418
|
}
|
|
5792
6419
|
return { type: "participants", participants: this.roster.records() };
|
|
5793
6420
|
}
|
|
6421
|
+
case "getAssessment": {
|
|
6422
|
+
const indexes = this.state.getTeamIndexes();
|
|
6423
|
+
const contexts = this.state.getTeamContexts();
|
|
6424
|
+
const complete = this.state.teamsFinished(this.tickLimit());
|
|
6425
|
+
const teams = indexes.map((index, position) => ({
|
|
6426
|
+
teamId: `team-${index + 1}`,
|
|
6427
|
+
context: contexts[position],
|
|
6428
|
+
complete: complete[position] ?? false
|
|
6429
|
+
}));
|
|
6430
|
+
return answerAssessment({
|
|
6431
|
+
query: command,
|
|
6432
|
+
assessments: this.executor.getConfig()?.assessments ?? [],
|
|
6433
|
+
teams,
|
|
6434
|
+
participants: teams.flatMap(
|
|
6435
|
+
(team) => this.participants.list(team.teamId).map((record) => ({ id: record.id, teamId: team.teamId }))
|
|
6436
|
+
),
|
|
6437
|
+
settings: this.executor.resolveConfiguration()
|
|
6438
|
+
});
|
|
6439
|
+
}
|
|
6440
|
+
case "getBenchmark": {
|
|
6441
|
+
try {
|
|
6442
|
+
const statistics = await answerBenchmarkFromSample({
|
|
6443
|
+
packagePath: this.options.packagePath,
|
|
6444
|
+
identifier: command.identifier,
|
|
6445
|
+
where: benchmarkFilters({ where: command.where }),
|
|
6446
|
+
declared: this.executor.getConfig()?.benchmarks?.map((benchmark) => benchmark.definition.identifier)
|
|
6447
|
+
});
|
|
6448
|
+
return { type: "benchmark", statistics };
|
|
6449
|
+
} catch (error) {
|
|
6450
|
+
return {
|
|
6451
|
+
type: "benchmarkFailure",
|
|
6452
|
+
error: errorMessage(error, "The benchmark could not be read")
|
|
6453
|
+
};
|
|
6454
|
+
}
|
|
6455
|
+
}
|
|
5794
6456
|
}
|
|
5795
6457
|
}
|
|
5796
6458
|
/** Convenience for a caller that does not care which kind it is holding. */
|
|
@@ -5820,6 +6482,16 @@ var Session = class {
|
|
|
5820
6482
|
canUndo: canUndo[position] ?? false,
|
|
5821
6483
|
context: withoutEngineState(contexts[position] ?? {}),
|
|
5822
6484
|
...contexts[position]?.[ENGINE_STATE_KEY] !== void 0 ? { state: structuredClone(contexts[position][ENGINE_STATE_KEY]) } : {},
|
|
6485
|
+
...contexts[position]?.[BENCHMARKS_KEY] !== void 0 ? {
|
|
6486
|
+
benchmarks: structuredClone(
|
|
6487
|
+
contexts[position][BENCHMARKS_KEY]
|
|
6488
|
+
)
|
|
6489
|
+
} : {},
|
|
6490
|
+
...contexts[position]?.[ASSESSMENTS_KEY] !== void 0 ? {
|
|
6491
|
+
assessments: structuredClone(
|
|
6492
|
+
contexts[position][ASSESSMENTS_KEY]
|
|
6493
|
+
)
|
|
6494
|
+
} : {},
|
|
5823
6495
|
participants: this.participants.list(teamId).map((record) => ({
|
|
5824
6496
|
id: record.id,
|
|
5825
6497
|
name: record.name,
|
|
@@ -5920,6 +6592,14 @@ var Session = class {
|
|
|
5920
6592
|
syncPresence(connected) {
|
|
5921
6593
|
if (this.roster.syncPresence(connected)) this.emitState("presence");
|
|
5922
6594
|
}
|
|
6595
|
+
/**
|
|
6596
|
+
* How many surfaces and console pages are open on this session, which the
|
|
6597
|
+
* host observes as it does presence. Opening one is activity, and while
|
|
6598
|
+
* any is open the session does not go dormant (§11.4a).
|
|
6599
|
+
*/
|
|
6600
|
+
syncOpenSurfaces(count) {
|
|
6601
|
+
this.finishWaking(this.timers.surfacesOpen(count));
|
|
6602
|
+
}
|
|
5923
6603
|
/** Edits on disk this session has not applied, each list empty when none is. */
|
|
5924
6604
|
pendingChanges() {
|
|
5925
6605
|
return {
|
|
@@ -6093,10 +6773,11 @@ var Session = class {
|
|
|
6093
6773
|
try {
|
|
6094
6774
|
const readsBefore = this.timers.readsBefore(command);
|
|
6095
6775
|
this.startWarnings = [];
|
|
6776
|
+
this.executor.takeWarnings();
|
|
6096
6777
|
const committedAtTick = await this.dispatch(command);
|
|
6097
6778
|
await this.timers.retime(command, readsBefore);
|
|
6098
6779
|
this.emitState(command.type);
|
|
6099
|
-
const warnings = this.startWarnings;
|
|
6780
|
+
const warnings = [...this.startWarnings, ...this.executor.takeWarnings()];
|
|
6100
6781
|
this.startWarnings = [];
|
|
6101
6782
|
return {
|
|
6102
6783
|
ok: true,
|
|
@@ -6136,7 +6817,11 @@ var Session = class {
|
|
|
6136
6817
|
case "tick":
|
|
6137
6818
|
return tick(this.host, command);
|
|
6138
6819
|
case "undo":
|
|
6139
|
-
return keepingSessionLifetime(this.host, () =>
|
|
6820
|
+
return keepingSessionLifetime(this.host, async () => {
|
|
6821
|
+
const tick2 = await undo(this.host, command);
|
|
6822
|
+
this.roster.settleAssessments();
|
|
6823
|
+
return tick2;
|
|
6824
|
+
});
|
|
6140
6825
|
case "reset":
|
|
6141
6826
|
return keepingSessionLifetime(this.host, () => reset(this.host, command));
|
|
6142
6827
|
case "updateContext":
|
|
@@ -6181,6 +6866,14 @@ var Session = class {
|
|
|
6181
6866
|
return void 0;
|
|
6182
6867
|
case "extendTick":
|
|
6183
6868
|
return this.timers.extend(command);
|
|
6869
|
+
case "makeDormant":
|
|
6870
|
+
if (!this.executor.getConfig()?.tick_controller) {
|
|
6871
|
+
throw new DeniedError(
|
|
6872
|
+
"This game has no tick controller, so nothing ticks on its own"
|
|
6873
|
+
);
|
|
6874
|
+
}
|
|
6875
|
+
this.timers.suspend();
|
|
6876
|
+
return void 0;
|
|
6184
6877
|
case "armFault":
|
|
6185
6878
|
this.faults.arm(command.fault, {
|
|
6186
6879
|
...command.times === void 0 ? {} : { times: command.times },
|
|
@@ -6451,8 +7144,13 @@ var Session = class {
|
|
|
6451
7144
|
return resolveTeamDisplayName(index, this.settings().teams.defaultNames, this.locale);
|
|
6452
7145
|
}
|
|
6453
7146
|
sharedEngineState() {
|
|
6454
|
-
const
|
|
6455
|
-
|
|
7147
|
+
const shared = this.executor.getSharedContext();
|
|
7148
|
+
const state = shared[SHARED_ENGINE_STATE_KEY];
|
|
7149
|
+
const benchmarks = shared[SHARED_BENCHMARKS_KEY];
|
|
7150
|
+
return {
|
|
7151
|
+
...state === void 0 ? {} : { sharedState: state },
|
|
7152
|
+
...benchmarks === void 0 ? {} : { sharedBenchmarks: structuredClone(benchmarks) }
|
|
7153
|
+
};
|
|
6456
7154
|
}
|
|
6457
7155
|
sharedStore() {
|
|
6458
7156
|
const shared = this.executor.getSharedContext();
|