copilot

package
v0.0.0-...-7c1ad8c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatMessage

type ChatMessage struct {
	Role      string    `json:"role"`
	Content   string    `json:"content"`
	Timestamp time.Time `json:"timestamp"`
}

ChatMessage represents a single message in a copilot conversation.

type EventData

type EventData struct {
	Content      *string `json:"content,omitempty"`
	ToolName     *string `json:"tool_name,omitempty"`
	ToolCallID   *string `json:"tool_call_id,omitempty"`
	ToolInput    *string `json:"tool_input,omitempty"`
	ToolResult   *string `json:"tool_result,omitempty"`
	ToolSuccess  *bool   `json:"tool_success,omitempty"`
	Intent       *string `json:"intent,omitempty"`
	ReasoningID  *string `json:"reasoning_id,omitempty"`
	Model        *string `json:"model,omitempty"`
	InputTokens  *int    `json:"input_tokens,omitempty"`
	OutputTokens *int    `json:"output_tokens,omitempty"`
	ErrorMessage *string `json:"error_message,omitempty"`

	// Subagent fields.
	AgentName        *string `json:"agent_name,omitempty"`
	AgentDisplayName *string `json:"agent_display_name,omitempty"`
	AgentDescription *string `json:"agent_description,omitempty"`
	ParentToolCallID *string `json:"parent_tool_call_id,omitempty"`
	Summary          *string `json:"summary,omitempty"`

	// Tool progress fields.
	ProgressMessage *string `json:"progress_message,omitempty"`
	PartialOutput   *string `json:"partial_output,omitempty"`

	// Session lifecycle fields.
	Title         *string `json:"title,omitempty"`
	NewModel      *string `json:"new_model,omitempty"`
	PreviousModel *string `json:"previous_model,omitempty"`
	NewMode       *string `json:"new_mode,omitempty"`
	PreviousMode  *string `json:"previous_mode,omitempty"`
	WarningType   *string `json:"warning_type,omitempty"`
	InfoType      *string `json:"info_type,omitempty"`
	Success       *bool   `json:"success,omitempty"`

	// User input / elicitation fields.
	RequestID     *string  `json:"request_id,omitempty"`
	Question      *string  `json:"question,omitempty"`
	Choices       []string `json:"choices,omitempty"`
	AllowFreeform *bool    `json:"allow_freeform,omitempty"`

	// Permission fields.
	PermissionKind     *string `json:"permission_kind,omitempty"`
	PermissionToolName *string `json:"permission_tool_name,omitempty"`

	// Hook fields.
	HookID   *string `json:"hook_id,omitempty"`
	HookType *string `json:"hook_type,omitempty"`

	// Skill fields.
	SkillName *string `json:"skill_name,omitempty"`
}

EventData carries the payload for a session event.

type EventType

type EventType string

EventType represents the type of event emitted during a copilot session.

const (
	EventContentDelta   EventType = "content_delta"
	EventToolStart      EventType = "tool_start"
	EventToolComplete   EventType = "tool_complete"
	EventIntentChanged  EventType = "intent_changed"
	EventTurnStart      EventType = "turn_start"
	EventTurnEnd        EventType = "turn_end"
	EventSessionError   EventType = "session_error"
	EventSessionIdle    EventType = "session_idle"
	EventUsageInfo      EventType = "usage_info"
	EventReasoningDelta EventType = "reasoning_delta"
	EventUserMessage    EventType = "user_message"

	// Subagent lifecycle.
	EventSubagentStart      EventType = "subagent_start"
	EventSubagentComplete   EventType = "subagent_complete"
	EventSubagentFailed     EventType = "subagent_failed"
	EventSubagentSelected   EventType = "subagent_selected"
	EventSubagentDeselected EventType = "subagent_deselected"

	// Tool progress.
	EventToolProgress      EventType = "tool_progress"
	EventToolPartialResult EventType = "tool_partial_result"

	// Session lifecycle.
	EventTitleChanged       EventType = "title_changed"
	EventCompactionStart    EventType = "compaction_start"
	EventCompactionComplete EventType = "compaction_complete"
	EventPlanChanged        EventType = "plan_changed"
	EventTaskComplete       EventType = "task_complete"
	EventContextChanged     EventType = "context_changed"
	EventModelChange        EventType = "model_change"
	EventModeChanged        EventType = "mode_changed"
	EventSessionWarning     EventType = "session_warning"
	EventSessionInfo        EventType = "session_info"

	// User input / elicitation.
	EventUserInputRequested   EventType = "user_input_requested"
	EventUserInputCompleted   EventType = "user_input_completed"
	EventElicitationRequested EventType = "elicitation_requested"
	EventElicitationCompleted EventType = "elicitation_completed"

	// Permissions.
	EventPermissionRequested EventType = "permission_requested"
	EventPermissionCompleted EventType = "permission_completed"

	// Hooks & skills.
	EventHookStart    EventType = "hook_start"
	EventHookEnd      EventType = "hook_end"
	EventSkillInvoked EventType = "skill_invoked"
)

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager manages multiple copilot sessions and broadcasts their events.

func NewManager

func NewManager() *Manager

NewManager creates a Manager. Call Start() before creating sessions.

func NewManagerWithConfig

func NewManagerWithConfig(cfg ManagerConfig) *Manager

NewManagerWithConfig creates a Manager with the given configuration.

func (*Manager) AbortSession

func (m *Manager) AbortSession(ctx context.Context, name string) error

AbortSession cancels the current in-flight request for a session.

func (*Manager) ActiveSessionName

func (m *Manager) ActiveSessionName() string

ActiveSessionName returns the name of the active session.

func (*Manager) CloseSession

func (m *Manager) CloseSession(name string) error

CloseSession closes and removes a session.

func (*Manager) CreateSession

func (m *Manager) CreateSession(ctx context.Context, name, model, workingDir string) error

CreateSession creates a new copilot session.

func (*Manager) ForkSession

func (m *Manager) ForkSession(ctx context.Context, sessionID, model string) (string, error)

ForkSession creates a new session seeded with the conversation history from an existing persisted session's events.jsonl. Returns the new session name.

func (*Manager) GetHistory

func (m *Manager) GetHistory(name string) ([]ChatMessage, error)

GetHistory returns the chat history for a session.

func (*Manager) GetSession

func (m *Manager) GetSession(name string) *Session

GetSession returns a session by name, or nil.

func (*Manager) ListPersistedSessions

func (m *Manager) ListPersistedSessions() []PersistedSession

ListPersistedSessions scans ~/.copilot/session-state/ for saved session directories. Uses session-store.db for metadata when available, falling back to workspace.yaml.

func (*Manager) ListSessions

func (m *Manager) ListSessions() []SessionInfo

ListSessions returns info about all active sessions.

func (*Manager) ReadSessionEvents

func (m *Manager) ReadSessionEvents(sessionID string) ([]ChatMessage, error)

ReadSessionEvents parses events.jsonl for a persisted session and returns the conversation as chat messages (user + assistant only).

func (*Manager) ResumeSession

func (m *Manager) ResumeSession(ctx context.Context, sessionID, displayName string) error

ResumeSession resumes a persisted session by its GUID.

func (*Manager) SearchSessions

func (m *Manager) SearchSessions(query string) []SessionSearchResult

SearchSessions performs FTS5 search across session history in session-store.db.

func (*Manager) SendPrompt

func (m *Manager) SendPrompt(ctx context.Context, name, prompt string) error

SendPrompt sends a prompt to the named session. If the SDK reports "Session not found" (e.g. server-side expiry after idle timeout), it tries to resume the session. If resume succeeds but the session is still dead, it falls back to rebuilding a fresh session seeded with conversation history — the user's message goes through transparently.

func (*Manager) SetActiveSession

func (m *Manager) SetActiveSession(name string) error

SetActiveSession switches the active session.

func (*Manager) SetEventHandler

func (m *Manager) SetEventHandler(fn func(SessionEvent))

SetEventHandler registers a callback for session events (content deltas, tool calls, intents, etc.). Called from any goroutine — the handler must be safe for concurrent use.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start initializes the Copilot SDK client.

func (*Manager) Stop

func (m *Manager) Stop()

Stop shuts down all sessions and the SDK client.

func (*Manager) WatchSession

func (m *Manager) WatchSession(ctx context.Context, sessionID string, onMessage func(ChatMessage)) error

WatchSession tails events.jsonl for a persisted session and sends new chat messages to the callback as they appear. Blocks until ctx is cancelled.

type ManagerConfig

type ManagerConfig struct {
	// ServerURL connects to an existing copilot headless server (e.g. "localhost:4321").
	// If empty, the SDK spawns its own copilot process via stdio.
	ServerURL string
}

ManagerConfig configures the copilot session Manager.

type PersistedSession

type PersistedSession struct {
	SessionID    string    `json:"session_id"`
	LastModified time.Time `json:"last_modified"`
	Path         string    `json:"path"`
	Summary      string    `json:"summary,omitempty"`
	CreatedAt    string    `json:"created_at,omitempty"`
	UpdatedAt    string    `json:"updated_at,omitempty"`
	IsActive     bool      `json:"is_active,omitempty"` // true if session files were modified recently
	// contains filtered or unexported fields
}

PersistedSession describes a session found in ~/.copilot/session-state/.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session wraps a single Copilot SDK session with event handling and history tracking.

func (*Session) Abort

func (s *Session) Abort(ctx context.Context) error

Abort cancels the current in-flight request.

func (*Session) Destroy

func (s *Session) Destroy()

Destroy cleans up the SDK session.

func (*Session) History

func (s *Session) History() []ChatMessage

History returns a copy of all chat messages.

func (*Session) Info

func (s *Session) Info() SessionInfo

Info returns a snapshot of the session info.

func (*Session) SendPrompt

func (s *Session) SendPrompt(ctx context.Context, prompt string) error

SendPrompt sends a user prompt to the session.

type SessionEvent

type SessionEvent struct {
	Type        EventType `json:"type"`
	SessionName string    `json:"session_name"`
	Data        EventData `json:"data"`
}

SessionEvent represents an event emitted by a copilot session.

type SessionInfo

type SessionInfo struct {
	Name          string       `json:"name"`
	Model         string       `json:"model"`
	SessionID     string       `json:"session_id"`
	WorkingDir    string       `json:"working_dir"`
	WorktreeID    string       `json:"worktree_id,omitempty"`
	CreatedAt     time.Time    `json:"created_at"`
	State         SessionState `json:"state"`
	MessageCount  int          `json:"message_count"`
	LastActivity  time.Time    `json:"last_activity"`
	Intent        string       `json:"intent"`
	ToolCallCount int          `json:"tool_call_count"`
}

SessionInfo represents a managed copilot session.

type SessionSearchResult

type SessionSearchResult struct {
	SessionID string `json:"session_id"`
	Summary   string `json:"summary"`
	Snippet   string `json:"snippet"`
	Hits      int    `json:"hits"`
	UpdatedAt string `json:"updated_at"`
}

SessionSearchResult represents a single search hit across session history.

type SessionState

type SessionState string

SessionState represents the current state of a copilot session.

const (
	StateIdle       SessionState = "idle"
	StateProcessing SessionState = "processing"
	StateError      SessionState = "error"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL