Documentation
¶
Overview ¶
Package copilotcli implements the Agent interface for GitHub Copilot CLI.
Index ¶
- Constants
- func ExtractModelFromTranscript(ctx context.Context, transcriptPath string) string
- func NewCopilotCLIAgent() agent.Agent
- type CopilotCLIAgent
- func (c *CopilotCLIAgent) AreHooksInstalled(ctx context.Context) bool
- func (c *CopilotCLIAgent) CalculateTokenUsage(transcriptData []byte, fromOffset int) (*agent.TokenUsage, error)
- func (c *CopilotCLIAgent) ChunkTranscript(_ context.Context, content []byte, maxSize int) ([][]byte, error)
- func (c *CopilotCLIAgent) Description() string
- func (c *CopilotCLIAgent) DetectPresence(ctx context.Context) (bool, error)
- func (c *CopilotCLIAgent) ExtractModifiedFilesFromOffset(path string, startOffset int) (files []string, currentPosition int, err error)
- func (c *CopilotCLIAgent) ExtractPrompts(sessionRef string, fromOffset int) ([]string, error)
- func (c *CopilotCLIAgent) ExtractSummary(sessionRef string) (string, error)
- func (c *CopilotCLIAgent) FormatResumeCommand(sessionID string) string
- func (c *CopilotCLIAgent) GetSessionDir(_ string) (string, error)
- func (c *CopilotCLIAgent) GetSessionID(input *agent.HookInput) string
- func (c *CopilotCLIAgent) GetSupportedHooks() []agent.HookType
- func (c *CopilotCLIAgent) GetTranscriptPosition(path string) (int, error)
- func (c *CopilotCLIAgent) HookNames() []string
- func (c *CopilotCLIAgent) InstallHooks(ctx context.Context, localDev bool, force bool) (int, error)
- func (c *CopilotCLIAgent) IsPreview() bool
- func (c *CopilotCLIAgent) Name() types.AgentName
- func (c *CopilotCLIAgent) ParseHookEvent(ctx context.Context, hookName string, stdin io.Reader) (*agent.Event, error)
- func (c *CopilotCLIAgent) ProtectedDirs() []string
- func (c *CopilotCLIAgent) ReadSession(input *agent.HookInput) (*agent.AgentSession, error)
- func (c *CopilotCLIAgent) ReadTranscript(sessionRef string) ([]byte, error)
- func (c *CopilotCLIAgent) ReassembleTranscript(chunks [][]byte) ([]byte, error)
- func (c *CopilotCLIAgent) ResolveSessionFile(sessionDir, agentSessionID string) string
- func (c *CopilotCLIAgent) Type() types.AgentType
- func (c *CopilotCLIAgent) UninstallHooks(ctx context.Context) error
- func (c *CopilotCLIAgent) WriteSession(_ context.Context, session *agent.AgentSession) error
- type CopilotHookEntry
- type CopilotHooks
- type CopilotHooksFile
Constants ¶
const ( HookNameUserPromptSubmitted = "user-prompt-submitted" HookNameSessionStart = "session-start" HookNameAgentStop = "agent-stop" HookNameSessionEnd = "session-end" HookNameSubagentStop = "subagent-stop" HookNamePreToolUse = "pre-tool-use" HookNamePostToolUse = "post-tool-use" HookNameErrorOccurred = "error-occurred" )
Copilot CLI hook names - these become subcommands under `entire hooks copilot-cli`
const HooksFileName = "entire.json"
HooksFileName is the hooks file managed by Entire for Copilot CLI.
Variables ¶
This section is empty.
Functions ¶
func ExtractModelFromTranscript ¶
ExtractModelFromTranscript extracts the LLM model name from a Copilot CLI transcript. It prefers session.model_change events (explicit model declarations), but falls back to the model field on tool.execution_complete events for Copilot CLI versions that do not emit session.model_change. Returns the last observed model, or empty string if unavailable.
func NewCopilotCLIAgent ¶
NewCopilotCLIAgent creates a new Copilot CLI agent instance.
Types ¶
type CopilotCLIAgent ¶
type CopilotCLIAgent struct{}
CopilotCLIAgent implements the Agent interface for GitHub Copilot CLI.
func (*CopilotCLIAgent) AreHooksInstalled ¶
func (c *CopilotCLIAgent) AreHooksInstalled(ctx context.Context) bool
AreHooksInstalled checks if Entire hooks are installed in the Copilot CLI config.
func (*CopilotCLIAgent) CalculateTokenUsage ¶
func (c *CopilotCLIAgent) CalculateTokenUsage(transcriptData []byte, fromOffset int) (*agent.TokenUsage, error)
CalculateTokenUsage computes token usage from the Copilot CLI JSONL transcript. For full transcripts (fromOffset == 0), it prefers session.shutdown, which contains session-wide aggregates. For sliced transcripts, session.shutdown would overcount because it is not checkpoint-scoped, so we fall back to summing assistant.message outputTokens within the slice.
func (*CopilotCLIAgent) ChunkTranscript ¶
func (c *CopilotCLIAgent) ChunkTranscript(_ context.Context, content []byte, maxSize int) ([][]byte, error)
ChunkTranscript splits a JSONL transcript at line boundaries.
func (*CopilotCLIAgent) Description ¶
func (c *CopilotCLIAgent) Description() string
Description returns a human-readable description.
func (*CopilotCLIAgent) DetectPresence ¶
func (c *CopilotCLIAgent) DetectPresence(ctx context.Context) (bool, error)
DetectPresence checks if Entire hooks are installed in the Copilot CLI config. Delegates to AreHooksInstalled which checks .github/hooks/entire.json for Entire hook entries.
func (*CopilotCLIAgent) ExtractModifiedFilesFromOffset ¶
func (c *CopilotCLIAgent) ExtractModifiedFilesFromOffset(path string, startOffset int) (files []string, currentPosition int, err error)
ExtractModifiedFilesFromOffset extracts files modified since a given line number. For Copilot CLI (JSONL format), offset is the starting line number. Uses bufio.Reader to handle arbitrarily long lines (no size limit). Returns:
- files: list of file paths modified by Copilot (from tool.execution_complete events)
- currentPosition: total number of lines in the file
- error: any error encountered during reading
func (*CopilotCLIAgent) ExtractPrompts ¶
func (c *CopilotCLIAgent) ExtractPrompts(sessionRef string, fromOffset int) ([]string, error)
ExtractPrompts extracts user prompts from the transcript starting at the given offset.
func (*CopilotCLIAgent) ExtractSummary ¶
func (c *CopilotCLIAgent) ExtractSummary(sessionRef string) (string, error)
ExtractSummary extracts the last assistant message as a session summary.
func (*CopilotCLIAgent) FormatResumeCommand ¶
func (c *CopilotCLIAgent) FormatResumeCommand(sessionID string) string
FormatResumeCommand returns a command to resume a Copilot CLI session.
func (*CopilotCLIAgent) GetSessionDir ¶
func (c *CopilotCLIAgent) GetSessionDir(_ string) (string, error)
GetSessionDir returns the directory where Copilot CLI stores session transcripts.
func (*CopilotCLIAgent) GetSessionID ¶
func (c *CopilotCLIAgent) GetSessionID(input *agent.HookInput) string
GetSessionID extracts the session ID from hook input.
func (*CopilotCLIAgent) GetSupportedHooks ¶
func (c *CopilotCLIAgent) GetSupportedHooks() []agent.HookType
GetSupportedHooks returns the normalized lifecycle events this agent supports. Note: HookNames() returns 8 hooks but GetSupportedHooks() returns only 6. The two not listed here are:
- subagentStop: handled by ParseHookEvent (returns SubagentEnd), but there is no HookType constant for subagent events (they use EventType instead).
- errorOccurred: pass-through hook with no lifecycle action (ParseHookEvent returns nil).
func (*CopilotCLIAgent) GetTranscriptPosition ¶
func (c *CopilotCLIAgent) GetTranscriptPosition(path string) (int, error)
GetTranscriptPosition returns the current line count of a Copilot CLI transcript. Copilot CLI uses JSONL format, so position is the number of lines. This is a lightweight operation that only counts lines without parsing JSON. Uses bufio.Reader to handle arbitrarily long lines (no size limit). Returns 0 if the file doesn't exist or is empty.
func (*CopilotCLIAgent) HookNames ¶
func (c *CopilotCLIAgent) HookNames() []string
HookNames returns all hook verbs Copilot CLI supports. These become subcommands: entire hooks copilot-cli <verb>
func (*CopilotCLIAgent) InstallHooks ¶
InstallHooks installs Copilot CLI hooks in .github/hooks/entire.json. If force is true, removes existing Entire hooks before installing. Returns the number of hooks installed. Unknown top-level fields and hook types are preserved on round-trip.
func (*CopilotCLIAgent) IsPreview ¶
func (c *CopilotCLIAgent) IsPreview() bool
IsPreview returns true because this is a new integration.
func (*CopilotCLIAgent) Name ¶
func (c *CopilotCLIAgent) Name() types.AgentName
Name returns the agent registry key.
func (*CopilotCLIAgent) ParseHookEvent ¶
func (c *CopilotCLIAgent) ParseHookEvent(ctx context.Context, hookName string, stdin io.Reader) (*agent.Event, error)
ParseHookEvent translates a Copilot CLI hook into a normalized lifecycle Event. Returns nil if the hook has no lifecycle significance (pass-through hooks).
func (*CopilotCLIAgent) ProtectedDirs ¶
func (c *CopilotCLIAgent) ProtectedDirs() []string
ProtectedDirs returns directories that Copilot CLI uses for config/state.
func (*CopilotCLIAgent) ReadSession ¶
func (c *CopilotCLIAgent) ReadSession(input *agent.HookInput) (*agent.AgentSession, error)
ReadSession reads a session from Copilot CLI's storage (JSONL transcript file).
func (*CopilotCLIAgent) ReadTranscript ¶
func (c *CopilotCLIAgent) ReadTranscript(sessionRef string) ([]byte, error)
ReadTranscript reads the raw JSONL transcript bytes for a session.
func (*CopilotCLIAgent) ReassembleTranscript ¶
func (c *CopilotCLIAgent) ReassembleTranscript(chunks [][]byte) ([]byte, error)
ReassembleTranscript concatenates JSONL chunks with newlines.
func (*CopilotCLIAgent) ResolveSessionFile ¶
func (c *CopilotCLIAgent) ResolveSessionFile(sessionDir, agentSessionID string) string
ResolveSessionFile returns the path to a Copilot CLI session transcript file. Copilot CLI stores transcripts at <sessionDir>/<sessionId>/events.jsonl.
func (*CopilotCLIAgent) Type ¶
func (c *CopilotCLIAgent) Type() types.AgentType
Type returns the agent type identifier.
func (*CopilotCLIAgent) UninstallHooks ¶
func (c *CopilotCLIAgent) UninstallHooks(ctx context.Context) error
UninstallHooks removes Entire hooks from Copilot CLI's entire.json. Unknown top-level fields and hook types are preserved on round-trip.
func (*CopilotCLIAgent) WriteSession ¶
func (c *CopilotCLIAgent) WriteSession(_ context.Context, session *agent.AgentSession) error
WriteSession writes a session to Copilot CLI's storage (JSONL transcript file).
type CopilotHookEntry ¶
type CopilotHooks ¶
type CopilotHooks struct {
UserPromptSubmitted []CopilotHookEntry `json:"userPromptSubmitted,omitempty"`
SessionStart []CopilotHookEntry `json:"sessionStart,omitempty"`
AgentStop []CopilotHookEntry `json:"agentStop,omitempty"`
SessionEnd []CopilotHookEntry `json:"sessionEnd,omitempty"`
SubagentStop []CopilotHookEntry `json:"subagentStop,omitempty"`
PreToolUse []CopilotHookEntry `json:"preToolUse,omitempty"`
PostToolUse []CopilotHookEntry `json:"postToolUse,omitempty"`
ErrorOccurred []CopilotHookEntry `json:"errorOccurred,omitempty"`
}
type CopilotHooksFile ¶
type CopilotHooksFile struct {
Version int `json:"version"`
Hooks CopilotHooks `json:"hooks"`
}