commands

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: BSD-3-Clause Imports: 68 Imported by: 0

Documentation

Overview

Package commands provide CLI commands for mehr.

Example (GenerateSecretCommand)

Example_generateSecretCommand provides an example usage.

// This example shows how to use the generate-secret command programmatically
rootCmd := &cobra.Command{Use: "mehr"}
rootCmd.AddCommand(generateSecretCmd)

// In actual usage, you would execute:
// rootCmd.SetArgs([]string{"generate-secret"})
// rootCmd.Execute()
fmt.Println("mehr generate-secret")
Output:

mehr generate-secret

Index

Examples

Constants

View Source
const DefaultPreferredPort = 6337

DefaultPreferredPort is the default port for the web server. Falls back to a random port if this port is already in use.

Variables

View Source
var (

	// Build-time variables set via ldflags.
	Version   = "dev"
	Commit    = "none"
	BuildTime = "unknown"
)

Functions

func BuildConductorOptions

func BuildConductorOptions(cmdOpts CommandOptions) []conductor.Option

BuildConductorOptions creates conductor options from command options. This centralizes the common pattern of building options.

func CleanupBrowserMCP added in v0.7.0

func CleanupBrowserMCP()

CleanupBrowserMCP disconnects the cached MCP browser controller. Called once when the MCP server shuts down to release Chrome resources.

func DisplayPendingQuestion added in v0.3.0

func DisplayPendingQuestion(cond *conductor.Conductor) bool

DisplayPendingQuestion displays a pending question from the agent. Returns true if a question was displayed.

func Execute

func Execute() error

Execute runs the root command with signal handling and command disambiguation.

func FormatError added in v0.3.0

func FormatError(err error) string

FormatError formats an error for stderr output. Multi-line errors are passed through as-is. Single-line errors get an "Error:" prefix.

func GetParallelRegistry added in v0.6.0

func GetParallelRegistry() *taskrunner.Registry

GetParallelRegistry returns the shared registry for parallel task tracking. Creates the registry on first access.

func GetSettings

func GetSettings() *config.Settings

GetSettings returns the loaded settings.

func IsQuiet

func IsQuiet() bool

IsQuiet returns true if quiet mode is enabled.

func IsSandbox added in v0.5.0

func IsSandbox() bool

IsSandbox returns true if sandbox mode is enabled.

func PrintNextSteps

func PrintNextSteps(steps ...string)

PrintNextSteps prints common next steps after a command completes. Respects quiet mode - suppresses output if enabled.

func RequireActiveTask

func RequireActiveTask(cond *conductor.Conductor) bool

RequireActiveTask checks for an active task and prints an error if none exists. Returns true if an active task exists, false otherwise.

func RunWithSpinner added in v0.3.0

func RunWithSpinner(verbose bool, spinnerMsg string, fn func() error) error

RunWithSpinner runs a function with either verbose output or a spinner. This consolidates the spinner/verbose pattern used across commands. If verbose is true, runs the function directly and returns its error. If verbose is false, shows a spinner with the given message during execution.

func SetBrowserMCPMode added in v0.7.0

func SetBrowserMCPMode(enabled bool)

SetBrowserMCPMode enables MCP mode for browser commands. In MCP mode, a single browser controller is cached and reused across sequential MCP tool calls. This prevents WebSocket and goroutine leaks. Headless mode is also enabled since AI agents don't need a visible browser.

func SetConductorFactory added in v0.10.0

func SetConductorFactory(f ConductorFactory) func()

SetConductorFactory allows tests to inject a mock factory. Returns a restore function that should be deferred.

Example usage in tests:

restore := SetConductorFactory(func(ctx context.Context, opts ...conductor.Option) (ConductorAPI, error) {
    return mockConductor, nil
})
defer restore()

func SetParallelRegistry added in v0.6.0

func SetParallelRegistry(r *taskrunner.Registry)

SetParallelRegistry sets the shared registry (used by parallel start).

func SetupVerboseEventHandlers

func SetupVerboseEventHandlers(cond *conductor.Conductor)

SetupVerboseEventHandlers subscribes to common events for verbose output. This centralizes the verbose event subscription pattern. Quiet mode suppresses progress and file change events but keeps errors.

Types

type CommandOptions

type CommandOptions struct {
	Verbose         bool
	Quiet           bool
	DryRun          bool
	StepAgent       string // Per-step agent override (e.g., "planning", "implementing")
	FullContext     bool
	OptimizePrompts bool // Optimize prompts before sending to agents
	Sandbox         bool // Enable sandboxing for agent execution
	LibraryInclude  bool // Auto-include library documentation
}

CommandOptions holds common options for command execution.

type ConductorAPI added in v0.10.0

type ConductorAPI interface {
	// Lifecycle
	Initialize(ctx context.Context) error
	Close() error

	// Workflow operations
	Start(ctx context.Context, reference string) error
	Plan(ctx context.Context) error
	Implement(ctx context.Context) error
	RunImplementation(ctx context.Context) error
	Review(ctx context.Context) error
	ImplementReview(ctx context.Context, reviewNumber int) error
	RunReviewImplementation(ctx context.Context, reviewNumber int) error
	Finish(ctx context.Context, opts conductor.FinishOptions) error
	Status(ctx context.Context) (*conductor.TaskStatus, error)
	AnswerQuestion(ctx context.Context, answer string) error
	ResetState(ctx context.Context) error
	Delete(ctx context.Context, opts conductor.DeleteOptions) error

	// Note management
	AddNote(ctx context.Context, message string) error

	// Quality operations
	RunQuality(ctx context.Context, opts conductor.QualityOptions) (*conductor.QualityResult, error)
	GenerateCommitMessagePreview(ctx context.Context) (string, error)

	// Specification operations
	GetSpecificationFileDiff(ctx context.Context, taskID string, specNumber int, filePath string, contextLines int) (string, error)

	// State access
	GetActiveTask() *storage.ActiveTask
	GetTaskWork() *storage.TaskWork
	GetWorkspace() *storage.Workspace
	GetGit() *vcs.Git
	GetMachine() *workflow.Machine
	GetActiveAgent() agent.Agent

	// I/O
	GetStdout() io.Writer
	GetStderr() io.Writer
	GetEventBus() *eventbus.Bus

	// Registries
	GetAgentRegistry() *agent.Registry
	GetProviderRegistry() *provider.Registry

	// Configuration
	SetAgent(agent string)
	ClearAgent()
	SetImplementationOptions(component, parallel string)
	ClearImplementationOptions()

	// Directories
	CodeDir() string
	TasksDir() string
	GetTaskID() string
	GetWorktreePath() string

	// Utilities
	ClearStaleTask() bool
}

ConductorAPI defines the conductor methods used by commands. This interface enables mocking for unit tests while keeping production code unchanged. The real *conductor.Conductor satisfies this interface.

func CreateConductor added in v0.10.0

func CreateConductor(ctx context.Context, opts ...conductor.Option) (ConductorAPI, error)

CreateConductor creates a conductor using the current factory. Commands should use this instead of initializeConductor directly.

type ConductorFactory added in v0.10.0

type ConductorFactory func(ctx context.Context, opts ...conductor.Option) (ConductorAPI, error)

ConductorFactory creates a conductor. Tests can override the default.

type GitCommitAPI added in v0.10.0

type GitCommitAPI interface {
	Add(ctx context.Context, files ...string) error
	Commit(ctx context.Context, message string) (string, error)
	CurrentBranch(ctx context.Context) (string, error)
	Push(ctx context.Context, remote, branch string) error
}

GitCommitAPI defines the git operations used by the commit command. This interface enables mocking for unit tests.

type InteractiveSession added in v0.6.0

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

InteractiveSession manages an interactive REPL session.

func (*InteractiveSession) Initialize added in v0.6.0

func (s *InteractiveSession) Initialize(ctx context.Context) error

Initialize sets up the interactive session.

func (*InteractiveSession) Run added in v0.6.0

Run starts the REPL loop.

type WorkspaceResolution

type WorkspaceResolution struct {
	Root       string   // Workspace root directory (main repo path if in worktree)
	Git        *vcs.Git // Git instance (nil if not in a git repository)
	IsWorktree bool     // True if currently in a git worktree
}

WorkspaceResolution holds the result of resolving the workspace root and git context.

func ResolveWorkspaceRoot

func ResolveWorkspaceRoot(ctx context.Context) (WorkspaceResolution, error)

ResolveWorkspaceRoot resolves the workspace root directory and git context. This function centralizes the common pattern of finding the workspace root while handling git worktrees correctly.

If in a git worktree, it returns the main repository path as the root. If not in git, it returns the current working directory. The git instance is only non-nil if successfully created.

Jump to

Keyboard shortcuts

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