Documentation
¶
Overview ¶
Package approval defines the contract between AI providers that run their own tools (CLI providers such as Claude Code) and the Atmos permission system.
A provider asks an Approver whether a tool invocation may proceed and reports progress events (tool started/finished) so the UI can show what is happening.
Index ¶
Constants ¶
const (
// AskUserQuestionTool is the name of Claude Code's tool for asking the user to choose.
AskUserQuestionTool = "AskUserQuestion"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Approvable ¶
type Approvable interface {
SetApprover(approver Approver)
}
Approvable is implemented by providers that can ask an Approver before running tools.
type ApproverOption ¶
type ApproverOption func(*PermissionApprover)
ApproverOption configures a PermissionApprover.
func WithAsker ¶
func WithAsker(asker Asker) ApproverOption
WithAsker replaces how questions are shown to the user.
func WithPromptHooks ¶
func WithPromptHooks(before, after func()) ApproverOption
WithPromptHooks registers callbacks that run immediately before and after the user is asked a question. Permission prompts get their hooks from permission.WithPromptHooks instead.
type Asker ¶
type Asker interface {
// Available reports whether the user can be asked at all (a terminal is attached).
Available() bool
// Ask shows each question in turn. Pressing ctrl+c returns errUtils.ErrUserAborted.
Ask(ctx context.Context, questions []Question) (map[string]string, error)
}
Asker shows questions to the user and returns their answers keyed by question text.
type Decision ¶
type Decision struct {
// Allow is true when the tool may run.
Allow bool
// UpdatedInput replaces the tool input when Allow is true and it is not nil.
// Questions to the user use it to return the answers.
UpdatedInput map[string]any
// Message is returned to the model when the tool is denied.
Message string
// Interrupt asks the provider to stop the whole run (user pressed Ctrl-C).
Interrupt bool
// NonInteractive is true when approval was required but no terminal was
// available to ask. The provider reports this as an error with a hint
// instead of surfacing the model's prose.
NonInteractive bool
}
Decision is the outcome of an approval request.
type Event ¶
type Event struct {
Kind EventKind
// Tool is the provider's tool name (for example "Bash").
Tool string
// Summary is a short human-readable description (for example "atmos list stacks").
Summary string
}
Event is a provider progress notification.
type PermissionApprover ¶
type PermissionApprover struct {
// contains filtered or unexported fields
}
PermissionApprover answers provider tool requests with the Atmos permission system: ai.tools.mode, the allowed/restricted/blocked lists, the persistent decision cache, and the interactive prompt.
Prompt hooks (for example to pause a spinner) are configured on the checker with permission.WithPromptHooks, so they fire only around real prompts.
func NewPermissionApprover ¶
func NewPermissionApprover(checker *permission.Checker, opts ...ApproverOption) *PermissionApprover
NewPermissionApprover creates an approver backed by the given permission checker.
type ProgressReporter ¶
type ProgressReporter interface {
SetProgressHandler(handler func(Event))
}
ProgressReporter is implemented by providers that can report tool progress.
type Question ¶
type Question struct {
// Question is the full text of the question.
Question string `json:"question"`
// Header is a short label for the question, such as "Beverage".
Header string `json:"header"`
// Options are the choices offered.
Options []QuestionOption `json:"options"`
// MultiSelect allows choosing more than one option.
MultiSelect bool `json:"multiSelect"`
}
Question is one multiple-choice question from the model.
type QuestionOption ¶
QuestionOption is one choice in a Question.
type Request ¶
type Request struct {
// ToolName is the provider's name for the tool (for example "Bash").
ToolName string
// ToolUseID identifies the tool call within the provider's session.
ToolUseID string
// Input holds the tool parameters (for Bash: "command" and "description").
Input map[string]any
}
Request describes a tool invocation that an AI provider wants to run.
type TimeoutManaged ¶
TimeoutManaged is implemented by providers that enforce the run timeout themselves so time spent waiting for a person (approval prompts) does not count. Callers must then use a cancel-only context.