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
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ jobs:
with:
name: package
# Permit checking an already published version; this job has no publishing permissions.
- run: npm publish ./*.tgz --access public --dry-run --force
# A pre-release goes to the next tag: npm refuses one without a tag, and latest must stay a release.
- run: npm publish ./*.tgz --access public --dry-run --force $(case "$(ls ./*.tgz)" in *[0-9]-*.tgz) echo --tag next ;; esac)

publish:
needs: build
Expand All @@ -124,7 +125,7 @@ jobs:

# npm, not pnpm: npm's trusted publishing is the documented path. A tarball runs no
# lifecycle scripts, and nothing is installed here.
- run: npm publish "wirecat-cli-base-$VERSION.tgz" --access public
- run: npm publish "wirecat-cli-base-$VERSION.tgz" --access public $(case "$VERSION" in *-*) echo --tag next ;; esac)

- name: wait for npm to show the version
if: ${{ !inputs.dry_run }}
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@ Versions before 0.8.0 are in the [git tags](https://github.com/WireCatLabs/cli-b
Every entry says what changed as a caller sees it, why, and what to watch for — the rules are
[`docs/dev/CONVENTIONS.md`](docs/dev/CONVENTIONS.md#the-changelog).

## Unreleased

### Added

- **Two changelog headings for libraries on their way to 1.0: "Changed — experimental" and "Deprecated".** Both need
a minor release. "Changed — may break callers" and "Removed" stay for the stable API and, from 1.0.0 on, need a
major. See [WC-REL-7](docs/standards/releases.md).
- **`bin/release --major`.** A version that raises the major over npm's latest now stops unless this flag is given.

### Changed — may break callers

- **The version-level check reads 1.0.0 rules.** From 1.0.0 on, a stable break needs a major, an experimental change
a minor. A release candidate (`1.0.0-rc.1`) counts as its plain version and is never read as the release below.
- **The optional peers `commander` and `vitest` are now `^15.0.0` and `^5.0.0`** instead of open ranges: `./commands`
and `./skill` use commander internals that a new major may change.

### Fixed

- **`next-version` keeps a taken major a major**: with 2.0.0 on npm, `2.0.0` gives `3.0.0`, not `2.1.0`.
- **A pre-release is published under npm's `next` tag**, from `bin/release` and from the release workflow. npm refuses
a pre-release without a tag, and `latest` must stay a release.

## 0.132.0 — 23.11.2026

### Added
Expand Down
22 changes: 16 additions & 6 deletions bin/release
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#
# bin/release # publishes from GitHub Actions (.github/workflows/release.yml)
# bin/release --local # publishes from this machine: the keyring entry NPM_KEYRING_ACCOUNT names, else npm's login
# bin/release --major # also allows a new major version; without it, a version that raises the major stops
#
# The npm token is never printed — not on success, not in an error.
set -eu
Expand All @@ -24,11 +25,14 @@ rerun_if_changed() {
}

mode=ci
case "${1:-}" in
"") ;;
--local) mode=local ;;
*) echo "usage: bin/release [--local]" >&2; exit 2 ;;
esac
major=""
for flag in "$@"; do
case "$flag" in
--local) mode=local ;;
--major) major=1 ;;
*) echo "usage: bin/release [--local] [--major]" >&2; exit 2 ;;
esac
done

git fetch -q origin
[ "$(git branch --show-current)" = "main" ] || { echo "not on main" >&2; exit 1; }
Expand Down Expand Up @@ -118,6 +122,11 @@ if published; then
echo "$version is already on npm — raise the version first" >&2
exit 1
fi
# A major breaks every caller of the stable API, so it ships only when the owner chose to (WC-REL-7).
if [ "${version%%.*}" != "${latest%%.*}" ] && [ -n "$latest" ] && [ -z "$major" ]; then
echo "$version raises the major version over npm's $latest — run bin/release --major if that is meant" >&2
exit 1
fi

if [ "$mode" = ci ]; then
last_run() {
Expand Down Expand Up @@ -154,7 +163,8 @@ if [ -n "${NPM_KEYRING_ACCOUNT:-}" ]; then
fi

echo "== publishing $version =="
pnpm publish --access public --no-git-checks
case "$version" in *-*) tag=next ;; *) tag=latest ;; esac
pnpm publish --access public --no-git-checks --tag "$tag"

echo "== waiting for npm to show $version (up to three minutes) =="
seen=""
Expand Down
2 changes: 1 addition & 1 deletion docs/PUBLISHING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Nothing is published to Homebrew, winget, scoop, apt or skills.sh. skills.sh rea

| Where | Version | Comes from |
|---|---|---|
| npm, git tag, GitHub release, MCP Registry | `x.y.z` ([WC-REL-7](standards/releases.md#wc-rel-7--versions-are-xyz-before-100-a-breaking-change-raises-the-minor)) | `package.json` |
| npm, git tag, GitHub release, MCP Registry | `x.y.z` ([WC-REL-7](standards/releases.md#wc-rel-7--versions-are-xyz-a-break-of-the-stable-api-raises-the-major-from-100-on-and-the-minor-before-it)) | `package.json` |
| ClawHub | its own `1.0.x`: the next patch after the latest **public** version, or `--version` | the ClawHub CLI |
| Claude plugin `plugin.json` | the npm version at the skill's last change | claude-plugins `bin/sync-skills` |
| `metadata.version` in an installed or indexed `SKILL.md` | the installed npm version, or cli-docs' `docsRef` | `withVersion` in [`src/skill`](../src/skill/index.ts) |
Expand Down
2 changes: 1 addition & 1 deletion docs/dev/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Raise `version` in `package.json` and date the `## Unreleased` section of
[`CHANGELOG.md`](../../CHANGELOG.md) as that version, through a pull request. Before 1.0.0, a section with an Added,
"Changed — may break callers" or Removed entry raises the minor; only fixes and document changes raise the patch
([Releases](../standards/releases.md#wc-rel-7--versions-are-xyz-before-100-a-breaking-change-raises-the-minor)).
([Releases](../standards/releases.md#wc-rel-7--versions-are-xyz-a-break-of-the-stable-api-raises-the-major-from-100-on-and-the-minor-before-it)).
Merge it, then on `main`:

```sh
Expand Down
7 changes: 5 additions & 2 deletions docs/standards/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,14 @@ Rule ids on this page are `WC-DOC-<n>`. How to read a rule, how ids work and whi
- **Applies to:** all CLIs and shared libraries. **Since:** cli-base 0.41.0; the empty-section check since the
release after 0.93.0. **Rulings:** none.

### WC-DOC-15 · Changelog entries go under five fixed headings, each at most once per section
<a id="wc-doc-15--changelog-entries-go-under-five-fixed-headings-each-at-most-once-per-section"></a>

### WC-DOC-15 · Changelog entries go under seven fixed headings, each at most once per section

- **Why:** one heading set lets a reader, an agent and one guard read every repository the same way.
- **Enforced by:** `pnpm docs:check` · `changelog-guard.yml`.
- **Example:** `### Added`, `### Changed — may break callers`, `### Fixed`, `### Security`, `### Removed`. max-cli
- **Example:** `### Added`, `### Changed — may break callers`, `### Changed — experimental`, `### Deprecated`, `### Fixed`,
`### Security`, `### Removed`. max-cli
uses this fixed Russian rendering: `Что нового`, `Изменено — может сломать скрипты`, `Исправлено`, `Безопасность`,
`Удалено`. Every entry sits under one of them: `docs:check` refuses an entry under no heading in the top
section.
Expand Down
29 changes: 20 additions & 9 deletions docs/standards/releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,27 @@ on the [CI](ci.md) page.
- **Exceptions:** a shared library that prints no version has no `src/version.ts`.
- **Applies to:** all CLIs. **Since:** cli-base 0.41.0. **Rulings:** none.

### WC-REL-7 · Versions are `x.y.z`; before 1.0.0 a breaking change raises the minor
<a id="wc-rel-7--versions-are-xyz-before-100-a-breaking-change-raises-the-minor"></a>

- **Why:** npm's `^0.40.4` takes every `0.40.x`, so a patch reaches callers who never read its changelog. It must not
break them.
- **Enforced by:** review only.
- **Example:** raise the minor (`0.40.4` to `0.41.0`) for a release with a new feature or with any entry under
"Changed — may break callers" or "Removed". Raise the patch (`0.40.4` to `0.40.5`) only when every entry is a fix
or a change to the documents.
- **Exceptions:** a pre-release version (`0.41.0-rc.1`) is chosen by hand.
- **Applies to:** all CLIs and shared libraries. **Since:** cli-base 0.41.0. **Rulings:** none.
### WC-REL-7 · Versions are `x.y.z`; a break of the stable API raises the major from 1.0.0 on, and the minor before it

- **Why:** npm's `^1.4.0` takes every `1.x`, so a minor reaches callers who never read its changelog: it must not break
what the package promises to keep. A library promises only its stable API; what it marks experimental may change in
a minor, so majors stay rare and work does not wait for them (NEED-2893).
- **Enforced by:** `<app>: bin/release`, which also stops a version that raises the major unless it runs with
--major.
- **Example:**
- A break of the stable API goes under "Changed — may break callers" or "Removed". Before 1.0.0 it raises the
minor (`0.40.4` to `0.41.0`); from 1.0.0 on, the major (`1.4.0` to `2.0.0`).
- A change to what the library marks experimental goes under "Changed — experimental". A stable API that a later
major removes is marked deprecated and listed under "Deprecated". Both raise the minor, as "Added" does.
- Raise the patch (`1.4.0` to `1.4.1`) only when every entry is a fix or a change to the documents.
- A stable break waits for a major the owner chose. Until then it lands as an addition beside the old API, which is
deprecated, never as a change in place.
- **Exceptions:** a pre-release version (`1.0.0-rc.1`) is chosen by hand and published under npm's `next` tag; the
version check reads the last plain release as the one below it.
- **Applies to:** all CLIs and shared libraries. **Since:** cli-base 0.41.0; the 1.0.0 rules since the next release.
**Rulings:** NEED-2893.

### WC-REL-8 · Any package may release at any time

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@
},
"peerDependencies": {
"@scalar/openapi-upgrader": "^0.4.6",
"commander": ">=15",
"commander": "^15.0.0",
"esbuild": "^0.28.0",
"swagger-converter": "^2.1.0",
"vitest": ">=5"
"vitest": "^5.0.0"
},
"peerDependenciesMeta": {
"@scalar/openapi-upgrader": {
Expand Down
7 changes: 6 additions & 1 deletion scripts/next-version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ if (!taken.has(wanted) && compare(want, top) > 0) {
process.exit(0)
}

// A taken x.0.0 stays a major: 2.0.0 taken goes to 3.0.0, never to 2.1.0.
const step =
want[2] === 0 ? ([major, minor]) => [major, minor + 1, 0] : ([major, minor, patch]) => [major, minor, patch + 1]
want[1] === 0 && want[2] === 0 && want[0] >= 1
? ([major]) => [major + 1, 0, 0]
: want[2] === 0
? ([major, minor]) => [major, minor + 1, 0]
: ([major, minor, patch]) => [major, minor, patch + 1]
let next = step(top)
while (taken.has(next.join("."))) next = step(next)
console.log(next.join("."))
6 changes: 6 additions & 0 deletions src/dev/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ describe("next-version", () => {
expect((await next("1.2.1", "1.2.3", '["1.2.3","1.2.4"]')).out).toEqual(["1.2.5"])
})

it("keeps a taken major a major, and a first 1.0.0 over 0.x as it is", async () => {
expect((await next("2.0.0", "2.0.0", '["2.0.0"]')).out).toEqual(["3.0.0"])
out.length = 0
expect((await next("1.0.0", "0.130.0", '["0.130.0"]')).out).toEqual(["1.0.0"])
})

it("passes a pre-release through, and a first publish when npm knows nothing", async () => {
expect((await next("2.0.0-rc.1", "1.0.0", "")).out).toEqual(["2.0.0-rc.1"])
out.length = 0
Expand Down
2 changes: 1 addition & 1 deletion src/dev/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const docsCheck = async (args: string[], io: DevIo) => {
} else {
const ids = [...JOURNAL_IDS, ...(values.ids?.split(",").filter(Boolean) ?? [])]
changelog = {
headings: ["Added", "Changed — may break callers", "Fixed", "Security", "Removed"],
headings: CHANGELOG_HEADINGS,
unreleased: "Unreleased",
ids,
}
Expand Down
10 changes: 8 additions & 2 deletions src/dev/next-version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* The version `bin/release` publishes: the one in package.json when npm has not taken it and it is
* above npm's latest, else the next free one at the same bump level (x.y.0 → minor, x.y.z → patch).
* above npm's latest, else the next free one at the same bump level (x.0.0 → major from 1.0.0 on, x.y.0 → minor,
* x.y.z → patch).
* npm's answers are arguments, not calls, so CI and a test can hand it any registry state.
*/
export const nextVersion = (
Expand Down Expand Up @@ -31,8 +32,13 @@ export const nextVersion = (

if (!taken.has(wanted) && compare(want, top) > 0) return { version: wanted }

// A taken x.0.0 stays a major: 2.0.0 taken goes to 3.0.0, never to 2.1.0.
const step = ([major = 0, minor = 0, patch = 0]: number[]) =>
want[2] === 0 ? [major, minor + 1, 0] : [major, minor, patch + 1]
want[1] === 0 && want[2] === 0 && (want[0] ?? 0) >= 1
? [major + 1, 0, 0]
: want[2] === 0
? [major, minor + 1, 0]
: [major, minor, patch + 1]
let next = step(top)
while (taken.has(next.join("."))) next = step(next)
return { version: next.join(".") }
Expand Down
15 changes: 13 additions & 2 deletions src/release/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@ import { idPattern } from "./markdown.js"

export type Fragment = { name: string; text: string }

/** The changelog's `###` headings in the WireCat CLIs, in their order. */
export const CHANGELOG_HEADINGS = ["Added", "Changed — may break callers", "Fixed", "Security", "Removed"] as const
/**
* The changelog's `###` headings in the WireCat CLIs, in their order. `Changed — experimental` and `Deprecated` are a
* library's: a change to what it marks experimental, and a stable API that a later major removes; both need a minor.
*/
export const CHANGELOG_HEADINGS = [
"Added",
"Changed — may break callers",
"Changed — experimental",
"Deprecated",
"Fixed",
"Security",
"Removed",
] as const
export type FragmentRules = { headings: readonly string[]; ids: readonly string[] }

const NAME = /^[a-z0-9][a-z0-9._-]*\.md$/
Expand Down
22 changes: 22 additions & 0 deletions src/release/level.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,25 @@ it.each([
it("raises a 1.x release that may break callers to the next major", () => {
expect(levelledVersion(unreleased(["Changed — may break callers"], "1.4.2"), "1.4.3")).toBe("2.0.0")
})

it.each([
["1.5.0", ["Changed — experimental"], "1.4.0"],
["1.5.0", ["Deprecated", "Fixed"], "1.4.0"],
["2.0.0", ["Changed — may break callers"], "1.4.0"],
["1.0.0", ["Removed"], "1.0.0-rc.2\n## 1.0.0-rc.1 — 20.10.2026\n## 0.9.0"],
])("from 1.0.0 on accepts %s with %j", (version, headings, previous) => {
expect(versionLevelProblem(changelog(version, headings, previous))).toBeUndefined()
})

it("from 1.0.0 on needs a major for a stable break, and only a minor for an experimental one", () => {
expect(versionLevelProblem(changelog("1.5.0", ["Changed — may break callers"], "1.4.0"))).toMatch(
/needs a major release/,
)
expect(levelledVersion(unreleased(["Changed — experimental"], "1.4.0"), "1.4.1")).toBe("1.5.0")
expect(levelledVersion(unreleased(["Removed"], "1.4.0"), "1.4.1")).toBe("2.0.0")
})

it("leaves a release candidate as chosen and never reads one as the release below", () => {
expect(levelledVersion(unreleased(["Removed"], "0.9.0"), "1.0.0-rc.1")).toBe("1.0.0-rc.1")
expect(versionLevelProblem(changelog("1.0.0-rc.2", ["Removed"], "1.0.0-rc.1"))).toBeUndefined()
})
29 changes: 18 additions & 11 deletions src/release/level.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/** The version level a changelog section needs: `Added` a minor, a break a major (a minor before 1.0.0). */
/**
* The version level a changelog section needs. `Added`, `Deprecated` and `Changed — experimental` need a minor; a
* break of the stable API (`Changed — may break callers`, `Removed`) a major from 1.0.0 on, a minor before it.
*/
const LEVELS = ["patch", "minor", "major"] as const
type Level = (typeof LEVELS)[number]

const parse = (version: string) => version.split(".").map(Number)
const PLAIN = /^\d+\.\d+\.\d+$/
// `1.0.0-rc.1` counts as 1.0.0: the pre-release tail never makes a number of its own.
const parse = (version: string) => (version.split("-")[0] ?? "").split(".").map(Number)

const raised = (from: string, to: string): Level => {
const [a = 0, b = 0] = parse(from)
Expand All @@ -11,11 +16,10 @@ const raised = (from: string, to: string): Level => {
return y !== b ? "minor" : "patch"
}

// Before 1.0.0 the minor carries what a major would; a fix-only release is the only patch.
const needed = (version: string, section: string): Level => {
const breaks = /^### (Changed — may break callers|Removed)$/m.test(section)
if (breaks) return (parse(version)[0] ?? 0) >= 1 ? "major" : "minor"
return /^### Added$/m.test(section) ? "minor" : "patch"
if (/^### (Changed — may break callers|Removed)$/m.test(section))
return (parse(version)[0] ?? 0) >= 1 ? "major" : "minor"
return /^### (Added|Deprecated|Changed — experimental)$/m.test(section) ? "minor" : "patch"
}

const raise = (from: string, level: Level) => {
Expand All @@ -30,22 +34,25 @@ const later = (x: string, y: string) => {
return i === -1 || (a[i] ?? 0) > (b[i] ?? 0) ? x : y
}

/** The top section and the last plain release below it: a release candidate in between is not a release. */
const sections = (changelog: string) => {
const [top, below] = [...changelog.matchAll(/^## (\S+).*$/gm)]
if (!top || !below?.[1]) return undefined
return { version: top[1], previous: below[1], section: changelog.slice(top.index, below.index) }
const [top, ...below] = [...changelog.matchAll(/^## (\S+).*$/gm)]
const previous = below.find((one) => PLAIN.test(one[1] ?? ""))
const next = below[0]
if (!top || !previous?.[1] || !next) return undefined
return { version: top[1], previous: previous[1], section: changelog.slice(top.index, next.index) }
}

// The next free number on npm is a patch; the top section may need a minor or major over the version below it.
export const levelledVersion = (changelog: string, next: string): string => {
const parts = sections(changelog)
if (!parts) return next
if (!parts || !PLAIN.test(next)) return next
return later(next, raise(parts.previous, needed(next, parts.section)))
}

export const versionLevelProblem = (changelog: string): string | undefined => {
const parts = sections(changelog)
if (!parts?.version || !/^\d+\.\d+\.\d+$/.test(parts.version)) return undefined
if (!parts?.version || !PLAIN.test(parts.version)) return undefined
const { version, previous, section } = parts
const want = needed(version, section)
const got = raised(previous, version)
Expand Down