hitlservice

package
v1.0.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 28 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

Index

Constants

View Source
const (
	AttentionToolsName = "mission"
	AttentionToolName  = "mission_ask_attention"
)
View Source
const (
	ReasonMatchedRule   = "matched_rule"
	ReasonDefaultAction = "default_action"
)
View Source
const (
	ShellKindPOSIX      = shellline.KindPOSIX
	ShellKindPowerShell = shellline.KindPowerShell
	ShellKindCmd        = shellline.KindCmd
	ShellKindUnknown    = shellline.KindUnknown
)
View Source
const (
	TrustedBinaryOK          = "ok"
	TrustedBinaryMissing     = "missing"
	TrustedBinaryMismatch    = "mismatch"
	TrustedBinaryUnreadable  = "unreadable"
	TrustedBinaryOutsideDirs = "outside_dirs"
)
View Source
const ClientMCPToolsSelector = "@client-mcp"

ClientMCPToolsSelector matches every session-scoped MCP server a client supplied, as opposed to one the operator registered.

View Source
const DefaultApprovalCeiling = time.Hour
View Source
const DefaultMaxAgentAnswers = 3
View Source
const DefaultMaxAgentApprovals = 10
View Source
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.

View Source
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.

View Source
const PolicySchemaVersion = 1

PolicySchemaVersion is the wire version of the policy document this binary can load.

View Source
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.

View Source
const WaitIndefinite = time.Duration(-1)

WaitIndefinite is TimeoutIndefinite as a duration; any negative wait is one.

Variables

View Source
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")
)
View Source
var ErrAgentAnswerBoundSpent = errors.New("hitlservice: mission agent-answer bound spent")
View Source
var ErrAgentApprovalBoundSpent = errors.New("hitlservice: mission agent-approval bound spent")
View Source
var ErrAttentionUnanswered = errors.New("hitlservice: attention ask went unanswered")
View Source
var ErrEnvelopeVet = errors.New("hitl policy failed validation")

ErrEnvelopeVet marks every defect the envelope vet reports.

View Source
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 CommandLineAllowedByPrefix

func CommandLineAllowedByPrefix(line, prefixList string) bool

func FormatWait

func FormatWait(wait time.Duration) string

FormatWait is ParseWait's inverse, so a stored wait reads back as it was written.

func Indefinite

func Indefinite(wait time.Duration) bool

func IndefiniteSpellings

func IndefiniteSpellings() string

func IsAttentionAsk

func IsAttentionAsk(row *runtimetypes.HITLApproval) bool

func IsIndefiniteWord

func IsIndefiniteWord(s string) bool

func ParseWait

func ParseWait(s string) (time.Duration, error)

ParseWait reads a wait as an operator writes one: a Go duration of whole seconds, or a word for no deadline.

func PolicyNameFromContext

func PolicyNameFromContext(ctx context.Context) string

func ResolveTrustedBinary

func ResolveTrustedBinary(name string) (realPath, sha256Hex string, err error)

func SetAdjudicator

func SetAdjudicator(svc Service, adjudicator Adjudicator)

func SetApprovalCeiling

func SetApprovalCeiling(svc Service, ceiling time.Duration)

func VetPolicy

func VetPolicy(data []byte) error

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 WaitOf

func WaitOf(timeoutS int) time.Duration

func WithPolicyName added in v0.36.0

func WithPolicyName(ctx context.Context, policyName string) context.Context

func WithShellKind

func WithShellKind(ctx context.Context, kind string) context.Context

Types

type Action

type Action string
const (
	ActionAllow   Action = "allow"
	ActionApprove Action = "approve"
	ActionDeny    Action = "deny"
)

type Adjudication

type Adjudication struct {
	AskID       string
	Kind        AskKind
	MissionID   string
	SessionID   string
	InstanceID  string
	AgentName   string
	Summary     string
	Detail      string
	ToolsName   string
	ToolName    string
	ArgsSummary string
	Diff        string
	PolicyName  string
	MatchedRule string
	OnTimeout   string
}

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 AskKind

type AskKind string
const (
	AskKindPermission AskKind = "permission"
	AskKindAttention  AskKind = "attention"
)

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 AttentionRequest struct {
	Summary    string
	Detail     string
	MissionID  string
	InstanceID string
	SessionID  string
	AgentName  string

	OnRaised func(askID string)
}

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 EvaluationResult struct {
	Action      Action
	MatchedRule *int
	Reason      string
	// Detail explains the match in words a person can act on: which condition
	// fired, and why a trusted-binary gate withheld an allow.
	Detail     string
	TimeoutS   int
	OnTimeout  Action
	PolicyName string
}

type KVReader

type KVReader interface {
	GetKV(ctx context.Context, key string, out interface{}) error
}

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 PolicyEvaluator interface {
	Evaluate(ctx context.Context, toolsName, toolName string, args map[string]any) (EvaluationResult, error)
}

type PolicySource

type PolicySource interface {
	ReadPolicy(ctx context.Context, tenantID, name string) ([]byte, error)
}

func NewFSPolicySource

func NewFSPolicySource(dirs ...string) PolicySource

type PolicyValidator

type PolicyValidator interface {
	ValidatePolicy(ctx context.Context, policyName string) error
}

func NewPolicyValidator

func NewPolicyValidator(src PolicySource, tenantID, fallbackPolicy string) PolicyValidator

type Rule

type Rule struct {
	Tools     string      `json:"tools"`
	Tool      string      `json:"tool"`
	When      []Condition `json:"when,omitempty"`
	Action    Action      `json:"action"`
	TimeoutS  int         `json:"timeout_s,omitempty"`
	OnTimeout Action      `json:"on_timeout,omitempty"`
}

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

type ShellKind = shellline.Kind

func ShellKindFromContext

func ShellKindFromContext(ctx context.Context) ShellKind

type TrustedBinaries

type TrustedBinaries struct {
	Dirs   []string          `json:"dirs,omitempty"`
	Hashes map[string]string `json:"hashes,omitempty"`
}

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

Jump to

Keyboard shortcuts

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