Files
CST-agent/app/qml/Main.qml
T
WHC 5ba215b36c v0.8.7: tool capability metadata, in-process engine, Qt app, Android engine
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.
2026-10-11 11:42:04 +08:00

230 lines
7.9 KiB
QML

// The app window: chat on the left, tool runs and consent on top of it.
//
// Qt Quick Controls only, laid out the way Kirigami expects (single column,
// cards, drawer for navigation) so that swapping `import QtQuick.Controls`
// for `import org.kde.kirigami as Kirigami` and Page/Card wrappers is a QML
// change, not a rewrite.
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
ApplicationWindow {
id: win
width: 980
height: 720
visible: true
title: "CST-agent — " + (agent.workspace.length ? agent.workspace : "no workspace")
ListModel { id: transcript }
header: ToolBar {
RowLayout {
anchors.fill: parent
Label {
text: agent.workspace.length ? agent.workspace : "(no workspace)"
elide: Text.ElideMiddle
Layout.fillWidth: true
}
BusyIndicator {
running: agent.running
visible: agent.running
implicitWidth: 24
implicitHeight: 24
}
ComboBox {
id: modeBox
model: ["coding", "general"]
currentIndex: agent.mode === "general" ? 1 : 0
onActivated: agent.setMode(model[currentIndex])
}
}
}
// ---- consent: the engine's on_permission hook waits for this ----
Dialog {
id: consent
anchors.centerIn: parent
width: Math.min(720, win.width - 40)
modal: true
property string tool: ""
property string detail: ""
property string preview: ""
title: "Allow " + tool + "?"
contentItem: ColumnLayout {
Label { text: consent.detail; wrapMode: Text.Wrap; Layout.fillWidth: true }
ScrollView {
Layout.fillWidth: true
Layout.preferredHeight: Math.min(300, previewText.implicitHeight + 16)
visible: consent.preview.length > 0
TextArea {
id: previewText
text: consent.preview
readOnly: true
font.family: "monospace"
wrapMode: TextArea.NoWrap
}
}
}
footer: DialogButtonBox {
Button { text: "Deny"; DialogButtonBox.buttonRole: DialogButtonBox.RejectRole }
Button { text: "Once"; DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole }
Button { text: "Always"; DialogButtonBox.buttonRole: DialogButtonBox.ActionRole }
onRejected: { agent.answerPermission(0); consent.close() }
onAccepted: { agent.answerPermission(1); consent.close() }
onClicked: function (button) {
if (button.text === "Always") { agent.answerPermission(2); consent.close() }
}
}
}
// ---- ask_user ----
Dialog {
id: question
anchors.centerIn: parent
width: Math.min(600, win.width - 40)
modal: true
property string text: ""
property string options: ""
title: "The agent asks"
contentItem: ColumnLayout {
Label { text: question.text; wrapMode: Text.Wrap; Layout.fillWidth: true }
Label {
visible: question.options.length > 0
text: question.options
wrapMode: Text.Wrap
Layout.fillWidth: true
opacity: 0.7
}
TextField { id: answerField; Layout.fillWidth: true; placeholderText: "your answer" }
}
footer: DialogButtonBox {
Button { text: "Send"; DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole }
onAccepted: { agent.answerQuestion(answerField.text); question.close() }
}
}
ColumnLayout {
anchors.fill: parent
anchors.margins: 12
spacing: 8
ListView {
id: chat
Layout.fillWidth: true
Layout.fillHeight: true
model: transcript
clip: true
spacing: 8
delegate: Frame {
width: chat.width
background: Rectangle {
color: model.role === "user" ? "#2b579a22" : "#00000000"
border.color: "#88888833"
radius: 6
}
ColumnLayout {
width: parent.width
spacing: 2
Label {
text: model.role === "user" ? "You" : "Agent"
font.bold: true
opacity: 0.7
}
TextEdit {
text: model.text
readOnly: true
wrapMode: TextEdit.Wrap
selectByMouse: true
Layout.fillWidth: true
}
}
}
onCountChanged: positionViewAtEnd()
}
RowLayout {
Layout.fillWidth: true
TextArea {
id: composer
Layout.fillWidth: true
Layout.preferredHeight: 90
placeholderText: agent.running ? "… working (Esc cancels)"
: "Ask something (Enter sends, Shift+Enter for a new line)"
wrapMode: TextArea.Wrap
enabled: !agent.running
Keys.onPressed: function (ev) {
if (ev.key === Qt.Key_Return && !(ev.modifiers & Qt.ShiftModifier)) {
sendButton.clicked()
ev.accepted = true
}
}
}
ColumnLayout {
Button {
id: sendButton
text: "Send"
enabled: !agent.running && composer.text.trim().length > 0
onClicked: {
transcript.append({ role: "user", text: composer.text })
transcript.append({ role: "agent", text: "" })
agent.send(composer.text)
composer.text = ""
}
}
Button {
text: "Stop"
enabled: agent.running
onClicked: agent.cancel()
}
}
}
}
Shortcut { sequence: "Escape"; onActivated: agent.cancel() }
// ---- engine -> UI ----
function appendToAgent(text) {
if (transcript.count === 0)
transcript.append({ role: "agent", text: "" })
const last = transcript.count - 1
transcript.setProperty(last, "text", transcript.get(last).text + text)
}
Connections {
target: agent
function onAssistantDelta(text) { appendToAgent(text) }
function onStatusChanged(text) {
transcript.append({ role: "agent", text: "· " + text })
}
function onToolEvent(phase, name, detail) {
transcript.append({
role: "agent",
text: "[" + name + " " + phase + (detail.length ? ": " + detail : "") + "]"
})
}
function onToolResult(name, exitCode, output) {
transcript.append({
role: "agent",
text: "[" + name + " exit=" + exitCode + "]\n" + output
})
}
function onPermissionRequested(tool, detail, preview) {
consent.tool = tool
consent.detail = detail
consent.preview = preview
consent.open()
}
function onQuestionAsked(text, options) {
question.text = text
question.options = options
answerField.text = ""
question.open()
}
function onTurnFinished(rc, err) {
if (err.length)
transcript.append({ role: "agent", text: "error: " + err })
}
}
}