REPL & Slash Commands
Relevant source files
The following files were used as context for generating this wiki page:
The REPL (Read-Eval-Print Loop) is the primary interactive interface for M31 Autonomous, providing a terminal-native environment where users can issue natural language instructions or structured slash commands. It serves as the entry point for the seven-phase workflow, allowing users to initialize projects, discuss requirements, and oversee the execution of AI-generated implementation plans.
The system supports over 16 registered slash commands that provide fine-grained control over session state, model selection, and workflow transitions. This architecture enables M31A to function both as an autonomous agent and as a manual tool for codebase exploration and management.
Sources: README.md:12-25, README.md:325-341, scripts/verify_v1.sh:147-148
Architecture and Command Processing
The command system is built on top of the Bubble Tea TUI framework. It utilizes a centralized command registry and a CommandContext to handle interactions between the user interface and the underlying workflow engine.
Command Execution Flow
When a user enters a command starting with /, the TUI identifies it as a slash command and routes it to the appropriate handler. These handlers return a CommandResult containing instructions for the UI, such as navigating to a new screen, displaying a toast message, or triggering a workflow resume.
The diagram shows the logic flow from user input to the execution of specific UI or engine actions.
Sources: internal/ui/tui/commands/commands_core.go:17-45, CONTRIBUTING.md:46-51
Core Components
| Component | Description |
|---|---|
CommandContext | A struct containing references to the SessionManager, Config, WorkflowEngine, and UI state required by handlers. |
CommandResult | The output of a handler, specifying success status, return messages, screen transitions, and confirmation requirements. |
DefaultDispatcher | The central registry where all 18+ tools and slash commands are registered for use within the application. |
Sources: internal/ui/tui/commands/commands_core.go:17-25, scripts/validate-release.sh:169-183
Slash Command Reference
M31A provides a variety of commands for session management, system diagnostics, and workflow control.
Session and State Management
These commands allow users to manage the lifecycle of their coding sessions and the persistent state of the application.
/clear: Clears the current conversation history. Requires user confirmation./reset: Factory resets M31A by deleting configuration files, API keys from the OS keychain, session data, and the ledger./undo: Restores the workflow to the latest saved checkpoint, allowing users to roll back to a previous phase or state./status: Displays information about the active session, including the current provider, model, workflow phase, and message count.
Sources: internal/ui/tui/commands/commands_core.go:27-118
Workflow and Quick Actions
Commands that modify how the AI agent operates during a task.
| Command | Argument | Description |
|---|---|---|
/quick | on / off | Toggles Quick Mode. When enabled, simple tasks skip the Discuss phase. |
/skip | <phase> | Manually advances the workflow to a specific phase (e.g., plan, execute, ship). |
/chat | N/A | Resets the REPL to a plain chat session, cancelling any active autonomous agents. |
/flush | N/A | Resets the viewport scroll position to provide a clean visual state. |
Sources: internal/ui/tui/commands/commands_core.go:297-362
System Diagnostics and Help
Tools for inspecting the M31A environment and accessing documentation.
This sequence illustrates how the /tools command retrieves and displays the available system tools.
Sources: internal/ui/tui/commands/commands_core.go:175-195
/help: Navigates to the Help screen containing a full keybinding and command reference./health: Triggers a health check for the currently active LLM provider (OpenRouter, Zen, or Nvidia)./tools: Lists all 18 built-in tools (e.g.,Bash,FileRead,Edit) currently registered in the dispatcher./search <query>: Performs a case-insensitive search across the current session's message segments.
Sources: internal/ui/tui/commands/commands_core.go:15-20, internal/ui/tui/commands/commands_core.go:160-218, internal/ui/tui/commands/commands_core.go:248-278
Technical Implementation Details
The command handlers are implemented in Go and interact heavily with the internal/core/types and internal/engine/workflow packages.
Checkpoint and Undo Logic
The /undo command leverages the SessionManager to retrieve CheckpointData. This data is then loaded into the WorkflowEngine to synchronize the state between the persistent storage and the active TUI session.
// internal/ui/tui/commands/commands_core.go:94-118
func handleUndo(_ []string, ctx CommandContext) CommandResult {
checkpoint, err := ctx.SessionManager.LatestCheckpoint(ctx.SessionID)
// ... validation ...
if ctx.WorkflowEngine != nil {
cpData := &workflow.CheckpointData{
Phase: latest.Phase,
Goal: latest.Goal,
PlanVersion: latest.PlanVersion,
Timestamp: latest.Timestamp,
}
ctx.WorkflowEngine.LoadCheckpointData(cpData)
}
// ... returns result to trigger workflow resume ...
}
Sources: internal/ui/tui/commands/commands_core.go:94-118
Security and Confirmation
Destructive commands like /reset and /clear use the ConfirmRequired field in CommandResult. This triggers a modal in the Bubble Tea TUI, preventing accidental data loss by requiring an explicit 'y' or 'n' input from the user before the Cmd callback is executed.
Sources: internal/ui/tui/commands/commands_core.go:29-33, internal/ui/tui/commands/commands_core.go:61-64, README.md:275-279
Summary
The REPL and Slash Command system provides the core interactive layer of M31 Autonomous. By combining natural language processing with a robust set of structured commands, it allows developers to maintain full control over the AI agent's workflow. The system is designed for safety, utilizing confirmation prompts for destructive actions, and for extensibility, with a centralized dispatcher that manages both TUI-level commands and the underlying tools used by the AI during execution.