zcf 2.8.2 → 2.9.0

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.
package/README.md CHANGED
@@ -250,6 +250,7 @@ Enter your choice: _
250
250
  ? Select workflows to install (space to select, enter to confirm)
251
251
  ❯ ◉ Six Steps Workflow (workflow) - Complete 6-phase development process
252
252
  ◉ Feature Planning and UX Design (feat + planner + ui-ux-designer) - Structured feature development
253
+ ◉ Git Commands (commit + rollback + cleanBranches) - Streamlined Git operations
253
254
  ◉ BMAD-Method Extension Installer - Enterprise agile development workflow
254
255
 
255
256
  ✔ Installing workflows...
@@ -257,6 +258,9 @@ Enter your choice: _
257
258
  ✔ Installed command: zcf/feat.md
258
259
  ✔ Installed agent: zcf/plan/planner.md
259
260
  ✔ Installed agent: zcf/plan/ui-ux-designer.md
261
+ ✔ Installed command: zcf/git/git-commit.md
262
+ ✔ Installed command: zcf/git/git-rollback.md
263
+ ✔ Installed command: zcf/git/git-cleanBranches.md
260
264
  ✔ Installed command: zcf/bmad-init.md
261
265
  ✔ Workflow installation successful
262
266
 
@@ -388,6 +392,10 @@ zcf/
388
392
 
389
393
  - **Feature Development** (`/feat`): Structured new feature development
390
394
  - **Workflow** (`/workflow`): Complete six-phase development workflow
395
+ - **Git Commands**: Streamlined Git operations
396
+ - `/git-commit`: Smart commit with automatic staging and message generation
397
+ - `/git-rollback`: Safely rollback to previous commits with backup
398
+ - `/git-cleanBranches`: Clean up merged branches and maintain repository hygiene
391
399
  - **BMad Workflow** (`/bmad-init`): Initialize BMad workflow for enterprise development
392
400
  - Supports both greenfield (new projects) and brownfield (existing projects)
393
401
  - Provides comprehensive templates for PRDs, architecture docs, and user stories
@@ -8,7 +8,6 @@ import { exec } from 'tinyexec';
8
8
  import { exec as exec$1 } from 'child_process';
9
9
  import { promisify } from 'util';
10
10
  import ora from 'ora';
11
- import prompts$1 from 'prompts';
12
11
  import { readFile as readFile$1, writeFile as writeFile$1, mkdir } from 'fs/promises';
13
12
  import { join as join$1 } from 'path';
14
13
  import { homedir as homedir$1 } from 'os';
@@ -19,7 +18,7 @@ import { promisify as promisify$1 } from 'node:util';
19
18
  import { homedir, platform } from 'node:os';
20
19
  import { join as join$2 } from 'node:path';
21
20
 
22
- const version = "2.8.2";
21
+ const version = "2.9.0";
23
22
  const homepage = "https://github.com/UfoMiao/zcf";
24
23
 
25
24
  const common$1 = {
@@ -245,7 +244,8 @@ const workflow$1 = {
245
244
  workflowOption: {
246
245
  featPlanUx: "\u529F\u80FD\u89C4\u5212\u548C UX \u8BBE\u8BA1 (feat + planner + ui-ux-designer)",
247
246
  sixStepsWorkflow: "\u516D\u6B65\u5DE5\u4F5C\u6D41 (workflow)",
248
- bmadWorkflow: "BMAD-Method \u6269\u5C55\u5B89\u88C5\u5668 (\u652F\u6301\u654F\u6377\u5F00\u53D1\u5DE5\u4F5C\u6D41)"
247
+ bmadWorkflow: "BMAD-Method \u6269\u5C55\u5B89\u88C5\u5668 (\u652F\u6301\u654F\u6377\u5F00\u53D1\u5DE5\u4F5C\u6D41)",
248
+ gitWorkflow: "Git \u6307\u4EE4 (commit + rollback + cleanBranches)"
249
249
  },
250
250
  // BMAD workflow
251
251
  bmadInitPrompt: "\u2728 \u8BF7\u5728\u9879\u76EE\u4E2D\u8FD0\u884C /bmad-init \u547D\u4EE4\u6765\u521D\u59CB\u5316\u6216\u66F4\u65B0 BMAD-Method \u6269\u5C55",
@@ -706,7 +706,8 @@ const workflow = {
706
706
  workflowOption: {
707
707
  featPlanUx: "Feature Planning and UX Design (feat + planner + ui-ux-designer)",
708
708
  sixStepsWorkflow: "Six Steps Workflow (workflow)",
709
- bmadWorkflow: "BMAD-Method Extension Installer (Agile Development Workflow)"
709
+ bmadWorkflow: "BMAD-Method Extension Installer (Agile Development Workflow)",
710
+ gitWorkflow: "Git Commands (commit + rollback + cleanBranches)"
710
711
  },
711
712
  // BMAD workflow
712
713
  bmadInitPrompt: "\u2728 Please run /bmad-init command in your project to initialize or update BMAD-Method extension",
@@ -2153,11 +2154,11 @@ async function updateCcr(scriptLang, force = false) {
2153
2154
  }
2154
2155
  console.log(ansis.cyan(format(i18n.updater.currentVersion, { version: currentVersion || "" })));
2155
2156
  console.log(ansis.cyan(format(i18n.updater.latestVersion, { version: latestVersion })));
2156
- const { confirm } = await prompts$1({
2157
+ const { confirm } = await inquirer.prompt({
2157
2158
  type: "confirm",
2158
2159
  name: "confirm",
2159
2160
  message: format(i18n.updater.confirmUpdate, { tool: "CCR" }),
2160
- initial: true
2161
+ default: true
2161
2162
  });
2162
2163
  if (!confirm) {
2163
2164
  console.log(ansis.gray(i18n.updater.updateSkipped));
@@ -2203,11 +2204,11 @@ async function updateClaudeCode(scriptLang, force = false) {
2203
2204
  }
2204
2205
  console.log(ansis.cyan(format(i18n.updater.currentVersion, { version: currentVersion || "" })));
2205
2206
  console.log(ansis.cyan(format(i18n.updater.latestVersion, { version: latestVersion })));
2206
- const { confirm } = await prompts$1({
2207
+ const { confirm } = await inquirer.prompt({
2207
2208
  type: "confirm",
2208
2209
  name: "confirm",
2209
2210
  message: format(i18n.updater.confirmUpdate, { tool: "Claude Code" }),
2210
- initial: true
2211
+ default: true
2211
2212
  });
2212
2213
  if (!confirm) {
2213
2214
  console.log(ansis.gray(i18n.updater.updateSkipped));
@@ -2411,12 +2412,24 @@ const WORKFLOW_CONFIGS = [
2411
2412
  category: "plan",
2412
2413
  outputDir: "feat"
2413
2414
  },
2415
+ {
2416
+ id: "gitWorkflow",
2417
+ nameKey: "workflowOption.gitWorkflow",
2418
+ descriptionKey: "workflowDescription.gitWorkflow",
2419
+ defaultSelected: true,
2420
+ order: 3,
2421
+ commands: ["git-commit.md", "git-rollback.md", "git-cleanBranches.md"],
2422
+ agents: [],
2423
+ autoInstallAgents: false,
2424
+ category: "git",
2425
+ outputDir: "git"
2426
+ },
2414
2427
  {
2415
2428
  id: "bmadWorkflow",
2416
2429
  nameKey: "workflowOption.bmadWorkflow",
2417
2430
  descriptionKey: "workflowDescription.bmadWorkflow",
2418
2431
  defaultSelected: true,
2419
- order: 3,
2432
+ order: 4,
2420
2433
  commands: ["bmad-init.md"],
2421
2434
  agents: [],
2422
2435
  autoInstallAgents: false,
@@ -2528,7 +2541,7 @@ async function installWorkflowWithDependencies(config, configLang, scriptLang) {
2528
2541
  console.log(ansis.green(`\u2714 ${workflowName} ${i18n.workflow.workflowInstallSuccess}`));
2529
2542
  if (config.id === "bmadWorkflow") {
2530
2543
  console.log(ansis.cyan(`
2531
- ${i18n.bmad.bmadInitPrompt}`));
2544
+ ${i18n.workflow.bmadInitPrompt}`));
2532
2545
  }
2533
2546
  } else {
2534
2547
  console.log(ansis.red(`\u2717 ${workflowName} ${i18n.workflow.workflowInstallError}`));
package/dist/cli.mjs CHANGED
@@ -13,7 +13,6 @@ import 'pathe';
13
13
  import 'dayjs';
14
14
  import 'node:url';
15
15
  import 'ora';
16
- import 'prompts';
17
16
  import 'fs/promises';
18
17
  import 'path';
19
18
  import 'os';
@@ -747,7 +746,7 @@ async function update(options = {}) {
747
746
  }
748
747
  const aiOutputLang = await resolveAiOutputLanguage(scriptLang, options.aiOutputLang, zcfConfig);
749
748
  console.log(ansis.cyan(`
750
- ${i18n.workflow.updatingPrompts}
749
+ ${i18n.configuration.updatingPrompts}
751
750
  `));
752
751
  await updatePromptOnly(configLang, scriptLang, aiOutputLang);
753
752
  await selectAndInstallWorkflows(configLang, scriptLang);
package/dist/index.mjs CHANGED
@@ -9,7 +9,6 @@ import 'tinyexec';
9
9
  import 'child_process';
10
10
  import 'util';
11
11
  import 'ora';
12
- import 'prompts';
13
12
  import 'fs/promises';
14
13
  import 'path';
15
14
  import 'os';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zcf",
3
3
  "type": "module",
4
- "version": "2.8.2",
4
+ "version": "2.9.0",
5
5
  "description": "Zero-Config Claude-Code Flow - One-click configuration tool for Claude Code",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/UfoMiao/zcf",
@@ -21,7 +21,6 @@
21
21
  "templates"
22
22
  ],
23
23
  "dependencies": {
24
- "@types/prompts": "^2.4.9",
25
24
  "@types/semver": "^7.7.0",
26
25
  "ansis": "^3.17.0",
27
26
  "cac": "^6.7.14",
@@ -30,7 +29,6 @@
30
29
  "inquirer": "^12.9.0",
31
30
  "ora": "^8.2.0",
32
31
  "pathe": "^2.0.3",
33
- "prompts": "^2.4.2",
34
32
  "semver": "^7.7.2",
35
33
  "tinyexec": "^1.0.1"
36
34
  },
@@ -0,0 +1,101 @@
1
+ ---
2
+ description: Safely find and clean up merged or stale Git branches with dry-run mode and custom base/protected branches support
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
+ This command **safely** identifies and cleans up **merged** or **stale** Git branches.
14
+ Runs in **read-only preview (`--dry-run`)** mode by default, requiring explicit instructions to perform deletions.
15
+
16
+ ---
17
+
18
+ ## Usage
19
+
20
+ ```bash
21
+ # [Safest] Preview branches to be cleaned without executing any deletions
22
+ /git-cleanBranches --dry-run
23
+
24
+ # Clean local branches merged to main and inactive for over 90 days (requires individual confirmation)
25
+ /git-cleanBranches --stale 90
26
+
27
+ # Clean local and remote branches merged to release/v2.1 (auto-confirm)
28
+ /git-cleanBranches --base release/v2.1 --remote --yes
29
+
30
+ # [Dangerous] Force delete an unmerged local branch
31
+ /git-cleanBranches --force outdated-feature
32
+ ```
33
+
34
+ ### Options
35
+ - `--base <branch>`: Specify the base branch for cleanup (defaults to repository's `main`/`master`).
36
+ - `--stale <days>`: Clean branches with no commits for specified days (disabled by default).
37
+ - `--remote`: Also clean remote merged/stale branches.
38
+ - `--dry-run`: **Default behavior**. Only list branches to be deleted without executing any operations.
39
+ - `--yes`: Skip individual confirmations and delete all identified branches directly (suitable for CI/CD).
40
+ - `--force`: Use `-D` to force delete local branches (even if unmerged).
41
+
42
+ ---
43
+
44
+ ## What This Command Does
45
+
46
+ 1. **Configuration and Safety Checks**
47
+ - **Update Information**: Automatically executes `git fetch --all --prune` to ensure branch status is current.
48
+ - **Read Protected Branches**: Reads the list of branches that should not be cleaned from Git config (see "Configuration" below).
49
+ - **Determine Base**: Uses `--base` parameter or auto-detected `main`/`master` as comparison baseline.
50
+
51
+ 2. **Analysis and Identification (Find)**
52
+ - **Merged Branches**: Find local (and remote if `--remote` is added) branches fully merged to `--base`.
53
+ - **Stale Branches**: If `--stale <days>` is specified, find branches with last commit N days ago.
54
+ - **Exclude Protected Branches**: Remove all configured protected branches from cleanup list.
55
+
56
+ 3. **Report and Preview (Report)**
57
+ - Clearly list "merged branches to be deleted" and "stale branches to be deleted".
58
+ - Without `--yes` parameter, **command ends here**, waiting for user confirmation to re-execute (without `--dry-run`).
59
+
60
+ 4. **Execute Cleanup (Execute)**
61
+ - **Only executed without `--dry-run` and after user confirmation** (or with `--yes`).
62
+ - Delete identified branches one by one, unless user chooses to skip in interactive confirmation.
63
+ - Local: `git branch -d <branch>`; Remote: `git push origin --delete <branch>`.
64
+ - If `--force` is specified, local deletion uses `git branch -D <branch>`.
65
+
66
+ ---
67
+
68
+ ## Configuration (Configure Once, Use Forever)
69
+
70
+ To prevent accidental deletion of important branches (e.g., `develop`, `release/*`), add protection rules to the repository's Git config. The command reads them automatically.
71
+
72
+ ```bash
73
+ # Protect develop branch
74
+ git config --add branch.cleanup.protected develop
75
+
76
+ # Protect all branches starting with release/ (wildcard)
77
+ git config --add branch.cleanup.protected 'release/*'
78
+
79
+ # View all configured protected branches
80
+ git config --get-all branch.cleanup.protected
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Best Practices for Embedded Devs
86
+
87
+ - **Prioritize `--dry-run`**: Develop the habit of previewing before executing.
88
+ - **Leverage `--base`**: When maintaining long-term `release` branches, use it to clean `feature` or `hotfix` branches merged to that release.
89
+ - **Careful with `--force`**: Don't force delete unless you're 100% certain an unmerged branch is useless.
90
+ - **Team Collaboration**: Notify the team channel before cleaning shared remote branches.
91
+ - **Regular Runs**: Run monthly or quarterly to keep the repository clean.
92
+
93
+ ---
94
+
95
+ ## Why This Version Is Better
96
+
97
+ - ✅ **Safer**: Default read-only preview with configurable protected branch list.
98
+ - ✅ **More Flexible**: Supports custom base branches, perfectly fits `release` / `develop` workflows.
99
+ - ✅ **More Compatible**: Avoids commands with inconsistent behavior across systems like `date -d`.
100
+ - ✅ **More Intuitive**: Condenses complex 16-step checklist into a single command with safety options.
101
+ - ✅ **Consistent Style**: Shares similar parameter design and documentation structure with `/commit` command.
@@ -0,0 +1,152 @@
1
+ ---
2
+ description: Analyze changes with Git only and auto-generate conventional commit messages with optional emoji; suggests splitting commits when needed, runs local Git hooks by default (use --no-verify to skip)
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 # Analyze current changes, generate commit message
7
+ # - /git-commit --all # Stage all changes and commit
8
+ # - /git-commit --no-verify # Skip Git hooks
9
+ # - /git-commit --emoji # Include emoji in commit message
10
+ # - /git-commit --scope ui --type feat # Specify scope and type
11
+ # - /git-commit --amend --signoff # Amend last commit with signature
12
+ ---
13
+
14
+ # Claude Command: Commit (Git-only)
15
+
16
+ This command works **without any package manager/build tools**, using only **Git** to:
17
+ - Read changes (staged/unstaged)
18
+ - Determine if changes should be **split into multiple commits**
19
+ - Generate **Conventional Commits** style messages with optional emoji for each commit
20
+ - Execute `git add` and `git commit` as needed (runs local Git hooks by default; use `--no-verify` to skip)
21
+
22
+ ---
23
+
24
+ ## Usage
25
+
26
+ ```bash
27
+ /git-commit
28
+ /git-commit --no-verify
29
+ /git-commit --emoji
30
+ /git-commit --all --signoff
31
+ /git-commit --amend
32
+ /git-commit --scope ui --type feat --emoji
33
+ ```
34
+
35
+ ### Options
36
+ - `--no-verify`: Skip local Git hooks (`pre-commit`/`commit-msg` etc.).
37
+ - `--all`: When staging area is empty, automatically `git add -A` to include all changes in the commit.
38
+ - `--amend`: **Amend** the last commit without creating a new one (preserves author and timestamp unless local Git config specifies otherwise).
39
+ - `--signoff`: Add `Signed-off-by` line (use when following DCO process).
40
+ - `--emoji`: Include emoji prefix in commit message (omit for plain text).
41
+ - `--scope <scope>`: Specify commit scope (e.g., `ui`, `docs`, `api`), written to message header.
42
+ - `--type <type>`: Force commit type (e.g., `feat`, `fix`, `docs`), overrides automatic detection.
43
+
44
+ > Note: If the framework doesn't support interactive confirmation, enable `confirm: true` in front-matter to avoid mistakes.
45
+
46
+ ---
47
+
48
+ ## What This Command Does
49
+
50
+ 1. **Repository/Branch Validation**
51
+ - Check if in a Git repository using `git rev-parse --is-inside-work-tree`.
52
+ - Read current branch/HEAD status; if in rebase/merge conflict state, prompt to resolve conflicts first.
53
+
54
+ 2. **Change Detection**
55
+ - Get staged and unstaged changes using `git status --porcelain` and `git diff`.
56
+ - If staged files = 0:
57
+ - If `--all` is passed → Execute `git add -A`.
58
+ - Otherwise prompt choice: continue analyzing unstaged changes for **suggestions**, or cancel to manually group staging.
59
+
60
+ 3. **Split Suggestions (Split Heuristics)**
61
+ - Cluster by **concerns**, **file modes**, **change types** (e.g., source code vs docs/tests; different directories/packages; additions vs deletions).
62
+ - If **multiple independent changesets** or large diff detected (e.g., > 300 lines / across multiple top-level directories), suggest splitting commits with pathspecs for each group (for subsequent `git add <paths>`).
63
+
64
+ 4. **Commit Message Generation (Conventional with Optional Emoji)**
65
+ - Auto-infer `type` (`feat`/`fix`/`docs`/`refactor`/`test`/`chore`/`perf`/`style`/`ci`/`revert`...) and optional `scope`.
66
+ - Generate message header: `[<emoji>] <type>(<scope>)?: <subject>` (first line ≤ 72 chars, imperative mood, emoji included only with `--emoji` flag).
67
+ - Generate message body: bullet points (motivation, implementation details, impact scope, BREAKING CHANGE if any).
68
+ - Write draft to `.git/COMMIT_EDITMSG` for use with `git commit`.
69
+
70
+ 5. **Execute Commit**
71
+ - Single commit scenario: `git commit [-S] [--no-verify] [-s] -F .git/COMMIT_EDITMSG`
72
+ - Multiple commit scenario (if split accepted): Provide clear instructions for `git add <paths> && git commit ...` per group; execute sequentially if allowed.
73
+
74
+ 6. **Safe Rollback**
75
+ - If mistakenly staged, use `git restore --staged <paths>` to unstage (command provides instructions, doesn't modify file contents).
76
+
77
+ ---
78
+
79
+ ## Best Practices for Commits
80
+
81
+ - **Atomic commits**: One commit does one thing, easier to trace and review.
82
+ - **Group before committing**: Split by directory/module/feature.
83
+ - **Clear subject**: First line ≤ 72 chars, imperative mood (e.g., "add... / fix...").
84
+ - **Body with context**: Explain motivation, solution, impact scope, risks, and next steps.
85
+ - **Follow Conventional Commits**: `<type>(<scope>): <subject>`.
86
+
87
+ ---
88
+
89
+ ## Type to Emoji Mapping (When --emoji is Used)
90
+
91
+ - ✨ `feat`: New feature
92
+ - 🐛 `fix`: Bug fix (includes 🔥 remove code/files, 🚑️ hotfix, 👽️ adapt to external API changes, 🔒️ security fix, 🚨 fix warnings, 💚 fix CI)
93
+ - 📝 `docs`: Documentation and comments
94
+ - 🎨 `style`: Code style/formatting (no semantic changes)
95
+ - ♻️ `refactor`: Refactoring (no new features, no bug fixes)
96
+ - ⚡️ `perf`: Performance improvements
97
+ - ✅ `test`: Add/fix tests, snapshots
98
+ - 🔧 `chore`: Build/tools/misc tasks (merge branches, update configs, release tags, pin dependencies, .gitignore, etc.)
99
+ - 👷 `ci`: CI/CD configuration and scripts
100
+ - ⏪️ `revert`: Revert commits
101
+ - 💥 `feat`: Breaking changes (explained in `BREAKING CHANGE:` section)
102
+
103
+ > If `--type`/`--scope` is passed, it will **override** auto-detection.
104
+ > Emoji is only included when `--emoji` flag is specified.
105
+
106
+ ---
107
+
108
+ ## Guidelines for Splitting Commits
109
+
110
+ 1. **Different concerns**: Unrelated feature/module changes should be split.
111
+ 2. **Different types**: Don't mix `feat`, `fix`, `refactor` in the same commit.
112
+ 3. **File modes**: Source code vs docs/tests/configs should be grouped separately.
113
+ 4. **Size threshold**: Large diffs (e.g., >300 lines or across multiple top-level directories) should be split.
114
+ 5. **Revertability**: Ensure each commit can be independently reverted.
115
+
116
+ ---
117
+
118
+ ## Examples
119
+
120
+ **Good (with --emoji)**
121
+ - ✨ feat(ui): add user authentication flow
122
+ - 🐛 fix(api): handle token refresh race condition
123
+ - 📝 docs: update API usage examples
124
+ - ♻️ refactor(core): extract retry logic into helper
125
+ - ✅ test: add unit tests for rate limiter
126
+ - 🔧 chore: update git hooks and repository settings
127
+ - ⏪️ revert: revert "feat(core): introduce streaming API"
128
+
129
+ **Good (without --emoji)**
130
+ - feat(ui): add user authentication flow
131
+ - fix(api): handle token refresh race condition
132
+ - docs: update API usage examples
133
+ - refactor(core): extract retry logic into helper
134
+ - test: add unit tests for rate limiter
135
+ - chore: update git hooks and repository settings
136
+ - revert: revert "feat(core): introduce streaming API"
137
+
138
+ **Split Example**
139
+ - `feat(types): add new type defs for payment method`
140
+ - `docs: update API docs for new types`
141
+ - `test: add unit tests for payment types`
142
+ - `fix: address linter warnings in new files` ← (if your repo has hook errors)
143
+
144
+ ---
145
+
146
+ ## Important Notes
147
+
148
+ - **Git only**: No package manager/build commands (`pnpm`/`npm`/`yarn` etc.).
149
+ - **Respects hooks**: Executes local Git hooks by default; use `--no-verify` to skip.
150
+ - **No source code changes**: Command only reads/writes `.git/COMMIT_EDITMSG` and staging area; doesn't directly edit working directory files.
151
+ - **Safety prompts**: In rebase/merge conflicts, detached HEAD states, prompts to handle/confirm before continuing.
152
+ - **Auditable and controllable**: If `confirm: true` is enabled, each actual `git add`/`git commit` step requires confirmation.
@@ -0,0 +1,89 @@
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
+ # Claude Command: Git Rollback
11
+
12
+ **Purpose**: Safely and visually rollback a specified branch to an older version.
13
+ Defaults to **read-only preview (`--dry-run`)**; actual execution requires `--yes` or interactive confirmation.
14
+
15
+ ---
16
+
17
+ ## Usage
18
+
19
+ ```bash
20
+ # Pure interactive: list branches → select branch → list recent 20 versions → select target → choose reset or revert → confirm
21
+ /git-rollback
22
+
23
+ # Specify branch, other interactive
24
+ /git-rollback --branch feature/calculator
25
+
26
+ # Specify branch and target commit, execute with hard-reset in one go (dangerous)
27
+ /git-rollback --branch main --target 1a2b3c4d --mode reset --yes
28
+
29
+ # Generate revert commit only (non-destructive rollback), preview
30
+ /git-rollback --branch release/v2.1 --target v2.0.5 --mode revert --dry-run
31
+ ```
32
+
33
+ ### Options
34
+
35
+ | Option | Description |
36
+ |------|------|
37
+ | `--branch <branch>` | Branch to rollback; interactively selected if omitted. |
38
+ | `--target <rev>` | Target version (commit hash, tag, or reflog reference); interactively selects recent `--depth` entries if omitted. |
39
+ | `--mode reset\|revert` | `reset`: Hard rollback history; `revert`: Generate reverse commits keeping history intact. Prompts by default. |
40
+ | `--depth <n>` | List recent n versions in interactive mode (default 20). |
41
+ | `--dry-run` | **Enabled by default**, only preview commands to be executed. |
42
+ | `--yes` | Skip all confirmations and execute directly, suitable for CI/CD scripts. |
43
+
44
+ ---
45
+
46
+ ## Interactive Flow
47
+
48
+ 1. **Sync remote** → `git fetch --all --prune`
49
+ 2. **List branches** → `git branch -a` (local + remote, filter protected branches)
50
+ 3. **Select branch** → User input or parameter
51
+ 4. **List versions** → `git log --oneline -n <depth>` + `git tag --merged` + `git reflog -n <depth>`
52
+ 5. **Select target** → User inputs commit hash / tag
53
+ 6. **Select mode** → `reset` or `revert`
54
+ 7. **Final confirmation** (unless `--yes`)
55
+ 8. **Execute rollback**
56
+ * `reset`: `git switch <branch> && git reset --hard <target>`
57
+ * `revert`: `git switch <branch> && git revert --no-edit <target>..HEAD`
58
+ 9. **Push suggestion** → Prompt whether to `git push --force-with-lease` (reset) or regular `git push` (revert)
59
+
60
+ ---
61
+
62
+ ## Safety Guards
63
+
64
+ * **Backup**: Automatically records current HEAD in reflog before execution, recoverable with `git switch -c backup/<timestamp>`.
65
+ * **Protected branches**: If protected branches like `main` / `master` / `production` are detected with `reset` mode enabled, requires additional confirmation.
66
+ * **--dry-run enabled by default**: Prevents accidental operations.
67
+ * **--force prohibited**: No `--force` provided; if force push needed, manually enter `git push --force-with-lease`.
68
+
69
+ ---
70
+
71
+ ## Use Case Examples
72
+
73
+ | Scenario | Command Example |
74
+ |------|---------|
75
+ | Hotfix patch deployed with bug, need to rollback to tag `v1.2.0` | `/git-rollback --branch release/v1 --target v1.2.0 --mode reset` |
76
+ | Ops colleague pushed debug logs by mistake, need to generate reverse commit | `/git-rollback --branch main --target 3f2e7c9 --mode revert` |
77
+ | Research historical bugs, guide newcomers through branch history | `/git-rollback` (full interactive, dry-run) |
78
+
79
+ ---
80
+
81
+ ## Notes
82
+
83
+ 1. **reset vs revert**
84
+ * **reset** changes history, requires force push and may affect other collaborators, use with caution.
85
+ * **revert** is safer, generates new commits preserving history, but adds one more record.
86
+ 2. **Embedded repositories** often have large binary files; ensure LFS/submodule state consistency before rollback.
87
+ 3. If repository has CI forced validation, rollback may trigger pipelines automatically; confirm control policies to avoid accidental deployment of old versions.
88
+
89
+ ---
@@ -0,0 +1,101 @@
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
+ - `--base <branch>`:指定清理的基准分支(默认为仓库的 `main`/`master`)。
36
+ - `--stale <days>`:清理超过指定天数未提交的分支(默认不启用)。
37
+ - `--remote`:同时清理远程已合并/过期的分支。
38
+ - `--dry-run`:**默认行为**。仅列出将要删除的分支,不执行任何操作。
39
+ - `--yes`:跳过逐一确认的步骤,直接删除所有已识别的分支(适合 CI/CD)。
40
+ - `--force`:使用 `-D` 强制删除本地分支(即使未合并)。
41
+
42
+ ---
43
+
44
+ ## What This Command Does
45
+
46
+ 1. **配置与安全预检**
47
+ - **更新信息**:自动执行 `git fetch --all --prune`,确保分支状态最新。
48
+ - **读取保护分支**:从 Git 配置读取不应被清理的分支列表(见下文“Configuration”)。
49
+ - **确定基准**:使用 `--base` 参数或自动识别的 `main`/`master` 作为比较基准。
50
+
51
+ 2. **分析识别(Find)**
52
+ - **已合并分支**:找出已完全合并到 `--base` 的本地(及远程,如加 `--remote`)分支。
53
+ - **过期分支**:如指定 `--stale <days>`,找出最后一次提交在 N 天前的分支。
54
+ - **排除保护分支**:从待清理列表中移除所有已配置的保护分支。
55
+
56
+ 3. **报告预览(Report)**
57
+ - 清晰列出“将要删除的已合并分支”与“将要删除的过期分支”。
58
+ - 若无 `--yes` 参数,**命令到此结束**,等待用户确认后再次执行(不带 `--dry-run`)。
59
+
60
+ 4. **执行清理(Execute)**
61
+ - **仅在不带 `--dry-run` 且用户确认后**(或带 `--yes`)执行。
62
+ - 逐一删除已识别的分支,除非用户在交互式确认中选择跳过。
63
+ - 本地用 `git branch -d <branch>`;远程用 `git push origin --delete <branch>`。
64
+ - 若指定 `--force`,本地删除会改用 `git branch -D <branch>`。
65
+
66
+ ---
67
+
68
+ ## Configuration (一次配置,永久生效)
69
+
70
+ 为防止误删重要分支(如 `develop`, `release/*`),请在仓库的 Git 配置中添加保护规则。命令会自动读取。
71
+
72
+ ```bash
73
+ # 保护 develop 分支
74
+ git config --add branch.cleanup.protected develop
75
+
76
+ # 保护所有 release/ 开头的分支 (通配符)
77
+ git config --add branch.cleanup.protected 'release/*'
78
+
79
+ # 查看所有已配置的保护分支
80
+ git config --get-all branch.cleanup.protected
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Best Practices for Embedded Devs
86
+
87
+ - **优先 `--dry-run`**:养成先预览再执行的习惯。
88
+ - **活用 `--base`**:维护长期 `release` 分支时,用它来清理已合并到该 release 的 `feature` 或 `hotfix` 分支。
89
+ - **谨慎 `--force`**:除非你百分百确定某个未合并分支是无用功,否则不要强制删除。
90
+ - **团队协作**:在清理共享的远程分支前,先在团队频道通知一声。
91
+ - **定期运行**:每月或每季度运行一次,保持仓库清爽。
92
+
93
+ ---
94
+
95
+ ## Why This Version Is Better
96
+
97
+ - ✅ **更安全**:默认只读预览,且有可配置的保护分支列表。
98
+ - ✅ **更灵活**:支持自定义基准分支,完美适配 `release` / `develop` 工作流。
99
+ - ✅ **更兼容**:避免了在不同系统上行为不一的 `date -d` 等命令。
100
+ - ✅ **更直观**:将复杂的 16 步清单,浓缩成一个带安全选项的、可直接执行的命令。
101
+ - ✅ **风格一致**:与 `/commit` 命令共享相似的参数设计与文档结构。
@@ -0,0 +1,152 @@
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
+ - 读取改动(staged/unstaged)
18
+ - 判断是否需要**拆分为多次提交**
19
+ - 为每个提交生成 **Conventional Commits** 风格的信息(可选 emoji)
20
+ - 按需执行 `git add` 与 `git commit`(默认运行本地 Git 钩子;可 `--no-verify` 跳过)
21
+
22
+ ---
23
+
24
+ ## Usage
25
+
26
+ ```bash
27
+ /git-commit
28
+ /git-commit --no-verify
29
+ /git-commit --emoji
30
+ /git-commit --all --signoff
31
+ /git-commit --amend
32
+ /git-commit --scope ui --type feat --emoji
33
+ ```
34
+
35
+ ### Options
36
+ - `--no-verify`:跳过本地 Git 钩子(`pre-commit`/`commit-msg` 等)。
37
+ - `--all`:当暂存区为空时,自动 `git add -A` 将所有改动纳入本次提交。
38
+ - `--amend`:在不创建新提交的情况下**修补**上一次提交(保持提交作者与时间,除非本地 Git 配置另有指定)。
39
+ - `--signoff`:附加 `Signed-off-by` 行(遵循 DCO 流程时使用)。
40
+ - `--emoji`:在提交信息中包含 emoji 前缀(省略则使用纯文本)。
41
+ - `--scope <scope>`:指定提交作用域(如 `ui`、`docs`、`api`),写入消息头部。
42
+ - `--type <type>`:强制提交类型(如 `feat`、`fix`、`docs` 等),覆盖自动判断。
43
+
44
+ > 注:如框架不支持交互式确认,可在 front‑matter 中开启 `confirm: true` 以避免误操作。
45
+
46
+ ---
47
+
48
+ ## What This Command Does
49
+
50
+ 1. **仓库/分支校验**
51
+ - 通过 `git rev-parse --is-inside-work-tree` 判断是否位于 Git 仓库。
52
+ - 读取当前分支/HEAD 状态;如处于 rebase/merge 冲突状态,先提示处理冲突后再继续。
53
+
54
+ 2. **改动检测**
55
+ - 用 `git status --porcelain` 与 `git diff` 获取已暂存与未暂存的改动。
56
+ - 若已暂存文件为 0:
57
+ - 若传入 `--all` → 执行 `git add -A`。
58
+ - 否则提示你选择:继续仅分析未暂存改动并给出**建议**,或取消命令后手动分组暂存。
59
+
60
+ 3. **拆分建议(Split Heuristics)**
61
+ - 按**关注点**、**文件模式**、**改动类型**聚类(示例:源代码 vs 文档、测试;不同目录/包;新增 vs 删除)。
62
+ - 若检测到**多组独立变更**或 diff 规模过大(如 > 300 行 / 跨多个顶级目录),建议拆分提交,并给出每一组的 pathspec(便于后续执行 `git add <paths>`)。
63
+
64
+ 4. **提交信息生成(Conventional 规范,可选 Emoji)**
65
+ - 自动推断 `type`(`feat`/`fix`/`docs`/`refactor`/`test`/`chore`/`perf`/`style`/`ci`/`revert` …)与可选 `scope`。
66
+ - 生成消息头:`[<emoji>] <type>(<scope>)?: <subject>`(首行 ≤ 72 字符,祈使语气,仅在使用 `--emoji` 时包含 emoji)。
67
+ - 生成消息体:要点列表(动机、实现要点、影响范围、BREAKING CHANGE 如有)。
68
+ - 将草稿写入 `.git/COMMIT_EDITMSG`,并用于 `git commit`。
69
+
70
+ 5. **执行提交**
71
+ - 单提交场景:`git commit [-S] [--no-verify] [-s] -F .git/COMMIT_EDITMSG`
72
+ - 多提交场景(如接受拆分建议):按分组给出 `git add <paths> && git commit ...` 的明确指令;若允许执行则逐一完成。
73
+
74
+ 6. **安全回滚**
75
+ - 如误暂存,可用 `git restore --staged <paths>` 撤回暂存(命令会给出指令,不修改文件内容)。
76
+
77
+ ---
78
+
79
+ ## Best Practices for Commits
80
+
81
+ - **Atomic commits**:一次提交只做一件事,便于回溯与审阅。
82
+ - **先分组再提交**:按目录/模块/功能点拆分。
83
+ - **清晰主题**:首行 ≤ 72 字符,祈使语气(如 “add… / fix…”)。
84
+ - **正文含上下文**:说明动机、方案、影响范围、风险与后续工作。
85
+ - **遵循 Conventional Commits**:`<type>(<scope>): <subject>`。
86
+
87
+ ---
88
+
89
+ ## Type 与 Emoji 映射(使用 --emoji 时)
90
+
91
+ - ✨ `feat`:新增功能
92
+ - 🐛 `fix`:缺陷修复(含 🔥 删除代码/文件、🚑️ 紧急修复、👽️ 适配外部 API 变更、🔒️ 安全修复、🚨 解决告警、💚 修复 CI)
93
+ - 📝 `docs`:文档与注释
94
+ - 🎨 `style`:风格/格式(不改语义)
95
+ - ♻️ `refactor`:重构(不新增功能、不修缺陷)
96
+ - ⚡️ `perf`:性能优化
97
+ - ✅ `test`:新增/修复测试、快照
98
+ - 🔧 `chore`:构建/工具/杂务(合并分支、更新配置、发布标记、依赖 pin、.gitignore 等)
99
+ - 👷 `ci`:CI/CD 配置与脚本
100
+ - ⏪️ `revert`:回滚提交
101
+ - 💥 `feat`:破坏性变更(`BREAKING CHANGE:` 段落中说明)
102
+
103
+ > 若传入 `--type`/`--scope`,将**覆盖**自动推断。
104
+ > 仅在指定 `--emoji` 标志时才会包含 emoji。
105
+
106
+ ---
107
+
108
+ ## Guidelines for Splitting Commits
109
+
110
+ 1. **不同关注点**:互不相关的功能/模块改动应拆分。
111
+ 2. **不同类型**:不要将 `feat`、`fix`、`refactor` 混在同一提交。
112
+ 3. **文件模式**:源代码 vs 文档/测试/配置分组提交。
113
+ 4. **规模阈值**:超大 diff(示例:>300 行或跨多个顶级目录)建议拆分。
114
+ 5. **可回滚性**:确保每个提交可独立回退。
115
+
116
+ ---
117
+
118
+ ## Examples
119
+
120
+ **Good (使用 --emoji)**
121
+ - ✨ feat(ui): add user authentication flow
122
+ - 🐛 fix(api): handle token refresh race condition
123
+ - 📝 docs: update API usage examples
124
+ - ♻️ refactor(core): extract retry logic into helper
125
+ - ✅ test: add unit tests for rate limiter
126
+ - 🔧 chore: update git hooks and repository settings
127
+ - ⏪️ revert: revert "feat(core): introduce streaming API"
128
+
129
+ **Good (不使用 --emoji)**
130
+ - feat(ui): add user authentication flow
131
+ - fix(api): handle token refresh race condition
132
+ - docs: update API usage examples
133
+ - refactor(core): extract retry logic into helper
134
+ - test: add unit tests for rate limiter
135
+ - chore: update git hooks and repository settings
136
+ - revert: revert "feat(core): introduce streaming API"
137
+
138
+ **Split Example**
139
+ - `feat(types): add new type defs for payment method`
140
+ - `docs: update API docs for new types`
141
+ - `test: add unit tests for payment types`
142
+ - `fix: address linter warnings in new files` ←(如你的仓库有钩子报错)
143
+
144
+ ---
145
+
146
+ ## Important Notes
147
+
148
+ - **仅使用 Git**:不调用任何包管理器/构建命令(无 `pnpm`/`npm`/`yarn` 等)。
149
+ - **尊重钩子**:默认执行本地 Git 钩子;使用 `--no-verify` 可跳过。
150
+ - **不改源码内容**:命令只读写 `.git/COMMIT_EDITMSG` 与暂存区;不会直接编辑工作区文件。
151
+ - **安全提示**:在 rebase/merge 冲突、detached HEAD 等状态下会先提示处理/确认再继续。
152
+ - **可审可控**:如开启 `confirm: true`,每个实际 `git add`/`git commit` 步骤都会进行二次确认。
@@ -0,0 +1,90 @@
1
+ ---
2
+ description: 交互式回滚 Git 分支到历史版本;列分支、列版本、二次确认后执行 reset / revert
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 # 全交互模式,dry‑run
7
+ # - /git-rollback --branch dev # 直接选 dev,其他交互
8
+ # - /git-rollback --branch dev --target v1.2.0 --mode reset --yes
9
+ ---
10
+
11
+ # Claude Command: Git Rollback
12
+
13
+ **目的**:安全、可视地将指定分支回滚到旧版本。
14
+ 默认处于 **只读预览 (`--dry-run`)**;真正执行需加 `--yes` 或在交互中确认。
15
+
16
+ ---
17
+
18
+ ## Usage
19
+
20
+ ```bash
21
+ # 纯交互:列出分支 → 选分支 → 列最近 20 个版本 → 选目标 → 选择 reset 或 revert → 二次确认
22
+ /git-rollback
23
+
24
+ # 指定分支,其他交互
25
+ /git-rollback --branch feature/calculator
26
+
27
+ # 指定分支与目标 commit,并用 hard‑reset 一键执行(危险)
28
+ /git-rollback --branch main --target 1a2b3c4d --mode reset --yes
29
+
30
+ # 只想生成 revert 提交(非破坏式回滚),预览即可
31
+ /git-rollback --branch release/v2.1 --target v2.0.5 --mode revert --dry-run
32
+ ```
33
+
34
+ ### Options
35
+
36
+ | 选项 | 说明 |
37
+ | ---------------------- | ---------------------------------------------------------------------------------- |
38
+ | `--branch <branch>` | 要回滚的分支;缺省时交互选择。 |
39
+ | `--target <rev>` | 目标版本(commit Hash、Tag、reflog 引用都行);缺省时交互选择近 `--depth` 条记录。 |
40
+ | `--mode reset\|revert` | `reset`:硬回滚历史;`revert`:生成反向提交保持历史完整。默认询问。 |
41
+ | `--depth <n>` | 在交互模式下列出最近 n 个版本(默认 20)。 |
42
+ | `--dry-run` | **默认开启**,只预览即将执行的命令。 |
43
+ | `--yes` | 跳过所有确认直接执行,适合 CI/CD 脚本。 |
44
+
45
+ ---
46
+
47
+ ## 交互流程
48
+
49
+ 1. **同步远端** → `git fetch --all --prune`
50
+ 2. **列分支** → `git branch -a`(本地+远端,过滤受保护分支)
51
+ 3. **选分支** → 用户输入或传参
52
+ 4. **列版本** → `git log --oneline -n <depth>` + `git tag --merged` + `git reflog -n <depth>`
53
+ 5. **选目标** → 用户输入 commit hash / tag
54
+ 6. **选模式** → `reset` 或 `revert`
55
+ 7. **最终确认** (除非 `--yes`)
56
+ 8. **执行回滚**
57
+ - `reset`:`git switch <branch> && git reset --hard <target>`
58
+ - `revert`:`git switch <branch> && git revert --no-edit <target>..HEAD`
59
+ 9. **推送建议** → 提示是否 `git push --force-with-lease`(reset)或普通 `git push`(revert)
60
+
61
+ ---
62
+
63
+ ## 安全护栏
64
+
65
+ - **备份**:执行前自动在 reflog 中记录当前 HEAD,可用 `git switch -c backup/<timestamp>` 恢复。
66
+ - **保护分支**:如检测到 `main` / `master` / `production` 等受保护分支且开启 `reset` 模式,将要求额外确认。
67
+ - **--dry-run 默认开启**:防止误操作。
68
+ - **--force 禁止**:不提供 `--force`;如需强推,请手动输入 `git push --force-with-lease`。
69
+
70
+ ---
71
+
72
+ ## 适用场景示例
73
+
74
+ | 场景 | 调用示例 |
75
+ | ----------------------------------------------- | ---------------------------------------------------------------- |
76
+ | 热修补丁上线后发现 bug,需要回到 Tag `v1.2.0` | `/git-rollback --branch release/v1 --target v1.2.0 --mode reset` |
77
+ | 运维同事误推了 debug 日志提交,需要生成反向提交 | `/git-rollback --branch main --target 3f2e7c9 --mode revert` |
78
+ | 调研历史 bug,引导新人浏览分支历史 | `/git-rollback` (全交互,dry‑run) |
79
+
80
+ ---
81
+
82
+ ## 注意
83
+
84
+ 1. **reset vs revert**
85
+ - **reset** 会改变历史,需要强推并可能影响其他协作者,谨慎使用。
86
+ - **revert** 更安全,生成新提交保留历史,但会增加一次记录。
87
+ 2. **嵌入式仓库** 常有大体积二进制文件;回滚前请确保 LFS/子模块状态一致。
88
+ 3. 若仓库启用了 CI 强制校验,回滚后可能自动触发流水线;确认管控策略以免误部署旧版本。
89
+
90
+ ---