comparison mrjunejune/inference_stack.sh @ 271:13d61401c57d

redirect Copilot cache to service state Set XDG_CACHE_HOME from the configured inference state so the systemd service can extract Copilot outside its protected home directory. Co-authored-by: Copilot <[email protected]>
author MrJuneJune <me@mrjunejune.com>
date Fri, 07 Aug 2026 13:24:05 -0700
parents 056790c4fb0d
children
comparison
equal deleted inserted replaced
270:358dd5950985 271:13d61401c57d
104 104
105 litellm_host="${LITELLM_HOST:-127.0.0.1}" 105 litellm_host="${LITELLM_HOST:-127.0.0.1}"
106 litellm_port="${LITELLM_PORT:-4000}" 106 litellm_port="${LITELLM_PORT:-4000}"
107 default_state_root="${XDG_STATE_HOME:-$HOME/.local/state}/mrjunejune/inference" 107 default_state_root="${XDG_STATE_HOME:-$HOME/.local/state}/mrjunejune/inference"
108 state_root="${MRJUNEJUNE_INFERENCE_STATE:-$default_state_root}" 108 state_root="${MRJUNEJUNE_INFERENCE_STATE:-$default_state_root}"
109 copilot_cache_root="$state_root/cache"
109 litellm_pid= 110 litellm_pid=
110 server_pid= 111 server_pid=
111 112
112 if [[ "$mode" == "check-config" ]]; then 113 if [[ "$mode" == "check-config" ]]; then
113 printf 'config=%s\n' "$config_file" 114 printf 'config=%s\n' "$config_file"
116 else 117 else
117 echo 'litellm_master_key=missing (generated on first local live run)' 118 echo 'litellm_master_key=missing (generated on first local live run)'
118 fi 119 fi
119 printf 'copilot_token_dir=%s\n' \ 120 printf 'copilot_token_dir=%s\n' \
120 "${GITHUB_COPILOT_TOKEN_DIR:-$state_root/litellm-copilot}" 121 "${GITHUB_COPILOT_TOKEN_DIR:-$state_root/litellm-copilot}"
122 printf 'copilot_cache_dir=%s\n' "$copilot_cache_root"
121 printf 'guest_inference=%s\n' \ 123 printf 'guest_inference=%s\n' \
122 "${MRJUNEJUNE_ALLOW_GUEST_INFERENCE:-false}" 124 "${MRJUNEJUNE_ALLOW_GUEST_INFERENCE:-false}"
123 exit 0 125 exit 0
124 fi 126 fi
125 127
126 if [[ "$mode" == "authenticate" ]]; then 128 if [[ "$mode" == "authenticate" ]]; then
127 token_dir="${GITHUB_COPILOT_TOKEN_DIR:-$state_root/litellm-copilot}" 129 token_dir="${GITHUB_COPILOT_TOKEN_DIR:-$state_root/litellm-copilot}"
128 mkdir -p "$token_dir" 130 mkdir -p "$token_dir" "$copilot_cache_root"
129 chmod 700 "$token_dir" 131 chmod 700 "$token_dir" "$copilot_cache_root"
132 export XDG_CACHE_HOME="$copilot_cache_root"
130 exec "$python" "$litellm_zip" --authenticate --token-dir "$token_dir" 133 exec "$python" "$litellm_zip" --authenticate --token-dir "$token_dir"
131 fi 134 fi
132 135
133 cleanup() { 136 cleanup() {
134 for pid in "$server_pid" "$litellm_pid"; do 137 for pid in "$server_pid" "$litellm_pid"; do
191 exit 1 194 exit 1
192 fi 195 fi
193 fi 196 fi
194 export LITELLM_MASTER_KEY 197 export LITELLM_MASTER_KEY
195 token_dir="${GITHUB_COPILOT_TOKEN_DIR:-$state_root/litellm-copilot}" 198 token_dir="${GITHUB_COPILOT_TOKEN_DIR:-$state_root/litellm-copilot}"
196 mkdir -p "$state_root/copilot" "$token_dir" 199 mkdir -p "$state_root/copilot" "$token_dir" "$copilot_cache_root"
197 chmod 700 "$state_root" "$state_root/copilot" "$token_dir" 200 chmod 700 "$state_root" "$state_root/copilot" "$token_dir" "$copilot_cache_root"
198 201
199 export GITHUB_COPILOT_TOKEN_DIR="$token_dir" 202 export GITHUB_COPILOT_TOKEN_DIR="$token_dir"
200 if [[ ! -s "$GITHUB_COPILOT_TOKEN_DIR/access-token" ]]; then 203 if [[ ! -s "$GITHUB_COPILOT_TOKEN_DIR/access-token" ]]; then
201 echo "GitHub Copilot is not authenticated for LiteLLM." >&2 204 echo "GitHub Copilot is not authenticated for LiteLLM." >&2
202 echo "Run: bazel run //mrjunejune:run_inference_stack -- --authenticate" >&2 205 echo "Run: bazel run //mrjunejune:run_inference_stack -- --authenticate" >&2
236 export MRJUNEJUNE_PYTHON_PATH="$python" 239 export MRJUNEJUNE_PYTHON_PATH="$python"
237 export MRJUNEJUNE_SIDECAR_ZIP="$sidecar_zip" 240 export MRJUNEJUNE_SIDECAR_ZIP="$sidecar_zip"
238 export MRJUNEJUNE_INFERENCE_SIDECAR_PATH="$sidecar_launcher" 241 export MRJUNEJUNE_INFERENCE_SIDECAR_PATH="$sidecar_launcher"
239 export MRJUNEJUNE_COPILOT_CLI_PATH="$copilot_cli" 242 export MRJUNEJUNE_COPILOT_CLI_PATH="$copilot_cli"
240 export COPILOT_SIDECAR_HOME="$state_root/copilot" 243 export COPILOT_SIDECAR_HOME="$state_root/copilot"
244 export XDG_CACHE_HOME="$copilot_cache_root"
241 export LITELLM_BASE_URL="http://${litellm_host}:${litellm_port}/v1" 245 export LITELLM_BASE_URL="http://${litellm_host}:${litellm_port}/v1"
242 export LITELLM_MODEL="${LITELLM_MODEL:-jrpg-copilot}" 246 export LITELLM_MODEL="${LITELLM_MODEL:-jrpg-copilot}"
243 export LITELLM_WIRE_API="${LITELLM_WIRE_API:-completions}" 247 export LITELLM_WIRE_API="${LITELLM_WIRE_API:-completions}"
244 export LITELLM_API_KEY="$LITELLM_MASTER_KEY" 248 export LITELLM_API_KEY="$LITELLM_MASTER_KEY"
245 export MRJUNEJUNE_ALLOW_GUEST_INFERENCE 249 export MRJUNEJUNE_ALLOW_GUEST_INFERENCE