mirror of
https://github.com/bitbaum/dotfiles.git
synced 2026-12-03 19:46:58 +01:00
refactor(hooks): kill dashboard, fix popup focus-steal, add Strategy 0 tab identity
- Delete claude-dashboard.py (superseded by Cockpit web UI) - Remove claude-dashboard alias from .bashrc - claude-popup.py: set WA_ShowWithoutActivating before show() — popup no longer steals keyboard focus from the user's active work - lib.sh: add Strategy 0 to resolve_tab — reads /tmp/claude-tab-$shell_pid written by claude() wrapper at launch; eliminates process-tree walking for tab resolution - .bashrc claude(): write focused tab name to /tmp at launch, clean up on exit Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
d32d68c1f6
commit
9717cf256b
4 files changed
+56
-1227
No files matched your search
@@ -303,9 +303,9 @@ if [ -z "${ZELLIJ:-}" ] && command -v zellij >/dev/null 2>&1; then
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════════════
|
||||
# Claude Code — Session Recovery with Zellij Tab Awareness
|
||||
# Agent + Cockpit helpers with Zellij Tab Awareness
|
||||
# ═══════════════════════════════════════════════════
|
||||
_claude_resolve_project_dir() {
|
||||
_agent_resolve_project_dir() {
|
||||
local CONFIG="$HOME/.config/claude-projects.conf"
|
||||
[ -f "$CONFIG" ] || return 1
|
||||
|
||||
@@ -332,15 +332,20 @@ _claude_resolve_project_dir() {
|
||||
echo "$DIR"
|
||||
}
|
||||
|
||||
claude() {
|
||||
if [ "$PWD" = "$HOME" ] && [ -n "${ZELLIJ:-}" ]; then
|
||||
local PROJECT_DIR
|
||||
PROJECT_DIR=$(_claude_resolve_project_dir)
|
||||
if [ -n "$PROJECT_DIR" ]; then
|
||||
echo " -> Tab -> $PROJECT_DIR"
|
||||
cd "$PROJECT_DIR" || true
|
||||
fi
|
||||
_agent_cd_from_tab_if_home() {
|
||||
[ "$PWD" = "$HOME" ] || return 0
|
||||
[ -n "${ZELLIJ:-}" ] || return 0
|
||||
|
||||
local PROJECT_DIR
|
||||
PROJECT_DIR=$(_agent_resolve_project_dir)
|
||||
if [ -n "$PROJECT_DIR" ]; then
|
||||
echo " -> Tab -> $PROJECT_DIR"
|
||||
cd "$PROJECT_DIR" || return 1
|
||||
fi
|
||||
}
|
||||
|
||||
claude() {
|
||||
_agent_cd_from_tab_if_home || true
|
||||
|
||||
local SESSION_DIR="$HOME/.claude/sessions"
|
||||
mkdir -p "$SESSION_DIR"
|
||||
@@ -374,9 +379,28 @@ claude() {
|
||||
fi
|
||||
|
||||
echo "$PROJECT|$(date +%s)|$(pwd)" > "$SESSION_FILE"
|
||||
|
||||
# Strategy 0 tab identity: write focused tab name to /tmp so hooks can
|
||||
# resolve the tab instantly without process-tree walking (lib.sh Strategy 0).
|
||||
local _tab
|
||||
_tab=$(zellij action dump-layout 2>/dev/null \
|
||||
| grep 'focus=true' | grep 'tab name=' \
|
||||
| sed 's/.*tab name="\([^"]*\)".*/\1/' | head -1)
|
||||
[ -n "$_tab" ] && printf '%s' "$_tab" > "/tmp/claude-tab-$$"
|
||||
|
||||
command claude "$@"
|
||||
rm -f "/tmp/claude-tab-$$"
|
||||
}
|
||||
|
||||
codex() {
|
||||
_agent_cd_from_tab_if_home || true
|
||||
command codex --no-alt-screen "$@"
|
||||
}
|
||||
|
||||
cockpit() {
|
||||
cd "$HOME/dev/cockpit" || return 1
|
||||
npm run dev "$@"
|
||||
}
|
||||
|
||||
# Secrets (passwords, tokens) — loaded from .env, which is gitignored
|
||||
[ -f "$HOME/.env" ] && source "$HOME/.env"
|
||||
alias claude-dashboard='DISPLAY=:0 python3 ~/.claude/hooks/claude-dashboard.py &'
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1003,9 +1003,9 @@ def main():
|
||||
sf = sys.argv[3] if len(sys.argv) > 3 else ""
|
||||
popup = ContinuePopup(mode, label, sf)
|
||||
|
||||
popup.setAttribute(Qt.WidgetAttribute.WA_ShowWithoutActivating, True)
|
||||
popup.show()
|
||||
popup.raise_()
|
||||
popup.activateWindow()
|
||||
app.exec()
|
||||
|
||||
if popup.result:
|
||||
|
||||
+20
-2
@@ -9,6 +9,11 @@ _DBUS="unix:path=/run/user/$(id -u)/bus"
|
||||
# resolve_tab <cwd>
|
||||
# Sets TAB_NAME to the exact Zellij tab name for the calling Claude process.
|
||||
#
|
||||
# Strategy 0 (fastest) — PID file:
|
||||
# The claude() bash wrapper writes /tmp/claude-tab-$$ before exec'ing claude.
|
||||
# Hook reads shell_pid = ps -o ppid= -p $PPID, then cat /tmp/claude-tab-$shell_pid.
|
||||
# Zero process-tree walking. Falls through to Strategy 1 if file is absent.
|
||||
#
|
||||
# Strategy 1 (primary) — CWD-group pane sort:
|
||||
# Walk: hook ($$) → claude ($PPID) → shell (grandparent).
|
||||
# Read ZELLIJ_PANE_ID from the shell's /proc environ.
|
||||
@@ -34,9 +39,22 @@ resolve_tab() {
|
||||
actual_tabs=$(zellij action query-tab-names 2>/dev/null)
|
||||
[ -z "$actual_tabs" ] && return
|
||||
|
||||
# ── Strategy 1: CWD-group pane sort → tab name ──────────────────────────────
|
||||
local shell_pid zellij_pid our_pane_id
|
||||
# ── Strategy 0: PID file written by claude() wrapper at launch time ──────────
|
||||
# The claude() bash function writes /tmp/claude-tab-$$ before exec'ing claude.
|
||||
# $$ in the shell = shell_pid here. This is the cheapest and most reliable path.
|
||||
local shell_pid
|
||||
shell_pid=$(ps -o ppid= -p "$PPID" 2>/dev/null | tr -d ' ')
|
||||
if [ -n "$shell_pid" ] && [ -f "/tmp/claude-tab-${shell_pid}" ]; then
|
||||
local s0_name
|
||||
s0_name=$(cat "/tmp/claude-tab-${shell_pid}" 2>/dev/null)
|
||||
if [ -n "$s0_name" ]; then
|
||||
TAB_NAME="$s0_name"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
# ── Strategy 1: CWD-group pane sort → tab name ──────────────────────────────
|
||||
local zellij_pid our_pane_id
|
||||
if [ -n "$shell_pid" ] && [ -n "$cwd" ]; then
|
||||
zellij_pid=$(ps -o ppid= -p "$shell_pid" 2>/dev/null | tr -d ' ')
|
||||
our_pane_id=$(tr '\0' '\n' < /proc/"$shell_pid"/environ 2>/dev/null \
|
||||
|
||||
Reference in new issue
Block a user