跳到主要内容

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

浏览文件

types.go

114 行 · 3.6 KB历史下载
1// Package remotehost owns saved remote hosts and authenticated connections.
2// It does not execute workloads, stop remote services, or expose SSH credentials
3// to the workbench page.
4package remotehost
5
6import (
7 "context"
8 "net/http"
9)
10
11const APIProtocol = 1
12
13type AuthConfig struct {
14 Kind string `json:"kind"`
15 IdentityFile string `json:"identity_file,omitempty"`
16}
17
18type HostKey struct {
19 Algorithm string `json:"algorithm"`
20 Fingerprint string `json:"fingerprint"`
21}
22
23type HostProfile struct {
24 ID string `json:"id"`
25 Name string `json:"name"`
26 Host string `json:"host"`
27 Port int `json:"port"`
28 User string `json:"user"`
29 Auth AuthConfig `json:"auth"`
30 HostKey *HostKey `json:"host_key,omitempty"`
31 Executable string `json:"executable,omitempty"`
32 ConfigPath string `json:"config_path,omitempty"`
33}
34
35type PublicManifest struct {
36 APIProtocol int `json:"api_protocol"`
37 InstanceID string `json:"instance_id"`
38 Version string `json:"version"`
39 Platform string `json:"platform"`
40 Runtime string `json:"runtime"`
41 Capabilities map[string]bool `json:"capabilities"`
42}
43
44// ServerManifest is the private SSH command response. Never return it from a
45// browser API: Ticket is consumed only inside the connector.
46type ServerManifest struct {
47 APIProtocol int `json:"api_protocol"`
48 InstanceID string `json:"instance_id"`
49 Version string `json:"version"`
50 Platform string `json:"platform"`
51 Runtime string `json:"runtime"`
52 Capabilities map[string]bool `json:"capabilities"`
53 Origin string `json:"origin"`
54 Ticket string `json:"ticket"`
55}
56
57func (m ServerManifest) Public() PublicManifest {
58 return PublicManifest{m.APIProtocol, m.InstanceID, m.Version, m.Platform, m.Runtime, m.Capabilities}
59}
60
61// ConnectSecrets are never serialized or persisted. Connect copies the
62// passphrase before returning and clears that copy after SSH authentication.
63type ConnectSecrets struct {
64 Deploy bool `json:"-"`
65 Passphrase []byte `json:"-"`
66}
67
68type ConnectionRef struct {
69 ID string `json:"connection_id"`
70 HostID string `json:"host_id"`
71 InstanceID string `json:"instance_id"`
72}
73
74type ConnectionState struct {
75 State string `json:"state"`
76 ConnectionID string `json:"connection_id,omitempty"`
77 HostID string `json:"host_id,omitempty"`
78 InstanceID string `json:"instance_id,omitempty"`
79 Phase string `json:"phase,omitempty"`
80 Message string `json:"message,omitempty"`
81 ErrorCode string `json:"error_code,omitempty"`
82 HostKey *HostKey `json:"host_key,omitempty"`
83 Manifest *PublicManifest `json:"manifest,omitempty"`
84}
85
86type Error struct {
87 Code string `json:"code"`
88 Message string `json:"message"`
89 HostKey *HostKey `json:"host_key,omitempty"`
90}
91
92func (e *Error) Error() string { return e.Message }
93
94func failure(code, message string) error { return &Error{Code: code, Message: message} }
95
96// Session remains pinned to one authenticated remote instance. Transport is
97// suitable for HTTP reverse proxies, including WebSocket upgrades and SSE.
98// Its URL must use Origin; it injects the private upstream session cookie.
99type Session struct {
100 Ref ConnectionRef
101 Manifest PublicManifest
102 Client *http.Client
103 Transport http.RoundTripper
104 Context context.Context
105 Origin string
106 close func() error
107}
108
109func (s *Session) Close() error {
110 if s == nil || s.close == nil {
111 return nil
112 }
113 return s.close()
114}