barrel_spaces (barrel_spaces v1.0.0)

View Source

Spaces: shared context containers for agents. A space IS a barrel database created through this layer: sharing context means holding a capability for the space (see barrel_caps), and every barrel feature (documents, search, channels, timeline, sync, per-database encryption) works inside one unchanged.

Space metadata lives as regular documents in the registry database _barrel_spaces (regular docs, not local docs: discovery needs folds and the changes feed). Space database names are generated (sp_ + 16 base32 chars) so the human label never constrains the database name rules; the label lives in the registry doc.

Space databases open through Barrel's database lifecycle manager (barrel_dbs), so idle spaces close automatically and hundreds of ephemeral spaces stay cheap. Runtime config (the encryption spec of an encrypted space) must be supplied again on every open, exactly as for any barrel database.

Summary

Functions

RFC 4648 base32, lowercase, no padding (callers pass sizes that are multiples of 5 bits: 10 bytes -> 16 chars, 25 -> 40).

Close a space's database (idempotent; reopen with open_space).

Create a space. Options

Drop a space: delete its database, mark the registry doc, and revoke every capability grant for it.

Like drop_space/1 with runtime open options (an encrypted space needs its encryption spec to open for deletion).

Open or create the registry database (docdb only: the registry holds small metadata docs and needs no vector store).

Active spaces: [#{id, label, purpose, owner, created_at}].

A generated identifier: Prefix + 16 lowercase base32 chars (10 random bytes), valid as a database name.

Open an existing space.

Open an existing space with runtime options (encryption for encrypted spaces, extra docdb/vectordb config).

The registry database name (documents: space:Id, grant:Id, handoff:Id).

The registry document of a space.

Types

space/0

-type space() :: #{id := binary(), db := barrel:db()}.

Functions

base32(Bin)

-spec base32(binary()) -> binary().

RFC 4648 base32, lowercase, no padding (callers pass sizes that are multiples of 5 bits: 10 bytes -> 16 chars, 25 -> 40).

close_space(Id)

-spec close_space(binary()) -> ok.

Close a space's database (idempotent; reopen with open_space).

create_space(Opts)

-spec create_space(map()) -> {ok, space()} | {error, term()}.

Create a space. Options:

  • label, purpose, owner - metadata binaries
  • encryption - a barrel_keyprovider spec; per-space keys are the agent isolation story (runtime config: pass it to open_space again after a restart)
  • session_ttl - default session TTL in seconds (3600)
  • ttl_sweep_interval - doc TTL sweep of the space db in ms (60000; sessions rely on it)
  • docdb, vectordb - extra store config

drop_space(Id)

-spec drop_space(binary()) -> ok | {error, term()}.

Drop a space: delete its database, mark the registry doc, and revoke every capability grant for it.

drop_space(Id, RuntimeOpts)

-spec drop_space(binary(), map()) -> ok | {error, term()}.

Like drop_space/1 with runtime open options (an encrypted space needs its encryption spec to open for deletion).

ensure_registry()

-spec ensure_registry() -> ok.

Open or create the registry database (docdb only: the registry holds small metadata docs and needs no vector store).

list_spaces()

-spec list_spaces() -> {ok, [map()]}.

Active spaces: [#{id, label, purpose, owner, created_at}].

new_id(Prefix)

-spec new_id(binary()) -> binary().

A generated identifier: Prefix + 16 lowercase base32 chars (10 random bytes), valid as a database name.

now_ms()

-spec now_ms() -> non_neg_integer().

open_space(Id)

-spec open_space(binary()) -> {ok, space()} | {error, term()}.

Open an existing space.

open_space(Id, RuntimeOpts)

-spec open_space(binary(), map()) -> {ok, space()} | {error, term()}.

Open an existing space with runtime options (encryption for encrypted spaces, extra docdb/vectordb config).

registry_db()

-spec registry_db() -> binary().

The registry database name (documents: space:Id, grant:Id, handoff:Id).

space_info(Id)

-spec space_info(binary()) -> {ok, map()} | {error, term()}.

The registry document of a space.