Documentation
¶
Overview ¶
Package copilot wraps the GitHub Copilot SDK to provide a streaming AI chat interface for the Dispatch TUI.
Index ¶
- func QuoteUntrusted(s string) string
- func SanitizeExternalContent(s string) string
- type Client
- func (c *Client) Available() bool
- func (c *Client) Close()
- func (c *Client) Init(ctx context.Context) error
- func (c *Client) InitError() error
- func (c *Client) Search(ctx context.Context, query string) ([]string, error)
- func (c *Client) SendMessage(ctx context.Context, prompt string) (<-chan StreamEvent, error)
- type GetSessionDetailParams
- type ListReposParams
- type SearchDeepParams
- type SearchSessionsParams
- type StreamEvent
- type StreamEventType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func QuoteUntrusted ¶
QuoteUntrusted wraps a single-line value using Go %q formatting, which escapes control characters and wraps the result in double quotes. Use this for short values like branch names, commit messages, and refs.
func SanitizeExternalContent ¶
SanitizeExternalContent wraps untrusted multi-line content in clearly delimited boundary markers so the LLM treats it as opaque data rather than as instructions. Any embedded delimiter tokens are defused first.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the Copilot SDK to provide search and streaming chat. It lazily initialises the SDK client on the first search/message, and creates sessions on-demand (no idle background sessions).
func New ¶
New creates a new copilot Client backed by the given data store. The SDK is not started until Init is called.
func (*Client) Close ¶
func (c *Client) Close()
Close shuts down the Copilot SDK client. Safe to call multiple times or on an uninitialised client.
func (*Client) Init ¶
Init starts the Copilot SDK client. Sessions are created on-demand by Search and SendMessage. This is safe to call from a goroutine; subsequent calls are no-ops if already initialised.
func (*Client) Search ¶
Search asks the Copilot SDK to find sessions matching the given query. It returns a list of session IDs found by AI-powered search. This is non-streaming — it sends the query and waits for the final result. If the client is not available, it returns nil, nil (graceful no-op).
Search is self-contained: it calls Init automatically and handles transport errors (e.g. "file already closed") by resetting the SDK and retrying. After all retries are exhausted it clears cached errors so the next call can attempt a fresh start.
func (*Client) SendMessage ¶
SendMessage sends a user prompt to the Copilot session and returns a channel of StreamEvents that the TUI can consume. The channel is closed when the response is complete or an error occurs.
The caller should range over the channel to receive events:
ch, err := client.SendMessage(ctx, "find auth sessions")
for ev := range ch {
switch ev.Type { ... }
}
type GetSessionDetailParams ¶
type GetSessionDetailParams struct {
ID string `json:"id" jsonschema:"The session ID to retrieve"`
}
GetSessionDetailParams are the arguments for get_session_detail.
type ListReposParams ¶
type ListReposParams struct {
Filter string `json:"filter,omitempty" jsonschema:"Optional substring to filter repository names"`
}
ListReposParams is used for the list_repositories tool. The unused field ensures the generated JSON schema includes a "properties" key — the API rejects object schemas without one.
type SearchDeepParams ¶
type SearchDeepParams struct {
Query string `json:"query" jsonschema:"Full-text search query across all session content"`
}
SearchDeepParams are the arguments for the deep FTS5 search tool.
type SearchSessionsParams ¶
type SearchSessionsParams struct {
Query string `json:"query,omitempty" jsonschema:"Keyword or phrase to search for"`
Repo string `json:"repo,omitempty" jsonschema:"Filter by repository name"`
Branch string `json:"branch,omitempty" jsonschema:"Filter by git branch"`
Since string `json:"since,omitempty" jsonschema:"Only sessions updated after this ISO-8601 date"`
Until string `json:"until,omitempty" jsonschema:"Only sessions updated before this ISO-8601 date"`
}
SearchSessionsParams are the arguments accepted by the search_sessions tool.
type StreamEvent ¶
type StreamEvent struct {
Type StreamEventType
Content string // text delta, tool name, or error message
}
StreamEvent is a single event delivered to the TUI via a channel.
type StreamEventType ¶
type StreamEventType int
StreamEventType classifies events flowing from the Copilot session to the TUI chat panel.
const ( // EventTextDelta carries an incremental text chunk from the assistant. EventTextDelta StreamEventType = iota // EventToolStart signals the assistant is invoking a tool. EventToolStart // EventToolDone signals a tool invocation has completed. EventToolDone // EventDone signals the assistant has finished its response. EventDone // EventError carries an error from the Copilot session. EventError )