Skip to main content

Module prompt

Module prompt 

Source
Expand description

Prompt storage backends.

Provides domain-scoped storage for prompt templates with pluggable backends:

  • Project scope: SQLite (faceted by repo/branch)
  • User scope: SQLite, PostgreSQL, Redis, or Filesystem
  • Org scope: SQLite or Filesystem (org-isolated)

§URN Scheme

subcog://{domain}/_prompts/{prompt-name}

Examples:

  • subcog://project/_prompts/code-review
  • subcog://user/_prompts/api-design
  • subcog://org/_prompts/team-review

§Backend Selection Logic

The backend is selected based on configuration and domain:

1. Check explicit backend type in config/env
    ├─► PostgreSQL if SUBCOG_POSTGRES_URL set + domain supports it
    ├─► Redis if SUBCOG_REDIS_URL set + domain supports it
    └─► Continue to step 2

2. Check domain scope
    ├─► Project → `SQLite` (faceted by repo/branch)
    ├─► User → `SQLite` (local, performant, no server required)
    └─► Org → `SQLite` with org-prefixed path

3. Fallback
    └─► Filesystem (always available, human-readable YAML files)

§Selection Priority by Domain

DomainPriority OrderRationale
ProjectSQLite → FilesystemFaceted by repo/branch
UserPostgreSQLRedisSQLite → FilesystemConfigured external, then local
OrgPostgreSQLRedisSQLite → FilesystemShared org database preferred

§Backend Capabilities

BackendACIDSharedVersionedQuerySetup
SQLiteYesNoNoFull SQLNone
PostgreSQLYesYesNoFull SQLServer
RedisNoYesNoPatternServer
FilesystemNoVia syncNoGlob onlyNone

§Domain Routing

Each domain scope maps to an appropriate storage backend:

DomainBackendLocation
ProjectSQLite~/.config/subcog/memories.db (with repo/branch facets)
UserSQLite~/.config/subcog/memories.db
UserPostgreSQLConfigured connection
UserRedisConfigured connection
UserFilesystem~/.config/subcog/prompts/
OrgSQLite~/.config/subcog/orgs/{org}/memories.db
OrgFilesystem~/.config/subcog/orgs/{org}/prompts/

§Org Identifier Resolution

The org identifier is resolved from:

  1. SUBCOG_ORG environment variable (highest priority)
  2. Git remote URL (extracts org from github.com/org/repo)
  3. Returns error if no identifier can be resolved

Modules§

filesystem 🔒
Filesystem-based prompt storage fallback.
postgresql 🔒
PostgreSQL-based prompt storage.
redis 🔒
Redis-based prompt storage using RediSearch.
sqlite 🔒
SQLite-based prompt storage for user scope.
traits 🔒
Prompt storage trait definition.

Structs§

FilesystemPromptStorage
Filesystem-based prompt storage.
PostgresPromptStorage
PostgreSQL-based prompt storage with auto-migration support.
PromptStorageFactory
Factory for creating domain-scoped prompt storage.
RedisPromptStorage
Redis-based prompt storage using RediSearch.
SqlitePromptStorage
SQLite-based prompt storage.

Enums§

PromptBackendType
Backend type for prompt storage.

Traits§

PromptStorage
Trait for prompt storage backends.