fedora-csb-system-manager
1{ pkgs }:
2
3let
4 # Helper script to start Claude Code with Vertex AI environment
5 # Takes required directory argument: claude-vertex <directory>
6 claude-vertex = pkgs.writeShellScript "claude-vertex" ''
7 export CLAUDE_CODE_USE_VERTEX=1
8 export CLOUD_ML_REGION=us-east5
9 export ANTHROPIC_VERTEX_PROJECT_ID=itpc-gcp-pnd-pe-eng-claude
10 # Set TERM for proper color support
11 export TERM=xterm-256color
12
13 # Directory is required
14 if [ -z "''${1:-}" ]; then
15 echo "Error: directory argument is required" >&2
16 exit 1
17 fi
18
19 # Check if directory exists
20 if [ ! -d "$1" ]; then
21 echo "Error: directory does not exist: $1" >&2
22 exit 1
23 fi
24
25 # Change to specified directory
26 cd "$1"
27
28 # Execute through zsh with proper environment
29 # zshenv sets up PATH and other environment variables
30 exec ${pkgs.zsh}/bin/zsh -c "source ~/.zshenv; exec /etc/profiles/per-user/vincent/bin/claude"
31 '';
32in
33
34pkgs.writeScriptBin "shpool-ssh-wrapper" ''
35 #!${pkgs.bash}/bin/bash
36 # Shpool SSH wrapper - automatically runs commands for specific session patterns
37 # Supports syntax: session-name=directory (e.g., "claude/home=src/home")
38
39 set -euo pipefail
40
41 # Parse session spec: "claude/home=src/home" -> session="claude/home", dir="src/home"
42 SESSION_SPEC="''${1}"
43 if [[ "$SESSION_SPEC" =~ ^([^=]+)=(.+)$ ]]; then
44 SESSION_NAME="''${BASH_REMATCH[1]}"
45 WORK_DIR="''${BASH_REMATCH[2]}"
46 else
47 SESSION_NAME="$SESSION_SPEC"
48 WORK_DIR=""
49 fi
50
51 # Function to run shpool with a specific command
52 run_with_command() {
53 local session="$1"
54 local cmd="$2"
55 shift 2
56 exec ${pkgs.shpool}/bin/shpool attach -f -c "$cmd $*" "$session"
57 }
58
59 # Check session name patterns and run appropriate commands
60 case "$SESSION_NAME" in
61 claude/*)
62 # Claude Code session - run with Vertex AI environment
63 # If no directory specified, default to src/{session-name}
64 if [ -z "$WORK_DIR" ]; then
65 # Extract session name part after "claude/"
66 SESSION_SUFFIX="''${SESSION_NAME#claude/}"
67 WORK_DIR="src/$SESSION_SUFFIX"
68 fi
69 # Use helper script since shpool -c expects a binary, not a shell command
70 run_with_command "$SESSION_NAME" "${claude-vertex}" "$WORK_DIR"
71 ;;
72 *)
73 # If work directory specified, cd into it before attaching
74 if [ -n "$WORK_DIR" ]; then
75 # Start shell and cd into directory
76 exec ${pkgs.shpool}/bin/shpool attach -f -c "${pkgs.zsh}/bin/zsh -c 'cd $WORK_DIR && exec ${pkgs.zsh}/bin/zsh'" "$SESSION_NAME"
77 else
78 # Default: just attach to session with default shell
79 exec ${pkgs.shpool}/bin/shpool attach -f "$SESSION_NAME"
80 fi
81 ;;
82 esac
83''