@carllee1983/dbcli 1.50.0 → 1.51.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbcli-agent",
3
- "version": "1.49.0",
3
+ "version": "1.51.1",
4
4
  "description": "Database CLI skill and command reference for AI agents.",
5
5
  "contextFileName": "AGENTS.md"
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carllee1983/dbcli",
3
- "version": "1.50.0",
3
+ "version": "1.51.1",
4
4
  "description": "Database CLI for AI agents",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbcli-agent",
3
- "version": "1.50.0",
3
+ "version": "1.51.1",
4
4
  "description": "Database CLI skill and command reference for AI agents",
5
5
  "author": {
6
6
  "name": "Carl Lee",
@@ -82,6 +82,16 @@ warnings) go to stderr so stdout stays parseable — when piping JSON into a par
82
82
  use `2>/dev/null` or leave stderr alone. **Never `2>&1`**: it merges those lines back
83
83
  into stdout and the parse fails.
84
84
 
85
+ **Business-language discovery:** When a user uses a business alias, metric, recurring
86
+ term, or relationship/join intent instead of a physical table or field name, first run
87
+ `dbcli skill context --format json`. If it includes `semantic`, treat that reviewed
88
+ section as the governed vocabulary; use `dbcli semantic search <terms> --format json`
89
+ to look up a specific term. If no semantic section exists or search returns no result,
90
+ fall back to `blacklist` → `schema` mapping and tell the user that optional
91
+ `dbcli.semantic.json` can make future requests consistent. Never create, update, or
92
+ migrate that file without an explicit human request; semantic vocabulary never replaces
93
+ schema confirmation or the normal query/write safety gates.
94
+
85
95
  ## Agent Task Packs
86
96
 
87
97
  When the user asks for a database workflow ("diagnose this slow query", "audit
@@ -375,6 +385,7 @@ Full flags and edge cases: see [reference.md](reference.md) `init` section.
375
385
  | `upgrade` | n/a | Self-update from npm; 24h-cached version hints on every command. |
376
386
  | `shell` | (same as query+) | Interactive REPL. SQL engines, MongoDB, and Redis (single-line; `.no-limit on/off`). **(v1.22)** Elasticsearch opens a Kibana Dev Tools-style REPL (`<METHOD> /<path>` + optional JSON body, blank line submits). |
377
387
  | `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). |
388
+ | `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. |
378
389
  | `migrate` | admin | SQL only. **DDL; dry-run by default** — needs `--execute`. |
379
390
 
380
391
  Use root-level `dbcli --use <name> <command>` for any command; `query`, `schema`, `list`,
@@ -551,7 +562,7 @@ schema. Raw `query` / `export` invocations render a sortable table only.
551
562
  - **Health / growth:** `check --all` (huge tables skipped unless `--include-large`); consult schema `sizeCategory` before ad-hoc queries.
552
563
  - **Codegen from live DB:** `schema --format json` to drive an ORM; cross-check once with `dbcli query`.
553
564
  - **Integration truth:** `query` before → run app → `query` after. Unit-test mocks are not a substitute.
554
- - **Natural language requests** (e.g. "update order to shipped"): pick `query` vs DML, map terms → columns via `schema` (and enum values in data), respect blacklist and `sizeCategory`, **always `--dry-run` writes first**.
565
+ - **Natural language requests** (e.g. "update order to shipped"): follow **Business-language discovery** first when the request uses business terminology; then pick `query` vs DML, map terms → columns via `schema` (and enum values in data), respect blacklist and `sizeCategory`, **always `--dry-run` writes first**.
555
566
 
556
567
  ## Notes
557
568
 
@@ -2190,6 +2190,132 @@ dbcli migrate drop-enum status --execute --force
2190
2190
 
2191
2191
  **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.
2192
2192
 
2193
+ ### semantic
2194
+
2195
+ Validate or print the optional, version-controlled `dbcli.semantic.json` in the
2196
+ project root. It supplies business names and descriptions to an agent, but is
2197
+ not a query language: these commands are offline, read-only, and never execute
2198
+ SQL or contact an LLM.
2199
+
2200
+ When an agent receives a business term, metric, alias, or relationship/join intent,
2201
+ it should first inspect `dbcli skill context --format json`. If that output includes
2202
+ `semantic`, use the reviewed vocabulary and use `semantic search <terms>` for a
2203
+ specific lookup. When the section is absent or search has no result, fall back to the
2204
+ blacklist-filtered schema and tell the user that `dbcli.semantic.json` is an optional
2205
+ way to make future terminology consistent. Do not create, update, or migrate the file
2206
+ without an explicit human request.
2207
+
2208
+ ```bash
2209
+ dbcli semantic validate
2210
+ dbcli semantic validate --format json
2211
+ dbcli semantic context
2212
+ dbcli semantic context --format markdown
2213
+ dbcli semantic context --file ./analytics.semantic.json
2214
+ dbcli semantic drift --format json
2215
+ dbcli semantic migrate --to 2 --format json
2216
+ dbcli semantic search purchases --kind model --format json
2217
+ dbcli semantic draft validate --input ./draft.json --format json
2218
+ external-agent | dbcli semantic draft validate --input - --format json
2219
+ ```
2220
+
2221
+ The default file has this compact contract:
2222
+
2223
+ ```json
2224
+ {
2225
+ "version": 2,
2226
+ "models": [
2227
+ {
2228
+ "name": "orders",
2229
+ "table": "orders",
2230
+ "description": "Completed purchases.",
2231
+ "aliases": ["purchases"],
2232
+ "fields": [
2233
+ { "column": "created_at", "aliases": ["order date"] },
2234
+ { "column": "customer_id" }
2235
+ ]
2236
+ },
2237
+ {
2238
+ "name": "customers",
2239
+ "table": "customers",
2240
+ "fields": [{ "column": "id" }]
2241
+ }
2242
+ ],
2243
+ "relationships": [
2244
+ {
2245
+ "name": "order-customer",
2246
+ "from": { "model": "orders", "field": "customer_id" },
2247
+ "to": { "model": "customers", "field": "id" },
2248
+ "cardinality": "many-to-one",
2249
+ "description": "Each order belongs to one customer."
2250
+ }
2251
+ ],
2252
+ "metrics": [
2253
+ { "name": "daily-revenue", "query": "@analytics/revenue" }
2254
+ ]
2255
+ }
2256
+ ```
2257
+
2258
+ Version 1 remains supported and is normalized with `relationships: []`.
2259
+ Version 2 relationships must reference a declared model and a declared field on
2260
+ that model; the field must also be visible in cached schema. Their `cardinality`
2261
+ is one of `one-to-one`, `one-to-many`, `many-to-one`, or `many-to-many`.
2262
+ `models[].table` and `models[].fields[].column` must name a visible cached
2263
+ schema object. Blacklisted tables and columns are not visible and are rejected.
2264
+ Each metric `query` must name an available saved query. Validation parses its
2265
+ local file through the normal saved-query safety checks, but never executes or
2266
+ emits SQL. The semantic file cannot contain SQL, connection data, or
2267
+ credentials. `semantic validate` reports a
2268
+ deterministic success summary (`--format text|json`); `semantic context` prints
2269
+ the validated context (`--format json|markdown`). `semantic drift` returns a
2270
+ stable `valid`, `stale`, `invalid`, or `unavailable` report and exits non-zero
2271
+ for every status except `valid`; it never connects to a database. `semantic
2272
+ migrate --to 2` prints a deterministic v2 JSON document to stdout and never
2273
+ writes the input file. An absent default file is allowed for `skill context`
2274
+ and simply omits the semantic section; a stale or invalid present file fails
2275
+ closed rather than being silently ignored.
2276
+
2277
+ `semantic search <terms...>` performs deterministic, case-insensitive matching
2278
+ over canonical names, aliases, descriptions, and governed model paths. Results
2279
+ are ranked by exact canonical name, exact alias, prefix, then description token;
2280
+ kind/name breaks ties. Use `--kind model|field|relationship|metric` and
2281
+ `--limit <1-100>` (default `20`). It returns only canonical references, matched
2282
+ terms, aliases, descriptions, and necessary model paths—never SQL bodies,
2283
+ connection data, or blacklist names. No result is an empty array / text notice
2284
+ with exit 0.
2285
+
2286
+ `semantic draft validate --input <file|-> [--format text|json]` accepts only an
2287
+ explicit untrusted `QueryDraft` JSON document from a file or stdin. First give
2288
+ the external agent reviewed `dbcli semantic context --format json` output; its
2289
+ provider credentials, prompt, and other agent context remain outside dbcli. The
2290
+ agent returns a draft using only the declared models and fields, for example:
2291
+
2292
+ ```json
2293
+ {
2294
+ "version": 1,
2295
+ "questionHash": "<sha256-of-the-original-question>",
2296
+ "candidate": { "kind": "sql", "sql": "<reviewed-read-only-sql>" },
2297
+ "semanticReferences": ["model:<model>", "field:<model>.<field>"]
2298
+ }
2299
+ ```
2300
+
2301
+ The command validates the contract, read-only single-statement SQL, canonical
2302
+ semantic references, saved-query names, and local filtered schema/blacklist
2303
+ compatibility without connecting to a database, reading query results, storing
2304
+ the draft, or calling a provider. JSON reports contain only status, hashes,
2305
+ canonical references, and safe violation codes; they never echo candidate SQL
2306
+ or protected names. Exit `0` means valid, `1` means rejected, and `2` means
2307
+ required local semantic evidence is unavailable. A valid report is not execution
2308
+ authorization: review the original draft, then separately and explicitly invoke
2309
+ `dbcli explain "<reviewed-read-only-sql>"` or `dbcli query
2310
+ "<reviewed-read-only-sql>"` when appropriate.
2311
+
2312
+ When valid, `dbcli skill context` includes the same bounded data in its JSON,
2313
+ XML, and Markdown output. To run a metric, an agent must still invoke the named
2314
+ saved query through `dbcli q`; all ordinary permissions, blacklist masking,
2315
+ limits, audit, and recovery safeguards remain in force.
2316
+
2317
+ **Permission:** n/a (local files only; no database connection).
2318
+
2193
2319
  ### skill
2194
2320
 
2195
2321
  Emit `SKILL.md` (and the companion `reference.md`) to stdout, a file, or an
@@ -82,6 +82,16 @@ warnings) go to stderr so stdout stays parseable — when piping JSON into a par
82
82
  use `2>/dev/null` or leave stderr alone. **Never `2>&1`**: it merges those lines back
83
83
  into stdout and the parse fails.
84
84
 
85
+ **Business-language discovery:** When a user uses a business alias, metric, recurring
86
+ term, or relationship/join intent instead of a physical table or field name, first run
87
+ `dbcli skill context --format json`. If it includes `semantic`, treat that reviewed
88
+ section as the governed vocabulary; use `dbcli semantic search <terms> --format json`
89
+ to look up a specific term. If no semantic section exists or search returns no result,
90
+ fall back to `blacklist` → `schema` mapping and tell the user that optional
91
+ `dbcli.semantic.json` can make future requests consistent. Never create, update, or
92
+ migrate that file without an explicit human request; semantic vocabulary never replaces
93
+ schema confirmation or the normal query/write safety gates.
94
+
85
95
  ## Agent Task Packs
86
96
 
87
97
  When the user asks for a database workflow ("diagnose this slow query", "audit
@@ -375,6 +385,7 @@ Full flags and edge cases: see [reference.md](reference.md) `init` section.
375
385
  | `upgrade` | n/a | Self-update from npm; 24h-cached version hints on every command. |
376
386
  | `shell` | (same as query+) | Interactive REPL. SQL engines, MongoDB, and Redis (single-line; `.no-limit on/off`). **(v1.22)** Elasticsearch opens a Kibana Dev Tools-style REPL (`<METHOD> /<path>` + optional JSON body, blank line submits). |
377
387
  | `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). |
388
+ | `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. |
378
389
  | `migrate` | admin | SQL only. **DDL; dry-run by default** — needs `--execute`. |
379
390
 
380
391
  Use root-level `dbcli --use <name> <command>` for any command; `query`, `schema`, `list`,
@@ -551,7 +562,7 @@ schema. Raw `query` / `export` invocations render a sortable table only.
551
562
  - **Health / growth:** `check --all` (huge tables skipped unless `--include-large`); consult schema `sizeCategory` before ad-hoc queries.
552
563
  - **Codegen from live DB:** `schema --format json` to drive an ORM; cross-check once with `dbcli query`.
553
564
  - **Integration truth:** `query` before → run app → `query` after. Unit-test mocks are not a substitute.
554
- - **Natural language requests** (e.g. "update order to shipped"): pick `query` vs DML, map terms → columns via `schema` (and enum values in data), respect blacklist and `sizeCategory`, **always `--dry-run` writes first**.
565
+ - **Natural language requests** (e.g. "update order to shipped"): follow **Business-language discovery** first when the request uses business terminology; then pick `query` vs DML, map terms → columns via `schema` (and enum values in data), respect blacklist and `sizeCategory`, **always `--dry-run` writes first**.
555
566
 
556
567
  ## Notes
557
568
 
@@ -2190,6 +2190,132 @@ dbcli migrate drop-enum status --execute --force
2190
2190
 
2191
2191
  **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.
2192
2192
 
2193
+ ### semantic
2194
+
2195
+ Validate or print the optional, version-controlled `dbcli.semantic.json` in the
2196
+ project root. It supplies business names and descriptions to an agent, but is
2197
+ not a query language: these commands are offline, read-only, and never execute
2198
+ SQL or contact an LLM.
2199
+
2200
+ When an agent receives a business term, metric, alias, or relationship/join intent,
2201
+ it should first inspect `dbcli skill context --format json`. If that output includes
2202
+ `semantic`, use the reviewed vocabulary and use `semantic search <terms>` for a
2203
+ specific lookup. When the section is absent or search has no result, fall back to the
2204
+ blacklist-filtered schema and tell the user that `dbcli.semantic.json` is an optional
2205
+ way to make future terminology consistent. Do not create, update, or migrate the file
2206
+ without an explicit human request.
2207
+
2208
+ ```bash
2209
+ dbcli semantic validate
2210
+ dbcli semantic validate --format json
2211
+ dbcli semantic context
2212
+ dbcli semantic context --format markdown
2213
+ dbcli semantic context --file ./analytics.semantic.json
2214
+ dbcli semantic drift --format json
2215
+ dbcli semantic migrate --to 2 --format json
2216
+ dbcli semantic search purchases --kind model --format json
2217
+ dbcli semantic draft validate --input ./draft.json --format json
2218
+ external-agent | dbcli semantic draft validate --input - --format json
2219
+ ```
2220
+
2221
+ The default file has this compact contract:
2222
+
2223
+ ```json
2224
+ {
2225
+ "version": 2,
2226
+ "models": [
2227
+ {
2228
+ "name": "orders",
2229
+ "table": "orders",
2230
+ "description": "Completed purchases.",
2231
+ "aliases": ["purchases"],
2232
+ "fields": [
2233
+ { "column": "created_at", "aliases": ["order date"] },
2234
+ { "column": "customer_id" }
2235
+ ]
2236
+ },
2237
+ {
2238
+ "name": "customers",
2239
+ "table": "customers",
2240
+ "fields": [{ "column": "id" }]
2241
+ }
2242
+ ],
2243
+ "relationships": [
2244
+ {
2245
+ "name": "order-customer",
2246
+ "from": { "model": "orders", "field": "customer_id" },
2247
+ "to": { "model": "customers", "field": "id" },
2248
+ "cardinality": "many-to-one",
2249
+ "description": "Each order belongs to one customer."
2250
+ }
2251
+ ],
2252
+ "metrics": [
2253
+ { "name": "daily-revenue", "query": "@analytics/revenue" }
2254
+ ]
2255
+ }
2256
+ ```
2257
+
2258
+ Version 1 remains supported and is normalized with `relationships: []`.
2259
+ Version 2 relationships must reference a declared model and a declared field on
2260
+ that model; the field must also be visible in cached schema. Their `cardinality`
2261
+ is one of `one-to-one`, `one-to-many`, `many-to-one`, or `many-to-many`.
2262
+ `models[].table` and `models[].fields[].column` must name a visible cached
2263
+ schema object. Blacklisted tables and columns are not visible and are rejected.
2264
+ Each metric `query` must name an available saved query. Validation parses its
2265
+ local file through the normal saved-query safety checks, but never executes or
2266
+ emits SQL. The semantic file cannot contain SQL, connection data, or
2267
+ credentials. `semantic validate` reports a
2268
+ deterministic success summary (`--format text|json`); `semantic context` prints
2269
+ the validated context (`--format json|markdown`). `semantic drift` returns a
2270
+ stable `valid`, `stale`, `invalid`, or `unavailable` report and exits non-zero
2271
+ for every status except `valid`; it never connects to a database. `semantic
2272
+ migrate --to 2` prints a deterministic v2 JSON document to stdout and never
2273
+ writes the input file. An absent default file is allowed for `skill context`
2274
+ and simply omits the semantic section; a stale or invalid present file fails
2275
+ closed rather than being silently ignored.
2276
+
2277
+ `semantic search <terms...>` performs deterministic, case-insensitive matching
2278
+ over canonical names, aliases, descriptions, and governed model paths. Results
2279
+ are ranked by exact canonical name, exact alias, prefix, then description token;
2280
+ kind/name breaks ties. Use `--kind model|field|relationship|metric` and
2281
+ `--limit <1-100>` (default `20`). It returns only canonical references, matched
2282
+ terms, aliases, descriptions, and necessary model paths—never SQL bodies,
2283
+ connection data, or blacklist names. No result is an empty array / text notice
2284
+ with exit 0.
2285
+
2286
+ `semantic draft validate --input <file|-> [--format text|json]` accepts only an
2287
+ explicit untrusted `QueryDraft` JSON document from a file or stdin. First give
2288
+ the external agent reviewed `dbcli semantic context --format json` output; its
2289
+ provider credentials, prompt, and other agent context remain outside dbcli. The
2290
+ agent returns a draft using only the declared models and fields, for example:
2291
+
2292
+ ```json
2293
+ {
2294
+ "version": 1,
2295
+ "questionHash": "<sha256-of-the-original-question>",
2296
+ "candidate": { "kind": "sql", "sql": "<reviewed-read-only-sql>" },
2297
+ "semanticReferences": ["model:<model>", "field:<model>.<field>"]
2298
+ }
2299
+ ```
2300
+
2301
+ The command validates the contract, read-only single-statement SQL, canonical
2302
+ semantic references, saved-query names, and local filtered schema/blacklist
2303
+ compatibility without connecting to a database, reading query results, storing
2304
+ the draft, or calling a provider. JSON reports contain only status, hashes,
2305
+ canonical references, and safe violation codes; they never echo candidate SQL
2306
+ or protected names. Exit `0` means valid, `1` means rejected, and `2` means
2307
+ required local semantic evidence is unavailable. A valid report is not execution
2308
+ authorization: review the original draft, then separately and explicitly invoke
2309
+ `dbcli explain "<reviewed-read-only-sql>"` or `dbcli query
2310
+ "<reviewed-read-only-sql>"` when appropriate.
2311
+
2312
+ When valid, `dbcli skill context` includes the same bounded data in its JSON,
2313
+ XML, and Markdown output. To run a metric, an agent must still invoke the named
2314
+ saved query through `dbcli q`; all ordinary permissions, blacklist masking,
2315
+ limits, audit, and recovery safeguards remain in force.
2316
+
2317
+ **Permission:** n/a (local files only; no database connection).
2318
+
2193
2319
  ### skill
2194
2320
 
2195
2321
  Emit `SKILL.md` (and the companion `reference.md`) to stdout, a file, or an