@zaisma/cli 0.71.0 → 0.72.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.
- package/README.md +2 -0
- package/package.json +3 -1
- package/pieces.d.mts +201 -0
- package/pieces.mjs +1162 -0
- package/skill/SKILL.md +2 -0
- package/skill/references/developer-api.md +25 -2
- package/skill/references/naming.md +6 -0
- package/skill/references/pieces.md +251 -0
- package/zaisma.mjs +148 -3
package/skill/SKILL.md
CHANGED
|
@@ -52,6 +52,7 @@ The building blocks, each optional:
|
|
|
52
52
|
- **Rooms and a game server:** `Zaisma.joinRoom()` puts players in a room run by the game's server, which holds the official state and checks every move. It runs on Zaisma or on the developer's own server (`npx @zaisma/game-server@1`). Reference: `references/game-server.md`; how to make it hold up on a weak connection: `references/multiplayer.md`.
|
|
53
53
|
- **Player accounts and passes:** guests play at once; `Zaisma.player.getPass()` gives a signed pass any server can check; a game can ask a guest to sign in with `Zaisma.player.signIn()`. Reference: `references/sdk.md`.
|
|
54
54
|
- **Cloud saves:** a signed-in player's localStorage and IndexedDB follow them to every device with no code. `references/saves.md` says when and what to save.
|
|
55
|
+
- **Pieces:** shared building blocks a game is made from, so its effort goes into what makes it its own. `npx @zaisma/cli pieces add <name>` adds one with what it needs, never a second copy; `npx @zaisma/cli pieces --json` answers what each one gives, its settings and its hooks. A piece is changed through its settings and hooks, never its files. Anyone publishes pieces, for any engine. Reference: `references/pieces.md`.
|
|
55
56
|
- **A database** for the game, from its game server: `query_database`, `batch_database`.
|
|
56
57
|
- **Items and the buy sheet:** `set_item`, `Zaisma.items.buy()`, purchases delivered to the game or its server.
|
|
57
58
|
- **Backgrounds:** an image or a shader behind Zaisma's glass on the game's page (`set_background`, `check_shader`).
|
|
@@ -90,6 +91,7 @@ Every name in the API, MCP, SDK and game server says what it holds, its kind and
|
|
|
90
91
|
| `references/loading.md` (`zaisma://loading`) | The game is more than a few MB, or `performance_check` says its first frame is slow. |
|
|
91
92
|
| `references/phones.md` (`zaisma://phones`) | The game should play on phones or tablets. |
|
|
92
93
|
| `references/saves.md` (`zaisma://saves`) | The game keeps progress. |
|
|
94
|
+
| `references/pieces.md` (`zaisma://pieces`) | Adding a shared piece to the game, moving one to a newer version, changing one through its settings and hooks, or making a piece for other games. |
|
|
93
95
|
| `references/sdk.md` (`zaisma://sdk`) | Writing code that calls `Zaisma.*` in the game. |
|
|
94
96
|
| `references/game-server.md` (`zaisma://game-server`) | Writing the game server, running it on the developer's own server, or testing with play-locally. |
|
|
95
97
|
| `references/errors.md` (`zaisma://errors`) | An error code isn't clear from its answer. |
|
|
@@ -1938,7 +1938,7 @@ A minute after a version passes the scan, Zaisma has opened it in headless Chrom
|
|
|
1938
1938
|
|
|
1939
1939
|
### Checking a game
|
|
1940
1940
|
|
|
1941
|
-
Before uploading, the check says everything in a game that Zaisma would refuse, or that won't work inside Zaisma's game frame, each with how to fix it. It's the same check everywhere (`packages/cli/check.mjs`): `zaisma check <folder>` on a folder, with no key and nothing sent; the MCP's `check_game` with the same files as `upload_files`; and this call. `zaisma upload` runs it first.
|
|
1941
|
+
Before uploading, the check says everything in a game that Zaisma would refuse, or that won't work inside Zaisma's game frame, each with how to fix it. It's the same check everywhere (`packages/cli/check.mjs`): `zaisma check <folder>` on a folder, with no key and nothing sent; the MCP's `check_game` with the same files as `upload_files`; and this call. `zaisma upload` runs it first. The command leaves type files (`.d.ts`) out of what it checks and sends, since they never run: a piece carries one as its reference ([`docs/PIECES.md`](PIECES.md)).
|
|
1942
1942
|
|
|
1943
1943
|
| Call | What it does |
|
|
1944
1944
|
| --- | --- |
|
|
@@ -2050,6 +2050,12 @@ The files a version needed before its first frame in its run in Chrome are prelo
|
|
|
2050
2050
|
| `zaisma saves restore <slug> <player_id> <save_copy_id>` | Make an earlier version the save again | `POST /games/:slug/saves/:player_id/copies/:id/restore` |
|
|
2051
2051
|
| `zaisma export <slug> [--folder <folder>]` | Save everything about the game in a folder (`./<slug>-export` unless `--folder` says), with the database also as a ready `database.sqlite` | `GET /games/:slug/export/download` |
|
|
2052
2052
|
| `zaisma skill [--folder <folder>] [--project] [--yes]` | Install the Zaisma skill into the AI tools on this computer, or update the copies it installed (see Teaching your AI) | none, it writes files on this computer |
|
|
2053
|
+
| `zaisma pieces [--folder <folder>]` | The game's pieces, the shared building blocks it's made from ([`docs/PIECES.md`](PIECES.md)): each one's name, version, kind, standard, licence and needs, its settings and hooks, where to import it from, and whether its files were changed by hand | none, it reads the game's folder |
|
|
2054
|
+
| `zaisma pieces add <source> [--folder <folder>] [--dry-run]` | Add a piece with what it needs: a folder, the `.tgz` that `npm pack` makes, or a name on npm with an optional range. A piece the game already has is left exactly as it is; a version that doesn't fit stops with both versions named and nothing added. A piece's code is never run | none, it writes the game's folder (a name is fetched from npm) |
|
|
2055
|
+
| `zaisma pieces update <name> [--version <range>] [--from <source>] [--discard-edits] [--folder <folder>] [--dry-run]` | Move one of the game's pieces to another version: only the one named, and only when everything else in the game accepts it | none, it writes the game's folder |
|
|
2056
|
+
| `zaisma pieces remove <name> [--discard-edits] [--folder <folder>] [--dry-run]` | Take one piece out of the game, unless another of its pieces needs it; what it needed and nothing needs now is named, never removed | none, it writes the game's folder |
|
|
2057
|
+
| `zaisma pieces newer [--folder <folder>]` | Which of the game's pieces have a newer version on npm, the newest the rest of the game accepts, and what holds it back; it changes nothing | none, it asks npm |
|
|
2058
|
+
| `zaisma pieces check <folder> [--fix]` | Check a piece you're making before you publish it: its `piece.json`, the files it lists, that every import is a listed file or a stated need, and the `package.json` beside it. `--fix` writes `piece.json.js` again from `piece.json` | none, it reads the piece's folder |
|
|
2053
2059
|
|
|
2054
2060
|
- **Closed, like the API.** A command takes only its own flags and arguments: anything else is refused before anything is sent, with the flags it does take. Choices (`visibility`, `--screen`, `--kind`, `--category`, `--match-update-mode`) are checked first too, with the valid list. A flag that takes a value takes it as `--flag value` or `--flag=value`. Renamed commands and flags say their new name (`zaisma show` is now `zaisma visibility`; `--notes`, `--publish` and `--at` are `--patch-notes`, `--publish-when-approved` and `--scheduled-publish-at`).
|
|
2055
2061
|
- **`--json` on every command** prints the API's answer as-is, compact, and nothing else on stdout: the same data the MCP gets. On failure it prints the API's `{ "error": { code, message, field, fix, message_for_people, retry_after_sec, help_url } }`, or the same shape without `message_for_people` for the command's own errors (below), where `field` is the flag (`--game`) or argument (`slug`) at fault. `upload --json` prints the version's last answer (`GET /games/:slug/versions/:id`) and sends its progress to stderr; `forum --json` with no topic or search prints both tabs' answers, as `{ "yours": …, "messages": … }`. Without `--json`, the command prints lines for people, and errors go to stderr as `zaisma: <message> <fix> (<code>)`.
|
|
@@ -2075,7 +2081,7 @@ Exit codes, the same for every command:
|
|
|
2075
2081
|
| 3 | `held` | upload: the version is held for a person at Zaisma to look at, usually within a day. |
|
|
2076
2082
|
| 4 | `rejected` | upload: the version was rejected. Its review_reason and findings say why and how to fix it. |
|
|
2077
2083
|
| 5 | `still_scanning` | upload: the version was still being scanned after 10 minutes. Check it later with zaisma versions <slug>. |
|
|
2078
|
-
| 6 | `problems_found` | check: something in the game won't work on Zaisma as it is, and the upload command doesn't fix it; or the shader doesn't compile, is too slow or flashes. The problems say what and how to fix it. |
|
|
2084
|
+
| 6 | `problems_found` | check: something in the game won't work on Zaisma as it is, and the upload command doesn't fix it; or the shader doesn't compile, is too slow or flashes; or pieces check: the piece wouldn't add or would break in a game. The problems say what and how to fix it. |
|
|
2079
2085
|
|
|
2080
2086
|
Errors only the command answers with, beside the API's own codes (it also uses `unknown_field`, `missing_field`, `no_key`, `internal_error` and the `bad_<field>` codes of the choices it checks):
|
|
2081
2087
|
|
|
@@ -2109,3 +2115,20 @@ Errors only the command answers with, beside the API's own codes (it also uses `
|
|
|
2109
2115
|
| `unexpected_answer` | Zaisma answered without JSON, like a page from a network in between. |
|
|
2110
2116
|
| `skill_not_ours` | skill: a zaisma skill this command didn't install is already in that folder, so nothing was written; field names the folder. |
|
|
2111
2117
|
| `install_not_confirmed` | skill: nothing was installed, since nobody answered the question: give --yes to install without it. |
|
|
2118
|
+
| `bad_piece_statement` | pieces: a piece's piece.json isn't one: field names what's wrong in it. |
|
|
2119
|
+
| `piece_statement_newer` | pieces: a piece's piece.json is written for a newer command than this one: run the newest. |
|
|
2120
|
+
| `bad_piece_source` | pieces: what was given isn't a piece's folder, its .tgz or a name on npm, or its archive can't be trusted. |
|
|
2121
|
+
| `piece_not_found` | pieces: there's no such piece or version where it was looked for. |
|
|
2122
|
+
| `piece_source_unreachable` | pieces: npm couldn't be reached, so nothing was changed. |
|
|
2123
|
+
| `piece_already_added` | pieces add: the game already has this piece at another version; a piece moves to another version only with pieces update. |
|
|
2124
|
+
| `piece_not_added` | pieces update, pieces remove: the game has no such piece. |
|
|
2125
|
+
| `piece_version_clash` | pieces: two pieces need versions of the same thing that don't overlap, so nothing was changed; the error says both versions and the ways out. |
|
|
2126
|
+
| `piece_need_unmet` | pieces: something a piece needs wasn't found, so nothing was changed. |
|
|
2127
|
+
| `piece_edited` | pieces update, pieces remove: the piece's files in the game were changed by hand; --discard-edits loses the edits. |
|
|
2128
|
+
| `piece_source_needed` | pieces update: the piece came from a folder or a .tgz, so --from must say where the new version is. |
|
|
2129
|
+
| `piece_not_updatable` | pieces update: a template is copied once and is the game's own. |
|
|
2130
|
+
| `piece_not_removable` | pieces remove: a template's files are the game's own. |
|
|
2131
|
+
| `piece_still_needed` | pieces remove: another of the game's pieces needs this one, so nothing was changed. |
|
|
2132
|
+
| `template_file_exists` | pieces add: a template would write over a file the game already has, so nothing was changed. |
|
|
2133
|
+
| `bad_pieces_record` | pieces: the game's pieces/pieces.json can't be read. |
|
|
2134
|
+
| `pieces_record_newer` | pieces: the game's pieces/pieces.json was written by a newer command than this one: run the newest. |
|
|
@@ -445,6 +445,12 @@ One name per concept. The API and MCP column is snake_case; the SDK and game ser
|
|
|
445
445
|
| Whether a purchase, and its refund, reached the game, its game server or your own server | `handled_at` and `refund_handled_at` on a `purchase` (ISO time, `null` until then); `unhandled_purchases` (completed purchases not handled, and refunded or charged-back ones handled but not yet told, oldest first, at most 50 purchases and 50 refunds) in `get_player_items`; `mark_purchase_handled` (`POST …/purchases/:purchase_id/handled`); webhook events `purchase_completed` and `purchase_refunded` with `purchase` (`null` in every other event); errors `already_handled`, `handled_by_server` | `Zaisma.items.unhandled()` answers `Purchase[]` `{ id, itemName, itemKind, itemCount, purchaseSource, purchaseStatus, gameAccountId, paidMinorUnits, currencyCode, purchasedAt, refundedAt, receipt }`; `Zaisma.items.markHandled(purchaseId)`, errors `bad_purchase_id`, `no_purchase`, `already_handled`, `handled_by_server`, `slow_down` |
|
|
446
446
|
| A purchase, or its refund, arriving at the game or its game server | | `Zaisma.items.on("purchase", listener)` and `Zaisma.items.on("refund", listener)` (`ItemsEvents`, `off` to stop), each listener gets a `Purchase`; `onPurchase(state, player, room, purchase)` and `onRefund(state, player, room, purchase)` on the game server (`Purchase`, `PurchaseHandling`, `purchaseHandling` on a `Transport`); the room message `{ type: "zaisma:purchase", purchaseId, receipt? }` the SDK sends to a game server's rooms after a purchase |
|
|
447
447
|
| What a request to a game server can fail with | | `RequestErrorCode`: `bad_request`, `too_big`, `bad_pass`, `bad_player_token`, `account_needed`, `game_not_open_to_player`, `game_unavailable`, `no_request_handler`, `game_server_error`, `hosting_paused`, `rented_share_used`, `slow_down`, `bad_origin`, `busy` |
|
|
448
|
+
| A shared building block a game is made from, what it states about itself, its kind and the standard it's built on ([`docs/PIECES.md`](PIECES.md)) | in a `piece.json` (a piece's statement) and the upload command's answers: `statement_version_number`, `name`, `kind` (`foundation`, `extension`, `game_system`, `template`), `standard` (a name on npm), `summary`, `license`, `entry_path`, `server_entry_path`, `file_paths`, `server_file_paths`; where a game imports it from: `import_path`, `server_import_path`, `import_map`; a game's `standards` and `new_standards`; errors `bad_piece_statement`, `piece_statement_newer`, `bad_piece_source`, `piece_not_found`, `piece_source_unreachable`, `piece_already_added`, `piece_not_added`, `template_file_exists` | |
|
|
449
|
+
| A piece's version, apart from a game's (`version_id`), and a library's that isn't a piece | `piece_version`, `library_version` (semver, like `1.0.0`); `earlier_piece_version` and `earlier_library_version` on an update; `newest_piece_version`, `newest_accepted_piece_version`, `newest_library_version`, `newest_accepted_library_version` and `held_back_by_names` from `pieces newer`; errors `piece_source_needed`, `piece_not_updatable`, `piece_not_removable` | |
|
|
450
|
+
| What a piece needs and the versions it accepts | `needs`, each `{ name, version_range, kind }`, `kind` one of `piece`, `library`, `engine`; an answer's `kept_names` (left as they are), `engine_needs` (each `{ name, version_range, needed_by_name }`) and `no_longer_needed_names`; errors `piece_version_clash`, `piece_need_unmet`, `piece_still_needed` | |
|
|
451
|
+
| A piece's settings and hooks: everything a game changes it through | `settings`, each `{ name, value_kind, default_value, minimum_number, maximum_number, maximum_character_count, choices, summary }`, `value_kind` one of `number`, `integer`, `boolean`, `choice`, `text`, `color`, and `default_value` of the type `value_kind` names; `hooks`, each `{ name, hook_kind, summary }`, `hook_kind` one of `event`, `decision` | `@zaisma/piece`: `openPiece`, `openSettings`, `openHooks`; a piece's `settings` (`get`, `set`, `reset`, `values`, `list`, `onChange` with `{ name, newValue, earlierValue }`) and `hooks` (`on`, `off`, `list`), each name in camelCase (`jump_height_m` is `jumpHeightM`); the piece's own `tell`, `ask` and `refuse`; `PieceError` (`pieceName`, `code`, `field`, `fix`), its codes `unknown_setting`, `bad_setting`, `unknown_hook`, `bad_hook`, `wrong_hook_kind` |
|
|
452
|
+
| Where a game's piece came from, whether its files are as they were added, and the game's record of its pieces | `source_kind` (`folder`, `tarball`, `npm`), `files_sha256`, `is_edited`, `is_dry_run`; `pieces/pieces.json`: `record_version_number`, `pieces` (each `{ statement, source_kind, files_sha256 }`), `libraries`; errors `piece_edited`, `bad_pieces_record`, `pieces_record_newer` | |
|
|
453
|
+
| A maker's check of a piece before publishing it | `is_ready`, `problems`, each `{ code, problem_kind, message, path, fix }`, `problem_kind` `refused` or `note`; codes `bad_piece_statement`, `piece_statement_newer`, `missing_file`, `stale_statement_module`, `package_disagrees`, `unlisted_import`, `undeclared_need`, `file_not_uploadable`, `no_reference`, `no_readme` | |
|
|
448
454
|
| What an error or a review reason is, and its other parts | `code`; `message`, `field`, `fix`, `retry_after_sec` (inside `error` only); `content_rule` (inside `review_reason` and `findings` only) | `code` (on the error only) |
|
|
449
455
|
|
|
450
456
|
## Adding a field, option or tool
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
<!-- Made by scripts/build-skill.mjs: never edit it by hand. -->
|
|
2
|
+
|
|
3
|
+
# Pieces
|
|
4
|
+
|
|
5
|
+
A piece is a shared building block a game is made from: a body that already walks, input for every device, save and load, a sky, online play. A game adds the pieces it wants and spends its effort on what makes it its own. Every piece is optional, and no game is locked into any of them.
|
|
6
|
+
|
|
7
|
+
Pieces are open. Anyone publishes one, for any engine or kind of game. Zaisma's own are added, updated and checked exactly as a stranger's are: nothing in the command knows any piece, standard or publisher by name. Zaisma's are MIT licensed, in [`pieces/`](https://github.com/zaisma/zaisma-sdk/blob/main/pieces).
|
|
8
|
+
|
|
9
|
+
This page is the frame every piece stands on: what a piece states about itself, how it's added to a game, how its versions move, and how its settings and hooks are opened.
|
|
10
|
+
|
|
11
|
+
## The layers
|
|
12
|
+
|
|
13
|
+
| Kind | What it is |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| `foundation` | A standard everything else fits: a skeleton, a body, input, save and load, lighting, a networking core. |
|
|
16
|
+
| `extension` | Plugs into one foundation: a kind of sync, a camera style, a way to move, an ability. |
|
|
17
|
+
| `game_system` | A genre's part: a round timer, a combo counter, an inventory. |
|
|
18
|
+
| `template` | A genre's systems wired together, with no style of their own. It's copied into a game once and is then the game's own. |
|
|
19
|
+
|
|
20
|
+
## Standards
|
|
21
|
+
|
|
22
|
+
Every piece names the **standard** it's built on, so pieces made to fit one set of foundations are never mistaken for pieces made to fit another. A standard is whatever its keeper says it is: a set of foundations for three.js, a base for Godot, a skeleton alone.
|
|
23
|
+
|
|
24
|
+
A standard's name is a name on npm, like `@studio/standard`. Two makers' standards can never share a name, and whoever holds the name on npm keeps the standard. A piece built on someone else's standard names it the same way; a small standard can be one piece, named after itself. Zaisma's are in [Zaisma's pieces](#zaismas-pieces): one standard among any that people publish.
|
|
25
|
+
|
|
26
|
+
Adding a piece built on a standard the game didn't have says so, plainly. Nothing stops it: a game chooses its pieces.
|
|
27
|
+
|
|
28
|
+
## Adding pieces to a game
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
npx @zaisma/cli pieces add @studio/dash-move # by its name on npm, the newest version
|
|
32
|
+
npx @zaisma/cli pieces add @studio/dash-move@^1.2 # or the newest within a range
|
|
33
|
+
npx @zaisma/cli pieces add ./my-piece # a piece's folder
|
|
34
|
+
npx @zaisma/cli pieces add ./my-piece-1.0.0.tgz # or the .tgz that npm pack makes of it
|
|
35
|
+
npx @zaisma/cli pieces add @studio/dash-move --dry-run # what it would bring, changing nothing
|
|
36
|
+
npx @zaisma/cli pieces # what the game has
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Run them in the game's folder (the one with its `index.html`, or its source for a game that's built), or give `--folder`. Each takes `--json`.
|
|
40
|
+
|
|
41
|
+
A piece's files go in `pieces/<name>/` with its `piece.json`, its game server files (when it has any) in `zaisma-server/pieces/<name>/`, where a game server on Zaisma can import them and players are never served them, and the game's record of its pieces in `pieces/pieces.json`. Commit all three.
|
|
42
|
+
|
|
43
|
+
**What adding does, always:**
|
|
44
|
+
|
|
45
|
+
- **What a piece needs is stated, and comes with it.** Every piece states what it needs and which versions it accepts; adding brings what's missing, and says what it brought.
|
|
46
|
+
- **Never a second copy.** A piece the game already has, at a version the new piece accepts, is left exactly as it is.
|
|
47
|
+
- **Never moved by itself.** A piece changes version only when you run `pieces update` for it.
|
|
48
|
+
- **A clash stops everything, plainly.** When the game has a version the new piece doesn't accept, nothing is added, and the error (`piece_version_clash`) says both versions and the two ways out: move the one in the game, or use a version of the new piece that accepts it. Two pieces being added that need versions of the same thing with no overlap stop the same way.
|
|
49
|
+
- **A library isn't doubled either.** A piece may need a library that isn't a piece (three.js). A game that has it in its own `package.json` uses its own; one outside the accepted range is a clash like any other. A game without it gets the library's browser files in `pieces/<library>/`, and the command prints the import map its page needs.
|
|
50
|
+
- **An engine is stated, never brought.** A piece for an engine that isn't a library on npm (Godot) says which versions it needs; the command says so and leaves the engine to the game.
|
|
51
|
+
- **A piece's code is never run.** Adding copies the files a piece lists and nothing else: no install scripts, no links, no path outside the game's folder. A piece from npm is checked against npm's own hash of it first.
|
|
52
|
+
|
|
53
|
+
**Using one:** import it from where it was added, as the command prints:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
import { createDash } from "./pieces/@studio/dash-move/index.js";
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Each piece's `index.d.ts` is its reference, with every call, setting, hook and error explained, and its `README.md` shows it in use. An AI reads those two and never needs the piece's insides. `zaisma pieces --json` answers every piece's settings and hooks too.
|
|
60
|
+
|
|
61
|
+
**A page with no bundler** needs an import map before its scripts when a piece brought a library, so the pieces find it. `zaisma pieces` prints it:
|
|
62
|
+
|
|
63
|
+
```html
|
|
64
|
+
<script type="importmap">{"imports":{"three":"./pieces/three/build/three.module.js"}}</script>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Uploading:** `zaisma check` and `zaisma upload` leave every `.d.ts` out of what they check and send, since type files never run. Uploading through the MCP's `upload_files`, leave them out the same way.
|
|
68
|
+
|
|
69
|
+
## Moving a version
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
npx @zaisma/cli pieces newer # what has a newer version on npm, and what holds it back
|
|
73
|
+
npx @zaisma/cli pieces update @studio/dash-move # move one to the newest
|
|
74
|
+
npx @zaisma/cli pieces update @studio/dash-move --version "^1.4"
|
|
75
|
+
npx @zaisma/cli pieces update @studio/dash-move --from ./dash-move-1.5.0.tgz # one that didn't come from npm
|
|
76
|
+
npx @zaisma/cli pieces remove @studio/dash-move
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
- **A version moves when the game chooses,** one piece at a time: `pieces update` moves the piece named and nothing else. What its new version needs and the game lacks is brought; a piece the game has that it no longer accepts is a clash, with the ways out.
|
|
80
|
+
- **Only when everything else accepts it.** If another piece in the game needs a range the new version is outside, nothing moves, and the error names that piece. `pieces newer` shows this before you try: the newest version, the newest the rest of the game accepts, and which pieces hold it back.
|
|
81
|
+
- **Removing** takes one piece out, unless another needs it (`piece_still_needed`). What it needed stays: the answer names what no piece needs any more, for you to remove or keep.
|
|
82
|
+
- **A template is the game's own** once copied: it has no version to move and nothing to remove, and it no longer holds the versions of the pieces it brought.
|
|
83
|
+
|
|
84
|
+
## Settings and hooks
|
|
85
|
+
|
|
86
|
+
**A piece is never edited by a game.** Everything a game would change is a setting or a hook, so the piece can move to a newer version and keep the game's changes. A super jump is a setting turned up while playing. If a game would have to copy a piece to change it, the piece is missing a hook: tell its maker.
|
|
87
|
+
|
|
88
|
+
Every piece states its settings and hooks in its `piece.json`, so they're read without opening its code:
|
|
89
|
+
|
|
90
|
+
- A **setting** is a number or an integer with its range, `true` or `false`, one of a few choices, text, or a colour, with a default. Every setting can be changed while playing.
|
|
91
|
+
- A **hook** is a point where the piece calls the game's code. An `event` tells the game something happened. A `decision` asks the game before something happens, and what the game answers is what happens.
|
|
92
|
+
|
|
93
|
+
Pieces written in JavaScript open them the same way, through [`@zaisma/piece`](https://github.com/zaisma/zaisma-sdk/blob/main/pieces/piece): a create call takes `{ settings, hooks }` beside its own arguments and gives back an object with `settings` and `hooks` on it.
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
const dash = createDash({ settings: { dashSpeedMPerSec: 18 }, hooks: { dashed: () => playWhoosh() } });
|
|
97
|
+
|
|
98
|
+
dash.settings.set({ dashCooldownSec: 0.2 }); // while playing
|
|
99
|
+
dash.settings.get("dashCooldownSec"); // 0.2
|
|
100
|
+
dash.settings.list(); // every setting: what it takes, its default, what it is now
|
|
101
|
+
dash.hooks.on("beforeDash", (dashDistanceM) => (isSlowed ? dashDistanceM / 2 : dashDistanceM));
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
In code a name is in the language's own style (`dash_speed_m_per_sec` is `dashSpeedMPerSec` in JavaScript). A setting or hook the piece doesn't have is refused, with the ones it does have in the error's `fix`; so is a value outside what a setting takes.
|
|
105
|
+
|
|
106
|
+
`zaisma pieces` marks a piece whose files were changed by hand, and `pieces update` and `pieces remove` refuse to lose the edits until you say `--discard-edits`.
|
|
107
|
+
|
|
108
|
+
## Zaisma's pieces
|
|
109
|
+
|
|
110
|
+
| Piece | Kind and standard | Gives | Needs |
|
|
111
|
+
| --- | --- | --- | --- |
|
|
112
|
+
| `@zaisma/piece` | `foundation`, its own small standard `@zaisma/piece` | How a JavaScript piece opens its settings and hooks, the same in every piece, in a browser and on a game server. A game never adds it by name: it comes with any piece that needs it. | nothing |
|
|
113
|
+
|
|
114
|
+
Zaisma's foundations are built on the standard `@zaisma/standard`; the skeleton and its animation names are a small standard of their own, `@zaisma/skeleton`, so another maker's standard can build on just that.
|
|
115
|
+
|
|
116
|
+
## Making a piece
|
|
117
|
+
|
|
118
|
+
A piece is a folder with a `piece.json` at its top, its statement: what it is, the standard it's built on, what it needs, and its settings and hooks. The command, and anything else that lists pieces, reads only this.
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"statement_version_number": 1,
|
|
123
|
+
"name": "@studio/dash-move",
|
|
124
|
+
"piece_version": "1.0.0",
|
|
125
|
+
"kind": "extension",
|
|
126
|
+
"standard": "@studio/standard",
|
|
127
|
+
"summary": "A dash for the character: a burst of speed with a cooldown.",
|
|
128
|
+
"license": "MIT",
|
|
129
|
+
"entry_path": "index.js",
|
|
130
|
+
"server_entry_path": null,
|
|
131
|
+
"file_paths": ["index.js", "index.d.ts", "piece.json.js", "README.md", "LICENSE.txt"],
|
|
132
|
+
"server_file_paths": [],
|
|
133
|
+
"needs": [
|
|
134
|
+
{ "name": "@studio/body", "version_range": "^1.0.0", "kind": "piece" },
|
|
135
|
+
{ "name": "@zaisma/piece", "version_range": "^1.0.0", "kind": "piece" },
|
|
136
|
+
{ "name": "three", "version_range": ">=0.160.0 <1.0.0", "kind": "library" }
|
|
137
|
+
],
|
|
138
|
+
"settings": [
|
|
139
|
+
{ "name": "dash_speed_m_per_sec", "value_kind": "number", "default_value": 14, "minimum_number": 1, "maximum_number": 60, "maximum_character_count": null, "choices": null, "summary": "How fast a dash moves the character." },
|
|
140
|
+
{ "name": "dash_cooldown_sec", "value_kind": "number", "default_value": 1.5, "minimum_number": 0, "maximum_number": 30, "maximum_character_count": null, "choices": null, "summary": "How long before the character can dash again." }
|
|
141
|
+
],
|
|
142
|
+
"hooks": [
|
|
143
|
+
{ "name": "before_dash", "hook_kind": "decision", "summary": "Asked before each dash with its distance in metres; answer another distance to change it, or 0 to stop it." },
|
|
144
|
+
{ "name": "dashed", "hook_kind": "event", "summary": "Told when a dash ends." }
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### What a piece states
|
|
150
|
+
|
|
151
|
+
Every field is there every time, and an unknown one is refused, so a typo never passes quietly.
|
|
152
|
+
|
|
153
|
+
| Field | What it holds |
|
|
154
|
+
| --- | --- |
|
|
155
|
+
| `statement_version_number` | The format this file is written in: `1`. A command that meets a higher number says to run the newest command instead of guessing. |
|
|
156
|
+
| `name` | The piece's name, as npm takes them. |
|
|
157
|
+
| `piece_version` | Its version: three numbers, like `1.0.0`. Follow semver: a change that breaks games raises the first number. |
|
|
158
|
+
| `kind` | `foundation`, `extension`, `game_system` or `template`. |
|
|
159
|
+
| `standard` | The standard it's built on, by its name on npm ([Standards](#standards)). |
|
|
160
|
+
| `summary` | A sentence or two on what it gives a game, up to 400 characters. |
|
|
161
|
+
| `license` | The licence it's under, as SPDX names it: `MIT`, `Apache-2.0`. |
|
|
162
|
+
| `entry_path` | The file a game starts from (in JavaScript, the one it imports); `null` for a piece with only game server files. |
|
|
163
|
+
| `server_entry_path` | The file a game server imports; `null` for a piece with no game server files. |
|
|
164
|
+
| `file_paths` | Every file a game gets, each by its path inside the piece: forward slashes, nothing hidden (no part starting with a dot) and nothing in `node_modules`. The `piece.json` always comes too and isn't listed. A template's are copied into the game's own folder. |
|
|
165
|
+
| `server_file_paths` | Every file a game server gets. A file both sides share is listed in both. Empty for a template, whose game server files are the game's own, under `zaisma-server/` in `file_paths`. |
|
|
166
|
+
| `needs` | What it needs: each `{ name, version_range, kind }`. |
|
|
167
|
+
| `settings` | Its settings: each `{ name, value_kind, default_value, minimum_number, maximum_number, maximum_character_count, choices, summary }`. Empty for a template. |
|
|
168
|
+
| `hooks` | Its hooks: each `{ name, hook_kind, summary }`. Empty for a template. |
|
|
169
|
+
|
|
170
|
+
**A need** is `{ name, version_range, kind }`. `version_range` is a semver range like `^1.0.0`, `>=0.160.0 <1.0.0` or `1.x || 2.x`. `kind` says what it is:
|
|
171
|
+
|
|
172
|
+
| Need `kind` | What it is |
|
|
173
|
+
| --- | --- |
|
|
174
|
+
| `piece` | Another piece, by its name. Brought when the game lacks it. |
|
|
175
|
+
| `library` | A library on npm that isn't a piece. The game's own is used when its `package.json` has one; else its browser files are brought. |
|
|
176
|
+
| `engine` | An engine that isn't a library on npm, by its name in lowercase (`godot`). Stated to the developer, never brought or checked. |
|
|
177
|
+
|
|
178
|
+
**A setting** names what it holds and its unit, in lowercase with underscores ([`docs/NAMING.md`](naming.md)): `jump_height_m`, `shadows_enabled`. Its `value_kind` says what it takes, and the fields that don't apply to that kind are `null`:
|
|
179
|
+
|
|
180
|
+
| `value_kind` | `default_value` | Also given |
|
|
181
|
+
| --- | --- | --- |
|
|
182
|
+
| `number` | a number | `minimum_number` and `maximum_number`: every number has a range |
|
|
183
|
+
| `integer` | a whole number | `minimum_number` and `maximum_number` |
|
|
184
|
+
| `boolean` | `true` or `false` | |
|
|
185
|
+
| `choice` | one of `choices` | `choices`: 2 to 50 lowercase words |
|
|
186
|
+
| `text` | text | `maximum_character_count` |
|
|
187
|
+
| `color` | six hex digits in lowercase, like `"#3fa9f5"` | |
|
|
188
|
+
|
|
189
|
+
A setting can be changed while playing. What can only be given once, when the piece is made, is an argument of its create call instead, explained in its reference.
|
|
190
|
+
|
|
191
|
+
**A hook** is `{ name, hook_kind, summary }`, `hook_kind` being `event` (the piece tells the game) or `decision` (the piece asks, and the game's answer is what happens). What a hook is called with is in the piece's reference.
|
|
192
|
+
|
|
193
|
+
### Its code
|
|
194
|
+
|
|
195
|
+
What makes a piece good to build on:
|
|
196
|
+
|
|
197
|
+
- **Files that run as they are,** with no build step. In JavaScript: plain ES modules that import the piece's own files, its needs, and nothing else.
|
|
198
|
+
- **Needs imported from where a game has them.** A game holds `@studio/dash-move` at `pieces/@studio/dash-move/`, so from there a piece of the same scope is `../body/index.js`, one of another scope `../../@zaisma/piece/index.js`, and one with no scope `../../round-timer/index.js`. A library is imported by its name (`three`).
|
|
199
|
+
- **One statement.** A JavaScript piece reads its own settings and hooks from `./piece.json.js`, the statement as a module, and opens them with `@zaisma/piece` (its [README](https://github.com/zaisma/zaisma-sdk/blob/main/pieces/piece/README.md) shows how). List `piece.json.js` in `file_paths`; `zaisma pieces check <folder> --fix` writes it from `piece.json`, and a piece whose two disagree is refused.
|
|
200
|
+
- **An `index.d.ts`** with every call, setting, hook and error explained and an example: it's what an AI reads.
|
|
201
|
+
- **Closed inputs and plain errors:** an unknown setting or argument is refused, and every error has a stable `code`, the `field` at fault and a `fix`.
|
|
202
|
+
- **Names that say what they hold** ([`docs/NAMING.md`](naming.md)).
|
|
203
|
+
- **No file without an extension** in a piece for a game whose folder is uploaded as it is: Zaisma's upload takes none, so a licence travels as `LICENSE.txt`.
|
|
204
|
+
|
|
205
|
+
### Check and publish
|
|
206
|
+
|
|
207
|
+
```
|
|
208
|
+
npx @zaisma/cli pieces check ./my-piece # before publishing
|
|
209
|
+
npx @zaisma/cli pieces check ./my-piece --fix # and write piece.json.js again from piece.json
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
The check reads the statement and the files it lists, and runs nothing. It ends with exit code 6 when the piece wouldn't add or would break in a game:
|
|
213
|
+
|
|
214
|
+
| Problem | Kind | What it found |
|
|
215
|
+
| --- | --- | --- |
|
|
216
|
+
| `bad_piece_statement` | refused | The piece.json isn't one: the message names the field. |
|
|
217
|
+
| `piece_statement_newer` | refused | The piece.json is written for a newer command than this one. |
|
|
218
|
+
| `missing_file` | refused | The piece.json lists a file that isn't there, or the file is a link. |
|
|
219
|
+
| `stale_statement_module` | refused | piece.json.js isn't piece.json as a module any more; --fix writes it again. |
|
|
220
|
+
| `package_disagrees` | refused | The package.json beside it has another name or version, or leaves a listed file out of what npm packs. |
|
|
221
|
+
| `unlisted_import` | refused | A file imports a file of the piece's own that the piece.json doesn't list, so a game wouldn't get it. |
|
|
222
|
+
| `undeclared_need` | refused | A file imports another piece or a library that isn't in needs. |
|
|
223
|
+
| `file_not_uploadable` | note | A file is of a type Zaisma's upload doesn't take, so a game whose folder is uploaded as it is can't hold the piece. |
|
|
224
|
+
| `no_reference` | note | The file a game imports has no .d.ts beside it: it's what an AI reads to use the piece without opening its code. |
|
|
225
|
+
| `no_readme` | note | There's no README.md among the piece's files. |
|
|
226
|
+
|
|
227
|
+
Publish it with `npm publish`, its `package.json` giving the same name and version as its `piece.json` and packing every file it lists; anyone adds it by name. A piece that isn't on npm is added from its folder or its `.tgz`.
|
|
228
|
+
|
|
229
|
+
## Errors
|
|
230
|
+
|
|
231
|
+
The command's errors, each with a `fix`:
|
|
232
|
+
|
|
233
|
+
| Code | What happened |
|
|
234
|
+
| --- | --- |
|
|
235
|
+
| `bad_piece_statement` | A piece's `piece.json` isn't one: `field` names what's wrong in it. |
|
|
236
|
+
| `piece_statement_newer` | A piece's `piece.json` is written for a newer command than this one: run the newest. |
|
|
237
|
+
| `bad_piece_source` | What was given isn't a piece's folder, its `.tgz` or a name on npm, or its archive can't be trusted. |
|
|
238
|
+
| `piece_not_found` | There's no such piece or version where it was looked for. |
|
|
239
|
+
| `piece_source_unreachable` | npm couldn't be reached, so nothing was changed. |
|
|
240
|
+
| `piece_already_added` | `pieces add`: the game already has this piece at another version; a piece moves to another version only with `pieces update`. |
|
|
241
|
+
| `piece_not_added` | `pieces update`, `pieces remove`: the game has no such piece. |
|
|
242
|
+
| `piece_version_clash` | Two pieces need versions of the same thing that don't overlap, so nothing was changed; the error says both versions and the ways out. |
|
|
243
|
+
| `piece_need_unmet` | Something a piece needs wasn't found, so nothing was changed. |
|
|
244
|
+
| `piece_edited` | `pieces update`, `pieces remove`: the piece's files in the game were changed by hand; `--discard-edits` loses the edits. |
|
|
245
|
+
| `piece_source_needed` | `pieces update`: the piece came from a folder or a `.tgz`, so `--from` must say where the new version is. |
|
|
246
|
+
| `piece_not_updatable` | `pieces update`: a template is copied once and is the game's own. |
|
|
247
|
+
| `piece_not_removable` | `pieces remove`: a template's files are the game's own. |
|
|
248
|
+
| `piece_still_needed` | `pieces remove`: another of the game's pieces needs this one, so nothing was changed. |
|
|
249
|
+
| `template_file_exists` | `pieces add`: a template would write over a file the game already has, so nothing was changed. |
|
|
250
|
+
| `bad_pieces_record` | The game's `pieces/pieces.json` can't be read. |
|
|
251
|
+
| `pieces_record_newer` | The game's `pieces/pieces.json` was written by a newer command than this one: run the newest. |
|
package/zaisma.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import { fileURLToPath } from "node:url";
|
|
|
12
12
|
import { createBrotliDecompress, createGunzip } from "node:zlib";
|
|
13
13
|
import { CHECKED_TEXT_EXTENSIONS, GAME_FILE_EXTENSIONS, PRECOMPRESSED_EXTENSIONS, checkGameFiles, extensionOf, findOutsideReferences } from "./check.mjs";
|
|
14
14
|
import { assetHeadSizes } from "./performance.mjs";
|
|
15
|
+
import { PiecesError, addPiece, checkPiece, listPieces, newerPieces, removePiece, updatePiece } from "./pieces.mjs";
|
|
15
16
|
import { findChrome, openChrome } from "./chrome.mjs";
|
|
16
17
|
import { SHADER_CHECK_PAGE, SHADER_LIMITS, isShaderCheckPassing, shaderCheckPageExpressions, shaderDraftAnswer, shaderRenderFromPage, shaderRenderInputOf } from "./shader-check.mjs";
|
|
17
18
|
|
|
@@ -126,7 +127,7 @@ const EXIT_CODES = {
|
|
|
126
127
|
held: { exitCode: 3, meaning: "upload: the version is held for a person at Zaisma to look at, usually within a day." },
|
|
127
128
|
rejected: { exitCode: 4, meaning: "upload: the version was rejected. Its review_reason and findings say why and how to fix it." },
|
|
128
129
|
still_scanning: { exitCode: 5, meaning: "upload: the version was still being scanned after 10 minutes. Check it later with zaisma versions <slug>." },
|
|
129
|
-
problems_found: { exitCode: 6, meaning: "check: something in the game won't work on Zaisma as it is, and the upload command doesn't fix it; or the shader doesn't compile, is too slow or flashes. The problems say what and how to fix it." },
|
|
130
|
+
problems_found: { exitCode: 6, meaning: "check: something in the game won't work on Zaisma as it is, and the upload command doesn't fix it; or the shader doesn't compile, is too slow or flashes; or pieces check: the piece wouldn't add or would break in a game. The problems say what and how to fix it." },
|
|
130
131
|
};
|
|
131
132
|
|
|
132
133
|
/** The errors only the command itself answers with; every other code is the API's (ERROR_CODES in packages/core/src/errors.ts). */
|
|
@@ -159,8 +160,27 @@ const COMMAND_ERROR_CODES = {
|
|
|
159
160
|
unexpected_answer: "Zaisma answered without JSON, like a page from a network in between.",
|
|
160
161
|
skill_not_ours: "skill: a zaisma skill this command didn't install is already in that folder, so nothing was written; field names the folder.",
|
|
161
162
|
install_not_confirmed: "skill: nothing was installed, since nobody answered the question: give --yes to install without it.",
|
|
163
|
+
bad_piece_statement: "pieces: a piece's piece.json isn't one: field names what's wrong in it.",
|
|
164
|
+
piece_statement_newer: "pieces: a piece's piece.json is written for a newer command than this one: run the newest.",
|
|
165
|
+
bad_piece_source: "pieces: what was given isn't a piece's folder, its .tgz or a name on npm, or its archive can't be trusted.",
|
|
166
|
+
piece_not_found: "pieces: there's no such piece or version where it was looked for.",
|
|
167
|
+
piece_source_unreachable: "pieces: npm couldn't be reached, so nothing was changed.",
|
|
168
|
+
piece_already_added: "pieces add: the game already has this piece at another version; a piece moves to another version only with pieces update.",
|
|
169
|
+
piece_not_added: "pieces update, pieces remove: the game has no such piece.",
|
|
170
|
+
piece_version_clash: "pieces: two pieces need versions of the same thing that don't overlap, so nothing was changed; the error says both versions and the ways out.",
|
|
171
|
+
piece_need_unmet: "pieces: something a piece needs wasn't found, so nothing was changed.",
|
|
172
|
+
piece_edited: "pieces update, pieces remove: the piece's files in the game were changed by hand; --discard-edits loses the edits.",
|
|
173
|
+
piece_source_needed: "pieces update: the piece came from a folder or a .tgz, so --from must say where the new version is.",
|
|
174
|
+
piece_not_updatable: "pieces update: a template is copied once and is the game's own.",
|
|
175
|
+
piece_not_removable: "pieces remove: a template's files are the game's own.",
|
|
176
|
+
piece_still_needed: "pieces remove: another of the game's pieces needs this one, so nothing was changed.",
|
|
177
|
+
template_file_exists: "pieces add: a template would write over a file the game already has, so nothing was changed.",
|
|
178
|
+
bad_pieces_record: "pieces: the game's pieces/pieces.json can't be read.",
|
|
179
|
+
pieces_record_newer: "pieces: the game's pieces/pieces.json was written by a newer command than this one: run the newest.",
|
|
162
180
|
};
|
|
163
181
|
|
|
182
|
+
const GAME_FOLDER = { hasValue: true, placeholder: "<folder>", about: "The game's folder, the one with its index.html (or its source, for a game that's built); this folder if left out" };
|
|
183
|
+
const DRY_RUN = { hasValue: false, about: "Say what it would do, and change nothing" };
|
|
164
184
|
const BY_ME = { hasValue: false, about: "Mark it as written by you; otherwise it says your AI wrote it" };
|
|
165
185
|
const TEXT = { hasValue: true, placeholder: '"…"', about: "The text, in markdown; or pipe it in" };
|
|
166
186
|
const KEYS = { hasValue: true, placeholder: "'[…]'", about: 'Only these localStorage keys, as a JSON list, like \'["coins", "level"]\'' };
|
|
@@ -387,10 +407,46 @@ const COMMANDS = {
|
|
|
387
407
|
yes: { hasValue: false, about: "Install without asking first" },
|
|
388
408
|
},
|
|
389
409
|
},
|
|
410
|
+
pieces: {
|
|
411
|
+
about: "A game's pieces, the shared building blocks it's made from (docs/PIECES.md): each one's name, version, kind, standard, licence, what it needs, its settings and hooks and where to import it from, and whether its files were changed by hand",
|
|
412
|
+
arguments: [],
|
|
413
|
+
flags: { folder: GAME_FOLDER },
|
|
414
|
+
},
|
|
415
|
+
"pieces add": {
|
|
416
|
+
about: "Add a piece to a game, with what it needs: a piece the game already has is left exactly as it is, and a version that doesn't fit stops with both versions named and nothing added. The piece is a folder, the .tgz that npm pack makes, or a name on npm with an optional range. Adding never runs a piece's code",
|
|
417
|
+
arguments: [{ name: "source" }],
|
|
418
|
+
flags: { folder: GAME_FOLDER, "dry-run": DRY_RUN },
|
|
419
|
+
},
|
|
420
|
+
"pieces update": {
|
|
421
|
+
about: "Move one of a game's pieces to another version: only the one you name, and only when everything else in the game accepts it",
|
|
422
|
+
arguments: [{ name: "name" }],
|
|
423
|
+
flags: {
|
|
424
|
+
folder: GAME_FOLDER,
|
|
425
|
+
version: { hasValue: true, placeholder: "<range>", about: 'The version to move to, or a range to take the newest of, like "^1.2"; the newest if left out' },
|
|
426
|
+
from: { hasValue: true, placeholder: "<source>", about: "Where the new version is, for a piece that came from a folder or a .tgz" },
|
|
427
|
+
"discard-edits": { hasValue: false, about: "Replace the piece's files even though they were changed by hand" },
|
|
428
|
+
"dry-run": DRY_RUN,
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
"pieces remove": {
|
|
432
|
+
about: "Take one piece out of a game, unless another of its pieces needs it. Nothing else is removed: what it needed and nothing needs now is named",
|
|
433
|
+
arguments: [{ name: "name" }],
|
|
434
|
+
flags: { folder: GAME_FOLDER, "discard-edits": { hasValue: false, about: "Remove the piece's files even though they were changed by hand" }, "dry-run": DRY_RUN },
|
|
435
|
+
},
|
|
436
|
+
"pieces newer": {
|
|
437
|
+
about: "Which of a game's pieces have a newer version on npm, the newest the rest of the game accepts, and what holds it back. It changes nothing: a version moves only with pieces update",
|
|
438
|
+
arguments: [],
|
|
439
|
+
flags: { folder: GAME_FOLDER },
|
|
440
|
+
},
|
|
441
|
+
"pieces check": {
|
|
442
|
+
about: "Check a piece you're making before you publish it: its piece.json, the files it lists, that every import is a listed file or a stated need, and its package.json beside it",
|
|
443
|
+
arguments: [{ name: "folder" }],
|
|
444
|
+
flags: { fix: { hasValue: false, about: "Write piece.json.js again from piece.json first, when the piece has one" } },
|
|
445
|
+
},
|
|
390
446
|
help: { about: "This help; with --json, every command, flag, exit code and error code", arguments: [], flags: {} },
|
|
391
447
|
};
|
|
392
448
|
/** Commands with a second word, like zaisma forum post. */
|
|
393
|
-
const SUBCOMMANDS = { clip: ["remove"], links: ["set", "remove"], forum: ["post", "message", "reply"], database: ["query", "batch", "export", "import", "restore", "undo-restore"], saves: ["get", "change", "replace", "reset", "copies", "copy", "restore"], secrets: ["set", "delete"], items: ["set", "remove"], "kept-rooms": ["delete", "bring-back", "erase-now", "restore", "undo-restore", "restores", "restore-all", "restore-all-status", "undo-restore-all"] };
|
|
449
|
+
const SUBCOMMANDS = { pieces: ["add", "update", "remove", "newer", "check"], clip: ["remove"], links: ["set", "remove"], forum: ["post", "message", "reply"], database: ["query", "batch", "export", "import", "restore", "undo-restore"], saves: ["get", "change", "replace", "reset", "copies", "copy", "restore"], secrets: ["set", "delete"], items: ["set", "remove"], "kept-rooms": ["delete", "bring-back", "erase-now", "restore", "undo-restore", "restores", "restore-all", "restore-all-status", "undo-restore-all"] };
|
|
394
450
|
/** Flags every command takes. */
|
|
395
451
|
const GLOBAL_FLAGS = {
|
|
396
452
|
json: { hasValue: false, about: "Print the API's answer as JSON, as-is (on failure its { error }), and nothing else" },
|
|
@@ -611,7 +667,8 @@ async function walk(root) {
|
|
|
611
667
|
const hiddenPaths = [];
|
|
612
668
|
async function visit(dir) {
|
|
613
669
|
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
614
|
-
|
|
670
|
+
// A .d.ts is for editors and AIs (a piece's index.d.ts, the SDK's types): it never runs, so it's never checked or sent.
|
|
671
|
+
if (JUNK.has(entry.name) || entry.name.endsWith(".d.ts")) continue;
|
|
615
672
|
const full = join(dir, entry.name);
|
|
616
673
|
if (entry.name.startsWith(".")) {
|
|
617
674
|
hiddenPaths.push(relative(root, full).split(sep).join("/"));
|
|
@@ -2304,6 +2361,7 @@ async function run({ command, values, flags, globalFlags, rest }) {
|
|
|
2304
2361
|
return EXIT_CODES.done;
|
|
2305
2362
|
}
|
|
2306
2363
|
if (command === "skill") return installSkill(flags);
|
|
2364
|
+
if (command === "pieces" || command.startsWith("pieces ")) return pieces(command, values, flags);
|
|
2307
2365
|
await updateSkillCopies();
|
|
2308
2366
|
if (command === "games") {
|
|
2309
2367
|
const answer = await api("GET", "/games");
|
|
@@ -2464,6 +2522,93 @@ async function updateSkillCopies() {
|
|
|
2464
2522
|
if (skillUpdates.length && !isJson) console.error(`Updated the Zaisma skill in ${skillUpdates.length} ${skillUpdates.length === 1 ? "AI tool" : "AI tools"} to ${CLI_VERSION}.`);
|
|
2465
2523
|
}
|
|
2466
2524
|
|
|
2525
|
+
/** zaisma pieces: a game's shared building blocks (pieces.mjs). Nothing reaches Zaisma: it reads and writes the game's folder. */
|
|
2526
|
+
async function pieces(command, values, flags) {
|
|
2527
|
+
const folder = resolve(command === "pieces check" ? values.folder : (flags.folder ?? "."));
|
|
2528
|
+
if (!(await stat(folder).catch(() => null))?.isDirectory()) refuse("not_a_folder", { message: `${folder} isn't a folder.`, field: "folder", fix: command === "pieces check" ? "Give the folder of the piece you're making." : "Give the game's folder with --folder, or run it inside the folder." });
|
|
2529
|
+
const isDryRun = Boolean(flags["dry-run"]);
|
|
2530
|
+
const isDiscardingEdits = Boolean(flags["discard-edits"]);
|
|
2531
|
+
let answer;
|
|
2532
|
+
try {
|
|
2533
|
+
if (command === "pieces") answer = await listPieces(folder);
|
|
2534
|
+
else if (command === "pieces add") answer = await addPiece(folder, values.source, { isDryRun });
|
|
2535
|
+
else if (command === "pieces update") answer = await updatePiece(folder, values.name, { versionRange: flags.version ?? "*", source: flags.from ?? null, isDiscardingEdits, isDryRun });
|
|
2536
|
+
else if (command === "pieces remove") answer = await removePiece(folder, values.name, { isDiscardingEdits, isDryRun });
|
|
2537
|
+
else if (command === "pieces newer") answer = await newerPieces(folder);
|
|
2538
|
+
else answer = await checkPiece(folder, { isFixing: Boolean(flags.fix) });
|
|
2539
|
+
} catch (error) {
|
|
2540
|
+
if (error instanceof PiecesError) throw new CommandError(error.error, EXIT_CODES.failed.exitCode);
|
|
2541
|
+
throw error;
|
|
2542
|
+
}
|
|
2543
|
+
const exit = command === "pieces check" && !answer.is_ready ? EXIT_CODES.problems_found : EXIT_CODES.done;
|
|
2544
|
+
if (isJson) {
|
|
2545
|
+
printAnswer(answer);
|
|
2546
|
+
return exit;
|
|
2547
|
+
}
|
|
2548
|
+
const needLine = (need) => `${need.name} ${need.version_range}${need.kind === "piece" ? "" : ` (${need.kind})`}`;
|
|
2549
|
+
const sayPiece = (shown, firstWord) => {
|
|
2550
|
+
console.log(`${firstWord}${shown.name} ${shown.piece_version} ${shown.kind}, standard ${shown.standard}, ${shown.license}${shown.is_edited ? " [its files were changed by hand]" : ""}`);
|
|
2551
|
+
console.log(` ${shown.summary}`);
|
|
2552
|
+
if (shown.needs.length) console.log(` needs: ${shown.needs.map(needLine).join(", ")}`);
|
|
2553
|
+
if (shown.import_path) console.log(` in the game: import ... from "${shown.import_path}"`);
|
|
2554
|
+
if (shown.server_import_path) console.log(` in zaisma-server/: import ... from "${shown.server_import_path}"`);
|
|
2555
|
+
if (shown.settings.length) console.log(` settings: ${shown.settings.map((setting) => setting.name).join(", ")}`);
|
|
2556
|
+
if (shown.hooks.length) console.log(` hooks: ${shown.hooks.map((hook) => hook.name).join(", ")}`);
|
|
2557
|
+
};
|
|
2558
|
+
const sayLibrary = (shown, firstWord) => console.log(`${firstWord}${shown.name} ${shown.library_version} library${shown.license ? `, ${shown.license}` : ""}${shown.is_edited ? " [its files were changed by hand]" : ""}`);
|
|
2559
|
+
const sayImportMap = (importMap) => {
|
|
2560
|
+
if (!Object.keys(importMap.imports).length) return;
|
|
2561
|
+
console.log("\nA page with no bundler needs this before its scripts, so the pieces find their libraries:");
|
|
2562
|
+
console.log(` <script type="importmap">${JSON.stringify(importMap)}</script>`);
|
|
2563
|
+
};
|
|
2564
|
+
const sayBrought = (brought, verb) => {
|
|
2565
|
+
for (const shown of brought.added_pieces) sayPiece(shown, `${verb} `);
|
|
2566
|
+
for (const shown of brought.added_libraries) sayLibrary(shown, `${verb} `);
|
|
2567
|
+
if (brought.kept_names.length) console.log(`Already in the game, left exactly as they are: ${brought.kept_names.join(", ")}.`);
|
|
2568
|
+
for (const need of brought.engine_needs) console.log(`${need.needed_by_name} needs the engine ${need.name} ${need.version_range}: the command can't bring or check an engine, so the game must already be on it.`);
|
|
2569
|
+
// A game's first pieces bring its first standards, which is no news; a standard beside the ones it had is.
|
|
2570
|
+
if (brought.new_standards.length && brought.standards.length > brought.new_standards.length) console.log(`${isDryRun ? "It would bring" : "The game now holds"} pieces built on ${brought.new_standards.join(" and ")}${brought.new_standards.length === 1 ? ", a standard" : ", standards"} it didn't have before: pieces of different standards aren't made to fit each other.`);
|
|
2571
|
+
};
|
|
2572
|
+
const dryRunLine = "Nothing was changed: this was a dry run.";
|
|
2573
|
+
if (command === "pieces") {
|
|
2574
|
+
if (!answer.pieces.length && !answer.libraries.length) console.log("This game has no pieces yet. Add one with: zaisma pieces add <a piece's folder, .tgz or npm name>");
|
|
2575
|
+
for (const shown of answer.pieces) sayPiece(shown, "");
|
|
2576
|
+
for (const shown of answer.libraries) sayLibrary(shown, "");
|
|
2577
|
+
sayImportMap(answer.import_map);
|
|
2578
|
+
} else if (command === "pieces add") {
|
|
2579
|
+
if (!answer.added_pieces.length && !answer.added_libraries.length) console.log("The game already has it: nothing to do.");
|
|
2580
|
+
sayBrought(answer, isDryRun ? "Would add" : "Added");
|
|
2581
|
+
sayImportMap(answer.import_map);
|
|
2582
|
+
console.log(isDryRun ? `\n${dryRunLine}` : "\nEach piece's index.d.ts and README say how to use it. Change a piece through its settings and hooks, never its files.");
|
|
2583
|
+
} else if (command === "pieces update") {
|
|
2584
|
+
const [updated, earlierVersion] = answer.updated_piece ? [answer.updated_piece.piece_version, answer.earlier_piece_version] : [answer.updated_library?.library_version, answer.earlier_library_version];
|
|
2585
|
+
if (!updated) console.log(`${answer.name} is already at ${answer.earlier_piece_version ?? answer.earlier_library_version}: nothing to do.`);
|
|
2586
|
+
else {
|
|
2587
|
+
console.log(`${isDryRun ? "Would move" : "Moved"} ${answer.name} from ${earlierVersion} to ${updated}.`);
|
|
2588
|
+
sayBrought(answer, isDryRun ? "Would add" : "Added");
|
|
2589
|
+
sayImportMap(answer.import_map);
|
|
2590
|
+
if (isDryRun) console.log(dryRunLine);
|
|
2591
|
+
}
|
|
2592
|
+
} else if (command === "pieces remove") {
|
|
2593
|
+
console.log(`${isDryRun ? "Would remove" : "Removed"} ${answer.removed_name} (${answer.removed_folders.join(", ")}).`);
|
|
2594
|
+
if (answer.no_longer_needed_names.length) console.log(`No piece needs these any more: ${answer.no_longer_needed_names.join(", ")}. They stay until you remove them: the game's own code may use them.`);
|
|
2595
|
+
if (isDryRun) console.log(dryRunLine);
|
|
2596
|
+
} else if (command === "pieces newer") {
|
|
2597
|
+
const newerLine = (name, current, newest, newestAccepted, heldBackByNames) => {
|
|
2598
|
+
if (newestAccepted === newest) return `${name} ${current} → ${newest}: zaisma pieces update ${name}`;
|
|
2599
|
+
return `${name} ${current} → ${newest}, held back by ${heldBackByNames.join(" and ")}${newestAccepted ? `; the newest they accept is ${newestAccepted}: zaisma pieces update ${name} --version ${newestAccepted}` : ""}`;
|
|
2600
|
+
};
|
|
2601
|
+
for (const shown of answer.newer_pieces) console.log(newerLine(shown.name, shown.piece_version, shown.newest_piece_version, shown.newest_accepted_piece_version, shown.held_back_by_names));
|
|
2602
|
+
for (const shown of answer.newer_libraries) console.log(newerLine(shown.name, shown.library_version, shown.newest_library_version, shown.newest_accepted_library_version, shown.held_back_by_names));
|
|
2603
|
+
if (!answer.newer_pieces.length && !answer.newer_libraries.length) console.log("Nothing newer on npm.");
|
|
2604
|
+
if (answer.unchecked_names.length) console.log(`Not on npm, so not looked up: ${answer.unchecked_names.join(", ")}.`);
|
|
2605
|
+
} else {
|
|
2606
|
+
for (const problem of answer.problems) console.log(`${problem.problem_kind === "refused" ? "✗" : "·"} ${problem.path ? `${problem.path}: ` : ""}${problem.message} ${problem.fix} (${problem.code})`);
|
|
2607
|
+
console.log(answer.is_ready ? `${answer.name} ${answer.piece_version} is ready: add it to a game with zaisma pieces add ${values.folder}, or publish it with npm publish.` : "Fix what's marked ✗, then check again.");
|
|
2608
|
+
}
|
|
2609
|
+
return exit;
|
|
2610
|
+
}
|
|
2611
|
+
|
|
2467
2612
|
/** zaisma skill: install the skill into each AI tool found, after one question (or --yes). */
|
|
2468
2613
|
async function installSkill(flags) {
|
|
2469
2614
|
if (flags.folder !== undefined && flags.project) refuse("conflicting_flags", { message: "--folder and --project don't go together.", field: "project", fix: "Give --folder to install into one skills folder, or --project to install into this project's tool folders." });
|