hooks

package
v0.1.147 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 21 Imported by: 0

Documentation

Overview

Package hooks watches filesystem paths and spawns tasks when things change.

Index

Constants

View Source
const (
	EventFsCreate = "fs.create"
	EventFsWrite  = "fs.write"
	EventFsDelete = "fs.delete"
)

Variables

This section is empty.

Functions

func DecodeToken

func DecodeToken(stored []byte) (string, error)

func EncodeToken

func EncodeToken(raw string) ([]byte, error)

func HookAgentKey added in v0.1.73

func HookAgentKey(path string) string

func HydrateHookAgent added in v0.1.73

func HydrateHookAgent(
	ctx context.Context,
	backend repository.BackendRepository,
	hook *types.Hook,
)

func NormalizePath

func NormalizePath(p string) string

func ParseUint

func ParseUint(v any) uint

func ResolveHookAgent added in v0.1.73

func ResolveHookAgent(
	ctx context.Context,
	backend repository.BackendRepository,
	workspaceID uint,
	path string,
	existingAgentID *string,
	patch *AgentConfigPatch,
) (*types.AgentProfile, error)

func ValidateHookPath added in v0.1.32

func ValidateHookPath(path string) error

ValidateHookPath checks if a path is valid for hook creation. This is a basic sanity check blocking obvious invalid paths. The real validation (checking for external_id) happens on the frontend.

Hooks cannot be attached to:

  • System root directories (/tasks, /tools, /skills, /sources)
  • Root-level source folders (/sources/gmail, /sources/github)

Hooks CAN be attached to:

  • Source view folders under sources (/sources/gmail/my-query)
  • Top-level query folders (/my-emails)

Types

type AgentConfigPatch added in v0.1.73

type AgentConfigPatch struct {
	Name             *string
	Runner           *string
	Model            *string
	SystemPrompt     *string
	SystemPromptMode *string
	WorkspaceDir     *string
}

type CompareResult added in v0.1.91

type CompareResult struct {
	Added   []string
	Removed []string
}

CompareResult holds the diff between previous and current ID sets.

type ContextEnricher added in v0.1.125

type ContextEnricher interface {
	FetchSourceContent(ctx context.Context, workspaceID uint, integration string, data map[string]any) string
	FetchViewRows(ctx context.Context, workspaceID uint, taskID string, queryHint string) string
}

type Engine

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

func NewEngine

func NewEngine(store repository.FilesystemStore, creator TaskCreator, backend repository.BackendRepository, skillReader SkillReader) *Engine

func (*Engine) Handle

func (eng *Engine) Handle(id string, data map[string]any)

func (*Engine) InvalidateCache

func (eng *Engine) InvalidateCache(wsId uint)

func (*Engine) Poll

func (eng *Engine) Poll(ctx context.Context)

Poll is retained as a no-op for compatibility with existing tests.

func (*Engine) SetContextEnricher added in v0.1.125

func (eng *Engine) SetContextEnricher(enricher ContextEnricher)

func (*Engine) Start

func (eng *Engine) Start(ctx context.Context)

Start blocks until the engine context is cancelled.

type SeenTracker

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

SeenTracker detects new and removed query result IDs by diffing against the previous set. Usage: Compare (read-only) → act on added/removed IDs → Commit (update stored set). This two-phase approach ensures the stored set only advances after the caller has successfully processed the changes.

func NewSeenTracker

func NewSeenTracker(rdb *common.RedisClient) *SeenTracker

func (*SeenTracker) Commit

func (t *SeenTracker) Commit(ctx context.Context, key string, current []string) error

Commit replaces the stored set with current and marks the key as initialized. Call only after the caller has successfully acted on the new IDs from Compare.

func (*SeenTracker) Compare

func (t *SeenTracker) Compare(ctx context.Context, key string, current []string) (*CompareResult, error)

Compare diffs current against the stored set at key, returning added and removed IDs. Does NOT modify the stored set — call Commit after successful processing. On first call, Added contains all current IDs and Removed is empty.

func (*SeenTracker) Reset added in v0.1.73

func (t *SeenTracker) Reset(ctx context.Context, key string) error

Reset clears both the tracked ID set and initialization marker for a key. The next Compare call for this key will behave like a first observation.

func (*SeenTracker) ResetPath added in v0.1.73

func (t *SeenTracker) ResetPath(ctx context.Context, workspaceID uint, path string) error

ResetPath clears seen state for a workspace + hook path.

type Service

type Service struct {
	Store    repository.FilesystemStore
	Backend  repository.BackendRepository
	EventBus *common.EventBus
	Seen     *SeenTracker
}

Service handles hook CRUD. Shared by HTTP and gRPC handlers.

func (*Service) Create

func (s *Service) Create(
	ctx context.Context,
	wsId uint,
	memberId, tokenId *uint,
	rawToken, path, prompt string,
	skillPaths []string,
	eventTypes []string,
	agentPatch *AgentConfigPatch,
) (*types.Hook, error)

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, externalId string) error

func (*Service) Get

func (s *Service) Get(ctx context.Context, externalId string) (*types.Hook, error)

func (*Service) List

func (s *Service) List(ctx context.Context, wsId uint) ([]*types.Hook, error)

func (*Service) ListRuns

func (s *Service) ListRuns(ctx context.Context, hookId uint) ([]*types.RunExecution, error)

ListRuns returns tasks associated with a hook.

func (*Service) Update

func (s *Service) Update(
	ctx context.Context,
	externalId string,
	prompt *string,
	active *bool,
	skillPaths *[]string,
	eventTypes *[]string,
	agentPatch *AgentConfigPatch,
) (*types.Hook, error)

type SkillReader added in v0.1.32

type SkillReader interface {
	// ReadSkillContent reads the SKILL.md file for a skill path (e.g., /skills/email-triage).
	// Returns the full content of the SKILL.md file.
	ReadSkillContent(ctx context.Context, workspaceId uint, skillPath string) (string, error)
}

SkillReader reads skill content from workspace storage.

type SourcePoller

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

SourcePoller periodically syncs source views watched by active hooks. Each view is locked via Redis SETNX so only one replica refreshes it per interval.

func NewSourcePoller

func NewSourcePoller(store repository.FilesystemStore, refresher ViewSyncer, rdb *common.RedisClient) *SourcePoller

func (*SourcePoller) Poll

func (p *SourcePoller) Poll(ctx context.Context)

Poll fetches stale watched queries and refreshes them with distributed locking.

func (*SourcePoller) PollNow added in v0.1.142

func (p *SourcePoller) PollNow(ctx context.Context)

PollNow refreshes all watched queries immediately, bypassing stale thresholds and distributed locks. Intended for test mode.

func (*SourcePoller) Start

func (p *SourcePoller) Start(ctx context.Context)

Start runs the poll loop. Call as a goroutine.

type SourceWatchFinder added in v0.1.115

type SourceWatchFinder interface {
	FindTasksByCorrelationKeys(ctx context.Context, integration string, keys []string) ([]repository.TaskSourceWatchMatch, error)
}

SourceWatchFinder looks up sleeping tasks that have registered interest in a particular integration entity via correlation keys (cross-workspace).

type StorageSkillReader added in v0.1.32

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

StorageSkillReader reads skill content from S3.

func NewStorageSkillReader added in v0.1.32

func NewStorageSkillReader(storage *clients.StorageClient, backend repository.BackendRepository) *StorageSkillReader

func (*StorageSkillReader) ReadSkillContent added in v0.1.32

func (r *StorageSkillReader) ReadSkillContent(ctx context.Context, workspaceId uint, skillPath string) (string, error)

ReadSkillContent reads SKILL.md for a skill path like "/skills/email-triage".

type TaskCreator

type TaskCreator interface {
	CreateTask(ctx context.Context, hook *types.Hook, eventID, event, prompt string, data map[string]any) error
}

type TaskFactory added in v0.1.47

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

TaskFactory bridges hook events into the agent orchestration pipeline.

func NewTaskFactory added in v0.1.47

func (*TaskFactory) CreateTask added in v0.1.47

func (f *TaskFactory) CreateTask(
	ctx context.Context,
	hook *types.Hook,
	eventID, event, prompt string,
	data map[string]any,
) error

CreateTask implements hooks.TaskCreator.

func (*TaskFactory) SetContextEnricher added in v0.1.125

func (f *TaskFactory) SetContextEnricher(enricher ContextEnricher)

func (*TaskFactory) SetSourceWatchFinder added in v0.1.115

func (f *TaskFactory) SetSourceWatchFinder(finder SourceWatchFinder)

type TaskInputSubmitter added in v0.1.142

type TaskInputSubmitter interface {
	SubmitTaskInput(ctx context.Context, workspaceID uint, taskID string, kind types.InputKind, action *types.TaskInputAction, message, idempotencyKey string, items []types.ItemDecision) (*types.AgentTask, error)
}

TaskInputSubmitter delivers input to a task (used to wake sleeping tasks).

type ViewSyncer added in v0.1.50

type ViewSyncer interface {
	RefreshQuery(ctx context.Context, query *types.FilesystemQuery) error
}

ViewSyncer re-executes a source view query and emits change events. Implemented by SourceService in the gateway layer.

Jump to

Keyboard shortcuts

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