mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-05-22 11:24:18 +00:00
refactor: improve readability of config setup and shellcheck discovery (#744)
- Replace hardcoded 4-cloud script list in run_shellcheck with dynamic discovery that covers all 21 clouds automatically - Convert 3 inline JSON templates (setup_claude_code_config, setup_openclaw_config, setup_continue_config) from single-line printf to readable heredocs while preserving json_escape security Agent: complexity-hunter Co-authored-by: A <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
242eb1dde0
commit
cec1806128
2 changed files with 76 additions and 18 deletions
|
|
@ -1925,8 +1925,25 @@ setup_claude_code_config() {
|
|||
${run_callback} "mkdir -p ~/.claude"
|
||||
|
||||
# Create settings.json
|
||||
local escaped_key
|
||||
escaped_key=$(json_escape "${openrouter_key}")
|
||||
local settings_json
|
||||
settings_json=$(printf '{\n "theme": "dark",\n "editor": "vim",\n "env": {\n "CLAUDE_CODE_ENABLE_TELEMETRY": "0",\n "ANTHROPIC_BASE_URL": "https://openrouter.ai/api",\n "ANTHROPIC_AUTH_TOKEN": %s\n },\n "permissions": {\n "defaultMode": "bypassPermissions",\n "dangerouslySkipPermissions": true\n }\n}\n' "$(json_escape "${openrouter_key}")")
|
||||
settings_json=$(cat << EOF
|
||||
{
|
||||
"theme": "dark",
|
||||
"editor": "vim",
|
||||
"env": {
|
||||
"CLAUDE_CODE_ENABLE_TELEMETRY": "0",
|
||||
"ANTHROPIC_BASE_URL": "https://openrouter.ai/api",
|
||||
"ANTHROPIC_AUTH_TOKEN": ${escaped_key}
|
||||
},
|
||||
"permissions": {
|
||||
"defaultMode": "bypassPermissions",
|
||||
"dangerouslySkipPermissions": true
|
||||
}
|
||||
}
|
||||
EOF
|
||||
)
|
||||
upload_config_file "${upload_callback}" "${run_callback}" "${settings_json}" "~/.claude/settings.json"
|
||||
|
||||
# Create .claude.json global state
|
||||
|
|
@ -1983,8 +2000,31 @@ setup_openclaw_config() {
|
|||
gateway_token=$(openssl rand -hex 16)
|
||||
|
||||
# Create openclaw.json config
|
||||
local escaped_key escaped_token
|
||||
escaped_key=$(json_escape "${openrouter_key}")
|
||||
escaped_token=$(json_escape "${gateway_token}")
|
||||
local openclaw_json
|
||||
openclaw_json=$(printf '{\n "env": {\n "OPENROUTER_API_KEY": %s\n },\n "gateway": {\n "mode": "local",\n "auth": {\n "token": %s\n }\n },\n "agents": {\n "defaults": {\n "model": {\n "primary": "openrouter/%s"\n }\n }\n }\n}\n' "$(json_escape "${openrouter_key}")" "$(json_escape "${gateway_token}")" "${model_id}")
|
||||
openclaw_json=$(cat << EOF
|
||||
{
|
||||
"env": {
|
||||
"OPENROUTER_API_KEY": ${escaped_key}
|
||||
},
|
||||
"gateway": {
|
||||
"mode": "local",
|
||||
"auth": {
|
||||
"token": ${escaped_token}
|
||||
}
|
||||
},
|
||||
"agents": {
|
||||
"defaults": {
|
||||
"model": {
|
||||
"primary": "openrouter/${model_id}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
)
|
||||
upload_config_file "${upload_callback}" "${run_callback}" "${openclaw_json}" "~/.openclaw/openclaw.json"
|
||||
}
|
||||
|
||||
|
|
@ -2021,8 +2061,23 @@ setup_continue_config() {
|
|||
${run_callback} "mkdir -p ~/.continue"
|
||||
|
||||
# Create config.json with json_escape to prevent injection
|
||||
local escaped_key
|
||||
escaped_key=$(json_escape "${openrouter_key}")
|
||||
local continue_json
|
||||
continue_json=$(printf '{\n "models": [\n {\n "title": "OpenRouter",\n "provider": "openrouter",\n "model": "openrouter/auto",\n "apiBase": "https://openrouter.ai/api/v1",\n "apiKey": %s\n }\n ]\n}\n' "$(json_escape "${openrouter_key}")")
|
||||
continue_json=$(cat << EOF
|
||||
{
|
||||
"models": [
|
||||
{
|
||||
"title": "OpenRouter",
|
||||
"provider": "openrouter",
|
||||
"model": "openrouter/auto",
|
||||
"apiBase": "https://openrouter.ai/api/v1",
|
||||
"apiKey": ${escaped_key}
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
)
|
||||
upload_config_file "${upload_callback}" "${run_callback}" "${continue_json}" "~/.continue/config.json"
|
||||
}
|
||||
|
||||
|
|
|
|||
33
test/run.sh
33
test/run.sh
|
|
@ -587,21 +587,24 @@ run_shellcheck() {
|
|||
return 0
|
||||
fi
|
||||
|
||||
# Find all shell scripts
|
||||
local all_scripts=(
|
||||
"${REPO_ROOT}"/sprite/*.sh
|
||||
"${REPO_ROOT}"/sprite/lib/common.sh
|
||||
"${REPO_ROOT}"/shared/common.sh
|
||||
"${REPO_ROOT}"/digitalocean/*.sh
|
||||
"${REPO_ROOT}"/digitalocean/lib/common.sh
|
||||
"${REPO_ROOT}"/hetzner/*.sh
|
||||
"${REPO_ROOT}"/hetzner/lib/common.sh
|
||||
"${REPO_ROOT}"/linode/*.sh
|
||||
"${REPO_ROOT}"/linode/lib/common.sh
|
||||
"${REPO_ROOT}"/vultr/*.sh
|
||||
"${REPO_ROOT}"/vultr/lib/common.sh
|
||||
"${REPO_ROOT}"/test/run.sh
|
||||
)
|
||||
# Dynamically discover all shell scripts (agent scripts + lib files + test harness)
|
||||
local all_scripts=()
|
||||
local dir
|
||||
for dir in "${REPO_ROOT}"/*/; do
|
||||
local cloud
|
||||
cloud=$(basename "${dir}")
|
||||
# Skip non-cloud directories
|
||||
case "${cloud}" in
|
||||
cli|shared|test|node_modules|.git|.github|.claude|.docs) continue ;;
|
||||
esac
|
||||
# Add agent scripts and lib/common.sh if they exist
|
||||
local f
|
||||
for f in "${dir}"*.sh; do
|
||||
[[ -f "${f}" ]] && all_scripts+=("${f}")
|
||||
done
|
||||
[[ -f "${dir}lib/common.sh" ]] && all_scripts+=("${dir}lib/common.sh")
|
||||
done
|
||||
all_scripts+=("${REPO_ROOT}/shared/common.sh" "${REPO_ROOT}/test/run.sh")
|
||||
|
||||
local issue_count=0
|
||||
local checked_count=0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue