# Commands A command declaration describes its slash name, arguments, caller permissions, and result. [`command.gleam`](../packages/albedo_sdk/src/albedo_sdk/command.gleam) owns the declaration, dispatch, catalog projection, and host routes. Clients also have presentation-only commands that are not daemon command declarations. ## The catalog The session command catalog describes prepared commands. [`command.catalog_json`](../packages/albedo_sdk/src/albedo_sdk/command.gleam) projects their metadata. The [CLI catalog client](../cli/internal/daemon/command_catalog.go) reads it. Resource commands identify their HTTP operation rather than exposing an endpoint for arbitrary slash-command execution. ## Contributing commands Extensions can declare commands through `CommandPlugin`, while managed extensions can supply dynamic commands. An extension declares a `Command(Invocation)`. Its handler receives an `Invocation`, which carries the session, the extension's storage handle bound to it, and the typed `StateOp` interface to session state. The host binds each declared command with `command.bind` into a `Command(Context)`, which the dispatchers run with a handle-free `Context`. Neither carries an inbox: a command reaches its own session through `StateOp`s and turns, and posting belongs to host routes and startup workers, whose contexts carry a gated inbox ([add a slash command](../docs/extensions.md#add-a-slash-command)). See [`Command`, `Invocation`, `Context`, and `StateOp`](../packages/albedo_sdk/src/albedo_sdk/command.gleam) and the [extension types](../packages/albedo_sdk/src/albedo_sdk/extension.gleam). The daemon builds every `Context`. [`command_state`](../apps/albedo/src/albedo/session/command_state.gleam) keeps each session actor's state closure by session ID. `command_state.context` serializes a state call through that actor. State calls return `command.StateError`: a missing actor is `SessionUnavailable`, a missing job is `JobNotFound`, and an output page no longer retained is `OutputLost(detail)`. Other failures carry their message in `Other(detail)`. A failed or timed-out state call returns `Other("session state call failed; outcome unknown")`. Match these variants when choosing a response. Use `command.state_error_text` only when displaying the failure. Core dispatch calls it directly. Extensions receive a context from the host instead: `host.Context.session_state` for the calling session, and `extension.Daemon.session_state` for a session a service request names. Command handlers run outside the session actor. A handler already running inside that actor must not call a command whose state operation waits on the actor, because that would deadlock. Model calls cannot invoke a command declared user-only or submit a user turn. `user_turn` controls delivery for a user invocation. See [`command.call`](../packages/albedo_sdk/src/albedo_sdk/command.gleam). ## Python bindings At kernel boot, the [Python commands plugin](../python/albedo_plugins/commands.py) creates an async method for each eligible model-callable command. Its signature and docstring come from the declaration. `commands.catalog()` reads the current catalog, and `commands.invoke(name, arguments)` invokes a model-callable command by name with text or a dictionary. Reserved, invalid, or later-added method names remain available through `invoke`. Model calls return data rather than submitting a turn. ## Client commands The [CLI command handling](../cli/internal/tui/commands.go) combines catalog entries with client presentation. Session settings changed by commands have the same persistence owners described in [settings](settings.md). Workspace-related operations are described in [workspaces](workspaces.md), and kernel operations in [kernel](kernel.md). The built-in resource declarations live in [`client.gleam`](../extensions/commands/src/albedo_ext_commands/client.gleam). Configuration commands bind the canonical configuration URL and observed ETag. The `putCompaction` declaration binds a client-owned `action_id`; CLI and web command adapters use their typed compaction workflow to allocate and retain it, recover an uncertain admission, and wait for the domain result. Generic command execution must not treat its 202 admission receipt as completed work. See [compaction receipts](operations.md#compaction-receipts). Title inference and `/retitle` are described under [generated titles](sessions.md#generated-titles). One slash name can carry a read and a change: `/shake` binds `getSessionMedia` without arguments and `shakeSessionMedia` with them, and the model calls the same declaration as `commands.shake`. Its state operation, `Shake`, needs `History` on another session. See [shake](media.md#shake). ## Related pages - [All topics](README.md) - [Change guidance](contributing.md) - [Persisted settings](settings.md) - [Plugins](plugins.md)