@gameslate/sdk 0.3.27 → 0.3.28

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.
@@ -13,7 +13,9 @@ import { initPlugin } from '../build/init-plugin.mjs';
13
13
  * Scaffolds a new plugin repository: an example plugin, a sandbox test, CI.
14
14
  * gameslate-plugin validate <builtDir> [--core-version <version>]
15
15
  * Checks a built plugin exactly as the core does before running it: manifest, contract,
16
- * hashes, then its live and asset code loaded in the core's own sandbox.
16
+ * hashes, then its live and asset code loaded in the core's own sandbox. Then the author's
17
+ * own checks, which the core doesn't refuse a plugin over: registry pins in a category their
18
+ * pack doesn't declare (src/host/validate.ts).
17
19
  * gameslate-plugin verify <verify.json>
18
20
  * Runs the game to a known moment (RetroArch on a save state) and checks what a local
19
21
  * GameSlate daemon reports, and the emulator's own memory reads, against the file.
@@ -48,29 +50,6 @@ const USAGE = [
48
50
  ' gameslate-plugin names <map or symbol file> … does the decomp name the game? (triage)',
49
51
  ].join('\n');
50
52
 
51
- async function validate(builtDir) {
52
- const { inspectPlugin, loadQuickJs, readPluginManifest } = await import('../lib/host/index.js');
53
- const read = readPluginManifest(builtDir);
54
- if ('problem' in read) return [read.problem];
55
- const { manifest } = read;
56
- const coreVersion = values['core-version'] ?? manifest.testedWith[0] ?? '0.0.0';
57
- const result = inspectPlugin(await loadQuickJs(), builtDir, manifest, {
58
- coreVersion,
59
- log: line => console.error(line),
60
- });
61
- if (typeof result === 'string') return [result];
62
- const { live, assets, registryGames, warnings } = result;
63
- console.log(`${manifest.id} ${manifest.version} (contract ${manifest.sdkApi}): OK`);
64
- console.log(` packs: ${live.packs.map(p => p.id).join(', ') || 'none'}`);
65
- console.log(
66
- ` sources: ${live.sources.map(s => `${s.gameId} (${s.supportedBuildIds.size} builds)`).join(', ') || 'none'}`,
67
- );
68
- console.log(` assets: ${assets?.games.join(', ') || 'none'}`);
69
- console.log(` registry: ${registryGames.join(', ') || 'none'}`);
70
- for (const w of warnings) console.log(` warning: ${w}`);
71
- return [];
72
- }
73
-
74
53
  if (command === 'build' && dir && values.out) {
75
54
  const built = await buildPlugin({
76
55
  srcDir: path.resolve(dir),
@@ -93,8 +72,13 @@ if (command === 'build' && dir && values.out) {
93
72
  });
94
73
  console.log(`created ${dir}: yarn install && yarn check`);
95
74
  } else if (command === 'validate' && dir) {
96
- const problems = await validate(path.resolve(dir));
97
- for (const p of problems) console.error(`refused: ${p}`);
75
+ const { validatePlugin } = await import('../lib/host/index.js');
76
+ const { report, problems } = await validatePlugin(path.resolve(dir), {
77
+ coreVersion: values['core-version'],
78
+ log: line => console.error(line),
79
+ });
80
+ for (const line of report) console.log(line);
81
+ for (const p of problems) console.error(p);
98
82
  process.exit(problems.length ? 1 : 0);
99
83
  } else if (command === 'verify' && dir) {
100
84
  const { expandEnv, runVerify, VerifySpecSchema } = await import('../lib/host/index.js');
@@ -571,16 +571,24 @@ export declare const PinCategorySchema: z.ZodObject<{
571
571
  shownByDefault: z.ZodBoolean;
572
572
  /** the map glyph for its pins: key, weapon, health, armor, ammo, powerup, bonus, secret, door, switch, item */
573
573
  icon: z.ZodOptional<z.ZodString>;
574
+ /**
575
+ * How many leading sentences of a pin's `context` its spot card shows, so a spoiler (how a
576
+ * secret opens) waits until the player asks the AI, which gets all of it. Absent: the whole
577
+ * context.
578
+ */
579
+ cardSentences: z.ZodOptional<z.ZodNumber>;
574
580
  }, "strip", z.ZodTypeAny, {
575
581
  label: string;
576
582
  id: string;
577
583
  shownByDefault: boolean;
578
584
  icon?: string | undefined;
585
+ cardSentences?: number | undefined;
579
586
  }, {
580
587
  label: string;
581
588
  id: string;
582
589
  shownByDefault: boolean;
583
590
  icon?: string | undefined;
591
+ cardSentences?: number | undefined;
584
592
  }>;
585
593
  export type PinCategory = z.infer<typeof PinCategorySchema>;
586
594
  export declare const CatalogueSchema: z.ZodObject<{
@@ -1042,16 +1050,24 @@ export declare const CatalogueSchema: z.ZodObject<{
1042
1050
  shownByDefault: z.ZodBoolean;
1043
1051
  /** the map glyph for its pins: key, weapon, health, armor, ammo, powerup, bonus, secret, door, switch, item */
1044
1052
  icon: z.ZodOptional<z.ZodString>;
1053
+ /**
1054
+ * How many leading sentences of a pin's `context` its spot card shows, so a spoiler (how a
1055
+ * secret opens) waits until the player asks the AI, which gets all of it. Absent: the whole
1056
+ * context.
1057
+ */
1058
+ cardSentences: z.ZodOptional<z.ZodNumber>;
1045
1059
  }, "strip", z.ZodTypeAny, {
1046
1060
  label: string;
1047
1061
  id: string;
1048
1062
  shownByDefault: boolean;
1049
1063
  icon?: string | undefined;
1064
+ cardSentences?: number | undefined;
1050
1065
  }, {
1051
1066
  label: string;
1052
1067
  id: string;
1053
1068
  shownByDefault: boolean;
1054
1069
  icon?: string | undefined;
1070
+ cardSentences?: number | undefined;
1055
1071
  }>, "many">>;
1056
1072
  /** the variants `state.variant` may name (vanilla, master quest, randomizer, …) */
1057
1073
  variants: z.ZodOptional<z.ZodArray<z.ZodObject<{
@@ -1183,6 +1199,7 @@ export declare const CatalogueSchema: z.ZodObject<{
1183
1199
  id: string;
1184
1200
  shownByDefault: boolean;
1185
1201
  icon?: string | undefined;
1202
+ cardSentences?: number | undefined;
1186
1203
  }[] | undefined;
1187
1204
  variants?: {
1188
1205
  label: string;
@@ -1304,6 +1321,7 @@ export declare const CatalogueSchema: z.ZodObject<{
1304
1321
  id: string;
1305
1322
  shownByDefault: boolean;
1306
1323
  icon?: string | undefined;
1324
+ cardSentences?: number | undefined;
1307
1325
  }[] | undefined;
1308
1326
  variants?: {
1309
1327
  label: string;
package/lib/catalogue.js CHANGED
@@ -191,6 +191,12 @@ export const PinCategorySchema = z.object({
191
191
  shownByDefault: z.boolean(),
192
192
  /** the map glyph for its pins: key, weapon, health, armor, ammo, powerup, bonus, secret, door, switch, item */
193
193
  icon: z.string().optional(),
194
+ /**
195
+ * How many leading sentences of a pin's `context` its spot card shows, so a spoiler (how a
196
+ * secret opens) waits until the player asks the AI, which gets all of it. Absent: the whole
197
+ * context.
198
+ */
199
+ cardSentences: z.number().int().positive().optional(),
194
200
  });
195
201
  export const CatalogueSchema = z
196
202
  .object({
@@ -8,3 +8,4 @@ export * from './addresses.js';
8
8
  export * from './udp-ports.js';
9
9
  export * from './game-support.js';
10
10
  export * from './wasm-host.js';
11
+ export * from './validate.js';
package/lib/host/index.js CHANGED
@@ -12,3 +12,4 @@ export * from './addresses.js';
12
12
  export * from './udp-ports.js';
13
13
  export * from './game-support.js';
14
14
  export * from './wasm-host.js';
15
+ export * from './validate.js';
@@ -1,3 +1,4 @@
1
+ import type { GamePack } from '../pack.js';
1
2
  import type { PluginManifest } from '../plugin-manifest.js';
2
3
  export declare const REGISTRY_DIR = "registry";
3
4
  /** Why an SVG can't be served (a tag outside the set, a script hook, a bare `&`), or null. */
@@ -9,3 +10,10 @@ export declare function svgProblem(text: string): string | null;
9
10
  export declare function inspectPluginRegistry(dir: string, manifest: PluginManifest): {
10
11
  games: string[];
11
12
  } | string;
13
+ /**
14
+ * Registry pins in a category their game's pack doesn't declare, one line per category
15
+ * (`undeclaredPinCategories`), for `gameslate-plugin validate`. `games` are the ones
16
+ * `inspectPluginRegistry` passed. The core's loader doesn't refuse these (the pins still draw,
17
+ * and a whole plugin shouldn't fail to load over a toggle), so the author hears it here.
18
+ */
19
+ export declare function registryPinCategoryProblems(dir: string, games: readonly string[], packs: readonly Pick<GamePack, 'id' | 'catalogue'>[]): string[];
@@ -1,5 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
+ import { declaredPinCategories, undeclaredPinCategories } from '../pin-categories.js';
3
4
  import { GameManifestSchema, HintGraphSchema } from '../registry.js';
4
5
  /*
5
6
  * A plugin's registry data: the committed, simplified map data for its games, served by the core
@@ -128,3 +129,19 @@ export function inspectPluginRegistry(dir, manifest) {
128
129
  }
129
130
  return { games: games.sort() };
130
131
  }
132
+ /**
133
+ * Registry pins in a category their game's pack doesn't declare, one line per category
134
+ * (`undeclaredPinCategories`), for `gameslate-plugin validate`. `games` are the ones
135
+ * `inspectPluginRegistry` passed. The core's loader doesn't refuse these (the pins still draw,
136
+ * and a whole plugin shouldn't fail to load over a toggle), so the author hears it here.
137
+ */
138
+ export function registryPinCategoryProblems(dir, games, packs) {
139
+ return games.flatMap(gameId => {
140
+ const file = path.join(dir, REGISTRY_DIR, 'games', gameId, 'manifest.json');
141
+ const manifest = readJson(file, GameManifestSchema);
142
+ if (typeof manifest === 'string')
143
+ throw new Error(`${file}: ${manifest}`);
144
+ const declared = declaredPinCategories(packs, gameId);
145
+ return undeclaredPinCategories(gameId, manifest.locations, declared);
146
+ });
147
+ }
@@ -0,0 +1,10 @@
1
+ export interface Validation {
2
+ /** what the core makes of the plugin, and its warnings (empty when the core refuses it) */
3
+ report: string[];
4
+ /** each labelled: `refused: …` (the core won't load it), `pin category: …` */
5
+ problems: string[];
6
+ }
7
+ export declare function validatePlugin(builtDir: string, opts: {
8
+ coreVersion?: string;
9
+ log: (line: string) => void;
10
+ }): Promise<Validation>;
@@ -0,0 +1,36 @@
1
+ import { inspectPlugin, readPluginManifest } from './inspect.js';
2
+ import { loadQuickJs } from './quickjs-guest.js';
3
+ import { registryPinCategoryProblems } from './plugin-registry.js';
4
+ export async function validatePlugin(builtDir, opts) {
5
+ const read = readPluginManifest(builtDir);
6
+ if ('problem' in read)
7
+ return { report: [], problems: [`refused: ${read.problem}`] };
8
+ const { manifest } = read;
9
+ const coreVersion = opts.coreVersion ?? manifest.testedWith[0] ?? '0.0.0';
10
+ const result = inspectPlugin(await loadQuickJs(), builtDir, manifest, {
11
+ coreVersion,
12
+ log: opts.log,
13
+ });
14
+ if (typeof result === 'string')
15
+ return { report: [], problems: [`refused: ${result}`] };
16
+ try {
17
+ const { live, assets, registryGames, warnings } = result;
18
+ const problems = registryPinCategoryProblems(builtDir, registryGames, live.packs).map(p => `pin category: ${p}`);
19
+ const sources = live.sources.map(s => `${s.gameId} (${s.supportedBuildIds.size} builds)`);
20
+ const verdict = problems.length ? 'loads, with the problems below' : 'OK';
21
+ return {
22
+ report: [
23
+ `${manifest.id} ${manifest.version} (contract ${manifest.sdkApi}): ${verdict}`,
24
+ ` packs: ${live.packs.map(p => p.id).join(', ') || 'none'}`,
25
+ ` sources: ${sources.join(', ') || 'none'}`,
26
+ ` assets: ${assets?.games.join(', ') || 'none'}`,
27
+ ` registry: ${registryGames.join(', ') || 'none'}`,
28
+ ...warnings.map(w => ` warning: ${w}`),
29
+ ],
30
+ problems,
31
+ };
32
+ }
33
+ finally {
34
+ result.dispose();
35
+ }
36
+ }
@@ -1045,6 +1045,13 @@ export declare const VerifySpecSchema: z.ZodObject<{
1045
1045
  variant?: string | undefined;
1046
1046
  equipped?: string | null | undefined;
1047
1047
  };
1048
+ ui?: {
1049
+ url: string;
1050
+ tabs: ("Map" | "Inventory" | "Missions" | "Ref")[];
1051
+ } | {
1052
+ url: string;
1053
+ tabs: string[];
1054
+ } | undefined;
1048
1055
  gameslate?: string | undefined;
1049
1056
  retroarch?: {
1050
1057
  binary: string;
@@ -1059,13 +1066,6 @@ export declare const VerifySpecSchema: z.ZodObject<{
1059
1066
  launchPrefix: string[];
1060
1067
  command: string[];
1061
1068
  } | undefined;
1062
- ui?: {
1063
- url: string;
1064
- tabs: ("Map" | "Inventory" | "Missions" | "Ref")[];
1065
- } | {
1066
- url: string;
1067
- tabs: string[];
1068
- } | undefined;
1069
1069
  }, {
1070
1070
  game: string;
1071
1071
  expect: {
@@ -1149,6 +1149,10 @@ export declare const VerifySpecSchema: z.ZodObject<{
1149
1149
  } | {
1150
1150
  waitMs: number;
1151
1151
  })[] | undefined;
1152
+ ui?: string | {
1153
+ url: string;
1154
+ tabs?: string[] | undefined;
1155
+ } | undefined;
1152
1156
  memory?: {
1153
1157
  counter: string;
1154
1158
  size: 2 | 1 | 4;
@@ -1173,10 +1177,6 @@ export declare const VerifySpecSchema: z.ZodObject<{
1173
1177
  daemon?: {
1174
1178
  url?: string | undefined;
1175
1179
  } | undefined;
1176
- ui?: string | {
1177
- url: string;
1178
- tabs?: string[] | undefined;
1179
- } | undefined;
1180
1180
  settleMs?: number | undefined;
1181
1181
  }>;
1182
1182
  export type VerifySpec = z.infer<typeof VerifySpecSchema>;
package/lib/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from './condition.js';
5
5
  export * from './catalogue.js';
6
6
  export * from './status.js';
7
7
  export * from './pins.js';
8
+ export * from './pin-categories.js';
8
9
  export * from './chips.js';
9
10
  export * from './pack.js';
10
11
  export * from './views.js';
package/lib/index.js CHANGED
@@ -5,6 +5,7 @@ export * from './condition.js';
5
5
  export * from './catalogue.js';
6
6
  export * from './status.js';
7
7
  export * from './pins.js';
8
+ export * from './pin-categories.js';
8
9
  export * from './chips.js';
9
10
  export * from './pack.js';
10
11
  export * from './views.js';
package/lib/pack.d.ts CHANGED
@@ -435,16 +435,19 @@ export declare const PackDataSchema: z.ZodObject<{
435
435
  label: z.ZodString;
436
436
  shownByDefault: z.ZodBoolean;
437
437
  icon: z.ZodOptional<z.ZodString>;
438
+ cardSentences: z.ZodOptional<z.ZodNumber>;
438
439
  }, "strip", z.ZodTypeAny, {
439
440
  label: string;
440
441
  id: string;
441
442
  shownByDefault: boolean;
442
443
  icon?: string | undefined;
444
+ cardSentences?: number | undefined;
443
445
  }, {
444
446
  label: string;
445
447
  id: string;
446
448
  shownByDefault: boolean;
447
449
  icon?: string | undefined;
450
+ cardSentences?: number | undefined;
448
451
  }>, "many">>;
449
452
  variants: z.ZodOptional<z.ZodArray<z.ZodObject<{
450
453
  id: z.ZodString;
@@ -574,6 +577,7 @@ export declare const PackDataSchema: z.ZodObject<{
574
577
  id: string;
575
578
  shownByDefault: boolean;
576
579
  icon?: string | undefined;
580
+ cardSentences?: number | undefined;
577
581
  }[] | undefined;
578
582
  variants?: {
579
583
  label: string;
@@ -695,6 +699,7 @@ export declare const PackDataSchema: z.ZodObject<{
695
699
  id: string;
696
700
  shownByDefault: boolean;
697
701
  icon?: string | undefined;
702
+ cardSentences?: number | undefined;
698
703
  }[] | undefined;
699
704
  variants?: {
700
705
  label: string;
@@ -845,6 +850,7 @@ export declare const PackDataSchema: z.ZodObject<{
845
850
  id: string;
846
851
  shownByDefault: boolean;
847
852
  icon?: string | undefined;
853
+ cardSentences?: number | undefined;
848
854
  }[] | undefined;
849
855
  variants?: {
850
856
  label: string;
@@ -977,6 +983,7 @@ export declare const PackDataSchema: z.ZodObject<{
977
983
  id: string;
978
984
  shownByDefault: boolean;
979
985
  icon?: string | undefined;
986
+ cardSentences?: number | undefined;
980
987
  }[] | undefined;
981
988
  variants?: {
982
989
  label: string;
@@ -1420,16 +1427,19 @@ export declare const ServedPackDataSchema: z.ZodObject<{
1420
1427
  label: z.ZodString;
1421
1428
  shownByDefault: z.ZodBoolean;
1422
1429
  icon: z.ZodOptional<z.ZodString>;
1430
+ cardSentences: z.ZodOptional<z.ZodNumber>;
1423
1431
  }, "strip", z.ZodTypeAny, {
1424
1432
  label: string;
1425
1433
  id: string;
1426
1434
  shownByDefault: boolean;
1427
1435
  icon?: string | undefined;
1436
+ cardSentences?: number | undefined;
1428
1437
  }, {
1429
1438
  label: string;
1430
1439
  id: string;
1431
1440
  shownByDefault: boolean;
1432
1441
  icon?: string | undefined;
1442
+ cardSentences?: number | undefined;
1433
1443
  }>, "many">>;
1434
1444
  variants: z.ZodOptional<z.ZodArray<z.ZodObject<{
1435
1445
  id: z.ZodString;
@@ -1559,6 +1569,7 @@ export declare const ServedPackDataSchema: z.ZodObject<{
1559
1569
  id: string;
1560
1570
  shownByDefault: boolean;
1561
1571
  icon?: string | undefined;
1572
+ cardSentences?: number | undefined;
1562
1573
  }[] | undefined;
1563
1574
  variants?: {
1564
1575
  label: string;
@@ -1680,6 +1691,7 @@ export declare const ServedPackDataSchema: z.ZodObject<{
1680
1691
  id: string;
1681
1692
  shownByDefault: boolean;
1682
1693
  icon?: string | undefined;
1694
+ cardSentences?: number | undefined;
1683
1695
  }[] | undefined;
1684
1696
  variants?: {
1685
1697
  label: string;
@@ -1834,6 +1846,7 @@ export declare const ServedPackDataSchema: z.ZodObject<{
1834
1846
  id: string;
1835
1847
  shownByDefault: boolean;
1836
1848
  icon?: string | undefined;
1849
+ cardSentences?: number | undefined;
1837
1850
  }[] | undefined;
1838
1851
  variants?: {
1839
1852
  label: string;
@@ -1967,6 +1980,7 @@ export declare const ServedPackDataSchema: z.ZodObject<{
1967
1980
  id: string;
1968
1981
  shownByDefault: boolean;
1969
1982
  icon?: string | undefined;
1983
+ cardSentences?: number | undefined;
1970
1984
  }[] | undefined;
1971
1985
  variants?: {
1972
1986
  label: string;
@@ -0,0 +1,12 @@
1
+ import type { PinCategory } from './catalogue.js';
2
+ import type { GamePack } from './pack.js';
3
+ import type { GameManifest } from './registry.js';
4
+ /** The pin categories a game declares: its pack's (a pack without `pinCategories` declares
5
+ * none), or 'no pack' when no loaded pack is for the game. */
6
+ export type DeclaredPinCategories = readonly PinCategory[] | 'no pack';
7
+ export declare function declaredPinCategories(packs: readonly Pick<GamePack, 'id' | 'catalogue'>[], gameId: string): DeclaredPinCategories;
8
+ /**
9
+ * One line per category that `locations`' pins name and the game doesn't declare, naming the
10
+ * game, how many pins and the first.
11
+ */
12
+ export declare function undeclaredPinCategories(gameId: string, locations: GameManifest['locations'], declared: DeclaredPinCategories): string[];
@@ -0,0 +1,32 @@
1
+ export function declaredPinCategories(packs, gameId) {
2
+ const pack = packs.find(p => p.id === gameId);
3
+ return pack ? (pack.catalogue.pinCategories ?? []) : 'no pack';
4
+ }
5
+ /**
6
+ * One line per category that `locations`' pins name and the game doesn't declare, naming the
7
+ * game, how many pins and the first.
8
+ */
9
+ export function undeclaredPinCategories(gameId, locations, declared) {
10
+ const known = new Set(declared === 'no pack' ? [] : declared.map(c => c.id));
11
+ const found = new Map();
12
+ for (const [locationId, location] of Object.entries(locations)) {
13
+ for (const layer of location.map?.layers ?? []) {
14
+ for (const pin of layer.landmarks) {
15
+ if (pin.category === undefined || known.has(pin.category))
16
+ continue;
17
+ const seen = found.get(pin.category);
18
+ if (seen)
19
+ seen.count++;
20
+ else
21
+ found.set(pin.category, {
22
+ count: 1,
23
+ first: `"${pin.label}" (${pin.id}) in ${locationId}/${layer.id}`,
24
+ });
25
+ }
26
+ }
27
+ }
28
+ const why = declared === 'no pack'
29
+ ? 'but no loaded pack is for this game to declare it'
30
+ : "which the pack's catalogue.pinCategories doesn't declare";
31
+ return [...found].map(([category, { count, first }]) => `${gameId}: ${count} pin${count === 1 ? '' : 's'} in category "${category}", ${why}, so the player can't hide them (first: ${first})`);
32
+ }
@@ -509,16 +509,19 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
509
509
  label: z.ZodString;
510
510
  shownByDefault: z.ZodBoolean;
511
511
  icon: z.ZodOptional<z.ZodString>;
512
+ cardSentences: z.ZodOptional<z.ZodNumber>;
512
513
  }, "strip", z.ZodTypeAny, {
513
514
  label: string;
514
515
  id: string;
515
516
  shownByDefault: boolean;
516
517
  icon?: string | undefined;
518
+ cardSentences?: number | undefined;
517
519
  }, {
518
520
  label: string;
519
521
  id: string;
520
522
  shownByDefault: boolean;
521
523
  icon?: string | undefined;
524
+ cardSentences?: number | undefined;
522
525
  }>, "many">>;
523
526
  variants: z.ZodOptional<z.ZodArray<z.ZodObject<{
524
527
  id: z.ZodString;
@@ -648,6 +651,7 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
648
651
  id: string;
649
652
  shownByDefault: boolean;
650
653
  icon?: string | undefined;
654
+ cardSentences?: number | undefined;
651
655
  }[] | undefined;
652
656
  variants?: {
653
657
  label: string;
@@ -769,6 +773,7 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
769
773
  id: string;
770
774
  shownByDefault: boolean;
771
775
  icon?: string | undefined;
776
+ cardSentences?: number | undefined;
772
777
  }[] | undefined;
773
778
  variants?: {
774
779
  label: string;
@@ -915,6 +920,7 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
915
920
  id: string;
916
921
  shownByDefault: boolean;
917
922
  icon?: string | undefined;
923
+ cardSentences?: number | undefined;
918
924
  }[] | undefined;
919
925
  variants?: {
920
926
  label: string;
@@ -1047,6 +1053,7 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
1047
1053
  id: string;
1048
1054
  shownByDefault: boolean;
1049
1055
  icon?: string | undefined;
1056
+ cardSentences?: number | undefined;
1050
1057
  }[] | undefined;
1051
1058
  variants?: {
1052
1059
  label: string;
@@ -1258,6 +1265,7 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
1258
1265
  id: string;
1259
1266
  shownByDefault: boolean;
1260
1267
  icon?: string | undefined;
1268
+ cardSentences?: number | undefined;
1261
1269
  }[] | undefined;
1262
1270
  variants?: {
1263
1271
  label: string;
@@ -1411,6 +1419,7 @@ export declare const SandboxDescriptionSchema: z.ZodObject<{
1411
1419
  id: string;
1412
1420
  shownByDefault: boolean;
1413
1421
  icon?: string | undefined;
1422
+ cardSentences?: number | undefined;
1414
1423
  }[] | undefined;
1415
1424
  variants?: {
1416
1425
  label: string;
package/lib/types.d.ts CHANGED
@@ -304,6 +304,8 @@ export declare const GameStateSchema: z.ZodObject<{
304
304
  }> | undefined;
305
305
  }>;
306
306
  export type GameState = z.infer<typeof GameStateSchema>;
307
+ export declare const OptionalStateFieldSchema: z.ZodEnum<["difficulty", "variant", "enemies", "npcs", "stats", "counters", "flagSets", "equipped", "objectiveProgress"]>;
308
+ export type OptionalStateField = z.infer<typeof OptionalStateFieldSchema>;
307
309
  export declare const SessionEventSchema: z.ZodObject<{
308
310
  id: z.ZodString;
309
311
  timestamp: z.ZodNumber;
@@ -2285,6 +2287,8 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
2285
2287
  }> | undefined;
2286
2288
  flags?: Record<string, boolean> | undefined;
2287
2289
  }>;
2290
+ /** fields the pack stopped reporting: the client deletes them (absent = none removed) */
2291
+ removed: z.ZodOptional<z.ZodArray<z.ZodEnum<["difficulty", "variant", "enemies", "npcs", "stats", "counters", "flagSets", "equipped", "objectiveProgress"]>, "many">>;
2288
2292
  }, "strip", z.ZodTypeAny, {
2289
2293
  type: "state:patch";
2290
2294
  timestamp: number;
@@ -2339,6 +2343,7 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
2339
2343
  }> | undefined;
2340
2344
  flags?: Record<string, boolean> | undefined;
2341
2345
  };
2346
+ removed?: ("stats" | "difficulty" | "variant" | "enemies" | "npcs" | "counters" | "flagSets" | "equipped" | "objectiveProgress")[] | undefined;
2342
2347
  }, {
2343
2348
  type: "state:patch";
2344
2349
  timestamp: number;
@@ -2393,6 +2398,7 @@ export declare const ServerWsMessageSchema: z.ZodDiscriminatedUnion<"type", [z.Z
2393
2398
  }> | undefined;
2394
2399
  flags?: Record<string, boolean> | undefined;
2395
2400
  };
2401
+ removed?: ("stats" | "difficulty" | "variant" | "enemies" | "npcs" | "counters" | "flagSets" | "equipped" | "objectiveProgress")[] | undefined;
2396
2402
  }>, z.ZodObject<{
2397
2403
  type: z.ZodLiteral<"event">;
2398
2404
  sessionId: z.ZodString;
package/lib/types.js CHANGED
@@ -65,6 +65,22 @@ export const GameStateSchema = z.object({
65
65
  objectiveProgress: z.record(z.string(), ObjectiveProgressSchema).optional(),
66
66
  flags: z.record(z.string(), z.boolean()),
67
67
  });
68
+ /*
69
+ * The GameState fields a pack may leave out ("not tracked / not streamed"). A state:patch names the
70
+ * ones that went from present to absent in `removed`, since JSON has no way to send `undefined`.
71
+ * Mirrors the schema's optional fields; types.test.ts fails when they drift.
72
+ */
73
+ export const OptionalStateFieldSchema = z.enum([
74
+ 'difficulty',
75
+ 'variant',
76
+ 'enemies',
77
+ 'npcs',
78
+ 'stats',
79
+ 'counters',
80
+ 'flagSets',
81
+ 'equipped',
82
+ 'objectiveProgress',
83
+ ]);
68
84
  export const SessionEventSchema = z.object({
69
85
  id: z.string(),
70
86
  timestamp: z.number(),
@@ -230,6 +246,8 @@ export const ServerWsMessageSchema = z.discriminatedUnion('type', [
230
246
  timestamp: z.number(),
231
247
  gameId: z.string(),
232
248
  patch: GameStateSchema.partial(),
249
+ /** fields the pack stopped reporting: the client deletes them (absent = none removed) */
250
+ removed: z.array(OptionalStateFieldSchema).optional(),
233
251
  }),
234
252
  z.object({
235
253
  type: z.literal('event'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gameslate/sdk",
3
- "version": "0.3.27",
3
+ "version": "0.3.28",
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",
@@ -353,7 +353,12 @@ Images have a `purpose` (`atlas`, `map`, `icon`, `actor`, which picks the folder
353
353
  - `{ format: 'webp', lossless: true }`;
354
354
  - `{ format: 'webp', quality: 88 }`.
355
355
 
356
- Every image of a game uses one format. In the sandbox:
356
+ Every image of a game uses one format. A mesh may link to an atlas another asset builds (one
357
+ atlas per campaign): the core writes the mesh once the atlas is written, whatever order the builder
358
+ threads finish in. Test a first build into an empty out-dir: `extract-assets` exits 1 if any asset
359
+ failed, so a race or a missing atlas can't pass as a partial success.
360
+
361
+ In the sandbox:
357
362
 
358
363
  - **No `TextDecoder`, `TextEncoder` or `Buffer`.** Decode Latin-1 and ASCII with `new
359
364
  Bytes(data).toString('latin1', start, end)` (sdk >= 0.3.26 is fast at any length), and UTF-8 by
@@ -849,6 +854,109 @@ the plugin repos) in the same change as the fix. The next game should not have t
849
854
  (`@gameslate/sdk/host`). After a change that grows the geometry, run `gameslate extract-assets
850
855
  <game> --input <rom> --out-dir <scratch>` (the core's `dist/gameslate.mjs` with
851
856
  `GAMESLATE_PLUGINS_DIR=<plugin>/dist`).
857
+ - **Reading a game's actor list.** A list that grows with `realloc` has no fixed size: cap the read
858
+ at a pool every entry must take from (Banjo-Kazooie's 0xE0-entry marker pool, one per actor) and
859
+ refuse a count above it. Read only the used slots, and test the size of every read by wrapping
860
+ `memory.read` (a mutation that read the whole capacity passed every result-based test; a guard
861
+ that only skips a big read outside play survives the same way). Check
862
+ an id → name table against the ROM's placements (count the setup files' props by id) to catch a
863
+ wrong id and find ids only code spawns. When the game removes an actor by moving its last one
864
+ into the freed slot, a slot index isn't a stable id: key on something that stays put (the
865
+ actor's pooled marker pointer). The pointer, header and slot reads aren't one instant: the game
866
+ bumps the count before it writes the new slot and can `realloc` the array between your reads.
867
+ Re-read the pointer and header after the slots and retry a few times; if it never settles, leave
868
+ `enemies`/`npcs` out for that tick (unknown, not none) rather than throw away the whole poll.
869
+ A header that matches before and after doesn't catch a slot the game hasn't written yet, so
870
+ retry on an impossible value too (a bad count, a NaN position, an id past the enum). Throw only
871
+ when it stays impossible across steady samples: that's not a tear. Read the game's remove
872
+ routine as well as its add: Banjo-Kazooie's `__actor_free` copies the last actor into the freed
873
+ slot before lowering the count and never clears the old one, so a just-counted slot can hold a
874
+ stale copy of a live actor under an unchanged header. Treat two used slots that share a unique
875
+ field (the marker pointer) as a torn sample. Log a give-up with `GameMemory.log`: plugin code
876
+ can't import `debug`. A fixed array with no count (Conker's `movement_obj[26]`) is one read of
877
+ its declared size: confirm the size from the linker (the next symbol's address), not from a
878
+ loop's literal. When the spawn code writes the model last and the clear starts at `type`, a torn
879
+ slot can't show a named actor in a stale place, so the name table is itself the guard. Throw
880
+ only after impossible samples on several polls in a row: an emulator paused mid-routine shows
881
+ the same half-written slot to every retry within one poll; a poll that skips the read (a menu)
882
+ ends the run. A used slot isn't a live character: read the kill, split and remove paths and
883
+ drop the dying states (Conker's `effect_killAndSplitActor` leaves a spinning-down victim plus
884
+ a copy, two dots for one kill), attached parts, and a mount while it's ridden. Check the loops'
885
+ bound against the array's size: Conker's last slot is an overflow scratch slot that never gets
886
+ cleared. The daemon holds a list that's
887
+ absent for a single poll, so a one-poll give-up doesn't blink the dots.
888
+ In play with nothing there, send empty lists: a missing list reads as "not tracked".
889
+ - **A decomp's enum can name the wrong actor.** DK64's `ACTOR_DOGADON` (294) is K. Rool's Tiny
890
+ round; Dogadon is 236, and its boss overlay names and boss model enums are shuffled too. Settle
891
+ each name by where the ROM's placements put it (a boss sits only on its own map), and check
892
+ every lead's names (ScriptHawk's too) the same way.
893
+ - **Two compressed members back to back.** DK64's global segment is code then data, packed one
894
+ after the other: inflate the whole ROM range and check the size equals VRAM to BSS start.
895
+ Inflating only the first member silently drops `.data`.
896
+ - **`at += readThatMovesAt()` loses the call's own advance:** JavaScript reads `at` before the
897
+ call runs. Assign the result first.
898
+ - **Collision that isn't a display list.** A game can collide with more than the level mesh: read
899
+ the function that builds its collision maps (Conker's `level_buildCollisionTris` builds map 2
900
+ from every placed object's model), not a "list N" label in notes. Port each filter it applies
901
+ (status bits, inactive flags), and take the placement matrix from the collision code even when
902
+ it's hand-written asm; it should multiply out to the render path's C matrix. When a placement
903
+ defers a field to a table in the game's data segment (Conker's `gGroupedObjectDefaults`),
904
+ unpack that segment from the player's ROM, check its size against the linker layout, confirm
905
+ every entry once in a scratch test against the decomp's table, and never commit it. Check the
906
+ new geometry by counting spawn points on a drawn floor with and without it: the count should
907
+ rise. Pin it exactly rather than asserting that a wrong rotation lowers it: in SM64 a negated
908
+ yaw *raised* it (points from other acts landed on the misturned object). That count can also
909
+ be blind to rotation: markers
910
+ often sit at a prop's centre, where turning it moves nothing (a flipped roll left Banjo-Kazooie's
911
+ count unchanged). Pin the rotation with unit rows computed from the game's own matrix steps, and
912
+ pin which maps gain floors, not only the total. Look for code that moves placed props after load
913
+ (BK's `func_803515EC`): those are drawn only where they start. An object's collision pose can
914
+ come from its behaviour as well as its placement: walk the script's data commands (scale,
915
+ position and angle writes, a `GOTO` into the middle of another script), read every native init
916
+ function a collision behaviour calls (match it by linker-map address), and refuse a pose write
917
+ you can't follow, but only for objects that have a model. Two unnamed static tables from one
918
+ `.c` file sit back to back in its `.data`: find the one with sentinels by shape, take the other
919
+ by offset, and confirm against the `.o`'s `.data` size. Read every object map the loader
920
+ spawns and every spawner: most of DKR's solid objects come from its second map
921
+ (`collectables`) or are spawned by animation nodes, which hand them their own position, turn
922
+ and size (take that transform from the spawner, `obj_init_animobject`, not the child's init).
923
+ Paired doors make a ROM check that sees rotation: closed halves must meet, and a flipped sign,
924
+ the wrong angle unit or the wrong size opens a gap (DKR, 2026-12-06).
925
+ - **Declare every pin `category` in the pack's `catalogue.pinCategories`.** An undeclared one still
926
+ draws and is still offered by chips, the nudge and the AI, but the player gets no toggle for it,
927
+ so a spoiler can't be hidden. Write it as `PIN_CATEGORIES.<key>` from the game's
928
+ `pin-categories.ts`, which the pack's declarations read too, never as an expression; shared
929
+ builders (`topdown.ts`) set none. `plugin/pin-categories.test.ts` refuses anything else, and a
930
+ map test checks the built pins' categories. The core checks too: `gameslate-plugin validate`
931
+ (sdk 0.3.28) fails on registry pins in an undeclared category, and `extract-assets` writes
932
+ extracted ones but prints each category and exits 1 for pins your current asset code built
933
+ (pins in maps an earlier release left are reported, and a rebuild replaces them), so run it
934
+ on a real build before a release. Mark spoilers
935
+ `shownByDefault: false`. Renaming an id leaves maps built by earlier releases on the old id
936
+ until the player rebuilds them (gameslate-n64, 2026-12-06). When a category's pin `context`
937
+ ends with the answer (how a secret opens), set its `cardSentences` (sdk 0.3.28) to the leading
938
+ sentences the spot card may show; the AI still gets all of it. The core keys on no category
939
+ id (Doom's `secrets`, 2026-12-06). Emit those leading sentences for every pin, even when the
940
+ fact behind one is missing: a Doom secret with no pin to place it by dropped its "where"
941
+ sentence, so a two-sentence card showed how it opens. A sentence ends at `.`, `?` or `!`
942
+ before a space.
943
+ - **Tables loaded back to back: walk them exactly as the loader does.** Body Harvest's
944
+ `loadLevelData` skips 4 bytes after one table and aligns to 16 before the packed blocks; apply
945
+ the loader's own sanity checks (a first byte, a magic word) at each step, and confirm the walk
946
+ against the decomp's published counts. A token-stream parser ends where the game's does:
947
+ Body Harvest's condition reader stops only at a command-list marker, so a fixture without one
948
+ hangs, while the real data always has one (2026-12-06).
949
+ - **Pointers into a segment loaded at run time** (SM64's behaviour scripts in segment 0x13): read
950
+ where the game's segment table says the segment was loaded and match offsets within it against
951
+ the map's segmented symbols, never fixed virtual addresses. When variants share one script
952
+ (Koopa and Koopa the Quick), read the init branch and test the parameter exactly: the tiny
953
+ Koopa's value is also above the race base.
954
+ - **Take a field's order from the code that uses the data**, not from the loader's names: SM64's
955
+ `load_environmental_regions` names unused fields loX, hiX, loZ, hiZ, but `find_water_level`
956
+ reads loX, loZ, hiX, hiZ.
957
+ - **A static table no symbol names** can be found in the player's ROM by its shape and sentinels
958
+ (null first and last entries): require exactly one match, keep the sentinels, and keep the first
959
+ entry for an id, as the game's own search does. Nothing from it is committed.
852
960
  - **Never build a long string with `+=` a piece at a time.** QuickJS copies the whole string on
853
961
  every `+=`, so it is quadratic where Node is linear: a 1 MB string a byte at a time took 147 s
854
962
  in the sandbox (the sdk's own `Bytes#toString` did this until 0.3.26). Push the pieces into an
@@ -927,7 +1035,12 @@ the plugin repos) in the same change as the fix. The next game should not have t
927
1035
  decomp's routine as a black-box test binary on the dev machine. A second agent, which never
928
1036
  opens the source, implements from the spec and must match the binary's output on every real
929
1037
  input. Why: on 2026-12-05 the Doom 64 decompressor was ported step by step from DOOM64-RE, and
930
- had to be rewritten clean before the repo could be published.
1038
+ had to be rewritten clean before the repo could be published. A parser for a data format counts
1039
+ too: if you read the game's parser to learn the format, you can't then write ours. On 2026-12-06
1040
+ Body Harvest's mission-stream reader, written by the agent that had read the unlicensed
1041
+ `missions.c` for "facts only", came out function by function and error by error from the C.
1042
+ Plan the split before anyone opens such code: it's the spec agent's, and someone else writes the
1043
+ reader.
931
1044
  - **Implement a game's decompressor at the game's widths, and check it on every file.** Doom 64's
932
1045
  map compression is adaptive Huffman whose counts are C `short`s, rescaled only when the root
933
1046
  count *equals* 2000. In MAP07 the root steps past 2000, the counts climb to 32767 and wrap, and