@codluv/versionguard 0.4.0 → 0.5.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.
package/dist/cli.js CHANGED
@@ -4,9 +4,1020 @@ import * as path from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import chalk from "chalk";
6
6
  import { Command } from "commander";
7
- import { i as isValidCalVerFormat, g as getConfig, a as installHooks, b as getPackageVersion, c as getVersionFeedback, v as validate, h as handlePostTag, r as runGuardChecks, d as getSyncFeedback, e as getChangelogFeedback, f as doctor, j as fixAll, k as fixSyncIssues, s as suggestNextVersion, l as setPackageVersion, m as createTag, u as uninstallHooks, n as areHooksInstalled } from "./chunks/index-B3R60bYJ.js";
7
+ import { i as isValidCalVerFormat, c as createCkmEngine, g as getConfig, a as installHooks, b as getPackageVersion, d as getVersionFeedback, v as validate, h as handlePostTag, r as runGuardChecks, e as getSyncFeedback, f as getChangelogFeedback, j as doctor, k as fixAll, l as isChangesetMangled, m as fixChangesetMangling, n as fixSyncIssues, s as suggestNextVersion, o as setPackageVersion, p as createTag, u as uninstallHooks, q as areHooksInstalled, t as findProjectRoot, w as formatNotProjectError } from "./chunks/index-CwOyEn5L.js";
8
8
  import * as p from "@clack/prompts";
9
9
  import * as yaml from "js-yaml";
10
+ const ckmRaw = `{
11
+ "$schema": "https://forge-ts.dev/schemas/ckm/v1.json",
12
+ "version": "1.0.0",
13
+ "project": "@codluv/versionguard",
14
+ "generated": "2026-03-26T15:45:30.788Z",
15
+ "concepts": [
16
+ {
17
+ "id": "concept-ManifestConfig",
18
+ "name": "ManifestConfig",
19
+ "what": "Configures the version source manifest.",
20
+ "properties": [
21
+ {
22
+ "name": "source",
23
+ "type": "ManifestSourceType",
24
+ "description": "Manifest file to read the version from. Use \`'auto'\` for file-existence detection or a specific filename."
25
+ },
26
+ {
27
+ "name": "path",
28
+ "type": "string | undefined",
29
+ "description": "Dotted key path to the version field within the manifest. For example \`'version'\` for package.json, \`'package.version'\` for Cargo.toml, or \`'project.version'\` for pyproject.toml."
30
+ },
31
+ {
32
+ "name": "regex",
33
+ "type": "string | undefined",
34
+ "description": "Regex pattern to extract the version from source-code manifests. Capture group 1 must contain the version string."
35
+ }
36
+ ]
37
+ },
38
+ {
39
+ "id": "concept-CalVerConfig",
40
+ "name": "CalVerConfig",
41
+ "what": "Configures CalVer validation rules.",
42
+ "properties": [
43
+ {
44
+ "name": "format",
45
+ "type": "CalVerFormat",
46
+ "description": "Calendar format used when parsing and validating versions."
47
+ },
48
+ {
49
+ "name": "preventFutureDates",
50
+ "type": "boolean",
51
+ "description": "Rejects versions that point to a future date."
52
+ },
53
+ {
54
+ "name": "strictMutualExclusion",
55
+ "type": "boolean | undefined",
56
+ "description": "Enforces that week tokens (WW/0W) cannot be mixed with month/day tokens."
57
+ }
58
+ ]
59
+ },
60
+ {
61
+ "id": "concept-SyncConfig",
62
+ "name": "SyncConfig",
63
+ "what": "Configures files and patterns that should stay in sync with the canonical version.",
64
+ "properties": [
65
+ {
66
+ "name": "files",
67
+ "type": "string[]",
68
+ "description": "File globs or paths that should be scanned for version updates."
69
+ },
70
+ {
71
+ "name": "patterns",
72
+ "type": "SyncPattern[]",
73
+ "description": "Replacement patterns applied to matching files."
74
+ }
75
+ ]
76
+ },
77
+ {
78
+ "id": "concept-ChangelogConfig",
79
+ "name": "ChangelogConfig",
80
+ "what": "Controls changelog validation behavior.",
81
+ "properties": [
82
+ {
83
+ "name": "enabled",
84
+ "type": "boolean",
85
+ "description": "Enables changelog validation."
86
+ },
87
+ {
88
+ "name": "file",
89
+ "type": "string",
90
+ "description": "Path to the changelog file to inspect."
91
+ },
92
+ {
93
+ "name": "strict",
94
+ "type": "boolean",
95
+ "description": "Treats changelog problems as hard failures."
96
+ },
97
+ {
98
+ "name": "requireEntry",
99
+ "type": "boolean",
100
+ "description": "Requires an entry for the current version."
101
+ }
102
+ ]
103
+ },
104
+ {
105
+ "id": "concept-GitHooksConfig",
106
+ "name": "GitHooksConfig",
107
+ "what": "Toggles each supported git hook integration.",
108
+ "properties": [
109
+ {
110
+ "name": "'pre-commit'",
111
+ "type": "boolean",
112
+ "description": "Enables validation during the \`pre-commit\` hook."
113
+ },
114
+ {
115
+ "name": "'pre-push'",
116
+ "type": "boolean",
117
+ "description": "Enables validation during the \`pre-push\` hook."
118
+ },
119
+ {
120
+ "name": "'post-tag'",
121
+ "type": "boolean",
122
+ "description": "Enables follow-up tasks after a tag is created."
123
+ }
124
+ ]
125
+ },
126
+ {
127
+ "id": "concept-GitConfig",
128
+ "name": "GitConfig",
129
+ "what": "Configures git-related enforcement.",
130
+ "properties": [
131
+ {
132
+ "name": "hooks",
133
+ "type": "GitHooksConfig",
134
+ "description": "Hook toggles used by the CLI and validation workflow."
135
+ },
136
+ {
137
+ "name": "enforceHooks",
138
+ "type": "boolean",
139
+ "description": "Fails validation when required hooks are missing."
140
+ }
141
+ ]
142
+ },
143
+ {
144
+ "id": "concept-VersioningConfig",
145
+ "name": "VersioningConfig",
146
+ "what": "Configures the active versioning mode.",
147
+ "properties": [
148
+ {
149
+ "name": "type",
150
+ "type": "VersioningType",
151
+ "description": "Versioning strategy used for the project."
152
+ },
153
+ {
154
+ "name": "schemeRules",
155
+ "type": "SchemeRules | undefined",
156
+ "description": "Scheme-level validation rules applied regardless of versioning type."
157
+ },
158
+ {
159
+ "name": "calver",
160
+ "type": "CalVerConfig | undefined",
161
+ "description": "CalVer-specific settings when \`type\` is \`'calver'\`."
162
+ }
163
+ ]
164
+ },
165
+ {
166
+ "id": "concept-VersionGuardConfig",
167
+ "name": "VersionGuardConfig",
168
+ "what": "Top-level configuration consumed by versionguard.",
169
+ "properties": [
170
+ {
171
+ "name": "versioning",
172
+ "type": "VersioningConfig",
173
+ "description": "Active versioning settings."
174
+ },
175
+ {
176
+ "name": "manifest",
177
+ "type": "ManifestConfig",
178
+ "description": "Version source manifest settings."
179
+ },
180
+ {
181
+ "name": "sync",
182
+ "type": "SyncConfig",
183
+ "description": "Synchronization settings for mirrored version strings."
184
+ },
185
+ {
186
+ "name": "changelog",
187
+ "type": "ChangelogConfig",
188
+ "description": "Changelog validation settings."
189
+ },
190
+ {
191
+ "name": "git",
192
+ "type": "GitConfig",
193
+ "description": "Git enforcement settings."
194
+ },
195
+ {
196
+ "name": "ignore",
197
+ "type": "string[]",
198
+ "description": "Files or patterns excluded from validation."
199
+ }
200
+ ]
201
+ },
202
+ {
203
+ "id": "concept-ValidationResult",
204
+ "name": "ValidationResult",
205
+ "what": "Result returned by version parsing and validation helpers.",
206
+ "properties": [
207
+ {
208
+ "name": "valid",
209
+ "type": "boolean",
210
+ "description": "Indicates whether validation completed without errors."
211
+ },
212
+ {
213
+ "name": "errors",
214
+ "type": "ValidationError[]",
215
+ "description": "Collected validation issues."
216
+ },
217
+ {
218
+ "name": "version",
219
+ "type": "ParsedVersion | undefined",
220
+ "description": "Parsed version details when validation succeeds."
221
+ }
222
+ ]
223
+ },
224
+ {
225
+ "id": "concept-SyncResult",
226
+ "name": "SyncResult",
227
+ "what": "Reports the result of synchronizing a single file.",
228
+ "properties": [
229
+ {
230
+ "name": "file",
231
+ "type": "string",
232
+ "description": "File that was inspected or updated."
233
+ },
234
+ {
235
+ "name": "updated",
236
+ "type": "boolean",
237
+ "description": "Indicates whether the file content changed."
238
+ },
239
+ {
240
+ "name": "changes",
241
+ "type": "SyncChange[]",
242
+ "description": "Detailed replacements applied within the file."
243
+ }
244
+ ]
245
+ },
246
+ {
247
+ "id": "concept-FullValidationResult",
248
+ "name": "FullValidationResult",
249
+ "what": "Combined result from a full project validation run.",
250
+ "properties": [
251
+ {
252
+ "name": "valid",
253
+ "type": "boolean",
254
+ "description": "Indicates whether all checks passed."
255
+ },
256
+ {
257
+ "name": "version",
258
+ "type": "string",
259
+ "description": "Canonical version string used for validation."
260
+ },
261
+ {
262
+ "name": "versionValid",
263
+ "type": "boolean",
264
+ "description": "Indicates whether the root version string is valid."
265
+ },
266
+ {
267
+ "name": "syncValid",
268
+ "type": "boolean",
269
+ "description": "Indicates whether synchronized files are in sync."
270
+ },
271
+ {
272
+ "name": "changelogValid",
273
+ "type": "boolean",
274
+ "description": "Indicates whether changelog checks passed."
275
+ },
276
+ {
277
+ "name": "errors",
278
+ "type": "string[]",
279
+ "description": "Human-readable validation failures collected during the run."
280
+ }
281
+ ]
282
+ },
283
+ {
284
+ "id": "concept-ChangelogValidationResult",
285
+ "name": "ChangelogValidationResult",
286
+ "what": "Describes the outcome of validating a changelog file.",
287
+ "properties": [
288
+ {
289
+ "name": "valid",
290
+ "type": "boolean",
291
+ "description": "Indicates whether the changelog satisfies all requested checks."
292
+ },
293
+ {
294
+ "name": "errors",
295
+ "type": "string[]",
296
+ "description": "Human-readable validation errors."
297
+ },
298
+ {
299
+ "name": "hasEntryForVersion",
300
+ "type": "boolean",
301
+ "description": "Indicates whether the changelog contains an entry for the requested version."
302
+ }
303
+ ]
304
+ },
305
+ {
306
+ "id": "concept-FeedbackResult",
307
+ "name": "FeedbackResult",
308
+ "what": "Aggregates validation errors with suggested next steps.",
309
+ "properties": [
310
+ {
311
+ "name": "valid",
312
+ "type": "boolean",
313
+ "description": "Indicates whether the inspected version state is valid."
314
+ },
315
+ {
316
+ "name": "errors",
317
+ "type": "ValidationError[]",
318
+ "description": "Validation errors collected during the check."
319
+ },
320
+ {
321
+ "name": "suggestions",
322
+ "type": "Suggestion[]",
323
+ "description": "Suggested next steps for resolving the reported issues."
324
+ },
325
+ {
326
+ "name": "canAutoFix",
327
+ "type": "boolean",
328
+ "description": "Indicates whether at least one suggestion can be auto-applied."
329
+ }
330
+ ]
331
+ },
332
+ {
333
+ "id": "concept-FixResult",
334
+ "name": "FixResult",
335
+ "what": "Fix entry point exports for auto-remediation helpers.",
336
+ "properties": [
337
+ {
338
+ "name": "fixed",
339
+ "type": "boolean",
340
+ "description": "Indicates whether the operation changed repository state."
341
+ },
342
+ {
343
+ "name": "message",
344
+ "type": "string",
345
+ "description": "Human-readable description of the fix attempt."
346
+ },
347
+ {
348
+ "name": "file",
349
+ "type": "string | undefined",
350
+ "description": "Absolute path to the file that was updated, when applicable."
351
+ }
352
+ ]
353
+ },
354
+ {
355
+ "id": "concept-ProjectRootResult",
356
+ "name": "ProjectRootResult",
357
+ "what": "Result of project root detection.",
358
+ "properties": [
359
+ {
360
+ "name": "found",
361
+ "type": "boolean",
362
+ "description": "Whether a project root was found."
363
+ },
364
+ {
365
+ "name": "root",
366
+ "type": "string",
367
+ "description": "The resolved project root directory, or the original cwd if not found."
368
+ },
369
+ {
370
+ "name": "marker",
371
+ "type": "string | undefined",
372
+ "description": "Which marker file was found."
373
+ },
374
+ {
375
+ "name": "hasConfig",
376
+ "type": "boolean",
377
+ "description": "Whether the directory has a VersionGuard config."
378
+ },
379
+ {
380
+ "name": "hasGit",
381
+ "type": "boolean",
382
+ "description": "Whether the directory is inside a git repository."
383
+ },
384
+ {
385
+ "name": "hasManifest",
386
+ "type": "boolean",
387
+ "description": "Whether a version manifest file exists."
388
+ }
389
+ ]
390
+ },
391
+ {
392
+ "id": "concept-InitOptions",
393
+ "name": "InitOptions",
394
+ "what": "Options for headless (non-interactive) initialization.",
395
+ "properties": [
396
+ {
397
+ "name": "cwd",
398
+ "type": "string",
399
+ "description": "Working directory path."
400
+ },
401
+ {
402
+ "name": "type",
403
+ "type": "\\"semver\\" | \\"calver\\" | undefined",
404
+ "description": "Versioning type (semver or calver)."
405
+ },
406
+ {
407
+ "name": "format",
408
+ "type": "string | undefined",
409
+ "description": "CalVer format string."
410
+ },
411
+ {
412
+ "name": "manifest",
413
+ "type": "string | undefined",
414
+ "description": "Manifest source type."
415
+ },
416
+ {
417
+ "name": "hooks",
418
+ "type": "boolean | undefined",
419
+ "description": "Whether to install git hooks."
420
+ },
421
+ {
422
+ "name": "changelog",
423
+ "type": "boolean | undefined",
424
+ "description": "Whether to enable changelog validation."
425
+ },
426
+ {
427
+ "name": "yes",
428
+ "type": "boolean | undefined",
429
+ "description": "Accept defaults without prompting."
430
+ },
431
+ {
432
+ "name": "force",
433
+ "type": "boolean | undefined",
434
+ "description": "Overwrite existing config."
435
+ }
436
+ ]
437
+ }
438
+ ],
439
+ "operations": [
440
+ {
441
+ "id": "op-validate",
442
+ "name": "validate",
443
+ "what": "Validates a CalVer string against formatting and date rules.",
444
+ "inputs": [
445
+ {
446
+ "name": "version",
447
+ "type": "unknown",
448
+ "required": true,
449
+ "description": "Version string to validate."
450
+ },
451
+ {
452
+ "name": "calverFormat",
453
+ "type": "unknown",
454
+ "required": true,
455
+ "description": "Format expected for the version string."
456
+ },
457
+ {
458
+ "name": "preventFutureDates",
459
+ "type": "unknown",
460
+ "required": true,
461
+ "description": "Whether future dates should be reported as errors."
462
+ },
463
+ {
464
+ "name": "schemeRules",
465
+ "type": "unknown",
466
+ "required": true,
467
+ "description": "Optional scheme rules for modifier validation and segment count warnings."
468
+ }
469
+ ],
470
+ "outputs": {
471
+ "text": "A validation result containing any discovered errors and the parsed version on success."
472
+ }
473
+ },
474
+ {
475
+ "id": "op-validateChangelog",
476
+ "name": "validateChangelog",
477
+ "what": "Validates a changelog file for release readiness.",
478
+ "inputs": [
479
+ {
480
+ "name": "changelogPath",
481
+ "type": "unknown",
482
+ "required": true,
483
+ "description": "Path to the changelog file."
484
+ },
485
+ {
486
+ "name": "version",
487
+ "type": "unknown",
488
+ "required": true,
489
+ "description": "Version that must be present in the changelog."
490
+ },
491
+ {
492
+ "name": "strict",
493
+ "type": "unknown",
494
+ "required": true,
495
+ "description": "Whether to require compare links and dated release headings."
496
+ },
497
+ {
498
+ "name": "requireEntry",
499
+ "type": "unknown",
500
+ "required": true,
501
+ "description": "Whether the requested version must already have an entry."
502
+ }
503
+ ],
504
+ "outputs": {
505
+ "text": "The result of validating the changelog file."
506
+ }
507
+ },
508
+ {
509
+ "id": "op-checkHardcodedVersions",
510
+ "name": "checkHardcodedVersions",
511
+ "what": "Checks configured files for hardcoded version mismatches.",
512
+ "inputs": [
513
+ {
514
+ "name": "expectedVersion",
515
+ "type": "unknown",
516
+ "required": true,
517
+ "description": "Version all matching entries should use."
518
+ },
519
+ {
520
+ "name": "config",
521
+ "type": "unknown",
522
+ "required": true,
523
+ "description": "Sync configuration describing files and replacement patterns."
524
+ },
525
+ {
526
+ "name": "ignorePatterns",
527
+ "type": "unknown",
528
+ "required": true,
529
+ "description": "Glob patterns to exclude while scanning."
530
+ },
531
+ {
532
+ "name": "cwd",
533
+ "type": "unknown",
534
+ "required": true,
535
+ "description": "Project directory used to resolve file globs."
536
+ }
537
+ ],
538
+ "outputs": {
539
+ "text": "A list of detected version mismatches."
540
+ }
541
+ },
542
+ {
543
+ "id": "op-generateHookScript",
544
+ "name": "generateHookScript",
545
+ "what": "Generates the shell script content for a Git hook.",
546
+ "inputs": [
547
+ {
548
+ "name": "hookName",
549
+ "type": "unknown",
550
+ "required": true,
551
+ "description": "Name of the Git hook to generate."
552
+ }
553
+ ],
554
+ "outputs": {
555
+ "text": "Executable shell script contents for the hook."
556
+ }
557
+ },
558
+ {
559
+ "id": "op-checkHooksPathOverride",
560
+ "name": "checkHooksPathOverride",
561
+ "what": "Checks whether git hooks have been redirected away from the repository.",
562
+ "inputs": [
563
+ {
564
+ "name": "cwd",
565
+ "type": "unknown",
566
+ "required": true,
567
+ "description": "Repository directory to inspect."
568
+ }
569
+ ],
570
+ "outputs": {
571
+ "text": "A guard warning when a hooksPath override is detected."
572
+ }
573
+ },
574
+ {
575
+ "id": "op-checkHuskyBypass",
576
+ "name": "checkHuskyBypass",
577
+ "what": "Checks whether the HUSKY environment variable is disabling hooks.",
578
+ "inputs": [],
579
+ "outputs": {
580
+ "text": "A guard warning when the HUSKY bypass is detected."
581
+ }
582
+ },
583
+ {
584
+ "id": "op-checkHookIntegrity",
585
+ "name": "checkHookIntegrity",
586
+ "what": "Verifies that installed hook scripts match the expected content.",
587
+ "inputs": [
588
+ {
589
+ "name": "config",
590
+ "type": "unknown",
591
+ "required": true,
592
+ "description": "VersionGuard configuration that defines which hooks should exist."
593
+ },
594
+ {
595
+ "name": "cwd",
596
+ "type": "unknown",
597
+ "required": true,
598
+ "description": "Repository directory to inspect."
599
+ }
600
+ ],
601
+ "outputs": {
602
+ "text": "Guard warnings for each hook that has been tampered with."
603
+ }
604
+ },
605
+ {
606
+ "id": "op-checkEnforceHooksPolicy",
607
+ "name": "checkEnforceHooksPolicy",
608
+ "what": "Checks whether hooks are configured as required but not enforced.",
609
+ "inputs": [
610
+ {
611
+ "name": "config",
612
+ "type": "unknown",
613
+ "required": true,
614
+ "description": "VersionGuard configuration to inspect."
615
+ }
616
+ ],
617
+ "outputs": {
618
+ "text": "A guard warning when hooks are enabled but not enforced."
619
+ }
620
+ },
621
+ {
622
+ "id": "op-runGuardChecks",
623
+ "name": "runGuardChecks",
624
+ "what": "Runs all guard checks and returns a consolidated report.",
625
+ "inputs": [
626
+ {
627
+ "name": "config",
628
+ "type": "unknown",
629
+ "required": true,
630
+ "description": "VersionGuard configuration."
631
+ },
632
+ {
633
+ "name": "cwd",
634
+ "type": "unknown",
635
+ "required": true,
636
+ "description": "Repository directory to inspect."
637
+ }
638
+ ],
639
+ "outputs": {
640
+ "text": "A guard report with all findings."
641
+ }
642
+ },
643
+ {
644
+ "id": "op-initConfig",
645
+ "name": "initConfig",
646
+ "what": "Initializes a new VersionGuard config file in a project.",
647
+ "inputs": [
648
+ {
649
+ "name": "cwd",
650
+ "type": "unknown",
651
+ "required": true,
652
+ "description": "Project directory where the config should be created."
653
+ }
654
+ ],
655
+ "outputs": {
656
+ "text": "The path to the created config file."
657
+ }
658
+ },
659
+ {
660
+ "id": "op-createTag",
661
+ "name": "createTag",
662
+ "what": "Creates a release tag and optionally fixes version state first.",
663
+ "inputs": [
664
+ {
665
+ "name": "version",
666
+ "type": "unknown",
667
+ "required": true,
668
+ "description": "Version to embed in the new tag name."
669
+ },
670
+ {
671
+ "name": "message",
672
+ "type": "unknown",
673
+ "required": true,
674
+ "description": "Custom annotated tag message."
675
+ },
676
+ {
677
+ "name": "autoFix",
678
+ "type": "unknown",
679
+ "required": true,
680
+ "description": "Whether to auto-fix version mismatches before tagging."
681
+ },
682
+ {
683
+ "name": "config",
684
+ "type": "unknown",
685
+ "required": true,
686
+ "description": "Loaded VersionGuard configuration used for validation and fixes."
687
+ },
688
+ {
689
+ "name": "cwd",
690
+ "type": "unknown",
691
+ "required": true,
692
+ "description": "Repository directory where git commands should run."
693
+ }
694
+ ],
695
+ "outputs": {
696
+ "text": "The tagging outcome and any actions performed along the way."
697
+ }
698
+ },
699
+ {
700
+ "id": "op-validateTagForPush",
701
+ "name": "validateTagForPush",
702
+ "what": "Validates that a local tag is safe to push to the default remote.",
703
+ "inputs": [
704
+ {
705
+ "name": "tagName",
706
+ "type": "unknown",
707
+ "required": true,
708
+ "description": "Name of the tag to validate."
709
+ },
710
+ {
711
+ "name": "cwd",
712
+ "type": "unknown",
713
+ "required": true,
714
+ "description": "Repository directory where git commands should run."
715
+ }
716
+ ],
717
+ "outputs": {
718
+ "text": "A validation result with an optional suggested fix command."
719
+ }
720
+ },
721
+ {
722
+ "id": "op-validateVersion",
723
+ "name": "validateVersion",
724
+ "what": "Validates a version string against the active versioning strategy.",
725
+ "inputs": [
726
+ {
727
+ "name": "version",
728
+ "type": "unknown",
729
+ "required": true,
730
+ "description": "Version string to validate."
731
+ },
732
+ {
733
+ "name": "config",
734
+ "type": "unknown",
735
+ "required": true,
736
+ "description": "VersionGuard configuration that selects the validation rules."
737
+ }
738
+ ],
739
+ "outputs": {
740
+ "text": "The validation result for the provided version."
741
+ }
742
+ },
743
+ {
744
+ "id": "op-runWizard",
745
+ "name": "runWizard",
746
+ "what": "Runs the interactive setup wizard.",
747
+ "inputs": [
748
+ {
749
+ "name": "cwd",
750
+ "type": "unknown",
751
+ "required": true,
752
+ "description": "Project directory to initialize."
753
+ }
754
+ ],
755
+ "outputs": {
756
+ "text": "The path to the created config file, or \`null\` if cancelled."
757
+ }
758
+ },
759
+ {
760
+ "id": "op-runHeadless",
761
+ "name": "runHeadless",
762
+ "what": "Initializes VersionGuard non-interactively using CLI flags.",
763
+ "inputs": [
764
+ {
765
+ "name": "options",
766
+ "type": "unknown",
767
+ "required": true,
768
+ "description": "Headless initialization options."
769
+ }
770
+ ],
771
+ "outputs": {
772
+ "text": "The path to the created config file."
773
+ }
774
+ },
775
+ {
776
+ "id": "op-createProgram",
777
+ "name": "createProgram",
778
+ "what": "Creates the VersionGuard CLI program definition.",
779
+ "inputs": [],
780
+ "outputs": {
781
+ "text": "A configured Commander program for the VersionGuard CLI."
782
+ }
783
+ },
784
+ {
785
+ "id": "op-runCli",
786
+ "name": "runCli",
787
+ "what": "Parses CLI arguments and executes the matching command.",
788
+ "inputs": [
789
+ {
790
+ "name": "argv",
791
+ "type": "unknown",
792
+ "required": true,
793
+ "description": "Full argument vector to parse."
794
+ }
795
+ ]
796
+ },
797
+ {
798
+ "id": "op-createTempProject",
799
+ "name": "createTempProject",
800
+ "what": "Creates a temporary project directory with a minimal \`package.json\` fixture.",
801
+ "inputs": [],
802
+ "outputs": {
803
+ "text": "The absolute path to the temporary project directory."
804
+ }
805
+ },
806
+ {
807
+ "id": "op-initGitRepo",
808
+ "name": "initGitRepo",
809
+ "what": "Initializes a git repository in a fixture directory with a first commit.",
810
+ "inputs": [
811
+ {
812
+ "name": "cwd",
813
+ "type": "unknown",
814
+ "required": true,
815
+ "description": "Absolute path to the fixture repository."
816
+ }
817
+ ]
818
+ },
819
+ {
820
+ "id": "op-createBareRemote",
821
+ "name": "createBareRemote",
822
+ "what": "Creates a bare git repository to use as a remote in integration tests.",
823
+ "inputs": [],
824
+ "outputs": {
825
+ "text": "The absolute path to the new bare repository."
826
+ }
827
+ }
828
+ ],
829
+ "constraints": [],
830
+ "workflows": [],
831
+ "configSchema": [
832
+ {
833
+ "key": "ManifestConfig.source",
834
+ "type": "ManifestSourceType",
835
+ "description": "Manifest file to read the version from. Use \`'auto'\` for file-existence detection or a specific filename.",
836
+ "default": "'auto'"
837
+ },
838
+ {
839
+ "key": "ManifestConfig.path",
840
+ "type": "string | undefined",
841
+ "description": "Dotted key path to the version field within the manifest. For example \`'version'\` for package.json, \`'package.version'\` for Cargo.toml, or \`'project.version'\` for pyproject.toml.",
842
+ "default": "undefined (uses the provider's built-in default)"
843
+ },
844
+ {
845
+ "key": "ManifestConfig.regex",
846
+ "type": "string | undefined",
847
+ "description": "Regex pattern to extract the version from source-code manifests. Capture group 1 must contain the version string.",
848
+ "default": "undefined"
849
+ },
850
+ {
851
+ "key": "CalVerConfig.format",
852
+ "type": "CalVerFormat",
853
+ "description": "Calendar format used when parsing and validating versions."
854
+ },
855
+ {
856
+ "key": "CalVerConfig.preventFutureDates",
857
+ "type": "boolean",
858
+ "description": "Rejects versions that point to a future date.",
859
+ "default": "true"
860
+ },
861
+ {
862
+ "key": "CalVerConfig.strictMutualExclusion",
863
+ "type": "boolean | undefined",
864
+ "description": "Enforces that week tokens (WW/0W) cannot be mixed with month/day tokens.",
865
+ "default": "true"
866
+ },
867
+ {
868
+ "key": "SyncConfig.files",
869
+ "type": "string[]",
870
+ "description": "File globs or paths that should be scanned for version updates."
871
+ },
872
+ {
873
+ "key": "SyncConfig.patterns",
874
+ "type": "SyncPattern[]",
875
+ "description": "Replacement patterns applied to matching files."
876
+ },
877
+ {
878
+ "key": "ChangelogConfig.enabled",
879
+ "type": "boolean",
880
+ "description": "Enables changelog validation.",
881
+ "default": "false"
882
+ },
883
+ {
884
+ "key": "ChangelogConfig.file",
885
+ "type": "string",
886
+ "description": "Path to the changelog file to inspect."
887
+ },
888
+ {
889
+ "key": "ChangelogConfig.strict",
890
+ "type": "boolean",
891
+ "description": "Treats changelog problems as hard failures.",
892
+ "default": "false"
893
+ },
894
+ {
895
+ "key": "ChangelogConfig.requireEntry",
896
+ "type": "boolean",
897
+ "description": "Requires an entry for the current version.",
898
+ "default": "false"
899
+ },
900
+ {
901
+ "key": "GitHooksConfig.'pre-commit'",
902
+ "type": "boolean",
903
+ "description": "Enables validation during the \`pre-commit\` hook.",
904
+ "default": "false"
905
+ },
906
+ {
907
+ "key": "GitHooksConfig.'pre-push'",
908
+ "type": "boolean",
909
+ "description": "Enables validation during the \`pre-push\` hook.",
910
+ "default": "false"
911
+ },
912
+ {
913
+ "key": "GitHooksConfig.'post-tag'",
914
+ "type": "boolean",
915
+ "description": "Enables follow-up tasks after a tag is created.",
916
+ "default": "false"
917
+ },
918
+ {
919
+ "key": "GitConfig.hooks",
920
+ "type": "GitHooksConfig",
921
+ "description": "Hook toggles used by the CLI and validation workflow."
922
+ },
923
+ {
924
+ "key": "GitConfig.enforceHooks",
925
+ "type": "boolean",
926
+ "description": "Fails validation when required hooks are missing.",
927
+ "default": "false"
928
+ },
929
+ {
930
+ "key": "VersioningConfig.type",
931
+ "type": "VersioningType",
932
+ "description": "Versioning strategy used for the project."
933
+ },
934
+ {
935
+ "key": "VersioningConfig.schemeRules",
936
+ "type": "SchemeRules | undefined",
937
+ "description": "Scheme-level validation rules applied regardless of versioning type.",
938
+ "default": "\`{ maxNumericSegments: 3, allowedModifiers: ['dev', 'alpha', 'beta', 'rc'] }\`"
939
+ },
940
+ {
941
+ "key": "VersioningConfig.calver",
942
+ "type": "CalVerConfig | undefined",
943
+ "description": "CalVer-specific settings when \`type\` is \`'calver'\`.",
944
+ "default": "undefined"
945
+ },
946
+ {
947
+ "key": "VersionGuardConfig.versioning",
948
+ "type": "VersioningConfig",
949
+ "description": "Active versioning settings."
950
+ },
951
+ {
952
+ "key": "VersionGuardConfig.manifest",
953
+ "type": "ManifestConfig",
954
+ "description": "Version source manifest settings.",
955
+ "default": "\`{ source: 'auto' }\`"
956
+ },
957
+ {
958
+ "key": "VersionGuardConfig.sync",
959
+ "type": "SyncConfig",
960
+ "description": "Synchronization settings for mirrored version strings."
961
+ },
962
+ {
963
+ "key": "VersionGuardConfig.changelog",
964
+ "type": "ChangelogConfig",
965
+ "description": "Changelog validation settings."
966
+ },
967
+ {
968
+ "key": "VersionGuardConfig.git",
969
+ "type": "GitConfig",
970
+ "description": "Git enforcement settings."
971
+ },
972
+ {
973
+ "key": "VersionGuardConfig.ignore",
974
+ "type": "string[]",
975
+ "description": "Files or patterns excluded from validation."
976
+ },
977
+ {
978
+ "key": "InitOptions.cwd",
979
+ "type": "string",
980
+ "description": "Working directory path."
981
+ },
982
+ {
983
+ "key": "InitOptions.type",
984
+ "type": "\\"semver\\" | \\"calver\\" | undefined",
985
+ "description": "Versioning type (semver or calver)."
986
+ },
987
+ {
988
+ "key": "InitOptions.format",
989
+ "type": "string | undefined",
990
+ "description": "CalVer format string."
991
+ },
992
+ {
993
+ "key": "InitOptions.manifest",
994
+ "type": "string | undefined",
995
+ "description": "Manifest source type."
996
+ },
997
+ {
998
+ "key": "InitOptions.hooks",
999
+ "type": "boolean | undefined",
1000
+ "description": "Whether to install git hooks."
1001
+ },
1002
+ {
1003
+ "key": "InitOptions.changelog",
1004
+ "type": "boolean | undefined",
1005
+ "description": "Whether to enable changelog validation."
1006
+ },
1007
+ {
1008
+ "key": "InitOptions.yes",
1009
+ "type": "boolean | undefined",
1010
+ "description": "Accept defaults without prompting."
1011
+ },
1012
+ {
1013
+ "key": "InitOptions.force",
1014
+ "type": "boolean | undefined",
1015
+ "description": "Overwrite existing config."
1016
+ }
1017
+ ]
1018
+ }
1019
+ `;
1020
+ const llmsRaw = "# @codluv/versionguard\n> Strict versioning enforcement for SemVer and CalVer with git hooks, changelog validation, and file sync from package.json\n> Version: 0.4.0\n\n## Install\n\n```bash\nnpm install -D @codluv/versionguard\n```\n\n## Documentation\n\n- [API Reference](./api-reference.mdx): Full API documentation (MDX)\n- [Full Context](./llms-full.txt): Complete symbol documentation for deep LLM consumption\n\n## Packages\n\n### main\n90 functions, 42 types\n\n- getCalVerConfig() — Extracts the CalVer config from a VersionGuard config, throwing if missing.\n- isValidCalVerFormat() — Validates that a CalVer format string is composed of valid tokens and follows structural rules.\n- parseFormat() — Breaks a CalVer format string into its component tokens.\n- getRegexForFormat() — Builds a regular expression that matches a supported CalVer format.\n- parse() — Parses a CalVer string using the supplied format.\n- validate() — Validates a CalVer string against formatting and date rules.\n- format() — Formats a parsed CalVer object back into a version string.\n- getCurrentVersion() — Creates the current CalVer string for a format.\n- compare() — Compares two CalVer strings using a shared format.\n- increment() — Increments a CalVer string.\n- getNextVersions() — Returns the most likely next CalVer candidates.\n- validateChangelog() — Validates a changelog file for release readiness.\n- getLatestVersion() — Gets the most recent released version from a changelog.\n- addVersionEntry() — Inserts a new version entry beneath the `[Unreleased]` section.\n- isChangesetMangled() — Detects whether a changelog has been mangled by Changesets.\n- fixChangesetMangling() — Fixes a Changesets-mangled changelog into proper Keep a Changelog format.\n- parse() — Parses a semantic version string.\n- validate() — Validates that a string is a supported semantic version.\n- compare() — Compares two semantic version strings.\n- gt() — Checks whether one semantic version is greater than another.\n- lt() — Checks whether one semantic version is less than another.\n- eq() — Checks whether two semantic versions are equal in precedence.\n- increment() — Increments a semantic version string by release type.\n- format() — Formats a parsed semantic version object.\n- getVersionFeedback() — Generates actionable feedback for a version string.\n- getSyncFeedback() — Generates suggestions for version sync mismatches in a file.\n- getChangelogFeedback() — Generates suggestions for changelog-related validation issues.\n- getTagFeedback() — Generates suggestions for git tag mismatches.\n- getNestedValue() — Traverses a nested object using a dotted key path.\n- setNestedValue() — Sets a value at a dotted key path, throwing if intermediate segments are missing.\n- escapeRegExp() — Escapes special regex characters in a string for safe use in `new RegExp()`.\n- resolveVersionSource() — Resolves the version source provider for a project.\n- detectManifests() — Detects all manifest files present in a project directory.\n- getPackageJsonPath() — Gets the `package.json` path for a project directory.\n- readPackageJson() — Reads and parses a project's `package.json` file.\n- writePackageJson() — Writes a `package.json` document back to disk.\n- getPackageVersion() — Gets the version string from the project manifest. When a `manifest` config is provided, uses the configured version source provider (auto-detection or explicit). Falls back to `package.json` for backwards compatibility when no config is provided.\n- setPackageVersion() — Sets the version field in the project manifest. When a `manifest` config is provided, uses the configured version source provider. Falls back to `package.json` for backwards compatibility when no config is provided.\n- getVersionSource() — Resolves the version source provider for a project.\n- syncVersion() — Synchronizes configured files to a single version string.\n- syncFile() — Synchronizes a single file to a target version.\n- checkHardcodedVersions() — Checks configured files for hardcoded version mismatches.\n- fixPackageVersion() — Updates the `package.json` version field when needed.\n- fixSyncIssues() — Synchronizes configured files to the package version.\n- fixChangelog() — Ensures the changelog contains an entry for a version.\n- fixAll() — Runs all configured auto-fix operations.\n- suggestNextVersion() — Suggests candidate next versions for a release.\n- installHooks() — Installs VersionGuard-managed Git hooks in a repository.\n- uninstallHooks() — Removes VersionGuard-managed Git hooks from a repository.\n- findGitDir() — Finds the nearest `.git` directory by walking up from a starting directory.\n- areHooksInstalled() — Checks whether all VersionGuard-managed hooks are installed.\n- generateHookScript() — Generates the shell script content for a Git hook.\n- checkHooksPathOverride() — Checks whether git hooks have been redirected away from the repository.\n- checkHuskyBypass() — Checks whether the HUSKY environment variable is disabling hooks.\n- checkHookIntegrity() — Verifies that installed hook scripts match the expected content.\n- checkEnforceHooksPolicy() — Checks whether hooks are configured as required but not enforced.\n- runGuardChecks() — Runs all guard checks and returns a consolidated report.\n- getTopicIndex() — Returns the topic index listing.\n- getTopicContent() — Returns help content for a specific topic.\n- getLlmContext() — Returns the full API context for LLM consumption.\n- getHelpJson() — Returns the topic index as a JSON structure for machine parsing.\n- getDefaultConfig() — Returns a deep-cloned copy of the built-in VersionGuard configuration.\n- findConfig() — Finds the first supported VersionGuard config file in a directory.\n- loadConfig() — Loads a VersionGuard config file from disk.\n- getConfig() — Resolves the active VersionGuard configuration for a project.\n- initConfig() — Initializes a new VersionGuard config file in a project.\n- findProjectRoot() — Walks up from `startDir` to find the nearest project root.\n- formatNotProjectError() — Formats a helpful error message when a command can't find a project.\n- getLatestTag() — Returns the most recent reachable git tag for a repository.\n- getAllTags() — Lists all tags in a repository.\n- createTag() — Creates a release tag and optionally fixes version state first.\n- handlePostTag() — Runs post-tag validation and sync checks.\n- validateTagForPush() — Validates that a local tag is safe to push to the default remote.\n- suggestTagMessage() — Suggests an annotated tag message from changelog content.\n- validateVersion() — Validates a version string against the active versioning strategy.\n- validate() — Validates the current project state against the supplied configuration.\n- doctor() — Runs an extended readiness check for a project.\n- sync() — Synchronizes configured files to the current package version.\n- canBump() — Determines whether a project can move from one version to another.\n- runWizard() — Runs the interactive setup wizard.\n- runHeadless() — Initializes VersionGuard non-interactively using CLI flags.\n- createProgram() — Creates the VersionGuard CLI program definition.\n- runCli() — Parses CLI arguments and executes the matching command.\n- shouldRunCli() — Determines whether the current module is the invoked CLI entry point.\n- createTempProject() — Creates a temporary project directory with a minimal `package.json` fixture.\n- initGitRepo() — Initializes a git repository in a fixture directory with a first commit.\n- writeTextFile() — Writes a text fixture file relative to a temporary project directory.\n- createBareRemote() — Creates a bare git repository to use as a remote in integration tests.\n- addGitRemote() — Adds a local bare repository as the `origin` remote for a fixture repo.\n- commitAll() — Stages all changes and creates a commit in a fixture repository.\n\n- VersioningType — Supported versioning strategies.\n- ManifestSourceType — Supported manifest source types for version extraction.\n- ManifestConfig — Configures the version source manifest.\n- CalVerToken — Valid CalVer token names for building format strings.\n- CalVerFormat — A CalVer format string composed of dot-separated tokens.\n- SchemeRules — Configures scheme-level validation rules applied regardless of versioning type.\n- CalVerConfig — Configures CalVer validation rules.\n- SyncPattern — Describes a search-and-replace pattern used during version synchronization.\n- SyncConfig — Configures files and patterns that should stay in sync with the canonical version.\n- ChangelogConfig — Controls changelog validation behavior.\n- GitHooksConfig — Toggles each supported git hook integration.\n- GitConfig — Configures git-related enforcement.\n- VersioningConfig — Configures the active versioning mode.\n- VersionGuardConfig — Top-level configuration consumed by versionguard.\n- SemVer — Parsed semantic version components.\n- CalVer — Parsed calendar version components.\n- ParsedSemVer — Parsed semantic version result wrapper.\n- ParsedCalVer — Parsed calendar version result wrapper.\n- ParsedVersion — Union of supported parsed version payloads.\n- ValidationError — Describes a single validation problem.\n- ValidationResult — Result returned by version parsing and validation helpers.\n- SyncChange — Describes a single in-file version replacement.\n- SyncResult — Reports the result of synchronizing a single file.\n- VersionMismatch — Reports a discovered version mismatch.\n- FullValidationResult — Combined result from a full project validation run.\n- DoctorReport — Reports whether a project is ready to pass VersionGuard checks.\n- ParsedCalVerFormat — Parsed token layout for a supported CalVer format string.\n- ChangelogValidationResult — Describes the outcome of validating a changelog file.\n- Suggestion — Feedback entry point exports for suggestion and guidance helpers.\n- FeedbackResult — Aggregates validation errors with suggested next steps.\n- VersionSourceProvider — Abstraction for reading and writing a version string from any manifest format.\n- PackageJsonValue — JSON-compatible scalar, array, or object value used by package metadata.\n- PackageJsonArray — Recursive array type used for arbitrary JSON-compatible package values.\n- PackageJsonObject — Recursive object type used for arbitrary JSON-compatible package values.\n- PackageJson — Minimal shape of a `package.json` document used by VersionGuard.\n- FixResult — Fix entry point exports for auto-remediation helpers.\n- GuardWarning — Describes a single guard finding.\n- GuardReport — Result of a full guard check pass.\n- HelpTopic — Embedded help topics for the CLI help system.\n- ProjectRootResult — Result of project root detection.\n- TagInfo — Tag entry point exports for release-tag management helpers.\n- InitOptions — Options for headless (non-interactive) initialization.\n";
10
1021
  async function runWizard(cwd) {
11
1022
  p.intro("VersionGuard Setup");
12
1023
  const existingConfig = findExistingConfig(cwd);
@@ -73,8 +1084,10 @@ async function runWizard(cwd) {
73
1084
  }
74
1085
  function runHeadless(options) {
75
1086
  const existingConfig = findExistingConfig(options.cwd);
76
- if (existingConfig && !options.yes) {
77
- throw new Error(`Config already exists: ${existingConfig}. Use --yes to overwrite.`);
1087
+ if (existingConfig && !options.force && !options.yes) {
1088
+ throw new Error(
1089
+ `Config already exists: ${existingConfig}. Use --force to overwrite or --yes to accept defaults.`
1090
+ );
78
1091
  }
79
1092
  const config = buildConfig({
80
1093
  type: options.type ?? "semver",
@@ -219,6 +1232,7 @@ function findExistingConfig(cwd) {
219
1232
  }
220
1233
  const CLI_DIR = path.dirname(fileURLToPath(import.meta.url));
221
1234
  const CLI_VERSION = JSON.parse(fs.readFileSync(path.join(CLI_DIR, "..", "package.json"), "utf-8")).version;
1235
+ const ckmEngine = createCkmEngine(JSON.parse(ckmRaw));
222
1236
  const styles = {
223
1237
  error: chalk.red,
224
1238
  warning: chalk.yellow,
@@ -227,10 +1241,18 @@ const styles = {
227
1241
  dim: chalk.gray,
228
1242
  bold: chalk.bold
229
1243
  };
1244
+ function requireProject(cwd, command) {
1245
+ const result = findProjectRoot(cwd);
1246
+ if (!result.found) {
1247
+ console.error(styles.error(formatNotProjectError(cwd, command)));
1248
+ process.exit(1);
1249
+ }
1250
+ return result.root;
1251
+ }
230
1252
  function createProgram() {
231
1253
  const program = new Command();
232
1254
  program.name("versionguard").description("Strict versioning enforcement for SemVer and CalVer").version(CLI_VERSION);
233
- program.command("init").description("Initialize VersionGuard configuration (interactive wizard or headless)").option("-c, --cwd <path>", "Working directory", process.cwd()).option("-t, --type <type>", "Versioning type: semver or calver").option("-f, --format <format>", "CalVer format tokens (e.g., YYYY.M.MICRO)").option("--manifest <source>", "Manifest source (e.g., Cargo.toml, pyproject.toml, auto)").option("--hooks", "Install git hooks (default: true)").option("--no-hooks", "Skip git hooks").option("--changelog", "Enable changelog validation (default: true)").option("--no-changelog", "Disable changelog validation").option("-y, --yes", "Accept all defaults, no prompts").action(
1255
+ program.command("init").description("Initialize VersionGuard configuration (interactive wizard or headless)").option("-c, --cwd <path>", "Working directory", process.cwd()).option("-t, --type <type>", "Versioning type: semver or calver").option("-f, --format <format>", "CalVer format tokens (e.g., YYYY.M.MICRO)").option("--manifest <source>", "Manifest source (e.g., Cargo.toml, pyproject.toml, auto)").option("--hooks", "Install git hooks (default: true)").option("--no-hooks", "Skip git hooks").option("--changelog", "Enable changelog validation (default: true)").option("--no-changelog", "Disable changelog validation").option("-y, --yes", "Accept all defaults, no prompts").option("--force", "Overwrite existing config file").action(
234
1256
  async (options) => {
235
1257
  try {
236
1258
  const isHeadless = options.yes || options.type || options.format || options.manifest;
@@ -243,7 +1265,8 @@ function createProgram() {
243
1265
  manifest: options.manifest,
244
1266
  hooks: options.hooks,
245
1267
  changelog: options.changelog,
246
- yes: options.yes
1268
+ yes: options.yes,
1269
+ force: options.force
247
1270
  });
248
1271
  console.log(styles.success(`✓ Created ${path.relative(options.cwd, configPath)}`));
249
1272
  } else {
@@ -270,6 +1293,7 @@ function createProgram() {
270
1293
  );
271
1294
  program.command("check").description("Check the current version with actionable feedback").option("-c, --cwd <path>", "Working directory", process.cwd()).option("--prev <version>", "Previous version for comparison").option("--json", "Print machine-readable JSON output").action((options) => {
272
1295
  try {
1296
+ options.cwd = requireProject(options.cwd, "check");
273
1297
  const config = getConfig(options.cwd);
274
1298
  const version = getPackageVersion(options.cwd, config.manifest);
275
1299
  const result = getVersionFeedback(version, config, options.prev);
@@ -322,6 +1346,7 @@ function createProgram() {
322
1346
  });
323
1347
  program.command("validate").description("Run full validation with smart feedback").option("-c, --cwd <path>", "Working directory", process.cwd()).option("--hook <name>", "Running as git hook").option("--json", "Print machine-readable JSON output").option("--strict", "Run guard checks and fail on any policy gap or bypass").action((options) => {
324
1348
  try {
1349
+ options.cwd = requireProject(options.cwd, "validate");
325
1350
  const config = getConfig(options.cwd);
326
1351
  const version = getPackageVersion(options.cwd, config.manifest);
327
1352
  const result = validate(config, options.cwd);
@@ -413,6 +1438,7 @@ function createProgram() {
413
1438
  });
414
1439
  program.command("doctor").description("Report repository readiness in one pass").option("-c, --cwd <path>", "Working directory", process.cwd()).option("--json", "Print machine-readable JSON output").option("--strict", "Include guard checks for bypass detection").action((options) => {
415
1440
  try {
1441
+ options.cwd = requireProject(options.cwd, "doctor");
416
1442
  const config = getConfig(options.cwd);
417
1443
  const report = doctor(config, options.cwd);
418
1444
  const guardReport = options.strict ? runGuardChecks(config, options.cwd) : void 0;
@@ -464,6 +1490,7 @@ function createProgram() {
464
1490
  });
465
1491
  program.command("fix").description("Auto-fix detected issues").option("-c, --cwd <path>", "Working directory", process.cwd()).action((options) => {
466
1492
  try {
1493
+ options.cwd = requireProject(options.cwd, "fix");
467
1494
  const config = getConfig(options.cwd);
468
1495
  const version = getPackageVersion(options.cwd, config.manifest);
469
1496
  const results = fixAll(config, version, options.cwd);
@@ -478,8 +1505,31 @@ function createProgram() {
478
1505
  process.exit(1);
479
1506
  }
480
1507
  });
1508
+ program.command("fix-changelog").description("Fix Changesets-mangled changelog into Keep a Changelog format").option("-c, --cwd <path>", "Working directory", process.cwd()).action((options) => {
1509
+ try {
1510
+ options.cwd = requireProject(options.cwd, "fix-changelog");
1511
+ const config = getConfig(options.cwd);
1512
+ const changelogPath = path.join(options.cwd, config.changelog.file);
1513
+ if (!isChangesetMangled(changelogPath)) {
1514
+ console.log(styles.dim("• Changelog is not mangled — no fix needed"));
1515
+ return;
1516
+ }
1517
+ const fixed = fixChangesetMangling(changelogPath);
1518
+ if (fixed) {
1519
+ console.log(
1520
+ styles.success(`✓ Restructured ${config.changelog.file} to Keep a Changelog format`)
1521
+ );
1522
+ } else {
1523
+ console.log(styles.dim("• Could not auto-fix changelog structure"));
1524
+ }
1525
+ } catch (error) {
1526
+ console.error(styles.error(`✗ ${error.message}`));
1527
+ process.exit(1);
1528
+ }
1529
+ });
481
1530
  program.command("sync").description("Sync version to all configured files").option("-c, --cwd <path>", "Working directory", process.cwd()).action((options) => {
482
1531
  try {
1532
+ options.cwd = requireProject(options.cwd, "sync");
483
1533
  const config = getConfig(options.cwd);
484
1534
  const version = getPackageVersion(options.cwd, config.manifest);
485
1535
  const results = fixSyncIssues(config, options.cwd);
@@ -496,6 +1546,7 @@ function createProgram() {
496
1546
  program.command("bump").description("Suggest and optionally apply the next version").option("-c, --cwd <path>", "Working directory", process.cwd()).option("-t, --type <type>", "Bump type (major, minor, patch, auto)").option("--apply", "Apply the first suggested version").action(
497
1547
  (options) => {
498
1548
  try {
1549
+ options.cwd = requireProject(options.cwd, "bump");
499
1550
  const config = getConfig(options.cwd);
500
1551
  const currentVersion = getPackageVersion(options.cwd, config.manifest);
501
1552
  const suggestions = suggestNextVersion(currentVersion, config, options.type);
@@ -523,6 +1574,7 @@ function createProgram() {
523
1574
  program.command("tag").description("Create a git tag with automation").argument("[version]", "Version to tag (defaults to manifest version)").option("-c, --cwd <path>", "Working directory", process.cwd()).option("-m, --message <msg>", "Tag message").option("--no-fix", "Skip auto-fixing files before tagging").action(
524
1575
  (version, options) => {
525
1576
  try {
1577
+ options.cwd = requireProject(options.cwd, "tag");
526
1578
  const config = getConfig(options.cwd);
527
1579
  const tagVersion = version || getPackageVersion(options.cwd, config.manifest);
528
1580
  const result = createTag(
@@ -546,9 +1598,32 @@ function createProgram() {
546
1598
  }
547
1599
  }
548
1600
  );
1601
+ program.command("ckm [topic]").description("Codebase Knowledge Manifest — auto-generated docs and help").option("--json", "Machine-readable CKM output for LLM agents").option("--llm", "Full API context (forge-ts llms.txt)").action((topic, options) => {
1602
+ if (options.llm) {
1603
+ console.log(llmsRaw);
1604
+ return;
1605
+ }
1606
+ if (options.json) {
1607
+ console.log(JSON.stringify(ckmEngine.getTopicJson(topic), null, 2));
1608
+ return;
1609
+ }
1610
+ if (topic) {
1611
+ const content = ckmEngine.getTopicContent(topic);
1612
+ if (!content) {
1613
+ console.error(styles.error(`Unknown topic: ${topic}`));
1614
+ console.log("");
1615
+ console.log(ckmEngine.getTopicIndex("versionguard"));
1616
+ process.exit(1);
1617
+ }
1618
+ console.log(content);
1619
+ } else {
1620
+ console.log(ckmEngine.getTopicIndex("versionguard"));
1621
+ }
1622
+ });
549
1623
  const hooksCommand = program.command("hooks").description("Manage git hooks");
550
1624
  hooksCommand.command("install").description("Install git hooks").option("-c, --cwd <path>", "Working directory", process.cwd()).action((options) => {
551
1625
  try {
1626
+ options.cwd = requireProject(options.cwd, "hooks install");
552
1627
  const config = getConfig(options.cwd);
553
1628
  installHooks(config.git, options.cwd);
554
1629
  console.log(styles.success("✓ Git hooks installed"));
@@ -559,6 +1634,7 @@ function createProgram() {
559
1634
  });
560
1635
  hooksCommand.command("uninstall").description("Uninstall git hooks").option("-c, --cwd <path>", "Working directory", process.cwd()).action((options) => {
561
1636
  try {
1637
+ options.cwd = requireProject(options.cwd, "hooks uninstall");
562
1638
  uninstallHooks(options.cwd);
563
1639
  console.log(styles.success("✓ Git hooks uninstalled"));
564
1640
  } catch (error) {
@@ -568,6 +1644,7 @@ function createProgram() {
568
1644
  });
569
1645
  hooksCommand.command("status").description("Check if hooks are installed").option("-c, --cwd <path>", "Working directory", process.cwd()).action((options) => {
570
1646
  try {
1647
+ options.cwd = requireProject(options.cwd, "hooks status");
571
1648
  if (areHooksInstalled(options.cwd)) {
572
1649
  console.log(styles.success("✓ VersionGuard hooks are installed"));
573
1650
  return;
@@ -585,8 +1662,14 @@ async function runCli(argv = process.argv) {
585
1662
  await createProgram().parseAsync(argv);
586
1663
  }
587
1664
  function shouldRunCli(argv = process.argv, metaUrl = import.meta.url) {
588
- const entryPath = argv[1] ? path.resolve(argv[1]) : null;
589
- return entryPath === fileURLToPath(metaUrl);
1665
+ if (!argv[1]) return false;
1666
+ const metaPath = fileURLToPath(metaUrl);
1667
+ const resolved = path.resolve(argv[1]);
1668
+ try {
1669
+ return fs.realpathSync(resolved) === metaPath;
1670
+ } catch {
1671
+ return resolved === metaPath;
1672
+ }
590
1673
  }
591
1674
  if (shouldRunCli()) {
592
1675
  void runCli();