store

package
v0.13.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

View Source
const (
	ScopeGlobal = "global"
	ScopeFolder = "folder"
	ScopePage   = "page"
)

Scope constants for the three storage levels.

View Source
const (
	TypeString  = "string"
	TypeJSON    = "json"
	TypeFileRef = "file_ref"
)

Entry type constants.

View Source
const StoreDir = ".agnt/store"

StoreDir is the directory within each project for store data.

Variables

View Source
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

func GetFolderKey(rawURL string) string

GetFolderKey extracts the folder/path prefix from a URL. For example:

func HashScopeKey

func HashScopeKey(scopeKey string) string

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

func NormalizeURL(rawURL string) string

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

func NewStoreFile(scope, scopeKey string) *StoreFile

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.

func (*StoreManager) List

func (m *StoreManager) List(basePath, scope, scopeKey string) ([]string, error)

List returns all keys in a scope.

func (*StoreManager) Set

func (m *StoreManager) Set(basePath, scope, scopeKey, key string, value interface{}, metadata map[string]any) error

Set stores a value in the store.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL