跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

提交记录
修改scripts/build-app.sh+4 −0看文件
@@ -36,6 +36,7 @@ short_version="${version%%-*}"
3636build_version="${CAGE_BUILD_NUMBER:-1}"
3737if [[ ! "$build_version" =~ ^[0-9]+(\.[0-9]+){0,2}$ ]]; then echo 'Invalid CAGE_BUILD_NUMBER.' >&2; exit 1; fi
3838identity="${CAGE_SIGNING_IDENTITY:--}"
39新增:export CAGE_SIGNING_IDENTITY="$identity"
3940# The host SDK may default to the developer's newer macOS version. Set the
4041# deployment target for the Go/cgo helper as well as the Swift launcher.
4142export MACOSX_DEPLOYMENT_TARGET=14.0
@@ -59,6 +60,9 @@ cp _output/bin/cage "$bundle/Contents/Resources/cage"
5960if [[ "$(uname -m)" == arm64 ]]; then "$bundle/Contents/Resources/cage" verify-macos-guest; fi
6061if [[ "$(uname -m)" == arm64 ]]; then
6162 bash scripts/guest-os/package-macos-guest.sh "$bundle/Contents/Resources/guest-os"
63新增: # The kit signs all nested native code before this outer App is sealed.
64新增: # Do not generate or reuse an unsigned component manifest here: installation
65新增: # hashes the final signed kit, including each nested bundle's CodeResources.
6266fi
6367node scripts/bundle-cloud-kit.mjs "$bundle/Contents/Resources"
6468cp _output/proxy-core/mihomo "$bundle/Contents/Resources/mihomo"
修改scripts/guest-os/package-macos-guest.sh+3 −0看文件
@@ -33,3 +33,6 @@ cp "$src/../../internal/cage/claude-account.py" "$src/../../internal/workbench/"
3333# Shared component maintenance is installed separately from first-run accounts.
3434cp "$src/maintain-macos-workbench.sh" "$src/native-component-manifest.pl" "$dest/"
3535cp "$src/configure-macos-session.sh" "$dest/"
36新增:# Final signing runs after every helper has been built. Component manifests are
37新增:# computed from these final bytes by RequiredNativeComponents at installation.
38新增:bash "$src/sign-macos-guest.sh" "$dest" "${CAGE_SIGNING_IDENTITY:--}"
新增scripts/guest-os/sign-macos-guest.sh+37 −0看文件
@@ -0,0 +1,37 @@
1新增:#!/bin/bash
2新增:# Sign only the guest kit's Mach-O code, inside out. Source and foreign payloads
3新增:# are data; every native executable is refreshed even if a cache was ad-hoc signed.
4新增:set -euo pipefail
5新增:[[ $# == 2 && -d $1 ]] || { echo 'Usage: sign-macos-guest.sh /guest-kit signing-identity' >&2; exit 2; }
6新增:kit=$1 identity=$2
7新增:src=$(cd "$(dirname "$0")" && pwd)
8新增:sign=(/usr/bin/codesign --force --sign "$identity")
9新增:if [[ $identity != - ]]; then
10新增: [[ $identity == 'Developer ID Application:'* || $identity =~ ^[[:xdigit:]]{40}$ ]] || { echo 'Guest release code requires a Developer ID Application name or certificate fingerprint.' >&2; exit 2; }
11新增: sign+=(--timestamp --options runtime)
12新增:fi
13新增:count=0
14新增:while IFS= read -r -d '' executable; do
15新增: kind=$(/usr/bin/file -b "$executable")
16新增: [[ $kind == *Mach-O* ]] || continue
17新增: if [[ $executable == "$kit/project/cage-sshfs" ]]; then
18新增: # macFUSE is installed in the guest by its own publisher, outside our team.
19新增: "${sign[@]}" --entitlements "$src/sshfs.entitlements" "$executable"
20新增: else
21新增: "${sign[@]}" "$executable"
22新增: fi
23新增: /usr/bin/codesign --verify --strict "$executable"
24新增: if [[ $identity != - ]]; then
25新增: metadata=$(/usr/bin/codesign -d --verbose=4 "$executable" 2>&1)
26新增: grep -q '^Authority=Developer ID Application:' <<< "$metadata"
27新增: grep -q 'flags=.*runtime' <<< "$metadata"
28新增: grep -q '^Timestamp=' <<< "$metadata"
29新增: fi
30新增: count=$((count+1))
31新增:done < <(/usr/bin/find "$kit" -type f -print0)
32新增:[[ $count -gt 0 ]] || { echo 'Guest kit contains no native executable.' >&2; exit 1; }
33新增:while IFS= read -r -d '' app; do
34新增: "${sign[@]}" "$app"
35新增: /usr/bin/codesign --verify --deep --strict "$app"
36新增:done < <(/usr/bin/find "$kit" -depth -type d -name '*.app' -print0)
37新增:printf 'Signed and verified %s guest Mach-O files.\n' "$count"
新增scripts/guest-os/sshfs.entitlements+6 −0看文件
@@ -0,0 +1,6 @@
1新增:<?xml version="1.0" encoding="UTF-8"?>
2新增:<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3新增:<plist version="1.0"><dict>
4新增:<!-- macFUSE's signed system-installed library belongs to a different team. -->
5新增:<key>com.apple.security.cs.disable-library-validation</key><true/>
6新增:</dict></plist>
修改scripts/test-macos-install.mjs+26 −6看文件
@@ -28,6 +28,8 @@ const run = (exe, args, options = {}) => execFileSync(exe, args, { encoding: "ut
2828const cli = (...args) => run(path.join(installed, "Contents/Resources/cage"), args, { env });
2929const hash = async file => createHash("sha256").update(await fs.readFile(file)).digest("hex");
3030const password = randomUUID() + "7z";
31新增:const username = "install_smoke";
32新增:const evidence = process.env.CAGE_REMOTE_QA_DIR;
3133let browser, mounted = false, running = false;
3234
3335try {
@@ -45,10 +47,13 @@ try {
4547 launcher_sha256: await hash(path.join(source, "Contents/MacOS/Cage")),
4648 };
4749
48删除: browser = await chromium.launch({ headless: true });
50新增: if (evidence) await fs.mkdir(evidence, { recursive: true });
51新增: browser = await chromium.launch({ headless: true, executablePath: process.env.CAGE_TEST_BROWSER_PATH });
52新增: let savedAccountHash;
4953 for (const phase of ["install", "reinstall"]) {
5054 if (phase === "reinstall") await fs.rm(installed, { recursive: true });
5155 run("ditto", [path.join(mount, "Cage.app"), installed]);
56新增: if (savedAccountHash) assert.equal(await hash(path.join(profile, "account.json")), savedAccountHash, "reinstall changed the account file");
5257 run("codesign", ["--verify", "--deep", "--strict", installed]);
5358 assert.equal(await hash(path.join(installed, "Contents/Resources/cage")), result.backend_sha256);
5459 cli("verify-web-assets");
@@ -57,12 +62,14 @@ try {
5762 const entry = JSON.parse(cli("desktop", "--json"));
5863 assert.equal(entry.status, "ready");
5964 const page = await browser.newPage();
65新增: const errors = [];
66新增: page.on("pageerror", error => errors.push(error.message));
6067 try {
6168 await page.goto(entry.url);
6269 if (phase === "install") {
63删除: await page.getByRole("button", { name: "使用用户名和密码", exact: true }).click();
70新增: await page.getByRole("heading", { name: "注册 Cage 账户", exact: true }).waitFor();
6471 await page.getByRole("checkbox", { name: /^记住我/ }).uncheck();
65删除: await page.getByLabel("用户名", { exact: true }).fill("整包验收");
72新增: await page.getByLabel("用户名", { exact: true }).fill(username);
6673 await page.getByLabel("设置密码", { exact: true }).fill(password);
6774 await page.getByLabel("确认密码", { exact: true }).fill(password);
6875 await page.getByRole("button", { name: "创建本地账户", exact: true }).click();
@@ -70,24 +77,37 @@ try {
7077 await page.getByLabel("账户密码", { exact: true }).fill(password);
7178 await page.getByRole("button", { name: "解锁 Cage", exact: true }).click();
7279 }
73删除: await page.getByRole("button", { name: "设置", exact: true }).waitFor();
80新增: await page.getByRole("heading", { name: "为 Cage 准备独立环境", exact: true }).waitFor();
81新增: assert.equal(await page.getByRole("navigation", { name: "主导航" }).count(), 0, "workbench must remain hidden before initialization");
82新增: if (evidence) await page.screenshot({ animations: "disabled", path: path.join(evidence, `${phase}-initialization.png`) });
83新增: await page.getByRole("button", { name: "下一步:配置代理", exact: true }).click();
84新增: await page.getByRole("heading", { name: "连接你的网络代理", exact: true }).waitFor();
85新增: assert.ok(await page.getByRole("button", { name: "开始安装", exact: true }).isDisabled(), "a fresh profile must require a proxy before installing");
86新增: // Do not start a VM or configure real network credentials in package-preservation QA.
87新增: await page.getByRole("button", { name: "上一步", exact: true }).click();
88新增: await page.getByRole("heading", { name: "为 Cage 准备独立环境", exact: true }).waitFor();
7489 const account = await page.evaluate(async () => {
7590 const context = await (await fetch("/api/client/context")).json();
7691 return (await fetch("/api/account", { headers: { "X-Cage-Connection": context.connection_id } })).json();
7792 });
78删除: assert.equal(account.username, "整包验收");
93新增: assert.equal(account.username, username);
7994 assert.equal(account.unlocked, true);
80删除: result[phase] = { original_account: true, preserved: await verify(qaHome, manifest) };
95新增: const status = await page.evaluate(async () => (await fetch("/api/client/local-status")).json());
96新增: assert.ok(status.known && status.service_running && !status.running, "installation QA must leave the VM stopped");
97新增: assert.deepEqual(errors, []);
98新增: result[phase] = { original_account: true, initialization_wizard: true, proxy_required: true, vm_stopped: true, preserved: await verify(qaHome, manifest) };
8199 } finally {
82100 await page.close();
83101 }
84102 cli("prepare-update", "--json");
85103 running = false;
104新增: savedAccountHash = await hash(path.join(profile, "account.json"));
86105 }
87106 const accountHash = await hash(path.join(profile, "account.json"));
88107 await fs.rm(installed, { recursive: true });
89108 assert.equal(await hash(path.join(profile, "account.json")), accountHash);
90109 result.uninstall = { account_preserved: true, preserved: await verify(qaHome, manifest) };
110新增: if (evidence) await fs.writeFile(path.join(evidence, "result.json"), JSON.stringify(result, null, 2));
91111 console.log(JSON.stringify(result, null, 2));
92112} finally {
93113 try {