跳到主要内容

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

浏览文件

0020-windows-resource-probe-ssh.patch

97 行 · 3.4 KB历史下载
1Subject: [PATCH] Open independent Windows SSH connections for resource probes
2
3diff --git a/pkg/hostagent/resources.go b/pkg/hostagent/resources.go
4index 0fc1e79..8158552 100644
5--- a/pkg/hostagent/resources.go
6+++ b/pkg/hostagent/resources.go
7@@ -8,12 +8,14 @@ import (
8 "errors"
9 "io"
10 "os/exec"
11+ "runtime"
12 "strconv"
13 "sync"
14 "time"
15
16 "github.com/lima-vm/lima/v2/pkg/driver"
17 "github.com/lima-vm/lima/v2/pkg/limatype"
18+ "github.com/lima-vm/lima/v2/pkg/sshutil"
19 )
20
21 // ManageResources is an optional embedding hook. It starts after the driver and
22@@ -33,11 +35,7 @@ func (a *HostAgent) startResourceManager(ctx context.Context) func() {
23 return func() {}
24 }
25 read := func(ctx context.Context, script string) ([]byte, error) {
26- args := append([]string{}, a.sshConfig.Args()...)
27- args = append(args, "-o", "ConnectTimeout=2", "-o", "ClearAllForwardings=yes", "-T", "-p", strconv.Itoa(a.sshLocalPort), a.instSSHAddress, "--", script)
28- cmd := exec.CommandContext(ctx, a.sshConfig.Binary(), args...)
29- hideResourceProbe(cmd)
30- cmd.WaitDelay = time.Second
31+ cmd := a.resourceProbeCommand(ctx, script)
32 pipe, err := cmd.StdoutPipe()
33 if err != nil {
34 return nil, err
35@@ -57,3 +55,16 @@ func (a *HostAgent) startResourceManager(ctx context.Context) func() {
36 var once sync.Once
37 return func() { once.Do(stop) }
38 }
39+
40+func (a *HostAgent) resourceProbeCommand(ctx context.Context, script string) *exec.Cmd {
41+ args := a.sshConfig.Args()
42+ if runtime.GOOS == "windows" {
43+ // The bundled Windows SSH client cannot run the probe over Lima's mux socket.
44+ args = sshutil.DisableControlMasterOptsFromSSHArgs(args)
45+ }
46+ args = append(args, "-o", "ConnectTimeout=2", "-o", "ClearAllForwardings=yes", "-T", "-p", strconv.Itoa(a.sshLocalPort), a.instSSHAddress, "--", script)
47+ cmd := exec.CommandContext(ctx, a.sshConfig.Binary(), args...)
48+ hideResourceProbe(cmd)
49+ cmd.WaitDelay = time.Second
50+ return cmd
51+}
52diff --git a/pkg/hostagent/resources_test.go b/pkg/hostagent/resources_test.go
53new file mode 100644
54index 0000000..30e5726
55--- /dev/null
56+++ b/pkg/hostagent/resources_test.go
57@@ -0,0 +1,40 @@
58+// SPDX-FileCopyrightText: Copyright The Lima Authors
59+// SPDX-License-Identifier: Apache-2.0
60+
61+package hostagent
62+
63+import (
64+ "context"
65+ "runtime"
66+ "slices"
67+ "testing"
68+
69+ "github.com/lima-vm/sshocker/pkg/ssh"
70+)
71+
72+func TestResourceProbeCommand(t *testing.T) {
73+ agent := HostAgent{
74+ sshLocalPort: 60022, instSSHAddress: "127.0.0.1",
75+ sshConfig: &ssh.SSHConfig{AdditionalArgs: []string{
76+ "-o", "IdentityFile=private-instance-key", "-o", "ControlMaster=auto",
77+ "-o", "ControlPath=instance/ssh.sock", "-o", "ControlPersist=5m",
78+ }},
79+ }
80+ configured := slices.Clone(agent.sshConfig.Args())
81+ const probe = "cat /proc/meminfo"
82+ cmd := agent.resourceProbeCommand(context.Background(), probe)
83+ want := slices.Clone(configured)
84+ if runtime.GOOS == "windows" {
85+ want = []string{
86+ "-o", "ControlMaster=no", "-o", "ControlPath=none", "-o", "ControlPersist=no",
87+ "-o", "IdentityFile=private-instance-key",
88+ }
89+ }
90+ want = append(want, "-o", "ConnectTimeout=2", "-o", "ClearAllForwardings=yes", "-T", "-p", "60022", "127.0.0.1", "--", probe)
91+ if !slices.Equal(cmd.Args[1:], want) {
92+ t.Fatalf("probe arguments: got %q, want %q", cmd.Args[1:], want)
93+ }
94+ if !slices.Equal(configured, agent.sshConfig.Args()) {
95+ t.Fatal("resource probe changed the SSH configuration used by other host-agent tasks")
96+ }
97+}