freelygive / ai-diff
A package to support AI generated code diffs, inspired by Aider's edit formats.
1.0.0-beta2
2025-06-13 12:13 UTC
Requires
- php: ^8.3
Requires (Dev)
- acquia/coding-standards: ^3.0
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpunit/phpunit: ^12.2
This package is auto-updated.
Last update: 2025-06-13 11:20:28 UTC
README
A PHP library for parsing and applying AI friendly diffs. Inspired by Aider edit formats.
Features
- Parse and validate a diff
- Apply a parsed diff to original content
Supported diffs
Installation
composer require freelyive/ai-diff
Usage
use FreelyGive\AiDiff\Format\Udiff;
$diff = (new Udiff())->parse($diff_from_ai);
// Handle new files.
if ($diff->from === NULL) {
add_file(
filename: $diff->to,
contents: $diff->chunks[0]->getAfter(),
);
}
// Handle removed files.
elseif ($diff->to === NULL) {
remove_file(
filename: $diff->from,
);
}
// Handle updating files.
else {
update_file(
filename: $diff->from,
new_filename: $diff->to,
content: $diff->applyTo($original_content),
);
}