Skip to content

About

Human-in-the-loop governance middleware preventing AI hallucination at the Git level.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

184 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

defense-in-depth Icon

defense-in-depth

Git-based governance middleware for AI coding agents

AI handles artifacts and execution. Humans handle business logic and ground truth.

Status: Active Version: 1.0.0-rc.1 Coverage: line≥97% branch≥91% func≥95% License: MIT Platform: Cross-Platform Node: ≥18 TypeScript: Strict PRs Welcome

English · Tiếng Việt


AI coding agents generate 10x code, but also introduce failure modes: hollow templates, SSoT corruption, cowboy commits, and plan bypasses.
defense-in-depth catches these failure modes deterministically at commit time.

Note

defense-in-depth ships an opinionated scaffold, not a turnkey black box.
The deterministic guard pipeline (9 built-in guards + pure Guard interface) is the core. The optional .agents/ ecosystem (20 rules, cognitive tree, skill templates) is a starting point: fork it, delete what doesn't fit, and adapt it to your team's conventions.

Important

Client-side hooks are bypassable with --no-verify. For real enterprise governance, pair local hooks with the official GitHub Action and branch protection rules on your default branch.


⚡ 60-Second Quickstart

# 1. Initialize inside any existing Git repository
npx defense-in-depth init

# What this does:
# ✅ Creates defense.config.yml with sensible defaults
# ✅ Installs pre-commit and pre-push Git hooks
# ✅ Enables hollow-artifact and ssot-pollution guards

# 2. Verify repository health
npx defense-in-depth doctor

# 3. Manually scan your staged files
npx defense-in-depth verify

Optional: Scaffold AI Agent Governance Kit

# Set up the full .agents/ governance framework for AI-driven workflows
npx defense-in-depth init --scaffold

Server-Side Enforcement (CI/CD)

Add the official GitHub Action to validate pull requests beyond any agent's reach:

# .github/workflows/defense.yml
name: defense-in-depth
on: [pull_request]

jobs:
  verify:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: tamld/defense-in-depth/.github/actions/verify@v1.0.0-rc.1

🛡️ Built-in Guards

Guard Default Severity Hook Trigger What It Catches
Hollow Artifact ✅ ON BLOCK pre-commit Unfilled stub markers and empty scaffolding
SSoT Pollution ✅ ON BLOCK pre-commit Unauthorized edits to governance files (.agents/**, backlog.yml)
Root Pollution ✅ ON BLOCK pre-commit Unapproved scratch files or folders placed in the repository root
Commit Format ✅ ON WARN commit-msg Non-conventional commit messages (type(scope): description)
Branch Naming ❌ OFF WARN pre-push Branch names not matching feat/*, fix/*, chore/*, docs/*
Ticket Identity ❌ OFF WARN pre-commit Conflicting or missing ticket IDs in commit metadata (TKID)
Phase Gate ❌ OFF BLOCK pre-commit Committing feature code without an implementation_plan.md
HITL Review ❌ OFF BLOCK pre-commit Committing protected files without human review sign-off markers
Federation ❌ OFF BLOCK pre-commit Ticket state validation across federated/parent-child repositories

📖 For complete configuration options and customization, see Configuration Guide.


🏗️ Architecture: Progressive Enhancement

defense-in-depth is engineered with a strict 4-tier layering model:

Tier 0 — Deterministic Core (Zero dependencies, stdlib + yaml only)
  Regex/AST heuristics, Git hooks, sequential engine, <100ms execution
  → Guarantees: BLOCK/WARN on known anti-patterns anywhere

Tier 1 — Lesson Injection (Offline, evidence-grounded)
  Matches findings to lessons.jsonl (wrongApproachPattern → correctApproach)
  → Guarantees: Actionable hints from past failures; RUNTIME/CODE evidence

Tier 2 — Optional Intelligence (Opt-in plugins)
  Local embeddings (MiniLM), LLM-as-judge (Ollama/vLLM), DSPy semantic evaluation
  → Guarantees: Recall/precision boost when available; Tier 0+1 hold when offline

Tier 3 — Multi-Agent Governance (.agents/ directory)
  Lazy-loaded rules, cognitive framework, and multi-agent contracts
  → Guarantees: Consistent behavioral standards across all AI contributors
flowchart LR
    A["🤖 AI Agent<br/>generates code"] --> B["📦 git commit"]
    B --> C{"🛡️ defense-in-depth<br/>pre-commit hook"}
    C -->|"❌ BLOCK (Tier 0)"| D["Agent fixes<br/>before commit"]
    C -->|"⚠️ WARN + Hint (Tier 1)"| E["Lesson suggestion<br/>from past failures"]
    C -->|"✅ PASS"| F["Clean commit"]
    E --> F
    F --> G["👨‍💼 Human Review<br/>(Business Logic)"]
    G -->|"Approved"| H["✅ Merged to main"]
Loading

💻 CLI Commands

Command Purpose
npx defense-in-depth init [--scaffold] Install Git hooks and initialize defense.config.yml
npx defense-in-depth verify [--staged] [--all] Execute the guard pipeline on staged or workspace files
npx defense-in-depth doctor Run comprehensive environment and hook health checks
npx defense-in-depth feedback --file <path> Ingest human feedback into the Án Lệ memory loop
npx defense-in-depth lesson --tag <tag> Query recorded lessons and past failure patterns
npx defense-in-depth eval Run semantic evaluation on artifacts via DSPy (Tier 3, opt-in)
npx defense-in-depth hints-emit Emit context-aware progressive hints for agents

📖 Full CLI reference: CLI Reference Manual.


📚 Documentation Hub

Explore our comprehensive 5-pillar documentation:


🛠️ Development

npm run dev          # Watch mode compilation
npm test             # Run test suite
npm run test:watch   # Run tests in watch mode
npm run coverage     # Run tests with strict coverage gate
npm run lint         # TypeScript strict type check
npm run sync:wiki    # Sync wiki/ directory to GitHub Wiki repo

🤝 Contributing

We welcome contributions from both humans and AI agents operating under human direction!

  1. Read the Immutable Consistency Rules.
  2. Check open issues on GitHub Issues.
  3. Fork, create a branch (feat/*, fix/*, docs/*), and open a Pull Request.
  4. Ensure all tests pass: npm test and npx defense-in-depth verify.

📄 License

Distributed under the MIT License. See LICENSE for more information.

About

Human-in-the-loop governance middleware preventing AI hallucination at the Git level.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages