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 ¶
- Constants
- Variables
- func BuildConductorOptions(cmdOpts CommandOptions) []conductor.Option
- func CleanupBrowserMCP()
- func DisplayPendingQuestion(cond *conductor.Conductor) bool
- func Execute() error
- func FormatError(err error) string
- func GetParallelRegistry() *taskrunner.Registry
- func GetSettings() *config.Settings
- func IsQuiet() bool
- func IsSandbox() bool
- func PrintNextSteps(steps ...string)
- func RequireActiveTask(cond *conductor.Conductor) bool
- func RunWithSpinner(verbose bool, spinnerMsg string, fn func() error) error
- func SetBrowserMCPMode(enabled bool)
- func SetConductorFactory(f ConductorFactory) func()
- func SetParallelRegistry(r *taskrunner.Registry)
- func SetupVerboseEventHandlers(cond *conductor.Conductor)
- type CommandOptions
- type ConductorAPI
- type ConductorFactory
- type GitCommitAPI
- type InteractiveSession
- type WorkspaceResolution
Examples ¶
Constants ¶
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 ¶
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
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
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 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 ¶
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
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 ¶
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
CreateConductor creates a conductor using the current factory. Commands should use this instead of initializeConductor directly.
type ConductorFactory ¶ added in v0.10.0
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.
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.
Source Files
¶
- abandon.go
- agents.go
- auto.go
- browser.go
- browser_devtools.go
- browser_interaction.go
- browser_monitoring.go
- budget.go
- commit.go
- common.go
- conductor_api.go
- config.go
- continue.go
- cost.go
- delete.go
- export.go
- find.go
- finish.go
- generate_secret.go
- guide.go
- implement.go
- init.go
- interactive.go
- interactive_events.go
- interactive_features.go
- label.go
- library.go
- license.go
- links.go
- list.go
- mcp.go
- memory.go
- note.go
- optimize.go
- parallel.go
- plan.go
- plugins.go
- project.go
- provider_login.go
- providers.go
- question.go
- quick.go
- redo.go
- reset.go
- review.go
- review_pr.go
- root.go
- scan.go
- serve.go
- simplify.go
- specification.go
- stack.go
- start.go
- status.go
- submit.go
- sync.go
- templates.go
- undo.go
- update.go
- update_check.go
- workflow.go