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.
108 lines
3.8 KiB
Bash
Executable File
108 lines
3.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Cross-build the engine for Android: libcstcore.a (what the APK embeds) plus
|
|
# cst-agent and tests/test_embed, which run straight from /data/local/tmp.
|
|
# No TUI (no ncurses on Android) and no WebUI (the phone app talks to the
|
|
# engine in-process; the stub compiles instead of the HTTP server).
|
|
#
|
|
# scripts/build_android.sh [arm64-v8a|x86_64] [--push] [--run] [--run-tests]
|
|
#
|
|
# --push copy the binaries to /data/local/tmp
|
|
# --run also smoke-test there: cst-agent --version, test_embed
|
|
# --run-tests build and run the whole tests/ suite on the device
|
|
#
|
|
# Needs ANDROID_NDK_HOME (see build_third_party_android.sh) and the deps from
|
|
# scripts/build_third_party_android.sh ABI all.
|
|
set -euo pipefail
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
ABI="arm64-v8a"
|
|
DO_PUSH=0
|
|
DO_RUN=0
|
|
DO_TESTS=0
|
|
for a in "$@"; do
|
|
case "$a" in
|
|
arm64-v8a | x86_64) ABI="$a" ;;
|
|
--push) DO_PUSH=1 ;;
|
|
--run) DO_PUSH=1; DO_RUN=1 ;;
|
|
--run-tests) DO_PUSH=1; DO_TESTS=1 ;;
|
|
*) echo "usage: $0 [arm64-v8a|x86_64] [--push] [--run|--run-tests]" >&2; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
API_LEVEL="${API_LEVEL:-24}"
|
|
PREFIX="$ROOT/third_party/prefix-android-$ABI"
|
|
BUILD="$ROOT/build-android-$ABI"
|
|
JOBS="${JOBS:-$(nproc 2>/dev/null || echo 4)}"
|
|
|
|
NDK="${ANDROID_NDK_HOME:-${ANDROID_NDK_ROOT:-}}"
|
|
if [[ -z "$NDK" || ! -f "$NDK/build/cmake/android.toolchain.cmake" ]]; then
|
|
echo "set ANDROID_NDK_HOME to an NDK (see build_third_party_android.sh)" >&2
|
|
exit 1
|
|
fi
|
|
if [[ ! -f "$PREFIX/lib/libcurl.a" ]]; then
|
|
echo "missing $PREFIX/lib/libcurl.a -- run:" >&2
|
|
echo " scripts/build_third_party_android.sh $ABI all" >&2
|
|
exit 1
|
|
fi
|
|
|
|
cmake -S "$ROOT" -B "$BUILD" -G Ninja \
|
|
-DCMAKE_TOOLCHAIN_FILE="$NDK/build/cmake/android.toolchain.cmake" \
|
|
-DANDROID_ABI="$ABI" -DANDROID_PLATFORM="android-$API_LEVEL" \
|
|
-DANDROID_NDK="$NDK" \
|
|
-DCMAKE_BUILD_TYPE=Release \
|
|
-DCMAKE_PREFIX_PATH="$PREFIX" \
|
|
-DCURL_INCLUDE_DIR="$PREFIX/include" -DCURL_LIBRARY="$PREFIX/lib/libcurl.a" \
|
|
-DCMAKE_EXE_LINKER_FLAGS="-L$PREFIX/lib" \
|
|
-DCST_BUILD_TUI=OFF -DCST_BUILD_WEBUI=OFF -DCST_BUILD_APP=OFF \
|
|
-DCST_BUNDLE_BUSYBOX=OFF
|
|
if [[ "$DO_TESTS" == 1 ]]; then
|
|
cmake --build "$BUILD" -j"$JOBS" # every test target
|
|
else
|
|
cmake --build "$BUILD" -j"$JOBS" --target cst-agent test_embed
|
|
fi
|
|
echo "built in $BUILD"
|
|
[[ "$DO_PUSH" == 1 ]] || exit 0
|
|
|
|
ADB="${ADB:-adb}"
|
|
command -v "$ADB" >/dev/null || { echo "adb not found (nix-shell -p android-tools)" >&2; exit 1; }
|
|
DEV=/data/local/tmp
|
|
NAMES=(cst-agent test_embed)
|
|
FILES=("$BUILD/cst-agent" "$BUILD/test_embed")
|
|
TESTS=()
|
|
if [[ "$DO_TESTS" == 1 ]]; then
|
|
mapfile -t TESTS < <(find "$BUILD" -maxdepth 1 -type f -name 'test_*' -perm -u+x | sort)
|
|
for t in "${TESTS[@]}"; do
|
|
NAMES+=("${t##*/}")
|
|
FILES+=("$t")
|
|
done
|
|
fi
|
|
"$ADB" push "${FILES[@]}" "$DEV/" >/dev/null
|
|
"$ADB" shell chmod 755 "${NAMES[@]/#/$DEV/}"
|
|
echo "pushed ${#NAMES[@]} binaries to $DEV"
|
|
[[ "$DO_PUSH" == 1 && ( "$DO_RUN" == 1 || "$DO_TESTS" == 1 ) ]] || exit 0
|
|
|
|
echo "--- $DEV/cst-agent --version"
|
|
"$ADB" shell "$DEV/cst-agent --version"
|
|
if [[ "$DO_TESTS" == 0 ]]; then
|
|
echo "--- $DEV/test_embed"
|
|
"$ADB" shell "cd $DEV && ./test_embed"
|
|
exit 0
|
|
fi
|
|
|
|
# The suite runs on the device as the shell user; tests that want a real
|
|
# /bin/sh, a host fixture tree or a Linux-specific sandbox report their own
|
|
# failure, which is the point of running them here.
|
|
# The sandbox test builds its scratch trees under $PWD/tests, the same way
|
|
# ctest runs it from the repo root.
|
|
"$ADB" shell mkdir -p "$DEV/tests"
|
|
pass=0; fail=0; skipped=()
|
|
for t in "${TESTS[@]}"; do
|
|
name="${t##*/}"
|
|
if "$ADB" shell "cd $DEV && ./$name" >/dev/null 2>&1; then
|
|
pass=$((pass + 1)); echo "ok $name"
|
|
else
|
|
fail=$((fail + 1)); skipped+=("$name"); echo "FAIL $name"
|
|
fi
|
|
done
|
|
echo "--- $pass passed, $fail failed"
|
|
[[ "$fail" == 0 ]] || { printf 'failed: %s\n' "${skipped[*]}"; exit 1; }
|