How tsuno08/aimai works
Project Type and Purpose
• This is a command‑line interface (CLI) tool (“Aimai CLI”) that converts Japanese natural‑language instructions into shell commands.
• It follows an MVC‑style decomposition (src/model.py, src/view.py, src/controller.py) with a thin CLI entrypoint (src/cli.py) and a launcher script (bin/aimai).
Key Components
a. CLI Entrypoint (bin/aimai → src/cli.py)
• bin/aimai: Unix‑executable that bootstraps the Python environment and calls src/cli.py.
• src/cli.py: Uses Click to parse user arguments and dispatch to the controller.
b. Controller Layer (src/controller.py)
• Receives parsed input from cli.py.
• Coordinates the flow: calls the model to generate command candidates and passes results to the view.
c. Model Layer (src/model.py)
• Contains business logic and data structures.
• Wraps the Google Generative AI (Gemini) API client to translate natural language into shell commands.
• Handles environment variable loading (python‑dotenv) and API key management.
• May invoke subprocess or shell to execute confirmed commands.
d. View Layer (src/view.py)
• Renders output in the terminal using Rich for formatting.
e. External Services
• Google Generative AI (Gemini 1.5 Flash) via google-generativeai SDK.
Data and Control Flow
1. User runs aimai "指示文" in shell. → bin/aimai → src/cli.py.
2. cli.py (Click) parses the argument and calls controller.handle_request(natural_text).
3. Controller invokes Model.generate_commands(natural_text).
4. Model sends request to Gemini API, receives a set of shell command candidates.
5. Controller passes candidates to View.present_choices(candidates).
6. View displays formatted list (Rich) and lets the user select one (PromptToolkit).
7. On user confirmation, Controller tells Model to execute the chosen command.
8. Model runs the command in the shell and returns the result.
9. View prints execution output.
Architectural Patterns and Principles
• MVC Separation:
• Model: API integration & execution logic.
• View: Presentation & interactive UI.
• Controller: Orchestration between model/view.
• Single Responsibility: each module focuses on one concern.
• Dependency Injection via function parameters (e.g., injecting API client into model).
• External‑service boundary clearly marked (Gemini API).
• Each component clearly labeled with file name and responsibility.
• Internal modules (blue),
• External services (green),
• Scripts & shell (gray).