RaiGuard 4.5.5

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global RaiGuard --version 4.5.5
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local RaiGuard --version 4.5.5
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=RaiGuard&version=4.5.5
                    
nuke :add-package RaiGuard --version 4.5.5
                    

RaiGuard

Opinionated Roslyn analyzer, code-fix provider, and rail command-line tool enforcing framework physics and conventions across RAIkeep solutions.

4.5.5

Initial release of rail CLI and RaiGuard Roslyn guardrail engine. Public behavior is aligned with the synchronized RAIkeep platform (4.5.5 dependency line).

Terminal font

Font note: The rail help screen and console diagnostics use glyph icons from Nerd Fonts. Most Nerd Font-patched fonts render correctly in most terminal environments. Blink on iPadOS showed clipping and character-width problems with some choices; the tested solution was Blink's Jet Brains Mono Nerd Font stylesheet. See the RAIkeep terminal font guide for Blink, macOS, and Ubuntu setup.

Overview

RaiGuard prevents LLMs and developers from backsliding into standard .NET boilerplate (such as System.IO.Directory or default serializers) when custom abstractions (RaiPath, JsonPit, etc.) are required.

It operates as two complementary NuGet packages:

  1. RaiGuard.Analyzer: Roslyn analyzer and code-fix package invoked directly during dotnet build, IDE compilation, and CI pipelines to emit compiler warnings/errors and provide automated quick fixes.
  2. RaiGuard: Official .NET Global Tool CLI (ToolCommandName=rail) running anywhere .NET is installed to audit, verify, and automatically refactor source files across repositories.

Quick Start

Install the Global CLI Tool (rail)

dotnet tool install --global RaiGuard
rail --version

Install the Roslyn Analyzer Package

<PackageReference Include="RaiGuard.Analyzer" Version="4.5.5">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

📖 Comprehensive Adoption Guide: See INTEGRATION_GUIDE.md for repository-wide protection via Directory.Build.props, VS Code C# Dev Kit live squiggles, .editorconfig severity overrides, and CI pipelines.

CLI Commands & Options

Commands: check, fix, rules
  rail check [<path>] [--rule <id>] [--json]
  rail fix [<path>] [--rule <id>] [--dry-run]
  rail rules [--json]

Options:
  -h, --help      print out all options
  -v, --version   print version info
  -n, --nologo    do not display the banner
  -b, --debug     enable debug output
  -p, --path      target file or directory (defaults to current directory)
  --rule          filter by rule ID (e.g. RAI001)
  --json          output diagnostics in JSON format
  --dry-run       simulate code fixes without modifying source files on disk

Examples

Check current directory for framework violations:

rail check

Automatically refactor prohibited patterns to framework equivalents:

rail fix

Inspect active guardrail definitions:

rail rules

Guardrail Rules

Rule ID Severity Description Remedy
RAI001 Warning Direct usage of System.IO.Directory methods is prohibited Use RaiPath methods (e.g. RaiPath.EnumerateDirectories, RaiPath.EnumerateFiles)
RAI002 Warning Direct usage of System.IO.File methods is prohibited Use RaiFile or TextFile methods (e.g. new RaiFile(filename).Exists(), new RaiFile(filename).rm(), new TextFile(filename).Read(), new TextFile(filename, "first line\nsecond line"))
RAI003 Warning Direct usage of System.IO.Path methods is prohibited Use RaiPath or RaiRelPath with operator / (e.g. new RaiPath(a) / b)
RAI010 Warning Tab indentation required and consecutive spaces prohibited Indent code with tabs (\t) and use single spaces between tokens outside string and character literals

Idiomatic Platform Patterns

  • Writing / Creating: new TextFile(filename, "first line\nsecond line"); (constructor appends and writes to disk immediately)
  • Reading: var tf = new TextFile(filename).Read(); (reads directly into memory as List<string>)
  • In-Memory Manipulation & Save:
    • tf.Delete(0); (removes line 0 in memory and marks Changed = true; updates disk on next .Save())
    • tf.DeleteAll().Save(); (clears all lines in memory and commits the empty file to disk)
  • Physical File Removal: new RaiFile(filename).rm(); or tf.rm(); (removes the file from disk via POSIX rm())
  • Existence: new RaiFile(filename).Exists();
  • Path Composition (Operator /):
    • var myPath = new RaiPath("~") / ".config";
    • workspace ??= Os.TempDir / "RAIkeep" / "image-import" / Guid.NewGuid().ToString("N");
    • (Never use System.IO.Path.Combine)

Solution Structure

RaiGuard/
├── rail/                                 # 1. The rail CLI tool (executable anywhere dotnet is installed)
│   ├── rail.csproj                       # ToolCommandName=rail, references all RAIkeep packages
│   └── Program.cs                        # CLI parsing, Nerd Font phenotype, and analysis/refactoring engine
│
├── rail.Tests/                           # 2. CLI End-to-End Tests
│   ├── rail.Tests.csproj
│   └── RailCliTests.cs
│
├── src/
│   ├── RaiGuard.Core/                    # 3. Roslyn Analyzer & Diagnostic Engine (netstandard2.0)
│   │   ├── RaiGuard.Core.csproj
│   │   ├── Diagnostics/DiagnosticDescriptors.cs
│   │   ├── Rules/SystemIoDirectoryAnalyzer.cs
│   │   ├── Rules/SystemIoFileAnalyzer.cs
│   │   ├── Rules/SystemIoPathAnalyzer.cs
│   │   ├── Rules/WhitespaceFormattingAnalyzer.cs
│   │   └── Helpers/SemanticExtensions.cs
│   │
│   ├── RaiGuard.CodeFixes/               # 4. Automated Code Fix Providers (netstandard2.0)
│   │   ├── RaiGuard.CodeFixes.csproj
│   │   ├── Fixes/SystemIoDirectoryCodeFix.cs
│   │   ├── Fixes/SystemIoFileCodeFix.cs
│   │   └── Fixes/SystemIoPathCodeFix.cs
│   │
│   └── RaiGuard.Package/                 # 5. Analyzer NuGet Packaging Project
│       └── RaiGuard.Package.csproj       # Packages analyzers into analyzers/dotnet/cs
│
├── tests/
│   └── RaiGuard.Tests/                   # 6. Unit Tests for Analyzers & Code Fixes
│       ├── RaiGuard.Tests.csproj
│       ├── SystemIoDirectoryAnalyzerTests.cs
│       ├── SystemIoFileAnalyzerTests.cs
│       ├── SystemIoPathAnalyzerTests.cs
│       └── WhitespaceFormattingAnalyzerTests.cs
│
├── samples/
│   └── HeatRecord/                       # 7. Sample App & Tutorial (Sparse Pit + Guardrails)
│       ├── HeatRecord.csproj
│       ├── Program.cs
│       ├── Program.Naive.cs
│       └── TUTORIAL.md
│
├── RaiGuard.slnx                         # Solution (slnx format)
└── RaiGuard.sln                          # Solution (classic sln format)

Building & Installation

See BuildFromSource.md for detailed build and deployment instructions.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
4.5.15 121 10/30/2026
4.5.14 119 10/26/2026
4.5.13 115 10/20/2026
4.5.12 114 10/19/2026
4.5.10 114 10/12/2026
4.5.9 105 10/12/2026
4.5.8 100 10/10/2026
4.5.5 111 10/8/2026

Initial release of rail CLI for RaiGuard Roslyn guardrail verification and refactoring.