Skip to content

Command Palette

Diagnostics can expose safe operational shortcuts through command palette providers. Providers return command metadata; execution and authorization stay in the Diagnostics package.

Implement CommandPaletteProvider and tag it as capell.diagnostics.command-palette-provider. Each returned key should be stable because command runs are persisted.

use Capell\Diagnostics\Contracts\CommandPaletteProvider;
use Capell\Diagnostics\Data\CommandPaletteCommandData;
use Capell\Diagnostics\Enums\CommandPaletteDanger;
use Capell\Diagnostics\Enums\CommandPaletteType;
final class DemoPaletteProvider implements CommandPaletteProvider
{
public function commandPaletteCommands(): array
{
return [
'demo.clear-cache' => new CommandPaletteCommandData(
id: 'demo.clear-cache',
label: __('host-app::diagnostics.clear_demo_cache'),
type: CommandPaletteType::Artisan,
description: __('host-app::diagnostics.clear_demo_cache_description'),
command: 'cache:clear',
ability: 'run_diagnostics_commands',
danger: CommandPaletteDanger::Safe,
requiresConfirmation: true,
keywords: ['cache', 'demo'],
group: 'Demo',
),
];
}
}
$this->app->singleton(DemoPaletteProvider::class);
$this->app->tag([DemoPaletteProvider::class], 'capell.diagnostics.command-palette-provider');

Use host-package translations for labels and descriptions. Do not put user-facing text directly in provider classes.

FieldUse
idStable command identifier.
typeCommand type, such as link or Artisan command.
commandCommand string for command-backed entries.
abilityAuthorization ability checked before execution.
dangerRisk level shown in the UI.
requiresConfirmationAdds a confirmation step before execution.
parametersParameter definitions for command input.
keywordsSearch terms for palette filtering.

Keep dangerous commands out unless they have explicit authorization and confirmation.

Terminal window
vendor/bin/pest packages/diagnostics/tests --configuration=phpunit.xml