跳到主要内容

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

浏览文件

instance.go

48 行 · 1.6 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package driverutil
5
6import (
7 "context"
8 "fmt"
9
10 "github.com/sirupsen/logrus"
11
12 "github.com/lima-vm/lima/v2/pkg/driver"
13 "github.com/lima-vm/lima/v2/pkg/driver/external/server"
14 "github.com/lima-vm/lima/v2/pkg/limatype"
15 "github.com/lima-vm/lima/v2/pkg/registry"
16)
17
18// CreateConfiguredDriver creates a driver.ConfiguredDriver for the given instance.
19// For external drivers, it reuses an existing server if one is already running,
20// or starts a new one if needed.
21func CreateConfiguredDriver(ctx context.Context, inst *limatype.Instance, sshLocalPort int) (*driver.ConfiguredDriver, error) {
22 limaDriver := inst.Config.VMType
23 extDriver, intDriver, exists := registry.Get(*limaDriver)
24 if !exists {
25 return nil, fmt.Errorf("unknown or unsupported VM type: %s", *limaDriver)
26 }
27 var driverInfo driver.Info
28 if extDriver != nil {
29 extDriver.Logger.Debugf("Connecting to external driver %#q for %#q", extDriver.Name, inst.Name)
30 if err := server.Start(ctx, extDriver, inst.Name); err != nil {
31 extDriver.Logger.Errorf("Failed to start external driver %#q: %v", extDriver.Name, err)
32 return nil, err
33 }
34
35 driverInfo = extDriver.Client.Info(ctx)
36 if !driverInfo.Features.StaticSSHPort {
37 inst.SSHLocalPort = sshLocalPort
38 }
39 return extDriver.Client.Configure(ctx, inst)
40 }
41
42 driverInfo = intDriver.Info(ctx)
43 logrus.Debugf("Using internal driver %q", driverInfo.Name)
44 if !driverInfo.Features.StaticSSHPort {
45 inst.SSHLocalPort = sshLocalPort
46 }
47 return intDriver.Configure(ctx, inst)
48}