Class: RubynCode::Hooks::Response
- Inherits:
-
Object
- Object
- RubynCode::Hooks::Response
- Defined in:
- lib/rubyn_code/hooks/response.rb
Overview
Normalized response from an external (Claude Code-style) hook.
External hooks communicate control-flow decisions and prompt augmentations back to the agent via JSON. This class wraps the parsed response and provides predicate methods so call sites don’t have to know the response shape details.
Supported response shapes (any subset can be combined):
{ "continue": false, "stopReason": "Denied by policy" }
— ask the agent to stop. stopReason is appended to the conversation.
{ "decision": "block", "reason": "rm -rf is forbidden" }
— for PreToolUse only; abort this tool call before it runs.
{ "decision": "approve" } or { "decision": undefined }
— allow the call to proceed (default).
{
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"additionalContext": "Project policy: always run rubocop before commit"
}
}
— additionalContext is injected into the next system prompt / LLM
request so the model sees the hook's guidance.
{ "suppressOutput": true }
— UI hook wants to silence default output rendering (e.g. streamed
json progress). Best-effort; honoured by the renderer when present.
Instance Attribute Summary collapse
-
#additional_context ⇒ String?
readonly
AdditionalContext injected into the next LLM call.
-
#hook_event_name ⇒ Object
readonly
Returns the value of attribute hook_event_name.
-
#reason ⇒ String?
readonly
Reason text for block/stop decisions.
-
#stop_reason ⇒ Object
readonly
Returns the value of attribute stop_reason.
Instance Method Summary collapse
-
#additional_context? ⇒ Boolean
True if the hook has context to inject.
-
#block? ⇒ Boolean
True if the hook says to abort a PreToolUse call.
-
#initialize(raw: {}) ⇒ Response
constructor
A new instance of Response.
-
#stop? ⇒ Boolean
True if the hook says to stop the agent entirely.
-
#suppress_output? ⇒ Boolean
True if the hook wants output suppressed.
-
#to_h ⇒ Hash
The raw JSON response (for debugging/logging).
Constructor Details
#initialize(raw: {}) ⇒ Response
Returns a new instance of Response.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rubyn_code/hooks/response.rb', line 44 def initialize(raw: {}) @raw = raw || {} @decision = @raw['decision'] @continue = @raw.key?('continue') ? @raw['continue'] : true @stop_reason = @raw['stopReason'] @reason = @raw['reason'] @suppress = @raw['suppressOutput'] == true specific = @raw['hookSpecificOutput'].is_a?(Hash) ? @raw['hookSpecificOutput'] : {} @hook_event_name = specific['hookEventName'] @additional_context = specific['additionalContext'] end |
Instance Attribute Details
#additional_context ⇒ String? (readonly)
Returns additionalContext injected into the next LLM call.
40 41 42 |
# File 'lib/rubyn_code/hooks/response.rb', line 40 def additional_context @additional_context end |
#hook_event_name ⇒ Object (readonly)
Returns the value of attribute hook_event_name.
42 43 44 |
# File 'lib/rubyn_code/hooks/response.rb', line 42 def hook_event_name @hook_event_name end |
#reason ⇒ String? (readonly)
Returns reason text for block/stop decisions.
37 38 39 |
# File 'lib/rubyn_code/hooks/response.rb', line 37 def reason @reason end |
#stop_reason ⇒ Object (readonly)
Returns the value of attribute stop_reason.
42 43 44 |
# File 'lib/rubyn_code/hooks/response.rb', line 42 def stop_reason @stop_reason end |
Instance Method Details
#additional_context? ⇒ Boolean
Returns true if the hook has context to inject.
68 69 70 |
# File 'lib/rubyn_code/hooks/response.rb', line 68 def additional_context? !@additional_context.nil? && !@additional_context.to_s.empty? end |
#block? ⇒ Boolean
Returns true if the hook says to abort a PreToolUse call.
58 59 60 |
# File 'lib/rubyn_code/hooks/response.rb', line 58 def block? @decision == 'block' end |
#stop? ⇒ Boolean
Returns true if the hook says to stop the agent entirely.
63 64 65 |
# File 'lib/rubyn_code/hooks/response.rb', line 63 def stop? @continue == false end |
#suppress_output? ⇒ Boolean
Returns true if the hook wants output suppressed.
73 74 75 |
# File 'lib/rubyn_code/hooks/response.rb', line 73 def suppress_output? @suppress end |
#to_h ⇒ Hash
Returns the raw JSON response (for debugging/logging).
78 79 80 |
# File 'lib/rubyn_code/hooks/response.rb', line 78 def to_h @raw end |