-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli-contract.yaml
More file actions
1424 lines (1255 loc) · 43.9 KB
/
Copy pathcli-contract.yaml
File metadata and controls
1424 lines (1255 loc) · 43.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# yaml-language-server: $schema=./node_modules/cli-contracts/schemas/cli-contract.schema.json
cli_contracts: 0.1.0
info:
title: micro-contracts CLI
version: 0.17.10
description: >-
Contract-first OpenAPI toolchain for TypeScript Web/API systems.
Generates contract packages, server routes, and frontend clients
from OpenAPI specifications with enforceable guardrails.
license:
name: MIT
contact:
name: foo-log-inc
url: https://github.com/foo-log-inc/micro-contracts
artifact_slots:
openapi-specs:
direction: read
description: OpenAPI specification files
config:
direction: read
description: micro-contracts.config.yaml configuration
generated-packages:
direction: write
description: Generated contract packages, server routes, and frontend clients
guardrails-config:
direction: read
description: guardrails.yaml configuration
manifest:
direction: write
description: Generated manifest (.generated-manifest.json)
command_sets:
micro-contracts:
summary: Contract-first OpenAPI toolchain for TypeScript.
executable: micro-contracts
global_options:
- name: version
aliases: [V]
description: Print version and exit.
schema:
type: boolean
- name: help
aliases: [h]
description: Show help and exit.
schema:
type: boolean
commands:
# ── generate ─────────────────────────────────────
generate:
summary: Generate code from OpenAPI specifications.
description: >-
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.
usage:
- micro-contracts generate
- micro-contracts generate -c my-config.yaml
- micro-contracts generate -m core,billing
- micro-contracts generate --contracts-only
- micro-contracts generate --force
options:
- name: config
aliases: [c]
description: Path to config file (micro-contracts.config.yaml).
value_name: path
schema:
type: string
file:
mode: read
exists: false
media_type: application/yaml
encoding: utf-8
- name: module
aliases: [m]
description: Module names, comma-separated. Generates all modules if omitted.
value_name: names
schema:
type: string
- name: contracts-only
description: Generate contract packages only.
schema:
type: boolean
default: false
- name: server-only
description: Generate server routes only.
schema:
type: boolean
default: false
- name: frontend-only
description: Generate frontend clients only.
schema:
type: boolean
default: false
- name: docs-only
description: Generate documentation only.
schema:
type: boolean
default: false
- name: skip-lint
description: Skip Spectral linting before generation.
schema:
type: boolean
default: false
- name: manifest
description: >-
Generate manifest after generation. Enabled by default when
guardrails.yaml has a generated section. Use --no-manifest to disable.
schema:
type: boolean
default: true
- name: manifest-dir
description: Directory for manifest output.
value_name: path
schema:
type: string
default: packages/
- name: force
description: Bypass input hash cache and always regenerate.
schema:
type: boolean
default: false
- name: cache
description: >-
Enable input hash caching. Enabled by default.
Use --no-cache to disable both reading and writing cache.
schema:
type: boolean
default: true
exits:
'0':
description: Generation succeeded.
stdout:
format: text
files:
- path: packages/contract/{module}/**/*.ts
required: true
media_type: text/x-typescript
encoding: utf-8
description: Generated contract packages.
- path: packages/contract-published/{module}/**/*.ts
required: false
media_type: text/x-typescript
encoding: utf-8
description: Generated public contract packages.
'1':
description: Generation failed (config not found, spec invalid, or generation error).
stderr:
format: text
x-agent:
risk_level: medium
requires_confirmation: false
idempotent: true
side_effects:
- file_write
recommended_before_use:
- Ensure micro-contracts.config.yaml exists.
- Verify OpenAPI specs are valid.
# ── lint ─────────────────────────────────────────
lint:
summary: Lint OpenAPI specification.
description: >-
Validates an OpenAPI specification for x-micro-contracts extension
violations and structural issues using Spectral rules.
usage:
- micro-contracts lint spec/core/openapi/core.yaml
- micro-contracts lint spec/core/openapi/core.yaml --strict
arguments:
- name: input
index: 0
required: true
description: Path to OpenAPI spec file.
schema:
type: string
file:
mode: read
exists: true
media_type: application/yaml
encoding: utf-8
options:
- name: strict
description: Treat warnings as errors.
schema:
type: boolean
default: false
exits:
'0':
description: Spec is valid. No lint errors found.
stdout:
format: text
'1':
description: Lint failed. Errors or warnings (in strict mode) found.
stderr:
format: text
x-agent:
risk_level: low
requires_confirmation: false
idempotent: true
side_effects: []
# ── init ─────────────────────────────────────────
init:
summary: Initialize a new module structure with starter templates.
description: >-
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.
usage:
- micro-contracts init core
- micro-contracts init core --openapi path/to/spec.yaml
- micro-contracts init myScreens --screens
- micro-contracts init users --skip-templates
arguments:
- name: name
index: 0
required: true
description: Module name (e.g., core, users, billing).
schema:
type: string
options:
- name: dir
aliases: [d]
description: Base directory for server/frontend files.
value_name: path
schema:
type: string
default: src
- name: openapi
aliases: [i]
description: OpenAPI spec to process (auto-adds x-micro-contracts-service/method extensions).
value_name: path
schema:
type: string
file:
mode: read
exists: true
media_type: application/yaml
encoding: utf-8
- name: output
aliases: [o]
description: Output path for processed OpenAPI. Defaults to spec/{name}/openapi/{name}.yaml.
value_name: path
schema:
type: string
- name: skip-templates
description: Skip creating starter Handlebars templates.
schema:
type: boolean
default: false
- name: screens
description: Initialize as screen spec module (generates screen templates and starter spec).
schema:
type: boolean
default: false
exits:
'0':
description: Module initialized successfully.
stdout:
format: text
files:
- path: spec/{name}/openapi/{name}.yaml
required: false
media_type: application/yaml
encoding: utf-8
description: OpenAPI spec (created when --openapi provided or --screens used).
- path: spec/default/templates/*.hbs
required: false
media_type: text/x-handlebars-template
encoding: utf-8
description: Starter Handlebars templates.
- path: micro-contracts.config.yaml
required: false
media_type: application/yaml
encoding: utf-8
description: Config file (created if not already present).
'1':
description: Initialization failed (OpenAPI file not found or write error).
stderr:
format: text
x-agent:
risk_level: medium
requires_confirmation: false
idempotent: true
side_effects:
- file_write
- directory_create
# ── check ────────────────────────────────────────
check:
summary: Run guardrail checks.
description: >-
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.
usage:
- micro-contracts check
- micro-contracts check --gate 1,2
- micro-contracts check --only drift,manifest
- micro-contracts check --fix
- micro-contracts check --list
- micro-contracts check --list-gates
options:
- name: only
description: Run only specific checks (comma-separated check names).
value_name: checks
schema:
type: string
- name: skip
description: Skip specific checks (comma-separated check names).
value_name: checks
schema:
type: string
- name: gate
description: Run checks for specific gates only (comma-separated, 1-5).
value_name: gates
schema:
type: string
- name: verbose
aliases: [v]
description: Enable verbose output.
schema:
type: boolean
default: false
- name: fix
description: Auto-fix issues where possible.
schema:
type: boolean
default: false
- name: guardrails
aliases: [g]
description: Path to guardrails.yaml.
value_name: path
schema:
type: string
file:
mode: read
exists: false
media_type: application/yaml
encoding: utf-8
- name: generated-dir
aliases: [d]
description: Path to generated files directory.
value_name: path
schema:
type: string
default: packages/
- name: changed-files
description: Path to file containing list of changed files (for CI).
value_name: path
schema:
type: string
file:
mode: read
exists: true
media_type: text/plain
encoding: utf-8
- name: list
description: List available checks and exit.
schema:
type: boolean
default: false
- name: list-gates
description: List available gates and exit.
schema:
type: boolean
default: false
exits:
'0':
description: All checks passed (or --list/--list-gates output).
stdout:
format: text
'1':
description: One or more checks failed.
stdout:
format: text
stderr:
required: false
format: text
x-agent:
risk_level: low
requires_confirmation: false
idempotent: true
side_effects: []
recommended_before_use:
- Run generate first so generated files exist.
# ── pipeline ─────────────────────────────────────
pipeline:
summary: Run full guardrails pipeline.
description: >-
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.
usage:
- micro-contracts pipeline
- micro-contracts pipeline --verbose
- micro-contracts pipeline --continue-on-error
- micro-contracts pipeline --contracts-only --skip-lint
options:
- name: config
aliases: [c]
description: Path to config file (micro-contracts.config.yaml).
value_name: path
schema:
type: string
file:
mode: read
exists: false
media_type: application/yaml
encoding: utf-8
- name: verbose
aliases: [v]
description: Enable verbose output (show detailed logs).
schema:
type: boolean
default: false
- name: skip
description: Skip specific checks (comma-separated).
value_name: checks
schema:
type: string
- name: continue-on-error
description: Continue running even if a step fails.
schema:
type: boolean
default: false
- name: guardrails
aliases: [g]
description: Path to guardrails.yaml.
value_name: path
schema:
type: string
file:
mode: read
exists: false
media_type: application/yaml
encoding: utf-8
- name: generated-dir
aliases: [d]
description: Path to generated files directory.
value_name: path
schema:
type: string
default: packages/
- name: manifest
description: >-
Generate manifest after generation. Enabled by default.
Use --no-manifest to disable.
schema:
type: boolean
default: true
- name: skip-lint
description: Skip Spectral linting before generation.
schema:
type: boolean
default: false
- name: contracts-only
description: Generate contract packages only.
schema:
type: boolean
default: false
- name: server-only
description: Generate server routes only.
schema:
type: boolean
default: false
- name: frontend-only
description: Generate frontend clients only.
schema:
type: boolean
default: false
- name: docs-only
description: Generate documentation only.
schema:
type: boolean
default: false
- name: force
description: Bypass input hash cache and always regenerate.
schema:
type: boolean
default: false
- name: cache
description: >-
Enable input hash caching. Enabled by default.
Use --no-cache to disable both reading and writing cache.
schema:
type: boolean
default: true
exits:
'0':
description: Pipeline completed successfully. All gates passed and generation succeeded.
stdout:
format: text
'1':
description: Pipeline failed. One or more steps had errors.
stdout:
format: text
stderr:
required: false
format: text
x-agent:
risk_level: medium
requires_confirmation: false
idempotent: true
side_effects:
- file_write
recommended_before_use:
- Ensure micro-contracts.config.yaml and guardrails.yaml exist.
- Verify OpenAPI specs are valid.
# ── deps ─────────────────────────────────────────
deps:
summary: Analyze module dependencies.
description: >-
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.
usage:
- micro-contracts deps
- micro-contracts deps --graph
- micro-contracts deps --module billing
- micro-contracts deps --impact core.User.getUsers
- micro-contracts deps --who-depends-on core
- micro-contracts deps --validate
options:
- name: config
aliases: [c]
description: Path to config file.
value_name: path
schema:
type: string
file:
mode: read
exists: false
media_type: application/yaml
encoding: utf-8
- name: module
aliases: [m]
description: Module to analyze.
value_name: name
schema:
type: string
- name: graph
description: Output dependency graph in Mermaid format.
schema:
type: boolean
default: false
- name: impact
description: Analyze impact of changing a specific API (e.g., core.User.getUsers).
value_name: ref
schema:
type: string
- name: who-depends-on
description: Find modules that depend on a specific API.
value_name: ref
schema:
type: string
- name: validate
description: Validate dependencies against OpenAPI declarations.
schema:
type: boolean
default: false
exits:
'0':
description: Dependency analysis completed successfully.
stdout:
format: text
'1':
description: Analysis failed or validation errors found.
stderr:
format: text
x-agent:
risk_level: low
requires_confirmation: false
idempotent: true
side_effects: []
# ── insights ─────────────────────────────────────
insights:
summary: Emit ExternalInsight JSON for agent-contracts-analyzer.
description: >-
Reads x-micro-contracts-depend-on from OpenAPI specs and outputs
structured dependency edges and anchor mappings as JSON on stdout.
Used by agent-contracts-analyzer CommandProvider integration.
usage:
- micro-contracts insights --format json
- micro-contracts insights --format json --project-root .
options:
- name: format
description: Output format (json only).
value_name: format
schema:
type: string
default: json
- name: project-root
description: Project root directory containing micro-contracts.config.yaml.
value_name: path
schema:
type: string
default: .
- name: config
aliases: [c]
description: Path to config file (micro-contracts.config.yaml).
value_name: path
schema:
type: string
file:
mode: read
exists: false
media_type: application/yaml
encoding: utf-8
exits:
'0':
description: ExternalInsight JSON written to stdout.
stdout:
format: json
'1':
description: Insights generation failed.
stderr:
format: text
x-agent:
risk_level: low
requires_confirmation: false
idempotent: true
side_effects: []
# ── guardrails-init ──────────────────────────────
guardrails-init:
path: [guardrails-init]
summary: Create a guardrails.yaml configuration file.
description: >-
Generates a starter guardrails.yaml with default check
configuration. Fails if the target file already exists.
usage:
- micro-contracts guardrails-init
- micro-contracts guardrails-init -o custom-guardrails.yaml
options:
- name: output
aliases: [o]
description: Output path for guardrails.yaml.
value_name: path
schema:
type: string
default: guardrails.yaml
exits:
'0':
description: guardrails.yaml created successfully.
stdout:
format: text
files:
- path: '{options.output}'
required: true
media_type: application/yaml
encoding: utf-8
'1':
description: Failed to create (file already exists or write error).
stderr:
format: text
x-agent:
risk_level: low
requires_confirmation: false
idempotent: false
side_effects:
- file_write
# ── manifest ─────────────────────────────────────
manifest:
summary: Generate or verify manifest for generated artifacts.
description: >-
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.
usage:
- micro-contracts manifest
- micro-contracts manifest -d packages/
- micro-contracts manifest --verify
- micro-contracts manifest -o custom-manifest.json
options:
- name: dir
aliases: [d]
description: Directory to scan.
value_name: path
schema:
type: string
default: packages/
- name: verify
description: Verify existing manifest instead of generating.
schema:
type: boolean
default: false
- name: output
aliases: [o]
description: Output manifest path. Defaults to {dir}/.generated-manifest.json.
value_name: path
schema:
type: string
exits:
'0':
description: Manifest generated or verification passed.
stdout:
format: text
files:
- path: '{options.dir}/.generated-manifest.json'
required: false
media_type: application/json
encoding: utf-8
description: Generated manifest (not created in verify mode).
'1':
description: Directory not found, manifest generation failed, or verification failed.
stderr:
format: text
x-agent:
risk_level: low
requires_confirmation: false
idempotent: true
side_effects:
- file_write
# ── audit-openapi ──────────────────────────────
audit-openapi:
path: [audit-openapi]
summary: Run LLM-based OpenAPI design quality audit.
description: >-
Performs a semantic review of OpenAPI specification design quality
using an LLM agent. Evaluates path design, module boundary alignment,
schema bloat, CRUD vs use-case orientation, and cross-cutting
concern coverage. Requires agent-contracts-runtime.
usage:
- micro-contracts audit-openapi
- micro-contracts audit-openapi -m core
- micro-contracts audit-openapi --adapter claude --report-format text
- micro-contracts audit-openapi --show-prompt
options:
- name: config
aliases: [c]
description: Path to config file (micro-contracts.config.yaml).
value_name: path
schema:
type: string
file:
mode: read
exists: false
media_type: application/yaml
encoding: utf-8
- name: module
aliases: [m]
description: Module name to audit (default is all modules).
value_name: name
schema:
type: string
- name: adapter
aliases: [a]
description: SDK adapter to use for LLM execution.
value_name: name
schema:
type: string
enum: [claude, openai, gemini, mock]
- name: model
description: LLM model override.
value_name: name
schema:
type: string
- name: fail-on
description: Minimum severity that causes a non-zero exit.
value_name: level
schema:
type: string
enum: [warning, error, critical]
default: error
- name: output
aliases: [o]
description: Write result to a file instead of stdout.
value_name: file
schema:
type: string
file:
mode: write
media_type: application/json
encoding: utf-8
- name: report-format
description: Output format for the audit report.
value_name: fmt
schema:
type: string
enum: [json, text, yaml]
default: text
- name: log-file
aliases: [l]
description: Write agent progress log to this file path.
schema:
type: string
exits:
'0':
description: Audit completed, no blocking findings.
stdout:
format: '{options.report-format}'
schema:
$ref: '#/components/schemas/OpenApiAuditResult'
'1':
description: Unexpected error.
stderr:
format: text
'3':
description: Input validation failed (config not found, spec invalid).
stderr:
format: text
'10':
description: Completed with blocking findings.
stdout:
format: '{options.report-format}'
schema:
$ref: '#/components/schemas/OpenApiAuditResult'
'11':
description: Runtime dependency missing (agent-contracts-runtime).
stderr:
format: text
'12':
description: LLM provider or adapter error.
stderr:
format: text
effects:
reads: [openapi-specs, config]
writes: []
network:
description: LLM API calls when adapter is not mock
requires_secrets: []
idempotent: true
x-agent:
dsl_task: audit-openapi-design
expectedDurationMs: 120000
retryableExitCodes: [12]
# ── review-published ───────────────────────────
review-published:
path: [review-published]
summary: Review published API surface for internal leakage.
description: >-
Analyzes the published (public-facing) API specification for
internal type leakage, backward compatibility risks, and
x-micro-contracts-non-exportable violations.
Requires agent-contracts-runtime.
usage:
- micro-contracts review-published
- micro-contracts review-published -m billing
- micro-contracts review-published --adapter claude --report-format json
options:
- name: config
aliases: [c]
description: Path to config file (micro-contracts.config.yaml).
value_name: path
schema:
type: string
file:
mode: read
exists: false
media_type: application/yaml
encoding: utf-8
- name: module
aliases: [m]
description: Module name to review (default is all modules).
value_name: name
schema:
type: string
- name: adapter
aliases: [a]
description: SDK adapter to use for LLM execution.
value_name: name
schema:
type: string
enum: [claude, openai, gemini, mock]
- name: model
description: LLM model override.
value_name: name
schema:
type: string
- name: fail-on
description: Minimum severity that causes a non-zero exit.
value_name: level
schema:
type: string
enum: [warning, error, critical]
default: error
- name: output
aliases: [o]
description: Write result to a file instead of stdout.
value_name: file
schema: