Created
March 9, 2026 22:36
-
-
Save Timtech4u/bec3b9509abcdd8102bd72fe9267f4e0 to your computer and use it in GitHub Desktop.
acpx-chat: Interactive chat REPL for ACPX persistent sessions (Agent Client Protocol)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # acpx-chat: Interactive chat REPL for ACPX persistent sessions | |
| # Usage: acpx-chat [agent] [session-name] | |
| # agent: codex (default), claude, gemini, opencode, pi, kimi | |
| # session-name: name for persistent session (default: chat) | |
| set -euo pipefail | |
| AGENT="${1:-codex}" | |
| SESSION="${2:-chat}" | |
| ACPX="${ACPX_BIN:-acpx}" | |
| APPROVE_FLAG="--approve-all" | |
| # Colors | |
| CYAN='\033[0;36m' | |
| GREEN='\033[0;32m' | |
| DIM='\033[2m' | |
| BOLD='\033[1m' | |
| RESET='\033[0m' | |
| echo -e "${BOLD}acpx-chat${RESET} ${DIM}— interactive ACP session${RESET}" | |
| echo -e "${DIM}agent:${RESET} ${GREEN}${AGENT}${RESET} ${DIM}session:${RESET} ${GREEN}${SESSION}${RESET}" | |
| echo -e "${DIM}Type your prompt and press Enter. Ctrl+D or 'exit' to quit.${RESET}" | |
| echo "" | |
| # Ensure session exists | |
| $ACPX $AGENT sessions ensure --name "$SESSION" 2>/dev/null || \ | |
| $ACPX $AGENT sessions new --name "$SESSION" 2>/dev/null || true | |
| while true; do | |
| # Prompt | |
| echo -ne "${CYAN}you>${RESET} " | |
| # Read input (supports multi-line with backslash continuation) | |
| if ! IFS= read -r line; then | |
| echo "" | |
| echo -e "${DIM}bye${RESET}" | |
| break | |
| fi | |
| # Trim whitespace | |
| prompt="$(echo "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')" | |
| # Skip empty | |
| [ -z "$prompt" ] && continue | |
| # Exit commands | |
| case "$prompt" in | |
| exit|quit|bye|q) | |
| echo -e "${DIM}bye${RESET}" | |
| break | |
| ;; | |
| /status) | |
| $ACPX $AGENT status 2>/dev/null || echo "no active session" | |
| continue | |
| ;; | |
| /history) | |
| $ACPX $AGENT sessions history "$SESSION" --limit 10 2>/dev/null || echo "no history" | |
| continue | |
| ;; | |
| /close) | |
| $ACPX $AGENT sessions close "$SESSION" 2>/dev/null || echo "no session to close" | |
| echo -e "${DIM}session closed${RESET}" | |
| break | |
| ;; | |
| /help) | |
| echo -e "${DIM}Commands:${RESET}" | |
| echo -e " ${GREEN}/status${RESET} — show session status" | |
| echo -e " ${GREEN}/history${RESET} — show recent turn history" | |
| echo -e " ${GREEN}/close${RESET} — close session and exit" | |
| echo -e " ${GREEN}/help${RESET} — show this help" | |
| echo -e " ${GREEN}exit${RESET} — exit (session stays alive)" | |
| continue | |
| ;; | |
| esac | |
| # Send prompt to ACPX | |
| echo "" | |
| $ACPX $APPROVE_FLAG $AGENT -s "$SESSION" "$prompt" | |
| echo "" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment