@seriousgaming/sdk-tools 1.5.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/dist/agent/guidance.md +350 -0
  2. package/dist/bundling/ui-bundler.d.ts +12 -0
  3. package/dist/cli-25RWY5BQ.js +41 -0
  4. package/dist/cli-2BH7FX27.js +52 -0
  5. package/dist/cli-2GZYGRVL.js +36 -0
  6. package/dist/cli-2NU2LPEE.js +97 -0
  7. package/dist/cli-3BRC32CP.js +132 -0
  8. package/dist/cli-3D3ZXWOV.js +111 -0
  9. package/dist/cli-3ZKWV3PN.js +96 -0
  10. package/dist/cli-45OCBG53.js +60 -0
  11. package/dist/cli-4LKXZQ2B.js +48 -0
  12. package/dist/cli-4PXNOJQX.js +81 -0
  13. package/dist/cli-4SIWLHQO.js +717 -0
  14. package/dist/cli-4UWFQNGF.js +54 -0
  15. package/dist/cli-4VFZHLDG.js +202 -0
  16. package/dist/cli-4YB3ROVR.js +78 -0
  17. package/dist/cli-5ACDPCXI.js +21 -0
  18. package/dist/cli-5IAW3LIF.js +38 -0
  19. package/dist/cli-5SM367K7.js +30 -0
  20. package/dist/cli-64AB62PM.js +25 -0
  21. package/dist/cli-6K3VQQUS.js +307 -0
  22. package/dist/cli-6QB2VFPY.js +80 -0
  23. package/dist/cli-6SGCYEEC.js +649 -0
  24. package/dist/cli-6UTPHWRQ.js +207 -0
  25. package/dist/cli-6VNKQ3OX.js +391 -0
  26. package/dist/cli-72XDEFU3.js +61 -0
  27. package/dist/cli-7A6MKCUJ.js +463 -0
  28. package/dist/cli-7XLHO2FE.js +226 -0
  29. package/dist/cli-AV2FYC5G.js +225 -0
  30. package/dist/cli-B6YHEKIJ.js +248 -0
  31. package/dist/cli-BJMS3VX3.js +1837 -0
  32. package/dist/cli-BUQI5UU4.js +43 -0
  33. package/dist/cli-BWX5E7TQ.js +23 -0
  34. package/dist/cli-BYCHKSSH.js +1331 -0
  35. package/dist/cli-C3CMJSNL.js +89 -0
  36. package/dist/cli-C47GJATR.js +42 -0
  37. package/dist/cli-C5QOJJWX.js +46 -0
  38. package/dist/cli-C6ZLPK2U.js +124 -0
  39. package/dist/cli-CD5CIJZI.js +72 -0
  40. package/dist/cli-DDJYUKQG.js +36 -0
  41. package/dist/cli-DFBTZEBX.js +167 -0
  42. package/dist/cli-DOXRQ3S5.js +60 -0
  43. package/dist/cli-EVI36HEM.js +79 -0
  44. package/dist/cli-F2D4GGUA.js +549 -0
  45. package/dist/cli-FQRVFGN6.js +0 -0
  46. package/dist/cli-FWFRKQNE.js +11 -0
  47. package/dist/cli-G6CANSPL.js +88 -0
  48. package/dist/cli-GFNDW2DL.js +124 -0
  49. package/dist/cli-HCRTYQQS.js +16 -0
  50. package/dist/cli-HFX3YPUL.js +76 -0
  51. package/dist/cli-HKORECAG.js +53 -0
  52. package/dist/cli-HOE3WLFH.js +73 -0
  53. package/dist/cli-HSIHDN6K.js +187 -0
  54. package/dist/cli-HW53ICZC.js +89 -0
  55. package/dist/cli-IDVUHGKG.js +218 -0
  56. package/dist/cli-IEMKI7J7.js +1387 -0
  57. package/dist/cli-ILFDANBR.js +101 -0
  58. package/dist/cli-ILKCQNM6.js +8 -0
  59. package/dist/cli-IP4RXGHM.js +2847 -0
  60. package/dist/cli-IUS2YCD3.js +31 -0
  61. package/dist/cli-J4DKUUTK.js +138 -0
  62. package/dist/cli-J4UBELKF.js +37 -0
  63. package/dist/cli-JJSWBW4H.js +89 -0
  64. package/dist/cli-JVI24FI6.js +68 -0
  65. package/dist/cli-JZCLIT3O.js +135 -0
  66. package/dist/cli-JZOZOEZM.js +131 -0
  67. package/dist/cli-KGM6RRQW.js +185 -0
  68. package/dist/cli-KGT5L7VZ.js +13641 -0
  69. package/dist/cli-KOGRWFN7.js +89 -0
  70. package/dist/cli-KSGB2ZLK.js +101 -0
  71. package/dist/cli-L7VYSXQK.js +243 -0
  72. package/dist/cli-LK3V4RI5.js +36 -0
  73. package/dist/cli-LQOHATY2.js +126 -0
  74. package/dist/cli-MJUYJIEP.js +13 -0
  75. package/dist/cli-MJV47HKI.js +143 -0
  76. package/dist/cli-MMN4BPO4.js +145 -0
  77. package/dist/cli-MOPSZ3CS.js +88 -0
  78. package/dist/cli-MU5LB43S.js +136 -0
  79. package/dist/cli-MYJGMA6U.js +40 -0
  80. package/dist/cli-N24OHSAN.js +36 -0
  81. package/dist/cli-N45DREM4.js +99 -0
  82. package/dist/cli-N6H6T2E2.js +616 -0
  83. package/dist/cli-NROTDF5Y.js +182 -0
  84. package/dist/cli-O5ABH2WK.js +226 -0
  85. package/dist/cli-OMWC75CC.js +256 -0
  86. package/dist/cli-OXAUOWCN.js +50 -0
  87. package/dist/cli-PGCIHPU7.js +143 -0
  88. package/dist/cli-Q6ZBZYK2.js +35 -0
  89. package/dist/cli-QUNIRH7A.js +57 -0
  90. package/dist/cli-QUSCIUOM.js +142 -0
  91. package/dist/cli-QVASWX2A.js +187 -0
  92. package/dist/cli-QWQMPCL6.js +253 -0
  93. package/dist/cli-QY5NZAR7.js +97 -0
  94. package/dist/cli-R2MUZQE2.js +62 -0
  95. package/dist/cli-RCIWBCXD.js +36 -0
  96. package/dist/cli-RLEGRWFM.js +81 -0
  97. package/dist/cli-RSW6EBBD.js +89 -0
  98. package/dist/cli-RZITKPJX.js +367 -0
  99. package/dist/cli-S5IVGDDD.js +32 -0
  100. package/dist/cli-SRHBXZCN.js +159 -0
  101. package/dist/cli-TDSQSCX4.js +131 -0
  102. package/dist/cli-TIDQ4WUE.js +257 -0
  103. package/dist/cli-TT36JCU5.js +370 -0
  104. package/dist/cli-TTKICM5P.js +100 -0
  105. package/dist/cli-TTMBBEJC.js +131 -0
  106. package/dist/cli-UMEBPAZQ.js +16 -0
  107. package/dist/cli-UNAJ2OTE.js +15 -0
  108. package/dist/cli-UZZFNXRX.js +226 -0
  109. package/dist/cli-VDBW23SS.js +81 -0
  110. package/dist/cli-VL2P354N.js +46 -0
  111. package/dist/cli-VPRRICZA.js +304 -0
  112. package/dist/cli-VQ6HVQW4.js +4010 -0
  113. package/dist/cli-WR3NOY74.js +36 -0
  114. package/dist/cli-WU43JT4T.js +52 -0
  115. package/dist/cli-XAT25PRU.js +117 -0
  116. package/dist/cli-XOTNXEJA.js +124 -0
  117. package/dist/cli-XSLNH5PR.js +6417 -0
  118. package/dist/cli-XSVGKI3R.js +39 -0
  119. package/dist/cli-XZCJIKIV.js +124 -0
  120. package/dist/cli-Y3DDNMPX.js +97 -0
  121. package/dist/cli-Y3O5F4JN.js +90 -0
  122. package/dist/cli-YOTGR3NB.js +82 -0
  123. package/dist/cli-Z56ZIVA6.js +97 -0
  124. package/dist/cli-ZBN5KAIB.js +59 -0
  125. package/dist/cli-ZDOTXEKL.js +31 -0
  126. package/dist/cli-ZDUADFBY.js +88 -0
  127. package/dist/cli-ZJFQ7EEA.js +131 -0
  128. package/dist/cli-ZTWOE3ZT.js +65 -0
  129. package/dist/cli.js +148 -43093
  130. package/dist/client/build-surfaces.d.ts +33 -0
  131. package/dist/client/dev-server.d.ts +6 -0
  132. package/dist/client/index.d.ts +1 -0
  133. package/dist/client/playwright.d.ts +62 -0
  134. package/dist/client.js +228 -48
  135. package/dist/core/session.d.ts +15 -1
  136. package/dist/dev/console/assets/{index-BVF8exas.js → index-CuMOOH9m.js} +1 -1
  137. package/dist/dev/console/index.html +1 -1
  138. package/dist/dev/shell.d.ts +19 -0
  139. package/dist/dev/surfaces.d.ts +7 -0
  140. package/dist/docs/ai-agents.md +1 -1
  141. package/dist/docs/api/index.md +14 -12
  142. package/dist/docs/api/sdk-tools-client.md +29 -0
  143. package/dist/docs/api/sdk-tools-playwright.md +104 -0
  144. package/dist/docs/changelog.md +34 -0
  145. package/dist/docs/cli-and-dev-server.md +21 -0
  146. package/dist/docs/cli-reference.md +45 -31
  147. package/dist/docs/environment-variables.md +6 -0
  148. package/dist/docs/getting-started.md +1 -1
  149. package/dist/docs/guides/designing-a-game.md +29 -4
  150. package/dist/docs/guides/starter-game.md +3 -3
  151. package/dist/docs/guides/testing.md +33 -18
  152. package/dist/docs/guides/upgrading.md +19 -2
  153. package/dist/docs/page-index.md +10 -9
  154. package/dist/docs/recipes/e2e-testing.md +19 -20
  155. package/dist/playwright.js +32232 -0
  156. package/dist/templates/package/CLAUDE.md.template +7 -346
  157. package/dist/templates/package/claude/rules/workflow-create-engine.md +2 -2
  158. package/dist/templates/package/claude/rules/workflow-create-guide.md +2 -2
  159. package/dist/templates/package/claude/rules/workflow-create-user-interface.md +1 -1
  160. package/dist/templates/package/claude/rules/workflow-test-engine-or-ui.md +1 -1
  161. package/dist/templates/package/claude/rules/workflow-update-sdk-version.md +3 -3
  162. package/dist/templates/package/global-setup.ts.template +7 -18
  163. package/dist/templates/package/playwright.config.ts.liquid +8 -11
  164. package/dist/templates/starter-game/playwright.config.ts +8 -11
  165. package/dist/templates/starter-game/testing/e2e/game.spec.ts +1 -1
  166. package/dist/templates/starter-game/testing/e2e/global-setup.ts +7 -18
  167. package/dist/utils/prompt.d.ts +5 -5
  168. package/dist/utils/resource-scan.d.ts +39 -0
  169. package/package.json +7 -3
@@ -0,0 +1,207 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ promptForSettings
4
+ } from "./cli-ZDOTXEKL.js";
5
+ import {
6
+ loadResourceIdentifiers,
7
+ promptForCapabilities
8
+ } from "./cli-Q6ZBZYK2.js";
9
+ import {
10
+ resolvePatchedDefinition
11
+ } from "./cli-5IAW3LIF.js";
12
+ import "./cli-S5IVGDDD.js";
13
+ import {
14
+ readAuthoredBundle
15
+ } from "./cli-4VFZHLDG.js";
16
+ import {
17
+ resolveInputSource
18
+ } from "./cli-4UWFQNGF.js";
19
+ import {
20
+ updateEngineFiles
21
+ } from "./cli-4SIWLHQO.js";
22
+ import "./cli-IUS2YCD3.js";
23
+ import "./cli-QUNIRH7A.js";
24
+ import "./cli-J4UBELKF.js";
25
+ import {
26
+ loadPackageContext
27
+ } from "./cli-XSVGKI3R.js";
28
+ import "./cli-TT36JCU5.js";
29
+ import {
30
+ findBundleFile
31
+ } from "./cli-OXAUOWCN.js";
32
+ import {
33
+ operationError,
34
+ printOperationResult,
35
+ regenerateTypes
36
+ } from "./cli-KSGB2ZLK.js";
37
+ import {
38
+ confirmAction
39
+ } from "./cli-ZTWOE3ZT.js";
40
+ import "./cli-LQOHATY2.js";
41
+ import "./cli-IEMKI7J7.js";
42
+ import "./cli-OMWC75CC.js";
43
+ import "./cli-BYCHKSSH.js";
44
+ import "./cli-25RWY5BQ.js";
45
+ import "./cli-QWQMPCL6.js";
46
+ import {
47
+ validateSDKEngine
48
+ } from "./cli-VQ6HVQW4.js";
49
+ import "./cli-F2D4GGUA.js";
50
+ import {
51
+ logger
52
+ } from "./cli-4YB3ROVR.js";
53
+ import {
54
+ CliError
55
+ } from "./cli-N6H6T2E2.js";
56
+
57
+ // cli/commands/resources/engine/update.ts
58
+ import { readFileSync } from "fs";
59
+ function logReadWriteChanges(label, existing, updated) {
60
+ const added = updated.filter((id) => !existing.includes(id));
61
+ const removed = existing.filter((id) => !updated.includes(id));
62
+ if (added.length === 0 && removed.length === 0) {
63
+ logger.info(` ${label}: unchanged`);
64
+ return;
65
+ }
66
+ logger.info(` ${label}: CHANGED`);
67
+ for (const id of added) {
68
+ logger.info(` + ${id}`);
69
+ }
70
+ for (const id of removed) {
71
+ logger.info(` - ${id}`);
72
+ }
73
+ }
74
+ async function updateEngine(definitionInput, options) {
75
+ logger.info("\nUpdating engine...\n");
76
+ const identifier = "engine";
77
+ loadPackageContext(options.workingDir);
78
+ let jsonDefinition = null;
79
+ if (options.patch) {
80
+ jsonDefinition = resolvePatchedDefinition({
81
+ patch: options.patch,
82
+ workingDir: options.workingDir,
83
+ type: "engine",
84
+ identifier,
85
+ resourceLabel: "Engine"
86
+ });
87
+ } else {
88
+ const inputSource = await resolveInputSource(definitionInput, options.file);
89
+ if (inputSource.kind === "json") jsonDefinition = inputSource.json;
90
+ }
91
+ if (jsonDefinition) {
92
+ const engineInput = readAuthoredBundle({
93
+ json: jsonDefinition,
94
+ type: "engine",
95
+ command: "update",
96
+ validate: validateSDKEngine,
97
+ identifier,
98
+ validationHint: "Full replacement requires all fields to be specified."
99
+ });
100
+ logger.info("Updating engine files...\n");
101
+ const result2 = updateEngineFiles({
102
+ packagePath: options.workingDir,
103
+ oldIdentifier: identifier,
104
+ newDefinition: engineInput.definition
105
+ });
106
+ if (!result2.success) {
107
+ throw operationError(result2, "Failed to update engine files");
108
+ }
109
+ logger.success("Engine updated successfully!");
110
+ printOperationResult(result2);
111
+ await regenerateTypes(options.workingDir);
112
+ logger.info("");
113
+ return;
114
+ }
115
+ logger.info("No JSON definition provided. Starting interactive mode...\n");
116
+ const enginePath = findBundleFile(options.workingDir, "engine", identifier);
117
+ if (!enginePath) {
118
+ throw new CliError("RESOURCE_NOT_FOUND", `Engine "${identifier}" not found
119
+ `);
120
+ }
121
+ let existingBundle;
122
+ try {
123
+ const engineContent = readFileSync(enginePath, "utf-8");
124
+ existingBundle = JSON.parse(engineContent);
125
+ } catch (error) {
126
+ throw new CliError(
127
+ "BUNDLE_INVALID",
128
+ "Could not read engine file\n" + (error instanceof Error ? error.message : "Unknown error")
129
+ );
130
+ }
131
+ const validation = validateSDKEngine({
132
+ ...existingBundle,
133
+ definition: { ...existingBundle.definition, identifier }
134
+ });
135
+ if (!validation.valid) {
136
+ throw new CliError("BUNDLE_INVALID", `Invalid engine file format
137
+ ${validation.errors}`);
138
+ }
139
+ const existingDef = { ...existingBundle.definition, identifier };
140
+ logger.info("Current engine values:");
141
+ logger.info(` Identifier: ${existingDef.identifier}`);
142
+ const existingReads = existingDef.reads || [];
143
+ logger.info(` Read Capabilities: ${existingReads.length}`);
144
+ for (const read of existingReads) {
145
+ logger.info(` - ${read}`);
146
+ }
147
+ const existingWrites = existingDef.writes || [];
148
+ logger.info(` Written Capabilities: ${existingWrites.length}`);
149
+ for (const write of existingWrites) {
150
+ logger.info(` - ${write}`);
151
+ }
152
+ const existingSettings = existingDef.settings || [];
153
+ logger.info(` Settings: ${existingSettings.length}`);
154
+ for (const id of existingSettings) {
155
+ logger.info(` - ${id}`);
156
+ }
157
+ logger.info("");
158
+ const availableCapabilities = loadResourceIdentifiers(options.workingDir, "capability");
159
+ logger.info("");
160
+ const newReadCapabilities = await promptForCapabilities(
161
+ "Select capabilities the engine reads (use space to select, enter to confirm):",
162
+ availableCapabilities,
163
+ existingReads
164
+ );
165
+ logger.info("");
166
+ const newWriteCapabilities = await promptForCapabilities(
167
+ "Select capabilities the engine writes (use space to select, enter to confirm):",
168
+ availableCapabilities,
169
+ existingWrites
170
+ );
171
+ logger.info("");
172
+ const newSettings = await promptForSettings(options.workingDir, "engine", existingSettings);
173
+ logger.info("\nChanges to be made:");
174
+ logReadWriteChanges("Read Capabilities", existingReads, newReadCapabilities);
175
+ logReadWriteChanges("Written Capabilities", existingWrites, newWriteCapabilities);
176
+ logReadWriteChanges("Settings", existingSettings, newSettings);
177
+ logger.info("\nThis will update 1 file and may update references in games.");
178
+ logger.info("");
179
+ const confirmed = await confirmAction({ message: "Continue with update?", default: true });
180
+ if (!confirmed) {
181
+ logger.info("\nUpdate cancelled.\n");
182
+ return;
183
+ }
184
+ logger.info("\nUpdating engine files...\n");
185
+ const { reads: _reads, writes: _writes, settings: _settings, ...kept } = existingDef;
186
+ const newEngineDefinition = {
187
+ ...kept,
188
+ identifier: existingDef.identifier,
189
+ ...newReadCapabilities.length > 0 && { reads: newReadCapabilities },
190
+ ...newWriteCapabilities.length > 0 && { writes: newWriteCapabilities },
191
+ ...newSettings.length > 0 && { settings: newSettings }
192
+ };
193
+ const result = updateEngineFiles({
194
+ packagePath: options.workingDir,
195
+ oldIdentifier: existingDef.identifier,
196
+ newDefinition: newEngineDefinition
197
+ });
198
+ if (!result.success) {
199
+ throw operationError(result, "Failed to update engine files");
200
+ }
201
+ logger.success("Engine updated successfully!");
202
+ printOperationResult(result);
203
+ await regenerateTypes(options.workingDir);
204
+ }
205
+ export {
206
+ updateEngine
207
+ };
@@ -0,0 +1,391 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ resolveSession
4
+ } from "./cli-6K3VQQUS.js";
5
+ import "./cli-WU43JT4T.js";
6
+ import {
7
+ emit,
8
+ participantsFromArgument,
9
+ raiseIfRefused,
10
+ teamIndexFromArgument,
11
+ tickReport,
12
+ wholeNumberFromFlag
13
+ } from "./cli-L7VYSXQK.js";
14
+ import "./cli-FQRVFGN6.js";
15
+ import {
16
+ IDLE_TIMER
17
+ } from "./cli-XSLNH5PR.js";
18
+ import "./cli-TDSQSCX4.js";
19
+ import "./cli-SRHBXZCN.js";
20
+ import "./cli-KGT5L7VZ.js";
21
+ import "./cli-4LKXZQ2B.js";
22
+ import "./cli-MMN4BPO4.js";
23
+ import "./cli-QUNIRH7A.js";
24
+ import {
25
+ loadPackageContext
26
+ } from "./cli-XSVGKI3R.js";
27
+ import "./cli-BYCHKSSH.js";
28
+ import "./cli-25RWY5BQ.js";
29
+ import "./cli-QWQMPCL6.js";
30
+ import {
31
+ loadConfig
32
+ } from "./cli-VQ6HVQW4.js";
33
+ import "./cli-F2D4GGUA.js";
34
+ import "./cli-4YB3ROVR.js";
35
+ import {
36
+ CliError
37
+ } from "./cli-N6H6T2E2.js";
38
+
39
+ // cli/commands/session.ts
40
+ import { resolve } from "path";
41
+ async function withSession(options, use) {
42
+ const session = await resolveSession({
43
+ packagePath: options.workingDir,
44
+ ...options.walkthrough ? { runKind: "walkthrough" } : {},
45
+ ...options.server === false ? { noServer: true } : {}
46
+ });
47
+ try {
48
+ return await use(session);
49
+ } finally {
50
+ await session.close();
51
+ }
52
+ }
53
+ async function submit(options, build, describe) {
54
+ await withSession(options, async (session) => {
55
+ raiseIfRefused(await session.send(await build(session)));
56
+ emit(await describe(session));
57
+ });
58
+ }
59
+ async function undoCommand(options) {
60
+ await submit(
61
+ options,
62
+ async (session) => ({
63
+ type: "undo",
64
+ ...scopeOf(await session.state(), options.team)
65
+ }),
66
+ async (session) => tickReport(await session.state())
67
+ );
68
+ }
69
+ async function playCommand(options) {
70
+ await withSession(options, async (session) => {
71
+ const before = await session.state();
72
+ if (before.session.inSetup) {
73
+ raiseIfRefused(await session.send({ type: "play" }));
74
+ }
75
+ const after = await session.state();
76
+ emit({
77
+ started: before.session.inSetup,
78
+ ...tickReport(after),
79
+ settings: after.settings
80
+ });
81
+ });
82
+ }
83
+ async function reconfigureCommand(options) {
84
+ await submit(
85
+ options,
86
+ () => ({ type: "reconfigure" }),
87
+ async (session) => {
88
+ const state = await session.state();
89
+ return {
90
+ inSetup: state.session.inSetup,
91
+ settings: state.settings
92
+ };
93
+ }
94
+ );
95
+ }
96
+ async function resetCommand(options) {
97
+ await submit(
98
+ options,
99
+ async (session) => ({ type: "reset", ...scopeOf(await session.state(), options.team) }),
100
+ async (session) => tickReport(await session.state())
101
+ );
102
+ }
103
+ async function teamAddCommand(name, options) {
104
+ const participants = options.participants === void 0 ? void 0 : participantsFromArgument(options.participants);
105
+ if (Array.isArray(participants)) {
106
+ throw new CliError("USAGE_BAD_FLAG", "--participants takes one count when adding one team");
107
+ }
108
+ await submit(
109
+ options,
110
+ () => ({
111
+ type: "addTeam",
112
+ ...name === void 0 ? {} : { name },
113
+ ...participants === void 0 ? {} : { participants }
114
+ }),
115
+ teamSummary
116
+ );
117
+ }
118
+ async function teamRemoveCommand(team, options) {
119
+ await submit(
120
+ options,
121
+ async (session) => ({
122
+ type: "removeTeam",
123
+ teamIndex: requireTeam(await session.state(), team)
124
+ }),
125
+ teamSummary
126
+ );
127
+ }
128
+ async function teamRenameCommand(team, name, options) {
129
+ if (!name)
130
+ throw new CliError(
131
+ "USAGE_MISSING_ARGUMENT",
132
+ "A new name is required\nUsage: sdk team rename <n> <name>"
133
+ );
134
+ await submit(
135
+ options,
136
+ async (session) => {
137
+ const state = await session.state();
138
+ const index = requireTeam(state, team);
139
+ const found = state.teams.find((candidate) => candidate.index === index);
140
+ return { type: "renameTeam", teamId: found?.teamId ?? "", name };
141
+ },
142
+ teamSummary
143
+ );
144
+ }
145
+ async function participantAddCommand(name, options) {
146
+ await submit(
147
+ options,
148
+ async (session) => {
149
+ const state = await session.state();
150
+ const index = requireTeam(state, options.team ?? "1");
151
+ const found = state.teams.find((candidate) => candidate.index === index);
152
+ return {
153
+ type: "addParticipant",
154
+ teamId: found?.teamId ?? "",
155
+ ...name === void 0 ? {} : { name }
156
+ };
157
+ },
158
+ rosterOf
159
+ );
160
+ }
161
+ async function participantRenameCommand(participantId, name, options) {
162
+ if (!name) {
163
+ throw new CliError(
164
+ "USAGE_MISSING_ARGUMENT",
165
+ "A new name is required\nUsage: sdk participant rename <id> <name>"
166
+ );
167
+ }
168
+ await submit(options, () => ({ type: "renameParticipant", participantId, name }), rosterOf);
169
+ }
170
+ async function participantMoveCommand(participantId, team, options) {
171
+ if (!team) {
172
+ throw new CliError(
173
+ "USAGE_MISSING_ARGUMENT",
174
+ "A destination team is required\nUsage: sdk participant move <id> <n>"
175
+ );
176
+ }
177
+ await submit(
178
+ options,
179
+ async (session) => {
180
+ const state = await session.state();
181
+ const index = requireTeam(state, team);
182
+ const found = state.teams.find((candidate) => candidate.index === index);
183
+ return { type: "moveParticipant", participantId, teamId: found?.teamId ?? "" };
184
+ },
185
+ rosterOf
186
+ );
187
+ }
188
+ async function waitingRoomCommand(action, options) {
189
+ if (action !== "open" && action !== "close") {
190
+ throw new CliError(
191
+ "USAGE_BAD_ARGUMENT",
192
+ `Unknown waiting-room action "${action}". Use open or close.`
193
+ );
194
+ }
195
+ await submit(
196
+ options,
197
+ () => ({ type: "setWaitingRoom", open: action === "open" }),
198
+ async (session) => ({ waitingRoomOpen: (await session.state()).session.waitingRoomOpen })
199
+ );
200
+ }
201
+ async function scenarioCommand(scenarioId, options) {
202
+ const selected = scenarioId === void 0 || scenarioId === "none" ? null : scenarioId;
203
+ await submit(
204
+ options,
205
+ () => ({ type: "selectScenario", scenarioId: selected }),
206
+ async (session) => {
207
+ const state = await session.state();
208
+ return { scenarioId: state.game.scenarioId, settings: state.settings };
209
+ }
210
+ );
211
+ }
212
+ async function localeCommand(locale, options) {
213
+ if (!locale)
214
+ throw new CliError(
215
+ "USAGE_MISSING_ARGUMENT",
216
+ "A locale is required\nUsage: sdk locale <code>"
217
+ );
218
+ await submit(
219
+ options,
220
+ () => ({ type: "setLocale", locale }),
221
+ async (session) => ({ locale: (await session.state()).session.locale })
222
+ );
223
+ }
224
+ var TIMER_ACTIONS = ["status", "pause", "resume", "extend"];
225
+ async function timerCommand(action, seconds, options) {
226
+ const chosen = action ?? "status";
227
+ if (!TIMER_ACTIONS.includes(chosen)) {
228
+ throw new CliError(
229
+ "USAGE_BAD_ARGUMENT",
230
+ `Unknown timer action "${action}". Use ${TIMER_ACTIONS.slice(1).join(", ")}, or none to report the timer.`
231
+ );
232
+ }
233
+ if (chosen !== "extend" && seconds !== void 0) {
234
+ throw new CliError("USAGE_BAD_ARGUMENT", `sdk timer ${chosen} takes no value`);
235
+ }
236
+ const byMs = chosen === "extend" ? parseSeconds(seconds, "sdk timer extend <seconds>") * 1e3 : 0;
237
+ const config = await loadConfig(loadPackageContext(resolve(options.workingDir)).configPath);
238
+ if (!config.tick_controller) {
239
+ throw new CliError(
240
+ "USAGE_NOT_APPLICABLE",
241
+ "This game has no tick controller, so it has no automatic tick timer (\xA711)"
242
+ );
243
+ }
244
+ await withSession(options, async (session) => {
245
+ const state = await session.state();
246
+ const scope = timerScopeOf(state, options.team);
247
+ if (chosen !== "status") {
248
+ const command = chosen === "extend" ? { type: "extendTick", byMs, ...scope } : { type: chosen === "pause" ? "pauseTimer" : "resumeTimer", ...scope };
249
+ raiseIfRefused(await session.send(command));
250
+ }
251
+ emit(timerReport(await session.state(), scope.teamIndex));
252
+ });
253
+ }
254
+ function parseSeconds(value, usage) {
255
+ if (value === void 0) {
256
+ throw new CliError(
257
+ "USAGE_MISSING_ARGUMENT",
258
+ `A number of seconds is required
259
+ Usage: ${usage}`
260
+ );
261
+ }
262
+ const parsed = Number(value);
263
+ if (value.trim() === "" || !Number.isFinite(parsed)) {
264
+ throw new CliError("USAGE_BAD_ARGUMENT", `"${value}" is not a number of seconds`);
265
+ }
266
+ return parsed;
267
+ }
268
+ function perTeamTimers(state) {
269
+ return state.session.mode === "independent" && state.timer === null;
270
+ }
271
+ function timerScopeOf(state, team) {
272
+ if (team !== void 0 && !perTeamTimers(state)) {
273
+ throw new CliError(
274
+ "USAGE_NOT_APPLICABLE",
275
+ "--team only applies to an independent multi-team game, where each team has its own timer. This session has one timer for every team."
276
+ );
277
+ }
278
+ return scopeOf(state, team);
279
+ }
280
+ function summarise(timer) {
281
+ return {
282
+ ...timer,
283
+ nextTickIn: timer.nextTickAt === null || timer.paused ? null : Math.max(0, Math.round((timer.nextTickAt - Date.now()) / 1e3))
284
+ };
285
+ }
286
+ function timerReport(state, teamIndex) {
287
+ if (!perTeamTimers(state)) {
288
+ return {
289
+ mode: state.session.mode,
290
+ timer: summarise(state.timer ?? IDLE_TIMER)
291
+ };
292
+ }
293
+ const teams = [...state.teams].sort((a, b) => a.index - b.index).filter((team) => teamIndex === void 0 || team.index === teamIndex).map((team) => ({
294
+ team: team.index + 1,
295
+ name: team.name,
296
+ timer: summarise(team.timer ?? IDLE_TIMER)
297
+ }));
298
+ return { mode: state.session.mode, teams };
299
+ }
300
+ async function clockAdvanceCommand(seconds, options) {
301
+ const byMs = parseSeconds(seconds, "sdk clock advance <seconds>") * 1e3;
302
+ if (byMs < 0) throw new CliError("USAGE_BAD_ARGUMENT", "Time only moves forward");
303
+ await withSession(options, async (session) => {
304
+ const before = (await session.state()).session.completedTicks;
305
+ raiseIfRefused(await session.send({ type: "advanceClock", byMs }));
306
+ const state = await session.state();
307
+ emit({
308
+ advancedBy: byMs / 1e3,
309
+ ticksRun: state.session.completedTicks - before,
310
+ ...timerReport(state, void 0),
311
+ ...tickReport(state)
312
+ });
313
+ });
314
+ }
315
+ var FAULTS = [
316
+ "conflict",
317
+ "denied",
318
+ "llm-failure",
319
+ "hook-throw",
320
+ "endpoint-timeout",
321
+ "tick-failure"
322
+ ];
323
+ async function faultCommand(fault, options) {
324
+ if (!fault || !FAULTS.includes(fault)) {
325
+ throw new CliError(
326
+ "USAGE_BAD_ARGUMENT",
327
+ `Unknown fault "${fault ?? ""}".
328
+ Available: ${FAULTS.join(", ")}`
329
+ );
330
+ }
331
+ await submit(
332
+ options,
333
+ () => options.disarm ? { type: "disarmFault", fault } : {
334
+ type: "armFault",
335
+ fault,
336
+ ...options.times === void 0 ? {} : { times: wholeNumberFromFlag("--times", options.times, 1) },
337
+ ...options.reason === void 0 ? {} : { reason: options.reason }
338
+ },
339
+ async (session) => ({ faults: (await session.state()).faults })
340
+ );
341
+ }
342
+ function scopeOf(state, team) {
343
+ const index = teamIndexFromArgument(state, team);
344
+ return index === void 0 ? {} : { teamIndex: index };
345
+ }
346
+ function requireTeam(state, team) {
347
+ const index = teamIndexFromArgument(state, team);
348
+ if (index === void 0)
349
+ throw new CliError("USAGE_MISSING_ARGUMENT", "A team number is required");
350
+ return index;
351
+ }
352
+ async function teamSummary(session) {
353
+ const state = await session.state();
354
+ return {
355
+ teams: [...state.teams].sort((a, b) => a.index - b.index).map((team) => ({
356
+ team: team.index + 1,
357
+ teamId: team.teamId,
358
+ name: team.name,
359
+ completedTicks: team.completedTicks,
360
+ participants: team.participants.length
361
+ }))
362
+ };
363
+ }
364
+ async function rosterOf(session) {
365
+ const state = await session.state();
366
+ return {
367
+ teams: state.teams.map((team) => ({
368
+ team: team.index + 1,
369
+ teamId: team.teamId,
370
+ participants: team.participants
371
+ }))
372
+ };
373
+ }
374
+ export {
375
+ clockAdvanceCommand,
376
+ faultCommand,
377
+ localeCommand,
378
+ participantAddCommand,
379
+ participantMoveCommand,
380
+ participantRenameCommand,
381
+ playCommand,
382
+ reconfigureCommand,
383
+ resetCommand,
384
+ scenarioCommand,
385
+ teamAddCommand,
386
+ teamRemoveCommand,
387
+ teamRenameCommand,
388
+ timerCommand,
389
+ undoCommand,
390
+ waitingRoomCommand
391
+ };
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ validateEngine
4
+ } from "./cli-7XLHO2FE.js";
5
+ import "./cli-4LKXZQ2B.js";
6
+ import {
7
+ LOGIC_NODE_BUILTIN,
8
+ Transpile,
9
+ loadConfig
10
+ } from "./cli-VQ6HVQW4.js";
11
+ import "./cli-F2D4GGUA.js";
12
+ import "./cli-4YB3ROVR.js";
13
+ import {
14
+ CliError,
15
+ reportResult
16
+ } from "./cli-N6H6T2E2.js";
17
+
18
+ // cli/commands/build-engine.ts
19
+ import { resolve, join } from "path";
20
+ async function buildEngineCommand(options) {
21
+ const configPath = resolve(options.workingDir, options.config);
22
+ const config = await loadConfig(configPath);
23
+ const engine = config.engine;
24
+ if (!engine) {
25
+ throw new CliError(
26
+ "RESOURCE_NOT_FOUND",
27
+ "This package has no engine: the `engine` slot is empty"
28
+ );
29
+ }
30
+ const validationResult = validateEngine(engine, config);
31
+ if (!validationResult.success) {
32
+ throw new CliError(
33
+ validationResult.errors.every((error) => error.includes(LOGIC_NODE_BUILTIN)) ? LOGIC_NODE_BUILTIN : "PACKAGE_INVALID",
34
+ `Engine validation failed:
35
+ ${validationResult.errors.map((error) => ` - ${error}`).join("\n")}`,
36
+ {
37
+ diagnostics: validationResult.errors.map((message) => ({
38
+ severity: "error",
39
+ ...validationResult.findings?.find(
40
+ (finding) => finding.message === message
41
+ ) ?? {
42
+ code: message.includes(LOGIC_NODE_BUILTIN) ? LOGIC_NODE_BUILTIN : "PACKAGE_INVALID",
43
+ message
44
+ },
45
+ resource: { type: "engine", identifier: "engine" }
46
+ }))
47
+ }
48
+ );
49
+ }
50
+ const engineSourceDir = join(options.workingDir, engine.rootDirectory);
51
+ const logicDirectory = resolve(engineSourceDir, engine.logic.directory);
52
+ const logicEntrypoint = resolve(logicDirectory, engine.logic.entrypoint);
53
+ const bundledCode = await Transpile({
54
+ entrypoint: logicEntrypoint,
55
+ packageRoot: options.workingDir
56
+ });
57
+ reportResult({ code: bundledCode }, () => process.stdout.write(bundledCode));
58
+ }
59
+ export {
60
+ buildEngineCommand
61
+ };