# al-control

al-control is the control room CLI: it shows what is in every bin, why workpieces failed, and starts and stops factory sessions, on this machine or on hosts you reach over SSH. It doesn't run stations. Install it with `npm install -g @assemblyline/al-control` (Node.js 18 or later, macOS or Linux). The same views, in a desktop app: [Watch lines in Control Room](/docs/guides/watch-lines-in-control-room).

```text
al-control <resource> <action> [options]
```

| Global option | What it does |
|---|---|
| `--host <name>` | Target this host for one command, instead of the current host |
| `-h`, `--help` | Show help; works after any command |
| `-v`, `--version` | Show the version |

## Where its lines come from

al-control reads a factory's lines and stations from `.factory/factory.json` in the factory's folder. The factory session writes that file when it starts (`startBinWatcher()`), from the definitions on the Orchestrator. So:

- **A factory shows no lines until its session has started once.** Until then `lines status` prints `No lines for factory-acme: .factory/factory.json is written when the factory session starts.`
- **It shows the definitions as of the session's last start.** After changing a line or station on the Orchestrator, restart the session to see the change.

The bins and workpieces it reads straight from disk, in `.factory/stations/`.

## Choosing the factory

Commands about one factory take `-f`, `--factory`:

| `-f` | Means |
|---|---|
| a name, such as `factory-acme` | A factory in the config, on the current host (or `--host`) |
| a path, such as `.`, `..`, `~/factories/factory-acme` or anything with a `/` | That folder. Needs no config. With `--host`, a path on that host. |

The current folder is used only when you pass `-f .`.

## Config

`~/.al/al-control/config.yml`; `AL_CONTROL_CONFIG_DIR` moves the folder.

```yaml
current_host: local
hosts:
  local:
    factories:
      factory-acme: ~/factories/factory-acme
  build-box:
    ssh: build-box                  # an alias from ~/.ssh/config
    node: /home/me/.nvm/versions/node/v22.21.0/bin/node   # when node and pm2 come from nvm
    factories:
      factory-acme:
        path: ~/factories/factory-acme
        keep: [IN5/output, IN5/done]    # bins workpieces clear never touches
```

- **`local`** is this machine. Any other host is reached with your own `ssh`, which needs key-based login. Nothing is installed on it: al-control pipes a read-only script to its `node`, and runs its `pm2`.
- **Factory paths** are paths on that host; `~` expands there.

## Hosts and factories

| Command | What it does | Options |
|---|---|---|
| `hosts list` | List the configured hosts | `--json` |
| `hosts use <name>` | Set the current host | |
| `hosts current` | Print the current host | |
| `factories list` | The factories configured on the current host, and whether each is running | `--json` |
| `config show` | Config path, current host, hosts and factories | |
| `completion` | Print a shell completion script: `al-control completion >> ~/.zshrc` | |

## Lines and stations

Each needs `-f`.

| Command | What it does | Options |
|---|---|---|
| `lines list` | Lines and their stations | `--json` |
| `lines show <line>` | A line's stations in dependency order, and its conveyors | `--json` |
| `lines status [line]` | Live bin counts; with no line, a summary per line | `--json`, `--watch`, `--interval <seconds>` (default 1) |
| `stations status <id>` | One station's bins and the workpieces in them; `<id>` is its short code | `--json`, `--watch`, `--interval <seconds>` (default 1) |

`--watch` redraws on an interval and can't be combined with `--json`.

## Workpieces

`<id>` is a workpiece id, or a substring of one. `--bin` takes `STATION/BIN`, such as `IN3/failed`.

| Command | `-f` | What it does | Options |
|---|---|---|---|
| `workpieces list` | yes | Workpieces on disk: position, last event, folder | `--line`, `--bin`, `--match <substring>`, `--json` |
| `workpieces show <id>` | yes | One workpiece and its journey; a substring that matches several shows the list | `--json` |
| `workpieces watch [id]` | yes | Live tail of bin moves and new log events | `--line`, `--bin`, `--match`, `--interval <seconds>` (default 2) |
| `workpieces count [bin]` | optional | `failed`, `done` and `finished` counts; `[bin]` shows only that one | `--by factory`, `line` or `station` (default `station`), `--json` |
| `workpieces errors` | optional | Failed workpieces grouped by error, most common first | `--line`, `--station`, `--json` |
| `workpieces cat <id> <file>` | yes | Print one file from a workpiece's folder, such as `error.json`; safe for binary files when redirected | |
| `workpieces open <id>` | yes | Open the workpiece's folder: in Finder locally (`xdg-open` on Linux), a shell in it on a remote host | |
| `workpieces clear [id]` | yes | Delete done workpieces or finished ones, or one workpiece's done and finished copies. A dry run unless `--yes`. | `--bin done` (every done bin) or `--bin finished` (each line's last output), `--line`, `--station`, `--older-than <days>` (no activity for that long), `--yes` |
| `workpieces requeue [id]` | yes | Move every workpiece in a failed bin, or one failed or done workpiece, back to its station's `input/`. A dry run unless `--yes`. | `--bin STATION/failed`, `--yes` |

`count` and `errors` cover every factory on the host unless given `-f`. `clear` skips the bins in a factory's `keep` list and bins a conveyor takes from.

How to use them on failures: [Find out why a workpiece failed, and retry it](/docs/guides/handle-failures).

## Processes

Factory sessions run under pm2 on their host.

| Command | `-f` | What it does |
|---|---|---|
| `procs list` | | Every running factory on the host (`--json`) |
| `procs start` | yes | Start a factory under pm2 |
| `procs stop` | yes | Stop a factory pm2 runs |
| `procs restart` | yes | Restart a factory pm2 runs |
| `procs logs` | yes | Tail a factory's pm2 logs; Ctrl-C stops |
| `procs monit` | | pm2's interactive CPU and memory monitor on the host |
