@pikku/skills 0.12.9 → 0.12.10

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.
@@ -3,10 +3,14 @@ name: pikku-versioning
3
3
  description: >-
4
4
  Use when versioning Pikku function contracts, detecting breaking changes, or managing API
5
5
  backward compatibility. Covers the version property, versions.pikku.json manifest, contract
6
- hashing, and CI integration. TRIGGER when: code uses version: on a pikkuFunc, user asks about
7
- API versioning, breaking changes, contract hashes, backward compatibility, or "pikku versions"
6
+ hashing, and CI integration. Also covers `pikku semver`, which derives a release's semver by
7
+ diffing this build's surface against a deployed one and writes .pikku/changes.gen.json.
8
+ TRIGGER when: code uses version: on a pikkuFunc, user asks about
9
+ API versioning, breaking changes, contract hashes, backward compatibility, what semver a
10
+ release should get, comparing against production/staging, or "pikku versions" / "pikku semver"
8
11
  CLI commands. DO NOT TRIGGER when: user asks about secrets/variables/OAuth2 (use pikku-config)
9
- or general function definitions (use pikku-concepts).
12
+ or general function definitions (use pikku-concepts), or about updating dependency versions
13
+ (use pikku-deps).
10
14
  installGroups: [core]
11
15
  ---
12
16
 
@@ -145,6 +149,84 @@ the manifest alone. Fix the contract or bump the version, then run it again.
145
149
  4. If intentional: pin the old contract as `…V1` with `version: 1`, bump the
146
150
  live function to `version: 2`, then `pikku versions update`
147
151
 
152
+ ## The `pikku semver` command
153
+
154
+ `versions check` and `semver` answer different questions and share no state.
155
+ `check` is a within-repo gate — "you changed a contract without bumping
156
+ `version:`". `semver` is a release question — "what does this build owe the
157
+ clients of the one already deployed?" — and needs an **external baseline**,
158
+ which is why the answer is always relative to an environment rather than to
159
+ the previous commit.
160
+
161
+ ```bash
162
+ npx pikku semver --against https://api.acme.com/surface.json # vs production
163
+ npx pikku semver --against ../other-app/.pikku # vs a checkout
164
+ npx pikku semver --emit --out surface.json # publish a baseline
165
+ npx pikku semver --against ... --fail-on major # CI gate
166
+ ```
167
+
168
+ `--against` takes three things and tells them apart itself: a directory is read
169
+ as a `.pikku` tree, an `http(s)` URL is fetched as a published snapshot, and any
170
+ other file is read as a snapshot. `--emit` produces the snapshot; **use `--out`**
171
+ — plain `--emit` writes to stdout _after_ the CLI banner, so a bare `> file.json`
172
+ captures the banner too. Publish the snapshot from CI on deploy and it becomes
173
+ the baseline everyone else compares against.
174
+
175
+ The verdict, in order:
176
+
177
+ - **major** — a function or client-facing wiring was removed, or a surviving
178
+ one tightened its contract.
179
+ - **minor** — anything was added, or a contract loosened compatibly.
180
+ - **patch** — the surface did not move; the release is internal work.
181
+
182
+ Below the id level it reads the generated JSON Schemas, and **direction
183
+ decides**. An input is contravariant (the caller writes it) and an output is
184
+ covariant (the caller reads it), so the same edit is not the same event on both:
185
+
186
+ | Change | On an input | On an output |
187
+ | ------------------------------ | ------------------------------------ | ------------ |
188
+ | field removed | breaking (when the schema is closed) | breaking |
189
+ | required field added | breaking | compatible |
190
+ | field became optional | compatible | breaking |
191
+ | optional field became required | breaking | compatible |
192
+ | enum value removed | breaking | compatible |
193
+ | enum value added | compatible | breaking |
194
+ | type changed | breaking | breaking |
195
+
196
+ It consumes `versions.pikku.json`: published versions are immutable, so a
197
+ function id that left the source while the manifest still records it is a `@vN`
198
+ bump, not a removal — that is what keeps a deliberate version bump at `minor`.
199
+ Without the manifest the same disappearance reads as `major`, which is the safe
200
+ reading rather than a wrong one.
201
+
202
+ Two things it deliberately will not guess. A named schema whose body did not
203
+ travel with the baseline falls back to `contractHash` and, if that moved, is
204
+ reported **breaking with the reason stated** — never quietly "unchanged". And at
205
+ the wiring level only `auth` going from absent/false to true is classified as
206
+ breaking; every other metadata change is reported as compatible, because there
207
+ is no general way to tell a cosmetic wiring edit from a restricting one.
208
+
209
+ Output is `.pikku/changes.gen.json` (override with `--out`), so it rides the
210
+ same meta pipeline as `audit.json`:
211
+
212
+ ```json
213
+ {
214
+ "schemaVersion": 1,
215
+ "baseline": "https://api.acme.com/surface.json",
216
+ "verdict": "major",
217
+ "summary": { "breaking": 1, "added": 1, "removed": 0, "modified": 1 },
218
+ "changes": [
219
+ {
220
+ "kind": "function",
221
+ "id": "getUser",
222
+ "status": "modified",
223
+ "breaking": true,
224
+ "reasons": ["input.tenant: required field added"]
225
+ }
226
+ ]
227
+ }
228
+ ```
229
+
148
230
  ## CI Integration
149
231
 
150
232
  ```yaml
@@ -159,6 +241,8 @@ jobs:
159
241
  - uses: actions/checkout@v4
160
242
  - run: npm ci
161
243
  - run: npx pikku versions check
244
+ # Refuse to ship a breaking change to production unintentionally.
245
+ - run: npx pikku semver --against https://api.acme.com/surface.json --fail-on major
162
246
  ```
163
247
 
164
248
  ## Complete Example
@@ -36,7 +36,7 @@ class. You own the `http.Server` and the `WebSocketServer`; the handler attaches
36
36
  the upgrade and message plumbing to them.
37
37
 
38
38
  ```typescript
39
- import { pikkuWebsocketHandler } from '@pikku/ws'
39
+ import { DEFAULT_WS_MAX_PAYLOAD, pikkuWebsocketHandler } from '@pikku/ws'
40
40
  import { stopSingletonServices } from '@pikku/core'
41
41
  import { Server } from 'http'
42
42
  import { WebSocketServer } from 'ws'
@@ -48,7 +48,10 @@ const config = await createConfig()
48
48
  const singletonServices = await createSingletonServices(config)
49
49
 
50
50
  const server = new Server()
51
- const wss = new WebSocketServer({ noServer: true })
51
+ const wss = new WebSocketServer({
52
+ noServer: true,
53
+ maxPayload: DEFAULT_WS_MAX_PAYLOAD,
54
+ })
52
55
 
53
56
  pikkuWebsocketHandler({
54
57
  server,