@join-pantheon/cli 0.34.0 → 0.34.1-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin-founder.js +179 -0
- package/dist/admin-pages.js +249 -116
- package/dist/admin-ui.js +149 -73
- package/dist/board.js +30 -3
- package/dist/claude-confine.js +3 -2
- package/dist/cli.js +75 -5
- package/dist/client.js +31 -3
- package/dist/config.js +21 -0
- package/dist/conn-report.js +148 -0
- package/dist/doctor.js +13 -0
- package/dist/flow-stats.js +21 -18
- package/dist/founder-stats.js +203 -0
- package/dist/goal-flow.js +218 -0
- package/dist/home-safety.js +2 -0
- package/dist/machine.js +95 -2
- package/dist/mcp.js +6 -0
- package/dist/notifier.js +166 -101
- package/dist/power.js +66 -0
- package/dist/readiness-alert.js +16 -3
- package/dist/relay.js +303 -23
- package/dist/spend.js +24 -1
- package/dist/status-engine.js +222 -0
- package/dist/status-nudge.js +34 -0
- package/dist/tray.js +57 -7
- package/dist/viewer-pages.js +36 -29
- package/dist/win-host.js +79 -7
- package/dist/worker.js +17 -8
- package/helper/macos/main.swift +45 -12
- package/helper/macos/menubar.swift +409 -67
- package/helper/macos/prebuilt/manifest.json +6 -6
- package/helper/macos/prebuilt/pantheon-hud +0 -0
- package/helper/macos/prebuilt/pantheon-tray +0 -0
- package/helper/windows/pantheon-tray.ps1 +216 -15
- package/package.json +1 -1
|
@@ -5,11 +5,19 @@
|
|
|
5
5
|
* remember to type `pantheon ps`. This puts that answer where WARP puts its
|
|
6
6
|
* toggle: one glyph in the menu bar, one menu, one pause/resume.
|
|
7
7
|
*
|
|
8
|
-
* Deliberately a THIN SHELL: every fact comes from
|
|
8
|
+
* Deliberately a THIN SHELL: every fact comes from the CLI's tray status (JSON)
|
|
9
9
|
* and every action is a pantheon command, so the CLI stays the single source of
|
|
10
10
|
* truth and this file never grows business logic. No network of its own, no
|
|
11
11
|
* state of its own, no credentials — it cannot leak what it never holds.
|
|
12
12
|
*
|
|
13
|
+
* Where the status comes from (0.34.1, DataLoop below): its parent, `pantheon
|
|
14
|
+
* menubar`, computes it and writes it down this process's stdin, one JSON line
|
|
15
|
+
* per change and at least every 15 s (60 s on battery) — after this helper says
|
|
16
|
+
* `@hello 3` on its stdout. Until the first line arrives, under an older parent
|
|
17
|
+
* that sends none, or when they stop, it runs `pantheon tray-status` itself every
|
|
18
|
+
* poll, as every helper before it did. It tells the parent `@refresh` (the menu
|
|
19
|
+
* opened, Refresh now, a wake from sleep) and `@power ac|battery`.
|
|
20
|
+
*
|
|
13
21
|
* The menu is also the daily review surface: every open thing — decisions for
|
|
14
22
|
* this human, what their side owes teammates, what teammates owe them — is a
|
|
15
23
|
* row with a copy button, and opens a centred panel with the whole text and the
|
|
@@ -17,11 +25,17 @@
|
|
|
17
25
|
* decisions need your input" and left nothing to look at.
|
|
18
26
|
*
|
|
19
27
|
* pantheon-tray <absolute-path-to-pantheon> [poll-seconds]
|
|
28
|
+
* pantheon-tray headless <absolute-path-to-pantheon> [poll-seconds]
|
|
29
|
+
* the same data loop with no menu bar item and no window: each status it
|
|
30
|
+
* applies is one stderr line, `applied <epoch ms> {"source":"pipe"|"spawn",…}`
|
|
31
|
+
* (tests, the battery bench). SIGTERM finishes a check in flight, then exits.
|
|
20
32
|
*/
|
|
21
33
|
import AppKit
|
|
34
|
+
import IOKit.ps
|
|
22
35
|
|
|
23
36
|
let argv = CommandLine.arguments
|
|
24
|
-
|
|
37
|
+
/// 3: speaks the status pipe (`@hello 3`), and has the headless mode.
|
|
38
|
+
if argv.count == 2, argv[1] == "version" { print("3"); exit(0) }
|
|
25
39
|
/// `pantheon-tray measure-warning <lead> <line>`: how the board's warning row lays the text out —
|
|
26
40
|
/// "<text width> <row height> <one line's height>" — measured, nothing drawn (for tests).
|
|
27
41
|
/// `pantheon-tray measure-header <lead> <rest>`: "<text width> <room>" for the board's heading line (HeaderView).
|
|
@@ -51,8 +65,9 @@ guard argv.count >= 2 else {
|
|
|
51
65
|
/// a PNG and exit — the layout can be checked without anyone clicking the icon.
|
|
52
66
|
/// PANTHEON_TRAY_OPEN="handling,waiting,…" opens those counted lines in the picture.
|
|
53
67
|
let renderTo: String? = argv.count >= 4 && argv[1] == "render" ? argv[3] : nil
|
|
54
|
-
let
|
|
55
|
-
let
|
|
68
|
+
let headless = argv.count >= 3 && argv[1] == "headless"
|
|
69
|
+
let pantheonBin = renderTo != nil || headless ? argv[2] : argv[1]
|
|
70
|
+
let pollSeconds = headless ? (argv.count >= 4 ? (Double(argv[3]) ?? 15) : 15) : argv.count >= 3 ? (Double(argv[2]) ?? 15) : 15
|
|
56
71
|
|
|
57
72
|
struct TrayState {
|
|
58
73
|
var configured = false
|
|
@@ -87,6 +102,24 @@ struct TrayState {
|
|
|
87
102
|
/// teams gone for this machine (deleted, or this person removed): the line to show, and the id `pantheon leave <id> --yes` takes
|
|
88
103
|
var gone: [(space: String, line: String)] = []
|
|
89
104
|
var version = ""
|
|
105
|
+
/// the one button that fixes agentProblem, as the alert has it: "sign_in" or "how", its label, and the agent (tray.ts agent_problem_fix)
|
|
106
|
+
var problemFixKind = ""
|
|
107
|
+
var problemFixLabel = ""
|
|
108
|
+
var problemFixAgent = ""
|
|
109
|
+
/// "Your agent ran 3 teammate requests today (12 min)"; empty when it ran none (spend.ts runsTodayLine)
|
|
110
|
+
var runsToday = ""
|
|
111
|
+
/// Pantheon processes here stuck without the relay for over two minutes, each with its fix (conn-report.ts)
|
|
112
|
+
var stuck: [String] = []
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Secondary text that reads: at least 4.5:1 on the dark board, and on light and
|
|
117
|
+
* dark menus and panels (0.34.1 review — the system's tertiary label, used for
|
|
118
|
+
* "show", "can't run now" and "version …", was 2.2:1 on the board; its secondary
|
|
119
|
+
* label sits at the edge of 4.5:1 on a light menu). Measured: 7.9:1 on the board.
|
|
120
|
+
*/
|
|
121
|
+
let readableDim = NSColor(name: nil) { a in
|
|
122
|
+
a.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua ? NSColor(white: 1, alpha: 0.66) : NSColor(white: 0, alpha: 0.64)
|
|
90
123
|
}
|
|
91
124
|
|
|
92
125
|
/// One open thing, as the menu shows it and the panel expands it.
|
|
@@ -165,6 +198,9 @@ func run(_ launchPath: String, _ args: [String], timeout: Double = 10) -> (out:
|
|
|
165
198
|
let p = Process()
|
|
166
199
|
p.executableURL = URL(fileURLWithPath: launchPath)
|
|
167
200
|
p.arguments = args
|
|
201
|
+
// Never this helper's own stdin: under `pantheon menubar` it is the status pipe, and a child holding it open
|
|
202
|
+
// would keep it alive after the parent went (and could read frames meant for this helper).
|
|
203
|
+
p.standardInput = FileHandle.nullDevice
|
|
168
204
|
let pipe = Pipe()
|
|
169
205
|
p.standardOutput = pipe
|
|
170
206
|
p.standardError = Pipe()
|
|
@@ -177,10 +213,25 @@ func run(_ launchPath: String, _ args: [String], timeout: Double = 10) -> (out:
|
|
|
177
213
|
}
|
|
178
214
|
|
|
179
215
|
func fetchState() -> TrayState {
|
|
180
|
-
var s = TrayState()
|
|
181
216
|
guard let r = run(pantheonBin, ["tray-status"], timeout: 20), r.code == 0,
|
|
182
217
|
let data = r.out.data(using: .utf8),
|
|
183
|
-
let j = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else { return
|
|
218
|
+
let j = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else { return TrayState() }
|
|
219
|
+
return trayState(j)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/// "Your agent ran N teammate requests today (M min)" — the CLI's words (spend.ts runsTodayLine); empty when N is 0.
|
|
223
|
+
func runsTodayLine(_ r: [String: Any]?) -> String {
|
|
224
|
+
guard let r = r else { return "" }
|
|
225
|
+
let n = (r["n"] as? Int) ?? Int((r["n"] as? Double) ?? 0)
|
|
226
|
+
guard n > 0 else { return "" }
|
|
227
|
+
let what = "Your agent ran \(n) teammate request\(n == 1 ? "" : "s") today"
|
|
228
|
+
guard let m = (r["minutes"] as? Int) ?? (r["minutes"] as? Double).map({ Int($0) }) else { return what }
|
|
229
|
+
return what + " (\(m < 1 ? "<1" : String(m)) min)"
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/// One tray status (the JSON `pantheon tray-status` prints, and each frame carries) as the menu draws it.
|
|
233
|
+
func trayState(_ j: [String: Any]) -> TrayState {
|
|
234
|
+
var s = TrayState()
|
|
184
235
|
s.reachable = true
|
|
185
236
|
s.configured = j["configured"] as? Bool ?? false
|
|
186
237
|
s.version = j["version"] as? String ?? ""
|
|
@@ -203,6 +254,15 @@ func fetchState() -> TrayState {
|
|
|
203
254
|
s.surfaceBundleID = j["surface_bundle_id"] as? String ?? ""
|
|
204
255
|
s.openIn = j["open_in"] as? String ?? "terminal"
|
|
205
256
|
s.claudeApp = j["claude_app"] as? Bool ?? false
|
|
257
|
+
if let fix = j["agent_problem_fix"] as? [String: Any], let kind = fix["kind"] as? String, kind == "sign_in" || kind == "how" {
|
|
258
|
+
s.problemFixKind = kind
|
|
259
|
+
s.problemFixLabel = (fix["label"] as? String).flatMap { $0.isEmpty || $0.count > 30 ? nil : $0 } ?? (kind == "sign_in" ? "Sign in" : "Show me how")
|
|
260
|
+
s.problemFixAgent = (fix["agent"] as? String).flatMap { $0.range(of: "^[a-z-]{1,20}$", options: .regularExpression) != nil ? $0 : nil } ?? ""
|
|
261
|
+
}
|
|
262
|
+
s.runsToday = runsTodayLine(j["runs_today"] as? [String: Any])
|
|
263
|
+
for c in (j["stuck_connections"] as? [[String: Any]] ?? []).prefix(5) {
|
|
264
|
+
if let line = c["line"] as? String, !line.isEmpty { s.stuck.append(String(line.prefix(200))) }
|
|
265
|
+
}
|
|
206
266
|
s.decisionsPrompt = j["decisions_prompt"] as? String ?? ""
|
|
207
267
|
s.spaces = j["spaces"] as? [String] ?? []
|
|
208
268
|
for g in (j["gone_spaces"] as? [[String: Any]] ?? []) {
|
|
@@ -245,6 +305,228 @@ func fetchState() -> TrayState {
|
|
|
245
305
|
}
|
|
246
306
|
|
|
247
307
|
|
|
308
|
+
// MARK: the data loop — the parent's status down the pipe, or tray-status every poll
|
|
309
|
+
|
|
310
|
+
/// A line to the parent, on stdout: `@hello 3`, `@refresh`, `@power …`, or a log line it passes on.
|
|
311
|
+
/// Written with write(2), SIGPIPE ignored: a parent that is gone is never this process's crash.
|
|
312
|
+
func sayToParent(_ line: String) {
|
|
313
|
+
var bytes = Array((line + "\n").utf8)
|
|
314
|
+
var off = 0
|
|
315
|
+
while off < bytes.count {
|
|
316
|
+
let n = bytes.withUnsafeMutableBytes { Darwin.write(1, $0.baseAddress! + off, $0.count - off) }
|
|
317
|
+
if n <= 0 { if n < 0 && errno == EINTR { continue }; return }
|
|
318
|
+
off += n
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/// AC or battery. Low Power Mode counts as battery: the person asked the Mac to save power.
|
|
323
|
+
func machinePower() -> String {
|
|
324
|
+
if #available(macOS 12.0, *), ProcessInfo.processInfo.isLowPowerModeEnabled { return "battery" }
|
|
325
|
+
guard let blob = IOPSCopyPowerSourcesInfo()?.takeRetainedValue(),
|
|
326
|
+
let type = IOPSGetProvidingPowerSourceType(blob)?.takeUnretainedValue() as String? else { return "ac" }
|
|
327
|
+
return type == "Battery Power" ? "battery" : "ac"
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/// One status frame from the parent (status-engine.ts): the state, and the latest the next one comes.
|
|
331
|
+
struct StatusFrame { let state: TrayState; let nextMs: Double; let seq: Int }
|
|
332
|
+
/// A frame line, checked: a JSON object with t "status" and a status the menu can draw. Anything else is nil.
|
|
333
|
+
func parseFrame(_ line: Data) -> StatusFrame? {
|
|
334
|
+
guard line.count <= 1_000_000,
|
|
335
|
+
let j = try? JSONSerialization.jsonObject(with: line) as? [String: Any],
|
|
336
|
+
(j["t"] as? String) == "status", let st = j["status"] as? [String: Any] else { return nil }
|
|
337
|
+
let state = trayState(st)
|
|
338
|
+
// A status that says this machine is in no team (the last one left) is the news: shown at once,
|
|
339
|
+
// as the parent's answer — not dropped, which kept the old board up and fell back to tray-status.
|
|
340
|
+
let next = (j["next_ms"] as? Double) ?? Double((j["next_ms"] as? Int) ?? 15_000)
|
|
341
|
+
return StatusFrame(state: state, nextMs: min(max(next, 1_000), 600_000), seq: (j["seq"] as? Int) ?? 0)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Where the status comes from. PIPE: frames from the parent (`pantheon menubar`,
|
|
346
|
+
* status-engine.ts), and no process is started for it. SPAWN: `pantheon
|
|
347
|
+
* tray-status` every poll (15 s, 60 s on battery) — today's loop, unchanged —
|
|
348
|
+
* until the first frame, under an older parent that sends none, after the
|
|
349
|
+
* parent's stdin closes, or when frames stop for 2 × next_ms + 10 s.
|
|
350
|
+
*/
|
|
351
|
+
final class DataLoop {
|
|
352
|
+
enum Mode { case spawn, pipe }
|
|
353
|
+
private(set) var mode: Mode = .spawn
|
|
354
|
+
private(set) var power = "ac"
|
|
355
|
+
/// what was applied, and from where ("pipe" | "spawn")
|
|
356
|
+
var onApply: ((TrayState, String) -> Void)?
|
|
357
|
+
private let poll: Double
|
|
358
|
+
private var spawning = false
|
|
359
|
+
private var stopping = false
|
|
360
|
+
private var tick: Timer?
|
|
361
|
+
private var stale: Timer?
|
|
362
|
+
private var firstWait: Timer?
|
|
363
|
+
private var stdinOpen = false
|
|
364
|
+
private var buffer = Data()
|
|
365
|
+
private var discarding = false
|
|
366
|
+
private var powerSource: CFRunLoopSource?
|
|
367
|
+
|
|
368
|
+
init(poll: Double) { self.poll = poll }
|
|
369
|
+
private var cadence: Double { power == "battery" ? max(poll, 60) : poll }
|
|
370
|
+
private func log(_ s: String) { sayToParent("pantheon-tray: " + s) }
|
|
371
|
+
|
|
372
|
+
func start() {
|
|
373
|
+
signal(SIGPIPE, SIG_IGN)
|
|
374
|
+
power = machinePower()
|
|
375
|
+
watchPower()
|
|
376
|
+
sayToParent("@hello 3")
|
|
377
|
+
sayToParent("@power \(power)")
|
|
378
|
+
var st = stat()
|
|
379
|
+
// Node's "pipe" stdio is a socket pair on a Mac; a hand-made pipe is a FIFO. launchd's /dev/null,
|
|
380
|
+
// a terminal: neither — no parent that sends status, so it checks for itself at once.
|
|
381
|
+
if fstat(0, &st) == 0 && ((st.st_mode & S_IFMT) == S_IFIFO || (st.st_mode & S_IFMT) == S_IFSOCK) {
|
|
382
|
+
// A parent that speaks the pipe answers within a moment; one that does not leaves the
|
|
383
|
+
// pipe silent (or closed), and the first check is our own, three seconds on.
|
|
384
|
+
stdinOpen = true
|
|
385
|
+
readStdin()
|
|
386
|
+
firstWait = Timer.scheduledTimer(withTimeInterval: 3, repeats: false) { [weak self] _ in
|
|
387
|
+
guard let self = self else { return }
|
|
388
|
+
self.firstWait = nil
|
|
389
|
+
if self.mode == .spawn { self.spawn() }
|
|
390
|
+
}
|
|
391
|
+
} else {
|
|
392
|
+
spawn()
|
|
393
|
+
}
|
|
394
|
+
armTick()
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/// The menu opened, Refresh now, a wake from sleep: look again now.
|
|
398
|
+
func requestRefresh() {
|
|
399
|
+
if mode == .pipe && stdinOpen { sayToParent("@refresh") } else { spawn() }
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/// SIGTERM (headless): a check in flight is finished first, so its child is reaped.
|
|
403
|
+
func finish() {
|
|
404
|
+
stopping = true
|
|
405
|
+
if !spawning { exit(0) }
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
private func armTick() {
|
|
409
|
+
tick?.invalidate()
|
|
410
|
+
let t = Timer(timeInterval: cadence, repeats: true) { [weak self] _ in
|
|
411
|
+
guard let self = self, self.mode == .spawn, self.firstWait == nil else { return }
|
|
412
|
+
self.spawn()
|
|
413
|
+
}
|
|
414
|
+
t.tolerance = cadence * 0.1 // let macOS coalesce the wakeup
|
|
415
|
+
RunLoop.main.add(t, forMode: .common)
|
|
416
|
+
tick = t
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
private func watchPower() {
|
|
420
|
+
let changed: () -> Void = { [weak self] in
|
|
421
|
+
guard let self = self else { return }
|
|
422
|
+
let now = machinePower()
|
|
423
|
+
guard now != self.power else { return }
|
|
424
|
+
self.power = now
|
|
425
|
+
sayToParent("@power \(now)")
|
|
426
|
+
self.armTick()
|
|
427
|
+
}
|
|
428
|
+
powerChanged = { DispatchQueue.main.async(execute: changed) }
|
|
429
|
+
if let src = IOPSNotificationCreateRunLoopSource({ _ in powerChanged?() }, nil)?.takeRetainedValue() {
|
|
430
|
+
CFRunLoopAddSource(CFRunLoopGetMain(), src, .defaultMode)
|
|
431
|
+
powerSource = src
|
|
432
|
+
}
|
|
433
|
+
if #available(macOS 12.0, *) {
|
|
434
|
+
NotificationCenter.default.addObserver(forName: .NSProcessInfoPowerStateDidChange, object: nil, queue: .main) { _ in changed() }
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
private func readStdin() {
|
|
439
|
+
FileHandle.standardInput.readabilityHandler = { [weak self] h in
|
|
440
|
+
let d = h.availableData
|
|
441
|
+
guard let self = self else { return }
|
|
442
|
+
if d.isEmpty {
|
|
443
|
+
h.readabilityHandler = nil
|
|
444
|
+
DispatchQueue.main.async { self.stdinClosed() }
|
|
445
|
+
return
|
|
446
|
+
}
|
|
447
|
+
// Lines on this handler's own queue; each frame applied on main.
|
|
448
|
+
var chunk = d
|
|
449
|
+
while let nl = chunk.firstIndex(of: 0x0A) {
|
|
450
|
+
let piece = chunk[chunk.startIndex..<nl]
|
|
451
|
+
chunk = chunk[(nl + 1)...]
|
|
452
|
+
if self.discarding { self.discarding = false; self.buffer.removeAll(); continue }
|
|
453
|
+
self.buffer.append(piece)
|
|
454
|
+
let line = self.buffer
|
|
455
|
+
self.buffer.removeAll()
|
|
456
|
+
if let f = parseFrame(line) { DispatchQueue.main.async { self.apply(f) } }
|
|
457
|
+
else if !line.isEmpty { DispatchQueue.main.async { self.log("dropped a line from the parent that is not a status frame (\(line.count) bytes)") } }
|
|
458
|
+
}
|
|
459
|
+
if !self.discarding {
|
|
460
|
+
self.buffer.append(chunk)
|
|
461
|
+
// A line that never ends cannot grow this without bound: dropped to its newline.
|
|
462
|
+
if self.buffer.count > 1_000_000 { self.buffer.removeAll(); self.discarding = true }
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
private func apply(_ f: StatusFrame) {
|
|
468
|
+
if stopping { return }
|
|
469
|
+
if mode == .spawn { mode = .pipe; log("status now comes from pantheon menubar (no tray-status checks)") }
|
|
470
|
+
firstWait?.invalidate(); firstWait = nil
|
|
471
|
+
stale?.invalidate()
|
|
472
|
+
let bound = 2 * f.nextMs / 1000 + 10
|
|
473
|
+
stale = Timer.scheduledTimer(withTimeInterval: bound, repeats: false) { [weak self] _ in
|
|
474
|
+
guard let self = self, self.mode == .pipe else { return }
|
|
475
|
+
self.mode = .spawn
|
|
476
|
+
self.log("no status from pantheon menubar for \(Int(bound)) s — checking for itself again")
|
|
477
|
+
self.spawn()
|
|
478
|
+
}
|
|
479
|
+
onApply?(f.state, "pipe")
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
private func stdinClosed() {
|
|
483
|
+
stdinOpen = false
|
|
484
|
+
stale?.invalidate(); stale = nil
|
|
485
|
+
if firstWait != nil { firstWait?.invalidate(); firstWait = nil }
|
|
486
|
+
if mode == .pipe { log("pantheon menubar went — checking for itself") }
|
|
487
|
+
mode = .spawn
|
|
488
|
+
spawn()
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
private func spawn() {
|
|
492
|
+
guard !spawning, !stopping else { return }
|
|
493
|
+
spawning = true
|
|
494
|
+
DispatchQueue.global().async {
|
|
495
|
+
let next = fetchState()
|
|
496
|
+
DispatchQueue.main.async {
|
|
497
|
+
self.spawning = false
|
|
498
|
+
if self.stopping { exit(0) }
|
|
499
|
+
// A frame came while it ran: the parent's answer is the newer one.
|
|
500
|
+
if self.mode == .pipe { return }
|
|
501
|
+
self.onApply?(next, "spawn")
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
/// The power-source callback is a C function: it reaches the loop through this.
|
|
507
|
+
var powerChanged: (() -> Void)?
|
|
508
|
+
|
|
509
|
+
/// `pantheon-tray headless`: the data loop alone. Each applied status is one stderr line.
|
|
510
|
+
func runHeadless() -> Never {
|
|
511
|
+
setvbuf(stderr, nil, _IOLBF, 0)
|
|
512
|
+
let loop = DataLoop(poll: pollSeconds)
|
|
513
|
+
loop.onApply = { s, source in
|
|
514
|
+
var o: [String: Any] = ["source": source, "ok": s.reachable, "relay_ok": s.relayOk, "refs": s.items.map { $0.ref }.filter { !$0.isEmpty }]
|
|
515
|
+
if !s.runsToday.isEmpty { o["runs_today"] = s.runsToday }
|
|
516
|
+
let d = (try? JSONSerialization.data(withJSONObject: o)) ?? Data()
|
|
517
|
+
fputs("applied \(Int(Date().timeIntervalSince1970 * 1000)) \(String(data: d, encoding: .utf8) ?? "{}")\n", stderr)
|
|
518
|
+
}
|
|
519
|
+
signal(SIGTERM, SIG_IGN)
|
|
520
|
+
let term = DispatchSource.makeSignalSource(signal: SIGTERM, queue: .main)
|
|
521
|
+
term.setEventHandler { loop.finish() }
|
|
522
|
+
term.resume()
|
|
523
|
+
headlessKeep = [loop, term]
|
|
524
|
+
loop.start()
|
|
525
|
+
RunLoop.main.run()
|
|
526
|
+
exit(0)
|
|
527
|
+
}
|
|
528
|
+
var headlessKeep: [Any] = []
|
|
529
|
+
|
|
248
530
|
/**
|
|
249
531
|
* One open thing, as a menu row: title, a dim second line, and a copy control on
|
|
250
532
|
* the right. Clicking the row opens the detail panel; clicking the copy glyph
|
|
@@ -379,7 +661,7 @@ final class RowView: NSView {
|
|
|
379
661
|
NSBezierPath(roundedRect: bounds.insetBy(dx: 5, dy: 1), xRadius: 5, yRadius: 5).fill()
|
|
380
662
|
}
|
|
381
663
|
let fg: NSColor = selected ? .selectedMenuItemTextColor : .labelColor
|
|
382
|
-
let dim: NSColor = selected ? NSColor.selectedMenuItemTextColor.withAlphaComponent(0.
|
|
664
|
+
let dim: NSColor = selected ? NSColor.selectedMenuItemTextColor.withAlphaComponent(0.85) : readableDim
|
|
383
665
|
let para = NSMutableParagraphStyle()
|
|
384
666
|
para.lineBreakMode = .byWordWrapping // break between words, not inside one
|
|
385
667
|
para.lineSpacing = 0
|
|
@@ -420,16 +702,21 @@ final class RowView: NSView {
|
|
|
420
702
|
NSBezierPath(roundedRect: copyRect, xRadius: 5, yRadius: 5).fill()
|
|
421
703
|
}
|
|
422
704
|
let glyphName = copied ? "checkmark" : "doc.on.doc"
|
|
423
|
-
let tint: NSColor = copied ? (selected ? .selectedMenuItemTextColor : .systemGreen) : (selected ? .selectedMenuItemTextColor :
|
|
705
|
+
let tint: NSColor = copied ? (selected ? .selectedMenuItemTextColor : .systemGreen) : (selected ? .selectedMenuItemTextColor : readableDim)
|
|
424
706
|
if let sym = NSImage(systemSymbolName: glyphName, accessibilityDescription: copied ? "Copied" : "Copy the question") {
|
|
425
707
|
let cfg = NSImage.SymbolConfiguration(pointSize: 12, weight: .medium)
|
|
426
708
|
let img = sym.withSymbolConfiguration(cfg) ?? sym
|
|
427
709
|
let size = img.size
|
|
428
710
|
let box = NSRect(x: copyRect.midX - size.width / 2, y: copyRect.midY - size.height / 2, width: size.width, height: size.height)
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
711
|
+
// A template image drawn straight is black whatever colour is set: on the dark board
|
|
712
|
+
// the copy glyph was black on near-black. Tinted here — the glyph's shape in `tint`.
|
|
713
|
+
let tinted = NSImage(size: size, flipped: false) { r in
|
|
714
|
+
img.draw(in: r)
|
|
715
|
+
tint.set()
|
|
716
|
+
r.fill(using: .sourceAtop)
|
|
717
|
+
return true
|
|
718
|
+
}
|
|
719
|
+
tinted.draw(in: box, from: .zero, operation: .sourceOver, fraction: 1.0)
|
|
433
720
|
} else {
|
|
434
721
|
let p2 = NSMutableParagraphStyle(); p2.alignment = .center
|
|
435
722
|
NSAttributedString(string: copied ? "ok" : "copy", attributes: [
|
|
@@ -457,7 +744,7 @@ final class HeaderView: NSView {
|
|
|
457
744
|
override func draw(_ dirtyRect: NSRect) {
|
|
458
745
|
let text = NSMutableAttributedString(string: lead, attributes: [
|
|
459
746
|
.font: NSFont.systemFont(ofSize: 12, weight: .semibold),
|
|
460
|
-
.foregroundColor: bright ? NSColor.labelColor :
|
|
747
|
+
.foregroundColor: bright ? NSColor.labelColor : readableDim,
|
|
461
748
|
])
|
|
462
749
|
if !rest.isEmpty {
|
|
463
750
|
text.append(NSAttributedString(string: " " + rest, attributes: [
|
|
@@ -508,7 +795,7 @@ final class TeamHeaderView: NSView {
|
|
|
508
795
|
NSAttributedString(string: name.uppercased(), attributes: [.font: NSFont.systemFont(ofSize: 11.5, weight: .bold), .kern: 0.6, .foregroundColor: NSColor.labelColor, .paragraphStyle: para])
|
|
509
796
|
.draw(in: NSRect(x: 24, y: bounds.midY - 8, width: bounds.width * 0.6, height: 16))
|
|
510
797
|
let r = NSMutableParagraphStyle(); r.alignment = .right
|
|
511
|
-
NSAttributedString(string: detail, attributes: [.font: NSFont.systemFont(ofSize: 12), .foregroundColor:
|
|
798
|
+
NSAttributedString(string: detail, attributes: [.font: NSFont.systemFont(ofSize: 12), .foregroundColor: readableDim, .paragraphStyle: r])
|
|
512
799
|
.draw(in: NSRect(x: bounds.maxX - 14 - 220, y: bounds.midY - 8, width: 220, height: 16))
|
|
513
800
|
}
|
|
514
801
|
}
|
|
@@ -569,13 +856,13 @@ final class ActionRow: NSView {
|
|
|
569
856
|
NSColor.selectedContentBackgroundColor.setFill()
|
|
570
857
|
NSBezierPath(roundedRect: bounds.insetBy(dx: 5, dy: 1), xRadius: 5, yRadius: 5).fill()
|
|
571
858
|
}
|
|
572
|
-
let fg: NSColor = onClick == nil ?
|
|
859
|
+
let fg: NSColor = onClick == nil ? readableDim : hovering ? .selectedMenuItemTextColor : .labelColor
|
|
573
860
|
let para = NSMutableParagraphStyle(); para.lineBreakMode = .byTruncatingTail
|
|
574
861
|
NSAttributedString(string: title, attributes: [.font: NSFont.systemFont(ofSize: 13), .foregroundColor: fg, .paragraphStyle: para])
|
|
575
862
|
.draw(in: NSRect(x: 12, y: bounds.midY - 8, width: bounds.width - 24 - (hint.isEmpty ? 0 : 80), height: 17))
|
|
576
863
|
if !hint.isEmpty {
|
|
577
864
|
let h = NSMutableParagraphStyle(); h.alignment = .right
|
|
578
|
-
NSAttributedString(string: hint, attributes: [.font: NSFont.systemFont(ofSize: 12), .foregroundColor: hovering ? NSColor.selectedMenuItemTextColor.withAlphaComponent(0.
|
|
865
|
+
NSAttributedString(string: hint, attributes: [.font: NSFont.systemFont(ofSize: 12), .foregroundColor: hovering ? NSColor.selectedMenuItemTextColor.withAlphaComponent(0.85) : readableDim, .paragraphStyle: h])
|
|
579
866
|
.draw(in: NSRect(x: bounds.maxX - 12 - 160, y: bounds.midY - 8, width: 160, height: 17))
|
|
580
867
|
}
|
|
581
868
|
}
|
|
@@ -584,9 +871,15 @@ final class ActionRow: NSView {
|
|
|
584
871
|
/// A warning across the whole board, wrapped to as many lines as it needs: this
|
|
585
872
|
/// computer can't take teammates' requests, and the fix (readiness-alert.ts). Its
|
|
586
873
|
/// height is measured from the text at the board's width, so nothing is cut.
|
|
874
|
+
/// With a fix to run (0.34.1: "Sign in →", the alert's own button), the whole row
|
|
875
|
+
/// is the button: a click runs it, the hint sits at the trailing edge.
|
|
587
876
|
final class WarningView: NSView {
|
|
588
877
|
private let text: NSAttributedString
|
|
878
|
+
private let hint: String
|
|
879
|
+
private let onClick: (() -> Void)?
|
|
880
|
+
private var hovering = false
|
|
589
881
|
static let inset: CGFloat = 26
|
|
882
|
+
static let hintFont = NSFont.systemFont(ofSize: 12.5, weight: .semibold)
|
|
590
883
|
static func attributed(lead: String, line: String) -> NSAttributedString {
|
|
591
884
|
let a = NSMutableAttributedString(string: lead + ": ", attributes: [.font: NSFont.systemFont(ofSize: 12.5, weight: .semibold), .foregroundColor: NSColor.labelColor])
|
|
592
885
|
a.append(NSAttributedString(string: line, attributes: [.font: NSFont.systemFont(ofSize: 12.5), .foregroundColor: NSColor.labelColor]))
|
|
@@ -594,27 +887,54 @@ final class WarningView: NSView {
|
|
|
594
887
|
a.addAttribute(.paragraphStyle, value: para, range: NSRange(location: 0, length: a.length))
|
|
595
888
|
return a
|
|
596
889
|
}
|
|
890
|
+
/// The room the trailing hint takes from the text, 0 without one.
|
|
891
|
+
static func hintWidth(_ hint: String) -> CGFloat {
|
|
892
|
+
hint.isEmpty ? 0 : ceil((hint as NSString).size(withAttributes: [.font: hintFont]).width) + 12
|
|
893
|
+
}
|
|
597
894
|
/// The height the text needs at `width`, measured — the row is that plus its padding.
|
|
598
|
-
static func height(_ text: NSAttributedString, width: CGFloat) -> CGFloat {
|
|
599
|
-
let inner = width - inset - 16
|
|
895
|
+
static func height(_ text: NSAttributedString, width: CGFloat, hint: String = "") -> CGFloat {
|
|
896
|
+
let inner = width - inset - 16 - hintWidth(hint)
|
|
600
897
|
return ceil(text.boundingRect(with: NSSize(width: inner, height: 10_000), options: [.usesLineFragmentOrigin, .usesFontLeading]).height) + 16
|
|
601
898
|
}
|
|
602
|
-
init(lead: String, line: String, width: CGFloat) {
|
|
899
|
+
init(lead: String, line: String, width: CGFloat, hint: String = "", onClick: (() -> Void)? = nil) {
|
|
603
900
|
text = WarningView.attributed(lead: lead, line: line)
|
|
604
|
-
|
|
901
|
+
self.hint = onClick == nil ? "" : hint
|
|
902
|
+
self.onClick = onClick
|
|
903
|
+
super.init(frame: NSRect(x: 0, y: 0, width: width, height: WarningView.height(text, width: width, hint: onClick == nil ? "" : hint)))
|
|
605
904
|
autoresizingMask = [.width]
|
|
606
|
-
|
|
607
|
-
|
|
905
|
+
if onClick != nil {
|
|
906
|
+
setAccessibilityRole(.button)
|
|
907
|
+
setAccessibilityLabel("\(lead): \(line). \(hint.replacingOccurrences(of: " →", with: ""))")
|
|
908
|
+
} else {
|
|
909
|
+
setAccessibilityRole(.staticText)
|
|
910
|
+
setAccessibilityLabel("\(lead): \(line)")
|
|
911
|
+
}
|
|
608
912
|
}
|
|
609
913
|
required init?(coder: NSCoder) { return nil }
|
|
610
914
|
override var isFlipped: Bool { true }
|
|
915
|
+
override func updateTrackingAreas() {
|
|
916
|
+
super.updateTrackingAreas()
|
|
917
|
+
for a in trackingAreas { removeTrackingArea(a) }
|
|
918
|
+
if onClick != nil { addTrackingArea(NSTrackingArea(rect: bounds, options: [.mouseEnteredAndExited, .activeAlways], owner: self, userInfo: nil)) }
|
|
919
|
+
}
|
|
920
|
+
override func mouseEntered(with e: NSEvent) { hovering = true; needsDisplay = true }
|
|
921
|
+
override func mouseExited(with e: NSEvent) { hovering = false; needsDisplay = true }
|
|
922
|
+
override func mouseUp(with e: NSEvent) { onClick?() }
|
|
923
|
+
override func resetCursorRects() { if onClick != nil { addCursorRect(bounds, cursor: .pointingHand) } }
|
|
611
924
|
override func draw(_ dirtyRect: NSRect) {
|
|
612
925
|
let band = NSRect(x: 6, y: 2, width: bounds.width - 12, height: bounds.height - 4)
|
|
613
|
-
NSColor.systemOrange.withAlphaComponent(0.16).setFill()
|
|
926
|
+
NSColor.systemOrange.withAlphaComponent(hovering ? 0.26 : 0.16).setFill()
|
|
614
927
|
NSBezierPath(roundedRect: band, xRadius: 6, yRadius: 6).fill()
|
|
615
928
|
NSColor.systemOrange.setFill()
|
|
616
929
|
NSBezierPath(roundedRect: NSRect(x: 12, y: 8, width: 4, height: bounds.height - 16), xRadius: 2, yRadius: 2).fill()
|
|
617
|
-
|
|
930
|
+
let hw = WarningView.hintWidth(hint)
|
|
931
|
+
text.draw(with: NSRect(x: WarningView.inset, y: 8, width: bounds.width - WarningView.inset - 16 - hw, height: bounds.height - 16), options: [.usesLineFragmentOrigin, .usesFontLeading])
|
|
932
|
+
if !hint.isEmpty {
|
|
933
|
+
// On the first line, at the trailing edge: where the eye ends the sentence.
|
|
934
|
+
let r = NSMutableParagraphStyle(); r.alignment = .right
|
|
935
|
+
NSAttributedString(string: hint, attributes: [.font: WarningView.hintFont, .foregroundColor: NSColor.labelColor, .paragraphStyle: r])
|
|
936
|
+
.draw(in: NSRect(x: bounds.maxX - 16 - hw, y: 8, width: hw, height: 17))
|
|
937
|
+
}
|
|
618
938
|
}
|
|
619
939
|
}
|
|
620
940
|
|
|
@@ -630,8 +950,7 @@ final class BoardSeparator: NSView {
|
|
|
630
950
|
final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
631
951
|
private var item: NSStatusItem!
|
|
632
952
|
private var state = TrayState()
|
|
633
|
-
private var
|
|
634
|
-
private var refreshing = false
|
|
953
|
+
private var loop: DataLoop?
|
|
635
954
|
private var menuOpen = false
|
|
636
955
|
private var hasLoaded = false
|
|
637
956
|
private var workerAction: String?
|
|
@@ -650,42 +969,38 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
650
969
|
item.button?.action = #selector(iconClicked(_:))
|
|
651
970
|
item.button?.sendAction(on: [.leftMouseUp, .rightMouseUp])
|
|
652
971
|
paint()
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
972
|
+
let loop = DataLoop(poll: pollSeconds)
|
|
973
|
+
loop.onApply = { [weak self] next, source in self?.apply(next, source: source) }
|
|
974
|
+
self.loop = loop
|
|
975
|
+
loop.start()
|
|
976
|
+
// Back from sleep: the status is as old as the sleep was — asked for at once.
|
|
977
|
+
NSWorkspace.shared.notificationCenter.addObserver(forName: NSWorkspace.didWakeNotification, object: nil, queue: .main) { [weak self] _ in self?.refresh() }
|
|
657
978
|
}
|
|
658
979
|
|
|
659
980
|
/// Consecutive checks that did not come back (timed out, or did not parse).
|
|
660
981
|
private var missedChecks = 0
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
self.missedChecks += 1
|
|
675
|
-
self.refreshing = false
|
|
676
|
-
return
|
|
677
|
-
}
|
|
678
|
-
self.missedChecks = next.reachable ? 0 : self.missedChecks + 1
|
|
679
|
-
self.state = next
|
|
680
|
-
self.hasLoaded = true
|
|
681
|
-
self.refreshing = false
|
|
682
|
-
self.paint()
|
|
683
|
-
if !self.menuOpen, let menu = self.item.menu { self.menuNeedsUpdate(menu) }
|
|
684
|
-
// The board redraws only when what it shows has changed, so a poll never
|
|
685
|
-
// pulls a row out from under the pointer for nothing.
|
|
686
|
-
if self.boardPanel?.isVisible == true && self.boardSignature != self.signature() { self.rebuildBoard() }
|
|
687
|
-
}
|
|
982
|
+
/// Look again now: the parent is asked (`@refresh`), or tray-status is run when there is no parent's status.
|
|
983
|
+
@objc func refresh() { loop?.requestRefresh() }
|
|
984
|
+
|
|
985
|
+
private func apply(_ next: TrayState, source: String) {
|
|
986
|
+
// A check that did not come back is not news that the relay is down: on a
|
|
987
|
+
// busy machine `pantheon tray-status` can take longer than its limit, and
|
|
988
|
+
// the mark flipped to the slashed "unreachable" state with a "!" — while
|
|
989
|
+
// the relay, the team and every decision were fine. What was last known is
|
|
990
|
+
// kept through two misses; only a third in a row is shown as "unable to
|
|
991
|
+
// check". A check that did come back — and every frame from the parent — always wins.
|
|
992
|
+
if source == "spawn" && !next.reachable && hasLoaded && state.reachable && missedChecks < 2 {
|
|
993
|
+
missedChecks += 1
|
|
994
|
+
return
|
|
688
995
|
}
|
|
996
|
+
missedChecks = next.reachable ? 0 : missedChecks + 1
|
|
997
|
+
state = next
|
|
998
|
+
hasLoaded = true
|
|
999
|
+
paint()
|
|
1000
|
+
if !menuOpen, let menu = item.menu { menuNeedsUpdate(menu) }
|
|
1001
|
+
// The board redraws only when what it shows has changed, so a poll never
|
|
1002
|
+
// pulls a row out from under the pointer for nothing.
|
|
1003
|
+
if boardPanel?.isVisible == true && boardSignature != signature() { rebuildBoard() }
|
|
689
1004
|
}
|
|
690
1005
|
|
|
691
1006
|
// MARK: the board
|
|
@@ -721,7 +1036,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
721
1036
|
// Everything the board draws from, not just which ids: a row moving lane (out
|
|
722
1037
|
// of the worker's window), a new repeat, a claim, or a Later coming due all
|
|
723
1038
|
// change what an open board must show.
|
|
724
|
-
"\(state.items.map { "\($0.id):\($0.effectiveLane):\($0.claimed):\($0.context)" }.joined(separator: ","))|\(Later.active().keys.sorted().joined(separator: ","))|\(state.decisions.count)|\(state.online)|\(state.members)|\(state.workerRunning)|\(state.relayOk)|\(state.gone.map { $0.space }.joined(separator: ","))|\(state.agentProblem)|\(actionError ?? "")|\(workerAction ?? "")"
|
|
1039
|
+
"\(state.items.map { "\($0.id):\($0.effectiveLane):\($0.claimed):\($0.context)" }.joined(separator: ","))|\(Later.active().keys.sorted().joined(separator: ","))|\(state.decisions.count)|\(state.online)|\(state.members)|\(state.workerRunning)|\(state.relayOk)|\(state.gone.map { $0.space }.joined(separator: ","))|\(state.agentProblem)|\(state.problemFixKind)|\(state.runsToday)|\(state.stuck.joined(separator: ","))|\(actionError ?? "")|\(workerAction ?? "")"
|
|
725
1040
|
}
|
|
726
1041
|
|
|
727
1042
|
@objc private func iconClicked(_ sender: Any?) {
|
|
@@ -837,7 +1152,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
837
1152
|
var rows: [NSView] = []
|
|
838
1153
|
let note = { (text: String) in rows.append(ActionRow(text, width: w)) }
|
|
839
1154
|
let act = { (text: String, hint: String, f: @escaping () -> Void) in rows.append(ActionRow(text, hint: hint, width: w, onClick: { [weak self] in self?.closeBoard(); f() })) }
|
|
840
|
-
|
|
1155
|
+
// Never two separators in a row (nothing between them reads as a gap with a line in it).
|
|
1156
|
+
let sep = { if !(rows.last is BoardSeparator) { rows.append(BoardSeparator(width: w)) } }
|
|
841
1157
|
let openRow: (Item) -> Void = { [weak self] it in self?.closeBoard(); self?.showDetail(it) }
|
|
842
1158
|
let copyRow: (Item) -> Void = { [weak self] it in self?.copyPrompt(it) }
|
|
843
1159
|
if !hasLoaded {
|
|
@@ -865,11 +1181,20 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
865
1181
|
// Every team gone: "alex · No active teams", not "0 of 0 online".
|
|
866
1182
|
let noTeams = state.spaces.isEmpty && !state.gone.isEmpty
|
|
867
1183
|
rows.append(HeaderView(lead: need, rest: "\(state.member) · \(where_)" + (noTeams ? "" : " · " + (state.relayOk ? "\(state.online) of \(state.members) online" : "connection unavailable")), width: w))
|
|
868
|
-
if !problem.isEmpty {
|
|
1184
|
+
if !problem.isEmpty {
|
|
1185
|
+
// The alert's own fix, from the row itself: Sign in (or Show me how), the same action.
|
|
1186
|
+
if !state.problemFixKind.isEmpty {
|
|
1187
|
+
rows.append(WarningView(lead: state.agentProblemLead, line: problem, width: w, hint: "\(state.problemFixLabel) →", onClick: { [weak self] in self?.closeBoard(); self?.runProblemFix() }))
|
|
1188
|
+
} else {
|
|
1189
|
+
rows.append(WarningView(lead: state.agentProblemLead, line: problem, width: w))
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
869
1192
|
// A team gone for this computer: said plainly, never as "could not reach" — one click removes it.
|
|
870
1193
|
for g in state.gone { act("\(g.line) · Remove from this computer", "") { [weak self] in self?.forgetTeam(g.space, g.line) } }
|
|
871
1194
|
if !state.relayOk { note("Could not reach: \(state.unavailableSpaces.joined(separator: ", "))") }
|
|
872
1195
|
if !state.decisionsOk { note("Some of this could not be checked — the list may be incomplete") }
|
|
1196
|
+
// A process here that lost the relay and is not getting it back: which one, and the fix.
|
|
1197
|
+
for line in state.stuck { rows.append(WarningView(lead: "Not connected", line: line, width: w)) }
|
|
873
1198
|
sep()
|
|
874
1199
|
// The heading already says nothing needs you: said again only what it does not.
|
|
875
1200
|
if cards.isEmpty && state.decisionsOk && handling.isEmpty && waiting.isEmpty && older.isEmpty && putAway.isEmpty && problem.isEmpty {
|
|
@@ -913,6 +1238,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
913
1238
|
act("Review all \(state.decisions.count) questions in \(state.surfaceName)", "") { [weak self] in self?.openAllDecisions() }
|
|
914
1239
|
}
|
|
915
1240
|
sep()
|
|
1241
|
+
// What the worker did for teammates today, when it did anything.
|
|
1242
|
+
if !state.runsToday.isEmpty { note(state.runsToday) }
|
|
916
1243
|
if let action = workerAction { note(action) }
|
|
917
1244
|
// The problem has its own row at the top: the hint here would cut it to a word.
|
|
918
1245
|
else if state.workerRunning { act("Pause unattended work", problem.isEmpty ? state.workerState : "can't run now") { [weak self] in self?.pauseWorker() } }
|
|
@@ -1057,6 +1384,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
1057
1384
|
}
|
|
1058
1385
|
if !state.relayOk { info("Could not reach: \(state.unavailableSpaces.joined(separator: ", "))") }
|
|
1059
1386
|
if !state.decisionsOk { info("Some of this could not be checked — the list may be incomplete") }
|
|
1387
|
+
for line in state.stuck { for part in AppDelegate.wrap("Not connected: " + line, 100) { info(part) } }
|
|
1060
1388
|
menu.addItem(.separator())
|
|
1061
1389
|
let row = { (it: Item) -> NSMenuItem in self.menuRow(it, showSpace: multi) }
|
|
1062
1390
|
for it in cards { menu.addItem(row(it)) }
|
|
@@ -1082,9 +1410,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
1082
1410
|
menu.addItem(makeItem("Review all \(state.decisions.count) questions in \(state.surfaceName)", #selector(openAllDecisions)))
|
|
1083
1411
|
}
|
|
1084
1412
|
menu.addItem(.separator())
|
|
1085
|
-
|
|
1413
|
+
// Never "on" above a line that says it can't run: a worker that is up but can take nothing is stuck.
|
|
1414
|
+
info(state.workerRunning ? (state.agentProblem.isEmpty ? "Unattended work is on" : "Unattended work is stuck") : state.workerInstalled ? "Unattended work is paused" : "Unattended work is not set up")
|
|
1086
1415
|
// Wrapped, never cut: the problem line ("…signed out — open Terminal, type …") runs past one menu row.
|
|
1087
1416
|
if !state.workerState.isEmpty && state.workerRunning { for part in AppDelegate.wrap(state.workerState, 100) { info(part) } }
|
|
1417
|
+
if !state.runsToday.isEmpty { info(state.runsToday) }
|
|
1088
1418
|
if let action = workerAction {
|
|
1089
1419
|
info(action)
|
|
1090
1420
|
} else if state.workerRunning {
|
|
@@ -1105,6 +1435,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
1105
1435
|
for text in ["Version \(state.version)", "Alerts: \(state.notifierRunning ? "running" : "off")", "Wake hook: \(state.hookOn ? "installed" : "off")"] {
|
|
1106
1436
|
let row = NSMenuItem(title: text, action: nil, keyEquivalent: "")
|
|
1107
1437
|
row.isEnabled = false
|
|
1438
|
+
row.attributedTitle = NSAttributedString(string: text, attributes: [.foregroundColor: NSColor.labelColor])
|
|
1108
1439
|
submenu.addItem(row)
|
|
1109
1440
|
}
|
|
1110
1441
|
submenu.addItem(makeItem("View decision details in Terminal", #selector(openApprovals)))
|
|
@@ -1284,7 +1615,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
1284
1615
|
box.arrangedSubviews.forEach { $0.removeFromSuperview() }
|
|
1285
1616
|
let note = NSTextField(labelWithString: "Answer with one of its options:")
|
|
1286
1617
|
note.font = .systemFont(ofSize: 12, weight: .medium)
|
|
1287
|
-
note.textColor =
|
|
1618
|
+
note.textColor = readableDim
|
|
1288
1619
|
box.addArrangedSubview(note)
|
|
1289
1620
|
for (n, o) in options.enumerated() {
|
|
1290
1621
|
let title = "(\(o.key)) " + (o.text.count > 78 ? String(o.text.prefix(77)) + "…" : o.text)
|
|
@@ -1353,7 +1684,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
1353
1684
|
var eyebrow = item.heading.uppercased()
|
|
1354
1685
|
if item.when > 0 { eyebrow += " · " + Item.age(item.when) }
|
|
1355
1686
|
if !item.space.isEmpty { eyebrow += " · " + item.space }
|
|
1356
|
-
let eye = label(eyebrow, size: 11, weight: .semibold, color:
|
|
1687
|
+
let eye = label(eyebrow, size: 11, weight: .semibold, color: readableDim, width: inner)
|
|
1357
1688
|
panelEyebrow = eye
|
|
1358
1689
|
stack.addArrangedSubview(eye)
|
|
1359
1690
|
let headline = label(item.headline, size: 17, weight: .semibold, color: .labelColor, width: inner)
|
|
@@ -1385,7 +1716,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
1385
1716
|
|
|
1386
1717
|
var meta = item.kind == "change" ? "setup change \(item.id)" : item.isDecision ? "decision \(item.id)" : "obligation \(item.id)"
|
|
1387
1718
|
if !item.goal.isEmpty { meta += " · goal \(item.goal)" }
|
|
1388
|
-
stack.addArrangedSubview(label(meta, size: 11, weight: .regular, color:
|
|
1719
|
+
stack.addArrangedSubview(label(meta, size: 11, weight: .regular, color: readableDim, width: inner))
|
|
1389
1720
|
|
|
1390
1721
|
// Whose decision this is, said before the box that answers it. Your own
|
|
1391
1722
|
// answer to a teammate's decision lands as an act and settles nothing, so the
|
|
@@ -1401,7 +1732,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
1401
1732
|
ownerRow.alignment = .centerY
|
|
1402
1733
|
ownerRow.spacing = 10
|
|
1403
1734
|
ownerRow.translatesAutoresizingMaskIntoConstraints = false
|
|
1404
|
-
let ownerLabel = label(owner, size: 12, weight: .medium, color:
|
|
1735
|
+
let ownerLabel = label(owner, size: 12, weight: .medium, color: readableDim, width: inner - 170)
|
|
1405
1736
|
ownerLabel.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
|
1406
1737
|
ownerRow.addArrangedSubview(ownerLabel)
|
|
1407
1738
|
let ownerSpacer = NSView()
|
|
@@ -1486,7 +1817,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
1486
1817
|
statusRow.orientation = .horizontal
|
|
1487
1818
|
statusRow.spacing = 10
|
|
1488
1819
|
statusRow.translatesAutoresizingMaskIntoConstraints = false
|
|
1489
|
-
let status = label("", size: 11, weight: .medium, color:
|
|
1820
|
+
let status = label("", size: 11, weight: .medium, color: readableDim, width: inner - 90)
|
|
1490
1821
|
status.isHidden = true
|
|
1491
1822
|
panelStatus = status
|
|
1492
1823
|
statusRow.addArrangedSubview(status)
|
|
@@ -2007,7 +2338,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
2007
2338
|
} else {
|
|
2008
2339
|
header.attributedTitle = NSAttributedString(string: title, attributes: [
|
|
2009
2340
|
.font: NSFont.systemFont(ofSize: 11, weight: .semibold),
|
|
2010
|
-
.foregroundColor:
|
|
2341
|
+
.foregroundColor: readableDim,
|
|
2011
2342
|
])
|
|
2012
2343
|
}
|
|
2013
2344
|
menu.addItem(header)
|
|
@@ -2140,6 +2471,16 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
2140
2471
|
}
|
|
2141
2472
|
@objc private func refreshNow() { refresh() }
|
|
2142
2473
|
|
|
2474
|
+
/// The warning row's "Sign in →" / "Show me how →": exactly what the alert's button does — the
|
|
2475
|
+
/// CLI, in Terminal, runs only its own fixed steps for this kind and agent, and asks first.
|
|
2476
|
+
func runProblemFix() {
|
|
2477
|
+
guard !state.problemFixKind.isEmpty else { return }
|
|
2478
|
+
var payload: [String: Any] = ["action": "fix", "fix_kind": state.problemFixKind, "why": state.agentProblem]
|
|
2479
|
+
if !state.problemFixAgent.isEmpty { payload["agent"] = state.problemFixAgent }
|
|
2480
|
+
if writeAction(payload) { openCommand("pantheon-details.command") }
|
|
2481
|
+
else { reportFailure("Could not start it. Run pantheon doctor in Terminal: it shows the fix.") }
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2143
2484
|
/// Quit through the CLI, not NSApp.terminate: under launchd, KeepAlive would
|
|
2144
2485
|
/// resurrect a self-terminated tray thirty seconds later — a menu item that
|
|
2145
2486
|
/// only pretends to work. `pantheon stop menubar` boots the service out;
|
|
@@ -2152,6 +2493,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
2152
2493
|
}
|
|
2153
2494
|
}
|
|
2154
2495
|
|
|
2496
|
+
if headless { runHeadless() }
|
|
2155
2497
|
let app = NSApplication.shared
|
|
2156
2498
|
let delegate = AppDelegate()
|
|
2157
2499
|
app.delegate = delegate
|