跳到主要内容

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

浏览文件

storage_paths.go

84 行 · 2.4 KB历史下载
1package workbench
2
3import (
4 "errors"
5 "os"
6 "path/filepath"
7
8 "github.com/sylvinus/agent-vm/internal/cage"
9 "github.com/sylvinus/agent-vm/internal/guestos"
10 "github.com/sylvinus/agent-vm/internal/mounts"
11 "github.com/sylvinus/agent-vm/internal/paths"
12)
13
14func (s *Server) validateStoragePlacement(directory string) error {
15 target, err := cage.StoragePhysicalPath(directory)
16 if err != nil {
17 return err
18 }
19 projects, err := s.projectPaths()
20 if err != nil {
21 return err
22 }
23 for _, project := range projects {
24 physical, err := cage.StoragePhysicalPath(project)
25 if err != nil {
26 return err
27 }
28 if cage.StoragePathsOverlap(physical, target) {
29 return errors.New("环境存储目录与已共享的项目重叠,请选择项目以外的专用文件夹")
30 }
31 }
32 return nil
33}
34
35// Resolve both sides of the sharing boundary. A profile or retained backup
36// can be reached through a Windows junction even if its saved path looks
37// unrelated to the requested project.
38func privateProjectDirectories(profile string) ([]string, error) {
39 directories, err := cage.StoragePrivatePaths(profile)
40 if err != nil {
41 return nil, err
42 }
43 directories = append(directories, profile)
44 directories = append(directories, guestos.WindowsPrivateStoragePaths()...)
45 for _, directory := range directories {
46 physical, err := cage.StoragePhysicalPath(directory)
47 if os.IsNotExist(err) {
48 // A detached backup drive still reserves its recorded location.
49 continue
50 }
51 if err != nil {
52 return nil, err
53 }
54 if !paths.Equal(physical, directory) {
55 directories = append(directories, physical)
56 }
57 }
58 return directories, nil
59}
60
61func validateHostProjectData(root, profile string) error {
62 home, err := os.UserHomeDir()
63 if err != nil {
64 return err
65 }
66 defaultProfile := filepath.Join(home, ".claude-cage")
67 // Independent profiles also protect disks and backups of the default workload.
68 if !paths.Equal(profile, defaultProfile) {
69 private, err := privateProjectDirectories(defaultProfile)
70 if err != nil {
71 return err
72 }
73 for _, dir := range private {
74 if cage.StoragePathsOverlap(root, dir) {
75 return errors.New("Cage 配置、环境存储及备份不能共享")
76 }
77 }
78 }
79 refs := mounts.Refs(paths.Host(home), "", paths.Host(defaultProfile))
80 if _, unsafe := mounts.UnsafeProject(paths.Host(root), refs); unsafe {
81 return errors.New("此目录包含或属于凭据、用户资料或版本控制数据,无法共享")
82 }
83 return nil
84}