Class: RubynCode::Tools::CodeGraph

Inherits:
Base
  • Object
show all
Defined in:
lib/rubyn_code/tools/code_graph.rb

Overview

Codegraph-style exploration over the persistent codebase index: one call answers "where is X and how is it wired?" with the verbatim line-numbered source of matching symbols plus their callers, callees, and affected files — replacing a grep + read_file loop.

Constant Summary collapse

TOOL_NAME =
'code_graph'
DESCRIPTION =
'Explores the codebase knowledge graph. Given symbol names or keywords, returns the ' \
'matching definitions with verbatim line-numbered source, the methods that call them, ' \
'the methods they call, and the affected files (including specs). Prefer this over ' \
'grep/read_file when locating or understanding code — one call replaces a search loop.'
PARAMETERS =
{
  query: { type: :string, required: true,
           description: 'Symbol names or keywords, e.g. "build_request_body" or "task budget"' },
  max_symbols: { type: :integer, required: false, default: 5,
                 description: 'Maximum matching symbols to expand (default 5)' }
}.freeze
RISK_LEVEL =
:read
REQUIRES_CONFIRMATION =
false
MAX_SOURCE_LINES =
60
15
MATCHABLE_TYPES =
%w[class module model controller service concern method].freeze

Instance Attribute Summary

Attributes inherited from Base

#project_root

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

description, #initialize, parameters, requires_confirmation?, risk_level, #safe_path, to_schema, tool_name, #truncate

Constructor Details

This class inherits a constructor from RubynCode::Tools::Base

Class Method Details

.summarize(output, args) ⇒ Object



31
32
33
34
35
# File 'lib/rubyn_code/tools/code_graph.rb', line 31

def self.summarize(output, args)
  query = args['query'] || args[:query] || ''
  count = output.to_s.scan(/^## /).size
  "code_graph #{query} (#{count} symbols)"
end

Instance Method Details

#execute(query:, max_symbols: 5) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/rubyn_code/tools/code_graph.rb', line 37

def execute(query:, max_symbols: 5)
  index = Index::CodebaseIndex.new(project_root: project_root)
  index.load_or_build!

  matches = ranked_matches(index, query, max_symbols)
  return "No symbols matching '#{query}' in the codebase index." if matches.empty?

  sections = matches.map { |node| render_symbol(index, node) }
  truncate(sections.join("\n\n"))
end