Documentation
¶
Overview ¶
Package toolconfirm centralizes the tool-confirmation policy shared by docker-agent's own confirmation dialog and embedders that bring their own dialog framework (e.g. the Gordon assistant embedded in Docker Sandboxes): the decision set and its runtime resume semantics, the "always allow" permission-pattern construction, key bindings, and the user-facing strings.
Keeping this policy in one runtime-agnostic place matters most for BuildPermissionPattern: the pattern shown to the user ("always allow ls*") and the pattern granted to the runtime must come from the same code, in every UI that hosts a confirmation.
Index ¶
Constants ¶
const ( Title = "Tool Confirmation" Question = "Do you want to allow this tool call?" )
User-facing strings of the confirmation prompt.
const ActionKeys = "YNTA"
ActionKeys are the uppercase action letters of the decision row, in display order. Click hit-testing on the rendered options walks these letters; map a hit back to its decision with DecisionForAction.
Variables ¶
This section is empty.
Functions ¶
func AlwaysAllowLabel ¶
AlwaysAllowLabel is the descriptive label of the "always allow" option for a pattern from BuildPermissionPattern: the command pattern for shell ("always allow ls*"), the tool name otherwise.
func BuildPermissionPattern ¶
BuildPermissionPattern creates the permission pattern granted by the "always allow" decision. For shell commands it extracts the first word of the command and creates a pattern like "shell:cmd=ls*" matching all invocations of that command; for other tools it returns the tool name.
func OptionsHelp ¶
OptionsHelp returns the key/label pairs of the decision row, in display order, ready for a help-keys renderer (e.g. dialog.RenderHelpKeys).
Types ¶
type Decision ¶
type Decision int
Decision is the user's answer to a tool confirmation.
const ( // Approve runs this one call. Approve Decision = iota // ApproveTool runs the call and always allows the tool, scoped by the // permission pattern from BuildPermissionPattern. ApproveTool // ApproveSession runs the call and approves all tools for the rest of // the session. ApproveSession // Reject rejects the call with an optional reason shown to the model. Reject )
func DecisionForAction ¶ added in v1.79.0
DecisionForAction maps an action letter from ActionKeys ("Y", "N", "T", "A") to its decision. ok is false for any other string.
func (Decision) Resume ¶
func (d Decision) Resume(pattern, reason string) runtime.ResumeRequest
Resume translates the decision into the runtime resume request. pattern is the permission pattern for ApproveTool (from BuildPermissionPattern); reason is the optional rejection reason for Reject. Each is ignored by the other decisions.
type KeyMap ¶
KeyMap defines the confirmation key bindings.
func DefaultKeyMap ¶
func DefaultKeyMap() KeyMap
DefaultKeyMap returns the standard confirmation key bindings.
func (KeyMap) DecisionFor ¶ added in v1.79.0
func (k KeyMap) DecisionFor(msg tea.KeyPressMsg) (decision Decision, ok bool)
DecisionFor maps a key press to its decision. ok is false when the key is not a confirmation key. Every UI hosting a confirmation should dispatch through this single mapping so the bindings and their meaning can never drift apart.
type RejectionReason ¶
type RejectionReason struct {
ID string // stable identifier
Label string // short label shown to the user
Value string // model-friendly sentence sent as the rejection reason
}
RejectionReason is one preset answer to "Why reject this tool call?".
func RejectionReasons ¶
func RejectionReasons() []RejectionReason
RejectionReasons returns the preset rejection reasons, in display order.