How radareorg/r2ai works
Based on your project’s file tree and README, the project is clearly a multi-component tool built for reverse engineering with radare2. Its primary purpose is to integrate language models (local or remote) to assist and automate reverse engineering tasks, including decompilation, code analysis, and interactive querying from within radare2. There are four main components with clear roles:
Main components
• r2ai (the Python CLI tool): This is the central “brain” where users interact via a REPL. It handles command interpretation, communicates with radare2 via r2pipe, implements auto mode (including function calling), and supports interactions with multiple language models (e.g., OpenAI, Anthropic, local models from Hugging Face).
• decai (r2js plugin for decompilation): This JavaScript-based plugin integrates directly into radare2 to provide an additional “command” inside the shell (the decai command) and focuses on decompiling code. It serves as a bridge between radare2 (through r2js) and external language model services via curl.
• r2ai-plugin (native C plugin): Although not a separate folder in the file tree, it is mentioned in the README. This lightweight plugin is written in C and injects an r2ai command directly into the r2 shell. It is responsible for low-level interactions, providing integration and speed.
• r2ai-server (the webserver tool): This component acts as a local server exposing an OpenAPI interface. It is used to list and select models and to start local servers that can interact with language models (supporting models like llamafile, llamacpp, r2ai-w, and kobaldcpp). It may be used to host local AI models, such as Mistral, serving requests from r2ai and decai.
Architectural relationships and interactions
• The central CLI (r2ai) communicates with radare2 via the r2pipe interface for commands and embedding outputs.
• r2ai uses configuration files (including settings for API keys, model defaults, and environment variables) to connect to external language model services.
• When a decompilation or auto command is issued via decai, the plugin passes the query (directly or after some preprocessing) to the appropriate language model service, either locally (via r2ai-server) or remotely. In auto mode, there’s also a confirmation step where generated commands are shown for approval.
• r2ai-server, running as a separate CLI tool, provides a local API that can be used by both the CLI and decai. This encapsulation facilitates model management and selection (including differences like local model services via Ollama).
Key design principles and patterns
• Modular Split: The application is divided into independent components that can be installed separately (via r2pm or from sources).
• Client–Server Model: r2ai and decai act as clients while the r2ai-server acts as a service backend to manage and serve language model queries.
• Plugin Architecture: The native plugin and the r2js-based decai enhance radare2 by extending its capabilities.
• Configurability: There is significant runtime configuration (API key files, model selection, environment variables) to allow dynamic behavior based on the user’s needs.
Final checklist
• All components (r2ai CLI, decai plugin, native plugin, r2ai-server, radare2, external language model sources) are represented.
• Distinguish between different types of interactions – command execution, API calls, model downloading/selection, etc.
• Special configuration flows (API keys, local storage locations like ~/.r2ai.models) where necessary.