clawt 2.7.1 → 2.7.3

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.
@@ -7,7 +7,7 @@
7
7
  - 命令流程在 `5. 需求场景详细设计` 下,每个命令一个子章节(5.1-5.13)
8
8
  - run 命令对应 `5.2 批量创建 Worktree + 执行 Claude Code 任务`,流程按步骤编号描述
9
9
  - merge 命令对应 `5.6 合并验证过的分支`,-b 可选,支持模糊匹配(与 resume/validate 共享匹配逻辑),流程按步骤编号描述
10
- - config 命令对应 `5.10 查看全局配置`,只读展示配置
10
+ - config 命令对应 `5.10 查看和管理全局配置`,包含查看配置和 config reset 子命令两部分(使用 `####` 子标题区分)
11
11
  - resume 命令对应 `5.11 在已有 Worktree 中恢复会话`,支持模糊匹配和交互式分支选择(-b 可选)
12
12
  - validate 命令对应 `5.4 在主 Worktree 验证其他分支`,-b 可选,支持模糊匹配(与 resume 共享匹配逻辑)
13
13
  - sync 命令对应 `5.12 将主分支代码同步到目标 Worktree`,-b 可选,支持模糊匹配(与 resume/validate/merge 共享匹配逻辑)
@@ -22,7 +22,7 @@
22
22
 
23
23
  ## 关键约定
24
24
  - `autoDeleteBranch` 配置项影响三处:remove 命令、merge 命令、run 中断清理
25
- - `confirmDestructiveOps` 配置项影响两处:reset 命令、validate --clean
25
+ - `confirmDestructiveOps` 配置项影响三处:reset 命令、validate --clean、config reset
26
26
  - merge 的清理确认和清理操作均在 merge 成功后执行(避免 merge 冲突时提前询问用户造成困惑)
27
27
  - merge 成功后自动清理对应的 validate 快照(hasSnapshot + removeSnapshot)
28
28
  - merge 成功消息根据 `autoPullPush` 配置动态显示推送状态
@@ -35,7 +35,7 @@
35
35
  - `launchInteractiveClaude` 是 run(交互式模式)和 resume 共用的公共函数(在 src/utils/claude.ts)
36
36
  - killAllChildProcesses 是 run 专用的子进程终止函数(在 src/utils/shell.ts)
37
37
  - validate 快照管理函数在 `src/utils/validate-snapshot.ts`,被 validate、merge 和 remove 三个命令使用
38
- - `confirmDestructiveAction` 在 `src/utils/formatter.ts`,被 resetvalidate --clean 使用
38
+ - `confirmDestructiveAction` 在 `src/utils/formatter.ts`,被 resetvalidate --clean 和 config reset 使用
39
39
  - sanitizeBranchName 清理后为空串时抛出 BRANCH_NAME_EMPTY 错误
40
40
 
41
41
  ## 配置项同步检查点
package/README.md CHANGED
@@ -246,7 +246,7 @@ clawt list [--json]
246
246
  | ---- | ---- | ---- |
247
247
  | `--json` | 否 | 以 JSON 格式输出(仅包含 path 和 branch) |
248
248
 
249
- 列出当前项目在 `~/.clawt/worktrees/` 下的所有 worktree 及对应分支。指定 `--json` 时以 JSON 格式输出,便于脚本解析。
249
+ 列出当前项目在 `~/.clawt/worktrees/` 下的所有 worktree 及对应分支。文本模式下,如果某个 worktree 处于空闲状态(0 个提交、无变更、无未提交修改),其路径会以橙色高亮显示,方便快速识别可能需要清理或还未开始工作的 worktree。指定 `--json` 时以 JSON 格式输出,便于脚本解析。
250
250
 
251
251
  ```bash
252
252
  # 文本格式输出(默认)
@@ -269,14 +269,20 @@ clawt reset
269
269
  clawt reset
270
270
  ```
271
271
 
272
- ### `clawt config` — 查看全局配置
272
+ ### `clawt config` — 查看和管理全局配置
273
273
 
274
274
  ```bash
275
+ # 查看全局配置
275
276
  clawt config
277
+
278
+ # 将配置恢复为默认值
279
+ clawt config reset
276
280
  ```
277
281
 
278
282
  读取并展示全局配置文件 `~/.clawt/config.json` 中的所有配置项,包括每项的当前值和描述说明。编辑配置需直接修改配置文件。
279
283
 
284
+ `config reset` 子命令可将配置文件恢复为默认值,执行前会弹出确认提示(受 `confirmDestructiveOps` 配置项控制)。
285
+
280
286
  ## 配置文件
281
287
 
282
288
  安装后会自动在 `~/.clawt/config.json` 生成全局配置文件:
@@ -295,7 +301,7 @@ clawt config
295
301
  | `autoDeleteBranch` | `boolean` | `false` | 移除 worktree 时自动删除对应本地分支;merge 成功后自动清理 worktree 和分支;run 中断后自动清理本次创建的 worktree 和分支 |
296
302
  | `claudeCodeCommand` | `string` | `"claude"` | Claude Code CLI 启动指令,用于 `clawt run` 不传 `--tasks` 时和 `clawt resume` 在 worktree 中打开交互式界面 |
297
303
  | `autoPullPush` | `boolean` | `false` | merge 成功后是否自动执行 git pull 和 git push |
298
- | `confirmDestructiveOps` | `boolean` | `true` | 执行破坏性操作(reset、validate --clean)前是否提示确认 |
304
+ | `confirmDestructiveOps` | `boolean` | `true` | 执行破坏性操作(reset、validate --clean、config reset)前是否提示确认 |
299
305
 
300
306
  ## 分支名规则
301
307
 
package/dist/index.js CHANGED
@@ -76,6 +76,8 @@ var MESSAGES = {
76
76
  INTERRUPT_KEPT: "\u5DF2\u4FDD\u7559 worktree\uFF0C\u53EF\u7A0D\u540E\u4F7F\u7528 clawt remove \u624B\u52A8\u6E05\u7406",
77
77
  /** 配置文件损坏,已重新生成默认配置 */
78
78
  CONFIG_CORRUPTED: "\u914D\u7F6E\u6587\u4EF6\u635F\u574F\u6216\u65E0\u6CD5\u89E3\u6790\uFF0C\u5DF2\u91CD\u65B0\u751F\u6210\u9ED8\u8BA4\u914D\u7F6E",
79
+ /** 配置已恢复为默认值 */
80
+ CONFIG_RESET_SUCCESS: "\u2713 \u914D\u7F6E\u5DF2\u6062\u590D\u4E3A\u9ED8\u8BA4\u503C",
79
81
  /** 分隔线 */
80
82
  SEPARATOR: "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500",
81
83
  /** 粗分隔线 */
@@ -497,6 +499,9 @@ function confirmDestructiveAction(dangerousCommand, description) {
497
499
  printWarning(`\u5373\u5C06\u6267\u884C ${chalk.red.bold(dangerousCommand)}\uFF0C${description}`);
498
500
  return confirmAction("\u662F\u5426\u7EE7\u7EED\uFF1F");
499
501
  }
502
+ function isWorktreeIdle(status) {
503
+ return status.commitCount === 0 && status.insertions === 0 && status.deletions === 0 && !status.hasDirtyFiles;
504
+ }
500
505
  function formatWorktreeStatus(status) {
501
506
  const parts = [];
502
507
  parts.push(chalk.yellow(`${status.commitCount} \u4E2A\u63D0\u4EA4`));
@@ -852,8 +857,10 @@ function printListAsText(projectName, worktrees) {
852
857
  printInfo(` ${MESSAGES.NO_WORKTREES}`);
853
858
  } else {
854
859
  for (const wt of worktrees) {
855
- printInfo(` ${wt.path} [${wt.branch}]`);
856
860
  const status = getWorktreeStatus(wt);
861
+ const isIdle = status ? isWorktreeIdle(status) : false;
862
+ const pathDisplay = isIdle ? chalk2.hex("#FF8C00")(wt.path) : wt.path;
863
+ printInfo(` ${pathDisplay} [${wt.branch}]`);
857
864
  if (status) {
858
865
  printInfo(` ${formatWorktreeStatus(status)}`);
859
866
  } else {
@@ -1445,9 +1452,12 @@ async function handleMerge(options) {
1445
1452
  // src/commands/config.ts
1446
1453
  import chalk3 from "chalk";
1447
1454
  function registerConfigCommand(program2) {
1448
- program2.command("config").description("\u67E5\u770B\u5168\u5C40\u914D\u7F6E").action(() => {
1455
+ const configCmd = program2.command("config").description("\u67E5\u770B\u548C\u7BA1\u7406\u5168\u5C40\u914D\u7F6E").action(() => {
1449
1456
  handleConfig();
1450
1457
  });
1458
+ configCmd.command("reset").description("\u5C06\u914D\u7F6E\u6062\u590D\u4E3A\u9ED8\u8BA4\u503C").action(async () => {
1459
+ await handleConfigReset();
1460
+ });
1451
1461
  }
1452
1462
  function handleConfig() {
1453
1463
  const config = loadConfig();
@@ -1469,6 +1479,19 @@ ${chalk3.dim("\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84:")} ${CONFIG_PATH}
1469
1479
  }
1470
1480
  printSeparator();
1471
1481
  }
1482
+ async function handleConfigReset() {
1483
+ logger.info("config reset \u547D\u4EE4\u6267\u884C\uFF0C\u6062\u590D\u9ED8\u8BA4\u914D\u7F6E");
1484
+ const confirmed = await confirmDestructiveAction(
1485
+ "config reset",
1486
+ "\u5F53\u524D\u914D\u7F6E\u5C06\u88AB\u8986\u76D6\u4E3A\u9ED8\u8BA4\u503C"
1487
+ );
1488
+ if (!confirmed) {
1489
+ printInfo(MESSAGES.DESTRUCTIVE_OP_CANCELLED);
1490
+ return;
1491
+ }
1492
+ writeDefaultConfig();
1493
+ printSuccess(MESSAGES.CONFIG_RESET_SUCCESS);
1494
+ }
1472
1495
  function formatConfigValue(value) {
1473
1496
  if (typeof value === "boolean") {
1474
1497
  return value ? chalk3.green("true") : chalk3.yellow("false");
package/docs/spec.md CHANGED
@@ -21,7 +21,7 @@
21
21
  - [5.7 默认配置文件](#57-默认配置文件)
22
22
  - [5.8 获取当前项目所有 Worktree](#58-获取当前项目所有-worktree)
23
23
  - [5.9 日志系统](#59-日志系统)
24
- - [5.10 查看全局配置](#510-查看全局配置)
24
+ - [5.10 查看和管理全局配置](#510-查看和管理全局配置)
25
25
  - [5.11 在已有 Worktree 中恢复会话](#511-在已有-worktree-中恢复会话)
26
26
  - [5.12 将主分支代码同步到目标 Worktree](#512-将主分支代码同步到目标-worktree)
27
27
  - [5.13 重置主 Worktree 工作区和暂存区](#513-重置主-worktree-工作区和暂存区)
@@ -168,6 +168,7 @@ git show-ref --verify refs/heads/<branchName> 2>/dev/null
168
168
  | `clawt remove` | 移除 worktree(支持单个/批量/全部) | 5.5 |
169
169
  | `clawt list` | 列出当前项目所有 worktree(支持 `--json` 格式输出) | 5.8 |
170
170
  | `clawt config` | 查看全局配置 | 5.10 |
171
+ | `clawt config reset` | 将配置恢复为默认值 | 5.10 |
171
172
  | `clawt resume` | 在已有 worktree 中恢复 Claude Code 交互式会话 | 5.11 |
172
173
  | `clawt sync` | 将主分支最新代码同步到目标 worktree | 5.12 |
173
174
  | `clawt reset` | 重置主 worktree 工作区和暂存区 | 5.13 |
@@ -775,7 +776,7 @@ clawt merge [-m <commitMessage>]
775
776
  | `autoDeleteBranch` | `boolean` | `false` | 移除 worktree 时是否自动删除对应本地分支(无需每次确认);merge 成功后是否自动清理 worktree 和分支;run 任务被中断(Ctrl+C)后是否自动清理本次创建的 worktree 和分支 |
776
777
  | `claudeCodeCommand` | `string` | `"claude"` | Claude Code CLI 启动指令,用于 `clawt run` 不传 `--tasks` 时和 `clawt resume` 在 worktree 中打开交互式界面 |
777
778
  | `autoPullPush` | `boolean` | `false` | merge 成功后是否自动执行 git pull 和 git push |
778
- | `confirmDestructiveOps` | `boolean` | `true` | 执行破坏性操作(reset、validate --clean)前是否提示确认 |
779
+ | `confirmDestructiveOps` | `boolean` | `true` | 执行破坏性操作(reset、validate --clean、config reset)前是否提示确认 |
779
780
 
780
781
  ---
781
782
 
@@ -805,6 +806,8 @@ clawt list [--json]
805
806
 
806
807
  **文本输出格式(默认):**
807
808
 
809
+ 每个 worktree 会显示路径、分支名和变更状态。如果某个 worktree 处于空闲状态(0 个提交、无变更、无未提交修改),其路径会以橙色高亮显示,方便用户快速识别可能需要清理或还未开始工作的 worktree。
810
+
808
811
  ```
809
812
  当前项目: main-project
810
813
 
@@ -878,14 +881,20 @@ clawt list [--json]
878
881
 
879
882
  ---
880
883
 
881
- ### 5.10 查看全局配置
884
+ ### 5.10 查看和管理全局配置
882
885
 
883
886
  **命令:**
884
887
 
885
888
  ```bash
889
+ # 查看全局配置
886
890
  clawt config
891
+
892
+ # 将配置恢复为默认值
893
+ clawt config reset
887
894
  ```
888
895
 
896
+ #### 查看配置
897
+
889
898
  **运行流程:**
890
899
 
891
900
  1. 读取全局配置文件 `~/.clawt/config.json`
@@ -916,6 +925,14 @@ clawt config
916
925
 
917
926
  ```
918
927
 
928
+ #### 恢复默认配置
929
+
930
+ **运行流程:**
931
+
932
+ 1. 如果配置项 `confirmDestructiveOps` 为 `true`,提示确认(显示即将执行的操作和后果:当前配置将被覆盖为默认值),用户取消则退出
933
+ 2. 将默认配置写入 `~/.clawt/config.json`(覆盖现有配置文件)
934
+ 3. 输出成功提示:`✓ 配置已恢复为默认值`
935
+
919
936
  ---
920
937
 
921
938
  ### 5.11 在已有 Worktree 中恢复会话
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clawt",
3
- "version": "2.7.1",
3
+ "version": "2.7.3",
4
4
  "description": "本地并行执行多个Claude Code Agent任务,融合 Git Worktree 与 Claude Code CLI 的命令行工具",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,21 +1,28 @@
1
1
  import type { Command } from 'commander';
2
2
  import chalk from 'chalk';
3
- import { CONFIG_PATH, DEFAULT_CONFIG, CONFIG_DESCRIPTIONS } from '../constants/index.js';
3
+ import { CONFIG_PATH, DEFAULT_CONFIG, CONFIG_DESCRIPTIONS, MESSAGES } from '../constants/index.js';
4
4
  import { logger } from '../logger/index.js';
5
- import { loadConfig, printInfo, printSeparator } from '../utils/index.js';
5
+ import { loadConfig, writeDefaultConfig, printInfo, printSuccess, printSeparator, confirmDestructiveAction } from '../utils/index.js';
6
6
  import type { ClawtConfig } from '../types/index.js';
7
7
 
8
8
  /**
9
- * 注册 config 命令:查看全局配置
9
+ * 注册 config 命令组:查看和管理全局配置
10
10
  * @param {Command} program - Commander 实例
11
11
  */
12
12
  export function registerConfigCommand(program: Command): void {
13
- program
13
+ const configCmd = program
14
14
  .command('config')
15
- .description('查看全局配置')
15
+ .description('查看和管理全局配置')
16
16
  .action(() => {
17
17
  handleConfig();
18
18
  });
19
+
20
+ configCmd
21
+ .command('reset')
22
+ .description('将配置恢复为默认值')
23
+ .action(async () => {
24
+ await handleConfigReset();
25
+ });
19
26
  }
20
27
 
21
28
  /**
@@ -48,6 +55,26 @@ function handleConfig(): void {
48
55
  printSeparator();
49
56
  }
50
57
 
58
+ /**
59
+ * 执行 config reset 子命令的核心逻辑,将配置恢复为默认值
60
+ */
61
+ async function handleConfigReset(): Promise<void> {
62
+ logger.info('config reset 命令执行,恢复默认配置');
63
+
64
+ const confirmed = await confirmDestructiveAction(
65
+ 'config reset',
66
+ '当前配置将被覆盖为默认值',
67
+ );
68
+
69
+ if (!confirmed) {
70
+ printInfo(MESSAGES.DESTRUCTIVE_OP_CANCELLED);
71
+ return;
72
+ }
73
+
74
+ writeDefaultConfig();
75
+ printSuccess(MESSAGES.CONFIG_RESET_SUCCESS);
76
+ }
77
+
51
78
  /**
52
79
  * 格式化配置值的显示样式
53
80
  * @param {ClawtConfig[keyof ClawtConfig]} value - 配置值
@@ -9,6 +9,7 @@ import {
9
9
  getProjectWorktrees,
10
10
  getWorktreeStatus,
11
11
  formatWorktreeStatus,
12
+ isWorktreeIdle,
12
13
  printInfo,
13
14
  } from '../utils/index.js';
14
15
  // getWorktreeStatus 和 formatWorktreeStatus 仅在文本模式下使用
@@ -77,10 +78,15 @@ function printListAsText(projectName: string, worktrees: import('../types/index.
77
78
  printInfo(` ${MESSAGES.NO_WORKTREES}`);
78
79
  } else {
79
80
  for (const wt of worktrees) {
80
- printInfo(` ${wt.path} [${wt.branch}]`);
81
-
82
81
  // 获取并展示 worktree 变更状态
83
82
  const status = getWorktreeStatus(wt);
83
+
84
+ // 空闲状态的 worktree 路径用橙色高亮,提示用户关注
85
+ const isIdle = status ? isWorktreeIdle(status) : false;
86
+ const pathDisplay = isIdle ? chalk.hex('#FF8C00')(wt.path) : wt.path;
87
+
88
+ printInfo(` ${pathDisplay} [${wt.branch}]`);
89
+
84
90
  if (status) {
85
91
  printInfo(` ${formatWorktreeStatus(status)}`);
86
92
  } else {
@@ -60,6 +60,8 @@ export const MESSAGES = {
60
60
  INTERRUPT_KEPT: '已保留 worktree,可稍后使用 clawt remove 手动清理',
61
61
  /** 配置文件损坏,已重新生成默认配置 */
62
62
  CONFIG_CORRUPTED: '配置文件损坏或无法解析,已重新生成默认配置',
63
+ /** 配置已恢复为默认值 */
64
+ CONFIG_RESET_SUCCESS: '✓ 配置已恢复为默认值',
63
65
  /** 分隔线 */
64
66
  SEPARATOR: '────────────────────────────────────────',
65
67
  /** 粗分隔线 */
@@ -27,7 +27,7 @@ export function loadConfig(): ClawtConfig {
27
27
  /**
28
28
  * 将默认配置写入配置文件
29
29
  */
30
- function writeDefaultConfig(): void {
30
+ export function writeDefaultConfig(): void {
31
31
  writeFileSync(CONFIG_PATH, JSON.stringify(DEFAULT_CONFIG, null, 2), 'utf-8');
32
32
  }
33
33
 
@@ -78,6 +78,18 @@ export function confirmDestructiveAction(dangerousCommand: string, description:
78
78
  return confirmAction('是否继续?');
79
79
  }
80
80
 
81
+ /**
82
+ * 判断 worktree 是否处于空闲状态(0 个提交、无变更、无未提交修改)
83
+ * @param {WorktreeStatus} status - worktree 变更统计信息
84
+ * @returns {boolean} 是否空闲
85
+ */
86
+ export function isWorktreeIdle(status: WorktreeStatus): boolean {
87
+ return status.commitCount === 0
88
+ && status.insertions === 0
89
+ && status.deletions === 0
90
+ && !status.hasDirtyFiles;
91
+ }
92
+
81
93
  /**
82
94
  * 将 WorktreeStatus 格式化为带颜色的字符串
83
95
  * @param {WorktreeStatus} status - worktree 变更统计信息
@@ -47,8 +47,8 @@ export {
47
47
  export { sanitizeBranchName, generateBranchNames, validateBranchesNotExist } from './branch.js';
48
48
  export { validateMainWorktree, validateGitInstalled, validateClaudeCodeInstalled } from './validation.js';
49
49
  export { createWorktrees, getProjectWorktrees, getProjectWorktreeDir, cleanupWorktrees, getWorktreeStatus } from './worktree.js';
50
- export { loadConfig, getConfigValue, ensureClawtDirs } from './config.js';
51
- export { printSuccess, printError, printWarning, printInfo, printSeparator, printDoubleSeparator, confirmAction, confirmDestructiveAction, formatWorktreeStatus } from './formatter.js';
50
+ export { loadConfig, writeDefaultConfig, getConfigValue, ensureClawtDirs } from './config.js';
51
+ export { printSuccess, printError, printWarning, printInfo, printSeparator, printDoubleSeparator, confirmAction, confirmDestructiveAction, formatWorktreeStatus, isWorktreeIdle } from './formatter.js';
52
52
  export { ensureDir, removeEmptyDir } from './fs.js';
53
53
  export { multilineInput } from './prompt.js';
54
54
  export { launchInteractiveClaude } from './claude.js';