@codluv/versionguard 0.3.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.
Files changed (54) hide show
  1. package/dist/calver.d.ts +66 -22
  2. package/dist/calver.d.ts.map +1 -1
  3. package/dist/changelog.d.ts +52 -0
  4. package/dist/changelog.d.ts.map +1 -1
  5. package/dist/chunks/{index-BrZJDWya.js → index-CwOyEn5L.js} +904 -176
  6. package/dist/chunks/index-CwOyEn5L.js.map +1 -0
  7. package/dist/ckm/engine.d.ts +92 -0
  8. package/dist/ckm/engine.d.ts.map +1 -0
  9. package/dist/ckm/index.d.ts +32 -0
  10. package/dist/ckm/index.d.ts.map +1 -0
  11. package/dist/ckm/types.d.ts +168 -0
  12. package/dist/ckm/types.d.ts.map +1 -0
  13. package/dist/cli.d.ts.map +1 -1
  14. package/dist/cli.js +1333 -27
  15. package/dist/cli.js.map +1 -1
  16. package/dist/config.d.ts.map +1 -1
  17. package/dist/feedback/index.d.ts +1 -1
  18. package/dist/feedback/index.d.ts.map +1 -1
  19. package/dist/fix/index.d.ts +6 -1
  20. package/dist/fix/index.d.ts.map +1 -1
  21. package/dist/guard.d.ts +45 -1
  22. package/dist/guard.d.ts.map +1 -1
  23. package/dist/hooks.d.ts +14 -7
  24. package/dist/hooks.d.ts.map +1 -1
  25. package/dist/index.d.ts +4 -2
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +38 -32
  28. package/dist/init-wizard.d.ts +68 -0
  29. package/dist/init-wizard.d.ts.map +1 -0
  30. package/dist/project-root.d.ts +74 -0
  31. package/dist/project-root.d.ts.map +1 -0
  32. package/dist/project.d.ts +23 -2
  33. package/dist/project.d.ts.map +1 -1
  34. package/dist/sources/git-tag.d.ts +29 -0
  35. package/dist/sources/git-tag.d.ts.map +1 -1
  36. package/dist/sources/json.d.ts +31 -0
  37. package/dist/sources/json.d.ts.map +1 -1
  38. package/dist/sources/regex.d.ts +30 -0
  39. package/dist/sources/regex.d.ts.map +1 -1
  40. package/dist/sources/resolve.d.ts +27 -8
  41. package/dist/sources/resolve.d.ts.map +1 -1
  42. package/dist/sources/toml.d.ts +36 -1
  43. package/dist/sources/toml.d.ts.map +1 -1
  44. package/dist/sources/utils.d.ts +73 -0
  45. package/dist/sources/utils.d.ts.map +1 -0
  46. package/dist/sources/version-file.d.ts +28 -1
  47. package/dist/sources/version-file.d.ts.map +1 -1
  48. package/dist/sources/yaml.d.ts +29 -0
  49. package/dist/sources/yaml.d.ts.map +1 -1
  50. package/dist/tag/index.d.ts.map +1 -1
  51. package/dist/types.d.ts +89 -4
  52. package/dist/types.d.ts.map +1 -1
  53. package/package.json +3 -2
  54. package/dist/chunks/index-BrZJDWya.js.map +0 -1
package/dist/cli.js CHANGED
@@ -4,9 +4,1235 @@ 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 initConfig, 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-BrZJDWya.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
+ import * as p from "@clack/prompts";
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";
1021
+ async function runWizard(cwd) {
1022
+ p.intro("VersionGuard Setup");
1023
+ const existingConfig = findExistingConfig(cwd);
1024
+ if (existingConfig) {
1025
+ p.log.warning(`Config already exists: ${path.relative(cwd, existingConfig)}`);
1026
+ const overwrite = await p.confirm({ message: "Overwrite existing config?" });
1027
+ if (p.isCancel(overwrite) || !overwrite) {
1028
+ p.outro("Setup cancelled.");
1029
+ return null;
1030
+ }
1031
+ }
1032
+ const type = await p.select({
1033
+ message: "Versioning strategy",
1034
+ options: [
1035
+ { value: "semver", label: "SemVer", hint: "MAJOR.MINOR.PATCH (e.g., 1.2.3)" },
1036
+ { value: "calver", label: "CalVer", hint: "Calendar-based (e.g., 2026.3.0)" }
1037
+ ]
1038
+ });
1039
+ if (p.isCancel(type)) {
1040
+ p.outro("Setup cancelled.");
1041
+ return null;
1042
+ }
1043
+ let format;
1044
+ if (type === "calver") {
1045
+ const selected = await selectCalVerFormat();
1046
+ if (!selected) {
1047
+ p.outro("Setup cancelled.");
1048
+ return null;
1049
+ }
1050
+ format = selected;
1051
+ }
1052
+ const manifest = await selectManifest(cwd);
1053
+ if (manifest === null) {
1054
+ p.outro("Setup cancelled.");
1055
+ return null;
1056
+ }
1057
+ const hooks = await p.confirm({
1058
+ message: "Install git hooks? (pre-commit, pre-push, post-tag)",
1059
+ initialValue: true
1060
+ });
1061
+ if (p.isCancel(hooks)) {
1062
+ p.outro("Setup cancelled.");
1063
+ return null;
1064
+ }
1065
+ const changelog = await p.confirm({
1066
+ message: "Enable changelog validation?",
1067
+ initialValue: true
1068
+ });
1069
+ if (p.isCancel(changelog)) {
1070
+ p.outro("Setup cancelled.");
1071
+ return null;
1072
+ }
1073
+ const config = buildConfig({
1074
+ type,
1075
+ format,
1076
+ manifest: manifest === "auto" ? void 0 : manifest,
1077
+ hooks,
1078
+ changelog
1079
+ });
1080
+ const configPath = writeConfig(cwd, config);
1081
+ p.log.success(`Created ${path.relative(cwd, configPath)}`);
1082
+ p.outro("Run `versionguard validate` to verify your setup.");
1083
+ return configPath;
1084
+ }
1085
+ function runHeadless(options) {
1086
+ const existingConfig = findExistingConfig(options.cwd);
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
+ );
1091
+ }
1092
+ const config = buildConfig({
1093
+ type: options.type ?? "semver",
1094
+ format: options.format,
1095
+ manifest: options.manifest,
1096
+ hooks: options.hooks ?? true,
1097
+ changelog: options.changelog ?? true
1098
+ });
1099
+ return writeConfig(options.cwd, config);
1100
+ }
1101
+ async function selectCalVerFormat() {
1102
+ const preset = await p.select({
1103
+ message: "CalVer format",
1104
+ options: [
1105
+ { value: "YYYY.M.MICRO", label: "YYYY.M.MICRO", hint: "calver.org standard — 2026.3.0" },
1106
+ { value: "YYYY.MM.MICRO", label: "YYYY.MM.MICRO", hint: "padded month — 2026.03.0" },
1107
+ { value: "YY.0M.MICRO", label: "YY.0M.MICRO", hint: "Twisted/pip style — 26.03.0" },
1108
+ { value: "YYYY.0M.0D", label: "YYYY.0M.0D", hint: "date-based — 2026.03.25" },
1109
+ {
1110
+ value: "YYYY.0M.0D.MICRO",
1111
+ label: "YYYY.0M.0D.MICRO",
1112
+ hint: "youtube-dl style — 2026.03.25.0"
1113
+ },
1114
+ { value: "YY.0M", label: "YY.0M", hint: "Ubuntu style — 26.03" },
1115
+ { value: "custom", label: "Custom...", hint: "enter your own token format" }
1116
+ ]
1117
+ });
1118
+ if (p.isCancel(preset)) return null;
1119
+ if (preset === "custom") {
1120
+ const custom = await p.text({
1121
+ message: "Enter CalVer format (dot-separated tokens)",
1122
+ placeholder: "YYYY.MM.MICRO",
1123
+ validate(value) {
1124
+ if (!value || !isValidCalVerFormat(value)) {
1125
+ return "Invalid format. Use tokens: YYYY|YY|0Y, MM|M|0M, WW|0W, DD|D|0D, MICRO|PATCH";
1126
+ }
1127
+ }
1128
+ });
1129
+ if (p.isCancel(custom)) return null;
1130
+ return custom;
1131
+ }
1132
+ return preset;
1133
+ }
1134
+ async function selectManifest(cwd) {
1135
+ const detected = [];
1136
+ const checks = [
1137
+ { file: "package.json", label: "package.json", hint: "Node.js / Bun" },
1138
+ { file: "Cargo.toml", label: "Cargo.toml", hint: "Rust" },
1139
+ { file: "pyproject.toml", label: "pyproject.toml", hint: "Python" },
1140
+ { file: "pubspec.yaml", label: "pubspec.yaml", hint: "Dart / Flutter" },
1141
+ { file: "composer.json", label: "composer.json", hint: "PHP" },
1142
+ { file: "pom.xml", label: "pom.xml", hint: "Java / Maven" },
1143
+ { file: "VERSION", label: "VERSION", hint: "Plain text file" }
1144
+ ];
1145
+ for (const check of checks) {
1146
+ if (fs.existsSync(path.join(cwd, check.file))) {
1147
+ detected.push({ value: check.file, label: `${check.label} (detected)`, hint: check.hint });
1148
+ }
1149
+ }
1150
+ const options = [
1151
+ { value: "auto", label: "Auto-detect", hint: "scan for known manifests at runtime" },
1152
+ ...detected,
1153
+ ...checks.filter((c) => !detected.some((d) => d.value === c.file)).map((c) => ({ value: c.file, label: c.label, hint: c.hint })),
1154
+ { value: "git-tag", label: "Git tags", hint: "Go / Swift — version from tags" }
1155
+ ];
1156
+ const result = await p.select({
1157
+ message: "Version source",
1158
+ options,
1159
+ initialValue: detected.length === 1 ? detected[0].value : "auto"
1160
+ });
1161
+ if (p.isCancel(result)) return null;
1162
+ return result;
1163
+ }
1164
+ function buildConfig(input) {
1165
+ const config = {
1166
+ versioning: {
1167
+ type: input.type,
1168
+ ...input.type === "calver" && input.format ? {
1169
+ calver: {
1170
+ format: input.format,
1171
+ preventFutureDates: true
1172
+ }
1173
+ } : {}
1174
+ }
1175
+ };
1176
+ if (input.manifest) {
1177
+ config.manifest = { source: input.manifest };
1178
+ }
1179
+ config.sync = {
1180
+ files: ["README.md", "CHANGELOG.md"],
1181
+ patterns: [
1182
+ {
1183
+ regex: `(version\\s*[=:]\\s*["'])(.+?)(["'])`,
1184
+ template: "$1{{version}}$3"
1185
+ },
1186
+ {
1187
+ regex: "(##\\s*\\[)(.+?)(\\])",
1188
+ template: "$1{{version}}$3"
1189
+ }
1190
+ ]
1191
+ };
1192
+ config.changelog = {
1193
+ enabled: input.changelog,
1194
+ file: "CHANGELOG.md",
1195
+ strict: true,
1196
+ requireEntry: input.changelog
1197
+ };
1198
+ config.git = {
1199
+ hooks: {
1200
+ "pre-commit": input.hooks,
1201
+ "pre-push": input.hooks,
1202
+ "post-tag": input.hooks
1203
+ },
1204
+ enforceHooks: input.hooks
1205
+ };
1206
+ config.ignore = ["node_modules/**", "dist/**", ".git/**", "*.lock", ".changeset/**"];
1207
+ return config;
1208
+ }
1209
+ function writeConfig(cwd, config) {
1210
+ const configPath = path.join(cwd, ".versionguard.yml");
1211
+ const content = yaml.dump(config, {
1212
+ indent: 2,
1213
+ lineWidth: 120,
1214
+ noRefs: true,
1215
+ quotingType: '"',
1216
+ forceQuotes: false
1217
+ });
1218
+ fs.writeFileSync(configPath, content, "utf-8");
1219
+ return configPath;
1220
+ }
1221
+ function findExistingConfig(cwd) {
1222
+ for (const name of [
1223
+ ".versionguard.yml",
1224
+ ".versionguard.yaml",
1225
+ "versionguard.yml",
1226
+ "versionguard.yaml"
1227
+ ]) {
1228
+ const full = path.join(cwd, name);
1229
+ if (fs.existsSync(full)) return full;
1230
+ }
1231
+ return null;
1232
+ }
8
1233
  const CLI_DIR = path.dirname(fileURLToPath(import.meta.url));
9
1234
  const CLI_VERSION = JSON.parse(fs.readFileSync(path.join(CLI_DIR, "..", "package.json"), "utf-8")).version;
1235
+ const ckmEngine = createCkmEngine(JSON.parse(ckmRaw));
10
1236
  const styles = {
11
1237
  error: chalk.red,
12
1238
  warning: chalk.yellow,
@@ -15,38 +1241,59 @@ const styles = {
15
1241
  dim: chalk.gray,
16
1242
  bold: chalk.bold
17
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
+ }
18
1252
  function createProgram() {
19
1253
  const program = new Command();
20
1254
  program.name("versionguard").description("Strict versioning enforcement for SemVer and CalVer").version(CLI_VERSION);
21
- program.command("init").description("Initialize VersionGuard configuration").option("-c, --cwd <path>", "Working directory", process.cwd()).action((options) => {
22
- try {
23
- const configPath = initConfig(options.cwd);
24
- console.log(styles.success(`✓ Created ${path.relative(options.cwd, configPath)}`));
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(
1256
+ async (options) => {
25
1257
  try {
26
- const config = getConfig(options.cwd);
27
- installHooks(config.git, options.cwd);
28
- console.log(styles.success("✓ Git hooks installed"));
29
- } catch {
30
- console.log(
31
- styles.info("ℹ Skipped hooks install (not a git repository or hooks disabled)")
32
- );
1258
+ const isHeadless = options.yes || options.type || options.format || options.manifest;
1259
+ let configPath;
1260
+ if (isHeadless) {
1261
+ configPath = runHeadless({
1262
+ cwd: options.cwd,
1263
+ type: options.type,
1264
+ format: options.format,
1265
+ manifest: options.manifest,
1266
+ hooks: options.hooks,
1267
+ changelog: options.changelog,
1268
+ yes: options.yes,
1269
+ force: options.force
1270
+ });
1271
+ console.log(styles.success(`✓ Created ${path.relative(options.cwd, configPath)}`));
1272
+ } else {
1273
+ configPath = await runWizard(options.cwd);
1274
+ if (!configPath) {
1275
+ process.exit(0);
1276
+ return;
1277
+ }
1278
+ }
1279
+ try {
1280
+ const config = getConfig(options.cwd);
1281
+ if (config.git.enforceHooks) {
1282
+ installHooks(config.git, options.cwd);
1283
+ console.log(styles.success("✓ Git hooks installed"));
1284
+ }
1285
+ } catch {
1286
+ console.log(styles.info("ℹ Skipped hooks install (not a git repository)"));
1287
+ }
1288
+ } catch (error) {
1289
+ console.error(styles.error(`✗ ${error.message}`));
1290
+ process.exit(1);
33
1291
  }
34
- console.log("");
35
- console.log(styles.info("Next steps:"));
36
- console.log(" 1. Edit .versionguard.yml to set your versioning type");
37
- console.log(" 2. Run: npx versionguard check");
38
- console.log("");
39
- console.log(
40
- styles.info("Tip: Add a prepare script to package.json for clone persistence:")
41
- );
42
- console.log(' "prepare": "npx versionguard hooks install"');
43
- } catch (error) {
44
- console.error(styles.error(`✗ ${error.message}`));
45
- process.exit(1);
46
1292
  }
47
- });
1293
+ );
48
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) => {
49
1295
  try {
1296
+ options.cwd = requireProject(options.cwd, "check");
50
1297
  const config = getConfig(options.cwd);
51
1298
  const version = getPackageVersion(options.cwd, config.manifest);
52
1299
  const result = getVersionFeedback(version, config, options.prev);
@@ -99,6 +1346,7 @@ function createProgram() {
99
1346
  });
100
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) => {
101
1348
  try {
1349
+ options.cwd = requireProject(options.cwd, "validate");
102
1350
  const config = getConfig(options.cwd);
103
1351
  const version = getPackageVersion(options.cwd, config.manifest);
104
1352
  const result = validate(config, options.cwd);
@@ -190,6 +1438,7 @@ function createProgram() {
190
1438
  });
191
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) => {
192
1440
  try {
1441
+ options.cwd = requireProject(options.cwd, "doctor");
193
1442
  const config = getConfig(options.cwd);
194
1443
  const report = doctor(config, options.cwd);
195
1444
  const guardReport = options.strict ? runGuardChecks(config, options.cwd) : void 0;
@@ -241,6 +1490,7 @@ function createProgram() {
241
1490
  });
242
1491
  program.command("fix").description("Auto-fix detected issues").option("-c, --cwd <path>", "Working directory", process.cwd()).action((options) => {
243
1492
  try {
1493
+ options.cwd = requireProject(options.cwd, "fix");
244
1494
  const config = getConfig(options.cwd);
245
1495
  const version = getPackageVersion(options.cwd, config.manifest);
246
1496
  const results = fixAll(config, version, options.cwd);
@@ -255,8 +1505,31 @@ function createProgram() {
255
1505
  process.exit(1);
256
1506
  }
257
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
+ });
258
1530
  program.command("sync").description("Sync version to all configured files").option("-c, --cwd <path>", "Working directory", process.cwd()).action((options) => {
259
1531
  try {
1532
+ options.cwd = requireProject(options.cwd, "sync");
260
1533
  const config = getConfig(options.cwd);
261
1534
  const version = getPackageVersion(options.cwd, config.manifest);
262
1535
  const results = fixSyncIssues(config, options.cwd);
@@ -273,6 +1546,7 @@ function createProgram() {
273
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(
274
1547
  (options) => {
275
1548
  try {
1549
+ options.cwd = requireProject(options.cwd, "bump");
276
1550
  const config = getConfig(options.cwd);
277
1551
  const currentVersion = getPackageVersion(options.cwd, config.manifest);
278
1552
  const suggestions = suggestNextVersion(currentVersion, config, options.type);
@@ -300,6 +1574,7 @@ function createProgram() {
300
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(
301
1575
  (version, options) => {
302
1576
  try {
1577
+ options.cwd = requireProject(options.cwd, "tag");
303
1578
  const config = getConfig(options.cwd);
304
1579
  const tagVersion = version || getPackageVersion(options.cwd, config.manifest);
305
1580
  const result = createTag(
@@ -323,9 +1598,32 @@ function createProgram() {
323
1598
  }
324
1599
  }
325
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
+ });
326
1623
  const hooksCommand = program.command("hooks").description("Manage git hooks");
327
1624
  hooksCommand.command("install").description("Install git hooks").option("-c, --cwd <path>", "Working directory", process.cwd()).action((options) => {
328
1625
  try {
1626
+ options.cwd = requireProject(options.cwd, "hooks install");
329
1627
  const config = getConfig(options.cwd);
330
1628
  installHooks(config.git, options.cwd);
331
1629
  console.log(styles.success("✓ Git hooks installed"));
@@ -336,6 +1634,7 @@ function createProgram() {
336
1634
  });
337
1635
  hooksCommand.command("uninstall").description("Uninstall git hooks").option("-c, --cwd <path>", "Working directory", process.cwd()).action((options) => {
338
1636
  try {
1637
+ options.cwd = requireProject(options.cwd, "hooks uninstall");
339
1638
  uninstallHooks(options.cwd);
340
1639
  console.log(styles.success("✓ Git hooks uninstalled"));
341
1640
  } catch (error) {
@@ -345,6 +1644,7 @@ function createProgram() {
345
1644
  });
346
1645
  hooksCommand.command("status").description("Check if hooks are installed").option("-c, --cwd <path>", "Working directory", process.cwd()).action((options) => {
347
1646
  try {
1647
+ options.cwd = requireProject(options.cwd, "hooks status");
348
1648
  if (areHooksInstalled(options.cwd)) {
349
1649
  console.log(styles.success("✓ VersionGuard hooks are installed"));
350
1650
  return;
@@ -362,8 +1662,14 @@ async function runCli(argv = process.argv) {
362
1662
  await createProgram().parseAsync(argv);
363
1663
  }
364
1664
  function shouldRunCli(argv = process.argv, metaUrl = import.meta.url) {
365
- const entryPath = argv[1] ? path.resolve(argv[1]) : null;
366
- 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
+ }
367
1673
  }
368
1674
  if (shouldRunCli()) {
369
1675
  void runCli();