debug-agent 0.7.0 → 0.8.0
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 +4 -4
- data/README.md +67 -0
- data/lib/debug_agent/chat_page.rb +11 -2
- data/lib/debug_agent/chat_session.rb +33 -2
- data/lib/debug_agent/config.rb +112 -4
- data/lib/debug_agent/engine.rb +69 -1
- data/lib/debug_agent/inspectors/cache.rb +2 -1
- data/lib/debug_agent/inspectors/endpoint_test.rb +35 -1
- data/lib/debug_agent/inspectors/gc.rb +2 -2
- data/lib/debug_agent/inspectors/leak_detector.rb +5 -0
- data/lib/debug_agent/inspectors/logging.rb +2 -1
- data/lib/debug_agent/inspectors/runtime.rb +1 -1
- data/lib/debug_agent/inspectors/snapshot.rb +6 -0
- data/lib/debug_agent/llm_client.rb +2 -1
- data/lib/debug_agent/middleware.rb +306 -26
- data/lib/debug_agent/system_prompt_builder.rb +85 -5
- data/lib/debug_agent/tool_registry.rb +72 -7
- data/lib/debug_agent/version.rb +1 -1
- data/lib/debug_agent.rb +0 -9
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3765ed2a5d8a59ed8e2dbe9fbc5d2242495e010efba4572eae92812dd5e8a364
|
|
4
|
+
data.tar.gz: 64244f052df523defa0b948e6c1198a36b137398f3bed04e481ad6fdda572322
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e9986fd62e11d4bd221cd913f538b851593d7edc85be8f622b32f6a72ab14be8cdadd8ac496dbc11bd402ee24d0e09253f2a2cfc5e60b1140e5f9896077a1256
|
|
7
|
+
data.tar.gz: e8e8edb65859072215d97edc08ae4942bcd90972666ea50fec1491e050970c0540df1fa48cb89ba8a2ee890f71d41c30f417aeb6ccffeb3b036844bf8d1526c1
|
data/README.md
CHANGED
|
@@ -292,6 +292,13 @@ require 'debug_agent'
|
|
|
292
292
|
DebugAgent.register_tool('check_redis', 'Check Redis connection') do
|
|
293
293
|
{ connected: true }
|
|
294
294
|
end
|
|
295
|
+
|
|
296
|
+
# Tools with side effects are hidden and refused until
|
|
297
|
+
# DEBUG_AGENT_ALLOW_MUTATING_TOOLS=true (see Troubleshooting is read-only by default):
|
|
298
|
+
DebugAgent.mutating_tool('purge_tmp', 'Remove temporary files') do
|
|
299
|
+
{ purged: true }
|
|
300
|
+
end
|
|
301
|
+
# or equivalently: DebugAgent.register_tool('purge_tmp', 'Remove temporary files', mutating: true) { ... }
|
|
295
302
|
```
|
|
296
303
|
|
|
297
304
|
## Configuration
|
|
@@ -303,6 +310,66 @@ end
|
|
|
303
310
|
| `LLM_MODEL` | `glm-5.2` | Model name |
|
|
304
311
|
| `LLM_MAX_TOOL_ROUNDS` | `25` | Max tool-calling rounds |
|
|
305
312
|
| `LLM_CONTEXT_WINDOW_TOKENS` | `100000` | Context window size |
|
|
313
|
+
| `DEBUG_AGENT_ENABLED` | `true` | Set `false` to disable the agent: every `/agent` route is passed through to the app as if not mounted |
|
|
314
|
+
| `DEBUG_AGENT_BASE_PATH` | `/agent` | Mount path |
|
|
315
|
+
| `DEBUG_AGENT_API_KEY` | *(empty = no auth)* | When set, the UI and all `/agent/api/*` require this key |
|
|
316
|
+
| `DEBUG_AGENT_CORS_ORIGIN` | `*` | `Access-Control-Allow-Origin`; with an API key set, `*` means same-origin only |
|
|
317
|
+
| `DEBUG_AGENT_MAX_SESSIONS` | `200` | In-memory session cap (least-recently-active evicted first) |
|
|
318
|
+
| `DEBUG_AGENT_SESSION_TTL_SECONDS` | `3600` | Drop a session's history after this much inactivity |
|
|
319
|
+
| `DEBUG_AGENT_MAX_HISTORY` | `100` | Stored messages per session (oldest whole rounds dropped) |
|
|
320
|
+
| `DEBUG_AGENT_MAX_BODY_BYTES` | `1048576` | Request body limit for POST endpoints (413 beyond) |
|
|
321
|
+
| `DEBUG_AGENT_RATE_LIMIT` | `60` | `POST /agent/api/chat` requests per client IP per minute (429 beyond) |
|
|
322
|
+
| `DEBUG_AGENT_ALLOW_MUTATING_TOOLS` | `false` | Opt in to tools with side effects: `trigger_gc`, `force_gc`, `set_log_level`, `clear_cache`, and non-GET/HEAD/OPTIONS requests through `test_endpoint` / `batch_test_endpoints` |
|
|
323
|
+
|
|
324
|
+
### Troubleshooting is read-only by default
|
|
325
|
+
|
|
326
|
+
Only read-only tools are offered to the model. Mutating tools are hidden from the
|
|
327
|
+
tool list (and from `/agent/api/tools`) and refused with a `disabled` error until
|
|
328
|
+
`DEBUG_AGENT_ALLOW_MUTATING_TOOLS=true`:
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
export DEBUG_AGENT_ALLOW_MUTATING_TOOLS=true
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
| Tool | Side effect |
|
|
335
|
+
|------|-------------|
|
|
336
|
+
| `trigger_gc`, `force_gc` | Run a garbage collection in the app process |
|
|
337
|
+
| `set_log_level` | Changes a registered logger's level |
|
|
338
|
+
| `clear_cache` | Removes all entries of a registered cache |
|
|
339
|
+
| `test_endpoint`, `batch_test_endpoints` | Non-`GET`/`HEAD`/`OPTIONS` requests to the app (`GET`/`HEAD`/`OPTIONS` always work) |
|
|
340
|
+
|
|
341
|
+
Endpoint testing only ever targets the app's own `localhost` port: a `path` that
|
|
342
|
+
does not start with `/` (or starts with `//`) is rejected, so the request can
|
|
343
|
+
never be redirected to another host. Starting without `DEBUG_AGENT_API_KEY`
|
|
344
|
+
logs a one-line warning to stderr; it does not change behaviour.
|
|
345
|
+
|
|
346
|
+
> **Upgrade note (breaking):** before this change the mutating tools above were
|
|
347
|
+
available by default. After upgrading they are hidden from the model and refused
|
|
348
|
+
with a `disabled` error; calls with `POST`/`PUT`/`PATCH`/`DELETE` through the
|
|
349
|
+
endpoint-testing tools are refused in the same way. Set
|
|
350
|
+
`DEBUG_AGENT_ALLOW_MUTATING_TOOLS=true` to restore the previous behaviour.
|
|
351
|
+
|
|
352
|
+
### Security in production
|
|
353
|
+
|
|
354
|
+
By default the agent has **no authentication** and allows any origin — fine on a
|
|
355
|
+
developer laptop, not on a reachable port. Before exposing it:
|
|
356
|
+
|
|
357
|
+
```bash
|
|
358
|
+
export DEBUG_AGENT_API_KEY=$(openssl rand -hex 32) # required on every agent route
|
|
359
|
+
export DEBUG_AGENT_ENABLED=false # or switch it off entirely in prod
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
With a key set, present it as `Authorization: Bearer <key>`, `X-API-Key: <key>`,
|
|
363
|
+
or open the UI as `/agent?api_key=<key>` (the page then sends it as a Bearer
|
|
364
|
+
header). CORS becomes same-origin only unless `DEBUG_AGENT_CORS_ORIGIN` names an
|
|
365
|
+
explicit origin. `POST /api/chat` is rate-limited per client IP (first
|
|
366
|
+
`X-Forwarded-For` hop when behind a proxy — only trust it behind one you control).
|
|
367
|
+
|
|
368
|
+
### Running the tests
|
|
369
|
+
|
|
370
|
+
```bash
|
|
371
|
+
bundle exec rspec
|
|
372
|
+
```
|
|
306
373
|
|
|
307
374
|
## Run the Demo
|
|
308
375
|
|
|
@@ -248,6 +248,15 @@ module DebugAgent
|
|
|
248
248
|
const sessionId = 'session-' + Math.random().toString(36).substring(2, 11);
|
|
249
249
|
const BASE_PATH = window.location.pathname;
|
|
250
250
|
|
|
251
|
+
// When the agent is protected by an API key, open the UI as /agent?api_key=...
|
|
252
|
+
// and every request below carries it as a Bearer header.
|
|
253
|
+
const AGENT_KEY = new URLSearchParams(location.search).get('api_key') || '';
|
|
254
|
+
function agentHeaders() {
|
|
255
|
+
const h = {'Content-Type': 'application/json'};
|
|
256
|
+
if (AGENT_KEY) h['Authorization'] = 'Bearer ' + AGENT_KEY;
|
|
257
|
+
return h;
|
|
258
|
+
}
|
|
259
|
+
|
|
251
260
|
const chatMessages = document.getElementById('chat-messages');
|
|
252
261
|
const chatContainer = document.getElementById('chat-container');
|
|
253
262
|
const input = document.getElementById('input');
|
|
@@ -271,7 +280,7 @@ module DebugAgent
|
|
|
271
280
|
e.preventDefault();
|
|
272
281
|
if (confirm('Clear conversation history?')) {
|
|
273
282
|
fetch(BASE_PATH + '/api/clear', {
|
|
274
|
-
method: 'POST', headers:
|
|
283
|
+
method: 'POST', headers: agentHeaders(),
|
|
275
284
|
body: JSON.stringify({sessionId: sessionId})
|
|
276
285
|
}).then(() => {
|
|
277
286
|
chatMessages.innerHTML = '';
|
|
@@ -494,7 +503,7 @@ module DebugAgent
|
|
|
494
503
|
try {
|
|
495
504
|
const response = await fetch(BASE_PATH + '/api/chat', {
|
|
496
505
|
method: 'POST',
|
|
497
|
-
headers:
|
|
506
|
+
headers: agentHeaders(),
|
|
498
507
|
body: JSON.stringify({message: text, sessionId: sessionId})
|
|
499
508
|
});
|
|
500
509
|
if (!response.ok) throw new Error('HTTP ' + response.status);
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
require 'time'
|
|
2
2
|
|
|
3
3
|
module DebugAgent
|
|
4
|
+
# defaultMaxHistory is the per-session message cap unless configured otherwise.
|
|
5
|
+
DEFAULT_MAX_HISTORY = 100
|
|
6
|
+
|
|
4
7
|
class ChatSession
|
|
5
8
|
attr_accessor :session_id, :messages, :last_token_usage,
|
|
6
|
-
:cumulative_prompt_tokens, :cumulative_completion_tokens
|
|
9
|
+
:cumulative_prompt_tokens, :cumulative_completion_tokens,
|
|
10
|
+
:last_active_at
|
|
11
|
+
attr_reader :created_at
|
|
12
|
+
|
|
13
|
+
# MaxHistory caps messages.length; 0 means unlimited.
|
|
14
|
+
attr_accessor :max_history
|
|
7
15
|
|
|
8
|
-
def initialize(session_id)
|
|
16
|
+
def initialize(session_id, max_history = DEFAULT_MAX_HISTORY)
|
|
9
17
|
@session_id = session_id
|
|
10
18
|
@messages = []
|
|
11
19
|
@created_at = Time.now
|
|
@@ -13,10 +21,12 @@ module DebugAgent
|
|
|
13
21
|
@last_token_usage = nil
|
|
14
22
|
@cumulative_prompt_tokens = 0
|
|
15
23
|
@cumulative_completion_tokens = 0
|
|
24
|
+
@max_history = max_history.nil? ? DEFAULT_MAX_HISTORY : max_history
|
|
16
25
|
end
|
|
17
26
|
|
|
18
27
|
def add_message(msg)
|
|
19
28
|
@messages << msg
|
|
29
|
+
trim_history
|
|
20
30
|
@last_active_at = Time.now
|
|
21
31
|
end
|
|
22
32
|
|
|
@@ -25,6 +35,27 @@ module DebugAgent
|
|
|
25
35
|
@last_active_at = Time.now
|
|
26
36
|
end
|
|
27
37
|
|
|
38
|
+
# trimHistory drops the oldest whole rounds until messages.length <= max_history.
|
|
39
|
+
# Cuts only happen at a `user` message boundary so the remaining history never
|
|
40
|
+
# starts with an assistant tool_call or an orphaned tool result (which the LLM
|
|
41
|
+
# API rejects). If no safe cut point exists the history is left untouched.
|
|
42
|
+
def trim_history
|
|
43
|
+
return if @max_history.nil? || @max_history <= 0 || @messages.length <= @max_history
|
|
44
|
+
|
|
45
|
+
while @messages.length > @max_history
|
|
46
|
+
cut = nil
|
|
47
|
+
(1...@messages.length).each do |i|
|
|
48
|
+
if @messages[i]['role'] == 'user'
|
|
49
|
+
cut = i
|
|
50
|
+
break
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
return if cut.nil?
|
|
54
|
+
|
|
55
|
+
@messages = @messages[cut..-1]
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
28
59
|
def record_token_usage(usage)
|
|
29
60
|
return unless usage
|
|
30
61
|
@last_token_usage = usage
|
data/lib/debug_agent/config.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
1
3
|
module DebugAgent
|
|
2
4
|
LLMConfig = Struct.new(
|
|
3
5
|
:base_url, :api_key, :model, :temperature, :max_tokens,
|
|
@@ -19,16 +21,122 @@ module DebugAgent
|
|
|
19
21
|
self.context_window_tokens ||= 100_000
|
|
20
22
|
self
|
|
21
23
|
end
|
|
24
|
+
|
|
25
|
+
# The LLM api key is a secret: keep it out of inspect/serialization output.
|
|
26
|
+
def to_h
|
|
27
|
+
super.tap { |h| h[:api_key] = '[REDACTED]' unless h[:api_key].to_s.empty? }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def to_json(*args)
|
|
31
|
+
to_h.to_json(*args)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def inspect
|
|
35
|
+
fields = to_h.map { |field, value| "#{field}=#{value.inspect}" }
|
|
36
|
+
"#<struct #{self.class.name} #{fields.join(', ')}>"
|
|
37
|
+
end
|
|
22
38
|
end
|
|
23
39
|
|
|
24
|
-
|
|
40
|
+
# Agent configuration, env-driven (see Config.from_env).
|
|
41
|
+
#
|
|
42
|
+
# Hardening fields:
|
|
43
|
+
# api_key non-empty → UI and all /api/* require the key
|
|
44
|
+
# cors_origin Access-Control-Allow-Origin (see MiddlewareCore.cors_headers)
|
|
45
|
+
# max_sessions session table cap (LRU eviction); 0 = unlimited
|
|
46
|
+
# session_ttl_seconds idle > ttl → fresh history on next use; 0 = never
|
|
47
|
+
# max_history_messages stored messages per session (whole rounds); 0 = unlimited
|
|
48
|
+
# max_body_bytes POST body limit (413 beyond)
|
|
49
|
+
# rate_limit_per_minute POST /api/chat per client IP; 0 = unlimited
|
|
50
|
+
# allow_mutating_tools true → tools with side effects (trigger_gc,
|
|
51
|
+
# set_log_level, clear_cache, non-GET/HEAD/OPTIONS
|
|
52
|
+
# test_endpoint requests) are offered and run.
|
|
53
|
+
# false (default) → hidden from the LLM and refused.
|
|
54
|
+
#
|
|
55
|
+
# Every field is optional: a nil value falls back to DEFAULTS.
|
|
56
|
+
Config = Struct.new(
|
|
57
|
+
:enabled, :base_path, :llm,
|
|
58
|
+
:api_key, :cors_origin, :max_sessions, :session_ttl_seconds,
|
|
59
|
+
:max_history_messages, :max_body_bytes, :rate_limit_per_minute,
|
|
60
|
+
:allow_mutating_tools,
|
|
61
|
+
keyword_init: true
|
|
62
|
+
) do
|
|
25
63
|
def self.from_env
|
|
26
|
-
llm = LLMConfig.new.defaults!
|
|
27
64
|
new(
|
|
28
|
-
enabled:
|
|
65
|
+
enabled: env_bool('DEBUG_AGENT_ENABLED', true),
|
|
29
66
|
base_path: ENV.fetch('DEBUG_AGENT_BASE_PATH', '/agent'),
|
|
30
|
-
|
|
67
|
+
api_key: ENV.fetch('DEBUG_AGENT_API_KEY', ''),
|
|
68
|
+
cors_origin: ENV.fetch('DEBUG_AGENT_CORS_ORIGIN', '*'),
|
|
69
|
+
max_sessions: env_int('DEBUG_AGENT_MAX_SESSIONS', 200),
|
|
70
|
+
session_ttl_seconds: env_int('DEBUG_AGENT_SESSION_TTL_SECONDS', 3600),
|
|
71
|
+
max_history_messages: env_int('DEBUG_AGENT_MAX_HISTORY', 100),
|
|
72
|
+
max_body_bytes: env_int('DEBUG_AGENT_MAX_BODY_BYTES', 1_048_576),
|
|
73
|
+
rate_limit_per_minute: env_int('DEBUG_AGENT_RATE_LIMIT', 60),
|
|
74
|
+
allow_mutating_tools: env_bool('DEBUG_AGENT_ALLOW_MUTATING_TOOLS', false),
|
|
75
|
+
llm: LLMConfig.new.defaults!
|
|
31
76
|
)
|
|
32
77
|
end
|
|
78
|
+
|
|
79
|
+
# Integer env value; unset, malformed or negative values fall back to the
|
|
80
|
+
# default (0 is valid and means "unlimited" / "off").
|
|
81
|
+
def self.env_int(key, default)
|
|
82
|
+
raw = ENV[key]
|
|
83
|
+
return default if raw.nil? || raw.strip.empty?
|
|
84
|
+
|
|
85
|
+
n = Integer(raw.strip, 10)
|
|
86
|
+
n.negative? ? default : n
|
|
87
|
+
rescue ArgumentError
|
|
88
|
+
default
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Boolean env value (same spellings as Go's strconv.ParseBool); unset or
|
|
92
|
+
# unparseable values fall back to the default.
|
|
93
|
+
def self.env_bool(key, default)
|
|
94
|
+
raw = ENV[key]
|
|
95
|
+
return default if raw.nil? || raw.strip.empty?
|
|
96
|
+
|
|
97
|
+
case raw.strip.downcase
|
|
98
|
+
when 'true', '1', 't' then true
|
|
99
|
+
when 'false', '0', 'f' then false
|
|
100
|
+
else default
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Fields a caller leaves out (nil) get their default, so configs built
|
|
105
|
+
# before the hardening fields existed keep the default behaviour.
|
|
106
|
+
def initialize(*args, &block)
|
|
107
|
+
super
|
|
108
|
+
Config::DEFAULTS.each { |field, value| self[field] = value if self[field].nil? }
|
|
109
|
+
self.llm = LLMConfig.new.defaults! if self.llm.nil?
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# The agent api key is a secret: it is never included in to_h / to_json /
|
|
113
|
+
# inspect output.
|
|
114
|
+
def to_h
|
|
115
|
+
members.each_with_object({}) do |field, hash|
|
|
116
|
+
hash[field] = self[field] unless field == :api_key
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def to_json(*args)
|
|
121
|
+
to_h.to_json(*args)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def inspect
|
|
125
|
+
fields = to_h.map { |field, value| "#{field}=#{value.inspect}" }
|
|
126
|
+
"#<struct #{self.class.name} #{fields.join(', ')}>"
|
|
127
|
+
end
|
|
33
128
|
end
|
|
129
|
+
|
|
130
|
+
Config::DEFAULTS = {
|
|
131
|
+
enabled: true,
|
|
132
|
+
base_path: '/agent',
|
|
133
|
+
api_key: '',
|
|
134
|
+
cors_origin: '*',
|
|
135
|
+
max_sessions: 200,
|
|
136
|
+
session_ttl_seconds: 3600,
|
|
137
|
+
max_history_messages: 100,
|
|
138
|
+
max_body_bytes: 1_048_576,
|
|
139
|
+
rate_limit_per_minute: 60,
|
|
140
|
+
allow_mutating_tools: false
|
|
141
|
+
}.freeze
|
|
34
142
|
end
|
data/lib/debug_agent/engine.rb
CHANGED
|
@@ -34,6 +34,8 @@ module DebugAgent
|
|
|
34
34
|
|
|
35
35
|
def initialize(config = nil)
|
|
36
36
|
@config = config || Config.from_env
|
|
37
|
+
DebugAgent.set_allow_mutating_tools(@config.allow_mutating_tools)
|
|
38
|
+
DebugAgent.warn_if_unauthenticated(@config)
|
|
37
39
|
@llm = LLMClient.new(@config.llm)
|
|
38
40
|
@tools = REGISTRY
|
|
39
41
|
|
|
@@ -64,11 +66,57 @@ module DebugAgent
|
|
|
64
66
|
end
|
|
65
67
|
end
|
|
66
68
|
|
|
69
|
+
# Number of live sessions (diagnostics / tests).
|
|
70
|
+
def session_count
|
|
71
|
+
@mutex.synchronize { @sessions.length }
|
|
72
|
+
end
|
|
73
|
+
|
|
67
74
|
private
|
|
68
75
|
|
|
69
76
|
def get_or_create_session(session_id)
|
|
77
|
+
session_id = 'default' if session_id.nil? || session_id.empty?
|
|
78
|
+
|
|
70
79
|
@mutex.synchronize do
|
|
71
|
-
@sessions[session_id]
|
|
80
|
+
session = @sessions[session_id]
|
|
81
|
+
if session
|
|
82
|
+
if session_expired?(session)
|
|
83
|
+
# Idle beyond the TTL: drop the stale history and start over.
|
|
84
|
+
session = new_session(session_id)
|
|
85
|
+
@sessions[session_id] = session
|
|
86
|
+
end
|
|
87
|
+
return session
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
session = new_session(session_id)
|
|
91
|
+
@sessions[session_id] = session
|
|
92
|
+
evict_overflow_sessions
|
|
93
|
+
session
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def new_session(session_id)
|
|
98
|
+
ChatSession.new(session_id, @config.max_history_messages)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def session_expired?(session)
|
|
102
|
+
ttl = @config.session_ttl_seconds
|
|
103
|
+
return false if ttl.nil? || ttl <= 0
|
|
104
|
+
|
|
105
|
+
Time.now - session.last_active_at > ttl
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Keeps the session table within max_sessions by dropping the
|
|
109
|
+
# least-recently-active sessions. 0 (or nil) disables the cap.
|
|
110
|
+
# Caller holds @mutex.
|
|
111
|
+
def evict_overflow_sessions
|
|
112
|
+
max = @config.max_sessions
|
|
113
|
+
return if max.nil? || max <= 0
|
|
114
|
+
|
|
115
|
+
while @sessions.length > max
|
|
116
|
+
oldest_id = @sessions.min_by { |_id, s| s.last_active_at }&.first
|
|
117
|
+
break if oldest_id.nil?
|
|
118
|
+
|
|
119
|
+
@sessions.delete(oldest_id)
|
|
72
120
|
end
|
|
73
121
|
end
|
|
74
122
|
|
|
@@ -159,4 +207,24 @@ module DebugAgent
|
|
|
159
207
|
cb.on_complete
|
|
160
208
|
end
|
|
161
209
|
end
|
|
210
|
+
|
|
211
|
+
UNAUTHENTICATED_WARNING = '[debug-agent] WARNING: DEBUG_AGENT_API_KEY is not set - the agent UI and API ' \
|
|
212
|
+
'are unauthenticated; anyone who can reach this port can drive the LLM and ' \
|
|
213
|
+
'diagnostic tools (safe on localhost only).'.freeze
|
|
214
|
+
|
|
215
|
+
class << self
|
|
216
|
+
# Emits a one-line startup warning (stderr only) the first time an engine
|
|
217
|
+
# is created without an API key: anyone who can reach the port can then
|
|
218
|
+
# drive the LLM and every diagnostic tool. Does not change behaviour - only
|
|
219
|
+
# the operator can decide whether the port is reachable. Nothing is printed
|
|
220
|
+
# when a key is configured.
|
|
221
|
+
def warn_if_unauthenticated(config)
|
|
222
|
+
key = config.respond_to?(:api_key) ? config.api_key.to_s : ''
|
|
223
|
+
return unless key.empty?
|
|
224
|
+
return if @unauthenticated_warned
|
|
225
|
+
|
|
226
|
+
@unauthenticated_warned = true
|
|
227
|
+
warn UNAUTHENTICATED_WARNING
|
|
228
|
+
end
|
|
229
|
+
end
|
|
162
230
|
end
|
|
@@ -154,7 +154,8 @@ module DebugAgent
|
|
|
154
154
|
|
|
155
155
|
register_tool('clear_cache',
|
|
156
156
|
'Clear a registered cache (destructive: removes all entries)',
|
|
157
|
-
name: { type: 'string', description: 'Registered cache name (optional, defaults to first)', required: false }
|
|
157
|
+
name: { type: 'string', description: 'Registered cache name (optional, defaults to first)', required: false },
|
|
158
|
+
mutating: true) do |name: nil|
|
|
158
159
|
if caches.empty?
|
|
159
160
|
next { error: 'No caches registered. Call DebugAgent.register_cache(:name, cache).' }
|
|
160
161
|
end
|
|
@@ -54,6 +54,10 @@ module DebugAgent
|
|
|
54
54
|
port = app_port
|
|
55
55
|
host = app_host
|
|
56
56
|
|
|
57
|
+
# The URL is built from a fixed host/port; the path is the only
|
|
58
|
+
# caller-controlled part, so it must stay an absolute path on this host
|
|
59
|
+
# (rejects "@evil.com/x", "//evil.com", absolute URLs, backslashes,
|
|
60
|
+
# control characters).
|
|
57
61
|
uri = URI("http://#{host}:#{port}#{path}")
|
|
58
62
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
59
63
|
http.read_timeout = 30
|
|
@@ -100,6 +104,24 @@ module DebugAgent
|
|
|
100
104
|
rescue => e
|
|
101
105
|
{ error: "Request failed: #{e.message}", method: method, path: path }
|
|
102
106
|
end
|
|
107
|
+
|
|
108
|
+
# True for an absolute path that cannot move the request to another host.
|
|
109
|
+
def valid_endpoint_path?(path)
|
|
110
|
+
path.is_a?(String) && path.start_with?('/') &&
|
|
111
|
+
!path.start_with?('//') && path !~ /[\\\s\x00-\x1f\x7f]/
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def endpoint_path_error
|
|
115
|
+
{ error: 'path must be relative and start with /' }
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def mutating_method_refused?(method)
|
|
119
|
+
!DebugAgent.safe_http_method?(method) && !DebugAgent.mutating_tools_allowed?
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def endpoint_disabled_error(method, path)
|
|
123
|
+
{ error: "#{method} #{path} is #{DebugAgent::MUTATING_DISABLED}" }
|
|
124
|
+
end
|
|
103
125
|
end
|
|
104
126
|
|
|
105
127
|
register_tool('test_endpoint',
|
|
@@ -109,11 +131,15 @@ module DebugAgent
|
|
|
109
131
|
path: { type: 'string', description: 'Request path (e.g. /api/orders)', required: true },
|
|
110
132
|
headers: { type: 'object', description: 'Optional HTTP headers as key-value pairs (e.g. {"X-API-Key": "demo-key-12345"})', required: false },
|
|
111
133
|
body: { type: 'string', description: 'Optional request body (JSON string for POST/PUT)', required: false }) do |method:, path:, headers: nil, body: nil|
|
|
112
|
-
method_up = method.to_s.upcase
|
|
134
|
+
method_up = method.to_s.strip.upcase
|
|
135
|
+
method_up = 'GET' if method_up.empty?
|
|
113
136
|
unless %w[GET POST PUT DELETE PATCH HEAD OPTIONS].include?(method_up)
|
|
114
137
|
next { error: "Unsupported HTTP method: #{method}. Use GET, POST, PUT, DELETE, PATCH, HEAD, or OPTIONS." }
|
|
115
138
|
end
|
|
116
139
|
|
|
140
|
+
next endpoint_path_error unless valid_endpoint_path?(path)
|
|
141
|
+
next endpoint_disabled_error(method_up, path) if mutating_method_refused?(method_up)
|
|
142
|
+
|
|
117
143
|
result = perform_http_request(method_up, path, headers, body)
|
|
118
144
|
|
|
119
145
|
if result[:error]
|
|
@@ -146,6 +172,14 @@ module DebugAgent
|
|
|
146
172
|
next { method: method, path: '(missing)', error: 'Missing required field: path' }
|
|
147
173
|
end
|
|
148
174
|
|
|
175
|
+
# Per-entry refusals: the remaining entries still run.
|
|
176
|
+
unless valid_endpoint_path?(path)
|
|
177
|
+
next { method: method, path: path, error: endpoint_path_error[:error], passed: false }
|
|
178
|
+
end
|
|
179
|
+
if mutating_method_refused?(method)
|
|
180
|
+
next { method: method, path: path, error: endpoint_disabled_error(method, path)[:error], passed: false }
|
|
181
|
+
end
|
|
182
|
+
|
|
149
183
|
http_result = perform_http_request(method, path, headers, body)
|
|
150
184
|
|
|
151
185
|
if http_result[:error]
|
|
@@ -115,8 +115,8 @@ module DebugAgent
|
|
|
115
115
|
{ error: e.message }
|
|
116
116
|
end
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
mutating_tool('force_gc',
|
|
119
|
+
'Trigger a full garbage collection (GC.start with full_mark) and show before/after comparison') do
|
|
120
120
|
before_stats = GC.stat
|
|
121
121
|
before_objects = ObjectSpace.count_objects.values.sum
|
|
122
122
|
|
|
@@ -45,6 +45,11 @@ module DebugAgent
|
|
|
45
45
|
heap_pages: gc_stats[:heap_length]
|
|
46
46
|
}
|
|
47
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
|
|
48
53
|
@heap_snapshots[snapshot_id] = snapshot
|
|
49
54
|
|
|
50
55
|
{
|
|
@@ -140,7 +140,8 @@ module DebugAgent
|
|
|
140
140
|
register_tool('set_log_level',
|
|
141
141
|
"Dynamically change a registered logger's level",
|
|
142
142
|
logger_name: { type: 'string', description: 'Registered logger name' },
|
|
143
|
-
level: { type: 'string', description: 'One of: debug, info, warn, error, fatal' }
|
|
143
|
+
level: { type: 'string', description: 'One of: debug, info, warn, error, fatal' },
|
|
144
|
+
mutating: true) do |logger_name:, level:|
|
|
144
145
|
logger = loggers[logger_name.to_s]
|
|
145
146
|
next({ error: "No logger registered under '#{logger_name}'" }) unless logger
|
|
146
147
|
next({ error: 'Logger does not respond to level=' }) unless logger.respond_to?(:level=)
|
|
@@ -29,7 +29,7 @@ module DebugAgent
|
|
|
29
29
|
}
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
register_tool('trigger_gc', 'Trigger GC and show before/after comparison') do
|
|
32
|
+
register_tool('trigger_gc', 'Trigger GC and show before/after comparison', mutating: true) do
|
|
33
33
|
before = ObjectSpace.count_objects.values.sum
|
|
34
34
|
GC.start
|
|
35
35
|
after = ObjectSpace.count_objects.values.sum
|
|
@@ -49,6 +49,12 @@ module DebugAgent
|
|
|
49
49
|
|
|
50
50
|
@metric_snapshot_counter += 1
|
|
51
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
|
|
52
58
|
@metric_snapshots[snapshot_id] = metrics
|
|
53
59
|
|
|
54
60
|
{
|
|
@@ -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}"
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
require 'json'
|
|
2
|
+
require 'digest'
|
|
3
|
+
require 'uri'
|
|
2
4
|
require_relative 'chat_page'
|
|
3
5
|
|
|
4
6
|
module DebugAgent
|
|
5
|
-
# SSE callback that
|
|
7
|
+
# SSE callback that collects events for both buffered and streaming modes.
|
|
8
|
+
# In streaming mode, events are yielded in real-time via an Enumerator.
|
|
6
9
|
class SseCallback < ChatCallback
|
|
7
10
|
def initialize
|
|
8
11
|
@events = []
|
|
12
|
+
@queue = Queue.new
|
|
13
|
+
@done = false
|
|
9
14
|
end
|
|
10
15
|
|
|
11
16
|
def events
|
|
@@ -14,27 +19,47 @@ module DebugAgent
|
|
|
14
19
|
|
|
15
20
|
def on_content(chunk)
|
|
16
21
|
@events << ['content', JSON.generate(chunk)]
|
|
22
|
+
@queue << ['content', JSON.generate(chunk)]
|
|
17
23
|
end
|
|
18
24
|
|
|
19
25
|
def on_tool_start(tool_name, args)
|
|
20
26
|
@events << ['tool_start', tool_name]
|
|
27
|
+
@queue << ['tool_start', tool_name]
|
|
21
28
|
end
|
|
22
29
|
|
|
23
30
|
def on_tool_result(tool_name, result)
|
|
24
31
|
@events << ['tool_result', "#{tool_name}: #{result}"]
|
|
32
|
+
@queue << ['tool_result', "#{tool_name}: #{result}"]
|
|
25
33
|
end
|
|
26
34
|
|
|
27
35
|
def on_complete
|
|
28
36
|
@events << ['done', '']
|
|
37
|
+
@queue << ['done', '']
|
|
38
|
+
@done = true
|
|
39
|
+
@queue.close
|
|
29
40
|
end
|
|
30
41
|
|
|
31
42
|
def on_error(message)
|
|
32
43
|
@events << ['error', message]
|
|
44
|
+
@queue << ['error', message]
|
|
45
|
+
@done = true
|
|
46
|
+
@queue.close
|
|
33
47
|
end
|
|
34
48
|
|
|
35
49
|
def on_context_compressed(original, compressed, removed_rounds)
|
|
36
50
|
info = JSON.generate({ originalTokens: original, compressedTokens: compressed, removedRounds: removed_rounds })
|
|
37
51
|
@events << ['context_compressed', info]
|
|
52
|
+
@queue << ['context_compressed', info]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Real-time streaming Enumerator: yields SSE-formatted lines as events arrive.
|
|
56
|
+
def streaming_enum
|
|
57
|
+
Enumerator.new do |yielder|
|
|
58
|
+
while (item = @queue.pop)
|
|
59
|
+
event_type, data = item
|
|
60
|
+
yielder << "event: #{event_type}\ndata: #{data}\n\n"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
38
63
|
end
|
|
39
64
|
end
|
|
40
65
|
|
|
@@ -43,12 +68,22 @@ module DebugAgent
|
|
|
43
68
|
def initialize(app, config = nil)
|
|
44
69
|
@app = app
|
|
45
70
|
@config = config || Config.from_env
|
|
46
|
-
|
|
71
|
+
if @config.enabled
|
|
72
|
+
@engine = DebugEngine.new(@config)
|
|
73
|
+
@limiter = RateLimiter.new(@config.rate_limit_per_minute)
|
|
74
|
+
else
|
|
75
|
+
# Hardening: DEBUG_AGENT_ENABLED=false is enforced at mount time. Nothing
|
|
76
|
+
# is built and the wrapped app is served as if the agent were not mounted.
|
|
77
|
+
@engine = nil
|
|
78
|
+
@limiter = nil
|
|
79
|
+
end
|
|
47
80
|
DebugAgent.app = app
|
|
48
81
|
end
|
|
49
82
|
|
|
50
83
|
def call(env)
|
|
51
|
-
MiddlewareCore.
|
|
84
|
+
return MiddlewareCore.pass_through(env, @app) unless @engine
|
|
85
|
+
|
|
86
|
+
MiddlewareCore.call(env, @app, @engine, @config, @limiter)
|
|
52
87
|
end
|
|
53
88
|
end
|
|
54
89
|
|
|
@@ -56,72 +91,317 @@ module DebugAgent
|
|
|
56
91
|
# Create a lambda-based middleware (for non-Sinatra Rack apps)
|
|
57
92
|
def self.new(app = nil, config = nil)
|
|
58
93
|
config_obj = config || Config.from_env
|
|
94
|
+
unless config_obj.enabled
|
|
95
|
+
# Disabled at mount time: pass through to the app as if not mounted.
|
|
96
|
+
return lambda { |env| MiddlewareCore.pass_through(env, app) }
|
|
97
|
+
end
|
|
98
|
+
|
|
59
99
|
engine = DebugEngine.new(config_obj)
|
|
100
|
+
limiter = RateLimiter.new(config_obj.rate_limit_per_minute)
|
|
60
101
|
DebugAgent.app = app
|
|
61
102
|
|
|
62
103
|
lambda do |env|
|
|
63
|
-
MiddlewareCore.call(env, app, engine, config_obj)
|
|
104
|
+
MiddlewareCore.call(env, app, engine, config_obj, limiter)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Sinatra helper: `register DebugAgent::Middleware` mounts the Rack middleware
|
|
109
|
+
# (equivalent to `use DebugAgent::RackMiddleware`). A disabled agent is never mounted.
|
|
110
|
+
def self.registered(app)
|
|
111
|
+
return unless Config.from_env.enabled
|
|
112
|
+
|
|
113
|
+
app.use DebugAgent::RackMiddleware
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Fixed-window per-IP rate limiter (requests per minute) for POST /api/chat.
|
|
118
|
+
class RateLimiter
|
|
119
|
+
WINDOW_SECONDS = 60
|
|
120
|
+
MAX_TRACKED_IPS = 10_000
|
|
121
|
+
|
|
122
|
+
def initialize(limit)
|
|
123
|
+
@limit = limit.nil? ? 0 : limit
|
|
124
|
+
@mutex = Mutex.new
|
|
125
|
+
@hits = {}
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def allow?(ip)
|
|
129
|
+
return true if @limit <= 0
|
|
130
|
+
|
|
131
|
+
now = Time.now
|
|
132
|
+
@mutex.synchronize do
|
|
133
|
+
# Bound memory: reset the table if an attacker sprays source addresses.
|
|
134
|
+
@hits = {} if @hits.length > MAX_TRACKED_IPS
|
|
135
|
+
window = @hits[ip]
|
|
136
|
+
if window.nil? || now - window[0] >= WINDOW_SECONDS
|
|
137
|
+
@hits[ip] = [now, 1]
|
|
138
|
+
true
|
|
139
|
+
else
|
|
140
|
+
window[1] += 1
|
|
141
|
+
window[1] <= @limit
|
|
142
|
+
end
|
|
64
143
|
end
|
|
65
144
|
end
|
|
66
145
|
end
|
|
67
146
|
|
|
68
147
|
# Shared routing logic used by both RackMiddleware class and Middleware lambda
|
|
69
148
|
module MiddlewareCore
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
149
|
+
CORS_METHODS = 'GET, POST, OPTIONS'
|
|
150
|
+
CORS_ALLOW_HEADERS = 'Content-Type, Authorization, X-API-Key'
|
|
151
|
+
|
|
152
|
+
BodyResult = Struct.new(:status, :error, :body, keyword_init: true) do
|
|
153
|
+
def ok?
|
|
154
|
+
status.nil?
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# Hardening, all controlled through Config (see config.rb):
|
|
159
|
+
# - enabled=false → the agent is not mounted (pass-through / 404).
|
|
160
|
+
# - api_key set → UI and /api/* require the key (Bearer / X-API-Key /
|
|
161
|
+
# ?api_key=); otherwise 401. With a key set, CORS is same-origin only
|
|
162
|
+
# unless cors_origin is configured explicitly.
|
|
163
|
+
# - max_body_bytes → oversized POST bodies answer 413, malformed JSON 400.
|
|
164
|
+
# - rate_limit_per_minute → POST /api/chat is limited per client IP (429).
|
|
165
|
+
def self.call(env, app, engine, config, limiter = nil)
|
|
166
|
+
base = config.base_path.to_s.sub(%r{/+\z}, '')
|
|
167
|
+
path = env['PATH_INFO'].to_s
|
|
168
|
+
method = env['REQUEST_METHOD'].to_s.upcase
|
|
169
|
+
return pass_through(env, app) unless agent_path?(path, base)
|
|
170
|
+
|
|
171
|
+
headers = cors_headers(config)
|
|
172
|
+
|
|
173
|
+
# CORS preflight for all agent routes. Never requires auth: browsers send
|
|
174
|
+
# no custom headers here. (204 carries no body and no Content-Length.)
|
|
175
|
+
return [204, headers, []] if method == 'OPTIONS'
|
|
176
|
+
|
|
177
|
+
unless authorized?(env, config.api_key)
|
|
178
|
+
return json_response(401, { 'error' => 'unauthorized' }, headers)
|
|
179
|
+
end
|
|
74
180
|
|
|
75
181
|
# Chat UI
|
|
76
182
|
if path == base || path == "#{base}/"
|
|
77
183
|
if method == 'GET'
|
|
78
184
|
html = ChatPage.render(base)
|
|
79
|
-
return [200, { '
|
|
185
|
+
return [200, { 'content-type' => 'text/html; charset=utf-8' }.merge(headers), [html]]
|
|
80
186
|
end
|
|
81
187
|
end
|
|
82
188
|
|
|
83
|
-
# SSE streaming chat
|
|
84
|
-
if path == "#{base}/api/chat"
|
|
85
|
-
|
|
189
|
+
# SSE streaming chat — real-time streaming via Rack response body
|
|
190
|
+
if path == "#{base}/api/chat"
|
|
191
|
+
return json_response(405, { 'error' => 'method not allowed' }, headers) unless method == 'POST'
|
|
192
|
+
|
|
193
|
+
(limiter ||= RateLimiter.new(config.rate_limit_per_minute))
|
|
194
|
+
unless limiter.allow?(client_ip(env))
|
|
195
|
+
return json_response(429, { 'error' => 'rate limit exceeded, retry later' }, headers)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
parsed = read_json_body(env, config.max_body_bytes)
|
|
199
|
+
return json_response(parsed.status, { 'error' => parsed.error }, headers) unless parsed.ok?
|
|
200
|
+
|
|
201
|
+
body = parsed.body
|
|
86
202
|
message = body['message'] || ''
|
|
87
203
|
session_id = body['sessionId'] || "session-#{Time.now.to_i}"
|
|
88
204
|
|
|
89
205
|
cb = SseCallback.new
|
|
90
|
-
engine.chat(message, session_id, cb)
|
|
91
206
|
|
|
92
|
-
|
|
207
|
+
# Run engine in a background thread for real-time streaming
|
|
208
|
+
Thread.new do
|
|
209
|
+
begin
|
|
210
|
+
engine.chat(message, session_id, cb)
|
|
211
|
+
rescue => e
|
|
212
|
+
cb.on_error("Internal error: #{e.message}")
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
# Return a streaming response body (Rack 2+ / Rack 3 compatible)
|
|
217
|
+
streaming_body = cb.streaming_enum
|
|
93
218
|
|
|
94
219
|
return [200, {
|
|
95
|
-
'
|
|
96
|
-
'
|
|
97
|
-
'
|
|
98
|
-
},
|
|
220
|
+
'content-type' => 'text/event-stream',
|
|
221
|
+
'cache-control' => 'no-cache',
|
|
222
|
+
'connection' => 'keep-alive',
|
|
223
|
+
}.merge(headers), streaming_body]
|
|
99
224
|
end
|
|
100
225
|
|
|
101
226
|
# Clear conversation
|
|
102
|
-
if path == "#{base}/api/clear"
|
|
103
|
-
|
|
104
|
-
|
|
227
|
+
if path == "#{base}/api/clear"
|
|
228
|
+
return json_response(405, { 'error' => 'method not allowed' }, headers) unless method == 'POST'
|
|
229
|
+
|
|
230
|
+
parsed = read_json_body(env, config.max_body_bytes)
|
|
231
|
+
return json_response(parsed.status, { 'error' => parsed.error }, headers) unless parsed.ok?
|
|
232
|
+
|
|
233
|
+
session_id = parsed.body['sessionId'] || ''
|
|
105
234
|
engine.clear_session(session_id) if session_id && !session_id.empty?
|
|
106
|
-
return [200, { '
|
|
235
|
+
return [200, { 'content-type' => 'application/json' }.merge(headers), [JSON.generate({ status: 'cleared' })]]
|
|
107
236
|
end
|
|
108
237
|
|
|
109
238
|
# Health check
|
|
110
239
|
if path == "#{base}/api/health" && method == 'GET'
|
|
111
|
-
return [200, { '
|
|
240
|
+
return [200, { 'content-type' => 'application/json' }.merge(headers), [JSON.generate({ status: 'ok', agent: 'ruby-debug-agent' })]]
|
|
112
241
|
end
|
|
113
242
|
|
|
114
243
|
# List tools
|
|
115
244
|
if path == "#{base}/api/tools" && method == 'GET'
|
|
116
|
-
return [200, { '
|
|
245
|
+
return [200, { 'content-type' => 'application/json' }.merge(headers), [JSON.generate({ tools: engine.tools.all_schemas })]]
|
|
117
246
|
end
|
|
118
247
|
|
|
119
|
-
|
|
248
|
+
pass_through(env, app)
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
# Hand the request to the wrapped app as if the agent were not mounted.
|
|
252
|
+
def self.pass_through(env, app)
|
|
120
253
|
if app
|
|
121
254
|
app.call(env)
|
|
122
255
|
else
|
|
123
|
-
[404, { '
|
|
256
|
+
[404, { 'content-type' => 'text/plain' }, ['Not Found']]
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
# Only the mount path itself and everything beneath it belong to the agent.
|
|
261
|
+
def self.agent_path?(path, base)
|
|
262
|
+
return true if base.empty?
|
|
263
|
+
|
|
264
|
+
path == base || path.start_with?("#{base}/")
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
# authorized? reports whether the request carries the configured API key.
|
|
268
|
+
# An empty configured key disables auth entirely.
|
|
269
|
+
def self.authorized?(env, api_key)
|
|
270
|
+
return true if api_key.nil? || api_key.empty?
|
|
271
|
+
|
|
272
|
+
presented = env['HTTP_X_API_KEY'].to_s
|
|
273
|
+
if presented.empty?
|
|
274
|
+
auth = env['HTTP_AUTHORIZATION'].to_s
|
|
275
|
+
presented = auth.delete_prefix('Bearer ').strip if auth.start_with?('Bearer ')
|
|
276
|
+
end
|
|
277
|
+
presented = query_param(env, 'api_key').to_s if presented.empty?
|
|
278
|
+
return false if presented.empty?
|
|
279
|
+
|
|
280
|
+
secure_compare(presented, api_key)
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# Constant-time comparison. Both sides are hashed first so the compare runs
|
|
284
|
+
# over a fixed 32-byte length - a different-length key never bails out early.
|
|
285
|
+
# Uses Rack::Utils.secure_compare when rack is loadable, else a manual
|
|
286
|
+
# constant-time byte loop.
|
|
287
|
+
def self.secure_compare(presented, expected)
|
|
288
|
+
left = Digest::SHA256.digest(presented.to_s)
|
|
289
|
+
right = Digest::SHA256.digest(expected.to_s)
|
|
290
|
+
rack_compare = rack_secure_compare
|
|
291
|
+
return rack_compare.call(left, right) if rack_compare
|
|
292
|
+
|
|
293
|
+
constant_time_equal?(left, right)
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
# => Rack::Utils.secure_compare (when rack is loadable), else nil.
|
|
297
|
+
# Resolved lazily, once per thread; `false` caches "not available".
|
|
298
|
+
def self.rack_secure_compare
|
|
299
|
+
cached = Thread.current[:debug_agent_rack_compare]
|
|
300
|
+
return nil if cached == false
|
|
301
|
+
return cached unless cached.nil?
|
|
302
|
+
|
|
303
|
+
begin
|
|
304
|
+
require 'rack'
|
|
305
|
+
rack_compare = Rack::Utils.respond_to?(:secure_compare) ? Rack::Utils.method(:secure_compare) : false
|
|
306
|
+
rescue LoadError, StandardError
|
|
307
|
+
rack_compare = false
|
|
308
|
+
end
|
|
309
|
+
Thread.current[:debug_agent_rack_compare] = rack_compare
|
|
310
|
+
rack_compare == false ? nil : rack_compare
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
def self.constant_time_equal?(left, right)
|
|
314
|
+
a = left.to_s.unpack('C*')
|
|
315
|
+
b = right.to_s.unpack('C*')
|
|
316
|
+
result = a.length ^ b.length
|
|
317
|
+
[a.length, b.length].max.times { |i| result |= (a[i] || 0) ^ (b[i] || 0) }
|
|
318
|
+
result.zero?
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
# cors_headers applies the configured CORS policy. With auth enabled and the
|
|
322
|
+
# default wildcard origin, no CORS headers are emitted (same-origin only),
|
|
323
|
+
# because a wildcard origin must never be combined with a bearer-protected endpoint.
|
|
324
|
+
def self.cors_headers(config)
|
|
325
|
+
origin = config.cors_origin.to_s
|
|
326
|
+
origin = '*' if origin.empty?
|
|
327
|
+
return {} if origin == '*' && !config.api_key.to_s.empty?
|
|
328
|
+
|
|
329
|
+
headers = {
|
|
330
|
+
'access-control-allow-origin' => origin,
|
|
331
|
+
'access-control-allow-methods' => CORS_METHODS,
|
|
332
|
+
'access-control-allow-headers' => CORS_ALLOW_HEADERS,
|
|
333
|
+
}
|
|
334
|
+
headers['vary'] = 'Origin' if origin != '*'
|
|
335
|
+
headers
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
# read_json_body reads a JSON object with the configured size limit.
|
|
339
|
+
# Returns a BodyResult carrying either the parsed body or the 413/400 to write.
|
|
340
|
+
def self.read_json_body(env, max_bytes)
|
|
341
|
+
raw, error = read_limited_body(env, max_bytes)
|
|
342
|
+
return BodyResult.new(status: 413, error: error) if raw.nil?
|
|
343
|
+
|
|
344
|
+
begin
|
|
345
|
+
body = JSON.parse(raw)
|
|
346
|
+
rescue JSON::ParserError, TypeError
|
|
347
|
+
return BodyResult.new(status: 400, error: 'invalid JSON body')
|
|
348
|
+
end
|
|
349
|
+
return BodyResult.new(status: 400, error: 'invalid JSON body') unless body.is_a?(Hash)
|
|
350
|
+
|
|
351
|
+
BodyResult.new(body: body)
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
def self.read_limited_body(env, max_bytes)
|
|
355
|
+
limited = !max_bytes.nil? && max_bytes.positive?
|
|
356
|
+
if limited
|
|
357
|
+
declared = env['CONTENT_LENGTH'].to_s
|
|
358
|
+
return [nil, 'request body too large'] if declared.match?(/\A\d+\z/) && declared.to_i > max_bytes
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
input = env['rack.input']
|
|
362
|
+
raw = if input.respond_to?(:read)
|
|
363
|
+
limited ? input.read(max_bytes + 1) : input.read
|
|
364
|
+
else
|
|
365
|
+
''
|
|
124
366
|
end
|
|
367
|
+
raw = raw.to_s
|
|
368
|
+
return [nil, 'request body too large'] if limited && raw.bytesize > max_bytes
|
|
369
|
+
|
|
370
|
+
[raw, nil]
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
def self.query_param(env, name)
|
|
374
|
+
env['QUERY_STRING'].to_s.split('&').each do |pair|
|
|
375
|
+
key, value = pair.split('=', 2)
|
|
376
|
+
next if decode_component(key) != name
|
|
377
|
+
|
|
378
|
+
return decode_component(value.to_s)
|
|
379
|
+
end
|
|
380
|
+
nil
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
def self.decode_component(value)
|
|
384
|
+
URI.decode_www_form_component(value.to_s)
|
|
385
|
+
rescue ArgumentError
|
|
386
|
+
value.to_s
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
def self.client_ip(env)
|
|
390
|
+
forwarded = env['HTTP_X_FORWARDED_FOR'].to_s
|
|
391
|
+
return forwarded.split(',').first.strip unless forwarded.empty?
|
|
392
|
+
|
|
393
|
+
addr = env['REMOTE_ADDR'].to_s
|
|
394
|
+
if addr.start_with?('[')
|
|
395
|
+
addr[1, addr.index(']') - 1] || addr
|
|
396
|
+
elsif addr.count(':') == 1
|
|
397
|
+
addr.split(':').first
|
|
398
|
+
else
|
|
399
|
+
addr
|
|
400
|
+
end
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
def self.json_response(status, payload, extra_headers = {})
|
|
404
|
+
[status, { 'content-type' => 'application/json' }.merge(extra_headers), [JSON.generate(payload)]]
|
|
125
405
|
end
|
|
126
406
|
end
|
|
127
407
|
end
|
|
@@ -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
|
-
'
|
|
19
|
+
'runtime' => 'Runtime Info',
|
|
14
20
|
'system' => 'System Info',
|
|
15
21
|
'disk' => 'System Info',
|
|
16
|
-
'environment' => '
|
|
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
|
-
'
|
|
34
|
+
'rails' => 'Framework & Routes',
|
|
35
|
+
'sinatra' => 'Framework & Routes',
|
|
36
|
+
# HTTP
|
|
20
37
|
'recent' => 'HTTP Requests',
|
|
21
38
|
'slow' => 'HTTP Requests',
|
|
22
|
-
'error' => '
|
|
39
|
+
'error' => 'Error Tracking',
|
|
23
40
|
'request' => 'HTTP Requests',
|
|
24
|
-
'
|
|
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
|
|
@@ -7,7 +7,12 @@ module DebugAgent
|
|
|
7
7
|
end
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
ToolDefinition
|
|
10
|
+
# ToolDefinition.mutating marks tools that change runtime state, affect
|
|
11
|
+
# business data, or call the host app with a non-safe HTTP method (see
|
|
12
|
+
# DebugAgent.safe_http_method?). Mutating tools are hidden from the LLM and
|
|
13
|
+
# from /api/tools and refused by ToolRegistry#execute unless
|
|
14
|
+
# DEBUG_AGENT_ALLOW_MUTATING_TOOLS=true.
|
|
15
|
+
ToolDefinition = Struct.new(:name, :description, :func, :params, :mutating, keyword_init: true)
|
|
11
16
|
|
|
12
17
|
class ToolRegistry
|
|
13
18
|
def initialize
|
|
@@ -22,14 +27,22 @@ module DebugAgent
|
|
|
22
27
|
@tools[name]
|
|
23
28
|
end
|
|
24
29
|
|
|
30
|
+
# Schemas for every tool the LLM may call. Mutating tools are omitted
|
|
31
|
+
# while they are disabled.
|
|
25
32
|
def all_schemas
|
|
26
|
-
|
|
33
|
+
visible_tools.map(&:to_schema)
|
|
27
34
|
end
|
|
28
35
|
|
|
36
|
+
# Runs a registered tool by name. Mutating tools are refused while they
|
|
37
|
+
# are disabled; tool errors are returned as a structured {error: ...} hash.
|
|
29
38
|
def execute(name, args)
|
|
30
39
|
tool = @tools[name]
|
|
31
40
|
return { error: "Unknown tool: #{name}" } unless tool
|
|
32
41
|
|
|
42
|
+
if tool.mutating && !DebugAgent.mutating_tools_allowed?
|
|
43
|
+
return { error: "#{name} is #{MUTATING_DISABLED}" }
|
|
44
|
+
end
|
|
45
|
+
|
|
33
46
|
begin
|
|
34
47
|
result = tool.func.call(**args)
|
|
35
48
|
result
|
|
@@ -38,8 +51,21 @@ module DebugAgent
|
|
|
38
51
|
end
|
|
39
52
|
end
|
|
40
53
|
|
|
54
|
+
# Names of the tools the LLM may call (mutating tools omitted while off).
|
|
41
55
|
def names
|
|
42
|
-
|
|
56
|
+
visible_tools.map(&:name)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def mutating?(name)
|
|
60
|
+
tool = @tools[name]
|
|
61
|
+
tool ? tool.mutating == true : false
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def visible_tools
|
|
67
|
+
allowed = DebugAgent.mutating_tools_allowed?
|
|
68
|
+
@tools.values.reject { |tool| tool.mutating && !allowed }
|
|
43
69
|
end
|
|
44
70
|
end
|
|
45
71
|
|
|
@@ -74,22 +100,61 @@ module DebugAgent
|
|
|
74
100
|
# Patch Struct to include schema method
|
|
75
101
|
ToolDefinition.prepend(ToolDefinitionExt)
|
|
76
102
|
|
|
103
|
+
# Refusal message for a mutating tool while mutating tools are off.
|
|
104
|
+
MUTATING_DISABLED = 'disabled: this tool changes state and mutating tools are off ' \
|
|
105
|
+
'(set DEBUG_AGENT_ALLOW_MUTATING_TOOLS=true)'.freeze
|
|
106
|
+
|
|
77
107
|
# Global registry singleton
|
|
78
108
|
REGISTRY = ToolRegistry.new
|
|
79
109
|
|
|
110
|
+
SAFE_HTTP_METHODS = ['', 'GET', 'HEAD', 'OPTIONS'].freeze
|
|
111
|
+
|
|
80
112
|
module ClassMethods
|
|
81
113
|
def registry
|
|
82
114
|
REGISTRY
|
|
83
115
|
end
|
|
84
116
|
|
|
85
|
-
|
|
86
|
-
|
|
117
|
+
# Registers a read-only tool. Pass mutating: true for a tool with side
|
|
118
|
+
# effects (or use mutating_tool): it is then hidden and refused until
|
|
119
|
+
# set_allow_mutating_tools(true) / DEBUG_AGENT_ALLOW_MUTATING_TOOLS=true.
|
|
120
|
+
#
|
|
121
|
+
# DebugAgent.register_tool('purge_tmp', 'Remove tmp files', mutating: true) { ... }
|
|
122
|
+
def register_tool(name, description, params = nil, mutating: false, **extra_params, &block)
|
|
123
|
+
REGISTRY.register(build_tool(name, description, params, extra_params, mutating, block))
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Registers a tool with side effects (GC, log level, cache clears,
|
|
127
|
+
# non-safe HTTP to the host app) - see ToolDefinition.mutating.
|
|
128
|
+
def mutating_tool(name, description, params = nil, **extra_params, &block)
|
|
129
|
+
REGISTRY.register(build_tool(name, description, params, extra_params, true, block))
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# Enables or disables mutating tools for the global registry.
|
|
133
|
+
def set_allow_mutating_tools(allowed)
|
|
134
|
+
@allow_mutating_tools = allowed ? true : false
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Whether mutating tools are currently enabled (default: false).
|
|
138
|
+
def mutating_tools_allowed?
|
|
139
|
+
@allow_mutating_tools == true
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Whether an HTTP method is read-only (GET/HEAD/OPTIONS; empty = GET).
|
|
143
|
+
def safe_http_method?(method)
|
|
144
|
+
SAFE_HTTP_METHODS.include?(method.to_s.strip.upcase)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
private
|
|
148
|
+
|
|
149
|
+
def build_tool(name, description, params, extra_params, mutating, block)
|
|
150
|
+
params = (params || {}).merge(extra_params || {})
|
|
151
|
+
ToolDefinition.new(
|
|
87
152
|
name: name,
|
|
88
153
|
description: description,
|
|
89
154
|
func: block,
|
|
90
|
-
params: params
|
|
155
|
+
params: params,
|
|
156
|
+
mutating: mutating ? true : false
|
|
91
157
|
)
|
|
92
|
-
REGISTRY.register(tool)
|
|
93
158
|
end
|
|
94
159
|
end
|
|
95
160
|
|
data/lib/debug_agent/version.rb
CHANGED
data/lib/debug_agent.rb
CHANGED
|
@@ -50,15 +50,6 @@ require_relative 'debug_agent/inspectors/service_registry'
|
|
|
50
50
|
module DebugAgent
|
|
51
51
|
class Error < StandardError; end
|
|
52
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
|
-
|
|
62
53
|
# Process start time for uptime tracking
|
|
63
54
|
PROCESS_START_TIME = Time.now
|
|
64
55
|
|
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.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ggcode
|
|
@@ -226,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
226
226
|
- !ruby/object:Gem::Version
|
|
227
227
|
version: '0'
|
|
228
228
|
requirements: []
|
|
229
|
-
rubygems_version: 4.0.
|
|
229
|
+
rubygems_version: 4.0.20
|
|
230
230
|
specification_version: 4
|
|
231
231
|
summary: AI-powered runtime debugging agent for Ruby applications
|
|
232
232
|
test_files: []
|