Search by

adachsoft / codegen-file-list

Arkadiusz Adach

Execute ordered code-generation file operations with optional AI-assisted edits and implementation.

Package info

gitlab.com/a.adach/codegen-file-list

Issues

pkg:composer/adachsoft/codegen-file-list

Statistics

Installs: 8

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.1 2026-11-23 19:00 UTC

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 edit and implement agent:

  • 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 edit and implement operations

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():

FieldDefaultBehavior
agentMaxSteps40Maximum number of agent steps per run.
agentMaxToolCallsPerTurn10Maximum tool calls in each agent turn. Excess calls are rejected while the run continues.
agentTimeoutSeconds900Maximum 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.

ActionArgumentsBehavior and failure conditions
removeNoneDeletes the file at path. Fails if the file does not exist.
movedestination (string)Moves the existing file at path. Fails if the source is missing or the destination already exists.
copydestination (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.
newcontent (string)Creates a file at path. Fails if a file already exists there.
editinstruction (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.
implementinstruction (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: an OperationResultDtoCollection in plan order;
  • finalTestRun: a FinalTestRunDto with passed and summary, or null when an operation failed before the full test run;
  • success: true only 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_single
  • file_write_single
  • file_delete
  • file_edit_fragment
  • file_edit_lines
  • file_read_lines
  • file_read_range
  • file_search_in_file
  • phpunit_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.