Documentation
¶
Overview ¶
Package external provides an adapter that bridges external agent binaries (discovered via PATH as entire-agent-<name>) to the agent.Agent interface. Communication uses a subcommand-based protocol with JSON over stdin/stdout.
Index ¶
- Constants
- func DiscoverAndRegister(ctx context.Context)
- func Wrap(ea *Agent) (agent.Agent, error)
- type Agent
- func (e *Agent) AreHooksInstalled(ctx context.Context) bool
- func (e *Agent) CalculateTokenUsage(transcriptData []byte, fromOffset int) (*agent.TokenUsage, error)
- func (e *Agent) CalculateTotalTokenUsage(transcriptData []byte, fromOffset int, subagentsDir string) (*agent.TokenUsage, error)
- func (e *Agent) ChunkTranscript(ctx context.Context, content []byte, maxSize int) ([][]byte, error)
- func (e *Agent) Description() string
- func (e *Agent) DetectPresence(ctx context.Context) (bool, error)
- func (e *Agent) ExtractAllModifiedFiles(transcriptData []byte, fromOffset int, subagentsDir string) ([]string, error)
- func (e *Agent) ExtractModifiedFilesFromOffset(path string, startOffset int) ([]string, int, error)
- func (e *Agent) ExtractPrompts(sessionRef string, fromOffset int) ([]string, error)
- func (e *Agent) ExtractSummary(sessionRef string) (string, error)
- func (e *Agent) FormatResumeCommand(sessionID string) string
- func (e *Agent) GenerateText(ctx context.Context, prompt string, model string) (string, error)
- func (e *Agent) GetSessionDir(repoPath string) (string, error)
- func (e *Agent) GetSessionID(input *agent.HookInput) string
- func (e *Agent) GetTranscriptPosition(path string) (int, error)
- func (e *Agent) HookNames() []string
- func (e *Agent) Info() *InfoResponse
- func (e *Agent) InstallHooks(ctx context.Context, localDev bool, force bool) (int, error)
- func (e *Agent) IsPreview() bool
- func (e *Agent) Name() types.AgentName
- func (e *Agent) ParseHookEvent(ctx context.Context, hookName string, stdin io.Reader) (*agent.Event, error)
- func (e *Agent) PrepareTranscript(ctx context.Context, sessionRef string) error
- func (e *Agent) ProtectedDirs() []string
- func (e *Agent) ReadSession(input *agent.HookInput) (*agent.AgentSession, error)
- func (e *Agent) ReadTranscript(sessionRef string) ([]byte, error)
- func (e *Agent) ReassembleTranscript(chunks [][]byte) ([]byte, error)
- func (e *Agent) ResolveSessionFile(sessionDir, agentSessionID string) string
- func (e *Agent) Type() types.AgentType
- func (e *Agent) UninstallHooks(ctx context.Context) error
- func (e *Agent) WriteHookResponse(message string) error
- func (e *Agent) WriteSession(ctx context.Context, session *agent.AgentSession) error
- type AgentSessionJSON
- type AreHooksInstalledResponse
- type ChunkResponse
- type DetectResponse
- type ExtractFilesResponse
- type ExtractPromptsResponse
- type ExtractSummaryResponse
- type GenerateTextResponse
- type HookInputJSON
- type HooksInstalledCountResponse
- type InfoResponse
- type ResumeCommandResponse
- type SessionDirResponse
- type SessionFileResponse
- type SessionIDResponse
- type TokenUsageResponse
- type TranscriptPositionResponse
Constants ¶
const ProtocolVersion = 1
ProtocolVersion is the current protocol version expected by the CLI.
Variables ¶
This section is empty.
Functions ¶
func DiscoverAndRegister ¶
DiscoverAndRegister scans $PATH for executables matching "entire-agent-<name>", calls their "info" subcommand, and registers them in the agent registry. Binaries whose name conflicts with an already-registered agent are skipped. Errors during discovery are logged but do not prevent other agents from loading.
func Wrap ¶
Wrap returns the Agent wrapped as an agent.Agent that implements ALL optional interfaces (forwarding to the underlying external agent) plus CapabilityDeclarer. The As* helpers in the agent package use DeclaredCapabilities() to gate access, so callers only see capabilities the external binary actually declared.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent implements agent.Agent by delegating to an external binary. Each method invokes a subcommand on the binary and parses the JSON response.
func New ¶
New creates an Agent by calling the binary's "info" subcommand to cache its metadata. Returns an error if the binary cannot be invoked or returns invalid/incompatible protocol data. The provided context bounds the "info" call; pass a context with a deadline to limit how long discovery waits for each binary.
func (*Agent) CalculateTokenUsage ¶
func (*Agent) CalculateTotalTokenUsage ¶
func (*Agent) ChunkTranscript ¶
func (*Agent) Description ¶
func (*Agent) ExtractAllModifiedFiles ¶
func (*Agent) ExtractModifiedFilesFromOffset ¶
func (*Agent) ExtractPrompts ¶
func (*Agent) FormatResumeCommand ¶
func (*Agent) GenerateText ¶
func (*Agent) GetTranscriptPosition ¶
func (*Agent) InstallHooks ¶
func (*Agent) ParseHookEvent ¶
func (*Agent) PrepareTranscript ¶
func (*Agent) ProtectedDirs ¶
func (*Agent) ReadSession ¶
func (*Agent) ReassembleTranscript ¶
func (*Agent) ResolveSessionFile ¶
func (*Agent) WriteHookResponse ¶
func (*Agent) WriteSession ¶
type AgentSessionJSON ¶
type AgentSessionJSON struct {
SessionID string `json:"session_id"`
AgentName string `json:"agent_name"`
RepoPath string `json:"repo_path"`
SessionRef string `json:"session_ref"`
StartTime string `json:"start_time"`
NativeData []byte `json:"native_data"`
ModifiedFiles []string `json:"modified_files"`
NewFiles []string `json:"new_files"`
DeletedFiles []string `json:"deleted_files"`
}
AgentSessionJSON is the JSON representation of agent.AgentSession for stdin/stdout transfer.
type AreHooksInstalledResponse ¶
type AreHooksInstalledResponse struct {
Installed bool `json:"installed"`
}
AreHooksInstalledResponse is the JSON returned by the "are-hooks-installed" subcommand.
type ChunkResponse ¶
type ChunkResponse struct {
Chunks [][]byte `json:"chunks"`
}
ChunkResponse is the JSON returned by the "chunk-transcript" subcommand.
type DetectResponse ¶
type DetectResponse struct {
Present bool `json:"present"`
}
DetectResponse is the JSON returned by the "detect" subcommand.
type ExtractFilesResponse ¶
type ExtractFilesResponse struct {
Files []string `json:"files"`
CurrentPosition int `json:"current_position"`
}
ExtractFilesResponse is the JSON returned by file-extraction subcommands.
type ExtractPromptsResponse ¶
type ExtractPromptsResponse struct {
Prompts []string `json:"prompts"`
}
ExtractPromptsResponse is the JSON returned by the "extract-prompts" subcommand.
type ExtractSummaryResponse ¶
type ExtractSummaryResponse struct {
Summary string `json:"summary"`
HasSummary bool `json:"has_summary"`
}
ExtractSummaryResponse is the JSON returned by the "extract-summary" subcommand.
type GenerateTextResponse ¶
type GenerateTextResponse struct {
Text string `json:"text"`
}
GenerateTextResponse is the JSON returned by the "generate-text" subcommand.
type HookInputJSON ¶
type HookInputJSON struct {
HookType string `json:"hook_type"`
SessionID string `json:"session_id"`
SessionRef string `json:"session_ref"`
Timestamp string `json:"timestamp"`
UserPrompt string `json:"user_prompt,omitempty"`
ToolName string `json:"tool_name,omitempty"`
ToolUseID string `json:"tool_use_id,omitempty"`
ToolInput json.RawMessage `json:"tool_input,omitempty"`
RawData map[string]interface{} `json:"raw_data,omitempty"`
}
HookInputJSON is the JSON representation of agent.HookInput for stdin/stdout transfer.
type HooksInstalledCountResponse ¶
type HooksInstalledCountResponse struct {
HooksInstalled int `json:"hooks_installed"`
}
HooksInstalledCountResponse is the JSON returned by the "install-hooks" subcommand.
type InfoResponse ¶
type InfoResponse struct {
ProtocolVersion int `json:"protocol_version"`
Name string `json:"name"`
Type string `json:"type"`
Description string `json:"description"`
IsPreview bool `json:"is_preview"`
ProtectedDirs []string `json:"protected_dirs"`
HookNames []string `json:"hook_names"`
Capabilities agent.DeclaredCaps `json:"capabilities"`
}
InfoResponse is the JSON returned by the "info" subcommand.
type ResumeCommandResponse ¶
type ResumeCommandResponse struct {
Command string `json:"command"`
}
ResumeCommandResponse is the JSON returned by the "format-resume-command" subcommand.
type SessionDirResponse ¶
type SessionDirResponse struct {
SessionDir string `json:"session_dir"`
}
SessionDirResponse is the JSON returned by the "get-session-dir" subcommand.
type SessionFileResponse ¶
type SessionFileResponse struct {
SessionFile string `json:"session_file"`
}
SessionFileResponse is the JSON returned by the "resolve-session-file" subcommand.
type SessionIDResponse ¶
type SessionIDResponse struct {
SessionID string `json:"session_id"`
}
SessionIDResponse is the JSON returned by the "get-session-id" subcommand.
type TokenUsageResponse ¶
type TokenUsageResponse struct {
InputTokens int `json:"input_tokens"`
CacheCreationTokens int `json:"cache_creation_tokens"`
CacheReadTokens int `json:"cache_read_tokens"`
OutputTokens int `json:"output_tokens"`
APICallCount int `json:"api_call_count"`
SubagentTokens *TokenUsageResponse `json:"subagent_tokens,omitempty"`
}
TokenUsageResponse is the JSON returned by token calculation subcommands.
type TranscriptPositionResponse ¶
type TranscriptPositionResponse struct {
Position int `json:"position"`
}
TranscriptPositionResponse is the JSON returned by the "get-transcript-position" subcommand.