@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.
- package/dist/agent/guidance.md +350 -0
- package/dist/bundling/ui-bundler.d.ts +12 -0
- package/dist/cli-25RWY5BQ.js +41 -0
- package/dist/cli-2BH7FX27.js +52 -0
- package/dist/cli-2GZYGRVL.js +36 -0
- package/dist/cli-2NU2LPEE.js +97 -0
- package/dist/cli-3BRC32CP.js +132 -0
- package/dist/cli-3D3ZXWOV.js +111 -0
- package/dist/cli-3ZKWV3PN.js +96 -0
- package/dist/cli-45OCBG53.js +60 -0
- package/dist/cli-4LKXZQ2B.js +48 -0
- package/dist/cli-4PXNOJQX.js +81 -0
- package/dist/cli-4SIWLHQO.js +717 -0
- package/dist/cli-4UWFQNGF.js +54 -0
- package/dist/cli-4VFZHLDG.js +202 -0
- package/dist/cli-4YB3ROVR.js +78 -0
- package/dist/cli-5ACDPCXI.js +21 -0
- package/dist/cli-5IAW3LIF.js +38 -0
- package/dist/cli-5SM367K7.js +30 -0
- package/dist/cli-64AB62PM.js +25 -0
- package/dist/cli-6K3VQQUS.js +307 -0
- package/dist/cli-6QB2VFPY.js +80 -0
- package/dist/cli-6SGCYEEC.js +649 -0
- package/dist/cli-6UTPHWRQ.js +207 -0
- package/dist/cli-6VNKQ3OX.js +391 -0
- package/dist/cli-72XDEFU3.js +61 -0
- package/dist/cli-7A6MKCUJ.js +463 -0
- package/dist/cli-7XLHO2FE.js +226 -0
- package/dist/cli-AV2FYC5G.js +225 -0
- package/dist/cli-B6YHEKIJ.js +248 -0
- package/dist/cli-BJMS3VX3.js +1837 -0
- package/dist/cli-BUQI5UU4.js +43 -0
- package/dist/cli-BWX5E7TQ.js +23 -0
- package/dist/cli-BYCHKSSH.js +1331 -0
- package/dist/cli-C3CMJSNL.js +89 -0
- package/dist/cli-C47GJATR.js +42 -0
- package/dist/cli-C5QOJJWX.js +46 -0
- package/dist/cli-C6ZLPK2U.js +124 -0
- package/dist/cli-CD5CIJZI.js +72 -0
- package/dist/cli-DDJYUKQG.js +36 -0
- package/dist/cli-DFBTZEBX.js +167 -0
- package/dist/cli-DOXRQ3S5.js +60 -0
- package/dist/cli-EVI36HEM.js +79 -0
- package/dist/cli-F2D4GGUA.js +549 -0
- package/dist/cli-FQRVFGN6.js +0 -0
- package/dist/cli-FWFRKQNE.js +11 -0
- package/dist/cli-G6CANSPL.js +88 -0
- package/dist/cli-GFNDW2DL.js +124 -0
- package/dist/cli-HCRTYQQS.js +16 -0
- package/dist/cli-HFX3YPUL.js +76 -0
- package/dist/cli-HKORECAG.js +53 -0
- package/dist/cli-HOE3WLFH.js +73 -0
- package/dist/cli-HSIHDN6K.js +187 -0
- package/dist/cli-HW53ICZC.js +89 -0
- package/dist/cli-IDVUHGKG.js +218 -0
- package/dist/cli-IEMKI7J7.js +1387 -0
- package/dist/cli-ILFDANBR.js +101 -0
- package/dist/cli-ILKCQNM6.js +8 -0
- package/dist/cli-IP4RXGHM.js +2847 -0
- package/dist/cli-IUS2YCD3.js +31 -0
- package/dist/cli-J4DKUUTK.js +138 -0
- package/dist/cli-J4UBELKF.js +37 -0
- package/dist/cli-JJSWBW4H.js +89 -0
- package/dist/cli-JVI24FI6.js +68 -0
- package/dist/cli-JZCLIT3O.js +135 -0
- package/dist/cli-JZOZOEZM.js +131 -0
- package/dist/cli-KGM6RRQW.js +185 -0
- package/dist/cli-KGT5L7VZ.js +13641 -0
- package/dist/cli-KOGRWFN7.js +89 -0
- package/dist/cli-KSGB2ZLK.js +101 -0
- package/dist/cli-L7VYSXQK.js +243 -0
- package/dist/cli-LK3V4RI5.js +36 -0
- package/dist/cli-LQOHATY2.js +126 -0
- package/dist/cli-MJUYJIEP.js +13 -0
- package/dist/cli-MJV47HKI.js +143 -0
- package/dist/cli-MMN4BPO4.js +145 -0
- package/dist/cli-MOPSZ3CS.js +88 -0
- package/dist/cli-MU5LB43S.js +136 -0
- package/dist/cli-MYJGMA6U.js +40 -0
- package/dist/cli-N24OHSAN.js +36 -0
- package/dist/cli-N45DREM4.js +99 -0
- package/dist/cli-N6H6T2E2.js +616 -0
- package/dist/cli-NROTDF5Y.js +182 -0
- package/dist/cli-O5ABH2WK.js +226 -0
- package/dist/cli-OMWC75CC.js +256 -0
- package/dist/cli-OXAUOWCN.js +50 -0
- package/dist/cli-PGCIHPU7.js +143 -0
- package/dist/cli-Q6ZBZYK2.js +35 -0
- package/dist/cli-QUNIRH7A.js +57 -0
- package/dist/cli-QUSCIUOM.js +142 -0
- package/dist/cli-QVASWX2A.js +187 -0
- package/dist/cli-QWQMPCL6.js +253 -0
- package/dist/cli-QY5NZAR7.js +97 -0
- package/dist/cli-R2MUZQE2.js +62 -0
- package/dist/cli-RCIWBCXD.js +36 -0
- package/dist/cli-RLEGRWFM.js +81 -0
- package/dist/cli-RSW6EBBD.js +89 -0
- package/dist/cli-RZITKPJX.js +367 -0
- package/dist/cli-S5IVGDDD.js +32 -0
- package/dist/cli-SRHBXZCN.js +159 -0
- package/dist/cli-TDSQSCX4.js +131 -0
- package/dist/cli-TIDQ4WUE.js +257 -0
- package/dist/cli-TT36JCU5.js +370 -0
- package/dist/cli-TTKICM5P.js +100 -0
- package/dist/cli-TTMBBEJC.js +131 -0
- package/dist/cli-UMEBPAZQ.js +16 -0
- package/dist/cli-UNAJ2OTE.js +15 -0
- package/dist/cli-UZZFNXRX.js +226 -0
- package/dist/cli-VDBW23SS.js +81 -0
- package/dist/cli-VL2P354N.js +46 -0
- package/dist/cli-VPRRICZA.js +304 -0
- package/dist/cli-VQ6HVQW4.js +4010 -0
- package/dist/cli-WR3NOY74.js +36 -0
- package/dist/cli-WU43JT4T.js +52 -0
- package/dist/cli-XAT25PRU.js +117 -0
- package/dist/cli-XOTNXEJA.js +124 -0
- package/dist/cli-XSLNH5PR.js +6417 -0
- package/dist/cli-XSVGKI3R.js +39 -0
- package/dist/cli-XZCJIKIV.js +124 -0
- package/dist/cli-Y3DDNMPX.js +97 -0
- package/dist/cli-Y3O5F4JN.js +90 -0
- package/dist/cli-YOTGR3NB.js +82 -0
- package/dist/cli-Z56ZIVA6.js +97 -0
- package/dist/cli-ZBN5KAIB.js +59 -0
- package/dist/cli-ZDOTXEKL.js +31 -0
- package/dist/cli-ZDUADFBY.js +88 -0
- package/dist/cli-ZJFQ7EEA.js +131 -0
- package/dist/cli-ZTWOE3ZT.js +65 -0
- package/dist/cli.js +148 -43093
- package/dist/client/build-surfaces.d.ts +33 -0
- package/dist/client/dev-server.d.ts +6 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/playwright.d.ts +62 -0
- package/dist/client.js +228 -48
- package/dist/core/session.d.ts +15 -1
- package/dist/dev/console/assets/{index-BVF8exas.js → index-CuMOOH9m.js} +1 -1
- package/dist/dev/console/index.html +1 -1
- package/dist/dev/shell.d.ts +19 -0
- package/dist/dev/surfaces.d.ts +7 -0
- package/dist/docs/ai-agents.md +1 -1
- package/dist/docs/api/index.md +14 -12
- package/dist/docs/api/sdk-tools-client.md +29 -0
- package/dist/docs/api/sdk-tools-playwright.md +104 -0
- package/dist/docs/changelog.md +34 -0
- package/dist/docs/cli-and-dev-server.md +21 -0
- package/dist/docs/cli-reference.md +45 -31
- package/dist/docs/environment-variables.md +6 -0
- package/dist/docs/getting-started.md +1 -1
- package/dist/docs/guides/designing-a-game.md +29 -4
- package/dist/docs/guides/starter-game.md +3 -3
- package/dist/docs/guides/testing.md +33 -18
- package/dist/docs/guides/upgrading.md +19 -2
- package/dist/docs/page-index.md +10 -9
- package/dist/docs/recipes/e2e-testing.md +19 -20
- package/dist/playwright.js +32232 -0
- package/dist/templates/package/CLAUDE.md.template +7 -346
- package/dist/templates/package/claude/rules/workflow-create-engine.md +2 -2
- package/dist/templates/package/claude/rules/workflow-create-guide.md +2 -2
- 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 +3 -3
- package/dist/templates/package/global-setup.ts.template +7 -18
- package/dist/templates/package/playwright.config.ts.liquid +8 -11
- package/dist/templates/starter-game/playwright.config.ts +8 -11
- package/dist/templates/starter-game/testing/e2e/game.spec.ts +1 -1
- package/dist/templates/starter-game/testing/e2e/global-setup.ts +7 -18
- package/dist/utils/prompt.d.ts +5 -5
- package/dist/utils/resource-scan.d.ts +39 -0
- package/package.json +7 -3
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
confirm,
|
|
4
|
+
input,
|
|
5
|
+
select
|
|
6
|
+
} from "./cli-ZTWOE3ZT.js";
|
|
7
|
+
|
|
8
|
+
// cli/prompts/validators.ts
|
|
9
|
+
var PASCAL_CASE_PATTERN = /^[A-Z][a-zA-Z0-9]*$/;
|
|
10
|
+
function validatePropertyName(name, existingNames) {
|
|
11
|
+
if (!name.trim()) {
|
|
12
|
+
return "Property name is required";
|
|
13
|
+
}
|
|
14
|
+
if (!PASCAL_CASE_PATTERN.test(name.trim())) {
|
|
15
|
+
return "Property name must be in PascalCase (start with uppercase letter, no spaces or special characters)";
|
|
16
|
+
}
|
|
17
|
+
if (existingNames.includes(name.trim())) {
|
|
18
|
+
return "A property with this name already exists";
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
function validateNumberValue(value, constraints) {
|
|
23
|
+
if (isNaN(Number(value))) {
|
|
24
|
+
return "Value must be a valid number";
|
|
25
|
+
}
|
|
26
|
+
const numValue = Number(value);
|
|
27
|
+
if (constraints?.min !== void 0 && numValue < constraints.min) {
|
|
28
|
+
return `Value must be greater than or equal to ${constraints.min}`;
|
|
29
|
+
}
|
|
30
|
+
if (constraints?.max !== void 0 && numValue > constraints.max) {
|
|
31
|
+
return `Value must be less than or equal to ${constraints.max}`;
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
function validateMaximumValue(maximum, minimum) {
|
|
36
|
+
const baseValidation = validateNumberValue(maximum);
|
|
37
|
+
if (baseValidation !== true) {
|
|
38
|
+
return baseValidation;
|
|
39
|
+
}
|
|
40
|
+
if (minimum !== void 0 && Number(maximum) < minimum) {
|
|
41
|
+
return "Maximum must be greater than or equal to minimum";
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// cli/prompts/schema-builder.ts
|
|
47
|
+
async function promptNumberProperties(currentDefaults) {
|
|
48
|
+
const defaultValue = await input({
|
|
49
|
+
message: "Default value (number):",
|
|
50
|
+
default: currentDefaults?.default !== void 0 ? String(currentDefaults.default) : "0",
|
|
51
|
+
validate: (value) => validateNumberValue(value)
|
|
52
|
+
});
|
|
53
|
+
const defaults = {
|
|
54
|
+
default: Number(defaultValue)
|
|
55
|
+
};
|
|
56
|
+
const currentHasMin = currentDefaults?.minimum !== void 0;
|
|
57
|
+
const hasMinimum = await confirm({
|
|
58
|
+
message: "Add minimum value constraint?",
|
|
59
|
+
default: currentHasMin
|
|
60
|
+
});
|
|
61
|
+
if (hasMinimum) {
|
|
62
|
+
const minimum = await input({
|
|
63
|
+
message: "Minimum value:",
|
|
64
|
+
default: currentHasMin ? String(currentDefaults.minimum) : "",
|
|
65
|
+
validate: (value) => validateNumberValue(value)
|
|
66
|
+
});
|
|
67
|
+
defaults.minimum = Number(minimum);
|
|
68
|
+
}
|
|
69
|
+
const currentHasMax = currentDefaults?.maximum !== void 0;
|
|
70
|
+
const hasMaximum = await confirm({
|
|
71
|
+
message: "Add maximum value constraint?",
|
|
72
|
+
default: currentHasMax
|
|
73
|
+
});
|
|
74
|
+
if (hasMaximum) {
|
|
75
|
+
const maximum = await input({
|
|
76
|
+
message: "Maximum value:",
|
|
77
|
+
default: currentHasMax ? String(currentDefaults.maximum) : "",
|
|
78
|
+
validate: (value) => validateMaximumValue(value, defaults.minimum)
|
|
79
|
+
});
|
|
80
|
+
defaults.maximum = Number(maximum);
|
|
81
|
+
}
|
|
82
|
+
return defaults;
|
|
83
|
+
}
|
|
84
|
+
async function promptStringProperties(currentDefaults) {
|
|
85
|
+
const defaultValue = await input({
|
|
86
|
+
message: "Default value (string):",
|
|
87
|
+
default: currentDefaults?.default ?? ""
|
|
88
|
+
});
|
|
89
|
+
return { default: defaultValue };
|
|
90
|
+
}
|
|
91
|
+
async function promptBooleanProperties(currentDefaults) {
|
|
92
|
+
const defaultValue = await confirm({
|
|
93
|
+
message: "Default value:",
|
|
94
|
+
default: currentDefaults?.default ?? false
|
|
95
|
+
});
|
|
96
|
+
return { default: defaultValue };
|
|
97
|
+
}
|
|
98
|
+
var CONTEXT_COPY = {
|
|
99
|
+
variable: {
|
|
100
|
+
label: "Variable",
|
|
101
|
+
singular: "variable",
|
|
102
|
+
plural: "variables",
|
|
103
|
+
intro: "Variables define the state this capability holds."
|
|
104
|
+
},
|
|
105
|
+
setting: {
|
|
106
|
+
label: "Setting",
|
|
107
|
+
singular: "setting",
|
|
108
|
+
plural: "settings",
|
|
109
|
+
intro: "Settings are the values a game plays with, which scenarios can override."
|
|
110
|
+
},
|
|
111
|
+
property: { label: "Property", singular: "property", plural: "properties" }
|
|
112
|
+
};
|
|
113
|
+
async function promptForSchemaProperty(options) {
|
|
114
|
+
const contextLabel = CONTEXT_COPY[options.context || "variable"].label;
|
|
115
|
+
const propertyName = await input({
|
|
116
|
+
message: `${contextLabel} name (PascalCase, e.g., "Price", "TotalCost"):`,
|
|
117
|
+
validate: (value) => validatePropertyName(value, options.existingNames)
|
|
118
|
+
});
|
|
119
|
+
const propertyType = await select({
|
|
120
|
+
message: `${contextLabel} type:`,
|
|
121
|
+
choices: [
|
|
122
|
+
{ name: "Number", value: "number" },
|
|
123
|
+
{ name: "String", value: "string" },
|
|
124
|
+
{ name: "Boolean", value: "boolean" }
|
|
125
|
+
]
|
|
126
|
+
});
|
|
127
|
+
const propertyDescription = await input({
|
|
128
|
+
message: `${contextLabel} description:`,
|
|
129
|
+
validate: (value) => {
|
|
130
|
+
if (!value.trim()) {
|
|
131
|
+
return "Description is required";
|
|
132
|
+
}
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
const propertySchema = {
|
|
137
|
+
type: propertyType,
|
|
138
|
+
description: propertyDescription
|
|
139
|
+
};
|
|
140
|
+
if (propertyType === "number") {
|
|
141
|
+
const numberDefaults = await promptNumberProperties();
|
|
142
|
+
propertySchema.default = numberDefaults.default;
|
|
143
|
+
if (numberDefaults.minimum !== void 0) {
|
|
144
|
+
propertySchema.minimum = numberDefaults.minimum;
|
|
145
|
+
}
|
|
146
|
+
if (numberDefaults.maximum !== void 0) {
|
|
147
|
+
propertySchema.maximum = numberDefaults.maximum;
|
|
148
|
+
}
|
|
149
|
+
} else if (propertyType === "string") {
|
|
150
|
+
const stringDefaults = await promptStringProperties();
|
|
151
|
+
propertySchema.default = stringDefaults.default;
|
|
152
|
+
} else if (propertyType === "boolean") {
|
|
153
|
+
const booleanDefaults = await promptBooleanProperties();
|
|
154
|
+
propertySchema.default = booleanDefaults.default;
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
name: propertyName.trim(),
|
|
158
|
+
schema: propertySchema
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
async function promptForSchemaProperties(options = {}) {
|
|
162
|
+
const context = options.context || "variable";
|
|
163
|
+
const copy = CONTEXT_COPY[context];
|
|
164
|
+
const properties = {
|
|
165
|
+
...options.existingProperties
|
|
166
|
+
};
|
|
167
|
+
const existingNames = Object.keys(properties);
|
|
168
|
+
if (existingNames.length === 0) {
|
|
169
|
+
console.log(`Now let's add ${copy.plural}.`);
|
|
170
|
+
if (copy.intro) console.log(`${copy.intro}
|
|
171
|
+
`);
|
|
172
|
+
}
|
|
173
|
+
let addingProperties = true;
|
|
174
|
+
while (addingProperties) {
|
|
175
|
+
const result = await promptForSchemaProperty({
|
|
176
|
+
existingNames: Object.keys(properties),
|
|
177
|
+
context
|
|
178
|
+
});
|
|
179
|
+
if (result) {
|
|
180
|
+
properties[result.name] = result.schema;
|
|
181
|
+
console.log(`
|
|
182
|
+
\u2713 Added ${copy.singular}: ${result.name} (${result.schema.type})
|
|
183
|
+
`);
|
|
184
|
+
}
|
|
185
|
+
if (options.minProperties !== void 0 && Object.keys(properties).length < options.minProperties) {
|
|
186
|
+
console.log(`At least ${options.minProperties} ${copy.plural} required.
|
|
187
|
+
`);
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
addingProperties = await confirm({
|
|
191
|
+
message: `Add another ${copy.singular}?`,
|
|
192
|
+
default: Object.keys(properties).length === 0
|
|
193
|
+
});
|
|
194
|
+
if (addingProperties) {
|
|
195
|
+
console.log("");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return properties;
|
|
199
|
+
}
|
|
200
|
+
async function editSchemaProperty(name, currentSchema) {
|
|
201
|
+
const modifiedChanges = [];
|
|
202
|
+
const newDescription = await input({
|
|
203
|
+
message: "Property description:",
|
|
204
|
+
default: currentSchema.description || "",
|
|
205
|
+
validate: (value) => {
|
|
206
|
+
if (!value.trim()) {
|
|
207
|
+
return "Description is required";
|
|
208
|
+
}
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
const editedSchema = {
|
|
213
|
+
type: currentSchema.type,
|
|
214
|
+
description: newDescription
|
|
215
|
+
};
|
|
216
|
+
if (newDescription !== currentSchema.description) {
|
|
217
|
+
modifiedChanges.push("description");
|
|
218
|
+
}
|
|
219
|
+
if (currentSchema.type === "number") {
|
|
220
|
+
const numberDefaults = await promptNumberProperties({
|
|
221
|
+
default: currentSchema.default,
|
|
222
|
+
minimum: currentSchema.minimum,
|
|
223
|
+
maximum: currentSchema.maximum
|
|
224
|
+
});
|
|
225
|
+
editedSchema.default = numberDefaults.default;
|
|
226
|
+
if (numberDefaults.default !== currentSchema.default) {
|
|
227
|
+
modifiedChanges.push("default");
|
|
228
|
+
}
|
|
229
|
+
if (numberDefaults.minimum !== void 0) {
|
|
230
|
+
editedSchema.minimum = numberDefaults.minimum;
|
|
231
|
+
if (numberDefaults.minimum !== currentSchema.minimum) {
|
|
232
|
+
modifiedChanges.push("minimum");
|
|
233
|
+
}
|
|
234
|
+
} else if (currentSchema.minimum !== void 0) {
|
|
235
|
+
modifiedChanges.push("minimum removed");
|
|
236
|
+
}
|
|
237
|
+
if (numberDefaults.maximum !== void 0) {
|
|
238
|
+
editedSchema.maximum = numberDefaults.maximum;
|
|
239
|
+
if (numberDefaults.maximum !== currentSchema.maximum) {
|
|
240
|
+
modifiedChanges.push("maximum");
|
|
241
|
+
}
|
|
242
|
+
} else if (currentSchema.maximum !== void 0) {
|
|
243
|
+
modifiedChanges.push("maximum removed");
|
|
244
|
+
}
|
|
245
|
+
} else if (currentSchema.type === "string") {
|
|
246
|
+
const stringDefaults = await promptStringProperties({
|
|
247
|
+
default: currentSchema.default
|
|
248
|
+
});
|
|
249
|
+
editedSchema.default = stringDefaults.default;
|
|
250
|
+
if (stringDefaults.default !== currentSchema.default) {
|
|
251
|
+
modifiedChanges.push("default");
|
|
252
|
+
}
|
|
253
|
+
} else if (currentSchema.type === "boolean") {
|
|
254
|
+
const booleanDefaults = await promptBooleanProperties({
|
|
255
|
+
default: currentSchema.default
|
|
256
|
+
});
|
|
257
|
+
editedSchema.default = booleanDefaults.default;
|
|
258
|
+
if (booleanDefaults.default !== currentSchema.default) {
|
|
259
|
+
modifiedChanges.push("default");
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (modifiedChanges.length > 0) {
|
|
263
|
+
return {
|
|
264
|
+
action: "edit",
|
|
265
|
+
schema: editedSchema,
|
|
266
|
+
changes: modifiedChanges
|
|
267
|
+
};
|
|
268
|
+
} else {
|
|
269
|
+
return {
|
|
270
|
+
action: "keep",
|
|
271
|
+
schema: currentSchema,
|
|
272
|
+
changes: []
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
async function reviewSchemaProperties(existingProperties, options = {}) {
|
|
277
|
+
const newProperties = {};
|
|
278
|
+
const changes = {
|
|
279
|
+
kept: [],
|
|
280
|
+
modified: [],
|
|
281
|
+
deleted: [],
|
|
282
|
+
added: []
|
|
283
|
+
};
|
|
284
|
+
const existingEntries = Object.entries(existingProperties);
|
|
285
|
+
if (existingEntries.length > 0) {
|
|
286
|
+
console.log("Let's review your existing properties.\n");
|
|
287
|
+
for (const [propName, propSchema] of existingEntries) {
|
|
288
|
+
console.log(`Property: ${propName}`);
|
|
289
|
+
console.log(` Type: ${propSchema.type}`);
|
|
290
|
+
console.log(` Description: ${propSchema.description || "(none)"}`);
|
|
291
|
+
if (propSchema.default !== void 0) {
|
|
292
|
+
console.log(` Default: ${propSchema.default}`);
|
|
293
|
+
}
|
|
294
|
+
if (propSchema.minimum !== void 0) {
|
|
295
|
+
console.log(` Minimum: ${propSchema.minimum}`);
|
|
296
|
+
}
|
|
297
|
+
if (propSchema.maximum !== void 0) {
|
|
298
|
+
console.log(` Maximum: ${propSchema.maximum}`);
|
|
299
|
+
}
|
|
300
|
+
console.log("");
|
|
301
|
+
const actionChoices = [
|
|
302
|
+
{ name: "Keep unchanged", value: "keep" },
|
|
303
|
+
{ name: "Edit", value: "edit" }
|
|
304
|
+
];
|
|
305
|
+
if (options.allowDelete) {
|
|
306
|
+
actionChoices.push({ name: "Delete", value: "delete" });
|
|
307
|
+
}
|
|
308
|
+
const action = await select({
|
|
309
|
+
message: `What do you want to do with "${propName}"?`,
|
|
310
|
+
choices: actionChoices
|
|
311
|
+
});
|
|
312
|
+
if (action === "keep") {
|
|
313
|
+
newProperties[propName] = propSchema;
|
|
314
|
+
changes.kept.push(propName);
|
|
315
|
+
console.log(`\u2713 Keeping ${propName} unchanged
|
|
316
|
+
`);
|
|
317
|
+
} else if (action === "delete") {
|
|
318
|
+
changes.deleted.push(propName);
|
|
319
|
+
console.log(`\u2713 Will delete ${propName}
|
|
320
|
+
`);
|
|
321
|
+
} else {
|
|
322
|
+
const result = await editSchemaProperty(propName, propSchema);
|
|
323
|
+
newProperties[propName] = result.schema;
|
|
324
|
+
if (result.changes && result.changes.length > 0) {
|
|
325
|
+
changes.modified.push({
|
|
326
|
+
name: propName,
|
|
327
|
+
changes: result.changes.join(", ")
|
|
328
|
+
});
|
|
329
|
+
console.log(`\u2713 Modified ${propName} (${result.changes.join(", ")})
|
|
330
|
+
`);
|
|
331
|
+
} else {
|
|
332
|
+
changes.kept.push(propName);
|
|
333
|
+
console.log(`\u2713 No changes to ${propName}
|
|
334
|
+
`);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (options.allowAdd) {
|
|
340
|
+
const addNew = await confirm({
|
|
341
|
+
message: "Add new properties?",
|
|
342
|
+
default: false
|
|
343
|
+
});
|
|
344
|
+
if (addNew) {
|
|
345
|
+
console.log("");
|
|
346
|
+
const newProps = await promptForSchemaProperties({
|
|
347
|
+
existingProperties: newProperties,
|
|
348
|
+
context: options.context
|
|
349
|
+
});
|
|
350
|
+
for (const propName of Object.keys(newProps)) {
|
|
351
|
+
if (!newProperties[propName]) {
|
|
352
|
+
changes.added.push(propName);
|
|
353
|
+
}
|
|
354
|
+
newProperties[propName] = newProps[propName];
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return {
|
|
359
|
+
properties: newProperties,
|
|
360
|
+
changes
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export {
|
|
365
|
+
promptForSchemaProperties,
|
|
366
|
+
reviewSchemaProperties
|
|
367
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// cli/utils/json-patch.ts
|
|
4
|
+
import * as rfc6902 from "rfc6902";
|
|
5
|
+
function applyJsonPatch(obj, operations) {
|
|
6
|
+
let result = structuredClone(obj);
|
|
7
|
+
const realmSafeOperations = structuredClone(operations);
|
|
8
|
+
try {
|
|
9
|
+
const errors = rfc6902.applyPatch(result, realmSafeOperations);
|
|
10
|
+
if (errors && errors.length > 0) {
|
|
11
|
+
const actualErrors = errors.filter((e) => e !== null);
|
|
12
|
+
if (actualErrors.length > 0) {
|
|
13
|
+
const errorMessages = actualErrors.map((e) => e?.message || String(e)).join("; ");
|
|
14
|
+
throw new Error(`Patch failed: ${errorMessages}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
const message = error.message;
|
|
20
|
+
if (message.includes("out of range")) {
|
|
21
|
+
throw new Error("Array index out of range");
|
|
22
|
+
}
|
|
23
|
+
if (message.includes("undefined") || message.includes("Cannot read")) {
|
|
24
|
+
throw new Error("Path does not exist");
|
|
25
|
+
}
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
applyJsonPatch
|
|
32
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
CliError
|
|
4
|
+
} from "./cli-N6H6T2E2.js";
|
|
5
|
+
|
|
6
|
+
// cli/dev/lockfile.ts
|
|
7
|
+
import { createHash, randomUUID } from "crypto";
|
|
8
|
+
import { existsSync as existsSync2 } from "fs";
|
|
9
|
+
import { mkdir, readFile, rm, writeFile } from "fs/promises";
|
|
10
|
+
import { hostname } from "os";
|
|
11
|
+
import { basename, dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
12
|
+
|
|
13
|
+
// cli/dev/tools-identity.ts
|
|
14
|
+
import { existsSync, readFileSync, realpathSync } from "fs";
|
|
15
|
+
import { dirname, join, resolve, sep } from "path";
|
|
16
|
+
import { fileURLToPath } from "url";
|
|
17
|
+
var cached = null;
|
|
18
|
+
function toolsIdentity() {
|
|
19
|
+
cached ??= readIdentity(fileURLToPath(import.meta.url));
|
|
20
|
+
return cached;
|
|
21
|
+
}
|
|
22
|
+
function readIdentity(filename) {
|
|
23
|
+
const here = dirname(filename);
|
|
24
|
+
const fromSource = filename.includes(`${sep}cli${sep}dev${sep}`);
|
|
25
|
+
const root = fromSource ? resolve(here, "..", "..") : resolve(here, "..");
|
|
26
|
+
const entry = fromSource ? join(root, "cli", "cli.ts") : join(here, "cli.js");
|
|
27
|
+
let version = "0.0.0";
|
|
28
|
+
try {
|
|
29
|
+
const manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf-8"));
|
|
30
|
+
version = manifest.version ?? version;
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
return { version, path: existsSync(entry) ? realpathSync(entry) : entry };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// cli/dev/lockfile.ts
|
|
37
|
+
var DEV_STATE_DIR_ENV_VAR = "SERIOUSGAMING_DEV_STATE_DIR";
|
|
38
|
+
var ownInstances = /* @__PURE__ */ new Set();
|
|
39
|
+
function lockFilePath(packagePath, env = process.env) {
|
|
40
|
+
const stateDir = env[DEV_STATE_DIR_ENV_VAR]?.trim();
|
|
41
|
+
if (!stateDir) return join2(packagePath, ".seriousgaming-sdk", "session.json");
|
|
42
|
+
const absolute = resolve2(packagePath);
|
|
43
|
+
const key = createHash("sha256").update(absolute).digest("hex").slice(0, 12);
|
|
44
|
+
return join2(resolve2(stateDir), `${basename(absolute)}-${key}`, "session.json");
|
|
45
|
+
}
|
|
46
|
+
async function writeLockFile(packagePath, details) {
|
|
47
|
+
const path = lockFilePath(packagePath);
|
|
48
|
+
await mkdir(dirname2(path), { recursive: true });
|
|
49
|
+
const tools = toolsIdentity();
|
|
50
|
+
const lock = {
|
|
51
|
+
pid: process.pid,
|
|
52
|
+
port: details.port,
|
|
53
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
54
|
+
toolsVersion: tools.version,
|
|
55
|
+
toolsPath: tools.path,
|
|
56
|
+
hostname: hostname(),
|
|
57
|
+
instanceId: details.instanceId,
|
|
58
|
+
background: details.background ?? false
|
|
59
|
+
};
|
|
60
|
+
ownInstances.add(details.instanceId);
|
|
61
|
+
await writeFile(path, `${JSON.stringify(lock, null, 4)}
|
|
62
|
+
`, "utf-8");
|
|
63
|
+
}
|
|
64
|
+
async function removeLockFile(packagePath, instanceId) {
|
|
65
|
+
if (instanceId !== void 0) ownInstances.delete(instanceId);
|
|
66
|
+
await rm(lockFilePath(packagePath), { force: true });
|
|
67
|
+
}
|
|
68
|
+
function newInstanceId() {
|
|
69
|
+
return randomUUID();
|
|
70
|
+
}
|
|
71
|
+
async function readLockFile(packagePath, options = {}) {
|
|
72
|
+
const inspection = await inspectLockFile(packagePath, options);
|
|
73
|
+
if (inspection.status === "live") return inspection.lock;
|
|
74
|
+
if (inspection.status === "unresponsive") {
|
|
75
|
+
if (options.unresponsive === "accept") return inspection.lock;
|
|
76
|
+
throw unresponsiveError(inspection.lock);
|
|
77
|
+
}
|
|
78
|
+
if (inspection.status === "stale") await rm(lockFilePath(packagePath), { force: true });
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
async function inspectLockFile(packagePath, options = {}) {
|
|
82
|
+
const path = lockFilePath(packagePath);
|
|
83
|
+
if (!existsSync2(path)) return { status: "none" };
|
|
84
|
+
let lock;
|
|
85
|
+
try {
|
|
86
|
+
lock = JSON.parse(await readFile(path, "utf-8"));
|
|
87
|
+
} catch {
|
|
88
|
+
return { status: "stale", reason: "unreadable" };
|
|
89
|
+
}
|
|
90
|
+
if (typeof lock.pid !== "number" || typeof lock.port !== "number") {
|
|
91
|
+
return { status: "stale", reason: "unreadable" };
|
|
92
|
+
}
|
|
93
|
+
const own = typeof lock.instanceId === "string" && ownInstances.has(lock.instanceId);
|
|
94
|
+
if (lock.pid === process.pid && !own) return { status: "stale", reason: "this-process" };
|
|
95
|
+
if (typeof lock.hostname === "string" && lock.hostname !== hostname()) {
|
|
96
|
+
return { status: "stale", reason: "other-host" };
|
|
97
|
+
}
|
|
98
|
+
if (!isAlive(lock.pid)) return { status: "stale", reason: "process-gone" };
|
|
99
|
+
const answer = await (options.probe ?? probeInstance)(lock.port);
|
|
100
|
+
if (answer === "refused") return { status: "stale", reason: "not-answering" };
|
|
101
|
+
if (answer === "unknown") return { status: "unresponsive", lock };
|
|
102
|
+
if (typeof lock.instanceId === "string" && answer !== lock.instanceId) {
|
|
103
|
+
return { status: "stale", reason: "other-instance" };
|
|
104
|
+
}
|
|
105
|
+
return { status: "live", lock };
|
|
106
|
+
}
|
|
107
|
+
var PROBE_TIMEOUT_MS = 5e3;
|
|
108
|
+
async function probeInstance(port, options = {}) {
|
|
109
|
+
try {
|
|
110
|
+
const response = await fetch(`http://localhost:${port}/api/session`, {
|
|
111
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? PROBE_TIMEOUT_MS)
|
|
112
|
+
});
|
|
113
|
+
if (!response.ok) return null;
|
|
114
|
+
const body = await response.json().catch(() => ({}));
|
|
115
|
+
return typeof body.instanceId === "string" ? body.instanceId : null;
|
|
116
|
+
} catch (error) {
|
|
117
|
+
return refused(error) ? "refused" : "unknown";
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function refused(error) {
|
|
121
|
+
const cause = error?.cause;
|
|
122
|
+
if (cause?.code === "ECONNREFUSED") return true;
|
|
123
|
+
return (cause?.errors ?? []).length > 0 ? (cause?.errors ?? []).every((inner) => inner.code === "ECONNREFUSED") : false;
|
|
124
|
+
}
|
|
125
|
+
function unresponsiveError(lock) {
|
|
126
|
+
return new CliError(
|
|
127
|
+
"DEV_SERVER_UNRESPONSIVE",
|
|
128
|
+
`The dev server for this package (pid ${lock.pid}, port ${lock.port}) accepts connections but did not answer within ${PROBE_TIMEOUT_MS / 1e3}s. Its logic is most likely stuck in a synchronous loop.`,
|
|
129
|
+
{
|
|
130
|
+
hint: "Stop it with `sdk dev stop`, which kills it if it does not exit, then run the command again."
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
async function lockOnDisk(packagePath) {
|
|
135
|
+
try {
|
|
136
|
+
return JSON.parse(await readFile(lockFilePath(packagePath), "utf-8"));
|
|
137
|
+
} catch {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function isAlive(pid) {
|
|
142
|
+
try {
|
|
143
|
+
process.kill(pid, 0);
|
|
144
|
+
return true;
|
|
145
|
+
} catch (error) {
|
|
146
|
+
return error.code === "EPERM";
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export {
|
|
151
|
+
toolsIdentity,
|
|
152
|
+
writeLockFile,
|
|
153
|
+
removeLockFile,
|
|
154
|
+
newInstanceId,
|
|
155
|
+
readLockFile,
|
|
156
|
+
inspectLockFile,
|
|
157
|
+
lockOnDisk,
|
|
158
|
+
isAlive
|
|
159
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
loadGlobalSettings
|
|
4
|
+
} from "./cli-MMN4BPO4.js";
|
|
5
|
+
|
|
6
|
+
// cli/utils/env-loader.ts
|
|
7
|
+
import { readFileSync, existsSync } from "fs";
|
|
8
|
+
import { join } from "path";
|
|
9
|
+
function parseEnvFile(content) {
|
|
10
|
+
const vars = {};
|
|
11
|
+
const lines = content.split(/\r?\n/);
|
|
12
|
+
for (const line of lines) {
|
|
13
|
+
const trimmed = line.trim();
|
|
14
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const match = trimmed.match(/^([A-Z_][A-Z0-9_]*)=(.*)$/i);
|
|
18
|
+
if (match) {
|
|
19
|
+
const key = match[1];
|
|
20
|
+
let value = match[2];
|
|
21
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
22
|
+
value = value.slice(1, -1);
|
|
23
|
+
}
|
|
24
|
+
vars[key] = value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return vars;
|
|
28
|
+
}
|
|
29
|
+
function loadEnvironmentConfig(workingDir, flags) {
|
|
30
|
+
const config = {};
|
|
31
|
+
const ttsVoicePresets = {};
|
|
32
|
+
applyGlobalSettings(config);
|
|
33
|
+
const envPath = join(workingDir, ".env");
|
|
34
|
+
if (existsSync(envPath)) {
|
|
35
|
+
try {
|
|
36
|
+
const content = readFileSync(envPath, "utf-8");
|
|
37
|
+
const envVars = parseEnvFile(content);
|
|
38
|
+
if (envVars.ELEVENLABS_API_KEY) {
|
|
39
|
+
config.elevenLabsApiKey = envVars.ELEVENLABS_API_KEY;
|
|
40
|
+
}
|
|
41
|
+
if (envVars.TTS_MODEL_QUICK) {
|
|
42
|
+
config.ttsQuickModel = envVars.TTS_MODEL_QUICK;
|
|
43
|
+
}
|
|
44
|
+
if (envVars.TTS_MODEL_STANDARD) {
|
|
45
|
+
config.ttsStandardModel = envVars.TTS_MODEL_STANDARD;
|
|
46
|
+
}
|
|
47
|
+
if (envVars.TTS_MODEL_EXPERT) {
|
|
48
|
+
config.ttsExpertModel = envVars.TTS_MODEL_EXPERT;
|
|
49
|
+
}
|
|
50
|
+
if (envVars.SERIOUSGAMING_API_KEY) {
|
|
51
|
+
config.seriousGamingApiKey = envVars.SERIOUSGAMING_API_KEY;
|
|
52
|
+
}
|
|
53
|
+
if (envVars.SERIOUSGAMING_API_HOST) {
|
|
54
|
+
config.seriousGamingApiHost = envVars.SERIOUSGAMING_API_HOST;
|
|
55
|
+
}
|
|
56
|
+
if (envVars.SERIOUSGAMING_PUBLISHER) {
|
|
57
|
+
config.defaultPublisher = envVars.SERIOUSGAMING_PUBLISHER;
|
|
58
|
+
}
|
|
59
|
+
collectVoicePresets(envVars, ttsVoicePresets);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.warn(
|
|
62
|
+
"Warning: Failed to read .env file:",
|
|
63
|
+
error instanceof Error ? error.message : "Unknown error"
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (process.env.ELEVENLABS_API_KEY) {
|
|
68
|
+
config.elevenLabsApiKey = process.env.ELEVENLABS_API_KEY;
|
|
69
|
+
}
|
|
70
|
+
if (process.env.TTS_MODEL_QUICK) {
|
|
71
|
+
config.ttsQuickModel = process.env.TTS_MODEL_QUICK;
|
|
72
|
+
}
|
|
73
|
+
if (process.env.TTS_MODEL_STANDARD) {
|
|
74
|
+
config.ttsStandardModel = process.env.TTS_MODEL_STANDARD;
|
|
75
|
+
}
|
|
76
|
+
if (process.env.TTS_MODEL_EXPERT) {
|
|
77
|
+
config.ttsExpertModel = process.env.TTS_MODEL_EXPERT;
|
|
78
|
+
}
|
|
79
|
+
if (process.env.SERIOUSGAMING_API_KEY) {
|
|
80
|
+
config.seriousGamingApiKey = process.env.SERIOUSGAMING_API_KEY;
|
|
81
|
+
}
|
|
82
|
+
if (process.env.SERIOUSGAMING_API_HOST) {
|
|
83
|
+
config.seriousGamingApiHost = process.env.SERIOUSGAMING_API_HOST;
|
|
84
|
+
}
|
|
85
|
+
if (process.env.SERIOUSGAMING_PUBLISHER) {
|
|
86
|
+
config.defaultPublisher = process.env.SERIOUSGAMING_PUBLISHER;
|
|
87
|
+
}
|
|
88
|
+
collectVoicePresets(process.env, ttsVoicePresets);
|
|
89
|
+
if (flags?.seriousGamingApiKey) {
|
|
90
|
+
config.seriousGamingApiKey = flags.seriousGamingApiKey;
|
|
91
|
+
}
|
|
92
|
+
if (flags?.seriousGamingApiHost) {
|
|
93
|
+
config.seriousGamingApiHost = flags.seriousGamingApiHost;
|
|
94
|
+
}
|
|
95
|
+
if (flags?.defaultPublisher) {
|
|
96
|
+
config.defaultPublisher = flags.defaultPublisher;
|
|
97
|
+
}
|
|
98
|
+
if (Object.keys(ttsVoicePresets).length > 0) {
|
|
99
|
+
config.ttsVoicePresets = ttsVoicePresets;
|
|
100
|
+
}
|
|
101
|
+
return config;
|
|
102
|
+
}
|
|
103
|
+
function applyGlobalSettings(config) {
|
|
104
|
+
const settings = loadGlobalSettings();
|
|
105
|
+
if (settings.elevenLabs?.apiKey) {
|
|
106
|
+
config.elevenLabsApiKey = settings.elevenLabs.apiKey;
|
|
107
|
+
}
|
|
108
|
+
if (settings.platform?.apiHost) {
|
|
109
|
+
config.seriousGamingApiHost = settings.platform.apiHost;
|
|
110
|
+
}
|
|
111
|
+
if (settings.platform?.apiKey) {
|
|
112
|
+
config.seriousGamingApiKey = settings.platform.apiKey;
|
|
113
|
+
}
|
|
114
|
+
if (settings.platform?.defaultPublisher) {
|
|
115
|
+
config.defaultPublisher = settings.platform.defaultPublisher;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function collectVoicePresets(source, target) {
|
|
119
|
+
const prefix = "TTS_VOICE_";
|
|
120
|
+
for (const [key, value] of Object.entries(source)) {
|
|
121
|
+
if (!key.startsWith(prefix)) continue;
|
|
122
|
+
if (!value) continue;
|
|
123
|
+
const preset = key.slice(prefix.length).toLowerCase();
|
|
124
|
+
if (!preset) continue;
|
|
125
|
+
target[preset] = value;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export {
|
|
130
|
+
loadEnvironmentConfig
|
|
131
|
+
};
|