|
| 1 | +""" |
| 2 | +Command system for Aider. |
| 3 | +
|
| 4 | +This package contains individual command implementations that follow the |
| 5 | +BaseCommand pattern for modular, testable command execution. |
| 6 | +""" |
| 7 | + |
| 8 | +import sys |
| 9 | +import traceback |
| 10 | +from pathlib import Path |
| 11 | + |
| 12 | +from .add import AddCommand |
| 13 | +from .agent import AgentCommand |
| 14 | +from .architect import ArchitectCommand |
| 15 | +from .ask import AskCommand |
| 16 | +from .clear import ClearCommand |
| 17 | +from .code import CodeCommand |
| 18 | +from .command_prefix import CommandPrefixCommand |
| 19 | +from .commit import CommitCommand |
| 20 | +from .context import ContextCommand |
| 21 | +from .context_blocks import ContextBlocksCommand |
| 22 | +from .context_management import ContextManagementCommand |
| 23 | +from .copy import CopyCommand |
| 24 | +from .copy_context import CopyContextCommand |
| 25 | +from .diff import DiffCommand |
| 26 | + |
| 27 | +# Import and register commands |
| 28 | +from .drop import DropCommand |
| 29 | +from .editor import EditCommand, EditorCommand |
| 30 | +from .exit import ExitCommand |
| 31 | +from .git import GitCommand |
| 32 | +from .help import HelpCommand |
| 33 | +from .history_search import HistorySearchCommand |
| 34 | +from .lint import LintCommand |
| 35 | +from .list_sessions import ListSessionsCommand |
| 36 | +from .load import LoadCommand |
| 37 | +from .load_session import LoadSessionCommand |
| 38 | +from .load_skill import LoadSkillCommand |
| 39 | +from .ls import LsCommand |
| 40 | +from .map import MapCommand |
| 41 | +from .map_refresh import MapRefreshCommand |
| 42 | +from .model import ModelCommand |
| 43 | +from .models import ModelsCommand |
| 44 | +from .multiline_mode import MultilineModeCommand |
| 45 | +from .paste import PasteCommand |
| 46 | +from .quit import QuitCommand |
| 47 | +from .read_only import ReadOnlyCommand |
| 48 | +from .read_only_stub import ReadOnlyStubCommand |
| 49 | +from .reasoning_effort import ReasoningEffortCommand |
| 50 | +from .remove_skill import RemoveSkillCommand |
| 51 | +from .report import ReportCommand |
| 52 | +from .reset import ResetCommand |
| 53 | +from .run import RunCommand |
| 54 | +from .save import SaveCommand |
| 55 | +from .save_session import SaveSessionCommand |
| 56 | +from .settings import SettingsCommand |
| 57 | +from .test import TestCommand |
| 58 | +from .think_tokens import ThinkTokensCommand |
| 59 | +from .tokens import TokensCommand |
| 60 | +from .undo import UndoCommand |
| 61 | +from .utils.base_command import BaseCommand |
| 62 | +from .utils.helpers import ( |
| 63 | + CommandError, |
| 64 | + expand_subdir, |
| 65 | + format_command_result, |
| 66 | + get_available_files, |
| 67 | + glob_filtered_to_repo, |
| 68 | + parse_quoted_filenames, |
| 69 | + quote_filename, |
| 70 | + validate_file_access, |
| 71 | +) |
| 72 | +from .utils.registry import CommandRegistry |
| 73 | +from .voice import VoiceCommand |
| 74 | +from .web import WebCommand |
| 75 | + |
| 76 | +# Register commands |
| 77 | +CommandRegistry.register(DropCommand) |
| 78 | +CommandRegistry.register(ClearCommand) |
| 79 | +CommandRegistry.register(LsCommand) |
| 80 | +CommandRegistry.register(DiffCommand) |
| 81 | +CommandRegistry.register(ResetCommand) |
| 82 | +CommandRegistry.register(CopyCommand) |
| 83 | +CommandRegistry.register(PasteCommand) |
| 84 | +CommandRegistry.register(SettingsCommand) |
| 85 | +CommandRegistry.register(ReportCommand) |
| 86 | +CommandRegistry.register(TokensCommand) |
| 87 | +CommandRegistry.register(UndoCommand) |
| 88 | +CommandRegistry.register(GitCommand) |
| 89 | +CommandRegistry.register(RunCommand) |
| 90 | +CommandRegistry.register(HelpCommand) |
| 91 | +CommandRegistry.register(CommitCommand) |
| 92 | +CommandRegistry.register(ModelsCommand) |
| 93 | +CommandRegistry.register(ExitCommand) |
| 94 | +CommandRegistry.register(QuitCommand) |
| 95 | +CommandRegistry.register(VoiceCommand) |
| 96 | +CommandRegistry.register(MapCommand) |
| 97 | +CommandRegistry.register(MapRefreshCommand) |
| 98 | +CommandRegistry.register(MultilineModeCommand) |
| 99 | +CommandRegistry.register(EditorCommand) |
| 100 | +CommandRegistry.register(EditCommand) |
| 101 | +CommandRegistry.register(HistorySearchCommand) |
| 102 | +CommandRegistry.register(ThinkTokensCommand) |
| 103 | +CommandRegistry.register(LoadCommand) |
| 104 | +CommandRegistry.register(SaveCommand) |
| 105 | +CommandRegistry.register(ReasoningEffortCommand) |
| 106 | +CommandRegistry.register(SaveSessionCommand) |
| 107 | +CommandRegistry.register(ListSessionsCommand) |
| 108 | +CommandRegistry.register(LoadSessionCommand) |
| 109 | +CommandRegistry.register(ReadOnlyCommand) |
| 110 | +CommandRegistry.register(ReadOnlyStubCommand) |
| 111 | +CommandRegistry.register(AddCommand) |
| 112 | +CommandRegistry.register(ModelCommand) |
| 113 | +CommandRegistry.register(WebCommand) |
| 114 | +CommandRegistry.register(LintCommand) |
| 115 | +CommandRegistry.register(TestCommand) |
| 116 | +CommandRegistry.register(ContextManagementCommand) |
| 117 | +CommandRegistry.register(ContextBlocksCommand) |
| 118 | +CommandRegistry.register(AskCommand) |
| 119 | +CommandRegistry.register(CodeCommand) |
| 120 | +CommandRegistry.register(ArchitectCommand) |
| 121 | +CommandRegistry.register(ContextCommand) |
| 122 | +CommandRegistry.register(AgentCommand) |
| 123 | +CommandRegistry.register(CopyContextCommand) |
| 124 | +CommandRegistry.register(CommandPrefixCommand) |
| 125 | +CommandRegistry.register(LoadSkillCommand) |
| 126 | +CommandRegistry.register(RemoveSkillCommand) |
| 127 | + |
| 128 | +# Import SwitchCoder and Commands directly from commands.py |
| 129 | +# We need to handle the circular import carefully |
| 130 | + |
| 131 | +# Add parent directory to path to import commands.py directly |
| 132 | +parent_dir = str(Path(__file__).parent.parent) |
| 133 | +if parent_dir not in sys.path: |
| 134 | + sys.path.insert(0, parent_dir) |
| 135 | + |
| 136 | +# Import the commands module directly |
| 137 | +try: |
| 138 | + import importlib.util |
| 139 | + |
| 140 | + spec = importlib.util.spec_from_file_location( |
| 141 | + "aider.commands_module", Path(__file__).parent.parent / "commands.py" |
| 142 | + ) |
| 143 | + commands_module = importlib.util.module_from_spec(spec) |
| 144 | + sys.modules["aider.commands_module"] = commands_module |
| 145 | + spec.loader.exec_module(commands_module) |
| 146 | + |
| 147 | + # Get the classes from the module |
| 148 | + Commands = getattr(commands_module, "Commands", None) |
| 149 | + SwitchCoder = getattr(commands_module, "SwitchCoder", None) |
| 150 | + |
| 151 | + if Commands is None or SwitchCoder is None: |
| 152 | + raise ImportError("Commands or SwitchCoder not found in commands.py") |
| 153 | + |
| 154 | +except Exception as e: |
| 155 | + # Print the error for debugging |
| 156 | + print(f"Error importing commands.py: {e}") |
| 157 | + traceback.print_exc() |
| 158 | + |
| 159 | + # Fallback: define simple placeholder classes |
| 160 | + class SwitchCoder(Exception): |
| 161 | + def __init__(self, placeholder=None, **kwargs): |
| 162 | + self.kwargs = kwargs |
| 163 | + self.placeholder = placeholder |
| 164 | + |
| 165 | + class Commands: |
| 166 | + """Placeholder for Commands class defined in original commands.py""" |
| 167 | + |
| 168 | + def __init__(self, *args, **kwargs): |
| 169 | + # Accept any arguments but do nothing |
| 170 | + pass |
| 171 | + |
| 172 | + |
| 173 | +__all__ = [ |
| 174 | + "BaseCommand", |
| 175 | + "CommandRegistry", |
| 176 | + "CommandError", |
| 177 | + "quote_filename", |
| 178 | + "parse_quoted_filenames", |
| 179 | + "glob_filtered_to_repo", |
| 180 | + "validate_file_access", |
| 181 | + "format_command_result", |
| 182 | + "get_available_files", |
| 183 | + "expand_subdir", |
| 184 | + "DropCommand", |
| 185 | + "ClearCommand", |
| 186 | + "LsCommand", |
| 187 | + "DiffCommand", |
| 188 | + "ResetCommand", |
| 189 | + "CopyCommand", |
| 190 | + "PasteCommand", |
| 191 | + "SettingsCommand", |
| 192 | + "ReportCommand", |
| 193 | + "TokensCommand", |
| 194 | + "UndoCommand", |
| 195 | + "GitCommand", |
| 196 | + "RunCommand", |
| 197 | + "HelpCommand", |
| 198 | + "CommitCommand", |
| 199 | + "ModelsCommand", |
| 200 | + "ExitCommand", |
| 201 | + "QuitCommand", |
| 202 | + "VoiceCommand", |
| 203 | + "MapCommand", |
| 204 | + "MapRefreshCommand", |
| 205 | + "MultilineModeCommand", |
| 206 | + "EditorCommand", |
| 207 | + "EditCommand", |
| 208 | + "HistorySearchCommand", |
| 209 | + "ThinkTokensCommand", |
| 210 | + "LoadCommand", |
| 211 | + "SaveCommand", |
| 212 | + "ReasoningEffortCommand", |
| 213 | + "SaveSessionCommand", |
| 214 | + "ListSessionsCommand", |
| 215 | + "LoadSessionCommand", |
| 216 | + "ReadOnlyCommand", |
| 217 | + "ReadOnlyStubCommand", |
| 218 | + "AddCommand", |
| 219 | + "ModelCommand", |
| 220 | + "WebCommand", |
| 221 | + "LintCommand", |
| 222 | + "TestCommand", |
| 223 | + "ContextManagementCommand", |
| 224 | + "ContextBlocksCommand", |
| 225 | + "AskCommand", |
| 226 | + "CodeCommand", |
| 227 | + "ArchitectCommand", |
| 228 | + "ContextCommand", |
| 229 | + "AgentCommand", |
| 230 | + "CopyContextCommand", |
| 231 | + "CommandPrefixCommand", |
| 232 | + "LoadSkillCommand", |
| 233 | + "RemoveSkillCommand", |
| 234 | + "SwitchCoder", |
| 235 | + "Commands", |
| 236 | +] |
0 commit comments