@carllee1983/dbcli 1.51.2 → 1.52.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/.cursor/rules/dbcli.mdc +34 -27
- package/.cursor/skills/dbcli/reference.md +290 -16
- package/.github/skills/dbcli/SKILL.md +31 -24
- package/.github/skills/dbcli/reference.md +290 -16
- package/CHANGELOG.md +37 -0
- package/README.md +1 -0
- package/README.zh-TW.md +1 -0
- package/assets/SKILL.md +31 -24
- package/assets/SKILL.zh-TW.md +44 -29
- package/assets/reference.md +290 -16
- package/assets/tasks/design-review.md +42 -0
- package/dist/cli-runtime.mjs +109629 -0
- package/dist/cli.mjs +140 -108817
- package/dist/core.d.ts +8 -0
- package/package.json +4 -1
- package/plugins/dbcli-agent/skills/dbcli/SKILL.md +31 -24
- package/plugins/dbcli-agent/skills/dbcli/reference.md +290 -16
- package/skills/dbcli/SKILL.md +31 -24
- package/skills/dbcli/reference.md +290 -16
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,43 @@ 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.52.1] - 2026-08-08 - Skill audit: correct claims, per-platform install, drift gate
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- **The skill documented three flags that do not exist.** `q --use` (the global `dbcli --use <name> q` form is the real one), `q --collection` (a MongoDB snippet's `target:` is the only collection source), and `audit tail --recovery-ref` (it lives on `audit show`). The same wrong `audit tail --recovery-ref` is corrected in `docs/user` (en/zh, Markdown and HTML).
|
|
13
|
+
- **The `design` artifact example failed its own validator.** It is replaced with one that validates clean, and the naming rules it has to satisfy are now documented: lowercase kebab-case for design names versus SQL identifiers for tables and columns, endpoints referencing a model rather than a table, strict objects, descriptions that must not contain SQL keywords, and the size limits. Structural violations report `INVALID_ARTIFACT`, a code the severity table did not list.
|
|
14
|
+
- **Stale lists corrected against the CLI.** `--recovery` covers `lint` and `diff`; verification subject kinds include `table` (what `verify constraint` writes); the Redis permission table includes `XLEN` / `XREAD` / `XRANGE` / `XREVRANGE` / `XADD` / `XDEL` / `LREM`; `audit show` lists `--brief` and `--for-agent`; the snippet guard emits `LIMIT 1001`, fetching one extra row to detect truncation. Elasticsearch supports `q`, and the 10 000 bound belongs to `query` — `export --no-limit` streams via the scroll API. `schema --help` claimed `--sample-size` defaults to 50; it is 100.
|
|
15
|
+
- **`design` was unreachable from the skill entry point.** `SKILL.md` did not mention it at all, so an agent asked to design or review a schema would hand-write DDL and bypass the review-only `propose` contract. It now has a command row, both workflows, and a guardrail that a proposed plan is never executed.
|
|
16
|
+
- **Six drifts between the English and Traditional Chinese skills.** The most serious dropped the permission-tier semantics (multi-statement SQL rejected below `admin`, snippets free of write and DDL keywords, `$out` / `$merge` requiring `data-admin`). The MongoDB connection guidance also disagreed between languages — field-by-field is the recommendation, full URI the escape hatch — and the zh-TW side was missing the env-refs MongoDB exception, the `uri`-wins-silently gotcha, `--slow-ms` on `query` and `q`, and the `proxy analyze` action guidance.
|
|
17
|
+
- **Cursor and Windsurf installs were the Claude skill verbatim.** Windsurf does not parse frontmatter, so roughly 900 characters of `description:` were read as rule text; Cursor reads `description` / `globs` / `alwaysApply` and received none of them. Both platforms keep `reference.md` outside the primary file's directory, so every mention of it resolved to nothing. `dbcli skill --install` now shapes the file per platform — Cursor as an Agent Requested rule, Windsurf with the frontmatter stripped and the description kept as prose — and repoints the reference path. Recognizing an existing dbcli install no longer depends on the frontmatter, so a Windsurf reinstall stops backing up dbcli's own file. See ADR 0006.
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- **`reference.md` has an index.** 3300 lines previously offered no way in but a full read or a guessed grep, and the skill pointed at it in prose ("reference.md Redis section"). Those pointers are real anchors now, and a test derives the anchors from the headings so a renamed heading cannot break them silently.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- **The bilingual parity gate compares content, not just shape.** It checked heading levels, fence counts, table rows, and a curated token list for mere presence — every drift above kept that structure intact. It now compares per-section counts of every code token and list item; run against 1.52.0 it reports 48 problems it used to pass. Its success message no longer reads as "the docs are aligned" when it only checked the skeleton.
|
|
26
|
+
- **The skill entry point carries less that an agent cannot act on.** The always-loaded `description` drops from 990 to 626 characters with every trigger branch intact, release markers such as `(v1.23)` and an internal ticket id are gone (an agent has exactly one installed version), and the `proxy` row's flag wall becomes an anchor.
|
|
27
|
+
|
|
28
|
+
## [1.52.0] - 2026-08-07 - Offline database design assistant and slow-query hints
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
|
|
32
|
+
- **Offline database design assistant.** `dbcli design init|validate|render|diff|propose` authors and reviews a version-controlled `dbcli.design.json` beside the code. Every subcommand is offline: none opens a connection, executes DDL, or calls a provider, and `design init` is the only writer — to the explicit `--output` path, refusing to overwrite. `validate` is fail-closed, so `render`, `diff`, and `propose` refuse to work while `error` findings remain; `render` emits `json`, `markdown`, or `mermaid`.
|
|
33
|
+
- **Design drift comparison and review-only proposals.** `design diff` and `design propose` compare the artifact against the local schema cache (`--against-cache`) or local ORM definitions (`--against-orm`, supporting Prisma, DDL, Drizzle, TypeORM, Sequelize, and JSON), with `--orm-format` and `--ignore` for control. `propose` turns drift into a plan a human reviews and never applies a write: each entry carries a `dry-run` or `migration-review` safety level plus `preflight`, `rollback`, and `verification` steps.
|
|
34
|
+
- **Two further design review rules.** `REVERSE_RELATIONSHIP` (error) fires when the same endpoints are declared again in the opposite direction, and `PREFIX_REDUNDANT_INDEX` (warn) fires when a non-unique index is a leading-column prefix of a longer index.
|
|
35
|
+
- **Passive slow-query hint on `query` and `q`.** At or above `--slow-ms` (default 1000, `0` disables), a finished query gains a Performance hint footer and `metadata.performanceAdvisory`. It reuses the execution time already measured — no `EXPLAIN`, no schema read, no second request. The recommendation is engine-aware: PostgreSQL, MySQL, MariaDB, and Redis are pointed at `guide slow-query`; MongoDB and Elasticsearch state the timing instead. `--recovery` suppresses the hint so that envelope keeps its contract.
|
|
36
|
+
|
|
37
|
+
### Changed
|
|
38
|
+
|
|
39
|
+
- **Skill reference documents the new surface.** `skills/dbcli/reference.md` gains the `design` section (subcommands, artifact shape, finding codes and severities, the review-only `propose` contract, and workflows) plus the `--slow-ms` flag and the `metadata.performanceAdvisory` shape, disambiguated from the proxy flag of the same name.
|
|
40
|
+
|
|
41
|
+
### Tests
|
|
42
|
+
|
|
43
|
+
- Gherkin CLI workflow coverage for workspace inspection, blacklist review, and the verification prune dry run.
|
|
44
|
+
|
|
8
45
|
## [1.51.2] - 2026-08-07 - Intent confirmation for business requests
|
|
9
46
|
|
|
10
47
|
### Added
|
package/README.md
CHANGED
|
@@ -1679,6 +1679,7 @@ bun test # full test suite (Bun test runner)
|
|
|
1679
1679
|
bun run typecheck # TypeScript compile-time validation
|
|
1680
1680
|
bun run test:unit # unit + core tests only
|
|
1681
1681
|
bun run test:integration # integration tests
|
|
1682
|
+
bun run test:gherkin # Gherkin feature tests at the CLI boundary
|
|
1682
1683
|
bun run test:docker # integration tests with docker-compose.test.yml (MySQL + PostgreSQL)
|
|
1683
1684
|
bun run build # bundle CLI to dist/ (used before publish)
|
|
1684
1685
|
```
|
package/README.zh-TW.md
CHANGED
|
@@ -1558,6 +1558,7 @@ import {
|
|
|
1558
1558
|
bun test # 完整測試(Bun test runner)
|
|
1559
1559
|
bun run test:unit # 僅單元與 core 測試
|
|
1560
1560
|
bun run test:integration # 整合測試
|
|
1561
|
+
bun run test:gherkin # CLI 邊界的 Gherkin feature 測試
|
|
1561
1562
|
bun run test:docker # 搭配 docker-compose.test.yml(MySQL + PostgreSQL)
|
|
1562
1563
|
bun run build # 建置 CLI 至 dist/(發布前使用)
|
|
1563
1564
|
```
|
package/assets/SKILL.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: dbcli
|
|
3
|
-
description: Database CLI for AI agents with permission-
|
|
3
|
+
description: Database CLI for AI agents with permission-gated access to MySQL, PostgreSQL, MariaDB, MongoDB, Redis, and Elasticsearch. Trigger when: wiring up a connection (`.dbcli` / `.env`, v1 single vs v2 multi-connection, auth mode); running SQL / MongoDB JSON / Redis commands / Elasticsearch DSL; inspecting table, collection, key, or index structure; writing rows or exporting results; building a report, dashboard, or HTML UI; authoring or reviewing a schema design; protecting sensitive data with the blacklist; or recovering after a failed command. For exhaustive flags and examples, read the sibling `reference.md`.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# dbcli
|
|
@@ -71,7 +71,7 @@ afterwards add only the `@diag/*` it does not cover (`missing-indexes`, `locks`,
|
|
|
71
71
|
`export` / `schema` / `inspect` / `lint` / `diff --against-orm`. The command emits a `RecoveryEnvelope` to stdout and saves
|
|
72
72
|
it to `.dbcli/last-recovery.json`; then `dbcli recover` inspects it and `dbcli recover --apply`
|
|
73
73
|
runs the saved plan under risk gating. Multi-turn `--next`, connection branching, and the
|
|
74
|
-
post-apply verify probe are documented in reference.md
|
|
74
|
+
post-apply verify probe are documented in [reference.md](reference.md#recovery-cookbook-agent-walkthroughs).
|
|
75
75
|
|
|
76
76
|
When reporting a check's outcome use the vocabulary `verified` (evidence matched) /
|
|
77
77
|
`not_verified` (check ran and contradicted) / `indeterminate` (ran but ambiguous) /
|
|
@@ -157,6 +157,8 @@ in **How to use dbcli** still applies.
|
|
|
157
157
|
| DB report / dashboard request | `blacklist list` → `queries search <keywords>` / `queries suggest <intent>` → `queries show @<name>` → `q @<name> --ui` or `--format html` |
|
|
158
158
|
| Application data bug | `audit tail --for-agent --n 10` → `blacklist list` → `schema <object>` → narrow query |
|
|
159
159
|
| ORM or migration work | `schema --format json` → `diff --against-orm <orm-schema>` → review error-level drift → proposals via `migrate` (dry-run) → `migration-review` task pack → `diff --against <snapshot>` after applying. |
|
|
160
|
+
| Schema design, no database yet | `design init --output ./dbcli.design.json` → edit → `design validate` → `design render --format mermaid`. With existing ORM models, reconcile via `design diff --against-orm <path>` first. |
|
|
161
|
+
| Design drift on a live database | `blacklist list` → `schema --format json` → `design diff --against-cache` → `design propose --against-cache`, then hand the plan to a human before any migration. |
|
|
160
162
|
| PR database review | Review changed persistence paths, then propose concrete `schema` / `plan` / `dry-run` / `report` / `guide` commands per material claim. |
|
|
161
163
|
| Slow endpoint or query | `report --section perf` → task pack `analyze-table-perf` → `lint "<query>"` → `guide missing-index-for "<query>"`; use `proxy analyze` when logs exist. |
|
|
162
164
|
| Safe data backfill | `blacklist list` → `schema <object>` → count/scope query → `update … --dry-run` → read-back or snippet `--verify`. |
|
|
@@ -193,12 +195,14 @@ Guardrails:
|
|
|
193
195
|
- Separate database facts from application-code inference. Report which dbcli output shaped the conclusion.
|
|
194
196
|
- For writes and backfills, include scope count, dry-run preview, execution command, and read-back.
|
|
195
197
|
- Do not create indexes directly from a performance suggestion; turn them into reviewed migrations.
|
|
198
|
+
- Do not execute the `commands` in a `design propose` plan, and do not create or rewrite
|
|
199
|
+
`dbcli.design.json` unless a human asked for it.
|
|
196
200
|
- Do not print credentials, copied connection strings, or blacklisted values.
|
|
197
201
|
- Durable evidence: `assert … --write-verification-artifact --verification-subject <kind:name>`;
|
|
198
202
|
inspect with `verification summary` / `list` / `show <id>`. The `verify safe-backfill` /
|
|
199
203
|
`migration` / `rollback --kind <ddl|dml>` / `constraint --check <fk|not-null|unique|custom>`
|
|
200
204
|
family runs preflight + `--after-write` checks and **never executes the write**. Full flags
|
|
201
|
-
and the per-command blocks are in reference.md.
|
|
205
|
+
and the per-command blocks are in [reference.md](reference.md#commands).
|
|
202
206
|
|
|
203
207
|
## Audit log
|
|
204
208
|
|
|
@@ -215,7 +219,7 @@ The `inspect` / `guide` / `recover` agent JSON embeds `audit_recent` (last 5 ent
|
|
|
215
219
|
fresh session has immediate history. An envelope's `audit_ref` and an audit entry's
|
|
216
220
|
`recovery_ref` point at each other, so you can pivot either way. Audit is on by default
|
|
217
221
|
(`audit.enabled = false` to opt out); entries are metadata-only (never SQL bodies, `--param`
|
|
218
|
-
values, or result cells) and rotate at ~10 MB / 1000 entries. Full flags: reference.md
|
|
222
|
+
values, or result cells) and rotate at ~10 MB / 1000 entries. Full flags: [reference.md](reference.md#audit).
|
|
219
223
|
|
|
220
224
|
## Quick start
|
|
221
225
|
|
|
@@ -371,7 +375,7 @@ refs have no value to connect with yet.
|
|
|
371
375
|
- **Re-running `init`** — refuses to overwrite without `--force`; never use
|
|
372
376
|
`--force` to "fix" a config full of `{ "$env": "..." }` refs.
|
|
373
377
|
|
|
374
|
-
Full flags and edge cases: see [reference.md](reference.md)
|
|
378
|
+
Full flags and edge cases: see [reference.md](reference.md#init).
|
|
375
379
|
|
|
376
380
|
## Command overview
|
|
377
381
|
|
|
@@ -381,33 +385,34 @@ Full flags and edge cases: see [reference.md](reference.md) `init` section.
|
|
|
381
385
|
| `use` | n/a | Show/switch default named connection (v2 only). |
|
|
382
386
|
| `list` | query-only+ | Tables (SQL), collections (MongoDB), keys (Redis), or indices (Elasticsearch). |
|
|
383
387
|
| `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`. |
|
|
384
|
-
| `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. `--fields` (projection), `--truncate` (cell width), `-f/--query-file` (read query from file or stdin), `--use a,b` (read-only fan-out). Supports `--recovery`. See **Query workflow flags**. |
|
|
385
|
-
| `explain` | query-only+ |
|
|
388
|
+
| `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. `--fields` (projection), `--truncate` (cell width), `-f/--query-file` (read query from file or stdin), `--use a,b` (read-only fan-out). Supports `--recovery`. `--slow-ms <n>` sets the passive slow-query hint threshold (default 1000, `0` off): at or above it, table output gains a `Performance hint` footer and JSON gains `metadata.performanceAdvisory`; it runs no extra diagnostics and is suppressed under `--recovery`. Distinct from the `proxy` flag of the same name. See **Query workflow flags**. |
|
|
389
|
+
| `explain` | query-only+ | 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`. |
|
|
386
390
|
| `lint` | n/a | Static SQL anti-pattern advisor (no DB connection). 9 rules incl. schema-aware implicit-cast / NOT IN-nullable checks via the layered `.dbcli/schemas/` cache; global `--use <conn>` selects a named cache. Findings carry rewrite drafts + guarded `explain` verify commands (`--analyze` only for proven read-only SQL) — report-only, never executes. `--format text\|json\|markdown`, `--min-severity`, `--no-schema`, `--bulk`. Supports `--recovery`. |
|
|
387
391
|
| `plan` | n/a | Static SQL risk analyzer (`--format text\|json`); classifies a statement without connecting to the database. |
|
|
388
|
-
| `q` | query-only+ | Run a saved snippet by `@name` with `--param k=v`. Supports `--verify` to run assertions. |
|
|
392
|
+
| `q` | query-only+ | Run a saved snippet by `@name` with `--param k=v`. Supports `--verify` to run assertions and `--slow-ms <n>` (same passive slow-query hint as `query`). |
|
|
389
393
|
| `queries` | n/a | Manage saved snippets: `list` / `show` / `search` / `suggest` / `new` / `edit` / `check` / `delete` / `rename` / `copy` / `import` / `export`. |
|
|
390
394
|
| `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`. |
|
|
391
395
|
| `delete` | data-admin+ | SQL or MongoDB; Redis has a basic implementation (see Redis section). `--where` required; `--dry-run` first. Supports `--recovery`. |
|
|
392
|
-
| `export` | query-only+ | SQL, MongoDB, or
|
|
396
|
+
| `export` | query-only+ | SQL, MongoDB, or Elasticsearch (DSL `--index` or whole-index scroll). Query → `--format json\|jsonl\|csv\|html` file or stdout. `html` emits a standalone interactive dashboard. **Fails closed rather than truncating silently**: if the auto-limit would drop rows, the export errors out and you must pass `--no-limit` or `--limit N`. Supports `--recovery`. |
|
|
393
397
|
| `blacklist` | n/a | `list` / `table` / `column` subcommands redact sensitive data from query results. |
|
|
394
398
|
| `check` | query-only+ | SQL only (best on MySQL/MariaDB). |
|
|
395
|
-
| `diff` | query-only+ | SQL only. Save/compare schema snapshots.
|
|
396
|
-
| `
|
|
397
|
-
| `
|
|
399
|
+
| `diff` | query-only+ | SQL only. Save/compare schema snapshots. `--against-orm <path>` compares a Prisma schema / DDL file / normalized JSON against the local schema cache (no DB connection): categorized drift (`missing_in_db` = error, `missing_in_orm` = warn, `mismatch` per tolerance table, `unmanaged`) with dry-run `migrate` proposals; exit 1 on error-level drift. `--orm-format prisma\|ddl\|json\|drizzle\|typeorm\|sequelize`, `--ignore <globs>`, `--format json\|table\|markdown`. Drizzle: point at `drizzle/meta/<NNNN>_snapshot.json` (run `drizzle-kit generate` first; `.ts` sources are rejected with a hint). TypeORM/Sequelize: feed tool-generated DDL (`schema:log` / a schema-only dump); source files are rejected with the exact generation command to run. |
|
|
400
|
+
| `design` | n/a | Offline SQL design assistant over a version-controlled `dbcli.design.json`: never connects, never runs DDL, never calls a provider. `init --output <path>` is the only writer and refuses to overwrite; `validate` is fail-closed, so `render` / `diff` / `propose` refuse to run while `error` findings remain. `diff` / `propose` need exactly one of `--against-cache` or `--against-orm <paths>`. **`propose` is review-only — it plans, it never writes.** Naming rules, finding codes, and the artifact shape are in [reference.md](reference.md#design). |
|
|
401
|
+
| `snapshot` | query-only+ | SQL only. Capture a result fingerprint (`rowCount` + per-column null/distinct/min/max/sum + order-independent checksum). `--out` (default `.dbcli/snapshots/snap-<ts>.json`), `--rows`, `--stdout`, `--format`, `--no-limit`. Baseline for `assert --against`. |
|
|
402
|
+
| `assert` | query-only+ | SQL only. Verify an invariant; exit 1 on failure unless `--no-fail`. `--expect "rows>0\|value==X\|col:c not null\|unique\|between a and b\|>= n"`, `--vs <query> --compare rows\|value` (reconcile), `--against <snapshot> --tolerance <pct>`. |
|
|
398
403
|
| `verification` | n/a | Inspect and manage local verification artifacts. `list` / `show <id-or-path>` / `summary` are read-only; `prune` is dry-run by default and deletes only with `--execute --force`. Reads `<cwd>/.dbcli/verification/`; no DB connection, no audit writes. |
|
|
399
404
|
| `backfill artifact` | n/a | Build a bounded, reviewable source-to-SQL backfill artifact from JSON. Includes source/target identity, blacklist/schema preflight, read-back verification, and rollback hints; dry-run only and never executes writes. |
|
|
400
|
-
| `proxy` | n/a |
|
|
405
|
+
| `proxy` | n/a | MySQL/MariaDB/PostgreSQL only. Local-dev observability proxy — relays app traffic to the real DB and appends query/latency/byte/error events to `.dbcli/proxy/events.jsonl`. Observe-only. `proxy analyze` aggregates that log offline (summary, byFingerprint, slowest, errors, hotTables, N+1; `--format markdown` produces the QueryLens report) and errors out if no events exist. Act on it: run each finding's `suggestedCommands`, read its `hints`, then propose the fix — never guess a table name, confirm with `schema`. Protect the log itself with `--redact literals`. [Flags](reference.md#proxy). |
|
|
401
406
|
| `status` | query-only+ | Safe JSON/text summary (no credentials). |
|
|
402
|
-
| `inspect` | query-only+ | Read-only context snapshot (connection, permission, blacklist, objects, snippets, context-aware `suggestedCommands`, and
|
|
407
|
+
| `inspect` | query-only+ | Read-only context snapshot (connection, permission, blacklist, objects, snippets, context-aware `suggestedCommands`, and human-readable `hints`). `--for-agent` / `--brief` / `--no-connect` / `--require-schema-cache`. Supports `--recovery`. |
|
|
403
408
|
| `report` | query-only+ | Diagnostic report built from `@diag/*` snippets. `--section <health\|capacity\|perf>` (comma-separated to combine), `--brief`, `--for-agent`, `--no-connect`. |
|
|
404
|
-
| `guide` | query-only+ | Deterministic next-command plan for a fixed goal (`slow-query`, `capacity`, `health`, `index-usage`, `permissions`, `schema-overview`). `--list` to enumerate.
|
|
409
|
+
| `guide` | query-only+ | Deterministic next-command plan for a fixed goal (`slow-query`, `capacity`, `health`, `index-usage`, `permissions`, `schema-overview`). `--list` to enumerate. `guide missing-index-for <query>` suggests composite indexes for a single SELECT (`--format yaml\|json\|markdown`, `--min-confidence`). |
|
|
405
410
|
| `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. |
|
|
406
411
|
| `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. |
|
|
407
412
|
| `doctor` | n/a | Environment/runtime identity, config, connection, SRV diagnostics (Mongo), schema cache age. `--format json --remediation` emits candidate-only blacklist/schema/bounded-sample plans (SQL: `dbcli plan` → human-confirmed bounded `dbcli query`; MongoDB/Elasticsearch: `dbcli schema` preflight → human-confirmed bounded query); it never applies them. |
|
|
408
413
|
| `completion` | n/a | bash / zsh / fish scripts. |
|
|
409
414
|
| `upgrade` | n/a | Self-update from npm; 24h-cached version hints on every command. |
|
|
410
|
-
| `shell` | (same as query+) | Interactive REPL. SQL engines, MongoDB, and Redis (single-line; `.no-limit on/off`).
|
|
415
|
+
| `shell` | (same as query+) | Interactive REPL. SQL engines, MongoDB, and Redis (single-line; `.no-limit on/off`). Elasticsearch opens a Kibana Dev Tools-style REPL (`<METHOD> /<path>` + optional JSON body, blank line submits). |
|
|
411
416
|
| `skill` | n/a | Generate / install AI skill docs (`--install <claude\|gemini\|antigravity\|copilot\|cursor\|codex\|windsurf>`); `skill tasks list/show/plan` for Agent Task Packs; `skill context` for an LLM prompt-context payload (for injecting into another LLM, not needed for normal operation). |
|
|
412
417
|
| `semantic` | n/a | Validate, search, inspect drift, migrate to v2, or print the optional project-root `dbcli.semantic.json`. Give its reviewed context to an external agent, but keep provider credentials, prompts, and agent context outside dbcli. `semantic draft validate --input <file|-> [--format text\|json]` validates only the explicit untrusted `QueryDraft` offline against local semantic/schema/saved-query metadata; it returns safe hashes/references/violation codes, never executes or echoes candidate SQL. Review the original draft, then invoke `explain` or `query` separately if intended. |
|
|
413
418
|
| `migrate` | admin | SQL only. **DDL; dry-run by default** — needs `--execute`. |
|
|
@@ -475,12 +480,12 @@ truncation from a round number. This applies to `query` and to `q` snippets
|
|
|
475
480
|
explicit operators (`$set`/`$inc`/`$push`/…) pass through. Nested blacklist accepts dotted
|
|
476
481
|
paths (`profile.email`) and trailing wildcards (`profile.tokens.*`). Saved snippets end in
|
|
477
482
|
`.mongodb.sql` (frontmatter `engine: mongodb`, `operation: find|aggregate`). Full
|
|
478
|
-
write-planner tiers and syntax: reference.md
|
|
483
|
+
write-planner tiers and syntax: [reference.md](reference.md#mongodb-support).
|
|
479
484
|
|
|
480
485
|
## Redis
|
|
481
486
|
|
|
482
487
|
- `query` runs a single **whitelisted** Redis command (e.g. `GET`, `SET`, `HSET`, `DEL`).
|
|
483
|
-
The full whitelist and the per-command permission tier are defined in reference.md.
|
|
488
|
+
The full whitelist and the per-command permission tier are defined in [reference.md](reference.md#redis-support).
|
|
484
489
|
- **Supported:** `init`, `list` (keys via SCAN), `schema <key>` (type / TTL / size / sample),
|
|
485
490
|
`query`, `q` (saved snippets — **read-only commands only**), `delete` (basic implementation:
|
|
486
491
|
`DEL` / `HDEL` / `LREM` / `SREM` / `ZREM`, needs `data-admin`; `query "DEL <key>"` also
|
|
@@ -493,7 +498,7 @@ truncation from a round number. This applies to `query` and to `q` snippets
|
|
|
493
498
|
blacklist (matching reads/writes are rejected). To preview a delete, use `delete <key> --dry-run`.
|
|
494
499
|
- `database` is the logical DB index (default `0`). `dbcli blacklist table add 'secrets:*'`
|
|
495
500
|
registers a key glob; an optional `redis.mask` block masks values on read. Size guards
|
|
496
|
-
(SCAN/HGETALL truncation, `--no-limit` to bypass) and masking details: reference.md
|
|
501
|
+
(SCAN/HGETALL truncation, `--no-limit` to bypass) and masking details: [reference.md](reference.md#redis-support).
|
|
497
502
|
|
|
498
503
|
## Elasticsearch
|
|
499
504
|
|
|
@@ -505,12 +510,14 @@ dbcli query '{"query":{"match":{"status":"active"}}}' --collection orders
|
|
|
505
510
|
|
|
506
511
|
- `query` takes a DSL (JSON body) or Lucene query string; `--collection <index>` is required.
|
|
507
512
|
- **Supported:** `init`, `list` (indices with doc count), `schema [index]` (flattened mapping),
|
|
508
|
-
`query`, `
|
|
513
|
+
`query`, `q` (snippets use the `.elasticsearch.sql` extension), `export`,
|
|
514
|
+
`shell`, `status`, `use`, `doctor`. **Not supported:**
|
|
509
515
|
`insert`, `update`, `delete`, `check`, `diff`, `migrate`.
|
|
510
516
|
- `export` takes a search DSL with `--index <index>`, or an index name as the query to scroll
|
|
511
|
-
the whole index via `match_all`. Query-only caps at 1000 hits; `--no-limit`
|
|
517
|
+
the whole index via `match_all`. Query-only caps at 1000 hits; `--no-limit` streams the whole
|
|
518
|
+
index via the scroll API. (The 10 000 bound belongs to `query`, not `export`.)
|
|
512
519
|
- Schema flattens nested fields (`a.b.c`) and surfaces `.fields` multi-fields. `shell` opens a
|
|
513
|
-
Kibana Dev Tools-style REPL. Full syntax and examples: reference.md
|
|
520
|
+
Kibana Dev Tools-style REPL. Full syntax and examples: [reference.md](reference.md#elasticsearch-support).
|
|
514
521
|
|
|
515
522
|
## Saved queries
|
|
516
523
|
|
|
@@ -575,7 +582,7 @@ dbcli export "SELECT * FROM orders" --format html --output orders.html
|
|
|
575
582
|
When a saved snippet exists, prefer `q @<name> --ui` / `q @<name> --format html` because snippet
|
|
576
583
|
metadata can drive titles, KPI cards, and charts. Blacklist redaction is applied **before**
|
|
577
584
|
rendering. To get KPIs and charts instead of a plain table, add a `visual:` block (`title`,
|
|
578
|
-
`kpis[]`, `charts[]`) to the snippet frontmatter — see reference.md for the full `visual:`
|
|
585
|
+
`kpis[]`, `charts[]`) to the snippet frontmatter — see [reference.md](reference.md#interactive-html-dashboard) for the full `visual:`
|
|
579
586
|
schema. Raw `query` / `export` invocations render a sortable table only.
|
|
580
587
|
|
|
581
588
|
## Common workflows
|
|
@@ -592,6 +599,6 @@ schema. Raw `query` / `export` invocations render a sortable table only.
|
|
|
592
599
|
|
|
593
600
|
- Query-only mode auto-appends `LIMIT 1000`; add `--no-limit` for `information_schema` or statements that break with `LIMIT`.
|
|
594
601
|
- Blacklisted tables and columns are redacted from query output.
|
|
595
|
-
- `schema` reports `estimatedRowCount` and `sizeCategory` (small / medium / large / huge). For large/huge tables add `WHERE` or `LIMIT` — bands in reference.md.
|
|
602
|
+
- `schema` reports `estimatedRowCount` and `sizeCategory` (small / medium / large / huge). For large/huge tables add `WHERE` or `LIMIT` — bands in [reference.md](reference.md#schema).
|
|
596
603
|
- `doctor` on `mongodb+srv://` reports whether SRV resolves natively or through the DoH fallback — useful when the runtime restricts DNS.
|
|
597
604
|
- **Global flags:** `--version`, `--config <path>`, `--global`, `--use <name>`, `--timeout <ms>`, `-v` / `--verbose` / `-vv`, `-q` / `--quiet`, `--no-color` (also honours `NO_COLOR`). Root-level flags must precede the command unless the command explicitly declares a command-level option.
|
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-
|
|
3
|
+
description: Database CLI for AI agents with permission-gated access to MySQL, PostgreSQL, MariaDB, MongoDB, Redis, and Elasticsearch. Trigger when: wiring up a connection (`.dbcli` / `.env`, v1 single vs v2 multi-connection, auth mode); running SQL / MongoDB JSON / Redis commands / Elasticsearch DSL; inspecting table, collection, key, or index structure; writing rows or exporting results; building a report, dashboard, or HTML UI; authoring or reviewing a schema design; protecting sensitive data with the blacklist; or recovering after a failed command. For exhaustive flags and examples, read the sibling `reference.md`.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# dbcli
|
|
@@ -56,7 +56,7 @@ legacy 單檔 `.dbcli`。若要防護同一 OS 使用者的惡意 process,host
|
|
|
56
56
|
|
|
57
57
|
`report --section perf` 已涵蓋 slow-query、index-usage 與 cache-hit 診斷 — 之後只需補上它未涵蓋的 `@diag/*`(`missing-indexes`、`locks`、`connections`、`table-sizes`)。一旦鎖定特定慢語句,`explain --analyze "<SQL>"` 可顯示執行計畫。
|
|
58
58
|
|
|
59
|
-
**失敗時:** 在 `query` / `q` / `insert` / `update` / `delete` / `export` / `schema` / `inspect` / `lint` / `diff --against-orm` 加上 `--recovery`。指令會把 `RecoveryEnvelope` 輸出到 stdout 並儲存到 `.dbcli/last-recovery.json`;然後用 `dbcli recover` 檢視、`dbcli recover --apply` 在風險門控下執行儲存的計畫。Multi-turn `--next`、連線分支與 post-apply 驗證探針詳見 reference.md
|
|
59
|
+
**失敗時:** 在 `query` / `q` / `insert` / `update` / `delete` / `export` / `schema` / `inspect` / `lint` / `diff --against-orm` 加上 `--recovery`。指令會把 `RecoveryEnvelope` 輸出到 stdout 並儲存到 `.dbcli/last-recovery.json`;然後用 `dbcli recover` 檢視、`dbcli recover --apply` 在風險門控下執行儲存的計畫。Multi-turn `--next`、連線分支與 post-apply 驗證探針詳見 [reference.md](reference.md#recovery-cookbook-agent-walkthroughs)。
|
|
60
60
|
|
|
61
61
|
回報驗證結果時使用詞彙:`verified`(證據符合)/ `not_verified`(驗證執行但結果矛盾)/ `indeterminate`(執行但證據不明確)/ `blocked`(因 config、權限、schema、placeholder 或安全閘門導致無法執行)。
|
|
62
62
|
|
|
@@ -115,6 +115,8 @@ dbcli skill tasks plan <task> --param key=value --format json # generate pla
|
|
|
115
115
|
| DB report / dashboard request | `blacklist list` → `queries search <keywords>` / `queries suggest <intent>` → `queries show @<name>` → `q @<name> --ui` 或 `--format html` |
|
|
116
116
|
| 應用程式資料錯誤 | `audit tail --for-agent --n 10` → `blacklist list` → `schema <object>` → 最小查詢 |
|
|
117
117
|
| ORM 或 migration | `schema --format json` → `diff --against-orm <orm-schema>` → 審查 error-level drift → 透過 `migrate` 取得提案(dry-run)→ `migration-review` task pack → 套用後執行 `diff --against <snapshot>`。 |
|
|
118
|
+
| 資料庫設計(尚未有 DB) | `design init --output ./dbcli.design.json` → 編輯 → `design validate` → `design render --format mermaid`。已有 ORM 模型時,先用 `design diff --against-orm <path>` 對齊。 |
|
|
119
|
+
| 既有資料庫的設計漂移 | `blacklist list` → `schema --format json` → `design diff --against-cache` → `design propose --against-cache`,計畫交人類審查後才執行 migration。 |
|
|
118
120
|
| PR 資料庫風險審查 | 審查變更的 persistence path,並針對每個重要主張提出具體 `schema`、`plan`、`dry-run`、`report` 或 `guide` 指令。 |
|
|
119
121
|
| 慢 endpoint 或查詢 | `report --section perf` → task pack `analyze-table-perf` → `lint "<query>"` → `guide missing-index-for "<query>"`;有 proxy log 時使用 `proxy analyze`。 |
|
|
120
122
|
| 安全資料回填 | `blacklist list` → `schema <object>` → count/scope query → `update … --dry-run` → read-back 或 snippet `--verify`。 |
|
|
@@ -149,8 +151,9 @@ dbcli inspect --for-agent --no-connect --format json
|
|
|
149
151
|
- 分離資料庫事實與應用程式推論;回報是哪個 dbcli 輸出影響了結論。
|
|
150
152
|
- 寫入與 backfill 必須包含 scope count、dry-run preview、execution command,以及 read-back。
|
|
151
153
|
- 不要直接從 performance suggestion 建 index;應轉成經過 review 的 migration。
|
|
154
|
+
- 不要執行 `design propose` 計畫裡的 `commands`;未經人類要求,也不要建立或改寫 `dbcli.design.json`。
|
|
152
155
|
- 不要列印 credentials、複製的連線字串或 blacklisted 值。
|
|
153
|
-
- 持久化佐證:`assert … --write-verification-artifact --verification-subject <kind:name>`;以 `verification summary` / `list` / `show <id>` 檢視。`verify safe-backfill` / `migration` / `rollback --kind <ddl|dml>` / `constraint --check <fk|not-null|unique|custom>` 系列執行 preflight + `--after-write` 驗證,**永不執行寫入**。完整旗標與每個指令的區塊詳見 reference.md。
|
|
156
|
+
- 持久化佐證:`assert … --write-verification-artifact --verification-subject <kind:name>`;以 `verification summary` / `list` / `show <id>` 檢視。`verify safe-backfill` / `migration` / `rollback --kind <ddl|dml>` / `constraint --check <fk|not-null|unique|custom>` 系列執行 preflight + `--after-write` 驗證,**永不執行寫入**。完整旗標與每個指令的區塊詳見 [reference.md](reference.md#commands)。
|
|
154
157
|
|
|
155
158
|
## Audit Log 使用
|
|
156
159
|
|
|
@@ -162,7 +165,7 @@ dbcli audit show <id-prefix> # full entry by id prefix (≥4 cha
|
|
|
162
165
|
dbcli audit show --recovery-ref <env-id> # find the entry that emitted an envelope
|
|
163
166
|
```
|
|
164
167
|
|
|
165
|
-
`inspect` / `guide` / `recover` agent JSON 內嵌 `audit_recent`(最近 5 筆)— 新 session 立即有歷史。Envelope 的 `audit_ref` 與 audit entry 的 `recovery_ref` 互為雙向指標,可從任一方向 pivot。Audit 預設開啟(`audit.enabled = false` 可關閉);entry 僅含 metadata(不含 SQL body、`--param` 值或結果 cell),並在約 10 MB / 1000 筆時輪替。完整旗標:reference.md
|
|
168
|
+
`inspect` / `guide` / `recover` agent JSON 內嵌 `audit_recent`(最近 5 筆)— 新 session 立即有歷史。Envelope 的 `audit_ref` 與 audit entry 的 `recovery_ref` 互為雙向指標,可從任一方向 pivot。Audit 預設開啟(`audit.enabled = false` 可關閉);entry 僅含 metadata(不含 SQL body、`--param` 值或結果 cell),並在約 10 MB / 1000 筆時輪替。完整旗標:[reference.md](reference.md#audit)。
|
|
166
169
|
|
|
167
170
|
## 快速開始
|
|
168
171
|
|
|
@@ -192,7 +195,9 @@ dbcli query "SELECT * FROM users" # Execute SQL (auto LIMIT 1000)
|
|
|
192
195
|
`--password` / `--name`(與 `--system`)。
|
|
193
196
|
3. **要哪一個權限層?** 預設取**最低**夠用的:
|
|
194
197
|
`query-only` → `read-write` → `data-admin` → `admin`。透過 `--permission` 設定
|
|
195
|
-
(預設 `query-only
|
|
198
|
+
(預設 `query-only`)。權限層判斷的是「這條語句做什麼」,不是「它怎麼開啟連線」:
|
|
199
|
+
低於 `admin` 時多語句 SQL 一律被拒;snippet 不得含寫入與 DDL 關鍵字;
|
|
200
|
+
MongoDB 的 `$out` / `$merge` 需要 `data-admin`,且在 snippet 與 `export` 中一律拒絕。
|
|
196
201
|
4. **驗證、不要假設。** init 結束後跑 `dbcli status`(系統 + 權限 + blacklist 摘要、不含憑證)與 `dbcli doctor --format json`(env、設定形狀、連線、schema-cache 年齡、Mongo SRV 路徑)。
|
|
197
202
|
|
|
198
203
|
### 每個引擎的必備指令
|
|
@@ -205,11 +210,13 @@ dbcli init --system postgresql --host localhost --port 5432 \
|
|
|
205
210
|
# Reuse an existing .env (DATABASE_URL=postgresql://user:pw@host:5432/db)
|
|
206
211
|
dbcli init # parses .env in cwd
|
|
207
212
|
|
|
208
|
-
# MongoDB —
|
|
213
|
+
# MongoDB — 逐欄位指定(無驗證就省略 --user/--password)
|
|
214
|
+
dbcli init --system mongodb --host localhost --port 27017 --name mydb
|
|
215
|
+
dbcli init --system mongodb --host localhost --port 27017 \
|
|
216
|
+
--user admin --password '<secret>' --auth-source admin --name mydb
|
|
217
|
+
# MongoDB — full URI(進階逃生口:多 host、非標準 driver 選項)
|
|
209
218
|
dbcli init --system mongodb \
|
|
210
219
|
--uri "mongodb+srv://user:pw@cluster.example.mongodb.net/mydb?authSource=admin"
|
|
211
|
-
# MongoDB — discrete params (no auth = omit --user/--password)
|
|
212
|
-
dbcli init --system mongodb --host localhost --port 27017 --name mydb
|
|
213
220
|
|
|
214
221
|
# Redis — `--name` is the LOGICAL DB INDEX ("0".."15"), not a database name
|
|
215
222
|
dbcli init --system redis --host localhost --port 6379 --password '<secret>' --name 0
|
|
@@ -249,7 +256,7 @@ dbcli --global query "SELECT 1"
|
|
|
249
256
|
|
|
250
257
|
`--global` 必須放在指令之前。未帶它時,指令仍使用目前專案的 `.dbcli` binding;全域與專案 registry 彼此獨立。
|
|
251
258
|
|
|
252
|
-
每個命名連線的 schema cache 存於 `.dbcli/schemas/<connection>/`。在 `schema <table>` 前,每個連線都先跑一次 `dbcli schema --use <name>` — 否則 cache 可能回傳到別的連線欄位。`schema --refresh` / `--reset` 管理 cache(reference.md)。`--skip-test` 跳過 init 時的 TCP 連線測試;使用 `--use-env-refs` 時會自動隱含(`$env` refs 尚無值可連線)。`--system` 在 v2 中為選填 — 若省略,引擎會從 `--env-file` / `.env`(`DATABASE_URL` scheme)推斷,預設為 `postgresql`。
|
|
259
|
+
每個命名連線的 schema cache 存於 `.dbcli/schemas/<connection>/`。在 `schema <table>` 前,每個連線都先跑一次 `dbcli schema --use <name>` — 否則 cache 可能回傳到別的連線欄位。`schema --refresh` / `--reset` 管理 cache([reference.md](reference.md#schema))。`--skip-test` 跳過 init 時的 TCP 連線測試;使用 `--use-env-refs` 時會自動隱含(`$env` refs 尚無值可連線)。`--system` 在 v2 中為選填 — 若省略,引擎會從 `--env-file` / `.env`(`DATABASE_URL` scheme)推斷,預設為 `postgresql`。
|
|
253
260
|
|
|
254
261
|
### env-refs(把機密排除在 `.dbcli` 之外)
|
|
255
262
|
|
|
@@ -267,15 +274,22 @@ dbcli init --conn-name prod --env-file .env.production --use-env-refs --skip-tes
|
|
|
267
274
|
|
|
268
275
|
在**互動式終端機**中,省略 `--env-*` 旗標會逐一提示輸入 key 名稱(預設如上)— 可輸入非預設名稱如 `PROD_DB_PASSWORD`,它會以 `$env` ref 形式儲存。在**非互動式 / CI** 環境中,**必須**傳齊全部五個 `--env-*` 旗標;否則 `init` 會以錯誤退出 — 不會靜默 fallback 為明文。`--env-file <path>` 是 env 檔路徑,與 `$env` key 名稱無關。
|
|
269
276
|
|
|
277
|
+
**MongoDB 是例外**:非互動式下只有 `--env-host` 是必填。`--env-port` / `--env-user` /
|
|
278
|
+
`--env-password` / `--env-database` 皆為選填——省略的欄位會寫成 literal 值(`user` /
|
|
279
|
+
`password` 為空字串,`port` / `database` 為解析後的值)而非 `$env` ref,讓這條連線根本
|
|
280
|
+
用不到的欄位不會日後因未定義變數而 fail closed。此模式下 `init` 也會無視 `--skip-test`
|
|
281
|
+
一律跳過連線測試——`$env` ref 此時還沒有值可以用來連線。
|
|
282
|
+
|
|
270
283
|
### 常見陷阱
|
|
271
284
|
|
|
272
285
|
- **MongoDB `mongodb+srv://`** — `dbcli doctor` 回報 SRV 是用原生方式解析還是走 DoH fallback;在執行環境限制 DNS 時很有用。
|
|
286
|
+
- **MongoDB `authSource` / `replicaSet` / `tls` / `srv`** — `init` 會互動式詢問這些(`authSource` 只在有設 user 時問;`replicaSet` / `tls` 在「advanced options?」提示之後);只有 `--auth-source <db>` 有對應的非互動旗標,所以 `replicaSet` / `tls` 要嘛互動式設定、要嘛事後編輯 `.dbcli`。若一份設定同時有 `uri` 與分項欄位,**`uri` 會靜默勝出** — `dbcli doctor` 會標記這點,也會在 `srv: true` 搭配非預設 `port` 時警告。
|
|
273
287
|
- **MySQL/Postgres 密碼含 `@` `:` `/`** — 使用 `DATABASE_URL` 時要 percent-encode(`@` → `%40`);分項的 `--password` 旗標不需編碼。
|
|
274
288
|
- **Redis `--name`** — 僅接受 logical DB index 字串;非數字會被拒絕。
|
|
275
289
|
- **Elasticsearch TLS** — `caPath` 與 `rejectUnauthorized` 沒有對應旗標;`init` 後直接編輯 `.dbcli` 加上。
|
|
276
290
|
- **重跑 `init`** — 沒有 `--force` 拒絕覆寫;千萬不要為了「修好」一個含 `{ "$env": "..." }` 參照的設定而用 `--force`。
|
|
277
291
|
|
|
278
|
-
完整旗標與邊界案例見 [reference.md](reference.md)
|
|
292
|
+
完整旗標與邊界案例見 [reference.md](reference.md#init)。
|
|
279
293
|
|
|
280
294
|
## 指令總覽 (Command overview)
|
|
281
295
|
|
|
@@ -285,33 +299,34 @@ dbcli init --conn-name prod --env-file .env.production --use-env-refs --skip-tes
|
|
|
285
299
|
| `use` | n/a | 顯示 / 切換預設命名連線(僅 v2)。 |
|
|
286
300
|
| `list` | query-only+ | 資料表(SQL)、collections(MongoDB)、keys(Redis)或 indices(Elasticsearch)。 |
|
|
287
301
|
| `schema` | query-only+ | SQL:單表或全掃描存入 `.dbcli/schemas/`。MongoDB:sampled。ES:flattened mapping。Redis:僅單一 key(type / TTL / size)。支援 `--recovery`。 |
|
|
288
|
-
| `query` | query-only+ | SQL、Mongo JSON(`--collection`)、Redis 指令、ES DSL / Lucene(`--collection`)。`--format table\|json\|csv\|html`、`--ui` 開啟瀏覽器互動式 dashboard。`--fields`(欄位投影)、`--truncate`(欄位值寬度)、`-f/--query-file`(從檔案或 stdin 讀查詢)、`--use a,b`(唯讀扇出)。支援 `--recovery
|
|
289
|
-
| `explain` | query-only+ |
|
|
302
|
+
| `query` | query-only+ | SQL、Mongo JSON(`--collection`)、Redis 指令、ES DSL / Lucene(`--collection`)。`--format table\|json\|csv\|html`、`--ui` 開啟瀏覽器互動式 dashboard。`--fields`(欄位投影)、`--truncate`(欄位值寬度)、`-f/--query-file`(從檔案或 stdin 讀查詢)、`--use a,b`(唯讀扇出)。支援 `--recovery`。`--slow-ms <n>` 設定被動慢查詢提示的門檻(預設 1000,`0` 關閉):達到門檻時 table 輸出多一行 `Performance hint` footer、JSON 多出 `metadata.performanceAdvisory`;它不執行任何額外診斷,且在 `--recovery` 下被抑制。與 `proxy` 的同名旗標不同。見 **查詢工作流程旗標**。 |
|
|
303
|
+
| `explain` | query-only+ | 唯讀查詢計畫並附註解。僅 SQL。單一查詢、`@saved-query`、`@file.sql` 或 `--bulk @glob/*`。`--analyze`(EXPLAIN ANALYZE / MariaDB ANALYZE SELECT)、`--format markdown\|json\|table`。 |
|
|
290
304
|
| `lint` | n/a | 靜態 SQL 反模式顧問(不連線 DB)。共 9 條規則,包含透過分層 `.dbcli/schemas/` 快取進行的 schema-aware implicit-cast / NOT IN-nullable 檢查;全域 `--use <conn>` 會選擇命名連線的快取。Finding 可附 rewrite 草稿與受保護的 `explain` 驗證指令;只有已證明唯讀的 SQL 才會加上 `--analyze`,且只回報、絕不執行。`--format text\|json\|markdown`、`--min-severity`、`--no-schema`、`--bulk`。支援 `--recovery`。 |
|
|
291
305
|
| `plan` | n/a | 靜態 SQL 風險分析器(`--format text\|json`);不連線即可分類語句。 |
|
|
292
|
-
| `q` | query-only+ | 以 `@name` 執行已儲存 snippet,搭配 `--param k=v`。支援 `--verify`
|
|
306
|
+
| `q` | query-only+ | 以 `@name` 執行已儲存 snippet,搭配 `--param k=v`。支援 `--verify` 以執行斷言,以及 `--slow-ms <n>`(與 `query` 相同的被動慢查詢提示)。 |
|
|
293
307
|
| `queries` | n/a | 管理已儲存 snippet:`list` / `show` / `search` / `suggest` / `new` / `edit` / `check` / `delete` / `rename` / `copy` / `import` / `export`。 |
|
|
294
308
|
| `insert` / `update` | read-write+ | 僅 SQL 與 MongoDB。JSON `--data` / `--set`;`update` 必填 `--where`;先 `--dry-run`。Redis 寫入透過 `query`。支援 `--recovery`。 |
|
|
295
309
|
| `delete` | data-admin+ | 僅 SQL 與 MongoDB;Redis 有基本實作(見 Redis 段落)。必填 `--where`;先 `--dry-run`。支援 `--recovery`。 |
|
|
296
|
-
| `export` | query-only+ | SQL、MongoDB 或
|
|
310
|
+
| `export` | query-only+ | SQL、MongoDB 或 Elasticsearch(DSL `--index` 或全 index scroll)。Query → `--format json\|jsonl\|csv\|html` 檔案或 stdout。`html` 輸出獨立可互動 dashboard。**寧可失敗也不靜默截斷**:若 auto-limit 會砍掉資料列,匯出直接報錯,必須改用 `--no-limit` 或 `--limit N`。支援 `--recovery`。 |
|
|
297
311
|
| `blacklist` | n/a | `list` / `table` / `column` 子指令,從查詢結果中遮蔽敏感資料。 |
|
|
298
312
|
| `check` | query-only+ | 僅 SQL(在 MySQL / MariaDB 最佳)。 |
|
|
299
|
-
| `diff` | query-only+ | 僅 SQL。儲存 / 比較 schema snapshot
|
|
300
|
-
| `
|
|
301
|
-
| `
|
|
313
|
+
| `diff` | query-only+ | 僅 SQL。儲存 / 比較 schema snapshot。`--against-orm <path>` 會將 Prisma schema / DDL 檔 / normalized JSON 與本地 schema cache 比對(不連線 DB):分類為 `missing_in_db`(error)、`missing_in_orm`(warn)、依 tolerance 表判定的 `mismatch`、以及 `unmanaged`,並提供 dry-run `migrate` 提案;出現 error-level drift 時 exit 1。`--orm-format prisma\|ddl\|json\|drizzle\|typeorm\|sequelize`、`--ignore <globs>`、`--format json\|table\|markdown`。Drizzle:請指向 `drizzle/meta/<NNNN>_snapshot.json`(先執行 `drizzle-kit generate`;`.ts` source 會被拒絕並顯示提示)。TypeORM/Sequelize:傳入工具產生的 DDL(`schema:log` / schema-only dump);source file 會被拒絕,並顯示要執行的精確產生指令。 |
|
|
314
|
+
| `design` | n/a | 離線 SQL 設計助手,操作版本控管的 `dbcli.design.json`:不連線、不執行 DDL、不呼叫 provider。`init --output <path>` 是唯一的寫入者且拒絕覆寫;`validate` 為 fail-closed,只要還有 `error` finding,`render` / `diff` / `propose` 一律拒絕執行。`diff` / `propose` 必須且只能給 `--against-cache` 或 `--against-orm <paths>` 其中一個。**`propose` 只做審查用的計畫,永不寫入。** 命名規則、finding code 與 artifact 結構見 [reference.md](reference.md#design)。 |
|
|
315
|
+
| `snapshot` | query-only+ | 僅 SQL。擷取結果指紋(`rowCount` + 每欄 null/distinct/min/max/sum + 順序無關 checksum)。`--out`(預設 `.dbcli/snapshots/snap-<ts>.json`)、`--rows`、`--stdout`、`--format`、`--no-limit`。作為 `assert --against` 的基準。 |
|
|
316
|
+
| `assert` | query-only+ | 僅 SQL。驗證不變量;失敗時 exit 1,除非 `--no-fail`。`--expect "rows>0\|value==X\|col:c not null\|unique\|between a and b\|>= n"`、`--vs <query> --compare rows\|value`(對帳)、`--against <snapshot> --tolerance <pct>`。 |
|
|
302
317
|
| `verification` | n/a | 檢視與管理本機驗證 artifact。`list` / `show <id-or-path>` / `summary` 為唯讀;`prune` 預設 dry-run,僅在 `--execute --force` 時刪除。讀取 `<cwd>/.dbcli/verification/`;不需 DB 連線,不寫入 audit log。 |
|
|
303
318
|
| `backfill artifact` | n/a | 將受限 JSON source catalog 產生可檢閱的 source-to-SQL 回填 artifact,包含 source/target identity、blacklist/schema preflight、read-back 驗證與 rollback hint;只產生 dry-run,絕不執行寫入。 |
|
|
304
|
-
| `proxy` | n/a |
|
|
319
|
+
| `proxy` | n/a | 僅 MySQL/MariaDB/PostgreSQL。本地端開發觀測代理 — 中繼應用程式流量至真實資料庫,並將查詢/延遲/位元組/錯誤事件附加到 `.dbcli/proxy/events.jsonl`。僅作觀測。`proxy analyze` 離線彙整該 log(summary、byFingerprint、slowest、errors、hotTables、N+1;`--format markdown` 產生 QueryLens 報告),若尚無事件則報錯。據以行動:執行每個 finding 的 `suggestedCommands`、讀它的 `hints`,再提出修正——絕不猜資料表名稱,一律用 `schema` 確認。事件日誌本身以 `--redact literals` 保護。[旗標](reference.md#proxy)。 |
|
|
305
320
|
| `status` | query-only+ | 安全 JSON / 文字摘要(不含憑證)。 |
|
|
306
|
-
| `inspect` | query-only+ | 唯讀脈絡快照(連線、權限、blacklist、物件、snippets
|
|
321
|
+
| `inspect` | query-only+ | 唯讀脈絡快照(連線、權限、blacklist、物件、snippets、依脈絡產生的 `suggestedCommands`,以及 人類可讀 `hints`)。`--for-agent` / `--brief` / `--no-connect` / `--require-schema-cache`。支援 `--recovery`。 |
|
|
307
322
|
| `report` | query-only+ | 以 `@diag/*` snippet 組成的診斷報告。`--section <health\|capacity\|perf>`(可用逗號組合)、`--brief`、`--for-agent`、`--no-connect`。 |
|
|
308
|
-
| `guide` | query-only+ | 針對固定目標產出確定性下一步指令計畫(`slow-query`、`capacity`、`health`、`index-usage`、`permissions`、`schema-overview`)。`--list`
|
|
323
|
+
| `guide` | query-only+ | 針對固定目標產出確定性下一步指令計畫(`slow-query`、`capacity`、`health`、`index-usage`、`permissions`、`schema-overview`)。`--list` 列舉所有目標。`guide missing-index-for <query>` 為單一 SELECT 建議複合索引(`--format yaml\|json\|markdown`、`--min-confidence`)。 |
|
|
309
324
|
| `recovery` | n/a | 對已知錯誤代碼查詢結構化 `RecoveryEnvelope`(`--code <CODE>` 或 `--list`)。獨立合成器;不需真實失敗。 |
|
|
310
325
|
| `recover` | n/a | 檢視(預設)或 `--apply` 執行 `.dbcli/last-recovery.json` 中自動儲存的復原計畫。`--allow-write=readonly-cmd\|write-cmd`、`--no-verify`、`--from <file>`、`--next --after-step <n> --result <json\|@file>` 多輪逐步執行。 |
|
|
311
326
|
| `doctor` | n/a | 環境/runtime identity、設定、連線、SRV 診斷(Mongo)、schema cache 年齡。`--format json --remediation` 僅輸出 blacklist/schema/bounded-sample 候選計畫(SQL:`dbcli plan` → 人工確認後的 bounded `dbcli query`;MongoDB/Elasticsearch:先以 `dbcli schema` 預檢,再由人工確認 bounded query),不會套用。 |
|
|
312
327
|
| `completion` | n/a | bash / zsh / fish 腳本。 |
|
|
313
328
|
| `upgrade` | n/a | 從 npm 自我更新;每個指令都帶 24h 快取的版本提示。 |
|
|
314
|
-
| `shell` | (與 query 同) | 互動式 REPL。SQL 引擎、MongoDB 與 Redis(單行;`.no-limit on/off
|
|
329
|
+
| `shell` | (與 query 同) | 互動式 REPL。SQL 引擎、MongoDB 與 Redis(單行;`.no-limit on/off`)。Elasticsearch 開啟 Kibana Dev Tools 風格的 REPL(`<METHOD> /<path>` + 可選 JSON body,空白行送出)。 |
|
|
315
330
|
| `skill` | n/a | 產出 / 安裝 AI skill 文件(`--install <claude\|gemini\|antigravity\|copilot\|cursor\|codex\|windsurf>`);`skill tasks list/show/plan` 提供 Agent Task Packs;`skill context` 提供 LLM 提示詞脈絡載荷(用於注入其他 LLM,正常操作不需要)。 |
|
|
316
331
|
| `semantic` | n/a | 驗證、搜尋、檢查漂移、遷移至 v2 或輸出可選的專案根目錄 `dbcli.semantic.json`。把已檢閱的 context 交給外部 agent,但 provider 憑證、prompt 與 agent context 都留在 dbcli 外。`semantic draft validate --input <file|-> [--format text\|json]` 只會以本機 semantic/schema/saved-query metadata 離線驗證明確提交、不受信任的 `QueryDraft`;只回傳安全的 hash/reference/violation code,絕不執行或回顯 candidate SQL。先檢閱原始 draft,若要執行再另行呼叫 `explain` 或 `query`。 |
|
|
317
332
|
| `migrate` | admin | 僅 SQL。**DDL;預設 dry-run** — 需 `--execute`。 |
|
|
@@ -360,15 +375,15 @@ dbcli init --conn-name prod --env-file .env.production --use-env-refs --skip-tes
|
|
|
360
375
|
- `query` 接受 JSON filter 物件(`find`)或陣列(`aggregate`);SQL 會被拒絕。`--collection <name>` 在 `query` 上為必填。
|
|
361
376
|
- **支援:** `init`、`list`、`schema`(sampled)、`query`、`insert`、`update`、`delete`、`export`、`q`、`status`、`use`、`shell`、`doctor`。**不支援:** `diff`、`migrate`、`check`。
|
|
362
377
|
- Schema 由 `$sample` **採樣**(預設 100 份文件,上限 1000;`--sample-method natural` 改用 `find().limit()`)。欄位以 dot-path 呈現(如 `profile.tokens.access`),附帶 `presence`(0..1)與 `redacted` 旗標。
|
|
363
|
-
- 寫入:`--set` / `--data` JSON 在無 `$` 運算子時自動包裝為 `$set`;明確傳入的運算子(`$set`/`$inc`/`$push`/…)則直接傳遞。巢狀黑名單接受 dot-path(`profile.email`)與結尾萬用字元(`profile.tokens.*`)。Saved snippet 以 `.mongodb.sql` 結尾(frontmatter `engine: mongodb`,`operation: find|aggregate`)。完整寫入規劃分層與語法:reference.md
|
|
378
|
+
- 寫入:`--set` / `--data` JSON 在無 `$` 運算子時自動包裝為 `$set`;明確傳入的運算子(`$set`/`$inc`/`$push`/…)則直接傳遞。巢狀黑名單接受 dot-path(`profile.email`)與結尾萬用字元(`profile.tokens.*`)。Saved snippet 以 `.mongodb.sql` 結尾(frontmatter `engine: mongodb`,`operation: find|aggregate`)。完整寫入規劃分層與語法:[reference.md](reference.md#mongodb-support)。
|
|
364
379
|
|
|
365
380
|
## Redis
|
|
366
381
|
|
|
367
|
-
- `query` 執行單一**白名單內**的 Redis 指令(如 `GET`、`SET`、`HSET`、`DEL`)。完整白名單與每個指令的權限層詳見 reference.md。
|
|
382
|
+
- `query` 執行單一**白名單內**的 Redis 指令(如 `GET`、`SET`、`HSET`、`DEL`)。完整白名單與每個指令的權限層詳見 [reference.md](reference.md#redis-support)。
|
|
368
383
|
- **支援:** `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`。
|
|
369
384
|
- **權限分層:** 讀取類(`GET`/`HGET`/`SCAN`/…)→ `query-only`;mutator(`SET`/`HSET`/`INCR`/`EXPIRE`/`SETEX`/`RENAME`/…)→ `read-write`;`DEL`/`UNLINK`/`HDEL`/`XDEL` → `data-admin`。白名單外的指令一律拒絕。
|
|
370
385
|
- **Redis `query` 無 `--dry-run`** — 寫入安全來自權限門檻與 key 黑名單(命中的讀寫會被拒絕)。如需預覽刪除,請用 `delete <key> --dry-run`。
|
|
371
|
-
- `database` 是 logical DB index(預設 `0`)。`dbcli blacklist table add 'secrets:*'` 註冊 key glob;可選的 `redis.mask` 區塊在讀取時遮罩值。大小防護(SCAN/HGETALL 截斷,`--no-limit` 可略過)與遮罩細節:reference.md
|
|
386
|
+
- `database` 是 logical DB index(預設 `0`)。`dbcli blacklist table add 'secrets:*'` 註冊 key glob;可選的 `redis.mask` 區塊在讀取時遮罩值。大小防護(SCAN/HGETALL 截斷,`--no-limit` 可略過)與遮罩細節:[reference.md](reference.md#redis-support)。
|
|
372
387
|
|
|
373
388
|
## Elasticsearch
|
|
374
389
|
|
|
@@ -379,9 +394,9 @@ dbcli query '{"query":{"match":{"status":"active"}}}' --collection orders
|
|
|
379
394
|
```
|
|
380
395
|
|
|
381
396
|
- `query` 接受 DSL(JSON body)或 Lucene query string;`--collection <index>` 為必填。
|
|
382
|
-
- **支援:** `init`、`list`(含文件數的索引清單)、`schema [index]`(flattened mapping)、`query`、`
|
|
383
|
-
- `export` 接受含 `--index <index>` 的 search DSL,或以 index 名稱作為查詢來透過 `match_all` scroll 整個 index。Query-only 上限 1000 hits;`--no-limit`
|
|
384
|
-
- Schema 會 flatten 巢狀欄位(`a.b.c`),並列出 `.fields` multi-fields。`shell` 開啟 Kibana Dev Tools 風格的 REPL。完整語法與範例:reference.md
|
|
397
|
+
- **支援:** `init`、`list`(含文件數的索引清單)、`schema [index]`(flattened mapping)、`query`、`q`(snippet 使用 `.elasticsearch.sql` 副檔名)、`export`、`shell`、`status`、`use`、`doctor`。**不支援:** `insert`、`update`、`delete`、`check`、`diff`、`migrate`。
|
|
398
|
+
- `export` 接受含 `--index <index>` 的 search DSL,或以 index 名稱作為查詢來透過 `match_all` scroll 整個 index。Query-only 上限 1000 hits;`--no-limit` 會透過 scroll API 取出整個 index。(10,000 那個上限屬於 `query`,不是 `export`。)
|
|
399
|
+
- Schema 會 flatten 巢狀欄位(`a.b.c`),並列出 `.fields` multi-fields。`shell` 開啟 Kibana Dev Tools 風格的 REPL。完整語法與範例:[reference.md](reference.md#elasticsearch-support)。
|
|
385
400
|
|
|
386
401
|
## Saved queries
|
|
387
402
|
|
|
@@ -436,7 +451,7 @@ dbcli query "SELECT * FROM orders" --format html > out.html # pipe HTML to stdou
|
|
|
436
451
|
dbcli export "SELECT * FROM orders" --format html --output orders.html
|
|
437
452
|
```
|
|
438
453
|
|
|
439
|
-
`--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。
|
|
454
|
+
`--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](reference.md#interactive-html-dashboard)。原始 `query` / `export` 呼叫只能渲染 sortable table。
|
|
440
455
|
|
|
441
456
|
## 常見工作流程
|
|
442
457
|
|
|
@@ -452,6 +467,6 @@ dbcli export "SELECT * FROM orders" --format html --output orders.html
|
|
|
452
467
|
|
|
453
468
|
- Query-only 模式自動補 `LIMIT 1000`;查 `information_schema` 或會被 `LIMIT` 破壞的語句請加 `--no-limit`。
|
|
454
469
|
- 被 blacklist 的 table / column 會從查詢輸出中遮蔽。
|
|
455
|
-
- `schema` 回報 `estimatedRowCount` 與 `sizeCategory`(small / medium / large / huge)。大 / 巨大表要加 `WHERE` 或 `LIMIT` — 分界值見 reference.md。
|
|
470
|
+
- `schema` 回報 `estimatedRowCount` 與 `sizeCategory`(small / medium / large / huge)。大 / 巨大表要加 `WHERE` 或 `LIMIT` — 分界值見 [reference.md](reference.md#schema)。
|
|
456
471
|
- 對 `mongodb+srv://` 連線,`doctor` 會回報 SRV 是用原生解析或走 DoH fallback — 在執行環境限制 DNS 時很有用。
|
|
457
472
|
- **全域旗標:** `--version`、`--config <path>`、`--global`、`--use <name>`、`--timeout <ms>`、`-v` / `--verbose` / `-vv`、`-q` / `--quiet`、`--no-color`(也尊重 `NO_COLOR`)。除非指令明確宣告 command-level 選項,否則 root-level 旗標必須放在指令之前。
|