跳到主要内容

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

浏览文件

runtime_windows.go

80 行 · 3.0 KB历史下载
1package host
2
3import (
4 "fmt"
5 "os"
6 "os/exec"
7 "path/filepath"
8 "runtime"
9 "strings"
10 "syscall"
11 "unsafe"
12
13 "golang.org/x/sys/windows"
14)
15
16// HideCommandWindow prevents a background console child from opening a terminal.
17func HideCommandWindow(cmd *exec.Cmd) {
18 if cmd.SysProcAttr == nil {
19 cmd.SysProcAttr = &syscall.SysProcAttr{}
20 }
21 cmd.SysProcAttr.HideWindow = true
22 cmd.SysProcAttr.CreationFlags |= windows.CREATE_NO_WINDOW
23}
24
25// ConfigureWindowsRuntime uses only the runtime shipped next to cage.exe.
26// The install does not modify the user's system PATH or SSH configuration.
27func ConfigureWindowsRuntime() error {
28 // These describe an OpenSSH ancestor's private descriptors. Forwarding
29 // them through a non-OpenSSH process corrupts a new SSH client's pipes.
30 for _, name := range []string{"OPENSSH_STDIO_MODE", "c28fc6f98a2c44abbbd89d6a3037d0d9_POSIX_FD_STATE"} {
31 os.Unsetenv(name)
32 }
33 version := windows.RtlGetVersion()
34 if runtime.GOARCH != "amd64" || version.MajorVersion < 10 || version.BuildNumber < 19045 {
35 return fmt.Errorf("Cage 需要 64 位 Windows 10 22H2(19045)或 Windows 11")
36 }
37 var processMachine, nativeMachine uint16
38 if err := windows.IsWow64Process2(windows.CurrentProcess(), &processMachine, &nativeMachine); err != nil || nativeMachine != 0x8664 {
39 return fmt.Errorf("Cage Windows 版本需要 Intel 或 AMD 的 x64 处理器,暂不支持 Windows on ARM")
40 }
41 exe, err := os.Executable()
42 if err != nil {
43 return err
44 }
45 base := filepath.Join(filepath.Dir(exe), "runtime")
46 paths := []string{}
47 for _, item := range []struct{ dir, exe string }{{"qemu", "qemu-system-x86_64.exe"}, {"openssh", "ssh.exe"}} {
48 dir := filepath.Join(base, item.dir)
49 if st, err := os.Stat(filepath.Join(dir, item.exe)); err == nil && st.Mode().IsRegular() {
50 paths = append(paths, dir)
51 if item.dir == "qemu" {
52 os.Setenv("AGENT_VM_QEMU_DIR", dir)
53 } else {
54 // Shellwords parses this override; forward slashes preserve paths
55 // with spaces without interpreting Windows backslashes as escapes.
56 os.Setenv("SSH", "'"+strings.ReplaceAll(filepath.ToSlash(filepath.Join(dir, "ssh.exe")), "'", "'\\''")+"'")
57 }
58 }
59 }
60 if len(paths) > 0 {
61 paths = append(paths, os.Getenv("PATH"))
62 return os.Setenv("PATH", strings.Join(paths, string(os.PathListSeparator)))
63 }
64 return nil
65}
66
67// This capability query does not require elevation and performs no changes.
68// The desktop installer can offer the Windows Features screen separately.
69func windowsHypervisorReady() error {
70 proc := windows.NewLazySystemDLL("WinHvPlatform.dll").NewProc("WHvGetCapability")
71 if err := proc.Find(); err != nil {
72 return fmt.Errorf("请启用 Windows Hypervisor Platform(Windows 虚拟机监控程序平台)并重启后再启动环境")
73 }
74 var present, written uint32
75 result, _, _ := proc.Call(0, uintptr(unsafe.Pointer(&present)), unsafe.Sizeof(present), uintptr(unsafe.Pointer(&written)))
76 if result != 0 || written != 4 || present == 0 {
77 return fmt.Errorf("Windows 虚拟化尚未就绪:请在固件中启用 CPU 虚拟化,启用 Windows Hypervisor Platform 并重启")
78 }
79 return nil
80}