How I built mechanical enforcement for AI coding agents —…
    Neura MarketNeura Market/Perplexity
    ChatGPTChatGPTClaudeClaudeGeminiGeminiCursorCursorGrokGrokPerplexityPerplexityDeepSeekDeepSeek
    CoPilotCoPilotStable DiffusionStable DiffusionMidjourneyMidjourney
    View All Directories
    OverviewRulesPromptsMCPsAgentsGamesBlogVideosGuidesCoursesCommunityTrending
    PerplexityBlogHow I built mechanical enforcement for AI coding agents — and why prompts aren't enough
    Back to Blog
    How I built mechanical enforcement for AI coding agents — and why prompts aren't enough
    opensource

    How I built mechanical enforcement for AI coding agents — and why prompts aren't enough

    David Emilio Sierra Puentes June 25, 2026
    0 views

    I spent months watching AI coding agents produce impressive demos that couldn't survive...

    I spent months watching AI coding agents produce impressive demos that couldn't survive production.

    The code looked right. It compiled. It even passed the first test.

    Then it hit edge cases. Forgotten constraints. A rule the agent agreed to five minutes ago, now gone — overwritten by the next context window.

    The root cause wasn't capability. It was process.

    "A raw model is not an agent. It becomes one once a harness gives it state, tool execution, feedback loops, and enforceable constraints." — Osmani, Saboo & Kartakis, The New SDLC With Vibe Coding, 2026 [1]


    The problem: capable but undisciplined

    AI agents are brilliant at generating code. They have zero built-in discipline:

    • They commit without tests
    • They push without review
    • They overwrite each other's work
    • They produce output that looks correct but breaks silently

    A METR study (Becker et al., July 2025 [2]) found something counterintuitive: developers using AI took 19% longer while feeling 20% faster. The speed was an illusion. The debugging cost was real.

    The industry's response has been more skills, more prompts, bigger context windows. But the problem isn't intelligence — it's accountability.

    A rule that lives only in a prompt is a suggestion. An agent that "knows" the rules will eventually forget them. Context degrades. Attention drifts. The question isn't if your agent will break a rule — it's when.


    The insight: memory is not enforcement

    Three incidents in 48 hours taught me this lesson.

    My agent bypassed its own commit approval system in under 30 seconds. Not because it was malicious — because the "gate" was just another rule in a file. Another thing to remember. Another thing to forget.

    I had built a SHA256 token system for commit approval. Thought it was bulletproof. Then my agent ran with --auto and the tokens became theater.

    The fix wasn't a better token system. The fix was changing the architecture.

    Rules that depend on memory fail. Rules that depend on visible blocks succeed.

    This is the core insight behind mechanical enforcement: gates that run at the infrastructure level, not the agent level. The agent cannot bypass what it cannot ignore.


    The solution: Agent = Model + Harness

    I built this project as a complete open-source implementation of the Harness architecture [3] — the mechanical infrastructure that turns raw AI intelligence into reliable output.

    ComponentWhat It Is
    Instructions & RulesWho the agent is, what it cares about, what it must never do
    Tools57 composable skills loaded on demand (lazy-loaded, ~250 lines each)
    Sandboxes & ExecutionTerminal, git workspace, CI
    OrchestrationWhen each tool fires, how agents coordinate
    Guardrails & HooksDeterministic enforcement at lifecycle points — pre-commit, commit-msg, approval
    ObservabilityMetrics, health checks, drift detection

    What makes this different: Most "agent frameworks" are just prompt libraries. This one adds 12 mechanical pre-commit gates, a three-gate commit approval system, and a context engineering layer that saves ~45% of always-loaded tokens.


    The code: a commit-msg hook that can't be bypassed

    Here's the heart of mechanical enforcement — a commit-msg git hook (v6) [4] that blocks unstamped commits:

    #!/usr/bin/env bash
    # commit-msg — Three-Gate Approval Check (v6)
    set -euo pipefail
    
    REPO_ROOT=$(git rev-parse --show-toplevel)
    APPROVAL_FILE="${REPO_ROOT}/.git/COMMIT_APPROVED"
    MANIFEST_FILE="${REPO_ROOT}/.git/COMMIT_MANIFEST"
    TEST_LOG="${REPO_ROOT}/.git/TEST_LOG"
    CURRENT_MSG=$(head -1 "$COMMIT_MSG_FILE" | tr -d '\n')
    NOW_EPOCH=$(date +%s)
    
    # Gate 1: Tests passed recently?
    if [[ -f "$TEST_LOG" ]]; then
      STATUS=$(grep "^status=" "$TEST_LOG" | cut -d= -f2-)
      if [[ "$STATUS" == "PASS" ]]; then
        TS_EPOCH=$(date -d "$(grep "^timestamp=" "$TEST_LOG" | cut -d= -f2-)" +%s)
        AGE=$((NOW_EPOCH - TS_EPOCH))
        [ $AGE -le 3600 ] && GATE1=true
      fi
    fi
    
    # Gate 2: Commit manifest exists and has content?
    [[ -f "$MANIFEST_FILE" ]] && \
      [ $(wc -c < "$MANIFEST_FILE") -gt 20 ] && GATE2=true
    
    # Gate 3: Approval fresh (<5 min) and message matches?
    if [[ -f "$APPROVAL_FILE" ]]; then
      TIMESTAMP=$(grep "^timestamp=" "$APPROVAL_FILE" | cut -d= -f2-)
      STORED_MSG=$(grep "^message=" "$APPROVAL_FILE" | cut -d= -f2-)
      TS_EPOCH=$(date -d "$TIMESTAMP" +%s 2>/dev/null || echo 0)
      AGE=$((NOW_EPOCH - TS_EPOCH))
      [ $AGE -le 300 ] && [ "$STORED_MSG" = "$CURRENT_MSG" ] && GATE3=true
    fi
    
    # All three must pass
    if [ "$GATE1" = true ] && [ "$GATE2" = true ] && [ "$GATE3" = true ]; then
      echo "✓ All 3 gates passed. Commit allowed."
      exit 0
    else
      echo "✗ Commit blocked — missing gates:"
      [ "$GATE1" != true ] && echo "  - Tests not run or expired"
      [ "$GATE2" != true ] && echo "  - Commit manifest missing"
      [ "$GATE3" != true ] && echo "  - Approval missing or expired"
      exit 1
    fi
    

    Three conditions must be met before any commit goes through:

    1. Tests passed (within the last hour) — no blind commits
    2. Commit manifest exists (the agent writes what changed) — no silent mutations
    3. User approved (within 5 minutes, message matches) — no stale approvals

    The agent writes the approval file after the user says "yes commit" in chat. The hook verifies the file is fresh (<5 min) and matches the exact commit message. If the agent tries to commit without approval, the hook blocks it — every time.

    This isn't a rule the agent remembers. It's a gate the agent cannot bypass.


    The results: 57 skills, 12 gates, zero shortcuts

    After months of iteration, the project ships [5]:

    MetricCount
    Composable skills57
    Lazy-loaded guides54
    Pre-commit gates9 (v8) + 3 commit-msg gates
    Enforcement levels4 (process → manifest → time-window → manifest gate)
    Agent compatibilityOpenCode, Claude Code, Cursor, Kiro, any git agent [6]
    Context tokens saved~45% vs eager loading [7]
    Stack supportNode, Python, Rust, Go, Ruby, any language with git
    PriceFree (MIT)

    What I learned

    Prompts are instructions. Gates are guarantees.

    If you're building with AI agents, ask yourself:

    • Does your agent run tests before every commit? Mechanically, not as a suggestion?
    • Does your agent present changes for review before pushing? Every time, not just when it remembers?
    • Can your agent bypass its own rules? If yes, those aren't rules — they're suggestions.

    The gap between an "impressive demo" and "production-grade" isn't intelligence. It's the harness around it.


    Try it:

    git clone https://github.com/juandelossantos/another-agent-skills.git
    cd another-agent-skills
    bash install.sh
    init-agents   # Activates skill-driven mode in any project
    

    MIT. Free. Zero subscriptions. 57 skills. 12 gates.

    juandelossantos.github.io/another-agent-skills


    What patterns have you found for keeping AI agents disciplined in production? I'd love to hear what's working (or not working) in your stack.


    References

    1. <a id="ref1"></a> Osmani, A., Saboo, S., & Kartakis, S. (2026). The New SDLC With Vibe Coding: From ad-hoc prompting to Agentic Engineering. — Harness architecture paper
    2. <a id="ref2"></a> Becker, S. et al. (2025). When Developers Use AI: Productivity and Perception. METR (Model Evaluation and Threat Research). — arxiv.org/abs/2507.09089
    3. <a id="ref3"></a> Another Agent Skills. Harness Architecture — The Six Components. — docs/HARNESS.md
    4. <a id="ref4"></a> Another Agent Skills. commit-msg hook (v6) — Three-Gate Approval Check. — scripts/git-hooks/commit-msg
    5. <a id="ref5"></a> Another Agent Skills. Repository and Documentation. — github.com/juandelossantos/another-agent-skills
    6. <a id="ref6"></a> Another Agent Skills. Agent Adapters — Compatibility Matrix. — docs/AGENT-ADAPTERS.md
    7. <a id="ref7"></a> Another Agent Skills. Context Budget — Lazy Loading Architecture. — README.md
    8. <a id="ref8"></a> Singhal et al. (2026). Agent Skills: Evaluation-Driven Development for AI Coding Agents. Google Research. — Paper
    9. <a id="ref9"></a> Osmani, A. (2026). The Factory Model: From Conductors to Orchestrators. — addyosmani.com
    10. <a id="ref10"></a> Another Agent Skills. SOUL.md — Project Identity and Principles. — SOUL.md

    Tags

    opensourceaiproductivitytooling

    Comments

    More Blog

    View all
    Five Gemma-4 models, one accelerator: what porting E2B 31B to AWS Inferentia2 taught megemma

    Five Gemma-4 models, one accelerator: what porting E2B 31B to AWS Inferentia2 taught me

    I ported the whole Gemma-4 family — E2B, E4B, 12B, 31B, and the 26B-A4B MoE — to run on...

    X
    xbill
    Hey DEV, I'm Tobore. Let's actually connect.community

    Hey DEV, I'm Tobore. Let's actually connect.

    Hey DEV, I'm Tobore. Let's actually connect. I've been on here for a while now, mostly writing and...

    L
    Laurina Ayarah
    I burned through thousands of AI tokens. Then a friend did it for freeai

    I burned through thousands of AI tokens. Then a friend did it for free

    (yep, kinda clickbait, just for the funsies 😊) At the beginning of the year, I relaunched my...

    P
    Paulo Henrique
    Claude might be saturating your machineai

    Claude might be saturating your machine

    My laptop was sitting idle with the fan at full tilt. Nothing was running that I knew of. The culprit...

    S
    Sidhant Panda
    Automated GitHub Code Reviews Using Google Geminigithubactions

    Automated GitHub Code Reviews Using Google Gemini

    I Built a Thing! TL;DR — Google Gemini-based Pull Request reviews and Issue Triaging for...

    D
    Darren "Dazbo" Lester
    What is an "agentic harness," actually?ai

    What is an "agentic harness," actually?

    I've been hearing the word "harness" thrown around a lot lately. I assumed it just meant "the IDE" or...

    T
    Tilde A. Thurium

    Stay up to date

    Get the latest Perplexity prompts, rules, and resources delivered to your inbox weekly.

    Neura Market LogoNeura Market

    Discover the best AI prompts, plugins, and resources for Perplexity and more.

    Content Types

    • Rules
    • Prompts
    • MCPs
    • Agents
    • Guides

    Platforms

    • ChatGPT Directory
    • Claude Directory
    • Gemini Directory
    • Cursor Directory
    • Grok Directory
    • Perplexity Directory
    • DeepSeek Directory
    • CoPilot Directory
    • Stable Diffusion Directory
    • Midjourney Directory
    • All Directories

    Resources

    • Blog
    • Documentation
    • Help Center
    • Marketplace

    Legal

    • Privacy Policy
    • Terms of Service

    © 2026 Neura Market. All rights reserved.

    |

    Not affiliated with any AI platform vendors.

    Neura Market

    Custom AI Systems & Services

    Our team of experienced AI builders will help build custom AI systems, workflows, and solutions for your business.

    Request custom work

    Ready-made automations for this

    Workflows from the Neura Market marketplace related to this Perplexity resource

    • Automate SEO-Optimized Blog Creation with GPT-4, Perplexity AI & Multi-Language Supportn8n · $24.99 · Related topic
    • Automate SEO Blog Content Creation with GPT-4, Perplexity AI, and WordPressn8n · $24.99 · Related topic
    • Automate SEO Blog Creation + Social Media with GPT-4, Perplexity, and WordPressn8n · $24.99 · Related topic
    • Auto-Generate SEO Blog Posts with Perplexity, GPT, Leonardo & WordPressn8n · $14.99 · Related topic
    Browse all workflows