small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
albedo robot-docs plugins.md

Plugins #

Plugins are contributions declared by an extension, not independently installed packages. Plugin defines the host contracts.

Session contributions #

ContextPlugin loads workspace context. ToolPlugin declares instructions, tools, Python modules, and routes without allocating resources or doing I/O in the declaration. ManagedPlugin prepares a session contribution. OwnedManagedPlugin adds a preparation owner for resources that must survive handoff safely. CommandPlugin contributes session commands. See extension.gleam.

composition.gleam collects these contributions in registry order. Managed contributions can observe session events, provide a hook, and define adoption and close callbacks. Observers run inside the session actor and must only send and return. Resource close callbacks must be idempotent. OwnedManagedPlugin returns Result(Option(Owned), String). extension.owned(contribution, adopt, close) constructs the opaque value with both callbacks. None retains no resource or contribution. The opaque result prevents accidentally returning an ordinary contribution with default callbacks. Resource monitoring remains the allocator's responsibility.

Host route context #

host.Context supplies the store, session ID, workspace, and the loaded search, worktree, and image generation providers to kernel host routes. kernels.kernel_routes builds it from the same loaded Cached snapshot as the route composition. Reloads replace the callback for later calls. Calls already running keep their captured context, including the old workspace while a family move is deferred.

Routes that need only these values can be static ToolPlugin contributions, as in work and paperclips. Use context.workspace for their loaded workspace. The database's desired workspace and the process working directory can differ from it.

Image generation drivers #

ImagegenPlugin contributes a named imagegen.Provider. Its generate callback receives validated reference images and the session, profile, and call identities. It returns encoded image data and optional request and generation identifiers. The shared image generation extension owns driver selection and admission; Python owns local publication.

Run the request once. Do not retry an uncertain outcome or fall back to another service. The callback runs in a cancellable worker, so keep sockets there and ensure any resource-owning child terminates when that worker dies.

Owned worker helper #

worker.observer(owner, run, observed, wait_ms) starts an owned worker with worker.start and returns its opaque extension.Owned contribution. The contribution starts from extension.empty(). Its observe sends observed(handle, event) to the worker inbox. Its adopt and close are the started worker callbacks.

observer returns Error(Nil) when the worker does not start. The caller maps that error to its own startup message with result.replace_error. wait_ms is the startup wait passed to worker.start.

Daemon contributions #

The same Plugin type declares provider and model catalogs, login, services, startup, migrations, settings, cleanup, and state transfer. ServicePlugin defines an admission policy and a body limit for its routes. MigrationPlugin distinguishes schema migrations from data migrations. CleanPlugin runs for installed extensions when a session is deleted, including extensions that are disabled. See extension.gleam.

Startup callbacks run after the schema transaction commits. The host does not roll back an earlier successful startup if a later startup or dependency check fails. Extensions own the lifetime of long-lived startup resources.

Persisted extension settings #

Use settings.Section for a typed section decoder and validation. settings.update(section, encode, change) performs a locked read-modify-write of that section without extension-owned native code. Follow the typed update contract for encoder overlays, pure callbacks, defaults, and failure behavior. Credentials and multi-document mutations retain specialized owners.

HTTP services #

ServicePlugin serves routes below /extensions/<name>/ while the extension is enabled globally. Session selection does not control these routes. The daemon ingress applies the service's admission policy before calling its handler.

service.json(body_limit, handle) supplies daemon-token authentication and a fixed body limit. Its handler receives the daemon, path segments below the mount, and a buffered Request(BitArray). It returns a response or http_api.Failure. The adapter renders failures as problem responses and rejects negotiation that selects an event stream with 406 not_acceptable.

Route dispatch, query and body decoding, and domain error mapping remain extension-owned. Services that stream, serve non-JSON content, or need different admission policies use extension.Service directly. See Expose a JSON service for registration steps.

http_api.resource(url, etag, value) encodes resource envelopes. revision_etag(namespace, id, revision) formats integer-ID validators, and notification(status) encodes NotRequested, Queued, or Failed(detail). Callers retain URL and payload selection, fingerprint inputs, notification effects, invalidation, transactions, and precondition checks.

Client declarations #

client_api owns typed field kinds, declarative request bindings, and resource pages. ClientPlugin commands are validated during installation, before the extension initializer runs. A malformed command quarantines its extension with the command and field in the error. Installation behavior is owned by extension.install. After preparation, composition requires each client binding to name a command contributed by the same extension. A missing command makes that extension inactive for the session, closes its prepared contributions, and reports the extension and command names. Commands prepared by managed plugins are checked at this stage.

Build page actions with client_api.actions, which returns validated Actions or an error naming the action. Page requires this validated value. JSON services return declaration failures as 500 invalid_client_declaration instead of sending malformed controls to clients.

Validation rejects repeated or empty field names, action names, and binding keys, choices on other field kinds, empty choice lists, incompatible defaults, malformed JSON pointers, undeclared form inputs, and unmatched path placeholders. A null default means no preset value. Displayed defaults may bind only to row or session data. Actual row and session values are resolved and checked by the clients when the user opens a form. These declaration checks do not authorize requests or validate submitted domain values.