Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Android/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ platform=${ANDROID_PLATFORM:-35}
jar=$sdk/platforms/android-$platform/android.jar
[ -f "$jar" ] || { echo "No $jar: install the platform with sdkmanager \"platforms;android-$platform\"." >&2; exit 1; }
tools=$(ls -d "$sdk"/build-tools/* | sort -V | tail -1)
version=${APP_VERSION:-0.9.13}
version=${APP_VERSION:-0.9.14}
IFS=. read -r major minor patch <<<"$version.0.0"
code=$((major * 10000 + minor * 100 + ${patch%%[^0-9]*}))

Expand Down
5 changes: 4 additions & 1 deletion App/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,10 @@ enum MenuBarIcon {

final class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
Task { @MainActor in AppStore.shared.bootstrap() }
Task { @MainActor in
AppStore.shared.bootstrap()
PinnedStrip.shared.restore()
}
}

/// Usage is saved a few seconds after each request; whatever is still waiting is saved before quitting.
Expand Down
4 changes: 3 additions & 1 deletion App/CommandPalette.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ enum CommandPalette {
/// - "gizmo-explain": Explain mode on the page showing (Gizmo explains whatever the pointer is on);
/// - "setup-fix:<fix>": a button of the Setup page or of Welcome's tour (App/SetupMap.swift, `SetupMap.fix`);
/// - "tour": Welcome, on the first step of Gizmo's tour;
/// - "connect-agent", "add-engine", "watch-live" (Performance with Watch live on), "login" (start at login), "setup:show" (Welcome).
/// - "connect-agent", "add-engine", "pin-strip" (the pinned strip, shown or put away), "watch-live" (Performance with Watch live on), "login" (start at login), "setup:show" (Welcome).
let action: String
}

Expand Down Expand Up @@ -124,6 +124,8 @@ enum CommandPalette {
tone: "violet", action: "page:mesh"),
Item(id: "add-engine", group: .actions, title: "Add a Server on Another Port", detail: mac ? "saved engine" : "Engines",
keywords: "engine port address", tone: "violet", action: "add-engine"),
Item(id: "pin-strip", group: .actions, title: "Pin a Strip Above Other Windows", detail: "speed, queue, GPU and power while you work elsewhere",
keywords: "pinned strip always on top float mini small window overlay hud", tone: "violet", action: "pin-strip"),
Item(id: "watch-live", group: .actions, title: "Watch Live", detail: "answers streaming through an Engine Proxy, piece by piece",
keywords: "waterfall stream streaming tokens pieces live proxy", tone: "violet", action: "watch-live"),
Item(id: "setup", group: .actions, title: "Show Welcome", detail: "what Tokenmeter is for, and getting set up",
Expand Down
2 changes: 2 additions & 0 deletions App/CommandPaletteView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ extension AppStore {
page = .agents
case "add-engine":
EngineConfigStore.shared.editing = .init(original: nil)
case "pin-strip":
PinnedStrip.shared.toggle()
case "watch-live":
LiveWatch.shared.set(on: true)
page = .performance
Expand Down
30 changes: 30 additions & 0 deletions App/PinnedStripFigures.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Foundation

/// What the pinned strip shows, cell by cell: the same words on the Mac and in the KDE app (ui/PinnedStrip.qml).
enum PinnedStripFigures {
struct Cell: Identifiable, Equatable {
/// "speed", "queue", "gpu" or "power".
var id: String
var label: String
var value: String
var unit: String
/// A tone of the Machine Room: "green", "blue", "amber", "violet" or "grey".
var tone: String
/// For a screen reader: "Speed: 218.1 tok/s".
var spoken: String { label + ": " + value + (unit.isEmpty ? "" : " " + unit) }
}

/// `serving` is how many servers are up with a model; a figure nobody reports is a dash, never a zero.
static func cells(connected: Bool, serving: Int, speed: Double, waiting: Int, gpuPercent: Double?, watts: Double?) -> [Cell] {
let none = "—"
return [
Cell(id: "speed", label: "Speed", value: !connected ? none : serving == 0 ? "idle" : String(format: "%.1f", speed),
unit: connected && serving > 0 ? "tok/s" : "", tone: connected && speed > 0 ? "green" : "grey"),
Cell(id: "queue", label: "Queue", value: connected && serving > 0 ? String(waiting) : none, unit: connected && serving > 0 ? "waiting" : "",
tone: waiting >= 3 ? "amber" : waiting > 0 ? "blue" : "grey"),
Cell(id: "gpu", label: "GPU", value: gpuPercent.map { String(format: "%.0f%%", $0) } ?? none, unit: "",
tone: (gpuPercent ?? 0) >= 90 ? "amber" : "violet"),
Cell(id: "power", label: "Power", value: watts.map { String(format: "%.0f", $0) } ?? none, unit: watts == nil ? "" : "W", tone: "amber"),
]
}
}
102 changes: 102 additions & 0 deletions App/PinnedStripView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import AppKit
import SwiftUI

/// The pinned strip: a small panel that floats above the other windows with the speed, the queue, the GPU and
/// the power, for watching a model while working somewhere else. The figures are the menu bar's. Drag it
/// anywhere; a click opens the main window; × puts it away. The command palette shows and hides it.
@MainActor
final class PinnedStrip {
static let shared = PinnedStrip()
private static let shownKey = "pinnedStripShown"
private var panel: NSPanel?

var isShown: Bool { panel?.isVisible ?? false }

/// Back where it was left, when it was showing as Tokenmeter was last quit.
func restore() {
if Prefs.defaults.bool(forKey: Self.shownKey) { show() }
}

func toggle() {
if isShown { hide() } else { show() }
}

func show() {
let panel = self.panel ?? make()
self.panel = panel
panel.orderFrontRegardless()
Prefs.defaults.set(true, forKey: Self.shownKey)
}

func hide() {
panel?.orderOut(nil)
Prefs.defaults.set(false, forKey: Self.shownKey)
}

private func make() -> NSPanel {
let panel = NSPanel(contentRect: NSRect(x: 0, y: 0, width: 430, height: 44),
styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
panel.level = .floating
panel.isFloatingPanel = true
panel.hidesOnDeactivate = false
panel.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]
panel.isMovableByWindowBackground = true
panel.backgroundColor = .clear
panel.isOpaque = false
panel.hasShadow = true
panel.title = "Tokenmeter Strip"
let host = NSHostingView(rootView: PinnedStripView().preferredColorScheme(.dark))
panel.contentView = host
panel.setContentSize(host.fittingSize)
// Its place is kept by AppKit under this name; the first time it goes to the top right corner.
if !panel.setFrameUsingName("TokenmeterPinnedStrip"), let screen = NSScreen.main {
let frame = screen.visibleFrame
panel.setFrameTopLeftPoint(NSPoint(x: frame.maxX - panel.frame.width - 24, y: frame.maxY - 24))
}
panel.setFrameAutosaveName("TokenmeterPinnedStrip")
return panel
}
}

struct PinnedStripView: View {
@ObservedObject private var monitor = EngineMonitor.shared
@Environment(\.openWindow) private var openWindow

var body: some View {
let cells = PinnedStripFigures.cells(connected: true, serving: monitor.servers.filter(\.isUp).count, speed: monitor.totalThroughput,
waiting: monitor.deferredRequests, gpuPercent: monitor.gpu.utilization, watts: monitor.power?.watts)
HStack(spacing: 14) {
ForEach(cells) { cell in
HStack(spacing: 5) {
Circle().fill(RoomColors.of(cell.tone)).frame(width: 6, height: 6)
Text(cell.label).font(.system(size: 10)).foregroundStyle(RoomColors.muted)
Text(cell.value).font(.system(size: 14, weight: .semibold)).monospacedDigit().foregroundStyle(RoomColors.ink)
if !cell.unit.isEmpty { Text(cell.unit).font(.system(size: 10)).foregroundStyle(RoomColors.muted) }
}
.accessibilityElement(children: .ignore)
.accessibilityLabel(cell.spoken)
}
Button {
PinnedStrip.shared.hide()
} label: {
Image(systemName: "xmark").font(.system(size: 9, weight: .bold)).foregroundStyle(RoomColors.muted)
}
.buttonStyle(.plain)
.help("Put the strip away. The command palette (⌘K) brings it back.")
.accessibilityLabel("Put the strip away")
}
.padding(.horizontal, 14).frame(height: 44)
.background(RoundedRectangle(cornerRadius: 10).fill(RoomColors.surface))
.overlay(RoundedRectangle(cornerRadius: 10).strokeBorder(RoomColors.line))
.onTapGesture(count: 2) {
// The main window if it is open somewhere; else a new one.
if let window = NSApp.windows.first(where: { $0.identifier?.rawValue.hasPrefix("main") == true }) {
window.makeKeyAndOrderFront(nil)
} else {
openWindow(id: "main")
}
NSApp.activate(ignoringOtherApps: true)
}
.help("Double-click to open Tokenmeter. Drag to move.")
}
}
2 changes: 1 addition & 1 deletion App/StatusJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ struct LocalResponse {
extension StatusReport {
/// Tokenmeter's version. The Mac app reads it from its Info.plist, which build-library-app.sh writes; the
/// Linux service has no Info.plist, so it uses `releaseVersion`. Keep that in step with the build scripts.
static let releaseVersion = "0.9.13"
static let releaseVersion = "0.9.14"
static var appVersion: String {
Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? releaseVersion
}
Expand Down
2 changes: 1 addition & 1 deletion Linux/kde/app/AppVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
// update keeps saying the version it is, while the service reports its own (backend.snapshot.version).
// scripts/package-linux.sh and package-flatpak.sh write it from the package's version; keep it in step with
// StatusReport.releaseVersion when bumping (a unit test checks it).
var version = "0.9.13"
var version = "0.9.14"
12 changes: 12 additions & 0 deletions Linux/kde/app/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ ApplicationWindow {
current = "agents"; agentsSlot.active = true
Qt.callLater(function () { agentsSlot.item.connectAgent(rest) })
break
case "pin-strip": pinnedStrip.toggle(); break
case "watch-live":
current = "performance"; performanceSlot.active = true
Qt.callLater(function () { performanceSlot.item.watchLive() })
Expand Down Expand Up @@ -277,6 +278,17 @@ ApplicationWindow {
function onActionRequested(action) { window.perform(action) }
}

// The pinned strip (speed, queue, GPU, power above the other windows): the command palette shows and hides it,
// `--strip` opens it with the window (for pictures and the checks), and it comes back if it was left showing.
PinnedStrip {
id: pinnedStrip
backend: window.service
onOpenRequested: { window.show(); window.raise(); window.requestActivate() }
Component.onCompleted: {
if (Qt.application.arguments.indexOf("--strip") >= 0) show_()
else if (Qt.application.arguments.indexOf("--mock") < 0) restore()
}
}
CommandPalette {
id: commandPalette
parent: Overlay.overlay
Expand Down
2 changes: 1 addition & 1 deletion Linux/kde/mock/machines.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"report": {
"schema": 1,
"app": "Tokenmeter",
"version": "0.9.13",
"version": "0.9.14",
"host": "studio",
"chip": "Apple M3 Ultra",
"time": "2026-11-13T19:00:00Z",
Expand Down
2 changes: 1 addition & 1 deletion Linux/kde/mock/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"addresses": [
"192.168.1.20"
],
"version": "0.9.13",
"version": "0.9.14",
"shareHistory": false,
"footprint": {
"cpuPercent": 0.4,
Expand Down
2 changes: 1 addition & 1 deletion Linux/kde/plasmoid/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Icon": "tokenmeter",
"Category": "System Information",
"License": "Apache-2.0",
"Version": "0.9.13",
"Version": "0.9.14",
"Website": "https://github.com/tokenmeter1/Tokenmeter"
},
"X-Plasma-API-Minimum-Version": "6.0",
Expand Down
113 changes: 113 additions & 0 deletions Linux/kde/ui/PinnedStrip.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Window
import "Format.js" as Format
import "Look"

// The pinned strip: a small window that stays above the others with the speed, the queue, the GPU and the power,
// for watching a model while working somewhere else. The figures are the ones the notification area icon and the
// sidebar show: every server that is up, here and on the connected machines. Drag it anywhere; a click on the
// figures opens the main window; × puts it away. It asks the service nothing of its own.
Window {
id: strip
property Backend backend
// Remembered across launches: whether it is shown, and where ("x,y").
property var kept: backend ? backend.keptSettings("PinnedStrip", "place") : null
property var keptShown: backend ? backend.keptSettings("PinnedStrip", "shown") : null
signal openRequested()

readonly property var room: Format.room
readonly property var tones: Format.darkTones
// This computer's servers that are up, then the connected machines'.
readonly property var up: !backend ? [] : backend.online.filter(Format.serving)
.concat(backend.remoteCards.filter(function (c) { return Format.serving(c.server) }).map(function (c) { return c.server }))
readonly property real speed: up.reduce(function (sum, s) { return sum + (s.generationTPS || 0) }, 0)
readonly property int waiting: up.reduce(function (sum, s) { return sum + (s.deferredRequests || 0) }, 0)
readonly property int working: up.reduce(function (sum, s) { return sum + (s.activeRequests || 0) }, 0)
readonly property var system: backend ? backend.system : ({})
// What each cell says, for the screen reader and the drills: "218.1 tok/s", "1 waiting", "GPU 74%", "312 W".
readonly property var cells: [
{ id: "speed", label: "Speed", value: !backend || !backend.connected ? "—" : up.length === 0 ? "idle" : speed.toFixed(1), unit: up.length === 0 ? "" : "tok/s",
tone: speed > 0 ? tones.green : room.muted },
{ id: "queue", label: "Queue", value: up.length === 0 ? "—" : String(waiting), unit: up.length === 0 ? "" : "waiting",
tone: waiting >= 3 ? tones.amber : waiting > 0 ? tones.blue : room.muted, detail: working > 0 ? working + " running" : "" },
{ id: "gpu", label: "GPU", value: system.gpuPercent === undefined || system.gpuPercent === null ? "—" : Math.round(system.gpuPercent) + "%", unit: "",
tone: (system.gpuPercent || 0) >= 90 ? tones.amber : tones.violet },
{ id: "power", label: "Power", value: system.powerWatts === undefined || system.powerWatts === null ? "—" : Math.round(system.powerWatts), unit: system.powerWatts === undefined || system.powerWatts === null ? "" : "W",
tone: tones.amber }
]

title: "Tokenmeter Strip"
flags: Qt.Tool | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
color: "transparent"
width: row.implicitWidth + 20
height: 44

// Whether it stands where the person left it; until then it keeps to the top right corner as its figures widen it.
property bool placed: false
function corner() { x = Screen.virtualX + Screen.width - width - 24; y = Screen.virtualY + 48 }
onWidthChanged: if (visible && !placed) corner()
function show_() {
var at = kept && kept.place ? String(kept.place).split(",") : []
placed = at.length === 2 && !isNaN(parseInt(at[0])) && !isNaN(parseInt(at[1]))
if (placed) { x = parseInt(at[0]); y = parseInt(at[1]) } else corner()
visible = true
raise()
}
function toggle() { if (visible) visible = false; else show_() }
// Back where it was left, when it was showing as Tokenmeter was last closed.
function restore() { if (keptShown && keptShown.shown === "yes") show_() }
onVisibleChanged: if (keptShown) keptShown.shown = visible ? "yes" : "no"
function remember() { if (kept && visible && placed) kept.place = x + "," + y }
onXChanged: remember()
onYChanged: remember()

Rectangle {
anchors.fill: parent
radius: 10
color: strip.room.surface
border.color: strip.room.line; border.width: 1

// Dragging anywhere moves it; a click that didn't move opens the main window.
MouseArea {
anchors.fill: parent
property point pressed
property bool moved: false
cursorShape: Qt.OpenHandCursor
onPressed: function (mouse) { pressed = Qt.point(mouse.x, mouse.y); moved = false }
onPositionChanged: function (mouse) {
if (!moved && Math.abs(mouse.x - pressed.x) + Math.abs(mouse.y - pressed.y) > 6) { moved = true; strip.placed = true; strip.startSystemMove() }
}
onClicked: if (!moved) strip.openRequested()
}

RowLayout {
id: row
anchors.centerIn: parent
spacing: 14
Repeater {
model: strip.cells
RowLayout {
objectName: "strip_" + modelData.id
spacing: 5
Accessible.role: Accessible.StaticText
Accessible.name: modelData.label + ": " + modelData.value + (modelData.unit ? " " + modelData.unit : "")
Rectangle { width: 6; height: 6; radius: 3; color: modelData.tone }
Label { text: modelData.label; font.pixelSize: Look.px(10); color: strip.room.muted }
Label { text: modelData.value; font.pixelSize: Look.px(14); font.weight: Font.DemiBold; color: strip.room.ink }
Label { visible: modelData.unit !== ""; text: modelData.unit; font.pixelSize: Look.px(10); color: strip.room.muted }
}
}
ToolButton {
objectName: "stripClose"
text: "×"
flat: true
implicitWidth: 22; implicitHeight: 22
Accessible.name: "Put the strip away"
ToolTip.visible: hovered; ToolTip.delay: 600; ToolTip.text: "Put the strip away. The command palette (Ctrl K) brings it back."
onClicked: strip.visible = false
}
}
}
}
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let sources = [
"App/AgentTrace.swift",
"App/ToolStats.swift",
"App/Facility.swift",
"App/Insights.swift", "App/UnnamedCallers.swift", "App/Changes.swift", "App/Forecasts.swift", "App/Visibility.swift", "App/Topology.swift",
"App/Insights.swift", "App/UnnamedCallers.swift", "App/PinnedStripFigures.swift", "App/Changes.swift", "App/Forecasts.swift", "App/Visibility.swift", "App/Topology.swift",
"App/Fleet.swift",
"App/Mesh.swift",
"App/MeshCrypto.swift",
Expand Down
Loading
Loading