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