self-heallm / php-self-heallm
Framework-agnostic PHP library for automated error triage and LLM-powered self-healing.
Requires
- php: ^8.2
- ext-json: *
- ext-mbstring: *
- symfony/console: ^6.4|^7.0
- symfony/http-client: ^6.4|^7.0
Requires (Dev)
- phpunit/phpunit: ^10.5|^11.0
README
Packagist (self-heallm/php-self-heallm)
GitHub (universe-coder/php-self-heallm)
Canonical repository URLs are in composer.json (homepage, support). The Composer package name on Packagist remains self-heallm/php-self-heallm.
Framework-agnostic PHP Composer library that scans recent log errors, asks an LLM for a fix (OpenAI, Anthropic, Hugging Face OpenAI-compatible endpoint, or Ollama), validates path safety, optionally applies patches, and sends reports (Telegram, Slack, webhook, Sentry, JSONL file).
Install
composer require self-heallm/php-self-heallm
CLI
From your project root (with config/self-heal.php or env vars):
vendor/bin/self-heal
Or pass an explicit config path:
vendor/bin/self-heal --config=/absolute/path/to/self-heal.php
Copy config/self-heal.php into your app and adjust paths under log, reporting, and deduplication defaults (package defaults use <package>/var/... when shipped alone).
Programmatic use
use SelfHealLM\Bootstrap\SelfHealApplication; $pipeline = SelfHealApplication::fromConfigFile(__DIR__ . '/config/self-heal.php'); $result = $pipeline->run(); // ['status' => 'ok'|'skipped', 'reason' => ...?]
Or build config in memory:
$pipeline = SelfHealApplication::fromConfigArray([ 'enabled' => true, 'dry_run' => true, 'log' => ['path' => '/var/log/app.log', 'max_lines' => 200], // ... same keys as in config/self-heal.php (no outer `self-heal` key required) ]);
Environment variables
Same SELF_HEAL_* names as the Laravel-oriented package; see config/self-heal.php for the full list. Set SELF_HEAL_OPENAI_TOKEN, SELF_HEAL_LOG_PATH, etc., in your process environment or .env loader before including the config file.
Security
- Only paths under configured
allowed_pathsare accepted;forbidden_pathsalways win. - Auto-apply runs only when
enabled,auto_apply, anddry_runare set accordingly in config.
Related
The laravel-self-heallm package targets Laravel apps; this library is suitable for any PHP runtime with Composer.
License
MIT. See LICENSE.