adachsoft / composer-package-browser-tool
AI SPI tool for browsing remote Composer/Packagist package source code across versions (list files, read file, search by name, list versions).
Package info
gitlab.com/a.adach/composer-package-browser-tool
pkg:composer/adachsoft/composer-package-browser-tool
Requires
- php: >=8.3
- adachsoft/ai-tool-call: ^2.0
- adachsoft/normalized-safe-path: ^0.1
- adachsoft/packagist-api-client: ^1.0
- adachsoft/remote-code-browser-lib: ^0.1.0
- guzzlehttp/guzzle: ^7.9
Requires (Dev)
- adachsoft/php-code-style: ^0.8.0
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^12.4
- rector/rector: ^2.9
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
An AI tool (SPI implementation for adachsoft/ai-tool-call) that lets an AI agent browse the source code of
remote Composer/Packagist packages across their published versions, without installing them into the project.
Purpose
When an AI assistant needs to understand how a third-party package is implemented, it usually has no access to that code. This tool fills the gap: it resolves a package on Packagist, downloads the requested version's distribution archive into a local cache, and exposes read-only operations over its files.
Main features
- List versions of a package with their source references and release dates.
- List files of a package version, optionally recursively and limited by depth.
- Read a file from a package version, as text or Base64, with a configurable size limit.
- Search files by name using a name pattern within a specific version.
- Latest stable resolution: when no version is given, the latest stable release is used.
- Local caching of downloaded archives, with an option to force a refresh.
- Read-only: the tool never modifies packages or the project it runs in.
Requirements
- PHP
>= 8.3 - Composer
Installation
composer require adachsoft/composer-package-browser-tool
Integration
The package provides ComposerPackageBrowserToolFactory, which implements the ToolFactoryInterface from
adachsoft/ai-tool-call. The factory is created from a ConfigMap with the following keys:
| Key | Required | Default | Description |
|---|---|---|---|
cache_dir | yes | – | Directory used to cache downloaded package archives. |
username | no | '' | Packagist username used for API requests. |
api_token | no | '' | Packagist API token used for API requests. |
max_file_size_bytes | no | 1048576 | Maximum size of a file returned by read_file. |
http_timeout_seconds | no | 30 | HTTP timeout used when downloading package archives. |
The created tool is registered under the name composer_package_browser and accepts the following parameters:
operation(required):list_versions,list_files,read_fileorsearch_file.package_name(required): full package name invendor/nameformat.version(optional): for example1.2.3,v1.2.3ordev-master. Latest stable is used when omitted.force_refresh(optional): skip the cache and download the archive again.options(optional): operation-specific options:path– relative path inside the package source (list_files,read_file),recursiveandmax_depth– forlist_files,encoding(textorbase64) – forread_file,name_pattern– forsearch_file.
Usage examples are available in docs/examples.
Usage
Once the tool is registered in your AI tool-call setup, the agent invokes composer_package_browser with a JSON
parameter object. A typical sequence is: list the available versions, list the files of a chosen version, and read
the file of interest. For example, a read_file call looks like this:
{
"operation": "read_file",
"package_name": "adachsoft/ai-tool-call",
"options": {
"path": "README.md",
"encoding": "text"
}
}
See docs/examples for complete examples of every operation.
Development
Run the test suite and quality tools from the project root:
vendor/bin/phpunit --configuration phpunit.xml
vendor/bin/phpstan analyse
vendor/bin/php-cs-fixer check
vendor/bin/rector process --dry-run
License
MIT