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