supervisor

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 7 Imported by: 1 module, 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 supervisor is the runtime layer's rules engine: a Supervisor observes the effect bus, decides interventions (inject, fork, discard, halt, deny) through registered SupervisionRules, and acts on scopes through the ScopeManager. The scope tree, the merge gate, and the settlement surface live in the root goatherd package; this package owns the rule engine only.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Intervention

type Intervention struct {
	Type    InterventionType
	ScopeID string
	Payload any
	Time    time.Time
}

Intervention is a supervisor action on a sub-agent scope.

type InterventionType

type InterventionType string

InterventionType identifies the kind of supervisor action.

const (
	InterventionInject  InterventionType = "inject"  // push guidance into sub-agent
	InterventionFork    InterventionType = "fork"    // fork before risky action
	InterventionDiscard InterventionType = "discard" // discard failed branch
	InterventionHalt    InterventionType = "halt"    // stop sub-agent
	InterventionDeny    InterventionType = "deny"    // block the tool call before execution
)

type SupervisionRule

type SupervisionRule struct {
	// Name identifies this rule in logs and traces.
	Name string
	// Match returns true if this rule applies to the effect event.
	Match func(trace.EffectEvent) bool
	// Action returns the intervention to take, or nil for observe-only.
	// The scope parameter is the ScopeManager lookup for the event's owner.
	Action func(event trace.EffectEvent) *Intervention
}

SupervisionRule defines when and how to intervene.

func DestructiveToolGuard

func DestructiveToolGuard() SupervisionRule

DestructiveToolGuard returns a rule that DENIES destructive tool calls (blocking them before execution). This is the synchronous variant of DestructiveToolRule — use with CheckCall for pre-execution interception.

Where DestructiveToolRule (the async variant) returns InterventionInject (a warning injected after the fact), DestructiveToolGuard returns InterventionDeny to actually prevent the operation.

Because this is a blocking security boundary, it uses default-deny for bash commands (isBlockableToolCall) rather than the advisory blacklist: shell expansion makes a blacklist trivially bypassable, and a blocking guard must not give false confidence.

func DestructiveToolRule

func DestructiveToolRule() SupervisionRule

DestructiveToolRule intervenes before potentially destructive file operations. Matches bash commands containing rm, mv, chmod, or write tool calls that look like overwrites.

func HighErrorRateRule

func HighErrorRateRule(threshold float64, window int) SupervisionRule

HighErrorRateRule intervenes when a sub-agent's error rate exceeds a threshold within a sliding window of recent tool calls.

This rule maintains per-owner state via closures.

func StuckDetectionRule

func StuckDetectionRule(repeatThreshold int) SupervisionRule

StuckDetectionRule intervenes when a sub-agent repeats the same tool call (by kind label + args hash) more than threshold times in a row.

This rule maintains per-owner state via closures.

type Supervisor

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

Supervisor watches sub-agent effect streams and evaluates rules against each event. When a rule matches, the supervisor emits an Intervention that the orchestrator can act on.

The supervisor is stateless by default — rules that need state (error rates, repetition tracking) maintain their own via closures.

func NewSupervisor

func NewSupervisor(manager *goatherd.ScopeManager, bus *trace.EffectBus) *Supervisor

NewSupervisor creates a supervisor that watches the given bus and evaluates rules against each event. Interventions are sent to the returned channel.

Call Close() to stop the supervisor's background goroutine.

func (*Supervisor) AddRule

func (s *Supervisor) AddRule(rule SupervisionRule)

AddRule registers a supervision rule. Rules are evaluated in order; the first matching rule that produces an intervention wins.

func (*Supervisor) CheckCall

func (s *Supervisor) CheckCall(event trace.EffectEvent) *Intervention

CheckCall evaluates rules synchronously against a tool-call event. Returns nil if the call is approved (no rule matched or all rules returned nil). Returns a non-nil Intervention if a rule wants to block or modify the call.

This is the synchronous counterpart to the async bus loop. The caller (agent loop, pre-tool hook) calls this BEFORE executing the tool and checks the result:

  • nil → proceed with the tool call
  • InterventionDeny → block the tool call, return the reason to the model
  • InterventionInject → proceed but inject guidance into the next turn
  • InterventionHalt → stop the sub-agent entirely

func (*Supervisor) Close

func (s *Supervisor) Close()

Close stops the supervisor and closes the interventions channel. It unsubscribes from the bus and, once the loop has exited (so no in-flight evaluate can send after the close), closes Interventions. Buffered interventions stay receivable after the close. Safe to call multiple times, without a prior Start, and from inside a rule action running on the loop goroutine: the join happens on a separate goroutine, so Close itself never blocks on the loop it is quitting.

func (*Supervisor) Halt

func (s *Supervisor) Halt(scopeID string) error

Halt records a supervisor halt action and marks the scope as discarded.

func (*Supervisor) Inject

func (s *Supervisor) Inject(scopeID, guidance string) error

Inject records a supervisor inject action in the target scope's trace.

func (*Supervisor) Interventions

func (s *Supervisor) Interventions() <-chan Intervention

Interventions returns a receive-only channel of interventions.

func (*Supervisor) ReviewMerge

func (s *Supervisor) ReviewMerge(scopeID string, proposal goatherd.MergeProposal) *Intervention

ReviewMerge evaluates the supervisor's rules against a merge proposal and returns the intervention a rule produced, or nil for approval. It is how a rule engine participates in the review gate: the caller passes the result to its reviewer, records the decision with RecordMergeDecision, and then integrates or discards the child.

The proposal is presented to the rules as a synthetic effect event — Mode Declaration, SchemaRef goatherd.merge.proposed.v1, KindLabel "merge:proposed" — carrying the changed paths, so the same rule set that watches tool calls can watch merges. This is the emitter that makes InterventionDiscard reachable: before it, nothing in the kernel produced one.

The returned intervention is the rules' verdict only; acting on it is the caller's decision, unlike Halt which executes immediately.

func (*Supervisor) Start

func (s *Supervisor) Start(subscriberID string) error

Start begins watching the bus for effect events. It subscribes to the bus and runs a background goroutine that evaluates rules.

It returns an error when the supervisor cannot be activated — notably when it was built without an effect bus — instead of silently no-op'ing (a silent no-op left Close with nothing to stop and a never-closed Interventions channel).

Jump to

Keyboard shortcuts

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