| 1 | package workbench |
| 2 | |
| 3 | import ( |
| 4 | "path" |
| 5 | |
| 6 | "al.essio.dev/pkg/shellescape" |
| 7 | ) |
| 8 | |
| 9 | const macCLIInstall = "/usr/local/libexec/cage-cli" |
| 10 | |
| 11 | const macOSLegacyWorkspaceNotice = "此历史会话仍使用原来的客机目录,文件保留在虚拟 Mac 内。要使用与主机共享的默认工作区,请从默认工作区新建会话。" |
| 12 | |
| 13 | |
| 14 | |
| 15 | func (s *Server) macOSLegacyWorkspace(record *mobileRecord) string { |
| 16 | if s.macosGuest == nil || record == nil || !record.Terminal || record.Workspace != s.environmentDir() { |
| 17 | return "" |
| 18 | } |
| 19 | root := path.Join("/Users", s.macosGuest.User, ".local/share/cage/workspace") |
| 20 | if record.GuestWorkspace != path.Clean(record.GuestWorkspace) || !cliWorkspaceWithin(record.GuestWorkspace, root, false) { |
| 21 | return "" |
| 22 | } |
| 23 | return root |
| 24 | } |
| 25 | |
| 26 | func (s *Server) cliWorkspace(workspace string) string { |
| 27 | if s.macosGuest == nil { |
| 28 | return guestPath(workspace) |
| 29 | } |
| 30 | return macOSProjectPath(s.macosGuest.User, workspace) |
| 31 | } |
| 32 | |
| 33 | func (s *Server) cliHelperCommand(mode, argument string) string { |
| 34 | if s.macosGuest == nil { |
| 35 | return cliChannelCommand(mode, argument) |
| 36 | } |
| 37 | return shellescape.QuoteCommand([]string{macCLIInstall + "/bin/python3", "-I", macCLIInstall + "/macos-cli.py", mode, argument}) |
| 38 | } |
| 39 | |
| 40 | func (s *Server) macOSClaudeLaunch(workspace, payload string) string { |
| 41 | |
| 42 | |
| 43 | return "exec " + shellescape.QuoteCommand([]string{"/usr/local/libexec/cage-macos-terminal", "--claude", s.cliWorkspace(workspace), payload}) |
| 44 | } |