adachsoft / codegen-file-list
Execute ordered code-generation file operations with optional AI-assisted edits and implementation.
Requires
- php: ^8.3
- adachsoft/ai-agent: ^0.13
- adachsoft/ai-agent-config-repository: ^0.6
- adachsoft/ai-agent-factory: ^0.3
- adachsoft/ai-file-tool: ^0.5
- adachsoft/ai-tool-call: ^2.0
- adachsoft/codegen-core: ^0.1
- adachsoft/collection: ^3.0
- adachsoft/command-executor-lib: ^2.4
- adachsoft/file-content-tool: ^0.1
- adachsoft/file-edit-tool: ^0.1
- adachsoft/filesystem: ^1.4
- adachsoft/phpunit-runner-lib: ^0.2
- adachsoft/phpunit-runner-tool: ^0.5
Requires (Dev)
- adachsoft/php-code-style: ^0.7.3
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13.4
- rector/rector: ^2.8
- symplify/phpstan-rules: ^14.19
- vlucas/phpdotenv: ^5.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-23 18:00:48 UTC
README
adachsoft/codegen-file-list executes an ordered list of file operations in a project directory. Deterministic operations are handled by adachsoft/codegen-core; edit and implement use an AI agent with tools sandboxed to the configured project root.
Security warning (0.1.x): use only with trusted instructions and in a disposable working copy. In this version the
editandimplementagent:
- can write and delete any file in the project root except the configured forbidden files; the restriction to one class and its test exists only in the prompt;
- runs the unit tests it writes through PHPUnit on the host. That code runs as plain PHP with the permissions and environment of the calling process (including API keys in environment variables), outside the file-tool sandbox;
- is not protected by any instruction gate or output review; off-topic or malicious instructions are passed to the model as they are.
Do not pass instructions from untrusted sources (user input, content generated by other models without review) and do not run it where the process environment holds secrets. Operation-scoped tools, a restricted test process, capability checks and decision-model gates are planned for 0.2.0.
Requirements and installation
- PHP 8.3 or later
- A working PHPUnit executable for the project in
basePath - An AI provider and model for
editandimplementoperations
Install the package with Composer:
composer require adachsoft/codegen-file-list
Agent configuration
CodegenFileListConfigDto provides these limits for the standard agent created by CodegenFileListExecutorFactory::create():
| Field | Default | Behavior |
|---|---|---|
agentMaxSteps | 40 | Maximum number of agent steps per run. |
agentMaxToolCallsPerTurn | 10 | Maximum tool calls in each agent turn. Excess calls are rejected while the run continues. |
agentTimeoutSeconds | 900 | Maximum agent run duration in seconds. |
createFromDefinition() uses the consumer-provided AgentDefinitionDto unchanged, including its agent policies. These three configuration values do not override the policies supplied in that definition.
Usage
<?php
declare(strict_types=1);
use AdachSoft\CodegenCore\Collection\CodegenSourceCollection;
use AdachSoft\CodegenCore\Plan\CodegenPlanParser;
use AdachSoft\CodegenFileList\CodegenFileListExecutorFactory;
use AdachSoft\CodegenFileList\Dto\CodegenFileListConfigDto;
$planJson = <<<'JSON'
{
"version": "1.0",
"operations": [
{
"id": "create-note",
"path": "notes/summary.txt",
"action": "new",
"arguments": { "content": "Generated summary" }
},
{
"id": "edit-service",
"path": "src/Service.php",
"action": "edit",
"arguments": { "instruction": "Add the requested method and update its unit test." }
}
]
}
JSON;
$plan = (new CodegenPlanParser())->parseJson($planJson);
$executor = (new CodegenFileListExecutorFactory())->create(
new CodegenFileListConfigDto(basePath: __DIR__),
providerId: 'your-provider-id',
modelId: 'your-model-id',
apiKey: $_ENV['AI_API_KEY'] ?? '',
additionalSources: new CodegenSourceCollection([]),
);
$report = $executor->execute($plan);
foreach ($report->operations as $operation) {
printf("%s: %s\n", $operation->operationId, $operation->status->value);
}
if ($report->finalTestRun !== null) {
printf("Final tests: %s (%s)\n", $report->finalTestRun->passed ? 'passed' : 'failed', $report->finalTestRun->summary);
}
CodegenFileListExecutorFactory::create() builds a standard agent definition. Use createFromDefinition() to supply a complete AgentDefinitionDto; the consumer's model, system prompt, and toolIds are passed through unchanged. Both methods register the supported tool set, while the agent definition controls which tools the agent may call.
Operation format
A plan has a version and an ordered operations array. Each operation has an id, a project-relative path, an action, and optional arguments.
| Action | Arguments | Behavior and failure conditions |
|---|---|---|
remove | None | Deletes the file at path. Fails if the file does not exist. |
move | destination (string) | Moves the existing file at path. Fails if the source is missing or the destination already exists. |
copy | destination (string), optional overwrite (boolean, default false) | Copies the source file. Fails if the source is missing, or if the destination exists and overwrite is false. When overwrite is true, the destination content is replaced. |
new | content (string) | Creates a file at path. Fails if a file already exists there. |
edit | instruction (non-blank string) | Asks the agent to edit the existing class at path and update its unit test. The file must exist before and after the operation. |
implement | instruction (non-blank string) | Asks the agent to create a new class at path and write its unit test. The file must not exist before the operation and must exist afterward. |
Paths are relative to basePath and are validated by adachsoft/codegen-core.
Execution and reporting
Before changing files, the executor validates that every operation has a registered source. If any operation is unsupported, it throws UnsupportedOperationsException without applying changes.
Supported operations run in plan order. Each operation sees changes made by earlier operations. The first operation failure stops execution; that operation is reported as failed and later operations as skipped. There is no rollback, so earlier changes remain.
After every operation succeeds, the executor runs the full PHPUnit suite configured for basePath, using phpUnitPath and phpUnitTimeoutSeconds. The report contains:
operations: anOperationResultDtoCollectionin plan order;finalTestRun: aFinalTestRunDtowithpassedandsummary, ornullwhen an operation failed before the full test run;success:trueonly when every operation succeeded and the final test run passed.
A failing full test run leaves the operation statuses as succeeded, but sets finalTestRun->passed and report success to false.
Agent operations
The standard agent can use these nine tools:
file_read_singlefile_write_singlefile_deletefile_edit_fragmentfile_edit_linesfile_read_linesfile_read_rangefile_search_in_filephpunit_runner
All file tools and the PHPUnit tool are scoped to basePath. By default, the agent cannot read composer.lock or .env; it cannot write or delete composer.lock, .env, vendor/*, CHANGELOG.md, or changelog.json. File reads and writes are limited by maxFileSizeBytes (default: 75,536 bytes). The edit tools use base_dir; the other file tools receive base_path.
For edit and implement, the agent writes changes directly to the project filesystem. Those changes are not part of a generated file-change preview. The agent is instructed to write or update the changed class's unit test and to run only that class's unit tests with a PHPUnit filter. The executor then runs the full project suite after the complete operation list succeeds.
phpUnitPath must point to a working PHPUnit executable for the project in basePath. phpUnitTimeoutSeconds applies to both agent-invoked PHPUnit runs and the final full-suite run.
Extending operations
Pass consumer-defined SourceInterface implementations through additionalSources. These sources are registered before the built-in deterministic and agent sources, so a consumer source with an existing identifier takes precedence. The built-in sources are registered afterward in this order: remove, move, copy, new, edit, and implement.
End-to-end tests
The E2E suite calls the configured AI provider and is not part of the default test command. Copy .env.example to .env, fill in the provider credentials, then run:
composer test:e2e
The suite is skipped when any E2E credential is missing. Do not commit .env or real credentials.