hooks

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package hooks provides lifecycle hook management for contextd

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// AutoCheckpointOnClear enables automatic checkpoint before /clear
	AutoCheckpointOnClear bool `json:"auto_checkpoint_on_clear"`

	// AutoResumeOnStart enables automatic resume on session start
	AutoResumeOnStart bool `json:"auto_resume_on_start"`

	// CheckpointThreshold is the context percentage to trigger checkpoint (70-95)
	CheckpointThreshold int `json:"checkpoint_threshold_percent"`

	// VerifyBeforeClear enables verification before clearing
	VerifyBeforeClear bool `json:"verify_before_clear"`
}

Config holds hook configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads configuration from a JSON file Returns default config if file doesn't exist

func LoadConfigWithEnvOverride

func LoadConfigWithEnvOverride(path string) (*Config, error)

LoadConfigWithEnvOverride loads config from file and applies environment variable overrides

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration

type ConfigFile

type ConfigFile struct {
	Hooks *Config `json:"hooks"`
}

ConfigFile represents the structure of the config file

type HookHandler

type HookHandler func(ctx context.Context, data map[string]interface{}) error

HookHandler is a function that handles a hook event

type HookManager

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

HookManager manages lifecycle hooks

func NewHookManager

func NewHookManager(config *Config) *HookManager

NewHookManager creates a new hook manager

func (*HookManager) Config

func (h *HookManager) Config() *Config

Config returns the hook configuration

func (*HookManager) Execute

func (h *HookManager) Execute(ctx context.Context, hookType HookType, data map[string]interface{}) error

Execute executes all handlers for the given hook type

func (*HookManager) RegisterHandler

func (h *HookManager) RegisterHandler(hookType HookType, handler HookHandler)

RegisterHandler registers a handler for a hook type

type HookType

type HookType string

HookType represents different lifecycle hooks

const (
	// HookSessionStart is called when a new session starts
	HookSessionStart HookType = "session_start"

	// HookSessionEnd is called when a session ends
	HookSessionEnd HookType = "session_end"

	// HookBeforeClear is called before /clear command
	HookBeforeClear HookType = "before_clear"

	// HookAfterClear is called after /clear command
	HookAfterClear HookType = "after_clear"

	// HookContextThreshold is called when context threshold reached
	HookContextThreshold HookType = "context_threshold"
)

Jump to

Keyboard shortcuts

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