Documentation
¶
Overview ¶
Package template provides agent template definitions and file-based storage. Templates replace Roles as the agent creation primitive.
Index ¶
- Variables
- func SeedDefaults(dir string) error
- type Scope
- type Store
- func (s *Store) Create(t Template, systemPrompt string, scope Scope) error
- func (s *Store) Delete(name string, scope Scope) error
- func (s *Store) Get(name string) (*Template, string, error)
- func (s *Store) GlobalDir() string
- func (s *Store) List() ([]Template, error)
- func (s *Store) Update(name string, t Template, systemPrompt string) error
- func (s *Store) WithOverride(workspaceDir string) *Store
- func (s *Store) WorkspaceDir() string
- type Template
- type ToolPolicies
Constants ¶
This section is empty.
Variables ¶
var ErrWrongScope = errors.New("template exists only in a different scope")
ErrWrongScope is returned from Delete when the caller is operating in a scope that does not own the named template. The command layer can match this with errors.Is to produce a friendly "use --global" hint.
Functions ¶
func SeedDefaults ¶
SeedDefaults creates the built-in templates when the directory is empty. It is a no-op when the directory already contains templates.
Types ¶
type Scope ¶
type Scope string
Scope identifies which layer of a LayeredStore a template lives in.
const ( // ScopeWorkspace is the per-workspace override directory // (<ws>/.bc/templates/). Values here win when a name collides with // the global scope. ScopeWorkspace Scope = "workspace" // ScopeGlobal is the user-global directory (~/.bc/templates/). It is // the default for writes unless the caller asks for a workspace // override explicitly. ScopeGlobal Scope = "global" )
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a file-based template store. Each template is stored as <name>.json (metadata) and an optional <name>.md (system prompt).
When both a workspace dir and a global dir are configured, List/Get merge the two with workspace overrides winning on name collision. Create defaults to writing the global dir; callers may pass ScopeWorkspace to write into the override dir instead. This keeps single-layer callers (legacy workspace-only code) working by passing only one directory.
func NewLayeredStore ¶
NewLayeredStore creates a two-layer Store. globalDir is the default write target and the fallback read source; workspaceDir, when non-empty, overrides globalDir on reads and is the write target only when scope == ScopeWorkspace.
Either argument may be empty: an empty globalDir degrades to a workspace-only store, and an empty workspaceDir degrades to a global-only store. At least one must be non-empty.
func NewStore ¶
NewStore creates a single-layer Store rooted at dir. The directory is created on first write. This is retained for backwards compatibility with callers that operate in a single-tenant model (eg. legacy per-workspace usage). Prefer NewLayeredStore for new code.
func (*Store) Create ¶
Create writes a new template. If scope is empty it defaults to ScopeGlobal when a global dir is configured, otherwise ScopeWorkspace. Returns an error if the template already exists in the target scope.
func (*Store) Delete ¶
Delete removes both the .json and .md files for the named template. If scope is empty the delete targets whichever layer owns the template, preferring the workspace override. When the caller asks for ScopeWorkspace but the template exists only in the global layer, the call fails with ErrWrongScope so the CLI can suggest --global.
func (*Store) Get ¶
Get returns the template and its system prompt markdown content. The workspace override is checked first; if not present there, the lookup falls back to the global layer. The system prompt is empty string when no .md file exists.
func (*Store) GlobalDir ¶
GlobalDir returns the configured global directory (empty when the store is workspace-only).
func (*Store) List ¶
List returns all templates visible through the store. When a workspace override dir is configured its templates shadow any global template with the same name; the Scope is reported on the returned Template for the UI / CLI.
func (*Store) Update ¶
Update overwrites an existing template. The write goes to whichever scope currently owns the template — if both layers have it, the workspace copy is updated, preserving user-global defaults.
func (*Store) WithOverride ¶
WithOverride returns a new Store that inherits the receiver's global dir but uses workspaceDir as its override layer. The receiver is unchanged so it remains safe for concurrent use with multiple workspace scopes.
func (*Store) WorkspaceDir ¶
WorkspaceDir returns the configured workspace override directory (empty when the store is single-layer).
type Template ¶
type Template struct {
ToolPolicies *ToolPolicies `json:"tool_policies,omitempty"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
SystemPromptFile string `json:"system_prompt_file,omitempty"`
Scope Scope `json:"scope,omitempty"`
MCPs []string `json:"mcps,omitempty"`
Secrets []string `json:"secrets,omitempty"`
Plugins []string `json:"plugins,omitempty"`
ContextFiles []string `json:"context_files,omitempty"`
MaxCostUSD float64 `json:"max_cost_usd,omitempty"`
StuckTimeoutMin int `json:"stuck_timeout_min,omitempty"`
}
Template defines an agent template — a reusable configuration for spawning agents.
Scope is a runtime-only attribute set by the Store when loading a template; it is never persisted to disk. It records which layer of a LayeredStore the template came from ("global" for ~/.bc/templates/, "workspace" for <ws>/.bc/templates/).
type ToolPolicies ¶
type ToolPolicies struct {
Allowed []string `json:"allowed,omitempty"`
Denied []string `json:"denied,omitempty"`
}
ToolPolicies defines allow/deny lists for agent tool access.