@carllee1983/dbcli 1.2.1 → 1.4.1

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,33 @@ 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
+ ## [1.4.1] - 2026-04-21
9
+
10
+ ### Added
11
+
12
+ - **Documentation Update**: Added per-connection schema isolation details to `SKILL.md` for AI agents.
13
+ - Clarified schema storage layout in `.dbcli/schemas/`.
14
+ - Added usage examples for `--use <connection>` with schema commands.
15
+
16
+ ## [1.4.0] - 2026-04-21
17
+
18
+ ### Added
19
+
20
+ - **Layered Schema Cache (Wave 1)**: Integrated file-based persistence for database schemas.
21
+ - New `SchemaWriter` for saving schema snapshots to `.dbcli/schemas/`.
22
+ - Layered schema loading (Hot/Cold) integrated into `configModule`.
23
+ - Per-connection isolation: Each connection now has its own schema directory (`.dbcli/schemas/<connection>/`).
24
+ - **Improved Migration UX**: Added proactive hints during schema migration to ensure data consistency.
25
+
26
+ ## [1.3.0] - 2026-04-02
27
+
28
+ ### Added
29
+
30
+ - **Skill Update Reminders**: Added automated reminders for updating AI agent skills (`SKILL.md`).
31
+ - New `dbcli upgrade` check that notifies if installed skills are outdated compared to the project's `assets/SKILL.md`.
32
+ - Background check in CLI that displays a one-line reminder to stderr after commands finish.
33
+ - Support for checking skills in `.claude/`, `.local/share/gemini/`, etc.
34
+
8
35
  ## [1.2.1] - 2026-03-31
9
36
 
10
37
  ### Fixed
package/README.md CHANGED
@@ -472,9 +472,9 @@ dbcli skill --install cursor # Install to Cursor IDE
472
472
  ```
473
473
 
474
474
  **Behavior:**
475
- - Dynamically generates SKILL.md from CLI introspection
476
- - Filters commands by permission level (Query-only hides write commands)
477
- - Supports multiple output modes: stdout, file, platform installation
475
+ - Ships a canonical **`assets/SKILL.md`** in the package (single source of truth)
476
+ - Prints that file to **stdout**, writes it with **`--output`**, or copies it to a **platform-specific path** with **`--install`**
477
+ - Actual database access is still enforced by your `.dbcli` permission level and blacklist — the skill text describes the full CLI surface
478
478
 
479
479
  **Examples:**
480
480
  ```bash
@@ -669,7 +669,10 @@ dbcli upgrade --check # Only check, do not upgrade
669
669
  ```
670
670
 
671
671
  **Options:** `--check` — check only, don't install
672
- **Background check:** dbcli silently checks npm registry once per 24 hours. If a newer version is found, a hint is shown after command output.
672
+
673
+ **Background checks (stderr, skipped when `--quiet` or for `upgrade` / `skill`):**
674
+ - **CLI version:** dbcli checks the npm registry (cached, about once per 24 hours). If a newer package exists, a one-line hint prints after normal command output.
675
+ - **Installed skills:** If you used `dbcli skill --install <platform>`, dbcli compares each installed copy to the bundled `assets/SKILL.md`. When they differ, a short reminder lists which platforms to re-install (`dbcli skill --install <platform>`). Run `dbcli upgrade` to see the same skill status together with version info.
673
676
 
674
677
  #### `dbcli shell`
675
678
 
@@ -746,6 +749,7 @@ All commands support these global options:
746
749
  | Flag | Description |
747
750
  |------|-------------|
748
751
  | `--config <path>` | Path to .dbcli config file (default: `.dbcli`) |
752
+ | `--use <connection>` | Use a named v2 connection for this invocation only (does not change the default) |
749
753
  | `-v, --verbose` | Increase verbosity (`-v` verbose, `-vv` debug) |
750
754
  | `-q, --quiet` | Suppress non-essential output |
751
755
  | `--no-color` | Disable colored output (respects `NO_COLOR` env var) |
@@ -928,7 +932,7 @@ A Query-only agent cannot write to any table, and also cannot read blacklisted t
928
932
 
929
933
  ## AI Integration Guide
930
934
 
931
- dbcli generates AI-consumable skill documentation and can be integrated into your favorite AI development tools.
935
+ dbcli ships AI-consumable skill documentation (`assets/SKILL.md`) and can copy it into your favorite AI development tool directories.
932
936
 
933
937
  ### Quick Start
934
938
 
@@ -960,7 +964,7 @@ After installation, the AI agent will have access to dbcli commands and can use
960
964
  4. Restart Claude Code extension
961
965
  5. In Claude Code chat, ask: "Show me the database schema" or "Query active users"
962
966
 
963
- **Skill location:** `~/.claude/skills/SKILL.md`
967
+ **Skill location:** `~/.claude/skills/dbcli/SKILL.md`
964
968
 
965
969
  ---
966
970
 
@@ -972,7 +976,7 @@ After installation, the AI agent will have access to dbcli commands and can use
972
976
  4. Start Gemini: `gemini start`
973
977
  5. In chat, request: "Query the users table" or "Show database tables"
974
978
 
975
- **Skill location:** `~/.local/share/gemini/skills/` (Linux) or platform equivalent
979
+ **Skill location:** `~/.gemini/skills/dbcli/SKILL.md`
976
980
 
977
981
  ---
978
982
 
@@ -984,7 +988,7 @@ After installation, the AI agent will have access to dbcli commands and can use
984
988
  4. Install Copilot CLI: `npm install -g @github-next/github-copilot-cli`
985
989
  5. Use copilot preview: `copilot --help` and explore dbcli integration
986
990
 
987
- **Skill location:** Per Copilot configuration
991
+ **Skill location:** `.github/skills/dbcli/SKILL.md` under the **current working directory** when you run `dbcli skill --install copilot` (typically your project root).
988
992
 
989
993
  ---
990
994
 
@@ -996,7 +1000,7 @@ After installation, the AI agent will have access to dbcli commands and can use
996
1000
  4. Open Cursor editor
997
1001
  5. Use Cursor's Composer: "Insert a new user" or "Export user data"
998
1002
 
999
- **Skill location:** `~/.cursor/skills/`
1003
+ **Skill location:** `.cursor/rules/dbcli.mdc` under the **current working directory** when you run `dbcli skill --install cursor` (project-level Cursor rule).
1000
1004
 
1001
1005
  ---
1002
1006
 
@@ -1021,19 +1025,18 @@ dbcli skill --install claude
1021
1025
  # - Provide analysis
1022
1026
  ```
1023
1027
 
1024
- ### Skill Refresh
1028
+ ### Updating the skill after upgrades
1025
1029
 
1026
- dbcli dynamically generates skills based on your current configuration:
1030
+ The markdown installed by `dbcli skill` is the bundled **`assets/SKILL.md`**. It is **not** regenerated from your live config. When you **upgrade dbcli** or the bundled skill changes, re-copy it to each platform you use:
1027
1031
 
1028
1032
  ```bash
1029
- # When permission level changes, skill updates automatically
1030
- # Edit .dbcli/config.json and set "permission" to "admin" (or re-run dbcli init)
1031
- dbcli skill # Now shows delete and admin commands
1032
-
1033
- # Re-install to push changes to AI platform
1034
1033
  dbcli skill --install claude
1034
+ dbcli skill --install gemini
1035
+ # ... etc.
1035
1036
  ```
1036
1037
 
1038
+ If an installed copy is older than the bundled file, dbcli prints a **stderr reminder** after most commands (see **`dbcli upgrade`**). Changing **permission level** or **blacklist** in `.dbcli` affects what the CLI allows at runtime — keep project context (e.g. `dbcli status`, `dbcli blacklist list`) in mind for agents even though the skill text lists the full command set.
1039
+
1037
1040
  ---
1038
1041
 
1039
1042
  ## Troubleshooting
@@ -1226,8 +1229,11 @@ chmod +x dist/cli.mjs
1226
1229
  ## Development
1227
1230
 
1228
1231
  ```bash
1229
- bun test # run test suite
1230
- bun run build # bundle CLI to dist/ (used before publish)
1232
+ bun test # full test suite (Bun test runner)
1233
+ bun run test:unit # unit + core tests only
1234
+ bun run test:integration # integration tests
1235
+ bun run test:docker # integration tests with docker-compose.test.yml (MySQL + PostgreSQL)
1236
+ bun run build # bundle CLI to dist/ (used before publish)
1231
1237
  ```
1232
1238
 
1233
1239
  See [CONTRIBUTING.md](./CONTRIBUTING.md) for full setup, testing, and release process.
package/README.zh-TW.md CHANGED
@@ -99,53 +99,64 @@ dbcli skill --install claude
99
99
 
100
100
  ## 多重連線支援 (v2)
101
101
 
102
- dbcli 支援在單一專案中管理多個具名的資料庫連線。這對於管理不同環境(開發、測試、正式)或多個資料庫非常有用。
102
+ 在**同一個專案目錄**裡,dbcli 可以保存多組**具名資料庫連線**(例如 `dev`、`staging`、`prod`),各自可有不同主機、資料庫、權限與選用的 `.env` 檔。適合同一 repo 對應多環境、或多個資料庫後端。
103
103
 
104
- ### 初始化具名連線
104
+ ### v1 與 v2 設定檔
105
105
 
106
- 若要建立具名連線,請在 `init` 時使用 `--conn-name` 選項。您也可以為該連線指定自訂的 `.env` 檔案。
106
+ | 項目 | **v1(單一連線)** | **v2(多重連線)** |
107
+ |------|-------------------|-------------------|
108
+ | 設定 | 單一連線物件 | `config.json` 內 `version: 2`,含 `connections`(多個具名連線)與 `default`(預設使用哪一組) |
109
+ | 典型檔案 | 舊版可能為單一 `.dbcli` 檔或目錄內單一連線 | `.dbcli/config.json`(目錄結構) |
110
+
111
+ 若你已有 **v1** 設定,之後執行 `dbcli init --conn-name ...` 追加連線時,工具會把既有連線**匯入為名稱 `default` 的連線**,再寫入 v2 結構,無須手動搬設定。
112
+
113
+ ### 預設連線 vs 單次指定
114
+
115
+ - **`dbcli use <名稱>`** — 變更設定檔裡的**預設連線**(持久)。之後執行 `dbcli query`、`dbcli list` 等**未**加 `--use` 的指令,都會用這一組。
116
+ - **`dbcli ... --use <名稱>`**(全域選項)— **只影響這一條指令**,不改預設。適合在仍以 `dev` 為預設時,偶爾查一下 `prod`。
117
+
118
+ 兩者都**需要 v2 設定**;若指令回報需要 v2,請先完成至少一次具名連線初始化(見下方)。
119
+
120
+ ### 初始化與追加連線
121
+
122
+ 第一次可直接 `dbcli init`(可互動輸入);要**追加**另一環境時,在 `init` 加上 **`--conn-name`**,並可搭配 **`--env-file`** 讓該連線讀獨立的環境檔:
107
123
 
108
124
  ```bash
109
125
  # 使用 .env.staging 建立名為 staging 的連線
110
126
  dbcli init --conn-name staging --env-file .env.staging
111
127
 
112
- # 建立名為 prod 的正式環境連線,並使用環境變數引用
128
+ # 建立名為 prod 的正式環境連線,並使用環境變數引用(憑證不寫死進 repo)
113
129
  dbcli init --conn-name prod --env-file .env.production --use-env-refs
114
130
  ```
115
131
 
116
- ### 管理連線
132
+ 每一條具名連線可以設定不同的 **`--permission`**(例如正式環境只給 `query-only`)。同一專案下的 **schema 快取、黑名單** 等仍共用同一個 `.dbcli` 目錄;切換連線只改「連到哪一台資料庫」,不複製整份專案設定目錄。
117
133
 
118
- 使用 `dbcli use` 指令切換連線或列出所有連線。
134
+ ### 管理連線(`use` / 移除 / 更名)
119
135
 
120
- ```bash
121
- # 列出所有連線(* 標記目前的預設值)
122
- dbcli use --list
136
+ 使用 **`dbcli use`** 切換預設或列出連線(列表中 **`*`** 表示目前的預設連線):
123
137
 
124
- # 將預設連線切換至 'staging'
125
- dbcli use staging
126
-
127
- # 顯示目前的預設連線
128
- dbcli use
138
+ ```bash
139
+ dbcli use --list # 列出全部;* = 預設
129
140
 
130
- # 移除連線
131
- dbcli init --remove staging
141
+ dbcli use staging # 將預設連線改為 staging(寫入設定)
142
+ dbcli use # 顯示目前預設名稱並列出連線
132
143
 
133
- # 重新命名連線
134
- dbcli init --rename staging:production
144
+ dbcli init --remove staging # 從設定移除某具名連線
145
+ dbcli init --rename staging:production # 更名(格式:舊名:新名)
135
146
  ```
136
147
 
137
- ### 臨時使用特定連線
148
+ ### 臨時指定連線(不改預設)
138
149
 
139
- 您可以使用 `--use <name>` 全域旗標,針對特定連線執行任一指令,而無需變更預設設定。
150
+ 任何子指令皆可加全域 **`--use <名稱>`**,僅本次使用該連線:
140
151
 
141
152
  ```bash
142
- # 針對正式資料庫執行一次查詢
143
153
  dbcli query "SELECT count(*) FROM users" --use prod
144
-
145
- # 檢查測試環境資料表的健康狀態
146
154
  dbcli check users --use staging
155
+ dbcli list --use prod
147
156
  ```
148
157
 
158
+ 若同時需要自訂設定路徑,可與 **`--config <路徑>`** 併用(仍指向含 `config.json` 的 `.dbcli` 目錄)。
159
+
149
160
  ---
150
161
 
151
162
 
@@ -176,6 +187,7 @@ dbcli init [OPTIONS]
176
187
  - `--env-file <path>` — 從指定的 `.env` 檔案載入此連線的憑證
177
188
  - `--remove <name>` — 從設定中移除具名連線
178
189
  - `--rename <old:new>` — 重新命名現有連線(格式:`舊名:新名`)
190
+
179
191
  **行為:**
180
192
  - 若存在 `.env` 會讀取(自動帶入 DATABASE_URL、DB_* 等變數)
181
193
  - 缺少的欄位會互動提示(主機、埠、使用者、密碼、資料庫名、權限等級)
@@ -477,9 +489,9 @@ dbcli skill --install cursor # 安裝至 Cursor IDE
477
489
  ```
478
490
 
479
491
  **行為:**
480
- - CLI 內省動態產生 SKILL.md
481
- - 依權限等級過濾指令(Query-only 會隱藏寫入類指令)
482
- - 支援 stdout、檔案、各平台安裝等輸出方式
492
+ - 套件內建唯一的 **`assets/SKILL.md`**(單一來源)
493
+ - 可輸出至 **stdout**、以 **`--output`** 寫入檔案,或以 **`--install`** 複製到**各平台預設路徑**
494
+ - 實際能否存取資料庫仍由 `.dbcli` 的**權限等級**與**黑名單**決定;skill 文字描述的是完整 CLI 能力
483
495
 
484
496
  **範例:**
485
497
  ```bash
@@ -666,8 +678,11 @@ dbcli upgrade # 有新版則升級
666
678
  dbcli upgrade --check # 僅檢查,不安裝
667
679
  ```
668
680
 
669
- **選項:** `--check` — 只檢查,不安裝
670
- **背景檢查:** dbcli 每 24 小時會靜默查詢 npm registry 一次;若有新版,會在指令輸出結束後顯示提示。
681
+ **選項:** `--check` — 只檢查,不安裝
682
+
683
+ **背景檢查(stderr;使用 `--quiet` 或執行 `upgrade` / `skill` 時略過):**
684
+ - **CLI 版本:** dbcli 會查詢 npm registry(有快取,約每 24 小時一次)。若有新版,一般指令結束後會印一行提示。
685
+ - **已安裝的 skill:** 若曾執行 `dbcli skill --install <platform>`,dbcli 會比對各平台安裝檔與套件內的 `assets/SKILL.md`;若不一致,會列出需重新安裝的平台(`dbcli skill --install <platform>`)。執行 `dbcli upgrade` 時也會一併顯示 skill 狀態與版本資訊。
671
686
 
672
687
  #### `dbcli shell`
673
688
 
@@ -744,6 +759,7 @@ dbcli migrate drop-enum status --execute --force
744
759
  | 旗標 | 說明 |
745
760
  |------|------|
746
761
  | `--config <path>` | `.dbcli` 設定檔路徑(預設:`.dbcli`) |
762
+ | `--use <connection>` | 僅本次指令使用具名的 v2 連線(不變更預設連線) |
747
763
  | `-v, --verbose` | 提高詳細度(`-v` 詳細、`-vv` 除錯) |
748
764
  | `-q, --quiet` | 抑制非必要輸出 |
749
765
  | `--no-color` | 關閉彩色輸出(亦遵守 `NO_COLOR` 環境變數) |
@@ -922,7 +938,7 @@ Query-only 代理無法寫入任何表,也無法讀取黑名單表或欄位
922
938
 
923
939
  ## AI 整合指南
924
940
 
925
- dbcli 可產生供 AI 使用的 skill 文件,並可整合至常見 AI 開發工具。
941
+ dbcli 內建可供 AI 使用的 skill 文件(`assets/SKILL.md`),並可複製到常見 AI 開發工具的目錄。
926
942
 
927
943
  ### 快速開始
928
944
 
@@ -954,7 +970,7 @@ dbcli skill --install cursor
954
970
  4. 重新啟動 Claude Code 擴充
955
971
  5. 在對話中詢問:「顯示資料庫 schema」或「查詢作用中使用者」
956
972
 
957
- **Skill 路徑:** `~/.claude/skills/SKILL.md`
973
+ **Skill 路徑:** `~/.claude/skills/dbcli/SKILL.md`
958
974
 
959
975
  ---
960
976
 
@@ -966,7 +982,7 @@ dbcli skill --install cursor
966
982
  4. 啟動 Gemini:`gemini start`
967
983
  5. 在對話中請求:「查詢 users 表」或「列出資料庫資料表」
968
984
 
969
- **Skill 路徑:** `~/.local/share/gemini/skills/`(Linux)或各平台對應路徑
985
+ **Skill 路徑:** `~/.gemini/skills/dbcli/SKILL.md`
970
986
 
971
987
  ---
972
988
 
@@ -978,7 +994,7 @@ dbcli skill --install cursor
978
994
  4. 安裝 Copilot CLI:`npm install -g @github-next/github-copilot-cli`
979
995
  5. 使用 `copilot --help` 並探索與 dbcli 的整合
980
996
 
981
- **Skill 路徑:** Copilot 設定而定
997
+ **Skill 路徑:** 執行 `dbcli skill --install copilot` 時,寫入**目前工作目錄**下的 `.github/skills/dbcli/SKILL.md`(通常為專案根目錄)。
982
998
 
983
999
  ---
984
1000
 
@@ -990,7 +1006,7 @@ dbcli skill --install cursor
990
1006
  4. 開啟 Cursor
991
1007
  5. 在 Composer 中:「新增一筆使用者」或「匯出使用者資料」
992
1008
 
993
- **Skill 路徑:** `~/.cursor/skills/`
1009
+ **Skill 路徑:** 執行 `dbcli skill --install cursor` 時,寫入**目前工作目錄**下的 `.cursor/rules/dbcli.mdc`(專案層級 Cursor 規則)。
994
1010
 
995
1011
  ---
996
1012
 
@@ -1015,18 +1031,18 @@ dbcli skill --install claude
1015
1031
  # - 提供分析
1016
1032
  ```
1017
1033
 
1018
- ### 重新整理 Skill
1034
+ ### 升級後更新 skill
1019
1035
 
1020
- 權限或設定變更後,可重新產生 skill
1036
+ `dbcli skill` 安裝的是套件內建的 **`assets/SKILL.md`**,**不會**依你目前的設定即時重新產生。當你**升級 dbcli** 或內建 skill 內容變更時,請對各平台重新安裝:
1021
1037
 
1022
1038
  ```bash
1023
- # 例如編輯 .dbcli/config.json,將 "permission" 設為 "admin"(或重新執行 dbcli init)
1024
- dbcli skill # 會顯示 delete 與 migrate 等指令
1025
-
1026
- # 再安裝一次以更新 AI 平台
1027
1039
  dbcli skill --install claude
1040
+ dbcli skill --install gemini
1041
+ # …依需求
1028
1042
  ```
1029
1043
 
1044
+ 若本機安裝檔與套件內檔案不一致,多數指令結束後會在 **stderr** 提示(見 **`dbcli upgrade`**)。**權限**或**黑名單**變更會影響 CLI 實際允許的操作 — 建議搭配 `dbcli status`、`dbcli blacklist list` 等讓代理掌握專案現況;skill 文字仍可能列出完整指令集。
1045
+
1030
1046
  ---
1031
1047
 
1032
1048
  ## 故障排除
@@ -1213,8 +1229,11 @@ chmod +x dist/cli.mjs
1213
1229
  ## 開發
1214
1230
 
1215
1231
  ```bash
1216
- bun test # 執行測試
1217
- bun run build # 建置 CLI 至 dist/(發布前使用)
1232
+ bun test # 完整測試(Bun test runner)
1233
+ bun run test:unit # 僅單元與 core 測試
1234
+ bun run test:integration # 整合測試
1235
+ bun run test:docker # 搭配 docker-compose.test.yml(MySQL + PostgreSQL)
1236
+ bun run build # 建置 CLI 至 dist/(發布前使用)
1218
1237
  ```
1219
1238
 
1220
1239
  完整環境、測試與發布流程見 [CONTRIBUTING.md](./CONTRIBUTING.md)。
package/assets/SKILL.md CHANGED
@@ -75,17 +75,23 @@ dbcli list --format json
75
75
  Display table schema or scan entire database.
76
76
 
77
77
  ```bash
78
- dbcli schema # Scan all tables, save to .dbcli
78
+ dbcli schema # Scan all tables, save to .dbcli/schemas/
79
79
  dbcli schema users # Show single table schema
80
80
  dbcli schema users --format json
81
81
  dbcli schema --refresh # Detect and apply schema changes
82
82
  dbcli schema --reset # Clear all schema data and re-fetch
83
83
  dbcli schema --reset --force # Skip confirmation
84
+
85
+ # Per-connection schema isolation (v2 multi-connection config)
86
+ dbcli schema --use staging # Scan staging DB; saves to .dbcli/schemas/staging/
87
+ dbcli schema --use prod # Scan prod DB; saves to .dbcli/schemas/prod/
84
88
  ```
85
89
 
86
- **Options:** `--format <table|json>`, `--refresh`, `--reset`, `--force`
90
+ **Options:** `--format <table|json>`, `--refresh`, `--reset`, `--force`, `--use <connection>`
87
91
  **Permission:** query-only+
88
92
 
93
+ **Schema storage (v1.4+):** Schema is persisted as layered files under `.dbcli/schemas/`. With v2 multi-connection config each connection gets its own subdirectory (`.dbcli/schemas/<connection>/`). Run `dbcli schema --use <connection>` once per connection before querying it — otherwise `schema <table>` may return data from the wrong connection's cache.
94
+
89
95
  ### query
90
96
 
91
97
  Execute SQL query.