Class: Woods::Console::Confirmation

Inherits:
Object
  • Object
show all
Defined in:
lib/woods/console/confirmation.rb

Overview

Human-in-the-loop confirmation protocol for Tier 4 tools.

Supports three modes:

  • ‘:auto_approve` — Always approve (for testing/trusted environments)

  • ‘:auto_deny` — Always deny (for locked-down environments)

  • ‘:callback` — Delegates to a callable that returns true/false

Tracks confirmation history for audit purposes.

Examples:

Auto-approve mode

confirmation = Confirmation.new(mode: :auto_approve)
confirmation.request_confirmation(tool: 'eval', description: '1+1', params: {})
# => true

Callback mode

confirmation = Confirmation.new(mode: :callback, callback: ->(req) { req[:tool] != 'eval' })
confirmation.request_confirmation(tool: 'sql', description: 'SELECT 1', params: {})
# => true

Constant Summary collapse

VALID_MODES =
%i[auto_approve auto_deny callback].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mode:, callback: nil) ⇒ Confirmation

Returns a new instance of Confirmation.

Parameters:

  • mode (Symbol)

    One of :auto_approve, :auto_deny, :callback

  • callback (Proc, nil) (defaults to: nil)

    Required when mode is :callback

Raises:

  • (ArgumentError)

    if mode is invalid or callback is missing for callback mode



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/woods/console/confirmation.rb', line 38

def initialize(mode:, callback: nil)
  unless VALID_MODES.include?(mode)
    raise ArgumentError, "Invalid mode: #{mode}. Must be one of: #{VALID_MODES.join(', ')}"
  end

  raise ArgumentError, 'Callback required for callback mode' if mode == :callback && callback.nil?

  @mode = mode
  @callback = callback
  @history = []
end

Instance Attribute Details

#historyArray<Hash> (readonly)

Returns History of confirmation requests and outcomes.

Returns:

  • (Array<Hash>)

    History of confirmation requests and outcomes



33
34
35
# File 'lib/woods/console/confirmation.rb', line 33

def history
  @history
end

Instance Method Details

#request_confirmation(tool:, description:, params:) ⇒ Object

Request confirmation for a Tier 4 operation.

Parameters:

  • tool (String)

    Tool name

  • description (String)

    Human-readable description of the action

  • params (Hash)

    Tool parameters

Raises:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/woods/console/confirmation.rb', line 56

def request_confirmation(tool:, description:, params:)
  approved = evaluate(tool: tool, description: description, params: params)

  @history << {
    tool: tool,
    description: description,
    params: params,
    approved: approved,
    timestamp: Time.now.utc.iso8601
  }

  return if approved

  raise ConfirmationDeniedError, "Confirmation denied for #{tool}: #{description}"
end