hakhant / laravel-ai-context
Machine-readable codebase context for AI assistants, with safe-refactor tooling for Laravel projects.
v1.0.2
2026-12-03 07:31 UTC
Requires
- php: ^8.2
- illuminate/console: ^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/filesystem: ^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0|^13.0
- symfony/process: ^5.4|^6.0|^7.0
Requires (Dev)
- laravel/pint: ^1.0
- orchestra/testbench: ^7.0|^9.0|^10.0|^11.0
- phpunit/phpunit: ^10.5|^11.0
- symfony/console: >=6.4 <7.4
- symfony/string: ^7.2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
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
This is a development tool. Install it with --dev so it is not pulled into production:
composer require --dev 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