Class: Kward::PluginRegistry::Context
- Inherits:
-
Object
- Object
- Kward::PluginRegistry::Context
- Defined in:
- lib/kward/plugin_registry.rb
Overview
Runtime context passed to plugin commands, footers, prompt context renderers, and transcript event handlers.
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#workspace_root ⇒ Object
readonly
Returns the value of attribute workspace_root.
Instance Method Summary collapse
-
#allow(message = nil, metadata: nil) ⇒ Hooks::Decision
Allows the current lifecycle event to continue.
-
#ask(message = nil, metadata: nil) ⇒ Hooks::Decision
Requests frontend approval for the current lifecycle event.
-
#defer(message = nil, payload: nil, metadata: nil) ⇒ Hooks::Decision
Defers the event when the current workflow supports it.
-
#deny(message = nil, metadata: nil) ⇒ Hooks::Decision
Denies the current lifecycle event.
-
#initialize(conversation:, args: "", session: nil, workspace_root: Dir.pwd, say_callback: nil) ⇒ Context
constructor
Creates an object for trusted plugin loading and dispatch.
-
#modify(payload, message: nil, metadata: nil) ⇒ Hooks::Decision
Continues with an event-specific payload replacement.
-
#refresh_system_message! ⇒ nil
Requests that the conversation rebuild its system message after plugin state changes that affect prompt context.
-
#retry(message = nil, payload: nil, metadata: nil) ⇒ Hooks::Decision
Requests a retry when the current event supports it.
-
#say(message) ⇒ nil
Emits command output to the active frontend when available.
-
#session_id ⇒ String?
Active session identifier.
-
#session_name ⇒ String?
Human-readable active session name.
-
#session_path ⇒ String?
Saved active session path.
-
#transcript ⇒ Transcript
Read-only transcript wrapper.
-
#warn(message = nil, metadata: nil) ⇒ Hooks::Decision
Allows the event while recording a warning.
Constructor Details
#initialize(conversation:, args: "", session: nil, workspace_root: Dir.pwd, say_callback: nil) ⇒ Context
Creates an object for trusted plugin loading and dispatch.
68 69 70 71 72 73 74 |
# File 'lib/kward/plugin_registry.rb', line 68 def initialize(conversation:, args: "", session: nil, workspace_root: Dir.pwd, say_callback: nil) @conversation = conversation @args = args.to_s @session = session @workspace_root = workspace_root @say_callback = say_callback end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
65 66 67 |
# File 'lib/kward/plugin_registry.rb', line 65 def args @args end |
#workspace_root ⇒ Object (readonly)
Returns the value of attribute workspace_root.
65 66 67 |
# File 'lib/kward/plugin_registry.rb', line 65 def workspace_root @workspace_root end |
Instance Method Details
#allow(message = nil, metadata: nil) ⇒ Hooks::Decision
Allows the current lifecycle event to continue.
116 117 118 |
# File 'lib/kward/plugin_registry.rb', line 116 def allow( = nil, metadata: nil) Hooks::Decision.allow(, metadata: ) end |
#ask(message = nil, metadata: nil) ⇒ Hooks::Decision
Requests frontend approval for the current lifecycle event.
128 129 130 |
# File 'lib/kward/plugin_registry.rb', line 128 def ask( = nil, metadata: nil) Hooks::Decision.ask(, metadata: ) end |
#defer(message = nil, payload: nil, metadata: nil) ⇒ Hooks::Decision
Defers the event when the current workflow supports it.
153 154 155 |
# File 'lib/kward/plugin_registry.rb', line 153 def defer( = nil, payload: nil, metadata: nil) Hooks::Decision.defer(, payload: payload, metadata: ) end |
#deny(message = nil, metadata: nil) ⇒ Hooks::Decision
Denies the current lifecycle event.
122 123 124 |
# File 'lib/kward/plugin_registry.rb', line 122 def deny( = nil, metadata: nil) Hooks::Decision.deny(, metadata: ) end |
#modify(payload, message: nil, metadata: nil) ⇒ Hooks::Decision
Continues with an event-specific payload replacement.
135 136 137 |
# File 'lib/kward/plugin_registry.rb', line 135 def modify(payload, message: nil, metadata: nil) Hooks::Decision.modify(payload, message: , metadata: ) end |
#refresh_system_message! ⇒ nil
Requests that the conversation rebuild its system message after plugin state changes that affect prompt context.
109 110 111 112 |
# File 'lib/kward/plugin_registry.rb', line 109 def @conversation. if @conversation.respond_to?(:refresh_system_message!) nil end |
#retry(message = nil, payload: nil, metadata: nil) ⇒ Hooks::Decision
Requests a retry when the current event supports it.
147 148 149 |
# File 'lib/kward/plugin_registry.rb', line 147 def retry( = nil, payload: nil, metadata: nil) Hooks::Decision.retry(, payload: payload, metadata: ) end |
#say(message) ⇒ nil
Emits command output to the active frontend when available.
85 86 87 88 |
# File 'lib/kward/plugin_registry.rb', line 85 def say() @say_callback&.call(.to_s) nil end |
#session_id ⇒ String?
Returns active session identifier.
91 92 93 |
# File 'lib/kward/plugin_registry.rb', line 91 def session_id @session&.id end |
#session_name ⇒ String?
Returns human-readable active session name.
96 97 98 |
# File 'lib/kward/plugin_registry.rb', line 96 def session_name @session&.name end |
#session_path ⇒ String?
Returns saved active session path.
101 102 103 |
# File 'lib/kward/plugin_registry.rb', line 101 def session_path @session&.path end |
#transcript ⇒ Transcript
Returns read-only transcript wrapper.
77 78 79 |
# File 'lib/kward/plugin_registry.rb', line 77 def transcript Transcript.new(@conversation) end |
#warn(message = nil, metadata: nil) ⇒ Hooks::Decision
Allows the event while recording a warning.
141 142 143 |
# File 'lib/kward/plugin_registry.rb', line 141 def warn( = nil, metadata: nil) Hooks::Decision.warn(, metadata: ) end |