-
Notifications
You must be signed in to change notification settings - Fork 764
Add MicroPython runtime scaffolding #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d99cfa4
bf0961e
a25708f
54e3ff4
5cf61e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,104 @@ | |
| # CMakeLists in this exact order for cmake to work correctly | ||
| cmake_minimum_required(VERSION 3.16) | ||
|
|
||
| option(MIMI_ENABLE_MICROPYTHON "Enable MicroPython integration" OFF) | ||
|
|
||
| # MicroPython helper (local clone to avoid component-manager object lib issues) | ||
| if(MIMI_ENABLE_MICROPYTHON) | ||
| set(MICROPY_HELPER_DIR "${CMAKE_CURRENT_LIST_DIR}/third_party/micropython-helper") | ||
| if(NOT EXISTS "${MICROPY_HELPER_DIR}") | ||
| find_package(Git QUIET) | ||
| if(GIT_FOUND) | ||
| execute_process( | ||
| COMMAND "${GIT_EXECUTABLE}" clone --depth 1 --recurse-submodules | ||
| https://github.com/mr9you/micropython-helper.git | ||
| "${MICROPY_HELPER_DIR}" | ||
| RESULT_VARIABLE _mimi_git_clone_rc | ||
| ) | ||
| endif() | ||
| endif() | ||
| endif() | ||
| if(NOT MICROPY_BOARD) | ||
| set(MICROPY_BOARD "ESP32_GENERIC_S3") | ||
| endif() | ||
| if(MIMI_ENABLE_MICROPYTHON AND EXISTS "${MICROPY_HELPER_DIR}/mpy.cmake") | ||
| # Work around IDF 5.5 + micropython-helper 1.22.1: linking micropy_extmod_btree | ||
| # (OBJECT_LIBRARY) breaks ldgen when TARGET_FILE is expanded. | ||
| set(_mimi_extmod_cmake "${MICROPY_HELPER_DIR}/micropython/extmod/extmod.cmake") | ||
| if(EXISTS "${_mimi_extmod_cmake}") | ||
| file(READ "${_mimi_extmod_cmake}" _mimi_extmod_src) | ||
| string(REPLACE | ||
| "add_library(micropy_extmod_btree OBJECT" | ||
| "add_library(micropy_extmod_btree STATIC" | ||
| _mimi_extmod_src | ||
| "${_mimi_extmod_src}" | ||
| ) | ||
| file(WRITE "${_mimi_extmod_cmake}" "${_mimi_extmod_src}") | ||
| endif() | ||
| set(_mimi_mpy_common "${MICROPY_HELPER_DIR}/micropython/ports/esp32/esp32_common.cmake") | ||
| if(EXISTS "${_mimi_mpy_common}") | ||
| file(READ "${_mimi_mpy_common}" _mimi_mpy_common_src) | ||
| string(REGEX REPLACE | ||
| "[^\n]*target_link_libraries\\([^\n]*micropy_extmod_btree[^\n]*\\)\n" | ||
| "" | ||
| _mimi_mpy_common_src | ||
| "${_mimi_mpy_common_src}" | ||
| ) | ||
| file(WRITE "${_mimi_mpy_common}" "${_mimi_mpy_common_src}") | ||
| endif() | ||
|
Comment on lines
+28
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modifying files in Writing to
Prefer a downstream fix: after |
||
| include(${MICROPY_HELPER_DIR}/mpy.cmake) | ||
| # If btree is an OBJECT library, wrap it as STATIC and replace references. | ||
| if(TARGET micropy_extmod_btree) | ||
| get_target_property(_mimi_btree_type micropy_extmod_btree TYPE) | ||
| if(_mimi_btree_type STREQUAL "OBJECT_LIBRARY") | ||
| add_library(micropy_extmod_btree_static STATIC $<TARGET_OBJECTS:micropy_extmod_btree>) | ||
| get_target_property(_mimi_btree_iface micropy_extmod_btree INTERFACE_LINK_LIBRARIES) | ||
| if(_mimi_btree_iface) | ||
| target_link_libraries(micropy_extmod_btree_static INTERFACE ${_mimi_btree_iface}) | ||
| endif() | ||
| endif() | ||
| endif() | ||
| # Remove problematic link entry even if helper CMake layout changes. | ||
| get_property(_mimi_all_targets GLOBAL PROPERTY TARGETS) | ||
| foreach(_mimi_tgt IN LISTS _mimi_all_targets) | ||
| foreach(_mimi_prop IN ITEMS LINK_LIBRARIES INTERFACE_LINK_LIBRARIES) | ||
| get_target_property(_mimi_links ${_mimi_tgt} ${_mimi_prop}) | ||
| if(_mimi_links) | ||
| set(_mimi_links_new "${_mimi_links}") | ||
| list(REMOVE_ITEM _mimi_links_new micropy_extmod_btree "$<LINK_ONLY:micropy_extmod_btree>") | ||
| if(TARGET micropy_extmod_btree_static) | ||
| list(REMOVE_ITEM _mimi_links_new micropy_extmod_btree_static "$<LINK_ONLY:micropy_extmod_btree_static>") | ||
| list(APPEND _mimi_links_new micropy_extmod_btree_static) | ||
| endif() | ||
| if(NOT _mimi_links_new STREQUAL _mimi_links) | ||
| set_property(TARGET ${_mimi_tgt} PROPERTY ${_mimi_prop} "${_mimi_links_new}") | ||
| endif() | ||
| endif() | ||
| endforeach() | ||
| endforeach() | ||
|
Comment on lines
+63
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
get_property(_mimi_all_targets DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" PROPERTY BUILDSYSTEM_TARGETS)However, even with this fix, the loop runs before 🤖 Prompt for AI Agents |
||
| endif() | ||
| if(EXISTS "${CMAKE_BINARY_DIR}/sdkconfig.combined") | ||
| file(READ "${CMAKE_BINARY_DIR}/sdkconfig.combined" _sc) | ||
| string(REPLACE "CONFIG_MBEDTLS_SSL_ALPN=n" "CONFIG_MBEDTLS_SSL_ALPN=y" _sc "${_sc}") | ||
| string(REPLACE "CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=n" "CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=y" _sc "${_sc}") | ||
| file(WRITE "${CMAKE_BINARY_DIR}/sdkconfig.combined" "${_sc}") | ||
| file(APPEND "${CMAKE_BINARY_DIR}/sdkconfig.combined" | ||
| "\nCONFIG_MBEDTLS_SSL_ALPN=y\nCONFIG_MBEDTLS_CERTIFICATE_BUNDLE=y\n") | ||
| endif() | ||
|
Comment on lines
+81
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant patching and timing issue with
Consider moving this logic to a post-configure hook or using Proposed simplification (remove redundant append) if(EXISTS "${CMAKE_BINARY_DIR}/sdkconfig.combined")
file(READ "${CMAKE_BINARY_DIR}/sdkconfig.combined" _sc)
string(REPLACE "CONFIG_MBEDTLS_SSL_ALPN=n" "CONFIG_MBEDTLS_SSL_ALPN=y" _sc "${_sc}")
string(REPLACE "CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=n" "CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=y" _sc "${_sc}")
file(WRITE "${CMAKE_BINARY_DIR}/sdkconfig.combined" "${_sc}")
- file(APPEND "${CMAKE_BINARY_DIR}/sdkconfig.combined"
- "\nCONFIG_MBEDTLS_SSL_ALPN=y\nCONFIG_MBEDTLS_CERTIFICATE_BUNDLE=y\n")
endif()🤖 Prompt for AI Agents |
||
| set(_mimi_sdkconfig_defaults | ||
| "sdkconfig.defaults" | ||
| "${CMAKE_CURRENT_LIST_DIR}/sdkconfig.defaults.esp32s3" | ||
| ) | ||
| if(MIMI_ENABLE_MICROPYTHON) | ||
| list(APPEND _mimi_sdkconfig_defaults | ||
| "${CMAKE_CURRENT_LIST_DIR}/sdkconfig.micropython.override" | ||
| ) | ||
| endif() | ||
| if(EXISTS "${CMAKE_BINARY_DIR}/sdkconfig.combined") | ||
| list(INSERT _mimi_sdkconfig_defaults 1 "${CMAKE_BINARY_DIR}/sdkconfig.combined") | ||
| endif() | ||
| set(SDKCONFIG_DEFAULTS "${_mimi_sdkconfig_defaults}" CACHE STRING "Kconfig defaults" FORCE) | ||
|
|
||
| include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
| project(mimiclaw) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,66 @@ | ||
| set(MIMI_MAIN_SRCS | ||
| "mimi.c" | ||
| "bus/message_bus.c" | ||
| "wifi/wifi_manager.c" | ||
| "channels/telegram/telegram_bot.c" | ||
| "channels/feishu/feishu_bot.c" | ||
| "llm/llm_proxy.c" | ||
| "agent/agent_loop.c" | ||
| "agent/context_builder.c" | ||
| "memory/memory_store.c" | ||
| "memory/session_mgr.c" | ||
| "gateway/ws_server.c" | ||
| "compat/esp_tls_stubs.c" | ||
| "cli/serial_cli.c" | ||
| "proxy/http_proxy.c" | ||
| "cron/cron_service.c" | ||
| "heartbeat/heartbeat.c" | ||
| "tools/tool_registry.c" | ||
| "tools/tool_cron.c" | ||
| "tools/tool_web_search.c" | ||
| "tools/tool_get_time.c" | ||
| "tools/tool_files.c" | ||
| "skills/skill_loader.c" | ||
| ) | ||
|
|
||
| set(MIMI_MAIN_INCLUDE_DIRS "." "compat") | ||
|
|
||
| set(MIMI_MAIN_REQUIRES | ||
| nvs_flash esp_wifi esp_netif esp_http_client esp_http_server | ||
| esp_https_ota esp_event json spiffs console vfs app_update esp-tls | ||
| esp_timer esp_websocket_client tcp_transport | ||
| ) | ||
|
|
||
| if(MIMI_ENABLE_MICROPYTHON) | ||
| list(APPEND MIMI_MAIN_SRCS | ||
| "micropython/mpy_runner.c" | ||
| "micropython/mpy_stubs.c" | ||
| "micropython/mpy_uart_stubs.c" | ||
| ) | ||
| list(APPEND MIMI_MAIN_INCLUDE_DIRS | ||
| "micropython" | ||
| "${CMAKE_BINARY_DIR}" | ||
| "${CMAKE_SOURCE_DIR}/third_party/micropython-helper/micropython" | ||
| "${CMAKE_SOURCE_DIR}/third_party/micropython-helper/micropython/ports/esp32" | ||
| "${CMAKE_SOURCE_DIR}/third_party/micropython-helper/micropython/ports/esp32/boards/${MICROPY_BOARD}" | ||
| ) | ||
| list(APPEND MIMI_MAIN_REQUIRES esp_driver_gpio esp_driver_i2s) | ||
| endif() | ||
|
|
||
| idf_component_register( | ||
| SRCS | ||
| "mimi.c" | ||
| "bus/message_bus.c" | ||
| "wifi/wifi_manager.c" | ||
| "channels/telegram/telegram_bot.c" | ||
| "channels/feishu/feishu_bot.c" | ||
| "llm/llm_proxy.c" | ||
| "agent/agent_loop.c" | ||
| "agent/context_builder.c" | ||
| "memory/memory_store.c" | ||
| "memory/session_mgr.c" | ||
| "gateway/ws_server.c" | ||
| "cli/serial_cli.c" | ||
| "proxy/http_proxy.c" | ||
| "cron/cron_service.c" | ||
| "heartbeat/heartbeat.c" | ||
| "tools/tool_registry.c" | ||
| "tools/tool_cron.c" | ||
| "tools/tool_web_search.c" | ||
| "tools/tool_get_time.c" | ||
| "tools/tool_files.c" | ||
| "skills/skill_loader.c" | ||
| INCLUDE_DIRS | ||
| "." | ||
| REQUIRES | ||
| nvs_flash esp_wifi esp_netif esp_http_client esp_http_server | ||
| esp_https_ota esp_event json spiffs console vfs app_update esp-tls | ||
| esp_timer esp_websocket_client | ||
| SRCS ${MIMI_MAIN_SRCS} | ||
| INCLUDE_DIRS ${MIMI_MAIN_INCLUDE_DIRS} | ||
| REQUIRES ${MIMI_MAIN_REQUIRES} | ||
| ) | ||
|
|
||
| target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-format-truncation) | ||
| target_include_directories(${COMPONENT_LIB} PRIVATE ${IDF_PATH}/components/mbedtls/esp_crt_bundle/include) | ||
| if(MIMI_ENABLE_MICROPYTHON) | ||
| if(DEFINED MICROPY_GENHDR_DIR) | ||
| get_filename_component(_mimi_genhdr_parent "${MICROPY_GENHDR_DIR}" DIRECTORY) | ||
| target_include_directories(${COMPONENT_LIB} PRIVATE "${_mimi_genhdr_parent}") | ||
| endif() | ||
| if(DEFINED MICROPY_TARGET) | ||
| add_dependencies(${COMPONENT_LIB} ${MICROPY_TARGET}) | ||
| endif() | ||
| endif() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,13 +172,23 @@ static void agent_loop_task(void *arg) | |
| { | ||
| ESP_LOGI(TAG, "Agent loop started on core %d", xPortGetCoreID()); | ||
|
|
||
| /* Allocate large buffers from PSRAM */ | ||
| /* Allocate large buffers from PSRAM, fallback to internal RAM */ | ||
| char *system_prompt = heap_caps_calloc(1, MIMI_CONTEXT_BUF_SIZE, MALLOC_CAP_SPIRAM); | ||
| char *history_json = heap_caps_calloc(1, MIMI_LLM_STREAM_BUF_SIZE, MALLOC_CAP_SPIRAM); | ||
| char *tool_output = heap_caps_calloc(1, TOOL_OUTPUT_SIZE, MALLOC_CAP_SPIRAM); | ||
|
|
||
| if (!system_prompt) { | ||
| system_prompt = heap_caps_calloc(1, MIMI_CONTEXT_BUF_SIZE, MALLOC_CAP_8BIT); | ||
| } | ||
| if (!history_json) { | ||
| history_json = heap_caps_calloc(1, MIMI_LLM_STREAM_BUF_SIZE, MALLOC_CAP_8BIT); | ||
| } | ||
| if (!tool_output) { | ||
| tool_output = heap_caps_calloc(1, TOOL_OUTPUT_SIZE, MALLOC_CAP_8BIT); | ||
| } | ||
|
|
||
| if (!system_prompt || !history_json || !tool_output) { | ||
| ESP_LOGE(TAG, "Failed to allocate PSRAM buffers"); | ||
| ESP_LOGE(TAG, "Failed to allocate agent buffers"); | ||
| vTaskDelete(NULL); | ||
|
Comment on lines
+180
to
192
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Free successful allocations before aborting startup. If one buffer still fails after fallback, Lines 190-192 delete the task without releasing the buffers that already succeeded. On a low-memory boot that leaks tens of KiB permanently and makes recovery harder. Proposed fix if (!system_prompt || !history_json || !tool_output) {
ESP_LOGE(TAG, "Failed to allocate agent buffers");
+ free(system_prompt);
+ free(history_json);
+ free(tool_output);
vTaskDelete(NULL);
return;
}🤖 Prompt for AI Agents |
||
| return; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: memovai/mimiclaw
Length of output: 1203
🏁 Script executed:
Repository: memovai/mimiclaw
Length of output: 370
🏁 Script executed:
Repository: memovai/mimiclaw
Length of output: 98
🏁 Script executed:
Repository: memovai/mimiclaw
Length of output: 77
🏁 Script executed:
Repository: memovai/mimiclaw
Length of output: 3383
🏁 Script executed:
Repository: memovai/mimiclaw
Length of output: 42
🏁 Script executed:
Repository: memovai/mimiclaw
Length of output: 42
🏁 Script executed:
Repository: memovai/mimiclaw
Length of output: 173
The
$<TARGET_FILE:micropy_extmod_btree>generator expression is not being removed by the current workaround.The workaround removes
$<LINK_ONLY:micropy_extmod_btree>at line 32 and attempts regex removal from source files at line 17, but the error indicates$<TARGET_FILE:micropy_extmod_btree>is still being generated. These are different generator expression patterns—theTARGET_FILEvariant is not caught by the current mitigation. This requires either a patched version of micropython-helper that doesn't generate the TARGET_FILE expression, or a deterministic component-level fix after the target graph exists, before merge.🤖 Prompt for AI Agents