SkillAgentSearch skills...

Pattern8

๐ŸŽฑ AI Agent Governance Framework โ€” Constrain how AI Agents behave in your project. pip install pattern8

Install / Use

/learn @Aquifer-sea/Pattern8
About this skill

Quality Score

0/100

Supported Platforms

Claude Code
Claude Desktop
Cursor
Gemini CLI

README

<div align="center">

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."

PyPI version Python CI Coverage License: MIT

๐Ÿ‡จ๐Ÿ‡ณ ็ฎ€ไฝ“ไธญๆ–‡ ยท Architecture (ๆบ็ ๅฏผ่ฏป)

</div>

Table of Contents


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 -rf by 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 zh generates 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

View on GitHub
GitHub Stars83
CategoryDevelopment
Updated1d ago
Forks5

Languages

Python

Security Score

100/100

Audited on Apr 7, 2026

No findings