Skip to content

About

Deterministic action-risk classification, workspace containment, secret redaction & approval gates for AI coding agents (MCP Server + Multi-CLI Skills)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

CodexCli-GuardRails

Guardrails for AI coding assistants and shell workflows with two interchangeable delivery modes:

  • Declarative CLI skills (SKILL.md) for Codex/OpenAI-style tool loading
  • MCP server (mcp-server/) for MCP-aware clients

This repository provides a production-friendly baseline for teams that want:

  • strong classification of destructive actions
  • explicit approval gates for risky commands
  • workspace-boundary safety checks
  • secret redaction and deterministic payload matching
  • safe test coverage that avoids running destructive commands

Quick reference

Risk model

Class Meaning Required approval Examples
Class 0 Read-only work No git status, git diff, ls
Class 1 Bounded local mutation No Edit one file, update one function
Class 2 Destructive local state change Yes git clean -fdx (after preview), recursive delete
Class 3 Cloud credentials / remote execution / install risk Yes terraform apply, `curl ...
Class X Hard refuse (never executes) Not applicable Disk wipe, system boot/root deletion, global security disablement

Approval templates

  • Class 2:
    • APPROVE-DESTRUCTIVE:
  • Class 3:
    • APPROVE-CLOUD: (primary)
    • APPROVE-RISKY: (accepted alias for compatibility)

Approval payload shape:

APPROVE-DESTRUCTIVE:
payload_id: <slug>
workdir: .
commands:
- <command 1>
- <command 2>

Minimum safe command contract

  • No APPROVE-DESTRUCTIVE or APPROVE-CLOUD payload may use a workdir outside the resolved workspace root.
  • Payload matching normalizes line endings and trims trailing spaces before comparison.
  • Class X actions are never bypassed by approval.

Repository standards for public release

  • No embedded credentials, tokens, private keys, or connection strings in policy/docs/code examples.
  • Deterministic behavior across clients (stable approvals, predictable classification outputs).
  • Non-destructive tests only; destructive behavior is simulated and never executed against real system resources.

Repository layout

skills/

Contains one folder per supported AI CLI:

  • guard-users-claude
  • guard-users-codex
  • guard-users-gemini
  • guard-users-chatgpt
  • guard-users-aider
  • guard-users-openhands
  • guard-users-qwen
  • guard-users-llama

Each folder includes:

  • SKILL.md - policy for that interface
  • agents/openai.yaml - loader metadata for OpenAI-style orchestrators

mcp-server/

Python implementation of a Guard Users MCP server.

  • mcp_server/server.py - protocol loop, classification engine, approval payload builder/validator
  • mcp_server/skills_loader.py - discovers and loads guard-users-* skills from skills/
  • mcp-server/tests/test_guard_users_mcp.py - non-destructive test suite for all major policy outcomes
  • mcp-server/README.md - focused server usage notes
  • mcp-server/CHANGELOG.md - MCP release notes

What this repo solves

1) Safe default behavior across tools

All policy documents share the same core model:

  • Class 0: read-only
  • Class 1: bounded local mutation
  • Class 2: destructive local mutation, requires explicit payload + approval
  • Class 3: credential/cloud/network execute risk, requires strict approval
  • Class X: non-permissible actions (catastrophic/system destructive)

Rules can be interpreted directly by humans and by MCP clients.

2) Deterministic approvals

For Class 2 and Class 3, approvals are generated from exact payloads.

Key properties:

  • exact text block matching
  • workspace-aware workdir validation
  • optional digest (payload_sha256) for tamper evidence
  • strict CRLF/whitespace normalization behavior
  • deterministic parser that can be tested in CI

3) Workspace containment

The MCP implementation always resolves workdir and candidate targets against a workspace root (git root if present, else process cwd) and rejects writes/mutations that escape scope.

4) Safe redaction by default

Classifier output masks known secret shapes (for example AWS-style keys, GitHub tokens, JWT-like strings, private key blocks) when present in prompts or output.


Quick start (MCP server)

Option A: run from source (Python)

Set-Location <REPO_ROOT>
cd <REPO_ROOT>
Set-Location mcp-server
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -e .
python -m mcp_server

Option B: local editable install

Set-Location <REPO_ROOT>\mcp-server
python -m pip install -e .
guard-users-mcp

MCP client wiring examples

Use stdio transport with working directory pointing at the repo:

{
  "mcpServers": {
    "guard-users-mcp": {
      "command": "python",
      "args": ["-m", "mcp_server"],
      "cwd": "<REPO_ROOT>\\mcp-server"
    }
  }
}

If you prefer a script entry point:

{
  "mcpServers": {
    "guard-users-mcp": {
      "command": "guard-users-mcp",
      "args": [],
      "cwd": "<REPO_ROOT>\\mcp-server"
    }
  }
}

MCP tools exposed

list_guardrail_skills

List all available guard skill variants.

evaluate_request

Classify user text into action blocks and return policy metadata.

Useful output includes:

  • policy_version and schema_version
  • overall and per-block classification
  • approval_required
  • approval_prefix for Class 2/3
  • deny_code and sanitized preview of request

build_approval_payload

Construct exact approval payload text for Class 2/3 execution.

  • supports payload_id
  • supports multi-command payloads
  • validates workdir inside workspace
  • optional digest emission

validate_approval

Validate user reply text against proposed payload with strict normalization rules.

  • checks exact payload body match
  • checks optional digest hash when present
  • supports APPROVE-RISKY: alias for Class 3

Skill mode (non-MCP)

If your environment uses direct skill loading instead of MCP, each SKILL.md is a first-class, versioned policy file:

  • choose one by CLI family (guard-users-codex, guard-users-gemini, etc.)
  • keep exactly one active policy format per tool integration
  • legacy root-level skill files were intentionally removed in favor of per-CLI folders

Safe test suite

All existing tests are read-only and do not write outside test fixtures.

Run with:

Set-Location <REPO_ROOT>\mcp-server
$env:PYTHONPATH = (Resolve-Path ".").Path
python -m unittest discover -s tests -p "test_guard_users_mcp.py"

The suite validates:

  • skill discovery from skills/
  • command-class synthesis for read-only, class 2, class 3, and class X paths
  • payload construction and strict validation behavior
  • CRLF normalization behavior for safe approval matching
  • secret redaction and escape checks

Change history highlights

  • MCP policy version: 1.4.1
  • Added action-block classification output
  • Added workspace-aware payload validation
  • Added payload_sha256 integrity checks
  • Added APPROVE-RISKY compatibility for Class 3 approvals
  • Added expanded test vectors for mixed-class chains and safe validation

See mcp-server/CHANGELOG.md for the full timeline.


Contributing

When adding new CLI variants:

  1. create skills/guard-users-<cli>/SKILL.md
  2. include deterministic action classes and approval wording
  3. add/adjust any agents/openai.yaml metadata
  4. add test vectors in mcp-server/tests if classification behavior changes
  5. ensure tests remain read-only and non-destructive

Safety notes

  • Do not add dangerous destructive commands into new docs/tests.
  • Keep destructive or networked operations behind approval gates.
  • Assume all patterns are high-risk until proven bounded and local.
  • Class X should remain non-overridable by confirmation wording.

Credential and secret hygiene

This repository intentionally contains no real secrets. Test coverage includes synthetic token-shaped fixtures (for redaction-path verification) and verifies those values are never reflected in sanitized outputs.

Release checks include:

  • No token-like hardcoded credentials in policy files
  • No environment variable snapshots or secret dumps in logs
  • No credential-bearing example commands without explicit masking guidance
  • README and examples written for reuse by third parties without exposing internal/private state

This repository ships guardrails; it does not remove your responsibility to review risky operations.

About

Deterministic action-risk classification, workspace containment, secret redaction & approval gates for AI coding agents (MCP Server + Multi-CLI Skills)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages