answerguard

package
v0.154.5 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 3 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 answerguard is the派生作答白名单闸 (监督分层升级路由 P3.1, design §8.5/§10). It堵 the "any driver may answer any interaction" security gap: a通用 supervisor (role=supervisor) answering an interaction it did NOT launch must pass the SAME whitelist a L0 auto-answer would (type=choice + enumerable options + prompt matches allow_prompt_regex); anything高危 (confirmation / free-text / non-whitelisted) is refused so the interaction stays pending and escalates to a human (L3).

Owner (responder==job.origin_agent) and人 (no driver identity) are放行 unconditionally — they hold the plan context / are human-authorized, so they answer等同人 (design §8.5).

Layering (G021/G022): this package is deliberately self-contained — it imports NEITHER internal/job NOR internal/supervisor, so it can be the shared seam both the answer path (job.Service, via the job.AnswerGuard interface it satisfies structurally) and any future caller reuse without a dependency cycle. The role lookup is injected through the narrow RoleLookup interface (satisfied by presence.Service.Role), so answerguard does not import presence either.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAllowed = errors.New("answer not allowed")

ErrNotAllowed is returned (wrapped) by Check when a supervisor driver may not answer the interaction. The answer path maps it to a refusal that keeps the interaction pending (and surfaces a 403 over HTTP).

Functions

This section is empty.

Types

type Guard

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

Guard holds the compiled prompt whitelist + the role lookup seam. The zero value is not usable; build with New.

func New

func New(allowRegex []string, roles RoleLookup) *Guard

New compiles allowRegex into the prompt whitelist and binds the role lookup. An invalid pattern is dropped (so it never silently widens the gate) — mirroring supervisor.NewService. roles may be nil (role lookup then always misses → only owner/human are放行, every other responder is treated as non-supervisor and放行; a nil-roles guard therefore only enforces the owner/human distinction, which is the conservative degraded mode).

func (*Guard) Check

func (g *Guard) Check(responder, originAgent, itType string, hasOptions bool, prompt string) error

Check decides whether responder may answer the interaction. It returns nil to allow, or an ErrNotAllowed-wrapped error to refuse (caller keeps the interaction pending).

Source grading (design §8.5):

  • responder=="" → human (web/CLI, no driver identity) → allow.
  • responder==originAgent → owner (L1, holds plan context) → allow.
  • presence role != supervisor → another trusted driver → allow (not gated).
  • presence role == supervisor (and not the owner) → L2 sup → gate: only a whitelisted choice with enumerable options passes; confirmation / free-text / no-options / non-whitelisted prompt → refuse.

type RoleLookup

type RoleLookup interface {
	Role(agentID string) (string, bool)
}

RoleLookup resolves a driver agent_id to its presence role. The bool is false for an unknown/expired agent_id (treated as a non-supervisor → not gated). presence.Service satisfies it structurally via its Role method.

Jump to

Keyboard shortcuts

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