@gameslate/sdk 0.3.16 → 0.3.19
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 +23 -3
- package/bin/gameslate-plugin.mjs +8 -3
- package/build/build-plugin.d.mts +8 -2
- package/build/build-plugin.mjs +74 -43
- package/build/third-party-licences.d.mts +7 -0
- package/build/third-party-licences.mjs +52 -0
- package/build/zip.d.mts +6 -0
- package/build/zip.mjs +94 -0
- package/lib/assets.d.ts +41 -1
- package/lib/assets.js +22 -0
- package/lib/host/asset-sandbox.d.ts +2 -1
- package/lib/host/asset-sandbox.js +7 -2
- package/lib/host/index.d.ts +1 -0
- package/lib/host/index.js +1 -0
- package/lib/host/inspect.d.ts +2 -0
- package/lib/host/inspect.js +6 -2
- package/lib/host/plugin-registry.d.ts +11 -0
- package/lib/host/plugin-registry.js +130 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/pack.d.ts +1 -1
- package/lib/plugin/contract.d.ts +3 -46
- package/lib/plugin-manifest.d.ts +175 -24
- package/lib/plugin-manifest.js +88 -11
- package/lib/plugin-permissions.d.ts +20 -0
- package/lib/plugin-permissions.js +58 -0
- package/lib/plugins-api.d.ts +476 -6
- package/lib/plugins-api.js +56 -1
- package/lib/registry.d.ts +0 -81
- package/lib/registry.js +0 -16
- package/package.json +1 -1
- package/template/README.md +8 -0
- package/template/claude/skills/build-gameslate-plugin/SKILL.md +185 -10
- package/template/claude/skills/verify-gameslate-plugin/SKILL.md +4 -3
- package/template/github/workflows/release.yml +38 -0
- package/template/gitignore +2 -0
- package/template/plugin/tracked-documents.test.ts +68 -0
package/lib/host/inspect.js
CHANGED
|
@@ -4,6 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import { PluginManifestSchema, SDK_API } from '../plugin-manifest.js';
|
|
5
5
|
import { AssetSandbox, InputSet } from './asset-sandbox.js';
|
|
6
6
|
import { PluginSandbox } from './live-sandbox.js';
|
|
7
|
+
import { inspectPluginRegistry } from './plugin-registry.js';
|
|
7
8
|
export function readPluginManifest(dir) {
|
|
8
9
|
let raw;
|
|
9
10
|
try {
|
|
@@ -77,11 +78,14 @@ export function inspectPlugin(quickJs, dir, manifest, opts) {
|
|
|
77
78
|
if (manifest.sdkApi !== SDK_API) {
|
|
78
79
|
return `built for plugin contract ${manifest.sdkApi}, this core speaks ${SDK_API}`;
|
|
79
80
|
}
|
|
80
|
-
const bad = [manifest.code, manifest.assets
|
|
81
|
+
const bad = [manifest.code, manifest.assets]
|
|
81
82
|
.flatMap(code => (code ? [codeProblem(dir, code)] : []))
|
|
82
83
|
.find(reason => reason !== null);
|
|
83
84
|
if (bad)
|
|
84
85
|
return bad;
|
|
86
|
+
const registry = inspectPluginRegistry(dir, manifest);
|
|
87
|
+
if (typeof registry === 'string')
|
|
88
|
+
return registry;
|
|
85
89
|
const warnings = manifest.testedWith.includes(opts.coreVersion)
|
|
86
90
|
? []
|
|
87
91
|
: [
|
|
@@ -93,5 +97,5 @@ export function inspectPlugin(quickJs, dir, manifest, opts) {
|
|
|
93
97
|
const assets = loadAssets(quickJs, dir, manifest, opts.log);
|
|
94
98
|
if (typeof assets === 'string')
|
|
95
99
|
return assets;
|
|
96
|
-
return { manifest, live, assets, warnings };
|
|
100
|
+
return { manifest, live, assets, registryGames: registry.games, warnings };
|
|
97
101
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PluginManifest } from '../plugin-manifest.js';
|
|
2
|
+
export declare const REGISTRY_DIR = "registry";
|
|
3
|
+
/** Why an SVG can't be served (a tag outside the set, a script hook, a bare `&`), or null. */
|
|
4
|
+
export declare function svgProblem(text: string): string | null;
|
|
5
|
+
/**
|
|
6
|
+
* The games a built (or source) plugin folder carries registry data for, or why it can't be used:
|
|
7
|
+
* a game its manifest doesn't list, a file that fails its schema, an SVG outside the safe set.
|
|
8
|
+
*/
|
|
9
|
+
export declare function inspectPluginRegistry(dir: string, manifest: PluginManifest): {
|
|
10
|
+
games: string[];
|
|
11
|
+
} | string;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { GameManifestSchema, HintGraphSchema } from '../registry.js';
|
|
4
|
+
/*
|
|
5
|
+
* A plugin's registry data: the committed, simplified map data for its games, served by the core
|
|
6
|
+
* at `/registry/games/<gameId>/…` (docs/plugin-architecture.md). In a plugin folder and in its
|
|
7
|
+
* build it is
|
|
8
|
+
*
|
|
9
|
+
* registry/games/<gameId>/manifest.json GameManifestSchema (a layer's `svg` is
|
|
10
|
+
* `games/<gameId>/maps/<file>.svg`)
|
|
11
|
+
* registry/games/<gameId>/hints.json HintGraphSchema, optional
|
|
12
|
+
* registry/games/<gameId>/maps/*.svg schematic floorplans, from a fixed set of tags
|
|
13
|
+
*
|
|
14
|
+
* Nothing else. It is untrusted input, so the core checks it here before serving any of it.
|
|
15
|
+
*/
|
|
16
|
+
export const REGISTRY_DIR = 'registry';
|
|
17
|
+
/* Shapes and text only: the web app draws these, so no script, links, styles or embedded content. */
|
|
18
|
+
const SVG_TAGS = new Set([
|
|
19
|
+
'svg',
|
|
20
|
+
'g',
|
|
21
|
+
'path',
|
|
22
|
+
'polygon',
|
|
23
|
+
'polyline',
|
|
24
|
+
'rect',
|
|
25
|
+
'circle',
|
|
26
|
+
'line',
|
|
27
|
+
'text',
|
|
28
|
+
'title',
|
|
29
|
+
]);
|
|
30
|
+
const UNSAFE_SVG = [/\son[a-z]+\s*=/i, /javascript:/i, /<!DOCTYPE/i, /<!ENTITY/i, /href\s*=/i];
|
|
31
|
+
const BARE_AMPERSAND = /&(?!(?:amp|lt|gt|quot|apos|#\d+|#x[0-9a-fA-F]+);)/;
|
|
32
|
+
/** Why an SVG can't be served (a tag outside the set, a script hook, a bare `&`), or null. */
|
|
33
|
+
export function svgProblem(text) {
|
|
34
|
+
const unsafe = UNSAFE_SVG.find(re => re.test(text));
|
|
35
|
+
if (unsafe)
|
|
36
|
+
return `matches ${unsafe.source}`;
|
|
37
|
+
if (BARE_AMPERSAND.test(text))
|
|
38
|
+
return 'has a bare &';
|
|
39
|
+
for (const m of text.matchAll(/<\/?([a-zA-Z][\w:.-]*)/g)) {
|
|
40
|
+
const tag = m[1] ?? '';
|
|
41
|
+
if (!SVG_TAGS.has(tag))
|
|
42
|
+
return `has a <${tag}> tag`;
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
function readJson(file, schema) {
|
|
47
|
+
let raw;
|
|
48
|
+
try {
|
|
49
|
+
raw = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
return `unreadable (${e instanceof Error ? e.message : String(e)})`;
|
|
53
|
+
}
|
|
54
|
+
const parsed = schema.safeParse(raw);
|
|
55
|
+
if (parsed.success)
|
|
56
|
+
return parsed.data;
|
|
57
|
+
return parsed.error.issues.map(i => `${i.path.join('.')} ${i.message}`).join('; ');
|
|
58
|
+
}
|
|
59
|
+
const entriesOf = (dir) => fs.readdirSync(dir, { withFileTypes: true });
|
|
60
|
+
/** Why a game's maps can't be served (an unsafe SVG, a layer naming one that isn't there), or null. */
|
|
61
|
+
function mapsProblem(dir, manifest) {
|
|
62
|
+
const mapsDir = path.join(dir, 'maps');
|
|
63
|
+
const maps = fs.existsSync(mapsDir) ? entriesOf(mapsDir) : [];
|
|
64
|
+
for (const e of maps) {
|
|
65
|
+
if (!e.isFile() || !e.name.endsWith('.svg'))
|
|
66
|
+
return `unexpected maps/${e.name}`;
|
|
67
|
+
const problem = svgProblem(fs.readFileSync(path.join(mapsDir, e.name), 'utf8'));
|
|
68
|
+
if (problem)
|
|
69
|
+
return `maps/${e.name} ${problem}`;
|
|
70
|
+
}
|
|
71
|
+
const svgs = new Set(maps.map(e => `games/${manifest.gameId}/maps/${e.name}`));
|
|
72
|
+
for (const [locationId, location] of Object.entries(manifest.locations)) {
|
|
73
|
+
const missing = location.map?.layers.find(layer => !svgs.has(layer.svg));
|
|
74
|
+
if (missing) {
|
|
75
|
+
return `${locationId}'s layer ${missing.id} names ${missing.svg}, which isn't in its maps/`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
/** Why one game's folder can't be served, or null. */
|
|
81
|
+
function gameProblem(gamesDir, gameId) {
|
|
82
|
+
const dir = path.join(gamesDir, gameId);
|
|
83
|
+
const stray = entriesOf(dir)
|
|
84
|
+
.filter(e => e.isDirectory() ? e.name !== 'maps' : !['manifest.json', 'hints.json'].includes(e.name))
|
|
85
|
+
.map(e => e.name);
|
|
86
|
+
if (stray.length)
|
|
87
|
+
return `unexpected ${stray.join(', ')}`;
|
|
88
|
+
const manifest = readJson(path.join(dir, 'manifest.json'), GameManifestSchema);
|
|
89
|
+
if (typeof manifest === 'string')
|
|
90
|
+
return `manifest.json: ${manifest}`;
|
|
91
|
+
if (manifest.gameId !== gameId)
|
|
92
|
+
return `manifest.json says it is ${manifest.gameId}`;
|
|
93
|
+
if (fs.existsSync(path.join(dir, 'hints.json'))) {
|
|
94
|
+
const hints = readJson(path.join(dir, 'hints.json'), HintGraphSchema);
|
|
95
|
+
if (typeof hints === 'string')
|
|
96
|
+
return `hints.json: ${hints}`;
|
|
97
|
+
if (hints.gameId !== gameId)
|
|
98
|
+
return `hints.json says it is ${hints.gameId}`;
|
|
99
|
+
}
|
|
100
|
+
return mapsProblem(dir, manifest);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The games a built (or source) plugin folder carries registry data for, or why it can't be used:
|
|
104
|
+
* a game its manifest doesn't list, a file that fails its schema, an SVG outside the safe set.
|
|
105
|
+
*/
|
|
106
|
+
export function inspectPluginRegistry(dir, manifest) {
|
|
107
|
+
const root = path.join(dir, REGISTRY_DIR);
|
|
108
|
+
if (!fs.existsSync(root))
|
|
109
|
+
return { games: [] };
|
|
110
|
+
const stray = entriesOf(root)
|
|
111
|
+
.filter(e => !(e.isDirectory() && e.name === 'games'))
|
|
112
|
+
.map(e => e.name);
|
|
113
|
+
if (stray.length)
|
|
114
|
+
return `registry: unexpected ${stray.join(', ')}`;
|
|
115
|
+
const gamesDir = path.join(root, 'games');
|
|
116
|
+
const listed = new Set(manifest.games.map(g => g.id));
|
|
117
|
+
const games = [];
|
|
118
|
+
for (const e of entriesOf(gamesDir)) {
|
|
119
|
+
if (!e.isDirectory())
|
|
120
|
+
return `registry: unexpected games/${e.name}`;
|
|
121
|
+
if (!listed.has(e.name)) {
|
|
122
|
+
return `registry: carries ${e.name}, which its manifest doesn't list`;
|
|
123
|
+
}
|
|
124
|
+
const problem = gameProblem(gamesDir, e.name);
|
|
125
|
+
if (problem)
|
|
126
|
+
return `registry/games/${e.name}: ${problem}`;
|
|
127
|
+
games.push(e.name);
|
|
128
|
+
}
|
|
129
|
+
return { games: games.sort() };
|
|
130
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './views.js';
|
|
|
11
11
|
export * from './bytes.js';
|
|
12
12
|
export * from './navigation.js';
|
|
13
13
|
export * from './plugin-manifest.js';
|
|
14
|
+
export * from './plugin-permissions.js';
|
|
14
15
|
export * from './sandbox-protocol.js';
|
|
15
16
|
export * from './assets.js';
|
|
16
17
|
export * from './plugins-api.js';
|
package/lib/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export * from './views.js';
|
|
|
11
11
|
export * from './bytes.js';
|
|
12
12
|
export * from './navigation.js';
|
|
13
13
|
export * from './plugin-manifest.js';
|
|
14
|
+
export * from './plugin-permissions.js';
|
|
14
15
|
export * from './sandbox-protocol.js';
|
|
15
16
|
export * from './assets.js';
|
|
16
17
|
export * from './plugins-api.js';
|
package/lib/pack.d.ts
CHANGED
|
@@ -990,7 +990,7 @@ export declare const PackDataSchema: z.ZodObject<{
|
|
|
990
990
|
}>;
|
|
991
991
|
export type PackData = z.infer<typeof PackDataSchema>;
|
|
992
992
|
/**
|
|
993
|
-
* Everything about one game, as a plugin exports it
|
|
993
|
+
* Everything about one game, as a plugin exports it from its live.ts: its data, plus code the
|
|
994
994
|
* daemon runs over the live state to produce `PackViews`.
|
|
995
995
|
*/
|
|
996
996
|
export interface GamePack extends PackData {
|
package/lib/plugin/contract.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export interface BuildSupport {
|
|
|
43
43
|
region: string;
|
|
44
44
|
ramAnchor?: N64RamAnchor;
|
|
45
45
|
}
|
|
46
|
-
/** A memory-read state source for one game.
|
|
46
|
+
/** A memory-read state source for one game. A plugin lists its sources in its live.ts. */
|
|
47
47
|
export interface GamePlugin {
|
|
48
48
|
readonly gameId: string;
|
|
49
49
|
readonly stateSchemaVersion: number;
|
|
@@ -73,7 +73,8 @@ export interface PluginSession {
|
|
|
73
73
|
/**
|
|
74
74
|
* Builds a game's assets from the player's files, one at a time, in the core's sandbox. The core
|
|
75
75
|
* makes one instance per run (so it can keep parsed files between assets), hands in the files it
|
|
76
|
-
* opened
|
|
76
|
+
* opened (the game's declared downloads among them, as `downloads/<id>`), and writes and
|
|
77
|
+
* validates whatever comes back (docs/plugin-architecture.md).
|
|
77
78
|
*/
|
|
78
79
|
export interface AssetExtractor {
|
|
79
80
|
/** what can be built from these files: cheap, no heavy parsing */
|
|
@@ -81,32 +82,6 @@ export interface AssetExtractor {
|
|
|
81
82
|
/** one asset's outputs: data in the sdk's shapes, never files */
|
|
82
83
|
buildAsset(id: string, inputs: readonly InputFile[]): AssetOutput[];
|
|
83
84
|
}
|
|
84
|
-
/** A Python-based extraction (the Zelda map renderer, until it's ported): what to run. */
|
|
85
|
-
export type PythonExtractPlan = {
|
|
86
|
-
kind: 'error';
|
|
87
|
-
message: string;
|
|
88
|
-
} | {
|
|
89
|
-
kind: 'run';
|
|
90
|
-
gameId: string;
|
|
91
|
-
pythonArgs: string[];
|
|
92
|
-
playerArgs: string[];
|
|
93
|
-
outDir: string;
|
|
94
|
-
};
|
|
95
|
-
export interface PythonExtract {
|
|
96
|
-
/** the games it extracts */
|
|
97
|
-
games: readonly string[];
|
|
98
|
-
plan(args: readonly string[], paths: {
|
|
99
|
-
script: string;
|
|
100
|
-
registryDir: string;
|
|
101
|
-
localAssetsDir: string;
|
|
102
|
-
}): PythonExtractPlan;
|
|
103
|
-
/** a game's step after the renderer succeeded */
|
|
104
|
-
after: ReadonlyMap<string, (ctx: {
|
|
105
|
-
args: readonly string[];
|
|
106
|
-
outDir: string;
|
|
107
|
-
extractorScript: string;
|
|
108
|
-
}) => Promise<void>>;
|
|
109
|
-
}
|
|
110
85
|
/**
|
|
111
86
|
* What a plugin's live code exports (its default export): the packs and memory sources for the
|
|
112
87
|
* games it covers. It runs in the core's sandbox, built with `exposeToHost`, so it may use no Node
|
|
@@ -125,21 +100,3 @@ export interface PluginAssetsModule {
|
|
|
125
100
|
/** a new extractor for each run, by game id */
|
|
126
101
|
extractors: ReadonlyMap<string, () => AssetExtractor>;
|
|
127
102
|
}
|
|
128
|
-
/**
|
|
129
|
-
* The Python map renderer's hooks (the Zelda ports). Still unsandboxed, with Node, until the
|
|
130
|
-
* renderer is ported and those games get an AssetExtractor.
|
|
131
|
-
*/
|
|
132
|
-
/** What a game's after-assets step gets: where its assets were written. */
|
|
133
|
-
export interface AfterAssetsContext {
|
|
134
|
-
outDir: string;
|
|
135
|
-
}
|
|
136
|
-
export interface PluginExtractModule {
|
|
137
|
-
/** must equal the manifest's id */
|
|
138
|
-
id: string;
|
|
139
|
-
/** @deprecated the Python map renderer is gone (GameSlate builds assets in the sandbox);
|
|
140
|
-
* kept so plugins built against older sdk versions still load */
|
|
141
|
-
pythonExtract?: PythonExtract;
|
|
142
|
-
/** per game: a step after its extraction job, unsandboxed (e.g. notes built from data fetched
|
|
143
|
-
* over the network); it must not fail the extraction when it can't run */
|
|
144
|
-
afterAssets?: ReadonlyMap<string, (ctx: AfterAssetsContext) => Promise<void>>;
|
|
145
|
-
}
|
package/lib/plugin-manifest.d.ts
CHANGED
|
@@ -2,13 +2,55 @@ import { z } from 'zod';
|
|
|
2
2
|
/**
|
|
3
3
|
* The plugin contract this core speaks; a plugin built for another can't work.
|
|
4
4
|
* 2: `code` is a sandbox script built with `exposeToHost`, and extractors are a separate file.
|
|
5
|
-
* 3: asset extractors are a sandbox script (`assets`, `exposeAssetsToHost`)
|
|
6
|
-
* the
|
|
5
|
+
* 3: asset extractors are a sandbox script (`assets`, `exposeAssetsToHost`). Since sdk 0.3.19 no
|
|
6
|
+
* plugin code runs outside the sandbox: `extract` is gone, and data from the web comes in as
|
|
7
|
+
* declared `downloads`.
|
|
7
8
|
*/
|
|
8
9
|
export declare const SDK_API = 3;
|
|
10
|
+
/** A plugin or game id. `constructor` passes it: records keyed by id use `Object.hasOwn`. */
|
|
11
|
+
export declare const PluginIdSchema: z.ZodString;
|
|
9
12
|
/** Why a manifest may not offer `folder`, or null. */
|
|
10
13
|
export declare function homeFolderProblem(folder: string): string | null;
|
|
11
|
-
export declare const
|
|
14
|
+
export declare const Sha256Schema: z.ZodString;
|
|
15
|
+
/** Why `raw` can't be a download's URL, or null. */
|
|
16
|
+
export declare function downloadUrlProblem(raw: string): string | null;
|
|
17
|
+
/**
|
|
18
|
+
* A file from the web an asset job needs (a port's source tarball at a pinned commit): the core fetches it
|
|
19
|
+
* when a job runs, checks its sha256, caches it and hands it to the asset code as the input
|
|
20
|
+
* `downloads/<id>`. Each one is a permission the player sees.
|
|
21
|
+
*/
|
|
22
|
+
export declare const PluginDownloadSchema: z.ZodObject<{
|
|
23
|
+
id: z.ZodString;
|
|
24
|
+
url: z.ZodEffects<z.ZodString, string, string>;
|
|
25
|
+
sha256: z.ZodString;
|
|
26
|
+
}, "strict", z.ZodTypeAny, {
|
|
27
|
+
id: string;
|
|
28
|
+
url: string;
|
|
29
|
+
sha256: string;
|
|
30
|
+
}, {
|
|
31
|
+
id: string;
|
|
32
|
+
url: string;
|
|
33
|
+
sha256: string;
|
|
34
|
+
}>;
|
|
35
|
+
export type PluginDownload = z.infer<typeof PluginDownloadSchema>;
|
|
36
|
+
/** The input name a download reaches the asset code under. */
|
|
37
|
+
export declare const downloadInputName: (id: string) => string;
|
|
38
|
+
/** major.minor.patch, the only form `compareVersions` orders. */
|
|
39
|
+
export declare const PluginVersionSchema: z.ZodString;
|
|
40
|
+
/** The release zip a published manifest names: its URL (absolute, or relative to the URL the
|
|
41
|
+
* player gave for the manifest, as `gameslate-plugin build --release` writes it) and its sha256. */
|
|
42
|
+
export declare const PluginBundleSchema: z.ZodObject<{
|
|
43
|
+
url: z.ZodString;
|
|
44
|
+
sha256: z.ZodString;
|
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
|
46
|
+
url: string;
|
|
47
|
+
sha256: string;
|
|
48
|
+
}, {
|
|
49
|
+
url: string;
|
|
50
|
+
sha256: string;
|
|
51
|
+
}>;
|
|
52
|
+
export type PluginBundle = z.infer<typeof PluginBundleSchema>;
|
|
53
|
+
export declare const PluginManifestSchema: z.ZodEffects<z.ZodObject<{
|
|
12
54
|
id: z.ZodString;
|
|
13
55
|
name: z.ZodString;
|
|
14
56
|
version: z.ZodString;
|
|
@@ -37,18 +79,6 @@ export declare const PluginManifestSchema: z.ZodObject<{
|
|
|
37
79
|
file: string;
|
|
38
80
|
sha256: string;
|
|
39
81
|
}>>;
|
|
40
|
-
/** steps that run unsandboxed after a game's extraction job (e.g. data fetched over the
|
|
41
|
-
* network); the Python renderer's hooks lived here too */
|
|
42
|
-
extract: z.ZodOptional<z.ZodObject<{
|
|
43
|
-
file: z.ZodString;
|
|
44
|
-
sha256: z.ZodString;
|
|
45
|
-
}, "strip", z.ZodTypeAny, {
|
|
46
|
-
file: string;
|
|
47
|
-
sha256: string;
|
|
48
|
-
}, {
|
|
49
|
-
file: string;
|
|
50
|
-
sha256: string;
|
|
51
|
-
}>>;
|
|
52
82
|
games: z.ZodArray<z.ZodObject<{
|
|
53
83
|
id: z.ZodString;
|
|
54
84
|
title: z.ZodString;
|
|
@@ -70,7 +100,29 @@ export declare const PluginManifestSchema: z.ZodObject<{
|
|
|
70
100
|
folders: string[];
|
|
71
101
|
subfolders?: string[] | undefined;
|
|
72
102
|
}>, "many">>;
|
|
73
|
-
|
|
103
|
+
/** files from the web its asset code reads (fetched only when a job runs) */
|
|
104
|
+
downloads: z.ZodDefault<z.ZodEffects<z.ZodArray<z.ZodObject<{
|
|
105
|
+
id: z.ZodString;
|
|
106
|
+
url: z.ZodEffects<z.ZodString, string, string>;
|
|
107
|
+
sha256: z.ZodString;
|
|
108
|
+
}, "strict", z.ZodTypeAny, {
|
|
109
|
+
id: string;
|
|
110
|
+
url: string;
|
|
111
|
+
sha256: string;
|
|
112
|
+
}, {
|
|
113
|
+
id: string;
|
|
114
|
+
url: string;
|
|
115
|
+
sha256: string;
|
|
116
|
+
}>, "many">, {
|
|
117
|
+
id: string;
|
|
118
|
+
url: string;
|
|
119
|
+
sha256: string;
|
|
120
|
+
}[], {
|
|
121
|
+
id: string;
|
|
122
|
+
url: string;
|
|
123
|
+
sha256: string;
|
|
124
|
+
}[]>>;
|
|
125
|
+
}, "strict", z.ZodTypeAny, {
|
|
74
126
|
id: string;
|
|
75
127
|
title: string;
|
|
76
128
|
inputs: {
|
|
@@ -78,6 +130,11 @@ export declare const PluginManifestSchema: z.ZodObject<{
|
|
|
78
130
|
folders: string[];
|
|
79
131
|
subfolders?: string[] | undefined;
|
|
80
132
|
}[];
|
|
133
|
+
downloads: {
|
|
134
|
+
id: string;
|
|
135
|
+
url: string;
|
|
136
|
+
sha256: string;
|
|
137
|
+
}[];
|
|
81
138
|
aliases?: string[] | undefined;
|
|
82
139
|
}, {
|
|
83
140
|
id: string;
|
|
@@ -88,14 +145,35 @@ export declare const PluginManifestSchema: z.ZodObject<{
|
|
|
88
145
|
folders: string[];
|
|
89
146
|
subfolders?: string[] | undefined;
|
|
90
147
|
}[] | undefined;
|
|
148
|
+
downloads?: {
|
|
149
|
+
id: string;
|
|
150
|
+
url: string;
|
|
151
|
+
sha256: string;
|
|
152
|
+
}[] | undefined;
|
|
91
153
|
}>, "many">;
|
|
92
|
-
|
|
154
|
+
/** only in a published manifest (`manifest.json` beside the release zip, which a player adds
|
|
155
|
+
* by URL): the zip it describes. The manifest inside the zip has none, since it can't carry
|
|
156
|
+
* its own zip's hash. */
|
|
157
|
+
bundle: z.ZodOptional<z.ZodObject<{
|
|
158
|
+
url: z.ZodString;
|
|
159
|
+
sha256: z.ZodString;
|
|
160
|
+
}, "strip", z.ZodTypeAny, {
|
|
161
|
+
url: string;
|
|
162
|
+
sha256: string;
|
|
163
|
+
}, {
|
|
164
|
+
url: string;
|
|
165
|
+
sha256: string;
|
|
166
|
+
}>>;
|
|
167
|
+
}, "strict", z.ZodTypeAny, {
|
|
93
168
|
code: {
|
|
94
169
|
file: string;
|
|
95
170
|
sha256: string;
|
|
96
171
|
};
|
|
97
172
|
id: string;
|
|
98
173
|
name: string;
|
|
174
|
+
version: string;
|
|
175
|
+
sdkApi: number;
|
|
176
|
+
testedWith: string[];
|
|
99
177
|
games: {
|
|
100
178
|
id: string;
|
|
101
179
|
title: string;
|
|
@@ -104,17 +182,19 @@ export declare const PluginManifestSchema: z.ZodObject<{
|
|
|
104
182
|
folders: string[];
|
|
105
183
|
subfolders?: string[] | undefined;
|
|
106
184
|
}[];
|
|
185
|
+
downloads: {
|
|
186
|
+
id: string;
|
|
187
|
+
url: string;
|
|
188
|
+
sha256: string;
|
|
189
|
+
}[];
|
|
107
190
|
aliases?: string[] | undefined;
|
|
108
191
|
}[];
|
|
109
|
-
|
|
110
|
-
sdkApi: number;
|
|
111
|
-
testedWith: string[];
|
|
112
|
-
extract?: {
|
|
192
|
+
assets?: {
|
|
113
193
|
file: string;
|
|
114
194
|
sha256: string;
|
|
115
195
|
} | undefined;
|
|
116
|
-
|
|
117
|
-
|
|
196
|
+
bundle?: {
|
|
197
|
+
url: string;
|
|
118
198
|
sha256: string;
|
|
119
199
|
} | undefined;
|
|
120
200
|
}, {
|
|
@@ -124,6 +204,8 @@ export declare const PluginManifestSchema: z.ZodObject<{
|
|
|
124
204
|
};
|
|
125
205
|
id: string;
|
|
126
206
|
name: string;
|
|
207
|
+
version: string;
|
|
208
|
+
sdkApi: number;
|
|
127
209
|
games: {
|
|
128
210
|
id: string;
|
|
129
211
|
title: string;
|
|
@@ -133,17 +215,86 @@ export declare const PluginManifestSchema: z.ZodObject<{
|
|
|
133
215
|
folders: string[];
|
|
134
216
|
subfolders?: string[] | undefined;
|
|
135
217
|
}[] | undefined;
|
|
218
|
+
downloads?: {
|
|
219
|
+
id: string;
|
|
220
|
+
url: string;
|
|
221
|
+
sha256: string;
|
|
222
|
+
}[] | undefined;
|
|
136
223
|
}[];
|
|
224
|
+
assets?: {
|
|
225
|
+
file: string;
|
|
226
|
+
sha256: string;
|
|
227
|
+
} | undefined;
|
|
228
|
+
testedWith?: string[] | undefined;
|
|
229
|
+
bundle?: {
|
|
230
|
+
url: string;
|
|
231
|
+
sha256: string;
|
|
232
|
+
} | undefined;
|
|
233
|
+
}>, {
|
|
234
|
+
code: {
|
|
235
|
+
file: string;
|
|
236
|
+
sha256: string;
|
|
237
|
+
};
|
|
238
|
+
id: string;
|
|
239
|
+
name: string;
|
|
137
240
|
version: string;
|
|
138
241
|
sdkApi: number;
|
|
139
|
-
|
|
242
|
+
testedWith: string[];
|
|
243
|
+
games: {
|
|
244
|
+
id: string;
|
|
245
|
+
title: string;
|
|
246
|
+
inputs: {
|
|
247
|
+
label: string;
|
|
248
|
+
folders: string[];
|
|
249
|
+
subfolders?: string[] | undefined;
|
|
250
|
+
}[];
|
|
251
|
+
downloads: {
|
|
252
|
+
id: string;
|
|
253
|
+
url: string;
|
|
254
|
+
sha256: string;
|
|
255
|
+
}[];
|
|
256
|
+
aliases?: string[] | undefined;
|
|
257
|
+
}[];
|
|
258
|
+
assets?: {
|
|
140
259
|
file: string;
|
|
141
260
|
sha256: string;
|
|
142
261
|
} | undefined;
|
|
262
|
+
bundle?: {
|
|
263
|
+
url: string;
|
|
264
|
+
sha256: string;
|
|
265
|
+
} | undefined;
|
|
266
|
+
}, {
|
|
267
|
+
code: {
|
|
268
|
+
file: string;
|
|
269
|
+
sha256: string;
|
|
270
|
+
};
|
|
271
|
+
id: string;
|
|
272
|
+
name: string;
|
|
273
|
+
version: string;
|
|
274
|
+
sdkApi: number;
|
|
275
|
+
games: {
|
|
276
|
+
id: string;
|
|
277
|
+
title: string;
|
|
278
|
+
aliases?: string[] | undefined;
|
|
279
|
+
inputs?: {
|
|
280
|
+
label: string;
|
|
281
|
+
folders: string[];
|
|
282
|
+
subfolders?: string[] | undefined;
|
|
283
|
+
}[] | undefined;
|
|
284
|
+
downloads?: {
|
|
285
|
+
id: string;
|
|
286
|
+
url: string;
|
|
287
|
+
sha256: string;
|
|
288
|
+
}[] | undefined;
|
|
289
|
+
}[];
|
|
143
290
|
assets?: {
|
|
144
291
|
file: string;
|
|
145
292
|
sha256: string;
|
|
146
293
|
} | undefined;
|
|
147
294
|
testedWith?: string[] | undefined;
|
|
295
|
+
bundle?: {
|
|
296
|
+
url: string;
|
|
297
|
+
sha256: string;
|
|
298
|
+
} | undefined;
|
|
148
299
|
}>;
|
|
149
300
|
export type PluginManifest = z.infer<typeof PluginManifestSchema>;
|
package/lib/plugin-manifest.js
CHANGED
|
@@ -7,13 +7,16 @@ import { z } from 'zod';
|
|
|
7
7
|
/**
|
|
8
8
|
* The plugin contract this core speaks; a plugin built for another can't work.
|
|
9
9
|
* 2: `code` is a sandbox script built with `exposeToHost`, and extractors are a separate file.
|
|
10
|
-
* 3: asset extractors are a sandbox script (`assets`, `exposeAssetsToHost`)
|
|
11
|
-
* the
|
|
10
|
+
* 3: asset extractors are a sandbox script (`assets`, `exposeAssetsToHost`). Since sdk 0.3.19 no
|
|
11
|
+
* plugin code runs outside the sandbox: `extract` is gone, and data from the web comes in as
|
|
12
|
+
* declared `downloads`.
|
|
12
13
|
*/
|
|
13
14
|
export const SDK_API = 3;
|
|
14
|
-
|
|
15
|
+
/** A plugin or game id. `constructor` passes it: records keyed by id use `Object.hasOwn`. */
|
|
16
|
+
export const PluginIdSchema = z
|
|
15
17
|
.string()
|
|
16
18
|
.regex(/^[a-z0-9][a-z0-9-]*$/, 'plugin and game ids are lower-case words and dashes');
|
|
19
|
+
const Id = PluginIdSchema;
|
|
17
20
|
/* a file next to the manifest, never a path out of the plugin's folder */
|
|
18
21
|
const FileName = z.string().regex(/^[A-Za-z0-9_][A-Za-z0-9_.-]*$/, 'a plain file name');
|
|
19
22
|
/* Hidden folders where games live; any other (`~/.ssh`, `~/.config/gameslate` with the pairing
|
|
@@ -50,14 +53,71 @@ const InputLocation = z.object({
|
|
|
50
53
|
* (e.g. a port's `mods`) */
|
|
51
54
|
subfolders: z.array(FileName).max(10).optional(),
|
|
52
55
|
});
|
|
56
|
+
export const Sha256Schema = z.string().regex(/^[0-9a-f]{64}$/, 'a sha256 in lower-case hex');
|
|
57
|
+
const Sha256 = Sha256Schema;
|
|
58
|
+
/* An exact https URL, the same string a browser would show for it: no templates, no credentials,
|
|
59
|
+
* so nothing but the manifest decides what is fetched. Whether the host is public is checked
|
|
60
|
+
* when it is fetched (each redirect too). */
|
|
61
|
+
const DownloadUrl = z
|
|
62
|
+
.string()
|
|
63
|
+
.max(2000)
|
|
64
|
+
.superRefine((raw, ctx) => {
|
|
65
|
+
const problem = downloadUrlProblem(raw);
|
|
66
|
+
if (problem)
|
|
67
|
+
ctx.addIssue({ code: 'custom', message: problem });
|
|
68
|
+
});
|
|
69
|
+
/** Why `raw` can't be a download's URL, or null. */
|
|
70
|
+
export function downloadUrlProblem(raw) {
|
|
71
|
+
let url;
|
|
72
|
+
try {
|
|
73
|
+
url = new URL(raw);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return 'not a URL';
|
|
77
|
+
}
|
|
78
|
+
if (url.protocol !== 'https:')
|
|
79
|
+
return 'a download is fetched over https only';
|
|
80
|
+
if (url.username || url.password)
|
|
81
|
+
return 'a download URL carries no credentials';
|
|
82
|
+
if (/[{}]|%7b|%7d/i.test(raw))
|
|
83
|
+
return 'a download URL is exact: no templates';
|
|
84
|
+
if (url.href !== raw)
|
|
85
|
+
return `a download URL is written exactly as ${url.href}`;
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A file from the web an asset job needs (a port's source tarball at a pinned commit): the core fetches it
|
|
90
|
+
* when a job runs, checks its sha256, caches it and hands it to the asset code as the input
|
|
91
|
+
* `downloads/<id>`. Each one is a permission the player sees.
|
|
92
|
+
*/
|
|
93
|
+
export const PluginDownloadSchema = z
|
|
94
|
+
.object({
|
|
95
|
+
id: PluginIdSchema,
|
|
96
|
+
url: DownloadUrl,
|
|
97
|
+
sha256: Sha256,
|
|
98
|
+
})
|
|
99
|
+
.strict();
|
|
100
|
+
/** The input name a download reaches the asset code under. */
|
|
101
|
+
export const downloadInputName = (id) => `downloads/${id}`;
|
|
53
102
|
const CodeFile = z.object({
|
|
54
103
|
file: FileName,
|
|
55
|
-
sha256:
|
|
104
|
+
sha256: Sha256,
|
|
105
|
+
});
|
|
106
|
+
/** major.minor.patch, the only form `compareVersions` orders. */
|
|
107
|
+
export const PluginVersionSchema = z
|
|
108
|
+
.string()
|
|
109
|
+
.regex(/^\d+\.\d+\.\d+$/, 'version is major.minor.patch');
|
|
110
|
+
/** The release zip a published manifest names: its URL (absolute, or relative to the URL the
|
|
111
|
+
* player gave for the manifest, as `gameslate-plugin build --release` writes it) and its sha256. */
|
|
112
|
+
export const PluginBundleSchema = z.object({
|
|
113
|
+
url: z.string().min(1).max(2000),
|
|
114
|
+
sha256: Sha256,
|
|
56
115
|
});
|
|
57
|
-
export const PluginManifestSchema = z
|
|
116
|
+
export const PluginManifestSchema = z
|
|
117
|
+
.object({
|
|
58
118
|
id: Id,
|
|
59
119
|
name: z.string().min(1),
|
|
60
|
-
version:
|
|
120
|
+
version: PluginVersionSchema,
|
|
61
121
|
sdkApi: z.number().int().positive(),
|
|
62
122
|
/** core versions it was tested with; outside them it still loads, with a warning */
|
|
63
123
|
testedWith: z.array(z.string()).default([]),
|
|
@@ -65,17 +125,34 @@ export const PluginManifestSchema = z.object({
|
|
|
65
125
|
code: CodeFile,
|
|
66
126
|
/** asset extractors, run in the core's sandbox by extraction jobs */
|
|
67
127
|
assets: CodeFile.optional(),
|
|
68
|
-
/** steps that run unsandboxed after a game's extraction job (e.g. data fetched over the
|
|
69
|
-
* network); the Python renderer's hooks lived here too */
|
|
70
|
-
extract: CodeFile.optional(),
|
|
71
128
|
games: z
|
|
72
|
-
.array(z
|
|
129
|
+
.array(z
|
|
130
|
+
.object({
|
|
73
131
|
id: Id,
|
|
74
132
|
title: z.string().min(1),
|
|
75
133
|
/** short names a player may type for it (`gameslate extract-assets oot`) */
|
|
76
134
|
aliases: z.array(Id).max(5).optional(),
|
|
77
135
|
/** where the player's own files for asset extraction usually are */
|
|
78
136
|
inputs: z.array(InputLocation).default([]),
|
|
79
|
-
|
|
137
|
+
/** files from the web its asset code reads (fetched only when a job runs) */
|
|
138
|
+
downloads: z
|
|
139
|
+
.array(PluginDownloadSchema)
|
|
140
|
+
.max(20)
|
|
141
|
+
.refine(ds => new Set(ds.map(d => d.id)).size === ds.length, "a game's download ids are unique")
|
|
142
|
+
.default([]),
|
|
143
|
+
})
|
|
144
|
+
/* a misspelt key (`download`) is refused, not dropped with what it declared */
|
|
145
|
+
.strict())
|
|
80
146
|
.min(1),
|
|
147
|
+
/** only in a published manifest (`manifest.json` beside the release zip, which a player adds
|
|
148
|
+
* by URL): the zip it describes. The manifest inside the zip has none, since it can't carry
|
|
149
|
+
* its own zip's hash. */
|
|
150
|
+
bundle: PluginBundleSchema.optional(),
|
|
151
|
+
})
|
|
152
|
+
/* strict: a key this core doesn't know (an older contract's `extract`, code that ran outside
|
|
153
|
+
* the sandbox) is refused, not silently dropped */
|
|
154
|
+
.strict()
|
|
155
|
+
.refine(m => m.assets || m.games.every(g => g.downloads.length === 0), {
|
|
156
|
+
message: 'downloads are read only by asset code: a plugin with downloads needs assets',
|
|
157
|
+
path: ['games'],
|
|
81
158
|
});
|