From 6a2264e3a734e1a63445603343f9d4a1b1ad6690 Mon Sep 17 00:00:00 2001 From: OpenCode Test Date: Mon, 29 Dec 2025 02:10:37 -0800 Subject: [PATCH] feat: add pa-mode launch script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds the main launch script for PA Agent Mode that manages a persistent tmux session named "pa". Supports attach/create, new, kill, and status commands. Records session starts in the history index.json file. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- automation/pa-mode | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 automation/pa-mode diff --git a/automation/pa-mode b/automation/pa-mode new file mode 100755 index 0000000..f6b92ea --- /dev/null +++ b/automation/pa-mode @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +# PA Agent Mode - Launch/attach to persistent PA tmux session +set -euo pipefail + +SESSION_NAME="pa" +HISTORY_DIR="$HOME/.claude/state/personal-assistant/history" +INDEX_FILE="$HISTORY_DIR/index.json" + +usage() { + echo "Usage: pa-mode [command]" + echo "" + echo "Commands:" + echo " (none) Attach to existing session or create new one" + echo " new Force new session (detaches existing if any)" + echo " kill Terminate the PA session" + echo " status Show session status" + echo "" +} + +get_session_id() { + date +"%Y-%m-%d_%H-%M-%S" +} + +create_session() { + local session_id + session_id=$(get_session_id) + local history_file="$HISTORY_DIR/${session_id}.jsonl" + + # Record session start in index + local tmp_file + tmp_file=$(mktemp) + jq --arg id "$session_id" --arg started "$(date -Iseconds)" \ + '.sessions += [{"id": $id, "started": $started, "ended": null, "summarized": false, "topics": []}]' \ + "$INDEX_FILE" > "$tmp_file" && mv "$tmp_file" "$INDEX_FILE" + + # Create tmux session with claude in PA mode + # Using HISTFILE-like approach: set env var for history location + tmux new-session -d -s "$SESSION_NAME" -c "$HOME" \ + "PA_SESSION_ID='$session_id' PA_HISTORY_FILE='$history_file' claude --dangerously-skip-permissions --agent personal-assistant" + + echo "Created new PA session: $session_id" +} + +attach_session() { + if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then + tmux attach-session -t "$SESSION_NAME" + else + create_session + tmux attach-session -t "$SESSION_NAME" + fi +} + +case "${1:-}" in + "") + attach_session + ;; + new) + if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then + echo "Killing existing session..." + tmux kill-session -t "$SESSION_NAME" + fi + create_session + tmux attach-session -t "$SESSION_NAME" + ;; + kill) + if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then + tmux kill-session -t "$SESSION_NAME" + echo "PA session terminated" + else + echo "No PA session running" + fi + ;; + status) + if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then + echo "PA session is running" + tmux list-sessions -F "#{session_name}: #{session_created} (#{session_attached} attached)" | grep "^$SESSION_NAME:" + else + echo "PA session is not running" + fi + ;; + -h|--help|help) + usage + ;; + *) + echo "Unknown command: $1" + usage + exit 1 + ;; +esac