@vestra-player/sdk 1.7.20 → 1.9.0

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.
Files changed (96) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/README.md +2 -2
  3. package/bin/vestra-plugin.mjs +139 -100
  4. package/capability-scan.json +369 -0
  5. package/dist/api-requests.d.ts +11 -36
  6. package/dist/api-requests.js +22 -47
  7. package/dist/capability-scan.d.ts +95 -0
  8. package/dist/capability-scan.js +249 -0
  9. package/dist/commands.d.ts +35 -0
  10. package/dist/commands.js +42 -1
  11. package/dist/docs-tree.json.gz +0 -0
  12. package/dist/docs.d.ts +1 -1
  13. package/dist/docs.js +1 -1
  14. package/dist/index.d.ts +4 -5
  15. package/dist/manifest.d.ts +5 -0
  16. package/dist/manifest.js +9 -24
  17. package/dist/member-uses.d.ts +61 -0
  18. package/dist/member-uses.js +160 -0
  19. package/dist/mpv.d.ts +139 -0
  20. package/dist/mpv.js +496 -0
  21. package/dist/player-runtime.d.ts +3 -3
  22. package/dist/player-runtime.js +3 -3
  23. package/dist/plugin/appearance.d.ts +1 -1
  24. package/dist/plugin/appearance.js +2 -2
  25. package/dist/plugin/bindings.d.ts +1 -1
  26. package/dist/plugin/bindings.js +2 -2
  27. package/dist/plugin/commands.js +6 -14
  28. package/dist/plugin/connection.d.ts +26 -7
  29. package/dist/plugin/connection.js +68 -36
  30. package/dist/plugin/drops.js +1 -1
  31. package/dist/plugin/index.js +9 -15
  32. package/dist/plugin/media.js +0 -12
  33. package/dist/plugin/mpv.d.ts +3 -0
  34. package/dist/plugin/mpv.js +91 -0
  35. package/dist/plugin/packages.js +1 -2
  36. package/dist/plugin/player/events.d.ts +4 -3
  37. package/dist/plugin/player/events.js +7 -6
  38. package/dist/plugin/player.d.ts +21 -13
  39. package/dist/plugin/player.js +56 -21
  40. package/dist/plugin/scope.d.ts +1 -0
  41. package/dist/plugin/scope.js +2 -0
  42. package/dist/plugin/services.d.ts +4 -4
  43. package/dist/plugin/services.js +7 -29
  44. package/dist/plugin/settings.js +1 -1
  45. package/dist/plugin/shaders.js +0 -2
  46. package/dist/plugin/stream.d.ts +2 -1
  47. package/dist/plugin/stream.js +2 -2
  48. package/dist/plugin/testing/commands.d.ts +3 -10
  49. package/dist/plugin/testing/commands.js +43 -24
  50. package/dist/plugin/testing/index.d.ts +75 -114
  51. package/dist/plugin/testing/index.js +83 -102
  52. package/dist/plugin/testing/mpv.d.ts +7 -0
  53. package/dist/plugin/testing/mpv.js +90 -0
  54. package/dist/plugin/testing/processing.js +1 -1
  55. package/dist/plugin/testing/services.js +0 -1
  56. package/dist/plugin/timeline.d.ts +2 -3
  57. package/dist/plugin/timeline.js +4 -8
  58. package/dist/plugin/types/base.d.ts +49 -88
  59. package/dist/plugin/types/commands.d.ts +44 -77
  60. package/dist/plugin/types/packages.d.ts +17 -55
  61. package/dist/plugin/types/playback.d.ts +302 -135
  62. package/dist/plugin/types/plugin-wire.d.ts +6 -36
  63. package/dist/plugin/types/processing.d.ts +10 -49
  64. package/dist/plugin/types/services.d.ts +11 -70
  65. package/dist/plugin/types/snapshots.d.ts +7 -60
  66. package/dist/plugin/types/sources.d.ts +2 -11
  67. package/dist/plugin/types/subtitles.d.ts +5 -26
  68. package/dist/plugin/types/ui-content.d.ts +1 -16
  69. package/dist/plugin/types/ui-layout.d.ts +53 -79
  70. package/dist/plugin/types/ui-locale.d.ts +5 -23
  71. package/dist/plugin/types/ui-shell.d.ts +13 -59
  72. package/dist/plugin/view/layout.js +1 -1
  73. package/dist/plugin/view.js +0 -2
  74. package/dist/plugin/window.d.ts +1 -1
  75. package/dist/plugin/window.js +1 -1
  76. package/dist/plugin/wire-facade.js +1 -2
  77. package/dist/processing.d.ts +2 -3
  78. package/dist/protocol.d.ts +14 -0
  79. package/dist/protocol.js +14 -0
  80. package/dist/request-queue.js +1 -1
  81. package/dist/subtitles.d.ts +1 -1
  82. package/dist/ts-plugin.d.ts +8 -15
  83. package/dist/ts-plugin.js +3 -141
  84. package/dist/wire.d.ts +22 -12
  85. package/dist/wire.js +17 -8
  86. package/llms.txt +5 -5
  87. package/package.json +4 -3
  88. package/slint/vestra/widgets.slint +12 -4
  89. package/dist/capabilities.d.ts +0 -107
  90. package/dist/capabilities.js +0 -69
  91. package/dist/capability-check.d.ts +0 -133
  92. package/dist/capability-check.js +0 -371
  93. package/dist/capability-rules.d.ts +0 -125
  94. package/dist/capability-rules.js +0 -192
  95. package/dist/host-capabilities.d.ts +0 -10
  96. package/dist/host-capabilities.js +0 -477
package/CHANGELOG.md CHANGED
@@ -1,5 +1,77 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.9.0
4
+
5
+ **Who must change: every plugin with a `capabilities` field, and every plugin that follows the player's state.** Manifest capabilities are gone (user rulings 2026-11-13; plan `design/sdk-1.9/PLAN.md`, C2 and the SDK half of C3). A manifest says who the plugin is; what the store shows the user comes only from the capability scan of the code ([Capability scan](docs/reference/scan.md)). The two declarations that changed how a plugin ran are now calls, and nothing else is declared or checked. Needs player 0.9.0, which removes its gate in the same release; `apiVersion` stays `vestra/1`.
6
+
7
+ **Migration** (first lines of `activate`, then delete the field):
8
+
9
+ ```ts
10
+ export default async function activate(plugin: Plugin) {
11
+ plugin.player.subscribe(); // was "events"
12
+ await plugin.player.read(); // was "playback.read"
13
+ // …the rest unchanged
14
+ }
15
+ ```
16
+
17
+ Keep only the lines whose declaration the manifest had; a plugin that had neither adds nothing. Set `minPlayerVersion` to `0.9.0`: an older player requires the field. Remove `@vestra-player/sdk/ts-plugin` from `tsconfig.json`, `capabilities` from `startPlugin(…)` options in tests, and `--json` from `vestra-plugin check`.
18
+
19
+ **New: the explicit calls** (C2).
20
+
21
+ - **`plugin.player.subscribe()`** (sync, idempotent): turns on event delivery for this run and subscribes the state copy now. Until it is called, a listener of `source.state`, `playback.backend`, `window.state`, `timeline.changed`, `appearance.changed` or `resolvers.fileTypes` never runs, as without `events` before (the one-time warning in the log now names `subscribe()`); a listener added earlier starts to hear events at the call. The other events (`packages.changed`, `bindings.changed`, `commands.keys`, `video.upscaling.changed`, `video.motion.changed`) arrive from the first listener, as they did with their own declarations.
22
+ - **`await plugin.player.read()`** (idempotent; a failed read is tried again by the next call): reads `source.state` and `timeline.marks` and turns on the re-reads after the plugin's own actions (`host.run`, closing a `Media`, a stream's end), as `playback.read` did. Before it, `plugin.player.state` is the empty state. `subscribe()` after `read()` reads the state once more, since a change between the two sent no event.
23
+ - **Command keys and the layout state start on first use** (`plugin.commands.keys`, `plugin.panels.*.state`), with no declaration.
24
+ - **Wire order** (the one ruled shift): the start-up `window.state` read now comes first, because it is answered before `activate` begins; the player-state requests follow it, one round trip later. Proof: with the explicit calls first in `activate`, all 19 golden scenarios equal their declared traces after that one transformation (step 1 of this release, recorded on both paths before the declared one was removed; `test/explicit-calls.test.ts` keeps the request sequences); in this release the 14 traces it changes were regenerated (list below) and the others are byte-identical.
25
+
26
+ **Removed: everything that reads declarations** (C3, SDK half; no legacy path).
27
+
28
+ - **Manifest field `capabilities`**: an error everywhere the SDK reads a manifest (`vestra-plugin check`/`build`/`pack`, `startPlugin`), with a message that names the change and the two calls (`CAPABILITIES_REMOVED`). An error, not a warning, because the player refuses unknown manifest fields and an ignored list would leave a plugin that silently stops hearing events or reading the state; the message says exactly what to write instead.
29
+ - **Early refusals with `capability`** (`media.sources`, `playback.control` for `media.sources.open`, `mpv`, `secrets`, `rendering.manage`, `video.upscaling`, `video.motion`, `processing.video`, `timeline.marks`, `commands.run`, `palette.lead`): the calls are sent and the player answers. `capability` remains the player's (and `TestHost`'s) code for the built-in-only requests (`commands.list`, `commands.run`, `palette.lead.*`) from a plugin that is not built in.
30
+ - **`CAPABILITY_INFO` and `CapabilityInfo`** (`./testing`), **`CAPABILITIES`, `CAPABILITY_INFO`, `HOST_CAPABILITIES`** (`./runtime`), the copy of the player's capability table (`src/host-capabilities.ts`, `npm run capabilities:sync`), the capability checker and its rules, the `@capability` doc tag and the [Capabilities](https://vestrasys.github.io/vestra-player-sdk/documents/Reference.html) reference page.
31
+ - **`vestra-plugin check`**: no capability step; `--json` (which only reported it) fails with a message.
32
+ - **`@vestra-player/sdk/ts-plugin`**: no checker and no quick fix; the module stays as a no-op so that a `tsconfig.json` that lists it still loads (remove it; a later major removes the module).
33
+ - **`PluginInfo.capabilities`, `PackageManifest.capabilities`** and `TestHost.packages[].capabilities`.
34
+ - **`startPlugin`'s `capabilities` option.** `id` now means "start with this id and read no manifest".
35
+ - **`TestHost` `bindings.list`** lists a plugin's `focus: "panel"` commands without a `ui.mount` declaration to look at (player 0.8.0 left them out). Everything else in `TestHost` is unchanged.
36
+
37
+ **Player side: panels compile one by one, when first shown** (player 0.9.0; no API change). A panel shown at once (the bottom bar, the backdrop, the current tab of an open column) still compiles at the mount and rejects `ready` with `ui-prepare`; a tab mounted in the background compiles when it is first shown (an adjust tab when the column opens), and a failure then reaches `onError` as `ui-prepare`, the tab staying empty until the plugin mounts it again. Mounting or unmounting a panel no longer rebuilds the main window, so other panels keep their component state; a panel gets a new instance only when its place is made again (a column closed and opened, the fullscreen overlay, the floating sidebar) or after the player unloaded it (at most 4 loaded per column). Docs follow (`Panel`, `Panel.ready`, `ui-prepare`, the guides).
38
+
39
+ **Kept**: the capability scan and `capability-scan.json` (its test now covers every method the SDK sends instead of the removed table), `API_REQUESTS` (the message and event tables), the message and event reference pages (by area; the events table says which events wait for `subscribe()`).
40
+
41
+ **Golden traces regenerated** (the ruled `window.state` shift; nothing else differs): `builtins-info`, `builtins-playback`, `builtins-playlist`, `builtins-subtitles`, `builtins-video`, `examples-adjust-panel`, `examples-blur`, `examples-bookmark`, `examples-menus`, `examples-signal-generator`, `styles-speed-a`, `styles-speed-b`, `styles-speed-c`, `host-start-taken`. The 11 examples and the three style plugins were migrated (field deleted, the calls inserted, `minPlayerVersion` 0.9.0); built-ins at the pinned player commit, which still declare, start through the same calls (`test/explicit.ts`) until they are migrated and re-pinned.
42
+
43
+ ## 1.8.0
44
+
45
+ **Who must change: nobody.** Pure additions and a product-data sync (user rulings 2026-11-13, plan A): the 31 existing capabilities, their members, what each needs and every existing behaviour of the SDK and of `TestHost` are as in 1.7.20; the existing tests and golden traces pass unchanged. A plugin that does nothing keeps working on every player. A plugin that uses an addition needs the player released with this SDK (`minPlayerVersion`); `apiVersion` stays `vestra/1`.
46
+
47
+ **mpv pass-through** (a new capability and member). `plugin.mpv` sends mpv's own commands and properties to the player's mpv. Intended users: a GPU vendor's motion-smoothing or upscaling plugin (a filter and its options, without a new player method per feature, as 1.7.19 needed), a shader or scaler pack that sets renderer options, a statistics panel that observes mpv's measurements.
48
+
49
+ - **Capability `mpv`** (new, the 32nd; **risky**: the store highlights it; not built-in only; residency `live`), shown as "Control the playback engine (mpv) directly: send its commands and change its options". It crosses a boundary (§1.6): what it sets is the user's player beyond the plugin's own contributions and stays after the plugin stops. It is the last row of the player's table; no existing capability changes.
50
+ - **`Mpv`** (`plugin.mpv`): `command(args)` (the command's name and its arguments as an array; resolves with mpv's result), `get(name)`, `set(name, value)`, `observe(name, listener)` (the current value first, then each change, at most every 100 ms; a `Disposable`). Values are `MpvValue` (JSON). Messages: `mpv.command`, `mpv.get`, `mpv.set`, `mpv.observe`, `mpv.unobserve`, and the event `mpv.property`, sent to the observer without a subscription. The channel is the contract; the names and what they do are mpv's and can change with a player version.
51
+ - **Refused** with the new error code **`refused`** (the message names the command or property and why), by a closed rule: what starts a program, loads scripts or configuration, opens a control channel or talks to mpv's other clients, makes the player write or delete files, ends the player, drives its keyboard and mouse, reaches the clipboard, or changes what the player manages itself (the source and the playlist, the position, the tracks, the output and the window, the subtitle style, the renderer options of `plugin.video`, the filter chains as a whole). Reading is not refused, except the clipboard. It is not a sandbox: a plugin does the first four with Node. The table is data shared with the player (`MPV_RULES`, `MPV_LIMITS`, exported from `./runtime` for its agreement test) and printed in the new reference page [mpv](docs/reference/mpv.md). mpv's own errors arrive as `backend` with mpv's words ("mpv: property not found").
52
+ - **Ownership**: a filter is added as `["vf", "add", "@label:…"]` (`af`; `add`, `pre`, `toggle`, `remove`) with a label of the plugin's own, not starting with `vestra-`. The label has one owner (`conflict` for another plugin), the player removes a plugin's filters and observers when it stops, and keeps a plugin that has one running. The player's own filters (the typed chains, the upscaler, motion smoothing) stay beside it; a pass-through filter does not reach snapshots and exports, which the typed chains do. A property a plugin set stays set until the player quits.
53
+ - **`TestHost.mpv`** and **`TestHost.setMpvProperty()`** (new members; nothing existing changes): the commands sent, a map of property values, the owners of filter labels and the observed properties, with the player's refusals from the same table; no mpv runs. Test: `test/mpv.test.ts`.
54
+
55
+ **Palette lead status** (additions). For a plugin that holds the palette's lead row and reports a request's progress (Ask Vestra today; a calculator or a search that answers in the strip, an assistant that the user can stop). An older player refuses each of them with `invalid`.
56
+
57
+ - **An end state's `status.text` may have 160 characters** (`done`, `failed`, `note`, `stopped`), still on one line: the strip shows it on up to two lines. A working text stays at 80 (one line of the row and of the strip).
58
+ - **`status.state: "stopped"`**: a new end state for the text shown after the user stopped the work, which was sent as `note` and looked like an answer. The player shows it plain with its icon dimmed, for about 2 s.
59
+ - **`status.strip`**: an optional text the strip shows instead of `text` while working (1–80 characters on one line), so the row can read "Vestra is working · Planning…" and the strip "Planning…". Sent only when set; with an end state it is `invalid` (an end state shows in the strip alone, so its `text` is the strip's).
60
+ - **`TestHost`** accepts the new values and nothing else changes: its checks keep their order (texts, icon, state), a wrong state keeps the 80-character limit, and `strip` is checked last and kept in `host.paletteLead.status`. The refusal of a wrong state lists the fifth name ("status.state is one of working, done, failed, note, stopped"). The limits and the state names are `PALETTE_LEAD_LIMITS` and `PALETTE_LEAD_STATES`, exported from `./runtime` for the player's agreement test. Test: `test/lead-status.test.ts`.
61
+
62
+ **Capability scan** (new tooling; user's design, 2026-11-13). `vestra-plugin scan [plugin-dir...]` reads a plugin's source and prints, as JSON, which boundary categories its code uses: `player`, `plugins`, `clipboard`, `credentials`, `camera`, `microphone`, `screen`, `notifications` (the last four reserved: no member reaches them today). Used by the plugin repository's index (stored per package) and by the store's install and update dialogs; also for an author who wants to see what the store will say. It gates nothing: the capabilities, what each needs, every `capability` refusal and `TestHost` are untouched, and `vestra-plugin check` is as before.
63
+
64
+ - **`capability-scan.json`** (the package's root, exported as `@vestra-player/sdk/capability-scan.json`; written by hand, nothing generates it): per category and for `none`, the API's methods (`Interface.member`) and the methods of the player's protocol (for requests by name). The rule: a member is in a category when it changes the user's own settings or the player beyond the plugin's own contributions (`player`), acts on other plugins (`plugins`) or reaches a resource the system protects; what only reads is `none`, the clipboard and the keychain excepted. `test/capability-scan.test.ts` fails when a method of the API surface snapshot or of the capability table is in no list or in two.
65
+ - **The scan**: TypeScript by type, with the capability checker's resolution (aliases, destructuring, a parameter's type, `plugin.wire.request` with a literal method) against this SDK's own declarations, so the plugin's dependencies need not be installed; JavaScript, and TypeScript that imports no SDK types, by name (best effort; `method` and `notes` of the output say so). A request whose method it cannot read is `unchecked`, not in `uses`. No type check, no build, nothing written.
66
+ - **Output**: `{ scan: 1, sdk, plugin, version, uses, method, files, evidence, unchecked, notes }`; `uses` is the list of categories, in the table's order. One object for one directory, an array (each with `directory`) for several. Reference: [Capability scan](docs/reference/scan.md); maintainers: `docs/maintaining.md`.
67
+
68
+ **Product data** (player f54a87d3).
69
+
70
+ - **Slint widget copy**: `slint/vestra/widgets.slint` gains `Button`'s `key` property (the key that presses it, shown as a key cap after the text; empty by default, which draws nothing).
71
+ - **`BUILTIN_COMMANDS`**: the playlist's `playlist.reveal` is titled "Show in Folder" (playlist 0.2.7; it said "Show in Finder"). Its id, key and focus are unchanged; the table in [Reference: commands](docs/reference/commands.md#built-in-commands) follows.
72
+
73
+ The API surface snapshot gains `Mpv`, `MpvValue`, `Scope.mpv`, `TestHost.mpv`, `TestHost.setMpvProperty`, and `strip` and `"stopped"` in `PaletteLeadOptions.status`; nothing is removed. `test/constants.test.ts` gains the name `mpv` in its two lists of capabilities (one added line each).
74
+
3
75
  ## 1.7.20
4
76
 
5
77
  **Who must change: nobody.** A docs-only patch (a review follow-up of motion smoothing): no API change, `apiVersion` stays `vestra/1`, the API surface snapshot is unchanged.
package/README.md CHANGED
@@ -41,7 +41,7 @@ npm i -D @vestra-player/sdk # Node.js 26 or newer
41
41
  "version": "0.1.0",
42
42
  "apiVersion": "vestra/1",
43
43
  "entry": "main.ts",
44
- "capabilities": ["commands", "ui.osd"]
44
+ "minPlayerVersion": "0.9.0"
45
45
  }
46
46
  ```
47
47
 
@@ -81,7 +81,7 @@ The [documentation site](https://vestrasys.github.io/vestra-player-sdk/) is the
81
81
 
82
82
  - **[Tutorial](https://vestrasys.github.io/vestra-player-sdk/documents/Tutorial.html)**: one page: what a plugin is (a process that talks to the player), the three ways to write one with an example each, where things live, and running, testing and publishing.
83
83
  - **[Guides](https://vestrasys.github.io/vestra-player-sdk/documents/Guides.html)**: one task each (goal, steps, often a complete example): windows, settings and translations, playback, storage, window state, sliders, subtitles, video filters, the GPU switch, menu state that needs no running plugin (`plugin.when`), testing, publishing, your own store, documentation for coding agents; the design rules every plugin follows; and troubleshooting.
84
- - **[Reference](https://vestrasys.github.io/vestra-player-sdk/documents/Reference.html)**: capabilities, manifest fields, limits, menus and bindings, platforms, theme, error codes, events, messages, translations, the test host, and the [command line](https://vestrasys.github.io/vestra-player-sdk/documents/Command_line.html) (`vestra-plugin check`, `test`, `build`, `pack`, `i18n extract`, `i18n check`).
84
+ - **[Reference](https://vestrasys.github.io/vestra-player-sdk/documents/Reference.html)**: manifest fields, limits, menus and bindings, platforms, theme, error codes, events, messages, translations, the test host, and the [command line](https://vestrasys.github.io/vestra-player-sdk/documents/Command_line.html) (`vestra-plugin check`, `test`, `build`, `pack`, `i18n extract`, `i18n check`).
85
85
  - **[Examples](https://vestrasys.github.io/vestra-player-sdk/documents/Examples.html)**: the walkthroughs above.
86
86
  - **[API](https://vestrasys.github.io/vestra-player-sdk/modules/_vestra-player_sdk.html)**: every type and member of `@vestra-player/sdk` and `@vestra-player/sdk/testing`.
87
87
 
@@ -4,6 +4,7 @@
4
4
  * keep its translations up to date.
5
5
  *
6
6
  * vestra-plugin <check|build|test|pack> [plugin-dir...] [--version x.y.z] [--out dir]
7
+ * vestra-plugin scan [plugin-dir...]
7
8
  * vestra-plugin i18n extract [plugin-dir...] [--locale <lang>]...
8
9
  * vestra-plugin i18n check [plugin-dir...]
9
10
  * vestra-plugin docs [path] [--page N]
@@ -12,17 +13,18 @@
12
13
  * A plugin directory holds manifest.json; the default is the current
13
14
  * directory. Works in any project that depends on @vestra-player/sdk.
14
15
  *
15
- * check strict type check of the plugin's .ts files and tests/*.ts
16
- * (then every use of an API member whose capability manifest.json
17
- * does not declare: file:line, member, capability; fails on any;
18
- * a plugin.wire.request or event listener whose name the check
19
- * cannot read is listed as unchecked, without failing; --json
20
- * prints the findings and the unchecked calls as JSON)
16
+ * check the manifest, then a strict type check of the plugin's .ts
17
+ * files and tests/*.ts
21
18
  * build check, then write dist/: .ts → .js with types stripped, other
22
19
  * package files copied, dist/manifest.json with `version`
23
20
  * test node --test on tests/*.test.{ts,mjs}
24
21
  * pack build, then dist/ → <out>/<id>-<version>.vxp (a zip; default
25
22
  * out: the current directory) with its sha256 and size
23
+ * scan the boundary categories the plugin's code uses (player,
24
+ * plugins, clipboard, credentials, camera, microphone, screen,
25
+ * notifications), as JSON: by type for TypeScript, by name
26
+ * (best effort, said in the output) for JavaScript; reads the
27
+ * source only, checks and changes nothing
26
28
  * docs the SDK's documentation by path, for coding agents: `/` lists
27
29
  * Overview, Guides and API, `/API/Media/Snapshot/dispose` is
28
30
  * one member's whole documentation; --search <query> lists
@@ -99,9 +101,6 @@ const i18n = await import(pathToFileURL(join(sdkRoot, "dist/i18n.js")).href);
99
101
  const i18nTools = await import(
100
102
  pathToFileURL(join(sdkRoot, "dist/i18n-tools.js")).href
101
103
  );
102
- const capabilityCheck = await import(
103
- pathToFileURL(join(sdkRoot, "dist/capability-check.js")).href
104
- );
105
104
  const SDK = "@vestra-player/sdk";
106
105
 
107
106
  /** Never part of a production package. */
@@ -313,10 +312,10 @@ function checkConfig(target, sources) {
313
312
  };
314
313
  }
315
314
 
316
- async function check(target, report = null) {
317
- const say = report ? () => {} : (line) => console.log(line);
315
+ async function check(target) {
316
+ const say = (line) => console.log(line);
318
317
  for (const hint of target.hints ?? []) say(`${target.name}: hint: ${hint}`);
319
- dependencies(target, !!report);
318
+ dependencies(target);
320
319
  const own = (await files(target.directory)).filter(
321
320
  (file) => isTypeScript(file) || file.endsWith(".mts"),
322
321
  );
@@ -330,48 +329,19 @@ async function check(target, report = null) {
330
329
  );
331
330
  if (!sources.length) {
332
331
  say(`${target.name}: no TypeScript to check`);
333
- report?.push({ plugin: target.name, findings: [], unchecked: [] });
334
332
  return;
335
333
  }
336
334
  const tsc = compiler("typescript/lib/tsc.js");
337
335
  const scratch = await mkdtemp(join(tmpdir(), "vestra-plugin-check-"));
338
- let findings;
339
- let unchecked;
340
336
  try {
341
337
  const config = join(scratch, "tsconfig.json");
342
338
  await writeFile(config, JSON.stringify(checkConfig(target, sources)));
343
- if (
344
- run(process.execPath, [tsc, "-p", config], {
345
- stdio: report ? ["ignore", process.stderr, "inherit"] : "inherit",
346
- }) !== 0
347
- )
339
+ if (run(process.execPath, [tsc, "-p", config], { stdio: "inherit" }) !== 0)
348
340
  fail(`${target.name}: type check failed`);
349
341
  say(`${target.name}: type check passed (${sources.length} files)`);
350
- ({ findings, unchecked } = await capabilityFindings(target, config));
351
342
  } finally {
352
343
  await rm(scratch, { recursive: true, force: true });
353
344
  }
354
- if (report) report.push({ plugin: target.name, findings, unchecked });
355
- else {
356
- for (const finding of findings)
357
- console.error(
358
- `${relative(process.cwd(), finding.file) || finding.file}:${finding.line}:${finding.column}: ${finding.message} (request ${finding.method})`,
359
- );
360
- // Calls whose capability depends on a name the check cannot read
361
- // (plugin.wire.request with a computed method): a note, never a failure.
362
- for (const call of unchecked)
363
- console.log(
364
- `${relative(process.cwd(), call.file) || call.file}:${call.line}:${call.column}: unchecked: ${call.message}`,
365
- );
366
- }
367
- if (findings.length) {
368
- const missing = [...new Set(findings.map((each) => each.capability))];
369
- fail(
370
- `${target.name}: ${findings.length} use${findings.length === 1 ? "" : "s"} of undeclared capabilities; add ${missing.map((each) => `"${each}"`).join(", ")} to manifest.json "capabilities" (or stop using those members)`,
371
- );
372
- }
373
- say(`${target.name}: capabilities declared for every API use`);
374
- if (report) return;
375
345
  for (const line of await forWarnings(target))
376
346
  console.log(`${target.name}: warning: ${line}`);
377
347
  // Translation warnings never fail the check.
@@ -386,48 +356,6 @@ async function check(target, report = null) {
386
356
  }
387
357
  }
388
358
 
389
- /**
390
- * Uses of API members whose capability the manifest does not declare
391
- * (`findings`), and calls whose capability depends on a name the check
392
- * cannot read (`unchecked`: `plugin.wire.request` with a computed method),
393
- * in the plugin's production files (not tests/), with the type check's
394
- * compiler options (src/capability-check.ts).
395
- */
396
- async function capabilityFindings(target, config) {
397
- const ts = await typescript();
398
- const parsed = ts.getParsedCommandLineOfConfigFile(
399
- config,
400
- {},
401
- {
402
- ...ts.sys,
403
- onUnRecoverableConfigFileDiagnostic: (diagnostic) =>
404
- fail(
405
- `${target.name}: ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`,
406
- ),
407
- },
408
- );
409
- const files = (await sourceFiles(target)).typescript.map((file) =>
410
- join(target.directory, file),
411
- );
412
- if (!parsed || !files.length) return { findings: [], unchecked: [] };
413
- const program = ts.createProgram(parsed.fileNames, parsed.options);
414
- const capabilities = Array.isArray(target.manifest.capabilities)
415
- ? target.manifest.capabilities
416
- : [];
417
- const { findings, unchecked } = capabilityCheck.checkCapabilities(
418
- ts,
419
- program,
420
- { files, capabilities },
421
- );
422
- return {
423
- findings: findings.map((finding) => ({
424
- ...finding,
425
- file: resolve(finding.file),
426
- })),
427
- unchecked: unchecked.map((call) => ({ ...call, file: resolve(call.file) })),
428
- };
429
- }
430
-
431
359
  /** Slint source without its comments (string literals kept as they are). */
432
360
  function slintCode(text) {
433
361
  let out = "";
@@ -871,9 +799,126 @@ async function pack(target, flag, outDirectory) {
871
799
  );
872
800
  }
873
801
 
802
+ /**
803
+ * `vestra-plugin scan`: the boundary categories a plugin's code uses
804
+ * (src/capability-scan.ts, capability-scan.json), as JSON on standard
805
+ * output: one object for one directory, an array for several. It reads the
806
+ * source and the manifest's id and version; it runs no type check and no
807
+ * build, and changes nothing.
808
+ *
809
+ * TypeScript files are scanned by type, against this SDK's own
810
+ * declarations (whatever the project has installed); JavaScript files, and
811
+ * TypeScript files of a plugin that imports no SDK types, by name. A
812
+ * directory with no source outside dist/ (a built package) is scanned in
813
+ * dist/.
814
+ */
815
+ async function scanPlugin(directory) {
816
+ const ts = await typescript();
817
+ const scanner = await import(
818
+ pathToFileURL(join(sdkRoot, "dist/capability-scan.js")).href
819
+ );
820
+ const root = resolve(directory);
821
+ if (!present(join(root, "manifest.json")))
822
+ fail(`${directory}: no manifest.json in ${root}`);
823
+ const manifest = await json(join(root, "manifest.json"));
824
+ const isScript = (file) => /\.[mc]?js$/.test(file);
825
+ const isTyped = (file) => /\.[mc]?tsx?$/.test(file) && !isDeclaration(file);
826
+ let all = (await files(root)).filter(
827
+ (file) => isScript(file) || isTyped(file),
828
+ );
829
+ // A built package: its code is dist/ alone.
830
+ if (!all.length && present(join(root, "dist")))
831
+ all = (await files(join(root, "dist")))
832
+ .filter(isScript)
833
+ .map((file) => join("dist", file));
834
+ all.sort();
835
+ let typed = all.filter(isTyped).map((file) => join(root, file));
836
+ const read = async (file) => ({
837
+ file,
838
+ text: await readFile(file, "utf8"),
839
+ });
840
+ const named = await Promise.all(
841
+ all.filter(isScript).map((file) => read(join(root, file))),
842
+ );
843
+ const relativeTo = (file) =>
844
+ relative(root, resolve(file)).split(sep).join("/");
845
+ const program = typed.length
846
+ ? ts.createProgram(typed, {
847
+ target: ts.ScriptTarget.ES2023,
848
+ module: ts.ModuleKind.NodeNext,
849
+ moduleResolution: ts.ModuleResolutionKind.NodeNext,
850
+ allowImportingTsExtensions: true,
851
+ noEmit: true,
852
+ skipLibCheck: true,
853
+ types: [],
854
+ // This SDK's declarations, wherever the plugin's own copy is.
855
+ paths: { [SDK]: [join(sdkRoot, "dist/index.d.ts")] },
856
+ })
857
+ : undefined;
858
+ let found = scanner.scan(ts, program, {
859
+ typed,
860
+ named,
861
+ relative: relativeTo,
862
+ });
863
+ const notes = [];
864
+ if (!found.resolved) {
865
+ // No SDK types to go by: read the TypeScript by name too.
866
+ notes.push(
867
+ "The TypeScript files import no types of @vestra-player/sdk; they were scanned by name (best effort).",
868
+ );
869
+ named.push(...(await Promise.all(typed.map(read))));
870
+ typed = [];
871
+ found = scanner.scan(ts, undefined, {
872
+ typed,
873
+ named,
874
+ relative: relativeTo,
875
+ });
876
+ }
877
+ if (named.length)
878
+ notes.push(
879
+ "Files scanned by name have no types: a member counts when it is used on something named as its module of plugin (plugin.clipboard.readText, clipboard.readText). A use under another name is missed, and a name that only looks like one is counted.",
880
+ );
881
+ if (!typed.length && !named.length)
882
+ notes.push("No TypeScript or JavaScript files were found.");
883
+ if (found.unchecked.length)
884
+ notes.push(
885
+ "Some requests by name could not be placed (unchecked): what they ask for is not in uses.",
886
+ );
887
+ return {
888
+ scan: scanner.SCAN_FORMAT,
889
+ sdk: (await json(join(sdkRoot, "package.json"))).version,
890
+ plugin: typeof manifest.id === "string" ? manifest.id : null,
891
+ version: typeof manifest.version === "string" ? manifest.version : null,
892
+ uses: found.uses,
893
+ method:
894
+ typed.length && named.length
895
+ ? "mixed"
896
+ : typed.length
897
+ ? "types"
898
+ : named.length
899
+ ? "names"
900
+ : "none",
901
+ files: { types: typed.length, names: named.length },
902
+ evidence: found.evidence,
903
+ unchecked: found.unchecked,
904
+ notes,
905
+ };
906
+ }
907
+
908
+ /** `vestra-plugin scan [plugin-dir...]`. */
909
+ async function scanCommand(args) {
910
+ const directories = args.length ? args : ["."];
911
+ const results = [];
912
+ for (const directory of directories)
913
+ results.push({ directory, ...(await scanPlugin(directory)) });
914
+ const [only] = results;
915
+ if (results.length === 1) delete only.directory;
916
+ console.log(JSON.stringify(results.length === 1 ? only : results, null, 2));
917
+ }
918
+
874
919
  const USAGE = [
875
920
  "usage: vestra-plugin <check|build|test|pack> [plugin-dir...] [--version x.y.z] [--out dir]",
876
- " vestra-plugin check [plugin-dir...] --json",
921
+ " vestra-plugin scan [plugin-dir...]",
877
922
  " vestra-plugin i18n extract [plugin-dir...] [--locale <lang>]...",
878
923
  " vestra-plugin i18n check [plugin-dir...]",
879
924
  " vestra-plugin docs [path] [--page N]",
@@ -932,6 +977,10 @@ async function main() {
932
977
  await docsCommand(args);
933
978
  return;
934
979
  }
980
+ if (command === "scan") {
981
+ await scanCommand(args);
982
+ return;
983
+ }
935
984
  let subcommand = null;
936
985
  if (command === "i18n") {
937
986
  subcommand = args.shift();
@@ -951,12 +1000,10 @@ async function main() {
951
1000
  }
952
1001
  if (locales.length && subcommand !== "extract")
953
1002
  fail("--locale applies to i18n extract");
954
- const jsonIndex = args.indexOf("--json");
955
- const report = jsonIndex >= 0 ? [] : null;
956
- if (report) {
957
- args.splice(jsonIndex, 1);
958
- if (command !== "check") fail("--json applies to check");
959
- }
1003
+ if (args.includes("--json"))
1004
+ fail(
1005
+ "--json was removed in SDK 1.9.0 with the capability check it reported (manifest capabilities are gone); check prints its result as text",
1006
+ );
960
1007
  const flag = option("--version");
961
1008
  const out = option("--out");
962
1009
  const directories = args.length ? args : ["."];
@@ -964,12 +1011,11 @@ async function main() {
964
1011
  fail("--version applies to a single plugin");
965
1012
  const failed = [];
966
1013
  for (const directory of directories) {
967
- const reported = report?.length ?? 0;
968
1014
  try {
969
1015
  const target = await plugin(directory);
970
1016
  if (subcommand === "extract") await i18nExtract(target, locales);
971
1017
  else if (subcommand === "check") await i18nCheck(target);
972
- else if (command === "check") await check(target, report);
1018
+ else if (command === "check") await check(target);
973
1019
  else if (command === "build") await build(target, flag);
974
1020
  else if (command === "pack") await pack(target, flag, out);
975
1021
  else await test(target);
@@ -977,15 +1023,8 @@ async function main() {
977
1023
  if (!error.expected) throw error;
978
1024
  console.error(`✖ ${error.message}`);
979
1025
  failed.push(directory);
980
- if (report) {
981
- if (report.length === reported)
982
- report.push({ findings: [], unchecked: [] });
983
- report[reported].error = error.message;
984
- }
985
1026
  }
986
- if (report) report[reported] = { directory, ...report[reported] };
987
1027
  }
988
- if (report) console.log(JSON.stringify(report, null, 2));
989
1028
  if (failed.length) {
990
1029
  console.error(
991
1030
  `${subcommand ? `i18n ${subcommand}` : command} failed for: ${failed.join(", ")}`,