@carllee1983/dbcli 1.20.2 → 1.23.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 +104 -0
- package/README.zh-TW.md +7 -4
- package/assets/SKILL.md +24 -9
- package/assets/SKILL.zh-TW.md +9 -4
- package/assets/reference.md +193 -11
- package/assets/tasks/analyze-table-perf.md +35 -0
- package/dist/cli.mjs +53684 -1295
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,108 @@ 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
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [1.23.1] - 2026-05-29 - Skill Docs Sync
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- 補齊 `assets/SKILL.md` 與 `assets/reference.md`,涵蓋 v1.22(Redis `redis.mask` 遮罩、Elasticsearch export/shell)與 v1.23(`explain`、`guide missing-index-for`、`inspect` 情境感知 `suggestedCommands` + `hints`、內建 task pack `analyze-table-perf`)的指令與旗標說明,使 `dbcli skill --install` 產出的文件與實際行為一致
|
|
15
|
+
|
|
16
|
+
## [1.23.0] - 2026-05-29 - Source-Driven Performance Review Tooling
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- **`dbcli explain` 一級指令。** 把 `EXPLAIN` / `ANALYZE SELECT` / `EXPLAIN (ANALYZE, BUFFERS) SELECT` 包成統一介面,單條 query、`@saved-query`、`@file.sql`、`@glob/*` 通吃。輸出統一的 `ExplainRow` schema,附 5 條 actionable annotations(`full-scan` / `temp-table` / `filesort` / `cost-estimate-skew` / `nested-loop-large`)。輸出格式 markdown(預設)/ json / table。支援 `--bulk` 多筆批次。MariaDB + MySQL + PostgreSQL。(v1.23 P2)
|
|
21
|
+
- **`dbcli guide missing-index-for` 單條 query 複合索引顧問。** 解析一條 `SELECT`,結合真實 `EXPLAIN` 計畫與既有索引,輸出帶 `confidence`(high/medium/low)與 `reason` 的索引候選;偵測既有索引碰撞(single-col 可擴成 composite),並把函式/運算式欄位與無法解析的 SQL 列為 `warnings`。輸出格式 yaml(預設)/ json / markdown,支援 `--min-confidence` 過濾。唯讀(僅 EXPLAIN + 索引內省)。(v1.23 P3)
|
|
22
|
+
- **`dbcli inspect` 情境感知 `suggestedCommands` 與新的 `hints` 欄位。** `suggestedCommands` 改為三層加權(bootstrap / context-aware / discovery):collector 讀近 10 條 audit 找出最熱門資料表,有 task pack 時自動建議 `skill tasks plan analyze-table-perf --param table=<table>` 與 `skill tasks list`。新增與 `suggestedCommands` 平行的 `hints` 欄位(JSON 機器可讀 + markdown `## Hints`),提示最熱門資料表、可用 task pack 數量與 schema 快取概況。新增內建 task pack `analyze-table-perf`(唯讀 `plan-only`,吃必填 `table` 參數)。audit 讀取唯讀且永不 throw。(v1.23 P4)
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- query-only 模式不再對 `SHOW`/`DESCRIBE`/`EXPLAIN`/`ANALYZE SELECT` 注入 `LIMIT`,避免 server 拒絕(v1.23 P1, issue #1)
|
|
27
|
+
- MariaDB `ANALYZE SELECT` 與 PostgreSQL `EXPLAIN (ANALYZE, BUFFERS) SELECT` 視為 read-only,query-only 模式可執行(v1.23 P1, issue #2)
|
|
28
|
+
- driver 在 execute 階段丟出的 SQL 錯誤(語法錯、table 不存在、column 不存在)不再被誤包成 `Connection failed`;訊息附 actionable hints 與 fuzzy table 候選(v1.23 P1, issue #3)
|
|
29
|
+
- `dbcli schema --refresh` 首次 bootstrap 不再要求 `--force`(v1.23 P1, issue #7)
|
|
30
|
+
- query-only 模式拒絕未知 SQL 時的訊息明確化:加入當前 permission level 與 issue 連結
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
|
|
34
|
+
- `ConnectionError.code` union 新增 `SQL_SYNTAX_ERROR` / `TABLE_NOT_FOUND` / `COLUMN_NOT_FOUND`(向後相容;既有 consumer 只匹配 `UNKNOWN` 仍 fallback)
|
|
35
|
+
|
|
36
|
+
## [1.22.0] - 2026-05-21 - Elasticsearch Shell/Export + Redis Masking
|
|
37
|
+
|
|
38
|
+
### Added
|
|
39
|
+
|
|
40
|
+
- **Elasticsearch interactive shell.** `dbcli shell` 對 ES 連線開啟 Kibana Dev Tools 風格 REPL:輸入請求行 `<METHOD> /<path>` 加上可選的多行 JSON body,以空白行送出整個區塊,回應以美化 JSON 呈現。以讀取為主 — index 層級黑名單於前端直接拒絕受保護 index;`_search` 若 body 未指定 `size` 自動上限 1000 筆。(P1)
|
|
41
|
+
- **Elasticsearch export.** `dbcli export` 對 ES 連線支援兩種形式:傳入 search DSL 並以 `--index` 指定索引以匯出命中結果,或直接以 index 名稱當作查詢、透過 `match_all` + scroll 匯出整個索引。輸出 JSON / JSONL / CSV,預設上限 1000 筆(`--no-limit` 匯出全索引,以 scroll 分批串流)。匯出前套用索引層級黑名單檢查,並寫入稽核紀錄。(P2)
|
|
42
|
+
- **Redis value / hash-field 遮罩。** 新增 `.dbcli` `redis.mask` 設定區塊:key 命中 `keyPattern` glob 者,其值(或指定的 hash `fields`)於讀取時(`GET`、`GETRANGE`、`HGETALL`、`HGET`、`HMGET`、`HVALS`)回傳 `[REDACTED]`。遮罩與既有 key-glob 拒絕黑名單並存,且**拒絕一律優先於遮罩**。(P3)
|
|
43
|
+
|
|
44
|
+
### Fixed
|
|
45
|
+
|
|
46
|
+
- **Redis shell 單行指令路由。** 在 `dbcli shell` 對 Redis 連線輸入不帶結尾 `;` 的單行指令(`GET mykey`、`SCAN 0`、`HGETALL h`)現可正確執行,修正先前被誤判為未知 dbcli 指令的路由瑕疵。SQL 的分號 / 多行語意不變。(P4)
|
|
47
|
+
|
|
48
|
+
### Changed
|
|
49
|
+
|
|
50
|
+
- `src/adapters/capabilities.ts`:ES `export` 由 unsupported 改為 limited(readonly);Redis `blacklist` note 補上 value/hash-field 遮罩;Redis `shell` 單行說明修正。
|
|
51
|
+
|
|
52
|
+
### Docs
|
|
53
|
+
|
|
54
|
+
- 雙語 user docs(`docs/user/en` / `docs/user/zh-TW`,md + html)新增 ES shell、ES export、Redis 遮罩段落;`docs/feature-matrix.md` 同步 ES export 與 Redis blacklist 儲存格。
|
|
55
|
+
|
|
56
|
+
## [1.21.0] - 2026-05-20 - Redis-Parity Pack
|
|
57
|
+
|
|
58
|
+
### Added
|
|
59
|
+
|
|
60
|
+
- **Redis shell.** `dbcli shell` 現對 Redis 連線開啟互動式 REPL,具備歷史、readline、tab 補全(指令 + key 前綴)與 `.no-limit on/off` meta 指令。單行語意。
|
|
61
|
+
- **Redis size guard.** `SCAN` / `HSCAN` / `SSCAN` / `ZSCAN` 在缺少時補上 `COUNT 1000`;`LRANGE` / `ZRANGE` / `ZREVRANGE` 夾限 `stop`;`ZRANGEBYSCORE` 補上 `LIMIT 0 1000`。`HGETALL` / `HKEYS` / `HVALS` / `SMEMBERS` / `KEYS` 的無上限回覆在 client 端截斷至 1000 並帶 `REDIS_SIZE_TRUNCATE` 警告。`--no-limit` 略過所有防護。
|
|
62
|
+
- **Redis blacklist 強制。** `dbcli blacklist add 'pattern'` 現會封鎖 key 命中的 Redis 讀寫。採 Redis 原生 glob(`*`、`?`、`[abc]`、`[a-z]`)。與黑名單重疊的 `KEYS` / `SCAN MATCH` 會被拒絕;未重疊的掃描則濾掉黑名單 keys 並帶 `REDIS_BLACKLIST_FILTERED` 警告。稽核記錄含 `metadata.rejection_reason: 'blacklist'` 與 `matched_pattern`。
|
|
63
|
+
|
|
64
|
+
### Changed
|
|
65
|
+
|
|
66
|
+
- `ExecutionResult.warnings` 現為公開型別的一部分(optional),目前僅由 Redis 發出。
|
|
67
|
+
- `src/adapters/capabilities.ts` Redis row 更新:`shell` → `interactive`、`query auto-limit` → `limited`、`blacklist` → `limited`。
|
|
68
|
+
|
|
69
|
+
### Out of scope
|
|
70
|
+
|
|
71
|
+
- Elasticsearch shell、Redis/ES export、Redis value/hash-field 遮罩 — 延後至 v1.22 或之後。
|
|
72
|
+
|
|
73
|
+
## [1.20.2] - 2026-05-19
|
|
74
|
+
|
|
75
|
+
### Added
|
|
76
|
+
|
|
77
|
+
- **MongoDB MVP 全套支援。** `q` 指令現以 limited-supported 等級納入 MongoDB(`find` / `aggregate` 兩種 snippet body),路由經過專屬分支與 field-masker;`schema` 採 `$sample` + 遞迴 path 偵測(含 BSON 型別),新增 `--sample-method` 旗標;`query` / `export` 套用 `maskMongoRows` 對巢狀結構遞迴遮罩。
|
|
78
|
+
- **MongoDB blacklist 強化。** 新增 path-matcher(exact / dotted / suffix-wildcard)、field-masker 遞迴遮罩、insert / update 在寫入前強制套用 nested-path blacklist;`blacklist list` 對 collection 上的 middle-`*` pattern 發出警告。
|
|
79
|
+
- **MongoDB 安全模型升級。** update operator 從硬性 allowlist 改為分級安全(tiered operator safety);schema 對 blacklist 欄位直接 redact;`cache` / `doctor` 暴露 `sampleMethod`。
|
|
80
|
+
- **MongoDB snippets 一級公民化。** 內建 reference snippets(find + aggregate)、`queries list/search/suggest` 將 MongoDB snippets 與 SQL 引擎並列;`mongoStrategy` 驗證 body 與 params 並支援 map 形式插值。
|
|
81
|
+
- **Recovery — per-code branching for connection codes (MVP)。** `recover --next` 對 connection 類錯誤碼支援多 branch 派發:新增 `buildConnectionBranches` factory(4 個 connection branch)、`matchConnectionBranch` resolver、`classify` emit `branches` / `branchFork`,並提供 `--branch <id>` 旗標讓 agent 顯式選擇 branch。輸出 `NextResult.branchId` 與 markdown 中的 branchId/description 一併呈現。
|
|
82
|
+
|
|
83
|
+
### Changed
|
|
84
|
+
|
|
85
|
+
- **MongoDB `q` 文件升級。** `docs/feature-matrix.md` / 雙語 user docs 將 MongoDB `q` 從 unsupported 改為 limited supported(記載目前支援的 body 形式與限制)。
|
|
86
|
+
- **Recovery schema 新增 `branches` / `branchFork`。** 行為向下相容(無 branch 時與舊版一致);`GuideStep` / `NextResult` / `NextStepOutput` 全鏈打通 `branchId`;`shellQuote` 抽離為共用模組。
|
|
87
|
+
|
|
88
|
+
### Security
|
|
89
|
+
|
|
90
|
+
- **Pin `brace-expansion ^5.0.6`** 修補 GHSA-jxxr-4gwj-5jf2 ReDoS。
|
|
91
|
+
|
|
92
|
+
### Tests
|
|
93
|
+
|
|
94
|
+
- `tests/integration/` — MongoDB tier、blacklist、sampling、snippet 整合覆蓋。
|
|
95
|
+
- 新增 mongo plan + schema envelope shape 的 contract test。
|
|
96
|
+
- Recovery: doctor↔resolver keyword coupling contract test、connection envelope 6 變體 snapshot、`recover` E2E branching(fork / walk / fallback / `--apply` 不變)覆蓋。
|
|
97
|
+
|
|
98
|
+
### Docs
|
|
99
|
+
|
|
100
|
+
- 雙語 user docs 新增 Agent 修復工作流段落(精簡 walkthrough)與 Recovery Cookbook。
|
|
101
|
+
- `assets/SKILL.md` / `assets/reference.md` 補 `--branch` 旗標與 `NextResult.branchId` 說明、MongoDB tier / operator / blacklist / sampling 行為。
|
|
102
|
+
- 統一 npm 套件名為 `@carllee1983/dbcli`;關閉 v1.20.0 Phase 23-04 已知限制段落。
|
|
103
|
+
- `.planning/PROJECT.md` 同步:`bun test`、已 ship 項目移出 OOS。
|
|
104
|
+
|
|
105
|
+
### Internal
|
|
106
|
+
|
|
107
|
+
- `style: [recovery] format with prettier (printWidth 100)` / `style: [mongo] format with prettier (printWidth 100)` — 全面套用 prettier `printWidth 100`。
|
|
108
|
+
- `fix: [test] remove this alias in mongo sampling mock` — 修正 eslint `no-this-alias`。
|
|
109
|
+
- `refactor: [snippets] register mongo as a first-class engine family` / `refactor: [recovery] extract shellQuote to a shared module`。
|
|
8
110
|
|
|
9
111
|
## [1.20.1] - 2026-05-18
|
|
10
112
|
|
|
@@ -420,6 +522,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
420
522
|
### Stable Release
|
|
421
523
|
|
|
422
524
|
dbcli v1.0.0 is the first stable release. All three milestones are complete:
|
|
525
|
+
|
|
423
526
|
- **M1 (v0.6.0):** Smart REPL — interactive shell with SQL + dbcli commands
|
|
424
527
|
- **M2 (v0.8.0):** Schema DDL — CREATE/DROP/ALTER TABLE, INDEX, CONSTRAINT, ENUM
|
|
425
528
|
- **M3 (v1.0.0):** Stabilization — documentation, permission matrix, known limitations update
|
|
@@ -586,6 +689,7 @@ Added table and column-level blacklisting to protect sensitive data from AI agen
|
|
|
586
689
|
### Configuration
|
|
587
690
|
|
|
588
691
|
Blacklist rules stored in `.dbcli`:
|
|
692
|
+
|
|
589
693
|
```json
|
|
590
694
|
{
|
|
591
695
|
"blacklist": {
|
package/README.zh-TW.md
CHANGED
|
@@ -1177,11 +1177,14 @@ Redaction 沿用 v1.19.1 agent-facing JSON 合約的同一來源
|
|
|
1177
1177
|
`recover --apply` 的 JSON 輸出會內嵌 `audit_recent: AuditEntryBrief[]`(最近 5 筆),
|
|
1178
1178
|
讓新 session 立即擁有歷史脈絡。
|
|
1179
1179
|
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1180
|
+
**完整雙向覆蓋(v1.20.1+):** Recovery ↔ audit linkage 已在每一個
|
|
1181
|
+
`--recovery`-capable 指令落地 — `query`、`inspect`、`insert`、`update`、`delete`、
|
|
1182
|
+
`export`、`q`、`schema` 皆 wired。失敗路徑上,audit entry 的 `recovery_ref` 與
|
|
1183
|
+
envelope 的 `audit_ref` 互帶相同 UUID;agent 可從 envelope(`.dbcli/last-recovery.json`)
|
|
1184
|
+
透過 `dbcli audit tail --recovery-ref <id>` 跳到對應的 audit entry,或反向以
|
|
1185
|
+
`dbcli audit show --recovery-ref <id>` 從 audit 找回 envelope。v1.20.0 在 6 個
|
|
1186
|
+
DML/DDL 指令上的部分覆蓋缺口已於 v1.20.1 結清,完整對照表見
|
|
1183
1187
|
[`.planning/phases/25-recovery-envelope-bi-directional-linkage/25-J1-COVERAGE-MATRIX.md`](./.planning/phases/25-recovery-envelope-bi-directional-linkage/25-J1-COVERAGE-MATRIX.md)。
|
|
1184
|
-
Recovery envelope 自身的 linkage 不受影響。
|
|
1185
1188
|
|
|
1186
1189
|
進階 agent 工作流程(session handoff、forensics walk-through)詳見
|
|
1187
1190
|
[`assets/SKILL.md`](./assets/SKILL.md) §Audit Log usage(英文)或
|
package/assets/SKILL.md
CHANGED
|
@@ -9,6 +9,7 @@ Database CLI for AI agents with permission-based access control.
|
|
|
9
9
|
|
|
10
10
|
## AI agent workflow (follow in order)
|
|
11
11
|
|
|
12
|
+
0. `dbcli skill context --format xml` — LLM prompt context payload: serializes connection metadata, schema caches, and saved queries into a compressed XML/JSON structure for prompt injection.
|
|
12
13
|
1. `dbcli inspect --for-agent` — bounded snapshot: connection, permission, blacklist, objects, snippets, suggested next commands.
|
|
13
14
|
2. `dbcli report --format json` — diagnostic report (health/capacity/perf) using built-in snippets.
|
|
14
15
|
3. `dbcli guide <goal> --format json` — deterministic next-command plan for a fixed goal (`slow-query`, `capacity`, `health`, `index-usage`, `permissions`, `schema-overview`). Use `dbcli guide --list` to see goals.
|
|
@@ -49,6 +50,7 @@ Database CLI for AI agents with permission-based access control.
|
|
|
49
50
|
6. `dbcli schema <table> --format json` — real column names (SQL/Mongo/ES) or `schema <key>` (Redis). **Never guess.**
|
|
50
51
|
7. Run `query` / `insert` / `update` / `delete` / `export` within permission.
|
|
51
52
|
8. All writes: `--dry-run` (SQL/Mongo) → run → `query` read-back to confirm.
|
|
53
|
+
- **v1.21.0 Self-Verification Loops**: If a snippet defines a `verify` block in its frontmatter, run the snippet with `dbcli q @name --verify` to automatically run primary changes, execute the verification query, and validate assertions.
|
|
52
54
|
|
|
53
55
|
Prefer `--format json` for agent-friendly output.
|
|
54
56
|
|
|
@@ -68,6 +70,12 @@ The plan output is an ordered list of dbcli commands with rationale and risk
|
|
|
68
70
|
labels. Execute them one at a time — task plans do **not** override blacklist,
|
|
69
71
|
schema, dry-run, or confirmation requirements.
|
|
70
72
|
|
|
73
|
+
Builtin packs: `diagnose-slow-query` and **(v1.23)** `analyze-table-perf` — a
|
|
74
|
+
read-only `plan-only` pack taking a required `table` parameter that walks
|
|
75
|
+
`blacklist list` → `schema <table> --format json` → `guide index-usage`. `dbcli
|
|
76
|
+
inspect` suggests `analyze-table-perf` automatically for the hottest table in
|
|
77
|
+
recent audit activity.
|
|
78
|
+
|
|
71
79
|
Tasks live under `assets/tasks/` (builtin), `.dbcli-shared/tasks/` (shared), and
|
|
72
80
|
`.dbcli/tasks/` (local override).
|
|
73
81
|
|
|
@@ -232,26 +240,27 @@ Full flags and edge cases: see [reference.md](reference.md) `init` section.
|
|
|
232
240
|
| `list` | query-only+ | Tables (SQL), collections (MongoDB), keys (Redis), or indices (Elasticsearch). |
|
|
233
241
|
| `schema` | query-only+ | SQL: per-table or full scan into `.dbcli/schemas/`. MongoDB: sampled. ES: flattened mapping. Redis: per-key only (type/TTL/size). Supports `--recovery`. |
|
|
234
242
|
| `query` | query-only+ | SQL, Mongo JSON (`--collection`), Redis command, or ES DSL/Lucene (`--collection`). `--format table\|json\|csv\|html`, `--ui` to open the interactive dashboard in a browser. Supports `--recovery`. |
|
|
243
|
+
| `explain` | query-only+ | **(v1.23)** Read-only query plan with annotations. SQL only. Single query, `@saved-query`, `@file.sql`, or `--bulk @glob/*`. `--analyze` (EXPLAIN ANALYZE / MariaDB ANALYZE SELECT), `--format markdown\|json\|table`. |
|
|
235
244
|
| `plan` | n/a | Static SQL risk analyzer (`--format text\|json`); classifies a statement without connecting to the database. |
|
|
236
|
-
| `q` | query-only+ | Run a saved snippet by `@name` with `--param k=v`.
|
|
245
|
+
| `q` | query-only+ | Run a saved snippet by `@name` with `--param k=v`. Supports `--verify` to run assertions. |
|
|
237
246
|
| `queries` | n/a | Manage saved snippets: `list` / `show` / `search` / `suggest` / `new` / `edit` / `check` / `delete` / `rename` / `copy` / `import` / `export`. |
|
|
238
247
|
| `insert` / `update` | read-write+ | SQL or MongoDB only. JSON `--data` / `--set`; `--where` required on `update`; `--dry-run` first. Redis writes go through `query`. Supports `--recovery`. |
|
|
239
248
|
| `delete` | data-admin+ | SQL or MongoDB only. `--where` required; `--dry-run` first. Supports `--recovery`. |
|
|
240
|
-
| `export` | query-only+ | SQL or
|
|
249
|
+
| `export` | query-only+ | SQL, MongoDB, or **(v1.22)** Elasticsearch (DSL `--index` or whole-index scroll). Query → `--format json\|jsonl\|csv\|html` file or stdout. `html` emits a standalone interactive dashboard. Supports `--recovery`. |
|
|
241
250
|
| `blacklist` | n/a | `list` / `table` / `column` subcommands redact sensitive data from query results. |
|
|
242
251
|
| `check` | query-only+ | SQL only (best on MySQL/MariaDB). |
|
|
243
252
|
| `diff` | query-only+ | SQL only. Save/compare schema snapshots. |
|
|
244
253
|
| `status` | query-only+ | Safe JSON/text summary (no credentials). |
|
|
245
|
-
| `inspect` | query-only+ | Read-only context snapshot (connection, permission, blacklist, objects, snippets,
|
|
254
|
+
| `inspect` | query-only+ | Read-only context snapshot (connection, permission, blacklist, objects, snippets, context-aware `suggestedCommands`, and **(v1.23)** human-readable `hints`). `--for-agent` / `--brief` / `--no-connect` / `--require-schema-cache`. Supports `--recovery`. |
|
|
246
255
|
| `report` | query-only+ | Diagnostic report (health / capacity / perf) built from `@diag/*` snippets. `--section`, `--brief`, `--for-agent`, `--no-connect`. |
|
|
247
|
-
| `guide` | query-only+ | Deterministic next-command plan for a fixed goal (`slow-query`, `capacity`, `health`, `index-usage`, `permissions`, `schema-overview`). `--list` to enumerate. |
|
|
256
|
+
| `guide` | query-only+ | Deterministic next-command plan for a fixed goal (`slow-query`, `capacity`, `health`, `index-usage`, `permissions`, `schema-overview`). `--list` to enumerate. **(v1.23)** `guide missing-index-for <query>` suggests composite indexes for a single SELECT (`--format yaml\|json\|markdown`, `--min-confidence`). |
|
|
248
257
|
| `recovery` | n/a | Look up the structured `RecoveryEnvelope` for a known error code (`--code <CODE>` or `--list`). Standalone synthesizer; does not require a real failure. |
|
|
249
258
|
| `recover` | n/a | Inspect (default) or `--apply` the auto-saved recovery plan in `.dbcli/last-recovery.json`. `--allow-write=readonly-cmd\|write-cmd`, `--no-verify`, `--from <file>`, `--next --after-step <n> --result <json\|@file>` for multi-turn step-at-a-time. |
|
|
250
259
|
| `doctor` | n/a | Environment, config, connection, SRV diagnostics (Mongo), schema cache age. |
|
|
251
260
|
| `completion` | n/a | bash / zsh / fish scripts. |
|
|
252
261
|
| `upgrade` | n/a | Self-update from npm; 24h-cached version hints on every command. |
|
|
253
|
-
| `shell` | (same as query+) | Interactive REPL. SQL engines +
|
|
254
|
-
| `skill` | n/a | Generate / install AI skill docs (`--install <claude\|gemini\|copilot\|cursor>`); `skill tasks list/show/plan` for Agent Task Packs. |
|
|
262
|
+
| `shell` | (same as query+) | Interactive REPL. SQL engines, MongoDB, and Redis (single-line; `.no-limit on/off`). **(v1.22)** Elasticsearch opens a Kibana Dev Tools-style REPL (`<METHOD> /<path>` + optional JSON body, blank line submits). |
|
|
263
|
+
| `skill` | n/a | Generate / install AI skill docs (`--install <claude\|gemini\|copilot\|cursor>`); `skill tasks list/show/plan` for Agent Task Packs; `skill context` for LLM prompt context payload. |
|
|
255
264
|
| `migrate` | admin | SQL only. **DDL; dry-run by default** — needs `--execute`. |
|
|
256
265
|
|
|
257
266
|
`--use <name>` on any subcommand targets a v2 connection without changing the default.
|
|
@@ -286,19 +295,25 @@ Full flags and edge cases: see [reference.md](reference.md) `init` section.
|
|
|
286
295
|
## Redis
|
|
287
296
|
|
|
288
297
|
- Command-style execution; `query` runs a whitelisted Redis command (e.g. `GET`, `HSET`, `DEL`).
|
|
289
|
-
- **Supported:** `init`, `list` (keys via SCAN), `schema <key>` (type / TTL / size / sample), `query`, `status`, `use`, `doctor`, `upgrade`, `completion`.
|
|
298
|
+
- **Supported:** `init`, `list` (keys via SCAN), `schema <key>` (type / TTL / size / sample), `query`, `shell`, `status`, `use`, `doctor`, `upgrade`, `completion`.
|
|
290
299
|
- **Not supported:** `schema` full scan, `insert`, `update`, `delete`, `export`, `check`, `diff`, `migrate`, `q`.
|
|
291
300
|
Use `query "DEL <key>"` etc. for writes — they go through the same permission gate.
|
|
292
301
|
- Permission tiers map to commands: read commands → `query-only`; mutators (`SET`, `HSET`, ...) → `read-write`; `DEL` / `UNLINK` → `data-admin`.
|
|
293
302
|
- `database` field is the logical DB index (default `0`); `list` returns ≤ 100 000 keys via SCAN.
|
|
303
|
+
- **Size guard:** `SCAN`/`HSCAN`/`SSCAN`/`ZSCAN` inject `COUNT 1000`; `LRANGE`/`ZRANGE` clamp `stop`; `ZRANGEBYSCORE` injects `LIMIT 0 1000`; `HGETALL`/`HKEYS`/`HVALS`/`SMEMBERS`/`KEYS` truncate at 1000. Results carry `warnings[]` (`REDIS_SIZE_REWRITE` / `REDIS_SIZE_TRUNCATE`). Pass `--no-limit` (CLI) or `.no-limit on` (shell) to bypass.
|
|
304
|
+
- **Blacklist:** `dbcli blacklist add 'secrets:*'` registers a Redis-native key glob. Reads/writes whose keys match are rejected (`BlacklistRejection`, audited with `metadata.matched_pattern`); `KEYS`/`SCAN MATCH` overlapping a rule are rejected; non-overlapping listings filter blacklisted keys.
|
|
305
|
+
- **Masking (v1.22):** add a `redis.mask` block to `.dbcli` — keys matching a `keyPattern` glob have their value (or named hash `fields`) returned as `[REDACTED]` on reads (`GET`, `GETRANGE`, `HGETALL`, `HGET`, `HMGET`, `HVALS`). Masking coexists with key-glob rejection, and **rejection always wins over masking**.
|
|
306
|
+
- **Shell:** `dbcli shell` on a Redis connection opens a single-line REPL (history, tab completion of commands + key prefixes, `.no-limit on/off`).
|
|
294
307
|
- See reference.md Redis section.
|
|
295
308
|
|
|
296
309
|
## Elasticsearch
|
|
297
310
|
|
|
298
311
|
- DSL (JSON body) or Lucene query string; `--collection <index>` is required on `query`.
|
|
299
|
-
- **Supported:** `init`, `list` (indices with doc count), `schema [index]` (flattened mapping), `query`, `status`, `use`, `doctor`, `upgrade`, `completion`.
|
|
300
|
-
- **Not supported:** `insert`, `update`, `delete`, `
|
|
312
|
+
- **Supported:** `init`, `list` (indices with doc count), `schema [index]` (flattened mapping), `query`, `export` (v1.22), `shell` (v1.22), `status`, `use`, `doctor`, `upgrade`, `completion`.
|
|
313
|
+
- **Not supported:** `insert`, `update`, `delete`, `check`, `diff`, `migrate`, `q`.
|
|
301
314
|
Writes are not exposed via dedicated subcommands yet — use `query` if the cluster allows or external tools.
|
|
315
|
+
- **Export (v1.22):** `dbcli export` takes a search DSL with `--index <index>` to export hits, or an index name as the query to scroll the whole index via `match_all`. Outputs JSON / JSONL / CSV (default 1000 rows; `--no-limit` scrolls the full index in batches). Index-level blacklist + audit apply.
|
|
316
|
+
- **Shell (v1.22):** `dbcli shell` opens a Kibana Dev Tools-style REPL — request line `<METHOD> /<path>` plus an optional multi-line JSON body, submitted with a blank line; index-level blacklist rejects protected indices and `_search` auto-caps at 1000 when `size` is omitted.
|
|
302
317
|
- Query-only mode caps at 1000 hits; `--no-limit` is bounded at 10 000.
|
|
303
318
|
- Schema flattens nested fields (`a.b.c`) and surfaces `.fields` multi-fields.
|
|
304
319
|
- See reference.md Elasticsearch section.
|
package/assets/SKILL.zh-TW.md
CHANGED
|
@@ -11,6 +11,7 @@ description: 為 AI 代理設計、具權限控管的資料庫 CLI。可用於
|
|
|
11
11
|
|
|
12
12
|
## AI 代理工作流程(依序執行)
|
|
13
13
|
|
|
14
|
+
0. `dbcli skill context --format xml` — LLM 提示詞脈絡載荷:將連線中介資料、Schema 快取和已儲存查詢序列化為高度壓縮的 XML/JSON 結構以進行 Prompt 注入。
|
|
14
15
|
1. `dbcli inspect --for-agent` — 有界快照:連線、權限、blacklist、物件、snippets、建議的下一個指令。
|
|
15
16
|
2. `dbcli report --format json` — 使用內建 snippets 產出診斷報告(health / capacity / perf)。
|
|
16
17
|
3. `dbcli guide <goal> --format json` — 針對固定目標產出確定性的下一步指令計畫(`slow-query`、`capacity`、`health`、`index-usage`、`permissions`、`schema-overview`)。執行 `dbcli guide --list` 查看所有目標。
|
|
@@ -51,6 +52,7 @@ description: 為 AI 代理設計、具權限控管的資料庫 CLI。可用於
|
|
|
51
52
|
6. `dbcli schema <table> --format json` — 取得真實欄位名稱(SQL / Mongo / ES)或 `schema <key>`(Redis)。**禁止猜測。**
|
|
52
53
|
7. 在允許的權限範圍內執行 `query` / `insert` / `update` / `delete` / `export`。
|
|
53
54
|
8. 所有寫入:`--dry-run`(SQL / Mongo)→ 實際執行 → `query` 回讀確認。
|
|
55
|
+
- **v1.21.0 自我驗證循環(Self-Verification Loops)**:如果 snippet 在其 frontmatter 中定義了 `verify` 區塊,使用 `dbcli q @name --verify` 來執行該 snippet,即可自動跑完主要變更、執行驗證查詢並驗證斷言。
|
|
54
56
|
|
|
55
57
|
代理友善的輸出請優先用 `--format json`。
|
|
56
58
|
|
|
@@ -199,7 +201,7 @@ dbcli init --use-env-refs \
|
|
|
199
201
|
| `schema` | query-only+ | SQL:單表或全掃描存入 `.dbcli/schemas/`。MongoDB:sampled。ES:flattened mapping。Redis:僅單一 key(type / TTL / size)。支援 `--recovery`。 |
|
|
200
202
|
| `query` | query-only+ | SQL、Mongo JSON(`--collection`)、Redis 指令、ES DSL / Lucene(`--collection`)。`--format table\|json\|csv\|html`、`--ui` 開啟瀏覽器互動式 dashboard。支援 `--recovery`。 |
|
|
201
203
|
| `plan` | n/a | 靜態 SQL 風險分析器(`--format text\|json`);不連線即可分類語句。 |
|
|
202
|
-
| `q` | query-only+ | 以 `@name` 執行已儲存 snippet
|
|
204
|
+
| `q` | query-only+ | 以 `@name` 執行已儲存 snippet,搭配 `--param k=v`。支援 `--verify` 以執行斷言。 |
|
|
203
205
|
| `queries` | n/a | 管理已儲存 snippet:`list` / `show` / `search` / `suggest` / `new` / `edit` / `check` / `delete` / `rename` / `copy` / `import` / `export`。 |
|
|
204
206
|
| `insert` / `update` | read-write+ | 僅 SQL 與 MongoDB。JSON `--data` / `--set`;`update` 必填 `--where`;先 `--dry-run`。Redis 寫入透過 `query`。支援 `--recovery`。 |
|
|
205
207
|
| `delete` | data-admin+ | 僅 SQL 與 MongoDB。必填 `--where`;先 `--dry-run`。支援 `--recovery`。 |
|
|
@@ -216,8 +218,8 @@ dbcli init --use-env-refs \
|
|
|
216
218
|
| `doctor` | n/a | 環境、設定、連線、SRV 診斷(Mongo)、schema cache 年齡。 |
|
|
217
219
|
| `completion` | n/a | bash / zsh / fish 腳本。 |
|
|
218
220
|
| `upgrade` | n/a | 從 npm 自我更新;每個指令都帶 24h 快取的版本提示。 |
|
|
219
|
-
| `shell` | (與 query 同) | 互動式 REPL
|
|
220
|
-
| `skill` | n/a | 產出 / 安裝 AI skill
|
|
221
|
+
| `shell` | (與 query 同) | 互動式 REPL。支援 SQL 引擎、MongoDB 與 Redis(單行;`.no-limit on/off`)。 |
|
|
222
|
+
| `skill` | n/a | 產出 / 安裝 AI skill 文件(`--install <claude\|gemini\|copilot\|cursor>`);`skill tasks list/show/plan` 提供 Agent Task Packs;`skill context` 提供 LLM 提示詞脈絡載荷。 |
|
|
221
223
|
| `migrate` | admin | 僅 SQL。**DDL;預設 dry-run** — 需 `--execute` 才會真的執行。 |
|
|
222
224
|
|
|
223
225
|
任何子指令上的 `--use <name>` 都會把目標切到對應的 v2 連線,但不改變預設值。
|
|
@@ -252,11 +254,14 @@ dbcli init --use-env-refs \
|
|
|
252
254
|
## Redis
|
|
253
255
|
|
|
254
256
|
- 指令式執行;`query` 跑白名單內的 Redis 指令(例如 `GET`、`HSET`、`DEL`)。
|
|
255
|
-
- **支援:** `init`、`list`(透過 SCAN 列 keys)、`schema <key>`(type / TTL / size / sample)、`query`、`status`、`use`、`doctor`、`upgrade`、`completion`。
|
|
257
|
+
- **支援:** `init`、`list`(透過 SCAN 列 keys)、`schema <key>`(type / TTL / size / sample)、`query`、`shell`、`status`、`use`、`doctor`、`upgrade`、`completion`。
|
|
256
258
|
- **不支援:** `schema` 全掃描、`insert`、`update`、`delete`、`export`、`check`、`diff`、`migrate`、`q`。
|
|
257
259
|
寫入請走 `query "DEL <key>"` 等 — 同樣經過權限門檻。
|
|
258
260
|
- 權限分層對應指令:讀取類 → `query-only`;mutator(`SET`、`HSET`、...)→ `read-write`;`DEL` / `UNLINK` → `data-admin`。
|
|
259
261
|
- `database` 欄位是 logical DB index(預設 `0`);`list` 透過 SCAN 最多回傳 100 000 個 keys。
|
|
262
|
+
- **大小防護(size guard):** `SCAN`/`HSCAN`/`SSCAN`/`ZSCAN` 自動補上 `COUNT 1000`;`LRANGE`/`ZRANGE` 夾限 `stop`;`ZRANGEBYSCORE` 補上 `LIMIT 0 1000`;`HGETALL`/`HKEYS`/`HVALS`/`SMEMBERS`/`KEYS` 在 1000 筆截斷。結果帶有 `warnings[]`(`REDIS_SIZE_REWRITE` / `REDIS_SIZE_TRUNCATE`)。以 `--no-limit`(CLI)或 `.no-limit on`(shell)略過。
|
|
263
|
+
- **黑名單:** `dbcli blacklist add 'secrets:*'` 註冊 Redis 原生 key glob。命中規則的讀寫會被拒絕(`BlacklistRejection`,稽核記錄含 `metadata.matched_pattern`);與規則重疊的 `KEYS`/`SCAN MATCH` 會被拒絕;未重疊的列舉會濾掉黑名單 keys。
|
|
264
|
+
- **Shell:** Redis 連線執行 `dbcli shell` 會開啟單行 REPL(歷史、指令與 key 前綴 tab 補全、`.no-limit on/off`)。
|
|
260
265
|
- 詳見 reference.md Redis 段落。
|
|
261
266
|
|
|
262
267
|
## Elasticsearch
|
package/assets/reference.md
CHANGED
|
@@ -161,6 +161,40 @@ dbcli query "SELECT * FROM orders" --format html > orders.html # pipe to stdou
|
|
|
161
161
|
> - Hits are flattened: each result row contains `_id` plus dotted-path fields from `_source`. Pass `--format json` to keep nested structures readable.
|
|
162
162
|
> - Query-only mode caps at 1000 hits; `--no-limit` is internally capped at 10 000 (use saved searches / `search_after` for deeper pagination).
|
|
163
163
|
|
|
164
|
+
### explain
|
|
165
|
+
|
|
166
|
+
**(v1.23)** Read-only query-plan inspection across MySQL/MariaDB and PostgreSQL,
|
|
167
|
+
wrapping `EXPLAIN` / `EXPLAIN ANALYZE` / MariaDB `ANALYZE SELECT` behind one
|
|
168
|
+
interface. Output is a unified `ExplainRow` schema plus severity-coded
|
|
169
|
+
annotations. SQL `SELECT` only.
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
dbcli explain "SELECT * FROM betting_logs WHERE settled_at >= '2026-03-01'"
|
|
173
|
+
dbcli explain @analytics/live-summary # saved query
|
|
174
|
+
dbcli explain @file.sql # @file reference
|
|
175
|
+
dbcli explain --analyze "SELECT ..." # MariaDB ANALYZE SELECT / PG EXPLAIN ANALYZE
|
|
176
|
+
dbcli explain --format json "..." # markdown (default) | json | table
|
|
177
|
+
dbcli explain --bulk @queries.sql # batch from file
|
|
178
|
+
dbcli explain --bulk @analytics/* # glob over saved queries
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
**Options:** `--analyze` (run the query for real — EXPLAIN ANALYZE / ANALYZE SELECT), `--format <markdown|json|table>` (default `markdown`), `--bulk <input>` (comma-separated `@file` / `@glob` / `@saved-query`).
|
|
182
|
+
**Permission:** query-only+ (no upgrade required).
|
|
183
|
+
|
|
184
|
+
**Annotations:**
|
|
185
|
+
|
|
186
|
+
| Rule | Severity | Triggered when |
|
|
187
|
+
|---|---|---|
|
|
188
|
+
| `full-scan` | red | MySQL `type=ALL` or `key=NULL`; PG `Seq Scan` |
|
|
189
|
+
| `temp-table` | yellow | MySQL `Using temporary` |
|
|
190
|
+
| `filesort` | yellow | MySQL `Using filesort`; PG `Sort Method: external merge` |
|
|
191
|
+
| `cost-estimate-skew` | gray | `--analyze` actual rows / planner rows > 10× |
|
|
192
|
+
| `nested-loop-large` | yellow | PG `Nested Loop` with planner rows > 10,000 |
|
|
193
|
+
|
|
194
|
+
> Notes:
|
|
195
|
+
> - `--analyze` executes the statement — do not use against destructive SQL.
|
|
196
|
+
> - Auto-`LIMIT` is **not** applied to EXPLAIN statements (since v1.23 P1).
|
|
197
|
+
|
|
164
198
|
### plan
|
|
165
199
|
|
|
166
200
|
Static SQL risk analyzer. Classifies a statement into the same permission tiers
|
|
@@ -480,13 +514,20 @@ dbcli export "SELECT * FROM users" --format csv --output users.csv --force # Sk
|
|
|
480
514
|
dbcli export "SELECT * FROM users" --format json | jq '.[]'
|
|
481
515
|
dbcli export "SELECT * FROM users" --format jsonl --output users.ndjson
|
|
482
516
|
dbcli export "SELECT * FROM orders" --format html --output orders.html # standalone dashboard
|
|
517
|
+
|
|
518
|
+
# Elasticsearch (v1.22)
|
|
519
|
+
dbcli export '{"query":{"match":{"status":"active"}}}' --index orders --format jsonl --output orders.ndjson
|
|
520
|
+
dbcli export orders --format csv --output orders.csv # index name as query → match_all + scroll
|
|
521
|
+
dbcli export orders --no-limit --format jsonl # scroll the whole index in batches
|
|
483
522
|
```
|
|
484
523
|
|
|
485
|
-
**Options:** `--format <json|jsonl|csv|html>` (required), `--output <path>`, `--force`, `--recovery`
|
|
486
|
-
**Permission:** query-only+
|
|
524
|
+
**Options:** `--format <json|jsonl|csv|html>` (required), `--output <path>`, `--force`, `--recovery`, `--index <name>` (Elasticsearch), `--no-limit` (Elasticsearch full-index scroll)
|
|
525
|
+
**Permission:** query-only+ — SQL, MongoDB, and **(v1.22)** Elasticsearch.
|
|
487
526
|
|
|
488
527
|
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.
|
|
489
528
|
|
|
529
|
+
> **Elasticsearch export (v1.22):** pass a search DSL with `--index <index>` to export the hits, or pass an index name as the query to scroll the whole index via `match_all`. Default cap is 1000 rows; `--no-limit` streams the full index via scroll in batches. Index-level blacklist is checked before export and an audit record is written.
|
|
530
|
+
|
|
490
531
|
### blacklist
|
|
491
532
|
|
|
492
533
|
Manage sensitive data blacklist to prevent AI access to restricted tables/columns.
|
|
@@ -554,6 +595,8 @@ Read-only snapshot for AI agents. Never emits credentials or blacklisted values.
|
|
|
554
595
|
| `--for-agent` | Shortcut for `--format json --brief` |
|
|
555
596
|
| `--no-connect` | Skip the cheap version/object probe (no DB traffic) |
|
|
556
597
|
| `--probe-timeout <ms>` | Hard timeout for the version/object probe (default 1500) |
|
|
598
|
+
| `--require-schema-cache` | Throw `SCHEMA_CACHE_MISSING` (recovery code) when the active SQL connection has no usable schema cache |
|
|
599
|
+
| `--recovery` | On failure, emit a structured `RecoveryEnvelope` to stdout |
|
|
557
600
|
|
|
558
601
|
Example:
|
|
559
602
|
|
|
@@ -561,7 +604,14 @@ Example:
|
|
|
561
604
|
dbcli inspect --for-agent
|
|
562
605
|
```
|
|
563
606
|
|
|
564
|
-
Output schema is locked at `schemaVersion: 1`. Sections: `connection`, `permission`, `blacklist`, `objects`, `schemaCache`, `snippets`, `suggestedCommands`, `warnings`.
|
|
607
|
+
Output schema is locked at `schemaVersion: 1`. Sections: `connection`, `permission`, `blacklist`, `objects`, `schemaCache`, `snippets`, `suggestedCommands`, `hints` **(v1.23)**, `warnings`.
|
|
608
|
+
|
|
609
|
+
**`suggestedCommands` (context-aware, v1.23)** — a three-tier weighted list:
|
|
610
|
+
1. *Bootstrap* — always-safe orientation commands (`blacklist list`, `schema <table>`, ...).
|
|
611
|
+
2. *Context-aware* — driven by recent activity. When a hot table is detected in the audit log **and** task packs are available, suggests `dbcli skill tasks plan analyze-table-perf --param table=<table>` plus `dbcli queries suggest <intent>` from your snippet intents.
|
|
612
|
+
3. *Discovery* — broader exploration commands.
|
|
613
|
+
|
|
614
|
+
**`hints` (v1.23)** — a parallel array of human-readable, non-executable notes: the most-queried table from recent audit, the number of available task packs, and the schema-cache size with its last-refresh timestamp. In markdown output they render as a `## Hints` section. Audit reads here are read-only and never throw. Both `suggestedCommands` and `hints` are trimmed under `--for-agent` / `--brief` (≤ 3 hints, single safest command).
|
|
565
615
|
|
|
566
616
|
**Permission:** query-only+
|
|
567
617
|
|
|
@@ -633,6 +683,30 @@ Boundaries:
|
|
|
633
683
|
|
|
634
684
|
**Permission:** query-only+
|
|
635
685
|
|
|
686
|
+
#### guide missing-index-for (v1.23)
|
|
687
|
+
|
|
688
|
+
A single-query composite-index advisor. Parses one `SELECT`, combines a real
|
|
689
|
+
`EXPLAIN` plan with existing indexes, and emits index candidates each carrying a
|
|
690
|
+
`confidence` (`high` / `medium` / `low`) and a `reason`. Read-only (EXPLAIN +
|
|
691
|
+
index introspection only). MySQL/MariaDB + PostgreSQL.
|
|
692
|
+
|
|
693
|
+
```bash
|
|
694
|
+
dbcli guide missing-index-for "SELECT ... FROM betting_logs b JOIN hoster_machines hm ON ..."
|
|
695
|
+
dbcli guide missing-index-for @analytics/live-summary # @saved-query
|
|
696
|
+
dbcli guide missing-index-for "..." --format json # yaml (default) | json | markdown
|
|
697
|
+
dbcli guide missing-index-for "..." --min-confidence medium # drop candidates below low|medium|high
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
**Options:** `--format <yaml|json|markdown>` (default `yaml`), `--min-confidence <low|medium|high>`.
|
|
701
|
+
|
|
702
|
+
Behaviour:
|
|
703
|
+
- Detects existing-index collisions (a single-column index that can be extended into a composite).
|
|
704
|
+
- Functional/expression columns (e.g. `DATE(settled_at)`) and SQL it cannot parse are reported under `warnings`, never as recommendations.
|
|
705
|
+
- Single `SELECT` only — no INSERT/UPDATE/DELETE, stored procedures, or view bodies.
|
|
706
|
+
- Dialects beyond node-sql-parser support fall back to EXPLAIN-only heuristics.
|
|
707
|
+
|
|
708
|
+
**Permission:** query-only+
|
|
709
|
+
|
|
636
710
|
### recovery
|
|
637
711
|
|
|
638
712
|
Machine-readable error envelope. Two surfaces share one `RecoveryEnvelope`
|
|
@@ -1005,6 +1079,11 @@ Inside the shell:
|
|
|
1005
1079
|
- Multi-line SQL: keeps accumulating until `;` is found
|
|
1006
1080
|
- History persists across sessions (~/.dbcli_history)
|
|
1007
1081
|
|
|
1082
|
+
The REPL flavor depends on the active engine: SQL engines and MongoDB use the
|
|
1083
|
+
form above; **Redis** opens a single-line command REPL (see [Redis › Interactive
|
|
1084
|
+
shell](#interactive-shell)); **Elasticsearch** opens a Kibana Dev Tools-style
|
|
1085
|
+
REPL (v1.22, see [Elasticsearch › Interactive shell](#interactive-shell-v122)).
|
|
1086
|
+
|
|
1008
1087
|
### migrate
|
|
1009
1088
|
|
|
1010
1089
|
Schema DDL operations. **All commands default to dry-run** — use `--execute` to actually run the SQL. Destructive operations (DROP) also require `--force`.
|
|
@@ -1099,6 +1178,16 @@ dbcli skill tasks plan diagnose-slow-query --param query="..." --format json
|
|
|
1099
1178
|
- **show:** prints the full task definition (frontmatter + Agent Notes). Use `--format json` for an agent-friendly contract.
|
|
1100
1179
|
- **plan:** resolves `{{param}}` placeholders, validates required parameters, and emits a stable plan. Plans are **plan-only** in this version — dbcli will never execute the resulting commands automatically.
|
|
1101
1180
|
|
|
1181
|
+
**Builtin packs:** `diagnose-slow-query` and **(v1.23)** `analyze-table-perf` —
|
|
1182
|
+
a read-only (`plan-only`) pack taking a required `table` parameter that walks
|
|
1183
|
+
`blacklist list` → `schema <table> --format json` → `guide index-usage --format json`.
|
|
1184
|
+
`dbcli inspect` suggests `analyze-table-perf` automatically for the hottest table
|
|
1185
|
+
in recent audit activity.
|
|
1186
|
+
|
|
1187
|
+
```bash
|
|
1188
|
+
dbcli skill tasks plan analyze-table-perf --param table=betting_logs --format json
|
|
1189
|
+
```
|
|
1190
|
+
|
|
1102
1191
|
Task storage layers:
|
|
1103
1192
|
|
|
1104
1193
|
| Source | Path | Notes |
|
|
@@ -1531,19 +1620,19 @@ dbcli delete orders --where '{"status":"cancelled"}' --force
|
|
|
1531
1620
|
|
|
1532
1621
|
## Redis Support
|
|
1533
1622
|
|
|
1534
|
-
Redis connections speak Redis commands rather than SQL. The adapter uses
|
|
1623
|
+
Redis connections speak Redis commands rather than SQL. The adapter uses Bun's native `Bun.RedisClient` and exposes a permission-gated surface with a query size guard and key-glob blacklist enforcement.
|
|
1535
1624
|
|
|
1536
|
-
**Supported commands:** `init`, `use`, `list`, `schema`, `query`, `status`, `doctor`, `upgrade`, `completion`
|
|
1625
|
+
**Supported commands:** `init`, `use`, `list`, `schema`, `query`, `shell`, `status`, `doctor`, `upgrade`, `completion`
|
|
1537
1626
|
|
|
1538
1627
|
**Saved queries:** `q` is supported for read-only Redis commands (see "Redis snippets" below).
|
|
1539
1628
|
|
|
1540
|
-
**Not supported (exit with error or unsupported error):** `insert`, `update`, `delete`, `export`, `check`, `diff`, `migrate
|
|
1629
|
+
**Not supported (exit with error or unsupported error):** `insert`, `update`, `delete`, `export`, `check`, `diff`, `migrate`. For writes, run the equivalent Redis command via `query` — the same permission gate applies.
|
|
1541
1630
|
|
|
1542
1631
|
### Connection and configuration
|
|
1543
1632
|
|
|
1544
1633
|
- Required fields: `system: redis`, `host`, `port`. `password` and `database` are optional.
|
|
1545
1634
|
- `database` is the **logical DB index** (`"0"` … `"15"`), kept as a string to play nicely with env-ref bindings. `list` and the connection metadata both label it as the active DB.
|
|
1546
|
-
- `connection.timeout` (ms, default 5000) maps to
|
|
1635
|
+
- `connection.timeout` (ms, default 5000) maps to the client's `connectionTimeout`.
|
|
1547
1636
|
|
|
1548
1637
|
### Permission classification
|
|
1549
1638
|
|
|
@@ -1590,22 +1679,83 @@ dbcli query "DEL temp:lock"
|
|
|
1590
1679
|
dbcli query "HDEL user:42 lastLogin"
|
|
1591
1680
|
```
|
|
1592
1681
|
|
|
1682
|
+
### Size guard (`query --no-limit` / shell `.no-limit`)
|
|
1683
|
+
|
|
1684
|
+
The adapter rewrites unbounded reads before dispatch and truncates oversized replies after:
|
|
1685
|
+
|
|
1686
|
+
| Strategy | Commands | Behavior |
|
|
1687
|
+
|----------|----------|----------|
|
|
1688
|
+
| inject/cap `COUNT` | `SCAN`, `HSCAN`, `SSCAN`, `ZSCAN` | adds `COUNT 1000` when absent; caps a larger `COUNT` to 1000 |
|
|
1689
|
+
| clamp `stop` | `LRANGE`, `ZRANGE`, `ZREVRANGE` | rewrites `stop` so the span ≤ 1000 (`-1` becomes `start+999`) |
|
|
1690
|
+
| inject/cap `LIMIT` | `ZRANGEBYSCORE` | appends `LIMIT 0 1000` when absent; caps a larger count |
|
|
1691
|
+
| client truncate | `HGETALL`, `HKEYS`, `HVALS`, `SMEMBERS`, `KEYS` | keeps the first 1000 entries |
|
|
1692
|
+
|
|
1693
|
+
Rewrites emit a `REDIS_SIZE_REWRITE` warning; truncations emit `REDIS_SIZE_TRUNCATE`. Both surface in the result's `warnings[]`. Pass `--no-limit` (CLI) or toggle `.no-limit on` (shell) to disable all guards.
|
|
1694
|
+
|
|
1695
|
+
### Blacklist enforcement
|
|
1696
|
+
|
|
1697
|
+
Blacklist rules are enforced as **Redis-native key globs** (`*`, `?`, `[abc]`, `[a-z]`):
|
|
1698
|
+
|
|
1699
|
+
```bash
|
|
1700
|
+
dbcli blacklist add 'secrets:*' # register a key-glob rule
|
|
1701
|
+
dbcli query "GET secrets:api_key" # → BlacklistRejection (exit non-zero)
|
|
1702
|
+
dbcli query "MGET safe:k secrets:api" # → rejected (any matching key fails the whole command)
|
|
1703
|
+
dbcli query "KEYS secrets:*" # → rejected (pattern overlaps a rule)
|
|
1704
|
+
dbcli query "KEYS *" # → returns only non-blacklisted keys
|
|
1705
|
+
```
|
|
1706
|
+
|
|
1707
|
+
Rejections are written to the audit log with `success: false` and `metadata.rejection_reason: 'blacklist'` + `matched_pattern`.
|
|
1708
|
+
|
|
1709
|
+
### Value / hash-field masking (v1.22)
|
|
1710
|
+
|
|
1711
|
+
Where the key-glob blacklist *rejects*, masking instead *redacts*: a matched read still
|
|
1712
|
+
runs, but the sensitive value comes back as `[REDACTED]` so an agent can use the command
|
|
1713
|
+
without ever seeing it. Add an optional `redis.mask` block to `.dbcli`:
|
|
1714
|
+
|
|
1715
|
+
```yaml
|
|
1716
|
+
redis:
|
|
1717
|
+
mask:
|
|
1718
|
+
- keyPattern: 'session:*' # whole value redacted on read
|
|
1719
|
+
- keyPattern: 'user:*'
|
|
1720
|
+
fields: [password, token] # only these hash fields redacted
|
|
1721
|
+
```
|
|
1722
|
+
|
|
1723
|
+
- Applies on reads: `GET`, `GETRANGE`, `HGETALL`, `HGET`, `HMGET`, `HVALS`.
|
|
1724
|
+
- A rule without `fields` redacts the entire value; with `fields` only the named hash fields are redacted.
|
|
1725
|
+
- Masking and key-glob rejection coexist, and **rejection always wins over masking** — a key that matches a blacklist rule is rejected, never merely masked.
|
|
1726
|
+
|
|
1727
|
+
### Interactive shell
|
|
1728
|
+
|
|
1729
|
+
`dbcli shell` on a Redis connection opens a single-line REPL:
|
|
1730
|
+
|
|
1731
|
+
```text
|
|
1732
|
+
$ dbcli --use local-redis shell
|
|
1733
|
+
Redis shell: single-line commands; SCAN/LRANGE auto-capped at 1000. Type `.no-limit on` to bypass (unsafe).
|
|
1734
|
+
redis> SCAN 0 # wire args become: SCAN 0 COUNT 1000 (REDIS_SIZE_REWRITE)
|
|
1735
|
+
redis> HGETALL bighash # >1000 fields → kept 1000 (REDIS_SIZE_TRUNCATE)
|
|
1736
|
+
redis> .no-limit on # bypass size guard for this session
|
|
1737
|
+
redis> GET secrets:api_key # → REDIS_BLACKLIST / BlacklistRejection if blacklisted
|
|
1738
|
+
redis> .exit
|
|
1739
|
+
```
|
|
1740
|
+
|
|
1741
|
+
Tab completion offers Redis command names and known key prefixes; history persists to `~/.dbcli_history`.
|
|
1742
|
+
|
|
1593
1743
|
### Limitations
|
|
1594
1744
|
|
|
1595
1745
|
- No `--dry-run` for writes — Redis commands execute immediately. Pair writes with a confirming read (`GET`, `HGETALL`, `EXISTS`).
|
|
1596
1746
|
- No transaction wrapping (`MULTI`/`EXEC`). Submit one command at a time.
|
|
1597
1747
|
- `KEYS` requires `admin`. Prefer `SCAN` for routine work.
|
|
1598
|
-
- Blacklist
|
|
1748
|
+
- Blacklist enforcement covers **keys** (Redis-native globs); value / hash-field **masking** is available via the `redis.mask` config block (v1.22).
|
|
1599
1749
|
|
|
1600
1750
|
## Elasticsearch Support
|
|
1601
1751
|
|
|
1602
1752
|
Elasticsearch connections speak the REST API. The adapter is fetch-based (no SDK) and supports HTTPS, custom CA, API key, basic auth, and Cloud ID.
|
|
1603
1753
|
|
|
1604
|
-
**Supported commands:** `init`, `use`, `list`, `schema`, `query`, `status`, `doctor`, `upgrade`, `completion`
|
|
1754
|
+
**Supported commands:** `init`, `use`, `list`, `schema`, `query`, `export` (v1.22), `shell` (v1.22), `status`, `doctor`, `upgrade`, `completion`
|
|
1605
1755
|
|
|
1606
1756
|
**Saved queries:** `q` is supported for ES JSON DSL bodies (see "Elasticsearch snippets" below).
|
|
1607
1757
|
|
|
1608
|
-
**Not supported (use external tooling):** `insert`, `update`, `delete`, `
|
|
1758
|
+
**Not supported (use external tooling):** `insert`, `update`, `delete`, `check`, `diff`, `migrate`. The permission classifier already understands `_doc` / `_update` / `_bulk` so future write surfaces can be wired in without changing tiers.
|
|
1609
1759
|
|
|
1610
1760
|
### Connection and configuration
|
|
1611
1761
|
|
|
@@ -1658,6 +1808,38 @@ dbcli query '{"size":0,"aggs":{"by_status":{"terms":{"field":"status.keyword"}}}
|
|
|
1658
1808
|
dbcli query 'status:active AND amount:>100' --index orders --limit 100
|
|
1659
1809
|
```
|
|
1660
1810
|
|
|
1811
|
+
### Export (v1.22)
|
|
1812
|
+
|
|
1813
|
+
`dbcli export` supports two shapes on an ES connection:
|
|
1814
|
+
|
|
1815
|
+
```bash
|
|
1816
|
+
# (a) search DSL + --index → export the hits
|
|
1817
|
+
dbcli export '{"query":{"match":{"status":"active"}}}' --index orders --format jsonl --output orders.ndjson
|
|
1818
|
+
|
|
1819
|
+
# (b) index name as the query → match_all over the whole index (scroll)
|
|
1820
|
+
dbcli export orders --format csv --output orders.csv
|
|
1821
|
+
dbcli export orders --no-limit --format jsonl # full index, scrolled in batches
|
|
1822
|
+
```
|
|
1823
|
+
|
|
1824
|
+
- Outputs JSON / JSONL / CSV. Default cap is 1000 rows; `--no-limit` streams the full index via the scroll API in batches.
|
|
1825
|
+
- Index-level blacklist is checked before export and the run is written to the audit log.
|
|
1826
|
+
|
|
1827
|
+
### Interactive shell (v1.22)
|
|
1828
|
+
|
|
1829
|
+
`dbcli shell` on an ES connection opens a Kibana Dev Tools-style REPL:
|
|
1830
|
+
|
|
1831
|
+
```text
|
|
1832
|
+
$ dbcli --use local-es shell
|
|
1833
|
+
GET /orders/_search
|
|
1834
|
+
{
|
|
1835
|
+
"query": { "match": { "status": "active" } }
|
|
1836
|
+
}
|
|
1837
|
+
# ← blank line submits the whole block
|
|
1838
|
+
```
|
|
1839
|
+
|
|
1840
|
+
- Enter a request line `<METHOD> /<path>`, then an optional multi-line JSON body; a **blank line** submits the block. Responses render as pretty-printed JSON.
|
|
1841
|
+
- Read-focused: index-level blacklist rejects protected indices at the front end; a `_search` whose body omits `size` is auto-capped at 1000 hits.
|
|
1842
|
+
|
|
1661
1843
|
### Doctor and diagnostics
|
|
1662
1844
|
|
|
1663
1845
|
`dbcli doctor` runs a dedicated Elasticsearch path:
|
|
@@ -1669,7 +1851,7 @@ dbcli query 'status:active AND amount:>100' --index orders --limit 100
|
|
|
1669
1851
|
|
|
1670
1852
|
### Limitations
|
|
1671
1853
|
|
|
1672
|
-
- Writes (`insert`/`update`/`delete
|
|
1854
|
+
- Writes (`insert`/`update`/`delete`) are not exposed yet — the adapter implements them, but the CLI currently only routes them for SQL and MongoDB. Read-only `export` (v1.22) and the interactive `shell` (v1.22) are available.
|
|
1673
1855
|
- No `_search/scroll` or PIT pagination at the CLI layer; large pulls need a saved external script.
|
|
1674
1856
|
- `check`, `diff`, `migrate`, and `q` are SQL-only and exit with errors (or fall through to a generic "unsupported" path).
|
|
1675
1857
|
- Blacklist column rules are applied to flattened hit rows on `query`; table-level blacklist rejects an index up front.
|