Documentation
¶
Overview ¶
Package core contains librecode-compatible assistant core data structures.
Index ¶
- Constants
- func AssertSessionCWDExists(source SessionCWDSource, fallbackCWD string) error
- func AutoActivateSkills(prompt string, skills []Skill) ([]ActivatedSkill, []ResourceDiagnostic)
- func BashExecutionToText(message BashExecutionMessage) string
- func FormatActiveSkillsForPrompt(skills []ActivatedSkill) string
- func FormatMissingSessionCWDError(issue SessionCWDIssue) string
- func FormatMissingSessionCWDPrompt(issue SessionCWDIssue) 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 BashExecutionMessage
- type BranchSummaryMessage
- type CompactionSummaryMessage
- type ContentPart
- type CustomMessage
- type DefaultResourceLoader
- type LLMMessage
- type LoadSkillsResult
- type MissingSessionCWDError
- type ResourceCollision
- type ResourceDiagnostic
- type ResourceSnapshot
- type SessionCWDIssue
- type SessionCWDSource
- 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" )
const ( // CompactionSummaryPrefix wraps compacted conversation history. CompactionSummaryPrefix = "The conversation history before this point was compacted into the following summary:" + "\n\n<summary>\n" // CompactionSummarySuffix closes a compacted summary block. CompactionSummarySuffix = "\n</summary>" // BranchSummaryPrefix wraps summaries from abandoned branches. BranchSummaryPrefix = "The following is a summary of a branch that this conversation came back from:\n\n<summary>\n" // BranchSummarySuffix closes a branch summary block. BranchSummarySuffix = "</summary>" )
Variables ¶
This section is empty.
Functions ¶
func AssertSessionCWDExists ¶
func AssertSessionCWDExists(source SessionCWDSource, fallbackCWD string) error
AssertSessionCWDExists returns MissingSessionCWDError when the stored cwd is missing.
func AutoActivateSkills ¶
func AutoActivateSkills(prompt string, skills []Skill) ([]ActivatedSkill, []ResourceDiagnostic)
AutoActivateSkills selects matching skills and reads their SKILL.md content for prompt context.
func BashExecutionToText ¶
func BashExecutionToText(message BashExecutionMessage) string
BashExecutionToText renders a shell execution as user-message context.
func FormatActiveSkillsForPrompt ¶
func FormatActiveSkillsForPrompt(skills []ActivatedSkill) string
FormatActiveSkillsForPrompt formats full activated skill content for the model request.
func FormatMissingSessionCWDError ¶
func FormatMissingSessionCWDError(issue SessionCWDIssue) string
FormatMissingSessionCWDError formats a terminal error message.
func FormatMissingSessionCWDPrompt ¶
func FormatMissingSessionCWDPrompt(issue SessionCWDIssue) string
FormatMissingSessionCWDPrompt formats an interactive confirmation prompt.
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 BashExecutionMessage ¶
type BashExecutionMessage struct {
ExitCode *int `json:"exit_code,omitempty"`
Command string `json:"command"`
Output string `json:"output"`
FullOutputPath string `json:"full_output_path,omitempty"`
Timestamp int64 `json:"timestamp"`
Canceled bool `json:"canceled"`
Truncated bool `json:"truncated"`
ExcludeFromContext bool `json:"exclude_from_context,omitempty"`
}
BashExecutionMessage records a user-triggered shell command.
func (*BashExecutionMessage) UnmarshalJSON ¶
func (message *BashExecutionMessage) UnmarshalJSON(data []byte) error
UnmarshalJSON preserves compatibility with sessions written before the canonical American-English canceled key was fixed.
type BranchSummaryMessage ¶
type BranchSummaryMessage struct {
Summary string `json:"summary"`
FromID string `json:"from_id"`
Timestamp int64 `json:"timestamp"`
}
BranchSummaryMessage is a summary for a branch that was left.
func NewBranchSummaryMessage ¶
func NewBranchSummaryMessage(summary, fromID, timestamp string) BranchSummaryMessage
NewBranchSummaryMessage creates a branch summary message from an RFC3339 timestamp.
type CompactionSummaryMessage ¶
type CompactionSummaryMessage struct {
Summary string `json:"summary"`
Timestamp int64 `json:"timestamp"`
TokensBefore int `json:"tokens_before"`
}
CompactionSummaryMessage is a summary for compacted prior context.
func NewCompactionSummaryMessage ¶
func NewCompactionSummaryMessage(summary string, tokensBefore int, timestamp string) CompactionSummaryMessage
NewCompactionSummaryMessage creates a compaction summary message from an RFC3339 timestamp.
type ContentPart ¶
type ContentPart struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
Data string `json:"data,omitempty"`
MIMEType string `json:"mime_type,omitempty"`
}
ContentPart is a model-facing text or image block.
type CustomMessage ¶
type CustomMessage struct {
Details any `json:"details,omitempty"`
CustomType string `json:"custom_type"`
Content []ContentPart `json:"content"`
Timestamp int64 `json:"timestamp"`
Display bool `json:"display"`
}
CustomMessage is extension-injected context.
func NewCustomMessage ¶
func NewCustomMessage( customType string, content []ContentPart, display bool, details any, timestamp string, ) CustomMessage
NewCustomMessage creates an extension custom message from an RFC3339 timestamp.
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 LLMMessage ¶
type LLMMessage struct {
Role string `json:"role"`
Content []ContentPart `json:"content"`
Timestamp int64 `json:"timestamp"`
}
LLMMessage is the generic message shape sent to a model.
func BashExecutionToLLM ¶
func BashExecutionToLLM(message BashExecutionMessage) (LLMMessage, bool)
BashExecutionToLLM converts a bash execution into model-facing context.
func BranchSummaryToLLM ¶
func BranchSummaryToLLM(message BranchSummaryMessage) LLMMessage
BranchSummaryToLLM converts a branch summary into model-facing context.
func CompactionSummaryToLLM ¶
func CompactionSummaryToLLM(message CompactionSummaryMessage) LLMMessage
CompactionSummaryToLLM converts a compaction summary into model-facing context.
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 MissingSessionCWDError ¶
type MissingSessionCWDError struct {
Issue SessionCWDIssue `json:"issue"`
}
MissingSessionCWDError reports a missing stored working directory.
func (*MissingSessionCWDError) Error ¶
func (err *MissingSessionCWDError) Error() string
Error formats the missing cwd issue.
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 SessionCWDIssue ¶
type SessionCWDIssue struct {
SessionFile string `json:"session_file,omitempty"`
SessionCWD string `json:"session_cwd"`
FallbackCWD string `json:"fallback_cwd"`
}
SessionCWDIssue describes a missing stored session working directory.
func MissingSessionCWDIssueFor ¶
func MissingSessionCWDIssueFor(source SessionCWDSource, fallbackCWD string) (SessionCWDIssue, bool)
MissingSessionCWDIssueFor returns an issue if the session file points to a missing cwd.
type SessionCWDSource ¶
SessionCWDSource exposes session working-directory metadata.
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" )
Source Files
¶
- agent_instructions.go
- constants.go
- defaults.go
- diagnostics.go
- errors.go
- frontmatter.go
- home.go
- messages.go
- resource.go
- resource_loader.go
- session_cwd.go
- skills.go
- skills_activation.go
- skills_cache.go
- skills_discovery.go
- skills_frontmatter.go
- skills_ignore.go
- skills_prompt.go
- skills_source.go
- skills_validation.go
- source_info.go