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.
72 73 74 75 76 77 78 |
# File 'lib/kward/plugin_registry.rb', line 72 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.
69 70 71 |
# File 'lib/kward/plugin_registry.rb', line 69 def args @args end |
#workspace_root ⇒ Object (readonly)
Returns the value of attribute workspace_root.
69 70 71 |
# File 'lib/kward/plugin_registry.rb', line 69 def workspace_root @workspace_root end |
Instance Method Details
#allow(message = nil, metadata: nil) ⇒ Hooks::Decision
Allows the current lifecycle event to continue.
120 121 122 |
# File 'lib/kward/plugin_registry.rb', line 120 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.
132 133 134 |
# File 'lib/kward/plugin_registry.rb', line 132 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.
157 158 159 |
# File 'lib/kward/plugin_registry.rb', line 157 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.
126 127 128 |
# File 'lib/kward/plugin_registry.rb', line 126 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.
139 140 141 |
# File 'lib/kward/plugin_registry.rb', line 139 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.
113 114 115 116 |
# File 'lib/kward/plugin_registry.rb', line 113 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.
151 152 153 |
# File 'lib/kward/plugin_registry.rb', line 151 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.
89 90 91 92 |
# File 'lib/kward/plugin_registry.rb', line 89 def say() @say_callback&.call(.to_s) nil end |
#session_id ⇒ String?
Returns active session identifier.
95 96 97 |
# File 'lib/kward/plugin_registry.rb', line 95 def session_id @session&.id end |
#session_name ⇒ String?
Returns human-readable active session name.
100 101 102 |
# File 'lib/kward/plugin_registry.rb', line 100 def session_name @session&.name end |
#session_path ⇒ String?
Returns saved active session path.
105 106 107 |
# File 'lib/kward/plugin_registry.rb', line 105 def session_path @session&.path end |
#transcript ⇒ Transcript
Returns read-only transcript wrapper.
81 82 83 |
# File 'lib/kward/plugin_registry.rb', line 81 def transcript Transcript.new(@conversation) end |
#warn(message = nil, metadata: nil) ⇒ Hooks::Decision
Allows the event while recording a warning.
145 146 147 |
# File 'lib/kward/plugin_registry.rb', line 145 def warn( = nil, metadata: nil) Hooks::Decision.warn(, metadata: ) end |