跳到主要内容

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

浏览文件

register-macos-claude-window.sh

53 行 · 2.4 KB历史下载
1#!/bin/bash
2# Run once as the intended guest GUI user after installing the signed helper.
3set -euo pipefail
4export PATH=/usr/bin:/bin:/usr/sbin:/sbin
5[[ $(sysctl -n hw.model) =~ ^VirtualMac[0-9]+,[0-9]+$ && $(cat /var/db/cage-guest-os) == macos ]] || exit 2
6[[ $# == 0 || ( $# == 1 && $1 == --prepare ) ]] || exit 2
7uid=$(id -u)
8[[ $uid -ge 500 && ( ${1:-} == --prepare || $(stat -f %u /dev/console) == "$uid" ) ]] || { echo 'Log into the guest as the intended desktop user.' >&2; exit 4; }
9app='/Applications/Cage Guest Window.app'
10codesign --verify --strict -R '=identifier "dev.cage.GuestClaudeWindow"' "$app"
11label=dev.cage.GuestClaudeWindow
12cache="$HOME/Library/Caches/$label"
13agent="$HOME/Library/LaunchAgents/$label.plist"
14executable="$app/Contents/MacOS/CageGuestWindow"
15umask 077
16mkdir -p "$HOME/Library/LaunchAgents" "$cache"
17[[ ! -L $cache && $(stat -f %u "$cache") == "$uid" ]] || exit 2
18chmod 700 "$cache"
19temp=$(mktemp "$cache/plist.XXXXXXXX")
20legacy=$(mktemp "$cache/plist-legacy.XXXXXXXX")
21trap 'rm -f "$temp" "$legacy"' EXIT
22plutil -create xml1 "$temp"
23plutil -insert Label -string "$label" "$temp"
24plutil -insert ProgramArguments -xml '<array/>' "$temp"
25plutil -insert ProgramArguments.0 -string "$executable" "$temp"
26plutil -insert LimitLoadToSessionType -string Aqua "$temp"
27plutil -insert Sockets -xml '<dict><key>Window</key><dict/></dict>' "$temp"
28plutil -insert Sockets.Window.SockPathName -string "$cache/window.sock" "$temp"
29plutil -insert Sockets.Window.SockPathMode -integer 384 "$temp"
30cp "$temp" "$legacy"
31# LaunchServices delivers file-open events to the same GUI process as the
32# socket service. Keep that process alive before the first remote request.
33plutil -insert RunAtLoad -bool true "$temp"
34plutil -insert KeepAlive -bool true "$temp"
35changed=0
36if [[ -e $agent || -L $agent ]]; then
37 [[ -f $agent && ! -L $agent && $(stat -f %u "$agent") == "$uid" ]] || exit 2
38 if ! cmp -s "$agent" "$temp"; then
39 if ! cmp -s "$agent" "$legacy"; then
40 echo 'An existing LaunchAgent has different settings.' >&2
41 exit 2
42 fi
43 changed=1
44 fi
45fi
46if [[ ${1:-} != --prepare && $changed == 1 ]] && launchctl print "gui/$uid/$label" >/dev/null 2>&1; then
47 launchctl bootout "gui/$uid/$label"
48fi
49mv -f "$temp" "$agent"
50[[ ${1:-} == --prepare ]] && exit 0
51if ! launchctl print "gui/$uid/$label" >/dev/null 2>&1; then
52 launchctl bootstrap "gui/$uid" "$agent"
53fi