提交记录修改docs/guide/guest-systems.md+2 −2看文件
修改docs/guide/installation.md+1 −1看文件
新增internal/guestos/macos_settings_darwin_test.go+52 −0看文件
修改internal/workbench/macos_extension.go+1 −1看文件
修改internal/workbench/macos_projects.go+1 −1看文件
修改scripts/guest-os/macos-claude-window-app.swift+5 −5看文件
修改scripts/guest-os/macos-maintenance.swift+7 −3看文件
修改ui/scripts/macos-first-setup-smoke.mjs+3 −0看文件
修改ui/src/macos-first-setup.jsx+10 −3看文件
修改ui/src/macos-login.jsx+1 −1看文件
| @@ -87,9 +87,9 @@ Windows 在确认系统提权后自动创建磁盘、安装系统和建立客机 | ||
| 87 | 87 | 安装完成后,Cage 自动启动和登录虚拟 Mac,跳过可选的首次设置页面,并显示需要确认的系统权限: |
| 88 | 88 | |
| 89 | 89 | 1. 在客机的「窗口录制」「辅助功能」设置里允许 Cage Guest Window;若系统要求「退出并重新打开」,按提示完成。Cage 自动定位下一项未完成的权限,也可点击同名按钮重新打开。 |
| 90 | 删除:2. 在客机系统设置的「General(通用)→ Login Items & Extensions(登录项与扩展)」中,选择「By Category(按类别)→ File System Extensions(文件系统扩展)」,同时启用 `macFUSE` 和 `macFUSE (local)`。Cage 自动检查只读测试卷能否挂载和卸载;只打开其中一项不能完成验证。 | |
| 90 | 新增:2. Cage 自动打开「文件系统扩展」面板,打开 `macFUSE` 和 `macFUSE (local)` 两个开关即可。若页面被关闭,点击 Cage 的「文件系统扩展」按钮直接重新打开。Cage 自动检查只读测试卷能否挂载和卸载,通过后继续进入工作台;只打开其中一项不能完成验证。 | |
| 91 | 91 | |
| 92 | 删除:如果进入「macFUSE Extensions」后开关点击无反应,点击 Done 返回,切换到 By Category,再进入 File System Extensions。macOS 的 By Application(按应用)入口存在开关无法启用的问题,见 [macFUSE 维护者说明](https://github.com/macfuse/macfuse/issues/1194)。 | |
| 92 | 新增:如果系统没有自动展开面板,可手动进入「General(通用)→ Login Items & Extensions(登录项与扩展)→ By Category(按类别)→ File System Extensions(文件系统扩展)」。如果进入「macFUSE Extensions」后开关点击无反应,点击 Done 返回,改用上述入口。macOS 的 By Application(按应用)入口存在开关无法启用的问题,见 [macFUSE 维护者说明](https://github.com/macfuse/macfuse/issues/1194)。 | |
| 93 | 93 | |
| 94 | 94 | 这些权限都在虚拟 Mac 内确认,首次设置期间客机断网。Apple 询问管理员身份时,用户名填 `cagesetup`,密码与 Cage 账户相同;也可点选密码框后使用「填写授权密码」。Cage 检查三项授权后自动完成设置并进入工作台;收尾失败时提供重试入口。 |
| 95 | 95 | |
| @@ -51,7 +51,7 @@ Mac、Linux 使用默认配置时,环境数据放在用户主目录的 `.claud | ||
| 51 | 51 | 1. 点击“下一步:配置代理”,添加 Clash/Mihomo YAML 订阅、本地配置或手动 HTTP/SOCKS5 节点。详细步骤见[网络与代理](network.md)。 |
| 52 | 52 | 2. 选择最终出口,点击“应用代理”。Cage 使用独立核心,不会自动采用本机 Clash 当前所选节点。 |
| 53 | 53 | 3. 核对匹配的系统镜像、下载量和空间要求,点击“开始安装”。需要启用 Git 保护时,在初始化界面阅读影响并确认启用,再继续安装。 |
| 54 | 删除:4. 留在初始化界面查看下载、校验、系统安装和工具配置进度,完成客机首次登录和必要权限授权。失败时在原界面检查代理、查看操作详情或导出诊断,点击“继续安装”恢复。 | |
| 54 | 新增:4. 留在初始化界面查看下载、校验、系统安装和工具配置进度。macOS 客机安装后自动登录,并逐项打开需要确认的权限页面;按画面说明打开对应开关即可,「文件系统扩展」按钮会直接展开正确面板。授权通过后 Cage 自动检查并继续。失败时在原界面检查代理、查看操作详情或导出诊断,点击“继续安装”恢复。 | |
| 55 | 55 | 5. 客机可用且网络与隔离检查通过后,点击“进入工作台”。以后打开 Cage 直接进入原工作台,环境停止时可以直接启动使用。只需连接远程服务器时,初始化界面的“只连接 SSH 主机”可跳过本机安装。 |
| 56 | 56 | |
| 57 | 57 | Git 保护会修改当前主机用户的全局 `safe.bareRepository=explicit`,影响本机其他 Git 工具;普通 `.git` 项目操作不变,裸仓库需明确指定路径。只有你确认后才写入设置。 |
| @@ -0,0 +1,52 @@ | ||
| 1 | 新增:package guestos | |
| 2 | 新增: | |
| 3 | 新增:import ( | |
| 4 | 新增: "os" | |
| 5 | 新增: "os/exec" | |
| 6 | 新增: "path/filepath" | |
| 7 | 新增: "strings" | |
| 8 | 新增: "testing" | |
| 9 | 新增:) | |
| 10 | 新增: | |
| 11 | 新增:// Compile the real shared settings router without running maintenance or | |
| 12 | 新增:// touching user permissions. Both first setup and later maintenance use it. | |
| 13 | 新增:func TestMacSettingsRoutesOpenSpecificPermissionPanes(t *testing.T) { | |
| 14 | 新增: dir := t.TempDir() | |
| 15 | 新增: harness := `import AppKit | |
| 16 | 新增:struct Failure: Error { init(_ code: Int, _ reason: String) {} } | |
| 17 | 新增:func consoleUser() throws -> String { throw Failure(1,"unused") } | |
| 18 | 新增:func requireGuest() throws { throw Failure(1,"unused") } | |
| 19 | 新增:enum MacSetupPassword { static func runStream() -> Never { fatalError("unused") } } | |
| 20 | 新增:@main struct Check { | |
| 21 | 新增: @MainActor static func main() { | |
| 22 | 新增: for purpose in ["projects", "screen", "input"] { | |
| 23 | 新增: guard let url = MacMaintenance.settingsURL(for: purpose) else { exit(1) } | |
| 24 | 新增: print("\(purpose) \(url.absoluteString)") | |
| 25 | 新增: } | |
| 26 | 新增: guard MacMaintenance.settingsURL(for: "untrusted") == nil else { exit(2) } | |
| 27 | 新增: } | |
| 28 | 新增:} | |
| 29 | 新增:` | |
| 30 | 新增: input := filepath.Join(dir, "check.swift") | |
| 31 | 新增: if err := os.WriteFile(input, []byte(harness), 0600); err != nil { | |
| 32 | 新增: t.Fatal(err) | |
| 33 | 新增: } | |
| 34 | 新增: program := filepath.Join(dir, "settings-check") | |
| 35 | 新增: source := filepath.Join("..", "..", "scripts", "guest-os", "macos-maintenance.swift") | |
| 36 | 新增: compile := exec.CommandContext(t.Context(), "xcrun", "swiftc", "-parse-as-library", source, input, "-o", program) | |
| 37 | 新增: if output, err := compile.CombinedOutput(); err != nil { | |
| 38 | 新增: t.Fatalf("compile settings router: %v\n%s", err, output) | |
| 39 | 新增: } | |
| 40 | 新增: output, err := exec.CommandContext(t.Context(), program).CombinedOutput() | |
| 41 | 新增: if err != nil { | |
| 42 | 新增: t.Fatalf("settings routes: %v\n%s", err, output) | |
| 43 | 新增: } | |
| 44 | 新增: want := []string{ | |
| 45 | 新增: "projects x-apple.systempreferences:com.apple.ExtensionsPreferences?extensionPointIdentifier=com.apple.fskit.fsmodule", | |
| 46 | 新增: "screen x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture", | |
| 47 | 新增: "input x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility", | |
| 48 | 新增: } | |
| 49 | 新增: if strings.TrimSpace(string(output)) != strings.Join(want, "\n") { | |
| 50 | 新增: t.Fatalf("permission routes lost the specific destination: %s", output) | |
| 51 | 新增: } | |
| 52 | 新增:} | |
| @@ -25,7 +25,7 @@ func (s *Server) checkMacOSSetupProjects(parent context.Context) error { | ||
| 25 | 25 | } |
| 26 | 26 | s.mu.Unlock() |
| 27 | 27 | if err != nil { |
| 28 | 删除: return errors.New("尚未能挂载并卸载只读测试卷。请在客机设置的 By Category(按类别)→ File System Extensions(文件系统扩展)中启用 macFUSE 和 macFUSE (local),再点验证") | |
| 28 | 新增: return errors.New("文件共享权限尚未通过。请点击「文件系统扩展」重新打开授权面板,确认 macFUSE 和 macFUSE (local) 两个开关均已打开,Cage 会自动检查") | |
| 29 | 29 | } |
| 30 | 30 | return nil |
| 31 | 31 | } |
| @@ -182,7 +182,7 @@ func (s *Server) probeMacOSProject(ctx context.Context, hostDir, guestDir string | ||
| 182 | 182 | message := string(share.stderr.data) |
| 183 | 183 | _ = diagnostics.New(s.profile).Record("warn", "macos-project-mount", message) |
| 184 | 184 | if strings.Contains(strings.ToLower(message), "not enabled") { |
| 185 | 删除: return &projectShareError{Recovery: "filesystem-permission", Message: "虚拟 Mac 的文件系统扩展尚未启用。请在客机设置的 By Category(按类别)→ File System Extensions(文件系统扩展)中同时启用 macFUSE 和 macFUSE (local),然后重新连接项目。"} | |
| 185 | 新增: return &projectShareError{Recovery: "filesystem-permission", Message: "虚拟 Mac 的文件系统扩展尚未启用。请打开客机授权设置,按提示打开 macFUSE 和 macFUSE (local) 两个开关,Cage 会自动检查并重新连接项目。"} | |
| 186 | 186 | } |
| 187 | 187 | } |
| 188 | 188 | return &projectShareError{Recovery: "project-retry", Message: "客机文件共享连接已中断。Cage 会自动重试,持续失败时可查看诊断记录。"} |
| @@ -258,22 +258,22 @@ private func handle(_ input: Request, inputSession: MacWindowInputSession) async | ||
| 258 | 258 | case "setup-password-focus": |
| 259 | 259 | return try MacSetupPassword.probe() |
| 260 | 260 | case "setup-screen", "setup-input", "setup-projects": |
| 261 | 删除: let pane: String | |
| 261 | 新增: let purpose: String | |
| 262 | 262 | if input.action == "setup-screen" { |
| 263 | 263 | if !CGPreflightScreenCaptureAccess() { _ = CGRequestScreenCaptureAccess() } |
| 264 | 删除: pane = "com.apple.preference.security?Privacy_ScreenCapture" | |
| 264 | 新增: purpose = "screen" | |
| 265 | 265 | } else if input.action == "setup-input" { |
| 266 | 266 | let options = [kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String: true] as CFDictionary |
| 267 | 267 | _ = AXIsProcessTrustedWithOptions(options) |
| 268 | 删除: pane = "com.apple.preference.security?Privacy_Accessibility" | |
| 268 | 新增: purpose = "input" | |
| 269 | 269 | } else { |
| 270 | 270 | let vendor = URL(fileURLWithPath: "/Applications/macFUSE.app") |
| 271 | 271 | let configuration = NSWorkspace.OpenConfiguration() |
| 272 | 272 | configuration.activates = false |
| 273 | 273 | _ = try await NSWorkspace.shared.openApplication(at: vendor, configuration: configuration) |
| 274 | 删除: pane = "com.apple.LoginItems-Settings.extension" | |
| 274 | 新增: purpose = "projects" | |
| 275 | 275 | } |
| 276 | 删除: guard let url = URL(string: "x-apple.systempreferences:" + pane), NSWorkspace.shared.open(url) else { throw Failure(7, "settings_unavailable") } | |
| 276 | 新增: guard let url = MacMaintenance.settingsURL(for: purpose), NSWorkspace.shared.open(url) else { throw Failure(7, "settings_unavailable") } | |
| 277 | 277 | return ["ok":true] |
| 278 | 278 | case "status": |
| 279 | 279 | let installed = FileManager.default.fileExists(atPath: appURL.path) |
| @@ -8,11 +8,15 @@ import Security | ||
| 8 | 8 | enum MacMaintenance { |
| 9 | 9 | private static let applications: Set<String> = ["com.apple.systempreferences", "com.apple.authorizationhost"] |
| 10 | 10 | private static let panes = [ |
| 11 | 删除: "projects": "x-apple.systempreferences:com.apple.LoginItems-Settings.extension", | |
| 11 | 新增: "projects": "x-apple.systempreferences:com.apple.ExtensionsPreferences?extensionPointIdentifier=com.apple.fskit.fsmodule", | |
| 12 | 12 | "screen": "x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture", |
| 13 | 13 | "input": "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility", |
| 14 | 14 | ] |
| 15 | 15 | |
| 16 | 新增: static func settingsURL(for purpose: String) -> URL? { | |
| 17 | 新增: panes[purpose].flatMap { URL(string: $0) } | |
| 18 | 新增: } | |
| 19 | 新增: | |
| 16 | 20 | static func runPasswordProbe(purpose: String) -> Never { |
| 17 | 21 | guard panes[purpose] != nil else { exit(2) } |
| 18 | 22 | MacSetupPassword.runStream() |
| @@ -71,14 +75,14 @@ enum MacMaintenance { | ||
| 71 | 75 | static func run(_ operation: String, purpose: String) throws -> [String: Any] { |
| 72 | 76 | try requireGuest() |
| 73 | 77 | let session = try consoleSession() |
| 74 | 删除: guard let pane = panes[purpose] else { throw Failure(8, "maintenance_purpose_invalid") } | |
| 78 | 新增: guard let url = settingsURL(for: purpose) else { throw Failure(8, "maintenance_purpose_invalid") } | |
| 75 | 79 | if operation == "open" { |
| 76 | 80 | if purpose == "projects" { |
| 77 | 81 | let configuration = NSWorkspace.OpenConfiguration() |
| 78 | 82 | configuration.activates = false |
| 79 | 83 | NSWorkspace.shared.openApplication(at: URL(fileURLWithPath: "/Applications/macFUSE.app"), configuration: configuration) |
| 80 | 84 | } |
| 81 | 删除: guard let url = URL(string: pane), NSWorkspace.shared.open(url) else { throw Failure(8, "maintenance_open_failed") } | |
| 85 | 新增: guard NSWorkspace.shared.open(url) else { throw Failure(8, "maintenance_open_failed") } | |
| 82 | 86 | return ["opened": true] |
| 83 | 87 | } |
| 84 | 88 | guard operation == "probe", let front = NSWorkspace.shared.frontmostApplication, verified(front) else { |
| @@ -49,6 +49,7 @@ for (const failure of ["http", "native"]) { | ||
| 49 | 49 | try { |
| 50 | 50 | await page.getByRole("dialog",{name:"首次设置虚拟 Mac"}).waitFor(); |
| 51 | 51 | await waitCall("screen"); |
| 52 | 新增: await page.getByText(/打开 Cage Guest Window 的窗口录制开关/).waitFor(); | |
| 52 | 53 | const image = page.getByRole("dialog",{name:"首次设置虚拟 Mac"}).getByRole("img"); |
| 53 | 54 | await image.waitFor(); |
| 54 | 55 | const box = await image.boundingBox(); |
| @@ -60,8 +61,10 @@ for (const failure of ["http", "native"]) { | ||
| 60 | 61 | await waitCall("fill-password"); |
| 61 | 62 | permissions.screen=true; |
| 62 | 63 | await waitCall("input"); |
| 64 | 新增: await page.getByText(/打开 Cage Guest Window 的辅助功能开关/).waitFor(); | |
| 63 | 65 | permissions.input=true; |
| 64 | 66 | await waitCall("projects"); |
| 67 | 新增: await page.getByText(/打开 macFUSE 和 macFUSE \(local\) 两个开关,用于/).waitFor(); | |
| 65 | 68 | assert.ok(!calls.includes("finish"),"finished before filesystem permission"); |
| 66 | 69 | permissions.projects=true; |
| 67 | 70 | await page.getByRole("button",{name:"返回设置指引"}).click(); |
| @@ -8,7 +8,7 @@ const steps = [["screen", "窗口录制"], ["input", "辅助功能"], ["projects | ||
| 8 | 8 | |
| 9 | 9 | export function MacOSFirstSetup() { |
| 10 | 10 | const { account, refresh } = useAccount(); |
| 11 | 删除: const loginName = account?.macos_guest_user || "cage"; | |
| 11 | 新增: const [permissionPage, setPermissionPage] = useState("screen"); | |
| 12 | 12 | const [state, setState] = useState(null); |
| 13 | 13 | const [permissions, setPermissions] = useState({}); |
| 14 | 14 | const [error, setError] = useState(""); |
| @@ -38,6 +38,7 @@ export function MacOSFirstSetup() { | ||
| 38 | 38 | const pending = steps.find(([id]) => !measured[id]); |
| 39 | 39 | if (active && measured.managed_credential && pending && requested.current !== pending[0]) { |
| 40 | 40 | requested.current = pending[0]; |
| 41 | 新增: setPermissionPage(pending[0]); | |
| 41 | 42 | try { await api("/macos/first-setup",{action:pending[0]}); } |
| 42 | 43 | catch (e) { if (active) setError(e.message); } |
| 43 | 44 | } |
| @@ -65,6 +66,7 @@ export function MacOSFirstSetup() { | ||
| 65 | 66 | }, []); |
| 66 | 67 | async function act(action) { |
| 67 | 68 | if (busy) return; |
| 69 | 新增: if (steps.some(([id]) => id === action)) setPermissionPage(action); | |
| 68 | 70 | setBusy(true); setError(""); |
| 69 | 71 | try { |
| 70 | 72 | if (action === "start") await api("/start", {guest_system:"macos"}); |
| @@ -82,6 +84,11 @@ export function MacOSFirstSetup() { | ||
| 82 | 84 | const controls = <>{steps.map(([id, label]) => <button key={id} disabled={busy || !state?.ready} |
| 83 | 85 | onClick={() => act(id)}>{label}{permissions[id] && " ✓"}</button>)} |
| 84 | 86 | </>; |
| 87 | 新增: const permissionHint = { | |
| 88 | 新增: screen: "打开 Cage Guest Window 的窗口录制开关。如果提示「退出并重新打开」,按提示操作。", | |
| 89 | 新增: input: "打开 Cage Guest Window 的辅助功能开关,允许 Cage 操作客机窗口。", | |
| 90 | 新增: projects: "打开 macFUSE 和 macFUSE (local) 两个开关,用于在客机中访问你选择的项目。", | |
| 91 | 新增: }[permissionPage]; | |
| 85 | 92 | const progress = !state?.ready ? "正在等待虚拟 Mac 就绪;启动后再打开客机系统设置。" : |
| 86 | 93 | steps.every(([id]) => permissions[id]) ? completionFailed ? "授权已通过,请点击重试完成设置。" : "授权已通过,正在进入工作台…" : |
| 87 | 94 | `请确认:${steps.filter(([id]) => !permissions[id]).map(([, label]) => label).join("、")}。Cage 会自动检查并继续。`; |
| @@ -90,12 +97,12 @@ export function MacOSFirstSetup() { | ||
| 90 | 97 | <p>Cage 会自动登录、配置并检查环境。首次使用只需确认下面的系统权限;这些操作都在虚拟 Mac 内完成。</p> |
| 91 | 98 | <ol> |
| 92 | 99 | <li>在 Cage 打开的「窗口录制」「辅助功能」设置里允许 <strong>Cage Guest Window</strong>。如果提示「退出并重新打开」,按提示操作。需要重新定位时,点击同名按钮。</li> |
| 93 | 删除: <li>点击「文件系统扩展」,在客机设置中选择 <strong>By Category(按类别)→ File System Extensions(文件系统扩展)</strong>,同时打开 <strong>macFUSE</strong> 和 <strong>macFUSE (local)</strong>。Cage 会自动验证并进入工作台。</li> | |
| 100 | 新增: <li>Cage 会直接打开「文件系统扩展」面板,你只需打开 <strong>macFUSE</strong> 和 <strong>macFUSE (local)</strong> 两个开关。需要重新打开页面时,点击「文件系统扩展」。完成后 Cage 会自动检查并进入工作台。</li> | |
| 94 | 101 | </ol> |
| 95 | 102 | <p>授权时若要求管理员,用户名填 <strong>cagesetup</strong>,{account.macos_password_pending ? "密码正在等待同步,完成前可能仍需原客机密码。" : account.macos_credentials_ready ? "密码与 Cage 账户相同。" : "可点选系统密码框后点击「填写授权密码」。"}确认后继续授权。此管理员在完成后自动停用。</p> |
| 96 | 103 | {(!state?.vm_running || account.macos_password_pending) && <button className="primary" disabled={busy || !state || state.job?.running} onClick={() => act("start")}>{account.macos_password_pending ? "重试同步客机密码" : "启动虚拟 Mac"}</button>} |
| 97 | 104 | {state?.vm_running && <MacOSLogin initialSetup autoOpen={Boolean(permissions.managed_credential)} managedCredential={permissions.managed_credential} disabled={!state.ready} setupActions={controls} |
| 98 | 删除: setupHint={`Cage 自动登录 ${loginName}。管理员授权用 cagesetup。文件系统扩展请从 By Category(按类别)→ File System Extensions 进入,打开两个 macFUSE 开关。`} | |
| 105 | 新增: setupHint={`${permissionHint} 需要管理员授权时,用户名用 cagesetup;选中密码框后可点击「填写授权密码」。`} | |
| 99 | 106 | setupStatus={error || progress} setupError={Boolean(error)} />} |
| 100 | 107 | <div className="welcome-shortcuts">{controls}</div> |
| 101 | 108 | <p role="status">{progress}</p> |
| @@ -341,7 +341,7 @@ export function MacOSLogin({ disabled, initialSetup = false, maintenance = "", l | ||
| 341 | 341 | {authorizationPassword && <span className="mac-login-password">{authorizationPassword}<button onClick={() => setAuthorizationPassword("")}>隐藏</button></span>} |
| 342 | 342 | </div> |
| 343 | 343 | {maintenance && <div className="mac-setup-hint"> |
| 344 | 删除: {maintenance === "projects" && <p>在客机设置中选择 By Category(按类别)→ File System Extensions(文件系统扩展),同时启用 macFUSE 和 macFUSE (local)。授权后 Cage 会自动检查并重新连接项目。</p>} | |
| 344 | 新增: {maintenance === "projects" && <p>Cage 会直接打开「文件系统扩展」面板。打开 macFUSE 和 macFUSE (local) 两个开关,Cage 会自动检查并重新连接项目。</p>} | |
| 345 | 345 | {administrator && <p>系统要求管理员时,用户名填写 {administrator}。选中系统授权窗口的密码框后,点击「填写管理员密码」,再由你确认授权。</p>} |
| 346 | 346 | {administrator && <button type="button" onClick={() => enqueue("fill-password", {})}>填写管理员密码</button>} |
| 347 | 347 | </div>} |

