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

๐Ÿ‡จ๐Ÿ‡ณ ็ฎ€ไฝ“ไธญๆ–‡


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.1.tar.gz (51.4 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.1-py3-none-any.whl (65.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pattern8-0.3.1.tar.gz
  • Upload date:
  • Size: 51.4 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.1.tar.gz
Algorithm Hash digest
SHA256 d79d7e2510e4b7ac99ce7d8b23df1f3822c33ca5944706157c4007684b94d652
MD5 4a11164ffbd826e8d25c90d4a8ad0267
BLAKE2b-256 2a35aa6a8ae43331b11381f2a6ed89b0d6757242d55d1b6c3c90f12d147471f2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pattern8-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 65.7 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e78cda524c106262524af5f15bfa3e588aed2d6b0f298fd04b11366f6f6da9f5
MD5 2600c6ae1a09e8c368a982d35d11245b
BLAKE2b-256 3395b0b4cadd53255ce2765165903569b66c35821233eaaf9caceb5af641fab3

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