跳到主要内容

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

浏览文件

jobs_service.go

56 行 · 1.5 KB历史下载
1package workbench
2
3import (
4 "context"
5 "fmt"
6)
7
8func (s *Server) busy() bool { return s.jobs.snapshot().Running }
9
10// submitJob keeps network intent and account policy in the workbench. The
11// manager owns admission, execution, cancellation and published job state.
12func (s *Server) submitJob(kind string, run func() error) (Job, error) {
13 s.mu.Lock()
14 if s.closing {
15 s.mu.Unlock()
16 return Job{}, errJobsClosed
17 }
18 if s.storageRecoveryError != "" && kind != "storage-recovery" {
19 err := fmt.Errorf("环境存储待恢复,请在设置中恢复后继续。%s", s.storageRecoveryError)
20 s.mu.Unlock()
21 return Job{}, err
22 }
23 var afterSuccess func() error
24 if kind == "logout" {
25 kind = "stop"
26 afterSuccess = func() error { return s.account.lockAccess(true) }
27 }
28 intentFailed := false
29 job, err := s.jobs.submit(&s.op, kind, s.safety.pauseVersion, func() error {
30 if kind == "safety" || (s.macosGuest == nil && (kind == "start" || kind == "restore")) {
31 if err := s.saveNetworkIntentLocked(false); err != nil {
32 intentFailed = true
33 return err
34 }
35 }
36 if s.monitorCancel != nil {
37 s.monitorCancel()
38 }
39 return nil
40 }, afterSuccess, run)
41 s.mu.Unlock()
42 if intentFailed {
43 _ = s.closeProxyGate("网络恢复意图无法保存,外网保持关闭")
44 }
45 return job, err
46}
47
48func (s *Server) setMessage(message string) { s.jobs.execution().message(message) }
49
50func (s *Server) operationContext() context.Context {
51 execution := s.jobs.execution()
52 if execution.id != "" {
53 return execution.ctx
54 }
55 return s.lifetimeContext()
56}