Class: PromptObjects::Universal::ModifyPrompt
- Inherits:
-
Primitive
- Object
- Capability
- Primitive
- PromptObjects::Universal::ModifyPrompt
- Defined in:
- lib/prompt_objects/universal/modify_prompt.rb
Overview
Universal capability for POs to modify their own or other POs' markdown body (prompt). This enables self-modification of behavior, learning, and identity. Note: This does NOT modify the frontmatter (capabilities, etc.) - use add_capability for that.
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
13 14 15 |
# File 'lib/prompt_objects/universal/modify_prompt.rb', line 13 def description "Modify a prompt object's markdown body (its identity/behavior prompt). Can append, prepend, replace sections, or do a full rewrite. Does NOT change capabilities - use add_capability for that." end |
#name ⇒ Object
9 10 11 |
# File 'lib/prompt_objects/universal/modify_prompt.rb', line 9 def name "modify_prompt" end |
#parameters ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/prompt_objects/universal/modify_prompt.rb', line 17 def parameters { type: "object", properties: { target: { type: "string", description: "Name of the prompt object to modify. Use 'self' for the current PO." }, operation: { type: "string", enum: ["append", "prepend", "replace_section", "rewrite"], description: "Type of modification: 'append' adds to end, 'prepend' adds to beginning, 'replace_section' replaces a specific section, 'rewrite' replaces the entire prompt" }, content: { type: "string", description: "The new content to add or replace with" }, section: { type: "string", description: "(For replace_section only) The section heading to replace (e.g., '## Learnings', '## Behavior'). The section and all content until the next heading of same or higher level will be replaced." } }, required: ["target", "operation", "content"] } end |
#receive(message, context:) ⇒ Object
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/prompt_objects/universal/modify_prompt.rb', line 43 def receive(, context:) target = [:target] || ["target"] operation = [:operation] || ["operation"] content = [:content] || ["content"] section = [:section] || ["section"] # 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 # Get current body current_body = target_po.body || "" # Apply the operation new_body = case operation when "append" append_content(current_body, content) when "prepend" prepend_content(current_body, content) when "replace_section" unless section return "Error: 'section' parameter required for replace_section operation" end replace_section(current_body, section, content) when "rewrite" content else return "Error: Unknown operation '#{operation}'. Use: append, prepend, replace_section, or rewrite" end # Update the PO's body in memory target_po.instance_variable_set(:@body, new_body) # Persist to file saved = target_po.save # Notify for real-time UI update context.env.notify_po_modified(target_po) if saved describe_change(operation, target, section) else "Modified '#{target}' prompt (in-memory only, could not save to file)." end end |