feat: make the package installable from npm
pi loads a package's extensions through the `pi` manifest or an
`extensions/` directory, so a root index.ts loaded nothing as a
package. Add "pi": { "extensions": ["./index.ts"] }, a files
whitelist that keeps tests and docs out of the tarball, and the
repository links the pi.dev/packages gallery shows.
Add publish.sh for releases: checks, tarball preview, changelog
heading, commit, tag, npm publish, push. No CI (ADR 0003).
Lead the README with pi install npm:pi-nous-portal, document the
release script, and label the package unofficial and
community-maintained. The README also gets a plainer voice.
The publish itself is still pending. Refs #3
This commit is contained in:
1 parent
8829d3142c
commit
1af3a1360e
9 files changed
+155
-19
No files matched your search
@@ -9,6 +9,7 @@
|
||||
- `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`).
|
||||
- `./publish.sh`: cuts a release (clean tree on `main`, `npm run check`, `npm pack --dry-run`, changelog heading, commit, tag, `npm publish`, push). The changelog's `## [Unreleased]` heading is required.
|
||||
|
||||
## Architecture
|
||||
|
||||
@@ -16,6 +17,7 @@
|
||||
- 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.
|
||||
- **The `pi` manifest is what makes the package load.** pi's package loader reads `pi.extensions` from `package.json`, or scans an `extensions/` directory when there is no manifest. A root `index.ts` is only found by the legacy `~/.pi/agent/extensions/` loader, which is why the symlink install works and a package install would not. Keep `"pi": { "extensions": ["./index.ts"] }`, the `pi-package` keyword (the pi.dev/packages gallery lists only npm packages that carry it), and the `files` whitelist in `package.json`.
|
||||
|
||||
## Conventions and gotchas
|
||||
|
||||
@@ -24,6 +26,7 @@
|
||||
- **`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.
|
||||
- **Releases are local, through `publish.sh`.** No CI and no npm token: `npm publish` prompts for the 2FA code. The script renames the changelog's `## [Unreleased]` heading to the released version, so new entries always go under `## [Unreleased]`.
|
||||
|
||||
## Catalog tiers
|
||||
|
||||
@@ -128,6 +131,7 @@ Session logs live in `docs/devlog/` (one per completed task/issue/milestone). Fu
|
||||
<!-- write-log: window-start -->
|
||||
| Date | Log |
|
||||
|------|-----|
|
||||
| 2026-11-25 | [20261125-issue03-publish-pi-nous-portal-to-npm_log.md](docs/devlog/20261125-issue03-publish-pi-nous-portal-to-npm_log.md) |
|
||||
| 2026-11-25 | [20261125-finish-audit-architecture-review-unit_log.md](docs/devlog/20261125-finish-audit-architecture-review-unit_log.md) |
|
||||
| 2026-11-25 | [20261125-architecture-review-tier-property-and-login-clock_log.md](docs/devlog/20261125-architecture-review-tier-property-and-login-clock_log.md) |
|
||||
| 2026-11-25 | [20261125-fresh-context-audit-rounds-1-5_log.md](docs/devlog/20261125-fresh-context-audit-rounds-1-5_log.md) |
|
||||
|
||||
@@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. The format
|
||||
### Added
|
||||
|
||||
- Native `nous-portal` provider: device-code OAuth (subscription) and API-key login, with the OAuth access token used directly as the inference bearer credential.
|
||||
- npm package. `pi install npm:pi-nous-portal` installs it, the `pi` manifest points pi at `index.ts`, and `publish.sh` cuts a release.
|
||||
- Live model discovery from `inference-api.nousresearch.com/v1/models`, delegated to pi's built-in `openai-completions` streaming.
|
||||
- Offline baseline catalog so `pi -p` and `pi --list-models` stay usable without a network fetch.
|
||||
- `/nous-catalog` cycles `/model` between full, free and promo catalogs; `/nous-free` jumps to free. Switching never touches a session on another provider, and swaps the current model only if it was filtered out.
|
||||
|
||||
@@ -1,27 +1,34 @@
|
||||
# pi-nous-portal
|
||||
|
||||
Nous Portal provider for [pi](https://github.com/earendil-works/pi): subscription OAuth and API key, without agent-key minting.
|
||||
An unofficial, community-maintained provider that lets [pi](https://github.com/earendil-works/pi) sign in to Nous Portal and use its models. Not affiliated with Nous Research.
|
||||
|
||||
## Why this exists
|
||||
|
||||
Nous retired Hermes-style agent-key minting (`POST /api/oauth/agent-key` returns `410 session_key_minting_retired`). Both existing community extensions end their login at that endpoint, so neither can sign in with a Portal subscription. The inference API now accepts the **OAuth access token directly** as a bearer credential, so this extension never mints or stores an agent key.
|
||||
Nous retired Hermes-style agent-key minting. `POST /api/oauth/agent-key` returns `410 session_key_minting_retired`, and both existing community extensions end their login at that endpoint, so neither can sign in with a Portal subscription. The inference API does accept the OAuth access token itself as a bearer credential, so this extension never mints or stores an agent key.
|
||||
|
||||
## Requirements
|
||||
|
||||
- pi 1.6.0 or newer (`@earendil-works/pi-ai` native provider interface)
|
||||
- Node.js 22+
|
||||
- A Nous Portal subscription, or an inference API key from the Portal
|
||||
- pi 1.6.0 or newer, for the `@earendil-works/pi-ai` native provider interface
|
||||
- Node.js 22 or newer
|
||||
- a Nous Portal subscription, or an inference API key from the Portal
|
||||
|
||||
## Getting started
|
||||
## Install
|
||||
|
||||
```bash
|
||||
pi install npm:pi-nous-portal
|
||||
```
|
||||
|
||||
To run from a checkout instead, symlink it into pi's extensions directory:
|
||||
|
||||
```bash
|
||||
# from a checkout
|
||||
ln -s "$PWD" ~/.pi/agent/extensions/nous-portal
|
||||
```
|
||||
|
||||
Then in pi:
|
||||
## Use
|
||||
|
||||
- `/login nous-portal` offers two methods: **Sign in to Nous Portal (subscription)** for the device-code OAuth flow, or **Nous Portal API key** to store an `sk-nous-…` key.
|
||||
In pi:
|
||||
|
||||
- `/login nous-portal` offers two methods: "Sign in to Nous Portal (subscription)" for the device-code OAuth flow, or "Nous Portal API key" to store an `sk-nous-…` key.
|
||||
- The API-key route also reads `$NOUS_API_KEY`.
|
||||
- `/model` lists the live catalog in interactive sessions.
|
||||
|
||||
@@ -42,22 +49,31 @@ The choice is saved in `~/.pi/agent/nous-portal-catalog` and survives restarts.
|
||||
|
||||
### Offline baseline
|
||||
|
||||
`pi -p` and `pi --list-models` never fetch live catalogs (pi hard-codes `allowModelNetwork: false` there), so the provider ships a small static baseline so it is always usable. Interactive pi overlays the live list on the baseline by model id; a baseline id that disappears from the live catalog stays listed, with its frozen baseline price and context, until the next release.
|
||||
`pi -p` and `pi --list-models` never fetch live catalogs, because pi hard-codes `allowModelNetwork: false` there. The provider ships a small static baseline so those modes still list something. Interactive pi overlays the live list on the baseline by model id. A baseline id that disappears from the live catalog stays listed, with its frozen baseline price and context, until the next release.
|
||||
|
||||
## Known limits
|
||||
|
||||
- `upstage/solar-mini4:free` is left out of the baseline on purpose: it alone requires a `tags` body field that the other free models reject with a 500, so no single request shape serves all of them.
|
||||
- Subscription quota is per day. When the "Today" gauge is exhausted, inference returns `503 ChatGPT subscription inference is temporarily unavailable`. Purchased credits keep the API-key route working.
|
||||
- Requests to the portal's OAuth endpoints send a browser-like `User-Agent`, `Origin` and `Referer` (only to `portal.nousresearch.com`, never to inference). This gets past the Vercel browser checkpoint that otherwise rejects CLI clients. It is a robustness and terms-of-use risk, not a security one: if Nous tightens the checkpoint or treats the client as evasion, login can break or the account can be flagged.
|
||||
- `upstage/solar-mini4:free` is left out of the baseline. It alone requires a `tags` body field that the other free models reject with a 500, so no single request shape serves all of them.
|
||||
- Subscription quota is per day. When the "Today" gauge is empty, inference returns `503 ChatGPT subscription inference is temporarily unavailable`. Purchased credits keep the API-key route working.
|
||||
- Requests to the portal's OAuth endpoints send a browser-like `User-Agent`, `Origin` and `Referer`, and only to `portal.nousresearch.com`, never to inference. This gets past the Vercel browser checkpoint that otherwise rejects CLI clients. It is a terms-of-use risk, not a security one. If Nous tightens the checkpoint or treats the client as evasion, login can break or the account can be flagged.
|
||||
|
||||
## Development
|
||||
|
||||
```bash
|
||||
npm install --legacy-peer-deps --no-package-lock # typescript + jiti only; pi injects @earendil-works/* at load time
|
||||
npm run check # tsc --noEmit + node --test
|
||||
npm run check # tsc --noEmit + node --test
|
||||
```
|
||||
|
||||
Typechecking needs a local pi install: `tsconfig.json` `paths` point `@earendil-works/pi-ai` and `pi-coding-agent` at the type declarations under `~/.pi/agent/install/releases/<version>/`. Update those three paths when pi is upgraded. The extension itself runs against any pi with the native provider interface; only `tsc` is pinned.
|
||||
Typechecking needs a local pi install. The `paths` in `tsconfig.json` point `@earendil-works/pi-ai` and `pi-coding-agent` at the type declarations under `~/.pi/agent/install/releases/<version>/`, so update those three paths when pi is upgraded. The extension itself runs on any pi with the native provider interface. Only `tsc` is pinned.
|
||||
|
||||
## Releasing
|
||||
|
||||
```bash
|
||||
./publish.sh # release the version in package.json
|
||||
./publish.sh patch # bump first; minor and major work too
|
||||
```
|
||||
|
||||
The script runs the checks, shows the tarball contents, moves the `Unreleased` section of the changelog under the new version, commits, tags, publishes to npm, and pushes. npm asks for your 2FA code during the publish. You need `npm login` with publish rights to the package first.
|
||||
|
||||
## License
|
||||
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ Durable documentation that explains *why* the project is shaped the way it is: a
|
||||
- `0001-stack.md`: native pi-ai `Provider` over legacy `ProviderConfig`, because the legacy form leads to agent-key minting that Nous retired.
|
||||
- `0002-license.md`: GPL-3.0-or-later.
|
||||
- `0003-forge-and-ci.md`: Gitea remote, no CI file yet.
|
||||
- An ADR records a decision that is hard to reverse, surprising without context, and the result of a real trade-off. Easy-to-reverse choices do not get an ADR.
|
||||
- `0003-forge-and-ci.md`: Gitea remote, no CI file. Releases go through the local `publish.sh`.
|
||||
|
||||
## Work Guidance
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
# Gitea remote, no CI yet
|
||||
|
||||
The repository already had an `origin` on `git.babylondreams.de` (Gitea) when it was initialised, so that is the forge. No CI file: a single-file extension has nothing to build, and the test suite is `node --test` over offline assertions. Add a Gitea Actions workflow when the suite grows or a published npm package needs a release gate.
|
||||
The repository already had an `origin` on `git.babylondreams.de` (Gitea) when it was initialised, so that is the forge. No CI file: a single-file extension has nothing to build, and the test suite is `node --test` over offline assertions. Add a Gitea Actions workflow when the suite grows or a published npm package needs a release gate. Until then, releases are cut locally with `publish.sh`, which runs `npm run check` and `npm pack --dry-run` before `npm publish`.
|
||||
@@ -0,0 +1,66 @@
|
||||
# Issue #3: Publish pi-nous-portal 0.1.0 to npm
|
||||
|
||||
> **Date:** 2026-11-25
|
||||
> **Type:** issue
|
||||
> **Reference:** https://git.babylondreams.de/AlexKucera/nous-portal/issues/3
|
||||
|
||||
## Goal
|
||||
|
||||
Make the extension installable with `pi install npm:pi-nous-portal` and listed on https://pi.dev/packages, with a repeatable local release. Grew out of the research in #2.
|
||||
|
||||
## What Was Done
|
||||
|
||||
- Researched the gallery. It lists only npm packages that carry the `pi-package` keyword, and a git source installs but never lists. Posted that as the resolution of #2 and closed it.
|
||||
- Settled the publishing decisions with Alexander: npm, unscoped `pi-nous-portal`, Gitea as `repository`, labelled unofficial, semver with a `v0.1.0` tag, a local `publish.sh` instead of CI. Recorded on #3.
|
||||
- `package.json`: added `"pi": { "extensions": ["./index.ts"] }`, `repository`, `homepage`, `bugs`, `"files": ["index.ts", "CHANGELOG.md"]`, and "Unofficial, community-maintained" in `description`.
|
||||
- `publish.sh`: guards (clean tree, `main`, `npm whoami`), `npm run check`, `npm pack --dry-run`, changelog heading rename, commit, tag, `npm publish`, `git push --follow-tags`.
|
||||
- `README.md`: the install section now leads with `pi install npm:pi-nous-portal`, a new Releasing section, and an edit pass for a plainer voice at Alexander's request.
|
||||
- `CHANGELOG.md`: entry under Unreleased.
|
||||
- `AGENTS.md`, `docs/AGENTS.md`, `docs/adr/0003-forge-and-ci.md`: release steps and the manifest rule recorded.
|
||||
|
||||
Verified before stopping: `npm run check` (25 tests pass), `shellcheck`, `npm pack --dry-run` (5 files: `CHANGELOG.md`, `LICENSE`, `README.md`, `index.ts`, `package.json`), the dirty-tree guard stops the script with exit 1, the changelog rename turns `## [Unreleased]` into `## [0.1.0] - 2026-11-25` on a copy, and `npm version patch --no-git-tag-version` bumps a copy to 0.1.1.
|
||||
|
||||
## Decisions & Rationale
|
||||
|
||||
| Decision | Rationale |
|
||||
|----------|-----------|
|
||||
| Publish to npm, not a git source | The gallery indexes npm only. The issue asked "npm or git", and only npm reaches the destination. |
|
||||
| Keep the unscoped name `pi-nous-portal` | Already in `package.json`, unused on npm, and it matches most gallery entries. A scope would have needed an npm org. |
|
||||
| `publish.sh` over CI | Alexander asked for a script, not a pipeline. The instance has Actions enabled but no runner, and npm's trusted publishers exclude Gitea Actions, so CI would also have needed a bypass-2FA token. |
|
||||
| A `pi.extensions` manifest instead of moving `index.ts` | Moving the file would touch `tsconfig.json`, the tests that load `index.ts`, and the symlink install. One manifest entry leaves all three alone. |
|
||||
| Label the package unofficial | It carries Nous in its name and ships the public `hermes-cli` client id. The label keeps it from reading as a Nous product. |
|
||||
| No new ADR | The release setup is reversible, and the no-CI decision is already `0003-forge-and-ci.md`, which gained one sentence. |
|
||||
|
||||
## Gotchas & Fixes
|
||||
|
||||
| Problem | Root Cause | Fix |
|
||||
|---------|------------|-----|
|
||||
| A package install of the old tree would load no extension | pi 1.6.0's `collectDefaultResources` (`core/package-manager.js`) reads `manifest[resourceType]` or scans `<packageRoot>/extensions/`. A root `index.ts` is only found by the legacy `~/.pi/agent/extensions/` loader, which is why the symlink install works. | Add `"pi": { "extensions": ["./index.ts"] }`. |
|
||||
| The gallery would have shown no repo link | `package.json` had no `repository` field. | Added `repository`, `homepage` and `bugs`. |
|
||||
| `tests/`, `docs/` and `tsconfig.json` would have shipped | No `files` whitelist, so npm fell back to `.gitignore`. | `"files": ["index.ts", "CHANGELOG.md"]`. |
|
||||
| I read "automated publishing" as CI and wrote a runner-and-token plan | An assumption that was never asked for. | Alexander corrected it. #3 now describes `publish.sh`. |
|
||||
| `package.json` ended up with two `description` keys | The edit tool auto-relocated the line anchor to the wrong line and inserted instead of replacing. | Replaced both lines with one. `JSON.parse` takes the last key, so `npm pack` had hidden it. |
|
||||
|
||||
## Files Changed
|
||||
|
||||
| File | Change Summary |
|
||||
|------|---------------|
|
||||
| `publish.sh` | New release script |
|
||||
| `package.json` | `pi` manifest, `files`, repo links, description |
|
||||
| `README.md` | Install and Releasing sections, edit pass |
|
||||
| `CHANGELOG.md` | Unreleased entry for the npm package |
|
||||
| `AGENTS.md` | Release command, manifest rule, release convention, log window |
|
||||
| `docs/AGENTS.md` | ADR 0003 one-liner mentions `publish.sh` |
|
||||
| `docs/adr/0003-forge-and-ci.md` | One sentence on the local release gate |
|
||||
| `docs/devlog/INDEX.md` | Row for this log |
|
||||
|
||||
## Open Items & Next Steps
|
||||
|
||||
- [ ] Run `./publish.sh`. It prompts for the npm 2FA code. Not run in this session.
|
||||
- [ ] After the publish, check `pi -e npm:pi-nous-portal` in a throwaway agent dir, then `/login nous-portal`.
|
||||
- [ ] Confirm the package shows up on https://pi.dev/packages.
|
||||
- [ ] Close #3 once the listing is live.
|
||||
|
||||
---
|
||||
|
||||
*Log written by write-log skill*
|
||||
@@ -5,6 +5,7 @@ Complete history of session logs in this directory, newest first. One-line summa
|
||||
<!-- write-log: full-index -->
|
||||
| Date | Type | File | Summary |
|
||||
|------|------|------|---------|
|
||||
| 2026-11-25 | issue | [20261125-issue03-publish-pi-nous-portal-to-npm_log.md](20261125-issue03-publish-pi-nous-portal-to-npm_log.md) | npm package made publishable (manifest, `files`, repo links, `publish.sh`) and README edited, publish still pending |
|
||||
| 2026-11-25 | generic | [20261125-finish-audit-architecture-review-unit_log.md](20261125-finish-audit-architecture-review-unit_log.md) | Two-round finish audit of the carrier move and clock seam: two code nits and a test-hang guard fixed, then a docs-only round |
|
||||
| 2026-11-25 | generic | [20261125-architecture-review-tier-property-and-login-clock_log.md](20261125-architecture-review-tier-property-and-login-clock_log.md) | Architecture review: tier moves from a request header to a model property, `login` gains a clock seam, poll loop now tested |
|
||||
| 2026-11-25 | generic | [20261125-fresh-context-audit-rounds-1-5_log.md](20261125-fresh-context-audit-rounds-1-5_log.md) | Five-round fresh-context audit of the Nous Portal provider: two P1s surfaced in round 3, clean in round 5 |
|
||||
+16
-2
@@ -1,9 +1,23 @@
|
||||
{
|
||||
"name": "pi-nous-portal",
|
||||
"version": "0.1.0",
|
||||
"description": "Nous Portal provider for pi: subscription OAuth and API key, no agent-key minting.",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"description": "Unofficial, community-maintained Nous Portal provider for pi: subscription OAuth and API key, no agent-key minting.",
|
||||
"type": "module",
|
||||
"homepage": "https://git.babylondreams.de/AlexKucera/nous-portal",
|
||||
"bugs": "https://git.babylondreams.de/AlexKucera/nous-portal/issues",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.babylondreams.de/AlexKucera/nous-portal.git"
|
||||
},
|
||||
"files": [
|
||||
"index.ts",
|
||||
"CHANGELOG.md"
|
||||
],
|
||||
"pi": {
|
||||
"extensions": [
|
||||
"./index.ts"
|
||||
]
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
},
|
||||
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
# Release pi-nous-portal to npm and push the tag.
|
||||
#
|
||||
# ./publish.sh release the version in package.json
|
||||
# ./publish.sh patch bump first (minor, major, or an explicit version work too)
|
||||
#
|
||||
# npm asks for your 2FA code at the publish step. If the publish fails after
|
||||
# the tag exists, fix the cause and rerun: npm publish && git push origin main --follow-tags
|
||||
set -euo pipefail
|
||||
|
||||
bump="${1:-}"
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
[ -z "$(git status --porcelain)" ] || { echo "working tree is not clean" >&2; exit 1; }
|
||||
[ "$(git branch --show-current)" = "main" ] || { echo "not on main" >&2; exit 1; }
|
||||
npm whoami >/dev/null
|
||||
|
||||
if [ -n "$bump" ]; then
|
||||
npm version "$bump" --no-git-tag-version
|
||||
fi
|
||||
version=$(node -p "require('./package.json').version")
|
||||
|
||||
grep -qx '## \[Unreleased\]' CHANGELOG.md || { echo "CHANGELOG.md has no '## [Unreleased]' heading" >&2; exit 1; }
|
||||
|
||||
npm run check
|
||||
npm pack --dry-run
|
||||
|
||||
# The Unreleased section becomes the entry for this version.
|
||||
perl -0pi -e "s/^## \[Unreleased\]\$/## [$version] - $(date +%F)/m" CHANGELOG.md
|
||||
|
||||
git commit -am "release v$version"
|
||||
git tag -a "v$version" -m "v$version"
|
||||
npm publish
|
||||
git push origin main --follow-tags
|
||||
Reference in new issue
Block a user