# Commands and coding agents

Everything the dashboard does is also a command, so a script or a coding agent can run SuperCI without a browser. A command fills in the same form its page has and runs the same code, so the two never differ.

Commands have one shape, the Stripe CLI's:

```sh
superci <resource> <operation> [id] [--param=value]
```

The operations are `list`, `retrieve`, `create`, `update` and `delete` wherever they fit.

```sh
npx @superci/cli            # lists the commands
npx @superci/cli status
```

`superci help RESOURCE` (or `superci RESOURCE --help`) says more about one. The dashboard itself is `superci dashboard`.

## Signing in

A person signs in once, in the browser. SuperCI keeps that sign-in in its own folder (`~/.superci`), and commands use it from then on. If you look after several CIs from one computer, each has its own sign-ins: see [Workspaces](/docs/workspaces).

```sh
superci login            # any cloud; the first screen asks which
superci login aws        # or cloudflare, modal
superci logout           # removes the sign-ins from this computer
```

SuperCI reads no other tool's credentials: no AWS profile, no wrangler or Modal login. An AWS sign-in ends after twelve hours at most, as AWS has it. Looking goes on working after that; a change in AWS asks for the sign-in again.

## For a coding agent

- Add `--json` to any command: one JSON object with what was done or read.
- Add `--dry-run` to a change: it checks the flags, the sign-in and the control plane, and says what it would do.
- A command never asks a question. What it would delete needs `--confirm`.
- When a person is needed first, the answer says so and the status is 3:

```json
{ "ok": false, "error": "SuperCI's AWS sign-in has ended…", "needs": "superci login aws" }
```

Statuses: 0 done, 1 failed, 2 not a command or not a whole one, 3 a person is needed first.

## Read keys and run keys

A coding agent on your own machine uses SuperCI's sign-ins, and can do everything you can. To let one look and change nothing, or to let it run on another machine, give it a read key instead:

```sh
superci keys create agent          # shows the key once
SUPERCI_PLANE=https://… SUPERCI_KEY=superci_read_… superci jobs list --json
```

With those two set, whatever looks works with no sign-in. `superci keys create agent --runs` makes a run key: it may also start [runs from a computer](/docs/runs-from-a-computer) and fetch their artifacts, within your control plane's limits, and changes nothing else. Your control plane keeps only the key's SHA-256. A key ends by itself after 30 days (`--days` for another length), or at once with `superci keys delete agent`. `superci keys list` also lists each device that looks after your CI with its own device key (its dashboard and commands), which `superci keys delete DEVICE_KEY_…` takes out.

## What needs a person

Three things always need a person, once: the first sign-in to each cloud, creating the GitHub App and choosing its repositories (GitHub offers that only on its own pages; `superci connections create github OWNER` opens them), and making a GitLab token.

## Jobs

```sh
superci jobs list
superci usage retrieve --period=week             # jobs, machine minutes, cost, and what GitHub or GitLab would have charged
superci jobs retrieve 113201388423              # one job: how its start went, step by step, and the end of its log
superci jobs retrieve 113201388423 --out=job.log   # its whole log into a file, whatever its size
superci runs list                               # a workflow's jobs together: the run's time, cost, the job it waited for
superci runs retrieve 38420120788               # one run with its jobs
superci runs retrieve 38420120788 --tests       # and each job's tests, read from its whole log, passed or failed
superci runs create --workflow=.github/workflows/ci.yml   # runs it from this computer, nothing pushed
superci runs create --workflow=.github/workflows/ci.yml --quiet    # each step's result, and the end of one that failed
superci runs create --workflow=.github/workflows/ci.yml --detach   # its id, and back at once
superci runs wait ID                            # follows it to its end
superci artifacts list --run=ID                 # what its jobs kept with upload-artifact
superci artifacts retrieve coverage --run=ID    # unpacked into ./coverage
```

A run's time is from its first job queued to its last one over. Only the jobs SuperCI ran are counted.

## Control plane

```sh
superci status
superci planes list
superci planes create aws --region=us-east-1    # or: cloudflare, modal; --account=ID if several are signed in
superci planes update                           # to this program's version
superci planes move ID
superci planes allow                            # gives its AWS role what this version asks for
superci planes delete ID --confirm              # one that is not in use
superci leave --confirm                         # stops SuperCI and deletes what it made
superci leave --plane=ID --confirm              # stops one control plane; the others go on
superci status --plane=ID                       # any command: stops if it would act on another one
```

## Runners

```sh
superci runners list
superci runners create aws --region=us-east-1   # or: cloudflare, modal; --account=ID if several are signed in
superci runners create modal --account=WORKSPACE --name=modal-staging   # a further account: see Several accounts
superci runners order aws aws-on-demand cloudflare
superci runners update aws --max-jobs=20 --monthly-usd=500 --regions=us-east-1,us-east-2
superci runners update aws-on-demand --enabled=false
superci runners update cloudflare --location=weur
superci runners delete modal --confirm
superci labels list                             # what workflows may name in runs-on
superci labels create acmeci                    # `runs-on: acmeci` works too; `superci` keeps working
superci labels delete superci --confirm
superci name update AcmeCI                      # what it is called in the dashboard and on GitHub
superci machine retrieve                        # what `runs-on: superci` alone gets
superci machine update --cpu=4 --ram=16 --arch=arm64
superci machine update --spot=false --scratch=ramdisk   # every key a label has is a flag here
superci machine update --image=ubuntu26         # Ubuntu 26.04 for every job (unset: as ubuntu-latest)
superci machine update --disk-speed=default     # --KEY=default leaves one to each provider's standard again
superci limits retrieve
superci limits update --max-cpu=32 --max-hours=12   # the largest machine; the longest job
superci limits update --monthly-usd=500 --daily-usd=50   # the most everything may spend in a month, and in a day
```

## Cache

```sh
superci caches retrieve                         # whether it is on, and what each repository keeps
superci caches update --size-gb=50 --days=14
superci caches list --repo=acmeci/api
superci caches delete --repo=acmeci/api --confirm
```

## Cloud accounts

```sh
superci accounts list                           # the cloud accounts signed in to
superci accounts retrieve aws                   # what the AWS account allows: regions, spot, CPUs at once
superci accounts update aws --monthly-usd=300 --daily-usd=30   # its spot and on-demand machines together
superci accounts update modal-staging --monthly-usd=100         # any account, by its word
superci accounts update aws --aws-budget=emails --email=you@example.com   # AWS itself emails at 80% and 100%
superci accounts update aws --aws-budget=stops  # and refuses new machines at 100%; lift, none
superci images list                             # where the image jobs run on is, by region
superci images create eu-north-1                # copies it into a region that lacks it
superci images update eu-north-1                # a newer build, in place of your copy of an older one
superci images delete eu-north-1 --confirm
```

More on these: [What your AWS account allows](/docs/aws-accounts) and [Order and limits](/docs/order-and-limits).

More on what these mean: [Order and limits](/docs/order-and-limits), [Labels and machines](/docs/labels).

## Repositories

```sh
superci connections list
superci connections create github acme          # opens GitHub for a person
superci connections delete github other-org --confirm
superci deliveries list                         # what GitHub says it sent, for a job that never started
SUPERCI_GITLAB_TOKEN=… superci connections create gitlab --url=https://gitlab.com
superci projects list
superci projects update 123456 --enabled=true
superci public_repos create acme/site           # a public repository allowed to run here
```
