简体中文 · English
# Environment Bootstrap for AI Agents This document lets an AI agent bootstrap a clean checkout without relying on a developer-specific shell function, absolute path, IDE, or preinstalled ESP-IDF. The required baseline is ESP-IDF 5.5.3 for ESP32-C3. ## Agent contract Before installing anything: 1. Run `git status --short --branch` in an existing checkout and preserve all user changes. 2. Detect the operating system and architecture. Check for an already activated ESP-IDF before downloading another copy. 3. Reuse an existing installation only when `idf.py --version` reports `ESP-IDF v5.5.3`. Install other versions side by side; do not replace them. 4. Ask for approval before using `sudo`, installing system packages, writing outside the repository, changing group membership, or downloading through a restricted network. 5. Do not edit shell startup files, global Git configuration, proxy settings, certificate verification, or package-manager configuration without explicit user authorization. 6. Never use a machine-specific shell alias as a required command. 7. Prefer official upstream and Espressif-operated download services. Do not silently fall back to an unverified mirror. Start with read-only discovery: ```bash uname -s uname -m command -v idf.py || true idf.py --version 2>/dev/null || true printf 'IDF_PATH=%s\n' "${IDF_PATH:-}" git status --short --branch ``` If the correct environment is already active, continue at [Initialize the checkout](#initialize-the-checkout). ## Choose a download route Use the international route by default. Use the mainland China route when the user requests it or direct GitHub/registry downloads are unavailable or too slow. Keep mirror variables scoped to the current terminal or command. | Download | International default | Mainland China official route | | --- | --- | --- | | ESP-IDF source | GitHub `espressif/esp-idf` | Espressif Gitee mirror plus `esp-gitee-tools` | | Compiler and tool archives | GitHub release assets | `dl.espressif.cn/github_assets` | | Managed Components | ESP Component Registry default storage | `components-file.espressif.cn` | | Project repository | URL supplied by the user | A user-supplied mirror of the same repository | Do not invent a mirror URL for this project. If the supplied repository URL is unreachable, ask the user for an authorized mirror or archive. ## Install host prerequisites ### Ubuntu and Debian After approval for system changes: ```bash sudo apt-get update sudo apt-get install -y git wget curl flex bison gperf python3 \ python3-pip python3-venv cmake ninja-build ccache libffi-dev \ libssl-dev dfu-util libusb-1.0-0 build-essential ``` ### Fedora and related distributions ```bash sudo dnf install -y git wget curl flex bison gperf python3 cmake \ ninja-build ccache libffi-devel openssl-devel dfu-util libusb1-devel \ gcc gcc-c++ make ``` ### Arch Linux ```bash sudo pacman -S --needed base-devel git wget curl flex bison gperf python \ cmake ninja ccache dfu-util libusb ``` ### macOS Install Xcode Command Line Tools and Homebrew first, then: ```bash xcode-select --install brew install cmake ninja ccache dfu-util libusb python ``` Do not launch `xcode-select --install` or install Homebrew without user approval; both are host-level changes and may require interaction. ### Windows and WSL2 For native Windows, use Espressif's official ESP-IDF Tools Installer and select ESP-IDF v5.5.3. Run later commands in the installer-created ESP-IDF PowerShell or Command Prompt. Do not translate POSIX activation commands literally into PowerShell. WSL2 can run the Linux build flow. USB flashing and monitoring require a device forwarded into WSL; otherwise build in WSL and flash from an activated native Windows ESP-IDF terminal. ## Install ESP-IDF 5.5.3 Use a location outside this repository and without spaces. The variable below is task-specific and can be overridden by the user: ```bash export AI_PASSPORT_IDF_ROOT="${AI_PASSPORT_IDF_ROOT:-${HOME}/esp/esp-idf-v5.5.3}" ``` ### International route ```bash mkdir -p "$(dirname "${AI_PASSPORT_IDF_ROOT}")" git clone --branch v5.5.3 --recursive \ https://github.com/espressif/esp-idf.git \ "${AI_PASSPORT_IDF_ROOT}" "${AI_PASSPORT_IDF_ROOT}/install.sh" esp32c3 ``` If cloning was interrupted, repair the checkout instead of starting over: ```bash git -C "${AI_PASSPORT_IDF_ROOT}" submodule update --init --recursive "${AI_PASSPORT_IDF_ROOT}/install.sh" esp32c3 ``` ### Mainland China route The following route uses repositories and download endpoints operated by Espressif. It does not change global Git or pip configuration: ```bash export AI_PASSPORT_GITEE_TOOLS_ROOT="${AI_PASSPORT_GITEE_TOOLS_ROOT:-${HOME}/esp/esp-gitee-tools}" mkdir -p "$(dirname "${AI_PASSPORT_IDF_ROOT}")" git clone --branch v5.5.3 \ https://gitee.com/EspressifSystems/esp-idf.git \ "${AI_PASSPORT_IDF_ROOT}" git clone https://gitee.com/EspressifSystems/esp-gitee-tools.git \ "${AI_PASSPORT_GITEE_TOOLS_ROOT}" "${AI_PASSPORT_GITEE_TOOLS_ROOT}/submodule-update.sh" \ "${AI_PASSPORT_IDF_ROOT}" IDF_GITHUB_ASSETS=dl.espressif.cn/github_assets \ "${AI_PASSPORT_IDF_ROOT}/install.sh" esp32c3 ``` If the Gitee helper reports an interrupted download, rerun its submodule command for the same checkout. Do not mix partial submodules from unrelated ESP-IDF versions. ## Activate and verify ESP-IDF Activation applies to the current shell only and is the portable replacement for machine-specific aliases: ```bash source "${AI_PASSPORT_IDF_ROOT}/export.sh" idf.py --version python --version printf 'IDF_PATH=%s\n' "${IDF_PATH}" ``` Stop if the reported version is not exactly `ESP-IDF v5.5.3`. Do not generate project configuration with another version. For mainland China, optionally accelerate Managed Component archives in the current terminal: ```bash export IDF_COMPONENT_STORAGE_URL="https://components-file.espressif.cn" ``` This changes only the component file-storage endpoint. Version selection still comes from `components/bsp/idf_component.yml` and the tracked `dependencies.lock`. ## Obtain the project If the agent was given a repository URL but has no checkout yet: ```bash git clone