commands

package
v0.0.0-...-c11c1a8 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package commands provides a modular command registry for the iterate REPL. Each command group (session, git, safety, etc.) is in its own file.

Index

Constants

This section is empty.

Variables

View Source
var BinaryExtensions = map[string]bool{
	".png": true, ".jpg": true, ".jpeg": true, ".gif": true, ".ico": true,
	".svg": true, ".wasm": true, ".bin": true, ".exe": true, ".pdf": true,
	".zip": true, ".tar": true, ".gz": true, ".so": true, ".a": true,
	".dylib": true, ".dll": true, ".webp": true, ".mp4": true, ".mp3": true,
}
View Source
var ErrUserQuit = errors.New("user quit")

ErrUserQuit is returned when the user chooses to quit during an interactive diff review session. Callers should handle this gracefully instead of calling os.Exit directly from library code.

View Source
var Stdout io.Writer = os.Stdout

Stdout is the default writer for commands.

Functions

func BuildProjectTree

func BuildProjectTree(repoPath string, maxDepth int) string

func EvolutionHandler

func EvolutionHandler(fn func(Context, EvolutionContext) Result, evoCtx EvolutionContext) func(Context) Result

EvolutionHandler wraps a function that needs evolution context.

func ExtractFirstMeaningfulLine

func ExtractFirstMeaningfulLine(content string) string

func FetchGoPkgDoc

func FetchGoPkgDoc(pkg string) (string, error)

func FormatProjectIndex

func FormatProjectIndex(entries []IndexEntry) string

func FormatTreeFromPaths

func FormatTreeFromPaths(paths []string, maxDepth int) string

func GenerateIterateMD

func GenerateIterateMD(repoPath string) string

func GetPendingImageAttachment

func GetPendingImageAttachment() string

GetPendingImageAttachment returns and clears any pending image attachment. Called by streamAndPrint before sending each request.

func GetPendingTemplate

func GetPendingTemplate() string

GetPendingTemplate returns and clears any pending template injection.

func LastRunOutput

func LastRunOutput() string

LastRunOutput returns the captured output of the most recent /run call.

func PreviewEdit

func PreviewEdit(filename string, oldContent string, newContent string) error

PreviewEdit shows a preview of an edit before applying. Returns ErrUserQuit if the user chooses to quit.

func RegisterASTCommands

func RegisterASTCommands(r *Registry)

RegisterASTCommands adds AST analysis commands

func RegisterAgentCommands

func RegisterAgentCommands(r *Registry)

RegisterAgentCommands adds agent control commands.

func RegisterAll

func RegisterAll(r *Registry)

RegisterAll adds all command groups to the registry. This is the single entry point for wiring up all modular commands.

func RegisterAnalysisCommands

func RegisterAnalysisCommands(r *Registry)

RegisterAnalysisCommands adds repository analysis and benchmarking commands.

func RegisterAutofixCommands

func RegisterAutofixCommands(r *Registry)

RegisterAutofixCommands adds the /autofix command.

func RegisterBudgetCommands

func RegisterBudgetCommands(r *Registry)

RegisterBudgetCommands adds the /budget spending-limit command.

func RegisterConfigCommands

func RegisterConfigCommands(r *Registry)

RegisterConfigCommands adds configuration and settings commands.

func RegisterContextTemplateCommands

func RegisterContextTemplateCommands(r *Registry)

RegisterContextTemplateCommands adds context analytics.

func RegisterDevCommands

func RegisterDevCommands(r *Registry)

RegisterDevCommands adds development commands.

func RegisterDocsCommands

func RegisterDocsCommands(r *Registry)

RegisterDocsCommands adds dependency summary command.

func RegisterEvolutionCommands

func RegisterEvolutionCommands(r *Registry)

RegisterEvolutionCommands adds evolution-related commands.

func RegisterFileCommands

func RegisterFileCommands(r *Registry)

RegisterFileCommands adds file and search commands.

func RegisterGitCommands

func RegisterGitCommands(r *Registry)

RegisterGitCommands adds git commands.

func RegisterGitContextCommands

func RegisterGitContextCommands(r *Registry)

RegisterGitContextCommands adds git-aware context commands.

func RegisterGitHooksCommands

func RegisterGitHooksCommands(r *Registry)

RegisterGitHooksCommands adds git hooks integration commands. Task 70: Git Hooks Integration (pre-commit, post-commit)

func RegisterGitHubCommands

func RegisterGitHubCommands(r *Registry)

RegisterGitHubCommands adds GitHub-related commands.

func RegisterLearningCommands

func RegisterLearningCommands(r *Registry)

RegisterLearningCommands adds pattern recognition and learning curation.

func RegisterMemoryAnalyticsCommands

func RegisterMemoryAnalyticsCommands(r *Registry)

RegisterMemoryAnalyticsCommands adds memory search command.

func RegisterMemoryCommands

func RegisterMemoryCommands(r *Registry)

RegisterMemoryCommands adds memory/note-taking commands.

func RegisterModeCommands

func RegisterModeCommands(r *Registry)

RegisterModeCommands adds agent mode and display commands.

func RegisterProfileCommands

func RegisterProfileCommands(r *Registry)

RegisterProfileCommands adds /profile commands.

func RegisterSafetyCommands

func RegisterSafetyCommands(r *Registry)

RegisterSafetyCommands adds safety/config commands.

func RegisterSessionCommands

func RegisterSessionCommands(r *Registry)

RegisterSessionCommands adds session management commands.

func RegisterSnippetCommands

func RegisterSnippetCommands(r *Registry)

RegisterSnippetCommands adds code snippet commands

func RegisterTemplateCommands

func RegisterTemplateCommands(r *Registry)

RegisterTemplateCommands adds /template and /t commands.

func RegisterUtilityCommands

func RegisterUtilityCommands(r *Registry)

RegisterUtilityCommands adds utility/context management commands.

func StripHTMLTags

func StripHTMLTags(s string) string

Types

type AgentRuntime

type AgentRuntime struct {
	Agent    *iteragent.Agent
	Provider iteragent.Provider
	Thinking *iteragent.ThinkingLevel
	Context  context.Context
	Pool     *agent.Pool
}

AgentRuntime groups agent, provider, and pool fields.

type Bookmark

type Bookmark struct {
	Name      string
	CreatedAt time.Time
	Messages  []iteragent.Message
}

Bookmark represents a saved conversation state.

type Command

type Command struct {
	Name        string   // primary name (e.g., "/save")
	Aliases     []string // aliases (e.g., "/exit", "/q" for "/quit")
	Description string   // short help text
	Category    string   // grouping for help display
	Handler     func(Context) Result
}

Command represents a single REPL command.

type CommandInput

type CommandInput struct {
	Line  string
	Parts []string
}

CommandInput holds the parsed command line.

type ConfigCallbacks

type ConfigCallbacks struct {
	LoadConfig     func() interface{}
	SaveConfig     func(cfg interface{})
	ConfigPath     func() string
	HistoryFile    *string
	LoadAliases    func() map[string]string
	SaveAliases    func(m map[string]string)
	LoadMCPServers func() []MCPServerEntry
	SaveMCPServers func(servers []MCPServerEntry)
}

ConfigCallbacks groups configuration and alias callbacks.

type Context

type Context struct {
	RepoPath string
	Input    CommandInput
	Version  string
	Writer   io.Writer

	// Registry is the command registry — used by /help to generate dynamic output.
	Registry *Registry

	InputHistory  *[]string
	LastPrompt    *string
	RuntimeConfig *RuntimeConfig
	ApplyTheme    func(name string)

	// Sub-struct groups
	Runtime AgentRuntime
	Tokens  TokenUsage
	Safety  SafetyState
	Watch   WatchCallbacks

	// Grouped callbacks
	Session   SessionCallbacks
	Config    ConfigCallbacks
	REPL      REPLCallbacks
	State     StateAccessors
	Templates TemplateCallbacks
	Snapshots SnapshotCallbacks
}

Context holds all state needed by commands.

func (Context) Arg

func (ctx Context) Arg(n int) string

Arg returns the nth argument (1-indexed, after command name).

func (Context) Args

func (ctx Context) Args() string

Args returns all arguments after the command name.

func (Context) HasArg

func (ctx Context) HasArg(n int) bool

HasArg returns true if there are at least n arguments after command.

func (Context) Write

func (ctx Context) Write(format string, args ...any)

Write formats to the context writer (or stdout).

func (Context) WriteLn

func (ctx Context) WriteLn(format string, args ...any)

WriteLn writes a line to the context writer.

type DiffViewer

type DiffViewer struct {
	ColorAdded   *color.Color
	ColorRemoved *color.Color
	ColorContext *color.Color
	ColorHeader  *color.Color
}

DiffViewer shows unified diffs before applying changes

func NewDiffViewer

func NewDiffViewer() *DiffViewer

NewDiffViewer creates a new diff viewer with colors

func (*DiffViewer) BatchDiff

func (dv *DiffViewer) BatchDiff(files []string) (approved []string, rejected []string, err error)

BatchDiff shows diffs for multiple files. Returns ErrUserQuit if the user chooses to quit mid-review.

func (*DiffViewer) ConfirmChange

func (dv *DiffViewer) ConfirmChange(filename string) (bool, error)

ConfirmChange prompts user to confirm a change. Returns (apply bool, err error). err is ErrUserQuit when user chooses to quit.

func (*DiffViewer) ShowDiff

func (dv *DiffViewer) ShowDiff(filename string, original []string, proposed []string)

ShowDiff displays a unified diff between original and proposed content

func (*DiffViewer) ShowGitDiff

func (dv *DiffViewer) ShowGitDiff(filename string) error

ShowGitDiff shows git-style diff for file changes

type EvolutionContext

type EvolutionContext struct {
	Logger         *slog.Logger
	StreamAndPrint func(ctx context.Context, a *iteragent.Agent, prompt, repoPath string)
	EventSink      chan iteragent.Event
}

EvolutionContext provides additional context for evolution commands.

type IndexEntry

type IndexEntry struct {
	Path    string
	Lines   int
	Summary string
}

func BuildProjectIndex

func BuildProjectIndex(repoPath string) []IndexEntry

type MCPServerEntry

type MCPServerEntry struct {
	Name    string
	URL     string
	Command string
	Args    []string
}

MCPServerEntry represents an MCP server configuration.

type Profile

type Profile struct {
	Name         string    `json:"name"`
	Model        string    `json:"model,omitempty"`
	Temperature  float32   `json:"temperature,omitempty"`
	MaxTokens    int       `json:"max_tokens,omitempty"`
	SystemSuffix string    `json:"system_suffix,omitempty"`
	CreatedAt    time.Time `json:"created_at"`
}

Profile captures a named agent configuration snapshot.

type PromptTemplate

type PromptTemplate struct {
	Name    string
	Prompt  string
	Created time.Time
}

PromptTemplate represents a saved prompt template.

type REPLCallbacks

type REPLCallbacks struct {
	StreamAndPrint func(ctx context.Context, a *iteragent.Agent, prompt, repoPath string)
	RunShell       func(repoPath string, name string, args ...string)
	MakeAgent      func() *iteragent.Agent
	ReadMultiLine  func() (string, bool)
	PromptLine     func(prompt string) (string, bool)
	// Undo reverts the last agent file modifications.
	// Returns the list of restored paths and an error (if any).
	Undo func() ([]string, error)
	// BuildRepoMap returns a structural summary of the repository.
	// refresh=true forces a rebuild; false may return a cached result.
	BuildRepoMap func(repoPath string, refresh bool) string
	// InvalidateRepoMap clears the repo map cache.
	InvalidateRepoMap func()
}

REPLCallbacks groups REPL interaction callbacks.

type Registry

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

Registry holds all registered commands.

func DefaultRegistry

func DefaultRegistry() *Registry

DefaultRegistry returns a fully populated registry.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty command registry.

func (*Registry) All

func (r *Registry) All() []*Command

All returns all unique commands (by primary name only).

func (*Registry) ByCategory

func (r *Registry) ByCategory() map[string][]*Command

ByCategory returns commands grouped by category.

func (*Registry) Execute

func (r *Registry) Execute(name string, ctx Context) Result

Execute runs a command by name with the given context.

func (*Registry) Lookup

func (r *Registry) Lookup(name string) (*Command, bool)

Lookup finds a command by name or alias.

func (*Registry) Register

func (r *Registry) Register(cmd Command)

Register adds a command to the registry.

type Result

type Result struct {
	Done    bool  // true = exit REPL
	Handled bool  // true = command was recognized
	Err     error // non-nil = error occurred
}

Result represents the outcome of a command execution.

type RuntimeConfig

type RuntimeConfig struct {
	Temperature  *float32
	MaxTokens    *int
	CacheEnabled *bool
}

RuntimeConfig holds runtime settings for the agent.

type SafetyState

type SafetyState struct {
	SafeMode          *bool
	CurrentMode       *int
	DebugMode         *bool
	AutoCommitEnabled *bool
	NotifyEnabled     *bool
	PersistConfig     func()
}

SafetyState groups safety, mode, and notification toggles.

type SessionCallbacks

type SessionCallbacks struct {
	SaveSession   func(name string, msgs []iteragent.Message) error
	LoadSession   func(name string) ([]iteragent.Message, error)
	ListSessions  func() []string
	AddBookmark   func(name string, msgs []iteragent.Message)
	LoadBookmarks func() []Bookmark
	SelectItem    func(title string, items []string) (string, bool)
}

SessionCallbacks groups session management callbacks.

type Snapshot

type Snapshot struct {
	Name      string
	CreatedAt time.Time
	Messages  []iteragent.Message
}

Snapshot represents a saved conversation snapshot.

type SnapshotCallbacks

type SnapshotCallbacks struct {
	SaveSnapshot  func(name string, msgs []iteragent.Message) error
	ListSnapshots func() []Snapshot
}

SnapshotCallbacks groups snapshot management callbacks.

type StateAccessors

type StateAccessors struct {
	IsDenied             func(name string) bool
	DenyTool             func(name string)
	AllowTool            func(name string)
	GetDeniedList        func() []string
	GetPinnedMessages    func() []iteragent.Message
	SetPinnedMessages    func(msgs []iteragent.Message)
	GetConversationMark  func(name string) (int, bool)
	SetConversationMark  func(name string, idx int)
	GetConversationMarks func() map[string]int
	ConversationMarksLen func() int
}

StateAccessors groups thread-safe state access callbacks.

type TemplateCallbacks

type TemplateCallbacks struct {
	LoadTemplates        func() []PromptTemplate
	AddTemplate          func(name, prompt string)
	FormatSessionChanges func() string
}

TemplateCallbacks groups template management callbacks.

type TokenUsage

type TokenUsage struct {
	InputTokens   *int
	OutputTokens  *int
	CacheRead     *int
	CacheWrite    *int
	ContextWindow *int
	BudgetLimit   *float64
	CostUSD       *float64
}

TokenUsage groups session token and budget tracking fields.

type TreeNode

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

type WatchCallbacks

type WatchCallbacks struct {
	Start func(repoPath string)
	Stop  func()
}

WatchCallbacks groups file-watch start/stop callbacks.

Jump to

Keyboard shortcuts

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