Search by

adachsoft / php-class-scoped-tools

Arkadiusz Adach

Class-scoped PHP source and unit test tools for AI agents.

Package info

gitlab.com/a.adach/php-class-scoped-tools

Issues

pkg:composer/adachsoft/php-class-scoped-tools

Statistics

Installs: 8

Dependents: 1

Suggesters: 0

Stars: 0

v0.1.0 2026-11-24 21:38 UTC

This package is auto-updated.

Last update: 2026-11-25 04:16:08 UTC


README

adachsoft/php-class-scoped-tools provides AI tools that let an agent inspect and edit one configured PHP class and its unit test at a time. Each tool is restricted to explicit project-relative paths under a configured base directory.

Capabilities

  • Read and edit a configured PHP class source file.
  • Read, edit, or create its unit test using a deterministic test skeleton.
  • Check a configured class and test for capabilities before requesting execution of that single test file.
  • Delegate test execution to a consumer-provided runner; the library does not execute PHPUnit itself.

Installation

composer require adachsoft/php-class-scoped-tools

Usage

Register tool factories and matching configuration maps with AiToolCallFacadeBuilder:

use AdachSoft\AiToolCall\PublicApi\Builder\AiToolCallFacadeBuilder;
use AdachSoft\AiToolCall\SPI\Collection\ConfigMap;
use AdachSoft\PhpClassScopedTools\ClassTestRunnerInterface;
use AdachSoft\PhpClassScopedTools\Factory\ClassSourceReadToolFactory;
use AdachSoft\PhpClassScopedTools\Factory\ClassTestRunToolFactory;

/** @var ClassTestRunnerInterface $isolatedTestRunner */
$facade = AiToolCallFacadeBuilder::new()
    ->withSpiFactories([
        new ClassSourceReadToolFactory(),
        new ClassTestRunToolFactory($isolatedTestRunner),
    ])
    ->withToolConfigs([
        'class_source_read' => new ConfigMap([
            'base_path' => '/workspace/project',
            'class_path' => 'src/Example.php',
        ]),
        'class_test_run' => new ConfigMap([
            'base_path' => '/workspace/project',
            'class_path' => 'src/Example.php',
            'test_path' => 'tests/Unit/ExampleTest.php',
            'allowed_capabilities' => [],
        ]),
    ])
    ->build();

Requirements

  • PHP 8.3 or later.
  • Composer for dependency installation.

Configuration

Each tool is registered with a ConfigMap keyed by its tool name. Supported keys are:

KeyRequired forDescription
base_pathAll toolsExisting project directory used as the filesystem boundary.
class_pathclass_source_read, class_source_edit, class_test_create, class_test_runRelative PHP class path.
test_pathclass_test_read, class_test_edit, class_test_create, class_test_runRelative PHP test path.
allow_createclass_source_editWhether editing may create the class file; defaults to false.
allowed_capabilitiesclass_test_runList of CapabilityEnum string values allowed in the class; defaults to an empty list.
max_file_size_bytesAll toolsPositive maximum file size in bytes; defaults to 75536.

class_path and test_path must be relative paths ending in .php and must not contain .. path segments. Invalid configuration is reported with ToolConfigurationException.

Before requesting execution, class_test_run scans the configured class file and rejects capabilities that are not in allowed_capabilities. It scans the test file separately and rejects every detected capability; the class allow-list never applies to the test file. Process isolation and test execution are the responsibility of the consumer-provided ClassTestRunnerInterface implementation.

Available tools

  • class_source_read and class_source_edit operate on the configured class source file.
  • class_test_read, class_test_edit, and class_test_create operate on the configured unit-test file.
  • class_test_run checks the configured class and test for capabilities before requesting execution of that single test file.

See the usage example for a complete registration example.