Class: Kward::PluginRegistry::Context

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(conversation:, args: "", session: nil, workspace_root: Dir.pwd, say_callback: nil) ⇒ Context

Creates an object for trusted plugin loading and dispatch.



54
55
56
57
58
59
60
# File 'lib/kward/plugin_registry.rb', line 54

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

#argsObject (readonly)

Returns the value of attribute args.



51
52
53
# File 'lib/kward/plugin_registry.rb', line 51

def args
  @args
end

#workspace_rootObject (readonly)

Returns the value of attribute workspace_root.



51
52
53
# File 'lib/kward/plugin_registry.rb', line 51

def workspace_root
  @workspace_root
end

Instance Method Details

#refresh_system_message!nil

Requests that the conversation rebuild its system message after plugin state changes that affect prompt context.

Returns:

  • (nil)


92
93
94
95
# File 'lib/kward/plugin_registry.rb', line 92

def refresh_system_message!
  @conversation.refresh_system_message! if @conversation.respond_to?(:refresh_system_message!)
  nil
end

#say(message) ⇒ nil

Emits command output to the active frontend when available.

Parameters:

  • message (#to_s)

    message to display

Returns:

  • (nil)


71
72
73
74
# File 'lib/kward/plugin_registry.rb', line 71

def say(message)
  @say_callback&.call(message.to_s)
  nil
end

#session_idObject



76
77
78
# File 'lib/kward/plugin_registry.rb', line 76

def session_id
  @session&.id
end

#session_nameObject



80
81
82
# File 'lib/kward/plugin_registry.rb', line 80

def session_name
  @session&.name
end

#session_pathObject



84
85
86
# File 'lib/kward/plugin_registry.rb', line 84

def session_path
  @session&.path
end

#transcriptTranscript

Returns read-only transcript wrapper.

Returns:



63
64
65
# File 'lib/kward/plugin_registry.rb', line 63

def transcript
  Transcript.new(@conversation)
end