# Glass CLI reference and migration

This reference describes Glass CLI 0.28.1 on Linux and macOS with Python 3.11 or later.
Install Glass from your deployment toolkit and use its linked skill.
The [demo toolkit](https://demo.glass.bio/toolkit) links the installer, API address, and agent skill.
For dev, use the [dev toolkit](https://dev.glass.bio/toolkit).
For a worked example, read the [single-cell RNA-seq quickstart](https://glass.bio/docs/glass-cli/).
For agent setup, read the [Markdown install guide](https://glass.bio/install.md).

## Command map

The CLI has 34 leaf commands. Run `glass COMMAND --help` for flags and examples.

```text
glass
  astral
    get
    score
  auth
    login
    logout
    tokens
      create
      list
      revoke
  chat
    open
  cli
    status
  cohorts
    prepare
    aggregate
    score
    compare
    bundle
  datasets
    list
    get
    search
    values
      list
    clusters
      list
      search
      get
      compare
    upload
    subset
    merge
    delete
    annotations
      create
      get
    comparisons
      create
      get
  jobs
    list
    get
    wait
  update
```

`datasets search` searches catalog metadata. `datasets values list --field FIELD` lists live clinical filter values and counts.
Supported fields are `material`, `culture`, `disease-role`, `intervention`, `exposure`, and `intervention-time`.
`datasets clusters search` selects gene search or similarity search through explicit inputs.
`datasets clusters compare` compares one cluster with the atlas background through the existing similarity DGE service.
`datasets comparisons create` compares two selected populations and can start a job.
`chat open` opens interactive chat on deployments that support it.
`jobs list`, `jobs get JOB_ID`, and `jobs wait JOB_ID` retrieve job state.

`cohorts` exposes the existing donor workflows: preparation, raw-count aggregation, gene-set scoring, and unpaired donor comparison.
`cohorts bundle` packages supplied full comparison JSON and its inputs as an evidence ZIP.
It starts no biological analysis and does not retrieve a stored Analysis object.

## Commands and representations

`--representation` selects content. `--output` changes its destination only.

| Command                    | Representations                                         | Default      |
| -------------------------- | ------------------------------------------------------- | ------------ |
| `astral get`               | `table`, `manifest`                                     | `table`      |
| `datasets get`             | `metadata`, `h5ad`, `source_cell_map`, `input_grouping` | `metadata`   |
| `datasets clusters get`    | `inspection`, `gene_ranks`                              | `inspection` |
| `datasets annotations get` | `metadata`, `annotation_json`                           | `metadata`   |

`astral get --representation manifest` reads live columns, counts, versions, and limits.
`--schema` describes a command contract offline. It is not an Astral representation.
Parquet exports and evidence ZIPs require `--output FILE`.
Dataset artifacts can return a ready transfer or a preparation job without an output path.
With `--output`, a preparing artifact writes no file until ready. Use `--wait` to wait for preparation.

## JSON and file results

Noninteractive commands print one complete JSON envelope on stdout by default. `--json` remains accepted.
`--human` selects a terminal summary. `--verbose` prints HTTP traces to stderr.
Result commands accept `--output FILE`, including searches, clusters, cohorts, jobs, and `cli status`.
Login, interactive chat, and CLI update have separate lifecycle behavior.

For JSON, `--output` saves the complete success envelope and prints a small `json_file` receipt.
The receipt contains the file path, byte count, and SHA-256. Read the saved file for the result.
File inputs consume the saved result, not the stdout `json_file` receipt.
For binary exports, the file contains the artifact itself. Stdout contains its transfer receipt.
Atomic writes and integrity checks protect existing files. Failures leave the destination unchanged.

```sh
glass datasets search --query "lung fibrosis" --output catalog.json
glass datasets clusters search --genes CD3D CD3E CD3G TRAC IL7R --organism Homo_sapiens --output hits.json
glass datasets clusters get --from hits.json --rank 1 --representation gene_ranks --output ranks.json
glass datasets clusters compare --from hits.json --rank 1 --output atlas-comparison.json
glass astral get --representation manifest --organism human --output manifest.json
glass astral get --organism human --genes IL7R CD3D --output expression.parquet
```

Exit codes are 0 for success, 1 for API/job failure, 2 for invalid input, and 3 for required sign-in.
Code 4 means the wait deadline expired. Resume with `glass jobs wait JOB_ID`. Code 130 means interruption.
Errors remain JSON envelopes by default. Nonzero command results leave the destination unchanged.
Successful `jobs get` and `jobs list` commands can save failed or running job states.

## Typed input and offline schemas

These commands accept `--input FILE` or `--input -` and offline `--schema`:

- `auth tokens create`
- `datasets search`, `datasets values list`, `datasets get`, `datasets subset`, `datasets merge`
- `datasets clusters search`, `datasets clusters get`, `datasets clusters compare`
- `datasets annotations create`, `datasets annotations get`
- `datasets comparisons create`, `datasets comparisons get`
- `astral get`, `astral score`
- `cohorts prepare`, `cohorts aggregate`, `cohorts score`, `cohorts compare`, `cohorts bundle`

Other commands do not expose typed request contracts.
Input JSON contains the canonical request body without a response envelope.
Unknown fields, incorrect types, and competing data flags fail before HTTP.
`--output`, `--representation`, `--wait`, and `--idempotency-key` remain controls where supported.
Schemas describe the selected request, result, errors, and possible file or job receipts.

```sh
glass datasets clusters search --mode genes --schema
glass datasets clusters search --mode genes --input request.json --output hits.json
glass datasets clusters search --mode similarity --schema
glass astral get --representation manifest --schema
```

For gene mode, `request.json` can contain:

```json
{
  "genes": ["CD3D", "CD3E", "CD3G", "TRAC", "IL7R"],
  "organism": "Homo_sapiens",
  "limit": 10
}
```

Typed cluster search requires `--mode genes` or `--mode similarity`.
Gene mode uses `GeneSearchRequest`, with `limit` inside the body. It rejects a separate `--limit` with `--input`.
Similarity mode uses `ClusterSearchRequest`. Its `--limit` remains an HTTP query control outside the body.
Without a selector, offline cluster search schemas require `--mode`.
Flag requests use `--genes`, `--genes-file`, or `--similar-to`. These selectors are mutually exclusive and reject `--input`.
An explicit `--mode` must agree with the selector.

## Genes and exact references

`--genes VALUE...` always takes gene values. `--genes-file FILE` reads one gene per line. `--genes-file -` reads stdin.
These selectors are mutually exclusive on all four gene surfaces:

| Command                                             | Gene contract                                |
| --------------------------------------------------- | -------------------------------------------- |
| `astral get`                                        | Symbols or IDs; omit genes for metadata only |
| `datasets clusters search`                          | 5–50 symbols or canonical Ensembl IDs        |
| `datasets clusters get --representation gene_ranks` | 5–50 distinct canonical Ensembl IDs          |
| `cohorts prepare`                                   | Canonical gene IDs from the count axis       |

The CLI preserves server resolution rules. It does not convert symbols to IDs locally.
Saved gene-search hits supply matched IDs, the rank cutoff, and the index revision for `gene_ranks`.

`datasets clusters list DATASET_ID --version VERSION_ID --level LEVEL` returns exact `clusterRef` objects.
Save one complete object as `cluster.json` for `--cluster-ref` or `--similar-to`.
A `ClusterRef` contains `datasetId`, `versionId`, `level`, `clusterId`, and `groupingRevision`.
Use the returned values unchanged. Levels are `leiden`, `marble_cell_type`, `marble_refined_cell_type`, and `marble_user`.
Typed similarity uses its canonical query fields, including `expectedVersionId`, `expectedGroupingRevision`, and `expectedClusterId`.

Saved gene and similarity search envelopes support inspection with `--from hits.json --rank N`.
Subset uses `--from hits.json --ranks 1,2,5`. Cohort preparation uses repeated `--rank N`.
Indexed similarity hits resolve within their saved hosted version before inspection or selection.
Cluster comparison inspects the exact version before DGE. Its DGE route does not atomically pin the grouping revision.

`--references references.json` restricts similarity before ranking.
The file accepts an SRX array, an `allowedSrxAccessions` object, or a saved catalog result with both cursors null.
A partial catalog page fails. Use an explicit SRX array for deliberate selections from pages.
Search results describe bounded retrieval. They do not establish exhaustive atlas coverage.

`datasets comparisons create --group-a query.json --group-b reference.json` consumes arrays of exact cluster references.
Each group uses one dataset version. `datasets comparisons get --from comparison.json --output genes.parquet` retrieves the result.
Its input accepts a comparison receipt, successful job result, or exact `ComparisonResultRef`.
Typed dataset and annotation retrieval use an exact `DatasetRef` or `AnnotationRef`.

Read `atlasVersion` from `glass astral get --representation manifest --organism human`.
Replace `ATLAS_VERSION` with that value.
For donor workflows, prepare `cohort.json`, then supply the resolved manifest to aggregation:

```sh
glass cohorts prepare --from hits.json --rank 1 --genes-file gene-ids.txt --atlas-version ATLAS_VERSION --output cohort.json
glass cohorts aggregate --manifest cohort.json --output counts.json
glass cohorts score --counts counts.json --spec scoring.json --output scores.json
glass cohorts compare --cohort primary scores.json --spec contrasts.json --output results.json
glass cohorts bundle --from results.json --output evidence.zip
```

Inspect and resolve donor mappings before aggregation. The scoring and contrast files contain explicit statistical specifications.
Use the offline schemas for their exact fields.

## Login and profiles

Catalog and dataset commands require sign-in, including public dataset searches. Public Astral reads work without sign-in.
`glass auth login` opens a browser. For an agent, use `glass auth login --no-browser`.
Give the user the printed URL and code. Keep the login process alive until approval completes.
`GLASS_TOKEN` takes priority for commands that accept tokens. Keep credentials private.

Global flags work before or after command names:

```sh
glass --profile dev cli status
glass datasets search --profile dev --query lung
glass cli status --session-dir /path/to/session
glass --api-base https://dev.glass.bio/api/v1 cli status
```

Use either `--profile NAME` or `--session-dir PATH`. The selected directory supplies deployment configuration and saved login.
`--api-base` overrides the configured deployment URL.
Upload, annotation, subset, and merge commands can start paid jobs. Get user agreement before submission.
Dataset deletion requires explicit confirmation.

## Migration from older command trees

| Old syntax                                                    | Current syntax                                             |
| ------------------------------------------------------------- | ---------------------------------------------------------- |
| `glass search datasets`                                       | `glass datasets search`                                    |
| `glass search datasets --values FIELD`                        | `glass datasets values list --field FIELD`                 |
| `glass search genes genes.txt`                                | `glass datasets clusters search --genes-file genes.txt`    |
| `glass search similar --cluster-ref cluster.json`             | `glass datasets clusters search --similar-to cluster.json` |
| `glass datasets clusters get --representation similarity_dge` | `glass datasets clusters compare`                          |
| `glass analysis cohort`                                       | `glass cohorts prepare`                                    |
| `glass analysis aggregate`                                    | `glass cohorts aggregate`                                  |
| `glass analysis score`                                        | `glass cohorts score`                                      |
| `glass analysis compare`                                      | `glass cohorts compare`                                    |
| `glass analysis get`                                          | `glass cohorts bundle`                                     |
| `glass status`                                                | `glass cli status`                                         |
| `glass chat`                                                  | `glass chat open`                                          |
| File-valued `--genes genes.txt`                               | `--genes-file genes.txt`                                   |

For old similarity calls that used a dataset ID and cluster label, list clusters and save the matching exact `clusterRef` first.
Keep other required flags and references from the old command. Removed commands have no executable compatibility aliases.
`--genes INS GCG` now means two gene values, never file paths.
When saving JSON with `--output`, use the saved envelope in later commands. Do not redirect the receipt over that file.

Run `glass update` to update the selected deployment. Commands default to demo when no deployment is configured.
To replace an older installation that does not recognize `glass update`, use the installer:

```sh
curl -fsSL https://demo.glass.bio/api/scripts/install-glass.sh | bash -s -- --api-base https://demo.glass.bio/api/v1
```

For dev, replace both demo addresses with `dev.glass.bio`.
The installer preserves the standard launcher path and saves the selected deployment.
After installation, run `glass --version` and `glass cli status`.
