Class: PromptObjects::Universal::RemoveCapability

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

Overview

Universal capability to remove capabilities from a prompt object. Useful for cleanup or recovery when a capability is broken or no longer needed.

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/remove_capability.rb', line 12

def description
  "Remove a capability from a prompt object. This removes it from the PO's declared capabilities but does NOT delete the underlying primitive/PO file. Use delete_primitive to fully remove a broken primitive."
end

#nameObject



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

def name
  "remove_capability"
end

#parametersObject



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

def parameters
  {
    type: "object",
    properties: {
      target: {
        type: "string",
        description: "Name of the prompt object to remove the capability from. Use 'self' for the current PO."
      },
      capability: {
        type: "string",
        description: "Name of the capability to remove"
      }
    },
    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
# File 'lib/prompt_objects/universal/remove_capability.rb', line 33

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

  # Resolve 'self' to the calling PO
  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"
  end

  # Check if the capability is declared
  current_caps = target_po.config["capabilities"] || []
  unless current_caps.include?(capability)
    return "'#{target}' does not have '#{capability}' in its declared capabilities."
  end

  # Remove the capability
  target_po.config["capabilities"].delete(capability)

  # Persist to file
  saved = target_po.save

  # Notify for real-time UI update
  context.env.notify_po_modified(target_po)

  if saved
    "Removed '#{capability}' from '#{target}' and saved to file."
  else
    "Removed '#{capability}' from '#{target}' (in-memory only, could not save to file)."
  end
end