Class: RailsAiBridge::Tools::ExplainSymbol::CliExplorer

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/tools/explain_symbol/cli_explorer.rb

Overview

Runs local codegraph explore against an on-disk .codegraph/ index. Uses argv arrays (no shell) and a wall-clock timeout. Never opens a network connection — failures surface as ExploreError.

Constant Summary collapse

DEFAULT_TIMEOUT_SECONDS =
15

Instance Method Summary collapse

Constructor Details

#initialize(root:, timeout: DEFAULT_TIMEOUT_SECONDS) ⇒ CliExplorer

Returns a new instance of CliExplorer.

Parameters:

  • root (String)

    application root that should contain .codegraph/

  • timeout (Numeric) (defaults to: DEFAULT_TIMEOUT_SECONDS)

    wall-clock seconds for the CLI (must be positive)



17
18
19
20
# File 'lib/rails_ai_bridge/tools/explain_symbol/cli_explorer.rb', line 17

def initialize(root:, timeout: DEFAULT_TIMEOUT_SECONDS)
  @root = root
  @timeout = timeout
end

Instance Method Details

#explore(query) ⇒ String

Returns markdown from codegraph explore.

Parameters:

  • query (String)

    symbol or natural-language explore query

Returns:

  • (String)

    markdown from codegraph explore

Raises:

  • (ExploreError)

    when the CLI is missing, times out, or exits non-zero



25
26
27
28
29
30
31
32
33
34
# File 'lib/rails_ai_bridge/tools/explain_symbol/cli_explorer.rb', line 25

def explore(query)
  stdout, stderr, status = run_explore(query)
  return stdout.to_s if status.success?

  raise ExploreError, failure_detail(stderr, status)
rescue Errno::ENOENT
  raise ExploreError, 'codegraph CLI not found on PATH'
rescue Timeout::Error
  raise ExploreError, "codegraph explore timed out after #{@timeout} seconds"
end