跳到主要内容

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

浏览文件

import.go

46 行 · 1.2 KB历史下载
1package remotehost
2
3import (
4 "os"
5 "path/filepath"
6 "reflect"
7)
8
9// ImportOnce runs under the new desktop profile's controller lock. Old
10// profiles remain independently usable. A saved empty list is authoritative.
11func (s *Store) ImportOnce(directories ...string) error {
12 s.mu.Lock()
13 defer s.mu.Unlock()
14 if _, err := os.Lstat(filepath.Join(s.profile, "remote-hosts.json")); !os.IsNotExist(err) {
15 return err
16 }
17 var merged []HostProfile
18 seen := make(map[string]HostProfile)
19 for _, directory := range directories {
20 profiles, err := NewStore(directory).List()
21 if err != nil {
22 return err
23 }
24 for _, p := range profiles {
25 if old, exists := seen[p.ID]; exists {
26 if reflect.DeepEqual(old, p) {
27 continue
28 }
29 // A divergent device binding must be trusted again. Keep both
30 // choices; do not silently change the pin of an existing host.
31 p.ID = newID()
32 p.HostKey = nil
33 p.Name = "旧入口 · " + p.Name
34 if len(p.Name) > 200 {
35 p.Name = old.Name
36 }
37 }
38 if len(merged) >= 100 {
39 return failure("profile_limit", "已有主机列表合计超过 100 项,请整理后重试;原配置已保留")
40 }
41 seen[p.ID] = p
42 merged = append(merged, p)
43 }
44 }
45 return s.write(merged)
46}