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

Returns a new instance of Context.



46
47
48
49
50
51
52
# File 'lib/kward/plugin_registry.rb', line 46

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.



44
45
46
# File 'lib/kward/plugin_registry.rb', line 44

def args
  @args
end

#workspace_rootObject (readonly)

Returns the value of attribute workspace_root.



44
45
46
# File 'lib/kward/plugin_registry.rb', line 44

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)


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

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)


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

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

#session_idObject



68
69
70
# File 'lib/kward/plugin_registry.rb', line 68

def session_id
  @session&.id
end

#session_nameObject



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

def session_name
  @session&.name
end

#session_pathObject



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

def session_path
  @session&.path
end

#transcriptTranscript

Returns read-only transcript wrapper.

Returns:



55
56
57
# File 'lib/kward/plugin_registry.rb', line 55

def transcript
  Transcript.new(@conversation)
end