Give login an optional clock ({ now, sleep }) with the real timers as
the default, so the device-code poll loop can be tested without
wall-clock time. Neither t.mock.timers nor jiti aliasing reaches
node:timers/promises, so a seam is the only way in; auth.oauth.login
still passes only the interaction, so pi's interface is unchanged.
Six tests cover pending to slow_down to success, the interval fallback
and floor, the deadline cap, a non-retryable error and a non-OK device
code response. The token mock gives up after 100 polls: an
auto-advancing fake starves the event loop, so a sleep-less regression
would otherwise hang the suite with no test timeout able to fire.
133 lines
7.9 KiB
Markdown
133 lines
7.9 KiB
Markdown
# 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.
|
|
- The catalog tier rides **on the model** as the `catalogTier` property, because pi persists and restores model objects across runs and a side table would miss restored entries. It is a property, not a header: pi forwards only `model.headers` to requests (and copies them into the options first), so nothing is stripped before a request. Do not move it into `headers` without bringing back a strip on both the model and the options. The persisted catalog is `<agentDir>/models-store.json` (`ModelsStore`); `models.json` holds only user overrides, so check the store when verifying anything carried on a model.
|
|
- `login` accepts an optional clock (`{ now, sleep }`): production uses `node:timers/promises` and `Date.now`, tests an auto-advancing fake. `auth.oauth.login` passes only the interaction, so pi's interface is unchanged.
|
|
|
|
## Conventions and gotchas
|
|
|
|
- **Host imports are allowlisted.** pi's extension loader aliases only `@earendil-works/pi-coding-agent` and `@earendil-works/pi-ai` plus its `/models`, `/oauth`, `/compat`, `/providers/all` subpaths. 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.
|
|
|
|
# DOX framework
|
|
|
|
- DOX is highly performant AGENTS.md hierarchy installed here
|
|
- Agent must follow DOX instructions across any edits
|
|
|
|
## Core Contract
|
|
|
|
- AGENTS.md files are binding work contracts for their subtrees
|
|
- Work products, source materials, instructions, records, assets, and durable docs must stay understandable from the nearest applicable AGENTS.md plus every parent AGENTS.md above it
|
|
|
|
## Read Before Editing
|
|
|
|
1. Read the root AGENTS.md
|
|
2. Identify every file or folder you expect to touch
|
|
3. Walk from the repository root to each target path
|
|
4. Read every AGENTS.md found along each route
|
|
5. If a parent AGENTS.md lists a child AGENTS.md whose scope contains the path, read that child and continue from there
|
|
6. Use the nearest AGENTS.md as the local contract and parent docs for repo-wide rules
|
|
7. If docs conflict, the closer doc controls local work details, but no child doc may weaken DOX
|
|
|
|
Do not rely on memory. Re-read the applicable DOX chain in the current session before editing.
|
|
|
|
## Update After Editing
|
|
|
|
Every meaningful change requires a DOX pass before the task is done.
|
|
|
|
Update the closest owning AGENTS.md when a change affects:
|
|
|
|
- purpose, scope, ownership, or responsibilities
|
|
- durable structure, contracts, workflows, or operating rules
|
|
- required inputs, outputs, permissions, constraints, side effects, or artifacts
|
|
- user preferences about behavior, communication, process, organization, or quality
|
|
- AGENTS.md creation, deletion, move, rename, or index contents
|
|
|
|
Update parent docs when parent-level structure, ownership, workflow, or child index changes. Update child docs when parent changes alter local rules. Remove stale or contradictory text immediately. Small edits that do not change behavior or contracts may leave docs unchanged, but the DOX pass still must happen.
|
|
|
|
## Hierarchy
|
|
|
|
- Root AGENTS.md is the DOX rail: project-wide instructions, global preferences, durable workflow rules, and the top-level Child DOX Index
|
|
- Child AGENTS.md files own domain-specific instructions and their own Child DOX Index
|
|
- Each parent explains what its direct children cover and what stays owned by the parent
|
|
- The closer a doc is to the work, the more specific and practical it must be
|
|
|
|
## Child Doc Shape
|
|
|
|
- Create a child AGENTS.md when a folder becomes a durable boundary with its own purpose, rules, responsibilities, workflow, materials, or quality standards
|
|
- Work Guidance must reflect the current standards of the project or user instructions; if there are no specific standards or instructions yet, leave it empty
|
|
- Verification must reflect an existing check; if no verification framework exists yet, leave it empty and update it when one exists
|
|
|
|
Default section order:
|
|
- Purpose
|
|
- Ownership
|
|
- Local Contracts
|
|
- Work Guidance
|
|
- Verification
|
|
- Child DOX Index
|
|
|
|
## Style
|
|
|
|
- Keep docs concise, current, and operational
|
|
- Document stable contracts, not diary entries
|
|
- Put broad rules in parent docs and concrete details in child docs
|
|
- Prefer direct bullets with explicit names
|
|
- Do not duplicate rules across many files unless each scope needs a local version
|
|
- Delete stale notes instead of explaining history
|
|
- Trim obvious statements, repeated rules, misplaced detail, and warnings for risks that no longer exist
|
|
|
|
## Closeout
|
|
|
|
1. Re-check changed paths against the DOX chain
|
|
2. Update nearest owning docs and any affected parents or children
|
|
3. Refresh every affected Child DOX Index
|
|
4. Remove stale or contradictory text
|
|
5. Run existing verification when relevant
|
|
6. Report any docs intentionally left unchanged and why
|
|
|
|
## User Preferences
|
|
|
|
When the user requests a durable behavior change, record it here or in the relevant child AGENTS.md
|
|
|
|
## Child DOX Index
|
|
|
|
| Path | Scope |
|
|
|---|---|
|
|
| [docs/AGENTS.md](docs/AGENTS.md) | Durable documentation: ADRs (numbering, format, status) and session logs under `docs/devlog/` (one log per unit of work; `INDEX.md` is the source of truth) |
|
|
| [tests/AGENTS.md](tests/AGENTS.md) | Offline test suite: jiti aliasing to host-package stubs, fixtures, and what the tests pin |
|
|
|
|
## Session Logs
|
|
|
|
Session logs live in `docs/devlog/` (one per completed task/issue/milestone). Full history: [`docs/devlog/INDEX.md`](docs/devlog/INDEX.md). The 10 most recent:
|
|
|
|
<!-- write-log: window-start -->
|
|
| Date | Log |
|
|
|------|-----|
|
|
| 2026-11-25 | [20261125-fresh-context-audit-rounds-1-5_log.md](docs/devlog/20261125-fresh-context-audit-rounds-1-5_log.md) |
|
|
<!-- write-log: window-end -->
|