Documentation
¶
Overview ¶
Package store implements a scoped key-value store for agnt. Data is organized by scope (global, folder, page) and persisted to JSON files on disk under the project path.
Key types:
- StoreManager: manages multiple scopes with file-backed persistence
- StoreEntry: a single stored value with metadata and timestamps
Package store provides persistent key-value storage with three scopes: global (project-wide), folder (URL path prefix), and page (specific URL).
Package store provides persistent key-value storage with three scopes: global (project-wide), folder (URL path prefix), and page (specific URL).
Package store provides persistent key-value storage with three scopes: global (project-wide), folder (URL path prefix), and page (specific URL).
Package store provides persistent key-value storage with three scopes: global (project-wide), folder (URL path prefix), and page (specific URL).
Index ¶
- Constants
- Variables
- func GetFolderKey(rawURL string) string
- func HashScopeKey(scopeKey string) string
- func NormalizeURL(rawURL string) string
- type FileRef
- type StoreEntry
- type StoreFile
- type StoreManager
- func (m *StoreManager) Clear(basePath, scope, scopeKey string) error
- func (m *StoreManager) Delete(basePath, scope, scopeKey, key string) error
- func (m *StoreManager) Get(basePath, scope, scopeKey, key string) (*StoreEntry, error)
- func (m *StoreManager) GetAll(basePath, scope, scopeKey string) (map[string]*StoreEntry, error)
- func (m *StoreManager) List(basePath, scope, scopeKey string) ([]string, error)
- func (m *StoreManager) Set(basePath, scope, scopeKey, key string, value interface{}, ...) error
- type StoreRequest
- type StoreResponse
Constants ¶
const ( ScopeGlobal = "global" ScopeFolder = "folder" ScopePage = "page" )
Scope constants for the three storage levels.
const ( TypeString = "string" TypeJSON = "json" TypeFileRef = "file_ref" )
Entry type constants.
const StoreDir = ".agnt/store"
StoreDir is the directory within each project for store data.
Variables ¶
var ( // ErrNotFound is returned when a key doesn't exist. ErrNotFound = fmt.Errorf("key not found") // ErrInvalidScope is returned when an invalid scope is provided. ErrInvalidScope = fmt.Errorf("invalid scope: must be global, folder, or page") )
Functions ¶
func GetFolderKey ¶
GetFolderKey extracts the folder/path prefix from a URL. For example:
- "/products/123" -> "/products/"
- "/products/" -> "/products/"
- "/products" -> "/products/"
- "/" -> "/"
- "https://example.com/api/users/42" -> "/api/users/"
func HashScopeKey ¶
HashScopeKey generates a safe filename hash from a scope key. Uses SHA256 and returns the first 16 characters of the hex digest. This ensures consistent, filesystem-safe names for scope files.
func NormalizeURL ¶
NormalizeURL removes query params, hash fragments, and trailing slashes. This creates a canonical URL form for consistent storage keys.
Types ¶
type FileRef ¶
type FileRef struct {
FileID string `json:"file_id"`
FilePath string `json:"file_path"`
Size int64 `json:"size"`
ContentType string `json:"content_type,omitempty"`
}
FileRef represents a reference to a large file stored separately.
type StoreEntry ¶
type StoreEntry struct {
Value interface{} `json:"value"`
Type string `json:"type"` // string, json, file_ref
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Metadata map[string]any `json:"metadata,omitempty"`
}
StoreEntry represents a stored value with metadata.
func NewStoreEntry ¶
func NewStoreEntry(value interface{}, metadata map[string]any) *StoreEntry
NewStoreEntry creates a new store entry with the current timestamp.
type StoreFile ¶
type StoreFile struct {
Version int `json:"version"`
Scope string `json:"scope"`
ScopeKey string `json:"scope_key"`
Entries map[string]*StoreEntry `json:"entries"`
UpdatedAt string `json:"updated_at"`
}
StoreFile represents the JSON structure of a scope file.
func NewStoreFile ¶
NewStoreFile creates a new empty store file for a scope.
type StoreManager ¶
type StoreManager struct {
// contains filtered or unexported fields
}
StoreManager manages persistent key-value storage with file-based scopes.
func NewStoreManager ¶
func NewStoreManager() *StoreManager
NewStoreManager creates a new store manager.
func (*StoreManager) Clear ¶
func (m *StoreManager) Clear(basePath, scope, scopeKey string) error
Clear removes all entries from a scope.
func (*StoreManager) Delete ¶
func (m *StoreManager) Delete(basePath, scope, scopeKey, key string) error
Delete removes a key from the store.
func (*StoreManager) Get ¶
func (m *StoreManager) Get(basePath, scope, scopeKey, key string) (*StoreEntry, error)
Get retrieves a value from the store.
func (*StoreManager) GetAll ¶
func (m *StoreManager) GetAll(basePath, scope, scopeKey string) (map[string]*StoreEntry, error)
GetAll returns all entries in a scope.
type StoreRequest ¶
type StoreRequest struct {
Action string `json:"action"` // get, set, delete, list, clear, get_all
Scope string `json:"scope"` // global, folder, page
ScopeKey string `json:"scope_key"` // URL or path for page/folder
Key string `json:"key"`
Value interface{} `json:"value,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
StoreRequest represents a store operation request.
type StoreResponse ¶
type StoreResponse struct {
Success bool `json:"success"`
Entry *StoreEntry `json:"entry,omitempty"`
Entries map[string]*StoreEntry `json:"entries,omitempty"`
Keys []string `json:"keys,omitempty"`
Error string `json:"error,omitempty"`
}
StoreResponse represents a store operation response.