Skip to content
Closed
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
76 changes: 76 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Release process

## How releases work

This repo uses [Changesets](https://github.com/changesets/changesets) for
automated versioning and npm publishing.

### Automated flow (CI)

1. **Feature branch** — develop and test your changes.
2. **Add a changeset** before opening a PR:
```bash
pnpm changeset
# pick affected packages, bump type (patch/minor/major), write a description
```
This creates a `.changeset/<random-slug>.md` file. Commit it with your code.
3. **Open a PR** — CI validates the changeset is present.
4. **Merge to `main`** — `release.yml` runs and does one of two things:
- **Pending changesets exist** → opens/updates a "Version Packages" PR that
bumps all affected package versions and updates CHANGELOGs.
- **No pending changesets** (i.e. the "Version Packages" PR was just merged)
→ publishes every changed package to npm and creates GitHub releases.

### Manual publish (emergency / first publish of a new package)

```bash
# Dry-run first
scripts/publish-packages.sh --dry-run

# Publish with NPM_TOKEN in env
NPM_TOKEN=<token> scripts/publish-packages.sh

# Or let it prompt for TOTP
scripts/publish-packages.sh
```

## Secrets required

| Secret | Where | Notes |
|---|---|---|
| `NPM_TOKEN` | GitHub repo → Settings → Secrets | Granular access token for the `@agentproto` npm org. See note below on auth options. |
| `GITHUB_TOKEN` | Automatic | Provided by GitHub Actions; needs `contents: write` + `pull-requests: write` (set in `release.yml`). |

### NPM auth options (pick one)

**A. OIDC Trusted Publishing** — zero secrets, best security. Requires `id-token: write` permission in
`release.yml` and manually configuring a "Trusted Publisher" on npm.com for each published package
(Package settings → Access → Trusted Publishers → add the GitHub repo + workflow name). Not practical
with 50+ packages unless you script the npm API.

**B. Granular access token with "Bypass 2FA"** — what `release.yml` uses by default. "Bypass 2FA" is
npm's official CI publishing feature (not a security bypass): it lets a token perform write operations
without an OTP code, which is required for any unattended publish job. Create the token at
[npmjs.com/settings/agentiknet/tokens](https://www.npmjs.com/settings/agentiknet/tokens): choose
"Granular Access Token" → select the `@agentproto` packages → check "Bypass 2FA" → expiry ≤ 1 year.

If you later move to OIDC, remove `NODE_AUTH_TOKEN` from `release.yml` and add
`id-token: write` to the `permissions` block — provenance attestation is automatic.

## Bump type guide

| Bump | When |
|---|---|
| `patch` | Bug fix, docs, internal refactor — no API change. |
| `minor` | New export, new field, new optional method — backward-compatible. |
| `major` | Breaking change: removed export, changed signature, renamed type. |

During `0.x.y-alpha` pre-release, `minor` is appropriate for most new features.

## Adding a new package

1. Create the package under `packages/<name>/` with standard `package.json` + `tsup.config.ts`.
2. Add it to the PACKAGES list in `scripts/publish-packages.sh` at the right dependency layer.
3. First publish is manual (`scripts/publish-packages.sh`) — changesets doesn't publish packages
that have never been on npm before.
4. Subsequent releases are fully automated via the changeset flow above.
13 changes: 13 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://unpkg.com/@changesets/config@3.1.4/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": [
"@agentproto/tooling"
]
}
5 changes: 5 additions & 0 deletions .changeset/copper-owls-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@agentproto/corpus": patch
---

Fix dead code in synthesize.ts — `body.trim()` made `startsWith("\n")` unreachable; always prepend newline for gray-matter frontmatter separator.
67 changes: 67 additions & 0 deletions .github/workflows/auto-changeset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Auto Changeset

on:
pull_request:
types: [opened, synchronize]

# Write access to push the generated changeset back to the branch.
# Only works for PRs from the same repo (not forks) — which is the
# normal case for an internal monorepo.
permissions:
contents: write

jobs:
auto-changeset:
name: Generate changeset
runs-on: ubuntu-latest
# Skip the "Version Packages" PR that changesets/action opens itself.
if: |
!startsWith(github.event.pull_request.title, 'chore(release):')

steps:
- name: Checkout branch (with write token)
uses: actions/checkout@v4
with:
fetch-depth: 0
# Check out the head of the PR branch so we can push back to it.
ref: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Check if changeset already exists
id: check
run: |
ADDED=$(git diff --diff-filter=A --name-only origin/main...HEAD -- '.changeset/*.md' \
| grep -v '^\.changeset/README\.md$' || true)
if [ -n "$ADDED" ]; then
echo "present=true" >> "$GITHUB_OUTPUT"
echo "✓ Changeset already present: $ADDED"
else
echo "present=false" >> "$GITHUB_OUTPUT"
echo "No changeset found — will auto-generate."
fi

- name: Setup Node.js
if: steps.check.outputs.present == 'false'
uses: actions/setup-node@v4
with:
node-version: 22

- name: Generate changeset via Claude
if: steps.check.outputs.present == 'false'
run: node scripts/auto-changeset.mjs
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}

- name: Commit generated changeset
if: steps.check.outputs.present == 'false'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Stage only new .changeset/*.md files (not README, not existing ones)
git add '.changeset/*.md'
if git diff --cached --quiet; then
echo "Nothing to commit (no packages changed, changeset not needed)."
else
git commit -m "chore: auto-generate changeset [skip ci]"
git push
fi
49 changes: 39 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,70 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: 'true'

jobs:
build-and-test:
name: Build + test
runs-on: ubuntu-latest
timeout-minutes: 10
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.4.1
# version read from packageManager field in package.json

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm

- name: Install dependencies
run: pnpm install --no-frozen-lockfile
run: pnpm install --frozen-lockfile

# Build first — `tsc --noEmit` resolves workspace package imports
# through their published `.d.ts` files in `dist/`, which only
# exist after `pnpm build`. Running `check-types` before `build`
# produced "Cannot find module '@agentproto/<pkg>'" cascades on
# every commit since the multi-package extraction.
- name: Build all packages
run: pnpm -r --filter "./packages/**" --filter "./adapters/**" build
run: pnpm build

- name: Type-check all packages
run: pnpm -r --filter "./packages/**" --filter "./adapters/**" check-types
run: pnpm check-types

- name: Run tests
run: pnpm -r --filter "./packages/**" --filter "./adapters/**" test
run: pnpm test

# On PRs: verify a changeset was added (or the author opted out with
# the "skip changeset" label). This prevents "Version Packages" PRs
# from accidentally shipping without changelog entries.
changeset-check:
name: Changeset present?
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check for changeset
# Uses git directly — avoids fragile `changeset status` exit codes.
# Passes when a .changeset/*.md file (not README) was added in this
# branch, or when the PR title starts with "chore(release):" (the
# "Version Packages" PR opened by changesets/action itself).
run: |
TITLE="${{ github.event.pull_request.title }}"
if [[ "$TITLE" == chore\(release\):* ]]; then
echo "Version Packages PR — no changeset required."
exit 0
fi
ADDED=$(git diff --diff-filter=A --name-only origin/main...HEAD -- '.changeset/*.md' \
| grep -v '^\.changeset/README\.md$' || true)
if [ -z "$ADDED" ]; then
echo "No changeset found. Run 'pnpm changeset' and commit the .changeset/*.md file."
exit 1
fi
echo "✓ Changeset present: $ADDED"
64 changes: 64 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Release

on:
push:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false # never cancel a release in progress

permissions:
contents: write # create tags + GitHub releases
pull-requests: write # open "Version Packages" PR

jobs:
release:
name: Version or publish
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout (full history for changesets)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup pnpm
uses: pnpm/action-setup@v4
# version read from packageManager field in package.json

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
registry-url: 'https://registry.npmjs.org'
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build all packages
run: pnpm build

# changesets/action does one of two things depending on state:
#
# A) Pending changesets exist → opens (or updates) a "Version Packages"
# PR that bumps versions + regenerates CHANGELOGs.
#
# B) No pending changesets (i.e. the "Version Packages" PR was just
# merged) → publishes every package whose version isn't yet on npm
# and creates a GitHub release per package.
- name: Version or publish
uses: changesets/action@v1
with:
version: pnpm changeset version
publish: pnpm release:ci
commit: "chore(release): version packages"
title: "chore(release): version packages"
createGithubReleases: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# NPM_TOKEN must be a granular access token with "Bypass 2FA"
# scoped to the @agentproto org. Set it in the repo's Secrets.
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_CONFIG_PROVENANCE: 'true'
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,18 @@
"clean": "pnpm -r --filter \"./packages/**\" --filter \"./adapters/**\" clean",
"scaffold-aip": "node scripts/scaffold-aip.mjs",
"sync-specs": "node scripts/sync-specs.mjs",
"sync-specs:check": "node scripts/sync-specs.mjs --check"
"sync-specs:check": "node scripts/sync-specs.mjs --check",
"changeset": "changeset",
"changeset:auto": "node scripts/auto-changeset.mjs",
"version": "changeset version",
"release": "scripts/release.sh",
"release:ci": "pnpm build && changeset publish",
"release:npm": "scripts/release.sh --npm-only",
"release:server": "scripts/release.sh --server-only",
"release:dry": "scripts/release.sh --dry-run"
},
"devDependencies": {
"@changesets/cli": "^2.31.0",
"gray-matter": "^4.0.3",
"json-schema-to-typescript": "^15.0.4",
"json-schema-to-zod": "^2.6.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/corpus/src/distill/synthesize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ function serializeSynthesis(
},
}
const trimmed = body.trim()
return matter.stringify(trimmed.startsWith("\n") ? trimmed : "\n" + trimmed, fm)
// gray-matter needs a leading newline to separate frontmatter from body
return matter.stringify("\n" + trimmed, fm)
}

/** Build the synthesis prompt — the model-agnostic core (mirrors buildDistillPrompt). */
Expand Down
Loading
Loading