Class: Ace::Hitl::Molecules::HitlCreator
- Inherits:
-
Object
- Object
- Ace::Hitl::Molecules::HitlCreator
- Defined in:
- lib/ace/hitl/molecules/hitl_creator.rb
Instance Method Summary collapse
- #create(title, kind: nil, questions: [], tags: [], assignment: nil, step: nil, step_name: nil, resume_instructions: nil, move_to: nil, time: Time.now.utc) ⇒ Object
-
#initialize(root_dir:, config: {}) ⇒ HitlCreator
constructor
A new instance of HitlCreator.
Constructor Details
#initialize(root_dir:, config: {}) ⇒ HitlCreator
Returns a new instance of HitlCreator.
15 16 17 18 |
# File 'lib/ace/hitl/molecules/hitl_creator.rb', line 15 def initialize(root_dir:, config: {}) @root_dir = root_dir @config = config end |
Instance Method Details
#create(title, kind: nil, questions: [], tags: [], assignment: nil, step: nil, step_name: nil, resume_instructions: nil, move_to: nil, time: Time.now.utc) ⇒ Object
20 21 22 23 24 25 26 27 28 29 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 |
# File 'lib/ace/hitl/molecules/hitl_creator.rb', line 20 def create(title, kind: nil, questions: [], tags: [], assignment: nil, step: nil, step_name: nil, resume_instructions: nil, move_to: nil, time: Time.now.utc) raise ArgumentError, "Title is required" if title.nil? || title.strip.empty? effective_kind = kind || @config.dig("hitl", "default_kind") || "clarification" id = generate_unique_id(time) folder_slug = generate_folder_slug(title) file_slug = generate_file_slug(title) target_dir = determine_target_dir(move_to) FileUtils.mkdir_p(target_dir) folder_name, _ = unique_folder_name(id, folder_slug, target_dir) item_dir = File.join(target_dir, folder_name) FileUtils.mkdir_p(item_dir) frontmatter = { "id" => id, "title" => title, "kind" => effective_kind, "status" => "pending", "tags" => , "questions" => questions, "assignment" => assignment, "step" => step, "step_name" => step_name, "resume_instructions" => resume_instructions, "answered" => false, "created_at" => time }.merge(infer_requester_context(assignment: assignment, step: step)).compact body = build_body(title: title, questions: questions) content = Ace::Support::Items::Atoms::FrontmatterSerializer.rebuild(frontmatter, body) item_file = File.join(item_dir, Atoms::HitlFilePattern.filename(id, file_slug)) File.write(item_file, content) loader = HitlLoader.new special_folder = Ace::Support::Items::Atoms::SpecialFolderDetector.detect_in_path( item_dir, root: @root_dir ) loader.load(item_dir, id: id, special_folder: special_folder) end |