Search by

hakhant / laravel-ai-context

hakhant21

Machine-readable codebase context for AI assistants, with safe-refactor tooling for Laravel projects.

Package info

github.com/hakhant21/ai-context

pkg:composer/hakhant/laravel-ai-context

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.2 2026-12-03 07:31 UTC

This package is auto-updated.

Last update: 2026-12-03 07:31:44 UTC


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:fix is dry-run by default. --apply runs git apply --recount, lints every touched PHP file, and reverts via git 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 to routes,jobs,events from config) makes ai:diff exit 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