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
12 changes: 7 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# AGENTS.md

Instructions for coding agents (any harness) working in this repository, and the reference for
Expand Down Expand Up @@ -59,8 +59,7 @@
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
Expand Down Expand Up @@ -157,7 +156,8 @@
├── 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
```

Expand Down Expand Up @@ -224,7 +224,8 @@
| `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`

Expand Down Expand Up @@ -405,7 +406,8 @@
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.

Expand Down
2 changes: 2 additions & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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 = "<!-- 0 -->Features" },
{ message = "^fix", group = "<!-- 1 -->Fixes" },
{ message = "^perf", group = "<!-- 2 -->Performance" },
Expand Down
69 changes: 69 additions & 0 deletions scripts/generate.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Computes every generated file from plugin.config.json and the repo's content folders, then
// writes them (write) or compares them with what is on disk (check). See AGENTS.md, "Generator".

Expand Down Expand Up @@ -29,7 +29,73 @@
'.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 = "<!-- 0 -->Features" },
{ message = "^fix", group = "<!-- 1 -->Fixes" },
{ message = "^perf", group = "<!-- 2 -->Performance" },
{ message = "^refactor", group = "<!-- 3 -->Refactoring" },
{ message = "^docs", group = "<!-- 4 -->Documentation" },
{ message = "^test", group = "<!-- 5 -->Tests" },
{ message = "^(chore|ci|build)", group = "<!-- 6 -->Maintenance" },
{ message = ".*", group = "<!-- 7 -->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 {
Expand Down Expand Up @@ -351,6 +417,9 @@
},
}), c.packageJson)));

// cliff.toml: always written; the commit link comes from `repository`.
files.set('cliff.toml', cliffToml(c.repository));

return { files, errors, warnings };
}

Expand Down
31 changes: 31 additions & 0 deletions tests/build.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Generator tests: each builds a throwaway plugin folder in the temp directory (no network).
import { test } from 'node:test';
import assert from 'node:assert/strict';
Expand Down Expand Up @@ -285,3 +285,34 @@
'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'));
});