@carllee1983/dbcli 1.10.1 → 1.17.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 +125 -0
- package/README.md +75 -0
- package/README.zh-TW.md +20 -16
- package/assets/SKILL.md +62 -11
- package/assets/reference.md +296 -0
- package/assets/snippets/diag/blocking-queries.postgres.sql +17 -0
- package/assets/snippets/diag/cache-hit.mysql.sql +1 -0
- package/assets/snippets/diag/cache-hit.postgres.sql +1 -0
- package/assets/snippets/diag/client-list.redis.sql +8 -0
- package/assets/snippets/diag/cluster-info.redis.sql +8 -0
- package/assets/snippets/diag/connections.mysql.sql +1 -0
- package/assets/snippets/diag/connections.postgres.sql +1 -0
- package/assets/snippets/diag/db-size.mysql.sql +1 -0
- package/assets/snippets/diag/db-size.postgres.sql +1 -0
- package/assets/snippets/diag/es-cluster-health.elasticsearch.sql +1 -0
- package/assets/snippets/diag/hot-threads.elasticsearch.sql +9 -0
- package/assets/snippets/diag/index-stats.elasticsearch.sql +16 -0
- package/assets/snippets/diag/index-usage.mysql.sql +1 -0
- package/assets/snippets/diag/index-usage.postgres.sql +1 -0
- package/assets/snippets/diag/locks.mysql.sql +1 -0
- package/assets/snippets/diag/locks.postgres.sql +1 -0
- package/assets/snippets/diag/long-running.mysql.sql +1 -0
- package/assets/snippets/diag/long-running.postgres.sql +1 -0
- package/assets/snippets/diag/memory-usage.redis.sql +8 -0
- package/assets/snippets/diag/missing-indexes.mysql.sql +1 -0
- package/assets/snippets/diag/missing-indexes.postgres.sql +1 -0
- package/assets/snippets/diag/pending-tasks.elasticsearch.sql +9 -0
- package/assets/snippets/diag/redis-key-stats.redis.sql +1 -0
- package/assets/snippets/diag/slowlog.redis.sql +12 -0
- package/assets/snippets/diag/table-sizes.mysql.sql +1 -0
- package/assets/snippets/diag/table-sizes.postgres.sql +1 -0
- package/assets/snippets/diag/unassigned-shards.elasticsearch.sql +9 -0
- package/dist/cli.mjs +15193 -15944
- package/package.json +12 -14
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,131 @@ 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.17.0] - 2026-05-10
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `dbcli recover` top-level command. Without `--apply`, prints the auto-saved last envelope (Markdown by default, JSON with `--format json`); with `--apply`, executes the recovery plan under risk gating.
|
|
13
|
+
- `--apply` runs `tier=readonly` and `tier=dry-run` steps by default (tier is determined by the code-owned allowlist, not the envelope). Open the gate one tier with `--allow-write=readonly-cmd` (local-side writes) or `--allow-write=write-cmd` (database writes).
|
|
14
|
+
- `--from <path>` overrides the auto-saved envelope and accepts either a raw `RecoveryEnvelope` or a `SavedRecoveryEnvelope` wrapper.
|
|
15
|
+
- Auto-write `.dbcli/last-recovery.json` on every `--recovery` failure across `query`, `q`, `insert`, `update`, `delete`, `export`, `schema`, and `inspect`. Atomic write; SQL text and sensitive flag values are redacted in the saved `command` summary.
|
|
16
|
+
- New optional `GuideStep` fields: `interactive`, `dbWrite`, `placeholders` (additive — no `schemaVersion` bump).
|
|
17
|
+
- Per-`error.code` argv allowlist enforced before any child-process execution; hand-authored envelopes cannot escalate beyond the steps dbcli already knows how to run.
|
|
18
|
+
- Strict zod-based schema validation for envelopes from `--from <file>` and `.dbcli/last-recovery.json`. Missing `recovery`, missing `error.code`, malformed step shape, or wrong `schemaVersion` all surface as exit code 2 with a structured reason instead of crashing.
|
|
19
|
+
- Exit-code matrix for `dbcli recover --apply`: `0` ok, `1` failed, `2` envelope missing/malformed, `3` skipped-only.
|
|
20
|
+
- `RecoveryEnvelope.verify?: GuideStep` — optional read-only verifier appended by `classifyError()` per recovery code (additive, no `schemaVersion` bump).
|
|
21
|
+
- `dbcli recover --apply` now runs the verifier after the main plan when `finalStatus === 'ok'`. Output gains `verifyResult` and `verifyStatus` (`passed | failed | indeterminate`). `--no-verify` opts out.
|
|
22
|
+
- `--no-verify` flag on `dbcli recover --apply`.
|
|
23
|
+
- `BLACKLIST_COLUMN_WRITE` allowlist now permits `dbcli inspect --for-agent` (used as the verifier).
|
|
24
|
+
- `dbcli recover --next --after-step <n> --result <json|@file>` — multi-turn protocol that returns one deterministic step at a time, given the result of the previous step. Output is a `NextResult` envelope with `kind: 'step' | 'done'`, `cursor`, `totalSteps`, and (when stepping) the next `GuideStep`.
|
|
25
|
+
- `--next` is mutually exclusive with `--apply`; `--result` accepts inline JSON or `@<path>` (file ≤ 64 KB; `stdoutSummary`/`stderrSummary` ≤ 4 KB each).
|
|
26
|
+
- New `nextStepFromEnvelope` pure function and `StepResultSummary` / `NextResult` types in `src/core/recovery/next-step.ts` + `next-types.ts`. v1 walks the plan linearly; the function signature reserves `prevResult` for future per-code branching without breaking callers.
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- `dbcli recover --apply` defaults to `--format json` for machine-readability; `dbcli recover` (no `--apply`) keeps `--format markdown` as the default. Either default can be overridden explicitly.
|
|
31
|
+
- `dbcli init` and `dbcli init --force` recovery steps are now marked `interactive: true`; `--apply` skips them with `skipped:interactive`.
|
|
32
|
+
- Recovery steps that fall back to placeholder tokens (`<table>`, `<hint>`, `<snippet>`, `<name>`, `<value>`) now declare those tokens in `placeholders`; `--apply` skips them with `skipped:placeholder`.
|
|
33
|
+
- `dbcli use <connection>` recovery step is now `risk: 'write'` with `dbWrite: false` — selecting a connection rewrites the active-connection field in config.
|
|
34
|
+
|
|
35
|
+
### Security
|
|
36
|
+
|
|
37
|
+
- **Trust boundary on `--apply`**: envelope `risk`, `dbWrite`, and `interactive` fields are no longer authoritative for execution decisions. The gate derives the canonical execution tier (`readonly` / `dry-run` / `local-write` / `db-write` / `interactive`) from the per-`error.code` allowlist. A hand-crafted envelope claiming `risk: 'readonly'` for `dbcli delete users --where id=1` is still classified as `db-write` and skipped under the default tier. Falsified `interactive: false` on `dbcli init` is still skipped because the allowlist marks it `interactive`.
|
|
38
|
+
- `insert` / `update` / `delete` / `q` are tier `dry-run` only when argv contains `--dry-run`; otherwise they are tier `db-write`.
|
|
39
|
+
- Auto-saved envelope source now also rejects (exit 2) when `saved.cwd` no longer exists on disk, matching the existing `--from` saved-envelope behavior.
|
|
40
|
+
|
|
41
|
+
### Internal
|
|
42
|
+
|
|
43
|
+
- New modules under `src/core/recovery/`: `apply-types`, `apply-shell`, `apply-allowlist`, `apply-gate`, `apply-exec`, `apply`, `apply-render-json`, `apply-render-markdown`, `last-envelope`, `envelope-schema`.
|
|
44
|
+
- `apply-allowlist` exposes `classifyArgvForCode(argv, code)` returning `{ kind, tier }` so the gate can decide tier without trusting envelope hints. `isAllowedForCode` is preserved as a boolean wrapper.
|
|
45
|
+
- Test seam `__setExecutorForTests` allows unit tests to swap the child-process executor without spawning real processes.
|
|
46
|
+
|
|
47
|
+
## [1.16.0] - 2026-05-09
|
|
48
|
+
|
|
49
|
+
### Added
|
|
50
|
+
|
|
51
|
+
- `dbcli insert --recovery`, `dbcli update --recovery`, `dbcli delete --recovery`, `dbcli export --recovery`, `dbcli schema --recovery`, `dbcli inspect --recovery` — same opt-in envelope behavior as v1.15.0's `query --recovery` / `q --recovery`. On failure, a `RecoveryEnvelope` JSON is written to stdout, the human stderr message is suppressed, and the process exits non-zero. Without `--recovery`, the existing per-command error behavior is preserved byte-for-byte.
|
|
52
|
+
- `dbcli inspect --require-schema-cache` — flag that throws `SCHEMA_CACHE_MISSING` (recovery code) when the active SQL connection has no usable schema cache. Combine with `--recovery` to get a structured envelope. Together with the v1.15.0 `recovery` module this gives the `SCHEMA_CACHE_MISSING` classifier path end-to-end coverage from a real CLI surface.
|
|
53
|
+
- New `dry-run` recovery steps prepended to `BLACKLIST_COLUMN_WRITE` and `PERMISSION_DENIED` envelopes when the failing operation was a write (`INSERT` / `UPDATE` / `DELETE`). Agents now get a `dbcli <verb> <table> --dry-run` suggestion as the first step before the existing inventory / inspect / init steps.
|
|
54
|
+
|
|
55
|
+
### Notes
|
|
56
|
+
|
|
57
|
+
- `RecoveryEnvelope` shape, `RECOVERY_SCHEMA_VERSION`, and the 14 recovery codes are unchanged from v1.15.0. The new `RecoveryContext.writeOperation` field is optional and additive.
|
|
58
|
+
- Other commands (`q` was already covered in v1.15.0; `report`, `guide`, `recovery`, `doctor`, `migrate`, `init`, `use`, etc.) keep their existing error behavior.
|
|
59
|
+
- No new runtime dependencies. The classifier and step library remain pure functions.
|
|
60
|
+
|
|
61
|
+
## [1.15.0] - 2026-05-09
|
|
62
|
+
|
|
63
|
+
### Added
|
|
64
|
+
|
|
65
|
+
- `dbcli recovery` — machine-readable error envelope with deterministic recovery commands. Standalone lookup mode: `dbcli recovery --code <CODE>` synthesizes an envelope for any of 14 recovery codes (`CONFIG_MISSING`, `CONN_REFUSED`, `CONN_AUTH_FAILED`, `CONN_TIMEOUT`, `CONN_HOST_NOT_FOUND`, `CONN_UNKNOWN`, `PERMISSION_DENIED`, `BLACKLIST_TABLE`, `BLACKLIST_COLUMN_WRITE`, `SNIPPET_NOT_FOUND`, `SNIPPET_AMBIGUOUS`, `SNIPPET_PARAM_MISSING`, `SCHEMA_CACHE_MISSING`, `UNKNOWN`). Supports `--format json|markdown`, `--list`, `--brief`, `--for-agent`, plus placeholder bindings (`--hint`, `--snippet`, `--table`).
|
|
66
|
+
- `dbcli query --recovery` and `dbcli q --recovery` — opt-in flag that, on failure, emits a `RecoveryEnvelope` JSON to stdout (suppressing the usual human stderr message) and exits non-zero. Existing behavior without the flag is unchanged.
|
|
67
|
+
- `RecoveryEnvelope` schema (`schemaVersion: 1`) reuses the v1.14.0 `GuideStep` shape and is the first surface to emit `risk: 'dry-run'` and `risk: 'write'` recovery steps.
|
|
68
|
+
|
|
69
|
+
### Notes
|
|
70
|
+
|
|
71
|
+
- v1.15.0 wires `--recovery` into `query` and `q` only. Other commands (`insert`, `update`, `delete`, `export`) preserve their current error behavior; broader integration is planned for v1.16+.
|
|
72
|
+
- Recovery is reactive (responds to a thrown error) while `dbcli guide` is proactive (chooses next steps before any failure). They share the `GuideStep` contract via `src/core/guide/types.ts`.
|
|
73
|
+
- No new runtime dependencies. Classifier and step library are pure functions.
|
|
74
|
+
|
|
75
|
+
## [1.14.0] - 2026-05-09
|
|
76
|
+
|
|
77
|
+
### Added
|
|
78
|
+
|
|
79
|
+
- `dbcli guide <goal>` — deterministic next-command planner for a fixed list of database goals (`slow-query`, `capacity`, `health`, `index-usage`, `permissions`, `schema-overview`). Reuses `dbcli inspect` context cache-first; pass `--probe` to refresh via a live probe. Each step carries `risk: 'readonly'` (forward-compatible with v1.15.0 recovery) plus `rationale` and `expects` (trimmed by `--brief` / `--for-agent`). Supports `--format json|markdown`, `--list`.
|
|
80
|
+
- Goal-list view: `dbcli guide --list` returns all available goals with one-line descriptions.
|
|
81
|
+
|
|
82
|
+
### Notes
|
|
83
|
+
|
|
84
|
+
- Guide does not execute any commands; it only plans them. All v1.14.0 plans are read-only by construction.
|
|
85
|
+
- MongoDB connections still produce a useful plan (anchor + `queries suggest` + `doctor`) even though no built-in mongo diagnostic snippets exist yet.
|
|
86
|
+
- Coexists with `dbcli skill tasks plan` (template-driven). Guide is taxonomy-driven from the static goal map.
|
|
87
|
+
|
|
88
|
+
## [1.13.0] - 2026-05-09
|
|
89
|
+
|
|
90
|
+
### Added
|
|
91
|
+
|
|
92
|
+
- `dbcli report` — Markdown / JSON diagnostic report built on top of v1.12.0 inspect collectors. Reuses connection / permission / blacklist / snippet inventory context; runs curated read-only built-in `@diag/*` snippets grouped into `health` / `capacity` / `perf` sections; per-snippet timeout (default 3000 ms) and per-evidence row cap (default 50). Supports `--format json|markdown`, `--section <list>`, `--brief`, `--for-agent`, `--no-connect`.
|
|
93
|
+
|
|
94
|
+
### Notes
|
|
95
|
+
|
|
96
|
+
- MongoDB connections emit a context-only report (no built-in mongo snippets in v1.13.0).
|
|
97
|
+
- No new built-in snippets in this release; report uses the v1.11 `@diag/*` inventory.
|
|
98
|
+
|
|
99
|
+
## [1.12.0] - 2026-05-08
|
|
100
|
+
|
|
101
|
+
### Added
|
|
102
|
+
|
|
103
|
+
- `dbcli inspect` — read-only context snapshot for AI agents (`--format json|markdown`, `--brief`, `--for-agent`, `--no-connect`, `--probe-timeout`).
|
|
104
|
+
- `src/core/inspect/` collector layer (connection, permission, blacklist, objects, schema-cache, snippets, version, suggested commands) reused via the orchestrator.
|
|
105
|
+
- `release:check` script — sequences `bun audit`, format check, typecheck, lint, tests, build, and dist smoke.
|
|
106
|
+
|
|
107
|
+
### Changed
|
|
108
|
+
|
|
109
|
+
- `assets/SKILL.md` agent workflow now starts with `dbcli inspect --for-agent`.
|
|
110
|
+
- `README.md` quick-start documents the agent first-look command.
|
|
111
|
+
|
|
112
|
+
### Notes
|
|
113
|
+
|
|
114
|
+
- Snapshot output is locked at `schemaVersion: 1`. Non-SQL engines emit `objects` and `schemaCache` as `unavailable: true` until later milestones.
|
|
115
|
+
- No new runtime dependencies.
|
|
116
|
+
|
|
117
|
+
## [1.11.0] - 2026-05-08
|
|
118
|
+
|
|
119
|
+
### Added
|
|
120
|
+
|
|
121
|
+
- `dbcli queries search <keywords>` — fuzzy keyword search across saved queries.
|
|
122
|
+
- `dbcli queries suggest <intent>` — intent-prefix suggestion.
|
|
123
|
+
- Optional `intent` frontmatter field on snippets.
|
|
124
|
+
- 9 new diagnostic snippets: ES x4 (hot-threads, index-stats, unassigned-shards, pending-tasks); Redis x4 (slowlog, client-list, memory-usage, cluster-info); SQL x1 (blocking-queries.postgres).
|
|
125
|
+
- "When you don't know which query to run" section in SKILL.md.
|
|
126
|
+
|
|
127
|
+
### Changed
|
|
128
|
+
|
|
129
|
+
- All 18 existing built-in diagnostic snippets backfilled with `intent`.
|
|
130
|
+
- `foldVariants` extracted from `src/commands/queries.ts` to `src/core/saved-queries/fold.ts`.
|
|
131
|
+
- Redis read-only allowlist gained `CLIENT`, `INFO`, `CLUSTER`, `SLOWLOG` for diagnostic snippets.
|
|
132
|
+
|
|
8
133
|
## [1.10.1] - 2026-05-08
|
|
9
134
|
|
|
10
135
|
### Fixed
|
package/README.md
CHANGED
|
@@ -97,6 +97,81 @@ dbcli migrate create posts --column "id:serial:pk" --column "title:varchar(200):
|
|
|
97
97
|
dbcli skill --install claude
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
+
### Agent first-look
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
dbcli inspect --for-agent
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
A single read-only command that returns a bounded JSON snapshot of the current
|
|
107
|
+
connection, permission level, blacklist size, schema cache freshness, available
|
|
108
|
+
saved-query intents, and the safest next commands to run. No host, no port, no
|
|
109
|
+
credentials — safe to log or pipe to an LLM.
|
|
110
|
+
|
|
111
|
+
### Diagnostic report
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
dbcli report --format json
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Builds on `inspect` to also run curated read-only built-in `@diag/*` snippets
|
|
118
|
+
grouped into `health` / `capacity` / `perf` sections. Bounded by per-snippet
|
|
119
|
+
timeout and per-evidence row cap. Use `--format markdown` for human reading,
|
|
120
|
+
`--section health,capacity` to scope, or `--for-agent` for compact JSON.
|
|
121
|
+
|
|
122
|
+
### Guide
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
dbcli guide slow-query --format json
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Deterministic next-command planner. Pick a goal (`slow-query`, `capacity`,
|
|
129
|
+
`health`, `index-usage`, `permissions`, `schema-overview`) and `dbcli guide`
|
|
130
|
+
emits an ordered plan that combines `dbcli inspect`, engine-appropriate
|
|
131
|
+
`@diag/*` snippets, and `dbcli queries suggest` / `dbcli doctor` follow-ups.
|
|
132
|
+
The planner is cache-first (no network); add `--probe` to refresh the
|
|
133
|
+
underlying inspect context. Use `--list` to see all goals,
|
|
134
|
+
`--format markdown` for human reading, or `--for-agent` for compact JSON.
|
|
135
|
+
|
|
136
|
+
### Recovery & Guided Remediation
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# Lookup recovery commands for a code
|
|
140
|
+
dbcli recovery --code CONN_REFUSED --format json
|
|
141
|
+
|
|
142
|
+
# Execute a failing command with recovery opt-in
|
|
143
|
+
dbcli query "SELECT 1" --recovery
|
|
144
|
+
|
|
145
|
+
# (v1.17.0+) Inspect or apply the last saved recovery plan
|
|
146
|
+
dbcli recover # View last plan (Markdown)
|
|
147
|
+
dbcli recover --apply # Execute safe steps (readonly/dry-run)
|
|
148
|
+
dbcli recover --apply --allow-write=readonly-cmd # Allow local writes
|
|
149
|
+
dbcli recover --apply --allow-write=write-cmd # Allow database writes
|
|
150
|
+
|
|
151
|
+
# (v1.17.0+) Multi-turn recovery (for AI agents)
|
|
152
|
+
dbcli recover --next --after-step 1 --result '{"status":"ok"}'
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Machine-readable error envelope with guided remediation. As of v1.16.0 every
|
|
156
|
+
first-party command accepts the `--recovery` flag. In v1.17.0, the `recover`
|
|
157
|
+
command was added to automate the execution of these plans.
|
|
158
|
+
|
|
159
|
+
- **Risk Gating:** `--apply` is safe-by-default, running only `readonly` and
|
|
160
|
+
`dry-run` steps. Elevated tiers require `--allow-write`.
|
|
161
|
+
- **Verification:** After a successful `--apply`, dbcli automatically runs a
|
|
162
|
+
verification step to confirm the fix actually worked.
|
|
163
|
+
- **Multi-turn Protocol:** The `--next` flag allows agents to advance recovery
|
|
164
|
+
one step at a time, providing the result of the previous step to enable
|
|
165
|
+
deterministic branching.
|
|
166
|
+
|
|
167
|
+
`dbcli inspect --require-schema-cache` throws `SCHEMA_CACHE_MISSING` when the
|
|
168
|
+
active SQL connection has no usable schema cache; combine with `--recovery`
|
|
169
|
+
to receive the structured envelope.
|
|
170
|
+
|
|
171
|
+
For write commands (`insert` / `update` / `delete`), `BLACKLIST_COLUMN_WRITE`
|
|
172
|
+
and `PERMISSION_DENIED` envelopes lead with a `risk: 'dry-run'` step
|
|
173
|
+
that suggests previewing the SQL with `--dry-run` before re-attempting.
|
|
174
|
+
|
|
100
175
|
### MongoDB Atlas / SRV Connections
|
|
101
176
|
|
|
102
177
|
MongoDB connections are supported via both standard `mongodb://` URIs and Atlas-style `mongodb+srv://` URIs.
|
package/README.zh-TW.md
CHANGED
|
@@ -72,30 +72,34 @@ bun run src/cli.ts -- --help
|
|
|
72
72
|
|
|
73
73
|
若 `dbcli` 未在 `PATH` 中,請使用 `bun run src/cli.ts <子指令> ...`(與 `bun run dev -- <子指令> ...` 相同)。
|
|
74
74
|
|
|
75
|
-
###
|
|
75
|
+
### 復原與引導式修復 (Recovery & Guided Remediation)
|
|
76
76
|
|
|
77
77
|
```bash
|
|
78
|
-
#
|
|
79
|
-
dbcli
|
|
78
|
+
# 查詢特定代碼的復原指令
|
|
79
|
+
dbcli recovery --code CONN_REFUSED --format json
|
|
80
80
|
|
|
81
|
-
#
|
|
82
|
-
dbcli
|
|
81
|
+
# 執行指令並在失敗時啟用復原信封
|
|
82
|
+
dbcli query "SELECT 1" --recovery
|
|
83
83
|
|
|
84
|
-
#
|
|
85
|
-
dbcli
|
|
84
|
+
# (v1.17.0+) 檢視或執行最後一次儲存的復原計畫
|
|
85
|
+
dbcli recover # 檢視最後一個計畫 (Markdown)
|
|
86
|
+
dbcli recover --apply # 執行安全步驟 (readonly/dry-run)
|
|
87
|
+
dbcli recover --apply --allow-write=readonly-cmd # 允許本機端寫入
|
|
88
|
+
dbcli recover --apply --allow-write=write-cmd # 允許資料庫端寫入
|
|
86
89
|
|
|
87
|
-
#
|
|
88
|
-
dbcli
|
|
90
|
+
# (v1.17.0+) 多輪對話復原協定 (供 AI 代理使用)
|
|
91
|
+
dbcli recover --next --after-step 1 --result '{"status":"ok"}'
|
|
92
|
+
```
|
|
89
93
|
|
|
90
|
-
|
|
91
|
-
dbcli query "SELECT * FROM users"
|
|
94
|
+
具備引導修復能力的機器可讀錯誤信封。自 v1.16.0 起,所有核心指令皆支援 `--recovery` 旗標。在 v1.17.0 中,新增了 `recover` 指令來自動化執行這些計畫。
|
|
92
95
|
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
- **風險門控 (Risk Gating):** `--apply` 預設為安全優先,僅執行 `readonly` 與 `dry-run` 步驟。較高風險的操作需透過 `--allow-write` 授權。
|
|
97
|
+
- **自動驗證:** 當 `--apply` 執行成功後,dbcli 會自動執行一個驗證步驟 (verify) 以確認修復是否生效。
|
|
98
|
+
- **多輪對話協定:** `--next` 旗標允許 Agent 逐步執行復原,並提供上一步的執行結果,以實現決定性的分支邏輯。
|
|
95
99
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
`dbcli inspect --require-schema-cache` 會在 SQL 連線缺少可用快取時拋出 `SCHEMA_CACHE_MISSING`;配合 `--recovery` 可取得結構化信封。
|
|
101
|
+
|
|
102
|
+
針對寫入指令 (`insert` / `update` / `delete`),`BLACKLIST_COLUMN_WRITE` 與 `PERMISSION_DENIED` 信封會優先提供 `risk: 'dry-run'` 步驟,建議在重試前先以 `--dry-run` 預覽 SQL。
|
|
99
103
|
|
|
100
104
|
### MongoDB Atlas / SRV 連線
|
|
101
105
|
|
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 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,
|
|
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, protecting sensitive data from AI access, or performing automated recovery and guided remediation after command failures. For exhaustive flags and examples, read the sibling `reference.md`.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# dbcli
|
|
@@ -9,11 +9,44 @@ Database CLI for AI agents with permission-based access control.
|
|
|
9
9
|
|
|
10
10
|
## AI agent workflow (follow in order)
|
|
11
11
|
|
|
12
|
-
1. `dbcli
|
|
13
|
-
2. `dbcli
|
|
14
|
-
3. `dbcli
|
|
15
|
-
4.
|
|
16
|
-
|
|
12
|
+
1. `dbcli inspect --for-agent` — bounded snapshot: connection, permission, blacklist, objects, snippets, suggested next commands.
|
|
13
|
+
2. `dbcli report --format json` — diagnostic report (health/capacity/perf) using built-in snippets.
|
|
14
|
+
3. `dbcli guide <goal> --format json` — deterministic next-command plan for a fixed goal (`slow-query`, `capacity`, `health`, `index-usage`, `permissions`, `schema-overview`). Use `dbcli guide --list` to see goals.
|
|
15
|
+
4. `dbcli recovery --code <CODE>` — look up structured recovery commands for a known error code (e.g. `CONN_REFUSED`, `PERMISSION_DENIED`, `SNIPPET_NOT_FOUND`). Pass `--recovery` to `dbcli query` / `dbcli q` to have failures emit a `RecoveryEnvelope` directly. In v1.16.0 the `--recovery` flag is also accepted by `dbcli insert`, `dbcli update`, `dbcli delete`, `dbcli export`, `dbcli schema`, and `dbcli inspect` (which also gained `--require-schema-cache` for the `SCHEMA_CACHE_MISSING` path).
|
|
16
|
+
- **v1.17.0** `dbcli recover` reads the auto-saved envelope (`.dbcli/last-recovery.json`) written by any prior `--recovery` failure. Inspect it (Markdown by default) or pass `--apply` to execute the saved plan under risk gating.
|
|
17
|
+
- **v1.17.0** `dbcli recover --apply` runs `risk=readonly` and `risk=dry-run` steps by default. Open the gate one tier with `--allow-write=readonly-cmd` (run local-side writes such as `blacklist remove`) or `--allow-write=write-cmd` (also run steps that mutate the connected database). Pass `--from <file>` to read an explicit envelope instead of the auto-saved one. Use `--format json` for an aggregated machine-readable result.
|
|
18
|
+
- Exit codes: `0` ok, `1` step failed, `2` envelope missing/malformed, `3` every step skipped (open `--allow-write` or fix interactive/placeholder).
|
|
19
|
+
- GuideStep optional fields agents should respect:
|
|
20
|
+
- `interactive: true` — step requires a TTY (`dbcli init` family). `dbcli recover --apply` skips with `skipped:interactive`.
|
|
21
|
+
- `dbWrite: true` — step mutates the connected database. Gates the highest risk tier; reserved for future write-side recovery steps.
|
|
22
|
+
- `placeholders: ['<token>', ...]` — agent must replace these tokens before `--apply` will execute. Skipped with `skipped:placeholder`.
|
|
23
|
+
- **v1.17.0 P4 Verification.** After `--apply` finishes the main plan, dbcli runs **one extra read-only step** (`envelope.verify`) to probe whether the original failure is gone. The output gains `verifyResult` (the executed step) and `verifyStatus`:
|
|
24
|
+
- `passed` — verifier exited 0 and (where applicable) the expected JSON shape was found.
|
|
25
|
+
- `failed` — verifier exited non-zero or timed out.
|
|
26
|
+
- `indeterminate` — verifier exited 0 but the heuristic could not confirm the fix (JSON parse failure, missing field, gate skip).
|
|
27
|
+
Verify is **only run when** `finalStatus === 'ok'`. Pass `--no-verify` to skip it. Heuristic is intentionally cheap; agents should still re-run their own check against the original failing operation when correctness matters.
|
|
28
|
+
- **v1.17.0 P2 Multi-turn `--next`.** When `--apply` is too coarse — interactive blocks it, the plan needs per-step inspection, or the agent wants to drive recovery with its own tools — execute steps one at a time and ask dbcli for the next:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# The agent reads step 1 from the envelope, runs it, then asks dbcli for step 2:
|
|
32
|
+
dbcli recover --next --after-step 1 --result '{"status":"ok","exitCode":0}'
|
|
33
|
+
# Returns a NextResult envelope:
|
|
34
|
+
# {
|
|
35
|
+
# "schemaVersion": 1,
|
|
36
|
+
# "kind": "step",
|
|
37
|
+
# "errorCode": "BLACKLIST_TABLE",
|
|
38
|
+
# "cursor": 2,
|
|
39
|
+
# "totalSteps": 3,
|
|
40
|
+
# "step": { "order": 2, "command": "dbcli inspect --for-agent", ... }
|
|
41
|
+
# }
|
|
42
|
+
# After the last step, dbcli returns kind: "done".
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`--result` accepts inline JSON `StepResultSummary` or `@<path>` to read from a file. `stdoutSummary` and `stderrSummary` are capped at 4 KB each — pre-truncate to the **last** 4 KB before passing. `--next` is mutually exclusive with `--apply`. Each call is independent (no persisted cursor) — the agent tracks `--after-step` itself.
|
|
46
|
+
5. `dbcli blacklist list` — sensitive data boundaries.
|
|
47
|
+
6. `dbcli schema <table> --format json` — real column names (SQL/Mongo/ES) or `schema <key>` (Redis). **Never guess.**
|
|
48
|
+
7. Run `query` / `insert` / `update` / `delete` / `export` within permission.
|
|
49
|
+
8. All writes: `--dry-run` (SQL/Mongo) → run → `query` read-back to confirm.
|
|
17
50
|
|
|
18
51
|
Prefer `--format json` for agent-friendly output.
|
|
19
52
|
|
|
@@ -154,22 +187,32 @@ Full flags and edge cases: see [reference.md](reference.md) `init` section.
|
|
|
154
187
|
| `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. |
|
|
155
188
|
| `use` | n/a | Show/switch default named connection (v2 only). |
|
|
156
189
|
| `list` | query-only+ | Tables (SQL), collections (MongoDB), keys (Redis), or indices (Elasticsearch). |
|
|
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`). |
|
|
159
|
-
| `
|
|
160
|
-
| `
|
|
161
|
-
| `
|
|
190
|
+
| `schema` | query-only+ | SQL: per-table or full scan into `.dbcli/schemas/`. MongoDB: sampled. ES: flattened mapping. Redis: per-key only (type/TTL/size). Supports `--recovery`. |
|
|
191
|
+
| `query` | query-only+ | SQL, Mongo JSON (`--collection`), Redis command, or ES DSL/Lucene (`--collection`). Supports `--recovery`. |
|
|
192
|
+
| `plan` | n/a | Static SQL risk analyzer (`--format text\|json`); classifies a statement without connecting to the database. |
|
|
193
|
+
| `q` | query-only+ | Run a saved snippet by `@name` with `--param k=v`. SQL / Elasticsearch DSL / read-only Redis bodies; blacklist enforced. Supports `--recovery`. |
|
|
194
|
+
| `queries` | n/a | Manage saved snippets: `list` / `show` / `search` / `suggest` / `new` / `edit` / `check` / `delete` / `rename` / `copy` / `import` / `export`. |
|
|
195
|
+
| `insert` / `update` | read-write+ | SQL or MongoDB only. JSON `--data` / `--set`; `--where` required on `update`; `--dry-run` first. Redis writes go through `query`. Supports `--recovery`. |
|
|
196
|
+
| `delete` | data-admin+ | SQL or MongoDB only. `--where` required; `--dry-run` first. Supports `--recovery`. |
|
|
197
|
+
| `export` | query-only+ | SQL or MongoDB only. Query → CSV/JSON(L) file or stdout. Supports `--recovery`. |
|
|
162
198
|
| `blacklist` | n/a | `list` / `table` / `column` subcommands redact sensitive data from query results. |
|
|
163
199
|
| `check` | query-only+ | SQL only (best on MySQL/MariaDB). |
|
|
164
200
|
| `diff` | query-only+ | SQL only. Save/compare schema snapshots. |
|
|
165
201
|
| `status` | query-only+ | Safe JSON/text summary (no credentials). |
|
|
202
|
+
| `inspect` | query-only+ | Read-only context snapshot (connection, permission, blacklist, objects, snippets, suggested commands). `--for-agent` / `--no-connect` / `--require-schema-cache`. Supports `--recovery`. |
|
|
203
|
+
| `report` | query-only+ | Diagnostic report (health / capacity / perf) built from `@diag/*` snippets. `--section`, `--brief`, `--for-agent`, `--no-connect`. |
|
|
204
|
+
| `guide` | query-only+ | Deterministic next-command plan for a fixed goal (`slow-query`, `capacity`, `health`, `index-usage`, `permissions`, `schema-overview`). `--list` to enumerate. |
|
|
205
|
+
| `recovery` | n/a | Look up the structured `RecoveryEnvelope` for a known error code (`--code <CODE>` or `--list`). Standalone synthesizer; does not require a real failure. |
|
|
206
|
+
| `recover` | n/a | Inspect (default) or `--apply` the auto-saved recovery plan in `.dbcli/last-recovery.json`. `--allow-write=readonly-cmd\|write-cmd`, `--no-verify`, `--from <file>`, `--next --after-step <n> --result <json\|@file>` for multi-turn step-at-a-time. |
|
|
166
207
|
| `doctor` | n/a | Environment, config, connection, SRV diagnostics (Mongo), schema cache age. |
|
|
167
208
|
| `completion` | n/a | bash / zsh / fish scripts. |
|
|
168
209
|
| `upgrade` | n/a | Self-update from npm; 24h-cached version hints on every command. |
|
|
169
210
|
| `shell` | (same as query+) | Interactive REPL. SQL engines + MongoDB shell only. |
|
|
211
|
+
| `skill` | n/a | Generate / install AI skill docs (`--install <claude\|gemini\|copilot\|cursor>`); `skill tasks list/show/plan` for Agent Task Packs. |
|
|
170
212
|
| `migrate` | admin | SQL only. **DDL; dry-run by default** — needs `--execute`. |
|
|
171
213
|
|
|
172
214
|
`--use <name>` on any subcommand targets a v2 connection without changing the default.
|
|
215
|
+
`--recovery` is honoured by `query`, `q`, `insert`, `update`, `delete`, `export`, `schema`, and `inspect`; on failure these emit a `RecoveryEnvelope` JSON to stdout, suppress the human stderr message, and atomically save the envelope to `.dbcli/last-recovery.json` for `dbcli recover` to consume.
|
|
173
216
|
|
|
174
217
|
## Permission levels
|
|
175
218
|
|
|
@@ -224,6 +267,14 @@ Run reusable parameterised SELECT snippets stored in your repo.
|
|
|
224
267
|
| 2. Inspect | `dbcli queries show @<name>` |
|
|
225
268
|
| 3. Run | `dbcli q @<name> --param k=v` |
|
|
226
269
|
|
|
270
|
+
### When you don't know which query to run
|
|
271
|
+
|
|
272
|
+
1. `dbcli queries search <keywords>` — natural keywords, fuzzy ranked
|
|
273
|
+
2. `dbcli queries suggest <intent>` — browse a category
|
|
274
|
+
Common intents: perf.slow-query, perf.cache-hit, capacity.size,
|
|
275
|
+
safety.connections, monitor.cluster-health
|
|
276
|
+
3. Once you find one: `dbcli q @<name>` (blacklist always enforced)
|
|
277
|
+
|
|
227
278
|
Snippets resolve from three layers, **local > shared > builtin** (local wins):
|
|
228
279
|
- `builtin` — bundled with dbcli (e.g. `@diag/*`); read-only at runtime
|
|
229
280
|
- `.dbcli-shared/queries/` — committed, team-shared
|