@carllee1983/dbcli 1.52.0 → 1.52.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,66 @@ 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
+ [snapshot](#snapshot) ·
42
+ [assert](#assert) ·
43
+ [proxy](#proxy) ·
44
+ [status](#status) ·
45
+ [inspect](#inspect) ·
46
+ [report](#report) ·
47
+ [guide](#guide) ·
48
+ [recovery](#recovery) ·
49
+ [recover](#recover) ·
50
+ [audit](#audit) ·
51
+ [verify](#verify) ·
52
+ [verification](#verification) ·
53
+ [backfill](#backfill) ·
54
+ [doctor](#doctor) ·
55
+ [completion](#completion) ·
56
+ [upgrade](#upgrade) ·
57
+ [shell](#dbcli-shell) ·
58
+ [migrate](#migrate) ·
59
+ [semantic](#semantic) ·
60
+ [skill](#skill) ·
61
+ [skill context](#skill-context) ·
62
+ [skill tasks](#skill-tasks-agent-task-packs)
63
+
64
+ Also worth knowing before you connect:
65
+ [Agent configuration trust boundary](#agent-configuration-trust-boundary).
66
+
7
67
  ## Global options and placement
8
68
 
9
69
  These options are available on the root `dbcli` command. Root-level options must
@@ -561,13 +621,15 @@ dbcli q @analytics/revenue --param days=30 --format html > report.html
561
621
  - `--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
622
  - `--param <key=value>` — pass a parameter (repeatable)
563
623
  - `--param-file <path>` — JSON object whose keys are param names
564
- - `--no-limit` — skip the `SELECT * FROM (…) AS _dbcli_guard LIMIT 1000` wrap
624
+ - `--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
625
  - `--dry-run` — print the bound SQL + values without executing
566
- - `--use <name>` — pick a v2 named connection
567
626
  - `--slow-ms <number>` — passive slow-query hint threshold (default `1000`; `0` disables). Same contract as `query` — see "Passive slow-query hint" there
568
627
  - `--recovery` — emit a `RecoveryEnvelope` on failure (see `recover`)
569
628
  - `--verify` — run the snippet's verification assertions after execution (only if the snippet defines them)
570
629
 
630
+ `q` has no command-level `--use`. To run a snippet against a v2 named connection,
631
+ use the global form: `dbcli --use <name> q @<snippet>`.
632
+
571
633
  **Permission:** query-only+
572
634
 
573
635
  #### Snippet file format
@@ -691,8 +753,9 @@ Size guard: `LRANGE` / `ZRANGE` stop overridden when `< 0` or `> 1000`; `SCAN` /
691
753
  ##### MongoDB snippets
692
754
 
693
755
  File extension: `.mongodb.sql`. Frontmatter must declare `engine: mongodb` and
694
- `operation: find` or `operation: aggregate`. `target: <collection>` provides a default
695
- collection that `dbcli q --collection <name>` can override. The body is JSON: an object
756
+ `operation: find` or `operation: aggregate`. `target: <collection>` declares the
757
+ collection the snippet runs against; the CLI has no flag to override it, so a different
758
+ collection means a different snippet. The body is JSON: an object
696
759
  for `find` and an array for `aggregate`. Each `{{param}}` placeholder is JSON-encoded
697
760
  at substitution time — strings are quoted and escaped, so an attacker-supplied string
698
761
  cannot escape into operator position.
@@ -1155,6 +1218,8 @@ neither is an error.
1155
1218
 
1156
1219
  #### Artifact shape
1157
1220
 
1221
+ This example validates clean (0 errors, 0 warnings):
1222
+
1158
1223
  ```json
1159
1224
  {
1160
1225
  "version": 1,
@@ -1166,14 +1231,24 @@ neither is an error.
1166
1231
  "description": "Completed purchases.",
1167
1232
  "fields": [
1168
1233
  { "name": "id", "type": "bigint", "nullable": false, "primaryKey": true, "unique": true },
1169
- { "name": "customer_id", "type": "bigint", "nullable": false, "primaryKey": false, "unique": false }
1234
+ { "name": "customer_id", "type": "bigint", "nullable": false },
1235
+ { "name": "created_at", "type": "timestamptz", "nullable": false }
1170
1236
  ],
1171
- "indexes": [{ "name": "orders_customer_idx", "columns": ["customer_id"], "unique": false }]
1237
+ "indexes": [
1238
+ { "name": "orders_customer_idx", "columns": ["customer_id", "created_at"], "unique": false }
1239
+ ]
1240
+ },
1241
+ {
1242
+ "name": "customers",
1243
+ "table": "customers",
1244
+ "fields": [
1245
+ { "name": "id", "type": "bigint", "nullable": false, "primaryKey": true, "unique": true }
1246
+ ]
1172
1247
  }
1173
1248
  ],
1174
1249
  "relationships": [
1175
1250
  {
1176
- "name": "orders_customer",
1251
+ "name": "orders-customer",
1177
1252
  "from": { "model": "orders", "field": "customer_id" },
1178
1253
  "to": { "model": "customers", "field": "id" },
1179
1254
  "cardinality": "many-to-one"
@@ -1188,11 +1263,38 @@ It holds no SQL, credentials, rows, or provider configuration. `design init`
1188
1263
  emits this envelope with empty `models`, `relationships`, `accessPatterns`, and
1189
1264
  `decisions`.
1190
1265
 
1266
+ #### Naming and limits
1267
+
1268
+ Two different naming rules apply, and mixing them up is the most common way an
1269
+ artifact fails before any review rule runs.
1270
+
1271
+ | Applies to | Rule |
1272
+ |---|---|
1273
+ | `models[].name`, `relationships[].name`, `relationships[].from/to.model`, `accessPatterns[].model`, `decisions[].name` | lowercase kebab-case, `^[a-z][a-z0-9-]*$` — underscores are rejected |
1274
+ | `models[].table`, `fields[].name`, `indexes[].name`, `indexes[].columns[]`, `filters[]`, `sort[]` | SQL identifier, `^[A-Za-z_][A-Za-z0-9_]*$` |
1275
+
1276
+ Relationship endpoints reference a **model name**, not a table name. Every object
1277
+ is strict: an unknown key is an error, not ignored. `description` and `rationale`
1278
+ are 1–1000 characters and must not contain SQL keywords or a connection string —
1279
+ "rows we delete after 30 days" is rejected for the word `delete`. `fields[].type`
1280
+ is at most 100 characters with no `;` or newline. `primaryKey`, `unique`,
1281
+ `indexes`, `filters`, `sort`, `relationships`, `accessPatterns`, and `decisions`
1282
+ may all be omitted.
1283
+
1284
+ Limits: file 256 KiB, 100 models, 100 fields per model, 200 relationships,
1285
+ 200 access patterns, 100 decisions, 1–16 columns per index, ≤16 entries in
1286
+ `filters` and `sort`.
1287
+
1191
1288
  #### Review findings
1192
1289
 
1193
1290
  `validate` is fail-closed: any `error` finding exits `1`, and `render`, `diff`,
1194
1291
  and `propose` refuse to do their work while errors remain.
1195
1292
 
1293
+ Structural problems — malformed JSON, an unknown key, a naming or type violation,
1294
+ a missing file, or a file over 256 KiB — are rejected before review runs and are
1295
+ reported as a single `INVALID_ARTIFACT` finding (`error`) whose `path` points at
1296
+ the offending JSON location. None of the codes below appear in that case.
1297
+
1196
1298
  | Severity | Codes |
1197
1299
  |---|---|
1198
1300
  | `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 +1399,7 @@ Opt-in flag trio that persists a **VerificationArtifact JSON** (schema v1) under
1297
1399
  | Flag | Required | Description |
1298
1400
  | :--- | :--- | :--- |
1299
1401
  | `--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`. |
1402
+ | `--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
1403
  | `--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
1404
 
1303
1405
  **Output contract:**
@@ -1559,7 +1661,7 @@ Examples:
1559
1661
 
1560
1662
  Boundaries:
1561
1663
  - Recovery only **suggests** commands; agents (or humans) execute them. No automatic remediation in v1.15.0.
1562
- - As of v1.16.0, `--recovery` is honored on `query`, `q`, `insert`, `update`, `delete`, `export`, `schema`, and `inspect`. Other commands (`report`, `guide`, `doctor`, `migrate`, `init`, `use`, `status`, `list`, `check`, `diff`, `plan`, `shell`, `blacklist`, `completion`, `upgrade`, `skill`) keep their existing error behavior.
1664
+ - `--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
1665
  - `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
1666
  - `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
1667
  - Recovery steps reuse the v1.14.0 `GuideStep` shape, including the full `risk` enum (`readonly` / `dry-run` / `write` / `unknown`).
@@ -1593,7 +1695,7 @@ Boundaries:
1593
1695
  |---|---|---|
1594
1696
  | `readonly` | local read-only | `dbcli inspect`, `dbcli doctor`, `dbcli blacklist list`, `dbcli schema <table>` |
1595
1697
  | `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` |
1698
+ | `local-write` | writes local config / cache / blacklist | `dbcli blacklist table remove <table>`, `dbcli use <name>`, `dbcli schema --refresh` |
1597
1699
  | `db-write` | mutates the connected database | `dbcli update orders --where id=1 --set …` (no `--dry-run`), `dbcli q @x` (no `--dry-run`) |
1598
1700
  | `interactive` | requires TTY | `dbcli init`, `dbcli init --force` |
1599
1701
 
@@ -1746,7 +1848,7 @@ dbcli recover --next --after-step 1 --result '{"status":"ok"}' --format markdown
1746
1848
 
1747
1849
  (v1.20.0+) Inspect, query, and manage the per-connection audit log written to `.dbcli/audit/<connection>.jsonl`.
1748
1850
 
1749
- Audit entries are metadata-only by design — never raw SQL bodies, `--param` values, or result cell contents (D3 lock). Redaction is sourced from `tests/helpers/sensitive-output.ts` (same source as `inspect` / `guide` / `recover` agent contracts).
1851
+ 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
1852
 
1751
1853
  #### Subcommands
1752
1854
 
@@ -1783,7 +1885,9 @@ Examples:
1783
1885
  | `<id-prefix>` | Positional. UUID or prefix ≥ 4 characters; ambiguous prefix exits 1 with disambiguation hint; prefix < 4 chars exits 1. | — |
1784
1886
  | `--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
1887
  | `--all` | Search across all connections. Output is an envelope `{ connection, entry }` (single-hit also envelope, for shape stability — D-36). | off |
1786
- | `--no-brief` | Disable brief mode when a higher-level default enables it. | off |
1888
+ | `--brief` | Trim `metadata` and `redacted_query` from the entry. | off |
1889
+ | `--for-agent` | Shortcut for `--format json --brief`. | off |
1890
+ | `--no-brief` | Disable brief mode when a higher-level default enables it (e.g. `--for-agent`). | off |
1787
1891
  | `--format <fmt>` | `table` \| `json`. | `table` |
1788
1892
 
1789
1893
  Examples:
@@ -1817,7 +1921,7 @@ Output reports: writer enabled/disabled, last write result, file-lock state, rot
1817
1921
  #### Boundaries
1818
1922
 
1819
1923
  - 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 tail --recovery-ref <id>` to find the audit entry an envelope was emitted alongside.
1924
+ - 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
1925
  - 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
1926
  - 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
1927
 
@@ -2078,7 +2182,7 @@ dbcli verification list --include-invalid --format json
2078
2182
  | `--format <json\|table>` | Output format. | `json` |
2079
2183
  | `--limit <n>` | Maximum number of entries to return. | `20` |
2080
2184
  | `--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 |
2185
+ | `--subject <kind[:name]>` | Filter by subject kind or exact `kind:name`. Allowed kinds: `recovery`, `task-pack`, `assertion`, `migration`, `backfill`, `table`, `manual`. | all |
2082
2186
  | `--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
2187
 
2084
2188
  **Missing directory:** if `.dbcli/verification/` does not exist, exits `0` with an
@@ -2192,6 +2296,7 @@ includes `storageDir`, `dryRun`, `cutoff`, `criteria`, `protected`, `candidates`
2192
2296
  | `assertion` | General-purpose inline assertions. |
2193
2297
  | `migration` | Schema migration pre/post checks. |
2194
2298
  | `backfill` | Data backfill verification assertions. |
2299
+ | `table` | `verify constraint` artifacts — the subject name is the table checked. |
2195
2300
  | `manual` | Manually triggered or ad-hoc verification runs. |
2196
2301
 
2197
2302
  **Storage root:** `<cwd>/.dbcli/verification/` (cwd-relative; independent of `--config`).
@@ -3024,9 +3129,9 @@ Permission is derived from the command's first token (case-insensitive). Unknown
3024
3129
 
3025
3130
  | Tier | Commands |
3026
3131
  |------|----------|
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` |
3132
+ | `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` |
3133
+ | `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` |
3134
+ | `data-admin` | `DEL`, `UNLINK`, `HDEL`, `XDEL` |
3030
3135
  | `admin` | `FLUSHDB`, `FLUSHALL`, `CONFIG`, `INFO`, `CLIENT`, `DEBUG`, `SHUTDOWN`, `KEYS`, `MONITOR`, `SAVE`, `BGSAVE`, `BGREWRITEAOF`, `REPLICAOF`, `SLAVEOF`, `ACL` |
3031
3136
 
3032
3137
  ### Schema inspection
@@ -3237,5 +3342,5 @@ GET /orders/_search
3237
3342
 
3238
3343
  - 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
3344
  - No `_search/scroll` or PIT pagination at the CLI layer; large pulls need a saved external script.
3240
- - `check`, `diff`, `migrate`, and `q` are SQL-only and exit with errors (or fall through to a generic "unsupported" path).
3345
+ - `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
3346
  - Blacklist column rules are applied to flattened hit rows on `query`; table-level blacklist rejects an index up front.