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