@join-pantheon/cli 0.33.10 → 0.33.11-rc.2

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.
@@ -13,6 +13,9 @@
13
13
  * Sign in (your agent is signed out) opens a Terminal that asks, then signs it in
14
14
  * Show me how (no agent CLI, a sandbox that cannot start) shows this computer's steps
15
15
  * Done (decisions) answers it as handled, silently — the reminders stop
16
+ * Approve / Keep as is (a change to the person's setup an agent asked for) answers it, silently
17
+ * Review (several setup changes, or several started requests) opens them to read first
18
+ * Take over / Stop (work the worker just started for a teammate) hands it to the person, or stops it
16
19
  * Dismiss / × closes
17
20
  *
18
21
  * It owns no state. Everything it needs arrives as one JSON document:
@@ -43,6 +46,12 @@ struct Details: Decodable { let act: String?; let decision: String? }
43
46
  /// The one thing a person could do about a failed run: where, and which steps.
44
47
  /// `kind` "sign_in" / "how": a readiness alert's one button (no pull-down); the CLI runs only its own fixed steps for it.
45
48
  struct Fix: Decodable { let label: String; let dir: String; let lines: [String]; let why: String; let kind: String?; let agent: String? }
49
+ /// A change to the person's setup waiting for their yes (0.33.10): Approve / Keep as is.
50
+ struct Change: Decodable { let id: String }
51
+ /// Work the worker just started for a teammate (0.33.10): Take over / Stop. `ref` is the request it answers.
52
+ struct RunRef: Decodable { let ref: String }
53
+ /// One Review button in place of acting blind (0.33.10): the waiting setup changes ("changes"), or the board ("board").
54
+ struct Review: Decodable { let what: String }
46
55
  struct Notice: Decodable {
47
56
  let kind: String
48
57
  let who: String
@@ -55,6 +64,11 @@ struct Notice: Decodable {
55
64
  let primary: Primary?
56
65
  let details: Details?
57
66
  let fix: Fix?
67
+ let change: Change?
68
+ let run: RunRef?
69
+ let review: Review?
70
+ /** alerts with the same tag are one alert: a new one replaces the one on screen (0.33.10, never a burst) */
71
+ let tag: String?
58
72
  /** the team it came from (0.33.4): written into every action, so the CLI answers in that team with no default picked */
59
73
  let space: String?
60
74
  /** where to write the chosen action and which .command files to open — supplied by the CLI */
@@ -64,16 +78,21 @@ struct Notice: Decodable {
64
78
  }
65
79
 
66
80
  /// The panel's buttons, decided in one place: what `post` draws and what `buttons` prints.
67
- enum MainAction { case details, legacyOpen, fix }
81
+ enum MainAction { case details, legacyOpen, fix, review }
68
82
  enum ButtonPlan {
69
83
  /// the "Open in …" pull-down, then whichever of Show details, the fix, Done apply, then Dismiss
70
84
  case pulldown(String, [String])
71
85
  /// one main button, then Dismiss
72
86
  case single(String, MainAction)
87
+ /// two answers the CLI acts on silently (Approve / Keep as is, Take over / Stop), then Dismiss
88
+ case answers([String])
73
89
  /// no buttons: the panel closes with ×
74
90
  case none
75
91
  }
76
92
  func buttonPlan(_ n: Notice, legacy: Bool) -> ButtonPlan {
93
+ if n.review != nil { return .single("Review", .review) }
94
+ if n.change != nil { return .answers(["Approve", "Keep as is"]) }
95
+ if n.run != nil { return .answers(["Take over", "Stop"]) }
77
96
  if let p = n.primary {
78
97
  var rest: [String] = []
79
98
  if n.details != nil { rest.append("Show details") }
@@ -92,6 +111,7 @@ func buttonTitles(_ plan: ButtonPlan) -> [String] {
92
111
  switch plan {
93
112
  case .pulldown(let label, let rest): return [label] + rest + ["Dismiss"]
94
113
  case .single(let title, _): return [title, "Dismiss"]
114
+ case .answers(let titles): return titles + ["Dismiss"]
95
115
  case .none: return []
96
116
  }
97
117
  }
@@ -133,7 +153,7 @@ private func label(_ text: String, font: NSFont, colour: NSColor, lines: Int) ->
133
153
  field.font = font
134
154
  field.textColor = colour
135
155
  field.maximumNumberOfLines = lines
136
- field.lineBreakMode = lines > 1 ? .byWordWrapping : .byTruncatingTail
156
+ field.lineBreakMode = lines == 1 ? .byTruncatingTail : .byWordWrapping // 0 = as many lines as it takes
137
157
  field.cell?.truncatesLastVisibleLine = true
138
158
  field.translatesAutoresizingMaskIntoConstraints = false
139
159
  field.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
@@ -145,7 +165,10 @@ private func label(_ text: String, font: NSFont, colour: NSColor, lines: Int) ->
145
165
  final class AppDelegate: NSObject, NSApplicationDelegate {
146
166
  private var panel: NSPanel?
147
167
  private var timer: DispatchWorkItem?
148
- private var hovering = false
168
+ private var hovering = false {
169
+ // While the pointer is on this alert, an update of it waits (an alert being read is never swapped under the pointer).
170
+ didSet { if hovering != oldValue { markHover(hovering) } }
171
+ }
149
172
 
150
173
  // MARK: actions
151
174
 
@@ -196,8 +219,22 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
196
219
  /// Done: write the action, run the CLI without a Terminal, close. The CLI answers the decision as handled.
197
220
  @objc func markDone(_ sender: Any?) {
198
221
  guard !notice.bin_dir.isEmpty, let decision = notice.details?.decision else { NSApp.terminate(nil); return }
222
+ runQuietly(["action": "done", "decision": decision, "act": notice.details?.act as Any, "space": notice.space as Any].compactMapValues { $0 is NSNull ? nil : $0 })
223
+ }
224
+
225
+ /// Approve / Keep as is, Take over / Stop: the first button is tag 0. The CLI does it, silently.
226
+ @objc func answer(_ sender: NSButton) {
227
+ guard !notice.bin_dir.isEmpty else { NSApp.terminate(nil); return }
228
+ if let c = notice.change {
229
+ runQuietly(["action": "change", "change": c.id, "answer": sender.tag == 0 ? "approve" : "keep", "by": "alert"])
230
+ } else if let r = notice.run {
231
+ runQuietly(["action": "run", "ref": r.ref, "run": sender.tag == 0 ? "takeover" : "stop", "space": notice.space as Any].compactMapValues { $0 is NSNull ? nil : $0 })
232
+ } else { NSApp.terminate(nil) }
233
+ }
234
+
235
+ /// Write the action for `pantheon explain --queued` and run it without a Terminal, then close.
236
+ private func runQuietly(_ payload: [String: Any]) {
199
237
  let dir = URL(fileURLWithPath: notice.bin_dir)
200
- let payload: [String: Any] = ["action": "done", "decision": decision, "act": notice.details?.act as Any, "space": notice.space as Any].compactMapValues { $0 is NSNull ? nil : $0 }
201
238
  if let data = try? JSONSerialization.data(withJSONObject: payload) {
202
239
  try? data.write(to: dir.appendingPathComponent(".hud-action.json"), options: .atomic)
203
240
  }
@@ -223,6 +260,19 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
223
260
  act(["action": "fix", "dir": f.dir, "lines": f.lines, "why": f.why], command: "pantheon-details.command")
224
261
  }
225
262
 
263
+ /// Review: the waiting setup changes, one by one, in Terminal — or the board, for several started requests.
264
+ @objc func reviewIt(_ sender: Any?) {
265
+ guard let r = notice.review, !notice.bin_dir.isEmpty else { NSApp.terminate(nil); return }
266
+ if r.what == "changes" { act(["action": "changes"], command: "pantheon-details.command"); return }
267
+ let bin = (notice.pantheon?.isEmpty == false) ? notice.pantheon! : "pantheon"
268
+ let quoted = "'" + bin.replacingOccurrences(of: "'", with: "'\\''") + "'"
269
+ let p = Process()
270
+ p.executableURL = URL(fileURLWithPath: "/bin/sh")
271
+ p.arguments = ["-lc", "\(quoted) board --open >/dev/null 2>&1"]
272
+ try? p.run()
273
+ NSApp.terminate(nil)
274
+ }
275
+
226
276
  @objc func legacyOpen(_ sender: Any?) {
227
277
  if !legacyPrompt.isEmpty { NSPasteboard.general.clearContents(); NSPasteboard.general.setString(legacyPrompt, forType: .string) }
228
278
  if let b = legacyBundle, let url = NSWorkspace.shared.urlForApplication(withBundleIdentifier: b) {
@@ -277,8 +327,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
277
327
 
278
328
  let who = label(notice.who, font: .systemFont(ofSize: 12, weight: .medium), colour: .secondaryLabelColor, lines: 1)
279
329
  let heading = label(notice.heading, font: .systemFont(ofSize: 16, weight: .semibold), colour: .labelColor, lines: 1)
280
- let context = label(notice.context, font: .systemFont(ofSize: 12, weight: .medium), colour: .tertiaryLabelColor, lines: 1)
281
- let body = label(notice.body, font: .systemFont(ofSize: 13), colour: .secondaryLabelColor, lines: 3)
330
+ // What a setup change would do is shown whole, every line of it: a person never approves words
331
+ // the panel cut off. Everything else keeps its three lines.
332
+ let whole = notice.change != nil || notice.kind == "setup" || notice.review != nil
333
+ let context = label(notice.context, font: .systemFont(ofSize: 12, weight: .medium), colour: whole ? .secondaryLabelColor : .tertiaryLabelColor, lines: whole ? 0 : 1)
334
+ let body = label(notice.body, font: .systemFont(ofSize: 13), colour: .secondaryLabelColor, lines: whole ? 0 : 3)
282
335
 
283
336
  let close = NSButton(title: "×", target: self, action: #selector(dismiss(_:)))
284
337
  close.isBordered = false
@@ -371,7 +424,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
371
424
  root.addSubview(dis)
372
425
  constraints += [dis.leadingAnchor.constraint(equalTo: trailing.trailingAnchor, constant: 14), dis.centerYAnchor.constraint(equalTo: pull.centerYAnchor)]
373
426
  } else if case .single(let title, let what) = plan {
374
- let main = NSButton(title: title, target: self, action: what == .legacyOpen ? #selector(legacyOpen(_:)) : what == .fix ? #selector(fixIt(_:)) : #selector(showDetails(_:)))
427
+ let main = NSButton(title: title, target: self, action: what == .legacyOpen ? #selector(legacyOpen(_:)) : what == .fix ? #selector(fixIt(_:)) : what == .review ? #selector(reviewIt(_:)) : #selector(showDetails(_:)))
375
428
  main.bezelStyle = .rounded; main.font = .systemFont(ofSize: 12, weight: .semibold)
376
429
  main.translatesAutoresizingMaskIntoConstraints = false
377
430
  let dis = NSButton(title: "Dismiss", target: self, action: #selector(dismiss(_:)))
@@ -383,6 +436,28 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
383
436
  dis.leadingAnchor.constraint(equalTo: main.trailingAnchor, constant: 14), dis.centerYAnchor.constraint(equalTo: main.centerYAnchor),
384
437
  ]
385
438
  }
439
+ if case .answers(let titles) = plan {
440
+ var trailing: NSView? = nil
441
+ for (n, title) in titles.enumerated() {
442
+ let b = NSButton(title: title, target: self, action: #selector(answer(_:)))
443
+ b.tag = n
444
+ if n == 0 { b.bezelStyle = .rounded; b.font = .systemFont(ofSize: 12, weight: .semibold) }
445
+ else { b.isBordered = false; b.font = .systemFont(ofSize: 12, weight: .medium); b.contentTintColor = .controlAccentColor }
446
+ b.translatesAutoresizingMaskIntoConstraints = false
447
+ root.addSubview(b)
448
+ if let t = trailing {
449
+ constraints += [b.leadingAnchor.constraint(equalTo: t.trailingAnchor, constant: 14), b.centerYAnchor.constraint(equalTo: t.centerYAnchor)]
450
+ } else {
451
+ constraints += [b.leadingAnchor.constraint(equalTo: who.leadingAnchor), b.topAnchor.constraint(equalTo: body.bottomAnchor, constant: 16), b.bottomAnchor.constraint(equalTo: root.bottomAnchor, constant: -14)]
452
+ }
453
+ trailing = b
454
+ }
455
+ let dis = NSButton(title: "Dismiss", target: self, action: #selector(dismiss(_:)))
456
+ dis.isBordered = false; dis.font = .systemFont(ofSize: 12); dis.contentTintColor = .secondaryLabelColor
457
+ dis.translatesAutoresizingMaskIntoConstraints = false
458
+ root.addSubview(dis)
459
+ if let t = trailing { constraints += [dis.leadingAnchor.constraint(equalTo: t.trailingAnchor, constant: 14), dis.centerYAnchor.constraint(equalTo: t.centerYAnchor)] }
460
+ }
386
461
  if case .none = plan {
387
462
  constraints.append(body.bottomAnchor.constraint(equalTo: root.bottomAnchor, constant: -16))
388
463
  }
@@ -390,26 +465,142 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
390
465
 
391
466
  panel.contentView = effect
392
467
  effect.layoutSubtreeIfNeeded()
393
- let height = max(120, root.fittingSize.height)
394
- panel.setContentSize(NSSize(width: width, height: height))
395
- effect.frame = NSRect(x: 0, y: 0, width: width, height: height)
396
468
  guard let screen = NSScreen.main ?? NSScreen.screens.first else { NSApp.terminate(nil); return }
397
469
  let visible = screen.visibleFrame
470
+ let height = min(max(120, root.fittingSize.height), visible.height - 36)
471
+ panel.setContentSize(NSSize(width: width, height: height))
472
+ effect.frame = NSRect(x: 0, y: 0, width: width, height: height)
473
+ // One alert per thing: the alert with this tag already on screen is replaced, in place — no slide, no second sound.
474
+ // Not while the pointer is on it: the update waits until the pointer leaves (or two minutes pass).
475
+ waitForPointer(until: Date().addingTimeInterval(120)) { [weak self] in self?.present(panel, width: width, height: height, visible: visible) }
476
+ }
477
+
478
+ func present(_ panel: NSPanel, width: CGFloat, height: CGFloat, visible: NSRect) {
479
+ let replaced = replacePrevious()
398
480
  let target = NSPoint(x: visible.maxX - width - 18, y: visible.maxY - height - 18)
399
- panel.setFrameOrigin(NSPoint(x: target.x + 24, y: target.y))
400
- panel.alphaValue = 0
401
- panel.orderFrontRegardless()
402
- NSAnimationContext.runAnimationGroup { context in
403
- context.duration = 0.22
404
- panel.animator().alphaValue = 1
405
- panel.animator().setFrameOrigin(target)
481
+ if replaced {
482
+ panel.setFrameOrigin(target)
483
+ panel.orderFrontRegardless()
484
+ } else {
485
+ panel.setFrameOrigin(NSPoint(x: target.x + 24, y: target.y))
486
+ panel.alphaValue = 0
487
+ panel.orderFrontRegardless()
488
+ NSAnimationContext.runAnimationGroup { context in
489
+ context.duration = 0.22
490
+ panel.animator().alphaValue = 1
491
+ panel.animator().setFrameOrigin(target)
492
+ }
493
+ if notice.sound { NSSound(named: "Glass")?.play() }
406
494
  }
407
- if notice.sound { NSSound(named: "Glass")?.play() }
408
495
  self.panel = panel
409
496
  schedule()
410
497
  }
411
498
  }
412
499
 
500
+ /// The executable a pid runs, or nil: a pid is ended only when it is this same helper (never a reused pid's process).
501
+ func executablePath(_ pid: Int32) -> String? {
502
+ var buf = [CChar](repeating: 0, count: 4096)
503
+ let n = proc_pidpath(pid, &buf, UInt32(buf.count))
504
+ return n > 0 ? URL(fileURLWithPath: String(cString: buf)).resolvingSymlinksInPath().path : nil
505
+ }
506
+
507
+ /// The arguments a process was started with (KERN_PROCARGS2), or nil.
508
+ func processArgs(_ pid: Int32) -> [String]? {
509
+ var argmax: Int32 = 0
510
+ var sz = MemoryLayout<Int32>.size
511
+ var m1: [Int32] = [CTL_KERN, KERN_ARGMAX]
512
+ guard sysctl(&m1, 2, &argmax, &sz, nil, 0) == 0, argmax > 0 else { return nil }
513
+ var buf = [UInt8](repeating: 0, count: Int(argmax))
514
+ var size = Int(argmax)
515
+ var m2: [Int32] = [CTL_KERN, KERN_PROCARGS2, pid]
516
+ guard sysctl(&m2, 3, &buf, &size, nil, 0) == 0, size > 4 else { return nil }
517
+ let argc = Int(buf.withUnsafeBytes { $0.load(as: Int32.self) })
518
+ var i = 4
519
+ while i < size && buf[i] != 0 { i += 1 } // the executable's path
520
+ while i < size && buf[i] == 0 { i += 1 } // its padding
521
+ var out: [String] = []
522
+ while out.count < argc && i < size {
523
+ let start = i
524
+ while i < size && buf[i] != 0 { i += 1 }
525
+ out.append(String(decoding: buf[start..<i], as: UTF8.self))
526
+ i += 1
527
+ }
528
+ return out
529
+ }
530
+
531
+ /// Is `pid` this same helper, showing an alert with this same tag from the same Pantheon folder? Only such a one is ever ended.
532
+ func sameAlert(_ pid: Int32) -> Bool {
533
+ guard pid > 1, pid != getpid(), let mine = executablePath(getpid()), executablePath(pid) == mine,
534
+ let a = processArgs(pid), a.count >= 4, a[1] == "post", a[2] == "--json", let d = a[3].data(using: .utf8),
535
+ let n = try? JSONDecoder().decode(Notice.self, from: d) else { return false }
536
+ return n.tag != nil && n.tag == notice.tag && n.bin_dir == notice.bin_dir
537
+ }
538
+
539
+ /// The marker an alert keeps while the pointer is on it.
540
+ func hoverFile(_ tag: String) -> URL? {
541
+ guard let f = tagPidFile(tag) else { return nil }
542
+ return f.deletingPathExtension().appendingPathExtension("hover")
543
+ }
544
+
545
+ /// The update waiting for the pointer to leave: only the newest one waits; an older one gives way.
546
+ func nextFile(_ tag: String) -> URL? {
547
+ guard let f = tagPidFile(tag) else { return nil }
548
+ return f.deletingPathExtension().appendingPathExtension("next")
549
+ }
550
+
551
+ /// The pid file of the panel showing a tag: a new panel with the same tag ends the old one.
552
+ func tagPidFile(_ tag: String) -> URL? {
553
+ guard !notice.bin_dir.isEmpty, !tag.isEmpty, tag.range(of: "^[A-Za-z0-9_]{1,60}$", options: .regularExpression) != nil else { return nil }
554
+ return URL(fileURLWithPath: notice.bin_dir).appendingPathComponent(".hud-\(tag).pid")
555
+ }
556
+
557
+ extension AppDelegate {
558
+ /// Say (in a marker beside the pid file) whether the pointer is on this alert.
559
+ func markHover(_ on: Bool) {
560
+ guard let tag = notice.tag, let f = hoverFile(tag) else { return }
561
+ if on { try? "\(getpid())".write(to: f, atomically: true, encoding: .utf8) }
562
+ else if let t = try? String(contentsOf: f, encoding: .utf8), t.trimmingCharacters(in: .whitespacesAndNewlines) == "\(getpid())" { try? FileManager.default.removeItem(at: f) }
563
+ }
564
+
565
+ /// Run `then` once no alert with this tag has the pointer on it (checked twice a second), or at `until`.
566
+ /// Several updates arriving meanwhile coalesce: each new one takes the waiting slot (`.next`), and an
567
+ /// older one that finds the slot taken quits — so only the newest appears when the pointer leaves.
568
+ func waitForPointer(until: Date, claimed: Bool = false, then: @escaping () -> Void) {
569
+ let me = "\(getpid())"
570
+ let slot = notice.tag.flatMap { nextFile($0) }
571
+ let read = { (u: URL?) -> String? in u.flatMap { try? String(contentsOf: $0, encoding: .utf8) }?.trimmingCharacters(in: .whitespacesAndNewlines) }
572
+ guard let tag = notice.tag, let f = hoverFile(tag), let t = read(f), let pid = Int32(t), sameAlert(pid), Date() < until else {
573
+ if let s = slot, read(s) == me { try? FileManager.default.removeItem(at: s) }
574
+ then(); return
575
+ }
576
+ if let s = slot {
577
+ // The first look claims the slot (a newer update always takes it); a later look that finds another's there quits.
578
+ if !claimed { try? me.write(to: s, atomically: true, encoding: .utf8) }
579
+ else if let held = read(s), held != me, let other = Int32(held), sameAlert(other) { NSApp.terminate(nil); return }
580
+ }
581
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak self] in self?.waitForPointer(until: until, claimed: true, then: then) }
582
+ }
583
+
584
+ /// End the panel already showing this alert's tag — only when that pid is this same helper showing this same
585
+ /// tag (its own arguments say so) — and take its place.
586
+ func replacePrevious() -> Bool {
587
+ guard let tag = notice.tag, let f = tagPidFile(tag) else { return false }
588
+ var replaced = false
589
+ if let text = try? String(contentsOf: f, encoding: .utf8), let pid = Int32(text.trimmingCharacters(in: .whitespacesAndNewlines)), sameAlert(pid) {
590
+ kill(pid, SIGTERM)
591
+ replaced = true
592
+ }
593
+ try? "\(getpid())".write(to: f, atomically: true, encoding: .utf8)
594
+ atexit {
595
+ guard let tag = notice.tag else { return }
596
+ for f in [tagPidFile(tag), hoverFile(tag), nextFile(tag)].compactMap({ $0 }) {
597
+ if let t = try? String(contentsOf: f, encoding: .utf8), t.trimmingCharacters(in: .whitespacesAndNewlines) == "\(getpid())" { try? FileManager.default.removeItem(at: f) }
598
+ }
599
+ }
600
+ return replaced
601
+ }
602
+ }
603
+
413
604
  /// Tracks the pointer so a notification being read does not fade under it.
414
605
  final class HoverView: NSView {
415
606
  var onHover: ((Bool) -> Void)?
@@ -110,6 +110,8 @@ struct Item {
110
110
  var claimed: Bool = false
111
111
  /// a delivery this person's agent committed to — theirs, not a teammate's request
112
112
  var promise: Bool = false
113
+ /// under "Your agents are handling": the request Take over / Stop act on (tray.ts run.ref), "" when neither applies
114
+ var runRef: String = ""
113
115
 
114
116
  var isDecision: Bool { kind == "decision" }
115
117
  /// A tray-status from before lanes — or with a lane this helper does not know —
@@ -121,6 +123,7 @@ struct Item {
121
123
  switch kind {
122
124
  case "decision": return "Needs your decision"
123
125
  case "owed": return "Your side owes this"
126
+ case "change": return "Your setup — waiting for you"
124
127
  default: return "Waiting on \(who)"
125
128
  }
126
129
  }
@@ -220,7 +223,8 @@ func fetchState() -> TrayState {
220
223
  lane: i["lane"] as? String ?? "",
221
224
  context: i["context"] as? String ?? "",
222
225
  claimed: i["claimed"] as? Bool ?? false,
223
- promise: i["promise"] as? Bool ?? false
226
+ promise: i["promise"] as? Bool ?? false,
227
+ runRef: (i["run"] as? [String: Any])?["ref"] as? String ?? ""
224
228
  ))
225
229
  }
226
230
  for d in (j["decisions"] as? [[String: Any]] ?? []) {
@@ -1367,14 +1371,16 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
1367
1371
  stack.addArrangedSubview(scroll)
1368
1372
  stack.setCustomSpacing(14, after: stack.arrangedSubviews[1])
1369
1373
 
1370
- var meta = item.isDecision ? "decision \(item.id)" : "obligation \(item.id)"
1374
+ var meta = item.kind == "change" ? "setup change \(item.id)" : item.isDecision ? "decision \(item.id)" : "obligation \(item.id)"
1371
1375
  if !item.goal.isEmpty { meta += " · goal \(item.goal)" }
1372
1376
  stack.addArrangedSubview(label(meta, size: 11, weight: .regular, color: .tertiaryLabelColor, width: inner))
1373
1377
 
1374
1378
  // Whose decision this is, said before the box that answers it. Your own
1375
1379
  // answer to a teammate's decision lands as an act and settles nothing, so the
1376
1380
  // panel offers Answer only to the person it is waiting on.
1377
- let owner: String = item.isDecision ? "Yours to decide."
1381
+ let owner: String = item.kind == "change" ? "Your agent asked to change your setup. Nothing changes until you approve it."
1382
+ : !item.runRef.isEmpty ? "Your agent is working on this now."
1383
+ : item.isDecision ? "Yours to decide."
1378
1384
  : !item.decider.isEmpty ? "\(item.decider)'s to decide. You can add a note or ask back."
1379
1385
  : item.kind == "owed" ? "Your agent owes this. You can add a note or ask back."
1380
1386
  : "Waiting on \(item.who). You can add a note or ask back."
@@ -1398,6 +1404,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
1398
1404
  replyBtn.setContentCompressionResistancePriority(.required, for: .horizontal)
1399
1405
  replyBtn.toolTip = "Type your own answer, note or question. Nothing is drafted for you, and nothing is sent until you press Send."
1400
1406
  panelReplyButton = replyBtn
1407
+ // A setup change is answered with Approve or Keep as is, never with a reply.
1408
+ replyBtn.isHidden = item.kind == "change"
1409
+ if item.kind == "change" { replyBtn.keyEquivalent = "" }
1401
1410
  ownerRow.addArrangedSubview(replyBtn)
1402
1411
  ownerRow.widthAnchor.constraint(equalToConstant: inner).isActive = true
1403
1412
  if let idLine = stack.arrangedSubviews.last { stack.setCustomSpacing(6, after: idLine) }
@@ -1522,9 +1531,36 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
1522
1531
  rows.addArrangedSubview(row0)
1523
1532
  }
1524
1533
 
1534
+ // A change to this person's setup: what it would do is the text above, in full; then Approve or Keep as is.
1535
+ if item.kind == "change" {
1536
+ let row0 = NSStackView()
1537
+ row0.orientation = .horizontal
1538
+ row0.spacing = 10
1539
+ let ok = button("Approve", #selector(panelChange(_:)), "Makes this change to your setup.")
1540
+ ok.tag = 0; ok.keyEquivalent = ""
1541
+ let keep = button("Keep as is", #selector(panelChange(_:)), "Leaves your setup as it is. Nothing changes.")
1542
+ keep.tag = 1
1543
+ row0.addArrangedSubview(ok); row0.addArrangedSubview(keep)
1544
+ rows.addArrangedSubview(row0)
1545
+ }
1546
+
1547
+ // Work the worker has under "Your agents are handling": take it back, or stop it (run-control.ts).
1548
+ if !item.runRef.isEmpty {
1549
+ let row0 = NSStackView()
1550
+ row0.orientation = .horizontal
1551
+ row0.spacing = 10
1552
+ let take = button("Take over", #selector(panelRun(_:)), "Stops your agent's work on it and makes it yours: your teammate is told you're handling it personally.")
1553
+ take.tag = 0
1554
+ let stop = button("Stop", #selector(panelRun(_:)), "Stops your agent's work on it. Your agent won't pick it up again, and your teammate is told you stopped it.")
1555
+ stop.tag = 1
1556
+ row0.addArrangedSubview(take); row0.addArrangedSubview(stop)
1557
+ rows.addArrangedSubview(row0)
1558
+ }
1559
+
1525
1560
  let row1 = NSStackView()
1526
1561
  row1.orientation = .horizontal
1527
1562
  row1.spacing = 10
1563
+ row1.isHidden = item.kind == "change"
1528
1564
  row1.addArrangedSubview(button("Explain in \(state.surfaceName)", #selector(panelOpen),
1529
1565
  "Opens \(state.surfaceName) in the team's folder and asks it to lay out your options. It will not decide or reply for you."))
1530
1566
  if item.isDecision {
@@ -1688,6 +1724,54 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
1688
1724
  }
1689
1725
  }
1690
1726
 
1727
+ /// Approve (tag 0) or Keep as is (tag 1) on a change to this person's setup — the text above was the whole of it.
1728
+ @objc private func panelChange(_ sender: NSButton) {
1729
+ guard let item = panelItem, item.kind == "change" else { return }
1730
+ let answer = sender.tag == 0 ? "approve" : "keep"
1731
+ guard writeAction(["action": "change", "change": item.id, "answer": answer, "by": "tray"]) else { setStatus("Could not write the action. In a terminal: pantheon changes"); return }
1732
+ setStatus(answer == "approve" ? "Approving…" : "Keeping it as it is…")
1733
+ sender.isEnabled = false
1734
+ DispatchQueue.global().async {
1735
+ let r = run(pantheonBin, ["explain", "--queued"], timeout: 60)
1736
+ DispatchQueue.main.async {
1737
+ sender.isEnabled = true
1738
+ let out = (r?.out ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
1739
+ if r?.code == 0 {
1740
+ self.setStatus(answer == "approve" ? "Approved — your setup is changed." : "Kept as it is — nothing changed.")
1741
+ self.refresh()
1742
+ } else {
1743
+ self.setStatus(out.hasPrefix("not sent: ") ? String(out.dropFirst("not sent: ".count)) : "Could not answer it — in a terminal: pantheon changes")
1744
+ }
1745
+ }
1746
+ }
1747
+ }
1748
+
1749
+ /// Take over (tag 0) or Stop (tag 1) on work under "Your agents are handling": written for the worker, which stops its run.
1750
+ @objc private func panelRun(_ sender: NSButton) {
1751
+ guard let item = panelItem, !item.runRef.isEmpty else { return }
1752
+ let how = sender.tag == 0 ? "takeover" : "stop"
1753
+ var payload: [String: Any] = ["action": "run", "ref": item.runRef, "run": how]
1754
+ // Always with its team: on one team the item carries none, so the status's own team is it (review round 3).
1755
+ let team = item.space.isEmpty ? state.space : item.space
1756
+ if !team.isEmpty { payload["space"] = team }
1757
+ guard writeAction(payload) else { setStatus("Could not write the action. Use Show the thread instead."); return }
1758
+ setStatus(how == "takeover" ? "Taking it over…" : "Stopping…")
1759
+ sender.isEnabled = false
1760
+ DispatchQueue.global().async {
1761
+ let r = run(pantheonBin, ["explain", "--queued"], timeout: 25)
1762
+ DispatchQueue.main.async {
1763
+ sender.isEnabled = true
1764
+ let out = (r?.out ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
1765
+ if r?.code == 0 {
1766
+ self.setStatus(how == "takeover" ? "It's yours now — your teammate is told you're handling it." : "Stopped — your agent won't pick it up again.")
1767
+ self.refresh()
1768
+ } else {
1769
+ self.setStatus(out.hasPrefix("not sent: ") ? String(out.dropFirst("not sent: ".count)) : "Could not stop it — try again")
1770
+ }
1771
+ }
1772
+ }
1773
+ }
1774
+
1691
1775
  /// One of the decision's stated options, sent as its ANSWER — the same local path a typed answer takes.
1692
1776
  @objc private func panelChooseOption(_ sender: NSButton) {
1693
1777
  guard let item = panelItem, sender.tag >= 0, sender.tag < panelOptionList.count else { return }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "format": 1,
3
- "built_at": "2026-10-13T22:11:23.149Z",
3
+ "built_at": "2026-10-14T11:53:40.645Z",
4
4
  "swiftc": "Apple Swift version 6.3.3 (swiftlang-6.3.3.1.3 clang-2100.1.1.101)",
5
5
  "helpers": {
6
6
  "pantheon-tray": {
7
7
  "source": "menubar.swift",
8
- "source_sha256": "9bf57ddc5d356fafb0bafe0f214f5ef2cbba66b03b9cd1370016ce282e47c1ac",
9
- "sha256": "c73c1f1ae8ed6932dc0aee6c63f3d50457f6eb493b8d0a49f77022c779e32b2d",
8
+ "source_sha256": "41a787261a7b50ce12b8e846f698a3c3ab4861b17664a90e71f50abc7777c4d1",
9
+ "sha256": "4e0c4e7f9006891593e8d9b73098e5055ba63a70946893eecca041c2d2e1aac3",
10
10
  "archs": [
11
11
  "arm64",
12
12
  "x86_64"
@@ -16,8 +16,8 @@
16
16
  },
17
17
  "pantheon-hud": {
18
18
  "source": "main.swift",
19
- "source_sha256": "d3e4b3df9442901ffc5eb95d4679fe08e428f0f67b1f3f86d68ed7ea036de691",
20
- "sha256": "f855bac430e21a63b94917170ef5fe7adb46cdd37441f5aa7a84168a45062f6c",
19
+ "source_sha256": "eb2d10c53246bd705baf4698d0e637e42d3d7f84b1c325702e9c9f056344c83e",
20
+ "sha256": "18d58739022b20539b57720511e9b9e7f3a2188dc8da77fe15ce0f6c83cd16d4",
21
21
  "archs": [
22
22
  "arm64",
23
23
  "x86_64"
Binary file
Binary file
@@ -45,7 +45,9 @@ function global:Get-PantheonToastSetting($Notifier) {
45
45
  # One toast: the XML, tried under each app id in turn. Returns @{ code; said }.
46
46
  # $Api stands in for the WinRT calls (the checks run it on Linux); left out,
47
47
  # the real ToastNotificationManager is used.
48
- function global:Show-PantheonToast([string]$Xml, [string]$Tag, [string[]]$Aumids, [hashtable]$Api = $null) {
48
+ # $ExpiresMinutes: a toast about something that soon stops being true (work the
49
+ # worker started) leaves the Action Center on its own after this long; 0 = never.
50
+ function global:Show-PantheonToast([string]$Xml, [string]$Tag, [string[]]$Aumids, [hashtable]$Api = $null, [int]$ExpiresMinutes = 0) {
49
51
  $said = New-Object System.Collections.Generic.List[string]
50
52
  $doc = $null
51
53
  if (-not $Api) {
@@ -76,6 +78,7 @@ function global:Show-PantheonToast([string]$Xml, [string]$Tag, [string[]]$Aumids
76
78
  if ($setting -like 'Disabled*') { $said.Add('off ' + $id + ' ' + $setting); continue }
77
79
  $toast = & $Api.toast $doc
78
80
  if ($Tag) { $toast.Tag = $Tag; $toast.Group = 'pantheon' }
81
+ if ($ExpiresMinutes -gt 0 -and $ExpiresMinutes -le 1440) { try { $toast.ExpirationTime = [DateTimeOffset]::Now.AddMinutes($ExpiresMinutes) } catch { } }
79
82
  $notifier.Show($toast)
80
83
  # Pantheon's own app id is used only when Windows then has the toast in
81
84
  # its history for that id: a build that ignores the registration falls
@@ -119,7 +122,8 @@ if ($Mode -eq 'toast') {
119
122
  $ErrorActionPreference = 'Stop'
120
123
  $xml = ''
121
124
  try { $xml = ConvertFrom-PantheonB64 ([string]$env:PANTHEON_TOAST_XML) } catch { [Console]::Out.WriteLine('bad-input ' + $_.Exception.Message); exit 3 }
122
- $r = Show-PantheonToast $xml ([string]$env:PANTHEON_TOAST_TAG) (([string]$env:PANTHEON_TOAST_AUMIDS) -split ';')
125
+ $exp = 0; if ([string]$env:PANTHEON_TOAST_EXPIRES -match '^\d{1,4}$') { $exp = [int]$env:PANTHEON_TOAST_EXPIRES }
126
+ $r = Show-PantheonToast $xml ([string]$env:PANTHEON_TOAST_TAG) (([string]$env:PANTHEON_TOAST_AUMIDS) -split ';') $null $exp
123
127
  foreach ($l in $r.said) { [Console]::Out.WriteLine($l) }
124
128
  exit $r.code
125
129
  }