Documentation
¶
Overview ¶
Package core contains librecode-compatible assistant core data structures.
Index ¶
- Constants
- func FormatActiveSkillsForPrompt(skills []ActivatedSkill) string
- func FormatSkillsForPrompt(skills []Skill) string
- func LibrecodeHome() (string, error)
- func LoadAgentInstructions(cwd string) string
- func ProjectConfigDir(cwd string) string
- func SkillContent(skill *Skill) (string, error)
- type ActivatedSkill
- type DefaultResourceLoader
- type LoadSkillsResult
- type ResourceCollision
- type ResourceDiagnostic
- type ResourceSnapshot
- type Skill
- type SkillActivationDiagnostic
- type SkillActivationResult
- type SkillsCache
- type SourceInfo
- type SourceInfoOptions
- type SourceOrigin
- type SourceScope
Constants ¶
const ( // DefaultThinkingLevel matches librecode's default model reasoning level. DefaultThinkingLevel = "medium" // ConfigDirName is the project-local configuration directory. ConfigDirName = ".librecode" // AgentsDirName is the OpenSkills/agent-compatible configuration directory. AgentsDirName = ".agents" )
Variables ¶
This section is empty.
Functions ¶
func FormatActiveSkillsForPrompt ¶
func FormatActiveSkillsForPrompt(skills []ActivatedSkill) string
FormatActiveSkillsForPrompt formats full activated skill content for the model request.
func FormatSkillsForPrompt ¶
FormatSkillsForPrompt formats skill metadata in librecode's XML prompt block.
func LibrecodeHome ¶
LibrecodeHome returns the user-level librecode home directory.
LIBRECODE_HOME overrides the default ~/.librecode location. The returned path is cleaned and may be relative only when the caller explicitly configured a relative LIBRECODE_HOME.
func LoadAgentInstructions ¶
LoadAgentInstructions loads global and project AGENTS.md-style instructions for cwd. It follows Codex-compatible precedence: one file from the global LibreCode home, then one file per project directory from root to cwd.
func ProjectConfigDir ¶
ProjectConfigDir returns the project-local librecode directory for cwd.
func SkillContent ¶
SkillContent reads one skill file's full Markdown content.
Types ¶
type ActivatedSkill ¶
type ActivatedSkill struct {
Content string `json:"content"`
Skill Skill `json:"skill"`
Truncated bool `json:"truncated"`
}
ActivatedSkill contains full skill content selected for the current prompt.
type DefaultResourceLoader ¶
type DefaultResourceLoader struct {
// contains filtered or unexported fields
}
DefaultResourceLoader loads local skills and agent instructions for a working directory.
func NewDefaultResourceLoader ¶
func NewDefaultResourceLoader(cwd string) *DefaultResourceLoader
NewDefaultResourceLoader creates a resource loader for cwd.
func (*DefaultResourceLoader) Reload ¶
func (loader *DefaultResourceLoader) Reload(ctx context.Context) error
Reload refreshes the resource snapshot from disk.
func (*DefaultResourceLoader) Snapshot ¶
func (loader *DefaultResourceLoader) Snapshot() ResourceSnapshot
Snapshot returns a defensive copy of the current resource state.
type LoadSkillsResult ¶
type LoadSkillsResult struct {
Skills []Skill `json:"skills"`
AgentInstructions string `json:"agent_instructions"`
Diagnostics []ResourceDiagnostic `json:"diagnostics"`
}
LoadSkillsResult returns loaded skills, agent instructions, and validation diagnostics.
func LoadSkills ¶
func LoadSkills(cwd string, skillPaths []string, includeDefaults bool) LoadSkillsResult
LoadSkills loads skills from the four supported default roots and explicit paths.
type ResourceCollision ¶
type ResourceCollision struct {
ResourceType string `json:"resource_type"`
Name string `json:"name"`
WinnerPath string `json:"winner_path"`
LoserPath string `json:"loser_path"`
}
ResourceCollision describes a resource name collision.
type ResourceDiagnostic ¶
type ResourceDiagnostic struct {
Collision *ResourceCollision `json:"collision,omitempty"`
Type string `json:"type"`
Message string `json:"message"`
Path string `json:"path,omitempty"`
}
ResourceDiagnostic reports a loaded resource warning, error, or name collision.
type ResourceSnapshot ¶
type ResourceSnapshot struct {
SkillDiagnostics []ResourceDiagnostic `json:"skill_diagnostics"`
AgentInstructions string `json:"agent_instructions"`
Skills []Skill `json:"skills"`
}
ResourceSnapshot is a coherent immutable view of loaded resources.
type Skill ¶
type Skill struct {
Metadata map[string]any `json:"metadata,omitempty"`
SourceInfo SourceInfo `json:"source_info"`
Name string `json:"name"`
Description string `json:"description"`
FilePath string `json:"file_path"`
BaseDir string `json:"base_dir"`
License string `json:"license,omitempty"`
Compatibility string `json:"compatibility,omitempty"`
AllowedTools []string `json:"allowed_tools,omitempty"`
UserInvocable bool `json:"user_invocable,omitempty"`
DisableModelInvocation bool `json:"disable_model_invocation"`
}
Skill describes one Agent Skills compatible skill file.
type SkillActivationDiagnostic ¶
type SkillActivationDiagnostic struct {
Reason string `json:"reason"`
Skill Skill `json:"skill"`
Score int `json:"score"`
}
SkillActivationDiagnostic explains why a skill was automatically activated.
type SkillActivationResult ¶
type SkillActivationResult struct {
Activated []ActivatedSkill `json:"activated"`
Diagnostics []ResourceDiagnostic `json:"diagnostics"`
Matches []SkillActivationDiagnostic `json:"matches"`
}
SkillActivationResult returns activated skill content plus activation diagnostics.
func AutoActivateSkillsDetailed ¶
func AutoActivateSkillsDetailed(prompt string, skills []Skill) SkillActivationResult
AutoActivateSkillsDetailed selects matching skills and returns activation reasons for diagnostics.
type SkillsCache ¶
type SkillsCache struct {
// contains filtered or unexported fields
}
SkillsCache memoizes LoadSkills results per working directory using samber/hot. Cached entries are invalidated automatically when underlying files change via fsnotify so that new or edited skills are picked up without a restart. Burst events (e.g. git checkout) are debounced so a burst triggers a single purge rather than one per file. If the watcher cannot be created the cache still functions as simple memoization.
func NewSkillsCache ¶
func NewSkillsCache() *SkillsCache
NewSkillsCache creates a skills cache backed by samber/hot with an fsnotify watcher.
func (*SkillsCache) Close ¶
func (c *SkillsCache) Close()
Close stops the background watcher goroutine and cache janitor. It is safe to call multiple times and when the watcher was never started.
func (*SkillsCache) Get ¶
func (c *SkillsCache) Get(cwd string) LoadSkillsResult
Get returns the cached skills for cwd, loading from disk on first access or after a file system change has invalidated the cache.
type SourceInfo ¶
type SourceInfo struct {
Path string `json:"path"`
Source string `json:"source"`
Scope SourceScope `json:"scope"`
Origin SourceOrigin `json:"origin"`
BaseDir string `json:"base_dir,omitempty"`
}
SourceInfo describes where a loaded resource came from.
func NewSourceInfo ¶
func NewSourceInfo(path string, options SourceInfoOptions) SourceInfo
NewSourceInfo creates SourceInfo with librecode-compatible defaults.
type SourceInfoOptions ¶
type SourceInfoOptions struct {
Scope SourceScope `json:"scope"`
Origin SourceOrigin `json:"origin"`
BaseDir string `json:"base_dir,omitempty"`
Source string `json:"source"`
}
SourceInfoOptions contains optional source metadata.
type SourceOrigin ¶
type SourceOrigin string
SourceOrigin identifies whether a resource came from a package or top-level path.
const ( // SourceOriginPackage identifies package-provided resources. SourceOriginPackage SourceOrigin = "package" // SourceOriginTopLevel identifies top-level resources. SourceOriginTopLevel SourceOrigin = "top-level" )
type SourceScope ¶
type SourceScope string
SourceScope identifies whether a resource came from user, project, or temporary config.
const ( // SourceScopeUser identifies user-scoped resources. SourceScopeUser SourceScope = "user" // SourceScopeProject identifies project-scoped resources. SourceScopeProject SourceScope = "project" // SourceScopeTemporary identifies temporary CLI/session resources. SourceScopeTemporary SourceScope = "temporary" )