目前 mac 的 codex desktop app 还没有设置代理功能,但是如果用代理软件开启虚拟网卡,会导致和公司的 vpn 冲突,之前是一直在命令行使用export 然后启动 codex cli 的,后面发现可以直接这样启动
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
export ALL_PROXY=http://127.0.0.1:7890
/Applications/Codex.app/Contents/MacOS/Codex
于是写了一个脚本,可以直接 build 出来配置好代理环境的 codex proxy app。
使用方式:
chmod +x build.sh
./build.sh
然后打开:
/Applications/Codex Proxy.app
build.sh
#!/bin/zsh
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
CONFIG_PATH="$ROOT_DIR/config.env"
usage() {
cat <<'USAGE'
Usage: build.sh [--config PATH]
Builds /Applications/Codex Proxy.app from config.env.
Edit config.env, then rerun this script to rebuild the launcher.
USAGE
}
fail() {
printf 'ERROR: %s\n' "$1" >&2
exit 1
}
escape_double_quoted() {
local value="$1"
value="${value//\\/\\\\}"
value="${value//\"/\\\"}"
value="${value//\$/\\\$}"
value="${value//\`/\\\`}"
printf '%s' "$value"
}
plist_escape() {
local value="$1"
value="${value//&/&}"
value="${value//</<}"
value="${value//>/>}"
value="${value//\"/"}"
value="${value//\'/'}"
printf '%s' "$value"
}
validate_no_newline() {
local name="$1"
local value="$2"
[[ "$value" != *$'\n'* ]] || fail "$name must not contain newlines"
}
while [[ $# -gt 0 ]]; do
case "$1" in
--config)
[[ $# -ge 2 ]] || fail "--config requires a path"
CONFIG_PATH="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
fail "unknown argument: $1"
;;
esac
done
APP_NAME="Codex Proxy"
APP_PATH="/Applications/Codex Proxy.app"
CODEX_BIN="/Applications/Codex.app/Contents/MacOS/Codex"
ICON_SOURCE="/Applications/Codex.app/Contents/Resources/electron.icns"
PROXY_URL="http://127.0.0.1:7890"
NO_PROXY_LIST=()
[[ -f "$CONFIG_PATH" ]] || fail "config file not found: $CONFIG_PATH"
source "$CONFIG_PATH"
validate_no_newline "APP_NAME" "$APP_NAME"
validate_no_newline "APP_PATH" "$APP_PATH"
validate_no_newline "CODEX_BIN" "$CODEX_BIN"
validate_no_newline "ICON_SOURCE" "$ICON_SOURCE"
validate_no_newline "PROXY_URL" "$PROXY_URL"
[[ "$APP_PATH" == *.app ]] || fail "APP_PATH must end with .app"
[[ "$APP_PATH" != "/Applications/Codex.app" ]] || fail "APP_PATH must not overwrite the real Codex.app"
[[ -x "$CODEX_BIN" ]] || fail "Codex binary is not executable: $CODEX_BIN"
[[ -f "$ICON_SOURCE" ]] || fail "icon file not found: $ICON_SOURCE"
for entry in "${NO_PROXY_LIST[@]}"; do
validate_no_newline "NO_PROXY_LIST entry" "$entry"
[[ "$entry" != *","* ]] || fail "NO_PROXY_LIST entries must not contain commas: $entry"
done
NO_PROXY_VALUE="${(j:,:)NO_PROXY_LIST}"
APP_BASENAME="$(basename "$APP_PATH")"
STAGING_ROOT="$(mktemp -d)"
trap 'rm -rf "$STAGING_ROOT"' EXIT
STAGED_APP="$STAGING_ROOT/$APP_BASENAME"
mkdir -p "$STAGED_APP/Contents/MacOS" "$STAGED_APP/Contents/Resources"
APP_NAME_XML="$(plist_escape "$APP_NAME")"
cat > "$STAGED_APP/Contents/Info.plist" <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>$APP_NAME_XML</string>
<key>CFBundleExecutable</key>
<string>CodexProxyLauncher</string>
<key>CFBundleIconFile</key>
<string>electron.icns</string>
<key>CFBundleIdentifier</key>
<string>com.example.codex-proxy-launcher</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$APP_NAME_XML</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
<string>12.0</string>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>
PLIST
CODEX_BIN_SCRIPT="$(escape_double_quoted "$CODEX_BIN")"
PROXY_URL_SCRIPT="$(escape_double_quoted "$PROXY_URL")"
NO_PROXY_SCRIPT="$(escape_double_quoted "$NO_PROXY_VALUE")"
cat > "$STAGED_APP/Contents/MacOS/CodexProxyLauncher" <<LAUNCHER
#!/bin/zsh
set -euo pipefail
CODEX_BIN="$CODEX_BIN_SCRIPT"
PROXY_URL="$PROXY_URL_SCRIPT"
NO_PROXY_VALUE="$NO_PROXY_SCRIPT"
export http_proxy="\$PROXY_URL"
export https_proxy="\$PROXY_URL"
export all_proxy="\$PROXY_URL"
export HTTP_PROXY="\$PROXY_URL"
export HTTPS_PROXY="\$PROXY_URL"
export ALL_PROXY="\$PROXY_URL"
export no_proxy="\$NO_PROXY_VALUE"
export NO_PROXY="\$NO_PROXY_VALUE"
export MallocNanoZone="0"
if [[ "\${CODEX_PROXY_LAUNCHER_DRY_RUN:-}" == "1" ]]; then
printf 'Codex binary: %s\n' "\$CODEX_BIN"
printf 'http_proxy: %s\n' "\$http_proxy"
printf 'https_proxy: %s\n' "\$https_proxy"
printf 'ALL_PROXY: %s\n' "\$ALL_PROXY"
printf 'no_proxy: %s\n' "\$no_proxy"
exit 0
fi
if [[ ! -x "\$CODEX_BIN" ]]; then
/usr/bin/osascript -e 'display dialog "Cannot find executable Codex binary at /Applications/Codex.app/Contents/MacOS/Codex." buttons {"OK"} default button "OK" with icon stop'
exit 1
fi
exec "\$CODEX_BIN" "\$@"
LAUNCHER
chmod +x "$STAGED_APP/Contents/MacOS/CodexProxyLauncher"
cp "$ICON_SOURCE" "$STAGED_APP/Contents/Resources/electron.icns"
/usr/bin/plutil -lint "$STAGED_APP/Contents/Info.plist" >/dev/null
/bin/zsh -n "$STAGED_APP/Contents/MacOS/CodexProxyLauncher"
rm -rf "$APP_PATH"
mkdir -p "$(dirname "$APP_PATH")"
cp -R "$STAGED_APP" "$APP_PATH"
/usr/bin/codesign --force --deep --sign - "$APP_PATH" >/dev/null
/usr/bin/codesign --verify --deep --strict --verbose=2 "$APP_PATH" >/dev/null
/usr/bin/xattr -dr com.apple.quarantine "$APP_PATH" 2>/dev/null || true
printf 'Built %s\n' "$APP_PATH"
printf 'Proxy: %s\n' "$PROXY_URL"
printf 'no_proxy: %s\n' "$NO_PROXY_VALUE"
config.env
# Edit this file, then run:
# ./build.sh
APP_NAME="Codex Proxy"
APP_PATH="/Applications/Codex Proxy.app"
CODEX_BIN="/Applications/Codex.app/Contents/MacOS/Codex"
ICON_SOURCE="/Applications/Codex.app/Contents/Resources/electron.icns"
PROXY_URL="http://127.0.0.1:7890"
# One no_proxy entry per line. build.sh joins these with commas.
NO_PROXY_LIST=(
"127.0.0.1"
"::1"
"localhost"
# Add your company/VPN/internal domains here.
"*.company.com"
# Add internal IPs here if needed.
"192.168.0.0/16"
"10.0.0.0/8"
)
1 个帖子 - 1 位参与者