# Extensions An extension is a named bundle of plugins. The registry in [extensions.gleam](../apps/albedo/src/albedo/composition/extensions.gleam) declares installed extensions and defaults. The [extension types](../packages/albedo_sdk/src/albedo_sdk/extension.gleam) define their contributions. See [plugins](plugins.md) for the host contracts, [Write an extension](../docs/extensions.md) for a working Gleam example, and the [extension API reference](../docs/extension-api.md) for function-level documentation and generated signatures. ## The harness base Python is part of the harness, not an extension. Every session composes the [harness base](../apps/albedo/src/albedo/kernel/base.gleam) ahead of its selected extensions: the `python` tool, the kernel's `cells`, `user_shell_output`, and `session` host routes, the `/kernel` command and its client bindings, and the remote-place context. Every session also runs a kernel. No selection adds or removes them, so every extension may rely on the kernel and on the Python bindings that it and other extensions contribute. Do not declare a requirement on `python`. The runtime builds the base once at startup and publishes it with the installed extensions (`Installed.base` in [runtime/state.gleam](../apps/albedo/src/albedo/runtime/state.gleam)), and `composition.compose` takes that shared value. Do not call `base.contribution()` per session: a base built on a composing process's heap is copied into every session's composition, about 10 KB each. The base keeps the owner name `python`, which the python extension had in earlier releases. Client command ids such as `python:/kernel:kernelAction` and the kernel's transfer adapter keep that name. Extension install refuses an extension with that name. A saved choice that names `python`, in the global `enabled` section, a session's `session_extensions` rows, or a configuration or defaults patch from an older client, is accepted and changes nothing. See `selection.select` and `selection.change_defaults` in [selection.gleam](../apps/albedo/src/albedo/composition/selection.gleam). ## Installed and enabled Installation makes an extension known to the daemon. Session selection combines global defaults with stored session overrides. `selection.select` preserves registry order and handles exclusive compaction strategies. `selection.validate_selection` checks requirements before the selection is used. A quarantined extension appears in summaries with its reason and no capabilities. See [selection.gleam](../apps/albedo/src/albedo/composition/selection.gleam). ## Session composition [`composition.compose`](../apps/albedo/src/albedo/composition/composition.gleam) loads static contributions and prepares managed contributions for the harness base and then each selected extension. `composition.extensions` lists only the selected extensions. A failed load, failed preparation, module clash, or duplicate tool, command, or route leaves that extension inactive and adds a warning. Extensions compose in registry order, except that each one composes after the selected extensions it requires. An extension whose requirement is unselected or already inactive is left out before it loads or prepares, so it claims no tool, command, or route name that a later extension could use. A requirement cycle composes in registry order, and its members are removed afterwards if any requirement ends up inactive. A composition is immutable. A refresh prepares a replacement, and the host closes the composition that loses. Managed resources close in reverse preparation order. Adoption failure closes the candidate. Owned callbacks return an optional opaque `Owned` value with explicitly attached adoption and close callbacks. `None` contributes nothing. The ownership contract is defined by `PreparationOwner`, `Preparation`, and `OwnedManagedPlugin` in [extension.gleam](../packages/albedo_sdk/src/albedo_sdk/extension.gleam). During reload, application workers borrow the adopted candidate and previous session. The runtime settles their results and closes the losing resources. See [reload ownership](runtime.md#extension-reload-ownership) for rejection, worker death, and late-result cleanup. ## Extension settings `SettingsPlugin` registers an extension's settings declaration. [`settings/declared.gleam`](../packages/albedo_sdk/src/albedo_sdk/settings/declared.gleam) collects declarations and validates declared values. [`core_settings.all`](../apps/albedo/src/albedo/settings/core_settings.gleam) lists the daemon's own sections before each extension's `extension.settings_sections`. The daemon exposes them through its settings resources. See [persisted settings](settings.md) for conditional updates and recovery, and [plugins](plugins.md) for contribution types. ### Settings panes For a field editor, give the section the same name as its extension ID and register its editable fields with `SettingsPlugin`. The clients match sections from `/settings/extension_settings` to globally enabled extensions outside quarantine. The section label names the entry under **settings → extensions**. The [extension author guide](../docs/extensions.md#read-settings) shows a complete field declaration. For a service sign-in, register a `LoginPlugin` with kind `oauth.Service`. The clients match providers and saved service accounts from `/auth` by provider ID. Reuse the section name as the provider ID to put the account controls beside the fields. A service with only an account gets its own entry. A saved service account remains accessible when its provider stops offering sign-in. Model accounts belong under **providers**. The [web pane builder](../web/src/lib/settings/panes.ts) and [terminal settings index](../cli/internal/tui/settings_index.go) own navigation and controls. Both generate field editors from the declaration. A service with a dedicated management screen also shows its declared settings in its pane. For example, **Discord** includes message debounce. Its bot manager appears in the same web pane and opens from **manage Discord** in the terminal when a session is open. See [web settings](web.md#settings) and [terminal settings](tui.md#settings). ## SDK imports and native bindings An extension belongs to the module path `albedo_ext_/` and its top module, `albedo_ext_`, which exports every constructor the directory builds. The [registry](../apps/albedo/src/albedo/composition/extensions.gleam) imports only these top modules. Every extension is the workspace package `albedo_ext_`, which keeps both under its `src/`, such as [`extensions/checklist`](../extensions/checklist) ([extension packages](workspace-packages.md#current-packages)). The package depends on what it imports and never on another extension; `test/packages.sh check` refuses such a dependency. Use the SDK's modules for shared extension helpers and contracts, and import modules within your own extension for feature behavior. The SDK is the workspace package [`albedo_sdk`](workspace-packages.md#current-packages). Its modules are `albedo_sdk/*`. Standard library and other declared dependency imports, including [workspace packages](workspace-packages.md) and the [shared extension libraries](#shared-extension-libraries), remain available. Extensions import nothing from the core `albedo/*` modules. Storage is the scoped [`sdk/storage`](../packages/albedo_sdk/src/albedo_sdk/storage.gleam) handle described in [extension storage](#extension-storage), and the HTTP contract is [`sdk/http_api`](../packages/albedo_sdk/src/albedo_sdk/http_api.gleam). No other harness module is open to extensions. A workspace location is the SDK's [`sdk/location`](../packages/albedo_sdk/src/albedo_sdk/location.gleam) value, and an extension reaches the hosts workspaces live on through the `hosts` [capability](#extension-capabilities), which core's `locations` and `ssh` serve. The worktree contract is [`sdk/worktree`](../packages/albedo_sdk/src/albedo_sdk/worktree.gleam), and an extension reaches the host's worktree service through the `worktrees` capability, which core's [`worktree`](../apps/albedo/src/albedo/workspace/worktree.gleam) serves. A preparation reads its session's project files, instruction files, and capability preferences through `extension.Preparation`'s `project_files`, `instructions`, and `preferences`, which core's [`project_files`](../apps/albedo/src/albedo/workspace/project_files.gleam), [`instruction_files`](../apps/albedo/src/albedo/workspace/instruction_files.gleam), and [`capability_preferences`](../apps/albedo/src/albedo/settings/capability_preferences.gleam) answer. They are the session's own data, not capabilities. The skills catalog is part of the SDK, under [`sdk/skills/`](../packages/albedo_sdk/src/albedo_sdk/skills). Every kernel module is private to core, including [`albedo/kernel`](../apps/albedo/src/albedo/kernel.gleam), [`kernel/journal`](../apps/albedo/src/albedo/kernel/journal.gleam), [`kernel/jobs`](../apps/albedo/src/albedo/kernel/jobs.gleam), [`kernel/resources`](../apps/albedo/src/albedo/kernel/resources.gleam), [`kernel/tool`](../apps/albedo/src/albedo/kernel/tool.gleam), and the [harness base](#the-harness-base) modules, along with link, launch, recovery, termination, and cell storage. Extensions take the kernel's types from [`sdk/kernel`](../packages/albedo_sdk/src/albedo_sdk/kernel.gleam), and read its job book and recorded processes through the `kernel_jobs` and `kernel_resources` [capabilities](#extension-capabilities). The saved extension selection is the `selection` capability, not an import of `extension/selection`. Reach the kernel through Python bindings and host routes, not by driving cells. Extensions also import the [workspace packages](#workspace-packages) listed below directly. Transfer adapters import [`sdk/transfer`](../packages/albedo_sdk/src/albedo_sdk/transfer.gleam) for the `Adapter`, `Table`, `Shift`, and `Activation` types. Use supplied host or session callbacks for daemon effects that the SDK does not expose. Follow the [shared contribution rules](contributing.md). The existing SDK modules are: - [`sdk/extension`](../packages/albedo_sdk/src/albedo_sdk/extension.gleam): Extension declarations, contributions, preparation and startup contexts, and preparation ownership. - [`sdk/storage`](../packages/albedo_sdk/src/albedo_sdk/storage.gleam): An extension's storage handle and the store operations it runs its own SQL through. See [extension storage](#extension-storage). - [`sdk/service`](../packages/albedo_sdk/src/albedo_sdk/service.gleam): Buffered JSON extension HTTP services. - [`sdk/http_api`](../packages/albedo_sdk/src/albedo_sdk/http_api.gleam): HTTP failures, problem and JSON replies, request decoding through `albedo_json`'s strict decoder with field policy, which representations a route offers, preconditions, revision validators, and paging tokens shared with the daemon. It reads Accept headers through `albedo_web/accept`. - [`sdk/worker`](../packages/albedo_sdk/src/albedo_sdk/worker.gleam): Owned worker startup and adoption. - [`sdk/startup`](../packages/albedo_sdk/src/albedo_sdk/startup.gleam): Boot-stage timing under `ALBEDO_BOOT_TIMING=1`. - [`sdk/host`](../packages/albedo_sdk/src/albedo_sdk/host.gleam): Context and routes for kernel host calls. - [`sdk/kernel`](../packages/albedo_sdk/src/albedo_sdk/kernel.gleam): The `Kernel` handle a tool context and `command.KernelRead` carry, the live background `Job` that `command.KernelJobs` projects, the job book's records, pages and failures, and the `Jobs` and `Resources` records of the `kernel_jobs` and `kernel_resources` capabilities. The kernel runtime behind the handle stays in core, which builds those records (`kernel/jobs.capability` and `kernel/resources.capability`). - [`sdk/python_repair`](../packages/albedo_sdk/src/albedo_sdk/python_repair.gleam): The python tool's replay repair: whether cell source shows token-stream corruption, and `replay_item`, which elides that source from python calls through `replay.rewrite_tool_input` and leaves every other item unchanged. - [`sdk/rpc`](../packages/albedo_sdk/src/albedo_sdk/rpc.gleam): Host-call dispatch and argument decoding. - [`sdk/selection`](../packages/albedo_sdk/src/albedo_sdk/selection.gleam): The `Selection` record of the `selection` capability: whether an extension is enabled by default, whether the session permits it, and the models whose context cap is raised. [Core selection](../apps/albedo/src/albedo/composition/selection.gleam) builds it. `session_allows` checks the session override for a globally enabled extension. A failed read denies delivery. - [`sdk/command`](../packages/albedo_sdk/src/albedo_sdk/command.gleam): Session command declarations and state operations. - [`sdk/follow`](../packages/albedo_sdk/src/albedo_sdk/follow.gleam): Core history and worktree changes that `FollowPlugin` callbacks receive. - [`sdk/hook`](../packages/albedo_sdk/src/albedo_sdk/hook.gleam): Turn and tool hook events and verdicts. - [`sdk/tool`](../packages/albedo_sdk/src/albedo_sdk/tool.gleam): Retrieval tool schemas, paging, and rendering. - [`sdk/compaction`](../packages/albedo_sdk/src/albedo_sdk/compaction.gleam): The compaction `Strategy` contract, its `Context`, and request preparation. See [compaction](compaction.md). - [`sdk/transfer`](../packages/albedo_sdk/src/albedo_sdk/transfer.gleam): Transfer adapters, the tables and files a session's move carries, and `occurred_in`. See [moving a session](workspaces.md#moving-a-session). - [`sdk/client_api`](../packages/albedo_sdk/src/albedo_sdk/client_api.gleam): Declarative client HTTP operations. - [`sdk/imagegen`](../packages/albedo_sdk/src/albedo_sdk/imagegen.gleam): Provider-neutral image generation contracts. - [`sdk/web_search`](../packages/albedo_sdk/src/albedo_sdk/web_search.gleam): Web search provider contracts and selection. - [`sdk/search`](../packages/albedo_sdk/src/albedo_sdk/search.gleam): Transcript search with bounded database reads. - [`sdk/sessions`](../packages/albedo_sdk/src/albedo_sdk/sessions.gleam): What the `sessions` table says about sessions: their names, workspaces, and whether a transfer is importing them or moved them. See [extension storage](#extension-storage). - [`sdk/page`](../packages/albedo_sdk/src/albedo_sdk/page.gleam): Sidebar rows and command argument parsing. - [`sdk/http`](../packages/albedo_sdk/src/albedo_sdk/http.gleam): Buffered HTTP requests under albedo's network policy. Each call sends through [`albedo_http/buffered`](../packages/albedo_http/src/albedo_http/buffered.gleam) with the caller's route and albedo's trusted roots, and words the failure. Build `buffered.Timeouts` and `buffered.Body`, and read `buffered.Response`. `request` returns status, headers, and bytes, including non-2xx responses. `failure` formats status errors; `locations` follows redirect locations concurrently under the caller's route. - [`sdk/settings`](../packages/albedo_sdk/src/albedo_sdk/settings.gleam): Extension settings declarations and decoding. - [`sdk/settings/declared`](../packages/albedo_sdk/src/albedo_sdk/settings/declared.gleam): The registry of declared extension settings and validation of their values. See [extension settings](#extension-settings). - [`sdk/credentials`](../packages/albedo_sdk/src/albedo_sdk/credentials.gleam): Credential recovery, persistence, and notifications. `text` and `lenient_text` treat missing or non-string credential fields as empty strings. - [`sdk/key_accounts`](../packages/albedo_sdk/src/albedo_sdk/key_accounts.gleam): Typed snapshots of profile-bound key accounts. `fast_mode` selects the current connection before invoking the provider's support callback. A selection failure returns `FastUnknown` with the provider's error prefix. The callback owns model and endpoint eligibility, mode, source, and unavailable reasons. - [`sdk/key_environment`](../packages/albedo_sdk/src/albedo_sdk/key_environment.gleam): The runtime's composed `KeyEnvironmentPlugin` lookups. Pass the value from the context you receive to key account readers. See [typed key accounts](auth.md#typed-key-accounts). - [`sdk/accounts`](../packages/albedo_sdk/src/albedo_sdk/accounts.gleam): Pure account pool ordering. - [`sdk/rotation`](../packages/albedo_sdk/src/albedo_sdk/rotation.gleam): Rate-limit account rotation. - [`sdk/oauth`](../packages/albedo_sdk/src/albedo_sdk/oauth.gleam): OAuth sign-in and token helpers. Build `DeviceFlow` inside `oauth.device`'s start callback so runtime environment overrides are read after sealed declarations load. It runs a device flow through [`albedo_oauth/device`](../packages/albedo_oauth/src/albedo_oauth/device.gleam), sending through `sdk/http` and wording each failure. - [`sdk/oauth_flows`](../packages/albedo_sdk/src/albedo_sdk/oauth_flows.gleam): The sign-in service that runs `oauth.Login` declarations. The daemon starts it and passes the opaque `Service` handle to its HTTP handlers. Extensions do not call it. See [sign-in](auth.md#sign-in). - [`sdk/google_oauth`](../packages/albedo_sdk/src/albedo_sdk/google_oauth.gleam): Shared Google token renewal. - [`sdk/model_lists`](../packages/albedo_sdk/src/albedo_sdk/model_lists.gleam): Provider model-list helpers. - [`sdk/usage_feed`](../packages/albedo_sdk/src/albedo_sdk/usage_feed.gleam): Usage driver execution and bounded I/O. The SDK also provides these helpers. - [`sdk/cached_fetch`](../packages/albedo_sdk/src/albedo_sdk/cached_fetch.gleam): The bounded fetch of a url-backed cache file. It allows https, and plain http only on loopback. `refresh` starts at most one background fetch per refresh key when the file is stale. `reload` fetches now and reports the failure. A fetch commits through `commit`, a rename that a failed fetch never reaches. `isolated` runs a large decode in a fresh process. - [`sdk/credential_store`](../packages/albedo_sdk/src/albedo_sdk/credential_store.gleam): `creds.json` reads, private atomic writes of JSON documents through `albedo_file`, the saved account sections, and cache file age. Hold the settings lock from [`sdk/settings_store`](../packages/albedo_sdk/src/albedo_sdk/settings_store.gleam) across a read and the write that depends on it. - [`sdk/settings_documents`](../packages/albedo_sdk/src/albedo_sdk/settings_documents.gleam): Whole settings documents such as `creds.json`, read and committed as a group through the settings store. Hold `with_lock` across a read and the commit that depends on it. `mcp_secrets` reads the `mcp` section of `creds.json`. - [`sdk/host_resources`](../packages/albedo_sdk/src/albedo_sdk/host_resources.gleam): What the host lends the SDK outside any session: albedo's priv directory, the two Python launch policies, `open_python` for a long-running helper port an extension reads itself and `open_kernel_script`, and the CA roots albedo's trust policy keeps, which `network_context` passes to every connection. See [host resources](runtime.md#host-resources). - [`sdk/priv`](../packages/albedo_sdk/src/albedo_sdk/priv.gleam): Paths and reads of files shipped in albedo's priv directory, as the host installed it. A failed read names the path and the file error. `shipped` names a shipped file only when there is an installed priv directory. - [`sdk/model_facts`](../packages/albedo_sdk/src/albedo_sdk/model_facts.gleam): Albedo's own facts about models, merged by [`sdk/layered_table`](../packages/albedo_sdk/src/albedo_sdk/layered_table.gleam) from the shipped default, a remote copy, and local overrides. [`sdk/context_limits`](../packages/albedo_sdk/src/albedo_sdk/context_limits.gleam), [`sdk/cache_ttl`](../packages/albedo_sdk/src/albedo_sdk/cache_ttl.gleam) and [`sdk/media_facts`](../packages/albedo_sdk/src/albedo_sdk/media_facts.gleam) read its context window, prompt-cache lifetime and clip sections. See [model facts](model-facts.md). - [`sdk/location`](../packages/albedo_sdk/src/albedo_sdk/location.gleam): Where a session works, a local path or `[user@]host:/path`, parsed, normalized, and spelled. It reads nothing: `label` and `to_json` take the ssh config lookup from their caller. See [locations](workspaces.md#locations). - [`sdk/hosts`](../packages/albedo_sdk/src/albedo_sdk/hosts.gleam): What a host's probe observed, why a host is not ready (`Failure`), and the `Hosts` record of the `hosts` capability. Core's `ssh` and `locations` run every operation. - [`sdk/worktree`](../packages/albedo_sdk/src/albedo_sdk/worktree.gleam): The worktree contract: the provider a version-control extension contributes, the `Worktree` record, the `Worktrees` record of the `worktrees` capability, the `Origins` reads linked groups take, and helpers for providers. See [worktrees](worktrees.md). - [`sdk/capabilities`](../packages/albedo_sdk/src/albedo_sdk/capabilities.gleam): Skill, instruction, and MCP preferences, their validation, and the precedence where a session's choice overrides the global default. The host loads them: core's [`capability_preferences`](../apps/albedo/src/albedo/settings/capability_preferences.gleam) reads `capabilities.json` and the session's saved choices, and a preparing extension reads its session's through `Preparation.preferences`. - [`sdk/links`](../packages/albedo_sdk/src/albedo_sdk/links.gleam): Linked workspace groups. Each read takes the `worktree.Origins` the caller's context carries. See [linked workspaces](workspaces.md#linked-workspaces). - [`sdk/skills/catalog`](../packages/albedo_sdk/src/albedo_sdk/skills/catalog.gleam): The Agent Skills catalog behind each session's `skills` configuration, with its scanner, frontmatter policy, and prompt mentions. `scan_at` reads project skills from the directory its `readable` argument answers. See [skills](skills.md). - [`sdk/file_fingerprint`](../packages/albedo_sdk/src/albedo_sdk/file_fingerprint.gleam): A file's content fingerprint. - [`sdk/local_command`](../packages/albedo_sdk/src/albedo_sdk/local_command.gleam): A bounded local command, how it ended, and how its output is collected. The host runs it: core's [`local_run`](../apps/albedo/src/albedo/workspace/local_run.gleam) finds the program on `PATH` and starts it with the usage feed's environment allowlist. The SDK starts no process itself. - [`sdk/helper`](../packages/albedo_sdk/src/albedo_sdk/helper.gleam): Python helper subprocess execution with explicit outcomes. - [`sdk/renderer`](../packages/albedo_sdk/src/albedo_sdk/renderer.gleam): Runs of the optional `albedo-render` binary, its report lines, and a scratch directory deleted after each render. The compiler and [package checks](workspace-packages.md#enforcement) enforce extension imports. Each extension builds as a standalone package. It cannot import daemon or host harness modules, and the package checker refuses a dependency on albedo or another extension. Use SDK helpers, supplied callbacks, or context capabilities for host behavior. Shared code belongs in the [shared libraries](#shared-extension-libraries), and provider contributions still resolve from the active composition. Two lint rules enforce the remaining boundaries in the commit and review profiles: - `albedo_extension_external` flags `@external(erlang, M, _)` unless `M` has an `.erl` file in the extension's package `src/`. OTP modules also violate this rule. Call an SDK Gleam helper instead of its native implementation, or keep feature-specific natives with their owner. A packaged extension's binding takes the package's name, `albedo_ext__ffi`, as memory's does. - `albedo_core_extension_import` checks every Gleam module in albedo's own `src/`. Only the registry [`extensions.gleam`](../apps/albedo/src/albedo/composition/extensions.gleam) may import an extension, and only its top module `albedo_ext_`. It rejects internal extension imports even in the registry, and bindings to extension-owned Erlang modules from any core module. The SDK also builds independently of albedo and extensions. [`albedo_package_external`](gleam-lint.md#package-bindings) refuses its bindings to their Erlang modules. Move reusable behavior into the SDK, or have the host supply it through a context capability. Core reaches extension behavior through plugin contracts in the active composition. These rules read Gleam source only. Core Erlang modules must not call extension natives, and SDK and extension Erlang natives must not call daemon-owned Erlang modules. No lint rule checks those Erlang calls, so check them in review. Process-wide infrastructure lives where every layer can use it, in process helpers such as [`albedo_process`](../packages/albedo_process/src/albedo_process.gleam) in [workspace packages](workspace-packages.md). [`albedo_process/registry`](../packages/albedo_process/src/albedo_process/registry.gleam) holds keyed ETS registries whose tables outlive their callers. [`sdk/priv`](../packages/albedo_sdk/src/albedo_sdk/priv.gleam) answers albedo's priv directory from the [host resources](runtime.md#host-resources) the daemon installed at boot. The daemon keeps its own handler registries in such tables, each behind a typed handle in the module that owns it, such as the coordinator in [`session_control`](../apps/albedo/src/albedo/session/session_control.gleam) and the state closures in [`command_state`](../apps/albedo/src/albedo/session/command_state.gleam). Extensions reach them only through capabilities in their context, such as `control` and `session_state`, that they [declare](#extension-capabilities). Do not let the SDK or an extension find a process, handler, or callback that carries daemon or extension behavior through a process-wide registration, such as a registered name, a registry key, a persistent term, or a named table. Pass a capability or opaque handle in a context instead. The one exception is the [host resources](runtime.md#host-resources) record, which the host installs once per VM for work outside any session and never changes. Caches, single-flight claims, subscriptions, and locks may stay process-wide, because they hand out no behavior. The same rule covers a process an extension starts itself. Create its handle in the `StartupPlugin` callback and return the `extension.Started` contributions that use it, as described in [startup plugins](plugins.md#daemon-contributions). The first four rules do not restrict SDK implementation imports or JavaScript external bindings. The [lint profiles](gleam-lint.md#extension-boundary-review) run the same boundary checks. Two checks enforce the process-wide registration rule above in SDK, extension, and workspace package code. The `albedo_process_registration` lint rule reads Gleam bindings and the gleam_erlang and gleam_otp naming APIs. The Erlang registration check scans `.erl` and `.hrl` files. Both fail on a use that is not in the [reviewed allow-list](../tools/lint/src/albedo_lint/registrations.gleam). Add an entry only for a cache, single-flight claim, subscription, lock, VM-wide setting, or handle name, with its reason. A handle name is a fresh name from `process.new_name` that an opaque handle holds so its supervised process keeps one address across restarts. The handle is the interface callers use, not enforced isolation: the name is registered, and any Erlang code could find it among the registered names. Do not find a process by enumerating registered names, even by a known prefix. Test probes under `test/` may do so to inspect a running daemon. Fix any other finding by passing a capability or handle in a context. [Gleam lint](gleam-lint.md#process-wide-registration-checks) describes what each check matches. ### Workspace packages The general BEAM helpers live in [workspace packages](workspace-packages.md) under `packages/`. They are not part of the SDK and import nothing from albedo. Extensions, the SDK, and the daemon import their Gleam APIs directly; the boundary rules treat them as declared dependencies. Do not bind a package's Erlang modules with `@external` from an extension. - [`albedo_protect`](../packages/albedo_protect/src/albedo_protect.gleam): Callback crash recovery as a result value, a typed `rescue` that can raise the crash again, and `finally` for cleanup that must run however a callback ends. - [`albedo_clock`](../packages/albedo_clock/src/albedo_clock.gleam): System and monotonic clocks in explicit units, timers and sleeps that a test can scale, and UTC and RFC 3339 text. `format_rfc3339` writes the millisecond timestamps HTTP replies carry. See [clocks](runtime.md#clocks). - [`albedo_bytes/scalars`](../packages/albedo_bytes/src/albedo_bytes/scalars.gleam): Scalar-bounded `length`, `take`, `drop`, and `tail` for previews and names. See [Unicode scalar limits](runtime.md#unicode-scalar-limits). - [`albedo_bytes/digest`](../packages/albedo_bytes/src/albedo_bytes/digest.gleam): Hash, hex, base64, HMAC, and constant-time comparison helpers. - [`albedo_bytes/ids`](../packages/albedo_bytes/src/albedo_bytes/ids.gleam): Random and unique identifier helpers, including a version-4-shaped UUID derived from a seed. - [`albedo_bytes/term_codec`](../packages/albedo_bytes/src/albedo_bytes/term_codec.gleam): The Erlang external term format for caches and fingerprints that earlier daemons wrote. `decode_safe` refuses bytes that would create unknown atoms or functions. `tuple` and `binary` check decoded shapes exactly. Use JSON for new persisted data. - [`albedo_bytes/zlib`](../packages/albedo_bytes/src/albedo_bytes/zlib.gleam): zlib compression and inflation bounded by a caller's byte limit. A damaged stream or checksum mismatch is an error. - [`albedo_bytes/text`](../packages/albedo_bytes/src/albedo_bytes/text.gleam): OTP character data as text, keeping an incomplete or invalid conversion apart from a value the converter refuses, and every match's captured groups. - [`albedo_env`](../packages/albedo_env/src/albedo_env.gleam): Environment variable lookup. `lookup` tells an unset variable from an empty one, and `get` reads both as `""`. Read a variable during resolution or startup callbacks, never while constructing an extension's declaration: a sealed build caches declarations, so a value read there would be frozen into the build. `set` and `unset` change the VM's environment, which every process shares; extensions do not call them. - [`albedo_env/log`](../packages/albedo_env/src/albedo_env/log.gleam): Warning, error, and debug messages for the daemon's log. Never include secrets or tokens. - [`albedo_process/actor_call`](../packages/albedo_process/src/albedo_process/actor_call.gleam): Monitored actor calls that answer a timeout or a dead callee as a value. - [`albedo_process/memo`](../packages/albedo_process/src/albedo_process/memo.gleam): Typed cache handles with explicit expiry clocks and decoded reads. The owner sweeps expired entries every second. Each namespace keeps at most 1024 entries and evicts its oldest write when full. - [`albedo_process/lock`](../packages/albedo_process/src/albedo_process/lock.gleam): A mutex per key within the node. `hold` waits `Within` a limit or `Forever` and answers `Error(Nil)` when the key stays busy. - [`albedo_process/parallel`](../packages/albedo_process/src/albedo_process/parallel.gleam): Linked concurrent calls with caller lifetime, a bound, and answers in the items' order. A map inside a worker runs serially. Workers start without the caller's route, so a caller that makes requests uses `map_carrying` with [`network_context.carried`](../packages/albedo_sdk/src/albedo_sdk/network_context.gleam). - [`albedo_process/once`](../packages/albedo_process/src/albedo_process/once.gleam): Single-flight work shared by concurrent callers. The returned process runs the job; killing it cancels that job. It does not carry the route; a job routes itself. - [`albedo_process/subscriptions`](../packages/albedo_process/src/albedo_process/subscriptions.gleam): One-shot keyed wakeups with owner-death and explicit close cleanup. Subscribe before reading state and publish after commit. Handles belong to their creating process; callers must bound concurrent subscriptions. - [`albedo_process/pinned`](../packages/albedo_process/src/albedo_process/pinned.gleam): Values shared with every process without copying, under a namespace and key. Each `put` and `erase` costs a global garbage collection pass, so pin only values that change rarely. - [`albedo_process/flag`](../packages/albedo_process/src/albedo_process/flag.gleam): Flags in the calling process's dictionary that last as long as that process. Use a key type your module owns. - [`albedo_process/within`](../packages/albedo_process/src/albedo_process/within.gleam): Work on a helper process that the caller gives up on, and kills, at a deadline. See [reuse runtime helpers](contributing.md#reuse-runtime-helpers). - [`albedo_process`](../packages/albedo_process/src/albedo_process.gleam): Process labels, callback names that leave out a closure's environment, and garbage collection once a heap grows. - [`albedo_ports`](../packages/albedo_ports/src/albedo_ports.gleam): Typed `open_port` settings and events, port reads that select only the port's own messages, writes and closes that tolerate a closed port, and the deadline kill. - [`albedo_ports/subprocess`](../packages/albedo_ports/src/albedo_ports/subprocess.gleam): Credential helpers with bounded stdout and timeouts, the command environment allowlist, and PATH lookup. - [`albedo_http`](../packages/albedo_http/src/albedo_http.gleam): The streaming HTTP/1.1 client provider wires and MCP over HTTP use. Open albedo's outbound connections with [`network_context.connection_options()`](../packages/albedo_sdk/src/albedo_sdk/network_context.gleam), which carries the [outbound route](network.md) and albedo's trusted roots, not with `albedo_http.options()`. [`albedo_http/body`](../packages/albedo_http/src/albedo_http/body.gleam) adds deferred and digest parts and compression to a request body. See [provider requests](provider-requests.md#transport). For a buffered request, call `sdk/http`, which passes albedo's options to `albedo_http/buffered`. - [`albedo_sse`](../packages/albedo_sse/src/albedo_sse.gleam): An incremental, bounded Server-Sent Events parser. - [`albedo_file`](../packages/albedo_file/src/albedo_file.gleam): File reads and private atomic writes by path. Join a name to a home with `albedo_file.join`. `read_optional` distinguishes absence from read failure so a save can preserve an unreadable existing file. Bounded prefix and range reads close descriptors on every outcome. `write_private` replaces a file through a synced temporary file with mode 0600. `with_lock` serializes a complete cache update for one path within the VM, waiting `Forever` or `Within` a limit; it is separate from credential transactions and does not coordinate other OS processes. - [`albedo_file/info`](../packages/albedo_file/src/albedo_file/info.gleam): What a path names, its kind, size, times, mode, device, and inode, following links with `read` or not with `read_link`, and directory listings. A missing path is `Missing`. Check that a secret file is a private regular file with `read_link` before reading it. - [`albedo_file/revision`](../packages/albedo_file/src/albedo_file/revision.gleam): A file's size and modification time, for caches derived once per file revision. - [`albedo_file/journal`](../packages/albedo_file/src/albedo_file/journal.gleam): Durable group replacement of files through a recovery record. The settings store publishes through it; extensions save settings through `sdk/settings` instead. - [`albedo_json`](../packages/albedo_json/src/albedo_json.gleam): Strict JSON decoding into native terms that refuses duplicate keys and trailing content, and JSON encoding of native terms. Encode a native term through it rather than binding `json:encode`. [`albedo_json/fields`](../packages/albedo_json/src/albedo_json/fields.gleam) reads the common shape of a decoded provider event's fields before falling back to a decoder, and [`albedo_json/decoding`](../packages/albedo_json/src/albedo_json/decoding.gleam) words a decode failure without its values. - [`albedo_model`](../packages/albedo_model/src/albedo_model.gleam): The provider-neutral model types: requests, inputs, tools, stream events, replay items, images, usage, errors and refusals. Provider extensions build requests and read turns through them, imported as `types`. Its `replay`, `reasoning`, `refusal` and `cost` modules hold replayed messages and tool calls, reasoning fields, typed provider refusals and reported costs, and `size` is the only token estimator. - [`albedo_image`](../packages/albedo_image/src/albedo_image.gleam): An image's MIME type, dimensions, and size read from canonical base64 PNG, JPEG, or WebP under a caller's byte limit. Admit an image to a request through `sdk/image`, which applies albedo's limit. - [`albedo_web/accept`](../packages/albedo_web/src/albedo_web/accept.gleam) and [`albedo_web/etag`](../packages/albedo_web/src/albedo_web/etag.gleam): Accept and Accept-Encoding parsing and ranking, and strong entity tags. An extension service negotiates through `sdk/http_api` and `sdk/service`, not directly. - [`albedo_jwt`](../packages/albedo_jwt/src/albedo_jwt.gleam): RS256-signed JWTs from a PEM private key, for service-account assertions. The caller chooses the claims and their times. - [`albedo_oauth/device`](../packages/albedo_oauth/src/albedo_oauth/device.gleam): RFC 8628 device authorization over a send function the caller supplies. Extensions describe a device flow with `oauth.DeviceFlow` rather than calling it. - [`albedo_oauth/listener`](../packages/albedo_oauth/src/albedo_oauth/listener.gleam): The loopback listener that serves a sign-in's browser redirect. Only `oauth_flows` uses it. See [sign-in](auth.md#sign-in). ## Extension storage Each extension declares the tables it creates in the `tables` field of its [`extension.Extension`](../packages/albedo_sdk/src/albedo_sdk/extension.gleam). Write the list as a `pub const tables: List(String)` of string literals in a Gleam module under the extension's directory, and pass that constant to the constructor. The lint reads the constant, not the constructor call. Extensions in the same directory, such as `lcm` and `lcm-memory`, share the directory's declaration. List only tables a `CREATE TABLE` in that directory makes, or in a [shared library](#shared-library-tables) whose tables the directory owns, whose own `tables` constant the extension passes: a core table in `tables` is a lint finding, not a way to write it. See [Gleam lint](gleam-lint.md#extension-storage-rules) for the two tables allowed explicitly. Core tables belong to the daemon, not to an extension: `sessions`, `session_family`, `mail`, `transcript`, `transfer_occurrences`, `session_extensions`, and the other tables the daemon creates. Extension SQL names only the extension's own tables. Read or change a core table through a typed core or SDK operation that takes the extension's handle, never through extension SQL. Those operations apply the capability and session rules ([extension capabilities](#extension-capabilities)), which no lint can check in SQL. For example, an extension that was renamed moves sessions' choices of its former name with `extension.rename_session_choices`, which owns the write to `session_extensions`. Reach another extension's tables through the [shared library](#shared-library-tables) that owns them. The typed core reads that extensions use are: - [`sdk/sessions`](../packages/albedo_sdk/src/albedo_sdk/sessions.gleam): a session's `names`, given name, family name, and title, from which each caller picks its own precedence (`label` gives the one agents and `family.name_of` use); its `standing`, whether a transfer is importing it or it moved; which of some sessions are `importing`; `describe`, its names with its workspace; and the discovery reads `find`, `all`, and `occupied`. - [`sdk/history`](../packages/albedo_sdk/src/albedo_sdk/history.gleam): besides the history reads, `conversation_page` for bounded pages of identified human submissions and visible assistant replies, `seqs` for a page of a session's transcript rows, `spans` for when ranges of them were written, and `context_use` for its pin and the prompt tokens of its latest request. - [`sdk/mail`](../packages/albedo_sdk/src/albedo_sdk/mail.gleam): `statuses_in` for the letters an extension posted, by ID, `queued_in` for the letters still waiting for some sessions, `undelivered_in` and `delivered_in` for a page of the letters a producer filed under one grouping (`input.Filed`), `file_in` to file letters posted before, and `requested` for whom a session asked for work. - [`sdk/transfer`](../packages/albedo_sdk/src/albedo_sdk/transfer.gleam): `occurred_in`, for an occurrence the daemon a session moved from ran after its export. - [`follow.Forked`](../packages/albedo_sdk/src/albedo_sdk/follow.gleam) carries the branch's copied rows as `branch_seqs`, so a follower maps source rows to their copies without reading the transcript. A read whose name ends in `_in` takes the caller's connection as well as its handle, so it runs inside the caller's transaction or read snapshot with the extension's own reads. Where a feature filtered its own rows by a core fact in one statement, it now reads its rows and asks the typed read about the sessions or letters they name. Keep such a split bounded: ask about the rows of one page, or the letters waiting for some sessions, which `mail.pending_limit` bounds, not about every row an extension ever kept. Do not filter a page by a core fact by walking the extension's history in Gleam. Page from the side whose index the filter selects, as webhooks' receipts page the letters filed under their hook in the state the page asks for. A grouping can live in a column the table already has, as `input.Filed` keeps it in the letter's key. Keep local bookkeeping that should not travel in a table no transfer carries, as webhooks' `webhook_upgrades` does. Adding a column to a carried table is allowed: moves are supported only from an older daemon to a newer one, and a move to an older daemon whose tables lack the column is refused at staging. See [moves between versions](workspaces.md#moves-between-versions). Settle an owner's imported rows in its transfer adapter's `activate`, which runs as the import goes live. `schedule` reads every due job and leaves out any importing session's, so neither those jobs nor ones a tick leaves due crowd out others. The host gives each extension a [`storage.Storage`](../packages/albedo_sdk/src/albedo_sdk/storage.gleam) handle that carries the shared store, the extension's name, its declared tables, and its declared capabilities. `extension.storage_of` builds it. The contexts an extension receives carry the handle in a `storage` field, and none carries the raw store: `Setup`, `Startup`, `Daemon`, `Preparation`, `ModelContext`, the tool `Context`, `host.Context`, `hook.Context`, `compaction.Context`, `web_search.Query`, `transfer.BindingsContext`, `transfer.Activation`, and the `extension.Sidebar` a `GlancePlugin` reads with. Callbacks that touch the store receive the handle too: `SchedulePlugin`, `DataMigration`, `FoldPlugin`, and `extension.storage_initialise`. No plugin variant hands an extension the raw store. Callbacks that receive a connection, such as `CleanPlugin`, `SchemaMigration`, `FollowPlugin`, and `Due.advance`, need no handle. The transfer adapter's `disarm`, `occurrences`, and `refuse` take the handle, and its `activate` reads it from its `transfer.Activation`. When the host builds one context before it knows which extension receives it, it fills `storage` with `extension.unscoped`, which names no extension and no tables. The host replaces it before an extension's callback runs: - `composition.tools`, `composition.tool`, and `composition.routes` wrap each extension's tools and routes, so one `host.Context` per composition reaches each route with its own extension's handle, bound to the calling session. They wrap when read, not in `composition.compose`: the composition is copied between processes, and a stored wrapper copied its handle once per closure, about 18 KB per idle session. `composition.definitions` reads tool definitions without wrapping, and `composition.tool` wraps only the tool a call names. - `composition.commands` and `composition.command_entries` bind each declared `command.Command(command.Invocation)` with `extension.scoped_commands` into the `command.Command(command.Context)` the dispatchers run. Each call turns the handle-free `command.Context` the host built into a `command.Invocation` that carries the command's extension's handle, bound to the context's session, as `storage`. A `command.Context`, such as `host.Context.session_state`, carries no handle, and the types keep a command from running without one. Read the handle from the invocation instead of capturing one in a command: a captured handle is copied with every copy of the composition (skills' load recorder cost about 16 KB per idle session). - `composition.hooks` gives each hook, from a `HookPlugin` or a managed contribution, a `hook.Context` that carries its extension's handle bound to the session it asks for, built by `extension.hook_context` when the hooks are read. Read it there instead of capturing one in the hook (agents' hook cost about 0.3 KB per idle session). See [hook context](hooks.md#hook-context). - `extension.service` scopes the `Daemon` its handler receives. - `extension.upstream`, `fast_mode`, `cyber_catalog`, and `cyber_access` scope the `ModelContext` for the provider they ask. - `extension.compaction` and `extension.notes` scope the `compaction.Context`. - `extension.searches` scopes each provider's `web_search.Query`. - `extension.transfers` scopes each adapter's `BindingsContext`, its `Activation`, and the handle its `disarm`, `occurrences`, and `refuse` receive, and gates the inbox in the `Activation`. The daemon passes them `extension.unscoped`. - `extension.install` builds each extension's `Setup` and `Startup`. Keep each extension's SQL, generated query bindings, schema, and migrations in its own package under its namespace. Only shared execution belongs in the SDK and tooling. Keep query files under the owning module's `sql/` directory and the generated modules under the extension's `generated/sql/` directory. Pass a generated schema script to `extension.schema_initialise` when installation only needs that script. Use [`sdk/storage`](../packages/albedo_sdk/src/albedo_sdk/storage.gleam) to schedule generated queries on the extension's handle. Pass a query with `db: _` to `storage.reading` or `storage.writing` for a single operation. Generated reads and statements with `RETURNING` return a list. A query that selects one column returns that column's values unless it names a row type. Generated writes without `RETURNING` return `Nil`. Both return the SQLite error message on failure. On a connection already supplied by a callback, call the generated query directly. Use one `storage.snapshot` for related reads that must see the same state, and one `storage.transaction` on the writer for changes that must commit together. Follow the [database access rule](contributing.md#use-marmot-for-database-access) when migrating existing raw SQL callers. Typed core and SDK operations take the handle itself, such as `sdk/history`, `sdk/family`, `sdk/search`, `sdk/links`, `worktree`, `kernel/journal`, an `input.Inbox` callback, or a `mail.Letters` read. Pass them the handle from your context. Core owns the tables those operations touch ([core table operations](#core-table-operations)), and the ones `capability.functions` lists check the handle's declared capabilities ([extension capabilities](#extension-capabilities)). No extension code holds the raw store. Core code that holds the store passes `storage.host(store)`, a handle with no extension, no tables, and every capability. Do not call `storage.new`, `storage.host`, `storage.bind`, `storage.ledger`, or `storage.core` from an extension. Register a generated query or a callback that calls owner-local generated queries in `CleanPlugin`. The host runs it on the session deletion transaction's connection. Register owner-local generated migration scripts with `SchemaMigration`. Keep any required ordering and backfill in the owning migration callback. Nothing checks the table scope at run time. The connection a callback receives is the shared writer's or a reader's. Two lint rules enforce the contract in extension code: - `albedo_extension_raw_store` flags an import of `albedo_sdk/store` and any use of `storage.new`, `storage.host`, `storage.grant`, `storage.declare`, `storage.bind`, `storage.ledger`, or `storage.core`, and any use of an SDK reader that takes a raw connection and reads a session's stored data. It also flags `storage.owned_by` outside a shared library. - `albedo_table_ownership` flags SQL that names another extension's created table. It also flags SQL that names a table the extension does not declare, including one it creates. SQLite's `sqlite_` schema tables, `pragma_` functions, `json_each`, and `json_tree` are exempt. Core tables are not exempt: read them through the typed operations above. The rule also flags a `tables` entry the extension does not create, and SQL in an SDK module that names a core table ([core table operations](#core-table-operations)). ### Core table operations Core keeps the schema, migrations, and statements of its own tables. The SDK modules that read or change them hold no SQL on them. Each one checks the handle's capabilities and its session rule, keeps its own logic, and calls typed operations that core injects. The contract is [`sdk/core_tables`](../packages/albedo_sdk/src/albedo_sdk/core_tables.gleam): one record of operations per area, gathered in `core_tables.Tables`. Core implements each area's record next to that area's schema, and [`storage/core_store`](../apps/albedo/src/albedo/storage/core_store.gleam) gathers them: - `Sessions`, the reads of `sdk/sessions` on the `sessions` table: [`storage/session_rows`](../apps/albedo/src/albedo/storage/session_rows.gleam). The values they answer, such as `Names`, `Summary`, and `Standing`, are typed in [`sdk/session_info`](../packages/albedo_sdk/src/albedo_sdk/session_info.gleam), below the store, and `sdk/sessions` names them by alias. - `Family`, the reads and writes of `sdk/family` on `session_family`, `family_remote`, and the family columns of `sessions`: [`session/family`](../apps/albedo/src/albedo/session/family.gleam), which also creates those tables. - `Sessions` also holds the session reads of `sdk/history`: `info`, `listing`, `acp_marker`, and `context_use`. `ContextUse` is typed in `sdk/session_info`. - `Transcript`, the reads of `sdk/history` and `sdk/search` on `transcript`, `continuation_markers`, and the `transcript_text` index: [`storage/transcript_rows`](../apps/albedo/src/albedo/storage/transcript_rows.gleam). A search pages through `core_tables.Window`s, and core answers each window's `Hits`. - `Mail`, the reads of `sdk/mail` on the `mail` table and `file_in`'s write: [`storage/mail`](../apps/albedo/src/albedo/storage/mail.gleam). `mail.Status` names `core_tables.Status`. - `Images`, the payload reads and inserts of `sdk/images` on the `images` table: [`storage/images`](../apps/albedo/src/albedo/storage/images.gleam). Core's own writes, such as `images.externalize`, use the same insertion. - `Requests`, the reads of `sdk/request_history` on `provider_requests`: [`storage/requests`](../apps/albedo/src/albedo/storage/requests.gleam), whose `last_turn` selects the turn through the same statement. `request_history.LastTurn` names `core_tables.LastTurn`. - `Transfers`, the read of `transfer.occurred_in` on `transfer_occurrences`: [`transfer/transfers`](../apps/albedo/src/albedo/transfer/transfers.gleam). It answers the recorded detail, and `sdk/transfer` builds the `Occurrence`. The operations reach SDK code through the storage handle, so there is one path. The host starts the store with the record (`store.start(path, configure, tables)`), and every handle on that store reaches it with `storage.core`. Only the host and the SDK call `storage.core`. An extension calls the SDK functions, which check its capabilities first, and the `albedo_extension_raw_store` lint rule refuses `storage.core` in extension code. Every operation takes the connection it runs on. An SDK function that ran several statements in one read snapshot or transaction still opens it once and passes the same connection to each operation, and an `_in` function passes the caller's connection on. A function that read or wrote outside a snapshot runs its operation with `storage.reading` or `storage.writing`, which return `the store stopped` once the store has closed. To read or change a core table from the SDK, add an operation to the area's record and implement it next to the table's schema. Do not add SQL on a core table to an SDK module: the `albedo_table_ownership` lint rule flags it ([Gleam lint](gleam-lint.md#extension-storage-rules)). SQL in the SDK on the SDK's own tables, such as `session_extensions`, `breaking_migrations`, and `workspace_links`, stays there, as does an extension's SQL on its own tables through `storage`. A test that starts a store passes `core_store.tables()`, so a test of these SDK functions runs where core is available. ### Migrations An extension changes its stored data with a `MigrationPlugin`. Both variants of [`extension.Migration`](../packages/albedo_sdk/src/albedo_sdk/extension.gleam) take a `name` and a [`migration.Compatibility`](../packages/albedo_sdk/src/albedo_sdk/migration.gleam): - `SchemaMigration(name, compatibility, apply)` runs on a connection right after the extension's initialiser, at every startup. Make `apply` idempotent. Register a generated column batch with `extension.column_migration(name, compatibility, apply)` when the migration only adds the columns. If added columns require a backfill, use their returned names in the schema migration callback on the same connection. - `DataMigration(name, compatibility, run)` runs after core data migrations, with the extension's handle and the pre-upgrade backup path. It returns the rows it rewrote. Mark a migration `Breaking` when a build without it would misread or lose the extension's data, for example after a rename or a format rewrite. The host records a breaking migration's name in the home before it writes, and a build that does not know the name refuses that home. Prefix the name with the extension's name and never change it. When you remove a breaking migration, or the extension that declares it, add its name to `migrations.retired`. See [downgrades](migrations.md#downgrades). ### Shared library tables A [shared library](#shared-extension-libraries) runs its SQL under the handle of the extension that owns its tables, even when another extension calls it. The library declares a `storage.Owner` with `storage.owned_by`, from the owning extension's name and the library's `tables` constant, which that extension passes as its own `tables` and creates in its `initialise`. Its functions run their SQL under `storage.as_owner(caller, owner, session)`. An extension that calls the library declares that owner with `extension.FeaturePlugin(library.owner())`. `extension.storage_of` grants the extension's handle each owner it declares. `as_owner` answers a handle scoped to the owner's name and tables when the caller declares the owner, and the caller's own handle when the caller is the owner. It answers an error otherwise, so a setup that calls an undeclared owner's library quarantines its extension. The grant does not limit SQL at run time. `session` names the session whose data the call reads or writes. `as_owner` applies the same rule as the SDK history reads to it ([extension capabilities](#extension-capabilities)): a handle bound to that session, or a host handle, passes, and any other handle passes only when its extension declares `History`. The owner's handle would otherwise read another session's rows for any caller. Pass `Some(session)` from every library function keyed by a session, and from one keyed by a row of a session, such as an LCM node, the session that holds the row. Pass `None` only for work on no session's data, such as `initialise`. - [`albedo_rolling`](../packages/albedo_rolling/src/albedo_rolling.gleam) declares `rolling.owner()`, owned by `rolling`. Its strategy and `initialise` read and write `rolling_compaction_state` under rolling's handle. `snapcompact` and `snapcompact-memory` declare it, because the text fallback and their setup use rolling's strategy and table. - [`albedo_lcm/graph`](../packages/albedo_lcm/src/albedo_lcm/graph.gleam) declares `graph.owner()`, owned by `lcm-memory`. Every graph function that takes a handle runs under it, including those [`albedo_lcm`](../packages/albedo_lcm/src/albedo_lcm.gleam) calls. `coding-lcm` and `persistent-agent` declare it. - [`albedo_models_dev`](../packages/albedo_models_dev/src/albedo_models_dev.gleam) touches no tables, so it declares no owner. The table rules read a library's SQL and `tables` as the owning extension directory's, which the lint's [`layout.library_tables`](../tools/lint/src/albedo_lint/layout.gleam) names, so the table names and schemas stay where they were and stored data needs no migration. A library that owns no tables names none. Pass a library function the handle from your context. Do not build a handle for the owner, and do not reach the owner's tables through the raw store. A new library that touches tables declares an owner the same way, names its owning directory in `layout.library_tables`, and each extension that calls it declares a `FeaturePlugin`. ### No storage baseline Every extension declares its tables and runs its SQL through its handle, so both storage rules apply to all extension code without exceptions. There is no baseline to add a finding to. Fix a new finding by declaring the table, by moving the SQL behind the handle, or by reading or changing the core table through a typed core or SDK operation, adding one where none answers. See [Gleam lint](gleam-lint.md#extension-storage-rules) for what the rules match. An extension that exports a session can bind to its own explicit selection with `selection.acquire_grant_in` and recheck it with `selection.grant_in`. Both require `Selection`; reading another session's grant also requires `Sessions`. The opaque token changes after a disable or return to inheritance. The SDK owns the grant table and revokes tokens in the same transaction as the choice. Global defaults confer no explicit grant. Use `effective_grant_in` and `acquire_effective_grant_in` for deliveries authorized by the daemon default or an explicit choice. Call them inside `selection.with_effective_default`, passing it the `Selection.enabled_by_default` lookup. It observes the setting on the writer and commits any revocations before your callback starts its transaction. A session choice takes precedence. Equivalent enabled choices keep the same token. Disabling the effective selection revokes it, so an earlier delivery cannot reuse it after re-enrollment. ## Extension capabilities Some context fields carry authority beyond an extension's own session data: posting to any session, controlling sessions, reaching other daemons, or calling other extensions' providers. These fields are capabilities. Each extension declares the capabilities its code uses in the `uses` field of its [`extension.Extension`](../packages/albedo_sdk/src/albedo_sdk/extension.gleam). Write the list as a constant of [`capability.Capability`](../packages/albedo_sdk/src/albedo_sdk/capability.gleam) constructors in a Gleam module under the extension's directory, and pass that constant to the constructor as `uses:`, `uses: editor_uses`, or `uses: module.uses`. An extension that uses no capability passes `uses: []`. Each constructor has its own declaration, even where several extensions share a directory and its [`tables`](#extension-storage): `editor-mcp` passes `editor_uses`, which holds the `EditorOverlay` it reads, and `mcp` passes `[]`. Set `uses` only in the constructor. A record update such as `extension.Extension(..bundled, plugins: ...)` keeps its record's declaration. | Capability | Context fields | | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------ | | `Inbox` | `inbox` on `Setup`, `Startup`, `Daemon`, `host.Context`, and `transfer.Activation` | | `Mail` | `letters` on `Preparation` and `host.Context`, and `host.Context.send_mail` | | `SessionControl` | `control` on `Daemon` and `host.Context` | | `SessionState` | `session_state` on `Daemon` and `host.Context` | | `Sessions` | `Daemon.sessions`, `Daemon.linked_summaries`, and `host.Context.kernel_resources` with `KernelResources`; worktrees with `Worktrees` | | `History` | none: the SDK reads of another session's history | | `Correspondence` | none: the SDK reads and changes of another session's letters | | `Remote` | `host.Context.correspondents` and `ask_moved`, and `Daemon.tell_refused` and `hook_gone` | | `Intake` | `intake_port` on `Daemon` and `Preparation`, and `transfer.BindingsContext.intake_url` | | `ShellOutput` | `host.Context.read_shell_output` | | `Upstream` | `Daemon.upstream` | | `Models` | `Daemon.models` and `Daemon.efforts` | | `Providers` | `searches` and `imagegens` on `host.Context`, and `Daemon.searches` | | `Worktrees` | `worktrees` on `host.Context` and `Preparation`, with `Sessions` | | `Invalidate` | `invalidate` on `Startup` and `Daemon` | | `EditorOverlay` | `Preparation.editor_overlay` | | `Selection` | `selection` on `command.Invocation` and `Startup` | | `KernelJobs` | `Daemon.kernel_jobs` | | `KernelResources` | `host.Context.kernel_resources`, with `Sessions` | | `CellMedia` | `host.Context.stage_media` for the calling session’s cell | | `Hosts` | `hosts` on `Daemon` and `Preparation` | `capability.fields` in [`sdk/capability`](../packages/albedo_sdk/src/albedo_sdk/capability.gleam) holds this table, the host gate denies exactly those fields, and the lint rule reads the constant from source. [`extension_capability_test`](../apps/albedo/test/albedo/composition/extension_capability_test.gleam) keeps its own copy of this section's rules, written by hand. It runs every host call the section names, each capability field, listed function, and `command.StateOp`, once for each capability left out, and fails when `capability.fields` or the function lists name a call its copy does not. The lint also reads the SDK's constructors from source to learn where the host calls extension code with a context. Every other field is plain data that the host always passes: session IDs, the workspace, the daemon home, the storage handle, the preparation owner, the tool context's kernel and image limits, `host.Context.progress`, which is bound to the calling session, the worktree `origins` on `host.Context`, `Preparation`, `Daemon`, and `extension.Sidebar`, and a preparation's `preferences`, `project_files`, and `instructions`, which read the session's own data. `ModelContext`, `compaction.Context`, `web_search.Query`, and `hook.Context` carry no capability. A command's `command.Invocation` carries one, `selection`. The host gates capabilities where it scopes `storage`. `composition.compose` gates each extension's routes, `extension.scoped_commands` each call's `command.Invocation`, `extension.service` its `Daemon`, `composition.prepare` its `Preparation`, `extension.install` its `Setup` and `Startup`, and `extension.transfers` each adapter's `BindingsContext` and `Activation`. It replaces every capability the extension does not declare with a stand-in of the same type: - An operation that answers a `Result` answers `Error(" does not declare ")`. The inbox's `post` and `post_in` answer `input.Failed` with that text, and `intake_port` answers `Error(Nil)`, as it does while the listener is down. The job book's reads answer `Unavailable` with that text. - `Daemon.models`, the reader `Daemon.efforts` returns, `Daemon.sessions`, and the selection's `raised_caps` answer an empty list, and both `session_allows` and `enabled_by_default` answer `False`. `invalidate` and `tell_refused` do nothing. `hook_gone` answers the refusal text as its description, and `intake_url` answers `None`. - The two provider lists on `host.Context` have no failing path, so a denied `Providers` passes them empty. - A denied `worktrees`, for want of `Worktrees` or `Sessions`, answers every operation with the refusal, and `for_session` and `running_occupant` with `None`. - A denied `hosts` observes every host as `unreachable` with the refusal as its detail, and its `exists` and `workspace` answer the refusal. The first denied call of each extension and capability within an hour logs a warning that names both. A denied provider list logs nothing, because reading a list calls nothing. Extensions that declare what they use see the host's values unchanged. Typed SDK operations take the storage handle, and a few of them act beyond the caller's own data. `capability.functions` lists them with the capability whose authority they grant. The rule for `Sessions` is that a function which answers the ID of a session other than one its caller passed in needs it: - listings: `history.sessions`, `search.candidates`, `family.children`, `resources.recorded_kernels`, `sessions.all`, and `mail.requested`. The `kernel_resources` capability's `recorded` calls `recorded_kernels` with the handle the extension passes, so it needs `Sessions` besides `KernelResources`; - a name resolved to an ID: `family.resolve`, `family.locate`, `family.remote`, and `sessions.find`; - a related session's ID: `family.get`, which names the parent, and `family.started_by`; - the session a worktree records or runs: core's `worktree.get`, `for_session`, `for_workspace`, `list`, `remove`, and `running_occupant`. Extensions call them through the `worktrees` capability with their own handle, so the field needs `Sessions` as well as `Worktrees`. `sessions.occupied` answers no ID, but it tells whether any session works in a workspace, so it needs `Sessions` too. `family.set_role` and `family.set_verifier` change another session's family row, so they need `SessionControl`. `search.candidates` is listed under both `Sessions` and `History`, because it finds other sessions by what their messages say. `mail.requested` is listed under `Mail` and `Sessions`, because it reads a session's letters and answers their recipients. `mail.statuses_in`, `queued_in`, `undelivered_in`, `delivered_in`, and `file_in` read or file letters in the inbox, so they need `Inbox`, which posts them. A function listed more than once needs every capability listed for it. These mail functions also keep the session rule below. Holding another session's ID, from a letter, a webhook, or a tool argument the model supplied, does not let an extension read that session's history. `capability.session_functions` lists the SDK functions that take a session ID, or a `transcript.Snapshot` or kernel cell that names one, and read that session's stored history: its `sessions` row (`history.get`, `history.acp_marker`, `history.context_use`), its transcript (`history.snapshot`, `source_stats`, `latest_user_seq`, `rows_before`, `fold_sources`, `conversation_page`, `uploaded_image`, `seqs`, `spans`, `tool.transcript_read`, `tool.source_page`, `search.newest`, `page`, `page_without`, `running_call`, and `transcript_grep`), its request history (`request_history.last_turn`), and its kernel journal (`journal.get`, `find_call`, `draft`, `prepare`, `unfinished`, `recent`, `trace`, and `saved_trace`). Each one calls `storage.permit_session` with the session it reads. The rule is: - a host handle reads any session; - a handle bound to a session reads that session without a capability; - a handle reads any other session only when its extension declares `History`. The same rule covers a session's letters under `Correspondence` instead of `History`. The [`sdk/mail`](../packages/albedo_sdk/src/albedo_sdk/mail.gleam) reads of letters in the inbox are listed under it: `statuses_in`, `queued_in`, `undelivered_in`, `delivered_in`, `file_in`, which files letters, and `requested`. Each checks the rule for every session whose letters it reaches. `queued_in` checks the recipients it names and `requested` its sender before reading. `statuses_in` and the filed pages check the recipients of the letters they find, and `file_in` those of the letters it would file, before it writes. One letter to a session the handle may not reach refuses the whole call. These functions need the capability `capability.functions` lists for them as well. The list also names, by field, the reads of the `input.Inbox` and `mail.Letters` the host hands extensions that reach one session's letters: the inbox's `withdraw` and `waiting`, and the letters' `owed_requesters`, `owes_reply`, which reads both sessions it names, and `open_json`. [`inbox.extension_inbox`](../apps/albedo/src/albedo/session/inbox.gleam) and [`mail.letters`](../apps/albedo/src/albedo/storage/mail.gleam) check them. The inbox's `post`, `post_in`, and `post_image_event_in` reach any session under `Inbox`. So an extension that declares `Inbox` posts to any session, but withdraws from or reads the queue of another session only when it declares `Correspondence` too: withdrawing can take out another producer's letter. `Daemon.session_state` reaches any session's actor under `SessionState`, but a service's handle is bound to no session, so the gate keeps the same rule for the operations that read a session's letters or history. [`command.other_session_needs`](../packages/albedo_sdk/src/albedo_sdk/command.gleam) decides every `command.StateOp` in an exhaustive `case`, so a new operation does not compile until it is classified: - `QueueRead`, `QueueDrop`, and `QueueArrange` need `Correspondence`. - `ContextSummary`, `ContextPage`, `KernelJobs`, and `KernelRead` need `History`. Their answers carry what the session ran and its output, including the retained output of its background jobs. `Shake` needs it too, because it drops media from the session's history. - The rest need nothing more than `SessionState`. They set or report the session's settings, drive its turn, or start, stop, or replace its kernel or jobs, and answer no output. `capability.session_functions` lists the operations that need a capability by constructor name, which the lint reads, and [`extension_capability_test`](../apps/albedo/test/albedo/composition/extension_capability_test.gleam) runs every operation against the classification above. `extension.gate_daemon` checks them with `storage.permit_session` for the session the context serves, and refuses an operation whose two answers disagree. An extension that declares every capability these operations need gets the host's `session_state` unchanged. `host.Context.session_state` serves the calling session, which its handle is bound to, so the host does not wrap it. The `mail` extension's queue service declares `Correspondence` for this, and the `run` extension's service, which lists and reads any session's jobs, declares `History`. `History` and `Correspondence` grant nothing of each other. Letters are where a producer's posts stand, which a service needs without reading any transcript. A transcript holds what the model said and ran, which letters do not show. `sessions.describe` follows the same rule under `Sessions` instead of `History`. It answers a session's workspace, not its history, and every `Sessions` listing shows that workspace already. The host binds a handle to the session of the context or callback that carries one, where it scopes `storage`: the tool `Context` and `host.Context` in `extension.scoped`, `Preparation` in `composition.prepare`, `compaction.Context` in `extension.compaction` and `notes`, `ModelContext` for each provider, `web_search.Query` in `extension.searches`, `hook.Context` in `composition.hooks`, `FoldPlugin` folds, and the `extension.Sidebar` of a `GlancePlugin` read. `extension.session_storage_of` builds such a handle. `Setup`, `Startup`, `Daemon`, `transfer.BindingsContext`, `transfer.Activation`, `SchedulePlugin`, and `DataMigration` handles are bound to no session, so a service or a startup worker reads no session's history without `History`, and no session's letters without `Correspondence`. The host cannot bind a handle to a session that only an extension's own tables name, such as the session that owns a webhook or a Discord bot. A service that reaches the letters of such sessions declares `Correspondence`. `storage.as_owner` keeps the caller's bound session and checks the session a feature call names. Only the host calls `storage.bind`. Family facts, such as `family.role`, `family.closed`, `family.owns`, and `family.name_of`, stay plain: they address a session but do not read its history. So do `sessions.names`, `standing`, `standing_in`, and `importing`, which answer only about the sessions their caller names, and `transfer.occurred_in`, which reads no session's data. `images.bytes` and `images.reader` stay plain too, because they read an image by its content hash, which only a transcript row names. Finding another session's ID still takes a `Sessions` function, and reading its history takes `History`. A callback that holds a connection, from `storage.snapshot`, `storage.query`, or a plugin that receives one, has no handle to check. So the readers that take a connection and read a session's stored data are core's alone. They live in core, such as `session_rows.read_info` and `transcript_rows.snapshot`, which extension code cannot import. The kernel's `journal.traces_in` and `session_hashes` are refused in extension code by the `albedo_extension_raw_store` lint. Read through their handle-taking counterparts, such as `history.get`, `history.snapshot`, or `request_history.last_turn`. A transfer export collects the images that the moved sessions' kernel cells name in core (`transfers.cell_images`), not in the kernel's transfer adapter. `History` is separate from `Sessions` so that discovery does not imply reading. `links` and `worktrees` list sessions and their metadata but read no transcript. `schedule` checks that the session a new schedule names exists, which needs `History` but not discovery. `agents` reads and searches other sessions' messages and declares both. It also shows which requests other sessions owe and await, so it declares `Correspondence`. `webhooks` and `discord` read and file the letters they posted to the sessions that own their hooks and bots, from an upgrade, an import, a service, or a gateway manager bound to no session. They declare `Correspondence`, not `History`, because they read no transcript. `extension.storage_of` records the extension's `uses` in its handle, and each listed function calls `storage.permit` before it acts. A handle whose extension does not declare the capability gets `Error(" does not declare ")`, logged as for a denied field. `worktree.for_session`, `for_workspace`, and `running_occupant` answer an `Option`, so they answer `None`, as `journal.trace` and `saved_trace` do. `permit_session` refuses the same way. A host handle (`storage.host` or `extension.unscoped`) may call them all. A handle `storage.as_owner` returns for a shared library keeps its caller's capabilities. `permit` and `permit_session` refuse a function their list does not name, so a check cannot pass by a misspelt name. Extension SQL names no core table, so every core read an extension makes goes through one of these typed operations and its check. Add a typed operation for a new core read, and list it in `capability.functions` or `capability.session_functions` when it answers another session's ID or reads another session's history. The `albedo_extension_capability` lint rule checks the declaration in extension code. It flags a capability field read, or a call of a `capability.functions` entry, that an extension which may run it does not declare. A call of a `capability.session_functions` entry may read the session its handle is bound to, which the lint cannot tell from a variable, so it counts as a use of its capability but is flagged as undeclared only when its handle is the `storage` of a context with no `session` field, such as `daemon.storage`. The host refuses the other cross-session reads at run time. A read belongs to one extension when only that extension's constructor reaches the function that holds it, through calls or function references within the constructor's module. Every other read is shared: code in another module of the directory, a function two constructors reach, or a public function another module of the directory references may run under any of the directory's extensions, so each of them must declare the capability. Keep a read only one extension needs in a function only its constructor reaches. The rule also flags a declared capability the extension never reads, a name that is not a capability, a capability constant no extension passes, a `uses:` argument other than `[]` or a reference to a capability constant in the directory, and a record update that sets `uses`. A directory that moves plugins between `Extension` values shares every read, and a read in code another extension directory reaches is a finding, because it runs under the installing extension's declaration. Give such code what it needs as a parameter instead. A read in a shared library is a finding too. It reads field access on a variable whose type is a context and record patterns of a context. A variable's type comes from an annotation, an alias of a known variable, or the callback position of an anonymous function the SDK calls with a context, such as a `StartupPlugin` callback or a handler in a route list. Pass a context to a helper with an annotated parameter, and the helper's reads count. Every extension declares its capabilities, so the rule has no baseline. See [Gleam lint](gleam-lint.md#extension-capability-rule) for what it matches. Declare only what the extension reads. Do not declare a capability to reserve it for later. ## Session data and effects [`sdk/history`](../packages/albedo_sdk/src/albedo_sdk/history.gleam) owns read-only history observations, including generic folds, boundary snapshots, uploaded image pages, and session metadata lists. The daemon reads history through the same functions and keeps every transcript write and every statement on its tables ([core table operations](#core-table-operations)). Keep the captured snapshot through related reads. [`sdk/transcript`](../packages/albedo_sdk/src/albedo_sdk/transcript.gleam) and [`sdk/session_info`](../packages/albedo_sdk/src/albedo_sdk/session_info.gleam) own the shared value types, including a session stage's stored spelling. [`sdk/transcript_codec`](../packages/albedo_sdk/src/albedo_sdk/transcript_codec.gleam) owns the stored row format, and [`sdk/image_fit`](../packages/albedo_sdk/src/albedo_sdk/image_fit.gleam) applies image fit rows to earlier images. Producing a fit stays with the daemon's turn loop. Some of these functions are public only because the daemon calls them across modules: the `transcript_codec` packing functions. Treat them as internal storage helpers. Read history through the typed `sdk/history` functions. Do not write the core transcript, session, or image tables from an extension. Replay projection, note encoding, and image validation use [`sdk/projection`](../packages/albedo_sdk/src/albedo_sdk/projection.gleam), whose caller passes the repair applied to each replay item: the host passes `loop.replay_repair`, the python tool's [`sdk/python_repair`](../packages/albedo_sdk/src/albedo_sdk/python_repair.gleam), and an extension that projects history, such as the proxy, passes that repair itself, [`sdk/message_content`](../packages/albedo_sdk/src/albedo_sdk/message_content.gleam), [`sdk/note`](../packages/albedo_sdk/src/albedo_sdk/note.gleam), and [`sdk/image`](../packages/albedo_sdk/src/albedo_sdk/image.gleam), which reads headers through [`albedo_image`](../packages/albedo_image/src/albedo_image.gleam). [`sdk/request_history`](../packages/albedo_sdk/src/albedo_sdk/request_history.gleam) owns the request `Prefix` type. Its `last_turn` returns the latest successful transcript turn's input identity. Background pings do not replace that observation. It reads only the turn's sequence, head hash, and inputs, so a malformed cost or cache-mark column on that row, or any malformed ping row, does not fail it. `requests.last_turn` in the daemon still reads and validates the whole row and its pings. Give a session something to read through [`sdk/input`](../packages/albedo_sdk/src/albedo_sdk/input.gleam) with the shared [`sdk/letter`](../packages/albedo_sdk/src/albedo_sdk/letter.gleam) kinds and deliveries: describe the input and post it through the `input.Inbox` the context carries. `extension.Setup`, `extension.Startup`, `extension.Daemon`, and `host.Context` each have an `inbox` field. Pass it on to the code that posts, as the Discord manager keeps it in its state. Do not store it in process-wide state. The record's `post_in` takes the caller's connection, so feature changes and their input commit together, and the session hears of it after the commit. Do not reach into the inbox's storage or the session's actor. See [inbox](inbox.md). Agents' letters to each other go through `host.Context.send_mail`, which is bound to the calling session. The [`mail.Letters`](../packages/albedo_sdk/src/albedo_sdk/mail.gleam) on `host.Context` and `extension.Preparation` reads the requests a session owes and has open. [`sdk/images`](../packages/albedo_sdk/src/albedo_sdk/images.gleam) owns image payload reads and inserts. `images.store_images` and `read_in` take the caller's handle and connection, so they retain its transaction. The daemon keeps the `images` schema, release, and elision, and runs every statement on the table ([core table operations](#core-table-operations)). [`sdk/image_codec`](../packages/albedo_sdk/src/albedo_sdk/image_codec.gleam) owns historical image row packing, validated loading with lazy readers, and legacy compaction fingerprints. It also owns image externalization, referenced-hash scans, and legacy base64 decoding. The packed shapes are private constructors in `image_codec` and `transcript_codec`, so rows keep the bytes earlier daemons wrote. [`transcript_codec_golden_test`](../packages/albedo_sdk/test/albedo_sdk/transcript_codec_golden_test.gleam) checks packing and the decoding of historical rows against [golden rows](../packages/albedo_sdk/test/fixtures/transcript-codec-golden.txt) from the earlier Erlang codec. Change a packed shape only with a migration, and keep those rows passing. The daemon retains migration transactions. Publish notifications after commit. `extension.Daemon.invalidate` announces service changes. `host.Context.progress` is bound to its session. `host.Context.session_state` is the calling session's [`command.Context`](../packages/albedo_sdk/src/albedo_sdk/command.gleam). `extension.Daemon.session_state` returns the context of the session a service request names. Both reach session state through `command.StateOp` values, which the session's actor answers. The daemon owns the lookup from session ID to actor in [`command_state`](../apps/albedo/src/albedo/session/command_state.gleam). The SDK cannot discover a session's state callback, so use the context the host supplies. Do not call `state` from inside the session's actor, because the call waits on that actor. `host.Context.read_shell_output` reads only that session's captured user-command output. A background service without a request context keeps the `extension.Startup.invalidate` callback its `StartupPlugin` received and calls it after commit. [`sdk/notice`](../packages/albedo_sdk/src/albedo_sdk/notice.gleam) decodes the completion notices a kernel posts under its own keys and withdraws them by key once their result was read. Its `post`, `withdraw`, and `waiting` take the route's `host.Context.inbox`. [`sdk/webhook_address`](../packages/albedo_sdk/src/albedo_sdk/webhook_address.gleam) builds delivery paths and addresses from a port. `extension.Daemon.intake_port` and `extension.Preparation.intake_port` read the daemon intake listener's current port, or `Error(Nil)` while it has none. Read it when you show an address. See [webhooks](webhooks.md#setup). [`sdk/session_control`](../packages/albedo_sdk/src/albedo_sdk/session_control.gleam) exposes typed session operations. It also defines the coordinator's `Op` and `Reply` values, which only the daemon's session registry handles. Each typed function takes the `session_control.Control` that `host.Context.control` and `extension.Daemon.control` carry. See [agents](agent-sessions.md). [`sdk/family`](../packages/albedo_sdk/src/albedo_sdk/family.gleam) owns the extension-facing family operations and their capability checks. [`session/family`](../apps/albedo/src/albedo/session/family.gleam) owns the family tables, their schema, and every statement on them, and keeps child admission, limits, closing, family revisions, remote stubs, and deletion claims. [`sdk/session_identity`](../packages/albedo_sdk/src/albedo_sdk/session_identity.gleam) owns the shared family member, address, stub, and local or remote destination values. `host.Context.ask_moved`, `extension.Daemon.tell_refused`, and `extension.Daemon.hook_gone` keep forwarding and refusal behavior for moved sessions with the daemon's [move owner](../apps/albedo/src/albedo/transfer/moves.gleam). `extension.Preparation.editor_overlay` resolves an authorized editor overlay for MCP preparation. The daemon binds it to [`acp_overlay.resolve`](../apps/albedo/src/albedo/acp/acp_overlay.gleam). The returned [`sdk/editor_mcp.Overlay`](../packages/albedo_sdk/src/albedo_sdk/editor_mcp.gleam) captures its catalogue revision in lookup and save callbacks. A stale preparation cannot publish into a newer revision. Keep resource adoption with the MCP preparation owner. Obtaining this value does not allocate a client. [`sdk/profiles`](../packages/albedo_sdk/src/albedo_sdk/profiles.gleam) owns provider-profile validation and decoding, including generic settings reads. It does not require a session context. Native persistence and settings locking retain their existing owners. [`albedo_bytes`](../packages/albedo_bytes/src/albedo_bytes.gleam), [`albedo_bytes/text`](../packages/albedo_bytes/src/albedo_bytes/text.gleam), and [`albedo_bytes/term`](../packages/albedo_bytes/src/albedo_bytes/term.gleam) provide binary framing, native text conversion, and legacy term-order operations. Keep those conversions at foreign-data boundaries. [`albedo_openai/opencode`](../packages/albedo_openai/src/albedo_openai/opencode.gleam) shares gateway request encoding, Responses replay reduction, and charged, allowance, and list-cost interpretation. Provider routing, account identity, and headers remain with each provider. ## Shared extension libraries Code several extensions use lives in a shared library, a [workspace package](workspace-packages.md#layers) in the layer of the extension packages. A library depends on the SDK and the general packages, never on albedo or an extension. It has no extension constructor and declares no capability, so it reads none: it runs under whichever extension calls it, and takes what it needs as a parameter. Importing one does not enable an extension or substitute for selection of a provider. - [`albedo_models_dev`](../packages/albedo_models_dev/src/albedo_models_dev.gleam) owns shared model enrichment from the models.dev catalogue and its cache refresh policy. The `models` extension declares its settings and catalog, and the provider extensions call it for limits and endpoints. - [`albedo_lcm`](../packages/albedo_lcm/src/albedo_lcm.gleam) and [`albedo_lcm/graph`](../packages/albedo_lcm/src/albedo_lcm/graph.gleam) hold the LCM strategy and the compaction graph `coding-lcm`, `lcm-memory` and `persistent-agent` share. `lcm-memory` owns the graph's tables. - [`albedo_rolling`](../packages/albedo_rolling/src/albedo_rolling.gleam) holds the rolling strategy, which rolling installs and snapcompact's fallback runs. `rolling` owns its table. The lint knows the libraries by name, in [`layout.libraries`](../tools/lint/src/albedo_lint/layout.gleam). An extension imports no other extension's modules: standalone compilation and the [package dependency checks](workspace-packages.md#enforcement) enforce that boundary. Move what several extensions share into a library, and reach another extension's behaviour through a plugin contract in the active composition. Links, for example, tells sessions about a workspace that joined their group without reading memory: memory contributes a `LinkedSummaryPlugin`, which the host runs for each recipient whose composition has memory active ([daemon contributions](plugins.md#daemon-contributions)). A library that touches tables runs under its owner's handle, as [shared library tables](#shared-library-tables) describes. ## Boundaries to preserve `extension.invoke` catches a tool crash and returns a refusal that says its effects are unknown. A `Fatal` failure ends the turn when the host could not record what a call did. Inspect effects before retrying an interrupted or crashed operation. Tool output can contain text and images. Consumers must use the provider's image limits. See [extension.gleam](../packages/albedo_sdk/src/albedo_sdk/extension.gleam). Extensions can expose Python bindings, such as [MCP](mcp.md), [skills](skills.md), and [image generation](imagegen.md). Every session has the kernel these bindings load into, so a binding needs no requirement. A binding is an interface to its host routes, not a separate permission grant. Its module is `python/albedo_plugins/.py`, named in a `ToolPlugin`'s `python_modules`. See [add a Python binding](../docs/extensions.md#add-a-python-binding). Declare a binding's module in a static `ToolPlugin` unless whether it loads depends on the session, as the editor's `mcp` does. Spares import the modules that the harness base and the default extensions declare statically before a session adopts them. A module named only by a managed plugin loads at adoption instead. See [fresh spare kernels](kernel.md#fresh-spare-kernels). An extension owns the tables it creates. Keep SQL that names those tables inside the owning extension and expose operations through its interfaces. Declare them as described in [extension storage](#extension-storage). The [`albedo_table_ownership` lint rule](../tools/lint/src/albedo_lint/rules/table_ownership.gleam) checks that boundary. Use migration and cleanup plugins for extension-owned storage. Follow the [extension change rules](contributing.md#preserve-extension-lifecycle-boundaries) when changing selection, discovery, or resource lifetime. ## Related pages - [All topics](README.md) - [Change guidance](contributing.md) - [Compaction](compaction.md) - [Plugins](plugins.md) - [Honcho](honcho.md) - [Persisted settings](settings.md) - [Workspace packages](workspace-packages.md)