Class: PromptObjects::Universal::DeletePrimitive
- Inherits:
-
Primitive
- Object
- Capability
- Primitive
- PromptObjects::Universal::DeletePrimitive
- Defined in:
- lib/prompt_objects/universal/delete_primitive.rb
Overview
Universal capability to delete a primitive file from the environment. This is for recovery when a broken primitive is causing problems. USE WITH CAUTION - this permanently deletes the primitive file.
Constant Summary collapse
- PROTECTED_PRIMITIVES =
Built-in primitives that cannot be deleted
%w[read_file list_files write_file http_get think].freeze
Instance Attribute Summary
Attributes inherited from Capability
Instance Method Summary collapse
Methods inherited from Primitive
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
#description ⇒ Object
16 17 18 |
# File 'lib/prompt_objects/universal/delete_primitive.rb', line 16 def description "Delete a primitive (Ruby tool) file from the environment. This is a DESTRUCTIVE operation - use for recovery when a broken primitive is causing problems. Cannot delete built-in primitives." end |
#name ⇒ Object
12 13 14 |
# File 'lib/prompt_objects/universal/delete_primitive.rb', line 12 def name "delete_primitive" end |
#parameters ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/prompt_objects/universal/delete_primitive.rb', line 20 def parameters { type: "object", properties: { primitive: { type: "string", description: "Name of the primitive to delete" }, confirm: { type: "boolean", description: "Must be true to confirm deletion. This is a safety check." } }, required: ["primitive", "confirm"] } end |
#receive(message, context:) ⇒ Object
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 |
# File 'lib/prompt_objects/universal/delete_primitive.rb', line 37 def receive(, context:) primitive_name = [:primitive] || ["primitive"] confirm = [:confirm] || ["confirm"] # Safety check unless confirm == true return "Error: Must set confirm=true to delete a primitive. This is a destructive operation." end # Check if it's a protected primitive if PROTECTED_PRIMITIVES.include?(primitive_name) return "Error: Cannot delete built-in primitive '#{primitive_name}'." end # Check if it's a universal capability if UNIVERSAL_CAPABILITIES.include?(primitive_name) return "Error: Cannot delete universal capability '#{primitive_name}'." end # Find the primitive file primitives_dir = context.env.primitives_dir path = File.join(primitives_dir, "#{primitive_name}.rb") unless File.exist?(path) return "Error: Primitive file not found at #{path}. It may be a built-in primitive or not exist." end # Unregister from registry first context.env.registry.unregister(primitive_name) # Delete the file begin File.delete(path) "Deleted primitive '#{primitive_name}' and removed from registry. File: #{path}" rescue => e "Error deleting file: #{e.}. Primitive was unregistered from memory." end end |