# pi-copilot-auto

A [pi](https://github.com/earendil-works/pi) extension that adds GitHub Copilot's Auto model routing to the built-in `github-copilot` provider.

The extension adds:

- `github-copilot/auto`, which asks Copilot to select a model for each user turn.
- `github-copilot/auto-<model-id>` entries for models in the account's Auto pool. These entries keep the Auto session protocol while forcing a specific pool model.
- Automatic forwarding to the selected model's native API format, including Anthropic Messages, OpenAI Responses, and OpenAI Completions.

## Requirements

- pi 0.82.0 or later.
- A GitHub account with an active Copilot plan.
- Authentication for pi's built-in `github-copilot` provider.

Authenticate in pi with `/login`, then select **GitHub Copilot**.

## Install

From npm after publication:

```sh
pi install npm:pi-copilot-auto
```

From GitHub after the repository is published:

```sh
pi install git:github.com/asp345/pi-copilot-auto
```

From a local checkout:

```sh
pi install /absolute/path/to/pi-copilot-auto
```

For a one-off test without changing settings:

```sh
pi -e /absolute/path/to/pi-copilot-auto
```

Restart pi after installation, open `/model`, and select `github-copilot/auto`.

## Development

```sh
npm ci
npm run audit
npm run check
npm run pack:check
pi -e .
```

`npm run check` verifies formatting, lint, types, and extension loading. The package has no runtime dependencies. Its two optional peer dependencies document the APIs supplied by pi, while development dependencies provide local checks. The package ships its TypeScript source directly because pi loads TypeScript extensions without a build step.

CI runs the audit and checks on pushes and pull requests. Dependabot checks npm and GitHub Actions dependencies weekly.

## Publishing

The first release must be published manually because npm trusted publishing can only be configured after the package exists:

```sh
npm login
npm publish
```

Then configure **Trusted Publisher** in the `pi-copilot-auto` package settings on npm:

- Provider: GitHub Actions
- Organization or user: `asp345`
- Repository: `pi-copilot-auto`
- Workflow filename: `publish.yml`
- Allowed action: `npm publish`

Future releases are published with npm OIDC authentication and automatic provenance. Bump the version, push the commit and tag, then create a GitHub Release for that tag:

```sh
npm version patch
git push origin main --follow-tags
gh release create "v$(node --print "require('./package.json').version")" --generate-notes
```

The release workflow rejects a tag that does not match the version in `package.json`.

## How it works

The extension wraps pi's built-in `github-copilot` provider. It creates a Copilot model session, sends the latest user prompt to Copilot's intent endpoint, and streams the request through the provider implementation matching the selected model. Session tokens are cached by pi session and refreshed before expiration.

The Auto session and intent endpoints are GitHub Copilot implementation details and may change without notice.

## License

MIT
