跳到主要内容

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

提交记录
修改docs/guide/guest-systems.md+1 −1看文件
@@ -93,7 +93,7 @@ Windows 在确认系统提权后自动创建磁盘、安装系统和建立客机
9393
9494如果系统没有自动展开面板,可手动进入「General(通用)→ Login Items & Extensions(登录项与扩展)→ By Category(按类别)→ File System Extensions(文件系统扩展)」。如果进入「macFUSE Extensions」后开关点击无反应,点击 Done 返回,改用上述入口。macOS 的 By Application(按应用)入口存在开关无法启用的问题,见 [macFUSE 维护者说明](https://github.com/macfuse/macfuse/issues/1194)。
9595
96删除:这些权限都在虚拟 Mac 内确认,首次设置期间客机断网。Apple 询问管理员身份时,用户名填 `cagesetup`,密码与 Cage 账户相同;也可点选密码框后使用「填写授权密码」。设置画面的提示和操作按钮保留在客机画面之外,可以随时返回指引。启动、密码同步、读取权限或收尾失败时,引导显示具体原因与对应的重试入口。
96新增:这些权限都在虚拟 Mac 内确认,首次设置期间客机断网。Apple 询问管理员身份时,用户名填 `cagesetup`,密码与 Cage 账户相同;也可点选密码框后使用「填写授权密码」。已经允许辅助功能后,后续系统授权弹窗仍可使用该按钮;密码填入后,由你点击弹窗中的按钮确认授权。设置画面的提示和操作按钮保留在客机画面之外,可以随时返回指引。启动、密码同步、读取权限或收尾失败时,引导显示具体原因与对应的重试入口。
9797
9898系统设置收尾时,Cage 会撤销临时管理员并关闭这台客机的首次设置入口。初始化页面随后提供「连接工作区并继续检查」;需要文件夹授权时,点击「打开工作区授权」,在 Cage 显示的授权窗口中核对目录并点击 Use Project(使用项目),验证通过后继续联网检查。操作详情显示失败原因及各项检查证据;只有全部关键检查通过,才能点击「进入工作台」。
9999
新增internal/guestos/macos_password_darwin_test.go+37 −0看文件
@@ -0,0 +1,37 @@
1新增:package guestos
2新增:
3新增:import (
4新增: "os"
5新增: "os/exec"
6新增: "path/filepath"
7新增: "testing"
8新增:)
9新增:
10新增:// Exercise the shipping native password policy without granting host permissions.
11新增:func TestMacPasswordAcceptsVerifiedSettingsExtensions(t *testing.T) {
12新增: dir := t.TempDir()
13新增: harness := `import AppKit
14新增:struct Failure: Error {
15新增: let code: Int
16新增: let message: String
17新增: init(_ code: Int, _ message: String) { self.code = code; self.message = message }
18新增:}
19新增:func requireGuest() throws { throw Failure(1,"unused") }
20新增:func consoleUser() throws { throw Failure(1,"unused") }
21新增:@main struct Check {
22新增: @MainActor static func main() throws { try MacSetupPassword.selfTest() }
23新增:}
24新增:`
25新增: input := filepath.Join(dir, "check.swift")
26新增: if err := os.WriteFile(input, []byte(harness), 0600); err != nil {
27新增: t.Fatal(err)
28新增: }
29新增: program := filepath.Join(dir, "password-check")
30新增: source := filepath.Join("..", "..", "scripts", "guest-os", "macos-setup-password.swift")
31新增: if output, err := exec.CommandContext(t.Context(), "xcrun", "swiftc", "-parse-as-library", source, input, "-o", program).CombinedOutput(); err != nil {
32新增: t.Fatalf("compile password policy: %v\n%s", err, output)
33新增: }
34新增: if output, err := exec.CommandContext(t.Context(), program).CombinedOutput(); err != nil {
35新增: t.Fatalf("password policy: %v\n%s", err, output)
36新增: }
37新增:}
修改internal/guestos/macos_settings_darwin_test.go+4 −1看文件
@@ -16,7 +16,10 @@ func TestMacSettingsRoutesOpenSpecificPermissionPanes(t *testing.T) {
1616struct Failure: Error { init(_ code: Int, _ reason: String) {} }
1717func consoleUser() throws -> String { throw Failure(1,"unused") }
1818func requireGuest() throws { throw Failure(1,"unused") }
19删除:enum MacSetupPassword { static func runStream() -> Never { fatalError("unused") } }
19新增:enum MacSetupPassword {
20新增: static func runStream() -> Never { fatalError("unused") }
21新增: static func passwordFocused(_ app: NSRunningApplication, window: CGRect) -> Bool { false }
22新增:}
2023@main struct Check {
2124 @MainActor static func main() {
2225 for purpose in ["projects", "screen", "input"] {
修改scripts/guest-os/macos-maintenance.swift+1 −25看文件
@@ -48,30 +48,6 @@ enum MacMaintenance {
4848 code != nil && requirement != nil && SecCodeCheckValidity(code!, [], requirement!) == errSecSuccess
4949 }
5050
51删除: private static func passwordFocused(_ app: NSRunningApplication, window: CGRect) -> Bool {
52删除: guard let bundle = app.bundleIdentifier, applications.contains(bundle), AXIsProcessTrusted() else { return false }
53删除: let application = AXUIElementCreateApplication(app.processIdentifier)
54删除: AXUIElementSetMessagingTimeout(application, 0.5)
55删除: func attribute(_ element: AXUIElement, _ name: String) -> CFTypeRef? {
56删除: var value: CFTypeRef?
57删除: return AXUIElementCopyAttributeValue(element, name as CFString, &value) == .success ? value : nil
58删除: }
59删除: guard let value = attribute(application, kAXFocusedUIElementAttribute), CFGetTypeID(value) == AXUIElementGetTypeID() else { return false }
60删除: let field = value as! AXUIElement
61删除: var pid: pid_t = 0
62删除: guard AXUIElementGetPid(field, &pid) == .success, pid == app.processIdentifier,
63删除: attribute(field, kAXSubroleAttribute) as? String == kAXSecureTextFieldSubrole,
64删除: attribute(field, kAXEnabledAttribute) as? Bool == true,
65删除: let rawWindow = attribute(field, kAXWindowAttribute), CFGetTypeID(rawWindow) == AXUIElementGetTypeID() else { return false }
66删除: let owner = rawWindow as! AXUIElement
67删除: var origin = CGPoint.zero, size = CGSize.zero
68删除: guard let position = attribute(owner, kAXPositionAttribute), let extent = attribute(owner, kAXSizeAttribute),
69删除: CFGetTypeID(position) == AXValueGetTypeID(), CFGetTypeID(extent) == AXValueGetTypeID(),
70删除: AXValueGetValue(position as! AXValue, .cgPoint, &origin), AXValueGetValue(extent as! AXValue, .cgSize, &size) else { return false }
71删除: return abs(origin.x - window.minX) < 1 && abs(origin.y - window.minY) < 1 &&
72删除: abs(size.width - window.width) < 1 && abs(size.height - window.height) < 1
73删除: }
74删除:
7551 static func run(_ operation: String, purpose: String) throws -> [String: Any] {
7652 try requireGuest()
7753 let session = try consoleSession()
@@ -119,7 +95,7 @@ enum MacMaintenance {
11995 }
12096 return ["version": 1, "session": session, "user": NSUserName(), "pid": front.processIdentifier,
12197 "window": id, "bundle": front.bundleIdentifier!,
122删除: "password_focused": passwordFocused(front, window: bounds),
98新增: "password_focused": MacSetupPassword.passwordFocused(front, window: bounds),
12399 "rect": [region.minX, region.minY, region.width, region.height],
124100 "display": [display.minX, display.minY, display.width, display.height]]
125101 }
修改scripts/guest-os/macos-setup-password.swift+59 −9看文件
@@ -105,26 +105,63 @@ enum MacSetupPassword {
105105 return target
106106 }
107107
108删除: private static func passwordFocused(_ app: NSRunningApplication, window: CGRect) -> Bool {
108新增: static func allowsPasswordProcess(hostBundle: String, hostPID: pid_t, fieldPID: pid_t,
109新增: fieldBundle: String, appleSigned: Bool) -> Bool {
110新增: guard hostPID > 0, fieldPID > 0,
111新增: ["com.apple.systempreferences", "com.apple.authorizationhost"].contains(hostBundle) else { return false }
112新增: if fieldPID == hostPID { return true }
113新增: return hostBundle == "com.apple.systempreferences" && appleSigned &&
114新增: ["com.apple.settings.PrivacySecurity.extension", "com.apple.extensionkit.AppExtensionManagement"].contains(fieldBundle)
115新增: }
116新增:
117新增: static func passwordFocused(_ app: NSRunningApplication, window: CGRect) -> Bool {
118新增: guard let bundle = app.bundleIdentifier, AXIsProcessTrusted(),
119新增: ["com.apple.systempreferences", "com.apple.authorizationhost"].contains(bundle), signed(app, bundle: bundle) else { return false }
109120 let application = AXUIElementCreateApplication(app.processIdentifier)
110121 AXUIElementSetMessagingTimeout(application, 0.25)
111122 func attribute(_ element: AXUIElement, _ key: String) -> CFTypeRef? {
112123 var value: CFTypeRef?
113124 return AXUIElementCopyAttributeValue(element, key as CFString, &value) == .success ? value : nil
114125 }
126新增: func bounds(_ element: AXUIElement) -> CGRect? {
127新增: var origin = CGPoint.zero, size = CGSize.zero
128新增: guard let position = attribute(element, kAXPositionAttribute), let extent = attribute(element, kAXSizeAttribute),
129新增: CFGetTypeID(position) == AXValueGetTypeID(), CFGetTypeID(extent) == AXValueGetTypeID(),
130新增: AXValueGetValue(position as! AXValue, .cgPoint, &origin), AXValueGetValue(extent as! AXValue, .cgSize, &size),
131新增: [origin.x, origin.y, size.width, size.height].allSatisfy({ $0.isFinite }), size.width > 0, size.height > 0 else { return nil }
132新增: return CGRect(origin: origin, size: size)
133新增: }
134新增: func ownsTarget(_ element: AXUIElement) -> Bool {
135新增: var pid: pid_t = 0
136新增: guard AXUIElementGetPid(element, &pid) == .success, pid == app.processIdentifier,
137新增: let role = attribute(element, kAXRoleAttribute) as? String, [kAXSheetRole, kAXWindowRole].contains(role),
138新增: let rect = bounds(element) else { return false }
139新增: return abs(rect.minX - window.minX) < 1 && abs(rect.minY - window.minY) < 1 &&
140新增: abs(rect.width - window.width) < 1 && abs(rect.height - window.height) < 1
141新增: }
115142 guard let value = attribute(application, kAXFocusedUIElementAttribute), CFGetTypeID(value) == AXUIElementGetTypeID() else { return false }
116143 let field = value as! AXUIElement
144新增: AXUIElementSetMessagingTimeout(field, 0.25)
117145 var pid: pid_t = 0
118删除: guard AXUIElementGetPid(field, &pid) == .success, pid == app.processIdentifier,
146新增: guard AXUIElementGetPid(field, &pid) == .success,
119147 attribute(field, kAXSubroleAttribute) as? String == kAXSecureTextFieldSubrole,
120148 attribute(field, kAXEnabledAttribute) as? Bool == true,
121删除: let owner = attribute(field, kAXWindowAttribute), CFGetTypeID(owner) == AXUIElementGetTypeID() else { return false }
122删除: var origin = CGPoint.zero, size = CGSize.zero
123删除: guard let position = attribute(owner as! AXUIElement, kAXPositionAttribute), let extent = attribute(owner as! AXUIElement, kAXSizeAttribute),
124删除: CFGetTypeID(position) == AXValueGetTypeID(), CFGetTypeID(extent) == AXValueGetTypeID(),
125删除: AXValueGetValue(position as! AXValue, .cgPoint, &origin), AXValueGetValue(extent as! AXValue, .cgSize, &size) else { return false }
126删除: return abs(origin.x - window.minX) < 1 && abs(origin.y - window.minY) < 1 &&
127删除: abs(size.width - window.width) < 1 && abs(size.height - window.height) < 1
149新增: let fieldBounds = bounds(field), window.contains(fieldBounds) else { return false }
150新增: let owner = pid == app.processIdentifier ? app : NSRunningApplication(processIdentifier: pid)
151新增: let ownerBundle = owner?.bundleIdentifier ?? ""
152新增: guard allowsPasswordProcess(hostBundle: bundle, hostPID: app.processIdentifier, fieldPID: pid,
153新增: fieldBundle: ownerBundle, appleSigned: owner.map { signed($0, bundle: ownerBundle) } ?? false) else { return false }
154新增: // System Settings embeds Apple settings extensions. Their secure field
155新增: // can omit AXWindow; AXParent links it to the host's authorization sheet.
156新增: if let raw = attribute(field, kAXWindowAttribute), CFGetTypeID(raw) == AXUIElementGetTypeID(), ownsTarget(raw as! AXUIElement) { return true }
157新增: var ancestor = field
158新增: for _ in 0..<12 {
159新增: guard let raw = attribute(ancestor, kAXParentAttribute), CFGetTypeID(raw) == AXUIElementGetTypeID() else { return false }
160新增: ancestor = raw as! AXUIElement
161新增: AXUIElementSetMessagingTimeout(ancestor, 0.25)
162新增: if ownsTarget(ancestor) { return true }
163新增: }
164新增: return false
128165 }
129166
130167 static func probe() throws -> [String: Any] {
@@ -174,6 +211,19 @@ enum MacSetupPassword {
174211 do { try validateRequest(Data(request.utf8)); throw Failure(1, "setup_password_test_request") }
175212 catch let error as Failure where error.message == "setup_password_probe_request_invalid" { }
176213 }
214新增: // System Settings may host a secure field in its signed Apple extension.
215新增: for extensionBundle in ["com.apple.settings.PrivacySecurity.extension", "com.apple.extensionkit.AppExtensionManagement"] {
216新增: guard allowsPasswordProcess(hostBundle: "com.apple.systempreferences", hostPID: 613, fieldPID: 731,
217新增: fieldBundle: extensionBundle, appleSigned: true),
218新增: !allowsPasswordProcess(hostBundle: "com.apple.systempreferences", hostPID: 613, fieldPID: 731,
219新增: fieldBundle: extensionBundle, appleSigned: false) else { throw Failure(1, "setup_password_test_extension_signature") }
220新增: }
221新增: guard allowsPasswordProcess(hostBundle: "com.apple.authorizationhost", hostPID: 613, fieldPID: 613,
222新增: fieldBundle: "com.apple.authorizationhost", appleSigned: true),
223新增: !allowsPasswordProcess(hostBundle: "com.apple.systempreferences", hostPID: 613, fieldPID: 731,
224新增: fieldBundle: "com.apple.finder", appleSigned: true),
225新增: !allowsPasswordProcess(hostBundle: "com.apple.authorizationhost", hostPID: 613, fieldPID: 731,
226新增: fieldBundle: "com.apple.settings.PrivacySecurity.extension", appleSigned: true) else { throw Failure(1, "setup_password_test_process_binding") }
177227 let display = CGRect(x: 0, y: 0, width: 1920, height: 1200)
178228 let parent = Window(id: 38, pid: 2338, bounds: CGRect(x: 598, y: 258, width: 723, height: 625), layer: 0)
179229 let panel = Window(id: 49, pid: 2338, bounds: CGRect(x: 830, y: 376, width: 260, height: 389), layer: 0)