@carllee1983/dbcli 0.4.0-beta → 0.5.2-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,59 @@ 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.2-beta] - 2026-03-27
9
+
10
+ ### Fixed
11
+
12
+ - **`init --use-env-refs` permission bug**: Interactive env-ref mode now correctly offers all 4 permission levels (was missing `data-admin`)
13
+ - **`init` i18n completeness**: All 10 hardcoded English messages replaced with i18n keys (supports en/zh-TW)
14
+ - **`init` duplicate code**: Extracted shared `.dbcli exists` overwrite check into `checkOverwrite()` helper
15
+ - **`--use-env-refs` help text**: Improved option description to clarify CI/CD and multi-env use case
16
+ - **Documentation**: Added `--use-env-refs` to README (en/zh-TW), CHANGELOG, and SKILL.md with AI agent guidance
17
+
18
+ ---
19
+
20
+ ## [0.5.1-beta] - 2026-03-27
21
+
22
+ ### Added
23
+
24
+ - **Database version check**: Warns on stderr when connected database version is below minimum supported (PostgreSQL 12+, MySQL 8.0+, MariaDB 10.5+). Non-blocking — connection proceeds normally.
25
+ - **`dbcli doctor` DB version check**: New "Database version" item in Connection & Data group.
26
+ - **`dbcli init --use-env-refs`**: Store environment variable references (`{"$env": "DB_HOST"}`) in config instead of actual values. Supports interactive and non-interactive modes with `--env-host`, `--env-port`, `--env-user`, `--env-password`, `--env-database` options. Suitable for CI/CD and multi-environment deployments.
27
+
28
+ ### Fixed
29
+
30
+ - **`init` permission bug**: Interactive env-ref mode now correctly offers all 4 permission levels (was missing `data-admin`)
31
+ - **`init` i18n**: All hardcoded English messages in init command replaced with i18n keys (10 messages)
32
+ - **`init` duplicate code**: Extracted shared `.dbcli exists` overwrite check into `checkOverwrite()` helper
33
+
34
+ ---
35
+
36
+ ## [0.5.0-beta] - 2026-03-27
37
+
38
+ ### UX & Developer Experience — Colors, Logging, Diagnostics, and Tooling
39
+
40
+ ### Added
41
+
42
+ - **Color system** (`picocolors`): Semantic color helpers (`success`/`error`/`warn`/`info`/`dim`/`bold`) with automatic `NO_COLOR` support
43
+ - **SQL syntax highlighting**: Keywords (blue bold), strings (green), numbers (yellow) — applied in verbose mode and dry-run preview
44
+ - **Leveled logger**: Four levels — quiet (`-q`), normal (default), verbose (`-v`), debug (`-vv`) — all output to stderr to keep stdout clean for structured data
45
+ - **`--no-color` global flag**: Disable colored output; also respects `NO_COLOR` environment variable (<https://no-color.org/>)
46
+ - **`-v, --verbose` global flag**: Increase verbosity (`-v` = verbose, `-vv` = debug)
47
+ - **`-q, --quiet` global flag**: Suppress non-essential output
48
+ - **`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.
49
+ - **`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.
50
+ - **`dbcli upgrade` command**: Self-update from npm registry. `--check` flag for check-only mode.
51
+ - **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`.
52
+ - **Table formatter colorization**: Table headers now display in bold
53
+ - **62 new tests**: colors (7), sql-highlight (6), logger (10), doctor (12), completion (8), upgrade/version-check (19)
54
+
55
+ ### Dependencies
56
+
57
+ - Added `picocolors` (~0.4 KB) as production dependency
58
+
59
+ ---
60
+
8
61
  ## [0.2.0-beta] - 2026-03-26
9
62
 
10
63
  ### Data Access Control — Blacklist System
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Carl Lee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
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
 
@@ -92,9 +96,27 @@ Initialize a new dbcli project with database connection configuration.
92
96
 
93
97
  **Usage:**
94
98
  ```bash
95
- dbcli init
99
+ dbcli init [OPTIONS]
96
100
  ```
97
101
 
102
+ **Options:**
103
+ - `--system <type>` — Database system: `postgresql`, `mysql`, `mariadb`
104
+ - `--host <host>` — Database host
105
+ - `--port <port>` — Database port
106
+ - `--user <user>` — Database user
107
+ - `--password <pass>` — Database password
108
+ - `--name <db>` — Database name
109
+ - `--permission <level>` — Permission level: `query-only`, `read-write`, `data-admin`, `admin`
110
+ - `--use-env-refs` — Store environment variable references instead of actual values in config
111
+ - `--env-host <var>` — Env var name for host (with `--use-env-refs`)
112
+ - `--env-port <var>` — Env var name for port (with `--use-env-refs`)
113
+ - `--env-user <var>` — Env var name for user (with `--use-env-refs`)
114
+ - `--env-password <var>` — Env var name for password (with `--use-env-refs`)
115
+ - `--env-database <var>` — Env var name for database (with `--use-env-refs`)
116
+ - `--skip-test` — Skip connection test
117
+ - `--no-interactive` — Non-interactive mode (requires all options)
118
+ - `--force` — Overwrite existing config without confirmation
119
+
98
120
  **Behavior:**
99
121
  - Reads `.env` file if present (auto-fills DATABASE_URL, DB_* variables)
100
122
  - Prompts for missing values (host, port, user, password, database name, permission level)
@@ -112,8 +134,20 @@ dbcli init
112
134
 
113
135
  # Specify permission level
114
136
  echo "PERMISSION_LEVEL=admin" >> .env && dbcli init
137
+
138
+ # Store env var references instead of values (interactive)
139
+ dbcli init --use-env-refs
140
+
141
+ # Store env var references (non-interactive)
142
+ dbcli init --use-env-refs --system mysql \
143
+ --env-host DB_HOST --env-port DB_PORT \
144
+ --env-user DB_USER --env-password DB_PASSWORD \
145
+ --env-database DB_DATABASE \
146
+ --no-interactive
115
147
  ```
116
148
 
149
+ > **`--use-env-refs`:** When enabled, the config stores environment variable names (e.g., `{"$env": "DB_HOST"}`) instead of actual values. This avoids writing sensitive credentials into the config file, making it suitable for multi-environment deployments and CI/CD pipelines. At connection time, dbcli automatically reads the actual values from the referenced environment variables.
150
+
117
151
  ---
118
152
 
119
153
  #### `dbcli list`
@@ -438,6 +472,68 @@ DBCLI_OVERRIDE_BLACKLIST=true dbcli query "SELECT * FROM secrets_vault"
438
472
 
439
473
  ---
440
474
 
475
+ #### `dbcli doctor`
476
+
477
+ Run diagnostic checks on environment, configuration, connection, and data.
478
+
479
+ ```bash
480
+ dbcli doctor # Colored text output
481
+ dbcli doctor --format json # JSON output for AI agents
482
+ ```
483
+
484
+ **Checks:**
485
+ - **Environment:** Bun version compatibility, dbcli version (compares with npm registry)
486
+ - **Configuration:** Config file exists/valid, permission level, blacklist completeness
487
+ - **Connection & Data:** Database connectivity, schema cache freshness (> 7 days warning), large table warnings (> 1M rows)
488
+
489
+ **Options:** `--format <text|json>`
490
+ **Exit code:** 0 = all pass or warnings only, 1 = errors found
491
+
492
+ ---
493
+
494
+ #### `dbcli completion [shell]`
495
+
496
+ Generate shell completion scripts for tab auto-complete.
497
+
498
+ ```bash
499
+ dbcli completion bash # Output bash completion to stdout
500
+ dbcli completion zsh # Output zsh completion to stdout
501
+ dbcli completion fish # Output fish completion to stdout
502
+ dbcli completion --install # Auto-detect shell and install to rc file
503
+ dbcli completion --install zsh # Install for specific shell
504
+ ```
505
+
506
+ **Supported shells:** bash, zsh, fish
507
+
508
+ ---
509
+
510
+ #### `dbcli upgrade`
511
+
512
+ Check for updates and self-upgrade dbcli.
513
+
514
+ ```bash
515
+ dbcli upgrade # Check and upgrade if newer version available
516
+ dbcli upgrade --check # Only check, do not upgrade
517
+ ```
518
+
519
+ **Options:** `--check` — check only, don't install
520
+ **Background check:** dbcli silently checks npm registry once per 24 hours. If a newer version is found, a hint is shown after command output.
521
+
522
+ ---
523
+
524
+ ## Global Options
525
+
526
+ All commands support these global options:
527
+
528
+ | Flag | Description |
529
+ |------|-------------|
530
+ | `--config <path>` | Path to .dbcli config file (default: `.dbcli`) |
531
+ | `-v, --verbose` | Increase verbosity (`-v` verbose, `-vv` debug) |
532
+ | `-q, --quiet` | Suppress non-essential output |
533
+ | `--no-color` | Disable colored output (respects `NO_COLOR` env var) |
534
+
535
+ ---
536
+
441
537
  ## Permission Model
442
538
 
443
539
  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 使用三層粗粒度權限模型,並搭配黑名單系統提供敏感表和欄位的細粒度保護(見[資料存取控制](#資料存取控制)):
@@ -232,8 +238,19 @@ dbcli init
232
238
 
233
239
  dbcli init --host db.example.com --port 5432 --user admin --password secret --name prod_db --system postgresql
234
240
  # 非交互式初始化
241
+
242
+ dbcli init --use-env-refs
243
+ # 交互式:提示輸入環境變數名稱,config 中儲存 {"$env": "DB_HOST"} 而非實際值
244
+
245
+ dbcli init --use-env-refs --system mysql \
246
+ --env-host DB_HOST --env-port DB_PORT \
247
+ --env-user DB_USER --env-password DB_PASSWORD \
248
+ --env-database DB_DATABASE --no-interactive
249
+ # 非交互式環境變數參照模式,適合 CI/CD
235
250
  ```
236
251
 
252
+ > **`--use-env-refs` 說明:** 使用此選項時,config 中儲存的是環境變數名稱(如 `{"$env": "DB_HOST"}`)而非實際值。這樣可以避免將敏感資訊寫入 config 檔案,適合多環境部署或 CI/CD 場景。連線時 dbcli 會自動從環境變數讀取實際值。
253
+
237
254
  ### 列出表
238
255
 
239
256
  ```bash
@@ -358,6 +375,62 @@ dbcli blacklist column remove users.ssn
358
375
  DBCLI_OVERRIDE_BLACKLIST=true dbcli query "SELECT * FROM secrets_vault"
359
376
  ```
360
377
 
378
+ #### `dbcli doctor`
379
+
380
+ 執行環境、設定、連線與資料的全面診斷。
381
+
382
+ ```bash
383
+ dbcli doctor # 彩色文字輸出
384
+ dbcli doctor --format json # JSON 輸出供 AI agent 使用
385
+ ```
386
+
387
+ **檢查項目:**
388
+ - **環境:** Bun 版本相容性、dbcli 版本(與 npm registry 比對)
389
+ - **設定:** 設定檔存在/合法、權限等級、blacklist 完整性
390
+ - **連線與資料:** 資料庫連線測試、schema cache 新鮮度(> 7 天警告)、大表警告(> 1M 列)
391
+
392
+ **選項:** `--format <text|json>`
393
+
394
+ ---
395
+
396
+ #### `dbcli completion [shell]`
397
+
398
+ 產生 shell 自動補全腳本。
399
+
400
+ ```bash
401
+ dbcli completion bash # 輸出 bash 補全腳本
402
+ dbcli completion zsh # 輸出 zsh 補全腳本
403
+ dbcli completion fish # 輸出 fish 補全腳本
404
+ dbcli completion --install # 自動偵測 shell 並安裝
405
+ dbcli completion --install zsh # 指定 shell 安裝
406
+ ```
407
+
408
+ **支援 shell:** bash、zsh、fish
409
+
410
+ ---
411
+
412
+ #### `dbcli upgrade`
413
+
414
+ 檢查更新並自動升級 dbcli。
415
+
416
+ ```bash
417
+ dbcli upgrade # 檢查並升級
418
+ dbcli upgrade --check # 僅檢查,不升級
419
+ ```
420
+
421
+ **背景檢查:** 每個指令靜默檢查 npm registry(每 24 小時一次),有新版時在指令完成後顯示提示。
422
+
423
+ ## 全域選項
424
+
425
+ 以下選項適用於所有指令:
426
+
427
+ | 選項 | 說明 |
428
+ |------|------|
429
+ | `--config <path>` | 指定 .dbcli 設定檔路徑(預設:`.dbcli`) |
430
+ | `-v, --verbose` | 增加輸出詳細度(`-v` 詳細、`-vv` 除錯) |
431
+ | `-q, --quiet` | 靜音模式,抑制非必要輸出 |
432
+ | `--no-color` | 關閉彩色輸出(支援 `NO_COLOR` 環境變數) |
433
+
361
434
  ## 環境配置
362
435
 
363
436
  ### .dbcli 配置檔案
package/assets/SKILL.md CHANGED
@@ -30,6 +30,8 @@ dbcli init --no-interactive --force # Non-interactive, skip overwrite confirmati
30
30
 
31
31
  **Key options:** `--system <postgresql|mysql|mariadb>`, `--permission <query-only|read-write|data-admin|admin>`, `--use-env-refs`, `--skip-test`, `--no-interactive`, `--force`
32
32
 
33
+ > **AI agent note on `--use-env-refs`:** If an existing `.dbcli` config contains `{"$env": "DB_HOST"}` style references, the connection values are read from environment variables at runtime. Do NOT re-run `init` to replace these references with actual values — the env-ref format is intentional for CI/CD and multi-environment setups.
34
+
33
35
  ### list
34
36
 
35
37
  List all tables.
@@ -176,6 +178,50 @@ dbcli status --format text # Human-readable text output
176
178
  **Output:** `permission`, `system`, `blacklist` summary, `version`
177
179
  **Permission:** query-only+
178
180
 
181
+ ### doctor
182
+
183
+ Run diagnostic checks on environment, configuration, connection, and data.
184
+
185
+ ```bash
186
+ dbcli doctor # Colored text output
187
+ dbcli doctor --format json # JSON output for AI agents
188
+ ```
189
+
190
+ **Checks:**
191
+ - Environment: Bun version, dbcli version (compares with npm registry)
192
+ - Configuration: config file exists/valid, permission level, blacklist completeness (detects unprotected sensitive columns)
193
+ - Connection & Data: database connectivity, schema cache freshness (warns if > 7 days), large table warnings (> 1M rows)
194
+
195
+ **Exit code:** 0 if all pass or warnings only, 1 if any error
196
+ **Options:** `--format <text|json>`
197
+
198
+ ### completion
199
+
200
+ Generate shell completion scripts for tab auto-complete.
201
+
202
+ ```bash
203
+ dbcli completion bash # Output bash completion script
204
+ dbcli completion zsh # Output zsh completion script
205
+ dbcli completion fish # Output fish completion script
206
+ dbcli completion --install # Auto-detect shell and install
207
+ dbcli completion --install zsh # Install for specific shell
208
+ ```
209
+
210
+ **Supported shells:** bash, zsh, fish
211
+
212
+ ### upgrade
213
+
214
+ Check for updates and self-upgrade dbcli to the latest version from npm.
215
+
216
+ ```bash
217
+ dbcli upgrade # Check and upgrade if newer version available
218
+ dbcli upgrade --check # Only check, do not upgrade
219
+ ```
220
+
221
+ **Options:** `--check`
222
+
223
+ **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.
224
+
179
225
  ## Permission Levels
180
226
 
181
227
  | Level | Allowed Operations |
@@ -189,7 +235,12 @@ Set via `dbcli init --permission <level>` or in `.dbcli` config.
189
235
 
190
236
  ## Global Options
191
237
 
192
- All commands support `--config <path>` to specify a custom config file (default: `.dbcli`).
238
+ | Flag | Description |
239
+ |------|-------------|
240
+ | `--config <path>` | Path to .dbcli config file (default: `.dbcli`) |
241
+ | `-v, --verbose` | Increase verbosity (`-v` verbose, `-vv` debug) |
242
+ | `-q, --quiet` | Suppress non-essential output |
243
+ | `--no-color` | Disable colored output (also respects `NO_COLOR` env var) |
193
244
 
194
245
  ## AI Agent Workflow
195
246