Class: Ace::Task::Molecules::TaskPlanCache
- Inherits:
-
Object
- Object
- Ace::Task::Molecules::TaskPlanCache
- Defined in:
- lib/ace/task/molecules/task_plan_cache.rb
Overview
Manages task plan cache lookup, freshness checks, and artifact writes.
Constant Summary collapse
- LATEST_POINTER =
"latest-plan.md"
Instance Method Summary collapse
- #cache_dir ⇒ Object
- #fresh?(plan_path, task_file:) ⇒ Boolean
-
#initialize(task_id:, cache_root: ".ace-local/task") ⇒ TaskPlanCache
constructor
A new instance of TaskPlanCache.
- #latest_pointer_path ⇒ Object
- #prompts_dir ⇒ Object
- #resolve_latest_plan ⇒ Object
- #write_plan(content:, model:, task_file:, context_files:, prompt_files: nil) ⇒ Object
Constructor Details
#initialize(task_id:, cache_root: ".ace-local/task") ⇒ TaskPlanCache
Returns a new instance of TaskPlanCache.
17 18 19 20 |
# File 'lib/ace/task/molecules/task_plan_cache.rb', line 17 def initialize(task_id:, cache_root: ".ace-local/task") @task_id = task_id @cache_root = cache_root end |
Instance Method Details
#cache_dir ⇒ Object
22 23 24 |
# File 'lib/ace/task/molecules/task_plan_cache.rb', line 22 def cache_dir File.join(Dir.pwd, @cache_root, @task_id) end |
#fresh?(plan_path, task_file:) ⇒ Boolean
41 42 43 44 45 46 47 48 |
# File 'lib/ace/task/molecules/task_plan_cache.rb', line 41 def fresh?(plan_path, task_file:) return false unless File.file?(plan_path) = (plan_path) return false unless fresh_task_file?(, task_file) && fresh_context_files?() end |
#latest_pointer_path ⇒ Object
30 31 32 |
# File 'lib/ace/task/molecules/task_plan_cache.rb', line 30 def latest_pointer_path File.join(cache_dir, LATEST_POINTER) end |
#prompts_dir ⇒ Object
26 27 28 |
# File 'lib/ace/task/molecules/task_plan_cache.rb', line 26 def prompts_dir File.join(cache_dir, "prompts") end |
#resolve_latest_plan ⇒ Object
34 35 36 37 38 39 |
# File 'lib/ace/task/molecules/task_plan_cache.rb', line 34 def resolve_latest_plan from_pointer = resolve_from_pointer return from_pointer if from_pointer plan_files.max_by { |path| File.mtime(path) } end |
#write_plan(content:, model:, task_file:, context_files:, prompt_files: nil) ⇒ Object
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 |
# File 'lib/ace/task/molecules/task_plan_cache.rb', line 50 def write_plan(content:, model:, task_file:, context_files:, prompt_files: nil) FileUtils.mkdir_p(cache_dir) plan_path = build_unique_plan_path = { "task_id" => @task_id, "generated_at" => Time.now.utc.iso8601, "model" => model, "task_file" => { "path" => relative_path(task_file), "mtime" => File.mtime(task_file).to_i }, "context_files" => context_files.map { |path| { "path" => relative_path(path), "mtime" => File.mtime(path).to_i } } } if prompt_files ["prompt_files"] = prompt_files.transform_values { |path| relative_path(path) } end body = "#{YAML.dump()}---\n\n" body << content.to_s.rstrip body << "\n" File.write(plan_path, body) File.write(latest_pointer_path, "#{File.basename(plan_path)}\n") File.write( File.join(cache_dir, "latest-plan.meta.yml"), YAML.dump() ) plan_path end |