diff --git a/AGENTS.md b/AGENTS.md index edb2a7c..6b36b5d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -59,8 +59,7 @@ Rules carried over from `agent-skills`: 4. Add optional parts (agents, hooks, MCP, code) from "Layout" below. 5. `node scripts/build.ts`, then commit everything it wrote. CI fails if a generated file is stale (`--check`). -6. Update `README.md` (install table, owner/repo, and the badge row's owner/repo) and `cliff.toml` - (commit link). +6. Update `README.md` (install table, owner/repo, and the badge row's owner/repo). 7. Put the repo's own checks in `scripts/ci.sh` (see "Checks"). It starts with the template's three; add yours below them. 8. In a repo just created from the template, delete the template's own files under @@ -157,7 +156,8 @@ the plugin uses it; **doc** = described here only, not in the template. ├── README.md core ≥ 40 words (Claude directory check); install table ├── TODO.md core open work and the [T] install tests ├── CHANGELOG.md gen git-cliff (not scripts/build.ts) -├── cliff.toml, tsconfig.json, .gitignore core +├── cliff.toml gen git-cliff config; the commit link comes from `repository` +├── tsconfig.json, .gitignore core └── LICENSE core MIT ``` @@ -224,7 +224,8 @@ Modules: `types.ts` (config shape, `validateConfig`, `nameProblem`), `frontmatte | `kimi` | `.kimi-plugin/plugin.json` | | `muse` | `.muse-plugin/plugin.json`, `marketplace.json` | -`package.json` is always written: it also carries the dev scripts. +`package.json` and `cliff.toml` are always written: `package.json` also carries the dev scripts, +and `cliff.toml`'s commit link comes from `repository` (plain commit ids when there is none). ### `mcp/servers.json` @@ -405,7 +406,8 @@ is skipped while the plugin has no copy, and compared and applied once it exists the changelog by these. - Commit straight to `main` unless a change wants review on a branch. - The version lives only in `plugin.config.json`; bump it there and rebuild. -- `CHANGELOG.md` is generated: `npx git-cliff@2.14.2 -o CHANGELOG.md`, never by hand. +- `CHANGELOG.md` is generated: `npx git-cliff@2.14.2 -o CHANGELOG.md`, never by hand. So is + `cliff.toml` (by `scripts/build.ts`, from `repository`); it skips merge commits. - Merge a release branch by fast-forward or a merge commit, never squash or rebase, so the tagged commit stays in `main`'s history. diff --git a/cliff.toml b/cliff.toml index 4f2005b..62417b8 100644 --- a/cliff.toml +++ b/cliff.toml @@ -1,3 +1,4 @@ +# Generated from plugin.config.json by scripts/build.ts; don't edit by hand. Change the config and rebuild. # git-cliff config: https://git-cliff.org/docs/configuration # Generate: npx git-cliff@2.14.2 -o CHANGELOG.md (all releases + unreleased) # Release: npx git-cliff@2.14.2 --tag vX.Y.Z -o CHANGELOG.md (before tagging vX.Y.Z) @@ -38,6 +39,7 @@ protect_breaking_commits = true commit_parsers = [ { message = "^Initial commit", skip = true }, { message = "^chore\\(release\\)", skip = true }, + { message = "^Merge (pull request|branch)", skip = true }, { message = "^feat", group = "Features" }, { message = "^fix", group = "Fixes" }, { message = "^perf", group = "Performance" }, diff --git a/scripts/generate.ts b/scripts/generate.ts index 61da672..0d99ea1 100644 --- a/scripts/generate.ts +++ b/scripts/generate.ts @@ -29,7 +29,73 @@ const FIXED_OUTPUTS: Record = { '.muse-plugin/plugin.json': 'muse', '.muse-plugin/marketplace.json': 'muse', 'package.json': 'always', + 'cliff.toml': 'always', }; +// Backticks are written as @@TICK@@ because the template is a String.raw literal. +const CLIFF_TEMPLATE = String.raw`# Generated from plugin.config.json by scripts/build.ts; don't edit by hand. Change the config and rebuild. +# git-cliff config: https://git-cliff.org/docs/configuration +# Generate: npx git-cliff@2.14.2 -o CHANGELOG.md (all releases + unreleased) +# Release: npx git-cliff@2.14.2 --tag vX.Y.Z -o CHANGELOG.md (before tagging vX.Y.Z) +# Notes: npx git-cliff@2.14.2 --latest --strip header (one release, for a GitHub release) + +[changelog] +header = """ +# Changelog + +All notable changes to this repository. Generated by [git-cliff](https://git-cliff.org) from the +commit history (see @@TICK@@cliff.toml@@TICK@@); don't edit by hand.\n +""" +body = """ +{% if version %}\ +## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} +{% else %}\ +## [Unreleased] +{% endif %}\ +{% for group, commits in commits | group_by(attribute="group") %} +### {{ group | striptags | trim | upper_first }} +{% for commit in commits %} +- {% if commit.scope %}**{{ commit.scope }}:** {% endif %}\ +{% if commit.breaking %}**BREAKING** {% endif %}\ +{{ commit.message | split(pat="\n") | first | upper_first | trim }} \ +@@COMMIT@@ +{% endfor %} +{% endfor %}\n +""" +footer = "" +trim = true + +[git] +# Conventional commits (see AGENTS.md); anything else lands under "Changes". +conventional_commits = true +filter_unconventional = false +split_commits = false +protect_breaking_commits = true +commit_parsers = [ + { message = "^Initial commit", skip = true }, + { message = "^chore\\(release\\)", skip = true }, + { message = "^Merge (pull request|branch)", skip = true }, + { message = "^feat", group = "Features" }, + { message = "^fix", group = "Fixes" }, + { message = "^perf", group = "Performance" }, + { message = "^refactor", group = "Refactoring" }, + { message = "^docs", group = "Documentation" }, + { message = "^test", group = "Tests" }, + { message = "^(chore|ci|build)", group = "Maintenance" }, + { message = ".*", group = "Changes" }, +] +tag_pattern = "v[0-9]+\\.[0-9]+\\.[0-9]+$" +sort_commits = "oldest" +`; + +// cliff.toml (the git-cliff changelog config). Only the commit link depends on the config. +function cliffToml(repository: string | undefined): string { + const short = '{{ commit.id | truncate(length=7, end="") }}'; + const base = repository?.replace(/(\.git|\/)+$/, ''); + const commit = base + ? `([${short}](${base}/commit/{{ commit.id }}))\\` + : `(${short})\\`; + return CLIFF_TEMPLATE.replaceAll('@@TICK@@', '`').replace('@@COMMIT@@', () => commit); +} const COPILOT_AGENTS_DIR = 'com.github.copilot/agents'; export interface Skill { @@ -351,6 +417,9 @@ export function plan(root: string, configPath = join(root, 'plugin.config.json') }, }), c.packageJson))); + // cliff.toml: always written; the commit link comes from `repository`. + files.set('cliff.toml', cliffToml(c.repository)); + return { files, errors, warnings }; } diff --git a/tests/build.test.ts b/tests/build.test.ts index e29cfa8..9531973 100644 --- a/tests/build.test.ts +++ b/tests/build.test.ts @@ -285,3 +285,34 @@ test('an icon that is a generated path is a config error and the file is left al 'icon must not be a generated file (.claude-plugin/icon.png): keep the source icon elsewhere, such as assets/icon.png'))); assert.equal(readFileSync(join(root, '.claude-plugin/icon.png'), 'utf8'), 'mine'); }); + +test('cliff.toml is generated: commit link from repository, merge commits skipped', () => { + const root = fixture(config({ name: 'demo', repository: 'https://github.com/someone/demo-plugin.git' })); + put(root, '.opencode/plugins/demo.js', 'export default {};\n'); + const p = plan(root); + assert.deepEqual(p.errors, []); + write(root, p); + const toml = readFileSync(join(root, 'cliff.toml'), 'utf8'); + assert.match(toml, /^# Generated from plugin\.config\.json by scripts\/build\.ts; don't edit by hand\./); + assert.ok(toml.includes('](https://github.com/someone/demo-plugin/commit/{{ commit.id }})')); + assert.ok(toml.includes('{ message = "^Merge (pull request|branch)", skip = true },')); + assert.ok(toml.includes(String.raw`tag_pattern = "v[0-9]+\\.[0-9]+\\.[0-9]+$"`)); + assert.ok(toml.includes(String.raw`{ message = "^chore\\(release\\)", skip = true },`)); + assert.ok(toml.includes('{{ commit.message | split(pat="\\n") | first | upper_first | trim }} \\\n')); + assert.deepEqual(diff(root, plan(root)), { stale: [], missing: [], leftover: [] }); +}); + +test('cliff.toml without a repository prints the commit id as plain text', () => { + const root = fixture(); + write(root, plan(root)); + const toml = readFileSync(join(root, 'cliff.toml'), 'utf8'); + assert.ok(!toml.includes('/commit/')); + assert.ok(toml.includes('{{ commit.id | truncate(length=7, end="") }}')); +}); + +test('a hand-edited cliff.toml is stale', () => { + const root = fixture(); + write(root, plan(root)); + writeFileSync(join(root, 'cliff.toml'), readFileSync(join(root, 'cliff.toml'), 'utf8') + '# edit\n'); + assert.ok(diff(root, plan(root)).stale.includes('cliff.toml')); +});