agent-command-tab 0.1.0__py3-none-any.whl
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.
- agent_command_tab/__init__.py +4 -0
- agent_command_tab/agent_adapters/__init__.py +48 -0
- agent_command_tab/agent_adapters/base.py +162 -0
- agent_command_tab/agent_adapters/claude_code.py +120 -0
- agent_command_tab/agent_adapters/codex.py +102 -0
- agent_command_tab/agent_adapters/generic.py +22 -0
- agent_command_tab/agent_process_tree.py +557 -0
- agent_command_tab/agent_session_pausing.py +254 -0
- agent_command_tab/app_controller.py +947 -0
- agent_command_tab/claude_code_transcript_records.py +75 -0
- agent_command_tab/command_line.py +187 -0
- agent_command_tab/context_window_usage.py +230 -0
- agent_command_tab/dashboard_core_api.py +57 -0
- agent_command_tab/docked_window_frames_store.py +60 -0
- agent_command_tab/global_shortcut_key_filter.py +167 -0
- agent_command_tab/hook_event_forwarder.py +116 -0
- agent_command_tab/hook_event_tracking.py +129 -0
- agent_command_tab/hook_states_store.py +60 -0
- agent_command_tab/hooks_installer.py +300 -0
- agent_command_tab/installed_copy_paths.py +41 -0
- agent_command_tab/iterm2_actions.py +325 -0
- agent_command_tab/iterm2_connection_thread.py +2299 -0
- agent_command_tab/iterm2_snapshot_builder.py +403 -0
- agent_command_tab/list_sorting.py +117 -0
- agent_command_tab/messages_between_agent_sessions.py +78 -0
- agent_command_tab/monitor_assignment.py +109 -0
- agent_command_tab/pause_records_store.py +61 -0
- agent_command_tab/screen_readings.py +108 -0
- agent_command_tab/session_preview_computation.py +228 -0
- agent_command_tab/session_status_computation.py +235 -0
- agent_command_tab/settings_store.py +292 -0
- agent_command_tab/snapshot_data_classes.py +145 -0
- agent_command_tab/start_with_iterm2.py +138 -0
- agent_command_tab/tab_order_computation.py +26 -0
- agent_command_tab/user_interface/__init__.py +1 -0
- agent_command_tab/user_interface/agent_session_outline_view.py +2120 -0
- agent_command_tab/user_interface/agent_tool_icons.py +124 -0
- agent_command_tab/user_interface/app_icon.py +75 -0
- agent_command_tab/user_interface/control_helpers.py +38 -0
- agent_command_tab/user_interface/list_window.py +116 -0
- agent_command_tab/user_interface/menu_bar_status_item.py +193 -0
- agent_command_tab/user_interface/named_colors.py +58 -0
- agent_command_tab/user_interface/pointing_hand_button.py +42 -0
- agent_command_tab/user_interface/popover_container.py +461 -0
- agent_command_tab/user_interface/row_text_rendering.py +342 -0
- agent_command_tab/user_interface/screen_layout.py +91 -0
- agent_command_tab/user_interface/settings_window.py +530 -0
- agent_command_tab/user_interface/sidebar_panel.py +486 -0
- agent_command_tab/user_interface/sidebar_placement.py +105 -0
- agent_command_tab/user_interface/talk_to_each_other_alert.py +130 -0
- agent_command_tab/window_list_ordering.py +44 -0
- agent_command_tab-0.1.0.dist-info/METADATA +85 -0
- agent_command_tab-0.1.0.dist-info/RECORD +57 -0
- agent_command_tab-0.1.0.dist-info/WHEEL +5 -0
- agent_command_tab-0.1.0.dist-info/entry_points.txt +2 -0
- agent_command_tab-0.1.0.dist-info/licenses/LICENSE +21 -0
- agent_command_tab-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
"""The panel around the list: the sort order, Hide Idle and expand or collapse all at the top, then the column titles; Settings at the bottom left, then a note while the app's hooks are missing, and pause or resume all at the bottom right.
|
|
2
|
+
|
|
3
|
+
The same panel class is used in the dropdown (an NSPopover under the menu bar item), in the
|
|
4
|
+
sidebar and in the list window, each with its own list controller.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import math
|
|
8
|
+
|
|
9
|
+
import objc
|
|
10
|
+
from AppKit import (NSBezelStyleRecessed, NSColor, NSControlSizeSmall, NSEdgeInsetsMake, NSEvent, NSFont, NSFontWeightRegular,
|
|
11
|
+
NSImage, NSImageLeading, NSImageSymbolConfiguration,
|
|
12
|
+
NSLineBreakByTruncatingTail, NSMakeRect, NSPopover, NSPopoverBehaviorTransient, NSPopUpButton, NSRectFill, NSScreen,
|
|
13
|
+
NSScrollView, NSTextField, NSView, NSViewController, NSViewHeightSizable, NSViewMaxXMargin, NSViewMaxYMargin,
|
|
14
|
+
NSViewMinXMargin, NSViewMinYMargin, NSViewWidthSizable)
|
|
15
|
+
|
|
16
|
+
from agent_command_tab.hooks_installer import HOOKS_ARE_MISSING, HOOKS_AWAIT_APPROVAL
|
|
17
|
+
from agent_command_tab.session_status_computation import split_agent_sessions_into_pausable_and_resumable
|
|
18
|
+
from agent_command_tab.user_interface.control_helpers import (ROWS_OPEN_SYMBOL_NAMES, add_popup_choices,
|
|
19
|
+
read_popup_choice, select_popup_choice,
|
|
20
|
+
show_symbol_on_button)
|
|
21
|
+
from agent_command_tab.user_interface.named_colors import appearance_is_dark
|
|
22
|
+
from agent_command_tab.user_interface.pointing_hand_button import PointingHandButton
|
|
23
|
+
|
|
24
|
+
# The Sort pop-up's titles for settings_store.LIST_SORT_ORDERS.
|
|
25
|
+
LIST_SORT_ORDER_TITLES = {"manual": "Manual", "activity": "Activity", "alphabet": "Alphabetically", "context_percent": "Tokens",
|
|
26
|
+
"created_time": "Created Time", "memory_usage": "Memory Usage",
|
|
27
|
+
"cpu_usage": "CPU Usage", "state_duration": "Status Change"}
|
|
28
|
+
POPOVER_WIDTH = 460 # before the first fit
|
|
29
|
+
SMALLEST_POPOVER_WIDTH = 320
|
|
30
|
+
LARGEST_SHARE_OF_SCREEN_WIDTH = 0.9
|
|
31
|
+
SPACE_FOR_SCROLLER_AND_MARGINS = 24
|
|
32
|
+
# Its controls sit 3 points above its bottom; the 3 points more than the 26 it had put about as
|
|
33
|
+
# much room above them as below them, down to the column titles (user request, 2026-10-27).
|
|
34
|
+
TOP_BAR_HEIGHT = 29
|
|
35
|
+
BOTTOM_BAR_HEIGHT = 28
|
|
36
|
+
SMALLEST_LIST_HEIGHT = 60
|
|
37
|
+
LIST_BOTTOM_PADDING = 6
|
|
38
|
+
SPACE_FOR_POPOVER_ARROW_AND_MARGIN = 40
|
|
39
|
+
INITIAL_PANEL_HEIGHT = 300
|
|
40
|
+
TOP_BAR_DRAG_DISTANCE_TO_DETACH = 6 # points: a shorter drag is a click
|
|
41
|
+
PANEL_SIDE_MARGIN = 6 # between the panel's edges and the expand or collapse, the Settings and the pause or resume buttons
|
|
42
|
+
EXPAND_OR_COLLAPSE_ALL_BUTTON_SIZE = (24, 22)
|
|
43
|
+
# The top bar's one expand or collapse button (user requests, 2026-10-19): (SF Symbol, text
|
|
44
|
+
# fallback, tooltip), by whether the list is fully expanded. The symbol shows the current state;
|
|
45
|
+
# the fallback text and the tooltip say what a click does.
|
|
46
|
+
EXPAND_OR_COLLAPSE_ALL_LOOKS = {False: (ROWS_OPEN_SYMBOL_NAMES[False], "Expand all", "Expand all"),
|
|
47
|
+
True: (ROWS_OPEN_SYMBOL_NAMES[True], "Collapse all", "Collapse all")}
|
|
48
|
+
# The bottom bar's pause or resume button, at the right (user requests, 2026-10-20 and
|
|
49
|
+
# 2026-10-21): (SF Symbol, text fallback, tooltip), by what a click does: pause the agent
|
|
50
|
+
# sessions that run, or, once all are paused, resume them.
|
|
51
|
+
# The tooltips say how (user request, 2026-10-28; agent_session_pausing).
|
|
52
|
+
PAUSE_OR_RESUME_ALL_LOOKS = {"pause": ("pause.circle", "Pause all", "Pause all agent processes by suspending them (Ctrl+Z, or a STOP signal)"),
|
|
53
|
+
"resume": ("play.circle", "Resume all", "Resume all paused agent processes (fg, then a CONT signal)")}
|
|
54
|
+
# The top bar's Hide Idle / Show Idle button, left of the expand or collapse button (user
|
|
55
|
+
# requests, 2026-10-21): (title, tooltip), by whether idle tabs are hidden; the title says what a click does.
|
|
56
|
+
IDLE_TABS_BUTTON_LOOKS = {False: ("Hide Idle", "Hide tabs whose agent is idle"), # the user's wording, 2026-10-28
|
|
57
|
+
True: ("Show Idle", "Show tabs whose agent is idle")}
|
|
58
|
+
GAP_BETWEEN_TOP_BAR_BUTTONS = 4
|
|
59
|
+
SMALLEST_SORT_POPUP_WIDTH = 60 # a few letters of its title and its arrows
|
|
60
|
+
HOOKS_NOTE_TOOL_TIP = ("These hooks provide AgentCommandTab more details about agent status, including whether it "
|
|
61
|
+
"launched background processes, etc.") # the user's wording, 2026-10-28
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def choose_hooks_note(hooks_status_per_agent_tool, listed_agent_tool_names):
|
|
65
|
+
"""Returns (the bottom bar's note about the app's hooks, or "" for none, the agent tools its
|
|
66
|
+
Install Hooks button installs them for) (user request, 2026-10-27). Only tools with a session
|
|
67
|
+
in the list count, so someone who never runs Codex isn't asked to install its hooks.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
hooks_status_per_agent_tool: ComputerSnapshot.hooks_status_per_agent_tool.
|
|
71
|
+
listed_agent_tool_names: The agent tools of the list's sessions.
|
|
72
|
+
"""
|
|
73
|
+
missing_agent_tool_names = [agent_tool_name for agent_tool_name, status in hooks_status_per_agent_tool
|
|
74
|
+
if status == HOOKS_ARE_MISSING and agent_tool_name in listed_agent_tool_names]
|
|
75
|
+
if missing_agent_tool_names:
|
|
76
|
+
# The user's wording, 2026-10-28 ("No hooks for Claude Code" until then).
|
|
77
|
+
return f"{' and '.join(missing_agent_tool_names)} hooks not installed yet", missing_agent_tool_names
|
|
78
|
+
if any(status == HOOKS_AWAIT_APPROVAL and agent_tool_name in listed_agent_tool_names
|
|
79
|
+
for agent_tool_name, status in hooks_status_per_agent_tool):
|
|
80
|
+
return "Approve the Codex hooks: /hooks in Codex", []
|
|
81
|
+
return "", []
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class ListPanelView(NSView):
|
|
85
|
+
"""The panel's root view: tells its controller when its size changes, so the top bar fits,
|
|
86
|
+
and when the top bar's empty space is dragged (the dropdown or the sidebar then turns into
|
|
87
|
+
the list window; user requests, 2026-10-19 and 2026-10-22). The top bar's controls take
|
|
88
|
+
their own clicks."""
|
|
89
|
+
|
|
90
|
+
def acceptsFirstMouse_(self, event):
|
|
91
|
+
return True # the sidebar's top bar drags from the first click, though the dashboard isn't the active app
|
|
92
|
+
|
|
93
|
+
def drawRect_(self, rect):
|
|
94
|
+
# In dark mode, the top bar, the column titles and the bottom bar are on the list's own
|
|
95
|
+
# background (the outline view's default, controlBackgroundColor) rather than the lighter
|
|
96
|
+
# gray of the window, the popover or the sidebar around it; light mode keeps that gray
|
|
97
|
+
# around the list, whose rows are on a very light gray there (user requests, 2026-10-27 and
|
|
98
|
+
# 2026-10-28; named_colors' "list_background"). AppKit redraws views when the mode changes.
|
|
99
|
+
if appearance_is_dark(self.effectiveAppearance()):
|
|
100
|
+
NSColor.controlBackgroundColor().set()
|
|
101
|
+
NSRectFill(rect)
|
|
102
|
+
|
|
103
|
+
def resizeSubviewsWithOldSize_(self, old_size):
|
|
104
|
+
objc.super(ListPanelView, self).resizeSubviewsWithOldSize_(old_size)
|
|
105
|
+
controller = getattr(self, "controller", None)
|
|
106
|
+
if controller is not None:
|
|
107
|
+
controller.fit_top_bar_to_width()
|
|
108
|
+
controller.fit_bottom_bar_to_width()
|
|
109
|
+
|
|
110
|
+
def mouseDown_(self, event):
|
|
111
|
+
point = self.convertPoint_fromView_(event.locationInWindow(), None)
|
|
112
|
+
is_on_the_top_bar = point.y >= self.bounds().size.height - TOP_BAR_HEIGHT
|
|
113
|
+
self.top_bar_drag_start = NSEvent.mouseLocation() if is_on_the_top_bar else None # screen coordinates
|
|
114
|
+
if not is_on_the_top_bar:
|
|
115
|
+
objc.super(ListPanelView, self).mouseDown_(event)
|
|
116
|
+
|
|
117
|
+
def mouseDragged_(self, event):
|
|
118
|
+
start = getattr(self, "top_bar_drag_start", None)
|
|
119
|
+
pointer = NSEvent.mouseLocation()
|
|
120
|
+
if start is not None and math.hypot(pointer.x - start.x, pointer.y - start.y) >= TOP_BAR_DRAG_DISTANCE_TO_DETACH:
|
|
121
|
+
self.top_bar_drag_start = None
|
|
122
|
+
self.controller.list_controller.owner.top_bar_dragged(self.controller, (start.x, start.y))
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class ListPanelController(NSViewController):
|
|
126
|
+
"""Holds a list controller's outline view in a scroll view, with a top and a bottom bar and the
|
|
127
|
+
list controller's row of column titles between the top bar and the list.
|
|
128
|
+
|
|
129
|
+
The owner is the list controller's owner (see AgentSessionListController); the panel also
|
|
130
|
+
calls its open_settings(), list_sort_order_chosen(list_sort_order, list_sort_order_is_reversed)
|
|
131
|
+
(as the list controller does when a column's title is clicked),
|
|
132
|
+
idle_tabs_are_hidden_chosen(idle_tabs_are_hidden),
|
|
133
|
+
top_bar_dragged(list_panel_controller, start_point_on_screen) and
|
|
134
|
+
install_hooks(agent_tool_names) (the bottom bar's Install Hooks button).
|
|
135
|
+
"""
|
|
136
|
+
|
|
137
|
+
def initWithListController_(self, list_controller):
|
|
138
|
+
self = objc.super(ListPanelController, self).initWithNibName_bundle_(None, None)
|
|
139
|
+
if self is None:
|
|
140
|
+
return None
|
|
141
|
+
self.list_controller = list_controller
|
|
142
|
+
return self
|
|
143
|
+
|
|
144
|
+
def loadView(self):
|
|
145
|
+
width, height = POPOVER_WIDTH, INITIAL_PANEL_HEIGHT
|
|
146
|
+
root_view = ListPanelView.alloc().initWithFrame_(NSMakeRect(0, 0, width, height))
|
|
147
|
+
scroll_view = NSScrollView.alloc().initWithFrame_(
|
|
148
|
+
NSMakeRect(0, BOTTOM_BAR_HEIGHT, width, height - TOP_BAR_HEIGHT - BOTTOM_BAR_HEIGHT))
|
|
149
|
+
scroll_view.setDocumentView_(self.list_controller.outline_view)
|
|
150
|
+
self.list_controller.outline_view.sizeLastColumnToFit() # a new column is only 100 points wide
|
|
151
|
+
scroll_view.setHasVerticalScroller_(True)
|
|
152
|
+
scroll_view.setAutohidesScrollers_(True)
|
|
153
|
+
scroll_view.setAutomaticallyAdjustsContentInsets_(False) # no blank band above the first row
|
|
154
|
+
scroll_view.setContentInsets_(NSEdgeInsetsMake(0, 0, 0, 0))
|
|
155
|
+
scroll_view.setDrawsBackground_(False)
|
|
156
|
+
scroll_view.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable)
|
|
157
|
+
root_view.addSubview_(scroll_view)
|
|
158
|
+
# The column titles, between the top bar and the list (user request, 2026-10-26), as tall
|
|
159
|
+
# as their titles need (fit_list_under_column_titles).
|
|
160
|
+
column_titles_row_view = self.list_controller.column_titles_row_view
|
|
161
|
+
column_titles_row_view.setFrame_(NSMakeRect(0, height - TOP_BAR_HEIGHT, width, 0))
|
|
162
|
+
column_titles_row_view.setAutoresizingMask_(NSViewWidthSizable | NSViewMinYMargin)
|
|
163
|
+
root_view.addSubview_(column_titles_row_view)
|
|
164
|
+
self.list_controller.on_column_titles_row_height_changed = self.fit_list_under_column_titles
|
|
165
|
+
|
|
166
|
+
# Top bar (user requests, milestone 2, 2026-10-19 to 2026-10-28): the sort order on the
|
|
167
|
+
# left; at the right, Hide Idle and one button that expands or collapses all; a
|
|
168
|
+
# message line after the sort order. Settings was in its middle from 2026-10-26 to 2026-10-28.
|
|
169
|
+
self.sort_label = NSTextField.labelWithString_("Sort:")
|
|
170
|
+
self.sort_label.setFont_(NSFont.systemFontOfSize_(NSFont.smallSystemFontSize()))
|
|
171
|
+
self.sort_label.sizeToFit()
|
|
172
|
+
self.sort_label.setFrameOrigin_((8, height - TOP_BAR_HEIGHT + 6))
|
|
173
|
+
self.sort_label.setAutoresizingMask_(NSViewMinYMargin)
|
|
174
|
+
root_view.addSubview_(self.sort_label)
|
|
175
|
+
self.list_sort_order_popup = NSPopUpButton.alloc().initWithFrame_pullsDown_(NSMakeRect(0, 0, 90, 20), False)
|
|
176
|
+
# A gray pill like the buttons beside it, and narrower than the standard style (the inline
|
|
177
|
+
# style draws no text in a pop-up).
|
|
178
|
+
self.list_sort_order_popup.setBezelStyle_(NSBezelStyleRecessed)
|
|
179
|
+
self.list_sort_order_popup.setControlSize_(NSControlSizeSmall)
|
|
180
|
+
self.list_sort_order_popup.setFont_(NSFont.systemFontOfSize_(NSFont.smallSystemFontSize()))
|
|
181
|
+
add_popup_choices(self.list_sort_order_popup, LIST_SORT_ORDER_TITLES)
|
|
182
|
+
self.list_sort_order_popup.sizeToFit()
|
|
183
|
+
self.sort_popup_width_for_its_widest_title = self.list_sort_order_popup.frame().size.width
|
|
184
|
+
self.list_sort_order_popup.setTarget_(self)
|
|
185
|
+
self.list_sort_order_popup.setAction_("listSortOrderChosen:")
|
|
186
|
+
self.list_sort_order_popup.setFrameOrigin_((0, height - TOP_BAR_HEIGHT + 3)) # fit_top_bar_to_width sets x
|
|
187
|
+
self.list_sort_order_popup.setAutoresizingMask_(NSViewMinYMargin)
|
|
188
|
+
root_view.addSubview_(self.list_sort_order_popup)
|
|
189
|
+
self.idle_tabs_button = PointingHandButton.alloc().initWithFrame_(NSMakeRect(0, 0, 70, 20))
|
|
190
|
+
self.idle_tabs_button.setBezelStyle_(NSBezelStyleRecessed) # a gray pill like the Sort pop-up's
|
|
191
|
+
self.idle_tabs_button.setShowsBorderOnlyWhileMouseInside_(False)
|
|
192
|
+
self.idle_tabs_button.setControlSize_(NSControlSizeSmall)
|
|
193
|
+
self.idle_tabs_button.setFont_(NSFont.systemFontOfSize_(NSFont.smallSystemFontSize()))
|
|
194
|
+
# As wide as the wider of its two titles, so the top bar doesn't shift when it toggles.
|
|
195
|
+
idle_tabs_button_widths = []
|
|
196
|
+
for title, _ in IDLE_TABS_BUTTON_LOOKS.values():
|
|
197
|
+
self.idle_tabs_button.setTitle_(title)
|
|
198
|
+
self.idle_tabs_button.sizeToFit()
|
|
199
|
+
idle_tabs_button_widths.append(self.idle_tabs_button.frame().size.width)
|
|
200
|
+
self.idle_tabs_button.setFrame_(NSMakeRect( # fit_top_bar_to_width sets x
|
|
201
|
+
0, height - TOP_BAR_HEIGHT + 3, max(idle_tabs_button_widths), self.list_sort_order_popup.frame().size.height))
|
|
202
|
+
self.idle_tabs_button.setTarget_(self)
|
|
203
|
+
self.idle_tabs_button.setAction_("idleTabsButtonClicked:")
|
|
204
|
+
self.idle_tabs_button.setAutoresizingMask_(NSViewMinYMargin | NSViewMinXMargin)
|
|
205
|
+
root_view.addSubview_(self.idle_tabs_button)
|
|
206
|
+
self.update_idle_tabs_button()
|
|
207
|
+
button_width, button_height = EXPAND_OR_COLLAPSE_ALL_BUTTON_SIZE
|
|
208
|
+
self.expand_or_collapse_all_button = PointingHandButton.alloc().initWithFrame_(NSMakeRect( # update_top_and_bottom_bar_buttons gives its look
|
|
209
|
+
width - PANEL_SIDE_MARGIN - button_width, height - TOP_BAR_HEIGHT + 3, button_width, button_height))
|
|
210
|
+
self.expand_or_collapse_all_button.setBordered_(False)
|
|
211
|
+
self.expand_or_collapse_all_button.setTarget_(self)
|
|
212
|
+
self.expand_or_collapse_all_button.setAction_("expandOrCollapseAllClicked:")
|
|
213
|
+
self.expand_or_collapse_all_button.setAutoresizingMask_(NSViewMinYMargin | NSViewMinXMargin) # stays at the top right
|
|
214
|
+
root_view.addSubview_(self.expand_or_collapse_all_button)
|
|
215
|
+
self.list_controller.on_snapshot_or_expansion_changed = self.update_top_and_bottom_bar_buttons
|
|
216
|
+
self.message_text_field = NSTextField.labelWithString_("")
|
|
217
|
+
self.message_text_field.setFrame_(NSMakeRect(0, height - TOP_BAR_HEIGHT + 4, 0, 18)) # fit_top_bar_to_width sets x and width
|
|
218
|
+
self.message_text_field.setTextColor_(NSColor.secondaryLabelColor())
|
|
219
|
+
self.message_text_field.setAutoresizingMask_(NSViewMinYMargin)
|
|
220
|
+
root_view.addSubview_(self.message_text_field)
|
|
221
|
+
|
|
222
|
+
# Bottom bar: a Settings button with its name, easier to see than an icon, at the left, a
|
|
223
|
+
# gray pill like the top bar's controls (user request, 2026-10-28; in the middle of the top bar
|
|
224
|
+
# from 2026-10-26, at the bottom left before), and one button that pauses or resumes all, at the
|
|
225
|
+
# right; a new window with an agent session is the "+" row at the end of the list (user
|
|
226
|
+
# requests, 2026-10-19 to 2026-10-21).
|
|
227
|
+
self.settings_button = PointingHandButton.alloc().initWithFrame_(NSMakeRect(0, 0, 80, 20))
|
|
228
|
+
self.settings_button.setTitle_("Settings")
|
|
229
|
+
self.settings_button.setBezelStyle_(NSBezelStyleRecessed)
|
|
230
|
+
self.settings_button.setShowsBorderOnlyWhileMouseInside_(False)
|
|
231
|
+
self.settings_button.setControlSize_(NSControlSizeSmall)
|
|
232
|
+
self.settings_button.setFont_(NSFont.systemFontOfSize_(NSFont.smallSystemFontSize()))
|
|
233
|
+
# A gear before its name (user request, 2026-10-27), as tall as the small text; the name alone where the symbol is missing.
|
|
234
|
+
gear_image = NSImage.imageWithSystemSymbolName_accessibilityDescription_("gearshape", None)
|
|
235
|
+
if gear_image is not None:
|
|
236
|
+
self.settings_button.setImage_(gear_image.imageWithSymbolConfiguration_(
|
|
237
|
+
NSImageSymbolConfiguration.configurationWithPointSize_weight_(NSFont.smallSystemFontSize(), NSFontWeightRegular)))
|
|
238
|
+
self.settings_button.setImagePosition_(NSImageLeading)
|
|
239
|
+
self.settings_button.setTarget_(self)
|
|
240
|
+
self.settings_button.setAction_("settingsClicked:")
|
|
241
|
+
self.settings_button.sizeToFit()
|
|
242
|
+
self.settings_button.setFrameOrigin_((PANEL_SIDE_MARGIN, (BOTTOM_BAR_HEIGHT - self.settings_button.frame().size.height) / 2))
|
|
243
|
+
self.settings_button.setAutoresizingMask_(NSViewMaxYMargin | NSViewMaxXMargin) # stays at the bottom left
|
|
244
|
+
root_view.addSubview_(self.settings_button)
|
|
245
|
+
self.pause_or_resume_all_button = PointingHandButton.alloc().initWithFrame_(NSMakeRect(
|
|
246
|
+
width - PANEL_SIDE_MARGIN - button_width, (BOTTOM_BAR_HEIGHT - button_height) / 2, button_width, button_height))
|
|
247
|
+
self.pause_or_resume_all_button.setBordered_(False)
|
|
248
|
+
self.pause_or_resume_all_button.setTarget_(self)
|
|
249
|
+
self.pause_or_resume_all_button.setAction_("pauseOrResumeAllClicked:")
|
|
250
|
+
self.pause_or_resume_all_button.setAutoresizingMask_(NSViewMaxYMargin | NSViewMinXMargin) # stays at the bottom right
|
|
251
|
+
root_view.addSubview_(self.pause_or_resume_all_button)
|
|
252
|
+
# After the Settings button, while the app's hooks are missing for an agent tool with a session
|
|
253
|
+
# in the list, a note and a button that installs them (user request, 2026-10-27).
|
|
254
|
+
self.hooks_note_text_field = NSTextField.labelWithString_("")
|
|
255
|
+
self.hooks_note_text_field.setFont_(NSFont.systemFontOfSize_(NSFont.smallSystemFontSize()))
|
|
256
|
+
self.hooks_note_text_field.setTextColor_(NSColor.secondaryLabelColor())
|
|
257
|
+
self.hooks_note_text_field.cell().setLineBreakMode_(NSLineBreakByTruncatingTail)
|
|
258
|
+
self.hooks_note_text_field.setToolTip_(HOOKS_NOTE_TOOL_TIP)
|
|
259
|
+
root_view.addSubview_(self.hooks_note_text_field)
|
|
260
|
+
self.install_hooks_button = PointingHandButton.alloc().initWithFrame_(NSMakeRect(0, 0, 80, 20))
|
|
261
|
+
self.install_hooks_button.setTitle_("Install Hooks")
|
|
262
|
+
self.install_hooks_button.setBezelStyle_(NSBezelStyleRecessed) # a gray pill like the top bar's buttons
|
|
263
|
+
self.install_hooks_button.setShowsBorderOnlyWhileMouseInside_(False)
|
|
264
|
+
self.install_hooks_button.setControlSize_(NSControlSizeSmall)
|
|
265
|
+
self.install_hooks_button.setFont_(NSFont.systemFontOfSize_(NSFont.smallSystemFontSize()))
|
|
266
|
+
self.install_hooks_button.sizeToFit()
|
|
267
|
+
self.install_hooks_button.setTarget_(self)
|
|
268
|
+
self.install_hooks_button.setAction_("installHooksClicked:")
|
|
269
|
+
self.install_hooks_button.setToolTip_(HOOKS_NOTE_TOOL_TIP)
|
|
270
|
+
root_view.addSubview_(self.install_hooks_button)
|
|
271
|
+
self.agent_tool_names_to_install_hooks_for = []
|
|
272
|
+
self.setView_(root_view)
|
|
273
|
+
root_view.controller = self
|
|
274
|
+
self.update_top_and_bottom_bar_buttons()
|
|
275
|
+
self.fit_top_bar_to_width()
|
|
276
|
+
self.fit_list_under_column_titles()
|
|
277
|
+
|
|
278
|
+
@objc.python_method
|
|
279
|
+
def fit_list_under_column_titles(self):
|
|
280
|
+
"""Gives the row of column titles the height its titles need (none, hidden, while no
|
|
281
|
+
titled column shows) and the list the room below it."""
|
|
282
|
+
bounds = self.view().bounds()
|
|
283
|
+
column_titles_row_height = self.list_controller.measure_column_titles_row_height()
|
|
284
|
+
list_top = bounds.size.height - TOP_BAR_HEIGHT - column_titles_row_height
|
|
285
|
+
column_titles_row_view = self.list_controller.column_titles_row_view
|
|
286
|
+
column_titles_row_view.setFrame_(NSMakeRect(0, list_top, bounds.size.width, column_titles_row_height))
|
|
287
|
+
column_titles_row_view.setHidden_(not column_titles_row_height) # its titles would show above a 0-high row
|
|
288
|
+
self.list_controller.outline_view.enclosingScrollView().setFrame_(
|
|
289
|
+
NSMakeRect(0, BOTTOM_BAR_HEIGHT, bounds.size.width, list_top - BOTTOM_BAR_HEIGHT))
|
|
290
|
+
|
|
291
|
+
@objc.python_method
|
|
292
|
+
def fit_top_bar_to_width(self):
|
|
293
|
+
"""Puts the expand or collapse all button at the right end and the Hide Idle button just
|
|
294
|
+
left of it (user request, 2026-10-26; in the middle of the bar before). The sort control
|
|
295
|
+
fits between the panel's left edge and those buttons: with its "Sort:" label when there is
|
|
296
|
+
room, without it in a narrower one, and then with the pop-up narrowed, cutting its title
|
|
297
|
+
short, until it hides below SMALLEST_SORT_POPUP_WIDTH (only in a sidebar or a list window,
|
|
298
|
+
where the column titles still sort the list). Where each step happens depends on how wide
|
|
299
|
+
macOS draws the controls: on macOS 27 the label goes below 267 points and the pop-up
|
|
300
|
+
narrows below 235; it would hide below 171, narrower than the sidebar's smallest width
|
|
301
|
+
(200). The message line takes the room left before the buttons, so it never covers them;
|
|
302
|
+
while it shows a message (iTerm2 can't be reached, so there are no rows to sort or hide)
|
|
303
|
+
the sort control and the Hide Idle button step aside for it."""
|
|
304
|
+
label_x, label_width = self.sort_label.frame().origin.x, self.sort_label.frame().size.width
|
|
305
|
+
popup_frame = self.list_sort_order_popup.frame()
|
|
306
|
+
is_showing_a_message = bool(self.message_text_field.stringValue())
|
|
307
|
+
self.idle_tabs_button.setHidden_(is_showing_a_message)
|
|
308
|
+
right_end_x = self.view().bounds().size.width - PANEL_SIDE_MARGIN # then the left end of the leftmost button placed
|
|
309
|
+
gap_before_the_buttons_placed = 0
|
|
310
|
+
for button in (self.expand_or_collapse_all_button, self.idle_tabs_button): # side by side from the right end
|
|
311
|
+
if not button.isHidden():
|
|
312
|
+
right_end_x -= gap_before_the_buttons_placed + button.frame().size.width
|
|
313
|
+
button.setFrameOrigin_((right_end_x, button.frame().origin.y))
|
|
314
|
+
gap_before_the_buttons_placed = GAP_BETWEEN_TOP_BAR_BUTTONS
|
|
315
|
+
room_right_edge = right_end_x - gap_before_the_buttons_placed
|
|
316
|
+
popup_x_after_label = label_x + label_width + 2
|
|
317
|
+
label_fits = not is_showing_a_message and popup_x_after_label + self.sort_popup_width_for_its_widest_title <= room_right_edge
|
|
318
|
+
popup_x = popup_x_after_label if label_fits else label_x
|
|
319
|
+
popup_width = max(min(self.sort_popup_width_for_its_widest_title, room_right_edge - popup_x), 0)
|
|
320
|
+
popup_fits = not is_showing_a_message and popup_width >= SMALLEST_SORT_POPUP_WIDTH
|
|
321
|
+
self.sort_label.setHidden_(not label_fits)
|
|
322
|
+
self.list_sort_order_popup.setHidden_(not popup_fits)
|
|
323
|
+
self.list_sort_order_popup.setFrame_(NSMakeRect(popup_x, popup_frame.origin.y, popup_width, popup_frame.size.height))
|
|
324
|
+
message_x = popup_x + popup_width + 8 if popup_fits else label_x
|
|
325
|
+
message_frame = self.message_text_field.frame()
|
|
326
|
+
self.message_text_field.setFrame_(NSMakeRect(message_x, message_frame.origin.y,
|
|
327
|
+
max(right_end_x - message_x - 8, 0), message_frame.size.height))
|
|
328
|
+
|
|
329
|
+
def expandOrCollapseAllClicked_(self, sender):
|
|
330
|
+
"""Collapses all monitor and window rows when the list is fully expanded, and otherwise
|
|
331
|
+
expands them all (the tabs' previews stay as they are)."""
|
|
332
|
+
self.list_controller.set_all_expanded(not self.list_controller.is_fully_expanded())
|
|
333
|
+
|
|
334
|
+
def pauseOrResumeAllClicked_(self, sender):
|
|
335
|
+
"""Pauses every agent session that runs, or, once all are paused, resumes them all."""
|
|
336
|
+
sessions_to_pause, sessions_to_resume = split_agent_sessions_into_pausable_and_resumable(
|
|
337
|
+
self.list_controller.list_agent_session_entries())
|
|
338
|
+
pause = bool(sessions_to_pause)
|
|
339
|
+
self.list_controller.pause_or_resume_agent_sessions(
|
|
340
|
+
[entry.session_id for entry in (sessions_to_pause if pause else sessions_to_resume)], pause=pause)
|
|
341
|
+
|
|
342
|
+
@objc.python_method
|
|
343
|
+
def update_top_and_bottom_bar_buttons(self):
|
|
344
|
+
"""Gives the expand or collapse button (top bar) and the pause or resume button (bottom
|
|
345
|
+
bar) the look of the list's current state and shows each only when it applies; the top bar
|
|
346
|
+
refits when its button appears or goes. Called after every snapshot and expansion change.
|
|
347
|
+
|
|
348
|
+
The expand or collapse button shows while the list has two or more windows (user request,
|
|
349
|
+
2026-10-19); the pause or resume button while it has an agent session that a click would
|
|
350
|
+
pause or resume."""
|
|
351
|
+
expand_or_collapse_all_button_was_hidden = self.expand_or_collapse_all_button.isHidden()
|
|
352
|
+
symbol_name, fallback_title, tool_tip = EXPAND_OR_COLLAPSE_ALL_LOOKS[self.list_controller.is_fully_expanded()]
|
|
353
|
+
show_symbol_on_button(self.expand_or_collapse_all_button, symbol_name, fallback_title, tool_tip)
|
|
354
|
+
self.expand_or_collapse_all_button.setToolTip_(tool_tip)
|
|
355
|
+
self.expand_or_collapse_all_button.setHidden_(self.list_controller.count_window_rows() < 2)
|
|
356
|
+
sessions_to_pause, sessions_to_resume = split_agent_sessions_into_pausable_and_resumable(
|
|
357
|
+
self.list_controller.list_agent_session_entries())
|
|
358
|
+
symbol_name, fallback_title, tool_tip = PAUSE_OR_RESUME_ALL_LOOKS["pause" if sessions_to_pause else "resume"]
|
|
359
|
+
show_symbol_on_button(self.pause_or_resume_all_button, symbol_name, fallback_title, tool_tip)
|
|
360
|
+
self.pause_or_resume_all_button.setToolTip_(tool_tip)
|
|
361
|
+
self.pause_or_resume_all_button.setHidden_(not (sessions_to_pause or sessions_to_resume))
|
|
362
|
+
if self.expand_or_collapse_all_button.isHidden() != expand_or_collapse_all_button_was_hidden:
|
|
363
|
+
self.fit_top_bar_to_width()
|
|
364
|
+
snapshot = self.list_controller.snapshot
|
|
365
|
+
note, self.agent_tool_names_to_install_hooks_for = choose_hooks_note(
|
|
366
|
+
snapshot.hooks_status_per_agent_tool if snapshot is not None else (),
|
|
367
|
+
{entry.agent_tool_name for entry in self.list_controller.list_agent_session_entries()})
|
|
368
|
+
self.hooks_note_text_field.setStringValue_(note)
|
|
369
|
+
self.fit_bottom_bar_to_width()
|
|
370
|
+
|
|
371
|
+
@objc.python_method
|
|
372
|
+
def fit_bottom_bar_to_width(self):
|
|
373
|
+
"""Puts the hooks note after the Settings button at the bottom left, then its Install Hooks
|
|
374
|
+
button (when there is something to install), the note cut short before the button and the
|
|
375
|
+
pause or resume button."""
|
|
376
|
+
note = self.hooks_note_text_field.stringValue()
|
|
377
|
+
shows_install_button = bool(note and self.agent_tool_names_to_install_hooks_for)
|
|
378
|
+
self.hooks_note_text_field.setHidden_(not note)
|
|
379
|
+
self.install_hooks_button.setHidden_(not shows_install_button)
|
|
380
|
+
if not note:
|
|
381
|
+
return
|
|
382
|
+
right_end_x = (self.pause_or_resume_all_button.frame().origin.x - GAP_BETWEEN_TOP_BAR_BUTTONS
|
|
383
|
+
if not self.pause_or_resume_all_button.isHidden() else self.view().bounds().size.width - PANEL_SIDE_MARGIN)
|
|
384
|
+
button_width, button_height = self.install_hooks_button.frame().size
|
|
385
|
+
if shows_install_button:
|
|
386
|
+
right_end_x -= button_width + GAP_BETWEEN_TOP_BAR_BUTTONS
|
|
387
|
+
note_size = self.hooks_note_text_field.fittingSize()
|
|
388
|
+
settings_button_frame = self.settings_button.frame()
|
|
389
|
+
note_x = settings_button_frame.origin.x + settings_button_frame.size.width + 8
|
|
390
|
+
note_width = max(min(note_size.width, right_end_x - note_x), 0)
|
|
391
|
+
self.hooks_note_text_field.setFrame_(NSMakeRect(note_x, (BOTTOM_BAR_HEIGHT - note_size.height) / 2,
|
|
392
|
+
note_width, note_size.height))
|
|
393
|
+
self.install_hooks_button.setFrameOrigin_((note_x + note_width + GAP_BETWEEN_TOP_BAR_BUTTONS,
|
|
394
|
+
(BOTTOM_BAR_HEIGHT - button_height) / 2))
|
|
395
|
+
|
|
396
|
+
def installHooksClicked_(self, sender):
|
|
397
|
+
self.list_controller.owner.install_hooks(self.agent_tool_names_to_install_hooks_for)
|
|
398
|
+
|
|
399
|
+
def listSortOrderChosen_(self, sender):
|
|
400
|
+
self.list_controller.owner.list_sort_order_chosen(read_popup_choice(sender), False) # in its first direction
|
|
401
|
+
|
|
402
|
+
@objc.python_method
|
|
403
|
+
def show_list_sort_order(self, list_sort_order, is_reversed):
|
|
404
|
+
"""Shows the rows in this order (reversed when is_reversed) and the pop-up with it chosen
|
|
405
|
+
(the dropdown, the sidebar and the list window share one choice)."""
|
|
406
|
+
self.view()
|
|
407
|
+
select_popup_choice(self.list_sort_order_popup, list_sort_order)
|
|
408
|
+
self.list_controller.set_list_sort_order(list_sort_order, is_reversed)
|
|
409
|
+
|
|
410
|
+
def idleTabsButtonClicked_(self, sender):
|
|
411
|
+
self.list_controller.owner.idle_tabs_are_hidden_chosen(not self.list_controller.idle_tabs_are_hidden)
|
|
412
|
+
|
|
413
|
+
@objc.python_method
|
|
414
|
+
def show_idle_tabs_are_hidden(self, idle_tabs_are_hidden):
|
|
415
|
+
"""Hides or shows the idle tabs' rows, and gives the button the title of what a click then
|
|
416
|
+
does (the dropdown, the sidebar and the list window share one choice)."""
|
|
417
|
+
self.view()
|
|
418
|
+
self.list_controller.set_idle_tabs_are_hidden(idle_tabs_are_hidden)
|
|
419
|
+
self.update_idle_tabs_button()
|
|
420
|
+
|
|
421
|
+
@objc.python_method
|
|
422
|
+
def update_idle_tabs_button(self):
|
|
423
|
+
title, tool_tip = IDLE_TABS_BUTTON_LOOKS[self.list_controller.idle_tabs_are_hidden]
|
|
424
|
+
self.idle_tabs_button.setTitle_(title)
|
|
425
|
+
self.idle_tabs_button.setToolTip_(tool_tip)
|
|
426
|
+
|
|
427
|
+
def settingsClicked_(self, sender):
|
|
428
|
+
self.list_controller.owner.open_settings()
|
|
429
|
+
|
|
430
|
+
@objc.python_method
|
|
431
|
+
def show_message(self, message):
|
|
432
|
+
"""Shows one gray line at the top; the app controller uses it when iTerm2 can't be reached."""
|
|
433
|
+
self.view()
|
|
434
|
+
self.message_text_field.setStringValue_(message)
|
|
435
|
+
self.message_text_field.setToolTip_(message)
|
|
436
|
+
self.fit_top_bar_to_width()
|
|
437
|
+
|
|
438
|
+
@objc.python_method
|
|
439
|
+
def fit_size_to_rows(self):
|
|
440
|
+
"""Sizes the panel so every row's text shows in full when all rows are expanded, scrolling
|
|
441
|
+
only when the rows are taller (or wider) than the screen allows. Collapsing or expanding
|
|
442
|
+
rows keeps that size (user request, milestone 2)."""
|
|
443
|
+
window = self.view().window()
|
|
444
|
+
screen = (window.screen() if window is not None else None) or NSScreen.screens()[0]
|
|
445
|
+
usable_frame = screen.visibleFrame()
|
|
446
|
+
bars_height = TOP_BAR_HEIGHT + BOTTOM_BAR_HEIGHT + self.list_controller.measure_column_titles_row_height() # and the column titles
|
|
447
|
+
list_height = self.list_controller.measure_fully_expanded_list_height() # the list has no spacing between rows
|
|
448
|
+
largest_list_height = usable_frame.size.height - bars_height - SPACE_FOR_POPOVER_ARROW_AND_MARGIN
|
|
449
|
+
list_height = min(max(list_height + LIST_BOTTOM_PADDING, SMALLEST_LIST_HEIGHT), largest_list_height)
|
|
450
|
+
width = self.list_controller.measure_widest_row_width() + SPACE_FOR_SCROLLER_AND_MARGINS
|
|
451
|
+
width = min(max(width, SMALLEST_POPOVER_WIDTH), usable_frame.size.width * LARGEST_SHARE_OF_SCREEN_WIDTH)
|
|
452
|
+
self.setPreferredContentSize_((width, list_height + bars_height))
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
def build_dropdown_popover(list_panel_controller):
|
|
456
|
+
"""Returns a transient NSPopover (it closes when you click elsewhere) showing the panel."""
|
|
457
|
+
popover = NSPopover.alloc().init()
|
|
458
|
+
popover.setContentViewController_(list_panel_controller)
|
|
459
|
+
popover.setBehavior_(NSPopoverBehaviorTransient)
|
|
460
|
+
popover.setAnimates_(False)
|
|
461
|
+
return popover
|