From 3c8f8f89ae15458d05a684eaa03d96f5a8b0ec8b Mon Sep 17 00:00:00 2001 From: sunrisepeak Date: Wed, 13 May 2026 14:44:27 +0800 Subject: [PATCH] feat: upgrade to mcpp 0.0.13 + llmapi 0.2.6 + mcpp build support - mcpp.toml: canonical namespace deps - .xlings.json: mcpp 0.0.13 - CI linux: mcpp build (xlings 0.4.31) - xmake.lua: llmapi 0.2.5 + explicit transitive deps (tinyhttps, mbedtls) - Source: llmapi 0.2.x API migration --- .github/workflows/ci.yml | 79 +++++++++---------- .gitignore | 3 +- .xlings.json | 4 +- mcpp.toml | 17 ++++ src/assistant.cppm | 17 ++-- src/platform/linux.cppm | 2 +- src/platform/macos.cppm | 2 +- src/platform/windows.cppm | 2 +- src/ui/plugin/print.cppm | 4 +- src/ui/plugin/print_backend/checker_page.cppm | 2 +- src/ui/plugin/print_backend/help_page.cppm | 2 +- src/ui/plugin/tui.cppm | 4 +- src/ui/plugin/tui_backend/checker_page.cppm | 2 +- src/ui/plugin/tui_backend/help_page.cppm | 2 +- xmake.lua | 9 ++- 15 files changed, 85 insertions(+), 66 deletions(-) create mode 100644 mcpp.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a706324..c028ef7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,50 +4,46 @@ on: push: branches: [main] pull_request: - branches: [main] - -env: - XLINGS_VERSION: v0.4.0 jobs: - build-linux: - runs-on: ubuntu-24.04 + build-linux-mcpp: + name: build (linux x86_64, mcpp) + runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install system deps - run: | - sudo apt-get update -qq - sudo apt-get install -y curl git build-essential + - uses: actions/checkout@v4 - - name: Install Xlings + - name: Install xlings env: - XLINGS_NON_INTERACTIVE: 1 + XLINGS_VERSION: 0.4.31 run: | - VERSION_NUM="${XLINGS_VERSION#v}" - TARBALL="xlings-${VERSION_NUM}-linux-x86_64.tar.gz" - curl -fSL -o "$RUNNER_TEMP/$TARBALL" "https://github.com/d2learn/xlings/releases/download/${XLINGS_VERSION}/${TARBALL}" - tar -xzf "$RUNNER_TEMP/$TARBALL" -C "$RUNNER_TEMP" - EXTRACT_DIR=$(find "$RUNNER_TEMP" -maxdepth 1 -type d -name "xlings-*" | head -1) - chmod +x "$EXTRACT_DIR/bin/xlings" - "$EXTRACT_DIR/bin/xlings" self install - echo "PATH=$HOME/.xlings/subos/current/bin:$PATH" >> "$GITHUB_ENV" + tarball="xlings-${XLINGS_VERSION}-linux-x86_64.tar.gz" + curl -fsSL -o "/tmp/${tarball}" \ + "https://github.com/d2learn/xlings/releases/download/v${XLINGS_VERSION}/${tarball}" + tar -xzf "/tmp/${tarball}" -C /tmp + "/tmp/xlings-${XLINGS_VERSION}-linux-x86_64/subos/default/bin/xlings" self install + echo "$HOME/.xlings/subos/current/bin" >> "$GITHUB_PATH" - - name: Install Project Dependencies via Xlings - run: | - xlings install + - name: Refresh package index + run: xlings update + - name: Install workspace tools (.xlings.json → mcpp 0.0.13) + run: xlings install -y - - name: Build with xmake - run: | - xmake f -m release -vv -y - xmake -j$(nproc) + - name: Cache mcpp sandbox + uses: actions/cache@v4 + with: + path: ~/.xlings/data/xpkgs/xim-x-mcpp/0.0.13/registry + key: mcpp-sandbox-${{ runner.os }}-mcpp0.0.13 + + - name: Build with mcpp + run: mcpp build - name: Verify d2x run: | - ./build/linux/x86_64/release/d2x --version - ./build/linux/x86_64/release/d2x new hello + binary=$(find target -name d2x -type f | head -1) + test -n "$binary" || { echo "d2x binary not found"; find target -type f | head -20; exit 1; } + chmod +x "$binary" + "$binary" --version build-macos: runs-on: macos-15 @@ -58,10 +54,10 @@ jobs: - name: Install Xlings env: XLINGS_NON_INTERACTIVE: 1 + XLINGS_VERSION: 0.4.31 run: | - VERSION_NUM="${XLINGS_VERSION#v}" - TARBALL="xlings-${VERSION_NUM}-macosx-arm64.tar.gz" - curl -fSL -o "$RUNNER_TEMP/$TARBALL" "https://github.com/d2learn/xlings/releases/download/${XLINGS_VERSION}/${TARBALL}" + TARBALL="xlings-${XLINGS_VERSION}-macosx-arm64.tar.gz" + curl -fSL -o "$RUNNER_TEMP/$TARBALL" "https://github.com/d2learn/xlings/releases/download/v${XLINGS_VERSION}/${TARBALL}" tar -xzf "$RUNNER_TEMP/$TARBALL" -C "$RUNNER_TEMP" EXTRACT_DIR=$(find "$RUNNER_TEMP" -maxdepth 1 -type d -name "xlings-*" | head -1) xattr -dr com.apple.quarantine "$EXTRACT_DIR" 2>/dev/null || true @@ -74,16 +70,20 @@ jobs: xlings install clang --version + - name: Configure xmake + run: | + LLVM_ROOT="$HOME/.xlings/data/xpkgs/xim-x-llvm" + LLVM_SDK=$(find "$LLVM_ROOT" -mindepth 1 -maxdepth 1 -type d | sort -V | tail -1) + test -d "$LLVM_SDK" + "$LLVM_SDK/bin/clang++" --version + xmake f -m release --toolchain=llvm --sdk="$LLVM_SDK" -y -vvD - name: Build with xmake - run: | - xmake f -m release --toolchain=llvm -vv -y - xmake -j$(nproc) + run: xmake -a -j"$(sysctl -n hw.logicalcpu)" - name: Verify d2x run: | ./build/macosx/arm64/release/d2x --version - ./build/macosx/arm64/release/d2x new hello build-windows: runs-on: windows-latest @@ -104,4 +104,3 @@ jobs: - name: Verify d2x run: | build\windows\x64\release\d2x.exe --version - build\windows\x64\release\d2x.exe new hello \ No newline at end of file diff --git a/.gitignore b/.gitignore index 82a5778..700d111 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .xlings .xmake build -d2x.zip \ No newline at end of file +target +d2x.zip diff --git a/.xlings.json b/.xlings.json index 232895a..1eb6d31 100644 --- a/.xlings.json +++ b/.xlings.json @@ -1,8 +1,8 @@ { "workspace": { + "mcpp": { "linux": "0.0.13" }, "xmake": "3.0.7", "gcc": { "linux": "15.1.0" }, - "openssl": { "linux": "3.1.5" }, "llvm": { "macosx": "20" } } -} \ No newline at end of file +} diff --git a/mcpp.toml b/mcpp.toml new file mode 100644 index 0000000..966fdb6 --- /dev/null +++ b/mcpp.toml @@ -0,0 +1,17 @@ +[package] +name = "d2x" +version = "0.1.2" +description = "AI-powered development assistant for C++ projects" +license = "Apache-2.0" +repo = "https://github.com/d2learn/d2x" + +[targets.d2x] +kind = "bin" +main = "src/main.cpp" + +[dependencies.compat] +ftxui = "6.1.9" + +[dependencies.mcpplibs] +cmdline = "0.0.2" +llmapi = "0.2.6" diff --git a/src/assistant.cppm b/src/assistant.cppm index ae7e75a..778e836 100644 --- a/src/assistant.cppm +++ b/src/assistant.cppm @@ -52,7 +52,7 @@ constexpr std::string_view user_prompt_template = R"( export class Assistant { - std::optional mLLMClient; + std::optional> mLLMClient; // 流式请求状态 mutable std::mutex mAnswerMutex; @@ -74,11 +74,13 @@ public: mEnable(Config::is_llm_enabled()) { if (mEnable) { - mLLMClient.emplace(Config::api_key(), Config::api_url()); - log::info("Initialized Assistant with API URL: {}", Config::api_url()); - - mLLMClient->model(Config::model()); - log::info("Using model: {}", Config::model()); + mLLMClient.emplace(llmapi::Config{ + .apiKey = Config::api_key(), + .baseUrl = Config::api_url(), + .model = Config::model() + }); + log::info("Initialized Assistant with API URL: {}, model: {}", + Config::api_url(), Config::model()); } else { log::info("Assistant is disabled (no LLM API key configured)."); } @@ -190,8 +192,7 @@ private: ui::update_ai_tips(mCurrentAnswer); }; - mLLMClient->user(mCurrentQuestion) - .request(capture_stream); + mLLMClient->chat_stream(mCurrentQuestion, capture_stream); } catch (...) { // 忽略异常,保留已接收的部分答案 log::warning("Assistant request encountered an error."); diff --git a/src/platform/linux.cppm b/src/platform/linux.cppm index 867d185..bec2721 100644 --- a/src/platform/linux.cppm +++ b/src/platform/linux.cppm @@ -4,10 +4,10 @@ module; #include export module d2x.platform:linux; +import std; #if defined(__linux__) -import std; namespace d2x { namespace platform_impl { diff --git a/src/platform/macos.cppm b/src/platform/macos.cppm index dad3508..371ff8c 100644 --- a/src/platform/macos.cppm +++ b/src/platform/macos.cppm @@ -4,10 +4,10 @@ module; #include export module d2x.platform:macos; +import std; #if defined(__APPLE__) -import std; namespace d2x { namespace platform_impl { diff --git a/src/platform/windows.cppm b/src/platform/windows.cppm index 7a075fe..e39bf33 100644 --- a/src/platform/windows.cppm +++ b/src/platform/windows.cppm @@ -4,10 +4,10 @@ module; #include export module d2x.platform:windows; +import std; #if defined(_WIN32) -import std; namespace d2x { namespace platform_impl { diff --git a/src/ui/plugin/print.cppm b/src/ui/plugin/print.cppm index 122bb66..68efa14 100644 --- a/src/ui/plugin/print.cppm +++ b/src/ui/plugin/print.cppm @@ -7,8 +7,8 @@ export module d2x.ui.plugin.print; import std; import d2x.ui.interface; -import :checker_page; -import :help_page; +export import :checker_page; +export import :help_page; namespace d2x { diff --git a/src/ui/plugin/print_backend/checker_page.cppm b/src/ui/plugin/print_backend/checker_page.cppm index 9a8ff1c..9f01f8f 100644 --- a/src/ui/plugin/print_backend/checker_page.cppm +++ b/src/ui/plugin/print_backend/checker_page.cppm @@ -1,4 +1,4 @@ -module d2x.ui.plugin.print:checker_page; +export module d2x.ui.plugin.print:checker_page; import std; diff --git a/src/ui/plugin/print_backend/help_page.cppm b/src/ui/plugin/print_backend/help_page.cppm index 02645bf..8272074 100644 --- a/src/ui/plugin/print_backend/help_page.cppm +++ b/src/ui/plugin/print_backend/help_page.cppm @@ -1,4 +1,4 @@ -module d2x.ui.plugin.print:help_page; +export module d2x.ui.plugin.print:help_page; import std; diff --git a/src/ui/plugin/tui.cppm b/src/ui/plugin/tui.cppm index 9f9e8ea..2390e4e 100644 --- a/src/ui/plugin/tui.cppm +++ b/src/ui/plugin/tui.cppm @@ -7,8 +7,8 @@ export module d2x.ui.plugin.tui; import std; import d2x.ui.interface; -import :checker_page; -import :help_page; +export import :checker_page; +export import :help_page; namespace d2x { diff --git a/src/ui/plugin/tui_backend/checker_page.cppm b/src/ui/plugin/tui_backend/checker_page.cppm index 6547406..74619cd 100644 --- a/src/ui/plugin/tui_backend/checker_page.cppm +++ b/src/ui/plugin/tui_backend/checker_page.cppm @@ -4,7 +4,7 @@ module; #include #include -module d2x.ui.plugin.tui:checker_page; +export module d2x.ui.plugin.tui:checker_page; import std; import d2x.ui.interface; diff --git a/src/ui/plugin/tui_backend/help_page.cppm b/src/ui/plugin/tui_backend/help_page.cppm index 3bd6d0d..297e39f 100644 --- a/src/ui/plugin/tui_backend/help_page.cppm +++ b/src/ui/plugin/tui_backend/help_page.cppm @@ -3,7 +3,7 @@ module; #include #include -module d2x.ui.plugin.tui:help_page; +export module d2x.ui.plugin.tui:help_page; import std; import d2x.ui.interface; diff --git a/xmake.lua b/xmake.lua index aab0947..bef1f14 100644 --- a/xmake.lua +++ b/xmake.lua @@ -4,7 +4,9 @@ set_languages("c++23") add_repositories("mcpplibs-index https://github.com/mcpplibs/mcpplibs-index.git") -add_requires("llmapi 0.0.2") +add_requires("llmapi 0.2.5") +add_requires("mcpplibs-tinyhttps 0.2.2") +add_requires("mbedtls v3.6.1") add_requires("cmdline 0.0.2") add_requires("ftxui 6.1.9") @@ -14,13 +16,12 @@ target("d2x") add_files("src/main.cpp") -- add common module interface units add_files("src/**.cppm") - add_packages("ftxui", "llmapi", "cmdline") + add_packages("ftxui", "llmapi", "mcpplibs-tinyhttps", "mbedtls", "cmdline") set_policy("build.c++.modules", true) - + -- platform specific settings if is_plat("macosx") then set_toolchains("llvm") elseif is_plat("linux") then add_ldflags("-static", {force = true}) end -