commands

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	SourceProject = "project"
	SourceUser    = "user"
	SourceSkill   = "skill"
	SourceBuiltin = "builtin"
)

Sources of a command, by precedence (project wins).

View Source
const (
	FileExt = ".md"
	Folder  = "commands"
)

FileExt is the extension of a command file; Folder is the folder name inside a configuration directory.

View Source
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.

View Source
const InitPrompt = `` /* 726-byte string literal not displayed */

InitPrompt is the prompt of the builtin /init command.

Variables

View Source
var ErrNotFound = errors.New("unknown command")

ErrNotFound is returned by Expand for an unknown command.

Functions

func Expand

func Expand(template, args string) string

Expand substitutes the placeholders of a template in one pass, so a placeholder inside an argument is not expanded again.

func Fields

func Fields(s string) []string

Fields splits arguments on white space; single or double quotes group words (the quotes are dropped).

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

func Load(o Options) *Set

Load reads the commands of every source. Lower precedence sources are added first and replaced by higher ones of the same name.

func (*Set) Expand

func (s *Set) Expand(name, args string) (string, error)

Expand returns the prompt of "/name args": the template with $ARGUMENTS and $1 to $9 replaced (a placeholder without argument becomes ""). A template without any placeholder gets the arguments appended after a blank line.

func (*Set) List

func (s *Set) List() []Command

List returns the commands sorted by name.

type Skill

type Skill struct{ Name, Description string }

Skill is an installed skill offered as a command.

Jump to

Keyboard shortcuts

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