Skip to main content

Crate cortexkit_store_types

Crate cortexkit_store_types 

Source
Expand description

Dependency-light storage descriptor types: the wire/config contract for CortexKit module storage.

There is one central storage config. subc resolves it into a StorageDescriptor per module and delivers that descriptor to the module (today via the registration handshake). The module hands the descriptor to the cortexkit-store crate, which opens the actual database.

This crate is kept dependency-light (serde only, no database driver) so the wire crate that carries the descriptor can depend on it without pulling sqlite or a postgres driver into the thin daemon. The heavy cortexkit-store crate re-exports these types and provides the open/migrate mechanics.

§Design invariants

  • The backend set is extensible (sqlite now, postgres soon, cloud later). A new variant is additive; module code does not branch on the backend, it just hands the descriptor to cortexkit-store.
  • Database isolation is explicit, never derived from a naming convention, so a future per-(module, project) isolation is an additive variant rather than a breaking change to how names are built.
  • The descriptor a module receives is fully resolved and least-privilege: it never carries central config or an admin credential. For postgres the DSN reaches only the module’s own database.

Structs§

StorageDescriptor
The resolved storage handle subc delivers to a module. The module passes this to cortexkit-store to open its database; it never sees central config.

Enums§

Isolation
How many physical databases a module’s storage spans.
StorageBackend
The backend a module’s storage runs on.

Functions§

module_data_dir
The conventional module data directory (<data_home>/cortexkit/<module_id>), with the data home resolved by resolve_data_home. Modules that keep non-sqlite state (journals, caches, rings) root it here.
module_store_path
THE entry point for a module resolving its own sqlite store path: <resolved data home>/cortexkit/<module_id>/store.db. Wraps resolve_data_home + sqlite_store_path so no module hand-assembles either half. Prefer this over calling sqlite_store_path directly; the two-argument form exists for callers that genuinely hold a foreign data home (the daemon resolving descriptors, tests, rig tooling).
postgres_database_name
Build the per-module postgres database name: cortexkit_<slug>_<16hex>.
resolve_config_home
The XDG-style CONFIG HOME (~/.config, %APPDATA%), with no cortexkit/ tail: a module joins cortexkit/<its file> under it. Mirrors the supervisor’s default_config_home exactly and is pinned to the same golden rows (tests/golden/config_home_resolution.json, vendored from subconscious). Modules previously carried a dated hand copy of this ladder because the only callable was the daemon’s, which bakes in its own cortexkit/subc.jsonc tail; a copy is current the day it is taken and every local check passes forever after, so the ladder lives here once.
resolve_data_home
The platform data home, resolved by THE SUPERVISOR’S RULES – this function is a byte-for-byte mirror of default_data_home in subconscious crates/subc-core/src/daemon_config.rs, which is the authority: the daemon resolves each module’s storage descriptor with that function, so a module resolving its own path with different rules silently splits from the directory its supervisor serves. Any change lands THERE first and is mirrored here against the shared golden fixture (tests/golden/data_home_resolution.json, vendored from subconscious).
sqlite_store_path
The conventional sqlite store path for a module under a data-home root (<data_home>/cortexkit/<module_id>/store.db). subc uses this to resolve a sqlite descriptor; the resolved absolute path then travels in the descriptor.