hookspool

package
v0.16.397 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hookspool is the file the agents' lifecycle hooks leave their events in before they call the runtime: an event told while the runtime was away, restarting or too busy to answer is read from the file once it is back, so the end of a turn is not lost with the request that carried it. The hook appends a line and delivers; the runtime applies the lines in the order they were written, each once, and empties the file.

Index

Constants

View Source
const File = "hook-spool.jsonl"

File is the spool's name in the runtime's data folder.

Variables

View Source
var (
	ErrFull = errors.New("hookspool: the spool is full")
	ErrBusy = errors.New("hookspool: the spool is locked")
)

ErrFull is a spool at its limit; ErrBusy, one whose lock did not come in time.

Functions

func Append

func Append(path string, event []byte) error

Append adds one event (a JSON object, with its "id") as a line of the spool.

func NewID

func NewID() string

NewID names an event.

Types

type Queue

type Queue struct {
	// Path is the spool file.
	Path string
	// Apply takes one event; it is called for the events in the order they were written, never twice for an id.
	Apply func(event map[string]any)
	// Ready says whether events can be applied now (nil: always). Until then they stay in the file.
	Ready func() bool
	// contains filtered or unexported fields
}

Queue is the runtime's end of the spool.

func (*Queue) Deliver

func (q *Queue) Deliver(id string, event map[string]any) bool

Deliver is an event the hook brought itself. What the spool holds goes first, so an event the runtime missed is applied before the one that came after it; the event is then applied unless the spool had it. False: events cannot be applied yet, and the event waits in the spool.

func (*Queue) Drain

func (q *Queue) Drain() int

Drain applies what the spool holds and empties it; it returns how many events it applied.

Jump to

Keyboard shortcuts

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