Skip to content

Commit 99a2434

Browse files
authored
refactor(macos): status menu polish — owned width, quiet header, structured diagnostics, native highlight (#130388)
* fix(macos): stabilize status menu width across hosted and native rows * fix(macos): format node worker termination status without optionals * refactor(macos): give status menu width one owner fittedTitle's hasImage/hasSubmenu/keyEquivalent parameters never changed the computation - the budget always included image, submenu, and shortcut chrome - because AppKit aligns those columns across the whole menu, so a per-item budget is the wrong model. Collapse to one menu-wide budget and drop the misleading knobs from all 13 call sites. * refactor(macos): keep the status menu header quiet when healthy A working system now says nothing: the header renders only operator- actionable trouble lines (colored text, no status bubbles), the healthy state is title + toggle + capability strip, and the churn sources that made the open menu jump are gone - relative check ages, 'health check running', and the per-tool activity label (the critter icon already animates work). Session-row kind icons go monochrome; green conveyed nothing actionable. Healthy title is 'OpenClaw' (or the primary gateway name with multiple gateways) since the toggle already communicates active. DashboardGatewayMenuModel.connectionLabel lost its last caller and is deleted with its test. * fix(macos): preserve structured node worker diagnostics in status menu * feat(macos): highlight hosted menu rows from AppKit's selection signal AppKit paints no selection behind NSMenuItem.view, so hosted session and device rows had no hover or keyboard highlight. HostedMenuRowView now draws the native selection material (rounded, emphasized) and flips the SwiftUI content through the existing menuItemHighlighted environment, driven by NSMenuDelegate.menu(_:willHighlight:) so pointer and arrow-key navigation both light up. Submenus get a shared highlight-only delegate; the controller's root-menu guards keep open/refresh paths unaffected. * refactor(macos): drop the manual Open Canvas action Canvas panels are agent-opened; a manual open action was noise. The Allow Canvas capability tile stays - that is the permission. Removes the menu action, the dock-menu item, and the now-orphaned AppNavigationActions.toggleCanvas. * fix(macos): clear hosted submenu selection when the submenu closes AppKit sends no willHighlight(nil) on submenu close, so a hosted device row selected there reopened still lit. The shared highlight delegate now resets its menu's hosted rows in menuDidClose; regression covers the close cycle. * style(macos): apply swiftformat to highlight delegate
1 parent f0ab89e commit 99a2434

28 files changed

Lines changed: 697 additions & 399 deletions

‎apps/.i18n/native-source.json‎

Lines changed: 6 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎apps/macos/Sources/OpenClaw/AppNavigationActions.swift‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ enum AppNavigationActions {
3030
}
3131
}
3232

33-
static func toggleCanvas() {
34-
NSApp.activate(ignoringOtherApps: true)
35-
Task { @MainActor in
36-
if AppStateStore.shared.canvasPanelVisible {
37-
CanvasManager.shared.hideAll()
38-
} else {
39-
let sessionKey = await GatewayConnection.shared.mainSessionKey()
40-
_ = try? CanvasManager.shared.show(sessionKey: sessionKey, path: nil)
41-
}
42-
}
43-
}
44-
4533
static func openSettings(tab: SettingsTab = .general) {
4634
SettingsTabRouter.request(tab)
4735
SettingsWindowOpener.shared.open()

‎apps/macos/Sources/OpenClaw/ContextRingView.swift‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,19 @@ struct ContextRingView: View {
4747
static let compactThreshold = 0.90
4848

4949
let percentUsed: Double
50+
@Environment(\.menuItemHighlighted) private var isHighlighted
5051

5152
var body: some View {
5253
let style = ContextRingStyle(ratio: self.percentUsed / 100)
54+
let fillColor = self.isHighlighted ? MenuItemHighlightColors.palette(true).secondary : style.fillColor
5355

5456
HStack(spacing: 4) {
5557
ZStack {
5658
Circle()
57-
.stroke(style.fillColor.opacity(0.22), lineWidth: 2.5)
59+
.stroke(fillColor.opacity(0.22), lineWidth: 2.5)
5860
Circle()
5961
.trim(from: 0, to: min(max(style.ratio, 0), 1))
60-
.stroke(style.fillColor, style: StrokeStyle(lineWidth: 2.5, lineCap: .round))
62+
.stroke(fillColor, style: StrokeStyle(lineWidth: 2.5, lineCap: .round))
6163
.rotationEffect(.degrees(-90))
6264
}
6365
.frame(width: 13, height: 13)
@@ -66,7 +68,7 @@ struct ContextRingView: View {
6668
if style.showsLabel {
6769
Text("\(style.percent)%")
6870
.font(.caption2.monospacedDigit())
69-
.foregroundStyle(style.fillColor)
71+
.foregroundStyle(fillColor)
7072
}
7173
}
7274
.accessibilityElement(children: .ignore)

‎apps/macos/Sources/OpenClaw/ContextUsageBar.swift‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import SwiftUI
33
struct ContextUsageBar: View {
44
let usedTokens: Int
55
let contextTokens: Int
6-
var width: CGFloat?
76
var height: CGFloat = 6
87

98
private static let okGreen: NSColor = .init(name: nil) { appearance in
@@ -44,19 +43,11 @@ struct ContextUsageBar: View {
4443
}
4544

4645
var body: some View {
47-
let fraction = self.clampedFractionUsed
48-
Group {
49-
if let width = self.width, width > 0 {
50-
self.barBody(width: width, fraction: fraction)
51-
.frame(width: width, height: self.height)
52-
} else {
53-
GeometryReader { proxy in
54-
self.barBody(width: proxy.size.width, fraction: fraction)
55-
.frame(width: proxy.size.width, height: self.height)
56-
}
57-
.frame(height: self.height)
58-
}
46+
GeometryReader { proxy in
47+
self.barBody(width: proxy.size.width, fraction: self.clampedFractionUsed)
48+
.frame(width: proxy.size.width, height: self.height)
5949
}
50+
.frame(height: self.height)
6051
.accessibilityLabel("Context usage")
6152
.accessibilityValue(self.accessibilityValue)
6253
}

‎apps/macos/Sources/OpenClaw/CostUsageMenuView.swift‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import SwiftUI
33

44
struct CostUsageHistoryMenuView: View {
55
let summary: GatewayCostUsageSummary
6-
let width: CGFloat
76

87
var body: some View {
98
VStack(alignment: .leading, spacing: 10) {
@@ -13,7 +12,7 @@ struct CostUsageHistoryMenuView: View {
1312
}
1413
.padding(.horizontal, 12)
1514
.padding(.vertical, 10)
16-
.frame(width: max(1, self.width), alignment: .leading)
15+
.frame(maxWidth: .infinity, alignment: .leading)
1716
}
1817

1918
private var header: some View {

‎apps/macos/Sources/OpenClaw/DashboardGatewayMenuModel.swift‎

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -27,51 +27,4 @@ enum DashboardGatewayMenuModel {
2727
shortcutNumber: index < 9 ? index + 1 : nil)
2828
}
2929
}
30-
31-
static func connectionLabel(
32-
mode: AppState.ConnectionMode,
33-
controlState: ControlChannel.ConnectionState,
34-
entries: [DashboardGatewayEntry]) -> String
35-
{
36-
guard entries.count >= 2,
37-
let primaryName = entries.first(where: \.isPrimary)?.name.nonEmpty
38-
else {
39-
return switch mode {
40-
case .unconfigured:
41-
String(localized: "OpenClaw Not Configured")
42-
case .remote:
43-
self.remoteConnectionLabel(state: controlState)
44-
case .local:
45-
String(localized: "OpenClaw Active")
46-
}
47-
}
48-
return switch mode {
49-
case .unconfigured:
50-
String(localized: "OpenClaw Not Configured — \(primaryName)")
51-
case .remote:
52-
self.remoteConnectionLabel(state: controlState, primaryName: primaryName)
53-
case .local:
54-
String(localized: "OpenClaw Active — \(primaryName)")
55-
}
56-
}
57-
58-
private static func remoteConnectionLabel(
59-
state: ControlChannel.ConnectionState,
60-
primaryName: String? = nil) -> String
61-
{
62-
switch (state, primaryName) {
63-
case (.connected, nil):
64-
String(localized: "Remote OpenClaw Active")
65-
case let (.connected, .some(name)):
66-
String(localized: "Remote OpenClaw Active — \(name)")
67-
case (.connecting, nil):
68-
String(localized: "Remote OpenClaw Connecting")
69-
case let (.connecting, .some(name)):
70-
String(localized: "Remote OpenClaw Connecting — \(name)")
71-
case (.disconnected, nil), (.degraded, nil):
72-
String(localized: "Remote OpenClaw Needs Attention")
73-
case let (.disconnected, .some(name)), let (.degraded, .some(name)):
74-
String(localized: "Remote OpenClaw Needs Attention — \(name)")
75-
}
76-
}
7730
}

‎apps/macos/Sources/OpenClaw/MenuBar.swift‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
236236
title: "Open Dashboard",
237237
systemImage: "gauge",
238238
action: #selector(self.openDashboardFromDockMenu(_:))))
239-
let canvasTitle = AppStateStore.shared.canvasPanelVisible ? "Close Canvas" : "Open Canvas"
240-
let canvasItem = self.dockMenuItem(
241-
title: canvasTitle,
242-
systemImage: "rectangle.inset.filled.on.rectangle",
243-
action: #selector(self.toggleCanvasFromDockMenu(_:)))
244-
canvasItem.isEnabled = AppStateStore.shared.canvasEnabled
245-
menu.addItem(canvasItem)
246239
menu.addItem(.separator())
247240
menu.addItem(self.dockMenuItem(
248241
title: "Settings…",
@@ -263,11 +256,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
263256
self.openDashboardAction()
264257
}
265258

266-
@objc
267-
private func toggleCanvasFromDockMenu(_: Any?) {
268-
AppNavigationActions.toggleCanvas()
269-
}
270-
271259
@objc
272260
private func openSettingsFromDockMenu(_: Any?) {
273261
AppNavigationActions.openSettings()

‎apps/macos/Sources/OpenClaw/NodeMode/MacNodeChannelStatusStore.swift‎

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ enum MacNodeChannelState: Equatable, Sendable {
1010
case idle
1111
/// The channel connected. A non-nil reason means the node-host worker is
1212
/// unavailable and only native capabilities are advertised.
13-
case connected(workerUnavailableReason: String?)
13+
case connected(workerUnavailableReason: String?, diagnostic: String? = nil)
1414
/// The last connect attempt failed; the coordinator keeps retrying.
15-
case unavailable(reason: String)
15+
case unavailable(reason: String, diagnostic: String? = nil)
1616

17-
var operatorStatusLine: (label: String, isDegraded: Bool)? {
17+
var operatorStatusLine: (label: String, diagnostic: String?, isDegraded: Bool)? {
1818
switch self {
19-
case .idle, .connected(workerUnavailableReason: nil):
19+
case .idle, .connected(workerUnavailableReason: nil, diagnostic: _):
2020
nil
21-
case let .connected(workerUnavailableReason: .some(reason)):
22-
("Mac node degraded — \(Self.condense(reason))", true)
23-
case let .unavailable(reason):
24-
("Mac node unavailable — \(Self.condense(reason))", false)
21+
case let .connected(workerUnavailableReason: .some(reason), diagnostic: diagnostic):
22+
("Mac node degraded — \(Self.condense(reason))", Self.excerpt(diagnostic), true)
23+
case let .unavailable(reason, diagnostic):
24+
("Mac node unavailable — \(Self.condense(reason))", Self.excerpt(diagnostic), false)
2525
}
2626
}
2727

@@ -34,6 +34,35 @@ enum MacNodeChannelState: Equatable, Sendable {
3434
.map { $0.trimmingCharacters(in: .whitespaces) } ?? reason
3535
return firstLine.count > 220 ? firstLine.prefix(220) + "…" : firstLine
3636
}
37+
38+
/// Preserve complete stderr lines whenever possible so truncation cannot
39+
/// turn a useful CLI diagnostic into another clipped headline fragment.
40+
private static func excerpt(_ diagnostic: String?) -> String? {
41+
guard let diagnostic = diagnostic?.trimmingCharacters(in: .whitespacesAndNewlines).nonEmpty else {
42+
return nil
43+
}
44+
let lines = diagnostic.split(separator: "\n", omittingEmptySubsequences: false)
45+
let needsEllipsis = diagnostic.count > 360 || lines.count > 4
46+
let maximumLength = needsEllipsis ? 359 : 360
47+
var retainedLines: [Substring] = []
48+
var retainedLength = 0
49+
50+
for line in lines.prefix(4) {
51+
let length = retainedLength + (retainedLines.isEmpty ? 0 : 1) + line.count
52+
guard length <= maximumLength else { break }
53+
retainedLines.append(line)
54+
retainedLength = length
55+
}
56+
57+
if retainedLines.isEmpty {
58+
let prefix = diagnostic.prefix(maximumLength)
59+
let boundary = prefix.lastIndex(where: \.isWhitespace) ?? prefix.endIndex
60+
return "\(prefix[..<boundary])…"
61+
}
62+
63+
let excerpt = retainedLines.joined(separator: "\n")
64+
return retainedLines.count == lines.count ? excerpt : "\(excerpt)…"
65+
}
3766
}
3867

3968
@MainActor

‎apps/macos/Sources/OpenClaw/NodeMode/MacNodeHostWorker.swift‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,15 @@ final class MacNodeHostWorker: MacNodeHostWorking, @unchecked Sendable {
7777
}
7878

7979
enum WorkerError: LocalizedError {
80-
case unavailable(String)
80+
case unavailable(reason: String, diagnostic: String? = nil)
8181

8282
var errorDescription: String? {
8383
switch self {
84-
case let .unavailable(message): message
84+
case let .unavailable(reason, diagnostic):
85+
diagnostic?
86+
.split(separator: "\n", omittingEmptySubsequences: true)
87+
.first
88+
.map { "\(reason): \($0)" } ?? reason
8589
}
8690
}
8791
}
@@ -140,7 +144,8 @@ final class MacNodeHostWorker: MacNodeHostWorking, @unchecked Sendable {
140144
return
141145
}
142146
guard self.startContinuation == nil else {
143-
continuation.resume(throwing: WorkerError.unavailable("node-host worker is already starting"))
147+
continuation.resume(throwing: WorkerError.unavailable(
148+
reason: "node-host worker is already starting"))
144149
return
145150
}
146151
self.startContinuation = continuation
@@ -337,7 +342,7 @@ final class MacNodeHostWorker: MacNodeHostWorking, @unchecked Sendable {
337342
private func startLocked(launch: MacNodeHostWorkerLaunch) {
338343
let command = launch.command
339344
guard let executable = command.first, !executable.isEmpty else {
340-
self.finishStartLocked(.failure(WorkerError.unavailable("node-host worker command missing")))
345+
self.finishStartLocked(.failure(WorkerError.unavailable(reason: "node-host worker command missing")))
341346
return
342347
}
343348
if self.process != nil {
@@ -355,7 +360,7 @@ final class MacNodeHostWorker: MacNodeHostWorking, @unchecked Sendable {
355360
let stdoutPipe = Pipe()
356361
let stderrPipe = Pipe()
357362
guard stdinPipe.fileHandleForWriting.disableSIGPIPE() else {
358-
self.finishStartLocked(.failure(WorkerError.unavailable("could not protect worker input pipe")))
363+
self.finishStartLocked(.failure(WorkerError.unavailable(reason: "could not protect worker input pipe")))
359364
return
360365
}
361366
var environment = ProcessInfo.processInfo.environment.filter { key, _ in
@@ -380,7 +385,8 @@ final class MacNodeHostWorker: MacNodeHostWorking, @unchecked Sendable {
380385
guard let self else { return }
381386
let state = self.process?.isRunning == true ? "running" : "exited"
382387
self.finishStartLocked(.failure(WorkerError.unavailable(
383-
"node-host worker startup timed out (process \(state), buffered \(self.stdoutBuffer.count) bytes)")))
388+
reason: "node-host worker startup timed out (process \(state), " +
389+
"buffered \(self.stdoutBuffer.count) bytes)")))
384390
self.stopLocked(reason: "worker startup timed out", notifyUnexpectedExit: true)
385391
}
386392
self.startTimer = timer
@@ -468,7 +474,8 @@ final class MacNodeHostWorker: MacNodeHostWorking, @unchecked Sendable {
468474
self.processCleanupTask == nil
469475
else { return }
470476
self.stopLocked(
471-
reason: "worker exited with status \(String(describing: status))",
477+
reason: status.map { String(localized: "worker exited with status \(String(describing: $0))") }
478+
?? String(localized: "worker exited with unknown status"),
472479
notifyUnexpectedExit: true)
473480
}
474481
}
@@ -598,7 +605,7 @@ final class MacNodeHostWorker: MacNodeHostWorking, @unchecked Sendable {
598605
{
599606
do {
600607
guard let paramsJSON = String(bytes: paramsData, encoding: .utf8) else {
601-
throw WorkerError.unavailable("node-host worker gateway request was not UTF-8")
608+
throw WorkerError.unavailable(reason: "node-host worker gateway request was not UTF-8")
602609
}
603610
let data = try await self.session.request(
604611
method: method,
@@ -692,7 +699,7 @@ final class MacNodeHostWorker: MacNodeHostWorking, @unchecked Sendable {
692699
self.process?.isRunning == true,
693700
let processGeneration = self.processGeneration
694701
else {
695-
throw WorkerError.unavailable("node-host worker is not running")
702+
throw WorkerError.unavailable(reason: "node-host worker is not running")
696703
}
697704
var data = try JSONSerialization.data(withJSONObject: object)
698705
data.append(0x0A)
@@ -732,7 +739,7 @@ final class MacNodeHostWorker: MacNodeHostWorking, @unchecked Sendable {
732739
// A worker that dies before its ready manifest still needs its stderr
733740
// surfaced: the raw exit status alone cannot explain a CLI bootstrap
734741
// refusal (missing runtime, incompatible state database, bad install).
735-
let detailedReason = self.stderrHead.isEmpty ? reason : "\(reason): \(self.stderrHead)"
742+
let diagnostic = self.stderrHead.nonEmpty
736743
self.stderrHead = ""
737744
self.startTimer?.cancel()
738745
self.startTimer = nil
@@ -742,7 +749,7 @@ final class MacNodeHostWorker: MacNodeHostWorking, @unchecked Sendable {
742749
self.inventoryData = nil
743750
self.route = nil
744751
if !preserveStart {
745-
self.finishStartLocked(.failure(WorkerError.unavailable(detailedReason)))
752+
self.finishStartLocked(.failure(WorkerError.unavailable(reason: reason, diagnostic: diagnostic)))
746753
}
747754
if let processCleanupTask = self.processCleanupTask { return processCleanupTask }
748755
let pending = self.invokeContinuations

0 commit comments

Comments
 (0)