### Install Baconfy Prompt Source: https://github.com/baconfy/prompt/blob/main/README.md Install the package via Composer. ```bash composer require baconfy/prompt ``` -------------------------------- ### Boot local development environment Source: https://github.com/baconfy/prompt/blob/main/README.md Initializes the workbench database and starts a local server at http://127.0.0.1:8000 using Orchestra Testbench. ```bash composer dev # builds the workbench DB and serves at http://127.0.0.1:8000 ``` -------------------------------- ### Public API Usage Source: https://github.com/baconfy/prompt/blob/main/CLAUDE.md Examples of using the helper function, Facade, testing utilities, and Eloquent models for prompt management. ```php // Helper prompt(string $name, array $data = []): RenderedPrompt // Facade Prompt::get('welcome', ['name' => 'João']); // RenderedPrompt Prompt::source('welcome'); // ParsedFrontMatter|null Prompt::driver('database'); // Driver instance // Testing Prompt::fake([ 'welcome' => 'Hello stub!', 'auth.login' => new RenderedPrompt('...', ['model' => 'gpt-4']), ]); Prompt::assertCalled('welcome'); Prompt::assertNotCalled('other'); // Eloquent use Baconfy\Prompt\Models\Prompt; Prompt::create(['name' => '...', 'content' => '...']); Prompt::factory()->create(); ``` -------------------------------- ### Publish and Migrate Assets Source: https://github.com/baconfy/prompt/blob/main/README.md Publish configuration and migration files, then run migrations for database storage support. ```bash php artisan vendor:publish --tag=prompt-config php artisan vendor:publish --tag=prompt-migrations # only if you plan to use the database driver php artisan migrate ``` -------------------------------- ### Configuring prompt drivers Source: https://github.com/baconfy/prompt/blob/main/README.md Define storage drivers and their settings in the configuration file. ```php return [ 'default' => env('PROMPTS_DRIVER', 'file'), 'drivers' => [ 'file' => [ 'driver' => 'file', 'folder' => env('PROMPTS_FOLDER', resource_path('prompts')), ], 'database' => [ 'driver' => 'database', 'connection' => env('PROMPTS_CONNECTION'), 'table' => env('PROMPTS_TABLE', 'prompts'), ], ], ]; ``` -------------------------------- ### Project Directory Structure Source: https://github.com/baconfy/prompt/blob/main/CLAUDE.md Overview of the source code, database migrations, configuration, and testing directory layout. ```text src/ ├── Commands/ │ ├── ListPromptsCommand.php │ ├── MakePromptCommand.php │ └── ShowPromptCommand.php ├── Contracts/ │ └── Driver.php # find(), all() ├── Database/Factories/ │ └── PromptFactory.php ├── Drivers/ │ ├── DatabaseDriver.php │ └── FileDriver.php ├── Exceptions/ │ ├── MissingRequiredVariablesException.php │ └── PromptNotFoundException.php ├── Facades/ │ └── Prompt.php # exposes get, source, driver, fake, assertCalled, assertNotCalled ├── FrontMatter/ │ ├── Parser.php │ └── ParsedFrontMatter.php ├── Models/ │ └── Prompt.php ├── Testing/ │ └── PromptFake.php ├── Validators/ │ └── RequiredVariablesValidator.php ├── helpers.php # global prompt() function ├── PromptManager.php ├── PromptServiceProvider.php ├── RenderedPrompt.php └── Renderer.php database/migrations/ └── 2024_01_01_000001_create_prompts_table.php config/ └── prompt.php tests/ ├── Unit/ # pure components, no Laravel boot ├── Feature/ # uses Orchestra Testbench ├── Fixtures/prompts/ # sample .md files for FileDriver tests ├── Pest.php └── TestCase.php ``` -------------------------------- ### Render a prompt using the helper function Source: https://github.com/baconfy/prompt/blob/main/README.md Use the global helper to render a prompt by name with optional data. ```php prompt(string $name, array $data = []): RenderedPrompt ``` -------------------------------- ### Define a prompt file Source: https://github.com/baconfy/prompt/blob/main/README.md Create a prompt file with YAML front matter and Blade template syntax. ```markdown --- model: claude-opus-4-5 temperature: 0.7 required: [name] --- You are a helpful assistant. Greet {{ $name }} warmly and ask how you can help today. ``` -------------------------------- ### Configure Prompt Panel Settings Source: https://github.com/baconfy/prompt/blob/main/README.md Adjust panel settings such as path, gate, and middleware in the configuration file. ```php // config/prompt.php 'panel' => [ 'enabled' => env('PROMPTS_PANEL_ENABLED', true), 'path' => env('PROMPTS_PANEL_PATH', '_prompts'), 'gate' => 'viewPrompts', 'middleware' => ['web'], ], ``` -------------------------------- ### Interact with the Prompt Facade Source: https://github.com/baconfy/prompt/blob/main/README.md Access prompt rendering, source retrieval, and driver management via the Prompt facade. ```php use Baconfy\Prompt\Facades\Prompt; Prompt::get('welcome', ['name' => 'John']); // RenderedPrompt Prompt::source('welcome'); // ParsedFrontMatter|null Prompt::driver('database'); // Driver instance (defaults to active) ``` -------------------------------- ### Publish Admin Panel Views Source: https://github.com/baconfy/prompt/blob/main/README.md Run this command to publish the Blade views for customization. ```bash php artisan vendor:publish --tag=prompt-views ``` -------------------------------- ### Prompt Facade Methods Source: https://github.com/baconfy/prompt/blob/main/CLAUDE.md Methods available via the Prompt facade for managing drivers and retrieving prompt sources. ```APIDOC ## Prompt::get(string $name, array $data = []) ### Description Retrieves and renders a prompt using the currently configured driver. ## Prompt::source(string $name) ### Description Retrieves the raw parsed front matter for a specific prompt without rendering. ## Prompt::driver(string $name) ### Description Switches the active storage driver (e.g., 'database' or 'file'). ``` -------------------------------- ### Render and use prompts Source: https://github.com/baconfy/prompt/blob/main/README.md Render a prompt with variables and access its metadata or content. ```php $prompt = prompt('welcome', ['name' => 'John']); $prompt->content; // rendered string $prompt->metadata['model']; // 'claude-opus-4-5' (string) $prompt; // same as ->content (implements Stringable) ``` ```php $prompt = prompt('welcome', ['name' => 'John']); $response = $anthropic->messages()->create([ 'model' => $prompt->metadata['model'], 'temperature' => $prompt->metadata['temperature'], 'messages' => [['role' => 'user', 'content' => (string) $prompt]], ]); ``` -------------------------------- ### Prompt Facade Source: https://github.com/baconfy/prompt/blob/main/README.md The Prompt facade provides static access to prompt management methods. ```APIDOC ## Prompt Facade ### Methods - **Prompt::get(string $name, array $data)**: Renders a prompt. - **Prompt::source(string $name)**: Retrieves the raw template and metadata (ParsedFrontMatter) without rendering. - **Prompt::driver(string $name)**: Returns a specific driver instance. ``` -------------------------------- ### Execute CLI commands for prompt management Source: https://github.com/baconfy/prompt/blob/main/README.md Use Artisan commands to list, show, and scaffold prompts. ```bash php artisan prompt:list # list prompts across all configured drivers php artisan prompt:list database # list prompts for a specific driver php artisan prompt:show welcome # show metadata and raw content for a single prompt php artisan prompt:show welcome --driver=database # target a specific driver php artisan prompt:make welcome # scaffold resources/prompts/welcome.md ``` -------------------------------- ### Configure drivers in .env Source: https://github.com/baconfy/prompt/blob/main/README.md Set the default driver and connection details in the environment file. ```dotenv PROMPTS_DRIVER=database PROMPTS_CONNECTION=mysql # optional, falls back to DB_CONNECTION PROMPTS_TABLE=prompts # optional ``` -------------------------------- ### Use the database driver Source: https://github.com/baconfy/prompt/blob/main/README.md Store and retrieve prompts from a database table using the same format as file-based prompts. ```php use Baconfy\Prompt\Models\Prompt; Prompt::create([ 'name' => 'welcome', 'content' => <<<'MD' --- model: claude-opus-4-5 required: [name] --- Hello {{ $name }}! MD, ]); prompt('welcome', ['name' => 'John']); // works the same way ``` -------------------------------- ### Run project quality assurance commands Source: https://github.com/baconfy/prompt/blob/main/CLAUDE.md Execute these commands to run tests, check coverage, perform static analysis, and format code. ```bash composer test # pest composer test:coverage # pest --coverage --min=100 composer test:types # phpstan analyse composer format # pint ``` -------------------------------- ### Define prompt front matter Source: https://github.com/baconfy/prompt/blob/main/README.md Use YAML front matter to define metadata, tags, and required variables. ```markdown --- model: claude-opus-4-5 temperature: 0.7 required: [user_name, context] description: Onboarding greeting tags: [onboarding, greeting] --- Hello {{ $user_name }}! Considering {{ $context }}, welcome aboard. ``` -------------------------------- ### Configure multiple drivers Source: https://github.com/baconfy/prompt/blob/main/README.md Define multiple drivers in the configuration file and access them explicitly. ```php // config/prompt.php 'drivers' => [ 'system' => [ 'driver' => 'file', 'folder' => resource_path('prompts/system'), ], 'user' => [ 'driver' => 'database', 'table' => 'user_prompts', ], ], ``` ```php Prompt::driver('system')->find('welcome'); Prompt::driver('user')->find('welcome'); ``` -------------------------------- ### Import Prompt Exceptions Source: https://github.com/baconfy/prompt/blob/main/README.md Import these classes to handle specific errors thrown by the Prompt driver. ```php use Baconfy\Prompt\Exceptions\PromptNotFoundException; use Baconfy\Prompt\Exceptions\MissingRequiredVariablesException; ``` -------------------------------- ### Seeding prompts with factories Source: https://github.com/baconfy/prompt/blob/main/README.md Utilize Eloquent factories to seed prompt data when using the database driver. ```php use Baconfy\Prompt\Models\Prompt; Prompt::factory()->create(); Prompt::factory()->count(5)->create(); Prompt::factory()->create(['name' => 'welcome', 'content' => 'Hi!']); ``` -------------------------------- ### prompt(string $name, array $data = []) Source: https://github.com/baconfy/prompt/blob/main/CLAUDE.md Global helper function to render a prompt by name with provided data. ```APIDOC ## prompt(string $name, array $data = []) ### Description Retrieves and renders a prompt identified by its name, optionally injecting data for Blade rendering. ### Parameters - **name** (string) - Required - The identifier of the prompt. - **data** (array) - Optional - Key-value pairs to be used during rendering. ### Returns - **RenderedPrompt** - The rendered prompt object. ``` -------------------------------- ### Define Prompt Front Matter Source: https://github.com/baconfy/prompt/blob/main/CLAUDE.md Configuration block for prompt metadata including model, temperature, and required variables. ```markdown --- model: claude-opus-4-5 temperature: 0.7 required: [user_name] description: Greeting prompt --- Hello {{ $user_name }}! ``` -------------------------------- ### Mocking prompts in tests Source: https://github.com/baconfy/prompt/blob/main/README.md Use the Prompt facade to stub prompt responses and verify calls without hitting external storage. ```php use Baconfy\Prompt\Facades\Prompt; use Baconfy\Prompt\RenderedPrompt; Prompt::fake([ 'welcome' => 'Hello stub!', 'auth.login' => new RenderedPrompt('Stub login.', ['model' => 'gpt-4']), ]); // code under test prompt('welcome', ['name' => 'whatever']); Prompt::assertCalled('welcome'); Prompt::assertNotCalled('checkout'); ``` -------------------------------- ### Access file-based prompts Source: https://github.com/baconfy/prompt/blob/main/README.md Use dot notation to reference prompt files within subdirectories. ```php prompt('auth.login'); // resources/prompts/auth/login.md prompt('emails.welcome.subject'); // resources/prompts/emails/welcome/subject.md ``` -------------------------------- ### Prompt Testing Utilities Source: https://github.com/baconfy/prompt/blob/main/CLAUDE.md Methods for mocking and asserting prompt interactions during testing. ```APIDOC ## Prompt::fake(array $stubs) ### Description Registers fake prompt responses for testing purposes. ## Prompt::assertCalled(string $name) ### Description Asserts that a specific prompt was rendered during the test. ## Prompt::assertNotCalled(string $name) ### Description Asserts that a specific prompt was not rendered during the test. ``` -------------------------------- ### Manage database prompts with the Prompt model Source: https://github.com/baconfy/prompt/blob/main/README.md Use the Eloquent model to perform CRUD operations on database-backed prompts. ```php use Baconfy\Prompt\Models\Prompt as PromptModel; PromptModel::create([ 'name' => 'welcome', 'content' => <<<'MD' --- model: claude-opus-4-5 --- Hello {{ $name }}! MD, ]); PromptModel::where('name', 'welcome')->update(['content' => 'Hi {{ $name }}!']); ``` -------------------------------- ### CLI Commands Source: https://github.com/baconfy/prompt/blob/main/README.md Artisan commands for managing and debugging prompts via the command line. ```APIDOC ## CLI Commands ### Commands - **php artisan prompt:list [driver]**: List prompts across all drivers or a specific driver. - **php artisan prompt:show [name] [--driver=]**: Show metadata and raw content for a single prompt. - **php artisan prompt:make [name]**: Scaffold a new prompt file in resources/prompts/. ``` -------------------------------- ### Run package test suite Source: https://github.com/baconfy/prompt/blob/main/README.md Executes various testing and quality assurance tools including Pest, coverage analysis, static analysis, and code formatting. ```bash composer test # pest composer test:coverage # 100% required composer test:types # phpstan composer format # pint ``` -------------------------------- ### Access RenderedPrompt properties Source: https://github.com/baconfy/prompt/blob/main/README.md Retrieve rendered content and metadata from a RenderedPrompt instance. ```php $prompt->content; // rendered string $prompt->metadata; // array (string) $prompt; // same as ->content ``` -------------------------------- ### Configure Admin Panel Authorization Source: https://github.com/baconfy/prompt/blob/main/README.md Define access control for the admin panel using either a closure or a Laravel Gate. ```php // AppServiceProvider::boot() — closure style (like Horizon::auth) use Baconfy\Prompt\Panel; Panel::auth(fn ($user = null) => $user?->email === 'you@example.com'); ``` ```php // or via a regular Gate use Illuminate emplate\Facades\Gate; Gate::define('viewPrompts', fn ($user = null) => $user?->isAdmin()); ``` -------------------------------- ### Access ParsedFrontMatter properties Source: https://github.com/baconfy/prompt/blob/main/README.md Retrieve raw template content and metadata without rendering Blade tags. ```php $source = Prompt::source('welcome'); $source->metadata['model']; // 'claude-opus-4-5' $source->content; // raw template, with Blade tags untouched ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.