# AGENTS.md ## Project `nous-portal`: a [pi](https://github.com/earendil-works/pi) provider extension (single `index.ts`, no build step). Registers the `nous-portal` provider with device-code OAuth and API-key auth against Nous inference, plus `/model` catalog filters. ## Commands - `npm run check`: `tsc --noEmit` then `node --test tests/*.test.mjs`. - Install dev deps with `npm install --legacy-peer-deps --no-package-lock`. Plain `npm install` ignores the `"*"` peer ranges and pulls a full duplicate copy of `@earendil-works/pi-ai` into `node_modules`, which pi's loader explicitly warns against. - Local install for pi: `ln -s "$PWD" ~/.pi/agent/extensions/nous-portal` (sibling convention in `~/Projects/scripting/pi-extensions`). ## Architecture - Uses the **native** pi-ai `Provider` (`createProvider`) rather than the legacy `ProviderConfig` + `oauth` block. The legacy `getApiKey` contract pushes an extension toward minting an agent key; Nous retired that endpoint (`410 session_key_minting_retired`). Here `OAuthAuth.toAuth` returns the access token itself, and pi owns the locked refresh pattern. See `docs/adr/0001-stack.md`. - Streaming is delegated to pi's built-in `openai-completions` API. No custom wire protocol. - `Model.headers["x-nous-catalog-tier"]` carries the catalog tier **on the model**, because pi persists and restores model objects across runs and a side table would miss restored entries. `withoutTierHeader` strips it before every request. ## Conventions and gotchas - **Host imports are allowlisted.** pi's extension loader aliases only `@earendil-works/pi-ai`, `/models`, `/oauth`, `/compat`, `/providers/all`. Import `openAICompletionsApi` from `@earendil-works/pi-ai/compat`; the `./api/*` subpath typechecks but fails at load. - **`ctx` vs `pi`:** `setModel`, `registerCommand`, `registerProvider` are on `pi`; `ui.notify`, `model`, `modelRegistry` are on the handler's `ctx`. Check with `tsc` rather than guessing. - **`pi -p` and `--list-models` never fetch live catalogs** (`allowModelNetwork` is hard-coded `false`). That is why the provider ships `BASELINE`; interactive startup overlays the live list. - **Tests load `index.ts` through jiti with the host packages aliased to `tests/stubs/pi-ai.mjs`.** Alias keys are longest-prefix first, so `pi-ai/compat` must precede `pi-ai` or the bare key swallows the subpath. - **Never blanket-inject `tags.user` into request bodies.** As of 2026-11-25 Nous free and discounted models return 500 when that field is present, and only `upstage/solar-mini4:free` requires it. `solar-mini4:free` is therefore left out of `BASELINE` on purpose. ## Catalog tiers Live catalog signals, classified in `tierOf`: - free: `synthesizedFreeVariant: true` (also suffixed `:free`) - promo: `pricing.original.prompt` greater than the current `pricing.prompt` `billing_mode: "subscription"` is a separate axis (batch models billed to the plan), not a promo marker.