fsdb

package
v1.4.474 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LooksLikePatternFilePath added in v1.4.474

func LooksLikePatternFilePath(source string) bool

LooksLikePatternFilePath reports whether loadPattern uses source as a filesystem path. HTTP handlers must reject these names to keep the CLI file-path feature out of the REST API.

func ValidateStorageName added in v1.4.474

func ValidateStorageName(name string) error

ValidateStorageName rejects an empty name, ".", "..", and each name that is not a single path element. It also rejects names that are dangerous only on Windows: names with ":" (an NTFS alternate data stream suffix), names with a dot or space at the end, and reserved DOS device names. Windows removes a dot or space at the end, and the shortened name then collides with an existing entry. The policy is the same on each platform, and an entry made on one system stays valid on the other systems. A Unix entry that already has a name against these rules shows in GetNames but is not accessible. To repair it, rename its file or directory on disk. Call this function before you join a name to a storage directory.

Types

type Context

type Context struct {
	Name    string
	Content string
}

type ContextsEntity

type ContextsEntity struct {
	*StorageEntity
}

func (*ContextsEntity) Get

func (o *ContextsEntity) Get(name string) (ret *Context, err error)

Get Load a context from file

func (*ContextsEntity) PrintContext

func (o *ContextsEntity) PrintContext(name string) (err error)

type Db

type Db struct {
	Dir string

	Patterns *PatternsEntity
	Sessions *SessionsEntity
	Contexts *ContextsEntity

	EnvFilePath string
	// contains filtered or unexported fields
}

func NewDb

func NewDb(dir string) (db *Db)

func (*Db) ApplyEnvUpdates added in v1.4.471

func (o *Db) ApplyEnvUpdates(updates map[string]string) error

ApplyEnvUpdates writes non-empty updates atomically. Callers holding WithEnvLock use this.

func (*Db) Configure

func (o *Db) Configure() (err error)

func (*Db) FilePath

func (o *Db) FilePath(fileName string) (ret string)

func (*Db) IsEnvFileExists

func (o *Db) IsEnvFileExists() (ret bool)

func (*Db) LoadEnvFile

func (o *Db) LoadEnvFile() (err error)

func (*Db) ReadEnvFile added in v1.4.471

func (o *Db) ReadEnvFile() (map[string]string, error)

func (*Db) SaveEnv

func (o *Db) SaveEnv(content string) error

func (*Db) UpdateEnvVars added in v1.4.471

func (o *Db) UpdateEnvVars(updates map[string]string) error

UpdateEnvVars merges non-empty values into .env under a file lock. Comments and key order are not preserved.

func (*Db) WithEnvLock added in v1.4.471

func (o *Db) WithEnvLock(fn func() error) error

type DirectoryChange

type DirectoryChange struct {
	Dir       string
	Timestamp time.Time
}

type InvalidStorageNameError added in v1.4.474

type InvalidStorageNameError struct {
	Name    string
	Message string // optional: the default is the storage_invalid_name translation
}

InvalidStorageNameError reports a name that storage-name validation rejected. HTTP handlers map it to 400 Bad Request. All other storage errors stay 500 errors.

func (*InvalidStorageNameError) Error added in v1.4.474

func (e *InvalidStorageNameError) Error() string

type Pattern

type Pattern struct {
	Name        string
	Description string
	Pattern     string
}

Pattern represents a single pattern with its metadata

type PatternsEntity

type PatternsEntity struct {
	*StorageEntity
	SystemPatternFile      string
	UniquePatternsFilePath string
	CustomPatternsDir      string
}

func (*PatternsEntity) Get

func (o *PatternsEntity) Get(name string) (*Pattern, error)

Get required for Storage interface

func (*PatternsEntity) GetApplyVariables

func (o *PatternsEntity) GetApplyVariables(
	source string, variables map[string]string, input string) (pattern *Pattern, err error)

GetApplyVariables main entry point for getting patterns from any source

func (*PatternsEntity) GetNames

func (o *PatternsEntity) GetNames() (ret []string, err error)

GetNames overrides StorageEntity.GetNames to include custom patterns directory

func (*PatternsEntity) GetRaw added in v1.4.429

func (o *PatternsEntity) GetRaw(name string) (*Pattern, error)

GetRaw returns a pattern from storage without applying variable processing.

func (*PatternsEntity) GetWithoutVariables added in v1.4.289

func (o *PatternsEntity) GetWithoutVariables(source, input string) (pattern *Pattern, err error)

GetWithoutVariables returns a pattern with only the {{input}} placeholder processed and skips template variable replacement

func (*PatternsEntity) ListNames

func (o *PatternsEntity) ListNames(shellCompleteList bool) (err error)

ListNames overrides StorageEntity.ListNames to use PatternsEntity.GetNames

func (*PatternsEntity) PrintLatestPatterns

func (o *PatternsEntity) PrintLatestPatterns(latestNumber int) (err error)

func (*PatternsEntity) PrintPattern added in v1.4.446

func (o *PatternsEntity) PrintPattern(name string) (err error)

PrintPattern prints the raw contents of the named pattern to the terminal. It checks the custom patterns directory first, then falls back to the main directory.

func (*PatternsEntity) Rename added in v1.4.474

func (o *PatternsEntity) Rename(oldName, newName string) error

Rename applies the file-path guard from Save to the destination name. Without the guard, the inherited StorageEntity.Rename accepts ".foo" or "~foo", and loadPattern then reads these names from the filesystem. A path-like source stays permitted, which lets you rename a legacy entry to a valid name.

func (*PatternsEntity) Save

func (o *PatternsEntity) Save(name string, content []byte) (err error)

type Session

type Session struct {
	Name     string
	Messages []*chat.ChatCompletionMessage
	// contains filtered or unexported fields
}

func (*Session) Append

func (o *Session) Append(messages ...*chat.ChatCompletionMessage)

func (*Session) GetLastMessage

func (o *Session) GetLastMessage() (ret *chat.ChatCompletionMessage)

func (*Session) GetVendorMessages

func (o *Session) GetVendorMessages() (ret []*chat.ChatCompletionMessage)

func (*Session) IsEmpty

func (o *Session) IsEmpty() bool

func (*Session) String

func (o *Session) String() (ret string)

type SessionsEntity

type SessionsEntity struct {
	*StorageEntity
}

func (*SessionsEntity) Get

func (o *SessionsEntity) Get(name string) (session *Session, err error)

func (*SessionsEntity) PrintSession

func (o *SessionsEntity) PrintSession(name string) (err error)

func (*SessionsEntity) SaveSession

func (o *SessionsEntity) SaveSession(session *Session) (err error)

type StorageEntity

type StorageEntity struct {
	Label         string
	Dir           string
	ItemIsDir     bool
	FileExtension string
}

StorageEntity is the filesystem-backed db.Storage implementation. Each method that gets a name requires one that obeys ValidateStorageName. It rejects other names with *InvalidStorageNameError, which HTTP handlers map to 400.

func (*StorageEntity) BuildFilePath

func (o *StorageEntity) BuildFilePath(fileName string) (ret string)

func (*StorageEntity) Configure

func (o *StorageEntity) Configure() (err error)

func (*StorageEntity) Delete

func (o *StorageEntity) Delete(name string) (err error)

func (*StorageEntity) Exists

func (o *StorageEntity) Exists(name string) (ret bool)

func (*StorageEntity) GetNames

func (o *StorageEntity) GetNames() (ret []string, err error)

GetNames finds all patterns in the patterns directory and enters the id, name, and pattern into a slice of Entry structs. it returns these entries or an error

func (*StorageEntity) ListNames

func (o *StorageEntity) ListNames(shellCompleteList bool) (err error)

func (*StorageEntity) Load

func (o *StorageEntity) Load(name string) (ret []byte, err error)

func (*StorageEntity) LoadAsJson

func (o *StorageEntity) LoadAsJson(name string, item any) (err error)

func (*StorageEntity) Rename

func (o *StorageEntity) Rename(oldName, newName string) (err error)

func (*StorageEntity) Save

func (o *StorageEntity) Save(name string, content []byte) (err error)

func (*StorageEntity) SaveAsJson

func (o *StorageEntity) SaveAsJson(name string, item any) (err error)

Jump to

Keyboard shortcuts

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