Class: Antigravity::Hooks
- Inherits:
-
Object
- Object
- Antigravity::Hooks
- Defined in:
- lib/antigravity/hooks.rb
Instance Attribute Summary collapse
-
#post_response_hooks ⇒ Object
readonly
Returns the value of attribute post_response_hooks.
-
#post_tool_hooks ⇒ Object
readonly
Returns the value of attribute post_tool_hooks.
-
#pre_prompt_hooks ⇒ Object
readonly
Returns the value of attribute pre_prompt_hooks.
-
#pre_tool_hooks ⇒ Object
readonly
Returns the value of attribute pre_tool_hooks.
Instance Method Summary collapse
- #after_response(&block) ⇒ Object
-
#after_tool_call(&block) ⇒ Object
Filter / sanitize result after a tool runs before model receives it.
- #before_prompt(&block) ⇒ Object
-
#before_tool_call(&block) ⇒ Object
Guard execution before a tool runs.
-
#initialize ⇒ Hooks
constructor
A new instance of Hooks.
- #run_post_response(response) ⇒ Object
- #run_post_tool(tool_name, params, result) ⇒ Object
- #run_pre_prompt(prompt_text) ⇒ Object
- #run_pre_tool(tool_name, params) ⇒ Object
Constructor Details
#initialize ⇒ Hooks
Returns a new instance of Hooks.
7 8 9 10 11 12 |
# File 'lib/antigravity/hooks.rb', line 7 def initialize @pre_prompt_hooks = [] @post_response_hooks = [] @pre_tool_hooks = [] @post_tool_hooks = [] end |
Instance Attribute Details
#post_response_hooks ⇒ Object (readonly)
Returns the value of attribute post_response_hooks.
5 6 7 |
# File 'lib/antigravity/hooks.rb', line 5 def post_response_hooks @post_response_hooks end |
#post_tool_hooks ⇒ Object (readonly)
Returns the value of attribute post_tool_hooks.
5 6 7 |
# File 'lib/antigravity/hooks.rb', line 5 def post_tool_hooks @post_tool_hooks end |
#pre_prompt_hooks ⇒ Object (readonly)
Returns the value of attribute pre_prompt_hooks.
5 6 7 |
# File 'lib/antigravity/hooks.rb', line 5 def pre_prompt_hooks @pre_prompt_hooks end |
#pre_tool_hooks ⇒ Object (readonly)
Returns the value of attribute pre_tool_hooks.
5 6 7 |
# File 'lib/antigravity/hooks.rb', line 5 def pre_tool_hooks @pre_tool_hooks end |
Instance Method Details
#after_response(&block) ⇒ Object
18 19 20 |
# File 'lib/antigravity/hooks.rb', line 18 def after_response(&block) @post_response_hooks << block if block_given? end |
#after_tool_call(&block) ⇒ Object
Filter / sanitize result after a tool runs before model receives it. Block can return modified result.
28 29 30 |
# File 'lib/antigravity/hooks.rb', line 28 def after_tool_call(&block) @post_tool_hooks << block if block_given? end |
#before_prompt(&block) ⇒ Object
14 15 16 |
# File 'lib/antigravity/hooks.rb', line 14 def before_prompt(&block) @pre_prompt_hooks << block if block_given? end |
#before_tool_call(&block) ⇒ Object
Guard execution before a tool runs. Block can return :allow, :deny, or a hash { status: :deny, reason: "..." }
23 24 25 |
# File 'lib/antigravity/hooks.rb', line 23 def before_tool_call(&block) @pre_tool_hooks << block if block_given? end |
#run_post_response(response) ⇒ Object
36 37 38 |
# File 'lib/antigravity/hooks.rb', line 36 def run_post_response(response) @post_response_hooks.each { |hook| hook.call(response) } end |
#run_post_tool(tool_name, params, result) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/antigravity/hooks.rb', line 51 def run_post_tool(tool_name, params, result) current_result = result @post_tool_hooks.each do |hook| modified = hook.call(tool_name, params, current_result) current_result = modified unless modified.nil? end current_result end |
#run_pre_prompt(prompt_text) ⇒ Object
32 33 34 |
# File 'lib/antigravity/hooks.rb', line 32 def run_pre_prompt(prompt_text) @pre_prompt_hooks.each { |hook| hook.call(prompt_text) } end |
#run_pre_tool(tool_name, params) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/antigravity/hooks.rb', line 40 def run_pre_tool(tool_name, params) @pre_tool_hooks.each do |hook| result = hook.call(tool_name, params) if result == :deny || (result.is_a?(Hash) && result[:status] == :deny) reason = result.is_a?(Hash) ? result[:reason] : "Blocked by safety pre-hook policy" return { allowed: false, reason: reason } end end { allowed: true } end |