agent tracker + tmux updates

This commit is contained in:
David Chen 2026-04-09 10:07:43 -07:00
parent ba2c8ef54e
commit 75403c927f
5 changed files with 67 additions and 17 deletions

View file

@ -112,11 +112,11 @@ set -g display-time 2000
# create session
bind C-c new-session
bind O run-shell "~/.config/tmux/scripts/restart_opencode_pane.sh \"#{pane_id}\""
bind -n M-S run-shell "~/.config/tmux/scripts/new_session.sh #{q:session_id}"
bind -n M-S run-shell "~/.config/tmux/scripts/new_session.sh #{q:session_id} #{q:pane_current_path}"
bind -n M-O break-pane
# window management
bind -n M-o new-window -a -c "#{pane_current_path}"
bind -n M-o run-shell "~/.config/tmux/scripts/open_shell_here.sh new-window '#{window_id}' '#{pane_current_path}' -a"
bind -n M-Q kill-pane
bind . command-prompt -p "Rename session to:" "run-shell \"~/.config/tmux/scripts/rename_session_prompt.sh '%%'\""
unbind ,
@ -159,10 +159,10 @@ bind -n M-& join-pane -t :7
bind -n M-* join-pane -t :8
bind -n M-( join-pane -t :9
bind u split-window -vb -c "#{pane_current_path}"
bind e split-window -v -c "#{pane_current_path}"
bind n split-window -hb -c "#{pane_current_path}"
bind i split-window -h -c "#{pane_current_path}"
bind u run-shell "~/.config/tmux/scripts/open_shell_here.sh split '#{pane_id}' '#{pane_current_path}' -v -b"
bind e run-shell "~/.config/tmux/scripts/open_shell_here.sh split '#{pane_id}' '#{pane_current_path}' -v"
bind n run-shell "~/.config/tmux/scripts/open_shell_here.sh split '#{pane_id}' '#{pane_current_path}' -h -b"
bind i run-shell "~/.config/tmux/scripts/open_shell_here.sh split '#{pane_id}' '#{pane_current_path}' -h"
bind -n M-f resize-pane -Z

View file

@ -15,14 +15,14 @@
"help": "?",
"focus_ai": "M-a",
"focus_git": "M-g",
"focus_dashboard": "M-s",
"focus_run": "M-r"
},
"devices": [
"web-server",
"ipm",
"opm",
"macos"
"macos",
"ipp"
],
"status_right": {
"cpu": false,

View file

@ -1339,15 +1339,24 @@ func activeAgentWindowID(record *agentRecord) string {
return windowID
}
func launchAgentLayout(record *agentRecord) error {
func launchAgentLayout(record *agentRecord) (err error) {
previousWindowID := currentTmuxWindowID()
cleanupWindow := false
windowID := ""
windowID, sessionID, sessionName, attachAfter, err := createWindow(record.Name, record.RepoCopyPath, record.LaunchWindowID)
if err != nil {
return err
}
if err := runTmux("select-window", "-t", windowID); err != nil {
return err
}
cleanupWindow = true
defer func() {
if err == nil || !cleanupWindow || strings.TrimSpace(windowID) == "" {
return
}
_ = runTmux("kill-window", "-t", windowID)
if strings.TrimSpace(previousWindowID) != "" {
_ = runTmux("select-window", "-t", previousWindowID)
}
}()
topPane, err := currentPane(windowID)
if err != nil {
return err
@ -1400,12 +1409,20 @@ func launchAgentLayout(record *agentRecord) error {
return err
}
}
if attachAfter && canAttachTmux() {
if err := runTmux("attach-session", "-t", sessionID); err != nil {
return err
}
cleanupWindow = false
return nil
}
if err := runTmux("select-window", "-t", windowID); err != nil {
return err
}
if err := runTmux("select-pane", "-t", aiPane); err != nil {
return err
}
if attachAfter && canAttachTmux() {
return runTmux("attach-session", "-t", sessionID)
}
cleanupWindow = false
return nil
}

View file

@ -2,9 +2,16 @@
LOCK="/tmp/tmux-new-session.lock"
current_session_id="${1:-}"
current_path="${2:-}"
touch "$LOCK"
session_id=$(tmux new-session -d -P -s 'session' -F '#{session_id}' 2>/dev/null)
tmux_args=(new-session -d -P -s 'session' -F '#{session_id}')
if [ -n "$current_path" ]; then
tmux_args+=( -c "$current_path" )
printf -v start_cmd 'cd %q && exec ${SHELL:-/bin/zsh} -l' "$current_path"
tmux_args+=( "$start_cmd" )
fi
session_id=$(tmux "${tmux_args[@]}" 2>/dev/null)
if [ -z "$session_id" ]; then
rm -f "$LOCK"

26
tmux/scripts/open_shell_here.sh Executable file
View file

@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -euo pipefail
mode="${1:-}"
target="${2:-}"
target_path="${3:-}"
shift 3 || true
if [[ -z "$target_path" || ! -d "$target_path" ]]; then
target_path="$HOME"
fi
printf -v start_cmd 'cd %q && exec ${SHELL:-/bin/zsh} -l' "$target_path"
case "$mode" in
split)
exec tmux split-window "$@" -t "$target" -c "$target_path" "$start_cmd"
;;
new-window)
exec tmux new-window "$@" -t "$target" -c "$target_path" "$start_cmd"
;;
*)
printf 'open_shell_here: unknown mode %s\n' "$mode" >&2
exit 1
;;
esac