@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
|
@@ -4,6 +4,69 @@ Companion to [SKILL.md](SKILL.md). Exhaustive flags, copy-paste examples, `shell
|
|
|
4
4
|
|
|
5
5
|
For cross-engine support status, see `docs/feature-matrix.md` in the repository.
|
|
6
6
|
|
|
7
|
+
## Index
|
|
8
|
+
|
|
9
|
+
Jump straight to what you need — this file is long, and reading it end to end is
|
|
10
|
+
never the right move.
|
|
11
|
+
|
|
12
|
+
| Section | What is in it |
|
|
13
|
+
|---|---|
|
|
14
|
+
| [Global options and placement](#global-options-and-placement) | Flags that must precede the command (`--use`, `--config`), and [redirecting output](#redirecting-output). |
|
|
15
|
+
| [Commands](#commands) | Every command, one `###` each — see the command list below. |
|
|
16
|
+
| [Recovery Cookbook](#recovery-cookbook-agent-walkthroughs) | Failure-to-fix walkthroughs S1–S6, the [scenario index](#scenario-index), [risk gate cheat sheet](#risk-gate-cheat-sheet), and [common pitfalls](#common-pitfalls). |
|
|
17
|
+
| [Interactive HTML dashboard](#interactive-html-dashboard) | `--ui` / `--format html`: [entry points](#entry-points), [data injection contract](#data-injection-contract), [`meta` shape](#meta-shape). |
|
|
18
|
+
| [MongoDB Support](#mongodb-support) | Connection shapes, JSON query bodies, write-stage guard. |
|
|
19
|
+
| [Redis Support](#redis-support) | Command permission tiers, size guards, key masking. |
|
|
20
|
+
| [Elasticsearch Support](#elasticsearch-support) | DSL and Lucene queries, scroll export, mapping flattening. |
|
|
21
|
+
|
|
22
|
+
**Commands** —
|
|
23
|
+
[init](#init) ·
|
|
24
|
+
[use](#use) ·
|
|
25
|
+
[list](#list) ·
|
|
26
|
+
[schema](#schema) ·
|
|
27
|
+
[query](#query) ·
|
|
28
|
+
[explain](#explain) ·
|
|
29
|
+
[lint](#lint) ·
|
|
30
|
+
[plan](#plan) ·
|
|
31
|
+
[q](#q) ·
|
|
32
|
+
[queries](#queries) ·
|
|
33
|
+
[insert](#insert) ·
|
|
34
|
+
[update](#update) ·
|
|
35
|
+
[delete](#delete) ·
|
|
36
|
+
[export](#export) ·
|
|
37
|
+
[blacklist](#blacklist) ·
|
|
38
|
+
[check](#check) ·
|
|
39
|
+
[diff](#diff) ·
|
|
40
|
+
[design](#design) ·
|
|
41
|
+
[impact assess](#impact-assess) ·
|
|
42
|
+
[snapshot](#snapshot) ·
|
|
43
|
+
[assert](#assert) ·
|
|
44
|
+
[proxy](#proxy) ·
|
|
45
|
+
[status](#status) ·
|
|
46
|
+
[inspect](#inspect) ·
|
|
47
|
+
[report](#report) ·
|
|
48
|
+
[guide](#guide) ·
|
|
49
|
+
[recovery](#recovery) ·
|
|
50
|
+
[recover](#recover) ·
|
|
51
|
+
[audit](#audit) ·
|
|
52
|
+
[verify](#verify) ·
|
|
53
|
+
[verification](#verification) ·
|
|
54
|
+
[backfill](#backfill) ·
|
|
55
|
+
[evidence](#evidence) ·
|
|
56
|
+
[doctor](#doctor) ·
|
|
57
|
+
[completion](#completion) ·
|
|
58
|
+
[upgrade](#upgrade) ·
|
|
59
|
+
[shell](#dbcli-shell) ·
|
|
60
|
+
[migrate](#migrate) ·
|
|
61
|
+
[semantic](#semantic) ·
|
|
62
|
+
[contract](#contract) ·
|
|
63
|
+
[skill](#skill) ·
|
|
64
|
+
[skill context](#skill-context) ·
|
|
65
|
+
[skill tasks](#skill-tasks-agent-task-packs)
|
|
66
|
+
|
|
67
|
+
Also worth knowing before you connect:
|
|
68
|
+
[Agent configuration trust boundary](#agent-configuration-trust-boundary).
|
|
69
|
+
|
|
7
70
|
## Global options and placement
|
|
8
71
|
|
|
9
72
|
These options are available on the root `dbcli` command. Root-level options must
|
|
@@ -561,13 +624,15 @@ dbcli q @analytics/revenue --param days=30 --format html > report.html
|
|
|
561
624
|
- `--ui` — open the rendered HTML dashboard in the system browser (implies `--format html`; writes to a temp file then invokes `open` / `xdg-open` / `start`)
|
|
562
625
|
- `--param <key=value>` — pass a parameter (repeatable)
|
|
563
626
|
- `--param-file <path>` — JSON object whose keys are param names
|
|
564
|
-
- `--no-limit` — skip the `SELECT * FROM (…) AS _dbcli_guard LIMIT
|
|
627
|
+
- `--no-limit` — skip the `SELECT * FROM (…) AS _dbcli_guard LIMIT 1001` wrap (the effective cap is 1000; one extra row is fetched to detect truncation)
|
|
565
628
|
- `--dry-run` — print the bound SQL + values without executing
|
|
566
|
-
- `--use <name>` — pick a v2 named connection
|
|
567
629
|
- `--slow-ms <number>` — passive slow-query hint threshold (default `1000`; `0` disables). Same contract as `query` — see "Passive slow-query hint" there
|
|
568
630
|
- `--recovery` — emit a `RecoveryEnvelope` on failure (see `recover`)
|
|
569
631
|
- `--verify` — run the snippet's verification assertions after execution (only if the snippet defines them)
|
|
570
632
|
|
|
633
|
+
`q` has no command-level `--use`. To run a snippet against a v2 named connection,
|
|
634
|
+
use the global form: `dbcli --use <name> q @<snippet>`.
|
|
635
|
+
|
|
571
636
|
**Permission:** query-only+
|
|
572
637
|
|
|
573
638
|
#### Snippet file format
|
|
@@ -691,8 +756,9 @@ Size guard: `LRANGE` / `ZRANGE` stop overridden when `< 0` or `> 1000`; `SCAN` /
|
|
|
691
756
|
##### MongoDB snippets
|
|
692
757
|
|
|
693
758
|
File extension: `.mongodb.sql`. Frontmatter must declare `engine: mongodb` and
|
|
694
|
-
`operation: find` or `operation: aggregate`. `target: <collection>`
|
|
695
|
-
collection
|
|
759
|
+
`operation: find` or `operation: aggregate`. `target: <collection>` declares the
|
|
760
|
+
collection the snippet runs against; the CLI has no flag to override it, so a different
|
|
761
|
+
collection means a different snippet. The body is JSON: an object
|
|
696
762
|
for `find` and an array for `aggregate`. Each `{{param}}` placeholder is JSON-encoded
|
|
697
763
|
at substitution time — strings are quoted and escaped, so an attacker-supplied string
|
|
698
764
|
cannot escape into operator position.
|
|
@@ -1126,6 +1192,7 @@ dbcli design validate [--file <path>] [--format <format>]
|
|
|
1126
1192
|
dbcli design render [--file <path>] [--format <format>]
|
|
1127
1193
|
dbcli design diff (--against-cache | --against-orm <paths>) [options]
|
|
1128
1194
|
dbcli design propose (--against-cache | --against-orm <paths>) [options]
|
|
1195
|
+
dbcli impact assess --design <path> (--against-cache | --against-orm <paths>) --output <path> [options]
|
|
1129
1196
|
```
|
|
1130
1197
|
|
|
1131
1198
|
```bash
|
|
@@ -1137,6 +1204,7 @@ dbcli design render --format mermaid
|
|
|
1137
1204
|
dbcli design diff --against-cache --format markdown
|
|
1138
1205
|
dbcli design diff --against-orm ./prisma/schema.prisma --format markdown
|
|
1139
1206
|
dbcli design propose --against-orm ./prisma/schema.prisma --format markdown
|
|
1207
|
+
dbcli impact assess --design ./dbcli.design.json --against-cache --output ./impact.json --fail-on warn
|
|
1140
1208
|
```
|
|
1141
1209
|
|
|
1142
1210
|
| Option | Applies to | Default | Meaning |
|
|
@@ -1153,8 +1221,14 @@ dbcli design propose --against-orm ./prisma/schema.prisma --format markdown
|
|
|
1153
1221
|
`diff` and `propose` require **exactly one** comparison target; passing both or
|
|
1154
1222
|
neither is an error.
|
|
1155
1223
|
|
|
1224
|
+
### impact assess
|
|
1225
|
+
|
|
1226
|
+
Writes an offline JSON or Markdown report for the known declared impact of a design change. It requires `--design`, exactly one baseline (`--against-cache` or `--against-orm`), and an explicit workspace-contained `--output`. `--format` is `json` (default) or `markdown`; `--fail-on` is `error`, `warn`, or `never` (default). The threshold changes only the successful command exit code after the report is written. The report is limited to declared/partial coverage and never claims complete coverage. It may join the optional reviewed `dbcli.data-access.json` manifest only after validating its canonical semantic references and existing workspace-relative source paths; it never reads those sources. An optional explicit `--events <path>` is bounded and streamed through a redaction-first projection that retains recent safe table metadata only. It never starts a proxy, reads a rotated log, renders SQL/literals/errors/sessions/paths, or makes the command fail solely because workload evidence is absent or advisory. It reads no database, executes no SQL, and never reads saved-query bodies.
|
|
1227
|
+
|
|
1156
1228
|
#### Artifact shape
|
|
1157
1229
|
|
|
1230
|
+
This example validates clean (0 errors, 0 warnings):
|
|
1231
|
+
|
|
1158
1232
|
```json
|
|
1159
1233
|
{
|
|
1160
1234
|
"version": 1,
|
|
@@ -1166,14 +1240,24 @@ neither is an error.
|
|
|
1166
1240
|
"description": "Completed purchases.",
|
|
1167
1241
|
"fields": [
|
|
1168
1242
|
{ "name": "id", "type": "bigint", "nullable": false, "primaryKey": true, "unique": true },
|
|
1169
|
-
{ "name": "customer_id", "type": "bigint", "nullable": false
|
|
1243
|
+
{ "name": "customer_id", "type": "bigint", "nullable": false },
|
|
1244
|
+
{ "name": "created_at", "type": "timestamptz", "nullable": false }
|
|
1170
1245
|
],
|
|
1171
|
-
"indexes": [
|
|
1246
|
+
"indexes": [
|
|
1247
|
+
{ "name": "orders_customer_idx", "columns": ["customer_id", "created_at"], "unique": false }
|
|
1248
|
+
]
|
|
1249
|
+
},
|
|
1250
|
+
{
|
|
1251
|
+
"name": "customers",
|
|
1252
|
+
"table": "customers",
|
|
1253
|
+
"fields": [
|
|
1254
|
+
{ "name": "id", "type": "bigint", "nullable": false, "primaryKey": true, "unique": true }
|
|
1255
|
+
]
|
|
1172
1256
|
}
|
|
1173
1257
|
],
|
|
1174
1258
|
"relationships": [
|
|
1175
1259
|
{
|
|
1176
|
-
"name": "
|
|
1260
|
+
"name": "orders-customer",
|
|
1177
1261
|
"from": { "model": "orders", "field": "customer_id" },
|
|
1178
1262
|
"to": { "model": "customers", "field": "id" },
|
|
1179
1263
|
"cardinality": "many-to-one"
|
|
@@ -1188,11 +1272,38 @@ It holds no SQL, credentials, rows, or provider configuration. `design init`
|
|
|
1188
1272
|
emits this envelope with empty `models`, `relationships`, `accessPatterns`, and
|
|
1189
1273
|
`decisions`.
|
|
1190
1274
|
|
|
1275
|
+
#### Naming and limits
|
|
1276
|
+
|
|
1277
|
+
Two different naming rules apply, and mixing them up is the most common way an
|
|
1278
|
+
artifact fails before any review rule runs.
|
|
1279
|
+
|
|
1280
|
+
| Applies to | Rule |
|
|
1281
|
+
|---|---|
|
|
1282
|
+
| `models[].name`, `relationships[].name`, `relationships[].from/to.model`, `accessPatterns[].model`, `decisions[].name` | lowercase kebab-case, `^[a-z][a-z0-9-]*$` — underscores are rejected |
|
|
1283
|
+
| `models[].table`, `fields[].name`, `indexes[].name`, `indexes[].columns[]`, `filters[]`, `sort[]` | SQL identifier, `^[A-Za-z_][A-Za-z0-9_]*$` |
|
|
1284
|
+
|
|
1285
|
+
Relationship endpoints reference a **model name**, not a table name. Every object
|
|
1286
|
+
is strict: an unknown key is an error, not ignored. `description` and `rationale`
|
|
1287
|
+
are 1–1000 characters and must not contain SQL keywords or a connection string —
|
|
1288
|
+
"rows we delete after 30 days" is rejected for the word `delete`. `fields[].type`
|
|
1289
|
+
is at most 100 characters with no `;` or newline. `primaryKey`, `unique`,
|
|
1290
|
+
`indexes`, `filters`, `sort`, `relationships`, `accessPatterns`, and `decisions`
|
|
1291
|
+
may all be omitted.
|
|
1292
|
+
|
|
1293
|
+
Limits: file 256 KiB, 100 models, 100 fields per model, 200 relationships,
|
|
1294
|
+
200 access patterns, 100 decisions, 1–16 columns per index, ≤16 entries in
|
|
1295
|
+
`filters` and `sort`.
|
|
1296
|
+
|
|
1191
1297
|
#### Review findings
|
|
1192
1298
|
|
|
1193
1299
|
`validate` is fail-closed: any `error` finding exits `1`, and `render`, `diff`,
|
|
1194
1300
|
and `propose` refuse to do their work while errors remain.
|
|
1195
1301
|
|
|
1302
|
+
Structural problems — malformed JSON, an unknown key, a naming or type violation,
|
|
1303
|
+
a missing file, or a file over 256 KiB — are rejected before review runs and are
|
|
1304
|
+
reported as a single `INVALID_ARTIFACT` finding (`error`) whose `path` points at
|
|
1305
|
+
the offending JSON location. None of the codes below appear in that case.
|
|
1306
|
+
|
|
1196
1307
|
| Severity | Codes |
|
|
1197
1308
|
|---|---|
|
|
1198
1309
|
| `error` | `NO_MODELS`, `DUPLICATE_MODEL`, `DUPLICATE_TABLE`, `DUPLICATE_FIELD`, `PRIMARY_KEY_COUNT`, `NULLABLE_PRIMARY_KEY`, `UNKNOWN_INDEX_FIELD`, `DUPLICATE_RELATIONSHIP`, `REVERSE_RELATIONSHIP`, `UNKNOWN_RELATIONSHIP_MODEL`, `UNKNOWN_RELATIONSHIP_FIELD`, `RELATIONSHIP_TYPE_MISMATCH`, `MANY_TO_MANY_REQUIRES_BRIDGE`, `ONE_TO_ONE_REQUIRES_UNIQUE_FK`, `UNKNOWN_ACCESS_MODEL`, `UNKNOWN_ACCESS_FIELD` |
|
|
@@ -1297,7 +1408,7 @@ Opt-in flag trio that persists a **VerificationArtifact JSON** (schema v1) under
|
|
|
1297
1408
|
| Flag | Required | Description |
|
|
1298
1409
|
| :--- | :--- | :--- |
|
|
1299
1410
|
| `--write-verification-artifact` | opt-in | Trigger artifact write. No-op when no verdict has been produced. |
|
|
1300
|
-
| `--verification-subject <kind:name>` | yes (when flag is set) | Subject identifier. Format: `<kind>:<name>`. Allowed kinds: `recovery`, `task-pack`, `assertion`, `migration`, `backfill`, `manual`. |
|
|
1411
|
+
| `--verification-subject <kind:name>` | yes (when flag is set) | Subject identifier. Format: `<kind>:<name>`. Allowed kinds: `recovery`, `task-pack`, `assertion`, `migration`, `backfill`, `table`, `manual`. |
|
|
1301
1412
|
| `--verification-summary <text>` | no | Free-text summary line stored in the artifact. Default when pass: "Assertion verified the expected state." Default when fail: "Assertion did not verify the expected state." |
|
|
1302
1413
|
|
|
1303
1414
|
**Output contract:**
|
|
@@ -1559,7 +1670,7 @@ Examples:
|
|
|
1559
1670
|
|
|
1560
1671
|
Boundaries:
|
|
1561
1672
|
- Recovery only **suggests** commands; agents (or humans) execute them. No automatic remediation in v1.15.0.
|
|
1562
|
-
-
|
|
1673
|
+
- `--recovery` is honored on `query`, `q`, `insert`, `update`, `delete`, `export`, `schema`, `inspect`, `lint`, and `diff`. Other commands (`report`, `guide`, `doctor`, `migrate`, `init`, `use`, `status`, `list`, `check`, `plan`, `shell`, `blacklist`, `completion`, `upgrade`, `skill`) keep their existing error behavior.
|
|
1563
1674
|
- `dbcli inspect --require-schema-cache` throws `SCHEMA_CACHE_MISSING` when the active SQL connection has no usable schema cache. Combine with `--recovery` for the structured envelope.
|
|
1564
1675
|
- `BLACKLIST_COLUMN_WRITE` and `PERMISSION_DENIED` envelopes prepend a `risk: 'dry-run'` step (e.g. `dbcli insert <table> --dry-run`) when the failing operation was an INSERT / UPDATE / DELETE.
|
|
1565
1676
|
- Recovery steps reuse the v1.14.0 `GuideStep` shape, including the full `risk` enum (`readonly` / `dry-run` / `write` / `unknown`).
|
|
@@ -1593,7 +1704,7 @@ Boundaries:
|
|
|
1593
1704
|
|---|---|---|
|
|
1594
1705
|
| `readonly` | local read-only | `dbcli inspect`, `dbcli doctor`, `dbcli blacklist list`, `dbcli schema <table>` |
|
|
1595
1706
|
| `dry-run` | write subcommand invoked with `--dry-run` | `dbcli update orders --where id=1 --dry-run`, `dbcli q @x --dry-run` |
|
|
1596
|
-
| `local-write` | writes local config / cache / blacklist | `dbcli blacklist remove <table>`, `dbcli use <name>`, `dbcli schema --refresh` |
|
|
1707
|
+
| `local-write` | writes local config / cache / blacklist | `dbcli blacklist table remove <table>`, `dbcli use <name>`, `dbcli schema --refresh` |
|
|
1597
1708
|
| `db-write` | mutates the connected database | `dbcli update orders --where id=1 --set …` (no `--dry-run`), `dbcli q @x` (no `--dry-run`) |
|
|
1598
1709
|
| `interactive` | requires TTY | `dbcli init`, `dbcli init --force` |
|
|
1599
1710
|
|
|
@@ -1746,7 +1857,7 @@ dbcli recover --next --after-step 1 --result '{"status":"ok"}' --format markdown
|
|
|
1746
1857
|
|
|
1747
1858
|
(v1.20.0+) Inspect, query, and manage the per-connection audit log written to `.dbcli/audit/<connection>.jsonl`.
|
|
1748
1859
|
|
|
1749
|
-
Audit entries are metadata-only by design — never raw SQL bodies, `--param` values, or result cell contents (D3 lock). Redaction is sourced from `
|
|
1860
|
+
Audit entries are metadata-only by design — never raw SQL bodies, `--param` values, or result cell contents (D3 lock). Redaction is sourced from `src/utils/redaction.ts` (same source as `inspect` / `guide` / `recover` agent contracts).
|
|
1750
1861
|
|
|
1751
1862
|
#### Subcommands
|
|
1752
1863
|
|
|
@@ -1783,7 +1894,9 @@ Examples:
|
|
|
1783
1894
|
| `<id-prefix>` | Positional. UUID or prefix ≥ 4 characters; ambiguous prefix exits 1 with disambiguation hint; prefix < 4 chars exits 1. | — |
|
|
1784
1895
|
| `--recovery-ref <id>` | Find the audit entry whose `recovery_ref` field matches this id (exact, not prefix). Mutually exclusive with positional `<id-prefix>` (D-38). | — |
|
|
1785
1896
|
| `--all` | Search across all connections. Output is an envelope `{ connection, entry }` (single-hit also envelope, for shape stability — D-36). | off |
|
|
1786
|
-
| `--
|
|
1897
|
+
| `--brief` | Trim `metadata` and `redacted_query` from the entry. | off |
|
|
1898
|
+
| `--for-agent` | Shortcut for `--format json --brief`. | off |
|
|
1899
|
+
| `--no-brief` | Disable brief mode when a higher-level default enables it (e.g. `--for-agent`). | off |
|
|
1787
1900
|
| `--format <fmt>` | `table` \| `json`. | `table` |
|
|
1788
1901
|
|
|
1789
1902
|
Examples:
|
|
@@ -1817,7 +1930,7 @@ Output reports: writer enabled/disabled, last write result, file-lock state, rot
|
|
|
1817
1930
|
#### Boundaries
|
|
1818
1931
|
|
|
1819
1932
|
- Entries are append-only JSONL; rotation triggers at `~10 MB` or `~1000` entries (whichever first). Previous segment is preserved as `.jsonl.1`.
|
|
1820
|
-
- Bi-directional `recovery_ref` / `audit_ref` linkage is wired on every command that accepts `--recovery`: `query`, `inspect`, `insert`, `update`, `delete`, `export`, `q`, and `schema`. Use `audit
|
|
1933
|
+
- Bi-directional `recovery_ref` / `audit_ref` linkage is wired on every command that accepts `--recovery`: `query`, `inspect`, `insert`, `update`, `delete`, `export`, `q`, and `schema`. Use `audit show --recovery-ref <id>` to find the audit entry an envelope was emitted alongside.
|
|
1821
1934
|
- Audit writer failures are non-fatal (D6): main command result and exit code are preserved; a stderr warning is emitted. `audit health` surfaces the failure reason.
|
|
1822
1935
|
- Reader truncation tolerance: a crash-truncated last line is skipped with a stderr warn `[dbcli audit] skipping truncated last line in <file>`; a mid-file non-JSON line is treated as corruption, exits 1, and points at `dbcli audit clear`.
|
|
1823
1936
|
|
|
@@ -1835,7 +1948,7 @@ Output reports: writer enabled/disabled, last write result, file-lock state, rot
|
|
|
1835
1948
|
### verify
|
|
1836
1949
|
|
|
1837
1950
|
Run a verification scenario. `verify` **runs** verification scenarios (safe-backfill,
|
|
1838
|
-
migration, rollback) and never executes writes/DDL. `verification` **inspects and manages**
|
|
1951
|
+
migration, rollback, constraint) and never executes writes/DDL. `verification` **inspects and manages**
|
|
1839
1952
|
the local result artifacts those scenarios produce under `.dbcli/verification/`.
|
|
1840
1953
|
|
|
1841
1954
|
```bash
|
|
@@ -1847,7 +1960,8 @@ dbcli verify safe-backfill \
|
|
|
1847
1960
|
--expect "value == 0"
|
|
1848
1961
|
|
|
1849
1962
|
# After-write: re-run guards, run the read-back assertion, write a v1 artifact.
|
|
1850
|
-
|
|
1963
|
+
# An optional receipt is provenance only, never approval to execute a write.
|
|
1964
|
+
dbcli verify safe-backfill ... --after-write --evidence-receipt .dbcli/evidence/verify-receipt.json
|
|
1851
1965
|
|
|
1852
1966
|
# JSON for agents.
|
|
1853
1967
|
dbcli verify safe-backfill ... --format json
|
|
@@ -1855,7 +1969,11 @@ dbcli verify safe-backfill ... --format json
|
|
|
1855
1969
|
|
|
1856
1970
|
Options: `--table` (req), `--query` (req, analyzed not executed), `--verify-query`
|
|
1857
1971
|
(req, **plain SELECT only**), `--expect` (req), `--after-write`, `--format <table|json>`,
|
|
1858
|
-
`--subject-name <name>`, `--summary <text
|
|
1972
|
+
`--subject-name <name>`, `--summary <text>`, `--evidence-receipt <workspace-relative-path>`
|
|
1973
|
+
(after-write only). A receipt is safe provenance for the already-executed verification,
|
|
1974
|
+
not approval to execute a write. Its `succeeded`/`failed` outcome remains distinct from
|
|
1975
|
+
the artifact status (`verified`, `not_verified`, `indeterminate`, or `blocked`); task-pack
|
|
1976
|
+
`planned` evidence stays plan-only.
|
|
1859
1977
|
|
|
1860
1978
|
Guard constraints (fail closed): `--verify-query` must be a **plain `SELECT`** —
|
|
1861
1979
|
`EXPLAIN`/`EXPLAIN ANALYZE`, `SHOW`, `DESCRIBE`, and data-modifying CTEs are rejected
|
|
@@ -2078,7 +2196,7 @@ dbcli verification list --include-invalid --format json
|
|
|
2078
2196
|
| `--format <json\|table>` | Output format. | `json` |
|
|
2079
2197
|
| `--limit <n>` | Maximum number of entries to return. | `20` |
|
|
2080
2198
|
| `--status <status>` | Filter by status. One of: `verified`, `not_verified`, `indeterminate`, `blocked`. | all |
|
|
2081
|
-
| `--subject <kind[:name]>` | Filter by subject kind or exact `kind:name`. Allowed kinds: `recovery`, `task-pack`, `assertion`, `migration`, `backfill`, `manual`. | all |
|
|
2199
|
+
| `--subject <kind[:name]>` | Filter by subject kind or exact `kind:name`. Allowed kinds: `recovery`, `task-pack`, `assertion`, `migration`, `backfill`, `table`, `manual`. | all |
|
|
2082
2200
|
| `--include-invalid` | Surface malformed artifact files (normally skipped silently). Invalid files are returned as a separate top-level `invalid` array in JSON output, each entry shaped `{ "path": "...", "filename": "...", "error": "..." }`. When off, `invalid` is `[]`. | off |
|
|
2083
2201
|
|
|
2084
2202
|
**Missing directory:** if `.dbcli/verification/` does not exist, exits `0` with an
|
|
@@ -2192,6 +2310,7 @@ includes `storageDir`, `dryRun`, `cutoff`, `criteria`, `protected`, `candidates`
|
|
|
2192
2310
|
| `assertion` | General-purpose inline assertions. |
|
|
2193
2311
|
| `migration` | Schema migration pre/post checks. |
|
|
2194
2312
|
| `backfill` | Data backfill verification assertions. |
|
|
2313
|
+
| `table` | `verify constraint` artifacts — the subject name is the table checked. |
|
|
2195
2314
|
| `manual` | Manually triggered or ad-hoc verification runs. |
|
|
2196
2315
|
|
|
2197
2316
|
**Storage root:** `<cwd>/.dbcli/verification/` (cwd-relative; independent of `--config`).
|
|
@@ -2359,6 +2478,66 @@ dbcli migrate drop-enum status --execute --force
|
|
|
2359
2478
|
|
|
2360
2479
|
**AI agent note:** Always use dry-run first (no `--execute`) to preview generated SQL. Only add `--execute` after confirming the SQL is correct. For DROP operations, both `--execute` and `--force` are required.
|
|
2361
2480
|
|
|
2481
|
+
### evidence
|
|
2482
|
+
|
|
2483
|
+
Compose a canonical, offline **Evidence Pack** from existing verification artifacts
|
|
2484
|
+
and audit entries. This command never opens a database connection. A pack retains only
|
|
2485
|
+
safe pointers and outcome fields: it excludes SQL, targets, audit metadata, verification
|
|
2486
|
+
summaries, result data, and credentials. Claims are external statements, never dbcli
|
|
2487
|
+
verification verdicts.
|
|
2488
|
+
|
|
2489
|
+
#### `evidence compose`
|
|
2490
|
+
|
|
2491
|
+
```bash
|
|
2492
|
+
dbcli evidence compose --claims ./claims.json --verification ver_abcd --audit 1a2b \
|
|
2493
|
+
--receipt .dbcli/evidence/verify-receipt.json \
|
|
2494
|
+
--output .dbcli/evidence/review.json --format json
|
|
2495
|
+
```
|
|
2496
|
+
|
|
2497
|
+
| Flag | Purpose | Default |
|
|
2498
|
+
|---|---|---|
|
|
2499
|
+
| `--claims <file>` | Required JSON file with exactly `subject` and `claims`; every claim has an `id` and plain-language `text`. SQL-shaped text, credentials, error content, and blacklisted identifiers are rejected. | — |
|
|
2500
|
+
| `--verification <selector...>` | One or more verification artifact ids, unique prefixes, filenames, or in-bounds paths. | none |
|
|
2501
|
+
| `--audit <selector...>` | One or more audit ids or unique prefixes (minimum four characters) from the active connection. | none |
|
|
2502
|
+
| `--receipt <path...>` | Explicit workspace-relative receipt path(s). Receipts contribute safe provenance only; they are not execution approval. | none |
|
|
2503
|
+
| `--output <path>` | Required new JSON path under the current workspace. Existing files and paths outside the workspace are refused. | — |
|
|
2504
|
+
| `--format <json\|markdown>` | Compose receipt format printed to stdout. | `json` |
|
|
2505
|
+
|
|
2506
|
+
At least one `--verification`, `--audit`, or `--receipt` reference is required. The resulting pack
|
|
2507
|
+
contains a canonical SHA-256 integrity digest and `coverage.completeForDeclaredEvidence:
|
|
2508
|
+
true` for its explicitly selected references.
|
|
2509
|
+
|
|
2510
|
+
#### `evidence validate`
|
|
2511
|
+
|
|
2512
|
+
```bash
|
|
2513
|
+
dbcli evidence validate --file .dbcli/evidence/review.json --format json
|
|
2514
|
+
```
|
|
2515
|
+
|
|
2516
|
+
| Flag | Purpose | Default |
|
|
2517
|
+
|---|---|---|
|
|
2518
|
+
| `--file <path>` | Required evidence-pack JSON file. | — |
|
|
2519
|
+
| `--format <json\|markdown>` | Validation report format. | `json` |
|
|
2520
|
+
|
|
2521
|
+
Exit `0` when digest and all selected sources are valid. If a referenced audit or
|
|
2522
|
+
verification artifact later rotates, is cleared, disappears, or belongs to a different
|
|
2523
|
+
active connection, output stays parseable with `integrity: "valid"` and
|
|
2524
|
+
`references: "source-expired"`, then exits `1`.
|
|
2525
|
+
|
|
2526
|
+
#### `evidence render`
|
|
2527
|
+
|
|
2528
|
+
```bash
|
|
2529
|
+
dbcli evidence render --file .dbcli/evidence/review.json --format markdown
|
|
2530
|
+
```
|
|
2531
|
+
|
|
2532
|
+
| Flag | Purpose | Default |
|
|
2533
|
+
|---|---|---|
|
|
2534
|
+
| `--file <path>` | Required evidence-pack JSON file. | — |
|
|
2535
|
+
| `--format <json\|markdown>` | Render format. | `markdown` |
|
|
2536
|
+
|
|
2537
|
+
`render` validates the pack digest and active blacklist policy but does not resolve its
|
|
2538
|
+
original references. It is therefore available for historical review after `validate`
|
|
2539
|
+
reports `source-expired`, unless an exposed pack field is now blacklisted.
|
|
2540
|
+
|
|
2362
2541
|
### semantic
|
|
2363
2542
|
|
|
2364
2543
|
Validate or print the optional, version-controlled `dbcli.semantic.json` in the
|
|
@@ -2485,6 +2664,39 @@ limits, audit, and recovery safeguards remain in force.
|
|
|
2485
2664
|
|
|
2486
2665
|
**Permission:** n/a (local files only; no database connection).
|
|
2487
2666
|
|
|
2667
|
+
### contract
|
|
2668
|
+
|
|
2669
|
+
Inspect the optional, version-controlled `dbcli.contracts.json` without opening a
|
|
2670
|
+
database connection. A contract adds a reviewed owner and descriptive evidence policy
|
|
2671
|
+
to canonical semantic references; it is not an executable data contract, assertion,
|
|
2672
|
+
query, or verification scenario.
|
|
2673
|
+
|
|
2674
|
+
```bash
|
|
2675
|
+
dbcli contract validate --format json
|
|
2676
|
+
dbcli contract context --format json
|
|
2677
|
+
dbcli contract context --format markdown
|
|
2678
|
+
dbcli contract search customer --format json
|
|
2679
|
+
dbcli contract drift --format json
|
|
2680
|
+
```
|
|
2681
|
+
|
|
2682
|
+
The strict v1 artifact contains `version` and `contracts`. Each contract has a unique
|
|
2683
|
+
canonical `name`, `status` (`draft`, `approved`, or `deprecated`), bounded plain-text
|
|
2684
|
+
`description` and `owner`, one or more canonical semantic `subjects`, optional aliases,
|
|
2685
|
+
and an `evidencePolicy` of `none`, `receipt-required`, or `verification-required`.
|
|
2686
|
+
Subjects must remain in the existing visible semantic registry; protected identifiers,
|
|
2687
|
+
unknown keys, duplicate names or subjects, SQL-like text, credentials, and stale
|
|
2688
|
+
references fail closed without exposing protected names.
|
|
2689
|
+
|
|
2690
|
+
`contract validate` requires an explicit valid artifact. `contract context` and
|
|
2691
|
+
`contract search` return only valid approved contracts; draft and deprecated contracts
|
|
2692
|
+
remain local review artifacts. `contract drift` reports `valid`, `stale`, `invalid`, or
|
|
2693
|
+
`unavailable` evidence offline and exits non-zero except for `valid`. A missing default
|
|
2694
|
+
file is allowed by `skill context` and leaves ordinary semantic context unchanged; a
|
|
2695
|
+
present invalid file fails closed. No contract command writes a file, opens a database
|
|
2696
|
+
connection, widens a `QueryDraft`, or changes permission/blacklist behavior.
|
|
2697
|
+
|
|
2698
|
+
**Permission:** n/a (local files only; no database connection).
|
|
2699
|
+
|
|
2488
2700
|
### skill
|
|
2489
2701
|
|
|
2490
2702
|
Emit `SKILL.md` (and the companion `reference.md`) to stdout, a file, or an
|
|
@@ -3024,9 +3236,9 @@ Permission is derived from the command's first token (case-insensitive). Unknown
|
|
|
3024
3236
|
|
|
3025
3237
|
| Tier | Commands |
|
|
3026
3238
|
|------|----------|
|
|
3027
|
-
| `query-only` | `GET`, `MGET`, `STRLEN`, `EXISTS`, `TTL`, `PTTL`, `TYPE`, `SCAN`, `HGET`, `HGETALL`, `HKEYS`, `HVALS`, `HLEN`, `HEXISTS`, `HMGET`, `LRANGE`, `LLEN`, `LINDEX`, `SMEMBERS`, `SCARD`, `SISMEMBER`, `ZRANGE`, `ZREVRANGE`, `ZRANGEBYSCORE`, `ZCARD`, `ZSCORE`, `PING`, `ECHO` |
|
|
3028
|
-
| `read-write` | `SET`, `SETEX`, `SETNX`, `PSETEX`, `MSET`, `MSETNX`, `APPEND`, `INCR`/`INCRBY`, `DECR`/`DECRBY`, `HSET`/`HSETNX`/`HMSET`/`HINCRBY`, `LPUSH`/`RPUSH`/`LPOP`/`RPOP`/`LSET`, `SADD`/`SREM`, `ZADD`/`ZREM`, `EXPIRE`/`EXPIREAT`/`PEXPIRE`/`PERSIST`, `RENAME` |
|
|
3029
|
-
| `data-admin` | `DEL`, `UNLINK`, `HDEL` |
|
|
3239
|
+
| `query-only` | `GET`, `MGET`, `STRLEN`, `EXISTS`, `TTL`, `PTTL`, `TYPE`, `SCAN`, `HGET`, `HGETALL`, `HKEYS`, `HVALS`, `HLEN`, `HEXISTS`, `HMGET`, `LRANGE`, `LLEN`, `LINDEX`, `SMEMBERS`, `SCARD`, `SISMEMBER`, `ZRANGE`, `ZREVRANGE`, `ZRANGEBYSCORE`, `ZCARD`, `ZSCORE`, `XLEN`, `XREAD`, `XRANGE`, `XREVRANGE`, `PING`, `ECHO` |
|
|
3240
|
+
| `read-write` | `SET`, `SETEX`, `SETNX`, `PSETEX`, `MSET`, `MSETNX`, `APPEND`, `INCR`/`INCRBY`, `DECR`/`DECRBY`, `HSET`/`HSETNX`/`HMSET`/`HINCRBY`, `LPUSH`/`RPUSH`/`LPOP`/`RPOP`/`LSET`/`LREM`, `SADD`/`SREM`, `ZADD`/`ZREM`, `XADD`, `EXPIRE`/`EXPIREAT`/`PEXPIRE`/`PERSIST`, `RENAME` |
|
|
3241
|
+
| `data-admin` | `DEL`, `UNLINK`, `HDEL`, `XDEL` |
|
|
3030
3242
|
| `admin` | `FLUSHDB`, `FLUSHALL`, `CONFIG`, `INFO`, `CLIENT`, `DEBUG`, `SHUTDOWN`, `KEYS`, `MONITOR`, `SAVE`, `BGSAVE`, `BGREWRITEAOF`, `REPLICAOF`, `SLAVEOF`, `ACL` |
|
|
3031
3243
|
|
|
3032
3244
|
### Schema inspection
|
|
@@ -3237,5 +3449,5 @@ GET /orders/_search
|
|
|
3237
3449
|
|
|
3238
3450
|
- Writes (`insert`/`update`/`delete`) are not exposed yet — the adapter implements them, but the CLI currently only routes them for SQL and MongoDB. Read-only `export` (v1.22) and the interactive `shell` (v1.22) are available.
|
|
3239
3451
|
- No `_search/scroll` or PIT pagination at the CLI layer; large pulls need a saved external script.
|
|
3240
|
-
- `check`, `diff`,
|
|
3452
|
+
- `check`, `diff`, and `migrate` are SQL-only and exit with errors (or fall through to a generic "unsupported" path). `q` **is** supported — Elasticsearch snippets use the `.elasticsearch.sql` extension (see `@diag/es-cluster-health`).
|
|
3241
3453
|
- Blacklist column rules are applied to flattened hit rows on `query`; table-level blacklist rejects an index up front.
|
package/skills/dbcli/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.
|