diff options
| -rwxr-xr-x | claude-templates/bin/ai | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/claude-templates/bin/ai b/claude-templates/bin/ai index 45cc56a..a167174 100755 --- a/claude-templates/bin/ai +++ b/claude-templates/bin/ai @@ -15,8 +15,8 @@ # # ai -h | --help Show this help. # -# Source: ~/projects/claude-templates/bin/ai -# Install: make -C ~/projects/claude-templates install +# Source: ~/code/rulesets/claude-templates/bin/ai +# Install: make -C ~/code/rulesets install # # NOTE: do not enable `set -e`. Several helper functions use # `[ test ] && action` patterns that legitimately return non-zero when @@ -26,7 +26,17 @@ SESSION="ai" CLAUDE_CMD="claude" -CLAUDE_INSTRUCTIONS='Read .ai/protocols.org and follow all instructions.' + +# Format the per-project opening line passed to claude. Takes the project +# directory's basename; returns a string of the form +# "This is <host> <name> project. Follow all instructions in .ai/protocols.org." +# Uses uname -n for the host (POSIX, no dependency on the hostname binary +# which isn't installed by default on every distro). The project name +# disambiguates windows when multiple projects share an ai-session. +build_instructions() { + local name="$1" + printf 'This is %s %s project. Follow all instructions in .ai/protocols.org.' "$(uname -n)" "$name" +} usage() { sed -n '2,20p' "$0" | sed 's|^# \?||' @@ -52,10 +62,11 @@ attach_session() { # Create a window in the ai session, launch claude, return window id. create_window() { - local dir="$1" name="$2" wid + local dir="$1" name="$2" wid instructions wid=$(tmux new-window -t "$SESSION" -n "$name" -c "$dir" -P -F '#{window_id}') sleep 0.1 - tmux send-keys -t "$wid" "$CLAUDE_CMD \"$CLAUDE_INSTRUCTIONS\"" Enter + instructions=$(build_instructions "$name") + tmux send-keys -t "$wid" "$CLAUDE_CMD \"$instructions\"" Enter echo "$wid" } @@ -297,8 +308,10 @@ single_mode() { if tmux has-session -t "$SESSION" 2>/dev/null; then wid=$(create_window "$dir" "$name") else + local instructions wid=$(tmux new-session -d -s "$SESSION" -n "$name" -c "$dir" -P -F '#{window_id}') - tmux send-keys -t "$wid" "$CLAUDE_CMD \"$CLAUDE_INSTRUCTIONS\"" Enter + instructions=$(build_instructions "$name") + tmux send-keys -t "$wid" "$CLAUDE_CMD \"$instructions\"" Enter fi sort_windows @@ -355,8 +368,10 @@ multi_mode() { dir="${first/#\~/$HOME}" name="$(basename "$dir")" auto_pull_if_clean "$dir" + local instructions first_wid=$(tmux new-session -d -s "$SESSION" -n "$name" -c "$dir" -P -F '#{window_id}') - tmux send-keys -t "$first_wid" "$CLAUDE_CMD \"$CLAUDE_INSTRUCTIONS\"" Enter + instructions=$(build_instructions "$name") + tmux send-keys -t "$first_wid" "$CLAUDE_CMD \"$instructions\"" Enter for entry in "${selected[@]:1}"; do dir="${entry/#\~/$HOME}" name="$(basename "$dir")" |
