@patterkit/cli 0.8.0 → 0.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 (3) hide show
  1. package/README.md +66 -267
  2. package/dist/cli.js +14189 -13607
  3. package/package.json +4 -4
package/README.md CHANGED
@@ -1,290 +1,89 @@
1
1
  # `patter` - the Patter CLI
2
2
 
3
- Command-line tooling for **Patter** projects: scaffold, validate, format, play,
4
- compile, report, and package authored dialogue. The CLI is a thin front-end over
5
- `@patterkit/ops` (the shared operations layer), so it behaves identically to the
6
- Patterpad editor and to CI.
3
+ Command-line tooling for **Patter** projects: scaffold, validate, format, compile, play, test
4
+ coverage, localise, report, and share authored dialogue. The CLI is a thin front end over
5
+ `@patterkit/ops` (the shared operations layer), so it does what the Patterpad editor does, in CI or a
6
+ terminal.
7
7
 
8
- ## Install / run
8
+ The full reference, with every flag, is at **[patterkit.dev/cli](https://patterkit.dev/cli/)**, and
9
+ `patter <command> --help` prints any command's usage.
9
10
 
10
- - **Standalone binary** (no Node required): the `patter` executable shipped for
11
- your platform - put it on your `PATH`.
12
- - **npm** (once published): `npm i -g @patterkit/cli`, which installs the
13
- `patter` command.
14
- - **From a checkout of this repo:** `node packages/cli/dist/cli.js <command>`
15
- (run `npm run build` in `packages/cli` first).
11
+ ## Install / run
16
12
 
17
- Running `patter` with no command prints usage.
13
+ - **npm:** `npm i -g @patterkit/cli`, which installs the `patter` command.
14
+ - **Standalone binary** (no Node needed): the `patter` executable for your platform, from
15
+ [the downloads page](https://patterkit.dev/download/). Put it on your `PATH`.
16
+ - **From a checkout of this repo:** `node packages/cli/dist/cli.js <command>` (run `npm run build` in
17
+ `packages/cli` first).
18
18
 
19
19
  ## Quick start
20
20
 
21
21
  ```sh
22
- patter init my-game --name "My Game" --vcs git # scaffold a project
23
- patter play my-game # play it through the runtime
24
- patter export my-game # compile -> dist/my-game.patterc
22
+ patter init my-game --name "My Game" --vcs git # scaffold my-game.patter
23
+ patter play my-game.patter # play it through the runtime
24
+ patter export my-game.patter # compile -> patter-dist/my_game.patterc beside it
25
25
  ```
26
26
 
27
27
  ## Commands
28
28
 
29
- Most commands accept a project `path` - a directory, or any file inside the
30
- project, from which the CLI walks up to the nearest `*.patterproj` - defaulting
31
- to the current directory (`.`). The exceptions: `format` takes explicit files,
32
- `unpack` takes a `.patter` file, and `resolve` takes a lookup query.
33
-
34
- ### `patter init [dir]`
35
-
36
- Scaffold a new project: the project file, a minimal playable starter scene + its
37
- strings, an `.editorconfig`, a `vcs-setup.md`, and the VCS config for your VCS.
38
- Refuses to scaffold over an existing project.
39
-
40
- | Option | Values | Default | Meaning |
41
- |--------|--------|---------|---------|
42
- | `--name <x>` | string | directory basename | Project display name. |
43
- | `--vcs <x>` | `git` \| `perforce` \| `plastic` \| `svn` | none | Emit tailored VCS config (`.gitattributes` + an ignore file for git/perforce/plastic; SVN guidance in `vcs-setup.md`). |
44
- | `--bundle <x>` | `commit` \| `ignore` | `commit` | Whether the compiled `.patterc` bundle is committed (kept honest by the validate staleness gate) or git-ignored and built in CI. |
45
-
46
- ```sh
47
- patter init # scaffold in the current directory
48
- patter init game --name "Heist" # named, in ./game
49
- patter init game --vcs git --bundle ignore
50
- ```
51
-
52
- ### `patter validate [path]`
53
-
54
- Validate a project: structure + invariants (unique ids, no dangling jumps,
55
- non-empty names, cast membership, scope rules), condition / interpolation
56
- expressions, encoding + line-endings (UTF-8 no-BOM, LF), and **bundle staleness**
57
- (any committed `.patterc` whose embedded hash no longer matches source). Exits
58
- non-zero if there are any issues. Ideal as a pre-commit hook and in CI.
59
-
60
- Where the game keeps a shared `game-scopes/` folder (found by walking up from the
61
- project, or named by the project's `gameScopes`), it also checks the names and
62
- types the project uses from other tools' scopes against their files, and reports
63
- the folder (`[game-scopes]`): a file that won't parse or a scope two files claim is
64
- an issue; another tool's undeclared name, a type mismatch, a write to a read-only
65
- property, `patter.scopes.json` out of date, or the project's copy of a game scope
66
- differing from `game.scopes.json` is a **warning**, printed as one, which never
67
- fails the run.
68
-
69
- ```sh
70
- patter validate
71
- patter validate my-game
72
- ```
73
-
74
- ### `patter format [files...]` (alias `fmt`)
75
-
76
- Rewrite source files to canonical form (sorted keys, 2-space indent, LF, final
77
- newline, trailing commas). Pass explicit files.
78
-
79
- | Option | Meaning |
80
- |--------|---------|
81
- | `--check` | Report what *would* change and write nothing; exits non-zero if any file is non-canonical (for CI). |
82
-
83
- ```sh
84
- patter format scenes/*.patterflow
85
- patter format --check scenes/opening.patterflow # CI: fail if not canonical
86
- ```
87
-
88
- ### `patter export [path]`
89
-
90
- Compile a project (flow + selected locales) to a `.patterc` runtime bundle -
91
- strict JSON the game runtime loads.
92
-
93
- | Option | Meaning |
94
- |--------|---------|
95
- | `-o <file>` | Write to `<file>`. |
96
- | `-o -` | Stream the bundle to stdout (for pipelines). |
97
- | *(no `-o`)* | Write the conventional path: the project's `export.bundle`, else `dist/<project-name>.patterc`. |
98
-
99
- ```sh
100
- patter export # -> dist/<name>.patterc
101
- patter export -o build/game.patterc
102
- patter export -o - | gzip > game.patterc.gz
103
- ```
104
-
105
- Where the game keeps a shared `game-scopes/` folder, `export` also writes
106
- `game-scopes/patter.scopes.json` (the project's shared `@patter` properties), and
107
- only when its content would change. Not with `-o -`.
108
-
109
- ### `patter play [path]`
110
-
111
- Play a project through the reference runtime and print a transcript - lines,
112
- text, game events, and choices. Exits non-zero if the playthrough cannot finish
113
- (a stall / max-steps), which makes it usable as a smoke test. A line naming another
114
- engine's scope (`@story.act`) plays where the game's `game-scopes/` folder declares
115
- it, standing that engine in from its declared defaults; without the folder it is
116
- refused, since Patter is playing alone. `patter coverage` does the same.
117
-
118
- | Option | Values | Meaning |
119
- |--------|--------|---------|
120
- | `--scene <id>` | scene id | Start at this scene. |
121
- | `--block <id>` | block id | Start at this block. |
122
- | `--choices <a,b,c>` | comma list | Auto-pick these option ids, in order, at successive choices. |
123
- | `--seed <n>` | integer | Seed the runtime PRNG for reproducible selection. |
124
-
125
- ```sh
126
- patter play
127
- patter play --scene scn_tavern --choices opt_work,opt_secret
128
- patter play --seed 42
129
- ```
130
-
131
- ### `patter coverage [path]`
132
-
133
- Play the story many times with random choices and count how often each beat comes
134
- up, to find content no player can reach. The summary counts beats reached, never
135
- reached, and rarely reached (in fewer than 5% of runs), and says how the runs
136
- ended: reached the end, stalled at a choice with nothing to pick, or hit the step
137
- limit. The table gives each beat's **reached** (the share of runs that played it)
138
- and **played** (times it played in all runs), least reached first. Marks: `‼`
139
- never reached, `?` never reached but may just need an input driver, `~` rarely
140
- reached. Choices that ran dry (nothing to take and no fallback) are listed too.
141
-
142
- | Option | Values | Meaning |
143
- |--------|--------|---------|
144
- | `--runs <n>` | integer | How many playthroughs (default 5000). |
145
- | `--max-steps <n>` | integer | Steps before a run is stopped (default 200). |
146
- | `--seed <n>` | integer | The same seed gives the same result. |
147
- | `--scene <id>` / `--block <id>` | id | Start here instead of the project's start. |
148
- | `--order <o>` | `least` / `script` | Least reached first (default), or the script's order, scene by scene. |
149
- | `--fail-on-gap` | | Exit 1 if any beat is never reached (a CI gate). |
150
- | `--propose` | | Print suggested `@world` input drivers instead of running. |
151
- | `--json` | | The full report as JSON. |
152
-
153
- ```sh
154
- patter coverage
155
- patter coverage --runs 10000 --seed 7 --order script
156
- patter coverage --fail-on-gap
157
- ```
158
-
159
- ### `patter resolve <query> [path]`
160
-
161
- Look up an **id**, **handle**, or **name** and report what it is and where it
162
- lives (file + location path). The CLI counterpart to the editor's dual search -
163
- handy when a locale table or VO asset references something by id.
164
-
165
- ```sh
166
- patter resolve scn_tavern
167
- patter resolve "Tavern > Intro"
168
- ```
169
-
170
- ### `patter report [path]` (alias `stats`)
171
-
172
- Production report: writing/recording status against the project ladders, the
173
- voiced-vs-written line split, the burndown (done / to-write / projected), plan
174
- coverage, cut content, character rollups, and localisation staleness. Prints a
175
- compact summary by default.
176
-
177
- | Option | Meaning |
178
- |--------|---------|
179
- | `--xlsx <file>` | Also write a polished spreadsheet (Scenes / Characters / Localisation / Plan). |
180
- | `--json` | Emit the full structured report as JSON on stdout (for pipelines). With `--xlsx`, the "wrote" note goes to stderr so stdout stays pure JSON. |
181
-
182
- ```sh
183
- patter report
184
- patter stats --xlsx report.xlsx
185
- patter report --json | jq '.totals'
186
- ```
187
-
188
- ### `patter share-scopes [path] [--at <dir>]`
189
-
190
- Share the project's scopes with the game's other editing tools, as Patterpad's **File > Share Scopes
191
- with Other Tools** does: makes the game's `game-scopes/` folder (in `--at`, else at the
192
- version-control root above the project, else beside it) with `patter.scopes.json` and a
193
- `game.scopes.json` holding the project's own game scopes (its World properties), which the project
194
- keeps as its synced copy. A folder another tool already made is joined, not replaced: its
195
- `game.scopes.json` keeps every scope it holds and gains only the ones it lacks. When looking up from
196
- the project wouldn't find the folder, the project names it in `gameScopes`. A project that already
197
- shares its scopes is refused.
198
-
199
- ### `patter pack [path] -o <file.patterpack>`
200
-
201
- Pack a project (the `.patter` folder) into a single portable **`.patterpack`** - a
202
- binary zip envelope, the send-and-return artifact for collaborators without VCS
203
- (you cannot email a folder; this is the zip of it). `-o` is required. When the
204
- project has a game scopes folder (`game-scopes/`, found as every command finds it),
205
- the pack also carries a read-only snapshot of every `*.scopes.json` in it, as
206
- `game-scopes/<name>` entries listed in the manifest's `gameScopes`. A project with
207
- no folder packs to exactly the same bytes as before.
208
-
209
- ```sh
210
- patter pack my-game.patter -o my-game.patterpack
211
- ```
212
-
213
- ### `patter unpack <file.patterpack> -o <dir>`
214
-
215
- Explode a `.patterpack` back into source shards under `<dir>`. Both the input
216
- file and `-o <dir>` are required. Entry paths that would escape the target
217
- directory are rejected. A pack's game scopes snapshot is written to
218
- `<dir>/game-scopes/`, where the unpacked project finds it first, so `validate`,
219
- `play`, and `coverage` there know the other tools' scopes.
220
-
221
- | Option | Meaning |
222
- |--------|---------|
223
- | `--merge --base <sent.patterpack>` | Instead of extracting, **fold a returned document's edits back into the existing project** at `<dir>` via the 3-way merge engine. `--base` is the `.patterpack` you originally packed and sent (the common ancestor). Per shard: a clean merge updates the file, a conflict writes a `.patterconflict` sidecar; a file only in the returned document is added. Exits non-zero if any shard conflicts. The returned pack's game scopes snapshot is never written. When the project has a game scopes folder and the returned project file's copy of the game's scopes (World properties) differs from the base pack's, the scopes they changed are written to `game.scopes.json` (the rest of the file is kept) and a `game scopes:` line says so. |
224
-
225
- ```sh
226
- patter unpack returned.patterpack -o ./my-game.patter --merge --base sent.patterpack
227
- ```
228
-
229
- ### `patter merge BASE OURS THEIRS`
230
-
231
- Domain-aware **3-way merge** of Patter source by node id (not by line), for all
232
- four shard types (flow / loc / authoring / project). The merged output is always
233
- valid canonical source; conflicts resolve provisionally to OURS and are listed
234
- in a `.patterconflict` sidecar. Mostly invoked by your VCS via `mergetool`, but
235
- usable directly.
236
-
237
- | Option | Meaning |
238
- |--------|---------|
239
- | `-o <file>` | Write the merged result to `<file>` (+ `<file>.patterconflict` on conflicts). Without it, the merge streams to stdout. |
240
- | `--type <t>` | Force the type (`flow`/`loc`/`authoring`/`project`); default auto-detects from the `schema` tag. |
241
- | `--json` | Emit the structured `{ type, merged, conflicts, warnings }` as JSON. |
242
-
243
- Exit: `0` clean, `1` conflicts (sidecar written), `2` error. `%O %A %B` from a
244
- git driver map to BASE OURS THEIRS.
245
-
246
- ```sh
247
- patter merge base.patterflow ours.patterflow theirs.patterflow -o ours.patterflow
248
- patter merge base.patterloc ours.patterloc theirs.patterloc --json
249
- ```
250
-
251
- ### `patter mergetool BASE THEIRS OURS OUT`
252
-
253
- The **VCS merge-tool wrapper** - register it once as your single global merge
254
- tool. It sniffs the path: Patter source goes to the structured merge above;
255
- anything else is handed to your normal tool. Arguments are in the BASE THEIRS
256
- OURS OUT order that Perforce / Plastic / SVN all use; `patter init --vcs <x>`
257
- writes the exact registration into `vcs-setup.md`. (git instead uses its
258
- per-path driver and calls `patter merge` directly.)
259
-
260
- | Option | Meaning |
261
- |--------|---------|
262
- | `--fallback <cmd>` | The tool to run for non-Patter files (e.g. `p4merge`, `"code --wait --merge"`). It receives the same four file arguments. |
263
-
264
- ```sh
265
- patter mergetool $BASE $THEIRS $OURS $OUT --fallback p4merge
266
- ```
29
+ Most commands take a project `path`: a folder, or any file inside the project, from which the CLI
30
+ walks up to the nearest `*.patterproj`. It defaults to the current folder.
31
+
32
+ | Command | What it does |
33
+ |---------|--------------|
34
+ | `init [dir]` | Scaffold a new project with a starter scene and version-control config. |
35
+ | `validate [path]` | Check structure, expressions, interpolation, encoding, localisation files, a stale bundle, and unresolved merges. The command to gate a pull request on. |
36
+ | `format [paths...]` (`fmt`) | Rewrite Patter source to canonical form; `--check` for CI. Anything that is not a shard is left alone. |
37
+ | `export [path]` | Compile the `.patterc` bundle (plus the game's scopes file and the audio manifest, where the project has them). Refuses content `validate` finds errors in. |
38
+ | `export-html [path]` | One self-contained, playable `.html` page. |
39
+ | `export-script [path]` | A readable screenplay, as `.pdf` or `.docx`. |
40
+ | `play [path]` | Play the story non-interactively and print a transcript. |
41
+ | `coverage [path]` | Play the story many times with random choices and find content nobody reaches. |
42
+ | `resolve <query> [path]` | Find a line or node by id, Game ID, or name. |
43
+ | `usage <query> [path]` | Find everywhere a property is used. |
44
+ | `report [path]` (`stats`) | The production report; `--xlsx` for a spreadsheet, `--json` for pipelines. |
45
+ | `loc-export [path]` | Export strings for translation (JSON, Excel, or PO). |
46
+ | `loc-import <file> [path]` | Import a translated file back. |
47
+ | `voice-export [path]` | The voice-recording script, as a spreadsheet. |
48
+ | `export-editable [path]` | An editable `.docx` script for an editor outside Patter. |
49
+ | `import-editable <file> [path]` | Bring that file back as suggestions and comments. |
50
+ | `suggestions [path]` | List open suggestions; `--accept-clean` accepts the clean ones. |
51
+ | `share-scopes [path]` | Share the project's scopes with the game's other editing tools. |
52
+ | `pack [path] -o file` | Pack a project into one portable `.patterpack`. |
53
+ | `unpack <file> -o dir` | Explode a pack into a project, or with `--merge --base sent.patterpack`, fold a returned one back in. |
54
+ | `merge BASE OURS THEIRS` | 3-way structured merge of Patter source by node id (git's merge driver). |
55
+ | `mergetool BASE THEIRS OURS OUT` | The single merge tool for Perforce, Plastic, and SVN: Patter source to the structured merge, anything else to your usual tool. |
56
+ | `--version` | Print the version (also `-v`, `version`). |
57
+
58
+ ## Conventions
59
+
60
+ - Every write goes through your version control (checking a file out first, adding new files), so a
61
+ locked or read-only file fails the write rather than being overwritten.
62
+ - `patter <command> --help` (or `-h`, or `patter help <command>`) prints that command's usage.
63
+ - A flag takes its value as the next word or inline (`--seed=-5`). Anything starting with `-` is a
64
+ flag, so a mistyped one is refused rather than read as a path. `-o -` streams text output to stdout
65
+ where that makes sense.
66
+ - Usage errors are printed under `usage:`, followed by the command's whole form.
267
67
 
268
68
  ## File types
269
69
 
270
- | Extension | Role | In VCS? |
271
- |-----------|------|---------|
272
- | `.patter` | The **project** folder (a macOS package; a plain folder elsewhere) | yes - it *is* the source tree |
273
- | `.patterproj` | Project settings manifest (inside the `.patter`) | yes (source) |
274
- | `.patterflow` | One flow / scene (the structural tree) | yes (source) |
275
- | `.patterloc` | Localised strings, per scene per locale | yes (source) |
276
- | `.patterx` | Authoring / production metadata (status, comments, estimates) | yes (source) |
277
- | `.patterc` | Compiled runtime bundle (`export` output, strict JSON) | committed by default (see `--bundle`) |
278
- | `.patterpack` | Packed portable send document (`pack` output, binary zip) | no - ignored, ephemeral |
70
+ | Extension | Role | In version control? |
71
+ |-----------|------|---------------------|
72
+ | `.patter` | The **project** folder (a macOS package; a plain folder elsewhere) | yes, it *is* the source tree |
73
+ | `.patterproj` | Project settings (inside the `.patter`) | yes (source) |
74
+ | `.patterflow` | One scene's structure | yes (source) |
75
+ | `.patterloc` | Localised strings, per scene per language | yes (source) |
76
+ | `.patterx` | Authoring metadata (status, comments, suggestions) | yes (source) |
77
+ | `.patterc` | Compiled runtime bundle (`export` output, strict JSON) | committed by default (see `init --bundle`) |
78
+ | `.patterpack` | Packed portable document (`pack` output, a zip) | no, ignored |
279
79
 
280
- Source files are UTF-8 + LF JSON5 (trailing commas allowed); `patter format`
281
- keeps them canonical, and the VCS config from `patter init` pins encoding and
282
- wires structured merge.
80
+ Source files are UTF-8 + LF JSON5 (trailing commas allowed); `patter format` keeps them canonical,
81
+ and the version-control config from `patter init` pins the encoding and wires up the structured merge.
283
82
 
284
83
  ## Exit codes
285
84
 
286
85
  | Code | Meaning |
287
86
  |------|---------|
288
87
  | `0` | Success. |
289
- | `1` | The operation ran but found problems or failed (validation issues, a stalled playthrough, a write failure). |
290
- | `2` | Usage error (unknown command, unknown flag, missing required value). |
88
+ | `1` | The operation ran but found problems or failed (validation issues, a failed playthrough, a write failure). |
89
+ | `2` | Usage error (unknown command or flag, a missing value). `merge` and `mergetool` also exit 2 for input that is not Patter source, so a version control can fall back to its own merge. |