简体中文 · 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 Git service mirror (`git.espressif.com.cn`), or 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. The Espressif Git service mirror hosts the full `esp-idf` history and every v5.5.3 submodule repository (`espressif/esp32-wifi-lib`, `espressif/esp-lwip`, `ThrowTheSwitch/CMock`, and so on). Because the v5.5.3 `.gitmodules` entries are relative URLs, cloning the parent repository from the mirror resolves every submodule to the same mirror automatically; no separate submodule rewrite is needed. Cloning from the mirror leaves a working checkout identical to the GitHub clone: verify the tag commit matches `https://github.com/espressif/esp-idf/releases/tag/v5.5.3` (currently `b31fcc7a314a44ad992b58f589f7d1d8a4fadff6`). Legacy mirror installers sometimes write a global per-repository `insteadOf` rewrite for Jihulab (`jihulab.com/esp-mirror/...`, or a `git config --global url."https://jihulab.com/esp-mirror/".insteadOf` switch). A per-repository entry is more specific than any bulk switch and silently redirects submodules to a source that returns 404 or timeouts. When a submodule fetch fails this way, inspect and clean the residue after user approval instead of retrying blindly: ```bash git config --global --get-regexp 'url\..*jihulab' # Cleaning requires user approval: unset each entry individually; removing only # the bulk switch leaves per-repository entries that still redirect submodules. ``` ## 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 routes use repositories and download endpoints operated by Espressif. They do not change global Git or pip configuration. **Espressif Git service mirror (preferred).** Clone from the mirror URL directly — `origin` becomes the mirror URL, so every relative submodule URL inside `esp-idf` (`../../espressif/...`) resolves to the same mirror without a rewrite and without global Git configuration: ```bash mkdir -p "$(dirname "${AI_PASSPORT_IDF_ROOT}")" git clone --branch v5.5.3 --recursive \ https://git.espressif.com.cn/espressif/esp-idf.git \ "${AI_PASSPORT_IDF_ROOT}" IDF_GITHUB_ASSETS=dl.espressif.cn/github_assets \ "${AI_PASSPORT_IDF_ROOT}/install.sh" esp32c3 ``` The mirror has published the same v5.5.3 tag commit as GitHub (`b31fcc7a314a44ad992b58f589f7d1d8a4fadff6`), and it hosts the submodule repositories themselves, so the checkout is identical to the GitHub clone. **Gitee mirror plus esp-gitee-tools (fallback).** ```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. ### Submodule pulls and long waits `esp-idf` v5.5.3 bundles more than twenty submodules, and several of them (`components/esp_wifi/lib`, `components/esp_phy/lib`, `components/bt/controller/lib_esp32c3_family`) are large prebuilt libraries. A `git submodule update --init --recursive` can therefore run for minutes with little output, and agent shells commonly kill it after a fixed wait (for example a 300000 ms or "exceeding timeout" message) while the process is still fetching. Check the real state first instead of assuming the mirror failed: - Submodule fetching in progress is not a failure until the shell reports an exit code AND `git status` stays non-clean. Re-run with a longer shell wait limit, or run the command in the background until it truly exits. - An interrupted `git submodule update` leaves `modified:` entries under `components/` (for example `components/esp_wifi/lib`). This is a partial checkout, not corrupted state. Repair in place rather than cloning from scratch: ```bash git -C "${AI_PASSPORT_IDF_ROOT}" submodule update --init --recursive # if status still lists submodule paths, update each one by path: git -C "${AI_PASSPORT_IDF_ROOT}" submodule update --init components/