@sdt-tools/cli 0.2.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.
@@ -0,0 +1,393 @@
1
+ import { Command } from 'commander';
2
+
3
+ declare function initCommand(): Command;
4
+
5
+ declare function buildCommand(): Command;
6
+
7
+ declare function extractCommand(): Command;
8
+
9
+ declare function compareCommand(): Command;
10
+
11
+ declare function publishCommand(): Command;
12
+
13
+ declare function driftCommand(): Command;
14
+
15
+ /**
16
+ * `sdt validate` — schema-shape sanity check on a `.sdtproj`. Default
17
+ * mode confirms the project file parses, scope resolves, and object
18
+ * files discover successfully. The `--references` flag adds the
19
+ * Microsoft-SSDT-style build-time semantic resolution: every object reference in every
20
+ * project body is classified as resolved / dangling / external /
21
+ * temporary / dynamic, with warnings for unresolved references.
22
+ *
23
+ * Column-level resolution is Phase 2 (BACKLOG-tracked).
24
+ */
25
+ declare function validateCommand(): Command;
26
+
27
+ declare function connectionCommand(): Command;
28
+
29
+ /**
30
+ * Placeholder factory for commands whose backing engine is a later
31
+ * deliverable. Prints a clear "not yet implemented" message and exits
32
+ * non-zero so CI notices.
33
+ *
34
+ * Mirrors `ddt scaffold` — exported for embedders, not wired into the
35
+ * SDT CLI itself.
36
+ */
37
+ declare function scaffoldCommand(name: string): Command;
38
+
39
+ /**
40
+ * `sdt graph` — emit an object-dependency DAG (Mermaid or DOT) from a
41
+ * `.sdtproj` or `.sdtpac`. Lets reviewers see blast radius before a
42
+ * drop. Inspired by DBeaver's "Object References" panel — but at the
43
+ * cross-object level rather than column level.
44
+ *
45
+ * With `--compare-to <other-source>`, diffs the two graphs and (when
46
+ * `--explain` is on) narrates the DAG changes in plain English — the
47
+ * AI Phase 6 "lineage explanation" surface.
48
+ *
49
+ * Mirrors `ddt graph`.
50
+ */
51
+ declare function graphCommand(): Command;
52
+
53
+ declare function historyCommand(): Command;
54
+
55
+ /**
56
+ * `sdt verify <pac>` — recompute checksums and confirm the .sdtpac is
57
+ * intact. Catches tampering / corruption / partial-extraction
58
+ * accidents. Sets up the Enterprise-tier signing chain — a signed pac
59
+ * is `verify` + `signature-check` together.
60
+ */
61
+ declare function verifyCommand(): Command;
62
+
63
+ declare function installHooksCommand(): Command;
64
+
65
+ /**
66
+ * `sdt script` — generate a deploy SQL script for source → target. Mirrors
67
+ * SqlPackage `/Action:Script` / SSDT's "Generate Script" affordance. Always
68
+ * offline — does not touch a live Snowflake account.
69
+ *
70
+ * Output formats:
71
+ * - sql (default): human-readable migration script with banner comments
72
+ * - json: raw CompareResult + safety assessment + per-statement
73
+ * metadata, suitable for CI gates or UI rendering
74
+ *
75
+ * Mirrors `ddt script`. To compare against a live account, use
76
+ * `sdt compare` or `sdt publish`.
77
+ */
78
+ declare function scriptCommand(): Command;
79
+
80
+ /**
81
+ * `sdt revert --manifest <path>` — undo a previous deploy by executing
82
+ * each step's `reverseSql` in reverse order. Manifests come from
83
+ * `sdt publish --apply --manifest <path>` (the JSON deploy manifest
84
+ * captured after `--apply`).
85
+ *
86
+ * Steps without `reverseSql` are inherently irreversible (DROP, etc.)
87
+ * and skipped with a clear warning. The command exits non-zero if any
88
+ * reverse fails or if any step was irreversible (the user must inspect
89
+ * by hand).
90
+ *
91
+ * Mirrors `Databricks/packages/cli/src/commands/revert.ts`. Use case: a
92
+ * deploy succeeded but something downstream broke; revert it. Use case:
93
+ * drift is detected and you need to roll back to the last-known-good
94
+ * state.
95
+ */
96
+ declare function revertCommand(): Command;
97
+
98
+ /**
99
+ * `sdt seed` — declare static reference rows next to DDL; engine
100
+ * generates MERGE statements to keep them in sync.
101
+ *
102
+ * Mirrors `Databricks/packages/cli/src/commands/seed.ts`. Subcommands:
103
+ * list enumerate seed files + row counts
104
+ * render -p <project> emit MERGEs to stdout (offline)
105
+ * apply -p <project> -c <conn> execute the MERGEs against an account
106
+ */
107
+ declare function seedCommand(): Command;
108
+
109
+ /**
110
+ * `sdt lineage` — extract data-flow lineage from a `.sdtproj` or
111
+ * `.sdtpac` and emit it as Mermaid, DOT, JSON, or Markdown.
112
+ *
113
+ * Distinct from `sdt graph`: graph is FQN-level dependency edges
114
+ * (A references B). Lineage adds direction-of-data-flow classification
115
+ * (READS_FROM vs WRITES_TO), upstream/downstream traversal, and
116
+ * column-level best-effort tagging for view SELECT lists.
117
+ *
118
+ * Use cases:
119
+ * - "What does ANALYTICS.GOLD.CUSTOMER_360 depend on?" (upstream slice)
120
+ * - "If I drop RAW.STAGING.ORDERS_RAW, what breaks?" (downstream slice)
121
+ * - "Embed this graph in our PR template / docs / dashboard."
122
+ *
123
+ * Mirrors `ddt lineage`.
124
+ */
125
+ declare function lineageCommand(): Command;
126
+
127
+ /**
128
+ * `sdt diagnose` — project-level health report. Bundles lint, lineage
129
+ * smells (orphan / no-downstream / hot-table / cycle), object smells
130
+ * (`SELECT *` in views, large tables without clustering, missing PK)
131
+ * and cost smells (warehouse without AUTO_SUSPEND, long Time Travel)
132
+ * into one ranked report. Every finding ships with a **reasoning**
133
+ * line explaining *why* it matters — readers learn the engineering
134
+ * motivation, not just the patch.
135
+ *
136
+ * Use cases:
137
+ * - Pre-PR check: `sdt diagnose --source <proj> --min-severity warning`
138
+ * - Periodic project audit: weekly cron emitting JSON to a dashboard
139
+ * - Onboarding: a new engineer reads the report to learn what good
140
+ * looks like in this codebase
141
+ *
142
+ * Mirrors `ddt diagnose`.
143
+ */
144
+ declare function diagnoseCommand(): Command;
145
+
146
+ /**
147
+ * `sdt review` — produce a senior-DBA Markdown report combining lint,
148
+ * lineage findings, smell findings, cost findings, and safety
149
+ * reasoning. The deliverable a reviewer can paste straight into a PR
150
+ * or an architecture-review meeting.
151
+ *
152
+ * Default mode (project health): pure composition of existing modules —
153
+ * every finding's reasoning + suggestion is generated by
154
+ * `@sdt-tools/core/diagnostics`; the format is the value-add.
155
+ *
156
+ * `--senior-dba` mode (AI Phase 4): takes a compare-result JSON
157
+ * (typically the output of `sdt compare --json`) + a safety-summary
158
+ * JSON + optional target-metadata snapshot + truncated DDL preview,
159
+ * asks the configured AI provider for a senior-DBA verdict, and emits
160
+ * the parsed result as Markdown (or JSON via `--format json`).
161
+ */
162
+ declare function reviewCommand(): Command;
163
+
164
+ /**
165
+ * `sdt impact <fqn>` — single-FQN blast-radius answer. "If I change
166
+ * this, what breaks? What feeds it? What pending diagnostics
167
+ * touch it?" Composition of `@sdt-tools/core/lineage` (upstream/downstream)
168
+ * and `@sdt-tools/core/diagnostics` (findings filtered to the FQN).
169
+ *
170
+ * Output is Markdown by default; `--format json` returns a structured
171
+ * payload for CI integration.
172
+ */
173
+ declare function impactCommand(): Command;
174
+
175
+ /**
176
+ * `sdt cost-estimate` — static heuristic estimator for the Snowflake
177
+ * credits a migration script will consume when applied.
178
+ *
179
+ * Approach: classify each statement by its observable cost-class
180
+ * (TABLE rebuild, CREATE OR REPLACE VIEW, ADD COLUMN, ALTER TYPE,
181
+ * dynamic-table refresh, etc.) and assign a credit-band estimate per
182
+ * class. Estimates are intentionally **ranges** rather than point
183
+ * values because actual cost depends on row count, warehouse size,
184
+ * and data layout — we don't pretend otherwise.
185
+ *
186
+ * The framing alone is uniquely valuable: no other Snowflake schema
187
+ * tool surfaces "this migration will roughly cost X credits at S
188
+ * warehouse" before you apply it.
189
+ *
190
+ * The classifier is regex-based and conservative — when a statement
191
+ * doesn't match a known cost-class it's reported as
192
+ * "unknown / negligible" so the user knows the estimate didn't see it.
193
+ */
194
+ declare function costEstimateCommand(): Command;
195
+
196
+ /**
197
+ * `sdt pr-comment` — produce a Markdown PR sticky-comment from a
198
+ * source↔target compare. Bundles the diff summary, reversibility-
199
+ * grouped safety findings, project health diagnostics, and a
200
+ * collapsible per-object changelog into a single deliverable a CI
201
+ * step can POST as a pull-request comment.
202
+ *
203
+ * Distinct from `sdt review`: `review` is project-only, `pr-comment`
204
+ * is change-driven (here's what's *in this PR*).
205
+ */
206
+ declare function prCommentCommand(): Command;
207
+
208
+ /**
209
+ * `sdt template <kind> <name>` — schema cookbook generator. Produces
210
+ * a complete set of `.sql` files implementing a common pattern, ready
211
+ * to drop into a `.sdtproj`'s object tree. Saves a junior engineer
212
+ * from re-inventing the SCD2 pattern from scratch.
213
+ *
214
+ * Supported kinds:
215
+ * - `scd1` — Slowly-changing-dimension type-1 (overwrite, no history).
216
+ * - `scd2` — Slowly-changing-dimension type-2 (history-preserving).
217
+ * - `scd3` — Slowly-changing-dimension type-3 (one previous value).
218
+ * - `scd4` — Slowly-changing-dimension type-4 (current + history table).
219
+ * - `scd6` — Hybrid 1+2+3 (current + valid_from/to + previous value).
220
+ * - `star` — Star schema fact + N dimensions.
221
+ * - `fact` — Fact table only, with surrogate-key FKs to named dims.
222
+ * - `scd2-merge` — Canonical MERGE statement to load an SCD2 dimension.
223
+ * - `current-view` — `CREATE VIEW` over an SCD2 table where IS_CURRENT = TRUE.
224
+ * - `time-series` — Hash-partitioned time-series with retention.
225
+ * - `audit` — Generic audit-log table with append-only constraints.
226
+ *
227
+ * Mirrors `ddt template`. Patterns are conservative: every template
228
+ * sets a PK, populates COMMENT fields, and prefers `CREATE OR ALTER`
229
+ * over `CREATE OR REPLACE` to play well with the safety classifier.
230
+ */
231
+ declare function templateCommand(): Command;
232
+
233
+ /**
234
+ * `sdt anonymize` — generate masking-policy DDL for PII columns
235
+ * discovered in a project model. Pairs with the L012 `pii-without-mask`
236
+ * lint rule: the lint surfaces *which* columns need masking; this
237
+ * command writes the policy DDL ready to copy into the project.
238
+ *
239
+ * Use case: refresh prod → dev pipeline. Most teams need to
240
+ * pseudonymize PII before any non-prod role sees the data. This
241
+ * command auto-generates a starter set of MASKING POLICY statements
242
+ * + the ALTER TABLE ... ALTER COLUMN ... SET MASKING POLICY calls
243
+ * to apply them.
244
+ *
245
+ * Output is intentionally **conservative**: every emitted policy has
246
+ * `RETURN VAL` (no-op) when the current role is in `('PROD_ETL')` so
247
+ * production keeps working as-is; every other role sees a hashed /
248
+ * redacted value. Adjust the role allow-list before applying.
249
+ */
250
+ declare function anonymizeCommand(): Command;
251
+
252
+ /**
253
+ * `sdt safety` — inspect safety-finding codes.
254
+ *
255
+ * Subcommands:
256
+ * sdt safety list — list every known finding code with a one-line summary
257
+ * sdt safety explain <code> — deep explainer for a single code: why it is dangerous,
258
+ * what cannot be reversed, safer alternatives, required gates
259
+ *
260
+ * The finding codes are stable identifiers attached to every `SafetyFinding`
261
+ * the classifier emits during `sdt compare` / `sdt publish`. When the user
262
+ * sees a finding they don't understand, they can copy the code and ask:
263
+ *
264
+ * sdt safety explain DROP_UNRECOVERABLE
265
+ *
266
+ * See `docs/UX_PLAYBOOK.md` §3 (dangerous-op UX) and
267
+ * `docs/AI_FEATURES.md` use case C2.
268
+ */
269
+
270
+ declare function safetyCommand(): Command;
271
+
272
+ declare function saferAlternativeCommand(): Command;
273
+
274
+ declare function sketchCommand(): Command;
275
+
276
+ declare function compareProfilesCommand(): Command;
277
+
278
+ /**
279
+ * `sdt explorer` — ASCII tree dump of the live db/schema/object hierarchy
280
+ * for a connected target, read from the EE1 catalog cache.
281
+ *
282
+ * The eventual VS Code TreeDataProvider walks the same `treeForSnapshot`
283
+ * shape; this CLI gives non-VS-Code users the same browsable view of the
284
+ * cached catalog. No live queries are issued — the cache is read-only.
285
+ * Run `sdt catalog refresh --connection <name>` first to populate it.
286
+ *
287
+ * Inputs:
288
+ * --connection <name> Required. Connection profile name to load the cache for.
289
+ * --root <path> Project root (where .sdt/cache/ lives). Default cwd.
290
+ * --filter <query> Typeahead filter; case-insensitive substring match.
291
+ * Keeps every ancestor of a leaf match.
292
+ * --json Emit the tree as JSON instead of an ASCII tree.
293
+ */
294
+
295
+ declare function explorerCommand(): Command;
296
+
297
+ /**
298
+ * `sdt catalog` — manage the per-connection catalog cache (EE1 substrate).
299
+ *
300
+ * sdt catalog refresh --connection <name> [--databases <csv>] [--concurrency <n>]
301
+ * sdt catalog show --connection <name> [--json]
302
+ * sdt catalog clear --connection <name>
303
+ *
304
+ * `refresh` opens a live Snowflake connection, discovers databases via
305
+ * `SHOW DATABASES`, runs the bulk-scan SQL per database via the bounded
306
+ * promise pool, and writes the assembled snapshot to
307
+ * `<root>/.sdt/cache/<conn>/catalog.msgpack` (RES.1 — was `catalog.json`
308
+ * before 2026-05-16; the cache reader still accepts the legacy form for
309
+ * one major version). Schema fingerprints (`MAX(LAST_ALTERED)`) are
310
+ * checked first; databases that haven't changed since the last refresh
311
+ * are skipped.
312
+ *
313
+ * `show` reads the cache file and pretty-prints (or emits JSON).
314
+ * `clear` deletes the cache file (and its parent dir if empty).
315
+ *
316
+ * Object Explorer (`sdt explorer`) and the eventual EE2 intellisense
317
+ * provider both consume this cache.
318
+ */
319
+
320
+ declare function catalogCommand(): Command;
321
+
322
+ /**
323
+ * `sdt exec <file.sql> --profiles <list>` — AUTH.3.
324
+ *
325
+ * Runs a SQL script on one or more connection profiles in parallel and
326
+ * prints a merged report. Guarded against any profile whose name matches
327
+ * the word "prod" or "production" (case-insensitive) unless `--yes` is
328
+ * passed.
329
+ *
330
+ * Mirrors `Databricks/packages/cli/src/commands/exec.ts`.
331
+ */
332
+
333
+ interface ExecResult {
334
+ profile: string;
335
+ status: 'success' | 'error';
336
+ rowsAffected?: number;
337
+ durationMs: number;
338
+ error?: string;
339
+ }
340
+ type ExecFn = (profile: string, sql: string, timeoutMs: number) => Promise<Omit<ExecResult, 'profile' | 'durationMs'>>;
341
+ declare function execCommand(execFn?: ExecFn): Command;
342
+
343
+ /**
344
+ * `sdt search <pattern> --profiles <list|all>` — AUTH.4.
345
+ *
346
+ * Finds objects whose name matches a pattern across one or more connection
347
+ * profiles. Surfaces presence/absence drift: if an object exists in some
348
+ * profiles but not others, those profiles are flagged.
349
+ *
350
+ * The search is case-insensitive substring match by default; --exact
351
+ * switches to exact name match; --type filters by objectType.
352
+ *
353
+ * Mirrors `Databricks/packages/cli/src/commands/search.ts`.
354
+ */
355
+
356
+ interface SearchMatch {
357
+ profile: string;
358
+ fqn: string;
359
+ objectType: string;
360
+ }
361
+ interface SearchResult {
362
+ profile: string;
363
+ matches: SearchMatch[];
364
+ error?: string;
365
+ }
366
+ interface SearchFnOptions {
367
+ exact: boolean;
368
+ objectType?: string;
369
+ /** Project / cache root. Defaults to `process.cwd()`. */
370
+ root?: string;
371
+ }
372
+ type SearchFn = (profile: string, pattern: string, opts: SearchFnOptions) => Promise<SearchMatch[]>;
373
+ declare function searchCommand(searchFn?: SearchFn): Command;
374
+
375
+ /**
376
+ * `sdt query-log` — AUTH.5 local query log CLI.
377
+ *
378
+ * Subcommands:
379
+ * sdt query-log list [--profile <p>] [--limit N] [--format text|json]
380
+ * sdt query-log show <id> [--format text|json|sql]
381
+ * sdt query-log add <sql> --profile <p> [--status success|error] [--store <path>]
382
+ * sdt query-log clear [--profile <p>] [--yes]
383
+ *
384
+ * The log is stored at `~/.sdt/query-log.json` (override with --store).
385
+ * EE3 will call `appendEntry()` on the substrate directly when a query
386
+ * is executed. This CLI surfaces it for ad-hoc review + rerun.
387
+ *
388
+ * Mirrors `Databricks/packages/cli/src/commands/query-log.ts`.
389
+ */
390
+
391
+ declare function queryLogCommand(): Command;
392
+
393
+ export { type ExecFn, type ExecResult, type SearchFn, type SearchMatch, type SearchResult, anonymizeCommand, buildCommand, catalogCommand, compareCommand, compareProfilesCommand, connectionCommand, costEstimateCommand, diagnoseCommand, driftCommand, execCommand, explorerCommand, extractCommand, graphCommand, historyCommand, impactCommand, initCommand, installHooksCommand, lineageCommand, prCommentCommand, publishCommand, queryLogCommand, revertCommand, reviewCommand, saferAlternativeCommand, safetyCommand, scaffoldCommand, scriptCommand, searchCommand, seedCommand, sketchCommand, templateCommand, validateCommand, verifyCommand };