Class: Ace::PromptPrep::Organisms::PromptInitializer
- Inherits:
-
Object
- Object
- Ace::PromptPrep::Organisms::PromptInitializer
- Defined in:
- lib/ace/prompt_prep/organisms/prompt_initializer.rb
Overview
Handles prompt initialization and reset operations
Constant Summary collapse
- DEFAULT_TEMPLATE_URI =
"tmpl://the-prompt-base"- DEFAULT_PROMPT_FILE =
"the-prompt.md"
Class Method Summary collapse
-
.default_prompt_dir ⇒ Object
Get default prompt directory (project-local).
-
.reset(template_uri: DEFAULT_TEMPLATE_URI, target_dir: nil, force: false) ⇒ Hash
Reset prompt to template (archive current).
-
.setup(template_uri: DEFAULT_TEMPLATE_URI, target_dir: nil, force: false) ⇒ Hash
Setup prompt with template.
Class Method Details
.default_prompt_dir ⇒ Object
Get default prompt directory (project-local)
17 18 19 20 |
# File 'lib/ace/prompt_prep/organisms/prompt_initializer.rb', line 17 def default_prompt_dir project_root = Ace::Support::Fs::Molecules::ProjectRootFinder.find_or_current File.join(project_root, ".ace-local", "prompt-prep", "prompts") end |
.reset(template_uri: DEFAULT_TEMPLATE_URI, target_dir: nil, force: false) ⇒ Hash
Reset prompt to template (archive current)
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/ace/prompt_prep/organisms/prompt_initializer.rb', line 112 def reset(template_uri: DEFAULT_TEMPLATE_URI, target_dir: nil, force: false) target_dir ||= default_prompt_dir # Resolve template URI to file path resolve_result = Molecules::TemplateResolver.call(uri: template_uri) unless resolve_result[:success] return { success: false, path: nil, archive_path: nil, error: resolve_result[:error] } end template_path = resolve_result[:path] target_path = File.join(target_dir, DEFAULT_PROMPT_FILE) archive_dir = File.join(target_dir, "archive") # Restore template (archive current if exists) restore_result = Molecules::TemplateManager.restore_template( template_path: template_path, target_path: target_path, archive_dir: archive_dir, force: force ) unless restore_result[:success] return { success: false, path: nil, archive_path: nil, error: restore_result[:error] } end { success: true, path: restore_result[:path], archive_path: restore_result[:archive_path], error: nil } rescue => e { success: false, path: nil, archive_path: nil, error: "Reset failed: #{e.}" } end |
.setup(template_uri: DEFAULT_TEMPLATE_URI, target_dir: nil, force: false) ⇒ Hash
Setup prompt with template
30 31 32 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/ace/prompt_prep/organisms/prompt_initializer.rb', line 30 def setup(template_uri: DEFAULT_TEMPLATE_URI, target_dir: nil, force: false) target_dir ||= default_prompt_dir # Resolve template URI to file path resolve_result = Molecules::TemplateResolver.call(uri: template_uri) unless resolve_result[:success] return { success: false, path: nil, archive_path: nil, error: resolve_result[:error] } end template_path = resolve_result[:path] target_path = File.join(target_dir, DEFAULT_PROMPT_FILE) archive_dir = File.join(target_dir, "archive") # If force is false, use restore_template (which archives) # If force is true, use copy_template (which overwrites) if force copy_result = Molecules::TemplateManager.copy_template( template_path: template_path, target_path: target_path, force: true ) unless copy_result[:success] return { success: false, path: nil, archive_path: nil, error: copy_result[:error] } end { success: true, path: copy_result[:path], archive_path: nil, error: nil } else # Use restore_template to archive existing file restore_result = Molecules::TemplateManager.restore_template( template_path: template_path, target_path: target_path, archive_dir: archive_dir, force: false ) unless restore_result[:success] return { success: false, path: nil, archive_path: nil, error: restore_result[:error] } end { success: true, path: restore_result[:path], archive_path: restore_result[:archive_path], error: nil } end rescue => e { success: false, path: nil, archive_path: nil, error: "Setup failed: #{e.}" } end |