adachsoft / php-class-scoped-tools
Class-scoped PHP source and unit test tools for AI agents.
Package info
gitlab.com/a.adach/php-class-scoped-tools
pkg:composer/adachsoft/php-class-scoped-tools
Requires
- php: ^8.3
- adachsoft/ai-tool-call: ^2.0
- adachsoft/filesystem: ^1.4
- adachsoft/php-capability-scanner: ^0.1
- adachsoft/text-editor: ^0.1.2
- nikic/php-parser: ^5.0
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
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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:
| Key | Required for | Description |
|---|---|---|
base_path | All tools | Existing project directory used as the filesystem boundary. |
class_path | class_source_read, class_source_edit, class_test_create, class_test_run | Relative PHP class path. |
test_path | class_test_read, class_test_edit, class_test_create, class_test_run | Relative PHP test path. |
allow_create | class_source_edit | Whether editing may create the class file; defaults to false. |
allowed_capabilities | class_test_run | List of CapabilityEnum string values allowed in the class; defaults to an empty list. |
max_file_size_bytes | All tools | Positive 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_readandclass_source_editoperate on the configured class source file.class_test_read,class_test_edit, andclass_test_createoperate on the configured unit-test file.class_test_runchecks the configured class and test for capabilities before requesting execution of that single test file.
See the usage example for a complete registration example.