debug-agent 0.6.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b9c945dc45966ff8c9d06b0679357d54ba9dc443d5ee68c532ae1058878c6e4
4
- data.tar.gz: a986e568c59ca3f8d04f71d647ba0649bbbff7659f021eca349bc3cce3b3b044
3
+ metadata.gz: 3e6a7d1a5a0a33669a5e1b1c830761c5bf5a7a0b339e58328d29c7af1621dda4
4
+ data.tar.gz: 5beda4ad577f6598bcfd967e6124e819ebcbd853e00e5291a14baa08a7750ba4
5
5
  SHA512:
6
- metadata.gz: 90d75283c6f362c3be78a419923c26d622aa6d55ed3d29ebfca1c40341d7d264a9a6074fd30e93140fb13db44991a8a52261d0695a2df22bcf1e17e865f793bb
7
- data.tar.gz: 319d197cd23d9c9fd15845dc4a8a896b2560d3da83b85ac69e9687ba4ce3495ed1b720089ce82cc6adef8497e570177078f9430191bbca260a32a230f68171aa
6
+ metadata.gz: a4e5b1d103102c3446309f51b5d27dc689ff0a83bd32ab83eb4d800befd3fb72b4efbe0ae57362acc225974b36ec8b3f95ee24e7f1323dec9287f119a13c116c
7
+ data.tar.gz: b4105c3b8e1f29d7df9dce15c10852f6c7cf6eb2b9797dfd71fa0f8b5ea56989d9a34386e0b9166a5987c199ec86da5b1a5be8bdf3c084d1f30ed01f074b2f76
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Ruby Debug Agent
2
2
 
3
3
  [![Gem Version](https://img.shields.io/badge/gem-debug--agent-red)](https://github.com/topcheer/ruby-debug-agent)
4
- ![Tools](https://img.shields.io/badge/tools-84-blue)
5
- ![Inspectors](https://img.shields.io/badge/inspectors-31-green)
4
+ ![Tools](https://img.shields.io/badge/tools-98-blue)
5
+ ![Inspectors](https://img.shields.io/badge/inspectors-36-green)
6
6
  ![Ruby](https://img.shields.io/badge/Ruby-2.7%2B-CC342D)
7
7
  ![Gem](https://img.shields.io/badge/gem-debug--agent-red)
8
8
 
9
- An AI-powered runtime debugging agent that embeds directly into your Ruby application. Add one gem, configure an LLM key, and chat with your live app at `/agent` to inspect GC, ObjectSpace, threads, routes, Redis, Rails models/routes, Sidekiq queues, Puma stats, fibers/signals, process info, HTTP requests, and more — **84 diagnostic tools across 31 inspectors**.
9
+ An AI-powered runtime debugging agent that embeds directly into your Ruby application. Add one gem, configure an LLM key, and chat with your live app at `/agent` to inspect GC, ObjectSpace, threads, routes, Redis, Rails models/routes, Sidekiq queues, Puma stats, fibers/signals, process info, HTTP requests, and more — **98 diagnostic tools across 36 inspectors**.
10
10
 
11
11
  ## Version Support
12
12
 
@@ -71,10 +71,10 @@ http://localhost:4567/agent
71
71
  - **Context compression** — automatically summarizes old conversation when token limit is approached
72
72
  - **Dark-themed chat UI** with full markdown rendering (tables, code blocks, lists)
73
73
  - **Max tool rounds** (25) with forced final summary when limit is reached
74
- - **84 diagnostic tools** across **31 inspectors**
74
+ - **98 diagnostic tools** across **36 inspectors**
75
75
  - Zero external dependencies (no Datadog, no Grafana, no APM)
76
76
 
77
- ## Inspectors & Tools (84)
77
+ ## Inspectors & Tools (98)
78
78
 
79
79
  ### GC Inspector
80
80
  | Tool | Description |
@@ -250,6 +250,40 @@ http://localhost:4567/agent
250
250
  | `detect_pool_leaks` | Heuristic leak detection (growing pool, high wait ratio, saturation) |
251
251
  | `get_pool_wait_stats` | Connection acquire wait stats (avg, P95, max wait, timeout count) |
252
252
 
253
+ ### CPU Profiler Inspector (v0.7.0)
254
+ | Tool | Description |
255
+ |------|-------------|
256
+ | `start_cpu_profile` | Start a CPU profiling session (stackprof/stackprof-native) |
257
+ | `stop_cpu_profile` | Stop CPU profiling and return collected profile data |
258
+ | `get_top_functions` | Get top CPU-consuming functions from the current profile |
259
+
260
+ ### Memory Leak Detector Inspector (v0.7.0)
261
+ | Tool | Description |
262
+ |------|-------------|
263
+ | `take_heap_snapshot` | Capture an ObjectSpace heap snapshot for leak analysis |
264
+ | `compare_heap_snapshots` | Compare two heap snapshots to identify object growth |
265
+ | `get_leak_candidates` | Identify objects likely to be memory leaks |
266
+
267
+ ### Deployment/Build Info Inspector (v0.7.0)
268
+ | Tool | Description |
269
+ |------|-------------|
270
+ | `get_build_info` | Build version, commit hash, and gem metadata |
271
+ | `get_deployment_info` | Deployment environment, container, and orchestration metadata |
272
+ | `get_runtime_version` | Ruby interpreter version, engine, and platform details |
273
+
274
+ ### Snapshot & Diff Inspector (v0.7.0)
275
+ | Tool | Description |
276
+ |------|-------------|
277
+ | `take_snapshot` | Capture a runtime state snapshot |
278
+ | `compare_snapshots` | Compare two snapshots to identify state changes |
279
+ | `list_snapshots` | List all saved snapshots with timestamps |
280
+
281
+ ### Service Registry Inspector (v0.7.0)
282
+ | Tool | Description |
283
+ |------|-------------|
284
+ | `get_registered_services` | List all registered application services |
285
+ | `get_service_dependencies` | Map service-to-service dependency graph |
286
+
253
287
  ## Custom Tools
254
288
 
255
289
  ```ruby
@@ -302,6 +336,12 @@ cd demo && ruby -I../lib app.rb
302
336
 
303
337
  [![Gem](https://img.shields.io/badge/rubygems-debug--agent-red)](https://github.com/topcheer/ruby-debug-agent)
304
338
 
339
+ ## Built With
340
+
341
+ [![ggcode](https://img.shields.io/badge/built%20with-ggcode-blue)](https://github.com/topcheer/ggcode)
342
+
343
+ This project was built using [ggcode](https://github.com/topcheer/ggcode) — an AI coding assistant for terminal-based development.
344
+
305
345
  ## License
306
346
 
307
347
  MIT
@@ -0,0 +1,87 @@
1
+ require 'socket'
2
+ require 'etc'
3
+
4
+ module DebugAgent
5
+ register_tool('get_build_info',
6
+ 'Get Ruby build info: version, engine (MRI/JRuby/TruffleRuby), ' \
7
+ 'platform, build date, RUBY_DESCRIPTION') do
8
+ {
9
+ ruby_version: RUBY_VERSION,
10
+ ruby_engine: RUBY_ENGINE,
11
+ ruby_engine_version: defined?(RUBY_ENGINE_VERSION) ? RUBY_ENGINE_VERSION : RUBY_VERSION,
12
+ platform: RUBY_PLATFORM,
13
+ ruby_description: RUBY_DESCRIPTION,
14
+ ruby_patchlevel: defined?(RUBY_PATCHLEVEL) ? RUBY_PATCHLEVEL : nil,
15
+ ruby_revision: defined?(RUBY_REVISION) ? RUBY_REVISION.to_s : nil,
16
+ ruby_release_date: defined?(RUBY_RELEASE_DATE) ? RUBY_RELEASE_DATE : nil,
17
+ build_date: defined?(RUBY_RELEASE_DATE) ? RUBY_RELEASE_DATE : nil,
18
+ host_os: RbConfig::CONFIG['host_os'],
19
+ host_cpu: RbConfig::CONFIG['host_cpu'],
20
+ configure_args: RbConfig::CONFIG['configure_args']
21
+ }
22
+ rescue => e
23
+ { error: e.message }
24
+ end
25
+
26
+ register_tool('get_deployment_info',
27
+ 'Get deployment info: hostname, PID, uptime, container detection, ' \
28
+ 'APP_ENV, Rails env') do
29
+ rss = `ps -o rss= -p #{Process.pid}`.to_i
30
+ uptime_seconds = Time.now - DebugAgent::PROCESS_START_TIME
31
+
32
+ container_detected = File.exist?('/.dockerenv')
33
+ in_cgroup = false
34
+ begin
35
+ in_cgroup = File.read('/proc/1/cgroup').include?('docker') ||
36
+ File.read('/proc/1/cgroup').include?('containerd')
37
+ rescue
38
+ end
39
+
40
+ {
41
+ hostname: Socket.gethostname,
42
+ pid: Process.pid,
43
+ ppid: Process.ppid,
44
+ process_name: $0,
45
+ uptime_seconds: uptime_seconds.round(0),
46
+ rss_mb: (rss / 1024.0).round(2),
47
+ container_detected: container_detected || in_cgroup,
48
+ docker_detected: File.exist?('/.dockerenv'),
49
+ app_env: ENV['APP_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'unknown',
50
+ rails_env: defined?(::Rails) ? ::Rails.env.to_s : nil,
51
+ user: Etc.getpwuid(Process.uid)&.name,
52
+ uid: Process.uid,
53
+ gid: Process.gid,
54
+ cpu_count: Etc.nprocessors
55
+ }
56
+ rescue => e
57
+ { error: e.message }
58
+ end
59
+
60
+ register_tool('get_runtime_versions',
61
+ 'Get versions of key gems: rails, sinatra, sidekiq, redis, puma ' \
62
+ 'if loaded') do
63
+ key_gems = %w[rails sinatra sidekiq redis puma rack rack-attack \
64
+ activerecord activesupport postgresql pg mysql2 bunny \
65
+ faraday httplog oj msgpack json]
66
+
67
+ versions = {}
68
+ key_gems.each do |gem_name|
69
+ spec = Gem.loaded_specs[gem_name] || Gem.loaded_specs.values.find { |s| s.name == gem_name }
70
+ versions[gem_name] = spec&.version&.to_s if spec
71
+ end
72
+
73
+ # Remove nils
74
+ versions.compact!
75
+
76
+ {
77
+ ruby_version: RUBY_VERSION,
78
+ ruby_engine: RUBY_ENGINE,
79
+ rubygems_version: Gem::VERSION,
80
+ bundler_version: defined?(Bundler) ? Bundler::VERSION : nil,
81
+ loaded_gem_count: Gem.loaded_specs.size,
82
+ key_gem_versions: versions
83
+ }
84
+ rescue => e
85
+ { error: e.message }
86
+ end
87
+ end
@@ -0,0 +1,192 @@
1
+ require 'timeout'
2
+
3
+ module DebugAgent
4
+ # CPU profiler inspector. Uses stackprof if available, otherwise falls back
5
+ # to a sampling profiler that periodically captures caller stacks.
6
+ @cpu_profile_data = nil
7
+ @cpu_profile_running = false
8
+ @cpu_profile_lock = Mutex.new
9
+
10
+ class << self
11
+ attr_reader :cpu_profile_data, :cpu_profile_running
12
+ end
13
+
14
+ register_tool('start_cpu_profile',
15
+ 'Start CPU profiling for a given duration. Uses stackprof if available, ' \
16
+ 'otherwise falls back to a sampling profiler. Auto-stops after duration.',
17
+ duration_seconds: { type: 'integer', description: 'Profile duration in seconds', required: false }) do |duration_seconds: 10|
18
+ duration = duration_seconds.to_i
19
+ duration = 10 if duration <= 0
20
+
21
+ @cpu_profile_lock.synchronize do
22
+ next { error: 'CPU profile already running' } if @cpu_profile_running
23
+ @cpu_profile_running = true
24
+ @cpu_profile_data = nil
25
+ end
26
+
27
+ if defined?(::StackProf)
28
+ # StackProf path: block-based profiling
29
+ StackProf.run(mode: :cpu, interval: 1000) do
30
+ sleep(duration)
31
+ end
32
+ @cpu_profile_lock.synchronize { @cpu_profile_running = false }
33
+ raw = StackProf.results
34
+ @cpu_profile_data = parse_stackprof(raw) if raw
35
+ {
36
+ status: 'completed',
37
+ backend: 'stackprof',
38
+ duration_seconds: duration,
39
+ samples: raw ? raw[:samples] : 0
40
+ }
41
+ else
42
+ # Fallback: sampling profiler using caller stacks
43
+ samples = Hash.new(0)
44
+ total_samples = 0
45
+ sample_lock = Mutex.new
46
+ end_time = Time.now + duration
47
+
48
+ sampler = Thread.new do
49
+ while Time.now < end_time && @cpu_profile_running
50
+ stack = caller(2)&.join("\n")
51
+ sample_lock.synchronize do
52
+ samples[stack] += 1
53
+ total_samples += 1
54
+ end if stack
55
+ sleep(0.001)
56
+ end
57
+ end
58
+
59
+ sampler.join
60
+ @cpu_profile_lock.synchronize { @cpu_profile_running = false }
61
+ @cpu_profile_data = parse_call_samples(samples, total_samples)
62
+ {
63
+ status: 'completed',
64
+ backend: 'sampling',
65
+ duration_seconds: duration,
66
+ total_samples: total_samples,
67
+ unique_stacks: samples.size
68
+ }
69
+ end
70
+ rescue => e
71
+ @cpu_profile_running = false
72
+ { error: e.message }
73
+ end
74
+
75
+ register_tool('stop_cpu_profile',
76
+ 'Stop CPU profiling and return top 20 methods by self time. ' \
77
+ 'Each entry includes method name, file, line, self_ms, total_ms, calls.') do
78
+ next { error: 'No profile data available. Run start_cpu_profile first.' } unless @cpu_profile_data
79
+
80
+ @cpu_profile_running = false
81
+ top = (@cpu_profile_data[:functions] || []).first(20)
82
+
83
+ {
84
+ status: 'stopped',
85
+ backend: @cpu_profile_data[:backend],
86
+ total_samples: @cpu_profile_data[:total_samples],
87
+ top_functions: top
88
+ }
89
+ rescue => e
90
+ { error: e.message }
91
+ end
92
+
93
+ register_tool('get_top_functions',
94
+ 'Return top methods from last CPU profile. Sort by self_time, total_time, or calls.',
95
+ limit: { type: 'integer', description: 'Number of functions to return (default 20)', required: false },
96
+ sort_by: { type: 'string', description: 'Sort key: self_time, total_time, or calls (default self_time)', required: false }) do |limit: 20, sort_by: 'self_time'|
97
+ next { error: 'No profile data available. Run start_cpu_profile first.' } unless @cpu_profile_data
98
+
99
+ funcs = (@cpu_profile_data[:functions] || []).dup
100
+ sort_key = %w[self_time total_time calls].include?(sort_by.to_s) ? sort_by.to_sym : :self_time
101
+ funcs.sort_by! { |f| -f[sort_key].to_f }
102
+ top = funcs.first(limit.to_i > 0 ? limit.to_i : 20)
103
+
104
+ {
105
+ sort_by: sort_key,
106
+ total_functions: @cpu_profile_data[:functions]&.size || 0,
107
+ top_functions: top
108
+ }
109
+ rescue => e
110
+ { error: e.message }
111
+ end
112
+
113
+ # --- Helpers ---
114
+
115
+ class << self
116
+ private
117
+
118
+ def parse_stackprof(raw)
119
+ return nil unless raw && raw[:frames]
120
+
121
+ funcs = raw[:frames].map do |_frame_key, frame|
122
+ {
123
+ method: frame[:name] || 'unknown',
124
+ file: frame[:file],
125
+ line: frame[:line],
126
+ self_ms: ((frame[:samples].to_f / raw[:samples].to_f) * (raw[:gc_profile_time] || raw[:walltime] || 0) * 1000).round(2),
127
+ total_ms: ((frame[:total_samples].to_f / raw[:samples].to_f) * (raw[:gc_profile_time] || raw[:walltime] || 0) * 1000).round(2),
128
+ calls: frame[:samples].to_i
129
+ }
130
+ end.sort_by { |f| -f[:self_ms] }
131
+
132
+ {
133
+ backend: 'stackprof',
134
+ total_samples: raw[:samples],
135
+ functions: funcs
136
+ }
137
+ end
138
+
139
+ def parse_call_samples(samples, total_samples)
140
+ method_stats = Hash.new { |h, k| h[k] = { self_time: 0, total_time: 0, calls: 0 } }
141
+
142
+ samples.each do |stack_str, count|
143
+ lines = stack_str.split("\n")
144
+ next if lines.empty?
145
+
146
+ # First line of caller(2) is the most recently called method
147
+ top_line = lines.first
148
+ parsed = parse_backtrace_line(top_line)
149
+
150
+ key = "#{parsed[:file]}:#{parsed[:method]}"
151
+ method_stats[key][:self_time] += count
152
+ method_stats[key][:total_time] += count
153
+ method_stats[key][:calls] += 1
154
+
155
+ # All lines contribute to total_time of their respective methods
156
+ lines.each do |line|
157
+ p = parse_backtrace_line(line)
158
+ k = "#{p[:file]}:#{p[:method]}"
159
+ method_stats[k][:total_time] += count
160
+ method_stats[k][:calls] += count unless k == key
161
+ end
162
+ end
163
+
164
+ funcs = method_stats.map do |_k, s|
165
+ parsed = parse_backtrace_line(samples.keys.find { |stk| stk.include?(_k) || true }&.split("\n")&.first || '')
166
+ {
167
+ method: _k.split(':').last,
168
+ file: _k.split(':')[0...-1].join(':'),
169
+ line: parsed[:line],
170
+ self_ms: (s[:self_time].to_f / total_samples.to_f * 10000).round(2),
171
+ total_ms: (s[:total_time].to_f / total_samples.to_f * 10000).round(2),
172
+ calls: s[:calls]
173
+ }
174
+ end.sort_by { |f| -f[:self_ms] }
175
+
176
+ {
177
+ backend: 'sampling',
178
+ total_samples: total_samples,
179
+ functions: funcs
180
+ }
181
+ end
182
+
183
+ def parse_backtrace_line(line)
184
+ # Format: "/path/to/file.rb:42:in `method_name'"
185
+ if line =~ /^(.+):(\d+):in `(.+)'$/
186
+ { file: $1, line: $2.to_i, method: $3 }
187
+ else
188
+ { file: 'unknown', line: 0, method: 'unknown' }
189
+ end
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,166 @@
1
+ require 'objspace'
2
+
3
+ module DebugAgent
4
+ # Memory leak detector inspector. Records heap snapshots and compares them
5
+ # to identify object types with consistent growth.
6
+ @heap_snapshots = {}
7
+ @heap_snapshot_counter = 0
8
+
9
+ class << self
10
+ attr_reader :heap_snapshots
11
+ end
12
+
13
+ register_tool('take_heap_snapshot',
14
+ 'Take a heap snapshot recording object counts by type, heap slots, ' \
15
+ 'and GC counts. Returns a snapshot ID for later comparison.') do
16
+ counts = Hash.new(0)
17
+ ObjectSpace.each_object do |obj|
18
+ begin
19
+ name = obj.class.name || obj.class.to_s
20
+ counts[name] += 1
21
+ rescue
22
+ counts['<unknown>'] += 1
23
+ end
24
+ end
25
+
26
+ gc_stats = GC.stat
27
+ total_objects = counts.values.sum
28
+
29
+ @heap_snapshot_counter += 1
30
+ snapshot_id = "heap-#{@heap_snapshot_counter}"
31
+
32
+ snapshot = {
33
+ id: snapshot_id,
34
+ taken_at: Time.now,
35
+ object_counts: counts,
36
+ total_objects: total_objects,
37
+ live_slots: gc_stats[:heap_live_slots],
38
+ free_slots: gc_stats[:heap_free_slots],
39
+ total_slots: gc_stats[:heap_live_slots].to_i + gc_stats[:heap_free_slots].to_i,
40
+ gc_count: gc_stats[:count],
41
+ major_gc_count: gc_stats[:major_gc_count],
42
+ minor_gc_count: gc_stats[:minor_gc_count],
43
+ total_allocated_objects: gc_stats[:total_allocated_objects],
44
+ total_freed_objects: gc_stats[:total_freed_objects],
45
+ heap_pages: gc_stats[:heap_length]
46
+ }
47
+
48
+ # Enforce max 50 heap snapshots to prevent unbounded memory growth
49
+ if @heap_snapshots.size >= 50
50
+ oldest_key = @heap_snapshots.keys.min_by { |k| k[/\d+/].to_i }
51
+ @heap_snapshots.delete(oldest_key)
52
+ end
53
+ @heap_snapshots[snapshot_id] = snapshot
54
+
55
+ {
56
+ snapshot_id: snapshot_id,
57
+ taken_at: snapshot[:taken_at].iso8601,
58
+ summary: {
59
+ total_objects: total_objects,
60
+ total_classes: counts.size,
61
+ live_slots: snapshot[:live_slots],
62
+ free_slots: snapshot[:free_slots],
63
+ gc_count: snapshot[:gc_count],
64
+ top_types: counts.sort_by { |_, v| -v }.first(10).to_h
65
+ }
66
+ }
67
+ rescue => e
68
+ { error: e.message }
69
+ end
70
+
71
+ register_tool('compare_heap_snapshots',
72
+ 'Compare two heap snapshots. Returns per-type count delta and growth ' \
73
+ 'percentage, sorted by absolute growth.',
74
+ snapshot_a: { type: 'string', description: 'First snapshot ID', required: true },
75
+ snapshot_b: { type: 'string', description: 'Second snapshot ID', required: true }) do |snapshot_a:, snapshot_b:|
76
+ snap_a = @heap_snapshots[snapshot_a.to_s]
77
+ snap_b = @heap_snapshots[snapshot_b.to_s]
78
+
79
+ next { error: "Snapshot '#{snapshot_a}' not found. Available: #{@heap_snapshots.keys.join(', ')}" } unless snap_a
80
+ next { error: "Snapshot '#{snapshot_b}' not found. Available: #{@heap_snapshots.keys.join(', ')}" } unless snap_b
81
+
82
+ counts_a = snap_a[:object_counts]
83
+ counts_b = snap_b[:object_counts]
84
+
85
+ all_types = (counts_a.keys | counts_b.keys).uniq
86
+ deltas = all_types.map do |type|
87
+ ca = counts_a[type] || 0
88
+ cb = counts_b[type] || 0
89
+ delta = cb - ca
90
+ growth_pct = ca > 0 ? (delta.to_f / ca * 100).round(2) : (delta > 0 ? Float::INFINITY : 0.0)
91
+
92
+ {
93
+ type: type,
94
+ count_before: ca,
95
+ count_after: cb,
96
+ count_delta: delta,
97
+ growth_percentage: growth_pct
98
+ }
99
+ end
100
+
101
+ # Sort by absolute growth descending
102
+ deltas.sort_by! { |d| -d[:count_delta].abs }
103
+
104
+ {
105
+ snapshot_a: snapshot_a,
106
+ snapshot_b: snapshot_b,
107
+ time_between: (snap_b[:taken_at] - snap_a[:taken_at]).round(2),
108
+ summary: {
109
+ total_objects_before: snap_a[:total_objects],
110
+ total_objects_after: snap_b[:total_objects],
111
+ net_delta: snap_b[:total_objects] - snap_a[:total_objects],
112
+ gc_runs_between: snap_b[:gc_count] - snap_a[:gc_count],
113
+ live_slots_delta: snap_b[:live_slots] - snap_a[:live_slots]
114
+ },
115
+ type_changes: deltas.first(50)
116
+ }
117
+ rescue => e
118
+ { error: e.message }
119
+ end
120
+
121
+ register_tool('get_leak_candidates',
122
+ 'Identify object types with consistent growth across stored snapshots. ' \
123
+ 'Shows top growing object types.') do |snapshot_limit: 10|
124
+ next { error: 'Need at least 2 snapshots to detect trends' } if @heap_snapshots.size < 2
125
+
126
+ snapshots = @heap_snapshots.values.sort_by { |s| s[:taken_at] }
127
+ snapshots = snapshots.last([snapshot_limit.to_i, 2].max)
128
+
129
+ # For each type, compute growth across consecutive snapshot pairs
130
+ type_growth = Hash.new { |h, k| h[k] = { deltas: [], total_growth: 0 } }
131
+
132
+ snapshots.each_cons(2) do |s1, s2|
133
+ all_types = (s1[:object_counts].keys | s2[:object_counts].keys)
134
+ all_types.each do |type|
135
+ c1 = s1[:object_counts][type] || 0
136
+ c2 = s2[:object_counts][type] || 0
137
+ delta = c2 - c1
138
+ type_growth[type][:deltas] << delta
139
+ type_growth[type][:total_growth] += delta
140
+ end
141
+ end
142
+
143
+ candidates = type_growth
144
+ .select { |_, g| g[:total_growth] > 0 && g[:deltas].all? { |d| d >= 0 } }
145
+ .map do |type, g|
146
+ {
147
+ type: type,
148
+ total_growth: g[:total_growth],
149
+ snapshots_growing: g[:deltas].count(&:positive?),
150
+ total_snapshots_compared: g[:deltas].size,
151
+ consistency: g[:deltas].all?(&:positive?) ? 'consistent' : 'partial',
152
+ per_period_deltas: g[:deltas]
153
+ }
154
+ end
155
+ .sort_by { |c| -c[:total_growth] }
156
+
157
+ {
158
+ snapshots_analyzed: snapshots.size,
159
+ first_snapshot: snapshots.first[:id],
160
+ last_snapshot: snapshots.last[:id],
161
+ leak_candidates: candidates.first(20)
162
+ }
163
+ rescue => e
164
+ { error: e.message }
165
+ end
166
+ end
@@ -0,0 +1,88 @@
1
+ module DebugAgent
2
+ register_tool('get_registered_services',
3
+ 'List all registered debug agent tools grouped by inspector category. ' \
4
+ 'Shows tool count and names per group.') do
5
+ all_tools = registry.names
6
+
7
+ # Categorize tools by known inspector groups
8
+ categories = {
9
+ 'runtime' => %w[get_gc_stats get_memory_summary trigger_gc get_thread_summary get_runtime_info get_object_allocations],
10
+ 'gc' => %w[],
11
+ 'object_space' => %w[],
12
+ 'threads' => %w[],
13
+ 'process' => %w[],
14
+ 'system' => %w[],
15
+ 'http_tracker' => %w[],
16
+ 'routes' => %w[],
17
+ 'redis' => %w[],
18
+ 'rails' => %w[],
19
+ 'sidekiq' => %w[],
20
+ 'puma' => %w[],
21
+ 'logging' => %w[],
22
+ 'cache' => %w[],
23
+ 'http_client' => %w[],
24
+ 'metrics' => %w[],
25
+ 'active_record_stats' => %w[],
26
+ 'faraday' => %w[],
27
+ 'concurrent' => %w[],
28
+ 'security' => %w[],
29
+ 'health' => %w[],
30
+ 'scheduler' => %w[],
31
+ 'error_tracking' => %w[],
32
+ 'websocket' => %w[],
33
+ 'locks' => %w[],
34
+ 'migration' => %w[],
35
+ 'config' => %w[],
36
+ 'feature_flags' => %w[],
37
+ 'endpoint_test' => %w[],
38
+ 'pool_inspector' => %w[],
39
+ 'cpu_profile' => %w[],
40
+ 'leak_detector' => %w[],
41
+ 'build_info' => %w[],
42
+ 'snapshot' => %w[],
43
+ 'service_registry' => %w[]
44
+ }
45
+
46
+ # Since we cannot reliably categorize at runtime without a lookup table,
47
+ # we list all tools alphabetically with their descriptions
48
+ tools_with_desc = all_tools.sort.map do |name|
49
+ tool = registry.get(name)
50
+ {
51
+ name: name,
52
+ description: tool&.respond_to?(:description) ? tool.description : nil
53
+ }
54
+ end
55
+
56
+ {
57
+ total_tools: all_tools.size,
58
+ tools: tools_with_desc
59
+ }
60
+ rescue => e
61
+ { error: e.message }
62
+ end
63
+
64
+ register_tool('get_service_dependencies',
65
+ 'Show all loaded gems and their versions from Gem.loaded_specs') do
66
+ specs = Gem.loaded_specs.values.sort_by(&:name)
67
+
68
+ gems = specs.map do |spec|
69
+ {
70
+ name: spec.name,
71
+ version: spec.version.to_s,
72
+ loaded_from: spec.loaded_from,
73
+ dependencies: spec.dependencies.map { |d| "#{d.name} (#{d.requirement})" }
74
+ }
75
+ end
76
+
77
+ {
78
+ total_gems: gems.size,
79
+ ruby_version: RUBY_VERSION,
80
+ ruby_engine: RUBY_ENGINE,
81
+ rubygems_version: Gem::VERSION,
82
+ bundler_version: defined?(Bundler) ? Bundler::VERSION : nil,
83
+ gems: gems
84
+ }
85
+ rescue => e
86
+ { error: e.message }
87
+ end
88
+ end
@@ -0,0 +1,212 @@
1
+ require 'objspace'
2
+
3
+ module DebugAgent
4
+ # Snapshot & Diff inspector. Collects metrics across all inspectors at a
5
+ # point in time and allows comparing snapshots to detect changes.
6
+ @metric_snapshots = {}
7
+ @metric_snapshot_counter = 0
8
+
9
+ class << self
10
+ attr_reader :metric_snapshots
11
+ end
12
+
13
+ register_tool('take_snapshot',
14
+ 'Take a cross-inspector snapshot: thread count, fiber count, memory (RSS), ' \
15
+ 'GC stats, object count, DB pool stats, cache stats, error count. Returns snapshot ID.') do
16
+ gc = GC.stat
17
+ obj_counts = ObjectSpace.count_objects
18
+ rss = `ps -o rss= -p #{Process.pid}`.to_i
19
+
20
+ metrics = {
21
+ taken_at: Time.now,
22
+ threads: Thread.list.size,
23
+ alive_threads: Thread.list.count(&:alive?),
24
+ fiber_count: Fiber.respond_to?(:list) ? Fiber.list.size : count_fibers,
25
+ rss_mb: (rss / 1024.0).round(2),
26
+ gc: {
27
+ count: gc[:count],
28
+ major_gc_count: gc[:major_gc_count],
29
+ minor_gc_count: gc[:minor_gc_count],
30
+ heap_live_slots: gc[:heap_live_slots],
31
+ heap_free_slots: gc[:heap_free_slots],
32
+ total_allocated_objects: gc[:total_allocated_objects],
33
+ total_freed_objects: gc[:total_freed_objects],
34
+ old_objects: gc[:old_objects]
35
+ },
36
+ objects: {
37
+ total: obj_counts[:TOTAL] || obj_counts.values.sum,
38
+ free_slots: obj_counts[:FREE] || 0,
39
+ t_string: obj_counts[:T_STRING] || 0,
40
+ t_array: obj_counts[:T_ARRAY] || 0,
41
+ t_hash: obj_counts[:T_HASH] || 0,
42
+ t_object: obj_counts[:T_OBJECT] || 0,
43
+ t_data: obj_counts[:T_DATA] || 0
44
+ },
45
+ db_pool: gather_db_pool_stats,
46
+ cache: gather_cache_stats,
47
+ error_count: gather_error_count
48
+ }
49
+
50
+ @metric_snapshot_counter += 1
51
+ snapshot_id = "snap-#{@metric_snapshot_counter}"
52
+
53
+ # Enforce max 100 snapshots to prevent unbounded growth
54
+ if @metric_snapshots.size >= 100
55
+ oldest_key = @metric_snapshots.keys.min_by { |k| k[/\d+/].to_i }
56
+ @metric_snapshots.delete(oldest_key)
57
+ end
58
+ @metric_snapshots[snapshot_id] = metrics
59
+
60
+ {
61
+ snapshot_id: snapshot_id,
62
+ taken_at: metrics[:taken_at].iso8601,
63
+ summary: {
64
+ threads: metrics[:threads],
65
+ fibers: metrics[:fiber_count],
66
+ rss_mb: metrics[:rss_mb],
67
+ total_objects: metrics[:objects][:total],
68
+ gc_count: metrics[:gc][:count],
69
+ live_slots: metrics[:gc][:heap_live_slots]
70
+ }
71
+ }
72
+ rescue => e
73
+ { error: e.message }
74
+ end
75
+
76
+ register_tool('compare_snapshots',
77
+ 'Compare two cross-inspector snapshots. Returns all changed values ' \
78
+ 'with deltas.',
79
+ snapshot_a: { type: 'string', description: 'First snapshot ID', required: true },
80
+ snapshot_b: { type: 'string', description: 'Second snapshot ID', required: true }) do |snapshot_a:, snapshot_b:|
81
+ snap_a = @metric_snapshots[snapshot_a.to_s]
82
+ snap_b = @metric_snapshots[snapshot_b.to_s]
83
+
84
+ next { error: "Snapshot '#{snapshot_a}' not found. Available: #{@metric_snapshots.keys.join(', ')}" } unless snap_a
85
+ next { error: "Snapshot '#{snapshot_b}' not found. Available: #{@metric_snapshots.keys.join(', ')}" } unless snap_b
86
+
87
+ changes = compute_snapshot_diff(snap_a, snap_b, '')
88
+
89
+ {
90
+ snapshot_a: snapshot_a,
91
+ snapshot_b: snapshot_b,
92
+ time_between_seconds: (snap_b[:taken_at] - snap_a[:taken_at]).round(2),
93
+ changes: changes
94
+ }
95
+ rescue => e
96
+ { error: e.message }
97
+ end
98
+
99
+ register_tool('list_snapshots',
100
+ 'List all stored cross-inspector snapshots') do
101
+ if @metric_snapshots.empty?
102
+ next { message: 'No snapshots taken yet. Call take_snapshot first.', count: 0, snapshots: [] }
103
+ end
104
+
105
+ {
106
+ count: @metric_snapshots.size,
107
+ snapshots: @metric_snapshots.map do |id, snap|
108
+ {
109
+ snapshot_id: id,
110
+ taken_at: snap[:taken_at].iso8601,
111
+ threads: snap[:threads],
112
+ rss_mb: snap[:rss_mb],
113
+ total_objects: snap[:objects][:total],
114
+ gc_count: snap[:gc][:count]
115
+ }
116
+ end
117
+ }
118
+ rescue => e
119
+ { error: e.message }
120
+ end
121
+
122
+ # --- Helpers ---
123
+
124
+ class << self
125
+ private
126
+
127
+ def count_fibers
128
+ # Best-effort fiber count via ObjectSpace
129
+ count = 0
130
+ ObjectSpace.each_object(Fiber) { count += 1 }
131
+ count
132
+ rescue
133
+ 0
134
+ end
135
+
136
+ def gather_db_pool_stats
137
+ return nil unless defined?(::ActiveRecord::Base)
138
+
139
+ begin
140
+ pool = ::ActiveRecord::Base.connection_pool
141
+ stats = pool.respond_to?(:stats) ? pool.stats : {}
142
+ {
143
+ size: pool.respond_to?(:size) ? pool.size : nil,
144
+ stats: stats
145
+ }
146
+ rescue
147
+ nil
148
+ end
149
+ end
150
+
151
+ def gather_cache_stats
152
+ return nil unless defined?(::Rails)
153
+
154
+ begin
155
+ cache = ::Rails.cache
156
+ return nil unless cache
157
+ stats = if cache.respond_to?(:stats)
158
+ cache.stats
159
+ elsif cache.respond_to?(:info)
160
+ cache.info
161
+ else
162
+ {}
163
+ end
164
+ { backend: cache.class.name, stats: stats }
165
+ rescue
166
+ nil
167
+ end
168
+ end
169
+
170
+ def gather_error_count
171
+ # ErrorTracking inspector stores error counts if available
172
+ if defined?(@error_log) && @error_log.is_a?(Array)
173
+ @error_log.size
174
+ else
175
+ 0
176
+ end
177
+ end
178
+
179
+ def compute_snapshot_diff(a, b, prefix)
180
+ changes = []
181
+
182
+ if a.is_a?(Hash) && b.is_a?(Hash)
183
+ all_keys = (a.keys | b.keys)
184
+ all_keys.each do |key|
185
+ va = a[key]
186
+ vb = b[key]
187
+ path = prefix.empty? ? key.to_s : "#{prefix}.#{key}"
188
+
189
+ if va.is_a?(Hash) && vb.is_a?(Hash)
190
+ changes.concat(compute_snapshot_diff(va, vb, path))
191
+ elsif va != vb
192
+ changes << {
193
+ metric: path,
194
+ before: va,
195
+ after: vb,
196
+ delta: (va.is_a?(Numeric) && vb.is_a?(Numeric)) ? (vb - va) : nil
197
+ }
198
+ end
199
+ end
200
+ elsif a != b
201
+ changes << {
202
+ metric: prefix,
203
+ before: a,
204
+ after: b,
205
+ delta: (a.is_a?(Numeric) && b.is_a?(Numeric)) ? (b - a) : nil
206
+ }
207
+ end
208
+
209
+ changes
210
+ end
211
+ end
212
+ end
@@ -84,7 +84,7 @@ module DebugAgent
84
84
  def stream_request(path, body, handler)
85
85
  uri = URI(@cfg.base_url + path)
86
86
 
87
- Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', read_timeout: @cfg.timeout_seconds) do |http|
87
+ Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', read_timeout: @cfg.timeout_seconds, open_timeout: 10) do |http|
88
88
  request = Net::HTTP::Post.new(uri.path)
89
89
  request['Authorization'] = "Bearer #{@cfg.api_key}"
90
90
  request['Content-Type'] = 'application/json'
@@ -181,6 +181,7 @@ module DebugAgent
181
181
  http = Net::HTTP.new(uri.host, uri.port)
182
182
  http.use_ssl = uri.scheme == 'https'
183
183
  http.read_timeout = @cfg.timeout_seconds
184
+ http.open_timeout = 10
184
185
 
185
186
  request = Net::HTTP::Post.new(uri.path)
186
187
  request['Authorization'] = "Bearer #{@cfg.api_key}"
@@ -2,10 +2,13 @@ require 'json'
2
2
  require_relative 'chat_page'
3
3
 
4
4
  module DebugAgent
5
- # SSE callback that bridges engine to SSE response lines
5
+ # SSE callback that collects events for both buffered and streaming modes.
6
+ # In streaming mode, events are yielded in real-time via an Enumerator.
6
7
  class SseCallback < ChatCallback
7
8
  def initialize
8
9
  @events = []
10
+ @queue = Queue.new
11
+ @done = false
9
12
  end
10
13
 
11
14
  def events
@@ -14,27 +17,47 @@ module DebugAgent
14
17
 
15
18
  def on_content(chunk)
16
19
  @events << ['content', JSON.generate(chunk)]
20
+ @queue << ['content', JSON.generate(chunk)]
17
21
  end
18
22
 
19
23
  def on_tool_start(tool_name, args)
20
24
  @events << ['tool_start', tool_name]
25
+ @queue << ['tool_start', tool_name]
21
26
  end
22
27
 
23
28
  def on_tool_result(tool_name, result)
24
29
  @events << ['tool_result', "#{tool_name}: #{result}"]
30
+ @queue << ['tool_result', "#{tool_name}: #{result}"]
25
31
  end
26
32
 
27
33
  def on_complete
28
34
  @events << ['done', '']
35
+ @queue << ['done', '']
36
+ @done = true
37
+ @queue.close
29
38
  end
30
39
 
31
40
  def on_error(message)
32
41
  @events << ['error', message]
42
+ @queue << ['error', message]
43
+ @done = true
44
+ @queue.close
33
45
  end
34
46
 
35
47
  def on_context_compressed(original, compressed, removed_rounds)
36
48
  info = JSON.generate({ originalTokens: original, compressedTokens: compressed, removedRounds: removed_rounds })
37
49
  @events << ['context_compressed', info]
50
+ @queue << ['context_compressed', info]
51
+ end
52
+
53
+ # Real-time streaming Enumerator: yields SSE-formatted lines as events arrive.
54
+ def streaming_enum
55
+ Enumerator.new do |yielder|
56
+ while (item = @queue.pop)
57
+ event_type, data = item
58
+ yielder << "event: #{event_type}\ndata: #{data}\n\n"
59
+ end
60
+ end
38
61
  end
39
62
  end
40
63
 
@@ -67,35 +90,55 @@ module DebugAgent
67
90
 
68
91
  # Shared routing logic used by both RackMiddleware class and Middleware lambda
69
92
  module MiddlewareCore
93
+ CORS_HEADERS = {
94
+ 'Access-Control-Allow-Origin' => '*',
95
+ 'Access-Control-Allow-Methods' => 'GET, POST, OPTIONS',
96
+ 'Access-Control-Allow-Headers' => 'Content-Type, Authorization',
97
+ }.freeze
98
+
70
99
  def self.call(env, app, engine, config)
71
100
  path = env['PATH_INFO']
72
101
  method = env['REQUEST_METHOD']
73
102
  base = config.base_path
74
103
 
104
+ # CORS preflight for all agent routes
105
+ if path.start_with?(base) && method == 'OPTIONS'
106
+ return [204, CORS_HEADERS.merge('Content-Length' => '0'), []]
107
+ end
108
+
75
109
  # Chat UI
76
110
  if path == base || path == "#{base}/"
77
111
  if method == 'GET'
78
112
  html = ChatPage.render(base)
79
- return [200, { 'Content-Type' => 'text/html; charset=utf-8' }, [html]]
113
+ return [200, { 'Content-Type' => 'text/html; charset=utf-8' }.merge(CORS_HEADERS), [html]]
80
114
  end
81
115
  end
82
116
 
83
- # SSE streaming chat
117
+ # SSE streaming chat — real-time streaming via Rack response body
84
118
  if path == "#{base}/api/chat" && method == 'POST'
85
119
  body = JSON.parse(env['rack.input'].read)
86
120
  message = body['message'] || ''
87
121
  session_id = body['sessionId'] || "session-#{Time.now.to_i}"
88
122
 
89
123
  cb = SseCallback.new
90
- engine.chat(message, session_id, cb)
91
124
 
92
- stream = cb.events.map { |event_type, data| "event: #{event_type}\ndata: #{data}\n\n" }.join
125
+ # Run engine in a background thread for real-time streaming
126
+ Thread.new do
127
+ begin
128
+ engine.chat(message, session_id, cb)
129
+ rescue => e
130
+ cb.on_error("Internal error: #{e.message}")
131
+ end
132
+ end
133
+
134
+ # Return a streaming response body (Rack 2+ / Rack 3 compatible)
135
+ streaming_body = cb.streaming_enum
93
136
 
94
137
  return [200, {
95
138
  'Content-Type' => 'text/event-stream',
96
139
  'Cache-Control' => 'no-cache',
97
- 'Connection' => 'keep-alive'
98
- }, [stream]]
140
+ 'Connection' => 'keep-alive',
141
+ }.merge(CORS_HEADERS), streaming_body]
99
142
  end
100
143
 
101
144
  # Clear conversation
@@ -103,17 +146,17 @@ module DebugAgent
103
146
  body = JSON.parse(env['rack.input'].read)
104
147
  session_id = body['sessionId'] || ''
105
148
  engine.clear_session(session_id) if session_id && !session_id.empty?
106
- return [200, { 'Content-Type' => 'application/json' }, [JSON.generate({ status: 'cleared' })]]
149
+ return [200, { 'Content-Type' => 'application/json' }.merge(CORS_HEADERS), [JSON.generate({ status: 'cleared' })]]
107
150
  end
108
151
 
109
152
  # Health check
110
153
  if path == "#{base}/api/health" && method == 'GET'
111
- return [200, { 'Content-Type' => 'application/json' }, [JSON.generate({ status: 'ok', agent: 'ruby-debug-agent' })]]
154
+ return [200, { 'Content-Type' => 'application/json' }.merge(CORS_HEADERS), [JSON.generate({ status: 'ok', agent: 'ruby-debug-agent' })]]
112
155
  end
113
156
 
114
157
  # List tools
115
158
  if path == "#{base}/api/tools" && method == 'GET'
116
- return [200, { 'Content-Type' => 'application/json' }, [JSON.generate({ tools: engine.tools.all_schemas })]]
159
+ return [200, { 'Content-Type' => 'application/json' }.merge(CORS_HEADERS), [JSON.generate({ tools: engine.tools.all_schemas })]]
117
160
  end
118
161
 
119
162
  # Pass through to the wrapped app
@@ -1,5 +1,6 @@
1
1
  module DebugAgent
2
2
  CATEGORY_MAP = {
3
+ # Memory & GC
3
4
  'gc' => 'Memory & GC',
4
5
  'object_space' => 'Memory & GC',
5
6
  'memory' => 'Memory & GC',
@@ -7,22 +8,101 @@ module DebugAgent
7
8
  'allocations' => 'Memory & GC',
8
9
  'force_gc' => 'Memory & GC',
9
10
  'trigger_gc' => 'Memory & GC',
11
+ 'leak' => 'Memory & GC',
12
+ 'heap' => 'Memory & GC',
13
+ 'snapshot' => 'Memory & Snapshots',
14
+ 'compare' => 'Memory & Snapshots',
15
+ # Process & Runtime
10
16
  'process' => 'Process Info',
11
17
  'cpu' => 'Process Info',
12
18
  'uptime' => 'Process Info',
13
- 'thread' => 'Threads',
19
+ 'runtime' => 'Runtime Info',
14
20
  'system' => 'System Info',
15
21
  'disk' => 'System Info',
16
- 'environment' => 'System Info',
22
+ 'environment' => 'Environment & Config',
23
+ # Threads & Locks
24
+ 'thread' => 'Threads & Locks',
25
+ 'lock' => 'Threads & Locks',
26
+ 'deadlock' => 'Threads & Locks',
27
+ 'contention' => 'Threads & Locks',
28
+ 'gvl' => 'Threads & Locks',
29
+ 'mutex' => 'Threads & Locks',
30
+ 'fiber' => 'Threads & Locks',
31
+ # Framework
17
32
  'routes' => 'Framework & Routes',
18
33
  'middleware' => 'Framework & Routes',
19
- 'runtime' => 'Runtime Info',
34
+ 'rails' => 'Framework & Routes',
35
+ 'sinatra' => 'Framework & Routes',
36
+ # HTTP
20
37
  'recent' => 'HTTP Requests',
21
38
  'slow' => 'HTTP Requests',
22
- 'error' => 'HTTP Requests',
39
+ 'error' => 'Error Tracking',
23
40
  'request' => 'HTTP Requests',
24
- 'gem' => 'Dependencies',
41
+ 'http' => 'HTTP Requests',
42
+ 'outbound' => 'HTTP Requests',
43
+ 'faraday' => 'HTTP Requests',
44
+ # Database
45
+ 'active_record' => 'Database',
46
+ 'migration' => 'Database Migration',
47
+ 'pending' => 'Database Migration',
48
+ 'sql' => 'Database',
49
+ 'database' => 'Database',
50
+ # Configuration
51
+ 'config' => 'Configuration',
52
+ 'env' => 'Configuration',
53
+ # Cache
54
+ 'cache' => 'Cache',
55
+ # Health & Security
56
+ 'health' => 'Health Checks',
57
+ 'auth' => 'Security',
58
+ 'cors' => 'Security',
59
+ # WebSocket
60
+ 'ws' => 'WebSocket',
61
+ 'websocket' => 'WebSocket',
62
+ # Profiling
63
+ 'start' => 'Profiling',
64
+ 'stop' => 'Profiling',
65
+ 'top' => 'Profiling',
66
+ 'profile' => 'Profiling',
67
+ # Feature Flags
68
+ 'feature' => 'Feature Flags',
69
+ 'flag' => 'Feature Flags',
70
+ 'evaluate' => 'Feature Flags',
71
+ # Endpoint Testing
72
+ 'test' => 'Endpoint Testing',
73
+ 'batch' => 'Endpoint Testing',
74
+ 'endpoint' => 'Endpoint Testing',
75
+ 'coverage' => 'Endpoint Testing',
76
+ # Connection Pool
77
+ 'pool' => 'Connection Pool',
78
+ 'connection' => 'Connection Pool',
79
+ # File Descriptors
80
+ 'fd' => 'File Descriptors',
81
+ 'handle' => 'File Descriptors',
82
+ # Metrics
83
+ 'metric' => 'Metrics',
84
+ 'counter' => 'Metrics',
85
+ # Build & Deployment
86
+ 'build' => 'Build & Deployment',
87
+ 'deployment' => 'Build & Deployment',
88
+ 'version' => 'Build & Deployment',
89
+ # Service Registry
90
+ 'registered' => 'Service Registry',
91
+ 'service' => 'Service Registry',
92
+ 'dependencies' => 'Service Registry',
93
+ # Job Queue
94
+ 'sidekiq' => 'Job Queue',
95
+ 'queue' => 'Job Queue',
96
+ 'job' => 'Job Queue',
97
+ # Redis
98
+ 'redis' => 'Redis',
99
+ # Logging
100
+ 'log' => 'Logging',
101
+ # Modules & Dependencies
25
102
  'module' => 'Module Info',
103
+ 'gem' => 'Dependencies',
104
+ 'loaded' => 'Module Info',
105
+ 'installed' => 'Dependencies',
26
106
  }.freeze
27
107
 
28
108
  class SystemPromptBuilder
@@ -1,3 +1,3 @@
1
1
  module DebugAgent
2
- VERSION = '0.6.0'.freeze
2
+ VERSION = '0.7.1'.freeze
3
3
  end
data/lib/debug_agent.rb CHANGED
@@ -41,10 +41,24 @@ require_relative 'debug_agent/inspectors/config_inspector'
41
41
  require_relative 'debug_agent/inspectors/feature_flags'
42
42
  require_relative 'debug_agent/inspectors/endpoint_test'
43
43
  require_relative 'debug_agent/inspectors/pool_inspector'
44
+ require_relative 'debug_agent/inspectors/cpu_profile'
45
+ require_relative 'debug_agent/inspectors/leak_detector'
46
+ require_relative 'debug_agent/inspectors/build_info'
47
+ require_relative 'debug_agent/inspectors/snapshot'
48
+ require_relative 'debug_agent/inspectors/service_registry'
44
49
 
45
50
  module DebugAgent
46
51
  class Error < StandardError; end
47
52
 
53
+ # ggcode promotional message — shown once on first require
54
+ unless defined?(@_ggcode_banner_shown)
55
+ @_ggcode_banner_shown = true
56
+ puts ""
57
+ puts " This package was built with ggcode — an AI coding assistant."
58
+ puts " https://github.com/topcheer/ggcode"
59
+ puts ""
60
+ end
61
+
48
62
  # Process start time for uptime tracking
49
63
  PROCESS_START_TIME = Time.now
50
64
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debug-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ggcode
@@ -165,10 +165,12 @@ files:
165
165
  - lib/debug_agent/context_compressor.rb
166
166
  - lib/debug_agent/engine.rb
167
167
  - lib/debug_agent/inspectors/active_record_stats.rb
168
+ - lib/debug_agent/inspectors/build_info.rb
168
169
  - lib/debug_agent/inspectors/cache.rb
169
170
  - lib/debug_agent/inspectors/concurrent.rb
170
171
  - lib/debug_agent/inspectors/config_inspector.rb
171
172
  - lib/debug_agent/inspectors/core_ext.rb
173
+ - lib/debug_agent/inspectors/cpu_profile.rb
172
174
  - lib/debug_agent/inspectors/endpoint_test.rb
173
175
  - lib/debug_agent/inspectors/error_tracking.rb
174
176
  - lib/debug_agent/inspectors/faraday.rb
@@ -177,6 +179,7 @@ files:
177
179
  - lib/debug_agent/inspectors/health.rb
178
180
  - lib/debug_agent/inspectors/http_client.rb
179
181
  - lib/debug_agent/inspectors/http_tracker.rb
182
+ - lib/debug_agent/inspectors/leak_detector.rb
180
183
  - lib/debug_agent/inspectors/locks.rb
181
184
  - lib/debug_agent/inspectors/logging.rb
182
185
  - lib/debug_agent/inspectors/metrics.rb
@@ -191,7 +194,9 @@ files:
191
194
  - lib/debug_agent/inspectors/runtime.rb
192
195
  - lib/debug_agent/inspectors/scheduler.rb
193
196
  - lib/debug_agent/inspectors/security.rb
197
+ - lib/debug_agent/inspectors/service_registry.rb
194
198
  - lib/debug_agent/inspectors/sidekiq.rb
199
+ - lib/debug_agent/inspectors/snapshot.rb
195
200
  - lib/debug_agent/inspectors/system.rb
196
201
  - lib/debug_agent/inspectors/threads.rb
197
202
  - lib/debug_agent/inspectors/websocket.rb