@carllee1983/dbcli 1.25.0 → 1.28.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,7 +5,31 @@ 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
- ## [Unreleased]
8
+ ## [1.28.0] - 2026-06-08 - Core Subpath Export
9
+
10
+ ### Added
11
+
12
+ - **`@carllee1983/dbcli/core` 子路徑匯出。** 新增穩定對外 API barrel(`src/core/public.ts`),透過 `package.json` 的 `exports` map 開出 `./core` 子路徑,並隨套件發布 `dist/core.mjs` 與扁平型別宣告 `dist/core.d.ts`。外部專案(如 `dbcli-gui` 桌面客戶端的 Bun sidecar)可 `import { AdapterFactory, QueryExecutor, SchemaLayeredLoader, listConnections, BlacklistManager } from '@carllee1983/dbcli/core'` 直接重用引擎能力。CLI(`bin`)行為完全不變。
13
+
14
+ ## [1.27.0] - 2026-06-05 - Proxy Analyze
15
+
16
+ ### Added
17
+
18
+ - **`dbcli proxy analyze` — 離線分析 proxy 事件日誌。** 讀取 `.dbcli/proxy/events.jsonl`(預設含 rotation `.1` 段),聚合成 agent-facing JSON 報告(`summary`、`byFingerprint`、`slowest`、`errors`、`hotTables`、`repetition`)或人類版 text。重用 `redactLiterals` 做 SQL 指紋正規化;對最吃總時間的 SELECT 指紋附上可執行的 `suggestedCommands`(`explain` / `guide missing-index-for`),僅輸出建議指令字串、不自動執行。旗標:`--events`、`--format json|text`、`--top`、`--slow-ms`、`--n-plus-one`、`--no-include-rotated`。不連資料庫。
19
+
20
+ ### Changed
21
+
22
+ - **`dbcli proxy` — 事件日誌寫入序列化 + 自動輪替。** `EventWriter` 現在將所有寫入(根事件 + 全部 session)序列化到單一 in-process promise 鏈,避免多連線併發時 JSONL 行交錯或 rotation 計數競態;單一寫入失敗只影響該呼叫端(維持 fail-loud),不會卡住後續寫入。新增自動輪替(重用抽出的中性工具 `src/utils/jsonl-rotation.ts`,audit logger 亦改用同一份):當下一行將達 ~50 MiB 或 200,000 筆時,目前檔案改名為 `<events>.1`(覆寫舊段),保留單一滾動段,最壞磁碟用量約為位元組上限的 2 倍。先前 `events.jsonl` 會無限制成長。
23
+
24
+ ### Fixed
25
+
26
+ - **`dbcli proxy` — `--slow-ms` 現在會在事件中標記 `slow`。** `query_completed` 事件新增 `slow: boolean` 欄位(`durationMs >= --slow-ms` 時為 `true`),與既有的終端警告一致。先前 `--slow-ms` 僅印出終端警告,但 CHANGELOG/使用者文件/reference 卻宣稱事件帶有 `slow` 旗標——此落差已修正。同步修正 `reference.md` 的 JSONL 事件範例(欄位名與實際 `query_completed` 結構對齊),並更新 en/zh-TW 使用者文件(md + html)中對 `--slow-ms` 的描述。
27
+
28
+ ## [1.26.0] - 2026-06-04 - Observability Proxy
29
+
30
+ ### Added
31
+
32
+ - **`dbcli proxy` — 本地端開發觀測代理。** 支援 `mysql`、`mariadb`、`postgresql` 子指令。在現有應用程式與真實資料庫之間插入一個中繼層:dbcli 監聽 `--listen` 埠,轉送流量至 `--target`(或 `--use` / config 目標推斷),並把每個查詢的查詢文字、延遲、傳輸位元組、錯誤等事件以 JSONL 格式附加到 `.dbcli/proxy/events.jsonl`(可用 `--events` 覆寫)。僅作觀測使用,不執行任何改寫或封鎖。旗標:`--listen <addr:port>`、`--target <addr:port>`、`--events <path>`(預設 `.dbcli/proxy/events.jsonl`)、`--slow-ms <ms>`(預設 `1000`,超過即在事件中標記 `slow: true`)、`--redact none|literals`(預設 `none`;`literals` 會從事件裡剔除 SQL 字面值)、`--format text|json`(預設 `text`)。TLS 在 v1 僅轉送不解密;prepared / extended 協定為盡力標記。
9
33
 
10
34
  ## [1.25.0] - 2026-05-29 - Data-Layer Verification
11
35
 
package/README.md CHANGED
@@ -812,6 +812,29 @@ dbcli assert "SELECT * FROM orders" --against base.json --tolerance 0.01
812
812
 
813
813
  ---
814
814
 
815
+ #### `dbcli proxy` (v1.26)
816
+
817
+ Local-development **observability proxy** for MySQL, MariaDB, and PostgreSQL. Point an existing app at the proxy port; dbcli relays all TCP frames to the real database and appends one JSONL event per query to `.dbcli/proxy/events.jsonl`. Observe-only — no rewrite or blocking. Not a production gateway.
818
+
819
+ **Subcommands:** `mysql` · `mariadb` · `postgresql`
820
+
821
+ ```bash
822
+ dbcli proxy mysql --listen 127.0.0.1:3307 --target 127.0.0.1:3306
823
+ dbcli proxy postgresql --listen 127.0.0.1:5434 --target 127.0.0.1:5432
824
+ dbcli proxy mysql --slow-ms 500 --redact literals
825
+ dbcli proxy mariadb --events ./logs/proxy.jsonl
826
+ ```
827
+
828
+ **Options:**
829
+ - `--listen <addr:port>` — Proxy listen address
830
+ - `--target <addr:port>` — Real database address (inferred from config / `--use` if omitted)
831
+ - `--events <path>` — JSONL event log (default: `.dbcli/proxy/events.jsonl`)
832
+ - `--slow-ms <ms>` — Flag events slower than this threshold as `slow: true` (default: `1000`)
833
+ - `--redact none|literals` — Strip SQL literal values from event records (default: `none`)
834
+ - `--format text|json` — Startup output format (default: `text`)
835
+
836
+ ---
837
+
815
838
  #### `dbcli status`
816
839
 
817
840
  Show non-sensitive configuration summary (permission level, DB system, blacklist counts, config metadata version). Does not print connection credentials — intended for AI agents.
package/README.zh-TW.md CHANGED
@@ -711,6 +711,29 @@ dbcli assert "SELECT * FROM orders" --against base.json --tolerance 0.01
711
711
 
712
712
  ---
713
713
 
714
+ #### `dbcli proxy`(v1.26)
715
+
716
+ MySQL、MariaDB、PostgreSQL 的本地端**開發觀測代理**。將現有應用程式指向代理埠;dbcli 會將所有 TCP 訊框中繼至真實資料庫,並把每個查詢的事件(查詢文字、延遲、傳輸位元組、錯誤)附加到 `.dbcli/proxy/events.jsonl`。僅作觀測使用,不執行任何改寫或封鎖。非正式環境閘道。
717
+
718
+ **子指令:** `mysql` · `mariadb` · `postgresql`
719
+
720
+ ```bash
721
+ dbcli proxy mysql --listen 127.0.0.1:3307 --target 127.0.0.1:3306
722
+ dbcli proxy postgresql --listen 127.0.0.1:5434 --target 127.0.0.1:5432
723
+ dbcli proxy mysql --slow-ms 500 --redact literals
724
+ dbcli proxy mariadb --events ./logs/proxy.jsonl
725
+ ```
726
+
727
+ **選項:**
728
+ - `--listen <addr:port>` — 代理監聽位址
729
+ - `--target <addr:port>` — 真實資料庫位址(若省略則從 config / `--use` 推斷)
730
+ - `--events <path>` — JSONL 事件記錄路徑(預設:`.dbcli/proxy/events.jsonl`)
731
+ - `--slow-ms <ms>` — 超過此門檻的事件標記 `slow: true`(預設:`1000`)
732
+ - `--redact none|literals` — 從事件記錄中剔除 SQL 字面值(預設:`none`)
733
+ - `--format text|json` — 啟動輸出格式(預設:`text`)
734
+
735
+ ---
736
+
714
737
  #### `dbcli status`
715
738
 
716
739
  顯示不含連線憑證的設定摘要(權限、資料庫系統、黑名單筆數、設定中繼版本),適合提供給 AI 代理。
package/assets/SKILL.md CHANGED
@@ -252,6 +252,7 @@ Full flags and edge cases: see [reference.md](reference.md) `init` section.
252
252
  | `diff` | query-only+ | SQL only. Save/compare schema snapshots. |
253
253
  | `snapshot` | query-only+ | **(v1.25)** SQL only. Capture a result fingerprint (`rowCount` + per-column null/distinct/min/max/sum + order-independent checksum). `--out` (default `.dbcli/snapshots/snap-<ts>.json`), `--rows`, `--stdout`, `--format`, `--no-limit`. Baseline for `assert --against`. |
254
254
  | `assert` | query-only+ | **(v1.25)** SQL only. Verify an invariant; exit 1 on failure unless `--no-fail`. `--expect "rows>0\|value==X\|col:c not null\|unique\|between a and b\|>= n"`, `--vs <query> --compare rows\|value` (reconcile), `--against <snapshot> --tolerance <pct>`. |
255
+ | `proxy` | n/a | **(v1.26)** MySQL/MariaDB/PostgreSQL only. Local-dev observability proxy — relays app traffic to the real DB and appends query/latency/byte/error events to `.dbcli/proxy/events.jsonl`. Subcommands: `mysql` \| `mariadb` \| `postgresql`. `--listen`, `--target`, `--events` (default `.dbcli/proxy/events.jsonl`), `--slow-ms` (default `1000`), `--redact none\|literals` (default `none`). Observe-only. **(v1.27)** `proxy analyze` aggregates the event log offline into a JSON/text report (summary, byFingerprint with suggestedCommands, slowest, errors, hotTables, N+1) — `--format`, `--top`, `--slow-ms`, `--n-plus-one`. |
255
256
  | `status` | query-only+ | Safe JSON/text summary (no credentials). |
256
257
  | `inspect` | query-only+ | Read-only context snapshot (connection, permission, blacklist, objects, snippets, context-aware `suggestedCommands`, and **(v1.23)** human-readable `hints`). `--for-agent` / `--brief` / `--no-connect` / `--require-schema-cache`. Supports `--recovery`. |
257
258
  | `report` | query-only+ | Diagnostic report (health / capacity / perf) built from `@diag/*` snippets. `--section`, `--brief`, `--for-agent`, `--no-connect`. |
@@ -211,6 +211,7 @@ dbcli init --use-env-refs \
211
211
  | `diff` | query-only+ | 僅 SQL。儲存 / 比較 schema snapshot。 |
212
212
  | `snapshot` | query-only+ | **(v1.25)** 僅 SQL。擷取結果指紋(`rowCount` + 每欄 null/distinct/min/max/sum + 順序無關 checksum)。`--out`(預設 `.dbcli/snapshots/snap-<ts>.json`)、`--rows`、`--stdout`、`--format`、`--no-limit`。作為 `assert --against` 的基準。 |
213
213
  | `assert` | query-only+ | **(v1.25)** 僅 SQL。驗證不變量;失敗時 exit 1,除非 `--no-fail`。`--expect "rows>0\|value==X\|col:c not null\|unique\|between a and b\|>= n"`、`--vs <query> --compare rows\|value`(對帳)、`--against <snapshot> --tolerance <pct>`。 |
214
+ | `proxy` | n/a | **(v1.26)** 僅 MySQL/MariaDB/PostgreSQL。本地端開發觀測代理 — 中繼應用程式流量至真實資料庫,並將查詢 / 延遲 / 位元組 / 錯誤事件附加到 `.dbcli/proxy/events.jsonl`。子指令:`mysql` \| `mariadb` \| `postgresql`。`--listen`、`--target`、`--events`(預設 `.dbcli/proxy/events.jsonl`)、`--slow-ms`(預設 `1000`)、`--redact none\|literals`(預設 `none`)。僅作觀測,不改寫或封鎖。 |
214
215
  | `status` | query-only+ | 安全 JSON / 文字摘要(不含憑證)。 |
215
216
  | `inspect` | query-only+ | 唯讀脈絡快照(連線、權限、blacklist、物件、snippets、建議指令)。`--for-agent` / `--no-connect` / `--require-schema-cache`。支援 `--recovery`。 |
216
217
  | `report` | query-only+ | 以 `@diag/*` snippet 組成的診斷報告(health / capacity / perf)。`--section`、`--brief`、`--for-agent`、`--no-connect`。 |
@@ -616,6 +616,50 @@ dbcli assert "SELECT count(*) FROM orders" --expect "value > 100" --no-fail #
616
616
  **Engines:** SQL only (PostgreSQL / MySQL / MariaDB)
617
617
  **Permission:** query-only+
618
618
 
619
+ ### proxy
620
+
621
+ Local-development **observability proxy** for MySQL/MariaDB/PostgreSQL. Inserts dbcli
622
+ between an existing application and its real database: it listens on a configurable
623
+ port, relays TCP frames to the real server, and appends one JSONL event per query to
624
+ `.dbcli/proxy/events.jsonl`. Observe-only — no rewrite, blocking, or query modification.
625
+ Not intended as a production gateway.
626
+
627
+ **Subcommands:** `mysql` · `mariadb` · `postgresql`
628
+
629
+ ```bash
630
+ dbcli proxy mysql --listen 127.0.0.1:3307 --target 127.0.0.1:3306
631
+ dbcli proxy postgresql --listen 127.0.0.1:5434 --target 127.0.0.1:5432
632
+ dbcli proxy mysql --slow-ms 500 --redact literals # redact SQL literals in events
633
+ dbcli proxy mariadb --events ./logs/proxy.jsonl # custom event file
634
+ dbcli proxy postgresql --use prod # infer target from named connection
635
+
636
+ dbcli proxy analyze # analyze .dbcli/proxy/events.jsonl (JSON)
637
+ dbcli proxy analyze --format text --top 10 # human-readable top-10 view
638
+ dbcli proxy analyze --slow-ms 200 --n-plus-one 5 # custom thresholds
639
+ ```
640
+
641
+ **Options:**
642
+ - `--listen <addr:port>` — Address dbcli will listen on (e.g. `127.0.0.1:3307`)
643
+ - `--target <addr:port>` — Address of the real database server to relay to. If omitted, inferred from the active (or `--use`) connection config.
644
+ - `--events <path>` — JSONL event log path (default: `.dbcli/proxy/events.jsonl`)
645
+ - `--slow-ms <ms>` — Threshold in milliseconds above which events are flagged `slow: true` (default: `1000`)
646
+ - `--redact <none|literals>` — Whether to strip SQL literal values from event records (default: `none`; `literals` removes quoted strings and numbers)
647
+ - `--format <text|json>` — Startup / status output format (default: `text`)
648
+ - `--use <name>` — Target a named v2 connection for `--target` inference
649
+
650
+ **Event schema (JSONL):** each line is one event. `type` is one of `proxy_started`, `session_started`, `query_observed`, `query_completed`, `query_errored`, `session_ended`, `parse_error`. A representative `query_completed` line:
651
+ ```json
652
+ { "version": 1, "type": "query_completed", "timestamp": "<ISO-8601>", "engine": "mysql", "sessionId": "pxy_1", "queryId": "qry_pxy_1_1", "client": "127.0.0.1:54321", "target": "127.0.0.1:3306", "sql": "SELECT * FROM users WHERE id = 1", "statement": "SELECT", "tables": ["users"], "durationMs": 42, "requestBytes": 128, "responseBytes": 512, "rowCount": null, "slow": false, "error": null, "tags": [] }
653
+ ```
654
+ `slow` is `true` when `durationMs >= --slow-ms` (also printed as a terminal warning). `rowCount` is best-effort (PostgreSQL command tags; `null` for MySQL). TLS is relayed but not decrypted in v1. Prepared/extended wire protocols are best-effort tagged.
655
+
656
+ **Log rotation:** all writes are serialized through one in-process chain (concurrent sessions never interleave partial lines). The event log auto-rotates to keep one rolling segment — when the next line would reach ~50 MiB or 200,000 entries, the current file is renamed to `<events>.1` (overwriting any prior segment) and a fresh file starts. Worst-case on-disk footprint is ~2× the byte cap.
657
+
658
+ **`proxy analyze`** — offline aggregation of the event log (no DB). Flags: `--events <path>` (default `.dbcli/proxy/events.jsonl`), `--format json|text` (default `json`), `--top <n>` (default 20; text rows + suggestedCommands depth), `--slow-ms <ms>` (default 1000; recomputes slowCount), `--n-plus-one <n>` (default 10), `--no-include-rotated`. JSON report blocks: `summary`, `byFingerprint` (sorted by total time; SELECT entries in the top-N carry `suggestedCommands` for `explain` / `guide missing-index-for`), `slowest`, `errors`, `hotTables`, `repetition` (N+1 suspects). Reads the current log plus the rotated `.1` segment by default.
659
+
660
+ **Engines:** MySQL / MariaDB / PostgreSQL
661
+ **Permission:** n/a (acts as a TCP relay; does not use dbcli's SQL permission model)
662
+
619
663
  ### status
620
664
 
621
665
  Show current configuration status (safe for AI agents, no credentials exposed).