@gameslate/sdk 0.3.17 → 0.3.20

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/lib/types.js CHANGED
@@ -277,7 +277,8 @@ export const ServerWsMessageSchema = z.discriminatedUnion('type', [
277
277
  }),
278
278
  z.object({
279
279
  type: z.literal('error'),
280
- code: z.enum(['unauthorized', 'bad_request']),
280
+ /** not_paired: a screen that may view, without the pairing token, tried a change */
281
+ code: z.enum(['unauthorized', 'bad_request', 'not_paired']),
281
282
  message: z.string(),
282
283
  }),
283
284
  ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gameslate/sdk",
3
- "version": "0.3.17",
3
+ "version": "0.3.20",
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",
@@ -9,3 +9,11 @@ yarn check # typecheck, tests (in the core's own sandbox), build, validate
9
9
 
10
10
  `plugin/live.ts` is an example: replace its reads with offsets verified against the game (pin each
11
11
  build by its build id), and fill the pack's catalogue (items, missions, collectibles, pins).
12
+
13
+ ## Release
14
+
15
+ Bump the version in `package.json` and `plugin/manifest.json`, then push a `vX.Y.Z` tag. The release
16
+ workflow uploads `{{id}}-X.Y.Z.zip`, its `.sha256` and `manifest.json`. Players add the plugin in
17
+ GameSlate's settings (the cog, "Add plugin") with
18
+ `https://github.com/<owner>/gameslate-{{id}}/releases/latest/download/manifest.json`, and GameSlate
19
+ checks that URL for updates.
@@ -296,7 +296,8 @@ Anything with a place to move through, a track or a board still gets one.
296
296
 
297
297
  - `listAssets(inputs, pick)` must be cheap: name what can be built.
298
298
  - `buildAsset(id, inputs)` returns outputs in the SDK's shapes: floorplan, location, nav, mesh
299
- (GS3D), and image.
299
+ (GS3D), image, and notes (the text of one JSON object, written as `notes/<id>.json` for a
300
+ pack's `localSource`, e.g. `{ file: 'notes/check-notes.json', key: 'collectibleSets.gs' }`).
300
301
 
301
302
  Images have a `purpose` (`atlas`, `map`, `icon`, `actor`, which picks the folder) and an `encoding`:
302
303
 
@@ -313,6 +314,15 @@ Every image of a game uses one format. In the sandbox:
313
314
  - Inputs are named relative to the folder the player picked (`mods/pack.o2r`). The core also hands
314
315
  in the game's registry manifest as `registry/manifest.json` when there is one, so renders line up
315
316
  with the registry's maps.
317
+ - **Data from the web is a download, never a fetch.** Plugin code has no network and nothing
318
+ runs outside the sandbox (`extract.ts` fails the build). Declare the file in the game's
319
+ manifest entry, `downloads: [{ id, url, sha256 }]` with an exact https URL (a release asset, a
320
+ commit's tarball), and read it as the input `downloads/<id>`. The core fetches it when a build
321
+ starts (at most 64 MB), checks the hash and caches it; the player sees it as a permission, and
322
+ changing the URL or hash asks them again. A tarball is fine to unpack in the sandbox: SoH's
323
+ 11 MB `.tar.gz` (97 MB of tar) gunzips with `fflate/browser`'s streaming `Gunzip` in about 10 s.
324
+ Read the input in chunks and keep only the members you need. A plugin with no assets code can't
325
+ declare downloads.
316
326
  - **Data licensing:** ship the extractor, never its output. Textures, models and renders are
317
327
  built on the player's machine and never committed.
318
328
 
@@ -324,8 +334,11 @@ A plugin carries its games' committed map data in `plugin/registry/games/<gameId
324
334
  into the bundle, and the core serves it at `/registry/games/<gameId>/…`. `gameslate-plugin
325
335
  validate` and the core's loader refuse a plugin whose registry carries a game its manifest doesn't
326
336
  list, a file outside that layout, a file failing its schema, a layer naming a missing SVG, or an
327
- SVG with anything but `svg g path polygon polyline rect circle line text title`. Two plugins
328
- carrying the same game stop the core.
337
+ SVG with anything but `svg g path polygon polyline rect circle line text title`. Of two plugins
338
+ carrying the same game (id or alias), the second is refused. Every refused plugin is listed in
339
+ the cog as "Not loaded: <id> <version>: <reason>": look there first when a deployed plugin is
340
+ missing. A game whose plugin has asset code tells the player, on a place without a map, that its
341
+ maps aren't built yet and to press "Build maps" in the cog, until an extraction has run.
329
342
 
330
343
  Commit only simplified data you produced: schematic SVGs, pins, affines, location and item names,
331
344
  your own hint prose. Game text (objective and dialogue strings from the game's language files) is
@@ -351,7 +364,8 @@ bundles; a package without a licence file fails the build) and copies the repo's
351
364
  game collides with, apply the same filters (section flags that drop flat or upright triangles,
352
365
  vertices flagged "no collision"), keep floors facing up by winding, and colour by surface type.
353
366
  Shade by height and draw higher floors later so bridges sit over roads.
354
- 4. **Location ids are asset ids:** lower-case words, dots and dashes, **no underscores**. The
367
+ 4. **Location ids are asset ids:** lower case, digits, `.`, `_` and `-`, starting with a letter or
368
+ digit (`AssetIdSchema`; its message says "dots and dashes", but `g5_building` is valid). The
355
369
  `locationId` the live reader reports must equal them.
356
370
  5. **Place the player:** the layer's affine maps world x/z onto the drawing exactly as it was
357
371
  drawn. Find the heading convention live: drive straight, then steer one way, and compare the
@@ -486,8 +500,30 @@ yarn check
486
500
  ```
487
501
 
488
502
  That's the typecheck, the tests, the build, then `validate dist/<id>`, which checks the built
489
- plugin exactly as the core will before running it. Then bump `version`, tag `vX.Y.Z`, and publish the release bundle. GameSlate installs presets from
490
- `plugins.lock.json` (an entry with the release URL and its sha256).
503
+ plugin exactly as the core will before running it. Then bump `version` in `package.json` and
504
+ `plugin/manifest.json`, and push a `vX.Y.Z` tag. `.github/workflows/release.yml` runs
505
+ `yarn build --release release`, which writes three files beside each other and uploads them:
506
+
507
+ - `<id>-X.Y.Z.zip`: the built plugin under `<id>/`, made by the build itself, so its hash is known;
508
+ - `<id>-X.Y.Z.zip.sha256`;
509
+ - `manifest.json`: the **published manifest**, the built one plus `bundle: { url, sha256 }`
510
+ naming the zip (by name, resolved against the URL the player gives) and its sha256. Upload it with every release:
511
+ without it, players can't add the plugin by URL or get updates.
512
+
513
+ **How players get it.** In GameSlate's settings (the cog), "Add plugin" takes
514
+ `https://github.com/<owner>/<repo>/releases/latest/download/manifest.json`. The core shows the
515
+ plugin's games and permissions, then downloads the zip, refuses it unless its sha256 matches, checks
516
+ the zip's own manifest is the published one, and unpacks it. It re-reads that URL about hourly: a
517
+ newer version that asks for **no new permissions** installs itself (once none of its games is
518
+ running); one that asks for more (a new game's memory, a new folder) waits for the player to
519
+ confirm. A manifest naming an `extract` module (code outside the sandbox, removed in sdk 0.3.19)
520
+ fails the schema everywhere, presets included (docs/plugin-architecture.md, "Closing the
521
+ sandbox"). So adding a game, a folder or a download in a release
522
+ means every player is asked again: say why in the release notes. A plain zip URL works too
523
+ (validated the same way, its `.zip.sha256` used when present), but gets no updates.
524
+
525
+ GameSlate also builds a few plugins in as presets, from `plugins.lock.json` (the release URL and the
526
+ zip's sha256).
491
527
 
492
528
  ## Pitfalls seen in real plugins
493
529
 
@@ -495,6 +531,12 @@ plugin exactly as the core will before running it. Then bump `version`, tag `vX.
495
531
  game could repeat, add it here (in `@gameslate/sdk`'s `template/claude/skills`, then copy it into
496
532
  the plugin repos) in the same change as the fix. The next game should not have to find it again.
497
533
 
534
+ - **Write JSON whose key order matters as text, not as an object.** JavaScript objects list
535
+ number-like keys (`"3"`, `"12"`) first and in ascending order, whatever order they were added
536
+ in, so `JSON.stringify`, `JSON.parse` and every trip across the sandbox boundary reorder them.
537
+ SoH's check notes key chests and Gold Skulltulas by flag in Python's insertion order: they're
538
+ built as `Map`s and serialised by hand, then returned as a `notes` output's `json` text, which
539
+ the core writes unchanged (2026-12-05).
498
540
  - **Run the support check in `check` once the repo has a support table.** Add `"support":
499
541
  "gameslate-plugin support plugin --built dist/<id>"` and `&& yarn support` to `check`. Without
500
542
  it, gameslate-n64's README frontmatter said Harvest Moon 64 had no missions for a release after
@@ -884,3 +926,104 @@ the plugin repos) in the same change as the fix. The next game should not have t
884
926
  file on the player's PC or an asset extractor. Then grep your hint prose for quoted game strings:
885
927
  Perfect Dark's hints quoted an objective verbatim, and MM's objective labels carried the boss
886
928
  title cards (2026-12-05).
929
+ - **A floorplan drawing is not an SVG.** It has no text, no fill opacity, and fills and strokes are
930
+ separate layers (every stroke above every fill). Porting a hand-written SVG drops its title,
931
+ needs a group's opacity blended into the fill colour by hand, and shows outlines a later fill
932
+ used to cover. Check the port against the old output by geometry (each polygon's points), not
933
+ by bytes (TS2, 2026-12-05).
934
+ - **A local location replaces the registry's fields one level deep** (`{ ...registry, ...local }`),
935
+ and `name` is required. Leave `objectives` out of it to keep the registry's numbered ones; send
936
+ them only with the real labels and every difficulty rule (TS2, 2026-12-05).
937
+ - **Read archives by range, and know inputs by their contents.** A pak's names and directory may
938
+ sit at its end (TS2's P8CK): read the header and that tail, then only the entries you build
939
+ from, so `listAssets` stays cheap on a 20 MB pak. Match a file by its magic and the entries it
940
+ holds, not by the name a dump tool gave it (`_gs_tmp_l_20_ST.pak` is `l_20_ST.pak`) (2026-12-05).
941
+ - **Files the game ships encrypted can't be inputs.** Homefront keeps TS2's level paks inside an
942
+ encrypted `lsao_cached.pak`, so the extractor takes paks the player has extracted, and its
943
+ "nothing found" note and the README say where they come from (2026-12-05).
944
+ - **Objective text may live in the executable, not the level files.** TS2's Story paks hold no
945
+ strings; the labels are in `TimeSplitters2.exe`'s `.data` string table. Search the exe too
946
+ before reporting the text missing (2026-12-05).
947
+ - **Expected pixels in tests follow the port's rounding.** A Python-faithful port rounds half to
948
+ even (401.25 → 401.2): write the expected numbers out rather than computing them with
949
+ `Math.round` (2026-12-05).
950
+ - **Run a mutation's test green first.** A test that already fails "kills" every mutant: a TS2
951
+ test asserting the wrong note passed a mutation run until the full check caught it (2026-12-05).
952
+ - **An extractor is only offered from `plugin/assets.ts`.** The build looks for that file (default
953
+ export: `{ id, extractors: new Map([[gameId, factory]]) }`); a game's `assets.ts` elsewhere is
954
+ never bundled, and `validate` prints `assets: none`. Perfect Dark's objective-text extractor sat
955
+ unoffered for a release, blamed on underscores in its ids, which were valid (2026-12-05).
956
+ - **Read a level's setup from the ROM's binary, not the decomp's C text.** Text heuristics drift
957
+ from what the game does: Perfect Dark's `tag(id, n)` names the prop `n` commands on from the tag
958
+ (`setup.c`), not the next `PAD_` within a few lines, which put 563 tags on the wrong pad, and
959
+ text skips `#if VERSION` blocks (an Escape guard that exists only before NTSC 1.0) and literal
960
+ ids. Size each command from the engine's own length table, check the result against the C text
961
+ on every stage once, and explain each difference (2026-12-05).
962
+ - **Generate opcode tables from the engine, not the macros.** Perfect Dark's `g_CommandLengths`
963
+ has `#if VERSION` entries and a ternary, and four `commands.h` macros disagree with it in size;
964
+ the engine's length wins, the macro gives only operand roles, and a variable-length command
965
+ (`print`, 0x00b5) is sized by scanning to its terminator. Fail loud on an unknown opcode rather
966
+ than guessing a length (2026-12-05).
967
+ - **One background can serve several stages, under another stage's code.** Mr. Blonde's Revenge
968
+ uses Defection's `ame` pads under setup code `wax`: name pads by number from the file the stage
969
+ loads, not by the setup's `PAD_WAX_…` names (the old text builder lost its spawn) (2026-12-05).
970
+ - **Check hint facts against a walkthrough, and test hints for quoted labels.** Generated hint prose
971
+ invents plausible detail: TS2's Siberia hints had the filing cabinets burnt by shooting "red fuel
972
+ drums" in "four rooms", where the game has five cabinets you open and burn with timed mines,
973
+ and a dish "console" where you stick a mine on the dish. Write each fact from a walkthrough
974
+ (a GameFAQs FAQ, often mirrored as PDFs on video-games-museum.com; the Wayback Machine serves
975
+ pages that refuse fetches; StrategyWiki answers 403), in your own words, and name it in the
976
+ commit. Add a test, gated on the local labels file, that fails when a hint holds a label whole,
977
+ a quoted multi-word piece of one, or a five-word run of one; pin its matcher on made-up labels
978
+ so it runs everywhere (TS2, 2026-12-05).
979
+ - **Fact-check every level's hints, not only the one caught.** The other nine TS2 levels were
980
+ invented the same way: a getaway car behind the club (it comes down the street early on), a
981
+ Jacque who drops the crystal (it sits on the altar), a "police precinct" upload (it's a
982
+ computer inside the lab), fire against Stone Golems (trapdoors and grenades). Walkthroughs
983
+ split by difficulty (bomb, poster and golem counts, where the crystal is), so say which
984
+ difficulty a fact holds for, or leave the number out. Drop `obj_N` ids from hint text: the
985
+ player never sees them. Then compare the hints with the walkthrough texts and reword any run
986
+ of six or more words they share; keep the texts in a scratch folder, never in the repo
987
+ (TS2, 2026-12-05). Not in a worktree either: name the sources in the commit message only.
988
+ `plugin/tracked-documents.test.ts` fails on a tracked PDF, HTML, Word, RTF, EPUB or TXT file
989
+ outside licences and `fixtures/` (data-licensing rule, 2026-12-05).
990
+ - **Pins need fact-checking as much as hints.** Seventeen TS2 pin labels named places the level
991
+ doesn't have: a "Dish Control Room" anchored on an oil drum, a "turret" that was a console.
992
+ Label a pin after what its anchor actually is, the model or object type of its setup entry
993
+ (`damfilecabinet`), not after the objective it helps with. A point called a "portal" or an
994
+ "exit" may be the player's start position, so check it. A pin whose object appears only on
995
+ some difficulties gets `hiddenWhen`, built from the setup entry's per-difficulty flags
996
+ (TS2, 2026-12-05).
997
+ - **Invented hints name the wrong tool, place and method.** Perfect Dark's hints were wrong on
998
+ almost every mission: a Data Uplink on cleaning robots (two consoles start them), Mining
999
+ Explosives on a hangar door (a technician's key card), a security "booth" with biometrics, a
1000
+ saucer-hangar medpack, made-up `X=…, Z=…` coordinates. Never put coordinates or button names
1001
+ in hint prose unless the plugin's own data supplies them. A game's briefings are often in its
1002
+ language banks; the decomp's extracted text lets you check them locally, but cite a public
1003
+ copy (the LP Archive shows PD's). When no walkthrough covers a level (PD's Pelagic II), write
1004
+ only what the briefing says and keep it vague. Run the run-comparison after every rewrite:
1005
+ writing from a walkthrough copies its phrases (PD's first rewrite shared 41 six-word runs with
1006
+ its sources, against 6 before). Where an extractor already reads the labels from the player's
1007
+ file, the quoted-label test can call it directly, gated on the input's env var (PD, 2026-12-05).
1008
+ - **Build every published pin from the inputs; don't carry old ones forward.** The Zelda builder
1009
+ copied 201 MM exits, grottos and Pieces of Heart from the previous manifest because nothing
1010
+ made them; once the maps moved into the extractor there was no previous manifest. Each came
1011
+ from the scene: a collision polygon's surface names an exit index into the scene's exit list
1012
+ (the entrance there names the destination), and a collectible actor's params name a Piece of
1013
+ Heart. Compare the rebuild with the published pins by id, label and position, and explain each
1014
+ one you can't derive (one was placed by hand on a moving platform) (2026-12-05).
1015
+ - **Collision has no rooms.** Sort a floor into a room by where the room's own meshes are: the
1016
+ smallest room whose drawn extent holds the floor's centre, else the nearest. A floor under a
1017
+ water box isn't water when the box is a puddle a unit deep; count it as submerged only below
1018
+ wading depth (Zelda, 2026-12-05).
1019
+ - **Frame each pin on a layer that shows it.** Grottos are separate layers, each framed on its own
1020
+ room; an exit placed by height alone landed on another grotto's frame, thousands of pixels off
1021
+ screen. Pick among the layers whose frame holds the pin, then by height (Zelda, 2026-12-05).
1022
+ - **`describe.skipIf` still runs the describe body.** Work done there (opening the gated input)
1023
+ throws on a fresh clone before the skip applies. Build gated data lazily inside the tests.
1024
+ - **Round as the published data did.** Means of integer corners land exactly on .x5; JavaScript's
1025
+ `Math.round` goes up where Python's `round` goes to even, and 4 of 189 exit pins moved by 0.1.
1026
+ - **When a hint correction disagrees with the game's code, the code wins.** A reviewer said MM's
1027
+ barn defence starts at 2 AM; the invasion actor runs from `CLOCK_TIME(2, 30)`. Check timings and
1028
+ rewards in the decomp (the Oceanside Spider House's wallet is chosen by the day it's paid out),
1029
+ then name a walkthrough that agrees (2026-12-05).
@@ -0,0 +1,38 @@
1
+ name: Release
2
+
3
+ # Tag vX.Y.Z (matching package.json and plugin/manifest.json) to publish the built plugin. The
4
+ # release carries {{id}}-X.Y.Z.zip, its .sha256 and manifest.json, the published manifest naming
5
+ # the zip and its sha256. Players add the plugin in GameSlate's settings by this URL, and their
6
+ # GameSlate checks it for updates:
7
+ # https://github.com/<owner>/<repo>/releases/latest/download/manifest.json
8
+ on:
9
+ push:
10
+ tags: ['v*']
11
+
12
+ permissions:
13
+ contents: write
14
+
15
+ jobs:
16
+ release:
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+ - uses: actions/setup-node@v4
21
+ with:
22
+ node-version: 22
23
+ - run: corepack enable
24
+ - run: yarn install
25
+ - run: yarn typecheck && yarn test
26
+ - name: Check the tag matches the plugin's version
27
+ run: |
28
+ v="${GITHUB_REF_NAME#v}"
29
+ test "$(node -p "require('./plugin/manifest.json').version")" = "$v"
30
+ test "$(node -p "require('./package.json').version")" = "$v"
31
+ - run: yarn build --release release && yarn validate
32
+ - name: Publish the release
33
+ env:
34
+ GH_TOKEN: ${{ github.token }}
35
+ run: >-
36
+ gh release create "$GITHUB_REF_NAME"
37
+ release/{{id}}-*.zip release/{{id}}-*.zip.sha256 release/manifest.json
38
+ --title "{{id}} $GITHUB_REF_NAME" --generate-notes
@@ -1,5 +1,7 @@
1
1
  node_modules/
2
2
  dist/
3
+ # yarn build --release release: the zip and published manifest the release workflow uploads
4
+ release/
3
5
  .env
4
6
  .env.*
5
7
  # Yarn's generated install files (Plug'n'Play)
@@ -0,0 +1,68 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { describe, expect, it } from 'vitest';
3
+
4
+ /*
5
+ * No walkthroughs, FAQs or briefings in the repo (.claude/rules/data-licensing.md): they are other
6
+ * people's text, read for fact-checking and kept in a scratch folder. This fails on any tracked
7
+ * document-type file outside a short allowlist.
8
+ *
9
+ * The same file is the core's `tests/tracked-documents.test.ts` and the plugin template's
10
+ * `plugin/tracked-documents.test.ts`; the template test fails when they differ.
11
+ */
12
+ const DOCUMENT = /\.(pdf|html?|docx?|rtf|epub|txt)$/i;
13
+ const ALLOWED: RegExp[] = [
14
+ /* the core web app's entry page */
15
+ /^packages\/web\/index\.html$/,
16
+ /* licence and notice texts, which must travel with what they cover */
17
+ /(^|\/)(LICENSE|COPYING|THIRD_PARTY)[^/]*\.txt$/i,
18
+ /(^|\/)OFL\.txt$/,
19
+ /* golden test fixtures (a parser's expected text output) */
20
+ /(^|\/)fixtures\/.*\.txt$/,
21
+ ];
22
+
23
+ /** Tracked paths that look like a document someone else wrote. */
24
+ export function findDocuments(paths: string[]): string[] {
25
+ return paths.filter(p => DOCUMENT.test(p) && !ALLOWED.some(allowed => allowed.test(p)));
26
+ }
27
+
28
+ function trackedPaths(): string[] {
29
+ const root = execFileSync('git', ['rev-parse', '--show-toplevel'], {
30
+ cwd: import.meta.dirname,
31
+ encoding: 'utf8',
32
+ }).trim();
33
+ return execFileSync('git', ['ls-files', '-z'], { cwd: root, encoding: 'utf8' })
34
+ .split('\0')
35
+ .filter(Boolean);
36
+ }
37
+
38
+ describe('tracked documents', () => {
39
+ it('the allowlist spares licences, fixtures and the web entry page, and nothing else', () => {
40
+ expect(
41
+ findDocuments([
42
+ 'packages/web/index.html',
43
+ 'LICENSE.txt',
44
+ 'tools/fixtures/doom/COPYING-freedoom.txt',
45
+ 'packages/web/public/fonts/OFL.txt',
46
+ 'dist/THIRD_PARTY_LICENSES.txt',
47
+ 'plugin/soh/fixtures/tiny/check-notes.golden.txt',
48
+ 'plugin/live.ts',
49
+ 'README.md',
50
+ ]),
51
+ ).toEqual([]);
52
+ expect(
53
+ findDocuments([
54
+ 'x.pdf',
55
+ 'docs/guide.txt',
56
+ 'plugin/ts2/siberia-faq.TXT',
57
+ 'scratch/bellaonline.htm',
58
+ 'plugin/index.html',
59
+ 'briefing.docx',
60
+ 'notes.rtf',
61
+ 'book.epub',
62
+ ]),
63
+ ).toHaveLength(8);
64
+ });
65
+ it('no walkthrough, FAQ or briefing is tracked', () => {
66
+ expect(findDocuments(trackedPaths())).toEqual([]);
67
+ });
68
+ });