micro-contracts 0.14.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.
- package/README.md +4 -0
- package/cli-contract.yaml +736 -0
- package/docs/cli-reference.md +516 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -340,6 +340,8 @@ modules:
|
|
|
340
340
|
|
|
341
341
|
## CLI Reference
|
|
342
342
|
|
|
343
|
+
> **Machine-readable contract**: The full CLI specification is available as [`cli-contract.yaml`](cli-contract.yaml) ([CLI Contracts](https://www.npmjs.com/package/cli-contracts) format). For the detailed reference with exit codes, output contracts, and AI agent policies, see **[CLI Reference (full)](docs/cli-reference.md)**.
|
|
344
|
+
|
|
343
345
|
### generate
|
|
344
346
|
|
|
345
347
|
Generate code from OpenAPI specifications.
|
|
@@ -484,6 +486,8 @@ export class UserService implements UserServiceApi {
|
|
|
484
486
|
| Document | Description |
|
|
485
487
|
|----------|-------------|
|
|
486
488
|
| **[Examples](./examples/)** | Complete working project with multiple modules, overlays, and cross-module dependencies |
|
|
489
|
+
| **[CLI Reference](docs/cli-reference.md)** | Full CLI reference with exit codes, output contracts, and AI agent policies |
|
|
490
|
+
| **[CLI Contract](cli-contract.yaml)** | Machine-readable CLI specification ([CLI Contracts](https://www.npmjs.com/package/cli-contracts) format) |
|
|
487
491
|
| **[Screen Spec](docs/screen-spec.md)** | Frontend screen contracts — ViewModel, navigation, analytics events in OpenAPI |
|
|
488
492
|
| **[OpenAPI Overlays (Deep Dive)](docs/overlays-deep-dive.md)** | Complete overlay examples, JSONPath patterns, template context |
|
|
489
493
|
| **[Enforceable Guardrails (AI-ready)](docs/development-guardrails.md)** | CI integration, security checks, allowlist configuration |
|
|
@@ -0,0 +1,736 @@
|
|
|
1
|
+
# yaml-language-server: $schema=./node_modules/cli-contracts/schemas/cli-contract.schema.json
|
|
2
|
+
cliContracts: 0.1.0
|
|
3
|
+
|
|
4
|
+
info:
|
|
5
|
+
title: micro-contracts CLI
|
|
6
|
+
version: 0.14.1
|
|
7
|
+
description: >-
|
|
8
|
+
Contract-first OpenAPI toolchain for TypeScript Web/API systems.
|
|
9
|
+
Generates contract packages, server routes, and frontend clients
|
|
10
|
+
from OpenAPI specifications with enforceable guardrails.
|
|
11
|
+
license:
|
|
12
|
+
name: MIT
|
|
13
|
+
contact:
|
|
14
|
+
name: foo-ogawa
|
|
15
|
+
url: https://github.com/foo-ogawa/micro-contracts
|
|
16
|
+
|
|
17
|
+
commandSets:
|
|
18
|
+
micro-contracts:
|
|
19
|
+
summary: Contract-first OpenAPI toolchain for TypeScript.
|
|
20
|
+
executable: micro-contracts
|
|
21
|
+
|
|
22
|
+
globalOptions:
|
|
23
|
+
- name: version
|
|
24
|
+
aliases: [V]
|
|
25
|
+
description: Print version and exit.
|
|
26
|
+
schema:
|
|
27
|
+
type: boolean
|
|
28
|
+
|
|
29
|
+
- name: help
|
|
30
|
+
aliases: [h]
|
|
31
|
+
description: Show help and exit.
|
|
32
|
+
schema:
|
|
33
|
+
type: boolean
|
|
34
|
+
|
|
35
|
+
commands:
|
|
36
|
+
# ── generate ─────────────────────────────────────
|
|
37
|
+
generate:
|
|
38
|
+
summary: Generate code from OpenAPI specifications.
|
|
39
|
+
description: >-
|
|
40
|
+
Loads the multi-module config, applies overlays, runs Spectral
|
|
41
|
+
linting (unless skipped), and generates contract packages, server
|
|
42
|
+
routes, frontend clients, and documentation from OpenAPI specs.
|
|
43
|
+
Supports input-hash caching to skip unnecessary regeneration.
|
|
44
|
+
usage:
|
|
45
|
+
- micro-contracts generate
|
|
46
|
+
- micro-contracts generate -c my-config.yaml
|
|
47
|
+
- micro-contracts generate -m core,billing
|
|
48
|
+
- micro-contracts generate --contracts-only
|
|
49
|
+
- micro-contracts generate --force
|
|
50
|
+
|
|
51
|
+
options:
|
|
52
|
+
- name: config
|
|
53
|
+
aliases: [c]
|
|
54
|
+
description: Path to config file (micro-contracts.config.yaml).
|
|
55
|
+
valueName: path
|
|
56
|
+
schema:
|
|
57
|
+
type: string
|
|
58
|
+
file:
|
|
59
|
+
mode: read
|
|
60
|
+
exists: false
|
|
61
|
+
mediaType: application/yaml
|
|
62
|
+
encoding: utf-8
|
|
63
|
+
|
|
64
|
+
- name: module
|
|
65
|
+
aliases: [m]
|
|
66
|
+
description: Module names, comma-separated. Generates all modules if omitted.
|
|
67
|
+
valueName: names
|
|
68
|
+
schema:
|
|
69
|
+
type: string
|
|
70
|
+
|
|
71
|
+
- name: contracts-only
|
|
72
|
+
description: Generate contract packages only.
|
|
73
|
+
schema:
|
|
74
|
+
type: boolean
|
|
75
|
+
default: false
|
|
76
|
+
|
|
77
|
+
- name: server-only
|
|
78
|
+
description: Generate server routes only.
|
|
79
|
+
schema:
|
|
80
|
+
type: boolean
|
|
81
|
+
default: false
|
|
82
|
+
|
|
83
|
+
- name: frontend-only
|
|
84
|
+
description: Generate frontend clients only.
|
|
85
|
+
schema:
|
|
86
|
+
type: boolean
|
|
87
|
+
default: false
|
|
88
|
+
|
|
89
|
+
- name: docs-only
|
|
90
|
+
description: Generate documentation only.
|
|
91
|
+
schema:
|
|
92
|
+
type: boolean
|
|
93
|
+
default: false
|
|
94
|
+
|
|
95
|
+
- name: skip-lint
|
|
96
|
+
description: Skip Spectral linting before generation.
|
|
97
|
+
schema:
|
|
98
|
+
type: boolean
|
|
99
|
+
default: false
|
|
100
|
+
|
|
101
|
+
- name: manifest
|
|
102
|
+
description: >-
|
|
103
|
+
Generate manifest after generation. Enabled by default when
|
|
104
|
+
guardrails.yaml has a generated section. Use --no-manifest to disable.
|
|
105
|
+
schema:
|
|
106
|
+
type: boolean
|
|
107
|
+
default: true
|
|
108
|
+
|
|
109
|
+
- name: manifest-dir
|
|
110
|
+
description: Directory for manifest output.
|
|
111
|
+
valueName: path
|
|
112
|
+
schema:
|
|
113
|
+
type: string
|
|
114
|
+
default: packages/
|
|
115
|
+
|
|
116
|
+
- name: force
|
|
117
|
+
description: Bypass input hash cache and always regenerate.
|
|
118
|
+
schema:
|
|
119
|
+
type: boolean
|
|
120
|
+
default: false
|
|
121
|
+
|
|
122
|
+
- name: cache
|
|
123
|
+
description: >-
|
|
124
|
+
Enable input hash caching. Enabled by default.
|
|
125
|
+
Use --no-cache to disable both reading and writing cache.
|
|
126
|
+
schema:
|
|
127
|
+
type: boolean
|
|
128
|
+
default: true
|
|
129
|
+
|
|
130
|
+
exits:
|
|
131
|
+
'0':
|
|
132
|
+
description: Generation succeeded.
|
|
133
|
+
stdout:
|
|
134
|
+
format: text
|
|
135
|
+
files:
|
|
136
|
+
- path: packages/contract/{module}/**/*.ts
|
|
137
|
+
required: true
|
|
138
|
+
mediaType: text/x-typescript
|
|
139
|
+
encoding: utf-8
|
|
140
|
+
description: Generated contract packages.
|
|
141
|
+
- path: packages/contract-published/{module}/**/*.ts
|
|
142
|
+
required: false
|
|
143
|
+
mediaType: text/x-typescript
|
|
144
|
+
encoding: utf-8
|
|
145
|
+
description: Generated public contract packages.
|
|
146
|
+
|
|
147
|
+
'1':
|
|
148
|
+
description: Generation failed (config not found, spec invalid, or generation error).
|
|
149
|
+
stderr:
|
|
150
|
+
format: text
|
|
151
|
+
|
|
152
|
+
x-agent:
|
|
153
|
+
riskLevel: medium
|
|
154
|
+
requiresConfirmation: false
|
|
155
|
+
idempotent: true
|
|
156
|
+
sideEffects:
|
|
157
|
+
- file_write
|
|
158
|
+
recommendedBeforeUse:
|
|
159
|
+
- Ensure micro-contracts.config.yaml exists.
|
|
160
|
+
- Verify OpenAPI specs are valid.
|
|
161
|
+
|
|
162
|
+
# ── lint ─────────────────────────────────────────
|
|
163
|
+
lint:
|
|
164
|
+
summary: Lint OpenAPI specification.
|
|
165
|
+
description: >-
|
|
166
|
+
Validates an OpenAPI specification for x-micro-contracts extension
|
|
167
|
+
violations and structural issues using Spectral rules.
|
|
168
|
+
usage:
|
|
169
|
+
- micro-contracts lint spec/core/openapi/core.yaml
|
|
170
|
+
- micro-contracts lint spec/core/openapi/core.yaml --strict
|
|
171
|
+
|
|
172
|
+
arguments:
|
|
173
|
+
- name: input
|
|
174
|
+
index: 0
|
|
175
|
+
required: true
|
|
176
|
+
description: Path to OpenAPI spec file.
|
|
177
|
+
schema:
|
|
178
|
+
type: string
|
|
179
|
+
file:
|
|
180
|
+
mode: read
|
|
181
|
+
exists: true
|
|
182
|
+
mediaType: application/yaml
|
|
183
|
+
encoding: utf-8
|
|
184
|
+
|
|
185
|
+
options:
|
|
186
|
+
- name: strict
|
|
187
|
+
description: Treat warnings as errors.
|
|
188
|
+
schema:
|
|
189
|
+
type: boolean
|
|
190
|
+
default: false
|
|
191
|
+
|
|
192
|
+
exits:
|
|
193
|
+
'0':
|
|
194
|
+
description: Spec is valid. No lint errors found.
|
|
195
|
+
stdout:
|
|
196
|
+
format: text
|
|
197
|
+
|
|
198
|
+
'1':
|
|
199
|
+
description: Lint failed. Errors or warnings (in strict mode) found.
|
|
200
|
+
stderr:
|
|
201
|
+
format: text
|
|
202
|
+
|
|
203
|
+
x-agent:
|
|
204
|
+
riskLevel: low
|
|
205
|
+
requiresConfirmation: false
|
|
206
|
+
idempotent: true
|
|
207
|
+
sideEffects: []
|
|
208
|
+
|
|
209
|
+
# ── init ─────────────────────────────────────────
|
|
210
|
+
init:
|
|
211
|
+
summary: Initialize a new module structure with starter templates.
|
|
212
|
+
description: >-
|
|
213
|
+
Creates the directory structure, starter Handlebars templates,
|
|
214
|
+
shared schemas, Spectral rules, and optional config file for
|
|
215
|
+
a new module. Can also process an existing OpenAPI spec to
|
|
216
|
+
auto-add x-micro-contracts extensions.
|
|
217
|
+
usage:
|
|
218
|
+
- micro-contracts init core
|
|
219
|
+
- micro-contracts init core --openapi path/to/spec.yaml
|
|
220
|
+
- micro-contracts init myScreens --screens
|
|
221
|
+
- micro-contracts init users --skip-templates
|
|
222
|
+
|
|
223
|
+
arguments:
|
|
224
|
+
- name: name
|
|
225
|
+
index: 0
|
|
226
|
+
required: true
|
|
227
|
+
description: Module name (e.g., core, users, billing).
|
|
228
|
+
schema:
|
|
229
|
+
type: string
|
|
230
|
+
|
|
231
|
+
options:
|
|
232
|
+
- name: dir
|
|
233
|
+
aliases: [d]
|
|
234
|
+
description: Base directory for server/frontend files.
|
|
235
|
+
valueName: path
|
|
236
|
+
schema:
|
|
237
|
+
type: string
|
|
238
|
+
default: src
|
|
239
|
+
|
|
240
|
+
- name: openapi
|
|
241
|
+
aliases: [i]
|
|
242
|
+
description: OpenAPI spec to process (auto-adds x-micro-contracts-service/method extensions).
|
|
243
|
+
valueName: path
|
|
244
|
+
schema:
|
|
245
|
+
type: string
|
|
246
|
+
file:
|
|
247
|
+
mode: read
|
|
248
|
+
exists: true
|
|
249
|
+
mediaType: application/yaml
|
|
250
|
+
encoding: utf-8
|
|
251
|
+
|
|
252
|
+
- name: output
|
|
253
|
+
aliases: [o]
|
|
254
|
+
description: Output path for processed OpenAPI. Defaults to spec/{name}/openapi/{name}.yaml.
|
|
255
|
+
valueName: path
|
|
256
|
+
schema:
|
|
257
|
+
type: string
|
|
258
|
+
|
|
259
|
+
- name: skip-templates
|
|
260
|
+
description: Skip creating starter Handlebars templates.
|
|
261
|
+
schema:
|
|
262
|
+
type: boolean
|
|
263
|
+
default: false
|
|
264
|
+
|
|
265
|
+
- name: screens
|
|
266
|
+
description: Initialize as screen spec module (generates screen templates and starter spec).
|
|
267
|
+
schema:
|
|
268
|
+
type: boolean
|
|
269
|
+
default: false
|
|
270
|
+
|
|
271
|
+
exits:
|
|
272
|
+
'0':
|
|
273
|
+
description: Module initialized successfully.
|
|
274
|
+
stdout:
|
|
275
|
+
format: text
|
|
276
|
+
files:
|
|
277
|
+
- path: spec/{name}/openapi/{name}.yaml
|
|
278
|
+
required: false
|
|
279
|
+
mediaType: application/yaml
|
|
280
|
+
encoding: utf-8
|
|
281
|
+
description: OpenAPI spec (created when --openapi provided or --screens used).
|
|
282
|
+
- path: spec/default/templates/*.hbs
|
|
283
|
+
required: false
|
|
284
|
+
mediaType: text/x-handlebars-template
|
|
285
|
+
encoding: utf-8
|
|
286
|
+
description: Starter Handlebars templates.
|
|
287
|
+
- path: micro-contracts.config.yaml
|
|
288
|
+
required: false
|
|
289
|
+
mediaType: application/yaml
|
|
290
|
+
encoding: utf-8
|
|
291
|
+
description: Config file (created if not already present).
|
|
292
|
+
|
|
293
|
+
'1':
|
|
294
|
+
description: Initialization failed (OpenAPI file not found or write error).
|
|
295
|
+
stderr:
|
|
296
|
+
format: text
|
|
297
|
+
|
|
298
|
+
x-agent:
|
|
299
|
+
riskLevel: medium
|
|
300
|
+
requiresConfirmation: false
|
|
301
|
+
idempotent: true
|
|
302
|
+
sideEffects:
|
|
303
|
+
- file_write
|
|
304
|
+
- directory_create
|
|
305
|
+
|
|
306
|
+
# ── check ────────────────────────────────────────
|
|
307
|
+
check:
|
|
308
|
+
summary: Run guardrail checks.
|
|
309
|
+
description: >-
|
|
310
|
+
Runs AI guardrail checks against generated code and config.
|
|
311
|
+
Supports gating (1-5), selective check execution, auto-fix,
|
|
312
|
+
and CI integration via changed-files input.
|
|
313
|
+
usage:
|
|
314
|
+
- micro-contracts check
|
|
315
|
+
- micro-contracts check --gate 1,2
|
|
316
|
+
- micro-contracts check --only drift,manifest
|
|
317
|
+
- micro-contracts check --fix
|
|
318
|
+
- micro-contracts check --list
|
|
319
|
+
- micro-contracts check --list-gates
|
|
320
|
+
|
|
321
|
+
options:
|
|
322
|
+
- name: only
|
|
323
|
+
description: Run only specific checks (comma-separated check names).
|
|
324
|
+
valueName: checks
|
|
325
|
+
schema:
|
|
326
|
+
type: string
|
|
327
|
+
|
|
328
|
+
- name: skip
|
|
329
|
+
description: Skip specific checks (comma-separated check names).
|
|
330
|
+
valueName: checks
|
|
331
|
+
schema:
|
|
332
|
+
type: string
|
|
333
|
+
|
|
334
|
+
- name: gate
|
|
335
|
+
description: Run checks for specific gates only (comma-separated, 1-5).
|
|
336
|
+
valueName: gates
|
|
337
|
+
schema:
|
|
338
|
+
type: string
|
|
339
|
+
|
|
340
|
+
- name: verbose
|
|
341
|
+
aliases: [v]
|
|
342
|
+
description: Enable verbose output.
|
|
343
|
+
schema:
|
|
344
|
+
type: boolean
|
|
345
|
+
default: false
|
|
346
|
+
|
|
347
|
+
- name: fix
|
|
348
|
+
description: Auto-fix issues where possible.
|
|
349
|
+
schema:
|
|
350
|
+
type: boolean
|
|
351
|
+
default: false
|
|
352
|
+
|
|
353
|
+
- name: guardrails
|
|
354
|
+
aliases: [g]
|
|
355
|
+
description: Path to guardrails.yaml.
|
|
356
|
+
valueName: path
|
|
357
|
+
schema:
|
|
358
|
+
type: string
|
|
359
|
+
file:
|
|
360
|
+
mode: read
|
|
361
|
+
exists: false
|
|
362
|
+
mediaType: application/yaml
|
|
363
|
+
encoding: utf-8
|
|
364
|
+
|
|
365
|
+
- name: generated-dir
|
|
366
|
+
aliases: [d]
|
|
367
|
+
description: Path to generated files directory.
|
|
368
|
+
valueName: path
|
|
369
|
+
schema:
|
|
370
|
+
type: string
|
|
371
|
+
default: packages/
|
|
372
|
+
|
|
373
|
+
- name: changed-files
|
|
374
|
+
description: Path to file containing list of changed files (for CI).
|
|
375
|
+
valueName: path
|
|
376
|
+
schema:
|
|
377
|
+
type: string
|
|
378
|
+
file:
|
|
379
|
+
mode: read
|
|
380
|
+
exists: true
|
|
381
|
+
mediaType: text/plain
|
|
382
|
+
encoding: utf-8
|
|
383
|
+
|
|
384
|
+
- name: list
|
|
385
|
+
description: List available checks and exit.
|
|
386
|
+
schema:
|
|
387
|
+
type: boolean
|
|
388
|
+
default: false
|
|
389
|
+
|
|
390
|
+
- name: list-gates
|
|
391
|
+
description: List available gates and exit.
|
|
392
|
+
schema:
|
|
393
|
+
type: boolean
|
|
394
|
+
default: false
|
|
395
|
+
|
|
396
|
+
exits:
|
|
397
|
+
'0':
|
|
398
|
+
description: All checks passed (or --list/--list-gates output).
|
|
399
|
+
stdout:
|
|
400
|
+
format: text
|
|
401
|
+
|
|
402
|
+
'1':
|
|
403
|
+
description: One or more checks failed.
|
|
404
|
+
stdout:
|
|
405
|
+
format: text
|
|
406
|
+
stderr:
|
|
407
|
+
required: false
|
|
408
|
+
format: text
|
|
409
|
+
|
|
410
|
+
x-agent:
|
|
411
|
+
riskLevel: low
|
|
412
|
+
requiresConfirmation: false
|
|
413
|
+
idempotent: true
|
|
414
|
+
sideEffects: []
|
|
415
|
+
recommendedBeforeUse:
|
|
416
|
+
- Run generate first so generated files exist.
|
|
417
|
+
|
|
418
|
+
# ── pipeline ─────────────────────────────────────
|
|
419
|
+
pipeline:
|
|
420
|
+
summary: Run full guardrails pipeline.
|
|
421
|
+
description: >-
|
|
422
|
+
Executes the complete contract-first pipeline in order:
|
|
423
|
+
Gate 1,2 (pre-generation checks) → Generate → Gate 3,4,5
|
|
424
|
+
(post-generation checks). Supports --continue-on-error to
|
|
425
|
+
run all steps regardless of failures.
|
|
426
|
+
usage:
|
|
427
|
+
- micro-contracts pipeline
|
|
428
|
+
- micro-contracts pipeline --verbose
|
|
429
|
+
- micro-contracts pipeline --continue-on-error
|
|
430
|
+
- micro-contracts pipeline --contracts-only --skip-lint
|
|
431
|
+
|
|
432
|
+
options:
|
|
433
|
+
- name: config
|
|
434
|
+
aliases: [c]
|
|
435
|
+
description: Path to config file (micro-contracts.config.yaml).
|
|
436
|
+
valueName: path
|
|
437
|
+
schema:
|
|
438
|
+
type: string
|
|
439
|
+
file:
|
|
440
|
+
mode: read
|
|
441
|
+
exists: false
|
|
442
|
+
mediaType: application/yaml
|
|
443
|
+
encoding: utf-8
|
|
444
|
+
|
|
445
|
+
- name: verbose
|
|
446
|
+
aliases: [v]
|
|
447
|
+
description: Enable verbose output (show detailed logs).
|
|
448
|
+
schema:
|
|
449
|
+
type: boolean
|
|
450
|
+
default: false
|
|
451
|
+
|
|
452
|
+
- name: skip
|
|
453
|
+
description: Skip specific checks (comma-separated).
|
|
454
|
+
valueName: checks
|
|
455
|
+
schema:
|
|
456
|
+
type: string
|
|
457
|
+
|
|
458
|
+
- name: continue-on-error
|
|
459
|
+
description: Continue running even if a step fails.
|
|
460
|
+
schema:
|
|
461
|
+
type: boolean
|
|
462
|
+
default: false
|
|
463
|
+
|
|
464
|
+
- name: guardrails
|
|
465
|
+
aliases: [g]
|
|
466
|
+
description: Path to guardrails.yaml.
|
|
467
|
+
valueName: path
|
|
468
|
+
schema:
|
|
469
|
+
type: string
|
|
470
|
+
file:
|
|
471
|
+
mode: read
|
|
472
|
+
exists: false
|
|
473
|
+
mediaType: application/yaml
|
|
474
|
+
encoding: utf-8
|
|
475
|
+
|
|
476
|
+
- name: generated-dir
|
|
477
|
+
aliases: [d]
|
|
478
|
+
description: Path to generated files directory.
|
|
479
|
+
valueName: path
|
|
480
|
+
schema:
|
|
481
|
+
type: string
|
|
482
|
+
default: packages/
|
|
483
|
+
|
|
484
|
+
- name: manifest
|
|
485
|
+
description: >-
|
|
486
|
+
Generate manifest after generation. Enabled by default.
|
|
487
|
+
Use --no-manifest to disable.
|
|
488
|
+
schema:
|
|
489
|
+
type: boolean
|
|
490
|
+
default: true
|
|
491
|
+
|
|
492
|
+
- name: skip-lint
|
|
493
|
+
description: Skip Spectral linting before generation.
|
|
494
|
+
schema:
|
|
495
|
+
type: boolean
|
|
496
|
+
default: false
|
|
497
|
+
|
|
498
|
+
- name: contracts-only
|
|
499
|
+
description: Generate contract packages only.
|
|
500
|
+
schema:
|
|
501
|
+
type: boolean
|
|
502
|
+
default: false
|
|
503
|
+
|
|
504
|
+
- name: server-only
|
|
505
|
+
description: Generate server routes only.
|
|
506
|
+
schema:
|
|
507
|
+
type: boolean
|
|
508
|
+
default: false
|
|
509
|
+
|
|
510
|
+
- name: frontend-only
|
|
511
|
+
description: Generate frontend clients only.
|
|
512
|
+
schema:
|
|
513
|
+
type: boolean
|
|
514
|
+
default: false
|
|
515
|
+
|
|
516
|
+
- name: docs-only
|
|
517
|
+
description: Generate documentation only.
|
|
518
|
+
schema:
|
|
519
|
+
type: boolean
|
|
520
|
+
default: false
|
|
521
|
+
|
|
522
|
+
- name: force
|
|
523
|
+
description: Bypass input hash cache and always regenerate.
|
|
524
|
+
schema:
|
|
525
|
+
type: boolean
|
|
526
|
+
default: false
|
|
527
|
+
|
|
528
|
+
- name: cache
|
|
529
|
+
description: >-
|
|
530
|
+
Enable input hash caching. Enabled by default.
|
|
531
|
+
Use --no-cache to disable both reading and writing cache.
|
|
532
|
+
schema:
|
|
533
|
+
type: boolean
|
|
534
|
+
default: true
|
|
535
|
+
|
|
536
|
+
exits:
|
|
537
|
+
'0':
|
|
538
|
+
description: Pipeline completed successfully. All gates passed and generation succeeded.
|
|
539
|
+
stdout:
|
|
540
|
+
format: text
|
|
541
|
+
|
|
542
|
+
'1':
|
|
543
|
+
description: Pipeline failed. One or more steps had errors.
|
|
544
|
+
stdout:
|
|
545
|
+
format: text
|
|
546
|
+
stderr:
|
|
547
|
+
required: false
|
|
548
|
+
format: text
|
|
549
|
+
|
|
550
|
+
x-agent:
|
|
551
|
+
riskLevel: medium
|
|
552
|
+
requiresConfirmation: false
|
|
553
|
+
idempotent: true
|
|
554
|
+
sideEffects:
|
|
555
|
+
- file_write
|
|
556
|
+
recommendedBeforeUse:
|
|
557
|
+
- Ensure micro-contracts.config.yaml and guardrails.yaml exist.
|
|
558
|
+
- Verify OpenAPI specs are valid.
|
|
559
|
+
|
|
560
|
+
# ── deps ─────────────────────────────────────────
|
|
561
|
+
deps:
|
|
562
|
+
summary: Analyze module dependencies.
|
|
563
|
+
description: >-
|
|
564
|
+
Reads x-micro-contracts-depend-on declarations from OpenAPI specs
|
|
565
|
+
and config dependsOn fields. Can output dependency graphs (Mermaid),
|
|
566
|
+
impact analysis, reverse lookups, and validation results.
|
|
567
|
+
usage:
|
|
568
|
+
- micro-contracts deps
|
|
569
|
+
- micro-contracts deps --graph
|
|
570
|
+
- micro-contracts deps --module billing
|
|
571
|
+
- micro-contracts deps --impact core.User.getUsers
|
|
572
|
+
- micro-contracts deps --who-depends-on core
|
|
573
|
+
- micro-contracts deps --validate
|
|
574
|
+
|
|
575
|
+
options:
|
|
576
|
+
- name: config
|
|
577
|
+
aliases: [c]
|
|
578
|
+
description: Path to config file.
|
|
579
|
+
valueName: path
|
|
580
|
+
schema:
|
|
581
|
+
type: string
|
|
582
|
+
file:
|
|
583
|
+
mode: read
|
|
584
|
+
exists: false
|
|
585
|
+
mediaType: application/yaml
|
|
586
|
+
encoding: utf-8
|
|
587
|
+
|
|
588
|
+
- name: module
|
|
589
|
+
aliases: [m]
|
|
590
|
+
description: Module to analyze.
|
|
591
|
+
valueName: name
|
|
592
|
+
schema:
|
|
593
|
+
type: string
|
|
594
|
+
|
|
595
|
+
- name: graph
|
|
596
|
+
description: Output dependency graph in Mermaid format.
|
|
597
|
+
schema:
|
|
598
|
+
type: boolean
|
|
599
|
+
default: false
|
|
600
|
+
|
|
601
|
+
- name: impact
|
|
602
|
+
description: Analyze impact of changing a specific API (e.g., core.User.getUsers).
|
|
603
|
+
valueName: ref
|
|
604
|
+
schema:
|
|
605
|
+
type: string
|
|
606
|
+
|
|
607
|
+
- name: who-depends-on
|
|
608
|
+
description: Find modules that depend on a specific API.
|
|
609
|
+
valueName: ref
|
|
610
|
+
schema:
|
|
611
|
+
type: string
|
|
612
|
+
|
|
613
|
+
- name: validate
|
|
614
|
+
description: Validate dependencies against OpenAPI declarations.
|
|
615
|
+
schema:
|
|
616
|
+
type: boolean
|
|
617
|
+
default: false
|
|
618
|
+
|
|
619
|
+
exits:
|
|
620
|
+
'0':
|
|
621
|
+
description: Dependency analysis completed successfully.
|
|
622
|
+
stdout:
|
|
623
|
+
format: text
|
|
624
|
+
|
|
625
|
+
'1':
|
|
626
|
+
description: Analysis failed or validation errors found.
|
|
627
|
+
stderr:
|
|
628
|
+
format: text
|
|
629
|
+
|
|
630
|
+
x-agent:
|
|
631
|
+
riskLevel: low
|
|
632
|
+
requiresConfirmation: false
|
|
633
|
+
idempotent: true
|
|
634
|
+
sideEffects: []
|
|
635
|
+
|
|
636
|
+
# ── guardrails-init ──────────────────────────────
|
|
637
|
+
guardrails-init:
|
|
638
|
+
path: [guardrails-init]
|
|
639
|
+
summary: Create a guardrails.yaml configuration file.
|
|
640
|
+
description: >-
|
|
641
|
+
Generates a starter guardrails.yaml with default check
|
|
642
|
+
configuration. Fails if the target file already exists.
|
|
643
|
+
usage:
|
|
644
|
+
- micro-contracts guardrails-init
|
|
645
|
+
- micro-contracts guardrails-init -o custom-guardrails.yaml
|
|
646
|
+
|
|
647
|
+
options:
|
|
648
|
+
- name: output
|
|
649
|
+
aliases: [o]
|
|
650
|
+
description: Output path for guardrails.yaml.
|
|
651
|
+
valueName: path
|
|
652
|
+
schema:
|
|
653
|
+
type: string
|
|
654
|
+
default: guardrails.yaml
|
|
655
|
+
|
|
656
|
+
exits:
|
|
657
|
+
'0':
|
|
658
|
+
description: guardrails.yaml created successfully.
|
|
659
|
+
stdout:
|
|
660
|
+
format: text
|
|
661
|
+
files:
|
|
662
|
+
- path: '{options.output}'
|
|
663
|
+
required: true
|
|
664
|
+
mediaType: application/yaml
|
|
665
|
+
encoding: utf-8
|
|
666
|
+
|
|
667
|
+
'1':
|
|
668
|
+
description: Failed to create (file already exists or write error).
|
|
669
|
+
stderr:
|
|
670
|
+
format: text
|
|
671
|
+
|
|
672
|
+
x-agent:
|
|
673
|
+
riskLevel: low
|
|
674
|
+
requiresConfirmation: false
|
|
675
|
+
idempotent: false
|
|
676
|
+
sideEffects:
|
|
677
|
+
- file_write
|
|
678
|
+
|
|
679
|
+
# ── manifest ─────────────────────────────────────
|
|
680
|
+
manifest:
|
|
681
|
+
summary: Generate or verify manifest for generated artifacts.
|
|
682
|
+
description: >-
|
|
683
|
+
Scans a directory of generated files and produces a
|
|
684
|
+
.generated-manifest.json containing file hashes. In verify
|
|
685
|
+
mode, checks that existing files match the manifest.
|
|
686
|
+
usage:
|
|
687
|
+
- micro-contracts manifest
|
|
688
|
+
- micro-contracts manifest -d packages/
|
|
689
|
+
- micro-contracts manifest --verify
|
|
690
|
+
- micro-contracts manifest -o custom-manifest.json
|
|
691
|
+
|
|
692
|
+
options:
|
|
693
|
+
- name: dir
|
|
694
|
+
aliases: [d]
|
|
695
|
+
description: Directory to scan.
|
|
696
|
+
valueName: path
|
|
697
|
+
schema:
|
|
698
|
+
type: string
|
|
699
|
+
default: packages/
|
|
700
|
+
|
|
701
|
+
- name: verify
|
|
702
|
+
description: Verify existing manifest instead of generating.
|
|
703
|
+
schema:
|
|
704
|
+
type: boolean
|
|
705
|
+
default: false
|
|
706
|
+
|
|
707
|
+
- name: output
|
|
708
|
+
aliases: [o]
|
|
709
|
+
description: Output manifest path. Defaults to {dir}/.generated-manifest.json.
|
|
710
|
+
valueName: path
|
|
711
|
+
schema:
|
|
712
|
+
type: string
|
|
713
|
+
|
|
714
|
+
exits:
|
|
715
|
+
'0':
|
|
716
|
+
description: Manifest generated or verification passed.
|
|
717
|
+
stdout:
|
|
718
|
+
format: text
|
|
719
|
+
files:
|
|
720
|
+
- path: '{options.dir}/.generated-manifest.json'
|
|
721
|
+
required: false
|
|
722
|
+
mediaType: application/json
|
|
723
|
+
encoding: utf-8
|
|
724
|
+
description: Generated manifest (not created in verify mode).
|
|
725
|
+
|
|
726
|
+
'1':
|
|
727
|
+
description: Directory not found, manifest generation failed, or verification failed.
|
|
728
|
+
stderr:
|
|
729
|
+
format: text
|
|
730
|
+
|
|
731
|
+
x-agent:
|
|
732
|
+
riskLevel: low
|
|
733
|
+
requiresConfirmation: false
|
|
734
|
+
idempotent: true
|
|
735
|
+
sideEffects:
|
|
736
|
+
- file_write
|
|
@@ -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
|
+
---
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "micro-contracts",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "Contract-first OpenAPI toolchain that keeps TypeScript UI and microservices aligned via code generation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"files": [
|
|
12
12
|
"dist",
|
|
13
13
|
"docs",
|
|
14
|
+
"cli-contract.yaml",
|
|
14
15
|
"README.md",
|
|
15
16
|
"LICENSE"
|
|
16
17
|
],
|
|
@@ -55,6 +56,7 @@
|
|
|
55
56
|
"devDependencies": {
|
|
56
57
|
"@types/js-yaml": "^4.0.9",
|
|
57
58
|
"@types/node": "^20.11.0",
|
|
59
|
+
"cli-contracts": "^0.1.1",
|
|
58
60
|
"embedoc": "^0.9.0",
|
|
59
61
|
"tsx": "^4.7.0",
|
|
60
62
|
"typescript": "^5.3.3",
|