# Add Nous Portal Provider (#175) > **Date:** 2026-11-05 > **Type:** issue > **Reference:** https://git.babylondreams.de/AlexKucera/museion/issues/175 ## Goal Add the Nous Portal as a fourth provider in Settings, so chats and passes can run on Nous models using API-key and subscription credits (one account bill behind both, per the portal docs — the owner confirmed this reading mid-session). ## What Was Done - `ModelProvider` gains `.nous` — slug `nous`, label "Nous Portal", endpoint `https://inference-api.nousresearch.com/v1`, env `NOUS_API_KEY`, 5-level effort ladder (hermes' `OPENAI_COMPAT_WIRE_EFFORTS`), switch flagship `anthropic/claude-sonnet-5` (Museion/SettingsModel.swift). - `ProviderProbe` speaks the nous dialect: plain OpenAI chat-completions (`/chat/completions`, `messages` + the 512 cap, no thinking knobs), Bearer auth, existing chat-completions SSE decoder; `decodeErrorRoot` falls back to a bare root `message` (the portal's `{status, message}` envelope carries no error object) (Museion/ProviderProbe.swift). - New `PortalAuth` enum (SettingsModel.swift): lenient read of the shared `~/.hermes/auth.json` session `agent_key` — the credential the engine itself runs nous on. - `SettingsModel.testConnection`: an unkeyed nous test falls back to the session agent_key, **gated to the official https endpoint** — a hand-edited endpoint with an empty key refuses pre-network; no key and no login names `hermes auth add nous`. `probeTransport`/`portalAuthPath` injectable init seams. - `MentorSessionModel.refreshPassReadiness` (finish-audit HIGH fix): an unkeyed nous pass falls back to `PortalAuth.sessionKey` (injectable `portalAuthPath`) — a logged-in Portal machine reads `.ready` with no key; the UI no longer demands a key the feature says isn't needed. - Provider Keys page: the nous block carries the Portal-login note (chats ride the hermes Portal login; a pasted key bills the same account credits). - Tests: 8 new/extended pins across SettingsModelTests, SettingsModelWritePathTests, ProviderProbeTests, ProviderProbeTransportTests, EngineLifecycleTests (provider facts, ladder, switch default, request dialect, SSE decode + bare-envelope 404/401, session-key fallback, custom-endpoint refusal, keyless readiness). - DOX pass: Museion/AGENTS.md + MuseionTests/AGENTS.md updated (provider facts, probe dialect, fallback semantics, readiness, pins). ## Decisions & Rationale | Decision | Rationale | |----------|-----------| | Flagship `anthropic/claude-sonnet-5`, not a Hermes-4 model | Live-probed: the docs' `Hermes-4.3-36B` ids **404** on the real endpoint — the portal serves the OpenRouter catalog (`/v1/models` = 385 vendor-prefixed ids). Sonnet keeps the app's everywhere-default posture, billed through Nous. | | One pasted key covers API + subscription credits | The portal docs: "Add API credits **or** activate a subscription, then generate an API key" — the key is the billing instrument for both (owner confirmed). No dual-mode UI needed. | | Engine auth rides the Portal login; key optional | Hermes' nous runtime is OAuth-only (`resolve_nous_runtime_credentials`, shared across profiles; `NOUS_API_KEY` does not drive engine inference today). The `.env` write stays as future-proofing — a later hermes release lights it up with zero Museion changes. | | No `model.base_url` write for nous | Hermes derives nous routing from auth state (`_nous_effective_routing`); `config set model.provider` clears stale base_url anyway. | | Session-key fallback gated to the official endpoint | Finish-audit security finding: the implicit credential (never pasted, empty field) must not silently ride a user-edited URL (cleartext http / foreign host) with no on-screen cue. | | Readiness fallback at the shared gate | One guard in `refreshPassReadiness` covers both pass kinds — patching only the probe would have left Run Pass blocked. | ## Gotchas & Fixes | Problem | Root Cause | Fix | |---------|------------|-----| | Nous model dropdown missed `anthropic/claude-sonnet-5.5` | The dropdown reads hermes' `~/.hermes/provider_models_cache.json` (ADR-0014, zero HTTP from Museion); the cache was written 2026-09-03, before 5.5 existed (381 cached vs 385 live) | `hermes model --refresh` wipes + re-fetches — but it exits before fetching nous unless the provider is walked; filled the cache by calling hermes' own `fetch_nous_models` + `_store_cache_entry` through its venv (hermes' code, its fingerprint, its lock) | | `hermes model --refresh` refuses to run through a pipe | The picker guards non-TTY stdin | Run interactively (the owner's run wiped the cache and exited after 4 providers — nous never re-fetched) | | Finish-audit HIGH: keyless nous passes blocked by Run Pass | `refreshPassReadiness` mapped empty `.env` key → `.missingKey` with no Portal-login fallback — contradicting the feature's own UI note | Fallback to `PortalAuth.sessionKey` in the readiness gate, pinned | | Scoped flip run "passed" with a guard deleted | `EngineLifecycleTests` has no `@Suite` — its free functions don't run under `-only-testing` suite filters (the #31 lesson, re-confirmed) | Flip verdict needs the full suite; it failed with exactly the two new pins | | swiftlint orphaned_doc_comment | A `//` scenario block between a `///` doc block and its test detaches the doc (#143 lesson) | Scenario blocks go above the `///` block | | `@unchecked Sendable` / `@escaping` compile errors | Test transport closure captured a mutable box; stored closure param | `final class AuthSaw: @unchecked Sendable`; `@escaping` on the init param | ## Files Changed | File | Change Summary | |------|---------------| | `Museion/SettingsModel.swift` | `.nous` case + all five switches; `PortalAuth`; endpoint-gated session-key fallback in `testConnection`; injectable seams | | `Museion/ProviderProbe.swift` | nous dialect (URL/body/auth/decode); bare-root-message error fallback | | `Museion/MentorSessionModel.swift` | readiness nous fallback + injectable `portalAuthPath` | | `Museion/SettingsPagesView.swift` | nous Portal-login note on the Provider Keys page | | `MuseionTests/SettingsModelTests.swift` | registry fixture `.nous` row; ladder + switch-default pins | | `MuseionTests/SettingsModelWritePathTests.swift` | nous facts, session-key fallback, custom-endpoint refusal pins | | `MuseionTests/ProviderProbeTests.swift` | nous SSE decode + bare-envelope 404/401 pins | | `MuseionTests/ProviderProbeTransportTests.swift` | nous chat-completions dialect pin | | `MuseionTests/EngineLifecycleTests.swift` | keyless nous readiness pin | | `Museion/AGENTS.md`, `MuseionTests/AGENTS.md`, `AGENTS.md` | DOX pass + gitnexus counters | ## Open Items & Next Steps - [ ] Dogfood: Settings ▸ a surface ▸ Provider → Nous Portal ▸ Test Connection (no key needed on this machine) ▸ run a chat/pass. - [ ] Deferred (ceiling comment on `PortalAuth`): parse `agent_key_expires_at` if a stale-key verdict ever misleads — today the portal's 401 decodes `authFailed` honestly. - [ ] The hermes picker's `--refresh` not re-fetching nous on early exit is an upstream hermes wart — worth a report to the hermes repo if it recurs. --- *Log written by write-log skill. Verification cited: `xcodebuild test` (unit + UI) 635/635 passed, exit 0, 2026-11-05 16:0x; flip-cycle 632-passed/2-failed with both new guards deleted, restored sha-verified.*