# Extensions An extension is a named bundle of plugins. The registry in [extensions.gleam](../src/albedo/harness/extensions.gleam) declares installed extensions and defaults. The [extension types](../src/albedo/harness/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. ## 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](../src/albedo/harness/extension/selection.gleam). ## Session composition [`composition.compose`](../src/albedo/harness/extension/composition.gleam) loads static contributions and prepares managed contributions for each selected extension. A failed load, failed preparation, module clash, or duplicate tool, command, or route leaves that extension inactive and adds a warning. Dependents whose requirements are inactive are removed as well. 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](../src/albedo/harness/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`](../src/albedo/harness/settings/declared.gleam) collects declarations and validates declared values. [`core_settings.all`](../src/albedo/daemon/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. ## SDK imports and native bindings An extension belongs to one directory under `src/albedo/harness/extensions/`. Use `albedo/harness/sdk/*` for shared extension helpers and contracts, and import modules within your own extension for feature behavior. Standard library and other declared dependency imports remain available. Extensions import nothing from `albedo/daemon/`. Storage is [`sdk/store`](../src/albedo/harness/sdk/store.gleam) and the HTTP contract is [`sdk/http_api`](../src/albedo/harness/sdk/http_api.gleam). The allowed harness domain imports are `location`, `ssh`, `worktree`, `compaction`, `cache_ttl`, `capabilities`, `project_files`, `instruction_files`, `context_limits`, `links`, and `extension/selection`, each under `albedo/harness/`. Any extension may also import the core kernel modules [`kernel/jobs`](../src/albedo/harness/kernel/jobs.gleam), which owns live and saved job reads and fallback rules, and [`kernel/resources`](../src/albedo/harness/kernel/resources.gleam), which exposes the supported kernel resource types. Any extension may import the core skills modules under [`albedo/harness/skills/`](../src/albedo/harness/skills). Only the python extension may import [`albedo/harness/kernel`](../src/albedo/harness/kernel.gleam), [`kernel/journal`](../src/albedo/harness/kernel/journal.gleam), and [`kernel/tool`](../src/albedo/harness/kernel/tool.gleam). The other kernel modules, such as link, launch, recovery, termination, and cell storage, stay private to core. Shared helpers outside the SDK are [`albedo/clock`](../src/albedo/clock.gleam), [`albedo/text_scalars`](../src/albedo/text_scalars.gleam), and [`albedo/actor_call`](../src/albedo/actor_call.gleam). 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`](../src/albedo/harness/sdk/extension.gleam): Extension declarations, contributions, preparation and startup contexts, and preparation ownership. - [`sdk/service`](../src/albedo/harness/sdk/service.gleam): Buffered JSON extension HTTP services. - [`sdk/http_api`](../src/albedo/harness/sdk/http_api.gleam): HTTP failures, problem and JSON replies, strict request decoding, negotiation, validators, and paging tokens shared with the daemon. - [`sdk/worker`](../src/albedo/harness/sdk/worker.gleam): Owned worker startup and adoption. - [`sdk/host`](../src/albedo/harness/sdk/host.gleam): Context and routes for kernel host calls. - [`sdk/rpc`](../src/albedo/harness/sdk/rpc.gleam): Host-call dispatch and argument decoding. - [`sdk/command`](../src/albedo/harness/sdk/command.gleam): Session command declarations and state operations. - [`sdk/follow`](../src/albedo/harness/sdk/follow.gleam): Core history and worktree changes that `FollowPlugin` callbacks receive. - [`sdk/hook`](../src/albedo/harness/sdk/hook.gleam): Turn and tool hook events and verdicts. - [`sdk/tool`](../src/albedo/harness/sdk/tool.gleam): Retrieval tool schemas, paging, and rendering. - [`sdk/client_api`](../src/albedo/harness/sdk/client_api.gleam): Declarative client HTTP operations. - [`sdk/imagegen`](../src/albedo/harness/sdk/imagegen.gleam): Provider-neutral image generation contracts. - [`sdk/web_search`](../src/albedo/harness/sdk/web_search.gleam): Web search provider contracts and selection. - [`sdk/search`](../src/albedo/harness/sdk/search.gleam): Transcript search with bounded database reads. - [`sdk/page`](../src/albedo/harness/sdk/page.gleam): Sidebar rows and command argument parsing. - [`sdk/http`](../src/albedo/harness/sdk/http.gleam): Buffered HTTP requests and timeout settings. `request` returns status, headers, and bytes, including non-2xx responses. `failure` formats status errors; `locations` follows redirect locations concurrently. - [`sdk/settings`](../src/albedo/harness/sdk/settings.gleam): Extension settings declarations and decoding. - [`sdk/credentials`](../src/albedo/harness/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`](../src/albedo/harness/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`](../src/albedo/harness/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`](../src/albedo/harness/sdk/accounts.gleam): Pure account pool ordering. - [`sdk/rotation`](../src/albedo/harness/sdk/rotation.gleam): Rate-limit account rotation. - [`sdk/oauth`](../src/albedo/harness/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. - [`sdk/oauth_flows`](../src/albedo/harness/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/oauth_listener`](../src/albedo/harness/sdk/oauth_listener.gleam): The loopback listener that serves a sign-in flow's browser callback. Only `oauth_flows` uses it. See [sign-in](auth.md#sign-in). - [`sdk/google_oauth`](../src/albedo/harness/sdk/google_oauth.gleam): Shared Google token renewal. - [`sdk/model_lists`](../src/albedo/harness/sdk/model_lists.gleam): Provider model-list helpers. - [`sdk/concurrent`](../src/albedo/harness/sdk/concurrent.gleam): Linked concurrent calls with caller lifetime. - [`sdk/protect`](../src/albedo/harness/sdk/protect.gleam): Callback crash recovery as a result value. - [`sdk/usage_feed`](../src/albedo/harness/sdk/usage_feed.gleam): Usage driver execution and bounded I/O. The SDK also provides these helpers. - [`sdk/digest`](../src/albedo/harness/sdk/digest.gleam): Hash, hex, base64, HMAC, and constant-time comparison helpers. - [`sdk/ids`](../src/albedo/harness/sdk/ids.gleam): Random and unique identifier helpers, including a version-4-shaped UUID derived from a seed. - [`sdk/env`](../src/albedo/harness/sdk/env.gleam): Environment variable lookup, returning an empty string when unset. Read it during resolution or startup callbacks, never while constructing cached declarations. - [`sdk/file`](../src/albedo/harness/sdk/file.gleam): File reads and private atomic cache writes. `home_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. `with_lock` serializes a complete cache update within this daemon; it is separate from credential transactions and does not coordinate other OS processes. - [`sdk/file_status`](../src/albedo/harness/sdk/file_status.gleam): The kind, size, and permission bits of a path without following a final symbolic link, for checks that a secret file is private before reading it. - [`sdk/settings_documents`](../src/albedo/harness/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/term_codec`](../src/albedo/harness/sdk/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. Use JSON for new persisted data. - [`sdk/log`](../src/albedo/harness/sdk/log.gleam): Warnings for the daemon's log. Never include secrets or tokens. - [`sdk/priv`](../src/albedo/harness/sdk/priv.gleam): Paths and reads of files shipped in albedo's priv directory, as `albedo_priv:dir` pinned it at boot. A failed read names the path and the file error. - [`sdk/subprocess`](../src/albedo/harness/sdk/subprocess.gleam): Credential helpers with bounded stdout and timeouts. - [`sdk/helper`](../src/albedo/harness/sdk/helper.gleam): Python helper subprocess execution with explicit outcomes. - [`sdk/rsa`](../src/albedo/harness/sdk/rsa.gleam): RS256 signing for provider authentication. - [`sdk/memo`](../src/albedo/harness/sdk/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. - [`sdk/once`](../src/albedo/harness/sdk/once.gleam): Single-flight work shared by concurrent callers. The returned process runs the job; killing it cancels that job. - [`sdk/subscriptions`](../src/albedo/harness/sdk/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. Six lint rules enforce the layer boundaries in the commit and review profiles: - `albedo_extension_daemon_import` flags any `albedo/daemon/` import from an extension. Use SDK helpers or supplied callbacks instead. - `albedo_extension_harness_import` flags harness imports outside the SDK, extension directories, and the domain allow-list above. Use an SDK contract. - `albedo_extension_external` flags `@external(erlang, M, _)` unless `M` has an `.erl` file within the same extension directory, including its subdirectories. OTP modules also violate this rule. Call an SDK Gleam helper instead of its native implementation, or keep feature-specific natives with their owner. - `albedo_extension_cross_import` rejects another extension's private modules. Deliberate feature dependencies use the public entrypoints below. Provider contributions still resolve from the active composition. - `albedo_core_extension_import` flags an `albedo/harness/extensions/*` import from any Gleam module under `src/albedo/` outside the extension directories, including the SDK. It also flags an `@external(erlang, M, _)` binding in those modules when `M` is an Erlang module owned by an extension. The registry [`extensions.gleam`](../src/albedo/harness/extensions.gleam) is exempt. - `albedo_sdk_daemon_import` flags an `albedo/daemon/` import from an SDK module, and an `@external(erlang, M, _)` binding there when `M` has its `.erl` file under `src/albedo/daemon`. Move what the SDK needs into the SDK, so the daemon imports it, or have the host supply the behavior through a context callback. The first four rules check imports from extensions. The fifth checks the other direction. The sixth keeps the SDK independent of the daemon, so the layers run extensions, then the SDK, then the daemon. Core and SDK modules must not import extension modules. Reach a new core need through a plugin contract in the active composition, or move the shared code into a core module. The extension registry is the only exception. 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 native infrastructure, such as `albedo_registry`, `albedo_priv`, and `albedo_process`, lives in `src/albedo/` so every layer can use it. [`albedo_registry`](../src/albedo/albedo_registry.erl) holds keyed ETS registries whose tables outlive their callers. [`albedo_priv:dir`](../src/albedo/albedo_priv.erl) answers albedo's priv directory, with the link the daemon resolved at boot. The daemon keeps its own handler registries, such as [`albedo_agents`](../src/albedo/daemon/albedo_agents.erl) and [`albedo_commands`](../src/albedo/daemon/albedo_commands.erl). Extensions reach them only through capabilities in their context, such as `control` and `session_state`. 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. 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 and extension 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, 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. ## Session data and effects [`sdk/history`](../src/albedo/harness/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. Keep the captured snapshot through related reads. [`sdk/transcript`](../src/albedo/harness/sdk/transcript.gleam) and [`sdk/session_info`](../src/albedo/harness/sdk/session_info.gleam) own the shared value types. [`sdk/transcript_codec`](../src/albedo/harness/sdk/transcript_codec.gleam) owns the stored row format, and [`sdk/image_fit`](../src/albedo/harness/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: `history.info_columns`, `history.info_decoder`, and 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`](../src/albedo/harness/sdk/projection.gleam), [`sdk/message_content`](../src/albedo/harness/sdk/message_content.gleam), [`sdk/note`](../src/albedo/harness/sdk/note.gleam), and [`sdk/image`](../src/albedo/harness/sdk/image.gleam). [`sdk/request_history`](../src/albedo/harness/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`](../src/albedo/harness/sdk/input.gleam) with the shared [`sdk/letter`](../src/albedo/harness/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`](../src/albedo/harness/sdk/mail.gleam) on `host.Context` and `extension.Preparation` reads the requests a session owes and has open. [`sdk/images`](../src/albedo/harness/sdk/images.gleam) owns image payload reads and inserts. `images.store_images` likewise retains the caller's transaction. The daemon keeps the `images` schema, release, and elision. [`sdk/image_codec`](../src/albedo/harness/sdk/image_codec.gleam) owns historical image row packing, validated loading with lazy readers, and legacy compaction fingerprints. 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`](../src/albedo/harness/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`](../src/albedo/daemon/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`](../src/albedo/harness/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`](../src/albedo/harness/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`](../src/albedo/harness/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`](../src/albedo/harness/sdk/family.gleam) owns the family tables, their schema, and the extension-facing family operations. [`daemon/family`](../src/albedo/daemon/family.gleam) keeps child admission, limits, closing, family revisions, remote stubs, and deletion claims. [`sdk/session_identity`](../src/albedo/harness/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](../src/albedo/daemon/moves.gleam). `extension.Preparation.editor_overlay` resolves an authorized editor overlay for MCP preparation. The daemon binds it to [`acp_overlay.resolve`](../src/albedo/daemon/acp_overlay.gleam). The returned [`sdk/editor_mcp.Overlay`](../src/albedo/harness/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`](../src/albedo/harness/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. [`sdk/bytes`](../src/albedo/harness/sdk/bytes.gleam), [`sdk/text`](../src/albedo/harness/sdk/text.gleam), and [`sdk/term`](../src/albedo/harness/sdk/term.gleam) provide binary framing, native text conversion, and legacy term-order operations. Keep those conversions at foreign-data boundaries. [`sdk/opencode_gateway`](../src/albedo/harness/sdk/opencode_gateway.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. ## Public feature dependencies These entrypoints expose intentional feature dependencies. Importing one does not enable that extension or substitute for selection of a provider: - [`models/catalogue`](../src/albedo/harness/extensions/models/catalogue.gleam) owns shared model enrichment and its existing cache refresh policy. - [`lcm/core`](../src/albedo/harness/extensions/lcm/core.gleam) and [`lcm/graph`](../src/albedo/harness/extensions/lcm/graph.gleam) expose the compaction graph shared with persistent-agent. LCM remains its table owner. - [`rolling/strategy`](../src/albedo/harness/extensions/rolling/strategy.gleam) owns the rolling strategy used by snapcompact's fallback. - [`memory/linked`](../src/albedo/harness/extensions/memory/linked.gleam) exposes the memory operation used when linking workspaces. The exact public module list lives in [`extension_cross_import`](../tools/lint/src/albedo_lint/rules/extension_cross_import.gleam). Do not import declaration modules or private workers to reach these features. ## 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](../src/albedo/harness/sdk/extension.gleam). Extensions can expose Python bindings, such as [MCP](mcp.md), [skills](skills.md), and [image generation](imagegen.md). A binding is an interface to its host routes, not a separate permission grant. An extension owns the tables it creates. Keep SQL that names those tables inside the owning extension and expose operations through its interfaces. 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) - [Plugins](plugins.md) - [Persisted settings](settings.md)