sprag-cli 3.137.0 → 3.138.0

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.
Files changed (2) hide show
  1. package/mac/SpragBar.swift +79 -0
  2. package/package.json +1 -1
@@ -287,6 +287,79 @@ func jump(to s: Session) {
287
287
  try? p.run()
288
288
  }
289
289
  guard let app = owningApp(s.pid) else { return }
290
+ if let script = TAB_SCRIPTS[app.bundleIdentifier ?? ""], let tty = ttyPath(Int32(s.pid)) {
291
+ selectTab(script, tty: tty) { found in if !found { bringForward(app) } }
292
+ return
293
+ }
294
+ bringForward(app)
295
+ }
296
+ /** The terminal device a process writes to (`/dev/ttys003`), or nil for one without a terminal. */
297
+ func ttyPath(_ pid: Int32) -> String? {
298
+ var info = proc_bsdinfo()
299
+ let size = Int32(MemoryLayout<proc_bsdinfo>.size)
300
+ guard proc_pidinfo(pid, PROC_PIDTBSDINFO, 0, &info, size) == size, info.e_tdev != UInt32.max, let name = devname(dev_t(bitPattern: info.e_tdev), S_IFCHR) else { return nil }
301
+ return "/dev/" + String(cString: name)
302
+ }
303
+ /**
304
+ * Terminals that name each tab's tty to AppleScript, with a script that selects the tab on the tty given as its argument,
305
+ * restores and raises its window and prints true, or prints false when no tab has that tty. Running one asks once for the
306
+ * Automation permission; refused, the script fails and the jump falls back to bringing the app forward.
307
+ */
308
+ let TAB_SCRIPTS: [String: String] = [
309
+ "com.apple.Terminal": """
310
+ on run argv
311
+ tell application id "com.apple.Terminal"
312
+ repeat with w in windows
313
+ repeat with t in tabs of w
314
+ if tty of t is (item 1 of argv) then
315
+ if miniaturized of w then set miniaturized of w to false
316
+ set selected of t to true
317
+ set index of w to 1
318
+ activate
319
+ return true
320
+ end if
321
+ end repeat
322
+ end repeat
323
+ end tell
324
+ return false
325
+ end run
326
+ """,
327
+ "com.googlecode.iterm2": """
328
+ on run argv
329
+ tell application id "com.googlecode.iterm2"
330
+ repeat with w in windows
331
+ repeat with t in tabs of w
332
+ repeat with s in sessions of t
333
+ if tty of s is (item 1 of argv) then
334
+ if miniaturized of w then set miniaturized of w to false
335
+ select w
336
+ tell t to select
337
+ tell s to select
338
+ activate
339
+ return true
340
+ end if
341
+ end repeat
342
+ end repeat
343
+ end repeat
344
+ end tell
345
+ return false
346
+ end run
347
+ """,
348
+ ]
349
+ /** Run a tab script off the main thread; `done` gets whether the tab was found, on the main thread. A permission prompt left unanswered gives up after a minute. */
350
+ func selectTab(_ script: String, tty: String, done: @escaping (Bool) -> Void) {
351
+ let p = Process(), out = Pipe()
352
+ p.executableURL = URL(fileURLWithPath: "/usr/bin/osascript"); p.arguments = ["-e", script, tty]
353
+ p.standardOutput = out; p.standardError = FileHandle.nullDevice
354
+ p.terminationHandler = { _ in
355
+ let text = String(decoding: out.fileHandleForReading.readDataToEndOfFile(), as: UTF8.self).trimmingCharacters(in: .whitespacesAndNewlines)
356
+ DispatchQueue.main.async { done(text == "true") }
357
+ }
358
+ do { try p.run() } catch { done(false); return }
359
+ DispatchQueue.main.asyncAfter(deadline: .now() + 60) { if p.isRunning { p.terminate() } }
360
+ }
361
+ /** Bring a terminal app forward, restoring a minimized window when nothing of it is on screen (see jump). */
362
+ func bringForward(_ app: NSRunningApplication) {
290
363
  app.activate(options: [.activateAllWindows])
291
364
  if let url = app.bundleURL, app.isHidden || !hasWindowOnScreen(app.processIdentifier) {
292
365
  let cfg = NSWorkspace.OpenConfiguration(); cfg.activates = true
@@ -3456,6 +3529,8 @@ struct PanelView: View {
3456
3529
  case .warning(let chip): WarningView(w: model.snap?.warnings?.first { $0.chip == chip }, now: model.snap?.at ?? 0, limit: maxHeight, back: { nav.page = .status })
3457
3530
  }
3458
3531
  }
3532
+ // A page that still comes out taller than the screen loses its bottom, never the header with the back and menu buttons.
3533
+ .frame(maxHeight: still ? nil : maxHeight, alignment: .top)
3459
3534
  }
3460
3535
  /** How many sessions, and how they stand: working, waiting for a go-ahead, waiting for input. Sessions another one started are counted apart. */
3461
3536
  func sessionsTitle(_ snap: Snapshot) -> String {
@@ -3829,6 +3904,10 @@ final class App: NSObject {
3829
3904
  /** Size the window to its content and hang it under the menu bar item, wholly inside the screen. */
3830
3905
  func place() {
3831
3906
  guard let b = item.button, let bw = b.window, let screen = bw.screen ?? NSScreen.main else { return }
3907
+ // The content's own height limit follows the screen the menu bar item is on. Set once from the main screen at
3908
+ // launch, it let a page grow taller than a shorter screen's window, and the window cut the page off at the top.
3909
+ let cap = screen.visibleFrame.height - 12
3910
+ if abs(hosting.rootView.maxHeight - cap) > 0.5 { var v = hosting.rootView; v.maxHeight = cap; hosting.rootView = v }
3832
3911
  hosting.layoutSubtreeIfNeeded()
3833
3912
  let vis = screen.visibleFrame, fit = hosting.fittingSize
3834
3913
  let w = fit.width, h = min(fit.height, vis.height - 12)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sprag-cli",
3
- "version": "3.137.0",
3
+ "version": "3.138.0",
4
4
  "description": "The delegation layer for Claude Code and Codex: each task goes to the model and effort that fits it, down to cheaper models for lookups and up to higher effort when a cheaper run would miss, backed by public replay cases, with a live statusline and team rules for Pro and Enterprise.",
5
5
  "type": "module",
6
6
  "bin": {