跳到主要内容

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

浏览文件

guest-open.sh

42 行 · 1.6 KB历史下载
1#!/bin/sh
2set -eu
3case "${1:-}" in
4 --finish-login)
5 [ -n "${CAGE_CLAUDE_LOGIN:-}" ] || exit 2
6 set -- /login-finish "" "$CAGE_CLAUDE_LOGIN"
7 ;;
8 claude://*)
9 sudo -u cage /usr/local/bin/cage-claude-open "$1"
10 # Publish focus only after the running application accepted the handoff.
11 # The browser service never receives the login URL or its credentials.
12 set -- /desktop-focus
13 ;;
14 http://*|https://*|about:blank)
15 if [ -n "${CAGE_CLAUDE_LOGIN:-}" ]; then
16 set -- /login-open "$1" "$CAGE_CLAUDE_LOGIN"
17 else
18 set -- /new "$1"
19 fi
20 ;;
21 *)
22 # File operations belong to the desktop session, never the browser control
23 # token. The host resolves them only within Cage project directories.
24 exec /usr/local/bin/cage-desktop-files --open "${1:-}"
25 ;;
26esac
27# sudo records its arguments in the system journal. Send the URL on stdin.
28browser_request() {
29 # Chromium already runs as cage-browser, whose sudo rules intentionally do
30 # not allow running arbitrary commands (even as itself).
31 if [ "$(id -un)" = cage-browser ]; then
32 /usr/bin/node "$@"
33 else
34 sudo -u cage-browser /usr/bin/node "$@"
35 fi
36}
37printf '%s' "${2:-}" | browser_request --input-type=module -e '
38import {readFileSync} from "node:fs";
39const {token}=JSON.parse(readFileSync("/etc/claude-cage/browser-control.json","utf8"));
40const response=await fetch("http://127.0.0.1:18500"+process.argv[1],{method:"POST",headers:{Authorization:"Bearer "+token,"Content-Type":"application/json"},body:JSON.stringify({url:readFileSync(0,"utf8"),login:process.argv[2]})});
41if(!response.ok)process.exit(1);
42' "$1" "${3:-}"