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,342 @@
|
|
|
1
|
+
"""The text of each list row, in pyinstrument's style. Pure functions, no AppKit.
|
|
2
|
+
|
|
3
|
+
A row reads left to right: gray tree connectors, a status dot, the name (in the label color,
|
|
4
|
+
bold for window and monitor rows and the tab in front), then the details: a tab row's yellow
|
|
5
|
+
background task lights, a collapsed window row's gray state counts. Colors are names that the
|
|
6
|
+
view maps to system colors.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import collections
|
|
10
|
+
import time
|
|
11
|
+
|
|
12
|
+
from agent_command_tab.context_window_usage import format_token_count
|
|
13
|
+
from agent_command_tab.session_status_computation import pick_most_urgent_state, summarize_state_counts_in_urgency_order
|
|
14
|
+
|
|
15
|
+
RowTextParts = collections.namedtuple(
|
|
16
|
+
"RowTextParts", ["connector_text", "dot_glyph", "dot_color_name", "dot_blinks", "name_text", "details_text",
|
|
17
|
+
"agent_tool_name", "state_text", "elapsed_time_text", "context_text",
|
|
18
|
+
"created_time_text", "existence_duration_text", "memory_text", "cpu_text", "preview_connector_text",
|
|
19
|
+
"preview_text", "details_color_name", "dot_tool_tip", "details_tool_tip",
|
|
20
|
+
"context_fill_percent_color_name", "state_color_name", "state_text_is_semibold"],
|
|
21
|
+
defaults=["", "", "", "", "", "", "", "", "", "", "gray", "", "", "", "", False])
|
|
22
|
+
RowTextParts.__doc__ = ("The pieces of one row; dot_blinks marks a working session's dot. A tab row ends "
|
|
23
|
+
"in columns that line up from row to row (agent_session_outline_view.TAB_ROW_COLUMNS): "
|
|
24
|
+
"context_text (the context's size and its share of the context window, "
|
|
25
|
+
"\"425k (42%)\", the share in parentheses in context_fill_percent_color_name, or in the "
|
|
26
|
+
"column's color for \"\"), created_time_text (when the agent session "
|
|
27
|
+
"started) and existence_duration_text (how long ago), memory_text and cpu_text (what the "
|
|
28
|
+
"agent and the processes it started use), the icon for agent_tool_name, state_text "
|
|
29
|
+
"(in state_color_name, semibold for state_text_is_semibold) and elapsed_time_text (the "
|
|
30
|
+
"state's duration). Under it, a tab "
|
|
31
|
+
"row has a gray preview line: "
|
|
32
|
+
"preview_connector_text continues the tree's lines, and preview_text starts under "
|
|
33
|
+
"the name. A tab row's details are its background task lights, in details_color_name. "
|
|
34
|
+
"dot_tool_tip and details_tool_tip are what the dot and the details mean, shown when the "
|
|
35
|
+
"pointer rests on them, or \"\" for none (user request, 2026-10-27).")
|
|
36
|
+
|
|
37
|
+
# A light per background shell or background agent after a tab's name; more than
|
|
38
|
+
# MOST_BACKGROUND_TASK_LIGHTS show as one light and their number. After the name rather than the
|
|
39
|
+
# dot (as first built), so the names stay lined up from row to row.
|
|
40
|
+
BACKGROUND_TASK_LIGHT = "•"
|
|
41
|
+
BACKGROUND_TASK_LIGHTS_COLOR_NAME = "yellow"
|
|
42
|
+
MOST_BACKGROUND_TASK_LIGHTS = 4
|
|
43
|
+
# A child process's sub row has the light too when the agent left it running in the background,
|
|
44
|
+
# and a gray middle dot otherwise, the same width, so the commands line up.
|
|
45
|
+
CHILD_PROCESS_DOT_GLYPHS_AND_COLORS = {True: (BACKGROUND_TASK_LIGHT, BACKGROUND_TASK_LIGHTS_COLOR_NAME), False: ("·", "gray")}
|
|
46
|
+
CHILD_PROCESS_DOT_TOOL_TIPS = {
|
|
47
|
+
True: "Running in the background: the agent launched this command in the background and went on", # the user's wording, 2026-10-28
|
|
48
|
+
False: "Not a background task: a command from the agent's current turn, or a helper the agent runs for itself", # the user's wording, 2026-10-28
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
# Each state's dot and its color, also the menu bar icon's color for the most urgent state.
|
|
52
|
+
DOT_GLYPH_AND_COLOR_BY_STATE = {
|
|
53
|
+
"asking": ("●", "light_blue"), # also the asking count's color in the menu bar (user request, milestone 2)
|
|
54
|
+
"error": ("✕", "red"),
|
|
55
|
+
"stuck": ("◆", "orange"),
|
|
56
|
+
"working": ("●", "green"),
|
|
57
|
+
"background": ("●", "yellow"), # steady, the color of the background task lights (user request, 2026-10-28)
|
|
58
|
+
"done": ("✔", "green"),
|
|
59
|
+
"idle": ("○", "gray"),
|
|
60
|
+
"paused": ("‖", "purple"),
|
|
61
|
+
"unknown": ("◌", "gray"),
|
|
62
|
+
"exited": ("⊘", "gray"),
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
# The color of each state's text in the Status column: its dot's, but done is gray, in the names'
|
|
66
|
+
# color in dark mode, and unknown is pure black, or pure white in dark mode, so it stands out from
|
|
67
|
+
# done (user requests, 2026-10-28). named_colors' "_text" colors are darker in light mode, so they
|
|
68
|
+
# read on white.
|
|
69
|
+
STATE_TEXT_COLOR_NAME_BY_STATE = {
|
|
70
|
+
"asking": "light_blue_text",
|
|
71
|
+
"error": "red",
|
|
72
|
+
"stuck": "orange_text",
|
|
73
|
+
"working": "green_text", # a tab row's "thinking" and "running"
|
|
74
|
+
"background": "amber", # its "running" in yellow (user request, 2026-10-28), darker in light mode to read on white
|
|
75
|
+
"done": "gray_in_light_mode_only",
|
|
76
|
+
"idle": "light_gray", # a little fainter than gray (user request, 2026-10-28)
|
|
77
|
+
"paused": "purple",
|
|
78
|
+
"unknown": "pure_black_or_white",
|
|
79
|
+
"exited": "gray",
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
# The status text is semibold, easier to read, except idle's, the most common and least telling
|
|
83
|
+
# (user requests, 2026-10-28).
|
|
84
|
+
STATES_WHOSE_TEXT_IS_IN_THE_REGULAR_WEIGHT = frozenset({"idle"})
|
|
85
|
+
|
|
86
|
+
# What each state means, the dot's hover text (user request, 2026-10-27). The 10 and 5 minutes are
|
|
87
|
+
# iterm2_connection_thread's STUCK_THRESHOLD_SECONDS and EXITED_ROW_SECONDS.
|
|
88
|
+
MEANING_BY_STATE = { # asking, idle, paused and exited in the user's wording, 2026-10-28
|
|
89
|
+
"asking": "the agent is waiting for your answer to a question, or for permission to use a tool",
|
|
90
|
+
"error": "the agent reported an error",
|
|
91
|
+
"stuck": "the agent has been thinking for 10 minutes with nothing new on screen and no command running",
|
|
92
|
+
"working": "the agent is thinking or running a command",
|
|
93
|
+
"background": "the agent is at its prompt, and processes it started keep running in the background",
|
|
94
|
+
"done": "the agent is done and you haven't looked at its last message yet", # the user's wording, 2026-10-27
|
|
95
|
+
"idle": "nothing new here since you last looked at this tab",
|
|
96
|
+
# A plain CONT signal would leave it a background job (agent_session_pausing), so Resume types fg.
|
|
97
|
+
"paused": "the agent process has been suspended (Ctrl+Z, or a STOP signal); Resume types fg to continue it",
|
|
98
|
+
"unknown": "the app can't tell what the agent is doing",
|
|
99
|
+
"exited": "this status appears for 5 minutes after an agent exits abnormally (a crash, or killed)",
|
|
100
|
+
}
|
|
101
|
+
# A tab row names a working agent's state for what it does: "running" while it waits on a tool,
|
|
102
|
+
# a command at once and any other tool after 5 seconds, otherwise "thinking" (user requests,
|
|
103
|
+
# 2026-10-28; iterm2_snapshot_builder.choose_tool_the_agent_is_waiting_on). Window rows, whose
|
|
104
|
+
# counts sum up their tabs, still say "working" for both.
|
|
105
|
+
MEANING_BY_WORKING_STATE_NAME = {
|
|
106
|
+
"thinking": "the agent is thinking or briefly running tools", # the user's wording, 2026-10-28
|
|
107
|
+
"running": "the agent is waiting on a tool it started, such as a command, a subagent or a web fetch",
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
# The longest text each column at a tab row's right edge can get, by RowTextParts field (the font
|
|
111
|
+
# is monospaced, so the longest is the widest). The dropdown makes each shown column this wide,
|
|
112
|
+
# so its width stays put as numbers grow ("99k" to "100k", "9m" to "10m") and states change
|
|
113
|
+
# (user request, 2026-10-25).
|
|
114
|
+
LONGEST_TEXT_BY_COLUMN_FIELD_NAME = {
|
|
115
|
+
# format_token_count: "425k", or "1.2M" from 999,500 up; the share is over 100% only for a
|
|
116
|
+
# context larger than the window it is measured against.
|
|
117
|
+
"context_text": "999k (100%)",
|
|
118
|
+
"created_time_text": "12:59 PM", # format_clock_time: "6:08 AM" today, otherwise "Oct 17"
|
|
119
|
+
"existence_duration_text": "23h 59m", # format_elapsed_time
|
|
120
|
+
"memory_text": "1024M", # format_memory_size: "1024M" just under a gigabyte, then "1.4G" up to "99.9G"
|
|
121
|
+
"cpu_text": "100%", # an agent using ten cores or more gets a wider column
|
|
122
|
+
"state_text": "thinking", # the longest state, then running and unknown
|
|
123
|
+
"elapsed_time_text": "23h 59m", # format_elapsed_time
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def build_dot_text(dot_glyph):
|
|
128
|
+
"""Returns the text of a row's dot field: the glyph and a space, or "" for a row without one."""
|
|
129
|
+
return dot_glyph + (" " if dot_glyph else "")
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def format_elapsed_time(elapsed_seconds):
|
|
133
|
+
"""Returns a short elapsed time such as "45s", "3m", "1h 5m" or "2d"."""
|
|
134
|
+
elapsed_seconds = max(int(elapsed_seconds), 0)
|
|
135
|
+
if elapsed_seconds < 60:
|
|
136
|
+
return f"{elapsed_seconds}s"
|
|
137
|
+
if elapsed_seconds < 3600:
|
|
138
|
+
return f"{elapsed_seconds // 60}m"
|
|
139
|
+
if elapsed_seconds < 86400:
|
|
140
|
+
hours, minutes = divmod(elapsed_seconds // 60, 60)
|
|
141
|
+
return f"{hours}h {minutes}m" if minutes else f"{hours}h"
|
|
142
|
+
return f"{elapsed_seconds // 86400}d"
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def format_memory_size(memory_bytes):
|
|
146
|
+
"""Returns a short memory size such as "512M", or "1.4G" from a gigabyte up (powers of 1024, as Activity Monitor shows)."""
|
|
147
|
+
if memory_bytes >= 1024 ** 3:
|
|
148
|
+
return f"{memory_bytes / 1024 ** 3:.1f}G"
|
|
149
|
+
return f"{round(memory_bytes / 1024 ** 2)}M"
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def format_context_text(context_tokens, context_fill_percent):
|
|
153
|
+
"""Returns the Tokens column's text: the context's size and its share of the context window,
|
|
154
|
+
such as "134k (13%)" (user request, 2026-10-26), the size alone while the window's size isn't
|
|
155
|
+
known, or "" while the context's size isn't."""
|
|
156
|
+
if not context_tokens:
|
|
157
|
+
return ""
|
|
158
|
+
if context_fill_percent is None:
|
|
159
|
+
return format_token_count(context_tokens)
|
|
160
|
+
return f"{format_token_count(context_tokens)} ({context_fill_percent}%)"
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def choose_context_fill_percent_color_name(context_fill_percent):
|
|
164
|
+
"""Returns the color of the Tokens column's share of the context window: "amber" from 50%,
|
|
165
|
+
"red" from 75%, or "" below 50% or while the share isn't known, for the column's own color
|
|
166
|
+
(user request, 2026-10-27)."""
|
|
167
|
+
if context_fill_percent is None or context_fill_percent < 50:
|
|
168
|
+
return ""
|
|
169
|
+
return "amber" if context_fill_percent < 75 else "red"
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def format_clock_time(timestamp, now):
|
|
173
|
+
"""Returns a short local time: "6:08 AM" for a time today, otherwise the day, such as "Oct 17"."""
|
|
174
|
+
moment = time.localtime(timestamp)
|
|
175
|
+
if time.localtime(now)[:3] == moment[:3]:
|
|
176
|
+
return time.strftime("%I:%M %p", moment).lstrip("0")
|
|
177
|
+
return time.strftime("%b %d", moment).replace(" 0", " ")
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def build_tree_connector_text(is_last_child_at_each_level):
|
|
181
|
+
"""Returns the gray prefix that draws the tree, for example "│ └─ ".
|
|
182
|
+
|
|
183
|
+
Args:
|
|
184
|
+
is_last_child_at_each_level: For each level below the top, whether the row (last
|
|
185
|
+
element) or its ancestor at that level is its parent's last child. Empty for
|
|
186
|
+
top-level rows, which get no connector.
|
|
187
|
+
"""
|
|
188
|
+
if not is_last_child_at_each_level:
|
|
189
|
+
return ""
|
|
190
|
+
ancestor_parts = [" " if is_last else "│ " for is_last in is_last_child_at_each_level[:-1]]
|
|
191
|
+
return "".join(ancestor_parts) + ("└─ " if is_last_child_at_each_level[-1] else "├─ ")
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def build_tree_continuation_text(is_last_child_at_each_level):
|
|
195
|
+
"""Returns the gray prefix for a second line under a row: the tree's vertical lines carried
|
|
196
|
+
down, for example "│ │ " under "│ ├─ ", and " " under a last child's "└─ "."""
|
|
197
|
+
return "".join(" " if is_last else "│ " for is_last in is_last_child_at_each_level)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def build_background_task_lights_text(background_task_count):
|
|
201
|
+
"""Returns "••" for two background tasks, "•×6" beyond MOST_BACKGROUND_TASK_LIGHTS, "" for none."""
|
|
202
|
+
if background_task_count > MOST_BACKGROUND_TASK_LIGHTS:
|
|
203
|
+
return f"{BACKGROUND_TASK_LIGHT}×{background_task_count}"
|
|
204
|
+
return BACKGROUND_TASK_LIGHT * background_task_count
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def describe_background_task_lights(background_task_count):
|
|
208
|
+
"""Returns the background task lights' hover text, such as "2 background tasks", or "" for none."""
|
|
209
|
+
if not background_task_count:
|
|
210
|
+
return ""
|
|
211
|
+
return "1 background task" if background_task_count == 1 else f"{background_task_count} background tasks"
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def describe_state(state):
|
|
215
|
+
"""Returns a state dot's hover text, such as "Done: the agent is done and you haven't looked at its last message yet"."""
|
|
216
|
+
return f"{state.capitalize()}: {MEANING_BY_STATE[state]}"
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def name_and_describe_tab_rows_state(agent_session_entry, state):
|
|
220
|
+
"""Returns a tab row's state text and its dot's hover text, such as ("running", "Running: the
|
|
221
|
+
agent is waiting on a tool it started, such as a command, a subagent or a web fetch"): a working agent's state is "thinking" or
|
|
222
|
+
"running" (MEANING_BY_WORKING_STATE_NAME), and "background" is "running" too, in yellow (user
|
|
223
|
+
request, 2026-10-28). A state the app doesn't know shows as it came, with the hover text of
|
|
224
|
+
state, "unknown"."""
|
|
225
|
+
if state == "background":
|
|
226
|
+
return "running", f"Running in the background: {MEANING_BY_STATE['background']}"
|
|
227
|
+
if state != "working":
|
|
228
|
+
return agent_session_entry.status, describe_state(state)
|
|
229
|
+
working_state_name = "running" if agent_session_entry.running_tool_name else "thinking"
|
|
230
|
+
return working_state_name, f"{working_state_name.capitalize()}: {MEANING_BY_WORKING_STATE_NAME[working_state_name]}"
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def build_resource_usage_texts(memory_bytes, cpu_percent):
|
|
234
|
+
"""Returns (memory_text, cpu_text) for the Memory and CPU columns, "" while not read."""
|
|
235
|
+
return (format_memory_size(memory_bytes) if memory_bytes is not None else "",
|
|
236
|
+
f"{cpu_percent}%" if cpu_percent is not None else "")
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def build_agent_session_row_text_parts(agent_session_entry, is_last_child_at_each_level, now):
|
|
240
|
+
"""Returns the RowTextParts for a tab row.
|
|
241
|
+
|
|
242
|
+
Args:
|
|
243
|
+
agent_session_entry: An AgentSessionEntry.
|
|
244
|
+
is_last_child_at_each_level: See build_tree_connector_text.
|
|
245
|
+
now: The current time, for the elapsed time since the status changed and since the agent session started.
|
|
246
|
+
"""
|
|
247
|
+
state = agent_session_entry.status if agent_session_entry.status in DOT_GLYPH_AND_COLOR_BY_STATE else "unknown"
|
|
248
|
+
dot_glyph, dot_color_name = DOT_GLYPH_AND_COLOR_BY_STATE[state]
|
|
249
|
+
state_text, dot_tool_tip = name_and_describe_tab_rows_state(agent_session_entry, state)
|
|
250
|
+
started_at = agent_session_entry.started_at
|
|
251
|
+
memory_text, cpu_text = build_resource_usage_texts(agent_session_entry.memory_bytes, agent_session_entry.cpu_percent)
|
|
252
|
+
return RowTextParts(
|
|
253
|
+
connector_text=build_tree_connector_text(is_last_child_at_each_level),
|
|
254
|
+
dot_glyph=dot_glyph,
|
|
255
|
+
dot_color_name=dot_color_name,
|
|
256
|
+
dot_blinks=agent_session_entry.status == "working",
|
|
257
|
+
name_text=agent_session_entry.tab_title,
|
|
258
|
+
details_text=build_background_task_lights_text(agent_session_entry.background_task_count), # the preview has its own line
|
|
259
|
+
details_color_name=BACKGROUND_TASK_LIGHTS_COLOR_NAME,
|
|
260
|
+
dot_tool_tip=dot_tool_tip,
|
|
261
|
+
details_tool_tip=describe_background_task_lights(agent_session_entry.background_task_count),
|
|
262
|
+
agent_tool_name=agent_session_entry.agent_tool_name,
|
|
263
|
+
# While it waits on a tool, a working agent shows "running" and the tool's time.
|
|
264
|
+
state_text=state_text,
|
|
265
|
+
state_color_name=STATE_TEXT_COLOR_NAME_BY_STATE[state],
|
|
266
|
+
state_text_is_semibold=state not in STATES_WHOSE_TEXT_IS_IN_THE_REGULAR_WEIGHT,
|
|
267
|
+
elapsed_time_text=format_elapsed_time(now - (agent_session_entry.running_tool_started_at
|
|
268
|
+
if agent_session_entry.running_tool_name
|
|
269
|
+
else agent_session_entry.status_since)),
|
|
270
|
+
context_text=format_context_text(agent_session_entry.context_tokens, agent_session_entry.context_fill_percent),
|
|
271
|
+
context_fill_percent_color_name=choose_context_fill_percent_color_name(agent_session_entry.context_fill_percent),
|
|
272
|
+
created_time_text=format_clock_time(started_at, now) if started_at is not None else "",
|
|
273
|
+
existence_duration_text=format_elapsed_time(now - started_at) if started_at is not None else "",
|
|
274
|
+
memory_text=memory_text,
|
|
275
|
+
cpu_text=cpu_text,
|
|
276
|
+
preview_connector_text=build_tree_continuation_text(is_last_child_at_each_level),
|
|
277
|
+
preview_text=agent_session_entry.preview_line,
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def build_child_process_row_text_parts(child_process_entry, is_last_child_at_each_level, now):
|
|
282
|
+
"""Returns the RowTextParts for a sub row of an open tab row (user request, 2026-10-27): the
|
|
283
|
+
command the agent started, in gray, and when it started, how long ago, and its memory and CPU
|
|
284
|
+
use in the tab row's columns.
|
|
285
|
+
|
|
286
|
+
Args:
|
|
287
|
+
child_process_entry: A ChildProcessEntry.
|
|
288
|
+
is_last_child_at_each_level: See build_tree_connector_text.
|
|
289
|
+
now: The current time.
|
|
290
|
+
"""
|
|
291
|
+
dot_glyph, dot_color_name = CHILD_PROCESS_DOT_GLYPHS_AND_COLORS[child_process_entry.is_background_shell]
|
|
292
|
+
memory_text, cpu_text = build_resource_usage_texts(child_process_entry.memory_bytes, child_process_entry.cpu_percent)
|
|
293
|
+
return RowTextParts(
|
|
294
|
+
connector_text=build_tree_connector_text(is_last_child_at_each_level),
|
|
295
|
+
dot_glyph=dot_glyph,
|
|
296
|
+
dot_color_name=dot_color_name,
|
|
297
|
+
dot_blinks=False,
|
|
298
|
+
dot_tool_tip=CHILD_PROCESS_DOT_TOOL_TIPS[child_process_entry.is_background_shell],
|
|
299
|
+
name_text=child_process_entry.command_text,
|
|
300
|
+
details_text="",
|
|
301
|
+
created_time_text=format_clock_time(child_process_entry.started_at, now),
|
|
302
|
+
existence_duration_text=format_elapsed_time(now - child_process_entry.started_at),
|
|
303
|
+
memory_text=memory_text,
|
|
304
|
+
cpu_text=cpu_text,
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def build_window_row_text_parts(window_entry, is_last_child_at_each_level, is_expanded):
|
|
309
|
+
"""Returns the RowTextParts for a window row.
|
|
310
|
+
|
|
311
|
+
The dot shows the window's most urgent session state. A collapsed window counts its hidden
|
|
312
|
+
sessions' states ("1 working, 2 idle"); an
|
|
313
|
+
expanded one shows nothing there, since its tab rows show each state (user requests,
|
|
314
|
+
milestone 2).
|
|
315
|
+
"""
|
|
316
|
+
states = [agent_session_entry.status for agent_session_entry in window_entry.agent_sessions]
|
|
317
|
+
most_urgent_state = pick_most_urgent_state(states)
|
|
318
|
+
dot_glyph, dot_color_name = DOT_GLYPH_AND_COLOR_BY_STATE[most_urgent_state]
|
|
319
|
+
details_text = "" if is_expanded else summarize_state_counts_in_urgency_order(states)
|
|
320
|
+
return RowTextParts(
|
|
321
|
+
connector_text=build_tree_connector_text(is_last_child_at_each_level),
|
|
322
|
+
dot_glyph=dot_glyph,
|
|
323
|
+
dot_color_name=dot_color_name,
|
|
324
|
+
dot_blinks=most_urgent_state == "working", # blinks like its working tab's dot
|
|
325
|
+
# Its most urgent tab's state, without "The most urgent status among this window's tabs:" before it (user request, 2026-10-27).
|
|
326
|
+
dot_tool_tip=describe_state(most_urgent_state),
|
|
327
|
+
name_text=window_entry.title,
|
|
328
|
+
details_text=details_text,
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def build_monitor_row_text_parts(monitor_entry):
|
|
333
|
+
"""Returns the RowTextParts for a monitor group row (shown only with two or more monitors)."""
|
|
334
|
+
window_count = len(monitor_entry.windows)
|
|
335
|
+
return RowTextParts(
|
|
336
|
+
connector_text="",
|
|
337
|
+
dot_glyph="",
|
|
338
|
+
dot_color_name="gray",
|
|
339
|
+
dot_blinks=False,
|
|
340
|
+
name_text=monitor_entry.name or "Monitor",
|
|
341
|
+
details_text=f"{window_count} window" + ("" if window_count == 1 else "s"),
|
|
342
|
+
)
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Reads the monitors from AppKit as plain dicts for the core, checks saved
|
|
2
|
+
window frames against them, and saves the frames of the windows that keep one. Main thread only."""
|
|
3
|
+
|
|
4
|
+
import objc
|
|
5
|
+
from AppKit import NSIntersectsRect, NSMakeRect, NSScreen
|
|
6
|
+
from Foundation import NSObject
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def list_screen_frames():
|
|
10
|
+
"""Returns each connected screen's frame as (x, y, width, height)."""
|
|
11
|
+
return [(screen.frame().origin.x, screen.frame().origin.y, screen.frame().size.width, screen.frame().size.height)
|
|
12
|
+
for screen in NSScreen.screens()]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def frame_is_on_a_screen(frame, screen_frames):
|
|
16
|
+
"""Returns whether any part of frame (x, y, width, height) lies on one of the screens, so a
|
|
17
|
+
window saved on a monitor that is gone now opens where it can be seen."""
|
|
18
|
+
return any(NSIntersectsRect(NSMakeRect(*frame), NSMakeRect(*screen_frame)) for screen_frame in screen_frames)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def convert_rect_to_frame_list(rect):
|
|
22
|
+
"""Returns an NSRect as [x, y, width, height], the form window frames are saved in."""
|
|
23
|
+
return [rect.origin.x, rect.origin.y, rect.size.width, rect.size.height]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def grow_frame_to_smallest_size(frame, smallest_size):
|
|
27
|
+
"""Returns frame [x, y, width, height] made at least smallest_size (width, height), keeping
|
|
28
|
+
its top-left corner (y grows upward), so the settings accept it when they are loaded again."""
|
|
29
|
+
x, y, width, height = frame
|
|
30
|
+
new_width, new_height = max(width, smallest_size[0]), max(height, smallest_size[1])
|
|
31
|
+
return [x, y - (new_height - height), new_width, new_height]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def compute_list_window_content_rect_for_a_dragged_sidebar(sidebar_frame, pointer, content_size):
|
|
35
|
+
"""Returns the content rect [x, y, width, height] of the list window that the sidebar turns
|
|
36
|
+
into when its top bar is dragged: content_size, with its top level with the sidebar's top and
|
|
37
|
+
the pointer as far across it, in proportion, as across the sidebar, so the pointer stays on
|
|
38
|
+
the top bar, as far below the top as before.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
sidebar_frame: The sidebar's frame [x, y, width, height] on the screen (y grows upward).
|
|
42
|
+
pointer: Where the drag started (x, y), on the sidebar's top bar.
|
|
43
|
+
content_size: The list window's content size (width, height).
|
|
44
|
+
"""
|
|
45
|
+
sidebar_x, sidebar_y, sidebar_width, sidebar_height = sidebar_frame
|
|
46
|
+
width, height = content_size
|
|
47
|
+
return [pointer[0] - (pointer[0] - sidebar_x) / sidebar_width * width, sidebar_y + sidebar_height - height, width, height]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class WindowFrameSavingController(NSObject):
|
|
51
|
+
"""The base of the controllers of windows whose frame the settings keep (the list window and
|
|
52
|
+
the settings window). As the window's delegate it reports the frame to the owner's
|
|
53
|
+
window_frame_changed(frame_setting_name, frame) after each move and resize; a subclass sets
|
|
54
|
+
frame_setting_name (a settings_store.SMALLEST_WINDOW_SIZES name) and self.owner and self.window."""
|
|
55
|
+
|
|
56
|
+
frame_setting_name = None
|
|
57
|
+
|
|
58
|
+
@objc.python_method
|
|
59
|
+
def report_frame(self):
|
|
60
|
+
self.owner.window_frame_changed(self.frame_setting_name, convert_rect_to_frame_list(self.window.frame()))
|
|
61
|
+
|
|
62
|
+
def windowDidMove_(self, notification):
|
|
63
|
+
self.report_frame()
|
|
64
|
+
|
|
65
|
+
def windowDidEndLiveResize_(self, notification):
|
|
66
|
+
self.report_frame()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def place_window_at_saved_frame_or_center(window, saved_frame):
|
|
70
|
+
"""Puts a window at its saved frame [x, y, width, height] while that is still on a connected
|
|
71
|
+
screen, else in the middle of the main screen."""
|
|
72
|
+
if saved_frame is not None and frame_is_on_a_screen(saved_frame, list_screen_frames()):
|
|
73
|
+
window.setFrame_display_(NSMakeRect(*saved_frame), True)
|
|
74
|
+
else:
|
|
75
|
+
window.center()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def read_monitors_from_screens():
|
|
79
|
+
"""Returns the monitors as plain dicts, menu-bar monitor first (NSScreen's order)."""
|
|
80
|
+
monitors = []
|
|
81
|
+
for screen in NSScreen.screens():
|
|
82
|
+
frame = screen.frame()
|
|
83
|
+
visible_frame = screen.visibleFrame()
|
|
84
|
+
monitors.append({
|
|
85
|
+
"monitor_id": str(screen.deviceDescription()["NSScreenNumber"]),
|
|
86
|
+
"name": screen.localizedName(),
|
|
87
|
+
"frame": (frame.origin.x, frame.origin.y, frame.size.width, frame.size.height),
|
|
88
|
+
"visible_frame": (visible_frame.origin.x, visible_frame.origin.y, visible_frame.size.width,
|
|
89
|
+
visible_frame.size.height),
|
|
90
|
+
})
|
|
91
|
+
return monitors
|