corexhubhq/ai-coding-guard

There is no license information available for the latest version (v0.1-beta) of this package.

AI coding guardrail for Laravel

Maintainers

Package info

github.com/corexhubhq/ai-coding-guard

pkg:composer/corexhubhq/ai-coding-guard

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1-beta 2026-05-05 16:05 UTC

This package is auto-updated.

Last update: 2026-05-05 16:11:20 UTC


README

A lightweight guardrail layer that forces AI coding agents to think, predict, validate, and learn before applying any code change.

This package helps you safely integrate AI (Claude, GPT, etc.) into your Laravel workflow by enforcing:

  • Hypothesis-driven changes (no blind edits)
  • Structured change manifests
  • Automated evaluation (prediction vs reality)
  • Safe rollback on failure
  • Incremental learning via memory

โœจ Features

  • ๐Ÿง  System Prompt Builder โ€” enforce disciplined AI behavior
  • ๐Ÿ›ก๏ธ Manifest Validator โ€” reject vague or unsafe changes
  • ๐Ÿงช Evaluator โ€” compare prediction vs actual result
  • ๐Ÿ” Automatic Rollback โ€” revert failed changes instantly
  • ๐Ÿ“š Long-term Memory โ€” store lessons from success/failure
  • ๐Ÿ–ฅ๏ธ CLI Command (ai-coding-guard:run) โ€” run AI changes safely

Requirements

  • PHP >= 8.0
  • Laravel >= 11.0

๐Ÿ“ฆ Installation

Install via Composer:

composer require corexhubhq/ai-coding-guard

The package will auto-register via Laravel's package discovery and includes default implementations โ€” ready to use immediately!

โš™๏ธ Configuration

Publish the configuration file (optional):

php artisan vendor:publish --tag=ai-coding-guard-config

This creates config/ai-coding-guard.php:

return [
    'memory_path' => storage_path('ai-coding-guard/memory.json'),
    'backup_path' => storage_path('ai-coding-guard/last_changes.json'),
    'rollback_strategy' => 'patch', // patch | git | file
    'auto_create_storage' => true,
];

Storage directories are created automatically on first run.

๐ŸŽฏ Default Implementations

The package includes ready-to-use implementations:

GitPatchApplier

  • Applies code changes using git apply
  • Creates automatic backups before applying
  • Supports rollback to previous state
  • Requires: Git installed

PHPUnitTestRunner

  • Runs PHPUnit tests automatically
  • Parses test results with detailed output
  • Falls back gracefully if PHPUnit is not available

No additional setup needed โ€” just install and run!

๐Ÿ”Œ Custom Implementations (Optional)

Want to customize? You can override the default implementations:

Custom Code Applier

namespace App\AICodingGuard;

use AICodingGuard\Contracts\CodeApplierInterface;

class MyCustomApplier implements CodeApplierInterface
{
    public function apply(string $diff): void
    {
        // Your custom logic
    }

    public function rollback(): void
    {
        // Your rollback logic
    }
}

Custom Test Runner

namespace App\AICodingGuard;

use AICodingGuard\Contracts\TestRunnerInterface;

class MyCustomTestRunner implements TestRunnerInterface
{
    public function run(): array
    {
        // Run your tests
        return [
            'test_pass' => true,
            'output' => '...',
        ];
    }
}

Bind Custom Implementations

In your AppServiceProvider:

use AICodingGuard\Contracts\CodeApplierInterface;
use AICodingGuard\Contracts\TestRunnerInterface;
use App\AICodingGuard\MyCustomApplier;
use App\AICodingGuard\MyCustomTestRunner;

public function register()
{
    $this->app->bind(CodeApplierInterface::class, MyCustomApplier::class);
    $this->app->bind(TestRunnerInterface::class, MyCustomTestRunner::class);
}

๐Ÿš€ Usage

Prepare AI response (JSON)

Example: storage/ai-coding-guard/input.json

{
  "CHANGE_MANIFEST": {
    "evidence": "API response slow (~2s)",
    "root_cause": "missing index on user_id",
    "fix": "add index on user_id column",
    "prediction": {
      "response_time": 500,
      "test_pass": true,
      "risk_level": "low"
    }
  },
  "CODE_DIFF": "--- a/app/Models/User.php\n+++ b/app/Models/User.php\n@@ ..."
}

Run AI safely

php artisan ai-coding-guard:run --file=storage/ai-coding-guard/input.json

Other options

Dry run (no changes applied)

php artisan ai-coding-guard:run --file=storage/ai-coding-guard/input.json --dry

Skip test (debug only)

php artisan ai-coding-guard:run --file=storage/ai-coding-guard/input.json --no-test

Pipe input (advanced)

cat response.json | php artisan ai-coding-guard:run

๐Ÿ” Workflow

AI โ†’ CHANGE_MANIFEST โ†’ Validator โ†’ Apply โ†’ Test โ†’ Evaluate
                                      โ†“
                             PASS โ†’ Save memory
                             FAIL โ†’ Rollback + Save lesson

๐Ÿง  Memory System

Stored at:

storage/ai-coding-guard/memory.json

Example:

{
  "lessons": [
    {
      "type": "fail",
      "manifest": { ... },
      "actual": { ... }
    },
    {
      "type": "success",
      "manifest": { ... }
    }
  ]
}

โš ๏ธ Important Rules

1. Prediction must be measurable

โŒ Bad:

"expected_result": "faster response"

โœ… Good:

{
  "response_time": 500,
  "test_pass": true
}

2. Always use clean git working tree

git status

3. Keep changes small

  • Avoid multi-file refactors
  • Prefer minimal diffs

๐Ÿ”’ Safety Model

  • No manifest โ†’ โŒ reject
  • Weak reasoning โ†’ โŒ reject
  • Prediction mismatch โ†’ ๐Ÿ” rollback
  • Exception โ†’ ๐Ÿ” rollback

๐Ÿงฉ Extending

You can extend the system by:

  • Custom Evaluator logic
  • Advanced TestRunner (performance, API checks)
  • Memory filtering / pruning
  • CI/CD integration

๐Ÿš€ Roadmap Ideas

  • ai-coding-guard:ask โ€” call AI API directly
  • Auto retry loop (AHE cycle)
  • Patch validator
  • Prediction schema enforcement
  • Interactive approval mode

๐Ÿ’ก Philosophy

This package is not an AI tool.

It is a discipline layer that forces AI to behave like a real engineer:

Hypothesis โ†’ Prediction โ†’ Experiment โ†’ Evaluation โ†’ Learning

๐Ÿ“„ License

MIT