phramecms / cli
Structured, JSON-capable command-line module for PhrameCMS — auto-discovered CLI commands, generic operation execution, and deterministic exit codes.
Requires
- php: ^8.5
- phramecms/core: ^0.1
- symfony/console: ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.95
- infection/infection: ^0.35.12
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^13.0
- spaze/phpstan-disallowed-calls: ^4.15
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-04 21:34:19 UTC
README
Structured, JSON-capable command-line module for PhrameCMS, built equally for human developers, CI/CD pipelines, and shell-based AI agents.
phramecms/cli provides CliModule (phrame.cli) and CliApplication, wrapping symfony/console behind a vendor-neutral contract layer (PhrameCms\Cli\Contract\*, PhrameCms\Cli\Input\*, PhrameCms\Cli\Output\CliOutputInterface). In a PhrameCMS project based on phramecms/skeleton, commands are invoked via bin/phrame.
Built-In Commands
| Command | Description |
|---|---|
modules:list |
List booted PhrameCMS modules in resolved dependency order (name, dependencies, class). |
op:list |
List all registered Core Operations (name, description, requiredPermissions, mutatesState, supportsDryRun). |
op:describe <operation> |
Print full metadata, required permissions, dry-run support, and input/output JSON Schemas for a registered Core Operation. |
op:run <operation> [options] |
Execute any registered Core or custom Operation through Core's OperationBus. |
op:run Options
| Option | Shortcut | Default | Description |
|---|---|---|---|
--input=<json> |
-i |
— | JSON object string of operation input (mutually exclusive with --input-file). |
--input-file=<path> |
-f |
— | Path to a JSON file containing an operation input object (mutually exclusive with --input). |
--dry-run |
— | false |
Execute in dry-run mode when supported by the operation. |
--idempotency-key=<key> |
— | — | Idempotency key for deduplicating live executions. |
--actor-id=<id> |
— | cli |
Actor identifier for ExecutionContext. |
--actor-type=<type> |
— | human |
Actor type: human, agent, or system. |
--scopes=<list> |
— | — | Comma-separated permission scopes for the actor. |
--json |
— | false |
Output result as strictly valid JSON (available on every command). |
Example invocations (via bin/phrame in a project using phramecms/skeleton):
./bin/phrame modules:list --json
./bin/phrame op:list --json
./bin/phrame op:describe config.import --json
./bin/phrame op:run config.import \
--input='{"directory":"config/sync"}' \
--dry-run \
--actor-id=ci-bot \
--actor-type=agent \
--scopes=config.import \
--json
Domain operations & MCP entrypoint:
phramecms/cliintentionally does not duplicate CMS domain logic. Domain actions (configuration, entities, users, proposals, etc.) are exposed generically viaop:list,op:describe, andop:run, or registered as custom commands by feature/project modules. The Stdio MCP server is provided separately via the project entrypoint (bin/phrame-mcpinphramecms/skeleton).
Machine-Readable Mode (--json) & Exit Codes
Every command registered in CliApplication automatically receives the --json option (unless the command defines its own json option). When --json is passed:
- Interactivity and ANSI formatting are disabled.
stdoutcontains strictly valid JSON with no stray banners or warnings.- Uncaught exceptions and non-zero failures emit a structured JSON error envelope to
stdout:
{
"ok": false,
"exitCode": 2,
"error": {
"code": "validation_error",
"type": "PhrameCms\\Core\\Exception\\ValidationException",
"message": "Operation input JSON must decode to a JSON object.",
"validation": {
"message": "Operation input JSON must decode to a JSON object.",
"errors": [
{
"path": "input",
"message": "Operation input JSON must decode to a JSON object.",
"keyword": "cli"
}
],
"errorsByPath": {
"input": ["Operation input JSON must decode to a JSON object."]
}
}
}
}
For AuthorizationException, error.requiredPermissions is included. Without --json, exceptions are written to stderr as Error [<code>]: <message>.
Deterministic Exit Codes (PhrameCms\Cli\ExitCode)
| Exit Code | Enum Case | JSON Error Code | Meaning |
|---|---|---|---|
0 |
ExitCode::Ok |
ok |
Command succeeded. |
1 |
ExitCode::RuntimeError |
runtime_error |
Unhandled runtime error or fallback failure. |
2 |
ExitCode::ValidationError |
validation_error |
ValidationException, invalid CLI arguments/options, or malformed JSON input. |
3 |
ExitCode::AuthorizationDenied |
authorization_denied |
AuthorizationException (missing required actor permission scope). |
4 |
ExitCode::NotFound |
not_found |
OperationNotFoundException or unknown CLI command. |
Registering a Custom CLI Command
Custom modules add CLI commands by implementing PhrameCms\Cli\Contract\CommandInterface and tagging the service with CliApplication::COMMAND_TAG (phrame.cli_command). Commands never depend on symfony/console types directly.
<?php declare(strict_types=1); namespace Acme\MyModule\Command; use PhrameCms\Cli\Contract\CommandInterface; use PhrameCms\Cli\ExitCode; use PhrameCms\Cli\Input\ArgumentDefinition; use PhrameCms\Cli\Input\CliInput; use PhrameCms\Cli\Input\OptionDefinition; use PhrameCms\Cli\Output\CliOutputInterface; final readonly class PingCommand implements CommandInterface { public function name(): string { return 'acme:ping'; } public function description(): string { return 'Check module health'; } public function arguments(): array { return [ new ArgumentDefinition( name: 'target', description: 'Optional target label', required: false, default: 'default', ), ]; } public function options(): array { return [ new OptionDefinition( name: 'verbose-status', description: 'Include additional status details', acceptsValue: false, default: false, ), ]; } public function execute(CliInput $input, CliOutputInterface $output): ExitCode { $target = is_string($input->argument('target')) ? $input->argument('target') : 'default'; $payload = [ 'ok' => true, 'target' => $target, 'verbose' => $input->flag('verbose-status'), ]; if ($output->isJsonMode()) { $output->json($payload); return ExitCode::Ok; } $output->writeln(sprintf('Pong from %s.', $target)); return ExitCode::Ok; } }
Register and tag the command in your module's register() method so CliModule auto-discovers it:
<?php declare(strict_types=1); namespace Acme\MyModule; use Acme\MyModule\Command\PingCommand; use PhrameCms\Cli\CliApplication; use PhrameCms\Core\Contract\ContainerBuilderInterface; use PhrameCms\Core\Contract\ModuleInterface; use Psr\Container\ContainerInterface; final readonly class MyModule implements ModuleInterface { public function name(): string { return 'acme.my_module'; } public function dependencies(): array { return ['phrame.cli']; } public function register(ContainerBuilderInterface $builder): void { $builder->singleton( PingCommand::class, static fn(): PingCommand => new PingCommand(), [CliApplication::COMMAND_TAG], // 'phrame.cli_command' ); } public function boot(ContainerInterface $container): void {} }
AI-First Design Role
Gives shell-capable AI agents and CI workflows a zero-ambiguity, typed interface to PhrameCMS with full --dry-run, --idempotency-key, and --json support, backed by the same Core OperationBus, policy enforcement, and audit trail as REST and MCP.
Dependencies
- PHP
^8.5 phramecms/coresymfony/console^8.0(encapsulated internally behindPhrameCms\Cli\Contract\*andPhrameCms\Cli\Bridge\*)
Ecosystem
Part of the PhrameCMS multi-repo suite. See PhrameCMS/cms for the architecture docs and PhrameCMS/skeleton for the starter project (bin/phrame and bin/phrame-mcp).