agent-command-tab 0.3.0__tar.gz → 0.4.0__tar.gz
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-0.3.0/src/agent_command_tab.egg-info → agent_command_tab-0.4.0}/PKG-INFO +10 -8
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/README.md +9 -7
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/__init__.py +1 -1
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/agent_adapters/__init__.py +7 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/agent_adapters/base.py +83 -16
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/agent_adapters/claude_code.py +29 -38
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/agent_adapters/codex.py +69 -17
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/agent_input_box_typing.py +61 -18
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/agent_process_tree.py +113 -74
- agent_command_tab-0.4.0/src/agent_command_tab/agent_session_pausing.py +218 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/app_controller.py +220 -119
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/claude_code_transcript_records.py +4 -11
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/command_line.py +16 -16
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/context_window_usage.py +49 -17
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/dashboard_core.py +692 -326
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/dashboard_core_api.py +4 -4
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/docked_window_frames_store.py +9 -12
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/global_shortcut_key_filter.py +2 -3
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/hook_event_forwarder.py +15 -6
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/hook_event_tracking.py +9 -9
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/hook_states_store.py +5 -11
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/hooks_installer.py +63 -45
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/installed_copy_paths.py +3 -5
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/list_sorting.py +9 -11
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/login_shell_environment.py +2 -2
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/messages_between_agent_sessions.py +10 -6
- agent_command_tab-0.4.0/src/agent_command_tab/open_tool_call_reading.py +94 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/pause_records_store.py +12 -17
- agent_command_tab-0.4.0/src/agent_command_tab/saved_agent_sessions_store.py +193 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/screen_readings.py +2 -30
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/session_status_computation.py +45 -78
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/settings_store.py +92 -38
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/snapshot_builder.py +80 -71
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/snapshot_data_classes.py +16 -19
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/start_with_iterm2.py +49 -28
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/terminal_backends/base.py +18 -9
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/terminal_backends/iterm2_terminal_backend.py +18 -59
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/terminal_backends/tmux_terminal_backend.py +33 -47
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/user_interface/agent_session_outline_view.py +358 -432
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/user_interface/agent_tool_icons.py +3 -3
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/user_interface/app_icon.py +1 -1
- agent_command_tab-0.4.0/src/agent_command_tab/user_interface/control_helpers.py +62 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/user_interface/list_window.py +2 -2
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/user_interface/menu_bar_status_item.py +20 -13
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/user_interface/named_colors.py +10 -13
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/user_interface/pointing_hand_button.py +2 -2
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/user_interface/popover_container.py +75 -72
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/user_interface/process_info_alert.py +5 -10
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/user_interface/row_text_rendering.py +44 -60
- agent_command_tab-0.4.0/src/agent_command_tab/user_interface/saved_sessions_window.py +345 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/user_interface/screen_layout.py +20 -3
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/user_interface/settings_window.py +35 -62
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/user_interface/sidebar_panel.py +7 -8
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/user_interface/talk_to_each_other_alert.py +6 -13
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/window_list_ordering.py +2 -5
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0/src/agent_command_tab.egg-info}/PKG-INFO +10 -8
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab.egg-info/SOURCES.txt +3 -1
- agent_command_tab-0.3.0/src/agent_command_tab/agent_session_pausing.py +0 -265
- agent_command_tab-0.3.0/src/agent_command_tab/session_preview_computation.py +0 -228
- agent_command_tab-0.3.0/src/agent_command_tab/user_interface/control_helpers.py +0 -38
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/LICENSE +0 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/pyproject.toml +0 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/setup.cfg +0 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/agent_adapters/generic.py +0 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/monitor_assignment.py +0 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/terminal_backends/__init__.py +0 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/unix_socket_listeners.py +0 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/user_interface/__init__.py +0 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/user_interface/sidebar_placement.py +0 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab.egg-info/dependency_links.txt +0 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab.egg-info/entry_points.txt +0 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab.egg-info/requires.txt +0 -0
- {agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: agent-command-tab
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: macOS menu bar list, window or screen-edge sidebar of the iTerm2 tabs and tmux windows where AI coding agents run
|
|
5
5
|
Author: Ben Weisburd
|
|
6
6
|
License-Expression: MIT
|
|
@@ -29,10 +29,11 @@ A macOS menu bar app that lists the iTerm2 windows and tabs, and the tmux sessio
|
|
|
29
29
|
## What it does
|
|
30
30
|
|
|
31
31
|
- **One tree of your agents:** every iTerm2 window and tmux session with at least one agent tab, with its tabs below it, grouped by monitor when you have several. Tabs without an agent are left out.
|
|
32
|
-
- **What each agent is doing:** a status dot and word per tab (asking a question or for permission, thinking, running a tool,
|
|
33
|
-
- **
|
|
32
|
+
- **What each agent is doing:** a status dot and word per tab (asking a question or for permission, thinking, running a tool, running in the background, done, new, idle, paused, error), the context size in tokens and its share of the context window, and optionally when it started, how long it has run, its memory and CPU use. "Done" stays until you look at the tab, and a Claude Code session is "new" until you send it its first message. The menu bar icon counts the agents waiting for your answer.
|
|
33
|
+
- **Process rows:** a tab whose agent started processes has an arrow that opens a row for each of them (right-click one for Info or Kill). The button at the top right collapses or expands all windows.
|
|
34
34
|
- **Control:** double-click to bring a window or tab to the front; press and hold to peek at a tab; rename in place; drag tabs between windows and windows between monitors; start a new agent window or tab; duplicate a tab; type `/compact` or `/clear` into an agent waiting at its prompt; end an agent's process; pause agents (with every process they started) before going offline and resume them later, per tab, window or monitor from the right-click menu, or for the selected rows with the button at the bottom right. Select several rows (Command-click, Shift-click) to act on all their agents at once (a busy agent gets `/compact` or `/clear` when its turn ends), or to ask them to talk to each other: each gets your note and how to message the others.
|
|
35
|
-
- **
|
|
35
|
+
- **Saved sessions:** save Claude Code and Codex sessions before a reboot, or to come back to them later: right-click a tab row for "Save session", or a window or monitor row, or one of several selected rows, for "Save 3 sessions" (with the number it can save). "Restore sessions…", right below it (grayed out until something is saved) and in the menu bar icon's right-click menu once something is saved, opens the Saved sessions window: the saved sessions under the windows they were saved from, to restore, rename (double-click a name, or select its row and press Return, Command-R or Command-Shift-R) or delete. A restored session continues its conversation (`--resume` for Claude Code, `resume` for Codex, after the launch command in Settings) in its own tab when that tab waits at a shell prompt (iTerm2 brings its tabs back after a reboot; a tmux pane counts while its tmux session runs), else in a new tab beside the others of its window, else in a new window. A name you gave a tab or window goes back to it. A restored session leaves the list once its agent runs in its tab; one that couldn't be restored, or whose agent didn't start within 15 seconds, stays, and an alert says why.
|
|
36
|
+
- **Keyboard:** Return shows the selected tab or window, Delete ends its agent (asking first), R, Command-R or Command-Shift-R renames it, the Right and Left arrows open and close a tab's process rows, Command-E or Command-Shift-E collapses or expands all windows, typing a name's first letters selects its row, Command-comma opens Settings, and Esc closes the list.
|
|
36
37
|
- **Sort and filter:** sort by status, name, share of the context window, start time, memory or CPU use, or keep the tab order; hide the idle tabs with one click or Command-I (new ones stay).
|
|
37
38
|
- **Your choice of view:** a dropdown under the menu bar icon, a sidebar that hides at the screen's edge or stays visible (optionally keeping iTerm2 windows out of its way), or a regular window (optionally always on top).
|
|
38
39
|
- **A shortcut from any app:** Shift-Command-Tab (or Command-Fn-Tab, chosen in Settings) shows the list with the first agent waiting for your answer selected (or, while none is, the tab in front), and hides it when pressed again. While macOS's app switcher is open, the keys still go to it.
|
|
@@ -46,13 +47,14 @@ A macOS menu bar app that lists the iTerm2 windows and tabs, and the tmux sessio
|
|
|
46
47
|
|
|
47
48
|
Agents running inside tmux, in any terminal app, are listed next to iTerm2's. Each tmux session is a window row, labeled "tmux:", and each of its tmux windows a tab row, judged by its first pane (as an iTerm2 tab is). The app reads the default tmux server (the one a plain `tmux` command uses) once a second.
|
|
48
49
|
|
|
49
|
-
Almost everything works as in iTerm2: the states,
|
|
50
|
+
Almost everything works as in iTerm2: the states, process rows, /compact and /clear, Talk to Each Other, rename, new tabs and windows, Duplicate, moving a tab within a session or into another session, and Close. Some differences:
|
|
50
51
|
|
|
51
52
|
- tmux doesn't report agent states, so the app takes Claude Code's own report of each session, and for Codex the turn timer on its screen (a Codex approval request doesn't show as asking). Agent tools other than Claude Code and Codex aren't recognized in tmux.
|
|
52
53
|
- A tmux session has no window of its own, so it is listed with the menu-bar monitor and can't be moved to another monitor, and a tab can't move between iTerm2 and tmux.
|
|
53
54
|
- Showing a tab selects it in tmux and switches an attached client to its session, then brings that client's terminal to the front (its iTerm2 tab, or any other terminal app). With no client attached, the app says how to attach one.
|
|
54
55
|
- The app can't tell which tab of a terminal app other than iTerm2 is in front, so a "done" tab whose tmux client runs there stays "done" until you show it from the list.
|
|
55
|
-
-
|
|
56
|
+
- Agents in tmux can't be paused: tmux restarts a stopped pane's shell at once, which would then take the terminal from the agent.
|
|
57
|
+
- Typing into an agent (/compact, /clear, Talk to Each Other) is refused in a tmux window with `synchronize-panes` on, since the keys would reach its other panes too, and while its pane is in copy mode, which would take the keys.
|
|
56
58
|
|
|
57
59
|
## Install
|
|
58
60
|
|
|
@@ -90,7 +92,7 @@ agent-command-tab --version # prints the installed version, for bug reports
|
|
|
90
92
|
|
|
91
93
|
Click the "C" in the menu bar to see the list, right-click it for Settings. The first time, iTerm2 asks whether to allow the app to use its Python API.
|
|
92
94
|
|
|
93
|
-
From its first start on, iTerm2 starts the app whenever iTerm2 starts: the app adds `AgentCommandTab.scpt` to iTerm2's AutoLaunch folder (`~/Library/Application Support/iTerm2/Scripts/AutoLaunch`), which starts the copy
|
|
95
|
+
From its first start on, iTerm2 starts the app whenever iTerm2 starts: the app adds `AgentCommandTab.scpt` to iTerm2's AutoLaunch folder (`~/Library/Application Support/iTerm2/Scripts/AutoLaunch`), which starts the copy that added it, however you installed it. A script added by another copy is kept while that copy is still installed; once it is uninstalled, the copy you run next adds its own. Started that way, it has iTerm2's permissions, as when you start it from an iTerm2 tab, and writes its output to `~/Library/Logs/agent-command-tab.log`. Turning off Settings > Launch AgentCommandTab whenever iTerm2 is started removes the script. Only one copy runs at a time; starting another prints that one is already running.
|
|
94
96
|
|
|
95
97
|
The app's hooks tell a crashed agent from one that ended normally (its row stays, gray and "exited", for 5 minutes), count Claude Code's background shells and agents, and tell when a Claude Code turn ends while one of those still runs. The list offers to install them (Install Hooks, at its bottom left) while an agent tool in it lacks them. The first time the app changes a settings file, it copies it to `<file>.agent-command-tab-backup`. Sessions started afterwards use them, and Codex asks you to approve them first: type `/hooks` in Codex.
|
|
96
98
|
|
|
@@ -113,7 +115,7 @@ Its settings stay in `~/Library/Application Support/agent-command-tab`, and its
|
|
|
113
115
|
.venv/bin/python -m unittest discover -s tests -p '*_tests.py'
|
|
114
116
|
```
|
|
115
117
|
|
|
116
|
-
[
|
|
118
|
+
[dev/RELEASING.md](https://github.com/bw2/agent-command-tab/blob/main/dev/RELEASING.md) describes how to publish a version.
|
|
117
119
|
|
|
118
120
|
## License
|
|
119
121
|
|
|
@@ -7,10 +7,11 @@ A macOS menu bar app that lists the iTerm2 windows and tabs, and the tmux sessio
|
|
|
7
7
|
## What it does
|
|
8
8
|
|
|
9
9
|
- **One tree of your agents:** every iTerm2 window and tmux session with at least one agent tab, with its tabs below it, grouped by monitor when you have several. Tabs without an agent are left out.
|
|
10
|
-
- **What each agent is doing:** a status dot and word per tab (asking a question or for permission, thinking, running a tool,
|
|
11
|
-
- **
|
|
10
|
+
- **What each agent is doing:** a status dot and word per tab (asking a question or for permission, thinking, running a tool, running in the background, done, new, idle, paused, error), the context size in tokens and its share of the context window, and optionally when it started, how long it has run, its memory and CPU use. "Done" stays until you look at the tab, and a Claude Code session is "new" until you send it its first message. The menu bar icon counts the agents waiting for your answer.
|
|
11
|
+
- **Process rows:** a tab whose agent started processes has an arrow that opens a row for each of them (right-click one for Info or Kill). The button at the top right collapses or expands all windows.
|
|
12
12
|
- **Control:** double-click to bring a window or tab to the front; press and hold to peek at a tab; rename in place; drag tabs between windows and windows between monitors; start a new agent window or tab; duplicate a tab; type `/compact` or `/clear` into an agent waiting at its prompt; end an agent's process; pause agents (with every process they started) before going offline and resume them later, per tab, window or monitor from the right-click menu, or for the selected rows with the button at the bottom right. Select several rows (Command-click, Shift-click) to act on all their agents at once (a busy agent gets `/compact` or `/clear` when its turn ends), or to ask them to talk to each other: each gets your note and how to message the others.
|
|
13
|
-
- **
|
|
13
|
+
- **Saved sessions:** save Claude Code and Codex sessions before a reboot, or to come back to them later: right-click a tab row for "Save session", or a window or monitor row, or one of several selected rows, for "Save 3 sessions" (with the number it can save). "Restore sessions…", right below it (grayed out until something is saved) and in the menu bar icon's right-click menu once something is saved, opens the Saved sessions window: the saved sessions under the windows they were saved from, to restore, rename (double-click a name, or select its row and press Return, Command-R or Command-Shift-R) or delete. A restored session continues its conversation (`--resume` for Claude Code, `resume` for Codex, after the launch command in Settings) in its own tab when that tab waits at a shell prompt (iTerm2 brings its tabs back after a reboot; a tmux pane counts while its tmux session runs), else in a new tab beside the others of its window, else in a new window. A name you gave a tab or window goes back to it. A restored session leaves the list once its agent runs in its tab; one that couldn't be restored, or whose agent didn't start within 15 seconds, stays, and an alert says why.
|
|
14
|
+
- **Keyboard:** Return shows the selected tab or window, Delete ends its agent (asking first), R, Command-R or Command-Shift-R renames it, the Right and Left arrows open and close a tab's process rows, Command-E or Command-Shift-E collapses or expands all windows, typing a name's first letters selects its row, Command-comma opens Settings, and Esc closes the list.
|
|
14
15
|
- **Sort and filter:** sort by status, name, share of the context window, start time, memory or CPU use, or keep the tab order; hide the idle tabs with one click or Command-I (new ones stay).
|
|
15
16
|
- **Your choice of view:** a dropdown under the menu bar icon, a sidebar that hides at the screen's edge or stays visible (optionally keeping iTerm2 windows out of its way), or a regular window (optionally always on top).
|
|
16
17
|
- **A shortcut from any app:** Shift-Command-Tab (or Command-Fn-Tab, chosen in Settings) shows the list with the first agent waiting for your answer selected (or, while none is, the tab in front), and hides it when pressed again. While macOS's app switcher is open, the keys still go to it.
|
|
@@ -24,13 +25,14 @@ A macOS menu bar app that lists the iTerm2 windows and tabs, and the tmux sessio
|
|
|
24
25
|
|
|
25
26
|
Agents running inside tmux, in any terminal app, are listed next to iTerm2's. Each tmux session is a window row, labeled "tmux:", and each of its tmux windows a tab row, judged by its first pane (as an iTerm2 tab is). The app reads the default tmux server (the one a plain `tmux` command uses) once a second.
|
|
26
27
|
|
|
27
|
-
Almost everything works as in iTerm2: the states,
|
|
28
|
+
Almost everything works as in iTerm2: the states, process rows, /compact and /clear, Talk to Each Other, rename, new tabs and windows, Duplicate, moving a tab within a session or into another session, and Close. Some differences:
|
|
28
29
|
|
|
29
30
|
- tmux doesn't report agent states, so the app takes Claude Code's own report of each session, and for Codex the turn timer on its screen (a Codex approval request doesn't show as asking). Agent tools other than Claude Code and Codex aren't recognized in tmux.
|
|
30
31
|
- A tmux session has no window of its own, so it is listed with the menu-bar monitor and can't be moved to another monitor, and a tab can't move between iTerm2 and tmux.
|
|
31
32
|
- Showing a tab selects it in tmux and switches an attached client to its session, then brings that client's terminal to the front (its iTerm2 tab, or any other terminal app). With no client attached, the app says how to attach one.
|
|
32
33
|
- The app can't tell which tab of a terminal app other than iTerm2 is in front, so a "done" tab whose tmux client runs there stays "done" until you show it from the list.
|
|
33
|
-
-
|
|
34
|
+
- Agents in tmux can't be paused: tmux restarts a stopped pane's shell at once, which would then take the terminal from the agent.
|
|
35
|
+
- Typing into an agent (/compact, /clear, Talk to Each Other) is refused in a tmux window with `synchronize-panes` on, since the keys would reach its other panes too, and while its pane is in copy mode, which would take the keys.
|
|
34
36
|
|
|
35
37
|
## Install
|
|
36
38
|
|
|
@@ -68,7 +70,7 @@ agent-command-tab --version # prints the installed version, for bug reports
|
|
|
68
70
|
|
|
69
71
|
Click the "C" in the menu bar to see the list, right-click it for Settings. The first time, iTerm2 asks whether to allow the app to use its Python API.
|
|
70
72
|
|
|
71
|
-
From its first start on, iTerm2 starts the app whenever iTerm2 starts: the app adds `AgentCommandTab.scpt` to iTerm2's AutoLaunch folder (`~/Library/Application Support/iTerm2/Scripts/AutoLaunch`), which starts the copy
|
|
73
|
+
From its first start on, iTerm2 starts the app whenever iTerm2 starts: the app adds `AgentCommandTab.scpt` to iTerm2's AutoLaunch folder (`~/Library/Application Support/iTerm2/Scripts/AutoLaunch`), which starts the copy that added it, however you installed it. A script added by another copy is kept while that copy is still installed; once it is uninstalled, the copy you run next adds its own. Started that way, it has iTerm2's permissions, as when you start it from an iTerm2 tab, and writes its output to `~/Library/Logs/agent-command-tab.log`. Turning off Settings > Launch AgentCommandTab whenever iTerm2 is started removes the script. Only one copy runs at a time; starting another prints that one is already running.
|
|
72
74
|
|
|
73
75
|
The app's hooks tell a crashed agent from one that ended normally (its row stays, gray and "exited", for 5 minutes), count Claude Code's background shells and agents, and tell when a Claude Code turn ends while one of those still runs. The list offers to install them (Install Hooks, at its bottom left) while an agent tool in it lacks them. The first time the app changes a settings file, it copies it to `<file>.agent-command-tab-backup`. Sessions started afterwards use them, and Codex asks you to approve them first: type `/hooks` in Codex.
|
|
74
76
|
|
|
@@ -91,7 +93,7 @@ Its settings stay in `~/Library/Application Support/agent-command-tab`, and its
|
|
|
91
93
|
.venv/bin/python -m unittest discover -s tests -p '*_tests.py'
|
|
92
94
|
```
|
|
93
95
|
|
|
94
|
-
[
|
|
96
|
+
[dev/RELEASING.md](https://github.com/bw2/agent-command-tab/blob/main/dev/RELEASING.md) describes how to publish a version.
|
|
95
97
|
|
|
96
98
|
## License
|
|
97
99
|
|
{agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/agent_adapters/__init__.py
RENAMED
|
@@ -26,6 +26,13 @@ def list_agent_tool_names_whose_sessions_can_talk_to_each_other():
|
|
|
26
26
|
if adapter.how_other_agent_sessions_send_it_messages)
|
|
27
27
|
|
|
28
28
|
|
|
29
|
+
def list_agent_tool_names_whose_conversations_can_be_resumed():
|
|
30
|
+
"""Returns the names of the built-in tools whose sessions Save session can save (can_resume_conversations)."""
|
|
31
|
+
specific_adapters, generic_adapter = build_built_in_agent_tool_adapters()
|
|
32
|
+
return frozenset(adapter.agent_tool_name for adapter in [*specific_adapters, generic_adapter]
|
|
33
|
+
if adapter.can_resume_conversations)
|
|
34
|
+
|
|
35
|
+
|
|
29
36
|
def find_agent_tool_adapter_for_tab(command_line, iterm2_status_value, specific_adapters, generic_adapter):
|
|
30
37
|
"""Returns the adapter for a tab's first pane, or None when the tab runs no agent.
|
|
31
38
|
|
{agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/agent_adapters/base.py
RENAMED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""What every agent tool adapter provides."""
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
|
+
import re
|
|
4
5
|
import shlex
|
|
5
6
|
|
|
6
7
|
SHELL_PROGRAM_NAMES = {"sh", "bash", "zsh", "fish", "dash", "ksh", "tcsh", "csh", "nu", "xonsh", "elvish"}
|
|
@@ -9,11 +10,38 @@ SHELL_PROGRAM_NAMES = {"sh", "bash", "zsh", "fish", "dash", "ksh", "tcsh", "csh"
|
|
|
9
10
|
COMMAND_THAT_STARTS_A_NEW_CONVERSATION = "/clear"
|
|
10
11
|
# The slash commands of Claude Code and Codex alike, in menu order.
|
|
11
12
|
COMPACT_AND_CLEAR_SLASH_COMMANDS = ("/compact", COMMAND_THAT_STARTS_A_NEW_CONVERSATION)
|
|
12
|
-
# How other agent sessions send a tool's sessions messages ("Talk to Each Other"
|
|
13
|
-
#
|
|
13
|
+
# How other agent sessions send a tool's sessions messages ("Talk to Each Other"): Claude Code's SendMessage
|
|
14
|
+
# tool, addressed by the session's name, which only Claude
|
|
14
15
|
# Code sessions have; or `codex queue --thread <conversation ID>`, which any agent with a shell can run.
|
|
15
16
|
MESSAGES_THROUGH_THE_SEND_MESSAGE_TOOL = "send_message_tool"
|
|
16
17
|
MESSAGES_THROUGH_CODEX_QUEUE = "codex_queue"
|
|
18
|
+
# One "NAME=value " word in front of a launch command's program, the value maybe quoted
|
|
19
|
+
# ("ANTHROPIC_MODEL=x CLAUDE_CONFIG_DIR=~/.claude_work claude").
|
|
20
|
+
LEADING_ENVIRONMENT_SETTING_PATTERN = re.compile(r"""([A-Za-z_][A-Za-z0-9_]*)=(?:'[^']*'|"(?:[^"\\]|\\.)*"|\\.|[^\s'"\\])*\s+""")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def remove_environment_settings_from_launch_command(launch_command, variable_name):
|
|
24
|
+
"""Returns the launch command without the <variable_name>=... words in front of its program
|
|
25
|
+
(CLAUDE_CONFIG_DIR, CODEX_HOME), keeping its other environment settings, so a setting put in
|
|
26
|
+
front of it isn't overridden by the launch command's own."""
|
|
27
|
+
kept_settings = []
|
|
28
|
+
rest = launch_command.lstrip()
|
|
29
|
+
while (match := LEADING_ENVIRONMENT_SETTING_PATTERN.match(rest)):
|
|
30
|
+
if match.group(1) != variable_name:
|
|
31
|
+
kept_settings.append(match.group(0))
|
|
32
|
+
rest = rest[match.end():]
|
|
33
|
+
return "".join(kept_settings) + rest
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def split_command_line_into_words(command_line):
|
|
37
|
+
"""Returns the words of a command line (iTerm2's `commandLine` variable for a session, or
|
|
38
|
+
None), possibly none. Unbalanced quotes fall back to splitting on spaces."""
|
|
39
|
+
if not command_line:
|
|
40
|
+
return []
|
|
41
|
+
try:
|
|
42
|
+
return shlex.split(command_line)
|
|
43
|
+
except ValueError:
|
|
44
|
+
return command_line.split()
|
|
17
45
|
|
|
18
46
|
|
|
19
47
|
def split_command_line_into_program_names(command_line):
|
|
@@ -28,13 +56,7 @@ def split_command_line_into_program_names(command_line):
|
|
|
28
56
|
Returns:
|
|
29
57
|
A list of base names, possibly empty.
|
|
30
58
|
"""
|
|
31
|
-
|
|
32
|
-
return []
|
|
33
|
-
try:
|
|
34
|
-
words = shlex.split(command_line)
|
|
35
|
-
except ValueError:
|
|
36
|
-
words = command_line.split()
|
|
37
|
-
return [os.path.basename(word).lstrip("-") for word in words]
|
|
59
|
+
return [os.path.basename(word).lstrip("-") for word in split_command_line_into_words(command_line)]
|
|
38
60
|
|
|
39
61
|
|
|
40
62
|
def command_line_runs_a_shell(command_line):
|
|
@@ -43,6 +65,17 @@ def command_line_runs_a_shell(command_line):
|
|
|
43
65
|
return bool(program_names) and program_names[0] in SHELL_PROGRAM_NAMES
|
|
44
66
|
|
|
45
67
|
|
|
68
|
+
def command_line_is_a_shell_with_no_script_or_command(command_line):
|
|
69
|
+
"""Returns whether the foreground job described by command_line is a shell started with
|
|
70
|
+
nothing to run (`-zsh`, `/bin/bash`, `zsh -l`, `bash --login`), so it waits at its prompt for
|
|
71
|
+
what is typed into it. Unlike command_line_runs_a_shell, not `bash job.sh` or `zsh -c '...'`; a
|
|
72
|
+
script with a `#!/bin/bash` line runs as `/bin/bash ./job.sh`. To be safe, any option other
|
|
73
|
+
than login and interactive (-l, -i, --login, --interactive) counts as running something."""
|
|
74
|
+
return command_line_runs_a_shell(command_line) and all(
|
|
75
|
+
word in ("--login", "--interactive") or re.fullmatch(r"-[il]+", word)
|
|
76
|
+
for word in split_command_line_into_words(command_line)[1:])
|
|
77
|
+
|
|
78
|
+
|
|
46
79
|
class AgentToolAdapter:
|
|
47
80
|
"""Describes one agent tool. Subclasses set the class attributes and may override methods.
|
|
48
81
|
|
|
@@ -50,8 +83,6 @@ class AgentToolAdapter:
|
|
|
50
83
|
agent_tool_name: The name shown in the list, for example "Claude Code".
|
|
51
84
|
permission_dialog_screen_patterns: Compiled patterns that all appear while the tool's
|
|
52
85
|
permission dialog is showing; empty when the tool's own status already covers it.
|
|
53
|
-
progress_noise_patterns: Compiled patterns for screen text that changes every second
|
|
54
|
-
without real progress (screen_readings.compute_screen_fingerprint).
|
|
55
86
|
interrupted_turn_screen_pattern: Compiled pattern for the line the tool prints when a
|
|
56
87
|
permission prompt is denied or the turn is interrupted, or None.
|
|
57
88
|
helper_process_names: Names of processes the tool starts for itself during a turn, which
|
|
@@ -75,11 +106,12 @@ class AgentToolAdapter:
|
|
|
75
106
|
later; None when the tool prints none.
|
|
76
107
|
how_other_agent_sessions_send_it_messages: MESSAGES_THROUGH_THE_SEND_MESSAGE_TOOL,
|
|
77
108
|
MESSAGES_THROUGH_CODEX_QUEUE, or None when other sessions have no way to.
|
|
109
|
+
can_resume_conversations: Whether a saved session of the tool can be resumed later
|
|
110
|
+
(build_launch_command_to_resume; Save session).
|
|
78
111
|
"""
|
|
79
112
|
|
|
80
113
|
agent_tool_name = ""
|
|
81
114
|
permission_dialog_screen_patterns = ()
|
|
82
|
-
progress_noise_patterns = ()
|
|
83
115
|
interrupted_turn_screen_pattern = None
|
|
84
116
|
helper_process_names = frozenset()
|
|
85
117
|
slash_commands = ()
|
|
@@ -90,6 +122,7 @@ class AgentToolAdapter:
|
|
|
90
122
|
queues_slash_commands_typed_during_a_turn = False
|
|
91
123
|
slash_command_refused_during_a_turn_pattern = None
|
|
92
124
|
how_other_agent_sessions_send_it_messages = None
|
|
125
|
+
can_resume_conversations = False
|
|
93
126
|
|
|
94
127
|
async def find_conversation_id(self, agent_process_id, claude_agent_record):
|
|
95
128
|
"""Returns the ID of the conversation the agent process is in, or None if unknown.
|
|
@@ -100,6 +133,11 @@ class AgentToolAdapter:
|
|
|
100
133
|
"""
|
|
101
134
|
return None
|
|
102
135
|
|
|
136
|
+
async def find_conversation_ids_it_may_be_in(self, agent_process_id):
|
|
137
|
+
"""Returns the IDs of the conversations the agent process may be in when find_conversation_id
|
|
138
|
+
can't tell which one it is in: none, unless the tool overrides it."""
|
|
139
|
+
return []
|
|
140
|
+
|
|
103
141
|
async def find_conversation_file(self, agent_process_id, claude_agent_record, claude_config_folders):
|
|
104
142
|
"""Returns the path of the file the tool writes the conversation to, or None if unknown.
|
|
105
143
|
Runs on the core's event loop, so a lookup that reads folders or files does that in a
|
|
@@ -133,12 +171,23 @@ class AgentToolAdapter:
|
|
|
133
171
|
"""Returns when the current turn began, from the conversation file, or None."""
|
|
134
172
|
return None
|
|
135
173
|
|
|
136
|
-
def
|
|
137
|
-
"""Returns the conversation
|
|
138
|
-
|
|
174
|
+
def read_turn_is_under_way(self, conversation_file_path):
|
|
175
|
+
"""Returns whether the conversation file shows a turn under way, or None when it can't
|
|
176
|
+
tell. Called in a worker thread."""
|
|
139
177
|
return None
|
|
140
178
|
|
|
141
|
-
def
|
|
179
|
+
def read_turns_run_outside_the_tab(self, conversation_file_path):
|
|
180
|
+
"""Returns whether the conversation's turns and commands run in a process outside the
|
|
181
|
+
tab (Codex's shared background server), which a pause of the tab's processes can't stop.
|
|
182
|
+
Called in a worker thread."""
|
|
183
|
+
return False
|
|
184
|
+
|
|
185
|
+
def read_open_tool_call(self, conversation_file_path):
|
|
186
|
+
"""Returns the tool call the agent waits on, from the end of the conversation file
|
|
187
|
+
(open_tool_call_reading), or None. Called in a worker thread."""
|
|
188
|
+
return None
|
|
189
|
+
|
|
190
|
+
def build_launch_command_for_a_copy(self, launch_command, conversation_id, claude_agent_record=None, codex_home_folder=None):
|
|
142
191
|
"""Returns the command that starts a copy of a session (Duplicate): one that continues a
|
|
143
192
|
copy of the conversation where the tool can fork it, else a fresh session.
|
|
144
193
|
|
|
@@ -146,9 +195,27 @@ class AgentToolAdapter:
|
|
|
146
195
|
launch_command: The tool's launch command from the settings.
|
|
147
196
|
conversation_id: From find_conversation_id, or None.
|
|
148
197
|
claude_agent_record: The original's record from `claude agents --json`, or None.
|
|
198
|
+
codex_home_folder: For Codex, the original's CODEX_HOME, or None when not known.
|
|
149
199
|
"""
|
|
150
200
|
return launch_command
|
|
151
201
|
|
|
202
|
+
def build_launch_command_to_resume(self, launch_command, conversation_id, claude_config_folder=None, codex_home_folder=None):
|
|
203
|
+
"""Returns the command that resumes a saved conversation (can_resume_conversations only).
|
|
204
|
+
Each tool uses its own folder argument.
|
|
205
|
+
|
|
206
|
+
Args:
|
|
207
|
+
launch_command: The tool's launch command from the settings.
|
|
208
|
+
conversation_id: The saved conversation's ID.
|
|
209
|
+
claude_config_folder: The Claude Code config folder it ran with, or None for the default.
|
|
210
|
+
codex_home_folder: The CODEX_HOME a Codex conversation ran with, or None when not known
|
|
211
|
+
(the launch command's own then applies).
|
|
212
|
+
"""
|
|
213
|
+
raise NotImplementedError
|
|
214
|
+
|
|
215
|
+
def find_codex_home_folder_of_process(self, agent_process_id):
|
|
216
|
+
"""Returns the CODEX_HOME of a Codex process (codex.CodexAdapter's); None for other tools."""
|
|
217
|
+
return None
|
|
218
|
+
|
|
152
219
|
def matches_command_line(self, command_line):
|
|
153
220
|
"""Returns whether a tab whose foreground job has this command line runs this tool.
|
|
154
221
|
|
|
@@ -7,19 +7,17 @@ import re
|
|
|
7
7
|
import shlex
|
|
8
8
|
|
|
9
9
|
from agent_command_tab.agent_adapters.base import (COMPACT_AND_CLEAR_SLASH_COMMANDS, MESSAGES_THROUGH_THE_SEND_MESSAGE_TOOL,
|
|
10
|
-
AgentToolAdapter,
|
|
10
|
+
AgentToolAdapter, remove_environment_settings_from_launch_command,
|
|
11
|
+
split_command_line_into_program_names)
|
|
11
12
|
from agent_command_tab.agent_process_tree import read_process_arguments_and_environment
|
|
12
13
|
from agent_command_tab.context_window_usage import (choose_claude_code_context_window_tokens, find_claude_code_transcript,
|
|
13
14
|
read_claude_code_model_setting,
|
|
14
15
|
read_context_tokens_from_claude_code_transcript,
|
|
15
16
|
read_model_from_claude_code_transcript,
|
|
16
17
|
read_turn_started_at_from_claude_code_transcript)
|
|
17
|
-
from agent_command_tab.
|
|
18
|
+
from agent_command_tab.open_tool_call_reading import read_open_tool_call_from_claude_code_transcript
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
# One "NAME=value " word in front of a launch command's program, the value maybe quoted
|
|
21
|
-
# ("ANTHROPIC_MODEL=x CLAUDE_CONFIG_DIR=~/.claude_work claude").
|
|
22
|
-
LEADING_ENVIRONMENT_SETTING_PATTERN = re.compile(r"""([A-Za-z_][A-Za-z0-9_]*)=(?:'[^']*'|"(?:[^"\\]|\\.)*"|\\.|[^\s'"\\])*\s+""")
|
|
20
|
+
DEFAULT_CLAUDE_CONFIG_FOLDER = os.path.expanduser("~/.claude") # the one a Claude Code without CLAUDE_CONFIG_DIR uses
|
|
23
21
|
|
|
24
22
|
|
|
25
23
|
def list_claude_config_folders():
|
|
@@ -30,22 +28,15 @@ def list_claude_config_folders():
|
|
|
30
28
|
by `claude agents --json`, which lists a session only from its own folder, and by the hooks
|
|
31
29
|
installer, since such a session reads only its own folder's settings.json.
|
|
32
30
|
"""
|
|
33
|
-
default_folder = os.path.expanduser("~/.claude")
|
|
34
31
|
other_folders = ([os.environ["CLAUDE_CONFIG_DIR"]] if os.environ.get("CLAUDE_CONFIG_DIR") else []) + sorted(
|
|
35
32
|
folder for folder in glob.glob(os.path.expanduser("~/.claude*")) if os.path.isdir(os.path.join(folder, "sessions")))
|
|
36
|
-
return [None] + [folder for folder in dict.fromkeys(other_folders)
|
|
33
|
+
return [None] + [folder for folder in dict.fromkeys(other_folders)
|
|
34
|
+
if os.path.realpath(folder) != os.path.realpath(DEFAULT_CLAUDE_CONFIG_FOLDER)]
|
|
37
35
|
|
|
38
36
|
|
|
39
|
-
def
|
|
40
|
-
"""Returns
|
|
41
|
-
|
|
42
|
-
kept_settings = []
|
|
43
|
-
rest = launch_command.lstrip()
|
|
44
|
-
while (match := LEADING_ENVIRONMENT_SETTING_PATTERN.match(rest)):
|
|
45
|
-
if match.group(1) != "CLAUDE_CONFIG_DIR":
|
|
46
|
-
kept_settings.append(match.group(0))
|
|
47
|
-
rest = rest[match.end():]
|
|
48
|
-
return "".join(kept_settings) + rest
|
|
37
|
+
def list_claude_config_folder_paths():
|
|
38
|
+
"""Returns list_claude_config_folders's folders, the default one by its path."""
|
|
39
|
+
return [folder or DEFAULT_CLAUDE_CONFIG_FOLDER for folder in list_claude_config_folders()]
|
|
49
40
|
|
|
50
41
|
|
|
51
42
|
class ClaudeCodeAdapter(AgentToolAdapter):
|
|
@@ -59,21 +50,16 @@ class ClaudeCodeAdapter(AgentToolAdapter):
|
|
|
59
50
|
# "allow Claude to fetch this content?" in 2.1.303) above an "Esc to cancel" hint.
|
|
60
51
|
permission_dialog_screen_patterns = (re.compile(r"Do you want to .+\?"), re.compile(r"Esc to cancel"))
|
|
61
52
|
interrupted_turn_screen_pattern = re.compile(r"Interrupted · What should Claude do instead\?")
|
|
62
|
-
progress_noise_patterns = (
|
|
63
|
-
re.compile(r"^\s*[✳✶✢✻✽✺·*⏺]\s"), # the spinner glyph, and the tool line's blinking bullet
|
|
64
|
-
re.compile(r"\(" + ELAPSED_TIME + r"(?: · [↓↑] [\d.,]+k? tokens)?\)"), # "(5s · ↓ 97 tokens)", "(4s)"
|
|
65
|
-
re.compile(r" · " + ELAPSED_TIME + r"\b"), # the tool line's " · 4s"
|
|
66
|
-
re.compile(r"\(ctrl\+b to run in background\)"),
|
|
67
|
-
)
|
|
68
53
|
helper_process_names = frozenset({"caffeinate"}) # keeps the Mac awake while a turn runs
|
|
69
54
|
slash_commands = COMPACT_AND_CLEAR_SLASH_COMMANDS
|
|
70
|
-
# The input box: "❯" and a no-break space, then the input, between two rules of "─"
|
|
55
|
+
# The input box: "❯" and a no-break space, then the input, between two rules of "─".
|
|
71
56
|
input_line_marker = "❯"
|
|
72
57
|
input_area_end_pattern = re.compile(r"^─{10,}\s*$")
|
|
73
|
-
# Checked live with Claude Code 2.1.307
|
|
58
|
+
# Checked live with Claude Code 2.1.307: /compact and /clear typed during a turn
|
|
74
59
|
# showed under "Press up to edit queued messages" and ran when the turn ended.
|
|
75
60
|
queues_slash_commands_typed_during_a_turn = True
|
|
76
61
|
how_other_agent_sessions_send_it_messages = MESSAGES_THROUGH_THE_SEND_MESSAGE_TOOL
|
|
62
|
+
can_resume_conversations = True
|
|
77
63
|
|
|
78
64
|
def matches_command_line(self, command_line):
|
|
79
65
|
"""Returns whether the command line's program is `claude` (by base name, so full paths match)."""
|
|
@@ -90,7 +76,7 @@ class ClaudeCodeAdapter(AgentToolAdapter):
|
|
|
90
76
|
conversation_id = await self.find_conversation_id(agent_process_id, claude_agent_record)
|
|
91
77
|
if not conversation_id:
|
|
92
78
|
return None
|
|
93
|
-
own_config_folder = (claude_agent_record or {}).get("config_folder") or
|
|
79
|
+
own_config_folder = (claude_agent_record or {}).get("config_folder") or DEFAULT_CLAUDE_CONFIG_FOLDER
|
|
94
80
|
return await asyncio.to_thread(find_claude_code_transcript, [own_config_folder, *claude_config_folders], conversation_id)
|
|
95
81
|
|
|
96
82
|
def read_context_tokens(self, conversation_file_path):
|
|
@@ -98,23 +84,28 @@ class ClaudeCodeAdapter(AgentToolAdapter):
|
|
|
98
84
|
|
|
99
85
|
def read_context_window_tokens(self, conversation_file_path, agent_process_id, claude_agent_record, context_tokens):
|
|
100
86
|
return choose_claude_code_context_window_tokens(read_claude_code_model_setting(
|
|
101
|
-
*read_process_arguments_and_environment(agent_process_id),
|
|
87
|
+
*read_process_arguments_and_environment(agent_process_id),
|
|
88
|
+
(claude_agent_record or {}).get("config_folder") or DEFAULT_CLAUDE_CONFIG_FOLDER),
|
|
102
89
|
read_model_from_claude_code_transcript(conversation_file_path), context_tokens)
|
|
103
90
|
|
|
104
91
|
def read_turn_started_at(self, conversation_file_path):
|
|
105
92
|
return read_turn_started_at_from_claude_code_transcript(conversation_file_path)
|
|
106
93
|
|
|
107
|
-
def
|
|
108
|
-
return
|
|
94
|
+
def read_open_tool_call(self, conversation_file_path):
|
|
95
|
+
return read_open_tool_call_from_claude_code_transcript(conversation_file_path)
|
|
109
96
|
|
|
110
|
-
def build_launch_command_for_a_copy(self, launch_command, conversation_id, claude_agent_record=None):
|
|
97
|
+
def build_launch_command_for_a_copy(self, launch_command, conversation_id, claude_agent_record=None, codex_home_folder=None):
|
|
111
98
|
"""Continues a copy of the conversation under a new session ID (`--resume <id> --fork-session`),
|
|
112
|
-
in the original's config folder (
|
|
113
|
-
CLAUDE_CONFIG_DIR set in front of the launch command gives way to the original's folder,
|
|
114
|
-
or to none for an original in the default folder."""
|
|
99
|
+
in the original's config folder (build_launch_command_to_resume)."""
|
|
115
100
|
if not conversation_id:
|
|
116
101
|
return launch_command
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
102
|
+
return self.build_launch_command_to_resume(launch_command, conversation_id,
|
|
103
|
+
(claude_agent_record or {}).get("config_folder")) + " --fork-session"
|
|
104
|
+
|
|
105
|
+
def build_launch_command_to_resume(self, launch_command, conversation_id, claude_config_folder=None, codex_home_folder=None):
|
|
106
|
+
"""`<launch command> --resume <id>`, in the conversation's config folder (Claude Code finds
|
|
107
|
+
the conversation only there): a CLAUDE_CONFIG_DIR set in front of the launch command gives
|
|
108
|
+
way to that folder, or to none for a conversation in the default folder."""
|
|
109
|
+
environment_prefix = f"CLAUDE_CONFIG_DIR={shlex.quote(claude_config_folder)} " if claude_config_folder else ""
|
|
110
|
+
return (f"{environment_prefix}{remove_environment_settings_from_launch_command(launch_command, 'CLAUDE_CONFIG_DIR')}"
|
|
111
|
+
f" --resume {shlex.quote(conversation_id)}")
|
{agent_command_tab-0.3.0 → agent_command_tab-0.4.0}/src/agent_command_tab/agent_adapters/codex.py
RENAMED
|
@@ -7,14 +7,40 @@ import shlex
|
|
|
7
7
|
import time
|
|
8
8
|
|
|
9
9
|
from agent_command_tab.agent_adapters.base import (COMPACT_AND_CLEAR_SLASH_COMMANDS, MESSAGES_THROUGH_CODEX_QUEUE,
|
|
10
|
-
AgentToolAdapter,
|
|
10
|
+
AgentToolAdapter, remove_environment_settings_from_launch_command,
|
|
11
|
+
split_command_line_into_program_names)
|
|
11
12
|
from agent_command_tab.agent_process_tree import (read_process_arguments_and_environment, read_process_current_folder,
|
|
12
13
|
read_process_info)
|
|
13
|
-
from agent_command_tab.context_window_usage import (
|
|
14
|
+
from agent_command_tab.context_window_usage import (codex_session_header_says_it_runs_in_the_shared_server,
|
|
15
|
+
find_codex_conversation_files, read_codex_session_header,
|
|
14
16
|
read_context_tokens_from_codex_conversation_file,
|
|
15
17
|
read_context_window_tokens_from_codex_conversation_file,
|
|
18
|
+
read_turn_is_under_way_from_codex_conversation_file,
|
|
16
19
|
read_turn_started_at_from_codex_conversation_file)
|
|
17
|
-
from agent_command_tab.
|
|
20
|
+
from agent_command_tab.open_tool_call_reading import read_open_tool_call_from_codex_conversation_file
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
DEFAULT_CODEX_HOME_FOLDER = os.path.expanduser("~/.codex") # the one a Codex without CODEX_HOME uses
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def build_codex_home_setting(codex_home_folder):
|
|
27
|
+
"""Returns "CODEX_HOME=<folder> " to set in front of a command, or "" for None."""
|
|
28
|
+
return f"CODEX_HOME={shlex.quote(codex_home_folder)} " if codex_home_folder else ""
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def set_codex_home_in_front_of_launch_command(launch_command, codex_home_folder):
|
|
32
|
+
"""Returns the launch command run with CODEX_HOME set to codex_home_folder, in place of any it
|
|
33
|
+
sets itself (which would come later, and win); unchanged for None (not known)."""
|
|
34
|
+
if not codex_home_folder:
|
|
35
|
+
return launch_command
|
|
36
|
+
return build_codex_home_setting(codex_home_folder) + remove_environment_settings_from_launch_command(launch_command, "CODEX_HOME")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def find_codex_home_folder(environment=None):
|
|
40
|
+
"""Returns the folder Codex keeps its files in: environment's (by default the app's own)
|
|
41
|
+
CODEX_HOME, or DEFAULT_CODEX_HOME_FOLDER."""
|
|
42
|
+
return os.path.expanduser((os.environ if environment is None else environment).get("CODEX_HOME") or DEFAULT_CODEX_HOME_FOLDER)
|
|
43
|
+
|
|
18
44
|
|
|
19
45
|
# <sessions folder>/2026/10/18/rollout-2026-10-18T15-04-05-<conversation ID>.jsonl
|
|
20
46
|
CONVERSATION_FILE_PATTERN = re.compile(
|
|
@@ -32,20 +58,20 @@ class CodexAdapter(AgentToolAdapter):
|
|
|
32
58
|
"""
|
|
33
59
|
|
|
34
60
|
agent_tool_name = "Codex"
|
|
35
|
-
progress_noise_patterns = (TURN_TIMER_PATTERN,)
|
|
36
61
|
working_screen_pattern = TURN_TIMER_PATTERN
|
|
37
62
|
helper_process_names = frozenset({"codex-code-mode-host"}) # stays running for the whole session
|
|
38
63
|
slash_commands = COMPACT_AND_CLEAR_SLASH_COMMANDS
|
|
39
64
|
# The input box: "›", then the input, above the line with the model and the folder
|
|
40
|
-
# (" GPT-6-Astra low fast · /private/tmp/…"
|
|
65
|
+
# (" GPT-6-Astra low fast · /private/tmp/…").
|
|
41
66
|
input_line_marker = "›"
|
|
42
67
|
input_area_end_pattern = re.compile(r"^ \S[^·]* · [~/…]")
|
|
43
68
|
seconds_before_enter = 0.3 # Codex takes keys within 8 ms of each other as a paste, and Enter for 120 ms after it as a newline
|
|
44
69
|
# Codex 0.155.1 hides its turn timer while answer text streams, so a turn can look over on
|
|
45
70
|
# screen; a /compact typed then is refused with this line and dropped from the box.
|
|
46
71
|
slash_command_refused_during_a_turn_pattern = re.compile(r"'/\w+' is disabled while a task is in progress")
|
|
47
|
-
# `codex queue` reached a busy Codex 0.155.1 session in 0.2 s, which ran the message right after its turn
|
|
72
|
+
# `codex queue` reached a busy Codex 0.155.1 session in 0.2 s, which ran the message right after its turn.
|
|
48
73
|
how_other_agent_sessions_send_it_messages = MESSAGES_THROUGH_CODEX_QUEUE
|
|
74
|
+
can_resume_conversations = True
|
|
49
75
|
|
|
50
76
|
def matches_command_line(self, command_line):
|
|
51
77
|
"""Returns whether the command line runs `codex`, directly or as `node <path>/codex`."""
|
|
@@ -65,6 +91,12 @@ class CodexAdapter(AgentToolAdapter):
|
|
|
65
91
|
conversation_files = await asyncio.to_thread(self.find_conversation_files, agent_process_id)
|
|
66
92
|
return CONVERSATION_FILE_PATTERN.search(conversation_files[0]).group(1) if len(conversation_files) == 1 else None
|
|
67
93
|
|
|
94
|
+
async def find_conversation_ids_it_may_be_in(self, agent_process_id):
|
|
95
|
+
"""Returns the conversation ID of every file that fits the process: after /new, or with a
|
|
96
|
+
later Codex session in its folder, more than one does."""
|
|
97
|
+
conversation_files = await asyncio.to_thread(self.find_conversation_files, agent_process_id)
|
|
98
|
+
return [CONVERSATION_FILE_PATTERN.search(conversation_file).group(1) for conversation_file in conversation_files]
|
|
99
|
+
|
|
68
100
|
async def find_conversation_file(self, agent_process_id, claude_agent_record, claude_config_folders):
|
|
69
101
|
"""Returns the most recently written file that fits (see find_conversation_files)."""
|
|
70
102
|
conversation_files = await asyncio.to_thread(self.find_conversation_files, agent_process_id)
|
|
@@ -72,16 +104,24 @@ class CodexAdapter(AgentToolAdapter):
|
|
|
72
104
|
|
|
73
105
|
def find_conversation_files(self, agent_process_id):
|
|
74
106
|
"""Returns the files that may be the Codex process's conversation, matched by its folder and
|
|
75
|
-
start time in
|
|
76
|
-
Codex 0.163 doesn't keep
|
|
77
|
-
|
|
107
|
+
start time in the sessions folder of its Codex home folder (find_codex_home_folder_of_process),
|
|
108
|
+
newest first (context_window_usage.find_codex_conversation_files; Codex 0.163 doesn't keep
|
|
109
|
+
the file open, so lsof can't find it). A process started with `codex resume` (or `node
|
|
110
|
+
.../codex resume`) may be writing an earlier conversation's file."""
|
|
78
111
|
agent_process = read_process_info(agent_process_id) if agent_process_id else None
|
|
79
112
|
if agent_process is None:
|
|
80
113
|
return []
|
|
81
|
-
codex_home = os.environ.get("CODEX_HOME") or os.path.expanduser("~/.codex")
|
|
82
114
|
return find_codex_conversation_files(
|
|
83
|
-
os.path.join(
|
|
84
|
-
time.time(),
|
|
115
|
+
os.path.join(self.find_codex_home_folder_of_process(agent_process_id), "sessions"), agent_process.started_at,
|
|
116
|
+
read_process_current_folder(agent_process_id), time.time(),
|
|
117
|
+
agent_resumed_a_conversation="resume" in read_process_arguments_and_environment(agent_process_id)[0][1:])
|
|
118
|
+
|
|
119
|
+
def find_codex_home_folder_of_process(self, agent_process_id):
|
|
120
|
+
"""Returns the folder the Codex process keeps its files in: its own environment's
|
|
121
|
+
CODEX_HOME (a launch command may set another than the app's), ~/.codex when it has none,
|
|
122
|
+
or the app's own (find_codex_home_folder) when its environment can't be read."""
|
|
123
|
+
arguments, environment = read_process_arguments_and_environment(agent_process_id)
|
|
124
|
+
return find_codex_home_folder(environment if arguments else None)
|
|
85
125
|
|
|
86
126
|
def read_context_tokens(self, conversation_file_path):
|
|
87
127
|
return read_context_tokens_from_codex_conversation_file(conversation_file_path)
|
|
@@ -92,11 +132,23 @@ class CodexAdapter(AgentToolAdapter):
|
|
|
92
132
|
def read_turn_started_at(self, conversation_file_path):
|
|
93
133
|
return read_turn_started_at_from_codex_conversation_file(conversation_file_path)
|
|
94
134
|
|
|
95
|
-
def
|
|
96
|
-
return
|
|
135
|
+
def read_turn_is_under_way(self, conversation_file_path):
|
|
136
|
+
return read_turn_is_under_way_from_codex_conversation_file(conversation_file_path)
|
|
97
137
|
|
|
98
|
-
def
|
|
99
|
-
|
|
138
|
+
def read_turns_run_outside_the_tab(self, conversation_file_path):
|
|
139
|
+
return codex_session_header_says_it_runs_in_the_shared_server(read_codex_session_header(conversation_file_path))
|
|
140
|
+
|
|
141
|
+
def read_open_tool_call(self, conversation_file_path):
|
|
142
|
+
return read_open_tool_call_from_codex_conversation_file(conversation_file_path)
|
|
143
|
+
|
|
144
|
+
def build_launch_command_for_a_copy(self, launch_command, conversation_id, claude_agent_record=None, codex_home_folder=None):
|
|
145
|
+
"""Continues a copy of the conversation (`codex fork <id>`), with the original's CODEX_HOME
|
|
146
|
+
(build_launch_command_to_resume)."""
|
|
100
147
|
if not conversation_id:
|
|
101
148
|
return launch_command
|
|
102
|
-
return f"{launch_command} fork {shlex.quote(conversation_id)}"
|
|
149
|
+
return f"{set_codex_home_in_front_of_launch_command(launch_command, codex_home_folder)} fork {shlex.quote(conversation_id)}"
|
|
150
|
+
|
|
151
|
+
def build_launch_command_to_resume(self, launch_command, conversation_id, claude_config_folder=None, codex_home_folder=None):
|
|
152
|
+
"""`<launch command> resume <id>`, with CODEX_HOME set to the conversation's home folder
|
|
153
|
+
when it is known (Codex finds the conversation only there), in place of the launch command's own."""
|
|
154
|
+
return f"{set_codex_home_in_front_of_launch_command(launch_command, codex_home_folder)} resume {shlex.quote(conversation_id)}"
|