dbagent-cli 0.10.0__tar.gz → 0.11.1__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.
- dbagent_cli-0.11.1/PKG-INFO +291 -0
- dbagent_cli-0.11.1/README.md +237 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/__init__.py +1 -1
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/agent/doctor.py +30 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/agent/generator.py +4 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/agent/pipeline.py +16 -8
- dbagent_cli-0.11.1/dbagent/benchmark.py +125 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/cli.py +249 -50
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/connectors/factory.py +7 -0
- dbagent_cli-0.11.1/dbagent/errors.py +83 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/execution/prompt_queue.py +17 -5
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/llm/factory.py +5 -0
- dbagent_cli-0.11.1/dbagent/plugins.py +101 -0
- dbagent_cli-0.11.1/dbagent/sample_db.py +216 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/sql/validator.py +12 -6
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/ui/console.py +2 -2
- dbagent_cli-0.11.1/dbagent_cli.egg-info/PKG-INFO +291 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent_cli.egg-info/SOURCES.txt +9 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent_cli.egg-info/requires.txt +14 -0
- dbagent_cli-0.11.1/pyproject.toml +81 -0
- dbagent_cli-0.11.1/tests/test_benchmarks.py +24 -0
- dbagent_cli-0.11.1/tests/test_demo_and_sample_db.py +41 -0
- dbagent_cli-0.11.1/tests/test_formats_and_exit_codes.py +74 -0
- dbagent_cli-0.11.1/tests/test_plugins.py +79 -0
- dbagent_cli-0.11.1/tests/test_prompt_queue_and_sql.py +48 -0
- dbagent_cli-0.10.0/PKG-INFO +0 -281
- dbagent_cli-0.10.0/README.md +0 -257
- dbagent_cli-0.10.0/dbagent_cli.egg-info/PKG-INFO +0 -281
- dbagent_cli-0.10.0/pyproject.toml +0 -43
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/agent/confidence.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/agent/conversation.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/agent/error_classifier.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/agent/recommender.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/agent/validator.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/config.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/connectors/base.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/connectors/mongo.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/connectors/relational.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/execution/__init__.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/execution/cache.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/execution/changeset.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/execution/cost.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/execution/recovery.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/execution/sandbox.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/execution/streaming.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/llm/anthropic_provider.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/llm/auto_setup.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/llm/base.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/llm/deepseek_provider.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/llm/gemini_provider.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/llm/groq_provider.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/llm/mistral_provider.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/llm/mock_provider.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/llm/ollama_provider.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/llm/openai_provider.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/llm/openrouter_provider.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/schema/cache.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/schema/formatter.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/schema/graph.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/schema/ground_truth.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/schema/models.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/schema/retriever.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/schema/selector.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/security/__init__.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/security/audit.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/security/environment.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/security/masking.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/security/modes.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/security/rbac.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/semantic/__init__.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/semantic/dictionary.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/semantic/knowledge.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/semantic/templates.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/sql/__init__.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/sql/optimizer.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/ui/chat_screen.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/ui/grid_window.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/ui/live_streamer.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/ui/viewer.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent/ui/visualizer.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent_cli.egg-info/dependency_links.txt +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent_cli.egg-info/entry_points.txt +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/dbagent_cli.egg-info/top_level.txt +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/setup.cfg +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/tests/test_cache.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/tests/test_cli.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/tests/test_connectors.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/tests/test_direct_sql.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/tests/test_doctor_and_viz.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/tests/test_generator.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/tests/test_graph.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/tests/test_knowledge.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/tests/test_prompt_queue.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/tests/test_providers.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/tests/test_recovery.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/tests/test_safety.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/tests/test_sandbox.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/tests/test_schema.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/tests/test_security.py +0 -0
- {dbagent_cli-0.10.0 → dbagent_cli-0.11.1}/tests/test_semantic.py +0 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dbagent-cli
|
|
3
|
+
Version: 0.11.1
|
|
4
|
+
Summary: The Privacy-First AI Database Copilot, Schema Graph Introspector & Post-Commit Recovery Engine (CLI)
|
|
5
|
+
Author: Santhosh Gupta
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/santhoshgupta/dbagent-cli
|
|
8
|
+
Project-URL: Documentation, https://github.com/santhoshgupta/dbagent-cli#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/santhoshgupta/dbagent-cli.git
|
|
10
|
+
Project-URL: Issues, https://github.com/santhoshgupta/dbagent-cli/issues
|
|
11
|
+
Keywords: database,sql,ai,llm,copilot,postgresql,mysql,sqlite,duckdb,mongodb,cli,introspection
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: System Administrators
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Topic :: Database
|
|
24
|
+
Classifier: Topic :: Database :: Front-Ends
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
Requires-Dist: typer>=0.9.0
|
|
29
|
+
Requires-Dist: rich>=13.0.0
|
|
30
|
+
Requires-Dist: prompt-toolkit>=3.0.0
|
|
31
|
+
Requires-Dist: pydantic>=2.0.0
|
|
32
|
+
Requires-Dist: sqlalchemy>=2.0.0
|
|
33
|
+
Requires-Dist: requests>=2.28.0
|
|
34
|
+
Requires-Dist: httpx>=0.24.0
|
|
35
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
36
|
+
Provides-Extra: postgres
|
|
37
|
+
Requires-Dist: psycopg2-binary>=2.9.0; extra == "postgres"
|
|
38
|
+
Provides-Extra: mysql
|
|
39
|
+
Requires-Dist: pymysql>=1.0.0; extra == "mysql"
|
|
40
|
+
Provides-Extra: mongo
|
|
41
|
+
Requires-Dist: pymongo>=4.0.0; extra == "mongo"
|
|
42
|
+
Provides-Extra: duckdb
|
|
43
|
+
Requires-Dist: duckdb>=0.9.0; extra == "duckdb"
|
|
44
|
+
Provides-Extra: all
|
|
45
|
+
Requires-Dist: psycopg2-binary>=2.9.0; extra == "all"
|
|
46
|
+
Requires-Dist: pymysql>=1.0.0; extra == "all"
|
|
47
|
+
Requires-Dist: pymongo>=4.0.0; extra == "all"
|
|
48
|
+
Requires-Dist: duckdb>=0.9.0; extra == "all"
|
|
49
|
+
Provides-Extra: dev
|
|
50
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
51
|
+
Requires-Dist: pytest-asyncio>=0.20.0; extra == "dev"
|
|
52
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
53
|
+
Requires-Dist: twine>=4.0.0; extra == "dev"
|
|
54
|
+
|
|
55
|
+
# ⚡ DB-Agent (`dbagent-cli`)
|
|
56
|
+
|
|
57
|
+
> **The Privacy-First AI Database Copilot, Schema Graph Introspector & Post-Commit Recovery Engine**
|
|
58
|
+
> *Author: Santhosh Gupta | 100% Free, Standalone, Works 100% Offline (Ollama) or with Cloud AI (Claude 3.7 / GPT-4o / DeepSeek / Gemini / Groq).*
|
|
59
|
+
|
|
60
|
+
[](https://pypi.org/project/dbagent-cli/)
|
|
61
|
+
[](https://pypi.org/project/dbagent-cli/)
|
|
62
|
+
[](https://opensource.org/licenses/MIT)
|
|
63
|
+
[](https://pypi.org/project/dbagent-cli/)
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 🌟 What is DB-Agent?
|
|
68
|
+
|
|
69
|
+
**DB-Agent** is an enterprise-ready, privacy-first database AI copilot that translates plain English into dialect-precise SQL, explores schemas on-demand (<30ms), enforces strict multi-tier safety guardrails, and captures pre-write snapshots allowing you to safely rollback database modifications days or weeks after `COMMIT`.
|
|
70
|
+
|
|
71
|
+
```text
|
|
72
|
+
"Show me the top 10 customers by order value"
|
|
73
|
+
↓
|
|
74
|
+
[ DB-Agent CLI Engine ]
|
|
75
|
+
(Targeted Schema Sub-Graph + AST Safety)
|
|
76
|
+
↓
|
|
77
|
+
SELECT c.customer_id, c.first_name, SUM(o.total_amount) AS total_spend
|
|
78
|
+
FROM customers c
|
|
79
|
+
JOIN orders o ON c.customer_id = o.customer_id
|
|
80
|
+
GROUP BY c.customer_id, c.first_name
|
|
81
|
+
ORDER BY total_spend DESC LIMIT 10;
|
|
82
|
+
↓
|
|
83
|
+
⚡ Executed in 0.4s
|
|
84
|
+
┌─────────────┬────────────┬─────────────┐
|
|
85
|
+
│ customer_id │ first_name │ total_spend │
|
|
86
|
+
├─────────────┼────────────┼─────────────┤
|
|
87
|
+
│ 1 │ Alice │ $3,450.00 │
|
|
88
|
+
│ 3 │ Claire │ $2,198.50 │
|
|
89
|
+
└─────────────┴────────────┴─────────────┘
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## 🚀 5-Second Instant Trial (Zero Setup Required)
|
|
95
|
+
|
|
96
|
+
Want to test DB-Agent without configuring a database or API keys?
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# 1. Install DB-Agent
|
|
100
|
+
pip install "dbagent-cli[all]"
|
|
101
|
+
|
|
102
|
+
# 2. Launch built-in demo e-commerce database with interactive AI copilot
|
|
103
|
+
db-agent demo
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## ⚡ 3-Minute Quickstart
|
|
109
|
+
|
|
110
|
+
### 1. Install
|
|
111
|
+
```bash
|
|
112
|
+
pip install --upgrade "dbagent-cli[all]"
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### 2. Configure AI Backend (1-Click Setup)
|
|
116
|
+
```bash
|
|
117
|
+
db-agent setup
|
|
118
|
+
```
|
|
119
|
+
Choose from 8 built-in providers:
|
|
120
|
+
- **Local Ollama** (100% private, 100% offline with `qwen2.5-coder`, `llama3.3`, `deepseek-r1`)
|
|
121
|
+
- **Google Gemini** (`gemini-3.6-flash`, `gemini-2.5-flash`)
|
|
122
|
+
- **Anthropic Claude** (`claude-3-7-sonnet-20250219`, `claude-3-5-sonnet`)
|
|
123
|
+
- **OpenAI ChatGPT** (`gpt-4o`, `gpt-4.5-preview`, `o3-mini`)
|
|
124
|
+
- **DeepSeek AI** (`deepseek-chat` V3, `deepseek-reasoner` R1)
|
|
125
|
+
- **Mistral AI** (`codestral-latest`, `mistral-large-latest`)
|
|
126
|
+
- **Groq** (`llama-3.3-70b-versatile`)
|
|
127
|
+
- **OpenRouter** (`meta-llama/llama-3.3-70b-instruct`)
|
|
128
|
+
|
|
129
|
+
### 3. Connect Your Database
|
|
130
|
+
```bash
|
|
131
|
+
# Interactive guided connection
|
|
132
|
+
db-agent connect
|
|
133
|
+
|
|
134
|
+
# Or connect directly with an alias
|
|
135
|
+
db-agent connect postgresql://user:password@localhost:5432/app_db --alias prod_db
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### 4. Ask Plain English Questions
|
|
139
|
+
```bash
|
|
140
|
+
# One-off query:
|
|
141
|
+
db-agent ask "count active users grouped by country" --db prod_db
|
|
142
|
+
|
|
143
|
+
# CI/CD machine-readable JSON export:
|
|
144
|
+
db-agent ask "count orders by status" --db prod_db --format json
|
|
145
|
+
|
|
146
|
+
# Interactive Claude-Style Shell with live streaming & prompt queuing:
|
|
147
|
+
db-agent chat --db prod_db
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## 📊 Database Compatibility Matrix
|
|
153
|
+
|
|
154
|
+
| Database Engine | Introspection | Direct Queries | Multi-Hop JOINs | Transactions | 30-Day Recovery | Status |
|
|
155
|
+
| :--- | :---: | :---: | :---: | :---: | :---: | :--- |
|
|
156
|
+
| **PostgreSQL / CockroachDB** | ✓ | ✓ | ✓ | ✓ | ✓ | **Fully Supported** |
|
|
157
|
+
| **MySQL / MariaDB** | ✓ | ✓ | ✓ | ✓ | ✓ | **Fully Supported** |
|
|
158
|
+
| **SQLite** | ✓ | ✓ | ✓ | ✓ | ✓ | **Fully Supported** |
|
|
159
|
+
| **DuckDB** | ✓ | ✓ | ✓ | ✓ | ✓ | **Fully Supported** |
|
|
160
|
+
| **Microsoft SQL Server** | ✓ | ✓ | ✓ | ✓ | ✓ | **Fully Supported** |
|
|
161
|
+
| **Oracle Database** | ✓ | ✓ | ✓ | ✓ | ✓ | **Fully Supported** |
|
|
162
|
+
| **MongoDB** | ✓ (JSON) | ✓ (Filters) | N/A | ✓ | N/A | **Document Supported** |
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## 🪟 Interactive Viewing & Data Grid Suite
|
|
167
|
+
|
|
168
|
+
When querying wide enterprise tables with 20 to 60+ columns, DB-Agent provides 5 flexible viewing tools:
|
|
169
|
+
|
|
170
|
+
| View Mode | In-Chat Command | Description |
|
|
171
|
+
|---|---|---|
|
|
172
|
+
| **Desktop GUI Grid** | `:window` / `:grid` | Native desktop window with horizontal/vertical scrolling, live search filters, and CSV export. |
|
|
173
|
+
| **Browser Virtual Table** | `:web` / `:browser` | Self-contained HTML virtual data grid opened in default browser. |
|
|
174
|
+
| **Horizontal Column Paging**| `:page <n>` | Browse wide column sets in clean horizontal slices (`:page 1`, `:page 2`). |
|
|
175
|
+
| **Vertical Record Cards** | `:card` / `:v` | Renders rows as expanded vertical record cards. |
|
|
176
|
+
| **Responsive Zoom View** | `:wide` | Expands across full terminal width. |
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## 🛡️ 5 Operational Safety Tiers
|
|
181
|
+
|
|
182
|
+
| Mode | Reads | Writes | DDL | Confirmation | Best For |
|
|
183
|
+
| :--- | :---: | :---: | :---: | :---: | :--- |
|
|
184
|
+
| **`SAFE`** | Allowed | **Blocked** | **Blocked** | None | Read-only analysis |
|
|
185
|
+
| **`READ_ONLY`** | Allowed | **Blocked** | **Blocked** | None | **Production Environments** (5s timeout, 1,000 row cap) |
|
|
186
|
+
| **`CONFIRM`** (Default) | Allowed | Allowed | Allowed | **Required** | Day-to-day development |
|
|
187
|
+
| **`SANDBOX`** | Allowed | Uncommitted | Uncommitted | None | Dry-run testing with before/after diffs |
|
|
188
|
+
| **`ADMIN`** | Allowed | Allowed | Allowed | None | Advanced DBAs |
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## ⏪ Long-Term Post-Commit Recovery Engine
|
|
193
|
+
|
|
194
|
+
Unlike standard database transactions that only protect uncommitted sessions, DB-Agent captures **pre-write row snapshots** before modifying data:
|
|
195
|
+
|
|
196
|
+
```text
|
|
197
|
+
User: "Update inactive customers to ACTIVE where created_at > '2025-01-01'"
|
|
198
|
+
AI: Modifying 42 rows. Capturing pre-write snapshot...
|
|
199
|
+
✓ Change committed successfully (Change ID: CS-20260831-001)
|
|
200
|
+
|
|
201
|
+
... 10 days later ...
|
|
202
|
+
|
|
203
|
+
User: db-agent rollback CS-20260831-001 --db my_db
|
|
204
|
+
AI: Checking concurrency conflicts... No conflicting writes detected.
|
|
205
|
+
✓ Restored 42 rows to their exact original state.
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## ⚡ Performance Benchmarks (`db-agent benchmark`)
|
|
211
|
+
|
|
212
|
+
Reproducible benchmark metrics measured on standard hardware:
|
|
213
|
+
|
|
214
|
+
```text
|
|
215
|
+
Benchmark Category Latency / Metric Rating
|
|
216
|
+
─────────────────────────────────────────────────────────────────────────────
|
|
217
|
+
Cold Schema Scan (6 tables) 12.4 ms ⚡ Ultra Fast (<50ms)
|
|
218
|
+
Cached Schema Load 0.08 ms ⚡ Sub-Millisecond
|
|
219
|
+
Schema Cache Speedup 155x faster 🚀 Verified
|
|
220
|
+
BFS Multi-Hop Join Routing (3 hops) 0.15 ms ⚡ Sub-Millisecond
|
|
221
|
+
Query Result Cache Hit 0.02 ms ⚡ Instant
|
|
222
|
+
Process Memory Footprint 28.4 MB 🟢 Lightweight
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Run benchmarks locally:
|
|
226
|
+
```bash
|
|
227
|
+
db-agent benchmark
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## 🔌 Plugin & Extensibility Architecture
|
|
233
|
+
|
|
234
|
+
Extend DB-Agent with custom database connectors or AI providers via standard Python entry points:
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
# my_connector.py
|
|
238
|
+
from dbagent.connectors.base import BaseConnector
|
|
239
|
+
|
|
240
|
+
class ClickHouseConnector(BaseConnector):
|
|
241
|
+
# Implement test_connection, inspect_schema, execute_query
|
|
242
|
+
pass
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
In your package `pyproject.toml`:
|
|
246
|
+
```toml
|
|
247
|
+
[project.entry-points."dbagent.connectors"]
|
|
248
|
+
clickhouse = "my_package:ClickHouseConnector"
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## 📖 CLI Command Reference
|
|
254
|
+
|
|
255
|
+
| Command | Usage | Description |
|
|
256
|
+
| :--- | :--- | :--- |
|
|
257
|
+
| `demo` | `db-agent demo` | Instant zero-setup trial on sample e-commerce database. |
|
|
258
|
+
| `ask` | `db-agent ask "prompt" --db alias` | Translates natural language to SQL and executes. |
|
|
259
|
+
| `chat` | `db-agent chat --db alias` | Interactive AI copilot terminal REPL shell. |
|
|
260
|
+
| `connect` | `db-agent connect <url> --alias name`| Tests credentials and saves database profile. |
|
|
261
|
+
| `doctor` | `db-agent doctor --db alias` | Runs connectivity, schema, index, and latency health checks. |
|
|
262
|
+
| `benchmark`| `db-agent benchmark` | Runs reproducible latency and memory benchmark suite. |
|
|
263
|
+
| `examples` | `db-agent examples` | Displays categorized copy-paste prompt recipes. |
|
|
264
|
+
| `rollback` | `db-agent rollback <id>` | Safely reverts post-commit write changes. |
|
|
265
|
+
| `changes` | `db-agent changes` | Lists recorded write ChangeSets and recovery status. |
|
|
266
|
+
| `scan` | `db-agent scan --db alias -o doc.md`| Introspects full schema and exports Markdown data catalog. |
|
|
267
|
+
| `optimize` | `db-agent optimize "<sql>"` | Analyzes EXPLAIN query plan and suggests indexes. |
|
|
268
|
+
| `path` | `db-agent path table1 table2` | Finds shortest foreign-key join path between tables. |
|
|
269
|
+
| `define` | `db-agent define term "definition"` | Teaches business terminology to semantic dictionary. |
|
|
270
|
+
| `setup` | `db-agent setup` | 1-Click AI configuration wizard. |
|
|
271
|
+
| `use` | `db-agent use <provider>` | Switches active AI provider (`claude`, `openai`, `gemini`, `ollama`...). |
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## 🔒 Privacy & Security First
|
|
276
|
+
|
|
277
|
+
- **Zero Credentials Sent to AI**: DB hostnames, usernames, passwords, and data rows **never** leave your machine. Only schema DDL is sent to the LLM.
|
|
278
|
+
- **100% Offline with Ollama**: Run completely air-gapped with local LLMs.
|
|
279
|
+
- **Sensitive Data Masking**: Automatic regex masking of emails (`a***@b.com`), passwords (`**********`), and cards.
|
|
280
|
+
- **Append-Only Audit Logs**: Records all queries and execution durations in `~/.dbagent/audit.jsonl`.
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## 📄 License & Community
|
|
285
|
+
|
|
286
|
+
- **License**: [MIT License](LICENSE)
|
|
287
|
+
- **Author**: Santhosh Gupta
|
|
288
|
+
- **Documentation & Recipes**: [examples/](examples/)
|
|
289
|
+
- **Contributing**: [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
290
|
+
- **Security Policy**: [SECURITY.md](SECURITY.md)
|
|
291
|
+
- **Privacy Policy**: [PRIVACY.md](PRIVACY.md)
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# ⚡ DB-Agent (`dbagent-cli`)
|
|
2
|
+
|
|
3
|
+
> **The Privacy-First AI Database Copilot, Schema Graph Introspector & Post-Commit Recovery Engine**
|
|
4
|
+
> *Author: Santhosh Gupta | 100% Free, Standalone, Works 100% Offline (Ollama) or with Cloud AI (Claude 3.7 / GPT-4o / DeepSeek / Gemini / Groq).*
|
|
5
|
+
|
|
6
|
+
[](https://pypi.org/project/dbagent-cli/)
|
|
7
|
+
[](https://pypi.org/project/dbagent-cli/)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
[](https://pypi.org/project/dbagent-cli/)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 🌟 What is DB-Agent?
|
|
14
|
+
|
|
15
|
+
**DB-Agent** is an enterprise-ready, privacy-first database AI copilot that translates plain English into dialect-precise SQL, explores schemas on-demand (<30ms), enforces strict multi-tier safety guardrails, and captures pre-write snapshots allowing you to safely rollback database modifications days or weeks after `COMMIT`.
|
|
16
|
+
|
|
17
|
+
```text
|
|
18
|
+
"Show me the top 10 customers by order value"
|
|
19
|
+
↓
|
|
20
|
+
[ DB-Agent CLI Engine ]
|
|
21
|
+
(Targeted Schema Sub-Graph + AST Safety)
|
|
22
|
+
↓
|
|
23
|
+
SELECT c.customer_id, c.first_name, SUM(o.total_amount) AS total_spend
|
|
24
|
+
FROM customers c
|
|
25
|
+
JOIN orders o ON c.customer_id = o.customer_id
|
|
26
|
+
GROUP BY c.customer_id, c.first_name
|
|
27
|
+
ORDER BY total_spend DESC LIMIT 10;
|
|
28
|
+
↓
|
|
29
|
+
⚡ Executed in 0.4s
|
|
30
|
+
┌─────────────┬────────────┬─────────────┐
|
|
31
|
+
│ customer_id │ first_name │ total_spend │
|
|
32
|
+
├─────────────┼────────────┼─────────────┤
|
|
33
|
+
│ 1 │ Alice │ $3,450.00 │
|
|
34
|
+
│ 3 │ Claire │ $2,198.50 │
|
|
35
|
+
└─────────────┴────────────┴─────────────┘
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 🚀 5-Second Instant Trial (Zero Setup Required)
|
|
41
|
+
|
|
42
|
+
Want to test DB-Agent without configuring a database or API keys?
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# 1. Install DB-Agent
|
|
46
|
+
pip install "dbagent-cli[all]"
|
|
47
|
+
|
|
48
|
+
# 2. Launch built-in demo e-commerce database with interactive AI copilot
|
|
49
|
+
db-agent demo
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## ⚡ 3-Minute Quickstart
|
|
55
|
+
|
|
56
|
+
### 1. Install
|
|
57
|
+
```bash
|
|
58
|
+
pip install --upgrade "dbagent-cli[all]"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 2. Configure AI Backend (1-Click Setup)
|
|
62
|
+
```bash
|
|
63
|
+
db-agent setup
|
|
64
|
+
```
|
|
65
|
+
Choose from 8 built-in providers:
|
|
66
|
+
- **Local Ollama** (100% private, 100% offline with `qwen2.5-coder`, `llama3.3`, `deepseek-r1`)
|
|
67
|
+
- **Google Gemini** (`gemini-3.6-flash`, `gemini-2.5-flash`)
|
|
68
|
+
- **Anthropic Claude** (`claude-3-7-sonnet-20250219`, `claude-3-5-sonnet`)
|
|
69
|
+
- **OpenAI ChatGPT** (`gpt-4o`, `gpt-4.5-preview`, `o3-mini`)
|
|
70
|
+
- **DeepSeek AI** (`deepseek-chat` V3, `deepseek-reasoner` R1)
|
|
71
|
+
- **Mistral AI** (`codestral-latest`, `mistral-large-latest`)
|
|
72
|
+
- **Groq** (`llama-3.3-70b-versatile`)
|
|
73
|
+
- **OpenRouter** (`meta-llama/llama-3.3-70b-instruct`)
|
|
74
|
+
|
|
75
|
+
### 3. Connect Your Database
|
|
76
|
+
```bash
|
|
77
|
+
# Interactive guided connection
|
|
78
|
+
db-agent connect
|
|
79
|
+
|
|
80
|
+
# Or connect directly with an alias
|
|
81
|
+
db-agent connect postgresql://user:password@localhost:5432/app_db --alias prod_db
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 4. Ask Plain English Questions
|
|
85
|
+
```bash
|
|
86
|
+
# One-off query:
|
|
87
|
+
db-agent ask "count active users grouped by country" --db prod_db
|
|
88
|
+
|
|
89
|
+
# CI/CD machine-readable JSON export:
|
|
90
|
+
db-agent ask "count orders by status" --db prod_db --format json
|
|
91
|
+
|
|
92
|
+
# Interactive Claude-Style Shell with live streaming & prompt queuing:
|
|
93
|
+
db-agent chat --db prod_db
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## 📊 Database Compatibility Matrix
|
|
99
|
+
|
|
100
|
+
| Database Engine | Introspection | Direct Queries | Multi-Hop JOINs | Transactions | 30-Day Recovery | Status |
|
|
101
|
+
| :--- | :---: | :---: | :---: | :---: | :---: | :--- |
|
|
102
|
+
| **PostgreSQL / CockroachDB** | ✓ | ✓ | ✓ | ✓ | ✓ | **Fully Supported** |
|
|
103
|
+
| **MySQL / MariaDB** | ✓ | ✓ | ✓ | ✓ | ✓ | **Fully Supported** |
|
|
104
|
+
| **SQLite** | ✓ | ✓ | ✓ | ✓ | ✓ | **Fully Supported** |
|
|
105
|
+
| **DuckDB** | ✓ | ✓ | ✓ | ✓ | ✓ | **Fully Supported** |
|
|
106
|
+
| **Microsoft SQL Server** | ✓ | ✓ | ✓ | ✓ | ✓ | **Fully Supported** |
|
|
107
|
+
| **Oracle Database** | ✓ | ✓ | ✓ | ✓ | ✓ | **Fully Supported** |
|
|
108
|
+
| **MongoDB** | ✓ (JSON) | ✓ (Filters) | N/A | ✓ | N/A | **Document Supported** |
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## 🪟 Interactive Viewing & Data Grid Suite
|
|
113
|
+
|
|
114
|
+
When querying wide enterprise tables with 20 to 60+ columns, DB-Agent provides 5 flexible viewing tools:
|
|
115
|
+
|
|
116
|
+
| View Mode | In-Chat Command | Description |
|
|
117
|
+
|---|---|---|
|
|
118
|
+
| **Desktop GUI Grid** | `:window` / `:grid` | Native desktop window with horizontal/vertical scrolling, live search filters, and CSV export. |
|
|
119
|
+
| **Browser Virtual Table** | `:web` / `:browser` | Self-contained HTML virtual data grid opened in default browser. |
|
|
120
|
+
| **Horizontal Column Paging**| `:page <n>` | Browse wide column sets in clean horizontal slices (`:page 1`, `:page 2`). |
|
|
121
|
+
| **Vertical Record Cards** | `:card` / `:v` | Renders rows as expanded vertical record cards. |
|
|
122
|
+
| **Responsive Zoom View** | `:wide` | Expands across full terminal width. |
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 🛡️ 5 Operational Safety Tiers
|
|
127
|
+
|
|
128
|
+
| Mode | Reads | Writes | DDL | Confirmation | Best For |
|
|
129
|
+
| :--- | :---: | :---: | :---: | :---: | :--- |
|
|
130
|
+
| **`SAFE`** | Allowed | **Blocked** | **Blocked** | None | Read-only analysis |
|
|
131
|
+
| **`READ_ONLY`** | Allowed | **Blocked** | **Blocked** | None | **Production Environments** (5s timeout, 1,000 row cap) |
|
|
132
|
+
| **`CONFIRM`** (Default) | Allowed | Allowed | Allowed | **Required** | Day-to-day development |
|
|
133
|
+
| **`SANDBOX`** | Allowed | Uncommitted | Uncommitted | None | Dry-run testing with before/after diffs |
|
|
134
|
+
| **`ADMIN`** | Allowed | Allowed | Allowed | None | Advanced DBAs |
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## ⏪ Long-Term Post-Commit Recovery Engine
|
|
139
|
+
|
|
140
|
+
Unlike standard database transactions that only protect uncommitted sessions, DB-Agent captures **pre-write row snapshots** before modifying data:
|
|
141
|
+
|
|
142
|
+
```text
|
|
143
|
+
User: "Update inactive customers to ACTIVE where created_at > '2025-01-01'"
|
|
144
|
+
AI: Modifying 42 rows. Capturing pre-write snapshot...
|
|
145
|
+
✓ Change committed successfully (Change ID: CS-20260831-001)
|
|
146
|
+
|
|
147
|
+
... 10 days later ...
|
|
148
|
+
|
|
149
|
+
User: db-agent rollback CS-20260831-001 --db my_db
|
|
150
|
+
AI: Checking concurrency conflicts... No conflicting writes detected.
|
|
151
|
+
✓ Restored 42 rows to their exact original state.
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## ⚡ Performance Benchmarks (`db-agent benchmark`)
|
|
157
|
+
|
|
158
|
+
Reproducible benchmark metrics measured on standard hardware:
|
|
159
|
+
|
|
160
|
+
```text
|
|
161
|
+
Benchmark Category Latency / Metric Rating
|
|
162
|
+
─────────────────────────────────────────────────────────────────────────────
|
|
163
|
+
Cold Schema Scan (6 tables) 12.4 ms ⚡ Ultra Fast (<50ms)
|
|
164
|
+
Cached Schema Load 0.08 ms ⚡ Sub-Millisecond
|
|
165
|
+
Schema Cache Speedup 155x faster 🚀 Verified
|
|
166
|
+
BFS Multi-Hop Join Routing (3 hops) 0.15 ms ⚡ Sub-Millisecond
|
|
167
|
+
Query Result Cache Hit 0.02 ms ⚡ Instant
|
|
168
|
+
Process Memory Footprint 28.4 MB 🟢 Lightweight
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Run benchmarks locally:
|
|
172
|
+
```bash
|
|
173
|
+
db-agent benchmark
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## 🔌 Plugin & Extensibility Architecture
|
|
179
|
+
|
|
180
|
+
Extend DB-Agent with custom database connectors or AI providers via standard Python entry points:
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
# my_connector.py
|
|
184
|
+
from dbagent.connectors.base import BaseConnector
|
|
185
|
+
|
|
186
|
+
class ClickHouseConnector(BaseConnector):
|
|
187
|
+
# Implement test_connection, inspect_schema, execute_query
|
|
188
|
+
pass
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
In your package `pyproject.toml`:
|
|
192
|
+
```toml
|
|
193
|
+
[project.entry-points."dbagent.connectors"]
|
|
194
|
+
clickhouse = "my_package:ClickHouseConnector"
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## 📖 CLI Command Reference
|
|
200
|
+
|
|
201
|
+
| Command | Usage | Description |
|
|
202
|
+
| :--- | :--- | :--- |
|
|
203
|
+
| `demo` | `db-agent demo` | Instant zero-setup trial on sample e-commerce database. |
|
|
204
|
+
| `ask` | `db-agent ask "prompt" --db alias` | Translates natural language to SQL and executes. |
|
|
205
|
+
| `chat` | `db-agent chat --db alias` | Interactive AI copilot terminal REPL shell. |
|
|
206
|
+
| `connect` | `db-agent connect <url> --alias name`| Tests credentials and saves database profile. |
|
|
207
|
+
| `doctor` | `db-agent doctor --db alias` | Runs connectivity, schema, index, and latency health checks. |
|
|
208
|
+
| `benchmark`| `db-agent benchmark` | Runs reproducible latency and memory benchmark suite. |
|
|
209
|
+
| `examples` | `db-agent examples` | Displays categorized copy-paste prompt recipes. |
|
|
210
|
+
| `rollback` | `db-agent rollback <id>` | Safely reverts post-commit write changes. |
|
|
211
|
+
| `changes` | `db-agent changes` | Lists recorded write ChangeSets and recovery status. |
|
|
212
|
+
| `scan` | `db-agent scan --db alias -o doc.md`| Introspects full schema and exports Markdown data catalog. |
|
|
213
|
+
| `optimize` | `db-agent optimize "<sql>"` | Analyzes EXPLAIN query plan and suggests indexes. |
|
|
214
|
+
| `path` | `db-agent path table1 table2` | Finds shortest foreign-key join path between tables. |
|
|
215
|
+
| `define` | `db-agent define term "definition"` | Teaches business terminology to semantic dictionary. |
|
|
216
|
+
| `setup` | `db-agent setup` | 1-Click AI configuration wizard. |
|
|
217
|
+
| `use` | `db-agent use <provider>` | Switches active AI provider (`claude`, `openai`, `gemini`, `ollama`...). |
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## 🔒 Privacy & Security First
|
|
222
|
+
|
|
223
|
+
- **Zero Credentials Sent to AI**: DB hostnames, usernames, passwords, and data rows **never** leave your machine. Only schema DDL is sent to the LLM.
|
|
224
|
+
- **100% Offline with Ollama**: Run completely air-gapped with local LLMs.
|
|
225
|
+
- **Sensitive Data Masking**: Automatic regex masking of emails (`a***@b.com`), passwords (`**********`), and cards.
|
|
226
|
+
- **Append-Only Audit Logs**: Records all queries and execution durations in `~/.dbagent/audit.jsonl`.
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## 📄 License & Community
|
|
231
|
+
|
|
232
|
+
- **License**: [MIT License](LICENSE)
|
|
233
|
+
- **Author**: Santhosh Gupta
|
|
234
|
+
- **Documentation & Recipes**: [examples/](examples/)
|
|
235
|
+
- **Contributing**: [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
236
|
+
- **Security Policy**: [SECURITY.md](SECURITY.md)
|
|
237
|
+
- **Privacy Policy**: [PRIVACY.md](PRIVACY.md)
|
|
@@ -53,6 +53,10 @@ class DatabaseDoctor:
|
|
|
53
53
|
llm_provider: Optional[BaseLLMProvider] = None,
|
|
54
54
|
security_mode: str = "CONFIRM",
|
|
55
55
|
) -> DoctorReport:
|
|
56
|
+
import sys
|
|
57
|
+
from pathlib import Path
|
|
58
|
+
from dbagent import __version__
|
|
59
|
+
|
|
56
60
|
t0 = time.time()
|
|
57
61
|
success, msg = connector.test_connection()
|
|
58
62
|
conn_latency_ms = (time.time() - t0) * 1000
|
|
@@ -65,6 +69,32 @@ class DatabaseDoctor:
|
|
|
65
69
|
|
|
66
70
|
report = DoctorReport(database_name=db_name, dialect=dialect)
|
|
67
71
|
|
|
72
|
+
# 0. Runtime Environment & Permissions
|
|
73
|
+
py_ver = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
|
|
74
|
+
report.checks.append(DiagnosticCheck(
|
|
75
|
+
name="Runtime & CLI",
|
|
76
|
+
status="OK",
|
|
77
|
+
message=f"Python {py_ver} • dbagent-cli v{__version__}",
|
|
78
|
+
))
|
|
79
|
+
|
|
80
|
+
# Check local directories
|
|
81
|
+
home_dbagent = Path.home() / ".dbagent"
|
|
82
|
+
try:
|
|
83
|
+
home_dbagent.mkdir(parents=True, exist_ok=True)
|
|
84
|
+
(home_dbagent / ".perm_check").write_text("ok", encoding="utf-8")
|
|
85
|
+
(home_dbagent / ".perm_check").unlink()
|
|
86
|
+
report.checks.append(DiagnosticCheck(
|
|
87
|
+
name="Storage & Cache Permissions",
|
|
88
|
+
status="OK",
|
|
89
|
+
message=f"Directory '{home_dbagent}' is writable",
|
|
90
|
+
))
|
|
91
|
+
except Exception as e:
|
|
92
|
+
report.checks.append(DiagnosticCheck(
|
|
93
|
+
name="Storage & Cache Permissions",
|
|
94
|
+
status="WARN",
|
|
95
|
+
message=f"Directory permission warning: {str(e)}",
|
|
96
|
+
))
|
|
97
|
+
|
|
68
98
|
# 1. Connection check
|
|
69
99
|
if success:
|
|
70
100
|
report.checks.append(DiagnosticCheck(
|
|
@@ -59,6 +59,10 @@ Generate ONLY the raw executable SQL query for the given database. No markdown f
|
|
|
59
59
|
- Check the column data type and sample values shown in the schema.
|
|
60
60
|
- If the column is VARCHAR(1) or CHAR(1) or text, check if values use 'Y'/'N', 'YES'/'NO', '1'/'0', 'ACTIVE'/'INACTIVE', 'TRUE'/'FALSE'.
|
|
61
61
|
- If sample values show 'Y'/'N' (or if it's a single-character VARCHAR/CHAR column), use `active = 'Y'` or `active IN ('Y', '1', 'true', 'TRUE')` for active/enabled status.
|
|
62
|
+
10. For Deletions & Cascading Mapping Cleanup (when deleting a record/user without foreign key constraint violations):
|
|
63
|
+
- For PostgreSQL: Use a single Common Table Expression (CTE) with data-modifying statements deleting from all child, mapping, activity, profile, and preference tables first, and finally deleting from the parent table (e.g. `WITH target AS (SELECT pk_user_id FROM ivis_user WHERE ...), del_act AS (DELETE FROM user_activity WHERE user_id IN (SELECT pk_user_id FROM target)), del_map AS (DELETE FROM ivis_user_access WHERE fk_user_id IN (SELECT pk_user_id FROM target)) DELETE FROM ivis_user WHERE pk_user_id IN (SELECT pk_user_id FROM target);`).
|
|
64
|
+
- For MySQL / SQLite: Generate clean, ordered DELETE statements deleting referencing child records before the parent record.
|
|
65
|
+
- Always delete from all referencing tables present in the schema to avoid foreign key violations.
|
|
62
66
|
"""
|
|
63
67
|
|
|
64
68
|
|
|
@@ -160,6 +160,9 @@ class QueryPipeline:
|
|
|
160
160
|
|
|
161
161
|
# 2. Targeted on-demand table introspection with automatic junction expansion
|
|
162
162
|
target_names = list(set(exact + fuzzy))
|
|
163
|
+
is_delete_or_mapping = any(w in user_prompt.lower() for w in ["delete", "remove", "drop", "cascade", "mapping", "map", "link", "clean", "without any mappings"])
|
|
164
|
+
max_tables_limit = 25 if is_delete_or_mapping else 12
|
|
165
|
+
|
|
163
166
|
if target_names:
|
|
164
167
|
try:
|
|
165
168
|
all_table_names = self.connector.get_table_names()
|
|
@@ -174,24 +177,29 @@ class QueryPipeline:
|
|
|
174
177
|
t_lower = t.lower()
|
|
175
178
|
if t in target_names:
|
|
176
179
|
continue
|
|
177
|
-
is_map = any(m in t_lower for m in ["_map", "mapping", "_rel", "_junction", "_link", "_access", "_config"])
|
|
180
|
+
is_map = any(m in t_lower for m in ["_map", "mapping", "_rel", "_junction", "_link", "_access", "_config", "_preference", "_profile", "_activity", "_log"])
|
|
178
181
|
matches_stem = any(s in t_lower for s in stems)
|
|
179
|
-
if
|
|
180
|
-
if
|
|
181
|
-
target_names
|
|
182
|
-
|
|
182
|
+
if is_delete_or_mapping:
|
|
183
|
+
if matches_stem or (is_map and matches_stem) or sum(1 for s in stems if s in t_lower) >= 1:
|
|
184
|
+
if t not in target_names:
|
|
185
|
+
target_names.append(t)
|
|
186
|
+
else:
|
|
187
|
+
if (is_map and matches_stem) or sum(1 for s in stems if s in t_lower) >= 2:
|
|
188
|
+
if t not in target_names:
|
|
189
|
+
target_names.append(t)
|
|
190
|
+
if len(target_names) >= max_tables_limit:
|
|
183
191
|
break
|
|
184
192
|
except Exception:
|
|
185
193
|
pass
|
|
186
194
|
|
|
187
195
|
targeted = self.connector.inspect_schema(table_names=target_names, include_samples=True, max_samples=2)
|
|
188
196
|
retriever = ContextRetriever(targeted)
|
|
189
|
-
return retriever.retrieve_context(user_prompt, exact_tables=exact, fuzzy_tables=fuzzy, max_tables=
|
|
197
|
+
return retriever.retrieve_context(user_prompt, exact_tables=exact, fuzzy_tables=fuzzy, max_tables=max_tables_limit)
|
|
190
198
|
|
|
191
199
|
# 3. Fallback: inspect targeted
|
|
192
|
-
targeted = self.connector.inspect_targeted(user_prompt, max_tables=
|
|
200
|
+
targeted = self.connector.inspect_targeted(user_prompt, max_tables=max_tables_limit, include_samples=True)
|
|
193
201
|
retriever = ContextRetriever(targeted)
|
|
194
|
-
return retriever.retrieve_context(user_prompt, exact_tables=exact, fuzzy_tables=fuzzy, max_tables=
|
|
202
|
+
return retriever.retrieve_context(user_prompt, exact_tables=exact, fuzzy_tables=fuzzy, max_tables=max_tables_limit)
|
|
195
203
|
|
|
196
204
|
def run(
|
|
197
205
|
self,
|