import QtQuick import QtQuick.Controls import QtQuick.Layouts import Quickshell import Quickshell.Io import "Common" ShellRoot { id: shell property string currentTab: "assistant" // "assistant", "updates", "legacy", "alerts", "preferences" property var conversation: [] property bool busy: false property string statusText: "Ready" property var activeAlerts: [] property var updateOverview: null 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 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 = ""; AssistantBridge.getProactiveAlerts(reply => { if (reply.ok && reply.result) shell.activeAlerts = reply.result.alerts || []; }); 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(); } } 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() { shell.busy = true; shell.statusText = "Checking for updates across package sources..."; AssistantBridge.getUpdates(reply => { shell.busy = false; shell.statusText = "Ready"; if (reply.ok && reply.result) { shell.updateOverview = reply.result; } }); } 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 submitPrompt(query) { if (!query || query.trim().length === 0) return; const q = query.trim(); addMessage("user", q, null); shell.busy = true; shell.statusText = "Investigating request..."; AssistantBridge.ask(q, null, reply => { shell.busy = false; if (!reply.ok) { shell.statusText = "Error: " + reply.error; addMessage("assistant", "Could not complete request: " + reply.error, { kind: "error", state: "failed" }); 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"; } addMessage("assistant", text, res); }); } 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(); }); } 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"; }); } FloatingWindow { id: window title: "Phoebus Assistant" color: "transparent" // Default fits 1024x768 and 1280x720. Content areas scroll at // smaller window sizes and increased UI scale. implicitWidth: 820 implicitHeight: 640 // 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: "Phoebus Assistant" color: Theme.text font.pixelSize: 18 font.bold: true } Rectangle { Layout.preferredWidth: 8 Layout.preferredHeight: 8 radius: 4 color: shell.assistantConnected ? Theme.primary : Theme.warning } Label { text: 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() } // Tab buttons scroll horizontally instead of overflowing // at 1024x768, 1280x720 or increased UI scale. Flickable { Layout.preferredWidth: Math.min(420, parent.width * 0.55) 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 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 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 { 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 === "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; } } // 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 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 (text.length > 0) { shell.submitPrompt(text); text = ""; } } } PhoebusButton { label: "Send" primary: true actionEnabled: !shell.busy && promptField.text.trim().length > 0 onClicked: { shell.submitPrompt(promptField.text); promptField.text = ""; } } PhoebusButton { label: "Clear History" actionEnabled: !shell.busy onClicked: shell.clearConversation() } } } // TAB 2: Multi-Source Updates ColumnLayout { Layout.fillWidth: true Layout.fillHeight: true visible: shell.currentTab === "updates" spacing: 12 Label { text: "Unified Multi-Source Updates" color: Theme.text font.pixelSize: 16 font.bold: true } 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" onClicked: refreshStatus() } PhoebusButton { label: "Apply All Updates" primary: true onClicked: shell.submitPrompt("update system") } } } // 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.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 } } } } } } }