laravel-ai-context maintained by hakhant
laravel-ai-context
Machine-readable codebase context for AI assistants, plus deterministic safe-refactor tooling for Laravel projects. No LLM in the runtime path every command is fully deterministic.
Install
composer require hakhant/laravel-ai-context
php artisan vendor:publish --tag=ai-context-config
php artisan vendor:publish --tag=ai-context-docs # .ai/docs/*
php artisan vendor:publish --tag=ai-context-assistants # CLAUDE.md, AGENTS.md, cursor rule, copilot instructions
Quick start
php artisan ai:context # write .ai/generated/*
php artisan ai:context --check # CI drift check (exit 1 if stale)
php artisan ai:baseline main-current --force
php artisan ai:diff main-current --report
php artisan ai:cross-ref main-current --report
php artisan ai:fix main-current # dry-run → fix.patch + fix-report.md
php artisan ai:fix main-current --apply # git apply --recount + php -l gate + auto-revert
What gets generated (.ai/generated/)
| File | Contents |
|---|---|
routes.json / routes.md |
method / uri / name / action / middleware |
commands.json |
artisan list --format=json output |
events.json |
events → listeners (artisan event:list, filesystem fallback) |
jobs.json |
FQCN → file, traits, constructor payload, queue/connection/tries/timeout |
tree.txt |
sorted file list under the scan roots |
tree-hashes.json |
sha1 of every scanned file (used for drift, not mtimes) |
classes.json |
FQCN → kind, file, public methods |
config-keys.txt |
top-level config keys only — never values |
models.json |
model → table, fillable, methods, relationship kinds |
manifest.json |
generated_at, git commit, PHP/Laravel versions, sections, files |
Safety model
ai:fixis dry-run by default.--applyrunsgit apply --recount, lints every touched PHP file, and reverts viagit checkout --if any lint fails.--map="Old\\Fqcn=>New\\Fqcn"supplies manual renames; guessing otherwise uses exact short-name match, then a method-overlap heuristic (Jaccard ≥fix.overlap_threshold).--strict(defaults toroutes,jobs,eventsfrom config) makesai:diffexit 1 when a section loses or changes entries;--allow-change=exempts sections.
CI
Copy .github/workflows/ai-context.yml and .github/actions/ai-context/ into your app (they assume the package is installed): drift check on every push/PR, refactor guard with cross-reference gating on PRs, and an auto-refreshing baseline on pushes to main.
Testing
composer install
vendor/bin/phpunit