Documentation
¶
Overview ¶
Package supervisor is the E25 layered answerer (design §8.3-8.4). It polls for pending job interactions and either auto-answers the narrow low-risk slice (choice + enumerable options + whitelisted prompt) or escalates everything else (confirmation / free-text question / no-options / over-rounds / non-whitelisted) to a human via the E36 mailbox.
Honest scope (design §11): auto-answer is deliberately收窄 — its coverage is low by design; the real value is reliable ROUTING (discover pending → escalate to the right inbox), not autonomously answering. Escalation is the default; auto-answer only fires when explicitly opted into (AutoAnswer=true AND a prompt matches the whitelist).
Layering (G022): supervisor consumes job + presence via the narrow JobOps / PresenceOps interfaces it defines here (dependency inversion, mirroring job's WorkflowAdvancer). job and presence never import supervisor.
Index ¶
Constants ¶
const ( DefaultInterval = 5 * time.Second DefaultMaxRounds = 3 // DefaultEscalateTo is the global escalation recipient when the policy leaves // escalate_to empty. role-one:<role> targets a SINGLE online supervisor (取一, // design §8.1) so multiple online sups don't race to answer the same interaction // (role: would fan out to ALL of them). Changed from role:supervisor in // supervisor-routing P1.2. DefaultEscalateTo = "role-one:supervisor" // DefaultOwnerAnswerTimeout bounds how long an interaction may sit escalated to // its owner (L1) before the router falls it back to the global sup (L2). The // owner is会话式 and may have ended without answering (design §8.2 / §5.4); the // fallback keeps the chain converging instead of悬死. Applied when the policy // leaves OwnerAnswerTimeout <=0 (supervisor-routing P2.1). DefaultOwnerAnswerTimeout = 5 * time.Minute )
DefaultInterval / DefaultMaxRounds are the poller cadence and per-job auto-answer budget defaults (design §8.4 熔断).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JobOps ¶
type JobOps interface {
ListPendingInteractions() ([]job.Interaction, error)
// AnswerInteractionAuto answers as the L0 built-in rule answerer, stamping
// answered_by=auto:<policy> (监督分层升级路由 P3.2 审计区分). The L0 path has its own
// decide() gate, so it is never subject to the P3.1派生作答闸. Satisfied by
// job.Service.AnswerInteractionAuto.
AnswerInteractionAuto(jobID, interactionID, answer, policy string) (job.Interaction, error)
// Get returns the job snapshot (owner routing columns OriginAgent/EscalateTo) for
// owner-first escalation (§8.1). The bool is false for an unknown id, in which case
// the zero JobResult (empty owner cols) routes straight to the global policy.
// Satisfied by job.Service.Get.
Get(jobID string) (job.JobResult, bool)
// MarkInteractionEscalated stamps interactions.escalated_at (escalate dedup +
// owner-timeout clock, design §8.1/§9), replacing the old in-memory escalated map
// so dedup survives a serve restart. Satisfied by job.Service.MarkInteractionEscalated.
MarkInteractionEscalated(jobID, interactionID string, ts int64) error
}
JobOps is the narrow job-service capability the supervisor needs. job.Service satisfies it. ErrJobTerminal (a zombie interaction whose job已终态) is surfaced so tick can skip it silently (复审 #4).
type Policy ¶
type Policy struct {
Enabled bool
Interval time.Duration
AutoAnswer bool
EscalateTo string // a to-spec ("role-one:supervisor" | "role:..." | a concrete agent_id); default DefaultEscalateTo
MaxRoundsPerJob int
AllowPromptRegex []string
// OwnerAnswerTimeout is how long an interaction may sit escalated to its owner
// (L1) before the router falls it back past the owner to the global sup (L2,
// design §8.2, P2.1). <=0 applies DefaultOwnerAnswerTimeout in NewService.
OwnerAnswerTimeout time.Duration
}
Policy configures the answerer. The zero value is inert (Enabled=false). Empty AllowPromptRegex means NOTHING is whitelisted → every choice escalates too (auto-answer must be explicitly opted into via a matching pattern).
type PresenceOps ¶
PresenceOps is the narrow mailbox capability used to escalate to a human/agent. presence.Service satisfies it.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the layered answerer. nowFn is injectable for tests; the per-job round budget (rounds) is guarded by mu. Escalate dedup is NO LONGER in-memory — it lives in interactions.escalated_at (design §9, P1.2), so it survives a serve restart.
func NewService ¶
func NewService(jobs JobOps, presence PresenceOps, policy Policy) *Service
NewService builds a Service, applying defaults for a zero Interval / MaxRounds / EscalateTo and compiling the prompt whitelist (an invalid pattern is dropped with a warning rather than failing construction).
func (*Service) Run ¶
Run is the poller loop: it ticks once immediately then every Interval until ctx is cancelled (serve shutdown). A disabled policy returns at once (no goroutine churn). Tick errors are logged, never fatal.
func (*Service) SetWake ¶
func (s *Service) SetWake(f func())
SetWake injects the event-driven sup dispatch trigger (y5wt). serve wires it to the reconciler's wake channel so escalate() can demand a sup on the spot; a nil f resets to no-op. Call before Run (or any escalate); not safe to race with a running tick.