Add Quick Fix: a bar chat that hands quick fixes to Claude, Codex or a local model
Each request runs in its own systemd user unit and survives the shell restarting; the chat reopens on a running job or an unseen result. Auto picks the subscription with the most usage left (ai-usagebar). Runs are snapshotted so Undo can restore files and revert commits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
30e98bac63
commit
3d976b5961
8 files changed
+1693
No files matched your search
@@ -0,0 +1,407 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import qs.Commons
|
||||
import qs.Ui
|
||||
|
||||
// The chat: what you asked, and the agent's one-line answer to each. A
|
||||
// follow-up continues the same conversation; closing it starts fresh next
|
||||
// time (the conversation stays in History).
|
||||
Panel {
|
||||
id: root
|
||||
|
||||
property Item anchorItem: null
|
||||
property var service: null
|
||||
readonly property var session: service ? service.session : null
|
||||
readonly property var messages: session ? session.messages : []
|
||||
readonly property bool busy: !!service && service.running
|
||||
readonly property var providers: [
|
||||
{ value: "auto", label: "Auto" },
|
||||
{ value: "claude", label: "Claude" },
|
||||
{ value: "gpt", label: "GPT" },
|
||||
{ value: "local", label: "Local" }
|
||||
]
|
||||
readonly property string defaultProvider: setting("provider", "auto")
|
||||
readonly property int cardWidth: Style.space(460)
|
||||
readonly property int cardHeight: Style.space(470)
|
||||
|
||||
function send() {
|
||||
if (service && service.send(input.text, root.settings)) input.text = ""
|
||||
}
|
||||
function focusInput() {
|
||||
if (service) service.passive = false
|
||||
input.forceActiveFocus()
|
||||
}
|
||||
function when(seconds) {
|
||||
if (!seconds) return ""
|
||||
const d = new Date(seconds * 1000), now = new Date()
|
||||
const time = Qt.formatTime(d, "hh:mm")
|
||||
return d.toDateString() === now.toDateString() ? time : Qt.formatDate(d, "d MMM") + " " + time
|
||||
}
|
||||
function providerName(id) {
|
||||
return { claude: "Claude", gpt: "GPT", local: "Local", undo: "Undo" }[id] || ""
|
||||
}
|
||||
function usageLine() {
|
||||
if (!service) return ""
|
||||
const left = service.remaining || {}
|
||||
const parts = []
|
||||
if (left.claude !== undefined) parts.push("Claude " + Math.round(left.claude) + "% left")
|
||||
if (left.gpt !== undefined) parts.push("GPT " + Math.round(left.gpt) + "% left")
|
||||
if (!service.available.local) parts.push("no local model running")
|
||||
return parts.join(" · ")
|
||||
}
|
||||
|
||||
onOpenedChanged: {
|
||||
if (!service) return
|
||||
service.openPanels += opened ? 1 : -1
|
||||
if (opened) {
|
||||
if (!service.passive) service.provider = defaultProvider
|
||||
service.checkProviders(root.settings)
|
||||
input.text = ""
|
||||
}
|
||||
}
|
||||
Component.onDestruction: if (opened && service) service.openPanels--
|
||||
|
||||
// Scroll to the newest message whenever the conversation changes.
|
||||
Connections {
|
||||
target: root.service
|
||||
function onSessionChanged() { Qt.callLater(() => list.positionViewAtEnd()) }
|
||||
}
|
||||
Timer {
|
||||
id: clock
|
||||
property real now: Date.now()
|
||||
interval: 1000
|
||||
repeat: true
|
||||
running: root.opened && root.busy
|
||||
onTriggered: now = Date.now()
|
||||
}
|
||||
|
||||
KeyboardPanel {
|
||||
id: card
|
||||
anchorItem: root.anchorItem
|
||||
owner: root
|
||||
bar: root.bar
|
||||
open: root.opened
|
||||
// After a restart it shows without taking the keyboard; a click on it does.
|
||||
mode: root.service && root.service.passive ? "hover" : "keyboard"
|
||||
focusTarget: input
|
||||
contentWidth: card.fittedContentWidth(root.cardWidth)
|
||||
contentHeight: card.cappedContentHeight(root.cardHeight)
|
||||
|
||||
Column {
|
||||
id: column
|
||||
anchors.fill: parent
|
||||
spacing: Style.spacing.lg
|
||||
|
||||
// Pointing at it after a restart hands it the keyboard.
|
||||
HoverHandler {
|
||||
enabled: !!root.service && root.service.passive
|
||||
onHoveredChanged: if (hovered) root.focusInput()
|
||||
}
|
||||
|
||||
// Header
|
||||
Item {
|
||||
width: parent.width
|
||||
height: Style.space(30)
|
||||
Text {
|
||||
anchors.left: parent.left
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: root.service && root.service.showHistory ? "History" : "Quick fix"
|
||||
color: Color.foreground
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.heading
|
||||
font.bold: true
|
||||
}
|
||||
Row {
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
spacing: Style.spacing.sm
|
||||
Button {
|
||||
iconText: ""
|
||||
tooltipText: "History"
|
||||
selected: !!root.service && root.service.showHistory
|
||||
onClicked: root.service.openHistory()
|
||||
}
|
||||
Button {
|
||||
iconText: ""
|
||||
tooltipText: "New conversation"
|
||||
enabled: !root.busy
|
||||
opacity: enabled ? 1 : 0.4
|
||||
onClicked: { root.service.newChat(); root.focusInput() }
|
||||
}
|
||||
Button {
|
||||
iconText: ""
|
||||
tooltipText: "Close"
|
||||
onClicked: root.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Conversation or history
|
||||
Item {
|
||||
id: middle
|
||||
width: parent.width
|
||||
height: parent.height - y - footer.height - parent.spacing
|
||||
|
||||
ListView {
|
||||
id: list
|
||||
anchors.fill: parent
|
||||
visible: !(root.service && root.service.showHistory)
|
||||
clip: true
|
||||
spacing: Style.spacing.lg
|
||||
model: root.messages
|
||||
boundsBehavior: Flickable.StopAtBounds
|
||||
ScrollBar.vertical: ScrollBar {}
|
||||
onCountChanged: Qt.callLater(positionViewAtEnd)
|
||||
delegate: Item {
|
||||
id: row
|
||||
required property var modelData
|
||||
required property int index
|
||||
readonly property bool mine: modelData.role === "user"
|
||||
readonly property bool newest: index === root.messages.length - 1
|
||||
readonly property bool working: !mine && modelData.status === "running"
|
||||
readonly property bool canUndo: !mine && modelData.changed === true && !modelData.undone && !!modelData.run && !root.busy
|
||||
width: list.width
|
||||
height: bubble.height
|
||||
|
||||
Rectangle {
|
||||
id: bubble
|
||||
x: row.mine ? row.width - width : 0
|
||||
width: Math.min(row.width * 0.86, Math.max(body.implicitWidth, meta.implicitWidth) + 2 * Style.spacing.xxl)
|
||||
height: content.implicitHeight + 2 * Style.spacing.xl
|
||||
radius: Style.cornerRadius + 4
|
||||
color: row.mine ? Qt.alpha(Color.accent, 0.2)
|
||||
: row.modelData.status === "failed" ? Qt.alpha(Color.urgent, 0.14)
|
||||
: Qt.alpha(Color.foreground, 0.06)
|
||||
border.width: 1
|
||||
border.color: row.mine ? Qt.alpha(Color.accent, 0.45) : Qt.alpha(Color.foreground, 0.1)
|
||||
|
||||
Column {
|
||||
id: content
|
||||
x: Style.spacing.xxl
|
||||
y: Style.spacing.xl
|
||||
width: bubble.width - 2 * Style.spacing.xxl
|
||||
spacing: Style.spacing.sm
|
||||
Text {
|
||||
id: meta
|
||||
visible: !row.mine
|
||||
textFormat: Text.PlainText
|
||||
text: {
|
||||
const m = row.modelData
|
||||
const parts = [root.providerName(m.provider) || (row.working ? "Starting" : "")]
|
||||
if (m.status === "ok") parts.push("done")
|
||||
else if (m.status === "failed") parts.push("failed")
|
||||
if (m.rebuilt) parts.push("rebuilt")
|
||||
else if (m.changed) parts.push("files changed")
|
||||
if (m.undone) parts.push("undone")
|
||||
return parts.filter(p => p).join(" · ")
|
||||
}
|
||||
color: row.modelData.status === "failed" ? Color.urgent : Color.muted
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.caption
|
||||
font.bold: true
|
||||
}
|
||||
Text {
|
||||
id: body
|
||||
width: Math.min(implicitWidth, content.width)
|
||||
textFormat: Text.PlainText
|
||||
wrapMode: Text.Wrap
|
||||
text: row.working ? "Working… " + root.elapsed(row.modelData.time) : row.modelData.text
|
||||
color: row.working ? Color.muted : Color.foreground
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.subtitle
|
||||
}
|
||||
Row {
|
||||
visible: row.canUndo
|
||||
spacing: Style.spacing.sm
|
||||
Button {
|
||||
text: "Undo"
|
||||
iconText: ""
|
||||
bordered: true
|
||||
fontSize: Style.font.bodySmall
|
||||
onClicked: root.service.undo(row.modelData.run, root.settings)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Empty conversation
|
||||
Column {
|
||||
anchors.centerIn: parent
|
||||
width: parent.width - 2 * Style.spacing.huge
|
||||
spacing: Style.spacing.md
|
||||
visible: list.visible && root.messages.length === 0
|
||||
Text {
|
||||
width: parent.width
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: ""
|
||||
color: Color.muted
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.displayLarge
|
||||
}
|
||||
Text {
|
||||
width: parent.width
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
wrapMode: Text.Wrap
|
||||
textFormat: Text.PlainText
|
||||
text: "Ask for a quick fix: install an app, make a window float, squash a bug. It works on its own and answers in a line."
|
||||
color: Color.muted
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.body
|
||||
}
|
||||
Text {
|
||||
width: parent.width
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
wrapMode: Text.Wrap
|
||||
textFormat: Text.PlainText
|
||||
text: root.usageLine()
|
||||
visible: text !== ""
|
||||
color: Color.muted
|
||||
opacity: 0.75
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.caption
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: historyList
|
||||
anchors.fill: parent
|
||||
visible: !!root.service && root.service.showHistory
|
||||
clip: true
|
||||
spacing: Style.spacing.xs
|
||||
model: root.service ? root.service.history : []
|
||||
boundsBehavior: Flickable.StopAtBounds
|
||||
ScrollBar.vertical: ScrollBar {}
|
||||
delegate: Rectangle {
|
||||
id: entry
|
||||
required property var modelData
|
||||
width: historyList.width
|
||||
height: Style.space(42)
|
||||
radius: Style.cornerRadius
|
||||
color: entryArea.containsMouse ? Qt.alpha(Color.foreground, 0.08) : "transparent"
|
||||
Rectangle {
|
||||
id: dot
|
||||
x: Style.spacing.lg
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: 7
|
||||
height: 7
|
||||
radius: 4
|
||||
color: entry.modelData.status === "failed" ? Color.urgent : entry.modelData.status === "running" ? Color.accent : Qt.alpha(Color.foreground, 0.45)
|
||||
}
|
||||
Text {
|
||||
anchors.left: dot.right
|
||||
anchors.leftMargin: Style.spacing.lg
|
||||
anchors.right: stamp.left
|
||||
anchors.rightMargin: Style.spacing.lg
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
textFormat: Text.PlainText
|
||||
text: entry.modelData.title
|
||||
elide: Text.ElideRight
|
||||
color: Color.foreground
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.body
|
||||
}
|
||||
Text {
|
||||
id: stamp
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: Style.spacing.lg
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: root.when(entry.modelData.updated)
|
||||
color: Color.muted
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.caption
|
||||
}
|
||||
MouseArea {
|
||||
id: entryArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: root.service.load(entry.modelData.id)
|
||||
}
|
||||
}
|
||||
footer: Item {
|
||||
width: historyList.width
|
||||
height: historyList.count ? Style.space(44) : 0
|
||||
Button {
|
||||
visible: historyList.count > 0
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
text: "Clear history"
|
||||
fontSize: Style.font.bodySmall
|
||||
onClicked: root.service.clearHistory()
|
||||
}
|
||||
}
|
||||
}
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
visible: historyList.visible && historyList.count === 0
|
||||
text: "Nothing yet"
|
||||
color: Color.muted
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.body
|
||||
}
|
||||
}
|
||||
|
||||
// Input, agent choice and errors
|
||||
Column {
|
||||
id: footer
|
||||
width: parent.width
|
||||
spacing: Style.spacing.md
|
||||
Text {
|
||||
width: parent.width
|
||||
visible: !!root.service && root.service.error !== ""
|
||||
text: root.service ? root.service.error : ""
|
||||
textFormat: Text.PlainText
|
||||
wrapMode: Text.Wrap
|
||||
color: Color.urgent
|
||||
font.family: Style.font.family
|
||||
font.pixelSize: Style.font.bodySmall
|
||||
}
|
||||
Row {
|
||||
width: parent.width
|
||||
spacing: Style.spacing.md
|
||||
TextField {
|
||||
id: input
|
||||
width: parent.width - action.width - parent.spacing
|
||||
placeholderText: root.busy ? "Working on it…" : root.messages.length ? "Follow up…" : "Fix or install something…"
|
||||
enabled: !root.busy
|
||||
maximumLength: 8000
|
||||
font.pixelSize: Style.font.subtitle
|
||||
onAccepted: root.send()
|
||||
Keys.onEscapePressed: {
|
||||
if (text !== "") text = ""
|
||||
else root.close()
|
||||
}
|
||||
}
|
||||
Button {
|
||||
id: action
|
||||
anchors.verticalCenter: input.verticalCenter
|
||||
iconText: root.busy ? "" : ""
|
||||
tooltipText: root.busy ? "Stop" : "Send"
|
||||
bordered: true
|
||||
onClicked: root.busy ? root.service.stop() : root.send()
|
||||
}
|
||||
}
|
||||
ButtonGroup {
|
||||
options: root.providers.map(p => ({
|
||||
value: p.value,
|
||||
label: p.label,
|
||||
tooltip: p.value === "auto" ? "The subscription with the most usage left" : ""
|
||||
}))
|
||||
value: root.service && root.service.provider ? root.service.provider : root.defaultProvider
|
||||
focusable: false
|
||||
fontSize: Style.font.bodySmall
|
||||
onChanged: function(value) { if (root.service) root.service.provider = value }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function elapsed(started) {
|
||||
if (!started) return ""
|
||||
const s = Math.max(0, Math.round(clock.now / 1000 - started))
|
||||
return Math.floor(s / 60) + ":" + String(s % 60).padStart(2, "0")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user