@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/worker.js CHANGED
@@ -34,8 +34,10 @@ import { clip } from "./brief.js";
34
34
  import { composeWakeAsk, composeWorker } from "./notice.js";
35
35
  import { diagnoseRun, gitProbe, workNeedsCommands } from "./run-failure.js";
36
36
  import { installedTools, preferredTool } from "./notifier.js";
37
+ import { obligationSignature, StatusNudger } from "./status-nudge.js";
38
+ import { clientState, ConnectionReport } from "./conn-report.js";
37
39
  import { loadPersonas, matchPersona, personaByName, personaMatches, effectivePolicy, personaBrief, describePersona, } from "./persona.js";
38
- import { CONFIG_PATH, loadAll, repoInfo, updateMembershipToken } from "./config.js";
40
+ import { CONFIG_DIR, CONFIG_PATH, loadAll, repoInfo, updateMembershipToken } from "./config.js";
39
41
  import { shellArg } from "./team-name.js";
40
42
  import { repoName, routeRequest, safeName } from "./repo-route.js";
41
43
  import { holdsRepo } from "./repo-find.js";
@@ -2312,14 +2314,19 @@ export class Worker {
2312
2314
  ...(fromSeq ? { fromSeq } : {}),
2313
2315
  persistToken: (space, oldToken, newToken) => { updateMembershipToken(space, oldToken, newToken); trustWrite(CONFIG_PATH); },
2314
2316
  });
2315
- this.recoverGuard();
2316
- await client.connect();
2317
- this.client = client;
2317
+ const nudger = new StatusNudger(this.opts.home ?? CONFIG_DIR);
2318
+ const report = new ConnectionReport({ home: this.opts.home ?? CONFIG_DIR, role: "worker", space: this.cfg.space });
2319
+ report.observe("down");
2320
+ client.onChange = () => { nudger.observe(obligationSignature(client.obligations, client.connected)); report.observe(clientState(client)); };
2318
2321
  try {
2322
+ this.recoverGuard();
2323
+ await client.connect();
2324
+ this.client = client;
2319
2325
  await (this.opts.alertsOnly ? this.sayKeyChanges(client) : this.opts.housekeeping ? this.keepHouse(client) : this.serve(client));
2320
2326
  }
2321
2327
  finally {
2322
2328
  client.close();
2329
+ report.close();
2323
2330
  }
2324
2331
  }
2325
2332
  async keepHouse(client) {
@@ -2985,7 +2992,7 @@ export class Worker {
2985
2992
  killRunTree(r.pid);
2986
2993
  const sb = r.sandbox;
2987
2994
  if (sb && typeof sb.common === "string" && Array.isArray(sb.absent)) {
2988
- this.sandboxPending = { pid: Number.isInteger(r.pid) ? r.pid : 0, common: sb.common, absent: sb.absent.filter((x) => typeof x === "string") };
2995
+ this.sandboxPending = { pid: Number.isInteger(r.pid) ? r.pid : 0, common: sb.common, absent: sb.absent.filter((x) => typeof x === "string"), own: typeof sb.own === "string" ? sb.own : null };
2989
2996
  this.cleanPendingSandbox();
2990
2997
  }
2991
2998
  try {
@@ -3019,7 +3026,7 @@ export class Worker {
3019
3026
  return;
3020
3027
  this.sandboxPending = null;
3021
3028
  try {
3022
- const gone = removeSandboxLeftovers(p.absent, p.common);
3029
+ const gone = removeSandboxLeftovers(p.absent, p.common, p.own);
3023
3030
  if (gone.length)
3024
3031
  this.opts.log(` confine removed ${gone.length} empty mount point${gone.length === 1 ? "" : "s"} the interrupted run's sandbox left: ${gone.map((g) => basename(g)).join(", ")}`);
3025
3032
  }
@@ -3342,6 +3349,7 @@ export class Worker {
3342
3349
  let fenced = null;
3343
3350
  let sandboxAbsent = [];
3344
3351
  let sandboxCommon = "";
3352
+ let sandboxOwn = null;
3345
3353
  let heldRun = null;
3346
3354
  if (!client.features.includes("delegate") && client.signaturesExpected()) {
3347
3355
  const says = "this team's relay signs messages but did not offer a key for the run, so the run would have needed your own key — it was not started";
@@ -3418,6 +3426,7 @@ export class Worker {
3418
3426
  const own = ownWorktreeConfig(worktree, gc);
3419
3427
  if (own && !sandboxAbsent.includes(own))
3420
3428
  sandboxAbsent = [own, ...sandboxAbsent];
3429
+ sandboxOwn = own;
3421
3430
  }
3422
3431
  catch {
3423
3432
  sandboxAbsent = [];
@@ -3503,7 +3512,7 @@ export class Worker {
3503
3512
  }
3504
3513
  const pid = child.pid;
3505
3514
  if (pid)
3506
- this.trackRun(pid, { obligation: o.id, ref: runRef, spend: spendId, limit: runLimit.ms, ...(sandboxAbsent.length ? { sandbox: { common: sandboxCommon, absent: sandboxAbsent } } : {}) });
3515
+ this.trackRun(pid, { obligation: o.id, ref: runRef, spend: spendId, limit: runLimit.ms, ...(sandboxAbsent.length ? { sandbox: { common: sandboxCommon, absent: sandboxAbsent, ...(sandboxOwn ? { own: sandboxOwn } : {}) } } : {}) });
3507
3516
  let head = "", tail = "";
3508
3517
  const take = (b) => {
3509
3518
  const s = b.toString();
@@ -3572,7 +3581,7 @@ export class Worker {
3572
3581
  }
3573
3582
  finally {
3574
3583
  this.cleanupStep("removing the sandbox's empty mount points", () => {
3575
- const gone = sandboxAbsent.length ? removeSandboxLeftovers(sandboxAbsent, sandboxCommon) : [];
3584
+ const gone = sandboxAbsent.length ? removeSandboxLeftovers(sandboxAbsent, sandboxCommon, sandboxOwn) : [];
3576
3585
  if (gone.length)
3577
3586
  this.opts.log(` confine removed ${gone.length} empty mount point${gone.length === 1 ? "" : "s"} the sandbox left: ${gone.map((g) => basename(g)).join(", ")}`);
3578
3587
  for (const k of describeKept(sandboxAbsent.filter((p) => !gone.includes(p))))
@@ -152,6 +152,37 @@ func jsonString(_ s: String) -> String {
152
152
  return String(arr.dropFirst().dropLast())
153
153
  }
154
154
 
155
+ /// Secondary text that reads: at least 4.5:1 on the panel in light and dark (0.34.1 review — the system's
156
+ /// tertiary label, used for the context line and ×, was about 2.3:1 on the light panel).
157
+ let readableDim = NSColor(name: nil) { a in
158
+ a.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua ? NSColor(white: 1, alpha: 0.66) : NSColor(white: 0, alpha: 0.64)
159
+ }
160
+
161
+ /// The accent as link text that reads at 4.5:1 or more: a step darker on the light panel, lighter on the dark
162
+ /// one (the system blue as 12 pt text was 3.6:1 light and 2.9:1 dark).
163
+ let readableAccent = NSColor(name: nil) { a in
164
+ let base = NSColor.controlAccentColor.usingColorSpace(.sRGB) ?? NSColor.systemBlue
165
+ return a.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua ? (base.blended(withFraction: 0.45, of: .white) ?? base) : (base.blended(withFraction: 0.25, of: .black) ?? base)
166
+ }
167
+
168
+ /// The panel's main action, drawn as one: white on the accent colour, as a default button is (0.33.9
169
+ /// design review — "Sign in" read as grey as Dismiss). The panel belongs to an accessory app that is
170
+ /// never active, so the system's default-button look (and a push button's bezel colour) never shows:
171
+ /// it is drawn here. The accent is taken a step darker so white on it is over 4.5:1.
172
+ /// Returns the size constraints for the caller's list.
173
+ private func primary(_ b: NSButton) -> [NSLayoutConstraint] {
174
+ let font = b.font ?? .systemFont(ofSize: 12, weight: .semibold)
175
+ b.isBordered = false
176
+ b.wantsLayer = true
177
+ b.layer?.cornerRadius = 6
178
+ let fill = NSColor.controlAccentColor.usingColorSpace(.sRGB)?.blended(withFraction: 0.18, of: .black) ?? .controlAccentColor
179
+ b.layer?.backgroundColor = fill.cgColor
180
+ b.attributedTitle = NSAttributedString(string: b.title, attributes: [.foregroundColor: NSColor.white, .font: font])
181
+ b.setAccessibilityRole(.button)
182
+ let w = ceil((b.title as NSString).size(withAttributes: [.font: font]).width) + 28
183
+ return [b.widthAnchor.constraint(equalToConstant: w), b.heightAnchor.constraint(equalToConstant: 26)]
184
+ }
185
+
155
186
  private func label(_ text: String, font: NSFont, colour: NSColor, lines: Int) -> NSTextField {
156
187
  let field = NSTextField(wrappingLabelWithString: text)
157
188
  field.font = font
@@ -345,18 +376,19 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
345
376
  root.onHover = { [weak self] inside in self?.hovering = inside }
346
377
  effect.addSubview(root)
347
378
 
348
- let who = label(notice.who, font: .systemFont(ofSize: 12, weight: .medium), colour: .secondaryLabelColor, lines: 1)
379
+ let who = label(notice.who, font: .systemFont(ofSize: 12, weight: .medium), colour: readableDim, lines: 1)
349
380
  let heading = label(notice.heading, font: .systemFont(ofSize: 16, weight: .semibold), colour: .labelColor, lines: 1)
350
381
  // What a setup change would do is shown whole, every line of it: a person never approves words
351
382
  // the panel cut off. Everything else keeps its three lines.
352
383
  let whole = notice.change != nil || notice.kind == "setup" || notice.review != nil
353
- let context = label(notice.context, font: .systemFont(ofSize: 12, weight: .medium), colour: whole ? .secondaryLabelColor : .tertiaryLabelColor, lines: whole ? 0 : 1)
354
- let body = label(notice.body, font: .systemFont(ofSize: 13), colour: .secondaryLabelColor, lines: whole ? 0 : 3)
384
+ let context = label(notice.context, font: .systemFont(ofSize: 12, weight: .medium), colour: readableDim, lines: whole ? 0 : 1)
385
+ // The reading colour: the secondary grey fell under 4.5:1 on the light panel (0.33.9 design review).
386
+ let body = label(notice.body, font: .systemFont(ofSize: 13), colour: .labelColor, lines: whole ? 0 : 3)
355
387
 
356
388
  let close = NSButton(title: "×", target: self, action: #selector(dismiss(_:)))
357
389
  close.isBordered = false
358
390
  close.font = .systemFont(ofSize: 15, weight: .medium)
359
- close.contentTintColor = .tertiaryLabelColor
391
+ close.contentTintColor = readableDim
360
392
  close.translatesAutoresizingMaskIntoConstraints = false
361
393
  close.setAccessibilityLabel("Dismiss")
362
394
 
@@ -413,7 +445,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
413
445
  var trailing: NSView = pull
414
446
  if notice.details != nil {
415
447
  let d = NSButton(title: "Show details", target: self, action: #selector(showDetails(_:)))
416
- d.isBordered = false; d.font = .systemFont(ofSize: 12, weight: .medium); d.contentTintColor = .controlAccentColor
448
+ d.isBordered = false; d.font = .systemFont(ofSize: 12, weight: .medium); d.contentTintColor = readableAccent
417
449
  d.translatesAutoresizingMaskIntoConstraints = false
418
450
  root.addSubview(d)
419
451
  constraints += [d.leadingAnchor.constraint(equalTo: pull.trailingAnchor, constant: 14), d.centerYAnchor.constraint(equalTo: pull.centerYAnchor)]
@@ -421,7 +453,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
421
453
  }
422
454
  if notice.fix != nil {
423
455
  let fix = NSButton(title: notice.fix!.label, target: self, action: #selector(fixIt(_:)))
424
- fix.isBordered = false; fix.font = .systemFont(ofSize: 12, weight: .medium); fix.contentTintColor = .controlAccentColor
456
+ fix.isBordered = false; fix.font = .systemFont(ofSize: 12, weight: .medium); fix.contentTintColor = readableAccent
425
457
  fix.toolTip = notice.fix!.why
426
458
  fix.translatesAutoresizingMaskIntoConstraints = false
427
459
  root.addSubview(fix)
@@ -431,7 +463,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
431
463
  if notice.details?.decision != nil {
432
464
  // A decision can be settled from the banner itself: one click, no terminal, no more reminders.
433
465
  let done = NSButton(title: "Done", target: self, action: #selector(markDone(_:)))
434
- done.isBordered = false; done.font = .systemFont(ofSize: 12, weight: .medium); done.contentTintColor = .controlAccentColor
466
+ done.isBordered = false; done.font = .systemFont(ofSize: 12, weight: .medium); done.contentTintColor = readableAccent
435
467
  done.setAccessibilityLabel("Mark this decision handled")
436
468
  done.translatesAutoresizingMaskIntoConstraints = false
437
469
  root.addSubview(done)
@@ -439,16 +471,17 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
439
471
  trailing = done
440
472
  }
441
473
  let dis = NSButton(title: "Dismiss", target: self, action: #selector(dismiss(_:)))
442
- dis.isBordered = false; dis.font = .systemFont(ofSize: 12); dis.contentTintColor = .secondaryLabelColor
474
+ dis.isBordered = false; dis.font = .systemFont(ofSize: 12); dis.contentTintColor = readableDim
443
475
  dis.translatesAutoresizingMaskIntoConstraints = false
444
476
  root.addSubview(dis)
445
477
  constraints += [dis.leadingAnchor.constraint(equalTo: trailing.trailingAnchor, constant: 14), dis.centerYAnchor.constraint(equalTo: pull.centerYAnchor)]
446
478
  } else if case .single(let title, let what) = plan {
447
479
  let main = NSButton(title: title, target: self, action: what == .legacyOpen ? #selector(legacyOpen(_:)) : what == .fix ? #selector(fixIt(_:)) : what == .review ? #selector(reviewIt(_:)) : #selector(showDetails(_:)))
448
480
  main.bezelStyle = .rounded; main.font = .systemFont(ofSize: 12, weight: .semibold)
481
+ constraints += primary(main)
449
482
  main.translatesAutoresizingMaskIntoConstraints = false
450
483
  let dis = NSButton(title: "Dismiss", target: self, action: #selector(dismiss(_:)))
451
- dis.isBordered = false; dis.font = .systemFont(ofSize: 12); dis.contentTintColor = .secondaryLabelColor
484
+ dis.isBordered = false; dis.font = .systemFont(ofSize: 12); dis.contentTintColor = readableDim
452
485
  dis.translatesAutoresizingMaskIntoConstraints = false
453
486
  root.addSubview(main); root.addSubview(dis)
454
487
  constraints += [
@@ -461,8 +494,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
461
494
  for (n, title) in titles.enumerated() {
462
495
  let b = NSButton(title: title, target: self, action: #selector(answer(_:)))
463
496
  b.tag = n
464
- if n == 0 { b.bezelStyle = .rounded; b.font = .systemFont(ofSize: 12, weight: .semibold) }
465
- else { b.isBordered = false; b.font = .systemFont(ofSize: 12, weight: .medium); b.contentTintColor = .controlAccentColor }
497
+ if n == 0 { b.bezelStyle = .rounded; b.font = .systemFont(ofSize: 12, weight: .semibold); constraints += primary(b) }
498
+ else { b.isBordered = false; b.font = .systemFont(ofSize: 12, weight: .medium); b.contentTintColor = readableAccent }
466
499
  b.translatesAutoresizingMaskIntoConstraints = false
467
500
  root.addSubview(b)
468
501
  if let t = trailing {
@@ -473,7 +506,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
473
506
  trailing = b
474
507
  }
475
508
  let dis = NSButton(title: "Dismiss", target: self, action: #selector(dismiss(_:)))
476
- dis.isBordered = false; dis.font = .systemFont(ofSize: 12); dis.contentTintColor = .secondaryLabelColor
509
+ dis.isBordered = false; dis.font = .systemFont(ofSize: 12); dis.contentTintColor = readableDim
477
510
  dis.translatesAutoresizingMaskIntoConstraints = false
478
511
  root.addSubview(dis)
479
512
  if let t = trailing { constraints += [dis.leadingAnchor.constraint(equalTo: t.trailingAnchor, constant: 14), dis.centerYAnchor.constraint(equalTo: t.centerYAnchor)] }