From b71363efb9043884fd66b78a0dbeb2b7980c76e6 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Wed, 25 Nov 2026 16:51:36 +0100 Subject: [PATCH] build: move release scripts and harden publish publish.sh and test_npm_package.sh now live in scripts/ and cd to the repo root, so they run from any directory. publish.sh polls npm until the released version resolves: the first release ended inside the registry's processing window, when a fresh install still gets the 0.0.0-stage placeholder. It also reopens an empty Unreleased section after the rename and refuses an empty one before the version bump, so a refused release leaves the tree clean. test_npm_package.sh switches pi between the symlink checkout and npm:pi-nous-portal. Only one may be installed: pi identifies npm packages by name and local ones by path, so both register the provider twice. --- AGENTS.md | 15 ++++- CHANGELOG.md | 2 + README.md | 6 +- ...sue03-publish-pi-nous-portal-to-npm_log.md | 2 + ...se-scripts-npm-wait-toggle-and-move_log.md | 60 +++++++++++++++++++ docs/devlog/INDEX.md | 1 + publish.sh => scripts/publish.sh | 11 ++-- scripts/test_npm_package.sh | 57 ++++++++++++++++++ 8 files changed, 146 insertions(+), 8 deletions(-) create mode 100644 docs/devlog/20261125-release-scripts-npm-wait-toggle-and-move_log.md rename publish.sh => scripts/publish.sh (72%) create mode 100755 scripts/test_npm_package.sh diff --git a/AGENTS.md b/AGENTS.md index 9abfad5..3f49f95 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -9,7 +9,8 @@ - `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. +- `./scripts/test_npm_package.sh`: switches pi between the symlink checkout and the published npm package; `dev` or `npm` picks a side. Keep only one installed: pi identifies npm packages by name and local ones by path, so both at once register the provider twice. +- `./scripts/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 @@ -26,7 +27,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]`. npm answers with a placeholder version (`0.0.0-stage`) for about four minutes after the publish; a fresh install in that window loads no models, and the script waits until the real version resolves. The pi.dev/packages gallery lags further behind. +- **Releases are local, through `scripts/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 and opens a fresh `Unreleased` section above it, so new entries always go under `## [Unreleased]`. It refuses a release whose `Unreleased` section is empty. npm answers with a placeholder version (`0.0.0-stage`) for about four minutes after the publish; a fresh install in that window loads no models, and the script waits until the real version resolves. The pi.dev/packages gallery lags further behind. ## Catalog tiers @@ -124,6 +125,15 @@ When the user requests a durable behavior change, record it here or in the relev | [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 | +## Project Learnings + + + +### Release tooling + +- Keep every `scripts/publish.sh` guard ahead of the version bump: a refusal after `npm version` leaves `package.json` modified (`release-scripts-npm-wait-toggle-and-move`) +- Rehearse `scripts/publish.sh` in a scratch repo with a stubbed `npm` first on `PATH` and a local bare remote: it exercises checks, commit, tag, push and the publish call without touching npm or Gitea (`release-scripts-npm-wait-toggle-and-move`) + ## 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: @@ -131,6 +141,7 @@ Session logs live in `docs/devlog/` (one per completed task/issue/milestone). Fu | Date | Log | |------|-----| +| 2026-11-25 | [20261125-release-scripts-npm-wait-toggle-and-move_log.md](docs/devlog/20261125-release-scripts-npm-wait-toggle-and-move_log.md) | | 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) | diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b9111b..07364a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. The format is based on [Common Changelog](https://common-changelog.org) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + ## [0.1.0] - 2026-11-25 ### Added diff --git a/README.md b/README.md index de0cfd3..c1d6022 100644 --- a/README.md +++ b/README.md @@ -66,11 +66,13 @@ npm run check # tsc --noEmit + node --test 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//`, 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. +`./scripts/test_npm_package.sh` switches pi between this checkout and the published package, so you can try a release without hunting for the symlink. Run it with `dev` or `npm` to pick a side. + ## Releasing ```bash -./publish.sh # release the version in package.json -./publish.sh patch # bump first; minor and major work too +./scripts/publish.sh # release the version in package.json +./scripts/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. npm then takes a few minutes to serve the new version, and the script waits until it resolves. You need `npm login` with publish rights to the package first. diff --git a/docs/devlog/20261125-issue03-publish-pi-nous-portal-to-npm_log.md b/docs/devlog/20261125-issue03-publish-pi-nous-portal-to-npm_log.md index 2f12be5..34189f6 100644 --- a/docs/devlog/20261125-issue03-publish-pi-nous-portal-to-npm_log.md +++ b/docs/devlog/20261125-issue03-publish-pi-nous-portal-to-npm_log.md @@ -65,6 +65,8 @@ Verified before stopping: `npm run check` (25 tests pass), `shellcheck`, `npm pa Published. `./publish.sh` ran with the 2FA prompt, pushed `release v0.1.0` (e534b27) and tag `v0.1.0`. npm answered with a placeholder version `0.0.0-stage` for about four minutes ("Your package is being processed and may take a few minutes to become available"). A fresh-agent-dir install in that window listed no Nous models. At 15:19:25 UTC `latest` became `0.1.0`, and `pi -e npm:pi-nous-portal@0.1.0 --list-models` in a fresh agent dir listed 8 `nous-portal` models with an empty stderr. `publish.sh` now waits until the registry serves the version. The pi.dev/packages gallery still returned 404 at 15:26 UTC, so issue #3 stays open until the listing is live. +Follow-up: the release tooling that came after this log (the npm wait, the dev/npm toggle script, the move to `scripts/`) is recorded in [20261125-release-scripts-npm-wait-toggle-and-move_log.md](20261125-release-scripts-npm-wait-toggle-and-move_log.md). + --- *Log written by write-log skill* diff --git a/docs/devlog/20261125-release-scripts-npm-wait-toggle-and-move_log.md b/docs/devlog/20261125-release-scripts-npm-wait-toggle-and-move_log.md new file mode 100644 index 0000000..902c613 --- /dev/null +++ b/docs/devlog/20261125-release-scripts-npm-wait-toggle-and-move_log.md @@ -0,0 +1,60 @@ +# Release scripts: npm wait, dev/npm toggle, scripts/ folder + +> **Date:** 2026-11-25 +> **Type:** generic +> **Reference:** follow-up to https://git.babylondreams.de/AlexKucera/nous-portal/issues/3 + +## Goal + +Make the release script trustworthy after the first real publish, add a way to switch pi between this checkout and the published npm package, and keep both scripts runnable from any directory once they moved into `scripts/`. + +## What Was Done + +- `scripts/publish.sh` (moved from the repo root) waits until `npm view @` resolves, for at most ten minutes. Before the publish it opens a fresh `Unreleased` section and refuses an empty one. The guard runs before the version bump. +- `scripts/test_npm_package.sh` is new. With no argument it toggles between the symlink checkout and `npm:pi-nous-portal`; `dev` or `npm` forces a side. It removes whichever install is not wanted, honors `PI_CODING_AGENT_DIR`, and prints how many `nous-portal` models the next pi start lists. +- Both scripts `cd` to the repo root. `README.md` and `AGENTS.md` name the new paths. +- `CHANGELOG.md` has an empty `Unreleased` section again, the state the script now leaves after each release. +- Verified: the toggle matrix in a temporary agent dir, from three working directories. The whole release flow ran in a scratch repo with a stubbed `npm publish` and `npm view` and a local bare remote: a `patch` bump to 0.1.1, 25 tests, 5 files in the tarball, commit, tag and push. npm and Gitea were untouched. + +## Decisions & Rationale + +| Decision | Rationale | +|----------|-----------| +| Poll npm at the end of `publish.sh` | The first release ended inside the registry's processing window. The script's exit now means `pi install` works. Ten minutes caps a stuck registry. | +| Reopen `Unreleased` in the script | Common Changelog keeps an `Unreleased` section. The first release consumed it, and the next release would have been refused until someone re-added it by hand. | +| Refuse an empty `Unreleased`, before the bump | A release needs an entry, and a refused release must leave the tree clean. After the bump it would leave `package.json` modified. | +| The toggle keeps exactly one install | pi identifies npm packages by name and local ones by path, so both at once load and register the provider twice. | +| Honor `PI_CODING_AGENT_DIR` in the toggle | It lets the script be tested against a temporary agent dir without touching the real one. | +| Plain `rm` on the symlink | `-r` or a trailing slash would delete the checkout. | +| No `scripts/AGENTS.md` | Two scripts with no separate rules. The root `AGENTS.md` documents both. | +| `git mv` for `publish.sh`, plain `mv` for the new script | The tracked file keeps its rename history. The other was never committed. | + +## Gotchas & Fixes + +| Problem | Root Cause | Fix | +|---------|------------|-----| +| The toggle created no symlink in a fresh agent dir and printed nothing after `pi remove` | `extensions/` does not exist there, `ln -s` failed, and `set -e` stopped the script. | `mkdir -p` on the link's directory. | +| A scratch run of `publish.sh` was refused with "no Unreleased heading" | The first release had consumed the section. | The script reopens it, and the guard now asks for an entry. | +| A refusal after the bump would leave `package.json` modified | The guard ran after `npm version`. | Guard moved above the bump. The rerun test shows the version unchanged, a clean tree and no publish. | +| Both scripts would have broken after the move | `cd "$(dirname "$0")"` resolves to `scripts/`. | `cd "$(dirname "$0")/.."`, tested from three directories. | + +## Files Changed + +| File | Change Summary | +|------|---------------| +| `scripts/publish.sh` | Moved. npm wait, `Unreleased` reopen and guard. | +| `scripts/test_npm_package.sh` | New dev/npm toggle | +| `CHANGELOG.md` | Empty `Unreleased` section reopened | +| `README.md`, `AGENTS.md` | New script paths | +| `docs/devlog/INDEX.md`, `AGENTS.md` log window | Row for this log | +| `docs/devlog/20261125-issue03-publish-pi-nous-portal-to-npm_log.md` | Follow-up paragraph replaced by a pointer to this log | + +## Open Items & Next Steps + +- [ ] The pi.dev/packages listing was still missing at the last check. Confirm it and close #3. +- [ ] The npm wait and the changelog reopen have only run against stubs. The first real release that uses them confirms them. +- [ ] The login flow through the installed npm package is untested. + +--- + +*Log written by write-log skill* diff --git a/docs/devlog/INDEX.md b/docs/devlog/INDEX.md index 979d289..a5d4fcb 100644 --- a/docs/devlog/INDEX.md +++ b/docs/devlog/INDEX.md @@ -5,6 +5,7 @@ Complete history of session logs in this directory, newest first. One-line summa | Date | Type | File | Summary | |------|------|------|---------| +| 2026-11-25 | generic | [20261125-release-scripts-npm-wait-toggle-and-move_log.md](20261125-release-scripts-npm-wait-toggle-and-move_log.md) | publish.sh waits for npm and reopens Unreleased, dev/npm toggle script added, both moved to scripts/ | | 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 | diff --git a/publish.sh b/scripts/publish.sh similarity index 72% rename from publish.sh rename to scripts/publish.sh index a35dae3..eeed8dd 100755 --- a/publish.sh +++ b/scripts/publish.sh @@ -9,11 +9,14 @@ set -euo pipefail bump="${1:-}" -cd "$(dirname "$0")" +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 +# A release needs at least one entry under Unreleased. +awk '/^## \[Unreleased\]$/ { section = 1; next } /^## / { section = 0 } section && NF { entry = 1 } END { exit entry ? 0 : 1 }' CHANGELOG.md \ + || { echo "CHANGELOG.md needs an entry under '## [Unreleased]'" >&2; exit 1; } if [ -n "$bump" ]; then npm version "$bump" --no-git-tag-version @@ -21,13 +24,13 @@ fi version=$(node -p "require('./package.json').version") name=$(node -p "require('./package.json').name") -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 +# The Unreleased section becomes the entry for this version, and a fresh +# Unreleased section opens above it. +perl -0pi -e "s/^## \[Unreleased\]\$/## [Unreleased]\n\n## [$version] - $(date +%F)/m" CHANGELOG.md git commit -am "release v$version" git tag -a "v$version" -m "v$version" diff --git a/scripts/test_npm_package.sh b/scripts/test_npm_package.sh new file mode 100755 index 0000000..638c272 --- /dev/null +++ b/scripts/test_npm_package.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# Switch pi between this checkout (a symlink) and the published npm package. +# +# ./test_npm_package.sh toggle to whichever is not active +# ./test_npm_package.sh dev load this checkout +# ./test_npm_package.sh npm load the published package +# +# Only one of the two may be installed. pi identifies an npm package by name +# and a local one by path, so both at once register the provider twice. +# Takes effect on the next pi start or /reload. +set -euo pipefail + +cd "$(dirname "$0")/.." +name=$(node -p "require('./package.json').name") +provider=nous-portal +agent_dir="${PI_CODING_AGENT_DIR:-$HOME/.pi/agent}" +repo="$PWD" +link="$agent_dir/extensions/$provider" + +npm_installed() { + node -e " + const packages = require('$agent_dir/settings.json').packages || []; + const source = 'npm:$name'; + process.exit(packages.some(p => (typeof p === 'string' ? p : p.source) === source) ? 0 : 1); + " 2>/dev/null +} + +if [ -n "${1:-}" ]; then + target="$1" +elif [ -e "$link" ] || [ -L "$link" ]; then + target=npm +elif npm_installed; then + target=dev +else + target=npm +fi + +case "$target" in + dev) + if npm_installed; then pi remove "npm:$name"; fi + mkdir -p "$(dirname "$link")" + if [ ! -e "$link" ] && [ ! -L "$link" ]; then ln -s "$repo" "$link"; fi + echo "dev: $link -> $repo" + ;; + npm) + # Plain rm on the symlink. A trailing slash or -r would delete the checkout. + if [ -e "$link" ] || [ -L "$link" ]; then rm "$link"; fi + if ! npm_installed; then pi install "npm:$name"; fi + echo "npm: npm:$name in $agent_dir/settings.json" + ;; + *) + echo "usage: $0 [dev|npm]" >&2 + exit 1 + ;; +esac + +echo "$provider models on the next start: $(pi --list-models 2>/dev/null | grep -c -w "$provider")"