persona

package
v1.63.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

* ChatCLI - Persona System * pkg/persona/builder.go * Copyright (c) 2024 Edilson Freitas * License: MIT

* ChatCLI - Persona System * pkg/persona/loader.go * Copyright (c) 2024 Edilson Freitas * License: MIT

* ChatCLI - Persona System * Copyright (c) 2024 Edilson Freitas * License: MIT

* ChatCLI - Persona System * pkg/persona/types.go * Copyright (c) 2024 Edilson Freitas * License: MIT

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InferExecutionCommand added in v1.62.0

func InferExecutionCommand(scriptName, absPath string) string

inferExecutionCommand guesses the best command to run a script based on extension

Types

type Agent

type Agent struct {
	// Metadata from frontmatter
	Name        string     `json:"name" yaml:"name"`
	Description string     `json:"description" yaml:"description"`
	Skills      StringList `json:"skills" yaml:"skills"`   // Usando StringList para robustez
	Plugins     StringList `json:"plugins" yaml:"plugins"` // Usando StringList para robustez
	Tools       StringList `json:"tools" yaml:"tools"`     // Allowed tools for worker mode (Read, Grep, Glob, Bash, Write, Edit)
	Model       string     `json:"model" yaml:"model"`

	// Content is the markdown body (without frontmatter)
	Content string `json:"-" yaml:"-"`

	// Path to the source file
	Path string `json:"-" yaml:"-"`
}

Agent represents a loadable persona with skills

type Builder

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

Builder assembles system prompts from agents and skills

func NewBuilder

func NewBuilder(logger *zap.Logger, loader *Loader) *Builder

NewBuilder creates a new prompt builder

func (*Builder) BuildMultiAgentPrompt added in v1.49.0

func (b *Builder) BuildMultiAgentPrompt(agents []*Agent) (*ComposedPrompt, error)

BuildMultiAgentPrompt assembles a prompt for multiple agents simultaneously

func (*Builder) BuildSystemPrompt

func (b *Builder) BuildSystemPrompt(agentName string) (*ComposedPrompt, error)

BuildSystemPrompt legacy wrapper for single agent

func (*Builder) ValidateAgent

func (b *Builder) ValidateAgent(agentName string) ([]string, []string, error)

ValidateAgent checks if an agent and its linked skills are valid/exist

type ComposedPrompt

type ComposedPrompt struct {
	ActiveAgents  []string // List of active agent names
	SkillsLoaded  []string
	SkillsMissing []string
	FullPrompt    string
}

ComposedPrompt represents the final assembled system prompt

type LoadResult

type LoadResult struct {
	Agent         *Agent
	LoadedSkills  []string // Skills that were successfully loaded
	MissingSkills []string // Skills that were not found
	Warnings      []string // Non-fatal issues
}

LoadResult represents the result of loading an agent with its skills

type Loader

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

Loader handles loading agents and skills from disk

func NewLoader

func NewLoader(logger *zap.Logger) *Loader

NewLoader creates a new persona loader with default paths

func (*Loader) EnsureDirectories

func (l *Loader) EnsureDirectories() error

EnsureDirectories creates the agents and skills directories if they don't exist

func (*Loader) GetAgent

func (l *Loader) GetAgent(name string) (*Agent, error)

GetAgent returns an agent by name. It prioritizes: 1. Project-local agent file (.agent/agents/{name}.md) 2. Project-local agent by metadata search 3. Global agent file (~/.chatcli/agents/{name}.md) 4. Global agent by metadata search

func (*Loader) GetAgentsDir

func (l *Loader) GetAgentsDir() string

GetAgentsDir returns the path to the agents directory

func (*Loader) GetSkill

func (l *Loader) GetSkill(name string) (*Skill, error)

GetSkill locates and loads a skill by name. It prioritizes: 1. Project-local Package (Folder with SKILL.md) 2. Project-local File (.md) 3. Global Package 4. Global File

func (*Loader) GetSkillsDir

func (l *Loader) GetSkillsDir() string

GetSkillsDir returns the path to the skills directory

func (*Loader) ListAgents

func (l *Loader) ListAgents() ([]*Agent, error)

ListAgents returns all available agents scanning both project-local and global directories. Priority: Project Local (.agent/agents/) > Global (~/.chatcli/agents/)

func (*Loader) ListSkills

func (l *Loader) ListSkills() ([]*Skill, error)

ListSkills returns all available skills (names only for listing purposes) It performs a shallow scan of both project-local and global directories.

func (*Loader) SetProjectDir

func (l *Loader) SetProjectDir(dir string)

SetProjectDir sets an optional project-local directory for skills lookup Priority: Project Local > Global

type Manager

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

Manager handles the active persona state

func NewManager

func NewManager(logger *zap.Logger) *Manager

NewManager creates a new persona manager

func (*Manager) AttachAgent added in v1.49.0

func (m *Manager) AttachAgent(name string) (*LoadResult, error)

AttachAgent adds an agent to the active pool without removing others

func (*Manager) DetachAgent added in v1.49.0

func (m *Manager) DetachAgent(name string) error

DetachAgent removes a specific agent

func (*Manager) GetActiveAgent

func (m *Manager) GetActiveAgent() *Agent

GetActiveAgent returns the first active agent (legacy compatibility)

func (*Manager) GetActiveAgents added in v1.49.0

func (m *Manager) GetActiveAgents() []*Agent

GetActiveAgents returns list of active agents

func (*Manager) GetActivePrompt

func (m *Manager) GetActivePrompt() *ComposedPrompt

GetActivePrompt returns the composed prompt for the active agent

func (*Manager) GetAgentsDir

func (m *Manager) GetAgentsDir() string

GetAgentsDir returns the path to the agents directory

func (*Manager) GetLoader added in v1.62.0

func (m *Manager) GetLoader() *Loader

GetLoader returns the underlying loader for advanced callers (e.g., the worker system).

func (*Manager) GetSkill added in v1.62.0

func (m *Manager) GetSkill(name string) (*Skill, error)

GetSkill loads a skill by name, delegating to the loader.

func (*Manager) GetSkillsDir

func (m *Manager) GetSkillsDir() string

GetSkillsDir returns the path to the skills directory

func (*Manager) GetSystemPrompt

func (m *Manager) GetSystemPrompt() string

GetSystemPrompt returns the full system prompt string for the active agent

func (*Manager) HasActiveAgent

func (m *Manager) HasActiveAgent() bool

HasActiveAgent returns true if an agent is currently loaded

func (*Manager) Initialize

func (m *Manager) Initialize() error

Initialize sets up the persona system (creates directories if needed)

func (*Manager) ListAgents

func (m *Manager) ListAgents() ([]*Agent, error)

ListAgents returns all available agents

func (*Manager) ListSkills

func (m *Manager) ListSkills() ([]*Skill, error)

ListSkills returns all available skills

func (*Manager) LoadAgent

func (m *Manager) LoadAgent(name string) (*LoadResult, error)

LoadAgent (Legacy/Reset Mode): Clears all agents and loads specific one

func (*Manager) SetProjectDir

func (m *Manager) SetProjectDir(dir string)

SetProjectDir sets the project directory for local skills

func (*Manager) UnloadAgent

func (m *Manager) UnloadAgent()

UnloadAgent (legacy) - alias for backward compatibility

func (*Manager) UnloadAllAgents added in v1.49.0

func (m *Manager) UnloadAllAgents()

UnloadAllAgents (antigo UnloadAgent) clears everything

func (*Manager) ValidateAgent

func (m *Manager) ValidateAgent(name string) ([]string, []string, error)

ValidateAgent checks if an agent configuration is valid

type Skill

type Skill struct {
	// Metadata from frontmatter
	Name        string     `json:"name" yaml:"name"`
	Description string     `json:"description" yaml:"description"`
	Tools       StringList `json:"allowed-tools" yaml:"allowed-tools"` // Usando StringList

	// Content is the markdown body (without frontmatter)
	Content string `json:"-" yaml:"-"`

	// Path to the root directory of this skill
	Dir string `json:"-" yaml:"-"`

	// Path to the source file (legacy or main file)
	Path string `json:"-" yaml:"-"`

	// Subskills mapeia "nomearquivo.md" -> caminho absoluto
	Subskills map[string]string `json:"subskills" yaml:"-"`

	// Scripts mapeia "scripts/nomescript.py" -> caminho absoluto
	Scripts map[string]string `json:"scripts" yaml:"-"`
}

Skill represents a reusable knowledge/compliance module

type StringList

type StringList []string

StringList é um tipo auxiliar que permite que o usuário escreva no YAML tanto uma lista de strings quanto uma string única separada por vírgulas. Ex: skills: [a, b] OU skills: a, b, c

func (*StringList) UnmarshalYAML

func (sl *StringList) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implementa a interface yaml.Unmarshaler para flexibilidade

Jump to

Keyboard shortcuts

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