Documentation
¶
Overview ¶
Package budget enforces the pyry-side --max-turns cap for agent-run by counting assistant JSONL entries and signalling the claude child when the budget is reached.
In `claude -p` mode, claude exits after --max-turns natively. Interactive claude — what `pyry agent-run` spawns — does not, so pyry must enforce the cap itself. The Counter is a leaf unit consumable by the downstream agent-run driver: wire (*Counter).OnEvent and (*Counter).OnEndOfTurn to the matching fields on tail.Config, and the Counter's Terminate / Kill hooks to cmd.Process.Signal(SIGTERM) / SIGKILL respectively.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// MaxTurns is the assistant-entry cap. Required; must be > 0.
MaxTurns int
// Terminate is invoked exactly once when the assistant-entry count
// reaches MaxTurns on a non-end_turn event. Production wires this to
// cmd.Process.Signal(syscall.SIGTERM).
Terminate func() error
// Kill is invoked exactly once after GracePeriod elapses if Stop has not
// been called. Production wires this to cmd.Process.Signal(syscall.SIGKILL).
Kill func() error
// GracePeriod is the SIGTERM→SIGKILL window. Zero defaults to 5s.
GracePeriod time.Duration
// Logger is optional; defaults to slog.Default().
Logger *slog.Logger
}
Config configures a Counter. MaxTurns, Terminate, and Kill are required; New returns an error otherwise.
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter counts assistant JSONL entries and enforces the MaxTurns budget by invoking Terminate when the count reaches MaxTurns, then escalating to Kill after GracePeriod.
Safe for concurrent use. In production OnEvent / OnEndOfTurn fire from the tail.Watcher.Run goroutine, the grace timer fires from time.AfterFunc's goroutine, and Stop / Reason fire from the driver goroutine.
func New ¶
New constructs a Counter. Validates required fields, defaults GracePeriod to 5s and Logger to slog.Default().
func (*Counter) OnEndOfTurn ¶
func (c *Counter) OnEndOfTurn()
OnEndOfTurn wires to tail.Config.OnEndOfTurn. Records completion as the terminal reason unless the budget has already fired.
func (*Counter) OnEvent ¶
OnEvent wires to tail.Config.OnEvent. Counts assistant entries and triggers Terminate when the budget is reached on a non-end_turn event.