Search by

adachsoft / composer-package-browser-tool

Arkadiusz Adach

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

Issues

pkg:composer/adachsoft/composer-package-browser-tool

Statistics

Installs: 8

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-11-28 23:15 UTC

This package is auto-updated.

Last update: 2026-11-28 22:16:14 UTC


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:

KeyRequiredDefaultDescription
cache_diryes–Directory used to cache downloaded package archives.
usernameno''Packagist username used for API requests.
api_tokenno''Packagist API token used for API requests.
max_file_size_bytesno1048576Maximum size of a file returned by read_file.
http_timeout_secondsno30HTTP 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_file or search_file.
  • package_name (required): full package name in vendor/name format.
  • version (optional): for example 1.2.3, v1.2.3 or dev-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),
    • recursive and max_depth – for list_files,
    • encoding (text or base64) – for read_file,
    • name_pattern – for search_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