# axle daemon

Keeps the repository loaded for an editor, answers its questions and tells it when files change.

```sh
axle daemon
```

Keeps the repository loaded, watches its files and answers an editor's questions about it. The [VS Code extension and the JetBrains plugin](https://axlers.dev/docs/getting-started/editor-integration.md) start one for each window and stop it when the window closes, so the task list and its cache status update as you save; you don't run it yourself. When it can't start, such as with an older Axle, they run `axle` for each refresh instead.

It speaks [JSON-RPC 2.0](https://www.jsonrpc.org/specification) over standard input and output, one message per line:

| Message                                  | Answer                                                                                                                                                                                                              |
| ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `list`                                   | the JSON of [`axle list --json`](https://axlers.dev/docs/reference/list.md#json-output)                                                                                                                                                 |
| `rehearse` `{ "tasks": ["build"] }`      | the JSON of [`axle run build --dry=json`](https://axlers.dev/docs/reference/run.md#json-events)                                                                                                                                         |
| `shutdown`                               | `null`                                                                                                                                                                                                              |
| `exit`, a notification                   | none; the daemon stops, as it does at the end of its input                                                                                                                                                          |
| `changed` `{ "files" }`, from the daemon | a notification with the files that changed, after the same quiet tenth of a second as [`axle watch`](https://axlers.dev/docs/reference/watch.md); the list is empty when the system lost track of changes, so any file may have changed |

```json
{ "jsonrpc": "2.0", "id": 1, "method": "rehearse", "params": { "tasks": ["build"] } }
{ "jsonrpc": "2.0", "id": 1, "result": { "formatVersion": 1, "packageManager": "pnpm", "concurrency": 16, "tasks": [] } }
{ "jsonrpc": "2.0", "method": "changed", "params": { "files": ["packages/ui/src/button.tsx"] } }
```

It reads the repository again for the first question after files change, so the answers always match what `axle list` and `axle run --dry` would print then, except that a plugin that fails is left out with a [warning](https://axlers.dev/docs/messages/plugin-skipped.md) on standard error, where `axle run --dry` would stop. Files Git ignores and those under [`[watch]`](https://axlers.dev/docs/reference/configuration.md#watch-settings) don't count as changes, and a change to `[watch]` takes effect the next time the daemon starts. When Axle can't answer, such as for a task that doesn't exist, the error has `"code": -32000`, the message, and `data` with the error's `code`, the name of its [message page](https://axlers.dev/docs/messages/unknown-task.md), and its `hint`. A line that isn't JSON, a message without a method, an unknown method and wrong `params` get JSON-RPC's own errors, `-32700`, `-32600`, `-32601` and `-32602`.
