# TerminalSession and LocalTerminalSession

> For the complete documentation index, see [llms.txt](https://docs-stg.ringleader.dev/llms.txt).


> A TerminalSession is a named set of shells on one workstation that keep running while nothing is attached, and a LocalTerminalSession is the same on your own computer.


A **TerminalSession** is a named set of shells, called panes, on one workstation that keep
running while nothing is attached. A **LocalTerminalSession** is the same thing on the computer
you are using, with fewer fields. This page lists the fields of both kinds.
[Terminal sessions](https://docs-stg.ringleader.dev/workstations/sessions/terminal-sessions/) explains how a
session works and how to use one.

Both kinds are in the `workstations.ringleader.dev/v1` API group, and both belong to the person
who creates them. A member manages their own sessions, and an administrator of the namespace
manages all of the namespace's sessions.

## Minimal example

```yaml
apiVersion: workstations.ringleader.dev/v1
kind: TerminalSession
metadata:
  name: my-shells
  namespace: acme-dev
spec:
  workstationRef: {name: my-box}
  panes:
    - name: main
```

A session that sets every field:

```yaml
apiVersion: workstations.ringleader.dev/v1
kind: TerminalSession
metadata:
  name: fix
  namespace: acme-dev
spec:
  workstationRef: {name: my-box}
  panes:
    - name: main
    - name: tests
      command: "go test ./... -run Foo"
  worktreeSetRef: {name: tls-floor}   # or directory: src/app, never both
  initialSize: {cols: 200, rows: 50}
  recording: box
  recordingRetention: 7d
```

Apply a file with `rl apply -f`, or create a session with
[`rl terminalsession create`](https://docs-stg.ringleader.dev/reference/cli/commands/terminal-sessions/#rl-terminalsession-create-name).
Unknown fields are rejected.

## Spec fields

| Field | Type | Description |
|-------|------|-------------|
| `workstationRef` | `object` | **Required.** `{name}`: the workstation, in the session's namespace, that runs the panes. |
| `panes` | `[]object` | **Required.** At least one pane, in the order the session shows them. See [Pane fields](#pane-fields). |
| `directory` | `string` | Where the panes start. An absolute path, or one relative to the login user's home. It has no `~` and no `..`. Ringleader does not create it. It cannot change after you create the session. Not allowed with `worktreeSetRef`. |
| `worktreeSetRef` | `object` | `{name}`: a [WorktreeSet](https://docs-stg.ringleader.dev/reference/resources/worktreeset/) in the same namespace, on the same workstation, that you own. The panes start in the set's first tree. It cannot change after you create the session. Not allowed with `directory`. |
| `initialSize` | `object` | `{cols, rows}`: the size the window opens at. Each is a whole number from 2 to 1000. Default `80` by `24`, widening when a wider client attaches. You can change it on any write. |
| `recording` | `string` | `off` or `box`. `box` keeps a record of each pane's output on the workstation. Default `off`. Only the owner can turn it on. |
| `recordingRetention` | `string` | How long Ringleader keeps a record after you delete the session or close the pane, such as `7d` or `72h`. More than zero and at most 30 days. Default 30 days. |

### Pane fields

| Field | Type | Description |
|-------|------|-------------|
| `name` | `string` | **Required.** A lowercase label of up to 63 characters, made of letters, digits and `-`, starting and ending with a letter or digit. Unique in the session. |
| `command` | `string` | A command for the pane's login shell to run, as `<login shell> -l -c <command>`, in place of an interactive shell. Up to 4096 bytes of UTF-8, with no NUL. The pane closes when the command exits. You cannot change it: close the pane and add it again. |

## Status fields

The workstation reports these. They are read-only.

| Field | Type | Description |
|-------|------|-------------|
| `phase` | `string` | `Pending`, `Running`, `Stopped` or `Failed`. See [Phases](#phases). |
| `message` | `string` | A sentence that says what the session waits for, or why it failed. |
| `reason` | `string` | A one-word cause. A `Stopped` session with reason `WorkstationRemoved` or `LeaseEnded` never restarts. |
| `workstation` | `string` | The workstation the session runs on. |
| `server` | `object` | The session's terminal server: its process id, start time, `build`, `desiredBuild` and `restarts`. |
| `panes` | `[]object` | Each pane's `name`, its `id`, whether it has `exited`, and its `recording` as `{state, reason}`. |
| `worktree` | `object` | `{path, branch}`: the first tree of the session's worktree set. |
| `worktreeSet` | `string` | Why the session waits for its worktree set, while it does. |
| `directoryMissing` | `bool` | The `directory` is missing or the login user cannot enter it. New panes start in the home directory. |
| `outdatedLibraries` | `[]string` | Present when a package update replaced a library that a pane's process still uses. Restart that process. |

A TerminalSession reports no `conditions` list. `rl terminalsession get` prints these columns:
`NAME`, `WORKSTATION`, `PHASE`, `PANES`, `BUILD` and `AGE`, plus `NAMESPACE`, `OWNER` and `ORIGINS`
where they apply. `PANES` reads `3`, `3 (1 exited)` or `3 (1 exited, outdated libraries)`. `BUILD`
shows the running build, and `(current X)` after it when the deployment's current build differs.

## Phases

| Phase | Meaning |
|-------|---------|
| `Pending` | The workstation has not yet reported the session's server or panes. `status.message` says what it waits for. |
| `Running` | The server and the panes run. |
| `Stopped` | The workstation is not running. With reason `WorkstationRemoved` or `LeaseEnded`, the session rests for good and never restarts. |
| `Failed` | The workstation cannot run the server. `status.message` says why. |

A `Pending` session's message is one of these:

- `Waiting for <workstation> to report its phase.`
- `Waiting for <workstation>, which is <phase>.`
- `Waiting for the agent on <workstation> to be updated: it does not run terminal sessions.`
  Other messages of this form name the part the agent cannot do yet, such as a directory, a worktree
  set or a pane's command.
- `Starting this session's server on <workstation>.`
- `Starting this session's panes on <workstation>.`
- `This session's server on <workstation> is not answering.`

`rl terminalsession wait --for Running` returns once the session is running.

## Refusals

Ringleader checks a session when you create or apply it, and rejects it with a message that names
the field. These are the ones you are most likely to meet:

| Message | Fix |
|---------|-----|
| `spec.panes[0].name: must be a lowercase RFC 1123 label of at most 63 characters ...` | Rename the pane. |
| `spec.panes[2].name: repeats the pane name "x"` | Give each pane its own name. |
| `spec.panes[2].command: is empty. Give the command the pane's shell runs, or leave the key out for an interactive shell.` | Write the command, or remove the key. |
| `spec.directory: is "../x", which has a '..' component. Name the directory without one.` | Write the directory without `..`. |
| `spec.worktreeSetRef: cannot be set beside spec.directory.` | Name a worktree set, or a directory, not both. |
| `spec.recordingRetention: is "90d", and must be a duration above zero and at most 30 days ...` | Use a duration up to 30 days, or remove the key. |
| `spec.recording: "cloud" is not one of the allowed values: off, box` | Write `off` or `box`. |
| `spec.initialSize.rows: must be >= 2` | Give each number from 2 to 1000. |

The workstation must exist, and a named worktree set must exist on that workstation and belong to
you, or Ringleader rejects the session. The fields `source`, `sources` and `worktreeDir` are no
longer session fields. Name a worktree set in `spec.worktreeSetRef`, or a directory in
`spec.directory`.

## LocalTerminalSession

A LocalTerminalSession runs on the computer you are using, and that computer's daemon runs it.
It lives in the `local` namespace, and creating one in another namespace is rejected with a
message that names `-n local`. Signing in never copies it to a control plane, and it works while
you are signed out.

```yaml
apiVersion: workstations.ringleader.dev/v1
kind: LocalTerminalSession
metadata:
  name: scratch
  namespace: local
spec:
  panes:
    - name: main
    - name: logs
      command: "tail -f /var/log/system.log"
  directory: src/app
  initialSize: {cols: 120, rows: 40}
```

Its spec holds `panes`, `directory` and `initialSize`, which mean what they do above. Every other
TerminalSession field is rejected as unknown: `workstationRef`, `worktreeSetRef`, `recording` and
`recordingRetention`. Its status keeps `phase`, `message`, `server`, `panes` and
`directoryMissing`, and adds `startingPanes`.

A local session has no recording, no worktree set, no sharing and no console view. A file dropped
on one of its panes is refused with `a pane on this computer takes no dropped file yet`. No grant
can name one.

`rl localterminalsession create` writes a session with a name and no panes, and `-o yaml` prints
that file for you to complete. Write a full session in a file and apply it with `rl apply -f`.
[`rl localterminalsession`](https://docs-stg.ringleader.dev/reference/cli/commands/terminal-sessions/#rl-localterminalsession)
lists the commands.

## Next steps

- [Terminal sessions](https://docs-stg.ringleader.dev/workstations/sessions/terminal-sessions/): how a session
  works, who can open it and what recording keeps.
- [Worktree sets](https://docs-stg.ringleader.dev/workstations/sessions/worktree-sets/): the trees a session can
  start in.
- [WorktreeSet](https://docs-stg.ringleader.dev/reference/resources/worktreeset/): the fields of a set.
- [Terminal session and worktree set commands](https://docs-stg.ringleader.dev/reference/cli/commands/terminal-sessions/):
  every command and flag.
- [Grant](https://docs-stg.ringleader.dev/reference/resources/grant/): sharing a session.
- [Workstation](https://docs-stg.ringleader.dev/reference/resources/workstation/): the workstation a session runs on.

