@carllee1983/dbcli 1.52.0 → 1.53.0
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 +39 -28
- package/.cursor/skills/dbcli/reference.md +233 -21
- package/.github/skills/dbcli/SKILL.md +36 -25
- package/.github/skills/dbcli/reference.md +233 -21
- package/CHANGELOG.md +38 -0
- package/assets/SKILL.md +36 -25
- package/assets/SKILL.zh-TW.md +48 -30
- package/assets/reference.md +233 -21
- package/assets/ui-template.html +2 -2
- package/dist/cli-runtime.mjs +101686 -0
- package/dist/cli.mjs +140 -109572
- package/dist/core.d.ts +4 -0
- package/dist/core.mjs +157 -254
- package/dist/ui-style.css +2 -2
- package/package.json +4 -4
- package/plugins/dbcli-agent/skills/dbcli/SKILL.md +36 -25
- package/plugins/dbcli-agent/skills/dbcli/reference.md +233 -21
- package/skills/dbcli/SKILL.md +36 -25
- package/skills/dbcli/reference.md +233 -21
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) /
|
|
@@ -110,8 +110,8 @@ still stop where those gates require human confirmation.
|
|
|
110
110
|
term, or relationship/join intent instead of a physical table or field name, first run
|
|
111
111
|
`dbcli skill context --format json`. If it includes `semantic`, treat that reviewed
|
|
112
112
|
section as the governed vocabulary; use `dbcli semantic search <terms> --format json`
|
|
113
|
-
to look up a specific term. If
|
|
114
|
-
fall back to `blacklist` → `schema` mapping and tell the user that optional
|
|
113
|
+
to look up a specific term. If `contracts` is present, use only its approved terms and
|
|
114
|
+
their descriptive evidence policy; it never authorizes an assertion or query. If no semantic section exists or search returns no result, fall back to `blacklist` → `schema` mapping and tell the user that optional
|
|
115
115
|
`dbcli.semantic.json` can make future requests consistent. Never create, update, or
|
|
116
116
|
migrate that file without an explicit human request; semantic vocabulary never replaces
|
|
117
117
|
schema confirmation or the normal query/write safety gates.
|
|
@@ -157,6 +157,9 @@ 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. |
|
|
162
|
+
| PR schema-change review | `blacklist list` → `impact assess --design ./dbcli.design.json --against-cache --output ./impact.json --fail-on warn`; optionally add explicit `--events ./.dbcli/proxy/events.jsonl` for advisory redacted workload table evidence (never SQL/log rendering or a blocker), then review declared findings, coverage gaps, and the optional reviewed `dbcli.data-access.json` (declared operations only; never source parsing). |
|
|
160
163
|
| PR database review | Review changed persistence paths, then propose concrete `schema` / `plan` / `dry-run` / `report` / `guide` commands per material claim. |
|
|
161
164
|
| 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
165
|
| Safe data backfill | `blacklist list` → `schema <object>` → count/scope query → `update … --dry-run` → read-back or snippet `--verify`. |
|
|
@@ -193,12 +196,16 @@ Guardrails:
|
|
|
193
196
|
- Separate database facts from application-code inference. Report which dbcli output shaped the conclusion.
|
|
194
197
|
- For writes and backfills, include scope count, dry-run preview, execution command, and read-back.
|
|
195
198
|
- Do not create indexes directly from a performance suggestion; turn them into reviewed migrations.
|
|
199
|
+
- Do not execute the `commands` in a `design propose` plan, and do not create or rewrite
|
|
200
|
+
`dbcli.design.json` unless a human asked for it.
|
|
196
201
|
- Do not print credentials, copied connection strings, or blacklisted values.
|
|
197
202
|
- Durable evidence: `assert … --write-verification-artifact --verification-subject <kind:name>`;
|
|
198
203
|
inspect with `verification summary` / `list` / `show <id>`. The `verify safe-backfill` /
|
|
199
204
|
`migration` / `rollback --kind <ddl|dml>` / `constraint --check <fk|not-null|unique|custom>`
|
|
200
|
-
family runs preflight + `--after-write` checks and **never executes the write**.
|
|
201
|
-
|
|
205
|
+
family runs preflight + `--after-write` checks and **never executes the write**. Add
|
|
206
|
+
`--evidence-receipt <workspace-relative-path>` only after after-write for a safe provenance
|
|
207
|
+
receipt; it is never approval to execute a write. Full flags
|
|
208
|
+
and the per-command blocks are in [reference.md](reference.md#commands).
|
|
202
209
|
|
|
203
210
|
## Audit log
|
|
204
211
|
|
|
@@ -215,7 +222,7 @@ The `inspect` / `guide` / `recover` agent JSON embeds `audit_recent` (last 5 ent
|
|
|
215
222
|
fresh session has immediate history. An envelope's `audit_ref` and an audit entry's
|
|
216
223
|
`recovery_ref` point at each other, so you can pivot either way. Audit is on by default
|
|
217
224
|
(`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
|
|
225
|
+
values, or result cells) and rotate at ~10 MB / 1000 entries. Full flags: [reference.md](reference.md#audit).
|
|
219
226
|
|
|
220
227
|
## Quick start
|
|
221
228
|
|
|
@@ -371,7 +378,7 @@ refs have no value to connect with yet.
|
|
|
371
378
|
- **Re-running `init`** — refuses to overwrite without `--force`; never use
|
|
372
379
|
`--force` to "fix" a config full of `{ "$env": "..." }` refs.
|
|
373
380
|
|
|
374
|
-
Full flags and edge cases: see [reference.md](reference.md)
|
|
381
|
+
Full flags and edge cases: see [reference.md](reference.md#init).
|
|
375
382
|
|
|
376
383
|
## Command overview
|
|
377
384
|
|
|
@@ -382,34 +389,36 @@ Full flags and edge cases: see [reference.md](reference.md) `init` section.
|
|
|
382
389
|
| `list` | query-only+ | Tables (SQL), collections (MongoDB), keys (Redis), or indices (Elasticsearch). |
|
|
383
390
|
| `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
391
|
| `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**. |
|
|
385
|
-
| `explain` | query-only+ |
|
|
392
|
+
| `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
393
|
| `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
394
|
| `plan` | n/a | Static SQL risk analyzer (`--format text\|json`); classifies a statement without connecting to the database. |
|
|
388
395
|
| `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
396
|
| `queries` | n/a | Manage saved snippets: `list` / `show` / `search` / `suggest` / `new` / `edit` / `check` / `delete` / `rename` / `copy` / `import` / `export`. |
|
|
390
397
|
| `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
398
|
| `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
|
|
399
|
+
| `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
400
|
| `blacklist` | n/a | `list` / `table` / `column` subcommands redact sensitive data from query results. |
|
|
394
401
|
| `check` | query-only+ | SQL only (best on MySQL/MariaDB). |
|
|
395
|
-
| `diff` | query-only+ | SQL only. Save/compare schema snapshots.
|
|
396
|
-
| `
|
|
397
|
-
| `
|
|
402
|
+
| `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. |
|
|
403
|
+
| `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). |
|
|
404
|
+
| `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`. |
|
|
405
|
+
| `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
406
|
| `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
407
|
| `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 |
|
|
408
|
+
| `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
409
|
| `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
|
|
410
|
+
| `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
411
|
| `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.
|
|
412
|
+
| `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
413
|
| `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
414
|
| `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
415
|
| `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
416
|
| `completion` | n/a | bash / zsh / fish scripts. |
|
|
409
417
|
| `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`).
|
|
418
|
+
| `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
419
|
| `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
420
|
| `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. |
|
|
421
|
+
| `contract` | n/a | Validate, inspect approved context, search, or inspect drift for optional project-root `dbcli.contracts.json`. Contracts add ownership and a descriptive evidence policy to canonical semantic references; they are offline, never execute SQL, and cannot create verification or query authority. `skill context` includes only valid approved contracts. |
|
|
413
422
|
| `migrate` | admin | SQL only. **DDL; dry-run by default** — needs `--execute`. |
|
|
414
423
|
|
|
415
424
|
Use root-level `dbcli --use <name> <command>` for any command; `query`, `schema`, `list`,
|
|
@@ -475,12 +484,12 @@ truncation from a round number. This applies to `query` and to `q` snippets
|
|
|
475
484
|
explicit operators (`$set`/`$inc`/`$push`/…) pass through. Nested blacklist accepts dotted
|
|
476
485
|
paths (`profile.email`) and trailing wildcards (`profile.tokens.*`). Saved snippets end in
|
|
477
486
|
`.mongodb.sql` (frontmatter `engine: mongodb`, `operation: find|aggregate`). Full
|
|
478
|
-
write-planner tiers and syntax: reference.md
|
|
487
|
+
write-planner tiers and syntax: [reference.md](reference.md#mongodb-support).
|
|
479
488
|
|
|
480
489
|
## Redis
|
|
481
490
|
|
|
482
491
|
- `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.
|
|
492
|
+
The full whitelist and the per-command permission tier are defined in [reference.md](reference.md#redis-support).
|
|
484
493
|
- **Supported:** `init`, `list` (keys via SCAN), `schema <key>` (type / TTL / size / sample),
|
|
485
494
|
`query`, `q` (saved snippets — **read-only commands only**), `delete` (basic implementation:
|
|
486
495
|
`DEL` / `HDEL` / `LREM` / `SREM` / `ZREM`, needs `data-admin`; `query "DEL <key>"` also
|
|
@@ -493,7 +502,7 @@ truncation from a round number. This applies to `query` and to `q` snippets
|
|
|
493
502
|
blacklist (matching reads/writes are rejected). To preview a delete, use `delete <key> --dry-run`.
|
|
494
503
|
- `database` is the logical DB index (default `0`). `dbcli blacklist table add 'secrets:*'`
|
|
495
504
|
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
|
|
505
|
+
(SCAN/HGETALL truncation, `--no-limit` to bypass) and masking details: [reference.md](reference.md#redis-support).
|
|
497
506
|
|
|
498
507
|
## Elasticsearch
|
|
499
508
|
|
|
@@ -505,12 +514,14 @@ dbcli query '{"query":{"match":{"status":"active"}}}' --collection orders
|
|
|
505
514
|
|
|
506
515
|
- `query` takes a DSL (JSON body) or Lucene query string; `--collection <index>` is required.
|
|
507
516
|
- **Supported:** `init`, `list` (indices with doc count), `schema [index]` (flattened mapping),
|
|
508
|
-
`query`, `
|
|
517
|
+
`query`, `q` (snippets use the `.elasticsearch.sql` extension), `export`,
|
|
518
|
+
`shell`, `status`, `use`, `doctor`. **Not supported:**
|
|
509
519
|
`insert`, `update`, `delete`, `check`, `diff`, `migrate`.
|
|
510
520
|
- `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`
|
|
521
|
+
the whole index via `match_all`. Query-only caps at 1000 hits; `--no-limit` streams the whole
|
|
522
|
+
index via the scroll API. (The 10 000 bound belongs to `query`, not `export`.)
|
|
512
523
|
- 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
|
|
524
|
+
Kibana Dev Tools-style REPL. Full syntax and examples: [reference.md](reference.md#elasticsearch-support).
|
|
514
525
|
|
|
515
526
|
## Saved queries
|
|
516
527
|
|
|
@@ -575,7 +586,7 @@ dbcli export "SELECT * FROM orders" --format html --output orders.html
|
|
|
575
586
|
When a saved snippet exists, prefer `q @<name> --ui` / `q @<name> --format html` because snippet
|
|
576
587
|
metadata can drive titles, KPI cards, and charts. Blacklist redaction is applied **before**
|
|
577
588
|
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:`
|
|
589
|
+
`kpis[]`, `charts[]`) to the snippet frontmatter — see [reference.md](reference.md#interactive-html-dashboard) for the full `visual:`
|
|
579
590
|
schema. Raw `query` / `export` invocations render a sortable table only.
|
|
580
591
|
|
|
581
592
|
## Common workflows
|
|
@@ -592,6 +603,6 @@ schema. Raw `query` / `export` invocations render a sortable table only.
|
|
|
592
603
|
|
|
593
604
|
- Query-only mode auto-appends `LIMIT 1000`; add `--no-limit` for `information_schema` or statements that break with `LIMIT`.
|
|
594
605
|
- 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.
|
|
606
|
+
- `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
607
|
- `doctor` on `mongodb+srv://` reports whether SRV resolves natively or through the DoH fallback — useful when the runtime restricts DNS.
|
|
597
608
|
- **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
|
|
|
@@ -84,7 +84,8 @@ blacklist、schema、permission、dry-run、production 選取或寫入確認閘
|
|
|
84
84
|
**業務語言探索:** 當使用者以業務別名、metric、反覆出現的術語或 relationship/join 意圖,
|
|
85
85
|
而非實體 table 或 field 名稱提出需求時,先執行 `dbcli skill context --format json`。若輸出含有
|
|
86
86
|
`semantic`,將該已檢閱的區塊視為受治理詞彙;需查找特定術語時,用
|
|
87
|
-
`dbcli semantic search <terms> --format json
|
|
87
|
+
`dbcli semantic search <terms> --format json`。若有 `contracts` 區塊,只能使用其中 approved 術語
|
|
88
|
+
及描述性的 evidence policy;它絕不授權 assertion 或 query。若沒有 semantic 區塊,或搜尋沒有結果,就退回
|
|
88
89
|
`blacklist` → `schema` 對照,並告知使用者可選用的 `dbcli.semantic.json` 能讓後續需求保持一致。
|
|
89
90
|
除非人類明確要求,絕不可建立、更新或 migrate 此檔案;語意詞彙不能取代 schema 確認或正常的
|
|
90
91
|
query/write 安全閘門。
|
|
@@ -115,6 +116,9 @@ dbcli skill tasks plan <task> --param key=value --format json # generate pla
|
|
|
115
116
|
| DB report / dashboard request | `blacklist list` → `queries search <keywords>` / `queries suggest <intent>` → `queries show @<name>` → `q @<name> --ui` 或 `--format html` |
|
|
116
117
|
| 應用程式資料錯誤 | `audit tail --for-agent --n 10` → `blacklist list` → `schema <object>` → 最小查詢 |
|
|
117
118
|
| ORM 或 migration | `schema --format json` → `diff --against-orm <orm-schema>` → 審查 error-level drift → 透過 `migrate` 取得提案(dry-run)→ `migration-review` task pack → 套用後執行 `diff --against <snapshot>`。 |
|
|
119
|
+
| 資料庫設計(尚未有 DB) | `design init --output ./dbcli.design.json` → 編輯 → `design validate` → `design render --format mermaid`。已有 ORM 模型時,先用 `design diff --against-orm <path>` 對齊。 |
|
|
120
|
+
| 既有資料庫的設計漂移 | `blacklist list` → `schema --format json` → `design diff --against-cache` → `design propose --against-cache`,計畫交人類審查後才執行 migration。 |
|
|
121
|
+
| PR schema 變更審查 | `blacklist list` → `impact assess --design ./dbcli.design.json --against-cache --output ./impact.json --fail-on warn`;可選擇加入明確的 `--events ./.dbcli/proxy/events.jsonl` 取得 advisory、已 redaction 的 workload table evidence(不輸出 SQL/log,也不作為 blocker),再檢閱已宣告 findings、coverage gaps 與可選且已審閱的 `dbcli.data-access.json`(僅 declared operations;絕不解析 source)。 |
|
|
118
122
|
| PR 資料庫風險審查 | 審查變更的 persistence path,並針對每個重要主張提出具體 `schema`、`plan`、`dry-run`、`report` 或 `guide` 指令。 |
|
|
119
123
|
| 慢 endpoint 或查詢 | `report --section perf` → task pack `analyze-table-perf` → `lint "<query>"` → `guide missing-index-for "<query>"`;有 proxy log 時使用 `proxy analyze`。 |
|
|
120
124
|
| 安全資料回填 | `blacklist list` → `schema <object>` → count/scope query → `update … --dry-run` → read-back 或 snippet `--verify`。 |
|
|
@@ -149,8 +153,9 @@ dbcli inspect --for-agent --no-connect --format json
|
|
|
149
153
|
- 分離資料庫事實與應用程式推論;回報是哪個 dbcli 輸出影響了結論。
|
|
150
154
|
- 寫入與 backfill 必須包含 scope count、dry-run preview、execution command,以及 read-back。
|
|
151
155
|
- 不要直接從 performance suggestion 建 index;應轉成經過 review 的 migration。
|
|
156
|
+
- 不要執行 `design propose` 計畫裡的 `commands`;未經人類要求,也不要建立或改寫 `dbcli.design.json`。
|
|
152
157
|
- 不要列印 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`
|
|
158
|
+
- 持久化佐證:`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` 驗證,**永不執行寫入**。僅可在 after-write 後加入 `--evidence-receipt <工作區相對路徑>` 寫入安全 provenance receipt;它不代表核准執行寫入。完整旗標與每個指令的區塊詳見 [reference.md](reference.md#commands)。
|
|
154
159
|
|
|
155
160
|
## Audit Log 使用
|
|
156
161
|
|
|
@@ -162,7 +167,7 @@ dbcli audit show <id-prefix> # full entry by id prefix (≥4 cha
|
|
|
162
167
|
dbcli audit show --recovery-ref <env-id> # find the entry that emitted an envelope
|
|
163
168
|
```
|
|
164
169
|
|
|
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
|
|
170
|
+
`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
171
|
|
|
167
172
|
## 快速開始
|
|
168
173
|
|
|
@@ -192,7 +197,9 @@ dbcli query "SELECT * FROM users" # Execute SQL (auto LIMIT 1000)
|
|
|
192
197
|
`--password` / `--name`(與 `--system`)。
|
|
193
198
|
3. **要哪一個權限層?** 預設取**最低**夠用的:
|
|
194
199
|
`query-only` → `read-write` → `data-admin` → `admin`。透過 `--permission` 設定
|
|
195
|
-
(預設 `query-only
|
|
200
|
+
(預設 `query-only`)。權限層判斷的是「這條語句做什麼」,不是「它怎麼開啟連線」:
|
|
201
|
+
低於 `admin` 時多語句 SQL 一律被拒;snippet 不得含寫入與 DDL 關鍵字;
|
|
202
|
+
MongoDB 的 `$out` / `$merge` 需要 `data-admin`,且在 snippet 與 `export` 中一律拒絕。
|
|
196
203
|
4. **驗證、不要假設。** init 結束後跑 `dbcli status`(系統 + 權限 + blacklist 摘要、不含憑證)與 `dbcli doctor --format json`(env、設定形狀、連線、schema-cache 年齡、Mongo SRV 路徑)。
|
|
197
204
|
|
|
198
205
|
### 每個引擎的必備指令
|
|
@@ -205,11 +212,13 @@ dbcli init --system postgresql --host localhost --port 5432 \
|
|
|
205
212
|
# Reuse an existing .env (DATABASE_URL=postgresql://user:pw@host:5432/db)
|
|
206
213
|
dbcli init # parses .env in cwd
|
|
207
214
|
|
|
208
|
-
# MongoDB —
|
|
215
|
+
# MongoDB — 逐欄位指定(無驗證就省略 --user/--password)
|
|
216
|
+
dbcli init --system mongodb --host localhost --port 27017 --name mydb
|
|
217
|
+
dbcli init --system mongodb --host localhost --port 27017 \
|
|
218
|
+
--user admin --password '<secret>' --auth-source admin --name mydb
|
|
219
|
+
# MongoDB — full URI(進階逃生口:多 host、非標準 driver 選項)
|
|
209
220
|
dbcli init --system mongodb \
|
|
210
221
|
--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
222
|
|
|
214
223
|
# Redis — `--name` is the LOGICAL DB INDEX ("0".."15"), not a database name
|
|
215
224
|
dbcli init --system redis --host localhost --port 6379 --password '<secret>' --name 0
|
|
@@ -249,7 +258,7 @@ dbcli --global query "SELECT 1"
|
|
|
249
258
|
|
|
250
259
|
`--global` 必須放在指令之前。未帶它時,指令仍使用目前專案的 `.dbcli` binding;全域與專案 registry 彼此獨立。
|
|
251
260
|
|
|
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`。
|
|
261
|
+
每個命名連線的 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
262
|
|
|
254
263
|
### env-refs(把機密排除在 `.dbcli` 之外)
|
|
255
264
|
|
|
@@ -267,15 +276,22 @@ dbcli init --conn-name prod --env-file .env.production --use-env-refs --skip-tes
|
|
|
267
276
|
|
|
268
277
|
在**互動式終端機**中,省略 `--env-*` 旗標會逐一提示輸入 key 名稱(預設如上)— 可輸入非預設名稱如 `PROD_DB_PASSWORD`,它會以 `$env` ref 形式儲存。在**非互動式 / CI** 環境中,**必須**傳齊全部五個 `--env-*` 旗標;否則 `init` 會以錯誤退出 — 不會靜默 fallback 為明文。`--env-file <path>` 是 env 檔路徑,與 `$env` key 名稱無關。
|
|
269
278
|
|
|
279
|
+
**MongoDB 是例外**:非互動式下只有 `--env-host` 是必填。`--env-port` / `--env-user` /
|
|
280
|
+
`--env-password` / `--env-database` 皆為選填——省略的欄位會寫成 literal 值(`user` /
|
|
281
|
+
`password` 為空字串,`port` / `database` 為解析後的值)而非 `$env` ref,讓這條連線根本
|
|
282
|
+
用不到的欄位不會日後因未定義變數而 fail closed。此模式下 `init` 也會無視 `--skip-test`
|
|
283
|
+
一律跳過連線測試——`$env` ref 此時還沒有值可以用來連線。
|
|
284
|
+
|
|
270
285
|
### 常見陷阱
|
|
271
286
|
|
|
272
287
|
- **MongoDB `mongodb+srv://`** — `dbcli doctor` 回報 SRV 是用原生方式解析還是走 DoH fallback;在執行環境限制 DNS 時很有用。
|
|
288
|
+
- **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
289
|
- **MySQL/Postgres 密碼含 `@` `:` `/`** — 使用 `DATABASE_URL` 時要 percent-encode(`@` → `%40`);分項的 `--password` 旗標不需編碼。
|
|
274
290
|
- **Redis `--name`** — 僅接受 logical DB index 字串;非數字會被拒絕。
|
|
275
291
|
- **Elasticsearch TLS** — `caPath` 與 `rejectUnauthorized` 沒有對應旗標;`init` 後直接編輯 `.dbcli` 加上。
|
|
276
292
|
- **重跑 `init`** — 沒有 `--force` 拒絕覆寫;千萬不要為了「修好」一個含 `{ "$env": "..." }` 參照的設定而用 `--force`。
|
|
277
293
|
|
|
278
|
-
完整旗標與邊界案例見 [reference.md](reference.md)
|
|
294
|
+
完整旗標與邊界案例見 [reference.md](reference.md#init)。
|
|
279
295
|
|
|
280
296
|
## 指令總覽 (Command overview)
|
|
281
297
|
|
|
@@ -285,35 +301,37 @@ dbcli init --conn-name prod --env-file .env.production --use-env-refs --skip-tes
|
|
|
285
301
|
| `use` | n/a | 顯示 / 切換預設命名連線(僅 v2)。 |
|
|
286
302
|
| `list` | query-only+ | 資料表(SQL)、collections(MongoDB)、keys(Redis)或 indices(Elasticsearch)。 |
|
|
287
303
|
| `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+ |
|
|
304
|
+
| `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` 的同名旗標不同。見 **查詢工作流程旗標**。 |
|
|
305
|
+
| `explain` | query-only+ | 唯讀查詢計畫並附註解。僅 SQL。單一查詢、`@saved-query`、`@file.sql` 或 `--bulk @glob/*`。`--analyze`(EXPLAIN ANALYZE / MariaDB ANALYZE SELECT)、`--format markdown\|json\|table`。 |
|
|
290
306
|
| `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
307
|
| `plan` | n/a | 靜態 SQL 風險分析器(`--format text\|json`);不連線即可分類語句。 |
|
|
292
|
-
| `q` | query-only+ | 以 `@name` 執行已儲存 snippet,搭配 `--param k=v`。支援 `--verify`
|
|
308
|
+
| `q` | query-only+ | 以 `@name` 執行已儲存 snippet,搭配 `--param k=v`。支援 `--verify` 以執行斷言,以及 `--slow-ms <n>`(與 `query` 相同的被動慢查詢提示)。 |
|
|
293
309
|
| `queries` | n/a | 管理已儲存 snippet:`list` / `show` / `search` / `suggest` / `new` / `edit` / `check` / `delete` / `rename` / `copy` / `import` / `export`。 |
|
|
294
310
|
| `insert` / `update` | read-write+ | 僅 SQL 與 MongoDB。JSON `--data` / `--set`;`update` 必填 `--where`;先 `--dry-run`。Redis 寫入透過 `query`。支援 `--recovery`。 |
|
|
295
311
|
| `delete` | data-admin+ | 僅 SQL 與 MongoDB;Redis 有基本實作(見 Redis 段落)。必填 `--where`;先 `--dry-run`。支援 `--recovery`。 |
|
|
296
|
-
| `export` | query-only+ | SQL、MongoDB 或
|
|
312
|
+
| `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
313
|
| `blacklist` | n/a | `list` / `table` / `column` 子指令,從查詢結果中遮蔽敏感資料。 |
|
|
298
314
|
| `check` | query-only+ | 僅 SQL(在 MySQL / MariaDB 最佳)。 |
|
|
299
|
-
| `diff` | query-only+ | 僅 SQL。儲存 / 比較 schema snapshot
|
|
300
|
-
| `
|
|
301
|
-
| `
|
|
315
|
+
| `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 會被拒絕,並顯示要執行的精確產生指令。 |
|
|
316
|
+
| `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)。 |
|
|
317
|
+
| `snapshot` | query-only+ | 僅 SQL。擷取結果指紋(`rowCount` + 每欄 null/distinct/min/max/sum + 順序無關 checksum)。`--out`(預設 `.dbcli/snapshots/snap-<ts>.json`)、`--rows`、`--stdout`、`--format`、`--no-limit`。作為 `assert --against` 的基準。 |
|
|
318
|
+
| `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
319
|
| `verification` | n/a | 檢視與管理本機驗證 artifact。`list` / `show <id-or-path>` / `summary` 為唯讀;`prune` 預設 dry-run,僅在 `--execute --force` 時刪除。讀取 `<cwd>/.dbcli/verification/`;不需 DB 連線,不寫入 audit log。 |
|
|
303
320
|
| `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 |
|
|
321
|
+
| `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
322
|
| `status` | query-only+ | 安全 JSON / 文字摘要(不含憑證)。 |
|
|
306
|
-
| `inspect` | query-only+ | 唯讀脈絡快照(連線、權限、blacklist、物件、snippets
|
|
323
|
+
| `inspect` | query-only+ | 唯讀脈絡快照(連線、權限、blacklist、物件、snippets、依脈絡產生的 `suggestedCommands`,以及 人類可讀 `hints`)。`--for-agent` / `--brief` / `--no-connect` / `--require-schema-cache`。支援 `--recovery`。 |
|
|
307
324
|
| `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`
|
|
325
|
+
| `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
326
|
| `recovery` | n/a | 對已知錯誤代碼查詢結構化 `RecoveryEnvelope`(`--code <CODE>` 或 `--list`)。獨立合成器;不需真實失敗。 |
|
|
310
327
|
| `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
328
|
| `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
329
|
| `completion` | n/a | bash / zsh / fish 腳本。 |
|
|
313
330
|
| `upgrade` | n/a | 從 npm 自我更新;每個指令都帶 24h 快取的版本提示。 |
|
|
314
|
-
| `shell` | (與 query 同) | 互動式 REPL。SQL 引擎、MongoDB 與 Redis(單行;`.no-limit on/off
|
|
331
|
+
| `shell` | (與 query 同) | 互動式 REPL。SQL 引擎、MongoDB 與 Redis(單行;`.no-limit on/off`)。Elasticsearch 開啟 Kibana Dev Tools 風格的 REPL(`<METHOD> /<path>` + 可選 JSON body,空白行送出)。 |
|
|
315
332
|
| `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
333
|
| `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`。 |
|
|
334
|
+
| `contract` | n/a | 驗證、檢視 approved context、搜尋或檢查可選專案根目錄 `dbcli.contracts.json` 的漂移。契約為 canonical semantic reference 加上 owner 與描述性的 evidence policy;完全離線、絕不執行 SQL,也不能建立 verification 或 query 權限。`skill context` 只納入有效且 approved 的契約。 |
|
|
317
335
|
| `migrate` | admin | 僅 SQL。**DDL;預設 dry-run** — 需 `--execute`。 |
|
|
318
336
|
|
|
319
337
|
任何指令都可使用 root 層級的 `dbcli --use <name> <command>`;`query`、`schema`、`list`、`export`、`check` 也接受指令層級的 `--use`。兩種寫法都只把本次目標切到 v2 連線,不改變預設值。`--recovery` 被 `query`、`q`、`insert`、`update`、`delete`、`export`、`schema`、`inspect`、`lint` 與 `diff --against-orm` 支援(見上方**失敗時**)。
|
|
@@ -360,15 +378,15 @@ dbcli init --conn-name prod --env-file .env.production --use-env-refs --skip-tes
|
|
|
360
378
|
- `query` 接受 JSON filter 物件(`find`)或陣列(`aggregate`);SQL 會被拒絕。`--collection <name>` 在 `query` 上為必填。
|
|
361
379
|
- **支援:** `init`、`list`、`schema`(sampled)、`query`、`insert`、`update`、`delete`、`export`、`q`、`status`、`use`、`shell`、`doctor`。**不支援:** `diff`、`migrate`、`check`。
|
|
362
380
|
- 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
|
|
381
|
+
- 寫入:`--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
382
|
|
|
365
383
|
## Redis
|
|
366
384
|
|
|
367
|
-
- `query` 執行單一**白名單內**的 Redis 指令(如 `GET`、`SET`、`HSET`、`DEL`)。完整白名單與每個指令的權限層詳見 reference.md。
|
|
385
|
+
- `query` 執行單一**白名單內**的 Redis 指令(如 `GET`、`SET`、`HSET`、`DEL`)。完整白名單與每個指令的權限層詳見 [reference.md](reference.md#redis-support)。
|
|
368
386
|
- **支援:** `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
387
|
- **權限分層:** 讀取類(`GET`/`HGET`/`SCAN`/…)→ `query-only`;mutator(`SET`/`HSET`/`INCR`/`EXPIRE`/`SETEX`/`RENAME`/…)→ `read-write`;`DEL`/`UNLINK`/`HDEL`/`XDEL` → `data-admin`。白名單外的指令一律拒絕。
|
|
370
388
|
- **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
|
|
389
|
+
- `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
390
|
|
|
373
391
|
## Elasticsearch
|
|
374
392
|
|
|
@@ -379,9 +397,9 @@ dbcli query '{"query":{"match":{"status":"active"}}}' --collection orders
|
|
|
379
397
|
```
|
|
380
398
|
|
|
381
399
|
- `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
|
|
400
|
+
- **支援:** `init`、`list`(含文件數的索引清單)、`schema [index]`(flattened mapping)、`query`、`q`(snippet 使用 `.elasticsearch.sql` 副檔名)、`export`、`shell`、`status`、`use`、`doctor`。**不支援:** `insert`、`update`、`delete`、`check`、`diff`、`migrate`。
|
|
401
|
+
- `export` 接受含 `--index <index>` 的 search DSL,或以 index 名稱作為查詢來透過 `match_all` scroll 整個 index。Query-only 上限 1000 hits;`--no-limit` 會透過 scroll API 取出整個 index。(10,000 那個上限屬於 `query`,不是 `export`。)
|
|
402
|
+
- Schema 會 flatten 巢狀欄位(`a.b.c`),並列出 `.fields` multi-fields。`shell` 開啟 Kibana Dev Tools 風格的 REPL。完整語法與範例:[reference.md](reference.md#elasticsearch-support)。
|
|
385
403
|
|
|
386
404
|
## Saved queries
|
|
387
405
|
|
|
@@ -436,7 +454,7 @@ dbcli query "SELECT * FROM orders" --format html > out.html # pipe HTML to stdou
|
|
|
436
454
|
dbcli export "SELECT * FROM orders" --format html --output orders.html
|
|
437
455
|
```
|
|
438
456
|
|
|
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。
|
|
457
|
+
`--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
458
|
|
|
441
459
|
## 常見工作流程
|
|
442
460
|
|
|
@@ -452,6 +470,6 @@ dbcli export "SELECT * FROM orders" --format html --output orders.html
|
|
|
452
470
|
|
|
453
471
|
- Query-only 模式自動補 `LIMIT 1000`;查 `information_schema` 或會被 `LIMIT` 破壞的語句請加 `--no-limit`。
|
|
454
472
|
- 被 blacklist 的 table / column 會從查詢輸出中遮蔽。
|
|
455
|
-
- `schema` 回報 `estimatedRowCount` 與 `sizeCategory`(small / medium / large / huge)。大 / 巨大表要加 `WHERE` 或 `LIMIT` — 分界值見 reference.md。
|
|
473
|
+
- `schema` 回報 `estimatedRowCount` 與 `sizeCategory`(small / medium / large / huge)。大 / 巨大表要加 `WHERE` 或 `LIMIT` — 分界值見 [reference.md](reference.md#schema)。
|
|
456
474
|
- 對 `mongodb+srv://` 連線,`doctor` 會回報 SRV 是用原生解析或走 DoH fallback — 在執行環境限制 DNS 時很有用。
|
|
457
475
|
- **全域旗標:** `--version`、`--config <path>`、`--global`、`--use <name>`、`--timeout <ms>`、`-v` / `--verbose` / `-vv`、`-q` / `--quiet`、`--no-color`(也尊重 `NO_COLOR`)。除非指令明確宣告 command-level 選項,否則 root-level 旗標必須放在指令之前。
|