Dev Hub Prompt Commands
The developer hub exposes a global, slash-prefixed command prompt at the bottom of the screen (open with Cmd/Ctrl + K). Commands are first-class: each one is a small definition file that the registry auto-discovers, and commands can return a descriptor for inspection in a shared modal, or return null for a separate side effect. This prompt is distinct from AI App editing.
Use this guide alongside the current registry, command definition and backend route. Client discovery and argument parsing do not establish server authorization or successful execution.
At a glance
- Open the terminal: Cmd/Ctrl + K from anywhere in DevHub.
- List commands: an empty prompt shows up to seven available top-level suggestions; type
/and a few characters to filter. - Navigate suggestions: arrow keys;
Tabautocompletes the highlighted entry without running it;Enterruns. - Bare command (
/balance) opens that command's landing modal — for most commands this is a help/subcommand list, but a command can define a customopen()instead. - With arguments (
/balance topup ai_credits_usd 50) runs the matching subcommand and renders its result in the global modal.
File map
| Concern | Path |
|---|---|
| Registry composable | resources/js/Developer/Composables/useDevPrompt.js |
| Shared active result state | resources/js/Developer/Composables/useDevPromptResult.js |
| Result modal mount | resources/js/Developer/Components/UI/DPromptResultModal.vue (singleton in Developer/app.js) |
| Terminal dock UI | resources/js/Developer/Layouts/Partials/DevTerminalDock.vue |
| Default help renderer | resources/js/Developer/Prompt/components/DPromptCommandHelp.vue |
| Command definitions | resources/js/Developer/Prompt/commands/*.js |
| Command UI components | resources/js/Developer/Prompt/components/*.vue |
| Backend controllers | app/Http/Controllers/Developer/Prompt/*Controller.php |
| Backend routes | routes/developer.php under prompt.* |
Architecture
The dock owns no per-command logic. It calls
useDevPrompt().getSuggestions(input) to power the type-ahead list and
useDevPrompt().executeCommand(input) to dispatch. The result (if any)
is handed to useDevPromptResult().showResult(...), which a singleton
<DPromptResultModal /> mounted in Developer/app.js renders inside a
shared DModal.
Commands live as one file each under
resources/js/Developer/Prompt/commands/. The registry auto-imports
them with a Vite glob (import.meta.glob('../Prompt/commands/*.js', { eager: true })),
filters by permission via usePermissions(), and exposes the result as
availableCommands. Adding a command never requires editing the dock,
the registry, or the result modal — drop in a new file, optionally a
controller + routes, and it appears.
Adding a new command — checklist
- Define it. Create
resources/js/Developer/Prompt/commands/<name>.jsexporting aCommandDefinition(schema below). - (Optional) Modal panels. Put result/landing Vue components under
resources/js/Developer/Prompt/components/. Each receives an@closeevent it can emit to dismiss the modal. - (Optional) Backend endpoints. Add
app/Http/Controllers/Developer/Prompt/<Name>Controller.phpand register routes underdeveloper.prompt.<name>.*inside the existing/{team}/developergroup inroutes/developer.php. Guard mutation endpoints with thesuperAdminmiddleware unless you have a permission-string check. - That's it — Cmd/Ctrl + K and the new command appears.
CommandDefinition schema
export default {
// Required. The slash slug users type.
slug: "balance",
// Required. One-line description shown in type-ahead and help modals.
description: "Manage consumable balances for the current team",
// Optional. Controls visibility in the type-ahead and gates `executeCommand`.
// null — visible to anyone authenticated in DevHub
// 'super_admin' — visible only when isSuperAdmin() is true
// 'some.string' — visible only when userCan('some.string') is true
permission: null,
// Optional. Handler for the bare `/balance` invocation. Receives a `ctx`
// (see "Command context" below) and returns a ResultDescriptor, a
// Promise<ResultDescriptor>, or `null` to suppress the result modal.
// When omitted, a built-in help renderer lists the visible subcommands.
open: ({ ctx }) => ({
title: "Consumable Balances",
component: BalancePanel,
props: { teamSlug: ctx.teamSlug },
size: "lg",
}),
// Optional. Subcommands invoked as `/balance <slug> [args...]`.
subcommands: [
{
slug: "topup",
description: "Add credit to a direct bucket",
permission: "super_admin", // optional, same semantics as top-level
args: [
// Positional order matches array order. Required args fail parsing
// when absent. `type` controls coercion: 'string' | 'number' | 'boolean'.
{ name: "slug", type: "string", required: true },
{ name: "amount", type: "number", required: true },
{ name: "reason", type: "string", required: false },
],
run: async ({ args, ctx }) => {
const res = await axios.post(
route("developer.prompt.balance.top-up", { team: ctx.teamSlug }),
args,
)
return {
title: "Top-up complete",
component: BalanceTransactionResult,
props: { result: res.data, action: "topup" },
size: "md",
}
},
},
],
}
ResultDescriptor
What open() / run() should return (or resolve to):
| Field | Required | Notes |
|---|---|---|
component | for non-error UI results | Vue component rendered inside DModal. Receives the listed props plus an @close emit. |
props | no | Object spread onto the component. |
title | no | Modal title. Defaults to empty string. |
size | no | One of 'sm' | 'md' | 'lg' | 'xl'. Defaults to 'lg'. |
error | no | If set, the modal renders this error message instead of component. |
The result state is one active descriptor, not a FIFO queue: a new result replaces the previous one. Closing a modal clears that display state; it does not cancel a pending request or reverse a mutation. executeCommand catches execution errors and returns their response/message as an error descriptor; callers still need to verify the operation outcome.
Return null (or undefined) to opt out of the result modal entirely —
useful for side-effect-only commands like /flappy, which just toggles a
shared composable state to open its own modal.
Command context
open() and run() receive { ctx } (and run also receives args).
ctx is built from the current Inertia page and exposes:
| Key | Type | Source |
|---|---|---|
teamSlug | string | undefined | usePage().props.currentTeam?.slug |
team | object | undefined | usePage().props.currentTeam |
isSuperAdmin | boolean | usePermissions().isSuperAdmin() |
Add to this set by editing buildContext() in useDevPrompt.js —
only when the command needs a well-defined additional context. teamSlug/team can be undefined if currentTeam props are absent; they are not guaranteed by this object construction. Resolve and verify the intended team before invoking a team-scoped endpoint.
Argument parsing
The parser accepts both shapes — pick whichever feels right for the command. Positional comes first, named flags override.
| Input | Resolved args |
|---|---|
/balance topup ai_credits_usd 50 | { amount: 50, slug: "ai_credits_usd" } (positional, in args order) |
/balance topup --amount=50 --slug=ai_credits_usd | same |
/balance topup --amount 50 --slug ai_credits_usd | same (space-separated also works) |
/balance topup ai_credits_usd 50 --reason "manual top-up" | separate flag value preserves the quoted phrase |
Rules of thumb:
- Order positional args by frequency / obviousness — required ones
first. Frequent users will reach for positional, occasional users
will rely on
--name=for self-documentation. - Reserve
--flagsfor booleans, optional fields, or things that don't have an obvious positional slot. - Coercion is done from the
typefield on eachargsentry — finite numbers parse viaNumber(); a non-finite/unparseable value is returned unchanged. Boolean stringstrue|false|1|0are recognized, but other values use JavaScript truthiness. Strings useString(value).
Parser limits to account for
The tokenizer groups a double-quoted segment when the quote starts the token. Use --reason "manual top-up", not --reason="manual top-up": the latter can split at the space and retain quote fragments. Single quotes and shell escape syntax are not a supported shell parser. A shell command copied into this prompt is not executed as a shell command.
Named flags override their matching positional slot; remaining positionals are not shifted to fill a different schema slot. Unknown named flags and surplus positionals are not returned as declared arguments. Required checks detect missing values, not all invalid values. A bare flag becomes true; invalid numeric text can survive parsing; a nonempty unknown Boolean string can become true. Backend validation must enforce domain types, ranges and allowed values.
registerCommand(def) can register/replace a matching slug for late binding/tests; eager file discovery is not the only registration path. Do not rely on frontend registry entries as a privilege boundary.
Permissions
Permission checks happen in two places and both must hold:
- Frontend filters out commands and subcommands the user can't run
so they never appear in suggestions or execute via
executeCommand. - Backend enforces it again on the route — either by wrapping the
route in the
superAdminmiddleware or by adding a policy /userCancheck in the controller. The frontend filter is UX, not security.
When a subcommand mutates data, prefer:
Route::middleware(['superAdmin'])->group(function () {
Route::post('/top-up', [PromptBalanceController::class, 'topUp'])
->name('top-up');
});
inside the intended authenticated/team-scoped route group. Verify backend policy/middleware for read operations too; a null frontend permission is not public API access. The balance routes inherit authenticated, verified and team-scope middleware. Their request authorize methods return true and rely on route-level mutation restrictions, so copying only a request class does not copy that protection.
Reference: /balance
The shipped command demonstrates every piece:
| File | Role |
|---|---|
resources/js/Developer/Prompt/commands/balance.js | Definition: open panel + stats, ledger, topup, adjust subs |
resources/js/Developer/Prompt/components/BalancePanel.vue | Interactive landing modal — read for everyone, top-up + adjust forms shown to super admins |
resources/js/Developer/Prompt/components/BalanceTransactionResult.vue | Renders single-tx outcomes of topup / adjust |
resources/js/Developer/Prompt/components/BalanceLedgerResult.vue | Table view for /balance ledger [slug] |
app/Http/Controllers/Developer/Prompt/BalanceController.php | index, topUp, adjust, transactions; delegates mutations to TeamConsumableService |
routes/developer.php (prompt.balance.*) | 4 routes; mutations wrapped in inner superAdmin middleware |
Example syntax (top-up/adjust are privileged durable mutations, not test commands):
/balance
/balance stats
/balance ledger ai_credits_usd
/balance topup ai_credits_usd 50
/balance topup --slug=ai_credits_usd --amount=50 --reason "manual top-up"
/balance adjust --slug=ai_credits_usd --amount=-10 --reason "manual correction"
Bare balance and stats open panels; ledger reads filtered entries. Top-up positionals are slug, amount, optional reason. Adjustment positionals are slug, amount, required reason, optional source, optional source_ref; named flags make that intent explicit. Do not append shell-style comments to prompt input.
Migrating a side-effect command
If your command doesn't open a result modal (e.g. it toggles some
existing UI state), follow the /flappy pattern:
- Create a tiny
useX()composable that owns the shared ref. - Have the existing UI consumer (sidebar, layout, etc.) bind to that
composable's
openref. - The command file calls
useX().show()(or whatever) insideopen()and returnsnullto suppress the result modal.
Example: resources/js/Developer/Prompt/commands/flappy.js paired with
resources/js/Developer/Composables/useFlappy.js.
Anti-patterns
- Don't import command definitions from outside the registry — use the registry. Direct imports skip permission filtering.
- Don't put modal state into a command file. Returning a
ResultDescriptoris how a command opens UI; everything else routes through a shared composable. - Don't rely on the frontend permission filter for security. Always guard the route or controller too.
- Don't make
argsoptional when the backend requires them — the parser surfaces aMissing required argument(s)error if you declare themrequired: true, which is a better UX than a 422 from the API.
Verify and troubleshoot
Use a synthetic local command when testing parsing and result presentation. Balance top-up/adjust examples describe privileged durable mutations; they are not a harmless smoke test. The current dock does not establish a general one-execution-at-a-time or idempotency guarantee. Repeated Enter presses can require explicit command-side protection; inspect transaction/result state before retrying.
For /balance, top-up requires a configured consumable slug and positive numeric amount. Adjustment requires a nonzero signed amount, supported source and reason; the command defaults source to direct when omitted. The backend obtains currentTeam from request attributes and delegates to TeamConsumableService. A frontend context value, success title or closed modal is not proof the intended bucket/ledger changed.
| Symptom | Check |
|---|---|
| Command absent | Default export, slug, eager glob, effective frontend permission and seven-suggestion cap |
| Missing/incorrect argument | Declared positional order, named override, token boundaries and coercion limits |
| Quoted reason splits | Use separate --reason "two words"; avoid quoted equals syntax |
| Frontend allows, endpoint denies | Authenticated/verified/team context, super-admin middleware and actual request validation |
| Result disappears or changes | Singleton active-result replacement and close behavior |
| Duplicate mutation concern | Pending requests and ledger/result identity before retry; no generic exactly-once guarantee |
Validate a new command's allowed and denied principals, argument failures, context changes, repeated invocation, response errors and close behavior. No live balance mutation is required to verify parser behavior. Detailed financial/operational remediation belongs in separate runbooks.