The engine can be embedded now instead of only driven from a terminal: the same objects link into a Qt front end (app/) that owns a cst_agent_t inside its own process -- no port, no token, no second process -- and that front end now runs on the desktop and, engine-side, on the phone. Capability metadata (include/cst_tools.h, src/tools/registry.c): - cst_tool_def_t gains perm_name, platforms and available (a probe that returns a reason), so a permission is addressable by name and a tool can say why it cannot run here. - cst_platform_name(), cst_tool_platform_ok(), cst_tool_available(), cst_tool_meta_reload(), cst_tool_perm_name() and CST_PLAT_DESKTOP[]. - cst_tool_register() may take over a built-in name that is not runnable on this platform, so a front end replaces it with its own implementation. - the registry entries carry their class (delete_file -> "delete"), the desktop clipboard tools carry a clipboard probe; find/active/run gate on it. - /api/settings.tools[] exposes perm_name, platforms, available, why and the declared parameters. Engine as a library (Makefile, CMakeLists.txt): - libcstcore.a from the CORE_OBJ set, and a CMake cstcore target shared by the CLI and by app/ (-DCST_BUILD_APP=ON): the engine is compiled once. - Android branch for the vendored sashidown: a per-ABI archive built with the NDK's aarch64-linux-android24-clang wrapper, because CMake's compiler is plain clang and keeps --target/--sysroot in its own variables. Qt front end (app/, new): - AgentCore wraps one cst_agent_t: turns run on a worker thread, every cst_agent_hooks_t callback becomes a Qt signal, and the two hooks that need an answer (on_permission, on_ask_user) block the worker until the GUI replies; mode, approval and plan mode go through the engine's config. - ToolProvider hands the front end's tools to the engine (owner "app:*"); the Linux one is notification_send with a probe for notify-send/D-Bus. - Main.qml: transcript, tool blocks, consent dialog (Deny/Once/Always -> CST_PERM_*), ask_user, mode switch, Esc to cancel; --selftest stays headless and runs the embedding checks without QML. Android (scripts/, docs/android.md, new): - scripts/build_third_party_android.sh builds static mbedTLS + libcurl for an ABI (CA path /system/etc/security/cacerts); build_android.sh builds cst-agent, libcstcore.a and the test binaries for the phone, can push them and run the whole suite there. - sandbox_exec.c keeps the plain exec path on Android: the seccomp supervisor compiled in and the probe reported "seccomp", but writes outside the workspace were not denied on the device -- claiming a sandbox that does not hold is worse than reporting none. - tests/test_diff.c compares layouts only against real GNU diffutils: toybox's diff prints the same hunk header with its own hunk/context rules. Tests: test_tool_meta (metadata, platform gate, probe reasons, takeover of a built-in name) and test_embed (in-process embedding contract) are new; the existing registry/llm_body assertions now follow availability. 38 test binaries pass on the host, 36/36 on arm64-v8a Android 16, cst-app-selftest passes in both the standalone app/ build and the repo build. Version 0.8.7.
103 lines
4.2 KiB
CMake
103 lines
4.2 KiB
CMake
cmake_minimum_required(VERSION 3.16)
|
|
project(cst-agent-app LANGUAGES C CXX VERSION 0.1.0)
|
|
|
|
# The Qt front end (app/) embeds the C engine in-process: it links libcstcore
|
|
# and never opens a port. Two targets:
|
|
#
|
|
# cst-app-selftest pure C smoke test of the embedding path (no Qt), so the
|
|
# C side is still guarded on machines without Qt Quick
|
|
# cst-agent-app the GUI (Qt 6 Quick + QML), built when the Qt modules
|
|
# are there
|
|
#
|
|
# Standalone build (builds the engine from ../ too):
|
|
# cmake -S app -B build-app -DCMAKE_BUILD_TYPE=Debug && cmake --build build-app -j
|
|
# Inside the repo build (the parent defines the cstcore target, shared with the CLI):
|
|
# cmake -B build -DCST_BUILD_APP=ON && cmake --build build --target cst-agent-app
|
|
#
|
|
# Extra QML import paths, e.g. a Kirigami installed away from the Qt prefix:
|
|
# -DCST_APP_QML_IMPORT=... (added to QML2_IMPORT_PATH / the app's runtime)
|
|
|
|
option(CST_APP_GUI "build the Qt GUI (needs Qt6 Quick, Qml, QuickControls2)" ON)
|
|
option(CST_APP_SELFTEST "build the C embedding smoke test" ON)
|
|
|
|
# --- the engine ----------------------------------------------------------
|
|
# Used as a subproject (../CMakeLists.txt already defined cstcore, engine
|
|
# compiled once for CLI and app) or built here from the sources next door.
|
|
if(NOT TARGET cstcore)
|
|
set(CST_APP_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
|
include_directories("${CST_APP_ROOT}/include" "${CST_APP_ROOT}/vendor/cjson")
|
|
file(GLOB CST_APP_CORE_SRC
|
|
"${CST_APP_ROOT}/src/*.c"
|
|
"${CST_APP_ROOT}/src/tools/*.c"
|
|
"${CST_APP_ROOT}/vendor/cjson/cJSON.c")
|
|
list(REMOVE_ITEM CST_APP_CORE_SRC
|
|
"${CST_APP_ROOT}/src/main.c"
|
|
"${CST_APP_ROOT}/src/tui.c"
|
|
"${CST_APP_ROOT}/src/tui_stub.c"
|
|
"${CST_APP_ROOT}/src/textsel.c")
|
|
# The HTTP front end is not part of an in-process app: no server, no port.
|
|
list(REMOVE_ITEM CST_APP_CORE_SRC
|
|
"${CST_APP_ROOT}/src/net.c"
|
|
"${CST_APP_ROOT}/src/http_srv.c"
|
|
"${CST_APP_ROOT}/src/webui.c"
|
|
"${CST_APP_ROOT}/src/web_md.c")
|
|
if(EXISTS "${CST_APP_ROOT}/.gen/models_builtin.inc")
|
|
include_directories("${CST_APP_ROOT}/.gen")
|
|
endif()
|
|
add_library(cstcore STATIC ${CST_APP_CORE_SRC})
|
|
target_compile_definitions(cstcore PRIVATE CST_NO_WEBUI=1)
|
|
find_package(CURL REQUIRED)
|
|
find_package(Threads REQUIRED)
|
|
target_link_libraries(cstcore PUBLIC ${CURL_LIBRARIES} Threads::Threads m)
|
|
message(STATUS "app: building the engine from ${CST_APP_ROOT}")
|
|
else()
|
|
message(STATUS "app: linking the cstcore target of the parent build")
|
|
endif()
|
|
|
|
# --- the C smoke test ----------------------------------------------------
|
|
if(CST_APP_SELFTEST)
|
|
add_executable(cst-app-selftest tools/selftest.c)
|
|
target_link_libraries(cst-app-selftest PRIVATE cstcore)
|
|
enable_testing()
|
|
add_test(NAME cst-app-selftest COMMAND cst-app-selftest)
|
|
endif()
|
|
|
|
# --- the GUI -------------------------------------------------------------
|
|
if(CST_APP_GUI)
|
|
find_package(Qt6 6.4 COMPONENTS Core Gui Qml Quick QuickControls2 QUIET)
|
|
if(NOT Qt6_FOUND)
|
|
message(WARNING
|
|
"app: Qt 6 Quick/Qml not found, skipping cst-agent-app "
|
|
"(the C selftest still builds; install e.g. qt6.qtdeclarative / "
|
|
"qt6.qtquickcontrols2 and reconfigure)")
|
|
else()
|
|
qt_standard_project_setup()
|
|
# Qt 6.5+ policies: keep the module resource at :/qt/qml/<URI>/ (what
|
|
# main.cpp loads) and let CMake generate the qmldir of qml/ for us.
|
|
qt_policy(SET QTP0001 NEW)
|
|
qt_policy(SET QTP0004 NEW)
|
|
qt_add_executable(cst-agent-app
|
|
src/main.cpp
|
|
src/core/AgentCore.cpp
|
|
src/core/ToolProvider.cpp
|
|
src/platform/linux/NotifyTool.cpp)
|
|
target_include_directories(cst-agent-app PRIVATE
|
|
src "${CMAKE_CURRENT_SOURCE_DIR}/../include")
|
|
target_compile_definitions(cst-agent-app PRIVATE CST_APP_VERSION="${PROJECT_VERSION}")
|
|
if(CST_APP_QML_IMPORT)
|
|
target_compile_definitions(cst-agent-app PRIVATE
|
|
CST_APP_QML_IMPORT="${CST_APP_QML_IMPORT}")
|
|
endif()
|
|
target_link_libraries(cst-agent-app PRIVATE
|
|
Qt6::Core Qt6::Gui Qt6::Qml Qt6::Quick Qt6::QuickControls2 cstcore)
|
|
if(WIN32)
|
|
set_target_properties(cst-agent-app PROPERTIES WIN32_EXECUTABLE TRUE)
|
|
endif()
|
|
|
|
qt_add_qml_module(cst-agent-app
|
|
URI CstAgent
|
|
VERSION 1.0
|
|
QML_FILES qml/Main.qml)
|
|
endif()
|
|
endif()
|