Module: DebugAgent

Extended by:
ClassMethods
Defined in:
lib/debug_agent.rb,
lib/debug_agent/config.rb,
lib/debug_agent/engine.rb,
lib/debug_agent/version.rb,
lib/debug_agent/chat_page.rb,
lib/debug_agent/llm_client.rb,
lib/debug_agent/middleware.rb,
lib/debug_agent/chat_session.rb,
lib/debug_agent/inspectors/gc.rb,
lib/debug_agent/tool_registry.rb,
lib/debug_agent/inspectors/puma.rb,
lib/debug_agent/inspectors/rails.rb,
lib/debug_agent/inspectors/redis.rb,
lib/debug_agent/inspectors/routes.rb,
lib/debug_agent/inspectors/system.rb,
lib/debug_agent/context_compressor.rb,
lib/debug_agent/inspectors/runtime.rb,
lib/debug_agent/inspectors/sidekiq.rb,
lib/debug_agent/inspectors/threads.rb,
lib/debug_agent/inspectors/core_ext.rb,
lib/debug_agent/system_prompt_builder.rb,
lib/debug_agent/inspectors/http_tracker.rb,
lib/debug_agent/inspectors/object_space.rb,
lib/debug_agent/inspectors/process_info.rb

Defined Under Namespace

Modules: ChatPage, ClassMethods, HttpRequestTracker, Middleware, MiddlewareCore, ToolDefinitionExt Classes: ChatCallback, ChatSession, CompressionResult, Config, ContextCompressor, DebugEngine, EngineStreamHandler, Error, LLMClient, LLMConfig, RackMiddleware, RetriableError, SseCallback, StreamHandler, SystemPromptBuilder, ToolDefinition, ToolParam, ToolRegistry

Constant Summary collapse

PROCESS_START_TIME =

Process start time for uptime tracking

Time.now
VERSION =
'0.3.0'.freeze
REGISTRY =

Global registry singleton

ToolRegistry.new
CATEGORY_MAP =
{
  'gc'            => 'Memory & GC',
  'object_space'  => 'Memory & GC',
  'memory'        => 'Memory & GC',
  'object_count'  => 'Memory & GC',
  'allocations'   => 'Memory & GC',
  'force_gc'      => 'Memory & GC',
  'trigger_gc'    => 'Memory & GC',
  'process'       => 'Process Info',
  'cpu'           => 'Process Info',
  'uptime'        => 'Process Info',
  'thread'        => 'Threads',
  'system'        => 'System Info',
  'disk'          => 'System Info',
  'environment'   => 'System Info',
  'routes'        => 'Framework & Routes',
  'middleware'    => 'Framework & Routes',
  'runtime'       => 'Runtime Info',
  'recent'        => 'HTTP Requests',
  'slow'          => 'HTTP Requests',
  'error'         => 'HTTP Requests',
  'request'       => 'HTTP Requests',
  'gem'           => 'Dependencies',
  'module'        => 'Module Info',
}.freeze
MAX_REQUESTS =
500

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from ClassMethods

register_tool, registry

Class Attribute Details

.appObject

Returns the value of attribute app.



37
38
39
# File 'lib/debug_agent.rb', line 37

def app
  @app
end

.redis_clientsObject (readonly)

Returns the value of attribute redis_clients.



9
10
11
# File 'lib/debug_agent/inspectors/redis.rb', line 9

def redis_clients
  @redis_clients
end

.sidekiq_queuesObject (readonly)

Returns the value of attribute sidekiq_queues.



9
10
11
# File 'lib/debug_agent/inspectors/sidekiq.rb', line 9

def sidekiq_queues
  @sidekiq_queues
end

Class Method Details

.format_uptime(seconds) ⇒ Object

Helper method for formatting uptime



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/debug_agent/inspectors/process_info.rb', line 48

def self.format_uptime(seconds)
  days = (seconds / 86400).to_i
  hours = ((seconds % 86400) / 3600).to_i
  minutes = ((seconds % 3600) / 60).to_i
  secs = (seconds % 60).to_i

  parts = []
  parts << "#{days}d" if days > 0
  parts << "#{hours}h" if hours > 0 || days > 0
  parts << "#{minutes}m" if minutes > 0 || hours > 0 || days > 0
  parts << "#{secs}s"
  parts.join(' ')
end

.register_redis_client(name, client) ⇒ Object



11
12
13
# File 'lib/debug_agent/inspectors/redis.rb', line 11

def register_redis_client(name, client)
  @redis_clients[name.to_s] = client
end

.register_sidekiq_queue(name, queue) ⇒ Object



11
12
13
# File 'lib/debug_agent/inspectors/sidekiq.rb', line 11

def register_sidekiq_queue(name, queue)
  @sidekiq_queues[name.to_s] = queue
end

.with_redis(name = nil) ⇒ Object

Resolve a registered Redis client. Accepts a bare Redis object or a ConnectionPool (redis-rb ships ConnectionPool support). We yield a usable connection object to the block.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/debug_agent/inspectors/redis.rb', line 19

def self.with_redis(name = nil)
  name, client = if name
    [name.to_s, redis_clients[name.to_s]]
  else
    redis_clients.first
  end

  return [nil, nil] unless client

  [name, client]
end