aico-cli 0.0.9 → 0.1.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/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import cac from 'cac';
3
3
  import ansis from 'ansis';
4
- import { J as readZcfConfig, K as updateZcfConfig, N as getTranslation, k as AI_OUTPUT_LANGUAGES, O as inquirer, P as addNumbersToChoices, Q as version, q as backupExistingConfig, r as copyConfigFiles, x as applyAiLanguageDirective, R as configureAiPersonality, C as CLAUDE_DIR, T as readJsonConfig, H as addCompletedOnboarding, S as SETTINGS_FILE, U as writeJsonConfig, o as openSettingsJson, b as importRecommendedPermissions, a as importRecommendedEnv, V as isWindows, z as readMcpConfig, G as fixWindowsMcpConfig, B as writeMcpConfig, W as selectMcpServices, D as backupMcpConfig, M as MCP_SERVICES, F as buildMcpServerConfig, X as EscapeKeyPressed, E as mergeMcpServers, Y as displayBanner, I as I18N, Z as selectAndInstallWorkflows, _ as handleExitPromptError, $ as handleGeneralError, a0 as displayBannerWithInfo, a1 as readZcfConfigAsync, i as init, a2 as executeWithEscapeSupport } from './shared/aico-cli.Ngtnxi15.mjs';
4
+ import { J as readZcfConfig, K as updateZcfConfig, N as getTranslation, k as AI_OUTPUT_LANGUAGES, O as inquirer, P as addNumbersToChoices, Q as version, q as backupExistingConfig, r as copyConfigFiles, x as applyAiLanguageDirective, R as configureAiPersonality, C as CLAUDE_DIR, T as readJsonConfig, H as addCompletedOnboarding, S as SETTINGS_FILE, U as writeJsonConfig, o as openSettingsJson, b as importRecommendedPermissions, a as importRecommendedEnv, V as isWindows, z as readMcpConfig, G as fixWindowsMcpConfig, B as writeMcpConfig, W as selectMcpServices, D as backupMcpConfig, M as MCP_SERVICES, F as buildMcpServerConfig, X as EscapeKeyPressed, E as mergeMcpServers, Y as displayBanner, I as I18N, Z as selectAndInstallWorkflows, _ as handleExitPromptError, $ as handleGeneralError, a0 as displayBannerWithInfo, a1 as readZcfConfigAsync, i as init, a2 as executeWithEscapeSupport } from './shared/aico-cli.EaSFUITm.mjs';
5
5
  import inquirer$1 from 'inquirer';
6
6
  import { existsSync, copyFileSync, mkdirSync } from 'node:fs';
7
7
  import { exec, spawn } from 'node:child_process';
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AICO_CONFIG_FILE, k as AI_OUTPUT_LANGUAGES, C as CLAUDE_DIR, e as CLAUDE_MD_FILE, f as ClAUDE_CONFIG_FILE, I as I18N, j as LANG_LABELS, L as LEGACY_AICO_CONFIG_FILE, M as MCP_SERVICES, S as SETTINGS_FILE, h as SUPPORTED_LANGS, H as addCompletedOnboarding, x as applyAiLanguageDirective, q as backupExistingConfig, D as backupMcpConfig, F as buildMcpServerConfig, d as cleanupPermissions, c as commandExists, s as configureApi, r as copyConfigFiles, p as ensureClaudeDir, G as fixWindowsMcpConfig, w as getExistingApiConfig, y as getMcpConfigPath, g as getPlatform, a as importRecommendedEnv, b as importRecommendedPermissions, i as init, n as installClaudeCode, l as isClaudeCodeInstalled, m as mergeAndCleanPermissions, t as mergeConfigs, E as mergeMcpServers, v as mergeSettingsFile, o as openSettingsJson, z as readMcpConfig, u as updateDefaultModel, B as writeMcpConfig } from './shared/aico-cli.Ngtnxi15.mjs';
1
+ export { A as AICO_CONFIG_FILE, k as AI_OUTPUT_LANGUAGES, C as CLAUDE_DIR, e as CLAUDE_MD_FILE, f as ClAUDE_CONFIG_FILE, I as I18N, j as LANG_LABELS, L as LEGACY_AICO_CONFIG_FILE, M as MCP_SERVICES, S as SETTINGS_FILE, h as SUPPORTED_LANGS, H as addCompletedOnboarding, x as applyAiLanguageDirective, q as backupExistingConfig, D as backupMcpConfig, F as buildMcpServerConfig, d as cleanupPermissions, c as commandExists, s as configureApi, r as copyConfigFiles, p as ensureClaudeDir, G as fixWindowsMcpConfig, w as getExistingApiConfig, y as getMcpConfigPath, g as getPlatform, a as importRecommendedEnv, b as importRecommendedPermissions, i as init, n as installClaudeCode, l as isClaudeCodeInstalled, m as mergeAndCleanPermissions, t as mergeConfigs, E as mergeMcpServers, v as mergeSettingsFile, o as openSettingsJson, z as readMcpConfig, u as updateDefaultModel, B as writeMcpConfig } from './shared/aico-cli.EaSFUITm.mjs';
2
2
  import 'inquirer';
3
3
  import 'ansis';
4
4
  import 'node:fs';
@@ -80,7 +80,7 @@ const inquirer = {
80
80
  createPromptModule: inquirer$1.createPromptModule
81
81
  };
82
82
 
83
- const version = "0.0.9";
83
+ const version = "0.1.0";
84
84
 
85
85
  const common$1 = {
86
86
  // Basic
@@ -305,7 +305,7 @@ const workflow$1 = {
305
305
  featPlanUx: "\u529F\u80FD\u89C4\u5212\u548C UX \u8BBE\u8BA1 (feat + planner + ui-ux-designer)",
306
306
  sixStepsWorkflow: "\u516D\u6B65\u5DE5\u4F5C\u6D41 (workflow)",
307
307
  bmadWorkflow: "BMAD-Method \u6269\u5C55\u5B89\u88C5\u5668 (\u652F\u6301\u654F\u6377\u5F00\u53D1\u5DE5\u4F5C\u6D41)",
308
- gitWorkflow: "\u667A\u80FD Git \u64CD\u4F5C (Git \u63D0\u4EA4\u3001\u56DE\u6EDA\u3001\u6E05\u7406\u5206\u652F)"
308
+ gitWorkflow: "Git \u6307\u4EE4 (commit + rollback + cleanBranches + worktree)"
309
309
  },
310
310
  workflowDescription: {
311
311
  gitWorkflow: "\u589E\u5F3A\u7248 Git \u547D\u4EE4\uFF0C\u652F\u6301\u667A\u80FD\u63D0\u4EA4\u3001\u5B89\u5168\u56DE\u6EDA\u548C\u81EA\u52A8\u5316\u5206\u652F\u6E05\u7406"
@@ -751,7 +751,7 @@ const workflow = {
751
751
  featPlanUx: "Feature Planning and UX Design (feat + planner + ui-ux-designer)",
752
752
  sixStepsWorkflow: "Six Steps Workflow (workflow)",
753
753
  bmadWorkflow: "BMAD-Method Extension Installer (Agile Development Workflow)",
754
- gitWorkflow: "Smart Git Operations (Git Commit, Rollback, Clean Branches)"
754
+ gitWorkflow: "Git Commands (commit + rollback + cleanBranches + worktree)"
755
755
  },
756
756
  workflowDescription: {
757
757
  gitWorkflow: "Enhanced Git commands for smart commits, safe rollbacks, and automated branch cleanup"
@@ -1993,7 +1993,7 @@ const WORKFLOW_CONFIGS = [
1993
1993
  descriptionKey: "workflowDescription.gitWorkflow",
1994
1994
  defaultSelected: true,
1995
1995
  order: 4,
1996
- commands: ["git-commit.md", "git-rollback.md", "git-cleanBranches.md"],
1996
+ commands: ["git-commit.md", "git-rollback.md", "git-cleanBranches.md", "git-worktree.md"],
1997
1997
  agents: [],
1998
1998
  autoInstallAgents: false,
1999
1999
  category: "git",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aico-cli",
3
- "version": "0.0.9",
3
+ "version": "0.1.0",
4
4
  "packageManager": "pnpm@9.15.9",
5
5
  "description": "AI CLI",
6
6
  "repository": {
@@ -0,0 +1,301 @@
1
+ ---
2
+ description: Manage Git worktrees, support add/list/remove/migrate operations, create in .zcf/ directory by default, auto-configure git ignore rules, support IDE quick open 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, code, cursor, webstorm), Write(.git/info/exclude)
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 worktree, ask whether to open in IDE by default
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, worktree and open in IDE directly
9
+ # - /git-worktree migrate feature-ui --from main # migrate uncommitted content from main branch to feature-ui worktree
10
+ # - /git-worktree migrate feature-ui --stash # migrate current stash content to feature-ui worktree
11
+ ---
12
+
13
+ # Claude Command: Git Worktree
14
+
15
+ **Purpose**: Provide Git worktree quick operations, manage multiple working trees in `.zcf/` directory by default, auto-handle git ignore configuration, support IDE quick open and cross-worktree content migration.
16
+
17
+ ---
18
+
19
+ ## Usage
20
+
21
+ ```bash
22
+ # Add worktree (default in .zcf/)
23
+ /git-worktree add <path> # checkout same-name branch to .zcf/<path>, ask whether to open IDE
24
+ /git-worktree add <path> -b <branch> # create new branch and add worktree
25
+ /git-worktree add <path> -o # create and open directly in IDE
26
+ /git-worktree add <path> -b <branch> --open # create new branch, worktree and open directly
27
+
28
+ # Content migration
29
+ /git-worktree migrate <target-path> --from <source-path> # migrate uncommitted content
30
+ /git-worktree migrate <target-path> --stash # migrate stash content
31
+
32
+ # Other operations
33
+ /git-worktree list # show all worktree status
34
+ /git-worktree remove <path> # remove specified worktree
35
+ /git-worktree prune # clean invalid worktree records
36
+ ```
37
+
38
+ ### Options
39
+
40
+ | Option | Description |
41
+ |--------|-------------|
42
+ | `add <path>` | Add new worktree in `.zcf/<path>` |
43
+ | `migrate <target>` | Migrate content to specified worktree |
44
+ | `list` | List all worktrees and their status |
45
+ | `remove <path>` | Remove worktree at specified path |
46
+ | `prune` | Clean invalid worktree references |
47
+ | `-b <branch>` | Create new branch and checkout to worktree |
48
+ | `-o, --open` | Open directly in IDE after creation (skip prompt) |
49
+ | `--from <source>` | Specify migration source path (migrate only) |
50
+ | `--stash` | Migrate current stash content (migrate only) |
51
+ | `--track` | Set new branch to track corresponding remote branch |
52
+ | `--guess-remote` | Auto guess remote branch for tracking |
53
+ | `--detach` | Create detached HEAD worktree |
54
+ | `--checkout` | Checkout immediately after creation (default behavior) |
55
+ | `--lock` | Lock worktree after creation |
56
+
57
+ ---
58
+
59
+ ## What This Command Does
60
+
61
+ ### 1. **Environment Check**
62
+ - Confirm in Git repository via `git rev-parse --is-inside-work-tree`
63
+
64
+ ### 2. **Ignore Rules Configuration**
65
+ - Check if `.git/info/exclude` contains `/.zcf/` rule
66
+ - Auto-add `/.zcf/` to `.git/info/exclude` if not exists
67
+
68
+ ### 3. **Worktree Operations**
69
+ - **add**: Create new worktree in `.zcf/<path>`
70
+ - **list**: Show all worktree paths, branches and status
71
+ - **remove**: Safely remove specified worktree
72
+ - **prune**: Clean orphaned worktree records
73
+
74
+ ### 4. **🆕 IDE Quick Open Feature**
75
+ - **Default behavior**: Ask whether to open new worktree in IDE after `add` operation
76
+ - **Direct open**: Use `-o/--open` parameter to skip prompt and open directly
77
+ - **IDE detection**: Auto-detect common IDEs (VS Code, Cursor, WebStorm, etc.)
78
+ - **Smart selection**: Recommend best choice based on project type and installed IDEs
79
+
80
+ ### 5. **🆕 Content Migration Feature**
81
+ - **Uncommitted content migration**: Migrate uncommitted changes from one worktree to another
82
+ - **Stash migration**: Apply current stash content to target worktree
83
+ - **Safety check**: Check target worktree status before migration to avoid conflicts
84
+
85
+ ### 6. **Path Handling**
86
+ - Auto-add `.zcf/` prefix to all relative paths
87
+ - Keep absolute paths as-is
88
+ - Auto-create `.zcf/` directory if not exists
89
+
90
+ ### 7. **Branch Management**
91
+ - Support checking out existing branches or creating new branches
92
+ - Auto-handle remote branch tracking
93
+ - Provide branch status and HEAD position info
94
+
95
+ ---
96
+
97
+ ## Enhanced Features
98
+
99
+ ### 🖥️ **IDE Integration**
100
+
101
+ **Supported IDEs**
102
+ - **VS Code**: `code <path>`
103
+ - **Cursor**: `cursor <path>`
104
+ - **WebStorm**: `webstorm <path>`
105
+ - **Others**: Configurable custom IDE commands
106
+
107
+ **Open Modes**
108
+ ```bash
109
+ # Default: ask whether to open after creation
110
+ /git-worktree add feature-ui
111
+ # Output: 🖥️ Open .zcf/feature-ui in IDE? [y/n]:
112
+
113
+ # Direct open: skip prompt
114
+ /git-worktree add feature-ui -o
115
+ # Output: 🚀 Opening .zcf/feature-ui in VS Code...
116
+ ```
117
+
118
+ **Smart Detection Flow**
119
+ 1. Check installed IDEs in system
120
+ 2. Recommend based on project type (e.g., recommend VS Code for Node.js projects)
121
+ 3. Provide selection menu for user choice (default mode)
122
+ 4. Remember user preference for next time
123
+
124
+ ### 📦 **Content Migration System**
125
+
126
+ **Migration Types**
127
+ ```bash
128
+ # Migrate uncommitted content from main branch
129
+ /git-worktree migrate feature-ui --from main
130
+
131
+ # Migrate from other worktree
132
+ /git-worktree migrate hotfix --from .zcf/feature-ui
133
+
134
+ # Migrate current stash
135
+ /git-worktree migrate feature-ui --stash
136
+
137
+ # Migrate specific stash
138
+ /git-worktree migrate feature-ui --stash stash@{2}
139
+ ```
140
+
141
+ **Migration Flow**
142
+ 1. **Source check**: Verify source path exists and has uncommitted content
143
+ 2. **Target check**: Ensure target worktree working directory is clean
144
+ 3. **Content analysis**: Show files and changes to be migrated
145
+ 4. **Safe migration**: Use git native commands to ensure data safety
146
+ 5. **Result confirmation**: Show migration results and follow-up suggestions
147
+
148
+ ---
149
+
150
+ ## Safety Features
151
+
152
+ - **Path check**: Prevent creating worktree in existing directory
153
+ - **Branch conflict check**: Avoid same branch being checked out by multiple worktrees
154
+ - **Auto cleanup**: Remove operation cleans both directory and git references
155
+ - **Status display**: Clearly show each worktree's branch, commit and status
156
+
157
+ ### **Migration Safety Protection**
158
+ - **Conflict detection**: Check for potential file conflicts before migration
159
+ - **Backup mechanism**: Auto-create stash backup before migration
160
+ - **Rollback support**: Provide rollback solution when migration fails
161
+ - **Status validation**: Ensure source and target worktrees are in correct state
162
+
163
+ ### **IDE Integration Safety**
164
+ - **Path validation**: Ensure IDE commands use correct paths
165
+ - **Permission check**: Verify IDE executable permissions
166
+ - **Error handling**: Friendly error messages when IDE startup fails
167
+
168
+ ---
169
+
170
+ ## Examples
171
+
172
+ ### **Basic Usage + IDE Open**
173
+ ```bash
174
+ # Create worktree and ask for IDE open (default behavior)
175
+ /git-worktree add feature-ui
176
+ # Output:
177
+ # ✅ Worktree created at .zcf/feature-ui
178
+ # 🖥️ Detected IDEs:
179
+ # 1. VS Code (recommended)
180
+ # 2. Cursor
181
+ # Open this worktree in IDE? [1/2/n]: 1
182
+ # 🚀 Opening .zcf/feature-ui in VS Code...
183
+
184
+ # Create worktree and open IDE directly
185
+ /git-worktree add feature-ui -o
186
+ # Output:
187
+ # ✅ Worktree created at .zcf/feature-ui
188
+ # 🚀 Opening .zcf/feature-ui in VS Code...
189
+
190
+ # Create new branch and open directly
191
+ /git-worktree add hotfix -b fix/login --open
192
+ # Output:
193
+ # ✅ Created branch 'fix/login' and worktree at .zcf/hotfix
194
+ # 🚀 Opening .zcf/hotfix in VS Code...
195
+ ```
196
+
197
+ ### **Content Migration Scenarios**
198
+ ```bash
199
+ # Scenario: developed some features on main branch, want to move to new branch
200
+ # 1. Create new feature worktree
201
+ /git-worktree add feature-ui -b feature/new-ui
202
+
203
+ # 2. Migrate uncommitted content from main
204
+ /git-worktree migrate feature-ui --from main
205
+ # Output:
206
+ # 📦 Found uncommitted content:
207
+ # M src/components/Button.tsx
208
+ # A src/components/Modal.tsx
209
+ # ?? src/styles/new-theme.css
210
+ # 🔄 Migrating to .zcf/feature-ui...
211
+ # ✅ Migration completed! Suggest committing these changes in new worktree.
212
+
213
+ # 3. Ask whether to open IDE (since -o wasn't used during creation)
214
+ # 🖥️ Open .zcf/feature-ui in IDE? [y/n]: y
215
+ ```
216
+
217
+ ### **Stash Migration**
218
+ ```bash
219
+ # Have some stashes, want to apply to specific worktree
220
+ /git-worktree migrate hotfix --stash
221
+ # Output:
222
+ # 📋 Found stashes:
223
+ # stash@{0}: WIP on main: fix user login
224
+ # stash@{1}: WIP on main: update docs
225
+ # Select stash to migrate [0/1]: 0
226
+ # 🔄 Applying stash@{0} to .zcf/hotfix...
227
+ # ✅ Stash content applied successfully!
228
+ ```
229
+
230
+ ### **List and Manage Worktrees**
231
+ ```bash
232
+ # View all worktrees
233
+ /git-worktree list
234
+ # Output:
235
+ # /path/to/project [main] ← main working tree
236
+ # /path/to/project/.zcf/feature-ui [feature/new-ui]
237
+ # /path/to/project/.zcf/hotfix [fix/login]
238
+
239
+ # Remove unneeded worktree
240
+ /git-worktree remove feature-ui
241
+ # Output:
242
+ # ✅ Worktree .zcf/feature-ui removed successfully
243
+
244
+ # Clean invalid references
245
+ /git-worktree prune
246
+ # Output:
247
+ # 🧹 Pruned 0 worktree entries
248
+ ```
249
+
250
+ ---
251
+
252
+ ## Directory Structure
253
+
254
+ After using this command, project structure will be:
255
+ ```
256
+ your-project/
257
+ ├── .git/
258
+ ├── .zcf/ # worktree directory (ignored by git)
259
+ │ ├── feature-ui/ # feature-ui branch working tree
260
+ │ ├── hotfix/ # hotfix branch working tree
261
+ │ ├── debug/ # debug working tree
262
+ │ └── .worktree-config # worktree config file
263
+ ├── src/ # main working tree source
264
+ └── package.json # main working tree files
265
+ ```
266
+
267
+ ---
268
+
269
+ ## Configuration
270
+
271
+ ### **IDE Preferences**
272
+ Command saves user preferences in `.zcf/.worktree-config`:
273
+ ```json
274
+ {
275
+ "preferredIDE": "code",
276
+ "autoOpenIDE": false,
277
+ "migrateBackup": true,
278
+ "defaultWorktreeDir": ".zcf"
279
+ }
280
+ ```
281
+
282
+ ### **Custom IDE Commands**
283
+ ```bash
284
+ # Set custom IDE
285
+ git config worktree.ide.custom "subl %s" # Sublime Text
286
+ git config worktree.ide.preferred "custom"
287
+ ```
288
+
289
+ ---
290
+
291
+ ## Notes
292
+
293
+ - **Performance optimization**: Worktrees share `.git` directory, saving disk space
294
+ - **IDE support**: Most modern IDEs support multi-worktree projects
295
+ - **Cleanup suggestion**: Regularly run `prune` to clean invalid references
296
+ - **Branch protection**: Avoid operations on protected branches (like main/master)
297
+ - **Migration limitation**: Can only migrate uncommitted changes, use `git cherry-pick` for committed content
298
+ - **IDE requirement**: IDE command-line tools must be installed and in PATH
299
+ - **Cross-platform support**: IDE detection and startup support Windows, macOS, Linux
300
+
301
+ ---
@@ -11,9 +11,10 @@ argument-hint: [--no-verify] [--all] [--amend] [--signoff] [--emoji] [--scope <s
11
11
  # - /git-commit --amend --signoff # 修补上次提交并签名
12
12
  ---
13
13
 
14
- # Claude Command: Commit (Gitonly)
14
+ # Claude Command: Commit (Git-only)
15
15
 
16
16
  该命令在**不依赖任何包管理器/构建工具**的前提下,仅通过 **Git**:
17
+
17
18
  - 读取改动(staged/unstaged)
18
19
  - 判断是否需要**拆分为多次提交**
19
20
  - 为每个提交生成 **Conventional Commits** 风格的信息(可选 emoji)
@@ -33,6 +34,7 @@ argument-hint: [--no-verify] [--all] [--amend] [--signoff] [--emoji] [--scope <s
33
34
  ```
34
35
 
35
36
  ### Options
37
+
36
38
  - `--no-verify`:跳过本地 Git 钩子(`pre-commit`/`commit-msg` 等)。
37
39
  - `--all`:当暂存区为空时,自动 `git add -A` 将所有改动纳入本次提交。
38
40
  - `--amend`:在不创建新提交的情况下**修补**上一次提交(保持提交作者与时间,除非本地 Git 配置另有指定)。
@@ -41,33 +43,38 @@ argument-hint: [--no-verify] [--all] [--amend] [--signoff] [--emoji] [--scope <s
41
43
  - `--scope <scope>`:指定提交作用域(如 `ui`、`docs`、`api`),写入消息头部。
42
44
  - `--type <type>`:强制提交类型(如 `feat`、`fix`、`docs` 等),覆盖自动判断。
43
45
 
44
- > 注:如框架不支持交互式确认,可在 frontmatter 中开启 `confirm: true` 以避免误操作。
46
+ > 注:如框架不支持交互式确认,可在 front-matter 中开启 `confirm: true` 以避免误操作。
45
47
 
46
48
  ---
47
49
 
48
50
  ## What This Command Does
49
51
 
50
52
  1. **仓库/分支校验**
53
+
51
54
  - 通过 `git rev-parse --is-inside-work-tree` 判断是否位于 Git 仓库。
52
55
  - 读取当前分支/HEAD 状态;如处于 rebase/merge 冲突状态,先提示处理冲突后再继续。
53
56
 
54
57
  2. **改动检测**
58
+
55
59
  - 用 `git status --porcelain` 与 `git diff` 获取已暂存与未暂存的改动。
56
60
  - 若已暂存文件为 0:
57
61
  - 若传入 `--all` → 执行 `git add -A`。
58
62
  - 否则提示你选择:继续仅分析未暂存改动并给出**建议**,或取消命令后手动分组暂存。
59
63
 
60
64
  3. **拆分建议(Split Heuristics)**
65
+
61
66
  - 按**关注点**、**文件模式**、**改动类型**聚类(示例:源代码 vs 文档、测试;不同目录/包;新增 vs 删除)。
62
67
  - 若检测到**多组独立变更**或 diff 规模过大(如 > 300 行 / 跨多个顶级目录),建议拆分提交,并给出每一组的 pathspec(便于后续执行 `git add <paths>`)。
63
68
 
64
69
  4. **提交信息生成(Conventional 规范,可选 Emoji)**
70
+
65
71
  - 自动推断 `type`(`feat`/`fix`/`docs`/`refactor`/`test`/`chore`/`perf`/`style`/`ci`/`revert` …)与可选 `scope`。
66
72
  - 生成消息头:`[<emoji>] <type>(<scope>)?: <subject>`(首行 ≤ 72 字符,祈使语气,仅在使用 `--emoji` 时包含 emoji)。
67
73
  - 生成消息体:要点列表(动机、实现要点、影响范围、BREAKING CHANGE 如有)。
68
74
  - 将草稿写入 `.git/COMMIT_EDITMSG`,并用于 `git commit`。
69
75
 
70
76
  5. **执行提交**
77
+
71
78
  - 单提交场景:`git commit [-S] [--no-verify] [-s] -F .git/COMMIT_EDITMSG`
72
79
  - 多提交场景(如接受拆分建议):按分组给出 `git add <paths> && git commit ...` 的明确指令;若允许执行则逐一完成。
73
80
 
@@ -88,16 +95,16 @@ argument-hint: [--no-verify] [--all] [--amend] [--signoff] [--emoji] [--scope <s
88
95
 
89
96
  ## Type 与 Emoji 映射(使用 --emoji 时)
90
97
 
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`:回滚提交
98
+ - ✨ `feat`:新增功能
99
+ - 🐛 `fix`:缺陷修复(含 🔥 删除代码/文件、🚑️ 紧急修复、👽️ 适配外部 API 变更、🔒️ 安全修复、🚨 解决告警、💚 修复 CI)
100
+ - 📝 `docs`:文档与注释
101
+ - 🎨 `style`:风格/格式(不改语义)
102
+ - ♻️ `refactor`:重构(不新增功能、不修缺陷)
103
+ - ⚡️ `perf`:性能优化
104
+ - ✅ `test`:新增/修复测试、快照
105
+ - 🔧 `chore`:构建/工具/杂务(合并分支、更新配置、发布标记、依赖 pin、.gitignore 等)
106
+ - 👷 `ci`:CI/CD 配置与脚本
107
+ - ⏪️ `revert`:回滚提交
101
108
  - 💥 `feat`:破坏性变更(`BREAKING CHANGE:` 段落中说明)
102
109
 
103
110
  > 若传入 `--type`/`--scope`,将**覆盖**自动推断。
@@ -107,10 +114,10 @@ argument-hint: [--no-verify] [--all] [--amend] [--signoff] [--emoji] [--scope <s
107
114
 
108
115
  ## Guidelines for Splitting Commits
109
116
 
110
- 1. **不同关注点**:互不相关的功能/模块改动应拆分。
111
- 2. **不同类型**:不要将 `feat`、`fix`、`refactor` 混在同一提交。
112
- 3. **文件模式**:源代码 vs 文档/测试/配置分组提交。
113
- 4. **规模阈值**:超大 diff(示例:>300 行或跨多个顶级目录)建议拆分。
117
+ 1. **不同关注点**:互不相关的功能/模块改动应拆分。
118
+ 2. **不同类型**:不要将 `feat`、`fix`、`refactor` 混在同一提交。
119
+ 3. **文件模式**:源代码 vs 文档/测试/配置分组提交。
120
+ 4. **规模阈值**:超大 diff(示例:>300 行或跨多个顶级目录)建议拆分。
114
121
  5. **可回滚性**:确保每个提交可独立回退。
115
122
 
116
123
  ---
@@ -118,35 +125,38 @@ argument-hint: [--no-verify] [--all] [--amend] [--signoff] [--emoji] [--scope <s
118
125
  ## Examples
119
126
 
120
127
  **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
128
+
129
+ - feat(ui): add user authentication flow
130
+ - 🐛 fix(api): handle token refresh race condition
131
+ - 📝 docs: update API usage examples
132
+ - ♻️ refactor(core): extract retry logic into helper
133
+ - test: add unit tests for rate limiter
134
+ - 🔧 chore: update git hooks and repository settings
127
135
  - ⏪️ revert: revert "feat(core): introduce streaming API"
128
136
 
129
137
  **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
138
+
139
+ - feat(ui): add user authentication flow
140
+ - fix(api): handle token refresh race condition
141
+ - docs: update API usage examples
142
+ - refactor(core): extract retry logic into helper
143
+ - test: add unit tests for rate limiter
144
+ - chore: update git hooks and repository settings
136
145
  - revert: revert "feat(core): introduce streaming API"
137
146
 
138
147
  **Split Example**
148
+
139
149
  - `feat(types): add new type defs for payment method`
140
150
  - `docs: update API docs for new types`
141
151
  - `test: add unit tests for payment types`
142
- - `fix: address linter warnings in new files` ←(如你的仓库有钩子报错)
152
+ - `fix: address linter warnings in new files` ←(如你的仓库有钩子报错)
143
153
 
144
154
  ---
145
155
 
146
156
  ## Important Notes
147
157
 
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` 步骤都会进行二次确认。
158
+ - **仅使用 Git**:不调用任何包管理器/构建命令(无 `pnpm`/`npm`/`yarn` 等)。
159
+ - **尊重钩子**:默认执行本地 Git 钩子;使用 `--no-verify` 可跳过。
160
+ - **不改源码内容**:命令只读写 `.git/COMMIT_EDITMSG` 与暂存区;不会直接编辑工作区文件。
161
+ - **安全提示**:在 rebase/merge 冲突、detached HEAD 等状态下会先提示处理/确认再继续。
162
+ - **可审可控**:如开启 `confirm: true`,每个实际 `git add`/`git commit` 步骤都会进行二次确认。
@@ -0,0 +1,301 @@
1
+ ---
2
+ description: 管理 Git worktree,支持 add/list/remove/migrate 操作,默认在 .zcf/ 目录下创建,自动配置 git 忽略规则,支持 IDE 快速打开和内容迁移
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, code, cursor, webstorm), Write(.git/info/exclude)
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 # 创建 worktree,默认询问是否用 IDE 打开
7
+ # - /git-worktree add feature-ui -o # 创建 worktree 并直接用 IDE 打开
8
+ # - /git-worktree add hotfix -b fix/login -o # 创建新分支、worktree 并直接打开 IDE
9
+ # - /git-worktree migrate feature-ui --from main # 将主分支的未提交内容迁移到 feature-ui worktree
10
+ # - /git-worktree migrate feature-ui --stash # 将当前 stash 内容迁移到 feature-ui worktree
11
+ ---
12
+
13
+ # Claude Command: Git Worktree
14
+
15
+ **目的**:提供 Git worktree 的快捷操作,默认在 `.zcf/` 目录下管理多个工作树,自动处理 git 忽略配置,支持 IDE 快速打开和跨 worktree 内容迁移。
16
+
17
+ ---
18
+
19
+ ## Usage
20
+
21
+ ```bash
22
+ # 添加 worktree(默认在 .zcf/ 下)
23
+ /git-worktree add <path> # 检出同名分支到 .zcf/<path>,询问是否打开 IDE
24
+ /git-worktree add <path> -b <branch> # 创建新分支并添加 worktree
25
+ /git-worktree add <path> -o # 创建后直接用 IDE 打开
26
+ /git-worktree add <path> -b <branch> --open # 创建新分支、worktree 并直接打开
27
+
28
+ # 内容迁移
29
+ /git-worktree migrate <target-path> --from <source-path> # 迁移未提交内容
30
+ /git-worktree migrate <target-path> --stash # 迁移 stash 内容
31
+
32
+ # 其他操作
33
+ /git-worktree list # 显示所有 worktree 状态
34
+ /git-worktree remove <path> # 删除指定的 worktree
35
+ /git-worktree prune # 清理无效 worktree 记录
36
+ ```
37
+
38
+ ### Options
39
+
40
+ | 选项 | 说明 |
41
+ |------|------|
42
+ | `add <path>` | 在 `.zcf/<path>` 添加新的 worktree |
43
+ | `migrate <target>` | 迁移内容到指定 worktree |
44
+ | `list` | 列出所有 worktree 及其状态 |
45
+ | `remove <path>` | 删除指定路径的 worktree |
46
+ | `prune` | 清理无效的 worktree 引用 |
47
+ | `-b <branch>` | 创建新分支并检出到 worktree |
48
+ | `-o, --open` | 创建成功后直接用 IDE 打开(跳过询问)|
49
+ | `--from <source>` | 指定迁移源路径(migrate 专用)|
50
+ | `--stash` | 迁移当前 stash 内容(migrate 专用)|
51
+ | `--track` | 设置新分支跟踪对应的远程分支 |
52
+ | `--guess-remote` | 自动猜测远程分支进行跟踪 |
53
+ | `--detach` | 创建分离 HEAD 的 worktree |
54
+ | `--checkout` | 创建后立即检出(默认行为)|
55
+ | `--lock` | 创建后锁定 worktree |
56
+
57
+ ---
58
+
59
+ ## What This Command Does
60
+
61
+ ### 1. **环境检查**
62
+ - 通过 `git rev-parse --is-inside-work-tree` 确认在 Git 仓库中
63
+
64
+ ### 2. **忽略规则配置**
65
+ - 检查 `.git/info/exclude` 是否包含 `/.zcf/` 规则
66
+ - 如果不存在,自动添加 `/.zcf/` 到 `.git/info/exclude`
67
+
68
+ ### 3. **Worktree 操作**
69
+ - **add**: 在 `.zcf/<path>` 创建新的 worktree
70
+ - **list**: 显示所有 worktree 的路径、分支和状态
71
+ - **remove**: 安全删除指定的 worktree
72
+ - **prune**: 清理孤立的 worktree 记录
73
+
74
+ ### 4. **🆕 IDE 快速打开功能**
75
+ - **默认行为**:`add` 操作成功后询问是否用 IDE 打开新 worktree
76
+ - **直接打开**:使用 `-o/--open` 参数跳过询问,直接打开
77
+ - **IDE 检测**:自动检测常用 IDE(VS Code、Cursor、WebStorm 等)
78
+ - **智能选择**:基于项目类型和已安装的 IDE 推荐最佳选择
79
+
80
+ ### 5. **🆕 内容迁移功能**
81
+ - **未提交内容迁移**:将一个 worktree 的未提交改动迁移到另一个
82
+ - **Stash 迁移**:将当前 stash 内容应用到目标 worktree
83
+ - **安全检查**:迁移前检查目标 worktree 状态,避免冲突
84
+
85
+ ### 6. **路径处理**
86
+ - 所有相对路径自动添加 `.zcf/` 前缀
87
+ - 绝对路径保持原样
88
+ - 自动创建 `.zcf/` 目录(如果不存在)
89
+
90
+ ### 7. **分支管理**
91
+ - 支持检出现有分支或创建新分支
92
+ - 自动处理远程分支跟踪
93
+ - 提供分支状态和 HEAD 位置信息
94
+
95
+ ---
96
+
97
+ ## Enhanced Features
98
+
99
+ ### 🖥️ **IDE 集成**
100
+
101
+ **支持的 IDE**
102
+ - **VS Code**: `code <path>`
103
+ - **Cursor**: `cursor <path>`
104
+ - **WebStorm**: `webstorm <path>`
105
+ - **其他**: 可配置自定义 IDE 命令
106
+
107
+ **打开模式**
108
+ ```bash
109
+ # 默认:创建后询问是否打开
110
+ /git-worktree add feature-ui
111
+ # 输出:🖥️ 是否在 IDE 中打开 .zcf/feature-ui?[y/n]:
112
+
113
+ # 直接打开:跳过询问
114
+ /git-worktree add feature-ui -o
115
+ # 输出:🚀 正在用 VS Code 打开 .zcf/feature-ui...
116
+ ```
117
+
118
+ **智能检测流程**
119
+ 1. 检查系统中已安装的 IDE
120
+ 2. 基于项目类型推荐(如 Node.js 项目推荐 VS Code)
121
+ 3. 提供选择菜单让用户选择(默认模式)
122
+ 4. 记住用户偏好供下次使用
123
+
124
+ ### 📦 **内容迁移系统**
125
+
126
+ **迁移类型**
127
+ ```bash
128
+ # 从主分支迁移未提交内容
129
+ /git-worktree migrate feature-ui --from main
130
+
131
+ # 从其他 worktree 迁移
132
+ /git-worktree migrate hotfix --from .zcf/feature-ui
133
+
134
+ # 迁移当前 stash
135
+ /git-worktree migrate feature-ui --stash
136
+
137
+ # 迁移指定 stash
138
+ /git-worktree migrate feature-ui --stash stash@{2}
139
+ ```
140
+
141
+ **迁移流程**
142
+ 1. **源检查**:验证源路径存在且有未提交内容
143
+ 2. **目标检查**:确保目标 worktree 工作区干净
144
+ 3. **内容分析**:显示即将迁移的文件和改动
145
+ 4. **安全迁移**:使用 git 原生命令确保数据安全
146
+ 5. **结果确认**:显示迁移结果和后续建议
147
+
148
+ ---
149
+
150
+ ## Safety Features
151
+
152
+ - **路径检查**:防止在已存在的目录创建 worktree
153
+ - **分支冲突检查**:避免同一分支被多个 worktree 检出
154
+ - **自动清理**:remove 操作会同时清理目录和 git 引用
155
+ - **状态显示**:清晰显示每个 worktree 的分支、提交和状态
156
+
157
+ ### **迁移安全保护**
158
+ - **冲突检测**:迁移前检查是否会产生文件冲突
159
+ - **备份机制**:迁移前自动创建 stash 备份
160
+ - **回滚支持**:提供迁移失败时的回滚方案
161
+ - **状态验证**:确保源和目标 worktree 处于正确状态
162
+
163
+ ### **IDE 集成安全**
164
+ - **路径验证**:确保 IDE 命令使用正确的路径
165
+ - **权限检查**:验证 IDE 可执行文件的权限
166
+ - **错误处理**:IDE 启动失败时的友好错误提示
167
+
168
+ ---
169
+
170
+ ## Examples
171
+
172
+ ### **基础使用 + IDE 打开**
173
+ ```bash
174
+ # 创建 worktree 并询问 IDE 打开(默认行为)
175
+ /git-worktree add feature-ui
176
+ # 输出:
177
+ # ✅ Worktree created at .zcf/feature-ui
178
+ # 🖥️ 检测到以下 IDE:
179
+ # 1. VS Code (推荐)
180
+ # 2. Cursor
181
+ # 是否在 IDE 中打开此 worktree?[1/2/n]: 1
182
+ # 🚀 正在用 VS Code 打开 .zcf/feature-ui...
183
+
184
+ # 创建 worktree 并直接打开 IDE
185
+ /git-worktree add feature-ui -o
186
+ # 输出:
187
+ # ✅ Worktree created at .zcf/feature-ui
188
+ # 🚀 正在用 VS Code 打开 .zcf/feature-ui...
189
+
190
+ # 创建新分支并直接打开
191
+ /git-worktree add hotfix -b fix/login --open
192
+ # 输出:
193
+ # ✅ Created branch 'fix/login' and worktree at .zcf/hotfix
194
+ # 🚀 正在用 VS Code 打开 .zcf/hotfix...
195
+ ```
196
+
197
+ ### **内容迁移场景**
198
+ ```bash
199
+ # 场景:在 main 分支开发了一些功能,想移到新分支
200
+ # 1. 创建新的 feature worktree
201
+ /git-worktree add feature-ui -b feature/new-ui
202
+
203
+ # 2. 将 main 的未提交内容迁移过去
204
+ /git-worktree migrate feature-ui --from main
205
+ # 输出:
206
+ # 📦 发现以下未提交内容:
207
+ # M src/components/Button.tsx
208
+ # A src/components/Modal.tsx
209
+ # ?? src/styles/new-theme.css
210
+ # 🔄 迁移到 .zcf/feature-ui...
211
+ # ✅ 迁移完成!建议在新 worktree 中提交这些改动。
212
+
213
+ # 3. 询问是否打开 IDE(因为创建时没有使用 -o)
214
+ # 🖥️ 是否在 IDE 中打开 .zcf/feature-ui?[y/n]: y
215
+ ```
216
+
217
+ ### **Stash 迁移**
218
+ ```bash
219
+ # 当前有一些 stash,想应用到特定 worktree
220
+ /git-worktree migrate hotfix --stash
221
+ # 输出:
222
+ # 📋 发现以下 stash:
223
+ # stash@{0}: WIP on main: fix user login
224
+ # stash@{1}: WIP on main: update docs
225
+ # 选择要迁移的 stash [0/1]: 0
226
+ # 🔄 正在将 stash@{0} 应用到 .zcf/hotfix...
227
+ # ✅ Stash 内容已成功应用!
228
+ ```
229
+
230
+ ### **列出和管理 worktree**
231
+ ```bash
232
+ # 查看所有 worktree
233
+ /git-worktree list
234
+ # 输出:
235
+ # /path/to/project [main] ← 主工作树
236
+ # /path/to/project/.zcf/feature-ui [feature/new-ui]
237
+ # /path/to/project/.zcf/hotfix [fix/login]
238
+
239
+ # 删除不需要的 worktree
240
+ /git-worktree remove feature-ui
241
+ # 输出:
242
+ # ✅ Worktree .zcf/feature-ui removed successfully
243
+
244
+ # 清理无效引用
245
+ /git-worktree prune
246
+ # 输出:
247
+ # 🧹 Pruned 0 worktree entries
248
+ ```
249
+
250
+ ---
251
+
252
+ ## Directory Structure
253
+
254
+ 使用此命令后,项目结构会是:
255
+ ```
256
+ your-project/
257
+ ├── .git/
258
+ ├── .zcf/ # worktree 目录(被 git 忽略)
259
+ │ ├── feature-ui/ # feature-ui 分支的工作树
260
+ │ ├── hotfix/ # hotfix 分支的工作树
261
+ │ ├── debug/ # debug 用的工作树
262
+ │ └── .worktree-config # worktree 配置文件
263
+ ├── src/ # 主工作树的源码
264
+ └── package.json # 主工作树的文件
265
+ ```
266
+
267
+ ---
268
+
269
+ ## Configuration
270
+
271
+ ### **IDE 偏好设置**
272
+ 命令会在 `.zcf/.worktree-config` 中保存用户偏好:
273
+ ```json
274
+ {
275
+ "preferredIDE": "code",
276
+ "autoOpenIDE": false,
277
+ "migrateBackup": true,
278
+ "defaultWorktreeDir": ".zcf"
279
+ }
280
+ ```
281
+
282
+ ### **自定义 IDE 命令**
283
+ ```bash
284
+ # 设置自定义 IDE
285
+ git config worktree.ide.custom "subl %s" # Sublime Text
286
+ git config worktree.ide.preferred "custom"
287
+ ```
288
+
289
+ ---
290
+
291
+ ## Notes
292
+
293
+ - **性能优化**:worktree 共享 `.git` 目录,节省磁盘空间
294
+ - **IDE 支持**:大多数现代 IDE 都支持多 worktree 项目
295
+ - **清理建议**:定期运行 `prune` 清理无效引用
296
+ - **分支保护**:避免在受保护分支(如 main/master)上操作
297
+ - **迁移限制**:只能迁移未提交的改动,已提交的内容需要使用 `git cherry-pick`
298
+ - **IDE 要求**:需要 IDE 的命令行工具已安装并在 PATH 中
299
+ - **跨平台支持**:IDE 检测和启动支持 Windows、macOS、Linux
300
+
301
+ ---