commands

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Name     string   // e.g., "fix-ci", "retry", "review", "fix"
	Args     []string // positional arguments (e.g., issue number for retry)
	Prompt   string   // quoted prompt string, empty if not provided
	ParseErr error    // non-nil if the command line could not be parsed
}

Command represents a parsed /herd command.

func Parse

func Parse(body string) *Command

Parse extracts a /herd command from a comment body. Returns nil if no command is found. Format: /herd <command> [positional-args...] ["optional prompt"]

Examples:

/herd fix-ci
/herd fix-ci "the Node version file is missing"
/herd retry 42
/herd review "focus on error handling"
/herd fix "add missing error check in auth.go"

type HandlerContext

type HandlerContext struct {
	Ctx      context.Context
	Platform platform.Platform
	Agent    agent.Agent // may be nil for commands that don't need an agent
	Git      *git.Git    // may be nil for commands that don't need git
	Config   *config.Config
	RepoRoot string

	// Comment context — set by the CLI from workflow event payload
	IssueNumber int    // the issue/PR number where the comment was posted
	CommentID   int64  // for reactions
	IssueBody   string // full issue/PR body for future multi-turn commands
	AuthorLogin string // who posted the command
	IsPR        bool   // true when the comment was posted on a pull request
}

HandlerContext provides everything a command handler needs to execute. Designed for reuse: Phase 1 (slash commands) and Phase 2 (agent tool calls) both construct this struct and call the same handler functions.

type HandlerFunc

type HandlerFunc func(ctx *HandlerContext, cmd Command) Result

HandlerFunc is the signature for command handler functions.

type Registry

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

Registry maps command names to handler functions.

func DefaultRegistry

func DefaultRegistry() *Registry

DefaultRegistry returns a registry with all built-in commands registered.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty command registry.

func (*Registry) Handle

func (r *Registry) Handle(ctx *HandlerContext, cmd Command) Result

Handle dispatches a parsed command to its registered handler. Returns an error result if the command has a parse error or is unknown.

func (*Registry) Has

func (r *Registry) Has(name string) bool

Has returns true if the named command is registered.

func (*Registry) Register

func (r *Registry) Register(name string, handler HandlerFunc)

Register adds a command handler. Panics if the name is already registered (programming error, caught at startup).

type Result

type Result struct {
	Message string // human-readable summary to post as a reply comment
	Error   error  // non-nil if the command failed
}

Result holds the outcome of a command execution.

Jump to

Keyboard shortcuts

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