@carllee1983/dbcli 1.38.1 → 1.39.2
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/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.cursor/rules/dbcli.mdc +32 -6
- package/.cursor/skills/dbcli/reference.md +33 -5
- package/.cursor-plugin/plugin.json +1 -1
- package/.github/skills/dbcli/SKILL.md +32 -6
- package/.github/skills/dbcli/reference.md +33 -5
- package/CHANGELOG.md +40 -0
- package/assets/SKILL.md +32 -6
- package/assets/SKILL.zh-TW.md +28 -4
- package/assets/reference.md +33 -5
- package/assets/ui-template.html +8 -8
- package/dist/cli.mjs +682 -11334
- package/dist/core.mjs +21 -7
- package/dist/ui-style.css +1 -1
- package/package.json +1 -1
- package/plugins/dbcli-agent/.codex-plugin/plugin.json +1 -1
- package/plugins/dbcli-agent/skills/dbcli/SKILL.md +32 -6
- package/plugins/dbcli-agent/skills/dbcli/reference.md +33 -5
- package/skills/dbcli/SKILL.md +32 -6
- package/skills/dbcli/reference.md +33 -5
package/assets/SKILL.zh-TW.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: dbcli
|
|
3
|
-
description: Database CLI for AI agents with permission-based access control. Use to set up new connections, query, inspect schemas, insert/update/delete, export results, and blacklist sensitive columns/tables. Supports MySQL, PostgreSQL, MariaDB, MongoDB, Redis, and Elasticsearch with multiple named connections per project and custom env files. Trigger when configuring a database connection (`.dbcli` / `.env`), choosing between v1 single and v2 multi-connection layouts, picking auth modes (URI, env refs, Cloud ID, API key), running SQL / MongoDB JSON / Redis commands / Elasticsearch DSL, exploring table/collection/key/index structures, switching database environments, protecting sensitive data from AI access, or performing automated recovery and guided remediation after command failures. For exhaustive flags and examples, read the sibling `reference.md`.
|
|
3
|
+
description: Database CLI for AI agents with permission-based access control. Use to set up new connections, query, inspect schemas, insert/update/delete, export results, generate DB reports or interactive HTML dashboards, and blacklist sensitive columns/tables. Supports MySQL, PostgreSQL, MariaDB, MongoDB, Redis, and Elasticsearch with multiple named connections per project and custom env files. Trigger when configuring a database connection (`.dbcli` / `.env`), choosing between v1 single and v2 multi-connection layouts, picking auth modes (URI, env refs, Cloud ID, API key), running SQL / MongoDB JSON / Redis commands / Elasticsearch DSL, generating a report/dashboard/HTML UI from raw SQL or saved snippets, exploring table/collection/key/index structures, switching database environments, protecting sensitive data from AI access, or performing automated recovery and guided remediation after command failures. For exhaustive flags and examples, read the sibling `reference.md`.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# dbcli
|
|
@@ -15,7 +15,16 @@ description: Database CLI for AI agents with permission-based access control. Us
|
|
|
15
15
|
|
|
16
16
|
1. `dbcli blacklist list` — 確認敏感資料邊界。
|
|
17
17
|
2. `dbcli schema <object> --format json` — 確認真實欄位名稱。**禁止猜測。**
|
|
18
|
-
3. 所有寫入:`--dry-run`(SQL / Mongo)→ 實際執行 → `query` 回讀確認。
|
|
18
|
+
3. 所有寫入:`--dry-run`(SQL / Mongo)→ 實際執行 → `query` 回讀確認。Redis 的 `query`
|
|
19
|
+
**沒有 `--dry-run`**(見 **Redis** 節);Elasticsearch 為**唯讀**。
|
|
20
|
+
|
|
21
|
+
**`update` / `delete` 的 `--where` 僅支援等式(SQL)。** 只接受 `col=val` 或
|
|
22
|
+
`col1=v1 AND col2=v2`。比較 / 模式運算子(`>`、`>=`、`<`、`!=`、`LIKE`、`IN`)會直接
|
|
23
|
+
**報錯**;更危險的是,`OR` 會被**靜默當成值的一部分** — `a=1 OR b=2` 會被解析成
|
|
24
|
+
`a = "1 OR b=2"`,比對到錯誤的列(或完全比對不到)。需要範圍或複合條件時,先用
|
|
25
|
+
`query` / `export` 撈出目標列的主鍵,再對每個主鍵執行一次
|
|
26
|
+
`update` / `delete --where "id=<pk>"`(逐一等式)— 或升級交給人類處理。(MongoDB 的
|
|
27
|
+
`--where` 接受完整 JSON filter,不受此限。)
|
|
19
28
|
|
|
20
29
|
> `report` 與 `guide` 已內嵌 `inspect` 快照 — **不需要**先跑 `dbcli inspect`。只有在需要 audit-recent 脈絡或診斷連線問題時,才手動跑 `dbcli inspect --for-agent`。
|
|
21
30
|
|
|
@@ -25,6 +34,7 @@ description: Database CLI for AI agents with permission-based access control. Us
|
|
|
25
34
|
| --- | --- |
|
|
26
35
|
| 有名稱的工作流程符合(「診斷慢查詢」、「審計權限」) | `skill tasks list` → `skill tasks plan <pack>` — **優先選用;不要自己組合步驟** |
|
|
27
36
|
| 固定診斷目標 | `guide <goal>`(`slow-query` / `capacity` / `health` / `index-usage` / `permissions` / `schema-overview`;`guide --list`) |
|
|
37
|
+
| DB report / dashboard / HTML UI | `blacklist list` → `queries search <keywords>` 或 `queries suggest <intent>` → `queries show @<name>` → 瀏覽器:`q @<name> --param k=v --ui`;檔案:`q @<name> --format html > report.html` 或 `export "<SQL>" --format html --output report.html` |
|
|
28
38
|
| 設定連線 | 見 **連線設定** |
|
|
29
39
|
| 其他情況 | 手動執行指令;參考 **開發者工作流** 速查表 |
|
|
30
40
|
|
|
@@ -65,6 +75,7 @@ dbcli skill tasks plan <task> --param key=value --format json # generate pla
|
|
|
65
75
|
| 情境 | 最小安全路徑 |
|
|
66
76
|
| --- | --- |
|
|
67
77
|
| DB-backed 功能 | `blacklist list` → `schema <object>` → `queries suggest <intent>` |
|
|
78
|
+
| DB report / dashboard request | `blacklist list` → `queries search <keywords>` / `queries suggest <intent>` → `queries show @<name>` → `q @<name> --ui` 或 `--format html` |
|
|
68
79
|
| 應用程式資料錯誤 | `audit tail --for-agent --n 10` → `blacklist list` → `schema <object>` → 最小查詢 |
|
|
69
80
|
| ORM 或 migration | `schema --format json` → `diff --snapshot <name>` → `migrate add-index`/`add-column`(預覽 SQL)→ `diff --against <snapshot>` |
|
|
70
81
|
| PR 資料庫風險審查 | 審查變更的 persistence path,並針對每個重要主張提出具體 `schema`、`plan`、`dry-run`、`report` 或 `guide` 指令。 |
|
|
@@ -77,6 +88,11 @@ dbcli inspect --for-agent --format json
|
|
|
77
88
|
dbcli blacklist list --format json
|
|
78
89
|
dbcli schema <object> --format json
|
|
79
90
|
dbcli queries suggest <intent> --format json
|
|
91
|
+
dbcli queries search <report keywords> --format json
|
|
92
|
+
dbcli queries show @<name> --format json
|
|
93
|
+
dbcli q @<name> --param k=v --ui
|
|
94
|
+
dbcli q @<name> --param k=v --format html > report.html
|
|
95
|
+
dbcli export "<SQL>" --format html --output report.html
|
|
80
96
|
dbcli audit tail --for-agent --n 10
|
|
81
97
|
dbcli diff --snapshot <name>
|
|
82
98
|
dbcli report --section perf --format json
|
|
@@ -273,10 +289,16 @@ dbcli init --conn-name prod --env-file .env.production --use-env-refs --skip-tes
|
|
|
273
289
|
- **支援:** `init`、`list`(透過 SCAN 列 keys)、`schema <key>`(type / TTL / size / sample)、`query`、`q`(saved snippet — **僅唯讀命令**)、`delete`(基本實作:`DEL` / `HDEL` / `LREM` / `SREM` / `ZREM`,需 `data-admin`;`query "DEL <key>"` 亦可)、`shell`、`status`、`use`、`doctor`。**不支援:** `schema` 全掃描、`insert`、`update`、`check`、`diff`、`migrate`。
|
|
274
290
|
- **權限分層:** 讀取類(`GET`/`HGET`/`SCAN`/…)→ `query-only`;mutator(`SET`/`HSET`/`INCR`/`EXPIRE`/`SETEX`/`RENAME`/…)→ `read-write`;`DEL`/`UNLINK`/`HDEL`/`XDEL` → `data-admin`。白名單外的指令一律拒絕。
|
|
275
291
|
- **Redis `query` 無 `--dry-run`** — 寫入安全來自權限門檻與 key 黑名單(命中的讀寫會被拒絕)。如需預覽刪除,請用 `delete <key> --dry-run`。
|
|
276
|
-
- `database` 是 logical DB index(預設 `0`)。`dbcli blacklist add 'secrets:*'` 註冊 key glob;可選的 `redis.mask` 區塊在讀取時遮罩值。大小防護(SCAN/HGETALL 截斷,`--no-limit` 可略過)與遮罩細節:reference.md Redis 段落。
|
|
292
|
+
- `database` 是 logical DB index(預設 `0`)。`dbcli blacklist table add 'secrets:*'` 註冊 key glob;可選的 `redis.mask` 區塊在讀取時遮罩值。大小防護(SCAN/HGETALL 截斷,`--no-limit` 可略過)與遮罩細節:reference.md Redis 段落。
|
|
277
293
|
|
|
278
294
|
## Elasticsearch
|
|
279
295
|
|
|
296
|
+
**dbcli 對 Elasticsearch 為唯讀 — 不支援 `insert` / `update` / `delete`。**
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
dbcli query '{"query":{"match":{"status":"active"}}}' --collection orders
|
|
300
|
+
```
|
|
301
|
+
|
|
280
302
|
- `query` 接受 DSL(JSON body)或 Lucene query string;`--collection <index>` 為必填。
|
|
281
303
|
- **支援:** `init`、`list`(含文件數的索引清單)、`schema [index]`(flattened mapping)、`query`、`export`(v1.22)、`shell`(v1.22)、`status`、`use`、`doctor`。**不支援:** `insert`、`update`、`delete`、`check`、`diff`、`migrate`。
|
|
282
304
|
- `export` 接受含 `--index <index>` 的 search DSL,或以 index 名稱作為查詢來透過 `match_all` scroll 整個 index。Query-only 上限 1000 hits;`--no-limit` 放寬至 10,000。
|
|
@@ -329,11 +351,13 @@ Snippet 從三層解析,**local > shared > builtin**(本地優先):`buil
|
|
|
329
351
|
|
|
330
352
|
```bash
|
|
331
353
|
dbcli query "SELECT day, dau FROM dau_daily" --ui # open in browser
|
|
354
|
+
dbcli q @analytics/revenue --param days=30 --ui # snippet metadata + charts/KPIs
|
|
355
|
+
dbcli q @analytics/revenue --param days=30 --format html > report.html
|
|
332
356
|
dbcli query "SELECT * FROM orders" --format html > out.html # pipe HTML to stdout
|
|
333
357
|
dbcli export "SELECT * FROM orders" --format html --output orders.html
|
|
334
358
|
```
|
|
335
359
|
|
|
336
|
-
`--ui` 隱含 `--format html` 並開啟檔案;`--format html` 單獨使用則寫到 stdout
|
|
360
|
+
`--ui` 隱含 `--format html` 並開啟檔案;`--format html` 單獨使用則寫到 stdout。若已存在 saved snippet,優先用 `q @<name> --ui` / `q @<name> --format html`,因為 snippet metadata 可驅動標題、KPI cards 與圖表。Blacklist 遮蔽在渲染**之前**套用。若要取得 KPI 與圖表而非純 table,請在 snippet frontmatter 加上 `visual:` 區塊(`title`、`kpis[]`、`charts[]`)— 完整 `visual:` schema 見 reference.md。原始 `query` / `export` 呼叫只能渲染 sortable table。
|
|
337
361
|
|
|
338
362
|
## 常見工作流程
|
|
339
363
|
|
package/assets/reference.md
CHANGED
|
@@ -249,6 +249,7 @@ dbcli q @analytics/revenue --param days=30 --format html > report.html
|
|
|
249
249
|
- `--dry-run` — print the bound SQL + values without executing
|
|
250
250
|
- `--use <name>` — pick a v2 named connection
|
|
251
251
|
- `--recovery` — emit a `RecoveryEnvelope` on failure (see `recover`)
|
|
252
|
+
- `--verify` — run the snippet's verification assertions after execution (only if the snippet defines them)
|
|
252
253
|
|
|
253
254
|
**Permission:** query-only+
|
|
254
255
|
|
|
@@ -474,9 +475,10 @@ Insert data into a table.
|
|
|
474
475
|
dbcli insert users --data '{"name":"Alice","email":"alice@example.com"}'
|
|
475
476
|
dbcli insert users --data '{"name":"Alice"}' --dry-run
|
|
476
477
|
dbcli insert users --data '{"name":"Alice"}' --force
|
|
478
|
+
dbcli insert users --data '{"name":"Alice"}' --plan --format json # risk analysis only; no DB connection
|
|
477
479
|
```
|
|
478
480
|
|
|
479
|
-
**Options:** `--data <json>`, `--dry-run`, `--force`
|
|
481
|
+
**Options:** `--data <json>`, `--dry-run`, `--force`, `--plan` (analyze risk without connecting or executing), `--format <text|json>` (`--plan` output), `--recovery`
|
|
480
482
|
**Permission:** read-write+
|
|
481
483
|
|
|
482
484
|
### update
|
|
@@ -486,11 +488,19 @@ Update existing data.
|
|
|
486
488
|
```bash
|
|
487
489
|
dbcli update users --where "id=1" --set '{"name":"Bob"}'
|
|
488
490
|
dbcli update users --where "id=1" --set '{"name":"Bob"}' --dry-run
|
|
491
|
+
dbcli update users --where "id=1" --set '{"name":"Bob"}' --plan --format json # risk analysis only; no DB connection
|
|
489
492
|
```
|
|
490
493
|
|
|
491
|
-
**Options:** `--where <condition>` (required), `--set <json>` (required), `--dry-run`, `--force`
|
|
494
|
+
**Options:** `--where <condition>` (required), `--set <json>` (required), `--dry-run`, `--force`, `--plan` (analyze risk without connecting or executing), `--format <text|json>` (`--plan` output), `--recovery`
|
|
492
495
|
**Permission:** read-write+
|
|
493
496
|
|
|
497
|
+
> **`--where` grammar (SQL `update` / `delete`)** — equality only: `col=val` or
|
|
498
|
+
> `col1=v1 AND col2=v2`. Comparison / pattern operators (`>`, `>=`, `<`, `!=`, `LIKE`, `IN`)
|
|
499
|
+
> raise a parse error, and `OR` is **silently folded into the value** (`a=1 OR b=2` parses as
|
|
500
|
+
> `a = "1 OR b=2"`, matching nothing intended). For ranges or compound predicates, select the
|
|
501
|
+
> target primary keys first, then issue one `update` / `delete --where "id=<pk>"` per key.
|
|
502
|
+
> (MongoDB `--where` accepts a full JSON filter and is exempt.)
|
|
503
|
+
|
|
494
504
|
### delete
|
|
495
505
|
|
|
496
506
|
Delete data from a table.
|
|
@@ -499,9 +509,10 @@ Delete data from a table.
|
|
|
499
509
|
dbcli delete users --where "id=1"
|
|
500
510
|
dbcli delete users --where "id=1" --dry-run
|
|
501
511
|
dbcli delete users --where "id=1" --force
|
|
512
|
+
dbcli delete users --where "id=1" --plan --format json # risk analysis only; no DB connection
|
|
502
513
|
```
|
|
503
514
|
|
|
504
|
-
**Options:** `--where <condition>` (required), `--dry-run`, `--force`
|
|
515
|
+
**Options:** `--where <condition>` (required), `--dry-run`, `--force`, `--plan` (analyze risk without connecting or executing), `--format <text|json>` (`--plan` output), `--recovery`
|
|
505
516
|
**Permission:** data-admin+
|
|
506
517
|
|
|
507
518
|
### export
|
|
@@ -521,7 +532,7 @@ dbcli export orders --format csv --output orders.csv # index name as query
|
|
|
521
532
|
dbcli export orders --no-limit --format jsonl # scroll the whole index in batches
|
|
522
533
|
```
|
|
523
534
|
|
|
524
|
-
**Options:** `--format <json|jsonl|csv|html>` (required), `--output <path>`, `--force`, `--recovery`, `--index <name>` (Elasticsearch), `--no-limit` (Elasticsearch full-index scroll)
|
|
535
|
+
**Options:** `--format <json|jsonl|csv|html>` (required), `--output <path>`, `--force`, `--recovery`, `--collection <name>` (MongoDB collection) / `--index <name>` (Elasticsearch index; alias for `--collection`), `--limit <number>` (overrides auto-limit), `--no-limit` (Elasticsearch full-index scroll)
|
|
525
536
|
**Permission:** query-only+ — SQL, MongoDB, and **(v1.22)** Elasticsearch.
|
|
526
537
|
|
|
527
538
|
The `html` format emits the same self-contained dashboard as `query --ui` (see [Interactive HTML dashboard](#interactive-html-dashboard)). Because `export` runs raw SQL (no snippet metadata), the HTML report is always rendered as a sortable / filterable table — no KPIs or charts. Use `dbcli q @<name> --format html` (or `--ui`) for the charted view.
|
|
@@ -892,6 +903,7 @@ Boundaries:
|
|
|
892
903
|
| `--from <path>` | Read the envelope from this file instead of `.dbcli/last-recovery.json`. Accepts raw `RecoveryEnvelope` or `SavedRecoveryEnvelope`. | — |
|
|
893
904
|
| `--allow-write <tier>` | Open the risk gate. Values: `readonly-cmd` (local-side writes) \| `write-cmd` (database writes). | `none` |
|
|
894
905
|
| `--no-verify` | Skip the verify step appended after a successful `--apply`. | off (verify runs by default) |
|
|
906
|
+
| `--write-verification-artifact` | After a successful `--apply`, persist a secret-free `VerificationArtifact` JSON under `.dbcli/verification/`. | off |
|
|
895
907
|
| `--format <format>` | `markdown` \| `json`. | `markdown` for inspect, `json` for `--apply` |
|
|
896
908
|
|
|
897
909
|
#### Plan source resolution
|
|
@@ -1650,6 +1662,7 @@ dbcli skill --install codex # install to ~/.codex/skills/dbcli/
|
|
|
1650
1662
|
**Options:**
|
|
1651
1663
|
- `--install <platform>` — `claude` | `gemini` | `antigravity` | `copilot` | `cursor` | `codex` | `windsurf`. Writes `SKILL.md` plus `reference.md` next to it so the agent gets progressive disclosure.
|
|
1652
1664
|
- `--output <path>` — write `SKILL.md` to a file instead of stdout. Does not install `reference.md`.
|
|
1665
|
+
- `--lang <en|zh-TW>` — source language for the emitted SKILL content (default `en`). It selects `assets/SKILL.md` vs `assets/SKILL.zh-TW.md`; the install/output filename stays `SKILL.md` regardless.
|
|
1653
1666
|
|
|
1654
1667
|
**Notes:**
|
|
1655
1668
|
- Both files come straight from `assets/SKILL.md` + `assets/reference.md` inside the dbcli package — no runtime rendering. Keep these in sync when shipping a release.
|
|
@@ -1662,6 +1675,21 @@ dbcli skill --install codex # install to ~/.codex/skills/dbcli/
|
|
|
1662
1675
|
|
|
1663
1676
|
**Permission:** n/a.
|
|
1664
1677
|
|
|
1678
|
+
### skill context
|
|
1679
|
+
|
|
1680
|
+
Emit an AI-friendly snapshot of the connected database's schema and saved-query snippets (blacklist-filtered) so an agent can be primed with the current context.
|
|
1681
|
+
|
|
1682
|
+
```bash
|
|
1683
|
+
dbcli skill context # XML (default)
|
|
1684
|
+
dbcli skill context --format json
|
|
1685
|
+
dbcli skill context --format markdown
|
|
1686
|
+
```
|
|
1687
|
+
|
|
1688
|
+
**Options:**
|
|
1689
|
+
- `--format <xml|json|markdown>` — output format (default: `xml`)
|
|
1690
|
+
|
|
1691
|
+
**Permission:** query-only+ — read-only; blacklisted objects are never emitted.
|
|
1692
|
+
|
|
1665
1693
|
### skill tasks (Agent Task Packs)
|
|
1666
1694
|
|
|
1667
1695
|
```bash
|
|
@@ -2201,7 +2229,7 @@ Rewrites emit a `REDIS_SIZE_REWRITE` warning; truncations emit `REDIS_SIZE_TRUNC
|
|
|
2201
2229
|
Blacklist rules are enforced as **Redis-native key globs** (`*`, `?`, `[abc]`, `[a-z]`):
|
|
2202
2230
|
|
|
2203
2231
|
```bash
|
|
2204
|
-
dbcli blacklist add 'secrets:*'
|
|
2232
|
+
dbcli blacklist table add 'secrets:*' # register a key-glob rule
|
|
2205
2233
|
dbcli query "GET secrets:api_key" # → BlacklistRejection (exit non-zero)
|
|
2206
2234
|
dbcli query "MGET safe:k secrets:api" # → rejected (any matching key fails the whole command)
|
|
2207
2235
|
dbcli query "KEYS secrets:*" # → rejected (pattern overlaps a rule)
|