Class: Ace::Docs::Organisms::CrossDocumentAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/docs/organisms/cross_document_analyzer.rb

Overview

Orchestrates cross-document consistency analysis using LLM

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CrossDocumentAnalyzer

Returns a new instance of CrossDocumentAnalyzer.



26
27
28
29
30
31
32
# File 'lib/ace/docs/organisms/cross_document_analyzer.rb', line 26

def initialize(options = {})
  @options = options
  @registry = Organisms::DocumentRegistry.new(
    project_root: options[:project_root],
    scope_globs: options[:scope_globs]
  )
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



24
25
26
# File 'lib/ace/docs/organisms/cross_document_analyzer.rb', line 24

def options
  @options
end

#registryObject (readonly)

Returns the value of attribute registry.



24
25
26
# File 'lib/ace/docs/organisms/cross_document_analyzer.rb', line 24

def registry
  @registry
end

Instance Method Details

#analyze(pattern = nil) ⇒ ConsistencyReport

Analyze documents for consistency issues

Parameters:

  • pattern (String, nil) (defaults to: nil)

    glob pattern to filter documents

Returns:

  • (ConsistencyReport)

    analysis results



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
# File 'lib/ace/docs/organisms/cross_document_analyzer.rb', line 37

def analyze(pattern = nil)
  # Load documents
  puts "Loading documents..." if @options[:verbose]
  documents = load_documents(pattern)

  if documents.empty?
    puts "No documents found to analyze.".yellow
    return nil
  end

  # Create standardized session directory using PromptCacheManager
  session_dir = Ace::Core::Molecules::PromptCacheManager.create_session(
    "ace-docs",
    "analyze-consistency"
  )

  puts "Analyzing #{documents.count} documents for consistency issues...".cyan
  puts "Session directory: #{session_dir}".yellow

  # Save document list
  puts "Saving document list..." if @options[:verbose]
  save_document_list(documents, session_dir)

  # Prepare document paths (no need to load content, ace-bundle will do it)
  puts "Preparing document paths..." if @options[:verbose]
  document_data = prepare_document_paths(documents)
  puts "  Documents to analyze: #{document_data.size}" if @options[:verbose]

  # Build prompts
  puts "Building analysis prompts..." if @options[:verbose]
  prompt_builder = Prompts::ConsistencyPrompt.new
  prompts = prompt_builder.build(document_data, @options, session_dir: session_dir)

  # Save prompts
  puts "Saving prompts to session directory..." if @options[:verbose]
  save_prompts(prompts, session_dir)

  # Execute LLM query
  puts "\nExecuting LLM analysis..." if @options[:verbose]
  puts "This may take a few minutes for large document sets..." if documents.count > 10
  response = execute_llm_query(prompts, session_dir)

  unless response && File.exist?(response) && !File.read(response).strip.empty?
    raise "Consistency analysis did not produce a completed report"
  end

  # Save metadata for reference
  (documents, pattern, session_dir)

  # Display session info
  puts "\nAnalysis saved to: #{session_dir}".green

  # Return the report path
  response
end