@join-pantheon/cli 0.24.0 → 0.24.4
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/cli.js +76 -0
- package/dist/continued.js +35 -0
- package/dist/decision-ui.js +14 -1
- package/dist/humanize.js +223 -0
- package/dist/notifier.js +19 -5
- package/dist/relay.js +11 -0
- package/dist/tray.js +29 -4
- package/dist/upgrade.js +5 -1
- package/dist/worker.js +34 -10
- package/helper/macos/main.swift +31 -1
- package/helper/macos/menubar.swift +577 -17
- package/package.json +1 -1
|
@@ -10,12 +10,18 @@
|
|
|
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
|
+
* The menu is also the daily review surface: every open thing — decisions for
|
|
14
|
+
* this human, what their side owes teammates, what teammates owe them — is a
|
|
15
|
+
* row with a copy button, and opens a centred panel with the whole text and the
|
|
16
|
+
* actions that settle it. Before that it was a status light that said "no
|
|
17
|
+
* decisions need your input" and left nothing to look at.
|
|
18
|
+
*
|
|
13
19
|
* pantheon-tray <absolute-path-to-pantheon> [poll-seconds]
|
|
14
20
|
*/
|
|
15
21
|
import AppKit
|
|
16
22
|
|
|
17
23
|
let argv = CommandLine.arguments
|
|
18
|
-
if argv.count == 2, argv[1] == "version" { print("
|
|
24
|
+
if argv.count == 2, argv[1] == "version" { print("2"); exit(0) }
|
|
19
25
|
guard argv.count >= 2 else {
|
|
20
26
|
fputs("usage: pantheon-tray <path-to-pantheon> [poll-seconds]\n", stderr)
|
|
21
27
|
exit(64)
|
|
@@ -43,9 +49,49 @@ struct TrayState {
|
|
|
43
49
|
var surfaceBundleID = ""
|
|
44
50
|
var decisionsPrompt = ""
|
|
45
51
|
var decisions: [(id: String, body: String, detail: String, prompt: String)] = []
|
|
52
|
+
var items: [Item] = []
|
|
46
53
|
var version = ""
|
|
47
54
|
}
|
|
48
55
|
|
|
56
|
+
/// One open thing, as the menu shows it and the panel expands it.
|
|
57
|
+
struct Item {
|
|
58
|
+
let id: String
|
|
59
|
+
let kind: String // decision | owed | waiting
|
|
60
|
+
let title: String
|
|
61
|
+
let headline: String
|
|
62
|
+
let detail: String
|
|
63
|
+
let prompt: String
|
|
64
|
+
let who: String // member id, or "you"
|
|
65
|
+
let when: Double // ms since epoch
|
|
66
|
+
let goal: String
|
|
67
|
+
let ref: String
|
|
68
|
+
let space: String
|
|
69
|
+
|
|
70
|
+
var isDecision: Bool { kind == "decision" }
|
|
71
|
+
var heading: String {
|
|
72
|
+
switch kind {
|
|
73
|
+
case "decision": return "Needs your decision"
|
|
74
|
+
case "owed": return "Your side owes this"
|
|
75
|
+
default: return "Waiting on \(who)"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/// "praneet · 2d ago · pantheon"
|
|
79
|
+
var subtitle: String {
|
|
80
|
+
var parts: [String] = []
|
|
81
|
+
if kind == "owed" { parts.append("you owe") } else if kind == "waiting" { parts.append(who) }
|
|
82
|
+
if when > 0 { parts.append(Item.age(when)) }
|
|
83
|
+
if !space.isEmpty { parts.append(space) }
|
|
84
|
+
return parts.joined(separator: " · ")
|
|
85
|
+
}
|
|
86
|
+
static func age(_ ms: Double) -> String {
|
|
87
|
+
let secs = max(0, Date().timeIntervalSince1970 - ms / 1000)
|
|
88
|
+
if secs < 90 { return "just now" }
|
|
89
|
+
if secs < 5400 { return "\(Int(secs / 60))m ago" }
|
|
90
|
+
if secs < 172_800 { return "\(Int(secs / 3600))h ago" }
|
|
91
|
+
return "\(Int(secs / 86_400))d ago"
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
49
95
|
/// Run a command with a hard timeout. The menu bar must never beachball
|
|
50
96
|
/// because a laptop's relay is asleep — tray-status has its own network
|
|
51
97
|
/// timeouts, this bounds the whole process as the backstop.
|
|
@@ -88,6 +134,21 @@ func fetchState() -> TrayState {
|
|
|
88
134
|
s.surfaceName = j["surface_name"] as? String ?? "agent"
|
|
89
135
|
s.surfaceBundleID = j["surface_bundle_id"] as? String ?? ""
|
|
90
136
|
s.decisionsPrompt = j["decisions_prompt"] as? String ?? ""
|
|
137
|
+
for i in (j["items"] as? [[String: Any]] ?? []) {
|
|
138
|
+
s.items.append(Item(
|
|
139
|
+
id: i["id"] as? String ?? "",
|
|
140
|
+
kind: i["kind"] as? String ?? "decision",
|
|
141
|
+
title: i["title"] as? String ?? "",
|
|
142
|
+
headline: i["headline"] as? String ?? i["title"] as? String ?? "",
|
|
143
|
+
detail: i["detail"] as? String ?? i["title"] as? String ?? "",
|
|
144
|
+
prompt: i["prompt"] as? String ?? "",
|
|
145
|
+
who: i["who"] as? String ?? "",
|
|
146
|
+
when: (i["when"] as? Double) ?? Double(i["when"] as? Int ?? 0),
|
|
147
|
+
goal: i["goal"] as? String ?? "",
|
|
148
|
+
ref: i["ref"] as? String ?? "",
|
|
149
|
+
space: i["space"] as? String ?? ""
|
|
150
|
+
))
|
|
151
|
+
}
|
|
91
152
|
for d in (j["decisions"] as? [[String: Any]] ?? []) {
|
|
92
153
|
s.decisions.append((
|
|
93
154
|
id: d["id"] as? String ?? "",
|
|
@@ -99,6 +160,111 @@ func fetchState() -> TrayState {
|
|
|
99
160
|
return s
|
|
100
161
|
}
|
|
101
162
|
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* One open thing, as a menu row: title, a dim second line, and a copy control on
|
|
166
|
+
* the right. Clicking the row opens the detail panel; clicking the copy glyph
|
|
167
|
+
* puts the agent prompt on the clipboard and LEAVES THE MENU OPEN, so a person
|
|
168
|
+
* reviewing four things can take all four without reopening the menu each time.
|
|
169
|
+
*
|
|
170
|
+
* Drawn by hand rather than assembled from controls: a menu runs its own event
|
|
171
|
+
* loop, and hit-testing two zones in one view is far more predictable there than
|
|
172
|
+
* nesting buttons inside an NSMenuItem.
|
|
173
|
+
*/
|
|
174
|
+
final class RowView: NSView {
|
|
175
|
+
private let item: Item
|
|
176
|
+
private let onOpen: (Item) -> Void
|
|
177
|
+
private let onCopy: (Item) -> Void
|
|
178
|
+
private var hovering = false
|
|
179
|
+
private var overCopy = false
|
|
180
|
+
private var copied = false
|
|
181
|
+
|
|
182
|
+
init(item: Item, width: CGFloat, onOpen: @escaping (Item) -> Void, onCopy: @escaping (Item) -> Void) {
|
|
183
|
+
self.item = item
|
|
184
|
+
self.onOpen = onOpen
|
|
185
|
+
self.onCopy = onCopy
|
|
186
|
+
super.init(frame: NSRect(x: 0, y: 0, width: width, height: item.subtitle.isEmpty ? 30 : 42))
|
|
187
|
+
setAccessibilityRole(.button)
|
|
188
|
+
setAccessibilityLabel("\(item.title). \(item.subtitle). Return opens it; the button on the right copies the question.")
|
|
189
|
+
}
|
|
190
|
+
required init?(coder: NSCoder) { return nil }
|
|
191
|
+
|
|
192
|
+
private var copyRect: NSRect { NSRect(x: bounds.maxX - 42, y: bounds.midY - 12, width: 28, height: 24) }
|
|
193
|
+
|
|
194
|
+
override func updateTrackingAreas() {
|
|
195
|
+
super.updateTrackingAreas()
|
|
196
|
+
for a in trackingAreas { removeTrackingArea(a) }
|
|
197
|
+
addTrackingArea(NSTrackingArea(rect: bounds, options: [.mouseEnteredAndExited, .activeAlways], owner: self, userInfo: ["zone": "row"]))
|
|
198
|
+
addTrackingArea(NSTrackingArea(rect: copyRect, options: [.mouseEnteredAndExited, .activeAlways], owner: self, userInfo: ["zone": "copy"]))
|
|
199
|
+
}
|
|
200
|
+
private func zone(_ e: NSEvent) -> String { (e.trackingArea?.userInfo?["zone"] as? String) ?? "row" }
|
|
201
|
+
override func mouseEntered(with e: NSEvent) {
|
|
202
|
+
if zone(e) == "copy" { overCopy = true } else { hovering = true }
|
|
203
|
+
needsDisplay = true
|
|
204
|
+
}
|
|
205
|
+
override func mouseExited(with e: NSEvent) {
|
|
206
|
+
if zone(e) == "copy" { overCopy = false } else { hovering = false; overCopy = false }
|
|
207
|
+
needsDisplay = true
|
|
208
|
+
}
|
|
209
|
+
override func mouseUp(with e: NSEvent) {
|
|
210
|
+
if copyRect.contains(convert(e.locationInWindow, from: nil)) {
|
|
211
|
+
onCopy(item)
|
|
212
|
+
copied = true
|
|
213
|
+
needsDisplay = true
|
|
214
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 1.4) { [weak self] in self?.copied = false; self?.needsDisplay = true }
|
|
215
|
+
return
|
|
216
|
+
}
|
|
217
|
+
enclosingMenuItem?.menu?.cancelTracking()
|
|
218
|
+
onOpen(item)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
override func draw(_ dirtyRect: NSRect) {
|
|
222
|
+
let selected = hovering
|
|
223
|
+
if selected {
|
|
224
|
+
NSColor.selectedContentBackgroundColor.setFill()
|
|
225
|
+
NSBezierPath(roundedRect: bounds.insetBy(dx: 5, dy: 1), xRadius: 5, yRadius: 5).fill()
|
|
226
|
+
}
|
|
227
|
+
let fg: NSColor = selected ? .selectedMenuItemTextColor : .labelColor
|
|
228
|
+
let dim: NSColor = selected ? NSColor.selectedMenuItemTextColor.withAlphaComponent(0.7) : .secondaryLabelColor
|
|
229
|
+
let para = NSMutableParagraphStyle()
|
|
230
|
+
para.lineBreakMode = .byTruncatingTail
|
|
231
|
+
let textWidth = bounds.width - 14 - 48
|
|
232
|
+
let hasSub = !item.subtitle.isEmpty
|
|
233
|
+
let titleY = hasSub ? bounds.midY - 1 : bounds.midY - 8
|
|
234
|
+
NSAttributedString(string: item.title, attributes: [
|
|
235
|
+
.font: NSFont.systemFont(ofSize: 13, weight: .medium), .foregroundColor: fg, .paragraphStyle: para,
|
|
236
|
+
]).draw(in: NSRect(x: 14, y: titleY, width: textWidth, height: 18))
|
|
237
|
+
if hasSub {
|
|
238
|
+
NSAttributedString(string: item.subtitle, attributes: [
|
|
239
|
+
.font: NSFont.systemFont(ofSize: 11), .foregroundColor: dim, .paragraphStyle: para,
|
|
240
|
+
]).draw(in: NSRect(x: 14, y: bounds.midY - 17, width: textWidth, height: 15))
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// the copy control
|
|
244
|
+
if overCopy || copied {
|
|
245
|
+
(selected ? NSColor.white.withAlphaComponent(0.22) : NSColor.labelColor.withAlphaComponent(0.10)).setFill()
|
|
246
|
+
NSBezierPath(roundedRect: copyRect, xRadius: 5, yRadius: 5).fill()
|
|
247
|
+
}
|
|
248
|
+
let glyphName = copied ? "checkmark" : "doc.on.doc"
|
|
249
|
+
let tint: NSColor = copied ? (selected ? .selectedMenuItemTextColor : .systemGreen) : (selected ? .selectedMenuItemTextColor : .secondaryLabelColor)
|
|
250
|
+
if let sym = NSImage(systemSymbolName: glyphName, accessibilityDescription: copied ? "Copied" : "Copy the question") {
|
|
251
|
+
let cfg = NSImage.SymbolConfiguration(pointSize: 12, weight: .medium)
|
|
252
|
+
let img = sym.withSymbolConfiguration(cfg) ?? sym
|
|
253
|
+
let size = img.size
|
|
254
|
+
let box = NSRect(x: copyRect.midX - size.width / 2, y: copyRect.midY - size.height / 2, width: size.width, height: size.height)
|
|
255
|
+
tint.set()
|
|
256
|
+
img.isTemplate = true
|
|
257
|
+
img.draw(in: box, from: .zero, operation: .sourceOver, fraction: 1.0)
|
|
258
|
+
NSColor.clear.set()
|
|
259
|
+
} else {
|
|
260
|
+
let p2 = NSMutableParagraphStyle(); p2.alignment = .center
|
|
261
|
+
NSAttributedString(string: copied ? "ok" : "copy", attributes: [
|
|
262
|
+
.font: NSFont.systemFont(ofSize: 10, weight: .medium), .foregroundColor: tint, .paragraphStyle: p2,
|
|
263
|
+
]).draw(in: NSRect(x: copyRect.minX - 6, y: copyRect.midY - 6, width: copyRect.width + 12, height: 13))
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
102
268
|
final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
103
269
|
private var item: NSStatusItem!
|
|
104
270
|
private var state = TrayState()
|
|
@@ -222,21 +388,26 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
222
388
|
: "Connection unavailable · \(state.unavailableSpaces.joined(separator: ", "))")
|
|
223
389
|
menu.addItem(.separator())
|
|
224
390
|
if !state.decisionsOk {
|
|
225
|
-
info("Some
|
|
226
|
-
info("Refresh to try again
|
|
391
|
+
info("Some of this could not be checked")
|
|
392
|
+
info("Refresh to try again — the list may be incomplete")
|
|
227
393
|
}
|
|
228
|
-
|
|
229
|
-
|
|
394
|
+
let decisions = state.items.filter { $0.kind == "decision" }
|
|
395
|
+
let owed = state.items.filter { $0.kind == "owed" }
|
|
396
|
+
let waiting = state.items.filter { $0.kind == "waiting" }
|
|
397
|
+
if state.items.isEmpty {
|
|
398
|
+
if state.decisionsOk { info("Nothing open — nothing needs you, nothing owed either way") }
|
|
230
399
|
} else {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
menu.
|
|
400
|
+
addRows(menu, decisions.count == 1 ? "1 decision needs you" : "\(decisions.count) decisions need you", decisions)
|
|
401
|
+
addRows(menu, owed.count == 1 ? "You owe 1 thing" : "You owe \(owed.count) things", owed)
|
|
402
|
+
// Grouped by person, because "waiting on praneet" is what someone
|
|
403
|
+
// actually wants to know before they chase it.
|
|
404
|
+
for who in orderedPeers(waiting) {
|
|
405
|
+
let theirs = waiting.filter { $0.who == who }
|
|
406
|
+
addRows(menu, theirs.count == 1 ? "Waiting on \(who)" : "Waiting on \(who) · \(theirs.count)", theirs)
|
|
407
|
+
}
|
|
408
|
+
if !decisions.isEmpty {
|
|
409
|
+
menu.addItem(makeItem("\(decisions.count > 1 ? "Review all \(decisions.count) decisions" : "Review the decision") in \(state.surfaceName)", #selector(openAllDecisions)))
|
|
238
410
|
}
|
|
239
|
-
menu.addItem(makeItem("\(state.decisions.count > 5 ? "Review all \(state.decisions.count) decisions" : "Review decisions") in \(state.surfaceName)", #selector(openAllDecisions)))
|
|
240
411
|
}
|
|
241
412
|
menu.addItem(.separator())
|
|
242
413
|
info(state.workerRunning ? "Unattended work is on" : state.workerInstalled ? "Unattended work is paused" : "Unattended work is not set up")
|
|
@@ -274,6 +445,399 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
274
445
|
menu.addItem(makeItem("Quit pantheon menu bar", #selector(quit)))
|
|
275
446
|
}
|
|
276
447
|
|
|
448
|
+
|
|
449
|
+
// MARK: the detail panel — the centred window a row opens
|
|
450
|
+
|
|
451
|
+
private var detailPanel: NSPanel?
|
|
452
|
+
private var panelItem: Item?
|
|
453
|
+
private var panelStatus: NSTextField?
|
|
454
|
+
private var panelText: NSTextView?
|
|
455
|
+
private var panelBodyHeight: NSLayoutConstraint?
|
|
456
|
+
private var panelHeadline: NSTextField?
|
|
457
|
+
private var panelRendered: NSAttributedString? // the act laid out for a person
|
|
458
|
+
private var panelRaw: String = "" // the act exactly as it was sent
|
|
459
|
+
private var panelShowingRaw = false
|
|
460
|
+
private var panelRawToggle: NSButton?
|
|
461
|
+
|
|
462
|
+
private func label(_ text: String, size: CGFloat, weight: NSFont.Weight, color: NSColor, width: CGFloat) -> NSTextField {
|
|
463
|
+
let l = NSTextField(labelWithString: text)
|
|
464
|
+
l.font = .systemFont(ofSize: size, weight: weight)
|
|
465
|
+
l.textColor = color
|
|
466
|
+
l.lineBreakMode = .byWordWrapping
|
|
467
|
+
l.maximumNumberOfLines = 0
|
|
468
|
+
l.preferredMaxLayoutWidth = width
|
|
469
|
+
l.translatesAutoresizingMaskIntoConstraints = false
|
|
470
|
+
return l
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/// How tall the body should be for this much text, between a compact minimum
|
|
474
|
+
/// and a cap that keeps the panel on screen.
|
|
475
|
+
private func bodyHeight(_ text: NSAttributedString, width: CGFloat) -> CGFloat {
|
|
476
|
+
let measured = text.boundingRect(with: NSSize(width: width - 4, height: .greatestFiniteMagnitude),
|
|
477
|
+
options: [.usesLineFragmentOrigin, .usesFontLeading]).height
|
|
478
|
+
return min(max(ceil(measured) + 22, 96), 400)
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
private func plain(_ text: String) -> NSAttributedString {
|
|
482
|
+
let para = NSMutableParagraphStyle()
|
|
483
|
+
para.paragraphSpacing = 10
|
|
484
|
+
para.lineSpacing = 1.5
|
|
485
|
+
return NSAttributedString(string: text, attributes: [
|
|
486
|
+
.font: NSFont.systemFont(ofSize: 13), .foregroundColor: NSColor.labelColor, .paragraphStyle: para,
|
|
487
|
+
])
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* The act as blocks: paragraphs, the options as bullets, shell commands in a
|
|
492
|
+
* monospace run. The parsing is the CLI's (`pantheon tray-detail`), because it
|
|
493
|
+
* is testable there and this file stays a renderer.
|
|
494
|
+
*/
|
|
495
|
+
private func render(_ blocks: [[String: Any]]) -> NSAttributedString {
|
|
496
|
+
let out = NSMutableAttributedString()
|
|
497
|
+
let body = NSMutableParagraphStyle()
|
|
498
|
+
body.paragraphSpacing = 12
|
|
499
|
+
body.lineSpacing = 1.5
|
|
500
|
+
let bullet = NSMutableParagraphStyle()
|
|
501
|
+
bullet.paragraphSpacing = 5
|
|
502
|
+
bullet.lineSpacing = 1.5
|
|
503
|
+
bullet.headIndent = 20
|
|
504
|
+
bullet.firstLineHeadIndent = 6
|
|
505
|
+
let code = NSMutableParagraphStyle()
|
|
506
|
+
code.paragraphSpacing = 2
|
|
507
|
+
code.headIndent = 20
|
|
508
|
+
code.firstLineHeadIndent = 12
|
|
509
|
+
|
|
510
|
+
for block in blocks {
|
|
511
|
+
let kind = block["kind"] as? String ?? "para"
|
|
512
|
+
if kind == "para", let text = block["text"] as? String {
|
|
513
|
+
out.append(NSAttributedString(string: text + "\n", attributes: [
|
|
514
|
+
.font: NSFont.systemFont(ofSize: 13), .foregroundColor: NSColor.labelColor, .paragraphStyle: body,
|
|
515
|
+
]))
|
|
516
|
+
} else if kind == "bullets", let items = block["items"] as? [String] {
|
|
517
|
+
for item in items {
|
|
518
|
+
out.append(NSAttributedString(string: "• " + item + "\n", attributes: [
|
|
519
|
+
.font: NSFont.systemFont(ofSize: 13), .foregroundColor: NSColor.labelColor, .paragraphStyle: bullet,
|
|
520
|
+
]))
|
|
521
|
+
}
|
|
522
|
+
out.append(NSAttributedString(string: "\n", attributes: [.font: NSFont.systemFont(ofSize: 5)]))
|
|
523
|
+
} else if kind == "code", let lines = block["lines"] as? [String] {
|
|
524
|
+
for line in lines {
|
|
525
|
+
out.append(NSAttributedString(string: line + "\n", attributes: [
|
|
526
|
+
.font: NSFont.monospacedSystemFont(ofSize: 12, weight: .regular),
|
|
527
|
+
.foregroundColor: NSColor.labelColor,
|
|
528
|
+
.backgroundColor: NSColor.labelColor.withAlphaComponent(0.06),
|
|
529
|
+
.paragraphStyle: code,
|
|
530
|
+
]))
|
|
531
|
+
}
|
|
532
|
+
out.append(NSAttributedString(string: "\n", attributes: [.font: NSFont.systemFont(ofSize: 5)]))
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
return out
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
private func showBody(_ text: NSAttributedString, width: CGFloat) {
|
|
539
|
+
guard let tv = panelText else { return }
|
|
540
|
+
tv.textStorage?.setAttributedString(text)
|
|
541
|
+
panelBodyHeight?.constant = bodyHeight(text, width: width)
|
|
542
|
+
if let p = detailPanel {
|
|
543
|
+
p.contentView?.layoutSubtreeIfNeeded()
|
|
544
|
+
let h = min(max((p.contentView?.fittingSize.height ?? 420) + 30, 300), 680)
|
|
545
|
+
let f = p.frame
|
|
546
|
+
p.setFrame(NSRect(x: f.minX, y: f.maxY - h, width: f.width, height: h), display: true, animate: false)
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* The relay's obligation body is ONE clipped line — enough for a menu row, not
|
|
552
|
+
* for a panel that says "here is the whole thing". So fetch the act behind it
|
|
553
|
+
* and lay it out. On demand, only while a panel is open.
|
|
554
|
+
*/
|
|
555
|
+
private func loadDetail(_ item: Item, width: CGFloat) {
|
|
556
|
+
guard !item.ref.isEmpty else { return }
|
|
557
|
+
DispatchQueue.global().async {
|
|
558
|
+
let r = run(pantheonBin, ["tray-detail", item.ref], timeout: 20)
|
|
559
|
+
guard let out = r?.out, r?.code == 0,
|
|
560
|
+
let data = out.data(using: .utf8),
|
|
561
|
+
let j = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
|
|
562
|
+
j["ok"] as? Bool == true else { return }
|
|
563
|
+
let blocks = j["blocks"] as? [[String: Any]] ?? []
|
|
564
|
+
let rendered = self.render(blocks)
|
|
565
|
+
let raw = j["raw"] as? String ?? ""
|
|
566
|
+
let headline = j["headline"] as? String ?? ""
|
|
567
|
+
DispatchQueue.main.async {
|
|
568
|
+
guard self.panelItem?.id == item.id else { return }
|
|
569
|
+
self.panelRendered = rendered
|
|
570
|
+
self.panelRaw = raw
|
|
571
|
+
self.panelRawToggle?.isHidden = raw.isEmpty
|
|
572
|
+
if !headline.isEmpty { self.panelHeadline?.stringValue = headline }
|
|
573
|
+
if !self.panelShowingRaw && rendered.length > 0 { self.showBody(rendered, width: width) }
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/// Reformatting someone else's words is only honest if the original is one click away.
|
|
579
|
+
@objc private func panelToggleRaw() {
|
|
580
|
+
guard let item = panelItem else { return }
|
|
581
|
+
panelShowingRaw.toggle()
|
|
582
|
+
panelRawToggle?.title = panelShowingRaw ? "Show it laid out" : "Show it as sent"
|
|
583
|
+
let width: CGFloat = 620 - 52
|
|
584
|
+
if panelShowingRaw { showBody(plain(panelRaw.isEmpty ? item.detail : panelRaw), width: width) }
|
|
585
|
+
else if let r = panelRendered { showBody(r, width: width) }
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Everything about one open thing, in the middle of the screen: who it is
|
|
590
|
+
* from, the whole text (a menu row can only ever show a clipped line), and the
|
|
591
|
+
* actions that settle it. The menu answers "is anything waiting"; this answers
|
|
592
|
+
* "what is it, and what do I do about it" without a terminal.
|
|
593
|
+
*/
|
|
594
|
+
func showDetail(_ item: Item) {
|
|
595
|
+
detailPanel?.close()
|
|
596
|
+
panelItem = item
|
|
597
|
+
let width: CGFloat = 620
|
|
598
|
+
let inner = width - 52
|
|
599
|
+
let panel = NSPanel(contentRect: NSRect(x: 0, y: 0, width: width, height: 470),
|
|
600
|
+
styleMask: [.titled, .closable, .fullSizeContentView], backing: .buffered, defer: false)
|
|
601
|
+
panel.title = "Pantheon"
|
|
602
|
+
panel.titlebarAppearsTransparent = true
|
|
603
|
+
panel.isMovableByWindowBackground = true
|
|
604
|
+
panel.level = .floating
|
|
605
|
+
panel.isReleasedWhenClosed = false
|
|
606
|
+
panel.hidesOnDeactivate = false
|
|
607
|
+
|
|
608
|
+
let effect = NSVisualEffectView(frame: NSRect(x: 0, y: 0, width: width, height: 470))
|
|
609
|
+
effect.material = .popover
|
|
610
|
+
effect.blendingMode = .behindWindow
|
|
611
|
+
effect.state = .active
|
|
612
|
+
effect.autoresizingMask = [.width, .height]
|
|
613
|
+
|
|
614
|
+
let stack = NSStackView()
|
|
615
|
+
stack.orientation = .vertical
|
|
616
|
+
stack.alignment = .leading
|
|
617
|
+
stack.spacing = 9
|
|
618
|
+
stack.translatesAutoresizingMaskIntoConstraints = false
|
|
619
|
+
effect.addSubview(stack)
|
|
620
|
+
|
|
621
|
+
var eyebrow = item.heading.uppercased()
|
|
622
|
+
if item.when > 0 { eyebrow += " · " + Item.age(item.when) }
|
|
623
|
+
if !item.space.isEmpty { eyebrow += " · " + item.space }
|
|
624
|
+
let eye = label(eyebrow, size: 11, weight: .semibold, color: .secondaryLabelColor, width: inner)
|
|
625
|
+
stack.addArrangedSubview(eye)
|
|
626
|
+
let headline = label(item.headline, size: 17, weight: .semibold, color: .labelColor, width: inner)
|
|
627
|
+
panelHeadline = headline
|
|
628
|
+
stack.addArrangedSubview(headline)
|
|
629
|
+
|
|
630
|
+
// the whole text, selectable and scrollable — a decision is often several paragraphs
|
|
631
|
+
let scroll = NSScrollView()
|
|
632
|
+
scroll.hasVerticalScroller = true
|
|
633
|
+
scroll.drawsBackground = false
|
|
634
|
+
scroll.borderType = .noBorder
|
|
635
|
+
scroll.translatesAutoresizingMaskIntoConstraints = false
|
|
636
|
+
let tv = NSTextView()
|
|
637
|
+
tv.isEditable = false
|
|
638
|
+
tv.isSelectable = true
|
|
639
|
+
tv.drawsBackground = false
|
|
640
|
+
tv.font = .systemFont(ofSize: 13)
|
|
641
|
+
tv.textColor = .labelColor
|
|
642
|
+
tv.textStorage?.setAttributedString(plain(item.detail))
|
|
643
|
+
tv.textContainerInset = NSSize(width: 0, height: 6)
|
|
644
|
+
tv.isVerticallyResizable = true
|
|
645
|
+
tv.isHorizontallyResizable = false
|
|
646
|
+
tv.autoresizingMask = [.width]
|
|
647
|
+
tv.textContainer?.widthTracksTextView = true
|
|
648
|
+
scroll.documentView = tv
|
|
649
|
+
panelText = tv
|
|
650
|
+
stack.addArrangedSubview(scroll)
|
|
651
|
+
stack.setCustomSpacing(14, after: stack.arrangedSubviews[1])
|
|
652
|
+
|
|
653
|
+
var meta = item.isDecision ? "decision \(item.id)" : "obligation \(item.id)"
|
|
654
|
+
if !item.goal.isEmpty { meta += " · goal \(item.goal)" }
|
|
655
|
+
stack.addArrangedSubview(label(meta, size: 11, weight: .regular, color: .tertiaryLabelColor, width: inner))
|
|
656
|
+
|
|
657
|
+
let status = label("", size: 11, weight: .medium, color: .secondaryLabelColor, width: inner)
|
|
658
|
+
status.isHidden = true
|
|
659
|
+
panelStatus = status
|
|
660
|
+
stack.addArrangedSubview(status)
|
|
661
|
+
|
|
662
|
+
let row = NSStackView()
|
|
663
|
+
row.orientation = .horizontal
|
|
664
|
+
row.spacing = 10
|
|
665
|
+
row.translatesAutoresizingMaskIntoConstraints = false
|
|
666
|
+
let open = NSButton(title: "Open in \(state.surfaceName)", target: self, action: #selector(panelOpen))
|
|
667
|
+
open.bezelStyle = .rounded
|
|
668
|
+
open.keyEquivalent = "\r"
|
|
669
|
+
row.addArrangedSubview(open)
|
|
670
|
+
let copy = NSButton(title: "Copy the question", target: self, action: #selector(panelCopy))
|
|
671
|
+
copy.bezelStyle = .rounded
|
|
672
|
+
row.addArrangedSubview(copy)
|
|
673
|
+
if item.isDecision {
|
|
674
|
+
let done = NSButton(title: "Mark done", target: self, action: #selector(panelDone))
|
|
675
|
+
done.bezelStyle = .rounded
|
|
676
|
+
done.toolTip = "Answer it as handled, so it stops asking"
|
|
677
|
+
row.addArrangedSubview(done)
|
|
678
|
+
}
|
|
679
|
+
let thread = NSButton(title: "Show the thread", target: self, action: #selector(panelThread))
|
|
680
|
+
thread.bezelStyle = .rounded
|
|
681
|
+
row.addArrangedSubview(thread)
|
|
682
|
+
let rawToggle = NSButton(title: "Show it as sent", target: self, action: #selector(panelToggleRaw))
|
|
683
|
+
rawToggle.bezelStyle = .rounded
|
|
684
|
+
rawToggle.toolTip = "The act exactly as your teammate's agent wrote it"
|
|
685
|
+
rawToggle.isHidden = true
|
|
686
|
+
panelRawToggle = rawToggle
|
|
687
|
+
row.addArrangedSubview(rawToggle)
|
|
688
|
+
let close = NSButton(title: "Close", target: self, action: #selector(panelClose))
|
|
689
|
+
close.bezelStyle = .rounded
|
|
690
|
+
close.keyEquivalent = "\u{1b}"
|
|
691
|
+
row.addArrangedSubview(close)
|
|
692
|
+
stack.addArrangedSubview(row)
|
|
693
|
+
|
|
694
|
+
NSLayoutConstraint.activate([
|
|
695
|
+
stack.leadingAnchor.constraint(equalTo: effect.leadingAnchor, constant: 26),
|
|
696
|
+
stack.trailingAnchor.constraint(equalTo: effect.trailingAnchor, constant: -26),
|
|
697
|
+
stack.topAnchor.constraint(equalTo: effect.topAnchor, constant: 36),
|
|
698
|
+
stack.bottomAnchor.constraint(equalTo: effect.bottomAnchor, constant: -22),
|
|
699
|
+
scroll.widthAnchor.constraint(equalTo: stack.widthAnchor),
|
|
700
|
+
row.widthAnchor.constraint(lessThanOrEqualTo: stack.widthAnchor),
|
|
701
|
+
])
|
|
702
|
+
let bh = scroll.heightAnchor.constraint(equalToConstant: bodyHeight(plain(item.detail), width: inner))
|
|
703
|
+
bh.isActive = true
|
|
704
|
+
panelBodyHeight = bh
|
|
705
|
+
|
|
706
|
+
panel.contentView = effect
|
|
707
|
+
// Sized to what it holds: a one-line question should not open a half-empty window.
|
|
708
|
+
effect.layoutSubtreeIfNeeded()
|
|
709
|
+
let height = min(max(effect.fittingSize.height + 30, 300), 660)
|
|
710
|
+
panel.setContentSize(NSSize(width: width, height: height))
|
|
711
|
+
panel.center()
|
|
712
|
+
detailPanel = panel
|
|
713
|
+
NSApp.activate(ignoringOtherApps: true)
|
|
714
|
+
panel.makeKeyAndOrderFront(nil)
|
|
715
|
+
panelRendered = nil
|
|
716
|
+
panelRaw = ""
|
|
717
|
+
panelShowingRaw = false
|
|
718
|
+
loadDetail(item, width: inner)
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
private func setStatus(_ text: String) {
|
|
722
|
+
panelStatus?.stringValue = text
|
|
723
|
+
panelStatus?.isHidden = text.isEmpty
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
@objc private func panelClose() {
|
|
727
|
+
detailPanel?.close()
|
|
728
|
+
detailPanel = nil
|
|
729
|
+
panelText = nil
|
|
730
|
+
panelBodyHeight = nil
|
|
731
|
+
panelItem = nil
|
|
732
|
+
panelHeadline = nil
|
|
733
|
+
panelRendered = nil
|
|
734
|
+
panelRawToggle = nil
|
|
735
|
+
panelRaw = ""
|
|
736
|
+
panelShowingRaw = false
|
|
737
|
+
}
|
|
738
|
+
@objc private func panelCopy() {
|
|
739
|
+
guard let item = panelItem else { return }
|
|
740
|
+
copyPrompt(item)
|
|
741
|
+
setStatus("Copied. Paste it into your agent.")
|
|
742
|
+
}
|
|
743
|
+
@objc private func panelOpen() {
|
|
744
|
+
guard let item = panelItem else { return }
|
|
745
|
+
panelClose()
|
|
746
|
+
openItem(item)
|
|
747
|
+
}
|
|
748
|
+
@objc private func panelThread() {
|
|
749
|
+
guard let item = panelItem else { return }
|
|
750
|
+
panelClose()
|
|
751
|
+
showThread(item)
|
|
752
|
+
}
|
|
753
|
+
/// Answer the decision as handled, with no terminal — the same action the alert's Done takes.
|
|
754
|
+
@objc private func panelDone() {
|
|
755
|
+
guard let item = panelItem, item.isDecision else { return }
|
|
756
|
+
setStatus("Marking it done…")
|
|
757
|
+
var payload: [String: Any] = ["action": "done", "decision": item.id]
|
|
758
|
+
if !item.ref.isEmpty { payload["act"] = item.ref }
|
|
759
|
+
guard writeAction(payload) else {
|
|
760
|
+
setStatus("Could not write the action. Use Show the thread instead.")
|
|
761
|
+
return
|
|
762
|
+
}
|
|
763
|
+
DispatchQueue.global().async {
|
|
764
|
+
let r = run(pantheonBin, ["explain", "--queued"], timeout: 25)
|
|
765
|
+
DispatchQueue.main.async {
|
|
766
|
+
self.setStatus(r?.code == 0
|
|
767
|
+
? "Done — it is no longer waiting on you."
|
|
768
|
+
: "Could not mark it done. Use Show the thread instead.")
|
|
769
|
+
self.refresh()
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
// MARK: item actions, shared by the menu rows and the panel
|
|
775
|
+
|
|
776
|
+
private func binDir() -> String {
|
|
777
|
+
(Bundle.main.executablePath as NSString?)?.deletingLastPathComponent
|
|
778
|
+
?? URL(fileURLWithPath: CommandLine.arguments[0]).deletingLastPathComponent().path
|
|
779
|
+
}
|
|
780
|
+
/// What `pantheon explain --queued` reads. Same file the desktop alert writes.
|
|
781
|
+
private func writeAction(_ payload: [String: Any]) -> Bool {
|
|
782
|
+
guard let data = try? JSONSerialization.data(withJSONObject: payload) else { return false }
|
|
783
|
+
return (try? data.write(to: URL(fileURLWithPath: binDir() + "/.hud-action.json"), options: .atomic)) != nil
|
|
784
|
+
}
|
|
785
|
+
func copyPrompt(_ item: Item) {
|
|
786
|
+
let pb = NSPasteboard.general
|
|
787
|
+
pb.clearContents()
|
|
788
|
+
pb.setString(item.prompt, forType: .string)
|
|
789
|
+
}
|
|
790
|
+
/// Open the agent with this item's question already written out.
|
|
791
|
+
func openItem(_ item: Item) {
|
|
792
|
+
copyPrompt(item)
|
|
793
|
+
if writeAction(["action": "open", "prompt": item.prompt]) {
|
|
794
|
+
openCommand("pantheon-explain.command")
|
|
795
|
+
} else {
|
|
796
|
+
reportFailure("Could not open your agent. The question is copied; paste it into your agent.")
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
/// The act behind it, in Terminal, with the reply menu.
|
|
800
|
+
func showThread(_ item: Item) {
|
|
801
|
+
var payload: [String: Any] = ["action": "details"]
|
|
802
|
+
if !item.ref.isEmpty { payload["act"] = item.ref }
|
|
803
|
+
if item.isDecision { payload["decision"] = item.id }
|
|
804
|
+
if writeAction(payload) { openCommand("pantheon-details.command") }
|
|
805
|
+
else { reportFailure("Could not open Terminal. Run pantheon doctor to check your setup.") }
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/// Peers in the order their oldest unanswered thing arrived — longest wait first.
|
|
809
|
+
private func orderedPeers(_ items: [Item]) -> [String] {
|
|
810
|
+
var seen: [String] = []
|
|
811
|
+
for i in items.sorted(by: { $0.when < $1.when }) where !seen.contains(i.who) { seen.append(i.who) }
|
|
812
|
+
return seen
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/// A titled group of rows. Six at most: a menu is for triage, and anything
|
|
816
|
+
/// deeper belongs in `pantheon brief`, which the last row opens.
|
|
817
|
+
private func addRows(_ menu: NSMenu, _ title: String, _ items: [Item]) {
|
|
818
|
+
guard !items.isEmpty else { return }
|
|
819
|
+
let header = NSMenuItem(title: title, action: nil, keyEquivalent: "")
|
|
820
|
+
header.isEnabled = false
|
|
821
|
+
header.attributedTitle = NSAttributedString(string: title, attributes: [
|
|
822
|
+
.font: NSFont.systemFont(ofSize: 11, weight: .semibold),
|
|
823
|
+
.foregroundColor: NSColor.secondaryLabelColor,
|
|
824
|
+
])
|
|
825
|
+
menu.addItem(header)
|
|
826
|
+
for item in items.prefix(6) {
|
|
827
|
+
let mi = NSMenuItem(title: item.title, action: nil, keyEquivalent: "")
|
|
828
|
+
mi.toolTip = item.detail
|
|
829
|
+
mi.view = RowView(item: item, width: 360,
|
|
830
|
+
onOpen: { [weak self] it in self?.showDetail(it) },
|
|
831
|
+
onCopy: { [weak self] it in self?.copyPrompt(it) })
|
|
832
|
+
menu.addItem(mi)
|
|
833
|
+
}
|
|
834
|
+
if items.count > 6 {
|
|
835
|
+
let more = NSMenuItem(title: "…and \(items.count - 6) more", action: nil, keyEquivalent: "")
|
|
836
|
+
more.isEnabled = false
|
|
837
|
+
menu.addItem(more)
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
|
|
277
841
|
private func makeItem(_ title: String, _ sel: Selector) -> NSMenuItem {
|
|
278
842
|
let mi = NSMenuItem(title: title, action: sel, keyEquivalent: "")
|
|
279
843
|
mi.target = self
|
|
@@ -307,10 +871,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
|
|
307
871
|
@objc private func openStatus() { openCommand("pantheon-status.command") }
|
|
308
872
|
@objc private func openDoctor() { openCommand("pantheon-doctor.command") }
|
|
309
873
|
@objc private func openApprovals() { openCommand("pantheon-approvals.command") }
|
|
310
|
-
@objc private func openDecision(_ sender: NSMenuItem) {
|
|
311
|
-
let pair = sender.representedObject as? [String] ?? []
|
|
312
|
-
openAgent(id: pair.first ?? "all", prompt: pair.count > 1 ? pair[1] : "")
|
|
313
|
-
}
|
|
314
874
|
@objc private func openAllDecisions() { openAgent(id: "all", prompt: state.decisionsPrompt) }
|
|
315
875
|
/**
|
|
316
876
|
* The handoff: queue the chosen decision id for `pantheon explain --queued`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@join-pantheon/cli",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.4",
|
|
4
4
|
"description": "Let your coding agent collaborate directly with your teammates' agents — ask, agree an interface, and deliver, without a human relaying messages.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|