Class: PromptObjects::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/prompt_objects/environment.rb

Overview

Context object passed to capabilities during execution. Provides access to environment, message bus, and tracks execution.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env:, bus:, human_queue: nil) ⇒ Context

Returns a new instance of Context.



10
11
12
13
14
15
16
17
# File 'lib/prompt_objects/environment.rb', line 10

def initialize(env:, bus:, human_queue: nil)
  @env = env
  @bus = bus
  @human_queue = human_queue
  @current_capability = nil
  @calling_po = nil  # The PO that initiated the tool call (for resolving "self")
  @tui_mode = false
end

Instance Attribute Details

#busObject (readonly)

Returns the value of attribute bus.



7
8
9
# File 'lib/prompt_objects/environment.rb', line 7

def bus
  @bus
end

#calling_poObject

Returns the value of attribute calling_po.



8
9
10
# File 'lib/prompt_objects/environment.rb', line 8

def calling_po
  @calling_po
end

#current_capabilityObject

Returns the value of attribute current_capability.



8
9
10
# File 'lib/prompt_objects/environment.rb', line 8

def current_capability
  @current_capability
end

#envObject (readonly)

Returns the value of attribute env.



7
8
9
# File 'lib/prompt_objects/environment.rb', line 7

def env
  @env
end

#human_queueObject (readonly)

Returns the value of attribute human_queue.



7
8
9
# File 'lib/prompt_objects/environment.rb', line 7

def human_queue
  @human_queue
end

#tui_modeObject

Returns the value of attribute tui_mode.



8
9
10
# File 'lib/prompt_objects/environment.rb', line 8

def tui_mode
  @tui_mode
end

Instance Method Details

#env_data_scopeString?

Resolve the workspace scope for shared environment data.

Returns:

  • (String, nil)

    Scope id, or nil if it can't be resolved



21
22
23
24
25
26
27
28
29
30
# File 'lib/prompt_objects/environment.rb', line 21

def env_data_scope
  store = env.session_store
  return nil unless store

  if env.respond_to?(:env_data_scope)
    env.env_data_scope
  elsif env.respond_to?(:active_session_id) && env.active_session_id
    env.active_session_id
  end
end

#log_message(to:, message:) ⇒ Object

Log a message to the bus.

Parameters:

  • to (String)

    Destination capability

  • message (String, Hash)

    The message



35
36
37
# File 'lib/prompt_objects/environment.rb', line 35

def log_message(to:, message:)
  @bus.publish(from: @current_capability || "human", to: to, message: message)
end

#log_response(from:, message:) ⇒ Object

Log a response to the bus.

Parameters:

  • from (String)

    Source capability

  • message (String, Hash)

    The response



42
43
44
# File 'lib/prompt_objects/environment.rb', line 42

def log_response(from:, message:)
  @bus.publish(from: from, to: @current_capability || "human", message: message)
end