Class: Ace::Review::Molecules::GoalsBrief

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/review/molecules/goals_brief.rb

Overview

One content-addressed summary of the change goal, shared by review scopes. Sources and their authority are supplied by the caller from exact git refs.

Constant Summary collapse

CONTRACT =
"review-goals-v3"
DEFAULT_MODELS =
["pi:glmflash", "gemini:flash-latest"].freeze
MAX_BRIEF_TOKENS =
6_000
SYSTEM_PROMPT =
<<~PROMPT
  Summarize project requirements for a code reviewer. Return only JSON with keys:
  objective ({"text":"...","sources":["source-id"],"status":"accepted|proposed"}),
  accepted_requirements (array), constraints (accepted-only array),
  proposed_constraints (array), proposed_changes (array), deferred (array).
  Each array item must be
  {"text":"...","sources":["source-id"]}. Cite only provided source IDs.
  Cite the objective and every item. An accepted objective, requirement,
  or constraint may cite only accepted base sources. Keep PR-head
  constraints and goals explicitly proposed, not accepted authority.
  Preserve explicit constraints and deferred scope. Do not invent decisions.
PROMPT

Instance Method Summary collapse

Constructor Details

#initialize(project_root:, llm_executor: nil, cache_store: nil, model_resolver: nil, system_prompt: SYSTEM_PROMPT) ⇒ GoalsBrief

Returns a new instance of GoalsBrief.



32
33
34
35
36
37
38
# File 'lib/ace/review/molecules/goals_brief.rb', line 32

def initialize(project_root:, llm_executor: nil, cache_store: nil, model_resolver: nil, system_prompt: SYSTEM_PROMPT)
  @project_root = project_root
  @llm_executor = llm_executor || LlmExecutor.new
  @cache_store = cache_store || Ace::Compressor::Molecules::CacheStore.new(project_root: project_root)
  @model_resolver = model_resolver || method(:resolve_model)
  @system_prompt = system_prompt
end

Instance Method Details

#prepare(sources:, session_dir:, models: DEFAULT_MODELS, generate: false) ⇒ Object



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
# File 'lib/ace/review/molecules/goals_brief.rb', line 40

def prepare(sources:, session_dir:, models: DEFAULT_MODELS, generate: false)
  source_manifest = normalize_sources(sources)
  return failure("Goals brief needs at least one source") if source_manifest.empty?

  last_error = nil
  candidates = Array(models).filter_map do |candidate|
    resolved = @model_resolver.call(candidate)
    if resolved && resolved.split("@").first.match?(/\A[^:]+:\z/)
      last_error = "Goals-brief model selector must name a model: #{candidate}"
      next
    end
    [candidate, resolved] if resolved
  end
  candidates.each do |_candidate, resolved|
    key = cache_key(source_manifest, resolved)
    paths = cache_paths(source_manifest, key)
    cached = read_cache(paths, key)
    return materialize(cached.merge(cache_hit: true), source_manifest, session_dir) if cached
  end

  candidates.each do |candidate, resolved|
    next unless generate

    key = cache_key(source_manifest, resolved)
    paths = cache_paths(source_manifest, key)
    result = generate_brief(source_manifest, candidate, resolved, session_dir)
    unless result[:success]
      last_error = result[:error]
      next
    end

    write_cache(paths, key, result)
    return materialize(result.merge(cache_hit: false), source_manifest, session_dir)
  end

  message = generate ? "No goals-brief model completed" :
    "Goals brief is not cached; run ace-review --pr <number> --preset <preset> --prepare-goals-brief"
  failure(last_error || message)
end