@icode-js/icode 3.2.0 → 3.4.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 +287 -24
- package/bin/icode.js +10 -0
- package/package.json +3 -3
- package/src/cli.js +175 -8
- package/src/commands/checkout.js +73 -6
- package/src/commands/clean.js +47 -7
- package/src/commands/config-ux.js +292 -0
- package/src/commands/config.js +199 -48
- package/src/commands/continue.js +104 -0
- package/src/commands/doctor.js +15 -29
- package/src/commands/help.js +54 -34
- package/src/commands/history.js +147 -0
- package/src/commands/info.js +39 -4
- package/src/commands/log.js +142 -0
- package/src/commands/migrate.js +19 -12
- package/src/commands/open.js +138 -0
- package/src/commands/pr.js +219 -0
- package/src/commands/push.js +62 -22
- package/src/commands/ready.js +18 -48
- package/src/commands/release.js +112 -0
- package/src/commands/rescue.js +164 -0
- package/src/commands/save.js +52 -11
- package/src/commands/stash.js +210 -0
- package/src/commands/sw.js +89 -0
- package/src/commands/sync.js +19 -2
- package/src/commands/tag.js +40 -1
- package/src/commands/undo.js +9 -3
- package/src/core/ai/diff-range.js +1 -1
- package/src/core/cli/completion.js +237 -1
- package/src/core/cli/output.js +46 -0
- package/src/core/cli/render.js +121 -0
- package/src/core/commands/shell.js +9 -1
- package/src/core/config/repo-config.js +93 -0
- package/src/core/config/store.js +60 -10
- package/src/core/git/autostash.js +46 -0
- package/src/core/git/backup.js +170 -0
- package/src/core/git/conflicts.js +58 -0
- package/src/core/git/context.js +72 -5
- package/src/core/git/file-guard.js +193 -0
- package/src/core/git/operation-state.js +63 -0
- package/src/core/git/operations.js +32 -0
- package/src/core/git/semver.js +194 -0
- package/src/core/git/service.js +454 -24
- package/src/core/platform/http.js +53 -0
- package/src/core/platform/index.js +165 -0
- package/src/core/platform/providers.js +454 -0
- package/src/core/platform/remote-url.js +92 -0
- package/src/core/remote-merge/client.js +33 -3
- package/src/core/tools/browser.js +28 -0
- package/src/core/tools/commit-prompt.js +137 -0
- package/src/core/tools/interactive.js +272 -40
- package/src/core/tools/logger.js +33 -23
- package/src/core/tools/theme.js +228 -0
- package/src/workflows/ai-commit-workflow.js +52 -20
- package/src/workflows/checkout-workflow.js +24 -10
- package/src/workflows/clean-workflow.js +135 -83
- package/src/workflows/continue-workflow.js +233 -0
- package/src/workflows/doctor-workflow.js +10 -7
- package/src/workflows/history-workflow.js +211 -0
- package/src/workflows/migrate-workflow.js +39 -14
- package/src/workflows/pr-workflow.js +252 -0
- package/src/workflows/push/commit-step.js +123 -0
- package/src/workflows/push/local-merge-step.js +213 -0
- package/src/workflows/push/plan.js +63 -0
- package/src/workflows/push/remote-merge-step.js +224 -0
- package/src/workflows/push-workflow.js +185 -492
- package/src/workflows/ready-workflow.js +14 -10
- package/src/workflows/release-workflow.js +189 -0
- package/src/workflows/rescue-workflow.js +137 -0
- package/src/workflows/save-workflow.js +106 -41
- package/src/workflows/switch-workflow.js +171 -0
- package/src/workflows/sync-workflow.js +143 -44
- package/src/workflows/tag-workflow.js +103 -17
- package/src/workflows/undo-workflow.js +113 -34
- package/src/workflows/rollback-workflow.js +0 -99
package/README.md
CHANGED
|
@@ -49,9 +49,87 @@ source <(icode completion zsh)
|
|
|
49
49
|
|
|
50
50
|
## 全局参数
|
|
51
51
|
|
|
52
|
+
- `-R, --remote <name>`:指定本次使用的 remote(写在命令名前面,例如 `icode --remote upstream sync`)
|
|
52
53
|
- `-h, --help`:查看帮助(也可 `icode <command> -h` 查看子命令参数)
|
|
53
54
|
- `-d, --debug`:开启调试日志(输出更多细节)
|
|
54
55
|
|
|
56
|
+
## 命令一览
|
|
57
|
+
|
|
58
|
+
| 场景 | 命令 |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| 日常 | `ready` `save` `push` `sw` `checkout` `stash` `log` `sync` |
|
|
61
|
+
| 整理历史 | `amend` `fixup` `migrate` `clean` |
|
|
62
|
+
| 兜底 | `undo` `rescue` |
|
|
63
|
+
| 协作与发布 | `pr` `open` `tag` `release` |
|
|
64
|
+
| AI | `ai` `codereview` `explain` |
|
|
65
|
+
| 配置与环境 | `config` `doctor` `info` `completion` |
|
|
66
|
+
|
|
67
|
+
## 通用约定
|
|
68
|
+
|
|
69
|
+
### remote 选择
|
|
70
|
+
|
|
71
|
+
所有命令不再写死 `origin`,按以下优先级选择 remote:
|
|
72
|
+
|
|
73
|
+
1. 命令行 `--remote <name>`(或环境变量 `ICODE_REMOTE`),不存在时直接报错
|
|
74
|
+
2. 仓库 `.icoderc.json` 的 `remote`
|
|
75
|
+
3. 全局配置 `defaults.remote`(`icode config set remote upstream`)
|
|
76
|
+
4. 当前分支 upstream 所在的 remote
|
|
77
|
+
5. `origin`,没有时取第一个 remote
|
|
78
|
+
|
|
79
|
+
`fetch` 默认只拉取选中的 remote,不再 `fetch --all`。
|
|
80
|
+
|
|
81
|
+
### 仓库级配置 `.icoderc.json`
|
|
82
|
+
|
|
83
|
+
放在仓库根目录、可以提交进仓库,团队共享。`icode config init` 会按当前仓库生成:
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"remote": "origin",
|
|
88
|
+
"defaultBranch": "main",
|
|
89
|
+
"protectedBranches": ["main", "release"],
|
|
90
|
+
"save": {
|
|
91
|
+
"maxFileSizeMB": 5,
|
|
92
|
+
"sensitivePatterns": ["*.secret.json"],
|
|
93
|
+
"allowPatterns": ["fixtures/*.pem"]
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 恢复点
|
|
99
|
+
|
|
100
|
+
会改写历史或删除分支的操作执行前,都会自动把相关分支的位置记到 `refs/icode/backup/<时间>/` 下:
|
|
101
|
+
`undo`(reset)、`push`(本地 merge / 强推)、`sync`、`migrate`、`amend`、`fixup`、`clean`、`rescue --reset`。
|
|
102
|
+
`undo --mode hard` 还会备份已跟踪文件的未提交改动。恢复点不会被 push,也不会出现在分支列表里,用 `icode rescue` 查看和找回。
|
|
103
|
+
|
|
104
|
+
### 提交前风险扫描
|
|
105
|
+
|
|
106
|
+
`save`、`push`、`amend`、`fixup` 提交前会扫描将要提交的文件:
|
|
107
|
+
|
|
108
|
+
- 敏感文件名:`.env`、`*.pem`、`*.key`、`id_rsa`、`credentials.json`、`*.tfstate` 等(`.env.example` 这类模板不算)
|
|
109
|
+
- 疑似密钥内容:私钥、AWS / GitHub / GitLab / Slack / OpenAI / Google / npm token
|
|
110
|
+
- 大文件:默认超过 5MB
|
|
111
|
+
|
|
112
|
+
发现风险默认停止,确认无误可加 `--allow-risky`。
|
|
113
|
+
|
|
114
|
+
### 交互与输出
|
|
115
|
+
|
|
116
|
+
- 在终端里直接运行 `icode` 会显示常用操作菜单,选中即执行(可以打字过滤)。
|
|
117
|
+
- 所有选择都用方向键 `↑↓` + 回车;选项多时可以直接打字过滤,选项少时可以按数字快速选;多选用空格勾选、`a` 全选。确认框直接按 `y` / `n`。
|
|
118
|
+
- 尽量用选择代替输入:
|
|
119
|
+
- `save` / `push` 不传 `-m` 时进入提交信息向导:AI 生成,或选类型 → 选 scope(根据改动文件自动推荐)→ 只写一句描述
|
|
120
|
+
- AI 生成提交信息后可以选择:直接使用 / 修改标题 / 重新生成 / 取消
|
|
121
|
+
- `push` 不写目标分支时可以选“只推当前分支”或勾选要合并的分支
|
|
122
|
+
- `checkout` / `sync` / `clean` / `tag` / `amend` / `pr create` 不带参数时都会给出可选项
|
|
123
|
+
- `config` 的 AI 配置向导内置常见服务和模型(OpenAI、DeepSeek、通义、智谱、Kimi、Anthropic、Ollama)
|
|
124
|
+
- 输出统一配色:分支、提交、tag、路径、链接用固定颜色,结果用 ✔ ▲ ✖ 标识。
|
|
125
|
+
- 颜色只在终端中显示;输出到管道或文件时自动去掉。可用 `NO_COLOR=1` 关闭、`FORCE_COLOR=1` 强制开启。
|
|
126
|
+
- 加 `-y` 或在非交互环境(CI、脚本)中运行时,不会出现任何交互提示。
|
|
127
|
+
|
|
128
|
+
### JSON 输出
|
|
129
|
+
|
|
130
|
+
大多数命令支持 `--json`:stdout 只输出结构化结果(统一带 `ok` 字段),普通日志改走 stderr。
|
|
131
|
+
命令失败时 stdout 输出 `{"ok": false, "error": {"code": "...", "message": "...", "exitCode": 2}}`。
|
|
132
|
+
|
|
55
133
|
## AI 能力配置
|
|
56
134
|
|
|
57
135
|
先配置一个 AI profile(支持 OpenAI/Anthropic/Ollama 三种接口格式):
|
|
@@ -110,7 +188,7 @@ icode doctor
|
|
|
110
188
|
icode doctor --json
|
|
111
189
|
```
|
|
112
190
|
|
|
113
|
-
`doctor` 会检查 Git
|
|
191
|
+
`doctor` 会检查 Git 命令、当前 remote、hooks、AI profile 与平台 token,并给出修复建议。建议新成员初始化环境后先执行一次。
|
|
114
192
|
|
|
115
193
|
参数说明:
|
|
116
194
|
|
|
@@ -150,7 +228,12 @@ icode save -m "fix: adjust copy" --dry-run
|
|
|
150
228
|
icode save --ai-commit --dry-run --json
|
|
151
229
|
```
|
|
152
230
|
|
|
153
|
-
`save` 是安全快速提交场景:检查状态 ->
|
|
231
|
+
`save` 是安全快速提交场景:检查状态 -> 风险扫描 -> 暂存 -> 创建本地 commit。它不会 push,也不会隐式生成提交信息。
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
icode save -m "fix: typo" src/login.vue # 只提交指定路径
|
|
235
|
+
icode save --staged-only -m "chore: part" # 只提交已 git add 的内容
|
|
236
|
+
```
|
|
154
237
|
|
|
155
238
|
- 无改动会直接失败
|
|
156
239
|
- 存在冲突会直接失败
|
|
@@ -165,7 +248,10 @@ icode save --ai-commit --dry-run --json
|
|
|
165
248
|
- `--ai-commit`:使用 AI 根据全部未提交改动生成提交信息
|
|
166
249
|
- `--profile <name>`:指定 AI profile(仅 `--ai-commit` 使用)
|
|
167
250
|
- `--lang <zh|en>`:AI 提交信息语言,默认 `zh`
|
|
168
|
-
-
|
|
251
|
+
- `[path...]`:只提交这些路径
|
|
252
|
+
- `--staged-only`:只提交暂存区,不自动 `git add`
|
|
253
|
+
- `--allow-risky`:检测到敏感文件 / 疑似密钥 / 大文件时仍继续
|
|
254
|
+
- `--dry-run`:只检查并展示将提交的信息和风险,不执行 add/commit
|
|
169
255
|
- `--json`:输出机器可读 JSON
|
|
170
256
|
- `--repo-mode auto|strict`:仓库模式(自动继承父仓库/禁止继承)
|
|
171
257
|
- `--no-verify`:commit 时跳过 hook/husky 校验
|
|
@@ -189,11 +275,48 @@ icode checkout <branch> [base] [--push-origin] [--pull-main] [--repo-mode auto|s
|
|
|
189
275
|
- `[base]`:新建分支基线,默认主分支
|
|
190
276
|
- `--push-origin`:新建分支后立即推送到 `origin`
|
|
191
277
|
- `--pull-main`:切换后同步主分支到当前分支
|
|
278
|
+
- `--autostash`:有未提交改动时自动 stash,切换后恢复
|
|
279
|
+
- `--json`:输出机器可读 JSON
|
|
192
280
|
- `--repo-mode auto|strict`:仓库模式(自动继承父仓库/禁止继承)
|
|
193
281
|
- `--no-verify`:跳过 hook/husky 校验
|
|
194
282
|
- `-y, --yes`:自动确认(跳过交互提示)
|
|
195
283
|
- `-h, --help`:查看帮助
|
|
196
284
|
|
|
285
|
+
### sw
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
icode sw # 交互选择(最近使用在前,显示 ahead/behind)
|
|
289
|
+
icode sw login # 模糊匹配,例如 feature/login
|
|
290
|
+
icode sw - # 切回上一个分支
|
|
291
|
+
icode sw -c fix/x # 新建并切换
|
|
292
|
+
icode sw -l # 只列出
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
- 唯一匹配时直接切换,多个匹配时交互选择(`-y` / 非交互环境下报错并列出候选)
|
|
296
|
+
- `-a, --all`:候选包含仅存在于远程的分支,选中后自动建 tracking 分支
|
|
297
|
+
- `--autostash`:未提交改动与目标分支冲突时自动 stash 并在切换后恢复
|
|
298
|
+
|
|
299
|
+
### stash
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
icode stash # 交互:选择 stash 后 pop/apply/show/drop
|
|
303
|
+
icode stash save -m "wip: login" # 默认包含未跟踪文件
|
|
304
|
+
icode stash list
|
|
305
|
+
icode stash pop 1 # 等同 stash@{1}
|
|
306
|
+
icode stash drop 1 -y
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### log
|
|
310
|
+
|
|
311
|
+
```bash
|
|
312
|
+
icode log # 最近 20 条
|
|
313
|
+
icode log --mine --since "1 week ago"
|
|
314
|
+
icode log --unpushed # 还没推送的提交
|
|
315
|
+
icode log --file src/cli.js -n 5 # 文件历史(跟踪重命名)
|
|
316
|
+
icode log --graph
|
|
317
|
+
icode log main..HEAD --json
|
|
318
|
+
```
|
|
319
|
+
|
|
197
320
|
### push
|
|
198
321
|
|
|
199
322
|
```bash
|
|
@@ -211,13 +334,16 @@ icode push release test -r -y # 使用远程 MR 模式合并到多个目标分
|
|
|
211
334
|
|
|
212
335
|
- 自动 `add + commit + push`
|
|
213
336
|
- 存在冲突或未完成 Git 操作时会直接停止
|
|
214
|
-
- 本地 merge
|
|
337
|
+
- 本地 merge 冲突会暂停在目标分支现场;解决冲突后执行 `icode continue`,会自动暂存、推送该分支、继续处理剩下的目标分支并切回原分支;执行 `icode abort` 则放弃并切回原分支
|
|
215
338
|
- 支持 `--ai-commit` 在 push 前自动生成并应用 AI 提交信息
|
|
216
339
|
- 若仓库存在 husky/hooks/commitlint 规则,AI commit 会先扫描本地规范再生成提交信息
|
|
217
340
|
- 支持把当前分支合并到多个目标分支
|
|
218
341
|
- 默认使用本地 merge 模式(会生成 merge commit)
|
|
219
342
|
- 支持远程 PR/MR API 模式(需配置平台密钥)
|
|
220
|
-
- 支持受保护分支策略(通过 `icode config protect ...` 管理)
|
|
343
|
+
- 支持受保护分支策略(通过 `icode config protect ...` 或 `.icoderc.json` 管理)
|
|
344
|
+
- 目标分支在本地和远程都不存在时,默认会询问(`-y` 时直接报错),避免拼错分支名时悄悄新建;确需新建请加 `--create-target`
|
|
345
|
+
- 本地 merge 和强推前会自动创建恢复点
|
|
346
|
+
- `--force` 是安全强推:只作用于当前分支,只用 `--force-with-lease`(以 fetch 之前看到的远程位置为准),拒绝主分支和受保护分支
|
|
221
347
|
|
|
222
348
|
参数说明:
|
|
223
349
|
|
|
@@ -232,6 +358,10 @@ icode push release test -r -y # 使用远程 MR 模式合并到多个目标分
|
|
|
232
358
|
- `--pull-main`:提交前同步主分支到当前分支
|
|
233
359
|
- `--not-push-current`:不推送当前分支,只处理目标分支
|
|
234
360
|
- `--force-protected`:强制处理配置里的受保护分支
|
|
361
|
+
- `-f, --force`:安全强推当前分支(`--force-with-lease`)
|
|
362
|
+
- `--create-target`:目标分支不存在时允许从当前分支新建
|
|
363
|
+
- `--allow-risky`:检测到风险文件时仍继续提交
|
|
364
|
+
- `--json`:输出机器可读 JSON
|
|
235
365
|
- `--repo-mode auto|strict`:仓库模式(自动继承父仓库/禁止继承)
|
|
236
366
|
- `--no-verify`:跳过 hook/husky 校验
|
|
237
367
|
- `-h, --help`:查看帮助
|
|
@@ -240,16 +370,21 @@ icode push release test -r -y # 使用远程 MR 模式合并到多个目标分
|
|
|
240
370
|
|
|
241
371
|
- `push` 的布尔开关(如 `--ai-commit`、`--pull-main`、`--no-verify`、`-y`)仅在命令行显式传入时生效。
|
|
242
372
|
|
|
243
|
-
|
|
373
|
+
远程合并(`-r`)支持 GitHub、GitLab、Gitee、Gitea/Forgejo,平台按 remote 域名自动识别:
|
|
244
374
|
|
|
245
375
|
```bash
|
|
246
|
-
icode config platform
|
|
376
|
+
icode config platform token set github ghp_xxx
|
|
377
|
+
icode config platform token set gitlab glpat-xxx
|
|
378
|
+
icode config platform host set git.company.com gitlab # 自建平台域名映射
|
|
247
379
|
```
|
|
248
380
|
|
|
381
|
+
token 也可以用环境变量:`GITHUB_TOKEN` / `GH_TOKEN`、`GITLAB_TOKEN`、`GITEE_TOKEN`、`GITEA_TOKEN`。
|
|
382
|
+
旧配置 `icode config platform remote-merge set --provider gitlab --api-key xxx` 仍然有效。
|
|
383
|
+
|
|
249
384
|
建议:
|
|
250
385
|
|
|
251
386
|
- 密钥按平台维度管理,例如 GitLab / GitHub / 自建平台。
|
|
252
|
-
- GitLab API 地址固定为仓库
|
|
387
|
+
- GitLab API 地址固定为仓库 remote 对应站点的 `/api/v4`,无需再单独配置服务地址。
|
|
253
388
|
- 项目/仓库默认启用远程合并;如个别仓库不希望启用,可显式设置 `repositories.<repo>.remoteMerge.enabled=false`。
|
|
254
389
|
- 远程合并始终根据 `origin` 自动提取 GitLab 项目地址;若无法识别,会提示你修正仓库 remote 配置。
|
|
255
390
|
- GitLab 审批规则由 merge API 统一判断;若审批不足,会在 merge 阶段输出明确失败原因。
|
|
@@ -311,6 +446,8 @@ icode sync [branch...] [--all-local] [--merge-main] [--push]
|
|
|
311
446
|
- `--merge-main`:同步后把主分支 merge 到目标分支
|
|
312
447
|
- `--rebase`:pull 时使用 rebase
|
|
313
448
|
- `--push`:同步后自动 push
|
|
449
|
+
- `--autostash`:有未提交改动时自动 stash,结束后恢复(否则要求工作区干净)
|
|
450
|
+
- `--json`:输出机器可读 JSON
|
|
314
451
|
- `-y, --yes`:自动确认(跳过确认提示)
|
|
315
452
|
- `--repo-mode auto|strict`:仓库模式(自动继承父仓库/禁止继承)
|
|
316
453
|
- `--no-verify`:push 时跳过 hook/husky 校验
|
|
@@ -319,17 +456,24 @@ icode sync [branch...] [--all-local] [--merge-main] [--push]
|
|
|
319
456
|
### clean
|
|
320
457
|
|
|
321
458
|
```bash
|
|
322
|
-
icode clean
|
|
459
|
+
icode clean # 已合并到主分支(优先用远程版本判断)
|
|
460
|
+
icode clean --gone -y # 远程分支已被删除的本地分支
|
|
461
|
+
icode clean --stale 90 --dry-run # 超过 90 天没有新提交的分支
|
|
323
462
|
```
|
|
324
463
|
|
|
325
|
-
-
|
|
326
|
-
- 执行前要求当前处于普通分支、工作区干净,且不存在未完成 Git 操作
|
|
464
|
+
- 不再切换分支,工作区有改动也可以执行
|
|
327
465
|
- 默认保护当前分支/主分支/配置中的受保护分支
|
|
328
|
-
-
|
|
466
|
+
- 删除前会为所有待删分支创建恢复点,误删可用 `icode rescue` 找回
|
|
467
|
+
- 可选同步删除远程分支(`--remote`,仅限已合并的分支)
|
|
329
468
|
|
|
330
469
|
参数说明:
|
|
331
470
|
|
|
332
471
|
- `--merged-target <branch>`:基于该分支判断“已合并”状态
|
|
472
|
+
- `--merged`:清理已合并分支(默认;与 `--gone` / `--stale` 同用时取并集)
|
|
473
|
+
- `--gone`:清理远程分支已删除的本地分支
|
|
474
|
+
- `--stale <days>`:清理超过 N 天没有提交的分支
|
|
475
|
+
- `--dry-run`:只列出将被删除的分支
|
|
476
|
+
- `--json`:输出机器可读 JSON
|
|
333
477
|
- `--keep <branch|csv>`:额外保留分支,可重复或逗号分隔
|
|
334
478
|
- `--remote`:同时删除远程分支
|
|
335
479
|
- `--force`:强制删除本地分支(`-D`)
|
|
@@ -341,19 +485,125 @@ icode clean [--merged-target <branch>] [--remote] [--force]
|
|
|
341
485
|
|
|
342
486
|
```bash
|
|
343
487
|
icode tag [--name <tag>] [--message <msg>] [--from <ref>]
|
|
488
|
+
icode tag --bump auto --dry-run # 按提交推断下一个语义化版本
|
|
489
|
+
icode tag --bump minor -y
|
|
490
|
+
icode tag --bump prerelease --preid rc
|
|
344
491
|
```
|
|
345
492
|
|
|
346
|
-
默认 tag 规则:`vYYYYMMDD_NN`(例如 `v20260309_01
|
|
493
|
+
默认 tag 规则:`vYYYYMMDD_NN`(例如 `v20260309_01`)。传 `--bump` 时改用语义化版本:
|
|
494
|
+
破坏性变更(`feat!:` 或 `BREAKING CHANGE`)-> major,`feat` -> minor,其它 -> patch(0.x 版本的破坏性变更只升 minor)。
|
|
347
495
|
|
|
348
496
|
参数说明:
|
|
349
497
|
|
|
350
498
|
- `-n, --name <tag>`:指定 tag 名(默认 `vYYYYMMDD_NN`)
|
|
499
|
+
- `-b, --bump <kind>`:`auto | patch | minor | major | prerelease`
|
|
500
|
+
- `--preid <id>`:预发布标识,例如 `beta`、`rc`
|
|
501
|
+
- `--no-push`:只创建本地 tag
|
|
502
|
+
- `--dry-run`:只计算 tag 名
|
|
503
|
+
- `--json`:输出机器可读 JSON
|
|
504
|
+
- `-y, --yes`:不再询问 tag 名
|
|
351
505
|
- `-m, --message <msg>`:tag 备注
|
|
352
506
|
- `--from <ref>`:从指定分支/commit 创建 tag
|
|
353
507
|
- `--repo-mode auto|strict`:仓库模式(自动继承父仓库/禁止继承)
|
|
354
508
|
- `--no-verify`:跳过 hook/husky 校验
|
|
355
509
|
- `-h, --help`:查看帮助
|
|
356
510
|
|
|
511
|
+
### release
|
|
512
|
+
|
|
513
|
+
```bash
|
|
514
|
+
icode release --dry-run # 预览版本号和 changelog
|
|
515
|
+
icode release -y # 打 tag、推送、创建平台 Release
|
|
516
|
+
icode release --bump minor --write-changelog --update-package -y
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
流程:计算版本 -> 生成 changelog(按 Conventional Commits 分组)-> 可选写入 `CHANGELOG.md` / 更新 `package.json` 并提交 -> 打 annotated tag 并推送 -> 创建 GitHub / GitLab / Gitee / Gitea Release(没有 token 时只给出 Release 页面链接)。
|
|
520
|
+
|
|
521
|
+
参数:`--bump`、`--preid`、`--name`、`--write-changelog`、`--changelog-file <path>`、`--update-package`、`--no-platform`、`--draft`、`--prerelease`、`--no-push`、`--dry-run`、`--json`、`-y`。
|
|
522
|
+
|
|
523
|
+
### pr
|
|
524
|
+
|
|
525
|
+
```bash
|
|
526
|
+
icode pr create # 先推送当前分支,再创建 PR/MR(标题和正文取自提交)
|
|
527
|
+
icode pr create -b release --ai # AI 生成标题和描述
|
|
528
|
+
icode pr list --state all
|
|
529
|
+
icode pr view # 当前分支对应的 PR
|
|
530
|
+
icode pr checkout 42 # 检出到本地分支 pr/42(fork 来的 PR 也可以)
|
|
531
|
+
icode pr merge 42 --method squash -y
|
|
532
|
+
icode pr open
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
- 支持 GitHub、GitLab、Gitee、Gitea/Forgejo,按 remote 域名自动识别(`--provider` 可强制指定)
|
|
536
|
+
- 没有配置 token 时,`pr create` 会改为在浏览器中打开创建页面
|
|
537
|
+
- `icode mr` 是 `icode pr` 的别名
|
|
538
|
+
|
|
539
|
+
### open
|
|
540
|
+
|
|
541
|
+
```bash
|
|
542
|
+
icode open # 当前分支页面
|
|
543
|
+
icode open src/cli.js:42 # 文件指定行
|
|
544
|
+
icode open pr # 当前分支的 PR,没有则打开创建页面
|
|
545
|
+
icode open compare release # 当前分支与 release 的对比
|
|
546
|
+
icode open ci # CI / 流水线
|
|
547
|
+
icode open commit HEAD~1 -p # 只打印链接
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
除 `open pr` 查询已有 PR 外,都不需要 token。
|
|
551
|
+
|
|
552
|
+
### amend
|
|
553
|
+
|
|
554
|
+
```bash
|
|
555
|
+
icode amend -a # 把全部未提交改动追加到上一个提交
|
|
556
|
+
icode amend src/login.js # 只追加指定路径
|
|
557
|
+
icode amend -m "feat: 新的描述" # 只改提交信息
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
上一个提交已推送时会先提示(`-y` 跳过),之后需要 `icode push --force`。
|
|
561
|
+
|
|
562
|
+
### fixup
|
|
563
|
+
|
|
564
|
+
```bash
|
|
565
|
+
icode fixup -a # 交互选择当前分支上的某个提交,把改动合进去
|
|
566
|
+
icode fixup a1b2c3d -a
|
|
567
|
+
icode fixup a1b2c3d --no-rebase
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
等同 `git commit --fixup=<commit>` + `git rebase -i --autosquash`,不会打开编辑器。冲突时用 `icode continue` / `icode abort` 处理。
|
|
571
|
+
|
|
572
|
+
### continue / abort
|
|
573
|
+
|
|
574
|
+
冲突解决后继续:
|
|
575
|
+
|
|
576
|
+
```bash
|
|
577
|
+
icode continue
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
1. 检查冲突文件里是否还有 `<<<<<<<` / `>>>>>>>`,有就列出文件和行号,不会继续
|
|
581
|
+
2. 自动 `git add` 已解决的文件
|
|
582
|
+
3. 继续 merge / rebase / cherry-pick / revert(不会打开编辑器)
|
|
583
|
+
4. 如果是 `push` / `migrate` / `sync` 中途冲突,接着把剩下的步骤做完:推送当前分支、处理剩余目标分支、切回原分支
|
|
584
|
+
|
|
585
|
+
放弃:
|
|
586
|
+
|
|
587
|
+
```bash
|
|
588
|
+
icode abort
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
中止进行中的 Git 操作,切回原分支。已经推送成功的分支不会被撤回。
|
|
592
|
+
|
|
593
|
+
有被中断的操作时,`icode ready` 会标出来,直接运行 `icode` 的菜单也会把“继续 / 放弃”放在最前面。
|
|
594
|
+
`icode undo --recover continue|abort` 仍然可用,效果相同。
|
|
595
|
+
|
|
596
|
+
### rescue
|
|
597
|
+
|
|
598
|
+
```bash
|
|
599
|
+
icode rescue # 列出恢复点和最近的 HEAD 历史(reflog)
|
|
600
|
+
icode rescue restore 20261102-153012-120 # 新建分支指向恢复点(不动当前分支)
|
|
601
|
+
icode rescue restore 20261102-153012-120:main --reset # 把当前分支重置过去
|
|
602
|
+
icode rescue restore 20261102-153012-120:worktree # 找回 hard reset 前的未提交改动
|
|
603
|
+
icode rescue restore HEAD@{3} --branch fix/lost
|
|
604
|
+
icode rescue prune --keep 20
|
|
605
|
+
```
|
|
606
|
+
|
|
357
607
|
### undo
|
|
358
608
|
|
|
359
609
|
```bash
|
|
@@ -365,7 +615,8 @@ icode undo --mode revert --ref HEAD --json
|
|
|
365
615
|
- 适合新人或低频 Git 操作场景
|
|
366
616
|
- 也支持非交互参数:`--mode` + `--ref` / `--hash`
|
|
367
617
|
- 支持用位置参数指定 commit hash,例如:`icode undo a1b2c3d --mode revert -y`
|
|
368
|
-
-
|
|
618
|
+
- 检测到未完成的 merge/rebase/revert/cherry-pick 时,会提示继续或中止
|
|
619
|
+
- reset 模式执行前会自动创建恢复点;hard 模式还会备份已跟踪文件的未提交改动
|
|
369
620
|
- 支持 `--json` 输出结构化结果;适合 AI agent 判断是否已恢复现场
|
|
370
621
|
|
|
371
622
|
参数说明:
|
|
@@ -392,7 +643,7 @@ icode migrate <sourceBranch> <targetBranch> --dry-run --json
|
|
|
392
643
|
- 执行前要求工作区干净,且不能存在未完成的 merge/rebase/cherry-pick/revert
|
|
393
644
|
- 支持 `--dry-run` 输出 checkout/pull/cherry-pick/push 计划,不产生 Git 副作用
|
|
394
645
|
- 支持 `--json` 输出结构化计划或执行结果,适合 AI agent 消费
|
|
395
|
-
-
|
|
646
|
+
- 如果迁移冲突,解决后执行 `icode continue`(会接着迁移剩下的提交,带 `--push` 时自动推送并切回原分支),或执行 `icode abort` 放弃
|
|
396
647
|
|
|
397
648
|
参数说明:
|
|
398
649
|
|
|
@@ -411,17 +662,27 @@ icode migrate <sourceBranch> <targetBranch> --dry-run --json
|
|
|
411
662
|
### config
|
|
412
663
|
|
|
413
664
|
```bash
|
|
414
|
-
icode config
|
|
415
|
-
icode config
|
|
416
|
-
icode config set
|
|
665
|
+
icode config # 交互终端中进入引导式配置(token / AI / remote / 受保护分支 / .icoderc)
|
|
666
|
+
icode config list # 默认脱敏,--show-secrets 查看原文;同时显示当前仓库的 .icoderc.json
|
|
667
|
+
icode config set remote upstream # 常用项有简写
|
|
668
|
+
icode config set main main,develop
|
|
669
|
+
icode config set token.github ghp_xxx
|
|
670
|
+
icode config set host.git.company.com gitlab
|
|
671
|
+
icode config get remote
|
|
672
|
+
icode config init # 生成团队共享的 .icoderc.json
|
|
673
|
+
icode config edit # 用 $EDITOR 打开配置文件,保存时校验 JSON
|
|
674
|
+
icode config path
|
|
417
675
|
icode config protect add main release
|
|
418
|
-
icode config
|
|
419
|
-
icode config platform remote-merge set --provider gitlab --api-key rm_xxx
|
|
676
|
+
icode config platform token show
|
|
420
677
|
```
|
|
421
678
|
|
|
679
|
+
Key 简写:`remote`、`repo-mode`、`main`、`ai-profile`、`token.<平台>`、`host.<域名>`。
|
|
680
|
+
键名里带点时可以用方括号:`platforms.hosts[git.company.com]`。
|
|
681
|
+
|
|
422
682
|
参数说明:
|
|
423
683
|
|
|
424
|
-
- `list
|
|
684
|
+
- `list`:查看全部配置(默认脱敏)
|
|
685
|
+
- `path` / `edit` / `init`:配置文件路径 / 编辑 / 生成仓库配置
|
|
425
686
|
- `get <path>`:读取指定配置项
|
|
426
687
|
- `set <path> <value>`:写入配置项(支持数字/布尔/JSON)
|
|
427
688
|
- `delete <path>`:删除配置项
|
|
@@ -429,8 +690,9 @@ icode config platform remote-merge set --provider gitlab --api-key rm_xxx
|
|
|
429
690
|
- `protect add <branch...>`:添加受保护分支
|
|
430
691
|
- `protect remove <branch...>`:移除受保护分支
|
|
431
692
|
- `ai <subcommand>`:AI profile 管理(见上文“AI 能力配置”)
|
|
432
|
-
- `platform
|
|
433
|
-
- `platform
|
|
693
|
+
- `platform token show|set|remove`:管理各平台 token
|
|
694
|
+
- `platform host set|remove`:自建平台域名映射
|
|
695
|
+
- `platform remote-merge show|set`:旧命令,仍可用
|
|
434
696
|
- `--repo-mode auto|strict`:仓库模式(仅影响 protect)
|
|
435
697
|
- `-h, --help`:查看帮助
|
|
436
698
|
|
|
@@ -438,9 +700,10 @@ icode config platform remote-merge set --provider gitlab --api-key rm_xxx
|
|
|
438
700
|
|
|
439
701
|
```bash
|
|
440
702
|
icode info
|
|
703
|
+
icode info --json
|
|
441
704
|
```
|
|
442
705
|
|
|
443
|
-
输出 Git
|
|
706
|
+
输出 Git 版本、仓库根路径、当前分支、使用的 remote 及来源、`.icoderc.json` 路径、hook/husky 状态、受保护分支等信息。
|
|
444
707
|
|
|
445
708
|
## 复杂场景支持
|
|
446
709
|
|
package/bin/icode.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { handleCliError, main } from '../src/cli.js'
|
|
3
3
|
|
|
4
|
+
// 输出被管道提前关闭(例如 icode log | head)时静默退出,不打印堆栈。
|
|
5
|
+
for (const stream of [process.stdout, process.stderr]) {
|
|
6
|
+
stream.on('error', (error) => {
|
|
7
|
+
if (error.code === 'EPIPE') {
|
|
8
|
+
process.exit(0)
|
|
9
|
+
}
|
|
10
|
+
throw error
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
|
|
4
14
|
main().catch((error) => {
|
|
5
15
|
handleCliError(error)
|
|
6
16
|
})
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icode-js/icode",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Modern git workflow CLI with robust parent-repo and hook handling",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "C",
|
|
7
7
|
"bin": {
|
|
8
|
-
"icode": "
|
|
8
|
+
"icode": "bin/icode.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "node --test",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "https://github.com/wandou-cc/icode-js.git"
|
|
22
|
+
"url": "git+https://github.com/wandou-cc/icode-js.git"
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://github.com/wandou-cc/icode-js",
|
|
25
25
|
"license": "MIT",
|