Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 39 additions & 40 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -104,4 +104,3 @@ jobs:
- name: Verify d2x
run: |
build\windows\x64\release\d2x.exe --version
build\windows\x64\release\d2x.exe new hello
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.xlings
.xmake
build
d2x.zip
target
d2x.zip
4 changes: 2 additions & 2 deletions .xlings.json
Original file line number Diff line number Diff line change
@@ -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" }
}
}
}
17 changes: 17 additions & 0 deletions mcpp.toml
Original file line number Diff line number Diff line change
@@ -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"
17 changes: 9 additions & 8 deletions src/assistant.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ constexpr std::string_view user_prompt_template = R"(


export class Assistant {
std::optional<llmapi::Client> mLLMClient;
std::optional<llmapi::Client<llmapi::OpenAI>> mLLMClient;

// 流式请求状态
mutable std::mutex mAnswerMutex;
Expand All @@ -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).");
}
Expand Down Expand Up @@ -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.");
Expand Down
2 changes: 1 addition & 1 deletion src/platform/linux.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module;
#include <cstdlib>

export module d2x.platform:linux;
import std;

#if defined(__linux__)

import std;

namespace d2x {
namespace platform_impl {
Expand Down
2 changes: 1 addition & 1 deletion src/platform/macos.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module;
#include <cstdlib>

export module d2x.platform:macos;
import std;

#if defined(__APPLE__)

import std;

namespace d2x {
namespace platform_impl {
Expand Down
2 changes: 1 addition & 1 deletion src/platform/windows.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module;
#include <cstdlib>

export module d2x.platform:windows;
import std;

#if defined(_WIN32)

import std;

namespace d2x {
namespace platform_impl {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/plugin/print.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
2 changes: 1 addition & 1 deletion src/ui/plugin/print_backend/checker_page.cppm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module d2x.ui.plugin.print:checker_page;
export module d2x.ui.plugin.print:checker_page;

import std;

Expand Down
2 changes: 1 addition & 1 deletion src/ui/plugin/print_backend/help_page.cppm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module d2x.ui.plugin.print:help_page;
export module d2x.ui.plugin.print:help_page;

import std;

Expand Down
4 changes: 2 additions & 2 deletions src/ui/plugin/tui.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
2 changes: 1 addition & 1 deletion src/ui/plugin/tui_backend/checker_page.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module;
#include <ftxui/screen/screen.hpp>
#include <ftxui/screen/terminal.hpp>

module d2x.ui.plugin.tui:checker_page;
export module d2x.ui.plugin.tui:checker_page;

import std;
import d2x.ui.interface;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/plugin/tui_backend/help_page.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module;
#include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp>

module d2x.ui.plugin.tui:help_page;
export module d2x.ui.plugin.tui:help_page;

import std;
import d2x.ui.interface;
Expand Down
9 changes: 5 additions & 4 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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

Loading