The Amazon Q Developer CLI is part of a monorepo that houses the core code for the Amazon Q Developer desktop application and command-line interface. Amazon Q Developer is an AI assistant built by AWS to help developers with various tasks.
- q_cli: The main CLI tool that allows users to interact with Amazon Q Developer from the command line
- fig_desktop: The Rust desktop application that uses tao/wry for windowing and webviews
- Web Applications: React apps for autocomplete functionality and dashboard interface
- IDE Extensions: VSCode, JetBrains, and GNOME extensions
crates/
- Contains all internal Rust cratespackages/
- Contains all internal npm packagesproto/
- Protocol buffer message specifications for inter-process communicationextensions/
- IDE extensionsbuild-scripts/
- Python scripts for building, signing, and testingtests/
- Integration tests
-
Chat Module Structure
- The chat functionality is implemented in the
q_cli/src/cli/chat
directory - Main components include conversation state management, input handling, response parsing, and tool execution
- The chat functionality is implemented in the
-
User Interface
- Provides an interactive terminal-based chat interface
- Uses
rustyline
for command-line input with features like history, completion, and highlighting - Displays a welcome message with usage suggestions and available commands
- Supports special commands like
/help
,/quit
,/clear
, and/acceptall
-
Conversation Management
ConversationState
class maintains the chat history and context- Tracks user messages, assistant responses, and tool executions
- Manages conversation history with a maximum limit (100 messages)
- Preserves environmental context like working directory and shell state
-
Input Handling
InputSource
handles reading user input with support for multi-line inputsCommand
parser interprets user input as questions, commands, or special commands- Supports command completion for special commands like
/help
and/clear
-
Response Parsing
ResponseParser
processes streaming responses from the Amazon Q service- Handles markdown formatting and syntax highlighting
- Manages tool use requests from the assistant
The chat implementation includes a robust tool system that allows Amazon Q to interact with the user's environment:
-
Available Tools:
fs_read
: Reads files or lists directories (similar tocat
orls
)fs_write
: Creates or modifies files with various operations (create, append, replace)execute_bash
: Executes shell commands in the user's environmentuse_aws
: Makes AWS CLI API calls with specified services and operations
-
Tool Execution Flow:
- Amazon Q requests to use a tool via the API
- The CLI parses the request and validates parameters
- The tool is executed with appropriate permissions checks
- Results are returned to Amazon Q for further processing
- The conversation continues with the tool results incorporated
-
Security Considerations:
- Tools that modify the system (like
fs_write
andexecute_bash
) require user confirmation - The
/acceptall
command can toggle automatic acceptance for the session - Tool responses are limited to prevent excessive output (30KB limit)
- Tools that modify the system (like
-
API Communication:
- Uses a streaming client to communicate with the Amazon Q service
- Handles asynchronous responses and tool requests
- Manages timeouts and connection errors
-
Display Formatting:
- Uses
crossterm
for terminal control and styling - Implements markdown parsing and syntax highlighting
- Displays spinners during processing
- Uses
-
Error Handling:
- Comprehensive error types and handling for various failure scenarios
- Graceful degradation when services are unavailable
- Signal handling for user interruptions
-
Configuration:
- Respects user settings for editor mode (vi/emacs)
- Region checking for service availability
- Telemetry for usage tracking
The implementation provides a seamless interface between the user and Amazon Q's AI capabilities, with powerful tools that allow the assistant to help with file operations, command execution, and AWS service interactions, all within a terminal-based chat interface.