Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🔨 chore(cli): publish patches on production code changes (#22812)

Rdmclin215b0269f20c3
diff --git a/.github/scripts/cliRelease.mjs b/.github/scripts/cliRelease.mjs
new file mode 100644
index 00000000000..ae3a4de76e7
--- /dev/null
+++ b/.github/scripts/cliRelease.mjs
@@ -0,0 +1,191 @@
+import { execFile } from 'node:child_process';
+import { appendFile, readFile, writeFile } from 'node:fs/promises';
+import path from 'node:path';
+import { setTimeout } from 'node:timers/promises';
+import { pathToFileURL } from 'node:url';
+import { promisify } from 'node:util';
+
+const exec = promisify(execFile);
+const tagPrefix = 'cli-release/v';
+const stablePattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
+
+function parts(version) {
+ if (typeof version !== 'string' || !stablePattern.test(version)) {
+ throw new Error(`Expected a stable version, got ${version}`);
+ }
+ return version.split('.').map(BigInt);
+}
+
+function compare(a, b) {
+ const right = parts(b);
+ for (const [i, left] of parts(a).entries()) {
+ if (left !== right[i]) return left > right[i] ? 1 : -1;
+ }
+ return 0;
+}
+
+/** Pure release decisions; tags reserve versions even while npm is processing. */
+export async function planRelease({ sourceVersion, metadata, reservations, sha, isAncestor }) {
+ parts(sourceVersion);
+ if (!metadata.versions || !metadata['dist-tags']?.latest) {
+ throw new Error('Registry response is missing versions or latest');
+ }
+ parts(metadata['dist-tags'].latest);
+ const versions = Object.keys(metadata.versions).filter((version) => stablePattern.test(version));
+ if (!versions.includes(metadata['dist-tags'].latest)) {
+ throw new Error('Registry latest is missing from versions');
+ }
+ const newest = versions.sort(compare).at(-1);
+ const ordered = [...reservations].sort((a, b) => compare(b.version, a.version));
+ const existing = ordered.find((entry) => entry.sha === sha);
+ if (existing) {
+ const published = metadata.versions[existing.version];
+ if (published) {
+ if (published.gitHead !== sha) throw new Error(`Source mismatch for ${existing.version}`);
+ if (existing.version === newest && metadata['dist-tags'].latest !== existing.version) {
+ throw new Error(
+ `latest does not point to ${existing.version}; publication is not verified`,
+ );
+ }
+ return { publish: false, reason: `${existing.version} is already published` };
+ }
+ if (compare(existing.version, newest) <= 0) {
+ return { publish: false, reason: 'A newer version has already been published' };
+ }
+ }
+ for (const entry of ordered) {
+ if (entry.sha !== sha && (await isAncestor(sha, entry.sha))) {
+ return { publish: false, reason: 'A newer source commit already has a release reservation' };
+ }
+ if (
+ entry.sha !== sha &&
+ compare(entry.version, newest) > 0 &&
+ !metadata.versions[entry.version]
+ ) {
+ throw new Error(
+ `Release ${entry.version} (${entry.sha}) is unfinished; rerun its original workflow first`,
+ );
+ }
+ }
+ if (existing) return { publish: true, version: existing.version, reserved: true };
+ const next = parts(newest);
+ next[2]++;
+ const incremented = next.join('.');
+ const version = compare(sourceVersion, incremented) > 0 ? sourceVersion : incremented;
+ return { publish: true, version, reserved: false };
+}
+
+export async function readRegistry(name, request = fetch) {
+ const response = await request(`https://registry.npmjs.org/${encodeURIComponent(name)}`, {
+ headers: { 'Cache-Control': 'no-cache' },
+ signal: AbortSignal.timeout(30_000),
+ });
+ if (!response.ok) throw new Error(`Registry lookup failed: HTTP ${response.status}`);
+ return response.json();
+}
+
+export async function verifyPublication({
+ name,
+ version,
+ sha,
+ read = readRegistry,
+ sleep = setTimeout,
+ attempts = 60,
+}) {
+ for (let attempt = 0; attempt < attempts; attempt++) {
+ const metadata = await read(name);
+ const published = metadata.versions?.[version];
+ if (published) {
+ if (published.gitHead !== sha) throw new Error(`Source mismatch for ${name}@${version}`);
+ if (metadata['dist-tags']?.latest !== version)
+ throw new Error(`latest does not point to ${version}`);
+ return;
+ }
+ if (attempt + 1 < attempts) await sleep(10_000);
+ }
+ throw new Error(
+ `${name}@${version} is not visible yet. Its version stays reserved; rerun this workflow, not a new release`,
+ );
+}
+
+async function git(...args) {
+ return (await exec('git', args)).stdout.trim();
+}
+
+export async function prepareRelease({ env = process.env, read = readRegistry } = {}) {
+ const packagePath = 'apps/cli/package.json';
+ const pkg = JSON.parse(await readFile(packagePath, 'utf8'));
+ const sha = await git('rev-parse', 'HEAD');
+ // No forced tag updates: a collision must fail, never overwrite a reservation.
+ await git('fetch', 'origin', `refs/tags/${tagPrefix}*:refs/tags/${tagPrefix}*`);
+ const tags = await git(
+ 'for-each-ref',
+ '--format=%(refname:strip=2) %(objectname)',
+ `refs/tags/${tagPrefix}*`,
+ );
+ const reservations = tags
+ ? tags.split('\n').map((line) => {
+ const [tag, commit] = line.split(' ');
+ return { version: tag.slice(tagPrefix.length), sha: commit };
+ })
+ : [];
+ const plan = await planRelease({
+ sourceVersion: pkg.version,
+ metadata: await read(pkg.name),
+ reservations,
+ sha,
+ isAncestor: async (ancestor, descendant) => {
+ try {
+ await git('merge-base', '--is-ancestor', ancestor, descendant);
+ return true;
+ } catch (error) {
+ if (error.code === 1) return false;
+ throw error;
+ }
+ },
+ });
+ if (plan.publish) {
+ // npm pack receives the generated version and explicit source identity.
+ // The checkout and its checked-in manual are never committed back to canary.
+ pkg.version = plan.version;
+ pkg.gitHead = sha;
+ await writeFile(packagePath, `${JSON.stringify(pkg, null, 2)}\n`);
+ }
+ console.log(plan.publish ? `Prepared ${pkg.name}@${plan.version} from ${sha}` : plan.reason);
+ if (env.GITHUB_OUTPUT) {
+ await appendFile(
+ env.GITHUB_OUTPUT,
+ `publish=${plan.publish}\n${plan.publish ? `version=${plan.version}\n` : ''}`,
+ );
+ }
+ return plan;
+}
+
+export async function reserveRelease() {
+ const pkg = JSON.parse(await readFile('apps/cli/package.json', 'utf8'));
+ parts(pkg.version);
+ const sha = await git('rev-parse', 'HEAD');
+ if (pkg.gitHead !== sha) throw new Error('Prepared package does not match the checkout');
+ const tag = `${tagPrefix}${pkg.version}`;
+ const existing = await git('tag', '--list', tag);
+ if (existing) {
+ if ((await git('rev-parse', tag)) !== sha) throw new Error(`Reservation conflict for ${tag}`);
+ } else {
+ await git('tag', tag, sha);
+ }
+ await git('push', 'origin', `refs/tags/${tag}`);
+}
+
+if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) {
+ if (process.argv[2] === 'prepare') {
+ await prepareRelease();
+ } else if (process.argv[2] === 'reserve') {
+ await reserveRelease();
+ } else if (process.argv[2] === 'verify') {
+ const pkg = JSON.parse(await readFile('apps/cli/package.json', 'utf8'));
+ await verifyPublication({ name: pkg.name, version: pkg.version, sha: pkg.gitHead });
+ console.log(`Verified ${pkg.name}@${pkg.version} on npm latest`);
+ } else {
+ throw new Error('Usage: node .github/scripts/cliRelease.mjs prepare|reserve|verify');
+ }
+}
diff --git a/.github/scripts/cliRelease.test.mjs b/.github/scripts/cliRelease.test.mjs
new file mode 100644
index 00000000000..5fc468df468
--- /dev/null
+++ b/.github/scripts/cliRelease.test.mjs
@@ -0,0 +1,256 @@
+import assert from 'node:assert/strict';
+import { execFile } from 'node:child_process';
+import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import path from 'node:path';
+import { test } from 'node:test';
+import { fileURLToPath } from 'node:url';
+import { promisify } from 'node:util';
+
+import { planRelease, readRegistry, verifyPublication } from './cliRelease.mjs';
+
+const exec = promisify(execFile);
+const registry = (version = '0.0.78', extra = {}) => ({
+ 'dist-tags': { latest: version },
+ 'versions': { [version]: {}, ...extra },
+});
+const plan = (overrides = {}) =>
+ planRelease({
+ sourceVersion: '0.0.78',
+ metadata: registry(),
+ reservations: [],
+ sha: 'current',
+ isAncestor: async () => false,
+ ...overrides,
+ });
+
+test('increments the registry patch without a checked-in version bump', async () => {
+ assert.deepEqual(await plan(), { publish: true, version: '0.0.79', reserved: false });
+ assert.equal((await plan({ metadata: registry('0.0.99') })).version, '0.0.100');
+ assert.equal((await plan({ sourceVersion: '0.1.0' })).version, '0.1.0');
+ assert.equal((await plan({ sourceVersion: '0.0.1' })).version, '0.0.79');
+});
+
+test('allocates beyond every stable version even when latest was rolled back', async () => {
+ assert.equal(
+ (await plan({ metadata: registry('0.0.78', { '0.0.80': {}, '1.0.0-beta.1': {} }) })).version,
+ '0.0.81',
+ );
+});
+
+test('retries a reserved version while npm is still processing', async () => {
+ assert.deepEqual(await plan({ reservations: [{ version: '0.0.79', sha: 'current' }] }), {
+ publish: true,
+ version: '0.0.79',
+ reserved: true,
+ });
+});
+
+test('skips a published commit and rejects a mismatched source', async () => {
+ const reservations = [{ version: '0.0.79', sha: 'current' }];
+ assert.equal(
+ (
+ await plan({
+ reservations,
+ metadata: registry('0.0.79', { '0.0.79': { gitHead: 'current' } }),
+ })
+ ).publish,
+ false,
+ );
+ await assert.rejects(plan({ reservations, metadata: registry('0.0.79') }), /Source mismatch/);
+});
+
+test('retry still fails if the newest package is visible but latest is stale', async () => {
+ const reservations = [{ version: '0.0.79', sha: 'current' }];
+ const metadata = registry('0.0.78', { '0.0.79': { gitHead: 'current' } });
+ await assert.rejects(plan({ reservations, metadata }), /latest does not point to/);
+ assert.equal(
+ (
+ await plan({
+ reservations,
+ metadata: registry('0.0.80', { '0.0.79': { gitHead: 'current' } }),
+ })
+ ).publish,
+ false,
+ );
+});
+
+test('blocks a different commit behind an unfinished publication', async () => {
+ await assert.rejects(
+ plan({ reservations: [{ version: '0.0.79', sha: 'previous' }] }),
+ /unfinished/,
+ );
+});
+
+test('old workflow reruns cannot allocate a newer version or roll latest backwards', async () => {
+ assert.equal(
+ (
+ await plan({
+ reservations: [{ version: '0.0.79', sha: 'newer' }],
+ isAncestor: async () => true,
+ })
+ ).publish,
+ false,
+ );
+ assert.equal(
+ (
+ await plan({
+ reservations: [{ version: '0.0.79', sha: 'current' }],
+ metadata: registry('0.0.80'),
+ })
+ ).publish,
+ false,
+ );
+});
+
+test('rejects prereleases and malformed registry metadata', async () => {
+ for (const sourceVersion of ['0.0.79-beta.1', '01.0.0', 'garbage'])
+ await assert.rejects(plan({ sourceVersion }), /stable version/);
+ for (const metadata of [
+ {},
+ { versions: {} },
+ { 'versions': {}, 'dist-tags': { latest: '0.0.78' } },
+ ]) {
+ await assert.rejects(plan({ metadata }), /Registry/);
+ }
+});
+
+test('does not interpret registry authentication, outage or malformed JSON as an unpublished version', async () => {
+ for (const status of [401, 404, 500]) {
+ await assert.rejects(
+ readRegistry('@lobehub/cli', async () => new Response('', { status })),
+ new RegExp(`HTTP ${status}`),
+ );
+ }
+ await assert.rejects(
+ readRegistry('@lobehub/cli', async () => new Response('not JSON')),
+ /JSON/,
+ );
+});
+
+test('waits for public registry visibility, verifies source and latest, and bounds pending publications', async () => {
+ let calls = 0;
+ const opts = {
+ name: '@lobehub/cli',
+ version: '0.0.79',
+ sha: 'current',
+ sleep: async () => {},
+ attempts: 2,
+ };
+ await verifyPublication({
+ ...opts,
+ read: async () =>
+ ++calls === 1 ? registry() : registry('0.0.79', { '0.0.79': { gitHead: 'current' } }),
+ });
+ assert.equal(calls, 2);
+ await assert.rejects(
+ verifyPublication({ ...opts, read: async () => registry() }),
+ /not visible yet/,
+ );
+ await assert.rejects(
+ verifyPublication({ ...opts, read: async () => registry('0.0.79') }),
+ /Source mismatch/,
+ );
+ await assert.rejects(
+ verifyPublication({
+ ...opts,
+ read: async () => registry('0.0.80', { '0.0.79': { gitHead: 'current' } }),
+ }),
+ /latest/,
+ );
+});
+
+test('persists a reservation in Git, reuses it after a failed run, and skips after publication', async (t) => {
+ const root = await mkdtemp(path.join(tmpdir(), 'cli-release-test-'));
+ t.after(() => rm(root, { recursive: true, force: true }));
+ const origin = path.join(root, 'origin.git');
+ const checkout = path.join(root, 'checkout');
+ await exec('git', ['init', '--bare', origin]);
+ await exec('git', ['clone', origin, checkout]);
+ const git = (...args) => exec('git', args, { cwd: checkout });
+ await git('config', 'user.email', '[email protected]');
+ await git('config', 'user.name', 'Test');
+ await mkdir(path.join(checkout, 'apps/cli'), { recursive: true });
+ const pkgPath = path.join(checkout, 'apps/cli/package.json');
+ const pkg = { name: '@lobehub/cli', version: '0.0.78' };
+ await writeFile(pkgPath, JSON.stringify(pkg));
+ await git('add', '.');
+ await git('commit', '-m', 'source');
+ const sha = (await git('rev-parse', 'HEAD')).stdout.trim();
+ const script = pathToScript();
+ const invoke = async (metadata) => {
+ const runner = `
+ const { prepareRelease, reserveRelease } = await import(process.argv[1]);
+ const metadata = JSON.parse(process.argv[2]);
+ const plan = await prepareRelease({ env: {}, read: async () => metadata });
+ if (plan.publish) await reserveRelease();
+ `;
+ await exec(
+ process.execPath,
+ ['--input-type=module', '-e', runner, script, JSON.stringify(metadata)],
+ {
+ cwd: checkout,
+ },
+ );
+ };
+ await invoke(registry());
+ const publishedPackage = JSON.parse(await readFile(pkgPath, 'utf8'));
+ assert.equal(publishedPackage.version, '0.0.79');
+ assert.equal(publishedPackage.gitHead, sha);
+ assert.match((await git('ls-remote', '--tags', 'origin')).stdout, /cli-release\/v0\.0\.79/);
+ await git('restore', 'apps/cli/package.json');
+ await invoke(registry());
+ assert.equal(JSON.parse(await readFile(pkgPath, 'utf8')).version, '0.0.79');
+ assert.equal((await git('tag', '--list')).stdout.trim().split('\n').length, 1);
+ await git('restore', 'apps/cli/package.json');
+ await invoke(registry('0.0.79', { '0.0.79': { gitHead: sha } }));
+ assert.deepEqual(JSON.parse(await readFile(pkgPath, 'utf8')), pkg);
+});
+
+function pathToScript() {
+ return new URL('./cliRelease.mjs', import.meta.url).href;
+}
+
+test('workflow limits automatic publication to production inputs and serializes runs', async () => {
+ // YAML is a repository dependency; importing lazily keeps pure planner tests standalone.
+ const { parse } = await import('yaml');
+ const workflow = parse(
+ await readFile(fileURLToPath(new URL('../workflows/release-cli.yml', import.meta.url)), 'utf8'),
+ );
+ const patterns = workflow.on.push.paths;
+ assert.ok(patterns.includes('apps/cli/src/**'));
+ for (const excluded of [
+ '!apps/cli/**/*.test.*',
+ '!apps/cli/**/*.spec.*',
+ '!apps/cli/**/__tests__/**',
+ '!apps/cli/**/*.md',
+ ])
+ assert.ok(patterns.includes(excluded));
+ const triggers = (file) =>
+ patterns.reduce((included, pattern) => {
+ const exclude = pattern.startsWith('!');
+ return path.matchesGlob(file, exclude ? pattern.slice(1) : pattern) ? !exclude : included;
+ }, false);
+ for (const file of [
+ 'apps/cli/src/commands/agent.ts',
+ 'apps/cli/scripts/copyReportTemplate.ts',
+ 'apps/cli/package.json',
+ 'apps/cli/tsdown.config.ts',
+ ])
+ assert.equal(triggers(file), true, file);
+ for (const file of [
+ 'apps/cli/README.md',
+ 'apps/cli/man/man1/lh.1',
+ 'apps/cli/src/commands/agent.test.ts',
+ 'apps/cli/src/x.spec.ts',
+ 'apps/cli/src/__tests__/integration.ts',
+ 'apps/cli/src/fixtures/data.json',
+ 'apps/cli/src/docs/guide.md',
+ 'apps/cli/e2e/agent.ts',
+ ])
+ assert.equal(triggers(file), false, file);
+ assert.equal(workflow.concurrency.group, 'release-cli');
+ assert.equal(workflow.concurrency['cancel-in-progress'], false);
+ assert.equal(workflow.jobs.publish.steps[0].with['fetch-depth'], 0);
+ assert.match(workflow.jobs.publish.if, /refs\/heads\/canary/);
+});
diff --git a/.github/workflows/release-cli.yml b/.github/workflows/release-cli.yml
index 74de9f5b640..34e3991a975 100644
--- a/.github/workflows/release-cli.yml
+++ b/.github/workflows/release-cli.yml
@@ -1,7 +1,7 @@
name: Release CLI
permissions:
- contents: read
+ contents: write
id-token: write
on:
@@ -9,8 +9,22 @@ on:
branches:
- canary
paths:
- - apps/cli/package.json
- - .github/workflows/release-cli.yml
+ - 'apps/cli/src/**'
+ - 'apps/cli/scripts/**'
+ - 'apps/cli/package.json'
+ - 'apps/cli/pnpm-workspace.yaml'
+ - 'apps/cli/tsconfig.json'
+ - 'apps/cli/tsdown.config.ts'
+ - '!apps/cli/**/*.test.*'
+ - '!apps/cli/**/*.spec.*'
+ - '!apps/cli/**/__tests__/**'
+ - '!apps/cli/**/__fixtures__/**'
+ - '!apps/cli/**/fixtures/**'
+ - '!apps/cli/**/testUtils.*'
+ - '!apps/cli/**/*.md'
+ - '!apps/cli/**/*.mdx'
+ - '.github/workflows/release-cli.yml'
+ - '.github/scripts/cliRelease.mjs'
workflow_dispatch: {}
# Never interrupt a publish or let two runs publish the same version concurrently.
@@ -25,43 +39,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
+ with:
+ fetch-depth: 0
- - name: Check release version
+ - name: Prepare release version
id: release
- run: |
- node --input-type=module <<'NODE'
- import { appendFile, readFile } from 'node:fs/promises';
-
- const { name, version } = JSON.parse(await readFile('apps/cli/package.json', 'utf8'));
- if (!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(version)) {
- throw new Error(`Only stable versions can be published to latest: ${version}`);
- }
- const response = await fetch(`https://registry.npmjs.org/${encodeURIComponent(name)}`, {
- signal: AbortSignal.timeout(30_000),
- });
- if (!response.ok) throw new Error(`Registry lookup failed: HTTP ${response.status}`);
- const metadata = await response.json();
- if (!metadata.versions || !metadata['dist-tags']?.latest) {
- throw new Error('Registry response is missing versions or latest');
- }
- if (Object.hasOwn(metadata.versions, version)) {
- console.log(`${name}@${version} is already published; skipping.`);
- await appendFile(process.env.GITHUB_OUTPUT, 'publish=false\n');
- } else {
- const latest = metadata['dist-tags'].latest;
- if (!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(latest)) {
- throw new Error(`Unexpected latest version: ${latest}`);
- }
- const currentParts = version.split('.').map(BigInt);
- const latestParts = latest.split('.').map(BigInt);
- const firstDifference = currentParts.findIndex((part, i) => part !== latestParts[i]);
- if (firstDifference < 0 || currentParts[firstDifference] < latestParts[firstDifference]) {
- throw new Error(`${version} must be newer than latest (${latest})`);
- }
- await appendFile(process.env.GITHUB_OUTPUT, 'publish=true\n');
- console.log(`Publishing ${name}@${version}`);
- }
- NODE
+ run: node .github/scripts/cliRelease.mjs prepare
- name: Setup environment
if: steps.release.outputs.publish == 'true'
@@ -109,9 +92,17 @@ jobs:
run: npm pack --ignore-scripts
working-directory: apps/cli
+ - name: Reserve version for retries
+ if: steps.release.outputs.publish == 'true'
+ run: node .github/scripts/cliRelease.mjs reserve
+
- name: Publish to npm
if: steps.release.outputs.publish == 'true'
run: npm publish ./lobehub-cli-*.tgz --provenance --access public --tag latest
working-directory: apps/cli
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
+
+ - name: Verify npm publication
+ if: steps.release.outputs.publish == 'true'
+ run: node .github/scripts/cliRelease.mjs verify
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 1829b0e6729..c7ca41a7380 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -79,6 +79,9 @@ jobs:
run: pnpm install
working-directory: apps/cli
+ - name: Verify CLI release automation
+ run: node --test .github/scripts/cliRelease.test.mjs
+
- name: Verify hotfix operator CLI
run: node --test .github/scripts/hotfixWorkflow.test.mjs
diff --git a/apps/cli/README.md b/apps/cli/README.md
index 53ff87ab4b3..73f8dd03ac2 100644
--- a/apps/cli/README.md
+++ b/apps/cli/README.md
@@ -4,23 +4,42 @@ LobeHub command-line interface.
## Release to npm
-The `Release CLI` GitHub Actions workflow publishes stable versions to npm's
-`latest` tag from `canary`. To release, bump `apps/cli/package.json` in a PR:
-
-```bash
-cd apps/cli
-npm version patch --no-git-tag-version
-bun run man:generate
-```
-
-Commit the version and generated manual, complete the checks and any product
-acceptance required by the change, then merge the PR into `canary`. CI checks
-the registry, tests the CLI bundle, runs the complete `prepublishOnly` build
-(including the offline report), smoke-checks it, and publishes with provenance.
-The workflow can also be dispatched manually on `canary` to retry a failed run.
-Already published versions are skipped; prereleases and versions older than
-`latest` are rejected. Registry errors stop the run instead of assuming a
-version is unpublished. CI does not change versions or commit back to the repo.
+The `Release CLI` GitHub Actions workflow publishes to npm's `latest` tag when
+CLI production inputs change on `canary`. Merge the feature or fix PR after its
+checks and required product acceptance; no separate version-bump PR is needed.
+
+Automatic inputs are `apps/cli/src/**`, build scripts, `package.json`, the CLI
+workspace/TypeScript/tsdown configuration, and the release workflow/helper.
+Tests, fixtures, Markdown documentation, E2E-only changes and generated manuals
+are excluded. Changes only to shared workspace packages or the offline report
+can be released by manually dispatching `Release CLI` on `canary`.
+
+CI allocates the next patch above the highest stable npm version (for example,
+`0.0.78` → `0.0.79`). A higher stable version intentionally set in `package.json`
+is honored for a minor/major release. The generated version is used for the
+bundle and manual; CI does not commit version changes back to the branch. The
+checked-in version is therefore a development baseline, not necessarily npm's
+latest release. Use `npm view @lobehub/cli version` to check the published version.
+
+The workflow tests the bundle, runs the complete `prepublishOnly` build, checks
+the built CLI and packs it. Immediately before publication it creates a
+`cli-release/v<version>` Git tag pointing at the source commit. The tag reserves
+the version for retries; the published package also records `gitHead`.
+Publication is serialized and the workflow waits up to ten minutes for npm to
+expose the matching version/source under `latest`. A successful upload alone is
+not reported as a verified publication.
+
+Use **Re-run failed jobs** on the original run to recover a failed publication.
+A retry reuses its reserved version or skips it if already published. If npm is
+still processing an earlier reserved release, a different commit's release stops
+with a recovery message instead of allocating another version. Older reruns do
+not publish over newer source commits. Build/test failures before reservation
+can be fixed by the next PR normally. Do not delete reservation tags to retry a
+release. Registry errors stop the workflow.
+
+GitHub may coalesce queued runs while another release is running; the surviving
+newer commit includes the earlier merged changes. This publishes source snapshots,
+not necessarily one version per merged PR.
Publishing uses the repository's `NPM_TOKEN` secret, as the SDK release does.
It must have publish permission for `@lobehub/cli` and support unattended