Pattern8
๐ฑ AI Agent Governance Framework โ Constrain how AI Agents behave in your project. pip install pattern8
Install / Use
/learn @Aquifer-sea/Pattern8Quality Score
Category
Development & EngineeringSupported Platforms
README
Pattern 8 (P8)
Zero-Trust Governance Framework to stop AI Agents from hallucinating, breaking things, and bypassing your rules. <br/>
"Your prompt is merely a suggestion. P8 is the law."
๐จ๐ณ ็ฎไฝไธญๆ ยท Architecture (ๆบ็ ๅฏผ่ฏป)
</div>Table of Contents
- The Problem
- Quick Start
- Architecture
- Project Structure
- How It Works: Law vs. Police
- The 5 Patterns
- Anatomy of a SKILL
- The 5 Built-in SKILLs
- MCP Enforcement Engine
- Data Flow
- CLI Reference
- IDE Integration
- Pre-commit Hooks
- Creating Custom SKILLs
- Contributing
- License
The Chaos vs. The Law
Are you tired of AI coding agents (Claude, Cursor, Devin) ignoring your instructions, deleting the wrong files, or pushing code without tests?
Prompts are not enough. Prompt injection defence is impossible. To truly control an agent, constraints must be enforced at the OS and code level.
โ Without P8 (The Chaos)
- Agent decides to skip writing tests because it's "too trivial".
- Agent runs
rm -rfby mistake during a multi-step refactor. - Agent outputs a feature without ever writing a design doc.
- Agent ignores your 5,000-word system prompt because its context window is full.
๐ก๏ธ With P8 (The Law)
- MCP SecurityGuard intercepts and blocks dangerous commands at the OS level.
- MCP Reviewer forces the agent into a strict retry-loop if output doesn't match the
template.yaml. - Pre-commit Hooks ensure the agent hasn't tampered with the rules themselves.
- Inversion Pattern forces the agent to stop and ask you clarifying questions instead of hallucinating.
โก Zero to Hero in 30 Seconds
Take absolute control of your codebase with 3 commands:
# 1. Install the enforcer (Python 3.8+)
pip install pattern8
# 2. Add handcuffs to your current project
p8 init
# 3. Done. Your Agents are now under control.
p8 list
๐ก For Chinese-language teams:
p8 init --lang zhgenerates all SKILL files with Chinese annotations.
๐๏ธ Architecture Overview
P8 is NOT an AI Agent framework. It does not call LLMs or drive pipelines.
P8 is a governance layer โ a set of enforceable rule files + a runtime enforcement engine that constrains how any AI Agent works on your project.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ YOUR PROJECT โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ๐ LAW (Editable) โ โ ๐ POLICE (Read-Only Engine) โ โ
โ โ โ โ โ โ
โ โ skills/ โ โ src/p8/enforcement/ โ โ
โ โ โโโ prd/ โโโโ โ โโโ mcp_server.py (Gateway) โ โ
โ โ โโโ bug_fix/ โ โ โโโ security_guard.py (Block) โ โ
โ โ โโโ code_review/ โ โ โโโ reviewer.py (Audit) โ โ
โ โ โโโ refactor/ โ โ โ โ
โ โ โโโ feature_dev/ โ โ Runs as MCP stdio server โ โ
โ โ โ โ Agent โ MCP โ Police โ โ
โ โ AGENTS.md โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ .cursor/rules/*.mdc โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ๐ HOOKS (Git-level) โ โ
โ โ hooks/pre-commit โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Key Insight: The Agent can read SKILL.md, checklist.yaml, and template.yaml (the "law"). But it cannot read guidelines.yaml or security.yaml (the "audit criteria"). This prevents the Agent from gaming the audit.
๐ Project Structure
pattern8/
โโโ src/p8/ # Python package (pip install pattern8)
โ โโโ __init__.py # Package metadata (version)
โ โโโ cli.py # CLI entry point (click-based)
โ โโโ enforcement/ # ๐ Enforcement engine
โ โโโ __init__.py
โ โโโ mcp_server.py # MCP protocol gateway (3 Resources + 2 Tools)
โ โโโ security_guard.py # OS-level command blocker (regex blacklist)
โ โโโ reviewer.py # Static rule audit engine (format + rules)
โ
โโโ skills/ # ๐ Built-in SKILL rules (English)
โ โโโ prd/ # Product Requirements Document
โ โ โโโ SKILL.md # Pipeline definition (frontmatter + steps)
โ โ โโโ assets/
โ โ โ โโโ checklist.yaml # Inversion: pre-flight questions
โ โ โ โโโ template.yaml # Generator: output format
โ โ โโโ references/
โ โ โโโ guidelines.yaml # ๐ Reviewer audit rules (hidden from Agent)
โ โ โโโ security.yaml # ๐ SecurityGuard blacklist (hidden from Agent)
โ โโโ bug_fix/ # Bug Fix (same structure)
โ โโโ code_review/ # Code Review (same structure)
โ โโโ feature_dev/ # Feature Development (same structure)
โ โโโ refactor/ # Refactoring (same structure)
โ
โโโ skills_zh/ # ๐ Built-in SKILL rules (Chinese)
โ โโโ (same structure as skills/)
โ
โโโ hooks/
โ โโโ pre-commit # ๐ Git hook: SKILL integrity + secret scan
โ
โโโ AGENTS.md # Global agent behavior instructions
โโโ .cursor/rules/
โ โโโ p8-enforcement.mdc # Cursor IDE injection rules
โ
โโโ tests/
โ โโโ test_p8.py # CLI + SKILL management tests
โ โโโ test_enforcement.py # SecurityGuard + Reviewer + MCP tests
โ
โโโ .github/workflows/
โ โโโ ci.yml # CI: pytest on Python 3.11-3.13 ร Ubuntu/macOS
โ
โโโ pyproject.toml # Build config (hatchling)
โโโ CONTRIBUTING.md # Contributor guide
โโโ CHANGELOG.md # Version history
โโโ LICENSE # MIT
๐ How It Works: Law vs. Police
P8 separates Law (editable rules) from Police (read-only execution engine):
Developer-editable (Law) Read-only Engine (Police)
โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SKILL.md โ โ SecurityGuard โ
โ checklist.yaml โ read โ โ โณ regex blacklist โ
โ template.yaml โ โ โณ OS command hooks โ
โ guidelines.yaml ๐ โ โ Reviewer โ
โ security.yaml ๐ โ โ โณ static rule engine โ
โ โ โ โณ P8AuditError rollback โ
โ "The Constitution" โ โ "The Police" โ
โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Agent calls via MCP โ
You write the Law in simple Markdown and YAML. The Police engine enforces them automatically via MCP (Model Context Protocol). Files marked with ๐ are deliberately hidden from the Agent so it cannot read the security parameters used to audit it.
๐ The 5 Enforcement Patterns
Every SKILL enforces 5 patterns in sequence. These are the backbone of P8's governance philosophy:
| # | Pattern | What It Does | Controlled By |
|---|---------|-------------|---------------|
| 1 | Pipeline | Tasks execute in a strict ordered sequence. No step may be skipped. | SKILL.md |
| 2 | Inversion | Before starting, the Agent must verify all preconditions. If info is missing, it stops and asks โ no guessing. | assets/checklist.yaml |
| 3 | Generator | Output must follow a strict template. Every section must be filled. No freestyle. | assets/template.yaml |
| 4 | Tool Wrapper | Before executing OS commands, the Agent must pass through a security checkpoint. Blacklisted operations are rejected. | references/security.yaml ๐ |
| 5 | Reviewer | After completing output, a static audit engine scores the result. Non-compliant output triggers rollback + retry (up to 3ร). | references/guidelines.yaml ๐ |
Why are patterns 4 and 5 hidden? If the Agent can read the exact audit criteria, it can game the system by producing output that technically passes but is semantically garbage. By hiding them, the audit stays honest.
๐งฌ Anatomy of a SKILL
Each SKILL is a self-contained directory with 4 YAML config files and 1 Markdown pipeline definition:
skills/<skill_name>/
โโโ SKILL.md #
Related Skills
node-connect
352.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
claude-opus-4-5-migration
111.1kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
frontend-design
111.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Hook Development
111.1kThis skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.
