@patterkit/cli 0.1.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 +229 -0
  2. package/dist/cli.js +241560 -0
  3. package/package.json +30 -0
package/README.md ADDED
@@ -0,0 +1,229 @@
1
+ # `patter` - the Patter CLI
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.
7
+
8
+ ## Install / run
9
+
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).
16
+
17
+ Running `patter` with no command prints usage.
18
+
19
+ ## Quick start
20
+
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
25
+ ```
26
+
27
+ ## Commands
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
+ ```sh
61
+ patter validate
62
+ patter validate my-game
63
+ ```
64
+
65
+ ### `patter format [files...]` (alias `fmt`)
66
+
67
+ Rewrite source files to canonical form (sorted keys, 2-space indent, LF, final
68
+ newline, trailing commas). Pass explicit files.
69
+
70
+ | Option | Meaning |
71
+ |--------|---------|
72
+ | `--check` | Report what *would* change and write nothing; exits non-zero if any file is non-canonical (for CI). |
73
+
74
+ ```sh
75
+ patter format scenes/*.patterflow
76
+ patter format --check scenes/opening.patterflow # CI: fail if not canonical
77
+ ```
78
+
79
+ ### `patter export [path]`
80
+
81
+ Compile a project (flow + selected locales) to a `.patterc` runtime bundle -
82
+ strict JSON the game runtime loads.
83
+
84
+ | Option | Meaning |
85
+ |--------|---------|
86
+ | `-o <file>` | Write to `<file>`. |
87
+ | `-o -` | Stream the bundle to stdout (for pipelines). |
88
+ | *(no `-o`)* | Write the conventional path: the project's `export.bundle`, else `dist/<project-name>.patterc`. |
89
+
90
+ ```sh
91
+ patter export # -> dist/<name>.patterc
92
+ patter export -o build/game.patterc
93
+ patter export -o - | gzip > game.patterc.gz
94
+ ```
95
+
96
+ ### `patter play [path]`
97
+
98
+ Play a project through the reference runtime and print a transcript - lines,
99
+ text, game events, and choices. Exits non-zero if the playthrough cannot finish
100
+ (a stall / max-steps), which makes it usable as a smoke test.
101
+
102
+ | Option | Values | Meaning |
103
+ |--------|--------|---------|
104
+ | `--scene <id>` | scene id | Start at this scene. |
105
+ | `--block <id>` | block id | Start at this block. |
106
+ | `--choices <a,b,c>` | comma list | Auto-pick these option ids, in order, at successive choices. |
107
+ | `--seed <n>` | integer | Seed the runtime PRNG for reproducible selection. |
108
+
109
+ ```sh
110
+ patter play
111
+ patter play --scene scn_tavern --choices opt_work,opt_secret
112
+ patter play --seed 42
113
+ ```
114
+
115
+ ### `patter resolve <query> [path]`
116
+
117
+ Look up an **id**, **handle**, or **name** and report what it is and where it
118
+ lives (file + location path). The CLI counterpart to the editor's dual search -
119
+ handy when a locale table or VO asset references something by id.
120
+
121
+ ```sh
122
+ patter resolve scn_tavern
123
+ patter resolve "Tavern > Intro"
124
+ ```
125
+
126
+ ### `patter report [path]` (alias `stats`)
127
+
128
+ Production report: writing/recording status against the project ladders, the
129
+ voiced-vs-written line split, the burndown (done / to-write / projected), plan
130
+ coverage, cut content, character rollups, and localisation staleness. Prints a
131
+ compact summary by default.
132
+
133
+ | Option | Meaning |
134
+ |--------|---------|
135
+ | `--xlsx <file>` | Also write a polished spreadsheet (Scenes / Characters / Localisation / Plan). |
136
+ | `--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. |
137
+
138
+ ```sh
139
+ patter report
140
+ patter stats --xlsx report.xlsx
141
+ patter report --json | jq '.totals'
142
+ ```
143
+
144
+ ### `patter pack [path] -o <file.patterpack>`
145
+
146
+ Pack a project (the `.patter` folder) into a single portable **`.patterpack`** - a
147
+ binary zip envelope, the send-and-return artifact for collaborators without VCS
148
+ (you cannot email a folder; this is the zip of it). `-o` is required.
149
+
150
+ ```sh
151
+ patter pack my-game.patter -o my-game.patterpack
152
+ ```
153
+
154
+ ### `patter unpack <file.patterpack> -o <dir>`
155
+
156
+ Explode a `.patterpack` back into source shards under `<dir>`. Both the input
157
+ file and `-o <dir>` are required. Entry paths that would escape the target
158
+ directory are rejected.
159
+
160
+ | Option | Meaning |
161
+ |--------|---------|
162
+ | `--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. |
163
+
164
+ ```sh
165
+ patter unpack returned.patterpack -o ./my-game.patter --merge --base sent.patterpack
166
+ ```
167
+
168
+ ### `patter merge BASE OURS THEIRS`
169
+
170
+ Domain-aware **3-way merge** of Patter source by node id (not by line), for all
171
+ four shard types (flow / loc / authoring / project). The merged output is always
172
+ valid canonical source; conflicts resolve provisionally to OURS and are listed
173
+ in a `.patterconflict` sidecar. Mostly invoked by your VCS via `mergetool`, but
174
+ usable directly.
175
+
176
+ | Option | Meaning |
177
+ |--------|---------|
178
+ | `-o <file>` | Write the merged result to `<file>` (+ `<file>.patterconflict` on conflicts). Without it, the merge streams to stdout. |
179
+ | `--type <t>` | Force the type (`flow`/`loc`/`authoring`/`project`); default auto-detects from the `schema` tag. |
180
+ | `--json` | Emit the structured `{ type, merged, conflicts, warnings }` as JSON. |
181
+
182
+ Exit: `0` clean, `1` conflicts (sidecar written), `2` error. `%O %A %B` from a
183
+ git driver map to BASE OURS THEIRS.
184
+
185
+ ```sh
186
+ patter merge base.patterflow ours.patterflow theirs.patterflow -o ours.patterflow
187
+ patter merge base.patterloc ours.patterloc theirs.patterloc --json
188
+ ```
189
+
190
+ ### `patter mergetool BASE THEIRS OURS OUT`
191
+
192
+ The **VCS merge-tool wrapper** - register it once as your single global merge
193
+ tool. It sniffs the path: Patter source goes to the structured merge above;
194
+ anything else is handed to your normal tool. Arguments are in the BASE THEIRS
195
+ OURS OUT order that Perforce / Plastic / SVN all use; `patter init --vcs <x>`
196
+ writes the exact registration into `vcs-setup.md`. (git instead uses its
197
+ per-path driver and calls `patter merge` directly.)
198
+
199
+ | Option | Meaning |
200
+ |--------|---------|
201
+ | `--fallback <cmd>` | The tool to run for non-Patter files (e.g. `p4merge`, `"code --wait --merge"`). It receives the same four file arguments. |
202
+
203
+ ```sh
204
+ patter mergetool $BASE $THEIRS $OURS $OUT --fallback p4merge
205
+ ```
206
+
207
+ ## File types
208
+
209
+ | Extension | Role | In VCS? |
210
+ |-----------|------|---------|
211
+ | `.patter` | The **project** folder (a macOS package; a plain folder elsewhere) | yes - it *is* the source tree |
212
+ | `.patterproj` | Project settings manifest (inside the `.patter`) | yes (source) |
213
+ | `.patterflow` | One flow / scene (the structural tree) | yes (source) |
214
+ | `.patterloc` | Localised strings, per scene per locale | yes (source) |
215
+ | `.patterx` | Authoring / production metadata (status, comments, estimates) | yes (source) |
216
+ | `.patterc` | Compiled runtime bundle (`export` output, strict JSON) | committed by default (see `--bundle`) |
217
+ | `.patterpack` | Packed portable send document (`pack` output, binary zip) | no - ignored, ephemeral |
218
+
219
+ Source files are UTF-8 + LF JSON5 (trailing commas allowed); `patter format`
220
+ keeps them canonical, and the VCS config from `patter init` pins encoding and
221
+ wires structured merge.
222
+
223
+ ## Exit codes
224
+
225
+ | Code | Meaning |
226
+ |------|---------|
227
+ | `0` | Success. |
228
+ | `1` | The operation ran but found problems or failed (validation issues, a stalled playthrough, a write failure). |
229
+ | `2` | Usage error (unknown command, unknown flag, missing required value). |