@carllee1983/dbcli 1.19.1 → 1.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -787,6 +787,93 @@ dbcli recover --next --after-step 1 --result '{"status":"ok"}' --format markdown
787
787
 
788
788
  **Permission:** n/a (always-allowed lookup; child processes inherit the active permission level).
789
789
 
790
+ ### audit
791
+
792
+ (v1.20.0+) Inspect, query, and manage the per-connection audit log written to `.dbcli/audit/<connection>.jsonl`.
793
+
794
+ Audit entries are metadata-only by design — never raw SQL bodies, `--param` values, or result cell contents (D3 lock). Redaction is sourced from `tests/helpers/sensitive-output.ts` (same source as `inspect` / `guide` / `recover` agent contracts).
795
+
796
+ #### Subcommands
797
+
798
+ | Subcommand | Side-effect tier | Purpose |
799
+ |---|---|---|
800
+ | `audit tail` | `readonly` | List most recent entries on the current (or `--all`) connection. |
801
+ | `audit show` | `readonly` | Print a single full entry by id prefix or `--recovery-ref`. |
802
+ | `audit clear` | `local-write` | Delete `<conn>.jsonl` + rotated `.jsonl.1` from local disk. Requires `--yes` or interactive confirm. |
803
+ | `audit health` | `readonly` | Render `AuditLogger.getHealth()` snapshot (writer state, lock state, rotation usage). |
804
+
805
+ #### `audit tail`
806
+
807
+ | Flag | Purpose | Default |
808
+ |---|---|---|
809
+ | `--n <N>` | Number of recent entries to print (latest at bottom — D5). | `10` |
810
+ | `--all` | Merge entries across all connections; output is an envelope array `[{ connection, entry }, ...]` (D-39). | off (current connection only) |
811
+ | `--for-agent` | Shortcut for `--format json --brief`. Single-connection JSON is a flat array; `--all` JSON is an envelope array. | off |
812
+ | `--brief` | Drop large redaction fields from the entry; keep `ts / command / target / success` (D-33). | off |
813
+ | `--format <fmt>` | `table` \| `json`. | `table` |
814
+
815
+ Reader behavior (D-41): tail merges `<conn>.jsonl.1` (rotated segment, if present) and `<conn>.jsonl`, sorts by `ts` ascending, then takes the last `--n` entries — so `--n 1000` can span a fresh rotation boundary.
816
+
817
+ Examples:
818
+
819
+ dbcli audit tail --n 10
820
+ dbcli audit tail --all --for-agent --n 20
821
+ dbcli audit tail --format json --brief
822
+
823
+ #### `audit show`
824
+
825
+ | Flag | Purpose | Default |
826
+ |---|---|---|
827
+ | `<id-prefix>` | Positional. UUID or prefix ≥ 4 characters; ambiguous prefix exits 1 with disambiguation hint; prefix < 4 chars exits 1. | — |
828
+ | `--recovery-ref <id>` | Find the audit entry whose `recovery_ref` field matches this id (exact, not prefix). Mutually exclusive with positional `<id-prefix>` (D-38). | — |
829
+ | `--all` | Search across all connections. Output is an envelope `{ connection, entry }` (single-hit also envelope, for shape stability — D-36). | off |
830
+ | `--format <fmt>` | `table` \| `json`. | `table` |
831
+
832
+ Examples:
833
+
834
+ dbcli audit show 1a2b
835
+ dbcli audit show --recovery-ref 8f0e-1234-... --format json
836
+ dbcli audit show 1a2b --all
837
+
838
+ #### `audit clear`
839
+
840
+ | Flag | Purpose | Default |
841
+ |---|---|---|
842
+ | `--yes` | Skip interactive confirmation. Required in non-TTY contexts. | off (interactive confirm) |
843
+
844
+ Behavior (D-45 / D-46 / D-47): deletes `<conn>.jsonl` + rotated `<conn>.jsonl.1` for the current connection. Does NOT touch other connections (`--all` is not supported — destructive op cross-connection blast-radius is too high; use `dbcli use` to switch and clear each). Does NOT reset `.dbcli/last-session-id` (D-48). In non-TTY contexts without `--yes`, exits 1 with `Cannot prompt for confirmation in non-interactive session. Use --yes to clear without prompt.`
845
+
846
+ Examples:
847
+
848
+ dbcli audit clear # interactive (TTY only)
849
+ dbcli audit clear --yes # CI / scripted
850
+
851
+ #### `audit health`
852
+
853
+ | Flag | Purpose | Default |
854
+ |---|---|---|
855
+ | `--format <fmt>` | `table` \| `json`. | `table` |
856
+
857
+ Output reports: writer enabled/disabled, last write result, file-lock state, rotation cap usage (`max_bytes` / `max_entries`). When `audit.enabled = false` (D1 opt-out), `tail` / `show` / `health` still exit 0 and print `Audit is disabled (audit.enabled = false in .dbcli). Use 'dbcli audit health' for details.` (E note).
858
+
859
+ #### Boundaries
860
+
861
+ - Entries are append-only JSONL; rotation triggers at `~10 MB` or `~1000` entries (whichever first). Previous segment is preserved as `.jsonl.1`.
862
+ - Bi-directional `recovery_ref` / `audit_ref` linkage is wired on every command that accepts `--recovery`: `query`, `inspect`, `insert`, `update`, `delete`, `export`, `q`, and `schema`. Use `audit tail --recovery-ref <id>` to find the audit entry an envelope was emitted alongside.
863
+ - Audit writer failures are non-fatal (D6): main command result and exit code are preserved; a stderr warning is emitted. `audit health` surfaces the failure reason.
864
+ - Reader truncation tolerance: a crash-truncated last line is skipped with a stderr warn `[dbcli audit] skipping truncated last line in <file>`; a mid-file non-JSON line is treated as corruption, exits 1, and points at `dbcli audit clear`.
865
+
866
+ #### Exit codes
867
+
868
+ | Code | Condition |
869
+ |---|---|
870
+ | 0 | Read/list/clear/health succeeded; also `audit.enabled = false` opt-out path (E note). |
871
+ | 1 | `audit show` — id prefix < 4 chars, ambiguous, or not found; `--recovery-ref` not found; `<id>` and `--recovery-ref` both supplied (D-35 / D-37 / D-38). |
872
+ | 1 | `audit clear` — non-TTY without `--yes` (D-46). |
873
+ | 1 | Reader corruption — mid-file non-JSON line in a `.jsonl` segment. |
874
+
875
+ **Permission:** n/a
876
+
790
877
  ### doctor
791
878
 
792
879
  Run diagnostic checks on environment, configuration, connection, and data.