PHPackages                             corexhubhq/ai-coding-guard - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. corexhubhq/ai-coding-guard

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

corexhubhq/ai-coding-guard
==========================

AI coding guardrail for Laravel

v0.1-beta(1mo ago)11PHPPHP &gt;=8.0

Since May 5Pushed 1mo agoCompare

[ Source](https://github.com/corexhubhq/ai-coding-guard)[ Packagist](https://packagist.org/packages/corexhubhq/ai-coding-guard)[ RSS](/packages/corexhubhq-ai-coding-guard/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

AI Coding Guard (Laravel Package)
=================================

[](#ai-coding-guard-laravel-package)

> 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
==========

[](#-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
------------

[](#requirements)

- PHP &gt;= 8.0
- Laravel &gt;= 11.0

📦 Installation
==============

[](#-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
================

[](#️-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
=========================

[](#-default-implementations)

The package includes ready-to-use implementations:

GitPatchApplier
---------------

[](#gitpatchapplier)

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

PHPUnitTestRunner
-----------------

[](#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)
===================================

[](#-custom-implementations-optional)

Want to customize? You can override the default implementations:

Custom Code Applier
-------------------

[](#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
------------------

[](#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
---------------------------

[](#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
=======

[](#-usage)

Prepare AI response (JSON)
--------------------------

[](#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
-------------

[](#run-ai-safely)

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

---

Other options
-------------

[](#other-options)

### Dry run (no changes applied)

[](#dry-run-no-changes-applied)

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

---

### Skip test (debug only)

[](#skip-test-debug-only)

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

---

### Pipe input (advanced)

[](#pipe-input-advanced)

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

---

🔁 Workflow
==========

[](#-workflow)

```
AI → CHANGE_MANIFEST → Validator → Apply → Test → Evaluate
                                      ↓
                             PASS → Save memory
                             FAIL → Rollback + Save lesson

```

---

🧠 Memory System
===============

[](#-memory-system)

Stored at:

```
storage/ai-coding-guard/memory.json
```

### Example:

[](#example)

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

---

⚠️ Important Rules
==================

[](#️-important-rules)

### 1. Prediction must be measurable

[](#1-prediction-must-be-measurable)

❌ Bad:

```
"expected_result": "faster response"
```

✅ Good:

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

---

### 2. Always use clean git working tree

[](#2-always-use-clean-git-working-tree)

```
git status
```

---

### 3. Keep changes small

[](#3-keep-changes-small)

- Avoid multi-file refactors
- Prefer minimal diffs

---

🔒 Safety Model
==============

[](#-safety-model)

- No manifest → ❌ reject
- Weak reasoning → ❌ reject
- Prediction mismatch → 🔁 rollback
- Exception → 🔁 rollback

---

🧩 Extending
===========

[](#-extending)

You can extend the system by:

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

---

🚀 Roadmap Ideas
===============

[](#-roadmap-ideas)

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

---

💡 Philosophy
============

[](#-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
=========

[](#-license)

MIT

###  Health Score

33

—

LowBetter than 73% of packages

Maintenance93

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

35d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/911adac71bb41201b31b5cd6de683e1062f7fb65fde7eda68911a1ee65fe1ac0?d=identicon)[hidric197](/maintainers/hidric197)

---

Top Contributors

[![hidric197](https://avatars.githubusercontent.com/u/43696818?v=4)](https://github.com/hidric197 "hidric197 (2 commits)")

### Embed Badge

![Health badge](/badges/corexhubhq-ai-coding-guard/health.svg)

```
[![Health](https://phpackages.com/badges/corexhubhq-ai-coding-guard/health.svg)](https://phpackages.com/packages/corexhubhq-ai-coding-guard)
```

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

9782.1M153](/packages/laravel-ai)[illuminate/queue

The Illuminate Queue package.

20432.2M1.5k](/packages/illuminate-queue)[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[moonshine/moonshine

Laravel administration panel

1.3k239.9k72](/packages/moonshine-moonshine)[illuminate/session

The Illuminate Session package.

9938.5M818](/packages/illuminate-session)[tallstackui/tallstackui

TallStackUI is a powerful suite of Blade components that elevate your workflow of Livewire applications.

719160.4k12](/packages/tallstackui-tallstackui)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
