@carllee1983/dbcli 1.9.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 CHANGED
@@ -5,6 +5,18 @@ 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
+
8
20
  ## [1.9.0] - 2026-05-06
9
21
 
10
22
  ### Added
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 working with databases, 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`.
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
@@ -46,6 +46,107 @@ dbcli schema # Scan all tables → .dbcli/schemas/
46
46
  dbcli query "SELECT * FROM users" # Execute SQL (auto LIMIT 1000)
47
47
  ```
48
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
+
49
150
  ## Command overview
50
151
 
51
152
  | Command | Min permission | Summary |