Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .claude/skills/cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ For parent commands with subcommands, use `noop` from `@spotify-confidence/share

- **Standalone** — `login`, `logout`, `whoami`, `config`, `update` — directly perform their action
- **API commands** — `flags`, `events`, `recordings`, `docs`, `warehouse` — CRUD operations against Confidence APIs via each feature's `features/<x>/api.ts` client (`@network/*` holds only the shared HTTP client and config)
- **Data commands** — `data fact-tables|dimension-tables|entities|sql`, plus `warehouse list|get` — call the Metrics REST API directly (see below)
- **Integration** — `mcp`, `plugin`, `sdk`, `migrate` — manage IDE tooling and SDK setup
- **Setup** — `flags setup`, `events setup`, `recordings setup` — delegate to quickstart TUI with pre-selected features
- **TUI launcher** — `quickstart` — launches the full interactive wizard
Expand All @@ -51,6 +52,26 @@ All structured output goes through `src/output/`:

Commands never call `JSON.stringify` directly.

## Data Commands

`features/data/` holds the Metrics API resource client the data commands share:

- **`api.ts`** — `send()`, one authenticated request to the token's regional Metrics API. Redirects are refused, so a write is never replayed or sent elsewhere.
- **`resources.ts`** — resource types, name validation, list paging (`--all` follows page tokens up to 1000 pages and fails on a repeated token), and gets that check the response names the requested resource.
- **`operations.ts`** — each command builds one `DataOperation`: the request it sends first, `local` options that change how the CLI runs it (such as `--all`), whether the result is a list, and `run`. Creates go through `sendOnce`: only a 4xx counts as rejected; after a 5xx, dropped connection or unreadable response the outcome is unknown, so the CLI says so and names the command to check instead of retrying.
- **`request.ts`** — `executeDataRequest(argv, build)` validates input by building the operation, then either prints `{ request, local }` for `--dry-run` (no login, nothing sent) or runs it. Every failure prints through `printApiError`, which redacts tokens.

`warehouse list|get` live in `features/warehouse/data-warehouses.ts` on the same client.

Rules the data commands keep:

- Never print warehouse secrets: configs are reduced to an allowlist of public fields, since the API marks secrets `INPUT_ONLY` but the CLI should not rely on that.
- Never fetch or print SQL sample rows, which can hold customer data. `sql schema` reads the job itself, so it also works after the result table expires.
- Reject `skipSqlPreview: true` on table creates, so the service always validates the SQL. `skipSqlPreview: false` (as returned by `get`) is accepted.
- Protobuf JSON leaves out default enum values and empty repeated fields, so a missing list is empty and a missing job state is `STATE_UNSPECIFIED`.

Tests mock the Metrics API with `metricsReturns`, `metricsFails` and `metricsRequests` from `@spotify-confidence/testing`.

## Quickstart Integration

`launchQuickstart()` in `src/features/quickstart/launch.ts` maps feature names to goal IDs (`flags` → `feature-flags`, etc.), dynamically imports `startTui` from `@spotify-confidence/quickstart`, and passes through CLI options.
Expand Down
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ shared-kernel (shared leaf)
### packages/cli/ structure

- **`bin/cli.ts`** — Entry point (yargs, `confidence` binary)
- **`src/commands/`** — Command definitions (login, logout, whoami, config, flags, events, recordings, docs, mcp, plugin, sdk, migrate, update, quickstart, warehouse) + shared yargs `options.ts`
- **`src/features/`** — Feature implementations (docs, events, flags, ide, mcp, migrate, plugin, quickstart, recordings, sdk, update, warehouse). Each API-backed feature owns its client in `features/<x>/api.ts`
- **`src/commands/`** — Command definitions (login, logout, whoami, config, flags, events, recordings, docs, mcp, plugin, sdk, migrate, update, quickstart, warehouse, data) + shared yargs `options.ts`
- **`src/features/`** — Feature implementations (docs, events, flags, ide, mcp, migrate, plugin, quickstart, recordings, sdk, update, warehouse, data). Each API-backed feature owns its client in `features/<x>/api.ts`
- **`src/input/`** — Input parsing (file reading, aliases, resolve)
- **`src/output/`** — Output formatters (json, table, format detection)
- **`src/network/`** — Shared HTTP client and API config only
Expand Down
52 changes: 44 additions & 8 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,50 @@ confidence quickstart # Launch the interactive setup wizard

### Data Warehouses

| Command | Description |
| ---------------------------------------------------- | -------------------------------------------------- |
| `confidence warehouse validate` | Validate warehouse configuration |
| `confidence warehouse create` | Create a data warehouse connection |
| `confidence warehouse connector create-flag-applied` | Create flag assignment data connector |
| `confidence warehouse connector create-event` | Create event data connector |
| `confidence warehouse assignment-table create` | Create an assignment table for experiment analysis |
| `confidence warehouse crypto-key create` | Create a crypto key (Snowflake) |
| Command | Description |
| ----------------------------------------------------- | -------------------------------------------------- |
| `confidence warehouse list` | List data warehouse connections |
| `confidence warehouse get --name dataWarehouses/<id>` | Get a data warehouse connection |
| `confidence warehouse validate` | Validate warehouse configuration |
| `confidence warehouse create` | Create a data warehouse connection |
| `confidence warehouse connector create-flag-applied` | Create flag assignment data connector |
| `confidence warehouse connector create-event` | Create event data connector |
| `confidence warehouse assignment-table create` | Create an assignment table for experiment analysis |
| `confidence warehouse crypto-key create` | Create a crypto key (Snowflake) |

### Data

Data commands, and `warehouse list` / `warehouse get`, call the regional Metrics API directly with your credentials (or `--profile`). They don't need an MCP server.

| Command | Description |
| ------------------------------------------------------------- | ------------------------------------------------- |
| `confidence data fact-tables list\|get\|create` | List, get, or create fact tables |
| `confidence data dimension-tables list\|get\|create` | List, get, or create dimension tables |
| `confidence data entities list\|get` | List or get entities |
| `confidence data sql preview --from-file query.json [--wait]` | Start a preview query (may incur warehouse costs) |
| `confidence data sql status\|schema --name sqlJobs/<id>` | Inspect a SQL job, or only its schema and issues |

```bash
confidence data fact-tables list --filter 'displayName:purchases' --json
confidence data fact-tables get --name factTables/purchases
confidence data fact-tables create --from-file fact.json --id purchases --dry-run
confidence data sql preview --from-file query.json --wait --timeout 60
```

Every data command follows the same rules:

- **Names**: `get`, `status` and `schema` take a qualified `--name <collection>/<id>`, and fail if the response names a different resource.
- **Lists**: one page by default, with `--page-size` (1–1000) and `--page-token`. `--all` follows every page, up to 1000 pages, and fails on a repeated token rather than printing partial results. Fact and dimension tables also take `--filter`, `--order-by` and `--show-deleted`.
- **Create**: `--from-file` holds the resource itself as proto JSON (not a wrapper). The service validates it and the CLI prints its errors. `--id` picks the ID; otherwise the service generates one. The write is sent exactly once. If the connection drops, the server fails with a 5xx, or the response can't be read, the outcome is unknown: the CLI says so and tells you what to check before retrying.
- **`--dry-run`** prints the exact request (method, path, params, body) and any CLI-side options such as `--all` after validating local input. It authenticates nothing and sends no API request.
- **Output**: `--json` keeps the full response, including state and errors. A resource in a failed state still exits 0; inspect its `state`.

Things the CLI deliberately never does:

- `warehouse get` / `list` never print secrets (for example a Databricks `clientSecret` or Redshift `secretAccessKey`), even if the server returns them.
- `sql schema` never fetches or prints sample rows. It reads the job's result schema and issues only.
- `fact-tables create` rejects `skipSqlPreview: true`, so the service always validates the SQL.
- `sql preview` input is only `{ "query": "..." }`. Preview is never retried, and a timed-out `--wait` doesn't cancel the job; use `sql status`.

### SDK

Expand Down
Loading