debug-agent-py 0.5.0__tar.gz → 0.6.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.0 → debug_agent_py-0.6.0}/PKG-INFO +63 -6
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/README.md +62 -5
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/pyproject.toml +1 -1
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/__init__.py +2 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/__init__.py +6 -0
- debug_agent_py-0.6.0/src/debug_agent/inspectors/config_inspector.py +157 -0
- debug_agent_py-0.6.0/src/debug_agent/inspectors/endpoint_test_inspector.py +374 -0
- debug_agent_py-0.6.0/src/debug_agent/inspectors/feature_flag_inspector.py +124 -0
- debug_agent_py-0.6.0/src/debug_agent/inspectors/locks_inspector.py +307 -0
- debug_agent_py-0.6.0/src/debug_agent/inspectors/migration_inspector.py +312 -0
- debug_agent_py-0.6.0/src/debug_agent/inspectors/pool_inspector.py +309 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent_py.egg-info/PKG-INFO +63 -6
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent_py.egg-info/SOURCES.txt +6 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/setup.cfg +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/chat_session.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/config.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/context_compressor.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/engine.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/async_tasks.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/cache_inspector.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/celery.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/database.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/django.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/error_tracking.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/fastapi_ext.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/fd_inspector.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/flask_ext.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/framework.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/health_inspector.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/http_client_inspector.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/http_tracker.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/jinja2.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/logging_inspector.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/memory.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/metrics_inspector.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/modules.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/redis.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/runtime.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/scheduler_inspector.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/security_inspector.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/signals.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/system.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/threads.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/warnings_inspector.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/inspectors/websocket_inspector.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/llm_client.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/middleware.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/system_prompt_builder.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/tool_registry.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/web/__init__.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent/web/chat_page.py +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent_py.egg-info/dependency_links.txt +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.0}/src/debug_agent_py.egg-info/requires.txt +0 -0
- {debug_agent_py-0.5.0 → debug_agent_py-0.6.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.6.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,10 +52,26 @@ Requires-Dist: pytest; extra == "dev"
|
|
|
52
52
|
# Python Debug Agent
|
|
53
53
|
|
|
54
54
|
[](https://pypi.org/project/debug-agent-py/)
|
|
55
|
-

|
|
56
|
+

|
|
57
|
+

|
|
58
|
+

|
|
57
59
|
|
|
58
|
-
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 — **99 diagnostic tools across 33 inspectors**.
|
|
61
|
+
|
|
62
|
+
## Version Support
|
|
63
|
+
|
|
64
|
+
| Python Version | Status |
|
|
65
|
+
|----------------|--------|
|
|
66
|
+
| 3.8 | Not supported |
|
|
67
|
+
| 3.9 | Minimum supported |
|
|
68
|
+
| 3.10 | Supported |
|
|
69
|
+
| 3.11 | Supported |
|
|
70
|
+
| 3.12 | Supported |
|
|
71
|
+
| 3.13 | Supported |
|
|
72
|
+
| 3.14 | Tested |
|
|
73
|
+
|
|
74
|
+
> Uses `from __future__ import annotations` so `X | Y` union types work on Python 3.9+. Optional dependencies (Flask, SQLAlchemy, Redis, Celery) are not required at install time.
|
|
59
75
|
|
|
60
76
|
## Quick Start
|
|
61
77
|
|
|
@@ -99,11 +115,11 @@ http://localhost:8000/agent
|
|
|
99
115
|
- **Context compression** — automatically summarizes old conversation when token limit is approached
|
|
100
116
|
- **Dark-themed chat UI** with full markdown rendering (tables, code blocks, lists)
|
|
101
117
|
- **Max tool rounds** (25) with forced final summary when limit is reached
|
|
102
|
-
- **
|
|
118
|
+
- **99 diagnostic tools** across **33 inspectors**
|
|
103
119
|
- Works with Flask, FastAPI, and Django
|
|
104
120
|
- Zero external dependencies (no Datadog, no Grafana, no APM)
|
|
105
121
|
|
|
106
|
-
## Inspectors & Tools (
|
|
122
|
+
## Inspectors & Tools (99)
|
|
107
123
|
|
|
108
124
|
### Memory Inspector
|
|
109
125
|
| Tool | Description |
|
|
@@ -264,6 +280,47 @@ http://localhost:8000/agent
|
|
|
264
280
|
|------|-------------|
|
|
265
281
|
| `get_warnings` | List captured Python warnings with category, message, and location |
|
|
266
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
|
+
|
|
267
324
|
## Custom Tools
|
|
268
325
|
|
|
269
326
|
```python
|
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
# Python Debug Agent
|
|
2
2
|
|
|
3
3
|
[](https://pypi.org/project/debug-agent-py/)
|
|
4
|
-

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
6
8
|
|
|
7
|
-
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 — **99 diagnostic tools across 33 inspectors**.
|
|
10
|
+
|
|
11
|
+
## Version Support
|
|
12
|
+
|
|
13
|
+
| Python Version | Status |
|
|
14
|
+
|----------------|--------|
|
|
15
|
+
| 3.8 | Not supported |
|
|
16
|
+
| 3.9 | Minimum supported |
|
|
17
|
+
| 3.10 | Supported |
|
|
18
|
+
| 3.11 | Supported |
|
|
19
|
+
| 3.12 | Supported |
|
|
20
|
+
| 3.13 | Supported |
|
|
21
|
+
| 3.14 | Tested |
|
|
22
|
+
|
|
23
|
+
> Uses `from __future__ import annotations` so `X | Y` union types work on Python 3.9+. Optional dependencies (Flask, SQLAlchemy, Redis, Celery) are not required at install time.
|
|
8
24
|
|
|
9
25
|
## Quick Start
|
|
10
26
|
|
|
@@ -48,11 +64,11 @@ http://localhost:8000/agent
|
|
|
48
64
|
- **Context compression** — automatically summarizes old conversation when token limit is approached
|
|
49
65
|
- **Dark-themed chat UI** with full markdown rendering (tables, code blocks, lists)
|
|
50
66
|
- **Max tool rounds** (25) with forced final summary when limit is reached
|
|
51
|
-
- **
|
|
67
|
+
- **99 diagnostic tools** across **33 inspectors**
|
|
52
68
|
- Works with Flask, FastAPI, and Django
|
|
53
69
|
- Zero external dependencies (no Datadog, no Grafana, no APM)
|
|
54
70
|
|
|
55
|
-
## Inspectors & Tools (
|
|
71
|
+
## Inspectors & Tools (99)
|
|
56
72
|
|
|
57
73
|
### Memory Inspector
|
|
58
74
|
| Tool | Description |
|
|
@@ -213,6 +229,47 @@ http://localhost:8000/agent
|
|
|
213
229
|
|------|-------------|
|
|
214
230
|
| `get_warnings` | List captured Python warnings with category, message, and location |
|
|
215
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
|
+
|
|
216
273
|
## Custom Tools
|
|
217
274
|
|
|
218
275
|
```python
|
|
@@ -4,10 +4,13 @@ from debug_agent.inspectors import ( # noqa: F401
|
|
|
4
4
|
async_tasks,
|
|
5
5
|
cache_inspector,
|
|
6
6
|
celery,
|
|
7
|
+
config_inspector,
|
|
7
8
|
database,
|
|
8
9
|
django,
|
|
10
|
+
endpoint_test_inspector,
|
|
9
11
|
error_tracking,
|
|
10
12
|
fastapi_ext,
|
|
13
|
+
feature_flag_inspector,
|
|
11
14
|
fd_inspector,
|
|
12
15
|
flask_ext,
|
|
13
16
|
framework,
|
|
@@ -15,10 +18,13 @@ from debug_agent.inspectors import ( # noqa: F401
|
|
|
15
18
|
http_client_inspector,
|
|
16
19
|
http_tracker,
|
|
17
20
|
jinja2,
|
|
21
|
+
locks_inspector,
|
|
18
22
|
logging_inspector,
|
|
19
23
|
memory,
|
|
20
24
|
metrics_inspector,
|
|
25
|
+
migration_inspector,
|
|
21
26
|
modules,
|
|
27
|
+
pool_inspector,
|
|
22
28
|
redis,
|
|
23
29
|
runtime,
|
|
24
30
|
scheduler_inspector,
|
|
@@ -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
|
+
}
|