@gameslate/sdk 0.3.6 → 0.3.7

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 CHANGED
@@ -17,6 +17,10 @@ runs the plugin in a QuickJS sandbox, validates everything it returns, and owns
17
17
  | `gameslate-plugin init` | Scaffolds a new plugin repository: an example plugin, a test in the core's sandbox, CI |
18
18
  | `gameslate-plugin build` | Builds a plugin folder into what the core loads |
19
19
  | `gameslate-plugin validate` | Checks a built plugin exactly as the core does: manifest, contract, hashes, and its code loaded in the sandbox |
20
+ | `gameslate-plugin verify` | Runs the game to a known moment (an emulator save state) and checks what a local GameSlate daemon reports, plus the emulator's own memory reads, against a `verify.json` |
21
+
22
+ New plugin repos also get two agent skills in `.claude/skills/`: `build-gameslate-plugin` (from
23
+ choosing a state source to release) and `verify-gameslate-plugin`.
20
24
 
21
25
  ## Start a plugin
22
26
 
@@ -56,4 +60,17 @@ validates it and writes every file.
56
60
 
57
61
  `0.3.x` speaks plugin contract (`sdkApi`) 3: new 0.3 versions add tools, never change the contract. The core refuses a plugin built for another contract.
58
62
 
63
+ - **0.3.7:**
64
+ - image outputs carry a `purpose` (atlas, map, icon, actor) and an `encoding` (PNG or WebP);
65
+ - asset extractors can be up to 10 minutes per asset, and run across builder threads;
66
+ - manifest games take `aliases`, and inputs take `subfolders` (a port's `mods/`), named
67
+ relative to the picked folder;
68
+ - offered folders can't be hidden folders except where games live (`~/.var/app`,
69
+ `~/.local/share`, `~/.steam`);
70
+ - `afterAssets` steps replace `pythonExtract` (deprecated);
71
+ - `raToGuest` / `guestToRa` translate RetroAchievements' N64 addresses;
72
+ - `gameslate-plugin verify`, and the two agent skills in the template;
73
+ - a plugin's sandbox refuses a build none of its sources verified, instead of using the first
74
+ source.
75
+
59
76
  MIT licensed.
@@ -13,6 +13,9 @@ import { initPlugin } from '../build/init-plugin.mjs';
13
13
  * gameslate-plugin validate <builtDir> [--core-version <version>]
14
14
  * Checks a built plugin exactly as the core does before running it: manifest, contract,
15
15
  * hashes, then its live and asset code loaded in the core's own sandbox.
16
+ * gameslate-plugin verify <verify.json>
17
+ * Runs the game to a known moment (RetroArch on a save state) and checks what a local
18
+ * GameSlate daemon reports, and the emulator's own memory reads, against the file.
16
19
  */
17
20
  const { values, positionals } = parseArgs({
18
21
  options: {
@@ -29,6 +32,7 @@ const USAGE = [
29
32
  'usage: gameslate-plugin init <dir> --id <id> [--name <name>]',
30
33
  ' gameslate-plugin build <pluginDir> --out <dir> [--tested-with <version>]',
31
34
  ' gameslate-plugin validate <builtDir> [--core-version <version>]',
35
+ ' gameslate-plugin verify <verify.json>',
32
36
  ].join('\n');
33
37
 
34
38
  async function validate(builtDir) {
@@ -76,6 +80,16 @@ if (command === 'build' && dir && values.out) {
76
80
  const problems = await validate(path.resolve(dir));
77
81
  for (const p of problems) console.error(`refused: ${p}`);
78
82
  process.exit(problems.length ? 1 : 0);
83
+ } else if (command === 'verify' && dir) {
84
+ const { runVerify, VerifySpecSchema } = await import('../lib/host/index.js');
85
+ const { verifyEffects } = await import('../build/verify-effects.mjs');
86
+ const file = path.resolve(dir);
87
+ const spec = VerifySpecSchema.parse(JSON.parse(fs.readFileSync(file, 'utf8')));
88
+ const result = await runVerify(spec, verifyEffects(path.dirname(file)));
89
+ console.log(result.ok ? `${spec.game}: verified` : `${spec.game}: NOT verified`);
90
+ for (const p of result.problems) console.log(` ${p}`);
91
+ for (const s of result.screenshots) console.log(` screenshot: ${s}`);
92
+ process.exit(result.ok ? 0 : 1);
79
93
  } else {
80
94
  console.error(USAGE);
81
95
  process.exit(1);
@@ -13,6 +13,8 @@ const ID = /^[a-z0-9][a-z0-9-]*$/;
13
13
  const DOTFILES = new Map([
14
14
  ['gitignore', '.gitignore'],
15
15
  ['github', '.github'],
16
+ /* the agent skills for building and verifying the plugin */
17
+ ['claude', '.claude'],
16
18
  ]);
17
19
 
18
20
  function copy(from, to, fill) {
@@ -0,0 +1,120 @@
1
+ import { spawn } from 'node:child_process';
2
+ import dgram from 'node:dgram';
3
+ import path from 'node:path';
4
+
5
+ /*
6
+ * The real effects of `gameslate-plugin verify` (src/host/verify.ts has the steps and their
7
+ * tests): RetroArch started on a save state, its network commands over UDP, the daemon's state
8
+ * over its WebSocket, and screenshots (RetroArch's own; the GameSlate page through Playwright
9
+ * when it's installed).
10
+ */
11
+
12
+ const STARTUP_MS = 3000;
13
+ const COMMAND_TIMEOUT_MS = 2000;
14
+
15
+ /** @param {string} specDir paths in the spec are relative to it */
16
+ export function verifyEffects(specDir, log = line => console.error(line)) {
17
+ const at = p => path.resolve(specDir, p);
18
+ return {
19
+ launch: spec => launchRetroArch(spec, at, log),
20
+ wait: ms => new Promise(resolve => setTimeout(resolve, ms)),
21
+ state: spec => nextState(spec),
22
+ command: (spec, line) => retroArchCommand(spec.retroarch?.port ?? 55355, line),
23
+ screenshots: spec => screenshots(spec, at, log),
24
+ };
25
+ }
26
+
27
+ function launchRetroArch(spec, at, log) {
28
+ const ra = spec.retroarch;
29
+ if (!ra) return Promise.resolve({ stop: () => undefined });
30
+ const args = ['-L', at(ra.core), at(ra.rom), '-e', String(ra.stateSlot)];
31
+ if (ra.config) args.push('--appendconfig', at(ra.config));
32
+ const [first, ...rest] = [...ra.launchPrefix, at(ra.binary), ...args];
33
+ const child = spawn(first, rest, { stdio: 'ignore' });
34
+ log(`started RetroArch (pid ${child.pid}) on state slot ${ra.stateSlot}`);
35
+ return new Promise((resolve, reject) => {
36
+ child.once('error', reject);
37
+ child.once('exit', code => reject(new Error(`RetroArch exited (${code}) while starting`)));
38
+ setTimeout(() => {
39
+ child.removeAllListeners('exit');
40
+ resolve({ stop: () => child.kill('SIGTERM') });
41
+ }, STARTUP_MS);
42
+ });
43
+ }
44
+
45
+ /* the daemon's next full state for the spec's game */
46
+ function nextState(spec) {
47
+ return new Promise((resolve, reject) => {
48
+ const ws = new globalThis.WebSocket(spec.daemon.url);
49
+ const timer = setTimeout(() => {
50
+ ws.close();
51
+ reject(
52
+ new Error(
53
+ `no state for ${spec.game} from ${spec.daemon.url} in ${spec.timeoutMs} ms`,
54
+ ),
55
+ );
56
+ }, spec.timeoutMs);
57
+ ws.addEventListener('error', () => {
58
+ clearTimeout(timer);
59
+ reject(new Error(`can't reach the daemon at ${spec.daemon.url}`));
60
+ });
61
+ ws.addEventListener('message', event => {
62
+ const m = JSON.parse(String(event.data));
63
+ if (m.type !== 'state:full' || m.gameId !== spec.game || !m.state) return;
64
+ clearTimeout(timer);
65
+ ws.close();
66
+ resolve(m.state);
67
+ });
68
+ });
69
+ }
70
+
71
+ /* one RetroArch network command and its reply */
72
+ function retroArchCommand(port, line) {
73
+ return new Promise((resolve, reject) => {
74
+ const socket = dgram.createSocket('udp4');
75
+ const timer = setTimeout(() => {
76
+ socket.close();
77
+ reject(
78
+ new Error(`RetroArch didn't answer "${line}" (network commands on, port ${port}?)`),
79
+ );
80
+ }, COMMAND_TIMEOUT_MS);
81
+ socket.once('message', reply => {
82
+ clearTimeout(timer);
83
+ socket.close();
84
+ resolve(String(reply));
85
+ });
86
+ socket.send(line, port, '127.0.0.1');
87
+ });
88
+ }
89
+
90
+ async function screenshots(spec, at, log) {
91
+ const files = [];
92
+ if (spec.retroarch) {
93
+ /* no reply: the file goes to RetroArch's screenshot_directory */
94
+ const socket = dgram.createSocket('udp4');
95
+ await new Promise(resolve =>
96
+ socket.send('SCREENSHOT', spec.retroarch.port, '127.0.0.1', resolve),
97
+ );
98
+ socket.close();
99
+ files.push("(RetroArch's screenshot directory)");
100
+ }
101
+ if (spec.ui) {
102
+ const playwright = await import('playwright').catch(() => null);
103
+ if (!playwright) {
104
+ log('Playwright is not installed: no screenshot of the GameSlate page');
105
+ return files;
106
+ }
107
+ const browser = await playwright.chromium.launch();
108
+ try {
109
+ const page = await browser.newPage({ viewport: { width: 1280, height: 800 } });
110
+ await page.goto(spec.ui);
111
+ await page.waitForTimeout(2000);
112
+ const file = at(`verify-${spec.game}-ui.png`);
113
+ await page.screenshot({ path: file });
114
+ files.push(file);
115
+ } finally {
116
+ await browser.close();
117
+ }
118
+ }
119
+ return files;
120
+ }
package/lib/assets.d.ts CHANGED
@@ -127,11 +127,42 @@ export declare const FloorplanDrawingSchema: z.ZodObject<{
127
127
  export type FloorplanDrawing = z.infer<typeof FloorplanDrawingSchema>;
128
128
  /** The SVG for a drawing. Every value in it has passed the schema, so it's safe to serve. */
129
129
  export declare function floorplanToSvg(drawing: FloorplanDrawing): string;
130
+ export declare const ImagePurposeSchema: z.ZodEnum<["atlas", "map", "icon", "actor"]>;
131
+ export type ImagePurpose = z.infer<typeof ImagePurposeSchema>;
132
+ /** PNG, lossless WebP, or lossy WebP at a quality from 1 to 100. */
133
+ export declare const ImageEncodingSchema: z.ZodUnion<[z.ZodObject<{
134
+ format: z.ZodLiteral<"png">;
135
+ }, "strict", z.ZodTypeAny, {
136
+ format: "png";
137
+ }, {
138
+ format: "png";
139
+ }>, z.ZodObject<{
140
+ format: z.ZodLiteral<"webp">;
141
+ lossless: z.ZodLiteral<true>;
142
+ }, "strict", z.ZodTypeAny, {
143
+ format: "webp";
144
+ lossless: true;
145
+ }, {
146
+ format: "webp";
147
+ lossless: true;
148
+ }>, z.ZodObject<{
149
+ format: z.ZodLiteral<"webp">;
150
+ quality: z.ZodNumber;
151
+ }, "strict", z.ZodTypeAny, {
152
+ format: "webp";
153
+ quality: number;
154
+ }, {
155
+ format: "webp";
156
+ quality: number;
157
+ }>]>;
158
+ export type ImageEncoding = z.infer<typeof ImageEncodingSchema>;
130
159
  /**
131
160
  * One file-shaped result of building an asset; the core decides where each goes:
132
161
  * floorplan → maps/<id>.svg location → manifest.json (locations[id])
133
- * nav → navs/<id>.json mesh → meshes/<id>.bin (+ its atlas as meshes/<id>.png)
134
- * image → atlases/<id>.png
162
+ * nav → navs/<id>.json mesh → meshes/<id>.bin (+ its atlas beside it)
163
+ * image → by purpose: atlases/ (default), maps/, icons/ or actors/<id>.png | .webp
164
+ * The core encodes images from the pixels; every image of a game uses one format (the web app
165
+ * reads one extension per game).
135
166
  */
136
167
  export declare const AssetOutputSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
137
168
  kind: z.ZodLiteral<"floorplan">;
@@ -817,13 +848,13 @@ export declare const AssetOutputSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodOb
817
848
  }, "strip", z.ZodTypeAny, {
818
849
  id: string;
819
850
  kind: "mesh";
820
- data: number;
821
851
  atlas: string;
852
+ data: number;
822
853
  }, {
823
854
  id: string;
824
855
  kind: "mesh";
825
- data: number;
826
856
  atlas: string;
857
+ data: number;
827
858
  }>, z.ZodObject<{
828
859
  kind: z.ZodLiteral<"image">;
829
860
  id: z.ZodEffects<z.ZodString, string, string>;
@@ -831,18 +862,66 @@ export declare const AssetOutputSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodOb
831
862
  height: z.ZodNumber;
832
863
  /** RGBA, width × height × 4 bytes */
833
864
  pixels: z.ZodNumber;
865
+ /** what the image is for, which picks its folder (default atlas: a mesh's texture) */
866
+ purpose: z.ZodOptional<z.ZodEnum<["atlas", "map", "icon", "actor"]>>;
867
+ /** how the core encodes it (default PNG) */
868
+ encoding: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
869
+ format: z.ZodLiteral<"png">;
870
+ }, "strict", z.ZodTypeAny, {
871
+ format: "png";
872
+ }, {
873
+ format: "png";
874
+ }>, z.ZodObject<{
875
+ format: z.ZodLiteral<"webp">;
876
+ lossless: z.ZodLiteral<true>;
877
+ }, "strict", z.ZodTypeAny, {
878
+ format: "webp";
879
+ lossless: true;
880
+ }, {
881
+ format: "webp";
882
+ lossless: true;
883
+ }>, z.ZodObject<{
884
+ format: z.ZodLiteral<"webp">;
885
+ quality: z.ZodNumber;
886
+ }, "strict", z.ZodTypeAny, {
887
+ format: "webp";
888
+ quality: number;
889
+ }, {
890
+ format: "webp";
891
+ quality: number;
892
+ }>]>>;
834
893
  }, "strip", z.ZodTypeAny, {
835
894
  id: string;
836
895
  kind: "image";
837
896
  width: number;
838
897
  height: number;
839
898
  pixels: number;
899
+ purpose?: "icon" | "map" | "atlas" | "actor" | undefined;
900
+ encoding?: {
901
+ format: "png";
902
+ } | {
903
+ format: "webp";
904
+ lossless: true;
905
+ } | {
906
+ format: "webp";
907
+ quality: number;
908
+ } | undefined;
840
909
  }, {
841
910
  id: string;
842
911
  kind: "image";
843
912
  width: number;
844
913
  height: number;
845
914
  pixels: number;
915
+ purpose?: "icon" | "map" | "atlas" | "actor" | undefined;
916
+ encoding?: {
917
+ format: "png";
918
+ } | {
919
+ format: "webp";
920
+ lossless: true;
921
+ } | {
922
+ format: "webp";
923
+ quality: number;
924
+ } | undefined;
846
925
  }>]>;
847
926
  export type AssetOutputWire = z.infer<typeof AssetOutputSchema>;
848
927
  export declare const AssetResultSchema: z.ZodObject<{
@@ -1530,13 +1609,13 @@ export declare const AssetResultSchema: z.ZodObject<{
1530
1609
  }, "strip", z.ZodTypeAny, {
1531
1610
  id: string;
1532
1611
  kind: "mesh";
1533
- data: number;
1534
1612
  atlas: string;
1613
+ data: number;
1535
1614
  }, {
1536
1615
  id: string;
1537
1616
  kind: "mesh";
1538
- data: number;
1539
1617
  atlas: string;
1618
+ data: number;
1540
1619
  }>, z.ZodObject<{
1541
1620
  kind: z.ZodLiteral<"image">;
1542
1621
  id: z.ZodEffects<z.ZodString, string, string>;
@@ -1544,18 +1623,66 @@ export declare const AssetResultSchema: z.ZodObject<{
1544
1623
  height: z.ZodNumber;
1545
1624
  /** RGBA, width × height × 4 bytes */
1546
1625
  pixels: z.ZodNumber;
1626
+ /** what the image is for, which picks its folder (default atlas: a mesh's texture) */
1627
+ purpose: z.ZodOptional<z.ZodEnum<["atlas", "map", "icon", "actor"]>>;
1628
+ /** how the core encodes it (default PNG) */
1629
+ encoding: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
1630
+ format: z.ZodLiteral<"png">;
1631
+ }, "strict", z.ZodTypeAny, {
1632
+ format: "png";
1633
+ }, {
1634
+ format: "png";
1635
+ }>, z.ZodObject<{
1636
+ format: z.ZodLiteral<"webp">;
1637
+ lossless: z.ZodLiteral<true>;
1638
+ }, "strict", z.ZodTypeAny, {
1639
+ format: "webp";
1640
+ lossless: true;
1641
+ }, {
1642
+ format: "webp";
1643
+ lossless: true;
1644
+ }>, z.ZodObject<{
1645
+ format: z.ZodLiteral<"webp">;
1646
+ quality: z.ZodNumber;
1647
+ }, "strict", z.ZodTypeAny, {
1648
+ format: "webp";
1649
+ quality: number;
1650
+ }, {
1651
+ format: "webp";
1652
+ quality: number;
1653
+ }>]>>;
1547
1654
  }, "strip", z.ZodTypeAny, {
1548
1655
  id: string;
1549
1656
  kind: "image";
1550
1657
  width: number;
1551
1658
  height: number;
1552
1659
  pixels: number;
1660
+ purpose?: "icon" | "map" | "atlas" | "actor" | undefined;
1661
+ encoding?: {
1662
+ format: "png";
1663
+ } | {
1664
+ format: "webp";
1665
+ lossless: true;
1666
+ } | {
1667
+ format: "webp";
1668
+ quality: number;
1669
+ } | undefined;
1553
1670
  }, {
1554
1671
  id: string;
1555
1672
  kind: "image";
1556
1673
  width: number;
1557
1674
  height: number;
1558
1675
  pixels: number;
1676
+ purpose?: "icon" | "map" | "atlas" | "actor" | undefined;
1677
+ encoding?: {
1678
+ format: "png";
1679
+ } | {
1680
+ format: "webp";
1681
+ lossless: true;
1682
+ } | {
1683
+ format: "webp";
1684
+ quality: number;
1685
+ } | undefined;
1559
1686
  }>]>, "many">;
1560
1687
  }, "strip", z.ZodTypeAny, {
1561
1688
  outputs: ({
@@ -1651,14 +1778,24 @@ export declare const AssetResultSchema: z.ZodObject<{
1651
1778
  } | {
1652
1779
  id: string;
1653
1780
  kind: "mesh";
1654
- data: number;
1655
1781
  atlas: string;
1782
+ data: number;
1656
1783
  } | {
1657
1784
  id: string;
1658
1785
  kind: "image";
1659
1786
  width: number;
1660
1787
  height: number;
1661
1788
  pixels: number;
1789
+ purpose?: "icon" | "map" | "atlas" | "actor" | undefined;
1790
+ encoding?: {
1791
+ format: "png";
1792
+ } | {
1793
+ format: "webp";
1794
+ lossless: true;
1795
+ } | {
1796
+ format: "webp";
1797
+ quality: number;
1798
+ } | undefined;
1662
1799
  })[];
1663
1800
  }, {
1664
1801
  outputs: ({
@@ -1754,14 +1891,24 @@ export declare const AssetResultSchema: z.ZodObject<{
1754
1891
  } | {
1755
1892
  id: string;
1756
1893
  kind: "mesh";
1757
- data: number;
1758
1894
  atlas: string;
1895
+ data: number;
1759
1896
  } | {
1760
1897
  id: string;
1761
1898
  kind: "image";
1762
1899
  width: number;
1763
1900
  height: number;
1764
1901
  pixels: number;
1902
+ purpose?: "icon" | "map" | "atlas" | "actor" | undefined;
1903
+ encoding?: {
1904
+ format: "png";
1905
+ } | {
1906
+ format: "webp";
1907
+ lossless: true;
1908
+ } | {
1909
+ format: "webp";
1910
+ quality: number;
1911
+ } | undefined;
1765
1912
  })[];
1766
1913
  }>;
1767
1914
  /** An output as plugin code builds it: binary data as bytes. */
package/lib/assets.js CHANGED
@@ -77,11 +77,20 @@ export function floorplanToSvg(drawing) {
77
77
  /** Binary data in an output: in plugin code a Uint8Array; across the sandbox boundary, an index
78
78
  * into the chunks the guest handed the core during that call. */
79
79
  const BinaryRef = z.number().int().nonnegative();
80
+ export const ImagePurposeSchema = z.enum(['atlas', 'map', 'icon', 'actor']);
81
+ /** PNG, lossless WebP, or lossy WebP at a quality from 1 to 100. */
82
+ export const ImageEncodingSchema = z.union([
83
+ z.object({ format: z.literal('png') }).strict(),
84
+ z.object({ format: z.literal('webp'), lossless: z.literal(true) }).strict(),
85
+ z.object({ format: z.literal('webp'), quality: z.number().int().min(1).max(100) }).strict(),
86
+ ]);
80
87
  /**
81
88
  * One file-shaped result of building an asset; the core decides where each goes:
82
89
  * floorplan → maps/<id>.svg location → manifest.json (locations[id])
83
- * nav → navs/<id>.json mesh → meshes/<id>.bin (+ its atlas as meshes/<id>.png)
84
- * image → atlases/<id>.png
90
+ * nav → navs/<id>.json mesh → meshes/<id>.bin (+ its atlas beside it)
91
+ * image → by purpose: atlases/ (default), maps/, icons/ or actors/<id>.png | .webp
92
+ * The core encodes images from the pixels; every image of a game uses one format (the web app
93
+ * reads one extension per game).
85
94
  */
86
95
  export const AssetOutputSchema = z.discriminatedUnion('kind', [
87
96
  z.object({ kind: z.literal('floorplan'), id: AssetIdSchema, drawing: FloorplanDrawingSchema }),
@@ -102,6 +111,10 @@ export const AssetOutputSchema = z.discriminatedUnion('kind', [
102
111
  height: z.number().int().positive().max(16_384),
103
112
  /** RGBA, width × height × 4 bytes */
104
113
  pixels: BinaryRef,
114
+ /** what the image is for, which picks its folder (default atlas: a mesh's texture) */
115
+ purpose: ImagePurposeSchema.optional(),
116
+ /** how the core encodes it (default PNG) */
117
+ encoding: ImageEncodingSchema.optional(),
105
118
  }),
106
119
  ]);
107
120
  export const AssetResultSchema = z.object({ outputs: z.array(AssetOutputSchema).max(1000) });
@@ -43,17 +43,17 @@ export declare const CounterSchema: z.ZodObject<{
43
43
  id: string;
44
44
  icon?: string | undefined;
45
45
  max?: string | number | undefined;
46
+ format?: "number" | "percent" | undefined;
46
47
  display?: Record<string, string> | undefined;
47
48
  role?: "keys" | "health" | "magic" | "armor" | undefined;
48
- format?: "number" | "percent" | undefined;
49
49
  }, {
50
50
  label: string;
51
51
  id: string;
52
52
  icon?: string | undefined;
53
53
  max?: string | number | undefined;
54
+ format?: "number" | "percent" | undefined;
54
55
  display?: Record<string, string> | undefined;
55
56
  role?: "keys" | "health" | "magic" | "armor" | undefined;
56
- format?: "number" | "percent" | undefined;
57
57
  }>;
58
58
  export type CatalogueCounter = z.infer<typeof CounterSchema>;
59
59
  export type CounterRole = NonNullable<CatalogueCounter['role']>;
@@ -613,17 +613,17 @@ export declare const CatalogueSchema: z.ZodObject<{
613
613
  id: string;
614
614
  icon?: string | undefined;
615
615
  max?: string | number | undefined;
616
+ format?: "number" | "percent" | undefined;
616
617
  display?: Record<string, string> | undefined;
617
618
  role?: "keys" | "health" | "magic" | "armor" | undefined;
618
- format?: "number" | "percent" | undefined;
619
619
  }, {
620
620
  label: string;
621
621
  id: string;
622
622
  icon?: string | undefined;
623
623
  max?: string | number | undefined;
624
+ format?: "number" | "percent" | undefined;
624
625
  display?: Record<string, string> | undefined;
625
626
  role?: "keys" | "health" | "magic" | "armor" | undefined;
626
- format?: "number" | "percent" | undefined;
627
627
  }>, "many">;
628
628
  /** flag sets the pack's decoder streams (bit conditions may only reference these) */
629
629
  flagSets: z.ZodArray<z.ZodString, "many">;
@@ -1048,9 +1048,9 @@ export declare const CatalogueSchema: z.ZodObject<{
1048
1048
  id: string;
1049
1049
  icon?: string | undefined;
1050
1050
  max?: string | number | undefined;
1051
+ format?: "number" | "percent" | undefined;
1051
1052
  display?: Record<string, string> | undefined;
1052
1053
  role?: "keys" | "health" | "magic" | "armor" | undefined;
1053
- format?: "number" | "percent" | undefined;
1054
1054
  }[];
1055
1055
  flagSets: string[];
1056
1056
  items: {
@@ -1167,9 +1167,9 @@ export declare const CatalogueSchema: z.ZodObject<{
1167
1167
  id: string;
1168
1168
  icon?: string | undefined;
1169
1169
  max?: string | number | undefined;
1170
+ format?: "number" | "percent" | undefined;
1170
1171
  display?: Record<string, string> | undefined;
1171
1172
  role?: "keys" | "health" | "magic" | "armor" | undefined;
1172
- format?: "number" | "percent" | undefined;
1173
1173
  }[];
1174
1174
  flagSets: string[];
1175
1175
  items: {
@@ -4,17 +4,29 @@ export declare const ASSET_LIMITS: {
4
4
  readonly memoryBytes: number;
5
5
  readonly stackBytes: number;
6
6
  readonly loadMs: 10000;
7
- /** one asset (the spike's slowest Doom map took 0.3 s) */
8
- readonly callMs: 120000;
7
+ /**
8
+ * One asset. Extraction runs in a worker thread, away from the daemon, so this is a guard
9
+ * against a plugin that never returns, not a speed target: a Zelda map layer with an HD
10
+ * texture pack takes 40–70 s in the interpreter on a fast machine.
11
+ */
12
+ readonly callMs: 600000;
9
13
  /** the largest single input read */
10
14
  readonly maxReadBytes: number;
11
15
  /** all output bytes of one asset */
12
16
  readonly maxOutputBytes: number;
13
17
  };
14
18
  /** The player's files for one run, opened by the core and read by range. */
19
+ /** An input's name as the plugin sees it: relative to the folder the player picked (`mods/x.o2r`),
20
+ * or just the file's name when files were picked one by one. */
21
+ export declare const inputName: (file: string, root: string | undefined) => string;
15
22
  export declare class InputSet {
16
23
  private readonly files;
17
- constructor(paths: readonly string[]);
24
+ /** `named`: files from outside the picked folder, under the name the plugin sees (the core's
25
+ * registry data for the game, `registry/manifest.json`) */
26
+ constructor(paths: readonly string[], root?: string, named?: ReadonlyArray<{
27
+ path: string;
28
+ name: string;
29
+ }>);
18
30
  /** what the guest sees: handles, names and sizes, never paths */
19
31
  describe(): SandboxInputFile[];
20
32
  read(handle: number, offset: number, length: number): Uint8Array;
@@ -37,6 +49,8 @@ export declare class AssetSandbox {
37
49
  inputs: InputSet;
38
50
  log: (line: string) => void;
39
51
  });
52
+ /** whether it broke a limit (out of memory, over budget) and refuses every call from now on */
53
+ get switchedOff(): boolean;
40
54
  games(): string[];
41
55
  list(gameId: string, pick: InputPick): AssetList;
42
56
  build(gameId: string, id: string): BuiltAsset;
@@ -12,20 +12,37 @@ export const ASSET_LIMITS = {
12
12
  memoryBytes: 1024 * 1024 * 1024,
13
13
  stackBytes: 1024 * 1024,
14
14
  loadMs: 10_000,
15
- /** one asset (the spike's slowest Doom map took 0.3 s) */
16
- callMs: 120_000,
15
+ /**
16
+ * One asset. Extraction runs in a worker thread, away from the daemon, so this is a guard
17
+ * against a plugin that never returns, not a speed target: a Zelda map layer with an HD
18
+ * texture pack takes 40–70 s in the interpreter on a fast machine.
19
+ */
20
+ callMs: 600_000,
17
21
  /** the largest single input read */
18
22
  maxReadBytes: 64 * 1024 * 1024,
19
23
  /** all output bytes of one asset */
20
24
  maxOutputBytes: 256 * 1024 * 1024,
21
25
  };
22
26
  /** The player's files for one run, opened by the core and read by range. */
27
+ /** An input's name as the plugin sees it: relative to the folder the player picked (`mods/x.o2r`),
28
+ * or just the file's name when files were picked one by one. */
29
+ export const inputName = (file, root) => root ? path.relative(root, file).split(path.sep).join('/') : path.basename(file);
23
30
  export class InputSet {
24
31
  files = [];
25
- constructor(paths) {
26
- for (const p of paths) {
27
- const fd = fs.openSync(p, 'r');
28
- this.files.push({ fd, name: path.basename(p), size: fs.fstatSync(fd).size });
32
+ /** `named`: files from outside the picked folder, under the name the plugin sees (the core's
33
+ * registry data for the game, `registry/manifest.json`) */
34
+ constructor(paths, root, named = []) {
35
+ const all = [...paths.map(p => ({ path: p, name: inputName(p, root) })), ...named];
36
+ try {
37
+ for (const { path: p, name } of all) {
38
+ const fd = fs.openSync(p, 'r');
39
+ this.files.push({ fd, name, size: fs.fstatSync(fd).size });
40
+ }
41
+ }
42
+ catch (e) {
43
+ /* the daemon runs for days: close what was opened before the one that failed */
44
+ this.close();
45
+ throw e;
29
46
  }
30
47
  }
31
48
  /** what the guest sees: handles, names and sizes, never paths */
@@ -74,6 +91,10 @@ export class AssetSandbox {
74
91
  log,
75
92
  });
76
93
  }
94
+ /** whether it broke a limit (out of memory, over budget) and refuses every call from now on */
95
+ get switchedOff() {
96
+ return this.guest.switchedOff;
97
+ }
77
98
  games() {
78
99
  const games = this.guest.call('games', []);
79
100
  if (!Array.isArray(games) || !games.every(g => typeof g === 'string')) {
@@ -2,3 +2,4 @@ export * from './quickjs-guest.js';
2
2
  export * from './live-sandbox.js';
3
3
  export * from './asset-sandbox.js';
4
4
  export * from './inspect.js';
5
+ export * from './verify.js';
package/lib/host/index.js CHANGED
@@ -6,3 +6,4 @@ export * from './quickjs-guest.js';
6
6
  export * from './live-sandbox.js';
7
7
  export * from './asset-sandbox.js';
8
8
  export * from './inspect.js';
9
+ export * from './verify.js';