# crouter

## Install

```bash
npm install -g @crouton-kit/crouter
```

## Building from source

`npm run build` requires a C compiler and a local filesystem with atomic directory exchange support: APFS on macOS, or a Linux filesystem that supports `renameat2(..., RENAME_EXCHANGE)` (such as ext4, XFS, or Btrfs). The build verifies both prerequisites before compiling output because publication swaps the complete staged `dist` tree into place atomically; that is build/packaging behavior, not the runtime safety boundary.

To activate source changes, run `npm run build && npm run install-runtime`, then restart the daemon. `install-runtime` stages and seals a complete immutable local generation before atomically switching `selected`; a failed install preserves the prior selection, and live brokers continue using their own generation until restarted.

## Runtime generations

The packaged `runtime.lock.json` is copied to the staged generation's `package-lock.json` for its production dependency install. After a successful install, generation GC keeps `selected` plus the three newest generations, but conservatively skips pruning entirely while any crtr shim process may still be using a generation; old generations are reclaimed on a later install when no such process is live.

`crtr sys version` reports the selected and current-process generations and flags drift. `crtr sys doctor` validates their manifests, sealing and containment, and hashes their complete inventories on demand.

## Usage

```bash
crtr --help
```

## Official marketplace

`crtr` ships with the [crouter official marketplace](https://github.com/crouton-labs/crouter-official-marketplace) pre-installed. On first run it is cloned into your user scope and registered automatically — no plugins are enabled by default.

Browse and install plugins from it:

```bash
crtr pkg market browse crouter-official-marketplace
crtr pkg plugin install crouter-official-marketplace/<plugin>
```

To opt out of the bootstrap (e.g. in CI), set `CRTR_NO_BOOTSTRAP=1`.

## Running crouter on pi

The node runtime hosts the [pi coding agent](https://pi.dev) in each broker. To set your pi install up the way crouter's author runs it, add these to the `packages` array in `~/.pi/agent/settings.json` (neither ships with pi — you add them yourself):

- **[pi-claude-oauth-adapter](https://github.com/minzique/dotfiles-agents/tree/main/packages/pi-claude-oauth-adapter)** — third-party npm package; Anthropic OAuth / Claude Code compatibility adapter for pi. Install with `"npm:pi-claude-oauth-adapter"`.
- **pi-crtr-extensions** — crtr's engine-side pi extensions (crtr help-gate, slash-command surfacing, provider rotation, frontmatter rules, statusline). Bundled in this repo at `src/builtin-pi-packages/pi-crtr-extensions` and wired into `~/.pi/agent/settings.json` automatically by `crtr sys setup` — nothing to install separately.

