Documentation
ΒΆ
Index ΒΆ
- type Engine
- func (r *Engine) AddCronJob(ctx context.Context, job *cron.CronJob) error
- func (r *Engine) AddRelayBinding(ctx context.Context, binding *relay.RelayBinding) error
- func (r *Engine) CheckDanger(prompt string) (blocked bool, operation, reason string)
- func (r *Engine) CleanupSessionFiles(sessionID string) error
- func (r *Engine) CleanupSessionFilesDirect(providerSessionID, workDir string) error
- func (r *Engine) Close() error
- func (r *Engine) DeleteCronJob(ctx context.Context, id string) error
- func (r *Engine) EnterDrain(msg string)
- func (r *Engine) Execute(ctx context.Context, cfg *types.Config, prompt string, callback event.Callback) error
- func (r *Engine) ExitDrain()
- func (r *Engine) GetAllowedTools() []string
- func (r *Engine) GetCLIVersion() (string, error)
- func (r *Engine) GetCronRuns(ctx context.Context, jobID string) ([]*cron.CronRun, error)
- func (r *Engine) GetDisallowedTools() []string
- func (r *Engine) GetDrainMessage() string
- func (e *Engine) GetOptions() EngineOptions
- func (r *Engine) GetSession(sessionID string) (*intengine.Session, bool)
- func (r *Engine) GetSessionManager() intengine.SessionManager
- func (r *Engine) GetSessionStats(sessionID string) *SessionStats
- func (e *Engine) HandleRelay(ctx context.Context, req *RelayRequest) (*RelayResponse, error)
- func (r *Engine) IsDraining() bool
- func (r *Engine) ListCronJobs(ctx context.Context) ([]*cron.CronJob, error)
- func (r *Engine) ListRelayBindings(ctx context.Context) ([]*relay.RelayBinding, error)
- func (r *Engine) PauseCronJob(ctx context.Context, id string) error
- func (r *Engine) PermissionMatcher() *permission.PermissionMatcher
- func (r *Engine) RemoveRelayBinding(ctx context.Context, chatID string) error
- func (r *Engine) ResumeCronJob(ctx context.Context, id string) error
- func (r *Engine) SendRelay(ctx context.Context, to, content string) (*relay.RelayResponse, error)
- func (r *Engine) SetAllowedTools(tools []string)
- func (r *Engine) SetDangerAllowPaths(paths []string)
- func (r *Engine) SetDangerBypassEnabled(token string, enabled bool) error
- func (r *Engine) SetDisallowedTools(tools []string)
- func (r *Engine) SetPermissionMatcher(m *permission.PermissionMatcher)
- func (r *Engine) StopSession(sessionID string, reason string) error
- func (r *Engine) ValidateConfig(cfg *types.Config) error
- type EngineOptions
- type RelayExecutor
- type RelayRequest
- type RelayResponse
- type SessionStats
- func (s *SessionStats) EndGeneration()
- func (s *SessionStats) EndThinking()
- func (s *SessionStats) FinalizeDuration() *SessionStats
- func (s *SessionStats) GetCurrentToolID() string
- func (s *SessionStats) GetCurrentToolName() string
- func (s *SessionStats) GetToolNameByToolID(toolID string) string
- func (s *SessionStats) RecordFileModification(filePath string)
- func (s *SessionStats) RecordTokens(input, output, cacheWrite, cacheRead int32)
- func (s *SessionStats) RecordToolResult(toolID string) (durationMs int64, toolName string)
- func (s *SessionStats) RecordToolUse(toolName, toolID string)
- func (s *SessionStats) StartGeneration()
- func (s *SessionStats) StartThinking()
- func (s *SessionStats) ToSummary() map[string]interface{}
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type Engine ΒΆ
type Engine struct {
// contains filtered or unexported fields
}
Engine is the core Control Plane for AI CLI agent integration. Configured as a long-lived Singleton, it transforms local CLI tools into production-ready services by managing a hot-multiplexed process pool, enforcing security WAF rules, and providing a unified event-driven SDK for application integration.
func NewEngine ΒΆ
func NewEngine(options EngineOptions) (*Engine, error)
NewEngine creates a new HotPlex Engine instance.
func (*Engine) AddCronJob ΒΆ added in v0.35.0
AddCronJob adds a new cron job to the scheduler.
func (*Engine) AddRelayBinding ΒΆ added in v0.35.0
AddRelayBinding adds a new relay binding.
func (*Engine) CheckDanger ΒΆ added in v0.18.0
CheckDanger exposes the WAF danger detector to the chatapps layer. Returns blocked=true if the prompt matches dangerous patterns. chatapps uses this for pre-flight WAF checks before calling Execute.
func (*Engine) CleanupSessionFiles ΒΆ added in v0.17.0
CleanupSessionFiles deletes all session files associated with the provider session. This handles the complete removal of context on disk for commands like /reset. Note: This method requires the session to still exist in the pool. Use CleanupSessionFilesDirect if the session has already been terminated.
func (*Engine) CleanupSessionFilesDirect ΒΆ added in v0.29.0
CleanupSessionFilesDirect deletes session files using explicit IDs. Use this when the session has already been terminated and removed from the pool. This is the safe way to cleanup after StopSession has been called.
func (*Engine) Close ΒΆ
Close terminates all active sessions managed by this runner and cleans up resources. It triggers Graceful Shutdown by cascading termination signals down to the SessionManager, which drops the entire process group (PGID) to prevent zombie processes.
func (*Engine) DeleteCronJob ΒΆ added in v0.35.0
DeleteCronJob removes a cron job from the scheduler.
func (*Engine) EnterDrain ΒΆ added in v0.35.0
EnterDrain puts the engine into drain mode. New sessions will be rejected while existing sessions continue.
func (*Engine) Execute ΒΆ
func (r *Engine) Execute(ctx context.Context, cfg *types.Config, prompt string, callback event.Callback) error
Execute runs Claude Code CLI with the given configuration and streams
func (*Engine) ExitDrain ΒΆ added in v0.35.0
func (r *Engine) ExitDrain()
ExitDrain exits drain mode.
func (*Engine) GetAllowedTools ΒΆ added in v0.11.0
GetAllowedTools returns the current allowed tools list. Thread-safe: uses internal mutex.
func (*Engine) GetCLIVersion ΒΆ
GetCLIVersion returns the Claude Code CLI version.
func (*Engine) GetCronRuns ΒΆ added in v0.35.0
GetCronRuns returns all runs for a job.
func (*Engine) GetDisallowedTools ΒΆ added in v0.11.0
GetDisallowedTools returns the current disallowed tools list. Thread-safe: uses internal mutex.
func (*Engine) GetDrainMessage ΒΆ added in v0.35.0
GetDrainMessage returns the current drain message.
func (*Engine) GetOptions ΒΆ added in v0.21.0
func (e *Engine) GetOptions() EngineOptions
GetOptions returns the current engine options.
func (*Engine) GetSession ΒΆ added in v0.12.0
GetSession retrieves an active session by sessionID. Returns the session and true if found, or nil and false if not found.
func (*Engine) GetSessionManager ΒΆ added in v0.32.0
func (r *Engine) GetSessionManager() intengine.SessionManager
GetSessionManager returns the underlying session manager for admin operations.
func (*Engine) GetSessionStats ΒΆ
func (r *Engine) GetSessionStats(sessionID string) *SessionStats
GetSessionStats returns a copy of the accumulated session stats.
func (*Engine) HandleRelay ΒΆ added in v0.35.0
func (e *Engine) HandleRelay(ctx context.Context, req *RelayRequest) (*RelayResponse, error)
HandleRelay processes an incoming relay message.
func (*Engine) IsDraining ΒΆ added in v0.35.0
IsDraining returns true if the engine is in drain mode.
func (*Engine) ListCronJobs ΒΆ added in v0.35.0
ListCronJobs returns all cron jobs.
func (*Engine) ListRelayBindings ΒΆ added in v0.35.0
ListRelayBindings returns all relay bindings.
func (*Engine) PauseCronJob ΒΆ added in v0.35.0
PauseCronJob pauses a cron job.
func (*Engine) PermissionMatcher ΒΆ added in v0.31.9
func (r *Engine) PermissionMatcher() *permission.PermissionMatcher
PermissionMatcher returns the engine's permission matcher.
func (*Engine) RemoveRelayBinding ΒΆ added in v0.35.0
RemoveRelayBinding removes a relay binding by chat ID.
func (*Engine) ResumeCronJob ΒΆ added in v0.35.0
ResumeCronJob resumes a paused cron job.
func (*Engine) SendRelay ΒΆ added in v0.35.0
SendRelay sends a message to a remote agent via the relay network.
func (*Engine) SetAllowedTools ΒΆ added in v0.11.0
SetAllowedTools sets the allowed tools for the engine. This affects new sessions created after the call. Thread-safe: uses internal mutex.
func (*Engine) SetDangerAllowPaths ΒΆ
SetDangerAllowPaths sets the allowed safe paths for the danger detector.
func (*Engine) SetDangerBypassEnabled ΒΆ
SetDangerBypassEnabled enables or disables danger detection bypass. WARNING: Only use for Evolution mode (admin only).
func (*Engine) SetDisallowedTools ΒΆ added in v0.11.0
SetDisallowedTools sets the disallowed tools for the engine. This affects new sessions created after the call. Thread-safe: uses internal mutex.
func (*Engine) SetPermissionMatcher ΒΆ added in v0.31.9
func (r *Engine) SetPermissionMatcher(m *permission.PermissionMatcher)
SetPermissionMatcher sets the permission matcher for the engine.
func (*Engine) StopSession ΒΆ
StopSession terminates a running session by session ID. This is the implementation for session.stop from the spec.
type EngineOptions ΒΆ
type EngineOptions = intengine.EngineOptions
EngineOptions defines the configuration parameters for initializing a new HotPlex Engine. It allows customization of timeouts, logging, and foundational security boundaries that apply to all sessions managed by this engine instance.
type RelayExecutor ΒΆ added in v0.35.0
type RelayExecutor interface {
HandleRelay(ctx context.Context, req *RelayRequest) (*RelayResponse, error)
}
RelayExecutor handles cross-instance relay requests.
type RelayRequest ΒΆ added in v0.35.0
type RelayRequest struct {
From string `json:"from"`
To string `json:"to"`
SessionKey string `json:"session_key"`
Message string `json:"message"`
}
RelayRequest is the input for a relay operation.
type RelayResponse ΒΆ added in v0.35.0
type RelayResponse = relay.RelayResponse
RelayResponse is the result of a relay operation.
type SessionStats ΒΆ
type SessionStats struct {
SessionID string `json:"session_id"`
StartTime time.Time `json:"-"` // Internal use only, use ToSummary() for JSON
TotalDurationMs int64 `json:"total_duration_ms"`
ThinkingDurationMs int64 `json:"thinking_duration_ms"`
ToolDurationMs int64 `json:"tool_duration_ms"`
GenerationDurationMs int64 `json:"generation_duration_ms"`
InputTokens int32 `json:"input_tokens"`
OutputTokens int32 `json:"output_tokens"`
CacheWriteTokens int32 `json:"cache_write_tokens"`
CacheReadTokens int32 `json:"cache_read_tokens"`
ToolCallCount int32 `json:"tool_call_count"`
ToolsUsed map[string]bool `json:"-"` // Internal set, use ToSummary() for array
FilesModified int32 `json:"files_modified"`
FilePaths []string `json:"file_paths"`
// contains filtered or unexported fields
}
SessionStats collects session-level statistics for Geek/Evolution modes.
func (*SessionStats) EndGeneration ΒΆ
func (s *SessionStats) EndGeneration()
EndGeneration marks the end of the generation phase and records its duration.
func (*SessionStats) EndThinking ΒΆ
func (s *SessionStats) EndThinking()
EndThinking marks the end of the thinking phase and records its duration.
func (*SessionStats) FinalizeDuration ΒΆ
func (s *SessionStats) FinalizeDuration() *SessionStats
FinalizeDuration finalizes any ongoing phase tracking and returns the final stats.
func (*SessionStats) GetCurrentToolID ΒΆ added in v0.13.0
func (s *SessionStats) GetCurrentToolID() string
GetCurrentToolID returns the current tool ID being tracked. Returns empty string if no tool is currently being tracked.
func (*SessionStats) GetCurrentToolName ΒΆ added in v0.13.0
func (s *SessionStats) GetCurrentToolName() string
GetCurrentToolName returns the current tool name being tracked. Returns empty string if no tool is currently being tracked.
func (*SessionStats) GetToolNameByToolID ΒΆ added in v0.15.0
func (s *SessionStats) GetToolNameByToolID(toolID string) string
GetToolNameByToolID returns the tool name for a given tool ID. This is useful when tool_result events don't include tool_name. Returns empty string if tool ID is not found.
func (*SessionStats) RecordFileModification ΒΆ
func (s *SessionStats) RecordFileModification(filePath string)
RecordFileModification records that a file was modified. Uses O(1) map lookup for deduplication instead of O(n) linear scan.
func (*SessionStats) RecordTokens ΒΆ
func (s *SessionStats) RecordTokens(input, output, cacheWrite, cacheRead int32)
RecordTokens records token usage.
func (*SessionStats) RecordToolResult ΒΆ
func (s *SessionStats) RecordToolResult(toolID string) (durationMs int64, toolName string)
RecordToolResult records the end of a tool call. If RecordToolUse was not called (e.g., Claude Code didn't send tool_use event), this will record a minimal duration (1ms) to indicate the tool completed.
func (*SessionStats) RecordToolUse ΒΆ
func (s *SessionStats) RecordToolUse(toolName, toolID string)
RecordToolUse records the start of a tool call.
func (*SessionStats) StartGeneration ΒΆ
func (s *SessionStats) StartGeneration()
StartGeneration marks the start of the generation phase.
func (*SessionStats) StartThinking ΒΆ
func (s *SessionStats) StartThinking()
StartThinking marks the start of the thinking phase.
func (*SessionStats) ToSummary ΒΆ
func (s *SessionStats) ToSummary() map[string]interface{}
ToSummary converts stats to a summary map for JSON serialization.