mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-05-05 23:50:48 +00:00
refactor: Extract ENV_TEMP pattern to inject_env_vars_local (Modal)
Created inject_env_vars_local() function in shared/common.sh to eliminate
duplicate temporary file creation pattern. Converted 10 Modal scripts:
- aider, claude, amazonq, cline, codex
- gemini, goose, interpreter, nanoclaw, openclaw
Reduces ~10-15 lines per script to 3-4 lines.
Pattern before:
ENV_TEMP=$(mktemp)
trap 'rm -f "${ENV_TEMP}"' EXIT
cat > "${ENV_TEMP}" << EOF
# [spawn:env]
export KEY=value
EOF
upload_file "${ENV_TEMP}" "/tmp/env_config"
run_server "cat /tmp/env_config >> ~/.zshrc && rm /tmp/env_config"
Pattern after:
inject_env_vars_local upload_file run_server \
"KEY=value"
Special case: nanoclaw.sh has additional DOTENV_TEMP for agent-specific
.env file, which remains unchanged.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
b6ee6b6ab1
commit
3a0ecd80e9
11 changed files with 78 additions and 124 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#!/bin/bash
|
||||
# shellcheck disable=SC2154
|
||||
set -eo pipefail
|
||||
|
||||
# Source common functions - try local file first, fall back to remote
|
||||
|
|
@ -46,17 +47,9 @@ fi
|
|||
# 6. Inject environment variables into ~/.zshrc
|
||||
log_warn "Setting up environment variables..."
|
||||
|
||||
ENV_TEMP=$(mktemp)
|
||||
trap 'rm -f "${ENV_TEMP}"' EXIT
|
||||
cat > "${ENV_TEMP}" << EOF
|
||||
|
||||
# [spawn:env]
|
||||
export GOOSE_PROVIDER=openrouter
|
||||
export OPENROUTER_API_KEY="${OPENROUTER_API_KEY}"
|
||||
EOF
|
||||
|
||||
upload_file "${ENV_TEMP}" "/tmp/env_config"
|
||||
run_server "cat /tmp/env_config >> ~/.zshrc && rm /tmp/env_config"
|
||||
inject_env_vars_local upload_file run_server \
|
||||
"GOOSE_PROVIDER=openrouter" \
|
||||
"OPENROUTER_API_KEY=${OPENROUTER_API_KEY}"
|
||||
|
||||
echo ""
|
||||
log_info "Modal sandbox setup completed successfully!"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue