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 Component.onCompleted: { AssistantBridge.start(); refreshStatus(); } function refreshStatus() { AssistantBridge.getProactiveAlerts(reply => { if (reply.ok && reply.result) { shell.activeAlerts = reply.result.alerts || []; } }); AssistantBridge.getUpdates(reply => { if (reply.ok && reply.result) { shell.updateOverview = reply.result; } }); AssistantBridge.getPreferences(reply => { if (reply.ok && reply.result) { shell.preferences = 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; } 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, null); return; } shell.statusText = "Plan prepared"; const res = reply.result; if (res.kind === "install") { addMessage("assistant", res.recommendation, res); } else if (res.kind === "plan") { addMessage("assistant", res.summary, res); } else { addMessage("assistant", "Completed.", res); } }); } function executePlan(planData) { shell.busy = true; shell.statusText = "Executing approved plan..."; const actions = planData.action ? [planData.action] : (planData.actions ? planData.actions.map(a => a.action || a) : []); AssistantBridge.execute(actions, planData.digest, true, reply => { shell.busy = false; if (!reply.ok) { shell.statusText = "Execution failed"; addMessage("assistant", "Execution failed: " + reply.error, null); } else { shell.statusText = "Installed successfully"; addMessage("assistant", "Operation completed successfully.", { completed: true, application: planData.application, snapshot: reply.result ? reply.result.snapshot : null }); refreshStatus(); } }); } function launchApplication(app) { if (!app) return; Quickshell.execDetached(["gtk-launch", app]); } FloatingWindow { id: window title: "Phoebus Assistant" color: "transparent" width: 820 height: 640 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: AssistantBridge.ready ? Theme.primary : Theme.warning } Label { text: AssistantBridge.ready ? "Connected" : "Offline" color: Theme.muted font.pixelSize: 12 } Item { Layout.fillWidth: true } // Tab buttons RowLayout { spacing: 4 PhoebusButton { text: "Assistant" primary: shell.currentTab === "assistant" onClicked: shell.currentTab = "assistant" } PhoebusButton { text: "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 { text: "Legacy Admin" primary: shell.currentTab === "legacy" onClicked: shell.currentTab = "legacy" } PhoebusButton { text: "Alerts" + (shell.activeAlerts.length > 0 ? " (" + shell.activeAlerts.length + ")" : "") primary: shell.currentTab === "alerts" onClicked: { shell.currentTab = "alerts"; refreshStatus(); } } PhoebusButton { text: "Preferences" primary: shell.currentTab === "preferences" onClicked: { shell.currentTab = "preferences"; refreshStatus(); } } } } 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 } // Recommendation / Action Card ColumnLayout { Layout.fillWidth: true visible: modelData.data !== null spacing: 8 // Action buttons for installation RowLayout { Layout.fillWidth: true visible: modelData.data && modelData.data.kind === "install" && !modelData.data.completed spacing: 8 PhoebusButton { text: "Install" primary: true enabled: !shell.busy onClicked: shell.executePlan(modelData.data) } PhoebusButton { id: detailsBtn property bool expanded: false text: expanded ? "Hide Details" : "Compare Options" onClicked: expanded = !expanded } } // Expandable candidate details ColumnLayout { Layout.fillWidth: true visible: detailsBtn && detailsBtn.expanded spacing: 4 Label { text: "Resolved Source: " + (modelData.data ? modelData.data.backend + " (" + modelData.data.source + ")" : "") color: Theme.muted font.pixelSize: 12 } Label { text: "Plan Digest: " + (modelData.data ? modelData.data.digest : "") color: Theme.muted font.pixelSize: 11 } } // Completed follow-up action RowLayout { Layout.fillWidth: true visible: modelData.data && modelData.data.completed && modelData.data.application spacing: 8 PhoebusButton { text: "Launch " + (modelData.data ? modelData.data.application : "App") primary: true onClicked: shell.launchApplication(modelData.data.application) } } } } } 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 { text: "Send" primary: true enabled: !shell.busy && promptField.text.trim().length > 0 onClicked: { shell.submitPrompt(promptField.text); promptField.text = ""; } } } } // 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 { text: "Refresh Updates" onClicked: refreshStatus() } PhoebusButton { text: "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 { text: "Install Explicitly" primary: true enabled: 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) { shell.executePlan(reply.result); } 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 { text: "Execute Command" enabled: 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 { text: "Act: " + (modelData.suggested_phrase || "Fix") primary: true visible: modelData.suggested_phrase !== null onClicked: { shell.submitPrompt(modelData.suggested_phrase); shell.currentTab = "assistant"; } } PhoebusButton { text: "Snooze 1h" onClicked: { AssistantBridge.snoozeAlerts(3600, () => refreshStatus()); } } PhoebusButton { text: "Dismiss" onClicked: { AssistantBridge.dismissAlert(modelData.fingerprint, () => 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 model: ["Balanced", "FastInstallation", "NativeIntegration", "ApplicationIsolation"] currentIndex: 0 } } PhoebusButton { text: "Save Preferences" primary: true onClicked: { if (shell.preferences) { shell.preferences.profile = profileCombo.currentText; AssistantBridge.setPreferences(shell.preferences, reply => { if (reply.ok) shell.statusText = "Preferences saved."; }); } } } 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 } } } } } }