debug-agent-py 0.5.1__tar.gz → 0.7.0__tar.gz
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.
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/PKG-INFO +87 -6
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/README.md +86 -5
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/pyproject.toml +1 -1
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/__init__.py +11 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/__init__.py +11 -0
- debug_agent_py-0.7.0/src/debug_agent/inspectors/build_info_inspector.py +193 -0
- debug_agent_py-0.7.0/src/debug_agent/inspectors/config_inspector.py +157 -0
- debug_agent_py-0.7.0/src/debug_agent/inspectors/cpu_profile_inspector.py +160 -0
- debug_agent_py-0.7.0/src/debug_agent/inspectors/endpoint_test_inspector.py +374 -0
- debug_agent_py-0.7.0/src/debug_agent/inspectors/feature_flag_inspector.py +124 -0
- debug_agent_py-0.7.0/src/debug_agent/inspectors/leak_detector_inspector.py +175 -0
- debug_agent_py-0.7.0/src/debug_agent/inspectors/locks_inspector.py +307 -0
- debug_agent_py-0.7.0/src/debug_agent/inspectors/migration_inspector.py +312 -0
- debug_agent_py-0.7.0/src/debug_agent/inspectors/pool_inspector.py +309 -0
- debug_agent_py-0.7.0/src/debug_agent/inspectors/service_registry_inspector.py +176 -0
- debug_agent_py-0.7.0/src/debug_agent/inspectors/snapshot_inspector.py +297 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent_py.egg-info/PKG-INFO +87 -6
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent_py.egg-info/SOURCES.txt +11 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/setup.cfg +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/chat_session.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/config.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/context_compressor.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/engine.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/async_tasks.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/cache_inspector.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/celery.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/database.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/django.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/error_tracking.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/fastapi_ext.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/fd_inspector.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/flask_ext.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/framework.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/health_inspector.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/http_client_inspector.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/http_tracker.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/jinja2.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/logging_inspector.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/memory.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/metrics_inspector.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/modules.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/redis.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/runtime.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/scheduler_inspector.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/security_inspector.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/signals.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/system.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/threads.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/warnings_inspector.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/inspectors/websocket_inspector.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/llm_client.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/middleware.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/system_prompt_builder.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/tool_registry.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/web/__init__.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent/web/chat_page.py +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent_py.egg-info/dependency_links.txt +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent_py.egg-info/requires.txt +0 -0
- {debug_agent_py-0.5.1 → debug_agent_py-0.7.0}/src/debug_agent_py.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: debug-agent-py
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: AI-powered runtime debugging agent for Python web applications
|
|
5
5
|
Author-email: ggcode <noreply@ggcode.dev>
|
|
6
6
|
License: MIT
|
|
@@ -52,12 +52,12 @@ Requires-Dist: pytest; extra == "dev"
|
|
|
52
52
|
# Python Debug Agent
|
|
53
53
|
|
|
54
54
|
[](https://pypi.org/project/debug-agent-py/)
|
|
55
|
-

|
|
56
|
+

|
|
57
57
|

|
|
58
58
|

|
|
59
59
|
|
|
60
|
-
An AI-powered runtime debugging agent that embeds directly into your Python web application. Add one dependency, configure an LLM key, and chat with your live app at `/agent` to inspect memory, threads, GC, modules, database connections, Redis, Django models/URLs, Celery tasks, Flask extensions, Jinja2 templates, signals, routes, HTTP requests, and more — **
|
|
60
|
+
An AI-powered runtime debugging agent that embeds directly into your Python web application. Add one dependency, configure an LLM key, and chat with your live app at `/agent` to inspect memory, threads, GC, modules, database connections, Redis, Django models/URLs, Celery tasks, Flask extensions, Jinja2 templates, signals, routes, HTTP requests, and more — **113 diagnostic tools across 38 inspectors**.
|
|
61
61
|
|
|
62
62
|
## Version Support
|
|
63
63
|
|
|
@@ -115,11 +115,11 @@ http://localhost:8000/agent
|
|
|
115
115
|
- **Context compression** — automatically summarizes old conversation when token limit is approached
|
|
116
116
|
- **Dark-themed chat UI** with full markdown rendering (tables, code blocks, lists)
|
|
117
117
|
- **Max tool rounds** (25) with forced final summary when limit is reached
|
|
118
|
-
- **
|
|
118
|
+
- **113 diagnostic tools** across **38 inspectors**
|
|
119
119
|
- Works with Flask, FastAPI, and Django
|
|
120
120
|
- Zero external dependencies (no Datadog, no Grafana, no APM)
|
|
121
121
|
|
|
122
|
-
## Inspectors & Tools (
|
|
122
|
+
## Inspectors & Tools (113)
|
|
123
123
|
|
|
124
124
|
### Memory Inspector
|
|
125
125
|
| Tool | Description |
|
|
@@ -280,6 +280,81 @@ http://localhost:8000/agent
|
|
|
280
280
|
|------|-------------|
|
|
281
281
|
| `get_warnings` | List captured Python warnings with category, message, and location |
|
|
282
282
|
|
|
283
|
+
### Deadlock & Lock Contention Inspector (v0.6.0)
|
|
284
|
+
| Tool | Description |
|
|
285
|
+
|------|-------------|
|
|
286
|
+
| `get_lock_contention` | Threading lock contention stats (wait time, hold time, acquisition count) |
|
|
287
|
+
| `detect_deadlock` | Analyze all threads for deadlock patterns (circular wait detection) |
|
|
288
|
+
| `get_mutex_stats` | Per-lock statistics: total acquisitions, contentions, average wait time |
|
|
289
|
+
|
|
290
|
+
### Database Migration Inspector (v0.6.0)
|
|
291
|
+
| Tool | Description |
|
|
292
|
+
|------|-------------|
|
|
293
|
+
| `get_migration_status` | Current schema version, applied count, last migration applied |
|
|
294
|
+
| `get_pending_migrations` | Migrations not yet applied (version, description, dependencies) |
|
|
295
|
+
| `get_migration_history` | Applied migration history (version, applied_at, duration_ms) |
|
|
296
|
+
|
|
297
|
+
### Configuration Inspector (v0.6.0)
|
|
298
|
+
| Tool | Description |
|
|
299
|
+
|------|-------------|
|
|
300
|
+
| `get_config_snapshot` | All registered config values (sensitive keys masked) |
|
|
301
|
+
| `get_env_vars_masked` | Process environment variables with secret values redacted |
|
|
302
|
+
| `get_config_sources` | Config source hierarchy (env, file, defaults) with effective values |
|
|
303
|
+
|
|
304
|
+
### Feature Flags Inspector (v0.6.0)
|
|
305
|
+
| Tool | Description |
|
|
306
|
+
|------|-------------|
|
|
307
|
+
| `get_feature_flags` | List all registered feature flags with current state |
|
|
308
|
+
| `evaluate_feature_flag` | Evaluate a specific flag for a given context/user |
|
|
309
|
+
|
|
310
|
+
### Endpoint Testing Inspector (v0.6.0)
|
|
311
|
+
| Tool | Description |
|
|
312
|
+
|------|-------------|
|
|
313
|
+
| `test_endpoint` | Make an HTTP request to own app, return full response (status, headers, body) |
|
|
314
|
+
| `batch_test_endpoints` | Test multiple endpoints in one call with aggregated results |
|
|
315
|
+
| `get_endpoint_coverage` | Compare registered routes vs tested endpoints (coverage report) |
|
|
316
|
+
|
|
317
|
+
### Connection Pool Inspector (v0.6.0)
|
|
318
|
+
| Tool | Description |
|
|
319
|
+
|------|-------------|
|
|
320
|
+
| `get_pool_details` | Detailed DB pool stats (pool size, checked-in, checked-out, overflow) |
|
|
321
|
+
| `detect_pool_leaks` | Heuristic leak detection (growing pool, high wait ratio, saturation) |
|
|
322
|
+
| `get_pool_wait_stats` | Connection acquire wait stats (avg, P95, max wait, timeout count) |
|
|
323
|
+
|
|
324
|
+
### CPU Profiler Inspector (v0.7.0)
|
|
325
|
+
| Tool | Description |
|
|
326
|
+
|------|-------------|
|
|
327
|
+
| `start_cpu_profile` | Start a CPU profiling session (cProfile/yappi) |
|
|
328
|
+
| `stop_cpu_profile` | Stop CPU profiling and return collected profile data |
|
|
329
|
+
| `get_top_functions` | Get top CPU-consuming functions from the current profile |
|
|
330
|
+
|
|
331
|
+
### Memory Leak Detector Inspector (v0.7.0)
|
|
332
|
+
| Tool | Description |
|
|
333
|
+
|------|-------------|
|
|
334
|
+
| `take_heap_snapshot` | Capture a heap snapshot for leak analysis (tracemalloc) |
|
|
335
|
+
| `compare_heap_snapshots` | Compare two heap snapshots to identify object growth |
|
|
336
|
+
| `get_leak_candidates` | Identify objects likely to be memory leaks |
|
|
337
|
+
|
|
338
|
+
### Deployment/Build Info Inspector (v0.7.0)
|
|
339
|
+
| Tool | Description |
|
|
340
|
+
|------|-------------|
|
|
341
|
+
| `get_build_info` | Build version, commit hash, and package metadata |
|
|
342
|
+
| `get_deployment_info` | Deployment environment, container, and orchestration metadata |
|
|
343
|
+
| `get_runtime_version` | Python interpreter version and implementation details |
|
|
344
|
+
|
|
345
|
+
### Snapshot & Diff Inspector (v0.7.0)
|
|
346
|
+
| Tool | Description |
|
|
347
|
+
|------|-------------|
|
|
348
|
+
| `take_snapshot` | Capture a runtime state snapshot |
|
|
349
|
+
| `compare_snapshots` | Compare two snapshots to identify state changes |
|
|
350
|
+
| `list_snapshots` | List all saved snapshots with timestamps |
|
|
351
|
+
|
|
352
|
+
### Service Registry Inspector (v0.7.0)
|
|
353
|
+
| Tool | Description |
|
|
354
|
+
|------|-------------|
|
|
355
|
+
| `get_registered_services` | List all registered application services |
|
|
356
|
+
| `get_service_dependencies` | Map service-to-service dependency graph |
|
|
357
|
+
|
|
283
358
|
## Custom Tools
|
|
284
359
|
|
|
285
360
|
```python
|
|
@@ -332,6 +407,12 @@ cd demo && python app.py
|
|
|
332
407
|
|
|
333
408
|
[](https://pypi.org/project/debug-agent-py/)
|
|
334
409
|
|
|
410
|
+
## Built With
|
|
411
|
+
|
|
412
|
+
[](https://github.com/topcheer/ggcode)
|
|
413
|
+
|
|
414
|
+
This project was built using [ggcode](https://github.com/topcheer/ggcode) — an AI coding assistant for terminal-based development.
|
|
415
|
+
|
|
335
416
|
## License
|
|
336
417
|
|
|
337
418
|
MIT
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# Python Debug Agent
|
|
2
2
|
|
|
3
3
|
[](https://pypi.org/project/debug-agent-py/)
|
|
4
|
-

|
|
5
|
+

|
|
6
6
|

|
|
7
7
|

|
|
8
8
|
|
|
9
|
-
An AI-powered runtime debugging agent that embeds directly into your Python web application. Add one dependency, configure an LLM key, and chat with your live app at `/agent` to inspect memory, threads, GC, modules, database connections, Redis, Django models/URLs, Celery tasks, Flask extensions, Jinja2 templates, signals, routes, HTTP requests, and more — **
|
|
9
|
+
An AI-powered runtime debugging agent that embeds directly into your Python web application. Add one dependency, configure an LLM key, and chat with your live app at `/agent` to inspect memory, threads, GC, modules, database connections, Redis, Django models/URLs, Celery tasks, Flask extensions, Jinja2 templates, signals, routes, HTTP requests, and more — **113 diagnostic tools across 38 inspectors**.
|
|
10
10
|
|
|
11
11
|
## Version Support
|
|
12
12
|
|
|
@@ -64,11 +64,11 @@ http://localhost:8000/agent
|
|
|
64
64
|
- **Context compression** — automatically summarizes old conversation when token limit is approached
|
|
65
65
|
- **Dark-themed chat UI** with full markdown rendering (tables, code blocks, lists)
|
|
66
66
|
- **Max tool rounds** (25) with forced final summary when limit is reached
|
|
67
|
-
- **
|
|
67
|
+
- **113 diagnostic tools** across **38 inspectors**
|
|
68
68
|
- Works with Flask, FastAPI, and Django
|
|
69
69
|
- Zero external dependencies (no Datadog, no Grafana, no APM)
|
|
70
70
|
|
|
71
|
-
## Inspectors & Tools (
|
|
71
|
+
## Inspectors & Tools (113)
|
|
72
72
|
|
|
73
73
|
### Memory Inspector
|
|
74
74
|
| Tool | Description |
|
|
@@ -229,6 +229,81 @@ http://localhost:8000/agent
|
|
|
229
229
|
|------|-------------|
|
|
230
230
|
| `get_warnings` | List captured Python warnings with category, message, and location |
|
|
231
231
|
|
|
232
|
+
### Deadlock & Lock Contention Inspector (v0.6.0)
|
|
233
|
+
| Tool | Description |
|
|
234
|
+
|------|-------------|
|
|
235
|
+
| `get_lock_contention` | Threading lock contention stats (wait time, hold time, acquisition count) |
|
|
236
|
+
| `detect_deadlock` | Analyze all threads for deadlock patterns (circular wait detection) |
|
|
237
|
+
| `get_mutex_stats` | Per-lock statistics: total acquisitions, contentions, average wait time |
|
|
238
|
+
|
|
239
|
+
### Database Migration Inspector (v0.6.0)
|
|
240
|
+
| Tool | Description |
|
|
241
|
+
|------|-------------|
|
|
242
|
+
| `get_migration_status` | Current schema version, applied count, last migration applied |
|
|
243
|
+
| `get_pending_migrations` | Migrations not yet applied (version, description, dependencies) |
|
|
244
|
+
| `get_migration_history` | Applied migration history (version, applied_at, duration_ms) |
|
|
245
|
+
|
|
246
|
+
### Configuration Inspector (v0.6.0)
|
|
247
|
+
| Tool | Description |
|
|
248
|
+
|------|-------------|
|
|
249
|
+
| `get_config_snapshot` | All registered config values (sensitive keys masked) |
|
|
250
|
+
| `get_env_vars_masked` | Process environment variables with secret values redacted |
|
|
251
|
+
| `get_config_sources` | Config source hierarchy (env, file, defaults) with effective values |
|
|
252
|
+
|
|
253
|
+
### Feature Flags Inspector (v0.6.0)
|
|
254
|
+
| Tool | Description |
|
|
255
|
+
|------|-------------|
|
|
256
|
+
| `get_feature_flags` | List all registered feature flags with current state |
|
|
257
|
+
| `evaluate_feature_flag` | Evaluate a specific flag for a given context/user |
|
|
258
|
+
|
|
259
|
+
### Endpoint Testing Inspector (v0.6.0)
|
|
260
|
+
| Tool | Description |
|
|
261
|
+
|------|-------------|
|
|
262
|
+
| `test_endpoint` | Make an HTTP request to own app, return full response (status, headers, body) |
|
|
263
|
+
| `batch_test_endpoints` | Test multiple endpoints in one call with aggregated results |
|
|
264
|
+
| `get_endpoint_coverage` | Compare registered routes vs tested endpoints (coverage report) |
|
|
265
|
+
|
|
266
|
+
### Connection Pool Inspector (v0.6.0)
|
|
267
|
+
| Tool | Description |
|
|
268
|
+
|------|-------------|
|
|
269
|
+
| `get_pool_details` | Detailed DB pool stats (pool size, checked-in, checked-out, overflow) |
|
|
270
|
+
| `detect_pool_leaks` | Heuristic leak detection (growing pool, high wait ratio, saturation) |
|
|
271
|
+
| `get_pool_wait_stats` | Connection acquire wait stats (avg, P95, max wait, timeout count) |
|
|
272
|
+
|
|
273
|
+
### CPU Profiler Inspector (v0.7.0)
|
|
274
|
+
| Tool | Description |
|
|
275
|
+
|------|-------------|
|
|
276
|
+
| `start_cpu_profile` | Start a CPU profiling session (cProfile/yappi) |
|
|
277
|
+
| `stop_cpu_profile` | Stop CPU profiling and return collected profile data |
|
|
278
|
+
| `get_top_functions` | Get top CPU-consuming functions from the current profile |
|
|
279
|
+
|
|
280
|
+
### Memory Leak Detector Inspector (v0.7.0)
|
|
281
|
+
| Tool | Description |
|
|
282
|
+
|------|-------------|
|
|
283
|
+
| `take_heap_snapshot` | Capture a heap snapshot for leak analysis (tracemalloc) |
|
|
284
|
+
| `compare_heap_snapshots` | Compare two heap snapshots to identify object growth |
|
|
285
|
+
| `get_leak_candidates` | Identify objects likely to be memory leaks |
|
|
286
|
+
|
|
287
|
+
### Deployment/Build Info Inspector (v0.7.0)
|
|
288
|
+
| Tool | Description |
|
|
289
|
+
|------|-------------|
|
|
290
|
+
| `get_build_info` | Build version, commit hash, and package metadata |
|
|
291
|
+
| `get_deployment_info` | Deployment environment, container, and orchestration metadata |
|
|
292
|
+
| `get_runtime_version` | Python interpreter version and implementation details |
|
|
293
|
+
|
|
294
|
+
### Snapshot & Diff Inspector (v0.7.0)
|
|
295
|
+
| Tool | Description |
|
|
296
|
+
|------|-------------|
|
|
297
|
+
| `take_snapshot` | Capture a runtime state snapshot |
|
|
298
|
+
| `compare_snapshots` | Compare two snapshots to identify state changes |
|
|
299
|
+
| `list_snapshots` | List all saved snapshots with timestamps |
|
|
300
|
+
|
|
301
|
+
### Service Registry Inspector (v0.7.0)
|
|
302
|
+
| Tool | Description |
|
|
303
|
+
|------|-------------|
|
|
304
|
+
| `get_registered_services` | List all registered application services |
|
|
305
|
+
| `get_service_dependencies` | Map service-to-service dependency graph |
|
|
306
|
+
|
|
232
307
|
## Custom Tools
|
|
233
308
|
|
|
234
309
|
```python
|
|
@@ -281,6 +356,12 @@ cd demo && python app.py
|
|
|
281
356
|
|
|
282
357
|
[](https://pypi.org/project/debug-agent-py/)
|
|
283
358
|
|
|
359
|
+
## Built With
|
|
360
|
+
|
|
361
|
+
[](https://github.com/topcheer/ggcode)
|
|
362
|
+
|
|
363
|
+
This project was built using [ggcode](https://github.com/topcheer/ggcode) — an AI coding assistant for terminal-based development.
|
|
364
|
+
|
|
284
365
|
## License
|
|
285
366
|
|
|
286
367
|
MIT
|
|
@@ -2,6 +2,17 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
"""Debug Agent — AI-powered runtime debugging for Python applications."""
|
|
4
4
|
|
|
5
|
+
import sys as _sys
|
|
6
|
+
|
|
7
|
+
# ggcode promotional message — shown once on first import
|
|
8
|
+
if not hasattr(_sys, '_debug_agent_ggcode_shown'):
|
|
9
|
+
_sys._debug_agent_ggcode_shown = True
|
|
10
|
+
_print = print
|
|
11
|
+
_print('')
|
|
12
|
+
_print(' This package was built with ggcode — an AI coding assistant.')
|
|
13
|
+
_print(' https://github.com/topcheer/ggcode')
|
|
14
|
+
_print('')
|
|
15
|
+
|
|
5
16
|
from debug_agent.config import AgentConfig
|
|
6
17
|
from debug_agent.tool_registry import debug_tool, ToolParam, registry
|
|
7
18
|
from debug_agent.engine import DebugEngine, ChatCallback
|
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
from debug_agent.inspectors import ( # noqa: F401
|
|
4
4
|
async_tasks,
|
|
5
|
+
build_info_inspector,
|
|
5
6
|
cache_inspector,
|
|
6
7
|
celery,
|
|
8
|
+
cpu_profile_inspector,
|
|
9
|
+
config_inspector,
|
|
7
10
|
database,
|
|
8
11
|
django,
|
|
12
|
+
endpoint_test_inspector,
|
|
9
13
|
error_tracking,
|
|
10
14
|
fastapi_ext,
|
|
15
|
+
feature_flag_inspector,
|
|
11
16
|
fd_inspector,
|
|
12
17
|
flask_ext,
|
|
13
18
|
framework,
|
|
@@ -15,15 +20,21 @@ from debug_agent.inspectors import ( # noqa: F401
|
|
|
15
20
|
http_client_inspector,
|
|
16
21
|
http_tracker,
|
|
17
22
|
jinja2,
|
|
23
|
+
leak_detector_inspector,
|
|
24
|
+
locks_inspector,
|
|
18
25
|
logging_inspector,
|
|
19
26
|
memory,
|
|
20
27
|
metrics_inspector,
|
|
28
|
+
migration_inspector,
|
|
21
29
|
modules,
|
|
30
|
+
pool_inspector,
|
|
22
31
|
redis,
|
|
23
32
|
runtime,
|
|
24
33
|
scheduler_inspector,
|
|
25
34
|
security_inspector,
|
|
35
|
+
service_registry_inspector,
|
|
26
36
|
signals,
|
|
37
|
+
snapshot_inspector,
|
|
27
38
|
system,
|
|
28
39
|
threads,
|
|
29
40
|
warnings_inspector,
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"""Build / deployment info inspector: Python build details, runtime versions, deployment metadata."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import platform
|
|
7
|
+
import socket
|
|
8
|
+
import sys
|
|
9
|
+
import time
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from debug_agent.tool_registry import debug_tool, ToolParam
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
_PROCESS_START = time.time()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
_ENV_VARS_OF_INTEREST = [
|
|
22
|
+
"APP_ENV",
|
|
23
|
+
"FLASK_ENV",
|
|
24
|
+
"DJANGO_SETTINGS_MODULE",
|
|
25
|
+
"NODE_ENV",
|
|
26
|
+
"ENVIRONMENT",
|
|
27
|
+
"STAGE",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
_RUNTIME_DEPS = [
|
|
32
|
+
"flask",
|
|
33
|
+
"django",
|
|
34
|
+
"fastapi",
|
|
35
|
+
"sqlalchemy",
|
|
36
|
+
"redis",
|
|
37
|
+
"celery",
|
|
38
|
+
"psycopg2",
|
|
39
|
+
"pymongo",
|
|
40
|
+
"uvicorn",
|
|
41
|
+
"gunicorn",
|
|
42
|
+
"requests",
|
|
43
|
+
"aiohttp",
|
|
44
|
+
"pydantic",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _detect_container() -> dict[str, Any]:
|
|
49
|
+
"""Detect whether the process runs inside a container."""
|
|
50
|
+
container_type = None
|
|
51
|
+
|
|
52
|
+
if os.path.exists("/.dockerenv"):
|
|
53
|
+
container_type = "docker"
|
|
54
|
+
elif os.path.exists("/run/.containerenv"):
|
|
55
|
+
container_type = "podman"
|
|
56
|
+
else:
|
|
57
|
+
try:
|
|
58
|
+
with open("/proc/1/cgroup", "r") as f:
|
|
59
|
+
content = f.read()
|
|
60
|
+
if "docker" in content:
|
|
61
|
+
container_type = "docker"
|
|
62
|
+
elif "kubepods" in content:
|
|
63
|
+
container_type = "kubernetes"
|
|
64
|
+
elif "lxc" in content:
|
|
65
|
+
container_type = "lxc"
|
|
66
|
+
except (FileNotFoundError, IOError, OSError):
|
|
67
|
+
pass
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
"in_container": container_type is not None,
|
|
71
|
+
"container_type": container_type,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _get_uptime() -> float:
|
|
76
|
+
"""Return process uptime in seconds."""
|
|
77
|
+
return round(time.time() - _PROCESS_START, 2)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _get_package_versions() -> dict[str, str | None]:
|
|
81
|
+
"""Return versions of installed packages via importlib.metadata."""
|
|
82
|
+
try:
|
|
83
|
+
from importlib.metadata import version as get_version, PackageNotFoundError
|
|
84
|
+
except ImportError:
|
|
85
|
+
return {}
|
|
86
|
+
|
|
87
|
+
result = {}
|
|
88
|
+
for pkg in _RUNTIME_DEPS:
|
|
89
|
+
try:
|
|
90
|
+
result[pkg] = get_version(pkg)
|
|
91
|
+
except PackageNotFoundError:
|
|
92
|
+
pass
|
|
93
|
+
except Exception:
|
|
94
|
+
pass
|
|
95
|
+
return result
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
# ─── Tools ────────────────────────────────────────────────────────────────────
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@debug_tool(
|
|
102
|
+
"get_build_info",
|
|
103
|
+
"Get Python build details: version, implementation, build date, compiler, C API version",
|
|
104
|
+
)
|
|
105
|
+
def get_build_info() -> dict:
|
|
106
|
+
info: dict[str, Any] = {
|
|
107
|
+
"python_version": sys.version,
|
|
108
|
+
"version_info": {
|
|
109
|
+
"major": sys.version_info[0],
|
|
110
|
+
"minor": sys.version_info[1],
|
|
111
|
+
"micro": sys.version_info[2],
|
|
112
|
+
"releaselevel": sys.version_info[3],
|
|
113
|
+
"serial": sys.version_info[4],
|
|
114
|
+
},
|
|
115
|
+
"implementation": platform.python_implementation(),
|
|
116
|
+
"compiler": platform.python_compiler(),
|
|
117
|
+
"build_date": platform.python_build()[1] if len(platform.python_build()) > 1 else None,
|
|
118
|
+
"build_info_raw": platform.python_build()[0] if platform.python_build() else None,
|
|
119
|
+
"api_version": sys.api_version,
|
|
120
|
+
"hexversion": hex(sys.hexversion),
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
# C API version
|
|
124
|
+
try:
|
|
125
|
+
info["c_api_version"] = sys.api_version
|
|
126
|
+
except AttributeError:
|
|
127
|
+
pass
|
|
128
|
+
|
|
129
|
+
# Try to get installed package versions
|
|
130
|
+
pkg_versions = _get_package_versions()
|
|
131
|
+
if pkg_versions:
|
|
132
|
+
info["installed_packages"] = pkg_versions
|
|
133
|
+
|
|
134
|
+
return info
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@debug_tool(
|
|
138
|
+
"get_deployment_info",
|
|
139
|
+
"Get deployment metadata: hostname, PID, uptime, container detection, platform, selected env vars",
|
|
140
|
+
)
|
|
141
|
+
def get_deployment_info() -> dict:
|
|
142
|
+
container = _detect_container()
|
|
143
|
+
|
|
144
|
+
selected_env: dict[str, str | None] = {}
|
|
145
|
+
for var in _ENV_VARS_OF_INTEREST:
|
|
146
|
+
selected_env[var] = os.environ.get(var)
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
"hostname": socket.gethostname(),
|
|
150
|
+
"pid": os.getpid(),
|
|
151
|
+
"ppid": os.getppid(),
|
|
152
|
+
"uptime_seconds": _get_uptime(),
|
|
153
|
+
"platform": platform.platform(),
|
|
154
|
+
"architecture": platform.machine(),
|
|
155
|
+
"processor": platform.processor() or None,
|
|
156
|
+
"container_detected": container["in_container"],
|
|
157
|
+
"container_type": container["container_type"],
|
|
158
|
+
"working_directory": os.getcwd(),
|
|
159
|
+
"user": os.environ.get("USER") or os.environ.get("USERNAME"),
|
|
160
|
+
"environment_variables": {k: v for k, v in selected_env.items() if v is not None},
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
@debug_tool(
|
|
165
|
+
"get_runtime_version",
|
|
166
|
+
"Get versions of key runtime dependencies (flask, django, fastapi, sqlalchemy, redis, celery, etc.)",
|
|
167
|
+
)
|
|
168
|
+
def get_runtime_version() -> dict:
|
|
169
|
+
pkg_versions = _get_package_versions()
|
|
170
|
+
|
|
171
|
+
# Also try importing for modules that expose __version__
|
|
172
|
+
import_versions: dict[str, str | None] = {}
|
|
173
|
+
for dep in _RUNTIME_DEPS:
|
|
174
|
+
mod = sys.modules.get(dep)
|
|
175
|
+
if mod is not None:
|
|
176
|
+
ver = getattr(mod, "__version__", None)
|
|
177
|
+
if ver:
|
|
178
|
+
import_versions[dep] = ver
|
|
179
|
+
|
|
180
|
+
# Merge: prefer importlib.metadata, fall back to __version__
|
|
181
|
+
merged: dict[str, str | None] = {}
|
|
182
|
+
for dep in _RUNTIME_DEPS:
|
|
183
|
+
merged[dep] = pkg_versions.get(dep) or import_versions.get(dep)
|
|
184
|
+
|
|
185
|
+
installed = {k: v for k, v in merged.items() if v is not None}
|
|
186
|
+
not_installed = [k for k, v in merged.items() if v is None]
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
"installed": installed,
|
|
190
|
+
"not_installed": not_installed,
|
|
191
|
+
"total_checked": len(_RUNTIME_DEPS),
|
|
192
|
+
"total_installed": len(installed),
|
|
193
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""Config inspector: configuration snapshots, env vars, and provenance.
|
|
2
|
+
|
|
3
|
+
Register config dicts at runtime so they can be introspected:
|
|
4
|
+
|
|
5
|
+
from debug_agent.inspectors.config_inspector import register_config
|
|
6
|
+
register_config("flask", {"DEBUG": True, "SQLALCHEMY_DATABASE_URI": "..."})
|
|
7
|
+
|
|
8
|
+
Sensitive keys (matching password|secret|token|api.?key|private.?key|credential)
|
|
9
|
+
are automatically masked as ``"***"``.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import os
|
|
15
|
+
import re
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from debug_agent.tool_registry import debug_tool, ToolParam
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# ─── Registration ──────────────────────────────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
_registered_configs: dict[str, dict[str, Any]] = {}
|
|
24
|
+
|
|
25
|
+
# Optional provenance tracking: config name -> { key -> source }
|
|
26
|
+
_config_sources: dict[str, dict[str, str]] = {}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def register_config(
|
|
30
|
+
name: str,
|
|
31
|
+
config_dict: dict[str, Any],
|
|
32
|
+
sources: dict[str, str] | None = None,
|
|
33
|
+
) -> None:
|
|
34
|
+
"""Register a config dict under *name*.
|
|
35
|
+
|
|
36
|
+
*sources* optionally maps keys to provenance labels (``"env"``,
|
|
37
|
+
``"file"``, ``"default"``, ...).
|
|
38
|
+
"""
|
|
39
|
+
_registered_configs[name] = dict(config_dict)
|
|
40
|
+
if sources:
|
|
41
|
+
_config_sources[name] = dict(sources)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
45
|
+
|
|
46
|
+
_SENSITIVE_RE = re.compile(r"password|secret|token|api.?key|private.?key|credential", re.IGNORECASE)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _is_sensitive(key: str) -> bool:
|
|
50
|
+
return bool(_SENSITIVE_RE.search(str(key)))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _mask(key: str, value: Any) -> Any:
|
|
54
|
+
if _is_sensitive(key):
|
|
55
|
+
return "***"
|
|
56
|
+
return value
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _mask_config(config: dict[str, Any]) -> dict[str, Any]:
|
|
60
|
+
return {k: _mask(k, v) for k, v in config.items()}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
# ─── Tools ────────────────────────────────────────────────────────────────────
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@debug_tool(
|
|
67
|
+
"get_config_snapshot",
|
|
68
|
+
"Get all registered config values with sensitive keys masked",
|
|
69
|
+
)
|
|
70
|
+
def get_config_snapshot() -> dict:
|
|
71
|
+
if not _registered_configs:
|
|
72
|
+
return {
|
|
73
|
+
"count": 0,
|
|
74
|
+
"configs": {},
|
|
75
|
+
"message": "No configs registered. Use register_config(name, config_dict).",
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
snapshot: dict[str, Any] = {}
|
|
79
|
+
for name, config in _registered_configs.items():
|
|
80
|
+
snapshot[name] = _mask_config(config)
|
|
81
|
+
|
|
82
|
+
# Count how many values were masked for transparency.
|
|
83
|
+
masked_total = 0
|
|
84
|
+
for config in _registered_configs.values():
|
|
85
|
+
for key in config:
|
|
86
|
+
if _is_sensitive(key):
|
|
87
|
+
masked_total += 1
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
"count": len(snapshot),
|
|
91
|
+
"masked_values": masked_total,
|
|
92
|
+
"configs": snapshot,
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@debug_tool(
|
|
97
|
+
"get_env_vars",
|
|
98
|
+
"Dump os.environ with optional prefix filter; sensitive values are masked",
|
|
99
|
+
)
|
|
100
|
+
def get_env_vars(
|
|
101
|
+
prefix: str | None = None,
|
|
102
|
+
) -> dict:
|
|
103
|
+
env: dict[str, str] = {}
|
|
104
|
+
masked: list[str] = []
|
|
105
|
+
|
|
106
|
+
for key in sorted(os.environ):
|
|
107
|
+
if prefix and not key.startswith(prefix):
|
|
108
|
+
continue
|
|
109
|
+
if _is_sensitive(key):
|
|
110
|
+
env[key] = "***"
|
|
111
|
+
masked.append(key)
|
|
112
|
+
else:
|
|
113
|
+
env[key] = os.environ[key]
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
"prefix": prefix or None,
|
|
117
|
+
"total": len(env),
|
|
118
|
+
"masked_count": len(masked),
|
|
119
|
+
"masked_keys": masked,
|
|
120
|
+
"variables": env,
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@debug_tool(
|
|
125
|
+
"get_config_sources",
|
|
126
|
+
"Get config provenance — where each value came from (env, file, default)",
|
|
127
|
+
)
|
|
128
|
+
def get_config_sources(
|
|
129
|
+
name: str | None = None,
|
|
130
|
+
) -> dict:
|
|
131
|
+
if name:
|
|
132
|
+
if name not in _registered_configs:
|
|
133
|
+
return {"error": f"No config registered with name '{name}'"}
|
|
134
|
+
sources = _config_sources.get(name, {})
|
|
135
|
+
result: dict[str, Any] = {}
|
|
136
|
+
for key in _registered_configs[name]:
|
|
137
|
+
result[key] = sources.get(key, "default")
|
|
138
|
+
return {"name": name, "sources": result}
|
|
139
|
+
|
|
140
|
+
if not _registered_configs:
|
|
141
|
+
return {
|
|
142
|
+
"count": 0,
|
|
143
|
+
"configs": {},
|
|
144
|
+
"message": "No configs registered.",
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
all_sources: dict[str, dict[str, str]] = {}
|
|
148
|
+
for cfg_name, config in _registered_configs.items():
|
|
149
|
+
sources = _config_sources.get(cfg_name, {})
|
|
150
|
+
all_sources[cfg_name] = {
|
|
151
|
+
key: sources.get(key, "default") for key in config
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
"count": len(all_sources),
|
|
156
|
+
"configs": all_sources,
|
|
157
|
+
}
|