Class: PromptObjects::Universal::AddCapability

Inherits:
Primitive show all
Defined in:
lib/prompt_objects/universal/add_capability.rb

Overview

Universal capability to add capabilities to a prompt object at runtime. This allows dynamic extension of POs after primitives are created.

Instance Attribute Summary

Attributes inherited from Capability

#state

Instance Method Summary collapse

Methods inherited from Primitive

#initialize

Methods inherited from Capability

#descriptor, execution_policy, execution_policy_definition, #execution_policy_definition, #execution_policy_signature, #initialize, #resolved_execution_policy

Constructor Details

This class inherits a constructor from PromptObjects::Primitive

Instance Method Details

#descriptionObject



12
13
14
# File 'lib/prompt_objects/universal/add_capability.rb', line 12

def description
  "Add an existing capability (a primitive tool or another prompt object) to a prompt object, allowing it to use that capability. Can target self or another PO. Use list_capabilities to discover what's available."
end

#nameObject



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

def name
  "add_capability"
end

#parametersObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/prompt_objects/universal/add_capability.rb', line 16

def parameters
  {
    type: "object",
    properties: {
      target: {
        type: "string",
        description: "Name of the prompt object to add the capability to. Use 'self' for the current PO."
      },
      capability: {
        type: "string",
        description: "Name of the capability to add (must already exist in the registry)"
      }
    },
    required: ["target", "capability"]
  }
end

#receive(message, context:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/prompt_objects/universal/add_capability.rb', line 33

def receive(message, context:)
  target = message[:target] || message["target"]
  capability = message[:capability] || message["capability"]

  # Resolve 'self' to the calling PO (not current_capability which is this tool)
  target = context.calling_po if target == "self"

  # Find the target PO
  target_po = context.env.registry.get(target)
  unless target_po
    return "Error: Prompt object '#{target}' not found"
  end

  unless target_po.is_a?(PromptObject)
    return "Error: '#{target}' is not a prompt object (can only add capabilities to POs)"
  end

  # Check if capability exists
  unless context.env.registry.exists?(capability)
    return "Error: Capability '#{capability}' does not exist"
  end

  # Check if already has it
  current_caps = target_po.config["capabilities"] || []
  if current_caps.include?(capability)
    return "'#{target}' already has the '#{capability}' capability"
  end

  # Add the capability
  target_po.config["capabilities"] ||= []
  target_po.config["capabilities"] << capability

  # Persist to file so it's available on restart
  saved = target_po.save

  # Notify for real-time UI update (don't wait for file watcher)
  context.env.notify_po_modified(target_po)

  if saved
    "Added '#{capability}' to '#{target}' and saved to file. It can now use this capability."
  else
    "Added '#{capability}' to '#{target}' (in-memory only, could not save to file). It can now use this capability."
  end
end