Skip to content

Commit e61e1bb

Browse files
authored
feat: Optimize PR workflow with on-demand skill loading and project-level skills management (#12943)
### What this PR does Before this PR: - CLAUDE.md contained detailed PR workflow instructions that were loaded in every agent session, consuming unnecessary tokens - No unified project-level skills management mechanism; adding public skills lacked standardization - No automated checks to prevent non-compliant skills from being merged - Team members had no convenient way to share skills with each other After this PR: - Simplified PR instructions in CLAUDE.md, now loaded on-demand via the `gh-create-pr` skill - Introduced project-level skills management (`.agents/skills/` directory + `public-skills.txt` whitelist) - Added `scripts/skills-sync.ts` and `scripts/skills-check.ts` for automated management - Integrated skills validation into CI to prevent non-whitelisted skills from being merged - **Teams can now easily share skills through the project-level mechanism**, with `skills-sync.ts` automatically syncing skills to all team members' local environments, streamlining onboarding and avoiding duplicated configuration efforts - **Optimized PR creation workflow**: `gh-create-pr` skill enforces English PR body writing and displays the draft to users for review before creation, ensuring quality and compliance Fixes # ### Why we need it and why it was done in this way The following tradeoffs were made: - Moved PR workflow from CLAUDE.md to a skill, sacrificing immediate visibility for token efficiency - **Introduced whitelist mechanism (`public-skills.txt`) instead of auto-scanning all files**: Allows developers to freely use private project-level skills in the `.agents/skills/` directory (e.g., team-internal skills, personal customizations). Only skills added to the whitelist are tracked by git and submitted. This ensures standardization for shared skills while preserving development flexibility - Skills exist in both `.agents/skills/` (project-level, shareable) and `.claude/skills/` (local, private) - **Symlink only SKILL.md files instead of entire directories**: On some Windows/restricted filesystems, symlinks may fail or be treated as regular files. If an entire directory is symlinked, failure results in a regular file instead of a directory, causing complete skill failure that's hard to diagnose. Symlinking only SKILL.md allows quick detection when symlinks fail (file content displays directly or errors), reducing troubleshooting costs The following alternatives were considered: - Keeping PR instructions in CLAUDE.md with collapsible blocks, but this still consumes context tokens - Using git hooks for pre-commit checks, but CI checks are more reliable and don't block local development Links to places where the discussion took place: N/A ### Breaking changes None ### Special notes for your reviewer - `gh-create-pr` skill fully implements the project's PR workflow requirements (read template → display body → confirm → create) - `skills-check.ts` validates: 1) tracked skills are in the whitelist; 2) whitelist skills have corresponding files - Process for adding new public skills: 1) create skill files; 2) add to `public-skills.txt`; 3) CI auto-validation - `.claude/skills/` added to `.gitignore` for private skills ### Checklist This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR. Approvers are expected to review this list. - [x] PR: The PR description is expressive enough and will help future contributors - [x] Code: [Write code that humans can understand](https://en.wikiquote.org/wiki/Martin_Fowler#code-for-humans) and [Keep it simple](https://en.wikipedia.org/wiki/KISS_principle) - [x] Refactor: You have [left the code cleaner than you found it (Boy Scout Rule)](https://learning.oreilly.com/library/view/97-things-every/9780596809515/ch08.html) - [x] Upgrade: Impact of this change on upgrade flows was considered and is present (link) or not required. You want a user-guide update if it's a user facing feature. - [ ] Documentation: A user-guide update was considered and is present (link) or not required. You want a user-guide update if it's a user facing feature. ### Release note ```release-note Optimize PR workflow by moving instructions to on-demand skill; introduce project-level skills management with automated validation ```
1 parent e31029b commit e61e1bb

File tree

17 files changed

+677
-8
lines changed

17 files changed

+677
-8
lines changed

.agents/skills/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# AUTO-GENERATED by `pnpm skills:sync`.
2+
# Do not edit manually.
3+
*
4+
!.gitignore
5+
!README*.md
6+
!public-skills.txt
7+
!gh-create-pr/
8+
!gh-create-pr/**

.agents/skills/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Skills Management
2+
3+
This directory is the single source of truth for repository skills.
4+
5+
## Add a New Skill
6+
7+
1. Create a new folder under `.agents/skills/<skill-name>/`.
8+
2. Add a `SKILL.md` file with:
9+
- `name` and `description` in YAML frontmatter
10+
- concise workflow instructions in the body
11+
3. (Optional) Add `agents/openai.yaml` if Codex UI metadata is needed.
12+
4. If this skill should be shared in the repository, append `<skill-name>` to `.agents/skills/public-skills.txt`.
13+
14+
## Naming Rules
15+
16+
- Use lowercase letters, digits, and hyphens only.
17+
- Prefer short, action-oriented names (for example: `gh-create-pr`).
18+
19+
## Claude Compatibility
20+
21+
For each new public skill, run:
22+
23+
```bash
24+
pnpm skills:sync
25+
```
26+
27+
`skills:sync` will create/update `.claude/skills/<skill-name>/SKILL.md` as:
28+
29+
- a copied file from `.agents/skills/<skill-name>/SKILL.md`.
30+
- symlinks are not allowed; check enforces regular files for compatibility.
31+
32+
## White-list Tracking Rules
33+
34+
The public white-list is defined in `.agents/skills/public-skills.txt`.
35+
36+
- Skills listed there are synced to both `.agents/skills/.gitignore` and `.claude/skills/.gitignore`.
37+
- Private/local-only skills should stay out of `public-skills.txt`.
38+
- Use one skill name per line. Comment lines must start with `#` and cannot be appended inline.
39+
40+
After updating `public-skills.txt`, run:
41+
42+
```bash
43+
pnpm skills:sync
44+
```
45+
46+
Then validate:
47+
48+
```bash
49+
pnpm skills:check
50+
```
51+
52+
The sync/check scripts manage and verify:
53+
54+
- `.agents/skills/.gitignore`
55+
- `.claude/skills/.gitignore`
56+
- `.claude/skills/<skill-name>/SKILL.md` content matches `.agents/skills/<skill-name>/SKILL.md`

.agents/skills/README.zh.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Skills 管理说明
2+
3+
本目录是仓库内 skills 的唯一维护来源(single source of truth)。
4+
5+
## 新增 Skill 流程
6+
7+
1.`.agents/skills/<skill-name>/` 下创建新目录。
8+
2. 添加 `SKILL.md`,包含:
9+
- YAML frontmatter 中的 `name``description`
10+
- 正文中的精简流程说明
11+
3. (可选)如需 Codex UI 元数据,添加 `agents/openai.yaml`
12+
4. 若该 skill 需要作为仓库公共 skill 跟踪,请将 `<skill-name>` 追加到 `.agents/skills/public-skills.txt`
13+
14+
## 命名规则
15+
16+
- 仅使用小写字母、数字和连字符(`-`)。
17+
- 优先使用简短、动作导向的名称(例如:`gh-create-pr`)。
18+
19+
## Claude 兼容
20+
21+
每个新增的公共 skill,请执行:
22+
23+
```bash
24+
pnpm skills:sync
25+
```
26+
27+
`skills:sync` 会自动创建/更新 `.claude/skills/<skill-name>/SKILL.md`
28+
29+
- 复制 `.agents/skills/<skill-name>/SKILL.md` 的内容。
30+
- 不允许使用符号链接;check 会强制要求为普通文件以保证兼容性。
31+
32+
## 白名单跟踪规则
33+
34+
公共白名单由 `.agents/skills/public-skills.txt` 定义。
35+
36+
- 写入该文件的 skill 会同步到 `.agents/skills/.gitignore``.claude/skills/.gitignore`
37+
- 私有/仅本地使用的 skill 不应写入 `public-skills.txt`
38+
- 每行只写一个 skill 名称。注释行必须以 `#` 开头,不能写行尾注释。
39+
40+
更新 `public-skills.txt` 后,请执行:
41+
42+
```bash
43+
pnpm skills:sync
44+
```
45+
46+
然后校验:
47+
48+
```bash
49+
pnpm skills:check
50+
```
51+
52+
上述脚本会自动维护并校验:
53+
54+
- `.agents/skills/.gitignore`
55+
- `.claude/skills/.gitignore`
56+
- `.claude/skills/<skill-name>/SKILL.md``.agents/skills/<skill-name>/SKILL.md` 的内容一致性
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
name: gh-create-pr
3+
description: Create or update GitHub pull requests using the repository-required workflow and template compliance. Use when asked to create/open/update a PR so the assistant reads `.github/pull_request_template.md`, fills every template section, preserves markdown structure exactly, and marks missing data as N/A or None instead of skipping sections.
4+
---
5+
6+
# GitHub PR Creation
7+
8+
## Workflow
9+
10+
1. Read `.github/pull_request_template.md` before drafting the PR body.
11+
2. Collect PR context from the current branch (base/head, scope, linked issues, testing status, breaking changes, release note content).
12+
3. Draft the PR body using the template structure exactly:
13+
- Keep section order and headings.
14+
- Keep checkbox and code block formatting.
15+
- Fill every section; if not applicable, write `N/A` or `None`.
16+
4. Present the full Markdown PR body in chat for review before creating the PR.
17+
5. Ask for explicit confirmation to create the PR with that body.
18+
6. After confirmation, create the PR with `gh pr create --body-file` using a unique temp file path.
19+
7. Report the created PR URL and summarize title/base/head and any required follow-up.
20+
21+
## Constraints
22+
23+
- Never skip template sections.
24+
- Never rewrite the template format.
25+
- Keep content concise and specific to the current change set.
26+
- PR title and body must be written in English.
27+
- Never create the PR before showing the full final body to the user.
28+
- Never rely on command permission prompts as PR body preview.
29+
30+
## Command Pattern
31+
32+
```bash
33+
# read template
34+
cat .github/pull_request_template.md
35+
36+
# show this full Markdown body in chat first
37+
pr_body_file="$(mktemp /tmp/gh-pr-body-XXXXXX).md"
38+
cat > "$pr_body_file" <<'EOF'
39+
...filled template body...
40+
EOF
41+
42+
# run only after explicit user confirmation
43+
gh pr create --base <base> --head <head> --title "<title>" --body-file "$pr_body_file"
44+
rm -f "$pr_body_file"
45+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface:
2+
display_name: "Create GitHub PR"
3+
short_description: "Create PRs with required template compliance"
4+
default_prompt: "Create a pull request for my current branch using the repository template workflow."

.agents/skills/public-skills.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Public skills tracked by skills:sync and skills:check.
2+
# One skill name per line.
3+
gh-create-pr

.claude/skills/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# AUTO-GENERATED by `pnpm skills:sync`.
2+
# Do not edit manually.
3+
*
4+
!.gitignore
5+
!README*.md
6+
!gh-create-pr/
7+
!gh-create-pr/**

.claude/skills/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Claude Skills Mirror
2+
3+
This directory is a synced mirror for Claude-compatible skill files.
4+
5+
- Do not create new skills directly under `.claude/skills`.
6+
- Create and maintain skills under `.agents/skills` only.
7+
- Update `.agents/skills/public-skills.txt`, then run `pnpm skills:sync`.
8+
- `pnpm skills:check` verifies `.claude/skills/<skill>/SKILL.md` matches `.agents/skills/<skill>/SKILL.md`.

.claude/skills/README.zh.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Claude Skills 镜像说明
2+
3+
本目录是面向 Claude 的 skill 文件镜像目录。
4+
5+
- 不要直接在 `.claude/skills` 下创建新 skill。
6+
- 所有 skill 仅在 `.agents/skills` 中创建和维护。
7+
- 更新 `.agents/skills/public-skills.txt` 后,执行 `pnpm skills:sync`
8+
- `pnpm skills:check` 会校验 `.claude/skills/<skill>/SKILL.md``.agents/skills/<skill>/SKILL.md` 内容一致。
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
name: gh-create-pr
3+
description: Create or update GitHub pull requests using the repository-required workflow and template compliance. Use when asked to create/open/update a PR so the assistant reads `.github/pull_request_template.md`, fills every template section, preserves markdown structure exactly, and marks missing data as N/A or None instead of skipping sections.
4+
---
5+
6+
# GitHub PR Creation
7+
8+
## Workflow
9+
10+
1. Read `.github/pull_request_template.md` before drafting the PR body.
11+
2. Collect PR context from the current branch (base/head, scope, linked issues, testing status, breaking changes, release note content).
12+
3. Draft the PR body using the template structure exactly:
13+
- Keep section order and headings.
14+
- Keep checkbox and code block formatting.
15+
- Fill every section; if not applicable, write `N/A` or `None`.
16+
4. Present the full Markdown PR body in chat for review before creating the PR.
17+
5. Ask for explicit confirmation to create the PR with that body.
18+
6. After confirmation, create the PR with `gh pr create --body-file` using a unique temp file path.
19+
7. Report the created PR URL and summarize title/base/head and any required follow-up.
20+
21+
## Constraints
22+
23+
- Never skip template sections.
24+
- Never rewrite the template format.
25+
- Keep content concise and specific to the current change set.
26+
- PR title and body must be written in English.
27+
- Never create the PR before showing the full final body to the user.
28+
- Never rely on command permission prompts as PR body preview.
29+
30+
## Command Pattern
31+
32+
```bash
33+
# read template
34+
cat .github/pull_request_template.md
35+
36+
# show this full Markdown body in chat first
37+
pr_body_file="$(mktemp /tmp/gh-pr-body-XXXXXX).md"
38+
cat > "$pr_body_file" <<'EOF'
39+
...filled template body...
40+
EOF
41+
42+
# run only after explicit user confirmation
43+
gh pr create --base <base> --head <head> --title "<title>" --body-file "$pr_body_file"
44+
rm -f "$pr_body_file"
45+
```

0 commit comments

Comments
 (0)