adachsoft / project-map-prompt-function
Prompt function exposing project map to prompt templates.
Package info
gitlab.com/a.adach/project-map-prompt-function
pkg:composer/adachsoft/project-map-prompt-function
Requires
- php: ^8.3
- adachsoft/project-config-lib: ^0.1.0
- adachsoft/project-map: ^0.1.0
- adachsoft/prompt-template-lib: ^0.3
Requires (Dev)
- adachsoft/php-code-style: ^0.8.0
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13
- rector/rector: ^2.9
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A prompt-template function that makes a configured project's project map available to prompt templates as JSON. It resolves the current project from the prompt engine context and reads the map from the project's configured base path.
Features
- Exposes the project map through the
project_mapprompt function. - Provides a compact summary through
executeSummary(). - Returns a useful response when a project has not created a map index yet.
- Validates the project context and project base path, and reports failures through
ProjectMapPromptFunctionException.
Installation
Install the package with Composer:
composer require adachsoft/project-map-prompt-function
Integration
Create the function with your project's ProjectConfigRepositoryInterface implementation, set the project_id in the prompt engine context, and register the function. Registration also associates the function with the prompt engine.
use AdachSoft\ProjectMapPromptFunction\ProjectMapPromptFunction;
use AdachSoft\ProjectConfigLib\ProjectConfigRepositoryInterface;
use AdachSoft\PromptTemplateLib\PublicApi\PromptEngineInterface;
/** @var PromptEngineInterface $engine */
/** @var ProjectConfigRepositoryInterface $projectConfigRepository */
$engine->setContextValue('project_id', 'my-project');
$engine->registerFunction(new ProjectMapPromptFunction($projectConfigRepository));
The project configuration identified by project_id must contain a non-empty base_path parameter pointing to the project root. The function is named project_map; use that name in templates according to the syntax configured for your prompt engine.
See the usage example for details about the available output and context requirements.
Requirements
- PHP 8.3 or later.
- Composer.
Usage
Register ProjectMapPromptFunction with the prompt engine as shown in Integration, then call project_map from a prompt template. For a complete example, see the usage example.