@codluv/versionguard

中文文档
1.2.0发布于 2026/03/31MITTypeScriptES Module构建来源已验证近 30 天下载 6164

Strict versioning enforcement for SemVer and CalVer — language-agnostic manifest support, git hooks, changelog validation, and file sync

原始使用文档
文档目录30 节
  1. Why it exists
  2. What it does
  3. Where it runs
  4. Who needs it
  5. Install
  6. Quick start
  7. Example output
  8. Configuration
  9. Supported versioning modes
  10. SemVer
  11. CalVer
  12. Language-agnostic manifests
  13. Commands
  14. Git hook behavior
  15. Doctor command
  16. Validate JSON output
  17. Tagging behavior
  18. Stability Policy
  19. Typical workflows
  20. Validate before committing
  21. Repair drift after a manual version change
  22. Suggest and apply the next version
  23. Create a release tag safely
  24. Using with Changesets
  25. Recommended workflow
  26. CI integration
  27. Development
  28. Docs
  29. Forge
  30. License

VersionGuard

Strict version governance for any project — SemVer and CalVer enforcement, language-agnostic manifest support, git hooks, changelog validation, file sync, and repo-wide version scanning.

VersionGuard keeps your manifest, changelog entries, git tags, and configured version references in sync so humans and LLM agents stop shipping messy release state.

Why it exists

Versioning breaks in the same places over and over:

  • versions get hardcoded across docs, CI configs, and Dockerfiles
  • changelog entries are forgotten or use wrong section names
  • tags drift from the package version
  • SemVer and CalVer rules get bent under pressure
  • agents take shortcuts and leave the repo in an invalid release state

VersionGuard turns those into enforceable checks with repair-oriented feedback.

What it does

  • validates SemVer and CalVer formats with configurable rules
  • keeps configured files synced from your manifest (package.json, Cargo.toml, pyproject.toml, etc.)
  • scans the entire repo for stale version literals (enabled by default)
  • verifies publish status against your package registry (npm, crates.io, PyPI, etc.)
  • validates Keep a Changelog structure with section enforcement
  • installs cooperative git hooks for pre-commit, pre-push, and post-tag
  • provides CLI commands for validation, sync, bumps, and tagging
  • refuses unsafe tagging when hooks are required or the worktree is dirty
  • built-in CKM help system for humans and LLM agents (vg ckm)

Where it runs

VersionGuard enforces at three points in the development lifecycle:

  1. Local dev (git hooks): pre-commit and pre-push hooks run vg validate automatically. This catches version drift, changelog issues, and sync mismatches before code leaves the developer's machine. This is the primary enforcement point.

  2. CI (GitHub Actions): vg validate runs as a build gate in CI. This catches anything the hooks missed (hooks can be skipped with --no-verify), validates on every PR, and ensures Dependabot PRs don't break version consistency.

  3. CLI (developer workflow): vg check, vg fix, vg sync, vg tag, vg doctor — manual commands that developers and agents use during the release flow.

Who needs it

  • Any project that ships versioned software and wants to stop version-related drift: stale install commands in docs, missing changelog entries, hardcoded version strings in CI configs or Dockerfiles, tag/manifest mismatches
  • Teams using AI agents that modify code — VG is the guardrail that catches when agents skip versioning steps
  • Polyglot projects that need consistent version governance across npm, Rust, Python, Dart, PHP, Java, and more

Install

npm install -D @codluv/versionguard@latest
vg init
vg hooks install

vg is a shorthand alias for versionguard. Both work identically.

That gives you:

  • a .versionguard.yml config file
  • managed git hooks
  • a repo-local version policy built around your manifest

Quick start

Run a basic version check:

vg check

Run full repository validation (includes scan, guard, and publish checks by default):

vg validate

For CI or agent workflows:

vg validate --json

Sync configured files back to the manifest version:

vg sync

Repair common issues automatically:

vg fix

Example output

Valid version:

Current version: 1.2.3
Versioning type: semver

✓ Version is valid

Invalid version with actionable guidance:

Current version: v1.0.0
Versioning type: semver

✗ Version has issues:

  ✗ Version should not start with 'v': v1.0.0

How to fix:
  → Remove the 'v' prefix
    Run: npm version 1.0.0

Configuration

VersionGuard uses a single YAML config file. Both semver: and calver: blocks are always present — change type to switch.

Example:

versioning:
  type: semver
  semver:
    allowVPrefix: false
    allowBuildMetadata: true
    requirePrerelease: false
  calver:
    format: "YYYY.MM.PATCH"
    preventFutureDates: true

sync:
  files:
    - "README.md"
    - "CHANGELOG.md"
  patterns:
    - regex: '(version\s*[=:]\s*["'])(.+?)(["'])'
      template: '$1{{version}}$3'
    - regex: '(##\s*\[)(.+?)(\])'
      template: '$1{{version}}$3'

changelog:
  enabled: true
  file: "CHANGELOG.md"
  strict: true
  requireEntry: true
  enforceStructure: false
  sections:
    - Added
    - Changed
    - Deprecated
    - Removed
    - Fixed
    - Security

# All checks below are enabled by default — opt OUT via config
guard:
  enabled: true          # hook bypass detection

publish:
  enabled: true          # registry publish status verification
  timeout: 5000          # ms, fail-open on timeout

scan:
  enabled: true          # repo-wide stale version detection
  allowlist: []

git:
  hooks:
    pre-commit: true
    pre-push: true
    post-tag: true
  enforceHooks: true

ignore:
  - "node_modules/**"
  - "dist/**"
  - ".git/**"
  - "*.lock"

Supported versioning modes

SemVer

VersionGuard supports strict semantic version validation with configurable rules via the semver: block:

  • MAJOR.MINOR.PATCH with prerelease (1.2.3-alpha.1) and build metadata (1.2.3+build.5)
  • allowVPrefix — tolerate v1.2.3 format (stripped before parsing)
  • allowBuildMetadata — permit or reject +build metadata suffix
  • requirePrerelease — require prerelease labels on every version
  • schemeRules.allowedModifiers — whitelist prerelease tags (e.g., alpha, beta, rc)
  • precedence comparison and increment helpers

CalVer

Composable token-based format strings supporting all calver.org tokens:

  • Year: YYYY, YY, 0Y
  • Month: MM, M, 0M
  • Week: WW, 0W
  • Day: DD, D, 0D
  • Counter: MICRO, PATCH

CalVer validation can reject future-dated versions and enforce modifier allowlists.

Language-agnostic manifests

VersionGuard reads versions from any supported manifest:

  • package.json (Node.js), Cargo.toml (Rust), pyproject.toml (Python)
  • pubspec.yaml (Dart/Flutter), composer.json (PHP), pom.xml (Java/Maven)
  • VERSION (plain text), Git tags (Go/Swift), Custom regex patterns

Set manifest.source: auto for automatic detection.

Commands

CommandDescription
vg initCreate .versionguard.yml (interactive wizard or headless)
vg checkValidate the current version with actionable feedback
vg validateRun all checks: version, sync, changelog, scan, guard, publish
vg doctorReport repository readiness in one pass
vg fixApply deterministic fixes for common drift
vg fix-changelogFix Changesets-mangled changelogs to Keep a Changelog format
vg syncUpdate configured files to match manifest version
vg bumpSuggest the next version and optionally apply it
vg tag [version]Create an annotated release tag safely
vg hooks installInstall managed git hooks
vg hooks uninstallRemove managed git hooks
vg hooks statusCheck whether hooks are installed
vg ckm [topic]Codebase Knowledge Manifest — auto-generated help
vg ckm [topic] --jsonMachine-readable CKM for LLM agents

Git hook behavior

VersionGuard can install these hooks:

  • pre-commit
  • pre-push
  • post-tag

When git.enforceHooks is enabled, release tagging also expects managed hooks to be present.

Doctor command

Use doctor when you want a one-pass readiness report before releasing:

vg doctor

For CI or agent workflows:

vg doctor --json

It reports:

  • current package version
  • version validity
  • sync status
  • changelog readiness
  • hook installation state
  • worktree cleanliness

Validate JSON output

Use validate --json when you need machine-readable validation output:

vg validate --json

The JSON payload includes:

  • valid
  • version
  • versionValid
  • syncValid
  • changelogValid
  • scanValid
  • guardValid
  • publishValid
  • publishCheck
  • guardReport
  • errors
  • hook
  • postTag

Tagging behavior

versionguard tag is intentionally strict.

It can refuse to proceed when:

  • hooks are required but not installed
  • the working tree is dirty
  • the requested tag already exists
  • the package version or changelog state is invalid
  • synced files are out of date

That keeps release tags from becoming a bypass around normal validation.

Stability Policy

1.x maintains backward compatibility for all CLI commands and configuration formats. Breaking changes only occur in 2.0+.

Deprecated flags (--strict, --scan) continue to work in 1.x and print a warning. Their behavior is now the default. To opt out of specific checks, use config:

guard:
  enabled: false
scan:
  enabled: false
publish:
  enabled: false

Typical workflows

Validate before committing

vg validate

Repair drift after a manual version change

npm version patch
vg fix

Suggest and apply the next version

vg bump --apply

Create a release tag safely

vg tag 1.2.3 -m "Release 1.2.3"

Using with Changesets

VersionGuard and Changesets are complementary tools that handle different parts of the release lifecycle.

ConcernChangesetsVersionGuard
Decide the next versionYesNo (validates, doesn't choose)
Update manifest versionYesNo (reads it as source of truth)
Validate version formatNoYes (SemVer/CalVer strictness)
Sync version across filesNoYes (regex-based sync)
Validate changelog structureNoYes (Keep a Changelog + section enforcement)
Scan repo for stale versionsNoYes
Verify publish status on registryNoYes (fail-open)
Git hooks enforcementNoYes
Publish to npmYesNo

Changesets decides what version comes next. VersionGuard validates that the result is correct.

# 1. Add a changeset when making changes
npx changeset

# 2. When ready to release, version the packages
npx changeset version

# 3. VersionGuard validates the new state
vg validate

# 4. Publish
npx changeset publish

CI integration

In GitHub Actions, both tools run in sequence. Changesets creates a "Version Packages" PR when changesets are pending. VersionGuard validates the result before publishing:

- run: npm run build
- run: vg validate
- uses: changesets/action@v1
  with:
    publish: npx changeset publish --access public

VersionGuard does not replace Changesets and does not conflict with it. Use Changesets for release automation. Use VersionGuard for release correctness.

Development

This repository uses a modern ESM toolchain:

  • Vite for builds
  • Vitest for tests
  • Biome for formatting and baseline linting
  • ESLint for semantic TypeScript linting

Useful commands:

npm run lint
npm test
npm run build

Forge commands:

npm run forge:check
npm run forge:test
npm run forge:build
npm run forge:doctor

Initialize or refresh Forge scaffolding:

npm run forge:docs:init

Run a single test file:

npx vitest run src/__tests__/semver.test.ts

Run a single test by name:

npx vitest run src/__tests__/calver.test.ts -t "increments patch-based versions"

Docs

  • Product vision: docs/VISION.md
  • Verified feature ledger and roadmap: docs/FEATURES.md
  • CKM module documentation: src/ckm/README-CKM.md
  • Agent guidance for contributors: AGENTS.md

Forge

This repo is set up with @forge-ts/cli and a project config in forge-ts.config.ts.

Useful commands:

npm run forge:check
npm run forge:test
npm run forge:build
npm run forge:doctor

Current status:

  • Forge is installed and initialized
  • forge-ts check currently reports significant TSDoc debt
  • generated documentation artifacts are written into docs/

Recommended workflow:

npm run forge:check
npm run forge:build

Then fix TSDoc issues in the order reported by Forge.

License

MIT

版本与发布记录

@codluv/versionguard 共发布 13 个版本,首次发布于 2026/03/22;过去 12 个月发布了 13 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.2.0latest2026/03/317 个月前
1.1.02026/03/307 个月前
1.0.02026/03/297 个月前
0.9.02026/03/277 个月前
0.8.02026/03/277 个月前
0.7.02026/03/277 个月前

关于 @codluv/versionguard 的常见问题

@codluv/versionguard 是什么?

Strict versioning enforcement for SemVer and CalVer — language-agnostic manifest support, git hooks, changelog validation, and file sync

如何安装 @codluv/versionguard?

在项目目录运行 npm install @codluv/versionguard,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 versionguard、vg,可以用 npx versionguard 直接运行。

@codluv/versionguard 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@codluv/versionguard 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@codluv/versionguard 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@codluv/versionguard 可以商用吗?

@codluv/versionguard 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@codluv/versionguard 的下载量有多少?

根据 npm 官方下载统计,@codluv/versionguard 在 2026/10/10 – 2026/11/08 这 30 天内被下载 6,164 次,日均约 205 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@codluv/versionguard 还在维护吗?

最新版本 1.2.0 发布于 2026/03/31(7 个月前);至今共发布 13 个版本,其中过去 12 个月发布了 13 个;首次发布于 2026/03/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。