跳到主要内容

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

浏览文件

platform_windows.go

54 行 · 2.2 KB历史下载
1package workbench
2
3import (
4 "errors"
5 "os"
6 "os/exec"
7 "path/filepath"
8 "syscall"
9
10 "golang.org/x/sys/windows"
11)
12
13func lockController(f *os.File) error {
14 return windows.LockFileEx(windows.Handle(f.Fd()), windows.LOCKFILE_EXCLUSIVE_LOCK|windows.LOCKFILE_FAIL_IMMEDIATELY, 0, 1, 0, new(windows.Overlapped))
15}
16func unlockController(f *os.File) error {
17 return windows.UnlockFileEx(windows.Handle(f.Fd()), 0, 1, 0, new(windows.Overlapped))
18}
19func controllerLockContended(err error) bool { return errors.Is(err, windows.ERROR_LOCK_VIOLATION) }
20func processExists(pid int) bool {
21 if pid <= 0 {
22 return false
23 }
24 h, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid))
25 if err != nil {
26 return !errors.Is(err, windows.ERROR_INVALID_PARAMETER)
27 }
28 defer windows.CloseHandle(h)
29 var code uint32
30 return windows.GetExitCodeProcess(h, &code) != nil || code == 259
31}
32func terminateLegacy(pid int) error {
33 return errors.New("Windows 不支持接管未验证的旧版后台")
34}
35func detachController(cmd *exec.Cmd) {
36 cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true, CreationFlags: windows.CREATE_NEW_PROCESS_GROUP | windows.CREATE_NO_WINDOW}
37}
38func sshExecutable() string {
39 exe, _ := os.Executable()
40 bundled := filepath.Join(filepath.Dir(exe), "runtime", "openssh", "ssh.exe")
41 if st, err := os.Stat(bundled); err == nil && st.Mode().IsRegular() {
42 return bundled
43 }
44 // Source tests and standalone developer builds can use Windows' official
45 // optional client. Do not search a project-controlled PATH for ssh.exe.
46 return filepath.Join(os.Getenv("SystemRoot"), "System32", "OpenSSH", "ssh.exe")
47}
48func sshEnvironment() []string {
49 // OpenSSH needs Windows system directories but must not inherit keys,
50 // SSH_AUTH_SOCK, proxy settings or user-supplied SSH configuration.
51 // Win32-OpenSSH requires ProgramData before it initializes stderr.
52 return []string{"SystemRoot=" + os.Getenv("SystemRoot"), "WINDIR=" + os.Getenv("WINDIR"), "ProgramData=" + os.Getenv("ProgramData"), "TEMP=" + os.TempDir(), "TMP=" + os.TempDir(), "PATH=" + filepath.Dir(sshExecutable()), "LANG=C", "LC_ALL=C", "TERM=xterm-256color"}
53}
54func defaultKeyboard() string { return "native" }