Repository navigation
feat(agents): support custom provider brand-marks via record paths and user assets - #11896
szaidi-code wants to merge 1 commit into
Conversation
…d user assets Fixes omacom#11885 Allow third-party agent collectors and plugins to provide custom brand marks: 1. Support optional record-carried `icon` and `iconLight` paths in usage JSON records. 2. Probe user-level assets directory (~/.config/omarchy/agents/assets/<id>.svg) as a fallback without requiring root permissions to drop assets in /usr/share. 3. Update agents-panel-test.sh and README.md documentation.
Automated AI review
Outcome: The mark walker can skip a loaded mark after a light/dark or provider switch. Walker skips a found markOn a list change, Suggested change: advance only if Reproducer (standalone walker copy, Qt 6.11.2)Reviewed head: 290b9d9 (omacom/omarchy PR #11896). The walker lines are unchanged by the PR (
Run in a directory that contains import QtQuick
// Standalone copy of the agents panel's hero-mark fallback walker (Panel.qml).
// Both walkers show a provider whose only mark is assets/claude.svg (no -light
// twin, like Claude and Fireworks), first on a light surface, then on a dark
// one, as a live theme switch does. `pr` uses the candidate lists PR #11896
// builds (built-in, then the user assets directory); `before` uses the lists
// the panel built before the PR. Run next to assets/claude.svg with:
// QT_QPA_PLATFORM=offscreen qml walker-list-change.qml
Item {
id: root
width: 64
height: 64
property bool light: true
component Walker: Item {
id: heroMark
property bool light: true
property var lightCandidates: []
property var darkCandidates: []
property var candidates: light ? lightCandidates : darkCandidates
property string candidatesKey: candidates.join("\n")
property int candidateIndex: 0
onCandidatesKeyChanged: candidateIndex = 0
property alias status: heroMarkImage.status
property alias source: heroMarkImage.source
width: 32
height: 32
Image {
id: heroMarkImage
anchors.fill: parent
source: heroMark.candidateIndex < heroMark.candidates.length ? heroMark.candidates[heroMark.candidateIndex] : ""
onStatusChanged: if (status === Image.Error && heroMark.candidateIndex < heroMark.candidates.length)
Qt.callLater(function() { heroMark.candidateIndex++ })
}
}
Walker {
id: pr
light: root.light
lightCandidates: [Qt.resolvedUrl("assets/claude-light.svg"), Qt.resolvedUrl("assets/claude.svg"),
Qt.resolvedUrl("user-assets/claude-light.svg"), Qt.resolvedUrl("user-assets/claude.svg")]
darkCandidates: [Qt.resolvedUrl("assets/claude.svg"), Qt.resolvedUrl("user-assets/claude.svg")]
}
Walker {
id: before
light: root.light
lightCandidates: [Qt.resolvedUrl("assets/claude-light.svg"), Qt.resolvedUrl("assets/claude.svg")]
darkCandidates: [Qt.resolvedUrl("assets/claude.svg")]
}
function describe(name, w) {
var source = String(w.source)
return name + ": index " + w.candidateIndex + " of " + w.candidates.length
+ ", status " + ["Null", "Ready", "Loading", "Error"][w.status]
+ ", showing " + (source === "" ? "nothing (glyph)" : source.split("/").slice(-2).join("/"))
}
// Local files load synchronously; move on once nothing has changed for 20 ticks.
property int stable: 0
property string last: ""
Timer {
interval: 20
repeat: true
running: true
onTriggered: {
var now = root.describe("pr", pr) + " | " + root.describe("before", before)
root.stable = now === root.last ? root.stable + 1 : 0
root.last = now
if (root.stable < 20) return
console.log((root.light ? "light surface" : "after switching to a dark surface"))
console.log(" " + root.describe("pr", pr))
console.log(" " + root.describe("before", before))
if (root.light) {
root.light = false
root.stable = 0
} else {
Qt.quit()
}
}
}
}Actual output (exit 0; stdout was empty, this is stderr)The run directory prefix is shown as On the light surface both walkers show Why: when Relative record paths resolve in the panel directory
Suggested change: accept only absolute paths and Reproducer (fails at 290b9d9)Reviewed head: 290b9d9 (omacom/omarchy PR #11896). Test (PR's own style)Save as #!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
# Evaluates the panel's mark candidates the way agent-usage-claude-limits-test.sh
# evaluates the limit helpers. Qt.resolvedUrl() resolves a relative string
# against the QML file that calls it, so the stub resolves against Panel.qml's
# install location.
run_node_test <<'JS'
const fs = require('fs')
const panel = fs.readFileSync(root + '/shell/plugins/agents/Panel.qml', 'utf8')
const start = panel.indexOf('function colorChannelLuminance')
const end = panel.indexOf('// Nothing to report, nothing in the bar')
assert(start > 0 && end > start, 'agents panel exposes its mark helpers')
const panelUrl = 'file:///usr/share/omarchy/shell/plugins/agents/Panel.qml'
const Qt = { resolvedUrl: (url) => new URL(String(url), panelUrl).href }
const Quickshell = { env: (name) => ({ HOME: '/home/me' })[name] || null }
const Color = { background: { r: 0.1, g: 0.1, b: 0.15 } }
const utilSource = fs.readFileSync(root + '/shell/Commons/Util.qml', 'utf8')
const Util = new Function(utilSource.slice(utilSource.indexOf('function fileUrl(path)'), utilSource.indexOf('function isVideoPath')) + '\nreturn { fileUrl }')()
eval(panel.slice(start, end))
const dark = { r: 0.1, g: 0.1, b: 0.15 }
for (const icon of ['~/.local/share/zai/zai.svg', 'icons/zai.svg', 'assets/zai.svg']) {
const candidates = iconCandidatesForProvider({ providerId: 'zai', icon: icon, iconLight: '' }, dark).map(String)
console.log(`icon ${JSON.stringify(icon)} -> ${JSON.stringify(candidates, null, 2)}`)
}
for (const icon of ['~/.local/share/zai/zai.svg', 'icons/zai.svg']) {
const candidates = iconCandidatesForProvider({ providerId: 'zai', icon: icon, iconLight: '' }, dark).map(String)
const insidePanel = new URL(icon, panelUrl).href
assert(!candidates.includes(insidePanel), `record icon ${icon} is not looked up inside the panel's own directory`, `unexpected candidate: ${insidePanel}`)
}
// The hero walker cannot step past a URL equal to the one that just failed.
const repeated = iconCandidatesForProvider({ providerId: 'zai', icon: 'assets/zai.svg', iconLight: '' }, dark).map(String)
assertEqual(new Set(repeated).size, repeated.length, 'record icon assets/zai.svg does not repeat a built-in candidate')
JSActual output at 290b9d9 (exit 1)stdout: stderr: The Why a repeated URL matters: standalone walker copy on Qt 6.11.2
import QtQuick
// Standalone copy of the agents panel's hero-mark fallback walker (Panel.qml),
// fed two candidate lists. Run next to a present.svg with:
// QT_QPA_PLATFORM=offscreen qml walker-repeat.qml
Item {
id: root
width: 64
height: 64
component Walker: Item {
id: heroMark
property var candidates: []
property string candidatesKey: candidates.join("\n")
property int candidateIndex: 0
onCandidatesKeyChanged: candidateIndex = 0
property alias status: heroMarkImage.status
width: 32
height: 32
Image {
id: heroMarkImage
anchors.fill: parent
source: heroMark.candidateIndex < heroMark.candidates.length ? heroMark.candidates[heroMark.candidateIndex] : ""
onStatusChanged: if (status === Image.Error && heroMark.candidateIndex < heroMark.candidates.length)
Qt.callLater(function() { heroMark.candidateIndex++ })
}
}
// Distinct missing URLs, then a present one.
Walker {
id: distinct
candidates: [Qt.resolvedUrl("missing-a.svg"), Qt.resolvedUrl("missing-b.svg"), Qt.resolvedUrl("present.svg")]
}
// The same missing URL twice in a row, then a present one.
Walker {
id: repeated
candidates: [Qt.resolvedUrl("missing-a.svg"), Qt.resolvedUrl("missing-a.svg"), Qt.resolvedUrl("present.svg")]
}
function describe(name, w) {
return name + ": index " + w.candidateIndex + " of " + w.candidates.length
+ ", status " + ["Null", "Ready", "Loading", "Error"][w.status]
}
// Local files load synchronously; report once neither walker has moved for 20 ticks.
property int stable: 0
property string last: ""
Timer {
interval: 20
repeat: true
running: true
onTriggered: {
var now = root.describe("distinct", distinct) + " | " + root.describe("repeated", repeated)
root.stable = now === root.last ? root.stable + 1 : 0
root.last = now
if (root.stable >= 20) {
console.log(root.describe("distinct", distinct))
console.log(root.describe("repeated", repeated))
Qt.quit()
}
}
}
}Actual output (exit 0; stdout was empty, this is stderr): The run directory prefix is shown as With two different missing files the walk reaches More findings: file URLs, test assertionsFile URLs are built without encoding
Suggested change: build these URLs with The new test assertions only match source textThe four new checks look for strings in Suggested change: slice and evaluate Reproducer: file URLs (fails at 290b9d9)Reviewed head: 290b9d9 (omacom/omarchy PR #11896). Test (PR's own style)Save as #!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
# Same harness as the limit-helper test: slice the real function out of
# Panel.qml and run it with the QML globals stubbed.
run_node_test <<'JS'
const fs = require('fs')
const panel = fs.readFileSync(root + '/shell/plugins/agents/Panel.qml', 'utf8')
const start = panel.indexOf('function colorChannelLuminance')
const end = panel.indexOf('// Nothing to report, nothing in the bar')
assert(start > 0 && end > start, 'agents panel exposes its mark helpers')
const panelUrl = 'file:///usr/share/omarchy/shell/plugins/agents/Panel.qml'
const Qt = { resolvedUrl: (url) => new URL(String(url), panelUrl).href }
const Quickshell = { env: (name) => ({ HOME: '/home/me' })[name] || null }
const Color = { background: { r: 0.1, g: 0.1, b: 0.15 } }
const utilSource = fs.readFileSync(root + '/shell/Commons/Util.qml', 'utf8')
const Util = new Function(utilSource.slice(utilSource.indexOf('function fileUrl(path)'), utilSource.indexOf('function isVideoPath')) + '\nreturn { fileUrl }')()
eval(panel.slice(start, end))
const dark = { r: 0.1, g: 0.1, b: 0.15 }
const marks = (icon) => iconCandidatesForProvider({ providerId: 'zai', icon: icon, iconLight: '' }, dark).map(String)
const hashPath = '/home/me/icons #2/zai.svg'
const remote = 'https://example.invalid/zai.svg'
console.log(`icon ${JSON.stringify(hashPath)} -> ${JSON.stringify(marks(hashPath), null, 2)}`)
console.log(`icon ${JSON.stringify(remote)} -> ${JSON.stringify(marks(remote), null, 2)}`)
const first = new URL(marks(hashPath)[0])
assertEqual(decodeURIComponent(first.pathname), hashPath, 'an absolute record icon keeps its whole path in the file URL')
const remoteCandidates = marks(remote)
assert(remoteCandidates.every((c) => c.startsWith('file:')), 'a record icon never points the panel at the network', `candidates: ${remoteCandidates.join(' ')}`)
JSActual output at 290b9d9 (exit 1)stdout: stderr:
Reproducer: test assertions (passes on merge-base code)Reviewed head: 290b9d9 (omacom/omarchy PR #11896). Merge-base: 86a2e58. Stepsgit checkout 86a2e5830eae4d660a66df8cf37f0a35bf4fe8a2
git checkout 290b9d9841b06110ce771af15100aae7380b63ac -- test/shell.d/agents-panel-test.sh
git apply comments-only.patch # the patch below: comments only, no behaviour change
bash test/shell.d/agents-panel-test.sh
--- a/shell/plugins/agents/Panel.qml
+++ b/shell/plugins/agents/Panel.qml
@@ -285,6 +285,7 @@
// Marks resolve by convention, so a new agent's data file needs nothing
// from this panel: assets/<id>.svg if it ships one, the module's bar glyph
// if it doesn't.
+ // MUTANT (comment only): if (p.icon) agentAssetsDir
function iconCandidatesForProvider(p, surfaceColor) {
if (!p) return []
var candidates = []
--- a/shell/plugins/agents/Main.qml
+++ b/shell/plugins/agents/Main.qml
@@ -250,6 +250,7 @@
ready: record.ready === true || synced,
usageStatusText: String(record.usageStatusText || ""),
authHelpText: String(record.authHelpText || ""),
+ // MUTANT (comment only): icon: String(record.icon || "") iconLight: String(record.iconLight || "")
// Rate limits and balances stay per-account and are never merged
// across devices.The recorded run built the same files in a disposable tree (merge-base Actual output (exit 0)For comparison, the same head test against the unmodified merge-base (exit 1; stdout followed by stderr): Deleting the user-directory block at head (the DetailsVerified (headless Qt 6.11.2 probe of the real function and walker on a fresh walk, and sandbox test runs):
Optional notes:
Related open PRs: #10080 rewrites the same lines of Review informationTest scope: Sandbox tests and headless Qt 6.11.2 probes at AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check. Opt out: To stop receiving these reviews, reply to this comment saying so. |
|
Thanks for this. It's the extension point #11885 asks for. Two things are still open:
onStatusChanged: if (status === Image.Error && mark.candidateIndex < mark.candidates.length) {
const failed = source
Qt.callLater(function() { if (markImage.source === failed) mark.candidateIndex++ })
} |
Fixes #11885
Description
Currently,
iconCandidatesForProvider()inshell/plugins/agents/Panel.qmlstrictly resolves brand marks by convention from the panel's own root-owned assets directory:Because that directory ships with the package in
/usr/share, third-party collectors and plugins (such as custom usage plugins) cannot ship or install custom marks without needing sudo, and their assets get wiped during system upgrades.Changes
iconandiconLightfrom the usage record indisplayProvider()inMain.qml. When present in the record,iconCandidatesForProvider()probes them first.~/.config/omarchy/agents/assets/<id>.svg(and-light.svg) so users and third-party plugins can install SVG brand marks without root.test/shell.d/agents-panel-test.shto verify record-carried icon propagation and user assets directory candidate resolution, and documented the extension points inshell/plugins/agents/README.md.Verification
test/shell.d/agents-panel-test.shlocally and in Arch Linux container (CT 201) — 10/10 checks passed.test/shell.d/agent-*.sh) — 100% passed.