Documentation
¶
Overview ¶
Package commands loads custom commands: markdown prompt templates a user invokes by name ("/review src/main.go").
A command is a file <dir>/<name>.md with optional YAML frontmatter
--- description: Review a file argument-hint: <file> --- Review $1 for bugs. Extra instructions: $ARGUMENTS
in <project>/.har/commands and <user dir>/commands (a file in a subfolder is named folder:name). The body is the prompt: $ARGUMENTS is the whole argument text and $1 to $9 the arguments split on spaces (double or single quotes group words). Installed skills and the builtin commands are listed too.
A command is only text. Expanding it never runs a command, reads a file or follows a link; what the model then does with the prompt goes through the usual tools and approvals. A project command comes from the repository the agent works on, so it is labelled SourceProject, and it can replace a user, skill or builtin command of the same name only in the list the user sees (precedence: project, user, skill, builtin).
Index ¶
Constants ¶
const ( SourceProject = "project" SourceUser = "user" SourceSkill = "skill" SourceBuiltin = "builtin" )
Sources of a command, by precedence (project wins).
const ( FileExt = ".md" Folder = "commands" )
FileExt is the extension of a command file; Folder is the folder name inside a configuration directory.
const ( // MaxFileBytes is the largest command file read; a larger one is skipped with a warning. MaxFileBytes = 64 << 10 // MaxNameLen bounds a command name. MaxNameLen = 80 )
Limits of a command file.
const InitPrompt = `` /* 726-byte string literal not displayed */
InitPrompt is the prompt of the builtin /init command.
Variables ¶
var ErrNotFound = errors.New("unknown command")
ErrNotFound is returned by Expand for an unknown command.
Functions ¶
Types ¶
type Command ¶
type Command struct {
// Name is what follows the slash; a file in a subfolder is "folder:name".
Name string
Description string
// Source is SourceProject, SourceUser, SourceSkill or SourceBuiltin.
Source string
// ArgHint is shown after the name, e.g. "<file>".
ArgHint string
// Template is the prompt with its placeholders.
Template string
}
Command is a loaded command.
type Options ¶
type Options struct {
// ProjectDir is <project>/.har/commands.
ProjectDir string
// UserDir is <user dir>/commands.
UserDir string
// Skills are the installed skills, listed as commands that ask the agent to use the skill.
Skills []Skill
// Warn receives a problem with a file (nil: slog.Warn); the file is ignored.
Warn func(msg string)
}
Options says where commands come from. An empty directory is not read.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is the loaded commands.
func Load ¶
Load reads the commands of every source. Lower precedence sources are added first and replaced by higher ones of the same name.