micro-contracts 0.13.0 → 0.14.1

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.
@@ -0,0 +1,516 @@
1
+ # micro-contracts CLI
2
+
3
+ Contract-first OpenAPI toolchain for TypeScript Web/API systems. Generates contract packages, server routes, and frontend clients from OpenAPI specifications with enforceable guardrails.
4
+
5
+ **Version:** 0.14.0
6
+
7
+ ## Table of Contents
8
+
9
+ - [micro-contracts](#micro-contracts)
10
+ - [generate](#micro-contracts-generate)
11
+ - [lint](#micro-contracts-lint)
12
+ - [init](#micro-contracts-init)
13
+ - [check](#micro-contracts-check)
14
+ - [pipeline](#micro-contracts-pipeline)
15
+ - [deps](#micro-contracts-deps)
16
+ - [guardrails-init](#micro-contracts-guardrails-init)
17
+ - [manifest](#micro-contracts-manifest)
18
+
19
+ ---
20
+
21
+ ## micro-contracts
22
+
23
+ Contract-first OpenAPI toolchain for TypeScript.
24
+
25
+ ### Global Options
26
+
27
+ | Option | Aliases | Required | Default | Description |
28
+ |---|---|---|---|---|
29
+ | `--version` | -V | No | | Print version and exit. |
30
+ | `--help` | -h | No | | Show help and exit. |
31
+
32
+ ### generate
33
+
34
+ Generate code from OpenAPI specifications.
35
+
36
+ Loads the multi-module config, applies overlays, runs Spectral linting (unless skipped), and generates contract packages, server routes, frontend clients, and documentation from OpenAPI specs. Supports input-hash caching to skip unnecessary regeneration.
37
+
38
+ **Usage:**
39
+
40
+ ```
41
+ micro-contracts generate
42
+ ```
43
+ ```
44
+ micro-contracts generate -c my-config.yaml
45
+ ```
46
+ ```
47
+ micro-contracts generate -m core,billing
48
+ ```
49
+ ```
50
+ micro-contracts generate --contracts-only
51
+ ```
52
+ ```
53
+ micro-contracts generate --force
54
+ ```
55
+
56
+ #### Options
57
+
58
+ | Option | Aliases | Required | Default | Description |
59
+ |---|---|---|---|---|
60
+ | `--config` | -c | No | | Path to config file (micro-contracts.config.yaml). |
61
+ | `--module` | -m | No | | Module names, comma-separated. Generates all modules if omitted. |
62
+ | `--contracts-only` | | No | `false` | Generate contract packages only. |
63
+ | `--server-only` | | No | `false` | Generate server routes only. |
64
+ | `--frontend-only` | | No | `false` | Generate frontend clients only. |
65
+ | `--docs-only` | | No | `false` | Generate documentation only. |
66
+ | `--skip-lint` | | No | `false` | Skip Spectral linting before generation. |
67
+ | `--manifest` | | No | `true` | Generate manifest after generation. Enabled by default when guardrails.yaml has a generated section. Use --no-manifest to disable. |
68
+ | `--manifest-dir` | | No | `"packages/"` | Directory for manifest output. |
69
+ | `--force` | | No | `false` | Bypass input hash cache and always regenerate. |
70
+ | `--cache` | | No | `true` | Enable input hash caching. Enabled by default. Use --no-cache to disable both reading and writing cache. |
71
+
72
+ #### Exit Codes
73
+
74
+ **Exit 0:** Generation succeeded.
75
+
76
+ - **stdout:** format=`text`
77
+
78
+ - **Generated files:**
79
+ - `packages/contract/{module}/**/*.ts` (text/x-typescript)
80
+ - `packages/contract-published/{module}/**/*.ts` (text/x-typescript) *(optional)*
81
+
82
+ **Exit 1:** Generation failed (config not found, spec invalid, or generation error).
83
+
84
+ - **stderr:** format=`text`
85
+
86
+ #### Extensions
87
+
88
+ ```yaml
89
+ x-agent:
90
+ riskLevel: medium
91
+ requiresConfirmation: false
92
+ idempotent: true
93
+ sideEffects:
94
+ - file_write
95
+ recommendedBeforeUse:
96
+ - Ensure micro-contracts.config.yaml exists.
97
+ - Verify OpenAPI specs are valid.
98
+ ```
99
+
100
+ ---
101
+
102
+ ### lint
103
+
104
+ Lint OpenAPI specification.
105
+
106
+ Validates an OpenAPI specification for x-micro-contracts extension violations and structural issues using Spectral rules.
107
+
108
+ **Usage:**
109
+
110
+ ```
111
+ micro-contracts lint spec/core/openapi/core.yaml
112
+ ```
113
+ ```
114
+ micro-contracts lint spec/core/openapi/core.yaml --strict
115
+ ```
116
+
117
+ #### Arguments
118
+
119
+ | Name | Required | Description |
120
+ |---|---|---|
121
+ | `input` | Yes | Path to OpenAPI spec file. |
122
+
123
+ #### Options
124
+
125
+ | Option | Aliases | Required | Default | Description |
126
+ |---|---|---|---|---|
127
+ | `--strict` | | No | `false` | Treat warnings as errors. |
128
+
129
+ #### Exit Codes
130
+
131
+ **Exit 0:** Spec is valid. No lint errors found.
132
+
133
+ - **stdout:** format=`text`
134
+
135
+ **Exit 1:** Lint failed. Errors or warnings (in strict mode) found.
136
+
137
+ - **stderr:** format=`text`
138
+
139
+ #### Extensions
140
+
141
+ ```yaml
142
+ x-agent:
143
+ riskLevel: low
144
+ requiresConfirmation: false
145
+ idempotent: true
146
+ sideEffects:
147
+
148
+ ```
149
+
150
+ ---
151
+
152
+ ### init
153
+
154
+ Initialize a new module structure with starter templates.
155
+
156
+ Creates the directory structure, starter Handlebars templates, shared schemas, Spectral rules, and optional config file for a new module. Can also process an existing OpenAPI spec to auto-add x-micro-contracts extensions.
157
+
158
+ **Usage:**
159
+
160
+ ```
161
+ micro-contracts init core
162
+ ```
163
+ ```
164
+ micro-contracts init core --openapi path/to/spec.yaml
165
+ ```
166
+ ```
167
+ micro-contracts init myScreens --screens
168
+ ```
169
+ ```
170
+ micro-contracts init users --skip-templates
171
+ ```
172
+
173
+ #### Arguments
174
+
175
+ | Name | Required | Description |
176
+ |---|---|---|
177
+ | `name` | Yes | Module name (e.g., core, users, billing). |
178
+
179
+ #### Options
180
+
181
+ | Option | Aliases | Required | Default | Description |
182
+ |---|---|---|---|---|
183
+ | `--dir` | -d | No | `"src"` | Base directory for server/frontend files. |
184
+ | `--openapi` | -i | No | | OpenAPI spec to process (auto-adds x-micro-contracts-service/method extensions). |
185
+ | `--output` | -o | No | | Output path for processed OpenAPI. Defaults to spec/{name}/openapi/{name}.yaml. |
186
+ | `--skip-templates` | | No | `false` | Skip creating starter Handlebars templates. |
187
+ | `--screens` | | No | `false` | Initialize as screen spec module (generates screen templates and starter spec). |
188
+
189
+ #### Exit Codes
190
+
191
+ **Exit 0:** Module initialized successfully.
192
+
193
+ - **stdout:** format=`text`
194
+
195
+ - **Generated files:**
196
+ - `spec/{name}/openapi/{name}.yaml` (application/yaml) *(optional)*
197
+ - `spec/default/templates/*.hbs` (text/x-handlebars-template) *(optional)*
198
+ - `micro-contracts.config.yaml` (application/yaml) *(optional)*
199
+
200
+ **Exit 1:** Initialization failed (OpenAPI file not found or write error).
201
+
202
+ - **stderr:** format=`text`
203
+
204
+ #### Extensions
205
+
206
+ ```yaml
207
+ x-agent:
208
+ riskLevel: medium
209
+ requiresConfirmation: false
210
+ idempotent: true
211
+ sideEffects:
212
+ - file_write
213
+ - directory_create
214
+ ```
215
+
216
+ ---
217
+
218
+ ### check
219
+
220
+ Run guardrail checks.
221
+
222
+ Runs AI guardrail checks against generated code and config. Supports gating (1-5), selective check execution, auto-fix, and CI integration via changed-files input.
223
+
224
+ **Usage:**
225
+
226
+ ```
227
+ micro-contracts check
228
+ ```
229
+ ```
230
+ micro-contracts check --gate 1,2
231
+ ```
232
+ ```
233
+ micro-contracts check --only drift,manifest
234
+ ```
235
+ ```
236
+ micro-contracts check --fix
237
+ ```
238
+ ```
239
+ micro-contracts check --list
240
+ ```
241
+ ```
242
+ micro-contracts check --list-gates
243
+ ```
244
+
245
+ #### Options
246
+
247
+ | Option | Aliases | Required | Default | Description |
248
+ |---|---|---|---|---|
249
+ | `--only` | | No | | Run only specific checks (comma-separated check names). |
250
+ | `--skip` | | No | | Skip specific checks (comma-separated check names). |
251
+ | `--gate` | | No | | Run checks for specific gates only (comma-separated, 1-5). |
252
+ | `--verbose` | -v | No | `false` | Enable verbose output. |
253
+ | `--fix` | | No | `false` | Auto-fix issues where possible. |
254
+ | `--guardrails` | -g | No | | Path to guardrails.yaml. |
255
+ | `--generated-dir` | -d | No | `"packages/"` | Path to generated files directory. |
256
+ | `--changed-files` | | No | | Path to file containing list of changed files (for CI). |
257
+ | `--list` | | No | `false` | List available checks and exit. |
258
+ | `--list-gates` | | No | `false` | List available gates and exit. |
259
+
260
+ #### Exit Codes
261
+
262
+ **Exit 0:** All checks passed (or --list/--list-gates output).
263
+
264
+ - **stdout:** format=`text`
265
+
266
+ **Exit 1:** One or more checks failed.
267
+
268
+ - **stdout:** format=`text`
269
+
270
+ - **stderr:** format=`text` *(optional)*
271
+
272
+ #### Extensions
273
+
274
+ ```yaml
275
+ x-agent:
276
+ riskLevel: low
277
+ requiresConfirmation: false
278
+ idempotent: true
279
+ sideEffects:
280
+
281
+ recommendedBeforeUse:
282
+ - Run generate first so generated files exist.
283
+ ```
284
+
285
+ ---
286
+
287
+ ### pipeline
288
+
289
+ Run full guardrails pipeline.
290
+
291
+ Executes the complete contract-first pipeline in order: Gate 1,2 (pre-generation checks) → Generate → Gate 3,4,5 (post-generation checks). Supports --continue-on-error to run all steps regardless of failures.
292
+
293
+ **Usage:**
294
+
295
+ ```
296
+ micro-contracts pipeline
297
+ ```
298
+ ```
299
+ micro-contracts pipeline --verbose
300
+ ```
301
+ ```
302
+ micro-contracts pipeline --continue-on-error
303
+ ```
304
+ ```
305
+ micro-contracts pipeline --contracts-only --skip-lint
306
+ ```
307
+
308
+ #### Options
309
+
310
+ | Option | Aliases | Required | Default | Description |
311
+ |---|---|---|---|---|
312
+ | `--config` | -c | No | | Path to config file (micro-contracts.config.yaml). |
313
+ | `--verbose` | -v | No | `false` | Enable verbose output (show detailed logs). |
314
+ | `--skip` | | No | | Skip specific checks (comma-separated). |
315
+ | `--continue-on-error` | | No | `false` | Continue running even if a step fails. |
316
+ | `--guardrails` | -g | No | | Path to guardrails.yaml. |
317
+ | `--generated-dir` | -d | No | `"packages/"` | Path to generated files directory. |
318
+ | `--manifest` | | No | `true` | Generate manifest after generation. Enabled by default. Use --no-manifest to disable. |
319
+ | `--skip-lint` | | No | `false` | Skip Spectral linting before generation. |
320
+ | `--contracts-only` | | No | `false` | Generate contract packages only. |
321
+ | `--server-only` | | No | `false` | Generate server routes only. |
322
+ | `--frontend-only` | | No | `false` | Generate frontend clients only. |
323
+ | `--docs-only` | | No | `false` | Generate documentation only. |
324
+ | `--force` | | No | `false` | Bypass input hash cache and always regenerate. |
325
+ | `--cache` | | No | `true` | Enable input hash caching. Enabled by default. Use --no-cache to disable both reading and writing cache. |
326
+
327
+ #### Exit Codes
328
+
329
+ **Exit 0:** Pipeline completed successfully. All gates passed and generation succeeded.
330
+
331
+ - **stdout:** format=`text`
332
+
333
+ **Exit 1:** Pipeline failed. One or more steps had errors.
334
+
335
+ - **stdout:** format=`text`
336
+
337
+ - **stderr:** format=`text` *(optional)*
338
+
339
+ #### Extensions
340
+
341
+ ```yaml
342
+ x-agent:
343
+ riskLevel: medium
344
+ requiresConfirmation: false
345
+ idempotent: true
346
+ sideEffects:
347
+ - file_write
348
+ recommendedBeforeUse:
349
+ - Ensure micro-contracts.config.yaml and guardrails.yaml exist.
350
+ - Verify OpenAPI specs are valid.
351
+ ```
352
+
353
+ ---
354
+
355
+ ### deps
356
+
357
+ Analyze module dependencies.
358
+
359
+ Reads x-micro-contracts-depend-on declarations from OpenAPI specs and config dependsOn fields. Can output dependency graphs (Mermaid), impact analysis, reverse lookups, and validation results.
360
+
361
+ **Usage:**
362
+
363
+ ```
364
+ micro-contracts deps
365
+ ```
366
+ ```
367
+ micro-contracts deps --graph
368
+ ```
369
+ ```
370
+ micro-contracts deps --module billing
371
+ ```
372
+ ```
373
+ micro-contracts deps --impact core.User.getUsers
374
+ ```
375
+ ```
376
+ micro-contracts deps --who-depends-on core
377
+ ```
378
+ ```
379
+ micro-contracts deps --validate
380
+ ```
381
+
382
+ #### Options
383
+
384
+ | Option | Aliases | Required | Default | Description |
385
+ |---|---|---|---|---|
386
+ | `--config` | -c | No | | Path to config file. |
387
+ | `--module` | -m | No | | Module to analyze. |
388
+ | `--graph` | | No | `false` | Output dependency graph in Mermaid format. |
389
+ | `--impact` | | No | | Analyze impact of changing a specific API (e.g., core.User.getUsers). |
390
+ | `--who-depends-on` | | No | | Find modules that depend on a specific API. |
391
+ | `--validate` | | No | `false` | Validate dependencies against OpenAPI declarations. |
392
+
393
+ #### Exit Codes
394
+
395
+ **Exit 0:** Dependency analysis completed successfully.
396
+
397
+ - **stdout:** format=`text`
398
+
399
+ **Exit 1:** Analysis failed or validation errors found.
400
+
401
+ - **stderr:** format=`text`
402
+
403
+ #### Extensions
404
+
405
+ ```yaml
406
+ x-agent:
407
+ riskLevel: low
408
+ requiresConfirmation: false
409
+ idempotent: true
410
+ sideEffects:
411
+
412
+ ```
413
+
414
+ ---
415
+
416
+ ### guardrails-init
417
+
418
+ Create a guardrails.yaml configuration file.
419
+
420
+ Generates a starter guardrails.yaml with default check configuration. Fails if the target file already exists.
421
+
422
+ **Usage:**
423
+
424
+ ```
425
+ micro-contracts guardrails-init
426
+ ```
427
+ ```
428
+ micro-contracts guardrails-init -o custom-guardrails.yaml
429
+ ```
430
+
431
+ #### Options
432
+
433
+ | Option | Aliases | Required | Default | Description |
434
+ |---|---|---|---|---|
435
+ | `--output` | -o | No | `"guardrails.yaml"` | Output path for guardrails.yaml. |
436
+
437
+ #### Exit Codes
438
+
439
+ **Exit 0:** guardrails.yaml created successfully.
440
+
441
+ - **stdout:** format=`text`
442
+
443
+ - **Generated files:**
444
+ - `{options.output}` (application/yaml)
445
+
446
+ **Exit 1:** Failed to create (file already exists or write error).
447
+
448
+ - **stderr:** format=`text`
449
+
450
+ #### Extensions
451
+
452
+ ```yaml
453
+ x-agent:
454
+ riskLevel: low
455
+ requiresConfirmation: false
456
+ idempotent: false
457
+ sideEffects:
458
+ - file_write
459
+ ```
460
+
461
+ ---
462
+
463
+ ### manifest
464
+
465
+ Generate or verify manifest for generated artifacts.
466
+
467
+ Scans a directory of generated files and produces a .generated-manifest.json containing file hashes. In verify mode, checks that existing files match the manifest.
468
+
469
+ **Usage:**
470
+
471
+ ```
472
+ micro-contracts manifest
473
+ ```
474
+ ```
475
+ micro-contracts manifest -d packages/
476
+ ```
477
+ ```
478
+ micro-contracts manifest --verify
479
+ ```
480
+ ```
481
+ micro-contracts manifest -o custom-manifest.json
482
+ ```
483
+
484
+ #### Options
485
+
486
+ | Option | Aliases | Required | Default | Description |
487
+ |---|---|---|---|---|
488
+ | `--dir` | -d | No | `"packages/"` | Directory to scan. |
489
+ | `--verify` | | No | `false` | Verify existing manifest instead of generating. |
490
+ | `--output` | -o | No | | Output manifest path. Defaults to {dir}/.generated-manifest.json. |
491
+
492
+ #### Exit Codes
493
+
494
+ **Exit 0:** Manifest generated or verification passed.
495
+
496
+ - **stdout:** format=`text`
497
+
498
+ - **Generated files:**
499
+ - `{options.dir}/.generated-manifest.json` (application/json) *(optional)*
500
+
501
+ **Exit 1:** Directory not found, manifest generation failed, or verification failed.
502
+
503
+ - **stderr:** format=`text`
504
+
505
+ #### Extensions
506
+
507
+ ```yaml
508
+ x-agent:
509
+ riskLevel: low
510
+ requiresConfirmation: false
511
+ idempotent: true
512
+ sideEffects:
513
+ - file_write
514
+ ```
515
+
516
+ ---