# SDK Studio's work from the command line

Every pane of [SDK Studio](studio.md) has `sona` commands that do the same work, so a script, a build
server or an agent can do without the window whatever a person does in it. Output, `--json` and exit codes are as in
[The sona command-line tool](cli.md).

| Studio | sona |
|---|---|
| Consoles and Apps: your app, origins, the SDK Licence, downloads, builds, usage | `sona app show`, `app origins`, `app licence`, `app download`, `app builds`, `app revoke`, `app usage` |
| Consoles and Apps: the avatar items stored on a console | `sona console list <Content folder>` |
| Wardrobe: search, filters, previews | `sona catalogue search`, `--filter`, `sona item preview` |
| Wardrobe: Add custom item (v1 and v2) | `sona item check`, `item unpack`, `item pack`, `item mesh` |
| Avatar builder: dress, colours, shape, clips, camera, the console check | `sona avatar dress / colour / shape / body / ready / validate`, `sona render --clip --camera --yaw` |
| Avatar builder: Copy manifest, Export PNG, Export GLB | `sona avatar show`, `manifest unpack`, `sona render`, `sona export glb` |
| Scene: 1 to 10,000 avatars, timed | `sona scene` |
| Projects: templates, New project, the list | `sona project templates`, `project new`, `project list`, and `project build`, `project run` as an agent's |
| Docs, offline | `sona docs list`, `docs search`, `docs show` |
| Log | `--verbose` (the SDK's log lines), `--json` (`notes`) |
| Agents (MCP) | `sona mcp` (as sona-mcp: stdio, `--http <port>`) |

## app

```text
sona app request  --name <app name> --contact <e-mail> --about <text> --agree "I have read and understand the Developer Terms"
                  --app-key-file <file> [--wants lookup|signin] [--redirect <url>] [--force]
sona app show     --app <id> [--app-key-file <file>] [--server <url>]
sona app origins  [list | add <origin>... | remove <origin>... | set <origin>...]
sona app licence  --agree "I have read and understand the SDK Licence"
sona app download <platform> [-o file.zip] [--unpack <folder>] [--with-catalogue] [--force]
sona app tools    <platform> [-o file]
sona app builds
sona app revoke   <build id>
sona app usage
```

Your app on the 360sona server, by the app's key, through the developer API (`/sona/v1/apps/{id}/...`). The key is
read from `--app-key-file`, `$SONA_APP_KEY`, or the file `$SONA_APP_KEY_FILE` names, never from the command line, where
other users could see it. The server is `--server`, `$SONA_SERVER`, or `https://test.360sona.com`; the app id `--app` or
`$SONA_APP`.

- **request** asks for an app id (`POST /sona/v1/requests`). Every app is approved at once, with every scope it
  asks for: the id is printed and the key, shown once, goes into `--app-key-file` (or `$SONA_APP_KEY_FILE`) and is
  never printed. A new app's limits grow with its age (100 players the first week, 1,000 the first month). A name
  too close to 360sona, Xbox or Microsoft, or taken, is refused (exit 1, with why). A missing value is exit 2
  naming the flag.
- **show** prints the app's settings as the server keeps them (JSON `settings`).
- **origins** lists them, or adds, removes or sets them and prints the list the server kept. An origin is
  `https://host[:port]`, or `http://localhost[:port]` while you test.
- **licence** accepts the SDK Licence; the server records the app and the time (JSON `accepted_at`). Without
  `--agree` it accepts nothing, prints where to read it (`<server>/devterms.html#sdk-licence`) and the sentence to
  type, and exits 2.
- **download** saves the SDK made for your app (`web`, or a native platform: `windows-x64`, `linux-x64`,
  `linux-arm64`, `macos`, `ios`, `android`, `xbox360`, `unity`, `unreal`, `godot`), by default to
  `360sona-sdk-<platform>.zip`. JSON: `file`, `bytes`, `sha256`, the zip's `files`, and its `licence` (with the new
  `build` id). `--with-catalogue` adds the offline catalogue to a native download. `--unpack <folder>` writes the
  files into the folder instead (no unzip needed; an earlier unpack is replaced only with `--force`); set `SONA_SDK`
  to it and the installed tools use its licence, catalogue and `bin/sona`.
- **tools** saves the tools installer for `windows-x64`, `linux-x64` or `macos` and checks it against the SHA-256
  the server lists.
- **builds** lists every native build (id, platform, version, made, checks, revoked); **revoke** turns one off.
- **usage**: today's items and answers against the allowance.

A server whose certificate is not trusted is refused (exit 3) before the key is sent. On Linux and macOS
`$SONA_CA_FILE` names a PEM file of the certificate authorities to trust instead of the system's bundle (as `curl --cacert`; a libcurl built with a default CA path, as on Debian and Ubuntu, still trusts that path too);
on Windows https uses the Windows certificate store and `$SONA_CA_FILE` is refused.

A refused key exits 6; an answer of no from the server (a bad origin, a revoked build) exits 1; no answer at all
exits 3.

## console

`sona console list <Content folder>` reads the avatar item packages of a console's Content folder
(`Content/<profile>/<title>/00009000/`): each item's id, the package's name (and the catalogue's, with `--catalogue`),
profile, title, size and kind (`CON` made on a console, `LIVE` from Xbox Live). The same folder is a source of items
for the Studio (`console:<folder>`).

## item mesh, and v2 items in check, unpack and pack

```text
sona item mesh <file.glb> --template <id or name> --name <text> [--body ...] [--fit template|none] [--id <id>]
               [--version n] [--description t] [--creator t] [--created yyyy-mm-dd] [--item-licence t]
               [-o file] [--no-sign] [--key file] --dir <folder with avatar-rig.json>
```

`item mesh` is `sona-item mesh` ([custom items: your own mesh](custom-items.md#your-own-mesh-format-11)): your own skinned glb as a format 1.1
item, checked (rule 13) and packed by the core's `sona_custom_item_pack_mesh`, then signed with your creator key as
`item pack` signs. The item's licence text is `--item-licence` here (`--licence` is the SDK licence file). With the
same inputs it writes the same bytes as the node tool. `item check` reports a v2 item's `mesh` (`fit`, `primitives`,
`bytes`; `null` for v1), `item unpack` writes its glb as `mesh.glb` and names it in `item.json`'s `mesh.glb`, and
`item pack` packs such a folder back to the same bytes.

## scene

```text
sona scene [--count n] [--outfits starters|random] [--frames n] [--size WxH] [--clip key] [--seed n] [-o shot.png]
```

The Scene pane on a headless device: `--count` avatars (1 to 10,000, default 100) in the web benchmark's grid, the
four starters in turn or, with `--outfits random`, each dressed by `sona_make_random` from the catalogue with items the
`--dir` folders hold. It waits until every avatar is ready, fits the camera to the crowd, then times `--frames` frames
(default 60): `sona_update`, and one draw read back the way `sona_snapshot` reads it. JSON: `ready`, `ready_ms`,
`update_ms_mean` and `_max`, `draw_readback_ms_mean` and `_max`, `drawn`, `culled`, `draw_calls`, `gpu_mb`, `cpu_mb`;
`-o` saves the last frame. The read-back is part of each timed draw, so for the GPU time of a game's frame use
`sona-bench`.

## project

```text
sona project templates
sona project list  [--projects <folder>]
sona project new   <dir> [--template t] [--name n] [--avatar <avatar>] [--sdk-include dir --sdk-library file]
sona project build <dir> [--jobs n] [--sdk-include dir --sdk-library file]
sona project run   <dir> [-- <args>...]
```

The templates of the Studio's Projects pane and of an agent's `project_create` (`cpp-starter` and the rest of the
toolkit's). `new` writes the project with the avatar (default the starter) and your licence file; `build` configures
and builds it with CMake (log `.sona/build.log`); `run` runs it and reads its frame stats and screenshot from
`.sona/run.log`. `<dir>` may be relative (`sona project new kart`, then `sona project build kart` from the same
folder); it is made absolute before CMake and the program run in it. `list` defaults to the Studio's Projects folder (`~/360sona Projects`, on Windows
`Documents\360sona Projects`).

## docs

`sona docs list`, `sona docs search <words...>` (every line with all the words, any case) and `sona docs show <page>`
read the SDK's Markdown pages: `--docs`, `$SONA_DOCS`, or the `share/360sona/docs` an install puts beside `sona`.

## mcp

`sona mcp` is the SDK's MCP server ([sona-mcp](mcp.md)) in the CLI: stdio, or `--http <port>` (add `--stdio` for both),
with `--root`, `--allow-write`, `--allow-writes-anywhere`, `--allow-exec`, `--port-file`, `--token-file`, `--samples`
and the global `--dir`, `--gate`, `--licence`, `--catalogue`, `--filter`. It is built when the toolkit is (cJSON and
CivetWeb fetched); `app`, `console`, `project` and `docs` need it too and answer exit 5 without it.
