跳到主要内容

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

浏览文件

desktop_import.go

78 行 · 2.0 KB历史下载
1package workbench
2
3import (
4 "errors"
5 "os"
6 "path/filepath"
7 "strings"
8
9 "github.com/sylvinus/agent-vm/internal/host"
10 "github.com/sylvinus/agent-vm/internal/remotehost"
11)
12
13func importDesktopConnections(full, entry string) error {
14 old := []string{full, filepath.Join(full, "client")}
15 if err := remotehost.NewStore(entry).ImportOnce(old...); err != nil {
16 return err
17 }
18 marker := filepath.Join(entry, "downloads-imported.json")
19 if err := host.CheckPrivateFile(marker); err == nil {
20 return nil
21 } else if !os.IsNotExist(err) {
22 return err
23 }
24 // Import private records only, never copy a downloaded file or follow a
25 // saved user path. A retry after interruption preserves the newest record.
26 for _, profile := range old {
27 root := filepath.Join(profile, "remote-downloads")
28 info, err := os.Lstat(root)
29 if os.IsNotExist(err) {
30 continue
31 }
32 if err != nil {
33 return err
34 }
35 if !info.IsDir() {
36 return errors.New("旧入口下载记录目录无效")
37 }
38 instances, err := os.ReadDir(root)
39 if err != nil {
40 return err
41 }
42 for _, instance := range instances {
43 if !instance.IsDir() || !remoteInstanceID.MatchString(instance.Name()) {
44 continue
45 }
46 from := filepath.Join(root, instance.Name())
47 files, err := os.ReadDir(filepath.Join(from, "browser-downloads"))
48 if os.IsNotExist(err) {
49 continue
50 }
51 if err != nil {
52 return err
53 }
54 to := filepath.Join(entry, "remote-downloads", instance.Name())
55 for _, file := range files {
56 id := strings.TrimSuffix(file.Name(), ".json")
57 if !file.Type().IsRegular() || !browserFileID.MatchString(id) {
58 continue
59 }
60 record, err := readSavedDownload(from, id)
61 if err != nil || record.InstanceID != instance.Name() {
62 continue
63 }
64 current, err := readSavedDownload(to, id)
65 if err == nil && !record.SavedAt.After(current.SavedAt) {
66 continue
67 }
68 if err != nil && !os.IsNotExist(err) {
69 return err
70 }
71 if err = writePrivate(savedDownloadPath(to, id), record); err != nil {
72 return err
73 }
74 }
75 }
76 }
77 return writePrivate(marker, struct{}{})
78}