@gameslate/sdk 0.3.10 → 0.3.12
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/README.md +3 -0
- package/bin/gameslate-plugin.mjs +65 -0
- package/build/verify-effects.mjs +18 -2
- package/lib/game-support-yaml.d.ts +5 -0
- package/lib/game-support-yaml.js +124 -0
- package/lib/game-support.d.ts +400 -0
- package/lib/game-support.js +306 -0
- package/lib/host/addresses.d.ts +47 -0
- package/lib/host/addresses.js +79 -3
- package/lib/host/game-support.d.ts +27 -0
- package/lib/host/game-support.js +101 -0
- package/lib/host/index.d.ts +2 -0
- package/lib/host/index.js +2 -0
- package/lib/host/live-sandbox.d.ts +1 -0
- package/lib/host/live-sandbox.js +19 -0
- package/lib/host/udp-ports.d.ts +4 -0
- package/lib/host/udp-ports.js +26 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/pack.d.ts +15 -0
- package/lib/pack.js +14 -1
- package/lib/plugin/contract.d.ts +5 -0
- package/lib/plugin/sandbox-guest.js +3 -0
- package/lib/sandbox-protocol.d.ts +21 -0
- package/package.json +1 -1
- package/template/claude/skills/build-gameslate-plugin/SKILL.md +330 -9
- package/template/claude/skills/verify-gameslate-plugin/SKILL.md +76 -3
- package/template/{test → plugin}/live.test.ts +1 -1
- package/template/tsconfig.json +1 -1
package/lib/host/live-sandbox.js
CHANGED
|
@@ -36,6 +36,7 @@ export class PluginSandbox {
|
|
|
36
36
|
log;
|
|
37
37
|
now;
|
|
38
38
|
memories = new Map();
|
|
39
|
+
sessionGames = new Map();
|
|
39
40
|
nextHandle = 1;
|
|
40
41
|
/* each state's views, so a pack's three view accessors cost one call */
|
|
41
42
|
viewsCache = new WeakMap();
|
|
@@ -72,6 +73,7 @@ export class PluginSandbox {
|
|
|
72
73
|
this.restarts.push(now);
|
|
73
74
|
this.guest.dispose();
|
|
74
75
|
this.memories.clear();
|
|
76
|
+
this.sessionGames.clear();
|
|
75
77
|
this.guest = this.newGuest();
|
|
76
78
|
this.log(`[plugins] ${this.name}: restarted after breaking a sandbox limit`);
|
|
77
79
|
}
|
|
@@ -124,6 +126,7 @@ export class PluginSandbox {
|
|
|
124
126
|
this.restartIfSwitchedOff();
|
|
125
127
|
const handle = this.nextHandle++;
|
|
126
128
|
this.memories.set(handle, memory);
|
|
129
|
+
this.sessionGames.set(handle, { gameId, lastLog: null });
|
|
127
130
|
const info = {
|
|
128
131
|
buildId: memory.buildId,
|
|
129
132
|
commandLine: [...memory.commandLine],
|
|
@@ -138,6 +141,7 @@ export class PluginSandbox {
|
|
|
138
141
|
}
|
|
139
142
|
if (!started) {
|
|
140
143
|
this.memories.delete(handle);
|
|
144
|
+
this.sessionGames.delete(handle);
|
|
141
145
|
return null;
|
|
142
146
|
}
|
|
143
147
|
let lastProblem = null;
|
|
@@ -167,6 +171,7 @@ export class PluginSandbox {
|
|
|
167
171
|
}
|
|
168
172
|
finally {
|
|
169
173
|
this.memories.delete(handle);
|
|
174
|
+
this.sessionGames.delete(handle);
|
|
170
175
|
}
|
|
171
176
|
},
|
|
172
177
|
};
|
|
@@ -236,6 +241,20 @@ export class PluginSandbox {
|
|
|
236
241
|
const at = memory.scan(sig);
|
|
237
242
|
return at === null ? vm().null : vm().newString(at.toString());
|
|
238
243
|
},
|
|
244
|
+
log: (handle, message) => {
|
|
245
|
+
const meta = this.sessionGames.get(vm().getNumber(handle));
|
|
246
|
+
if (!meta)
|
|
247
|
+
return;
|
|
248
|
+
const clean = vm()
|
|
249
|
+
.getString(message)
|
|
250
|
+
.replace(/[\r\n]+/g, ' ')
|
|
251
|
+
.slice(0, 500);
|
|
252
|
+
if (!clean || clean === meta.lastLog)
|
|
253
|
+
return;
|
|
254
|
+
meta.lastLog = clean;
|
|
255
|
+
this.log(`[plugins] ${this.name}: ${meta.gameId}: ${clean}`);
|
|
256
|
+
this.memories.get(vm().getNumber(handle))?.log?.(clean);
|
|
257
|
+
},
|
|
239
258
|
};
|
|
240
259
|
}
|
|
241
260
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** RetroArch's default command port and player 1's network-pad port. */
|
|
2
|
+
export declare const RETROARCH_UDP_PORTS: readonly [55355, 55400];
|
|
3
|
+
/** The first of these UDP ports something else holds, or null when all are free. */
|
|
4
|
+
export declare function firstBusyUdpPort(ports: readonly number[]): Promise<number | null>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import dgram from 'node:dgram';
|
|
2
|
+
/*
|
|
3
|
+
* RetroArch's network commands (55355) and network pad (55400 + player) are UDP ports on
|
|
4
|
+
* localhost. A second RetroArch still holding them takes the route's presses and commands for
|
|
5
|
+
* itself, and the run fails for no visible reason (GoldenEye's route, 2026-12-01).
|
|
6
|
+
*/
|
|
7
|
+
/** RetroArch's default command port and player 1's network-pad port. */
|
|
8
|
+
export const RETROARCH_UDP_PORTS = [55355, 55400];
|
|
9
|
+
/* whether a UDP port on localhost can be bound now */
|
|
10
|
+
function udpPortFree(port) {
|
|
11
|
+
return new Promise(resolve => {
|
|
12
|
+
const socket = dgram.createSocket('udp4');
|
|
13
|
+
socket.once('error', () => {
|
|
14
|
+
socket.close();
|
|
15
|
+
resolve(false);
|
|
16
|
+
});
|
|
17
|
+
socket.bind(port, '127.0.0.1', () => socket.close(() => resolve(true)));
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/** The first of these UDP ports something else holds, or null when all are free. */
|
|
21
|
+
export async function firstBusyUdpPort(ports) {
|
|
22
|
+
for (const port of ports)
|
|
23
|
+
if (!(await udpPortFree(port)))
|
|
24
|
+
return port;
|
|
25
|
+
return null;
|
|
26
|
+
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/lib/pack.d.ts
CHANGED
|
@@ -704,6 +704,15 @@ export declare const PackDataSchema: z.ZodObject<{
|
|
|
704
704
|
unitsPerMeter: number;
|
|
705
705
|
northIsPositiveZ?: boolean | undefined;
|
|
706
706
|
}>;
|
|
707
|
+
/** Panels the game leaves out because they wouldn't help its player. */
|
|
708
|
+
panels: z.ZodOptional<z.ZodObject<{
|
|
709
|
+
/** false: play has no space to map (a single-screen puzzle); the map panel isn't offered */
|
|
710
|
+
map: z.ZodOptional<z.ZodBoolean>;
|
|
711
|
+
}, "strip", z.ZodTypeAny, {
|
|
712
|
+
map?: boolean | undefined;
|
|
713
|
+
}, {
|
|
714
|
+
map?: boolean | undefined;
|
|
715
|
+
}>>;
|
|
707
716
|
}, "strip", z.ZodTypeAny, {
|
|
708
717
|
id: string;
|
|
709
718
|
title: string;
|
|
@@ -831,6 +840,9 @@ export declare const PackDataSchema: z.ZodObject<{
|
|
|
831
840
|
shuffled?: boolean | undefined;
|
|
832
841
|
}[] | undefined;
|
|
833
842
|
};
|
|
843
|
+
panels?: {
|
|
844
|
+
map?: boolean | undefined;
|
|
845
|
+
} | undefined;
|
|
834
846
|
}, {
|
|
835
847
|
id: string;
|
|
836
848
|
title: string;
|
|
@@ -958,6 +970,9 @@ export declare const PackDataSchema: z.ZodObject<{
|
|
|
958
970
|
shuffled?: boolean | undefined;
|
|
959
971
|
}[] | undefined;
|
|
960
972
|
};
|
|
973
|
+
panels?: {
|
|
974
|
+
map?: boolean | undefined;
|
|
975
|
+
} | undefined;
|
|
961
976
|
}>;
|
|
962
977
|
export type PackData = z.infer<typeof PackDataSchema>;
|
|
963
978
|
/**
|
package/lib/pack.js
CHANGED
|
@@ -14,10 +14,23 @@ export const PackDataSchema = z.object({
|
|
|
14
14
|
/** true when +Z points north (Doom); otherwise +Z points south (the Zelda ports). */
|
|
15
15
|
northIsPositiveZ: z.boolean().optional(),
|
|
16
16
|
}),
|
|
17
|
+
/** Panels the game leaves out because they wouldn't help its player. */
|
|
18
|
+
panels: z
|
|
19
|
+
.object({
|
|
20
|
+
/** false: play has no space to map (a single-screen puzzle); the map panel isn't offered */
|
|
21
|
+
map: z.boolean().optional(),
|
|
22
|
+
})
|
|
23
|
+
.optional(),
|
|
17
24
|
});
|
|
18
25
|
/** The data part of a pack, without its code. */
|
|
19
26
|
export function packToData(pack) {
|
|
20
|
-
return {
|
|
27
|
+
return {
|
|
28
|
+
id: pack.id,
|
|
29
|
+
title: pack.title,
|
|
30
|
+
catalogue: pack.catalogue,
|
|
31
|
+
world: pack.world,
|
|
32
|
+
...(pack.panels ? { panels: pack.panels } : {}),
|
|
33
|
+
};
|
|
21
34
|
}
|
|
22
35
|
/** Runs a pack's code over the live state. */
|
|
23
36
|
export function packViewsFor(pack, state) {
|
package/lib/plugin/contract.d.ts
CHANGED
|
@@ -21,6 +21,11 @@ export interface GameMemory {
|
|
|
21
21
|
* Absent on cores before sdk 0.3.6 and for memory without an executable image (emulators).
|
|
22
22
|
*/
|
|
23
23
|
scan?(signature: Signature): bigint | null;
|
|
24
|
+
/**
|
|
25
|
+
* Emits a diagnostic line to the core's plugin debug log (deduplicated per session and
|
|
26
|
+
* clamped to 500 characters; no-op on older cores).
|
|
27
|
+
*/
|
|
28
|
+
log?(message: string): void;
|
|
24
29
|
}
|
|
25
30
|
/** A memory-read state source for one game. Packs export theirs from games/<id>/source.ts. */
|
|
26
31
|
export interface GamePlugin {
|
|
@@ -750,6 +750,13 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
750
750
|
unitsPerMeter: number;
|
|
751
751
|
northIsPositiveZ?: boolean | undefined;
|
|
752
752
|
}>;
|
|
753
|
+
panels: z.ZodOptional<z.ZodObject<{
|
|
754
|
+
map: z.ZodOptional<z.ZodBoolean>;
|
|
755
|
+
}, "strip", z.ZodTypeAny, {
|
|
756
|
+
map?: boolean | undefined;
|
|
757
|
+
}, {
|
|
758
|
+
map?: boolean | undefined;
|
|
759
|
+
}>>;
|
|
753
760
|
}, "strip", z.ZodTypeAny, {
|
|
754
761
|
id: string;
|
|
755
762
|
title: string;
|
|
@@ -877,6 +884,9 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
877
884
|
shuffled?: boolean | undefined;
|
|
878
885
|
}[] | undefined;
|
|
879
886
|
};
|
|
887
|
+
panels?: {
|
|
888
|
+
map?: boolean | undefined;
|
|
889
|
+
} | undefined;
|
|
880
890
|
}, {
|
|
881
891
|
id: string;
|
|
882
892
|
title: string;
|
|
@@ -1004,6 +1014,9 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
1004
1014
|
shuffled?: boolean | undefined;
|
|
1005
1015
|
}[] | undefined;
|
|
1006
1016
|
};
|
|
1017
|
+
panels?: {
|
|
1018
|
+
map?: boolean | undefined;
|
|
1019
|
+
} | undefined;
|
|
1007
1020
|
}>, "many">;
|
|
1008
1021
|
sources: z.ZodArray<z.ZodObject<{
|
|
1009
1022
|
gameId: z.ZodString;
|
|
@@ -1184,6 +1197,9 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
1184
1197
|
shuffled?: boolean | undefined;
|
|
1185
1198
|
}[] | undefined;
|
|
1186
1199
|
};
|
|
1200
|
+
panels?: {
|
|
1201
|
+
map?: boolean | undefined;
|
|
1202
|
+
} | undefined;
|
|
1187
1203
|
}[];
|
|
1188
1204
|
sources: {
|
|
1189
1205
|
gameId: string;
|
|
@@ -1328,6 +1344,9 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
|
|
|
1328
1344
|
shuffled?: boolean | undefined;
|
|
1329
1345
|
}[] | undefined;
|
|
1330
1346
|
};
|
|
1347
|
+
panels?: {
|
|
1348
|
+
map?: boolean | undefined;
|
|
1349
|
+
} | undefined;
|
|
1331
1350
|
}[];
|
|
1332
1351
|
sources: {
|
|
1333
1352
|
gameId: string;
|
|
@@ -1380,6 +1399,8 @@ export interface SandboxHostApi {
|
|
|
1380
1399
|
refreshMappings(handle: number): void;
|
|
1381
1400
|
/** a signature scan (JSON of a Signature); the address as a decimal string, or null */
|
|
1382
1401
|
scan(handle: number, signature: string): string | null;
|
|
1402
|
+
/** a diagnostic line from the guest; consecutive duplicates per session are suppressed */
|
|
1403
|
+
log?(handle: number, message: string): void;
|
|
1383
1404
|
}
|
|
1384
1405
|
/** A player's file as the asset guest sees it: a handle for `inputRead`, its name and size. */
|
|
1385
1406
|
export declare const SandboxInputFileSchema: z.ZodObject<{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gameslate/sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.12",
|
|
4
4
|
"description": "Build plugins for GameSlate, the second-screen companion for PC games: the plugin contract, game-state and catalogue schemas, and the plugin builder.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|