@carllee1983/dbcli 1.32.0 → 1.37.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.
@@ -616,6 +616,46 @@ dbcli assert "SELECT count(*) FROM orders" --expect "value > 100" --no-fail #
616
616
  **Engines:** SQL only (PostgreSQL / MySQL / MariaDB)
617
617
  **Permission:** query-only+
618
618
 
619
+ #### Verification artifact (--write-verification-artifact)
620
+
621
+ Opt-in flag trio that persists a **VerificationArtifact JSON** (schema v1) under `<cwd>/.dbcli/verification/` after the assertion runs. The artifact is always written to `<cwd>/.dbcli/verification/` (relative to the current working directory), regardless of where the `--config` file is located.
622
+
623
+ | Flag | Required | Description |
624
+ | :--- | :--- | :--- |
625
+ | `--write-verification-artifact` | opt-in | Trigger artifact write. No-op when no verdict has been produced. |
626
+ | `--verification-subject <kind:name>` | yes (when flag is set) | Subject identifier. Format: `<kind>:<name>`. Allowed kinds: `recovery`, `task-pack`, `assertion`, `migration`, `backfill`, `manual`. |
627
+ | `--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." |
628
+
629
+ **Output contract:**
630
+
631
+ - `--format json` — `AssertVerdict` gains `verificationArtifactPath: string` pointing to the written file.
632
+ - `--format table` — an extra `Verification artifact: <path>` line is printed after the verdict table.
633
+ - A `--no-fail` assertion that fails still records status `not_verified` and stores `exitCode: 1` in evidence.
634
+
635
+ **Planned vs Result evidence.** `dbcli skill tasks plan safe-backfill-verify --format json` returns a plan containing a `verification` block with `status: "planned"`. That block is the **planned** evidence definition — it describes which check will run. Running `assert --write-verification-artifact` on the actual data produces **result** evidence (`status: "verified"` or `status: "not_verified"`). The two records are distinct; `"planned"` does **not** indicate that verification has run or passed.
636
+
637
+ > **Casting note:** Postgres returns `count(*)` and `sum()` as bigint (a string in the result set). `value ==` uses strict equality, so `"0" == 0` is false. Cast to `::int` (`count(*)::int`) to ensure numeric comparison works correctly.
638
+
639
+ ```bash
640
+ dbcli assert "SELECT count(*)::int FROM orders WHERE status IS NULL" \
641
+ --expect "value == 0" \
642
+ --write-verification-artifact \
643
+ --verification-subject backfill:safe-backfill-verify
644
+
645
+ dbcli assert "SELECT count(*)::int FROM orders WHERE status IS NULL" \
646
+ --expect "value == 0" \
647
+ --write-verification-artifact \
648
+ --verification-subject backfill:safe-backfill-verify \
649
+ --verification-summary "Post-backfill null-status count is zero."
650
+
651
+ # --no-fail: exits 0 but still records not_verified on failure
652
+ dbcli assert "SELECT count(*)::int FROM orders WHERE status IS NULL" \
653
+ --expect "value == 0" \
654
+ --no-fail \
655
+ --write-verification-artifact \
656
+ --verification-subject backfill:safe-backfill-verify
657
+ ```
658
+
619
659
  ### proxy
620
660
 
621
661
  Local-development **observability proxy** for MySQL/MariaDB/PostgreSQL. Inserts dbcli
@@ -1104,6 +1144,243 @@ Output reports: writer enabled/disabled, last write result, file-lock state, rot
1104
1144
 
1105
1145
  **Permission:** n/a
1106
1146
 
1147
+ ### verify
1148
+
1149
+ Run a verification scenario. `verify` **runs** verification scenarios (safe-backfill,
1150
+ migration) and never executes writes/DDL. `verification` **inspects and manages** the
1151
+ local result artifacts those scenarios produce under `.dbcli/verification/`.
1152
+
1153
+ ```bash
1154
+ # Preflight (default): read-only guards + the exact after-write command. No artifact.
1155
+ dbcli verify safe-backfill \
1156
+ --table users \
1157
+ --query "UPDATE users SET status = 1 WHERE status IS NULL" \
1158
+ --verify-query "SELECT count(*)::int AS n FROM users WHERE status IS NULL" \
1159
+ --expect "value == 0"
1160
+
1161
+ # After-write: re-run guards, run the read-back assertion, write a v1 artifact.
1162
+ dbcli verify safe-backfill ... --after-write
1163
+
1164
+ # JSON for agents.
1165
+ dbcli verify safe-backfill ... --format json
1166
+ ```
1167
+
1168
+ Options: `--table` (req), `--query` (req, analyzed not executed), `--verify-query`
1169
+ (req, **plain SELECT only**), `--expect` (req), `--after-write`, `--format <table|json>`,
1170
+ `--subject-name <name>`, `--summary <text>`.
1171
+
1172
+ Guard constraints (fail closed): `--verify-query` must be a **plain `SELECT`** —
1173
+ `EXPLAIN`/`EXPLAIN ANALYZE`, `SHOW`, `DESCRIBE`, and data-modifying CTEs are rejected
1174
+ (on PostgreSQL `EXPLAIN ANALYZE <write>` actually performs the write). The `--query`
1175
+ **UPDATE target must equal `--table`**, compared schema-aware (`public.users` ≠
1176
+ `audit.users`). The persisted artifact stores only a bounded, literal-free label of the
1177
+ verify-query and `--expect` — string, numeric, and dollar-quoted literals are stripped,
1178
+ so raw SQL/values are never written to disk. The printed after-write
1179
+ command is shell-escaped and carries through `--subject-name`/`--summary`/non-default
1180
+ `--format`. For repeated backfills on the same table, pass a unique `--subject-name` so
1181
+ each operation is independently traceable (the subject defaults to `backfill:<table>`).
1182
+
1183
+ Status: `ready`/`blocked` in preflight (no artifact); `verified`, `not_verified`,
1184
+ `blocked`, or `indeterminate` in after-write (artifact written). `blocked` = a guard
1185
+ failed (blacklist/schema/plan/verify-query-not-plain-SELECT/target-table-mismatch);
1186
+ `not_verified` = the read-back contradicted `--expect`; `indeterminate` = the assertion
1187
+ could not produce a trustworthy verdict. Inspect the result with
1188
+ `dbcli verification show <artifact-id>`.
1189
+
1190
+ #### `verify migration`
1191
+
1192
+ Preflight or after-write verification for a schema migration. **This command never
1193
+ executes DDL** — it analyzes the proposed `ALTER TABLE`, runs read-only guards, and
1194
+ (in after-write mode) records evidence after you apply the migration externally.
1195
+
1196
+ ```bash
1197
+ # Preflight: read-only guards + the exact after-write command. Returns ready or blocked.
1198
+ dbcli verify migration \
1199
+ --table users \
1200
+ --ddl "ALTER TABLE users ADD COLUMN verified_at TIMESTAMPTZ" \
1201
+ --verify-query "SELECT count(*)::int AS n FROM users WHERE verified_at IS NOT NULL" \
1202
+ --expect "value == 0"
1203
+
1204
+ # After the migration is applied externally, record evidence:
1205
+ dbcli verify migration ... --after-write
1206
+
1207
+ # JSON for agents.
1208
+ dbcli verify migration ... --format json
1209
+ ```
1210
+
1211
+ | Option | Required | Description |
1212
+ | --- | --- | --- |
1213
+ | `--table <table>` | yes | Table affected by the migration. |
1214
+ | `--ddl <sql>` | yes | Proposed migration DDL, analyzed but never executed. MVP accepts `ALTER TABLE` only. |
1215
+ | `--verify-query <sql>` | yes | Plain `SELECT` for post-migration read-back verification. |
1216
+ | `--expect <expr>` | yes | Assertion expression for the read-back result. |
1217
+ | `--after-write` | no | Run the post-migration assertion and write a v1 artifact. |
1218
+ | `--format <table\|json>` | no | Output format, default `table`. |
1219
+ | `--subject-name <name>` | no | Artifact subject name. Default is the table name. |
1220
+ | `--summary <text>` | no | Optional artifact summary override. |
1221
+
1222
+ Preflight returns `ready` or `blocked` and prints the exact after-write command;
1223
+ **`ready` is not `verified`** — it only means the guards passed. After-write maps the
1224
+ read-back assertion to `verified` / `not_verified` / `indeterminate`, and a failed
1225
+ guard to `blocked`. `CREATE TABLE`, `DROP TABLE`, `CREATE INDEX`, and multi-statement
1226
+ DDL are blocked in the MVP.
1227
+
1228
+ The `ALTER TABLE` target may be `table`, `schema.table`, or `catalog.schema.table`.
1229
+ Each segment is a simple unquoted name (`[A-Za-z_][A-Za-z0-9_]*`) or a quoted
1230
+ identifier — double-quoted (`"…"`), backtick-quoted (`` `…` ``), or bracket-quoted
1231
+ (`[…]`) — so `"user accounts"` or `"tenant-1"."orders"` are accepted. Targets that
1232
+ cannot be fully parsed under this contract (unterminated quotes, unsupported escapes,
1233
+ or more than three parts) are blocked before the after-write assertion with a
1234
+ "could not be parsed" reason, distinct from the `must match --table` mismatch reason.
1235
+
1236
+ ### verification
1237
+
1238
+ (v1.33.0+) Local **VerificationArtifact** inspection and lifecycle surface over
1239
+ `<cwd>/.dbcli/verification/` (always relative to the current working directory,
1240
+ regardless of `--config` location). `list`, `show`, and `summary` are read-only;
1241
+ `prune` is a local lifecycle command — dry-run by default, deleting only with
1242
+ `--execute --force`. Requires no database connection and performs no audit writes.
1243
+
1244
+ **Subcommands:** `list` · `show` · `summary` · `prune`
1245
+
1246
+ #### `verification list`
1247
+
1248
+ List verification artifacts on disk, with optional filters.
1249
+
1250
+ ```bash
1251
+ dbcli verification list --format json
1252
+ dbcli verification list --status verified
1253
+ dbcli verification list --subject backfill
1254
+ dbcli verification list --subject backfill:safe-backfill-verify
1255
+ dbcli verification list --limit 20 --format json
1256
+ dbcli verification list --include-invalid --format json
1257
+ ```
1258
+
1259
+ | Flag | Purpose | Default |
1260
+ |---|---|---|
1261
+ | `--format <json\|table>` | Output format. | `json` |
1262
+ | `--limit <n>` | Maximum number of entries to return. | `20` |
1263
+ | `--status <status>` | Filter by status. One of: `verified`, `not_verified`, `indeterminate`, `blocked`. | all |
1264
+ | `--subject <kind[:name]>` | Filter by subject kind or exact `kind:name`. Allowed kinds: `recovery`, `task-pack`, `assertion`, `migration`, `backfill`, `manual`. | all |
1265
+ | `--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 |
1266
+
1267
+ **Missing directory:** if `.dbcli/verification/` does not exist, exits `0` with an
1268
+ empty result (list: `[]`, summary: zero counts).
1269
+
1270
+ **Malformed files:** by default, files that cannot be parsed as valid VerificationArtifact
1271
+ JSON are silently skipped. Pass `--include-invalid` to surface them.
1272
+
1273
+ #### `verification show`
1274
+
1275
+ Print a single verification artifact by its id (the artifact's `id` field) or by
1276
+ the path to the artifact file.
1277
+
1278
+ ```bash
1279
+ dbcli verification show abc123 --format json
1280
+ dbcli verification show abc123 --format table
1281
+ dbcli verification show .dbcli/verification/abc123.json --format json
1282
+ ```
1283
+
1284
+ | Flag | Purpose | Default |
1285
+ |---|---|---|
1286
+ | `<id-or-path>` | Positional. The artifact `id` (format `ver_<base36>_<hex>`), a unique id prefix, the artifact filename, or a path to the file inside `.dbcli/verification/`. | required |
1287
+ | `--format <json\|table>` | Output format. | `json` |
1288
+
1289
+ **Exit codes:**
1290
+ - `0` — artifact found and valid.
1291
+ - `1` — id or path not found, or the artifact file is malformed (parse error).
1292
+
1293
+ #### `verification summary`
1294
+
1295
+ Aggregate verification artifacts into status counts, optionally filtered.
1296
+
1297
+ ```bash
1298
+ dbcli verification summary --format json
1299
+ dbcli verification summary --status not_verified --format json
1300
+ dbcli verification summary --subject migration --format json
1301
+ dbcli verification summary --subject migration:add-status-column --format json
1302
+ ```
1303
+
1304
+ | Flag | Purpose | Default |
1305
+ |---|---|---|
1306
+ | `--format <json\|table>` | Output format. | `json` |
1307
+ | `--status <status>` | Filter to a single status before summarising. | all |
1308
+ | `--subject <kind[:name]>` | Filter by subject kind or exact `kind:name`. | all |
1309
+ | `--latest-only` | Narrow to the latest matching valid artifact plus status counts; the `subjects` breakdown is omitted. Missing artifacts return exit `0` with `latest: null`. | off |
1310
+
1311
+ **Output shape (JSON):**
1312
+ ```json
1313
+ {
1314
+ "storageDir": "/abs/path/.dbcli/verification",
1315
+ "latest": {
1316
+ "path": "...",
1317
+ "id": "ver_...",
1318
+ "createdAt": "2026-06-19T01:02:03.000Z",
1319
+ "status": "verified",
1320
+ "subject": { "kind": "backfill", "name": "safe-backfill-verify" },
1321
+ "summary": "..."
1322
+ },
1323
+ "counts": { "total": 4, "verified": 2, "not_verified": 1, "indeterminate": 0, "blocked": 1, "invalid": 0 },
1324
+ "subjects": [
1325
+ { "subject": { "kind": "backfill", "name": "safe-backfill-verify" }, "total": 3, "latestStatus": "verified", "latestCreatedAt": "2026-06-19T01:02:03.000Z" }
1326
+ ]
1327
+ }
1328
+ ```
1329
+
1330
+ `latest` is `null` when no valid artifacts match the filters.
1331
+
1332
+ #### `verification prune`
1333
+
1334
+ Preview or delete local verification artifacts under `<cwd>/.dbcli/verification/` by
1335
+ explicit retention criteria. **Dry-run by default**; deletes only with `--execute --force`.
1336
+
1337
+ ```bash
1338
+ dbcli verification prune --older-than 30d --format json # preview candidates
1339
+ dbcli verification prune --older-than 30d --execute --force # delete after preview
1340
+ dbcli verification prune --older-than 90d --status verified --keep-latest 50 --execute --force
1341
+ ```
1342
+
1343
+ | Option | Default | Meaning |
1344
+ | --- | --- | --- |
1345
+ | `--format <format>` | `json` | `json` or `table`. JSON is the authoritative contract. |
1346
+ | `--older-than <Nd>` | required | Minimum age in whole days (`7d`, `30d`, `365d`). |
1347
+ | `--keep-latest <n>` | `20` | Always protect the latest N valid artifacts across all subjects/statuses before filters. `0` protects none. |
1348
+ | `--status <status>` | none | Select only valid artifacts with this status. |
1349
+ | `--subject <kind:name>` | none | Select only valid artifacts with this subject. |
1350
+ | `--include-invalid` | `false` | Also select malformed `verification-*.json` files, by file mtime. |
1351
+ | `--execute` | `false` | Delete instead of preview. Requires `--force`. |
1352
+ | `--force` | `false` | Acknowledge deletion; required with `--execute`. |
1353
+
1354
+ Safety: deletion is scoped to regular `verification-*.json` files inside
1355
+ `.dbcli/verification/`; symlinks, directories, and path escapes are skipped with a
1356
+ reason. No database connection is opened and no audit entry is written. JSON output
1357
+ includes `storageDir`, `dryRun`, `cutoff`, `criteria`, `protected`, `candidates`,
1358
+ `deleted`, and `skipped`.
1359
+
1360
+ **Statuses:**
1361
+
1362
+ | Status | Meaning |
1363
+ |---|---|
1364
+ | `verified` | The assertion ran and evidence matched the expected state. |
1365
+ | `not_verified` | The assertion ran and evidence contradicted the expected state. |
1366
+ | `indeterminate` | The assertion ran but evidence was ambiguous (JSON parse failure, missing field, gate skip). |
1367
+ | `blocked` | Verification could not run due to config, permission, schema, placeholder, or safety gates. |
1368
+
1369
+ **Subject kinds:**
1370
+
1371
+ | Kind | Produced by |
1372
+ |---|---|
1373
+ | `recovery` | Post-recovery verification assertions. |
1374
+ | `task-pack` | Assertions generated by task pack plans. |
1375
+ | `assertion` | General-purpose inline assertions. |
1376
+ | `migration` | Schema migration pre/post checks. |
1377
+ | `backfill` | Data backfill verification assertions. |
1378
+ | `manual` | Manually triggered or ad-hoc verification runs. |
1379
+
1380
+ **Storage root:** `<cwd>/.dbcli/verification/` (cwd-relative; independent of `--config`).
1381
+
1382
+ **Permission:** n/a
1383
+
1107
1384
  ### doctor
1108
1385
 
1109
1386
  Run diagnostic checks on environment, configuration, connection, and data.