跳到主要内容

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

提交记录
修改internal/workbench/macos_workspace_test.go+58 −0看文件
@@ -6,10 +6,12 @@ import (
66 "crypto/rand"
77 "encoding/json"
88 "encoding/pem"
9新增: "errors"
910 "fmt"
1011 "io"
1112 "net"
1213 "net/http"
14新增: "net/http/httptest"
1315 "os"
1416 "path"
1517 "path/filepath"
@@ -180,6 +182,8 @@ func (g *macWorkspaceGuest) execute(channel ssh.Channel, command string) uint32
180182 json.NewEncoder(channel).Encode(macOSResourceSample{Version: 1, Total: 4 << 30, Available: 2 << 30,
181183 Free: 1 << 30, Inactive: 1 << 30, CPUs: 2, Boot: 10, CPUTicks: [4]uint32{ticks, 10, 80 + ticks, 0}})
182184 return 0
185新增: case command == "/usr/bin/open -a /Applications/CageProjectAccess.app":
186新增: return 0
183187 case strings.HasPrefix(command, "set -e;"):
184188 return 0
185189 case strings.HasPrefix(command, "exec /usr/local/libexec/cage-sshfs "):
@@ -442,3 +446,57 @@ func TestMacOSDefaultWorkspaceNewAndLegacyConversations(t *testing.T) {
442446 }
443447 }
444448}
449新增:
450新增:func TestMacOSProjectOpenRestoresPendingApprovalWindow(t *testing.T) {
451新增: var activations atomic.Int32
452新增: var activationFails atomic.Bool
453新增: guest := newMacWorkspaceGuest(t, func(channel ssh.Channel, command string) (uint32, bool) {
454新增: if strings.Contains(command, "/usr/bin/open -a /Applications/CageProjectAccess.app") {
455新增: activations.Add(1)
456新增: if activationFails.Load() {
457新增: return 1, true
458新增: }
459新增: return 0, true
460新增: }
461新增: return 0, false
462新增: })
463新增: s := guest.s
464新增: s.restoreProjectShares()
465新增: share := s.projectShares[guest.hostPath]
466新增: if share == nil || share.approval == "" {
467新增: t.Fatal("expected a pending project authorization")
468新增: }
469新增: grant := share.approval
470新增: if err := s.ensureProjectShare(guest.hostPath); !errors.Is(err, errMacOSProjectApproval) {
471新增: t.Fatalf("background project probe: %v", err)
472新增: }
473新增: if activations.Load() != 0 {
474新增: t.Fatal("background project recovery stole guest focus")
475新增: }
476新增: body, _ := json.Marshal(map[string]any{"workspace": guest.hostPath, "add": false})
477新增: open := func() *httptest.ResponseRecorder {
478新增: return windowsBrowserRequestForTest(s, http.MethodPost, "/api/projects/open", body)
479新增: }
480新增: response := open()
481新增: var pending struct{ Workspace, Approval string }
482新增: if response.Code != http.StatusOK || json.Unmarshal(response.Body.Bytes(), &pending) != nil || pending.Approval != grant || pending.Workspace != guest.hostPath {
483新增: t.Fatalf("pending project open: %d %s", response.Code, response.Body.String())
484新增: }
485新增: if activations.Load() != 1 || share.detach != nil {
486新增: t.Fatal("explicit project open did not show the pending window without approving it")
487新增: }
488新增: activationFails.Store(true)
489新增: response = open()
490新增: if response.Code == http.StatusOK || share.approval != grant || s.projectShares[guest.hostPath] != share || share.detach != nil {
491新增: t.Fatal("failed window activation lost its pending grant or reported success")
492新增: }
493新增: activationFails.Store(false)
494新增: guest.approved.Store(true)
495新增: response = open()
496新增: if response.Code != http.StatusOK || strings.Contains(response.Body.String(), "approval") || share.detach == nil {
497新增: t.Fatalf("approved project open: %d %s", response.Code, response.Body.String())
498新增: }
499新增: if activations.Load() != 2 {
500新增: t.Fatal("opening an approved project stole guest focus")
501新增: }
502新增:}
修改internal/workbench/projects.go+10 −0看文件
@@ -85,6 +85,16 @@ func (s *Server) openProject(w http.ResponseWriter, r *http.Request) {
8585 }
8686 s.mu.Unlock()
8787 if grant != "" {
88新增: // Only an explicit project open should restore the approval app;
89新增: // background probes and frame polling must not take guest focus.
90新增: ctx, cancel := context.WithTimeout(s.operationContext(), 5*time.Second)
91新增: _, openErr := s.guestControl(ctx, "/usr/bin/open -a /Applications/CageProjectAccess.app", "macos-project-approval")
92新增: cancel()
93新增: if openErr != nil {
94新增: w.Header().Set("X-Cage-Recovery", "project-approval")
95新增: requestError(w, errors.New("未能显示客机项目授权窗口,请重试"))
96新增: return
97新增: }
8898 jsonReply(w, map[string]string{"workspace": path, "approval": grant})
8999 return
90100 }