@benbenwu/zcf 3.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +193 -0
  3. package/bin/zcf.mjs +2 -0
  4. package/dist/chunks/api-providers.mjs +137 -0
  5. package/dist/chunks/claude-code-config-manager.mjs +731 -0
  6. package/dist/chunks/claude-code-incremental-manager.mjs +601 -0
  7. package/dist/chunks/codex-config-switch.mjs +394 -0
  8. package/dist/chunks/codex-provider-manager.mjs +197 -0
  9. package/dist/chunks/codex-uninstaller.mjs +422 -0
  10. package/dist/chunks/commands.mjs +118 -0
  11. package/dist/chunks/features.mjs +632 -0
  12. package/dist/chunks/simple-config.mjs +7904 -0
  13. package/dist/cli.d.mts +1 -0
  14. package/dist/cli.d.ts +1 -0
  15. package/dist/cli.mjs +2013 -0
  16. package/dist/i18n/locales/en/api.json +53 -0
  17. package/dist/i18n/locales/en/ccr.json +65 -0
  18. package/dist/i18n/locales/en/cli.json +55 -0
  19. package/dist/i18n/locales/en/codex.json +123 -0
  20. package/dist/i18n/locales/en/cometix.json +29 -0
  21. package/dist/i18n/locales/en/common.json +20 -0
  22. package/dist/i18n/locales/en/configuration.json +85 -0
  23. package/dist/i18n/locales/en/errors.json +26 -0
  24. package/dist/i18n/locales/en/installation.json +80 -0
  25. package/dist/i18n/locales/en/language.json +19 -0
  26. package/dist/i18n/locales/en/mcp.json +24 -0
  27. package/dist/i18n/locales/en/menu.json +51 -0
  28. package/dist/i18n/locales/en/multi-config.json +79 -0
  29. package/dist/i18n/locales/en/tools.json +15 -0
  30. package/dist/i18n/locales/en/uninstall.json +56 -0
  31. package/dist/i18n/locales/en/updater.json +25 -0
  32. package/dist/i18n/locales/en/workflow.json +23 -0
  33. package/dist/i18n/locales/zh-CN/api.json +53 -0
  34. package/dist/i18n/locales/zh-CN/ccr.json +65 -0
  35. package/dist/i18n/locales/zh-CN/cli.json +55 -0
  36. package/dist/i18n/locales/zh-CN/codex.json +123 -0
  37. package/dist/i18n/locales/zh-CN/cometix.json +29 -0
  38. package/dist/i18n/locales/zh-CN/common.json +20 -0
  39. package/dist/i18n/locales/zh-CN/configuration.json +85 -0
  40. package/dist/i18n/locales/zh-CN/errors.json +26 -0
  41. package/dist/i18n/locales/zh-CN/installation.json +80 -0
  42. package/dist/i18n/locales/zh-CN/language.json +19 -0
  43. package/dist/i18n/locales/zh-CN/mcp.json +24 -0
  44. package/dist/i18n/locales/zh-CN/menu.json +51 -0
  45. package/dist/i18n/locales/zh-CN/multi-config.json +79 -0
  46. package/dist/i18n/locales/zh-CN/tools.json +15 -0
  47. package/dist/i18n/locales/zh-CN/uninstall.json +56 -0
  48. package/dist/i18n/locales/zh-CN/updater.json +25 -0
  49. package/dist/i18n/locales/zh-CN/workflow.json +23 -0
  50. package/dist/index.d.mts +324 -0
  51. package/dist/index.d.ts +324 -0
  52. package/dist/index.mjs +19 -0
  53. package/dist/shared/zcf.DGjQxTq_.mjs +34 -0
  54. package/package.json +117 -0
  55. package/templates/CLAUDE.md +221 -0
  56. package/templates/claude-code/CLAUDE.md +250 -0
  57. package/templates/claude-code/common/settings.json +48 -0
  58. package/templates/claude-code/en/workflow/bmad/commands/bmad-init.md +275 -0
  59. package/templates/claude-code/en/workflow/common/agents/get-current-datetime.md +29 -0
  60. package/templates/claude-code/en/workflow/common/agents/init-architect.md +114 -0
  61. package/templates/claude-code/en/workflow/common/commands/init-project.md +53 -0
  62. package/templates/claude-code/en/workflow/plan/agents/planner.md +116 -0
  63. package/templates/claude-code/en/workflow/plan/agents/ui-ux-designer.md +91 -0
  64. package/templates/claude-code/en/workflow/plan/commands/feat.md +105 -0
  65. package/templates/claude-code/zh-CN/workflow/bmad/commands/bmad-init.md +275 -0
  66. package/templates/claude-code/zh-CN/workflow/common/agents/get-current-datetime.md +29 -0
  67. package/templates/claude-code/zh-CN/workflow/common/agents/init-architect.md +114 -0
  68. package/templates/claude-code/zh-CN/workflow/common/commands/init-project.md +53 -0
  69. package/templates/claude-code/zh-CN/workflow/plan/agents/planner.md +116 -0
  70. package/templates/claude-code/zh-CN/workflow/plan/agents/ui-ux-designer.md +91 -0
  71. package/templates/claude-code/zh-CN/workflow/plan/commands/feat.md +105 -0
  72. package/templates/codex/common/config.toml +0 -0
  73. package/templates/common/output-styles/en/engineer-professional.md +88 -0
  74. package/templates/common/output-styles/en/laowang-engineer.md +127 -0
  75. package/templates/common/output-styles/en/leibus-engineer.md +251 -0
  76. package/templates/common/output-styles/en/nekomata-engineer.md +120 -0
  77. package/templates/common/output-styles/en/ojousama-engineer.md +121 -0
  78. package/templates/common/output-styles/en/rem-engineer.md +173 -0
  79. package/templates/common/output-styles/zh-CN/engineer-professional.md +89 -0
  80. package/templates/common/output-styles/zh-CN/laowang-engineer.md +127 -0
  81. package/templates/common/output-styles/zh-CN/leibus-engineer.md +251 -0
  82. package/templates/common/output-styles/zh-CN/nekomata-engineer.md +120 -0
  83. package/templates/common/output-styles/zh-CN/ojousama-engineer.md +121 -0
  84. package/templates/common/output-styles/zh-CN/rem-engineer.md +179 -0
  85. package/templates/common/workflow/git/en/git-cleanBranches.md +102 -0
  86. package/templates/common/workflow/git/en/git-commit.md +205 -0
  87. package/templates/common/workflow/git/en/git-rollback.md +90 -0
  88. package/templates/common/workflow/git/en/git-worktree.md +276 -0
  89. package/templates/common/workflow/git/zh-CN/git-cleanBranches.md +102 -0
  90. package/templates/common/workflow/git/zh-CN/git-commit.md +205 -0
  91. package/templates/common/workflow/git/zh-CN/git-rollback.md +90 -0
  92. package/templates/common/workflow/git/zh-CN/git-worktree.md +276 -0
  93. package/templates/common/workflow/sixStep/en/workflow.md +251 -0
  94. package/templates/common/workflow/sixStep/zh-CN/workflow.md +215 -0
@@ -0,0 +1,90 @@
1
+ ---
2
+ description: Interactively rollback Git branch to historical version; lists branches, versions, then executes reset/revert after confirmation
3
+ allowed-tools: Read(**), Exec(git fetch, git branch, git tag, git log, git reflog, git checkout, git reset, git revert, git switch), Write()
4
+ argument-hint: [--branch <branch>] [--target <rev>] [--mode reset|revert] [--depth <n>] [--dry-run] [--yes]
5
+ # examples:
6
+ # - /git-rollback # Full interactive mode, dry-run
7
+ # - /git-rollback --branch dev # Select dev directly, other interactive
8
+ # - /git-rollback --branch dev --target v1.2.0 --mode reset --yes
9
+ ---
10
+
11
+ # Claude Command: Git Rollback
12
+
13
+ **Purpose**: Safely and visually rollback a specified branch to an older version.
14
+ Defaults to **read-only preview (`--dry-run`)**; actual execution requires `--yes` or interactive confirmation.
15
+
16
+ ---
17
+
18
+ ## Usage
19
+
20
+ ```bash
21
+ # Pure interactive: list branches → select branch → list recent 20 versions → select target → choose reset or revert → confirm
22
+ /git-rollback
23
+
24
+ # Specify branch, other interactive
25
+ /git-rollback --branch feature/calculator
26
+
27
+ # Specify branch and target commit, execute with hard-reset in one go (dangerous)
28
+ /git-rollback --branch main --target 1a2b3c4d --mode reset --yes
29
+
30
+ # Generate revert commit only (non-destructive rollback), preview
31
+ /git-rollback --branch release/v2.1 --target v2.0.5 --mode revert --dry-run
32
+ ```
33
+
34
+ ### Options
35
+
36
+ | Option | Description |
37
+ | ---------------------- | ------------------------------------------------------------------------------------------------------------------ |
38
+ | `--branch <branch>` | Branch to rollback; interactively selected if omitted. |
39
+ | `--target <rev>` | Target version (commit hash, tag, or reflog reference); interactively selects recent `--depth` entries if omitted. |
40
+ | `--mode reset\|revert` | `reset`: Hard rollback history; `revert`: Generate reverse commits keeping history intact. Prompts by default. |
41
+ | `--depth <n>` | List recent n versions in interactive mode (default 20). |
42
+ | `--dry-run` | **Enabled by default**, only preview commands to be executed. |
43
+ | `--yes` | Skip all confirmations and execute directly, suitable for CI/CD scripts. |
44
+
45
+ ---
46
+
47
+ ## Interactive Flow
48
+
49
+ 1. **Sync remote** → `git fetch --all --prune`
50
+ 2. **List branches** → `git branch -a` (local + remote, filter protected branches)
51
+ 3. **Select branch** → User input or parameter
52
+ 4. **List versions** → `git log --oneline -n <depth>` + `git tag --merged` + `git reflog -n <depth>`
53
+ 5. **Select target** → User inputs commit hash / tag
54
+ 6. **Select mode** → `reset` or `revert`
55
+ 7. **Final confirmation** (unless `--yes`)
56
+ 8. **Execute rollback**
57
+ - `reset`: `git switch <branch> && git reset --hard <target>`
58
+ - `revert`: `git switch <branch> && git revert --no-edit <target>..HEAD`
59
+ 9. **Push suggestion** → Prompt whether to `git push --force-with-lease` (reset) or regular `git push` (revert)
60
+
61
+ ---
62
+
63
+ ## Safety Guards
64
+
65
+ - **Backup**: Automatically records current HEAD in reflog before execution, recoverable with `git switch -c backup/<timestamp>`.
66
+ - **Protected branches**: If protected branches like `main` / `master` / `production` are detected with `reset` mode enabled, requires additional confirmation.
67
+ - **--dry-run enabled by default**: Prevents accidental operations.
68
+ - **--force prohibited**: No `--force` provided; if force push needed, manually enter `git push --force-with-lease`.
69
+
70
+ ---
71
+
72
+ ## Use Case Examples
73
+
74
+ | Scenario | Command Example |
75
+ | --------------------------------------------------------------------------- | ---------------------------------------------------------------- |
76
+ | Hotfix patch deployed with bug, need to rollback to tag `v1.2.0` | `/git-rollback --branch release/v1 --target v1.2.0 --mode reset` |
77
+ | Ops colleague pushed debug logs by mistake, need to generate reverse commit | `/git-rollback --branch main --target 3f2e7c9 --mode revert` |
78
+ | Research historical bugs, guide newcomers through branch history | `/git-rollback` (full interactive, dry-run) |
79
+
80
+ ---
81
+
82
+ ## Notes
83
+
84
+ 1. **reset vs revert**
85
+ - **reset** changes history, requires force push and may affect other collaborators, use with caution.
86
+ - **revert** is safer, generates new commits preserving history, but adds one more record.
87
+ 2. **Embedded repositories** often have large binary files; ensure LFS/submodule state consistency before rollback.
88
+ 3. If repository has CI forced validation, rollback may trigger pipelines automatically; confirm control policies to avoid accidental deployment of old versions.
89
+
90
+ ---
@@ -0,0 +1,276 @@
1
+ ---
2
+ description: Manage Git worktrees in project-level ../.zcf/project-name/ directory with smart defaults, IDE integration and content migration
3
+ allowed-tools: Read(**), Exec(git worktree add, git worktree list, git worktree remove, git worktree prune, git branch, git checkout, git rev-parse, git stash, git cp, detect-ide, open-ide, which, command, basename, dirname)
4
+ argument-hint: <add|list|remove|prune|migrate> [path] [-b <branch>] [-o|--open] [--track] [--guess-remote] [--detach] [--checkout] [--lock] [--migrate-from <source-path>] [--migrate-stash]
5
+ # examples:
6
+ # - /git-worktree add feature-ui # create new branch 'feature-ui' from main/master
7
+ # - /git-worktree add feature-ui -o # create worktree and open directly in IDE
8
+ # - /git-worktree add hotfix -b fix/login -o # create new branch 'fix/login' with path 'hotfix'
9
+ # - /git-worktree migrate feature-ui --from main # migrate uncommitted content from main to feature-ui
10
+ # - /git-worktree migrate feature-ui --stash # migrate current stash to feature-ui
11
+ ---
12
+
13
+ # Claude Command: Git Worktree
14
+
15
+ Manage Git worktrees with smart defaults, IDE integration and content migration in structured `../.zcf/project-name/` paths.
16
+
17
+ Execute commands directly and provide concise results.
18
+
19
+ ---
20
+
21
+ ## Usage
22
+
23
+ ```bash
24
+ # Basic operations
25
+ /git-worktree add <path> # create new branch named <path> from main/master
26
+ /git-worktree add <path> -b <branch> # create new branch with specified name
27
+ /git-worktree add <path> -o # create and open directly in IDE
28
+ /git-worktree list # show all worktree status
29
+ /git-worktree remove <path> # remove specified worktree
30
+ /git-worktree prune # clean invalid worktree references
31
+
32
+ # Content migration
33
+ /git-worktree migrate <target> --from <source> # migrate uncommitted content
34
+ /git-worktree migrate <target> --stash # migrate stash content
35
+ ```
36
+
37
+ ### Options
38
+
39
+ | Option | Description |
40
+ | ------------------ | ------------------------------------------------------ |
41
+ | `add [<path>]` | Add new worktree in `../.zcf/project-name/<path>` |
42
+ | `migrate <target>` | Migrate content to specified worktree |
43
+ | `list` | List all worktrees and their status |
44
+ | `remove <path>` | Remove worktree at specified path |
45
+ | `prune` | Clean invalid worktree references |
46
+ | `-b <branch>` | Create new branch and checkout to worktree |
47
+ | `-o, --open` | Open directly in IDE after creation (skip prompt) |
48
+ | `--from <source>` | Specify migration source path (migrate only) |
49
+ | `--stash` | Migrate current stash content (migrate only) |
50
+ | `--track` | Set new branch to track corresponding remote branch |
51
+ | `--guess-remote` | Auto guess remote branch for tracking |
52
+ | `--detach` | Create detached HEAD worktree |
53
+ | `--checkout` | Checkout immediately after creation (default behavior) |
54
+ | `--lock` | Lock worktree after creation |
55
+
56
+ ---
57
+
58
+ ## What This Command Does
59
+
60
+ 1. **Environment Check**
61
+ - Verify Git repository using `git rev-parse --is-inside-work-tree`
62
+ - Detect whether in main repo or existing worktree for smart path calculation
63
+
64
+ 2. **Smart Path Management**
65
+ - Auto-calculate project name from main repository path using worktree detection
66
+ - Create worktrees in structured `../.zcf/project-name/<path>` directory
67
+ - Handle both main repo and worktree execution contexts correctly
68
+
69
+ ```bash
70
+ # Core path calculation logic for worktree detection
71
+ get_main_repo_path() {
72
+ local git_common_dir=$(git rev-parse --git-common-dir 2>/dev/null)
73
+ local current_toplevel=$(git rev-parse --show-toplevel 2>/dev/null)
74
+
75
+ # Check if in worktree
76
+ if [[ "$git_common_dir" != "$current_toplevel/.git" ]]; then
77
+ # In worktree, derive main repo path from git-common-dir
78
+ dirname "$git_common_dir"
79
+ else
80
+ # In main repository
81
+ echo "$current_toplevel"
82
+ fi
83
+ }
84
+
85
+ MAIN_REPO_PATH=$(get_main_repo_path)
86
+ PROJECT_NAME=$(basename "$MAIN_REPO_PATH")
87
+ WORKTREE_BASE="$MAIN_REPO_PATH/../.zcf/$PROJECT_NAME"
88
+
89
+ # Always use absolute path to prevent nesting issues
90
+ ABSOLUTE_WORKTREE_PATH="$WORKTREE_BASE/<path>"
91
+ ```
92
+
93
+ **Critical Fix**: Always use absolute paths when creating worktrees from within existing worktrees to prevent path nesting issues like `../.zcf/project/.zcf/project/path`.
94
+
95
+ 3. **Worktree Operations**
96
+ - **add**: Create new worktree with smart branch/path defaults
97
+ - **list**: Display all worktrees with branches and status
98
+ - **remove**: Safely remove worktree and clean references
99
+ - **prune**: Clean orphaned worktree records
100
+
101
+ 4. **Smart Defaults**
102
+ - **Branch creation**: When no `-b` specified, create new branch using path name
103
+ - **Base branch**: New branches created from main/master branch
104
+ - **Path resolution**: Use branch name as path when unspecified
105
+ - **IDE integration**: Auto-detect and prompt for IDE opening
106
+
107
+ 5. **Content Migration**
108
+ - Migrate uncommitted changes between worktrees
109
+ - Apply stash content to target worktree
110
+ - Safety checks to prevent conflicts
111
+
112
+ 6. **Safety Features**
113
+ - **Path conflict prevention**: Check for existing directories before creation
114
+ - **Branch checkout validation**: Ensure branches aren't already in use
115
+ - **Absolute path enforcement**: Prevent nested `.zcf` directories when in worktree
116
+ - **Auto-cleanup on removal**: Clean both directory and git references
117
+ - **Clear status reporting**: Display worktree locations and branch status
118
+
119
+ 7. **Environment File Handling**
120
+ - **Auto-detection**: Scan `.gitignore` for environment variable file patterns
121
+ - **Smart copying**: Copy `.env` and `.env.*` files that are listed in `.gitignore`
122
+ - **Exclusion logic**: Skip `.env.example` and other template files
123
+ - **Permission preservation**: Maintain original file permissions and timestamps
124
+ - **User feedback**: Provide clear status on copied environment files
125
+
126
+ ```bash
127
+ # Environment file copying implementation
128
+ copy_environment_files() {
129
+ local main_repo="$MAIN_REPO_PATH"
130
+ local target_worktree="$ABSOLUTE_WORKTREE_PATH"
131
+ local gitignore_file="$main_repo/.gitignore"
132
+
133
+ # Check if .gitignore exists
134
+ if [[ ! -f "$gitignore_file" ]]; then
135
+ return 0
136
+ fi
137
+
138
+ local copied_count=0
139
+
140
+ # Detect .env file
141
+ if [[ -f "$main_repo/.env" ]] && grep -q "^\.env$" "$gitignore_file"; then
142
+ cp "$main_repo/.env" "$target_worktree/.env"
143
+ echo "✅ Copied .env"
144
+ ((copied_count++))
145
+ fi
146
+
147
+ # Detect .env.* pattern files (excluding .env.example)
148
+ for env_file in "$main_repo"/.env.*; do
149
+ if [[ -f "$env_file" ]] && [[ "$(basename "$env_file")" != ".env.example" ]]; then
150
+ local filename=$(basename "$env_file")
151
+ if grep -q "^\.env\.\*$" "$gitignore_file"; then
152
+ cp "$env_file" "$target_worktree/$filename"
153
+ echo "✅ Copied $filename"
154
+ ((copied_count++))
155
+ fi
156
+ fi
157
+ done
158
+
159
+ if [[ $copied_count -gt 0 ]]; then
160
+ echo "📋 Copied $copied_count environment file(s) from .gitignore"
161
+ fi
162
+ }
163
+ ```
164
+
165
+ ---
166
+
167
+ ## Enhanced Features
168
+
169
+ ### IDE Integration
170
+
171
+ - **Auto-detection**: VS Code → Cursor → WebStorm → Sublime Text → Vim
172
+ - **Smart prompting**: Ask to open in IDE after worktree creation
173
+ - **Direct open**: Use `-o` flag to skip prompt and open immediately
174
+ - **Custom configuration**: Configurable via git config
175
+
176
+ ### Content Migration System
177
+
178
+ ```bash
179
+ # Migrate uncommitted changes
180
+ /git-worktree migrate feature-ui --from main
181
+ /git-worktree migrate hotfix --from ../other-worktree
182
+
183
+ # Migrate stash content
184
+ /git-worktree migrate feature-ui --stash
185
+ ```
186
+
187
+ **Migration Flow**:
188
+
189
+ 1. Verify source has uncommitted content
190
+ 2. Ensure target worktree is clean
191
+ 3. Show changes to be migrated
192
+ 4. Execute safe migration using git commands
193
+ 5. Confirm results and suggest next steps
194
+
195
+ ---
196
+
197
+ ## Examples
198
+
199
+ ```bash
200
+ # Basic usage
201
+ /git-worktree add feature-ui # create new branch 'feature-ui' from main/master
202
+ /git-worktree add feature-ui -b my-feature # create new branch 'my-feature' with path 'feature-ui'
203
+ /git-worktree add feature-ui -o # create and open in IDE directly
204
+
205
+ # Content migration scenarios
206
+ /git-worktree add feature-ui -b feature/new-ui # create new feature worktree
207
+ /git-worktree migrate feature-ui --from main # migrate uncommitted changes
208
+ /git-worktree migrate hotfix --stash # migrate stash content
209
+
210
+ # Management operations
211
+ /git-worktree list # view all worktrees
212
+ /git-worktree remove feature-ui # remove unneeded worktree
213
+ /git-worktree prune # clean invalid references
214
+ ```
215
+
216
+ **Example Output**:
217
+
218
+ ```
219
+ ✅ Worktree created at ../.zcf/project-name/feature-ui
220
+ ✅ Copied .env
221
+ ✅ Copied .env.local
222
+ 📋 Copied 2 environment file(s) from .gitignore
223
+ 🖥️ Open ../.zcf/project-name/feature-ui in IDE? [y/n]: y
224
+ 🚀 Opening ../.zcf/project-name/feature-ui in VS Code...
225
+ ```
226
+
227
+ ---
228
+
229
+ ## Directory Structure
230
+
231
+ ```
232
+ parent-directory/
233
+ ├── your-project/ # main project
234
+ │ ├── .git/
235
+ │ └── src/
236
+ └── .zcf/ # worktree management
237
+ └── your-project/ # project worktrees
238
+ ├── feature-ui/ # feature branch
239
+ ├── hotfix/ # hotfix branch
240
+ └── debug/ # debug worktree
241
+ ```
242
+
243
+ ---
244
+
245
+ ## Configuration
246
+
247
+ ### IDE Configuration
248
+
249
+ - Supports VS Code, Cursor, WebStorm, Sublime Text, Vim
250
+ - Configurable via git config for custom IDEs
251
+ - Auto-detection with priority-based selection
252
+
253
+ ### Custom IDE Setup
254
+
255
+ ```bash
256
+ # Configure custom IDE
257
+ git config worktree.ide.custom.sublime "subl %s"
258
+ git config worktree.ide.preferred "sublime"
259
+
260
+ # Control auto-detection
261
+ git config worktree.ide.autodetect true # default
262
+ ```
263
+
264
+ ---
265
+
266
+ ## Notes
267
+
268
+ - **Performance**: Worktrees share `.git` directory, saving disk space
269
+ - **Safety**: Path conflict prevention and branch checkout validation
270
+ - **Migration**: Only uncommitted changes; use `git cherry-pick` for commits
271
+ - **IDE requirement**: Command-line tools must be in PATH
272
+ - **Cross-platform**: Supports Windows, macOS, Linux
273
+ - **Environment files**: Automatically copies environment files listed in `.gitignore` to new worktrees
274
+ - **File exclusions**: Template files like `.env.example` are preserved in main repo only
275
+
276
+ ---
@@ -0,0 +1,102 @@
1
+ ---
2
+ description: 安全查找并清理已合并或过期的 Git 分支,支持 dry-run 模式与自定义基准/保护分支
3
+ allowed-tools: Read(**), Exec(git fetch, git config, git branch, git remote, git push, git for-each-ref, git log), Write()
4
+ argument-hint: [--base <branch>] [--stale <days>] [--remote] [--force] [--dry-run] [--yes]
5
+ # examples:
6
+ # - /git-cleanBranches --dry-run
7
+ # - /git-cleanBranches --base release/v2.1 --stale 90
8
+ # - /git-cleanBranches --remote --yes
9
+ ---
10
+
11
+ # Claude Command: Clean Branches
12
+
13
+ 该命令**安全地**识别并清理**已合并**或**长期未更新 (stale)** 的 Git 分支。
14
+ 默认以**只读预览 (`--dry-run`)** 模式运行,需明确指令才会执行删除操作。
15
+
16
+ ---
17
+
18
+ ## Usage
19
+
20
+ ```bash
21
+ # [最安全] 预览将要清理的分支,不执行任何删除
22
+ /git-cleanBranches --dry-run
23
+
24
+ # 清理已合并到 main 且超过 90 天未动的本地分支 (需逐一确认)
25
+ /git-cleanBranches --stale 90
26
+
27
+ # 清理已合并到 release/v2.1 的本地与远程分支 (自动确认)
28
+ /git-cleanBranches --base release/v2.1 --remote --yes
29
+
30
+ # [危险] 强制删除一个未合并的本地分支
31
+ /git-cleanBranches --force outdated-feature
32
+ ```
33
+
34
+ ### Options
35
+
36
+ - `--base <branch>`:指定清理的基准分支(默认为仓库的 `main`/`master`)。
37
+ - `--stale <days>`:清理超过指定天数未提交的分支(默认不启用)。
38
+ - `--remote`:同时清理远程已合并/过期的分支。
39
+ - `--dry-run`:**默认行为**。仅列出将要删除的分支,不执行任何操作。
40
+ - `--yes`:跳过逐一确认的步骤,直接删除所有已识别的分支(适合 CI/CD)。
41
+ - `--force`:使用 `-D` 强制删除本地分支(即使未合并)。
42
+
43
+ ---
44
+
45
+ ## What This Command Does
46
+
47
+ 1. **配置与安全预检**
48
+ - **更新信息**:自动执行 `git fetch --all --prune`,确保分支状态最新。
49
+ - **读取保护分支**:从 Git 配置读取不应被清理的分支列表(见下文“Configuration”)。
50
+ - **确定基准**:使用 `--base` 参数或自动识别的 `main`/`master` 作为比较基准。
51
+
52
+ 2. **分析识别(Find)**
53
+ - **已合并分支**:找出已完全合并到 `--base` 的本地(及远程,如加 `--remote`)分支。
54
+ - **过期分支**:如指定 `--stale <days>`,找出最后一次提交在 N 天前的分支。
55
+ - **排除保护分支**:从待清理列表中移除所有已配置的保护分支。
56
+
57
+ 3. **报告预览(Report)**
58
+ - 清晰列出“将要删除的已合并分支”与“将要删除的过期分支”。
59
+ - 若无 `--yes` 参数,**命令到此结束**,等待用户确认后再次执行(不带 `--dry-run`)。
60
+
61
+ 4. **执行清理(Execute)**
62
+ - **仅在不带 `--dry-run` 且用户确认后**(或带 `--yes`)执行。
63
+ - 逐一删除已识别的分支,除非用户在交互式确认中选择跳过。
64
+ - 本地用 `git branch -d <branch>`;远程用 `git push origin --delete <branch>`。
65
+ - 若指定 `--force`,本地删除会改用 `git branch -D <branch>`。
66
+
67
+ ---
68
+
69
+ ## Configuration (一次配置,永久生效)
70
+
71
+ 为防止误删重要分支(如 `develop`, `release/*`),请在仓库的 Git 配置中添加保护规则。命令会自动读取。
72
+
73
+ ```bash
74
+ # 保护 develop 分支
75
+ git config --add branch.cleanup.protected develop
76
+
77
+ # 保护所有 release/ 开头的分支 (通配符)
78
+ git config --add branch.cleanup.protected 'release/*'
79
+
80
+ # 查看所有已配置的保护分支
81
+ git config --get-all branch.cleanup.protected
82
+ ```
83
+
84
+ ---
85
+
86
+ ## Best Practices for Embedded Devs
87
+
88
+ - **优先 `--dry-run`**:养成先预览再执行的习惯。
89
+ - **活用 `--base`**:维护长期 `release` 分支时,用它来清理已合并到该 release 的 `feature` 或 `hotfix` 分支。
90
+ - **谨慎 `--force`**:除非你百分百确定某个未合并分支是无用功,否则不要强制删除。
91
+ - **团队协作**:在清理共享的远程分支前,先在团队频道通知一声。
92
+ - **定期运行**:每月或每季度运行一次,保持仓库清爽。
93
+
94
+ ---
95
+
96
+ ## Why This Version Is Better
97
+
98
+ - ✅ **更安全**:默认只读预览,且有可配置的保护分支列表。
99
+ - ✅ **更灵活**:支持自定义基准分支,完美适配 `release` / `develop` 工作流。
100
+ - ✅ **更兼容**:避免了在不同系统上行为不一的 `date -d` 等命令。
101
+ - ✅ **更直观**:将复杂的 16 步清单,浓缩成一个带安全选项的、可直接执行的命令。
102
+ - ✅ **风格一致**:与 `/commit` 命令共享相似的参数设计与文档结构。
@@ -0,0 +1,205 @@
1
+ ---
2
+ description: 仅用 Git 分析改动并自动生成 conventional commit 信息(可选 emoji);必要时建议拆分提交,默认运行本地 Git 钩子(可 --no-verify 跳过)
3
+ allowed-tools: Read(**), Exec(git status, git diff, git add, git restore --staged, git commit, git rev-parse, git config), Write(.git/COMMIT_EDITMSG)
4
+ argument-hint: [--no-verify] [--all] [--amend] [--signoff] [--emoji] [--scope <scope>] [--type <type>]
5
+ # examples:
6
+ # - /git-commit # 分析当前改动,生成提交信息
7
+ # - /git-commit --all # 暂存所有改动并提交
8
+ # - /git-commit --no-verify # 跳过 Git 钩子检查
9
+ # - /git-commit --emoji # 在提交信息中包含 emoji
10
+ # - /git-commit --scope ui --type feat # 指定作用域和类型
11
+ # - /git-commit --amend --signoff # 修补上次提交并签名
12
+ ---
13
+
14
+ # Claude Command: Commit (Git-only)
15
+
16
+ 该命令在**不依赖任何包管理器/构建工具**的前提下,仅通过 **Git**:
17
+
18
+ - 读取改动(staged/unstaged)
19
+ - 判断是否需要**拆分为多次提交**
20
+ - 为每个提交生成 **Conventional Commits** 风格的信息(可选 emoji)
21
+ - 按需执行 `git add` 与 `git commit`(默认运行本地 Git 钩子;可 `--no-verify` 跳过)
22
+
23
+ ---
24
+
25
+ ## Usage
26
+
27
+ ```bash
28
+ /git-commit
29
+ /git-commit --no-verify
30
+ /git-commit --emoji
31
+ /git-commit --all --signoff
32
+ /git-commit --amend
33
+ /git-commit --scope ui --type feat --emoji
34
+ ```
35
+
36
+ ### Options
37
+
38
+ - `--no-verify`:跳过本地 Git 钩子(`pre-commit`/`commit-msg` 等)。
39
+ - `--all`:当暂存区为空时,自动 `git add -A` 将所有改动纳入本次提交。
40
+ - `--amend`:在不创建新提交的情况下**修补**上一次提交(保持提交作者与时间,除非本地 Git 配置另有指定)。
41
+ - `--signoff`:附加 `Signed-off-by` 行(遵循 DCO 流程时使用)。
42
+ - `--emoji`:在提交信息中包含 emoji 前缀(省略则使用纯文本)。
43
+ - `--scope <scope>`:指定提交作用域(如 `ui`、`docs`、`api`),写入消息头部。
44
+ - `--type <type>`:强制提交类型(如 `feat`、`fix`、`docs` 等),覆盖自动判断。
45
+
46
+ > 注:如框架不支持交互式确认,可在 front-matter 中开启 `confirm: true` 以避免误操作。
47
+
48
+ ---
49
+
50
+ ## What This Command Does
51
+
52
+ 1. **仓库/分支校验**
53
+ - 通过 `git rev-parse --is-inside-work-tree` 判断是否位于 Git 仓库。
54
+ - 读取当前分支/HEAD 状态;如处于 rebase/merge 冲突状态,先提示处理冲突后再继续。
55
+
56
+ 2. **改动检测**
57
+ - 用 `git status --porcelain` 与 `git diff` 获取已暂存与未暂存的改动。
58
+ - 若已暂存文件为 0:
59
+ - 若传入 `--all` → 执行 `git add -A`。
60
+ - 否则提示你选择:继续仅分析未暂存改动并给出**建议**,或取消命令后手动分组暂存。
61
+
62
+ 3. **拆分建议(Split Heuristics)**
63
+ - 按**关注点**、**文件模式**、**改动类型**聚类(示例:源代码 vs 文档、测试;不同目录/包;新增 vs 删除)。
64
+ - 若检测到**多组独立变更**或 diff 规模过大(如 > 300 行 / 跨多个顶级目录),建议拆分提交,并给出每一组的 pathspec(便于后续执行 `git add <paths>`)。
65
+
66
+ 4. **提交信息生成(Conventional 规范,可选 Emoji)**
67
+ - 自动推断 `type`(`feat`/`fix`/`docs`/`refactor`/`test`/`chore`/`perf`/`style`/`ci`/`revert` …)与可选 `scope`。
68
+ - 生成消息头:`[<emoji>] <type>(<scope>)?: <subject>`(首行 ≤ 72 字符,祈使语气,仅在使用 `--emoji` 时包含 emoji)。
69
+ - 生成消息体:
70
+ - 必须在 subject 之后空一行。
71
+ - 使用列表格式,每项以 `-` 开头。
72
+ - 每项**必须使用动词开头的祈使句**(如 "add…"、"fix…"、"update…")。
73
+ - **禁止使用冒号分隔的格式**(如 ~~"Feature: description"~~、~~"Impl: content"~~)。
74
+ - 说明变更的动机、实现要点或影响范围(3 项以内为宜)。
75
+ - 生成消息脚注(如有):
76
+ - 必须在 Body 之后空一行。
77
+ - **BREAKING CHANGE**:若存在破坏性变更,必须包含 `BREAKING CHANGE: <description>`,或在类型后添加感叹号(如 `feat!:`)。
78
+ - 其它脚注采用 git trailer 格式(如 `Closes #123`、`Refs: #456`、`Reviewed-by: Name`)。
79
+ - 根据 Git 历史提交的主要语言选择提交信息语言。优先检查最近提交主题(例如 `git log -n 50 --pretty=%s`)判断中文/英文;若无法判断,则回退到仓库主要语言或英文。
80
+ - 将草稿写入 `.git/COMMIT_EDITMSG`,并用于 `git commit`。
81
+
82
+ 5. **执行提交**
83
+ - 单提交场景:`git commit [-S] [--no-verify] [-s] -F .git/COMMIT_EDITMSG`
84
+ - 多提交场景(如接受拆分建议):按分组给出 `git add <paths> && git commit ...` 的明确指令;若允许执行则逐一完成。
85
+
86
+ 6. **安全回滚**
87
+ - 如误暂存,可用 `git restore --staged <paths>` 撤回暂存(命令会给出指令,不修改文件内容)。
88
+
89
+ ---
90
+
91
+ ## Best Practices for Commits
92
+
93
+ - **Atomic commits**:一次提交只做一件事,便于回溯与审阅。
94
+ - **先分组再提交**:按目录/模块/功能点拆分。
95
+ - **清晰主题**:首行 ≤ 72 字符,祈使语气。
96
+ - **正文含上下文**:说明动机、方案、影响范围(禁止冒号分隔格式)。
97
+ - **遵循 Conventional Commits**:`<type>(<scope>): <subject>`。
98
+
99
+ ---
100
+
101
+ ## Type 与 Emoji 映射(使用 --emoji 时)
102
+
103
+ - ✨ `feat`:新增功能
104
+ - 🐛 `fix`:缺陷修复(含 🔥 删除代码/文件、🚑️ 紧急修复、👽️ 适配外部 API 变更、🔒️ 安全修复、🚨 解决告警、💚 修复 CI)
105
+ - 📝 `docs`:文档与注释
106
+ - 🎨 `style`:风格/格式(不改语义)
107
+ - ♻️ `refactor`:重构(不新增功能、不修缺陷)
108
+ - ⚡️ `perf`:性能优化
109
+ - ✅ `test`:新增/修复测试、快照
110
+ - 🔧 `chore`:构建/工具/杂务(合并分支、更新配置、发布标记、依赖 pin、.gitignore 等)
111
+ - 👷 `ci`:CI/CD 配置与脚本
112
+ - ⏪️ `revert`:回滚提交
113
+ - 💥 `feat`:破坏性变更(`BREAKING CHANGE:` 段落中说明)
114
+
115
+ > 若传入 `--type`/`--scope`,将**覆盖**自动推断。
116
+ > 仅在指定 `--emoji` 标志时才会包含 emoji。
117
+
118
+ ---
119
+
120
+ ## Guidelines for Splitting Commits
121
+
122
+ 1. **不同关注点**:互不相关的功能/模块改动应拆分。
123
+ 2. **不同类型**:不要将 `feat`、`fix`、`refactor` 混在同一提交。
124
+ 3. **文件模式**:源代码 vs 文档/测试/配置分组提交。
125
+ 4. **规模阈值**:超大 diff(示例:>300 行或跨多个顶级目录)建议拆分。
126
+ 5. **可回滚性**:确保每个提交可独立回退。
127
+
128
+ ---
129
+
130
+ ## Examples
131
+
132
+ **Good (使用 --emoji)**
133
+
134
+ ```text
135
+ - ✨ feat(ui): add user authentication flow
136
+ - 🐛 fix(api): handle token refresh race condition
137
+ - 📝 docs: update API usage examples
138
+ - ♻️ refactor(core): extract retry logic into helper
139
+ - ✅ test: add unit tests for rate limiter
140
+ - 🔧 chore: update git hooks and repository settings
141
+ - ⏪️ revert: revert "feat(core): introduce streaming API"
142
+ ```
143
+
144
+ **Good (不使用 --emoji)**
145
+
146
+ ```text
147
+ - feat(ui): add user authentication flow
148
+ - fix(api): handle token refresh race condition
149
+ - docs: update API usage examples
150
+ - refactor(core): extract retry logic into helper
151
+ - test: add unit tests for rate limiter
152
+ - chore: update git hooks and repository settings
153
+ - revert: revert "feat(core): introduce streaming API"
154
+ ```
155
+
156
+ **Good (包含 Body)**
157
+
158
+ ```text
159
+ feat(auth): add OAuth2 login flow
160
+
161
+ - implement Google and GitHub third-party login
162
+ - add user authorization callback handling
163
+ - improve login state persistence logic
164
+
165
+ Closes #42
166
+ ```
167
+
168
+ ```text
169
+ fix(ui): fix button spacing on mobile devices
170
+
171
+ - adjust button padding to fit small screens
172
+ - fix styling issues on iOS Safari
173
+ - optimize touch target size
174
+ ```
175
+
176
+ **Good (包含 BREAKING CHANGE)**
177
+
178
+ ```text
179
+ feat(api)!: redesign authentication API
180
+
181
+ - migrate from session-based to JWT authentication
182
+ - update all endpoint signatures
183
+ - remove deprecated login methods
184
+
185
+ BREAKING CHANGE: authentication API has been completely redesigned, all clients must update their integration
186
+ ```
187
+
188
+ **Split Example**
189
+
190
+ ```text
191
+ - `feat(types): add new type defs for payment method`
192
+ - `docs: update API docs for new types`
193
+ - `test: add unit tests for payment types`
194
+ - `fix: address linter warnings in new files` ←(如你的仓库有钩子报错)
195
+ ```
196
+
197
+ ---
198
+
199
+ ## Important Notes
200
+
201
+ - **仅使用 Git**:不调用任何包管理器/构建命令(无 `pnpm`/`npm`/`yarn` 等)。
202
+ - **尊重钩子**:默认执行本地 Git 钩子;使用 `--no-verify` 可跳过。
203
+ - **不改源码内容**:命令只读写 `.git/COMMIT_EDITMSG` 与暂存区;不会直接编辑工作区文件。
204
+ - **安全提示**:在 rebase/merge 冲突、detached HEAD 等状态下会先提示处理/确认再继续。
205
+ - **可审可控**:如开启 `confirm: true`,每个实际 `git add`/`git commit` 步骤都会进行二次确认。