@carllee1983/dbcli 1.8.0 → 1.9.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.
- package/CHANGELOG.md +28 -0
- package/README.md +39 -1
- package/README.zh-TW.md +1 -1
- package/assets/SKILL.md +136 -18
- package/assets/reference.md +27 -0
- package/assets/tasks/README.md +30 -0
- package/assets/tasks/diagnose-slow-query.md +33 -0
- package/dist/cli.mjs +1499 -11217
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,34 @@ All notable changes to dbcli are documented here.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.9.1] - 2026-05-07
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **Skill 連線設定指引**:`assets/SKILL.md` 加入「Connection setup」章節,補齊 AI agent 協助使用者建立資料庫連線時所需的決策樹與各 engine essentials。
|
|
13
|
+
- 決策樹:v1 vs v2、credentials 來源(`.env` / env-refs / 明文)、權限 tier、`status` + `doctor` 驗證。
|
|
14
|
+
- Per-engine essentials:PostgreSQL / MySQL / MariaDB / MongoDB(含 `mongodb+srv://`)/ Redis(`--name` 為 logical DB index)/ Elasticsearch(basic / Cloud ID / API key)。
|
|
15
|
+
- v2 multi-connection 範例(`--conn-name`、`--env-file`、`use --list`、`--rename`、`--remove`)與 per-connection schema cache 注意事項。
|
|
16
|
+
- env-refs(`{ "$env": "..." }`)說明,以及「不要用 `--force` 把 env-refs 蓋成明文」的 guard。
|
|
17
|
+
- 常見陷阱:SRV DNS、URL 中特殊字元編碼、Redis `--name` 限制、Elasticsearch TLS 設定需手動編輯 `.dbcli`。
|
|
18
|
+
- 同步擴充 frontmatter `description`,加入 `init` / `.dbcli` / auth modes 觸發詞,提升 skill 觸發精準度。
|
|
19
|
+
|
|
20
|
+
## [1.9.0] - 2026-05-06
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- **Agent Task Packs(plan-only 第一版)**:`dbcli skill tasks list/show/plan` 讓 AI agent 可探索團隊定義的資料庫任務範本並產生安全可審查的執行計畫。
|
|
25
|
+
- 三層儲存:`assets/tasks/`(內建)< `.dbcli-shared/tasks/`(團隊共享)< `.dbcli/tasks/`(個人覆蓋)。
|
|
26
|
+
- Task 檔為 `.md`:YAML frontmatter(name/description/tags/engines/params/safety/steps)+ markdown agent notes。
|
|
27
|
+
- 嚴格 schema:`safety.mode` 僅接受 `plan-only`、`step.type` 僅接受 `command`,未知欄位直接 fail 解析而非靜默忽略。
|
|
28
|
+
- `plan` 輸出包含原始 `command`、`resolvedCommand`、`argv`(shell-aware 切分),方便 agent 直接消費。
|
|
29
|
+
- 內建第一版 `diagnose-slow-query` 任務作為範例。
|
|
30
|
+
- 文件:`assets/SKILL.md` 與 `assets/reference.md` 同步加入 Agent Task Packs 章節;`docs/feature-matrix.md` 補充 `skill tasks` 子命令說明。
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
|
|
34
|
+
- `src/core/saved-queries/yaml-mini.ts`:擴充支援 YAML block list 語法(`- scalar`、`- key: value` 起始的 sub-map),以承載 Agent Task Packs 的 frontmatter;既有 saved-queries 解析行為不變、66 個既有測試全綠。
|
|
35
|
+
|
|
8
36
|
## [1.8.0] - 2026-05-06
|
|
9
37
|
|
|
10
38
|
### Added
|
package/README.md
CHANGED
|
@@ -114,7 +114,45 @@ dbcli query '{"status":"active"}' --collection users --use atlas
|
|
|
114
114
|
|
|
115
115
|
For MongoDB, `list` and `query` operate on the database configured for the connection, and `query` requires `--collection <name>`.
|
|
116
116
|
|
|
117
|
-
For a command-by-command support matrix across PostgreSQL, MySQL, MariaDB, and
|
|
117
|
+
For a command-by-command support matrix across PostgreSQL, MySQL, MariaDB, MongoDB, Redis, and Elasticsearch, see [docs/feature-matrix.md](./docs/feature-matrix.md).
|
|
118
|
+
|
|
119
|
+
### Redis & Elasticsearch Support
|
|
120
|
+
|
|
121
|
+
dbcli extends its unified interface to Redis and Elasticsearch, providing consistent discovery and querying.
|
|
122
|
+
|
|
123
|
+
#### Redis
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Connect to Redis
|
|
127
|
+
dbcli init --system redis --host localhost --port 6379
|
|
128
|
+
|
|
129
|
+
# List keys (uses SCAN)
|
|
130
|
+
dbcli list
|
|
131
|
+
|
|
132
|
+
# Inspect a key (type, TTL, size, sample)
|
|
133
|
+
dbcli schema my-key
|
|
134
|
+
|
|
135
|
+
# Run Redis commands (whitelisted)
|
|
136
|
+
dbcli query "GET my-key"
|
|
137
|
+
dbcli query "HGETALL user:1"
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### Elasticsearch
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# Connect to Elasticsearch
|
|
144
|
+
dbcli init --system elasticsearch --host localhost --port 9200
|
|
145
|
+
|
|
146
|
+
# List indices and document counts
|
|
147
|
+
dbcli list
|
|
148
|
+
|
|
149
|
+
# Show mapping/structure of an index
|
|
150
|
+
dbcli schema my-index
|
|
151
|
+
|
|
152
|
+
# Query using Lucene or DSL JSON
|
|
153
|
+
dbcli query "status:active" --index my-index
|
|
154
|
+
dbcli query '{"query": {"match_all": {}}}' --index my-index
|
|
155
|
+
```
|
|
118
156
|
|
|
119
157
|
---
|
|
120
158
|
|
package/README.zh-TW.md
CHANGED
|
@@ -189,7 +189,7 @@ dbcli init [OPTIONS]
|
|
|
189
189
|
```
|
|
190
190
|
|
|
191
191
|
**選項 (基本):**
|
|
192
|
-
- `--system <type>` — 資料庫系統:`postgresql`、`mysql`、`mariadb`、`mongodb`
|
|
192
|
+
- `--system <type>` — 資料庫系統:`postgresql`、`mysql`、`mariadb`、`mongodb`、`redis`、`elasticsearch`
|
|
193
193
|
- `--host <host>` — 主機
|
|
194
194
|
- `--port <port>` — 埠號
|
|
195
195
|
- `--user <user>` — 使用者
|
package/assets/SKILL.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: dbcli
|
|
3
|
-
description: Database CLI for AI agents with permission-based access control. Use to query, inspect schemas, insert/update/delete, export results, and blacklist sensitive columns/tables. Supports MySQL, PostgreSQL, MariaDB, MongoDB, Redis, and Elasticsearch with multiple named connections per project and custom env files. Trigger when
|
|
3
|
+
description: Database CLI for AI agents with permission-based access control. Use to set up new connections, query, inspect schemas, insert/update/delete, export results, and blacklist sensitive columns/tables. Supports MySQL, PostgreSQL, MariaDB, MongoDB, Redis, and Elasticsearch with multiple named connections per project and custom env files. Trigger when configuring a database connection (`.dbcli` / `.env`), choosing between v1 single and v2 multi-connection layouts, picking auth modes (URI, env refs, Cloud ID, API key), running SQL / MongoDB JSON / Redis commands / Elasticsearch DSL, exploring table/collection/key/index structures, switching database environments, or protecting sensitive data from AI access. For exhaustive flags and examples, read the sibling `reference.md`.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# dbcli
|
|
@@ -11,13 +11,32 @@ Database CLI for AI agents with permission-based access control.
|
|
|
11
11
|
|
|
12
12
|
1. `dbcli status` — permission level and system summary (no credentials).
|
|
13
13
|
2. `dbcli blacklist list` — sensitive data boundaries.
|
|
14
|
-
3. `dbcli schema <table> --format json` — real column names. **Never guess.**
|
|
14
|
+
3. `dbcli schema <table> --format json` — real column names (SQL/Mongo/ES) or `schema <key>` (Redis). **Never guess.**
|
|
15
15
|
4. Run `query` / `insert` / `update` / `delete` / `export` within permission.
|
|
16
|
-
5. All writes: `--dry-run` → run → `query` read-back to confirm.
|
|
16
|
+
5. All writes: `--dry-run` (SQL/Mongo) → run → `query` read-back to confirm.
|
|
17
17
|
|
|
18
18
|
Prefer `--format json` for agent-friendly output.
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
## Agent Task Packs
|
|
21
|
+
|
|
22
|
+
When the user asks for a database workflow (e.g. "diagnose this slow query", "audit
|
|
23
|
+
permissions", "review long-running operations"), prefer published task templates
|
|
24
|
+
over inventing steps from memory.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
dbcli skill tasks list --format json # discover
|
|
28
|
+
dbcli skill tasks show <task> # inspect
|
|
29
|
+
dbcli skill tasks plan <task> --param key=value --format json # generate plan
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The plan output is an ordered list of dbcli commands with rationale and risk
|
|
33
|
+
labels. Execute them one at a time — task plans do **not** override blacklist,
|
|
34
|
+
schema, dry-run, or confirmation requirements.
|
|
35
|
+
|
|
36
|
+
Tasks live under `assets/tasks/` (builtin), `.dbcli-shared/tasks/` (shared), and
|
|
37
|
+
`.dbcli/tasks/` (local override).
|
|
38
|
+
|
|
39
|
+
Full flags, per-command copy-paste blocks, `migrate` DDL, interactive `shell`, and MongoDB/Redis/ES walkthroughs are in [reference.md](reference.md) (installed next to this file).
|
|
21
40
|
|
|
22
41
|
## Quick start
|
|
23
42
|
|
|
@@ -27,6 +46,107 @@ dbcli schema # Scan all tables → .dbcli/schemas/
|
|
|
27
46
|
dbcli query "SELECT * FROM users" # Execute SQL (auto LIMIT 1000)
|
|
28
47
|
```
|
|
29
48
|
|
|
49
|
+
If `.dbcli` does not yet exist, route through **Connection setup** below before
|
|
50
|
+
touching `schema` / `query`.
|
|
51
|
+
|
|
52
|
+
## Connection setup (helping the user wire up a database)
|
|
53
|
+
|
|
54
|
+
When the user asks "how do I connect to X?", "set up dbcli for our staging DB",
|
|
55
|
+
or `doctor` / `status` reports a missing or invalid config, follow this flow.
|
|
56
|
+
|
|
57
|
+
> **Default to guiding, not running.** `init` writes credentials to disk. Only
|
|
58
|
+
> execute it for the user with explicit permission and confirmed values.
|
|
59
|
+
> If a `.dbcli` already contains `{"$env": "..."}` references, **do not** rerun
|
|
60
|
+
> `init` to "fill them in" — the env-ref form is intentional for CI/multi-env.
|
|
61
|
+
|
|
62
|
+
### Decision tree (ask before writing)
|
|
63
|
+
|
|
64
|
+
1. **One DB or many environments?** One → v1 (single connection). Multiple
|
|
65
|
+
environments / tenants / replicas → v2 (`--conn-name <name>`, optionally
|
|
66
|
+
`--env-file <path>` per connection).
|
|
67
|
+
2. **Where do credentials live?**
|
|
68
|
+
- Already in a `.env` (`DATABASE_URL` or `DB_HOST` / `DB_PORT` / `DB_USER` /
|
|
69
|
+
`DB_PASSWORD` / `DB_NAME` | `DB_DATABASE`) → `init` parses it automatically.
|
|
70
|
+
- Need to keep secrets out of `.dbcli` (CI/CD, multi-env) → `--use-env-refs`
|
|
71
|
+
plus `--env-host` / `--env-port` / `--env-user` / `--env-password` / `--env-database`.
|
|
72
|
+
- Plain values are acceptable → pass `--host` / `--port` / `--user` /
|
|
73
|
+
`--password` / `--name` (and `--system`).
|
|
74
|
+
3. **What permission tier?** Default to the **lowest** that satisfies the task:
|
|
75
|
+
`query-only` → `read-write` → `data-admin` → `admin`. Set with `--permission`.
|
|
76
|
+
4. **Verify, never assume.** After init: `dbcli status` (system + permission +
|
|
77
|
+
blacklist summary, no creds) and `dbcli doctor --format json` (env, config
|
|
78
|
+
shape, connectivity, schema-cache age, Mongo SRV path).
|
|
79
|
+
|
|
80
|
+
### Per-engine essentials
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# PostgreSQL / MySQL / MariaDB (v1, plain values)
|
|
84
|
+
dbcli init --system postgresql --host localhost --port 5432 \
|
|
85
|
+
--user app --password '<secret>' --name appdb --permission query-only
|
|
86
|
+
|
|
87
|
+
# Reuse an existing .env (DATABASE_URL=postgresql://user:pw@host:5432/db)
|
|
88
|
+
dbcli init # parses .env in cwd
|
|
89
|
+
|
|
90
|
+
# MongoDB — full URI (Atlas / replica sets / authSource)
|
|
91
|
+
dbcli init --system mongodb \
|
|
92
|
+
--uri "mongodb+srv://user:pw@cluster.example.mongodb.net/mydb?authSource=admin"
|
|
93
|
+
# MongoDB — discrete params (no auth = omit --user/--password)
|
|
94
|
+
dbcli init --system mongodb --host localhost --port 27017 --name mydb
|
|
95
|
+
|
|
96
|
+
# Redis — `--name` is the LOGICAL DB INDEX ("0".."15"), not a database name
|
|
97
|
+
dbcli init --system redis --host localhost --port 6379 --password '<secret>' --name 0
|
|
98
|
+
|
|
99
|
+
# Elasticsearch — basic auth, Cloud ID, or API key
|
|
100
|
+
dbcli init --system elasticsearch --host localhost --port 9200 \
|
|
101
|
+
--user elastic --password '<secret>'
|
|
102
|
+
dbcli init --system elasticsearch \
|
|
103
|
+
--cloud-id "myCluster:dXMtZWFzdC0xLmF3..." --api-key "<base64>"
|
|
104
|
+
# Multi-node / custom CA / self-signed: edit `.dbcli` directly to add
|
|
105
|
+
# `nodes: [...]`, `protocol: https`, `caPath`, `rejectUnauthorized: false`.
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Multi-connection (v2)
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
dbcli init --conn-name staging --env-file .env.staging --permission query-only
|
|
112
|
+
dbcli init --conn-name prod --env-file .env.production --use-env-refs --skip-test
|
|
113
|
+
dbcli use --list # show all, * marks default
|
|
114
|
+
dbcli use prod # switch default
|
|
115
|
+
dbcli query --use staging "SELECT 1" # one-shot override
|
|
116
|
+
dbcli init --rename staging:stg # rename
|
|
117
|
+
dbcli init --remove stg # remove
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Per-connection schema cache lives at `.dbcli/schemas/<connection>/`. Run
|
|
121
|
+
`dbcli schema --use <name>` once per connection before `schema <table>` —
|
|
122
|
+
otherwise the cache may serve another connection's columns.
|
|
123
|
+
|
|
124
|
+
### env-refs (keep secrets out of `.dbcli`)
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
dbcli init --use-env-refs \
|
|
128
|
+
--env-host DB_HOST --env-port DB_PORT \
|
|
129
|
+
--env-user DB_USER --env-password DB_PASSWORD --env-database DB_NAME
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Stored as `{ "$env": "DB_HOST" }` etc. and resolved at runtime. Pair with
|
|
133
|
+
`--env-file <path>` (v2) when each connection has its own env file.
|
|
134
|
+
|
|
135
|
+
### Common gotchas
|
|
136
|
+
|
|
137
|
+
- **MongoDB `mongodb+srv://`** — `dbcli doctor` reports whether SRV resolves
|
|
138
|
+
natively or via the DoH fallback; useful when the runtime restricts DNS.
|
|
139
|
+
- **MySQL/Postgres password with `@` `:` `/`** — when using `DATABASE_URL`,
|
|
140
|
+
percent-encode (`@` → `%40`); discrete `--password` flags do not need encoding.
|
|
141
|
+
- **Redis `--name`** — accepts only the logical DB index string; non-numeric
|
|
142
|
+
values are rejected.
|
|
143
|
+
- **Elasticsearch TLS** — `caPath` and `rejectUnauthorized` are not exposed as
|
|
144
|
+
flags; edit `.dbcli` after `init` to add them.
|
|
145
|
+
- **Re-running `init`** — refuses to overwrite without `--force`; never use
|
|
146
|
+
`--force` to "fix" a config full of `{ "$env": "..." }` refs.
|
|
147
|
+
|
|
148
|
+
Full flags and edge cases: see [reference.md](reference.md) `init` section.
|
|
149
|
+
|
|
30
150
|
## Command overview
|
|
31
151
|
|
|
32
152
|
| Command | Min permission | Summary |
|
|
@@ -34,8 +154,8 @@ dbcli query "SELECT * FROM users" # Execute SQL (auto LIMIT 1000)
|
|
|
34
154
|
| `init` | n/a | Create `.dbcli` (v1 single or v2 multi via `--conn-name` / `--env-file`). **Usually run by the human** — do NOT re-run to strip `{"$env"}` references; that format is intentional. |
|
|
35
155
|
| `use` | n/a | Show/switch default named connection (v2 only). |
|
|
36
156
|
| `list` | query-only+ | Tables (SQL), collections (MongoDB), keys (Redis), or indices (Elasticsearch). |
|
|
37
|
-
| `schema` | query-only+ | SQL: per-table or full scan into `.dbcli/schemas
|
|
38
|
-
| `query` | query-only+ | SQL, Mongo JSON (`--collection`), Redis command, or ES DSL/Lucene (`--collection
|
|
157
|
+
| `schema` | query-only+ | SQL: per-table or full scan into `.dbcli/schemas/`. MongoDB: sampled. ES: flattened mapping. Redis: per-key only (type/TTL/size). |
|
|
158
|
+
| `query` | query-only+ | SQL, Mongo JSON (`--collection`), Redis command, or ES DSL/Lucene (`--collection`). |
|
|
39
159
|
| `insert` / `update` | read-write+ | SQL or MongoDB only. JSON `--data` / `--set`; `--where` required on `update`; `--dry-run` first. Redis writes go through `query`. |
|
|
40
160
|
| `delete` | data-admin+ | SQL or MongoDB only. `--where` required; `--dry-run` first. |
|
|
41
161
|
| `export` | query-only+ | SQL or MongoDB only. Query → CSV/JSON(L) file or stdout. |
|
|
@@ -43,11 +163,11 @@ dbcli query "SELECT * FROM users" # Execute SQL (auto LIMIT 1000)
|
|
|
43
163
|
| `check` | query-only+ | SQL only (best on MySQL/MariaDB). |
|
|
44
164
|
| `diff` | query-only+ | SQL only. Save/compare schema snapshots. |
|
|
45
165
|
| `status` | query-only+ | Safe JSON/text summary (no credentials). |
|
|
46
|
-
| `doctor` | n/a | Environment, config, connection, SRV diagnostics (Mongo), schema cache age
|
|
166
|
+
| `doctor` | n/a | Environment, config, connection, SRV diagnostics (Mongo), schema cache age. |
|
|
47
167
|
| `completion` | n/a | bash / zsh / fish scripts. |
|
|
48
168
|
| `upgrade` | n/a | Self-update from npm; 24h-cached version hints on every command. |
|
|
49
|
-
| `shell` | (same as query+) | Interactive REPL. SQL engines + MongoDB shell only
|
|
50
|
-
| `migrate` | admin | SQL only. **DDL; dry-run by default** — needs `--execute
|
|
169
|
+
| `shell` | (same as query+) | Interactive REPL. SQL engines + MongoDB shell only. |
|
|
170
|
+
| `migrate` | admin | SQL only. **DDL; dry-run by default** — needs `--execute`. |
|
|
51
171
|
|
|
52
172
|
`--use <name>` on any subcommand targets a v2 connection without changing the default.
|
|
53
173
|
|
|
@@ -71,29 +191,27 @@ dbcli query "SELECT * FROM users" # Execute SQL (auto LIMIT 1000)
|
|
|
71
191
|
- JSON filter object (`find`) or JSON array (`aggregate`); SQL is rejected. `--collection <name>` is required on `query`.
|
|
72
192
|
- **Supported:** `init`, `list`, `schema` (sampled), `query`, `insert`, `update`, `delete`, `export`, `status`, `use`, `shell`, `doctor`, `upgrade`, `completion`.
|
|
73
193
|
- **Not supported:** `q` (saved queries), `diff`, `migrate`, `check`.
|
|
74
|
-
- Schema is **sampled** (default 50 docs
|
|
75
|
-
- `--limit` applies on `find`/aggregate; query-only mode caps at 1000 unless `--no-limit`.
|
|
194
|
+
- Schema is **sampled** (default 50 docs); types are JS `typeof` strings.
|
|
76
195
|
- See reference.md MongoDB section for full syntax and examples.
|
|
77
196
|
|
|
78
197
|
## Redis
|
|
79
198
|
|
|
80
199
|
- Command-style execution; `query` runs a whitelisted Redis command (e.g. `GET`, `HSET`, `DEL`).
|
|
81
200
|
- **Supported:** `init`, `list` (keys via SCAN), `schema <key>` (type / TTL / size / sample), `query`, `status`, `use`, `doctor`, `upgrade`, `completion`.
|
|
82
|
-
- **Not supported:** `schema` full scan
|
|
201
|
+
- **Not supported:** `schema` full scan, `insert`, `update`, `delete`, `export`, `check`, `diff`, `migrate`, `q`.
|
|
83
202
|
Use `query "DEL <key>"` etc. for writes — they go through the same permission gate.
|
|
84
|
-
- Permission tiers map to commands: read commands → `query-only`; mutators (`SET`, `HSET`,
|
|
203
|
+
- Permission tiers map to commands: read commands → `query-only`; mutators (`SET`, `HSET`, ...) → `read-write`; `DEL` / `UNLINK` → `data-admin`.
|
|
85
204
|
- `database` field is the logical DB index (default `0`); `list` returns ≤ 100 000 keys via SCAN.
|
|
86
205
|
- See reference.md Redis section.
|
|
87
206
|
|
|
88
207
|
## Elasticsearch
|
|
89
208
|
|
|
90
|
-
- DSL (JSON body) or Lucene query string; `--collection <index>`
|
|
209
|
+
- DSL (JSON body) or Lucene query string; `--collection <index>` is required on `query`.
|
|
91
210
|
- **Supported:** `init`, `list` (indices with doc count), `schema [index]` (flattened mapping), `query`, `status`, `use`, `doctor`, `upgrade`, `completion`.
|
|
92
211
|
- **Not supported:** `insert`, `update`, `delete`, `export`, `check`, `diff`, `migrate`, `q`.
|
|
93
|
-
Writes are not exposed via dedicated subcommands yet — use
|
|
94
|
-
-
|
|
95
|
-
-
|
|
96
|
-
- Schema flattens nested fields (`a.b.c`) and surfaces `.fields` multi-fields (e.g. `text.keyword`).
|
|
212
|
+
Writes are not exposed via dedicated subcommands yet — use `query` if the cluster allows or external tools.
|
|
213
|
+
- Query-only mode caps at 1000 hits; `--no-limit` is bounded at 10 000.
|
|
214
|
+
- Schema flattens nested fields (`a.b.c`) and surfaces `.fields` multi-fields.
|
|
97
215
|
- See reference.md Elasticsearch section.
|
|
98
216
|
|
|
99
217
|
## Saved queries
|
package/assets/reference.md
CHANGED
|
@@ -498,6 +498,33 @@ dbcli migrate drop-enum status --execute --force
|
|
|
498
498
|
|
|
499
499
|
**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.
|
|
500
500
|
|
|
501
|
+
### skill tasks (Agent Task Packs)
|
|
502
|
+
|
|
503
|
+
```bash
|
|
504
|
+
dbcli skill tasks list # human table
|
|
505
|
+
dbcli skill tasks list --format json --tag diagnostics
|
|
506
|
+
dbcli skill tasks list --engine postgres --source builtin
|
|
507
|
+
dbcli skill tasks show diagnose-slow-query
|
|
508
|
+
dbcli skill tasks show diagnose-slow-query --format json
|
|
509
|
+
dbcli skill tasks plan diagnose-slow-query --param query="SELECT 1"
|
|
510
|
+
dbcli skill tasks plan diagnose-slow-query --param query="..." --format json
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
- **list filters:** `--tag <tag>`, `--engine <postgres|mysql|mongodb|redis|elasticsearch>`, `--source <builtin|shared|local>`, `--format <table|json>`.
|
|
514
|
+
- **show:** prints the full task definition (frontmatter + Agent Notes). Use `--format json` for an agent-friendly contract.
|
|
515
|
+
- **plan:** resolves `{{param}}` placeholders, validates required parameters, and emits a stable plan. Plans are **plan-only** in this version — dbcli will never execute the resulting commands automatically.
|
|
516
|
+
|
|
517
|
+
Task storage layers:
|
|
518
|
+
|
|
519
|
+
| Source | Path | Notes |
|
|
520
|
+
| --- | --- | --- |
|
|
521
|
+
| builtin | `assets/tasks/` | shipped with dbcli |
|
|
522
|
+
| shared | `.dbcli-shared/tasks/` | team-managed, version-controlled |
|
|
523
|
+
| local | `.dbcli/tasks/` | personal, gitignored |
|
|
524
|
+
|
|
525
|
+
Higher tiers override lower tiers by task name. Task name is derived from the
|
|
526
|
+
file path under the tier root (e.g. `diag/inspect.md` → `diag/inspect`).
|
|
527
|
+
|
|
501
528
|
## MongoDB Support
|
|
502
529
|
|
|
503
530
|
MongoDB connections use a JSON-based query model instead of SQL. Treat MongoDB support as a narrower document-database path, not as a full SQL feature equivalent.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# dbcli Agent Tasks (built-in)
|
|
2
|
+
|
|
3
|
+
Built-in task templates shipped with dbcli for AI agents.
|
|
4
|
+
|
|
5
|
+
## Resolution order
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
assets/tasks/ # builtin (lowest)
|
|
9
|
+
.dbcli-shared/tasks/ # shared, version-controlled
|
|
10
|
+
.dbcli/tasks/ # local, gitignored (highest)
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
A task with the same name in a higher tier overrides the lower one. Use this to
|
|
14
|
+
customize built-in workflows without modifying dbcli source.
|
|
15
|
+
|
|
16
|
+
## File format
|
|
17
|
+
|
|
18
|
+
Each task is a `.md` file with a YAML frontmatter block:
|
|
19
|
+
|
|
20
|
+
- `name` (required, must match the file path without `.md`)
|
|
21
|
+
- `description`, `tags`, `engines`
|
|
22
|
+
- `params` (map of name → `{ type, required?, default?, description?, enum? }`)
|
|
23
|
+
- `safety.mode` — only `plan-only` is supported in this version
|
|
24
|
+
- `steps[]` — each step is `{ type: command, command, reason?, risk? }`
|
|
25
|
+
|
|
26
|
+
Use block-style YAML (no inline `{ ... }` maps) — the built-in YAML parser does
|
|
27
|
+
not support inline maps.
|
|
28
|
+
|
|
29
|
+
The markdown body below the frontmatter is `Agent Notes` and is shown in
|
|
30
|
+
`dbcli skill tasks show <name>`.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: diagnose-slow-query
|
|
3
|
+
description: Diagnose slow query causes using safe read-only dbcli steps.
|
|
4
|
+
tags: [diagnostics, performance, readonly]
|
|
5
|
+
engines: [postgres, mysql]
|
|
6
|
+
params:
|
|
7
|
+
query:
|
|
8
|
+
type: string
|
|
9
|
+
required: true
|
|
10
|
+
description: The slow SQL query or query fingerprint to inspect.
|
|
11
|
+
safety:
|
|
12
|
+
mode: plan-only
|
|
13
|
+
requires:
|
|
14
|
+
- blacklist-list
|
|
15
|
+
- schema-check
|
|
16
|
+
steps:
|
|
17
|
+
- type: command
|
|
18
|
+
command: blacklist list
|
|
19
|
+
reason: Confirm sensitive tables and columns are protected before inspection.
|
|
20
|
+
risk: readonly
|
|
21
|
+
- type: command
|
|
22
|
+
command: plan "{{query}}"
|
|
23
|
+
reason: Analyze SQL risk without executing the query.
|
|
24
|
+
risk: readonly
|
|
25
|
+
- type: command
|
|
26
|
+
command: q @diag/long-running --format json
|
|
27
|
+
reason: Inspect active long-running queries through a saved diagnostic snippet.
|
|
28
|
+
risk: readonly
|
|
29
|
+
---
|
|
30
|
+
# Agent Notes
|
|
31
|
+
|
|
32
|
+
Use this task when the user reports a slow SQL query and wants safe diagnostic next steps.
|
|
33
|
+
Do not run write operations.
|