# CAS Commands

Manage Composable Audience Studio (CAS) resources — zero-copy CDP audiences that run directly on customer Cloud Data Warehouses (Snowflake, Databricks, BigQuery) without moving data into Treasure AI.

## Commands

### Discovery

| Command | Description |
|  --- | --- |
| [`list`](#list) | List composable audiences |
| [`desc`](#desc) | Describe a composable audience |


### YAML Sync

| Command | Description |
|  --- | --- |
| [`pull`](#pull) | Pull audience + segments to YAML files |
| [`push`](#push) | Push YAML files to CAS API |


### Operations

| Command | Description |
|  --- | --- |
| [`preview`](#preview) | Preview composable segment query on CDW |
| [`sg list`](#sg-list) | List composable segments for an audience |


## Typical Usage


```bash
# 1. List composable audiences
tdx cas list

# 2. Pull audience and all segments to YAML files
tdx cas pull "Customer360 Snowflake"
# Creates: cas/customer360-snowflake.yml (audience)
#          cas/high-value-customers.yml (segment)
#          cas/Marketing/newsletter-subs.yml (segment in folder)

# 3. Edit YAML files locally

# 4. Push changes back to CAS API
tdx cas push ./cas/

# 5. Preview a segment query on the CDW
tdx cas preview "High-Value Customers" --audience "Customer360 Snowflake"
```

## Session Context

Set a default composable audience to avoid repeating the name:


```bash
tdx use cas "Customer360 Snowflake"

# Now these commands use the context:
tdx cas sg list           # Lists segments for "Customer360 Snowflake"
tdx cas desc              # Describes "Customer360 Snowflake"
tdx cas pull              # Pulls "Customer360 Snowflake"
```

## How It Works

**Composable Audiences** define customer profiles from tables in your own data warehouse. Unlike Complete CDP audiences (which copy data into Treasure AI), composable audiences query your CDW directly — zero data movement.

Each composable audience has:

- A **master table** (the primary customer table in your CDW)
- **Attributes** (additional columns joined from other tables)
- **Behaviors** (time-series event tables for behavioral segmentation)
- **Segments** (filtered subsets using rules/conditions)
- **Activations** (exports from segments to external systems)


## YAML Format

### Audience YAML


```yaml
name: Customer360 Snowflake
description: Customer data from Snowflake
timezone: America/New_York
master:
  connection: my-snowflake-connection
  schema: customer_data
  table: customers
  key_column: cdp_customer_id
attributes:
  - name: email_info
    connection: my-snowflake-connection
    schema: customer_data
    table: customers
    join:
      table_key: cdp_customer_id
      master_key: cdp_customer_id
    columns:
      - name: email
        type: string
        column: email_address
behaviors:
  - name: purchase_events
    connection: my-snowflake-connection
    schema: events
    table: purchase_history
    join:
      table_key: customer_id
      master_key: cdp_customer_id
    time_column: event_timestamp
    columns:
      - name: product_id
        type: string
        column: product_sku
      - name: amount
        type: number
        column: purchase_amount
```

### Segment YAML


```yaml
type: composable_segment
name: High-Value Customers
description: Customers with > $1000 in purchases
folder: Marketing/Campaigns
rule:
  type: And
  conditions:
    - type: Behavior
      behavior: purchase_events
      aggregation: Sum
      column: amount
      operator: GreaterThanOrEqual
      value: 1000
activations:
  - name: Export to Marketing
    connection: salesforce-connection
    connector_config:
      object: Contact
    columns:
      - name: email
        type: string
    schedule:
      type: daily
      timezone: UTC
```

## Command Reference

### list

List all composable audiences.


```bash
tdx cas list [options]
```

| Option | Description |
|  --- | --- |
| `--json` | Output as JSON |
| `--jsonl` | Output as JSON Lines |


### desc

Describe a composable audience showing master table, attributes, and behaviors.


```bash
tdx cas desc [name]
```

Uses session context if `name` is omitted (set via `tdx use cas` or `tdx cas pull`).

### pull

Pull a composable audience and all its segments/activations to local YAML files.


```bash
tdx cas pull [name] [options]
```

| Option | Description |
|  --- | --- |
| `--dir <dir>` | Target directory for YAML files (default: `./cas/<audience-name>/`) |
| `--dry-run` | Show what would be done without writing files |


Uses session context if `name` is omitted. Also sets `composable_audience` context for subsequent commands.

The pull command shows diffs for changed files and prompts for confirmation before writing.

### push

Push local YAML files to the CAS API.


```bash
tdx cas push [target] [options]
```

| Option | Description |
|  --- | --- |
| `--dry-run` | Show what would be done without making changes |


`target` can be a file or directory. If omitted, pushes from the current directory. Audience files are pushed first, then segments and activations.

### preview

Preview a composable segment query by running it on the CDW.


```bash
tdx cas preview <segment_name> [options]
```

| Option | Description |
|  --- | --- |
| `--audience <name>` | Composable audience name (or use session context) |


### sg list

List composable segments for an audience.


```bash
tdx cas sg list [audience_name]
```

If `audience_name` is omitted, uses the session context set by `tdx use cas`.

## CAS vs Complete CDP

| Aspect | Complete (`tdx ps` / `tdx sg`) | Composable (`tdx cas`) |
|  --- | --- | --- |
| Data location | TD PlazmaDB | Customer's Snowflake/Databricks/BigQuery |
| Source reference | `database` + `table` | `connection` + `schema` + `table` |
| Query engine | Presto/Trino on TD | Direct SQL on CDW |
| Activations | `syndications` with `connectionId` | `composable_activations` with CDW-specific export |
| API prefix | `/audiences/`, `/entities/segments/` | `/composable_audiences/`, `/entities/composable_segments/` |