feat: AI command prompt adds e(dit) option with keyboard simulation
gates / consistency-and-conventions (push) Successful in 2m11s

- e: xdotool type (X11/Wayland) -> tmux send-keys -> history fallback
- Command appears on active terminal line for editing before Enter
- Y/Enter: execute, n: add to history
This commit is contained in:
Your Name
2026-08-26 03:51:16 -04:00
parent 710b626f47
commit c1f1c4109f
2 changed files with 24 additions and 2 deletions
+1 -1
View File
@@ -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` | 680 | AI assistant: ask, chat, sessions, capture, models, providers |
| `bin/pos-ai` | 702 | 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 |
+23 -1
View File
@@ -376,7 +376,7 @@ _prompt_run_command() {
[ -w /dev/tty ] || return 0
printf '\n%s\n' "Command detected:" >&2
printf ' %s\n\n' "$cmd" >&2
printf 'Run this command? [Y/n] ' >&2
printf 'Run this command? [Y/n/e(dit)] ' >&2
local choice
IFS= read -r choice </dev/tty || choice=""
case "${choice,,}" in
@@ -385,6 +385,9 @@ _prompt_run_command() {
history -s "$cmd" 2>/dev/null || true
printf '%s\n' "Command added to history — press ↑ to recall, edit, and run." >&2
;;
e|E)
_inject_command "$cmd"
;;
*)
# Y or Enter: execute
printf '%s\n' "$cmd"
@@ -393,6 +396,25 @@ _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() {
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
fi
}
# ── Machine context appended to the built-in default prompt ─────
mc_clean() {
sed -e 's/\x1b\[[0-9;]*[A-Za-z]//g' \