@ia-ccun/code-agent-cli 0.0.1
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 +211 -0
- package/bin/cli.js +83 -0
- package/config/agent/APPEND_SYSTEM.md +48 -0
- package/config/agent/SYSTEM.md +33 -0
- package/config/agent/bin/fd +0 -0
- package/config/agent/extensions/context.ts +578 -0
- package/config/agent/extensions/custom-footer.ts +170 -0
- package/config/agent/extensions/custom.ts +289 -0
- package/config/agent/extensions/review.ts +1281 -0
- package/config/agent/extensions/working-msg.ts +96 -0
- package/config/agent/help.md +364 -0
- package/config/agent/models.json +56 -0
- package/config/agent/prompts/feat.md +106 -0
- package/config/agent/prompts/git-commit.md +159 -0
- package/config/agent/prompts/git-rollback.md +91 -0
- package/config/agent/prompts/git-worktree.md +277 -0
- package/config/agent/prompts/help.md +10 -0
- package/config/agent/prompts/init-project.md +53 -0
- package/config/agent/prompts/workflow.md +194 -0
- package/config/agent/settings.json +7 -0
- package/config/agent/skills/code-review/SKILL.md +50 -0
- package/config/agent/skills/commit/SKILL.md +51 -0
- package/config/agent/skills/csv-data-summarizer/SKILL.md +149 -0
- package/config/agent/skills/csv-data-summarizer/analyze.py +182 -0
- package/config/agent/skills/csv-data-summarizer/examples/showcase_financial_pl_data.csv +46 -0
- package/config/agent/skills/csv-data-summarizer/requirements.txt +4 -0
- package/config/agent/skills/csv-data-summarizer/resources/sample.csv +22 -0
- package/config/agent/skills/find-skills/SKILL.md +133 -0
- package/config/agent/skills/frontend-design/LICENSE.txt +177 -0
- package/config/agent/skills/frontend-design/SKILL.md +42 -0
- package/config/agent/skills/github/SKILL.md +47 -0
- package/config/agent/skills/hello/SKILL.md +23 -0
- package/config/agent/skills/librarian/SKILL.md +195 -0
- package/config/agent/skills/markdown-to-html/SKILL.md +62 -0
- package/config/agent/skills/pr/SKILL.md +56 -0
- package/config/agent/skills/refactor/SKILL.md +37 -0
- package/config/agent/skills/skill-creator/LICENSE.txt +202 -0
- package/config/agent/skills/skill-creator/SKILL.md +356 -0
- package/config/agent/skills/skill-creator/references/output-patterns.md +82 -0
- package/config/agent/skills/skill-creator/references/workflows.md +28 -0
- package/config/agent/skills/skill-creator/scripts/init_skill.py +303 -0
- package/config/agent/skills/skill-creator/scripts/package_skill.py +110 -0
- package/config/agent/skills/skill-creator/scripts/quick_validate.py +95 -0
- package/config/agent/skills/ui-ux-pro-max/SKILL.md +264 -0
- package/config/agent/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/config/agent/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/config/agent/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/config/agent/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/config/agent/skills/ui-ux-pro-max/data/prompts.csv +24 -0
- package/config/agent/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/config/agent/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/config/agent/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/config/agent/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/config/agent/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/config/agent/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/config/agent/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/config/agent/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/config/agent/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/config/agent/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/config/agent/skills/ui-ux-pro-max/data/styles.csv +59 -0
- package/config/agent/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/config/agent/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/config/agent/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-312.pyc +0 -0
- package/config/agent/skills/ui-ux-pro-max/scripts/analyze.py +434 -0
- package/config/agent/skills/ui-ux-pro-max/scripts/core.py +238 -0
- package/config/agent/skills/ui-ux-pro-max/scripts/search.py +61 -0
- package/config/agent/skills/unit-test/SKILL.md +115 -0
- package/config/agent/themes/catppuccin-mocha.json +99 -0
- package/config.json +6 -0
- package/dist/banner.d.ts +10 -0
- package/dist/banner.d.ts.map +1 -0
- package/dist/banner.js +32 -0
- package/dist/banner.js.map +1 -0
- package/dist/config-loader.d.ts +17 -0
- package/dist/config-loader.d.ts.map +1 -0
- package/dist/config-loader.js +60 -0
- package/dist/config-loader.js.map +1 -0
- package/dist/config.d.ts +23 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +12 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/package.json +69 -0
- package/scripts/postinstall.js +197 -0
|
@@ -0,0 +1,159 @@
|
|
|
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
|
+
---
|
|
6
|
+
|
|
7
|
+
# examples:
|
|
8
|
+
# - /git-commit # 分析当前改动,生成提交信息
|
|
9
|
+
# - /git-commit --all # 暂存所有改动并提交
|
|
10
|
+
# - /git-commit --no-verify # 跳过 Git 钩子检查
|
|
11
|
+
# - /git-commit --emoji # 在提交信息中包含 emoji
|
|
12
|
+
# - /git-commit --scope ui --type feat # 指定作用域和类型
|
|
13
|
+
# - /git-commit --amend --signoff # 修补上次提交并签名
|
|
14
|
+
|
|
15
|
+
# Claude Command: Commit (Git-only)
|
|
16
|
+
|
|
17
|
+
该命令在**不依赖任何包管理器/构建工具**的前提下,仅通过 **Git**:
|
|
18
|
+
|
|
19
|
+
- 读取改动(staged/unstaged)
|
|
20
|
+
- 判断是否需要**拆分为多次提交**
|
|
21
|
+
- 为每个提交生成 **Conventional Commits** 风格的信息(可选 emoji)
|
|
22
|
+
- 按需执行 `git add` 与 `git commit`(默认运行本地 Git 钩子;可 `--no-verify` 跳过)
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
/git-commit
|
|
30
|
+
/git-commit --no-verify
|
|
31
|
+
/git-commit --emoji
|
|
32
|
+
/git-commit --all --signoff
|
|
33
|
+
/git-commit --amend
|
|
34
|
+
/git-commit --scope ui --type feat --emoji
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Options
|
|
38
|
+
|
|
39
|
+
- `--no-verify`:跳过本地 Git 钩子(`pre-commit`/`commit-msg` 等)。
|
|
40
|
+
- `--all`:当暂存区为空时,自动 `git add -A` 将所有改动纳入本次提交。
|
|
41
|
+
- `--amend`:在不创建新提交的情况下**修补**上一次提交(保持提交作者与时间,除非本地 Git 配置另有指定)。
|
|
42
|
+
- `--signoff`:附加 `Signed-off-by` 行(遵循 DCO 流程时使用)。
|
|
43
|
+
- `--emoji`:在提交信息中包含 emoji 前缀(省略则使用纯文本)。
|
|
44
|
+
- `--scope <scope>`:指定提交作用域(如 `ui`、`docs`、`api`),写入消息头部。
|
|
45
|
+
- `--type <type>`:强制提交类型(如 `feat`、`fix`、`docs` 等),覆盖自动判断。
|
|
46
|
+
|
|
47
|
+
> 注:如框架不支持交互式确认,可在 front-matter 中开启 `confirm: true` 以避免误操作。
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## What This Command Does
|
|
52
|
+
|
|
53
|
+
1. **仓库/分支校验**
|
|
54
|
+
- 通过 `git rev-parse --is-inside-work-tree` 判断是否位于 Git 仓库。
|
|
55
|
+
- 读取当前分支/HEAD 状态;如处于 rebase/merge 冲突状态,先提示处理冲突后再继续。
|
|
56
|
+
|
|
57
|
+
2. **改动检测**
|
|
58
|
+
- 用 `git status --porcelain` 与 `git diff` 获取已暂存与未暂存的改动。
|
|
59
|
+
- 若已暂存文件为 0:
|
|
60
|
+
- 若传入 `--all` → 执行 `git add -A`。
|
|
61
|
+
- 否则提示你选择:继续仅分析未暂存改动并给出**建议**,或取消命令后手动分组暂存。
|
|
62
|
+
|
|
63
|
+
3. **拆分建议(Split Heuristics)**
|
|
64
|
+
- 按**关注点**、**文件模式**、**改动类型**聚类(示例:源代码 vs 文档、测试;不同目录/包;新增 vs 删除)。
|
|
65
|
+
- 若检测到**多组独立变更**或 diff 规模过大(如 > 300 行 / 跨多个顶级目录),建议拆分提交,并给出每一组的 pathspec(便于后续执行 `git add <paths>`)。
|
|
66
|
+
|
|
67
|
+
4. **提交信息生成(Conventional 规范,可选 Emoji)**
|
|
68
|
+
- 自动推断 `type`(`feat`/`fix`/`docs`/`refactor`/`test`/`chore`/`perf`/`style`/`ci`/`revert` …)与可选 `scope`。
|
|
69
|
+
- 生成消息头:`[<emoji>] <type>(<scope>)?: <subject>`(首行 ≤ 72 字符,祈使语气,仅在使用 `--emoji` 时包含 emoji)。
|
|
70
|
+
- 生成消息体:要点列表(动机、实现要点、影响范围、BREAKING CHANGE 如有)。
|
|
71
|
+
- 根据 Git 历史提交的主要语言选择提交信息语言。优先检查最近提交主题(例如 `git log -n 50 --pretty=%s`)判断中文/英文;若无法判断,则回退到仓库主要语言或英文。
|
|
72
|
+
- 将草稿写入 `.git/COMMIT_EDITMSG`,并用于 `git commit`。
|
|
73
|
+
|
|
74
|
+
5. **执行提交**
|
|
75
|
+
- 单提交场景:`git commit [-S] [--no-verify] [-s] -F .git/COMMIT_EDITMSG`
|
|
76
|
+
- 多提交场景(如接受拆分建议):按分组给出 `git add <paths> && git commit ...` 的明确指令;若允许执行则逐一完成。
|
|
77
|
+
|
|
78
|
+
6. **安全回滚**
|
|
79
|
+
- 如误暂存,可用 `git restore --staged <paths>` 撤回暂存(命令会给出指令,不修改文件内容)。
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Best Practices for Commits
|
|
84
|
+
|
|
85
|
+
- **Atomic commits**:一次提交只做一件事,便于回溯与审阅。
|
|
86
|
+
- **先分组再提交**:按目录/模块/功能点拆分。
|
|
87
|
+
- **清晰主题**:首行 ≤ 72 字符,祈使语气(如 “add… / fix…”)。
|
|
88
|
+
- **正文含上下文**:说明动机、方案、影响范围、风险与后续工作。
|
|
89
|
+
- **遵循 Conventional Commits**:`<type>(<scope>): <subject>`。
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Type 与 Emoji 映射(使用 --emoji 时)
|
|
94
|
+
|
|
95
|
+
- ✨ `feat`:新增功能
|
|
96
|
+
- 🐛 `fix`:缺陷修复(含 🔥 删除代码/文件、🚑️ 紧急修复、👽️ 适配外部 API 变更、🔒️ 安全修复、🚨 解决告警、💚 修复 CI)
|
|
97
|
+
- 📝 `docs`:文档与注释
|
|
98
|
+
- 🎨 `style`:风格/格式(不改语义)
|
|
99
|
+
- ♻️ `refactor`:重构(不新增功能、不修缺陷)
|
|
100
|
+
- ⚡️ `perf`:性能优化
|
|
101
|
+
- ✅ `test`:新增/修复测试、快照
|
|
102
|
+
- 🔧 `chore`:构建/工具/杂务(合并分支、更新配置、发布标记、依赖 pin、.gitignore 等)
|
|
103
|
+
- 👷 `ci`:CI/CD 配置与脚本
|
|
104
|
+
- ⏪️ `revert`:回滚提交
|
|
105
|
+
- 💥 `feat`:破坏性变更(`BREAKING CHANGE:` 段落中说明)
|
|
106
|
+
|
|
107
|
+
> 若传入 `--type`/`--scope`,将**覆盖**自动推断。
|
|
108
|
+
> 仅在指定 `--emoji` 标志时才会包含 emoji。
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Guidelines for Splitting Commits
|
|
113
|
+
|
|
114
|
+
1. **不同关注点**:互不相关的功能/模块改动应拆分。
|
|
115
|
+
2. **不同类型**:不要将 `feat`、`fix`、`refactor` 混在同一提交。
|
|
116
|
+
3. **文件模式**:源代码 vs 文档/测试/配置分组提交。
|
|
117
|
+
4. **规模阈值**:超大 diff(示例:>300 行或跨多个顶级目录)建议拆分。
|
|
118
|
+
5. **可回滚性**:确保每个提交可独立回退。
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Examples
|
|
123
|
+
|
|
124
|
+
**Good (使用 --emoji)**
|
|
125
|
+
|
|
126
|
+
- ✨ feat(ui): add user authentication flow
|
|
127
|
+
- 🐛 fix(api): handle token refresh race condition
|
|
128
|
+
- 📝 docs: update API usage examples
|
|
129
|
+
- ♻️ refactor(core): extract retry logic into helper
|
|
130
|
+
- ✅ test: add unit tests for rate limiter
|
|
131
|
+
- 🔧 chore: update git hooks and repository settings
|
|
132
|
+
- ⏪️ revert: revert "feat(core): introduce streaming API"
|
|
133
|
+
|
|
134
|
+
**Good (不使用 --emoji)**
|
|
135
|
+
|
|
136
|
+
- feat(ui): add user authentication flow
|
|
137
|
+
- fix(api): handle token refresh race condition
|
|
138
|
+
- docs: update API usage examples
|
|
139
|
+
- refactor(core): extract retry logic into helper
|
|
140
|
+
- test: add unit tests for rate limiter
|
|
141
|
+
- chore: update git hooks and repository settings
|
|
142
|
+
- revert: revert "feat(core): introduce streaming API"
|
|
143
|
+
|
|
144
|
+
**Split Example**
|
|
145
|
+
|
|
146
|
+
- `feat(types): add new type defs for payment method`
|
|
147
|
+
- `docs: update API docs for new types`
|
|
148
|
+
- `test: add unit tests for payment types`
|
|
149
|
+
- `fix: address linter warnings in new files` ←(如你的仓库有钩子报错)
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Important Notes
|
|
154
|
+
|
|
155
|
+
- **仅使用 Git**:不调用任何包管理器/构建命令(无 `pnpm`/`npm`/`yarn` 等)。
|
|
156
|
+
- **尊重钩子**:默认执行本地 Git 钩子;使用 `--no-verify` 可跳过。
|
|
157
|
+
- **不改源码内容**:命令只读写 `.git/COMMIT_EDITMSG` 与暂存区;不会直接编辑工作区文件。
|
|
158
|
+
- **安全提示**:在 rebase/merge 冲突、detached HEAD 等状态下会先提示处理/确认再继续。
|
|
159
|
+
- **可审可控**:如开启 `confirm: true`,每个实际 `git add`/`git commit` 步骤都会进行二次确认。
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
---
|
|
6
|
+
|
|
7
|
+
# examples:
|
|
8
|
+
# - /git-rollback # 全交互模式,dry‑run
|
|
9
|
+
# - /git-rollback --branch dev # 直接选 dev,其他交互
|
|
10
|
+
# - /git-rollback --branch dev --target v1.2.0 --mode reset --yes
|
|
11
|
+
|
|
12
|
+
# Claude Command: Git Rollback
|
|
13
|
+
|
|
14
|
+
**目的**:安全、可视地将指定分支回滚到旧版本。
|
|
15
|
+
默认处于 **只读预览 (`--dry-run`)**;真正执行需加 `--yes` 或在交互中确认。
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# 纯交互:列出分支 → 选分支 → 列最近 20 个版本 → 选目标 → 选择 reset 或 revert → 二次确认
|
|
23
|
+
/git-rollback
|
|
24
|
+
|
|
25
|
+
# 指定分支,其他交互
|
|
26
|
+
/git-rollback --branch feature/calculator
|
|
27
|
+
|
|
28
|
+
# 指定分支与目标 commit,并用 hard‑reset 一键执行(危险)
|
|
29
|
+
/git-rollback --branch main --target 1a2b3c4d --mode reset --yes
|
|
30
|
+
|
|
31
|
+
# 只想生成 revert 提交(非破坏式回滚),预览即可
|
|
32
|
+
/git-rollback --branch release/v2.1 --target v2.0.5 --mode revert --dry-run
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Options
|
|
36
|
+
|
|
37
|
+
| 选项 | 说明 |
|
|
38
|
+
| ---------------------- | ---------------------------------------------------------------------------------- |
|
|
39
|
+
| `--branch <branch>` | 要回滚的分支;缺省时交互选择。 |
|
|
40
|
+
| `--target <rev>` | 目标版本(commit Hash、Tag、reflog 引用都行);缺省时交互选择近 `--depth` 条记录。 |
|
|
41
|
+
| `--mode reset\|revert` | `reset`:硬回滚历史;`revert`:生成反向提交保持历史完整。默认询问。 |
|
|
42
|
+
| `--depth <n>` | 在交互模式下列出最近 n 个版本(默认 20)。 |
|
|
43
|
+
| `--dry-run` | **默认开启**,只预览即将执行的命令。 |
|
|
44
|
+
| `--yes` | 跳过所有确认直接执行,适合 CI/CD 脚本。 |
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 交互流程
|
|
49
|
+
|
|
50
|
+
1. **同步远端** → `git fetch --all --prune`
|
|
51
|
+
2. **列分支** → `git branch -a`(本地+远端,过滤受保护分支)
|
|
52
|
+
3. **选分支** → 用户输入或传参
|
|
53
|
+
4. **列版本** → `git log --oneline -n <depth>` + `git tag --merged` + `git reflog -n <depth>`
|
|
54
|
+
5. **选目标** → 用户输入 commit hash / tag
|
|
55
|
+
6. **选模式** → `reset` 或 `revert`
|
|
56
|
+
7. **最终确认** (除非 `--yes`)
|
|
57
|
+
8. **执行回滚**
|
|
58
|
+
- `reset`:`git switch <branch> && git reset --hard <target>`
|
|
59
|
+
- `revert`:`git switch <branch> && git revert --no-edit <target>..HEAD`
|
|
60
|
+
9. **推送建议** → 提示是否 `git push --force-with-lease`(reset)或普通 `git push`(revert)
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 安全护栏
|
|
65
|
+
|
|
66
|
+
- **备份**:执行前自动在 reflog 中记录当前 HEAD,可用 `git switch -c backup/<timestamp>` 恢复。
|
|
67
|
+
- **保护分支**:如检测到 `main` / `master` / `production` 等受保护分支且开启 `reset` 模式,将要求额外确认。
|
|
68
|
+
- **--dry-run 默认开启**:防止误操作。
|
|
69
|
+
- **--force 禁止**:不提供 `--force`;如需强推,请手动输入 `git push --force-with-lease`。
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## 适用场景示例
|
|
74
|
+
|
|
75
|
+
| 场景 | 调用示例 |
|
|
76
|
+
| ----------------------------------------------- | ---------------------------------------------------------------- |
|
|
77
|
+
| 热修补丁上线后发现 bug,需要回到 Tag `v1.2.0` | `/git-rollback --branch release/v1 --target v1.2.0 --mode reset` |
|
|
78
|
+
| 运维同事误推了 debug 日志提交,需要生成反向提交 | `/git-rollback --branch main --target 3f2e7c9 --mode revert` |
|
|
79
|
+
| 调研历史 bug,引导新人浏览分支历史 | `/git-rollback` (全交互,dry‑run) |
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 注意
|
|
84
|
+
|
|
85
|
+
1. **reset vs revert**
|
|
86
|
+
- **reset** 会改变历史,需要强推并可能影响其他协作者,谨慎使用。
|
|
87
|
+
- **revert** 更安全,生成新提交保留历史,但会增加一次记录。
|
|
88
|
+
2. **嵌入式仓库** 常有大体积二进制文件;回滚前请确保 LFS/子模块状态一致。
|
|
89
|
+
3. 若仓库启用了 CI 强制校验,回滚后可能自动触发流水线;确认管控策略以免误部署旧版本。
|
|
90
|
+
|
|
91
|
+
---
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 管理 Git worktree
|
|
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
|
+
---
|
|
6
|
+
|
|
7
|
+
# examples:
|
|
8
|
+
# - /git-worktree add feature-ui # 从 main/master 创建新分支 'feature-ui'
|
|
9
|
+
# - /git-worktree add feature-ui -o # 创建 worktree 并直接用 IDE 打开
|
|
10
|
+
# - /git-worktree add hotfix -b fix/login -o # 创建新分支 'fix/login',路径为 'hotfix'
|
|
11
|
+
# - /git-worktree migrate feature-ui --from main # 将主分支未提交内容迁移到 feature-ui
|
|
12
|
+
# - /git-worktree migrate feature-ui --stash # 将当前 stash 迁移到 feature-ui
|
|
13
|
+
|
|
14
|
+
# Claude Command: Git Worktree
|
|
15
|
+
|
|
16
|
+
管理 Git worktree,支持智能默认、IDE 集成和内容迁移,使用结构化的 `../.zcf/项目名/` 路径。
|
|
17
|
+
|
|
18
|
+
直接执行命令并提供简洁结果。
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# 基本操作
|
|
26
|
+
/git-worktree add <path> # 从 main/master 创建名为 <path> 的新分支
|
|
27
|
+
/git-worktree add <path> -b <branch> # 创建指定名称的新分支
|
|
28
|
+
/git-worktree add <path> -o # 创建并直接用 IDE 打开
|
|
29
|
+
/git-worktree list # 显示所有 worktree 状态
|
|
30
|
+
/git-worktree remove <path> # 删除指定的 worktree
|
|
31
|
+
/git-worktree prune # 清理无效 worktree 记录
|
|
32
|
+
|
|
33
|
+
# 内容迁移
|
|
34
|
+
/git-worktree migrate <target> --from <source> # 迁移未提交内容
|
|
35
|
+
/git-worktree migrate <target> --stash # 迁移 stash 内容
|
|
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
|
+
- 检测是否在主仓库或现有 worktree 中,进行智能路径计算
|
|
64
|
+
|
|
65
|
+
2. **智能路径管理**
|
|
66
|
+
- 使用 worktree 检测自动从主仓库路径计算项目名
|
|
67
|
+
- 在结构化的 `../.zcf/项目名/<path>` 目录创建 worktree
|
|
68
|
+
- 正确处理主仓库和 worktree 执行上下文
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# worktree 检测的核心路径计算逻辑
|
|
72
|
+
get_main_repo_path() {
|
|
73
|
+
local git_common_dir=$(git rev-parse --git-common-dir 2>/dev/null)
|
|
74
|
+
local current_toplevel=$(git rev-parse --show-toplevel 2>/dev/null)
|
|
75
|
+
|
|
76
|
+
# 检测是否在 worktree 中
|
|
77
|
+
if [[ "$git_common_dir" != "$current_toplevel/.git" ]]; then
|
|
78
|
+
# 在 worktree 中,从 git-common-dir 推导主仓库路径
|
|
79
|
+
dirname "$git_common_dir"
|
|
80
|
+
else
|
|
81
|
+
# 在主仓库中
|
|
82
|
+
echo "$current_toplevel"
|
|
83
|
+
fi
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
MAIN_REPO_PATH=$(get_main_repo_path)
|
|
87
|
+
PROJECT_NAME=$(basename "$MAIN_REPO_PATH")
|
|
88
|
+
WORKTREE_BASE="$MAIN_REPO_PATH/../.zcf/$PROJECT_NAME"
|
|
89
|
+
|
|
90
|
+
# 始终使用绝对路径防止嵌套问题
|
|
91
|
+
ABSOLUTE_WORKTREE_PATH="$WORKTREE_BASE/<path>"
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**关键修复**: 在现有 worktree 内创建新 worktree 时,始终使用绝对路径以防止出现类似 `../.zcf/project/.zcf/project/path` 的路径嵌套问题。
|
|
95
|
+
|
|
96
|
+
3. **Worktree 操作**
|
|
97
|
+
- **add**: 使用智能分支/路径默认创建新 worktree
|
|
98
|
+
- **list**: 显示所有 worktree 的分支和状态
|
|
99
|
+
- **remove**: 安全删除 worktree 并清理引用
|
|
100
|
+
- **prune**: 清理孤立的 worktree 记录
|
|
101
|
+
|
|
102
|
+
4. **智能默认**
|
|
103
|
+
- **分支创建**: 未指定 `-b` 时,使用路径名创建新分支
|
|
104
|
+
- **基础分支**: 新分支从 main/master 分支创建
|
|
105
|
+
- **路径解析**: 未指定路径时使用分支名作为路径
|
|
106
|
+
- **IDE 集成**: 自动检测并提示 IDE 打开
|
|
107
|
+
|
|
108
|
+
5. **内容迁移**
|
|
109
|
+
- 在 worktree 之间迁移未提交改动
|
|
110
|
+
- 将 stash 内容应用到目标 worktree
|
|
111
|
+
- 安全检查防止冲突
|
|
112
|
+
|
|
113
|
+
6. **安全特性**
|
|
114
|
+
- **路径冲突防护**: 创建前检查目录是否已存在
|
|
115
|
+
- **分支检出验证**: 确保分支未被其他地方使用
|
|
116
|
+
- **绝对路径强制**: 防止在 worktree 内创建嵌套的 `.zcf` 目录
|
|
117
|
+
- **删除时自动清理**: 同时清理目录和 git 引用
|
|
118
|
+
- **清晰的状态报告**: 显示 worktree 位置和分支状态
|
|
119
|
+
|
|
120
|
+
7. **环境文件处理**
|
|
121
|
+
- **自动检测**: 扫描 `.gitignore` 文件中的环境变量文件模式
|
|
122
|
+
- **智能复制**: 复制 `.gitignore` 中列出的 `.env` 和 `.env.*` 文件
|
|
123
|
+
- **排除逻辑**: 跳过 `.env.example` 等模板文件
|
|
124
|
+
- **权限保护**: 保持原始文件权限和时间戳
|
|
125
|
+
- **用户反馈**: 提供已复制环境文件的清晰状态信息
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# 环境文件复制实现
|
|
129
|
+
copy_environment_files() {
|
|
130
|
+
local main_repo="$MAIN_REPO_PATH"
|
|
131
|
+
local target_worktree="$ABSOLUTE_WORKTREE_PATH"
|
|
132
|
+
local gitignore_file="$main_repo/.gitignore"
|
|
133
|
+
|
|
134
|
+
# 检查 .gitignore 是否存在
|
|
135
|
+
if [[ ! -f "$gitignore_file" ]]; then
|
|
136
|
+
return 0
|
|
137
|
+
fi
|
|
138
|
+
|
|
139
|
+
local copied_count=0
|
|
140
|
+
|
|
141
|
+
# 检测 .env 文件
|
|
142
|
+
if [[ -f "$main_repo/.env" ]] && grep -q "^\.env$" "$gitignore_file"; then
|
|
143
|
+
cp "$main_repo/.env" "$target_worktree/.env"
|
|
144
|
+
echo "✅ 已复制 .env"
|
|
145
|
+
((copied_count++))
|
|
146
|
+
fi
|
|
147
|
+
|
|
148
|
+
# 检测 .env.* 模式文件(排除 .env.example)
|
|
149
|
+
for env_file in "$main_repo"/.env.*; do
|
|
150
|
+
if [[ -f "$env_file" ]] && [[ "$(basename "$env_file")" != ".env.example" ]]; then
|
|
151
|
+
local filename=$(basename "$env_file")
|
|
152
|
+
if grep -q "^\.env\.\*$" "$gitignore_file"; then
|
|
153
|
+
cp "$env_file" "$target_worktree/$filename"
|
|
154
|
+
echo "✅ 已复制 $filename"
|
|
155
|
+
((copied_count++))
|
|
156
|
+
fi
|
|
157
|
+
fi
|
|
158
|
+
done
|
|
159
|
+
|
|
160
|
+
if [[ $copied_count -gt 0 ]]; then
|
|
161
|
+
echo "📋 已从 .gitignore 复制 $copied_count 个环境文件"
|
|
162
|
+
fi
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Enhanced Features
|
|
169
|
+
|
|
170
|
+
### IDE 集成
|
|
171
|
+
|
|
172
|
+
- **自动检测**: VS Code → Cursor → WebStorm → Sublime Text → Vim
|
|
173
|
+
- **智能提示**: 创建 worktree 后询问是否在 IDE 中打开
|
|
174
|
+
- **直接打开**: 使用 `-o` 标志跳过提示直接打开
|
|
175
|
+
- **自定义配置**: 通过 git config 配置
|
|
176
|
+
|
|
177
|
+
### 内容迁移系统
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
# 迁移未提交改动
|
|
181
|
+
/git-worktree migrate feature-ui --from main
|
|
182
|
+
/git-worktree migrate hotfix --from ../other-worktree
|
|
183
|
+
|
|
184
|
+
# 迁移 stash 内容
|
|
185
|
+
/git-worktree migrate feature-ui --stash
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**迁移流程**:
|
|
189
|
+
|
|
190
|
+
1. 验证源有未提交内容
|
|
191
|
+
2. 确保目标 worktree 干净
|
|
192
|
+
3. 显示即将迁移的改动
|
|
193
|
+
4. 使用 git 命令安全迁移
|
|
194
|
+
5. 确认结果并建议后续步骤
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Examples
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
# 基本用法
|
|
202
|
+
/git-worktree add feature-ui # 从 main/master 创建新分支 'feature-ui'
|
|
203
|
+
/git-worktree add feature-ui -b my-feature # 创建新分支 'my-feature',路径为 'feature-ui'
|
|
204
|
+
/git-worktree add feature-ui -o # 创建并直接用 IDE 打开
|
|
205
|
+
|
|
206
|
+
# 内容迁移场景
|
|
207
|
+
/git-worktree add feature-ui -b feature/new-ui # 创建新功能 worktree
|
|
208
|
+
/git-worktree migrate feature-ui --from main # 迁移未提交改动
|
|
209
|
+
/git-worktree migrate hotfix --stash # 迁移 stash 内容
|
|
210
|
+
|
|
211
|
+
# 管理操作
|
|
212
|
+
/git-worktree list # 查看所有 worktree
|
|
213
|
+
/git-worktree remove feature-ui # 删除不需要的 worktree
|
|
214
|
+
/git-worktree prune # 清理无效引用
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**示例输出**:
|
|
218
|
+
|
|
219
|
+
```
|
|
220
|
+
✅ Worktree created at ../.zcf/项目名/feature-ui
|
|
221
|
+
✅ 已复制 .env
|
|
222
|
+
✅ 已复制 .env.local
|
|
223
|
+
📋 已从 .gitignore 复制 2 个环境文件
|
|
224
|
+
🖥️ 是否在 IDE 中打开 ../.zcf/项目名/feature-ui?[y/n]: y
|
|
225
|
+
🚀 正在用 VS Code 打开 ../.zcf/项目名/feature-ui...
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## Directory Structure
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
parent-directory/
|
|
234
|
+
├── your-project/ # 主项目
|
|
235
|
+
│ ├── .git/
|
|
236
|
+
│ └── src/
|
|
237
|
+
└── .zcf/ # worktree 管理
|
|
238
|
+
└── your-project/ # 项目 worktree
|
|
239
|
+
├── feature-ui/ # 功能分支
|
|
240
|
+
├── hotfix/ # 修复分支
|
|
241
|
+
└── debug/ # 调试 worktree
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Configuration
|
|
247
|
+
|
|
248
|
+
### IDE 配置
|
|
249
|
+
|
|
250
|
+
- 支持 VS Code、Cursor、WebStorm、Sublime Text、Vim
|
|
251
|
+
- 通过 git config 配置自定义 IDE
|
|
252
|
+
- 基于优先级的自动检测选择
|
|
253
|
+
|
|
254
|
+
### 自定义 IDE 设置
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
# 配置自定义 IDE
|
|
258
|
+
git config worktree.ide.custom.sublime "subl %s"
|
|
259
|
+
git config worktree.ide.preferred "sublime"
|
|
260
|
+
|
|
261
|
+
# 控制自动检测
|
|
262
|
+
git config worktree.ide.autodetect true # 默认
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## Notes
|
|
268
|
+
|
|
269
|
+
- **性能**: worktree 共享 `.git` 目录,节省磁盘空间
|
|
270
|
+
- **安全**: 路径冲突防护和分支检出验证
|
|
271
|
+
- **迁移**: 仅限未提交改动;已提交内容需使用 `git cherry-pick`
|
|
272
|
+
- **IDE 要求**: 命令行工具必须在 PATH 中
|
|
273
|
+
- **跨平台**: 支持 Windows、macOS、Linux
|
|
274
|
+
- **环境文件**: 自动复制 `.gitignore` 中列出的环境文件到新 worktree
|
|
275
|
+
- **文件排除**: 模板文件如 `.env.example` 仅保留在主仓库中
|
|
276
|
+
|
|
277
|
+
---
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: 初始化项目 AI 上下文,生成/更新根级与模块级 CLAUDE.md 索引
|
|
3
|
+
allowed-tools: Read(**), Write(CLAUDE.md, **/CLAUDE.md)
|
|
4
|
+
argument-hint: <项目摘要或名称>
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 用法
|
|
8
|
+
|
|
9
|
+
`/init-project <项目摘要或名称>`
|
|
10
|
+
|
|
11
|
+
## 目标
|
|
12
|
+
|
|
13
|
+
以"根级简明 + 模块级详尽"的混合策略初始化项目 AI 上下文:
|
|
14
|
+
|
|
15
|
+
- 在仓库根生成/更新 `CLAUDE.md`(高层愿景、架构总览、模块索引、全局规范)。
|
|
16
|
+
- 在识别的各模块目录生成/更新本地 `CLAUDE.md`(接口、依赖、入口、测试、关键文件等)。
|
|
17
|
+
- ✨ **为了提升可读性,会在根 `CLAUDE.md` 中自动生成 Mermaid 结构图,并为每个模块 `CLAUDE.md` 添加导航面包屑**。
|
|
18
|
+
|
|
19
|
+
## 编排说明
|
|
20
|
+
|
|
21
|
+
**步骤 1**:调用 `get-current-datetime` 子智能体获取当前时间戳。
|
|
22
|
+
|
|
23
|
+
**步骤 2**:调用一次 `init-architect` 子智能体,输入:
|
|
24
|
+
|
|
25
|
+
- `project_summary`: $ARGUMENTS
|
|
26
|
+
- `current_timestamp`: (来自步骤1的时间戳)
|
|
27
|
+
|
|
28
|
+
## 执行策略(由 Agent 自适应决定,不需要用户传参)
|
|
29
|
+
|
|
30
|
+
- **阶段 A:全仓清点(轻量)**
|
|
31
|
+
快速统计文件与目录,识别模块根(package.json、pyproject.toml、go.mod、apps/_、packages/_、services/\* 等)。
|
|
32
|
+
- **阶段 B:模块优先扫描(中等)**
|
|
33
|
+
对每个模块做"入口/接口/依赖/测试/数据模型/质量工具"的定点读取与样本抽取。
|
|
34
|
+
- **阶段 C:深度补捞(按需)**
|
|
35
|
+
若仓库较小或模块规模较小,则扩大读取面;若较大,则对高风险/高价值路径分批追加扫描。
|
|
36
|
+
- **覆盖率度量与可续跑**
|
|
37
|
+
输出"已扫描文件数 / 估算总文件数、已覆盖模块占比、被忽略/跳过原因",并列出"建议下一步深挖的子路径"。重复运行 `/init-project` 时按上次索引做**增量更新**与**断点续扫**。
|
|
38
|
+
|
|
39
|
+
## 安全与边界
|
|
40
|
+
|
|
41
|
+
- 只读/写文档与索引,不改源代码。
|
|
42
|
+
- 默认忽略常见生成物与二进制大文件。
|
|
43
|
+
- 结果在主对话打印"摘要",全文写入仓库。
|
|
44
|
+
|
|
45
|
+
## 输出要求
|
|
46
|
+
|
|
47
|
+
- 在主对话中打印"初始化结果摘要",包含:
|
|
48
|
+
- 根级 `CLAUDE.md` 是否创建/更新、主要栏目概览。
|
|
49
|
+
- 识别的模块数量及其路径列表。
|
|
50
|
+
- 每个模块 `CLAUDE.md` 的生成/更新情况。
|
|
51
|
+
- ✨ **明确提及"已生成 Mermaid 结构图"和"已为 N 个模块添加导航面包屑"**。
|
|
52
|
+
- 覆盖率与主要缺口。
|
|
53
|
+
- 若未读全:说明"为何到此为止",并列出**推荐的下一步**(例如"建议优先补扫:packages/auth/src/controllers")。
|