Help us shape the future of Go! Take the 2026 Go Developer Survey

bayesh

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const BayeshDirEnvVar = "BAYESH_DIR"
View Source
const LogLevelEnvVar = "BAYESH_LOG_LEVEL"
View Source
const MinRequiredEventsEnvVar = "BAYESH_MIN_REQUIRED_EVENTS"

Variables

This section is empty.

Functions

func AnsiColorTokens

func AnsiColorTokens(cmds string) string

func ComputeCommandProbabilities added in v0.0.2

func ComputeCommandProbabilities(ctx context.Context, settings *Settings, queries DatabaseQuerer, cwd string, processedPreviousCmd string) (map[string]float64, error)

Computes a weighted average of conditional probabilities. I.e. it computes the average of P(cmd|cwd), P(cmd|previousCmd), and P(cmd|cwd, previousCmd). This can be thought of as a Bayesian inference (E(P(cmd|a)) where a is the context).

func ProcessCmd

func ProcessCmd(fs StatFileSystem, cmd string) string

Update ProcessCmd to use StatFileSystem

Types

type Core

type Core struct {
	Settings *Settings
	// contains filtered or unexported fields
}

func NewCore

func NewCore(ctx context.Context, settings *Settings) (*Core, error)

func (*Core) Close

func (c *Core) Close() error

Close should be called to gracefully close the database connection.

func (*Core) InferCommands

func (c *Core) InferCommands(ctx context.Context, cwd string, previousCmd string) ([]string, error)

func (*Core) RecordEvent

func (c *Core) RecordEvent(ctx context.Context, cwd string, previousCmd string, currentCmd string) error

type DBTX

type DBTX interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
}

type DatabaseQuerer added in v0.0.2

type DatabaseQuerer interface {
	ConditionalEventCounts(ctx context.Context, cwd *string, previousCmd *string, minRequiredEvents *int) (map[string]int, error)
}

type FileSystem

type FileSystem interface {
	UserHomeDir() (string, error)
	Getenv(key string) string
	MkdirAll(path string, perm os.FileMode) error
	Stat(name string) (os.FileInfo, error)
	Create(name string) (*os.File, error)
}

type OsFs

type OsFs struct{}

func (OsFs) Create

func (OsFs) Create(name string) (*os.File, error)

func (OsFs) Getenv

func (OsFs) Getenv(key string) string

func (OsFs) MkdirAll

func (OsFs) MkdirAll(path string, perm os.FileMode) error

func (OsFs) Stat

func (OsFs) Stat(name string) (os.FileInfo, error)

func (OsFs) UserHomeDir

func (OsFs) UserHomeDir() (string, error)

type Queries

type Queries struct {
	// contains filtered or unexported fields
}

func New

func New(db *sql.DB) *Queries

func (*Queries) ConditionalEventCounts added in v0.0.2

func (q *Queries) ConditionalEventCounts(ctx context.Context, cwd *string, previousCmd *string, minEventCount *int) (map[string]int, error)

func (*Queries) CreateSchema

func (q *Queries) CreateSchema(ctx context.Context) error

func (*Queries) GetRow

func (q *Queries) GetRow(ctx context.Context, cwd, previousCmd, currentCmd string) (Row, error)

func (*Queries) InsertRow

func (q *Queries) InsertRow(ctx context.Context, arg Row) error

func (*Queries) UpdateRow

func (q *Queries) UpdateRow(ctx context.Context, arg Row) error

func (*Queries) WithTx

func (q *Queries) WithTx(tx *sql.Tx) *Queries

type Row

type Row struct {
	Cwd          string
	PreviousCmd  string
	CurrentCmd   string
	EventCounter int
	LastModified time.Time
}

type Settings

type Settings struct {
	BayeshDir         string     `json:"BAYESH_DIR" validate:"required,dir"`
	Database          string     `json:"BAYESH_DATABASE" validate:"required,file"`
	LogLevel          slog.Level `json:"BAYESH_LOG_LEVEL" validate:"required"`
	MinRequiredEvents int        `json:"BAYESH_MIN_REQUIRED_EVENTS" validate:"required,min=0"`
}

func Setup

func Setup(context context.Context, fs FileSystem) (*Settings, error)

func (*Settings) ToJSON

func (s *Settings) ToJSON() (string, error)

type StatFileSystem

type StatFileSystem interface {
	Stat(name string) (os.FileInfo, error)
}

type Token

type Token string
const (
	PATH   Token = "<PATH>"
	STRING Token = "<STRING>"
)
const (
	CYAN  Token = "\033[94m"
	RESET Token = "\033[0m"
)

Jump to

Keyboard shortcuts

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