CodeGuard 0.1.1
See the version list below for details.
dotnet tool install --global CodeGuard --version 0.1.1
dotnet new tool-manifest
dotnet tool install --local CodeGuard --version 0.1.1
#tool dotnet:?package=CodeGuard&version=0.1.1
nuke :add-package CodeGuard --version 0.1.1
CodeGuard
A deterministic analysis/validation engine for enforcing an organisation's engineering standards (DDD, architecture layering, C# conventions, etc.) against .NET repositories. Rules are authored as declarative YAML (target selector + assertions), not C# code, so new standards can be added without touching the engine. It's designed to sit alongside AI coding agents as a machine-checkable guardrail: agents load applicable rules before generating code, then this engine validates the result and reports structured violations for the agent to remediate.
Requirements
- .NET SDK
10.0.100or later (pinned inglobal.json,rollForward: latestFeature)
Build & test
dotnet build
dotnet test
Installation
The CLI is published to nuget.org as a .NET tool:
dotnet tool install -g CodeGuard
codeguard --help
This installs the codeguard command globally. See CLI usage below (all
examples work the same whether invoked as codeguard <command> after a tool install, or as
dotnet run --project src/CodeGuard.Cli -- <command> from a checkout of this repo).
CLI usage
If you've installed the tool (see Installation), run commands directly as
codeguard <command>. If you're working in a checkout of this repo, run them via
dotnet run --project src/CodeGuard.Cli -- <command> instead.
| Command | Description |
|---|---|
validate |
Validate a repository against configured rules |
rules list |
List rules discovered from the configured rule directories |
rules explain <ruleId> |
Print full metadata and source YAML for a single rule |
rules validate |
Validate a set of rule YAML files for structural correctness (not run against a repository) |
rules create |
Interactively scaffold a new rule YAML file |
setup |
Configure the rules source (a directory or git repo) used across all repos |
Common options shared by validate/rules list/rules explain/rules validate/rules create:
--path (repo root, default cwd), --config (explicit .codeguard/config.yml),
--rules-source (ad-hoc rules directory or git URL, bypassing config entirely — see below),
--branch (git branch for --rules-source). validate additionally supports --format console|json|sarif|html, --output <file>, --rule <id> (repeatable, restricts evaluation),
--solution <file> (repeatable, restricts analysis to specific .sln/.slnx files),
--severity-threshold, --fail-on. rules list supports --format table|json, --tag, and
--enabled-only. rules validate supports --format console|json. setup supports --source,
--branch, and --type directory|git (see below).
Examples (installed tool):
codeguard rules list
codeguard rules explain DDD-ENTITY-001
codeguard rules create
codeguard validate --format json --output report.json
Examples (from a checkout of this repo):
dotnet run --project src/CodeGuard.Cli -- rules list
dotnet run --project src/CodeGuard.Cli -- rules explain DDD-ENTITY-001
dotnet run --project src/CodeGuard.Cli -- validate --format json --output report.json
Configuring where rules come from
By default, validate/rules list/etc. look for rules via .codeguard/config.yml in the
target repo. Two ways to point them somewhere else:
One-time setup, so every command works out of the box against any repo without per-repo configuration — stored outside any repo, in the OS user/app-data directory:
# interactive - prompts for a directory path or git URL (and a branch, for git)
dotnet run --project src/CodeGuard.Cli -- setup
# non-interactive, a local directory of rules
dotnet run --project src/CodeGuard.Cli -- setup --source /home/jamie/rules-checkout
# non-interactive, a git repo - clones on first run, fetches/fast-forwards on later runs
dotnet run --project src/CodeGuard.Cli -- setup --source https://github.com/org/rules-repo.git --branch main
Re-running setup is the only thing that ever syncs a git rule source — validate and friends
never fetch on their own, so results stay reproducible between runs. Re-run setup whenever you
want the latest rules.
Ad-hoc, one-off override — skip setup entirely and point a single command straight at a
rules directory or git URL, without persisting anything:
dotnet run --project src/CodeGuard.Cli -- validate --path . --rules-source ../local-rules-checkout
dotnet run --project src/CodeGuard.Cli -- validate --path . --rules-source https://github.com/org/rules-repo.git --branch main
Resolution precedence (highest first): --rules-source > --config > the target repo's
.codeguard/config.yml > a prior setup run's global settings > the built-in default. See
docs/done/SETUP_COMMAND_PLAN.md for the full design.
Known limitation: running
validateagainst this repo's own solution (CodeGuard.sln) currently crashes during self-analysis (a Buildalyzer build-output collision) — this doesn't affect validating other repos. SeeCLAUDE.mdanddocs/IMPLEMENTATION_STATUS.mdfor details.
Configuration
.codeguard/config.yml tells CodeGuard where to discover rules, skills, agents, source, and
tests in a given repository; missing paths are skipped silently. Rule files live under rules/
and are validated against rules/schema/rule.schema.json.
Project layout
CodeGuard.Analysis— pure model + analysis provider abstraction (no dependencies)CodeGuard.RuleModel— selector/assertion/condition interfacesCodeGuard.Evaluation/CodeGuard.Core— concrete selectors/assertions, and the rule evaluatorCodeGuard.Analyzers.Roslyn/.MSBuild/.Repository— data providers (Roslyn, MSBuild via Buildalyzer, filesystem)CodeGuard.Reporting— Console/Json/Sarif violation reportersCodeGuard.Configuration— YAML rule parsingCodeGuard.Cli— thecodeguardcommand-line tool, depends on everything above
Further reading
docs/PRIMITIVES.md— original design rationaledocs/done/SETUP_COMMAND_PLAN.md— design of thesetupcommand and rule-source resolutionCLAUDE.md— contributor/agent guidance, architecture detail, and known gotchas
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.