# Coding agents

A coding agent that works on a program built on fleethosts needs three facts: where the fleet is, how a run reports a dead machine, and how to test without one. Put them in `AGENTS.md`:

```md [AGENTS.md]
## Machines

- The fleet is in `~/.local/state/mytool/hosts.json` (`recordHosts`, `recordedHosts` from fleethosts).
- `runOnHosts` returns one result per machine. Read `exitCode` only when it is there: a machine that
  didn't answer has `reachable: false` and an `error`, not a failed exit code.
- Tests never reach a real host. `MYTOOL_SSH` and `MYTOOL_TAILSCALE` name fake CLIs; a `.mjs` file
  runs with Node.
```

## Testing without a host

`<PROGRAM>_SSH` names the ssh fleethosts runs. Point it at a script that runs the remote command on this machine:

```js [test/fake-ssh.mjs]
import { spawnSync } from "node:child_process";

const args = process.argv.slice(2);
while (args[0] === "-o") args.splice(0, 2);
if (args[0] === "--") args.shift();
const [, command] = args;
process.exit(spawnSync("sh", ["-c", command], { stdio: "inherit" }).status ?? 1);
```

```ts
process.env.MYTOOL_SSH = new URL("./fake-ssh.mjs", import.meta.url).pathname;
const [box] = await runOnHosts(places, [{ host: "box" }], ["echo", "hi"], 5_000, { here: false });
// { host: "box", reachable: true, exitCode: 0, stdout: "hi\n", stderr: "" }
```

Build the `Places` in a temporary folder, so a test never writes to the machine's own state.

## Markdown copies

Every page on this site has a raw Markdown copy at `/raw/<page>.md`, such as `/raw/guide/hosts.md`, and a full index at `/llms.txt`.

<!-- vitehub-docs:section-links -->
## In this section

- [Introduction](https://fleethosts.loadsheet.dev/raw/guide.md)
- [Installation](https://fleethosts.loadsheet.dev/raw/guide/installation.md)
- [Places](https://fleethosts.loadsheet.dev/raw/guide/places.md)
- [Hosts](https://fleethosts.loadsheet.dev/raw/guide/hosts.md)
- [Exec](https://fleethosts.loadsheet.dev/raw/guide/exec.md)
- [Coding agents](https://fleethosts.loadsheet.dev/raw/guide/agents.md) (this page)

All pages: [llms.txt](https://fleethosts.loadsheet.dev/llms.txt)

Something on this page does not work as written? Tell the user, and draft an issue for them to post: [issue tracker](https://github.com/words-with-agents/fleethosts/issues). Report a security vulnerability privately, never in a public issue.
