Documentation
¶
Index ¶
- Constants
- Variables
- func AnswerOf(row *runtimetypes.HITLApproval) string
- func CommandLineAllowedByPrefix(line, prefixList string) bool
- func FormatWait(wait time.Duration) string
- func Indefinite(wait time.Duration) bool
- func IndefiniteSpellings() string
- func IsAttentionAsk(row *runtimetypes.HITLApproval) bool
- func IsIndefiniteWord(s string) bool
- func ParseWait(s string) (time.Duration, error)
- func PolicyNameFromContext(ctx context.Context) string
- func ResolveTrustedBinary(name string) (realPath, sha256Hex string, err error)
- func SetAdjudicator(svc Service, adjudicator Adjudicator)
- func SetApprovalCeiling(svc Service, ceiling time.Duration)
- func VetPolicy(data []byte) error
- func WaitOf(timeoutS int) time.Duration
- func WithPolicyName(ctx context.Context, policyName string) context.Context
- func WithShellKind(ctx context.Context, kind string) context.Context
- type Action
- type Adjudication
- type Adjudicator
- type ApprovalRequest
- type AskKind
- type AttentionBounds
- type AttentionRequest
- type ComputeBounds
- type ComputeBoundsReader
- type Condition
- type ConditionOp
- type Decision
- type DecisionOutcome
- type DecisionRecorder
- type EvaluationResult
- type KVReader
- type OnExhausted
- type Policy
- type PolicyEvaluator
- type PolicySource
- type PolicyValidator
- type Rule
- type Service
- type ShellKind
- type TrustedBinaries
- type TrustedBinaryStatus
Constants ¶
const ( AttentionToolsName = "mission" AttentionToolName = "mission_ask_attention" )
const ( ReasonMatchedRule = "matched_rule" ReasonDefaultAction = "default_action" )
const ( ShellKindPOSIX = shellline.KindPOSIX ShellKindPowerShell = shellline.KindPowerShell ShellKindCmd = shellline.KindCmd ShellKindUnknown = shellline.KindUnknown )
const ( TrustedBinaryOK = "ok" TrustedBinaryMissing = "missing" TrustedBinaryMismatch = "mismatch" TrustedBinaryUnreadable = "unreadable" TrustedBinaryOutsideDirs = "outside_dirs" )
const ClientMCPToolsSelector = "@client-mcp"
ClientMCPToolsSelector matches every session-scoped MCP server a client supplied, as opposed to one the operator registered.
const DefaultApprovalCeiling = time.Hour
const DefaultMaxAgentAnswers = 3
const DefaultMaxAgentApprovals = 10
const FallbackApprovalCeiling = MaxRuleTimeoutS * time.Second
FallbackApprovalCeiling bounds an ask no rule and no operator gave a wait: MaxRuleTimeoutS, the longest wait a rule may state.
const MaxRuleTimeoutS = 7 * 24 * 60 * 60
MaxRuleTimeoutS bounds Rule.TimeoutS; every producer of a rule checks against this one value rather than restating seven days.
const PolicySchemaVersion = 1
PolicySchemaVersion is the wire version of the policy document this binary can load.
const TimeoutIndefinite = -1
TimeoutIndefinite is Rule.TimeoutS for an ask with no deadline at all; 0 still means "unset", which falls to the configured ceiling.
const WaitIndefinite = time.Duration(-1)
WaitIndefinite is TimeoutIndefinite as a duration; any negative wait is one.
Variables ¶
var ( ErrApprovalNotFound = errors.New("hitlservice: approval not found") ErrApprovalAlreadyResolved = errors.New("hitlservice: approval already answered") ErrApprovalExpired = errors.New("hitlservice: approval expired before it was answered") )
var ErrAgentAnswerBoundSpent = errors.New("hitlservice: mission agent-answer bound spent")
var ErrAgentApprovalBoundSpent = errors.New("hitlservice: mission agent-approval bound spent")
var ErrAttentionUnanswered = errors.New("hitlservice: attention ask went unanswered")
var ErrEnvelopeVet = errors.New("hitl policy failed validation")
ErrEnvelopeVet marks every defect the envelope vet reports.
var ErrPolicyVersion = errors.New("hitlservice: unsupported hitl policy version")
ErrPolicyVersion reports an envelope whose declared version this binary cannot load.
Functions ¶
func AnswerOf ¶
func AnswerOf(row *runtimetypes.HITLApproval) string
func FormatWait ¶
FormatWait is ParseWait's inverse, so a stored wait reads back as it was written.
func Indefinite ¶
func IndefiniteSpellings ¶
func IndefiniteSpellings() string
func IsAttentionAsk ¶
func IsAttentionAsk(row *runtimetypes.HITLApproval) bool
func IsIndefiniteWord ¶
func ParseWait ¶
ParseWait reads a wait as an operator writes one: a Go duration of whole seconds, or a word for no deadline.
func PolicyNameFromContext ¶
func ResolveTrustedBinary ¶
func SetAdjudicator ¶
func SetAdjudicator(svc Service, adjudicator Adjudicator)
func SetApprovalCeiling ¶
func VetPolicy ¶
VetPolicy validates a hitl-policy document for authoring — JSON shape, unknown fields, rule shapes — then applies validatePolicy, so vet can never pass a policy the runtime would refuse.
func WithPolicyName ¶ added in v0.36.0
Types ¶
type Adjudication ¶
type Adjudicator ¶
type Adjudicator interface {
Adjudicate(ctx context.Context, ask Adjudication)
}
type ApprovalRequest ¶
type ApprovalRequest struct {
ToolCallID string
ToolsName string
ToolName string
Args map[string]any
Diff string
DiffOld string
DiffNew string
PolicyName string
MatchedRule *int
TimeoutS int
OnTimeout Action
// Detail explains the match to the person being asked: which condition
// fired, or why a trusted-binary gate withheld an automatic allow.
Detail string
InstanceID string
SessionID string
AgentName string
MissionID string
}
type AttentionBounds ¶
type AttentionBounds struct {
AllowAgentAnswers bool `json:"allowAgentAnswers,omitempty"`
MaxAgentAnswers int `json:"maxAgentAnswers,omitempty"`
AllowAgentApprovals bool `json:"allowAgentApprovals,omitempty"`
MaxAgentApprovals int `json:"maxAgentApprovals,omitempty"`
}
func (AttentionBounds) EffectiveMaxAgentAnswers ¶
func (b AttentionBounds) EffectiveMaxAgentAnswers() int
func (AttentionBounds) EffectiveMaxAgentApprovals ¶
func (b AttentionBounds) EffectiveMaxAgentApprovals() int
type AttentionRequest ¶
type ComputeBounds ¶
type ComputeBounds struct {
MaxTurns int `json:"maxTurns,omitempty"`
MaxToolCalls int `json:"maxToolCalls,omitempty"`
MaxTokens int `json:"maxTokens,omitempty"`
ModelAllowlist []string `json:"modelAllowlist,omitempty"`
BackendAllowlist []string `json:"backendAllowlist,omitempty"`
OnExhausted OnExhausted `json:"onExhausted,omitempty"`
}
type ComputeBoundsReader ¶
type ComputeBoundsReader interface {
ComputeBoundsFor(ctx context.Context, policyName string) (ComputeBounds, error)
}
type Condition ¶
type Condition struct {
Key string `json:"key"`
Op ConditionOp `json:"op"`
Value string `json:"value"`
}
type ConditionOp ¶
type ConditionOp string
const ( OpEq ConditionOp = "eq" OpGlob ConditionOp = "glob" OpHost ConditionOp = "host" OpCommandBlacklist ConditionOp = "command_blacklist" OpCommandAskAlways ConditionOp = "command_ask_always" OpNoCommandSubstitution ConditionOp = "no_command_substitution" OpCommandPrefixAllowlist ConditionOp = "command_prefix_allowlist" )
type Decision ¶
type Decision struct {
Outcome DecisionOutcome
DecidedBy string // for example "acp_client"
AskedAt time.Time
}
Decision describes a finished interactive ask, for the audit record.
type DecisionOutcome ¶
type DecisionOutcome string
DecisionOutcome is how an interactive approval ask ended.
const ( DecisionApproved DecisionOutcome = "approved" DecisionDenied DecisionOutcome = "denied" // DecisionTimedOut means nobody answered before the rule's deadline. DecisionTimedOut DecisionOutcome = "timeout" // DecisionCancelled means the ask was abandoned (turn cancelled, client gone // or the client answered "cancelled"); nothing was approved. DecisionCancelled DecisionOutcome = "cancelled" )
type DecisionRecorder ¶
type DecisionRecorder interface {
RecordDecision(ctx context.Context, req ApprovalRequest, d Decision) error
}
DecisionRecorder writes a resolved hitl_approvals row for an ask that was answered outside the durable RequestApproval flow (for example by an ACP client through session/request_permission). It records after the fact and never changes the approval outcome.
type EvaluationResult ¶
type OnExhausted ¶
type OnExhausted string
const ( OnExhaustedFinishStuck OnExhausted = "finish_stuck" OnExhaustedPauseAsk OnExhausted = "pause_ask" )
type Policy ¶
type Policy struct {
// Version is the envelope's wire version; absent (0) means
// PolicySchemaVersion.
Version int `json:"version,omitempty"`
DefaultAction Action `json:"default_action,omitempty"`
Rules []Rule `json:"rules"`
Compute *ComputeBounds `json:"compute,omitempty"`
Attention *AttentionBounds `json:"attention,omitempty"`
// TrustedBinaries gates every allow that a command_prefix_allowlist grants
// on the identity and integrity of the resolved binary; nil is inert.
TrustedBinaries *TrustedBinaries `json:"trusted_binaries,omitempty"`
}
type PolicyEvaluator ¶
type PolicySource ¶
type PolicySource interface {
ReadPolicy(ctx context.Context, tenantID, name string) ([]byte, error)
}
func NewFSPolicySource ¶
func NewFSPolicySource(dirs ...string) PolicySource
type PolicyValidator ¶
func NewPolicyValidator ¶
func NewPolicyValidator(src PolicySource, tenantID, fallbackPolicy string) PolicyValidator
type Service ¶
type Service interface {
PolicyEvaluator
RequestApproval(ctx context.Context, req ApprovalRequest, sink taskengine.TaskEventSink) (bool, error)
Respond(ctx context.Context, approvalID string, approved bool) error
RequestAttention(ctx context.Context, req AttentionRequest, sink taskengine.TaskEventSink) (string, error)
Answer(ctx context.Context, askID, text string) error
AnswerAsAgent(ctx context.Context, askID, text string) error
PendingAttentionAsks(ctx context.Context, missionID string) ([]*runtimetypes.HITLApproval, error)
AttentionBoundsFor(ctx context.Context, policyName string) (AttentionBounds, error)
AgentAnswerCount(ctx context.Context, missionID string) (int, error)
SweepExpired(ctx context.Context) (int, error)
ListPending(ctx context.Context, limit int) ([]*runtimetypes.HITLApproval, error)
}
func New ¶
func New(src PolicySource, tenantID string, store KVReader, tracker libtracker.ActivityTracker) Service
func NewWithDefaultPolicy ¶
func NewWithDefaultPolicy(src PolicySource, tenantID string, store KVReader, tracker libtracker.ActivityTracker, fallbackPolicy string) Service
type ShellKind ¶
func ShellKindFromContext ¶
type TrustedBinaries ¶
type TrustedBinaryStatus ¶
type TrustedBinaryStatus struct {
Path string `json:"path"`
State string `json:"state"`
Actual string `json:"actual,omitempty"`
Detail string `json:"detail,omitempty"`
}
func CheckTrustedBinaries ¶
func CheckTrustedBinaries(tb *TrustedBinaries) []TrustedBinaryStatus
func (TrustedBinaryStatus) String ¶
func (s TrustedBinaryStatus) String() string