Skip to content

Commit c3c9d05

Browse files
authored
feat: upgrade to mcpp 0.0.13 + llmapi 0.2.6 + mcpp build support (#25)
- 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
1 parent db7fa99 commit c3c9d05

15 files changed

Lines changed: 85 additions & 66 deletions

File tree

.github/workflows/ci.yml

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,46 @@ on:
44
push:
55
branches: [main]
66
pull_request:
7-
branches: [main]
8-
9-
env:
10-
XLINGS_VERSION: v0.4.0
117

128
jobs:
13-
build-linux:
14-
runs-on: ubuntu-24.04
9+
build-linux-mcpp:
10+
name: build (linux x86_64, mcpp)
11+
runs-on: ubuntu-latest
1512
steps:
16-
- name: Checkout code
17-
uses: actions/checkout@v4
18-
19-
- name: Install system deps
20-
run: |
21-
sudo apt-get update -qq
22-
sudo apt-get install -y curl git build-essential
13+
- uses: actions/checkout@v4
2314

24-
- name: Install Xlings
15+
- name: Install xlings
2516
env:
26-
XLINGS_NON_INTERACTIVE: 1
17+
XLINGS_VERSION: 0.4.31
2718
run: |
28-
VERSION_NUM="${XLINGS_VERSION#v}"
29-
TARBALL="xlings-${VERSION_NUM}-linux-x86_64.tar.gz"
30-
curl -fSL -o "$RUNNER_TEMP/$TARBALL" "https://github.com/d2learn/xlings/releases/download/${XLINGS_VERSION}/${TARBALL}"
31-
tar -xzf "$RUNNER_TEMP/$TARBALL" -C "$RUNNER_TEMP"
32-
EXTRACT_DIR=$(find "$RUNNER_TEMP" -maxdepth 1 -type d -name "xlings-*" | head -1)
33-
chmod +x "$EXTRACT_DIR/bin/xlings"
34-
"$EXTRACT_DIR/bin/xlings" self install
35-
echo "PATH=$HOME/.xlings/subos/current/bin:$PATH" >> "$GITHUB_ENV"
19+
tarball="xlings-${XLINGS_VERSION}-linux-x86_64.tar.gz"
20+
curl -fsSL -o "/tmp/${tarball}" \
21+
"https://github.com/d2learn/xlings/releases/download/v${XLINGS_VERSION}/${tarball}"
22+
tar -xzf "/tmp/${tarball}" -C /tmp
23+
"/tmp/xlings-${XLINGS_VERSION}-linux-x86_64/subos/default/bin/xlings" self install
24+
echo "$HOME/.xlings/subos/current/bin" >> "$GITHUB_PATH"
3625
37-
- name: Install Project Dependencies via Xlings
38-
run: |
39-
xlings install
26+
- name: Refresh package index
27+
run: xlings update
4028

29+
- name: Install workspace tools (.xlings.json → mcpp 0.0.13)
30+
run: xlings install -y
4131

42-
- name: Build with xmake
43-
run: |
44-
xmake f -m release -vv -y
45-
xmake -j$(nproc)
32+
- name: Cache mcpp sandbox
33+
uses: actions/cache@v4
34+
with:
35+
path: ~/.xlings/data/xpkgs/xim-x-mcpp/0.0.13/registry
36+
key: mcpp-sandbox-${{ runner.os }}-mcpp0.0.13
37+
38+
- name: Build with mcpp
39+
run: mcpp build
4640

4741
- name: Verify d2x
4842
run: |
49-
./build/linux/x86_64/release/d2x --version
50-
./build/linux/x86_64/release/d2x new hello
43+
binary=$(find target -name d2x -type f | head -1)
44+
test -n "$binary" || { echo "d2x binary not found"; find target -type f | head -20; exit 1; }
45+
chmod +x "$binary"
46+
"$binary" --version
5147
5248
build-macos:
5349
runs-on: macos-15
@@ -58,10 +54,10 @@ jobs:
5854
- name: Install Xlings
5955
env:
6056
XLINGS_NON_INTERACTIVE: 1
57+
XLINGS_VERSION: 0.4.31
6158
run: |
62-
VERSION_NUM="${XLINGS_VERSION#v}"
63-
TARBALL="xlings-${VERSION_NUM}-macosx-arm64.tar.gz"
64-
curl -fSL -o "$RUNNER_TEMP/$TARBALL" "https://github.com/d2learn/xlings/releases/download/${XLINGS_VERSION}/${TARBALL}"
59+
TARBALL="xlings-${XLINGS_VERSION}-macosx-arm64.tar.gz"
60+
curl -fSL -o "$RUNNER_TEMP/$TARBALL" "https://github.com/d2learn/xlings/releases/download/v${XLINGS_VERSION}/${TARBALL}"
6561
tar -xzf "$RUNNER_TEMP/$TARBALL" -C "$RUNNER_TEMP"
6662
EXTRACT_DIR=$(find "$RUNNER_TEMP" -maxdepth 1 -type d -name "xlings-*" | head -1)
6763
xattr -dr com.apple.quarantine "$EXTRACT_DIR" 2>/dev/null || true
@@ -74,16 +70,20 @@ jobs:
7470
xlings install
7571
clang --version
7672
73+
- name: Configure xmake
74+
run: |
75+
LLVM_ROOT="$HOME/.xlings/data/xpkgs/xim-x-llvm"
76+
LLVM_SDK=$(find "$LLVM_ROOT" -mindepth 1 -maxdepth 1 -type d | sort -V | tail -1)
77+
test -d "$LLVM_SDK"
78+
"$LLVM_SDK/bin/clang++" --version
79+
xmake f -m release --toolchain=llvm --sdk="$LLVM_SDK" -y -vvD
7780
7881
- name: Build with xmake
79-
run: |
80-
xmake f -m release --toolchain=llvm -vv -y
81-
xmake -j$(nproc)
82+
run: xmake -a -j"$(sysctl -n hw.logicalcpu)"
8283

8384
- name: Verify d2x
8485
run: |
8586
./build/macosx/arm64/release/d2x --version
86-
./build/macosx/arm64/release/d2x new hello
8787
8888
build-windows:
8989
runs-on: windows-latest
@@ -104,4 +104,3 @@ jobs:
104104
- name: Verify d2x
105105
run: |
106106
build\windows\x64\release\d2x.exe --version
107-
build\windows\x64\release\d2x.exe new hello

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.xlings
22
.xmake
33
build
4-
d2x.zip
4+
target
5+
d2x.zip

.xlings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"workspace": {
3+
"mcpp": { "linux": "0.0.13" },
34
"xmake": "3.0.7",
45
"gcc": { "linux": "15.1.0" },
5-
"openssl": { "linux": "3.1.5" },
66
"llvm": { "macosx": "20" }
77
}
8-
}
8+
}

mcpp.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "d2x"
3+
version = "0.1.2"
4+
description = "AI-powered development assistant for C++ projects"
5+
license = "Apache-2.0"
6+
repo = "https://github.com/d2learn/d2x"
7+
8+
[targets.d2x]
9+
kind = "bin"
10+
main = "src/main.cpp"
11+
12+
[dependencies.compat]
13+
ftxui = "6.1.9"
14+
15+
[dependencies.mcpplibs]
16+
cmdline = "0.0.2"
17+
llmapi = "0.2.6"

src/assistant.cppm

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ constexpr std::string_view user_prompt_template = R"(
5252

5353

5454
export class Assistant {
55-
std::optional<llmapi::Client> mLLMClient;
55+
std::optional<llmapi::Client<llmapi::OpenAI>> mLLMClient;
5656

5757
// 流式请求状态
5858
mutable std::mutex mAnswerMutex;
@@ -74,11 +74,13 @@ public:
7474
mEnable(Config::is_llm_enabled())
7575
{
7676
if (mEnable) {
77-
mLLMClient.emplace(Config::api_key(), Config::api_url());
78-
log::info("Initialized Assistant with API URL: {}", Config::api_url());
79-
80-
mLLMClient->model(Config::model());
81-
log::info("Using model: {}", Config::model());
77+
mLLMClient.emplace(llmapi::Config{
78+
.apiKey = Config::api_key(),
79+
.baseUrl = Config::api_url(),
80+
.model = Config::model()
81+
});
82+
log::info("Initialized Assistant with API URL: {}, model: {}",
83+
Config::api_url(), Config::model());
8284
} else {
8385
log::info("Assistant is disabled (no LLM API key configured).");
8486
}
@@ -190,8 +192,7 @@ private:
190192
ui::update_ai_tips(mCurrentAnswer);
191193
};
192194

193-
mLLMClient->user(mCurrentQuestion)
194-
.request(capture_stream);
195+
mLLMClient->chat_stream(mCurrentQuestion, capture_stream);
195196
} catch (...) {
196197
// 忽略异常,保留已接收的部分答案
197198
log::warning("Assistant request encountered an error.");

src/platform/linux.cppm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ module;
44
#include <cstdlib>
55

66
export module d2x.platform:linux;
7+
import std;
78

89
#if defined(__linux__)
910

10-
import std;
1111

1212
namespace d2x {
1313
namespace platform_impl {

src/platform/macos.cppm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ module;
44
#include <cstdlib>
55

66
export module d2x.platform:macos;
7+
import std;
78

89
#if defined(__APPLE__)
910

10-
import std;
1111

1212
namespace d2x {
1313
namespace platform_impl {

src/platform/windows.cppm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ module;
44
#include <cstdlib>
55

66
export module d2x.platform:windows;
7+
import std;
78

89
#if defined(_WIN32)
910

10-
import std;
1111

1212
namespace d2x {
1313
namespace platform_impl {

src/ui/plugin/print.cppm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export module d2x.ui.plugin.print;
77
import std;
88

99
import d2x.ui.interface;
10-
import :checker_page;
11-
import :help_page;
10+
export import :checker_page;
11+
export import :help_page;
1212

1313
namespace d2x {
1414

src/ui/plugin/print_backend/checker_page.cppm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module d2x.ui.plugin.print:checker_page;
1+
export module d2x.ui.plugin.print:checker_page;
22

33
import std;
44

0 commit comments

Comments
 (0)