Skip to content

Package Commands

Applications usually need a few commands of their own: reconcile invoices, warm a cache, import a file. Packages often want to ship commands too. Instead of asking you to install another global tool, PAM lets both register commands that you run as pam <name>, executed by the same embedded PHP as your application.

PAM validates every registration before it runs anything: command names are checked, script paths are resolved and must stay inside their owner, and built-in or duplicate commands cannot be shadowed.

Terminal window
pam commands
app:warm Application command
billing:reconcile Reconcile pending invoices

pam commands must run inside a PAM project, that is, a directory with a pam.json manifest. When nothing is registered it prints No application or package commands are registered.

For tools and editor integrations, use the machine-readable forms instead of parsing terminal output:

Terminal window
pam commands --json
pam commands --names
{
"commands": [
{ "description": "Application command", "name": "app:warm" },
{ "description": "Reconcile pending invoices", "name": "billing:reconcile" }
],
"schema": 1
}

--names prints one name per line; it is the list used by the generated Bash, Zsh, Fish and PowerShell completions.

Register commands in the commands object of your project’s pam.json. Script paths are relative to the project root:

pam.json
{
"$schema": "https://push-in.github.io/pam-docs/schemas/pam.schema.json",
"schema": 1,
"type": 1,
"name": "billing-api",
"commands": {
"billing:reconcile": {
"script": "bin/reconcile.php",
"description": "Reconcile pending invoices"
},
"app:warm": "bin/warm.php"
}
}

The short form, "app:warm": "bin/warm.php", is enough when you do not need a description. The script is ordinary PHP: arguments arrive in $argv, and your Composer autoloader is already loaded.

bin/reconcile.php
<?php
declare(strict_types=1);
$options = getopt('', ['since:']);
$since = $options['since'] ?? 'today';
echo "Reconciling invoices since {$since}" . PHP_EOL;
exit(0);
Terminal window
pam billing:reconcile --since=yesterday
Reconciling invoices since yesterday

An object definition accepts these keys:

Key Description
script A PHP script, run by PAM’s embedded PHP
bin A native executable, run directly
description Text shown by pam commands (at most 240 characters); defaults to “Application command”
arguments Up to 32 strings inserted before the user’s arguments
environment Up to 32 environment variables (uppercase names) set for the command

A definition must contain exactly one of script or bin.

pam.json
{
"commands": {
"billing:reconcile": {
"script": "bin/reconcile.php",
"description": "Reconcile pending invoices",
"arguments": ["--dry-run"],
"environment": { "BILLING_MODE": "batch" }
}
}
}

With this definition, pam billing:reconcile --since=yesterday runs the script with --dry-run --since=yesterday and BILLING_MODE=batch in its environment.

A Composer package registers commands under extra.pam.commands in its own composer.json. Paths are relative to the installed package:

composer.json
{
"name": "acme/pam-inspector",
"type": "library",
"extra": {
"pam": {
"commands": {
"inspector:snapshot": {
"script": "bin/snapshot.php",
"description": "Capture an application snapshot"
}
}
}
}
}

When an application installs the package, the command appears automatically:

Terminal window
pam composer require acme/pam-inspector
pam commands
inspector:snapshot Capture an application snapshot

PAM reads Composer’s vendor/composer/installed.json, uses each package’s canonical install-path, and honors a custom config.vendor-dir. Packages installed through Composer path repositories (symlinks to a checkout elsewhere) work too; their commands must stay inside the resolved package directory.

Use bin when your package ships a compiled CLI. arguments lets several commands share one executable:

composer.json
{
"extra": {
"pam": {
"commands": {
"inspector:watch": {
"bin": "bin/pam-inspector",
"arguments": ["watch"],
"description": "Watch application diagnostics"
}
}
}
}
}

A bin command runs with the project root as its working directory and receives:

  • every argument the user typed, after your arguments prefix;
  • PAM_BINARY: the absolute path of the pam executable, so your tool can call back into PAM;
  • PAM_PACKAGE_COMMAND=1.

PAM removes its private library paths (LD_LIBRARY_PATH, DYLD_LIBRARY_PATH) and its php.ini settings (PHPRC, PHP_INI_SCAN_DIR) from the environment, so tools your executable starts (git, curl, a system php) use the host’s own setup. script commands also receive PAM_BINARY.

  • Names use lowercase ASCII letters, digits, :, - and _, start with a letter or digit, and are at most 96 bytes long.
  • Use a namespace prefix such as billing: or inspector: to avoid collisions.
  • A registration may not reuse a built-in command name. A few contextual built-ins, such as dev, build, test, doctor, format, lint, package, release and the make:* generators, can be provided by installed product packages; runtime commands such as start, composer, exec and self-update can never be replaced.
  • Two registrations with the same name are an error.

When a rule is broken, command discovery fails with an error that names the registration:

× ERROR [PAM-E005] PAM command registration start shadows a built-in command
× ERROR [PAM-E005] invalid PAM command name "Bad Name"
  • A command’s target must exist and must resolve inside its owner: the project root for application commands, the installed package for package commands. ../ paths and symlinks that escape are rejected.
  • A package whose install path resolves to the filesystem root, your home directory, or the project itself cannot register commands.
  • A project with its own composer.json never inherits commands from the vendor directory of a parent monorepo.

The project manifest follows the public pam.schema.json JSON Schema.