@carllee1983/dbcli 1.5.0 → 1.6.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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,36 @@ 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.6.0] - 2026-04-23
9
+
10
+ ### Added
11
+
12
+ - **Full MongoDB Support**: Extended all core operations to support MongoDB.
13
+ - Data operations: `query`, `insert`, `update`, `delete`.
14
+ - Safeguards: Integrated `blacklist` protection and `query-size-guard` for MongoDB commands.
15
+ - Discovery: Implemented schema inspection for MongoDB collections.
16
+ - Diagnostics: Added comprehensive MongoDB environment and connection diagnostics to `dbcli doctor`.
17
+ - **Improved AI Skill Installation**: `dbcli skill --install` now deploys both `SKILL.md` (high-level workflow) and `reference.md` (full command syntax and examples) to target platforms (Claude Code, Gemini CLI, Copilot, Cursor).
18
+ - **Security model enhancement**: `dbcli init` now defaults to a more secure storage model, placing sensitive connection details in `~/.config/dbcli/` rather than the local project workspace.
19
+
20
+ ### Changed
21
+
22
+ - **Documentation Refactor**: Updated and synchronized documentation (README, README.zh-TW, SKILL.md) to reflect full MongoDB capabilities and first-step walkthroughs.
23
+
24
+ ## [1.5.2] - 2026-04-22
25
+
26
+ ### Fixed
27
+
28
+ - **Doctor diagnostics for MongoDB SRV**: `dbcli doctor` now reports whether the current execution environment can resolve `mongodb+srv://` connections directly or only through the DNS-over-HTTPS fallback used by the MongoDB adapter.
29
+ - **Documentation**: Clarified the new MongoDB SRV environment diagnostic in README, README.zh-TW, and `assets/SKILL.md`.
30
+
31
+ ## [1.5.1] - 2026-04-22
32
+
33
+ ### Fixed
34
+
35
+ - **MongoDB SRV Connections**: `mongodb+srv://` URIs are now expanded and connected through the MongoDB adapter, and MongoDB operations consistently use the configured database.
36
+ - **MongoDB Documentation**: Clarified SRV URI support and configured-database behavior in README, README.zh-TW, and `assets/SKILL.md`.
37
+
8
38
  ## [1.5.0] - 2026-04-21
9
39
 
10
40
  ### Added
package/README.dev.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Development Guide
2
2
 
3
+ Scoped package: **`@carllee1983/dbcli`**. All `npm` / `npx` examples below use this name.
4
+
3
5
  ## npm Publishing Process
4
6
 
5
7
  ### Pre-Publication Checklist
@@ -9,115 +11,110 @@ Before running `npm publish`:
9
11
  1. **Verify build is clean:**
10
12
  ```bash
11
13
  bun run build
12
- ls -lh dist/cli.mjs # Should be 1.0-1.5MB
14
+ ls -lh dist/cli.mjs # expect a few MB (bundled CLI + dependencies)
13
15
  ```
14
16
 
15
- 2. **Verify test suite passes:**
17
+ 2. **Verify tests pass (pick one):**
16
18
  ```bash
17
- bun test --run unit/
19
+ # Fast path: unit + core only (matches CI-style smoke)
20
+ bun run test:unit
21
+
22
+ # Full suite (Bun test runner)
23
+ bun test
18
24
  ```
19
25
 
20
- For live database integration tests, use an explicit config path if needed:
26
+ For live database integration tests, set an explicit config if needed:
21
27
  ```bash
22
28
  LIVE_DB_CONFIG_PATH=/path/to/.dbcli bun test tests/integration/live-db.test.ts
23
29
  ```
24
30
 
25
31
  If no live config is available, `tests/integration/live-db.test.ts` skips
26
- instead of falling back to the default PostgreSQL configuration.
32
+ instead of falling back to the default PostgreSQL configuration. Use
33
+ `SKIP_INTEGRATION_TESTS=true` to skip integration tests when running a broad `bun test`.
27
34
 
28
35
  3. **Update version in package.json:**
29
36
  ```bash
30
- npm version minor # Updates package.json version + creates git tag
31
- # OR manually update "version" field in package.json
37
+ npm version minor # bumps version + creates git tag (in this repo)
38
+ # OR edit the "version" field in package.json by hand
32
39
  ```
33
40
 
34
41
  4. **Verify package contents (dry run):**
35
42
  ```bash
36
43
  npm pack --dry-run
37
- # Should list only: dist/*, README.md, CHANGELOG.md, package.json
38
44
  ```
45
+ Expect **`dist/`** (at least `cli.mjs`), **`assets/`** (e.g. `SKILL.md`, `reference.md` for `dbcli skill`), **`README.md`**, **`CHANGELOG.md`**, **`LICENSE`**, and **`package.json`**. There must be **no** `src/`, `tests/`, or `node_modules/`. The listing may also include other root `README*.md` files (npm can still pack them even when `files` is set); dev-only readmes are listed in **`.npmignore`** — re-check with dry-run if you add or remove docs.
39
46
 
40
47
  5. **Check package size:**
41
48
  ```bash
42
49
  npm pack
43
- ls -lh dbcli-*.tgz # Must be < 5MB
44
- rm dbcli-*.tgz # Cleanup
50
+ ls -lh carllee1983-dbcli-*.tgz # compressed tarball (typically well under 5MB)
51
+ rm carllee1983-dbcli-*.tgz # cleanup
45
52
  ```
46
53
 
47
54
  ### Publication
48
55
 
49
- The publication process is automated by npm hooks:
56
+ Publication uses the `prepublishOnly` script in `package.json`:
50
57
 
51
58
  ```bash
52
59
  npm publish
53
60
  ```
54
61
 
55
- This invokes (in order):
56
- 1. `prepublishOnly` hook: Runs `bun run build` → ensures fresh dist/cli.mjs
57
- 2. npm creates tarball with `files` whitelist → only intended files included
58
- 3. npm applies `.npmignore` rules → additional safety layer
59
- 4. npm publishes to registry
62
+ What runs (conceptually):
60
63
 
61
- **Note:** The build CANNOT be skipped. If you try to publish with a stale dist/cli.mjs, prepublishOnly will rebuild it.
64
+ 1. **`prepublishOnly`:** `bun run build` rebuilds `dist/cli.mjs` from `src/cli.ts` via `scripts/build.ts`.
65
+ 2. **Tarball** — paths from the **`files`** field in `package.json`, further filtered by **`.npmignore`**. (Some npm versions also merge in extra root `README*` files; use dry-run to see exactly what will ship.)
66
+ 3. **Registry** — with `"publishConfig": { "access": "public" }`, the scoped package is published as **public**.
67
+
68
+ A failed `bun run build` will fail the publish, so you should not ship a stale `dist/` from a previous local build.
62
69
 
63
70
  ### Verification (Post-Publication)
64
71
 
65
72
  After publishing:
66
73
 
67
- 1. **Test installation globally:**
74
+ 1. **Global install:**
68
75
  ```bash
69
- npm install -g dbcli
70
- which dbcli # Should show: /usr/local/bin/dbcli or similar
76
+ npm install -g @carllee1983/dbcli
77
+ which dbcli
71
78
  dbcli --version
72
79
  ```
73
80
 
74
- 2. **Test zero-install (npx):**
81
+ 2. **Zero-install (npx / bunx):**
75
82
  ```bash
76
- cd /tmp
77
- mkdir test-dbcli && cd test-dbcli
78
- npx dbcli --help
79
- npx dbcli --version
83
+ cd /tmp && mkdir -p test-dbcli && cd test-dbcli
84
+ npx @carllee1983/dbcli --help
85
+ npx @carllee1983/dbcli --version
86
+ # or: bunx @carllee1983/dbcli --help
80
87
  ```
81
88
 
82
- 3. **Test Windows installation (if available):**
83
- - On Windows machine: `npm install -g dbcli`
84
- - Verify: `dbcli --help` and `dbcli --version` work
85
- - npm creates .cmd wrapper automatically; no manual .cmd needed
89
+ 3. **Windows (if available):** `npm install -g @carllee1983/dbcli`, then `dbcli --help`. npm creates the `.cmd` stub for the `bin` entry; no hand-written `.cmd` in the repo.
86
90
 
87
91
  ### Rollback (if needed)
88
92
 
89
- If critical bug discovered after publishing:
93
+ If a bad release must be mitigated:
90
94
 
91
95
  ```bash
92
- npm unpublish dbcli@VERSION # Remove specific version
93
- # OR
94
- npm deprecate dbcli@VERSION "Critical bug; use VERSION-1" # Mark as deprecated
96
+ npm unpublish @carllee1983/dbcli@<VERSION>
97
+ # and/or
98
+ npm deprecate @carllee1983/dbcli@<VERSION> "Reason; use <SAFE_VERSION> instead"
95
99
  ```
96
100
 
97
- Then publish a patch fix.
101
+ Then ship a patch version with the fix. Prefer **deprecate** over **unpublish** when consumers may already depend on the version.
98
102
 
99
103
  ### Configuration Details
100
104
 
101
- - **files whitelist (package.json):** Restricts tarball to source only
102
- - Includes: dist/, README.md, CHANGELOG.md, LICENSE
103
- - Excludes: src/, tests/, node_modules/, .git/, docs/
104
- - **prepublishOnly hook:** Ensures build runs before pack
105
- - Prevents stale binaries from being published
106
- - Runs automatically; cannot be skipped with --no-scripts
107
- - **engines field:** Declares minimum Node >=18.0.0, Bun >=1.3.3
108
- - npm warns if consumer's environment is too old
109
- - **Cross-platform support:** Shebang `#!/usr/bin/env bun` works on all platforms
110
- - macOS/Linux: Direct shebang execution
111
- - Windows: npm creates .cmd wrapper automatically (no manual creation needed)
112
- - **Live integration tests:** `tests/integration/live-db.test.ts` reads `.dbcli/config.json`
113
- by default or `LIVE_DB_CONFIG_PATH` when you need to point at another config
114
- directory. Set `SKIP_INTEGRATION_TESTS=true` to skip all integration tests.
105
+ - **`files` (in `package.json`):** Publishes `dist/`, `assets/`, `README.md`, `CHANGELOG.md`, `LICENSE`. The `assets/` tree is required for `dbcli skill` to copy bundled `SKILL.md` / `reference.md` from the installed package.
106
+ - **`prepublishOnly`:** `bun run build` so `dist/cli.mjs` matches current source.
107
+ - **`engines`:** Declares `node >= 18.0.0` and `bun >= 1.3.3` so npm can warn on outdated runtimes.
108
+ - **Shebang:** `scripts/build.ts` prepends `#!/usr/bin/env bun` to `dist/cli.mjs`; the `bin` field in `package.json` points at that file.
109
+ - **Live DB tests:** `tests/integration/live-db.test.ts` uses project `.dbcli` by default or `LIVE_DB_CONFIG_PATH` when you point at another config directory. Set `SKIP_INTEGRATION_TESTS=true` to skip all integration tests.
110
+
111
+ For contributor workflow and release process, see **[CONTRIBUTING.md](./CONTRIBUTING.md)** and the main **[README.md](./README.md)** Development section.
115
112
 
116
113
  ### Troubleshooting
117
114
 
118
- | Issue | Solution |
119
- |-------|----------|
120
- | prepublishOnly fails (build error) | Fix TypeScript errors in src/, run `bun test --run unit/`, retry `npm publish` |
121
- | Package size > 5MB | Run `bun build --metafile=meta.json`, analyze output, remove unused dependencies |
122
- | Windows installation fails | Verify shebang is `#!/usr/bin/env bun` in dist/cli.mjs; npm's .cmd wrapper will be created automatically |
123
- | npx hangs or times out | Run `npm cache clean --force`, retry `npx dbcli` |
115
+ | Issue | What to do |
116
+ |-------|------------|
117
+ | `prepublishOnly` / build fails | Fix TypeScript or build errors, run `bun run test:unit`, then `bun run build` again. |
118
+ | Tarball unexpectedly large or bloated | Inspect the bundle: e.g. `bun build ./src/cli.ts --outfile=dist/cli.mjs --target=bun --metafile=meta.json` and review the metafile; trim dependencies or dev-only code paths. |
119
+ | Windows: `dbcli` not found after global install | Confirm PATH includes npms global `bin`; reinstall `npm i -g @carllee1983/dbcli`. |
120
+ | `npx` download slow or cache weird | `npm cache clean --force` and retry `npx @carllee1983/dbcli --version`. |
package/README.md CHANGED
@@ -6,6 +6,8 @@ A unified database CLI tool that enables AI agents (Claude Code, Gemini, Copilot
6
6
 
7
7
  **Core Value:** AI agents can safely and intelligently access project databases through a single, permission-controlled CLI tool with sensitive data protection.
8
8
 
9
+ > **Security update:** `dbcli init` now writes only a small project binding stub into `./.dbcli/config.json`. The full connection configuration is stored under `~/.config/dbcli/projects/<project-id>/config.json`, so sensitive settings do not live inside the project workspace by default.
10
+
9
11
  ## Internationalization (i18n)
10
12
 
11
13
  dbcli supports multiple languages via the `DBCLI_LANG` environment variable:
@@ -76,6 +78,9 @@ When `dbcli` is not on your `PATH`, use `bun run src/cli.ts <subcommand> ...` (s
76
78
  # Initialize project with database connection
77
79
  dbcli init
78
80
 
81
+ # Interactive shell (SQL + dbcli commands, tab completion)
82
+ dbcli shell
83
+
79
84
  # List available tables
80
85
  dbcli list
81
86
 
@@ -85,16 +90,38 @@ dbcli schema users
85
90
  # Query data
86
91
  dbcli query "SELECT * FROM users"
87
92
 
93
+ # Preview schema DDL (dry-run by default; add --execute to apply)
94
+ dbcli migrate create posts --column "id:serial:pk" --column "title:varchar(200):not-null"
95
+
88
96
  # Generate AI agent skill
89
97
  dbcli skill --install claude
90
98
  ```
91
99
 
100
+ ### MongoDB Atlas / SRV Connections
101
+
102
+ MongoDB connections are supported via both standard `mongodb://` URIs and Atlas-style `mongodb+srv://` URIs.
103
+
104
+ ```bash
105
+ # Atlas / SRV connection
106
+ dbcli init --system mongodb --conn-name atlas --uri "mongodb+srv://user:pass@cluster.example.mongodb.net/mydb"
107
+
108
+ # List collections in the configured MongoDB database
109
+ dbcli list --use atlas
110
+
111
+ # Query a collection with JSON filter or pipeline
112
+ dbcli query '{"status":"active"}' --collection users --use atlas
113
+ ```
114
+
115
+ For MongoDB, `list` and `query` operate on the database configured for the connection, and `query` requires `--collection <name>`.
116
+
92
117
  ---
93
118
 
94
119
  ## Multi-connection Support (v2)
95
120
 
96
121
  dbcli supports multiple named database connections within a single project. This is useful for managing different environments (development, staging, production) or multiple databases.
97
122
 
123
+ The project `.dbcli` directory now acts as a binding + cache layer. The actual connection config is stored in `~/.config/dbcli/projects/<project-id>/`, which keeps sensitive settings out of the workspace by default.
124
+
98
125
  ### Initializing Named Connections
99
126
 
100
127
  To create a named connection, use the `--conn-name` option during `init`. You can also specify a custom `.env` file for that connection.
@@ -153,13 +180,14 @@ dbcli init [OPTIONS]
153
180
  ```
154
181
 
155
182
  **Options (Basic):**
156
- - `--system <type>` — Database system: `postgresql`, `mysql`, `mariadb`
183
+ - `--system <type>` — Database system: `postgresql`, `mysql`, `mariadb`, `mongodb`
157
184
  - `--host <host>` — Database host
158
185
  - `--port <port>` — Database port
159
186
  - `--user <user>` — Database user
160
187
  - `--password <pass>` — Database password
161
188
  - `--name <db>` — Database name
162
189
  - `--permission <level>` — Permission level: `query-only`, `read-write`, `data-admin`, `admin`
190
+ - **MongoDB only:** `--uri <uri>` — full connection URI (`mongodb://…` or `mongodb+srv://…`); `--auth-source <db>` — auth database (default `admin` when using user/password)
163
191
  - `--use-env-refs` — Store environment variable references instead of actual values in config
164
192
  - `--skip-test` — Skip connection test
165
193
  - `--no-interactive` — Non-interactive mode (requires all options)
@@ -174,7 +202,7 @@ dbcli init [OPTIONS]
174
202
  **Behavior:**
175
203
  - Reads `.env` file if present (auto-fills DATABASE_URL, DB_* variables)
176
204
  - Prompts for missing values (host, port, user, password, database name, permission level)
177
- - Creates `.dbcli` JSON config file in project root
205
+ - Creates a project binding stub in `.dbcli/config.json` and stores the full config under `~/.config/dbcli/projects/<project-id>/`
178
206
  - Tests database connection before saving
179
207
 
180
208
  **Examples:**
@@ -224,6 +252,8 @@ dbcli use --list
224
252
 
225
253
  > **`--use-env-refs`:** When enabled, the config stores environment variable names (e.g., `{"$env": "DB_HOST"}`) instead of actual values. This avoids writing sensitive credentials into the config file, making it suitable for multi-environment deployments and CI/CD pipelines. At connection time, dbcli automatically reads the actual values from the referenced environment variables.
226
254
 
255
+ > **Storage model:** The project `.dbcli` directory is now a binding + cache layer, not the canonical home for secrets. If you inspect `./.dbcli/config.json`, you should only see the binding metadata; the full config lives in the home storage path shown above.
256
+
227
257
  ---
228
258
 
229
259
  #### `dbcli list`
@@ -472,8 +502,8 @@ dbcli skill --install cursor # Install to Cursor IDE
472
502
  ```
473
503
 
474
504
  **Behavior:**
475
- - Ships a canonical **`assets/SKILL.md`** in the package (single source of truth)
476
- - Prints that file to **stdout**, writes it with **`--output`**, or copies it to a **platform-specific path** with **`--install`**
505
+ - Ships canonical **`assets/SKILL.md`** + **`assets/reference.md`** (single source of truth: concise skill + long command reference)
506
+ - Prints the skill to **stdout**, writes it with **`--output`**, or copies it to a **platform-specific path** with **`--install`**
477
507
  - Actual database access is still enforced by your `.dbcli` permission level and blacklist — the skill text describes the full CLI surface
478
508
 
479
509
  **Examples:**
@@ -575,12 +605,8 @@ dbcli check users
575
605
  dbcli check orders --checks nulls,orphans --format table
576
606
  # Scan all tables
577
607
  dbcli check --all
578
- ```
579
608
 
580
- ---
581
-
582
- **Examples:**
583
- ```bash
609
+ # Table view + all-tables with selected checks
584
610
  dbcli check orders --format table
585
611
  dbcli check --all --checks nulls,duplicates --format json
586
612
  ```
@@ -637,6 +663,7 @@ dbcli doctor --format json # JSON output for AI agents
637
663
  - **Environment:** Bun version compatibility, dbcli version (compares with npm registry)
638
664
  - **Configuration:** Config file exists/valid, permission level, blacklist completeness
639
665
  - **Connection & Data:** Database connectivity, schema cache freshness (> 7 days warning), large table warnings (> 1M rows)
666
+ - **MongoDB SRV diagnostics:** For `mongodb+srv://` connections, `doctor` reports whether the current execution environment can resolve SRV records directly or only through the DNS-over-HTTPS fallback used by `dbcli`
640
667
 
641
668
  **Options:** `--format <text|json>`
642
669
  **Exit code:** 0 = all pass or warnings only, 1 = errors found
@@ -672,7 +699,7 @@ dbcli upgrade --check # Only check, do not upgrade
672
699
 
673
700
  **Background checks (stderr, skipped when `--quiet` or for `upgrade` / `skill`):**
674
701
  - **CLI version:** dbcli checks the npm registry (cached, about once per 24 hours). If a newer package exists, a one-line hint prints after normal command output.
675
- - **Installed skills:** If you used `dbcli skill --install <platform>`, dbcli compares each installed copy to the bundled `assets/SKILL.md`. When they differ, a short reminder lists which platforms to re-install (`dbcli skill --install <platform>`). Run `dbcli upgrade` to see the same skill status together with version info.
702
+ - **Installed skills:** If you used `dbcli skill --install <platform>`, dbcli compares each installed primary skill file (`SKILL.md` or `dbcli.mdc`) to the bundled `assets/SKILL.md`. When they differ, a short reminder lists which platforms to re-install (`dbcli skill --install <platform>`). Run `dbcli upgrade` to see the same skill status together with version info. Re-installing also refreshes `reference.md` next to the skill.
676
703
 
677
704
  #### `dbcli shell`
678
705
 
@@ -932,7 +959,7 @@ A Query-only agent cannot write to any table, and also cannot read blacklisted t
932
959
 
933
960
  ## AI Integration Guide
934
961
 
935
- dbcli ships AI-consumable skill documentation (`assets/SKILL.md`) and can copy it into your favorite AI development tool directories.
962
+ dbcli ships AI-consumable skill files (`assets/SKILL.md` and `assets/reference.md`) and can copy them into your favorite AI tool directories.
936
963
 
937
964
  ### Quick Start
938
965
 
@@ -964,7 +991,7 @@ After installation, the AI agent will have access to dbcli commands and can use
964
991
  4. Restart Claude Code extension
965
992
  5. In Claude Code chat, ask: "Show me the database schema" or "Query active users"
966
993
 
967
- **Skill location:** `~/.claude/skills/dbcli/SKILL.md`
994
+ **Skill location:** `~/.claude/skills/dbcli/` (SKILL.md + reference.md)
968
995
 
969
996
  ---
970
997
 
@@ -976,7 +1003,7 @@ After installation, the AI agent will have access to dbcli commands and can use
976
1003
  4. Start Gemini: `gemini start`
977
1004
  5. In chat, request: "Query the users table" or "Show database tables"
978
1005
 
979
- **Skill location:** `~/.gemini/skills/dbcli/SKILL.md`
1006
+ **Skill location:** `~/.gemini/skills/dbcli/` (SKILL.md + reference.md)
980
1007
 
981
1008
  ---
982
1009
 
@@ -988,7 +1015,7 @@ After installation, the AI agent will have access to dbcli commands and can use
988
1015
  4. Install Copilot CLI: `npm install -g @github-next/github-copilot-cli`
989
1016
  5. Use copilot preview: `copilot --help` and explore dbcli integration
990
1017
 
991
- **Skill location:** `.github/skills/dbcli/SKILL.md` under the **current working directory** when you run `dbcli skill --install copilot` (typically your project root).
1018
+ **Skill location:** `.github/skills/dbcli/` (SKILL.md + reference.md) when you run `dbcli skill --install copilot` in your project root.
992
1019
 
993
1020
  ---
994
1021
 
@@ -1000,7 +1027,7 @@ After installation, the AI agent will have access to dbcli commands and can use
1000
1027
  4. Open Cursor editor
1001
1028
  5. Use Cursor's Composer: "Insert a new user" or "Export user data"
1002
1029
 
1003
- **Skill location:** `.cursor/rules/dbcli.mdc` under the **current working directory** when you run `dbcli skill --install cursor` (project-level Cursor rule).
1030
+ **Skill location:** `.cursor/rules/dbcli.mdc` (summary + workflows) and `.cursor/skills/dbcli/reference.md` (full command flags and examples) under the **current working directory** when you run `dbcli skill --install cursor`.
1004
1031
 
1005
1032
  ---
1006
1033
 
@@ -1027,7 +1054,7 @@ dbcli skill --install claude
1027
1054
 
1028
1055
  ### Updating the skill after upgrades
1029
1056
 
1030
- The markdown installed by `dbcli skill` is the bundled **`assets/SKILL.md`**. It is **not** regenerated from your live config. When you **upgrade dbcli** or the bundled skill changes, re-copy it to each platform you use:
1057
+ `dbcli skill` copies the bundled **`assets/SKILL.md`** (and for `--install`, **`assets/reference.md`** next to it). It is **not** regenerated from your live config. When you **upgrade dbcli** or the bundled skill changes, re-copy it to each platform you use:
1031
1058
 
1032
1059
  ```bash
1033
1060
  dbcli skill --install claude
@@ -1035,7 +1062,7 @@ dbcli skill --install gemini
1035
1062
  # ... etc.
1036
1063
  ```
1037
1064
 
1038
- If an installed copy is older than the bundled file, dbcli prints a **stderr reminder** after most commands (see **`dbcli upgrade`**). Changing **permission level** or **blacklist** in `.dbcli` affects what the CLI allows at runtime — keep project context (e.g. `dbcli status`, `dbcli blacklist list`) in mind for agents even though the skill text lists the full command set.
1065
+ If an installed primary skill file is older than the bundled `assets/SKILL.md`, dbcli prints a **stderr reminder** after most commands (see **`dbcli upgrade`**). Changing **permission level** or **blacklist** in `.dbcli` affects what the CLI allows at runtime — keep project context (e.g. `dbcli status`, `dbcli blacklist list`) in mind for agents even though the skill text lists the full command set.
1039
1066
 
1040
1067
  ---
1041
1068
 
@@ -1212,6 +1239,7 @@ chmod +x dist/cli.mjs
1212
1239
  - **PostgreSQL:** 12.0+
1213
1240
  - **MySQL:** 8.0+
1214
1241
  - **MariaDB:** 10.5+
1242
+ - **MongoDB:** 4.4+ (query and collection listing via `mongodb://` and `mongodb+srv://`; see **MongoDB Atlas / SRV Connections** earlier in this document)
1215
1243
 
1216
1244
  ### Runtime
1217
1245
 
package/README.zh-TW.md CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
  **核心價值:** AI 代理可透過單一、具權限控管的 CLI 工具,在敏感資料保護下安全且智慧地存取專案資料庫。
8
8
 
9
+ > **安全性更新:** `dbcli init` 現在只會在 `./.dbcli/config.json` 寫入一個很小的專案綁定 stub。完整的連線設定會存放在 `~/.config/dbcli/projects/<project-id>/config.json`,因此敏感設定預設不會留在專案工作區內。
10
+
9
11
  ## 國際化(i18n)
10
12
 
11
13
  dbcli 透過環境變數 `DBCLI_LANG` 支援多語系:
@@ -88,13 +90,30 @@ dbcli schema users
88
90
  # 查詢資料
89
91
  dbcli query "SELECT * FROM users"
90
92
 
91
- # 修改結構 (DDL)
92
- dbcli migrate create posts --column "id:int:pk" "title:varchar(100)"
93
+ # 預覽結構變更(DDL,預設 dry-run;實際套用請加 --execute)
94
+ dbcli migrate create posts --column "id:serial:pk" --column "title:varchar(200):not-null"
93
95
 
94
96
  # 產生 AI 代理 skill
95
97
  dbcli skill --install claude
96
98
  ```
97
99
 
100
+ ### MongoDB Atlas / SRV 連線
101
+
102
+ MongoDB 連線同時支援標準 `mongodb://` URI 與 Atlas 常用的 `mongodb+srv://` URI。
103
+
104
+ ```bash
105
+ # Atlas / SRV 連線
106
+ dbcli init --system mongodb --conn-name atlas --uri "mongodb+srv://user:pass@cluster.example.mongodb.net/mydb"
107
+
108
+ # 列出該 MongoDB 連線中的集合
109
+ dbcli list --use atlas
110
+
111
+ # 以 JSON filter 或 pipeline 查詢某個集合
112
+ dbcli query '{"status":"active"}' --collection users --use atlas
113
+ ```
114
+
115
+ 對 MongoDB 而言,`list` 與 `query` 會使用該連線設定中的資料庫;`query` 也必須指定 `--collection <名稱>`。
116
+
98
117
  ---
99
118
 
100
119
  ## 多重連線支援 (v2)
@@ -129,7 +148,7 @@ dbcli init --conn-name staging --env-file .env.staging
129
148
  dbcli init --conn-name prod --env-file .env.production --use-env-refs
130
149
  ```
131
150
 
132
- 每一條具名連線可以設定不同的 **`--permission`**(例如正式環境只給 `query-only`)。同一專案下的 **schema 快取、黑名單** 等仍共用同一個 `.dbcli` 目錄;切換連線只改「連到哪一台資料庫」,不複製整份專案設定目錄。
151
+ 每一條具名連線可以設定不同的 **`--permission`**(例如正式環境只給 `query-only`)。現在專案內的 `.dbcli` 主要扮演**綁定 + 快取層**;真正的連線設定會存到使用者家目錄下的 `~/.config/dbcli/projects/<project-id>/`,避免敏感設定留在工作區。
133
152
 
134
153
  ### 管理連線(`use` / 移除 / 更名)
135
154
 
@@ -170,13 +189,14 @@ dbcli init [OPTIONS]
170
189
  ```
171
190
 
172
191
  **選項 (基本):**
173
- - `--system <type>` — 資料庫系統:`postgresql`、`mysql`、`mariadb`
192
+ - `--system <type>` — 資料庫系統:`postgresql`、`mysql`、`mariadb`、`mongodb`
174
193
  - `--host <host>` — 主機
175
194
  - `--port <port>` — 埠號
176
195
  - `--user <user>` — 使用者
177
196
  - `--password <pass>` — 密碼
178
197
  - `--name <db>` — 資料庫名稱
179
198
  - `--permission <level>` — 權限等級:`query-only`、`read-write`、`data-admin`、`admin`
199
+ - **僅 MongoDB:** `--uri <uri>` — 完整連線 URI(`mongodb://…` 或 `mongodb+srv://…`);`--auth-source <db>` — 驗證資料庫(使用帳密時預設為 `admin`)
180
200
  - `--use-env-refs` — 在設定檔中儲存環境變數名稱參照,而非實際值
181
201
  - `--skip-test` — 略過連線測試
182
202
  - `--no-interactive` — 非互動模式(須提供所有必要選項)
@@ -191,7 +211,7 @@ dbcli init [OPTIONS]
191
211
  **行為:**
192
212
  - 若存在 `.env` 會讀取(自動帶入 DATABASE_URL、DB_* 等變數)
193
213
  - 缺少的欄位會互動提示(主機、埠、使用者、密碼、資料庫名、權限等級)
194
- - 在專案根目錄建立 `.dbcli` JSON 設定檔
214
+ - `.dbcli/config.json` 建立專案綁定 stub,並將完整設定儲存在 `~/.config/dbcli/projects/<project-id>/`
195
215
  - 儲存前會測試資料庫連線
196
216
 
197
217
  **範例:**
@@ -241,6 +261,8 @@ dbcli use --list
241
261
 
242
262
  > **`--use-env-refs`:** 啟用後,設定檔會儲存環境變數名稱(例如 `{"$env": "DB_HOST"}`)而非實際值,避免將憑證寫入檔案,適合多環境與 CI/CD。連線時 dbcli 會自動從對應環境變數讀取實際值。
243
263
 
264
+ > **儲存模型:** 專案內的 `.dbcli` 現在是綁定 + 快取層,不再是秘密資訊的最終儲存地。若你查看 `./.dbcli/config.json`,應只會看到綁定 metadata;完整設定會放在前述 home storage 路徑中。
265
+
244
266
  ---
245
267
 
246
268
  #### `dbcli list`
@@ -489,8 +511,8 @@ dbcli skill --install cursor # 安裝至 Cursor IDE
489
511
  ```
490
512
 
491
513
  **行為:**
492
- - 套件內建唯一的 **`assets/SKILL.md`**(單一來源)
493
- - 可輸出至 **stdout**、以 **`--output`** 寫入檔案,或以 **`--install`** 複製到**各平台預設路徑**
514
+ - 內建 **`assets/SKILL.md`** 與 **`assets/reference.md`**(單一來源:精簡 skill+完整指令參考)
515
+ - 可輸出至 **stdout**、以 **`--output`** 寫入主要 skill 檔,或以 **`--install`** 複製到**各平台預設路徑**(`--install` 時一併寫入同目錄的 `reference.md`)
494
516
  - 實際能否存取資料庫仍由 `.dbcli` 的**權限等級**與**黑名單**決定;skill 文字描述的是完整 CLI 能力
495
517
 
496
518
  **範例:**
@@ -593,6 +615,10 @@ dbcli check orders --checks nulls,orphans --format table
593
615
 
594
616
  # 掃描所有資料表
595
617
  dbcli check --all
618
+
619
+ # 以表格顯示單表/掃全庫僅執行部分檢查
620
+ dbcli check orders --format table
621
+ dbcli check --all --checks nulls,duplicates --format json
596
622
  ```
597
623
 
598
624
  ---
@@ -647,6 +673,7 @@ dbcli doctor --format json # JSON 輸出(供 AI 代理)
647
673
  - **環境:** Bun 版本相容性、dbcli 版本(與 npm registry 比對)
648
674
  - **設定:** 設定檔是否存在/有效、權限等級、黑名單完整性
649
675
  - **連線與資料:** 資料庫連線、schema 快取新鮮度(超過 7 天警告)、大表警告(超過 100 萬列)
676
+ - **MongoDB SRV 偵測:** 對 `mongodb+srv://` 連線,`doctor` 會回報目前執行環境能否直接解析 SRV 記錄,或只能依賴 dbcli 內建的 DNS-over-HTTPS fallback
650
677
 
651
678
  **選項:** `--format <text|json>`
652
679
  **結束代碼:** 0 = 全部通過或僅警告,1 = 有錯誤
@@ -682,7 +709,7 @@ dbcli upgrade --check # 僅檢查,不安裝
682
709
 
683
710
  **背景檢查(stderr;使用 `--quiet` 或執行 `upgrade` / `skill` 時略過):**
684
711
  - **CLI 版本:** dbcli 會查詢 npm registry(有快取,約每 24 小時一次)。若有新版,一般指令結束後會印一行提示。
685
- - **已安裝的 skill:** 若曾執行 `dbcli skill --install <platform>`,dbcli 會比對各平台安裝檔與套件內的 `assets/SKILL.md`;若不一致,會列出需重新安裝的平台(`dbcli skill --install <platform>`)。執行 `dbcli upgrade` 時也會一併顯示 skill 狀態與版本資訊。
712
+ - **已安裝的 skill:** 若曾執行 `dbcli skill --install <platform>`,dbcli 會比對各平台**主 skill 檔**(`SKILL.md` 或 Cursor 的 `dbcli.mdc`)與套件內的 `assets/SKILL.md`;若不一致,會提示需重新安裝的平台(`dbcli skill --install <platform>`)。執行 `dbcli upgrade` 時也會一併顯示 skill 與版本資訊。重新安裝時也會一併更新技能旁的 `reference.md`。
686
713
 
687
714
  #### `dbcli shell`
688
715
 
@@ -938,7 +965,7 @@ Query-only 代理無法寫入任何表,也無法讀取黑名單表或欄位
938
965
 
939
966
  ## AI 整合指南
940
967
 
941
- dbcli 內建可供 AI 使用的 skill 文件(`assets/SKILL.md`),並可複製到常見 AI 開發工具的目錄。
968
+ dbcli 內建供 AI 使用的 skill 文件(`assets/SKILL.md` 與 `assets/reference.md`),並可複製到常見 AI 開發工具的目錄。
942
969
 
943
970
  ### 快速開始
944
971
 
@@ -970,7 +997,7 @@ dbcli skill --install cursor
970
997
  4. 重新啟動 Claude Code 擴充
971
998
  5. 在對話中詢問:「顯示資料庫 schema」或「查詢作用中使用者」
972
999
 
973
- **Skill 路徑:** `~/.claude/skills/dbcli/SKILL.md`
1000
+ **Skill 路徑:** `~/.claude/skills/dbcli/`(`SKILL.md` + `reference.md`)
974
1001
 
975
1002
  ---
976
1003
 
@@ -982,7 +1009,7 @@ dbcli skill --install cursor
982
1009
  4. 啟動 Gemini:`gemini start`
983
1010
  5. 在對話中請求:「查詢 users 表」或「列出資料庫資料表」
984
1011
 
985
- **Skill 路徑:** `~/.gemini/skills/dbcli/SKILL.md`
1012
+ **Skill 路徑:** `~/.gemini/skills/dbcli/`(`SKILL.md` + `reference.md`)
986
1013
 
987
1014
  ---
988
1015
 
@@ -994,7 +1021,7 @@ dbcli skill --install cursor
994
1021
  4. 安裝 Copilot CLI:`npm install -g @github-next/github-copilot-cli`
995
1022
  5. 使用 `copilot --help` 並探索與 dbcli 的整合
996
1023
 
997
- **Skill 路徑:** 執行 `dbcli skill --install copilot` 時,寫入**目前工作目錄**下的 `.github/skills/dbcli/SKILL.md`(通常為專案根目錄)。
1024
+ **Skill 路徑:** 執行 `dbcli skill --install copilot` 於專案根目錄時,寫入 **`.github/skills/dbcli/`**(`SKILL.md` + `reference.md`)。
998
1025
 
999
1026
  ---
1000
1027
 
@@ -1006,7 +1033,7 @@ dbcli skill --install cursor
1006
1033
  4. 開啟 Cursor
1007
1034
  5. 在 Composer 中:「新增一筆使用者」或「匯出使用者資料」
1008
1035
 
1009
- **Skill 路徑:** 執行 `dbcli skill --install cursor` 時,寫入**目前工作目錄**下的 `.cursor/rules/dbcli.mdc`(專案層級 Cursor 規則)。
1036
+ **Skill 路徑:** 在**目前工作目錄**執行 `dbcli skill --install cursor` 時,寫入 **`.cursor/rules/dbcli.mdc`**(摘要與工作流程)及 **`.cursor/skills/dbcli/reference.md`**(完整旗標與範例)。
1010
1037
 
1011
1038
  ---
1012
1039
 
@@ -1033,7 +1060,7 @@ dbcli skill --install claude
1033
1060
 
1034
1061
  ### 升級後更新 skill
1035
1062
 
1036
- `dbcli skill` 安裝的是套件內建的 **`assets/SKILL.md`**,**不會**依你目前的設定即時重新產生。當你**升級 dbcli** 或內建 skill 內容變更時,請對各平台重新安裝:
1063
+ `dbcli skill` 會複製套件內的 **`assets/SKILL.md`**;使用 **`--install`** 時另會複製 **`assets/reference.md`** 至技能旁。**不會**依你即時的 `.dbcli` 設定重新產生內文。當**升級 dbcli** 或內建 skill 變更時,請對所使用平台重新執行:
1037
1064
 
1038
1065
  ```bash
1039
1066
  dbcli skill --install claude
@@ -1041,7 +1068,7 @@ dbcli skill --install gemini
1041
1068
  # …依需求
1042
1069
  ```
1043
1070
 
1044
- 若本機安裝檔與套件內檔案不一致,多數指令結束後會在 **stderr** 提示(見 **`dbcli upgrade`**)。**權限**或**黑名單**變更會影響 CLI 實際允許的操作 — 建議搭配 `dbcli status`、`dbcli blacklist list` 等讓代理掌握專案現況;skill 文字仍可能列出完整指令集。
1071
+ 若本機**主 skill 檔**早於套件內 `assets/SKILL.md`,多數指令結束後會在 **stderr** 提醒(見 **`dbcli upgrade`**)。**權限**與**黑名單**變更會影響執行期允許的操作—建議搭配 `dbcli status`、`dbcli blacklist list` 讓代理掌握現況;skill 內文仍可能列出完整指令表。
1045
1072
 
1046
1073
  ---
1047
1074
 
@@ -1212,6 +1239,7 @@ chmod +x dist/cli.mjs
1212
1239
  - **PostgreSQL:** 12.0+
1213
1240
  - **MySQL:** 8.0+
1214
1241
  - **MariaDB:** 10.5+
1242
+ - **MongoDB:** 4.4+(`mongodb://` 與 `mongodb+srv://` 查詢與列集合;見前文 **MongoDB Atlas / SRV 連線**)
1215
1243
 
1216
1244
  ### 執行環境
1217
1245