@carllee1983/dbcli 0.1.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 ADDED
@@ -0,0 +1,255 @@
1
+ # Changelog
2
+
3
+ All notable changes to dbcli are documented here.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.0] - 2026-03-26
9
+
10
+ ### Initial Release - AI-Ready Database CLI
11
+
12
+ dbcli v1.0.0 is a complete, production-ready CLI tool enabling AI agents and developers to safely interact with PostgreSQL, MySQL, and MariaDB databases through a permission-controlled interface.
13
+
14
+ **Key Achievement:** Single command-line tool bridging AI agents (Claude Code, Gemini, Copilot, Cursor) to database access without requiring multiple MPC integrations.
15
+
16
+ ---
17
+
18
+ ## Features by Phase
19
+
20
+ ### Phase 1: Project Scaffold
21
+
22
+ - **Foundation established:** CLI framework with Commander.js v13.0+
23
+ - **Build process:** Bun bundler with native TypeScript support (1.1MB binary, <100ms startup)
24
+ - **Test infrastructure:** Vitest with 80%+ coverage target
25
+ - **Cross-platform CI:** GitHub Actions matrix testing (ubuntu, macos, windows)
26
+ - **Code quality:** ESLint + Prettier configured
27
+
28
+ **Status:** ✅ Complete
29
+
30
+ ---
31
+
32
+ ### Phase 2: Init & Config
33
+
34
+ - **`dbcli init` command:** Interactive configuration with `.env` parsing
35
+ - **Hybrid initialization:** Auto-fills from .env, prompts only for missing values
36
+ - **Config management:** `.dbcli` JSON file with immutable copy-on-write semantics
37
+ - **Database support preparation:** Multi-database adapter layer foundation
38
+ - **RFC 3986 percent-decoding:** Handles special characters in DATABASE_URL passwords
39
+ - **Validation:** Zod schemas for type-safe configuration
40
+
41
+ **Status:** ✅ Complete
42
+
43
+ **Commands added:** `dbcli init`
44
+
45
+ ---
46
+
47
+ ### Phase 3: DB Connection
48
+
49
+ - **Multi-database support:** PostgreSQL, MySQL, MariaDB via unified adapter interface
50
+ - **Bun.sql integration:** Native SQL API (zero npm dependencies for drivers)
51
+ - **Connection testing:** Validates credentials before saving config
52
+ - **Error mapping:** Categorized error messages with troubleshooting hints (5 categories: ECONNREFUSED, ETIMEDOUT, AUTH_FAILED, ENOTFOUND, UNKNOWN)
53
+ - **Adapter pattern:** Clean abstraction enabling driver swaps without CLI changes
54
+
55
+ **Status:** ✅ Complete
56
+
57
+ **Technical:** DatabaseAdapter interface with PostgreSQLAdapter, MySQLAdapter implementations
58
+
59
+ ---
60
+
61
+ ### Phase 4: Permission Model
62
+
63
+ - **Three-tier permission system:** Query-only, Read-Write, Admin
64
+ - **SQL classification:** Character state machine for robust SQL analysis (handles comments, strings, CTEs, subqueries)
65
+ - **Permission enforcement:** Coarse-grained checks (no per-table/column fine-grained control in V1)
66
+ - **Default-deny approach:** Uncertain operations require Admin mode
67
+ - **Zero external dependencies:** Pure TypeScript string processing
68
+
69
+ **Status:** ✅ Complete
70
+
71
+ **Technical:** PermissionGuard module with SQL classifier (120+ unit tests)
72
+
73
+ ---
74
+
75
+ ### Phase 5: Schema Discovery
76
+
77
+ - **`dbcli list` command:** Display all tables with metadata
78
+ - **`dbcli schema [table]` command:** Show single table structure or scan entire database
79
+ - **Foreign key extraction:** PostgreSQL FK metadata from pg_stat_user_tables; MySQL from REFERENTIAL_CONSTRAINTS
80
+ - **Output formatters:** Table (ASCII) and JSON (AI-parseable)
81
+ - **Schema storage:** Complete metadata in `.dbcli` for offline AI reference
82
+ - **Column details:** Type, constraints, nullable, defaults, primary keys, foreign keys
83
+
84
+ **Status:** ✅ Complete
85
+
86
+ **Commands added:** `dbcli list`, `dbcli schema`
87
+
88
+ **Output formats:** table, json
89
+
90
+ ---
91
+
92
+ ### Phase 6: Query Operations
93
+
94
+ - **`dbcli query "SQL"` command:** Direct SQL execution with permission enforcement
95
+ - **Output formatters:** Table (human-readable), JSON (AI-parseable), CSV (RFC 4180 compliant)
96
+ - **Auto-limiting:** Query-only mode limits to 1000 rows (with user notification)
97
+ - **Helpful errors:** Levenshtein distance table suggestions for typos
98
+ - **Structured results:** Metadata including row count, execution time, columns
99
+ - **Permission guarding:** Blocks write operations in Query-only/Read-Write modes
100
+
101
+ **Status:** ✅ Complete
102
+
103
+ **Commands added:** `dbcli query`
104
+
105
+ **Output formats:** table, json, csv
106
+
107
+ **Libraries:** Levenshtein distance (custom 30-line implementation, no deps)
108
+
109
+ ---
110
+
111
+ ### Phase 7: Data Modification
112
+
113
+ - **`dbcli insert [table]` command:** Insert rows with parameterized queries
114
+ - **`dbcli update [table]` command:** Update existing rows with WHERE clause and SET columns
115
+ - **`dbcli delete [table]` command:** Delete rows (Admin-only for safety)
116
+ - **Parameterized SQL:** Prevents SQL injection across all modification commands
117
+ - **Confirmation flows:** --force flag for bypass; default prompts user
118
+ - **Dry-run mode:** `--dry-run` shows SQL without executing
119
+ - **Permission enforcement:** Insert/Update require Read-Write+; Delete requires Admin
120
+
121
+ **Status:** ✅ Complete
122
+
123
+ **Commands added:** `dbcli insert`, `dbcli update`, `dbcli delete`
124
+
125
+ **Safety features:** Confirmation prompts, --dry-run, --force override
126
+
127
+ ---
128
+
129
+ ### Phase 8: Schema Refresh & Export
130
+
131
+ - **`dbcli schema --refresh` command:** Detect and apply schema changes incrementally
132
+ - **`dbcli export "SQL"` command:** Export query results as JSON or CSV
133
+ - **SchemaDiffEngine:** Two-phase diff algorithm (table-level, column-level)
134
+ - **Type normalization:** Case-insensitive comparison for column types
135
+ - **Immutable merge:** Preserves metadata.createdAt, updates schemaLastUpdated
136
+ - **Streaming output:** CSV generated line-by-line; JSON buffered for validity
137
+ - **File output:** `--output file` support for both export and schema refresh
138
+
139
+ **Status:** ✅ Complete
140
+
141
+ **Commands enhanced:** `dbcli schema` (added --refresh), new `dbcli export`
142
+
143
+ **Output:** JSON (standard), CSV (RFC 4180)
144
+
145
+ ---
146
+
147
+ ### Phase 9: AI Integration
148
+
149
+ - **`dbcli skill` command:** Generate AI-consumable skill documentation
150
+ - **SkillGenerator class:** Runtime CLI introspection (collects commands dynamically)
151
+ - **Permission-based filtering:** Query-only hides insert/update/delete; Read-Write hides delete
152
+ - **SKILL.md format:** YAML frontmatter + markdown (compatible with Claude Code, Gemini, Copilot, Cursor)
153
+ - **Platform installation:** `dbcli skill --install {claude|gemini|copilot|cursor}`
154
+ - **Cross-platform paths:** Installs to correct location per platform (.claude/, .local/share/gemini/, etc.)
155
+ - **Dynamic updates:** Skill regenerates as CLI evolves; no manual documentation maintenance
156
+
157
+ **Status:** ✅ Complete
158
+
159
+ **Commands added:** `dbcli skill`
160
+
161
+ **Installation targets:** Claude Code, Gemini CLI, GitHub Copilot, Cursor IDE
162
+
163
+ ---
164
+
165
+ ### Phase 10: Polish & Distribution
166
+
167
+ - **npm publication:** `files` whitelist, `engines` constraints, `prepublishOnly` hook
168
+ - **Cross-platform validation:** Windows CI matrix with .cmd wrapper verification
169
+ - **Comprehensive documentation:** API reference, permission model, AI guide, troubleshooting
170
+ - **Performance benchmarking:** CLI startup < 200ms, query overhead < 50ms
171
+ - **Release readiness:** v1.0.0 quality gates met, all requirements satisfied
172
+
173
+ **Status:** ✅ Complete
174
+
175
+ ---
176
+
177
+ ## Known Limitations (V1)
178
+
179
+ - **Single database per project:** Multi-connection support deferred to V1.1
180
+ - **Coarse-grained permissions:** Per-table/column access control not in scope
181
+ - **No audit logging:** WHO/WHAT/WHEN tracking deferred to V1.1
182
+ - **Read-only schema:** No schema modification commands (ALTER TABLE, etc.) in V1
183
+ - **CLI-only:** No visual schema designer, REPL, or interactive shell in V1
184
+
185
+ ---
186
+
187
+ ## Compatibility
188
+
189
+ ### Databases
190
+
191
+ - PostgreSQL 12+
192
+ - MySQL 8.0+
193
+ - MariaDB 10.5+
194
+
195
+ ### Runtime
196
+
197
+ - Node.js 18.0.0+
198
+ - Bun 1.3.3+
199
+
200
+ ### Platforms
201
+
202
+ - macOS (Intel, Apple Silicon)
203
+ - Linux (x86_64)
204
+ - Windows 10+ (via npm .cmd wrapper)
205
+
206
+ ### AI Agents
207
+
208
+ - Claude Code (Anthropic)
209
+ - Gemini CLI (Google)
210
+ - GitHub Copilot
211
+ - Cursor IDE
212
+
213
+ ---
214
+
215
+ ## Installation
216
+
217
+ ```bash
218
+ npm install -g dbcli
219
+
220
+ # or use with npx (no installation)
221
+ npx dbcli init
222
+ ```
223
+
224
+ ---
225
+
226
+ ## Quick Start
227
+
228
+ ```bash
229
+ # Initialize project with database connection
230
+ dbcli init
231
+
232
+ # List tables
233
+ dbcli list
234
+
235
+ # Show table schema
236
+ dbcli schema users
237
+
238
+ # Query data
239
+ dbcli query "SELECT * FROM users"
240
+
241
+ # Generate AI agent skill
242
+ dbcli skill --install claude
243
+ ```
244
+
245
+ ---
246
+
247
+ ## Contributing
248
+
249
+ See [CONTRIBUTING.md](./CONTRIBUTING.md) for development setup and release process.
250
+
251
+ ---
252
+
253
+ ## License
254
+
255
+ See LICENSE file for details.
package/README.dev.md ADDED
@@ -0,0 +1,112 @@
1
+ # Development Guide
2
+
3
+ ## npm Publishing Process
4
+
5
+ ### Pre-Publication Checklist
6
+
7
+ Before running `npm publish`:
8
+
9
+ 1. **Verify build is clean:**
10
+ ```bash
11
+ bun run build
12
+ ls -lh dist/cli.mjs # Should be 1.0-1.5MB
13
+ ```
14
+
15
+ 2. **Verify test suite passes:**
16
+ ```bash
17
+ bun test --run unit/
18
+ ```
19
+
20
+ 3. **Update version in package.json:**
21
+ ```bash
22
+ npm version minor # Updates package.json version + creates git tag
23
+ # OR manually update "version" field in package.json
24
+ ```
25
+
26
+ 4. **Verify package contents (dry run):**
27
+ ```bash
28
+ npm pack --dry-run
29
+ # Should list only: dist/*, README.md, CHANGELOG.md, package.json
30
+ ```
31
+
32
+ 5. **Check package size:**
33
+ ```bash
34
+ npm pack
35
+ ls -lh dbcli-*.tgz # Must be < 5MB
36
+ rm dbcli-*.tgz # Cleanup
37
+ ```
38
+
39
+ ### Publication
40
+
41
+ The publication process is automated by npm hooks:
42
+
43
+ ```bash
44
+ npm publish
45
+ ```
46
+
47
+ This invokes (in order):
48
+ 1. `prepublishOnly` hook: Runs `bun run build` → ensures fresh dist/cli.mjs
49
+ 2. npm creates tarball with `files` whitelist → only intended files included
50
+ 3. npm applies `.npmignore` rules → additional safety layer
51
+ 4. npm publishes to registry
52
+
53
+ **Note:** The build CANNOT be skipped. If you try to publish with a stale dist/cli.mjs, prepublishOnly will rebuild it.
54
+
55
+ ### Verification (Post-Publication)
56
+
57
+ After publishing:
58
+
59
+ 1. **Test installation globally:**
60
+ ```bash
61
+ npm install -g dbcli
62
+ which dbcli # Should show: /usr/local/bin/dbcli or similar
63
+ dbcli --version
64
+ ```
65
+
66
+ 2. **Test zero-install (npx):**
67
+ ```bash
68
+ cd /tmp
69
+ mkdir test-dbcli && cd test-dbcli
70
+ npx dbcli --help
71
+ npx dbcli --version
72
+ ```
73
+
74
+ 3. **Test Windows installation (if available):**
75
+ - On Windows machine: `npm install -g dbcli`
76
+ - Verify: `dbcli --help` and `dbcli --version` work
77
+ - npm creates .cmd wrapper automatically; no manual .cmd needed
78
+
79
+ ### Rollback (if needed)
80
+
81
+ If critical bug discovered after publishing:
82
+
83
+ ```bash
84
+ npm unpublish dbcli@VERSION # Remove specific version
85
+ # OR
86
+ npm deprecate dbcli@VERSION "Critical bug; use VERSION-1" # Mark as deprecated
87
+ ```
88
+
89
+ Then publish a patch fix.
90
+
91
+ ### Configuration Details
92
+
93
+ - **files whitelist (package.json):** Restricts tarball to source only
94
+ - Includes: dist/, README.md, CHANGELOG.md, LICENSE
95
+ - Excludes: src/, tests/, node_modules/, .git/, docs/
96
+ - **prepublishOnly hook:** Ensures build runs before pack
97
+ - Prevents stale binaries from being published
98
+ - Runs automatically; cannot be skipped with --no-scripts
99
+ - **engines field:** Declares minimum Node >=18.0.0, Bun >=1.3.3
100
+ - npm warns if consumer's environment is too old
101
+ - **Cross-platform support:** Shebang `#!/usr/bin/env bun` works on all platforms
102
+ - macOS/Linux: Direct shebang execution
103
+ - Windows: npm creates .cmd wrapper automatically (no manual creation needed)
104
+
105
+ ### Troubleshooting
106
+
107
+ | Issue | Solution |
108
+ |-------|----------|
109
+ | prepublishOnly fails (build error) | Fix TypeScript errors in src/, run `bun test --run unit/`, retry `npm publish` |
110
+ | Package size > 5MB | Run `bun build --metafile=meta.json`, analyze output, remove unused dependencies |
111
+ | Windows installation fails | Verify shebang is `#!/usr/bin/env bun` in dist/cli.mjs; npm's .cmd wrapper will be created automatically |
112
+ | npx hangs or times out | Run `npm cache clean --force`, retry `npx dbcli` |