跳到主要内容

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

浏览文件

main.go

68 行 · 2.1 KB历史下载
1// Command harness runs sshocker's builtin rooted SFTP server (the one the Lima
2// hostagent runs in-process for agent-vm shares) outside of Lima.
3//
4// harness mount <hostdir> <mountpoint> [extra sshfs args...]
5// sshfs -o slave <mountpoint>, served by the rooted server, with Lima's options.
6// harness stdio <hostdir>
7// the rooted server on stdin/stdout, for raw SFTP clients.
8//
9// readonlyNames is .git and .hg, as agent-vm sets it. A panic in the server
10// exits the process with Go's stack trace on stderr, as it would kill the hostagent.
11package main
12
13import (
14 "fmt"
15 "io"
16 "os"
17 "os/exec"
18
19 "github.com/lima-vm/sshocker/pkg/reversesshfs"
20 "github.com/lima-vm/sshocker/pkg/util"
21)
22
23var readonlyNames = []string{".git", ".hg"}
24
25func main() {
26 if len(os.Args) < 3 {
27 fmt.Fprintln(os.Stderr, "usage: harness mount <hostdir> <mountpoint> [sshfs args...] | harness stdio <hostdir>")
28 os.Exit(2)
29 }
30 switch os.Args[1] {
31 case "mount":
32 mount(os.Args[2], os.Args[3], os.Args[4:])
33 case "stdio":
34 serve(&util.RWC{ReadCloser: os.Stdin, WriteCloser: os.Stdout}, os.Args[2])
35 default:
36 os.Exit(2)
37 }
38}
39
40func mount(hostDir, mnt string, extra []string) {
41 // Lima: "-o slave" from sshocker, "allow_other" from the hostagent (cache and
42 // follow_symlinks at Lima's defaults), "no_contain_symlinks" from agent-vm's wrapper.
43 args := append([]string{":" + hostDir, mnt, "-o", "slave", "-o", "allow_other", "-o", "no_contain_symlinks", "-f"}, extra...)
44 cmd := exec.Command("sshfs", args...)
45 cmd.Stderr = os.Stderr
46 in, err := cmd.StdinPipe()
47 if err != nil {
48 panic(err)
49 }
50 out, err := cmd.StdoutPipe()
51 if err != nil {
52 panic(err)
53 }
54 if err := cmd.Start(); err != nil {
55 panic(err)
56 }
57 fmt.Fprintf(os.Stderr, "harness: serving %s on %s (pid %d)\n", hostDir, mnt, os.Getpid())
58 serve(&util.RWC{ReadCloser: out, WriteCloser: in}, hostDir)
59 _ = cmd.Process.Kill()
60}
61
62func serve(rwc io.ReadWriteCloser, hostDir string) {
63 srv, err := reversesshfs.HarnessServer(rwc, hostDir, readonlyNames)
64 if err != nil {
65 panic(err)
66 }
67 fmt.Fprintln(os.Stderr, "harness: Serve returned:", srv.Serve())
68}