@carllee1983/dbcli 0.3.2-beta → 0.5.0-beta

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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,31 @@ All notable changes to dbcli are documented here.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.5.0-beta] - 2026-03-27
9
+
10
+ ### UX & Developer Experience — Colors, Logging, Diagnostics, and Tooling
11
+
12
+ ### Added
13
+
14
+ - **Color system** (`picocolors`): Semantic color helpers (`success`/`error`/`warn`/`info`/`dim`/`bold`) with automatic `NO_COLOR` support
15
+ - **SQL syntax highlighting**: Keywords (blue bold), strings (green), numbers (yellow) — applied in verbose mode and dry-run preview
16
+ - **Leveled logger**: Four levels — quiet (`-q`), normal (default), verbose (`-v`), debug (`-vv`) — all output to stderr to keep stdout clean for structured data
17
+ - **`--no-color` global flag**: Disable colored output; also respects `NO_COLOR` environment variable (<https://no-color.org/>)
18
+ - **`-v, --verbose` global flag**: Increase verbosity (`-v` = verbose, `-vv` = debug)
19
+ - **`-q, --quiet` global flag**: Suppress non-essential output
20
+ - **`dbcli doctor` command**: Full self-diagnostic — checks Bun version, dbcli version (npm registry), config validity, permission level, blacklist completeness (detects unprotected sensitive columns like `password`/`token`/`secret`), database connectivity, schema cache freshness, and large table warnings (> 1M rows). Supports `--format json` for AI agents. Exits with code 1 on errors.
21
+ - **`dbcli completion` command**: Shell auto-completion script generation for bash, zsh, and fish. `--install` flag auto-writes to the shell rc file using idempotent marker blocks.
22
+ - **`dbcli upgrade` command**: Self-update from npm registry. `--check` flag for check-only mode.
23
+ - **Background version check**: Every command silently checks the npm registry (at most once per 24 hours, cached in `.dbcli/version-check.json`). Shows a one-line hint to stderr after the command completes if a newer version is available. Suppressed by `--quiet`.
24
+ - **Table formatter colorization**: Table headers now display in bold
25
+ - **62 new tests**: colors (7), sql-highlight (6), logger (10), doctor (12), completion (8), upgrade/version-check (19)
26
+
27
+ ### Dependencies
28
+
29
+ - Added `picocolors` (~0.4 KB) as production dependency
30
+
31
+ ---
32
+
8
33
  ## [0.2.0-beta] - 2026-03-26
9
34
 
10
35
  ### Data Access Control — Blacklist System
package/README.md CHANGED
@@ -49,6 +49,10 @@ npx @carllee1983/dbcli query "SELECT * FROM users"
49
49
  #### Update
50
50
 
51
51
  ```bash
52
+ # Self-update (recommended)
53
+ dbcli upgrade
54
+
55
+ # Or via npm
52
56
  npm update -g @carllee1983/dbcli
53
57
  ```
54
58
 
@@ -438,6 +442,68 @@ DBCLI_OVERRIDE_BLACKLIST=true dbcli query "SELECT * FROM secrets_vault"
438
442
 
439
443
  ---
440
444
 
445
+ #### `dbcli doctor`
446
+
447
+ Run diagnostic checks on environment, configuration, connection, and data.
448
+
449
+ ```bash
450
+ dbcli doctor # Colored text output
451
+ dbcli doctor --format json # JSON output for AI agents
452
+ ```
453
+
454
+ **Checks:**
455
+ - **Environment:** Bun version compatibility, dbcli version (compares with npm registry)
456
+ - **Configuration:** Config file exists/valid, permission level, blacklist completeness
457
+ - **Connection & Data:** Database connectivity, schema cache freshness (> 7 days warning), large table warnings (> 1M rows)
458
+
459
+ **Options:** `--format <text|json>`
460
+ **Exit code:** 0 = all pass or warnings only, 1 = errors found
461
+
462
+ ---
463
+
464
+ #### `dbcli completion [shell]`
465
+
466
+ Generate shell completion scripts for tab auto-complete.
467
+
468
+ ```bash
469
+ dbcli completion bash # Output bash completion to stdout
470
+ dbcli completion zsh # Output zsh completion to stdout
471
+ dbcli completion fish # Output fish completion to stdout
472
+ dbcli completion --install # Auto-detect shell and install to rc file
473
+ dbcli completion --install zsh # Install for specific shell
474
+ ```
475
+
476
+ **Supported shells:** bash, zsh, fish
477
+
478
+ ---
479
+
480
+ #### `dbcli upgrade`
481
+
482
+ Check for updates and self-upgrade dbcli.
483
+
484
+ ```bash
485
+ dbcli upgrade # Check and upgrade if newer version available
486
+ dbcli upgrade --check # Only check, do not upgrade
487
+ ```
488
+
489
+ **Options:** `--check` — check only, don't install
490
+ **Background check:** dbcli silently checks npm registry once per 24 hours. If a newer version is found, a hint is shown after command output.
491
+
492
+ ---
493
+
494
+ ## Global Options
495
+
496
+ All commands support these global options:
497
+
498
+ | Flag | Description |
499
+ |------|-------------|
500
+ | `--config <path>` | Path to .dbcli config file (default: `.dbcli`) |
501
+ | `-v, --verbose` | Increase verbosity (`-v` verbose, `-vv` debug) |
502
+ | `-q, --quiet` | Suppress non-essential output |
503
+ | `--no-color` | Disable colored output (respects `NO_COLOR` env var) |
504
+
505
+ ---
506
+
441
507
  ## Permission Model
442
508
 
443
509
  dbcli implements a coarse-grained permission system with three levels. Permission level is set during `dbcli init` and stored in `.dbcli` config file. The blacklist system works alongside permissions to provide fine-grained protection for sensitive tables and columns (see [Data Access Control](#data-access-control)).
package/README.zh-TW.md CHANGED
@@ -29,11 +29,11 @@ npm install --save-dev @carllee1983/dbcli
29
29
  ### 更新
30
30
 
31
31
  ```bash
32
- # Bun
33
- bun update @carllee1983/dbcli
32
+ # 自動更新(推薦)
33
+ dbcli upgrade
34
34
 
35
- # npm
36
- npm update --save-dev @carllee1983/dbcli
35
+ # 或手動更新
36
+ bun update @carllee1983/dbcli
37
37
  ```
38
38
 
39
39
  ### 初始化
@@ -142,6 +142,12 @@ dbcli init
142
142
  - 支援跨平台 AI 代理使用(Claude Code、Gemini、Copilot CLI、Cursor、IDE)
143
143
  - 技能動態反映 dbcli 功能
144
144
 
145
+ ### 診斷與維護
146
+
147
+ - `dbcli doctor` — 執行環境、設定、連線與資料的全面診斷
148
+ - `dbcli upgrade` — 檢查更新並自動升級 dbcli
149
+ - `dbcli completion [shell]` — 產生 shell 自動補全腳本(bash、zsh、fish)
150
+
145
151
  ## 權限模型
146
152
 
147
153
  dbcli 使用三層粗粒度權限模型,並搭配黑名單系統提供敏感表和欄位的細粒度保護(見[資料存取控制](#資料存取控制)):
@@ -358,6 +364,62 @@ dbcli blacklist column remove users.ssn
358
364
  DBCLI_OVERRIDE_BLACKLIST=true dbcli query "SELECT * FROM secrets_vault"
359
365
  ```
360
366
 
367
+ #### `dbcli doctor`
368
+
369
+ 執行環境、設定、連線與資料的全面診斷。
370
+
371
+ ```bash
372
+ dbcli doctor # 彩色文字輸出
373
+ dbcli doctor --format json # JSON 輸出供 AI agent 使用
374
+ ```
375
+
376
+ **檢查項目:**
377
+ - **環境:** Bun 版本相容性、dbcli 版本(與 npm registry 比對)
378
+ - **設定:** 設定檔存在/合法、權限等級、blacklist 完整性
379
+ - **連線與資料:** 資料庫連線測試、schema cache 新鮮度(> 7 天警告)、大表警告(> 1M 列)
380
+
381
+ **選項:** `--format <text|json>`
382
+
383
+ ---
384
+
385
+ #### `dbcli completion [shell]`
386
+
387
+ 產生 shell 自動補全腳本。
388
+
389
+ ```bash
390
+ dbcli completion bash # 輸出 bash 補全腳本
391
+ dbcli completion zsh # 輸出 zsh 補全腳本
392
+ dbcli completion fish # 輸出 fish 補全腳本
393
+ dbcli completion --install # 自動偵測 shell 並安裝
394
+ dbcli completion --install zsh # 指定 shell 安裝
395
+ ```
396
+
397
+ **支援 shell:** bash、zsh、fish
398
+
399
+ ---
400
+
401
+ #### `dbcli upgrade`
402
+
403
+ 檢查更新並自動升級 dbcli。
404
+
405
+ ```bash
406
+ dbcli upgrade # 檢查並升級
407
+ dbcli upgrade --check # 僅檢查,不升級
408
+ ```
409
+
410
+ **背景檢查:** 每個指令靜默檢查 npm registry(每 24 小時一次),有新版時在指令完成後顯示提示。
411
+
412
+ ## 全域選項
413
+
414
+ 以下選項適用於所有指令:
415
+
416
+ | 選項 | 說明 |
417
+ |------|------|
418
+ | `--config <path>` | 指定 .dbcli 設定檔路徑(預設:`.dbcli`) |
419
+ | `-v, --verbose` | 增加輸出詳細度(`-v` 詳細、`-vv` 除錯) |
420
+ | `-q, --quiet` | 靜音模式,抑制非必要輸出 |
421
+ | `--no-color` | 關閉彩色輸出(支援 `NO_COLOR` 環境變數) |
422
+
361
423
  ## 環境配置
362
424
 
363
425
  ### .dbcli 配置檔案
@@ -0,0 +1,376 @@
1
+ ---
2
+ name: dbcli
3
+ description: Database CLI for AI agents with permission-based access control. Use to query, inspect schemas, insert/update/delete data, export results, and manage sensitive data blacklists. Supports MySQL, PostgreSQL, MariaDB. Trigger when working with databases, running SQL, exploring table structures, or protecting sensitive columns/tables from AI access.
4
+ ---
5
+
6
+ # dbcli
7
+
8
+ Database CLI for AI agents with permission-based access control.
9
+
10
+ ## Quick Start
11
+
12
+ ```bash
13
+ dbcli init # Initialize .dbcli config (parses .env automatically)
14
+ dbcli schema # Scan all tables and save to .dbcli
15
+ dbcli query "SELECT * FROM users" # Execute SQL
16
+ ```
17
+
18
+ ## Commands
19
+
20
+ ### init
21
+
22
+ Initialize `.dbcli` configuration file. Typically run manually by the developer — avoid running on behalf of the user unless explicitly requested.
23
+
24
+ ```bash
25
+ dbcli init
26
+ dbcli init --system mysql --host localhost --port 3306 --user root --name mydb
27
+ dbcli init --use-env-refs # Store env var references instead of values
28
+ dbcli init --no-interactive --force # Non-interactive, skip overwrite confirmation
29
+ ```
30
+
31
+ **Key options:** `--system <postgresql|mysql|mariadb>`, `--permission <query-only|read-write|data-admin|admin>`, `--use-env-refs`, `--skip-test`, `--no-interactive`, `--force`
32
+
33
+ ### list
34
+
35
+ List all tables.
36
+
37
+ ```bash
38
+ dbcli list
39
+ dbcli list --format json
40
+ ```
41
+
42
+ **Permission:** query-only+
43
+
44
+ ### schema
45
+
46
+ Display table schema or scan entire database.
47
+
48
+ ```bash
49
+ dbcli schema # Scan all tables, save to .dbcli
50
+ dbcli schema users # Show single table schema
51
+ dbcli schema users --format json
52
+ dbcli schema --refresh # Detect and apply schema changes
53
+ dbcli schema --reset # Clear all schema data and re-fetch
54
+ dbcli schema --reset --force # Skip confirmation
55
+ ```
56
+
57
+ **Options:** `--format <table|json>`, `--refresh`, `--reset`, `--force`
58
+ **Permission:** query-only+
59
+
60
+ ### query
61
+
62
+ Execute SQL query.
63
+
64
+ ```bash
65
+ dbcli query "SELECT * FROM users LIMIT 10"
66
+ dbcli query "SELECT id, email FROM users" --format json
67
+ dbcli query "SELECT * FROM logs" --no-limit
68
+ ```
69
+
70
+ **Options:** `--format <table|json|csv>`, `--limit <number>`, `--no-limit`
71
+ **Permission:** query-only+
72
+
73
+ ### insert
74
+
75
+ Insert data into a table.
76
+
77
+ ```bash
78
+ dbcli insert users --data '{"name":"Alice","email":"alice@example.com"}'
79
+ dbcli insert users --data '{"name":"Alice"}' --dry-run
80
+ dbcli insert users --data '{"name":"Alice"}' --force
81
+ ```
82
+
83
+ **Options:** `--data <json>`, `--dry-run`, `--force`
84
+ **Permission:** read-write+
85
+
86
+ ### update
87
+
88
+ Update existing data.
89
+
90
+ ```bash
91
+ dbcli update users --where "id=1" --set '{"name":"Bob"}'
92
+ dbcli update users --where "id=1" --set '{"name":"Bob"}' --dry-run
93
+ ```
94
+
95
+ **Options:** `--where <condition>` (required), `--set <json>` (required), `--dry-run`, `--force`
96
+ **Permission:** read-write+
97
+
98
+ ### delete
99
+
100
+ Delete data from a table.
101
+
102
+ ```bash
103
+ dbcli delete users --where "id=1"
104
+ dbcli delete users --where "id=1" --dry-run
105
+ dbcli delete users --where "id=1" --force
106
+ ```
107
+
108
+ **Options:** `--where <condition>` (required), `--dry-run`, `--force`
109
+ **Permission:** data-admin+
110
+
111
+ ### export
112
+
113
+ Export query results to file or stdout.
114
+
115
+ ```bash
116
+ dbcli export "SELECT * FROM users" --format csv --output users.csv
117
+ dbcli export "SELECT * FROM users" --format json | jq '.[]'
118
+ ```
119
+
120
+ **Options:** `--format <json|csv>` (required), `--output <path>`
121
+ **Permission:** query-only+
122
+
123
+ ### blacklist
124
+
125
+ Manage sensitive data blacklist to prevent AI access to restricted tables/columns.
126
+
127
+ ```bash
128
+ dbcli blacklist list # Show current blacklist
129
+ dbcli blacklist table add payments # Block entire table
130
+ dbcli blacklist table remove payments # Unblock table
131
+ dbcli blacklist column add users.password # Block specific column
132
+ dbcli blacklist column remove users.password
133
+ ```
134
+
135
+ **Subcommands:** `list`, `table add <name>`, `table remove <name>`, `column add <table.column>`, `column remove <table.column>`
136
+
137
+ ### check
138
+
139
+ Run data health checks on tables.
140
+
141
+ ```bash
142
+ dbcli check users # Check single table
143
+ dbcli check users --format json # JSON output (default)
144
+ dbcli check --all # Check all tables (huge tables auto-skipped)
145
+ dbcli check --all --include-large # Include huge tables
146
+ dbcli check orders --checks nulls,orphans # Specific checks only
147
+ dbcli check orders --sample 10000 # Sample size for large tables
148
+ ```
149
+
150
+ **Checks:** `nulls`, `duplicates`, `orphans`, `emptyStrings`, `rowCount`, `size`
151
+ **Options:** `--all`, `--include-large`, `--checks <types>`, `--sample <number>`, `--format <json|table>`
152
+ **Permission:** query-only+
153
+
154
+ ### diff
155
+
156
+ Compare schema snapshots to detect changes.
157
+
158
+ ```bash
159
+ dbcli diff --snapshot before.json # Save current schema snapshot
160
+ dbcli diff --against before.json # Compare current vs snapshot
161
+ dbcli diff --against before.json --format json
162
+ ```
163
+
164
+ **Options:** `--snapshot <path>`, `--against <path>`, `--format <json|table>`
165
+ **Permission:** query-only+
166
+
167
+ ### status
168
+
169
+ Show current configuration status (safe for AI agents, no credentials exposed).
170
+
171
+ ```bash
172
+ dbcli status # JSON output (default)
173
+ dbcli status --format text # Human-readable text output
174
+ ```
175
+
176
+ **Output:** `permission`, `system`, `blacklist` summary, `version`
177
+ **Permission:** query-only+
178
+
179
+ ### doctor
180
+
181
+ Run diagnostic checks on environment, configuration, connection, and data.
182
+
183
+ ```bash
184
+ dbcli doctor # Colored text output
185
+ dbcli doctor --format json # JSON output for AI agents
186
+ ```
187
+
188
+ **Checks:**
189
+ - Environment: Bun version, dbcli version (compares with npm registry)
190
+ - Configuration: config file exists/valid, permission level, blacklist completeness (detects unprotected sensitive columns)
191
+ - Connection & Data: database connectivity, schema cache freshness (warns if > 7 days), large table warnings (> 1M rows)
192
+
193
+ **Exit code:** 0 if all pass or warnings only, 1 if any error
194
+ **Options:** `--format <text|json>`
195
+
196
+ ### completion
197
+
198
+ Generate shell completion scripts for tab auto-complete.
199
+
200
+ ```bash
201
+ dbcli completion bash # Output bash completion script
202
+ dbcli completion zsh # Output zsh completion script
203
+ dbcli completion fish # Output fish completion script
204
+ dbcli completion --install # Auto-detect shell and install
205
+ dbcli completion --install zsh # Install for specific shell
206
+ ```
207
+
208
+ **Supported shells:** bash, zsh, fish
209
+
210
+ ### upgrade
211
+
212
+ Check for updates and self-upgrade dbcli to the latest version from npm.
213
+
214
+ ```bash
215
+ dbcli upgrade # Check and upgrade if newer version available
216
+ dbcli upgrade --check # Only check, do not upgrade
217
+ ```
218
+
219
+ **Options:** `--check`
220
+
221
+ **Background check:** Every command silently checks the npm registry for a newer version (at most once per 24 hours, cached in `.dbcli/version-check.json`). If a newer version is found, a one-line hint is printed to stderr after the command completes. Pass `-q` / `--quiet` to suppress the hint.
222
+
223
+ ## Permission Levels
224
+
225
+ | Level | Allowed Operations |
226
+ |-------|-------------------|
227
+ | query-only | SELECT, list, schema, export |
228
+ | read-write | query-only + INSERT, UPDATE |
229
+ | data-admin | read-write + DELETE (full DML, no DDL) |
230
+ | admin | data-admin + DROP, ALTER, CREATE, TRUNCATE |
231
+
232
+ Set via `dbcli init --permission <level>` or in `.dbcli` config.
233
+
234
+ ## Global Options
235
+
236
+ | Flag | Description |
237
+ |------|-------------|
238
+ | `--config <path>` | Path to .dbcli config file (default: `.dbcli`) |
239
+ | `-v, --verbose` | Increase verbosity (`-v` verbose, `-vv` debug) |
240
+ | `-q, --quiet` | Suppress non-essential output |
241
+ | `--no-color` | Disable colored output (also respects `NO_COLOR` env var) |
242
+
243
+ ## AI Agent Workflow
244
+
245
+ **Before any database operation, follow this sequence:**
246
+
247
+ 1. `dbcli status` — Check current permission level and system info (safe — no credentials exposed)
248
+ 2. `dbcli blacklist list` — Confirm sensitive data is protected
249
+ 3. `dbcli schema <table> --format json` — Verify actual column names
250
+ 4. Then execute `query` / `insert` / `update` / `export` / `delete` according to your permission level
251
+
252
+ **Never guess column names.** Naming conventions vary across projects (e.g. `frozen_balance` vs `freeze`, `amount` vs `balance_variable`). Always confirm with `schema` first.
253
+
254
+ ## Debugging Workflow
255
+
256
+ When investigating a bug related to database state:
257
+
258
+ 1. `dbcli schema <table> --format json` — Confirm actual columns and types
259
+ 2. `dbcli check <table> --format json` — Quick health scan (nulls, orphans, duplicates)
260
+ 3. `dbcli query "SELECT * FROM <table> WHERE <condition>" --format json` — Inspect the specific record
261
+ 4. Follow foreign keys from schema to trace related tables
262
+ 5. Repeat step 3 for each related table to verify referential integrity
263
+
264
+ **Key principle:** Let the data tell the story. Don't hypothesize before seeing actual state.
265
+
266
+ ## Write Verification Workflow
267
+
268
+ After any INSERT or UPDATE:
269
+
270
+ 1. `dbcli insert <table> --data '...' --dry-run` — Preview SQL first
271
+ 2. Execute the actual insert/update (remove --dry-run)
272
+ 3. `dbcli query "SELECT * FROM <table> WHERE <condition>" --format json` — Read back the written record
273
+ 4. Compare the returned data against the intended values
274
+ 5. If mismatch, check for triggers, default values, or blacklisted columns that may alter the result
275
+
276
+ ## Migration Safety Workflow
277
+
278
+ Before and after running database migrations:
279
+
280
+ 1. `dbcli diff --snapshot before.json` — Capture current schema
281
+ 2. Run the migration
282
+ 3. `dbcli diff --against before.json --format json` — Compare changes
283
+ 4. Verify: added/removed/modified columns match the migration intent
284
+ 5. `dbcli check <affected-tables> --format json` — Ensure no orphaned data from column drops or FK changes
285
+
286
+ ## Health Check Workflow
287
+
288
+ Periodic or on-demand database health scan:
289
+
290
+ 1. `dbcli check --all --format json` — Scan all tables (huge tables auto-skipped)
291
+ 2. Review the summary: focus on orphans (broken FKs) and unexpected nulls
292
+ 3. For any flagged issues, drill down with `dbcli query` to inspect specific records
293
+ 4. Use `estimatedRowCount` and `sizeCategory` from schema to gauge table growth
294
+
295
+ ## Code Generation from Schema
296
+
297
+ When setting up a new project or migrating frameworks (e.g., Laravel to Bun + Drizzle):
298
+
299
+ 1. `dbcli schema --format json` — Export full database schema with FK, indexes, defaults, enums
300
+ 2. Use the JSON output to generate ORM schema definitions (Drizzle, Prisma, TypeORM, etc.)
301
+ 3. For each table, map:
302
+ - `primaryKey` + `autoIncrement` to ORM primary key decorator
303
+ - `foreignKey` to relation/reference definitions
304
+ - `indexes` to index declarations
305
+ - `enumValues` to TypeScript enums or union types
306
+ - `nullable` + `defaultValue` to column options
307
+ - `comment` to JSDoc or schema comments
308
+ 4. `dbcli check --all --format json` — Verify data health before trusting existing data
309
+ 5. After ORM setup, run a test query through the new ORM and compare results with `dbcli query` to validate correctness
310
+
311
+ ## Logic Verification Workflow
312
+
313
+ Validate that application logic produces correct database state:
314
+
315
+ 1. `dbcli query "SELECT * FROM <table> WHERE <condition>" --format json` — Capture state BEFORE
316
+ 2. Execute the application logic (API call, script, etc.)
317
+ 3. `dbcli query "SELECT * FROM <table> WHERE <condition>" --format json` — Capture state AFTER
318
+ 4. Compare before/after:
319
+ - Were the expected rows created/updated/deleted?
320
+ - Are computed values correct (totals, balances, counters)?
321
+ - Did related tables update consistently?
322
+ 5. For complex transactions, check ALL affected tables
323
+ 6. `dbcli check <affected-tables> --format json` — Ensure no orphaned data post-operation
324
+
325
+ **When to use:** Unit tests mock the DB and may miss real constraint violations, triggers, and default values. dbcli verifies actual DB state — catches what mocks hide. Best practice: unit tests for logic, dbcli for integration truth.
326
+
327
+ ## Natural Language Operations Workflow
328
+
329
+ When the user describes a database operation in plain language:
330
+
331
+ 1. **Parse intent** — Identify the operation type:
332
+ - "查今天的訂單" → query (SELECT)
333
+ - "幫我新增一筆記事" → insert (INSERT)
334
+ - "把這筆訂單改成已出貨" → update (UPDATE)
335
+
336
+ 2. **Resolve context** — Use schema to map natural language to actual columns:
337
+ - `dbcli schema <table> --format json` — Get real column names
338
+ - "今天的訂單" → `WHERE created_at >= CURDATE()` (verify column name from schema)
339
+ - "已出貨" → check status column's enum values or existing data patterns
340
+
341
+ 3. **Infer missing fields** — Use schema defaults and context:
342
+ - `defaultValue` from schema → skip fields with sensible defaults
343
+ - `autoIncrement` → don't include primary key in INSERT
344
+ - `nullable: false` without default → MUST ask user for this value
345
+
346
+ 4. **Safety gate**:
347
+ - `dbcli blacklist list` — Ensure no blacklisted columns in the operation
348
+ - Check `sizeCategory` — if querying a huge table without filter, warn and suggest conditions
349
+ - For writes: ALWAYS use `--dry-run` first, show the SQL, then confirm
350
+
351
+ 5. **Execute and verify**:
352
+ - Run the operation
353
+ - For INSERT/UPDATE: read back with `dbcli query` to confirm
354
+ - Report result in natural language back to user
355
+
356
+ **Key principle:** Never guess column names or values. Always schema-first, dry-run-first.
357
+
358
+ ## Notes
359
+
360
+ - **Use `--format json`**: More reliable for AI parsing than table format
361
+ - **Use `--dry-run` before writes**: Preview generated SQL before executing
362
+ - **auto-limit**: Query-only mode appends `LIMIT 1000` automatically. Use `--no-limit` for `information_schema` queries or statements incompatible with LIMIT
363
+ - **Blacklist scope**: Blacklisted tables/columns are automatically filtered from query results
364
+
365
+ ## Data Volume Protection
366
+
367
+ Schema output includes `estimatedRowCount` and `sizeCategory` for each table:
368
+
369
+ | Category | Rows | Behavior |
370
+ |----------|------|----------|
371
+ | small | < 10K | No restrictions |
372
+ | medium | 10K - 100K | Suggest adding LIMIT/WHERE |
373
+ | large | 100K - 1M | Warning displayed |
374
+ | huge | > 1M | Full-table SELECT blocked without WHERE/LIMIT — use `--no-limit` to override |
375
+
376
+ **Always check `sizeCategory` before querying.** For `large`/`huge` tables, add WHERE conditions or reasonable LIMIT.