phoebus_os/installer/live/desktop/phoebus-assistant/shell.qml
2026-10-03 09:32:16 -07:00

1221 lines
55 KiB
Bash

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Quickshell
import Quickshell.Io
import "Common"
ShellRoot {
id: shell
// Keep the broker and conversation alive while the scratchpad is hidden.
property bool panelOpen: true
property string currentTab: Quickshell.env("PHOEBUS_ASSISTANT_START_TAB") === "updates" ? "updates" : "assistant"
property var conversation: []
signal activityEvent(int messageIndex, int position, var entry)
property bool busy: false
property bool assistantPending: false
property int assistantElapsedSeconds: 0
property string statusText: "Ready"
property var activeAlerts: []
property var updateOverview: null
property string updateError: ""
property var preferences: null
// Truthful model connection: never "Connected" solely because the bridge
// process started. `aiConfigured` follows the handshake's ai_configured.
property bool aiConfigured: false
property string aiBackend: "direct"
property string aiError: ""
readonly property bool assistantConnected: AssistantBridge.ready && shell.aiConfigured
readonly property bool bridgeConnecting: AssistantBridge.handshake === null && !AssistantBridge.crashed
// Theme: dark by default (charcoal/warm-white/amber), light available,
// selection persists through preferences when the backend keeps it.
property string themeMode: "dark"
onThemeModeChanged: Theme.themeMode = shell.themeMode
Timer {
interval: 1000
repeat: true
running: shell.assistantPending
onTriggered: shell.assistantElapsedSeconds += 1
}
Component.onCompleted: {
Theme.themeMode = shell.themeMode;
AssistantBridge.start();
}
// The process starts asynchronously. Apply its handshake only when it
// arrives, then load the user's state; startup calls otherwise report a
// false offline error and leave the assistant disabled for the session.
Connections {
target: AssistantBridge
function onHandshakeReady() {
const result = AssistantBridge.handshake || {};
shell.aiConfigured = !!result.ai_configured;
shell.aiBackend = result.ai_backend || "direct";
shell.aiError = "";
shell.activeAlerts = result.active_alerts || [];
if (shell.currentTab === "updates")
shell.checkUpdates();
AssistantBridge.getPreferences(reply => {
if (reply.ok && reply.result) {
shell.preferences = reply.result;
if (reply.result.theme)
shell.themeMode = reply.result.theme === "light" ? "light" : "dark";
}
});
}
}
onCurrentTabChanged: {
if (currentTab === "updates" && !shell.updateOverview && !shell.busy) {
checkUpdates();
}
if (currentTab === "alerts") {
AssistantBridge.getProactiveAlerts(reply => {
if (reply.ok && reply.result)
shell.activeAlerts = reply.result.alerts || [];
});
}
}
function refreshStatus() {
AssistantBridge.refreshHandshake(reply => {
if (!reply.ok) {
shell.aiConfigured = false;
shell.aiError = reply.error || "The assistant broker did not answer.";
}
});
}
function toggleTheme() {
shell.themeMode = shell.themeMode === "dark" ? "light" : "dark";
Theme.themeMode = shell.themeMode;
// Persist the selection; the backend keeps unknown preference keys
// alongside the profile so a future session restores the theme.
const prefs = Object.assign({}, shell.preferences || {}, { theme: shell.themeMode });
shell.preferences = prefs;
AssistantBridge.setPreferences(prefs, () => {});
}
function checkUpdates() {
if (!AssistantBridge.ready)
return;
shell.busy = true;
shell.statusText = "Checking for updates across package sources...";
AssistantBridge.getUpdates(reply => {
if (!shell.assistantPending) {
shell.busy = false;
shell.statusText = "Ready";
}
if (reply.ok && reply.result) {
shell.updateOverview = reply.result;
shell.updateError = "";
} else {
shell.updateError = reply.error || "Could not check for updates.";
}
});
}
function addMessage(sender, text, data) {
const item = {
sender: sender,
text: text,
data: data || null,
time: new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
};
const list = shell.conversation.slice();
list.push(item);
shell.conversation = list;
return list.length - 1;
}
// Replace one message in place so its original card updates after an
// approval, completion or failure instead of appending a new message.
function updateMessage(index, dataPatch) {
const list = shell.conversation.slice();
if (index < 0 || index >= list.length)
return;
const current = list[index];
const next = Object.assign({}, current);
next.data = Object.assign({}, current.data || {}, dataPatch || {});
list[index] = next;
shell.conversation = list;
}
function finishMessage(index, text, data) {
const list = shell.conversation.slice();
if (index < 0 || index >= list.length)
return;
list[index] = Object.assign({}, list[index], { text: text, data: data });
shell.conversation = list;
}
function recordActivity(index, progress) {
const item = shell.conversation[index];
if (!item || !progress || !progress.label)
return;
const activity = (item.data && item.data.activity ? item.data.activity : []).slice();
const state = progress.state || "started";
let position = -1;
if (state !== "started") {
for (let i = activity.length - 1; i >= 0; i--) {
if (activity[i].label === progress.label && activity[i].state === "started") {
position = i;
break;
}
}
}
const entry = { label: progress.label, state: state };
if (position >= 0)
activity[position] = entry;
else
activity.push(entry);
item.data.activity = activity.slice(-30);
shell.activityEvent(index, position, entry);
if (state === "started")
shell.statusText = progress.label;
}
function submitPrompt(query) {
if (shell.assistantPending || !query || query.trim().length === 0)
return;
const q = query.trim();
addMessage("user", q, null);
const pendingIndex = addMessage("assistant",
"Investigating your request. Checking available options can take several minutes.",
{ kind: "progress", state: "running", activity: [] });
shell.assistantElapsedSeconds = 0;
shell.assistantPending = true;
shell.busy = true;
shell.statusText = "Investigating request...";
AssistantBridge.ask(q, null, reply => {
shell.assistantPending = false;
shell.busy = false;
const activity = (shell.conversation[pendingIndex].data || {}).activity || [];
if (!reply.ok) {
const detail = reply.error || "The assistant did not return a result.";
const invalidModelStep = detail.includes("proposal JSON is invalid")
|| detail.includes("invalid action JSON")
|| detail.includes("change rejected: invalid action")
|| detail.includes("change rejected: invalid application name")
|| detail.includes("the investigation did not reach a valid proposal within");
const message = invalidModelStep
? "The connected model could not finish a valid install plan. Nothing was installed. Try again, specify a package source, or use Legacy to choose an exact package."
: "Could not complete request: " + detail;
shell.statusText = "Request failed";
finishMessage(pendingIndex, message, {
kind: "error",
state: "error",
activity: activity
});
return;
}
const res = reply.result || {};
const text = res.recommendation || res.summary || "Prepared for review.";
if (res.kind === "info") {
shell.statusText = "Ready";
} else if (res.prepared) {
shell.statusText = "Plan ready for review";
} else {
shell.statusText = "Ready";
}
finishMessage(pendingIndex, text, Object.assign({}, res, { activity: activity }));
}, progress => shell.recordActivity(pendingIndex, progress));
}
function executePlan(index) {
const list = shell.conversation.slice();
if (index < 0 || index >= list.length)
return;
const data = list[index].data || {};
if (!data.plan_id || !data.digest) {
shell.updateMessage(index, { state: "failed", error: "No reviewed plan to execute." });
return;
}
// Only execute the referenced reviewed plan; the service revalidates it.
shell.busy = true;
shell.statusText = "Executing approved plan...";
shell.updateMessage(index, { state: "executing" });
AssistantBridge.execute(data.plan_id, data.digest, true, reply => {
shell.busy = false;
if (!reply.ok) {
shell.statusText = "Execution failed";
shell.updateMessage(index, { state: "failed", error: reply.error });
return;
}
const r = reply.result || {};
shell.statusText = "Operation completed and verified";
shell.updateMessage(index, {
state: "completed",
completed: true,
verification: r.verification,
snapshot: r.snapshot,
launch: r.launch || null
});
refreshStatus();
}, progress => shell.recordActivity(index, progress));
}
function cancelPlan(index) {
// Cancelling is purely local: nothing reaches the privileged broker.
shell.updateMessage(index, { state: "cancelled" });
shell.statusText = "Cancelled — no changes were made";
}
function launchFromMessage(index) {
const list = shell.conversation.slice();
if (index < 0 || index >= list.length)
return;
const cmd = list[index].data ? list[index].data.launch : null;
if (cmd && cmd.length > 0)
Quickshell.execDetached(cmd);
}
function clearConversation() {
AssistantBridge.clearConversation(() => {
shell.conversation = [];
shell.statusText = "Conversation history cleared";
});
}
function showPanel() {
shell.panelOpen = true;
focusTimer.start();
}
IpcHandler {
target: "panel"
function toggle(): string {
if (shell.panelOpen)
shell.panelOpen = false;
else
shell.showPanel();
return shell.panelOpen ? "shown" : "hidden";
}
function open(): string {
shell.showPanel();
return "shown";
}
function updates(): string {
shell.currentTab = "updates";
shell.showPanel();
if (!shell.updateOverview && !shell.busy && AssistantBridge.ready)
shell.checkUpdates();
return "shown";
}
}
Timer {
id: focusTimer
interval: 120
onTriggered: {
if (shell.panelOpen) {
promptField.forceActiveFocus();
}
}
}
FloatingWindow {
id: window
title: shell.currentTab === "updates" ? "Phoebus Updates" : "Phoebus Assistant"
color: "transparent"
visible: shell.panelOpen
// Default fits 1024x768 and 1280x720. Content areas scroll at
// smaller window sizes and increased UI scale.
implicitWidth: 900
implicitHeight: 650
Component.onCompleted: focusTimer.start()
Shortcut {
sequence: "Escape"
context: Qt.WindowShortcut
onActivated: shell.panelOpen = false
}
// FloatingWindow has no palette property. A Control provides an
// inherited palette for the Qt Quick Controls inside this window.
Control {
anchors.fill: parent
padding: 0
palette.window: Theme.background
palette.windowText: Theme.text
palette.base: Theme.card
palette.text: Theme.text
palette.button: Theme.card
palette.buttonText: Theme.text
palette.highlight: Theme.primary
palette.highlightedText: Theme.background
Rectangle {
anchors.fill: parent
radius: 12
color: Theme.background
border.color: Theme.border
border.width: 1
ColumnLayout {
anchors.fill: parent
anchors.margins: 16
spacing: 12
// Header
RowLayout {
Layout.fillWidth: true
spacing: 12
Label {
text: shell.currentTab === "updates" ? "Phoebus Updates" : "Phoebus Assistant"
color: Theme.text
font.pixelSize: 18
font.bold: true
}
Rectangle {
Layout.preferredWidth: 8
Layout.preferredHeight: 8
radius: 4
color: (shell.currentTab === "updates" ? AssistantBridge.ready : shell.assistantConnected) ? Theme.primary : Theme.warning
}
Label {
text: shell.currentTab === "updates" ? (AssistantBridge.ready ? "System broker ready" : "Connecting…") : (shell.assistantConnected ? "Connected (" + shell.aiBackend + ")" : (shell.bridgeConnecting ? "Connecting…" : (AssistantBridge.ready ? "Setup required" : "Offline")))
color: Theme.muted
font.pixelSize: 12
}
Item { Layout.fillWidth: true }
PhoebusButton {
label: shell.themeMode === "dark" ? "Light mode" : "Dark mode"
onClicked: shell.toggleTheme()
}
}
// Keep tabs on their own row so the header never pushes them
// outside a compact scratchpad window.
Flickable {
Layout.fillWidth: true
Layout.preferredHeight: 40
contentWidth: tabRow.width
contentHeight: 40
clip: true
flickableDirection: Flickable.HorizontalFlick
boundsBehavior: Flickable.StopAtBounds
RowLayout {
id: tabRow
spacing: 4
PhoebusButton {
label: "Assistant"
primary: shell.currentTab === "assistant"
onClicked: shell.currentTab = "assistant"
}
PhoebusButton {
label: "Updates" + (shell.updateOverview && shell.updateOverview.sources ? " (" + shell.updateOverview.sources.reduce((a, c) => a + c.updates.length, 0) + ")" : "")
primary: shell.currentTab === "updates"
onClicked: {
shell.currentTab = "updates";
refreshStatus();
}
}
PhoebusButton {
label: "Legacy"
primary: shell.currentTab === "legacy"
onClicked: shell.currentTab = "legacy"
}
PhoebusButton {
label: "Alerts" + (shell.activeAlerts.length > 0 ? " (" + shell.activeAlerts.length + ")" : "")
primary: shell.currentTab === "alerts"
onClicked: {
shell.currentTab = "alerts";
refreshStatus();
}
}
PhoebusButton {
label: "Prefs"
primary: shell.currentTab === "preferences"
onClicked: {
shell.currentTab = "preferences";
refreshStatus();
}
}
}
}
// Truthful connection bar: when no model is connected, show a
// setup action and the real error — never a false "Connected",
// and never approval controls for an error.
Rectangle {
Layout.fillWidth: true
visible: !shell.assistantConnected && shell.currentTab === "assistant"
radius: 8
color: Theme.card
border.color: Theme.warning
border.width: 1
height: setupRow.height + 16
RowLayout {
id: setupRow
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: 8
spacing: 8
Label {
Layout.fillWidth: true
Layout.minimumWidth: 0
wrapMode: Text.Wrap
text: shell.bridgeConnecting ? "Connecting to the assistant broker…" : (AssistantBridge.ready ? ("No AI model is connected" + (shell.aiError ? ": " + shell.aiError : ". Connect a provider or use Legacy Admin.")) : "The assistant broker is not running.")
color: Theme.text
font.pixelSize: 12
}
PhoebusButton {
label: "Open Legacy Admin"
onClicked: shell.currentTab = "legacy"
}
}
}
Rectangle {
Layout.fillWidth: true
height: 1
color: Theme.border
}
// TAB 1: Conversational Assistant
ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
visible: shell.currentTab === "assistant"
spacing: 10
ListView {
id: chatList
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
spacing: 12
model: shell.conversation
delegate: Rectangle {
id: messageCard
width: chatList.width
height: msgCol.height + 16
radius: 8
color: modelData.sender === "user" ? Theme.cardHover : Theme.card
border.color: Theme.border
border.width: 1
ColumnLayout {
id: msgCol
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: 10
spacing: 8
RowLayout {
Layout.fillWidth: true
Label {
text: modelData.sender === "user" ? "You" : "Phoebus Assistant"
color: modelData.sender === "user" ? Theme.primary : Theme.accent
font.bold: true
font.pixelSize: 13
}
Item { Layout.fillWidth: true }
Label {
text: modelData.time
color: Theme.muted
font.pixelSize: 11
}
}
Label {
Layout.fillWidth: true
text: modelData.text
color: Theme.text
font.pixelSize: 14
wrapMode: Text.Wrap
}
// Plan / review card. The same card serves every
// plan type; the shared service decides what is
// proposed and this only presents it.
ColumnLayout {
Layout.fillWidth: true
visible: modelData.data !== null
spacing: 8
Label {
Layout.fillWidth: true
visible: modelData.data && modelData.data.kind
color: modelData.data && modelData.data.state === "failed" ? Theme.warning : Theme.muted
font.pixelSize: 12
text: {
const d = modelData.data || {};
const kindName = d.kind === "install" ? "Install plan"
: d.kind === "removal" ? "Removal plan"
: d.kind === "confirm" ? "Confirmation required"
: d.kind === "plan" ? "Administration plan"
: d.kind === "info" ? "Information"
: d.kind === "progress" ? "Working"
: d.kind === "error" ? "Error" : "Result";
const stateName = d.state === "prepared" ? "— awaiting your approval"
: d.state === "executing" ? "— executing"
: d.state === "completed" ? "— completed and verified"
: d.state === "failed" ? "— failed"
: d.state === "cancelled" ? "— cancelled"
: "";
return kindName + " " + stateName;
}
}
ColumnLayout {
Layout.fillWidth: true
visible: !!(modelData.data &&
(modelData.data.kind === "progress" || activityList.count > 0))
spacing: 3
Label {
text: "sys activity"
color: Theme.muted
font.bold: true
font.pixelSize: 12
}
ListView {
id: activityList
Layout.fillWidth: true
Layout.preferredHeight: 150
clip: true
spacing: 3
model: ListModel { id: activityModel }
delegate: Label {
width: activityList.width
text: "[" + (model.state === "completed" ? "done" : model.state === "failed" ? "failed" : "running") + "] " + model.label
color: model.state === "failed" ? Theme.warning : model.state === "started" ? Theme.accent : Theme.muted
font.pixelSize: 12
wrapMode: Text.Wrap
}
Component.onCompleted: {
const activity = modelData.data && modelData.data.activity ? modelData.data.activity : [];
for (let i = 0; i < activity.length; i++)
activityModel.append(activity[i]);
positionViewAtEnd();
}
}
Connections {
target: shell
function onActivityEvent(messageIndex, position, entry) {
if (messageIndex !== index)
return;
if (position >= 0 && position < activityModel.count)
activityModel.set(position, entry);
else
activityModel.append(entry);
if (activityModel.count > 30)
activityModel.remove(0);
activityList.positionViewAtEnd();
}
}
}
// Approval and cancellation for every plan type.
RowLayout {
Layout.fillWidth: true
visible: !!(modelData.data && modelData.data.prepared && modelData.data.state === "prepared")
spacing: 8
PhoebusButton {
label: modelData.data && modelData.data.kind === "removal" ? "Approve & Remove" : "Approve & Execute"
primary: true
actionEnabled: !shell.busy
onClicked: shell.executePlan(index)
}
PhoebusButton {
label: "Cancel"
actionEnabled: !shell.busy
onClicked: shell.cancelPlan(index)
}
PhoebusButton {
id: detailsBtn
property bool expanded: false
label: expanded ? "Hide Details" : "Details"
onClicked: expanded = !expanded
}
}
// Expandable reviewed details.
ColumnLayout {
Layout.fillWidth: true
visible: detailsBtn && detailsBtn.expanded
spacing: 4
Label {
Layout.fillWidth: true
wrapMode: Text.Wrap
visible: modelData.data ? !!modelData.data.recommendation : false
text: modelData.data ? modelData.data.recommendation : ""
color: Theme.text
font.pixelSize: 12
}
Label {
text: "Source: " + (modelData.data ? (modelData.data.source || "-") : "-")
color: Theme.muted
font.pixelSize: 12
}
Label {
Layout.fillWidth: true
wrapMode: Text.Wrap
visible: modelData.data && modelData.data.effects && modelData.data.effects.length > 0
text: {
if (!modelData.data || !modelData.data.effects)
return "";
return "Effects: " + modelData.data.effects.map(e => (e.kind || "?") + " " + e.target).join(", ");
}
color: Theme.muted
font.pixelSize: 12
}
Label {
Layout.fillWidth: true
wrapMode: Text.Wrap
visible: modelData.data && modelData.data.warnings && modelData.data.warnings.length > 0
text: modelData.data ? "Warnings: " + (modelData.data.warnings || []).join("; ") : ""
color: Theme.warning
font.pixelSize: 12
}
Label {
Layout.fillWidth: true
wrapMode: Text.Wrap
text: "Plan digest: " + (modelData.data ? (modelData.data.digest || "") : "")
color: Theme.muted
font.pixelSize: 11
}
}
Label {
Layout.fillWidth: true
wrapMode: Text.Wrap
visible: modelData.data && modelData.data.state === "executing"
text: "Executing the approved plan…"
color: Theme.accent
font.pixelSize: 12
}
Label {
Layout.fillWidth: true
wrapMode: Text.Wrap
visible: modelData.data && modelData.data.state === "failed"
text: "Failed: " + (modelData.data && modelData.data.error ? modelData.data.error : "unknown error")
color: Theme.warning
font.pixelSize: 12
}
Label {
Layout.fillWidth: true
wrapMode: Text.Wrap
visible: modelData.data && modelData.data.state === "cancelled"
text: "Cancelled — no changes were made."
color: Theme.muted
font.pixelSize: 12
}
Label {
Layout.fillWidth: true
wrapMode: Text.Wrap
visible: modelData.data && modelData.data.state === "completed"
text: modelData.data && modelData.data.verification ? modelData.data.verification : "Completed successfully."
color: Theme.text
font.pixelSize: 12
}
// Offer launch only when the service identified
// a concrete desktop entry/command.
RowLayout {
Layout.fillWidth: true
visible: modelData.data && modelData.data.state === "completed" && modelData.data.launch
spacing: 8
PhoebusButton {
label: "Launch application"
primary: true
onClicked: shell.launchFromMessage(index)
}
}
}
}
}
onCountChanged: {
Qt.callLater(() => chatList.positionViewAtEnd());
}
}
// Prompt bar
RowLayout {
Layout.fillWidth: true
spacing: 8
TextField {
id: promptField
Layout.fillWidth: true
Layout.minimumWidth: 0
placeholderText: "Ask Phoebus... (e.g. Install Firefox, Show updates, Check audio)"
color: Theme.text
placeholderTextColor: Theme.muted
background: Rectangle {
radius: 8
color: Theme.card
border.color: promptField.activeFocus ? Theme.primary : Theme.border
border.width: 1
}
onAccepted: {
if (!shell.busy && !shell.assistantPending && text.trim().length > 0) {
shell.submitPrompt(text);
text = "";
}
}
}
PhoebusButton {
label: "Send"
primary: true
actionEnabled: !shell.busy && !shell.assistantPending && promptField.text.trim().length > 0
onClicked: {
shell.submitPrompt(promptField.text);
promptField.text = "";
}
}
PhoebusButton {
label: "Clear History"
actionEnabled: !shell.busy && !shell.assistantPending
onClicked: shell.clearConversation()
}
}
}
// TAB 2: Multi-Source Updates
ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
visible: shell.currentTab === "updates"
spacing: 12
Label {
text: "System Updates"
color: Theme.text
font.pixelSize: 16
font.bold: true
}
Label {
Layout.fillWidth: true
text: shell.updateError || "Portage, Flatpak and Snap updates appear below using your current repository metadata. Review the exact plan in the terminal before approving it."
wrapMode: Text.WordWrap
color: shell.updateError ? Theme.warning : Theme.muted
}
ListView {
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
spacing: 8
model: shell.updateOverview ? shell.updateOverview.sources : []
delegate: Rectangle {
width: parent.width
height: srcCol.height + 16
radius: 8
color: Theme.card
border.color: Theme.border
border.width: 1
ColumnLayout {
id: srcCol
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: 10
spacing: 6
RowLayout {
Layout.fillWidth: true
Label {
text: modelData.backend.toUpperCase()
color: Theme.primary
font.bold: true
}
Item { Layout.fillWidth: true }
Label {
text: modelData.updates.length + " update(s)"
color: Theme.muted
}
}
Label {
text: modelData.note
color: Theme.muted
font.pixelSize: 12
}
Repeater {
model: modelData.updates
Label {
text: "• " + modelData.name + " (" + (modelData.current_version || "none") + " -> " + modelData.new_version + ")"
color: Theme.text
font.pixelSize: 12
}
}
}
}
}
RowLayout {
Layout.fillWidth: true
PhoebusButton {
label: "Refresh Updates"
actionEnabled: !shell.busy
onClicked: shell.checkUpdates()
}
PhoebusButton {
label: "Review & Apply"
primary: true
actionEnabled: !shell.busy
onClicked: Quickshell.execDetached(["/usr/local/bin/phoebus-assistant", "--apply-updates"])
}
}
}
// TAB 3: Legacy Admin
ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
visible: shell.currentTab === "legacy"
spacing: 12
Label {
text: "Deterministic Legacy Administration (No Model)"
color: Theme.text
font.pixelSize: 16
font.bold: true
}
RowLayout {
Layout.fillWidth: true
spacing: 8
Label { text: "Lane:"; color: Theme.muted }
ComboBox {
id: legacyLaneCombo
model: ["flatpak", "portage", "nix", "snap", "appimage", "ebuild"]
}
TextField {
id: legacyAppField
Layout.fillWidth: true
placeholderText: "Application name (e.g. firefox, vim)"
color: Theme.text
placeholderTextColor: Theme.muted
background: Rectangle {
radius: 6
color: Theme.card
border.color: Theme.border
border.width: 1
}
}
PhoebusButton {
label: "Install Explicitly"
primary: true
actionEnabled: legacyAppField.text.trim().length > 0
onClicked: {
const app = legacyAppField.text.trim();
const lane = legacyLaneCombo.currentText;
shell.statusText = "Resolving legacy install...";
AssistantBridge.legacyInstall(app, lane, reply => {
if (reply.ok) {
// Show the reviewed plan and require approval;
// never execute merely because it was planned.
shell.currentTab = "assistant";
addMessage("assistant", "Legacy plan for " + app + " (" + lane + ").", reply.result);
shell.statusText = "Legacy plan ready for review";
} else {
shell.statusText = "Error: " + reply.error;
}
});
}
}
}
RowLayout {
Layout.fillWidth: true
spacing: 8
TextField {
id: legacyPhraseField
Layout.fillWidth: true
placeholderText: "Deterministic action (e.g. enable sshd, history, undo)"
color: Theme.text
placeholderTextColor: Theme.muted
background: Rectangle {
radius: 6
color: Theme.card
border.color: Theme.border
border.width: 1
}
}
PhoebusButton {
label: "Execute Command"
actionEnabled: legacyPhraseField.text.trim().length > 0
onClicked: {
const p = legacyPhraseField.text.trim();
AssistantBridge.legacyExecute(p, null, true, reply => {
if (reply.ok) {
shell.statusText = "Executed successfully";
addMessage("assistant", "Executed: " + p + "\n" + (reply.result ? reply.result.output : ""), null);
shell.currentTab = "assistant";
} else {
shell.statusText = "Error: " + reply.error;
}
});
}
}
}
Item { Layout.fillHeight: true }
}
// TAB 4: Proactive Alerts
ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
visible: shell.currentTab === "alerts"
spacing: 12
Label {
text: "Quiet Proactive System Alerts"
color: Theme.text
font.pixelSize: 16
font.bold: true
}
ListView {
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
spacing: 8
model: shell.activeAlerts
delegate: Rectangle {
width: parent.width
height: alertCol.height + 16
radius: 8
color: Theme.card
border.color: modelData.severity === "warning" ? Theme.warning : Theme.border
border.width: 1
ColumnLayout {
id: alertCol
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: 10
spacing: 6
RowLayout {
Layout.fillWidth: true
Label {
text: modelData.title
color: modelData.severity === "warning" ? Theme.warning : Theme.text
font.bold: true
font.pixelSize: 14
}
Item { Layout.fillWidth: true }
Label {
text: modelData.category
color: Theme.muted
font.pixelSize: 11
}
}
Label {
Layout.fillWidth: true
text: modelData.message
color: Theme.text
wrapMode: Text.Wrap
font.pixelSize: 13
}
RowLayout {
Layout.fillWidth: true
spacing: 8
PhoebusButton {
label: "Act: " + (modelData.suggested_phrase || "Fix")
primary: true
visible: modelData.suggested_phrase !== null
onClicked: {
shell.submitPrompt(modelData.suggested_phrase);
shell.currentTab = "assistant";
}
}
PhoebusButton {
label: "Snooze 1h"
onClicked: {
AssistantBridge.snoozeAlerts(3600, reply => {
if (reply.ok)
shell.statusText = "Alerts snoozed for 1 hour.";
else
shell.statusText = "Could not save snooze: " + (reply.error || "unknown error");
refreshStatus();
});
}
}
PhoebusButton {
label: "Dismiss"
onClicked: {
AssistantBridge.dismissAlert(modelData.fingerprint, reply => {
if (reply.ok)
shell.statusText = "Alert dismissed.";
else
shell.statusText = "Could not save dismissal: " + (reply.error || "unknown error");
refreshStatus();
});
}
}
}
}
}
}
Label {
visible: shell.activeAlerts.length === 0
text: "No active proactive alerts. System is quiet and running normally."
color: Theme.muted
font.italic: true
}
}
// TAB 5: Preferences
ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
visible: shell.currentTab === "preferences"
spacing: 12
Label {
text: "Administration Preferences"
color: Theme.text
font.pixelSize: 16
font.bold: true
}
RowLayout {
spacing: 12
Label { text: "Profile Strategy:"; color: Theme.muted }
ComboBox {
id: profileCombo
// These are the exact serde values the backend stores.
model: ["balanced", "fast_installation", "native_integration", "application_isolation"]
currentIndex: {
const current = shell.preferences ? shell.preferences.profile : "balanced";
const idx = model.indexOf(current);
return idx >= 0 ? idx : 0;
}
}
}
RowLayout {
spacing: 12
Label { text: "Theme:"; color: Theme.muted }
PhoebusButton {
label: shell.themeMode === "dark" ? "Dark (default)" : "Dark"
primary: shell.themeMode === "dark"
onClicked: { shell.themeMode = "dark"; Theme.themeMode = "dark"; }
}
PhoebusButton {
label: shell.themeMode === "light" ? "Light (selected)" : "Light"
primary: shell.themeMode === "light"
onClicked: { shell.themeMode = "light"; Theme.themeMode = "light"; }
}
}
Label {
text: "Personal preferences are saved to your own account, not the system."
color: Theme.muted
font.pixelSize: 11
wrapMode: Text.Wrap
}
PhoebusButton {
label: "Save Preferences"
primary: true
onClicked: {
if (shell.preferences) {
shell.preferences.profile = profileCombo.currentText;
shell.preferences.theme = shell.themeMode;
AssistantBridge.setPreferences(shell.preferences, reply => {
// Never report success when the write failed.
if (reply.ok)
shell.statusText = "Preferences saved.";
else
shell.statusText = "Could not save preferences: " + (reply.error || "unknown error");
});
}
}
}
Item { Layout.fillHeight: true }
}
// Footer status bar
Rectangle {
Layout.fillWidth: true
height: 1
color: Theme.border
}
RowLayout {
Layout.fillWidth: true
Label {
text: shell.assistantPending
? "Investigating request (" + shell.assistantElapsedSeconds + "s)..."
: shell.statusText
color: Theme.muted
font.pixelSize: 12
}
Item { Layout.fillWidth: true }
Label {
text: "Phoebus OS • sys 0.1.0"
color: Theme.muted
font.pixelSize: 11
}
}
}
}
}
}
}