1package proto
2
3import (
4 "time"
5
6 "github.com/charmbracelet/catwalk/pkg/catwalk"
7 "github.com/charmbracelet/crush/internal/config"
8 "github.com/charmbracelet/crush/internal/lsp"
9)
10
11// Instance represents a running app.App instance with its associated resources
12// and state.
13type Instance struct {
14 ID string `json:"id"`
15 Path string `json:"path"`
16 YOLO bool `json:"yolo,omitempty"`
17 Debug bool `json:"debug,omitempty"`
18 DataDir string `json:"data_dir,omitempty"`
19 Config *config.Config `json:"config,omitempty"`
20 Env []string `json:"env,omitempty"`
21}
22
23// ShellResolver returns a new [config.ShellResolver] based on the instance's
24// environment variables.
25func (i Instance) ShellResolver() *config.ShellVariableResolver {
26 return config.NewShellVariableResolver(i.Env)
27}
28
29// Error represents an error response.
30type Error struct {
31 Message string `json:"message"`
32}
33
34// AgentInfo represents information about the agent.
35type AgentInfo struct {
36 IsBusy bool `json:"is_busy"`
37 Model catwalk.Model `json:"model"`
38}
39
40// IsZero checks if the AgentInfo is zero-valued.
41func (a AgentInfo) IsZero() bool {
42 return a == AgentInfo{}
43}
44
45// AgentMessage represents a message sent to the agent.
46type AgentMessage struct {
47 SessionID string `json:"session_id"`
48 Prompt string `json:"prompt"`
49 Attachments []Attachment `json:"attachments,omitempty"`
50}
51
52// AgentSession represents a session with its busy status.
53type AgentSession struct {
54 Session
55 IsBusy bool `json:"is_busy"`
56}
57
58// IsZero checks if the AgentSession is zero-valued.
59func (a AgentSession) IsZero() bool {
60 return a == AgentSession{}
61}
62
63type PermissionAction string
64
65// Permission responses
66const (
67 PermissionAllow PermissionAction = "allow"
68 PermissionAllowForSession PermissionAction = "allow_session"
69 PermissionDeny PermissionAction = "deny"
70)
71
72// MarshalText implements the [encoding.TextMarshaler] interface.
73func (p PermissionAction) MarshalText() ([]byte, error) {
74 return []byte(p), nil
75}
76
77// UnmarshalText implements the [encoding.TextUnmarshaler] interface.
78func (p *PermissionAction) UnmarshalText(text []byte) error {
79 *p = PermissionAction(text)
80 return nil
81}
82
83// PermissionGrant represents a permission grant request.
84type PermissionGrant struct {
85 Permission PermissionRequest `json:"permission"`
86 Action PermissionAction `json:"action"`
87}
88
89// PermissionSkipRequest represents a request to skip permission prompts.
90type PermissionSkipRequest struct {
91 Skip bool `json:"skip"`
92}
93
94// LSPEventType represents the type of LSP event
95type LSPEventType string
96
97const (
98 LSPEventStateChanged LSPEventType = "state_changed"
99 LSPEventDiagnosticsChanged LSPEventType = "diagnostics_changed"
100)
101
102func (e LSPEventType) MarshalText() ([]byte, error) {
103 return []byte(e), nil
104}
105
106func (e *LSPEventType) UnmarshalText(data []byte) error {
107 *e = LSPEventType(data)
108 return nil
109}
110
111// LSPEvent represents an event in the LSP system
112type LSPEvent struct {
113 Type LSPEventType `json:"type"`
114 Name string `json:"name"`
115 State lsp.ServerState `json:"state"`
116 Error error `json:"error,omitempty"`
117 DiagnosticCount int `json:"diagnostic_count,omitempty"`
118}
119
120// LSPClientInfo holds information about an LSP client's state
121type LSPClientInfo struct {
122 Name string `json:"name"`
123 State lsp.ServerState `json:"state"`
124 Error error `json:"error,omitempty"`
125 DiagnosticCount int `json:"diagnostic_count,omitempty"`
126 ConnectedAt time.Time `json:"connected_at"`
127}