Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:
browser="$(command -v google-chrome || command -v chromium || command -v chromium-browser)"
test -n "$browser"
echo "RETENTION_BROWSER=$browser" >> "$GITHUB_ENV"
- name: Test release preflight with synthetic inputs
if: matrix.os == 'ubuntu-latest'
run: pnpm check:release-preflight
- run: pnpm check
env:
RETENTION_CANDIDATE_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
Expand Down
75 changes: 75 additions & 0 deletions .github/workflows/release-audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Release candidate audit

on:
pull_request:
paths:
- CHANGELOG.md
- package.json
- pnpm-lock.yaml
- .github/workflows/release-audit.yml
- .github/workflows/release.yml
- scripts/release-preflight.sh
- scripts/stage-release.sh
- tests/release-preflight.sh
push:
branches: [main]
paths:
- CHANGELOG.md
- package.json
- pnpm-lock.yaml
- .github/workflows/release-audit.yml
- .github/workflows/release.yml
- scripts/release-preflight.sh
- scripts/stage-release.sh
- tests/release-preflight.sh
workflow_dispatch:

permissions:
contents: read

jobs:
audit:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
persist-credentials: false
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- uses: pnpm/action-setup@v6
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24.22.3
package-manager-cache: false
- name: Check public registry version
run: |
set -euo pipefail
git rev-parse HEAD
version="$(node -p 'require("./package.json").version')"
status="$(curl --silent --show-error --max-time 30 --retry 2 \
--output "$RUNNER_TEMP/retention-packument.json" --write-out '%{http_code}' \
--header 'Accept: application/vnd.npm.install-v1+json' \
'https://registry.npmjs.org/@0xbuff%2fretention')"
echo "Public registry HTTP status: $status"
case "$status" in
404)
echo "No publicly visible package metadata. Scope ownership and staged/private versions need authenticated owner verification."
;;
200)
jq -e '.name == "@0xbuff/retention" and (.versions | type == "object")' "$RUNNER_TEMP/retention-packument.json" >/dev/null
if jq -e --arg v "$version" '.versions | has($v)' "$RUNNER_TEMP/retention-packument.json" >/dev/null; then
echo "::error::Candidate version $version is already public"
exit 1
fi
echo "Candidate version $version is not present in the public version list."
;;
*)
echo "::error::Registry status is inconclusive"
exit 1
;;
esac
- name: Audit locked development dependencies
if: always()
run: |
set -euo pipefail
pnpm audit --json --registry=https://registry.npmjs.org/
48 changes: 48 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Stage npm package

on:
workflow_dispatch:
inputs:
quality_run_id:
description: Successful main quality run ID
required: true
type: string

permissions: {}

concurrency:
group: retention-npm-stage
cancel-in-progress: false

jobs:
stage:
if: github.repository == '0xbuffdev/retention' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 10
environment: npm-stage
permissions:
contents: read
actions: read
id-token: write
steps:
- name: Check out exact staging commit
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
ref: ${{ github.sha }}
persist-credentials: false

- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24.22.3
package-manager-cache: false

- name: Verify and stage exact approved archive
env:
GH_TOKEN: ${{ github.token }}
RUN_ID: ${{ inputs.quality_run_id }}
APPROVED_RUN_ID: ${{ vars.RETENTION_STAGE_RUN_ID }}
APPROVED_SHA: ${{ vars.RETENTION_STAGE_COMMIT }}
APPROVED_DIGEST: ${{ vars.RETENTION_STAGE_SHA256 }}
NPM_CONFIG_REGISTRY: https://registry.npmjs.org/
run: bash scripts/stage-release.sh
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ Use `pnpm exec vitest run <test-path>` for focused tests. Run `pnpm check:archit

- Prioritize nondeterminism, incorrect time arithmetic, invalid lifecycle acceptance, deleted-history resurrection, practice-to-credit leakage, policy/prefix mismatch, resource-bound bypasses, unsafe diagnostics, dependency violations and weakened gates. Include file/line, triggering condition, impact and a testable correction.
- PRs must identify the ticket where applicable, requirement coverage, changes, tests and outstanding limitations. Do not mark tickets complete without required review, merge and acceptance evidence.
- Obtain maintainer approval for each publication. Preserve Apache-2.0 and copyright notices, and verify source and contributor rights. Follow [release policy](docs/releasing.md): check the exact ESM/types archive, explicit archive/export allowlists and independent offline Node/TypeScript and browser consumers. Host integration requires separate acceptance.
- Obtain maintainer approval for each publication. Preserve Apache-2.0 and copyright notices, and verify source and contributor rights. Follow [release policy](docs/releasing.md): check the exact ESM/types archive, explicit archive/export allowlists and independent offline Node/TypeScript and browser consumers. Host integration requires separate acceptance. Release staging uses the protected manual OIDC workflow; keep it stage-only, validate the approved main commit and exact CI archive, and require interactive npm approval. Never store npm publishing tokens in CI.
- No merge, tag, publication, deployment, maintainer signing, relicensing or repository ownership/visibility change without explicit maintainer authorization.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ Notable changes to Retention are recorded here. The format follows [Keep a Chang

## [Unreleased]

## [0.0.2] - 2026-11-29

### Changed

- Updated public documentation, installation guidance, event reference and architecture diagrams.
- Made packed-package verification use the version in the package manifest.
- Added protected, stage-only npm trusted publishing with exact CI artifact checks and synthetic preflight tests.
- Added a read-only release audit for registry version availability and locked development dependencies.

### Fixed

- Retry temporary browser profile removal on transient filesystem errors during package verification.

## [0.0.1] - 2026-11-29

### Added
Expand Down
2 changes: 1 addition & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ The source build targets ES2022 without Node ambient types or DOM APIs. Test and

The verifier checks the archive inventory and digest, installs the package offline in a temporary project, compiles a TypeScript consumer and the README quick start, and runs both against the installed package. The Ubuntu CI job also exercises the installed library in Chromium. Consult the release evidence for the tested browser version; older Chromium versions, Firefox and Safari have not been verified by these checks.

Run `pnpm verify:package` after building to verify the exact tarball and independent offline Node/TypeScript consumer. Set `RETENTION_BROWSER` to a Chromium executable on Linux to exercise the browser consumer too. See the [release policy](releasing.md) for release verification and [contributing](../CONTRIBUTING.md) for proposed changes.
Run `pnpm verify:package` after building to verify the exact tarball and independent offline Node/TypeScript consumer. Set `RETENTION_BROWSER` to a Chromium executable on Linux to exercise the browser consumer too. On Ubuntu, run `pnpm check:release-preflight` to exercise release approval and staging checks with synthetic archives and stub commands. The Ubuntu CI job runs these tests. See the [release policy](releasing.md) for release verification and [contributing](../CONTRIBUTING.md) for proposed changes.
20 changes: 16 additions & 4 deletions docs/releasing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Releasing Retention

Retention is published as [`@0xbuff/retention`](https://www.npmjs.com/package/@0xbuff/retention). Releases use Semantic Versioning. Pin tested versions before 1.0.0. Maintainers publish approved archives through npm; CI does not publish automatically.
Retention is published as [`@0xbuff/retention`](https://www.npmjs.com/package/@0xbuff/retention). Releases use Semantic Versioning. Pin tested versions before 1.0.0. A protected manual workflow stages the approved archive using npm trusted publishing. A maintainer approves publication separately.

## Prepare a release

Expand All @@ -12,6 +12,8 @@ pnpm install --frozen-lockfile
pnpm check
```

On Ubuntu, run `pnpm check:release-preflight` with Bash, jq, OpenSSL and GNU tar/coreutils. The tests use synthetic archives and stubbed GitHub and npm commands; they do not contact npm or stage a package.

## Verify the candidate

The package check packs the built files with npm, checks the exact archive allowlist and integrity, and installs the tarball offline outside the checkout. It compiles and executes a TypeScript consumer and the README quick start against the installed root export. It rejects unexpected files, runtime dependencies, install hooks and external module imports.
Expand All @@ -28,13 +30,23 @@ Compare the source SHA, archive SHA-256, npm SHA-512 integrity, byte count, file

## Release approval

Before accepting a candidate, review the changed behavior, applicable acceptance tests, exact source, package contents and security. Record verified runtime versions and limitations. Confirm ownership and contributor rights, license and notices, registry scope access and version availability. Obtain explicit maintainer approval for the source commit, successful CI run and verified archive digest before publishing. CI never publishes, tags or signs a release.
Before accepting a candidate, review the changed behavior, applicable acceptance tests, exact source, package contents and security. Record verified runtime versions and limitations. Confirm ownership and contributor rights, license and notices, registry scope access and version availability. Run the read-only Release candidate audit workflow and review the registry version check and locked dependency audit. Confirm the version is not already staged or published using the authenticated npm account. Obtain explicit maintainer approval for the current main commit, successful main quality run and verified archive digest. CI does not directly publish, tag or sign a release.

Applications are responsible for testing admission, authorization, grade invariance, deletion, delivery and stale-generation rejection in their own integrations.

## Publish and verify
## Stage with trusted publishing

The Stage npm package workflow runs manually on main. It uses the protected `npm-stage` environment and GitHub Actions OIDC. It verifies the successful main quality run, downloads the exact Ubuntu archive, checks the evidence, browser result, package metadata and archive digest, then rechecks main and the digest immediately before staging. It does not build or directly publish.

1. Configure the GitHub environment `npm-stage` for main only, require reviewers and disable administrator bypass. Prevent self-review when a separate reviewer is available.
2. Configure [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/) for `0xbuffdev/retention`, workflow `release.yml`, environment `npm-stage`. Allow staging only; disable direct publishing and dist-tag management. Do not store an npm token in CI.
3. Set environment variables `RETENTION_STAGE_COMMIT`, `RETENTION_STAGE_RUN_ID` and `RETENTION_STAGE_SHA256` to the approved main commit, quality run ID and archive SHA-256. Both CI archives must match. If an attempt lacks either archive after a partial rerun, rerun all quality jobs before approving.
4. Dispatch the workflow with the approved run ID and approve the environment deployment. Inspect the staged version and compare its tarball digest to the approved archive.
5. With explicit publication approval, approve the staged version through npm using the required interactive authentication. Clear the approval variables when finished.

## Verify publication

Publish the approved tarball through an authenticated npm account with public access and scripts disabled. If npm stages the package, inspect the staged version and approve it with the required authentication. Do not rebuild or republish while approval is pending. After publication, compare `npm view @0xbuff/retention@<version> dist.integrity` with the candidate evidence, then install the exact version in a temporary consumer outside the checkout and import the root API. Keep the verified source commit, artifact digest and registry integrity in the release record. Tag the source of the published artifact, not a subsequent documentation-only commit.
Download the public registry tarball and compare its SHA-256 with the approved archive. Check the registry version, dist-tag, integrity, signatures and available build provenance. Install the exact version with scripts disabled in a temporary ESM project outside the checkout and import the root API. Run the quick start against the installed package. Record the verified source commit, artifact digest, registry integrity and consumer results. Create the authorized tag and GitHub release for that source commit, not a later documentation change.

## Correct a published release

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0xbuff/retention",
"version": "0.0.1",
"version": "0.0.2",
"description": "Deterministic review scheduling for learning and long-term retention",
"private": false,
"license": "Apache-2.0",
Expand Down Expand Up @@ -40,7 +40,8 @@
"check:architecture": "node scripts/check-architecture.mjs",
"verify:dist": "node scripts/verify-dist.mjs",
"check": "pnpm check:architecture && pnpm typecheck && pnpm check:style && pnpm test && pnpm build && pnpm verify:package",
"verify:package": "node scripts/verify-package.mjs"
"verify:package": "node scripts/verify-package.mjs",
"check:release-preflight": "bash tests/release-preflight.sh"
},
"devDependencies": {
"@biomejs/biome": "2.6.8",
Expand Down
102 changes: 102 additions & 0 deletions scripts/release-preflight.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env bash
# Read-only candidate validation; no credentials, network, or npm operations.
set -euo pipefail

fail() {
printf 'Release preflight: %s\n' "$1" >&2
exit 1
}

approval() {
[[ "${GITHUB_REPOSITORY:-}" == "0xbuffdev/retention" ]] || fail repository
[[ "${GITHUB_REF:-}" == "refs/heads/main" ]] || fail branch
[[ "${RUN_ID:-}" =~ ^[1-9][0-9]*$ ]] || fail run-id
[[ "${APPROVED_RUN_ID:-}" == "$RUN_ID" ]] || fail approved-run-id
[[ "${APPROVED_SHA:-}" =~ ^[a-f0-9]{40}$ && "$APPROVED_SHA" == "$GITHUB_SHA" ]] || fail approved-sha
[[ "${APPROVED_DIGEST:-}" =~ ^[a-f0-9]{64}$ ]] || fail approved-digest
}

archive_files() {
printf '%s\n' CHANGELOG.md COPYRIGHT.md LICENSE README.md \
dist/index.d.ts dist/index.js package.json
}

root="$(cd "$(dirname "$0")/.." && pwd)"
version="$(jq -er '.version | strings' "$root/package.json")" || fail package-version
[[ "$version" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]] || fail package-version
archive="0xbuff-retention-$version.tgz"

approval
case "$1" in
filename)
[[ "$#" == 1 ]] || fail arguments
printf '%s\n' "$archive"
;;
approval)
[[ "$#" == 1 ]] || fail arguments
;;
run)
[[ "$#" == 3 ]] || fail arguments
[[ "$2" == "$GITHUB_SHA" ]] || fail stale-main
jq -e --arg sha "$GITHUB_SHA" --arg repo "$GITHUB_REPOSITORY" --arg id "$RUN_ID" '
(.id | tostring) == $id and
.head_sha == $sha and .head_branch == "main" and
.head_repository.full_name == $repo and .repository.full_name == $repo and
.path == ".github/workflows/ci.yml" and .event == "push" and
.status == "completed" and .conclusion == "success" and
(.run_attempt | type == "number" and . >= 1 and floor == .)
' "$3" >/dev/null || fail quality-run
attempt="$(jq -er '.run_attempt' "$3")"
[[ "$attempt" =~ ^[1-9][0-9]*$ ]] || fail run-attempt
printf '%s\n' "$attempt"
;;
archive)
[[ "$#" == 4 ]] || fail arguments
[[ "$3" =~ ^[1-9][0-9]*$ ]] || fail run-attempt
[[ "$4" == "retention-candidate-ubuntu-latest-$GITHUB_SHA-$3" ]] || fail artifact-name
cd "$2"
[[ -f "$archive" && ! -L "$archive" && -f evidence.json && ! -L evidence.json ]] || fail artifact-files
[[ "$(find . -mindepth 1 -maxdepth 1 | wc -l)" -eq 2 ]] || fail artifact-files
[[ "$(sha256sum "$archive" | cut -d ' ' -f 1)" == "$APPROVED_DIGEST" ]] || fail archive-digest
integrity="sha512-$(openssl dgst -sha512 -binary "$archive" | openssl base64 -A)"
jq -e --arg digest "$APPROVED_DIGEST" --argjson size "$(wc -c < "$archive")" \
--arg commit "$GITHUB_SHA" --arg integrity "$integrity" --arg version "$version" --arg archive "$archive" '
.name == "@0xbuff/retention" and .version == $version and
.commit == $commit and .platform == "linux" and
(.node | type == "string" and test("^v24\\.")) and
(.browser | type == "string" and length > 0) and
(.checks | sort) == ["archive","browser","node","offline-install","typescript"] and
.filename == $archive and .integrity == $integrity and
.sha256 == $digest and .bytes == $size and
(.files | sort) == [
"CHANGELOG.md", "COPYRIGHT.md", "LICENSE", "README.md",
"dist/index.d.ts", "dist/index.js", "package.json"
]
' evidence.json >/dev/null || fail archive-manifest
expected="$(archive_files | sed 's|^|package/|')"
actual="$(tar -tzf "$archive" | LC_ALL=C sort)"
[[ "$actual" == "$expected" ]] || fail archive-contents
# Require regular files only; no symlink, hardlink or directory entries.
tar -tvzf "$archive" | awk 'substr($0,1,1) != "-" { bad=1 } END { exit bad }' || fail archive-types
tar -xOzf "$archive" package/package.json | jq -e --arg version "$version" '
.name == "@0xbuff/retention" and .version == $version and
.private == false and .license == "Apache-2.0" and .type == "module" and
.publishConfig.access == "public" and
.publishConfig.registry == "https://registry.npmjs.org/" and
.engines.node == ">=24" and
.exports == {".":{types:"./dist/index.d.ts",import:"./dist/index.js"}} and
((.scripts // {}) | keys | all(. as $s | ["preinstall","install","postinstall","prepare","prepack","postpack","prepublish","prepublishOnly","publish","postpublish"] | index($s) | not)) and
([.dependencies, .optionalDependencies, .peerDependencies,
.bundledDependencies, .bundleDependencies] | all(. == null or length == 0))
' >/dev/null || fail package-metadata
notes="$(tar -xOzf "$archive" package/CHANGELOG.md)"
heading="$(awk -v version="$version" 'index($0, "## [" version "]") == 1' <<< "$notes")"
prefix="## [$version] - "
[[ "$heading" == "$prefix"* ]] || fail dated-notes
release_date="${heading#"$prefix"}"
[[ "$release_date" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]] || fail dated-notes
[[ "$(date -u -d "$release_date" +%F)" == "$release_date" ]] || fail dated-notes
printf '%s\n' "Release preflight passed"
;;
*) fail mode ;;
esac
Loading
Loading