From d0299d3f9829a0bee0100ce9a5d4261b3bdd7b01 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 26 Aug 2026 04:13:36 -0400 Subject: [PATCH] feat: AI command edit via clipboard + xdotool fallback - _inject_command tries: xclip/wl-copy (clipboard) -> xdotool (typing) -> tmux -> history - Clipboard is primary: user pastes with Ctrl+Shift+V - preinstall.sh: add xdotool and xclip to PACKAGES --- DOC/AGENT_Context_Project.md | 2 +- bin/pos-ai | 44 ++++++++++++++++++++++++------------ preinstall.sh | 1 + 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/DOC/AGENT_Context_Project.md b/DOC/AGENT_Context_Project.md index 1ad585e..63b23c4 100644 --- a/DOC/AGENT_Context_Project.md +++ b/DOC/AGENT_Context_Project.md @@ -633,7 +633,7 @@ Use conventional prefixes: `feat:`, `fix:`, `docs:`, `refactor:`, `chore:` | `bin/pos-system-health` | 209 | Host health dashboard (disk, RAM, services, backup age, fail2ban, docker); exit 1 if any FAIL | | `bin/pos-system-schedule` | 151 | Scheduled jobs: run a command on a timer; notify on threshold/change/error/always or silently | | `bin/pos-system-uninstall` | 415 | Remove pos toolkit binaries, services, shell integration, config, and data | -| `bin/pos-ai` | 702 | AI assistant: ask, chat, sessions, capture, models, providers | +| `bin/pos-ai` | 716 | AI assistant: ask, chat, sessions, capture, models, providers | | `bin/pos-config` | 80 | Interactive editor for the tools' runtime config (reads # POS_CONFIG: registry) | | `bin/pos-tree` | 112 | Show the pos CLI command tree: categories, commands, and subcommands | | `completions/pos.bash` | 306 | Dynamic bash completion | diff --git a/bin/pos-ai b/bin/pos-ai index 10aedf2..8d91937 100755 --- a/bin/pos-ai +++ b/bin/pos-ai @@ -396,23 +396,37 @@ _prompt_run_command() { esac } -# Simulate keyboard input to paste command onto the active terminal line. -# Tries: xdotool (X11/Wayland) → tmux send-keys → history fallback. +# Inject command for editing: clipboard copy → xdotool typing → tmux → history. +# User pastes with Ctrl+Shift+V (X11) or Ctrl+V (Wayland/SSH). _inject_command() { - local cmd="$1" - if command -v xdotool >/dev/null 2>&1 && [ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}" ]; then - # xdotool: simulate typing into the focused terminal - printf '%s\n' "Typing command — edit if needed, press Enter to run." >&2 - printf '%s' "$cmd" | xdotool type --clearmodifiers --file - - elif [ -n "${TMUX:-}" ]; then - # tmux: send keys directly into the pane - printf '%s\n' "Typing command — edit if needed, press Enter to run." >&2 - tmux send-keys "$cmd" - else - # Fallback: add to history, user presses ↑ to recall - history -s "$cmd" 2>/dev/null || true - printf '%s\n' "Command added to history — press ↑ to recall, edit, and run." >&2 + local cmd="$1" injected="" + # 1. Clipboard (most universal — works over SSH via OSC52 in modern terminals) + if command -v xclip >/dev/null 2>&1 && [ -n "${DISPLAY:-}" ]; then + printf '%s' "$cmd" | xclip -selection clipboard && injected="clipboard" + elif command -v wl-copy >/dev/null 2>&1 && [ -n "${WAYLAND_DISPLAY:-}" ]; then + printf '%s' "$cmd" | wl-copy && injected="clipboard" + elif command -v xsel >/dev/null 2>&1 && [ -n "${DISPLAY:-}" ]; then + printf '%s' "$cmd" | xsel --clipboard --input && injected="clipboard" fi + if [ -n "$injected" ]; then + printf '%s\n' "Command copied to clipboard — paste with Ctrl+Shift+V, edit, Enter to run." >&2 + return 0 + fi + # 2. xdotool: simulate typing into focused terminal + if command -v xdotool >/dev/null 2>&1 && [ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}" ]; then + printf '%s\n' "Typing command — edit if needed, Enter to run." >&2 + printf '%s' "$cmd" | xdotool type --clearmodifiers --file - + return 0 + fi + # 3. tmux: send keys directly into the pane + if [ -n "${TMUX:-}" ]; then + printf '%s\n' "Typing command — edit if needed, Enter to run." >&2 + tmux send-keys "$cmd" + return 0 + fi + # 4. Fallback: add to history, user presses ↑ to recall + history -s "$cmd" 2>/dev/null || true + printf '%s\n' "Command added to history — press ↑ to recall, edit, and run." >&2 } # ── Machine context appended to the built-in default prompt ───── diff --git a/preinstall.sh b/preinstall.sh index 658a3b8..f2655e7 100755 --- a/preinstall.sh +++ b/preinstall.sh @@ -39,6 +39,7 @@ PACKAGES=( python3 python3-pip rclone ffmpeg libqrencode4 libgtk-3-0 adb + xdotool xclip ) spawn "apt update" sudo apt update