# Helper

Every assent-helper command, setting and exit code for macOS and Windows, what a resumed agent receives, and how Run now stays safe.

The Assent helper pairs a computer with Assent by QR code or an 8 character code, sends a heartbeat every 30 seconds and runs **Run now**: when you answer an agent's ask on your phone, the helper restarts that agent on this computer with your answer. It needs macOS, or Windows 10 version 1809 or later, and Node.js 20 or later. On Linux it can pair and run, but `install` adds no background service. The commands are the same everywhere, in Terminal on a Mac or in PowerShell or Command Prompt on Windows.

For a step-by-step guide with the expected result of each step and fixes for common problems, see [Connect a computer](https://docs.specvista.com/assent/connect-a-computer.md).

```bash
npm install -g assent-helper
```

## Set it up

1. Run `assent-helper pair`. It shows a QR code and an 8 character code, which lasts 10 minutes.
2. Scan the QR code with your iPhone camera to open it in Assent, or sign in at [assent.specvista.com/connect/pair](https://assent.specvista.com/connect/pair) and type the code. Choose **Pair this computer**.
3. Link an agent to this computer in Assent: set **When you answer one of its asks** to **Run now**, pick this computer as its **Linked computer** and give it a **Resume command**.
4. Review and allow that agent's command on this computer, then start the background service:

```bash
assent-helper agents
assent-helper allow <agent-uuid>
assent-helper install
```

The helper talks to the hosted Assent service. Set `ASSENT_API_URL` or pass `--api-url` to `pair` only to point at another Assent server. Pairing refuses a plain `http://` address unless the host is `localhost` or `127.0.0.1`.

## Commands

```text
assent-helper pair [--api-url url] [--name name]   show a QR code and wait for your phone to scan it
assent-helper status                               pairing, allowed agents and the local queue size
assent-helper agents                               agents linked to this computer and whether each is allowed
assent-helper allow <agent-uuid> [--yes]           review and allow an agent's resume command
assent-helper revoke <agent-uuid>                  stop allowing it
assent-helper unpair                               remove this computer from Assent and forget its key
assent-helper queue                                answers claimed and waiting to run on this computer
assent-helper once                                 heartbeat, claim and run what is due, then exit
assent-helper run                                  keep doing that every 30 seconds
assent-helper install | uninstall                  add or remove the background service
```

`--name` sets the computer's name in Assent and defaults to the host name. Every command prints one line of JSON, and an error prints `{"error": message, "exitCode": code}` on stderr. `assent-helper help` prints the commands, and `assent-helper --version` the version.

## Settings

| Setting | What it does |
|---|---|
| `ASSENT_API_URL` | Optional. The Assent server `pair` uses when `--api-url` is not given. Default `https://ordia-api.specvista.com/api/v1`. |
| `ASSENT_HELPER_INTERVAL_SECONDS` | Loop interval. A whole number of at least 5, otherwise 30. |
| `ASSENT_HELPER_RUN_TIMEOUT_MINUTES` | How long one resume command may run before it is stopped. A positive whole number, otherwise 360. |

Requests to Assent give up after 15 seconds and count as Assent being unreachable. Pairing again while `run` is active takes effect on the next tick, without a restart.

## What the resumed agent receives

The helper runs the agent's resume command with your answer in these environment variables:

| Variable | Value |
|---|---|
| `ASSENT_RESUME` | `1` |
| `ASSENT_TASK_UUID` | The ask you answered. |
| `ASSENT_AGENT_UUID` | The agent. |
| `ASSENT_ANSWER_JSON` | Your answer, for example `{"actionId":"submit","selectedItemIds":["02"]}`. |
| `ASSENT_TASK_JSON` | The whole ask, when it fits in 64 KB. |
| `ASSENT_TASK_FILE` | Set instead of `ASSENT_TASK_JSON` when the ask is larger than 64 KB: a private file holding it, removed after the run. |

Exit code 75 from the command means "busy, try later". The helper tries again every 10 minutes, for up to 6 hours. If the agent is still busy after that, the answer is reported as failed and goes back to the agent's next scheduled run.

## Exit codes

| Code | Meaning |
|---|---|
| 0 | OK |
| 1 | Error |
| 2 | Usage error |
| 3 | Pairing expired, or another helper holds the queue |
| 4 | Unknown agent |
| 5 | Not paired |
| 69 | Assent unreachable |

## How Run now stays safe

- Only agents linked to this computer in Assent, with Run now on and a resume command, are considered.
- Nothing runs until you allow that agent's exact resume command on this computer with `assent-helper allow <agent-uuid>`, which shows you the command first. If the command changes in Assent, it stops running until you allow the new one. The helper always runs the command stored on this computer.
- The command gets your environment with every other `ASSENT_` variable removed, and without any value holding an agent or computer key.
- Each answer is claimed once. A run that was interrupted (helper stopped, computer restarted) is never re-run automatically: the helper tells Assent it was interrupted, the answer goes back to waiting for the agent's next scheduled run, and the log tells you which one to check.
- Only one helper works the queue at a time. A second `once` or `run` exits with code 3 and names the process holding it.
- The helper's log is redacted: emails, keys, tokens, phone numbers, home paths and this computer's own key. Pairing never prints the computer key.
- While Assent is unreachable, answers wait on the server. The helper keeps running anything it already claimed and catches up when Assent is back.

## Background service

`install` records the path of the helper and of Node.js it was run from, so run it again after reinstalling the helper somewhere else.

- **macOS**: `install` adds the launchd agent `com.ordia.helper`, which restarts the helper if it stops (at most once a minute). The log is `~/Library/Logs/ordia/helper.log`.
- **Windows**: `install` adds the scheduled task `AssentHelper` for your user, without needing an administrator. It starts when you sign in, runs in a hidden console and is checked every minute, so a helper that stopped is started again. The log is `%LOCALAPPDATA%\Assent\Logs\helper.log`, and the task's own output goes to `%LOCALAPPDATA%\Assent\Logs\helper.task.log`. Resume commands run in Git Bash when Git for Windows is installed, otherwise in `cmd.exe`. Write paths with forward slashes, such as `C:/jobs/scan.cmd`, because Git Bash drops unquoted backslashes. A command that runs too long is stopped with its child processes.
- **Linux**: `install` is not available. Keep `assent-helper run` going with your own service manager.

The service restarts itself if it stops, so to pause the helper run `assent-helper uninstall`, and `assent-helper install` to start it again.
