config

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContentHash

func ContentHash(content []byte) string

ContentHash computes the sha256 hex digest of content bytes.

Types

type ConflictAction added in v0.2.0

type ConflictAction int

ConflictAction describes the resolution the user selected for a single conflict-file entry during the cinematic ConflictsStage. Consumed by applyCinematicConflictPicks in cmd/add.go, which translates the per-file action into the WriteResult.ForceSelected + optional .bak write that the legacy buildConflictSteps / applyConflictPicks primitives perform as a bulk two-step form.

const (
	// ConflictActionKeep keeps the user's local edits — no write happens.
	ConflictActionKeep ConflictAction = iota
	// ConflictActionOverwrite overwrites the local file with the source
	// content. No backup is created.
	ConflictActionOverwrite
	// ConflictActionBackup writes the current local file to `<path>.bak`
	// and then overwrites with source content.
	ConflictActionBackup
)

type CustomItemMeta

type CustomItemMeta struct {
	DisplayName string `yaml:"display_name,omitempty"`
	Description string `yaml:"description"`
	Event       string `yaml:"event,omitempty"`     // sensors only
	Matcher     string `yaml:"matcher,omitempty"`   // sensors only
	Frequency   string `yaml:"frequency,omitempty"` // routines only
}

CustomItemMeta holds metadata for user-created custom items (parsed from frontmatter).

type FileEntry

type FileEntry struct {
	Hash   string `yaml:"hash"`
	Source string `yaml:"source,omitempty"`
}

FileEntry records a single generated file in the lock file.

type InstalledAgent

type InstalledAgent struct {
	AgentType   string                     `yaml:"agent_type"`
	Workspace   string                     `yaml:"workspace"`
	Skills      []string                   `yaml:"skills"`
	Workflows   []string                   `yaml:"workflows"`
	Protocols   []string                   `yaml:"protocols"`
	Sensors     []string                   `yaml:"sensors"`
	Routines    []string                   `yaml:"routines"`
	CustomItems map[string]*CustomItemMeta `yaml:"custom_items,omitempty"`
}

InstalledAgent represents an agent installed in a project.

type LockFile

type LockFile struct {
	Version int                   `yaml:"version"`
	Files   map[string]*FileEntry `yaml:"files"`
}

LockFile tracks all files generated by Bonsai.

func LoadLockFile

func LoadLockFile(projectRoot string) (*LockFile, error)

LoadLockFile reads the lock file from disk. Returns a new empty lock file if the file doesn't exist (first run / migration case).

func NewLockFile

func NewLockFile() *LockFile

NewLockFile creates an empty lock file.

func (*LockFile) IsModified

func (lf *LockFile) IsModified(projectRoot, relPath string) (exists, modified bool)

IsModified checks whether the file on disk differs from the lock file hash. Returns exists=false if the file is not on disk (safe to write). Returns modified=true if the file exists but differs from the lock hash, or if the file exists but has no lock entry (conservative: treat as user-owned).

func (*LockFile) Save

func (lf *LockFile) Save(projectRoot string) error

Save writes the lock file to disk.

func (*LockFile) Track

func (lf *LockFile) Track(relPath string, content []byte, source string)

Track records a file in the lock file.

func (*LockFile) Untrack

func (lf *LockFile) Untrack(relPath string)

Untrack removes a file from the lock file.

type ProjectConfig

type ProjectConfig struct {
	ProjectName string                     `yaml:"project_name"`
	Description string                     `yaml:"description,omitempty"`
	DocsPath    string                     `yaml:"docs_path,omitempty"`
	Scaffolding []string                   `yaml:"scaffolding,omitempty"`
	Agents      map[string]*InstalledAgent `yaml:"agents,omitempty"`
}

ProjectConfig is the root project config serialized to .bonsai.yaml.

func Load

func Load(path string) (*ProjectConfig, error)

Load reads a ProjectConfig from a YAML file.

func (*ProjectConfig) Save

func (c *ProjectConfig) Save(path string) error

Save writes the config to a YAML file.

func (*ProjectConfig) Validate added in v0.4.0

func (c *ProjectConfig) Validate() error

Validate checks the project config for required fields, valid workspace paths, and the absence of shell metacharacters in user-controlled strings. Run after YAML unmarshalling so callers fail fast on hand-edited configs.

Workspace + DocsPath are validated through wsvalidate (same rules as the init/add TUI flows). The shell-metachar scan covers ProjectName, every agent name (map key), every agent.Workspace, and DocsPath — these strings flow into shell scripts via sensor templates, so a stray `"` or `$` would either break the script or open a substitution channel.

Jump to

Keyboard shortcuts

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