Skip to main content

Pattern 8 (P8) โ€” AI Agent Governance Framework

Project description

Pattern 8 (P8)

Zero-Trust Governance Framework to stop AI Agents from hallucinating, breaking things, and bypassing your rules.

"Your prompt is merely a suggestion. P8 is the law."

PyPI version Python CI Coverage License: MIT

๐Ÿ“š Read the Docs โ€ข ๐Ÿ’ฌ Join Discord โ€ข ๐Ÿฆ Twitter โ€ข ๐Ÿ‡จ๐Ÿ‡ณ ็ฎ€ไฝ“ไธญๆ–‡

P8 intercepts dangerous agent command

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

๐Ÿš” 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 Golden SKILLs

P8 comes with 5 industrial-grade developer SKILLs out of the box. Don't just code. Engineer.

๐Ÿ“ PRD (skills/prd/)

Don't just build. Think first. Forces the agent to gather requirements and generate a structured Product Requirements Document before writing a single line of logic.

๐Ÿ› Bug Fix (skills/bug_fix/)

Find the root cause, or don't fix it at all. Forces the agent through a strict 4-step golden path: Reproduce โ†’ Root Cause Analysis โ†’ Fix โ†’ Regression Test.

๐Ÿ”’ Code Review (skills/code_review/)

Never merge unreviewed AI slop. The agent must submit its changes to the Reviewer engine. If the code fails security, performance, or correctness guidelines, the engine throws a P8_AUDIT_FAILED error, forcing the agent to retry and fix its own mess (up to 3 times) before presenting it to you.

๐Ÿ—๏ธ Refactor (skills/refactor/)

Change structure, not behavior. Forces the agent to guarantee functional equivalence test-passes after moving code around.

๐Ÿš€ Feature Dev (skills/feature_dev/)

End-to-end delivery. Requirements โ†’ Technical Design โ†’ Implementation โ†’ Unit Tests.


๐Ÿ› ๏ธ CLI Reference

p8 init [target]                # Initialize P8 and generate the 5 default SKILLs
p8 list                         # List all available SKILLs in the current project
p8 validate <skill_path>        # Validate SKILL file integrity (run after editing)
p8 new <skill_name>             # Create a scaffold for a new custom SKILL

๐Ÿ”Œ Connect to Cursor / Windsurf / Claude Desktop

To turn on the active "Police" enforcement engine, install the MCP extension:

# Full install with MCP server support
pip install 'pattern8[enforcement]'

# Generate MCP config for Cursor
p8 mcp-config --client cursor

Paste the output into .cursor/mcp.json. Now, every time the Cursor Agent tries to run a command or finish a task, it must pass through the P8 execute_tool and submit_review checkpoints.


๐Ÿค Contributing

We welcome completely new SKILLs! See CONTRIBUTING.md for architectural details and how to open a PR.

๐Ÿ“„ License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pattern8-0.3.0.tar.gz (51.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pattern8-0.3.0-py3-none-any.whl (65.9 kB view details)

Uploaded Python 3

File details

Details for the file pattern8-0.3.0.tar.gz.

File metadata

  • Download URL: pattern8-0.3.0.tar.gz
  • Upload date:
  • Size: 51.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for pattern8-0.3.0.tar.gz
Algorithm Hash digest
SHA256 968ae36af99fd8f5b7a6020a7c81202a456fae3991ce4aa717efa038af605a84
MD5 917efb50432d7590635701282a790a40
BLAKE2b-256 2cea608fa0d96755f6a5cfabcc16c0a2a6b47393289541bd6d3f2697899d6928

See more details on using hashes here.

File details

Details for the file pattern8-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pattern8-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 65.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for pattern8-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae129dbc3bdf2739328f09670fa400d8c641d17354cfda4bc103525579d9f6c8
MD5 2e6b8e5e2cbb9a2ddc8b92f764186422
BLAKE2b-256 893f63c5a63e1837d107c7a36fef5100c90df8e703e5a2a04b3b9d5c37f06400

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page