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}
21
22// Error represents an error response.
23type Error struct {
24 Message string `json:"message"`
25}
26
27// AgentInfo represents information about the agent.
28type AgentInfo struct {
29 IsBusy bool `json:"is_busy"`
30 Model catwalk.Model `json:"model"`
31}
32
33// IsZero checks if the AgentInfo is zero-valued.
34func (a AgentInfo) IsZero() bool {
35 return a == AgentInfo{}
36}
37
38// AgentMessage represents a message sent to the agent.
39type AgentMessage struct {
40 SessionID string `json:"session_id"`
41 Prompt string `json:"prompt"`
42 Attachments []Attachment `json:"attachments,omitempty"`
43}
44
45// AgentSession represents a session with its busy status.
46type AgentSession struct {
47 Session
48 IsBusy bool `json:"is_busy"`
49}
50
51// IsZero checks if the AgentSession is zero-valued.
52func (a AgentSession) IsZero() bool {
53 return a == AgentSession{}
54}
55
56type PermissionAction string
57
58// Permission responses
59const (
60 PermissionAllow PermissionAction = "allow"
61 PermissionAllowForSession PermissionAction = "allow_session"
62 PermissionDeny PermissionAction = "deny"
63)
64
65// MarshalText implements the [encoding.TextMarshaler] interface.
66func (p PermissionAction) MarshalText() ([]byte, error) {
67 return []byte(p), nil
68}
69
70// UnmarshalText implements the [encoding.TextUnmarshaler] interface.
71func (p *PermissionAction) UnmarshalText(text []byte) error {
72 *p = PermissionAction(text)
73 return nil
74}
75
76// PermissionGrant represents a permission grant request.
77type PermissionGrant struct {
78 Permission PermissionRequest `json:"permission"`
79 Action PermissionAction `json:"action"`
80}
81
82// PermissionSkipRequest represents a request to skip permission prompts.
83type PermissionSkipRequest struct {
84 Skip bool `json:"skip"`
85}
86
87// LSPEventType represents the type of LSP event
88type LSPEventType string
89
90const (
91 LSPEventStateChanged LSPEventType = "state_changed"
92 LSPEventDiagnosticsChanged LSPEventType = "diagnostics_changed"
93)
94
95func (e LSPEventType) MarshalText() ([]byte, error) {
96 return []byte(e), nil
97}
98
99func (e *LSPEventType) UnmarshalText(data []byte) error {
100 *e = LSPEventType(data)
101 return nil
102}
103
104// LSPEvent represents an event in the LSP system
105type LSPEvent struct {
106 Type LSPEventType `json:"type"`
107 Name string `json:"name"`
108 State lsp.ServerState `json:"state"`
109 Error error `json:"error,omitempty"`
110 DiagnosticCount int `json:"diagnostic_count,omitempty"`
111}
112
113// LSPClientInfo holds information about an LSP client's state
114type LSPClientInfo struct {
115 Name string `json:"name"`
116 State lsp.ServerState `json:"state"`
117 Error error `json:"error,omitempty"`
118 DiagnosticCount int `json:"diagnostic_count,omitempty"`
119 ConnectedAt time.Time `json:"connected_at"`
120}