@wirecat/cli-base 0.107.0 → 0.109.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 (43) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/README.md +2 -1
  3. package/dist/codegen/fake.d.ts +64 -0
  4. package/dist/codegen/fake.js +341 -0
  5. package/dist/codegen/index.d.ts +12 -4
  6. package/dist/codegen/index.js +11 -3
  7. package/dist/codegen/manifest.d.ts +4 -1
  8. package/dist/codegen/manifest.js +69 -2
  9. package/dist/codegen/merge.d.ts +37 -0
  10. package/dist/codegen/merge.js +257 -0
  11. package/dist/codegen/model.d.ts +94 -0
  12. package/dist/codegen/openapi.d.ts +5 -1
  13. package/dist/codegen/openapi.js +102 -10
  14. package/dist/codegen/pagination.d.ts +14 -0
  15. package/dist/codegen/pagination.js +129 -0
  16. package/dist/codegen/patch.d.ts +28 -0
  17. package/dist/codegen/patch.js +75 -0
  18. package/dist/codegen/pipeline.d.ts +57 -1
  19. package/dist/codegen/pipeline.js +214 -6
  20. package/dist/codegen/skill.d.ts +35 -0
  21. package/dist/codegen/skill.js +171 -0
  22. package/dist/codegen/swagger.d.ts +7 -0
  23. package/dist/codegen/swagger.js +39 -0
  24. package/dist/credentials.d.ts +2 -2
  25. package/dist/credentials.js +17 -3
  26. package/dist/dev/conformance.d.ts +0 -2
  27. package/dist/dev/conformance.js +3 -9
  28. package/dist/dev/main.js +5 -1
  29. package/dist/dev/ready.d.ts +30 -0
  30. package/dist/dev/ready.js +310 -0
  31. package/dist/dev/slow-tests.d.ts +1 -0
  32. package/dist/http/fetch.js +21 -1
  33. package/dist/standards/audit.js +2 -1
  34. package/dist/standards/errors.js +6 -0
  35. package/dist/standards/index.d.ts +1 -0
  36. package/dist/standards/index.js +1 -0
  37. package/dist/standards/monthly.d.ts +5 -0
  38. package/dist/standards/monthly.js +12 -0
  39. package/docs/standards/ci.md +4 -2
  40. package/docs/standards/kit-surface.md +166 -0
  41. package/docs/standards/layout.md +1 -1
  42. package/docs/standards/new-cli.md +18 -7
  43. package/package.json +11 -1
@@ -32,6 +32,172 @@ The template's config files also reach cli-base: `tsconfig.json` and `kit/tsconf
32
32
  `tsconfig.base.json`, `tsconfig.test.json` and `tsconfig.scripts.json` extend the files of those names, `vitest.config.ts`
33
33
  loads `@wirecat/cli-base/testing/setup`, and `.vale.ini` reads the styles in `config/vale`.
34
34
 
35
+ ## The API generator
36
+
37
+ `@wirecat/cli-base/codegen` turns a service's API description into committed files: types, Valibot schemas, an
38
+ operation manifest and a coverage page. cli-core's `generatedApiCommand` builds the `api <operation>` group from the
39
+ manifest. The [reference](../REFERENCE.md) has the API; this section says what goes in, what a CLI can correct, and
40
+ what it cannot do yet.
41
+
42
+ ### Inputs
43
+
44
+ | The service publishes | Read it with |
45
+ |---|---|
46
+ | OpenAPI 3.0 or 3.1 | `adaptOpenApi(document, { sourceUrl, sourceRevision })` |
47
+ | Swagger 2.0 | `adaptOpenApi(await upgradeToOpenApi3(document))` |
48
+ | Swagger 1.2 (Yandex Disk) | `upgradeToOpenApi3(listing, declarations)`: the resource listing, and each API declaration keyed by its `apis[].path`, fetched from the listing's `basePath` followed by that path |
49
+ | Google Discovery | `adaptDiscovery(readDiscovery(dir))`, snapshots written by `syncDiscovery` |
50
+
51
+ `upgradeToOpenApi3` converts with [swagger-converter](https://github.com/apigee-127/swagger-converter) (1.2 → 2.0) and
52
+ [@scalar/openapi-upgrader](https://github.com/scalar/scalar/tree/main/packages/openapi-upgrader) (2.0 → 3.0). They are
53
+ optional peer dependencies of cli-base: a CLI that converts adds them to its `devDependencies`. Commit the source as the
54
+ service serves it, with its URL and hash in `spec/<service>/provenance.json`, and convert in `scripts/generate.ts`.
55
+
56
+ **`mergeOpenApi(sources, { title, version })`** joins a service's specs into one, for a service that publishes one per
57
+ object (HubSpot: 127, of which a CRM CLI needs 15). Each source is `{ name, document, url }`; `document` is the
58
+ downloaded JSON text, so the report's hash is the file's, or the parsed document.
59
+
60
+ - Components that share a name and differ only in their text (`description`, `summary`, `example`, `examples`,
61
+ `title`, `externalDocs`) or in `x-` extensions are kept once. A field named `description` is a field, not text.
62
+ - A real difference keeps both: the later source's copy, and every component that refers to it, get the source's
63
+ name as a prefix (`schemas/Paging → LineItemsPaging`), and that source's references follow.
64
+ - A path two sources share is taken once when it is the same, references followed into the merged components; any
65
+ other difference stops the merge, as does an operation id two sources use, a renamed name that is taken, or a mix
66
+ of OpenAPI 3.0 and 3.1.
67
+ - Servers and tags are joined. OAuth scopes of one scheme are joined, since each spec lists only its object's; a
68
+ scheme that differs in anything else stops the merge. A source's document-wide `security` moves onto its
69
+ operations that have none; other document-wide keys (`webhooks`, `x-` extensions) are left out.
70
+ - It returns the document and a report: each source with its URL, SHA-256 and the operations it added (a shared path
71
+ counts once, for the first source), and what was merged, renamed or shared, for `spec/<service>/provenance.json`.
72
+
73
+ Run on HubSpot's 15 CRM specs (2026-11-16): version `3` gives 156 operations and 97 schemas with no rename; `2026-09`
74
+ gives 203 operations and 115 schemas, one renamed, and 20 association paths shared by every object spec.
75
+
76
+ **`patchSpec(document, { patches, stubMissingSchemas })`** corrects the source before `adaptOpenApi`, in place of a
77
+ CLI's own `scripts/<service>-spec.ts`. Each patch sets a value at a JSON pointer, with a reason. `stubMissingSchemas`
78
+ gives every schema the document references but does not define an "anything" stub (HubSpot's associations v4 refers
79
+ to a `Void` it lacks). It reads OpenAPI 3, so it runs after `upgradeToOpenApi3`. It returns a copy and the list of what
80
+ it changed, for the CLI's provenance.
81
+
82
+ From the source the generator reads:
83
+
84
+ - **Operations**: method and path, parameters, the request body (JSON, multipart or a form), and the first 2xx answer
85
+ with a JSON body (`200`, `201` as HubSpot creates, `202`, `207`, or `2XX`). `application/hal+json`,
86
+ `application/json; charset=utf-8` and other JSON types count as JSON.
87
+ - **Effect**: GET and HEAD read, POST, PUT and PATCH write, DELETE is destructive.
88
+ - **Servers and sign-in**: `servers` (each URL once, as written), `components/securitySchemes` and `security` go into
89
+ the manifest as `servers`, `securitySchemes` and `security`, and an operation's own `security` (`[]` for one that
90
+ needs no sign-in) onto that operation. A CLI then does not copy its base URL or OAuth endpoints by hand. They appear
91
+ only when the source has them. A requirement naming a scheme the document lacks stops generation.
92
+
93
+ ### Corrections a CLI passes to `generate`
94
+
95
+ - **`overrides`**: operation id → `{ effect, reason }`. The reason is required. An override that matches no operation
96
+ stops generation. HubSpot's `batch/archive`, `gdpr-delete` and `merge` are POSTs that delete: an override with
97
+ `effect: "destructive"` makes them deletes, and `permissions` then guards them.
98
+ - **`readingPosts: true`**: a POST whose path ends in `/search` or `/query` (`:search`, `:query` too) is a read, as
99
+ HubSpot's and Notion's are. It is off by default, because a wrong guess turns a write into a read (a `…/query` that
100
+ runs any SQL). An override still wins.
101
+ - **`names`**: `{ commands, fromPath, segments }`. `commands` maps an operation id to its command. With `fromPath`,
102
+ the rest are named from the path and the method (`deals-list`, `deals-get`, `deals-create`, `deals-delete`,
103
+ `deals-batch-archive`), leaving out path parameters and versions (`v3`, `2026-03`), which `segments` cannot rename. A name that comes out
104
+ empty or not in kebab case stops generation; map that operation in `commands`. `segments` renames a path segment
105
+ or, with `""`, leaves it out: `{ "0-3": "deals", crm: "", objects: "" }`. Without `names` the command is the operation
106
+ id in kebab case, as before.
107
+ - **`permissions`**: `{ group, deletingFlags, shares }`. `group` is a name (`files`) or a function of the operation, for
108
+ example the first word of its `command` (set only with `names`). Each key lands in the manifest as the operation's `permissions`.
109
+ - `<group>.delete` for every destructive operation (Yandex Disk's `DELETE /trash/resources` empties the whole
110
+ trash), and for every operation that takes a flag in `deletingFlags`, as a top-level body field (Notion's
111
+ `archived`, `in_trash`, a subtype's included) or a query parameter (Yandex Disk's `permanently`, `overwrite`). The
112
+ key applies when the flag is `true`. A flag no operation takes stops generation.
113
+ - `<group>.share` for the operation ids in `shares`: a public link opens a file to anyone, which is neither a
114
+ plain write nor a delete.
115
+
116
+ Which flags delete is the CLI's call: read the service's documentation, and count an undocumented flag as a delete.
117
+ A flag counts on every method, a GET included: Yandex Disk's upload link is a GET whose `overwrite` replaces a file.
118
+ Leave out a flag that only filters, as HubSpot's `archived` on a list does.
119
+ - **`pagination: true`**: each read's `pagination` in the manifest, for an executor that reads every page. It is
120
+ found from the names the request and the answer use: a cursor (`after` and `paging.next.after` as HubSpot's,
121
+ `start_cursor` and `next_cursor` as Notion's), an offset (`offset` and `limit` with `_embedded.items` as Yandex
122
+ Disk's), a page number, or a link to the next page. An offset, a page and a limit must be numbers and a cursor a
123
+ string, so a `start` date is not taken for an offset. Answer fields are dotted paths. Only reads page: a POST
124
+ search pages once `readingPosts` or an override makes it a read. An override's
125
+ `pagination` sets it where detection misses or misreads, and `pagination: null` says the read does not page; a
126
+ parameter the operation does not take stops generation.
127
+ - **`auth`**: `{ securitySchemes, security, reason }` replaces the source's sign-in, the operations' own requirements
128
+ included. Yandex Disk's Swagger 1.2 has no scheme, and its header is `Authorization: OAuth <token>`:
129
+ `{ oauth: { type: "http", scheme: "OAuth" } }`. HubSpot's spec has no private app token.
130
+
131
+ ### A strict fake for tests
132
+
133
+ `fakeApi({ operations, definitions, baseUrl, auth, answers, hosts })` serves the generated manifest and definitions as
134
+ a `fetch` for a CLI's tests. It refuses, with a 4xx and a line in `refusals`, an unknown path or method, an unknown or
135
+ mistyped query parameter (a repeated one is a list), a missing required one, a body field the schema lacks (JSON, a
136
+ form or multipart), and a call without the `auth` header, unless the operation's `security` is `[]`. An operation
137
+ answers a sample built from its response schema, or what `answers` gives for it, checked against that schema: an
138
+ answer off the schema throws. A string, bytes or a stream is sent as it is, for a file. `hosts` answers the other
139
+ hosts a link points at (`downloader.disk.yandex.ru`, `*.disk.yandex.net`), and refuses a call there over another
140
+ scheme or with the `auth` header. A CLI writes only its scenarios. `looseObjects` lets unknown fields through, for a
141
+ source whose subtypes the definitions cannot tell apart.
142
+
143
+ ### The API part of the agent skill
144
+
145
+ `apiSkillFiles({ cli, folder, files, service, skill, operations, commands, banner })` writes the API part of the
146
+ CLI's skill, in the shape of [openapi-to-skills](https://github.com/neutree-ai/openapi-to-skills): `references/api.md`,
147
+ a short index of the groups with their effects, and `references/api/api-<group>.md`, one file per group. An
148
+ operation's group is its first tag; one without a tag is in `api-untagged.md`. A tag with no Latin letter or digit
149
+ cannot name a file and stops the generation. An agent reads
150
+ the index, then only the group it needs, with `<cli> skill show api-<group>`. The `skill` command already ships and
151
+ shows every file beside `SKILL.md`; nothing else is needed.
152
+
153
+ - `commands` is `describeProgram(createProgram())` from the built program, made with the CLI's own copy of cli-base.
154
+ Each command's usage, arguments and flags come from there, as `--help` prints them; a flag is never made up from
155
+ the spec. An operation and its command are matched by the command's `api_operation`. An operation without a
156
+ command, a generated command whose operation is not in the manifest, and two commands for one operation stop the
157
+ generation.
158
+ - The manifest adds what only the API knows: the HTTP call, the effect, sign-in scopes, permission keys, paging
159
+ (named by the API's parameters and answer fields) and the request body's schema. Vendor text is cut to its first
160
+ line, its HTML and Markdown marks are escaped, and it always follows a label, since an installed skill is
161
+ instructions an agent follows.
162
+ - There are no examples: the manifest has none, and the generated commands carry none.
163
+ - `skill` is the text of `SKILL.md`, which must link `references/api.md`, or the agent never finds the files.
164
+ `files` is `skillFiles(<SKILL.md URL>)`: `skill show` finds a part by its base name, so a hand-written `api.md` or
165
+ `api-<name>.md` elsewhere in the folder, which would hide a generated one, stops the generation.
166
+ - Run it after the build, beside the commands page, and write it with
167
+ `writeArtifacts(files, { root, check, owns: ["skills/<cli>/references/api"] })`: `owns` makes a file of a group
168
+ that left the spec stale, so `generate:check` catches it, and `pnpm generate` removes it. The output holds no
169
+ version or date, so a version bump leaves it current.
170
+
171
+ ### Provenance
172
+
173
+ The coverage page lists every operation, with its call, command, effect and how far its request body can be trusted
174
+ (`contract` or `example`). Under it, **Effects not taken from the HTTP method** lists each operation `readingPosts` or
175
+ an override changed, with the reason; **Pagination** lists each read that pages, and whether it was detected or set by
176
+ an override; **Sign-in** gives the `auth` reason; and **Permission keys** lists each key from `permissions` and when
177
+ it applies. `patchSpec`'s list of changes goes into the CLI's own provenance. A reviewer diffs
178
+ the coverage page after a spec sync.
179
+
180
+ ### Limits
181
+
182
+ - **Nothing checks the permission keys yet.** cli-core does not read an operation's `permissions`, `servers` or
183
+ `securitySchemes` today. Until it does, a CLI adds the keys to its own `commandPermissions`, as notion-cli's
184
+ `src/config.ts` does.
185
+ - A merge joins every source's servers at the top, for every operation; sources on different hosts need a
186
+ `servers` entry per path, which the merge does not write.
187
+ - Pagination is found only from the names above; a service with its own names needs an override per operation.
188
+ cli-core reads every page by the manifest once its executor does.
189
+ - Pagination is not found in an answer that is a union.
190
+ - The fake checks shapes, not behaviour: it does not page, filter or keep state. A scenario that needs that writes
191
+ it in `answers`. It checks neither header parameters nor RPC operations. A sample follows enums and limits but not
192
+ patterns, so a link the CLI follows (Yandex Disk's `href`) comes from a scenario's answer.
193
+ - A `$ref` to a shared response in `components/responses` is passed through without a shape; a `$ref` security
194
+ scheme stops generation.
195
+ - A Swagger 1.2 listing that embeds its operations, and Postman, RAML or GraphQL sources, are not read.
196
+ - Swagger 1.2 lists a status code more than once in one operation (Yandex Disk's 400 and 403); a JSON object holds
197
+ one, so the conversion keeps one of them. Only 2xx answers reach the model.
198
+ - swagger-converter has had no release since 2021, and no maintained converter from Swagger 1.2 exists; Swagger 1.2
199
+ itself was replaced by 2.0 in 2014. It is a dev dependency only, used by the few services still on 1.2.
200
+
35
201
  ## When one of them changes
36
202
 
37
203
  A change that makes a CLI change its code for one of these exports ships with two things:
@@ -20,7 +20,7 @@ Rule ids on this page are `WC-LAY-<n>`. How to read a rule, how ids work and whi
20
20
  - `bin/`: the repository's own scripts, such as `bin/release` and a wrapper that runs the local build;
21
21
  - `scripts/`: development scripts in TypeScript or JavaScript;
22
22
  - `docs/`: user pages; `docs/dev/`: developer pages;
23
- - `lint/`: `baseline/` and `overrides.json` for the command lint;
23
+ - `lint/`: `baseline/` and `overrides.json` for the command lint, `contract-exceptions.json` for `cli-dev ready`;
24
24
  - `contracts/`: the offline contract plan and its snapshots;
25
25
  - `config/wirecat/`: the shared presets;
26
26
  - `skills/`: the agent skill the package ships;
@@ -156,12 +156,14 @@ installing that command; nothing else is registered anywhere.
156
156
  Environments → npm → Deployment branches → Selected branches): npm trusts `release.yml` by its name, and a
157
157
  dispatch runs that file from the branch it was started on. See
158
158
  [WC-REL-11](releases.md#wc-rel-11--publish-from-github-actions-with-npm-trusted-publishing).
159
- 3. **Pick a monthly cron minute** between 02:17 and 03:20 UTC that is not in the list of taken minutes under
160
- [WC-CI-9](ci.md#wc-ci-9--run-full-validation-and-release-security-on-the-first-day-of-each-month-without-publishing).
161
- The copy of `.github/workflows/monthly.yml` keeps the template's own minute, 03:02; change it by hand, and add the
162
- new minute to the list in the step 4 pull request.
163
- 4. **WireCat CLIs only: join the shared lists.** A pull request to cli-base's `PARITY_GROUPS` (at least the `all`
164
- group, which compares the shared root commands), a line in cli-core's `WIRECAT_TOOLS` and a line in cli-docs'
159
+ 3. **Check the monthly cron minute.** `new` sets it in `.github/workflows/monthly.yml`. A WireCat CLI gets a free
160
+ minute between 02:17 and 03:20 UTC, picked by its name, at least two minutes from the taken minutes under
161
+ [WC-CI-9](ci.md#wc-ci-9--run-full-validation-and-release-security-on-the-first-day-of-each-month-without-publishing)
162
+ and off the hour; a CLI outside WireCatLabs gets one between 04:01 and 05:59 UTC, after that window. Nothing to
163
+ change by hand.
164
+ 4. **WireCat CLIs only: join the shared lists.** `new` prints the entries ready to paste. A pull request to cli-base
165
+ with the new minute in WC-CI-9's table and the CLI in `PARITY_GROUPS` (at least the `all` group, which compares the
166
+ shared root commands), a line in cli-core's `WIRECAT_TOOLS` and, after the first release, a line in cli-docs'
165
167
  `tools.json`. A messenger also joins cli-core's `parity.json`. A CLI outside WireCatLabs keeps its parity groups
166
168
  in its own repository and runs `cli-dev audit --groups <file>`. See [Testing](testing.md).
167
169
 
@@ -177,7 +179,16 @@ The listings beyond npm (ClawHub, the MCP Registry, the Claude plugin, the docs
177
179
 
178
180
  ## Done when
179
181
 
180
- All of these pass on `main`, before the first release:
182
+ All of these pass on `main`, before the first release. `cli-dev ready` runs the CLI's own scripts for most of them in
183
+ order and prints what each one proves: verified (a script passed, a test runs the category's cli-core contract, the
184
+ live-check record is of this code), partially, not verified, or unsupported (a check that cannot apply: the live
185
+ check in cli-template itself). A contract call counts only when vitest's report shows its test file ran with no test
186
+ skipped, and every contract of the category must run. A CLI that cannot run one lists it in
187
+ `lint/contract-exceptions.json` as `[{ "contract": "crmSyncContract", "reason": "…" }]`; the row then shows
188
+ partially with the reason, and the exception does not hold back the exit code. An exception without a reason, for
189
+ another category's contract, for a contract that runs, or for every contract is not verified. A missing script is
190
+ not verified. `--json` gives the same rows and the one next
191
+ step to an agent. It never runs the live check: that is the owner's run against their account.
181
192
 
182
193
  - `pnpm standards:check`
183
194
  - `pnpm typecheck`, `pnpm lint` and `pnpm test` with coverage
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-base",
3
- "version": "0.107.0",
3
+ "version": "0.109.0",
4
4
  "description": "The parts every command line tool needs: output modes, terminal rendering, error model, exit codes, credentials, clocks",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Viacheslav Ptsarev",
@@ -143,6 +143,7 @@
143
143
  "@cspell/dict-en-gb": "5.0.38",
144
144
  "@cspell/dict-es-es": "3.0.9",
145
145
  "@cspell/dict-ru_ru": "2.3.4",
146
+ "@scalar/openapi-upgrader": "0.4.6",
146
147
  "@types/cross-spawn": "6.0.6",
147
148
  "@types/node": "^22.20.5",
148
149
  "@vitest/coverage-v8": "^5.0.5",
@@ -151,6 +152,7 @@
151
152
  "esbuild": "0.28.2",
152
153
  "lefthook": "2.2.2",
153
154
  "markdownlint-cli2": "0.24.0",
155
+ "swagger-converter": "2.1.0",
154
156
  "typescript": "^7.0.2",
155
157
  "vitest": "^5.0.5",
156
158
  "yaml": "^2.9.1"
@@ -159,17 +161,25 @@
159
161
  "access": "public"
160
162
  },
161
163
  "peerDependencies": {
164
+ "@scalar/openapi-upgrader": "^0.4.6",
162
165
  "commander": ">=15",
163
166
  "esbuild": "^0.28.0",
167
+ "swagger-converter": "^2.1.0",
164
168
  "vitest": ">=5"
165
169
  },
166
170
  "peerDependenciesMeta": {
171
+ "@scalar/openapi-upgrader": {
172
+ "optional": true
173
+ },
167
174
  "commander": {
168
175
  "optional": true
169
176
  },
170
177
  "esbuild": {
171
178
  "optional": true
172
179
  },
180
+ "swagger-converter": {
181
+ "optional": true
182
+ },
173
183
  "vitest": {
174
184
  "optional": true
175
185
  }