| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | cd "$(dirname "$0")/.." |
| 4 | |
| 5 | skip_ui=false |
| 6 | case "${1:-}" in |
| 7 | '') ;; |
| 8 | --skip-ui) skip_ui=true ;; |
| 9 | *) echo 'Usage: scripts/build-client.sh [--skip-ui]' >&2; exit 2 ;; |
| 10 | esac |
| 11 | case "$(uname -s)" in Darwin) platform=macos ;; Linux) platform=linux ;; *) echo 'Use build-client-windows.ps1 for Windows.' >&2; exit 1 ;; esac |
| 12 | case "$(uname -m)" in arm64|aarch64) arch=arm64 ;; x86_64) arch=amd64 ;; *) echo 'Unsupported client build architecture.' >&2; exit 1 ;; esac |
| 13 | version="$(tr -d '\r\n' < VERSION)" |
| 14 | [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.-]+)?$ ]] || { echo 'Invalid VERSION.' >&2; exit 1; } |
| 15 | short_version="${version%%-*}" |
| 16 | output_root="$PWD/_output/client-$platform-$arch" |
| 17 | mkdir -p "$output_root" |
| 18 | stage="$(mktemp -d "$output_root/.stage.XXXXXX")" |
| 19 | trap 'rm -rf "$stage"' EXIT |
| 20 | suffix="${stage##*.stage.}" |
| 21 | destination="$output_root/build-$(date +%Y%m%d-%H%M%S)-$suffix" |
| 22 | [[ ! -e "$destination" ]] || { echo 'Client output already exists; no files were replaced.' >&2; exit 1; } |
| 23 | |
| 24 | if [[ "$skip_ui" == false ]]; then |
| 25 | [[ -d ui/node_modules ]] || npm --prefix ui ci --no-audit --no-fund |
| 26 | npm --prefix ui run build |
| 27 | else |
| 28 | node ui/scripts/verify-build.mjs |
| 29 | fi |
| 30 | [[ -f internal/workbench/web/index.html ]] || { echo 'Build the UI before using --skip-ui.' >&2; exit 1; } |
| 31 | go list -deps ./cmd/cage-client > "$stage/dependencies.txt" |
| 32 | if grep -Eq 'internal/limaembed|github.com/lima-vm/lima/v2|github.com/Code-Hex/vz' "$stage/dependencies.txt"; then |
| 33 | echo 'The client unexpectedly depends on a virtual machine runtime; build stopped.' >&2; exit 1 |
| 34 | fi |
| 35 | CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X github.com/sylvinus/agent-vm/internal/version.Version=$version" -o "$stage/cage" ./cmd/cage-client |
| 36 | "$stage/cage" verify-web-assets |
| 37 | mkdir -p "$stage/result" |
| 38 | |
| 39 | if [[ "$platform" == macos ]]; then |
| 40 | bundle="$stage/result/Cage Client.app" |
| 41 | mkdir -p "$bundle/Contents/MacOS" "$bundle/Contents/Resources" |
| 42 | swiftc -O -target "$(uname -m)-apple-macosx14.0" -parse-as-library \ |
| 43 | -framework Cocoa -framework WebKit -framework Security -framework LocalAuthentication \ |
| 44 | desktop/Cage.swift desktop/MacKeyboard.swift desktop/NativeInput.swift desktop/Updates.swift desktop/AccountDevice.swift desktop/MacGuestLogin.swift \ |
| 45 | -o "$bundle/Contents/MacOS/Cage" |
| 46 | node scripts/bundle-cloud-kit.mjs "$bundle/Contents/Resources" |
| 47 | cp "$stage/cage" "$bundle/Contents/Resources/cage" |
| 48 | node scripts/collect-app-licenses.mjs "$bundle/Contents/Resources/licenses" |
| 49 | swift desktop/Icon.swift logo.png "$stage/Cage.iconset" |
| 50 | iconutil -c icns "$stage/Cage.iconset" -o "$bundle/Contents/Resources/Cage.icns" |
| 51 | cat > "$bundle/Contents/Info.plist" <<PLIST |
| 52 | <?xml version="1.0" encoding="UTF-8"?> |
| 53 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 54 | <plist version="1.0"><dict> |
| 55 | <key>CFBundleName</key><string>Cage Client</string> |
| 56 | <key>CFBundleDisplayName</key><string>Cage Client</string> |
| 57 | <key>CFBundleIdentifier</key><string>io.github.lee-xeo.claude-cage-client</string> |
| 58 | <key>CFBundleVersion</key><string>1</string> |
| 59 | <key>CFBundleShortVersionString</key><string>$short_version</string> |
| 60 | <key>CageVersion</key><string>$version</string> |
| 61 | <key>CageClientOnly</key><true/> |
| 62 | <key>CFBundleExecutable</key><string>Cage</string> |
| 63 | <key>CFBundleIconFile</key><string>Cage</string> |
| 64 | <key>CFBundlePackageType</key><string>APPL</string> |
| 65 | <key>LSMinimumSystemVersion</key><string>14.0</string> |
| 66 | <key>NSHighResolutionCapable</key><true/> |
| 67 | <key>NSAppTransportSecurity</key><dict><key>NSAllowsLocalNetworking</key><true/></dict> |
| 68 | </dict></plist> |
| 69 | PLIST |
| 70 | # An ad-hoc development signature makes the local build runnable. No release |
| 71 | # certificate, notarization, installer, or installed app is touched. |
| 72 | codesign --force --sign - "$bundle/Contents/Resources/cage" |
| 73 | codesign --force --sign - "$bundle/Contents/MacOS/Cage" |
| 74 | codesign --force --sign - "$bundle" |
| 75 | codesign --verify --deep --strict "$bundle" |
| 76 | ditto -c -k --keepParent "$bundle" "$stage/result/Cage-Client-macos-$arch.zip" |
| 77 | else |
| 78 | pkg-config --atleast-version=2.40 webkit2gtk-4.1 |
| 79 | pkg-config --exists gtk+-3.0 json-glib-1.0 |
| 80 | app="$stage/result/app" |
| 81 | mkdir -p "$app" |
| 82 | cc -std=c11 -O2 -Wall -Wextra -Werror -Wno-deprecated-declarations \ |
| 83 | "-DCAGE_VERSION=\"$version\"" -DCAGE_CLIENT_ONLY=1 desktop/linux/cage-desktop.c \ |
| 84 | $(pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.1 json-glib-1.0) -o "$app/cage-desktop" |
| 85 | install -m 755 "$stage/cage" "$app/cage" |
| 86 | node scripts/bundle-cloud-kit.mjs "$app" |
| 87 | touch "$app/client-only" |
| 88 | node scripts/collect-app-licenses.mjs "$app/licenses" |
| 89 | printf '%s\n' 'libwebkit2gtk-4.1-0 (>= 2.40), libgtk-3-0, libjson-glib-1.0-0, libglib2.0-bin, ca-certificates' > "$app/dependencies.txt" |
| 90 | cp /etc/os-release "$app/BUILD-PLATFORM.txt" |
| 91 | pkg-config --modversion gtk+-3.0 webkit2gtk-4.1 json-glib-1.0 >> "$app/BUILD-PLATFORM.txt" |
| 92 | cat > "$app/README.txt" <<'LINUX_README' |
| 93 | Cage 轻量远程客户端(Linux 开发构建) |
| 94 | 在兼容 BUILD-PLATFORM.txt 所列发行版的图形桌面中,以普通用户运行 cage-desktop。 |
| 95 | 系统依赖见 dependencies.txt。项目、应用与网络在云端运行;本机连接配置默认位于 ~/.claude-cage/client。 |
| 96 | 构建不安装或覆盖现有应用,不包含虚拟机、Mihomo 或 OpenSSH 程序。验收范围以项目测试报告为准。 |
| 97 | LINUX_README |
| 98 | "$app/cage-desktop" --self-test |
| 99 | tar -C "$stage/result" -czf "$stage/result/Cage-Client-linux-$arch.tar.gz" app |
| 100 | fi |
| 101 | cp LICENSE "$stage/result/LICENSE" |
| 102 | printf '%s\n' "$version" > "$stage/result/VERSION" |
| 103 | cat > "$stage/result/README.txt" <<'README' |
| 104 | Cage 轻量远程客户端(开发构建) |
| 105 | |
| 106 | 本机只提供窗口、SSH 连接、输入和文件传递;项目、浏览器、终端与网络在云端 Cage 运行。 |
| 107 | 默认连接配置目录为 ~/.claude-cage/client;显式设置 CLAUDE_CAGE_CONFIG 时沿用指定路径。 |
| 108 | 此目录为独立构建产物,不会安装或替换已安装的 Cage。当前构建使用手动更新。 |
| 109 | macOS 运行 Cage Client.app。Linux 安装 app/dependencies.txt 中的系统依赖后运行 app/cage-desktop。 |
| 110 | 本构建未公证或发布;原生运行验收范围以项目测试报告为准。 |
| 111 | README |
| 112 | mv "$stage/result" "$destination" |
| 113 | printf 'Built standalone client: %s\n' "$destination" |