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

Add an extension #

Use this guide to add capabilities through an extension. Read the extension reference, plugin contracts, and shared contribution rules before choosing an owner.

Choose the contributions #

Declare the extension's name, description, requirements, plugins, and initializer with extension.Extension. Keep declarations free of I/O and environment capture. A sealed build caches them.

Choose plugin types from the current Plugin definition instead of copying an old inventory. Use ToolPlugin for static instructions, tools, Python modules, and host routes. Use ManagedPlugin when a contribution must be prepared before use. Use OwnedManagedPlugin when allocated resources must survive preparation handoff safely. If a route needs only the values on host.Context, keep the route in ToolPlugin and do not add a managed contribution that only returns routes.

Keep schema, data migrations, deletion cleanup, and transfer behavior with the extension that owns the data. See migrations and extension lifecycle rules.

Connect host routes #

Use host.Route for Python-to-host calls. A route receives host.Context, a method string, and dynamically typed arguments. It returns JSON or an error pair. The context supplies the store, the session ID, the loaded workspace, and the providers from the active composition.

Declare routes that need only context values in ToolPlugin. Follow the work route, which passes context.store and context.workspace to its handler. Paperclips also passes context.session. Use this loaded workspace instead of querying session settings or reading the process working directory. See the context snapshot contract.

Resolve providers from the supplied context. Do not capture the installation registry as a substitute for the active session composition. Keep HTTP service admission separate from session host routes. The extension HTTP contract describes caller permissions, conditional edits, and notifications.

Declare client operations #

Use ClientPlugin for human commands that read or change an HTTP resource. Start with client_api.operation_defaults, then override the bindings and result constraints the operation needs. Reuse text_field, integer_field, choice_field, and form_body when their defaults fit. Preserve custom labels, defaults, validators, and success statuses. Use a FieldKind variant when constructing a field directly. Build resource-page actions with client_api.actions and propagate its error before encoding the page. See client declaration checks.

Follow the work declaration and its page actions. Keep model host routes separate from HTTP operations. Read client API ownership for transport, recovery, and authorization boundaries.

Prepare session contributions #

Follow the schedule extension for a managed contribution that builds a command from the supplied store and session ID. Start from extension.empty() and fill the contribution fields you need.

For an OwnedManagedPlugin whose worker only observes session events, use worker.observer. Pass the preparation owner, the worker loop, the message constructor that wraps a session handle and event, and the startup wait in milliseconds. Wrap its owned result in Some and map its Error(Nil) to the extension startup message:

worker.observer(owner, run, Observed, 5000)
|> result.map(Some)
|> result.replace_error("the worker did not start")

observer builds the managed contribution from extension.empty(). Use worker.start when other callbacks need the worker inbox, then attach its lifecycle with extension.owned(contribution, started.adopt, started.close). Return Ok(None) only when preparation retains no resource or contribution. See the owned worker helper reference.

Keep event observers short. They run inside the session actor, so send work to its owner and return instead of blocking. Run command handlers outside the actor whose state operations they call. See plugin contracts and commands.

Give allocated resources an explicit cleanup owner. Make close callbacks idempotent. For owned preparation, establish lifecycle monitors before readiness and complete adoption before publication. Preserve saved selection when applying it fails. The shared lifecycle rules describe the required failure boundaries.

Report hooks #

If the contribution steers turns, add a hook to its managed value. Use hook.Event and hook.Verdict and the hook reference for events, merge rules, refusal behavior, and output visibility. A hook that only observes work must send the event to its owner and return hook.proceed promptly.

For calls inside Python cells, use albedo_plugins.hook. Use reported(name, fields) when method parameters map to hook arguments, or around(name, arguments, run) for an asynchronous callback. Execute with the rewritten arguments, not the original arguments. Use before and after when completion must be reported separately.

For command-hook configuration, inspect the parser in albedo_hook_command.py. The hook reference describes command execution and failure behavior. Command hooks are not a fail-closed security boundary.

Expose a JSON service #

For a buffered JSON API authenticated with the daemon token, import harness/extension/service as http_service. Add its result to the extension's plugin list:

extension.ServicePlugin(http_service.json(65_536, service.dispatch))

Choose a body limit for the service's operations. Implement service.dispatch(daemon, path, request) with a Result(Response(mist.ResponseData), http_api.Failure) return value. Keep route matching, query and body decoding, and domain error mapping there. Follow the work service and reuse the decoders in http_api.

Read the HTTP service contract for negotiation and admission behavior. Use extension.Service directly when routes need streaming, non-JSON responses, different authentication, or different body limits per route.

Register and check the extension #

Add the constructor to extensions.declared. Set its default selection there only if the feature should be enabled by default. Keep discovery read-only and ensure failed preparation leaves no callable contributions from the rejected bundle.

Exercise the externally visible change through the shared daemon harness. Cover the relevant activation, failure, and cleanup paths. Update the canonical feature page with the behavior, limits, and guidance callers need, then follow the repository checks.