# wire

> A per-file control channel between the page and a process running in your terminal.

Source: https://clayjs.com/docs/plugins/wire/

A per-file control channel between the page and a process running in your terminal. The page sends a request, the process answers with progress, and the process edits *the file*.

HTML never travels over the wire: the change reaches your open page as an ordinary external file change, through live sync. Nothing in the wire depends on what a payload contains.

## Loading

```html
<script src="https://clayjs.com/v1/clay.js?plugins=wire,sync"></script>
```

## Sending a request

```js
const run = clay.wire.send({ ask: "tighten the intro" });
clay.wire.on((state, frame) => console.log(state.state, frame && frame.text));
const outcome = await run.done;
```

`send` returns its handle immediately, and `handle.done` resolves with the final snapshot and never rejects. `on` takes a function, not an event name. Its second argument is the inbound frame when one caused the update, which today means a status line and nothing else: `state.text` is sticky across later states, so the frame is the only way to tell a new line from the same line arriving again. Also `cancel`, `get`, `list` and `isBusy`. It runs in view mode too, so a read-only review page can drive one; nothing in it assumes the save lane exists. The stream is lazy and idle between requests, because a browser allows only six connections per origin and live sync already holds one.
