PHPackages                             padosoft/laravel-rebel-ai-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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. padosoft/laravel-rebel-ai-guard

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

padosoft/laravel-rebel-ai-guard
===============================

Anomaly detection + AI security copilot for Laravel Rebel: deterministic rules detect anomaly cases; the optional AI only explains/suggests (sanitized prompts, no PII/OTP, human review). Part of padosoft/laravel-rebel-\*.

v0.1.2(1mo ago)0205↓90%2MITPHPPHP ^8.3CI passing

Since Jun 3Pushed 1mo agoCompare

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

READMEChangelog (3)Dependencies (9)Versions (8)Used By (2)

Laravel Rebel — AI Guard
========================

[](#laravel-rebel--ai-guard)

> Official documentation:

> **Deterministic anomaly detection, with an AI that explains — never decides.** Fixed rules open anomaly cases (e.g. OTP bombing) from your audit log; an optional LLM can then describe a case in plain language. The AI only ever sees **sanitized** prompts (no PII, no OTPs, no tokens) and its output is advisory — humans review, destructive actions stay manual. Part of the `padosoft/laravel-rebel-*` suite.

 [![Laravel Rebel](resources/screenshoots/Laravel-Rebel-banner.png)](resources/screenshoots/Laravel-Rebel-banner.png)

 [![Laravel 12|13](https://camo.githubusercontent.com/9e9b743bcbf97a29fe735334a4a8e906d05d60310969905af6607cef8da30138/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d313225323025374325323031332d4646324432303f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/9e9b743bcbf97a29fe735334a4a8e906d05d60310969905af6607cef8da30138/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d313225323025374325323031332d4646324432303f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c266c6f676f436f6c6f723d7768697465) [![PHP 8.3+](https://camo.githubusercontent.com/6aa777dd33ef43fbef727d8187b578003a61e5dc41bbc958b0938c996cdc92f2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e33253230253743253230382e34253230253743253230382e352d3737374242343f7374796c653d666c61742d737175617265266c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/6aa777dd33ef43fbef727d8187b578003a61e5dc41bbc958b0938c996cdc92f2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e33253230253743253230382e34253230253743253230382e352d3737374242343f7374796c653d666c61742d737175617265266c6f676f3d706870266c6f676f436f6c6f723d7768697465) [![PHPStan max](https://camo.githubusercontent.com/4b9a3c97d76534abb905e64bd9e5bb9f13fe68e962071e0ccbbe7b629112f11c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6d61782d3241364644423f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/4b9a3c97d76534abb905e64bd9e5bb9f13fe68e962071e0ccbbe7b629112f11c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6d61782d3241364644423f7374796c653d666c61742d737175617265) [![Pest 4](https://camo.githubusercontent.com/9b9da1d7d243a7465ab338e9374e47300a7fe2e26b5c291e7e3c95b53153789a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d50657374253230342d3232433535453f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/9b9da1d7d243a7465ab338e9374e47300a7fe2e26b5c291e7e3c95b53153789a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d50657374253230342d3232433535453f7374796c653d666c61742d737175617265) [![AI explains](https://camo.githubusercontent.com/8ae1c5798fbe5a3501969f1dc59ef0ce9ccc41dfd9de14e731b963bdf76a5320/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f41492d6578706c61696e732532432532306e65766572253230646563696465732d3842354346363f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/8ae1c5798fbe5a3501969f1dc59ef0ce9ccc41dfd9de14e731b963bdf76a5320/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f41492d6578706c61696e732532432532306e65766572253230646563696465732d3842354346363f7374796c653d666c61742d737175617265) [![MIT](https://camo.githubusercontent.com/ac049ef4e7a0b7196b09add6ac2d4f180e544c0ac779c2b2ac2fd2723a209579/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/ac049ef4e7a0b7196b09add6ac2d4f180e544c0ac779c2b2ac2fd2723a209579/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75653f7374796c653d666c61742d737175617265)

---

Table of contents
-----------------

[](#table-of-contents)

- [What it is](#what-it-is)
- [The golden rule](#the-golden-rule)
- [Why this package](#why-this-package)
- [Rebel AI Guard vs the alternatives](#rebel-ai-guard-vs-the-alternatives)
- [Installation](#installation)
- [Usage](#usage)
- [Security notes](#security-notes)
- [`.env.example`](#envexample)
- [Testing &amp; License](#testing--license)

---

What it is
----------

[](#what-it-is)

Two things, deliberately separated:

1. **Deterministic anomaly detection** — `AnomalyDetector` scans `rebel_auth_events` and opens **anomaly cases** from fixed, auditable rules (v0.1.0: OTP bombing; more rules to come). No black box decides anything.
2. **An AI explainer (optional)** — `AiExplainer` can ask an LLM you provide to *describe* a case for an operator. It is advisory only, sees only sanitized input, and is absent unless you bind an `AiClient`.

Depends on [`padosoft/laravel-rebel-core`](https://github.com/padosoft/laravel-rebel-core).

---

The golden rule
---------------

[](#the-golden-rule)

> **The rules decide. The AI explains. Humans approve anything destructive.**

The AI never opens, closes, or mitigates a case. It turns a case's signals into a sentence. Everything that *acts* is deterministic and auditable.

---

Why this package
----------------

[](#why-this-package)

★WhatIn short★★★**Deterministic, auditable detection**Cases come from fixed rules you can read and test — not a model's whim.★★★**AI input is sanitized**Emails, phones, OTP/digit runs (incl. Unicode) and Bearer/Basic/JWT/key tokens are scrubbed before any prompt leaves the app.★★★**AI is advisory + injection-resistant**The system prompt forbids deciding and treats case data as opaque (no prompt injection).★★**Optional AI**No `AiClient` bound? Detection still works; the explainer just returns null.★★**Idempotent + tenant-aware**Cases de-duplicate by a stable key; re-runs update in place; rows are tenant-scoped.★★**Bring your own model**Bind OpenAI, Anthropic, or a local model behind a one-method contract.---

Rebel AI Guard vs the alternatives
----------------------------------

[](#rebel-ai-guard-vs-the-alternatives)

Capability**Rebel AI Guard**Shopify"AI fraud" black boxesDIY log scriptsDeterministic, testable rules you own✅❌❌➖AI **explains**, never decides✅❌❌n/aPrompt sanitization (no PII/secret leak to LLM)✅❌❌n/aPrompt-injection-resistant system prompt✅❌➖n/aWorks with NO AI configured✅➖❌✅Idempotent, de-duplicated cases✅➖➖❌Self-hosted over your own audit log✅❌❌✅Tenant-aware + audit-native (your app)✅❌❌❌> Legend: ✅ built-in · ➖ partial / hosted-only / not exposed to you · ❌ not available.
>
> Note: Shopify is a hosted, closed commerce platform — it runs its own opaque fraud scoring on its checkout, but never gives you a deterministic anomaly engine, a sanitized explain-not-decide AI, or rules you can read, test, and self-host over your own audit log.

---

Installation
------------

[](#installation)

```
composer require padosoft/laravel-rebel-ai-guard
php artisan vendor:publish --tag="rebel-ai-guard-migrations"
php artisan migrate
```

---

Usage
-----

[](#usage)

**Detection runs automatically.** Out of the box the package schedules the `rebel:detect-anomalies` command **hourly**, so anomaly cases appear in your admin panel on their own — you don't have to call the detector. The cadence is fully configurable (see [Scheduling](#scheduling)). Just make sure Laravel's scheduler is running (`* * * * * php artisan schedule:run` in cron, as usual).

You can also run it by hand at any time:

```
php artisan rebel:detect-anomalies               # scans the last 1440 min (config default)
php artisan rebel:detect-anomalies --lookback=60 # scan only the last hour
php artisan rebel:detect-anomalies \
  --from="2026-06-01T00:00:00" --to="2026-06-01T06:00:00" # explicit window
```

**Or call the detector directly** (e.g. from your own job):

```
use Padosoft\Rebel\AiGuard\Detection\AnomalyDetector;

$opened = app(AnomalyDetector::class)->detect(
    now()->subHour(),
    now(),
); // returns how many cases were opened/updated
```

### Scheduling

[](#scheduling)

Config keyEnvDefaultEffect`detect.schedule``REBEL_AIGUARD_SCHEDULE``true`Auto-register the schedule. Set `false` to opt out and wire your own.`detect.frequency``REBEL_AIGUARD_FREQUENCY``hourly`How often the scheduled command runs. A whitelisted cadence name **or** a raw cron expression.`detect.lookback_minutes``REBEL_AIGUARD_LOOKBACK``1440`Default scan window (minutes, ending "now"). The scheduled run passes this explicitly; `--lookback`/`--from`/`--to` override per manual run.The schedule is only registered in console context, so it never affects HTTP requests.

**Frequency** accepts either a whitelisted cadence name or a raw 5-field cron expression:

- Cadence names: `everyMinute`, `everyTwoMinutes`, `everyThreeMinutes`, `everyFourMinutes`, `everyFiveMinutes`, `everyTenMinutes`, `everyFifteenMinutes`, `everyThirtyMinutes`, `hourly`, `daily`, `weekly`, `monthly`, `quarterly`, `yearly` (case-insensitive).
- Cron expression: anything that looks like `*/15 * * * *` is applied via the scheduler's `->cron()`. Only whitelisted names are ever called as methods — an unrecognised value that is not a valid cron expression falls back to `hourly` (it never calls an arbitrary method).

```
REBEL_AIGUARD_FREQUENCY=everyFifteenMinutes   # cadence name
# REBEL_AIGUARD_FREQUENCY="*/15 9-17 * * 1-5" # or a raw cron (every 15 min, 9-17, Mon-Fri)
```

#### Running over an explicit window (`--from` / `--to`) and simulating cron

[](#running-over-an-explicit-window---from----to-and-simulating-cron)

`--lookback=` scans a window ending "now". For a precise window, pass ISO-8601 `--from` and `--to` (when both are given they override `--lookback`; if you pass only `--from`, `--to` defaults to "now"). Invalid datetimes — or a `--to` that is not after `--from` — print an error and exit non-zero.

```
# Simulate the hourly cron run for a specific past hour:
php artisan rebel:detect-anomalies \
  --from="2026-06-01T09:00:00" --to="2026-06-01T10:00:00"

# Backfill a whole day in one shot:
php artisan rebel:detect-anomalies \
  --from="2026-06-01T00:00:00" --to="2026-06-02T00:00:00"

# From a point in time until "now":
php artisan rebel:detect-anomalies --from="2026-06-01T00:00:00"
```

Because the scheduled invocation simply runs `rebel:detect-anomalies --lookback=`, a manual run with the same window behaves identically to the cron run.

**Explain a case** (optional AI):

```
use Padosoft\Rebel\AiGuard\AiExplainer;
use Padosoft\Rebel\AiGuard\Models\AnomalyCase;

$explainer = app(AiExplainer::class);
$case = AnomalyCase::query()->findOrFail($id);

$text = $explainer->explain($case); // null if no AiClient is bound
```

**Bring your own model** — implement and bind the contract:

```
use Padosoft\Rebel\AiGuard\Contracts\AiClient;

$this->app->singleton(AiClient::class, MyOpenAiClient::class);
```

---

Security notes
--------------

[](#security-notes)

- **No PII/secret to the LLM**: `PromptSanitizer` scrubs emails, phone numbers, 4+ digit runs (incl. Unicode), and Bearer/Basic/JWT/`sk-`/`ghp_`/`xox*` tokens before sending.
- **No decisions by AI**: the system prompt forbids deciding/recommending destructive actions and instructs the model to treat case data as opaque (prompt-injection resistant).
- **Deterministic core**: cases come from fixed rules; the audit log already stores only HMAC'd identifiers, so cases carry hashes, not raw PII.
- **Tenant-scoped, idempotent**: re-running the detector updates open cases instead of duplicating them.

---

`.env.example`
--------------

[](#envexample)

```
REBEL_AIGUARD_OTP_BOMBING_THRESHOLD=10
REBEL_AIGUARD_SCHEDULE=true
REBEL_AIGUARD_FREQUENCY=hourly
REBEL_AIGUARD_LOOKBACK=1440
```

---

🔋 Vibe coding with batteries included
-------------------------------------

[](#-vibe-coding-with-batteries-included)

This package ships **AI batteries** — so you (and your AI agent) can extend it correctly on the first try:

- **`CLAUDE.md`** — a concise AI working guide (purpose, conventions, architecture, how to extend, Definition of Done). Plain Markdown, so Claude Code, Cursor, Copilot and Codex all read it.
- **`AGENTS.md`** — the agent/workflow contract (branch → PR → CI → tag/release, the gates).
- **`.claude/skills/`** — invocable skills (at least `rebel-package-dev`) encoding the suite's TDD loop, the **PHPStan-level-max** recipes, the security/telemetry rules, and the release discipline.

Open the repo in your AI editor and just start — the rules, guardrails and extension recipes come with it. PRs that follow the shipped `CLAUDE.md` pass CI (PHPStan max + Pest + Pint) and review the first time around.

---

Testing &amp; License
---------------------

[](#testing--license)

```
composer test      # Pest (detection, idempotency, severity, sanitizer, AI explainer)
composer phpstan   # static analysis, level max
composer pint      # code style
```

**License:** MIT — see [LICENSE](LICENSE). Part of the [`padosoft/laravel-rebel`](https://github.com/padosoft) suite.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance91

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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

Every ~0 days

Total

3

Last Release

51d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10467699?v=4)[Lorenzo](/maintainers/lopadova)[@lopadova](https://github.com/lopadova)

---

Top Contributors

[![lopadova](https://avatars.githubusercontent.com/u/10467699?v=4)](https://github.com/lopadova "lopadova (8 commits)")

---

Tags

laravelsecurityAuthenticationpadosoftRebel

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/padosoft-laravel-rebel-ai-guard/health.svg)

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

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k102.4M1.5k](/packages/spatie-laravel-permission)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

813336.8k3](/packages/defstudio-telegraph)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

45955.7k](/packages/harris21-laravel-fuse)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.8k](/packages/rawilk-profile-filament-plugin)[masterix21/laravel-licensing

Laravel licensing package with polymorphic assignment to any model, activation keys, expirations/renewals, and seat control via LicenseUsage. Supports offline verification with public-key–signed tokens, a CLI to generate/rotate/revoke keys, and an extensible architecture via config and contracts.

1613.3k4](/packages/masterix21-laravel-licensing)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5022.6k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

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